Feat: include provider/model in ntfy, lower err prio

This commit is contained in:
2026-04-18 16:01:27 -07:00
parent bef94f6ff5
commit 0fcccb5953

19
run.js
View File

@@ -26,6 +26,8 @@ function meta(rid) {
controller: null, controller: null,
startedAt: snap.startedAt ?? 0, startedAt: snap.startedAt ?? 0,
timeoutTimer: null, timeoutTimer: null,
provider: snap.provider ?? null,
model: snap.model ?? null,
} }
runs.set(rid, r) runs.set(rid, r)
return r return r
@@ -46,6 +48,8 @@ function ensure(rid) {
controller: null, controller: null,
startedAt: 0, startedAt: 0,
timeoutTimer: null, timeoutTimer: null,
provider: null,
model: null,
} }
runs.set(rid, r) runs.set(rid, r)
return r return r
@@ -58,9 +62,15 @@ function saveSnapshot(r) {
phase: r.phase, phase: r.phase,
error: r.error, error: r.error,
startedAt: r.startedAt, startedAt: r.startedAt,
provider: r.provider,
model: r.model,
}) })
} }
function tag(r) {
return `[${r.provider || '?'}/${r.model || '?'}]`
}
function send(ws, obj) { function send(ws, obj) {
try { ws.send(JSON.stringify(obj)) } catch {} try { ws.send(JSON.stringify(obj)) } catch {}
} }
@@ -118,7 +128,7 @@ function stop(r) {
try { r.controller?.abort() } catch {} try { r.controller?.abort() } catch {}
saveSnapshot(r) saveSnapshot(r)
bcast(r, { type: 'done' }) bcast(r, { type: 'done' })
notify(`Run ${r.rid} ended. Duration: ${duration}s`, 2, ['stop_sign']) notify(`Run ${r.rid} ${tag(r)} ended. Duration: ${duration}s`, 2, ['stop_sign'])
} }
function fail(r, message) { function fail(r, message) {
@@ -133,7 +143,7 @@ function fail(r, message) {
try { r.controller?.abort() } catch {} try { r.controller?.abort() } catch {}
saveSnapshot(r) saveSnapshot(r)
bcast(r, { type: 'err', message: r.error }) bcast(r, { type: 'err', message: r.error })
notify(`Run ${r.rid} failed after ${duration}s: ${r.error}`, 3, ['rotating_light']) notify(`Run ${r.rid} ${tag(r)} failed after ${duration}s: ${r.error}`, 2, ['rotating_light'])
} }
function sanitizeMessages(messages) { function sanitizeMessages(messages) {
@@ -232,6 +242,7 @@ export function handleMessage(rid, ws, msg) {
return return
} }
const resolvedProvider = provider || 'openrouter'
r.rid = msgRid r.rid = msgRid
r.seq = -1 r.seq = -1
r.phase = 'running' r.phase = 'running'
@@ -240,6 +251,8 @@ export function handleMessage(rid, ws, msg) {
r.pendingImages = [] r.pendingImages = []
r.controller = new AbortController() r.controller = new AbortController()
r.startedAt = Date.now() r.startedAt = Date.now()
r.provider = resolvedProvider
r.model = body.model || null
// Hard timeout safety net // Hard timeout safety net
r.timeoutTimer = setTimeout(() => { r.timeoutTimer = setTimeout(() => {
@@ -248,7 +261,7 @@ export function handleMessage(rid, ws, msg) {
kv.set(`prompt:${r.rid}`, body.messages) kv.set(`prompt:${r.rid}`, body.messages)
saveSnapshot(r) saveSnapshot(r)
beginStream(r, { apiKey, body, provider: provider || 'openrouter' }) beginStream(r, { apiKey, body, provider: resolvedProvider })
} }
export function handlePoll(uid) { export function handlePoll(uid) {