agentfootprint 10.3.1 → 10.4.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/AGENTS.md +2 -2
- package/CAPABILITIES.md +6 -0
- package/README.md +44 -0
- package/ai-instructions/claude-code/SKILL.md +2 -2
- package/dist/adapters/mcp/agentcoreRuntime/errorType.js +24 -0
- package/dist/adapters/mcp/agentcoreRuntime/errorType.js.map +1 -0
- package/dist/adapters/mcp/agentcoreRuntime/invoke.js +265 -0
- package/dist/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -0
- package/dist/adapters/mcp/agentcoreRuntime/safeAnswer.js +415 -0
- package/dist/adapters/mcp/agentcoreRuntime/safeAnswer.js.map +1 -0
- package/dist/adapters/mcp/agentcoreRuntime/session.js +179 -0
- package/dist/adapters/mcp/agentcoreRuntime/session.js.map +1 -0
- package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js +117 -0
- package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -0
- package/dist/adapters/mcp/agentcoreRuntime/strictJson.js +220 -0
- package/dist/adapters/mcp/agentcoreRuntime/strictJson.js.map +1 -0
- package/dist/adapters/mcp/agentcoreRuntime/transport.js +204 -0
- package/dist/adapters/mcp/agentcoreRuntime/transport.js.map +1 -0
- package/dist/adapters/memory/agentcore.js +435 -20
- package/dist/adapters/memory/agentcore.js.map +1 -1
- package/dist/adapters/memory/memoryBank.js +16 -3
- package/dist/adapters/memory/memoryBank.js.map +1 -1
- package/dist/adapters/memory/pgVector.js +10 -4
- package/dist/adapters/memory/pgVector.js.map +1 -1
- package/dist/adapters/memory/redis.js +11 -3
- package/dist/adapters/memory/redis.js.map +1 -1
- package/dist/adapters/memory/s3Vectors.js +8 -3
- package/dist/adapters/memory/s3Vectors.js.map +1 -1
- package/dist/adapters/memory/sqliteVector.js +10 -4
- package/dist/adapters/memory/sqliteVector.js.map +1 -1
- package/dist/ag-ui/adapter.js +71 -0
- package/dist/ag-ui/adapter.js.map +1 -0
- package/dist/ag-ui/framing.js +66 -0
- package/dist/ag-ui/framing.js.map +1 -0
- package/dist/ag-ui/frontendTools.js +69 -0
- package/dist/ag-ui/frontendTools.js.map +1 -0
- package/dist/ag-ui/ids.js +54 -0
- package/dist/ag-ui/ids.js.map +1 -0
- package/dist/ag-ui/index.js +27 -0
- package/dist/ag-ui/index.js.map +1 -0
- package/dist/ag-ui/request.js +356 -0
- package/dist/ag-ui/request.js.map +1 -0
- package/dist/ag-ui/serializer.js +899 -0
- package/dist/ag-ui/serializer.js.map +1 -0
- package/dist/ag-ui/types.js +22 -0
- package/dist/ag-ui/types.js.map +1 -0
- package/dist/core/Agent.js +38 -5
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/RunnerBase.js +16 -2
- package/dist/core/RunnerBase.js.map +1 -1
- package/dist/core/agent/buildAgentChart.js +4 -0
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +4 -0
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/callerIdentity.js +2 -1
- package/dist/core/agent/callerIdentity.js.map +1 -1
- package/dist/core/agent/stages/routeTurn.js +3 -3
- package/dist/core/agent/stages/routeTurn.js.map +1 -1
- package/dist/core/agent/stages/seed.js +49 -8
- package/dist/core/agent/stages/seed.js.map +1 -1
- package/dist/core/agent/stages/timeLayer.js +2 -2
- package/dist/core/agent/stages/timeLayer.js.map +1 -1
- package/dist/core/agent/stages/toolCalls.js +26 -5
- package/dist/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/core/memberRun.js +244 -0
- package/dist/core/memberRun.js.map +1 -0
- package/dist/core/slots/buildToolsSlot.js +1 -1
- package/dist/core/slots/buildToolsSlot.js.map +1 -1
- package/dist/core-flow/Conditional.js +29 -8
- package/dist/core-flow/Conditional.js.map +1 -1
- package/dist/core-flow/Graph.js +38 -13
- package/dist/core-flow/Graph.js.map +1 -1
- package/dist/core-flow/Loop.js +29 -9
- package/dist/core-flow/Loop.js.map +1 -1
- package/dist/core-flow/Parallel.js +35 -14
- package/dist/core-flow/Parallel.js.map +1 -1
- package/dist/core-flow/Sequence.js +29 -8
- package/dist/core-flow/Sequence.js.map +1 -1
- package/dist/core-flow/Workflow.js +34 -10
- package/dist/core-flow/Workflow.js.map +1 -1
- package/dist/doors/ag-ui.js +36 -0
- package/dist/doors/ag-ui.js.map +1 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/errorType.d.ts +12 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/errorType.js +20 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/errorType.js.map +1 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.d.ts +116 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js +260 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/safeAnswer.d.ts +49 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/safeAnswer.js +409 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/safeAnswer.js.map +1 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/session.d.ts +80 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/session.js +175 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/session.js.map +1 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +61 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js +112 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/strictJson.d.ts +37 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/strictJson.js +215 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/strictJson.js.map +1 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.d.ts +176 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js +199 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js.map +1 -0
- package/dist/esm/adapters/memory/agentcore.d.ts +152 -7
- package/dist/esm/adapters/memory/agentcore.js +433 -19
- package/dist/esm/adapters/memory/agentcore.js.map +1 -1
- package/dist/esm/adapters/memory/memoryBank.d.ts +3 -2
- package/dist/esm/adapters/memory/memoryBank.js +16 -3
- package/dist/esm/adapters/memory/memoryBank.js.map +1 -1
- package/dist/esm/adapters/memory/pgVector.js +10 -4
- package/dist/esm/adapters/memory/pgVector.js.map +1 -1
- package/dist/esm/adapters/memory/redis.d.ts +8 -3
- package/dist/esm/adapters/memory/redis.js +11 -3
- package/dist/esm/adapters/memory/redis.js.map +1 -1
- package/dist/esm/adapters/memory/s3Vectors.js +8 -3
- package/dist/esm/adapters/memory/s3Vectors.js.map +1 -1
- package/dist/esm/adapters/memory/sqliteVector.js +10 -4
- package/dist/esm/adapters/memory/sqliteVector.js.map +1 -1
- package/dist/esm/ag-ui/adapter.d.ts +68 -0
- package/dist/esm/ag-ui/adapter.js +67 -0
- package/dist/esm/ag-ui/adapter.js.map +1 -0
- package/dist/esm/ag-ui/framing.d.ts +51 -0
- package/dist/esm/ag-ui/framing.js +62 -0
- package/dist/esm/ag-ui/framing.js.map +1 -0
- package/dist/esm/ag-ui/frontendTools.d.ts +37 -0
- package/dist/esm/ag-ui/frontendTools.js +64 -0
- package/dist/esm/ag-ui/frontendTools.js.map +1 -0
- package/dist/esm/ag-ui/ids.d.ts +43 -0
- package/dist/esm/ag-ui/ids.js +49 -0
- package/dist/esm/ag-ui/ids.js.map +1 -0
- package/dist/esm/ag-ui/index.d.ts +17 -0
- package/dist/esm/ag-ui/index.js +17 -0
- package/dist/esm/ag-ui/index.js.map +1 -0
- package/dist/esm/ag-ui/request.d.ts +72 -0
- package/dist/esm/ag-ui/request.js +350 -0
- package/dist/esm/ag-ui/request.js.map +1 -0
- package/dist/esm/ag-ui/serializer.d.ts +173 -0
- package/dist/esm/ag-ui/serializer.js +895 -0
- package/dist/esm/ag-ui/serializer.js.map +1 -0
- package/dist/esm/ag-ui/types.d.ts +305 -0
- package/dist/esm/ag-ui/types.js +19 -0
- package/dist/esm/ag-ui/types.js.map +1 -0
- package/dist/esm/core/Agent.d.ts +2 -0
- package/dist/esm/core/Agent.js +38 -5
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/RunnerBase.js +17 -3
- package/dist/esm/core/RunnerBase.js.map +1 -1
- package/dist/esm/core/agent/buildAgentChart.js +4 -0
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js +4 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/callerIdentity.js +2 -1
- package/dist/esm/core/agent/callerIdentity.js.map +1 -1
- package/dist/esm/core/agent/stages/routeTurn.d.ts +1 -1
- package/dist/esm/core/agent/stages/routeTurn.js +3 -3
- package/dist/esm/core/agent/stages/routeTurn.js.map +1 -1
- package/dist/esm/core/agent/stages/seed.d.ts +11 -1
- package/dist/esm/core/agent/stages/seed.js +49 -8
- package/dist/esm/core/agent/stages/seed.js.map +1 -1
- package/dist/esm/core/agent/stages/timeLayer.js +2 -2
- package/dist/esm/core/agent/stages/timeLayer.js.map +1 -1
- package/dist/esm/core/agent/stages/toolCalls.d.ts +11 -1
- package/dist/esm/core/agent/stages/toolCalls.js +26 -5
- package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/esm/core/agent/types.d.ts +16 -6
- package/dist/esm/core/memberRun.d.ts +132 -0
- package/dist/esm/core/memberRun.js +227 -0
- package/dist/esm/core/memberRun.js.map +1 -0
- package/dist/esm/core/slots/buildToolsSlot.d.ts +1 -1
- package/dist/esm/core/slots/buildToolsSlot.js +1 -1
- package/dist/esm/core/slots/buildToolsSlot.js.map +1 -1
- package/dist/esm/core-flow/Conditional.d.ts +8 -0
- package/dist/esm/core-flow/Conditional.js +29 -8
- package/dist/esm/core-flow/Conditional.js.map +1 -1
- package/dist/esm/core-flow/Graph.js +38 -13
- package/dist/esm/core-flow/Graph.js.map +1 -1
- package/dist/esm/core-flow/Loop.d.ts +8 -0
- package/dist/esm/core-flow/Loop.js +29 -9
- package/dist/esm/core-flow/Loop.js.map +1 -1
- package/dist/esm/core-flow/Parallel.d.ts +8 -0
- package/dist/esm/core-flow/Parallel.js +35 -14
- package/dist/esm/core-flow/Parallel.js.map +1 -1
- package/dist/esm/core-flow/Sequence.d.ts +8 -0
- package/dist/esm/core-flow/Sequence.js +29 -8
- package/dist/esm/core-flow/Sequence.js.map +1 -1
- package/dist/esm/core-flow/Workflow.js +34 -10
- package/dist/esm/core-flow/Workflow.js.map +1 -1
- package/dist/esm/doors/ag-ui.d.ts +19 -0
- package/dist/esm/doors/ag-ui.js +20 -0
- package/dist/esm/doors/ag-ui.js.map +1 -0
- package/dist/esm/hosting/envelope.js +5 -0
- package/dist/esm/hosting/envelope.js.map +1 -1
- package/dist/esm/hosting/httpHost.js +5 -78
- package/dist/esm/hosting/httpHost.js.map +1 -1
- package/dist/esm/hosting/index.d.ts +4 -1
- package/dist/esm/hosting/index.js +2 -0
- package/dist/esm/hosting/index.js.map +1 -1
- package/dist/esm/hosting/pendingAsk.d.ts +19 -0
- package/dist/esm/hosting/pendingAsk.js +38 -0
- package/dist/esm/hosting/pendingAsk.js.map +1 -0
- package/dist/esm/hosting/protocolAdapter.d.ts +229 -0
- package/dist/esm/hosting/protocolAdapter.js +23 -0
- package/dist/esm/hosting/protocolAdapter.js.map +1 -0
- package/dist/esm/hosting/refusalStatus.d.ts +30 -0
- package/dist/esm/hosting/refusalStatus.js +81 -0
- package/dist/esm/hosting/refusalStatus.js.map +1 -0
- package/dist/esm/hosting/standingAgent.js +1 -31
- package/dist/esm/hosting/standingAgent.js.map +1 -1
- package/dist/esm/hosting/stream.d.ts +39 -0
- package/dist/esm/hosting/stream.js +34 -2
- package/dist/esm/hosting/stream.js.map +1 -1
- package/dist/esm/hosting/streamHandler.d.ts +134 -0
- package/dist/esm/hosting/streamHandler.js +493 -0
- package/dist/esm/hosting/streamHandler.js.map +1 -0
- package/dist/esm/hosting/types.d.ts +15 -0
- package/dist/esm/hosting/types.js.map +1 -1
- package/dist/esm/hosting/verifiedThreads.d.ts +29 -0
- package/dist/esm/hosting/verifiedThreads.js +46 -0
- package/dist/esm/hosting/verifiedThreads.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/humanizeLLMError.d.ts +15 -0
- package/dist/esm/lib/humanizeLLMError.js +22 -7
- package/dist/esm/lib/humanizeLLMError.js.map +1 -1
- package/dist/esm/mcp/throttleRetry.d.ts +51 -0
- package/dist/esm/mcp/throttleRetry.js +37 -4
- package/dist/esm/mcp/throttleRetry.js.map +1 -1
- package/dist/esm/memory/define.js +45 -1
- package/dist/esm/memory/define.js.map +1 -1
- package/dist/esm/memory/define.types.d.ts +24 -0
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/stages/formatDefault.js +3 -1
- package/dist/esm/memory/stages/formatDefault.js.map +1 -1
- package/dist/esm/memory/store/InMemoryStore.d.ts +8 -3
- package/dist/esm/memory/store/InMemoryStore.js +12 -3
- package/dist/esm/memory/store/InMemoryStore.js.map +1 -1
- package/dist/esm/memory/store/index.d.ts +1 -0
- package/dist/esm/memory/store/index.js +5 -0
- package/dist/esm/memory/store/index.js.map +1 -1
- package/dist/esm/memory/store/types.d.ts +38 -4
- package/dist/esm/memory/store/writeOptions.d.ts +118 -0
- package/dist/esm/memory/store/writeOptions.js +242 -0
- package/dist/esm/memory/store/writeOptions.js.map +1 -0
- package/dist/esm/memory-providers.d.ts +1 -1
- package/dist/esm/memory-providers.js +4 -1
- package/dist/esm/memory-providers.js.map +1 -1
- package/dist/esm/patterns/MapReduce.js +8 -2
- package/dist/esm/patterns/MapReduce.js.map +1 -1
- package/dist/esm/tool-providers/index.d.ts +5 -0
- package/dist/esm/tool-providers/index.js +6 -0
- package/dist/esm/tool-providers/index.js.map +1 -1
- package/dist/esm/trace-toolpack/selfExplain.d.ts +8 -0
- package/dist/esm/trace-toolpack/selfExplain.js +25 -2
- package/dist/esm/trace-toolpack/selfExplain.js.map +1 -1
- package/dist/hosting/envelope.js +5 -0
- package/dist/hosting/envelope.js.map +1 -1
- package/dist/hosting/httpHost.js +5 -78
- package/dist/hosting/httpHost.js.map +1 -1
- package/dist/hosting/index.js +9 -3
- package/dist/hosting/index.js.map +1 -1
- package/dist/hosting/pendingAsk.js +42 -0
- package/dist/hosting/pendingAsk.js.map +1 -0
- package/dist/hosting/protocolAdapter.js +24 -0
- package/dist/hosting/protocolAdapter.js.map +1 -0
- package/dist/hosting/refusalStatus.js +84 -0
- package/dist/hosting/refusalStatus.js.map +1 -0
- package/dist/hosting/standingAgent.js +2 -32
- package/dist/hosting/standingAgent.js.map +1 -1
- package/dist/hosting/stream.js +35 -3
- package/dist/hosting/stream.js.map +1 -1
- package/dist/hosting/streamHandler.js +497 -0
- package/dist/hosting/streamHandler.js.map +1 -0
- package/dist/hosting/types.js.map +1 -1
- package/dist/hosting/verifiedThreads.js +50 -0
- package/dist/hosting/verifiedThreads.js.map +1 -0
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/humanizeLLMError.js +23 -8
- package/dist/lib/humanizeLLMError.js.map +1 -1
- package/dist/mcp/throttleRetry.js +41 -6
- package/dist/mcp/throttleRetry.js.map +1 -1
- package/dist/memory/define.js +45 -1
- package/dist/memory/define.js.map +1 -1
- package/dist/memory/define.types.js.map +1 -1
- package/dist/memory/stages/formatDefault.js +3 -1
- package/dist/memory/stages/formatDefault.js.map +1 -1
- package/dist/memory/store/InMemoryStore.js +12 -3
- package/dist/memory/store/InMemoryStore.js.map +1 -1
- package/dist/memory/store/index.js +11 -1
- package/dist/memory/store/index.js.map +1 -1
- package/dist/memory/store/writeOptions.js +250 -0
- package/dist/memory/store/writeOptions.js.map +1 -0
- package/dist/memory-providers.js +4 -1
- package/dist/memory-providers.js.map +1 -1
- package/dist/patterns/MapReduce.js +8 -2
- package/dist/patterns/MapReduce.js.map +1 -1
- package/dist/tool-providers/index.js +10 -1
- package/dist/tool-providers/index.js.map +1 -1
- package/dist/trace-toolpack/selfExplain.js +25 -2
- package/dist/trace-toolpack/selfExplain.js.map +1 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/errorType.d.ts +13 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/errorType.d.ts.map +1 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts +117 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts.map +1 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/safeAnswer.d.ts +50 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/safeAnswer.d.ts.map +1 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/session.d.ts +81 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/session.d.ts.map +1 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +62 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts.map +1 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/strictJson.d.ts +38 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/strictJson.d.ts.map +1 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts +177 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts.map +1 -0
- package/dist/types/adapters/memory/agentcore.d.ts +152 -7
- package/dist/types/adapters/memory/agentcore.d.ts.map +1 -1
- package/dist/types/adapters/memory/memoryBank.d.ts +3 -2
- package/dist/types/adapters/memory/memoryBank.d.ts.map +1 -1
- package/dist/types/adapters/memory/pgVector.d.ts.map +1 -1
- package/dist/types/adapters/memory/redis.d.ts +8 -3
- package/dist/types/adapters/memory/redis.d.ts.map +1 -1
- package/dist/types/adapters/memory/s3Vectors.d.ts.map +1 -1
- package/dist/types/adapters/memory/sqliteVector.d.ts.map +1 -1
- package/dist/types/ag-ui/adapter.d.ts +69 -0
- package/dist/types/ag-ui/adapter.d.ts.map +1 -0
- package/dist/types/ag-ui/framing.d.ts +52 -0
- package/dist/types/ag-ui/framing.d.ts.map +1 -0
- package/dist/types/ag-ui/frontendTools.d.ts +38 -0
- package/dist/types/ag-ui/frontendTools.d.ts.map +1 -0
- package/dist/types/ag-ui/ids.d.ts +44 -0
- package/dist/types/ag-ui/ids.d.ts.map +1 -0
- package/dist/types/ag-ui/index.d.ts +18 -0
- package/dist/types/ag-ui/index.d.ts.map +1 -0
- package/dist/types/ag-ui/request.d.ts +73 -0
- package/dist/types/ag-ui/request.d.ts.map +1 -0
- package/dist/types/ag-ui/serializer.d.ts +174 -0
- package/dist/types/ag-ui/serializer.d.ts.map +1 -0
- package/dist/types/ag-ui/types.d.ts +306 -0
- package/dist/types/ag-ui/types.d.ts.map +1 -0
- package/dist/types/core/Agent.d.ts +2 -0
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/RunnerBase.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/callerIdentity.d.ts.map +1 -1
- package/dist/types/core/agent/stages/routeTurn.d.ts +1 -1
- package/dist/types/core/agent/stages/routeTurn.d.ts.map +1 -1
- package/dist/types/core/agent/stages/seed.d.ts +11 -1
- package/dist/types/core/agent/stages/seed.d.ts.map +1 -1
- package/dist/types/core/agent/stages/toolCalls.d.ts +11 -1
- package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +16 -6
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/memberRun.d.ts +133 -0
- package/dist/types/core/memberRun.d.ts.map +1 -0
- package/dist/types/core/slots/buildToolsSlot.d.ts +1 -1
- package/dist/types/core/slots/buildToolsSlot.d.ts.map +1 -1
- package/dist/types/core-flow/Conditional.d.ts +8 -0
- package/dist/types/core-flow/Conditional.d.ts.map +1 -1
- package/dist/types/core-flow/Graph.d.ts.map +1 -1
- package/dist/types/core-flow/Loop.d.ts +8 -0
- package/dist/types/core-flow/Loop.d.ts.map +1 -1
- package/dist/types/core-flow/Parallel.d.ts +8 -0
- package/dist/types/core-flow/Parallel.d.ts.map +1 -1
- package/dist/types/core-flow/Sequence.d.ts +8 -0
- package/dist/types/core-flow/Sequence.d.ts.map +1 -1
- package/dist/types/core-flow/Workflow.d.ts.map +1 -1
- package/dist/types/doors/ag-ui.d.ts +20 -0
- package/dist/types/doors/ag-ui.d.ts.map +1 -0
- package/dist/types/hosting/httpHost.d.ts.map +1 -1
- package/dist/types/hosting/index.d.ts +4 -1
- package/dist/types/hosting/index.d.ts.map +1 -1
- package/dist/types/hosting/pendingAsk.d.ts +20 -0
- package/dist/types/hosting/pendingAsk.d.ts.map +1 -0
- package/dist/types/hosting/protocolAdapter.d.ts +230 -0
- package/dist/types/hosting/protocolAdapter.d.ts.map +1 -0
- package/dist/types/hosting/refusalStatus.d.ts +31 -0
- package/dist/types/hosting/refusalStatus.d.ts.map +1 -0
- package/dist/types/hosting/standingAgent.d.ts.map +1 -1
- package/dist/types/hosting/stream.d.ts +39 -0
- package/dist/types/hosting/stream.d.ts.map +1 -1
- package/dist/types/hosting/streamHandler.d.ts +135 -0
- package/dist/types/hosting/streamHandler.d.ts.map +1 -0
- package/dist/types/hosting/types.d.ts +15 -0
- package/dist/types/hosting/types.d.ts.map +1 -1
- package/dist/types/hosting/verifiedThreads.d.ts +30 -0
- package/dist/types/hosting/verifiedThreads.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/humanizeLLMError.d.ts +15 -0
- package/dist/types/lib/humanizeLLMError.d.ts.map +1 -1
- package/dist/types/mcp/throttleRetry.d.ts +51 -0
- package/dist/types/mcp/throttleRetry.d.ts.map +1 -1
- package/dist/types/memory/define.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +24 -0
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/memory/stages/formatDefault.d.ts.map +1 -1
- package/dist/types/memory/store/InMemoryStore.d.ts +8 -3
- package/dist/types/memory/store/InMemoryStore.d.ts.map +1 -1
- package/dist/types/memory/store/index.d.ts +1 -0
- package/dist/types/memory/store/index.d.ts.map +1 -1
- package/dist/types/memory/store/types.d.ts +38 -4
- package/dist/types/memory/store/types.d.ts.map +1 -1
- package/dist/types/memory/store/writeOptions.d.ts +119 -0
- package/dist/types/memory/store/writeOptions.d.ts.map +1 -0
- package/dist/types/memory-providers.d.ts +1 -1
- package/dist/types/memory-providers.d.ts.map +1 -1
- package/dist/types/patterns/MapReduce.d.ts.map +1 -1
- package/dist/types/tool-providers/index.d.ts +5 -0
- package/dist/types/tool-providers/index.d.ts.map +1 -1
- package/dist/types/trace-toolpack/selfExplain.d.ts +8 -0
- package/dist/types/trace-toolpack/selfExplain.d.ts.map +1 -1
- package/package.json +25 -1
|
@@ -0,0 +1,899 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* serializer — one run's served agentfootprint events → AG-UI events.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: a per-run state machine (`RunTranslation`), pure — no I/O, no clock,
|
|
6
|
+
* no import of `@ag-ui/*`. Frames are the framing strategy's job
|
|
7
|
+
* (`framing.ts`); reading a request is the adapter's (`adapter.ts`).
|
|
8
|
+
* Role: the Lens over a run for an AG-UI reader. It composes what that reader
|
|
9
|
+
* is served, from the RECORD only: every value it writes comes from a
|
|
10
|
+
* served event (the placeholder wherever a redaction policy selected a
|
|
11
|
+
* value), from the record's address (`meta.runtimeStageId`,
|
|
12
|
+
* `meta.subflowPath` — never selected by a policy), or from the
|
|
13
|
+
* AG-UI request's own ids. It never reads the run's live values, so
|
|
14
|
+
* nothing a policy hides can reach an AG-UI event. The record's own
|
|
15
|
+
* run id is never written: it counts every run the process made.
|
|
16
|
+
*
|
|
17
|
+
* THE MAPPING
|
|
18
|
+
* agent.turn_start (nested) → SUBAGENT_STARTED (a sub-agent's turn)
|
|
19
|
+
* agent.turn_end → SUBAGENT_FINISHED / the root answer
|
|
20
|
+
* agent.iteration_start/_end → STEP_STARTED/_FINISHED `iteration <n>`
|
|
21
|
+
* composition.enter/exit → STEP_STARTED/_FINISHED `<Kind>[:<mount>]`
|
|
22
|
+
* stream.token → TEXT_MESSAGE_START/CONTENT/END
|
|
23
|
+
* stream.llm_end (no agent around) → one whole TEXT message (an LLM call that streams nothing)
|
|
24
|
+
* stream.thinking_delta/_end → REASONING_START … REASONING_END (only with `reasoning: true`)
|
|
25
|
+
* stream.tool_start → TOOL_CALL_START + TOOL_CALL_ARGS + TOOL_CALL_END
|
|
26
|
+
* stream.tool_end → TOOL_CALL_RESULT
|
|
27
|
+
* pause.request + settle('paused') → RUN_FINISHED { outcome: interrupt }
|
|
28
|
+
* settle('paused', awaiting caller) → RUN_FINISHED { outcome: success, pendingToolCallIds }
|
|
29
|
+
* (a tool the client runs: its call is left to answer)
|
|
30
|
+
* error.fatal + settle('failed') → RUN_ERROR — the served error.fatal's words when they
|
|
31
|
+
* are a fixed sentence, else "The run failed."
|
|
32
|
+
* an allow-listed event → CUSTOM { name: <event type>, value: <its listed fields> }
|
|
33
|
+
* anything else → nothing
|
|
34
|
+
*
|
|
35
|
+
* WHAT LEAVES THE PROCESS. An AG-UI stream goes to a browser, so nothing goes
|
|
36
|
+
* out by default that a person is not meant to read. Every value comes from a
|
|
37
|
+
* served payload; `CUSTOM` carries only the event types on an allow-list, each
|
|
38
|
+
* with the fields its projection picks ({@link AG_UI_CUSTOM_EVENTS} — the whole
|
|
39
|
+
* record, such as `context.injected`'s assembled prompt or `error.retried`'s
|
|
40
|
+
* raw error, stays off the wire unless the app lists it); the model's
|
|
41
|
+
* reasoning goes out only when the app says so; and a failure is described by
|
|
42
|
+
* the record, never by the thrown value. Identity on the meta (`principal`,
|
|
43
|
+
* `tenant`, `sessionId`) is never written.
|
|
44
|
+
*
|
|
45
|
+
* WHO OWNS AN EVENT. Each agent's turn opens a SCOPE at its mount — the
|
|
46
|
+
* subflow path its `turn_start` fired at (`[]` for the root agent, `step-p/x`
|
|
47
|
+
* for an agent in a parallel branch). An event belongs to the deepest open scope
|
|
48
|
+
* whose mount prefixes its own subflow path, segment by segment, and carries
|
|
49
|
+
* that scope's `subagentRunId`. Parallel branches have different mounts, so
|
|
50
|
+
* their interleaved events can never be attributed to each other.
|
|
51
|
+
*
|
|
52
|
+
* A RUN THAT CONTINUES A PAUSE. A paused run hands back `suspension()` — the
|
|
53
|
+
* ids it gave the client (the interrupt, the open call) and every scope and
|
|
54
|
+
* step open at the pause. The run that continues it passes that as `resume`:
|
|
55
|
+
* the same sub-agents re-open (AG-UI: "a later run may continue the same
|
|
56
|
+
* invocation"), their steps re-open, and the first result in the paused call's
|
|
57
|
+
* scope answers that call under its own id — or, for a tool the client ran, is
|
|
58
|
+
* not written at all, because the client holds the result it sent.
|
|
59
|
+
*
|
|
60
|
+
* TEXT. The reply is what the record streamed (`stream.token`) — the channel
|
|
61
|
+
* `toSSE({ format: 'text' })` and a hosted reply read. An agent turn whose
|
|
62
|
+
* answer streamed no token (a provider without `stream()`) is written whole
|
|
63
|
+
* from `turn_end.finalContent`, unless the record marks it refused. An
|
|
64
|
+
* agent's `llm_end.content` is a DRAFT the library may be holding back
|
|
65
|
+
* (answer validation, an output policy) and is never written.
|
|
66
|
+
*/
|
|
67
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
+
exports.agUiSerializer = exports.AG_UI_SUBAGENT_CANCELLED = exports.AG_UI_SUBAGENT_UNFINISHED = exports.AG_UI_RUN_FAILED = exports.AG_UI_TOOL_FAILED = exports.AG_UI_CUSTOM_EVENTS = void 0;
|
|
69
|
+
const eventMeta_js_1 = require("../bridge/eventMeta.js");
|
|
70
|
+
const humanizeLLMError_js_1 = require("../lib/humanizeLLMError.js");
|
|
71
|
+
const wireJson_js_1 = require("../lib/wireJson.js");
|
|
72
|
+
const ids_js_1 = require("./ids.js");
|
|
73
|
+
const types_js_1 = require("./types.js");
|
|
74
|
+
/** The listed fields of `payload`, where present. */
|
|
75
|
+
const pick = (payload, fields) => {
|
|
76
|
+
const out = {};
|
|
77
|
+
for (const field of fields)
|
|
78
|
+
if (payload[field] !== undefined)
|
|
79
|
+
out[field] = payload[field];
|
|
80
|
+
return out;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The agentfootprint events that go out as AG-UI `CUSTOM` by default, each with
|
|
84
|
+
* the fields it carries: progress (which call, which iteration), spend, the
|
|
85
|
+
* loop's route, the answer's standing and a provider's retries — counts and the
|
|
86
|
+
* library's own words. Content (a tool's own progress `payload`,
|
|
87
|
+
* `context.injected`'s assembled prompt, `error.retried`'s raw error, memory,
|
|
88
|
+
* permission and credential facts) stays off the wire unless an app lists it:
|
|
89
|
+
* `agUiSerializer({ ..., custom: { ...AG_UI_CUSTOM_EVENTS, [type]: projection } })`.
|
|
90
|
+
*/
|
|
91
|
+
exports.AG_UI_CUSTOM_EVENTS = Object.freeze({
|
|
92
|
+
// Which call and which iteration — never the tool author's `payload`, which
|
|
93
|
+
// is whatever the tool chose to report (list it to send it).
|
|
94
|
+
'agentfootprint.stream.tool_progress': (payload, at) => ({
|
|
95
|
+
...(at.toolCallId !== undefined && { toolCallId: at.toolCallId }),
|
|
96
|
+
...pick(payload, ['iteration']),
|
|
97
|
+
}),
|
|
98
|
+
'agentfootprint.cost.tick': (payload) => pick(payload, [
|
|
99
|
+
'scope',
|
|
100
|
+
'model',
|
|
101
|
+
'provider',
|
|
102
|
+
'tokensInput',
|
|
103
|
+
'tokensOutput',
|
|
104
|
+
'estimatedUsd',
|
|
105
|
+
'cumulative',
|
|
106
|
+
]),
|
|
107
|
+
'agentfootprint.agent.route_decided': (payload) => pick(payload, ['iterIndex', 'chosen']),
|
|
108
|
+
'agentfootprint.answer.assessed': (payload) => pick(payload, ['standing', 'assessment', 'reasons', 'checked', 'turn', 'iteration']),
|
|
109
|
+
'agentfootprint.error.retried': (payload) => pick(payload, ['attempt', 'maxAttempts', 'backoffMs', 'statedWaitMs']),
|
|
110
|
+
'agentfootprint.error.recovered': (payload) => pick(payload, ['attempt', 'totalDurationMs']),
|
|
111
|
+
});
|
|
112
|
+
/** Said by `TOOL_CALL_RESULT` for a failed call, unless `toolErrors: 'served'`. */
|
|
113
|
+
exports.AG_UI_TOOL_FAILED = 'The tool failed.';
|
|
114
|
+
/** Said by `RUN_ERROR` when the run's `error.fatal` is not one of the record's fixed sentences. */
|
|
115
|
+
exports.AG_UI_RUN_FAILED = 'The run failed.';
|
|
116
|
+
/** Is `said` one of the record's fixed failure sentences — the only `error.fatal` words a `RUN_ERROR` repeats? */
|
|
117
|
+
const isFixedFailure = (said) => Object.values(humanizeLLMError_js_1.LLM_ERROR_SENTENCES).includes(said);
|
|
118
|
+
/** Said by `SUBAGENT_ERROR` for a sub-agent whose turn ended without an answer. */
|
|
119
|
+
exports.AG_UI_SUBAGENT_UNFINISHED = "The sub-agent's turn ended without an answer.";
|
|
120
|
+
/** Said by `SUBAGENT_ERROR` for a sub-agent still running when its run was cancelled. */
|
|
121
|
+
exports.AG_UI_SUBAGENT_CANCELLED = 'The run was cancelled before this sub-agent finished.';
|
|
122
|
+
const newScope = (mount, subagentRunId, name, parentSubagentRunId) => ({
|
|
123
|
+
mount,
|
|
124
|
+
subagentRunId,
|
|
125
|
+
...(name !== undefined && { name }),
|
|
126
|
+
...(parentSubagentRunId !== undefined && { parentSubagentRunId }),
|
|
127
|
+
llmAddress: undefined,
|
|
128
|
+
isAgent: false,
|
|
129
|
+
text: undefined,
|
|
130
|
+
callMessageId: undefined,
|
|
131
|
+
streamed: false,
|
|
132
|
+
reasoning: undefined,
|
|
133
|
+
steps: [],
|
|
134
|
+
calls: [],
|
|
135
|
+
});
|
|
136
|
+
/** Does `prefix` lead `path`, segment by segment? */
|
|
137
|
+
function leads(prefix, path) {
|
|
138
|
+
if (prefix.length > path.length)
|
|
139
|
+
return false;
|
|
140
|
+
for (let i = 0; i < prefix.length; i++)
|
|
141
|
+
if (prefix[i] !== path[i])
|
|
142
|
+
return false;
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
const sameMount = (a, b) => a.length === b.length && leads(a, b);
|
|
146
|
+
const record = (value) => typeof value === 'object' && value !== null ? value : {};
|
|
147
|
+
const text = (value) => typeof value === 'string' ? value : undefined;
|
|
148
|
+
/** A tool result as AG-UI text: a string as it is, anything else through the wire rule. */
|
|
149
|
+
const resultText = (value) => typeof value === 'string' ? value : value === undefined ? '' : (0, wireJson_js_1.toWireJson)(value);
|
|
150
|
+
/**
|
|
151
|
+
* The AG-UI serializer for ONE run: feed it every served agentfootprint event
|
|
152
|
+
* of the run, in order, then settle it once. `RUN_STARTED` comes before the
|
|
153
|
+
* first event it returns; `RUN_FINISHED` or `RUN_ERROR` is the last thing
|
|
154
|
+
* `settle` returns, with everything still open closed before it.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const ag = agUiSerializer({ threadId, runId });
|
|
159
|
+
* const off = agent.on('*', (event) => send(ag.event(event)));
|
|
160
|
+
* try {
|
|
161
|
+
* const out = await agent.run({ message });
|
|
162
|
+
* send(ag.settle({ kind: isPaused(out) ? 'paused' : 'finished' }));
|
|
163
|
+
* } catch {
|
|
164
|
+
* send(ag.settle({ kind: 'failed' })); // described by the record, never by the thrown value
|
|
165
|
+
* } finally {
|
|
166
|
+
* off();
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
function agUiSerializer(options) {
|
|
171
|
+
const { threadId, runId } = options;
|
|
172
|
+
if (typeof threadId !== 'string' || threadId.length === 0) {
|
|
173
|
+
throw new TypeError('AG-UI: `threadId` must be a non-empty string.');
|
|
174
|
+
}
|
|
175
|
+
const ids = (0, ids_js_1.agUiIdMinter)(runId);
|
|
176
|
+
const custom = options.custom ?? exports.AG_UI_CUSTOM_EVENTS;
|
|
177
|
+
const reasoning = options.reasoning === true;
|
|
178
|
+
const owns = options.owns;
|
|
179
|
+
const toolErrors = options.toolErrors ?? 'withheld';
|
|
180
|
+
const root = newScope([], undefined);
|
|
181
|
+
/** Open scopes — the root always, then each nested agent turn in open order. */
|
|
182
|
+
const scopes = [root];
|
|
183
|
+
let started = false;
|
|
184
|
+
let settled = false;
|
|
185
|
+
/**
|
|
186
|
+
* The run the events name, once one did — how a translation without `owns`
|
|
187
|
+
* keeps to one run. Never written: the library's run ids count every run the
|
|
188
|
+
* PROCESS made, and a browser must not learn how many other callers ran.
|
|
189
|
+
*/
|
|
190
|
+
let recordRunId;
|
|
191
|
+
/** The record's own words for a failure — the last served `error.fatal`. */
|
|
192
|
+
let fatal;
|
|
193
|
+
let pause;
|
|
194
|
+
/** The root agent's answer as the record serves it — `RUN_FINISHED.result`. */
|
|
195
|
+
let rootResult;
|
|
196
|
+
/** What a continuation needs — set when the run settles paused. */
|
|
197
|
+
let suspended;
|
|
198
|
+
const scopeOf = (path) => {
|
|
199
|
+
let best = root;
|
|
200
|
+
for (const scope of scopes) {
|
|
201
|
+
if (scope.mount.length > best.mount.length && leads(scope.mount, path))
|
|
202
|
+
best = scope;
|
|
203
|
+
}
|
|
204
|
+
return best;
|
|
205
|
+
};
|
|
206
|
+
/** The record's address of `event`, as AG-UI metadata. */
|
|
207
|
+
const addressOf = (event, extra) => ({
|
|
208
|
+
agentfootprint: {
|
|
209
|
+
runtimeStageId: event.meta.runtimeStageId,
|
|
210
|
+
subflowPath: [...event.meta.subflowPath],
|
|
211
|
+
...extra,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
/** The fields every event of `scope` carries. */
|
|
215
|
+
const owned = (scope, event) => ({
|
|
216
|
+
...(event !== undefined && { timestamp: event.meta.wallClockMs }),
|
|
217
|
+
...(scope.subagentRunId !== undefined && { subagentRunId: scope.subagentRunId }),
|
|
218
|
+
});
|
|
219
|
+
// ── closers — each leaves its entity closed and writes the events that say so ──
|
|
220
|
+
const closeText = (scope, out) => {
|
|
221
|
+
if (scope.text === undefined)
|
|
222
|
+
return;
|
|
223
|
+
out.push({ type: 'TEXT_MESSAGE_END', messageId: scope.text.id, ...owned(scope) });
|
|
224
|
+
scope.text = undefined;
|
|
225
|
+
};
|
|
226
|
+
const closeReasoning = (scope, out) => {
|
|
227
|
+
if (scope.reasoning === undefined)
|
|
228
|
+
return;
|
|
229
|
+
const { id } = scope.reasoning;
|
|
230
|
+
out.push({ type: 'REASONING_MESSAGE_END', messageId: id, ...owned(scope) });
|
|
231
|
+
out.push({ type: 'REASONING_END', messageId: id, ...owned(scope) });
|
|
232
|
+
scope.reasoning = undefined;
|
|
233
|
+
};
|
|
234
|
+
const closeSteps = (scope, out) => {
|
|
235
|
+
while (scope.steps.length > 0) {
|
|
236
|
+
const stepName = scope.steps.pop();
|
|
237
|
+
out.push({ type: 'STEP_FINISHED', stepName, ...owned(scope) });
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
/** Close what is open INSIDE a scope — the scope itself stays. */
|
|
241
|
+
const closeContents = (scope, out) => {
|
|
242
|
+
closeText(scope, out);
|
|
243
|
+
closeReasoning(scope, out);
|
|
244
|
+
closeSteps(scope, out);
|
|
245
|
+
};
|
|
246
|
+
/** Close one nested scope: what is open inside it, then its own terminal event. */
|
|
247
|
+
const closeScope = (scope, out, terminal) => {
|
|
248
|
+
closeContents(scope, out);
|
|
249
|
+
const at = scopes.indexOf(scope);
|
|
250
|
+
if (at > 0)
|
|
251
|
+
scopes.splice(at, 1);
|
|
252
|
+
if (scope.subagentRunId !== undefined)
|
|
253
|
+
out.push(terminal(scope.subagentRunId));
|
|
254
|
+
};
|
|
255
|
+
/** The open nested scopes mounted strictly under `mount`, deepest first. */
|
|
256
|
+
const scopesUnder = (mount) => scopes
|
|
257
|
+
.filter((s) => s !== root && s.mount.length > mount.length && leads(mount, s.mount))
|
|
258
|
+
.reverse()
|
|
259
|
+
.sort((a, b) => b.mount.length - a.mount.length);
|
|
260
|
+
/** End a nested scope: every turn still open under it first (they never answered), then it. */
|
|
261
|
+
const endScope = (scope, out, terminal) => {
|
|
262
|
+
for (const inner of scopesUnder(scope.mount))
|
|
263
|
+
closeScope(inner, out, unfinished);
|
|
264
|
+
closeScope(scope, out, terminal);
|
|
265
|
+
};
|
|
266
|
+
const unfinished = (subagentRunId) => ({
|
|
267
|
+
type: 'SUBAGENT_ERROR',
|
|
268
|
+
subagentRunId,
|
|
269
|
+
message: exports.AG_UI_SUBAGENT_UNFINISHED,
|
|
270
|
+
});
|
|
271
|
+
// ── openers ──
|
|
272
|
+
const openStep = (scope, stepName, event, out) => {
|
|
273
|
+
const at = scope.steps.indexOf(stepName);
|
|
274
|
+
if (at >= 0) {
|
|
275
|
+
// The same name still open in this scope: the record never closed it.
|
|
276
|
+
scope.steps.splice(at, 1);
|
|
277
|
+
out.push({ type: 'STEP_FINISHED', stepName, ...owned(scope) });
|
|
278
|
+
}
|
|
279
|
+
scope.steps.push(stepName);
|
|
280
|
+
out.push({
|
|
281
|
+
type: 'STEP_STARTED',
|
|
282
|
+
stepName,
|
|
283
|
+
...owned(scope, event),
|
|
284
|
+
metadata: addressOf(event),
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
const finishStep = (scope, stepName, event, out) => {
|
|
288
|
+
const at = scope.steps.indexOf(stepName);
|
|
289
|
+
if (at < 0)
|
|
290
|
+
return;
|
|
291
|
+
scope.steps.splice(at, 1);
|
|
292
|
+
out.push({ type: 'STEP_FINISHED', stepName, ...owned(scope, event) });
|
|
293
|
+
};
|
|
294
|
+
/** A whole text message in one go — an answer the record did not stream. */
|
|
295
|
+
const wholeText = (scope, content, event, out) => {
|
|
296
|
+
const { id } = ids.next('text', event.meta.runtimeStageId);
|
|
297
|
+
out.push({
|
|
298
|
+
type: 'TEXT_MESSAGE_START',
|
|
299
|
+
messageId: id,
|
|
300
|
+
role: 'assistant',
|
|
301
|
+
...owned(scope, event),
|
|
302
|
+
metadata: addressOf(event),
|
|
303
|
+
});
|
|
304
|
+
out.push({
|
|
305
|
+
type: 'TEXT_MESSAGE_CONTENT',
|
|
306
|
+
messageId: id,
|
|
307
|
+
delta: content,
|
|
308
|
+
...owned(scope, event),
|
|
309
|
+
});
|
|
310
|
+
out.push({ type: 'TEXT_MESSAGE_END', messageId: id, ...owned(scope, event) });
|
|
311
|
+
scope.callMessageId = id;
|
|
312
|
+
};
|
|
313
|
+
// ── the mapping ──
|
|
314
|
+
const translate = (event, out) => {
|
|
315
|
+
const path = event.meta.subflowPath;
|
|
316
|
+
const address = event.meta.runtimeStageId;
|
|
317
|
+
const payload = record(event.payload);
|
|
318
|
+
switch (event.type) {
|
|
319
|
+
case 'agentfootprint.agent.turn_start': {
|
|
320
|
+
if (path.length === 0) {
|
|
321
|
+
root.isAgent = true;
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const previous = scopes.find((s) => s !== root && sameMount(s.mount, path));
|
|
325
|
+
if (previous !== undefined)
|
|
326
|
+
endScope(previous, out, unfinished);
|
|
327
|
+
const parent = scopeOf(path);
|
|
328
|
+
const scope = newScope(path, ids.next('agent', address).id, path.join('/'), parent.subagentRunId);
|
|
329
|
+
scope.isAgent = true;
|
|
330
|
+
scopes.push(scope);
|
|
331
|
+
out.push({
|
|
332
|
+
type: 'SUBAGENT_STARTED',
|
|
333
|
+
subagentRunId: scope.subagentRunId,
|
|
334
|
+
name: scope.name,
|
|
335
|
+
...(parent.subagentRunId !== undefined && { parentSubagentRunId: parent.subagentRunId }),
|
|
336
|
+
timestamp: event.meta.wallClockMs,
|
|
337
|
+
metadata: addressOf(event),
|
|
338
|
+
});
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
case 'agentfootprint.agent.turn_end': {
|
|
342
|
+
const scope = scopeOf(path);
|
|
343
|
+
if (!scope.isAgent) {
|
|
344
|
+
// A turn this translation never saw open (it subscribed late): its
|
|
345
|
+
// answer has no scope to end, and the root's must not be guessed.
|
|
346
|
+
pushCustom(event, scope, out);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
closeText(scope, out);
|
|
350
|
+
closeReasoning(scope, out);
|
|
351
|
+
const refused = payload.refused !== undefined;
|
|
352
|
+
const answer = refused ? undefined : text(payload.finalContent);
|
|
353
|
+
if (!scope.streamed && answer !== undefined && answer.length > 0)
|
|
354
|
+
wholeText(scope, answer, event, out);
|
|
355
|
+
if (scope === root) {
|
|
356
|
+
rootResult = answer;
|
|
357
|
+
closeSteps(scope, out);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
endScope(scope, out, (subagentRunId) => ({
|
|
361
|
+
type: 'SUBAGENT_FINISHED',
|
|
362
|
+
subagentRunId,
|
|
363
|
+
...(answer !== undefined && { result: answer }),
|
|
364
|
+
timestamp: event.meta.wallClockMs,
|
|
365
|
+
}));
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
case 'agentfootprint.agent.iteration_start':
|
|
369
|
+
openStep(scopeOf(path), `iteration ${String(payload.iterIndex)}`, event, out);
|
|
370
|
+
return;
|
|
371
|
+
case 'agentfootprint.agent.iteration_end':
|
|
372
|
+
finishStep(scopeOf(path), `iteration ${String(payload.iterIndex)}`, event, out);
|
|
373
|
+
return;
|
|
374
|
+
case 'agentfootprint.composition.enter':
|
|
375
|
+
openStep(scopeOf(path), compositionStep(payload.kind, path), event, out);
|
|
376
|
+
return;
|
|
377
|
+
case 'agentfootprint.composition.exit': {
|
|
378
|
+
// A turn under this composition that is still open never answered — a
|
|
379
|
+
// branch a tolerant merge let fail. Said, never left dangling.
|
|
380
|
+
for (const inner of scopesUnder(path))
|
|
381
|
+
closeScope(inner, out, unfinished);
|
|
382
|
+
finishStep(scopeOf(path), compositionStep(payload.kind, path), event, out);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
case 'agentfootprint.stream.llm_start': {
|
|
386
|
+
const scope = scopeOf(path);
|
|
387
|
+
closeText(scope, out);
|
|
388
|
+
closeReasoning(scope, out);
|
|
389
|
+
scope.streamed = false;
|
|
390
|
+
scope.callMessageId = undefined;
|
|
391
|
+
scope.llmAddress = address;
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
case 'agentfootprint.stream.token': {
|
|
395
|
+
const content = text(payload.content);
|
|
396
|
+
if (content === undefined)
|
|
397
|
+
return;
|
|
398
|
+
const scope = scopeOf(path);
|
|
399
|
+
const index = typeof payload.tokenIndex === 'number' ? payload.tokenIndex : Number.NaN;
|
|
400
|
+
const open = scope.text;
|
|
401
|
+
if (open === undefined || open.address !== address || !(index > open.lastTokenIndex)) {
|
|
402
|
+
// A new message: the first token of a call, another stage's tokens (an
|
|
403
|
+
// answer released after validation), or a stream that restarted.
|
|
404
|
+
closeText(scope, out);
|
|
405
|
+
const { id } = ids.next('text', address);
|
|
406
|
+
scope.text = { id, address, lastTokenIndex: Number.isNaN(index) ? -1 : index };
|
|
407
|
+
scope.callMessageId = id;
|
|
408
|
+
out.push({
|
|
409
|
+
type: 'TEXT_MESSAGE_START',
|
|
410
|
+
messageId: id,
|
|
411
|
+
role: 'assistant',
|
|
412
|
+
...owned(scope, event),
|
|
413
|
+
metadata: addressOf(event),
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
open.lastTokenIndex = index;
|
|
418
|
+
}
|
|
419
|
+
scope.streamed = true;
|
|
420
|
+
out.push({
|
|
421
|
+
type: 'TEXT_MESSAGE_CONTENT',
|
|
422
|
+
messageId: scope.text.id,
|
|
423
|
+
delta: content,
|
|
424
|
+
...owned(scope, event),
|
|
425
|
+
});
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
case 'agentfootprint.stream.llm_end': {
|
|
429
|
+
const scope = scopeOf(path);
|
|
430
|
+
closeText(scope, out);
|
|
431
|
+
// Inside an agent's turn the content is a draft; the turn's answer comes
|
|
432
|
+
// at turn_end. With no agent around (an LLMCall, a merge by LLM) it IS
|
|
433
|
+
// the answer — written whole when it streamed nothing.
|
|
434
|
+
const content = text(payload.content);
|
|
435
|
+
if (!scope.isAgent && !scope.streamed && payload.contentWithheld !== true && content)
|
|
436
|
+
wholeText(scope, content, event, out);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
case 'agentfootprint.stream.thinking_delta': {
|
|
440
|
+
const content = text(payload.content);
|
|
441
|
+
if (!reasoning || content === undefined)
|
|
442
|
+
return;
|
|
443
|
+
const scope = scopeOf(path);
|
|
444
|
+
if (scope.reasoning === undefined || scope.reasoning.iteration !== payload.iteration) {
|
|
445
|
+
closeReasoning(scope, out);
|
|
446
|
+
const { id } = ids.next('reasoning', address);
|
|
447
|
+
scope.reasoning = { id, iteration: payload.iteration };
|
|
448
|
+
out.push({
|
|
449
|
+
type: 'REASONING_START',
|
|
450
|
+
messageId: id,
|
|
451
|
+
...owned(scope, event),
|
|
452
|
+
metadata: addressOf(event),
|
|
453
|
+
});
|
|
454
|
+
out.push({
|
|
455
|
+
type: 'REASONING_MESSAGE_START',
|
|
456
|
+
messageId: id,
|
|
457
|
+
role: 'reasoning',
|
|
458
|
+
...owned(scope, event),
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
out.push({
|
|
462
|
+
type: 'REASONING_MESSAGE_CONTENT',
|
|
463
|
+
messageId: scope.reasoning.id,
|
|
464
|
+
delta: content,
|
|
465
|
+
...owned(scope, event),
|
|
466
|
+
});
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
case 'agentfootprint.stream.thinking_end': {
|
|
470
|
+
if (!reasoning)
|
|
471
|
+
return;
|
|
472
|
+
const scope = scopeOf(path);
|
|
473
|
+
if (scope.reasoning !== undefined && scope.reasoning.iteration === payload.iteration) {
|
|
474
|
+
closeReasoning(scope, out);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
// Nothing streamed for this call: the blocks are the reasoning, one
|
|
478
|
+
// message each, in one span. A redacted block carries no text to show.
|
|
479
|
+
const blocks = Array.isArray(payload.blocks) ? payload.blocks : [];
|
|
480
|
+
const thoughts = blocks
|
|
481
|
+
.map((block) => record(block))
|
|
482
|
+
.filter((block) => block.type === 'thinking')
|
|
483
|
+
.map((block) => text(block.content))
|
|
484
|
+
.filter((content) => content !== undefined && content.length > 0);
|
|
485
|
+
if (thoughts.length === 0)
|
|
486
|
+
return;
|
|
487
|
+
closeReasoning(scope, out);
|
|
488
|
+
const messageIds = thoughts.map(() => ids.next('reasoning', address).id);
|
|
489
|
+
const span = messageIds[0];
|
|
490
|
+
out.push({
|
|
491
|
+
type: 'REASONING_START',
|
|
492
|
+
messageId: span,
|
|
493
|
+
...owned(scope, event),
|
|
494
|
+
metadata: addressOf(event),
|
|
495
|
+
});
|
|
496
|
+
thoughts.forEach((content, i) => {
|
|
497
|
+
const messageId = messageIds[i];
|
|
498
|
+
out.push({
|
|
499
|
+
type: 'REASONING_MESSAGE_START',
|
|
500
|
+
messageId,
|
|
501
|
+
role: 'reasoning',
|
|
502
|
+
...owned(scope, event),
|
|
503
|
+
});
|
|
504
|
+
out.push({
|
|
505
|
+
type: 'REASONING_MESSAGE_CONTENT',
|
|
506
|
+
messageId,
|
|
507
|
+
delta: content,
|
|
508
|
+
...owned(scope, event),
|
|
509
|
+
});
|
|
510
|
+
out.push({ type: 'REASONING_MESSAGE_END', messageId, ...owned(scope, event) });
|
|
511
|
+
});
|
|
512
|
+
out.push({ type: 'REASONING_END', messageId: span, ...owned(scope, event) });
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
case 'agentfootprint.stream.tool_start': {
|
|
516
|
+
const scope = scopeOf(path);
|
|
517
|
+
// The call's arguments are complete before it runs: a model's text
|
|
518
|
+
// message for this call is over, and so is its reasoning.
|
|
519
|
+
closeText(scope, out);
|
|
520
|
+
closeReasoning(scope, out);
|
|
521
|
+
// Every call of one LLM response belongs to ONE assistant message: the
|
|
522
|
+
// call's text message when it wrote any, else a message minted at the
|
|
523
|
+
// LLM call's own address for the first call and held for the rest.
|
|
524
|
+
if (scope.callMessageId === undefined)
|
|
525
|
+
scope.callMessageId = ids.next('text', scope.llmAddress ?? address).id;
|
|
526
|
+
const { id, n } = ids.next('tool', address);
|
|
527
|
+
scope.calls.push({ id, n, address, servedId: payload.toolCallId });
|
|
528
|
+
const toolCallName = text(payload.toolName) ?? '';
|
|
529
|
+
out.push({
|
|
530
|
+
type: 'TOOL_CALL_START',
|
|
531
|
+
toolCallId: id,
|
|
532
|
+
toolCallName,
|
|
533
|
+
parentMessageId: scope.callMessageId,
|
|
534
|
+
...owned(scope, event),
|
|
535
|
+
metadata: addressOf(event, { toolCallId: text(payload.toolCallId) }),
|
|
536
|
+
});
|
|
537
|
+
out.push({
|
|
538
|
+
type: 'TOOL_CALL_ARGS',
|
|
539
|
+
toolCallId: id,
|
|
540
|
+
delta: (0, wireJson_js_1.toWireJson)(payload.args ?? {}),
|
|
541
|
+
...owned(scope, event),
|
|
542
|
+
});
|
|
543
|
+
out.push({ type: 'TOOL_CALL_END', toolCallId: id, ...owned(scope, event) });
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
case 'agentfootprint.stream.tool_end': {
|
|
547
|
+
const scope = scopeOf(path);
|
|
548
|
+
const call = takeCall(scope, address, payload.toolCallId);
|
|
549
|
+
if (call === undefined) {
|
|
550
|
+
// A result the record cannot tie to a call this run opened — never
|
|
551
|
+
// attached to a call it may not belong to (CUSTOM only if listed).
|
|
552
|
+
pushCustom(event, scope, out);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
// A frontend tool's result is the one the client sent: it holds it already.
|
|
556
|
+
if (call.client === true)
|
|
557
|
+
return;
|
|
558
|
+
// A FAILED call's result is the thrown text — a connection string, a
|
|
559
|
+
// stack line, a provider's body. A person reads the fixed words unless
|
|
560
|
+
// the app chose to serve the record's own.
|
|
561
|
+
// Any `error` but an explicit `false` counts — under a policy that
|
|
562
|
+
// selects the key, the flag itself is served as the placeholder.
|
|
563
|
+
const failed = payload.error !== undefined && payload.error !== false && toolErrors !== 'served';
|
|
564
|
+
out.push({
|
|
565
|
+
type: 'TOOL_CALL_RESULT',
|
|
566
|
+
messageId: call.n < 0 ? ids.next('result', address).id : ids.at('result', call.n, call.address),
|
|
567
|
+
toolCallId: call.id,
|
|
568
|
+
content: failed ? exports.AG_UI_TOOL_FAILED : resultText(payload.result),
|
|
569
|
+
role: 'tool',
|
|
570
|
+
...owned(scope, event),
|
|
571
|
+
});
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
case 'agentfootprint.pause.request':
|
|
575
|
+
pause = { event, scope: scopeOf(path) };
|
|
576
|
+
return;
|
|
577
|
+
case 'agentfootprint.error.fatal': {
|
|
578
|
+
// Only a FIXED sentence goes to a browser. The record's own fallback
|
|
579
|
+
// quotes the raw thrown message ("The AI call failed: …"), which may
|
|
580
|
+
// hold anything a provider or a tool put in it.
|
|
581
|
+
const said = text(payload.error);
|
|
582
|
+
if (said !== undefined && isFixedFailure(said))
|
|
583
|
+
fatal = said;
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
default:
|
|
587
|
+
pushCustom(event, scopeOf(path), out);
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
/**
|
|
591
|
+
* The open call a `tool_end` closes. One agent runs its calls one at a time,
|
|
592
|
+
* so the open call at the result's stage execution is the one it answers;
|
|
593
|
+
* where the record still names the call (no redaction policy), the id
|
|
594
|
+
* decides among several.
|
|
595
|
+
*/
|
|
596
|
+
function takeCall(scope, address, servedId) {
|
|
597
|
+
let at = -1;
|
|
598
|
+
for (let i = scope.calls.length - 1; i >= 0; i--) {
|
|
599
|
+
const call = scope.calls[i];
|
|
600
|
+
if (call.address !== address)
|
|
601
|
+
continue;
|
|
602
|
+
if (at < 0)
|
|
603
|
+
at = i;
|
|
604
|
+
if (typeof servedId === 'string' && call.servedId === servedId) {
|
|
605
|
+
at = i;
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
// The call a paused run left open is answered by the first result in its
|
|
610
|
+
// scope: the continuation's stage executions are new, so no address matches.
|
|
611
|
+
if (at < 0)
|
|
612
|
+
at = scope.calls.findIndex((call) => call.resumed === true);
|
|
613
|
+
return at < 0 ? undefined : scope.calls.splice(at, 1)[0];
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Re-open what the paused run left open — the scopes (same `subagentRunId`),
|
|
617
|
+
* their steps and the call it stopped in — and return the events that say so,
|
|
618
|
+
* for `start` to write after `RUN_STARTED`.
|
|
619
|
+
*/
|
|
620
|
+
function restore(from) {
|
|
621
|
+
const events = [];
|
|
622
|
+
root.isAgent = from.rootAgent;
|
|
623
|
+
for (const kept of from.scopes) {
|
|
624
|
+
let scope = root;
|
|
625
|
+
if (kept.subagentRunId !== undefined) {
|
|
626
|
+
scope = newScope(kept.mount, kept.subagentRunId, kept.name, kept.parentSubagentRunId);
|
|
627
|
+
scope.isAgent = true;
|
|
628
|
+
scopes.push(scope);
|
|
629
|
+
events.push({
|
|
630
|
+
type: 'SUBAGENT_STARTED',
|
|
631
|
+
subagentRunId: kept.subagentRunId,
|
|
632
|
+
name: kept.name ?? kept.mount.join('/'),
|
|
633
|
+
...(kept.parentSubagentRunId !== undefined && {
|
|
634
|
+
parentSubagentRunId: kept.parentSubagentRunId,
|
|
635
|
+
}),
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
for (const stepName of kept.steps) {
|
|
639
|
+
scope.steps.push(stepName);
|
|
640
|
+
events.push({ type: 'STEP_STARTED', stepName, ...owned(scope) });
|
|
641
|
+
}
|
|
642
|
+
for (const call of kept.calls) {
|
|
643
|
+
scope.calls.push({
|
|
644
|
+
id: call.toolCallId,
|
|
645
|
+
n: -1,
|
|
646
|
+
address: '',
|
|
647
|
+
servedId: undefined,
|
|
648
|
+
resumed: true,
|
|
649
|
+
client: call.client,
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
if (kept.messageId !== undefined)
|
|
653
|
+
scope.callMessageId = kept.messageId;
|
|
654
|
+
}
|
|
655
|
+
return events;
|
|
656
|
+
}
|
|
657
|
+
/** The record a continuation resumes from: every scope open now, with its steps. */
|
|
658
|
+
function suspensionOf(interruptId, call) {
|
|
659
|
+
const kept = scopes.map((scope) => ({
|
|
660
|
+
mount: [...scope.mount],
|
|
661
|
+
...(scope.subagentRunId !== undefined && { subagentRunId: scope.subagentRunId }),
|
|
662
|
+
...(scope.name !== undefined && { name: scope.name }),
|
|
663
|
+
...(scope.parentSubagentRunId !== undefined && {
|
|
664
|
+
parentSubagentRunId: scope.parentSubagentRunId,
|
|
665
|
+
}),
|
|
666
|
+
steps: [...scope.steps],
|
|
667
|
+
calls: scope.calls.map((open) => ({
|
|
668
|
+
toolCallId: open.id,
|
|
669
|
+
client: open.id === call?.toolCallId ? call.client : open.client === true,
|
|
670
|
+
})),
|
|
671
|
+
...(scope.callMessageId !== undefined && { messageId: scope.callMessageId }),
|
|
672
|
+
}));
|
|
673
|
+
return {
|
|
674
|
+
version: 1,
|
|
675
|
+
runId,
|
|
676
|
+
...(interruptId !== undefined && { interruptId }),
|
|
677
|
+
...(call !== undefined && { call }),
|
|
678
|
+
rootAgent: root.isAgent,
|
|
679
|
+
scopes: kept,
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* `event` as CUSTOM — only when its type is on the allow-list, carrying only
|
|
684
|
+
* the fields its projection picks from the served payload, through the wire
|
|
685
|
+
* rule. An unlisted event writes nothing.
|
|
686
|
+
*/
|
|
687
|
+
function pushCustom(event, scope, out) {
|
|
688
|
+
const project = Object.prototype.hasOwnProperty.call(custom, event.type)
|
|
689
|
+
? custom[event.type]
|
|
690
|
+
: undefined;
|
|
691
|
+
if (typeof project !== 'function')
|
|
692
|
+
return;
|
|
693
|
+
const call = scope.calls[scope.calls.length - 1];
|
|
694
|
+
const value = project(record(event.payload), call === undefined ? {} : { toolCallId: call.id });
|
|
695
|
+
out.push({
|
|
696
|
+
type: 'CUSTOM',
|
|
697
|
+
name: event.type,
|
|
698
|
+
value: (0, wireJson_js_1.withWireErrors)(value ?? null),
|
|
699
|
+
...owned(scope, event),
|
|
700
|
+
metadata: addressOf(event),
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* What a pause leaves for its continuation, as of now: on whom it waits
|
|
705
|
+
* decides whether the open call is the client's (a frontend tool) or the
|
|
706
|
+
* interrupt's. Pure apart from minting the interrupt once.
|
|
707
|
+
*/
|
|
708
|
+
const pausedRecord = (awaiting) => {
|
|
709
|
+
const at = pause?.scope ?? root;
|
|
710
|
+
const open = at.calls[at.calls.length - 1];
|
|
711
|
+
if (awaiting === 'caller' && open !== undefined) {
|
|
712
|
+
return {
|
|
713
|
+
record: suspensionOf(undefined, {
|
|
714
|
+
toolCallId: open.id,
|
|
715
|
+
mount: [...at.mount],
|
|
716
|
+
client: true,
|
|
717
|
+
}),
|
|
718
|
+
clientCall: open.id,
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
return {
|
|
722
|
+
record: suspensionOf(interruptOf().id, open === undefined
|
|
723
|
+
? undefined
|
|
724
|
+
: { toolCallId: open.id, mount: [...at.mount], client: false }),
|
|
725
|
+
};
|
|
726
|
+
};
|
|
727
|
+
/** What `RUN_STARTED` is followed by in a continuation: the scopes and steps it re-opens. */
|
|
728
|
+
const reopened = options.resume === undefined ? [] : restore(options.resume);
|
|
729
|
+
const start = (out) => {
|
|
730
|
+
if (started)
|
|
731
|
+
return;
|
|
732
|
+
started = true;
|
|
733
|
+
out.push({
|
|
734
|
+
type: 'RUN_STARTED',
|
|
735
|
+
threadId,
|
|
736
|
+
runId,
|
|
737
|
+
protocolVersion: types_js_1.AG_UI_PROTOCOL_VERSION,
|
|
738
|
+
});
|
|
739
|
+
out.push(...reopened);
|
|
740
|
+
};
|
|
741
|
+
/** The interrupt a person-awaited pause hands out — minted once, so a record kept before settling names it. */
|
|
742
|
+
let interrupt;
|
|
743
|
+
const interruptOf = () => (interrupt ??= mintInterrupt());
|
|
744
|
+
const mintInterrupt = () => {
|
|
745
|
+
if (pause === undefined)
|
|
746
|
+
return { id: ids.next('interrupt', 'run').id, reason: 'paused' };
|
|
747
|
+
const { event, scope } = pause;
|
|
748
|
+
const payload = record(event.payload);
|
|
749
|
+
// The question a person is asked, as the record serves it — and nothing
|
|
750
|
+
// else of the pause's payload (a check-in's evidence pack, a typed ask's
|
|
751
|
+
// context), which a browser has no reason to receive.
|
|
752
|
+
const message = questionOf(record(payload.questionPayload));
|
|
753
|
+
const call = scope.calls[scope.calls.length - 1];
|
|
754
|
+
return {
|
|
755
|
+
id: ids.next('interrupt', event.meta.runtimeStageId).id,
|
|
756
|
+
reason: text(payload.reason) ?? 'paused',
|
|
757
|
+
...(message !== undefined && { message }),
|
|
758
|
+
...(call !== undefined && { toolCallId: call.id }),
|
|
759
|
+
...(scope.subagentRunId !== undefined && { subagentRunId: scope.subagentRunId }),
|
|
760
|
+
metadata: addressOf(event),
|
|
761
|
+
};
|
|
762
|
+
};
|
|
763
|
+
/** Close every open nested scope, deepest first, each with the terminal `end` names for it. */
|
|
764
|
+
const endAllNested = (out, end) => {
|
|
765
|
+
for (const scope of scopesUnder(root.mount))
|
|
766
|
+
closeScope(scope, out, end(scope));
|
|
767
|
+
};
|
|
768
|
+
return {
|
|
769
|
+
event(event) {
|
|
770
|
+
if (settled)
|
|
771
|
+
return [];
|
|
772
|
+
if (owns !== undefined && !owns(event))
|
|
773
|
+
return [];
|
|
774
|
+
const named = event.meta?.runId;
|
|
775
|
+
const namesRun = typeof named === 'string' && named !== eventMeta_js_1.CONSUMER_SCOPE_RUN_ID;
|
|
776
|
+
if (namesRun) {
|
|
777
|
+
// Without `owns`, the first run an event names is this run's, and
|
|
778
|
+
// another run's event is never this run's to translate.
|
|
779
|
+
if (recordRunId === undefined)
|
|
780
|
+
recordRunId = named;
|
|
781
|
+
else if (owns === undefined && named !== recordRunId)
|
|
782
|
+
return [];
|
|
783
|
+
}
|
|
784
|
+
const body = [];
|
|
785
|
+
translate(event, body);
|
|
786
|
+
// `RUN_STARTED` waits for the run to name itself (or to say something):
|
|
787
|
+
// a continuation opens with the resume's own bookkeeping, which names no
|
|
788
|
+
// run, and the run's id belongs on its first event.
|
|
789
|
+
if (!started && !namesRun && body.length === 0)
|
|
790
|
+
return [];
|
|
791
|
+
const out = [];
|
|
792
|
+
start(out);
|
|
793
|
+
out.push(...body);
|
|
794
|
+
return out;
|
|
795
|
+
},
|
|
796
|
+
settle(settlement) {
|
|
797
|
+
if (settled)
|
|
798
|
+
return [];
|
|
799
|
+
settled = true;
|
|
800
|
+
const out = [];
|
|
801
|
+
start(out);
|
|
802
|
+
switch (settlement.kind) {
|
|
803
|
+
case 'failed':
|
|
804
|
+
// The record's own words for the failure, never the thrown value.
|
|
805
|
+
out.push({
|
|
806
|
+
type: 'RUN_ERROR',
|
|
807
|
+
message: fatal ?? exports.AG_UI_RUN_FAILED,
|
|
808
|
+
});
|
|
809
|
+
return out;
|
|
810
|
+
case 'paused': {
|
|
811
|
+
const { record, clientCall } = pausedRecord(settlement.awaiting);
|
|
812
|
+
suspended = record;
|
|
813
|
+
if (clientCall !== undefined) {
|
|
814
|
+
// A tool the client runs: the run COMPLETED this segment and left
|
|
815
|
+
// the call for the application to answer in its next input.
|
|
816
|
+
endAllNested(out, () => (subagentRunId) => ({
|
|
817
|
+
type: 'SUBAGENT_FINISHED',
|
|
818
|
+
subagentRunId,
|
|
819
|
+
outcome: { type: 'suspended' },
|
|
820
|
+
}));
|
|
821
|
+
closeContents(root, out);
|
|
822
|
+
out.push({
|
|
823
|
+
type: 'RUN_FINISHED',
|
|
824
|
+
threadId,
|
|
825
|
+
runId,
|
|
826
|
+
outcome: { type: 'success', pendingToolCallIds: [clientCall] },
|
|
827
|
+
});
|
|
828
|
+
return out;
|
|
829
|
+
}
|
|
830
|
+
const interrupt = interruptOf();
|
|
831
|
+
endAllNested(out, (scope) => (subagentRunId) => ({
|
|
832
|
+
type: 'SUBAGENT_FINISHED',
|
|
833
|
+
subagentRunId,
|
|
834
|
+
outcome: {
|
|
835
|
+
type: 'suspended',
|
|
836
|
+
...(pause?.scope === scope && { interruptIds: [interrupt.id] }),
|
|
837
|
+
},
|
|
838
|
+
}));
|
|
839
|
+
closeContents(root, out);
|
|
840
|
+
out.push({
|
|
841
|
+
type: 'RUN_FINISHED',
|
|
842
|
+
threadId,
|
|
843
|
+
runId,
|
|
844
|
+
outcome: { type: 'interrupt', interrupts: [interrupt] },
|
|
845
|
+
});
|
|
846
|
+
return out;
|
|
847
|
+
}
|
|
848
|
+
case 'cancelled':
|
|
849
|
+
endAllNested(out, () => (subagentRunId) => ({
|
|
850
|
+
type: 'SUBAGENT_ERROR',
|
|
851
|
+
subagentRunId,
|
|
852
|
+
message: exports.AG_UI_SUBAGENT_CANCELLED,
|
|
853
|
+
code: 'cancelled',
|
|
854
|
+
}));
|
|
855
|
+
closeContents(root, out);
|
|
856
|
+
out.push({
|
|
857
|
+
type: 'RUN_FINISHED',
|
|
858
|
+
threadId,
|
|
859
|
+
runId,
|
|
860
|
+
outcome: { type: 'cancelled' },
|
|
861
|
+
});
|
|
862
|
+
return out;
|
|
863
|
+
case 'finished':
|
|
864
|
+
endAllNested(out, () => unfinished);
|
|
865
|
+
closeContents(root, out);
|
|
866
|
+
out.push({
|
|
867
|
+
type: 'RUN_FINISHED',
|
|
868
|
+
threadId,
|
|
869
|
+
runId,
|
|
870
|
+
...(rootResult !== undefined && { result: rootResult }),
|
|
871
|
+
});
|
|
872
|
+
return out;
|
|
873
|
+
}
|
|
874
|
+
},
|
|
875
|
+
suspension: (awaiting) => {
|
|
876
|
+
if (settled)
|
|
877
|
+
return suspended;
|
|
878
|
+
return pausedRecord(awaiting).record;
|
|
879
|
+
},
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
exports.agUiSerializer = agUiSerializer;
|
|
883
|
+
/**
|
|
884
|
+
* The question a pause put to a person, from whichever home its kind keeps it
|
|
885
|
+
* in: a plain ask (`askHuman` / `pauseHere` / an input request) at the top, a
|
|
886
|
+
* middleware's ask on `ask.question`, a check-in as the plain-words claim of
|
|
887
|
+
* what the tool will do (`checkIn.evidence.willDo`).
|
|
888
|
+
*/
|
|
889
|
+
function questionOf(payload) {
|
|
890
|
+
return (text(payload.question) ??
|
|
891
|
+
text(record(payload.ask).question) ??
|
|
892
|
+
text(record(record(payload.checkIn).evidence).willDo));
|
|
893
|
+
}
|
|
894
|
+
/** A composition's step name: its kind, and where it is mounted when it is not the run itself. */
|
|
895
|
+
function compositionStep(kind, path) {
|
|
896
|
+
const name = typeof kind === 'string' && kind.length > 0 ? kind : 'Composition';
|
|
897
|
+
return path.length === 0 ? name : `${name}:${path.join('/')}`;
|
|
898
|
+
}
|
|
899
|
+
//# sourceMappingURL=serializer.js.map
|