@johpaz/hive-agents 0.0.45 → 1.0.0
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/LICENSE +21 -0
- package/README.md +119 -852
- package/dist/hive.js +59290 -58797
- package/dist/tool-worker.js +220 -925
- package/dist/ui/assets/A2UIPage-D4nUFe5q.js +8 -0
- package/dist/ui/assets/AgentCreateForm-g1mQnIoJ.js +1 -0
- package/dist/ui/assets/AgentDetailPage-C3XkU4Ll.js +1 -0
- package/dist/ui/assets/AgentNewPage-CEkLeA79.js +1 -0
- package/dist/ui/assets/AgentsPage-CNA778Eo.js +10 -0
- package/dist/ui/assets/ApiClientPage-t5DpKhmA.js +3 -0
- package/dist/ui/assets/ChannelsPage-yY6t0YTU.js +8 -0
- package/dist/ui/assets/DashboardPage-BSeNSYg5.js +6 -0
- package/dist/ui/assets/{LoginPage-BTxJdFVG.js → LoginPage-eT5zDRDa.js} +1 -1
- package/dist/ui/assets/{LogsPage-DVV2eHbh.js → LogsPage-Gczzzsdh.js} +1 -1
- package/dist/ui/assets/MeetingPage-Bu4aMMNR.js +1 -0
- package/dist/ui/assets/ModelSelector-nNOrW3te.js +1 -0
- package/dist/ui/assets/{NotFound-BIUDlIXU.js → NotFound-Bpr12V51.js} +1 -1
- package/dist/ui/assets/Office3DPage-B_iXEbyv.js +4614 -0
- package/dist/ui/assets/Office3DPage-C3SIzd2H.css +1 -0
- package/dist/ui/assets/ProvidersPage-BupHs5yO.js +1 -0
- package/dist/ui/assets/{RecoverPage-7YDQysBL.js → RecoverPage-DMqSasKk.js} +1 -1
- package/dist/ui/assets/SettingsPage-B6FTSkOn.js +9 -0
- package/dist/ui/assets/SetupPage-DhcRbGgg.js +1 -0
- package/dist/ui/assets/WebChatPage-CWXjW4Hn.js +29 -0
- package/dist/ui/assets/{activity-c3pNngT_.js → activity-CQuPevhB.js} +1 -1
- package/dist/ui/assets/agentCapabilities-CDC6y91E.js +1 -0
- package/dist/ui/assets/alert-CQlRq6sv.js +1 -0
- package/dist/ui/assets/arrow-left-0EBE7nsF.js +1 -0
- package/dist/ui/assets/arrow-right-5QIaph-z.js +1 -0
- package/dist/ui/assets/arrow-up-right-DQQCY007.js +1 -0
- package/dist/ui/assets/badge-DKGZbVZJ.js +1 -0
- package/dist/ui/assets/{calendar-B-KZ9RQO.js → calendar-Be23hQGc.js} +1 -1
- package/dist/ui/assets/{card-CNf6BS2e.js → card-D3Nw3kh3.js} +1 -1
- package/dist/ui/assets/check-Dp6tzwax.js +1 -0
- package/dist/ui/assets/chevron-down-33N886NY.js +1 -0
- package/dist/ui/assets/chevron-left-C6itJXh3.js +1 -0
- package/dist/ui/assets/chevron-right-CFodBS-b.js +1 -0
- package/dist/ui/assets/chevron-up-BvSmyBEs.js +1 -0
- package/dist/ui/assets/{circle-alert-KuAm2FWh.js → circle-alert-BDVHxmAz.js} +1 -1
- package/dist/ui/assets/circle-check-BJWNbLuF.js +1 -0
- package/dist/ui/assets/{circle-x-DjLkFDO8.js → circle-x-Cb2Yer4s.js} +1 -1
- package/dist/ui/assets/{copy-Bu5d7C-0.js → copy-33tZrzc9.js} +1 -1
- package/dist/ui/assets/{dialog-Jk4bieO4.js → dialog-KOZKWbib.js} +1 -1
- package/dist/ui/assets/dist-CD_qfA30.js +1 -0
- package/dist/ui/assets/{download-Cjbk4Rek.js → download-CiQqqXyz.js} +1 -1
- package/dist/ui/assets/earth-DCvN7ynm.js +1 -0
- package/dist/ui/assets/ellipsis-vertical-BybFZDk2.js +1 -0
- package/dist/ui/assets/{external-link-6sTlRDUR.js → external-link-0iNNBvZm.js} +1 -1
- package/dist/ui/assets/{eye-Df8o0tkC.js → eye-C8sKSSkg.js} +1 -1
- package/dist/ui/assets/{file-text-lnxnjBp0.js → file-text-DO8jqiJK.js} +1 -1
- package/dist/ui/assets/{gateway-url-DwzPmoc8.js → gateway-url-BlnabM5e.js} +1 -1
- package/dist/ui/assets/gauge-BRGwuN8G.js +1 -0
- package/dist/ui/assets/{history-CAF_R34_.js → history-BtTD1kDo.js} +1 -1
- package/dist/ui/assets/index-Bejlp-R1.js +116 -0
- package/dist/ui/assets/index-XoTT41Hr.css +2 -0
- package/dist/ui/assets/{info-WjromB4Y.js → info-mpk1tsNC.js} +1 -1
- package/dist/ui/assets/key-CoQ0qtXt.js +1 -0
- package/dist/ui/assets/label-k0jYxoWW.js +1 -0
- package/dist/ui/assets/loader-circle-BhqRN2nO.js +1 -0
- package/dist/ui/assets/lock-open-Cd2aqwOd.js +1 -0
- package/dist/ui/assets/mail-BG0RYSkL.js +1 -0
- package/dist/ui/assets/{pause-VqeUmp2Z.js → pause-Cme88_9s.js} +1 -1
- package/dist/ui/assets/pencil-f1nJ1xhs.js +1 -0
- package/dist/ui/assets/play-CfYDHD6h.js +1 -0
- package/dist/ui/assets/plus-C5BxJeOX.js +1 -0
- package/dist/ui/assets/progress-DrI2UDu-.js +1 -0
- package/dist/ui/assets/radio-B5SpKJ-J.js +1 -0
- package/dist/ui/assets/{refresh-cw-CCzDCAuz.js → refresh-cw-CroGQY62.js} +1 -1
- package/dist/ui/assets/scroll-area-CfHn94Vb.js +1 -0
- package/dist/ui/assets/search-rfBcmohK.js +1 -0
- package/dist/ui/assets/select-BhbW0stK.js +1 -0
- package/dist/ui/assets/{send-BPk9XbIq.js → send-D6whYpw-.js} +1 -1
- package/dist/ui/assets/{settings-BGfrZ_zM.js → settings-BX6q3MGB.js} +1 -1
- package/dist/ui/assets/{shield-CxhcUT39.js → shield-BnGyu1xf.js} +1 -1
- package/dist/ui/assets/slider-CmE_z1Ii.js +1 -0
- package/dist/ui/assets/{sparkles-BhwlS1pc.js → sparkles-BcaOs_Jk.js} +1 -1
- package/dist/ui/assets/{square-DMNWw4Hi.js → square-ju5H8nrT.js} +1 -1
- package/dist/ui/assets/switch-DXcELPsM.js +1 -0
- package/dist/ui/assets/tabs-CxiybXcw.js +1 -0
- package/dist/ui/assets/terminal-Bjfu-TkS.js +1 -0
- package/dist/ui/assets/{textarea-B6Z1Zc6W.js → textarea-rp6vsOZl.js} +1 -1
- package/dist/ui/assets/{trash-2-xD2o4SgX.js → trash-2-DjQXac_0.js} +1 -1
- package/dist/ui/assets/{triangle-alert-pVIJGjga.js → triangle-alert-B04mgMcg.js} +1 -1
- package/dist/ui/assets/{useHiveAgentsModelLoad-BnC4jLE-.js → useHiveAgentsModelLoad-DT5-4CCj.js} +1 -1
- package/dist/ui/assets/useOfficeModel-Cy7cAyEn.js +1 -0
- package/dist/ui/assets/useProviders-DSX7eVsz.js +1 -0
- package/dist/ui/assets/utils-Dyb7SC2_.js +1 -0
- package/dist/ui/assets/vendor-charts-K3xcRl0X.js +60 -0
- package/dist/ui/assets/{vendor-query-DsWPbQdG.js → vendor-query-Dj8xYhQD.js} +1 -1
- package/dist/ui/assets/vendor-radix-D0s_k6Gp.js +63 -0
- package/dist/ui/assets/vendor-react-CPJEWbIG.js +1 -0
- package/dist/ui/assets/{vendor-router-gqiZ7xhx.js → vendor-router-zpB-76nT.js} +1 -1
- package/dist/ui/assets/volume-x-qnVxkRSM.js +1 -0
- package/dist/ui/assets/wifi-BA1m2dGO.js +1 -0
- package/dist/ui/assets/{zap-B4RaNNO5.js → zap-DT7cM7YS.js} +1 -1
- package/dist/ui/index.html +10 -9
- package/package.json +8 -9
- package/packages/cli/src/adapters/config.ts +1 -80
- package/packages/cli/src/adapters/factory.ts +0 -45
- package/packages/cli/src/adapters/index.ts +0 -8
- package/packages/cli/src/commands/doctor.ts +45 -1
- package/packages/cli/src/commands/gateway.ts +2 -9
- package/packages/cli/src/index.ts +9 -11
- package/packages/core/src/agent/acceptance-verifier.ts +300 -0
- package/packages/core/src/agent/agent-catalog.ts +384 -0
- package/packages/core/src/agent/agent-loop.ts +185 -28
- package/packages/core/src/agent/capability-search.ts +5 -5
- package/packages/core/src/agent/catalog-selector.ts +104 -0
- package/packages/core/src/agent/compaction.ts +36 -41
- package/packages/core/src/agent/context-compiler.ts +182 -62
- package/packages/core/src/agent/conversation-store.ts +56 -3
- package/packages/core/src/agent/curator.ts +129 -34
- package/packages/core/src/agent/delegation-runtime.ts +248 -0
- package/packages/core/src/agent/index.ts +17 -0
- package/packages/core/src/agent/llm-providers/hiveagents.ts +1 -1
- package/packages/core/src/agent/llm-providers/interface.ts +3 -3
- package/packages/core/src/agent/llm-providers/openai-compat-base.ts +1 -1
- package/packages/core/src/agent/minimal-loadout.ts +46 -0
- package/packages/core/src/agent/playbook-selector.ts +1 -1
- package/packages/core/src/agent/prompt-builder.ts +4 -0
- package/packages/core/src/agent/proof-packet.ts +15 -1
- package/packages/core/src/agent/providers/index.ts +8 -3
- package/packages/core/src/agent/routing-intent.ts +22 -0
- package/packages/core/src/agent/run-store.ts +24 -3
- package/packages/core/src/agent/service.ts +2 -2
- package/packages/core/src/agent/skill-selector.ts +12 -31
- package/packages/core/src/agent/tool-selector.ts +36 -35
- package/packages/core/src/agent/tracer.ts +5 -1
- package/packages/core/src/artifacts/store.ts +162 -0
- package/packages/core/src/canvas/canvas-manager.ts +5 -234
- package/packages/core/src/canvas/emitter.ts +165 -69
- package/packages/core/src/canvas/index.ts +0 -2
- package/packages/core/src/channels/base.ts +3 -1
- package/packages/core/src/channels/webchat.ts +4 -8
- package/packages/core/src/config/loader.ts +0 -22
- package/packages/core/src/events/agent-bus.ts +0 -31
- package/packages/core/src/events/narration.ts +82 -0
- package/packages/core/src/gateway/channel-notify.ts +34 -5
- package/packages/core/src/gateway/delegation-groups.ts +245 -0
- package/packages/core/src/gateway/delegation-notify.ts +103 -0
- package/packages/core/src/gateway/durable-queue.ts +33 -2
- package/packages/core/src/gateway/helpers/index.ts +2 -2
- package/packages/core/src/gateway/helpers/narration.ts +12 -7
- package/packages/core/src/gateway/helpers/redact.ts +1 -1
- package/packages/core/src/gateway/initializer.ts +15 -13
- package/packages/core/src/gateway/job-executors.ts +232 -101
- package/packages/core/src/gateway/lane-queue.ts +1 -1
- package/packages/core/src/gateway/notification-inbox.ts +57 -0
- package/packages/core/src/gateway/resolver.ts +1 -23
- package/packages/core/src/gateway/routes/agents.ts +91 -1
- package/packages/core/src/gateway/routes/auth.ts +21 -42
- package/packages/core/src/gateway/routes/chat.ts +6 -6
- package/packages/core/src/gateway/routes/cron-api.ts +0 -4
- package/packages/core/src/gateway/routes/mcp.ts +0 -63
- package/packages/core/src/gateway/routes/meeting.ts +245 -0
- package/packages/core/src/gateway/routes/providers.ts +1 -0
- package/packages/core/src/gateway/routes/setup.ts +29 -24
- package/packages/core/src/gateway/routes/skills.ts +2 -2
- package/packages/core/src/gateway/routes/system.ts +23 -5
- package/packages/core/src/gateway/routes/users.ts +24 -1
- package/packages/core/src/gateway/server.ts +153 -117
- package/packages/core/src/gateway/session.ts +6 -4
- package/packages/core/src/gateway/slash-commands.ts +7 -6
- package/packages/core/src/gateway/webchat-turn.ts +34 -8
- package/packages/core/src/index.ts +3 -0
- package/packages/core/src/mcp/hot-reload.ts +14 -7
- package/packages/core/src/mcp/singleton.ts +0 -3
- package/packages/core/src/mcp/tool-sync.ts +2 -2
- package/packages/core/src/resilience/retry.ts +1 -1
- package/packages/core/src/scheduler/CronScheduler.ts +3 -1
- package/packages/core/src/scheduler/integration.ts +1 -1
- package/packages/core/src/storage/bootstrap.ts +25 -5
- package/packages/core/src/storage/collections.ts +201 -27
- package/packages/core/src/storage/onboarding.ts +147 -32
- package/packages/core/src/storage/reconcile.ts +2 -5
- package/packages/core/src/storage/seed.ts +202 -38
- package/packages/core/src/storage/usage.ts +0 -9
- package/packages/core/src/storage/user-email.ts +11 -0
- package/packages/core/src/tool-runtime/index.ts +69 -23
- package/packages/core/src/tool-runtime/worker-tools.ts +4 -2
- package/packages/core/src/{canvas/a2ui-tools.ts → tools/a2ui/index.ts} +17 -8
- package/packages/core/src/tools/agents/get-available-models.ts +11 -3
- package/packages/core/src/tools/agents/index.ts +404 -86
- package/packages/core/src/tools/core/index.ts +28 -10
- package/packages/core/src/tools/cron/index.ts +1 -6
- package/packages/core/src/tools/index.ts +17 -45
- package/packages/core/src/tools/types.ts +1 -1
- package/packages/core/src/tools/web/artifact-inspect.ts +23 -0
- package/packages/core/src/tools/web/browser-screenshot.ts +26 -5
- package/packages/core/src/tools/web/index.ts +3 -0
- package/packages/core/src/utils/logger.ts +58 -30
- package/packages/core/src/utils/toon.ts +0 -20
- package/packages/mcp/src/manager.ts +8 -7
- package/packages/mcp/src/transports/sse.ts +0 -4
- package/packages/mcp/src/transports/websocket.ts +0 -6
- package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_dashboard/SKILL.md +4 -4
- package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_form/SKILL.md +4 -4
- package/packages/skills/src/bundled/{canvas → a2ui}/a2ui_interactive/SKILL.md +5 -5
- package/packages/skills/src/bundled/agents/acceptance_verification/SKILL.md +26 -0
- package/packages/skills/src/bundled/agents/agent_spawner/SKILL.md +24 -18
- package/packages/skills/src/bundled/agents/task_orchestrator/SKILL.md +47 -148
- package/packages/skills/src/bundled/cli/cli_pipeline/SKILL.md +9 -10
- package/packages/skills/src/bundled/cli/cli_safe_exec/SKILL.md +1 -1
- package/packages/skills/src/bundled/cli/software_engineering/SKILL.md +23 -0
- package/packages/skills/src/bundled/cron_manager/SKILL.md +2 -2
- package/packages/skills/src/bundled/cron_reminder/SKILL.md +7 -7
- package/packages/skills/src/bundled/filesystem/file_read_and_summarize/SKILL.md +11 -10
- package/packages/skills/src/bundled/filesystem/file_writer/SKILL.md +29 -35
- package/packages/skills/src/bundled/filesystem/workspace_file_operator/SKILL.md +22 -0
- package/packages/skills/src/bundled/search_knowledge/capability_discovery/SKILL.md +5 -4
- package/packages/skills/src/bundled-data.generated.ts +155 -720
- package/dist/ui/assets/AgentCreateForm-DzaIT-dA.js +0 -1
- package/dist/ui/assets/AgentDetailPage-DgqcJceY.js +0 -1
- package/dist/ui/assets/AgentNewPage-CNSpoOSA.js +0 -1
- package/dist/ui/assets/AgentsPage-BMUJzTD6.js +0 -10
- package/dist/ui/assets/ApiClientPage-Cum_a_3j.js +0 -3
- package/dist/ui/assets/CanvasPage-o6oCP6uq.js +0 -33
- package/dist/ui/assets/ChannelsPage-WrB0zwLq.js +0 -8
- package/dist/ui/assets/DashboardPage-BCd6kNw0.js +0 -6
- package/dist/ui/assets/MeetingPage-BULIAWzq.js +0 -1
- package/dist/ui/assets/ModelSelector-BMYOChYb.js +0 -1
- package/dist/ui/assets/ProvidersPage-BVN5UZrI.js +0 -1
- package/dist/ui/assets/SettingsPage-CYmpFfDn.js +0 -9
- package/dist/ui/assets/SetupPage-Dnmb1Lbv.js +0 -1
- package/dist/ui/assets/WebChatPage-DmmdFhIC.js +0 -16
- package/dist/ui/assets/accordion-CnLzKNHK.js +0 -1
- package/dist/ui/assets/alert-B9J6KHmt.js +0 -1
- package/dist/ui/assets/alert-dialog-KcYQWcJ6.js +0 -1
- package/dist/ui/assets/arrow-left-CBcbX5EZ.js +0 -1
- package/dist/ui/assets/badge-88dRb4M8.js +0 -1
- package/dist/ui/assets/bell-8BqRYmzf.js +0 -1
- package/dist/ui/assets/chevron-down-DIosfU_U.js +0 -1
- package/dist/ui/assets/chevron-left-D4U-5A27.js +0 -1
- package/dist/ui/assets/chevron-right-CR4Skrf3.js +0 -1
- package/dist/ui/assets/chevron-up-CI-W21Fy.js +0 -1
- package/dist/ui/assets/circle-check-6Ard1-2z.js +0 -1
- package/dist/ui/assets/dropdown-menu-DDiaHg5y.js +0 -1
- package/dist/ui/assets/es-4I-joeZz.js +0 -1
- package/dist/ui/assets/folder-open-DJBLDFjv.js +0 -1
- package/dist/ui/assets/format-DsLPBxvt.js +0 -1
- package/dist/ui/assets/gauge-B8Tj43rC.js +0 -1
- package/dist/ui/assets/hexagon-6L79pgVK.js +0 -1
- package/dist/ui/assets/index-BmwTAwOF.css +0 -2
- package/dist/ui/assets/index-Cyw7L0Li.js +0 -116
- package/dist/ui/assets/key-DyKOoQh5.js +0 -1
- package/dist/ui/assets/label-B_15zZlR.js +0 -1
- package/dist/ui/assets/loader-circle-BmBOgYze.js +0 -1
- package/dist/ui/assets/lock-BS6OLXPv.js +0 -1
- package/dist/ui/assets/play-zJpWuhrr.js +0 -1
- package/dist/ui/assets/plus-BZQX26Dr.js +0 -1
- package/dist/ui/assets/progress-D5c-Eilm.js +0 -1
- package/dist/ui/assets/scroll-area-CihOx0cb.js +0 -1
- package/dist/ui/assets/search-DzDptO9s.js +0 -1
- package/dist/ui/assets/select-BQCOjM2j.js +0 -1
- package/dist/ui/assets/slider-bcUiUfx0.js +0 -14
- package/dist/ui/assets/switch-BR30E4ej.js +0 -1
- package/dist/ui/assets/table-B3aGEaVp.js +0 -1
- package/dist/ui/assets/tabs-LQidMKRS.js +0 -1
- package/dist/ui/assets/terminal--7G943As.js +0 -1
- package/dist/ui/assets/useProviders-C1xVKLxB.js +0 -1
- package/dist/ui/assets/utils-3pnRFmFe.js +0 -1
- package/dist/ui/assets/vendor-charts-Bu2lyBKP.js +0 -65
- package/dist/ui/assets/vendor-radix-D6rA7xKY.js +0 -63
- package/dist/ui/assets/vendor-react-BU5iQU4f.js +0 -1
- package/dist/ui/assets/volume-2-BekVQl6P.js +0 -1
- package/packages/core/src/agent/context-guard.ts +0 -91
- package/packages/core/src/agent/hooks.ts +0 -166
- package/packages/core/src/agent/providers.ts +0 -1
- package/packages/core/src/auth/auth.ts +0 -111
- package/packages/core/src/auth/index.ts +0 -1
- package/packages/core/src/canvas/canvas-tools.ts +0 -448
- package/packages/core/src/gateway/router.ts +0 -126
- package/packages/core/src/scheduler/dag/AgentExecutor.ts +0 -53
- package/packages/core/src/scheduler/dag/DAGScheduler.ts +0 -250
- package/packages/core/src/scheduler/dag/EventBridge.ts +0 -122
- package/packages/core/src/scheduler/dag/TaskGraph.ts +0 -192
- package/packages/core/src/scheduler/dag/TaskNode.ts +0 -97
- package/packages/core/src/scheduler/dag/TaskResult.ts +0 -22
- package/packages/core/src/scheduler/dag/errors.ts +0 -37
- package/packages/core/src/scheduler/dag/index.ts +0 -26
- package/packages/core/src/scheduler/dag/presets/ResearchPreset.ts +0 -97
- package/packages/core/src/scheduler/dag/strategies/ParallelStrategy.ts +0 -21
- package/packages/core/src/scheduler/dag/strategies/PriorityStrategy.ts +0 -46
- package/packages/core/src/scheduler/index.ts +0 -22
- package/packages/core/src/scheduler/task-driver.ts +0 -216
- package/packages/core/src/tools/canvas/index.ts +0 -420
- package/packages/core/src/tools/meeting/index.ts +0 -336
- package/packages/core/src/tools/projects/index.ts +0 -348
- package/packages/core/src/tools/voice/index.ts +0 -104
- package/packages/core/src/utils/index.ts +0 -5
- package/packages/skills/src/bundled/agents/code_delegator/SKILL.md +0 -156
- package/packages/skills/src/bundled/canvas/canvas_dashboard/SKILL.md +0 -146
- package/packages/skills/src/bundled/canvas/canvas_interact/SKILL.md +0 -148
- package/packages/skills/src/bundled/canvas/canvas_report/SKILL.md +0 -146
- package/packages/skills/src/bundled/meeting/meeting_transcription/SKILL.md +0 -213
- package/packages/skills/src/bundled/voice/voice_assistant/SKILL.md +0 -174
- package/packages/skills/src/bundled/voice/voice_input/SKILL.md +0 -146
- package/packages/skills/src/bundled/voice/voice_output/SKILL.md +0 -151
|
@@ -20,7 +20,6 @@ import rootPackage from "../../../../package.json";
|
|
|
20
20
|
// Static JSON import lets Bun inline the release version into npm bundles and
|
|
21
21
|
// standalone executables instead of depending on a package.json at runtime.
|
|
22
22
|
const _pkgVersion = rootPackage.version;
|
|
23
|
-
import { cpus as osCpus } from "node:os";
|
|
24
23
|
import { ensureHiveDb } from "../storage/bootstrap";
|
|
25
24
|
import { col, fromIndexable, nextId } from "../storage/hive";
|
|
26
25
|
import { reconcileOnBoot } from "../storage/reconcile";
|
|
@@ -29,12 +28,11 @@ import { stopAllLeaseRenewals, interruptRun, findRunsByStatus } from "../agent/r
|
|
|
29
28
|
import { shutdownToolRuntime } from "../tool-runtime";
|
|
30
29
|
import { initDurableQueue, getDurableQueue } from "./durable-queue";
|
|
31
30
|
import { initJobExecutors, setJobExecutorMCPManager } from "./job-executors";
|
|
31
|
+
import { initDelegationNotify } from "./delegation-notify";
|
|
32
32
|
import { findAllPendingJobs, findExpiredLeases, loadJobRetryPolicy } from "./job-store";
|
|
33
|
-
import { initTaskDriver } from "../scheduler/task-driver";
|
|
34
33
|
import type { UserDoc, AgentDoc } from "../storage/collections";
|
|
35
34
|
import { canvasManager } from "../canvas/canvas-manager.ts";
|
|
36
|
-
import { subscribeCanvas, unsubscribeCanvas, emitCanvas, getCanvasSnapshot
|
|
37
|
-
import { resolveCanvasInteraction } from "../tools/canvas/index";
|
|
35
|
+
import { subscribeCanvas, unsubscribeCanvas, emitCanvas, getCanvasSnapshot } from "../canvas/emitter";
|
|
38
36
|
import { randomUUID } from "crypto";
|
|
39
37
|
import { circuitBreakerRegistry } from "../resilience/circuit-breaker.ts";
|
|
40
38
|
import { loadMcpHeaders } from "../storage/crypto.ts";
|
|
@@ -45,7 +43,7 @@ import { initializeGateway, type GatewayInitializationResult } from "./initializ
|
|
|
45
43
|
import { handleSetupStatus, handleVerifyProvider, handleCompleteSetup, handleSetupProviders, handleSetupEthics, handleSetupOllamaModels } from "./routes/setup";
|
|
46
44
|
import { handleAuthStatus, handleLogin, handleSetupCredentials, handleChangePassword, handleRecover, handleDisableAuth, handleRecoveryKey } from "./routes/auth";
|
|
47
45
|
import { resolveUserId } from "../storage/onboarding";
|
|
48
|
-
import { handleGetAgents, handleCreateAgent, handleUpdateAgent, handleDeleteAgent } from "./routes/agents";
|
|
46
|
+
import { handleGetAgents, handleCreateAgent, handleUpdateAgent, handleDeleteAgent, handleGetAgentProposals } from "./routes/agents";
|
|
49
47
|
import { handleGetProviders, handleCreateProvider, handleToggleProvider, handleUpdateProvider, handleSyncProviderModels, handleLoadHiveAgentsModel, handleGetHiveAgentsModelStatus } from "./routes/providers";
|
|
50
48
|
import { handleGetUsers, handleCreateUser, handleUpdateUserSettings, handleGetUserChannels, handleLinkUserChannel } from "./routes/users";
|
|
51
49
|
import { handleGetSkills, handleActivateSkill, handleUpdateSkill, handleDeleteSkill, handleCreateSkill } from "./routes/skills";
|
|
@@ -53,8 +51,13 @@ import { handleGetEthics, handleActivateEthics, handleDeleteEthics } from "./rou
|
|
|
53
51
|
import { handleGetTools, handleActivateTool, handleUpdateTool } from "./routes/tools";
|
|
54
52
|
import { handleGetTasks, handleUpdateTask } from "./routes/tasks";
|
|
55
53
|
import { setChannelSendFn } from "./channel-notify";
|
|
54
|
+
import {
|
|
55
|
+
acknowledgeNotification,
|
|
56
|
+
listPendingNotifications,
|
|
57
|
+
markNotificationDelivered,
|
|
58
|
+
} from "./notification-inbox";
|
|
59
|
+
import { setNarrationDelivery } from "../events/narration";
|
|
56
60
|
import { CronScheduler } from "../scheduler/CronScheduler";
|
|
57
|
-
import { DAGScheduler, ParallelStrategy } from "../scheduler/dag/index";
|
|
58
61
|
import { createTaskHandler, setSchedulerForCleanup } from "../scheduler/integration";
|
|
59
62
|
|
|
60
63
|
import { setSchedulerInstance as setScheduleToolsInstance } from "../tools/cron/index.ts";
|
|
@@ -78,9 +81,9 @@ import { handleGetModels, handleCreateModel, handleToggleModel, handleGetModelsC
|
|
|
78
81
|
import { handleGetVoiceProviders, handleGetConfiguredVoiceProviders, handleSaveVoiceProviderKey, handleTestVoice, handleGetChannelVoice, handleUpdateChannelVoice, handleGetVoiceProviderVoices } from "./routes/voice";
|
|
79
82
|
import { handleGetVisionProviders, handleGetChannelVision, handleUpdateChannelVision, handleOcrImage } from "./routes/multimodal";
|
|
80
83
|
import { handleGetLocalTTSStatus, handleGetLocalTTSLogs, handleInstallLocalTTS, handleStartLocalTTS, handleStopLocalTTS, handleSpeakLocalTTS, handleGetAvailableModels, handleGetInstalledVoices, handleDownloadModel, handleGetDownloadLogs, initializeLocalTTS } from "./routes/tts-local";
|
|
81
|
-
import { handleCreateMeeting, handleListMeetings, handleGetMeeting, handleAddMeetingSegment, handleStopMeeting } from "./routes/meeting";
|
|
84
|
+
import { handleCreateMeeting, handleListMeetings, handleGetMeeting, handleAddMeetingSegment, handleStopMeeting, handleGenerateMeetingReport, handleDownloadMeetingReport } from "./routes/meeting";
|
|
82
85
|
import { handleGetActivityStats, handleGetSystemStats, handleGetUsageStats, handleSystemReload, handleApiReload, handleGetVersion, handleTriggerUpdate } from "./routes/system";
|
|
83
|
-
import { handleGetChatHistory,
|
|
86
|
+
import { handleGetChatHistory, handleGetNotes, handleUpdateNote } from "./routes/chat";
|
|
84
87
|
import { handleChat as handlePostChat } from "./routes/chat";
|
|
85
88
|
import { handleGetConfig } from "./routes/config";
|
|
86
89
|
import { handleHttpRequest } from "./routes/http-client";
|
|
@@ -120,10 +123,6 @@ export async function startGateway(
|
|
|
120
123
|
// FIX 2 — startTime para calcular uptime en /status y /api/agents
|
|
121
124
|
const startTime = Date.now();
|
|
122
125
|
|
|
123
|
-
// CPU delta sampling — process.cpuUsage() is cumulative; we diff between calls
|
|
124
|
-
const numCores = osCpus().length || 1;
|
|
125
|
-
let lastCpuSample = process.cpuUsage();
|
|
126
|
-
let lastCpuSampleTime = Date.now();
|
|
127
126
|
const log = logger.child("gateway");
|
|
128
127
|
|
|
129
128
|
log.info(`Starting gateway on ${host}:${port}`);
|
|
@@ -209,8 +208,38 @@ export async function startGateway(
|
|
|
209
208
|
await initializeLocalTTS();
|
|
210
209
|
|
|
211
210
|
// Conectar channel-notify singleton para que las tools (notify, report_progress) puedan enviar mensajes
|
|
212
|
-
setChannelSendFn(async (channel, sessionId, content) => {
|
|
213
|
-
await channelManager.send(channel, sessionId, {
|
|
211
|
+
setChannelSendFn(async (channel, sessionId, content, metadata) => {
|
|
212
|
+
await channelManager.send(channel, sessionId, {
|
|
213
|
+
content,
|
|
214
|
+
type: metadata?.notificationId ? "notification" : "progress",
|
|
215
|
+
sessionId,
|
|
216
|
+
notificationId: metadata?.notificationId,
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
setNarrationDelivery(async (event) => {
|
|
220
|
+
if (event.channel === "webchat" && event.session_id) {
|
|
221
|
+
const session = sessionManager.get(event.session_id);
|
|
222
|
+
if (session?.ws && session.ws.readyState === 1) {
|
|
223
|
+
session.ws.send(JSON.stringify({
|
|
224
|
+
type: "process",
|
|
225
|
+
sessionId: event.session_id,
|
|
226
|
+
id: event.id,
|
|
227
|
+
messageId: event.turn_id,
|
|
228
|
+
processKind: event.kind === "tool_call" ? "tool" : "observation",
|
|
229
|
+
processStatus: event.status === "error" ? "error" : event.status === "done" ? "done" : "thinking",
|
|
230
|
+
label: event.label,
|
|
231
|
+
detail: event.detail,
|
|
232
|
+
timestamp: new Date(event.created_at).toISOString(),
|
|
233
|
+
}));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (event.channel && event.session_id) {
|
|
238
|
+
await channelManager.send(event.channel, event.session_id, {
|
|
239
|
+
content: event.detail ? `${event.label}: ${event.detail}` : event.label,
|
|
240
|
+
type: "progress",
|
|
241
|
+
});
|
|
242
|
+
}
|
|
214
243
|
});
|
|
215
244
|
|
|
216
245
|
if (gatewaySetupMode) {
|
|
@@ -241,12 +270,11 @@ export async function startGateway(
|
|
|
241
270
|
getProvider: () => dbProvider,
|
|
242
271
|
getModel: () => dbModel,
|
|
243
272
|
});
|
|
273
|
+
// Closes the async task_delegate loop: relays worker_task outcomes
|
|
274
|
+
// back into the delegating conversation (see delegation-notify.ts).
|
|
275
|
+
initDelegationNotify();
|
|
244
276
|
log.info(`🔀 DurableQueue initialized (maxConcurrency=${durableQueue.getMaxGlobalConcurrency()})`);
|
|
245
277
|
|
|
246
|
-
// Initialize TaskDriver (project/task engine)
|
|
247
|
-
initTaskDriver();
|
|
248
|
-
log.info("📋 TaskDriver initialized");
|
|
249
|
-
|
|
250
278
|
// Create and boot scheduler
|
|
251
279
|
const handler = createTaskHandler();
|
|
252
280
|
const scheduler = new CronScheduler(handler);
|
|
@@ -258,11 +286,6 @@ export async function startGateway(
|
|
|
258
286
|
setSchedulerForCleanup(scheduler);
|
|
259
287
|
|
|
260
288
|
log.info(`📅 CronScheduler initialized with ${(await scheduler.getStatus()).length} task(s)`);
|
|
261
|
-
|
|
262
|
-
// Register DAGScheduler as a global service (opt-in by swarms)
|
|
263
|
-
const dagScheduler = new DAGScheduler({ strategy: new ParallelStrategy(), maxConcurrentWorkers: 2 });
|
|
264
|
-
(globalThis as any).__dagScheduler = dagScheduler;
|
|
265
|
-
log.info("🔀 DAGScheduler ready");
|
|
266
289
|
} catch (err) {
|
|
267
290
|
log.error(`❌ CronScheduler initialization failed: ${(err as Error).message}`);
|
|
268
291
|
}
|
|
@@ -525,6 +548,7 @@ export async function startGateway(
|
|
|
525
548
|
try {
|
|
526
549
|
log.info(`🤖 Routing to agent loop...`);
|
|
527
550
|
|
|
551
|
+
const turnId = randomUUID();
|
|
528
552
|
const response = await runner.generate({
|
|
529
553
|
provider: dbProvider as any,
|
|
530
554
|
messages,
|
|
@@ -535,41 +559,11 @@ export async function startGateway(
|
|
|
535
559
|
threadId: unifiedSessionId,
|
|
536
560
|
userId,
|
|
537
561
|
channel: message.channel,
|
|
562
|
+
turnId,
|
|
563
|
+
sessionId: routingSessionId,
|
|
538
564
|
onStep: async (step) => {
|
|
539
|
-
//
|
|
540
|
-
|
|
541
|
-
const trimmedMessage = (typeof step.message === "string" ? step.message : "").trim();
|
|
542
|
-
if (trimmedMessage) {
|
|
543
|
-
log.debug(`[NARRATION] ${trimmedMessage.substring(0, 100)}`);
|
|
544
|
-
try {
|
|
545
|
-
await channelManager.send(message.channel, routingSessionId, {
|
|
546
|
-
content: trimmedMessage,
|
|
547
|
-
type: "progress",
|
|
548
|
-
});
|
|
549
|
-
} catch (err) {
|
|
550
|
-
log.warn(`[onStep] Narration send failed: ${(err as Error).message}`);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// "tool_call" = el agente va a ejecutar una herramienta → narrar al usuario
|
|
557
|
-
if (step.type === "tool_call" && step.toolName) {
|
|
558
|
-
const narration = getNarration(step.toolName);
|
|
559
|
-
log.debug(`[TOOL] ${step.toolName} → "${narration}"`);
|
|
560
|
-
try {
|
|
561
|
-
await channelManager.send(message.channel, routingSessionId, {
|
|
562
|
-
content: narration,
|
|
563
|
-
type: "progress",
|
|
564
|
-
});
|
|
565
|
-
} catch (err) {
|
|
566
|
-
log.warn(`[onStep] Tool narration send failed: ${(err as Error).message}`);
|
|
567
|
-
}
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// "tool_result" = resultado de la herramienta
|
|
572
|
-
// Solo enviamos al usuario si el resultado lo pide explícitamente
|
|
565
|
+
// Explicit tool-authored progress remains supported. Ordinary agent
|
|
566
|
+
// and tool lifecycle narration is emitted by the domain service.
|
|
573
567
|
if (step.type === "tool_result" && step.message) {
|
|
574
568
|
try {
|
|
575
569
|
const result = JSON.parse(step.message);
|
|
@@ -592,7 +586,9 @@ export async function startGateway(
|
|
|
592
586
|
},
|
|
593
587
|
});
|
|
594
588
|
|
|
595
|
-
const
|
|
589
|
+
const { sealDelegationGroup } = await import("./delegation-groups");
|
|
590
|
+
const delegationGroup = await sealDelegationGroup(turnId);
|
|
591
|
+
const responseContent = delegationGroup ? "" : response.content?.trim() || "";
|
|
596
592
|
if (!responseContent) {
|
|
597
593
|
log.warn(`📤 LLM response: empty — skipping send`);
|
|
598
594
|
return;
|
|
@@ -1272,6 +1268,10 @@ export async function startGateway(
|
|
|
1272
1268
|
return await handleGetAgents(req, addCorsHeaders)
|
|
1273
1269
|
}
|
|
1274
1270
|
|
|
1271
|
+
if (url.pathname === "/api/agents/proposals" && req.method === "GET") {
|
|
1272
|
+
return await handleGetAgentProposals(req, addCorsHeaders)
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
1275
|
if (url.pathname === "/api/agents" && req.method === "POST") {
|
|
1276
1276
|
return await handleCreateAgent(req, addCorsHeaders)
|
|
1277
1277
|
}
|
|
@@ -1506,7 +1506,10 @@ export async function startGateway(
|
|
|
1506
1506
|
const newServersConfig = { ...currentConfig.servers }
|
|
1507
1507
|
newServersConfig[mcpName] = mcpServerConfig
|
|
1508
1508
|
|
|
1509
|
-
//
|
|
1509
|
+
// Register the server (or refresh its config) — this alone does not
|
|
1510
|
+
// connect: updateConfig() only (re)connects a server whose config
|
|
1511
|
+
// actually changed, so an already-registered dormant server needs an
|
|
1512
|
+
// explicit connect below.
|
|
1510
1513
|
await mcp.updateConfig({
|
|
1511
1514
|
...currentConfig,
|
|
1512
1515
|
servers: newServersConfig,
|
|
@@ -1514,6 +1517,12 @@ export async function startGateway(
|
|
|
1514
1517
|
|
|
1515
1518
|
log.info(`[MCP] Server registered in MCP Manager`)
|
|
1516
1519
|
|
|
1520
|
+
// Explicitly wake the server — connectServer() is a no-op if it's
|
|
1521
|
+
// already connected, so this is safe to call unconditionally.
|
|
1522
|
+
await mcp.connectServer(mcpName).catch((err: Error) => {
|
|
1523
|
+
log.error(`[MCP] Connect attempt failed for ${mcpName}: ${err.message}`);
|
|
1524
|
+
});
|
|
1525
|
+
|
|
1517
1526
|
// Get tools after connection
|
|
1518
1527
|
const tools = mcp.getServerTools(mcpName) || [];
|
|
1519
1528
|
const serverDetails = mcp.getServerDetails?.(mcpName);
|
|
@@ -1608,7 +1617,10 @@ export async function startGateway(
|
|
|
1608
1617
|
const newServersConfig = { ...currentConfig.servers }
|
|
1609
1618
|
newServersConfig[mcpName] = mcpServerConfig
|
|
1610
1619
|
|
|
1611
|
-
//
|
|
1620
|
+
// Register the server (or refresh its config) — this alone does not
|
|
1621
|
+
// connect: updateConfig() only (re)connects a server whose config
|
|
1622
|
+
// actually changed, so an already-registered dormant server needs an
|
|
1623
|
+
// explicit connect below.
|
|
1612
1624
|
await mcp.updateConfig({
|
|
1613
1625
|
...currentConfig,
|
|
1614
1626
|
servers: newServersConfig,
|
|
@@ -1616,6 +1628,12 @@ export async function startGateway(
|
|
|
1616
1628
|
|
|
1617
1629
|
log.info(`[MCP] Server registered in MCP Manager`)
|
|
1618
1630
|
|
|
1631
|
+
// Explicitly wake the server — connectServer() is a no-op if it's
|
|
1632
|
+
// already connected, so this is safe to call unconditionally.
|
|
1633
|
+
await mcp.connectServer(mcpName).catch((err: Error) => {
|
|
1634
|
+
log.error(`[MCP] Connect attempt failed for ${mcpName}: ${err.message}`);
|
|
1635
|
+
});
|
|
1636
|
+
|
|
1619
1637
|
// Get tools after connection
|
|
1620
1638
|
const tools = mcp.getServerTools(mcpName) || [];
|
|
1621
1639
|
const serverDetails2 = mcp.getServerDetails?.(mcpName);
|
|
@@ -1814,7 +1832,17 @@ export async function startGateway(
|
|
|
1814
1832
|
return await handleStopMeeting(req, addCorsHeaders, meetingStopMatch[1]);
|
|
1815
1833
|
}
|
|
1816
1834
|
|
|
1817
|
-
|
|
1835
|
+
const meetingReportMatch = url.pathname.match(/^\/api\/meetings\/([^/]+)\/report$/);
|
|
1836
|
+
if (meetingReportMatch && req.method === "POST") {
|
|
1837
|
+
return await handleGenerateMeetingReport(req, addCorsHeaders, meetingReportMatch[1]);
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
const meetingReportDownloadMatch = url.pathname.match(/^\/api\/meetings\/([^/]+)\/report\/download$/);
|
|
1841
|
+
if (meetingReportDownloadMatch && req.method === "GET") {
|
|
1842
|
+
return await handleDownloadMeetingReport(req, addCorsHeaders, meetingReportDownloadMatch[1]);
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
// ── Chat / Notes API ────────────────────────────────────────────────
|
|
1818
1846
|
if (url.pathname === "/api/chat/history" && req.method === "GET") {
|
|
1819
1847
|
return await handleGetChatHistory(req, addCorsHeaders)
|
|
1820
1848
|
}
|
|
@@ -1823,10 +1851,6 @@ export async function startGateway(
|
|
|
1823
1851
|
return await handlePostChat(req, addCorsHeaders)
|
|
1824
1852
|
}
|
|
1825
1853
|
|
|
1826
|
-
if (url.pathname === "/api/canvas" && req.method === "GET") {
|
|
1827
|
-
return await handleGetCanvas(req, addCorsHeaders)
|
|
1828
|
-
}
|
|
1829
|
-
|
|
1830
1854
|
if (url.pathname === "/api/notes" && req.method === "GET") {
|
|
1831
1855
|
return await handleGetNotes(req, addCorsHeaders)
|
|
1832
1856
|
}
|
|
@@ -1904,6 +1928,26 @@ export async function startGateway(
|
|
|
1904
1928
|
websocket: {
|
|
1905
1929
|
async open(ws) {
|
|
1906
1930
|
const data = ws.data;
|
|
1931
|
+
|
|
1932
|
+
// ── Heartbeat a nivel de protocolo (todos los sockets) ──────────────
|
|
1933
|
+
// ws.ping() usa frames ping/pong WebSocket: el navegador responde pong
|
|
1934
|
+
// automáticamente incluso con la pestaña en segundo plano (los timers
|
|
1935
|
+
// JS se throttle-an, los frames de protocolo no). Si no hay señal de
|
|
1936
|
+
// vida en 90s (pong, mensaje o ping), cerramos para que el cliente
|
|
1937
|
+
// reconecte en lugar de quedar zombi.
|
|
1938
|
+
(data as any)._lastSeen = Date.now();
|
|
1939
|
+
const hbInterval = setInterval(() => {
|
|
1940
|
+
try {
|
|
1941
|
+
if (ws.readyState !== 1) return;
|
|
1942
|
+
ws.ping();
|
|
1943
|
+
const lastSeen = (data as any)._lastSeen ?? 0;
|
|
1944
|
+
if (Date.now() - lastSeen > 90_000) {
|
|
1945
|
+
try { ws.close(4000, "heartbeat timeout"); } catch { /* ignore */ }
|
|
1946
|
+
}
|
|
1947
|
+
} catch { /* ignore */ }
|
|
1948
|
+
}, 25_000);
|
|
1949
|
+
(data as any)._hbInterval = hbInterval;
|
|
1950
|
+
|
|
1907
1951
|
// ── Meeting Stream ─────────────────────────────────────────────────────
|
|
1908
1952
|
if (data.sessionId.startsWith("meeting:")) {
|
|
1909
1953
|
log.info(`Meeting stream client connected: ${data.sessionId}`);
|
|
@@ -1964,6 +2008,7 @@ export async function startGateway(
|
|
|
1964
2008
|
|
|
1965
2009
|
async message(ws, message) {
|
|
1966
2010
|
const data = ws.data;
|
|
2011
|
+
(data as any)._lastSeen = Date.now();
|
|
1967
2012
|
|
|
1968
2013
|
// Bridge events clients are read-only; only respond to ping keepalive
|
|
1969
2014
|
if (data.sessionId.startsWith("bridge:")) {
|
|
@@ -2064,6 +2109,28 @@ export async function startGateway(
|
|
|
2064
2109
|
return;
|
|
2065
2110
|
}
|
|
2066
2111
|
|
|
2112
|
+
if (msg.type === "notification_sync") {
|
|
2113
|
+
const pending = await listPendingNotifications(data.sessionId, "webchat");
|
|
2114
|
+
for (const notification of pending) {
|
|
2115
|
+
ws.send(JSON.stringify({
|
|
2116
|
+
type: "notification",
|
|
2117
|
+
sessionId: data.sessionId,
|
|
2118
|
+
notificationId: notification.id,
|
|
2119
|
+
content: notification.message,
|
|
2120
|
+
createdAt: notification.created_at,
|
|
2121
|
+
} as OutboundMessage));
|
|
2122
|
+
await markNotificationDelivered(notification.id, data.sessionId);
|
|
2123
|
+
}
|
|
2124
|
+
return;
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
if (msg.type === "notification_ack") {
|
|
2128
|
+
if (msg.notificationId) {
|
|
2129
|
+
await acknowledgeNotification(msg.notificationId, data.sessionId);
|
|
2130
|
+
}
|
|
2131
|
+
return;
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2067
2134
|
// Canvas subscribe
|
|
2068
2135
|
if (msg.type === "canvas_subscribe") {
|
|
2069
2136
|
subscribeCanvas(ws);
|
|
@@ -2078,7 +2145,7 @@ export async function startGateway(
|
|
|
2078
2145
|
// Canvas unsubscribe
|
|
2079
2146
|
if (msg.type === "canvas_unsubscribe") {
|
|
2080
2147
|
unsubscribeCanvas(ws);
|
|
2081
|
-
canvasManager.unregisterSession(`canvas:${data.sessionId}
|
|
2148
|
+
canvasManager.unregisterSession(`canvas:${data.sessionId}`, ws);
|
|
2082
2149
|
return;
|
|
2083
2150
|
}
|
|
2084
2151
|
|
|
@@ -2109,50 +2176,6 @@ export async function startGateway(
|
|
|
2109
2176
|
return;
|
|
2110
2177
|
}
|
|
2111
2178
|
|
|
2112
|
-
// Canvas interactions from the main session — route to canvasManager and local resolver
|
|
2113
|
-
if (msg.type === "canvas:interact") {
|
|
2114
|
-
const { componentId } = msg;
|
|
2115
|
-
let resolvedByPending = false;
|
|
2116
|
-
if (componentId) {
|
|
2117
|
-
removeCanvasComponent(componentId);
|
|
2118
|
-
// Resolve local pending interactions (canvas_confirm tool)
|
|
2119
|
-
resolvedByPending = resolveCanvasInteraction(componentId, msg.data);
|
|
2120
|
-
}
|
|
2121
|
-
const canvasSessionId = `canvas:${data.sessionId}`;
|
|
2122
|
-
canvasManager.handleMessage(canvasSessionId, JSON.stringify(msg));
|
|
2123
|
-
|
|
2124
|
-
// If no tool was waiting for this interaction, forward it to the agent as a new turn
|
|
2125
|
-
if (!resolvedByPending) {
|
|
2126
|
-
const interactionData = msg.data as Record<string, unknown> | undefined;
|
|
2127
|
-
const action = (msg as any).action as string | undefined;
|
|
2128
|
-
|
|
2129
|
-
// Build a human-readable message describing what the user clicked
|
|
2130
|
-
let interactionMsg = `[canvas:interact] componentId=${componentId ?? "unknown"}, action=${action ?? "click"}`;
|
|
2131
|
-
if (interactionData && Object.keys(interactionData).length > 0) {
|
|
2132
|
-
interactionMsg += `, data=${JSON.stringify(interactionData)}`;
|
|
2133
|
-
}
|
|
2134
|
-
|
|
2135
|
-
log.info(`Canvas interaction forwarded to agent: ${interactionMsg}`);
|
|
2136
|
-
|
|
2137
|
-
const sessionId = data.sessionId;
|
|
2138
|
-
|
|
2139
|
-
ws.send(JSON.stringify({ type: "typing", isTyping: true, sessionId } as OutboundMessage));
|
|
2140
|
-
|
|
2141
|
-
enqueueChatTurn({
|
|
2142
|
-
lane: sessionId,
|
|
2143
|
-
payload: { source: "canvas", sessionId, content: interactionMsg },
|
|
2144
|
-
live: { sendRaw: (payload) => ws.send(payload) },
|
|
2145
|
-
}).catch((error) => {
|
|
2146
|
-
ws.send(JSON.stringify({ type: "typing", isTyping: false, sessionId } as OutboundMessage));
|
|
2147
|
-
ws.send(JSON.stringify({ type: "error", sessionId, error: (error as Error).message } as OutboundMessage));
|
|
2148
|
-
log.error(`Canvas interact enqueue error: ${(error as Error).message}`);
|
|
2149
|
-
});
|
|
2150
|
-
}
|
|
2151
|
-
|
|
2152
|
-
return;
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
// Canvas session - handle interactions
|
|
2156
2179
|
if (msg.type === "command" || (msg.content && isSlashCommand(msg.content))) {
|
|
2157
2180
|
const result = await executeSlashCommand(msg.sessionId, msg.content ?? `/${msg.command}`, ws);
|
|
2158
2181
|
if (result) {
|
|
@@ -2316,8 +2339,22 @@ export async function startGateway(
|
|
|
2316
2339
|
} as OutboundMessage));
|
|
2317
2340
|
},
|
|
2318
2341
|
|
|
2342
|
+
// Frames de protocolo: cualquier señal de vida resetea el watchdog
|
|
2343
|
+
ping(ws) {
|
|
2344
|
+
(ws.data as any)._lastSeen = Date.now();
|
|
2345
|
+
try { ws.pong(); } catch { /* ignore */ }
|
|
2346
|
+
},
|
|
2347
|
+
|
|
2348
|
+
pong(ws) {
|
|
2349
|
+
(ws.data as any)._lastSeen = Date.now();
|
|
2350
|
+
},
|
|
2351
|
+
|
|
2319
2352
|
close(ws) {
|
|
2320
2353
|
const data = ws.data;
|
|
2354
|
+
if ((data as any)._hbInterval) {
|
|
2355
|
+
clearInterval((data as any)._hbInterval);
|
|
2356
|
+
(data as any)._hbInterval = null;
|
|
2357
|
+
}
|
|
2321
2358
|
if (data.sessionId.startsWith("meeting:")) {
|
|
2322
2359
|
log.info(`Meeting stream client disconnected: ${data.sessionId}`);
|
|
2323
2360
|
return;
|
|
@@ -2330,14 +2367,13 @@ export async function startGateway(
|
|
|
2330
2367
|
}
|
|
2331
2368
|
|
|
2332
2369
|
log.debug(`WebSocket disconnected: ${data.sessionId}`);
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
getDurableQueue().cancelLane(data.sessionId).catch(() => {});
|
|
2370
|
+
const wasCurrentSession = sessionManager.deleteIfOwner(data.sessionId, ws);
|
|
2371
|
+
if (wasCurrentSession) logSubscribers.delete(data.sessionId);
|
|
2336
2372
|
unsubscribeCanvas(ws);
|
|
2337
|
-
canvasManager.unregisterSession(`canvas:${data.sessionId}
|
|
2373
|
+
canvasManager.unregisterSession(`canvas:${data.sessionId}`, ws);
|
|
2338
2374
|
|
|
2339
2375
|
const channel = channelManager?.getChannel("webchat") as any;
|
|
2340
|
-
if (channel?.unregisterConnection) channel.unregisterConnection(data.sessionId);
|
|
2376
|
+
if (channel?.unregisterConnection) channel.unregisterConnection(data.sessionId, ws);
|
|
2341
2377
|
},
|
|
2342
2378
|
},
|
|
2343
2379
|
});
|
|
@@ -2377,7 +2413,7 @@ export async function startGateway(
|
|
|
2377
2413
|
log.info(`[gateway] UI: ${devUrl}`);
|
|
2378
2414
|
log.info(`[gateway] API: http://${host}:${port}`);
|
|
2379
2415
|
log.info(`[gateway] WebSocket: ws://${host}:${port}/ws`);
|
|
2380
|
-
log.info(`[gateway]
|
|
2416
|
+
log.info(`[gateway] Actividad: ws://${host}:${port}/canvas`);
|
|
2381
2417
|
log.info(`[gateway] Modo: desarrollo`);
|
|
2382
2418
|
if (!isGatewayChild) {
|
|
2383
2419
|
log.info(gatewaySetupMode ? `🎉 Primer arranque — abriendo setup...` : `🐝 Administra tu Hive aquí: ${devUrl}`);
|
|
@@ -2391,7 +2427,7 @@ export async function startGateway(
|
|
|
2391
2427
|
log.info(`[gateway] UI: ${uiUrl}`);
|
|
2392
2428
|
log.info(`[gateway] API: http://${host}:${port}`);
|
|
2393
2429
|
log.info(`[gateway] WebSocket: ws://${host}:${port}/ws`);
|
|
2394
|
-
log.info(`[gateway]
|
|
2430
|
+
log.info(`[gateway] Actividad: ws://${host}:${port}/canvas`);
|
|
2395
2431
|
|
|
2396
2432
|
// Always open browser on startup (setup and normal mode).
|
|
2397
2433
|
// Set NO_BROWSER=1 to skip in headless/server environments (e.g. CLI parent manages the browser).
|
|
@@ -11,10 +11,6 @@ export function parseSessionId(sessionId: string): SessionId | null {
|
|
|
11
11
|
return { userId: sessionId };
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export function formatSessionId(session: SessionId): string {
|
|
15
|
-
return session.userId;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
14
|
export interface Session {
|
|
19
15
|
id: string;
|
|
20
16
|
parsed: SessionId;
|
|
@@ -73,6 +69,12 @@ export class SessionManager {
|
|
|
73
69
|
return this.sessions.delete(sessionId);
|
|
74
70
|
}
|
|
75
71
|
|
|
72
|
+
deleteIfOwner(sessionId: string, ws: ServerWebSocket<unknown>): boolean {
|
|
73
|
+
const session = this.sessions.get(sessionId);
|
|
74
|
+
if (!session || session.ws !== ws) return false;
|
|
75
|
+
return this.sessions.delete(sessionId);
|
|
76
|
+
}
|
|
77
|
+
|
|
76
78
|
list(): Session[] {
|
|
77
79
|
return Array.from(this.sessions.values());
|
|
78
80
|
}
|
|
@@ -4,16 +4,15 @@ import { laneQueue } from "./lane-queue.ts";
|
|
|
4
4
|
import { logger } from "../utils/logger.ts";
|
|
5
5
|
|
|
6
6
|
export interface InboundMessage {
|
|
7
|
-
type: "message" | "command" | "ping" | "join" | "canvas_subscribe" | "canvas_unsubscribe" | "logs_subscribe" | "logs_unsubscribe" | "audio" | "
|
|
7
|
+
type: "message" | "command" | "ping" | "join" | "canvas_subscribe" | "canvas_unsubscribe" | "logs_subscribe" | "logs_unsubscribe" | "audio" | "a2ui:action" | "stop" | "notification_sync" | "notification_ack";
|
|
8
8
|
sessionId: string;
|
|
9
9
|
content?: string;
|
|
10
10
|
audio?: string;
|
|
11
11
|
command?: string;
|
|
12
12
|
args?: string[];
|
|
13
13
|
metadata?: Record<string, unknown>;
|
|
14
|
-
componentId?: string;
|
|
15
14
|
data?: Record<string, unknown>;
|
|
16
|
-
|
|
15
|
+
notificationId?: string;
|
|
17
16
|
image?: {
|
|
18
17
|
base64: string;
|
|
19
18
|
mimeType?: string;
|
|
@@ -27,11 +26,13 @@ export interface InboundMessage {
|
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
export interface OutboundMessage {
|
|
30
|
-
type: "message" | "stream" | "status" | "error" | "pong" | "command_result" | "joined" | "typing" | "audio" | "welcome" | "progress" | "process" | "reasoning";
|
|
29
|
+
type: "message" | "stream" | "status" | "error" | "pong" | "command_result" | "joined" | "typing" | "audio" | "welcome" | "progress" | "process" | "reasoning" | "notification";
|
|
31
30
|
sessionId: string;
|
|
32
31
|
id?: string; // Message ID for streaming
|
|
33
32
|
messageId?: string;
|
|
34
33
|
content?: string;
|
|
34
|
+
notificationId?: string;
|
|
35
|
+
createdAt?: number;
|
|
35
36
|
chunk?: string;
|
|
36
37
|
isChunk?: boolean; // True if this is a streaming chunk
|
|
37
38
|
isLast?: boolean;
|
|
@@ -80,7 +81,7 @@ export interface SlashCommand {
|
|
|
80
81
|
|
|
81
82
|
const slashCommands = new Map<string, SlashCommand>();
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
function registerSlashCommand(command: SlashCommand): void {
|
|
84
85
|
slashCommands.set(command.name, command);
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -88,7 +89,7 @@ export function isSlashCommand(content: string): boolean {
|
|
|
88
89
|
return content.startsWith("/") && content.length > 1;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
function parseSlashCommand(content: string): { name: string; args: string[] } | null {
|
|
92
93
|
if (!isSlashCommand(content)) return null;
|
|
93
94
|
|
|
94
95
|
const parts = content.slice(1).split(/\s+/);
|
|
@@ -21,12 +21,13 @@ 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 type { JobDoc } from "../storage/collections";
|
|
24
|
+
import type { JobDoc, TurnSource } from "../storage/collections";
|
|
25
25
|
|
|
26
26
|
const log = logger.child("webchat-turn");
|
|
27
27
|
|
|
28
28
|
export interface WebchatTurnPayload {
|
|
29
|
-
|
|
29
|
+
/** "task_complete"/"delegation_summary": synthetic system-authored turns delivering an async-delegated task's outcome (see delegation-notify.ts). Not literal user speech — persisted with the matching `source` so history/compaction/LLM serialization can treat them correctly. */
|
|
30
|
+
source: TurnSource;
|
|
30
31
|
/** webchat channelUserId for WS sources; canonical threadId for "api". */
|
|
31
32
|
sessionId: string;
|
|
32
33
|
/** User text / audio transcript / interaction description. */
|
|
@@ -43,6 +44,7 @@ export interface WebchatTurnPayload {
|
|
|
43
44
|
channel?: string;
|
|
44
45
|
/** Linked AgentRun (checkpoint/resume). Set by enqueueChatTurn. */
|
|
45
46
|
runId?: string;
|
|
47
|
+
turnId?: string;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
export interface WebchatTurnLive {
|
|
@@ -51,7 +53,7 @@ export interface WebchatTurnLive {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export interface WebchatTurnDeps {
|
|
54
|
-
runner: { generate: (opts:
|
|
56
|
+
runner: { generate: (opts: any) => Promise<{ content?: string }> };
|
|
55
57
|
getProvider: () => string;
|
|
56
58
|
getModel: () => string;
|
|
57
59
|
}
|
|
@@ -138,6 +140,9 @@ function createProcessReporter(sendRaw: (payload: string) => void, sessionId: st
|
|
|
138
140
|
error(summary = "No se pudo completar el proceso") {
|
|
139
141
|
send({ status: "error", summary });
|
|
140
142
|
},
|
|
143
|
+
pending(summary = "Tareas delegadas en ejecución") {
|
|
144
|
+
send({ kind: "analysis", status: "thinking", summary });
|
|
145
|
+
},
|
|
141
146
|
};
|
|
142
147
|
}
|
|
143
148
|
|
|
@@ -170,7 +175,7 @@ export async function runWebchatTurn(
|
|
|
170
175
|
let userId: string;
|
|
171
176
|
let threadId: string;
|
|
172
177
|
const channel = payload.channel ?? "webchat";
|
|
173
|
-
if (payload.source === "api") {
|
|
178
|
+
if (payload.source === "api" || payload.source === "delegation_summary") {
|
|
174
179
|
userId = payload.userId ?? "default";
|
|
175
180
|
threadId = payload.sessionId;
|
|
176
181
|
} else {
|
|
@@ -286,6 +291,16 @@ export async function runWebchatTurn(
|
|
|
286
291
|
runId: payload.runId,
|
|
287
292
|
resume,
|
|
288
293
|
durable: !!payload.runId,
|
|
294
|
+
turnId: payload.turnId,
|
|
295
|
+
sessionId,
|
|
296
|
+
channel,
|
|
297
|
+
rawUserMessage: payload.rawContent ?? payload.content,
|
|
298
|
+
// Every turn persists its provenance — see AgentLoopOptions.historySource.
|
|
299
|
+
// System-authored turns (async-delegation fan-in/fan-out notices) still
|
|
300
|
+
// use role:"user" in `messages` above to trigger generation; `source`
|
|
301
|
+
// lets downstream readers (history endpoint, compaction, LLM
|
|
302
|
+
// serialization) recognize and frame them without a second role.
|
|
303
|
+
historySource: payload.source,
|
|
289
304
|
onToken: async (token: string) => {
|
|
290
305
|
if (signal.aborted) return;
|
|
291
306
|
if (!reportedWriting && token.trim()) {
|
|
@@ -314,8 +329,6 @@ export async function runWebchatTurn(
|
|
|
314
329
|
},
|
|
315
330
|
onStep: async (step: { type: string; message?: string; toolName?: string }) => {
|
|
316
331
|
if (signal.aborted) return;
|
|
317
|
-
processReporter?.step(step);
|
|
318
|
-
|
|
319
332
|
// "tool_result" = resultado de herramienta → solo si pide enviarse al usuario
|
|
320
333
|
if (step.type === "tool_result" && step.message) {
|
|
321
334
|
try {
|
|
@@ -339,9 +352,15 @@ export async function runWebchatTurn(
|
|
|
339
352
|
}
|
|
340
353
|
|
|
341
354
|
const response = await d.runner.generate(generateOpts);
|
|
355
|
+
const { sealDelegationGroup } = await import("./delegation-groups");
|
|
356
|
+
const delegationGroup = payload.turnId
|
|
357
|
+
? await sealDelegationGroup(payload.turnId)
|
|
358
|
+
: null;
|
|
342
359
|
|
|
343
360
|
// Use streamed content from onToken, fallback to response.content
|
|
344
|
-
const content =
|
|
361
|
+
const content = delegationGroup
|
|
362
|
+
? ""
|
|
363
|
+
: streamedContent || response.content?.trim() || "";
|
|
345
364
|
log.info(`Response ready for session ${threadId} (${content.length} chars)`);
|
|
346
365
|
|
|
347
366
|
send({ type: "typing", isTyping: false, sessionId });
|
|
@@ -411,7 +430,11 @@ export async function runWebchatTurn(
|
|
|
411
430
|
);
|
|
412
431
|
}
|
|
413
432
|
|
|
414
|
-
|
|
433
|
+
if (delegationGroup) {
|
|
434
|
+
processReporter?.pending();
|
|
435
|
+
} else {
|
|
436
|
+
processReporter?.done("Listo");
|
|
437
|
+
}
|
|
415
438
|
return content;
|
|
416
439
|
} catch (error) {
|
|
417
440
|
processReporter?.error("No se pudo completar la respuesta");
|
|
@@ -433,7 +456,9 @@ export async function enqueueChatTurn(input: {
|
|
|
433
456
|
lane: string;
|
|
434
457
|
payload: WebchatTurnPayload;
|
|
435
458
|
live?: WebchatTurnLive;
|
|
459
|
+
idempotencyKey?: string;
|
|
436
460
|
}): Promise<JobDoc> {
|
|
461
|
+
input.payload.turnId ??= crypto.randomUUID();
|
|
437
462
|
const run = await createRun({
|
|
438
463
|
thread_id: input.payload.source === "api" ? input.payload.sessionId : `webchat:${input.payload.sessionId}`,
|
|
439
464
|
agent_id: input.payload.agentId ?? "",
|
|
@@ -450,5 +475,6 @@ export async function enqueueChatTurn(input: {
|
|
|
450
475
|
run_id: run.id,
|
|
451
476
|
payload: input.payload as unknown as Record<string, unknown>,
|
|
452
477
|
callbacks: input.live?.sendRaw ? { sendRaw: input.live.sendRaw } : undefined,
|
|
478
|
+
idempotency_key: input.idempotencyKey,
|
|
453
479
|
});
|
|
454
480
|
}
|