macro-agent 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +3 -0
- package/.opentasks/config.json +9 -0
- package/.sudocode/issues.jsonl +28 -0
- package/.sudocode/specs.jsonl +4 -0
- package/CLAUDE.md +433 -201
- package/README.md +129 -371
- package/dist/acp/index.d.ts +9 -51
- package/dist/acp/index.d.ts.map +1 -1
- package/dist/acp/index.js +5 -46
- package/dist/acp/index.js.map +1 -1
- package/dist/acp/macro-agent.d.ts +28 -255
- package/dist/acp/macro-agent.d.ts.map +1 -1
- package/dist/acp/macro-agent.js +593 -1231
- package/dist/acp/macro-agent.js.map +1 -1
- package/dist/acp/map-bridge.d.ts +62 -0
- package/dist/acp/map-bridge.d.ts.map +1 -0
- package/dist/acp/map-bridge.js +123 -0
- package/dist/acp/map-bridge.js.map +1 -0
- package/dist/acp/session-mapper.d.ts +29 -126
- package/dist/acp/session-mapper.d.ts.map +1 -1
- package/dist/acp/session-mapper.js +36 -234
- package/dist/acp/session-mapper.js.map +1 -1
- package/dist/acp/types.d.ts +24 -535
- package/dist/acp/types.d.ts.map +1 -1
- package/dist/acp/types.js +7 -7
- package/dist/acp/types.js.map +1 -1
- package/dist/acp/websocket-server.d.ts +16 -136
- package/dist/acp/websocket-server.d.ts.map +1 -1
- package/dist/acp/websocket-server.js +131 -371
- package/dist/acp/websocket-server.js.map +1 -1
- package/dist/adapters/federation.d.ts +76 -0
- package/dist/adapters/federation.d.ts.map +1 -0
- package/dist/adapters/federation.js +120 -0
- package/dist/adapters/federation.js.map +1 -0
- package/dist/adapters/inbox-adapter.d.ts +72 -0
- package/dist/adapters/inbox-adapter.d.ts.map +1 -0
- package/dist/adapters/inbox-adapter.js +196 -0
- package/dist/adapters/inbox-adapter.js.map +1 -0
- package/dist/adapters/inbox-client-adapter.d.ts +40 -0
- package/dist/adapters/inbox-client-adapter.d.ts.map +1 -0
- package/dist/adapters/inbox-client-adapter.js +135 -0
- package/dist/adapters/inbox-client-adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +11 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +10 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/opentasks-daemon.d.ts +32 -0
- package/dist/adapters/opentasks-daemon.d.ts.map +1 -0
- package/dist/adapters/opentasks-daemon.js +190 -0
- package/dist/adapters/opentasks-daemon.js.map +1 -0
- package/dist/adapters/tasks-adapter.d.ts +49 -0
- package/dist/adapters/tasks-adapter.d.ts.map +1 -0
- package/dist/adapters/tasks-adapter.js +209 -0
- package/dist/adapters/tasks-adapter.js.map +1 -0
- package/dist/adapters/types.d.ts +198 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +13 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/agent/agent-manager-v2.d.ts +38 -0
- package/dist/agent/agent-manager-v2.d.ts.map +1 -0
- package/dist/agent/agent-manager-v2.js +1097 -0
- package/dist/agent/agent-manager-v2.js.map +1 -0
- package/dist/agent/agent-manager.d.ts +52 -42
- package/dist/agent/agent-manager.d.ts.map +1 -1
- package/dist/agent/agent-manager.js +11 -1255
- package/dist/agent/agent-manager.js.map +1 -1
- package/dist/agent/agent-store.d.ts +89 -0
- package/dist/agent/agent-store.d.ts.map +1 -0
- package/dist/agent/agent-store.js +279 -0
- package/dist/agent/agent-store.js.map +1 -0
- package/dist/agent/types.d.ts +7 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/api/index.d.ts +5 -3
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +4 -3
- package/dist/api/index.js.map +1 -1
- package/dist/api/server.d.ts +6 -123
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +247 -1489
- package/dist/api/server.js.map +1 -1
- package/dist/api/types.d.ts +20 -248
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js +3 -1
- package/dist/api/types.js.map +1 -1
- package/dist/boot-v2.d.ts +165 -0
- package/dist/boot-v2.d.ts.map +1 -0
- package/dist/boot-v2.js +315 -0
- package/dist/boot-v2.js.map +1 -0
- package/dist/cli/acp.d.ts +6 -28
- package/dist/cli/acp.d.ts.map +1 -1
- package/dist/cli/acp.js +39 -373
- package/dist/cli/acp.js.map +1 -1
- package/dist/cli/index.d.ts +1 -2
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +65 -449
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/mcp.d.ts +18 -8
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +231 -282
- package/dist/cli/mcp.js.map +1 -1
- package/dist/cognitive/analyst-role.d.ts +13 -0
- package/dist/cognitive/analyst-role.d.ts.map +1 -0
- package/dist/cognitive/analyst-role.js +48 -0
- package/dist/cognitive/analyst-role.js.map +1 -0
- package/dist/cognitive/index.d.ts +18 -0
- package/dist/cognitive/index.d.ts.map +1 -0
- package/dist/cognitive/index.js +21 -0
- package/dist/cognitive/index.js.map +1 -0
- package/dist/cognitive/macro-agent-backend.d.ts +40 -0
- package/dist/cognitive/macro-agent-backend.d.ts.map +1 -0
- package/dist/cognitive/macro-agent-backend.js +290 -0
- package/dist/cognitive/macro-agent-backend.js.map +1 -0
- package/dist/cognitive/session-converter.d.ts +30 -0
- package/dist/cognitive/session-converter.d.ts.map +1 -0
- package/dist/cognitive/session-converter.js +119 -0
- package/dist/cognitive/session-converter.js.map +1 -0
- package/dist/cognitive/types.d.ts +129 -0
- package/dist/cognitive/types.d.ts.map +1 -0
- package/dist/cognitive/types.js +12 -0
- package/dist/cognitive/types.js.map +1 -0
- package/dist/cognitive/workspace-handler.d.ts +46 -0
- package/dist/cognitive/workspace-handler.d.ts.map +1 -0
- package/dist/cognitive/workspace-handler.js +135 -0
- package/dist/cognitive/workspace-handler.js.map +1 -0
- package/dist/config/project-config.d.ts +13 -2
- package/dist/config/project-config.d.ts.map +1 -1
- package/dist/config/project-config.js +12 -2
- package/dist/config/project-config.js.map +1 -1
- package/dist/control/control-client.d.ts +63 -0
- package/dist/control/control-client.d.ts.map +1 -0
- package/dist/control/control-client.js +276 -0
- package/dist/control/control-client.js.map +1 -0
- package/dist/control/control-server.d.ts +46 -0
- package/dist/control/control-server.d.ts.map +1 -0
- package/dist/control/control-server.js +237 -0
- package/dist/control/control-server.js.map +1 -0
- package/dist/control/index.d.ts +9 -0
- package/dist/control/index.d.ts.map +1 -0
- package/dist/control/index.js +8 -0
- package/dist/control/index.js.map +1 -0
- package/dist/control/types.d.ts +64 -0
- package/dist/control/types.d.ts.map +1 -0
- package/dist/control/types.js +10 -0
- package/dist/control/types.js.map +1 -0
- package/dist/index.d.ts +15 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -34
- package/dist/index.js.map +1 -1
- package/dist/integrations/context-builder.d.ts +49 -0
- package/dist/integrations/context-builder.d.ts.map +1 -0
- package/dist/integrations/context-builder.js +160 -0
- package/dist/integrations/context-builder.js.map +1 -0
- package/dist/integrations/sessionlog.d.ts +58 -0
- package/dist/integrations/sessionlog.d.ts.map +1 -0
- package/dist/integrations/sessionlog.js +152 -0
- package/dist/integrations/sessionlog.js.map +1 -0
- package/dist/integrations/skilltree.d.ts +53 -0
- package/dist/integrations/skilltree.d.ts.map +1 -0
- package/dist/integrations/skilltree.js +140 -0
- package/dist/integrations/skilltree.js.map +1 -0
- package/dist/lifecycle/cleanup.d.ts +5 -14
- package/dist/lifecycle/cleanup.d.ts.map +1 -1
- package/dist/lifecycle/cleanup.js +4 -34
- package/dist/lifecycle/cleanup.js.map +1 -1
- package/dist/lifecycle/handlers-v2.d.ts +33 -0
- package/dist/lifecycle/handlers-v2.d.ts.map +1 -0
- package/dist/lifecycle/handlers-v2.js +319 -0
- package/dist/lifecycle/handlers-v2.js.map +1 -0
- package/dist/lifecycle/index.d.ts +3 -5
- package/dist/lifecycle/index.d.ts.map +1 -1
- package/dist/lifecycle/index.js +3 -12
- package/dist/lifecycle/index.js.map +1 -1
- package/dist/lifecycle/types.d.ts +2 -0
- package/dist/lifecycle/types.d.ts.map +1 -1
- package/dist/lifecycle/types.js.map +1 -1
- package/dist/map/acp-bridge.d.ts +39 -0
- package/dist/map/acp-bridge.d.ts.map +1 -0
- package/dist/map/acp-bridge.js +180 -0
- package/dist/map/acp-bridge.js.map +1 -0
- package/dist/map/cc-swarm-hooks.d.ts +36 -0
- package/dist/map/cc-swarm-hooks.d.ts.map +1 -0
- package/dist/map/cc-swarm-hooks.js +218 -0
- package/dist/map/cc-swarm-hooks.js.map +1 -0
- package/dist/map/coordination-handler.d.ts +36 -0
- package/dist/map/coordination-handler.d.ts.map +1 -0
- package/dist/map/coordination-handler.js +166 -0
- package/dist/map/coordination-handler.js.map +1 -0
- package/dist/map/index.d.ts +5 -10
- package/dist/map/index.d.ts.map +1 -1
- package/dist/map/index.js +4 -13
- package/dist/map/index.js.map +1 -1
- package/dist/map/lifecycle-bridge.d.ts +34 -0
- package/dist/map/lifecycle-bridge.d.ts.map +1 -0
- package/dist/map/lifecycle-bridge.js +96 -0
- package/dist/map/lifecycle-bridge.js.map +1 -0
- package/dist/map/server.d.ts +38 -0
- package/dist/map/server.d.ts.map +1 -0
- package/dist/map/server.js +461 -0
- package/dist/map/server.js.map +1 -0
- package/dist/map/sidecar.d.ts +24 -0
- package/dist/map/sidecar.d.ts.map +1 -0
- package/dist/map/sidecar.js +263 -0
- package/dist/map/sidecar.js.map +1 -0
- package/dist/map/task-bridge.d.ts +22 -0
- package/dist/map/task-bridge.d.ts.map +1 -0
- package/dist/map/task-bridge.js +67 -0
- package/dist/map/task-bridge.js.map +1 -0
- package/dist/map/trajectory-reporter.d.ts +24 -0
- package/dist/map/trajectory-reporter.d.ts.map +1 -0
- package/dist/map/trajectory-reporter.js +86 -0
- package/dist/map/trajectory-reporter.js.map +1 -0
- package/dist/map/types.d.ts +162 -226
- package/dist/map/types.d.ts.map +1 -1
- package/dist/map/types.js +6 -165
- package/dist/map/types.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +2 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/mcp-server-v2.d.ts +44 -0
- package/dist/mcp/mcp-server-v2.d.ts.map +1 -0
- package/dist/mcp/mcp-server-v2.js +376 -0
- package/dist/mcp/mcp-server-v2.js.map +1 -0
- package/dist/mcp/tools/done-v2.d.ts +57 -0
- package/dist/mcp/tools/done-v2.d.ts.map +1 -0
- package/dist/mcp/tools/done-v2.js +129 -0
- package/dist/mcp/tools/done-v2.js.map +1 -0
- package/dist/metrics/index.d.ts +7 -1
- package/dist/metrics/index.d.ts.map +1 -1
- package/dist/metrics/index.js +6 -1
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics/metrics.d.ts +9 -70
- package/dist/metrics/metrics.d.ts.map +1 -1
- package/dist/metrics/metrics.js +89 -145
- package/dist/metrics/metrics.js.map +1 -1
- package/dist/metrics/types.d.ts +44 -0
- package/dist/metrics/types.d.ts.map +1 -0
- package/dist/metrics/types.js +7 -0
- package/dist/metrics/types.js.map +1 -0
- package/dist/roles/builtin/coordinator.d.ts.map +1 -1
- package/dist/roles/builtin/coordinator.js +2 -1
- package/dist/roles/builtin/coordinator.js.map +1 -1
- package/dist/roles/builtin/integrator.d.ts.map +1 -1
- package/dist/roles/builtin/integrator.js +2 -1
- package/dist/roles/builtin/integrator.js.map +1 -1
- package/dist/roles/builtin/worker.d.ts.map +1 -1
- package/dist/roles/builtin/worker.js +3 -1
- package/dist/roles/builtin/worker.js.map +1 -1
- package/dist/roles/capabilities.d.ts +6 -0
- package/dist/roles/capabilities.d.ts.map +1 -1
- package/dist/roles/capabilities.js +10 -0
- package/dist/roles/capabilities.js.map +1 -1
- package/dist/roles/config-loader.d.ts +1 -1
- package/dist/roles/config-loader.d.ts.map +1 -1
- package/dist/roles/config-loader.js +3 -2
- package/dist/roles/config-loader.js.map +1 -1
- package/dist/roles/types.d.ts +3 -1
- package/dist/roles/types.d.ts.map +1 -1
- package/dist/store/index.d.ts +3 -6
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +3 -21
- package/dist/store/index.js.map +1 -1
- package/dist/store/types/agents.d.ts +5 -0
- package/dist/store/types/agents.d.ts.map +1 -1
- package/dist/store/types/events.d.ts +3 -60
- package/dist/store/types/events.d.ts.map +1 -1
- package/dist/store/types/events.js +3 -46
- package/dist/store/types/events.js.map +1 -1
- package/dist/store/types/index.d.ts +0 -3
- package/dist/store/types/index.d.ts.map +1 -1
- package/dist/store/types/index.js +0 -3
- package/dist/store/types/index.js.map +1 -1
- package/dist/teams/index.d.ts +2 -2
- package/dist/teams/index.d.ts.map +1 -1
- package/dist/teams/index.js +1 -1
- package/dist/teams/index.js.map +1 -1
- package/dist/teams/seed-defaults.d.ts +20 -0
- package/dist/teams/seed-defaults.d.ts.map +1 -0
- package/dist/teams/seed-defaults.js +71 -0
- package/dist/teams/seed-defaults.js.map +1 -0
- package/dist/teams/team-loader.d.ts +6 -2
- package/dist/teams/team-loader.d.ts.map +1 -1
- package/dist/teams/team-loader.js +154 -162
- package/dist/teams/team-loader.js.map +1 -1
- package/dist/teams/team-manager-v2.d.ts +87 -0
- package/dist/teams/team-manager-v2.d.ts.map +1 -0
- package/dist/teams/team-manager-v2.js +203 -0
- package/dist/teams/team-manager-v2.js.map +1 -0
- package/dist/teams/team-runtime-v2.d.ts +149 -0
- package/dist/teams/team-runtime-v2.d.ts.map +1 -0
- package/dist/teams/team-runtime-v2.js +741 -0
- package/dist/teams/team-runtime-v2.js.map +1 -0
- package/dist/teams/types.d.ts +41 -151
- package/dist/teams/types.d.ts.map +1 -1
- package/dist/teams/types.js +2 -3
- package/dist/teams/types.js.map +1 -1
- package/dist/trigger/index.d.ts +2 -2
- package/dist/trigger/index.d.ts.map +1 -1
- package/dist/trigger/index.js +4 -4
- package/dist/trigger/index.js.map +1 -1
- package/dist/trigger/sources/cron/cron-service.d.ts +1 -1
- package/dist/trigger/sources/cron/cron-service.d.ts.map +1 -1
- package/dist/trigger/sources/webhook/webhook-handler.d.ts +1 -1
- package/dist/trigger/sources/webhook/webhook-handler.d.ts.map +1 -1
- package/dist/trigger/strategies/ai-router.d.ts +31 -0
- package/dist/trigger/strategies/ai-router.d.ts.map +1 -0
- package/dist/trigger/strategies/ai-router.js +132 -0
- package/dist/trigger/strategies/ai-router.js.map +1 -0
- package/dist/trigger/trigger-system-v2.d.ts +106 -0
- package/dist/trigger/trigger-system-v2.d.ts.map +1 -0
- package/dist/trigger/trigger-system-v2.js +347 -0
- package/dist/trigger/trigger-system-v2.js.map +1 -0
- package/dist/trigger/types.d.ts +8 -0
- package/dist/trigger/types.d.ts.map +1 -1
- package/dist/trigger/types.js.map +1 -1
- package/dist/workspace/strategies/optimistic.d.ts +13 -3
- package/dist/workspace/strategies/optimistic.d.ts.map +1 -1
- package/dist/workspace/strategies/optimistic.js +4 -4
- package/dist/workspace/strategies/optimistic.js.map +1 -1
- package/docs/design-subsystem-extraction.md +627 -0
- package/docs/lifecycle-events-design.md +111 -0
- package/docs/openhive-capability-summary.md +415 -0
- package/docs/openhive-integration.md +415 -0
- package/docs/roadmap-v2-gaps.md +216 -0
- package/docs/teams.md +73 -0
- package/package.json +26 -6
- package/src/__tests__/boot-v2.test.ts +196 -0
- package/src/__tests__/e2e/acp-over-map-live.e2e.test.ts +496 -0
- package/src/__tests__/e2e/acp-over-map.e2e.test.ts +365 -0
- package/src/__tests__/e2e/agent-lifecycle.e2e.test.ts +770 -0
- package/src/__tests__/e2e/cc-swarm-bridge.e2e.test.ts +253 -0
- package/src/__tests__/e2e/cognitive-workspace.e2e.test.ts +282 -0
- package/src/__tests__/e2e/done-scenarios.e2e.test.ts +322 -0
- package/src/__tests__/e2e/live-agent.e2e.test.ts +1330 -0
- package/src/__tests__/e2e/map-server.e2e.test.ts +128 -0
- package/src/__tests__/e2e/map-sidecar.e2e.test.ts +139 -0
- package/src/__tests__/e2e/opentasks-integration.e2e.test.ts +280 -0
- package/src/__tests__/e2e/pull-mode.e2e.test.ts +632 -0
- package/src/__tests__/e2e/resume-continue.e2e.test.ts +312 -0
- package/src/__tests__/e2e/swarmkit-integration.e2e.test.ts +562 -0
- package/src/__tests__/e2e/swarmkit-live.e2e.test.ts +1049 -0
- package/src/__tests__/e2e/trajectory-tracking.e2e.test.ts +258 -0
- package/src/__tests__/e2e/trigger-wake.e2e.test.ts +257 -0
- package/src/__tests__/e2e/workspace-lifecycle.e2e.test.ts +375 -0
- package/src/acp/__tests__/macro-agent.test.ts +234 -945
- package/src/acp/__tests__/session-mapper.test.ts +82 -155
- package/src/acp/__tests__/websocket-server.test.ts +121 -270
- package/src/acp/index.ts +18 -118
- package/src/acp/macro-agent.ts +692 -1752
- package/src/acp/map-bridge.ts +193 -0
- package/src/acp/session-mapper.ts +43 -276
- package/src/acp/types.ts +39 -767
- package/src/acp/websocket-server.ts +152 -588
- package/src/adapters/__tests__/federation.test.ts +256 -0
- package/src/adapters/__tests__/inbox-adapter.test.ts +316 -0
- package/src/adapters/__tests__/tasks-adapter.test.ts +269 -0
- package/src/adapters/federation.ts +185 -0
- package/src/adapters/inbox-adapter.ts +292 -0
- package/src/adapters/inbox-client-adapter.ts +173 -0
- package/src/adapters/index.ts +44 -0
- package/src/adapters/opentasks-daemon.ts +252 -0
- package/src/adapters/tasks-adapter.ts +327 -0
- package/src/adapters/types.ts +285 -0
- package/src/agent/__tests__/agent-manager-v2.test.ts +554 -0
- package/src/agent/__tests__/agent-store.test.ts +413 -0
- package/src/agent/agent-manager-v2.ts +1476 -0
- package/src/agent/agent-manager.ts +41 -1723
- package/src/agent/agent-store.ts +385 -0
- package/src/agent/types.ts +9 -0
- package/src/api/__tests__/server.test.ts +238 -961
- package/src/api/index.ts +5 -3
- package/src/api/server.ts +276 -1870
- package/src/api/types.ts +25 -337
- package/src/boot-v2.ts +527 -0
- package/src/cli/acp.ts +40 -435
- package/src/cli/index.ts +68 -466
- package/src/cli/mcp.ts +260 -326
- package/src/cognitive/__tests__/macro-agent-backend.test.ts +478 -0
- package/src/cognitive/__tests__/session-converter.test.ts +423 -0
- package/src/cognitive/__tests__/workspace-handler.test.ts +221 -0
- package/src/cognitive/analyst-role.ts +59 -0
- package/src/cognitive/index.ts +49 -0
- package/src/cognitive/macro-agent-backend.ts +354 -0
- package/src/cognitive/session-converter.ts +151 -0
- package/src/cognitive/types.ts +163 -0
- package/src/cognitive/workspace-handler.ts +163 -0
- package/src/config/project-config.ts +27 -3
- package/src/control/__tests__/control-resilience.test.ts +251 -0
- package/src/control/__tests__/control-socket.test.ts +240 -0
- package/src/control/control-client.ts +337 -0
- package/src/control/control-server.ts +298 -0
- package/src/control/index.ts +17 -0
- package/src/control/types.ts +95 -0
- package/src/index.ts +43 -222
- package/src/integrations/__tests__/context-builder.test.ts +218 -0
- package/src/integrations/__tests__/sessionlog.test.ts +498 -0
- package/src/integrations/__tests__/skilltree.test.ts +136 -0
- package/src/integrations/context-builder.ts +280 -0
- package/src/integrations/sessionlog.ts +194 -0
- package/src/integrations/skilltree.ts +183 -0
- package/src/lifecycle/__tests__/handlers-v2.test.ts +565 -0
- package/src/lifecycle/cleanup.ts +6 -46
- package/src/lifecycle/handlers-v2.ts +437 -0
- package/src/lifecycle/index.ts +2 -28
- package/src/lifecycle/types.ts +3 -0
- package/src/map/__tests__/lifecycle-bridge.test.ts +223 -0
- package/src/map/__tests__/permission-forwarding.test.ts +143 -0
- package/src/map/__tests__/sidecar-integration.test.ts +190 -0
- package/src/map/__tests__/task-bridge.test.ts +153 -0
- package/src/map/__tests__/trajectory-reporter.test.ts +173 -0
- package/src/map/acp-bridge.ts +270 -0
- package/src/map/cc-swarm-hooks.ts +242 -0
- package/src/map/coordination-handler.ts +220 -0
- package/src/map/index.ts +13 -14
- package/src/map/lifecycle-bridge.ts +140 -0
- package/src/map/server.ts +527 -0
- package/src/map/sidecar.ts +312 -0
- package/src/map/task-bridge.ts +89 -0
- package/src/map/trajectory-reporter.ts +124 -0
- package/src/map/types.ts +195 -367
- package/src/mcp/__tests__/mcp-server-v2.test.ts +236 -0
- package/src/mcp/index.ts +2 -2
- package/src/mcp/mcp-server-v2.ts +485 -0
- package/src/mcp/tools/done-v2.ts +203 -0
- package/src/metrics/__tests__/metrics.test.ts +205 -0
- package/src/metrics/index.ts +13 -9
- package/src/metrics/metrics.ts +110 -239
- package/src/metrics/types.ts +63 -0
- package/src/roles/builtin/coordinator.ts +2 -0
- package/src/roles/builtin/integrator.ts +2 -0
- package/src/roles/builtin/worker.ts +3 -0
- package/src/roles/capabilities.ts +11 -0
- package/src/roles/config-loader.ts +3 -2
- package/src/roles/types.ts +7 -0
- package/src/store/index.ts +3 -64
- package/src/store/types/agents.ts +5 -0
- package/src/store/types/events.ts +5 -100
- package/src/store/types/index.ts +0 -3
- package/src/teams/__tests__/team-manager-v2.test.ts +425 -0
- package/src/teams/__tests__/team-runtime-v2.test.ts +402 -0
- package/src/teams/index.ts +20 -4
- package/src/teams/seed-defaults.ts +79 -0
- package/src/teams/team-loader.ts +200 -234
- package/src/teams/team-manager-v2.ts +268 -0
- package/src/teams/team-runtime-v2.ts +898 -0
- package/src/teams/types.ts +99 -200
- package/src/trigger/__tests__/trigger-system-v2.test.ts +257 -0
- package/src/trigger/index.ts +16 -31
- package/src/trigger/sources/cron/cron-service.ts +1 -1
- package/src/trigger/sources/webhook/webhook-handler.ts +1 -1
- package/src/trigger/strategies/ai-router.ts +170 -0
- package/src/trigger/trigger-system-v2.ts +536 -0
- package/src/trigger/types.ts +13 -0
- package/src/workspace/strategies/optimistic.ts +9 -6
- package/.claude/settings.local.json +0 -61
- package/dist/acp/websocket-stream.d.ts +0 -30
- package/dist/acp/websocket-stream.d.ts.map +0 -1
- package/dist/acp/websocket-stream.js +0 -118
- package/dist/acp/websocket-stream.js.map +0 -1
- package/dist/activity/deduplication.d.ts +0 -85
- package/dist/activity/deduplication.d.ts.map +0 -1
- package/dist/activity/deduplication.js +0 -149
- package/dist/activity/deduplication.js.map +0 -1
- package/dist/activity/index.d.ts +0 -16
- package/dist/activity/index.d.ts.map +0 -1
- package/dist/activity/index.js +0 -17
- package/dist/activity/index.js.map +0 -1
- package/dist/activity/relevance.d.ts +0 -81
- package/dist/activity/relevance.d.ts.map +0 -1
- package/dist/activity/relevance.js +0 -161
- package/dist/activity/relevance.js.map +0 -1
- package/dist/activity/types.d.ts +0 -169
- package/dist/activity/types.d.ts.map +0 -1
- package/dist/activity/types.js +0 -33
- package/dist/activity/types.js.map +0 -1
- package/dist/activity/watcher.d.ts +0 -64
- package/dist/activity/watcher.d.ts.map +0 -1
- package/dist/activity/watcher.js +0 -212
- package/dist/activity/watcher.js.map +0 -1
- package/dist/agent/wake.d.ts +0 -85
- package/dist/agent/wake.d.ts.map +0 -1
- package/dist/agent/wake.js +0 -278
- package/dist/agent/wake.js.map +0 -1
- package/dist/lifecycle/handlers/generic.d.ts +0 -27
- package/dist/lifecycle/handlers/generic.d.ts.map +0 -1
- package/dist/lifecycle/handlers/generic.js +0 -56
- package/dist/lifecycle/handlers/generic.js.map +0 -1
- package/dist/lifecycle/handlers/index.d.ts +0 -47
- package/dist/lifecycle/handlers/index.d.ts.map +0 -1
- package/dist/lifecycle/handlers/index.js +0 -93
- package/dist/lifecycle/handlers/index.js.map +0 -1
- package/dist/lifecycle/handlers/integrator.d.ts +0 -81
- package/dist/lifecycle/handlers/integrator.d.ts.map +0 -1
- package/dist/lifecycle/handlers/integrator.js +0 -451
- package/dist/lifecycle/handlers/integrator.js.map +0 -1
- package/dist/lifecycle/handlers/monitor.d.ts +0 -29
- package/dist/lifecycle/handlers/monitor.d.ts.map +0 -1
- package/dist/lifecycle/handlers/monitor.js +0 -79
- package/dist/lifecycle/handlers/monitor.js.map +0 -1
- package/dist/lifecycle/handlers/worker.d.ts +0 -56
- package/dist/lifecycle/handlers/worker.d.ts.map +0 -1
- package/dist/lifecycle/handlers/worker.js +0 -381
- package/dist/lifecycle/handlers/worker.js.map +0 -1
- package/dist/mail/conversation-map.d.ts +0 -33
- package/dist/mail/conversation-map.d.ts.map +0 -1
- package/dist/mail/conversation-map.js +0 -61
- package/dist/mail/conversation-map.js.map +0 -1
- package/dist/mail/index.d.ts +0 -11
- package/dist/mail/index.d.ts.map +0 -1
- package/dist/mail/index.js +0 -11
- package/dist/mail/index.js.map +0 -1
- package/dist/mail/mail-service.d.ts +0 -85
- package/dist/mail/mail-service.d.ts.map +0 -1
- package/dist/mail/mail-service.js +0 -121
- package/dist/mail/mail-service.js.map +0 -1
- package/dist/mail/stores/eventstore-conversation-store.d.ts +0 -40
- package/dist/mail/stores/eventstore-conversation-store.d.ts.map +0 -1
- package/dist/mail/stores/eventstore-conversation-store.js +0 -131
- package/dist/mail/stores/eventstore-conversation-store.js.map +0 -1
- package/dist/mail/stores/eventstore-participant-store.d.ts +0 -43
- package/dist/mail/stores/eventstore-participant-store.d.ts.map +0 -1
- package/dist/mail/stores/eventstore-participant-store.js +0 -145
- package/dist/mail/stores/eventstore-participant-store.js.map +0 -1
- package/dist/mail/stores/eventstore-thread-store.d.ts +0 -46
- package/dist/mail/stores/eventstore-thread-store.d.ts.map +0 -1
- package/dist/mail/stores/eventstore-thread-store.js +0 -118
- package/dist/mail/stores/eventstore-thread-store.js.map +0 -1
- package/dist/mail/stores/eventstore-turn-store.d.ts +0 -47
- package/dist/mail/stores/eventstore-turn-store.d.ts.map +0 -1
- package/dist/mail/stores/eventstore-turn-store.js +0 -153
- package/dist/mail/stores/eventstore-turn-store.js.map +0 -1
- package/dist/mail/stores/index.d.ts +0 -12
- package/dist/mail/stores/index.d.ts.map +0 -1
- package/dist/mail/stores/index.js +0 -12
- package/dist/mail/stores/index.js.map +0 -1
- package/dist/mail/stores/types.d.ts +0 -146
- package/dist/mail/stores/types.d.ts.map +0 -1
- package/dist/mail/stores/types.js +0 -13
- package/dist/mail/stores/types.js.map +0 -1
- package/dist/mail/turn-recorder.d.ts +0 -30
- package/dist/mail/turn-recorder.d.ts.map +0 -1
- package/dist/mail/turn-recorder.js +0 -98
- package/dist/mail/turn-recorder.js.map +0 -1
- package/dist/map/adapter/acp-over-map.d.ts +0 -115
- package/dist/map/adapter/acp-over-map.d.ts.map +0 -1
- package/dist/map/adapter/acp-over-map.js +0 -1024
- package/dist/map/adapter/acp-over-map.js.map +0 -1
- package/dist/map/adapter/connection-manager.d.ts +0 -150
- package/dist/map/adapter/connection-manager.d.ts.map +0 -1
- package/dist/map/adapter/connection-manager.js +0 -207
- package/dist/map/adapter/connection-manager.js.map +0 -1
- package/dist/map/adapter/event-log.d.ts +0 -87
- package/dist/map/adapter/event-log.d.ts.map +0 -1
- package/dist/map/adapter/event-log.js +0 -122
- package/dist/map/adapter/event-log.js.map +0 -1
- package/dist/map/adapter/event-translator.d.ts +0 -85
- package/dist/map/adapter/event-translator.d.ts.map +0 -1
- package/dist/map/adapter/event-translator.js +0 -295
- package/dist/map/adapter/event-translator.js.map +0 -1
- package/dist/map/adapter/extensions/agent-detection.d.ts +0 -49
- package/dist/map/adapter/extensions/agent-detection.d.ts.map +0 -1
- package/dist/map/adapter/extensions/agent-detection.js +0 -91
- package/dist/map/adapter/extensions/agent-detection.js.map +0 -1
- package/dist/map/adapter/extensions/agent-lifecycle.d.ts +0 -82
- package/dist/map/adapter/extensions/agent-lifecycle.d.ts.map +0 -1
- package/dist/map/adapter/extensions/agent-lifecycle.js +0 -164
- package/dist/map/adapter/extensions/agent-lifecycle.js.map +0 -1
- package/dist/map/adapter/extensions/index.d.ts +0 -89
- package/dist/map/adapter/extensions/index.d.ts.map +0 -1
- package/dist/map/adapter/extensions/index.js +0 -187
- package/dist/map/adapter/extensions/index.js.map +0 -1
- package/dist/map/adapter/extensions/mcp-bridge.d.ts +0 -57
- package/dist/map/adapter/extensions/mcp-bridge.d.ts.map +0 -1
- package/dist/map/adapter/extensions/mcp-bridge.js +0 -745
- package/dist/map/adapter/extensions/mcp-bridge.js.map +0 -1
- package/dist/map/adapter/extensions/rename.d.ts +0 -29
- package/dist/map/adapter/extensions/rename.d.ts.map +0 -1
- package/dist/map/adapter/extensions/rename.js +0 -49
- package/dist/map/adapter/extensions/rename.js.map +0 -1
- package/dist/map/adapter/extensions/resume.d.ts +0 -47
- package/dist/map/adapter/extensions/resume.d.ts.map +0 -1
- package/dist/map/adapter/extensions/resume.js +0 -59
- package/dist/map/adapter/extensions/resume.js.map +0 -1
- package/dist/map/adapter/extensions/task.d.ts +0 -40
- package/dist/map/adapter/extensions/task.d.ts.map +0 -1
- package/dist/map/adapter/extensions/task.js +0 -197
- package/dist/map/adapter/extensions/task.js.map +0 -1
- package/dist/map/adapter/extensions/update-metadata.d.ts +0 -29
- package/dist/map/adapter/extensions/update-metadata.d.ts.map +0 -1
- package/dist/map/adapter/extensions/update-metadata.js +0 -67
- package/dist/map/adapter/extensions/update-metadata.js.map +0 -1
- package/dist/map/adapter/extensions/wake.d.ts +0 -60
- package/dist/map/adapter/extensions/wake.d.ts.map +0 -1
- package/dist/map/adapter/extensions/wake.js +0 -144
- package/dist/map/adapter/extensions/wake.js.map +0 -1
- package/dist/map/adapter/extensions/workspace-files.d.ts +0 -42
- package/dist/map/adapter/extensions/workspace-files.d.ts.map +0 -1
- package/dist/map/adapter/extensions/workspace-files.js +0 -338
- package/dist/map/adapter/extensions/workspace-files.js.map +0 -1
- package/dist/map/adapter/extensions/workspace.d.ts +0 -57
- package/dist/map/adapter/extensions/workspace.d.ts.map +0 -1
- package/dist/map/adapter/extensions/workspace.js +0 -81
- package/dist/map/adapter/extensions/workspace.js.map +0 -1
- package/dist/map/adapter/index.d.ts +0 -20
- package/dist/map/adapter/index.d.ts.map +0 -1
- package/dist/map/adapter/index.js +0 -38
- package/dist/map/adapter/index.js.map +0 -1
- package/dist/map/adapter/interface.d.ts +0 -450
- package/dist/map/adapter/interface.d.ts.map +0 -1
- package/dist/map/adapter/interface.js +0 -24
- package/dist/map/adapter/interface.js.map +0 -1
- package/dist/map/adapter/mail-handler-adapter.d.ts +0 -27
- package/dist/map/adapter/mail-handler-adapter.d.ts.map +0 -1
- package/dist/map/adapter/mail-handler-adapter.js +0 -292
- package/dist/map/adapter/mail-handler-adapter.js.map +0 -1
- package/dist/map/adapter/map-adapter.d.ts +0 -200
- package/dist/map/adapter/map-adapter.d.ts.map +0 -1
- package/dist/map/adapter/map-adapter.js +0 -1199
- package/dist/map/adapter/map-adapter.js.map +0 -1
- package/dist/map/adapter/rpc-handler.d.ts +0 -263
- package/dist/map/adapter/rpc-handler.d.ts.map +0 -1
- package/dist/map/adapter/rpc-handler.js +0 -365
- package/dist/map/adapter/rpc-handler.js.map +0 -1
- package/dist/map/adapter/subscription-manager.d.ts +0 -174
- package/dist/map/adapter/subscription-manager.d.ts.map +0 -1
- package/dist/map/adapter/subscription-manager.js +0 -248
- package/dist/map/adapter/subscription-manager.js.map +0 -1
- package/dist/map/adapter/types.d.ts +0 -194
- package/dist/map/adapter/types.d.ts.map +0 -1
- package/dist/map/adapter/types.js +0 -27
- package/dist/map/adapter/types.js.map +0 -1
- package/dist/map/adapter/websocket-integration.d.ts +0 -113
- package/dist/map/adapter/websocket-integration.d.ts.map +0 -1
- package/dist/map/adapter/websocket-integration.js +0 -134
- package/dist/map/adapter/websocket-integration.js.map +0 -1
- package/dist/map/federation/envelope.d.ts +0 -98
- package/dist/map/federation/envelope.d.ts.map +0 -1
- package/dist/map/federation/envelope.js +0 -160
- package/dist/map/federation/envelope.js.map +0 -1
- package/dist/map/federation/federation-handler.d.ts +0 -50
- package/dist/map/federation/federation-handler.d.ts.map +0 -1
- package/dist/map/federation/federation-handler.js +0 -306
- package/dist/map/federation/federation-handler.js.map +0 -1
- package/dist/map/federation/index.d.ts +0 -14
- package/dist/map/federation/index.d.ts.map +0 -1
- package/dist/map/federation/index.js +0 -13
- package/dist/map/federation/index.js.map +0 -1
- package/dist/map/federation/types.d.ts +0 -239
- package/dist/map/federation/types.d.ts.map +0 -1
- package/dist/map/federation/types.js +0 -23
- package/dist/map/federation/types.js.map +0 -1
- package/dist/map/utils/address-translation.d.ts +0 -99
- package/dist/map/utils/address-translation.d.ts.map +0 -1
- package/dist/map/utils/address-translation.js +0 -285
- package/dist/map/utils/address-translation.js.map +0 -1
- package/dist/map/utils/index.d.ts +0 -7
- package/dist/map/utils/index.d.ts.map +0 -1
- package/dist/map/utils/index.js +0 -7
- package/dist/map/utils/index.js.map +0 -1
- package/dist/mcp/map-client.d.ts +0 -39
- package/dist/mcp/map-client.d.ts.map +0 -1
- package/dist/mcp/map-client.js +0 -129
- package/dist/mcp/map-client.js.map +0 -1
- package/dist/mcp/mcp-server.d.ts +0 -70
- package/dist/mcp/mcp-server.d.ts.map +0 -1
- package/dist/mcp/mcp-server.js +0 -1015
- package/dist/mcp/mcp-server.js.map +0 -1
- package/dist/mcp/tools/claim_task.d.ts +0 -35
- package/dist/mcp/tools/claim_task.d.ts.map +0 -1
- package/dist/mcp/tools/claim_task.js +0 -58
- package/dist/mcp/tools/claim_task.js.map +0 -1
- package/dist/mcp/tools/done.d.ts +0 -102
- package/dist/mcp/tools/done.d.ts.map +0 -1
- package/dist/mcp/tools/done.js +0 -234
- package/dist/mcp/tools/done.js.map +0 -1
- package/dist/mcp/tools/inject_context.d.ts +0 -61
- package/dist/mcp/tools/inject_context.d.ts.map +0 -1
- package/dist/mcp/tools/inject_context.js +0 -123
- package/dist/mcp/tools/inject_context.js.map +0 -1
- package/dist/mcp/tools/list_claimable_tasks.d.ts +0 -38
- package/dist/mcp/tools/list_claimable_tasks.d.ts.map +0 -1
- package/dist/mcp/tools/list_claimable_tasks.js +0 -63
- package/dist/mcp/tools/list_claimable_tasks.js.map +0 -1
- package/dist/mcp/tools/unclaim_task.d.ts +0 -31
- package/dist/mcp/tools/unclaim_task.d.ts.map +0 -1
- package/dist/mcp/tools/unclaim_task.js +0 -47
- package/dist/mcp/tools/unclaim_task.js.map +0 -1
- package/dist/mcp/tools/wait_for_activity.d.ts +0 -60
- package/dist/mcp/tools/wait_for_activity.d.ts.map +0 -1
- package/dist/mcp/tools/wait_for_activity.js +0 -135
- package/dist/mcp/tools/wait_for_activity.js.map +0 -1
- package/dist/monitor/health-check-service.d.ts +0 -143
- package/dist/monitor/health-check-service.d.ts.map +0 -1
- package/dist/monitor/health-check-service.js +0 -240
- package/dist/monitor/health-check-service.js.map +0 -1
- package/dist/monitor/index.d.ts +0 -14
- package/dist/monitor/index.d.ts.map +0 -1
- package/dist/monitor/index.js +0 -14
- package/dist/monitor/index.js.map +0 -1
- package/dist/monitor/stall-detector.d.ts +0 -109
- package/dist/monitor/stall-detector.d.ts.map +0 -1
- package/dist/monitor/stall-detector.js +0 -152
- package/dist/monitor/stall-detector.js.map +0 -1
- package/dist/peer/capability-manager.d.ts +0 -56
- package/dist/peer/capability-manager.d.ts.map +0 -1
- package/dist/peer/capability-manager.js +0 -186
- package/dist/peer/capability-manager.js.map +0 -1
- package/dist/peer/encapsulation-manager.d.ts +0 -190
- package/dist/peer/encapsulation-manager.d.ts.map +0 -1
- package/dist/peer/encapsulation-manager.js +0 -486
- package/dist/peer/encapsulation-manager.js.map +0 -1
- package/dist/peer/federation-manager.d.ts +0 -223
- package/dist/peer/federation-manager.d.ts.map +0 -1
- package/dist/peer/federation-manager.js +0 -528
- package/dist/peer/federation-manager.js.map +0 -1
- package/dist/peer/hierarchy-errors.d.ts +0 -208
- package/dist/peer/hierarchy-errors.d.ts.map +0 -1
- package/dist/peer/hierarchy-errors.js +0 -268
- package/dist/peer/hierarchy-errors.js.map +0 -1
- package/dist/peer/hierarchy-protocol.d.ts +0 -159
- package/dist/peer/hierarchy-protocol.d.ts.map +0 -1
- package/dist/peer/hierarchy-protocol.js +0 -142
- package/dist/peer/hierarchy-protocol.js.map +0 -1
- package/dist/peer/index.d.ts +0 -15
- package/dist/peer/index.d.ts.map +0 -1
- package/dist/peer/index.js +0 -15
- package/dist/peer/index.js.map +0 -1
- package/dist/peer/peer-manager.d.ts +0 -99
- package/dist/peer/peer-manager.d.ts.map +0 -1
- package/dist/peer/peer-manager.js +0 -333
- package/dist/peer/peer-manager.js.map +0 -1
- package/dist/peer/task-delegation.d.ts +0 -189
- package/dist/peer/task-delegation.d.ts.map +0 -1
- package/dist/peer/task-delegation.js +0 -303
- package/dist/peer/task-delegation.js.map +0 -1
- package/dist/peer/transports/index.d.ts +0 -8
- package/dist/peer/transports/index.d.ts.map +0 -1
- package/dist/peer/transports/index.js +0 -8
- package/dist/peer/transports/index.js.map +0 -1
- package/dist/peer/transports/local-transport.d.ts +0 -56
- package/dist/peer/transports/local-transport.d.ts.map +0 -1
- package/dist/peer/transports/local-transport.js +0 -263
- package/dist/peer/transports/local-transport.js.map +0 -1
- package/dist/peer/transports/websocket-transport.d.ts +0 -86
- package/dist/peer/transports/websocket-transport.d.ts.map +0 -1
- package/dist/peer/transports/websocket-transport.js +0 -338
- package/dist/peer/transports/websocket-transport.js.map +0 -1
- package/dist/peer/types.d.ts +0 -268
- package/dist/peer/types.d.ts.map +0 -1
- package/dist/peer/types.js +0 -36
- package/dist/peer/types.js.map +0 -1
- package/dist/router/address-resolver.d.ts +0 -102
- package/dist/router/address-resolver.d.ts.map +0 -1
- package/dist/router/address-resolver.js +0 -198
- package/dist/router/address-resolver.js.map +0 -1
- package/dist/router/broadcast.d.ts +0 -53
- package/dist/router/broadcast.d.ts.map +0 -1
- package/dist/router/broadcast.js +0 -75
- package/dist/router/broadcast.js.map +0 -1
- package/dist/router/channels.d.ts +0 -148
- package/dist/router/channels.d.ts.map +0 -1
- package/dist/router/channels.js +0 -126
- package/dist/router/channels.js.map +0 -1
- package/dist/router/index.d.ts +0 -21
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/index.js +0 -18
- package/dist/router/index.js.map +0 -1
- package/dist/router/message-router.d.ts +0 -197
- package/dist/router/message-router.d.ts.map +0 -1
- package/dist/router/message-router.js +0 -903
- package/dist/router/message-router.js.map +0 -1
- package/dist/router/message-types.d.ts +0 -183
- package/dist/router/message-types.d.ts.map +0 -1
- package/dist/router/message-types.js +0 -79
- package/dist/router/message-types.js.map +0 -1
- package/dist/router/role-resolver.d.ts +0 -67
- package/dist/router/role-resolver.d.ts.map +0 -1
- package/dist/router/role-resolver.js +0 -106
- package/dist/router/role-resolver.js.map +0 -1
- package/dist/router/signals.d.ts +0 -253
- package/dist/router/signals.d.ts.map +0 -1
- package/dist/router/signals.js +0 -53
- package/dist/router/signals.js.map +0 -1
- package/dist/router/types.d.ts +0 -191
- package/dist/router/types.d.ts.map +0 -1
- package/dist/router/types.js +0 -34
- package/dist/router/types.js.map +0 -1
- package/dist/router/wake.d.ts +0 -111
- package/dist/router/wake.d.ts.map +0 -1
- package/dist/router/wake.js +0 -180
- package/dist/router/wake.js.map +0 -1
- package/dist/server/combined-server.d.ts +0 -88
- package/dist/server/combined-server.d.ts.map +0 -1
- package/dist/server/combined-server.js +0 -331
- package/dist/server/combined-server.js.map +0 -1
- package/dist/steering/index.d.ts +0 -11
- package/dist/steering/index.d.ts.map +0 -1
- package/dist/steering/index.js +0 -11
- package/dist/steering/index.js.map +0 -1
- package/dist/steering/inject.d.ts +0 -39
- package/dist/steering/inject.d.ts.map +0 -1
- package/dist/steering/inject.js +0 -197
- package/dist/steering/inject.js.map +0 -1
- package/dist/steering/types.d.ts +0 -100
- package/dist/steering/types.d.ts.map +0 -1
- package/dist/steering/types.js +0 -11
- package/dist/steering/types.js.map +0 -1
- package/dist/store/backends/index.d.ts +0 -11
- package/dist/store/backends/index.d.ts.map +0 -1
- package/dist/store/backends/index.js +0 -15
- package/dist/store/backends/index.js.map +0 -1
- package/dist/store/backends/json-backend.d.ts +0 -23
- package/dist/store/backends/json-backend.d.ts.map +0 -1
- package/dist/store/backends/json-backend.js +0 -220
- package/dist/store/backends/json-backend.js.map +0 -1
- package/dist/store/backends/memory-backend.d.ts +0 -12
- package/dist/store/backends/memory-backend.d.ts.map +0 -1
- package/dist/store/backends/memory-backend.js +0 -205
- package/dist/store/backends/memory-backend.js.map +0 -1
- package/dist/store/backends/sqlite-backend.d.ts +0 -27
- package/dist/store/backends/sqlite-backend.d.ts.map +0 -1
- package/dist/store/backends/sqlite-backend.js +0 -231
- package/dist/store/backends/sqlite-backend.js.map +0 -1
- package/dist/store/backends/tinybase-backend.d.ts +0 -22
- package/dist/store/backends/tinybase-backend.d.ts.map +0 -1
- package/dist/store/backends/tinybase-backend.js +0 -203
- package/dist/store/backends/tinybase-backend.js.map +0 -1
- package/dist/store/backends/types.d.ts +0 -175
- package/dist/store/backends/types.d.ts.map +0 -1
- package/dist/store/backends/types.js +0 -28
- package/dist/store/backends/types.js.map +0 -1
- package/dist/store/event-store.d.ts +0 -128
- package/dist/store/event-store.d.ts.map +0 -1
- package/dist/store/event-store.js +0 -1739
- package/dist/store/event-store.js.map +0 -1
- package/dist/store/instance.d.ts +0 -283
- package/dist/store/instance.d.ts.map +0 -1
- package/dist/store/instance.js +0 -363
- package/dist/store/instance.js.map +0 -1
- package/dist/store/migrations.d.ts +0 -41
- package/dist/store/migrations.d.ts.map +0 -1
- package/dist/store/migrations.js +0 -79
- package/dist/store/migrations.js.map +0 -1
- package/dist/store/types/config.d.ts +0 -16
- package/dist/store/types/config.d.ts.map +0 -1
- package/dist/store/types/config.js +0 -8
- package/dist/store/types/config.js.map +0 -1
- package/dist/store/types/conversations.d.ts +0 -91
- package/dist/store/types/conversations.d.ts.map +0 -1
- package/dist/store/types/conversations.js +0 -8
- package/dist/store/types/conversations.js.map +0 -1
- package/dist/store/types/sessions.d.ts +0 -44
- package/dist/store/types/sessions.d.ts.map +0 -1
- package/dist/store/types/sessions.js +0 -9
- package/dist/store/types/sessions.js.map +0 -1
- package/dist/task/backend/index.d.ts +0 -93
- package/dist/task/backend/index.d.ts.map +0 -1
- package/dist/task/backend/index.js +0 -178
- package/dist/task/backend/index.js.map +0 -1
- package/dist/task/backend/memory.d.ts +0 -70
- package/dist/task/backend/memory.d.ts.map +0 -1
- package/dist/task/backend/memory.js +0 -621
- package/dist/task/backend/memory.js.map +0 -1
- package/dist/task/backend/opentasks/backend.d.ts +0 -140
- package/dist/task/backend/opentasks/backend.d.ts.map +0 -1
- package/dist/task/backend/opentasks/backend.js +0 -1023
- package/dist/task/backend/opentasks/backend.js.map +0 -1
- package/dist/task/backend/opentasks/client.d.ts +0 -337
- package/dist/task/backend/opentasks/client.d.ts.map +0 -1
- package/dist/task/backend/opentasks/client.js +0 -225
- package/dist/task/backend/opentasks/client.js.map +0 -1
- package/dist/task/backend/opentasks/daemon-manager.d.ts +0 -89
- package/dist/task/backend/opentasks/daemon-manager.d.ts.map +0 -1
- package/dist/task/backend/opentasks/daemon-manager.js +0 -195
- package/dist/task/backend/opentasks/daemon-manager.js.map +0 -1
- package/dist/task/backend/opentasks/index.d.ts +0 -21
- package/dist/task/backend/opentasks/index.d.ts.map +0 -1
- package/dist/task/backend/opentasks/index.js +0 -21
- package/dist/task/backend/opentasks/index.js.map +0 -1
- package/dist/task/backend/opentasks/mapping.d.ts +0 -48
- package/dist/task/backend/opentasks/mapping.d.ts.map +0 -1
- package/dist/task/backend/opentasks/mapping.js +0 -77
- package/dist/task/backend/opentasks/mapping.js.map +0 -1
- package/dist/task/backend/sudocode/__tests__/integration/test-utils.d.ts +0 -54
- package/dist/task/backend/sudocode/__tests__/integration/test-utils.d.ts.map +0 -1
- package/dist/task/backend/sudocode/__tests__/integration/test-utils.js +0 -88
- package/dist/task/backend/sudocode/__tests__/integration/test-utils.js.map +0 -1
- package/dist/task/backend/sudocode/backend.d.ts +0 -155
- package/dist/task/backend/sudocode/backend.d.ts.map +0 -1
- package/dist/task/backend/sudocode/backend.js +0 -942
- package/dist/task/backend/sudocode/backend.js.map +0 -1
- package/dist/task/backend/sudocode/client.d.ts +0 -303
- package/dist/task/backend/sudocode/client.d.ts.map +0 -1
- package/dist/task/backend/sudocode/client.js +0 -101
- package/dist/task/backend/sudocode/client.js.map +0 -1
- package/dist/task/backend/sudocode/index.d.ts +0 -19
- package/dist/task/backend/sudocode/index.d.ts.map +0 -1
- package/dist/task/backend/sudocode/index.js +0 -17
- package/dist/task/backend/sudocode/index.js.map +0 -1
- package/dist/task/backend/sudocode/mapping.d.ts +0 -51
- package/dist/task/backend/sudocode/mapping.d.ts.map +0 -1
- package/dist/task/backend/sudocode/mapping.js +0 -86
- package/dist/task/backend/sudocode/mapping.js.map +0 -1
- package/dist/task/backend/sudocode/server-client.d.ts +0 -56
- package/dist/task/backend/sudocode/server-client.d.ts.map +0 -1
- package/dist/task/backend/sudocode/server-client.js +0 -367
- package/dist/task/backend/sudocode/server-client.js.map +0 -1
- package/dist/task/backend/sudocode/standalone-client.d.ts +0 -91
- package/dist/task/backend/sudocode/standalone-client.d.ts.map +0 -1
- package/dist/task/backend/sudocode/standalone-client.js +0 -476
- package/dist/task/backend/sudocode/standalone-client.js.map +0 -1
- package/dist/task/backend/sudocode/sync-policy.d.ts +0 -166
- package/dist/task/backend/sudocode/sync-policy.d.ts.map +0 -1
- package/dist/task/backend/sudocode/sync-policy.js +0 -221
- package/dist/task/backend/sudocode/sync-policy.js.map +0 -1
- package/dist/task/backend/sudocode/tools.d.ts +0 -87
- package/dist/task/backend/sudocode/tools.d.ts.map +0 -1
- package/dist/task/backend/sudocode/tools.js +0 -743
- package/dist/task/backend/sudocode/tools.js.map +0 -1
- package/dist/task/backend/tool-provider.d.ts +0 -56
- package/dist/task/backend/tool-provider.d.ts.map +0 -1
- package/dist/task/backend/tool-provider.js +0 -424
- package/dist/task/backend/tool-provider.js.map +0 -1
- package/dist/task/backend/types.d.ts +0 -297
- package/dist/task/backend/types.d.ts.map +0 -1
- package/dist/task/backend/types.js +0 -27
- package/dist/task/backend/types.js.map +0 -1
- package/dist/task/backend/unified-tool-provider.d.ts +0 -57
- package/dist/task/backend/unified-tool-provider.d.ts.map +0 -1
- package/dist/task/backend/unified-tool-provider.js +0 -623
- package/dist/task/backend/unified-tool-provider.js.map +0 -1
- package/dist/task/index.d.ts +0 -7
- package/dist/task/index.d.ts.map +0 -1
- package/dist/task/index.js +0 -7
- package/dist/task/index.js.map +0 -1
- package/dist/task/retry-policy.d.ts +0 -89
- package/dist/task/retry-policy.d.ts.map +0 -1
- package/dist/task/retry-policy.js +0 -160
- package/dist/task/retry-policy.js.map +0 -1
- package/dist/task/task-manager.d.ts +0 -70
- package/dist/task/task-manager.d.ts.map +0 -1
- package/dist/task/task-manager.js +0 -319
- package/dist/task/task-manager.js.map +0 -1
- package/dist/task/types.d.ts +0 -72
- package/dist/task/types.d.ts.map +0 -1
- package/dist/task/types.js +0 -33
- package/dist/task/types.js.map +0 -1
- package/dist/teams/team-runtime.d.ts +0 -139
- package/dist/teams/team-runtime.d.ts.map +0 -1
- package/dist/teams/team-runtime.js +0 -615
- package/dist/teams/team-runtime.js.map +0 -1
- package/dist/trigger/router/index.d.ts +0 -11
- package/dist/trigger/router/index.d.ts.map +0 -1
- package/dist/trigger/router/index.js +0 -10
- package/dist/trigger/router/index.js.map +0 -1
- package/dist/trigger/router/strategies/ai-router-strategy.d.ts +0 -34
- package/dist/trigger/router/strategies/ai-router-strategy.d.ts.map +0 -1
- package/dist/trigger/router/strategies/ai-router-strategy.js +0 -359
- package/dist/trigger/router/strategies/ai-router-strategy.js.map +0 -1
- package/dist/trigger/router/strategies/direct-strategy.d.ts +0 -32
- package/dist/trigger/router/strategies/direct-strategy.d.ts.map +0 -1
- package/dist/trigger/router/strategies/direct-strategy.js +0 -119
- package/dist/trigger/router/strategies/direct-strategy.js.map +0 -1
- package/dist/trigger/router/strategies/index.d.ts +0 -11
- package/dist/trigger/router/strategies/index.d.ts.map +0 -1
- package/dist/trigger/router/strategies/index.js +0 -11
- package/dist/trigger/router/strategies/index.js.map +0 -1
- package/dist/trigger/router/strategies/role-strategy.d.ts +0 -39
- package/dist/trigger/router/strategies/role-strategy.d.ts.map +0 -1
- package/dist/trigger/router/strategies/role-strategy.js +0 -207
- package/dist/trigger/router/strategies/role-strategy.js.map +0 -1
- package/dist/trigger/router/trigger-router.d.ts +0 -54
- package/dist/trigger/router/trigger-router.d.ts.map +0 -1
- package/dist/trigger/router/trigger-router.js +0 -362
- package/dist/trigger/router/trigger-router.js.map +0 -1
- package/dist/trigger/router/types.d.ts +0 -225
- package/dist/trigger/router/types.d.ts.map +0 -1
- package/dist/trigger/router/types.js +0 -10
- package/dist/trigger/router/types.js.map +0 -1
- package/dist/trigger/trigger-system.d.ts +0 -77
- package/dist/trigger/trigger-system.d.ts.map +0 -1
- package/dist/trigger/trigger-system.js +0 -84
- package/dist/trigger/trigger-system.js.map +0 -1
- package/references/acp-factory-ref/CHANGELOG.md +0 -33
- package/references/acp-factory-ref/LICENSE +0 -21
- package/references/acp-factory-ref/README.md +0 -341
- package/references/acp-factory-ref/package-lock.json +0 -3102
- package/references/acp-factory-ref/package.json +0 -96
- package/references/acp-factory-ref/python/CHANGELOG.md +0 -33
- package/references/acp-factory-ref/python/LICENSE +0 -21
- package/references/acp-factory-ref/python/Makefile +0 -57
- package/references/acp-factory-ref/python/README.md +0 -253
- package/references/acp-factory-ref/python/pyproject.toml +0 -73
- package/references/acp-factory-ref/python/tests/e2e/__init__.py +0 -1
- package/references/acp-factory-ref/python/tests/e2e/test_codex_e2e.py +0 -349
- package/references/acp-factory-ref/python/tests/e2e/test_gemini_e2e.py +0 -165
- package/references/acp-factory-ref/python/tests/e2e/test_opencode_e2e.py +0 -296
- package/references/acp-factory-ref/python/tests/test_client_handler.py +0 -543
- package/references/acp-factory-ref/python/tests/test_pushable.py +0 -199
- package/references/claude-code-acp/.github/workflows/ci.yml +0 -45
- package/references/claude-code-acp/.github/workflows/publish.yml +0 -34
- package/references/claude-code-acp/.prettierrc.json +0 -4
- package/references/claude-code-acp/CHANGELOG.md +0 -249
- package/references/claude-code-acp/LICENSE +0 -222
- package/references/claude-code-acp/README.md +0 -53
- package/references/claude-code-acp/docs/RELEASES.md +0 -24
- package/references/claude-code-acp/eslint.config.js +0 -48
- package/references/claude-code-acp/package-lock.json +0 -4570
- package/references/claude-code-acp/package.json +0 -88
- package/references/claude-code-acp/scripts/release.sh +0 -119
- package/references/claude-code-acp/src/acp-agent.ts +0 -2076
- package/references/claude-code-acp/src/index.ts +0 -26
- package/references/claude-code-acp/src/lib.ts +0 -38
- package/references/claude-code-acp/src/mcp-server.ts +0 -911
- package/references/claude-code-acp/src/settings.ts +0 -522
- package/references/claude-code-acp/src/tests/.claude/commands/quick-math.md +0 -5
- package/references/claude-code-acp/src/tests/.claude/commands/say-hello.md +0 -6
- package/references/claude-code-acp/src/tests/acp-agent-fork.test.ts +0 -479
- package/references/claude-code-acp/src/tests/acp-agent.test.ts +0 -1502
- package/references/claude-code-acp/src/tests/extract-lines.test.ts +0 -103
- package/references/claude-code-acp/src/tests/fork-session.test.ts +0 -335
- package/references/claude-code-acp/src/tests/replace-and-calculate-location.test.ts +0 -334
- package/references/claude-code-acp/src/tests/settings.test.ts +0 -617
- package/references/claude-code-acp/src/tests/skills-options.test.ts +0 -187
- package/references/claude-code-acp/src/tests/tools.test.ts +0 -318
- package/references/claude-code-acp/src/tests/typescript-declarations.test.ts +0 -558
- package/references/claude-code-acp/src/tools.ts +0 -819
- package/references/claude-code-acp/src/utils.ts +0 -171
- package/references/claude-code-acp/tsconfig.json +0 -18
- package/references/claude-code-acp/vitest.config.ts +0 -19
- package/references/multi-agent-protocol/.sudocode/issues.jsonl +0 -111
- package/references/multi-agent-protocol/.sudocode/specs.jsonl +0 -13
- package/references/multi-agent-protocol/LICENSE +0 -21
- package/references/multi-agent-protocol/README.md +0 -113
- package/references/multi-agent-protocol/docs/00-design-specification.md +0 -496
- package/references/multi-agent-protocol/docs/01-open-questions.md +0 -1050
- package/references/multi-agent-protocol/docs/02-wire-protocol.md +0 -296
- package/references/multi-agent-protocol/docs/03-streaming-semantics.md +0 -252
- package/references/multi-agent-protocol/docs/04-error-handling.md +0 -231
- package/references/multi-agent-protocol/docs/05-connection-model.md +0 -244
- package/references/multi-agent-protocol/docs/06-visibility-permissions.md +0 -243
- package/references/multi-agent-protocol/docs/07-federation.md +0 -259
- package/references/multi-agent-protocol/docs/08-macro-agent-migration.md +0 -253
- package/references/multi-agent-protocol/docs/09-authentication.md +0 -680
- package/references/multi-agent-protocol/docs/10-mail-protocol.md +0 -553
- package/references/multi-agent-protocol/docs/agent-iam-integration.md +0 -877
- package/references/multi-agent-protocol/docs/agentic-mesh-integration-draft.md +0 -459
- package/references/multi-agent-protocol/docs/git-transport-draft.md +0 -251
- package/references/multi-agent-protocol/docs-site/Gemfile +0 -22
- package/references/multi-agent-protocol/docs-site/README.md +0 -82
- package/references/multi-agent-protocol/docs-site/_config.yml +0 -91
- package/references/multi-agent-protocol/docs-site/_includes/head_custom.html +0 -20
- package/references/multi-agent-protocol/docs-site/_sass/color_schemes/map.scss +0 -42
- package/references/multi-agent-protocol/docs-site/_sass/custom/custom.scss +0 -34
- package/references/multi-agent-protocol/docs-site/examples/full-integration.md +0 -510
- package/references/multi-agent-protocol/docs-site/examples/index.md +0 -138
- package/references/multi-agent-protocol/docs-site/examples/simple-chat.md +0 -282
- package/references/multi-agent-protocol/docs-site/examples/task-queue.md +0 -399
- package/references/multi-agent-protocol/docs-site/getting-started/index.md +0 -98
- package/references/multi-agent-protocol/docs-site/getting-started/installation.md +0 -219
- package/references/multi-agent-protocol/docs-site/getting-started/overview.md +0 -172
- package/references/multi-agent-protocol/docs-site/getting-started/quickstart.md +0 -237
- package/references/multi-agent-protocol/docs-site/index.md +0 -136
- package/references/multi-agent-protocol/docs-site/protocol/authentication.md +0 -391
- package/references/multi-agent-protocol/docs-site/protocol/connection-model.md +0 -376
- package/references/multi-agent-protocol/docs-site/protocol/design.md +0 -284
- package/references/multi-agent-protocol/docs-site/protocol/error-handling.md +0 -312
- package/references/multi-agent-protocol/docs-site/protocol/federation.md +0 -449
- package/references/multi-agent-protocol/docs-site/protocol/index.md +0 -129
- package/references/multi-agent-protocol/docs-site/protocol/permissions.md +0 -398
- package/references/multi-agent-protocol/docs-site/protocol/streaming.md +0 -353
- package/references/multi-agent-protocol/docs-site/protocol/wire-protocol.md +0 -369
- package/references/multi-agent-protocol/docs-site/sdk/api/agent.md +0 -357
- package/references/multi-agent-protocol/docs-site/sdk/api/client.md +0 -380
- package/references/multi-agent-protocol/docs-site/sdk/api/index.md +0 -62
- package/references/multi-agent-protocol/docs-site/sdk/api/server.md +0 -453
- package/references/multi-agent-protocol/docs-site/sdk/api/types.md +0 -468
- package/references/multi-agent-protocol/docs-site/sdk/guides/agent.md +0 -375
- package/references/multi-agent-protocol/docs-site/sdk/guides/authentication.md +0 -405
- package/references/multi-agent-protocol/docs-site/sdk/guides/client.md +0 -352
- package/references/multi-agent-protocol/docs-site/sdk/guides/index.md +0 -89
- package/references/multi-agent-protocol/docs-site/sdk/guides/server.md +0 -360
- package/references/multi-agent-protocol/docs-site/sdk/guides/testing.md +0 -446
- package/references/multi-agent-protocol/docs-site/sdk/guides/transports.md +0 -363
- package/references/multi-agent-protocol/docs-site/sdk/index.md +0 -206
- package/references/multi-agent-protocol/package-lock.json +0 -3886
- package/references/multi-agent-protocol/package.json +0 -56
- package/references/multi-agent-protocol/schema/meta.json +0 -467
- package/references/multi-agent-protocol/schema/schema.json +0 -2558
- package/src/__tests__/e2e/agent-spawn-visibility.e2e.test.ts +0 -761
- package/src/__tests__/e2e/cascade-termination.e2e.test.ts +0 -588
- package/src/__tests__/e2e/conflict-resolution-flow.e2e.test.ts +0 -790
- package/src/__tests__/e2e/full-agent-conflict-resolution.e2e.test.ts +0 -714
- package/src/__tests__/e2e/full-agent-orchestration.e2e.test.ts +0 -536
- package/src/__tests__/e2e/mcp-server-debug.e2e.test.ts +0 -372
- package/src/__tests__/e2e/mcp-thin-client-bridge.e2e.test.ts +0 -304
- package/src/__tests__/e2e/mcp-tools-available.e2e.test.ts +0 -324
- package/src/__tests__/e2e/multi-agent.e2e.test.ts +0 -1527
- package/src/__tests__/e2e/multi-coordinator.e2e.test.ts +0 -602
- package/src/__tests__/e2e/orchestration-flow.e2e.test.ts +0 -686
- package/src/__tests__/e2e/spawn-session-streaming.e2e.test.ts +0 -563
- package/src/__tests__/e2e/steering-task.e2e.test.ts +0 -840
- package/src/__tests__/integration.e2e.test.ts +0 -407
- package/src/acp/__tests__/combined-websocket-server.test.ts +0 -260
- package/src/acp/__tests__/history.test.ts +0 -530
- package/src/acp/__tests__/integration.test.ts +0 -1049
- package/src/acp/__tests__/multi-client-mounting.test.ts +0 -303
- package/src/acp/__tests__/session-persistence.test.ts +0 -276
- package/src/acp/__tests__/websocket-full.e2e.test.ts +0 -401
- package/src/acp/__tests__/websocket-integration.test.ts +0 -484
- package/src/acp/__tests__/websocket-stream.test.ts +0 -281
- package/src/acp/__tests__/websocket.e2e.test.ts +0 -390
- package/src/acp/websocket-stream.ts +0 -140
- package/src/activity/__tests__/deduplication.test.ts +0 -345
- package/src/activity/__tests__/relevance.test.ts +0 -347
- package/src/activity/__tests__/watcher.test.ts +0 -344
- package/src/activity/deduplication.ts +0 -219
- package/src/activity/index.ts +0 -51
- package/src/activity/relevance.ts +0 -258
- package/src/activity/types.ts +0 -263
- package/src/activity/watcher.ts +0 -345
- package/src/agent/__tests__/agent-manager.test.ts +0 -1382
- package/src/agent/__tests__/wake.test.ts +0 -768
- package/src/agent/wake.ts +0 -357
- package/src/api/__tests__/conversation-api.test.ts +0 -468
- package/src/cli/__tests__/acp.test.ts +0 -214
- package/src/lifecycle/__tests__/cascade-termination.test.ts +0 -919
- package/src/lifecycle/__tests__/cascade.test.ts +0 -595
- package/src/lifecycle/__tests__/cleanup.test.ts +0 -322
- package/src/lifecycle/__tests__/handlers.test.ts +0 -1826
- package/src/lifecycle/__tests__/lifecycle.e2e.test.ts +0 -354
- package/src/lifecycle/__tests__/merge-queue.e2e.test.ts +0 -602
- package/src/lifecycle/handlers/generic.ts +0 -87
- package/src/lifecycle/handlers/index.ts +0 -166
- package/src/lifecycle/handlers/integrator.ts +0 -672
- package/src/lifecycle/handlers/monitor.ts +0 -114
- package/src/lifecycle/handlers/worker.ts +0 -506
- package/src/mail/__tests__/conversation-lifecycle.test.ts +0 -409
- package/src/mail/__tests__/eventstore-stores.test.ts +0 -1073
- package/src/mail/__tests__/mail-full-agent.e2e.test.ts +0 -575
- package/src/mail/__tests__/mail-integration.test.ts +0 -759
- package/src/mail/__tests__/mail-map-protocol.e2e.test.ts +0 -1068
- package/src/mail/__tests__/mail-service.test.ts +0 -506
- package/src/mail/__tests__/turn-recorder.test.ts +0 -328
- package/src/mail/conversation-map.ts +0 -107
- package/src/mail/index.ts +0 -25
- package/src/mail/mail-service.ts +0 -257
- package/src/mail/stores/eventstore-conversation-store.ts +0 -146
- package/src/mail/stores/eventstore-participant-store.ts +0 -172
- package/src/mail/stores/eventstore-thread-store.ts +0 -129
- package/src/mail/stores/eventstore-turn-store.ts +0 -173
- package/src/mail/stores/index.ts +0 -12
- package/src/mail/stores/types.ts +0 -160
- package/src/mail/turn-recorder.ts +0 -124
- package/src/map/README.md +0 -79
- package/src/map/__tests__/adapter-types.test.ts +0 -326
- package/src/map/__tests__/interface-types.test.ts +0 -342
- package/src/map/__tests__/types.test.ts +0 -411
- package/src/map/adapter/__tests__/acp-over-map-cancel.test.ts +0 -820
- package/src/map/adapter/__tests__/acp-over-map-getmodels.test.ts +0 -355
- package/src/map/adapter/__tests__/acp-over-map-history.test.ts +0 -1386
- package/src/map/adapter/__tests__/acp-over-map-persistence.e2e.test.ts +0 -440
- package/src/map/adapter/__tests__/connection-manager.test.ts +0 -344
- package/src/map/adapter/__tests__/event-broadcast.test.ts +0 -420
- package/src/map/adapter/__tests__/event-log.test.ts +0 -527
- package/src/map/adapter/__tests__/event-translator.test.ts +0 -550
- package/src/map/adapter/__tests__/extensions.test.ts +0 -1387
- package/src/map/adapter/__tests__/map-adapter.test.ts +0 -926
- package/src/map/adapter/__tests__/mcp-bridge.test.ts +0 -1187
- package/src/map/adapter/__tests__/multi-client-broadcast.test.ts +0 -711
- package/src/map/adapter/__tests__/rpc-handler.test.ts +0 -644
- package/src/map/adapter/__tests__/subscription-manager.test.ts +0 -536
- package/src/map/adapter/__tests__/websocket-integration.test.ts +0 -487
- package/src/map/adapter/__tests__/workspace-files.test.ts +0 -673
- package/src/map/adapter/acp-over-map.ts +0 -1483
- package/src/map/adapter/connection-manager.ts +0 -400
- package/src/map/adapter/event-log.ts +0 -208
- package/src/map/adapter/event-translator.ts +0 -415
- package/src/map/adapter/extensions/agent-detection.ts +0 -201
- package/src/map/adapter/extensions/agent-lifecycle.ts +0 -267
- package/src/map/adapter/extensions/index.ts +0 -280
- package/src/map/adapter/extensions/mcp-bridge.ts +0 -995
- package/src/map/adapter/extensions/resume.ts +0 -114
- package/src/map/adapter/extensions/task.ts +0 -326
- package/src/map/adapter/extensions/update-metadata.ts +0 -126
- package/src/map/adapter/extensions/wake.ts +0 -239
- package/src/map/adapter/extensions/workspace-files.ts +0 -449
- package/src/map/adapter/extensions/workspace.ts +0 -176
- package/src/map/adapter/index.ts +0 -158
- package/src/map/adapter/interface.ts +0 -581
- package/src/map/adapter/mail-handler-adapter.ts +0 -429
- package/src/map/adapter/map-adapter.ts +0 -1749
- package/src/map/adapter/rpc-handler.ts +0 -604
- package/src/map/adapter/subscription-manager.ts +0 -474
- package/src/map/adapter/types.ts +0 -259
- package/src/map/adapter/websocket-integration.ts +0 -229
- package/src/map/federation/__tests__/envelope.test.ts +0 -362
- package/src/map/federation/__tests__/federation-handler.test.ts +0 -461
- package/src/map/federation/envelope.ts +0 -243
- package/src/map/federation/federation-handler.ts +0 -442
- package/src/map/federation/index.ts +0 -65
- package/src/map/federation/types.ts +0 -344
- package/src/mcp/__tests__/map-client.test.ts +0 -386
- package/src/mcp/__tests__/mcp-server-thin-client.test.ts +0 -368
- package/src/mcp/__tests__/mcp-server.test.ts +0 -1002
- package/src/mcp/map-client.ts +0 -177
- package/src/mcp/mcp-server.ts +0 -1395
- package/src/mcp/tools/__tests__/done.test.ts +0 -484
- package/src/mcp/tools/claim_task.ts +0 -86
- package/src/mcp/tools/done.ts +0 -338
- package/src/mcp/tools/inject_context.ts +0 -173
- package/src/mcp/tools/list_claimable_tasks.ts +0 -93
- package/src/mcp/tools/unclaim_task.ts +0 -71
- package/src/mcp/tools/wait_for_activity.ts +0 -185
- package/src/monitor/__tests__/health-check-service.test.ts +0 -425
- package/src/monitor/__tests__/stale-agent-flow.integration.test.ts +0 -393
- package/src/monitor/__tests__/stall-detector.test.ts +0 -395
- package/src/monitor/health-check-service.ts +0 -359
- package/src/monitor/index.ts +0 -28
- package/src/monitor/stall-detector.ts +0 -238
- package/src/peer/__tests__/capability-manager.test.ts +0 -454
- package/src/peer/__tests__/encapsulation-manager.test.ts +0 -787
- package/src/peer/__tests__/federation-manager.test.ts +0 -828
- package/src/peer/__tests__/hierarchy-errors.test.ts +0 -307
- package/src/peer/__tests__/peer-manager.test.ts +0 -535
- package/src/peer/__tests__/task-delegation.test.ts +0 -741
- package/src/peer/capability-manager.ts +0 -289
- package/src/peer/encapsulation-manager.ts +0 -831
- package/src/peer/federation-manager.ts +0 -897
- package/src/peer/hierarchy-errors.ts +0 -382
- package/src/peer/hierarchy-protocol.ts +0 -328
- package/src/peer/index.ts +0 -15
- package/src/peer/peer-manager.ts +0 -540
- package/src/peer/task-delegation.ts +0 -594
- package/src/peer/transports/__tests__/local-transport.test.ts +0 -355
- package/src/peer/transports/__tests__/websocket-transport.test.ts +0 -270
- package/src/peer/transports/index.ts +0 -18
- package/src/peer/transports/local-transport.ts +0 -348
- package/src/peer/transports/websocket-transport.ts +0 -452
- package/src/peer/types.ts +0 -331
- package/src/roles/__tests__/capability-enforcement.test.ts +0 -989
- package/src/roles/__tests__/message-routing.e2e.test.ts +0 -464
- package/src/roles/__tests__/role-resolution.test.ts +0 -576
- package/src/router/README.md +0 -120
- package/src/router/__tests__/address-resolver.test.ts +0 -340
- package/src/router/__tests__/broadcast.test.ts +0 -185
- package/src/router/__tests__/message-router.test.ts +0 -1070
- package/src/router/__tests__/role-channel.test.ts +0 -213
- package/src/router/__tests__/send-to-address.test.ts +0 -731
- package/src/router/__tests__/wake.test.ts +0 -459
- package/src/router/address-resolver.ts +0 -303
- package/src/router/broadcast.ts +0 -117
- package/src/router/channels.ts +0 -283
- package/src/router/index.ts +0 -148
- package/src/router/message-router.ts +0 -1392
- package/src/router/message-types.ts +0 -294
- package/src/router/role-resolver.ts +0 -164
- package/src/router/signals.ts +0 -335
- package/src/router/types.ts +0 -306
- package/src/router/wake.ts +0 -270
- package/src/server/__tests__/combined-server.test.ts +0 -360
- package/src/server/combined-server.ts +0 -530
- package/src/steering/__tests__/inject.test.ts +0 -405
- package/src/steering/__tests__/injection.e2e.test.ts +0 -932
- package/src/steering/__tests__/steering-integration.test.ts +0 -747
- package/src/steering/index.ts +0 -25
- package/src/steering/inject.ts +0 -262
- package/src/steering/types.ts +0 -143
- package/src/store/README.md +0 -134
- package/src/store/__tests__/event-store.test.ts +0 -1446
- package/src/store/__tests__/instance.test.ts +0 -556
- package/src/store/__tests__/migrations.test.ts +0 -109
- package/src/store/backends/__tests__/memory-backend.test.ts +0 -383
- package/src/store/backends/__tests__/sqlite-backend.test.ts +0 -427
- package/src/store/backends/index.ts +0 -42
- package/src/store/backends/json-backend.ts +0 -295
- package/src/store/backends/memory-backend.ts +0 -256
- package/src/store/backends/sqlite-backend.ts +0 -337
- package/src/store/backends/tinybase-backend.ts +0 -276
- package/src/store/backends/types.ts +0 -252
- package/src/store/event-store.ts +0 -2204
- package/src/store/instance.ts +0 -681
- package/src/store/migrations.ts +0 -96
- package/src/store/types/config.ts +0 -19
- package/src/store/types/conversations.ts +0 -129
- package/src/store/types/sessions.ts +0 -53
- package/src/task/__tests__/retry-policy.test.ts +0 -409
- package/src/task/__tests__/task-integration.test.ts +0 -457
- package/src/task/__tests__/task-manager.test.ts +0 -815
- package/src/task/backend/__tests__/create-task-backend.test.ts +0 -225
- package/src/task/backend/__tests__/e2e/unified-tool-provider-opentasks.e2e.test.ts +0 -524
- package/src/task/backend/__tests__/memory.test.ts +0 -1274
- package/src/task/backend/__tests__/unified-tool-provider.test.ts +0 -579
- package/src/task/backend/index.ts +0 -310
- package/src/task/backend/memory.ts +0 -828
- package/src/task/backend/opentasks/__tests__/backend.test.ts +0 -968
- package/src/task/backend/opentasks/__tests__/daemon-manager.test.ts +0 -406
- package/src/task/backend/opentasks/__tests__/mapping.test.ts +0 -84
- package/src/task/backend/opentasks/__tests__/opentasks-backend.e2e.test.ts +0 -1338
- package/src/task/backend/opentasks/backend.ts +0 -1323
- package/src/task/backend/opentasks/client.ts +0 -652
- package/src/task/backend/opentasks/daemon-manager.ts +0 -253
- package/src/task/backend/opentasks/index.ts +0 -69
- package/src/task/backend/opentasks/mapping.ts +0 -94
- package/src/task/backend/types.ts +0 -458
- package/src/task/backend/unified-tool-provider.ts +0 -779
- package/src/task/index.ts +0 -7
- package/src/task/retry-policy.ts +0 -204
- package/src/task/task-manager.ts +0 -515
- package/src/task/types.ts +0 -136
- package/src/teams/__tests__/cross-subsystem.integration.test.ts +0 -983
- package/src/teams/__tests__/e2e/team-runtime.e2e.test.ts +0 -553
- package/src/teams/__tests__/team-system.test.ts +0 -1280
- package/src/teams/team-runtime.ts +0 -729
- package/src/trigger/CLAUDE.md +0 -308
- package/src/trigger/README.md +0 -429
- package/src/trigger/__tests__/macro-agent-regression.test.ts +0 -946
- package/src/trigger/__tests__/routing-strategies.test.ts +0 -329
- package/src/trigger/__tests__/trigger-router.test.ts +0 -433
- package/src/trigger/__tests__/trigger-system-integration.test.ts +0 -581
- package/src/trigger/router/index.ts +0 -36
- package/src/trigger/router/strategies/ai-router-strategy.ts +0 -481
- package/src/trigger/router/strategies/direct-strategy.ts +0 -162
- package/src/trigger/router/strategies/index.ts +0 -26
- package/src/trigger/router/strategies/role-strategy.ts +0 -274
- package/src/trigger/router/trigger-router.ts +0 -463
- package/src/trigger/router/types.ts +0 -273
- package/src/trigger/trigger-system.ts +0 -206
- package/src/workspace/__tests__/multi-coordinator.test.ts +0 -1005
- package/src/workspace/__tests__/workspace-manager.test.ts +0 -391
- package/src/workspace/__tests__/workspace.e2e.test.ts +0 -1155
- package/src/workspace/merge-queue/__tests__/hierarchical-consolidation.e2e.test.ts +0 -414
- package/test_fixtures/harness/__tests__/behavior-executor-and-stepper.test.ts +0 -714
- package/test_fixtures/harness/__tests__/fixtures.test.ts +0 -347
- package/test_fixtures/harness/__tests__/merge-queue-and-worktrees.test.ts +0 -452
- package/test_fixtures/harness/__tests__/temp-repo-and-simulator.test.ts +0 -422
- package/test_fixtures/harness/__tests__/test-harness-and-assertions.test.ts +0 -568
- /package/{references/acp-factory-ref/python/tests/__init__.py → .opentasks/graph.jsonl} +0 -0
|
@@ -1,1739 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Event Store implementation using TinyBase
|
|
3
|
-
*
|
|
4
|
-
* Provides an append-only event log with materialized views for:
|
|
5
|
-
* - Agents
|
|
6
|
-
* - Tasks
|
|
7
|
-
* - Messages (per-agent queues)
|
|
8
|
-
* - Subscriptions
|
|
9
|
-
*/
|
|
10
|
-
import { createStore } from 'tinybase';
|
|
11
|
-
import { createCustomPersister, createCustomSqlitePersister } from 'tinybase/persisters';
|
|
12
|
-
import Database from 'better-sqlite3';
|
|
13
|
-
import { nanoid } from 'nanoid';
|
|
14
|
-
import * as path from 'path';
|
|
15
|
-
import * as os from 'os';
|
|
16
|
-
import * as fs from 'fs';
|
|
17
|
-
import { CURRENT_EVENT_VERSION } from './types/events.js';
|
|
18
|
-
import { migrateEvent } from './migrations.js';
|
|
19
|
-
import { resolveInstancePath, ensureInstanceDir, createInstanceMeta, writeInstanceMeta, touchInstance, registerInstance, DEFAULT_PEER_VISIBILITY, filterEventsForPeer, } from './instance.js';
|
|
20
|
-
import { createTinyBaseBackend } from './backends/tinybase-backend.js';
|
|
21
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
22
|
-
// Tabular better-sqlite3 Persister
|
|
23
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
24
|
-
/**
|
|
25
|
-
* Build tabular config for the 10 TinyBase tables.
|
|
26
|
-
* Identity mapping: TinyBase table name === SQLite table name.
|
|
27
|
-
*/
|
|
28
|
-
function getTabularConfig() {
|
|
29
|
-
const tableNames = [
|
|
30
|
-
'events', 'agents', 'tasks', 'messages',
|
|
31
|
-
'sessions', 'conversations', 'turns',
|
|
32
|
-
'threads', 'subscriptions', 'participants',
|
|
33
|
-
];
|
|
34
|
-
const load = {};
|
|
35
|
-
const save = {};
|
|
36
|
-
for (const t of tableNames) {
|
|
37
|
-
load[t] = t; // SQLite table -> TinyBase table (same name)
|
|
38
|
-
save[t] = t; // TinyBase table -> SQLite table (same name)
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
mode: 'tabular',
|
|
42
|
-
tables: { load, save },
|
|
43
|
-
autoLoadIntervalSeconds: 1,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Creates a tabular TinyBase persister backed by better-sqlite3.
|
|
48
|
-
*
|
|
49
|
-
* Unlike the old JSON blob approach (entire store as one JSON string in a
|
|
50
|
-
* single row), tabular mode maps each TinyBase table to a real SQLite table
|
|
51
|
-
* and only writes changed rows on autoSave — making persistence O(delta)
|
|
52
|
-
* instead of O(total).
|
|
53
|
-
*/
|
|
54
|
-
function createTabularBetterSqlite3Persister(store, db) {
|
|
55
|
-
// Wrap better-sqlite3's sync API as the async DatabaseExecuteCommand.
|
|
56
|
-
// TinyBase generates SQL with $1, $2, ... placeholders (PostgreSQL-style),
|
|
57
|
-
// but better-sqlite3 uses ? for positional array binding. Convert them.
|
|
58
|
-
const executeCommand = async (sql, params) => {
|
|
59
|
-
const convertedSql = sql.replace(/\$\d+/g, '?');
|
|
60
|
-
const trimmed = convertedSql.trimStart().toUpperCase();
|
|
61
|
-
const stmt = db.prepare(convertedSql);
|
|
62
|
-
if (trimmed.startsWith('SELECT') || trimmed.startsWith('PRAGMA')) {
|
|
63
|
-
return (params ? stmt.all(...params) : stmt.all());
|
|
64
|
-
}
|
|
65
|
-
params ? stmt.run(...params) : stmt.run();
|
|
66
|
-
return [];
|
|
67
|
-
};
|
|
68
|
-
return createCustomSqlitePersister(store, getTabularConfig(), executeCommand,
|
|
69
|
-
// addChangeListener — better-sqlite3 has no native change events
|
|
70
|
-
(_listener) => null,
|
|
71
|
-
// delChangeListener — no-op
|
|
72
|
-
(_handle) => { },
|
|
73
|
-
// onSqlCommand
|
|
74
|
-
undefined,
|
|
75
|
-
// onIgnoredError
|
|
76
|
-
(error) => console.warn('[EventStore] Persister error:', error),
|
|
77
|
-
// destroy — do NOT close DB here; close() handles it after the persister drains
|
|
78
|
-
() => { },
|
|
79
|
-
// persist mode (1 = StoreOnly)
|
|
80
|
-
1,
|
|
81
|
-
// thing (the db instance)
|
|
82
|
-
db,
|
|
83
|
-
// getThing accessor name
|
|
84
|
-
'getDb');
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Parse a duration string (e.g., "30d", "7d") to milliseconds
|
|
88
|
-
*/
|
|
89
|
-
export function parseDuration(duration) {
|
|
90
|
-
const match = duration.match(/^(\d+)([dhms])$/);
|
|
91
|
-
if (!match) {
|
|
92
|
-
throw new Error(`Invalid duration format: "${duration}". Use format like "30d", "7d", "24h", "60m", "30s".`);
|
|
93
|
-
}
|
|
94
|
-
const value = parseInt(match[1], 10);
|
|
95
|
-
const unit = match[2];
|
|
96
|
-
const multipliers = {
|
|
97
|
-
s: 1000,
|
|
98
|
-
m: 60 * 1000,
|
|
99
|
-
h: 60 * 60 * 1000,
|
|
100
|
-
d: 24 * 60 * 60 * 1000,
|
|
101
|
-
};
|
|
102
|
-
return value * multipliers[unit];
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Create an Event Store instance
|
|
106
|
-
*/
|
|
107
|
-
export async function createEventStore(config = {}) {
|
|
108
|
-
// Resolve instance configuration
|
|
109
|
-
const resolved = resolveInstancePath(config);
|
|
110
|
-
const { instanceId, instancePath, namespace, isNew, backendType } = resolved;
|
|
111
|
-
// Reject deprecated legacy path option
|
|
112
|
-
if (config.path) {
|
|
113
|
-
throw new Error('[macro-agent] The `path` option has been removed. ' +
|
|
114
|
-
'Use `instanceId` and `baseDir` instead for per-instance isolation.');
|
|
115
|
-
}
|
|
116
|
-
// Track baseDir for MCP subprocess communication
|
|
117
|
-
const baseDir = config.baseDir ?? path.join(os.homedir(), '.multiagent');
|
|
118
|
-
// Get peer visibility config (default is restrictive)
|
|
119
|
-
const peerVisibility = config.peerVisibility ?? DEFAULT_PEER_VISIBILITY;
|
|
120
|
-
// Emit warning for in-memory mode (only in non-test environments)
|
|
121
|
-
if (config.inMemory && process.env.NODE_ENV !== 'test') {
|
|
122
|
-
console.warn('[macro-agent] WARNING: Using in-memory EventStore. MCP tools (done, spawn_agent, etc.) will not work ' +
|
|
123
|
-
'because MCP servers run as separate subprocesses that cannot access in-memory data. ' +
|
|
124
|
-
'Use file-based storage (remove inMemory option) for real agent workflows.');
|
|
125
|
-
}
|
|
126
|
-
const store = createStore();
|
|
127
|
-
// Set up persister based on backend type
|
|
128
|
-
let persister = null;
|
|
129
|
-
let db = null;
|
|
130
|
-
if (!config.inMemory) {
|
|
131
|
-
ensureInstanceDir(instancePath);
|
|
132
|
-
const dbPath = path.join(instancePath, 'store.sqlite');
|
|
133
|
-
db = new Database(dbPath);
|
|
134
|
-
db.pragma('journal_mode = WAL');
|
|
135
|
-
db.pragma('busy_timeout = 5000');
|
|
136
|
-
// Migration: if old JSON blob table exists, load data from it first
|
|
137
|
-
const oldTableExists = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='tinybase_store'").get();
|
|
138
|
-
if (oldTableExists) {
|
|
139
|
-
const oldPersister = createCustomPersister(store, async () => {
|
|
140
|
-
const row = db.prepare("SELECT store FROM tinybase_store WHERE _id = '_'").get();
|
|
141
|
-
return row ? JSON.parse(row.store) : undefined;
|
|
142
|
-
}, async () => { }, (listener) => setInterval(listener, 1000), (interval) => clearInterval(interval));
|
|
143
|
-
await oldPersister.load();
|
|
144
|
-
oldPersister.destroy();
|
|
145
|
-
}
|
|
146
|
-
persister = createTabularBetterSqlite3Persister(store, db);
|
|
147
|
-
if (oldTableExists) {
|
|
148
|
-
// Save migrated data to new tabular format, then drop old table
|
|
149
|
-
await persister.save();
|
|
150
|
-
db.exec('DROP TABLE IF EXISTS tinybase_store');
|
|
151
|
-
}
|
|
152
|
-
await persister.load();
|
|
153
|
-
// Auto-save: persist to disk whenever the in-memory store changes.
|
|
154
|
-
// Without this, emit() only writes to TinyBase's in-memory store and
|
|
155
|
-
// data is lost if the server is killed before an explicit persist().
|
|
156
|
-
await persister.startAutoSave();
|
|
157
|
-
}
|
|
158
|
-
// Initialize/update instance metadata
|
|
159
|
-
if (!config.inMemory) {
|
|
160
|
-
if (isNew) {
|
|
161
|
-
const meta = createInstanceMeta(resolved, config);
|
|
162
|
-
writeInstanceMeta(instancePath, meta);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
touchInstance(instancePath);
|
|
166
|
-
}
|
|
167
|
-
// Register in namespace for discovery
|
|
168
|
-
registerInstance(config.baseDir ?? path.join(os.homedir(), '.multiagent'), namespace, instanceId, { label: config.label });
|
|
169
|
-
}
|
|
170
|
-
// Initialize tables if they don't exist
|
|
171
|
-
initializeTables(store);
|
|
172
|
-
// Rebuild materialized views from events
|
|
173
|
-
rebuildViews(store);
|
|
174
|
-
// Listener registries
|
|
175
|
-
const agentListeners = new Set();
|
|
176
|
-
const agentIdListeners = new Map();
|
|
177
|
-
const taskListeners = new Set();
|
|
178
|
-
const sessionListeners = new Set();
|
|
179
|
-
const messageListeners = new Map();
|
|
180
|
-
const conversationListeners = new Set();
|
|
181
|
-
const turnListeners = new Set();
|
|
182
|
-
/**
|
|
183
|
-
* Emit a new event to the store
|
|
184
|
-
*/
|
|
185
|
-
function emit(input) {
|
|
186
|
-
const event = {
|
|
187
|
-
...input,
|
|
188
|
-
id: `evt_${nanoid(12)}`,
|
|
189
|
-
version: CURRENT_EVENT_VERSION,
|
|
190
|
-
timestamp: Date.now(),
|
|
191
|
-
};
|
|
192
|
-
// Store the event
|
|
193
|
-
// Note: Use empty object for undefined source to avoid JSON.parse errors in query
|
|
194
|
-
store.setRow('events', event.id, {
|
|
195
|
-
id: event.id,
|
|
196
|
-
version: event.version,
|
|
197
|
-
timestamp: event.timestamp,
|
|
198
|
-
type: event.type,
|
|
199
|
-
source: JSON.stringify(event.source ?? {}),
|
|
200
|
-
target: event.target ? JSON.stringify(event.target) : '',
|
|
201
|
-
payload: JSON.stringify(event.payload),
|
|
202
|
-
metadata: event.metadata ? JSON.stringify(event.metadata) : '',
|
|
203
|
-
});
|
|
204
|
-
// Update materialized views
|
|
205
|
-
applyEventToViews(store, event, notifyAgentChange, notifyTaskChange, notifyMessageChange, notifySessionChange, notifyConversationChange, notifyTurnChange);
|
|
206
|
-
return event;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Query events with filters
|
|
210
|
-
*/
|
|
211
|
-
function query(filter) {
|
|
212
|
-
const events = [];
|
|
213
|
-
const rowIds = store.getRowIds('events');
|
|
214
|
-
for (const rowId of rowIds) {
|
|
215
|
-
const row = store.getRow('events', rowId);
|
|
216
|
-
if (!row.id)
|
|
217
|
-
continue;
|
|
218
|
-
// Parse raw event data
|
|
219
|
-
// Handle legacy data where source might be stored as "undefined" string
|
|
220
|
-
const sourceStr = row.source;
|
|
221
|
-
const parsedSource = sourceStr && sourceStr !== 'undefined'
|
|
222
|
-
? JSON.parse(sourceStr)
|
|
223
|
-
: {};
|
|
224
|
-
const rawEvent = {
|
|
225
|
-
id: row.id,
|
|
226
|
-
version: row.version,
|
|
227
|
-
timestamp: row.timestamp,
|
|
228
|
-
type: row.type,
|
|
229
|
-
source: parsedSource,
|
|
230
|
-
target: row.target ? JSON.parse(row.target) : undefined,
|
|
231
|
-
payload: JSON.parse(row.payload),
|
|
232
|
-
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
233
|
-
};
|
|
234
|
-
// Migrate event to current version if needed
|
|
235
|
-
const event = migrateEvent(rawEvent);
|
|
236
|
-
// Apply filters
|
|
237
|
-
if (filter) {
|
|
238
|
-
if (filter.type && event.type !== filter.type)
|
|
239
|
-
continue;
|
|
240
|
-
if (filter.source_agent_id && event.source.agent_id !== filter.source_agent_id)
|
|
241
|
-
continue;
|
|
242
|
-
if (filter.target_agent_id && event.target?.agent_id !== filter.target_agent_id)
|
|
243
|
-
continue;
|
|
244
|
-
if (filter.after && event.timestamp <= filter.after)
|
|
245
|
-
continue;
|
|
246
|
-
if (filter.before && event.timestamp >= filter.before)
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
events.push(event);
|
|
250
|
-
}
|
|
251
|
-
// Sort by timestamp
|
|
252
|
-
events.sort((a, b) => a.timestamp - b.timestamp);
|
|
253
|
-
// Apply limit
|
|
254
|
-
if (filter?.limit) {
|
|
255
|
-
return events.slice(0, filter.limit);
|
|
256
|
-
}
|
|
257
|
-
return events;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Get agent by ID
|
|
261
|
-
*/
|
|
262
|
-
function getAgent(agentId) {
|
|
263
|
-
const row = store.getRow('agents', agentId);
|
|
264
|
-
if (!row.id)
|
|
265
|
-
return null;
|
|
266
|
-
return rowToAgent(row);
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* List agents with optional filter
|
|
270
|
-
*/
|
|
271
|
-
function listAgents(filter) {
|
|
272
|
-
const agents = [];
|
|
273
|
-
const rowIds = store.getRowIds('agents');
|
|
274
|
-
for (const rowId of rowIds) {
|
|
275
|
-
const row = store.getRow('agents', rowId);
|
|
276
|
-
if (!row.id)
|
|
277
|
-
continue;
|
|
278
|
-
const agent = rowToAgent(row);
|
|
279
|
-
if (filter) {
|
|
280
|
-
if (filter.state && agent.state !== filter.state)
|
|
281
|
-
continue;
|
|
282
|
-
if (filter.parent !== undefined && agent.parent !== filter.parent)
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
agents.push(agent);
|
|
286
|
-
}
|
|
287
|
-
return agents;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Update agent metadata fields (name, plan, metadata).
|
|
291
|
-
* Only provided fields are updated. Metadata is shallow-merged with existing.
|
|
292
|
-
*/
|
|
293
|
-
function updateAgentMetadata(agentId, updates) {
|
|
294
|
-
const row = store.getRow('agents', agentId);
|
|
295
|
-
if (!row.id)
|
|
296
|
-
return;
|
|
297
|
-
const partial = {
|
|
298
|
-
last_activity_at: Date.now(),
|
|
299
|
-
};
|
|
300
|
-
if (updates.name !== undefined) {
|
|
301
|
-
partial.name = updates.name;
|
|
302
|
-
}
|
|
303
|
-
if (updates.plan !== undefined) {
|
|
304
|
-
partial.plan = JSON.stringify(updates.plan);
|
|
305
|
-
}
|
|
306
|
-
if (updates.metadata !== undefined) {
|
|
307
|
-
// Shallow merge with existing metadata
|
|
308
|
-
const existing = row.metadata ? JSON.parse(row.metadata) : {};
|
|
309
|
-
partial.metadata = JSON.stringify({ ...existing, ...updates.metadata });
|
|
310
|
-
}
|
|
311
|
-
store.setPartialRow('agents', agentId, partial);
|
|
312
|
-
const agent = rowToAgent(store.getRow('agents', agentId));
|
|
313
|
-
notifyAgentChange(agentId, agent);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Update an agent's plan entries (persisted to SQLite via TinyBase).
|
|
317
|
-
* Convenience wrapper around updateAgentMetadata.
|
|
318
|
-
*/
|
|
319
|
-
function updateAgentPlan(agentId, plan) {
|
|
320
|
-
updateAgentMetadata(agentId, { plan });
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Get task by ID
|
|
324
|
-
*/
|
|
325
|
-
function getTask(taskId) {
|
|
326
|
-
const row = store.getRow('tasks', taskId);
|
|
327
|
-
if (!row.id)
|
|
328
|
-
return null;
|
|
329
|
-
return rowToTask(row);
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* List tasks with optional filter
|
|
333
|
-
*/
|
|
334
|
-
function listTasks(filter) {
|
|
335
|
-
const tasks = [];
|
|
336
|
-
const rowIds = store.getRowIds('tasks');
|
|
337
|
-
for (const rowId of rowIds) {
|
|
338
|
-
const row = store.getRow('tasks', rowId);
|
|
339
|
-
if (!row.id)
|
|
340
|
-
continue;
|
|
341
|
-
const task = rowToTask(row);
|
|
342
|
-
if (filter) {
|
|
343
|
-
if (filter.status && task.status !== filter.status)
|
|
344
|
-
continue;
|
|
345
|
-
if (filter.assigned_agent && task.assigned_agent !== filter.assigned_agent)
|
|
346
|
-
continue;
|
|
347
|
-
}
|
|
348
|
-
tasks.push(task);
|
|
349
|
-
}
|
|
350
|
-
return tasks;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Get pending messages for an agent
|
|
354
|
-
*/
|
|
355
|
-
function getMessages(agentId, limit) {
|
|
356
|
-
const messages = [];
|
|
357
|
-
const rowIds = store.getRowIds('messages');
|
|
358
|
-
for (const rowId of rowIds) {
|
|
359
|
-
const row = store.getRow('messages', rowId);
|
|
360
|
-
if (!row.id || row.recipient !== agentId)
|
|
361
|
-
continue;
|
|
362
|
-
messages.push({
|
|
363
|
-
id: row.id,
|
|
364
|
-
from: JSON.parse(row.from),
|
|
365
|
-
content: row.content,
|
|
366
|
-
timestamp: row.timestamp,
|
|
367
|
-
truncated: row.truncated,
|
|
368
|
-
correlation_id: row.correlation_id,
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
// Sort by timestamp
|
|
372
|
-
messages.sort((a, b) => a.timestamp - b.timestamp);
|
|
373
|
-
if (limit) {
|
|
374
|
-
return messages.slice(0, limit);
|
|
375
|
-
}
|
|
376
|
-
return messages;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Get full message content by ID
|
|
380
|
-
*/
|
|
381
|
-
function getFullMessage(messageId) {
|
|
382
|
-
// Look up the original event
|
|
383
|
-
const row = store.getRow('events', messageId);
|
|
384
|
-
if (!row.id || row.type !== 'message')
|
|
385
|
-
return null;
|
|
386
|
-
const payload = JSON.parse(row.payload);
|
|
387
|
-
return payload.content ?? null;
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Add a subscription for an agent
|
|
391
|
-
*/
|
|
392
|
-
function addSubscription(agentId, subscription) {
|
|
393
|
-
const subId = `${agentId}:${subscription.type}:${subscription.target}`;
|
|
394
|
-
store.setRow('subscriptions', subId, {
|
|
395
|
-
id: subId,
|
|
396
|
-
agent_id: agentId,
|
|
397
|
-
type: subscription.type,
|
|
398
|
-
target: subscription.target,
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Remove a subscription for an agent
|
|
403
|
-
*/
|
|
404
|
-
function removeSubscription(agentId, subscription) {
|
|
405
|
-
const subId = `${agentId}:${subscription.type}:${subscription.target}`;
|
|
406
|
-
store.delRow('subscriptions', subId);
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Get all subscriptions for an agent
|
|
410
|
-
*/
|
|
411
|
-
function getSubscriptions(agentId) {
|
|
412
|
-
const subscriptions = [];
|
|
413
|
-
const rowIds = store.getRowIds('subscriptions');
|
|
414
|
-
for (const rowId of rowIds) {
|
|
415
|
-
const row = store.getRow('subscriptions', rowId);
|
|
416
|
-
if (row.agent_id !== agentId)
|
|
417
|
-
continue;
|
|
418
|
-
subscriptions.push({
|
|
419
|
-
type: row.type,
|
|
420
|
-
target: row.target,
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
return subscriptions;
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Get all agents subscribed to a given subscription
|
|
427
|
-
*/
|
|
428
|
-
function getSubscribers(subscription) {
|
|
429
|
-
const subscribers = [];
|
|
430
|
-
const rowIds = store.getRowIds('subscriptions');
|
|
431
|
-
for (const rowId of rowIds) {
|
|
432
|
-
const row = store.getRow('subscriptions', rowId);
|
|
433
|
-
if (row.type !== subscription.type || row.target !== subscription.target)
|
|
434
|
-
continue;
|
|
435
|
-
subscribers.push(row.agent_id);
|
|
436
|
-
}
|
|
437
|
-
return subscribers;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Notify agent change listeners
|
|
441
|
-
*/
|
|
442
|
-
function notifyAgentChange(agentId, agent) {
|
|
443
|
-
// Global listeners
|
|
444
|
-
for (const callback of agentListeners) {
|
|
445
|
-
callback(agentId, agent);
|
|
446
|
-
}
|
|
447
|
-
// Specific agent listeners
|
|
448
|
-
const specificListeners = agentIdListeners.get(agentId);
|
|
449
|
-
if (specificListeners) {
|
|
450
|
-
for (const callback of specificListeners) {
|
|
451
|
-
callback(agentId, agent);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Notify task change listeners
|
|
457
|
-
*/
|
|
458
|
-
function notifyTaskChange(taskId, task) {
|
|
459
|
-
for (const callback of taskListeners) {
|
|
460
|
-
callback(taskId, task);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
|
-
* Notify message change listeners
|
|
465
|
-
*/
|
|
466
|
-
function notifyMessageChange(agentId) {
|
|
467
|
-
const listeners = messageListeners.get(agentId);
|
|
468
|
-
if (listeners) {
|
|
469
|
-
const messages = getMessages(agentId);
|
|
470
|
-
for (const callback of listeners) {
|
|
471
|
-
callback(agentId, messages);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Subscribe to agent changes (all agents or specific agent)
|
|
477
|
-
*/
|
|
478
|
-
function onAgentChange(callbackOrId, callback) {
|
|
479
|
-
if (typeof callbackOrId === 'function') {
|
|
480
|
-
// Global subscription
|
|
481
|
-
agentListeners.add(callbackOrId);
|
|
482
|
-
return () => agentListeners.delete(callbackOrId);
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
// Specific agent subscription
|
|
486
|
-
const agentId = callbackOrId;
|
|
487
|
-
const cb = callback;
|
|
488
|
-
if (!agentIdListeners.has(agentId)) {
|
|
489
|
-
agentIdListeners.set(agentId, new Set());
|
|
490
|
-
}
|
|
491
|
-
agentIdListeners.get(agentId).add(cb);
|
|
492
|
-
return () => agentIdListeners.get(agentId)?.delete(cb);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Subscribe to task changes
|
|
497
|
-
*/
|
|
498
|
-
function onTaskChange(callback) {
|
|
499
|
-
taskListeners.add(callback);
|
|
500
|
-
return () => taskListeners.delete(callback);
|
|
501
|
-
}
|
|
502
|
-
/**
|
|
503
|
-
* Subscribe to message changes for an agent
|
|
504
|
-
*/
|
|
505
|
-
function onMessageChange(agentId, callback) {
|
|
506
|
-
if (!messageListeners.has(agentId)) {
|
|
507
|
-
messageListeners.set(agentId, new Set());
|
|
508
|
-
}
|
|
509
|
-
messageListeners.get(agentId).add(callback);
|
|
510
|
-
return () => messageListeners.get(agentId)?.delete(callback);
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* Notify conversation change listeners
|
|
514
|
-
*/
|
|
515
|
-
function notifyConversationChange(conversationId, conversation) {
|
|
516
|
-
for (const callback of conversationListeners) {
|
|
517
|
-
callback(conversationId, conversation);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
/**
|
|
521
|
-
* Notify turn change listeners
|
|
522
|
-
*/
|
|
523
|
-
function notifyTurnChange(conversationId, turn) {
|
|
524
|
-
for (const callback of turnListeners) {
|
|
525
|
-
callback(conversationId, turn);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Subscribe to conversation changes
|
|
530
|
-
*/
|
|
531
|
-
function onConversationChange(callback) {
|
|
532
|
-
conversationListeners.add(callback);
|
|
533
|
-
return () => conversationListeners.delete(callback);
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Subscribe to turn changes
|
|
537
|
-
*/
|
|
538
|
-
function onTurnChange(callback) {
|
|
539
|
-
turnListeners.add(callback);
|
|
540
|
-
return () => turnListeners.delete(callback);
|
|
541
|
-
}
|
|
542
|
-
// ─── Session View Queries ───
|
|
543
|
-
function getSession(sessionId) {
|
|
544
|
-
const row = store.getRow('sessions', sessionId);
|
|
545
|
-
if (!row.id)
|
|
546
|
-
return null;
|
|
547
|
-
return rowToSession(row);
|
|
548
|
-
}
|
|
549
|
-
function listSessions(filter) {
|
|
550
|
-
const sessions = [];
|
|
551
|
-
const rowIds = store.getRowIds('sessions');
|
|
552
|
-
for (const rowId of rowIds) {
|
|
553
|
-
const row = store.getRow('sessions', rowId);
|
|
554
|
-
if (!row.id)
|
|
555
|
-
continue;
|
|
556
|
-
const session = rowToSession(row);
|
|
557
|
-
if (filter) {
|
|
558
|
-
if (filter.state && session.state !== filter.state)
|
|
559
|
-
continue;
|
|
560
|
-
if (filter.agent_id && session.current_agent_id !== filter.agent_id && session.head_manager_id !== filter.agent_id)
|
|
561
|
-
continue;
|
|
562
|
-
}
|
|
563
|
-
sessions.push(session);
|
|
564
|
-
}
|
|
565
|
-
return sessions;
|
|
566
|
-
}
|
|
567
|
-
/**
|
|
568
|
-
* Notify session change listeners
|
|
569
|
-
*/
|
|
570
|
-
function notifySessionChange(sessionId, session) {
|
|
571
|
-
for (const callback of sessionListeners) {
|
|
572
|
-
callback(sessionId, session);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
* Subscribe to session changes
|
|
577
|
-
*/
|
|
578
|
-
function onSessionChange(callback) {
|
|
579
|
-
sessionListeners.add(callback);
|
|
580
|
-
return () => sessionListeners.delete(callback);
|
|
581
|
-
}
|
|
582
|
-
// ─── Conversation View Queries ───
|
|
583
|
-
function getConversation(conversationId) {
|
|
584
|
-
const row = store.getRow('conversations', conversationId);
|
|
585
|
-
if (!row.id)
|
|
586
|
-
return null;
|
|
587
|
-
return rowToConversation(row);
|
|
588
|
-
}
|
|
589
|
-
function listConversations(filter) {
|
|
590
|
-
const conversations = [];
|
|
591
|
-
const rowIds = store.getRowIds('conversations');
|
|
592
|
-
for (const rowId of rowIds) {
|
|
593
|
-
const row = store.getRow('conversations', rowId);
|
|
594
|
-
if (!row.id)
|
|
595
|
-
continue;
|
|
596
|
-
const conversation = rowToConversation(row);
|
|
597
|
-
if (filter) {
|
|
598
|
-
if (filter.type && conversation.type !== filter.type)
|
|
599
|
-
continue;
|
|
600
|
-
if (filter.status && conversation.status !== filter.status)
|
|
601
|
-
continue;
|
|
602
|
-
if (filter.parentConversationId && conversation.parentConversationId !== filter.parentConversationId)
|
|
603
|
-
continue;
|
|
604
|
-
if (filter.participantId) {
|
|
605
|
-
// Check participants table for membership
|
|
606
|
-
const partRow = store.getRow('participants', `${conversation.id}:${filter.participantId}`);
|
|
607
|
-
if (!partRow.id)
|
|
608
|
-
continue;
|
|
609
|
-
// Skip if participant has left
|
|
610
|
-
if (partRow.left_at && partRow.left_at > 0)
|
|
611
|
-
continue;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
conversations.push(conversation);
|
|
615
|
-
}
|
|
616
|
-
return conversations;
|
|
617
|
-
}
|
|
618
|
-
function listTurns(filter) {
|
|
619
|
-
const turns = [];
|
|
620
|
-
const rowIds = store.getRowIds('turns');
|
|
621
|
-
for (const rowId of rowIds) {
|
|
622
|
-
const row = store.getRow('turns', rowId);
|
|
623
|
-
if (!row.id)
|
|
624
|
-
continue;
|
|
625
|
-
const turn = rowToTurn(row);
|
|
626
|
-
// Filter by conversation (required)
|
|
627
|
-
if (turn.conversationId !== filter.conversationId)
|
|
628
|
-
continue;
|
|
629
|
-
// Optional filters
|
|
630
|
-
if (filter.threadId && turn.threadId !== filter.threadId)
|
|
631
|
-
continue;
|
|
632
|
-
if (filter.contentType && turn.contentType !== filter.contentType)
|
|
633
|
-
continue;
|
|
634
|
-
if (filter.participantId && turn.participant !== filter.participantId)
|
|
635
|
-
continue;
|
|
636
|
-
turns.push(turn);
|
|
637
|
-
}
|
|
638
|
-
// Sort
|
|
639
|
-
const order = filter.order ?? 'asc';
|
|
640
|
-
turns.sort((a, b) => order === 'asc' ? a.timestamp - b.timestamp : b.timestamp - a.timestamp);
|
|
641
|
-
// Limit
|
|
642
|
-
if (filter.limit) {
|
|
643
|
-
return turns.slice(0, filter.limit);
|
|
644
|
-
}
|
|
645
|
-
return turns;
|
|
646
|
-
}
|
|
647
|
-
function listParticipants(conversationId, active) {
|
|
648
|
-
const participants = [];
|
|
649
|
-
const rowIds = store.getRowIds('participants');
|
|
650
|
-
for (const rowId of rowIds) {
|
|
651
|
-
const row = store.getRow('participants', rowId);
|
|
652
|
-
if (!row.id)
|
|
653
|
-
continue;
|
|
654
|
-
if (row.conversation_id !== conversationId)
|
|
655
|
-
continue;
|
|
656
|
-
const participant = rowToParticipant(row);
|
|
657
|
-
if (active && participant.leftAt)
|
|
658
|
-
continue;
|
|
659
|
-
participants.push(participant);
|
|
660
|
-
}
|
|
661
|
-
return participants;
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* Persist store to disk
|
|
665
|
-
*/
|
|
666
|
-
async function persist() {
|
|
667
|
-
if (persister) {
|
|
668
|
-
await persister.save();
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
/**
|
|
672
|
-
* Reload store from disk (refresh data from SQLite)
|
|
673
|
-
*/
|
|
674
|
-
async function reload() {
|
|
675
|
-
if (persister) {
|
|
676
|
-
await persister.load();
|
|
677
|
-
// Rebuild materialized views from freshly loaded events
|
|
678
|
-
rebuildViews(store);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* Close the store
|
|
683
|
-
*/
|
|
684
|
-
async function close() {
|
|
685
|
-
if (persister) {
|
|
686
|
-
// Stop auto-save first to prevent race conditions between
|
|
687
|
-
// auto-save callbacks and the explicit save/destroy sequence.
|
|
688
|
-
await persister.stopAutoSave();
|
|
689
|
-
await persister.save();
|
|
690
|
-
// Destroy the persister (removes store listeners) BEFORE closing the DB.
|
|
691
|
-
// The destroy callback is a no-op — we close the DB ourselves below
|
|
692
|
-
// after giving TinyBase's internal async queues time to drain.
|
|
693
|
-
persister.destroy();
|
|
694
|
-
// Allow any in-flight TinyBase microtasks to settle before closing
|
|
695
|
-
// the database connection. Without this, pending writes from store
|
|
696
|
-
// change listeners can race against db.close().
|
|
697
|
-
await new Promise(resolve => setTimeout(resolve, 50));
|
|
698
|
-
}
|
|
699
|
-
if (db) {
|
|
700
|
-
db.close();
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* Get archives directory path
|
|
705
|
-
*/
|
|
706
|
-
function getArchivesDir() {
|
|
707
|
-
return path.join(instancePath, 'archives');
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Get manifest file path
|
|
711
|
-
*/
|
|
712
|
-
function getManifestPath() {
|
|
713
|
-
return path.join(getArchivesDir(), 'manifest.json');
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Read archive manifest
|
|
717
|
-
*/
|
|
718
|
-
function readManifest() {
|
|
719
|
-
const manifestPath = getManifestPath();
|
|
720
|
-
if (fs.existsSync(manifestPath)) {
|
|
721
|
-
return JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
722
|
-
}
|
|
723
|
-
return { version: 1, archives: [] };
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Write archive manifest
|
|
727
|
-
*/
|
|
728
|
-
function writeManifest(manifest) {
|
|
729
|
-
const manifestPath = getManifestPath();
|
|
730
|
-
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* Archive old events to prevent unbounded store growth
|
|
734
|
-
*/
|
|
735
|
-
async function archive(options = {}) {
|
|
736
|
-
// Calculate cutoff timestamp
|
|
737
|
-
let cutoff;
|
|
738
|
-
if (options.before !== undefined) {
|
|
739
|
-
cutoff = options.before;
|
|
740
|
-
}
|
|
741
|
-
else if (options.olderThan) {
|
|
742
|
-
cutoff = Date.now() - parseDuration(options.olderThan);
|
|
743
|
-
}
|
|
744
|
-
else {
|
|
745
|
-
// Default to 30 days
|
|
746
|
-
cutoff = Date.now() - parseDuration('30d');
|
|
747
|
-
}
|
|
748
|
-
// Query events older than cutoff
|
|
749
|
-
const allEvents = query();
|
|
750
|
-
const eventsToArchive = allEvents.filter((e) => e.timestamp < cutoff);
|
|
751
|
-
const eventsToRetain = allEvents.filter((e) => e.timestamp >= cutoff);
|
|
752
|
-
if (eventsToArchive.length === 0) {
|
|
753
|
-
return {
|
|
754
|
-
archivedCount: 0,
|
|
755
|
-
archivePath: '',
|
|
756
|
-
oldestRetained: eventsToRetain.length > 0 ? eventsToRetain[0].timestamp : Date.now(),
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
// Ensure archives directory exists
|
|
760
|
-
const archivesDir = getArchivesDir();
|
|
761
|
-
if (!fs.existsSync(archivesDir)) {
|
|
762
|
-
fs.mkdirSync(archivesDir, { recursive: true });
|
|
763
|
-
}
|
|
764
|
-
// Group events by month
|
|
765
|
-
const eventsByMonth = new Map();
|
|
766
|
-
for (const event of eventsToArchive) {
|
|
767
|
-
const date = new Date(event.timestamp);
|
|
768
|
-
const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
|
|
769
|
-
if (!eventsByMonth.has(monthKey)) {
|
|
770
|
-
eventsByMonth.set(monthKey, []);
|
|
771
|
-
}
|
|
772
|
-
eventsByMonth.get(monthKey).push(event);
|
|
773
|
-
}
|
|
774
|
-
// Read existing manifest
|
|
775
|
-
const manifest = readManifest();
|
|
776
|
-
// Write archive files and update manifest
|
|
777
|
-
let lastArchivePath = '';
|
|
778
|
-
for (const [monthKey, monthEvents] of eventsByMonth) {
|
|
779
|
-
const archivePath = path.join(archivesDir, `${monthKey}.json`);
|
|
780
|
-
lastArchivePath = archivePath;
|
|
781
|
-
// Read existing archive if it exists and merge
|
|
782
|
-
let existingEvents = [];
|
|
783
|
-
if (fs.existsSync(archivePath)) {
|
|
784
|
-
existingEvents = JSON.parse(fs.readFileSync(archivePath, 'utf-8'));
|
|
785
|
-
}
|
|
786
|
-
// Merge and deduplicate by event ID
|
|
787
|
-
const mergedEvents = [...existingEvents, ...monthEvents];
|
|
788
|
-
const uniqueEvents = Array.from(new Map(mergedEvents.map((e) => [e.id, e])).values());
|
|
789
|
-
uniqueEvents.sort((a, b) => a.timestamp - b.timestamp);
|
|
790
|
-
// Write archive file
|
|
791
|
-
fs.writeFileSync(archivePath, JSON.stringify(uniqueEvents, null, 2));
|
|
792
|
-
// Update manifest entry
|
|
793
|
-
const existingIndex = manifest.archives.findIndex((a) => a.path === archivePath);
|
|
794
|
-
const archiveEntry = {
|
|
795
|
-
path: archivePath,
|
|
796
|
-
from: uniqueEvents[0].timestamp,
|
|
797
|
-
to: uniqueEvents[uniqueEvents.length - 1].timestamp,
|
|
798
|
-
eventCount: uniqueEvents.length,
|
|
799
|
-
};
|
|
800
|
-
if (existingIndex >= 0) {
|
|
801
|
-
manifest.archives[existingIndex] = archiveEntry;
|
|
802
|
-
}
|
|
803
|
-
else {
|
|
804
|
-
manifest.archives.push(archiveEntry);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
// Sort manifest archives by date
|
|
808
|
-
manifest.archives.sort((a, b) => a.from - b.from);
|
|
809
|
-
// Write updated manifest
|
|
810
|
-
writeManifest(manifest);
|
|
811
|
-
// Remove archived events from active store
|
|
812
|
-
for (const event of eventsToArchive) {
|
|
813
|
-
store.delRow('events', event.id);
|
|
814
|
-
}
|
|
815
|
-
// Persist the updated store
|
|
816
|
-
await persist();
|
|
817
|
-
return {
|
|
818
|
-
archivedCount: eventsToArchive.length,
|
|
819
|
-
archivePath: lastArchivePath,
|
|
820
|
-
oldestRetained: eventsToRetain.length > 0 ? eventsToRetain[0].timestamp : Date.now(),
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
/**
|
|
824
|
-
* Load archived events by date range
|
|
825
|
-
*/
|
|
826
|
-
async function loadArchive(options = {}) {
|
|
827
|
-
const manifest = readManifest();
|
|
828
|
-
const events = [];
|
|
829
|
-
for (const archive of manifest.archives) {
|
|
830
|
-
// Skip archives outside the requested range
|
|
831
|
-
if (options.from !== undefined && archive.to < options.from)
|
|
832
|
-
continue;
|
|
833
|
-
if (options.to !== undefined && archive.from > options.to)
|
|
834
|
-
continue;
|
|
835
|
-
// Read archive file
|
|
836
|
-
if (!fs.existsSync(archive.path))
|
|
837
|
-
continue;
|
|
838
|
-
const archiveEvents = JSON.parse(fs.readFileSync(archive.path, 'utf-8'));
|
|
839
|
-
// Filter by date range
|
|
840
|
-
for (const event of archiveEvents) {
|
|
841
|
-
if (options.from !== undefined && event.timestamp < options.from)
|
|
842
|
-
continue;
|
|
843
|
-
if (options.to !== undefined && event.timestamp > options.to)
|
|
844
|
-
continue;
|
|
845
|
-
events.push(event);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
// Sort by timestamp
|
|
849
|
-
events.sort((a, b) => a.timestamp - b.timestamp);
|
|
850
|
-
return events;
|
|
851
|
-
}
|
|
852
|
-
/**
|
|
853
|
-
* Get information about available archives
|
|
854
|
-
*/
|
|
855
|
-
async function getArchiveInfo() {
|
|
856
|
-
const manifest = readManifest();
|
|
857
|
-
const totalArchivedEvents = manifest.archives.reduce((sum, a) => sum + a.eventCount, 0);
|
|
858
|
-
return {
|
|
859
|
-
archives: manifest.archives,
|
|
860
|
-
totalArchivedEvents,
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
/**
|
|
864
|
-
* Export events for peer sync
|
|
865
|
-
* @param filter Optional event filter
|
|
866
|
-
* @param options Export options
|
|
867
|
-
* @param options.forPeer If true, filter by peerVisibility config
|
|
868
|
-
*/
|
|
869
|
-
function exportEvents(filter, options) {
|
|
870
|
-
let events = query(filter);
|
|
871
|
-
// If exporting for peer, apply visibility filter
|
|
872
|
-
if (options?.forPeer) {
|
|
873
|
-
events = filterEventsForPeer(events, peerVisibility);
|
|
874
|
-
}
|
|
875
|
-
return events.map((event) => ({
|
|
876
|
-
...event,
|
|
877
|
-
sourceInstance: instanceId,
|
|
878
|
-
}));
|
|
879
|
-
}
|
|
880
|
-
/**
|
|
881
|
-
* Import events from peer
|
|
882
|
-
*/
|
|
883
|
-
function importEvents(events) {
|
|
884
|
-
for (const event of events) {
|
|
885
|
-
// Skip if event already exists
|
|
886
|
-
const existing = store.getRow('events', event.id);
|
|
887
|
-
if (existing.id)
|
|
888
|
-
continue;
|
|
889
|
-
// Store the event
|
|
890
|
-
store.setRow('events', event.id, {
|
|
891
|
-
id: event.id,
|
|
892
|
-
version: event.version,
|
|
893
|
-
timestamp: event.timestamp,
|
|
894
|
-
type: event.type,
|
|
895
|
-
source: JSON.stringify(event.source),
|
|
896
|
-
target: event.target ? JSON.stringify(event.target) : '',
|
|
897
|
-
payload: JSON.stringify(event.payload),
|
|
898
|
-
metadata: event.metadata ? JSON.stringify(event.metadata) : '',
|
|
899
|
-
});
|
|
900
|
-
// Update materialized views
|
|
901
|
-
applyEventToViews(store, event, notifyAgentChange, notifyTaskChange, notifyMessageChange, notifySessionChange, notifyConversationChange, notifyTurnChange);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
/**
|
|
905
|
-
* Get underlying storage backend (for advanced use)
|
|
906
|
-
*/
|
|
907
|
-
function getBackend() {
|
|
908
|
-
return createTinyBaseBackend(store, {
|
|
909
|
-
onFlush: async () => {
|
|
910
|
-
if (persister) {
|
|
911
|
-
await persister.save();
|
|
912
|
-
}
|
|
913
|
-
},
|
|
914
|
-
onClose: async () => {
|
|
915
|
-
if (persister) {
|
|
916
|
-
await persister.save();
|
|
917
|
-
persister.destroy();
|
|
918
|
-
}
|
|
919
|
-
if (db) {
|
|
920
|
-
db.close();
|
|
921
|
-
}
|
|
922
|
-
},
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
return {
|
|
926
|
-
// Instance info
|
|
927
|
-
instanceId,
|
|
928
|
-
namespace,
|
|
929
|
-
instancePath,
|
|
930
|
-
baseDir,
|
|
931
|
-
backendType,
|
|
932
|
-
peerVisibility,
|
|
933
|
-
// Event operations
|
|
934
|
-
emit,
|
|
935
|
-
query,
|
|
936
|
-
// Views
|
|
937
|
-
getAgent,
|
|
938
|
-
listAgents,
|
|
939
|
-
updateAgentPlan,
|
|
940
|
-
updateAgentMetadata,
|
|
941
|
-
getTask,
|
|
942
|
-
listTasks,
|
|
943
|
-
getMessages,
|
|
944
|
-
getFullMessage,
|
|
945
|
-
getSession,
|
|
946
|
-
listSessions,
|
|
947
|
-
getConversation,
|
|
948
|
-
listConversations,
|
|
949
|
-
listTurns,
|
|
950
|
-
listParticipants,
|
|
951
|
-
// Subscriptions
|
|
952
|
-
addSubscription,
|
|
953
|
-
removeSubscription,
|
|
954
|
-
getSubscriptions,
|
|
955
|
-
getSubscribers,
|
|
956
|
-
// Reactive updates
|
|
957
|
-
onAgentChange,
|
|
958
|
-
onTaskChange,
|
|
959
|
-
onMessageChange,
|
|
960
|
-
onSessionChange,
|
|
961
|
-
onConversationChange,
|
|
962
|
-
onTurnChange,
|
|
963
|
-
// Lifecycle
|
|
964
|
-
persist,
|
|
965
|
-
reload,
|
|
966
|
-
close,
|
|
967
|
-
// Archival
|
|
968
|
-
archive,
|
|
969
|
-
loadArchive,
|
|
970
|
-
getArchiveInfo,
|
|
971
|
-
// Export/Import
|
|
972
|
-
exportEvents,
|
|
973
|
-
importEvents,
|
|
974
|
-
// Advanced
|
|
975
|
-
getBackend,
|
|
976
|
-
};
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* Initialize empty tables in the store
|
|
980
|
-
*/
|
|
981
|
-
function initializeTables(store) {
|
|
982
|
-
// Events table is created implicitly when rows are added
|
|
983
|
-
// We just ensure the tables exist by checking row IDs
|
|
984
|
-
store.getRowIds('events');
|
|
985
|
-
store.getRowIds('agents');
|
|
986
|
-
store.getRowIds('tasks');
|
|
987
|
-
store.getRowIds('messages');
|
|
988
|
-
store.getRowIds('subscriptions');
|
|
989
|
-
store.getRowIds('sessions');
|
|
990
|
-
store.getRowIds('conversations');
|
|
991
|
-
store.getRowIds('turns');
|
|
992
|
-
store.getRowIds('threads');
|
|
993
|
-
store.getRowIds('participants');
|
|
994
|
-
}
|
|
995
|
-
/**
|
|
996
|
-
* Rebuild materialized views from the event log
|
|
997
|
-
*/
|
|
998
|
-
function rebuildViews(store) {
|
|
999
|
-
// Preserve out-of-band agent fields that aren't derived from events.
|
|
1000
|
-
// These fields are written directly (not through events),
|
|
1001
|
-
// so they would be lost when we clear and replay.
|
|
1002
|
-
const OUT_OF_BAND_FIELDS = ['plan', 'name', 'metadata'];
|
|
1003
|
-
const savedOutOfBand = new Map();
|
|
1004
|
-
for (const rowId of store.getRowIds('agents')) {
|
|
1005
|
-
const row = store.getRow('agents', rowId);
|
|
1006
|
-
const saved = {};
|
|
1007
|
-
for (const field of OUT_OF_BAND_FIELDS) {
|
|
1008
|
-
const val = row[field];
|
|
1009
|
-
if (val && val !== '' && val !== '[]') {
|
|
1010
|
-
saved[field] = val;
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
if (Object.keys(saved).length > 0) {
|
|
1014
|
-
savedOutOfBand.set(rowId, saved);
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
// Clear existing views
|
|
1018
|
-
for (const rowId of store.getRowIds('agents')) {
|
|
1019
|
-
store.delRow('agents', rowId);
|
|
1020
|
-
}
|
|
1021
|
-
for (const rowId of store.getRowIds('tasks')) {
|
|
1022
|
-
store.delRow('tasks', rowId);
|
|
1023
|
-
}
|
|
1024
|
-
for (const rowId of store.getRowIds('messages')) {
|
|
1025
|
-
store.delRow('messages', rowId);
|
|
1026
|
-
}
|
|
1027
|
-
for (const rowId of store.getRowIds('sessions')) {
|
|
1028
|
-
store.delRow('sessions', rowId);
|
|
1029
|
-
}
|
|
1030
|
-
for (const rowId of store.getRowIds('conversations')) {
|
|
1031
|
-
store.delRow('conversations', rowId);
|
|
1032
|
-
}
|
|
1033
|
-
for (const rowId of store.getRowIds('turns')) {
|
|
1034
|
-
store.delRow('turns', rowId);
|
|
1035
|
-
}
|
|
1036
|
-
for (const rowId of store.getRowIds('threads')) {
|
|
1037
|
-
store.delRow('threads', rowId);
|
|
1038
|
-
}
|
|
1039
|
-
for (const rowId of store.getRowIds('participants')) {
|
|
1040
|
-
store.delRow('participants', rowId);
|
|
1041
|
-
}
|
|
1042
|
-
// Replay all events to rebuild views
|
|
1043
|
-
const events = [];
|
|
1044
|
-
for (const rowId of store.getRowIds('events')) {
|
|
1045
|
-
const row = store.getRow('events', rowId);
|
|
1046
|
-
if (!row.id)
|
|
1047
|
-
continue;
|
|
1048
|
-
// Parse raw event and migrate to current version
|
|
1049
|
-
const rawEvent = {
|
|
1050
|
-
id: row.id,
|
|
1051
|
-
version: row.version,
|
|
1052
|
-
timestamp: row.timestamp,
|
|
1053
|
-
type: row.type,
|
|
1054
|
-
source: JSON.parse(row.source),
|
|
1055
|
-
target: row.target ? JSON.parse(row.target) : undefined,
|
|
1056
|
-
payload: JSON.parse(row.payload),
|
|
1057
|
-
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
1058
|
-
};
|
|
1059
|
-
events.push(migrateEvent(rawEvent));
|
|
1060
|
-
}
|
|
1061
|
-
// Sort by timestamp
|
|
1062
|
-
events.sort((a, b) => a.timestamp - b.timestamp);
|
|
1063
|
-
// Apply each event (no-op callbacks since we're rebuilding)
|
|
1064
|
-
const noop = () => { };
|
|
1065
|
-
for (const event of events) {
|
|
1066
|
-
applyEventToViews(store, event, noop, noop, noop, noop, noop, noop);
|
|
1067
|
-
}
|
|
1068
|
-
// Restore out-of-band agent fields preserved before the wipe
|
|
1069
|
-
for (const [agentId, fields] of savedOutOfBand) {
|
|
1070
|
-
const row = store.getRow('agents', agentId);
|
|
1071
|
-
if (row.id) {
|
|
1072
|
-
store.setPartialRow('agents', agentId, fields);
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
/**
|
|
1077
|
-
* Apply a single event to materialized views
|
|
1078
|
-
*/
|
|
1079
|
-
function applyEventToViews(store, event, notifyAgentChange, notifyTaskChange, notifyMessageChange, notifySessionChange, notifyConversationChange, notifyTurnChange) {
|
|
1080
|
-
switch (event.type) {
|
|
1081
|
-
case 'spawn':
|
|
1082
|
-
applySpawnEvent(store, event, notifyAgentChange);
|
|
1083
|
-
break;
|
|
1084
|
-
case 'stop':
|
|
1085
|
-
applyStopEvent(store, event, notifyAgentChange);
|
|
1086
|
-
break;
|
|
1087
|
-
case 'status':
|
|
1088
|
-
applyStatusEvent(store, event, notifyAgentChange);
|
|
1089
|
-
break;
|
|
1090
|
-
case 'message':
|
|
1091
|
-
applyMessageEvent(store, event, notifyMessageChange);
|
|
1092
|
-
break;
|
|
1093
|
-
case 'task':
|
|
1094
|
-
applyTaskEvent(store, event, notifyTaskChange);
|
|
1095
|
-
break;
|
|
1096
|
-
case 'session':
|
|
1097
|
-
applySessionEvent(store, event, notifySessionChange);
|
|
1098
|
-
break;
|
|
1099
|
-
case 'conversation':
|
|
1100
|
-
applyConversationEvent(store, event, notifyConversationChange);
|
|
1101
|
-
break;
|
|
1102
|
-
case 'turn':
|
|
1103
|
-
applyTurnEvent(store, event, notifyTurnChange);
|
|
1104
|
-
break;
|
|
1105
|
-
case 'thread':
|
|
1106
|
-
applyThreadEvent(store, event);
|
|
1107
|
-
break;
|
|
1108
|
-
case 'peer_message':
|
|
1109
|
-
case 'peer_request':
|
|
1110
|
-
// Peer events are stored in the event log for audit trail
|
|
1111
|
-
// but not materialized into views since PeerManager handles
|
|
1112
|
-
// in-memory queues. Events can be queried via eventStore.query().
|
|
1113
|
-
break;
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
/**
|
|
1117
|
-
* Apply spawn event to agents view
|
|
1118
|
-
*/
|
|
1119
|
-
function applySpawnEvent(store, event, notify) {
|
|
1120
|
-
const payload = event.payload;
|
|
1121
|
-
const agentId = payload.agent_id;
|
|
1122
|
-
const parent = payload.parent ?? null;
|
|
1123
|
-
// Compute lineage
|
|
1124
|
-
let lineage = [];
|
|
1125
|
-
if (parent) {
|
|
1126
|
-
const parentRow = store.getRow('agents', parent);
|
|
1127
|
-
if (parentRow.lineage) {
|
|
1128
|
-
lineage = [...JSON.parse(parentRow.lineage), parent];
|
|
1129
|
-
}
|
|
1130
|
-
else {
|
|
1131
|
-
lineage = [parent];
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
store.setRow('agents', agentId, {
|
|
1135
|
-
id: agentId,
|
|
1136
|
-
name: '',
|
|
1137
|
-
session_id: payload.session_id,
|
|
1138
|
-
provider_session_id: '',
|
|
1139
|
-
parent: parent ?? '',
|
|
1140
|
-
lineage: JSON.stringify(lineage),
|
|
1141
|
-
state: 'spawning',
|
|
1142
|
-
stop_reason: '',
|
|
1143
|
-
task: payload.task,
|
|
1144
|
-
task_id: payload.task_id ?? '',
|
|
1145
|
-
role: payload.role ?? '',
|
|
1146
|
-
config: JSON.stringify(payload.config ?? {}),
|
|
1147
|
-
cwd: payload.cwd ?? process.cwd(),
|
|
1148
|
-
plan: '[]',
|
|
1149
|
-
metadata: '',
|
|
1150
|
-
created_at: event.timestamp,
|
|
1151
|
-
started_at: 0,
|
|
1152
|
-
stopped_at: 0,
|
|
1153
|
-
last_activity_at: event.timestamp,
|
|
1154
|
-
});
|
|
1155
|
-
const agent = rowToAgent(store.getRow('agents', agentId));
|
|
1156
|
-
notify(agentId, agent);
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* Apply stop event to agents view
|
|
1160
|
-
*/
|
|
1161
|
-
function applyStopEvent(store, event, notify) {
|
|
1162
|
-
const agentId = event.source.agent_id;
|
|
1163
|
-
if (!agentId)
|
|
1164
|
-
return;
|
|
1165
|
-
const payload = event.payload;
|
|
1166
|
-
store.setPartialRow('agents', agentId, {
|
|
1167
|
-
state: 'stopped',
|
|
1168
|
-
stop_reason: payload.reason,
|
|
1169
|
-
stopped_at: event.timestamp,
|
|
1170
|
-
last_activity_at: event.timestamp,
|
|
1171
|
-
});
|
|
1172
|
-
const agent = rowToAgent(store.getRow('agents', agentId));
|
|
1173
|
-
notify(agentId, agent);
|
|
1174
|
-
}
|
|
1175
|
-
/**
|
|
1176
|
-
* Apply status event to agents view
|
|
1177
|
-
*/
|
|
1178
|
-
function applyStatusEvent(store, event, notify) {
|
|
1179
|
-
const agentId = event.source.agent_id;
|
|
1180
|
-
if (!agentId)
|
|
1181
|
-
return;
|
|
1182
|
-
const payload = event.payload;
|
|
1183
|
-
// Handle specific status types
|
|
1184
|
-
if (payload.status_type === 'started') {
|
|
1185
|
-
const updates = {
|
|
1186
|
-
state: 'running',
|
|
1187
|
-
started_at: event.timestamp,
|
|
1188
|
-
last_activity_at: event.timestamp,
|
|
1189
|
-
};
|
|
1190
|
-
// Store the provider's session ID (e.g., Claude Code UUID for --resume)
|
|
1191
|
-
if (payload.provider_session_id) {
|
|
1192
|
-
updates.provider_session_id = payload.provider_session_id;
|
|
1193
|
-
}
|
|
1194
|
-
store.setPartialRow('agents', agentId, updates);
|
|
1195
|
-
}
|
|
1196
|
-
else {
|
|
1197
|
-
// Always update last_activity_at on any status event
|
|
1198
|
-
store.setPartialRow('agents', agentId, {
|
|
1199
|
-
last_activity_at: event.timestamp,
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
const agent = rowToAgent(store.getRow('agents', agentId));
|
|
1203
|
-
notify(agentId, agent);
|
|
1204
|
-
}
|
|
1205
|
-
/**
|
|
1206
|
-
* Apply message event to messages view
|
|
1207
|
-
*/
|
|
1208
|
-
function applyMessageEvent(store, event, notify) {
|
|
1209
|
-
const target = event.target;
|
|
1210
|
-
if (!target)
|
|
1211
|
-
return;
|
|
1212
|
-
const payload = event.payload;
|
|
1213
|
-
// Handle various payload formats - content may be a string, object, or missing
|
|
1214
|
-
const rawContent = payload.content;
|
|
1215
|
-
const content = typeof rawContent === 'string'
|
|
1216
|
-
? rawContent
|
|
1217
|
-
: rawContent != null
|
|
1218
|
-
? JSON.stringify(rawContent)
|
|
1219
|
-
: '[no content]';
|
|
1220
|
-
// Truncate if needed (1000 chars limit)
|
|
1221
|
-
const MAX_CONTENT_LENGTH = 1000;
|
|
1222
|
-
const truncated = content.length > MAX_CONTENT_LENGTH;
|
|
1223
|
-
const displayContent = truncated ? content.slice(0, MAX_CONTENT_LENGTH) + '...' : content;
|
|
1224
|
-
// Route to direct agent target
|
|
1225
|
-
if (target.agent_id) {
|
|
1226
|
-
const messageId = `${event.id}:${target.agent_id}`;
|
|
1227
|
-
store.setRow('messages', messageId, {
|
|
1228
|
-
id: event.id,
|
|
1229
|
-
recipient: target.agent_id,
|
|
1230
|
-
from: JSON.stringify(event.source),
|
|
1231
|
-
content: displayContent,
|
|
1232
|
-
timestamp: event.timestamp,
|
|
1233
|
-
truncated,
|
|
1234
|
-
correlation_id: payload.correlation_id ?? '',
|
|
1235
|
-
});
|
|
1236
|
-
notify(target.agent_id);
|
|
1237
|
-
}
|
|
1238
|
-
// Route to topic subscribers
|
|
1239
|
-
if (target.topic) {
|
|
1240
|
-
const rowIds = store.getRowIds('subscriptions');
|
|
1241
|
-
for (const rowId of rowIds) {
|
|
1242
|
-
const row = store.getRow('subscriptions', rowId);
|
|
1243
|
-
if (row.type === 'topic' && row.target === target.topic) {
|
|
1244
|
-
const recipientId = row.agent_id;
|
|
1245
|
-
const messageId = `${event.id}:${recipientId}`;
|
|
1246
|
-
store.setRow('messages', messageId, {
|
|
1247
|
-
id: event.id,
|
|
1248
|
-
recipient: recipientId,
|
|
1249
|
-
from: JSON.stringify(event.source),
|
|
1250
|
-
content: displayContent,
|
|
1251
|
-
timestamp: event.timestamp,
|
|
1252
|
-
truncated,
|
|
1253
|
-
correlation_id: payload.correlation_id ?? '',
|
|
1254
|
-
});
|
|
1255
|
-
notify(recipientId);
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
/**
|
|
1261
|
-
* Apply task event to tasks view
|
|
1262
|
-
*/
|
|
1263
|
-
function applyTaskEvent(store, event, notify) {
|
|
1264
|
-
const payload = event.payload;
|
|
1265
|
-
const taskId = payload.task_id;
|
|
1266
|
-
switch (payload.action) {
|
|
1267
|
-
case 'created': {
|
|
1268
|
-
const details = payload.details;
|
|
1269
|
-
store.setRow('tasks', taskId, {
|
|
1270
|
-
id: taskId,
|
|
1271
|
-
description: details.description,
|
|
1272
|
-
status: 'pending',
|
|
1273
|
-
assigned_agent: '',
|
|
1274
|
-
parent_task: details.parent_task ?? '',
|
|
1275
|
-
subtasks: JSON.stringify([]),
|
|
1276
|
-
blockers: JSON.stringify([]),
|
|
1277
|
-
tags: details.tags ? JSON.stringify(details.tags) : '',
|
|
1278
|
-
created_at: event.timestamp,
|
|
1279
|
-
started_at: 0,
|
|
1280
|
-
completed_at: 0,
|
|
1281
|
-
created_by: event.source.agent_id ?? '',
|
|
1282
|
-
inputs: JSON.stringify(details.inputs ?? {}),
|
|
1283
|
-
outputs: JSON.stringify({}),
|
|
1284
|
-
artifacts: JSON.stringify([]),
|
|
1285
|
-
agent_history: JSON.stringify([]),
|
|
1286
|
-
retry_policy: details.retryPolicy
|
|
1287
|
-
? JSON.stringify(details.retryPolicy)
|
|
1288
|
-
: '',
|
|
1289
|
-
retry_state: '',
|
|
1290
|
-
});
|
|
1291
|
-
break;
|
|
1292
|
-
}
|
|
1293
|
-
case 'assigned': {
|
|
1294
|
-
const details = payload.details;
|
|
1295
|
-
const existing = store.getRow('tasks', taskId);
|
|
1296
|
-
const history = existing.agent_history
|
|
1297
|
-
? JSON.parse(existing.agent_history)
|
|
1298
|
-
: [];
|
|
1299
|
-
history.push({
|
|
1300
|
-
agent_id: details.agent_id,
|
|
1301
|
-
role: details.role,
|
|
1302
|
-
assigned_at: event.timestamp,
|
|
1303
|
-
});
|
|
1304
|
-
store.setPartialRow('tasks', taskId, {
|
|
1305
|
-
status: 'assigned',
|
|
1306
|
-
assigned_agent: details.agent_id,
|
|
1307
|
-
agent_history: JSON.stringify(history),
|
|
1308
|
-
});
|
|
1309
|
-
break;
|
|
1310
|
-
}
|
|
1311
|
-
case 'unassigned': {
|
|
1312
|
-
const details = payload.details;
|
|
1313
|
-
const existing = store.getRow('tasks', taskId);
|
|
1314
|
-
const history = existing.agent_history
|
|
1315
|
-
? JSON.parse(existing.agent_history)
|
|
1316
|
-
: [];
|
|
1317
|
-
// Update the last entry for this agent with ended_at
|
|
1318
|
-
for (let i = history.length - 1; i >= 0; i--) {
|
|
1319
|
-
if (history[i].agent_id === details.agent_id && !history[i].ended_at) {
|
|
1320
|
-
history[i].ended_at = event.timestamp;
|
|
1321
|
-
break;
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
const updates = {
|
|
1325
|
-
assigned_agent: '',
|
|
1326
|
-
agent_history: JSON.stringify(history),
|
|
1327
|
-
};
|
|
1328
|
-
// Reset to pending if task was only assigned (not yet started)
|
|
1329
|
-
if (existing.status === 'assigned') {
|
|
1330
|
-
updates.status = 'pending';
|
|
1331
|
-
}
|
|
1332
|
-
store.setPartialRow('tasks', taskId, updates);
|
|
1333
|
-
break;
|
|
1334
|
-
}
|
|
1335
|
-
case 'status_change': {
|
|
1336
|
-
const details = payload.details;
|
|
1337
|
-
const updates = {};
|
|
1338
|
-
if (details.status) {
|
|
1339
|
-
updates.status = details.status;
|
|
1340
|
-
if (details.status === 'in_progress') {
|
|
1341
|
-
const existing = store.getRow('tasks', taskId);
|
|
1342
|
-
if (!existing.started_at) {
|
|
1343
|
-
updates.started_at = event.timestamp;
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
if (details.outputs !== undefined) {
|
|
1348
|
-
updates.outputs = JSON.stringify(details.outputs);
|
|
1349
|
-
}
|
|
1350
|
-
if (details.artifacts !== undefined) {
|
|
1351
|
-
const existing = store.getRow('tasks', taskId);
|
|
1352
|
-
const currentArtifacts = existing.artifacts
|
|
1353
|
-
? JSON.parse(existing.artifacts)
|
|
1354
|
-
: [];
|
|
1355
|
-
updates.artifacts = JSON.stringify([
|
|
1356
|
-
...currentArtifacts,
|
|
1357
|
-
...details.artifacts,
|
|
1358
|
-
]);
|
|
1359
|
-
}
|
|
1360
|
-
if (details.description !== undefined) {
|
|
1361
|
-
updates.description = details.description;
|
|
1362
|
-
}
|
|
1363
|
-
if (details.subtask_added) {
|
|
1364
|
-
const existing = store.getRow('tasks', taskId);
|
|
1365
|
-
const subtasks = existing.subtasks
|
|
1366
|
-
? JSON.parse(existing.subtasks)
|
|
1367
|
-
: [];
|
|
1368
|
-
subtasks.push(details.subtask_added);
|
|
1369
|
-
updates.subtasks = JSON.stringify(subtasks);
|
|
1370
|
-
}
|
|
1371
|
-
if (details.retryState !== undefined) {
|
|
1372
|
-
updates.retry_state = JSON.stringify(details.retryState);
|
|
1373
|
-
}
|
|
1374
|
-
// Allow clearing the assigned agent (for retry)
|
|
1375
|
-
if (details.agent_id === null) {
|
|
1376
|
-
updates.assigned_agent = '';
|
|
1377
|
-
}
|
|
1378
|
-
if (Object.keys(updates).length > 0) {
|
|
1379
|
-
store.setPartialRow('tasks', taskId, updates);
|
|
1380
|
-
}
|
|
1381
|
-
break;
|
|
1382
|
-
}
|
|
1383
|
-
case 'completed': {
|
|
1384
|
-
store.setPartialRow('tasks', taskId, {
|
|
1385
|
-
status: 'completed',
|
|
1386
|
-
completed_at: event.timestamp,
|
|
1387
|
-
});
|
|
1388
|
-
break;
|
|
1389
|
-
}
|
|
1390
|
-
case 'failed': {
|
|
1391
|
-
store.setPartialRow('tasks', taskId, {
|
|
1392
|
-
status: 'failed',
|
|
1393
|
-
completed_at: event.timestamp,
|
|
1394
|
-
});
|
|
1395
|
-
break;
|
|
1396
|
-
}
|
|
1397
|
-
case 'blocker_added': {
|
|
1398
|
-
const details = payload.details;
|
|
1399
|
-
const existing = store.getRow('tasks', taskId);
|
|
1400
|
-
const blockers = existing.blockers
|
|
1401
|
-
? JSON.parse(existing.blockers)
|
|
1402
|
-
: [];
|
|
1403
|
-
if (!blockers.includes(details.blocker_id)) {
|
|
1404
|
-
blockers.push(details.blocker_id);
|
|
1405
|
-
store.setPartialRow('tasks', taskId, {
|
|
1406
|
-
blockers: JSON.stringify(blockers),
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
|
-
break;
|
|
1410
|
-
}
|
|
1411
|
-
case 'blocker_removed': {
|
|
1412
|
-
const details = payload.details;
|
|
1413
|
-
const existing = store.getRow('tasks', taskId);
|
|
1414
|
-
const blockers = existing.blockers
|
|
1415
|
-
? JSON.parse(existing.blockers)
|
|
1416
|
-
: [];
|
|
1417
|
-
const idx = blockers.indexOf(details.blocker_id);
|
|
1418
|
-
if (idx >= 0) {
|
|
1419
|
-
blockers.splice(idx, 1);
|
|
1420
|
-
store.setPartialRow('tasks', taskId, {
|
|
1421
|
-
blockers: JSON.stringify(blockers),
|
|
1422
|
-
});
|
|
1423
|
-
}
|
|
1424
|
-
break;
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
const task = rowToTask(store.getRow('tasks', taskId));
|
|
1428
|
-
notify(taskId, task);
|
|
1429
|
-
}
|
|
1430
|
-
/**
|
|
1431
|
-
* Convert a TinyBase row to an Agent object
|
|
1432
|
-
*/
|
|
1433
|
-
function rowToAgent(row) {
|
|
1434
|
-
const stopReason = row.stop_reason;
|
|
1435
|
-
return {
|
|
1436
|
-
id: row.id,
|
|
1437
|
-
name: row.name || undefined,
|
|
1438
|
-
session_id: row.session_id,
|
|
1439
|
-
provider_session_id: row.provider_session_id || undefined,
|
|
1440
|
-
parent: row.parent || null,
|
|
1441
|
-
lineage: row.lineage ? JSON.parse(row.lineage) : [],
|
|
1442
|
-
state: row.state,
|
|
1443
|
-
stop_reason: stopReason ? stopReason : undefined,
|
|
1444
|
-
task: row.task,
|
|
1445
|
-
task_id: row.task_id || undefined,
|
|
1446
|
-
role: row.role || undefined,
|
|
1447
|
-
config: row.config ? JSON.parse(row.config) : {},
|
|
1448
|
-
cwd: row.cwd || process.cwd(),
|
|
1449
|
-
plan: row.plan ? JSON.parse(row.plan) : [],
|
|
1450
|
-
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
1451
|
-
created_at: row.created_at,
|
|
1452
|
-
started_at: row.started_at || undefined,
|
|
1453
|
-
stopped_at: row.stopped_at || undefined,
|
|
1454
|
-
last_activity_at: row.last_activity_at || undefined,
|
|
1455
|
-
};
|
|
1456
|
-
}
|
|
1457
|
-
/**
|
|
1458
|
-
* Convert a TinyBase row to a Task object
|
|
1459
|
-
*/
|
|
1460
|
-
function rowToTask(row) {
|
|
1461
|
-
return {
|
|
1462
|
-
id: row.id,
|
|
1463
|
-
description: row.description,
|
|
1464
|
-
status: row.status,
|
|
1465
|
-
assigned_agent: row.assigned_agent || undefined,
|
|
1466
|
-
parent_task: row.parent_task || undefined,
|
|
1467
|
-
subtasks: row.subtasks ? JSON.parse(row.subtasks) : undefined,
|
|
1468
|
-
blockers: row.blockers ? JSON.parse(row.blockers) : undefined,
|
|
1469
|
-
created_at: row.created_at,
|
|
1470
|
-
started_at: row.started_at || undefined,
|
|
1471
|
-
completed_at: row.completed_at || undefined,
|
|
1472
|
-
created_by: row.created_by,
|
|
1473
|
-
inputs: row.inputs ? JSON.parse(row.inputs) : undefined,
|
|
1474
|
-
outputs: row.outputs ? JSON.parse(row.outputs) : undefined,
|
|
1475
|
-
artifacts: row.artifacts ? JSON.parse(row.artifacts) : undefined,
|
|
1476
|
-
agent_history: row.agent_history ? JSON.parse(row.agent_history) : undefined,
|
|
1477
|
-
tags: row.tags ? JSON.parse(row.tags) : undefined,
|
|
1478
|
-
retryPolicy: row.retry_policy ? JSON.parse(row.retry_policy) : undefined,
|
|
1479
|
-
retryState: row.retry_state ? JSON.parse(row.retry_state) : undefined,
|
|
1480
|
-
};
|
|
1481
|
-
}
|
|
1482
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1483
|
-
// Session Event Handlers
|
|
1484
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1485
|
-
/**
|
|
1486
|
-
* Apply session event to sessions view
|
|
1487
|
-
*/
|
|
1488
|
-
function applySessionEvent(store, event, notify) {
|
|
1489
|
-
const payload = event.payload;
|
|
1490
|
-
const sessionId = payload.session_id;
|
|
1491
|
-
switch (payload.action) {
|
|
1492
|
-
case 'created': {
|
|
1493
|
-
store.setRow('sessions', sessionId, {
|
|
1494
|
-
id: sessionId,
|
|
1495
|
-
head_manager_id: payload.head_manager_id ?? '',
|
|
1496
|
-
current_agent_id: payload.head_manager_id ?? '',
|
|
1497
|
-
state: 'active',
|
|
1498
|
-
created_at: event.timestamp,
|
|
1499
|
-
updated_at: event.timestamp,
|
|
1500
|
-
closed_at: 0,
|
|
1501
|
-
});
|
|
1502
|
-
break;
|
|
1503
|
-
}
|
|
1504
|
-
case 'mounted': {
|
|
1505
|
-
store.setPartialRow('sessions', sessionId, {
|
|
1506
|
-
current_agent_id: payload.target_agent_id ?? '',
|
|
1507
|
-
state: 'mounted',
|
|
1508
|
-
updated_at: event.timestamp,
|
|
1509
|
-
});
|
|
1510
|
-
break;
|
|
1511
|
-
}
|
|
1512
|
-
case 'unmounted': {
|
|
1513
|
-
const existing = store.getRow('sessions', sessionId);
|
|
1514
|
-
store.setPartialRow('sessions', sessionId, {
|
|
1515
|
-
current_agent_id: existing.head_manager_id,
|
|
1516
|
-
state: 'active',
|
|
1517
|
-
updated_at: event.timestamp,
|
|
1518
|
-
});
|
|
1519
|
-
break;
|
|
1520
|
-
}
|
|
1521
|
-
case 'closed': {
|
|
1522
|
-
store.setPartialRow('sessions', sessionId, {
|
|
1523
|
-
state: 'closed',
|
|
1524
|
-
updated_at: event.timestamp,
|
|
1525
|
-
closed_at: event.timestamp,
|
|
1526
|
-
});
|
|
1527
|
-
break;
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
const session = rowToSession(store.getRow('sessions', sessionId));
|
|
1531
|
-
notify(sessionId, session);
|
|
1532
|
-
}
|
|
1533
|
-
/**
|
|
1534
|
-
* Convert a TinyBase row to a Session object
|
|
1535
|
-
*/
|
|
1536
|
-
function rowToSession(row) {
|
|
1537
|
-
return {
|
|
1538
|
-
id: row.id,
|
|
1539
|
-
head_manager_id: row.head_manager_id,
|
|
1540
|
-
current_agent_id: row.current_agent_id,
|
|
1541
|
-
state: row.state,
|
|
1542
|
-
created_at: row.created_at,
|
|
1543
|
-
updated_at: row.updated_at,
|
|
1544
|
-
closed_at: row.closed_at || undefined,
|
|
1545
|
-
};
|
|
1546
|
-
}
|
|
1547
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1548
|
-
// Conversation Event Handlers
|
|
1549
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1550
|
-
/**
|
|
1551
|
-
* Apply conversation event to conversations view
|
|
1552
|
-
*/
|
|
1553
|
-
function applyConversationEvent(store, event, notify) {
|
|
1554
|
-
const payload = event.payload;
|
|
1555
|
-
const conversationId = payload.conversation_id;
|
|
1556
|
-
switch (payload.action) {
|
|
1557
|
-
case 'created': {
|
|
1558
|
-
store.setRow('conversations', conversationId, {
|
|
1559
|
-
id: conversationId,
|
|
1560
|
-
type: payload.conversation_type,
|
|
1561
|
-
status: 'active',
|
|
1562
|
-
subject: payload.subject ?? '',
|
|
1563
|
-
parent_conversation_id: payload.parent_conversation_id ?? '',
|
|
1564
|
-
created_by: event.source.agent_id ?? 'unknown',
|
|
1565
|
-
created_at: event.timestamp,
|
|
1566
|
-
updated_at: event.timestamp,
|
|
1567
|
-
closed_at: 0,
|
|
1568
|
-
closed_by: '',
|
|
1569
|
-
close_reason: '',
|
|
1570
|
-
participant_count: 0,
|
|
1571
|
-
metadata: payload.metadata ? JSON.stringify(payload.metadata) : '',
|
|
1572
|
-
});
|
|
1573
|
-
break;
|
|
1574
|
-
}
|
|
1575
|
-
case 'closed': {
|
|
1576
|
-
const closeReason = payload.close_reason ?? '';
|
|
1577
|
-
// Map close_reason to valid ConversationStatus
|
|
1578
|
-
const validStatuses = new Set(['completed', 'failed', 'archived']);
|
|
1579
|
-
const closedStatus = validStatuses.has(closeReason) ? closeReason : 'completed';
|
|
1580
|
-
store.setPartialRow('conversations', conversationId, {
|
|
1581
|
-
status: closedStatus,
|
|
1582
|
-
closed_at: event.timestamp,
|
|
1583
|
-
updated_at: event.timestamp,
|
|
1584
|
-
closed_by: payload.closed_by ?? event.source.agent_id ?? '',
|
|
1585
|
-
close_reason: closeReason,
|
|
1586
|
-
});
|
|
1587
|
-
break;
|
|
1588
|
-
}
|
|
1589
|
-
case 'participant_joined': {
|
|
1590
|
-
const participantId = payload.participant_id;
|
|
1591
|
-
const partId = `${conversationId}:${participantId}`;
|
|
1592
|
-
store.setRow('participants', partId, {
|
|
1593
|
-
id: participantId,
|
|
1594
|
-
conversation_id: conversationId,
|
|
1595
|
-
type: payload.participant_type ?? 'agent',
|
|
1596
|
-
role: payload.participant_role ?? 'worker',
|
|
1597
|
-
joined_at: event.timestamp,
|
|
1598
|
-
left_at: 0,
|
|
1599
|
-
agent_id: payload.agent_id ?? '',
|
|
1600
|
-
});
|
|
1601
|
-
// Increment participant count
|
|
1602
|
-
const existing = store.getRow('conversations', conversationId);
|
|
1603
|
-
if (existing.id) {
|
|
1604
|
-
const count = existing.participant_count || 0;
|
|
1605
|
-
store.setPartialRow('conversations', conversationId, {
|
|
1606
|
-
participant_count: count + 1,
|
|
1607
|
-
updated_at: event.timestamp,
|
|
1608
|
-
});
|
|
1609
|
-
}
|
|
1610
|
-
break;
|
|
1611
|
-
}
|
|
1612
|
-
case 'participant_left': {
|
|
1613
|
-
const leftParticipantId = payload.participant_id;
|
|
1614
|
-
const partId = `${conversationId}:${leftParticipantId}`;
|
|
1615
|
-
store.setPartialRow('participants', partId, {
|
|
1616
|
-
left_at: event.timestamp,
|
|
1617
|
-
});
|
|
1618
|
-
// Decrement participant count
|
|
1619
|
-
const existing = store.getRow('conversations', conversationId);
|
|
1620
|
-
if (existing.id) {
|
|
1621
|
-
const count = existing.participant_count || 0;
|
|
1622
|
-
store.setPartialRow('conversations', conversationId, {
|
|
1623
|
-
participant_count: Math.max(0, count - 1),
|
|
1624
|
-
updated_at: event.timestamp,
|
|
1625
|
-
});
|
|
1626
|
-
}
|
|
1627
|
-
break;
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
const conversation = rowToConversation(store.getRow('conversations', conversationId));
|
|
1631
|
-
notify(conversationId, conversation);
|
|
1632
|
-
}
|
|
1633
|
-
/**
|
|
1634
|
-
* Apply turn event to turns view
|
|
1635
|
-
*/
|
|
1636
|
-
function applyTurnEvent(store, event, notify) {
|
|
1637
|
-
const payload = event.payload;
|
|
1638
|
-
if (payload.action !== 'recorded')
|
|
1639
|
-
return;
|
|
1640
|
-
const turnId = payload.turn_id;
|
|
1641
|
-
const conversationId = payload.conversation_id;
|
|
1642
|
-
const content = payload.content;
|
|
1643
|
-
store.setRow('turns', turnId, {
|
|
1644
|
-
id: turnId,
|
|
1645
|
-
conversation_id: conversationId,
|
|
1646
|
-
participant: payload.participant ?? event.source.agent_id ?? '',
|
|
1647
|
-
timestamp: event.timestamp,
|
|
1648
|
-
content_type: payload.content_type ?? 'text',
|
|
1649
|
-
content: typeof content === 'string' ? content : JSON.stringify(content),
|
|
1650
|
-
thread_id: payload.thread_id ?? '',
|
|
1651
|
-
in_reply_to: payload.in_reply_to ?? '',
|
|
1652
|
-
source_type: payload.source_type ?? 'explicit',
|
|
1653
|
-
source_message_id: payload.source_message_id ?? '',
|
|
1654
|
-
metadata: payload.metadata ? JSON.stringify(payload.metadata) : '',
|
|
1655
|
-
});
|
|
1656
|
-
// Update conversation's updatedAt
|
|
1657
|
-
const convRow = store.getRow('conversations', conversationId);
|
|
1658
|
-
if (convRow.id) {
|
|
1659
|
-
store.setPartialRow('conversations', conversationId, {
|
|
1660
|
-
updated_at: event.timestamp,
|
|
1661
|
-
});
|
|
1662
|
-
}
|
|
1663
|
-
const turn = rowToTurn(store.getRow('turns', turnId));
|
|
1664
|
-
notify(conversationId, turn);
|
|
1665
|
-
}
|
|
1666
|
-
/**
|
|
1667
|
-
* Apply thread event to threads view
|
|
1668
|
-
*/
|
|
1669
|
-
function applyThreadEvent(store, event) {
|
|
1670
|
-
const payload = event.payload;
|
|
1671
|
-
if (payload.action !== 'created')
|
|
1672
|
-
return;
|
|
1673
|
-
const threadId = payload.thread_id;
|
|
1674
|
-
store.setRow('threads', threadId, {
|
|
1675
|
-
id: threadId,
|
|
1676
|
-
conversation_id: payload.conversation_id ?? '',
|
|
1677
|
-
root_turn_id: payload.root_turn_id ?? '',
|
|
1678
|
-
subject: payload.subject ?? '',
|
|
1679
|
-
parent_thread_id: payload.parent_thread_id ?? '',
|
|
1680
|
-
created_by: event.source.agent_id ?? 'unknown',
|
|
1681
|
-
created_at: event.timestamp,
|
|
1682
|
-
turn_count: 0,
|
|
1683
|
-
});
|
|
1684
|
-
}
|
|
1685
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1686
|
-
// Conversation Row Conversion Functions
|
|
1687
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1688
|
-
function rowToConversation(row) {
|
|
1689
|
-
return {
|
|
1690
|
-
id: row.id,
|
|
1691
|
-
type: row.type,
|
|
1692
|
-
status: row.status,
|
|
1693
|
-
subject: row.subject || undefined,
|
|
1694
|
-
parentConversationId: row.parent_conversation_id || undefined,
|
|
1695
|
-
createdBy: row.created_by,
|
|
1696
|
-
createdAt: row.created_at,
|
|
1697
|
-
updatedAt: row.updated_at,
|
|
1698
|
-
closedAt: row.closed_at || undefined,
|
|
1699
|
-
closedBy: row.closed_by || undefined,
|
|
1700
|
-
closeReason: row.close_reason || undefined,
|
|
1701
|
-
participantCount: row.participant_count || 0,
|
|
1702
|
-
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
1703
|
-
};
|
|
1704
|
-
}
|
|
1705
|
-
function rowToTurn(row) {
|
|
1706
|
-
const rawContent = row.content;
|
|
1707
|
-
let content;
|
|
1708
|
-
try {
|
|
1709
|
-
content = JSON.parse(rawContent);
|
|
1710
|
-
}
|
|
1711
|
-
catch {
|
|
1712
|
-
content = rawContent;
|
|
1713
|
-
}
|
|
1714
|
-
return {
|
|
1715
|
-
id: row.id,
|
|
1716
|
-
conversationId: row.conversation_id,
|
|
1717
|
-
participant: row.participant,
|
|
1718
|
-
timestamp: row.timestamp,
|
|
1719
|
-
contentType: row.content_type,
|
|
1720
|
-
content,
|
|
1721
|
-
threadId: row.thread_id || undefined,
|
|
1722
|
-
inReplyTo: row.in_reply_to || undefined,
|
|
1723
|
-
sourceType: row.source_type,
|
|
1724
|
-
sourceMessageId: row.source_message_id || undefined,
|
|
1725
|
-
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
1726
|
-
};
|
|
1727
|
-
}
|
|
1728
|
-
function rowToParticipant(row) {
|
|
1729
|
-
return {
|
|
1730
|
-
id: row.id,
|
|
1731
|
-
conversationId: row.conversation_id,
|
|
1732
|
-
type: row.type,
|
|
1733
|
-
role: row.role,
|
|
1734
|
-
joinedAt: row.joined_at,
|
|
1735
|
-
leftAt: row.left_at || undefined,
|
|
1736
|
-
agentId: row.agent_id || undefined,
|
|
1737
|
-
};
|
|
1738
|
-
}
|
|
1739
|
-
//# sourceMappingURL=event-store.js.map
|