@johpaz/hive-agents 1.0.2 → 1.0.4
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 +4 -4
- package/dist/hive.js +46386 -45716
- package/dist/ui/assets/A2UIPage-7Ry5rHh9.js +8 -0
- package/dist/ui/assets/AgentCreateForm-Dh5W0q_t.js +1 -0
- package/dist/ui/assets/AgentDetailPage-CIoPjtsS.js +1 -0
- package/dist/ui/assets/AgentNewPage-BNsZcJQf.js +1 -0
- package/dist/ui/assets/AgentsPage-YZrDmgNI.js +10 -0
- package/dist/ui/assets/ApiClientPage-6a6KFwsQ.js +3 -0
- package/dist/ui/assets/ChannelsPage-Dice4dkJ.js +8 -0
- package/dist/ui/assets/DashboardPage-B9r0sc0F.js +6 -0
- package/dist/ui/assets/LoginPage-BkAAX_tu.js +1 -0
- package/dist/ui/assets/{LogsPage-6Po7_T2u.js → LogsPage-8-H1OJs3.js} +1 -1
- package/dist/ui/assets/MeetingPage-14JoQo71.js +1 -0
- package/dist/ui/assets/ModelSelector-CrgJQ7DG.js +1 -0
- package/dist/ui/assets/{NotFound-Bpr12V51.js → NotFound-B06kVW7N.js} +1 -1
- package/dist/ui/assets/{Office3DPage-BYwLMTCl.js → Office3DPage-BMUZWkFS.js} +2 -2
- package/dist/ui/assets/ProvidersPage-BiL3QxCs.js +1 -0
- package/dist/ui/assets/RecoverPage-D1o8yxNz.js +1 -0
- package/dist/ui/assets/SettingsPage-GP8UwQIL.js +9 -0
- package/dist/ui/assets/SetupPage-B_gU1YQU.js +1 -0
- package/dist/ui/assets/WebChatPage-Yahufnth.js +29 -0
- package/dist/ui/assets/activity-C_GS5wrG.js +1 -0
- package/dist/ui/assets/agentCapabilities-Dg72UAFj.js +1 -0
- package/dist/ui/assets/{alert-CQlRq6sv.js → alert-DChoEVJw.js} +1 -1
- package/dist/ui/assets/arrow-left-WyDPYZXU.js +1 -0
- package/dist/ui/assets/arrow-right-BuNjN-bk.js +1 -0
- package/dist/ui/assets/arrow-up-right-DWzTsCXj.js +1 -0
- package/dist/ui/assets/{badge-DKGZbVZJ.js → badge-uRjRSt86.js} +1 -1
- package/dist/ui/assets/calendar-B6x9cw-q.js +1 -0
- package/dist/ui/assets/{card-D3Nw3kh3.js → card-DwQizslL.js} +1 -1
- package/dist/ui/assets/check-C8pw-7Fx.js +1 -0
- package/dist/ui/assets/chevron-down-8GjmTjLR.js +1 -0
- package/dist/ui/assets/chevron-left-GK4EQOyZ.js +1 -0
- package/dist/ui/assets/chevron-right-BupZqrxu.js +1 -0
- package/dist/ui/assets/chevron-up-DZrzJIW8.js +1 -0
- package/dist/ui/assets/circle-alert-CtDbK2nl.js +1 -0
- package/dist/ui/assets/circle-check-BKNT2_q6.js +1 -0
- package/dist/ui/assets/circle-x-DfBjbztU.js +1 -0
- package/dist/ui/assets/copy-wR7o7Ly8.js +1 -0
- package/dist/ui/assets/core-Sjunb8Z1.js +1 -0
- package/dist/ui/assets/createLucideIcon-BRaPSYgN.js +1 -0
- package/dist/ui/assets/{dialog-CO1WrPJc.js → dialog--mljnfAi.js} +1 -1
- package/dist/ui/assets/dist-js-B0s_TDau.js +1 -0
- package/dist/ui/assets/dist-js-CLxM1g2B.js +1 -0
- package/dist/ui/assets/download-D0aDV8Y_.js +1 -0
- package/dist/ui/assets/earth-BJRGJbVn.js +1 -0
- package/dist/ui/assets/ellipsis-vertical-BOW_iEOO.js +1 -0
- package/dist/ui/assets/external-link-5cujQzfV.js +1 -0
- package/dist/ui/assets/eye-sRPY5qOa.js +1 -0
- package/dist/ui/assets/file-text-DNSyNLUh.js +1 -0
- package/dist/ui/assets/gauge-C__zxC3_.js +1 -0
- package/dist/ui/assets/history-BHQWfE-7.js +1 -0
- package/dist/ui/assets/index-BHHUQZJd.js +116 -0
- package/dist/ui/assets/index-CEFhf4dF.css +2 -0
- package/dist/ui/assets/info-CG1VohyH.js +1 -0
- package/dist/ui/assets/key-BC28VCjO.js +1 -0
- package/dist/ui/assets/{label-k0jYxoWW.js → label-BceoUB2w.js} +1 -1
- package/dist/ui/assets/lock-open-Bhp0UJlL.js +1 -0
- package/dist/ui/assets/mail-Biwn8WrV.js +1 -0
- package/dist/ui/assets/pause-C2l5G2Py.js +1 -0
- package/dist/ui/assets/pencil-CUbpCfeG.js +1 -0
- package/dist/ui/assets/play-CMAscR3a.js +1 -0
- package/dist/ui/assets/plus-DzvRxH4U.js +1 -0
- package/dist/ui/assets/radio-DfGzov4y.js +1 -0
- package/dist/ui/assets/refresh-cw-DZXu5FrG.js +1 -0
- package/dist/ui/assets/scroll-area-DMEaZZUp.js +1 -0
- package/dist/ui/assets/search-ykSx-zZU.js +1 -0
- package/dist/ui/assets/{select-BfRyBbi9.js → select-BBEBtcLm.js} +1 -1
- package/dist/ui/assets/send-DAhlz2i9.js +1 -0
- package/dist/ui/assets/settings-DL0REysC.js +1 -0
- package/dist/ui/assets/shield-BPZZhjCT.js +1 -0
- package/dist/ui/assets/slider-DcmBdvYD.js +1 -0
- package/dist/ui/assets/sparkles-BViXTAh7.js +1 -0
- package/dist/ui/assets/square-psq7k_CB.js +1 -0
- package/dist/ui/assets/{switch-DXcELPsM.js → switch-CgiDezVR.js} +1 -1
- package/dist/ui/assets/tabs-gUXIjjZv.js +1 -0
- package/dist/ui/assets/terminal-CzxPKG-h.js +1 -0
- package/dist/ui/assets/{textarea-rp6vsOZl.js → textarea-DedxQYBx.js} +1 -1
- package/dist/ui/assets/trash-2-SgYCWiVk.js +1 -0
- package/dist/ui/assets/{useHiveAgentsModelLoad-D3s2U82M.js → useHiveAgentsModelLoad-C7bhWPDG.js} +1 -1
- package/dist/ui/assets/useProviders-CiLSc05q.js +1 -0
- package/dist/ui/assets/vendor-radix-DUug7irY.js +63 -0
- package/dist/ui/assets/{vendor-react-CPJEWbIG.js → vendor-react-DYyYpuMy.js} +1 -1
- package/dist/ui/assets/volume-x-BDlMCDYT.js +1 -0
- package/dist/ui/assets/wifi-CyPHteEm.js +1 -0
- package/dist/ui/assets/zap-OVVrfEHr.js +1 -0
- package/dist/ui/index.html +8 -7
- package/package.json +1 -1
- package/packages/core/src/agent/agent-loop.ts +77 -3
- package/packages/core/src/agent/context-compiler.ts +13 -2
- package/packages/core/src/agent/llm-client.ts +41 -6
- package/packages/core/src/agent/llm-providers/nvidia.ts +39 -0
- package/packages/core/src/agent/llm-providers/openai-compat-base.ts +38 -2
- package/packages/core/src/agent/mcp-result-normalizer.ts +192 -0
- package/packages/core/src/agent/providers/index.ts +8 -0
- package/packages/core/src/agent/tool-selector.ts +1 -0
- package/packages/core/src/artifacts/store.ts +81 -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/events/tool-narration.ts +3 -0
- 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/routes/system.ts +9 -4
- package/packages/core/src/gateway/server.ts +36 -5
- package/packages/core/src/gateway/webchat-turn.ts +74 -2
- package/packages/core/src/storage/seed.ts +1 -0
- package/packages/core/src/tool-runtime/embedded-worker.generated.ts +20 -0
- package/packages/core/src/tool-runtime/index.ts +56 -14
- package/packages/core/src/tools/index.ts +3 -2
- package/packages/core/src/tools/web/artifact-read.ts +162 -0
- package/packages/core/src/tools/web/index.ts +3 -0
- package/packages/core/src/utils/redact-binary.ts +17 -0
- package/packages/skills/src/bundled-data.generated.ts +752 -752
- package/dist/ui/assets/A2UIPage-BRpjnMss.js +0 -8
- package/dist/ui/assets/AgentCreateForm-ASjKD7Js.js +0 -1
- package/dist/ui/assets/AgentDetailPage-bqJ-MS40.js +0 -1
- package/dist/ui/assets/AgentNewPage-CPaf2C3u.js +0 -1
- package/dist/ui/assets/AgentsPage-BIpLG0V6.js +0 -10
- package/dist/ui/assets/ApiClientPage-dRckcgrN.js +0 -3
- package/dist/ui/assets/ChannelsPage-BX_hPtiN.js +0 -8
- package/dist/ui/assets/DashboardPage-KMaMaFf4.js +0 -6
- package/dist/ui/assets/LoginPage-Zchu-f16.js +0 -1
- package/dist/ui/assets/MeetingPage-qrpYGVD-.js +0 -1
- package/dist/ui/assets/ModelSelector-C8ny_pxu.js +0 -1
- package/dist/ui/assets/ProvidersPage-DP9v_1ko.js +0 -1
- package/dist/ui/assets/RecoverPage-BXwjLfap.js +0 -1
- package/dist/ui/assets/SettingsPage-DD7GKtS6.js +0 -9
- package/dist/ui/assets/SetupPage-D7YX2io-.js +0 -1
- package/dist/ui/assets/WebChatPage-C3cgimxd.js +0 -29
- package/dist/ui/assets/activity-DZKL7dg4.js +0 -1
- package/dist/ui/assets/agentCapabilities-DuGs07XP.js +0 -1
- 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/calendar-CkDsc4OJ.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-alert-BkP6x0zQ.js +0 -1
- package/dist/ui/assets/circle-check-CXC2AiMS.js +0 -1
- package/dist/ui/assets/circle-x-h4OJiHV3.js +0 -1
- package/dist/ui/assets/copy-BtpYEEvV.js +0 -1
- package/dist/ui/assets/download-aPuVaZik.js +0 -1
- package/dist/ui/assets/earth-sc8YJMc0.js +0 -1
- package/dist/ui/assets/ellipsis-vertical-DEBZJGzY.js +0 -1
- package/dist/ui/assets/external-link-D_C_678M.js +0 -1
- package/dist/ui/assets/eye-BfN613fx.js +0 -1
- package/dist/ui/assets/file-text-Bth5pPZX.js +0 -1
- package/dist/ui/assets/gauge-DypSzSOE.js +0 -1
- package/dist/ui/assets/history-njH_sPSo.js +0 -1
- package/dist/ui/assets/index-D-9yCvjP.js +0 -116
- package/dist/ui/assets/index-wML8DaUo.css +0 -2
- package/dist/ui/assets/info-Def2ZFeP.js +0 -1
- package/dist/ui/assets/key-D8bkDl83.js +0 -1
- package/dist/ui/assets/loader-circle-wLVzSdML.js +0 -1
- package/dist/ui/assets/lock-open-Cdopbw1b.js +0 -1
- package/dist/ui/assets/mail-BQ_YA9_b.js +0 -1
- package/dist/ui/assets/pause-CvS_LzKx.js +0 -1
- package/dist/ui/assets/pencil-C3tPvnCk.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/progress-DrI2UDu-.js +0 -1
- package/dist/ui/assets/radio-dsaiFxuT.js +0 -1
- package/dist/ui/assets/refresh-cw-BmYQwOhh.js +0 -1
- package/dist/ui/assets/scroll-area-CfHn94Vb.js +0 -1
- package/dist/ui/assets/search-CTONpTyl.js +0 -1
- package/dist/ui/assets/send-C3o2wpLi.js +0 -1
- package/dist/ui/assets/settings-DEpdBuf2.js +0 -1
- package/dist/ui/assets/shield-gbUkSqfi.js +0 -1
- package/dist/ui/assets/slider-CmE_z1Ii.js +0 -1
- package/dist/ui/assets/sparkles-Ccd1JZ3s.js +0 -1
- package/dist/ui/assets/square-BrwQ6Mun.js +0 -1
- package/dist/ui/assets/tabs-CxiybXcw.js +0 -1
- package/dist/ui/assets/terminal-DP9j3HjM.js +0 -1
- package/dist/ui/assets/trash-2-CfCs7RhJ.js +0 -1
- package/dist/ui/assets/triangle-alert-C3lWSnRr.js +0 -1
- package/dist/ui/assets/useProviders-B3rT_xU9.js +0 -1
- package/dist/ui/assets/vendor-radix-D0s_k6Gp.js +0 -63
- package/dist/ui/assets/volume-x-D2h9cyml.js +0 -1
- package/dist/ui/assets/wifi-CGQECzu2.js +0 -1
- package/dist/ui/assets/zap-B1azpiE7.js +0 -1
- /package/dist/ui/assets/{gateway-url-BlnabM5e.js → gateway-url-BZj_2-jf.js} +0 -0
- /package/dist/ui/assets/{useOfficeModel-Cy7cAyEn.js → useOfficeModel-BAFasrg8.js} +0 -0
- /package/dist/ui/assets/{utils-Dyb7SC2_.js → utils-SGUggNJc.js} +0 -0
- /package/dist/ui/assets/{vendor-router-zpB-76nT.js → vendor-router-Dsg8fxNQ.js} +0 -0
|
@@ -91,6 +91,87 @@ export async function createArtifact(input: {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Reads an artifact's bytes straight off disk — for server-side consumers
|
|
96
|
+
* that don't need an HTTP round trip (routes/artifacts.ts is for the
|
|
97
|
+
* browser; channels/*.ts send()s use this directly to build a Telegram/
|
|
98
|
+
* Discord/Slack/WhatsApp photo attachment from the same file).
|
|
99
|
+
*/
|
|
100
|
+
export async function readArtifactBytes(
|
|
101
|
+
artifactId: string,
|
|
102
|
+
): Promise<{ bytes: Buffer; mimeType: string } | null> {
|
|
103
|
+
const artifacts = await col<ArtifactDoc>("artifacts");
|
|
104
|
+
const entry = await artifacts.get(artifactId);
|
|
105
|
+
if (!entry || entry.doc.status !== "active") return null;
|
|
106
|
+
if (!existsSync(entry.doc.path)) return null;
|
|
107
|
+
return { bytes: readFileSync(entry.doc.path), mimeType: entry.doc.mime_type };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Beyond this an artifact stops being something an agent can read into a context window. */
|
|
111
|
+
const MAX_TEXT_ARTIFACT_BYTES = 25 * 1024 * 1024;
|
|
112
|
+
|
|
113
|
+
function looksBinary(mimeType: string, bytes: Buffer): boolean {
|
|
114
|
+
if (/^(image|audio|video)\//.test(mimeType)) return true;
|
|
115
|
+
if (mimeType === "application/octet-stream") return true;
|
|
116
|
+
// A NUL byte in the first KB is the classic "this is not text" tell — a
|
|
117
|
+
// mislabelled text/plain artifact would otherwise decode to garbage.
|
|
118
|
+
return bytes.subarray(0, 1024).includes(0x00);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type ArtifactTextResult = {
|
|
122
|
+
ok: boolean;
|
|
123
|
+
text?: string;
|
|
124
|
+
artifact?: ArtifactDoc;
|
|
125
|
+
error?: string;
|
|
126
|
+
status?: string;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Decodes a text artifact for in-process consumers that need its *content*,
|
|
131
|
+
* not just its metadata (inspectArtifact) or its raw bytes (readArtifactBytes).
|
|
132
|
+
*
|
|
133
|
+
* This exists because mcp-result-normalizer.ts moves oversized MCP text results
|
|
134
|
+
* out of the context window and hands the model an `artifact_ref` instead. Until
|
|
135
|
+
* this, nothing could read that reference back: the agent held a receipt it
|
|
136
|
+
* could not cash, burned its iterations guessing, and the turn died on an empty
|
|
137
|
+
* synthesis. Ownership and status checks mirror inspectArtifact's.
|
|
138
|
+
*/
|
|
139
|
+
export async function readArtifactText(
|
|
140
|
+
artifactId: string,
|
|
141
|
+
options: { userId?: string } = {},
|
|
142
|
+
): Promise<ArtifactTextResult> {
|
|
143
|
+
const artifacts = await col<ArtifactDoc>("artifacts");
|
|
144
|
+
const entry = await artifacts.get(artifactId);
|
|
145
|
+
if (!entry) return { ok: false, error: "Artifact not found" };
|
|
146
|
+
const artifact = entry.doc;
|
|
147
|
+
|
|
148
|
+
if (options.userId && artifact.user_id && artifact.user_id !== options.userId) {
|
|
149
|
+
return { ok: false, error: "Artifact not accessible" };
|
|
150
|
+
}
|
|
151
|
+
if (artifact.status !== "active") {
|
|
152
|
+
return { ok: false, error: "Artifact binary has expired", status: artifact.status };
|
|
153
|
+
}
|
|
154
|
+
if (!existsSync(artifact.path)) {
|
|
155
|
+
return { ok: false, error: "Artifact binary is missing", status: "missing" };
|
|
156
|
+
}
|
|
157
|
+
if (artifact.size > MAX_TEXT_ARTIFACT_BYTES) {
|
|
158
|
+
return {
|
|
159
|
+
ok: false,
|
|
160
|
+
error: `Artifact is too large to read as text (${artifact.size} bytes, limit ${MAX_TEXT_ARTIFACT_BYTES})`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const bytes = readFileSync(artifact.path);
|
|
165
|
+
if (looksBinary(detectedMime(bytes, artifact.mime_type), bytes)) {
|
|
166
|
+
return {
|
|
167
|
+
ok: false,
|
|
168
|
+
error: `Artifact is binary (${detectedMime(bytes, artifact.mime_type)}) — use artifact_inspect for its metadata`,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return { ok: true, text: bytes.toString("utf-8"), artifact };
|
|
173
|
+
}
|
|
174
|
+
|
|
94
175
|
export async function inspectArtifact(
|
|
95
176
|
artifactId: string,
|
|
96
177
|
options: { userId?: string } = {},
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
import { readArtifactBytes } from "../artifacts/store";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolves an OutboundMessage.image to raw bytes for channels that need to
|
|
5
|
+
* upload a photo directly (Telegram/Discord/Slack/WhatsApp) — prefers the
|
|
6
|
+
* artifact on disk (artifactId, the common path from mcp-result-normalizer.ts
|
|
7
|
+
* results) over an inline base64 payload.
|
|
8
|
+
*/
|
|
9
|
+
export async function readOutboundImageBytes(
|
|
10
|
+
image: NonNullable<OutboundMessage["image"]>,
|
|
11
|
+
): Promise<Buffer | null> {
|
|
12
|
+
if (image.artifactId) {
|
|
13
|
+
const artifact = await readArtifactBytes(image.artifactId);
|
|
14
|
+
if (artifact) return artifact.bytes;
|
|
15
|
+
}
|
|
16
|
+
if (image.base64) return Buffer.from(image.base64, "base64");
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
1
20
|
export interface OutboundMessage {
|
|
2
21
|
type: "message" | "stream" | "status" | "error" | "pong" | "command_result" | "log" | "typing" | "audio" | "process" | "progress" | "notification";
|
|
3
22
|
sessionId: string;
|
|
@@ -19,6 +38,20 @@ export interface OutboundMessage {
|
|
|
19
38
|
base64?: string;
|
|
20
39
|
mimeType?: string;
|
|
21
40
|
};
|
|
41
|
+
/** Image artifact to show alongside the response (e.g. an MCP image-generation tool's result — see mcp-result-normalizer.ts). `url` points at the artifacts download endpoint (webchat/HTTP consumers); `artifactId` lets server-side channels (Telegram/Discord/Slack/WhatsApp) read the bytes straight off disk via artifacts/store.ts's readArtifactBytes — no HTTP round trip needed since they run in the same process. */
|
|
42
|
+
image?: {
|
|
43
|
+
artifactId?: string;
|
|
44
|
+
url?: string;
|
|
45
|
+
base64?: string;
|
|
46
|
+
mimeType?: string;
|
|
47
|
+
caption?: string;
|
|
48
|
+
};
|
|
49
|
+
document?: {
|
|
50
|
+
url?: string;
|
|
51
|
+
base64?: string;
|
|
52
|
+
mimeType?: string;
|
|
53
|
+
filename?: string;
|
|
54
|
+
};
|
|
22
55
|
status?: {
|
|
23
56
|
state: string;
|
|
24
57
|
model?: string;
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type DMChannel,
|
|
8
8
|
type NewsChannel,
|
|
9
9
|
} from "discord.js";
|
|
10
|
-
import { BaseChannel, type ChannelConfig, type IncomingMessage, type OutboundMessage } from "./base.ts";
|
|
10
|
+
import { BaseChannel, type ChannelConfig, type IncomingMessage, type OutboundMessage, readOutboundImageBytes } from "./base.ts";
|
|
11
11
|
import { logger } from "../utils/logger.ts";
|
|
12
12
|
import { updateDoc } from "../storage/hive.ts";
|
|
13
13
|
import type { ChannelDoc } from "../storage/collections.ts";
|
|
@@ -207,9 +207,28 @@ export class DiscordChannel extends BaseChannel {
|
|
|
207
207
|
throw new Error(`Channel not found for session: ${sessionId}`);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
+
if (message.image) {
|
|
211
|
+
try {
|
|
212
|
+
const bytes = await readOutboundImageBytes(message.image);
|
|
213
|
+
if (bytes) {
|
|
214
|
+
const ext = message.image.mimeType === "image/jpeg" ? "jpg" : message.image.mimeType === "image/webp" ? "webp" : "png";
|
|
215
|
+
await channel.send({
|
|
216
|
+
content: message.image.caption,
|
|
217
|
+
files: [{ attachment: bytes, name: `image.${ext}` }],
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
this.log.warn(`Image artifact unavailable, skipping photo send`, { sessionId });
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
this.log.error(`Failed to send Discord image: ${(error as Error).message}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
210
227
|
const content = message.content ?? "";
|
|
211
228
|
const maxLength = 2000;
|
|
212
229
|
|
|
230
|
+
if (!content) return;
|
|
231
|
+
|
|
213
232
|
try {
|
|
214
233
|
if (content.length <= maxLength) {
|
|
215
234
|
await channel.send(content);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { App, ExpressReceiver, type SlashCommand } from "@slack/bolt";
|
|
2
2
|
import type { ChannelConfig, IncomingMessage, OutboundMessage } from "./base.ts";
|
|
3
|
-
import { BaseChannel } from "./base.ts";
|
|
3
|
+
import { BaseChannel, readOutboundImageBytes } from "./base.ts";
|
|
4
4
|
import { logger } from "../utils/logger.ts";
|
|
5
5
|
import { updateDoc } from "../storage/hive.ts";
|
|
6
6
|
import type { ChannelDoc } from "../storage/collections.ts";
|
|
@@ -260,10 +260,29 @@ await this.handleMessage(incoming);
|
|
|
260
260
|
throw new Error("Slack not connected");
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
const peerId = this.extractPeerId(sessionId);
|
|
264
|
+
|
|
265
|
+
if (message.image) {
|
|
266
|
+
try {
|
|
267
|
+
const bytes = await readOutboundImageBytes(message.image);
|
|
268
|
+
if (bytes) {
|
|
269
|
+
await this.app.client.files.uploadV2({
|
|
270
|
+
channel_id: peerId,
|
|
271
|
+
file: bytes,
|
|
272
|
+
filename: `image.${message.image.mimeType === "image/jpeg" ? "jpg" : message.image.mimeType === "image/webp" ? "webp" : "png"}`,
|
|
273
|
+
title: message.image.caption ?? "Image response",
|
|
274
|
+
});
|
|
275
|
+
} else {
|
|
276
|
+
this.log.warn(`Image artifact unavailable, skipping photo send`, { sessionId });
|
|
277
|
+
}
|
|
278
|
+
} catch (error) {
|
|
279
|
+
this.log.error(`Failed to send Slack image: ${(error as Error).message}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
263
283
|
const text = message.content ?? message.chunk ?? "";
|
|
264
284
|
if (!text) return;
|
|
265
285
|
|
|
266
|
-
const peerId = this.extractPeerId(sessionId);
|
|
267
286
|
const pending = this.pendingMessages.get(sessionId);
|
|
268
287
|
|
|
269
288
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Bot, GrammyError, InputFile, type Context } from "grammy";
|
|
2
|
-
import { BaseChannel, type ChannelConfig, type IncomingMessage, type OutboundMessage } from "./base.ts";
|
|
2
|
+
import { BaseChannel, type ChannelConfig, type IncomingMessage, type OutboundMessage, readOutboundImageBytes } from "./base.ts";
|
|
3
3
|
import { logger } from "../utils/logger.ts";
|
|
4
4
|
import { col, updateDoc } from "../storage/hive.ts";
|
|
5
5
|
import type { ChannelDoc, UserIdentityDoc } from "../storage/collections.ts";
|
|
@@ -404,6 +404,21 @@ export class TelegramChannel extends BaseChannel {
|
|
|
404
404
|
throw new Error(`Invalid chat ID from session: ${sessionId}`);
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
+
if (message.image) {
|
|
408
|
+
try {
|
|
409
|
+
const bytes = await readOutboundImageBytes(message.image);
|
|
410
|
+
if (bytes) {
|
|
411
|
+
await this.bot.api.sendPhoto(chatId, new InputFile(bytes), {
|
|
412
|
+
caption: message.image.caption,
|
|
413
|
+
});
|
|
414
|
+
} else {
|
|
415
|
+
this.log.warn(`Image artifact unavailable, skipping photo send`, { sessionId });
|
|
416
|
+
}
|
|
417
|
+
} catch (error) {
|
|
418
|
+
this.log.error(`Telegram sendPhoto failed: ${(error as Error).message}`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
407
422
|
const content = message.content ?? "";
|
|
408
423
|
|
|
409
424
|
if (!content || content.trim().length === 0) {
|
|
@@ -8,7 +8,7 @@ import makeWASocket, {
|
|
|
8
8
|
type WAMessage,
|
|
9
9
|
} from "@whiskeysockets/baileys";
|
|
10
10
|
import type { ChannelConfig, IncomingMessage, OutboundMessage } from "./base.ts";
|
|
11
|
-
import { BaseChannel } from "./base.ts";
|
|
11
|
+
import { BaseChannel, readOutboundImageBytes } from "./base.ts";
|
|
12
12
|
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
|
13
13
|
import * as path from "node:path";
|
|
14
14
|
import { homedir } from "node:os";
|
|
@@ -488,11 +488,24 @@ export class WhatsAppChannel extends BaseChannel {
|
|
|
488
488
|
const isInterim = message.type === "progress";
|
|
489
489
|
if (!isInterim) await this.stopTyping(sessionId);
|
|
490
490
|
|
|
491
|
+
const jid = this.getJid(sessionId);
|
|
492
|
+
|
|
493
|
+
if (message.image) {
|
|
494
|
+
try {
|
|
495
|
+
const bytes = await readOutboundImageBytes(message.image);
|
|
496
|
+
if (bytes) {
|
|
497
|
+
await this.socket.sendMessage(jid, { image: bytes, caption: message.image.caption });
|
|
498
|
+
} else {
|
|
499
|
+
this.log.warn(`Image artifact unavailable, skipping photo send`, { sessionId });
|
|
500
|
+
}
|
|
501
|
+
} catch (error) {
|
|
502
|
+
this.log.error(`Failed to send WhatsApp image: ${(error as Error).message}`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
491
506
|
const text = message.content ?? message.chunk ?? "";
|
|
492
507
|
if (!text) return;
|
|
493
508
|
|
|
494
|
-
const jid = this.getJid(sessionId);
|
|
495
|
-
|
|
496
509
|
await this.socket.sendMessage(jid, { text });
|
|
497
510
|
if (isInterim) await this.startTyping(sessionId);
|
|
498
511
|
this.log.debug(`Sent message to ${jid}`);
|
|
@@ -44,6 +44,9 @@ const TOOL_NARRATIONS: Record<string, string> = {
|
|
|
44
44
|
browser_type: "Escribiendo en la página...",
|
|
45
45
|
browser_screenshot: "Tomando captura de pantalla...",
|
|
46
46
|
browser_extract: "Extrayendo información de la página...",
|
|
47
|
+
// Artefactos
|
|
48
|
+
artifact_inspect: "Verificando el archivo generado...",
|
|
49
|
+
artifact_read: "Leyendo el resultado completo...",
|
|
47
50
|
// Canvas
|
|
48
51
|
canvas_add_node: "Actualizando canvas...",
|
|
49
52
|
canvas_update: "Actualizando canvas...",
|
|
@@ -92,7 +92,8 @@ export function registerTerminalHook(type: JobType, hook: JobTerminalHook): void
|
|
|
92
92
|
terminalHooks.set(type, hook);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
/** Exported so job-store.ts's reclaimOrInterrupt can fire it too (dynamic import there — see its call site — avoids a static circular import since this module already imports reclaimOrInterrupt from job-store.ts). */
|
|
96
|
+
export async function runTerminalHook(job: JobDoc, outcome: JobTerminalOutcome): Promise<void> {
|
|
96
97
|
const hook = terminalHooks.get(job.type);
|
|
97
98
|
if (!hook) return;
|
|
98
99
|
try {
|
|
@@ -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
|
+
}
|
|
@@ -211,13 +211,18 @@ export async function handleTriggerUpdate(
|
|
|
211
211
|
// escritorio (Tauri) — GitHub Releases ya no publica binarios
|
|
212
212
|
// standalone sueltos, así que no hay un "archivo" que reemplazar
|
|
213
213
|
// manualmente. La actualización real la maneja el updater de Tauri.
|
|
214
|
+
// El gateway no puede actualizarse a sí mismo acá: vive embebido en la
|
|
215
|
+
// app de escritorio, y quien descarga, verifica la firma e instala es
|
|
216
|
+
// el updater de Tauri desde la ventana (components/DesktopUpdater.tsx).
|
|
217
|
+
// Este endpoint solo explica dónde ocurre; prometer que "se actualiza
|
|
218
|
+
// sola" cuando nadie disparaba el chequeo fue el bug anterior.
|
|
214
219
|
return addCorsHeaders(Response.json({
|
|
215
220
|
success: false,
|
|
216
|
-
error: "La app de escritorio se actualiza
|
|
221
|
+
error: "La app de escritorio se actualiza desde su propia ventana, no desde el gateway.",
|
|
217
222
|
instructions: [
|
|
218
|
-
"1. La app revisa
|
|
219
|
-
"2.
|
|
220
|
-
"3.
|
|
223
|
+
"1. La app revisa si hay versión nueva al abrirse y cada 6 horas",
|
|
224
|
+
"2. Cuando la encuentra te muestra un aviso con las notas y un botón para instalarla; al terminar se reinicia sola",
|
|
225
|
+
"3. Si preferís hacerlo a mano, descargá el instalador de tu sistema desde https://github.com/johpaz/hive/releases/latest — conserva tus datos y agentes"
|
|
221
226
|
]
|
|
222
227
|
}), req)
|
|
223
228
|
|
|
@@ -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)
|