fix: add notifications for response completion for all providers

This commit is contained in:
Haileyesus
2026-03-13 18:41:32 +03:00
parent 7eb52e73ea
commit ae494ea383
7 changed files with 189 additions and 170 deletions

View File

@@ -60,6 +60,22 @@ function createNotificationEvent({
};
}
function normalizeErrorMessage(error) {
if (typeof error === 'string') {
return error;
}
if (error && typeof error.message === 'string') {
return error.message;
}
if (error == null) {
return 'Unknown error';
}
return String(error);
}
function buildPushBody(event) {
const CODE_MAP = {
'permission.required': event.meta?.toolName
@@ -131,7 +147,41 @@ function notifyUserIfEnabled({ userId, event }) {
});
}
function notifyRunStopped({ userId, provider, sessionId = null, stopReason = 'completed' }) {
notifyUserIfEnabled({
userId,
event: createNotificationEvent({
provider,
sessionId,
kind: 'stop',
code: 'run.stopped',
meta: { stopReason },
severity: 'info',
dedupeKey: `${provider}:run:stop:${sessionId || 'none'}:${stopReason}`
})
});
}
function notifyRunFailed({ userId, provider, sessionId = null, error }) {
const errorMessage = normalizeErrorMessage(error);
notifyUserIfEnabled({
userId,
event: createNotificationEvent({
provider,
sessionId,
kind: 'error',
code: 'run.failed',
meta: { error: errorMessage },
severity: 'error',
dedupeKey: `${provider}:run:error:${sessionId || 'none'}:${errorMessage}`
})
});
}
export {
createNotificationEvent,
notifyUserIfEnabled
notifyUserIfEnabled,
notifyRunStopped,
notifyRunFailed
};