@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,106 @@
|
|
|
1
|
+
import { type AgUiEvent, type AgUiSourceFrame } from './types.js';
|
|
2
|
+
export interface AgUiEncoderOptions {
|
|
3
|
+
/** The ids the consumer sent on `RunAgentInput`: every boundary event echoes them. */
|
|
4
|
+
threadId: string;
|
|
5
|
+
runId: string;
|
|
6
|
+
/** The library run whose stream is being projected (it mints interrupt ids and the `agora.run` event). */
|
|
7
|
+
streamRunId: string;
|
|
8
|
+
/** The library's thread id, when it differs from what the consumer calls the thread. */
|
|
9
|
+
streamThreadId?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Frames of the library run's stream that an earlier AG-UI run already delivered (a resume). They
|
|
12
|
+
* are fed to the encoder like any other — it has to know what they opened — but produce no events.
|
|
13
|
+
*/
|
|
14
|
+
skip?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Tool calls a resuming request just answered. The run has not necessarily said so yet — a parked
|
|
17
|
+
* run takes a moment to wake — so without this the encoder would read them as still waiting and
|
|
18
|
+
* report the interrupt again before the answer had any effect.
|
|
19
|
+
*/
|
|
20
|
+
answered?: readonly string[];
|
|
21
|
+
/** Model id for the usage entry when the step frames carry none. */
|
|
22
|
+
model?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Projects one library run's stream ({@link AgUiSourceFrame}s, in buffer order) onto AG-UI 1.0 events.
|
|
26
|
+
*
|
|
27
|
+
* A pure state machine: the same frames always give the same events, which is what lets a resuming
|
|
28
|
+
* request — served by any replica — replay the run's buffer, skip what the interrupted AG-UI run
|
|
29
|
+
* already delivered, and continue. It writes nothing itself; {@link agUiEvents} drives it and
|
|
30
|
+
* decides when the run has stopped to ask.
|
|
31
|
+
*
|
|
32
|
+
* What maps where:
|
|
33
|
+
* - `text` → `TEXT_MESSAGE_*` (one message per stretch of text);
|
|
34
|
+
* - `reasoning` → a reasoning span with one reasoning message;
|
|
35
|
+
* - `step-start`/`step-finish` → `STEP_STARTED`/`STEP_FINISHED`, the step's usage folded into the
|
|
36
|
+
* run's `usage`;
|
|
37
|
+
* - `tool-input-*` → `TOOL_CALL_START`/`ARGS`/`END` (the call's kind as `metadata['agora.toolKind']`);
|
|
38
|
+
* `tool-output*` → `TOOL_CALL_RESULT`;
|
|
39
|
+
* - an approval or a question set the run parks on → an `Interrupt` on the closing `RUN_FINISHED`;
|
|
40
|
+
* - `cancelled` → the cancelled outcome; an error frame → `RUN_ERROR`;
|
|
41
|
+
* - generative UI, title, queue and the native approval/elicitation frames → `CUSTOM` events named
|
|
42
|
+
* in {@link AG_UI_CUSTOM}, for what AG-UI has no event for.
|
|
43
|
+
*
|
|
44
|
+
* Not mapped: sub-agent attribution (`subagentRunId`) — a delegated agent's frames are projected
|
|
45
|
+
* flat, as the protocol allows of a producer that does not attribute.
|
|
46
|
+
*/
|
|
47
|
+
export declare class AgUiEncoder {
|
|
48
|
+
private readonly options;
|
|
49
|
+
private position;
|
|
50
|
+
private started;
|
|
51
|
+
private closed;
|
|
52
|
+
private cancelled;
|
|
53
|
+
private crossed;
|
|
54
|
+
private messageSeq;
|
|
55
|
+
private stepSeq;
|
|
56
|
+
private openText;
|
|
57
|
+
private openReasoning;
|
|
58
|
+
/** The last text message of the current step: a tool call attaches to it. */
|
|
59
|
+
private stepMessage;
|
|
60
|
+
private readonly openSteps;
|
|
61
|
+
private readonly calls;
|
|
62
|
+
private readonly pending;
|
|
63
|
+
private readonly usage;
|
|
64
|
+
constructor(options: AgUiEncoderOptions);
|
|
65
|
+
/** How many frames of the library stream this encoder has consumed. */
|
|
66
|
+
get consumed(): number;
|
|
67
|
+
/** The run is waiting on at least one approval or question set nobody has settled yet. */
|
|
68
|
+
get waiting(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Is anything still in flight that is NOT waiting on a person — a tool call announced and neither
|
|
71
|
+
* answered nor parked? While there is, more frames are coming without anyone's help.
|
|
72
|
+
*/
|
|
73
|
+
get busy(): boolean;
|
|
74
|
+
/** `RUN_STARTED`, and the library's own ids for the run. Call once, before the first frame. */
|
|
75
|
+
start(): AgUiEvent[];
|
|
76
|
+
/** The AG-UI events the next frame of the library stream stands for (possibly none). */
|
|
77
|
+
encode(frame: AgUiSourceFrame): AgUiEvent[];
|
|
78
|
+
/**
|
|
79
|
+
* The replayed frames are behind us: from here on events are written. The AG-UI run that delivered
|
|
80
|
+
* them closed everything it had open before it finished, so this run starts with nothing open, and
|
|
81
|
+
* what the resuming request answered is no longer waiting.
|
|
82
|
+
*/
|
|
83
|
+
private crossBoundary;
|
|
84
|
+
private get replaying();
|
|
85
|
+
private project;
|
|
86
|
+
/**
|
|
87
|
+
* The events that end the AG-UI run: whatever is still open is closed first, then `RUN_FINISHED`
|
|
88
|
+
* with how it ended — interrupted when the run is waiting on someone, cancelled when it was
|
|
89
|
+
* stopped, success otherwise. Nothing after a `RUN_ERROR`. `ended` says the library run's stream
|
|
90
|
+
* itself ended, rather than this reader having stopped following it.
|
|
91
|
+
*/
|
|
92
|
+
finish(ended?: boolean): AgUiEvent[];
|
|
93
|
+
private interrupts;
|
|
94
|
+
private custom;
|
|
95
|
+
private nextMessageId;
|
|
96
|
+
private textDelta;
|
|
97
|
+
private reasoningDelta;
|
|
98
|
+
private closeText;
|
|
99
|
+
private closeReasoning;
|
|
100
|
+
private closeStreams;
|
|
101
|
+
private callStart;
|
|
102
|
+
private result;
|
|
103
|
+
private addUsage;
|
|
104
|
+
private usageEntries;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=encoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../../../src/ag-ui/core/encoder.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,SAAS,EAEd,KAAK,eAAe,EAErB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,0GAA0G;IAC1G,WAAW,EAAE,MAAM,CAAC;IACpB,wFAAwF;IACxF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA6DD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,WAAW;IAiBV,OAAO,CAAC,QAAQ,CAAC,OAAO;IAhBpC,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,aAAa,CAAqB;IAC1C,6EAA6E;IAC7E,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqC;IAE3D,YAA6B,OAAO,EAAE,kBAAkB,EAAI;IAE5D,uEAAuE;IACvE,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,0FAA0F;IAC1F,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;OAGG;IACH,IAAI,IAAI,IAAI,OAAO,CAKlB;IAED,+FAA+F;IAC/F,KAAK,IAAI,SAAS,EAAE,CAmBnB;IAED,wFAAwF;IACxF,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,EAAE,CAgB1C;IAED;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAarB,OAAO,KAAK,SAAS,GAEpB;IAED,OAAO,CAAC,OAAO;IAmMf;;;;;OAKG;IACH,MAAM,CAAC,KAAK,UAAQ,GAAG,SAAS,EAAE,CA+BjC;IAED,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,SAAS;IAYjB,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,SAAS;IAYjB,OAAO,CAAC,MAAM;IA0Bd,OAAO,CAAC,QAAQ;IAsBhB,OAAO,CAAC,YAAY;CAGrB"}
|
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
import { encodeInterruptId } from './interrupt-id.js';
|
|
2
|
+
import { AG_UI_CUSTOM, AG_UI_PROTOCOL_VERSION, } from './types.js';
|
|
3
|
+
const APPROVAL_SCHEMA = {
|
|
4
|
+
type: 'object',
|
|
5
|
+
properties: {
|
|
6
|
+
approved: { type: 'boolean' },
|
|
7
|
+
reason: { type: 'string' },
|
|
8
|
+
remember: { type: 'boolean' },
|
|
9
|
+
},
|
|
10
|
+
required: ['approved'],
|
|
11
|
+
};
|
|
12
|
+
/** The answer an elicitation expects: `{ answers: { <questionId>: string[] } }`. */
|
|
13
|
+
function elicitationSchema(request) {
|
|
14
|
+
const properties = {};
|
|
15
|
+
for (const question of request.questions) {
|
|
16
|
+
const options = question.options?.map((option) => option.value);
|
|
17
|
+
properties[question.id] = {
|
|
18
|
+
type: 'array',
|
|
19
|
+
title: question.prompt,
|
|
20
|
+
...(question.description !== undefined ? { description: question.description } : {}),
|
|
21
|
+
items: options !== undefined && options.length > 0 && question.allowFreeText !== true
|
|
22
|
+
? { type: 'string', enum: options }
|
|
23
|
+
: { type: 'string' },
|
|
24
|
+
...(question.multiple === true ? {} : { maxItems: 1 }),
|
|
25
|
+
...(question.defaults !== undefined ? { default: question.defaults } : {}),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: { answers: { type: 'object', properties } },
|
|
31
|
+
required: ['answers'],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function text(value) {
|
|
35
|
+
if (typeof value === 'string')
|
|
36
|
+
return value;
|
|
37
|
+
const json = JSON.stringify(value);
|
|
38
|
+
return json === undefined ? '' : json;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Projects one library run's stream ({@link AgUiSourceFrame}s, in buffer order) onto AG-UI 1.0 events.
|
|
42
|
+
*
|
|
43
|
+
* A pure state machine: the same frames always give the same events, which is what lets a resuming
|
|
44
|
+
* request — served by any replica — replay the run's buffer, skip what the interrupted AG-UI run
|
|
45
|
+
* already delivered, and continue. It writes nothing itself; {@link agUiEvents} drives it and
|
|
46
|
+
* decides when the run has stopped to ask.
|
|
47
|
+
*
|
|
48
|
+
* What maps where:
|
|
49
|
+
* - `text` → `TEXT_MESSAGE_*` (one message per stretch of text);
|
|
50
|
+
* - `reasoning` → a reasoning span with one reasoning message;
|
|
51
|
+
* - `step-start`/`step-finish` → `STEP_STARTED`/`STEP_FINISHED`, the step's usage folded into the
|
|
52
|
+
* run's `usage`;
|
|
53
|
+
* - `tool-input-*` → `TOOL_CALL_START`/`ARGS`/`END` (the call's kind as `metadata['agora.toolKind']`);
|
|
54
|
+
* `tool-output*` → `TOOL_CALL_RESULT`;
|
|
55
|
+
* - an approval or a question set the run parks on → an `Interrupt` on the closing `RUN_FINISHED`;
|
|
56
|
+
* - `cancelled` → the cancelled outcome; an error frame → `RUN_ERROR`;
|
|
57
|
+
* - generative UI, title, queue and the native approval/elicitation frames → `CUSTOM` events named
|
|
58
|
+
* in {@link AG_UI_CUSTOM}, for what AG-UI has no event for.
|
|
59
|
+
*
|
|
60
|
+
* Not mapped: sub-agent attribution (`subagentRunId`) — a delegated agent's frames are projected
|
|
61
|
+
* flat, as the protocol allows of a producer that does not attribute.
|
|
62
|
+
*/
|
|
63
|
+
export class AgUiEncoder {
|
|
64
|
+
options;
|
|
65
|
+
position = 0;
|
|
66
|
+
started = false;
|
|
67
|
+
closed = false;
|
|
68
|
+
cancelled = false;
|
|
69
|
+
crossed = false;
|
|
70
|
+
messageSeq = 0;
|
|
71
|
+
stepSeq = 0;
|
|
72
|
+
openText;
|
|
73
|
+
openReasoning;
|
|
74
|
+
/** The last text message of the current step: a tool call attaches to it. */
|
|
75
|
+
stepMessage;
|
|
76
|
+
openSteps = [];
|
|
77
|
+
calls = new Map();
|
|
78
|
+
pending = new Map();
|
|
79
|
+
usage = new Map();
|
|
80
|
+
constructor(options) {
|
|
81
|
+
this.options = options;
|
|
82
|
+
}
|
|
83
|
+
/** How many frames of the library stream this encoder has consumed. */
|
|
84
|
+
get consumed() {
|
|
85
|
+
return this.position;
|
|
86
|
+
}
|
|
87
|
+
/** The run is waiting on at least one approval or question set nobody has settled yet. */
|
|
88
|
+
get waiting() {
|
|
89
|
+
return this.pending.size > 0;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Is anything still in flight that is NOT waiting on a person — a tool call announced and neither
|
|
93
|
+
* answered nor parked? While there is, more frames are coming without anyone's help.
|
|
94
|
+
*/
|
|
95
|
+
get busy() {
|
|
96
|
+
for (const [id, call] of this.calls) {
|
|
97
|
+
if (!call.answered && !this.pending.has(id))
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
/** `RUN_STARTED`, and the library's own ids for the run. Call once, before the first frame. */
|
|
103
|
+
start() {
|
|
104
|
+
if (this.started)
|
|
105
|
+
return [];
|
|
106
|
+
this.started = true;
|
|
107
|
+
return [
|
|
108
|
+
{
|
|
109
|
+
type: 'RUN_STARTED',
|
|
110
|
+
threadId: this.options.threadId,
|
|
111
|
+
runId: this.options.runId,
|
|
112
|
+
protocolVersion: AG_UI_PROTOCOL_VERSION,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: 'CUSTOM',
|
|
116
|
+
name: AG_UI_CUSTOM.run,
|
|
117
|
+
value: {
|
|
118
|
+
runId: this.options.streamRunId,
|
|
119
|
+
threadId: this.options.streamThreadId ?? this.options.threadId,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
/** The AG-UI events the next frame of the library stream stands for (possibly none). */
|
|
125
|
+
encode(frame) {
|
|
126
|
+
const position = this.position;
|
|
127
|
+
this.position += 1;
|
|
128
|
+
if (this.closed)
|
|
129
|
+
return [];
|
|
130
|
+
const skip = this.options.skip ?? 0;
|
|
131
|
+
if (!this.crossed && position >= skip)
|
|
132
|
+
this.crossBoundary();
|
|
133
|
+
const events = this.project(frame, position);
|
|
134
|
+
// A frame an earlier AG-UI run already delivered still moves the state (what is open, what is
|
|
135
|
+
// pending; NOT what was spent — usage is per run) but writes nothing. The last of them is the
|
|
136
|
+
// boundary: crossed at once, not when the next frame happens to arrive, because a run that was
|
|
137
|
+
// just answered may take a moment to write one.
|
|
138
|
+
if (position < skip) {
|
|
139
|
+
if (this.position >= skip)
|
|
140
|
+
this.crossBoundary();
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
return events;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The replayed frames are behind us: from here on events are written. The AG-UI run that delivered
|
|
147
|
+
* them closed everything it had open before it finished, so this run starts with nothing open, and
|
|
148
|
+
* what the resuming request answered is no longer waiting.
|
|
149
|
+
*/
|
|
150
|
+
crossBoundary() {
|
|
151
|
+
this.crossed = true;
|
|
152
|
+
this.openText = undefined;
|
|
153
|
+
this.openReasoning = undefined;
|
|
154
|
+
this.stepMessage = undefined;
|
|
155
|
+
this.openSteps.length = 0;
|
|
156
|
+
for (const call of this.calls.values()) {
|
|
157
|
+
call.started = false;
|
|
158
|
+
call.ended = true;
|
|
159
|
+
}
|
|
160
|
+
for (const id of this.options.answered ?? [])
|
|
161
|
+
this.pending.delete(id);
|
|
162
|
+
}
|
|
163
|
+
get replaying() {
|
|
164
|
+
return this.position <= (this.options.skip ?? 0);
|
|
165
|
+
}
|
|
166
|
+
project(event, position) {
|
|
167
|
+
switch (event.kind) {
|
|
168
|
+
case 'error': {
|
|
169
|
+
this.closed = true;
|
|
170
|
+
const usage = this.usageEntries();
|
|
171
|
+
return [
|
|
172
|
+
{
|
|
173
|
+
type: 'RUN_ERROR',
|
|
174
|
+
message: event.message,
|
|
175
|
+
code: event.code,
|
|
176
|
+
...(usage.length > 0 ? { usage } : {}),
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
case 'ui':
|
|
181
|
+
return [
|
|
182
|
+
this.custom(AG_UI_CUSTOM.ui, {
|
|
183
|
+
id: event.id ?? `ui:${position}`,
|
|
184
|
+
component: event.component,
|
|
185
|
+
props: event.props,
|
|
186
|
+
...(event.version !== undefined ? { version: event.version } : {}),
|
|
187
|
+
// What a client that cannot draw the component shows instead.
|
|
188
|
+
...(event.fallbackText !== undefined ? { fallbackText: event.fallbackText } : {}),
|
|
189
|
+
...(event.componentVersions !== undefined
|
|
190
|
+
? { componentVersions: event.componentVersions }
|
|
191
|
+
: {}),
|
|
192
|
+
...(event.toolCallId !== undefined ? { toolCallId: event.toolCallId } : {}),
|
|
193
|
+
}),
|
|
194
|
+
];
|
|
195
|
+
case 'approval-requested': {
|
|
196
|
+
const call = this.calls.get(event.id);
|
|
197
|
+
const parked = event.runId ?? this.options.streamRunId;
|
|
198
|
+
const toolName = event.toolName ?? call?.name ?? '';
|
|
199
|
+
const input = event.input ?? call?.input ?? null;
|
|
200
|
+
// An independent proposal: decided through the proposal service, not by signalling the run.
|
|
201
|
+
const proposal = event.target?.kind === 'proposal' ? event.target : undefined;
|
|
202
|
+
this.pending.set(event.id, {
|
|
203
|
+
kind: proposal !== undefined ? 'proposal' : 'approval',
|
|
204
|
+
parked,
|
|
205
|
+
toolCallId: event.id,
|
|
206
|
+
...(proposal !== undefined ? { proposalId: proposal.proposalId } : {}),
|
|
207
|
+
interrupt: {
|
|
208
|
+
reason: 'tool_approval',
|
|
209
|
+
message: event.reason ?? (toolName.length > 0 ? `Approve ${toolName}?` : 'Approve?'),
|
|
210
|
+
toolCallId: event.id,
|
|
211
|
+
responseSchema: APPROVAL_SCHEMA,
|
|
212
|
+
...(event.expiresAt !== undefined ? { expiresAt: event.expiresAt } : {}),
|
|
213
|
+
metadata: {
|
|
214
|
+
'agora.toolName': toolName,
|
|
215
|
+
'agora.input': input,
|
|
216
|
+
'agora.approver': event.approver,
|
|
217
|
+
...(event.target !== undefined ? { 'agora.target': event.target } : {}),
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
return [
|
|
222
|
+
this.custom(AG_UI_CUSTOM.approvalRequested, {
|
|
223
|
+
id: event.id,
|
|
224
|
+
runId: parked,
|
|
225
|
+
toolName,
|
|
226
|
+
input,
|
|
227
|
+
approver: event.approver,
|
|
228
|
+
...(event.target !== undefined ? { target: event.target } : {}),
|
|
229
|
+
...(event.confirmation !== undefined ? { confirmation: event.confirmation } : {}),
|
|
230
|
+
...(event.expiresAt !== undefined ? { expiresAt: event.expiresAt } : {}),
|
|
231
|
+
...(event.reason !== undefined ? { reason: event.reason } : {}),
|
|
232
|
+
}),
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
case 'elicitation': {
|
|
236
|
+
const parked = event.runId ?? this.options.streamRunId;
|
|
237
|
+
this.pending.set(event.id, {
|
|
238
|
+
kind: 'elicitation',
|
|
239
|
+
parked,
|
|
240
|
+
toolCallId: event.id,
|
|
241
|
+
interrupt: {
|
|
242
|
+
reason: 'input_required',
|
|
243
|
+
message: event.request.preamble ?? event.request.questions[0]?.prompt ?? 'Input required',
|
|
244
|
+
// An intake's question set belongs to no tool call the stream announced.
|
|
245
|
+
...(this.calls.has(event.id) ? { toolCallId: event.id } : {}),
|
|
246
|
+
responseSchema: elicitationSchema(event.request),
|
|
247
|
+
metadata: { 'agora.request': event.request },
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
return [
|
|
251
|
+
this.custom(AG_UI_CUSTOM.elicitation, {
|
|
252
|
+
id: event.id,
|
|
253
|
+
runId: parked,
|
|
254
|
+
request: event.request,
|
|
255
|
+
}),
|
|
256
|
+
];
|
|
257
|
+
}
|
|
258
|
+
case 'text':
|
|
259
|
+
return event.text.length > 0 ? this.textDelta(event.text) : [];
|
|
260
|
+
case 'reasoning':
|
|
261
|
+
return event.text.length > 0 ? this.reasoningDelta(event.text) : [];
|
|
262
|
+
case 'step-start': {
|
|
263
|
+
this.stepSeq += 1;
|
|
264
|
+
const stepName = `step-${this.stepSeq}`;
|
|
265
|
+
this.openSteps.push(stepName);
|
|
266
|
+
this.stepMessage = undefined;
|
|
267
|
+
return [...this.closeStreams(), { type: 'STEP_STARTED', stepName }];
|
|
268
|
+
}
|
|
269
|
+
case 'step-finish': {
|
|
270
|
+
const out = this.closeStreams();
|
|
271
|
+
if (!this.replaying)
|
|
272
|
+
this.addUsage(event.usage, event.model);
|
|
273
|
+
const stepName = this.openSteps.pop();
|
|
274
|
+
if (stepName !== undefined)
|
|
275
|
+
out.push({ type: 'STEP_FINISHED', stepName });
|
|
276
|
+
if (event.usage !== undefined || event.costUsd !== undefined) {
|
|
277
|
+
out.push(this.custom(AG_UI_CUSTOM.stepUsage, {
|
|
278
|
+
...(event.usage !== undefined ? { usage: event.usage } : {}),
|
|
279
|
+
...(event.costUsd !== undefined ? { costUsd: event.costUsd } : {}),
|
|
280
|
+
...(event.reasoningMs !== undefined ? { reasoningMs: event.reasoningMs } : {}),
|
|
281
|
+
...(typeof event.model === 'string' ? { model: event.model } : {}),
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
return out;
|
|
285
|
+
}
|
|
286
|
+
case 'tool-input-start': {
|
|
287
|
+
if (this.calls.has(event.id))
|
|
288
|
+
return [];
|
|
289
|
+
const out = this.closeStreams();
|
|
290
|
+
this.calls.set(event.id, {
|
|
291
|
+
name: event.name,
|
|
292
|
+
started: true,
|
|
293
|
+
ended: false,
|
|
294
|
+
sawDelta: false,
|
|
295
|
+
answered: false,
|
|
296
|
+
});
|
|
297
|
+
out.push(this.callStart(event.id, event.name, event.toolKind));
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
case 'tool-input-delta': {
|
|
301
|
+
const call = this.calls.get(event.id);
|
|
302
|
+
if (call === undefined || call.ended || event.delta.length === 0)
|
|
303
|
+
return [];
|
|
304
|
+
call.sawDelta = true;
|
|
305
|
+
return [{ type: 'TOOL_CALL_ARGS', toolCallId: event.id, delta: event.delta }];
|
|
306
|
+
}
|
|
307
|
+
case 'tool-input-available': {
|
|
308
|
+
const known = this.calls.get(event.id);
|
|
309
|
+
if (known?.ended === true)
|
|
310
|
+
return [];
|
|
311
|
+
const out = this.closeStreams();
|
|
312
|
+
const call = known ?? {
|
|
313
|
+
name: event.name,
|
|
314
|
+
started: false,
|
|
315
|
+
ended: false,
|
|
316
|
+
sawDelta: false,
|
|
317
|
+
answered: false,
|
|
318
|
+
};
|
|
319
|
+
if (!call.started) {
|
|
320
|
+
call.started = true;
|
|
321
|
+
out.push(this.callStart(event.id, event.name, event.toolKind));
|
|
322
|
+
}
|
|
323
|
+
if (!call.sawDelta) {
|
|
324
|
+
out.push({
|
|
325
|
+
type: 'TOOL_CALL_ARGS',
|
|
326
|
+
toolCallId: event.id,
|
|
327
|
+
delta: text(event.input ?? {}),
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
call.ended = true;
|
|
331
|
+
call.input = event.input;
|
|
332
|
+
this.calls.set(event.id, call);
|
|
333
|
+
out.push({ type: 'TOOL_CALL_END', toolCallId: event.id });
|
|
334
|
+
return out;
|
|
335
|
+
}
|
|
336
|
+
case 'tool-output':
|
|
337
|
+
return this.result(event.id, text(event.output));
|
|
338
|
+
case 'tool-output-error':
|
|
339
|
+
return this.result(event.id, event.error, { 'agora.outcome': 'error' });
|
|
340
|
+
case 'tool-output-denied':
|
|
341
|
+
return this.result(event.id, event.reason ?? 'denied', { 'agora.outcome': 'denied' });
|
|
342
|
+
case 'approval-settled':
|
|
343
|
+
this.pending.delete(event.id);
|
|
344
|
+
return [this.custom(AG_UI_CUSTOM.approvalSettled, event)];
|
|
345
|
+
case 'title':
|
|
346
|
+
return [this.custom(AG_UI_CUSTOM.title, { title: event.title })];
|
|
347
|
+
case 'queue':
|
|
348
|
+
return [
|
|
349
|
+
this.custom(AG_UI_CUSTOM.queue, {
|
|
350
|
+
queue: event.queue,
|
|
351
|
+
...(event.started !== undefined ? { started: event.started } : {}),
|
|
352
|
+
}),
|
|
353
|
+
];
|
|
354
|
+
case 'cancelled':
|
|
355
|
+
this.cancelled = true;
|
|
356
|
+
return [];
|
|
357
|
+
default:
|
|
358
|
+
// A kind newer than this encoder: tolerated, as every reader of the stream must.
|
|
359
|
+
return [];
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* The events that end the AG-UI run: whatever is still open is closed first, then `RUN_FINISHED`
|
|
364
|
+
* with how it ended — interrupted when the run is waiting on someone, cancelled when it was
|
|
365
|
+
* stopped, success otherwise. Nothing after a `RUN_ERROR`. `ended` says the library run's stream
|
|
366
|
+
* itself ended, rather than this reader having stopped following it.
|
|
367
|
+
*/
|
|
368
|
+
finish(ended = false) {
|
|
369
|
+
if (this.closed)
|
|
370
|
+
return [];
|
|
371
|
+
this.closed = true;
|
|
372
|
+
if (!this.crossed)
|
|
373
|
+
this.crossBoundary();
|
|
374
|
+
// A library run that ended is waiting on no one, whatever it asked along the way.
|
|
375
|
+
if (ended)
|
|
376
|
+
this.pending.clear();
|
|
377
|
+
const out = this.start();
|
|
378
|
+
out.push(...this.closeStreams());
|
|
379
|
+
for (const [id, call] of this.calls) {
|
|
380
|
+
if (call.started && !call.ended) {
|
|
381
|
+
call.ended = true;
|
|
382
|
+
out.push({ type: 'TOOL_CALL_END', toolCallId: id });
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
while (this.openSteps.length > 0) {
|
|
386
|
+
out.push({ type: 'STEP_FINISHED', stepName: this.openSteps.pop() });
|
|
387
|
+
}
|
|
388
|
+
const usage = this.usageEntries();
|
|
389
|
+
const interrupts = this.cancelled ? [] : this.interrupts();
|
|
390
|
+
out.push({
|
|
391
|
+
type: 'RUN_FINISHED',
|
|
392
|
+
threadId: this.options.threadId,
|
|
393
|
+
runId: this.options.runId,
|
|
394
|
+
...(this.cancelled
|
|
395
|
+
? { outcome: { type: 'cancelled' } }
|
|
396
|
+
: interrupts.length > 0
|
|
397
|
+
? { outcome: { type: 'interrupt', interrupts } }
|
|
398
|
+
: {}),
|
|
399
|
+
...(usage.length > 0 ? { usage } : {}),
|
|
400
|
+
});
|
|
401
|
+
return out;
|
|
402
|
+
}
|
|
403
|
+
interrupts() {
|
|
404
|
+
return [...this.pending.values()].map((entry) => ({
|
|
405
|
+
id: encodeInterruptId({
|
|
406
|
+
kind: entry.kind,
|
|
407
|
+
parked: entry.parked,
|
|
408
|
+
stream: this.options.streamRunId,
|
|
409
|
+
toolCallId: entry.toolCallId,
|
|
410
|
+
position: this.position,
|
|
411
|
+
...(entry.proposalId !== undefined
|
|
412
|
+
? {
|
|
413
|
+
proposalId: entry.proposalId,
|
|
414
|
+
threadId: this.options.streamThreadId ?? this.options.threadId,
|
|
415
|
+
}
|
|
416
|
+
: {}),
|
|
417
|
+
}),
|
|
418
|
+
...entry.interrupt,
|
|
419
|
+
}));
|
|
420
|
+
}
|
|
421
|
+
custom(name, value) {
|
|
422
|
+
return { type: 'CUSTOM', name, value };
|
|
423
|
+
}
|
|
424
|
+
nextMessageId() {
|
|
425
|
+
this.messageSeq += 1;
|
|
426
|
+
return `${this.options.runId}:m${this.messageSeq}`;
|
|
427
|
+
}
|
|
428
|
+
textDelta(delta) {
|
|
429
|
+
const out = [];
|
|
430
|
+
if (this.openReasoning !== undefined)
|
|
431
|
+
out.push(...this.closeReasoning());
|
|
432
|
+
if (this.openText === undefined) {
|
|
433
|
+
this.openText = this.nextMessageId();
|
|
434
|
+
this.stepMessage = this.openText;
|
|
435
|
+
out.push({ type: 'TEXT_MESSAGE_START', messageId: this.openText, role: 'assistant' });
|
|
436
|
+
}
|
|
437
|
+
out.push({ type: 'TEXT_MESSAGE_CONTENT', messageId: this.openText, delta });
|
|
438
|
+
return out;
|
|
439
|
+
}
|
|
440
|
+
reasoningDelta(delta) {
|
|
441
|
+
const out = [];
|
|
442
|
+
if (this.openText !== undefined)
|
|
443
|
+
out.push(...this.closeText());
|
|
444
|
+
if (this.openReasoning === undefined) {
|
|
445
|
+
this.openReasoning = this.nextMessageId();
|
|
446
|
+
out.push({ type: 'REASONING_START', messageId: this.openReasoning }, { type: 'REASONING_MESSAGE_START', messageId: this.openReasoning, role: 'reasoning' });
|
|
447
|
+
}
|
|
448
|
+
out.push({ type: 'REASONING_MESSAGE_CONTENT', messageId: this.openReasoning, delta });
|
|
449
|
+
return out;
|
|
450
|
+
}
|
|
451
|
+
closeText() {
|
|
452
|
+
if (this.openText === undefined)
|
|
453
|
+
return [];
|
|
454
|
+
const messageId = this.openText;
|
|
455
|
+
this.openText = undefined;
|
|
456
|
+
return [{ type: 'TEXT_MESSAGE_END', messageId }];
|
|
457
|
+
}
|
|
458
|
+
closeReasoning() {
|
|
459
|
+
if (this.openReasoning === undefined)
|
|
460
|
+
return [];
|
|
461
|
+
const messageId = this.openReasoning;
|
|
462
|
+
this.openReasoning = undefined;
|
|
463
|
+
return [
|
|
464
|
+
{ type: 'REASONING_MESSAGE_END', messageId },
|
|
465
|
+
{ type: 'REASONING_END', messageId },
|
|
466
|
+
];
|
|
467
|
+
}
|
|
468
|
+
closeStreams() {
|
|
469
|
+
return [...this.closeReasoning(), ...this.closeText()];
|
|
470
|
+
}
|
|
471
|
+
callStart(id, name, kind) {
|
|
472
|
+
return {
|
|
473
|
+
type: 'TOOL_CALL_START',
|
|
474
|
+
toolCallId: id,
|
|
475
|
+
toolCallName: name,
|
|
476
|
+
...(this.stepMessage !== undefined ? { parentMessageId: this.stepMessage } : {}),
|
|
477
|
+
// Whether the call reads or acts — AG-UI has no field for it; a consumer of this family
|
|
478
|
+
// renders an action differently (and may be asked to approve it).
|
|
479
|
+
...(kind !== undefined ? { metadata: { 'agora.toolKind': kind } } : {}),
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
result(id, content, metadata) {
|
|
483
|
+
const call = this.calls.get(id);
|
|
484
|
+
if (call !== undefined)
|
|
485
|
+
call.answered = true;
|
|
486
|
+
else {
|
|
487
|
+
this.calls.set(id, {
|
|
488
|
+
name: '',
|
|
489
|
+
started: false,
|
|
490
|
+
ended: true,
|
|
491
|
+
sawDelta: false,
|
|
492
|
+
answered: true,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
this.pending.delete(id);
|
|
496
|
+
return [
|
|
497
|
+
...this.closeStreams(),
|
|
498
|
+
{
|
|
499
|
+
type: 'TOOL_CALL_RESULT',
|
|
500
|
+
messageId: `${this.options.runId}:tool:${id}`,
|
|
501
|
+
toolCallId: id,
|
|
502
|
+
content,
|
|
503
|
+
role: 'tool',
|
|
504
|
+
...(metadata !== undefined ? { metadata } : {}),
|
|
505
|
+
},
|
|
506
|
+
];
|
|
507
|
+
}
|
|
508
|
+
addUsage(usage, model) {
|
|
509
|
+
if (usage === undefined)
|
|
510
|
+
return;
|
|
511
|
+
const name = typeof model === 'string' && model.length > 0 ? model : this.options.model;
|
|
512
|
+
const key = name ?? '';
|
|
513
|
+
const entry = this.usage.get(key) ?? (name !== undefined ? { model: name } : {});
|
|
514
|
+
// The library's accounting is already the protocol's: input and output are totals, cache and
|
|
515
|
+
// reasoning counts are parts of them. A count the provider did not report stays absent.
|
|
516
|
+
entry.inputTokens = (entry.inputTokens ?? 0) + usage.inputTokens;
|
|
517
|
+
entry.outputTokens = (entry.outputTokens ?? 0) + usage.outputTokens;
|
|
518
|
+
entry.totalTokens = entry.inputTokens + entry.outputTokens;
|
|
519
|
+
if (usage.cacheReadTokens !== undefined) {
|
|
520
|
+
entry.cachedInputTokens = (entry.cachedInputTokens ?? 0) + usage.cacheReadTokens;
|
|
521
|
+
}
|
|
522
|
+
if (usage.cacheWriteTokens !== undefined) {
|
|
523
|
+
entry.cacheWriteInputTokens = (entry.cacheWriteInputTokens ?? 0) + usage.cacheWriteTokens;
|
|
524
|
+
}
|
|
525
|
+
if (usage.reasoningTokens !== undefined) {
|
|
526
|
+
entry.reasoningTokens = (entry.reasoningTokens ?? 0) + usage.reasoningTokens;
|
|
527
|
+
}
|
|
528
|
+
this.usage.set(key, entry);
|
|
529
|
+
}
|
|
530
|
+
usageEntries() {
|
|
531
|
+
return [...this.usage.values()];
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
//# sourceMappingURL=encoder.js.map
|