@swarmclawai/swarmclaw 0.7.8 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -15
- package/next.config.ts +13 -2
- package/package.json +4 -2
- package/src/app/api/agents/[id]/thread/route.ts +9 -0
- package/src/app/api/agents/route.ts +4 -0
- package/src/app/api/agents/thread-route.test.ts +133 -0
- package/src/app/api/approvals/route.test.ts +148 -0
- package/src/app/api/canvas/[sessionId]/route.ts +3 -1
- package/src/app/api/chatrooms/[id]/chat/route.ts +4 -2
- package/src/app/api/chats/[id]/devserver/route.ts +48 -7
- package/src/app/api/chats/[id]/messages/route.ts +42 -18
- package/src/app/api/chats/[id]/route.ts +1 -1
- package/src/app/api/chats/[id]/stop/route.ts +5 -4
- package/src/app/api/chats/route.ts +22 -2
- package/src/app/api/clawhub/install/route.ts +28 -8
- package/src/app/api/connectors/[id]/route.ts +26 -1
- package/src/app/api/external-agents/route.test.ts +165 -0
- package/src/app/api/gateways/[id]/health/route.ts +27 -12
- package/src/app/api/gateways/[id]/route.ts +2 -0
- package/src/app/api/gateways/health-route.test.ts +135 -0
- package/src/app/api/gateways/route.ts +2 -0
- package/src/app/api/mcp-servers/route.test.ts +130 -0
- package/src/app/api/openclaw/deploy/route.ts +38 -5
- package/src/app/api/plugins/install/route.ts +46 -6
- package/src/app/api/plugins/marketplace/route.ts +48 -15
- package/src/app/api/preview-server/route.ts +26 -11
- package/src/app/api/schedules/[id]/run/route.ts +4 -0
- package/src/app/api/schedules/route.test.ts +86 -0
- package/src/app/api/schedules/route.ts +6 -1
- package/src/app/api/setup/check-provider/route.test.ts +19 -0
- package/src/app/api/setup/check-provider/route.ts +40 -10
- package/src/app/api/skills/[id]/route.ts +12 -0
- package/src/app/api/skills/import/route.ts +14 -12
- package/src/app/api/skills/route.ts +13 -1
- package/src/app/api/tasks/[id]/route.ts +10 -1
- package/src/app/api/tasks/import/github/route.test.ts +65 -0
- package/src/app/api/tasks/import/github/route.ts +337 -0
- package/src/app/api/wallets/[id]/approve/route.ts +17 -3
- package/src/app/api/wallets/[id]/route.ts +79 -33
- package/src/app/api/wallets/[id]/send/route.ts +19 -33
- package/src/app/api/wallets/route.ts +78 -61
- package/src/app/api/webhooks/[id]/route.ts +33 -6
- package/src/app/api/webhooks/route.test.ts +272 -0
- package/src/cli/index.js +1 -0
- package/src/cli/spec.js +1 -0
- package/src/components/agents/agent-card.tsx +9 -2
- package/src/components/agents/agent-chat-list.tsx +18 -2
- package/src/components/agents/agent-list.tsx +1 -0
- package/src/components/agents/agent-sheet.tsx +73 -24
- package/src/components/agents/inspector-panel.tsx +41 -0
- package/src/components/canvas/canvas-panel.tsx +236 -65
- package/src/components/chat/chat-card.tsx +36 -13
- package/src/components/chat/chat-header.tsx +44 -16
- package/src/components/chat/chat-list.tsx +28 -4
- package/src/components/chat/checkpoint-timeline.tsx +50 -34
- package/src/components/chat/message-bubble.tsx +208 -145
- package/src/components/chat/message-list.tsx +48 -19
- package/src/components/chatrooms/chatroom-message.tsx +2 -2
- package/src/components/chatrooms/chatroom-sheet.tsx +16 -2
- package/src/components/connectors/connector-health.tsx +1 -1
- package/src/components/connectors/connector-list.tsx +7 -2
- package/src/components/connectors/connector-sheet.tsx +337 -148
- package/src/components/gateways/gateway-sheet.tsx +2 -2
- package/src/components/mcp-servers/mcp-server-list.tsx +26 -5
- package/src/components/mcp-servers/mcp-server-sheet.tsx +19 -2
- package/src/components/openclaw/openclaw-deploy-panel.tsx +269 -21
- package/src/components/plugins/plugin-list.tsx +45 -9
- package/src/components/plugins/plugin-sheet.tsx +55 -7
- package/src/components/providers/provider-list.tsx +2 -1
- package/src/components/providers/provider-sheet.tsx +21 -2
- package/src/components/schedules/schedule-card.tsx +25 -1
- package/src/components/schedules/schedule-sheet.tsx +44 -2
- package/src/components/secrets/secret-sheet.tsx +21 -2
- package/src/components/shared/agent-switch-dialog.tsx +12 -1
- package/src/components/shared/bottom-sheet.tsx +13 -3
- package/src/components/shared/command-palette.tsx +8 -1
- package/src/components/shared/confirm-dialog.tsx +19 -4
- package/src/components/shared/connector-platform-icon.test.ts +28 -0
- package/src/components/shared/connector-platform-icon.tsx +39 -6
- package/src/components/shared/settings/plugin-manager.tsx +29 -6
- package/src/components/shared/settings/section-capability-policy.tsx +7 -3
- package/src/components/skills/skill-list.tsx +25 -0
- package/src/components/skills/skill-sheet.tsx +84 -12
- package/src/components/tasks/approvals-panel.tsx +191 -95
- package/src/components/tasks/task-board.tsx +273 -2
- package/src/components/tasks/task-card.tsx +38 -9
- package/src/components/ui/dialog.tsx +2 -2
- package/src/components/wallets/wallet-approval-dialog.tsx +4 -2
- package/src/components/wallets/wallet-panel.tsx +435 -90
- package/src/components/wallets/wallet-section.tsx +198 -48
- package/src/components/webhooks/webhook-sheet.tsx +22 -2
- package/src/lib/approval-display.ts +20 -0
- package/src/lib/canvas-content.ts +198 -0
- package/src/lib/chat-artifact-summary.ts +165 -0
- package/src/lib/chat-display.test.ts +91 -0
- package/src/lib/chat-display.ts +58 -0
- package/src/lib/chat-streaming-state.test.ts +47 -1
- package/src/lib/chat-streaming-state.ts +42 -0
- package/src/lib/ollama-model.ts +10 -0
- package/src/lib/openclaw-endpoint.test.ts +8 -0
- package/src/lib/openclaw-endpoint.ts +6 -1
- package/src/lib/plugin-install-cors.ts +46 -0
- package/src/lib/plugin-sources.test.ts +43 -0
- package/src/lib/plugin-sources.ts +77 -0
- package/src/lib/providers/ollama.ts +16 -6
- package/src/lib/providers/openclaw.test.ts +54 -0
- package/src/lib/providers/openclaw.ts +127 -11
- package/src/lib/schedule-dedupe-advanced.test.ts +1335 -0
- package/src/lib/schedule-dedupe.test.ts +66 -1
- package/src/lib/schedule-dedupe.ts +169 -12
- package/src/lib/schedule-origin.test.ts +20 -0
- package/src/lib/schedule-origin.ts +15 -0
- package/src/lib/server/__fixtures__/fake-mcp-stdio-server.mjs +27 -0
- package/src/lib/server/agent-availability.ts +16 -0
- package/src/lib/server/agent-runtime-config.ts +12 -4
- package/src/lib/server/agent-thread-session.test.ts +51 -0
- package/src/lib/server/agent-thread-session.ts +7 -0
- package/src/lib/server/approval-match.ts +205 -0
- package/src/lib/server/approvals-auto-approve.test.ts +538 -1
- package/src/lib/server/approvals.ts +214 -1
- package/src/lib/server/assistant-control.test.ts +29 -0
- package/src/lib/server/assistant-control.ts +23 -0
- package/src/lib/server/build-llm.test.ts +79 -0
- package/src/lib/server/build-llm.ts +14 -4
- package/src/lib/server/canvas-content.test.ts +32 -0
- package/src/lib/server/canvas-content.ts +6 -0
- package/src/lib/server/capability-router.test.ts +11 -0
- package/src/lib/server/capability-router.ts +26 -1
- package/src/lib/server/chat-execution-advanced.test.ts +651 -0
- package/src/lib/server/chat-execution-disabled.test.ts +94 -0
- package/src/lib/server/chat-execution-tool-events.test.ts +157 -0
- package/src/lib/server/chat-execution.ts +353 -72
- package/src/lib/server/clawhub-client.test.ts +14 -8
- package/src/lib/server/connectors/manager.test.ts +1147 -0
- package/src/lib/server/connectors/manager.ts +362 -63
- package/src/lib/server/connectors/pairing.ts +26 -5
- package/src/lib/server/connectors/types.ts +2 -0
- package/src/lib/server/connectors/whatsapp.test.ts +134 -0
- package/src/lib/server/connectors/whatsapp.ts +271 -47
- package/src/lib/server/context-manager.ts +6 -1
- package/src/lib/server/daemon-state.ts +1 -1
- package/src/lib/server/data-dir.test.ts +37 -0
- package/src/lib/server/data-dir.ts +20 -1
- package/src/lib/server/delegation-jobs-advanced.test.ts +513 -0
- package/src/lib/server/devserver-launch.test.ts +60 -0
- package/src/lib/server/devserver-launch.ts +85 -0
- package/src/lib/server/elevenlabs.test.ts +189 -1
- package/src/lib/server/elevenlabs.ts +147 -43
- package/src/lib/server/ethereum.ts +590 -0
- package/src/lib/server/eval/agent-regression-advanced.test.ts +302 -0
- package/src/lib/server/eval/agent-regression.test.ts +18 -1
- package/src/lib/server/eval/agent-regression.ts +383 -11
- package/src/lib/server/evm-swap.ts +475 -0
- package/src/lib/server/execution-log.ts +1 -0
- package/src/lib/server/heartbeat-service-timer.test.ts +173 -0
- package/src/lib/server/heartbeat-service.ts +15 -10
- package/src/lib/server/heartbeat-wake.test.ts +112 -0
- package/src/lib/server/heartbeat-wake.ts +338 -57
- package/src/lib/server/main-agent-loop-advanced.test.ts +538 -0
- package/src/lib/server/mcp-client.test.ts +16 -0
- package/src/lib/server/mcp-client.ts +25 -0
- package/src/lib/server/memory-integration.test.ts +719 -0
- package/src/lib/server/memory-policy.test.ts +43 -0
- package/src/lib/server/memory-policy.ts +132 -0
- package/src/lib/server/memory-tiers.test.ts +60 -0
- package/src/lib/server/memory-tiers.ts +16 -0
- package/src/lib/server/ollama-runtime.ts +58 -0
- package/src/lib/server/openclaw-deploy.test.ts +109 -1
- package/src/lib/server/openclaw-deploy.ts +557 -81
- package/src/lib/server/openclaw-gateway.test.ts +131 -0
- package/src/lib/server/openclaw-gateway.ts +10 -4
- package/src/lib/server/openclaw-health.test.ts +35 -0
- package/src/lib/server/openclaw-health.ts +215 -47
- package/src/lib/server/orchestrator-lg.ts +2 -2
- package/src/lib/server/plugins-advanced.test.ts +351 -0
- package/src/lib/server/plugins.ts +205 -5
- package/src/lib/server/queue-advanced.test.ts +528 -0
- package/src/lib/server/queue-followups.test.ts +262 -0
- package/src/lib/server/queue-reconcile.test.ts +128 -0
- package/src/lib/server/queue.ts +293 -61
- package/src/lib/server/scheduler.ts +29 -1
- package/src/lib/server/session-note.test.ts +36 -0
- package/src/lib/server/session-note.ts +42 -0
- package/src/lib/server/session-run-manager.ts +52 -4
- package/src/lib/server/session-tools/canvas.ts +14 -12
- package/src/lib/server/session-tools/connector.test.ts +138 -0
- package/src/lib/server/session-tools/connector.ts +348 -61
- package/src/lib/server/session-tools/context.ts +12 -3
- package/src/lib/server/session-tools/crud.ts +221 -10
- package/src/lib/server/session-tools/delegate-fallback.test.ts +103 -0
- package/src/lib/server/session-tools/delegate.ts +64 -8
- package/src/lib/server/session-tools/discovery-approvals.test.ts +142 -0
- package/src/lib/server/session-tools/discovery.ts +80 -12
- package/src/lib/server/session-tools/file-normalize.test.ts +36 -0
- package/src/lib/server/session-tools/file.ts +43 -4
- package/src/lib/server/session-tools/human-loop.ts +35 -5
- package/src/lib/server/session-tools/index.ts +44 -9
- package/src/lib/server/session-tools/manage-connectors.test.ts +139 -0
- package/src/lib/server/session-tools/manage-schedules-advanced.test.ts +564 -0
- package/src/lib/server/session-tools/manage-schedules.test.ts +283 -0
- package/src/lib/server/session-tools/manage-tasks-advanced.test.ts +852 -0
- package/src/lib/server/session-tools/memory.test.ts +93 -0
- package/src/lib/server/session-tools/memory.ts +546 -79
- package/src/lib/server/session-tools/normalize-tool-args.ts +1 -1
- package/src/lib/server/session-tools/plugin-creator.ts +57 -1
- package/src/lib/server/session-tools/primitive-tools.test.ts +6 -0
- package/src/lib/server/session-tools/schedule.ts +6 -1
- package/src/lib/server/session-tools/shell-normalize.test.ts +25 -1
- package/src/lib/server/session-tools/shell.ts +22 -3
- package/src/lib/server/session-tools/wallet-tool.test.ts +254 -0
- package/src/lib/server/session-tools/wallet.ts +1374 -139
- package/src/lib/server/session-tools/web-inputs.test.ts +162 -1
- package/src/lib/server/session-tools/web.ts +468 -64
- package/src/lib/server/skill-discovery.ts +128 -0
- package/src/lib/server/skill-eligibility.test.ts +84 -0
- package/src/lib/server/skill-eligibility.ts +95 -0
- package/src/lib/server/skill-prompt-budget.test.ts +102 -0
- package/src/lib/server/skill-prompt-budget.ts +125 -0
- package/src/lib/server/skills-normalize.test.ts +54 -0
- package/src/lib/server/skills-normalize.ts +372 -26
- package/src/lib/server/solana.ts +214 -29
- package/src/lib/server/storage.ts +65 -36
- package/src/lib/server/stream-agent-chat.test.ts +419 -9
- package/src/lib/server/stream-agent-chat.ts +887 -83
- package/src/lib/server/system-events.ts +1 -1
- package/src/lib/server/tool-capability-policy-advanced.test.ts +502 -0
- package/src/lib/server/tool-loop-detection.test.ts +105 -0
- package/src/lib/server/tool-loop-detection.ts +260 -0
- package/src/lib/server/tool-planning.ts +4 -2
- package/src/lib/server/wallet-execution.test.ts +198 -0
- package/src/lib/server/wallet-portfolio.test.ts +98 -0
- package/src/lib/server/wallet-portfolio.ts +724 -0
- package/src/lib/server/wallet-service.test.ts +57 -0
- package/src/lib/server/wallet-service.ts +213 -0
- package/src/lib/server/watch-jobs-advanced.test.ts +594 -0
- package/src/lib/server/watch-jobs.ts +17 -2
- package/src/lib/server/workspace-context.ts +111 -0
- package/src/lib/skill-save-payload.test.ts +39 -0
- package/src/lib/skill-save-payload.ts +37 -0
- package/src/lib/tasks.ts +28 -0
- package/src/lib/tool-event-summary.test.ts +30 -0
- package/src/lib/tool-event-summary.ts +37 -0
- package/src/lib/validation/schemas.ts +1 -0
- package/src/lib/wallet-transactions.test.ts +75 -0
- package/src/lib/wallet-transactions.ts +43 -0
- package/src/lib/wallet.test.ts +17 -0
- package/src/lib/wallet.ts +183 -0
- package/src/proxy.test.ts +31 -0
- package/src/proxy.ts +34 -2
- package/src/stores/use-chat-store.ts +15 -1
- package/src/types/index.ts +210 -14
|
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict'
|
|
|
3
3
|
import type { BoardTask, Session } from '@/types'
|
|
4
4
|
import {
|
|
5
5
|
applyTaskResumeStateToSession,
|
|
6
|
+
collectTaskConnectorFollowupTargets,
|
|
6
7
|
dequeueNextRunnableTask,
|
|
7
8
|
resolveTaskOriginConnectorFollowupTarget,
|
|
8
9
|
resolveTaskResumeContext,
|
|
@@ -24,12 +25,19 @@ function makeTask(partial?: Partial<BoardTask> & { createdInSessionId?: string |
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
type SessionFixtureMap = Record<string, {
|
|
28
|
+
connectorContext?: {
|
|
29
|
+
connectorId?: string
|
|
30
|
+
channelId?: string
|
|
31
|
+
threadId?: string
|
|
32
|
+
}
|
|
27
33
|
messages: Array<{
|
|
28
34
|
role: string
|
|
29
35
|
text?: string
|
|
36
|
+
historyExcluded?: boolean
|
|
30
37
|
source?: {
|
|
31
38
|
connectorId?: string
|
|
32
39
|
channelId?: string
|
|
40
|
+
threadId?: string
|
|
33
41
|
}
|
|
34
42
|
}>
|
|
35
43
|
}>
|
|
@@ -227,6 +235,260 @@ describe('resolveTaskOriginConnectorFollowupTarget', () => {
|
|
|
227
235
|
channelId: '447700900123@s.whatsapp.net',
|
|
228
236
|
})
|
|
229
237
|
})
|
|
238
|
+
|
|
239
|
+
it('prefers explicit task followup metadata over later thread traffic', () => {
|
|
240
|
+
const task = makeTask({
|
|
241
|
+
createdInSessionId: 'session-1',
|
|
242
|
+
followupConnectorId: 'conn-wa',
|
|
243
|
+
followupChannelId: '447700900111@s.whatsapp.net',
|
|
244
|
+
followupThreadId: 'thread-me',
|
|
245
|
+
})
|
|
246
|
+
const sessions = {
|
|
247
|
+
'session-1': {
|
|
248
|
+
messages: [
|
|
249
|
+
{
|
|
250
|
+
role: 'user',
|
|
251
|
+
text: 'wife said hello',
|
|
252
|
+
source: {
|
|
253
|
+
connectorId: 'conn-wa',
|
|
254
|
+
channelId: '447700900222@s.whatsapp.net',
|
|
255
|
+
threadId: 'thread-wife',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
}
|
|
261
|
+
const connectors = {
|
|
262
|
+
'conn-wa': {
|
|
263
|
+
id: 'conn-wa',
|
|
264
|
+
platform: 'whatsapp',
|
|
265
|
+
agentId: 'agent-a',
|
|
266
|
+
config: {},
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
const running = [
|
|
270
|
+
{
|
|
271
|
+
id: 'conn-wa',
|
|
272
|
+
platform: 'whatsapp',
|
|
273
|
+
agentId: 'agent-a',
|
|
274
|
+
supportsSend: true,
|
|
275
|
+
configuredTargets: [],
|
|
276
|
+
recentChannelId: '447700900222@s.whatsapp.net',
|
|
277
|
+
},
|
|
278
|
+
]
|
|
279
|
+
|
|
280
|
+
const target = resolveTaskOriginConnectorFollowupTarget({
|
|
281
|
+
task,
|
|
282
|
+
sessions: sessions as SessionFixtureMap,
|
|
283
|
+
connectors,
|
|
284
|
+
running,
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
assert.deepEqual(target, {
|
|
288
|
+
connectorId: 'conn-wa',
|
|
289
|
+
channelId: '447700900111@s.whatsapp.net',
|
|
290
|
+
threadId: 'thread-me',
|
|
291
|
+
})
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
it('ignores mirrored connector transcript copies when resolving delayed followups', () => {
|
|
295
|
+
const task = makeTask({ createdInSessionId: 'session-main' })
|
|
296
|
+
const sessions = {
|
|
297
|
+
'session-main': {
|
|
298
|
+
messages: [
|
|
299
|
+
{
|
|
300
|
+
role: 'user',
|
|
301
|
+
text: 'from me over whatsapp',
|
|
302
|
+
historyExcluded: true,
|
|
303
|
+
source: {
|
|
304
|
+
connectorId: 'conn-wa',
|
|
305
|
+
channelId: '447700900111@s.whatsapp.net',
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
role: 'user',
|
|
310
|
+
text: 'from wife over whatsapp later',
|
|
311
|
+
historyExcluded: true,
|
|
312
|
+
source: {
|
|
313
|
+
connectorId: 'conn-wa',
|
|
314
|
+
channelId: '447700900222@s.whatsapp.net',
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
},
|
|
319
|
+
}
|
|
320
|
+
const connectors = {
|
|
321
|
+
'conn-wa': {
|
|
322
|
+
id: 'conn-wa',
|
|
323
|
+
platform: 'whatsapp',
|
|
324
|
+
agentId: 'agent-a',
|
|
325
|
+
config: {
|
|
326
|
+
taskFollowups: 'true',
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
}
|
|
330
|
+
const running = [
|
|
331
|
+
{
|
|
332
|
+
id: 'conn-wa',
|
|
333
|
+
platform: 'whatsapp',
|
|
334
|
+
agentId: 'agent-a',
|
|
335
|
+
supportsSend: true,
|
|
336
|
+
configuredTargets: [],
|
|
337
|
+
recentChannelId: '447700900222@s.whatsapp.net',
|
|
338
|
+
},
|
|
339
|
+
]
|
|
340
|
+
|
|
341
|
+
const target = resolveTaskOriginConnectorFollowupTarget({
|
|
342
|
+
task,
|
|
343
|
+
sessions: sessions as SessionFixtureMap,
|
|
344
|
+
connectors,
|
|
345
|
+
running,
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
assert.equal(target, null)
|
|
349
|
+
})
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
describe('collectTaskConnectorFollowupTargets', () => {
|
|
353
|
+
it('does not fall back to a connector recent channel when there is no explicit origin target', () => {
|
|
354
|
+
const task = makeTask({ createdInSessionId: 'session-main' })
|
|
355
|
+
const sessions = {
|
|
356
|
+
'session-main': {
|
|
357
|
+
messages: [
|
|
358
|
+
{
|
|
359
|
+
role: 'user',
|
|
360
|
+
text: 'mirrored from me',
|
|
361
|
+
historyExcluded: true,
|
|
362
|
+
source: {
|
|
363
|
+
connectorId: 'conn-wa',
|
|
364
|
+
channelId: '447700900111@s.whatsapp.net',
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
},
|
|
369
|
+
}
|
|
370
|
+
const connectors = {
|
|
371
|
+
'conn-wa': {
|
|
372
|
+
id: 'conn-wa',
|
|
373
|
+
platform: 'whatsapp',
|
|
374
|
+
agentId: 'agent-a',
|
|
375
|
+
config: {
|
|
376
|
+
taskFollowups: 'true',
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
}
|
|
380
|
+
const running = [
|
|
381
|
+
{
|
|
382
|
+
id: 'conn-wa',
|
|
383
|
+
platform: 'whatsapp',
|
|
384
|
+
agentId: 'agent-a',
|
|
385
|
+
supportsSend: true,
|
|
386
|
+
configuredTargets: [],
|
|
387
|
+
recentChannelId: '447700900222@s.whatsapp.net',
|
|
388
|
+
},
|
|
389
|
+
]
|
|
390
|
+
|
|
391
|
+
const targets = collectTaskConnectorFollowupTargets({
|
|
392
|
+
task,
|
|
393
|
+
sessions: sessions as SessionFixtureMap,
|
|
394
|
+
connectors,
|
|
395
|
+
running,
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
assert.deepEqual(targets, [])
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
it('uses only the origin target when both origin and a different recent channel exist', () => {
|
|
402
|
+
const task = makeTask({
|
|
403
|
+
createdInSessionId: 'session-origin',
|
|
404
|
+
followupConnectorId: 'conn-wa',
|
|
405
|
+
followupChannelId: '447700900111@s.whatsapp.net',
|
|
406
|
+
})
|
|
407
|
+
const sessions = {
|
|
408
|
+
'session-origin': {
|
|
409
|
+
messages: [],
|
|
410
|
+
},
|
|
411
|
+
}
|
|
412
|
+
const connectors = {
|
|
413
|
+
'conn-wa': {
|
|
414
|
+
id: 'conn-wa',
|
|
415
|
+
platform: 'whatsapp',
|
|
416
|
+
agentId: 'agent-a',
|
|
417
|
+
config: {
|
|
418
|
+
taskFollowups: 'true',
|
|
419
|
+
outboundJid: '447700900333@s.whatsapp.net',
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
}
|
|
423
|
+
const running = [
|
|
424
|
+
{
|
|
425
|
+
id: 'conn-wa',
|
|
426
|
+
platform: 'whatsapp',
|
|
427
|
+
agentId: 'agent-a',
|
|
428
|
+
supportsSend: true,
|
|
429
|
+
configuredTargets: [],
|
|
430
|
+
recentChannelId: '447700900222@s.whatsapp.net',
|
|
431
|
+
},
|
|
432
|
+
]
|
|
433
|
+
|
|
434
|
+
const targets = collectTaskConnectorFollowupTargets({
|
|
435
|
+
task,
|
|
436
|
+
sessions: sessions as SessionFixtureMap,
|
|
437
|
+
connectors,
|
|
438
|
+
running,
|
|
439
|
+
})
|
|
440
|
+
|
|
441
|
+
assert.deepEqual(targets, [
|
|
442
|
+
{
|
|
443
|
+
connectorId: 'conn-wa',
|
|
444
|
+
channelId: '447700900111@s.whatsapp.net',
|
|
445
|
+
},
|
|
446
|
+
])
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
it('uses configured outbound targets for generic task followups', () => {
|
|
450
|
+
const task = makeTask({ createdInSessionId: 'session-main' })
|
|
451
|
+
const sessions = {
|
|
452
|
+
'session-main': {
|
|
453
|
+
messages: [],
|
|
454
|
+
},
|
|
455
|
+
}
|
|
456
|
+
const connectors = {
|
|
457
|
+
'conn-wa': {
|
|
458
|
+
id: 'conn-wa',
|
|
459
|
+
platform: 'whatsapp',
|
|
460
|
+
agentId: 'agent-a',
|
|
461
|
+
config: {
|
|
462
|
+
taskFollowups: 'true',
|
|
463
|
+
outboundJid: '+44 7700 900333',
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
}
|
|
467
|
+
const running = [
|
|
468
|
+
{
|
|
469
|
+
id: 'conn-wa',
|
|
470
|
+
platform: 'whatsapp',
|
|
471
|
+
agentId: 'agent-a',
|
|
472
|
+
supportsSend: true,
|
|
473
|
+
configuredTargets: [],
|
|
474
|
+
recentChannelId: '447700900222@s.whatsapp.net',
|
|
475
|
+
},
|
|
476
|
+
]
|
|
477
|
+
|
|
478
|
+
const targets = collectTaskConnectorFollowupTargets({
|
|
479
|
+
task,
|
|
480
|
+
sessions: sessions as SessionFixtureMap,
|
|
481
|
+
connectors,
|
|
482
|
+
running,
|
|
483
|
+
})
|
|
484
|
+
|
|
485
|
+
assert.deepEqual(targets, [
|
|
486
|
+
{
|
|
487
|
+
connectorId: 'conn-wa',
|
|
488
|
+
channelId: '447700900333@s.whatsapp.net',
|
|
489
|
+
},
|
|
490
|
+
])
|
|
491
|
+
})
|
|
230
492
|
})
|
|
231
493
|
|
|
232
494
|
describe('task resume context', () => {
|
|
@@ -0,0 +1,128 @@
|
|
|
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 { spawnSync } from 'node:child_process'
|
|
6
|
+
import { describe, it } from 'node:test'
|
|
7
|
+
|
|
8
|
+
const repoRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname), '../../..')
|
|
9
|
+
|
|
10
|
+
function runWithTempDataDir(script: string) {
|
|
11
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'swarmclaw-queue-reconcile-'))
|
|
12
|
+
try {
|
|
13
|
+
const result = spawnSync(process.execPath, ['--import', 'tsx', '--input-type=module', '--eval', script], {
|
|
14
|
+
cwd: repoRoot,
|
|
15
|
+
env: {
|
|
16
|
+
...process.env,
|
|
17
|
+
DATA_DIR: path.join(tempDir, 'data'),
|
|
18
|
+
WORKSPACE_DIR: path.join(tempDir, 'workspace'),
|
|
19
|
+
SWARMCLAW_BUILD_MODE: '1',
|
|
20
|
+
},
|
|
21
|
+
encoding: 'utf-8',
|
|
22
|
+
})
|
|
23
|
+
assert.equal(result.status, 0, result.stderr || result.stdout || 'subprocess failed')
|
|
24
|
+
const lines = (result.stdout || '')
|
|
25
|
+
.trim()
|
|
26
|
+
.split('\n')
|
|
27
|
+
.map((line) => line.trim())
|
|
28
|
+
.filter(Boolean)
|
|
29
|
+
const jsonLine = [...lines].reverse().find((line) => line.startsWith('{'))
|
|
30
|
+
return JSON.parse(jsonLine || '{}')
|
|
31
|
+
} finally {
|
|
32
|
+
fs.rmSync(tempDir, { recursive: true, force: true })
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('reconcileFinishedRunningTasks', () => {
|
|
37
|
+
it('finalizes a completed one-off scheduled task from its finished session and deletes the schedule', () => {
|
|
38
|
+
const output = runWithTempDataDir(`
|
|
39
|
+
const storageMod = await import('./src/lib/server/storage.ts')
|
|
40
|
+
const queueMod = await import('./src/lib/server/queue.ts')
|
|
41
|
+
const storage = storageMod.default || storageMod
|
|
42
|
+
const queue = queueMod.default || queueMod
|
|
43
|
+
|
|
44
|
+
const now = Date.now()
|
|
45
|
+
const workspace = process.env.WORKSPACE_DIR
|
|
46
|
+
storage.saveAgents({
|
|
47
|
+
agent_birthday: {
|
|
48
|
+
id: 'agent_birthday',
|
|
49
|
+
name: 'Birthday Bot',
|
|
50
|
+
description: '',
|
|
51
|
+
systemPrompt: '',
|
|
52
|
+
provider: 'openai',
|
|
53
|
+
model: 'gpt-test',
|
|
54
|
+
threadSessionId: null,
|
|
55
|
+
createdAt: now,
|
|
56
|
+
updatedAt: now,
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
storage.saveSessions({
|
|
60
|
+
'session-birthday': {
|
|
61
|
+
id: 'session-birthday',
|
|
62
|
+
name: 'Birthday Run',
|
|
63
|
+
cwd: workspace,
|
|
64
|
+
user: 'tester',
|
|
65
|
+
provider: 'openai',
|
|
66
|
+
model: 'gpt-test',
|
|
67
|
+
claudeSessionId: null,
|
|
68
|
+
messages: [
|
|
69
|
+
{
|
|
70
|
+
role: 'assistant',
|
|
71
|
+
text: 'Happy birthday. I sent a WhatsApp follow-up to the user directly and confirmed delivery with message id 3EB0B7262FF68B7BD261D4.',
|
|
72
|
+
time: now,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
createdAt: now - 10_000,
|
|
76
|
+
lastActiveAt: now,
|
|
77
|
+
active: false,
|
|
78
|
+
currentRunId: null,
|
|
79
|
+
heartbeatEnabled: true,
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
storage.saveSchedules({
|
|
83
|
+
'schedule-birthday': {
|
|
84
|
+
id: 'schedule-birthday',
|
|
85
|
+
name: 'Birthday Reminder',
|
|
86
|
+
scheduleType: 'once',
|
|
87
|
+
status: 'completed',
|
|
88
|
+
agentId: 'agent_birthday',
|
|
89
|
+
createdByAgentId: 'agent_birthday',
|
|
90
|
+
createdAt: now - 20_000,
|
|
91
|
+
updatedAt: now - 5_000,
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
storage.saveTasks({
|
|
95
|
+
'task-birthday': {
|
|
96
|
+
id: 'task-birthday',
|
|
97
|
+
title: 'Birthday follow-up',
|
|
98
|
+
description: 'Wish me happy birthday tomorrow over WhatsApp.',
|
|
99
|
+
status: 'running',
|
|
100
|
+
agentId: 'agent_birthday',
|
|
101
|
+
createdAt: now - 20_000,
|
|
102
|
+
updatedAt: now - 5_000,
|
|
103
|
+
startedAt: now - 15_000,
|
|
104
|
+
sessionId: 'session-birthday',
|
|
105
|
+
sourceType: 'schedule',
|
|
106
|
+
sourceScheduleId: 'schedule-birthday',
|
|
107
|
+
sourceScheduleName: 'Birthday Reminder',
|
|
108
|
+
maxAttempts: 3,
|
|
109
|
+
retryBackoffSec: 30,
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const result = queue.reconcileFinishedRunningTasks()
|
|
114
|
+
console.log(JSON.stringify({
|
|
115
|
+
result,
|
|
116
|
+
task: storage.loadTasks()['task-birthday'],
|
|
117
|
+
schedule: storage.loadSchedules()['schedule-birthday'] || null,
|
|
118
|
+
session: storage.loadSessions()['session-birthday'],
|
|
119
|
+
}))
|
|
120
|
+
`)
|
|
121
|
+
|
|
122
|
+
assert.equal(output.result.reconciled, 1)
|
|
123
|
+
assert.equal(output.task.status, 'completed')
|
|
124
|
+
assert.equal(output.schedule, null)
|
|
125
|
+
assert.equal(output.session.heartbeatEnabled, false)
|
|
126
|
+
assert.match(output.task.result, /WhatsApp follow-up/i)
|
|
127
|
+
})
|
|
128
|
+
})
|