bada-terminal / src /loop-notifier.js
VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
2.44 kB
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');
}
};