Download src/loop-notifier.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 2.44 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/loop-notifier.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/loop-notifier.js
-
curl -L -o loop-notifier.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/loop-notifier.js
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'); | |
| } | |
| }; | |