@johpaz/hive-agents 0.0.47 → 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 -902
- package/dist/hive.js +68840 -68355
- 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 +196 -34
- 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/index.ts +392 -83
- 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 +690 -1255
- 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
|
@@ -6,8 +6,9 @@ import type { AgentDoc, ProviderDoc, McpServerDoc } from "../storage/collections
|
|
|
6
6
|
import { buildAgentLoop } from "../agent/agent-loop";
|
|
7
7
|
import { AgentRunner } from "../agent/providers/index";
|
|
8
8
|
import { ChannelManager } from "../channels/manager";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { syncToolsToIndex, syncSkillsToIndex, syncPlaybookToIndex } from "../agent/context-compiler";
|
|
10
|
+
import { syncMCPToolsToIndex } from "../mcp/tool-sync";
|
|
11
|
+
import { syncCatalogAgentsToIndex } from "../agent/catalog-selector";
|
|
11
12
|
import { AgentService, createAgentService } from "../agent/service";
|
|
12
13
|
import { mkdirSync } from "node:fs";
|
|
13
14
|
import * as path from "node:path";
|
|
@@ -24,7 +25,7 @@ const log = logger.child("gateway:init");
|
|
|
24
25
|
/**
|
|
25
26
|
* Verifica que exista al menos un usuario en la base de datos
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
async function verifyDatabaseUsers(): Promise<void> {
|
|
28
29
|
try {
|
|
29
30
|
await ensureHiveDb();
|
|
30
31
|
|
|
@@ -48,7 +49,7 @@ export async function verifyDatabaseUsers(): Promise<void> {
|
|
|
48
49
|
/**
|
|
49
50
|
* Escribe el archivo PID del proceso
|
|
50
51
|
*/
|
|
51
|
-
|
|
52
|
+
async function writePidFile(pidFile: string): Promise<void> {
|
|
52
53
|
try {
|
|
53
54
|
const dir = path.dirname(pidFile);
|
|
54
55
|
mkdirSync(dir, { recursive: true });
|
|
@@ -64,7 +65,7 @@ export async function writePidFile(pidFile: string): Promise<void> {
|
|
|
64
65
|
* Carga la configuración del agente desde la base de datos
|
|
65
66
|
* @returns Provider y modelo configurados
|
|
66
67
|
*/
|
|
67
|
-
|
|
68
|
+
async function loadAgentConfigFromDB(
|
|
68
69
|
config: Config
|
|
69
70
|
): Promise<{ provider: string; model: string }> {
|
|
70
71
|
// Último recurso cuando la BD aún no tiene providers/modelos activos (setup inicial)
|
|
@@ -143,7 +144,7 @@ export async function loadAgentConfigFromDB(
|
|
|
143
144
|
/**
|
|
144
145
|
* Inicializa el agent loop
|
|
145
146
|
*/
|
|
146
|
-
|
|
147
|
+
async function initializeAgentLoop(mcpManager?: any): Promise<void> {
|
|
147
148
|
try {
|
|
148
149
|
await buildAgentLoop({ mcpManager });
|
|
149
150
|
log.info("Agent loop initialized");
|
|
@@ -156,7 +157,7 @@ export async function initializeAgentLoop(mcpManager?: any): Promise<void> {
|
|
|
156
157
|
/**
|
|
157
158
|
* Inicializa el runner de LLM
|
|
158
159
|
*/
|
|
159
|
-
|
|
160
|
+
async function initializeLLMRunner(
|
|
160
161
|
config: Config,
|
|
161
162
|
provider: string,
|
|
162
163
|
model: string
|
|
@@ -174,7 +175,7 @@ export async function initializeLLMRunner(
|
|
|
174
175
|
/**
|
|
175
176
|
* Inicializa el manager de canales
|
|
176
177
|
*/
|
|
177
|
-
|
|
178
|
+
async function initializeChannelManager(
|
|
178
179
|
config: Config
|
|
179
180
|
): Promise<ChannelManager> {
|
|
180
181
|
try {
|
|
@@ -242,15 +243,16 @@ export async function initializeGateway(
|
|
|
242
243
|
const { getHiveDb } = await import("../storage/hivedb");
|
|
243
244
|
const searchDb = await getHiveDb();
|
|
244
245
|
await Promise.all([
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
syncToolsToIndex(),
|
|
247
|
+
syncSkillsToIndex(),
|
|
248
|
+
syncPlaybookToIndex(),
|
|
249
|
+
syncMCPToolsToIndex(),
|
|
250
|
+
syncCatalogAgentsToIndex()
|
|
249
251
|
]);
|
|
250
252
|
// Warmup query: the first search pays reader initialization; do it here
|
|
251
253
|
// so selector latency stays under budget on the first real message.
|
|
252
254
|
await searchDb.queryHybrid({ text: "warmup", k: 1 });
|
|
253
|
-
log.info("[initialize] ✅ HiveDB capability index synced (tools, skills, playbook, mcp_tools)")
|
|
255
|
+
log.info("[initialize] ✅ HiveDB capability index synced (tools, skills, playbook, mcp_tools, catalog agents)")
|
|
254
256
|
} catch (err) {
|
|
255
257
|
log.error(`[initialize] HiveDB index sync failed during startup: ${(err as Error).message}`);
|
|
256
258
|
// Consider if we should throw or continue. For now, continue but log error.
|
|
@@ -8,24 +8,35 @@
|
|
|
8
8
|
* Executors:
|
|
9
9
|
* - chat_turn: runs the agent loop + streams tokens back to the WS channel
|
|
10
10
|
* - worker_task: runs an isolated worker agent + notifies the bus + channel
|
|
11
|
-
* -
|
|
11
|
+
* - goal_run: multi-turn orchestration until the goal verifies or budget ends
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { registerExecutor, type JobExecutor } from "./durable-queue";
|
|
15
15
|
import { logger } from "../utils/logger";
|
|
16
16
|
import { col, updateDoc } from "../storage/hive";
|
|
17
17
|
import { isRetryableError } from "../resilience/retry";
|
|
18
|
-
import type { JobDoc, TaskDoc, AgentRunDoc } from "../storage/collections";
|
|
19
|
-
import { runAgent, runAgentIsolated } from "../agent/agent-loop";
|
|
18
|
+
import type { JobDoc, TaskDoc, AgentRunDoc, AgentDoc } from "../storage/collections";
|
|
19
|
+
import { runAgent, runAgentIsolated, runAgentIsolatedDetailed } from "../agent/agent-loop";
|
|
20
20
|
import { createRun, completeRun, failRun, interruptRun, getRun, reclaimRun, bumpTurn, startLeaseRenewal, stopLeaseRenewal, deserializeAcceptance, deserializeEpoch } from "../agent/run-store";
|
|
21
21
|
import { getDurableQueue } from "./durable-queue";
|
|
22
22
|
import { sendToUserChannel } from "./channel-notify";
|
|
23
23
|
import { verifyGoal } from "../agent/goal-runner";
|
|
24
24
|
import { buildProofPacket } from "../agent/proof-packet";
|
|
25
|
+
import { verifyAgentDelivery } from "../agent/acceptance-verifier";
|
|
26
|
+
import { prepareDelegation, type PreparedDelegation } from "../agent/delegation-runtime";
|
|
25
27
|
import { runWebchatTurn, type WebchatTurnPayload } from "./webchat-turn";
|
|
26
28
|
import { agentBus } from "../events/agent-bus";
|
|
27
29
|
import { resolveContext } from "./resolver";
|
|
28
30
|
import type { MCPClientManager } from "@johpaz/hive-agents-mcp";
|
|
31
|
+
import { publishNarration } from "../events/narration";
|
|
32
|
+
import {
|
|
33
|
+
emitDelegationStarted,
|
|
34
|
+
emitDelegationFinished,
|
|
35
|
+
emitVerificationStarted,
|
|
36
|
+
emitVerificationFinished,
|
|
37
|
+
emitWorkEvent,
|
|
38
|
+
} from "../canvas/emitter";
|
|
39
|
+
import { VERIFIER_AGENT_ID } from "../agent/acceptance-verifier";
|
|
29
40
|
|
|
30
41
|
const log = logger.child("job-executors");
|
|
31
42
|
|
|
@@ -65,17 +76,42 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
65
76
|
const taskDescription = payload.taskDescription as string;
|
|
66
77
|
const taskName = payload.taskName as string;
|
|
67
78
|
const taskId = payload.taskId as string | undefined;
|
|
79
|
+
const acceptance = (payload.acceptance ?? null) as import("../agent/run-store").AcceptanceCriterion[] | null;
|
|
68
80
|
const runId = job.run_id;
|
|
81
|
+
const turnId = payload.turnId as string | undefined;
|
|
82
|
+
const parentAgentId = (payload.parentAgentId as string | undefined) ?? "";
|
|
83
|
+
const originThreadId = payload.originThreadId as string | undefined;
|
|
84
|
+
const originChannel = payload.originChannel as string | undefined;
|
|
85
|
+
const originUserId = payload.userId as string | undefined;
|
|
86
|
+
const originSessionId = payload.originSessionId as string | undefined;
|
|
69
87
|
|
|
70
88
|
log.info(`[worker_task] Job ${job.id} → worker=${workerId} task="${taskName}"`);
|
|
71
89
|
|
|
72
|
-
const agentsCol = await col<
|
|
90
|
+
const agentsCol = await col<AgentDoc>("agents");
|
|
73
91
|
const workerEntry = await agentsCol.get(workerId);
|
|
74
92
|
if (!workerEntry) return { ok: false, error: `Worker not found: ${workerId}`, retryable: false };
|
|
75
93
|
if (!workerEntry.doc.enabled) return { ok: false, error: `Worker disabled: ${workerEntry.doc.name}`, retryable: false };
|
|
76
94
|
|
|
77
95
|
const workerName = workerEntry.doc.name;
|
|
96
|
+
const isCatalogAgent = workerEntry.doc.source === "catalog";
|
|
78
97
|
agentBus.notifyTaskStarted(workerId, workerName, 0, taskName, "");
|
|
98
|
+
const delegationRef = taskId ?? job.id;
|
|
99
|
+
emitDelegationStarted({ workerId, parentAgentId, taskRef: delegationRef, taskName });
|
|
100
|
+
if (turnId && originThreadId) {
|
|
101
|
+
await publishNarration({
|
|
102
|
+
turnId,
|
|
103
|
+
threadId: originThreadId,
|
|
104
|
+
channel: originChannel,
|
|
105
|
+
userId: originUserId,
|
|
106
|
+
sessionId: originSessionId,
|
|
107
|
+
agentId: workerId,
|
|
108
|
+
agentName: workerName,
|
|
109
|
+
kind: "worker_started",
|
|
110
|
+
status: "running",
|
|
111
|
+
label: `${workerName} inició “${taskName}”`,
|
|
112
|
+
dedupeKey: `worker_started:${taskId ?? job.id}`,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
79
115
|
|
|
80
116
|
// Update TaskDoc → in_progress if we have a taskId
|
|
81
117
|
if (taskId) {
|
|
@@ -88,13 +124,20 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
88
124
|
} as Partial<TaskDoc>).catch(() => {});
|
|
89
125
|
}
|
|
90
126
|
|
|
127
|
+
let prepared: PreparedDelegation | null = null;
|
|
91
128
|
try {
|
|
129
|
+
prepared = await prepareDelegation(workerId, {
|
|
130
|
+
workspace: payload.workspace ?? workerEntry.doc.workspace ?? null,
|
|
131
|
+
parentProviderId: payload.parentProviderId ?? null,
|
|
132
|
+
parentModelId: payload.parentModelId ?? null,
|
|
133
|
+
mcpManager,
|
|
134
|
+
});
|
|
92
135
|
// Resume from the checkpoint on a re-claimed job (payload can't know this)
|
|
93
136
|
const run = runId ? await getRun(runId) : null;
|
|
94
137
|
const resume = !!run?.state_json;
|
|
95
138
|
const threadId = run?.thread_id || `task-${Date.now()}-${workerId}`;
|
|
96
139
|
|
|
97
|
-
const
|
|
140
|
+
const execution = await runAgentIsolatedDetailed({
|
|
98
141
|
agentId: workerId,
|
|
99
142
|
taskDescription,
|
|
100
143
|
threadId,
|
|
@@ -103,10 +146,24 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
103
146
|
resume,
|
|
104
147
|
durable: !!runId,
|
|
105
148
|
signal,
|
|
149
|
+
turnId,
|
|
150
|
+
taskId,
|
|
151
|
+
userId: originUserId,
|
|
152
|
+
channel: originChannel,
|
|
153
|
+
sessionId: originSessionId,
|
|
106
154
|
});
|
|
155
|
+
const result = execution.content;
|
|
107
156
|
|
|
108
157
|
if (signal.aborted) {
|
|
109
158
|
agentBus.notifyTaskFailed(workerId, workerName, 0, taskName, "", "Aborted");
|
|
159
|
+
emitWorkEvent({
|
|
160
|
+
phase: "aborted",
|
|
161
|
+
taskRef: delegationRef,
|
|
162
|
+
taskName,
|
|
163
|
+
actorId: workerId,
|
|
164
|
+
targetId: parentAgentId || null,
|
|
165
|
+
detail: "Trabajo interrumpido",
|
|
166
|
+
});
|
|
110
167
|
if (taskId) {
|
|
111
168
|
await updateDoc<TaskDoc>("tasks", taskId, {
|
|
112
169
|
status: "pending",
|
|
@@ -116,6 +173,99 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
116
173
|
return { ok: false, error: "Aborted", retryable: false };
|
|
117
174
|
}
|
|
118
175
|
|
|
176
|
+
const finishedRun = runId ? await getRun(runId) : null;
|
|
177
|
+
if (turnId && originThreadId) {
|
|
178
|
+
await publishNarration({
|
|
179
|
+
turnId,
|
|
180
|
+
threadId: originThreadId,
|
|
181
|
+
channel: originChannel,
|
|
182
|
+
userId: originUserId,
|
|
183
|
+
sessionId: originSessionId,
|
|
184
|
+
agentId: workerId,
|
|
185
|
+
agentName: workerName,
|
|
186
|
+
kind: "verifying",
|
|
187
|
+
status: "running",
|
|
188
|
+
label: `El verificador está revisando la entrega de ${workerName}`,
|
|
189
|
+
dedupeKey: `verifying:${taskId ?? job.id}`,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
emitVerificationStarted({ verifierId: VERIFIER_AGENT_ID, workerId, taskRef: delegationRef, taskName });
|
|
193
|
+
const verification = await verifyAgentDelivery({
|
|
194
|
+
runId,
|
|
195
|
+
taskId,
|
|
196
|
+
executorAgentId: workerId,
|
|
197
|
+
objective: taskDescription,
|
|
198
|
+
acceptance: acceptance ?? (finishedRun ? deserializeAcceptance(finishedRun) : null),
|
|
199
|
+
delivery: result,
|
|
200
|
+
evidence: [result, ...execution.toolEvidence],
|
|
201
|
+
executorEpoch: finishedRun ? deserializeEpoch(finishedRun) : null,
|
|
202
|
+
mcpServerIds: prepared.mcpServerIds,
|
|
203
|
+
mcpManager,
|
|
204
|
+
});
|
|
205
|
+
const verdict = JSON.parse(verification.verdict_json);
|
|
206
|
+
emitVerificationFinished({ verifierId: VERIFIER_AGENT_ID, taskRef: delegationRef });
|
|
207
|
+
if (verification.status !== "verified") {
|
|
208
|
+
emitWorkEvent({
|
|
209
|
+
phase: "review_failed",
|
|
210
|
+
taskRef: delegationRef,
|
|
211
|
+
taskName,
|
|
212
|
+
actorId: VERIFIER_AGENT_ID,
|
|
213
|
+
targetId: workerId,
|
|
214
|
+
detail: verdict.summary || "La entrega no superó la verificación",
|
|
215
|
+
});
|
|
216
|
+
if (turnId && originThreadId) {
|
|
217
|
+
await publishNarration({
|
|
218
|
+
turnId,
|
|
219
|
+
threadId: originThreadId,
|
|
220
|
+
channel: originChannel,
|
|
221
|
+
userId: originUserId,
|
|
222
|
+
sessionId: originSessionId,
|
|
223
|
+
agentId: workerId,
|
|
224
|
+
agentName: workerName,
|
|
225
|
+
kind: "failed",
|
|
226
|
+
status: "error",
|
|
227
|
+
label: `El verificador no aprobó la entrega de ${workerName}`,
|
|
228
|
+
detail: verdict.summary || "Falta evidencia independiente.",
|
|
229
|
+
dedupeKey: `verification_failed:${taskId ?? job.id}`,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
if (taskId) {
|
|
233
|
+
await updateDoc<TaskDoc>("tasks", taskId, {
|
|
234
|
+
status: "blocked",
|
|
235
|
+
error: verdict.summary || "Independent verification did not authorize success.",
|
|
236
|
+
updated_at: Date.now(),
|
|
237
|
+
} as Partial<TaskDoc>).catch(() => {});
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
ok: false,
|
|
241
|
+
error: verdict.summary || "Independent verification did not authorize success.",
|
|
242
|
+
retryable: false,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
emitWorkEvent({
|
|
246
|
+
phase: "review_passed",
|
|
247
|
+
taskRef: delegationRef,
|
|
248
|
+
taskName,
|
|
249
|
+
actorId: VERIFIER_AGENT_ID,
|
|
250
|
+
targetId: workerId,
|
|
251
|
+
});
|
|
252
|
+
if (turnId && originThreadId) {
|
|
253
|
+
await publishNarration({
|
|
254
|
+
turnId,
|
|
255
|
+
threadId: originThreadId,
|
|
256
|
+
channel: originChannel,
|
|
257
|
+
userId: originUserId,
|
|
258
|
+
sessionId: originSessionId,
|
|
259
|
+
agentId: workerId,
|
|
260
|
+
agentName: workerName,
|
|
261
|
+
kind: "verified",
|
|
262
|
+
status: "done",
|
|
263
|
+
label: `El verificador aprobó la entrega de ${workerName}`,
|
|
264
|
+
detail: `verification_id=${verification.id}`,
|
|
265
|
+
dedupeKey: `verified:${taskId ?? job.id}`,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
119
269
|
agentBus.notifyTaskCompleted(workerId, workerName, 0, taskName, "", result);
|
|
120
270
|
|
|
121
271
|
// Update TaskDoc → completed
|
|
@@ -129,10 +279,61 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
129
279
|
} as Partial<TaskDoc>).catch(() => {});
|
|
130
280
|
}
|
|
131
281
|
|
|
132
|
-
|
|
282
|
+
await buildProofPacket({
|
|
283
|
+
runId,
|
|
284
|
+
agentId: workerId,
|
|
285
|
+
intendedOutcome: taskDescription,
|
|
286
|
+
met: true,
|
|
287
|
+
checksRun: acceptance?.map((criterion) => criterion.checkTool ?? "acceptance_verifier") ?? ["acceptance_verifier"],
|
|
288
|
+
evidence: [result, ...execution.toolEvidence],
|
|
289
|
+
epoch: finishedRun ? deserializeEpoch(finishedRun) : null,
|
|
290
|
+
verificationId: verification.id,
|
|
291
|
+
catalogAgentId: isCatalogAgent ? workerId : null,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
emitWorkEvent({
|
|
295
|
+
phase: "completed",
|
|
296
|
+
taskRef: delegationRef,
|
|
297
|
+
taskName,
|
|
298
|
+
actorId: workerId,
|
|
299
|
+
targetId: parentAgentId || null,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
ok: true,
|
|
304
|
+
result: {
|
|
305
|
+
content: result,
|
|
306
|
+
evidence: execution.toolEvidence,
|
|
307
|
+
verification_id: verification.id,
|
|
308
|
+
},
|
|
309
|
+
};
|
|
133
310
|
} catch (err) {
|
|
134
311
|
const errorMsg = (err as Error).message;
|
|
135
312
|
agentBus.notifyTaskFailed(workerId, workerName, 0, taskName, "", errorMsg);
|
|
313
|
+
emitWorkEvent({
|
|
314
|
+
phase: signal.aborted ? "aborted" : "failed",
|
|
315
|
+
taskRef: delegationRef,
|
|
316
|
+
taskName,
|
|
317
|
+
actorId: workerId,
|
|
318
|
+
targetId: parentAgentId || null,
|
|
319
|
+
detail: signal.aborted ? "Trabajo interrumpido" : errorMsg,
|
|
320
|
+
});
|
|
321
|
+
if (turnId && originThreadId) {
|
|
322
|
+
await publishNarration({
|
|
323
|
+
turnId,
|
|
324
|
+
threadId: originThreadId,
|
|
325
|
+
channel: originChannel,
|
|
326
|
+
userId: originUserId,
|
|
327
|
+
sessionId: originSessionId,
|
|
328
|
+
agentId: workerId,
|
|
329
|
+
agentName: workerName,
|
|
330
|
+
kind: "failed",
|
|
331
|
+
status: "error",
|
|
332
|
+
label: `${workerName} no pudo completar “${taskName}”`,
|
|
333
|
+
detail: errorMsg,
|
|
334
|
+
dedupeKey: `worker_failed:${taskId ?? job.id}`,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
136
337
|
|
|
137
338
|
// Update TaskDoc → failed
|
|
138
339
|
if (taskId) {
|
|
@@ -144,98 +345,11 @@ const workerTaskExecutor: JobExecutor = async (job, signal) => {
|
|
|
144
345
|
}
|
|
145
346
|
|
|
146
347
|
return { ok: false, error: errorMsg, retryable: isRetryableError(err) };
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const projectTaskExecutor: JobExecutor = async (job, signal) => {
|
|
153
|
-
const payload = JSON.parse(job.payload_json);
|
|
154
|
-
const taskId = payload.taskId as string;
|
|
155
|
-
const workerId = payload.workerId as string;
|
|
156
|
-
const taskDescription = payload.taskDescription as string;
|
|
157
|
-
const runId = job.run_id;
|
|
158
|
-
|
|
159
|
-
log.info(`[project_task] Job ${job.id} → task=${taskId} worker=${workerId}`);
|
|
160
|
-
|
|
161
|
-
// Update TaskDoc → in_progress
|
|
162
|
-
await updateDoc<TaskDoc>("tasks", taskId, {
|
|
163
|
-
status: "in_progress",
|
|
164
|
-
started_at: Date.now(),
|
|
165
|
-
job_id: job.id,
|
|
166
|
-
run_id: runId,
|
|
167
|
-
updated_at: Date.now(),
|
|
168
|
-
} as Partial<TaskDoc>).catch(() => {});
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
// Resume from the checkpoint on a re-claimed job (payload can't know this)
|
|
172
|
-
const run = runId ? await getRun(runId) : null;
|
|
173
|
-
const resume = !!run?.state_json;
|
|
174
|
-
const threadId = run?.thread_id || `project-${taskId}-${Date.now()}`;
|
|
175
|
-
|
|
176
|
-
const result = await runAgentIsolated({
|
|
177
|
-
agentId: workerId,
|
|
178
|
-
taskDescription,
|
|
179
|
-
threadId,
|
|
180
|
-
mcpManager,
|
|
181
|
-
runId,
|
|
182
|
-
resume,
|
|
183
|
-
durable: !!runId,
|
|
184
|
-
signal,
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
if (signal.aborted) {
|
|
188
|
-
await updateDoc<TaskDoc>("tasks", taskId, {
|
|
189
|
-
status: "pending",
|
|
190
|
-
updated_at: Date.now(),
|
|
191
|
-
} as Partial<TaskDoc>).catch(() => {});
|
|
192
|
-
return { ok: false, error: "Aborted", retryable: false };
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Update TaskDoc → completed
|
|
196
|
-
await updateDoc<TaskDoc>("tasks", taskId, {
|
|
197
|
-
status: "completed",
|
|
198
|
-
progress: 100,
|
|
199
|
-
result,
|
|
200
|
-
completed_at: Date.now(),
|
|
201
|
-
updated_at: Date.now(),
|
|
202
|
-
} as Partial<TaskDoc>).catch(() => {});
|
|
203
|
-
|
|
204
|
-
if (runId) {
|
|
205
|
-
const finishedRun = await getRun(runId);
|
|
206
|
-
await buildProofPacket({
|
|
207
|
-
runId,
|
|
208
|
-
agentId: workerId,
|
|
209
|
-
intendedOutcome: taskDescription,
|
|
210
|
-
met: true,
|
|
211
|
-
checksRun: [],
|
|
212
|
-
evidence: [typeof result === "string" ? result : JSON.stringify(result)].filter(Boolean),
|
|
213
|
-
epoch: finishedRun ? deserializeEpoch(finishedRun) : null,
|
|
214
|
-
}).catch(() => {});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Kick the TaskDriver to check for newly-ready tasks
|
|
218
|
-
try {
|
|
219
|
-
const { getTaskDriver } = await import("../scheduler/task-driver");
|
|
220
|
-
await getTaskDriver().kick("project_task:completed");
|
|
221
|
-
} catch { /* non-critical */ }
|
|
222
|
-
|
|
223
|
-
return { ok: true, result };
|
|
224
|
-
} catch (err) {
|
|
225
|
-
const errorMsg = (err as Error).message;
|
|
226
|
-
await updateDoc<TaskDoc>("tasks", taskId, {
|
|
227
|
-
status: "failed",
|
|
228
|
-
error: errorMsg,
|
|
229
|
-
updated_at: Date.now(),
|
|
230
|
-
} as Partial<TaskDoc>).catch(() => {});
|
|
231
|
-
|
|
232
|
-
// Kick the TaskDriver to check for newly-ready tasks (or blocked dependents)
|
|
233
|
-
try {
|
|
234
|
-
const { getTaskDriver } = await import("../scheduler/task-driver");
|
|
235
|
-
await getTaskDriver().kick("project_task:failed");
|
|
236
|
-
} catch { /* non-critical */ }
|
|
237
|
-
|
|
238
|
-
return { ok: false, error: errorMsg, retryable: isRetryableError(err) };
|
|
348
|
+
} finally {
|
|
349
|
+
// Idempotente: cubre también el caso en que verifyAgentDelivery lance
|
|
350
|
+
emitVerificationFinished({ verifierId: VERIFIER_AGENT_ID, taskRef: delegationRef });
|
|
351
|
+
emitDelegationFinished({ workerId, taskRef: delegationRef });
|
|
352
|
+
await prepared?.release();
|
|
239
353
|
}
|
|
240
354
|
};
|
|
241
355
|
|
|
@@ -349,6 +463,22 @@ const goalRunExecutor: JobExecutor = async (job, signal) => {
|
|
|
349
463
|
], providerCfg, acceptance);
|
|
350
464
|
|
|
351
465
|
if (verdict.met) {
|
|
466
|
+
const independent = await verifyAgentDelivery({
|
|
467
|
+
runId: goalRunId,
|
|
468
|
+
executorAgentId: agentId,
|
|
469
|
+
objective: goal,
|
|
470
|
+
acceptance,
|
|
471
|
+
delivery: lastContent,
|
|
472
|
+
evidence: [verdict.reason],
|
|
473
|
+
executorEpoch: epoch,
|
|
474
|
+
mcpManager,
|
|
475
|
+
});
|
|
476
|
+
if (independent.status !== "verified") {
|
|
477
|
+
const independentVerdict = JSON.parse(independent.verdict_json);
|
|
478
|
+
lastReason = independentVerdict.summary || "La verificación independiente no autorizó el éxito.";
|
|
479
|
+
log.info(`[goal_run] Independent verifier rejected attempt ${attempts}: ${lastReason}`);
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
352
482
|
await completeRun(goalRunId, lastContent);
|
|
353
483
|
await notify(`✅ Meta cumplida: "${goal}". ${verdict.reason}`);
|
|
354
484
|
log.info(`[goal_run] Goal met after ${attempts} attempt(s): ${verdict.reason}`);
|
|
@@ -361,7 +491,9 @@ const goalRunExecutor: JobExecutor = async (job, signal) => {
|
|
|
361
491
|
checksRun: acceptance ? acceptance.map((a) => a.checkTool ?? "llm_verifier") : [checkTool ?? "llm_verifier"],
|
|
362
492
|
evidence: [verdict.reason, lastContent].filter(Boolean),
|
|
363
493
|
epoch,
|
|
364
|
-
|
|
494
|
+
verificationId: independent.id,
|
|
495
|
+
catalogAgentId: null,
|
|
496
|
+
});
|
|
365
497
|
return { ok: true, result: { met: true, attempts, reason: verdict.reason, content: lastContent } };
|
|
366
498
|
}
|
|
367
499
|
|
|
@@ -399,8 +531,7 @@ export function initJobExecutors(): void {
|
|
|
399
531
|
if (initialized) return;
|
|
400
532
|
registerExecutor("chat_turn", chatTurnExecutor);
|
|
401
533
|
registerExecutor("worker_task", workerTaskExecutor);
|
|
402
|
-
registerExecutor("project_task", projectTaskExecutor);
|
|
403
534
|
registerExecutor("goal_run", goalRunExecutor);
|
|
404
535
|
initialized = true;
|
|
405
536
|
log.info("[initJobExecutors] All executors registered");
|
|
406
|
-
}
|
|
537
|
+
}
|
|
@@ -19,7 +19,7 @@ export interface LaneQueueOptions {
|
|
|
19
19
|
|
|
20
20
|
type TaskHandler<T> = (task: Task, signal: AbortSignal) => Promise<T>;
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
class LaneQueue {
|
|
23
23
|
private queues: Map<string, Task[]> = new Map();
|
|
24
24
|
private running: Map<string, Task> = new Map();
|
|
25
25
|
private handlers: Map<string, TaskHandler<unknown>> = new Map();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import type { NotificationDoc } from "../storage/collections";
|
|
3
|
+
import { col, updateDoc } from "../storage/hive";
|
|
4
|
+
|
|
5
|
+
export async function createNotification(input: {
|
|
6
|
+
userId: string;
|
|
7
|
+
channel: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}): Promise<NotificationDoc> {
|
|
10
|
+
const notifications = await col<NotificationDoc>("notifications");
|
|
11
|
+
const id = randomUUID();
|
|
12
|
+
const notification: NotificationDoc = {
|
|
13
|
+
id,
|
|
14
|
+
user_id: input.userId,
|
|
15
|
+
channel: input.channel,
|
|
16
|
+
message: input.message,
|
|
17
|
+
created_at: Date.now(),
|
|
18
|
+
delivered_at: null,
|
|
19
|
+
read_at: null,
|
|
20
|
+
};
|
|
21
|
+
await notifications.put(id, notification, { expectedVersion: 0 });
|
|
22
|
+
return notification;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function listPendingNotifications(
|
|
26
|
+
userId: string,
|
|
27
|
+
channel: string,
|
|
28
|
+
): Promise<NotificationDoc[]> {
|
|
29
|
+
const notifications = await col<NotificationDoc>("notifications");
|
|
30
|
+
const rows = await notifications.findBy("user_id", userId);
|
|
31
|
+
return rows
|
|
32
|
+
.map((row) => row.doc)
|
|
33
|
+
.filter((notification) => notification.channel === channel && notification.read_at === null)
|
|
34
|
+
.sort((a, b) => a.created_at - b.created_at);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function markNotificationDelivered(id: string, userId: string): Promise<boolean> {
|
|
38
|
+
const notifications = await col<NotificationDoc>("notifications");
|
|
39
|
+
const existing = await notifications.get(id);
|
|
40
|
+
if (!existing || existing.doc.user_id !== userId) return false;
|
|
41
|
+
if (existing.doc.delivered_at !== null) return true;
|
|
42
|
+
await updateDoc<NotificationDoc>("notifications", id, { delivered_at: Date.now() });
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function acknowledgeNotification(id: string, userId: string): Promise<boolean> {
|
|
47
|
+
const notifications = await col<NotificationDoc>("notifications");
|
|
48
|
+
const existing = await notifications.get(id);
|
|
49
|
+
if (!existing || existing.doc.user_id !== userId) return false;
|
|
50
|
+
if (existing.doc.read_at !== null) return true;
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
await updateDoc<NotificationDoc>("notifications", id, {
|
|
53
|
+
delivered_at: existing.doc.delivered_at ?? now,
|
|
54
|
+
read_at: now,
|
|
55
|
+
});
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { col
|
|
1
|
+
import { col } from "../storage/hive"
|
|
2
2
|
import type { UserIdentityDoc, UserDoc, AgentDoc } from "../storage/collections"
|
|
3
3
|
|
|
4
4
|
export interface ResolveContextResult {
|
|
@@ -56,25 +56,3 @@ export async function resolveContext(options: ResolveContextOptions): Promise<Re
|
|
|
56
56
|
return { userId, threadId, agentId, isNewUser }
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export async function getDefaultAgentId(): Promise<string> {
|
|
60
|
-
const agentsCol = await col<AgentDoc>("agents")
|
|
61
|
-
const coordinators = await agentsCol.findBy("role", "coordinator", { limit: 1 })
|
|
62
|
-
return coordinators[0]?.id || "bee"
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export async function getUserById(userId: string): Promise<UserDoc | undefined> {
|
|
66
|
-
const usersCol = await col<UserDoc>("users")
|
|
67
|
-
return (await usersCol.get(userId))?.doc
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function updateUserProfile(userId: string, updates: {
|
|
71
|
-
name?: string
|
|
72
|
-
language?: string
|
|
73
|
-
timezone?: string
|
|
74
|
-
occupation?: string
|
|
75
|
-
notes?: string
|
|
76
|
-
}): Promise<void> {
|
|
77
|
-
if (Object.keys(updates).length > 0) {
|
|
78
|
-
await updateDoc<UserDoc>("users", userId, updates).catch(() => { /* not found */ })
|
|
79
|
-
}
|
|
80
|
-
}
|