@swarmclawai/swarmclaw 0.8.4 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/bin/swarmclaw.js +5 -1
- package/bin/worker-cmd.js +73 -0
- package/package.json +2 -1
- package/src/app/api/agents/[id]/route.ts +17 -7
- package/src/app/api/agents/route.ts +21 -8
- package/src/app/api/approvals/route.test.ts +6 -6
- package/src/app/api/approvals/route.ts +2 -1
- package/src/app/api/auth/route.ts +2 -3
- package/src/app/api/chatrooms/[id]/chat/route.test.ts +299 -0
- package/src/app/api/chatrooms/[id]/chat/route.ts +3 -2
- package/src/app/api/chatrooms/[id]/route.ts +7 -6
- package/src/app/api/chats/[id]/chat/route.test.ts +496 -0
- package/src/app/api/chats/[id]/chat/route.ts +7 -3
- package/src/app/api/chats/[id]/clear/route.ts +9 -9
- package/src/app/api/chats/[id]/devserver/route.ts +2 -1
- package/src/app/api/chats/[id]/edit-resend/route.ts +3 -4
- package/src/app/api/chats/[id]/fork/route.ts +3 -5
- package/src/app/api/chats/[id]/restore/route.ts +6 -7
- package/src/app/api/chats/[id]/retry/route.ts +3 -4
- package/src/app/api/chats/[id]/route.ts +61 -62
- package/src/app/api/chats/route.ts +7 -1
- package/src/app/api/connectors/[id]/route.ts +7 -8
- package/src/app/api/connectors/route.ts +5 -4
- package/src/app/api/eval/run/route.ts +2 -1
- package/src/app/api/eval/suite/route.ts +2 -1
- package/src/app/api/external-agents/route.test.ts +1 -1
- package/src/app/api/external-agents/route.ts +2 -2
- package/src/app/api/files/serve/route.ts +1 -1
- package/src/app/api/gateways/[id]/route.ts +7 -5
- package/src/app/api/gateways/route.ts +1 -1
- package/src/app/api/knowledge/upload/route.ts +1 -1
- package/src/app/api/logs/route.ts +5 -7
- package/src/app/api/memory-images/[filename]/route.ts +2 -3
- package/src/app/api/openclaw/agent-files/route.ts +4 -3
- package/src/app/api/openclaw/approvals/route.ts +3 -4
- package/src/app/api/openclaw/config-sync/route.ts +3 -2
- package/src/app/api/openclaw/cron/route.ts +3 -2
- package/src/app/api/openclaw/dotenv-keys/route.ts +2 -1
- package/src/app/api/openclaw/exec-config/route.ts +3 -2
- package/src/app/api/openclaw/gateway/route.ts +5 -4
- package/src/app/api/openclaw/history/route.ts +3 -2
- package/src/app/api/openclaw/media/route.ts +2 -1
- package/src/app/api/openclaw/permissions/route.ts +3 -2
- package/src/app/api/openclaw/sandbox-env/route.ts +3 -2
- package/src/app/api/openclaw/skills/install/route.ts +2 -1
- package/src/app/api/openclaw/skills/remove/route.ts +2 -1
- package/src/app/api/openclaw/skills/route.ts +3 -2
- package/src/app/api/orchestrator/run/route.ts +5 -14
- package/src/app/api/perf/route.ts +43 -0
- package/src/app/api/plugins/dependencies/route.ts +2 -1
- package/src/app/api/plugins/install/route.ts +2 -1
- package/src/app/api/plugins/marketplace/route.ts +3 -2
- package/src/app/api/plugins/settings/route.ts +2 -1
- package/src/app/api/preview-server/route.ts +11 -10
- package/src/app/api/projects/[id]/route.ts +1 -1
- package/src/app/api/schedules/[id]/route.test.ts +128 -0
- package/src/app/api/schedules/[id]/route.ts +43 -43
- package/src/app/api/schedules/[id]/run/route.ts +11 -62
- package/src/app/api/schedules/route.ts +21 -87
- package/src/app/api/settings/route.ts +2 -0
- package/src/app/api/setup/doctor/route.ts +9 -8
- package/src/app/api/tasks/[id]/approve/route.ts +33 -30
- package/src/app/api/tasks/[id]/route.ts +12 -35
- package/src/app/api/tasks/import/github/route.ts +2 -1
- package/src/app/api/tasks/route.ts +79 -91
- package/src/app/api/wallets/[id]/approve/route.ts +2 -1
- package/src/app/api/wallets/[id]/route.ts +13 -19
- package/src/app/api/wallets/[id]/send/route.ts +2 -1
- package/src/app/api/wallets/route.ts +2 -1
- package/src/app/api/webhooks/[id]/route.ts +2 -1
- package/src/app/api/webhooks/route.test.ts +3 -1
- package/src/app/page.tsx +23 -331
- package/src/cli/index.js +19 -0
- package/src/cli/index.ts +38 -7
- package/src/cli/spec.js +9 -0
- package/src/components/activity/activity-feed.tsx +7 -4
- package/src/components/agents/agent-card.tsx +32 -6
- package/src/components/agents/agent-chat-list.tsx +55 -22
- package/src/components/agents/agent-files-editor.tsx +3 -2
- package/src/components/agents/agent-sheet.tsx +123 -22
- package/src/components/agents/inspector-panel.tsx +1 -1
- package/src/components/agents/openclaw-skills-panel.tsx +2 -1
- package/src/components/agents/trash-list.tsx +1 -1
- package/src/components/auth/access-key-gate.tsx +8 -2
- package/src/components/auth/setup-wizard.tsx +10 -9
- package/src/components/auth/user-picker.tsx +3 -2
- package/src/components/chat/chat-area.tsx +20 -1
- package/src/components/chat/chat-card.tsx +18 -3
- package/src/components/chat/chat-header.tsx +24 -4
- package/src/components/chat/chat-list.tsx +2 -11
- package/src/components/chat/heartbeat-history-panel.tsx +2 -1
- package/src/components/chat/message-bubble.tsx +45 -6
- package/src/components/chat/message-list.tsx +280 -145
- package/src/components/chat/streaming-bubble.tsx +217 -60
- package/src/components/chat/swarm-panel.test.ts +274 -0
- package/src/components/chat/swarm-panel.tsx +410 -0
- package/src/components/chat/swarm-status-card.tsx +346 -0
- package/src/components/chat/tool-call-bubble.tsx +48 -23
- package/src/components/chatrooms/chatroom-list.tsx +8 -5
- package/src/components/chatrooms/chatroom-message.tsx +10 -7
- package/src/components/chatrooms/chatroom-view.tsx +12 -9
- package/src/components/connectors/connector-health.tsx +6 -4
- package/src/components/connectors/connector-list.tsx +16 -11
- package/src/components/connectors/connector-sheet.tsx +12 -6
- package/src/components/home/home-view.tsx +38 -24
- package/src/components/input/chat-input.tsx +10 -1
- package/src/components/layout/app-layout.tsx +2 -38
- package/src/components/layout/sheet-layer.tsx +50 -0
- package/src/components/mcp-servers/mcp-server-list.tsx +37 -5
- package/src/components/mcp-servers/mcp-server-sheet.tsx +12 -2
- package/src/components/plugins/plugin-list.tsx +8 -4
- package/src/components/plugins/plugin-sheet.tsx +2 -1
- package/src/components/providers/provider-list.tsx +3 -2
- package/src/components/providers/provider-sheet.tsx +2 -1
- package/src/components/runs/run-list.tsx +11 -7
- package/src/components/schedules/schedule-card.tsx +5 -3
- package/src/components/shared/agent-switch-dialog.tsx +1 -1
- package/src/components/shared/attachment-chip.tsx +19 -3
- package/src/components/shared/notification-center.tsx +6 -3
- package/src/components/shared/settings/plugin-manager.tsx +3 -2
- package/src/components/shared/settings/section-embedding.tsx +2 -1
- package/src/components/shared/settings/section-orchestrator.tsx +2 -1
- package/src/components/shared/settings/section-user-preferences.tsx +107 -0
- package/src/components/shared/settings/settings-page.tsx +13 -9
- package/src/components/skills/clawhub-browser.tsx +15 -4
- package/src/components/skills/skill-list.tsx +15 -4
- package/src/components/tasks/approvals-panel.tsx +2 -1
- package/src/components/tasks/task-board.tsx +35 -37
- package/src/components/tasks/task-sheet.tsx +4 -3
- package/src/components/ui/full-screen-loader.tsx +164 -0
- package/src/components/wallets/wallet-approval-dialog.tsx +2 -1
- package/src/components/wallets/wallet-panel.tsx +6 -5
- package/src/components/wallets/wallet-section.tsx +3 -2
- package/src/components/webhooks/webhook-list.tsx +4 -5
- package/src/components/webhooks/webhook-sheet.tsx +6 -6
- package/src/hooks/use-app-bootstrap.ts +202 -0
- package/src/hooks/use-mounted-ref.ts +14 -0
- package/src/hooks/use-now.ts +31 -0
- package/src/hooks/use-openclaw-gateway.ts +2 -1
- package/src/instrumentation.ts +20 -8
- package/src/lib/agent-default-tools.test.ts +52 -0
- package/src/lib/agent-default-tools.ts +40 -0
- package/src/lib/api-client.test.ts +21 -0
- package/src/lib/api-client.ts +6 -11
- package/src/lib/canvas-content.test.ts +360 -0
- package/src/lib/chat-streaming-state.test.ts +49 -2
- package/src/lib/chat-streaming-state.ts +26 -10
- package/src/lib/fetch-timeout.test.ts +54 -0
- package/src/lib/fetch-timeout.ts +60 -3
- package/src/lib/live-tool-events.test.ts +77 -0
- package/src/lib/live-tool-events.ts +73 -0
- package/src/lib/local-observability.test.ts +2 -2
- package/src/lib/openclaw-endpoint.test.ts +1 -1
- package/src/lib/providers/anthropic.ts +12 -16
- package/src/lib/providers/index.ts +4 -2
- package/src/lib/providers/ollama.ts +9 -6
- package/src/lib/providers/openai.ts +11 -14
- package/src/lib/runtime-env.test.ts +8 -8
- package/src/lib/schedule-dedupe-advanced.test.ts +2 -2
- package/src/lib/schedule-dedupe.test.ts +1 -1
- package/src/lib/schedule-dedupe.ts +3 -2
- package/src/lib/server/agent-thread-session.test.ts +6 -6
- package/src/lib/server/agent-thread-session.ts +6 -9
- package/src/lib/server/alert-dispatch.ts +2 -1
- package/src/lib/server/api-routes.test.ts +6 -6
- package/src/lib/server/approval-connector-notify.test.ts +4 -4
- package/src/lib/server/approvals-auto-approve.test.ts +29 -29
- package/src/lib/server/approvals.test.ts +317 -0
- package/src/lib/server/approvals.ts +5 -4
- package/src/lib/server/autonomy-runtime.test.ts +11 -11
- package/src/lib/server/browser-state.ts +2 -2
- package/src/lib/server/capability-router.test.ts +1 -1
- package/src/lib/server/capability-router.ts +3 -2
- package/src/lib/server/chat-execution-advanced.test.ts +15 -2
- package/src/lib/server/chat-execution-connector-delivery.ts +67 -0
- package/src/lib/server/chat-execution-disabled.test.ts +3 -3
- package/src/lib/server/chat-execution-eval-history.test.ts +3 -3
- package/src/lib/server/chat-execution-heartbeat.test.ts +42 -1
- package/src/lib/server/chat-execution-session-sync.test.ts +119 -0
- package/src/lib/server/chat-execution-tool-events.ts +116 -0
- package/src/lib/server/chat-execution-utils.test.ts +479 -0
- package/src/lib/server/chat-execution-utils.ts +533 -0
- package/src/lib/server/chat-execution.ts +153 -748
- package/src/lib/server/chat-streaming-utils.ts +174 -0
- package/src/lib/server/chat-turn-tool-routing.ts +310 -0
- package/src/lib/server/chatroom-session-persistence.test.ts +2 -2
- package/src/lib/server/clawhub-client.ts +2 -1
- package/src/lib/server/collection-helpers.test.ts +92 -0
- package/src/lib/server/collection-helpers.ts +25 -3
- package/src/lib/server/connectors/access.ts +146 -0
- package/src/lib/server/connectors/bluebubbles.test.ts +1 -1
- package/src/lib/server/connectors/bluebubbles.ts +4 -4
- package/src/lib/server/connectors/commands.ts +367 -0
- package/src/lib/server/connectors/connector-routing.test.ts +4 -4
- package/src/lib/server/connectors/delivery.ts +142 -0
- package/src/lib/server/connectors/discord.ts +37 -40
- package/src/lib/server/connectors/email.ts +11 -10
- package/src/lib/server/connectors/googlechat.ts +4 -4
- package/src/lib/server/connectors/inbound-audio-transcription.ts +2 -1
- package/src/lib/server/connectors/ingress-delivery.ts +23 -0
- package/src/lib/server/connectors/manager-roundtrip.test.ts +300 -0
- package/src/lib/server/connectors/manager.test.ts +352 -77
- package/src/lib/server/connectors/manager.ts +134 -673
- package/src/lib/server/connectors/matrix.ts +4 -4
- package/src/lib/server/connectors/message-sentinel.ts +7 -0
- package/src/lib/server/connectors/openclaw.test.ts +1 -1
- package/src/lib/server/connectors/openclaw.ts +8 -10
- package/src/lib/server/connectors/outbox.test.ts +192 -0
- package/src/lib/server/connectors/outbox.ts +369 -0
- package/src/lib/server/connectors/pairing.test.ts +18 -1
- package/src/lib/server/connectors/pairing.ts +49 -4
- package/src/lib/server/connectors/policy.ts +9 -3
- package/src/lib/server/connectors/reconnect-state.ts +71 -0
- package/src/lib/server/connectors/response-media.ts +256 -0
- package/src/lib/server/connectors/runtime-state.ts +67 -0
- package/src/lib/server/connectors/session.test.ts +357 -0
- package/src/lib/server/connectors/session.ts +422 -0
- package/src/lib/server/connectors/signal.ts +7 -7
- package/src/lib/server/connectors/slack.ts +43 -43
- package/src/lib/server/connectors/teams.ts +4 -4
- package/src/lib/server/connectors/telegram.ts +37 -43
- package/src/lib/server/connectors/types.ts +31 -1
- package/src/lib/server/connectors/whatsapp.test.ts +108 -0
- package/src/lib/server/connectors/whatsapp.ts +106 -34
- package/src/lib/server/context-manager.test.ts +409 -0
- package/src/lib/server/cost.test.ts +1 -1
- package/src/lib/server/daemon-policy.ts +78 -0
- package/src/lib/server/daemon-state-connectors.test.ts +167 -0
- package/src/lib/server/daemon-state.test.ts +283 -55
- package/src/lib/server/daemon-state.ts +106 -109
- package/src/lib/server/data-dir.test.ts +5 -5
- package/src/lib/server/data-dir.ts +4 -0
- package/src/lib/server/delegation-jobs-advanced.test.ts +1 -1
- package/src/lib/server/delegation-jobs.test.ts +87 -0
- package/src/lib/server/delegation-jobs.ts +42 -48
- package/src/lib/server/devserver-launch.ts +1 -1
- package/src/lib/server/document-utils.ts +7 -9
- package/src/lib/server/elevenlabs.ts +2 -1
- package/src/lib/server/embeddings.test.ts +105 -0
- package/src/lib/server/ethereum.ts +3 -2
- package/src/lib/server/eval/agent-regression.ts +3 -2
- package/src/lib/server/eval/runner.ts +2 -1
- package/src/lib/server/eval/scorer.ts +2 -1
- package/src/lib/server/evm-swap.ts +2 -1
- package/src/lib/server/gateway/protocol.test.ts +1 -1
- package/src/lib/server/guardian.ts +2 -1
- package/src/lib/server/heartbeat-blocked-suppression.test.ts +151 -0
- package/src/lib/server/heartbeat-service-timer.test.ts +6 -6
- package/src/lib/server/heartbeat-service.test.ts +406 -0
- package/src/lib/server/heartbeat-service.ts +54 -7
- package/src/lib/server/heartbeat-wake.test.ts +19 -0
- package/src/lib/server/heartbeat-wake.ts +17 -16
- package/src/lib/server/integrity-monitor.test.ts +149 -0
- package/src/lib/server/json-utils.ts +22 -0
- package/src/lib/server/knowledge-db.test.ts +13 -13
- package/src/lib/server/link-understanding.ts +2 -1
- package/src/lib/server/llm-response-cache.test.ts +1 -1
- package/src/lib/server/main-agent-loop-advanced.test.ts +65 -3
- package/src/lib/server/main-agent-loop.test.ts +6 -6
- package/src/lib/server/main-agent-loop.ts +21 -7
- package/src/lib/server/mcp-client.test.ts +1 -1
- package/src/lib/server/mcp-conformance.test.ts +1 -1
- package/src/lib/server/mcp-conformance.ts +3 -2
- package/src/lib/server/memory-consolidation.ts +2 -1
- package/src/lib/server/memory-db.test.ts +485 -0
- package/src/lib/server/memory-db.ts +39 -26
- package/src/lib/server/memory-graph.test.ts +2 -2
- package/src/lib/server/memory-policy.test.ts +7 -7
- package/src/lib/server/memory-retrieval.test.ts +1 -1
- package/src/lib/server/openclaw-config-sync.ts +2 -1
- package/src/lib/server/openclaw-deploy.test.ts +1 -1
- package/src/lib/server/openclaw-deploy.ts +8 -12
- package/src/lib/server/openclaw-exec-config.ts +2 -1
- package/src/lib/server/openclaw-gateway.ts +6 -7
- package/src/lib/server/openclaw-skills-normalize.ts +2 -1
- package/src/lib/server/openclaw-sync.ts +7 -5
- package/src/lib/server/orchestrator-lg-structure.test.ts +17 -0
- package/src/lib/server/orchestrator-lg.ts +199 -327
- package/src/lib/server/path-utils.ts +31 -0
- package/src/lib/server/perf.ts +161 -0
- package/src/lib/server/plugins-approval-guidance.ts +115 -0
- package/src/lib/server/plugins.test.ts +1 -1
- package/src/lib/server/plugins.ts +22 -132
- package/src/lib/server/process-manager.ts +5 -8
- package/src/lib/server/provider-health.test.ts +137 -0
- package/src/lib/server/provider-health.ts +3 -3
- package/src/lib/server/provider-model-discovery.ts +3 -12
- package/src/lib/server/queue-followups.test.ts +9 -9
- package/src/lib/server/queue-reconcile.test.ts +2 -2
- package/src/lib/server/queue-recovery.test.ts +269 -0
- package/src/lib/server/queue.test.ts +570 -0
- package/src/lib/server/queue.ts +62 -455
- package/src/lib/server/resolve-image.ts +30 -0
- package/src/lib/server/runtime-settings.test.ts +4 -4
- package/src/lib/server/runtime-storage-write-paths.test.ts +60 -0
- package/src/lib/server/schedule-normalization.test.ts +279 -0
- package/src/lib/server/schedule-service.ts +263 -0
- package/src/lib/server/scheduler.ts +17 -74
- package/src/lib/server/session-mailbox.test.ts +191 -0
- package/src/lib/server/session-run-manager.test.ts +640 -0
- package/src/lib/server/session-run-manager.ts +59 -15
- package/src/lib/server/session-tools/autonomy-tools.test.ts +20 -20
- package/src/lib/server/session-tools/calendar.ts +2 -1
- package/src/lib/server/session-tools/canvas.ts +2 -1
- package/src/lib/server/session-tools/chatroom.ts +2 -1
- package/src/lib/server/session-tools/connector.ts +26 -28
- package/src/lib/server/session-tools/context-mgmt.ts +3 -2
- package/src/lib/server/session-tools/crawl.ts +4 -3
- package/src/lib/server/session-tools/crud.ts +105 -324
- package/src/lib/server/session-tools/delegate-fallback.test.ts +9 -9
- package/src/lib/server/session-tools/delegate.ts +6 -8
- package/src/lib/server/session-tools/discovery-approvals.test.ts +15 -15
- package/src/lib/server/session-tools/discovery.ts +4 -3
- package/src/lib/server/session-tools/document.ts +2 -1
- package/src/lib/server/session-tools/email.ts +2 -1
- package/src/lib/server/session-tools/extract.ts +2 -1
- package/src/lib/server/session-tools/file.ts +4 -3
- package/src/lib/server/session-tools/http.ts +2 -1
- package/src/lib/server/session-tools/human-loop.ts +2 -1
- package/src/lib/server/session-tools/image-gen.ts +4 -3
- package/src/lib/server/session-tools/index.ts +26 -30
- package/src/lib/server/session-tools/mailbox.ts +2 -1
- package/src/lib/server/session-tools/manage-connectors.test.ts +4 -4
- package/src/lib/server/session-tools/manage-schedules.test.ts +12 -12
- package/src/lib/server/session-tools/manage-tasks-advanced.test.ts +5 -5
- package/src/lib/server/session-tools/manage-tasks.test.ts +2 -2
- package/src/lib/server/session-tools/monitor.ts +2 -1
- package/src/lib/server/session-tools/platform.ts +2 -1
- package/src/lib/server/session-tools/plugin-creator.ts +2 -1
- package/src/lib/server/session-tools/replicate.ts +3 -2
- package/src/lib/server/session-tools/session-tools-wiring.test.ts +6 -6
- package/src/lib/server/session-tools/shell.ts +4 -9
- package/src/lib/server/session-tools/subagent.ts +322 -170
- package/src/lib/server/session-tools/table.ts +6 -5
- package/src/lib/server/session-tools/wallet-tool.test.ts +3 -3
- package/src/lib/server/session-tools/wallet.ts +7 -6
- package/src/lib/server/session-tools/web-browser-config.test.ts +1 -0
- package/src/lib/server/session-tools/web-utils.ts +317 -0
- package/src/lib/server/session-tools/web.ts +62 -328
- package/src/lib/server/skill-prompt-budget.test.ts +1 -1
- package/src/lib/server/skills-normalize.ts +2 -1
- package/src/lib/server/storage-item-access.test.ts +302 -0
- package/src/lib/server/storage.ts +366 -314
- package/src/lib/server/stream-agent-chat.test.ts +82 -3
- package/src/lib/server/stream-agent-chat.ts +146 -510
- package/src/lib/server/stream-continuation.ts +412 -0
- package/src/lib/server/subagent-lineage.test.ts +647 -0
- package/src/lib/server/subagent-lineage.ts +435 -0
- package/src/lib/server/subagent-runtime.test.ts +484 -0
- package/src/lib/server/subagent-runtime.ts +419 -0
- package/src/lib/server/subagent-swarm.test.ts +391 -0
- package/src/lib/server/subagent-swarm.ts +564 -0
- package/src/lib/server/system-events.ts +3 -3
- package/src/lib/server/task-followups.test.ts +491 -0
- package/src/lib/server/task-followups.ts +391 -0
- package/src/lib/server/task-lifecycle.test.ts +205 -0
- package/src/lib/server/task-lifecycle.ts +200 -0
- package/src/lib/server/task-quality-gate.test.ts +1 -1
- package/src/lib/server/task-resume.ts +208 -0
- package/src/lib/server/task-service.test.ts +108 -0
- package/src/lib/server/task-service.ts +264 -0
- package/src/lib/server/task-validation.test.ts +1 -1
- package/src/lib/server/test-utils/run-with-temp-data-dir.ts +42 -0
- package/src/lib/server/tool-capability-policy.test.ts +2 -2
- package/src/lib/server/tool-capability-policy.ts +3 -2
- package/src/lib/server/tool-planning.ts +2 -1
- package/src/lib/server/tool-retry.ts +2 -3
- package/src/lib/server/wake-dispatcher.test.ts +303 -0
- package/src/lib/server/wake-dispatcher.ts +318 -0
- package/src/lib/server/wake-mode.test.ts +161 -0
- package/src/lib/server/wake-mode.ts +174 -0
- package/src/lib/server/wallet-service.ts +8 -9
- package/src/lib/server/watch-jobs.ts +2 -1
- package/src/lib/server/workspace-context.ts +2 -2
- package/src/lib/shared-utils.test.ts +142 -0
- package/src/lib/shared-utils.ts +62 -0
- package/src/lib/tool-event-summary.ts +2 -1
- package/src/lib/view-routes.test.ts +100 -0
- package/src/lib/wallet.test.ts +322 -6
- package/src/proxy.test.ts +4 -4
- package/src/proxy.ts +2 -3
- package/src/stores/set-if-changed.ts +40 -0
- package/src/stores/slices/agent-slice.ts +111 -0
- package/src/stores/slices/auth-slice.ts +25 -0
- package/src/stores/slices/data-slice.ts +301 -0
- package/src/stores/slices/index.ts +7 -0
- package/src/stores/slices/session-slice.ts +112 -0
- package/src/stores/slices/task-slice.ts +63 -0
- package/src/stores/slices/ui-slice.ts +192 -0
- package/src/stores/use-app-store.ts +17 -822
- package/src/stores/use-approval-store.ts +2 -1
- package/src/stores/use-chat-store.ts +8 -1
- package/src/types/index.ts +10 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import os from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { after, before, describe, it } from 'node:test'
|
|
6
|
+
import type { Agent, Connector, Session } from '@/types'
|
|
7
|
+
|
|
8
|
+
const originalEnv = {
|
|
9
|
+
DATA_DIR: process.env.DATA_DIR,
|
|
10
|
+
WORKSPACE_DIR: process.env.WORKSPACE_DIR,
|
|
11
|
+
SWARMCLAW_BUILD_MODE: process.env.SWARMCLAW_BUILD_MODE,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let tempDir = ''
|
|
15
|
+
let mod: typeof import('./session')
|
|
16
|
+
let storage: typeof import('../storage')
|
|
17
|
+
|
|
18
|
+
before(async () => {
|
|
19
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'swarmclaw-connector-session-'))
|
|
20
|
+
process.env.DATA_DIR = path.join(tempDir, 'data')
|
|
21
|
+
process.env.WORKSPACE_DIR = path.join(tempDir, 'workspace')
|
|
22
|
+
process.env.SWARMCLAW_BUILD_MODE = '1'
|
|
23
|
+
storage = await import('../storage')
|
|
24
|
+
mod = await import('./session')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
after(() => {
|
|
28
|
+
if (originalEnv.DATA_DIR === undefined) delete process.env.DATA_DIR
|
|
29
|
+
else process.env.DATA_DIR = originalEnv.DATA_DIR
|
|
30
|
+
if (originalEnv.WORKSPACE_DIR === undefined) delete process.env.WORKSPACE_DIR
|
|
31
|
+
else process.env.WORKSPACE_DIR = originalEnv.WORKSPACE_DIR
|
|
32
|
+
if (originalEnv.SWARMCLAW_BUILD_MODE === undefined) delete process.env.SWARMCLAW_BUILD_MODE
|
|
33
|
+
else process.env.SWARMCLAW_BUILD_MODE = originalEnv.SWARMCLAW_BUILD_MODE
|
|
34
|
+
fs.rmSync(tempDir, { recursive: true, force: true })
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('connectors/session', () => {
|
|
38
|
+
// ---- modelHistoryTail ----
|
|
39
|
+
|
|
40
|
+
describe('modelHistoryTail', () => {
|
|
41
|
+
it('returns last N messages', () => {
|
|
42
|
+
const messages = Array.from({ length: 30 }, (_, i) => ({
|
|
43
|
+
role: 'user' as const,
|
|
44
|
+
text: `msg-${i}`,
|
|
45
|
+
time: i,
|
|
46
|
+
}))
|
|
47
|
+
const tail = mod.modelHistoryTail(messages, 5)
|
|
48
|
+
assert.equal(tail.length, 5)
|
|
49
|
+
assert.equal(tail[0].text, 'msg-25')
|
|
50
|
+
assert.equal(tail[4].text, 'msg-29')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('filters out historyExcluded messages', () => {
|
|
54
|
+
const messages = [
|
|
55
|
+
{ role: 'user' as const, text: 'a', time: 1 },
|
|
56
|
+
{ role: 'assistant' as const, text: 'b', time: 2, historyExcluded: true },
|
|
57
|
+
{ role: 'user' as const, text: 'c', time: 3 },
|
|
58
|
+
]
|
|
59
|
+
const tail = mod.modelHistoryTail(messages, 20)
|
|
60
|
+
assert.equal(tail.length, 2)
|
|
61
|
+
assert.equal(tail[0].text, 'a')
|
|
62
|
+
assert.equal(tail[1].text, 'c')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('returns empty array for null/undefined input', () => {
|
|
66
|
+
assert.deepEqual(mod.modelHistoryTail(null), [])
|
|
67
|
+
assert.deepEqual(mod.modelHistoryTail(undefined), [])
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('defaults to 20 message limit', () => {
|
|
71
|
+
const messages = Array.from({ length: 40 }, (_, i) => ({
|
|
72
|
+
role: 'user' as const,
|
|
73
|
+
text: `m-${i}`,
|
|
74
|
+
time: i,
|
|
75
|
+
}))
|
|
76
|
+
const tail = mod.modelHistoryTail(messages)
|
|
77
|
+
assert.equal(tail.length, 20)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
// ---- applyConnectorRuntimeDefaults ----
|
|
82
|
+
|
|
83
|
+
describe('applyConnectorRuntimeDefaults', () => {
|
|
84
|
+
it('overwrites session provider/model/endpoint/thinkingLevel', () => {
|
|
85
|
+
const session = {
|
|
86
|
+
id: 'sess-1',
|
|
87
|
+
name: 'test',
|
|
88
|
+
provider: 'ollama' as const,
|
|
89
|
+
model: 'old-model',
|
|
90
|
+
apiEndpoint: 'http://old',
|
|
91
|
+
connectorThinkLevel: null as string | null,
|
|
92
|
+
messages: [],
|
|
93
|
+
createdAt: Date.now(),
|
|
94
|
+
} as unknown as Session
|
|
95
|
+
|
|
96
|
+
mod.applyConnectorRuntimeDefaults(session, {
|
|
97
|
+
provider: 'anthropic',
|
|
98
|
+
model: 'claude-3',
|
|
99
|
+
apiEndpoint: 'https://api.anthropic.com',
|
|
100
|
+
thinkingLevel: 'high',
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
assert.equal(session.provider, 'anthropic')
|
|
104
|
+
assert.equal(session.model, 'claude-3')
|
|
105
|
+
assert.equal(session.apiEndpoint, 'https://api.anthropic.com')
|
|
106
|
+
assert.equal(session.connectorThinkLevel, 'high')
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// ---- findDirectSessionForInbound ----
|
|
111
|
+
|
|
112
|
+
describe('findDirectSessionForInbound', () => {
|
|
113
|
+
it('returns null for chatroom connectors', () => {
|
|
114
|
+
const connector = {
|
|
115
|
+
id: 'conn-1',
|
|
116
|
+
name: 'Test',
|
|
117
|
+
platform: 'discord' as const,
|
|
118
|
+
agentId: 'agent-1',
|
|
119
|
+
chatroomId: 'room-1',
|
|
120
|
+
config: {},
|
|
121
|
+
enabled: true,
|
|
122
|
+
createdAt: Date.now(),
|
|
123
|
+
updatedAt: Date.now(),
|
|
124
|
+
} as unknown as Connector
|
|
125
|
+
const msg = {
|
|
126
|
+
platform: 'discord',
|
|
127
|
+
channelId: 'ch-1',
|
|
128
|
+
senderId: 'user-1',
|
|
129
|
+
senderName: 'User',
|
|
130
|
+
text: 'hello',
|
|
131
|
+
}
|
|
132
|
+
const result = mod.findDirectSessionForInbound(connector, msg)
|
|
133
|
+
assert.equal(result, null)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('returns null when no matching sessions exist', () => {
|
|
137
|
+
const connector = {
|
|
138
|
+
id: 'conn-1',
|
|
139
|
+
name: 'Test',
|
|
140
|
+
platform: 'discord' as const,
|
|
141
|
+
agentId: 'agent-1',
|
|
142
|
+
config: {},
|
|
143
|
+
enabled: true,
|
|
144
|
+
createdAt: Date.now(),
|
|
145
|
+
updatedAt: Date.now(),
|
|
146
|
+
} as unknown as Connector
|
|
147
|
+
const msg = {
|
|
148
|
+
platform: 'discord',
|
|
149
|
+
channelId: 'ch-no-match',
|
|
150
|
+
senderId: 'user-no-match',
|
|
151
|
+
senderName: 'Ghost',
|
|
152
|
+
text: 'hello',
|
|
153
|
+
}
|
|
154
|
+
const result = mod.findDirectSessionForInbound(connector, msg)
|
|
155
|
+
assert.equal(result, null)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('finds session created by resolveDirectSession', () => {
|
|
159
|
+
// Use resolveDirectSession to create a session, then findDirectSessionForInbound should find it
|
|
160
|
+
const connector = {
|
|
161
|
+
id: 'conn-findable',
|
|
162
|
+
name: 'Findable',
|
|
163
|
+
platform: 'discord' as const,
|
|
164
|
+
agentId: 'agent-findable',
|
|
165
|
+
config: {},
|
|
166
|
+
enabled: true,
|
|
167
|
+
createdAt: Date.now(),
|
|
168
|
+
updatedAt: Date.now(),
|
|
169
|
+
} as unknown as Connector
|
|
170
|
+
const msg = {
|
|
171
|
+
platform: 'discord',
|
|
172
|
+
channelId: 'ch-findable',
|
|
173
|
+
senderId: 'sender-findable',
|
|
174
|
+
senderName: 'Finder',
|
|
175
|
+
text: 'hello',
|
|
176
|
+
}
|
|
177
|
+
const agent = {
|
|
178
|
+
id: 'agent-findable',
|
|
179
|
+
name: 'Findable Agent',
|
|
180
|
+
provider: 'anthropic' as const,
|
|
181
|
+
model: 'claude-3',
|
|
182
|
+
plugins: [],
|
|
183
|
+
systemPrompt: '',
|
|
184
|
+
createdAt: Date.now(),
|
|
185
|
+
} as unknown as Agent
|
|
186
|
+
|
|
187
|
+
storage.upsertStoredItem('agents', 'agent-findable', agent)
|
|
188
|
+
const created = mod.resolveDirectSession({ connector, msg, agent })
|
|
189
|
+
assert.equal(created.wasCreated, true)
|
|
190
|
+
|
|
191
|
+
// Now findDirectSessionForInbound should locate it
|
|
192
|
+
const found = mod.findDirectSessionForInbound(connector, msg)
|
|
193
|
+
assert.ok(found)
|
|
194
|
+
assert.equal(found!.id, created.session.id)
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
// ---- updateSessionConnectorContext ----
|
|
199
|
+
|
|
200
|
+
describe('updateSessionConnectorContext', () => {
|
|
201
|
+
it('populates connector context fields from message', () => {
|
|
202
|
+
const session = {
|
|
203
|
+
id: 'sess-ctx',
|
|
204
|
+
name: 'test',
|
|
205
|
+
provider: 'anthropic' as const,
|
|
206
|
+
model: 'test',
|
|
207
|
+
messages: [],
|
|
208
|
+
createdAt: Date.now(),
|
|
209
|
+
connectorContext: {},
|
|
210
|
+
} as unknown as Session
|
|
211
|
+
const connector = {
|
|
212
|
+
id: 'conn-ctx',
|
|
213
|
+
name: 'CTX',
|
|
214
|
+
platform: 'telegram' as const,
|
|
215
|
+
agentId: 'agent-ctx',
|
|
216
|
+
config: {},
|
|
217
|
+
enabled: true,
|
|
218
|
+
createdAt: Date.now(),
|
|
219
|
+
updatedAt: Date.now(),
|
|
220
|
+
} as unknown as Connector
|
|
221
|
+
const msg = {
|
|
222
|
+
platform: 'telegram',
|
|
223
|
+
channelId: 'tg-ch-1',
|
|
224
|
+
senderId: 'tg-user-1',
|
|
225
|
+
senderName: 'TG User',
|
|
226
|
+
text: 'hi',
|
|
227
|
+
isGroup: true,
|
|
228
|
+
threadId: 'thread-42',
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
mod.updateSessionConnectorContext(session, connector, msg, 'connector:telegram:agent-ctx:tg-ch-1')
|
|
232
|
+
|
|
233
|
+
assert.equal(session.connectorContext?.connectorId, 'conn-ctx')
|
|
234
|
+
assert.equal(session.connectorContext?.platform, 'telegram')
|
|
235
|
+
assert.equal(session.connectorContext?.channelId, 'tg-ch-1')
|
|
236
|
+
assert.equal(session.connectorContext?.senderId, 'tg-user-1')
|
|
237
|
+
assert.equal(session.connectorContext?.senderName, 'TG User')
|
|
238
|
+
assert.equal(session.connectorContext?.isGroup, true)
|
|
239
|
+
assert.equal(session.connectorContext?.threadId, 'thread-42')
|
|
240
|
+
assert.ok(typeof session.connectorContext?.lastInboundAt === 'number')
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
// ---- resolveDirectSession ----
|
|
245
|
+
|
|
246
|
+
describe('resolveDirectSession', () => {
|
|
247
|
+
it('creates a new session for unknown connector/channel', () => {
|
|
248
|
+
// Ensure agent exists in storage
|
|
249
|
+
storage.upsertStoredItem('agents', 'agent-new', {
|
|
250
|
+
id: 'agent-new',
|
|
251
|
+
name: 'New Agent',
|
|
252
|
+
provider: 'anthropic',
|
|
253
|
+
model: 'claude-3',
|
|
254
|
+
plugins: ['web'],
|
|
255
|
+
systemPrompt: 'You are helpful.',
|
|
256
|
+
createdAt: Date.now(),
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
const connector = {
|
|
260
|
+
id: 'conn-new',
|
|
261
|
+
name: 'New Conn',
|
|
262
|
+
platform: 'slack' as const,
|
|
263
|
+
agentId: 'agent-new',
|
|
264
|
+
config: {},
|
|
265
|
+
enabled: true,
|
|
266
|
+
createdAt: Date.now(),
|
|
267
|
+
updatedAt: Date.now(),
|
|
268
|
+
} as unknown as Connector
|
|
269
|
+
const msg = {
|
|
270
|
+
platform: 'slack',
|
|
271
|
+
channelId: 'slack-ch-unique',
|
|
272
|
+
senderId: 'slack-user-1',
|
|
273
|
+
senderName: 'Slack User',
|
|
274
|
+
text: 'first message',
|
|
275
|
+
}
|
|
276
|
+
const agent = {
|
|
277
|
+
id: 'agent-new',
|
|
278
|
+
name: 'New Agent',
|
|
279
|
+
provider: 'anthropic' as const,
|
|
280
|
+
model: 'claude-3',
|
|
281
|
+
plugins: ['web'],
|
|
282
|
+
systemPrompt: 'You are helpful.',
|
|
283
|
+
createdAt: Date.now(),
|
|
284
|
+
} as unknown as Agent
|
|
285
|
+
|
|
286
|
+
const result = mod.resolveDirectSession({ connector, msg, agent })
|
|
287
|
+
|
|
288
|
+
assert.equal(result.wasCreated, true)
|
|
289
|
+
assert.ok(result.session.id)
|
|
290
|
+
assert.equal(result.session.agentId, 'agent-new')
|
|
291
|
+
assert.equal(result.session.provider, 'anthropic')
|
|
292
|
+
assert.equal(result.session.model, 'claude-3')
|
|
293
|
+
assert.ok(result.sessionKey.includes('connector:'))
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
it('reuses existing session for same connector/channel/agent', () => {
|
|
297
|
+
const connector = {
|
|
298
|
+
id: 'conn-reuse',
|
|
299
|
+
name: 'Reuse Conn',
|
|
300
|
+
platform: 'discord' as const,
|
|
301
|
+
agentId: 'agent-reuse',
|
|
302
|
+
config: {},
|
|
303
|
+
enabled: true,
|
|
304
|
+
createdAt: Date.now(),
|
|
305
|
+
updatedAt: Date.now(),
|
|
306
|
+
} as unknown as Connector
|
|
307
|
+
const msg = {
|
|
308
|
+
platform: 'discord',
|
|
309
|
+
channelId: 'disc-ch-reuse',
|
|
310
|
+
senderId: 'disc-user-1',
|
|
311
|
+
senderName: 'Discord User',
|
|
312
|
+
text: 'first',
|
|
313
|
+
}
|
|
314
|
+
const agent = {
|
|
315
|
+
id: 'agent-reuse',
|
|
316
|
+
name: 'Reuse Agent',
|
|
317
|
+
provider: 'anthropic' as const,
|
|
318
|
+
model: 'claude-3',
|
|
319
|
+
plugins: [],
|
|
320
|
+
systemPrompt: '',
|
|
321
|
+
createdAt: Date.now(),
|
|
322
|
+
} as unknown as Agent
|
|
323
|
+
|
|
324
|
+
storage.upsertStoredItem('agents', 'agent-reuse', agent)
|
|
325
|
+
|
|
326
|
+
const first = mod.resolveDirectSession({ connector, msg, agent })
|
|
327
|
+
assert.equal(first.wasCreated, true)
|
|
328
|
+
|
|
329
|
+
const second = mod.resolveDirectSession({ connector, msg, agent })
|
|
330
|
+
assert.equal(second.wasCreated, false)
|
|
331
|
+
assert.equal(second.session.id, first.session.id)
|
|
332
|
+
})
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
// ---- persistSessionRecord ----
|
|
336
|
+
|
|
337
|
+
describe('persistSessionRecord', () => {
|
|
338
|
+
it('sets updatedAt and persists to storage', () => {
|
|
339
|
+
const session = {
|
|
340
|
+
id: 'sess-persist',
|
|
341
|
+
name: 'persist-test',
|
|
342
|
+
provider: 'anthropic' as const,
|
|
343
|
+
model: 'test',
|
|
344
|
+
messages: [],
|
|
345
|
+
createdAt: Date.now(),
|
|
346
|
+
updatedAt: 0,
|
|
347
|
+
} as unknown as Session
|
|
348
|
+
|
|
349
|
+
mod.persistSessionRecord(session)
|
|
350
|
+
|
|
351
|
+
assert.ok(session.updatedAt > 0)
|
|
352
|
+
const loaded = storage.loadStoredItem('sessions', 'sess-persist') as Record<string, unknown>
|
|
353
|
+
assert.ok(loaded)
|
|
354
|
+
assert.equal(loaded.name, 'persist-test')
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
})
|