@johpaz/hive-agents 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -11
- package/dist/hive.js +22245 -6788
- package/dist/tool-worker.js +6 -2
- package/dist/ui/assets/{A2UIPage-D4nUFe5q.js → A2UIPage-D4nzp5NV.js} +1 -1
- package/dist/ui/assets/{AgentCreateForm-g1mQnIoJ.js → AgentCreateForm-M2RhjeA1.js} +1 -1
- package/dist/ui/assets/{AgentDetailPage-C3XkU4Ll.js → AgentDetailPage-DkFRtj8g.js} +1 -1
- package/dist/ui/assets/AgentNewPage-CfBU7puz.js +1 -0
- package/dist/ui/assets/{AgentsPage-CNA778Eo.js → AgentsPage-Ctzq2LWx.js} +1 -1
- package/dist/ui/assets/{ApiClientPage-t5DpKhmA.js → ApiClientPage-DKbGO1QW.js} +1 -1
- package/dist/ui/assets/{ChannelsPage-yY6t0YTU.js → ChannelsPage-H6rgr8DQ.js} +2 -2
- package/dist/ui/assets/{DashboardPage-BSeNSYg5.js → DashboardPage-BIjYGf4m.js} +2 -2
- package/dist/ui/assets/{LoginPage-eT5zDRDa.js → LoginPage-DazoxtBJ.js} +1 -1
- package/dist/ui/assets/{LogsPage-Gczzzsdh.js → LogsPage-DMZ6KtQ3.js} +1 -1
- package/dist/ui/assets/{MeetingPage-Bu4aMMNR.js → MeetingPage-CSLFvHL7.js} +1 -1
- package/dist/ui/assets/{ModelSelector-nNOrW3te.js → ModelSelector-BCfvugHB.js} +1 -1
- package/dist/ui/assets/{Office3DPage-B_iXEbyv.js → Office3DPage-BE6Epe0d.js} +2 -2
- package/dist/ui/assets/ProvidersPage-D0cApfM1.js +1 -0
- package/dist/ui/assets/{RecoverPage-DMqSasKk.js → RecoverPage-BVUPHG9z.js} +1 -1
- package/dist/ui/assets/{SettingsPage-B6FTSkOn.js → SettingsPage-DCZ4nql4.js} +1 -1
- package/dist/ui/assets/{SetupPage-DhcRbGgg.js → SetupPage-In19p30M.js} +1 -1
- package/dist/ui/assets/{WebChatPage-CWXjW4Hn.js → WebChatPage-ByVBSzxL.js} +1 -1
- package/dist/ui/assets/{activity-CQuPevhB.js → activity-BIIli7ET.js} +1 -1
- package/dist/ui/assets/{agentCapabilities-CDC6y91E.js → agentCapabilities-D1PD9yFH.js} +1 -1
- package/dist/ui/assets/arrow-left-BfcnX8Er.js +1 -0
- package/dist/ui/assets/arrow-right-Q-dzAn8k.js +1 -0
- package/dist/ui/assets/arrow-up-right-Bf-8wrUQ.js +1 -0
- package/dist/ui/assets/{calendar-Be23hQGc.js → calendar-S9-_Q6QR.js} +1 -1
- package/dist/ui/assets/check-CryV78SQ.js +1 -0
- package/dist/ui/assets/chevron-down-QCtMs-Af.js +1 -0
- package/dist/ui/assets/chevron-left-dTGbyl5G.js +1 -0
- package/dist/ui/assets/chevron-right-D0GjXbnO.js +1 -0
- package/dist/ui/assets/chevron-up-Cg0jO8uT.js +1 -0
- package/dist/ui/assets/{circle-alert-BDVHxmAz.js → circle-alert-DTVW4R94.js} +1 -1
- package/dist/ui/assets/circle-check-BAolxswA.js +1 -0
- package/dist/ui/assets/{circle-x-Cb2Yer4s.js → circle-x-CJXbXzRh.js} +1 -1
- package/dist/ui/assets/{copy-33tZrzc9.js → copy-X_TPpA-A.js} +1 -1
- package/dist/ui/assets/{dialog-KOZKWbib.js → dialog-uUBz_NIB.js} +1 -1
- package/dist/ui/assets/{download-CiQqqXyz.js → download-C-fXu08w.js} +1 -1
- package/dist/ui/assets/{earth-DCvN7ynm.js → earth-CTsVjCmp.js} +1 -1
- package/dist/ui/assets/{ellipsis-vertical-BybFZDk2.js → ellipsis-vertical-5zBh5yzc.js} +1 -1
- package/dist/ui/assets/{external-link-0iNNBvZm.js → external-link-CvpRhwC_.js} +1 -1
- package/dist/ui/assets/{eye-C8sKSSkg.js → eye-CM-HQEWU.js} +1 -1
- package/dist/ui/assets/{file-text-DO8jqiJK.js → file-text-lwkvYGtA.js} +1 -1
- package/dist/ui/assets/gauge-CB-cas-h.js +1 -0
- package/dist/ui/assets/{history-BtTD1kDo.js → history-eSHspWRr.js} +1 -1
- package/dist/ui/assets/index-D489S18g.css +2 -0
- package/dist/ui/assets/{index-Bejlp-R1.js → index-ZjAc-KQS.js} +4 -4
- package/dist/ui/assets/{info-mpk1tsNC.js → info-DTgFQ_jA.js} +1 -1
- package/dist/ui/assets/{key-CoQ0qtXt.js → key-CeM9JJkq.js} +1 -1
- package/dist/ui/assets/loader-circle-Dtfz4FWw.js +1 -0
- package/dist/ui/assets/{lock-open-Cd2aqwOd.js → lock-open-B089GUAJ.js} +1 -1
- package/dist/ui/assets/{mail-BG0RYSkL.js → mail--gNFIe4M.js} +1 -1
- package/dist/ui/assets/{pause-Cme88_9s.js → pause-DjT1nwQM.js} +1 -1
- package/dist/ui/assets/{pencil-f1nJ1xhs.js → pencil-6PRgdjiU.js} +1 -1
- package/dist/ui/assets/play-tOrP0xUJ.js +1 -0
- package/dist/ui/assets/plus-Cnom3j47.js +1 -0
- package/dist/ui/assets/{radio-B5SpKJ-J.js → radio-D-joO9J0.js} +1 -1
- package/dist/ui/assets/{refresh-cw-CroGQY62.js → refresh-cw-BRrzoHQW.js} +1 -1
- package/dist/ui/assets/search-D277MUP0.js +1 -0
- package/dist/ui/assets/{select-BhbW0stK.js → select-BOR8MsSL.js} +1 -1
- package/dist/ui/assets/{send-D6whYpw-.js → send-DIlj81PT.js} +1 -1
- package/dist/ui/assets/{settings-BX6q3MGB.js → settings-CkBjgAEm.js} +1 -1
- package/dist/ui/assets/{shield-BnGyu1xf.js → shield-U0hIjGzm.js} +1 -1
- package/dist/ui/assets/{sparkles-BcaOs_Jk.js → sparkles-VXHGDbNh.js} +1 -1
- package/dist/ui/assets/{square-ju5H8nrT.js → square-OHeetvN3.js} +1 -1
- package/dist/ui/assets/terminal-C6YPcJl_.js +1 -0
- package/dist/ui/assets/{trash-2-DjQXac_0.js → trash-2-DQxm7DUM.js} +1 -1
- package/dist/ui/assets/{triangle-alert-B04mgMcg.js → triangle-alert-Dj8ZhmWj.js} +1 -1
- package/dist/ui/assets/{useHiveAgentsModelLoad-DT5-4CCj.js → useHiveAgentsModelLoad-COLvs-Ho.js} +1 -1
- package/dist/ui/assets/{useProviders-DSX7eVsz.js → useProviders-q6iROeWE.js} +1 -1
- package/dist/ui/assets/{volume-x-qnVxkRSM.js → volume-x-Bm735CXN.js} +1 -1
- package/dist/ui/assets/{wifi-BA1m2dGO.js → wifi-DklBfOZ6.js} +1 -1
- package/dist/ui/assets/{zap-DT7cM7YS.js → zap-BEZNJ0i0.js} +1 -1
- package/dist/ui/index.html +8 -6
- package/dist/ui/logoblack.png +0 -0
- package/dist/ui/logocolor-dark.png +0 -0
- package/dist/ui/logocolorbg.png +0 -0
- package/dist/ui/logodoradobg.png +0 -0
- package/package.json +12 -8
- package/packages/cli/src/commands/doctor.ts +111 -0
- package/packages/cli/src/commands/onboard.ts +126 -59
- package/packages/cli/src/ui-bundle.generated.ts +9 -92
- package/packages/core/src/agent/acceptance-checks.ts +172 -0
- package/packages/core/src/agent/agent-catalog.ts +1 -37
- package/packages/core/src/agent/agent-loop.ts +21 -2
- package/packages/core/src/agent/catalog-selector.ts +0 -1
- package/packages/core/src/agent/compaction.ts +16 -1
- package/packages/core/src/agent/context-compiler.ts +3 -1
- package/packages/core/src/agent/conversation-store.ts +1 -1
- package/packages/core/src/agent/delegation-runtime.ts +1 -8
- package/packages/core/src/agent/goal-runner.ts +111 -32
- package/packages/core/src/agent/index.ts +1 -1
- package/packages/core/src/agent/llm-client.ts +34 -2
- package/packages/core/src/agent/llm-providers/anthropic.ts +10 -7
- package/packages/core/src/agent/llm-providers/interface.ts +13 -2
- package/packages/core/src/agent/llm-providers/modelscope.ts +5 -0
- package/packages/core/src/agent/llm-providers/z-ai.ts +5 -0
- package/packages/core/src/agent/minimal-loadout.ts +1 -0
- package/packages/core/src/agent/proof-packet.ts +2 -11
- package/packages/core/src/agent/providers/index.ts +1 -1
- package/packages/core/src/agent/tool-selector.ts +25 -1
- package/packages/core/src/canvas/emitter.ts +0 -44
- package/packages/core/src/channels/manager.ts +117 -25
- package/packages/core/src/channels/whatsapp.ts +6 -1
- package/packages/core/src/config/loader.ts +13 -1
- package/packages/core/src/events/channel-narration.ts +150 -0
- package/packages/core/src/events/tool-narration.ts +62 -0
- package/packages/core/src/gateway/channel-notify.ts +11 -7
- package/packages/core/src/gateway/delegation-groups.ts +24 -11
- package/packages/core/src/gateway/helpers/narration.ts +4 -62
- package/packages/core/src/gateway/helpers/ui-source.ts +67 -0
- package/packages/core/src/gateway/job-executors.ts +29 -67
- package/packages/core/src/gateway/resolver.ts +10 -2
- package/packages/core/src/gateway/routes/agents.ts +6 -6
- package/packages/core/src/gateway/routes/channels.ts +15 -1
- package/packages/core/src/gateway/routes/models.ts +69 -12
- package/packages/core/src/gateway/routes/providers.ts +110 -28
- package/packages/core/src/gateway/routes/setup.ts +63 -11
- package/packages/core/src/gateway/routes/system.ts +8 -5
- package/packages/core/src/gateway/routes/voice.ts +3 -0
- package/packages/core/src/gateway/server.ts +58 -28
- package/packages/core/src/gateway/webchat-turn.ts +29 -5
- package/packages/core/src/index.ts +1 -1
- package/packages/core/src/storage/bootstrap.ts +13 -9
- package/packages/core/src/storage/collections.ts +12 -46
- package/packages/core/src/storage/crypto.ts +147 -58
- package/packages/core/src/storage/hivedb.ts +9 -0
- package/packages/core/src/storage/model-id.ts +53 -0
- package/packages/core/src/storage/onboarding.ts +15 -4
- package/packages/core/src/storage/seed.ts +254 -138
- package/packages/core/src/storage/usage.ts +61 -123
- package/packages/core/src/tools/agents/index.ts +199 -27
- package/packages/core/src/tools/index.ts +2 -1
- package/packages/core/src/tools/web/browser-backend.ts +129 -0
- package/packages/core/src/tools/web/browser-service.ts +75 -35
- package/packages/core/src/tools/web/webview-backend.ts +412 -0
- package/packages/core/src/voice/index.ts +108 -17
- package/packages/skills/src/bundled/agents/task_orchestrator/SKILL.md +2 -1
- package/packages/skills/src/bundled-data.generated.ts +2 -23
- package/dist/ui/assets/AgentNewPage-CEkLeA79.js +0 -1
- package/dist/ui/assets/ProvidersPage-BupHs5yO.js +0 -1
- package/dist/ui/assets/arrow-left-0EBE7nsF.js +0 -1
- package/dist/ui/assets/arrow-right-5QIaph-z.js +0 -1
- package/dist/ui/assets/arrow-up-right-DQQCY007.js +0 -1
- package/dist/ui/assets/check-Dp6tzwax.js +0 -1
- package/dist/ui/assets/chevron-down-33N886NY.js +0 -1
- package/dist/ui/assets/chevron-left-C6itJXh3.js +0 -1
- package/dist/ui/assets/chevron-right-CFodBS-b.js +0 -1
- package/dist/ui/assets/chevron-up-BvSmyBEs.js +0 -1
- package/dist/ui/assets/circle-check-BJWNbLuF.js +0 -1
- package/dist/ui/assets/gauge-BRGwuN8G.js +0 -1
- package/dist/ui/assets/index-XoTT41Hr.css +0 -2
- package/dist/ui/assets/loader-circle-BhqRN2nO.js +0 -1
- package/dist/ui/assets/play-CfYDHD6h.js +0 -1
- package/dist/ui/assets/plus-C5BxJeOX.js +0 -1
- package/dist/ui/assets/search-rfBcmohK.js +0 -1
- package/dist/ui/assets/terminal-Bjfu-TkS.js +0 -1
- package/packages/core/src/agent/acceptance-verifier.ts +0 -300
- package/packages/skills/src/bundled/agents/acceptance_verification/SKILL.md +0 -26
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// ─── Tool narration map ───────────────────────────────────────────────────────
|
|
2
|
+
// Maps tool name prefixes/exact names to human-readable Spanish narrations.
|
|
3
|
+
// Shown to the user while the agent executes a tool.
|
|
4
|
+
const TOOL_NARRATIONS: Record<string, string> = {
|
|
5
|
+
// Web
|
|
6
|
+
web_search: "Buscando en la web...",
|
|
7
|
+
web_fetch: "Leyendo página web...",
|
|
8
|
+
// Files
|
|
9
|
+
read: "Leyendo archivo...",
|
|
10
|
+
write: "Escribiendo archivo...",
|
|
11
|
+
edit: "Editando archivo...",
|
|
12
|
+
exec: "Ejecutando comando...",
|
|
13
|
+
// Cron
|
|
14
|
+
"cron.create": "Programando tarea...",
|
|
15
|
+
"cron.list": "Consultando tareas programadas...",
|
|
16
|
+
"cron.update": "Actualizando tarea programada...",
|
|
17
|
+
"cron.delete": "Eliminando tarea programada...",
|
|
18
|
+
"cron.pause": "Pausando tarea programada...",
|
|
19
|
+
"cron.resume": "Reanudando tarea programada...",
|
|
20
|
+
"cron.trigger": "Ejecutando tarea ahora...",
|
|
21
|
+
"cron.history": "Consultando historial...",
|
|
22
|
+
// Agents
|
|
23
|
+
agent_create: "Creando agente worker...",
|
|
24
|
+
agent_find: "Buscando agente disponible...",
|
|
25
|
+
agent_archive: "Archivando agente...",
|
|
26
|
+
get_available_models: "Consultando modelos disponibles...",
|
|
27
|
+
task_delegate: "Delegando tarea a un agente...",
|
|
28
|
+
task_list: "Listando tareas en ejecución...",
|
|
29
|
+
task_status: "Consultando estado de la tarea...",
|
|
30
|
+
bus_publish: "Coordinando con otro agente...",
|
|
31
|
+
bus_read: "Leyendo mensajes de los agentes...",
|
|
32
|
+
// Discovery
|
|
33
|
+
search_knowledge: "Buscando capacidades disponibles...",
|
|
34
|
+
// Memory
|
|
35
|
+
save_note: "Guardando nota...",
|
|
36
|
+
memory_write: "Guardando en memoria...",
|
|
37
|
+
memory_read: "Leyendo memoria...",
|
|
38
|
+
memory_search: "Buscando en memoria...",
|
|
39
|
+
memory_delete: "Eliminando de memoria...",
|
|
40
|
+
memory_list: "Listando notas...",
|
|
41
|
+
// Browser
|
|
42
|
+
browser_navigate: "Navegando a la página...",
|
|
43
|
+
browser_click: "Haciendo clic...",
|
|
44
|
+
browser_type: "Escribiendo en la página...",
|
|
45
|
+
browser_screenshot: "Tomando captura de pantalla...",
|
|
46
|
+
browser_extract: "Extrayendo información de la página...",
|
|
47
|
+
// Canvas
|
|
48
|
+
canvas_add_node: "Actualizando canvas...",
|
|
49
|
+
canvas_update: "Actualizando canvas...",
|
|
50
|
+
// Notify
|
|
51
|
+
notify: "Enviando notificación...",
|
|
52
|
+
report_progress: "Reportando progreso...",
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function getNarration(toolName: string): string {
|
|
56
|
+
if (TOOL_NARRATIONS[toolName]) return TOOL_NARRATIONS[toolName]
|
|
57
|
+
// Prefix matching for MCP tools like "github__create_pr" → "Ejecutando github..."
|
|
58
|
+
const prefix = toolName.split("__")[0]
|
|
59
|
+
if (prefix && prefix !== toolName) return `Ejecutando ${prefix}...`
|
|
60
|
+
// Fallback
|
|
61
|
+
return `Ejecutando ${toolName.replace(/_/g, " ")}...`
|
|
62
|
+
}
|
|
@@ -19,7 +19,7 @@ type SendFn = (
|
|
|
19
19
|
channel: string,
|
|
20
20
|
sessionId: string,
|
|
21
21
|
message: string,
|
|
22
|
-
metadata?: { notificationId?: string },
|
|
22
|
+
metadata?: { notificationId?: string; accountId?: string },
|
|
23
23
|
) => Promise<void>
|
|
24
24
|
|
|
25
25
|
let _sendFn: SendFn | null = null
|
|
@@ -31,18 +31,22 @@ export function setChannelSendFn(fn: SendFn): void {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Resuelve el sessionId real (chat ID de Telegram, etc.) desde user_identities
|
|
34
|
+
* Resuelve el sessionId real (chat ID de Telegram, etc.) desde user_identities,
|
|
35
|
+
* junto con la cuenta del canal por la que llegó — con varias cuentas del mismo
|
|
36
|
+
* tipo conectadas, la respuesta debe salir por la misma.
|
|
35
37
|
* Necesario porque config.thread_id es el userId interno, no el chat ID externo.
|
|
36
38
|
*/
|
|
37
|
-
async function
|
|
39
|
+
async function resolveSession(userId: string, channel: string): Promise<{ sessionId: string; accountId?: string }> {
|
|
38
40
|
try {
|
|
39
41
|
const identitiesCol = await col<UserIdentityDoc>("userIdentities")
|
|
40
42
|
const identity = await identitiesCol.get(`${userId}:${channel}`)
|
|
41
|
-
if (identity?.doc.channel_user_id)
|
|
43
|
+
if (identity?.doc.channel_user_id) {
|
|
44
|
+
return { sessionId: identity.doc.channel_user_id, accountId: identity.doc.account_id }
|
|
45
|
+
}
|
|
42
46
|
} catch {
|
|
43
47
|
// DB no lista — fallback al userId
|
|
44
48
|
}
|
|
45
|
-
return userId
|
|
49
|
+
return { sessionId: userId }
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
/**
|
|
@@ -75,11 +79,11 @@ export async function sendToUserChannel(
|
|
|
75
79
|
return { ok: false, error: "Channel send not initialized" }
|
|
76
80
|
}
|
|
77
81
|
|
|
78
|
-
const sessionId = await
|
|
82
|
+
const { sessionId, accountId } = await resolveSession(userId, channel)
|
|
79
83
|
log.info(`[channel-notify] Sending to ${channel}/${sessionId}: ${message.substring(0, 80)}`)
|
|
80
84
|
|
|
81
85
|
try {
|
|
82
|
-
await _sendFn(channel, sessionId, message, { notificationId })
|
|
86
|
+
await _sendFn(channel, sessionId, message, { notificationId, accountId })
|
|
83
87
|
if (notificationId) await markNotificationDelivered(notificationId, userId)
|
|
84
88
|
return { ok: true, queued: false, notificationId }
|
|
85
89
|
} catch (err) {
|
|
@@ -106,22 +106,35 @@ function isComplete(group: DelegationGroupDoc): boolean {
|
|
|
106
106
|
return expected.size > 0 && [...expected].every((id) => completed.has(id));
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
function summarize(value: unknown, maxLen = 800): unknown {
|
|
110
|
+
if (typeof value !== "string") return value;
|
|
111
|
+
return value.length > maxLen ? `${value.slice(0, maxLen)}…` : value;
|
|
112
|
+
}
|
|
113
|
+
|
|
109
114
|
function summaryPrompt(group: DelegationGroupDoc): string {
|
|
110
|
-
const factual = outcomes(group).map((outcome) =>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
const factual = outcomes(group).map((outcome) => {
|
|
116
|
+
const result = outcome.result as { content?: unknown; acceptance?: unknown; checks?: { status?: string; summary?: string } } | null;
|
|
117
|
+
return {
|
|
118
|
+
task_id: outcome.task_id,
|
|
119
|
+
worker_id: outcome.worker_id,
|
|
120
|
+
task: outcome.task_name,
|
|
121
|
+
ok: outcome.ok,
|
|
122
|
+
content: summarize(result?.content ?? outcome.result),
|
|
123
|
+
acceptance: result?.acceptance ?? null,
|
|
124
|
+
checks: result?.checks ? { status: result.checks.status, summary: summarize(result.checks.summary) } : null,
|
|
125
|
+
error: outcome.error,
|
|
126
|
+
};
|
|
127
|
+
});
|
|
118
128
|
// No manual framing here — persisted with source:"delegation_summary" and
|
|
119
129
|
// framed at serialization time by formatInternalEvent (conversation-store.ts).
|
|
120
130
|
return [
|
|
121
131
|
"Todas las tareas delegadas de este turno alcanzaron estado terminal.",
|
|
122
|
-
"
|
|
123
|
-
|
|
124
|
-
"
|
|
132
|
+
"Para cada una, comprobá la entrega contra sus criterios de aceptación (`acceptance`):",
|
|
133
|
+
'- checks.status="passed" → verificado determinísticamente, aceptá.',
|
|
134
|
+
'- checks.status="failed" → NO cumplió (ok=false). No lo reportes como éxito.',
|
|
135
|
+
'- checks.status="unchecked" o ausente → juzgalo vos con el contenido y la evidencia adjunta.',
|
|
136
|
+
"Si una entrega no cumple sus criterios: usá `task_revise` con el task_id y un feedback concreto, o arreglala vos si es trivial y tenés las tools. No inventes trabajo ni evidencia, y no declares éxito para ok=false.",
|
|
137
|
+
"Si todas cumplen, escribí UNA sola respuesta final para el usuario, en lenguaje natural: nunca expongas task_id, worker_id, nombres de tools ni JSON crudo.",
|
|
125
138
|
JSON.stringify(factual),
|
|
126
139
|
].join("\n\n");
|
|
127
140
|
}
|
|
@@ -1,62 +1,4 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// Web
|
|
6
|
-
web_search: "Buscando en la web...",
|
|
7
|
-
web_fetch: "Leyendo página web...",
|
|
8
|
-
// Files
|
|
9
|
-
read: "Leyendo archivo...",
|
|
10
|
-
write: "Escribiendo archivo...",
|
|
11
|
-
edit: "Editando archivo...",
|
|
12
|
-
exec: "Ejecutando comando...",
|
|
13
|
-
// Cron
|
|
14
|
-
"cron.create": "Programando tarea...",
|
|
15
|
-
"cron.list": "Consultando tareas programadas...",
|
|
16
|
-
"cron.update": "Actualizando tarea programada...",
|
|
17
|
-
"cron.delete": "Eliminando tarea programada...",
|
|
18
|
-
"cron.pause": "Pausando tarea programada...",
|
|
19
|
-
"cron.resume": "Reanudando tarea programada...",
|
|
20
|
-
"cron.trigger": "Ejecutando tarea ahora...",
|
|
21
|
-
"cron.history": "Consultando historial...",
|
|
22
|
-
// Agents
|
|
23
|
-
agent_create: "Creando agente worker...",
|
|
24
|
-
agent_find: "Buscando agente disponible...",
|
|
25
|
-
agent_archive: "Archivando agente...",
|
|
26
|
-
get_available_models: "Consultando modelos disponibles...",
|
|
27
|
-
task_delegate: "Delegando tarea a un agente...",
|
|
28
|
-
task_list: "Listando tareas en ejecución...",
|
|
29
|
-
task_status: "Consultando estado de la tarea...",
|
|
30
|
-
bus_publish: "Coordinando con otro agente...",
|
|
31
|
-
bus_read: "Leyendo mensajes de los agentes...",
|
|
32
|
-
// Discovery
|
|
33
|
-
search_knowledge: "Buscando capacidades disponibles...",
|
|
34
|
-
// Memory
|
|
35
|
-
save_note: "Guardando nota...",
|
|
36
|
-
memory_write: "Guardando en memoria...",
|
|
37
|
-
memory_read: "Leyendo memoria...",
|
|
38
|
-
memory_search: "Buscando en memoria...",
|
|
39
|
-
memory_delete: "Eliminando de memoria...",
|
|
40
|
-
memory_list: "Listando notas...",
|
|
41
|
-
// Browser
|
|
42
|
-
browser_navigate: "Navegando a la página...",
|
|
43
|
-
browser_click: "Haciendo clic...",
|
|
44
|
-
browser_type: "Escribiendo en la página...",
|
|
45
|
-
browser_screenshot: "Tomando captura de pantalla...",
|
|
46
|
-
browser_extract: "Extrayendo información de la página...",
|
|
47
|
-
// Canvas
|
|
48
|
-
canvas_add_node: "Actualizando canvas...",
|
|
49
|
-
canvas_update: "Actualizando canvas...",
|
|
50
|
-
// Notify
|
|
51
|
-
notify: "Enviando notificación...",
|
|
52
|
-
report_progress: "Reportando progreso...",
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function getNarration(toolName: string): string {
|
|
56
|
-
if (TOOL_NARRATIONS[toolName]) return TOOL_NARRATIONS[toolName]
|
|
57
|
-
// Prefix matching for MCP tools like "github__create_pr" → "Ejecutando github..."
|
|
58
|
-
const prefix = toolName.split("__")[0]
|
|
59
|
-
if (prefix && prefix !== toolName) return `Ejecutando ${prefix}...`
|
|
60
|
-
// Fallback
|
|
61
|
-
return `Ejecutando ${toolName.replace(/_/g, " ")}...`
|
|
62
|
-
}
|
|
1
|
+
// The tool narration map lives in the narration domain (`events/`) so the agent
|
|
2
|
+
// loop can label its own events without depending on the gateway. Re-exported
|
|
3
|
+
// here to keep the existing `gateway/helpers` import path working.
|
|
4
|
+
export { getNarration } from "../../events/tool-narration.ts";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* De dónde sale la UI que sirve el gateway en producción.
|
|
6
|
+
*
|
|
7
|
+
* `disk` gana siempre que haya un `index.html` real, porque esa copia se
|
|
8
|
+
* construye en el mismo paso que la publica (la etapa `ui-builder` del
|
|
9
|
+
* Dockerfile, o `packages/hive-ui/dist` en el monorepo). `embedded` es el
|
|
10
|
+
* bundle que `generate-ui-bundle.ts` compila dentro del ejecutable standalone,
|
|
11
|
+
* que es la única forma de que un binario suelto tenga UI pero que también
|
|
12
|
+
* puede quedar viejo respecto del disco.
|
|
13
|
+
*/
|
|
14
|
+
export type UISource =
|
|
15
|
+
| { kind: "disk"; dir: string }
|
|
16
|
+
| { kind: "embedded" }
|
|
17
|
+
| { kind: "none"; dir: string };
|
|
18
|
+
|
|
19
|
+
export type UISourceInput = {
|
|
20
|
+
uiDirEnv?: string;
|
|
21
|
+
distDirEnv?: string;
|
|
22
|
+
hiveDir: string;
|
|
23
|
+
cwd: string;
|
|
24
|
+
hasEmbedded: boolean;
|
|
25
|
+
/** Inyectable para poder testear sin tocar el filesystem. */
|
|
26
|
+
exists?: (candidate: string) => boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Orden:
|
|
31
|
+
* HIVE_UI_DIR > bundle embebido > ~/.hive/ui > HIVE_DIST_DIR/ui > cwd/packages/hive-ui/dist
|
|
32
|
+
*
|
|
33
|
+
* La elección es una sola por request y no por path: mezclar dos fuentes
|
|
34
|
+
* serviría un `index.html` de un build con los `assets/index-<hash>.js` de otro.
|
|
35
|
+
*/
|
|
36
|
+
export function resolveUISource(input: UISourceInput): UISource {
|
|
37
|
+
const exists = input.exists ?? existsSync;
|
|
38
|
+
const hasIndex = (dir: string) => exists(path.join(dir, "index.html"));
|
|
39
|
+
|
|
40
|
+
// HIVE_UI_DIR es un override explícito y le gana al embed. Es lo que usa la
|
|
41
|
+
// imagen Docker, cuya etapa ui-builder compila la UI en cada build y la deja
|
|
42
|
+
// en /app/ui. Cuando el embed ganaba, el contenedor servía la copia que
|
|
43
|
+
// viajaba dentro del binario —commiteada y congelada— y /app/ui quedaba
|
|
44
|
+
// inerte.
|
|
45
|
+
if (input.uiDirEnv && hasIndex(input.uiDirEnv)) {
|
|
46
|
+
return { kind: "disk", dir: input.uiDirEnv };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// El embed va compilado dentro del ejecutable, así que siempre corresponde a
|
|
50
|
+
// su versión. Le gana a los directorios heredados: ~/.hive/ui puede haber
|
|
51
|
+
// quedado de una instalación anterior y taparía la UI del binario nuevo.
|
|
52
|
+
if (input.hasEmbedded) return { kind: "embedded" };
|
|
53
|
+
|
|
54
|
+
const fallbacks = [
|
|
55
|
+
path.join(input.hiveDir, "ui"),
|
|
56
|
+
input.distDirEnv ? path.join(input.distDirEnv, "ui") : undefined,
|
|
57
|
+
path.join(input.cwd, "packages/hive-ui/dist"),
|
|
58
|
+
].filter((dir): dir is string => Boolean(dir));
|
|
59
|
+
|
|
60
|
+
for (const dir of fallbacks) {
|
|
61
|
+
if (hasIndex(dir)) return { kind: "disk", dir };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Sin UI en ningún lado: se devuelve el candidato preferido para poder
|
|
65
|
+
// nombrarlo en el mensaje de error.
|
|
66
|
+
return { kind: "none", dir: input.uiDirEnv ?? fallbacks[0]! };
|
|
67
|
+
}
|
|
@@ -22,7 +22,7 @@ import { getDurableQueue } from "./durable-queue";
|
|
|
22
22
|
import { sendToUserChannel } from "./channel-notify";
|
|
23
23
|
import { verifyGoal } from "../agent/goal-runner";
|
|
24
24
|
import { buildProofPacket } from "../agent/proof-packet";
|
|
25
|
-
import {
|
|
25
|
+
import { runAcceptanceChecks, recordAgentOutcome } from "../agent/acceptance-checks";
|
|
26
26
|
import { prepareDelegation, type PreparedDelegation } from "../agent/delegation-runtime";
|
|
27
27
|
import { runWebchatTurn, type WebchatTurnPayload } from "./webchat-turn";
|
|
28
28
|
import { agentBus } from "../events/agent-bus";
|
|
@@ -32,11 +32,8 @@ import { publishNarration } from "../events/narration";
|
|
|
32
32
|
import {
|
|
33
33
|
emitDelegationStarted,
|
|
34
34
|
emitDelegationFinished,
|
|
35
|
-
emitVerificationStarted,
|
|
36
|
-
emitVerificationFinished,
|
|
37
35
|
emitWorkEvent,
|
|
38
36
|
} from "../canvas/emitter";
|
|
39
|
-
import { VERIFIER_AGENT_ID } from "../agent/acceptance-verifier";
|
|
40
37
|
|
|
41
38
|
const log = logger.child("job-executors");
|
|
42
39
|
|
|
@@ -174,44 +171,24 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
174
171
|
}
|
|
175
172
|
|
|
176
173
|
const finishedRun = runId ? await getRun(runId) : null;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
threadId: originThreadId,
|
|
181
|
-
channel: originChannel,
|
|
182
|
-
userId: originUserId,
|
|
183
|
-
sessionId: originSessionId,
|
|
184
|
-
agentId: workerId,
|
|
185
|
-
agentName: workerName,
|
|
186
|
-
kind: "verifying",
|
|
187
|
-
status: "running",
|
|
188
|
-
label: `El verificador está revisando la entrega de ${workerName}`,
|
|
189
|
-
dedupeKey: `verifying:${taskId ?? job.id}`,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
emitVerificationStarted({ verifierId: VERIFIER_AGENT_ID, workerId, taskRef: delegationRef, taskName });
|
|
193
|
-
const verification = await verifyAgentDelivery({
|
|
194
|
-
runId,
|
|
195
|
-
taskId,
|
|
196
|
-
executorAgentId: workerId,
|
|
174
|
+
const resolvedAcceptance = acceptance ?? (finishedRun ? deserializeAcceptance(finishedRun) : null);
|
|
175
|
+
const evidence = [result, ...execution.toolEvidence];
|
|
176
|
+
const checks = await runAcceptanceChecks({
|
|
197
177
|
objective: taskDescription,
|
|
198
|
-
acceptance:
|
|
178
|
+
acceptance: resolvedAcceptance,
|
|
199
179
|
delivery: result,
|
|
200
|
-
evidence
|
|
201
|
-
executorEpoch: finishedRun ? deserializeEpoch(finishedRun) : null,
|
|
202
|
-
mcpServerIds: prepared.mcpServerIds,
|
|
203
|
-
mcpManager,
|
|
180
|
+
evidence,
|
|
204
181
|
});
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
182
|
+
|
|
183
|
+
if (checks.status === "failed") {
|
|
184
|
+
await recordAgentOutcome(workerId, "harmful");
|
|
208
185
|
emitWorkEvent({
|
|
209
186
|
phase: "review_failed",
|
|
210
187
|
taskRef: delegationRef,
|
|
211
188
|
taskName,
|
|
212
|
-
actorId:
|
|
189
|
+
actorId: parentAgentId || workerId,
|
|
213
190
|
targetId: workerId,
|
|
214
|
-
detail:
|
|
191
|
+
detail: checks.summary,
|
|
215
192
|
});
|
|
216
193
|
if (turnId && originThreadId) {
|
|
217
194
|
await publishNarration({
|
|
@@ -224,29 +201,31 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
224
201
|
agentName: workerName,
|
|
225
202
|
kind: "failed",
|
|
226
203
|
status: "error",
|
|
227
|
-
label: `
|
|
228
|
-
detail:
|
|
204
|
+
label: `La entrega de ${workerName} no pasó los checks automáticos`,
|
|
205
|
+
detail: checks.summary,
|
|
229
206
|
dedupeKey: `verification_failed:${taskId ?? job.id}`,
|
|
230
207
|
});
|
|
231
208
|
}
|
|
232
209
|
if (taskId) {
|
|
233
210
|
await updateDoc<TaskDoc>("tasks", taskId, {
|
|
234
211
|
status: "blocked",
|
|
235
|
-
error:
|
|
212
|
+
error: checks.summary,
|
|
236
213
|
updated_at: Date.now(),
|
|
237
214
|
} as Partial<TaskDoc>).catch(() => {});
|
|
238
215
|
}
|
|
239
216
|
return {
|
|
240
217
|
ok: false,
|
|
241
|
-
error:
|
|
218
|
+
error: checks.summary,
|
|
242
219
|
retryable: false,
|
|
243
220
|
};
|
|
244
221
|
}
|
|
222
|
+
|
|
223
|
+
await recordAgentOutcome(workerId, "helpful");
|
|
245
224
|
emitWorkEvent({
|
|
246
225
|
phase: "review_passed",
|
|
247
226
|
taskRef: delegationRef,
|
|
248
227
|
taskName,
|
|
249
|
-
actorId:
|
|
228
|
+
actorId: parentAgentId || workerId,
|
|
250
229
|
targetId: workerId,
|
|
251
230
|
});
|
|
252
231
|
if (turnId && originThreadId) {
|
|
@@ -260,8 +239,8 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
260
239
|
agentName: workerName,
|
|
261
240
|
kind: "verified",
|
|
262
241
|
status: "done",
|
|
263
|
-
label:
|
|
264
|
-
detail:
|
|
242
|
+
label: `${workerName} completó “${taskName}”`,
|
|
243
|
+
detail: checks.status === "passed" ? checks.summary : "El coordinador revisa el resultado.",
|
|
265
244
|
dedupeKey: `verified:${taskId ?? job.id}`,
|
|
266
245
|
});
|
|
267
246
|
}
|
|
@@ -284,10 +263,9 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
284
263
|
agentId: workerId,
|
|
285
264
|
intendedOutcome: taskDescription,
|
|
286
265
|
met: true,
|
|
287
|
-
checksRun:
|
|
288
|
-
evidence
|
|
266
|
+
checksRun: checks.results.length ? checks.results.map((r) => r.check) : ["none"],
|
|
267
|
+
evidence,
|
|
289
268
|
epoch: finishedRun ? deserializeEpoch(finishedRun) : null,
|
|
290
|
-
verificationId: verification.id,
|
|
291
269
|
catalogAgentId: isCatalogAgent ? workerId : null,
|
|
292
270
|
});
|
|
293
271
|
|
|
@@ -304,7 +282,8 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
304
282
|
result: {
|
|
305
283
|
content: result,
|
|
306
284
|
evidence: execution.toolEvidence,
|
|
307
|
-
|
|
285
|
+
acceptance: resolvedAcceptance,
|
|
286
|
+
checks,
|
|
308
287
|
},
|
|
309
288
|
};
|
|
310
289
|
} catch (err) {
|
|
@@ -346,8 +325,6 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
346
325
|
|
|
347
326
|
return { ok: false, error: errorMsg, retryable: isRetryableError(err) };
|
|
348
327
|
} finally {
|
|
349
|
-
// Idempotente: cubre también el caso en que verifyAgentDelivery lance
|
|
350
|
-
emitVerificationFinished({ verifierId: VERIFIER_AGENT_ID, taskRef: delegationRef });
|
|
351
328
|
emitDelegationFinished({ workerId, taskRef: delegationRef });
|
|
352
329
|
await prepared?.release();
|
|
353
330
|
}
|
|
@@ -355,7 +332,8 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
355
332
|
|
|
356
333
|
// ─── goal_run executor ──────────────────────────────────────────────────────
|
|
357
334
|
// Multi-turn orchestration: run a turn → verify the goal → continue with the
|
|
358
|
-
// verifier's feedback until the goal is met or
|
|
335
|
+
// verifier's feedback (verifyGoal, goal-runner.ts) until the goal is met or
|
|
336
|
+
// the budget runs out. The goal
|
|
359
337
|
// AgentRun row (job.run_id) is the orchestrator record: goal_attempts,
|
|
360
338
|
// turns_used and tokens_used accumulate across turns and the budget is HARD.
|
|
361
339
|
// Turns are plain (non-durable) runs on the same thread — a mid-turn crash
|
|
@@ -454,8 +432,9 @@ const goalRunExecutor: JobExecutor = async (job, signal) => {
|
|
|
454
432
|
updated_at: Date.now(),
|
|
455
433
|
} as Partial<AgentRunDoc>).catch(() => {});
|
|
456
434
|
|
|
457
|
-
// Verify: deterministic tool when configured, LLM
|
|
458
|
-
// (
|
|
435
|
+
// Verify: deterministic tool when configured, a single LLM judgment
|
|
436
|
+
// otherwise (one call total, covering every acceptance criterion —
|
|
437
|
+
// see verifyGoal in goal-runner.ts).
|
|
459
438
|
const providerCfg = await resolveGoalProviderCfg(agentId);
|
|
460
439
|
const verdict = await verifyGoal(goal, checkTool, [
|
|
461
440
|
{ role: "user", content: `Meta: ${goal}` },
|
|
@@ -463,22 +442,6 @@ const goalRunExecutor: JobExecutor = async (job, signal) => {
|
|
|
463
442
|
], providerCfg, acceptance);
|
|
464
443
|
|
|
465
444
|
if (verdict.met) {
|
|
466
|
-
const independent = await verifyAgentDelivery({
|
|
467
|
-
runId: goalRunId,
|
|
468
|
-
executorAgentId: agentId,
|
|
469
|
-
objective: goal,
|
|
470
|
-
acceptance,
|
|
471
|
-
delivery: lastContent,
|
|
472
|
-
evidence: [verdict.reason],
|
|
473
|
-
executorEpoch: epoch,
|
|
474
|
-
mcpManager,
|
|
475
|
-
});
|
|
476
|
-
if (independent.status !== "verified") {
|
|
477
|
-
const independentVerdict = JSON.parse(independent.verdict_json);
|
|
478
|
-
lastReason = independentVerdict.summary || "La verificación independiente no autorizó el éxito.";
|
|
479
|
-
log.info(`[goal_run] Independent verifier rejected attempt ${attempts}: ${lastReason}`);
|
|
480
|
-
continue;
|
|
481
|
-
}
|
|
482
445
|
await completeRun(goalRunId, lastContent);
|
|
483
446
|
await notify(`✅ Meta cumplida: "${goal}". ${verdict.reason}`);
|
|
484
447
|
log.info(`[goal_run] Goal met after ${attempts} attempt(s): ${verdict.reason}`);
|
|
@@ -491,7 +454,6 @@ const goalRunExecutor: JobExecutor = async (job, signal) => {
|
|
|
491
454
|
checksRun: acceptance ? acceptance.map((a) => a.checkTool ?? "llm_verifier") : [checkTool ?? "llm_verifier"],
|
|
492
455
|
evidence: [verdict.reason, lastContent].filter(Boolean),
|
|
493
456
|
epoch,
|
|
494
|
-
verificationId: independent.id,
|
|
495
457
|
catalogAgentId: null,
|
|
496
458
|
});
|
|
497
459
|
return { ok: true, result: { met: true, attempts, reason: verdict.reason, content: lastContent } };
|
|
@@ -11,10 +11,12 @@ export interface ResolveContextResult {
|
|
|
11
11
|
export interface ResolveContextOptions {
|
|
12
12
|
channel: string
|
|
13
13
|
channelUserId: string
|
|
14
|
+
/** Channel account the message arrived on — persisted so replies can be routed back to it. */
|
|
15
|
+
accountId?: string
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export async function resolveContext(options: ResolveContextOptions): Promise<ResolveContextResult> {
|
|
17
|
-
const { channel, channelUserId } = options
|
|
19
|
+
const { channel, channelUserId, accountId } = options
|
|
18
20
|
|
|
19
21
|
const identitiesCol = await col<UserIdentityDoc>("userIdentities")
|
|
20
22
|
const usersCol = await col<UserDoc>("users")
|
|
@@ -28,6 +30,11 @@ export async function resolveContext(options: ResolveContextOptions): Promise<Re
|
|
|
28
30
|
|
|
29
31
|
if (identity) {
|
|
30
32
|
userId = identity.doc.user_id
|
|
33
|
+
// Backfill/refresh the owning account so replies survive a restart, when
|
|
34
|
+
// the in-memory session→account map in ChannelManager is empty.
|
|
35
|
+
if (accountId && identity.doc.account_id !== accountId) {
|
|
36
|
+
await identitiesCol.put(identity.id, { ...identity.doc, account_id: accountId })
|
|
37
|
+
}
|
|
31
38
|
} else {
|
|
32
39
|
// Sistema mono-usuario: reutilizar el usuario del onboarding
|
|
33
40
|
const allUsers = await usersCol.scan({})
|
|
@@ -43,7 +50,8 @@ export async function resolveContext(options: ResolveContextOptions): Promise<Re
|
|
|
43
50
|
// put(): si ya existe una fila (user_id, channel), actualiza channel_user_id
|
|
44
51
|
// con el valor real del canal (e.g. chat ID numérico de Telegram).
|
|
45
52
|
await identitiesCol.put(`${userId}:${channel}`, {
|
|
46
|
-
user_id: userId, channel, channel_user_id: channelUserId,
|
|
53
|
+
user_id: userId, channel, channel_user_id: channelUserId,
|
|
54
|
+
account_id: accountId, linked_at: Date.now(),
|
|
47
55
|
})
|
|
48
56
|
}
|
|
49
57
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { col, updateDoc, toIndexable, fromIndexable } from "../../storage/hive"
|
|
2
|
-
import type { AgentDoc, AgentProposalDoc, McpServerDoc, SkillDoc,
|
|
2
|
+
import type { AgentDoc, AgentProposalDoc, McpServerDoc, SkillDoc, TaskDoc, UserDoc } from "../../storage/collections"
|
|
3
3
|
import { emitCanvas } from "../../canvas/emitter"
|
|
4
4
|
import { storeAgentHeaders, deleteAgentSecrets } from "../../storage/crypto"
|
|
5
5
|
import { getDefaultLLM } from "../../agent/llm-client"
|
|
@@ -11,7 +11,7 @@ export async function handleGetAgents(req: Request, addCorsHeaders: (r: Response
|
|
|
11
11
|
|
|
12
12
|
const agentsCol = await col<AgentDoc>("agents")
|
|
13
13
|
const usersCol = await col<UserDoc>("users")
|
|
14
|
-
const
|
|
14
|
+
const tasksCol = await col<TaskDoc>("tasks")
|
|
15
15
|
const skillsCol = await col<SkillDoc>("skills")
|
|
16
16
|
const mcpServersCol = await col<McpServerDoc>("mcpServers")
|
|
17
17
|
const mcpServers = new Map(
|
|
@@ -49,11 +49,11 @@ export async function handleGetAgents(req: Request, addCorsHeaders: (r: Response
|
|
|
49
49
|
|
|
50
50
|
let lastVerification: { status: string; taskId: string; createdAt: number } | null = null
|
|
51
51
|
if (isCatalog) {
|
|
52
|
-
const
|
|
53
|
-
const latest =
|
|
54
|
-
?
|
|
52
|
+
const taskRows = await tasksCol.findBy("agent_id", row.doc.id)
|
|
53
|
+
const latest = taskRows.length
|
|
54
|
+
? taskRows.map(e => e.doc).sort((a, b) => b.updated_at - a.updated_at)[0]
|
|
55
55
|
: null
|
|
56
|
-
lastVerification = latest ? { status: latest.status, taskId: latest.
|
|
56
|
+
lastVerification = latest ? { status: latest.status, taskId: latest.id, createdAt: latest.updated_at } : null
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
return {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { col, updateDoc, toIndexable } from "../../storage/hive"
|
|
2
2
|
import type { ChannelDoc } from "../../storage/collections"
|
|
3
3
|
import { storeChannelConfig, loadChannelConfig, deleteChannelSecrets } from "../../storage/crypto"
|
|
4
|
+
import { invalidateNarrationModeCache, DEFAULT_NARRATION_MODE } from "../../events/channel-narration"
|
|
4
5
|
|
|
5
6
|
export async function handleGetChannels(
|
|
6
7
|
req: Request,
|
|
@@ -162,7 +163,7 @@ export async function handleCreateChannel(
|
|
|
162
163
|
await channelsCol.put(id, {
|
|
163
164
|
id, user_id: toIndexable(null), type, enabled: true, active: true, status: "connecting",
|
|
164
165
|
last_active: null, voice_enabled: false, tts_enabled: false, stt_provider: null, tts_provider: null,
|
|
165
|
-
tts_voice_id: null, step_delivery_mode:
|
|
166
|
+
tts_voice_id: null, step_delivery_mode: DEFAULT_NARRATION_MODE, vision_enabled: false,
|
|
166
167
|
ocr_provider: null, vision_provider: null, vision_model_id: null,
|
|
167
168
|
}, { expectedVersion: 0 });
|
|
168
169
|
}
|
|
@@ -340,6 +341,16 @@ export async function handleUpdateChannelSettings(
|
|
|
340
341
|
}
|
|
341
342
|
}
|
|
342
343
|
|
|
344
|
+
if ("step_delivery_mode" in patch) {
|
|
345
|
+
const mode = patch.step_delivery_mode;
|
|
346
|
+
if (mode !== "off" && mode !== "milestones" && mode !== "all") {
|
|
347
|
+
return addCorsHeaders(Response.json(
|
|
348
|
+
{ error: "step_delivery_mode must be one of: off, milestones, all" },
|
|
349
|
+
{ status: 400 }
|
|
350
|
+
), req);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
343
354
|
// Merge type-specific config into the secrets store if body.config is provided
|
|
344
355
|
const newConfig = body.config as Record<string, unknown> | undefined;
|
|
345
356
|
if (newConfig && typeof newConfig === "object" && Object.keys(newConfig).length > 0) {
|
|
@@ -355,6 +366,9 @@ export async function handleUpdateChannelSettings(
|
|
|
355
366
|
|
|
356
367
|
if (entry) {
|
|
357
368
|
await channelsCol.put(channelId, { ...entry.doc, ...patch }, { expectedVersion: entry.version });
|
|
369
|
+
// Narration delivery caches the mode per channel type — drop it so the new
|
|
370
|
+
// setting applies to the next turn instead of after the TTL.
|
|
371
|
+
if ("step_delivery_mode" in patch) invalidateNarrationModeCache(entry.doc.type);
|
|
358
372
|
}
|
|
359
373
|
|
|
360
374
|
return addCorsHeaders(Response.json({ success: true }), req);
|