File size: 2,435 Bytes
d739b1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | const { Notification } = require('electron');
/**
* ๋ฐ์คํฌํฑ ๋ค์ดํฐ๋ธ ์๋ฆผ ๋ฐ์ก ํฌํผ
* @param {string} title ์๋ฆผ ์ ๋ชฉ
* @param {string} body ์๋ฆผ ๋ด์ฉ
* @param {'normal'|'critical'} urgency ๊ธด๊ธ์ฑ ๋ ๋ฒจ (critical ์ ๋ฌด์ ์๋, ์๋ฆผ์ฐฝ ์์ ๋๊ธฐ)
*/
function sendNotification(title, body, urgency = 'normal') {
if (!Notification?.isSupported?.()) {
console.warn('[Notifier] Native notifications are not supported on this platform.');
return { status: 'unsupported' };
}
try {
const notification = new Notification({
title: title,
body: body,
silent: urgency === 'normal',
// macOS์ ๊ฒฝ์ฐ urgency ๊ฐ critical ์ด๋ฉด ๋ฐฐ๋๊ฐ ๋ซํ์ง ์๊ณ ๋จธ๋ฌผ๋๋ก ์ค์
timeoutType: urgency === 'critical' ? 'never' : 'default'
});
// ์๋ฆผ ํด๋ฆญ ์ ๋ฉ์ธ ์๋์ฐ ํฌ์ปค์ฑ ์ด๋ฒคํธ ํธ๋ค๋ฌ ์ถ๊ฐ ๊ฐ๋ฅ
notification.on('click', () => {
const ctx = require('./context');
if (ctx.mainWindow) {
ctx.mainWindow.show();
ctx.mainWindow.focus();
}
});
notification.show();
return { status: 'submitted' };
} catch (err) {
console.error('[Notifier] Failed to show native notification:', err);
return { status: 'uncertain' };
}
}
module.exports = {
/**
* ๋ฃจํ ์ต์ข
์๋ฃ ์ ์๋ฆผ
*/
notifyLoopComplete(runId, success, reason, cost) {
const title = success ? 'โ
Closed-Loop ์ต์ข
์ฑ๊ณต' : 'โ Closed-Loop ์ข
๋ฃ (์คํจ)';
const body = success
? `ํ์คํฌ ${runId}๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ต์ข
๋ชฉํ(Goal)๋ฅผ ์์ํ์ต๋๋ค! (๋น์ฉ: $${cost.toFixed(2)})`
: `ํ์คํฌ ${runId}๊ฐ ๋ชฉํ ๋ฌ์ฑ์ ์คํจํ๊ฑฐ๋ ์ค๋จ๋์์ต๋๋ค: ${reason}`;
return sendNotification(title, body, success ? 'normal' : 'critical');
},
/**
* ์์ฐ 80% ๊ฒฝ๊ณ ๋ฑ ๋ฃจํ ๊ฒฝ๊ณ ์๋ฆผ
*/
notifyLoopWarning(runId, message) {
const title = 'โ ๏ธ Closed-Loop ๊ฐ๋๋ ์ผ ๊ฒฝ๊ณ ';
const body = `ํ์คํฌ ${runId}: ${message}`;
return sendNotification(title, body, 'normal');
},
/**
* HITL (์ฌ๋์ ํ๋จ) ๋๊ธฐ ์๋ฆผ
*/
notifyHitlWait(runId, message) {
const title = '๐ Closed-Loop ์ฌ๋์ ๊ฐ์
๋๊ธฐ';
const body = `ํ์คํฌ ${runId}๊ฐ ์ฌ์ฉ์์ ๋ถ์ ๋ฐ ์น์ธ ํผ๋๋ฐฑ์ ๊ธฐ๋ค๋ฆฝ๋๋ค: ${message}`;
return sendNotification(title, body, 'critical');
}
};
|