@johpaz/hive-agents 1.0.2 → 1.0.3
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 +3 -3
- package/dist/hive.js +1014 -644
- package/dist/ui/assets/{A2UIPage-BRpjnMss.js → A2UIPage-DExwevBV.js} +1 -1
- package/dist/ui/assets/{AgentCreateForm-ASjKD7Js.js → AgentCreateForm-7PPShsUn.js} +1 -1
- package/dist/ui/assets/{AgentDetailPage-bqJ-MS40.js → AgentDetailPage-CiV4tz4P.js} +1 -1
- package/dist/ui/assets/AgentNewPage-D3TtVwQf.js +1 -0
- package/dist/ui/assets/{AgentsPage-BIpLG0V6.js → AgentsPage-C2DThet7.js} +1 -1
- package/dist/ui/assets/{ApiClientPage-dRckcgrN.js → ApiClientPage-Cowdq-0f.js} +1 -1
- package/dist/ui/assets/{ChannelsPage-BX_hPtiN.js → ChannelsPage-D4IgglwJ.js} +1 -1
- package/dist/ui/assets/{DashboardPage-KMaMaFf4.js → DashboardPage-DAgVB7Iy.js} +1 -1
- package/dist/ui/assets/{LoginPage-Zchu-f16.js → LoginPage-CpU61b3u.js} +1 -1
- package/dist/ui/assets/{LogsPage-6Po7_T2u.js → LogsPage-DyJOGQNy.js} +1 -1
- package/dist/ui/assets/{MeetingPage-qrpYGVD-.js → MeetingPage-DLmqHmm2.js} +1 -1
- package/dist/ui/assets/{ModelSelector-C8ny_pxu.js → ModelSelector-D4OaICwN.js} +1 -1
- package/dist/ui/assets/{Office3DPage-BYwLMTCl.js → Office3DPage-BvO66B0h.js} +1 -1
- package/dist/ui/assets/{ProvidersPage-DP9v_1ko.js → ProvidersPage-Bhb6Qr87.js} +1 -1
- package/dist/ui/assets/{RecoverPage-BXwjLfap.js → RecoverPage-DaZrCpdB.js} +1 -1
- package/dist/ui/assets/{SettingsPage-DD7GKtS6.js → SettingsPage-BRD2F7up.js} +1 -1
- package/dist/ui/assets/{SetupPage-D7YX2io-.js → SetupPage-DKppgTja.js} +1 -1
- package/dist/ui/assets/WebChatPage-CPtETNL5.js +29 -0
- package/dist/ui/assets/{activity-DZKL7dg4.js → activity-BSosMryb.js} +1 -1
- package/dist/ui/assets/{agentCapabilities-DuGs07XP.js → agentCapabilities-VqxLmrF6.js} +1 -1
- package/dist/ui/assets/arrow-left-C9Y6p4Jt.js +1 -0
- package/dist/ui/assets/arrow-right-BYfOLnTB.js +1 -0
- package/dist/ui/assets/arrow-up-right-D2trA3Ob.js +1 -0
- package/dist/ui/assets/{calendar-CkDsc4OJ.js → calendar-rdd4nvY1.js} +1 -1
- package/dist/ui/assets/check-DUq9uoNQ.js +1 -0
- package/dist/ui/assets/chevron-down-rPF4Pr1n.js +1 -0
- package/dist/ui/assets/chevron-left-Crzzf2sY.js +1 -0
- package/dist/ui/assets/chevron-right-DtMIvG9A.js +1 -0
- package/dist/ui/assets/chevron-up-CG0_KGBy.js +1 -0
- package/dist/ui/assets/{circle-alert-BkP6x0zQ.js → circle-alert-CYt6gsDA.js} +1 -1
- package/dist/ui/assets/circle-check-Zl32-jCa.js +1 -0
- package/dist/ui/assets/{circle-x-h4OJiHV3.js → circle-x-BJXzKGmx.js} +1 -1
- package/dist/ui/assets/{copy-BtpYEEvV.js → copy-BmtJXmDe.js} +1 -1
- package/dist/ui/assets/{dialog-CO1WrPJc.js → dialog-Dn9hGPYl.js} +1 -1
- package/dist/ui/assets/{download-aPuVaZik.js → download-D3mYhuuL.js} +1 -1
- package/dist/ui/assets/{earth-sc8YJMc0.js → earth-BZzdDXFC.js} +1 -1
- package/dist/ui/assets/{ellipsis-vertical-DEBZJGzY.js → ellipsis-vertical-BF705XvB.js} +1 -1
- package/dist/ui/assets/{external-link-D_C_678M.js → external-link-gdpMTHUV.js} +1 -1
- package/dist/ui/assets/{eye-BfN613fx.js → eye-lSG04hI7.js} +1 -1
- package/dist/ui/assets/{file-text-Bth5pPZX.js → file-text-CjQxcJvN.js} +1 -1
- package/dist/ui/assets/gauge-DBryKhDK.js +1 -0
- package/dist/ui/assets/{history-njH_sPSo.js → history-BC6ir9qU.js} +1 -1
- package/dist/ui/assets/{index-D-9yCvjP.js → index-DyxoAvTq.js} +2 -2
- package/dist/ui/assets/{info-Def2ZFeP.js → info-BGBaIyKc.js} +1 -1
- package/dist/ui/assets/{key-D8bkDl83.js → key-D_CNJTY2.js} +1 -1
- package/dist/ui/assets/loader-circle-RXdrfPsH.js +1 -0
- package/dist/ui/assets/{lock-open-Cdopbw1b.js → lock-open-UB61lorP.js} +1 -1
- package/dist/ui/assets/{mail-BQ_YA9_b.js → mail-C5bJ_dBt.js} +1 -1
- package/dist/ui/assets/{pause-CvS_LzKx.js → pause-BSTJvxDu.js} +1 -1
- package/dist/ui/assets/{pencil-C3tPvnCk.js → pencil-C2B1Q7y2.js} +1 -1
- package/dist/ui/assets/play-tcMbj-0p.js +1 -0
- package/dist/ui/assets/plus-BSZvyMND.js +1 -0
- package/dist/ui/assets/{radio-dsaiFxuT.js → radio-D9CrjAar.js} +1 -1
- package/dist/ui/assets/{refresh-cw-BmYQwOhh.js → refresh-cw-D7EB_fVv.js} +1 -1
- package/dist/ui/assets/search-5S6LY69I.js +1 -0
- package/dist/ui/assets/{select-BfRyBbi9.js → select-ot0a6art.js} +1 -1
- package/dist/ui/assets/{send-C3o2wpLi.js → send-Dax1tJ5b.js} +1 -1
- package/dist/ui/assets/{settings-DEpdBuf2.js → settings-97CL32lC.js} +1 -1
- package/dist/ui/assets/{shield-gbUkSqfi.js → shield-DwbCEZbF.js} +1 -1
- package/dist/ui/assets/{sparkles-Ccd1JZ3s.js → sparkles-CWMAzkpD.js} +1 -1
- package/dist/ui/assets/{square-BrwQ6Mun.js → square-B4dgTXI3.js} +1 -1
- package/dist/ui/assets/terminal-DoLedTPM.js +1 -0
- package/dist/ui/assets/{trash-2-CfCs7RhJ.js → trash-2-DxnVYOz8.js} +1 -1
- package/dist/ui/assets/{triangle-alert-C3lWSnRr.js → triangle-alert-Cka-BeIE.js} +1 -1
- package/dist/ui/assets/{useHiveAgentsModelLoad-D3s2U82M.js → useHiveAgentsModelLoad-BjnIsQKR.js} +1 -1
- package/dist/ui/assets/{useProviders-B3rT_xU9.js → useProviders-CueMz_mL.js} +1 -1
- package/dist/ui/assets/{volume-x-D2h9cyml.js → volume-x-DLsli9cf.js} +1 -1
- package/dist/ui/assets/{wifi-CGQECzu2.js → wifi-BQRJGfLZ.js} +1 -1
- package/dist/ui/assets/{zap-B1azpiE7.js → zap-DSR3CEce.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
- package/packages/core/src/agent/agent-loop.ts +29 -3
- package/packages/core/src/agent/context-compiler.ts +13 -2
- package/packages/core/src/agent/mcp-result-normalizer.ts +150 -0
- package/packages/core/src/agent/providers/index.ts +8 -0
- package/packages/core/src/artifacts/store.ts +16 -0
- package/packages/core/src/channels/base.ts +33 -0
- package/packages/core/src/channels/discord.ts +20 -1
- package/packages/core/src/channels/slack.ts +21 -2
- package/packages/core/src/channels/telegram.ts +16 -1
- package/packages/core/src/channels/whatsapp.ts +16 -3
- package/packages/core/src/gateway/durable-queue.ts +2 -1
- package/packages/core/src/gateway/failure-notify.ts +78 -0
- package/packages/core/src/gateway/job-executors.ts +1 -0
- package/packages/core/src/gateway/job-store.ts +6 -0
- package/packages/core/src/gateway/process-safety.ts +40 -0
- package/packages/core/src/gateway/routes/artifacts.ts +60 -0
- package/packages/core/src/gateway/server.ts +36 -5
- package/packages/core/src/gateway/webchat-turn.ts +40 -1
- package/packages/core/src/utils/redact-binary.ts +17 -0
- package/dist/ui/assets/AgentNewPage-CPaf2C3u.js +0 -1
- package/dist/ui/assets/WebChatPage-C3cgimxd.js +0 -29
- package/dist/ui/assets/arrow-left-12JaXVoH.js +0 -1
- package/dist/ui/assets/arrow-right-Dbui5p0d.js +0 -1
- package/dist/ui/assets/arrow-up-right-CJBtXRrp.js +0 -1
- package/dist/ui/assets/check-DxOMIDcl.js +0 -1
- package/dist/ui/assets/chevron-down-CObv-xyx.js +0 -1
- package/dist/ui/assets/chevron-left-C0mqwhLU.js +0 -1
- package/dist/ui/assets/chevron-right-jCt1h8Kw.js +0 -1
- package/dist/ui/assets/chevron-up-DX_5iw7O.js +0 -1
- package/dist/ui/assets/circle-check-CXC2AiMS.js +0 -1
- package/dist/ui/assets/gauge-DypSzSOE.js +0 -1
- package/dist/ui/assets/loader-circle-wLVzSdML.js +0 -1
- package/dist/ui/assets/play-C-oR-PMH.js +0 -1
- package/dist/ui/assets/plus-CF9No2td.js +0 -1
- package/dist/ui/assets/search-CTONpTyl.js +0 -1
- package/dist/ui/assets/terminal-DP9j3HjM.js +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* failure-notify — closes the durable queue's silent-failure gap for the
|
|
3
|
+
* user's own turns (chat_turn, goal_run).
|
|
4
|
+
*
|
|
5
|
+
* durable-queue.ts's terminal-hook mechanism only had one consumer before
|
|
6
|
+
* this: delegation-notify.ts's worker_task hook, which relays a *delegated*
|
|
7
|
+
* task's outcome back to the coordinator's conversation. Nothing told the
|
|
8
|
+
* user when their OWN chat turn or goal run failed for good with no live
|
|
9
|
+
* socket attached (a rehydrated turn after a crash, a job that exhausted its
|
|
10
|
+
* lease via reclaimOrInterrupt, etc.) — the job/run just sat in HiveDB as
|
|
11
|
+
* "failed", logged, and otherwise silent. From the user's side that reads as
|
|
12
|
+
* the system not responding at all, not as an explained error.
|
|
13
|
+
*
|
|
14
|
+
* Unlike delegation-notify.ts, this sends directly via sendToUserChannel
|
|
15
|
+
* instead of enqueueing another synthetic chat turn: the failure already
|
|
16
|
+
* happened inside a turn/goal run, so routing it back through another LLM
|
|
17
|
+
* turn would just risk failing the same way again. A plain, immediate
|
|
18
|
+
* message is the safer default here.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { logger } from "../utils/logger";
|
|
22
|
+
import { registerTerminalHook, type JobTerminalOutcome } from "./durable-queue";
|
|
23
|
+
import { sendToUserChannel } from "./channel-notify";
|
|
24
|
+
import { resolveContext } from "./resolver";
|
|
25
|
+
import { getRun } from "../agent/run-store";
|
|
26
|
+
import type { JobDoc } from "../storage/collections";
|
|
27
|
+
import type { WebchatTurnPayload } from "./webchat-turn";
|
|
28
|
+
|
|
29
|
+
const log = logger.child("failure-notify");
|
|
30
|
+
|
|
31
|
+
async function notifyChatTurnFailure(job: JobDoc, outcome: JobTerminalOutcome): Promise<void> {
|
|
32
|
+
if (outcome.ok) return; // success is delivered by runWebchatTurn itself
|
|
33
|
+
|
|
34
|
+
const payload = JSON.parse(job.payload_json) as WebchatTurnPayload;
|
|
35
|
+
const channel = payload.channel ?? "webchat";
|
|
36
|
+
let userId = payload.userId;
|
|
37
|
+
|
|
38
|
+
if (!userId) {
|
|
39
|
+
// Live webchat turns ("message"/"audio"/"a2ui") never carry userId in the
|
|
40
|
+
// payload — same resolution runWebchatTurn itself falls back to.
|
|
41
|
+
try {
|
|
42
|
+
const ctx = await resolveContext({ channel: "webchat", channelUserId: payload.sessionId });
|
|
43
|
+
userId = ctx.userId;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
log.warn(`[notifyChatTurnFailure] Could not resolve a recipient for job ${job.id}: ${(err as Error).message}`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
await sendToUserChannel(
|
|
51
|
+
channel,
|
|
52
|
+
userId,
|
|
53
|
+
"No pude completar tu solicitud por un error interno. Por favor intentá de nuevo."
|
|
54
|
+
).catch((err) => log.warn(`[notifyChatTurnFailure] Delivery failed for job ${job.id}: ${(err as Error).message}`));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function notifyGoalRunFailure(job: JobDoc, outcome: JobTerminalOutcome): Promise<void> {
|
|
58
|
+
if (outcome.ok) return; // goalRunExecutor already notifies success/budget-exhausted inline
|
|
59
|
+
|
|
60
|
+
const run = await getRun(job.run_id).catch(() => null);
|
|
61
|
+
if (!run?.channel || !run.user_id) return;
|
|
62
|
+
|
|
63
|
+
await sendToUserChannel(
|
|
64
|
+
run.channel,
|
|
65
|
+
run.user_id,
|
|
66
|
+
`No pude completar la tarea. Motivo: ${outcome.error ?? "error desconocido"}`
|
|
67
|
+
).catch((err) => log.warn(`[notifyGoalRunFailure] Delivery failed for job ${job.id}: ${(err as Error).message}`));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let initialized = false;
|
|
71
|
+
|
|
72
|
+
export function initFailureNotify(): void {
|
|
73
|
+
if (initialized) return;
|
|
74
|
+
registerTerminalHook("chat_turn", notifyChatTurnFailure);
|
|
75
|
+
registerTerminalHook("goal_run", notifyGoalRunFailure);
|
|
76
|
+
initialized = true;
|
|
77
|
+
log.info("[initFailureNotify] Registered chat_turn/goal_run terminal hooks");
|
|
78
|
+
}
|
|
@@ -464,6 +464,7 @@ const goalRunExecutor: JobExecutor = async (job, signal) => {
|
|
|
464
464
|
}
|
|
465
465
|
} catch (err) {
|
|
466
466
|
await failRun(goalRunId, (err as Error).message).catch(() => {});
|
|
467
|
+
await notify(`❌ No pude completar la meta: "${goal}". Error: ${(err as Error).message}`);
|
|
467
468
|
return { ok: false, error: (err as Error).message, retryable: isRetryableError(err) };
|
|
468
469
|
} finally {
|
|
469
470
|
stopLeaseRenewal(goalRunId);
|
|
@@ -337,6 +337,12 @@ export async function reclaimOrInterrupt(jobId: string, opts?: { force?: boolean
|
|
|
337
337
|
try {
|
|
338
338
|
await c.put(jobId, updated, { expectedVersion: entry.version });
|
|
339
339
|
log.warn(`[reclaimOrInterrupt] Job ${jobId} interrupted (attempts exhausted)`);
|
|
340
|
+
// Terminal via lease-expiry, not executeJob's normal fail path — that
|
|
341
|
+
// path already fires the hook, this one didn't before. Dynamic import
|
|
342
|
+
// avoids a static circular import (durable-queue.ts imports
|
|
343
|
+
// reclaimOrInterrupt from this module).
|
|
344
|
+
const { runTerminalHook } = await import("./durable-queue");
|
|
345
|
+
await runTerminalHook(updated, { ok: false, error: updated.error ?? "Job interrupted after lease expiry" }).catch(() => {});
|
|
340
346
|
return updated;
|
|
341
347
|
} catch {
|
|
342
348
|
await occRetryDelay(attempt);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* process-safety — last-resort net for exceptions nothing else caught.
|
|
3
|
+
*
|
|
4
|
+
* Confirmed by exhaustive grep: before this, packages/core/src had no
|
|
5
|
+
* process.on("uncaughtException"/"unhandledRejection") handler anywhere.
|
|
6
|
+
* Bun/Node's default behavior for a truly uncaught exception is to kill the
|
|
7
|
+
* process immediately with just a stack trace on stdout — no attempt to
|
|
8
|
+
* notify anyone, no clean shutdown.
|
|
9
|
+
*
|
|
10
|
+
* This does NOT try to keep the process alive after a fatal error — doing
|
|
11
|
+
* that would mask real bugs and can leave the process in an inconsistent
|
|
12
|
+
* state (leases not released, locks not freed). It only guarantees the crash
|
|
13
|
+
* is loud (max-severity log line) and the shutdown is a clean, fast exit
|
|
14
|
+
* instead of an undefined one. The rest of the story is handled by existing
|
|
15
|
+
* machinery: reconcileOnBoot (storage/reconcile.ts) already notifies the user
|
|
16
|
+
* for interrupted chat runs when the process comes back up, and the process
|
|
17
|
+
* supervisor (systemd/pm2/docker) is expected to restart it.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { logger } from "../utils/logger";
|
|
21
|
+
|
|
22
|
+
const log = logger.child("process-safety");
|
|
23
|
+
|
|
24
|
+
let installed = false;
|
|
25
|
+
|
|
26
|
+
export function installProcessSafetyNet(): void {
|
|
27
|
+
if (installed) return;
|
|
28
|
+
installed = true;
|
|
29
|
+
|
|
30
|
+
const handleFatal = (err: unknown, origin: string) => {
|
|
31
|
+
const detail = err instanceof Error ? (err.stack ?? err.message) : String(err);
|
|
32
|
+
log.error(`[process-safety] FATAL ${origin} — process exiting: ${detail}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
process.on("uncaughtException", (err) => handleFatal(err, "uncaughtException"));
|
|
37
|
+
process.on("unhandledRejection", (err) => handleFatal(err, "unhandledRejection"));
|
|
38
|
+
|
|
39
|
+
log.info("[process-safety] Installed uncaughtException/unhandledRejection safety net");
|
|
40
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* routes/artifacts — serves artifact binaries (images generated by MCP
|
|
3
|
+
* tools, screenshots, etc.) created by artifacts/store.ts's createArtifact().
|
|
4
|
+
*
|
|
5
|
+
* Follows the same shape as routes/meeting.ts's handleDownloadMeetingReport:
|
|
6
|
+
* resolve metadata, stream the file from disk with the right Content-Type.
|
|
7
|
+
* Hive is single-tenant behind one bearer token (see startGateway's
|
|
8
|
+
* HIVE_AUTH_TOKEN gate) — same as meeting downloads, no per-user ownership
|
|
9
|
+
* check is layered on top here; inspectArtifact still enforces expiry and
|
|
10
|
+
* that the file on disk matches its recorded hash/size.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { logger } from "../../utils/logger";
|
|
14
|
+
import { col } from "../../storage/hive";
|
|
15
|
+
import type { ArtifactDoc } from "../../storage/collections";
|
|
16
|
+
import { inspectArtifact } from "../../artifacts/store";
|
|
17
|
+
|
|
18
|
+
const log = logger.child("routes/artifacts");
|
|
19
|
+
|
|
20
|
+
type CorsHelper = (r: Response, req: Request) => Response;
|
|
21
|
+
|
|
22
|
+
export async function handleDownloadArtifact(
|
|
23
|
+
req: Request,
|
|
24
|
+
addCorsHeaders: CorsHelper,
|
|
25
|
+
artifactId: string,
|
|
26
|
+
): Promise<Response> {
|
|
27
|
+
try {
|
|
28
|
+
const meta = await inspectArtifact(artifactId);
|
|
29
|
+
if (!meta.ok) {
|
|
30
|
+
return addCorsHeaders(Response.json(meta, { status: 404 }), req);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const artifactsCol = await col<ArtifactDoc>("artifacts");
|
|
34
|
+
const entry = await artifactsCol.get(artifactId);
|
|
35
|
+
if (!entry) {
|
|
36
|
+
return addCorsHeaders(Response.json({ ok: false, error: "Artifact not found" }, { status: 404 }), req);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const file = Bun.file(entry.doc.path);
|
|
40
|
+
if (!(await file.exists())) {
|
|
41
|
+
return addCorsHeaders(Response.json({ ok: false, error: "Artifact binary is missing" }, { status: 404 }), req);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return addCorsHeaders(
|
|
45
|
+
new Response(file, {
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": entry.doc.mime_type,
|
|
48
|
+
"Cache-Control": "private, max-age=3600",
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
req,
|
|
52
|
+
);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
log.error(`handleDownloadArtifact: ${(error as Error).message}`);
|
|
55
|
+
return addCorsHeaders(
|
|
56
|
+
Response.json({ ok: false, error: (error as Error).message }, { status: 500 }),
|
|
57
|
+
req,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -30,6 +30,8 @@ import { shutdownToolRuntime } from "../tool-runtime";
|
|
|
30
30
|
import { initDurableQueue, getDurableQueue } from "./durable-queue";
|
|
31
31
|
import { initJobExecutors, setJobExecutorMCPManager } from "./job-executors";
|
|
32
32
|
import { initDelegationNotify } from "./delegation-notify";
|
|
33
|
+
import { initFailureNotify } from "./failure-notify";
|
|
34
|
+
import { installProcessSafetyNet } from "./process-safety";
|
|
33
35
|
import { findAllPendingJobs, findExpiredLeases, loadJobRetryPolicy } from "./job-store";
|
|
34
36
|
import type { UserDoc, AgentDoc } from "../storage/collections";
|
|
35
37
|
import { canvasManager } from "../canvas/canvas-manager.ts";
|
|
@@ -92,6 +94,7 @@ import { handleGetVoiceProviders, handleGetConfiguredVoiceProviders, handleSaveV
|
|
|
92
94
|
import { handleGetVisionProviders, handleGetChannelVision, handleUpdateChannelVision, handleOcrImage } from "./routes/multimodal";
|
|
93
95
|
import { handleGetLocalTTSStatus, handleGetLocalTTSLogs, handleInstallLocalTTS, handleStartLocalTTS, handleStopLocalTTS, handleSpeakLocalTTS, handleGetAvailableModels, handleGetInstalledVoices, handleDownloadModel, handleGetDownloadLogs, initializeLocalTTS } from "./routes/tts-local";
|
|
94
96
|
import { handleCreateMeeting, handleListMeetings, handleGetMeeting, handleAddMeetingSegment, handleStopMeeting, handleGenerateMeetingReport, handleDownloadMeetingReport } from "./routes/meeting";
|
|
97
|
+
import { handleDownloadArtifact } from "./routes/artifacts";
|
|
95
98
|
import { handleGetActivityStats, handleGetSystemStats, handleGetUsageStats, handleSystemReload, handleApiReload, handleGetVersion, handleTriggerUpdate } from "./routes/system";
|
|
96
99
|
import { handleGetChatHistory, handleGetNotes, handleUpdateNote } from "./routes/chat";
|
|
97
100
|
import { handleChat as handlePostChat } from "./routes/chat";
|
|
@@ -135,6 +138,11 @@ export async function startGateway(
|
|
|
135
138
|
|
|
136
139
|
const log = logger.child("gateway");
|
|
137
140
|
|
|
141
|
+
// Installed first, before anything else can throw: an exception no catch
|
|
142
|
+
// block reaches should crash loudly and exit cleanly, not hang silently
|
|
143
|
+
// (see process-safety.ts).
|
|
144
|
+
installProcessSafetyNet();
|
|
145
|
+
|
|
138
146
|
log.info(`Starting gateway on ${host}:${port}`);
|
|
139
147
|
|
|
140
148
|
// ── Auto-generate auth token if not provided ─────────────────────────────
|
|
@@ -291,6 +299,9 @@ export async function startGateway(
|
|
|
291
299
|
// Closes the async task_delegate loop: relays worker_task outcomes
|
|
292
300
|
// back into the delegating conversation (see delegation-notify.ts).
|
|
293
301
|
initDelegationNotify();
|
|
302
|
+
// Never let a chat_turn/goal_run fail without telling the user (see
|
|
303
|
+
// failure-notify.ts) — previously only worker_task had a terminal hook.
|
|
304
|
+
initFailureNotify();
|
|
294
305
|
log.info(`🔀 DurableQueue initialized (maxConcurrency=${durableQueue.getMaxGlobalConcurrency()})`);
|
|
295
306
|
|
|
296
307
|
// Create and boot scheduler
|
|
@@ -614,6 +625,11 @@ export async function startGateway(
|
|
|
614
625
|
}
|
|
615
626
|
log.info(`📤 LLM response: ${responseContent.substring(0, 100)}${responseContent.length > 100 ? "..." : ""}`);
|
|
616
627
|
|
|
628
|
+
// Image artifacts (e.g. an MCP image-generation tool's result — see
|
|
629
|
+
// mcp-result-normalizer.ts) produced this turn, most recent first channel
|
|
630
|
+
// send only carries one at a time for now.
|
|
631
|
+
const imageArtifact = response.imageArtifacts?.[response.imageArtifacts.length - 1];
|
|
632
|
+
|
|
617
633
|
// Narration is delivered off the critical path — let it drain first so the
|
|
618
634
|
// final answer lands after the progress messages, not before them.
|
|
619
635
|
await awaitChannelNarration(`${message.channel}:${routingSessionId}`);
|
|
@@ -622,13 +638,17 @@ export async function startGateway(
|
|
|
622
638
|
let responseType: "text" | "audio" = "text";
|
|
623
639
|
let ttsProviderUsed: string | null = null;
|
|
624
640
|
let ttsMimeType: string | null = null;
|
|
641
|
+
const imageField = imageArtifact
|
|
642
|
+
? { image: { artifactId: imageArtifact.artifactId, mimeType: imageArtifact.mimeType } }
|
|
643
|
+
: {};
|
|
625
644
|
|
|
626
645
|
if (responseContent) {
|
|
627
646
|
if (shouldSpeak) {
|
|
628
647
|
if (!voiceConfig.ttsProvider) {
|
|
629
648
|
log.warn(`⚠️ TTS provider not configured, user requested audio`);
|
|
630
649
|
await channelManager.send(message.channel, routingSessionId, {
|
|
631
|
-
content: `${responseContent}\n\n🔊 Para recibir respuestas en audio, configura el proveedor TTS en Configuración > Canales > [Tu canal] (ej: elevenlabs, openai-tts)
|
|
650
|
+
content: `${responseContent}\n\n🔊 Para recibir respuestas en audio, configura el proveedor TTS en Configuración > Canales > [Tu canal] (ej: elevenlabs, openai-tts)`,
|
|
651
|
+
...imageField,
|
|
632
652
|
});
|
|
633
653
|
} else {
|
|
634
654
|
try {
|
|
@@ -643,22 +663,27 @@ export async function startGateway(
|
|
|
643
663
|
if (channel?.sendAudio) {
|
|
644
664
|
await channel.sendAudio(routingSessionId, audioOutput.data as Buffer, audioOutput.mimeType);
|
|
645
665
|
log.info(`✅ Audio sent to ${routingSessionId}`);
|
|
666
|
+
// sendAudio() is a dedicated binary path, separate from
|
|
667
|
+
// send(OutboundMessage) — the image needs its own send() call.
|
|
668
|
+
if (imageArtifact) {
|
|
669
|
+
await channelManager.send(message.channel, routingSessionId, { content: "", ...imageField });
|
|
670
|
+
}
|
|
646
671
|
} else {
|
|
647
672
|
log.warn(`Channel ${message.channel} does not support audio, sending text`);
|
|
648
|
-
await channelManager.send(message.channel, routingSessionId, { content: responseContent });
|
|
673
|
+
await channelManager.send(message.channel, routingSessionId, { content: responseContent, ...imageField });
|
|
649
674
|
}
|
|
650
675
|
} catch (audioError) {
|
|
651
676
|
log.error(`❌ Audio send failed: ${(audioError as Error).message}, sending text instead`);
|
|
652
677
|
// Fallback to text
|
|
653
|
-
await channelManager.send(message.channel, routingSessionId, { content: responseContent });
|
|
678
|
+
await channelManager.send(message.channel, routingSessionId, { content: responseContent, ...imageField });
|
|
654
679
|
}
|
|
655
680
|
} catch (ttsError) {
|
|
656
681
|
log.error(`❌ TTS failed: ${(ttsError as Error).message}, sending text instead`);
|
|
657
|
-
await channelManager.send(message.channel, routingSessionId, { content: responseContent });
|
|
682
|
+
await channelManager.send(message.channel, routingSessionId, { content: responseContent, ...imageField });
|
|
658
683
|
}
|
|
659
684
|
}
|
|
660
685
|
} else {
|
|
661
|
-
await channelManager.send(message.channel, routingSessionId, { content: responseContent });
|
|
686
|
+
await channelManager.send(message.channel, routingSessionId, { content: responseContent, ...imageField });
|
|
662
687
|
}
|
|
663
688
|
}
|
|
664
689
|
|
|
@@ -1888,6 +1913,12 @@ export async function startGateway(
|
|
|
1888
1913
|
return await handleDownloadMeetingReport(req, addCorsHeaders, meetingReportDownloadMatch[1]);
|
|
1889
1914
|
}
|
|
1890
1915
|
|
|
1916
|
+
// ── Artifacts (MCP tool binaries: images, screenshots, etc.) ─────────
|
|
1917
|
+
const artifactDownloadMatch = url.pathname.match(/^\/api\/artifacts\/([^/]+)\/download$/);
|
|
1918
|
+
if (artifactDownloadMatch && req.method === "GET") {
|
|
1919
|
+
return await handleDownloadArtifact(req, addCorsHeaders, artifactDownloadMatch[1]);
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1891
1922
|
// ── Chat / Notes API ────────────────────────────────────────────────
|
|
1892
1923
|
if (url.pathname === "/api/chat/history" && req.method === "GET") {
|
|
1893
1924
|
return await handleGetChatHistory(req, addCorsHeaders)
|
|
@@ -54,7 +54,12 @@ export interface WebchatTurnLive {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export interface WebchatTurnDeps {
|
|
57
|
-
runner: {
|
|
57
|
+
runner: {
|
|
58
|
+
generate: (opts: any) => Promise<{
|
|
59
|
+
content?: string;
|
|
60
|
+
imageArtifacts?: Array<{ artifactId: string; mimeType: string }>;
|
|
61
|
+
}>;
|
|
62
|
+
};
|
|
58
63
|
getProvider: () => string;
|
|
59
64
|
getModel: () => string;
|
|
60
65
|
}
|
|
@@ -454,6 +459,40 @@ export async function runWebchatTurn(
|
|
|
454
459
|
}
|
|
455
460
|
}
|
|
456
461
|
|
|
462
|
+
// ── Image artifacts (e.g. an MCP image-generation tool's result) ─────────
|
|
463
|
+
// Sent as a trailing frame regardless of which content/audio branch above
|
|
464
|
+
// ran — decouples the (already-branchy) text/TTS delivery logic from
|
|
465
|
+
// whether this turn happened to also produce an image. Points at the
|
|
466
|
+
// artifacts download endpoint (routes/artifacts.ts) rather than
|
|
467
|
+
// re-inflating base64 into the WS payload — the whole point of
|
|
468
|
+
// materializing it as an artifact in the first place (see
|
|
469
|
+
// mcp-result-normalizer.ts) was to keep it out of large payloads.
|
|
470
|
+
if (response.imageArtifacts?.length) {
|
|
471
|
+
const img = response.imageArtifacts[response.imageArtifacts.length - 1];
|
|
472
|
+
const imageFrame = JSON.stringify({
|
|
473
|
+
type: "message",
|
|
474
|
+
id: messageId,
|
|
475
|
+
sessionId,
|
|
476
|
+
content: "",
|
|
477
|
+
image: `/api/artifacts/${img.artifactId}/download`,
|
|
478
|
+
imageMimeType: img.mimeType,
|
|
479
|
+
isStep: false,
|
|
480
|
+
});
|
|
481
|
+
if (hasLive) {
|
|
482
|
+
sendRaw(imageFrame);
|
|
483
|
+
} else {
|
|
484
|
+
const liveSession = channel === "webchat" ? sessionManager.get(sessionId) : undefined;
|
|
485
|
+
const liveWs = liveSession?.ws?.readyState === 1 ? liveSession.ws : null;
|
|
486
|
+
if (liveWs) {
|
|
487
|
+
try { liveWs.send(imageFrame); } catch { /* socket gone, best effort */ }
|
|
488
|
+
}
|
|
489
|
+
// No live socket at all (crash recovery / async notification path):
|
|
490
|
+
// image delivery there is out of scope for now — sendToUserChannel
|
|
491
|
+
// only carries plain text. The artifact itself is still safely
|
|
492
|
+
// persisted and inspectable (artifact_inspect) either way.
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
457
496
|
if (delegationGroup) {
|
|
458
497
|
processReporter?.pending();
|
|
459
498
|
} else {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* redact-binary — last-line-of-defense redaction for stray base64 blobs.
|
|
3
|
+
*
|
|
4
|
+
* mcp-result-normalizer.ts (agent/mcp-result-normalizer.ts) is the real fix:
|
|
5
|
+
* it intercepts MCP image/audio/resource content blocks before they ever
|
|
6
|
+
* reach a string. This utility is the safety net for whatever slips past
|
|
7
|
+
* that — a producer that isn't MCP, a content shape normalizeMcpResult
|
|
8
|
+
* doesn't recognize, etc. Never rely on this alone to keep binaries out of
|
|
9
|
+
* the LLM context.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const DATA_URI_RE = /data:[a-z0-9.+-]+\/[a-z0-9.+-]+;base64,[a-z0-9+/=\s]+/gi;
|
|
13
|
+
const LONG_BASE64_RE = /[A-Za-z0-9+/]{1000,}={0,2}/g;
|
|
14
|
+
|
|
15
|
+
export function redactBinaryStrings(text: string): string {
|
|
16
|
+
return text.replace(DATA_URI_RE, "[REDACTED_BINARY]").replace(LONG_BASE64_RE, "[REDACTED_BINARY]");
|
|
17
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./vendor-query-Dj8xYhQD.js";import{t}from"./AgentCreateForm-ASjKD7Js.js";var n=e();function r(){return(0,n.jsx)(t,{})}export{r as AgentNewPage};
|