@swarmclawai/swarmclaw 1.2.6 → 1.2.9
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 +54 -23
- package/next.config.ts +1 -0
- package/package.json +4 -3
- package/scripts/easy-setup.mjs +1 -1
- package/scripts/postinstall.mjs +1 -1
- package/skills/swarmclaw.md +115 -0
- package/skills/tools/browser.md +131 -0
- package/skills/tools/execute.md +98 -0
- package/skills/tools/files.md +98 -0
- package/skills/tools/memory.md +104 -0
- package/skills/tools/platform.md +144 -0
- package/skills/tools/skills.md +83 -0
- package/src/app/agents/[id]/page.tsx +1 -18
- package/src/app/api/agents/thread-route.test.ts +0 -1
- package/src/app/api/approvals/route.test.ts +6 -22
- package/src/app/api/chats/[id]/messages/route.ts +23 -19
- package/src/app/api/chats/messages-route.test.ts +105 -51
- package/src/app/api/connectors/route.ts +2 -2
- package/src/app/api/mcp-servers/[id]/test/route.ts +3 -2
- package/src/app/api/openclaw/deploy/route.ts +2 -0
- package/src/app/api/portability/export/route.ts +8 -0
- package/src/app/api/portability/import/route.test.ts +80 -0
- package/src/app/api/portability/import/route.ts +28 -0
- package/src/app/api/settings/route.ts +0 -2
- package/src/app/api/setup/doctor/route.ts +4 -4
- package/src/app/api/wallets/[id]/route.ts +15 -157
- package/src/app/api/wallets/generate/route.ts +22 -0
- package/src/app/api/wallets/route.test.ts +147 -0
- package/src/app/api/wallets/route.ts +13 -95
- package/src/app/autonomy/page.tsx +2 -57
- package/src/app/protocols/page.tsx +2 -21
- package/src/app/settings/page.tsx +0 -9
- package/src/app/wallets/page.tsx +105 -5
- package/src/cli/index.js +21 -33
- package/src/cli/spec.js +19 -30
- package/src/components/agents/agent-chat-list.tsx +23 -1
- package/src/components/agents/agent-sheet.tsx +2 -40
- package/src/components/agents/inspector-panel.tsx +165 -131
- package/src/components/chat/chat-area.tsx +38 -9
- package/src/components/chat/chat-card.tsx +0 -31
- package/src/components/chat/message-bubble.tsx +1 -108
- package/src/components/chat/message-list.tsx +33 -19
- package/src/components/connectors/connector-sheet.tsx +25 -1
- package/src/components/gateways/gateway-sheet.tsx +5 -2
- package/src/components/layout/sidebar-rail.tsx +6 -10
- package/src/components/projects/project-detail.tsx +3 -35
- package/src/components/projects/tabs/overview-tab.tsx +3 -59
- package/src/components/projects/tabs/work-tab.tsx +7 -77
- package/src/components/protocols/structured-session-launcher.tsx +1 -22
- package/src/components/shared/connector-platform-icon.tsx +1 -0
- package/src/components/tasks/task-card.tsx +4 -34
- package/src/components/tasks/task-sheet.tsx +6 -36
- package/src/components/wallets/wallet-list.tsx +150 -0
- package/src/lib/agent-execute-defaults.test.ts +24 -0
- package/src/lib/agent-execute-defaults.ts +62 -0
- package/src/lib/app/navigation.test.ts +0 -13
- package/src/lib/app/navigation.ts +2 -7
- package/src/lib/app/view-constants.ts +14 -19
- package/src/lib/chat/queued-message-queue.test.ts +134 -1
- package/src/lib/chat/queued-message-queue.ts +77 -2
- package/src/lib/server/agents/agent-service.ts +5 -0
- package/src/lib/server/agents/agent-thread-session.ts +0 -1
- package/src/lib/server/agents/delegation-advisory.test.ts +0 -1
- package/src/lib/server/agents/delegation-jobs.test.ts +0 -69
- package/src/lib/server/agents/delegation-jobs.ts +0 -25
- package/src/lib/server/agents/main-agent-loop.ts +1 -49
- package/src/lib/server/agents/subagent-runtime.ts +0 -1
- package/src/lib/server/approval-match.ts +0 -85
- package/src/lib/server/approvals.test.ts +6 -6
- package/src/lib/server/approvals.ts +0 -6
- package/src/lib/server/autonomy/supervisor-reflection.test.ts +0 -1
- package/src/lib/server/builtin-extensions.ts +1 -2
- package/src/lib/server/capability-router.test.ts +0 -2
- package/src/lib/server/chat-execution/chat-execution-advanced.test.ts +1 -1
- package/src/lib/server/chat-execution/chat-execution-tool-events.test.ts +15 -14
- package/src/lib/server/chat-execution/chat-execution-types.ts +0 -2
- package/src/lib/server/chat-execution/chat-execution-utils.ts +2 -4
- package/src/lib/server/chat-execution/chat-streaming-utils.ts +2 -30
- package/src/lib/server/chat-execution/chat-turn-finalization.ts +1 -36
- package/src/lib/server/chat-execution/chat-turn-preparation.ts +81 -64
- package/src/lib/server/chat-execution/chat-turn-stream-execution.ts +4 -0
- package/src/lib/server/chat-execution/continuation-evaluator.ts +8 -0
- package/src/lib/server/chat-execution/iteration-event-handler.ts +0 -24
- package/src/lib/server/chat-execution/memory-mutation-tools.ts +1 -1
- package/src/lib/server/chat-execution/message-classifier.test.ts +0 -45
- package/src/lib/server/chat-execution/message-classifier.ts +11 -16
- package/src/lib/server/chat-execution/prompt-builder.test.ts +27 -0
- package/src/lib/server/chat-execution/prompt-builder.ts +14 -31
- package/src/lib/server/chat-execution/prompt-mode.test.ts +24 -0
- package/src/lib/server/chat-execution/prompt-mode.ts +5 -1
- package/src/lib/server/chat-execution/prompt-sections.ts +0 -1
- package/src/lib/server/chat-execution/situational-awareness.test.ts +2 -73
- package/src/lib/server/chat-execution/situational-awareness.ts +4 -38
- package/src/lib/server/chat-execution/stream-agent-chat.test.ts +13 -126
- package/src/lib/server/chat-execution/stream-agent-chat.ts +46 -21
- package/src/lib/server/chat-execution/stream-continuation.test.ts +4 -52
- package/src/lib/server/chat-execution/stream-continuation.ts +6 -48
- package/src/lib/server/chatrooms/chatroom-routing.test.ts +4 -0
- package/src/lib/server/chatrooms/session-mailbox.ts +0 -10
- package/src/lib/server/chats/chat-session-service.ts +3 -5
- package/src/lib/server/connectors/connector-inbound.ts +0 -1
- package/src/lib/server/connectors/connector-lifecycle.ts +19 -3
- package/src/lib/server/connectors/connector-service.ts +39 -9
- package/src/lib/server/connectors/discord.ts +2 -2
- package/src/lib/server/connectors/matrix.ts +3 -2
- package/src/lib/server/connectors/signal.ts +5 -4
- package/src/lib/server/connectors/slack.ts +10 -9
- package/src/lib/server/connectors/swarmdock-bidding.ts +74 -0
- package/src/lib/server/connectors/swarmdock-payloads.test.ts +85 -0
- package/src/lib/server/connectors/swarmdock-secret.test.ts +128 -0
- package/src/lib/server/connectors/swarmdock-secret.ts +152 -0
- package/src/lib/server/connectors/swarmdock-tasks.ts +119 -0
- package/src/lib/server/connectors/swarmdock.ts +255 -0
- package/src/lib/server/connectors/teams.ts +3 -2
- package/src/lib/server/connectors/telegram.ts +4 -4
- package/src/lib/server/connectors/whatsapp.ts +2 -2
- package/src/lib/server/daemon/controller.ts +7 -0
- package/src/lib/server/execution-brief.test.ts +2 -25
- package/src/lib/server/execution-brief.ts +12 -35
- package/src/lib/server/execution-engine/task-attempt.ts +0 -1
- package/src/lib/server/gateways/gateway-profile-service.ts +19 -1
- package/src/lib/server/messages/message-repository.test.ts +70 -0
- package/src/lib/server/messages/message-repository.ts +11 -6
- package/src/lib/server/openclaw/deploy.ts +32 -2
- package/src/lib/server/persistence/storage-context.ts +0 -5
- package/src/lib/server/plugins-advanced.test.ts +1 -2
- package/src/lib/server/portability/export.ts +109 -0
- package/src/lib/server/portability/import.ts +159 -0
- package/src/lib/server/protocols/protocol-normalization.ts +0 -4
- package/src/lib/server/protocols/protocol-queries.ts +0 -6
- package/src/lib/server/protocols/protocol-run-lifecycle.ts +4 -32
- package/src/lib/server/protocols/protocol-service.ts +0 -1
- package/src/lib/server/protocols/protocol-step-helpers.ts +0 -4
- package/src/lib/server/protocols/protocol-step-processors.ts +0 -6
- package/src/lib/server/protocols/protocol-swarm.ts +0 -2
- package/src/lib/server/protocols/protocol-types.ts +0 -2
- package/src/lib/server/provider-health.ts +1 -10
- package/src/lib/server/runtime/daemon-state/core.ts +0 -9
- package/src/lib/server/runtime/daemon-state.test.ts +0 -35
- package/src/lib/server/runtime/heartbeat-service.ts +3 -23
- package/src/lib/server/runtime/process-manager.ts +13 -9
- package/src/lib/server/runtime/queue/core.ts +11 -33
- package/src/lib/server/runtime/runtime-storage-write-paths.test.ts +6 -6
- package/src/lib/server/runtime/scheduler.ts +0 -13
- package/src/lib/server/runtime/session-run-manager/drain.ts +0 -24
- package/src/lib/server/runtime/session-run-manager/enqueue.ts +0 -1
- package/src/lib/server/runtime/session-run-manager/queries.ts +15 -1
- package/src/lib/server/runtime/session-run-manager/recovery.ts +0 -1
- package/src/lib/server/runtime/session-run-manager.test.ts +58 -28
- package/src/lib/server/sandbox/session-runtime.test.ts +18 -1
- package/src/lib/server/sandbox/session-runtime.ts +40 -28
- package/src/lib/server/session-tools/autonomy-tools.test.ts +7 -9
- package/src/lib/server/session-tools/context.ts +1 -1
- package/src/lib/server/session-tools/credential-env.ts +109 -0
- package/src/lib/server/session-tools/crud.ts +3 -17
- package/src/lib/server/session-tools/delegate.ts +0 -4
- package/src/lib/server/session-tools/edit_file.ts +3 -2
- package/src/lib/server/session-tools/execute.test.ts +58 -0
- package/src/lib/server/session-tools/execute.ts +334 -0
- package/src/lib/server/session-tools/files-tool.ts +635 -0
- package/src/lib/server/session-tools/index.ts +14 -8
- package/src/lib/server/session-tools/memory-tool.ts +242 -0
- package/src/lib/server/session-tools/memory.ts +1 -1
- package/src/lib/server/session-tools/openclaw-nodes.ts +3 -2
- package/src/lib/server/session-tools/openclaw-workspace.ts +3 -2
- package/src/lib/server/session-tools/platform-tool.ts +617 -0
- package/src/lib/server/session-tools/session-info.ts +3 -2
- package/src/lib/server/session-tools/session-tools-wiring.test.ts +3 -4
- package/src/lib/server/session-tools/shell.ts +7 -122
- package/src/lib/server/session-tools/skills-tool.ts +396 -0
- package/src/lib/server/session-tools/team-context.ts +0 -3
- package/src/lib/server/session-tools/web.ts +2 -2
- package/src/lib/server/storage-normalization.ts +10 -0
- package/src/lib/server/storage.ts +18 -45
- package/src/lib/server/tasks/task-checkout.ts +59 -0
- package/src/lib/server/tasks/task-lifecycle.ts +2 -0
- package/src/lib/server/tasks/task-route-service.ts +4 -26
- package/src/lib/server/tasks/task-service.ts +0 -7
- package/src/lib/server/tool-aliases.ts +2 -2
- package/src/lib/server/tool-capability-policy-advanced.test.ts +13 -6
- package/src/lib/server/tool-capability-policy.test.ts +2 -1
- package/src/lib/server/tool-capability-policy.ts +60 -35
- package/src/lib/server/tool-planning.ts +11 -12
- package/src/lib/server/universal-tool-access.ts +0 -1
- package/src/lib/server/wallets/wallet-crypto.ts +33 -0
- package/src/lib/server/wallets/wallet-repository.ts +24 -0
- package/src/lib/server/wallets/wallet-service.ts +119 -0
- package/src/lib/server/working-state/extraction.ts +8 -42
- package/src/lib/server/working-state/normalization.ts +10 -103
- package/src/lib/server/working-state/service.ts +12 -21
- package/src/lib/setup-defaults.ts +5 -0
- package/src/lib/strip-internal-metadata.test.ts +1 -1
- package/src/lib/strip-internal-metadata.ts +1 -1
- package/src/lib/tool-definitions.ts +1 -1
- package/src/lib/validation/schemas.test.ts +16 -0
- package/src/lib/validation/schemas.ts +49 -2
- package/src/stores/slices/data-slice.ts +5 -1
- package/src/stores/slices/ui-slice.ts +0 -4
- package/src/stores/use-chat-store.test.ts +231 -0
- package/src/stores/use-chat-store.ts +62 -13
- package/src/types/agent.ts +264 -0
- package/src/types/app-settings.ts +173 -0
- package/src/types/approval.ts +25 -0
- package/src/types/connector.ts +188 -0
- package/src/types/extension.ts +386 -0
- package/src/types/index.ts +16 -3555
- package/src/types/message.ts +56 -0
- package/src/types/misc.ts +737 -0
- package/src/types/protocol.ts +420 -0
- package/src/types/provider.ts +52 -0
- package/src/types/run.ts +180 -0
- package/src/types/schedule.ts +59 -0
- package/src/types/session.ts +215 -0
- package/src/types/skill.ts +157 -0
- package/src/types/swarmdock.ts +29 -0
- package/src/types/task.ts +144 -0
- package/src/types/working-state.ts +204 -0
- package/src/views/settings/section-heartbeat.tsx +2 -2
- package/src/views/settings/section-runtime-loop.tsx +0 -14
- package/src/app/api/canvas/[sessionId]/route.ts +0 -35
- package/src/app/api/missions/[id]/actions/route.ts +0 -31
- package/src/app/api/missions/[id]/events/route.ts +0 -14
- package/src/app/api/missions/[id]/route.ts +0 -10
- package/src/app/api/missions/route.test.ts +0 -244
- package/src/app/api/missions/route.ts +0 -57
- package/src/app/api/wallets/[id]/approve/route.ts +0 -79
- package/src/app/api/wallets/[id]/balance-history/route.ts +0 -18
- package/src/app/api/wallets/[id]/send/route.ts +0 -113
- package/src/app/api/wallets/[id]/transactions/route.ts +0 -18
- package/src/app/missions/[id]/page.tsx +0 -3
- package/src/app/missions/page.tsx +0 -685
- package/src/components/canvas/canvas-panel.tsx +0 -267
- package/src/components/wallets/wallet-approval-dialog.tsx +0 -107
- package/src/components/wallets/wallet-panel.tsx +0 -1010
- package/src/components/wallets/wallet-section.tsx +0 -260
- package/src/features/missions/queries.ts +0 -23
- package/src/lib/canvas-content.test.ts +0 -360
- package/src/lib/canvas-content.ts +0 -198
- package/src/lib/server/canvas-content.test.ts +0 -32
- package/src/lib/server/canvas-content.ts +0 -6
- package/src/lib/server/ethereum.ts +0 -591
- package/src/lib/server/evm-swap.ts +0 -476
- package/src/lib/server/missions/mission-intent.test.ts +0 -63
- package/src/lib/server/missions/mission-intent.ts +0 -569
- package/src/lib/server/missions/mission-repository.ts +0 -74
- package/src/lib/server/missions/mission-service/actions.ts +0 -6
- package/src/lib/server/missions/mission-service/bindings.ts +0 -9
- package/src/lib/server/missions/mission-service/context.ts +0 -4
- package/src/lib/server/missions/mission-service/core.ts +0 -2271
- package/src/lib/server/missions/mission-service/queries.ts +0 -12
- package/src/lib/server/missions/mission-service/recovery.ts +0 -5
- package/src/lib/server/missions/mission-service/ticks.ts +0 -9
- package/src/lib/server/missions/mission-service.test.ts +0 -888
- package/src/lib/server/missions/mission-service.ts +0 -6
- package/src/lib/server/session-tools/canvas.ts +0 -105
- package/src/lib/server/session-tools/sandbox.ts +0 -281
- package/src/lib/server/session-tools/wallet-tool.test.ts +0 -150
- package/src/lib/server/session-tools/wallet.ts +0 -1287
- package/src/lib/server/solana.ts +0 -327
- package/src/lib/server/wallet/wallet-execution.test.ts +0 -198
- package/src/lib/server/wallet/wallet-portfolio.test.ts +0 -98
- package/src/lib/server/wallet/wallet-portfolio.ts +0 -772
- package/src/lib/server/wallet/wallet-service.test.ts +0 -81
- package/src/lib/server/wallet/wallet-service.ts +0 -225
- package/src/lib/wallet/wallet-transactions.test.ts +0 -75
- package/src/lib/wallet/wallet-transactions.ts +0 -43
- package/src/lib/wallet/wallet.test.ts +0 -333
- package/src/lib/wallet/wallet.ts +0 -183
- package/src/views/settings/section-wallets.tsx +0 -35
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
import { loadAgents } from '@/lib/server/agents/agent-repository'
|
|
11
11
|
import { assessAutonomyRun } from '@/lib/server/autonomy/supervisor-reflection'
|
|
12
12
|
import { enqueueSystemEvent } from '@/lib/server/runtime/system-events'
|
|
13
|
-
import { buildMissionHeartbeatPrompt as buildMissionHeartbeatPromptFromMission, getMissionForSession } from '@/lib/server/missions/mission-service'
|
|
14
13
|
import { loadSettings } from '@/lib/server/settings/settings-repository'
|
|
15
14
|
import { getSession, loadSessions } from '@/lib/server/sessions/session-repository'
|
|
16
15
|
import { deleteSessionWorkingState, loadSessionWorkingState, syncWorkingStateFromMainLoopState } from '@/lib/server/working-state/service'
|
|
@@ -37,7 +36,6 @@ export interface MainLoopState {
|
|
|
37
36
|
currentPlanStep: string | null
|
|
38
37
|
reviewNote: string | null
|
|
39
38
|
reviewConfidence: number | null
|
|
40
|
-
missionTaskId: string | null
|
|
41
39
|
momentumScore: number
|
|
42
40
|
paused: boolean
|
|
43
41
|
status: 'idle' | 'progress' | 'blocked' | 'ok'
|
|
@@ -55,8 +53,6 @@ export interface MainLoopState {
|
|
|
55
53
|
note: string
|
|
56
54
|
status?: 'idle' | 'progress' | 'blocked' | 'ok' | 'reflection'
|
|
57
55
|
}>
|
|
58
|
-
missionTokens: number
|
|
59
|
-
missionCostUsd: number
|
|
60
56
|
followupChainCount: number
|
|
61
57
|
lifetimeIterations: number
|
|
62
58
|
metaMissCount: number
|
|
@@ -137,15 +133,12 @@ function defaultState(): MainLoopState {
|
|
|
137
133
|
currentPlanStep: null,
|
|
138
134
|
reviewNote: null,
|
|
139
135
|
reviewConfidence: null,
|
|
140
|
-
missionTaskId: null,
|
|
141
136
|
momentumScore: 0,
|
|
142
137
|
paused: false,
|
|
143
138
|
status: 'idle',
|
|
144
139
|
autonomyMode: 'assist',
|
|
145
140
|
pendingEvents: [],
|
|
146
141
|
timeline: [],
|
|
147
|
-
missionTokens: 0,
|
|
148
|
-
missionCostUsd: 0,
|
|
149
142
|
followupChainCount: 0,
|
|
150
143
|
lifetimeIterations: 0,
|
|
151
144
|
metaMissCount: 0,
|
|
@@ -304,8 +297,6 @@ function clampState(state: MainLoopState): MainLoopState {
|
|
|
304
297
|
state.followupChainCount = Math.max(0, Math.min(10, Math.trunc(state.followupChainCount || 0)))
|
|
305
298
|
state.lifetimeIterations = Math.max(0, Math.trunc(state.lifetimeIterations || 0))
|
|
306
299
|
state.metaMissCount = Math.max(0, Math.min(100, Math.trunc(state.metaMissCount || 0)))
|
|
307
|
-
state.missionTokens = Math.max(0, Math.trunc(state.missionTokens || 0))
|
|
308
|
-
state.missionCostUsd = Math.max(0, Number.isFinite(state.missionCostUsd) ? Number(state.missionCostUsd) : 0)
|
|
309
300
|
state.skillBlocker = normalizeSkillBlocker(state.skillBlocker)
|
|
310
301
|
state.updatedAt = typeof state.updatedAt === 'number' && Number.isFinite(state.updatedAt) ? Math.trunc(state.updatedAt) : now()
|
|
311
302
|
return state
|
|
@@ -325,15 +316,12 @@ function normalizeState(input?: Partial<MainLoopState> | null): MainLoopState {
|
|
|
325
316
|
if (typeof input.reviewConfidence === 'number' || typeof input.reviewConfidence === 'string' || input.reviewConfidence === null) {
|
|
326
317
|
next.reviewConfidence = normalizeConfidence(input.reviewConfidence)
|
|
327
318
|
}
|
|
328
|
-
if (typeof input.missionTaskId === 'string' || input.missionTaskId === null) next.missionTaskId = input.missionTaskId
|
|
329
319
|
if (typeof input.momentumScore === 'number') next.momentumScore = input.momentumScore
|
|
330
320
|
if (typeof input.paused === 'boolean') next.paused = input.paused
|
|
331
321
|
if (input.status) next.status = normalizeStatus(input.status, next.status)
|
|
332
322
|
if (input.autonomyMode) next.autonomyMode = normalizeAutonomyMode(input.autonomyMode, next.autonomyMode)
|
|
333
323
|
if (Array.isArray(input.pendingEvents)) next.pendingEvents = [...input.pendingEvents]
|
|
334
324
|
if (Array.isArray(input.timeline)) next.timeline = [...input.timeline]
|
|
335
|
-
if (typeof input.missionTokens === 'number') next.missionTokens = input.missionTokens
|
|
336
|
-
if (typeof input.missionCostUsd === 'number') next.missionCostUsd = input.missionCostUsd
|
|
337
325
|
if (typeof input.followupChainCount === 'number') next.followupChainCount = input.followupChainCount
|
|
338
326
|
if (typeof input.lifetimeIterations === 'number') next.lifetimeIterations = input.lifetimeIterations
|
|
339
327
|
if (typeof input.metaMissCount === 'number') next.metaMissCount = input.metaMissCount
|
|
@@ -435,10 +423,8 @@ function persistState(sessionId: string, state: MainLoopState): void {
|
|
|
435
423
|
upsertPersistedMainLoopState(sessionId, normalized as unknown as Record<string, unknown>)
|
|
436
424
|
const session = getSession(sessionId)
|
|
437
425
|
if (!session) return
|
|
438
|
-
const mission = getMissionForSession(session)
|
|
439
426
|
void syncWorkingStateFromMainLoopState({
|
|
440
427
|
sessionId,
|
|
441
|
-
mission,
|
|
442
428
|
goal: normalized.goal,
|
|
443
429
|
summary: normalized.summary,
|
|
444
430
|
status: normalized.status === 'ok'
|
|
@@ -797,11 +783,6 @@ export function buildMainLoopHeartbeatPrompt(session: unknown, fallbackPrompt: s
|
|
|
797
783
|
const candidate = asSession(session)
|
|
798
784
|
if (!candidate?.id) return fallbackPrompt
|
|
799
785
|
const persistedSession = getSession(String(candidate.id)) as Session | undefined
|
|
800
|
-
const missionPrompt = buildMissionHeartbeatPromptFromMission(
|
|
801
|
-
persistedSession || candidate as Session,
|
|
802
|
-
fallbackPrompt,
|
|
803
|
-
)
|
|
804
|
-
if (missionPrompt) return missionPrompt
|
|
805
786
|
const state = getOrCreateState(String(candidate.id))
|
|
806
787
|
if (!state) return fallbackPrompt
|
|
807
788
|
const latestExternalGoal = extractLatestGoal(Array.isArray(candidate.messages) ? candidate.messages as Message[] : [])
|
|
@@ -812,7 +793,6 @@ export function buildMainLoopHeartbeatPrompt(session: unknown, fallbackPrompt: s
|
|
|
812
793
|
const heartbeatSession = (persistedSession || candidate as Session)
|
|
813
794
|
const executionBrief = buildExecutionBrief({
|
|
814
795
|
session: heartbeatSession,
|
|
815
|
-
mission: getMissionForSession(heartbeatSession),
|
|
816
796
|
})
|
|
817
797
|
const executionBriefBlock = buildExecutionBriefContextBlock(executionBrief)
|
|
818
798
|
const boundedFallbackPrompt = cleanMultiline(fallbackPrompt, 500)
|
|
@@ -969,8 +949,6 @@ export function handleMainLoopRunResult(input: HandleMainLoopRunResultInput): Ma
|
|
|
969
949
|
const messageGoal = shouldCaptureMessageGoal ? parseGoalContractFromText(input.message || '') : null
|
|
970
950
|
const nowTs = now()
|
|
971
951
|
state.lifetimeIterations++
|
|
972
|
-
const mission = session ? getMissionForSession(session) : null
|
|
973
|
-
|
|
974
952
|
if (messageGoal) state.goalContract = mergeGoalContracts(state.goalContract, messageGoal)
|
|
975
953
|
if (!state.goal && shouldCaptureMessageGoal) state.goal = cleanMultiline(input.message, 900)
|
|
976
954
|
if (heartbeat?.goal) state.goal = heartbeat.goal
|
|
@@ -1011,8 +989,6 @@ export function handleMainLoopRunResult(input: HandleMainLoopRunResultInput): Ma
|
|
|
1011
989
|
|
|
1012
990
|
state.lastTickAt = nowTs
|
|
1013
991
|
state.updatedAt = nowTs
|
|
1014
|
-
state.missionTokens += Math.max(0, Math.trunc((input.inputTokens || 0) + (input.outputTokens || 0)))
|
|
1015
|
-
state.missionCostUsd += Math.max(0, Number(input.estimatedCost || 0))
|
|
1016
992
|
const cleanedResult = persistedText.trim()
|
|
1017
993
|
const waitingForExternal = extractWaitSignal(resultText)
|
|
1018
994
|
const gotTerminalAck = /^HEARTBEAT_OK$/i.test(cleanedResult) || /^NO_MESSAGE$/i.test(cleanedResult)
|
|
@@ -1073,32 +1049,8 @@ export function handleMainLoopRunResult(input: HandleMainLoopRunResultInput): Ma
|
|
|
1073
1049
|
const needsReplan = review?.needs_replan === true || ((review?.confidence ?? 1) < 0.45)
|
|
1074
1050
|
const limit = followupLimit(input.sessionId)
|
|
1075
1051
|
|
|
1076
|
-
if (mission) {
|
|
1077
|
-
state.goal = cleanMultiline(mission.objective, 900)
|
|
1078
|
-
state.missionTaskId = mission.rootTaskId || null
|
|
1079
|
-
state.summary = cleanMultiline(mission.verifierSummary || mission.plannerSummary || state.summary, 500)
|
|
1080
|
-
state.nextAction = cleanText(mission.currentStep, 280) || null
|
|
1081
|
-
state.currentPlanStep = cleanText(mission.currentStep, 280) || null
|
|
1082
|
-
state.planSteps = mission.currentStep ? [mission.currentStep] : []
|
|
1083
|
-
state.status = mission.status === 'completed'
|
|
1084
|
-
? 'ok'
|
|
1085
|
-
: mission.status === 'waiting' || mission.status === 'failed' || mission.status === 'cancelled'
|
|
1086
|
-
? 'blocked'
|
|
1087
|
-
: 'progress'
|
|
1088
|
-
state.paused = mission.status === 'waiting' || mission.status === 'failed' || mission.status === 'cancelled'
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
1052
|
let followup: MainLoopFollowupRequest | null = null
|
|
1092
|
-
if (
|
|
1093
|
-
state.followupChainCount = 0
|
|
1094
|
-
if (mission.status === 'completed') {
|
|
1095
|
-
state.status = 'ok'
|
|
1096
|
-
state.paused = false
|
|
1097
|
-
}
|
|
1098
|
-
if (mission.status === 'waiting' || mission.status === 'failed' || mission.status === 'cancelled') {
|
|
1099
|
-
state.paused = true
|
|
1100
|
-
}
|
|
1101
|
-
} else if (isDirectUserChat) {
|
|
1053
|
+
if (isDirectUserChat) {
|
|
1102
1054
|
state.followupChainCount = 0
|
|
1103
1055
|
state.lifetimeIterations = 0
|
|
1104
1056
|
if (successfulChatDelivery) {
|
|
@@ -237,7 +237,6 @@ async function spawnSubagentImpl(
|
|
|
237
237
|
const job = createDelegationJob({
|
|
238
238
|
kind: 'subagent',
|
|
239
239
|
parentSessionId: context.sessionId || null,
|
|
240
|
-
parentMissionId: typeof parent?.missionId === 'string' ? parent.missionId : null,
|
|
241
240
|
agentId: input.agentId,
|
|
242
241
|
task: input.message,
|
|
243
242
|
cwd: input.cwd || context.cwd,
|
|
@@ -34,80 +34,6 @@ function canonicalizeValue(value: unknown): unknown {
|
|
|
34
34
|
}, {})
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function canonicalizeEthereumTransaction(value: unknown): Record<string, unknown> | null {
|
|
38
|
-
if (!isPlainRecord(value)) return null
|
|
39
|
-
const tx = value
|
|
40
|
-
const comparable: Record<string, unknown> = {}
|
|
41
|
-
const to = trimString(tx.to)
|
|
42
|
-
const data = trimString(tx.data)
|
|
43
|
-
const valueAtomic = tx.value
|
|
44
|
-
const type = normalizeScalar(tx.type)
|
|
45
|
-
const chainId = normalizeScalar(tx.chainId)
|
|
46
|
-
|
|
47
|
-
if (to) comparable.to = /^0x[0-9a-f]+$/i.test(to) ? to.toLowerCase() : to
|
|
48
|
-
if (data) comparable.data = /^0x[0-9a-f]+$/i.test(data) ? data.toLowerCase() : data
|
|
49
|
-
if (valueAtomic !== undefined && valueAtomic !== null && valueAtomic !== '') comparable.value = normalizeScalar(valueAtomic)
|
|
50
|
-
if (type !== null && type !== undefined && type !== '') comparable.type = type
|
|
51
|
-
if (chainId !== null && chainId !== undefined && chainId !== '') comparable.chainId = chainId
|
|
52
|
-
|
|
53
|
-
return Object.keys(comparable).length > 0 ? comparable : null
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function comparableWalletActionPayload(data: Record<string, unknown>): Record<string, unknown> {
|
|
57
|
-
const action = trimString(data.action)
|
|
58
|
-
const chain = trimString(data.chain)
|
|
59
|
-
const network = trimString(data.network)
|
|
60
|
-
const payload: Record<string, unknown> = {
|
|
61
|
-
action,
|
|
62
|
-
chain,
|
|
63
|
-
network,
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const transaction = canonicalizeEthereumTransaction(data.transaction)
|
|
67
|
-
if (transaction) payload.transaction = transaction
|
|
68
|
-
|
|
69
|
-
const signedTransactionFingerprint = trimString(data.signedTransactionFingerprint)
|
|
70
|
-
if (signedTransactionFingerprint) payload.signedTransactionFingerprint = signedTransactionFingerprint
|
|
71
|
-
|
|
72
|
-
const transactionFingerprint = trimString(data.transactionFingerprint)
|
|
73
|
-
if (transactionFingerprint) payload.transactionFingerprint = transactionFingerprint
|
|
74
|
-
|
|
75
|
-
const messageDigest = trimString(data.messageDigest)
|
|
76
|
-
if (messageDigest) payload.messageDigest = messageDigest
|
|
77
|
-
|
|
78
|
-
const domain = canonicalizeValue(data.domain)
|
|
79
|
-
if (domain && typeof domain === 'object') payload.domain = domain
|
|
80
|
-
|
|
81
|
-
const types = canonicalizeValue(data.types)
|
|
82
|
-
if (types && typeof types === 'object') payload.types = types
|
|
83
|
-
|
|
84
|
-
const value = canonicalizeValue(data.value)
|
|
85
|
-
if (value && typeof value === 'object') payload.value = value
|
|
86
|
-
|
|
87
|
-
const toAddress = trimString(data.toAddress)
|
|
88
|
-
if (toAddress) payload.toAddress = /^0x[0-9a-f]+$/i.test(toAddress) ? toAddress.toLowerCase() : toAddress
|
|
89
|
-
|
|
90
|
-
const amountAtomic = normalizeScalar(data.amountAtomic)
|
|
91
|
-
if (amountAtomic !== null && amountAtomic !== undefined && amountAtomic !== '') payload.amountAtomic = amountAtomic
|
|
92
|
-
|
|
93
|
-
const sellToken = trimString(data.sellToken)
|
|
94
|
-
if (sellToken) payload.sellToken = /^0x[0-9a-f]+$/i.test(sellToken) ? sellToken.toLowerCase() : sellToken
|
|
95
|
-
|
|
96
|
-
const buyToken = trimString(data.buyToken)
|
|
97
|
-
if (buyToken) payload.buyToken = /^0x[0-9a-f]+$/i.test(buyToken) ? buyToken.toLowerCase() : buyToken
|
|
98
|
-
|
|
99
|
-
const recipient = trimString(data.recipient)
|
|
100
|
-
if (recipient) payload.recipient = /^0x[0-9a-f]+$/i.test(recipient) ? recipient.toLowerCase() : recipient
|
|
101
|
-
|
|
102
|
-
const routeProvider = trimString(data.routeProvider)
|
|
103
|
-
if (routeProvider) payload.routeProvider = routeProvider
|
|
104
|
-
|
|
105
|
-
const slippageBps = normalizeScalar(data.slippageBps)
|
|
106
|
-
if (slippageBps !== null && slippageBps !== undefined && slippageBps !== '') payload.slippageBps = slippageBps
|
|
107
|
-
|
|
108
|
-
return payload
|
|
109
|
-
}
|
|
110
|
-
|
|
111
37
|
export function buildApprovalComparablePayload(
|
|
112
38
|
category: ApprovalCategory,
|
|
113
39
|
data: Record<string, unknown>,
|
|
@@ -128,17 +54,6 @@ export function buildApprovalComparablePayload(
|
|
|
128
54
|
extensionId: trimString(data.extensionId),
|
|
129
55
|
filename: trimString(data.filename),
|
|
130
56
|
}
|
|
131
|
-
case 'wallet_transfer': {
|
|
132
|
-
const toAddress = trimString(data.toAddress)
|
|
133
|
-
return {
|
|
134
|
-
chain: trimString(data.chain),
|
|
135
|
-
toAddress: /^0x[0-9a-f]+$/i.test(toAddress) ? toAddress.toLowerCase() : toAddress,
|
|
136
|
-
amountAtomic: normalizeScalar(data.amountAtomic),
|
|
137
|
-
memo: trimString(data.memo),
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
case 'wallet_action':
|
|
141
|
-
return comparableWalletActionPayload(data)
|
|
142
57
|
case 'human_loop':
|
|
143
58
|
return {
|
|
144
59
|
question: trimString(data.question),
|
|
@@ -56,19 +56,19 @@ describe('approvals', () => {
|
|
|
56
56
|
title: 'Human approval',
|
|
57
57
|
data: { question: 'Proceed?' },
|
|
58
58
|
})
|
|
59
|
-
const
|
|
60
|
-
category: '
|
|
61
|
-
title: '
|
|
62
|
-
data: {
|
|
59
|
+
const other = approvals.requestApproval({
|
|
60
|
+
category: 'human_loop',
|
|
61
|
+
title: 'Another approval',
|
|
62
|
+
data: { question: 'Continue?' },
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
await approvals.submitDecision(
|
|
65
|
+
await approvals.submitDecision(other.id, true)
|
|
66
66
|
|
|
67
67
|
const pending = approvals.listPendingApprovals()
|
|
68
68
|
const humanPending = approvals.listPendingApprovals('human_loop')
|
|
69
69
|
|
|
70
70
|
assert.equal(pending.some((entry) => entry.id === human.id), true)
|
|
71
|
-
assert.equal(pending.some((entry) => entry.id ===
|
|
71
|
+
assert.equal(pending.some((entry) => entry.id === other.id), false)
|
|
72
72
|
assert.equal(humanPending.some((entry) => entry.id === human.id), true)
|
|
73
73
|
assert.equal(humanPending.every((entry) => entry.category === 'human_loop'), true)
|
|
74
74
|
})
|
|
@@ -5,7 +5,6 @@ import { notify } from './ws-hub'
|
|
|
5
5
|
import { dispatchWake } from '@/lib/server/runtime/wake-dispatcher'
|
|
6
6
|
import { enqueueSystemEvent } from '@/lib/server/runtime/system-events'
|
|
7
7
|
import { enqueueSessionRun } from '@/lib/server/runtime/session-run-manager'
|
|
8
|
-
import { requestMissionTicksForApprovalDecision } from '@/lib/server/missions/mission-service'
|
|
9
8
|
|
|
10
9
|
function trimToString(value: unknown): string {
|
|
11
10
|
return typeof value === 'string' ? value.trim() : ''
|
|
@@ -122,11 +121,6 @@ async function persistApprovalDecision(request: ApprovalRequest, approved: boole
|
|
|
122
121
|
// best-effort trigger only
|
|
123
122
|
})
|
|
124
123
|
if (request.sessionId) notify(`session:${request.sessionId}`)
|
|
125
|
-
requestMissionTicksForApprovalDecision({
|
|
126
|
-
approvalId: request.id,
|
|
127
|
-
status: approved ? 'approved' : 'rejected',
|
|
128
|
-
sessionId: request.sessionId || null,
|
|
129
|
-
})
|
|
130
124
|
return request
|
|
131
125
|
}
|
|
132
126
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import '@/lib/server/session-tools/shell'
|
|
2
|
+
import '@/lib/server/session-tools/execute'
|
|
2
3
|
import '@/lib/server/session-tools/file'
|
|
3
4
|
import '@/lib/server/session-tools/edit_file'
|
|
4
5
|
import '@/lib/server/session-tools/web'
|
|
@@ -6,10 +7,8 @@ import '@/lib/server/session-tools/memory'
|
|
|
6
7
|
import '@/lib/server/session-tools/platform'
|
|
7
8
|
import '@/lib/server/session-tools/monitor'
|
|
8
9
|
import '@/lib/server/session-tools/discovery'
|
|
9
|
-
import '@/lib/server/session-tools/wallet'
|
|
10
10
|
import '@/lib/server/session-tools/connector'
|
|
11
11
|
// http_request consolidated into web 'api' action
|
|
12
|
-
import '@/lib/server/session-tools/canvas'
|
|
13
12
|
import '@/lib/server/session-tools/chatroom'
|
|
14
13
|
import '@/lib/server/session-tools/delegate'
|
|
15
14
|
import '@/lib/server/session-tools/schedule'
|
|
@@ -80,7 +80,6 @@ test('routeTaskIntent uses structured classification when available', () => {
|
|
|
80
80
|
taskIntent: 'browsing',
|
|
81
81
|
isDeliverableTask: true,
|
|
82
82
|
isBroadGoal: false,
|
|
83
|
-
walletIntent: 'none',
|
|
84
83
|
hasHumanSignals: false,
|
|
85
84
|
hasSignificantEvent: false,
|
|
86
85
|
isResearchSynthesis: true,
|
|
@@ -108,7 +107,6 @@ function makeClassification(overrides: Partial<MessageClassification>): MessageC
|
|
|
108
107
|
taskIntent: 'general',
|
|
109
108
|
isDeliverableTask: false,
|
|
110
109
|
isBroadGoal: false,
|
|
111
|
-
walletIntent: 'none',
|
|
112
110
|
hasHumanSignals: false,
|
|
113
111
|
hasSignificantEvent: false,
|
|
114
112
|
isResearchSynthesis: false,
|
|
@@ -470,7 +470,7 @@ describe('hasDirectLocalCodingTools', () => {
|
|
|
470
470
|
assert.equal(hasDirectLocalCodingTools({ tools: ['files'] }), true)
|
|
471
471
|
})
|
|
472
472
|
|
|
473
|
-
it('returns true for sandbox
|
|
473
|
+
it('returns true for legacy sandbox alias', () => {
|
|
474
474
|
assert.equal(hasDirectLocalCodingTools({ tools: ['sandbox'] }), true)
|
|
475
475
|
})
|
|
476
476
|
})
|
|
@@ -108,31 +108,31 @@ describe('collectToolEvent', () => {
|
|
|
108
108
|
const bag: MessageToolEvent[] = []
|
|
109
109
|
collectToolEvent({
|
|
110
110
|
t: 'tool_call',
|
|
111
|
-
toolName: '
|
|
112
|
-
toolInput: '{"
|
|
113
|
-
toolCallId: 'call-
|
|
111
|
+
toolName: 'http_request',
|
|
112
|
+
toolInput: '{"method":"GET","url":"https://api-a.example.com"}',
|
|
113
|
+
toolCallId: 'call-a',
|
|
114
114
|
}, bag)
|
|
115
115
|
collectToolEvent({
|
|
116
116
|
t: 'tool_call',
|
|
117
|
-
toolName: '
|
|
118
|
-
toolInput: '{"
|
|
119
|
-
toolCallId: 'call-
|
|
117
|
+
toolName: 'http_request',
|
|
118
|
+
toolInput: '{"method":"GET","url":"https://api-b.example.com"}',
|
|
119
|
+
toolCallId: 'call-b',
|
|
120
120
|
}, bag)
|
|
121
121
|
collectToolEvent({
|
|
122
122
|
t: 'tool_result',
|
|
123
|
-
toolName: '
|
|
124
|
-
toolOutput: '{"
|
|
125
|
-
toolCallId: 'call-
|
|
123
|
+
toolName: 'http_request',
|
|
124
|
+
toolOutput: '{"source":"api-a"}',
|
|
125
|
+
toolCallId: 'call-a',
|
|
126
126
|
}, bag)
|
|
127
127
|
collectToolEvent({
|
|
128
128
|
t: 'tool_result',
|
|
129
|
-
toolName: '
|
|
130
|
-
toolOutput: '{"
|
|
131
|
-
toolCallId: 'call-
|
|
129
|
+
toolName: 'http_request',
|
|
130
|
+
toolOutput: '{"source":"api-b"}',
|
|
131
|
+
toolCallId: 'call-b',
|
|
132
132
|
}, bag)
|
|
133
133
|
|
|
134
|
-
assert.equal(bag[0].output, '{"
|
|
135
|
-
assert.equal(bag[1].output, '{"
|
|
134
|
+
assert.equal(bag[0].output, '{"source":"api-a"}')
|
|
135
|
+
assert.equal(bag[1].output, '{"source":"api-b"}')
|
|
136
136
|
})
|
|
137
137
|
})
|
|
138
138
|
|
|
@@ -259,6 +259,7 @@ describe('hasDirectLocalCodingTools', () => {
|
|
|
259
259
|
it('treats shell and file tooling as local coding capability', () => {
|
|
260
260
|
assert.equal(hasDirectLocalCodingTools({ extensions: ['files'] }), true)
|
|
261
261
|
assert.equal(hasDirectLocalCodingTools({ extensions: ['shell'] }), true)
|
|
262
|
+
assert.equal(hasDirectLocalCodingTools({ extensions: ['execute'] }), true)
|
|
262
263
|
assert.equal(hasDirectLocalCodingTools({ extensions: ['edit_file'] }), true)
|
|
263
264
|
assert.equal(hasDirectLocalCodingTools({ extensions: ['delegate'] }), false)
|
|
264
265
|
})
|
|
@@ -3,7 +3,6 @@ import type { MessageToolEvent, SSEEvent } from '@/types'
|
|
|
3
3
|
export interface ExecuteChatTurnInput {
|
|
4
4
|
sessionId: string
|
|
5
5
|
message: string
|
|
6
|
-
missionId?: string | null
|
|
7
6
|
imagePath?: string
|
|
8
7
|
imageUrl?: string
|
|
9
8
|
attachedFiles?: string[]
|
|
@@ -27,7 +26,6 @@ export interface ExecuteChatTurnInput {
|
|
|
27
26
|
export interface ExecuteChatTurnResult {
|
|
28
27
|
runId?: string
|
|
29
28
|
sessionId: string
|
|
30
|
-
missionId?: string | null
|
|
31
29
|
text: string
|
|
32
30
|
persisted: boolean
|
|
33
31
|
toolEvents: MessageToolEvent[]
|
|
@@ -321,11 +321,8 @@ export function requestedToolNamesFromMessage(message: string): string[] {
|
|
|
321
321
|
'memory_get',
|
|
322
322
|
'memory_store',
|
|
323
323
|
'memory_update',
|
|
324
|
-
'wallet_tool',
|
|
325
324
|
'http_request',
|
|
326
325
|
'send_file',
|
|
327
|
-
'sandbox_exec',
|
|
328
|
-
'sandbox_list_runtimes',
|
|
329
326
|
'schedule_wake',
|
|
330
327
|
'spawn_subagent',
|
|
331
328
|
'ask_human',
|
|
@@ -338,9 +335,9 @@ export function requestedToolNamesFromMessage(message: string): string[] {
|
|
|
338
335
|
'browser',
|
|
339
336
|
'web',
|
|
340
337
|
'shell',
|
|
338
|
+
'execute',
|
|
341
339
|
'files',
|
|
342
340
|
'edit_file',
|
|
343
|
-
'canvas',
|
|
344
341
|
'mailbox',
|
|
345
342
|
'email',
|
|
346
343
|
]
|
|
@@ -370,6 +367,7 @@ export function enabledDelegationTools(session: SessionWithTools): DelegateTool[
|
|
|
370
367
|
export function hasDirectLocalCodingTools(session: SessionWithTools): boolean {
|
|
371
368
|
return [
|
|
372
369
|
'shell',
|
|
370
|
+
'execute',
|
|
373
371
|
'execute_command',
|
|
374
372
|
'files',
|
|
375
373
|
'edit_file',
|
|
@@ -72,22 +72,14 @@ export function getExplicitRequiredToolNames(userMessage: string, enabledExtensi
|
|
|
72
72
|
return required
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export function shouldForceExternalServiceSummary(
|
|
75
|
+
export function shouldForceExternalServiceSummary(_params: {
|
|
76
76
|
userMessage: string
|
|
77
77
|
finalResponse: string
|
|
78
78
|
hasToolCalls: boolean
|
|
79
79
|
toolEventCount: number
|
|
80
80
|
classification?: MessageClassification | null
|
|
81
81
|
}): boolean {
|
|
82
|
-
|
|
83
|
-
&& params.classification.walletIntent !== 'none'
|
|
84
|
-
if (!walletDetected) return false
|
|
85
|
-
if (!params.hasToolCalls || params.toolEventCount === 0) return false
|
|
86
|
-
const trimmed = params.finalResponse.trim()
|
|
87
|
-
if (!trimmed) return true
|
|
88
|
-
if (/\b(blocker|blocked|cannot|can't|requires|need|missing|last reversible step|next step)\b/i.test(trimmed)) return false
|
|
89
|
-
if (trimmed.length >= 240 && !/(let me|i'll|i will|checking|verify|promising|look into|explore|access their interface)/i.test(trimmed)) return false
|
|
90
|
-
return /:$/.test(trimmed) || /(let me|i'll|i will|checking|verify|promising|look into|explore|access their interface)/i.test(trimmed) || trimmed.length < 240
|
|
82
|
+
return false
|
|
91
83
|
}
|
|
92
84
|
|
|
93
85
|
export type TerminalToolBoundary =
|
|
@@ -146,26 +138,6 @@ export function resolveSuccessfulTerminalToolBoundary(params: {
|
|
|
146
138
|
return null
|
|
147
139
|
}
|
|
148
140
|
|
|
149
|
-
export function getWalletApprovalBoundaryAction(output: string): string | null {
|
|
150
|
-
if (!output.includes('extension_wallet_')) return null
|
|
151
|
-
if (/"type":"extension_wallet_transfer_request"/.test(output)) return 'send'
|
|
152
|
-
const actionMatch = output.match(/"action":"([^"]+)"/)
|
|
153
|
-
const action = actionMatch?.[1] || ''
|
|
154
|
-
if (!action) return null
|
|
155
|
-
const readOnlyActions = new Set([
|
|
156
|
-
'balance',
|
|
157
|
-
'address',
|
|
158
|
-
'transactions',
|
|
159
|
-
'encode_contract_call',
|
|
160
|
-
'simulate_transaction',
|
|
161
|
-
])
|
|
162
|
-
return readOnlyActions.has(action) ? null : action
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function isWalletSimulationResult(toolName: string, output: string): boolean {
|
|
166
|
-
return toolName === 'wallet_tool' && /"status":"simulated"/.test(output)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
141
|
export function updateStreamedToolEvents(
|
|
170
142
|
events: MessageToolEvent[],
|
|
171
143
|
event: { type: 'call' | 'result'; name: string; input?: string; output?: string; toolCallId?: string },
|
|
@@ -26,9 +26,6 @@ import { estimateCost } from '@/lib/server/cost'
|
|
|
26
26
|
import { refreshSessionIdentityState } from '@/lib/server/identity-continuity'
|
|
27
27
|
import { log } from '@/lib/server/logger'
|
|
28
28
|
import { syncSessionArchiveMemory } from '@/lib/server/memory/session-archive-memory'
|
|
29
|
-
import {
|
|
30
|
-
applyMissionOutcomeForTurn,
|
|
31
|
-
} from '@/lib/server/missions/mission-service'
|
|
32
29
|
import { runCapabilityHook, transformCapabilityText } from '@/lib/server/native-capabilities'
|
|
33
30
|
import { isHeartbeatSource } from '@/lib/server/runtime/heartbeat-source'
|
|
34
31
|
import { perf } from '@/lib/server/runtime/perf'
|
|
@@ -181,7 +178,6 @@ export async function finalizeChatTurn(params: {
|
|
|
181
178
|
sessionForRun,
|
|
182
179
|
appSettings,
|
|
183
180
|
lifecycleRunId,
|
|
184
|
-
mission,
|
|
185
181
|
extensionsForRun,
|
|
186
182
|
effectiveMessage,
|
|
187
183
|
providerType,
|
|
@@ -589,45 +585,15 @@ export async function finalizeChatTurn(params: {
|
|
|
589
585
|
}
|
|
590
586
|
|
|
591
587
|
refreshSessionIdentityState(current, currentAgent)
|
|
592
|
-
let resolvedMissionId = mission?.id || current.missionId || null
|
|
593
|
-
let updatedMission = mission || null
|
|
594
|
-
if (resolvedMissionId) {
|
|
595
|
-
updatedMission = await applyMissionOutcomeForTurn({
|
|
596
|
-
session: current,
|
|
597
|
-
missionId: resolvedMissionId,
|
|
598
|
-
source,
|
|
599
|
-
runId: lifecycleRunId,
|
|
600
|
-
message,
|
|
601
|
-
assistantText: hiddenControlOnly ? '' : textForPersistence,
|
|
602
|
-
error: errorMessage || null,
|
|
603
|
-
toolEvents: persistedToolEvents,
|
|
604
|
-
})
|
|
605
|
-
if (updatedMission?.id) {
|
|
606
|
-
resolvedMissionId = updatedMission.id
|
|
607
|
-
current.missionId = updatedMission.id
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
const missionStateChanged = Boolean(
|
|
611
|
-
updatedMission
|
|
612
|
-
&& (
|
|
613
|
-
updatedMission.id !== mission?.id
|
|
614
|
-
|| updatedMission.updatedAt !== mission?.updatedAt
|
|
615
|
-
|| updatedMission.status !== mission?.status
|
|
616
|
-
|| updatedMission.phase !== mission?.phase
|
|
617
|
-
|| updatedMission.currentStep !== mission?.currentStep
|
|
618
|
-
|| updatedMission.waitState?.reason !== mission?.waitState?.reason
|
|
619
|
-
)
|
|
620
|
-
)
|
|
621
588
|
const shouldSyncWorkingState = (
|
|
622
589
|
(!isHeartbeatRun && (assistantPersisted || persistedToolEvents.length > 0 || Boolean(errorMessage)))
|
|
623
|
-
|| (isHeartbeatRun && (persistedToolEvents.length > 0 || Boolean(errorMessage)
|
|
590
|
+
|| (isHeartbeatRun && (persistedToolEvents.length > 0 || Boolean(errorMessage)))
|
|
624
591
|
)
|
|
625
592
|
if (shouldSyncWorkingState) {
|
|
626
593
|
try {
|
|
627
594
|
await synchronizeWorkingStateForTurn({
|
|
628
595
|
sessionId,
|
|
629
596
|
agentId: current.agentId || null,
|
|
630
|
-
mission: updatedMission,
|
|
631
597
|
message,
|
|
632
598
|
assistantText: hiddenControlOnly ? '' : textForPersistence,
|
|
633
599
|
error: errorMessage || null,
|
|
@@ -673,7 +639,6 @@ export async function finalizeChatTurn(params: {
|
|
|
673
639
|
return {
|
|
674
640
|
runId,
|
|
675
641
|
sessionId,
|
|
676
|
-
missionId: mission?.id || null,
|
|
677
642
|
text: hiddenControlOnly ? '' : textForPersistence,
|
|
678
643
|
persisted: assistantPersisted,
|
|
679
644
|
toolEvents: persistedToolEvents,
|