@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Config } from "../config/loader";
|
|
2
2
|
import { loadConfig, getHiveDir } from "../config/loader";
|
|
3
3
|
import { logger, onLogEntry } from "../utils/logger";
|
|
4
|
+
import { resolveUISource } from "./helpers/ui-source";
|
|
4
5
|
import { sessionManager, parseSessionId } from "./session";
|
|
5
6
|
import { enqueueChatTurn, initWebchatTurnRunner } from "./webchat-turn";
|
|
6
7
|
import {
|
|
@@ -44,7 +45,7 @@ import { handleSetupStatus, handleVerifyProvider, handleCompleteSetup, handleSet
|
|
|
44
45
|
import { handleAuthStatus, handleLogin, handleSetupCredentials, handleChangePassword, handleRecover, handleDisableAuth, handleRecoveryKey } from "./routes/auth";
|
|
45
46
|
import { resolveUserId } from "../storage/onboarding";
|
|
46
47
|
import { handleGetAgents, handleCreateAgent, handleUpdateAgent, handleDeleteAgent, handleGetAgentProposals } from "./routes/agents";
|
|
47
|
-
import { handleGetProviders, handleCreateProvider, handleToggleProvider, handleUpdateProvider, handleSyncProviderModels, handleLoadHiveAgentsModel, handleGetHiveAgentsModelStatus } from "./routes/providers";
|
|
48
|
+
import { handleGetProviders, handleCreateProvider, handleToggleProvider, handleUpdateProvider, handleSyncProviderModels, handleGetProviderAvailableModels, handleLoadHiveAgentsModel, handleGetHiveAgentsModelStatus } from "./routes/providers";
|
|
48
49
|
import { handleGetUsers, handleCreateUser, handleUpdateUserSettings, handleGetUserChannels, handleLinkUserChannel } from "./routes/users";
|
|
49
50
|
import { handleGetSkills, handleActivateSkill, handleUpdateSkill, handleDeleteSkill, handleCreateSkill } from "./routes/skills";
|
|
50
51
|
import { handleGetEthics, handleActivateEthics, handleDeleteEthics } from "./routes/ethics";
|
|
@@ -57,6 +58,13 @@ import {
|
|
|
57
58
|
markNotificationDelivered,
|
|
58
59
|
} from "./notification-inbox";
|
|
59
60
|
import { setNarrationDelivery } from "../events/narration";
|
|
61
|
+
import {
|
|
62
|
+
resolveNarrationMode,
|
|
63
|
+
shouldDeliverToChannel,
|
|
64
|
+
formatNarrationForChannel,
|
|
65
|
+
enqueueChannelNarration,
|
|
66
|
+
awaitChannelNarration,
|
|
67
|
+
} from "../events/channel-narration";
|
|
60
68
|
import { CronScheduler } from "../scheduler/CronScheduler";
|
|
61
69
|
import { createTaskHandler, setSchedulerForCleanup } from "../scheduler/integration";
|
|
62
70
|
|
|
@@ -214,7 +222,7 @@ export async function startGateway(
|
|
|
214
222
|
type: metadata?.notificationId ? "notification" : "progress",
|
|
215
223
|
sessionId,
|
|
216
224
|
notificationId: metadata?.notificationId,
|
|
217
|
-
});
|
|
225
|
+
}, metadata?.accountId);
|
|
218
226
|
});
|
|
219
227
|
setNarrationDelivery(async (event) => {
|
|
220
228
|
if (event.channel === "webchat" && event.session_id) {
|
|
@@ -234,12 +242,20 @@ export async function startGateway(
|
|
|
234
242
|
return;
|
|
235
243
|
}
|
|
236
244
|
}
|
|
237
|
-
if (event.channel
|
|
245
|
+
if (!event.channel || !event.session_id) return;
|
|
246
|
+
|
|
247
|
+
// Messaging channels turn every event into a permanent chat message, so
|
|
248
|
+
// they get a filtered feed (see events/channel-narration.ts) delivered
|
|
249
|
+
// off the agent loop's critical path.
|
|
250
|
+
const mode = await resolveNarrationMode(event.channel);
|
|
251
|
+
if (!shouldDeliverToChannel(event, mode)) return;
|
|
252
|
+
|
|
253
|
+
enqueueChannelNarration(`${event.channel}:${event.session_id}`, async () => {
|
|
238
254
|
await channelManager.send(event.channel, event.session_id, {
|
|
239
|
-
content: event
|
|
255
|
+
content: formatNarrationForChannel(event),
|
|
240
256
|
type: "progress",
|
|
241
257
|
});
|
|
242
|
-
}
|
|
258
|
+
});
|
|
243
259
|
});
|
|
244
260
|
|
|
245
261
|
if (gatewaySetupMode) {
|
|
@@ -504,6 +520,7 @@ export async function startGateway(
|
|
|
504
520
|
const { userId, threadId: conversationThreadId } = await resolveContext({
|
|
505
521
|
channel: message.channel,
|
|
506
522
|
channelUserId: message.sessionId,
|
|
523
|
+
accountId: message.accountId,
|
|
507
524
|
});
|
|
508
525
|
|
|
509
526
|
const telegramMeta = message.metadata?.telegram as { messageId?: number } | undefined;
|
|
@@ -595,6 +612,10 @@ export async function startGateway(
|
|
|
595
612
|
}
|
|
596
613
|
log.info(`📤 LLM response: ${responseContent.substring(0, 100)}${responseContent.length > 100 ? "..." : ""}`);
|
|
597
614
|
|
|
615
|
+
// Narration is delivered off the critical path — let it drain first so the
|
|
616
|
+
// final answer lands after the progress messages, not before them.
|
|
617
|
+
await awaitChannelNarration(`${message.channel}:${routingSessionId}`);
|
|
618
|
+
|
|
598
619
|
const shouldSpeak = preferAudioResponse;
|
|
599
620
|
let responseType: "text" | "audio" = "text";
|
|
600
621
|
let ttsProviderUsed: string | null = null;
|
|
@@ -616,7 +637,7 @@ export async function startGateway(
|
|
|
616
637
|
responseType = "audio";
|
|
617
638
|
|
|
618
639
|
try {
|
|
619
|
-
const channel = channelManager.getChannel(message.channel);
|
|
640
|
+
const channel = channelManager.getChannel(message.channel, message.accountId);
|
|
620
641
|
if (channel?.sendAudio) {
|
|
621
642
|
await channel.sendAudio(routingSessionId, audioOutput.data as Buffer, audioOutput.mimeType);
|
|
622
643
|
log.info(`✅ Audio sent to ${routingSessionId}`);
|
|
@@ -887,16 +908,16 @@ export async function startGateway(
|
|
|
887
908
|
return new Response("Not found", { status: 404 });
|
|
888
909
|
}
|
|
889
910
|
|
|
890
|
-
// In production: serve from dist folder
|
|
891
|
-
//
|
|
892
|
-
|
|
893
|
-
const
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
911
|
+
// In production: serve from dist folder, o del bundle embebido si no
|
|
912
|
+
// hay nada en disco. Ver helpers/ui-source.ts para el orden y por qué
|
|
913
|
+
// el disco le gana al embed.
|
|
914
|
+
const uiSource = resolveUISource({
|
|
915
|
+
uiDirEnv: process.env.HIVE_UI_DIR,
|
|
916
|
+
distDirEnv: process.env.HIVE_DIST_DIR,
|
|
917
|
+
hiveDir: getHiveDir(),
|
|
918
|
+
cwd: process.cwd(),
|
|
919
|
+
hasEmbedded: Boolean(embeddedUI?.size),
|
|
920
|
+
});
|
|
900
921
|
let subPath = url.pathname;
|
|
901
922
|
|
|
902
923
|
// En setup mode: / y /ui redirigen a /setup
|
|
@@ -927,7 +948,7 @@ export async function startGateway(
|
|
|
927
948
|
// Standalone executables carry the UI inside the Bun binary. The CLI
|
|
928
949
|
// passes that bundle into the child gateway process so both API and
|
|
929
950
|
// UI continue to share a single port without extracting files.
|
|
930
|
-
if (embeddedUI
|
|
951
|
+
if (uiSource.kind === "embedded" && embeddedUI) {
|
|
931
952
|
const entry = embeddedUI.get(subPath)
|
|
932
953
|
?? (!path.extname(subPath) ? embeddedUI.get("/index.html") : undefined);
|
|
933
954
|
if (entry) {
|
|
@@ -942,17 +963,18 @@ export async function startGateway(
|
|
|
942
963
|
}
|
|
943
964
|
}
|
|
944
965
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
966
|
+
if (uiSource.kind === "disk") {
|
|
967
|
+
const uiFile = Bun.file(path.join(uiSource.dir, subPath));
|
|
968
|
+
if (await uiFile.exists()) {
|
|
969
|
+
return new Response(uiFile);
|
|
970
|
+
}
|
|
950
971
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
972
|
+
// SPA fallback: paths without a file extension are React Router routes — serve index.html
|
|
973
|
+
if (!path.extname(subPath)) {
|
|
974
|
+
const indexFile = Bun.file(path.join(uiSource.dir, "index.html"));
|
|
975
|
+
if (await indexFile.exists()) {
|
|
976
|
+
return new Response(indexFile);
|
|
977
|
+
}
|
|
956
978
|
}
|
|
957
979
|
}
|
|
958
980
|
|
|
@@ -1045,7 +1067,9 @@ export async function startGateway(
|
|
|
1045
1067
|
return addCorsHeaders(new Response(
|
|
1046
1068
|
JSON.stringify({
|
|
1047
1069
|
status: "ok",
|
|
1048
|
-
|
|
1070
|
+
// Estaba hardcodeada en "0.1.7" mientras package.json iba por 1.0.1:
|
|
1071
|
+
// /status mentía sobre qué versión estaba corriendo.
|
|
1072
|
+
version: _pkgVersion,
|
|
1049
1073
|
uptime: Math.floor((Date.now() - startTime) / 1000),
|
|
1050
1074
|
gateway: { host, port },
|
|
1051
1075
|
sessions: sessionManager.list().map((s) => ({
|
|
@@ -1323,6 +1347,12 @@ export async function startGateway(
|
|
|
1323
1347
|
return await handleSyncProviderModels(req, addCorsHeaders, providerId)
|
|
1324
1348
|
}
|
|
1325
1349
|
|
|
1350
|
+
// GET /api/providers/:id/available-models — lista lo que sirve el provider, sin persistir
|
|
1351
|
+
const availableModelsMatch = url.pathname.match(/^\/api\/providers\/([^/]+)\/available-models$/)
|
|
1352
|
+
if (availableModelsMatch && req.method === "GET") {
|
|
1353
|
+
return await handleGetProviderAvailableModels(req, addCorsHeaders, availableModelsMatch[1])
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1326
1356
|
// POST /api/models - Create a new model
|
|
1327
1357
|
if (url.pathname === "/api/models" && req.method === "POST") {
|
|
1328
1358
|
return await handleCreateModel(req, addCorsHeaders)
|
|
@@ -21,6 +21,7 @@ import { sendToUserChannel } from "./channel-notify";
|
|
|
21
21
|
import { getNarration } from "./helpers";
|
|
22
22
|
import { createRun, getRun } from "../agent/run-store";
|
|
23
23
|
import { getDurableQueue } from "./durable-queue";
|
|
24
|
+
import { sessionManager } from "./session";
|
|
24
25
|
import type { JobDoc, TurnSource } from "../storage/collections";
|
|
25
26
|
|
|
26
27
|
const log = logger.child("webchat-turn");
|
|
@@ -423,11 +424,34 @@ export async function runWebchatTurn(
|
|
|
423
424
|
}
|
|
424
425
|
}
|
|
425
426
|
} else if (content && payload.source !== "api") {
|
|
426
|
-
//
|
|
427
|
-
//
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
427
|
+
// No live callback was attached to this job — either a genuine crash
|
|
428
|
+
// recovery, or (the common case for "delegation_summary"/"task_complete")
|
|
429
|
+
// a turn enqueued from a background job's terminal hook, which never has
|
|
430
|
+
// access to the original request's socket. Before falling back to the
|
|
431
|
+
// notification/toast path, check whether the user's browser still holds
|
|
432
|
+
// an open WS session under this exact sessionId — narration delivery
|
|
433
|
+
// (server.ts) already does this same lookup — and if so, push the
|
|
434
|
+
// response there as a normal chat message instead of a toast.
|
|
435
|
+
const liveSession = channel === "webchat" ? sessionManager.get(sessionId) : undefined;
|
|
436
|
+
const liveWs = liveSession?.ws?.readyState === 1 ? liveSession.ws : null;
|
|
437
|
+
if (liveWs) {
|
|
438
|
+
try {
|
|
439
|
+
liveWs.send(JSON.stringify({ type: "message", id: messageId, sessionId, content, isStep: false }));
|
|
440
|
+
liveWs.send(JSON.stringify({ type: "typing", isTyping: false, sessionId }));
|
|
441
|
+
} catch (err) {
|
|
442
|
+
log.warn(`[runWebchatTurn] Live push to open session failed, falling back to notification: ${(err as Error).message}`);
|
|
443
|
+
await sendToUserChannel(channel, userId, content).catch((err2) =>
|
|
444
|
+
log.warn(`[runWebchatTurn] Failed to deliver response: ${(err2 as Error).message}`)
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
} else {
|
|
448
|
+
// Rehydrated turn (crash recovery), or the user's browser isn't
|
|
449
|
+
// connected right now: deliver the final content through the user's
|
|
450
|
+
// channel (persisted notification for webchat; push API for the rest).
|
|
451
|
+
await sendToUserChannel(channel, userId, content).catch((err) =>
|
|
452
|
+
log.warn(`[runWebchatTurn] Failed to deliver crash-recovered response: ${(err as Error).message}`)
|
|
453
|
+
);
|
|
454
|
+
}
|
|
431
455
|
}
|
|
432
456
|
|
|
433
457
|
if (delegationGroup) {
|
|
@@ -13,7 +13,7 @@ export * from "./agent/skill-selector.ts";
|
|
|
13
13
|
export * from "./agent/playbook-selector.ts";
|
|
14
14
|
export * from "./agent/catalog-selector.ts";
|
|
15
15
|
export * from "./agent/delegation-runtime.ts";
|
|
16
|
-
export * from "./agent/acceptance-
|
|
16
|
+
export * from "./agent/acceptance-checks.ts";
|
|
17
17
|
export * from "./agent/llm-client.ts";
|
|
18
18
|
|
|
19
19
|
// Channels
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
* instead of `DELETE`+`INSERT`.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { getHiveDb } from "./hivedb";
|
|
14
|
+
import { getHiveDb, getOpenHiveDb } from "./hivedb";
|
|
15
15
|
import { col } from "./hive";
|
|
16
16
|
import { seedAllData } from "./seed";
|
|
17
|
+
import { ensureSecretsBackend } from "./crypto";
|
|
17
18
|
|
|
18
19
|
interface IndexSpec {
|
|
19
20
|
collection: string;
|
|
@@ -80,10 +81,6 @@ const INDEXES: IndexSpec[] = [
|
|
|
80
81
|
{ collection: "artifacts", field: "task_id" },
|
|
81
82
|
{ collection: "artifacts", field: "user_id" },
|
|
82
83
|
{ collection: "artifacts", field: "status" },
|
|
83
|
-
{ collection: "verifications", field: "run_id" },
|
|
84
|
-
{ collection: "verifications", field: "task_id" },
|
|
85
|
-
{ collection: "verifications", field: "executor_agent_id" },
|
|
86
|
-
{ collection: "verifications", field: "status" },
|
|
87
84
|
{ collection: "agentProposals", field: "agent_id" },
|
|
88
85
|
{ collection: "agentProposals", field: "status" },
|
|
89
86
|
{ collection: "agentProposals", field: "type" },
|
|
@@ -126,7 +123,10 @@ async function ensureSeedData(): Promise<void> {
|
|
|
126
123
|
await seedAllData();
|
|
127
124
|
}
|
|
128
125
|
|
|
129
|
-
|
|
126
|
+
// Bootstrap state belongs to a specific database instance. A boolean that
|
|
127
|
+
// survives closeHiveDb() can report a closed/replaced database as ready when
|
|
128
|
+
// tests or long-running processes open a fresh instance in the same runtime.
|
|
129
|
+
let bootstrappedDb: Awaited<ReturnType<typeof getHiveDb>> | null = null;
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
132
|
* Idempotent entry point: opens the database, ensures indexes, reseeds the
|
|
@@ -134,17 +134,21 @@ let bootstrapped = false;
|
|
|
134
134
|
* gateway boot.
|
|
135
135
|
*/
|
|
136
136
|
export async function ensureHiveDb(): Promise<void> {
|
|
137
|
-
await getHiveDb();
|
|
137
|
+
const db = await getHiveDb();
|
|
138
138
|
await ensureIndexes();
|
|
139
|
+
// Mint the master key before anything can save an API key, so a fresh
|
|
140
|
+
// install is durable from the first keystroke rather than after a restart
|
|
141
|
+
// has already dropped the secret.
|
|
142
|
+
ensureSecretsBackend();
|
|
139
143
|
await ensureSeedData();
|
|
140
144
|
|
|
141
145
|
const meta = await col<{ value: number }>("meta");
|
|
142
146
|
const existing = await meta.get("schemaVersion");
|
|
143
147
|
if (!existing) await meta.put("schemaVersion", { value: 1 }, { expectedVersion: 0 });
|
|
144
148
|
|
|
145
|
-
|
|
149
|
+
bootstrappedDb = db;
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
export function isBootstrapped(): boolean {
|
|
149
|
-
return
|
|
153
|
+
return bootstrappedDb !== null && bootstrappedDb === getOpenHiveDb();
|
|
150
154
|
}
|
|
@@ -53,6 +53,14 @@ export interface ModelDoc {
|
|
|
53
53
|
* agent pointing at it. Legacy rows (undefined) are treated as discovered.
|
|
54
54
|
*/
|
|
55
55
|
source?: "catalog" | "discovered"
|
|
56
|
+
/**
|
|
57
|
+
* Precio en USD por millón de tokens. Única fuente de verdad para el costo
|
|
58
|
+
* del dashboard: `calculateCost` (storage/usage.ts) lee de acá, no de una
|
|
59
|
+
* tabla aparte. `null` = precio desconocido (modelo agregado a mano o
|
|
60
|
+
* descubierto en runtime), que se reporta como $0 con un warning.
|
|
61
|
+
*/
|
|
62
|
+
input_per_1m?: number | null
|
|
63
|
+
output_per_1m?: number | null
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
export interface AgentDoc {
|
|
@@ -95,7 +103,7 @@ export interface AgentDoc {
|
|
|
95
103
|
workspace_scope_json?: string | null
|
|
96
104
|
model_override_json?: string | null
|
|
97
105
|
default_acceptance_json?: string | null
|
|
98
|
-
/** ACE learning counters — updated by
|
|
106
|
+
/** ACE learning counters — updated by deterministic acceptance checks and the coordinator's own accept/revise judgment (acceptance-checks.ts), not by loop completion. */
|
|
99
107
|
helpful_count?: number
|
|
100
108
|
harmful_count?: number
|
|
101
109
|
seed_version?: number
|
|
@@ -217,6 +225,8 @@ export interface UserIdentityDoc {
|
|
|
217
225
|
user_id: string
|
|
218
226
|
channel: string
|
|
219
227
|
channel_user_id: string
|
|
228
|
+
/** Account that owns this session — replies must go back out through it. Absent on legacy rows. */
|
|
229
|
+
account_id?: string
|
|
220
230
|
linked_at: number
|
|
221
231
|
}
|
|
222
232
|
|
|
@@ -459,8 +469,6 @@ export interface ProofPacketDoc {
|
|
|
459
469
|
known_limits: string | null
|
|
460
470
|
/** Fixed-worker epoch this run executed under — copied from AgentRunDoc.epoch_json. */
|
|
461
471
|
epoch_json: string | null
|
|
462
|
-
/** Required when met=true. Points at an independent verified verdict. */
|
|
463
|
-
verification_id: string
|
|
464
472
|
/** `toIndexable`-encoded catalog agent id, or `NO_PARENT`. */
|
|
465
473
|
catalog_agent_id: string
|
|
466
474
|
met: boolean
|
|
@@ -486,48 +494,6 @@ export interface ArtifactDoc {
|
|
|
486
494
|
expired_at: number | null
|
|
487
495
|
}
|
|
488
496
|
|
|
489
|
-
export interface VerificationCriterionResult {
|
|
490
|
-
criterion_id: string
|
|
491
|
-
met: boolean
|
|
492
|
-
evidence: string[]
|
|
493
|
-
check_used: string
|
|
494
|
-
confidence: number
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
export interface VerificationVerdict {
|
|
498
|
-
status: "verified" | "rejected" | "needs_evidence"
|
|
499
|
-
criterion_results: VerificationCriterionResult[]
|
|
500
|
-
summary: string
|
|
501
|
-
retry_guidance: string | null
|
|
502
|
-
risks: string[]
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/** Independent acceptance-gate record. Executors cannot write a verified proof packet without one. */
|
|
506
|
-
export interface VerificationDoc {
|
|
507
|
-
id: string
|
|
508
|
-
run_id: string
|
|
509
|
-
task_id: string
|
|
510
|
-
/** Any AgentDoc id (catalog-seeded or not). */
|
|
511
|
-
executor_agent_id: string
|
|
512
|
-
verifier_agent_id: "acceptance_verifier"
|
|
513
|
-
objective: string
|
|
514
|
-
acceptance_json: string
|
|
515
|
-
verdict_json: string
|
|
516
|
-
status: VerificationVerdict["status"]
|
|
517
|
-
attempt: number
|
|
518
|
-
executor_epoch_json: string
|
|
519
|
-
verifier_epoch_json: string
|
|
520
|
-
/** Diagnostic classification when the verifier could not produce a usable verdict. */
|
|
521
|
-
failure_code?: "invalid_output" | "verifier_error" | null
|
|
522
|
-
/** Sanitized diagnostic detail; never used to authorize success. */
|
|
523
|
-
failure_detail?: string | null
|
|
524
|
-
/** Bounded and sanitized preview of the verifier output. */
|
|
525
|
-
raw_output_preview?: string | null
|
|
526
|
-
verifier_provider?: string | null
|
|
527
|
-
verifier_model?: string | null
|
|
528
|
-
created_at: number
|
|
529
|
-
}
|
|
530
|
-
|
|
531
497
|
export interface AgentProposalDoc {
|
|
532
498
|
id: string
|
|
533
499
|
type: "move_tool" | "create_agent" | "disable_agent"
|
|
@@ -639,7 +605,7 @@ export interface NarrationEventDoc {
|
|
|
639
605
|
session_id: string
|
|
640
606
|
agent_id: string
|
|
641
607
|
agent_name: string
|
|
642
|
-
kind: "delegated" | "worker_started" | "tool_call" | "tool_result" | "
|
|
608
|
+
kind: "delegated" | "worker_started" | "tool_call" | "tool_result" | "verified" | "failed" | "group_ready"
|
|
643
609
|
status: "queued" | "running" | "done" | "error"
|
|
644
610
|
label: string
|
|
645
611
|
detail: string | null
|