@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,761 @@
|
|
|
1
|
+
import { ASK_TOOL_NAME, isHumanDecision, normalizeElicitationReply, settleElicitation, } from '../elicitation.js';
|
|
2
|
+
import { toElicitation, toFormAnswer } from './forms.js';
|
|
3
|
+
import { errorText, openCodeLog } from './log.js';
|
|
4
|
+
const FAILED_STATUSES = new Set(['error', 'failed', 'denied', 'cancelled']);
|
|
5
|
+
/**
|
|
6
|
+
* OpenCode tools the stream does not show as calls: the question tool IS the form, which streams as
|
|
7
|
+
* an `elicitation` of its own.
|
|
8
|
+
*/
|
|
9
|
+
const HIDDEN_TOOLS = new Set(['question']);
|
|
10
|
+
function emptySegment() {
|
|
11
|
+
return { text: '', reasoning: '', reasoningMs: 0, calls: [], results: [], ui: [] };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The arguments of the call a permission is about. OpenCode puts a built-in tool's arguments
|
|
15
|
+
* straight in `metadata` (`webfetch` → `{ url, format }`); calls that wrap others nest them under
|
|
16
|
+
* `input` or `args`.
|
|
17
|
+
*/
|
|
18
|
+
function permissionArgs(request) {
|
|
19
|
+
const metadata = request.metadata ?? {};
|
|
20
|
+
const nested = metadata.input ?? metadata.args;
|
|
21
|
+
if (nested !== null && typeof nested === 'object')
|
|
22
|
+
return nested;
|
|
23
|
+
return metadata;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* One turn of an OpenCode session, as the library's stream and store see it. Fed the session's
|
|
27
|
+
* events in order, it writes the protocol's frames and persists what the loop would have — the
|
|
28
|
+
* assistant messages with their tool calls and results, the calls put to a person (so the
|
|
29
|
+
* approve/answer routes find their run), usage per model step — and reports {@link Milestone}s: a
|
|
30
|
+
* person was asked something, or the execution ended.
|
|
31
|
+
*
|
|
32
|
+
* The turn does not wait for people itself. Whoever drives it (`OpenCodeTurns`, under an in-memory
|
|
33
|
+
* or a durable runner) takes the `ask` milestone, waits however it waits, and hands the answer back
|
|
34
|
+
* with {@link decide} — which is what lets a durable run wait across a restart and reply from
|
|
35
|
+
* another process, with a fresh turn object fed the journaled {@link PendingAsk}.
|
|
36
|
+
*/
|
|
37
|
+
export class OpenCodeTurn {
|
|
38
|
+
a;
|
|
39
|
+
/** Serializes the handling of events, so frames and rows land in the order OpenCode sent them. */
|
|
40
|
+
chain = Promise.resolve();
|
|
41
|
+
segment = emptySegment();
|
|
42
|
+
tools = new Map();
|
|
43
|
+
/** Results already persisted per message, so a late settlement adds to them rather than replacing. */
|
|
44
|
+
messageResults = new Map();
|
|
45
|
+
asked = new Set();
|
|
46
|
+
/** Calls of {@link HIDDEN_TOOLS}, by id. */
|
|
47
|
+
hidden = new Set();
|
|
48
|
+
milestones = [];
|
|
49
|
+
waiting;
|
|
50
|
+
usage = { inputTokens: 0, outputTokens: 0 };
|
|
51
|
+
costUsd;
|
|
52
|
+
steps = 0;
|
|
53
|
+
stepOpen = false;
|
|
54
|
+
sawText = false;
|
|
55
|
+
separator = false;
|
|
56
|
+
reasoningSince;
|
|
57
|
+
wroteMessage = false;
|
|
58
|
+
ended = false;
|
|
59
|
+
stepError;
|
|
60
|
+
constructor(a) {
|
|
61
|
+
this.a = a;
|
|
62
|
+
}
|
|
63
|
+
get sessionId() {
|
|
64
|
+
return this.a.sessionId;
|
|
65
|
+
}
|
|
66
|
+
get finished() {
|
|
67
|
+
return this.ended;
|
|
68
|
+
}
|
|
69
|
+
/** The turn's totals so far: tokens, cost, model steps. */
|
|
70
|
+
totals() {
|
|
71
|
+
return {
|
|
72
|
+
inputTokens: this.usage.inputTokens,
|
|
73
|
+
outputTokens: this.usage.outputTokens,
|
|
74
|
+
...(this.costUsd !== undefined ? { costUsd: this.costUsd } : {}),
|
|
75
|
+
steps: this.steps,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Feed one of the session's events. */
|
|
79
|
+
handle(event) {
|
|
80
|
+
this.enqueue(() => this.onEvent(event));
|
|
81
|
+
}
|
|
82
|
+
/** End the turn as failed without an event (the prompt was refused, the stream is gone). */
|
|
83
|
+
fail(error) {
|
|
84
|
+
this.enqueue(() => this.end({ status: 'failed', error }));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A component a tool pushed (`ctx.emitUi`, through the engine's MCP endpoint): streamed as a `ui`
|
|
88
|
+
* frame and persisted on the message being written, in the order it arrived. Pushing the same id
|
|
89
|
+
* again replaces it.
|
|
90
|
+
*/
|
|
91
|
+
pushUi(component) {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
this.chain = this.chain
|
|
94
|
+
.then(async () => {
|
|
95
|
+
await this.step();
|
|
96
|
+
const ui = this.segment.ui;
|
|
97
|
+
const at = ui.findIndex((existing) => existing.id === component.id);
|
|
98
|
+
if (at >= 0)
|
|
99
|
+
ui[at] = component;
|
|
100
|
+
else
|
|
101
|
+
ui.push(component);
|
|
102
|
+
await this.event({ kind: 'ui', ...component });
|
|
103
|
+
})
|
|
104
|
+
.then(resolve, reject);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** The next milestone: one already reached, or the next one to come. */
|
|
108
|
+
next() {
|
|
109
|
+
const ready = this.milestones.shift();
|
|
110
|
+
if (ready !== undefined)
|
|
111
|
+
return Promise.resolve(ready);
|
|
112
|
+
return new Promise((resolve) => {
|
|
113
|
+
this.waiting = resolve;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** Whether a milestone is waiting to be taken. */
|
|
117
|
+
hasMilestone() {
|
|
118
|
+
return this.milestones.length > 0;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Requests OpenCode raised while nobody listened (this process started after them, or the event
|
|
122
|
+
* stream dropped): its open permissions and forms, handled as if their events had just arrived.
|
|
123
|
+
* One already recorded in the store is reported without being recorded or streamed again.
|
|
124
|
+
*/
|
|
125
|
+
async catchUp() {
|
|
126
|
+
const { client, sessionId } = this.a;
|
|
127
|
+
const permissions = (await client.permission.list?.({ sessionID: sessionId })) ?? [];
|
|
128
|
+
const forms = (await client.session.form.list?.({ sessionID: sessionId })) ?? [];
|
|
129
|
+
await new Promise((resolve) => {
|
|
130
|
+
this.enqueue(async () => {
|
|
131
|
+
for (const permission of permissions)
|
|
132
|
+
await this.onPermission(permission, true);
|
|
133
|
+
for (const form of forms)
|
|
134
|
+
await this.onForm(form, true);
|
|
135
|
+
resolve();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Hand a person's answer to what the turn asked, and let OpenCode go on. `tellOpenCode: false`
|
|
141
|
+
* only settles the call (stream and store): the request died with a restarted server, and the
|
|
142
|
+
* new session is told the answer in its prompt instead.
|
|
143
|
+
*/
|
|
144
|
+
decide(ask, reply, opts = {}) {
|
|
145
|
+
const tell = opts.tellOpenCode ?? true;
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
this.chain = this.chain
|
|
148
|
+
.then(() => ask.kind === 'approval'
|
|
149
|
+
? this.decided(ask, reply, tell)
|
|
150
|
+
: this.answered(ask, reply, tell))
|
|
151
|
+
.then(resolve, reject);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
reach(milestone) {
|
|
155
|
+
const waiting = this.waiting;
|
|
156
|
+
if (waiting !== undefined) {
|
|
157
|
+
this.waiting = undefined;
|
|
158
|
+
waiting(milestone);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
this.milestones.push(milestone);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
enqueue(work) {
|
|
165
|
+
this.chain = this.chain.then(work).catch((error) => {
|
|
166
|
+
openCodeLog.error(`run ${this.a.runId}: ${errorText(error, 'event handling failed')}`);
|
|
167
|
+
// A turn whose bookkeeping broke can't be trusted to finish on its own.
|
|
168
|
+
if (!this.ended) {
|
|
169
|
+
this.ended = true;
|
|
170
|
+
this.reach({
|
|
171
|
+
kind: 'finished',
|
|
172
|
+
outcome: { status: 'failed', error: errorText(error, 'event handling failed') },
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
async write(frame) {
|
|
178
|
+
await this.a.writer.write(frame);
|
|
179
|
+
}
|
|
180
|
+
async event(event) {
|
|
181
|
+
await this.write({ t: 'event', event });
|
|
182
|
+
}
|
|
183
|
+
async step() {
|
|
184
|
+
if (this.stepOpen)
|
|
185
|
+
return;
|
|
186
|
+
this.stepOpen = true;
|
|
187
|
+
await this.event({ kind: 'step-start' });
|
|
188
|
+
}
|
|
189
|
+
endReasoning() {
|
|
190
|
+
if (this.reasoningSince === undefined)
|
|
191
|
+
return;
|
|
192
|
+
this.segment.reasoningMs += Date.now() - this.reasoningSince;
|
|
193
|
+
this.reasoningSince = undefined;
|
|
194
|
+
}
|
|
195
|
+
tool(id, name = 'tool') {
|
|
196
|
+
let state = this.tools.get(id);
|
|
197
|
+
if (state === undefined) {
|
|
198
|
+
state = {
|
|
199
|
+
name,
|
|
200
|
+
announced: false,
|
|
201
|
+
available: false,
|
|
202
|
+
settled: false,
|
|
203
|
+
input: {},
|
|
204
|
+
innerAnnounced: new Set(),
|
|
205
|
+
innerSettled: new Set(),
|
|
206
|
+
};
|
|
207
|
+
this.tools.set(id, state);
|
|
208
|
+
this.segment.calls.push({ id, name, input: state.input, kind: 'read' });
|
|
209
|
+
}
|
|
210
|
+
return state;
|
|
211
|
+
}
|
|
212
|
+
async announce(id, name) {
|
|
213
|
+
const state = this.tool(id, name);
|
|
214
|
+
if (!state.announced) {
|
|
215
|
+
state.announced = true;
|
|
216
|
+
await this.event({ kind: 'tool-input-start', id, name: state.name, toolKind: 'read' });
|
|
217
|
+
}
|
|
218
|
+
return state;
|
|
219
|
+
}
|
|
220
|
+
async makeAvailable(id) {
|
|
221
|
+
const state = await this.announce(id, this.tools.get(id)?.name ?? 'tool');
|
|
222
|
+
if (!state.available) {
|
|
223
|
+
state.available = true;
|
|
224
|
+
await this.event({
|
|
225
|
+
kind: 'tool-input-available',
|
|
226
|
+
id,
|
|
227
|
+
name: state.name,
|
|
228
|
+
input: state.input,
|
|
229
|
+
toolKind: 'read',
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return state;
|
|
233
|
+
}
|
|
234
|
+
setInput(id, input, name) {
|
|
235
|
+
const state = this.tool(id, name);
|
|
236
|
+
if (input === null || typeof input !== 'object')
|
|
237
|
+
return;
|
|
238
|
+
Object.assign(state.input, input);
|
|
239
|
+
}
|
|
240
|
+
/** Code-mode calls made inside a tool (`metadata.toolCalls`), nested under it by `parentId`. */
|
|
241
|
+
async innerCalls(parentId, raw) {
|
|
242
|
+
if (!Array.isArray(raw))
|
|
243
|
+
return;
|
|
244
|
+
const parent = this.tool(parentId);
|
|
245
|
+
for (const [index, call] of raw.entries()) {
|
|
246
|
+
const id = `${parentId}.${index}`;
|
|
247
|
+
const name = String(call?.tool ?? 'tool');
|
|
248
|
+
const input = call?.input !== null && typeof call?.input === 'object'
|
|
249
|
+
? call.input
|
|
250
|
+
: {};
|
|
251
|
+
if (!parent.innerAnnounced.has(index)) {
|
|
252
|
+
parent.innerAnnounced.add(index);
|
|
253
|
+
this.segment.calls.push({ id, name, input, kind: 'read', parentId });
|
|
254
|
+
await this.event({
|
|
255
|
+
kind: 'tool-input-available',
|
|
256
|
+
id,
|
|
257
|
+
name,
|
|
258
|
+
input,
|
|
259
|
+
toolKind: 'read',
|
|
260
|
+
parentId,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
const status = String(call?.status ?? '').toLowerCase();
|
|
264
|
+
if (parent.innerSettled.has(index) ||
|
|
265
|
+
status === 'running' ||
|
|
266
|
+
status === 'pending' ||
|
|
267
|
+
!status) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
parent.innerSettled.add(index);
|
|
271
|
+
if (FAILED_STATUSES.has(status)) {
|
|
272
|
+
this.segment.results.push({ id, name, output: { status }, error: status });
|
|
273
|
+
await this.event({ kind: 'tool-output-error', id, error: status });
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
this.segment.results.push({ id, name, output: { status } });
|
|
277
|
+
await this.event({ kind: 'tool-output', id, output: { status } });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async onEvent(e) {
|
|
282
|
+
if (this.ended)
|
|
283
|
+
return;
|
|
284
|
+
const d = e.data ?? {};
|
|
285
|
+
switch (e.type) {
|
|
286
|
+
case 'session.text.delta': {
|
|
287
|
+
const delta = typeof d.delta === 'string' ? d.delta : '';
|
|
288
|
+
if (!delta)
|
|
289
|
+
return;
|
|
290
|
+
this.endReasoning();
|
|
291
|
+
// Whitespace before anything was said is noise.
|
|
292
|
+
if (!this.sawText && !delta.trim())
|
|
293
|
+
return;
|
|
294
|
+
await this.step();
|
|
295
|
+
const text = this.separator && this.sawText ? `\n\n${delta}` : delta;
|
|
296
|
+
this.separator = false;
|
|
297
|
+
this.sawText = true;
|
|
298
|
+
this.segment.text += text;
|
|
299
|
+
await this.write({ t: 'text', v: text });
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
case 'session.text.ended':
|
|
303
|
+
// The next step's text starts a new paragraph.
|
|
304
|
+
this.separator = true;
|
|
305
|
+
return;
|
|
306
|
+
case 'session.reasoning.delta': {
|
|
307
|
+
const delta = typeof d.delta === 'string' ? d.delta : '';
|
|
308
|
+
if (!delta)
|
|
309
|
+
return;
|
|
310
|
+
this.reasoningSince ??= Date.now();
|
|
311
|
+
await this.step();
|
|
312
|
+
this.segment.reasoning += delta;
|
|
313
|
+
await this.event({ kind: 'reasoning', text: delta });
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
case 'session.tool.input.started':
|
|
317
|
+
this.endReasoning();
|
|
318
|
+
if (HIDDEN_TOOLS.has(String(d.name))) {
|
|
319
|
+
this.hidden.add(String(d.id));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
await this.step();
|
|
323
|
+
await this.announce(String(d.id), String(d.name ?? 'tool'));
|
|
324
|
+
return;
|
|
325
|
+
case 'session.tool.called':
|
|
326
|
+
if (this.hidden.has(String(d.id)))
|
|
327
|
+
return;
|
|
328
|
+
await this.step();
|
|
329
|
+
this.setInput(String(d.id), d.input, typeof d.name === 'string' ? d.name : undefined);
|
|
330
|
+
await this.makeAvailable(String(d.id));
|
|
331
|
+
return;
|
|
332
|
+
case 'session.skill.activated': {
|
|
333
|
+
const name = String(d.id ?? d.name ?? 'skill');
|
|
334
|
+
const id = `skill:${name}:${this.tools.size}`;
|
|
335
|
+
await this.step();
|
|
336
|
+
await this.announce(id, 'skill');
|
|
337
|
+
this.setInput(id, { name });
|
|
338
|
+
await this.makeAvailable(id);
|
|
339
|
+
await this.settleTool(id, true);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
case 'session.tool.progress':
|
|
343
|
+
if (this.hidden.has(String(d.id)))
|
|
344
|
+
return;
|
|
345
|
+
await this.step();
|
|
346
|
+
await this.makeAvailable(String(d.id));
|
|
347
|
+
await this.innerCalls(String(d.id), d.metadata?.toolCalls);
|
|
348
|
+
return;
|
|
349
|
+
case 'session.tool.success':
|
|
350
|
+
case 'session.tool.failed': {
|
|
351
|
+
const id = String(d.id);
|
|
352
|
+
if (this.hidden.has(id))
|
|
353
|
+
return;
|
|
354
|
+
await this.step();
|
|
355
|
+
await this.makeAvailable(id);
|
|
356
|
+
await this.innerCalls(id, d.metadata?.toolCalls);
|
|
357
|
+
await this.settleTool(id, e.type === 'session.tool.success', errorText(d.error, 'tool failed'));
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
case 'session.step.ended':
|
|
361
|
+
this.endReasoning();
|
|
362
|
+
await this.stepEnded(d);
|
|
363
|
+
return;
|
|
364
|
+
case 'session.step.failed':
|
|
365
|
+
this.stepError = errorText(d.error, 'the model call failed');
|
|
366
|
+
return;
|
|
367
|
+
case 'session.renamed':
|
|
368
|
+
if (typeof d.title === 'string' && d.title.trim()) {
|
|
369
|
+
await this.a.store.setTitle(this.a.input.threadId, d.title.trim());
|
|
370
|
+
await this.event({ kind: 'title', title: d.title.trim() });
|
|
371
|
+
}
|
|
372
|
+
return;
|
|
373
|
+
case 'permission.asked':
|
|
374
|
+
await this.onPermission(d, false);
|
|
375
|
+
return;
|
|
376
|
+
case 'form.created':
|
|
377
|
+
await this.onForm((d.form ?? d), false);
|
|
378
|
+
return;
|
|
379
|
+
case 'session.execution.succeeded':
|
|
380
|
+
await this.end({ status: 'succeeded' });
|
|
381
|
+
return;
|
|
382
|
+
case 'session.execution.failed':
|
|
383
|
+
await this.end({
|
|
384
|
+
status: 'failed',
|
|
385
|
+
error: errorText(d.error, this.stepError ?? 'the execution failed'),
|
|
386
|
+
});
|
|
387
|
+
return;
|
|
388
|
+
case 'session.execution.interrupted':
|
|
389
|
+
await this.end({ status: 'interrupted' });
|
|
390
|
+
return;
|
|
391
|
+
default:
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
async settleTool(id, ok, error = 'failed') {
|
|
396
|
+
const state = this.tool(id);
|
|
397
|
+
if (state.settled)
|
|
398
|
+
return;
|
|
399
|
+
state.settled = true;
|
|
400
|
+
if (ok) {
|
|
401
|
+
this.segment.results.push({ id, name: state.name, output: { ok: true } });
|
|
402
|
+
await this.event({ kind: 'tool-output', id, output: { ok: true } });
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
this.segment.results.push({ id, name: state.name, output: { ok: false }, error });
|
|
406
|
+
await this.event({ kind: 'tool-output-error', id, error });
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
// biome-ignore lint/suspicious/noExplicitAny: an OpenCode event payload, read defensively.
|
|
410
|
+
async stepEnded(d) {
|
|
411
|
+
const usage = {
|
|
412
|
+
inputTokens: Number(d.tokens?.input) || 0,
|
|
413
|
+
outputTokens: Number(d.tokens?.output) || 0,
|
|
414
|
+
...(Number(d.tokens?.cache?.read) ? { cacheReadTokens: Number(d.tokens.cache.read) } : {}),
|
|
415
|
+
...(Number(d.tokens?.cache?.write) ? { cacheWriteTokens: Number(d.tokens.cache.write) } : {}),
|
|
416
|
+
};
|
|
417
|
+
const costUsd = typeof d.cost === 'number' ? d.cost : undefined;
|
|
418
|
+
this.steps += 1;
|
|
419
|
+
this.usage.inputTokens += usage.inputTokens;
|
|
420
|
+
this.usage.outputTokens += usage.outputTokens;
|
|
421
|
+
if (costUsd !== undefined)
|
|
422
|
+
this.costUsd = (this.costUsd ?? 0) + costUsd;
|
|
423
|
+
await this.a.store.recordUsage({
|
|
424
|
+
threadId: this.a.input.threadId,
|
|
425
|
+
actorRef: this.a.input.actor.id,
|
|
426
|
+
runId: this.a.runId,
|
|
427
|
+
modelId: this.a.modelLabel,
|
|
428
|
+
purpose: 'chat',
|
|
429
|
+
usage,
|
|
430
|
+
...(costUsd !== undefined ? { costUsd } : {}),
|
|
431
|
+
});
|
|
432
|
+
if (!this.stepOpen)
|
|
433
|
+
return;
|
|
434
|
+
this.stepOpen = false;
|
|
435
|
+
await this.event({
|
|
436
|
+
kind: 'step-finish',
|
|
437
|
+
usage,
|
|
438
|
+
costUsd: costUsd ?? null,
|
|
439
|
+
...(this.segment.reasoningMs > 0 ? { reasoningMs: this.segment.reasoningMs } : {}),
|
|
440
|
+
model: this.a.modelLabel,
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Persist what the turn produced since the last flush as one assistant message — the message a
|
|
445
|
+
* call put to a person hangs on, or the turn's last one. Returns its id.
|
|
446
|
+
*/
|
|
447
|
+
async flush(final) {
|
|
448
|
+
this.endReasoning();
|
|
449
|
+
const s = this.segment;
|
|
450
|
+
const empty = !s.text && !s.reasoning && s.calls.length === 0 && s.ui.length === 0;
|
|
451
|
+
// A turn always leaves an answer behind, even an empty one, so the thread reads as answered.
|
|
452
|
+
if (empty && !(final && !this.wroteMessage))
|
|
453
|
+
return undefined;
|
|
454
|
+
this.segment = emptySegment();
|
|
455
|
+
const { input } = this.a;
|
|
456
|
+
const message = await this.a.store.appendMessage({
|
|
457
|
+
threadId: input.threadId,
|
|
458
|
+
role: 'assistant',
|
|
459
|
+
content: s.text,
|
|
460
|
+
runId: this.a.runId,
|
|
461
|
+
...(final
|
|
462
|
+
? {
|
|
463
|
+
usage: {
|
|
464
|
+
...this.usage,
|
|
465
|
+
...(this.costUsd !== undefined ? { costUsd: this.costUsd } : {}),
|
|
466
|
+
},
|
|
467
|
+
}
|
|
468
|
+
: {}),
|
|
469
|
+
...(typeof input.persona === 'string' ? { persona: input.persona } : {}),
|
|
470
|
+
...(s.reasoning ? { reasoning: s.reasoning, reasoningMs: s.reasoningMs } : {}),
|
|
471
|
+
...(s.calls.length > 0 ? { toolCalls: s.calls } : {}),
|
|
472
|
+
...(s.results.length > 0 ? { toolResults: s.results } : {}),
|
|
473
|
+
...(s.ui.length > 0 ? { ui: s.ui } : {}),
|
|
474
|
+
});
|
|
475
|
+
this.wroteMessage = true;
|
|
476
|
+
this.messageResults.set(message.id, [...s.results]);
|
|
477
|
+
return message.id;
|
|
478
|
+
}
|
|
479
|
+
/** A request recorded by an earlier process (a turn resumed after a restart). */
|
|
480
|
+
async alreadyRecorded(id) {
|
|
481
|
+
return ((await this.a.store.toolCallApproval?.(id)) ?? null) !== null;
|
|
482
|
+
}
|
|
483
|
+
/** The persisted assistant message carrying call `id`, so its result lands on the same message. */
|
|
484
|
+
async messageOf(id) {
|
|
485
|
+
const thread = await this.a.store.getThread(this.a.input.threadId);
|
|
486
|
+
return thread?.messages.find((m) => m.toolCalls?.some((call) => call.id === id))?.id;
|
|
487
|
+
}
|
|
488
|
+
async onPermission(request, recovering) {
|
|
489
|
+
if (this.asked.has(request.id))
|
|
490
|
+
return;
|
|
491
|
+
this.asked.add(request.id);
|
|
492
|
+
const { client, sessionId, input, store } = this.a;
|
|
493
|
+
const action = String(request.action);
|
|
494
|
+
const args = permissionArgs(request);
|
|
495
|
+
if (recovering && (await this.alreadyRecorded(request.id))) {
|
|
496
|
+
const state = await store.toolCallApproval?.(request.id);
|
|
497
|
+
const messageId = await this.messageOf(request.id);
|
|
498
|
+
this.reach({
|
|
499
|
+
kind: 'ask',
|
|
500
|
+
ask: {
|
|
501
|
+
kind: 'approval',
|
|
502
|
+
id: request.id,
|
|
503
|
+
action,
|
|
504
|
+
approver: state?.approver ?? 'requester',
|
|
505
|
+
...(state?.expiresAt ? { expiresAt: state.expiresAt } : {}),
|
|
506
|
+
...(messageId !== undefined ? { messageId } : {}),
|
|
507
|
+
},
|
|
508
|
+
...(state?.expiresAt
|
|
509
|
+
? { timeoutMs: Math.max(0, Date.parse(state.expiresAt) - Date.now()) }
|
|
510
|
+
: {}),
|
|
511
|
+
});
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
await this.step();
|
|
515
|
+
const requirement = await this.a.approvalFor(action);
|
|
516
|
+
const remembered = requirement.required
|
|
517
|
+
? ((await store.rememberedApprovals?.(input.threadId)) ?? []).includes(action)
|
|
518
|
+
: false;
|
|
519
|
+
// No one needs to decide: the policy does not require it, or it was approved "for this
|
|
520
|
+
// conversation" earlier. OpenCode asked because a rule said `ask`; the answer is yes.
|
|
521
|
+
if (!requirement.required || remembered) {
|
|
522
|
+
this.a.onGranted?.(action, request.id);
|
|
523
|
+
await client.permission.reply({
|
|
524
|
+
sessionID: sessionId,
|
|
525
|
+
requestID: request.id,
|
|
526
|
+
decision: 'once',
|
|
527
|
+
});
|
|
528
|
+
this.segment.calls.push({ id: request.id, name: action, input: args, kind: 'action' });
|
|
529
|
+
this.segment.results.push({ id: request.id, name: action, output: { approved: true } });
|
|
530
|
+
await this.event({
|
|
531
|
+
kind: 'tool-input-available',
|
|
532
|
+
id: request.id,
|
|
533
|
+
name: action,
|
|
534
|
+
input: args,
|
|
535
|
+
toolKind: 'action',
|
|
536
|
+
});
|
|
537
|
+
await this.event({
|
|
538
|
+
kind: 'approval-settled',
|
|
539
|
+
id: request.id,
|
|
540
|
+
status: 'approved',
|
|
541
|
+
approver: requirement.approver,
|
|
542
|
+
decidedVia: remembered ? 'remembered' : 'policy',
|
|
543
|
+
...(remembered ? { remember: true } : {}),
|
|
544
|
+
});
|
|
545
|
+
await this.event({ kind: 'tool-output', id: request.id, output: { approved: true } });
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const ttlMs = requirement.ttlMs !== undefined && Number.isFinite(requirement.ttlMs) && requirement.ttlMs > 0
|
|
549
|
+
? Math.floor(requirement.ttlMs)
|
|
550
|
+
: undefined;
|
|
551
|
+
const expiresAt = ttlMs !== undefined ? new Date(Date.now() + ttlMs).toISOString() : undefined;
|
|
552
|
+
this.segment.calls.push({ id: request.id, name: action, input: args, kind: 'action' });
|
|
553
|
+
const messageId = (await this.flush(false));
|
|
554
|
+
await store.recordToolCall({
|
|
555
|
+
toolCallId: request.id,
|
|
556
|
+
messageId,
|
|
557
|
+
toolName: action,
|
|
558
|
+
toolType: 'action',
|
|
559
|
+
input: args,
|
|
560
|
+
status: 'pending_approval',
|
|
561
|
+
runId: this.a.runId,
|
|
562
|
+
approver: requirement.approver,
|
|
563
|
+
...(expiresAt !== undefined ? { expiresAt } : {}),
|
|
564
|
+
});
|
|
565
|
+
await this.event({
|
|
566
|
+
kind: 'tool-input-available',
|
|
567
|
+
id: request.id,
|
|
568
|
+
name: action,
|
|
569
|
+
input: args,
|
|
570
|
+
toolKind: 'action',
|
|
571
|
+
});
|
|
572
|
+
await this.write({
|
|
573
|
+
t: 'approval',
|
|
574
|
+
runId: this.a.runId,
|
|
575
|
+
id: request.id,
|
|
576
|
+
toolName: action,
|
|
577
|
+
input: args,
|
|
578
|
+
approver: requirement.approver,
|
|
579
|
+
...(expiresAt !== undefined ? { expiresAt } : {}),
|
|
580
|
+
});
|
|
581
|
+
this.reach({
|
|
582
|
+
kind: 'ask',
|
|
583
|
+
ask: {
|
|
584
|
+
kind: 'approval',
|
|
585
|
+
id: request.id,
|
|
586
|
+
action,
|
|
587
|
+
approver: requirement.approver,
|
|
588
|
+
messageId,
|
|
589
|
+
...(expiresAt !== undefined ? { expiresAt } : {}),
|
|
590
|
+
},
|
|
591
|
+
...(ttlMs !== undefined ? { timeoutMs: ttlMs } : {}),
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
async decided(ask, reply, tell) {
|
|
595
|
+
// Answers to a form are not a yes: an approval only ever settles on a decision.
|
|
596
|
+
const decision = isHumanDecision(reply) ? reply : { approved: false };
|
|
597
|
+
const { client, sessionId, store } = this.a;
|
|
598
|
+
const { id, action } = ask;
|
|
599
|
+
const status = decision.approved ? 'approved' : decision.expired ? 'expired' : 'rejected';
|
|
600
|
+
if (decision.approved)
|
|
601
|
+
this.a.onGranted?.(action, id);
|
|
602
|
+
if (tell) {
|
|
603
|
+
await client.permission.reply({
|
|
604
|
+
sessionID: sessionId,
|
|
605
|
+
requestID: id,
|
|
606
|
+
decision: decision.approved ? 'once' : 'reject',
|
|
607
|
+
...(decision.approved
|
|
608
|
+
? {}
|
|
609
|
+
: {
|
|
610
|
+
message: decision.expired
|
|
611
|
+
? 'Nobody approved this action in time, so it was not run.'
|
|
612
|
+
: `The user denied this action${decision.reason ? `: ${decision.reason}` : ''}. Do not retry it; tell the user what you would have done.`,
|
|
613
|
+
}),
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
const result = decision.approved
|
|
617
|
+
? { id, name: action, output: { approved: true } }
|
|
618
|
+
: {
|
|
619
|
+
id,
|
|
620
|
+
name: action,
|
|
621
|
+
output: { rejected: true, ...(decision.reason ? { reason: decision.reason } : {}) },
|
|
622
|
+
error: decision.expired ? 'approval expired' : 'rejected by the user',
|
|
623
|
+
denied: true,
|
|
624
|
+
...(decision.expired ? { expired: true } : {}),
|
|
625
|
+
};
|
|
626
|
+
await store.updateToolCall({
|
|
627
|
+
toolCallId: id,
|
|
628
|
+
status: decision.approved ? 'executed' : status === 'expired' ? 'expired' : 'rejected',
|
|
629
|
+
output: result.output,
|
|
630
|
+
...(result.error !== undefined ? { error: result.error } : {}),
|
|
631
|
+
...(decision.executedByRef !== undefined ? { executedByRef: decision.executedByRef } : {}),
|
|
632
|
+
...(decision.remember === true ? { remember: true } : {}),
|
|
633
|
+
...(decision.decidedVia !== undefined ? { decidedVia: decision.decidedVia } : {}),
|
|
634
|
+
});
|
|
635
|
+
await this.addResult(ask.messageId, result);
|
|
636
|
+
await this.event({
|
|
637
|
+
kind: 'approval-settled',
|
|
638
|
+
id,
|
|
639
|
+
status,
|
|
640
|
+
approver: ask.approver,
|
|
641
|
+
...(decision.executedByRef !== undefined ? { decidedBy: decision.executedByRef } : {}),
|
|
642
|
+
...(decision.decidedVia !== undefined ? { decidedVia: decision.decidedVia } : {}),
|
|
643
|
+
...(decision.remember === true ? { remember: true } : {}),
|
|
644
|
+
...(decision.reason !== undefined ? { reason: decision.reason } : {}),
|
|
645
|
+
});
|
|
646
|
+
if (decision.approved) {
|
|
647
|
+
await this.event({ kind: 'tool-output', id, output: { approved: true } });
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
await this.event({
|
|
651
|
+
kind: 'tool-output-denied',
|
|
652
|
+
id,
|
|
653
|
+
...(decision.expired
|
|
654
|
+
? { reason: 'approval expired' }
|
|
655
|
+
: decision.reason
|
|
656
|
+
? { reason: decision.reason }
|
|
657
|
+
: {}),
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
async onForm(form, recovering) {
|
|
662
|
+
if (this.asked.has(form.id))
|
|
663
|
+
return;
|
|
664
|
+
this.asked.add(form.id);
|
|
665
|
+
const request = toElicitation(form.id, form);
|
|
666
|
+
if (recovering && (await this.alreadyRecorded(form.id))) {
|
|
667
|
+
const messageId = await this.messageOf(form.id);
|
|
668
|
+
this.reach({
|
|
669
|
+
kind: 'ask',
|
|
670
|
+
ask: {
|
|
671
|
+
kind: 'form',
|
|
672
|
+
id: form.id,
|
|
673
|
+
form,
|
|
674
|
+
request,
|
|
675
|
+
...(messageId !== undefined ? { messageId } : {}),
|
|
676
|
+
},
|
|
677
|
+
});
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
const input = {
|
|
681
|
+
...(request.preamble !== undefined ? { preamble: request.preamble } : {}),
|
|
682
|
+
questions: request.questions,
|
|
683
|
+
};
|
|
684
|
+
await this.step();
|
|
685
|
+
this.segment.calls.push({ id: form.id, name: ASK_TOOL_NAME, input, kind: 'ask' });
|
|
686
|
+
const messageId = (await this.flush(false));
|
|
687
|
+
// A question waiting on a person is what `action` + `pending_approval` already mean — the loop
|
|
688
|
+
// records its own questions the same way, so the answer route finds the run.
|
|
689
|
+
await this.a.store.recordToolCall({
|
|
690
|
+
toolCallId: form.id,
|
|
691
|
+
messageId,
|
|
692
|
+
toolName: ASK_TOOL_NAME,
|
|
693
|
+
toolType: 'action',
|
|
694
|
+
input,
|
|
695
|
+
status: 'pending_approval',
|
|
696
|
+
runId: this.a.runId,
|
|
697
|
+
});
|
|
698
|
+
await this.write({ t: 'elicitation', runId: this.a.runId, id: form.id, request });
|
|
699
|
+
this.reach({ kind: 'ask', ask: { kind: 'form', id: form.id, form, request, messageId } });
|
|
700
|
+
}
|
|
701
|
+
async answered(ask, reply, tell) {
|
|
702
|
+
const { client, sessionId } = this.a;
|
|
703
|
+
const { form, request } = ask;
|
|
704
|
+
// An Approve pressed on a form confirms its defaults; a Reject skips it.
|
|
705
|
+
const answer = normalizeElicitationReply(reply);
|
|
706
|
+
if (!tell) {
|
|
707
|
+
// The form died with the server; the new session is told the answer.
|
|
708
|
+
}
|
|
709
|
+
else if (answer.skipped === true) {
|
|
710
|
+
await client.session.form.cancel({ sessionID: sessionId, formID: form.id });
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
await client.session.form.reply({
|
|
714
|
+
sessionID: sessionId,
|
|
715
|
+
formID: form.id,
|
|
716
|
+
answer: toFormAnswer(form, answer.answers),
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
const result = settleElicitation({ request, reply: answer });
|
|
720
|
+
await this.a.store.updateToolCall({
|
|
721
|
+
toolCallId: form.id,
|
|
722
|
+
status: result.skipped ? 'rejected' : 'executed',
|
|
723
|
+
output: result,
|
|
724
|
+
...(result.skipped ? { error: 'skipped by the user' } : {}),
|
|
725
|
+
...(answer.answeredByRef !== undefined ? { executedByRef: answer.answeredByRef } : {}),
|
|
726
|
+
...(answer.answeredVia !== undefined ? { decidedVia: answer.answeredVia } : {}),
|
|
727
|
+
});
|
|
728
|
+
await this.addResult(ask.messageId, { id: form.id, name: ASK_TOOL_NAME, output: result });
|
|
729
|
+
await this.event({ kind: 'tool-output', id: form.id, output: result });
|
|
730
|
+
}
|
|
731
|
+
async addResult(messageId, result) {
|
|
732
|
+
if (messageId === undefined)
|
|
733
|
+
return;
|
|
734
|
+
// A message persisted by an earlier process: its results are in the store, not in this map.
|
|
735
|
+
let known = this.messageResults.get(messageId);
|
|
736
|
+
if (known === undefined) {
|
|
737
|
+
const thread = await this.a.store.getThread(this.a.input.threadId);
|
|
738
|
+
known = [...(thread?.messages.find((m) => m.id === messageId)?.toolResults ?? [])];
|
|
739
|
+
}
|
|
740
|
+
const results = [...known.filter((r) => r.id !== result.id), result];
|
|
741
|
+
this.messageResults.set(messageId, results);
|
|
742
|
+
await this.a.store.setMessageToolResults(messageId, results);
|
|
743
|
+
}
|
|
744
|
+
async end(outcome) {
|
|
745
|
+
if (this.ended)
|
|
746
|
+
return;
|
|
747
|
+
this.ended = true;
|
|
748
|
+
if (outcome.status !== 'failed' ||
|
|
749
|
+
this.segment.text ||
|
|
750
|
+
this.segment.calls.length > 0 ||
|
|
751
|
+
this.segment.ui.length > 0) {
|
|
752
|
+
await this.flush(true);
|
|
753
|
+
}
|
|
754
|
+
if (this.stepOpen) {
|
|
755
|
+
this.stepOpen = false;
|
|
756
|
+
await this.event({ kind: 'step-finish' });
|
|
757
|
+
}
|
|
758
|
+
this.reach({ kind: 'finished', outcome });
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
//# sourceMappingURL=turn.js.map
|