@adonis-agora/agent 0.61.0 → 0.63.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/CHANGELOG.md +91 -0
- package/README.md +12 -7
- package/dist/configure.d.ts +7 -5
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +7 -5
- package/dist/configure.js.map +1 -1
- package/dist/providers/a2a_provider.d.ts +14 -0
- package/dist/providers/a2a_provider.d.ts.map +1 -0
- package/dist/providers/a2a_provider.js +136 -0
- package/dist/providers/a2a_provider.js.map +1 -0
- package/dist/providers/agent_provider.d.ts.map +1 -1
- package/dist/providers/agent_provider.js +81 -25
- package/dist/providers/agent_provider.js.map +1 -1
- package/dist/providers/mcp_provider.d.ts +3 -0
- package/dist/providers/mcp_provider.d.ts.map +1 -1
- package/dist/providers/mcp_provider.js +147 -62
- package/dist/providers/mcp_provider.js.map +1 -1
- package/dist/src/a2a/auth.d.ts +67 -0
- package/dist/src/a2a/auth.d.ts.map +1 -0
- package/dist/src/a2a/auth.js +47 -0
- package/dist/src/a2a/auth.js.map +1 -0
- package/dist/src/a2a/define_config.d.ts +74 -0
- package/dist/src/a2a/define_config.d.ts.map +1 -0
- package/dist/src/a2a/define_config.js +5 -0
- package/dist/src/a2a/define_config.js.map +1 -0
- package/dist/src/a2a/gate.d.ts +23 -0
- package/dist/src/a2a/gate.d.ts.map +1 -0
- package/dist/src/a2a/gate.js +56 -0
- package/dist/src/a2a/gate.js.map +1 -0
- package/dist/src/a2a/handler.d.ts +65 -0
- package/dist/src/a2a/handler.d.ts.map +1 -0
- package/dist/src/a2a/handler.js +322 -0
- package/dist/src/a2a/handler.js.map +1 -0
- package/dist/src/a2a/index.d.ts +15 -0
- package/dist/src/a2a/index.d.ts.map +1 -0
- package/dist/src/a2a/index.js +9 -0
- package/dist/src/a2a/index.js.map +1 -0
- package/dist/src/a2a/permission-tool.d.ts +17 -0
- package/dist/src/a2a/permission-tool.d.ts.map +1 -0
- package/dist/src/a2a/permission-tool.js +70 -0
- package/dist/src/a2a/permission-tool.js.map +1 -0
- package/dist/src/a2a/protocol.d.ts +100 -0
- package/dist/src/a2a/protocol.d.ts.map +1 -0
- package/dist/src/a2a/protocol.js +106 -0
- package/dist/src/a2a/protocol.js.map +1 -0
- package/dist/src/a2a/runtime.d.ts +6 -0
- package/dist/src/a2a/runtime.d.ts.map +1 -0
- package/dist/src/a2a/runtime.js +13 -0
- package/dist/src/a2a/runtime.js.map +1 -0
- package/dist/src/a2a/server_middleware.d.ts +13 -0
- package/dist/src/a2a/server_middleware.d.ts.map +1 -0
- package/dist/src/a2a/server_middleware.js +18 -0
- package/dist/src/a2a/server_middleware.js.map +1 -0
- package/dist/src/a2a/store.d.ts +79 -0
- package/dist/src/a2a/store.d.ts.map +1 -0
- package/dist/src/a2a/store.js +151 -0
- package/dist/src/a2a/store.js.map +1 -0
- package/dist/src/a2a/turn.d.ts +80 -0
- package/dist/src/a2a/turn.d.ts.map +1 -0
- package/dist/src/a2a/turn.js +211 -0
- package/dist/src/a2a/turn.js.map +1 -0
- package/dist/src/action-proposal-executor.d.ts +3 -0
- package/dist/src/action-proposal-executor.d.ts.map +1 -1
- package/dist/src/action-proposal-executor.js +10 -0
- package/dist/src/action-proposal-executor.js.map +1 -1
- package/dist/src/action-proposal-service.d.ts +7 -2
- package/dist/src/action-proposal-service.d.ts.map +1 -1
- package/dist/src/action-proposal-service.js +21 -16
- package/dist/src/action-proposal-service.js.map +1 -1
- package/dist/src/action-proposal-text.d.ts +42 -3
- package/dist/src/action-proposal-text.d.ts.map +1 -1
- package/dist/src/action-proposal-text.js +80 -12
- package/dist/src/action-proposal-text.js.map +1 -1
- package/dist/src/action-proposal-worker.d.ts +2 -1
- package/dist/src/action-proposal-worker.d.ts.map +1 -1
- package/dist/src/action-proposal-worker.js +9 -2
- package/dist/src/action-proposal-worker.js.map +1 -1
- package/dist/src/actor-resolver.d.ts +12 -4
- package/dist/src/actor-resolver.d.ts.map +1 -1
- package/dist/src/actor-resolver.js +24 -7
- package/dist/src/actor-resolver.js.map +1 -1
- package/dist/src/ag-ui/adapter.d.ts.map +1 -1
- package/dist/src/ag-ui/adapter.js +115 -17
- package/dist/src/ag-ui/adapter.js.map +1 -1
- package/dist/src/ag-ui/core/encoder.d.ts +106 -0
- package/dist/src/ag-ui/core/encoder.d.ts.map +1 -0
- package/dist/src/ag-ui/core/encoder.js +534 -0
- package/dist/src/ag-ui/core/encoder.js.map +1 -0
- package/dist/src/ag-ui/core/index.d.ts +12 -0
- package/dist/src/ag-ui/core/index.d.ts.map +1 -0
- package/dist/src/ag-ui/core/index.js +12 -0
- package/dist/src/ag-ui/core/index.js.map +1 -0
- package/dist/src/ag-ui/core/input.d.ts +92 -0
- package/dist/src/ag-ui/core/input.d.ts.map +1 -0
- package/dist/src/ag-ui/core/input.js +246 -0
- package/dist/src/ag-ui/core/input.js.map +1 -0
- package/dist/src/ag-ui/core/interrupt-id.d.ts +31 -0
- package/dist/src/ag-ui/core/interrupt-id.d.ts.map +1 -0
- package/dist/src/ag-ui/core/interrupt-id.js +48 -0
- package/dist/src/ag-ui/core/interrupt-id.js.map +1 -0
- package/dist/src/ag-ui/{proposal-decision.d.ts → core/proposal-decision.d.ts} +1 -1
- package/dist/src/ag-ui/core/proposal-decision.d.ts.map +1 -0
- package/dist/src/ag-ui/{proposal-decision.js → core/proposal-decision.js} +3 -6
- package/dist/src/ag-ui/core/proposal-decision.js.map +1 -0
- package/dist/src/ag-ui/core/stream.d.ts +49 -0
- package/dist/src/ag-ui/core/stream.d.ts.map +1 -0
- package/dist/src/ag-ui/core/stream.js +90 -0
- package/dist/src/ag-ui/core/stream.js.map +1 -0
- package/dist/src/ag-ui/core/types.d.ts +249 -0
- package/dist/src/ag-ui/core/types.d.ts.map +1 -0
- package/dist/src/ag-ui/core/types.js +35 -0
- package/dist/src/ag-ui/core/types.js.map +1 -0
- package/dist/src/ag-ui/encoder.d.ts +3 -4
- package/dist/src/ag-ui/encoder.d.ts.map +1 -1
- package/dist/src/ag-ui/encoder.js +10 -11
- package/dist/src/ag-ui/encoder.js.map +1 -1
- package/dist/src/ag-ui/frames.d.ts +8 -5
- package/dist/src/ag-ui/frames.d.ts.map +1 -1
- package/dist/src/ag-ui/frames.js +21 -7
- package/dist/src/ag-ui/frames.js.map +1 -1
- package/dist/src/ag-ui/index.d.ts +3 -5
- package/dist/src/ag-ui/index.d.ts.map +1 -1
- package/dist/src/ag-ui/index.js +3 -5
- package/dist/src/ag-ui/index.js.map +1 -1
- package/dist/src/ag-ui/stream.d.ts +3 -4
- package/dist/src/ag-ui/stream.d.ts.map +1 -1
- package/dist/src/ag-ui/stream.js +4 -5
- package/dist/src/ag-ui/stream.js.map +1 -1
- package/dist/src/agent-deps-factory.d.ts +3 -0
- package/dist/src/agent-deps-factory.d.ts.map +1 -1
- package/dist/src/agent-deps-factory.js +3 -0
- package/dist/src/agent-deps-factory.js.map +1 -1
- package/dist/src/agent-deps.d.ts +3 -0
- package/dist/src/agent-deps.d.ts.map +1 -1
- package/dist/src/agent-deps.js.map +1 -1
- package/dist/src/agent-loop.d.ts +4 -3
- package/dist/src/agent-loop.d.ts.map +1 -1
- package/dist/src/agent-loop.js +50 -25
- package/dist/src/agent-loop.js.map +1 -1
- package/dist/src/agent-service.d.ts +46 -4
- package/dist/src/agent-service.d.ts.map +1 -1
- package/dist/src/agent-service.js +87 -11
- package/dist/src/agent-service.js.map +1 -1
- package/dist/src/ai-sdk/ai-sdk-model.js +4 -1
- package/dist/src/ai-sdk/ai-sdk-model.js.map +1 -1
- package/dist/src/ai-tool-ref.d.ts +4 -0
- package/dist/src/ai-tool-ref.d.ts.map +1 -1
- package/dist/src/ai-tool-ref.js +10 -14
- package/dist/src/ai-tool-ref.js.map +1 -1
- package/dist/src/attachment-limits.d.ts +10 -0
- package/dist/src/attachment-limits.d.ts.map +1 -0
- package/dist/src/attachment-limits.js +13 -0
- package/dist/src/attachment-limits.js.map +1 -0
- package/dist/src/channels/adapters/evolution_api.d.ts +49 -0
- package/dist/src/channels/adapters/evolution_api.d.ts.map +1 -0
- package/dist/src/channels/adapters/evolution_api.js +241 -0
- package/dist/src/channels/adapters/evolution_api.js.map +1 -0
- package/dist/src/channels/adapters/telegram.d.ts +34 -0
- package/dist/src/channels/adapters/telegram.d.ts.map +1 -0
- package/dist/src/channels/adapters/telegram.js +196 -0
- package/dist/src/channels/adapters/telegram.js.map +1 -0
- package/dist/src/channels/adapters/whatsapp_cloud.d.ts +31 -0
- package/dist/src/channels/adapters/whatsapp_cloud.d.ts.map +1 -0
- package/dist/src/channels/adapters/whatsapp_cloud.js +177 -0
- package/dist/src/channels/adapters/whatsapp_cloud.js.map +1 -0
- package/dist/src/channels/handler.d.ts +167 -0
- package/dist/src/channels/handler.d.ts.map +1 -0
- package/dist/src/channels/handler.js +569 -0
- package/dist/src/channels/handler.js.map +1 -0
- package/dist/src/channels/http.d.ts +45 -0
- package/dist/src/channels/http.d.ts.map +1 -0
- package/dist/src/channels/http.js +147 -0
- package/dist/src/channels/http.js.map +1 -0
- package/dist/src/channels/index.d.ts +16 -0
- package/dist/src/channels/index.d.ts.map +1 -0
- package/dist/src/channels/index.js +15 -0
- package/dist/src/channels/index.js.map +1 -0
- package/dist/src/channels/markdown.d.ts +12 -0
- package/dist/src/channels/markdown.d.ts.map +1 -0
- package/dist/src/channels/markdown.js +120 -0
- package/dist/src/channels/markdown.js.map +1 -0
- package/dist/src/channels/questions.d.ts +43 -0
- package/dist/src/channels/questions.d.ts.map +1 -0
- package/dist/src/channels/questions.js +90 -0
- package/dist/src/channels/questions.js.map +1 -0
- package/dist/src/channels/split.d.ts +8 -0
- package/dist/src/channels/split.d.ts.map +1 -0
- package/dist/src/channels/split.js +45 -0
- package/dist/src/channels/split.js.map +1 -0
- package/dist/src/channels/store.d.ts +78 -0
- package/dist/src/channels/store.d.ts.map +1 -0
- package/dist/src/channels/store.js +151 -0
- package/dist/src/channels/store.js.map +1 -0
- package/dist/src/channels/types.d.ts +138 -0
- package/dist/src/channels/types.d.ts.map +1 -0
- package/dist/src/channels/types.js +7 -0
- package/dist/src/channels/types.js.map +1 -0
- package/dist/src/chat-queue-service.d.ts.map +1 -1
- package/dist/src/chat-queue-service.js +2 -0
- package/dist/src/chat-queue-service.js.map +1 -1
- package/dist/src/define_config.d.ts +61 -12
- package/dist/src/define_config.d.ts.map +1 -1
- package/dist/src/define_config.js.map +1 -1
- package/dist/src/engine.d.ts +77 -0
- package/dist/src/engine.d.ts.map +1 -0
- package/dist/src/engine.js +27 -0
- package/dist/src/engine.js.map +1 -0
- package/dist/src/genui/builtins.d.ts +73 -3
- package/dist/src/genui/builtins.d.ts.map +1 -1
- package/dist/src/genui/builtins.js +357 -3
- package/dist/src/genui/builtins.js.map +1 -1
- package/dist/src/genui/capabilities.d.ts +24 -0
- package/dist/src/genui/capabilities.d.ts.map +1 -0
- package/dist/src/genui/capabilities.js +81 -0
- package/dist/src/genui/capabilities.js.map +1 -0
- package/dist/src/genui/catalog.d.ts +86 -0
- package/dist/src/genui/catalog.d.ts.map +1 -0
- package/dist/src/genui/catalog.js +96 -0
- package/dist/src/genui/catalog.js.map +1 -0
- package/dist/src/genui/factory.d.ts +7 -14
- package/dist/src/genui/factory.d.ts.map +1 -1
- package/dist/src/genui/factory.js.map +1 -1
- package/dist/src/genui/index.d.ts +4 -12
- package/dist/src/genui/index.d.ts.map +1 -1
- package/dist/src/genui/index.js +5 -18
- package/dist/src/genui/index.js.map +1 -1
- package/dist/src/genui/public.d.ts +9 -0
- package/dist/src/genui/public.d.ts.map +1 -0
- package/dist/src/genui/public.js +9 -0
- package/dist/src/genui/public.js.map +1 -0
- package/dist/src/genui/registry.d.ts +65 -0
- package/dist/src/genui/registry.d.ts.map +1 -0
- package/dist/src/genui/registry.js +151 -0
- package/dist/src/genui/registry.js.map +1 -0
- package/dist/src/genui/schema.d.ts +71 -0
- package/dist/src/genui/schema.d.ts.map +1 -0
- package/dist/src/genui/schema.js +304 -0
- package/dist/src/genui/schema.js.map +1 -0
- package/dist/src/genui/text.d.ts +36 -0
- package/dist/src/genui/text.d.ts.map +1 -0
- package/dist/src/genui/text.js +157 -0
- package/dist/src/genui/text.js.map +1 -0
- package/dist/src/genui/tools.d.ts +92 -0
- package/dist/src/genui/tools.d.ts.map +1 -0
- package/dist/src/genui/tools.js +291 -0
- package/dist/src/genui/tools.js.map +1 -0
- package/dist/src/genui/tree.d.ts +56 -0
- package/dist/src/genui/tree.d.ts.map +1 -0
- package/dist/src/genui/tree.js +188 -0
- package/dist/src/genui/tree.js.map +1 -0
- package/dist/src/index.d.ts +6 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/auth.d.ts +17 -1
- package/dist/src/mcp/auth.d.ts.map +1 -1
- package/dist/src/mcp/auth.js +14 -3
- package/dist/src/mcp/auth.js.map +1 -1
- package/dist/src/mcp/define_config.d.ts +81 -2
- package/dist/src/mcp/define_config.d.ts.map +1 -1
- package/dist/src/mcp/define_config.js.map +1 -1
- package/dist/src/mcp/index.d.ts +1 -1
- package/dist/src/mcp/index.d.ts.map +1 -1
- package/dist/src/mcp/index.js.map +1 -1
- package/dist/src/mcp/oauth-resource.d.ts +9 -0
- package/dist/src/mcp/oauth-resource.d.ts.map +1 -0
- package/dist/src/mcp/oauth-resource.js +16 -0
- package/dist/src/mcp/oauth-resource.js.map +1 -0
- package/dist/src/mcp/server.d.ts +5 -0
- package/dist/src/mcp/server.d.ts.map +1 -1
- package/dist/src/mcp/server.js +48 -16
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/negotiated-tool-ui.d.ts.map +1 -1
- package/dist/src/negotiated-tool-ui.js +12 -8
- package/dist/src/negotiated-tool-ui.js.map +1 -1
- package/dist/src/opencode/client.d.ts +202 -0
- package/dist/src/opencode/client.d.ts.map +1 -0
- package/dist/src/opencode/client.js +2 -0
- package/dist/src/opencode/client.js.map +1 -0
- package/dist/src/opencode/durable/index.d.ts +33 -0
- package/dist/src/opencode/durable/index.d.ts.map +1 -0
- package/dist/src/opencode/durable/index.js +38 -0
- package/dist/src/opencode/durable/index.js.map +1 -0
- package/dist/src/opencode/durable/runner.d.ts +36 -0
- package/dist/src/opencode/durable/runner.d.ts.map +1 -0
- package/dist/src/opencode/durable/runner.js +88 -0
- package/dist/src/opencode/durable/runner.js.map +1 -0
- package/dist/src/opencode/durable/workflow.d.ts +40 -0
- package/dist/src/opencode/durable/workflow.d.ts.map +1 -0
- package/dist/src/opencode/durable/workflow.js +106 -0
- package/dist/src/opencode/durable/workflow.js.map +1 -0
- package/dist/src/opencode/engine.d.ts +48 -0
- package/dist/src/opencode/engine.d.ts.map +1 -0
- package/dist/src/opencode/engine.js +98 -0
- package/dist/src/opencode/engine.js.map +1 -0
- package/dist/src/opencode/event-hub.d.ts +23 -0
- package/dist/src/opencode/event-hub.d.ts.map +1 -0
- package/dist/src/opencode/event-hub.js +99 -0
- package/dist/src/opencode/event-hub.js.map +1 -0
- package/dist/src/opencode/forms.d.ts +19 -0
- package/dist/src/opencode/forms.d.ts.map +1 -0
- package/dist/src/opencode/forms.js +82 -0
- package/dist/src/opencode/forms.js.map +1 -0
- package/dist/src/opencode/host.d.ts +179 -0
- package/dist/src/opencode/host.d.ts.map +1 -0
- package/dist/src/opencode/host.js +34 -0
- package/dist/src/opencode/host.js.map +1 -0
- package/dist/src/opencode/index.d.ts +15 -0
- package/dist/src/opencode/index.d.ts.map +1 -0
- package/dist/src/opencode/index.js +9 -0
- package/dist/src/opencode/index.js.map +1 -0
- package/dist/src/opencode/log.d.ts +9 -0
- package/dist/src/opencode/log.d.ts.map +1 -0
- package/dist/src/opencode/log.js +15 -0
- package/dist/src/opencode/log.js.map +1 -0
- package/dist/src/opencode/mcp.d.ts +60 -0
- package/dist/src/opencode/mcp.d.ts.map +1 -0
- package/dist/src/opencode/mcp.js +258 -0
- package/dist/src/opencode/mcp.js.map +1 -0
- package/dist/src/opencode/runner.d.ts +40 -0
- package/dist/src/opencode/runner.d.ts.map +1 -0
- package/dist/src/opencode/runner.js +125 -0
- package/dist/src/opencode/runner.js.map +1 -0
- package/dist/src/opencode/turn.d.ts +167 -0
- package/dist/src/opencode/turn.d.ts.map +1 -0
- package/dist/src/opencode/turn.js +761 -0
- package/dist/src/opencode/turn.js.map +1 -0
- package/dist/src/opencode/turns.d.ts +247 -0
- package/dist/src/opencode/turns.d.ts.map +1 -0
- package/dist/src/opencode/turns.js +867 -0
- package/dist/src/opencode/turns.js.map +1 -0
- package/dist/src/personas.d.ts.map +1 -1
- package/dist/src/personas.js +4 -1
- package/dist/src/personas.js.map +1 -1
- package/dist/src/react/ag-ui.d.ts +4 -2
- package/dist/src/react/ag-ui.d.ts.map +1 -1
- package/dist/src/react/ag-ui.js +2 -2
- package/dist/src/react/ag-ui.js.map +1 -1
- package/dist/src/react/client.d.ts +1 -1
- package/dist/src/react/client.d.ts.map +1 -1
- package/dist/src/react/client.js +1 -1
- package/dist/src/react/client.js.map +1 -1
- package/dist/src/react/core/ag-ui-backend.d.ts +109 -0
- package/dist/src/react/core/ag-ui-backend.d.ts.map +1 -0
- package/dist/src/react/core/ag-ui-backend.js +574 -0
- package/dist/src/react/core/ag-ui-backend.js.map +1 -0
- package/dist/src/react/core/agent-chat-transport.d.ts +187 -0
- package/dist/src/react/core/agent-chat-transport.d.ts.map +1 -0
- package/dist/src/react/core/agent-chat-transport.js +817 -0
- package/dist/src/react/core/agent-chat-transport.js.map +1 -0
- package/dist/src/react/core/approvals/countdown.d.ts +22 -0
- package/dist/src/react/core/approvals/countdown.d.ts.map +1 -0
- package/dist/src/react/core/approvals/countdown.js +39 -0
- package/dist/src/react/core/approvals/countdown.js.map +1 -0
- package/dist/src/react/core/approvals/proposals.d.ts +15 -0
- package/dist/src/react/core/approvals/proposals.d.ts.map +1 -0
- package/dist/src/react/core/approvals/proposals.js +82 -0
- package/dist/src/react/core/approvals/proposals.js.map +1 -0
- package/dist/src/react/core/approvals/use-action-proposals.d.ts +10 -0
- package/dist/src/react/core/approvals/use-action-proposals.d.ts.map +1 -0
- package/dist/src/react/core/approvals/use-action-proposals.js +86 -0
- package/dist/src/react/core/approvals/use-action-proposals.js.map +1 -0
- package/dist/src/react/core/attachments/files.d.ts +39 -0
- package/dist/src/react/core/attachments/files.d.ts.map +1 -0
- package/dist/src/react/core/attachments/files.js +89 -0
- package/dist/src/react/core/attachments/files.js.map +1 -0
- package/dist/src/react/core/attachments/use-attachments.d.ts +106 -0
- package/dist/src/react/core/attachments/use-attachments.d.ts.map +1 -0
- package/dist/src/react/core/attachments/use-attachments.js +217 -0
- package/dist/src/react/core/attachments/use-attachments.js.map +1 -0
- package/dist/src/react/core/backend.d.ts +245 -0
- package/dist/src/react/core/backend.d.ts.map +1 -0
- package/dist/src/react/core/backend.js +21 -0
- package/dist/src/react/core/backend.js.map +1 -0
- package/dist/src/react/core/background-runs.d.ts +32 -0
- package/dist/src/react/core/background-runs.d.ts.map +1 -0
- package/dist/src/react/core/background-runs.js +47 -0
- package/dist/src/react/core/background-runs.js.map +1 -0
- package/dist/src/react/core/catalog/use-agents.d.ts +31 -0
- package/dist/src/react/core/catalog/use-agents.d.ts.map +1 -0
- package/dist/src/react/core/catalog/use-agents.js +28 -0
- package/dist/src/react/core/catalog/use-agents.js.map +1 -0
- package/dist/src/react/core/catalog/use-models.d.ts +41 -0
- package/dist/src/react/core/catalog/use-models.d.ts.map +1 -0
- package/dist/src/react/core/catalog/use-models.js +35 -0
- package/dist/src/react/core/catalog/use-models.js.map +1 -0
- package/dist/src/react/core/catalog/use-resource.d.ts +12 -0
- package/dist/src/react/core/catalog/use-resource.d.ts.map +1 -0
- package/dist/src/react/core/catalog/use-resource.js +41 -0
- package/dist/src/react/core/catalog/use-resource.js.map +1 -0
- package/dist/src/react/core/client-wire.d.ts +14 -0
- package/dist/src/react/core/client-wire.d.ts.map +1 -0
- package/dist/src/react/core/client-wire.js +2 -0
- package/dist/src/react/core/client-wire.js.map +1 -0
- package/dist/src/react/core/client.d.ts +222 -0
- package/dist/src/react/core/client.d.ts.map +1 -0
- package/dist/src/react/core/client.js +435 -0
- package/dist/src/react/core/client.js.map +1 -0
- package/dist/src/react/core/components/ambient-ui.d.ts +22 -0
- package/dist/src/react/core/components/ambient-ui.d.ts.map +1 -0
- package/dist/src/react/core/components/ambient-ui.js +30 -0
- package/dist/src/react/core/components/ambient-ui.js.map +1 -0
- package/dist/src/react/core/components/chat-input.d.ts +44 -0
- package/dist/src/react/core/components/chat-input.d.ts.map +1 -0
- package/dist/src/react/core/components/chat-input.js +69 -0
- package/dist/src/react/core/components/chat-input.js.map +1 -0
- package/dist/src/react/core/components/index.d.ts +7 -0
- package/dist/src/react/core/components/index.d.ts.map +1 -0
- package/dist/src/react/core/components/index.js +7 -0
- package/dist/src/react/core/components/index.js.map +1 -0
- package/dist/src/react/core/components/message-item.d.ts +101 -0
- package/dist/src/react/core/components/message-item.d.ts.map +1 -0
- package/dist/src/react/core/components/message-item.js +118 -0
- package/dist/src/react/core/components/message-item.js.map +1 -0
- package/dist/src/react/core/components/message-list.d.ts +85 -0
- package/dist/src/react/core/components/message-list.d.ts.map +1 -0
- package/dist/src/react/core/components/message-list.js +45 -0
- package/dist/src/react/core/components/message-list.js.map +1 -0
- package/dist/src/react/core/components/speech-languages.d.ts +22 -0
- package/dist/src/react/core/components/speech-languages.d.ts.map +1 -0
- package/dist/src/react/core/components/speech-languages.js +38 -0
- package/dist/src/react/core/components/speech-languages.js.map +1 -0
- package/dist/src/react/core/components/use-speech-recognition.d.ts +19 -0
- package/dist/src/react/core/components/use-speech-recognition.d.ts.map +1 -0
- package/dist/src/react/core/components/use-speech-recognition.js +92 -0
- package/dist/src/react/core/components/use-speech-recognition.js.map +1 -0
- package/dist/src/react/core/composer/index.d.ts +4 -0
- package/dist/src/react/core/composer/index.d.ts.map +1 -0
- package/dist/src/react/core/composer/index.js +4 -0
- package/dist/src/react/core/composer/index.js.map +1 -0
- package/dist/src/react/core/composer/model.d.ts +83 -0
- package/dist/src/react/core/composer/model.d.ts.map +1 -0
- package/dist/src/react/core/composer/model.js +53 -0
- package/dist/src/react/core/composer/model.js.map +1 -0
- package/dist/src/react/core/composer/skills-source.d.ts +29 -0
- package/dist/src/react/core/composer/skills-source.d.ts.map +1 -0
- package/dist/src/react/core/composer/skills-source.js +61 -0
- package/dist/src/react/core/composer/skills-source.js.map +1 -0
- package/dist/src/react/core/composer/use-composer-autocomplete.d.ts +78 -0
- package/dist/src/react/core/composer/use-composer-autocomplete.d.ts.map +1 -0
- package/dist/src/react/core/composer/use-composer-autocomplete.js +244 -0
- package/dist/src/react/core/composer/use-composer-autocomplete.js.map +1 -0
- package/dist/src/react/core/config/use-agent-config.d.ts +21 -0
- package/dist/src/react/core/config/use-agent-config.d.ts.map +1 -0
- package/dist/src/react/core/config/use-agent-config.js +57 -0
- package/dist/src/react/core/config/use-agent-config.js.map +1 -0
- package/dist/src/react/core/elicitation/answers.d.ts +22 -0
- package/dist/src/react/core/elicitation/answers.d.ts.map +1 -0
- package/dist/src/react/core/elicitation/answers.js +65 -0
- package/dist/src/react/core/elicitation/answers.js.map +1 -0
- package/dist/src/react/core/feedback/use-message-feedback.d.ts +32 -0
- package/dist/src/react/core/feedback/use-message-feedback.d.ts.map +1 -0
- package/dist/src/react/core/feedback/use-message-feedback.js +106 -0
- package/dist/src/react/core/feedback/use-message-feedback.js.map +1 -0
- package/dist/src/react/core/genui/generative-ui.d.ts +76 -0
- package/dist/src/react/core/genui/generative-ui.d.ts.map +1 -0
- package/dist/src/react/core/genui/generative-ui.js +210 -0
- package/dist/src/react/core/genui/generative-ui.js.map +1 -0
- package/dist/src/react/core/genui/index.d.ts +5 -0
- package/dist/src/react/core/genui/index.d.ts.map +1 -0
- package/dist/src/react/core/genui/index.js +5 -0
- package/dist/src/react/core/genui/index.js.map +1 -0
- package/dist/src/react/core/genui/json-render.d.ts +54 -0
- package/dist/src/react/core/genui/json-render.d.ts.map +1 -0
- package/dist/src/react/core/genui/json-render.js +64 -0
- package/dist/src/react/core/genui/json-render.js.map +1 -0
- package/dist/src/react/core/genui/playwright.d.ts +12 -0
- package/dist/src/react/core/genui/playwright.d.ts.map +1 -0
- package/dist/src/react/core/genui/playwright.js +141 -0
- package/dist/src/react/core/genui/playwright.js.map +1 -0
- package/dist/src/react/core/genui/react-registry.d.ts +22 -0
- package/dist/src/react/core/genui/react-registry.d.ts.map +1 -0
- package/dist/src/react/core/genui/react-registry.js +72 -0
- package/dist/src/react/core/genui/react-registry.js.map +1 -0
- package/dist/src/react/core/genui/server.d.ts +32 -0
- package/dist/src/react/core/genui/server.d.ts.map +1 -0
- package/dist/src/react/core/genui/server.js +66 -0
- package/dist/src/react/core/genui/server.js.map +1 -0
- package/dist/src/react/core/genui/types.d.ts +98 -0
- package/dist/src/react/core/genui/types.d.ts.map +1 -0
- package/dist/src/react/core/genui/types.js +3 -0
- package/dist/src/react/core/genui/types.js.map +1 -0
- package/dist/src/react/core/genui/use-generative-ui.d.ts +42 -0
- package/dist/src/react/core/genui/use-generative-ui.d.ts.map +1 -0
- package/dist/src/react/core/genui/use-generative-ui.js +186 -0
- package/dist/src/react/core/genui/use-generative-ui.js.map +1 -0
- package/dist/src/react/core/http-error.d.ts +33 -0
- package/dist/src/react/core/http-error.d.ts.map +1 -0
- package/dist/src/react/core/http-error.js +47 -0
- package/dist/src/react/core/http-error.js.map +1 -0
- package/dist/src/react/core/index.d.ts +35 -0
- package/dist/src/react/core/index.d.ts.map +1 -0
- package/dist/src/react/core/index.js +34 -0
- package/dist/src/react/core/index.js.map +1 -0
- package/dist/src/react/core/markdown/agent-markdown.d.ts +39 -0
- package/dist/src/react/core/markdown/agent-markdown.d.ts.map +1 -0
- package/dist/src/react/core/markdown/agent-markdown.js +22 -0
- package/dist/src/react/core/markdown/agent-markdown.js.map +1 -0
- package/dist/src/react/core/markdown/index.d.ts +2 -0
- package/dist/src/react/core/markdown/index.d.ts.map +1 -0
- package/dist/src/react/core/markdown/index.js +2 -0
- package/dist/src/react/core/markdown/index.js.map +1 -0
- package/dist/src/react/core/media/index.d.ts +64 -0
- package/dist/src/react/core/media/index.d.ts.map +1 -0
- package/dist/src/react/core/media/index.js +135 -0
- package/dist/src/react/core/media/index.js.map +1 -0
- package/dist/src/react/core/media/tus.d.ts +13 -0
- package/dist/src/react/core/media/tus.d.ts.map +1 -0
- package/dist/src/react/core/media/tus.js +59 -0
- package/dist/src/react/core/media/tus.js.map +1 -0
- package/dist/src/react/core/presentation/phrasing.d.ts +25 -0
- package/dist/src/react/core/presentation/phrasing.d.ts.map +1 -0
- package/dist/src/react/core/presentation/phrasing.js +58 -0
- package/dist/src/react/core/presentation/phrasing.js.map +1 -0
- package/dist/src/react/core/presentation/result-view.d.ts +43 -0
- package/dist/src/react/core/presentation/result-view.d.ts.map +1 -0
- package/dist/src/react/core/presentation/result-view.js +90 -0
- package/dist/src/react/core/presentation/result-view.js.map +1 -0
- package/dist/src/react/core/presentation/tool-activity.d.ts +106 -0
- package/dist/src/react/core/presentation/tool-activity.d.ts.map +1 -0
- package/dist/src/react/core/presentation/tool-activity.js +165 -0
- package/dist/src/react/core/presentation/tool-activity.js.map +1 -0
- package/dist/src/react/core/presentation/use-tool-catalog.d.ts +39 -0
- package/dist/src/react/core/presentation/use-tool-catalog.d.ts.map +1 -0
- package/dist/src/react/core/presentation/use-tool-catalog.js +77 -0
- package/dist/src/react/core/presentation/use-tool-catalog.js.map +1 -0
- package/dist/src/react/core/provider.d.ts +68 -0
- package/dist/src/react/core/provider.d.ts.map +1 -0
- package/dist/src/react/core/provider.js +61 -0
- package/dist/src/react/core/provider.js.map +1 -0
- package/dist/src/react/core/queue/model.d.ts +73 -0
- package/dist/src/react/core/queue/model.d.ts.map +1 -0
- package/dist/src/react/core/queue/model.js +2 -0
- package/dist/src/react/core/queue/model.js.map +1 -0
- package/dist/src/react/core/quota/use-quota.d.ts +35 -0
- package/dist/src/react/core/quota/use-quota.d.ts.map +1 -0
- package/dist/src/react/core/quota/use-quota.js +47 -0
- package/dist/src/react/core/quota/use-quota.js.map +1 -0
- package/dist/src/react/core/reasoning/timing.d.ts +38 -0
- package/dist/src/react/core/reasoning/timing.d.ts.map +1 -0
- package/dist/src/react/core/reasoning/timing.js +73 -0
- package/dist/src/react/core/reasoning/timing.js.map +1 -0
- package/dist/src/react/core/run-errors.d.ts +37 -0
- package/dist/src/react/core/run-errors.d.ts.map +1 -0
- package/dist/src/react/core/run-errors.js +37 -0
- package/dist/src/react/core/run-errors.js.map +1 -0
- package/dist/src/react/core/stored-message-to-ui-message.d.ts +4 -0
- package/dist/src/react/core/stored-message-to-ui-message.d.ts.map +1 -0
- package/dist/src/react/core/stored-message-to-ui-message.js +216 -0
- package/dist/src/react/core/stored-message-to-ui-message.js.map +1 -0
- package/dist/src/react/core/stored-thread-to-ui-messages.d.ts +82 -0
- package/dist/src/react/core/stored-thread-to-ui-messages.d.ts.map +1 -0
- package/dist/src/react/core/stored-thread-to-ui-messages.js +116 -0
- package/dist/src/react/core/stored-thread-to-ui-messages.js.map +1 -0
- package/dist/src/react/core/threads/threads-events.d.ts +22 -0
- package/dist/src/react/core/threads/threads-events.d.ts.map +1 -0
- package/dist/src/react/core/threads/threads-events.js +21 -0
- package/dist/src/react/core/threads/threads-events.js.map +1 -0
- package/dist/src/react/core/threads/use-threads.d.ts +31 -0
- package/dist/src/react/core/threads/use-threads.d.ts.map +1 -0
- package/dist/src/react/core/threads/use-threads.js +81 -0
- package/dist/src/react/core/threads/use-threads.js.map +1 -0
- package/dist/src/react/core/transcript/index.d.ts +4 -0
- package/dist/src/react/core/transcript/index.d.ts.map +1 -0
- package/dist/src/react/core/transcript/index.js +4 -0
- package/dist/src/react/core/transcript/index.js.map +1 -0
- package/dist/src/react/core/transcript/model.d.ts +399 -0
- package/dist/src/react/core/transcript/model.d.ts.map +1 -0
- package/dist/src/react/core/transcript/model.js +725 -0
- package/dist/src/react/core/transcript/model.js.map +1 -0
- package/dist/src/react/core/transcript/use-chat-transcript.d.ts +254 -0
- package/dist/src/react/core/transcript/use-chat-transcript.d.ts.map +1 -0
- package/dist/src/react/core/transcript/use-chat-transcript.js +572 -0
- package/dist/src/react/core/transcript/use-chat-transcript.js.map +1 -0
- package/dist/src/react/core/transcript/use-stick-to-bottom.d.ts +33 -0
- package/dist/src/react/core/transcript/use-stick-to-bottom.d.ts.map +1 -0
- package/dist/src/react/core/transcript/use-stick-to-bottom.js +48 -0
- package/dist/src/react/core/transcript/use-stick-to-bottom.js.map +1 -0
- package/dist/src/react/core/use-agent-chat.d.ts +341 -0
- package/dist/src/react/core/use-agent-chat.d.ts.map +1 -0
- package/dist/src/react/core/use-agent-chat.js +1118 -0
- package/dist/src/react/core/use-agent-chat.js.map +1 -0
- package/dist/src/react/genui/index.d.ts +1 -7
- package/dist/src/react/genui/index.d.ts.map +1 -1
- package/dist/src/react/genui/index.js +1 -7
- package/dist/src/react/genui/index.js.map +1 -1
- package/dist/src/react/genui/json-render.d.ts +1 -5
- package/dist/src/react/genui/json-render.d.ts.map +1 -1
- package/dist/src/react/genui/json-render.js +1 -5
- package/dist/src/react/genui/json-render.js.map +1 -1
- package/dist/src/react/genui/server.d.ts +2 -0
- package/dist/src/react/genui/server.d.ts.map +1 -0
- package/dist/src/react/genui/server.js +2 -0
- package/dist/src/react/genui/server.js.map +1 -0
- package/dist/src/react/genui/server_playwright.d.ts +2 -0
- package/dist/src/react/genui/server_playwright.d.ts.map +1 -0
- package/dist/src/react/genui/server_playwright.js +2 -0
- package/dist/src/react/genui/server_playwright.js.map +1 -0
- package/dist/src/react/index.d.ts +5 -7
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +5 -7
- package/dist/src/react/index.js.map +1 -1
- package/dist/src/react/markdown.d.ts +1 -6
- package/dist/src/react/markdown.d.ts.map +1 -1
- package/dist/src/react/markdown.js +1 -6
- package/dist/src/react/markdown.js.map +1 -1
- package/dist/src/react/media.d.ts +1 -17
- package/dist/src/react/media.d.ts.map +1 -1
- package/dist/src/react/media.js +1 -17
- package/dist/src/react/media.js.map +1 -1
- package/dist/src/refusal.d.ts +3 -0
- package/dist/src/refusal.d.ts.map +1 -0
- package/dist/src/refusal.js +3 -0
- package/dist/src/refusal.js.map +1 -0
- package/dist/src/spi/agent-runner.d.ts +6 -0
- package/dist/src/spi/agent-runner.d.ts.map +1 -1
- package/dist/src/spi/chat-queue.d.ts +4 -1
- package/dist/src/spi/chat-queue.d.ts.map +1 -1
- package/dist/src/spi/chat-queue.js.map +1 -1
- package/dist/src/spi/protocol-adapter.d.ts +3 -3
- package/dist/src/spi/roles-policy.d.ts +7 -0
- package/dist/src/spi/roles-policy.d.ts.map +1 -1
- package/dist/src/spi/tool.d.ts +18 -3
- package/dist/src/spi/tool.d.ts.map +1 -1
- package/dist/src/stores/lucid-schema.d.ts +24 -6
- package/dist/src/stores/lucid-schema.d.ts.map +1 -1
- package/dist/src/stores/lucid-schema.js +49 -6
- package/dist/src/stores/lucid-schema.js.map +1 -1
- package/dist/src/stores/lucid.d.ts +2 -0
- package/dist/src/stores/lucid.d.ts.map +1 -1
- package/dist/src/stores/lucid.js +7 -0
- package/dist/src/stores/lucid.js.map +1 -1
- package/dist/src/testing/chat-queue-store-contract.d.ts.map +1 -1
- package/dist/src/testing/chat-queue-store-contract.js +4 -0
- package/dist/src/testing/chat-queue-store-contract.js.map +1 -1
- package/dist/src/testing/in-memory-store.d.ts.map +1 -1
- package/dist/src/testing/in-memory-store.js +1 -0
- package/dist/src/testing/in-memory-store.js.map +1 -1
- package/dist/src/tool-discovery.d.ts +1 -1
- package/dist/src/tool-discovery.d.ts.map +1 -1
- package/dist/src/tool-discovery.js +5 -1
- package/dist/src/tool-discovery.js.map +1 -1
- package/dist/src/tool-registry.d.ts +3 -0
- package/dist/src/tool-registry.d.ts.map +1 -1
- package/dist/src/tool-registry.js +15 -3
- package/dist/src/tool-registry.js.map +1 -1
- package/dist/src/tool-result-presentation.d.ts +12 -0
- package/dist/src/tool-result-presentation.d.ts.map +1 -0
- package/dist/src/tool-result-presentation.js +44 -0
- package/dist/src/tool-result-presentation.js.map +1 -0
- package/dist/src/types.d.ts +20 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/ui-capabilities.d.ts +1 -8
- package/dist/src/ui-capabilities.d.ts.map +1 -1
- package/dist/src/ui-capabilities.js +3 -24
- package/dist/src/ui-capabilities.js.map +1 -1
- package/package.json +128 -22
- package/skills/agent-governance/SKILL.md +12 -4
- package/skills/agent-personas-agents/SKILL.md +2 -1
- package/skills/agent-setup/SKILL.md +73 -14
- package/skills/agent-testing/SKILL.md +22 -0
- package/skills/agent-tools/SKILL.md +57 -9
- package/dist/src/ag-ui/proposal-decision.d.ts.map +0 -1
- package/dist/src/ag-ui/proposal-decision.js.map +0 -1
|
@@ -0,0 +1,817 @@
|
|
|
1
|
+
import { AgentClient } from './client.js';
|
|
2
|
+
import { reasoningDurationMetadata } from './reasoning/timing.js';
|
|
3
|
+
const DEFAULT_RECONNECT = {
|
|
4
|
+
maxAttempts: 6,
|
|
5
|
+
baseDelayMs: 500,
|
|
6
|
+
maxDelayMs: 8000,
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The tool name BOTH elicitation surfaces persist their question set under (core's
|
|
10
|
+
* `ASK_TOOL_NAME`), so a synthesized part and a replayed `tool-ask` row are the same part type.
|
|
11
|
+
* Spelled out rather than imported: every other core import in this package is type-only, and a
|
|
12
|
+
* value import would pull the agent loop into a browser bundle for a three-letter string.
|
|
13
|
+
*/
|
|
14
|
+
const ASK_TOOL_NAME = 'ask';
|
|
15
|
+
/**
|
|
16
|
+
* AI SDK v7 `ChatTransport` for the Adonis agent backend. POSTs
|
|
17
|
+
* `/agent/chat`, parses the backend's `meta` + `{delta}` + `done` SSE
|
|
18
|
+
* frames, and re-emits them as the v7 UI-message chunk stream
|
|
19
|
+
* (`start` → `text-start` → `text-delta`* → `text-end` → `finish`).
|
|
20
|
+
*
|
|
21
|
+
* The backend hydrates prior history from its store, so only the latest
|
|
22
|
+
* user message text is sent each turn — keeping payloads tiny and
|
|
23
|
+
* preventing the client from corrupting replayed history.
|
|
24
|
+
*
|
|
25
|
+
* Attachments (image/PDF for a vision-capable model) ride the per-send body:
|
|
26
|
+
* `sendMessage({ text }, { body: { attachments: MessageAttachment[] } })`. They
|
|
27
|
+
* flow to the backend as the turn's `attachments`, get persisted on the user
|
|
28
|
+
* message, and are rendered as native model content parts. Optimistic display of
|
|
29
|
+
* the user's own attachment thumbnails is the consumer's concern (it stages the
|
|
30
|
+
* upload), the same way history rendering reads `StoredMessage.attachments`.
|
|
31
|
+
*
|
|
32
|
+
* Frames beyond text/reasoning/tools become AI SDK data parts (seen by `useChat`'s `onData`):
|
|
33
|
+
* - `ui` → `data-ui` part, `id` = the component id (a repeat id updates it in place)
|
|
34
|
+
* - `approval-requested` → `data-approval-requested` part keyed by the call id, plus the SDK's
|
|
35
|
+
* native `tool-approval-request` (the part moves to `approval-requested`)
|
|
36
|
+
* - `approval-settled` → `data-approval-settled` part keyed by the call id (who decided, through
|
|
37
|
+
* what, remembered or not); the outcome still rides the call's own output
|
|
38
|
+
* - `title`, `cancelled`, `queue` → transient `data-title` / `data-cancelled` / `data-queue` (never
|
|
39
|
+
* stored on the message). A send the server queued (`202`) is reported
|
|
40
|
+
* as a transient `data-queue` too, carrying `queuedSend`
|
|
41
|
+
* - any other kind → `data-<kind>` part carrying the frame minus `kind`, keyed by its `id`
|
|
42
|
+
* when it has one — forwarded, never dropped
|
|
43
|
+
* `parentId` on a tool frame rides the part's `toolMetadata` next to `toolKind`.
|
|
44
|
+
*/
|
|
45
|
+
export class AgentChatTransport {
|
|
46
|
+
options;
|
|
47
|
+
currentRunId;
|
|
48
|
+
currentThreadId;
|
|
49
|
+
/**
|
|
50
|
+
* One attempt at a time. The AI SDK keeps a single in-flight response per chat and decides
|
|
51
|
+
* whether its streamed message REPLACES the list's last entry or is appended by comparing that
|
|
52
|
+
* response's message id against the last entry alone. Two attempts writing into one chat
|
|
53
|
+
* therefore append alternating copies of each other's message, and the list ends up holding
|
|
54
|
+
* several entries under each id — which React renders as duplicate keys.
|
|
55
|
+
*/
|
|
56
|
+
attemptLive = false;
|
|
57
|
+
backend;
|
|
58
|
+
constructor(options = {}) {
|
|
59
|
+
this.options = options;
|
|
60
|
+
this.backend =
|
|
61
|
+
options.backend ??
|
|
62
|
+
new AgentClient({
|
|
63
|
+
...(options.baseUrl !== undefined ? { baseUrl: options.baseUrl } : {}),
|
|
64
|
+
...(options.path !== undefined ? { path: options.path } : {}),
|
|
65
|
+
...(options.headers !== undefined ? { headers: options.headers } : {}),
|
|
66
|
+
...(options.getHeaders !== undefined ? { getHeaders: options.getHeaders } : {}),
|
|
67
|
+
...(options.credentials !== undefined ? { credentials: options.credentials } : {}),
|
|
68
|
+
...(options.fetch !== undefined ? { fetch: options.fetch } : {}),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Run id of the most recent stream — HITL approve/reject target this. */
|
|
72
|
+
get runId() {
|
|
73
|
+
return this.currentRunId;
|
|
74
|
+
}
|
|
75
|
+
/** Thread id of the most recent stream. */
|
|
76
|
+
get threadId() {
|
|
77
|
+
return this.currentThreadId;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* True from the moment a send or resume attempt starts until its chunk stream terminates. A
|
|
81
|
+
* caller that can refuse a turn BEFORE the SDK commits to one — `useAgentChat` wrapping
|
|
82
|
+
* `sendMessage` — reads this; the transport itself can only refuse a resume, which is the one
|
|
83
|
+
* attempt the SDK lets a transport decline.
|
|
84
|
+
*/
|
|
85
|
+
get isAttemptLive() {
|
|
86
|
+
return this.attemptLive;
|
|
87
|
+
}
|
|
88
|
+
async sendMessages(options) {
|
|
89
|
+
this.options.onAttemptStart?.();
|
|
90
|
+
this.attemptLive = true;
|
|
91
|
+
try {
|
|
92
|
+
const lastMessage = options.messages.at(-1);
|
|
93
|
+
const message = lastMessage ? extractText(lastMessage) : '';
|
|
94
|
+
const body = {
|
|
95
|
+
...(this.options.agent !== undefined ? { agent: this.options.agent } : {}),
|
|
96
|
+
...(this.options.persona !== undefined ? { persona: this.options.persona } : {}),
|
|
97
|
+
...(this.options.getBody?.() ?? {}),
|
|
98
|
+
...(options.body ?? {}),
|
|
99
|
+
message,
|
|
100
|
+
};
|
|
101
|
+
const headers = headerRecord(options.headers);
|
|
102
|
+
const files = lastMessage ? stagedFiles(lastMessage) : [];
|
|
103
|
+
const response = await this.backend.openChatStream({
|
|
104
|
+
body,
|
|
105
|
+
...(files.length > 0 ? { files } : {}),
|
|
106
|
+
...(headers !== undefined ? { headers } : {}),
|
|
107
|
+
...(options.abortSignal ? { signal: options.abortSignal } : {}),
|
|
108
|
+
});
|
|
109
|
+
if (response.queued !== undefined) {
|
|
110
|
+
// The thread already had a turn running (another tab, another device): the server queued
|
|
111
|
+
// the message instead. Nothing streams; the chat learns it through a transient part.
|
|
112
|
+
this.attemptLive = false;
|
|
113
|
+
return queuedChunkStream(response.queued);
|
|
114
|
+
}
|
|
115
|
+
this.captureHeaderMeta(response);
|
|
116
|
+
if (response.proposalDecision !== undefined) {
|
|
117
|
+
this.attemptLive = false;
|
|
118
|
+
return proposalDecisionChunkStream(response.proposalDecision);
|
|
119
|
+
}
|
|
120
|
+
return this.toChunkStream(response, {
|
|
121
|
+
...(headers !== undefined ? { headers } : {}),
|
|
122
|
+
...(options.abortSignal ? { signal: options.abortSignal } : {}),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
this.attemptLive = false;
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async reconnectToStream(options) {
|
|
131
|
+
// Already attached: a second reconnect replays the SAME buffered frames into the SAME chat, so
|
|
132
|
+
// it adds a duplicate of the message the first attempt is writing rather than a second turn.
|
|
133
|
+
// React StrictMode runs the SDK's resume effect twice on mount, which makes this the ordinary
|
|
134
|
+
// case and not an edge one. `null` is the SDK's own "nothing to resume" answer and, unlike a
|
|
135
|
+
// throw, leaves it holding no state for an attempt that never happened.
|
|
136
|
+
if (this.attemptLive)
|
|
137
|
+
return null;
|
|
138
|
+
this.options.onAttemptStart?.();
|
|
139
|
+
const runId = this.options.getResumeRunId?.();
|
|
140
|
+
// No buffered run → resolve null without a network round-trip so we
|
|
141
|
+
// never surface a 404 from a doomed resume GET.
|
|
142
|
+
if (runId === undefined)
|
|
143
|
+
return null;
|
|
144
|
+
this.attemptLive = true;
|
|
145
|
+
try {
|
|
146
|
+
const headers = headerRecord(options.headers);
|
|
147
|
+
const response = await this.backend.resumeChatStream({
|
|
148
|
+
runId,
|
|
149
|
+
...(headers !== undefined ? { headers } : {}),
|
|
150
|
+
});
|
|
151
|
+
if (response === null) {
|
|
152
|
+
this.attemptLive = false;
|
|
153
|
+
this.options.onResumeGone?.(runId);
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
this.captureHeaderMeta(response);
|
|
157
|
+
this.options.onResumeAttached?.(response.runId ?? runId);
|
|
158
|
+
return this.toChunkStream(response, {
|
|
159
|
+
runId,
|
|
160
|
+
...(headers !== undefined ? { headers } : {}),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
this.attemptLive = false;
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
captureHeaderMeta(response) {
|
|
169
|
+
if (response.runId)
|
|
170
|
+
this.currentRunId = response.runId;
|
|
171
|
+
if (response.threadId)
|
|
172
|
+
this.currentThreadId = response.threadId;
|
|
173
|
+
}
|
|
174
|
+
reconnectPolicy() {
|
|
175
|
+
const configured = this.options.reconnect;
|
|
176
|
+
if (configured === false)
|
|
177
|
+
return null;
|
|
178
|
+
return { ...DEFAULT_RECONNECT, ...configured };
|
|
179
|
+
}
|
|
180
|
+
recordMeta(meta) {
|
|
181
|
+
this.currentRunId = meta.runId;
|
|
182
|
+
this.currentThreadId = meta.threadId;
|
|
183
|
+
this.options.onMeta?.(meta);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Parse the backend's SSE byte stream and re-emit it as a valid v7 UI-message chunk stream.
|
|
187
|
+
* Recognized frames:
|
|
188
|
+
* - `event: meta` `data: {"runId","threadId"}` → records identity
|
|
189
|
+
* - `data: <AgentStreamEvent JSON>` → mapped to UI chunks (text / reasoning / tool /
|
|
190
|
+
* `data-*`; see {@link AgentChatTransport} docs)
|
|
191
|
+
* - `event: done` `data: {}` → terminates
|
|
192
|
+
* - `event: error` `data: {code,message}` → error chunk
|
|
193
|
+
*
|
|
194
|
+
* A run is ONE UI message with N steps. Each `step-start`/`step-finish` pair brackets a model
|
|
195
|
+
* call plus its tool execution; text and reasoning open lazily and close at the step boundary, so
|
|
196
|
+
* tool-call cards (input streaming → output) render live between the prose.
|
|
197
|
+
*/
|
|
198
|
+
toChunkStream(source, context) {
|
|
199
|
+
let reader = source.body.getReader();
|
|
200
|
+
let decoder = new TextDecoder();
|
|
201
|
+
let buffer = '';
|
|
202
|
+
// Resuming a dropped stream: the run it belongs to, and the sequence number (SSE `id:`) of the
|
|
203
|
+
// last frame this stream has taken in. Only a server that numbers its frames can be resumed.
|
|
204
|
+
let streamRunId = source.runId ?? context.runId;
|
|
205
|
+
let lastSeq;
|
|
206
|
+
let cancelled = false;
|
|
207
|
+
const backend = this.backend;
|
|
208
|
+
const policy = this.reconnectPolicy();
|
|
209
|
+
const notify = (state) => this.options.onConnectionChange?.(state);
|
|
210
|
+
const reportRunError = (failure) => {
|
|
211
|
+
try {
|
|
212
|
+
this.options.onRunError?.({
|
|
213
|
+
...failure,
|
|
214
|
+
...(streamRunId !== undefined ? { runId: streamRunId } : {}),
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
/* a listener that throws must not replace the stream's own terminal */
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const aborted = () => cancelled || context.signal?.aborted === true;
|
|
222
|
+
const canResume = () => policy !== null && lastSeq !== undefined && streamRunId !== undefined && !aborted();
|
|
223
|
+
/**
|
|
224
|
+
* Re-attach after a drop: `GET …/stream?after=<lastSeq>`, backing off between attempts. The
|
|
225
|
+
* chunk state (open step, text run, announced calls) is kept, so the resumed frames continue
|
|
226
|
+
* the message instead of starting another.
|
|
227
|
+
*/
|
|
228
|
+
const resume = async () => {
|
|
229
|
+
const runId = streamRunId;
|
|
230
|
+
const after = lastSeq ?? 0;
|
|
231
|
+
const { maxAttempts, baseDelayMs, maxDelayMs } = policy;
|
|
232
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
233
|
+
notify({ status: 'reconnecting', runId, attempt, after });
|
|
234
|
+
await delay(Math.min(maxDelayMs, baseDelayMs * 2 ** (attempt - 1)), context.signal);
|
|
235
|
+
if (aborted())
|
|
236
|
+
return 'aborted';
|
|
237
|
+
try {
|
|
238
|
+
const next = await backend.resumeChatStream({
|
|
239
|
+
runId,
|
|
240
|
+
after,
|
|
241
|
+
...(context.headers !== undefined ? { headers: context.headers } : {}),
|
|
242
|
+
...(context.signal !== undefined ? { signal: context.signal } : {}),
|
|
243
|
+
});
|
|
244
|
+
if (next === null) {
|
|
245
|
+
notify({ status: 'gone', runId });
|
|
246
|
+
return 'gone';
|
|
247
|
+
}
|
|
248
|
+
reader = next.body.getReader();
|
|
249
|
+
decoder = new TextDecoder();
|
|
250
|
+
buffer = '';
|
|
251
|
+
notify({ status: 'live' });
|
|
252
|
+
return 'resumed';
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
if (aborted())
|
|
256
|
+
return 'aborted';
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
notify({ status: 'failed', runId });
|
|
260
|
+
return 'failed';
|
|
261
|
+
};
|
|
262
|
+
let started = false;
|
|
263
|
+
let stepOpen = false;
|
|
264
|
+
let stepIndex = 0;
|
|
265
|
+
let textId = null;
|
|
266
|
+
let reasoningId = null;
|
|
267
|
+
// When the open reasoning run started, for the duration stamped on its end when the backend
|
|
268
|
+
// does not report one (see `closeRuns`).
|
|
269
|
+
let reasoningStartedAt = 0;
|
|
270
|
+
// Text/reasoning runs opened within the current step. A pushed UI component closes the open run
|
|
271
|
+
// so prose after it lands AFTER it; the next run then needs an id of its own.
|
|
272
|
+
let textSeq = 0;
|
|
273
|
+
let reasoningSeq = 0;
|
|
274
|
+
// Tool calls this STREAM has already announced. The AI SDK settles a tool part by looking it
|
|
275
|
+
// up by call id and throws — dropping the whole message — when there is none, so an outcome
|
|
276
|
+
// must never be the first a client hears of a call. Per stream, not per transport: a resumed
|
|
277
|
+
// run replays its buffered frames from the beginning.
|
|
278
|
+
const announced = new Set();
|
|
279
|
+
// What each call's tool part carries as `toolMetadata`. The SDK REPLACES a part's metadata with
|
|
280
|
+
// whatever the latest chunk carries, so a `parentId` learnt from `tool-input-start` would be
|
|
281
|
+
// wiped by the `tool-input-available` that follows unless every chunk restates the merge.
|
|
282
|
+
const toolMetadata = new Map();
|
|
283
|
+
const record = (meta) => {
|
|
284
|
+
streamRunId = meta.runId;
|
|
285
|
+
this.recordMeta(meta);
|
|
286
|
+
};
|
|
287
|
+
// Every way out of the read loop below passes through here: the attempt is over the moment its
|
|
288
|
+
// chunk stream terminates, and a latch left set would refuse every later turn.
|
|
289
|
+
const endAttempt = () => {
|
|
290
|
+
this.attemptLive = false;
|
|
291
|
+
};
|
|
292
|
+
return new ReadableStream({
|
|
293
|
+
async pull(controller) {
|
|
294
|
+
function ensureStarted() {
|
|
295
|
+
if (started)
|
|
296
|
+
return;
|
|
297
|
+
started = true;
|
|
298
|
+
// The run rides the message's metadata, so a later call about THIS message (feedback,
|
|
299
|
+
// a resync) can find the rows the server persisted for it.
|
|
300
|
+
// `createdAt` so a live message has a timestamp the way a replayed one does.
|
|
301
|
+
controller.enqueue({
|
|
302
|
+
type: 'start',
|
|
303
|
+
messageMetadata: {
|
|
304
|
+
...(streamRunId !== undefined ? { runId: streamRunId } : {}),
|
|
305
|
+
createdAt: new Date().toISOString(),
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
function openStep() {
|
|
310
|
+
ensureStarted();
|
|
311
|
+
if (stepOpen)
|
|
312
|
+
closeStep();
|
|
313
|
+
stepOpen = true;
|
|
314
|
+
stepIndex += 1;
|
|
315
|
+
textId = null;
|
|
316
|
+
reasoningId = null;
|
|
317
|
+
textSeq = 0;
|
|
318
|
+
reasoningSeq = 0;
|
|
319
|
+
controller.enqueue({ type: 'start-step' });
|
|
320
|
+
}
|
|
321
|
+
function ensureStep() {
|
|
322
|
+
if (!stepOpen)
|
|
323
|
+
openStep();
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* `reasoningMs` is the backend's own measurement (`step-finish.reasoningMs`) — the number the
|
|
327
|
+
* store persists, so a reloaded thread reads the same duration. Without one, the time this
|
|
328
|
+
* client watched the run stream, which is what the reader saw but reads ~0 on a replay.
|
|
329
|
+
*/
|
|
330
|
+
function closeRuns(reasoningMs) {
|
|
331
|
+
if (textId !== null) {
|
|
332
|
+
controller.enqueue({ type: 'text-end', id: textId });
|
|
333
|
+
textId = null;
|
|
334
|
+
}
|
|
335
|
+
if (reasoningId !== null) {
|
|
336
|
+
controller.enqueue({
|
|
337
|
+
type: 'reasoning-end',
|
|
338
|
+
id: reasoningId,
|
|
339
|
+
providerMetadata: reasoningDurationMetadata(reasoningMs ?? Math.max(0, Date.now() - reasoningStartedAt)),
|
|
340
|
+
});
|
|
341
|
+
reasoningId = null;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function closeStep(reasoningMs) {
|
|
345
|
+
if (!stepOpen)
|
|
346
|
+
return;
|
|
347
|
+
closeRuns(reasoningMs);
|
|
348
|
+
controller.enqueue({ type: 'finish-step' });
|
|
349
|
+
stepOpen = false;
|
|
350
|
+
}
|
|
351
|
+
/** Merge what this frame says about a call into what earlier frames said, and return it. */
|
|
352
|
+
function metadataFor(id, toolKind, parentId) {
|
|
353
|
+
const merged = { ...toolMetadata.get(id) };
|
|
354
|
+
if (toolKind !== undefined)
|
|
355
|
+
merged.toolKind = toolKind;
|
|
356
|
+
// A call's parent is fixed by the first frame that names one.
|
|
357
|
+
if (parentId !== undefined && merged.parentId === undefined)
|
|
358
|
+
merged.parentId = parentId;
|
|
359
|
+
if (Object.keys(merged).length === 0)
|
|
360
|
+
return undefined;
|
|
361
|
+
toolMetadata.set(id, merged);
|
|
362
|
+
return merged;
|
|
363
|
+
}
|
|
364
|
+
/** Forward a frame this transport has no dedicated mapping for as an AI SDK data part. */
|
|
365
|
+
function forwardAsData(event, transient) {
|
|
366
|
+
ensureStarted();
|
|
367
|
+
const { kind, ...data } = event;
|
|
368
|
+
controller.enqueue({
|
|
369
|
+
type: `data-${kind}`,
|
|
370
|
+
...(typeof data.id === 'string' ? { id: data.id } : {}),
|
|
371
|
+
data,
|
|
372
|
+
...(transient ? { transient: true } : {}),
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
function emit(event) {
|
|
376
|
+
switch (event.kind) {
|
|
377
|
+
case 'step-start':
|
|
378
|
+
openStep();
|
|
379
|
+
break;
|
|
380
|
+
case 'step-finish':
|
|
381
|
+
closeStep(event.reasoningMs);
|
|
382
|
+
// `costUsd` rides the step boundary once the backend reports it (older backends omit
|
|
383
|
+
// it entirely — `undefined`, never a crash). `null` means "priced provider/estimate
|
|
384
|
+
// unavailable", distinct from a real $0 turn — surfaced verbatim as message metadata
|
|
385
|
+
// (merged onto `message.metadata` by the AI SDK) so a UI can render running cost
|
|
386
|
+
// without polling `GET /quota`.
|
|
387
|
+
if (event.costUsd !== undefined) {
|
|
388
|
+
controller.enqueue({
|
|
389
|
+
type: 'message-metadata',
|
|
390
|
+
messageMetadata: { costUsd: event.costUsd },
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
break;
|
|
394
|
+
case 'text':
|
|
395
|
+
ensureStep();
|
|
396
|
+
if (textId === null) {
|
|
397
|
+
textId = textSeq === 0 ? `txt-${stepIndex}` : `txt-${stepIndex}.${textSeq}`;
|
|
398
|
+
textSeq += 1;
|
|
399
|
+
controller.enqueue({ type: 'text-start', id: textId });
|
|
400
|
+
}
|
|
401
|
+
controller.enqueue({ type: 'text-delta', id: textId, delta: event.text });
|
|
402
|
+
break;
|
|
403
|
+
case 'reasoning':
|
|
404
|
+
ensureStep();
|
|
405
|
+
if (reasoningId === null) {
|
|
406
|
+
reasoningId =
|
|
407
|
+
reasoningSeq === 0 ? `rsn-${stepIndex}` : `rsn-${stepIndex}.${reasoningSeq}`;
|
|
408
|
+
reasoningSeq += 1;
|
|
409
|
+
reasoningStartedAt = Date.now();
|
|
410
|
+
controller.enqueue({ type: 'reasoning-start', id: reasoningId });
|
|
411
|
+
}
|
|
412
|
+
controller.enqueue({ type: 'reasoning-delta', id: reasoningId, delta: event.text });
|
|
413
|
+
break;
|
|
414
|
+
case 'tool-input-start': {
|
|
415
|
+
ensureStep();
|
|
416
|
+
announced.add(event.id);
|
|
417
|
+
// `toolKind` is absent on older backends — omitted (not `undefined`-valued) so
|
|
418
|
+
// `toolMetadata` itself is only present when there's something to say, letting a
|
|
419
|
+
// UI gate approval affordances on `kind === 'action'` without hardcoding tool names.
|
|
420
|
+
// `parentId` nests the call under another one (see `TranscriptToolCall.children`).
|
|
421
|
+
const metadata = metadataFor(event.id, event.toolKind, event.parentId);
|
|
422
|
+
controller.enqueue({
|
|
423
|
+
type: 'tool-input-start',
|
|
424
|
+
toolCallId: event.id,
|
|
425
|
+
toolName: event.name,
|
|
426
|
+
...(metadata !== undefined ? { toolMetadata: metadata } : {}),
|
|
427
|
+
});
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
case 'tool-input-delta':
|
|
431
|
+
ensureStep();
|
|
432
|
+
controller.enqueue({
|
|
433
|
+
type: 'tool-input-delta',
|
|
434
|
+
toolCallId: event.id,
|
|
435
|
+
inputTextDelta: event.delta,
|
|
436
|
+
});
|
|
437
|
+
break;
|
|
438
|
+
case 'tool-input-available': {
|
|
439
|
+
ensureStep();
|
|
440
|
+
announced.add(event.id);
|
|
441
|
+
const metadata = metadataFor(event.id, event.toolKind, event.parentId);
|
|
442
|
+
controller.enqueue({
|
|
443
|
+
type: 'tool-input-available',
|
|
444
|
+
toolCallId: event.id,
|
|
445
|
+
toolName: event.name,
|
|
446
|
+
input: event.input,
|
|
447
|
+
...(metadata !== undefined ? { toolMetadata: metadata } : {}),
|
|
448
|
+
});
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
case 'elicitation':
|
|
452
|
+
ensureStep();
|
|
453
|
+
// An authored intake asks before the turn's first model call, so nothing announced
|
|
454
|
+
// the call this question set is parked under — open it here, carrying the request as
|
|
455
|
+
// the part's input, which is exactly what the store persists as the call's input and
|
|
456
|
+
// therefore what a reloaded thread replays. The model's own `ask` announced its call
|
|
457
|
+
// itself, and re-stating it would fire a consumer's `onToolCall` twice.
|
|
458
|
+
if (!announced.has(event.id)) {
|
|
459
|
+
announced.add(event.id);
|
|
460
|
+
controller.enqueue({
|
|
461
|
+
type: 'tool-input-available',
|
|
462
|
+
toolCallId: event.id,
|
|
463
|
+
toolName: ASK_TOOL_NAME,
|
|
464
|
+
input: {
|
|
465
|
+
...(event.request.preamble !== undefined
|
|
466
|
+
? { preamble: event.request.preamble }
|
|
467
|
+
: {}),
|
|
468
|
+
questions: event.request.questions,
|
|
469
|
+
},
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
case 'tool-output':
|
|
474
|
+
ensureStep();
|
|
475
|
+
controller.enqueue({
|
|
476
|
+
type: 'tool-output-available',
|
|
477
|
+
toolCallId: event.id,
|
|
478
|
+
output: event.output,
|
|
479
|
+
});
|
|
480
|
+
break;
|
|
481
|
+
case 'tool-output-error':
|
|
482
|
+
ensureStep();
|
|
483
|
+
controller.enqueue({
|
|
484
|
+
type: 'tool-output-error',
|
|
485
|
+
toolCallId: event.id,
|
|
486
|
+
errorText: event.error,
|
|
487
|
+
});
|
|
488
|
+
break;
|
|
489
|
+
case 'tool-output-denied':
|
|
490
|
+
ensureStep();
|
|
491
|
+
// The SDK's own state for "a person said no": it keeps the part's input and metadata
|
|
492
|
+
// and only moves its state, so a card can say the decision was carried out instead of
|
|
493
|
+
// drawing the red treatment an error gets. The reason (when one was given) rides the
|
|
494
|
+
// persisted call, not this chunk — the SDK's shape carries no room for it.
|
|
495
|
+
controller.enqueue({ type: 'tool-output-denied', toolCallId: event.id });
|
|
496
|
+
break;
|
|
497
|
+
case 'approval-requested':
|
|
498
|
+
ensureStep();
|
|
499
|
+
// Who decides and until when rides a `data-approval-requested` part keyed by the call
|
|
500
|
+
// id — the SDK's approval chunk has no room for it, and restating the call's input
|
|
501
|
+
// chunk to widen its metadata would fire a consumer's `onToolCall` a second time.
|
|
502
|
+
forwardAsData(event, false);
|
|
503
|
+
// The SDK settles an approval against a part it already holds and throws — dropping
|
|
504
|
+
// the whole message — when there is none, so only a call this stream announced moves
|
|
505
|
+
// into the native state. The approval id IS the call id: the lib settles approvals
|
|
506
|
+
// by tool-call id, so a second identifier would only have to be mapped back.
|
|
507
|
+
if (announced.has(event.id)) {
|
|
508
|
+
controller.enqueue({
|
|
509
|
+
type: 'tool-approval-request',
|
|
510
|
+
approvalId: event.id,
|
|
511
|
+
toolCallId: event.id,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
break;
|
|
515
|
+
case 'approval-settled':
|
|
516
|
+
ensureStep();
|
|
517
|
+
// Metadata about a call, like the request: the transcript folds it into that call's
|
|
518
|
+
// `approval`. The call's own state moves on its output frame, not on this one.
|
|
519
|
+
forwardAsData(event, false);
|
|
520
|
+
break;
|
|
521
|
+
case 'ui':
|
|
522
|
+
ensureStep();
|
|
523
|
+
// Positioned content: close the open prose so text written after the component
|
|
524
|
+
// renders after it instead of growing the paragraph above it.
|
|
525
|
+
closeRuns();
|
|
526
|
+
controller.enqueue({
|
|
527
|
+
type: 'data-ui',
|
|
528
|
+
id: event.id,
|
|
529
|
+
data: {
|
|
530
|
+
id: event.id,
|
|
531
|
+
component: event.component,
|
|
532
|
+
props: event.props,
|
|
533
|
+
...(event.version !== undefined ? { version: event.version } : {}),
|
|
534
|
+
...(event.toolCallId !== undefined ? { toolCallId: event.toolCallId } : {}),
|
|
535
|
+
},
|
|
536
|
+
});
|
|
537
|
+
break;
|
|
538
|
+
case 'message-metadata':
|
|
539
|
+
ensureStarted();
|
|
540
|
+
controller.enqueue({ type: 'message-metadata', messageMetadata: event.metadata });
|
|
541
|
+
break;
|
|
542
|
+
case 'title':
|
|
543
|
+
case 'cancelled':
|
|
544
|
+
// The thread's queue changed, or this run handed the thread to the next queued message
|
|
545
|
+
// (`started`). Thread-level, like the title.
|
|
546
|
+
case 'queue':
|
|
547
|
+
// Thread- and run-level facts, not message content: seen by `onData`, never stored
|
|
548
|
+
// as a part of the message.
|
|
549
|
+
forwardAsData(event, true);
|
|
550
|
+
break;
|
|
551
|
+
default:
|
|
552
|
+
// A kind this version does not know (a newer server, a runner that is not this
|
|
553
|
+
// library's loop). Forwarded rather than dropped, so a host can render it from
|
|
554
|
+
// `message.parts` / `onData` without waiting for a release that maps it.
|
|
555
|
+
// `proposal-decision` (an AG-UI text decision, re-framed) is the same transient
|
|
556
|
+
// `data-proposal-decision` part a native decision answers with.
|
|
557
|
+
forwardAsData(event, event.kind === 'proposal-decision');
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function finish() {
|
|
562
|
+
ensureStarted();
|
|
563
|
+
closeStep();
|
|
564
|
+
controller.enqueue({ type: 'finish' });
|
|
565
|
+
controller.close();
|
|
566
|
+
endAttempt();
|
|
567
|
+
}
|
|
568
|
+
function fail(errorText, start = true) {
|
|
569
|
+
if (start)
|
|
570
|
+
ensureStarted();
|
|
571
|
+
controller.enqueue({ type: 'error', errorText });
|
|
572
|
+
controller.close();
|
|
573
|
+
endAttempt();
|
|
574
|
+
}
|
|
575
|
+
/** The stream dropped (or ended without `done`): resume it, or report how it ended. */
|
|
576
|
+
async function recover(error) {
|
|
577
|
+
if (!canResume()) {
|
|
578
|
+
if (error === undefined) {
|
|
579
|
+
finish();
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
fail(error instanceof Error ? error.message : 'Agent stream error', false);
|
|
583
|
+
}
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
const outcome = await resume();
|
|
587
|
+
if (outcome === 'resumed')
|
|
588
|
+
return true;
|
|
589
|
+
if (outcome === 'failed') {
|
|
590
|
+
fail('Lost the connection to the agent stream');
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
// Gone: the run ended while we were away — what we have is all this stream will get,
|
|
594
|
+
// and the persisted thread holds the rest. Aborted: the user stopped the turn.
|
|
595
|
+
finish();
|
|
596
|
+
}
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
try {
|
|
600
|
+
while (true) {
|
|
601
|
+
let result;
|
|
602
|
+
try {
|
|
603
|
+
result = await reader.read();
|
|
604
|
+
}
|
|
605
|
+
catch (error) {
|
|
606
|
+
if (await recover(error))
|
|
607
|
+
continue;
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (result.done) {
|
|
611
|
+
if (await recover(undefined))
|
|
612
|
+
continue;
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
buffer += decoder.decode(result.value, { stream: true });
|
|
616
|
+
let separator = buffer.indexOf('\n\n');
|
|
617
|
+
while (separator !== -1) {
|
|
618
|
+
const rawEvent = buffer.slice(0, separator);
|
|
619
|
+
buffer = buffer.slice(separator + 2);
|
|
620
|
+
separator = buffer.indexOf('\n\n');
|
|
621
|
+
const frame = parseSseFrame(rawEvent);
|
|
622
|
+
if (frame.id !== undefined) {
|
|
623
|
+
// Already taken in before a reconnect — a server that ignored `after` resends it.
|
|
624
|
+
if (lastSeq !== undefined && frame.id <= lastSeq)
|
|
625
|
+
continue;
|
|
626
|
+
lastSeq = frame.id;
|
|
627
|
+
}
|
|
628
|
+
if (frame.event === 'done') {
|
|
629
|
+
finish();
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
if (frame.event === 'error') {
|
|
633
|
+
const failure = parseErrorFrame(frame.data);
|
|
634
|
+
reportRunError(failure);
|
|
635
|
+
fail(failure.message);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (frame.event === 'meta') {
|
|
639
|
+
const meta = parseMeta(frame.data);
|
|
640
|
+
if (meta)
|
|
641
|
+
record(meta);
|
|
642
|
+
}
|
|
643
|
+
else if (frame.data) {
|
|
644
|
+
const event = parseEvent(frame.data);
|
|
645
|
+
if (event)
|
|
646
|
+
emit(event);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
catch (error) {
|
|
652
|
+
fail(error instanceof Error ? error.message : 'Agent stream error', false);
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
cancel() {
|
|
656
|
+
cancelled = true;
|
|
657
|
+
// A stop aborts the request first, which errors the body: cancelling an errored stream
|
|
658
|
+
// rejects with that same AbortError, and nobody is left to hear it.
|
|
659
|
+
reader.cancel().catch(() => undefined);
|
|
660
|
+
endAttempt();
|
|
661
|
+
},
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
/** The chunk stream for a send the server queued: one transient `data-queue` part, then the end. */
|
|
666
|
+
function queuedChunkStream(queued) {
|
|
667
|
+
return new ReadableStream({
|
|
668
|
+
start(controller) {
|
|
669
|
+
controller.enqueue({
|
|
670
|
+
type: 'data-queue',
|
|
671
|
+
data: { queue: queued.queue, queuedSend: queued },
|
|
672
|
+
transient: true,
|
|
673
|
+
});
|
|
674
|
+
controller.close();
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
/** Split one `event:`/`data:` SSE block into its fields. */
|
|
679
|
+
function parseSseFrame(raw) {
|
|
680
|
+
let event;
|
|
681
|
+
let id;
|
|
682
|
+
const dataLines = [];
|
|
683
|
+
for (const line of raw.split('\n')) {
|
|
684
|
+
if (line.startsWith('event:')) {
|
|
685
|
+
event = line.slice('event:'.length).trim();
|
|
686
|
+
}
|
|
687
|
+
else if (line.startsWith('id:')) {
|
|
688
|
+
const parsed = Number(line.slice('id:'.length).trim());
|
|
689
|
+
if (Number.isSafeInteger(parsed) && parsed > 0)
|
|
690
|
+
id = parsed;
|
|
691
|
+
}
|
|
692
|
+
else if (line.startsWith('data:')) {
|
|
693
|
+
dataLines.push(line.slice('data:'.length).trimStart());
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return {
|
|
697
|
+
event,
|
|
698
|
+
data: dataLines.length > 0 ? dataLines.join('\n') : undefined,
|
|
699
|
+
id,
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
function parseMeta(data) {
|
|
703
|
+
if (!data)
|
|
704
|
+
return null;
|
|
705
|
+
try {
|
|
706
|
+
const parsed = JSON.parse(data);
|
|
707
|
+
if (parsed !== null &&
|
|
708
|
+
typeof parsed === 'object' &&
|
|
709
|
+
'runId' in parsed &&
|
|
710
|
+
'threadId' in parsed &&
|
|
711
|
+
typeof parsed.runId === 'string' &&
|
|
712
|
+
typeof parsed.threadId === 'string') {
|
|
713
|
+
return { runId: parsed.runId, threadId: parsed.threadId };
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
catch {
|
|
717
|
+
/* malformed meta frame — ignore */
|
|
718
|
+
}
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
/** Read the backend's `event: error` frame (`{code,message}`); a malformed one is a bare failure. */
|
|
722
|
+
function parseErrorFrame(data) {
|
|
723
|
+
const fallback = { code: undefined, message: 'Agent run failed' };
|
|
724
|
+
if (!data)
|
|
725
|
+
return fallback;
|
|
726
|
+
try {
|
|
727
|
+
const parsed = JSON.parse(data);
|
|
728
|
+
if (parsed !== null && typeof parsed === 'object') {
|
|
729
|
+
const record = parsed;
|
|
730
|
+
return {
|
|
731
|
+
code: typeof record.code === 'string' && record.code !== '' ? record.code : undefined,
|
|
732
|
+
message: typeof record.message === 'string' && record.message !== ''
|
|
733
|
+
? record.message
|
|
734
|
+
: fallback.message,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
catch {
|
|
739
|
+
/* malformed error frame — fall through to the default */
|
|
740
|
+
}
|
|
741
|
+
return fallback;
|
|
742
|
+
}
|
|
743
|
+
/** Parse a `data:` frame as an `AgentStreamEvent`. Returns null for anything without a `kind`. */
|
|
744
|
+
function parseEvent(data) {
|
|
745
|
+
try {
|
|
746
|
+
const parsed = JSON.parse(data);
|
|
747
|
+
if (parsed !== null && typeof parsed === 'object' && 'kind' in parsed) {
|
|
748
|
+
return parsed;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
catch {
|
|
752
|
+
/* not an event frame — ignore */
|
|
753
|
+
}
|
|
754
|
+
return null;
|
|
755
|
+
}
|
|
756
|
+
/** Collect all text parts of a UI message into a single string. */
|
|
757
|
+
function extractText(message) {
|
|
758
|
+
let text = '';
|
|
759
|
+
for (const part of message.parts ?? []) {
|
|
760
|
+
if (part.type === 'text')
|
|
761
|
+
text += part.text;
|
|
762
|
+
}
|
|
763
|
+
return text;
|
|
764
|
+
}
|
|
765
|
+
/** The message's file parts that name a staged upload (`providerMetadata.agent.mediaId`). */
|
|
766
|
+
function stagedFiles(message) {
|
|
767
|
+
const files = [];
|
|
768
|
+
for (const part of message.parts ?? []) {
|
|
769
|
+
if (part.type !== 'file')
|
|
770
|
+
continue;
|
|
771
|
+
const mediaId = part.providerMetadata?.agent?.mediaId;
|
|
772
|
+
if (typeof mediaId !== 'string' || mediaId.length === 0)
|
|
773
|
+
continue;
|
|
774
|
+
files.push({
|
|
775
|
+
mediaId,
|
|
776
|
+
...(part.mediaType ? { contentType: part.mediaType } : {}),
|
|
777
|
+
...(part.filename ? { name: part.filename } : {}),
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
return files;
|
|
781
|
+
}
|
|
782
|
+
/** Per-request headers as the AI SDK hands them over, as a plain record (or nothing). */
|
|
783
|
+
function headerRecord(headers) {
|
|
784
|
+
if (headers === undefined)
|
|
785
|
+
return undefined;
|
|
786
|
+
return headers instanceof Headers ? Object.fromEntries(headers.entries()) : headers;
|
|
787
|
+
}
|
|
788
|
+
/** Wait `ms`, resolving early when `signal` aborts. */
|
|
789
|
+
function delay(ms, signal) {
|
|
790
|
+
if (ms <= 0 || signal?.aborted)
|
|
791
|
+
return Promise.resolve();
|
|
792
|
+
return new Promise((resolve) => {
|
|
793
|
+
const timer = setTimeout(done, ms);
|
|
794
|
+
function done() {
|
|
795
|
+
clearTimeout(timer);
|
|
796
|
+
signal?.removeEventListener('abort', done);
|
|
797
|
+
resolve();
|
|
798
|
+
}
|
|
799
|
+
signal?.addEventListener('abort', done, { once: true });
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
function proposalDecisionChunkStream(decision) {
|
|
803
|
+
return new ReadableStream({
|
|
804
|
+
start(controller) {
|
|
805
|
+
controller.enqueue({ type: 'start', messageId: `decision:${crypto.randomUUID()}` });
|
|
806
|
+
controller.enqueue({ type: 'data-proposal-decision', data: decision, transient: true });
|
|
807
|
+
if (decision.text !== undefined && decision.text.length > 0) {
|
|
808
|
+
controller.enqueue({ type: 'text-start', id: 'decision' });
|
|
809
|
+
controller.enqueue({ type: 'text-delta', id: 'decision', delta: decision.text });
|
|
810
|
+
controller.enqueue({ type: 'text-end', id: 'decision' });
|
|
811
|
+
}
|
|
812
|
+
controller.enqueue({ type: 'finish', finishReason: 'stop' });
|
|
813
|
+
controller.close();
|
|
814
|
+
},
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
//# sourceMappingURL=agent-chat-transport.js.map
|