eve 0.83.2 → 0.84.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 +61 -0
- package/README.md +1 -5
- package/dist/src/_virtual/_rolldown/runtime.js +1 -1
- package/dist/src/acp/adapter.d.ts +8 -5
- package/dist/src/acp/adapter.js +1 -1
- package/dist/src/ai/decide.d.ts +3 -7
- package/dist/src/ai/decide.js +1 -1
- package/dist/src/ai/decision-adapter.d.ts +7 -0
- package/dist/src/ai/decision-adapter.js +1 -0
- package/dist/src/ai/decision-types.d.ts +86 -0
- package/dist/src/approval/definition.d.ts +5 -12
- package/dist/src/approval/evaluation.d.ts +48 -0
- package/dist/src/approval/evaluation.js +1 -0
- package/dist/src/approval/status.d.ts +14 -0
- package/dist/src/approval/status.js +1 -0
- package/dist/src/channel/adapter-context.d.ts +1 -3
- package/dist/src/channel/adapter-context.js +1 -1
- package/dist/src/channel/adapter.d.ts +34 -26
- package/dist/src/channel/adapter.js +1 -1
- package/dist/src/channel/audience.d.ts +0 -3
- package/dist/src/channel/audience.js +1 -1
- package/dist/src/channel/auth/definitions.d.ts +532 -0
- package/dist/src/channel/auth/definitions.js +1 -0
- package/dist/src/channel/auth/jwt-ecdsa.js +1 -1
- package/dist/src/channel/auth/jwt-hmac.js +1 -1
- package/dist/src/channel/auth/oidc.js +1 -1
- package/dist/src/channel/channel-address.d.ts +12 -10
- package/dist/src/channel/channel-address.js +1 -1
- package/dist/src/channel/channel-operations.d.ts +21 -22
- package/dist/src/channel/channel-operations.js +1 -1
- package/dist/src/channel/compiled-channel.d.ts +4 -4
- package/dist/src/channel/conversation-context.js +1 -1
- package/dist/src/channel/cors.d.ts +2 -2
- package/dist/src/channel/cors.js +1 -1
- package/dist/src/channel/cross-channel-receive.d.ts +3 -3
- package/dist/src/channel/delivery-idempotency.d.ts +6 -0
- package/dist/src/channel/delivery-idempotency.js +1 -1
- package/dist/src/channel/delivery-metadata.d.ts +2 -2
- package/dist/src/channel/delivery.d.ts +8 -0
- package/dist/src/channel/delivery.js +1 -0
- package/dist/src/channel/interaction-prompts.d.ts +54 -0
- package/dist/src/channel/interaction-prompts.js +1 -0
- package/dist/src/channel/invoke-tool.d.ts +11 -18
- package/dist/src/channel/pending-authorization.d.ts +3 -14
- package/dist/src/channel/pending-authorization.js +1 -1
- package/dist/src/channel/prompt-queue.d.ts +11 -19
- package/dist/src/channel/prompt-queue.js +1 -1
- package/dist/src/channel/resolve-text.d.ts +11 -18
- package/dist/src/channel/resolve-text.js +2 -2
- package/dist/src/channel/resolved-prompt.d.ts +7 -5
- package/dist/src/channel/resolved-prompt.js +1 -1
- package/dist/src/channel/routes.d.ts +4 -4
- package/dist/src/channel/schedule.d.ts +2 -2
- package/dist/src/channel/schedule.js +1 -1
- package/dist/src/channel/send-input.d.ts +3 -3
- package/dist/src/channel/send-input.js +1 -1
- package/dist/src/channel/session-callback.js +1 -1
- package/dist/src/channel/session-not-active-error.d.ts +8 -12
- package/dist/src/channel/session-not-active-error.js +1 -1
- package/dist/src/channel/session.d.ts +33 -59
- package/dist/src/channel/session.js +1 -1
- package/dist/src/channel/sign-in.d.ts +61 -0
- package/dist/src/channel/sign-in.js +3 -0
- package/dist/src/channel/surface.d.ts +44 -0
- package/dist/src/channel/surface.js +1 -0
- package/dist/src/channel/task-card.d.ts +24 -114
- package/dist/src/channel/task-card.js +1 -1
- package/dist/src/channel/types.d.ts +116 -110
- package/dist/src/channel/types.js +1 -1
- package/dist/src/chunks/use-eve-agent-BbbguIdB.js +5030 -0
- package/dist/src/chunks/use-eve-agent-DWjyzplb.js +5077 -0
- package/dist/src/cli/commands/logs-events.d.ts +2 -0
- package/dist/src/cli/commands/logs-events.js +2 -2
- package/dist/src/cli/dev/command.js +1 -1
- package/dist/src/cli/dev/remote-print.d.ts +8 -0
- package/dist/src/cli/dev/remote-print.js +1 -0
- package/dist/src/cli/dev/tui/conversation-view.d.ts +24 -19
- package/dist/src/cli/dev/tui/conversation-view.js +1 -1
- package/dist/src/cli/dev/tui/diagnostic-presentation.d.ts +0 -10
- package/dist/src/cli/dev/tui/diagnostic-presentation.js +2 -3
- package/dist/src/cli/dev/tui/errors.d.ts +9 -65
- package/dist/src/cli/dev/tui/errors.js +1 -1
- package/dist/src/cli/dev/tui/prompt-command-handler.js +1 -1
- package/dist/src/cli/dev/tui/runner.js +3 -3
- package/dist/src/cli/dev/tui/task-records.d.ts +3 -3
- package/dist/src/cli/dev/tui/task-records.js +1 -1
- package/dist/src/cli/dev/tui/terminal-renderer.js +10 -10
- package/dist/src/cli/dev/tui/terminal-tool-part.d.ts +2 -2
- package/dist/src/cli/dev/tui/terminal-tool-part.js +1 -1
- package/dist/src/cli/dev/tui/test/fake-eve-server.d.ts +3 -3
- package/dist/src/cli/dev/tui/test/fake-eve-server.js +1 -1
- package/dist/src/cli/dev/tui/tool-presentation.js +1 -1
- package/dist/src/cli/dev/tui/transcript-parts.d.ts +16 -16
- package/dist/src/cli/dev/tui/transcript-parts.js +3 -3
- package/dist/src/cli/dev/tui/transcript.d.ts +0 -4
- package/dist/src/cli/dev/tui/transcript.js +1 -1
- package/dist/src/cli/dev/tui/tui.js +1 -1
- package/dist/src/cli/run.d.ts +0 -2
- package/dist/src/cli/run.js +1 -1
- package/dist/src/cli/telemetry/index.js +1 -1
- package/dist/src/client/agent-base-url.d.ts +4 -0
- package/dist/src/client/agent-base-url.js +1 -0
- package/dist/src/client/agent-info-schema.d.ts +1 -923
- package/dist/src/client/agent-info-schema.js +1 -1
- package/dist/src/client/agent-info-types.d.ts +281 -0
- package/dist/src/client/agent-session.d.ts +19 -22
- package/dist/src/client/agent-session.js +1 -1
- package/dist/src/client/agent-stream-follower.d.ts +11 -20
- package/dist/src/client/agent-stream-follower.js +1 -1
- package/dist/src/client/client-error.d.ts +2 -1
- package/dist/src/client/client-error.js +1 -1
- package/dist/src/client/client.d.ts +1 -1
- package/dist/src/client/client.js +1 -1
- package/dist/src/client/conversation-client.d.ts +37 -28
- package/dist/src/client/conversation-client.js +1 -1
- package/dist/src/client/conversation-state.d.ts +70 -73
- package/dist/src/client/conversation-state.js +1 -1
- package/dist/src/client/conversation.d.ts +51 -0
- package/dist/src/client/conversation.js +1 -0
- package/dist/src/client/delivery-events.d.ts +3 -0
- package/dist/src/client/delivery-events.js +1 -0
- package/dist/src/client/delivery.d.ts +36 -0
- package/dist/src/client/delivery.js +1 -0
- package/dist/src/client/file-parts.d.ts +9 -4
- package/dist/src/client/file-parts.js +1 -1
- package/dist/src/client/health-schema.d.ts +1 -1
- package/dist/src/client/health-types.d.ts +6 -0
- package/dist/src/client/index.d.ts +17 -23
- package/dist/src/client/index.js +1 -1
- package/dist/src/client/message-types.d.ts +92 -0
- package/dist/src/client/message-types.js +1 -0
- package/dist/src/client/messages.d.ts +30 -0
- package/dist/src/client/messages.js +1 -0
- package/dist/src/client/ndjson.d.ts +6 -11
- package/dist/src/client/ndjson.js +3 -3
- package/dist/src/client/open-stream.d.ts +47 -20
- package/dist/src/client/open-stream.js +1 -1
- package/dist/src/client/optimistic-message-submissions.d.ts +10 -19
- package/dist/src/client/optimistic-message-submissions.js +1 -1
- package/dist/src/client/session-controls.d.ts +23 -26
- package/dist/src/client/session-controls.js +1 -1
- package/dist/src/client/session-event-stream.d.ts +5 -16
- package/dist/src/client/session-event-stream.js +1 -1
- package/dist/src/client/session-store-helpers.d.ts +8 -0
- package/dist/src/client/session-store-helpers.js +2 -0
- package/dist/src/client/session-store-state.d.ts +80 -0
- package/dist/src/client/session-store-state.js +1 -0
- package/dist/src/client/session-store.d.ts +48 -0
- package/dist/src/client/session-store.js +1 -0
- package/dist/src/client/session-utils.d.ts +45 -41
- package/dist/src/client/session-utils.js +2 -1
- package/dist/src/client/session.d.ts +32 -23
- package/dist/src/client/session.js +1 -1
- package/dist/src/client/sessions.d.ts +2 -2
- package/dist/src/client/stream-version.d.ts +3 -1
- package/dist/src/client/stream-version.js +1 -1
- package/dist/src/client/transcript.d.ts +43 -0
- package/dist/src/client/transcript.js +2 -0
- package/dist/src/client/types.d.ts +21 -82
- package/dist/src/client/url.d.ts +3 -3
- package/dist/src/compiled/.vendor-stamp.json +1 -1
- package/dist/src/compiled/@ai-sdk/anthropic/index.d.ts +34 -34
- package/dist/src/compiled/@ai-sdk/google/index.d.ts +15 -15
- package/dist/src/compiled/@ai-sdk/openai/index.d.ts +38 -38
- package/dist/src/compiled/@chat-adapter/slack/fetch-QqNM_Ef3.d.ts +4 -0
- package/dist/src/compiled/@chat-adapter/twilio/types-BaIqtt65.d.ts +100 -0
- package/dist/src/compiled/@linqapp/chat-sdk-adapter/adapter.d.ts +129 -0
- package/dist/src/compiled/@linqapp/chat-sdk-adapter/message-parser.d.ts +14 -0
- package/dist/src/compiled/@linqapp/chat-sdk-adapter/text-decorations.d.ts +28 -0
- package/dist/src/compiled/@workflow/core/runtime/step-executor.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/serialization/types.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/serialization.d.ts +2 -2
- package/dist/src/compiled/@workflow/core/telemetry/semantic-conventions.d.ts +2 -2
- package/dist/src/compiled/semver/index.d.ts +2 -0
- package/dist/src/compiler/development-extensions.js +1 -1
- package/dist/src/compiler/extension-compatibility.d.ts +19 -290
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/manifest.d.ts +1 -9
- package/dist/src/compiler/manifest.js +1 -1
- package/dist/src/compiler/normalize-agent-config.js +1 -1
- package/dist/src/compiler/normalize-connection.js +1 -1
- package/dist/src/compiler/normalize-hook.js +1 -1
- package/dist/src/compiler/normalize-instructions.js +1 -1
- package/dist/src/compiler/normalize-manifest.js +1 -1
- package/dist/src/compiler/normalize-memory.js +1 -1
- package/dist/src/compiler/normalize-schedule.js +1 -1
- package/dist/src/compiler/normalize-skill.js +1 -1
- package/dist/src/compiler/normalize-subagent.d.ts +0 -5
- package/dist/src/compiler/normalize-subagent.js +1 -1
- package/dist/src/compiler/normalize-tool.js +1 -1
- package/dist/src/compiler/remote-agent-node.d.ts +1 -6
- package/dist/src/compiler/source-graph.d.ts +0 -1
- package/dist/src/compiler/source-graph.js +1 -1
- package/dist/src/computer-use/extension/lib/computer-use-sandbox.js +1 -1
- package/dist/src/computer-use/extension/lib/sandbox.d.ts +1 -1
- package/dist/src/computer-use/extension/lib/sandbox.js +1 -1
- package/dist/src/computer-use/extension/tools/computer_use.js +1 -1
- package/dist/src/connections/errors.d.ts +3 -3
- package/dist/src/context/accessors.d.ts +0 -13
- package/dist/src/context/accessors.js +1 -1
- package/dist/src/context/container.d.ts +8 -11
- package/dist/src/context/container.js +1 -1
- package/dist/src/context/key-names.d.ts +1 -0
- package/dist/src/context/key-names.js +1 -1
- package/dist/src/context/keys.d.ts +20 -104
- package/dist/src/context/keys.js +1 -1
- package/dist/src/context/memory-tools.d.ts +4 -2
- package/dist/src/context/memory-tools.js +1 -1
- package/dist/src/context/providers/connection.js +1 -1
- package/dist/src/context/providers/session.js +1 -1
- package/dist/src/context/schedule-collection-tools.d.ts +2 -2
- package/dist/src/context/schedule-collection-tools.js +1 -1
- package/dist/src/context/session-context.d.ts +4 -2
- package/dist/src/discover/extensions.d.ts +2 -3
- package/dist/src/discover/extensions.js +1 -1
- package/dist/src/discover/manifest.js +1 -1
- package/dist/src/discover/skills.js +1 -1
- package/dist/src/dynamic/definition.d.ts +98 -108
- package/dist/src/dynamic/definition.js +1 -1
- package/dist/src/evals/assertions/collector.js +1 -1
- package/dist/src/evals/assertions/run.d.ts +12 -11
- package/dist/src/evals/assertions/run.js +2 -2
- package/dist/src/evals/assertions/scoped.js +1 -1
- package/dist/src/evals/cli/eval-client.js +1 -1
- package/dist/src/evals/cli/eval.js +2 -2
- package/dist/src/evals/context.js +1 -1
- package/dist/src/evals/expect/index.d.ts +0 -1
- package/dist/src/evals/index.d.ts +2 -5
- package/dist/src/evals/judge.js +1 -1
- package/dist/src/evals/match.d.ts +20 -17
- package/dist/src/evals/match.js +1 -1
- package/dist/src/evals/mock-model.d.ts +5 -1
- package/dist/src/evals/mock-model.js +1 -1
- package/dist/src/evals/output.d.ts +3 -0
- package/dist/src/evals/output.js +1 -0
- package/dist/src/evals/reported-tool-name.js +1 -1
- package/dist/src/evals/reporters/index.d.ts +4 -4
- package/dist/src/evals/reporters/index.js +1 -1
- package/dist/src/evals/runner/artifacts.js +1 -1
- package/dist/src/evals/runner/derive-run-facts.d.ts +8 -40
- package/dist/src/evals/runner/derive-run-facts.js +1 -1
- package/dist/src/evals/runner/execute-eval.js +1 -1
- package/dist/src/evals/runner/execute-task.d.ts +3 -1
- package/dist/src/evals/runner/execute-task.js +1 -1
- package/dist/src/evals/runner/reporters/braintrust.d.ts +1 -1
- package/dist/src/evals/runner/reporters/braintrust.js +2 -2
- package/dist/src/evals/runner/reporters/console.d.ts +1 -1
- package/dist/src/evals/runner/reporters/console.js +1 -1
- package/dist/src/evals/runner/reporters/datadog.d.ts +1 -1
- package/dist/src/evals/runner/reporters/datadog.js +2 -2
- package/dist/src/evals/runner/reporters/junit.d.ts +1 -1
- package/dist/src/evals/runner/reporters/junit.js +2 -2
- package/dist/src/evals/runner/reporters/types.d.ts +2 -2
- package/dist/src/evals/runner/run-evals.d.ts +1 -1
- package/dist/src/evals/session-cleanup.d.ts +1 -1
- package/dist/src/evals/session-cleanup.js +1 -1
- package/dist/src/evals/session-content.d.ts +2 -2
- package/dist/src/evals/session-content.js +2 -1
- package/dist/src/evals/session-manager.d.ts +3 -6
- package/dist/src/evals/session-manager.js +1 -1
- package/dist/src/evals/session.d.ts +33 -24
- package/dist/src/evals/session.js +2 -2
- package/dist/src/evals/target.js +1 -1
- package/dist/src/evals/types.d.ts +115 -94
- package/dist/src/eve-channel/create-request.d.ts +3 -5
- package/dist/src/eve-channel/descendant-stream.d.ts +9 -0
- package/dist/src/eve-channel/descendant-stream.js +1 -0
- package/dist/src/eve-channel/index.d.ts +2 -2
- package/dist/src/eve-channel/index.js +1 -1
- package/dist/src/eve-channel/request.d.ts +7 -6
- package/dist/src/eve-channel/request.js +1 -3
- package/dist/src/eve-channel/stream-headers.d.ts +1 -1
- package/dist/src/eve-channel/stream-headers.js +1 -1
- package/dist/src/eve-channel/support.d.ts +25 -13
- package/dist/src/eve-channel/support.js +2 -2
- package/dist/src/eve-channel/types.d.ts +7 -30
- package/dist/src/execution/agent-sessions/message.d.ts +4 -0
- package/dist/src/execution/agent-sessions/message.js +1 -0
- package/dist/src/execution/agent-sessions/metadata.js +1 -1
- package/dist/src/execution/agent-sessions/remote-credentials.d.ts +19 -0
- package/dist/src/execution/agent-sessions/remote-credentials.js +1 -0
- package/dist/src/execution/agent-sessions/remote.d.ts +35 -13
- package/dist/src/execution/agent-sessions/remote.js +1 -1
- package/dist/src/execution/agent-sessions/requests.d.ts +6 -6
- package/dist/src/execution/agent-sessions/requests.js +1 -1
- package/dist/src/execution/agent-sessions/session.js +1 -1
- package/dist/src/execution/agent-sessions/steps.d.ts +26 -4
- package/dist/src/execution/agent-sessions/steps.js +1 -1
- package/dist/src/execution/agent-sessions/target.d.ts +2 -1
- package/dist/src/execution/agent-sessions/target.js +1 -1
- package/dist/src/execution/agent-sessions/usage.d.ts +0 -8
- package/dist/src/execution/agent-sessions/usage.js +1 -1
- package/dist/src/execution/cancelled-model-call-batch.d.ts +4 -2
- package/dist/src/execution/cancelled-model-call-batch.js +1 -1
- package/dist/src/execution/cancelled-turn-message.d.ts +2 -2
- package/dist/src/execution/cancelled-turn-message.js +1 -1
- package/dist/src/execution/catalog/connection-auth.js +1 -1
- package/dist/src/execution/catalog/connection-entry.js +1 -1
- package/dist/src/execution/catalog/rank.js +1 -1
- package/dist/src/execution/catalog/search.js +1 -1
- package/dist/src/execution/catalog/skills.js +1 -1
- package/dist/src/execution/catalog/step-catalog.js +1 -1
- package/dist/src/execution/child-binding.d.ts +19 -0
- package/dist/src/execution/child-binding.js +1 -0
- package/dist/src/execution/close-session-stream-step.d.ts +9 -0
- package/dist/src/execution/close-session-stream-step.js +1 -0
- package/dist/src/execution/coordination-dispatch-shared.d.ts +13 -3
- package/dist/src/execution/coordination-dispatch-shared.js +1 -1
- package/dist/src/execution/coordination-dispatch-step.d.ts +9 -13
- package/dist/src/execution/coordination-dispatch-step.js +1 -1
- package/dist/src/execution/deliver-payloads.js +1 -1
- package/dist/src/execution/durable-session-store.d.ts +2 -5
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/dynamic-workflow/workflow.js +1 -1
- package/dist/src/execution/failure-summary.d.ts +11 -0
- package/dist/src/execution/failure-summary.js +1 -0
- package/dist/src/execution/forward-session-input.d.ts +2 -2
- package/dist/src/execution/forward-session-input.js +1 -1
- package/dist/src/execution/invoke-tool.js +1 -1
- package/dist/src/execution/legacy-session/prepare-step.js +1 -1
- package/dist/src/execution/legacy-session/snapshot.d.ts +4 -1
- package/dist/src/execution/legacy-session/snapshot.js +1 -1
- package/dist/src/execution/model-call-batching.d.ts +3 -3
- package/dist/src/execution/model-call-batching.js +1 -1
- package/dist/src/execution/ndjson-stream.d.ts +1 -1
- package/dist/src/execution/node-step.d.ts +2 -8
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/proxied-deliver-step.d.ts +8 -3
- package/dist/src/execution/proxied-deliver-step.js +1 -1
- package/dist/src/execution/public-destination.d.ts +34 -0
- package/dist/src/execution/public-destination.js +1 -0
- package/dist/src/execution/publish-session-events.d.ts +98 -36
- package/dist/src/execution/publish-session-events.js +1 -1
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/sandbox/abort-bound-session.js +1 -1
- package/dist/src/execution/sandbox/bash.js +1 -1
- package/dist/src/execution/sandbox/bindings/docker-connection.js +1 -1
- package/dist/src/execution/sandbox/bindings/docker.js +1 -1
- package/dist/src/execution/sandbox/bindings/eve-image.d.ts +0 -2
- package/dist/src/execution/sandbox/bindings/eve-image.js +1 -1
- package/dist/src/execution/sandbox/bindings/just-bash-runtime.js +1 -1
- package/dist/src/execution/sandbox/bindings/vercel.js +1 -1
- package/dist/src/execution/sandbox/ensure.js +1 -1
- package/dist/src/{extensions/code/extension/lib → execution/sandbox}/grep-search.d.ts +3 -2
- package/dist/src/execution/sandbox/grep-search.js +6 -0
- package/dist/src/execution/sandbox/read-file.d.ts +1 -1
- package/dist/src/execution/sandbox/session.js +1 -1
- package/dist/src/execution/sandbox/workspace-root.d.ts +31 -0
- package/dist/src/execution/sandbox/workspace-root.js +1 -0
- package/dist/src/execution/session/active-turn.d.ts +12 -6
- package/dist/src/execution/session/active-turn.js +1 -1
- package/dist/src/execution/session/admission.d.ts +7 -2
- package/dist/src/execution/session/admission.js +1 -1
- package/dist/src/execution/session/answer-caller.d.ts +4 -4
- package/dist/src/execution/session/answer-caller.js +1 -1
- package/dist/src/execution/session/checkpoint-migrations.d.ts +4 -6
- package/dist/src/execution/session/checkpoint-migrations.js +1 -1
- package/dist/src/execution/session/control-delivery.d.ts +4 -0
- package/dist/src/execution/session/control-delivery.js +1 -0
- package/dist/src/execution/session/delivery-facts.d.ts +27 -0
- package/dist/src/execution/session/delivery-facts.js +1 -0
- package/dist/src/execution/session/end-sandbox-step.js +1 -1
- package/dist/src/execution/session/entry.js +1 -1
- package/dist/src/execution/session/finalization.d.ts +4 -0
- package/dist/src/execution/session/finalization.js +1 -1
- package/dist/src/execution/session/handoff-state.js +1 -1
- package/dist/src/execution/session/handoff-steps.d.ts +1 -8
- package/dist/src/execution/session/handoff-steps.js +1 -1
- package/dist/src/execution/session/handoff.d.ts +5 -3
- package/dist/src/execution/session/handoff.js +1 -1
- package/dist/src/execution/session/input-queue.d.ts +8 -2
- package/dist/src/execution/session/input-queue.js +1 -1
- package/dist/src/execution/session/interrupted-step.d.ts +64 -0
- package/dist/src/execution/session/interrupted-step.js +3 -0
- package/dist/src/execution/session/next-input.d.ts +7 -1
- package/dist/src/execution/session/next-input.js +1 -1
- package/dist/src/execution/session/pending-turn-state.d.ts +32 -12
- package/dist/src/execution/session/pending-turn-state.js +1 -1
- package/dist/src/execution/session/prewarm-step.d.ts +1 -1
- package/dist/src/execution/session/prewarm-step.js +1 -1
- package/dist/src/execution/session/program.js +1 -1
- package/dist/src/execution/session/settle-control-delivery-step.d.ts +8 -0
- package/dist/src/execution/session/settle-control-delivery-step.js +1 -0
- package/dist/src/execution/session/settle-duplicate-delivery-step.d.ts +8 -0
- package/dist/src/execution/session/settle-duplicate-delivery-step.js +1 -0
- package/dist/src/execution/session/state-delta.d.ts +2 -12
- package/dist/src/execution/session/state-delta.js +1 -1
- package/dist/src/execution/session/step-decision-check.d.ts +9 -0
- package/dist/src/execution/session/step-decision-check.js +1 -0
- package/dist/src/execution/session/step-state-delta.d.ts +16 -0
- package/dist/src/execution/session/step-state-delta.js +1 -0
- package/dist/src/execution/session/task-tool-tracing-step.d.ts +0 -3
- package/dist/src/execution/session/task-tool-tracing-step.js +1 -1
- package/dist/src/execution/session/turn-event-handler.d.ts +6 -16
- package/dist/src/execution/session/turn-event-handler.js +1 -1
- package/dist/src/execution/session/turn-step-result.d.ts +7 -2
- package/dist/src/execution/session/turn-step-result.js +1 -1
- package/dist/src/execution/session/turn-step-types.d.ts +35 -33
- package/dist/src/execution/session/turn-step.js +1 -1
- package/dist/src/execution/session/turn.d.ts +19 -32
- package/dist/src/execution/session/turn.js +1 -1
- package/dist/src/execution/session-callback-request.d.ts +7 -1
- package/dist/src/execution/session-callback-request.js +1 -1
- package/dist/src/execution/session-event-stream.d.ts +37 -16
- package/dist/src/execution/session-event-stream.js +1 -1
- package/dist/src/execution/session-inbox/end-stranded-session.d.ts +7 -1
- package/dist/src/execution/session-inbox/end-stranded-session.js +1 -1
- package/dist/src/execution/session-inbox/inbox.js +1 -1
- package/dist/src/execution/session-inbox/owner.d.ts +5 -2
- package/dist/src/execution/session-inbox/owner.js +1 -1
- package/dist/src/execution/session-inbox/pre-v27.d.ts +5 -0
- package/dist/src/execution/session-inbox/pre-v27.js +1 -0
- package/dist/src/execution/session-inbox/protocol.js +1 -1
- package/dist/src/execution/session-inbox/resume.js +1 -1
- package/dist/src/execution/session-inbox/stranded-replay-guard.js +1 -1
- package/dist/src/execution/session-workflow-tool-run.js +1 -1
- package/dist/src/execution/session.d.ts +3 -14
- package/dist/src/execution/session.js +2 -2
- package/dist/src/execution/settle-cancelled-turn-step.d.ts +3 -0
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/stop-runs.d.ts +35 -0
- package/dist/src/execution/stop-runs.js +1 -0
- package/dist/src/execution/tasks/model-step.d.ts +5 -9
- package/dist/src/execution/tasks/model-step.js +1 -1
- package/dist/src/execution/tasks/render.d.ts +5 -2
- package/dist/src/execution/tasks/render.js +1 -1
- package/dist/src/execution/tasks/session.d.ts +6 -3
- package/dist/src/execution/tasks/session.js +1 -1
- package/dist/src/execution/tasks/start.d.ts +9 -6
- package/dist/src/execution/tasks/start.js +1 -1
- package/dist/src/execution/tasks/steps.d.ts +11 -6
- package/dist/src/execution/tasks/steps.js +1 -1
- package/dist/src/execution/tasks/table.d.ts +18 -5
- package/dist/src/execution/tasks/table.js +1 -1
- package/dist/src/execution/tasks/task-id-input.js +1 -1
- package/dist/src/execution/terminal-session-completion-step.d.ts +11 -1
- package/dist/src/execution/terminal-session-completion-step.js +1 -1
- package/dist/src/execution/terminal-session-failure-step.d.ts +6 -1
- package/dist/src/execution/terminal-session-failure-step.js +1 -1
- package/dist/src/execution/terminate-child-sessions-step.d.ts +5 -1
- package/dist/src/execution/terminate-child-sessions-step.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/execution/tools/workflow/answer.d.ts +4 -5
- package/dist/src/execution/tools/workflow/answer.js +1 -1
- package/dist/src/execution/tools/workflow/apply-run-messages-step.d.ts +1 -1
- package/dist/src/execution/tools/workflow/apply-run-messages-step.js +1 -1
- package/dist/src/execution/tools/workflow/ask.d.ts +3 -3
- package/dist/src/execution/tools/workflow/body.js +1 -1
- package/dist/src/execution/tools/workflow/harness-definition.js +1 -1
- package/dist/src/execution/tools/workflow/messages.d.ts +25 -33
- package/dist/src/execution/tools/workflow/messages.js +1 -1
- package/dist/src/execution/tools/workflow/owner-inbox.d.ts +9 -5
- package/dist/src/execution/tools/workflow/owner-inbox.js +1 -1
- package/dist/src/execution/tools/workflow/owner.d.ts +3 -3
- package/dist/src/execution/tools/workflow/owner.js +1 -1
- package/dist/src/execution/tools/workflow/serve.js +1 -1
- package/dist/src/execution/tools/workflow/step.js +1 -1
- package/dist/src/execution/tools/workflow/withdraw-step.d.ts +2 -2
- package/dist/src/execution/tools/workflow/withdraw-step.js +1 -1
- package/dist/src/execution/v26-history.d.ts +28 -0
- package/dist/src/execution/v26-history.fixtures.d.ts +4 -0
- package/dist/src/execution/v26-history.fixtures.js +2 -0
- package/dist/src/execution/v26-history.js +1 -0
- package/dist/src/execution/web-fetch/html.js +3 -4
- package/dist/src/execution/web-fetch/request.js +1 -1
- package/dist/src/execution/workflow-errors.d.ts +5 -0
- package/dist/src/execution/workflow-errors.js +1 -1
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/extensions/code/extension/extension.d.ts +1 -11
- package/dist/src/extensions/code/extension/extension.js +1 -1
- package/dist/src/extensions/code/extension/lib/prwatch-github.d.ts +5 -1
- package/dist/src/extensions/code/extension/lib/prwatch-github.js +1 -1
- package/dist/src/extensions/code/extension/lib/repository-root.js +1 -1
- package/dist/src/extensions/code/extension/lib/sandbox.d.ts +0 -4
- package/dist/src/extensions/code/extension/lib/sandbox.js +2 -2
- package/dist/src/extensions/code/extension/lib/tooling.d.ts +1 -1
- package/dist/src/extensions/code/extension/lib/tooling.js +1 -1
- package/dist/src/extensions/code/extension/lib/workspace-root.d.ts +1 -31
- package/dist/src/extensions/code/extension/lib/workspace-root.js +1 -1
- package/dist/src/extensions/code/extension/subagents/worker/agent.d.ts +1 -1
- package/dist/src/extensions/code/extension/subagents/worker/agent.js +1 -1
- package/dist/src/extensions/code/extension/tools/apply_patch.js +2 -2
- package/dist/src/extensions/code/extension/tools/grep.d.ts +1 -28
- package/dist/src/extensions/code/extension/tools/grep.js +1 -1
- package/dist/src/extensions/code/sandbox.d.ts +1 -0
- package/dist/src/extensions/code/sandbox.js +1 -0
- package/dist/src/extensions/code/tools.d.ts +1 -5
- package/dist/src/extensions/code/tools.js +1 -1
- package/dist/src/extensions/git/extension/extension.d.ts +3 -3
- package/dist/src/extensions/git/extension/instructions/github.d.ts +1 -1
- package/dist/src/extensions/git/extension/instructions/github.js +1 -1
- package/dist/src/extensions/git/extension/lib/gh-tool.d.ts +2 -11
- package/dist/src/extensions/git/extension/lib/gh-tool.js +1 -1
- package/dist/src/extensions/git/extension/lib/github-shell.d.ts +13 -3
- package/dist/src/extensions/git/extension/lib/sandbox.d.ts +0 -4
- package/dist/src/extensions/git/extension/lib/sandbox.js +1 -1
- package/dist/src/extensions/git/extension/skills/pr.d.ts +1 -4
- package/dist/src/extensions/git/extension/skills/pr.js +1 -1
- package/dist/src/extensions/git/extension/tools/gh.d.ts +1 -26
- package/dist/src/extensions/git/extension/tools/gh.js +1 -1
- package/dist/src/framework/sources/modules/schedule-collection-wrapper.js +1 -1
- package/dist/src/harness/action-presentation.d.ts +3 -5
- package/dist/src/harness/action-presentation.js +1 -1
- package/dist/src/harness/action-result-helpers.d.ts +2 -8
- package/dist/src/harness/action-result-helpers.js +1 -1
- package/dist/src/harness/approval-outcome.d.ts +32 -0
- package/dist/src/harness/approval-outcome.js +1 -0
- package/dist/src/harness/attachment-staging.js +1 -1
- package/dist/src/harness/authorization.d.ts +2 -3
- package/dist/src/harness/authorization.js +1 -1
- package/dist/src/harness/call-executor.d.ts +118 -0
- package/dist/src/harness/call-executor.js +1 -0
- package/dist/src/harness/call-facts.d.ts +31 -0
- package/dist/src/harness/call-facts.js +1 -0
- package/dist/src/harness/call-outcome.d.ts +6 -0
- package/dist/src/harness/call-outcome.js +1 -0
- package/dist/src/harness/compaction/engine.d.ts +11 -0
- package/dist/src/harness/compaction/engine.js +2 -2
- package/dist/src/harness/compaction/over-limit-error.d.ts +7 -0
- package/dist/src/harness/compaction/over-limit-error.js +1 -0
- package/dist/src/harness/compaction/prompt.js +1 -1
- package/dist/src/harness/compaction/step.d.ts +34 -5
- package/dist/src/harness/compaction/step.js +1 -1
- package/dist/src/harness/coordination.js +1 -1
- package/dist/src/harness/current-messages.d.ts +10 -0
- package/dist/src/harness/current-messages.js +1 -1
- package/dist/src/harness/emission.d.ts +9 -15
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/execute-call.d.ts +6 -23
- package/dist/src/harness/execute-call.js +1 -1
- package/dist/src/harness/execute-tool.d.ts +7 -3
- package/dist/src/harness/facts.d.ts +82 -0
- package/dist/src/harness/facts.js +1 -0
- package/dist/src/harness/finish-reason.d.ts +6 -1
- package/dist/src/harness/generation-steering.d.ts +4 -2
- package/dist/src/harness/generation-steering.js +1 -1
- package/dist/src/harness/hitl/approval-prompt.d.ts +3 -3
- package/dist/src/harness/hitl/approval-prompt.js +3 -3
- package/dist/src/harness/hitl/approvals.d.ts +66 -78
- package/dist/src/harness/hitl/approvals.js +2 -1
- package/dist/src/harness/hitl/approved-calls.d.ts +14 -36
- package/dist/src/harness/hitl/approved-calls.js +1 -1
- package/dist/src/harness/hitl/budget-request.d.ts +8 -46
- package/dist/src/harness/hitl/budget-request.js +1 -1
- package/dist/src/harness/hitl/budget.d.ts +9 -8
- package/dist/src/harness/hitl/budget.js +1 -1
- package/dist/src/harness/hitl/delivery.d.ts +16 -17
- package/dist/src/harness/hitl/delivery.js +1 -1
- package/dist/src/harness/hitl/index.d.ts +14 -19
- package/dist/src/harness/hitl/index.js +1 -1
- package/dist/src/harness/hitl/intake.d.ts +32 -43
- package/dist/src/harness/hitl/intake.js +1 -1
- package/dist/src/harness/hitl/relays.d.ts +7 -51
- package/dist/src/harness/hitl/relays.js +1 -1
- package/dist/src/harness/hitl/requests.d.ts +11 -53
- package/dist/src/harness/hitl/requests.js +1 -1
- package/dist/src/harness/hitl/responders.d.ts +50 -0
- package/dist/src/harness/hitl/responders.js +1 -0
- package/dist/src/harness/hitl/sign-ins.d.ts +7 -3
- package/dist/src/harness/hitl/sign-ins.js +1 -1
- package/dist/src/harness/hitl/stale-responses.d.ts +11 -11
- package/dist/src/harness/hitl/stale-responses.js +3 -3
- package/dist/src/harness/inline-tool-authorization.d.ts +8 -9
- package/dist/src/harness/inline-tool-authorization.js +1 -1
- package/dist/src/harness/interaction-facts.d.ts +36 -0
- package/dist/src/harness/interaction-facts.js +1 -0
- package/dist/src/harness/interaction-relay.d.ts +10 -0
- package/dist/src/harness/interaction-relay.js +1 -0
- package/dist/src/harness/interrupted-attempt.d.ts +19 -0
- package/dist/src/harness/interrupted-attempt.js +2 -0
- package/dist/src/harness/messages.d.ts +28 -15
- package/dist/src/harness/messages.js +1 -1
- package/dist/src/harness/model-call/call.d.ts +31 -13
- package/dist/src/harness/model-call/call.js +1 -1
- package/dist/src/harness/model-call/errors.js +1 -1
- package/dist/src/harness/model-call/failure.d.ts +10 -48
- package/dist/src/harness/model-call/failure.js +1 -1
- package/dist/src/harness/model-call/model.js +1 -1
- package/dist/src/harness/model-call/recovery.d.ts +4 -32
- package/dist/src/harness/model-call/recovery.js +1 -1
- package/dist/src/harness/model-call/request.d.ts +0 -1
- package/dist/src/harness/model-call/request.js +1 -1
- package/dist/src/harness/model-call/response.d.ts +22 -12
- package/dist/src/harness/model-call/response.js +1 -1
- package/dist/src/harness/model-call/retry.d.ts +23 -6
- package/dist/src/harness/model-call/retry.js +1 -1
- package/dist/src/harness/model-call/run.d.ts +4 -12
- package/dist/src/harness/model-call/run.js +1 -1
- package/dist/src/harness/model-call/tools.d.ts +0 -19
- package/dist/src/harness/model-call/tools.js +1 -1
- package/dist/src/harness/model-call/unique-call-ids.d.ts +13 -0
- package/dist/src/harness/model-call/unique-call-ids.js +1 -0
- package/dist/src/harness/model-call/usage.d.ts +7 -5
- package/dist/src/harness/model-call/usage.js +1 -1
- package/dist/src/harness/ordered-stream-emitter.d.ts +1 -0
- package/dist/src/harness/ordered-stream-emitter.js +1 -1
- package/dist/src/harness/provider-tool-history.js +1 -1
- package/dist/src/harness/publication.d.ts +4 -0
- package/dist/src/harness/publication.js +1 -0
- package/dist/src/harness/request-envelope.d.ts +0 -3
- package/dist/src/harness/request-envelope.js +1 -1
- package/dist/src/harness/running-work.d.ts +10 -0
- package/dist/src/harness/running-work.js +1 -0
- package/dist/src/harness/session-machine/cascade.d.ts +17 -0
- package/dist/src/harness/session-machine/cascade.js +1 -0
- package/dist/src/harness/session-machine/commit.d.ts +16 -16
- package/dist/src/harness/session-machine/commit.js +1 -1
- package/dist/src/harness/session-machine/current.d.ts +25 -9
- package/dist/src/harness/session-machine/current.js +1 -1
- package/dist/src/harness/session-machine/state.d.ts +43 -16
- package/dist/src/harness/session-machine/state.js +1 -1
- package/dist/src/harness/session-machine/suspended-steps.d.ts +22 -0
- package/dist/src/harness/session-machine/suspended-steps.js +1 -0
- package/dist/src/harness/session-machine/transitions.d.ts +144 -120
- package/dist/src/harness/session-machine/transitions.js +1 -1
- package/dist/src/harness/session-machine/view.d.ts +12 -8
- package/dist/src/harness/session-machine/view.js +1 -1
- package/dist/src/harness/session-machine/waiting.d.ts +16 -0
- package/dist/src/harness/session-machine/waiting.js +1 -0
- package/dist/src/harness/session-usage.d.ts +22 -0
- package/dist/src/harness/session-usage.js +1 -0
- package/dist/src/harness/step/after-model.d.ts +1 -4
- package/dist/src/harness/step/after-model.js +1 -1
- package/dist/src/harness/step/context.d.ts +21 -21
- package/dist/src/harness/step/context.js +1 -1
- package/dist/src/harness/step/intake.d.ts +7 -8
- package/dist/src/harness/step/intake.js +1 -1
- package/dist/src/harness/step/park.d.ts +19 -0
- package/dist/src/harness/step/park.js +1 -0
- package/dist/src/harness/step/prompt.d.ts +4 -5
- package/dist/src/harness/step/prompt.js +1 -1
- package/dist/src/harness/step-hooks.d.ts +24 -24
- package/dist/src/harness/step-hooks.js +1 -1
- package/dist/src/harness/stream-actions.d.ts +3 -9
- package/dist/src/harness/stream-actions.js +1 -1
- package/dist/src/harness/token-estimate.js +1 -1
- package/dist/src/harness/tool-history-repair.js +1 -1
- package/dist/src/harness/tool-loop.js +1 -1
- package/dist/src/harness/tools.d.ts +22 -38
- package/dist/src/harness/tools.js +1 -1
- package/dist/src/harness/types.d.ts +69 -67
- package/dist/src/harness/user-parts.d.ts +4 -0
- package/dist/src/harness/user-parts.js +1 -0
- package/dist/src/harness/workflow-tool-runs.d.ts +0 -1
- package/dist/src/harness/workflow-tool-runs.js +1 -1
- package/dist/src/instrumentation/ai-sdk-hook-bridge.d.ts +2 -2
- package/dist/src/instrumentation/ai-sdk-hook-bridge.js +1 -1
- package/dist/src/instrumentation/channel-delivery.d.ts +4 -23
- package/dist/src/instrumentation/channel-delivery.js +1 -1
- package/dist/src/instrumentation/content.d.ts +1 -7
- package/dist/src/instrumentation/content.js +1 -1
- package/dist/src/instrumentation/dispatch.js +1 -1
- package/dist/src/instrumentation/lifecycle.d.ts +135 -198
- package/dist/src/instrumentation/lifecycle.js +1 -1
- package/dist/src/instrumentation/memory.d.ts +4 -2
- package/dist/src/instrumentation/memory.js +1 -1
- package/dist/src/instrumentation/native-events.d.ts +17 -10
- package/dist/src/instrumentation/native-events.js +1 -1
- package/dist/src/instrumentation/prepare-trace-context.d.ts +3 -3
- package/dist/src/instrumentation/provider.d.ts +20 -28
- package/dist/src/instrumentation/providers.js +1 -1
- package/dist/src/instrumentation/runtime-context.d.ts +1 -0
- package/dist/src/instrumentation/runtime-context.js +1 -1
- package/dist/src/instrumentation/runtime.d.ts +9 -30
- package/dist/src/instrumentation/runtime.js +1 -1
- package/dist/src/instrumentation/scope.d.ts +6 -0
- package/dist/src/instrumentation/scope.js +1 -0
- package/dist/src/instrumentation/session-context.d.ts +1 -1
- package/dist/src/instrumentation/session-context.js +1 -1
- package/dist/src/instrumentation/session-init.js +1 -1
- package/dist/src/instrumentation/setup-context.d.ts +2 -2
- package/dist/src/instrumentation/setup-context.js +1 -1
- package/dist/src/instrumentation/state.d.ts +0 -21
- package/dist/src/instrumentation/state.js +1 -1
- package/dist/src/internal/application/dev-environment.d.ts +8 -2
- package/dist/src/internal/application/dev-environment.js +1 -1
- package/dist/src/internal/application/optional-package-install.js +1 -1
- package/dist/src/internal/application/stamped-package-version.js +1 -1
- package/dist/src/internal/authored-asset-import-plugin.d.ts +8 -7
- package/dist/src/internal/authored-asset-import-plugin.js +1 -1
- package/dist/src/internal/authored-definition/approval.d.ts +2 -4
- package/dist/src/internal/authored-definition/approval.js +1 -1
- package/dist/src/internal/authored-definition/connection.js +1 -1
- package/dist/src/internal/authored-definition/core.d.ts +1 -1
- package/dist/src/internal/authored-definition/core.js +1 -1
- package/dist/src/internal/authored-definition/memory.js +1 -1
- package/dist/src/internal/authored-definition/schema-backed.d.ts +0 -3
- package/dist/src/internal/authored-definition/schema-backed.js +1 -1
- package/dist/src/internal/authored-module-loader.d.ts +0 -1
- package/dist/src/internal/authored-module-loader.js +1 -1
- package/dist/src/internal/authored-package-boundary.js +1 -1
- package/dist/src/internal/git.d.ts +2 -0
- package/dist/src/internal/git.js +1 -0
- package/dist/src/internal/grep.d.ts +1 -0
- package/dist/src/internal/grep.js +1 -0
- package/dist/src/internal/helpers/markdown.js +1 -1
- package/dist/src/internal/invocation/agent-invocation.d.ts +16 -19
- package/dist/src/internal/invocation/metadata.d.ts +0 -2
- package/dist/src/internal/invocation/metadata.js +1 -1
- package/dist/src/internal/invocation/workflow-execution.d.ts +4 -4
- package/dist/src/internal/invocation/workflow-execution.js +1 -1
- package/dist/src/internal/legacy-events.d.ts +5 -0
- package/dist/src/internal/legacy-events.js +1 -0
- package/dist/src/internal/logging.d.ts +0 -12
- package/dist/src/internal/logging.js +1 -1
- package/dist/src/internal/mcp/protected-resource.js +1 -1
- package/dist/src/internal/mcp/published-tools.js +1 -1
- package/dist/src/internal/model-auth/api-key.js +1 -1
- package/dist/src/internal/model-auth/development-broker-client.js +1 -1
- package/dist/src/internal/model-auth/development-broker-server.js +1 -1
- package/dist/src/internal/model-auth/transport.js +1 -1
- package/dist/src/internal/nitro/dev-client-address.d.ts +12 -0
- package/dist/src/internal/nitro/dev-client-address.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-generation-metadata.js +1 -1
- package/dist/src/internal/nitro/host/build-extension.js +2 -2
- package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
- package/dist/src/internal/nitro/host/dev-host-fingerprint.js +1 -1
- package/dist/src/internal/nitro/host/dev-server-state.js +1 -1
- package/dist/src/internal/nitro/host/drained-nitro-dev-server.js +1 -1
- package/dist/src/internal/nitro/host/start-development-server.js +1 -1
- package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.js +1 -1
- package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
- package/dist/src/internal/nitro/routes/channel-request-instrumentation.d.ts +6 -3
- package/dist/src/internal/nitro/routes/channel-request-instrumentation.js +1 -1
- package/dist/src/internal/nitro/routes/channel-route-context.d.ts +8 -1
- package/dist/src/internal/nitro/routes/info.js +1 -1
- package/dist/src/internal/nitro/routes/schedule-task.js +1 -1
- package/dist/src/internal/scaffold.d.ts +5 -0
- package/dist/src/internal/scaffold.js +1 -0
- package/dist/src/internal/workflow/cancel-expired-development-run.js +1 -1
- package/dist/src/internal/workflow/development-world-client.js +1 -1
- package/dist/src/internal/workflow/development-world-server.js +1 -1
- package/dist/src/internal/workflow/local-world-data-directory.js +1 -1
- package/dist/src/internal/workspace.d.ts +1 -0
- package/dist/src/internal/workspace.js +1 -0
- package/dist/src/models/auto.d.ts +27 -14
- package/dist/src/models/auto.js +2 -2
- package/dist/src/protocol/delivery.d.ts +11 -0
- package/dist/src/protocol/delivery.js +1 -0
- package/dist/src/protocol/descendant-observation.d.ts +12 -0
- package/dist/src/protocol/descendant-observation.js +1 -0
- package/dist/src/protocol/interaction-json.d.ts +66 -0
- package/dist/src/protocol/interaction-json.js +1 -0
- package/dist/src/protocol/interaction-options.d.ts +4 -0
- package/dist/src/protocol/interaction-options.js +1 -0
- package/dist/src/protocol/remote-agent-protocol.d.ts +28 -1
- package/dist/src/protocol/remote-agent-protocol.js +1 -1
- package/dist/src/protocol/routes.d.ts +3 -2
- package/dist/src/protocol/routes.js +1 -1
- package/dist/src/protocol/session-event.d.ts +22 -0
- package/dist/src/protocol/session-event.js +1 -0
- package/dist/src/protocol/session-events/authoring.d.ts +2 -0
- package/dist/src/protocol/session-events/authoring.js +1 -0
- package/dist/src/protocol/session-events/catalog.d.ts +50 -0
- package/dist/src/protocol/session-events/catalog.js +1 -0
- package/dist/src/protocol/session-events/checker.d.ts +23 -0
- package/dist/src/protocol/session-events/checker.js +1 -0
- package/dist/src/protocol/session-events/common.d.ts +105 -0
- package/dist/src/protocol/session-events/common.js +1 -0
- package/dist/src/protocol/session-events/envelope.d.ts +174 -0
- package/dist/src/protocol/session-events/envelope.js +1 -0
- package/dist/src/protocol/session-events/facts.d.ts +24 -0
- package/dist/src/protocol/session-events/facts.js +1 -0
- package/dist/src/protocol/session-events/families/call.d.ts +142 -0
- package/dist/src/protocol/session-events/families/call.js +1 -0
- package/dist/src/protocol/session-events/families/child.d.ts +51 -0
- package/dist/src/protocol/session-events/families/child.js +1 -0
- package/dist/src/protocol/session-events/families/content.d.ts +56 -0
- package/dist/src/protocol/session-events/families/content.js +1 -0
- package/dist/src/protocol/session-events/families/context.d.ts +55 -0
- package/dist/src/protocol/session-events/families/context.js +1 -0
- package/dist/src/protocol/session-events/families/delivery.d.ts +86 -0
- package/dist/src/protocol/session-events/families/delivery.js +1 -0
- package/dist/src/protocol/session-events/families/interaction.d.ts +163 -0
- package/dist/src/protocol/session-events/families/interaction.js +1 -0
- package/dist/src/protocol/session-events/families/model.d.ts +88 -0
- package/dist/src/protocol/session-events/families/model.js +1 -0
- package/dist/src/protocol/session-events/families/response.d.ts +66 -0
- package/dist/src/protocol/session-events/families/response.js +1 -0
- package/dist/src/protocol/session-events/families/session.d.ts +73 -0
- package/dist/src/protocol/session-events/families/session.js +1 -0
- package/dist/src/protocol/session-events/families/task.d.ts +46 -0
- package/dist/src/protocol/session-events/families/task.js +1 -0
- package/dist/src/protocol/session-events/families/turn.d.ts +68 -0
- package/dist/src/protocol/session-events/families/turn.js +1 -0
- package/dist/src/protocol/session-events/families/usage.d.ts +30 -0
- package/dist/src/protocol/session-events/families/usage.js +1 -0
- package/dist/src/protocol/session-events/guards.d.ts +11 -0
- package/dist/src/protocol/session-events/guards.js +1 -0
- package/dist/src/protocol/session-events/index.d.ts +16 -0
- package/dist/src/protocol/session-events/index.js +1 -0
- package/dist/src/protocol/session-events/json.d.ts +20 -0
- package/dist/src/protocol/session-events/json.js +1 -0
- package/dist/src/protocol/session-events/schemas.d.ts +320 -0
- package/dist/src/protocol/session-events/schemas.js +1 -0
- package/dist/src/protocol/session-http.d.ts +7 -0
- package/dist/src/protocol/session-http.js +1 -0
- package/dist/src/protocol/session-lines.d.ts +19 -0
- package/dist/src/protocol/session-lines.js +1 -0
- package/dist/src/protocol/session-projection/fold.d.ts +75 -0
- package/dist/src/protocol/session-projection/fold.js +1 -0
- package/dist/src/protocol/session-projection/index.d.ts +4 -0
- package/dist/src/protocol/session-projection/index.js +1 -0
- package/dist/src/protocol/session-projection/observations.d.ts +150 -0
- package/dist/src/protocol/session-projection/observations.js +1 -0
- package/dist/src/protocol/session-projection/public-view.d.ts +74 -0
- package/dist/src/protocol/session-projection/public-view.js +1 -0
- package/dist/src/protocol/session-projection/reader.d.ts +62 -0
- package/dist/src/protocol/session-projection/reader.js +1 -0
- package/dist/src/protocol/session-projection/request-status.d.ts +7 -0
- package/dist/src/protocol/session-projection/request-status.js +1 -0
- package/dist/src/protocol/session-projection/selectors.d.ts +169 -0
- package/dist/src/protocol/session-projection/selectors.js +2 -0
- package/dist/src/protocol/session-projection/session-view.d.ts +18 -0
- package/dist/src/protocol/session-projection/session-view.js +1 -0
- package/dist/src/protocol/session-projection/tables.d.ts +237 -0
- package/dist/src/protocol/session-projection/tables.js +1 -0
- package/dist/src/protocol/session-projection/tree.d.ts +72 -0
- package/dist/src/protocol/session-projection/tree.js +1 -0
- package/dist/src/protocol/session-projection.d.ts +38 -157
- package/dist/src/protocol/session-projection.js +1 -1
- package/dist/src/protocol/task-tools.d.ts +8 -6
- package/dist/src/protocol/task-tools.js +1 -1
- package/dist/src/protocol/v26-interactions.d.ts +11 -0
- package/dist/src/protocol/v26-interactions.js +1 -0
- package/dist/src/protocol/v26-lines.d.ts +5 -0
- package/dist/src/protocol/v26-lines.js +1 -0
- package/dist/src/public/agents/auth.d.ts +2 -2
- package/dist/src/public/agents/auth.js +1 -1
- package/dist/src/public/ai/index.d.ts +1 -0
- package/dist/src/public/channels/auth.d.ts +2 -518
- package/dist/src/public/channels/auth.js +1 -1
- package/dist/src/public/channels/chat-sdk/authorization.d.ts +5 -2
- package/dist/src/public/channels/chat-sdk/authorization.js +1 -3
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.d.ts +16 -11
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.js +1 -3
- package/dist/src/public/channels/chat-sdk/index.d.ts +1 -1
- package/dist/src/public/channels/chat-sdk/index.js +1 -1
- package/dist/src/public/channels/chat-sdk/input-actions.d.ts +4 -4
- package/dist/src/public/channels/chat-sdk/input-actions.js +3 -3
- package/dist/src/public/channels/chat-sdk/{messageToUserContent.d.ts → message-content.d.ts} +3 -3
- package/dist/src/public/channels/chat-sdk/message-content.js +1 -0
- package/dist/src/public/channels/discord/api.d.ts +8 -11
- package/dist/src/public/channels/discord/api.js +1 -1
- package/dist/src/public/channels/discord/attachments.d.ts +2 -2
- package/dist/src/public/channels/discord/authorization.d.ts +3 -13
- package/dist/src/public/channels/discord/authorization.js +2 -2
- package/dist/src/public/channels/discord/credentials.d.ts +11 -0
- package/dist/src/public/channels/discord/credentials.js +1 -0
- package/dist/src/public/channels/discord/defaults.d.ts +7 -1
- package/dist/src/public/channels/discord/defaults.js +1 -3
- package/dist/src/public/channels/discord/discordChannel.d.ts +36 -48
- package/dist/src/public/channels/discord/discordChannel.js +1 -1
- package/dist/src/public/channels/discord/hitl.d.ts +5 -4
- package/dist/src/public/channels/discord/hitl.js +1 -1
- package/dist/src/public/channels/discord/index.d.ts +4 -12
- package/dist/src/public/channels/discord/index.js +1 -1
- package/dist/src/public/channels/discord/messages.js +1 -1
- package/dist/src/public/channels/github/defaults.js +2 -4
- package/dist/src/public/channels/github/githubChannel.d.ts +23 -36
- package/dist/src/public/channels/github/githubChannel.js +1 -1
- package/dist/src/public/channels/github/index.d.ts +3 -2
- package/dist/src/public/channels/github/index.js +1 -1
- package/dist/src/public/channels/github/state.d.ts +2 -0
- package/dist/src/public/channels/imessage-tapbacks.d.ts +1 -1
- package/dist/src/public/channels/index.d.ts +16 -37
- package/dist/src/public/channels/index.js +1 -1
- package/dist/src/public/channels/linear/defaults.js +2 -4
- package/dist/src/public/channels/linear/hitl.d.ts +3 -3
- package/dist/src/public/channels/linear/hitl.js +2 -2
- package/dist/src/public/channels/linear/inbound-uploads.d.ts +3 -3
- package/dist/src/public/channels/linear/inbound-uploads.js +1 -1
- package/dist/src/public/channels/linear/inbound.d.ts +5 -3
- package/dist/src/public/channels/linear/inbound.js +1 -1
- package/dist/src/public/channels/linear/index.d.ts +4 -6
- package/dist/src/public/channels/linear/index.js +1 -1
- package/dist/src/public/channels/linear/linearChannel.d.ts +19 -30
- package/dist/src/public/channels/linear/linearChannel.js +1 -1
- package/dist/src/public/channels/linq/inboundContent.d.ts +2 -2
- package/dist/src/public/channels/linq/inboundContent.js +1 -1
- package/dist/src/public/channels/linq/index.d.ts +1 -1
- package/dist/src/public/channels/linq/linqChannel.d.ts +1 -2
- package/dist/src/public/channels/mcp.d.ts +2 -2
- package/dist/src/public/channels/mcp.js +1 -1
- package/dist/src/public/channels/photon/inboundContent.d.ts +2 -2
- package/dist/src/public/channels/photon/inboundContent.js +1 -1
- package/dist/src/public/channels/photon/index.d.ts +1 -1
- package/dist/src/public/channels/photon/photonIMessageChannel.d.ts +1 -2
- package/dist/src/public/channels/reply.d.ts +22 -0
- package/dist/src/public/channels/reply.js +3 -0
- package/dist/src/public/channels/slack/action-status.js +1 -1
- package/dist/src/public/channels/slack/{input-response.d.ts → answers.d.ts} +5 -5
- package/dist/src/public/channels/slack/answers.js +1 -0
- package/dist/src/public/channels/slack/api.d.ts +5 -2
- package/dist/src/public/channels/slack/api.js +1 -1
- package/dist/src/public/channels/slack/approval-cards.d.ts +15 -5
- package/dist/src/public/channels/slack/approval-cards.js +2 -2
- package/dist/src/public/channels/slack/attachments.d.ts +6 -6
- package/dist/src/public/channels/slack/attachments.js +1 -1
- package/dist/src/public/channels/slack/blocks.d.ts +1 -1
- package/dist/src/public/channels/slack/blocks.js +1 -1
- package/dist/src/public/channels/slack/cards.d.ts +576 -0
- package/dist/src/public/channels/slack/cards.js +1 -0
- package/dist/src/public/channels/slack/connections.d.ts +4 -22
- package/dist/src/public/channels/slack/connections.js +1 -1
- package/dist/src/public/channels/slack/defaults.d.ts +13 -2
- package/dist/src/public/channels/slack/defaults.js +5 -5
- package/dist/src/public/channels/slack/hitl.d.ts +20 -19
- package/dist/src/public/channels/slack/hitl.js +3 -3
- package/dist/src/public/channels/slack/index.d.ts +7 -16
- package/dist/src/public/channels/slack/index.js +1 -1
- package/dist/src/public/channels/slack/interaction-cards.js +1 -1
- package/dist/src/public/channels/slack/interactions.d.ts +2 -2
- package/dist/src/public/channels/slack/interactions.js +1 -1
- package/dist/src/public/channels/slack/limits.js +1 -1
- package/dist/src/public/channels/slack/private-approval-delivery.d.ts +3 -3
- package/dist/src/public/channels/slack/private-approval-delivery.js +1 -1
- package/dist/src/public/channels/slack/renderers.d.ts +21 -27
- package/dist/src/public/channels/slack/renderers.js +1 -1
- package/dist/src/public/channels/slack/reply-delivery.d.ts +5 -11
- package/dist/src/public/channels/slack/reply-delivery.js +1 -1
- package/dist/src/public/channels/slack/session-operations.d.ts +4 -4
- package/dist/src/public/channels/slack/sign-in-cancel.js +1 -1
- package/dist/src/public/channels/slack/slackChannel.d.ts +32 -43
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/channels/slack/task-card.d.ts +9 -9
- package/dist/src/public/channels/slack/task-card.js +1 -1
- package/dist/src/public/channels/teams/api.d.ts +3 -7
- package/dist/src/public/channels/teams/attachments.d.ts +4 -4
- package/dist/src/public/channels/teams/authorization.d.ts +5 -9
- package/dist/src/public/channels/teams/authorization.js +1 -1
- package/dist/src/public/channels/teams/credentials.d.ts +13 -0
- package/dist/src/public/channels/teams/credentials.js +1 -0
- package/dist/src/public/channels/teams/defaults.d.ts +2 -6
- package/dist/src/public/channels/teams/defaults.js +1 -3
- package/dist/src/public/channels/teams/hitl.d.ts +8 -7
- package/dist/src/public/channels/teams/hitl.js +1 -1
- package/dist/src/public/channels/teams/index.d.ts +6 -8
- package/dist/src/public/channels/teams/index.js +1 -1
- package/dist/src/public/channels/teams/teamsChannel.d.ts +25 -44
- package/dist/src/public/channels/teams/teamsChannel.js +1 -1
- package/dist/src/public/channels/telegram/api.d.ts +3 -4
- package/dist/src/public/channels/telegram/attachments.d.ts +5 -5
- package/dist/src/public/channels/telegram/authorization-callback.js +1 -1
- package/dist/src/public/channels/telegram/authorization.d.ts +4 -8
- package/dist/src/public/channels/telegram/authorization.js +2 -2
- package/dist/src/public/channels/telegram/credentials.d.ts +9 -0
- package/dist/src/public/channels/telegram/credentials.js +1 -0
- package/dist/src/public/channels/telegram/defaults.js +1 -3
- package/dist/src/public/channels/telegram/hitl.d.ts +22 -20
- package/dist/src/public/channels/telegram/hitl.js +2 -2
- package/dist/src/public/channels/telegram/index.d.ts +5 -7
- package/dist/src/public/channels/telegram/index.js +1 -1
- package/dist/src/public/channels/telegram/telegramChannel.d.ts +23 -36
- package/dist/src/public/channels/telegram/telegramChannel.js +1 -1
- package/dist/src/public/channels/text.d.ts +4 -0
- package/dist/src/public/channels/text.js +1 -0
- package/dist/src/public/channels/twilio/api.d.ts +8 -8
- package/dist/src/public/channels/twilio/api.js +1 -1
- package/dist/src/public/channels/twilio/credentials.d.ts +7 -0
- package/dist/src/public/channels/twilio/credentials.js +1 -0
- package/dist/src/public/channels/twilio/defaults.d.ts +0 -1
- package/dist/src/public/channels/twilio/defaults.js +1 -5
- package/dist/src/public/channels/twilio/inbound.d.ts +2 -2
- package/dist/src/public/channels/twilio/index.d.ts +4 -4
- package/dist/src/public/channels/twilio/index.js +1 -1
- package/dist/src/public/channels/twilio/twilioChannel.d.ts +24 -37
- package/dist/src/public/channels/twilio/twilioChannel.js +1 -1
- package/dist/src/public/channels/twilio/verify.d.ts +6 -4
- package/dist/src/public/channels/undelivered-reply.d.ts +30 -0
- package/dist/src/public/channels/undelivered-reply.js +1 -0
- package/dist/src/public/channels/upload-policy.d.ts +7 -7
- package/dist/src/public/connections/index.d.ts +3 -5
- package/dist/src/public/context/index.d.ts +3 -2
- package/dist/src/public/definitions/agent.d.ts +18 -18
- package/dist/src/public/definitions/agent.js +1 -1
- package/dist/src/public/definitions/approval.d.ts +1 -1
- package/dist/src/public/definitions/channel.d.ts +57 -60
- package/dist/src/public/definitions/channel.js +1 -1
- package/dist/src/public/definitions/connections/dynamic.d.ts +3 -15
- package/dist/src/public/definitions/connections/dynamic.js +1 -1
- package/dist/src/public/definitions/connections/events.d.ts +9 -9
- package/dist/src/public/definitions/connections/mcp.d.ts +5 -3
- package/dist/src/public/definitions/connections/openapi.d.ts +1 -1
- package/dist/src/public/definitions/extension.d.ts +2 -4
- package/dist/src/public/definitions/extension.js +1 -1
- package/dist/src/public/definitions/hook.d.ts +63 -85
- package/dist/src/public/definitions/hook.js +1 -1
- package/dist/src/public/definitions/instructions.d.ts +3 -10
- package/dist/src/public/definitions/instructions.js +1 -1
- package/dist/src/public/definitions/model.d.ts +21 -0
- package/dist/src/public/definitions/model.js +1 -0
- package/dist/src/public/definitions/removed-event-keys.d.ts +2 -0
- package/dist/src/public/definitions/removed-event-keys.js +1 -0
- package/dist/src/public/definitions/sandbox.d.ts +1 -1
- package/dist/src/public/definitions/schedule.d.ts +4 -4
- package/dist/src/public/definitions/skill.d.ts +5 -0
- package/dist/src/public/definitions/skill.js +1 -1
- package/dist/src/public/events/index.d.ts +27 -0
- package/dist/src/public/events/index.js +1 -0
- package/dist/src/public/experimental/connections/index.d.ts +1 -0
- package/dist/src/public/experimental/connections/index.js +1 -0
- package/dist/src/public/experimental/schedules/client.js +1 -1
- package/dist/src/public/hooks/index.d.ts +4 -3
- package/dist/src/public/index.d.ts +3 -2
- package/dist/src/public/instructions/index.d.ts +2 -2
- package/dist/src/public/instrumentation/index.d.ts +9 -28
- package/dist/src/public/instrumentation/index.js +1 -1
- package/dist/src/public/instrumentation/otel.d.ts +1 -1
- package/dist/src/public/instrumentation/otel.js +1 -1
- package/dist/src/public/instrumentation/provider.d.ts +1 -1
- package/dist/src/public/instrumentation/provider.js +1 -1
- package/dist/src/public/local-dev.d.ts +3 -1
- package/dist/src/public/memory/file/backend.d.ts +1 -1
- package/dist/src/public/memory/file/backends/in-memory.js +1 -1
- package/dist/src/public/memory/file/backends/vercel-blob.js +1 -1
- package/dist/src/public/memory/file/provider.js +1 -1
- package/dist/src/public/memory/index.d.ts +14 -20
- package/dist/src/public/models/index.d.ts +3 -0
- package/dist/src/public/models/index.js +1 -1
- package/dist/src/public/models/openai/index.d.ts +0 -2
- package/dist/src/public/models/openai/index.js +1 -1
- package/dist/src/public/next/index.d.ts +5 -36
- package/dist/src/public/next/index.js +1 -1
- package/dist/src/public/nuxt/index.d.ts +1 -1
- package/dist/src/public/nuxt/module.d.ts +5 -2
- package/dist/src/public/sandbox/index.d.ts +1 -1
- package/dist/src/public/sandbox/vercel-sandbox.d.ts +52 -12
- package/dist/src/public/sandbox/vercel.d.ts +1 -1
- package/dist/src/public/schedules/subscription.d.ts +5 -8
- package/dist/src/public/server/index.d.ts +2 -14
- package/dist/src/public/server/index.js +1 -1
- package/dist/src/public/sessions/index.d.ts +6 -0
- package/dist/src/public/sessions/index.js +1 -0
- package/dist/src/public/skills/index.d.ts +2 -2
- package/dist/src/public/skills/index.js +1 -1
- package/dist/src/public/sveltekit/routing.d.ts +0 -4
- package/dist/src/public/sveltekit/routing.js +1 -1
- package/dist/src/public/tools/approval/index.d.ts +1 -1
- package/dist/src/public/tools/bash.d.ts +1 -1
- package/dist/src/public/tools/bash.js +1 -1
- package/dist/src/public/tools/glob.d.ts +1 -1
- package/dist/src/public/tools/glob.js +1 -1
- package/dist/src/public/tools/grep.d.ts +1 -1
- package/dist/src/public/tools/grep.js +1 -1
- package/dist/src/public/tools/index.d.ts +5 -9
- package/dist/src/public/tools/index.js +1 -1
- package/dist/src/public/tools/read-file.d.ts +1 -1
- package/dist/src/public/tools/read-file.js +1 -1
- package/dist/src/public/tools/result.d.ts +17 -9
- package/dist/src/public/tools/result.js +1 -1
- package/dist/src/public/tools/web-fetch.d.ts +1 -1
- package/dist/src/public/tools/web-fetch.js +1 -1
- package/dist/src/public/tools/web-search.d.ts +1 -3
- package/dist/src/public/tools/web-search.js +1 -1
- package/dist/src/public/tools/write-file.d.ts +1 -1
- package/dist/src/public/tools/write-file.js +1 -1
- package/dist/src/public/workflow-modules.d.ts +8 -2
- package/dist/src/react/index.d.ts +4 -7
- package/dist/src/react/index.js +1 -1
- package/dist/src/react/use-eve-agent.d.ts +68 -50
- package/dist/src/react/use-eve-agent.js +1 -1
- package/dist/src/reactions/bundle.d.ts +4 -0
- package/dist/src/reactions/bundle.js +1 -0
- package/dist/src/reactions/frame.d.ts +13 -0
- package/dist/src/reactions/frame.js +1 -0
- package/dist/src/reactions/intents.d.ts +22 -0
- package/dist/src/reactions/intents.js +1 -0
- package/dist/src/reactions/kinds/connection.d.ts +18 -0
- package/dist/src/reactions/kinds/connection.js +1 -0
- package/dist/src/reactions/kinds/hook.d.ts +8 -0
- package/dist/src/reactions/kinds/hook.js +1 -0
- package/dist/src/reactions/kinds/instructions.d.ts +21 -0
- package/dist/src/reactions/kinds/instructions.js +1 -0
- package/dist/src/reactions/kinds/memory.d.ts +72 -0
- package/dist/src/reactions/kinds/memory.js +1 -0
- package/dist/src/reactions/kinds/model.d.ts +21 -0
- package/dist/src/reactions/kinds/model.js +1 -0
- package/dist/src/reactions/kinds/skill.d.ts +27 -0
- package/dist/src/reactions/kinds/skill.js +1 -0
- package/dist/src/reactions/kinds/subagent.d.ts +16 -0
- package/dist/src/reactions/kinds/subagent.js +1 -0
- package/dist/src/reactions/kinds/tool.d.ts +16 -0
- package/dist/src/reactions/kinds/tool.js +1 -0
- package/dist/src/reactions/policy.d.ts +13 -0
- package/dist/src/reactions/policy.js +1 -0
- package/dist/src/reactions/reaction.d.ts +83 -0
- package/dist/src/reactions/reaction.js +1 -0
- package/dist/src/reactions/records.d.ts +40 -0
- package/dist/src/reactions/records.js +1 -0
- package/dist/src/reactions/remote.d.ts +25 -0
- package/dist/src/reactions/remote.js +1 -0
- package/dist/src/reactions/runner.d.ts +45 -0
- package/dist/src/reactions/runner.js +1 -0
- package/dist/src/reactions/state.d.ts +102 -0
- package/dist/src/reactions/state.js +1 -0
- package/dist/src/reactions/turn.d.ts +12 -0
- package/dist/src/reactions/turn.js +2 -0
- package/dist/src/runtime/agent/bootstrap.d.ts +1 -3
- package/dist/src/runtime/agent/mock-model-adapter.js +1 -1
- package/dist/src/runtime/agent/resolve-model.js +1 -1
- package/dist/src/runtime/connections/mcp-client.d.ts +5 -2
- package/dist/src/runtime/connections/mcp-client.js +1 -1
- package/dist/src/runtime/connections/openapi-client.js +1 -1
- package/dist/src/runtime/connections/openapi-operations.d.ts +4 -0
- package/dist/src/runtime/connections/openapi-operations.js +1 -1
- package/dist/src/runtime/connections/openapi-schema.d.ts +19 -14
- package/dist/src/runtime/connections/openapi-schema.js +1 -1
- package/dist/src/runtime/connections/principal.d.ts +2 -0
- package/dist/src/runtime/connections/principal.js +1 -1
- package/dist/src/runtime/connections/registry.d.ts +2 -2
- package/dist/src/runtime/connections/registry.js +1 -1
- package/dist/src/runtime/connections/scoped-authorization.d.ts +8 -1
- package/dist/src/runtime/connections/scoped-authorization.js +1 -1
- package/dist/src/runtime/graph.d.ts +0 -6
- package/dist/src/runtime/local-dev-capability.d.ts +4 -5
- package/dist/src/runtime/local-dev-capability.js +1 -1
- package/dist/src/runtime/resolve-agent-graph.js +1 -1
- package/dist/src/runtime/resolve-agent.js +1 -1
- package/dist/src/runtime/resolve-connection.js +1 -1
- package/dist/src/runtime/resolve-dynamic.d.ts +9 -0
- package/dist/src/runtime/resolve-dynamic.js +1 -0
- package/dist/src/runtime/resolve-hook.js +1 -1
- package/dist/src/runtime/resolve-memory.js +1 -1
- package/dist/src/runtime/resolve-tool.js +1 -1
- package/dist/src/runtime/schedules/collection-client.js +1 -1
- package/dist/src/runtime/schedules/dispatch-occurrence.js +1 -1
- package/dist/src/runtime/sessions/compiled-agent-cache.d.ts +0 -2
- package/dist/src/runtime/sessions/compiled-agent-cache.js +1 -1
- package/dist/src/runtime/subagents/dynamic-agent-config.js +1 -1
- package/dist/src/runtime/subagents/dynamic-remote-agent-config.d.ts +16 -3
- package/dist/src/runtime/subagents/dynamic-remote-agent-config.js +1 -1
- package/dist/src/runtime/subagents/workflow.js +1 -1
- package/dist/src/runtime/types.d.ts +22 -39
- package/dist/src/sandbox/provider.d.ts +3 -3
- package/dist/src/sandbox/providers/default.d.ts +4 -2
- package/dist/src/sandbox/providers/default.js +1 -1
- package/dist/src/self-modification/agent.d.ts +3 -3
- package/dist/src/self-modification/agent.js +1 -1
- package/dist/src/self-modification/config.d.ts +1 -1
- package/dist/src/self-modification/config.js +1 -1
- package/dist/src/self-modification/deployed-sandbox.js +1 -1
- package/dist/src/self-modification/extension/extension.d.ts +1 -0
- package/dist/src/self-modification/extension/local-only.d.ts +1 -1
- package/dist/src/self-modification/extension/local-only.js +1 -1
- package/dist/src/self-modification/extension/subagents/agent/agent.d.ts +15 -4
- package/dist/src/self-modification/extension/subagents/agent/agent.js +1 -1
- package/dist/src/self-modification/extension/subagents/agent/instructions.d.ts +1 -1
- package/dist/src/self-modification/extension/subagents/agent/instructions.js +2 -2
- package/dist/src/self-modification/extension/subagents/agent/sandbox.d.ts +2 -2
- package/dist/src/self-modification/extension/subagents/agent/sandbox.js +1 -1
- package/dist/src/self-modification/extension/subagents/agent/skills/trace_analysis.d.ts +3 -3
- package/dist/src/self-modification/extension/subagents/agent/skills/trace_analysis.js +1 -1
- package/dist/src/self-modification/extension/subagents/agent/tools/inspect_trace.d.ts +1 -1
- package/dist/src/self-modification/extension/subagents/agent/tools/inspect_trace_spans.d.ts +1 -1
- package/dist/src/self-modification/extension/subagents/agent/tools/registry_add.d.ts +1 -1
- package/dist/src/self-modification/extension/subagents/agent/tools/search_traces.d.ts +1 -1
- package/dist/src/self-modification/mode.d.ts +8 -0
- package/dist/src/self-modification/mode.js +1 -1
- package/dist/src/self-modification/remote/config.d.ts +3 -6
- package/dist/src/self-modification/remote/extension.d.ts +1 -0
- package/dist/src/self-modification/remote/production-registry-add.js +1 -1
- package/dist/src/self-modification/remote/subagents/agent/agent.d.ts +6 -3
- package/dist/src/self-modification/remote/subagents/agent/agent.js +1 -1
- package/dist/src/self-modification/remote/subagents/agent/instructions.d.ts +1 -1
- package/dist/src/self-modification/remote/subagents/agent/instructions.js +2 -2
- package/dist/src/self-modification/remote/subagents/agent/tools/publish.d.ts +1 -3
- package/dist/src/self-modification/remote/subagents/agent/tools/publish.js +1 -1
- package/dist/src/self-modification/remote/subagents/agent/tools/registry_add.d.ts +1 -3
- package/dist/src/self-modification/remote/subagents/agent/tools/registry_add.js +1 -1
- package/dist/src/self-modification/scaffold.js +1 -1
- package/dist/src/self-modification/setup.js +3 -6
- package/dist/src/services/dev-client/client-options.js +1 -1
- package/dist/src/services/dev-client.d.ts +4 -4
- package/dist/src/services/dev-client.js +1 -1
- package/dist/src/setup/integrations/self-modification/setup.d.ts +1 -4
- package/dist/src/setup/integrations/self-modification/setup.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/setup/scaffold/create/web-template.d.ts +9 -18
- package/dist/src/setup/scaffold/create/web-template.js +1015 -2537
- package/dist/src/setup/verified-remote-agent.js +1 -1
- package/dist/src/shared/action-label.d.ts +5 -3
- package/dist/src/shared/action-label.js +1 -1
- package/dist/src/shared/action-types.d.ts +5 -0
- package/dist/src/shared/action-types.js +1 -1
- package/dist/src/shared/agent-definition.d.ts +14 -9
- package/dist/src/shared/answers-delivery-id.d.ts +1 -0
- package/dist/src/shared/answers-delivery-id.js +1 -0
- package/dist/src/shared/channel-context.d.ts +12 -0
- package/dist/src/shared/channel-context.js +1 -0
- package/dist/src/shared/channel-definition.d.ts +19 -26
- package/dist/src/shared/channel-delivery.d.ts +16 -0
- package/dist/src/shared/channel-delivery.js +1 -0
- package/dist/src/shared/connection-events.d.ts +2 -2
- package/dist/src/shared/connection-types.d.ts +12 -32
- package/dist/src/shared/conversation-context.d.ts +4 -13
- package/dist/src/shared/delivery.d.ts +38 -0
- package/dist/src/shared/delivery.js +1 -0
- package/dist/src/shared/history-message.d.ts +190 -0
- package/dist/src/shared/history-message.js +1 -0
- package/dist/src/shared/input.d.ts +23 -97
- package/dist/src/shared/input.js +1 -1
- package/dist/src/shared/instructions-definition.d.ts +2 -8
- package/dist/src/shared/instrumentation-channel-kind.d.ts +1 -1
- package/dist/src/shared/instrumentation-channel.d.ts +12 -0
- package/dist/src/shared/instrumentation-channel.js +1 -0
- package/dist/src/shared/json.d.ts +2 -18
- package/dist/src/shared/memory-state.d.ts +4 -40
- package/dist/src/shared/memory-state.js +1 -1
- package/dist/src/shared/message-content.d.ts +19 -0
- package/dist/src/shared/message-content.js +1 -0
- package/dist/src/shared/network-address.d.ts +9 -0
- package/dist/src/shared/network-address.js +1 -1
- package/dist/src/shared/sandbox-environment.d.ts +2 -2
- package/dist/src/shared/sandbox-provider.d.ts +1 -1
- package/dist/src/shared/sandbox-session.d.ts +60 -85
- package/dist/src/shared/schedule-definition.d.ts +5 -5
- package/dist/src/shared/serialized-observability-state.d.ts +0 -2
- package/dist/src/shared/serialized-observability-state.js +1 -1
- package/dist/src/shared/session-history.d.ts +2 -2
- package/dist/src/shared/session.d.ts +22 -0
- package/dist/src/shared/session.js +1 -0
- package/dist/src/shared/skill-definition.d.ts +1 -1
- package/dist/src/shared/skill-package.d.ts +2 -2
- package/dist/src/shared/skill-package.js +1 -1
- package/dist/src/shared/token-usage-math.d.ts +5 -0
- package/dist/src/shared/token-usage-math.js +1 -0
- package/dist/src/shared/token-usage.d.ts +0 -2
- package/dist/src/shared/token-usage.js +1 -1
- package/dist/src/shared/validate-authorization.js +1 -1
- package/dist/src/shared/wait-with-signal.d.ts +2 -0
- package/dist/src/shared/wait-with-signal.js +1 -0
- package/dist/src/subagents/adapter.d.ts +3 -5
- package/dist/src/subagents/adapter.js +1 -1
- package/dist/src/subagents/callback-route.js +1 -1
- package/dist/src/subagents/event-proxy-step.d.ts +6 -9
- package/dist/src/subagents/event-proxy-step.js +1 -1
- package/dist/src/subagents/hitl-proxy.d.ts +11 -23
- package/dist/src/subagents/hitl-proxy.js +1 -1
- package/dist/src/subagents/invocation.d.ts +8 -8
- package/dist/src/subagents/invocation.js +2 -2
- package/dist/src/subagents/parent-notification.d.ts +5 -0
- package/dist/src/subagents/parent-notification.js +1 -1
- package/dist/src/subagents/protocol-two-callback.d.ts +27 -0
- package/dist/src/subagents/protocol-two-callback.js +1 -0
- package/dist/src/svelte/index.d.ts +3 -6
- package/dist/src/svelte/index.js +2 -39
- package/dist/src/svelte/use-eve-agent.d.ts +67 -56
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/tool-stubs/rules.js +1 -1
- package/dist/src/tools/approval/policies.d.ts +4 -16
- package/dist/src/tools/approval/policies.js +1 -1
- package/dist/src/tools/auth.d.ts +3 -3
- package/dist/src/tools/definition.d.ts +13 -35
- package/dist/src/tools/definition.js +1 -1
- package/dist/src/tools/dynamic.d.ts +13 -72
- package/dist/src/tools/dynamic.js +1 -1
- package/dist/src/tools/framework/agent.js +1 -1
- package/dist/src/tools/provided/ask-question-workflow.d.ts +3 -3
- package/dist/src/tools/provided/ask-question-workflow.js +1 -1
- package/dist/src/tools/provided/ask-question.d.ts +2 -2
- package/dist/src/tools/provided/ask-question.js +1 -1
- package/dist/src/tools/provided/grep.d.ts +2 -15
- package/dist/src/tools/provided/grep.js +1 -2
- package/dist/src/tools/provided/no-reply.d.ts +2 -2
- package/dist/src/tools/provided/no-reply.js +1 -1
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/dist/src/tools/provided/sleep.d.ts +2 -2
- package/dist/src/tools/provided/sleep.js +1 -1
- package/dist/src/tools/provided/workflow.js +1 -1
- package/dist/src/tools/schema.d.ts +2 -0
- package/dist/src/tools/schema.js +1 -1
- package/dist/src/tools/signature.js +1 -1
- package/dist/src/tools/workflow-definition.d.ts +17 -15
- package/dist/src/tracing/eve/agent-approval-instrumentation.d.ts +1 -1
- package/dist/src/tracing/eve/agent-approval-instrumentation.js +1 -1
- package/dist/src/tracing/eve/agent-channel-delivery-instrumentation.d.ts +2 -2
- package/dist/src/tracing/eve/agent-channel-delivery-instrumentation.js +1 -1
- package/dist/src/tracing/eve/agent-invocation-coordinator.d.ts +2 -2
- package/dist/src/tracing/eve/agent-otel-provider.js +1 -1
- package/dist/src/tracing/eve/agent-tool-instrumentation.d.ts +6 -7
- package/dist/src/tracing/eve/agent-tool-instrumentation.js +1 -1
- package/dist/src/tracing/eve/agent-trace-context-store.d.ts +3 -3
- package/dist/src/tracing/eve/agent-trace-state.d.ts +1 -6
- package/dist/src/tracing/eve/delegation.d.ts +4 -4
- package/dist/src/tracing/eve/install-instrumentation-runtime.js +1 -1
- package/dist/src/tracing/eve/invoke-tool-span.d.ts +3 -2
- package/dist/src/tracing/eve/invoke-tool-span.js +1 -1
- package/dist/src/tracing/eve/otel-declaration.d.ts +9 -10
- package/dist/src/tracing/eve/otel-declaration.js +1 -1
- package/dist/src/tracing/eve/policy.d.ts +2 -2
- package/dist/src/tracing/eve/policy.js +1 -1
- package/dist/src/tracing/eve/session.d.ts +4 -3
- package/dist/src/tracing/eve/session.js +1 -1
- package/dist/src/vue/index.d.ts +3 -6
- package/dist/src/vue/index.js +2 -39
- package/dist/src/vue/use-eve-agent.d.ts +70 -59
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/agent-config.md +40 -44
- package/docs/channels/chat-sdk.mdx +19 -13
- package/docs/channels/custom.mdx +106 -85
- package/docs/channels/discord.mdx +12 -12
- package/docs/channels/eve.mdx +48 -15
- package/docs/channels/github.mdx +2 -2
- package/docs/channels/linear.mdx +8 -8
- package/docs/channels/linq.mdx +1 -1
- package/docs/channels/mcp.mdx +2 -2
- package/docs/channels/overview.mdx +11 -1
- package/docs/channels/photon.mdx +1 -1
- package/docs/channels/slack.mdx +65 -58
- package/docs/channels/teams.mdx +4 -4
- package/docs/channels/telegram.mdx +1 -1
- package/docs/channels/twilio.mdx +2 -2
- package/docs/code-extension.mdx +19 -7
- package/docs/concepts/built-in-tools.md +21 -9
- package/docs/concepts/context-control.md +5 -8
- package/docs/concepts/default-harness.md +8 -9
- package/docs/concepts/execution-model-and-durability.mdx +119 -12
- package/docs/concepts/meta.json +1 -0
- package/docs/concepts/sessions-runs-and-streaming.md +244 -138
- package/docs/concepts/state.md +1 -1
- package/docs/concepts/upgrade-to-v27-events.md +128 -0
- package/docs/connections/mcp.mdx +38 -34
- package/docs/connections/openapi.mdx +24 -3
- package/docs/connections/overview.mdx +66 -57
- package/docs/evals/assertions.mdx +30 -24
- package/docs/evals/cases.mdx +19 -24
- package/docs/evals/judge.mdx +2 -2
- package/docs/evals/overview.mdx +7 -7
- package/docs/evals/reporters.mdx +15 -11
- package/docs/evals/targets.mdx +5 -3
- package/docs/evals/tool-stubs.mdx +2 -2
- package/docs/extensions.md +6 -3
- package/docs/guides/auth-and-route-protection.md +4 -0
- package/docs/guides/client/continuations.mdx +10 -10
- package/docs/guides/client/messages.mdx +50 -48
- package/docs/guides/client/output-schema.mdx +13 -13
- package/docs/guides/client/overview.mdx +12 -12
- package/docs/guides/client/streaming.mdx +160 -123
- package/docs/guides/decide.md +15 -9
- package/docs/guides/deployment/self-hosting.md +5 -40
- package/docs/guides/dynamic-capabilities.md +151 -406
- package/docs/guides/frontend/nextjs.mdx +1 -1
- package/docs/guides/frontend/nuxt.mdx +2 -2
- package/docs/guides/frontend/overview.mdx +257 -181
- package/docs/guides/frontend/sveltekit.mdx +4 -4
- package/docs/guides/frontend/tanstack.mdx +5 -5
- package/docs/guides/frontend/use-eve-agent-svelte.mdx +30 -38
- package/docs/guides/frontend/use-eve-agent-vue.mdx +35 -36
- package/docs/guides/hooks.md +67 -55
- package/docs/guides/instrumentation/instrumentation.mdx +33 -27
- package/docs/guides/instrumentation/otel.mdx +4 -2
- package/docs/guides/remote-agents.md +116 -50
- package/docs/guides/self-modification.md +11 -7
- package/docs/instructions.mdx +4 -6
- package/docs/memory/custom-provider.md +63 -56
- package/docs/memory/file.md +1 -1
- package/docs/memory/overview.mdx +10 -18
- package/docs/patterns/durable-cross-channel-notifications.md +4 -3
- package/docs/patterns/multi-tenant-approvals.md +3 -3
- package/docs/patterns/multi-tenant-auth.md +3 -3
- package/docs/patterns/multi-tenant-memory.md +6 -7
- package/docs/patterns/voice-notes.md +1 -1
- package/docs/reference/cli.md +11 -25
- package/docs/reference/typescript-api.md +88 -61
- package/docs/sandbox/custom-providers.mdx +13 -14
- package/docs/sandbox/default.mdx +1 -1
- package/docs/sandbox/docker.mdx +10 -0
- package/docs/sandbox/index.mdx +4 -0
- package/docs/sandbox/vercel.mdx +6 -6
- package/docs/schedules.mdx +4 -4
- package/docs/skills.mdx +6 -6
- package/docs/subagents/index.mdx +25 -34
- package/docs/tools/human-in-the-loop.md +42 -34
- package/docs/tools/overview.mdx +14 -12
- package/docs/tools/tasks-upgrade.md +13 -1
- package/docs/tools/tasks.md +58 -89
- package/docs/tools/workflows.mdx +44 -33
- package/docs/tutorial/guard-the-spend.mdx +1 -1
- package/docs/tutorial/run-analysis.mdx +15 -12
- package/docs/tutorial/team-playbooks.mdx +19 -23
- package/package.json +148 -93
- package/dist/src/chunks/use-eve-agent-DnbG9c7c.js +0 -4921
- package/dist/src/chunks/use-eve-agent-ZY7NQ2VW.js +0 -4963
- package/dist/src/cli/invoke/command.d.ts +0 -19
- package/dist/src/cli/invoke/command.js +0 -1
- package/dist/src/cli/invoke/invoke.d.ts +0 -27
- package/dist/src/cli/invoke/invoke.js +0 -1
- package/dist/src/cli/invoke/result.d.ts +0 -137
- package/dist/src/cli/invoke/result.js +0 -1
- package/dist/src/client/agent-host.d.ts +0 -4
- package/dist/src/client/agent-host.js +0 -1
- package/dist/src/client/authorization-message-parts.d.ts +0 -4
- package/dist/src/client/authorization-message-parts.js +0 -1
- package/dist/src/client/conversation-projection.d.ts +0 -4
- package/dist/src/client/conversation-projection.js +0 -1
- package/dist/src/client/conversation-reducer.d.ts +0 -29
- package/dist/src/client/conversation-reducer.js +0 -1
- package/dist/src/client/eve-agent-projection.d.ts +0 -28
- package/dist/src/client/eve-agent-projection.js +0 -1
- package/dist/src/client/eve-agent-store-helpers.d.ts +0 -34
- package/dist/src/client/eve-agent-store-helpers.js +0 -2
- package/dist/src/client/eve-agent-store-state.d.ts +0 -96
- package/dist/src/client/eve-agent-store.d.ts +0 -45
- package/dist/src/client/eve-agent-store.js +0 -1
- package/dist/src/client/message-action-parts.d.ts +0 -37
- package/dist/src/client/message-action-parts.js +0 -1
- package/dist/src/client/message-reducer-primitives.d.ts +0 -6
- package/dist/src/client/message-reducer-primitives.js +0 -1
- package/dist/src/client/message-reducer-types.d.ts +0 -244
- package/dist/src/client/message-reducer.d.ts +0 -14
- package/dist/src/client/message-reducer.js +0 -1
- package/dist/src/client/message-response.d.ts +0 -74
- package/dist/src/client/message-response.js +0 -1
- package/dist/src/client/message-run-parts.d.ts +0 -22
- package/dist/src/client/message-run-parts.js +0 -1
- package/dist/src/client/output-schema.d.ts +0 -5
- package/dist/src/client/output-schema.js +0 -1
- package/dist/src/client/reducer.d.ts +0 -67
- package/dist/src/client/session-turn-dispatch.d.ts +0 -15
- package/dist/src/client/session-turn-dispatch.js +0 -1
- package/dist/src/client/tool-call-state.d.ts +0 -23
- package/dist/src/client/tool-call-state.js +0 -1
- package/dist/src/client/tool-part-state.d.ts +0 -7
- package/dist/src/client/tool-part-state.js +0 -1
- package/dist/src/client/transcript-reducer.d.ts +0 -49
- package/dist/src/client/transcript-reducer.js +0 -2
- package/dist/src/context/build-dynamic-tools.d.ts +0 -10
- package/dist/src/context/build-dynamic-tools.js +0 -1
- package/dist/src/context/dynamic-connection-lifecycle.d.ts +0 -15
- package/dist/src/context/dynamic-connection-lifecycle.js +0 -1
- package/dist/src/context/dynamic-instruction-lifecycle.d.ts +0 -31
- package/dist/src/context/dynamic-instruction-lifecycle.js +0 -1
- package/dist/src/context/dynamic-model-lifecycle.d.ts +0 -19
- package/dist/src/context/dynamic-model-lifecycle.js +0 -1
- package/dist/src/context/dynamic-resolve-context.d.ts +0 -12
- package/dist/src/context/dynamic-resolve-context.js +0 -1
- package/dist/src/context/dynamic-skill-lifecycle.d.ts +0 -15
- package/dist/src/context/dynamic-skill-lifecycle.js +0 -1
- package/dist/src/context/dynamic-subagent-lifecycle.d.ts +0 -27
- package/dist/src/context/dynamic-subagent-lifecycle.js +0 -1
- package/dist/src/context/dynamic-tool-lifecycle.d.ts +0 -46
- package/dist/src/context/dynamic-tool-lifecycle.js +0 -1
- package/dist/src/context/dynamic-tool-metadata.d.ts +0 -47
- package/dist/src/context/dynamic-tool-metadata.js +0 -1
- package/dist/src/context/effective-model.d.ts +0 -5
- package/dist/src/context/effective-model.js +0 -1
- package/dist/src/context/hook-lifecycle.d.ts +0 -15
- package/dist/src/context/hook-lifecycle.js +0 -1
- package/dist/src/context/memory-event-lifecycle.d.ts +0 -15
- package/dist/src/context/memory-event-lifecycle.js +0 -1
- package/dist/src/context/memory-lifecycle.d.ts +0 -47
- package/dist/src/context/memory-lifecycle.js +0 -1
- package/dist/src/context/serialized-dynamic-model-selection.d.ts +0 -2
- package/dist/src/context/serialized-dynamic-model-selection.js +0 -1
- package/dist/src/execution/cancel-descendant-turns-step.d.ts +0 -6
- package/dist/src/execution/cancel-descendant-turns-step.js +0 -1
- package/dist/src/execution/dynamic-connection-recovery.d.ts +0 -14
- package/dist/src/execution/dynamic-connection-recovery.js +0 -1
- package/dist/src/execution/dynamic-connections.d.ts +0 -12
- package/dist/src/execution/dynamic-connections.js +0 -1
- package/dist/src/execution/history-view.d.ts +0 -10
- package/dist/src/execution/history-view.js +0 -1
- package/dist/src/execution/legacy-remote-agent/protocol.d.ts +0 -49
- package/dist/src/execution/legacy-remote-agent/protocol.js +0 -1
- package/dist/src/execution/runtime-errors.d.ts +0 -13
- package/dist/src/execution/runtime-errors.js +0 -1
- package/dist/src/execution/sandbox/grep-tool.d.ts +0 -26
- package/dist/src/execution/sandbox/grep-tool.js +0 -3
- package/dist/src/execution/session/turn-waiting-step.d.ts +0 -4
- package/dist/src/execution/session/turn-waiting-step.js +0 -1
- package/dist/src/execution/tools/workflow/cancel.d.ts +0 -13
- package/dist/src/execution/tools/workflow/cancel.js +0 -1
- package/dist/src/execution/workflow-trace-context.d.ts +0 -8
- package/dist/src/execution/workflow-trace-context.js +0 -1
- package/dist/src/extensions/code/extension/instructions/github.d.ts +0 -3
- package/dist/src/extensions/code/extension/instructions/github.js +0 -1
- package/dist/src/extensions/code/extension/lib/github-compat.d.ts +0 -28
- package/dist/src/extensions/code/extension/lib/github-compat.js +0 -1
- package/dist/src/extensions/code/extension/lib/grep-search.js +0 -6
- package/dist/src/extensions/code/extension/skills/pr.d.ts +0 -6
- package/dist/src/extensions/code/extension/skills/pr.js +0 -1
- package/dist/src/extensions/code/extension/tools/gh.d.ts +0 -28
- package/dist/src/extensions/code/extension/tools/gh.js +0 -1
- package/dist/src/harness/approval-recheck.d.ts +0 -7
- package/dist/src/harness/approval-recheck.js +0 -1
- package/dist/src/harness/authorization-event-fields.d.ts +0 -16
- package/dist/src/harness/authorization-event-fields.js +0 -1
- package/dist/src/harness/hitl/candidates.d.ts +0 -139
- package/dist/src/harness/hitl/candidates.js +0 -1
- package/dist/src/harness/hitl/coordinator.d.ts +0 -35
- package/dist/src/harness/hitl/coordinator.js +0 -1
- package/dist/src/harness/input-extraction.d.ts +0 -13
- package/dist/src/harness/input-extraction.js +0 -1
- package/dist/src/harness/input-request-class.d.ts +0 -3
- package/dist/src/harness/input-request-class.js +0 -1
- package/dist/src/harness/input-request-resolution.d.ts +0 -39
- package/dist/src/harness/input-request-resolution.js +0 -1
- package/dist/src/harness/open-input-request.d.ts +0 -8
- package/dist/src/harness/open-input-request.js +0 -1
- package/dist/src/harness/session-machine/events.d.ts +0 -6
- package/dist/src/harness/session-machine/events.js +0 -1
- package/dist/src/harness/session-machine/resolver-events.d.ts +0 -12
- package/dist/src/harness/session-machine/resolver-events.js +0 -1
- package/dist/src/harness/tool-call-action.d.ts +0 -9
- package/dist/src/harness/tool-call-action.js +0 -1
- package/dist/src/harness/tool-interrupts.d.ts +0 -22
- package/dist/src/harness/tool-interrupts.js +0 -1
- package/dist/src/harness/tool-presentation.d.ts +0 -5
- package/dist/src/harness/tool-presentation.js +0 -1
- package/dist/src/harness/turn-tag-state.d.ts +0 -115
- package/dist/src/harness/turn-tag-state.js +0 -1
- package/dist/src/internal/dynamic-tool-rebind.d.ts +0 -3
- package/dist/src/internal/dynamic-tool-rebind.js +0 -1
- package/dist/src/internal/nitro/host/extension-capability-requirements.d.ts +0 -14
- package/dist/src/internal/nitro/host/extension-capability-requirements.js +0 -1
- package/dist/src/internal/workflow-bundle/dynamic-capability-transform-plugin.d.ts +0 -12
- package/dist/src/internal/workflow-bundle/dynamic-capability-transform-plugin.js +0 -1
- package/dist/src/internal/workflow-bundle/dynamic-remote-agent-transform.d.ts +0 -7
- package/dist/src/internal/workflow-bundle/dynamic-remote-agent-transform.js +0 -3
- package/dist/src/internal/workflow-bundle/dynamic-tool-ast-references.d.ts +0 -79
- package/dist/src/internal/workflow-bundle/dynamic-tool-ast-references.js +0 -1
- package/dist/src/internal/workflow-bundle/dynamic-tool-transform.d.ts +0 -14
- package/dist/src/internal/workflow-bundle/dynamic-tool-transform.js +0 -3
- package/dist/src/protocol/event-dedupe.d.ts +0 -26
- package/dist/src/protocol/event-dedupe.js +0 -1
- package/dist/src/protocol/event-id.d.ts +0 -10
- package/dist/src/protocol/event-id.js +0 -1
- package/dist/src/protocol/message-version.d.ts +0 -53
- package/dist/src/protocol/message-version.js +0 -1
- package/dist/src/protocol/message.d.ts +0 -1198
- package/dist/src/protocol/message.js +0 -2
- package/dist/src/public/channels/chat-sdk/messageToUserContent.js +0 -1
- package/dist/src/public/channels/slack/input-response.js +0 -1
- package/dist/src/runtime/hooks/registry.d.ts +0 -34
- package/dist/src/runtime/hooks/registry.js +0 -1
- package/dist/src/runtime/resolve-dynamic-connection.d.ts +0 -5
- package/dist/src/runtime/resolve-dynamic-connection.js +0 -1
- package/dist/src/runtime/resolve-dynamic-instructions.d.ts +0 -4
- package/dist/src/runtime/resolve-dynamic-instructions.js +0 -1
- package/dist/src/runtime/resolve-dynamic-skill.d.ts +0 -8
- package/dist/src/runtime/resolve-dynamic-skill.js +0 -1
- package/dist/src/runtime/resolve-dynamic-subagent.d.ts +0 -9
- package/dist/src/runtime/resolve-dynamic-subagent.js +0 -1
- package/dist/src/runtime/resolve-dynamic-tool.d.ts +0 -12
- package/dist/src/runtime/resolve-dynamic-tool.js +0 -1
- package/dist/src/self-modification/migration.d.ts +0 -9
- package/dist/src/self-modification/migration.js +0 -28
- package/dist/src/shared/history-view.d.ts +0 -22
- package/dist/src/shared/history-view.js +0 -1
- package/dist/src/shared/package-version.d.ts +0 -2
- package/dist/src/shared/package-version.js +0 -1
- package/dist/src/tools/durable-callbacks.d.ts +0 -118
- package/dist/src/tools/durable-callbacks.js +0 -1
- package/dist/src/tools/durable-schema.d.ts +0 -16
- package/dist/src/tools/durable-schema.js +0 -1
- /package/dist/src/{client/eve-agent-store-state.js → ai/decision-types.js} +0 -0
- /package/dist/src/client/{message-reducer-types.js → agent-info-types.js} +0 -0
- /package/dist/src/client/{reducer.js → health-types.js} +0 -0
- /package/dist/src/{shared → protocol/session-projection}/display-name.d.ts +0 -0
- /package/dist/src/{shared → protocol/session-projection}/display-name.js +0 -0
|
@@ -1,4921 +0,0 @@
|
|
|
1
|
-
import { computed, onScopeDispose, shallowRef } from "vue";
|
|
2
|
-
import { z } from "#compiled/zod/index.js";
|
|
3
|
-
import "ai";
|
|
4
|
-
import { Validator } from "#compiled/@cfworker/json-schema/index.js";
|
|
5
|
-
|
|
6
|
-
//#region src/client/abort-signal.ts
|
|
7
|
-
function throwIfAborted(signal) {
|
|
8
|
-
if (signal === void 0) return;
|
|
9
|
-
const nativeThrowIfAborted = signal.throwIfAborted;
|
|
10
|
-
if (typeof nativeThrowIfAborted === "function") {
|
|
11
|
-
nativeThrowIfAborted.call(signal);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (!signal.aborted) return;
|
|
15
|
-
if (signal.reason !== void 0) throw signal.reason;
|
|
16
|
-
const error = /* @__PURE__ */ new Error("The operation was aborted.");
|
|
17
|
-
error.name = "AbortError";
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/protocol/routes.ts
|
|
23
|
-
const EVE_ROUTE_PREFIX = "/eve/v1";
|
|
24
|
-
const EVE_PRODUCTION_CRON_ROUTE_PATTERN = `${EVE_ROUTE_PREFIX}/cron/:token`;
|
|
25
|
-
const EVE_HEALTH_ROUTE_PATH = `${EVE_ROUTE_PREFIX}/health`;
|
|
26
|
-
const EVE_INFO_ROUTE_PATH = `${EVE_ROUTE_PREFIX}/info`;
|
|
27
|
-
const EVE_SESSION_ROUTE_PATH = `${EVE_ROUTE_PREFIX}/session`;
|
|
28
|
-
const EVE_SESSION_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId`;
|
|
29
|
-
const EVE_SESSION_CANCEL_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/cancel`;
|
|
30
|
-
const EVE_SESSION_COMPACT_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/compact`;
|
|
31
|
-
const EVE_SESSION_CLEAR_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/clear`;
|
|
32
|
-
const EVE_SESSION_RESET_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/reset`;
|
|
33
|
-
const EVE_SESSION_STUBS_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/stubs`;
|
|
34
|
-
const EVE_SESSION_STREAM_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/stream`;
|
|
35
|
-
const EVE_SUBAGENT_STREAM_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:parentSessionId/subagents/:callId/:childSessionId/stream`;
|
|
36
|
-
const EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN = `${EVE_ROUTE_PREFIX}/dev/schedules/:scheduleId`;
|
|
37
|
-
const EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH = `${EVE_ROUTE_PREFIX}/dev/runtime-artifacts`;
|
|
38
|
-
const EVE_DEV_RUNTIME_ARTIFACTS_REBUILD_ROUTE_PATH = `${EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}/rebuild`;
|
|
39
|
-
const EVE_DEV_RUNTIME_ARTIFACTS_SUSPEND_ROUTE_PATH = `${EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}/suspend`;
|
|
40
|
-
const EVE_DEV_RUNTIME_ARTIFACTS_RESUME_ROUTE_PATH = `${EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}/resume`;
|
|
41
|
-
const EVE_CONNECTION_CALLBACK_ROUTE_PATTERN = `${EVE_ROUTE_PREFIX}/connections/:name/callback/:attemptId/:token`;
|
|
42
|
-
const EVE_CALLBACK_ROUTE_PATTERN = `${EVE_ROUTE_PREFIX}/callback/:token`;
|
|
43
|
-
function createEveSessionRoutePath(sessionId) {
|
|
44
|
-
return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}`;
|
|
45
|
-
}
|
|
46
|
-
function createEveSessionCancelRoutePath(sessionId) {
|
|
47
|
-
return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/cancel`;
|
|
48
|
-
}
|
|
49
|
-
function createEveSessionCompactRoutePath(sessionId) {
|
|
50
|
-
return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/compact`;
|
|
51
|
-
}
|
|
52
|
-
function createEveSessionClearRoutePath(sessionId) {
|
|
53
|
-
return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/clear`;
|
|
54
|
-
}
|
|
55
|
-
function createEveSessionResetRoutePath(sessionId) {
|
|
56
|
-
return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/reset`;
|
|
57
|
-
}
|
|
58
|
-
function createEveSessionStreamRoutePath(sessionId) {
|
|
59
|
-
return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/stream`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/client/agent-info-error.ts
|
|
64
|
-
var AgentInfoResponseError = class extends Error {
|
|
65
|
-
issues;
|
|
66
|
-
constructor(issues = []) {
|
|
67
|
-
const detail = issues.length === 0 ? "" : ` (${issues.join("; ")})`;
|
|
68
|
-
super(`The server returned an unrecognized response from the eve agent info route.${detail}`);
|
|
69
|
-
this.name = "AgentInfoResponseError";
|
|
70
|
-
this.issues = issues;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/client/health-response-error.ts
|
|
76
|
-
var HealthResponseError = class extends Error {
|
|
77
|
-
issues;
|
|
78
|
-
constructor(issues = []) {
|
|
79
|
-
const detail = issues.length === 0 ? "" : ` (${issues.join("; ")})`;
|
|
80
|
-
super(`The server returned an unrecognized eve health response.${detail}`);
|
|
81
|
-
this.name = "HealthResponseError";
|
|
82
|
-
this.issues = issues;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region src/client/health-schema.ts
|
|
88
|
-
const HealthResultSchema = z.object({
|
|
89
|
-
ok: z.literal(true),
|
|
90
|
-
status: z.literal("ready"),
|
|
91
|
-
workflowId: z.string().min(1)
|
|
92
|
-
}).strict();
|
|
93
|
-
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/internal/http/basic-auth.ts
|
|
96
|
-
function encodeBasicCredentials(username, password) {
|
|
97
|
-
const bytes = new TextEncoder().encode(`${username}:${password}`);
|
|
98
|
-
const binaryString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
|
|
99
|
-
return btoa(binaryString);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/shared/extension-mount.ts
|
|
104
|
-
const mountIdSchema = z.string().min(1);
|
|
105
|
-
|
|
106
|
-
//#endregion
|
|
107
|
-
//#region src/client/agent-info-schema.ts
|
|
108
|
-
const owner = z.discriminatedUnion("kind", [
|
|
109
|
-
z.object({ kind: z.literal("application") }).strict(),
|
|
110
|
-
z.object({
|
|
111
|
-
feature: z.string(),
|
|
112
|
-
kind: z.literal("framework")
|
|
113
|
-
}).strict(),
|
|
114
|
-
z.object({
|
|
115
|
-
kind: z.literal("extension"),
|
|
116
|
-
mountId: mountIdSchema.optional(),
|
|
117
|
-
namespace: z.string(),
|
|
118
|
-
packageName: z.string()
|
|
119
|
-
}).strict()
|
|
120
|
-
]);
|
|
121
|
-
const moduleBacking = z.discriminatedUnion("kind", [z.object({
|
|
122
|
-
externalDependencies: z.array(z.string()),
|
|
123
|
-
extensionScope: z.object({
|
|
124
|
-
namespace: z.string(),
|
|
125
|
-
sourceRoot: z.string()
|
|
126
|
-
}).strict().optional(),
|
|
127
|
-
kind: z.literal("filesystem"),
|
|
128
|
-
mountId: z.string().optional(),
|
|
129
|
-
sourcePath: z.string()
|
|
130
|
-
}).strict(), z.object({
|
|
131
|
-
dependencies: z.record(z.string(), z.string()).optional(),
|
|
132
|
-
kind: z.literal("programmatic"),
|
|
133
|
-
mountId: z.string().optional(),
|
|
134
|
-
moduleId: z.string(),
|
|
135
|
-
parameters: z.record(z.string(), z.unknown()).optional(),
|
|
136
|
-
registryId: z.string(),
|
|
137
|
-
revision: z.string(),
|
|
138
|
-
semanticRevision: z.string().optional()
|
|
139
|
-
}).strict()]);
|
|
140
|
-
const binding = z.object({
|
|
141
|
-
backing: moduleBacking,
|
|
142
|
-
logicalPath: z.string(),
|
|
143
|
-
owner
|
|
144
|
-
}).strict();
|
|
145
|
-
const source = z.object({
|
|
146
|
-
binding: binding.optional(),
|
|
147
|
-
exportName: z.string().optional(),
|
|
148
|
-
logicalPath: z.string(),
|
|
149
|
-
owner,
|
|
150
|
-
sourceId: z.string(),
|
|
151
|
-
sourceKind: z.enum([
|
|
152
|
-
"markdown",
|
|
153
|
-
"module",
|
|
154
|
-
"skill-package"
|
|
155
|
-
])
|
|
156
|
-
}).strict();
|
|
157
|
-
const entry = source.extend({ name: z.string() }).strict();
|
|
158
|
-
const dynamicResolver = source.extend({
|
|
159
|
-
eventNames: z.array(z.string()),
|
|
160
|
-
slug: z.string()
|
|
161
|
-
}).strict();
|
|
162
|
-
const modelRouting = z.discriminatedUnion("kind", [z.object({
|
|
163
|
-
kind: z.literal("gateway"),
|
|
164
|
-
target: z.string(),
|
|
165
|
-
byok: z.string().optional()
|
|
166
|
-
}).strict(), z.object({
|
|
167
|
-
kind: z.literal("external"),
|
|
168
|
-
provider: z.string()
|
|
169
|
-
}).strict()]);
|
|
170
|
-
const modelEndpoint = z.union([
|
|
171
|
-
z.object({
|
|
172
|
-
kind: z.literal("external"),
|
|
173
|
-
provider: z.string()
|
|
174
|
-
}).strict(),
|
|
175
|
-
z.object({
|
|
176
|
-
kind: z.literal("chatgpt"),
|
|
177
|
-
state: z.enum([
|
|
178
|
-
"checking",
|
|
179
|
-
"ready",
|
|
180
|
-
"signed-out",
|
|
181
|
-
"reauth-required",
|
|
182
|
-
"unavailable"
|
|
183
|
-
]),
|
|
184
|
-
accountLabel: z.string().optional()
|
|
185
|
-
}).strict(),
|
|
186
|
-
z.object({
|
|
187
|
-
kind: z.literal("gateway"),
|
|
188
|
-
connected: z.literal(true),
|
|
189
|
-
credential: z.enum([
|
|
190
|
-
"api-key",
|
|
191
|
-
"oidc",
|
|
192
|
-
"oauth"
|
|
193
|
-
]),
|
|
194
|
-
team: z.optional(z.string())
|
|
195
|
-
}).strict(),
|
|
196
|
-
z.object({
|
|
197
|
-
kind: z.literal("gateway"),
|
|
198
|
-
connected: z.literal(false)
|
|
199
|
-
}).strict()
|
|
200
|
-
]);
|
|
201
|
-
const modelBaseFields = {
|
|
202
|
-
contextWindowTokens: z.number().optional(),
|
|
203
|
-
providerOptions: z.unknown().optional(),
|
|
204
|
-
reasoning: z.enum([
|
|
205
|
-
"provider-default",
|
|
206
|
-
"none",
|
|
207
|
-
"minimal",
|
|
208
|
-
"low",
|
|
209
|
-
"medium",
|
|
210
|
-
"high",
|
|
211
|
-
"xhigh"
|
|
212
|
-
]).optional().catch(void 0),
|
|
213
|
-
source: source.optional()
|
|
214
|
-
};
|
|
215
|
-
const agentModel = z.union([z.object({
|
|
216
|
-
...modelBaseFields,
|
|
217
|
-
endpoint: modelEndpoint.optional(),
|
|
218
|
-
id: z.string(),
|
|
219
|
-
routing: modelRouting
|
|
220
|
-
}).strict(), z.object({
|
|
221
|
-
...modelBaseFields,
|
|
222
|
-
endpoint: z.never().optional(),
|
|
223
|
-
id: z.never().optional(),
|
|
224
|
-
routing: z.object({
|
|
225
|
-
kind: z.literal("dynamic"),
|
|
226
|
-
resolver: dynamicResolver
|
|
227
|
-
}).strict()
|
|
228
|
-
}).strict()]);
|
|
229
|
-
const tool = entry.extend({
|
|
230
|
-
description: z.string(),
|
|
231
|
-
hasAuth: z.boolean(),
|
|
232
|
-
hasExecute: z.boolean(),
|
|
233
|
-
hasModelOutputProjection: z.boolean(),
|
|
234
|
-
hasOutputSchema: z.boolean(),
|
|
235
|
-
inputSchema: z.unknown(),
|
|
236
|
-
outputSchema: z.unknown().optional(),
|
|
237
|
-
requiresApproval: z.boolean()
|
|
238
|
-
}).strict();
|
|
239
|
-
const skill = entry.extend({
|
|
240
|
-
description: z.string(),
|
|
241
|
-
license: z.string().optional(),
|
|
242
|
-
markdown: z.string(),
|
|
243
|
-
metadata: z.record(z.string(), z.string()).optional()
|
|
244
|
-
}).strict();
|
|
245
|
-
const instructions = entry.extend({
|
|
246
|
-
content: z.string(),
|
|
247
|
-
role: z.enum(["system", "user"])
|
|
248
|
-
}).strict();
|
|
249
|
-
const schedule = entry.extend({
|
|
250
|
-
cron: z.string(),
|
|
251
|
-
hasRun: z.boolean(),
|
|
252
|
-
markdown: z.string().optional()
|
|
253
|
-
}).strict();
|
|
254
|
-
const channelMethod = z.enum([
|
|
255
|
-
"GET",
|
|
256
|
-
"HEAD",
|
|
257
|
-
"POST",
|
|
258
|
-
"PUT",
|
|
259
|
-
"PATCH",
|
|
260
|
-
"DELETE",
|
|
261
|
-
"OPTIONS",
|
|
262
|
-
"WEBSOCKET"
|
|
263
|
-
]);
|
|
264
|
-
const channelRoute = entry.extend({
|
|
265
|
-
adapterKind: z.string().optional(),
|
|
266
|
-
method: channelMethod,
|
|
267
|
-
urlPath: z.string()
|
|
268
|
-
}).strict();
|
|
269
|
-
const sourceDescriptor = z.object({
|
|
270
|
-
backing: z.union([moduleBacking, z.object({
|
|
271
|
-
kind: z.literal("resource"),
|
|
272
|
-
sourcePath: z.string()
|
|
273
|
-
}).strict()]),
|
|
274
|
-
form: z.enum(["derived", "direct"]),
|
|
275
|
-
layer: z.enum([
|
|
276
|
-
"framework-default",
|
|
277
|
-
"extension-package",
|
|
278
|
-
"extension-override",
|
|
279
|
-
"application"
|
|
280
|
-
]),
|
|
281
|
-
logicalPath: z.string(),
|
|
282
|
-
owner,
|
|
283
|
-
sourceId: z.string()
|
|
284
|
-
}).strict();
|
|
285
|
-
const shadowedChannelRoute = z.object({
|
|
286
|
-
method: channelMethod,
|
|
287
|
-
source: sourceDescriptor,
|
|
288
|
-
urlPath: z.string(),
|
|
289
|
-
winnerSourceId: z.string()
|
|
290
|
-
}).strict();
|
|
291
|
-
const connection = source.extend({
|
|
292
|
-
connectionName: z.string(),
|
|
293
|
-
description: z.string(),
|
|
294
|
-
hasApproval: z.boolean(),
|
|
295
|
-
hasAuthorization: z.boolean(),
|
|
296
|
-
hasHeaders: z.boolean(),
|
|
297
|
-
protocol: z.string(),
|
|
298
|
-
toolFilter: z.unknown().optional(),
|
|
299
|
-
url: z.string()
|
|
300
|
-
}).strict();
|
|
301
|
-
const hook = source.extend({
|
|
302
|
-
eventNames: z.array(z.string()),
|
|
303
|
-
slug: z.string()
|
|
304
|
-
}).strict();
|
|
305
|
-
const memory = source.extend({
|
|
306
|
-
description: z.string().optional(),
|
|
307
|
-
slot: z.string(),
|
|
308
|
-
visibility: z.enum(["scope", "session"])
|
|
309
|
-
}).strict();
|
|
310
|
-
const sandbox = source.extend({
|
|
311
|
-
provider: z.string().optional(),
|
|
312
|
-
environmentExportName: z.string().optional(),
|
|
313
|
-
revisionHash: z.string()
|
|
314
|
-
}).strict();
|
|
315
|
-
const subagent = entry.extend({
|
|
316
|
-
configResolver: dynamicResolver.optional(),
|
|
317
|
-
description: z.string().optional(),
|
|
318
|
-
entryPath: z.string(),
|
|
319
|
-
nodeId: z.string(),
|
|
320
|
-
parentNodeId: z.string(),
|
|
321
|
-
rootPath: z.string(),
|
|
322
|
-
summary: z.object({
|
|
323
|
-
channels: z.number(),
|
|
324
|
-
connections: z.number(),
|
|
325
|
-
hooks: z.number(),
|
|
326
|
-
instructions: z.number(),
|
|
327
|
-
memories: z.number(),
|
|
328
|
-
schedules: z.number(),
|
|
329
|
-
skills: z.number(),
|
|
330
|
-
tools: z.number()
|
|
331
|
-
}).strict()
|
|
332
|
-
}).strict();
|
|
333
|
-
const remoteAgent = entry.extend({
|
|
334
|
-
description: z.string(),
|
|
335
|
-
nodeId: z.string(),
|
|
336
|
-
parentNodeId: z.string(),
|
|
337
|
-
url: z.string().optional()
|
|
338
|
-
}).strict();
|
|
339
|
-
const kernelEffect = z.object({
|
|
340
|
-
action: z.union([z.enum(["subagent-call", "workflow-tool-call"]), z.literal("unrecognized")]).catch("unrecognized").optional(),
|
|
341
|
-
audience: z.array(z.union([z.literal("root-session"), z.literal("unrecognized")]).catch("unrecognized")),
|
|
342
|
-
kind: z.union([z.enum(["dispatch", "provider-tool"]), z.literal("unrecognized")]).catch("unrecognized"),
|
|
343
|
-
sourceId: z.string()
|
|
344
|
-
}).strict();
|
|
345
|
-
const compositionDiagnostic = z.object({
|
|
346
|
-
kind: z.enum(["disabled", "shadowed"]),
|
|
347
|
-
logicalPath: z.string(),
|
|
348
|
-
owner,
|
|
349
|
-
sourceId: z.string(),
|
|
350
|
-
winnerSourceId: z.string().optional()
|
|
351
|
-
}).strict();
|
|
352
|
-
const AgentInfoResultSchema = z.object({
|
|
353
|
-
agent: z.object({
|
|
354
|
-
agentRoot: z.string(),
|
|
355
|
-
appRoot: z.string(),
|
|
356
|
-
config: source.extend({ binding }).strict(),
|
|
357
|
-
description: z.string().optional(),
|
|
358
|
-
model: agentModel,
|
|
359
|
-
name: z.string(),
|
|
360
|
-
nodeId: z.string(),
|
|
361
|
-
outputSchema: z.unknown().optional()
|
|
362
|
-
}).strict(),
|
|
363
|
-
capabilities: z.object({ devRoutes: z.boolean() }).strict(),
|
|
364
|
-
channels: z.object({
|
|
365
|
-
routes: z.array(channelRoute),
|
|
366
|
-
shadowed: z.array(shadowedChannelRoute)
|
|
367
|
-
}).strict(),
|
|
368
|
-
composition: z.object({
|
|
369
|
-
disabled: z.array(compositionDiagnostic),
|
|
370
|
-
shadowed: z.array(compositionDiagnostic)
|
|
371
|
-
}).strict(),
|
|
372
|
-
connections: z.array(connection),
|
|
373
|
-
diagnostics: z.object({
|
|
374
|
-
discoveryErrors: z.number(),
|
|
375
|
-
discoveryWarnings: z.number()
|
|
376
|
-
}).strict(),
|
|
377
|
-
hooks: z.array(hook),
|
|
378
|
-
instructions: z.object({
|
|
379
|
-
dynamic: z.array(dynamicResolver),
|
|
380
|
-
static: z.array(instructions)
|
|
381
|
-
}).strict(),
|
|
382
|
-
instrumentation: source.optional(),
|
|
383
|
-
kernelEffects: z.array(kernelEffect),
|
|
384
|
-
kind: z.literal("eve-agent-info"),
|
|
385
|
-
memories: z.array(memory),
|
|
386
|
-
mode: z.enum(["development", "production"]),
|
|
387
|
-
remoteAgents: z.object({
|
|
388
|
-
entries: z.array(remoteAgent),
|
|
389
|
-
total: z.number()
|
|
390
|
-
}).strict(),
|
|
391
|
-
sandbox,
|
|
392
|
-
schedules: z.array(schedule),
|
|
393
|
-
skills: z.object({
|
|
394
|
-
dynamic: z.array(dynamicResolver),
|
|
395
|
-
static: z.array(skill)
|
|
396
|
-
}).strict(),
|
|
397
|
-
subagents: z.object({
|
|
398
|
-
local: z.array(subagent),
|
|
399
|
-
total: z.number()
|
|
400
|
-
}).strict(),
|
|
401
|
-
tools: z.object({
|
|
402
|
-
dynamic: z.array(dynamicResolver),
|
|
403
|
-
static: z.array(tool)
|
|
404
|
-
}).strict(),
|
|
405
|
-
version: z.literal(5),
|
|
406
|
-
workspace: z.object({
|
|
407
|
-
resourceRoot: z.unknown(),
|
|
408
|
-
rootEntries: z.array(z.string())
|
|
409
|
-
}).strict()
|
|
410
|
-
}).strict().superRefine((value, context) => {
|
|
411
|
-
const assertUnique = (entries, identity, path) => {
|
|
412
|
-
const seen = /* @__PURE__ */ new Set();
|
|
413
|
-
entries.forEach((entry, index) => {
|
|
414
|
-
const key = identity(entry);
|
|
415
|
-
if (seen.has(key)) context.addIssue({
|
|
416
|
-
code: "custom",
|
|
417
|
-
message: `Duplicate public identity "${key}".`,
|
|
418
|
-
path: [...path, index]
|
|
419
|
-
});
|
|
420
|
-
seen.add(key);
|
|
421
|
-
});
|
|
422
|
-
};
|
|
423
|
-
const assertTotal = (total, entries, path) => {
|
|
424
|
-
if (!Number.isSafeInteger(total) || total < 0 || total !== entries.length) context.addIssue({
|
|
425
|
-
code: "custom",
|
|
426
|
-
message: `Expected total ${entries.length}, received ${total}.`,
|
|
427
|
-
path: [...path]
|
|
428
|
-
});
|
|
429
|
-
};
|
|
430
|
-
assertUnique(value.tools.static, (entry) => entry.name, ["tools", "static"]);
|
|
431
|
-
assertUnique(value.tools.dynamic, (entry) => entry.slug, ["tools", "dynamic"]);
|
|
432
|
-
assertUnique(value.skills.static, (entry) => entry.name, ["skills", "static"]);
|
|
433
|
-
assertUnique(value.skills.dynamic, (entry) => entry.slug, ["skills", "dynamic"]);
|
|
434
|
-
assertUnique(value.instructions.static, (entry) => entry.name, ["instructions", "static"]);
|
|
435
|
-
assertUnique(value.instructions.dynamic, (entry) => entry.slug, ["instructions", "dynamic"]);
|
|
436
|
-
assertUnique(value.schedules, (entry) => entry.name, ["schedules"]);
|
|
437
|
-
assertUnique(value.connections, (entry) => entry.connectionName, ["connections"]);
|
|
438
|
-
assertUnique(value.hooks, (entry) => entry.slug, ["hooks"]);
|
|
439
|
-
assertUnique(value.memories, (entry) => entry.slot, ["memories"]);
|
|
440
|
-
assertUnique(value.channels.routes, (entry) => `${entry.method} ${normalizeRoutePattern(entry.urlPath)}`, ["channels", "routes"]);
|
|
441
|
-
assertUnique(value.subagents.local, (entry) => entry.nodeId, ["subagents", "local"]);
|
|
442
|
-
assertUnique(value.remoteAgents.entries, (entry) => entry.nodeId, ["remoteAgents", "entries"]);
|
|
443
|
-
assertTotal(value.subagents.total, value.subagents.local, ["subagents", "total"]);
|
|
444
|
-
assertTotal(value.remoteAgents.total, value.remoteAgents.entries, ["remoteAgents", "total"]);
|
|
445
|
-
const boundSources = [
|
|
446
|
-
[value.agent.config, ["agent", "config"]],
|
|
447
|
-
...value.agent.model.source === void 0 ? [] : [[value.agent.model.source, [
|
|
448
|
-
"agent",
|
|
449
|
-
"model",
|
|
450
|
-
"source"
|
|
451
|
-
]]],
|
|
452
|
-
...value.agent.model.routing.kind === "dynamic" ? [[value.agent.model.routing.resolver, [
|
|
453
|
-
"agent",
|
|
454
|
-
"model",
|
|
455
|
-
"routing",
|
|
456
|
-
"resolver"
|
|
457
|
-
]]] : [],
|
|
458
|
-
...value.channels.routes.map((entry, index) => [entry, [
|
|
459
|
-
"channels",
|
|
460
|
-
"routes",
|
|
461
|
-
index
|
|
462
|
-
]]),
|
|
463
|
-
...value.connections.map((entry, index) => [entry, ["connections", index]]),
|
|
464
|
-
...value.hooks.map((entry, index) => [entry, ["hooks", index]]),
|
|
465
|
-
...value.instructions.dynamic.map((entry, index) => [entry, [
|
|
466
|
-
"instructions",
|
|
467
|
-
"dynamic",
|
|
468
|
-
index
|
|
469
|
-
]]),
|
|
470
|
-
...value.instructions.static.map((entry, index) => [entry, [
|
|
471
|
-
"instructions",
|
|
472
|
-
"static",
|
|
473
|
-
index
|
|
474
|
-
]]),
|
|
475
|
-
...value.memories.map((entry, index) => [entry, ["memories", index]]),
|
|
476
|
-
...value.instrumentation === void 0 ? [] : [[value.instrumentation, ["instrumentation"]]],
|
|
477
|
-
...value.remoteAgents.entries.map((entry, index) => [entry, [
|
|
478
|
-
"remoteAgents",
|
|
479
|
-
"entries",
|
|
480
|
-
index
|
|
481
|
-
]]),
|
|
482
|
-
...value.schedules.map((entry, index) => [entry, ["schedules", index]]),
|
|
483
|
-
...value.skills.dynamic.map((entry, index) => [entry, [
|
|
484
|
-
"skills",
|
|
485
|
-
"dynamic",
|
|
486
|
-
index
|
|
487
|
-
]]),
|
|
488
|
-
...value.skills.static.map((entry, index) => [entry, [
|
|
489
|
-
"skills",
|
|
490
|
-
"static",
|
|
491
|
-
index
|
|
492
|
-
]]),
|
|
493
|
-
...value.subagents.local.flatMap((entry, index) => entry.configResolver === void 0 ? [] : [[entry.configResolver, [
|
|
494
|
-
"subagents",
|
|
495
|
-
"local",
|
|
496
|
-
index,
|
|
497
|
-
"configResolver"
|
|
498
|
-
]]]),
|
|
499
|
-
...value.tools.dynamic.map((entry, index) => [entry, [
|
|
500
|
-
"tools",
|
|
501
|
-
"dynamic",
|
|
502
|
-
index
|
|
503
|
-
]]),
|
|
504
|
-
...value.tools.static.map((entry, index) => [entry, [
|
|
505
|
-
"tools",
|
|
506
|
-
"static",
|
|
507
|
-
index
|
|
508
|
-
]]),
|
|
509
|
-
[value.sandbox, ["sandbox"]]
|
|
510
|
-
];
|
|
511
|
-
for (const [entry, path] of boundSources) {
|
|
512
|
-
if (entry.sourceKind === "module" && entry.binding === void 0) {
|
|
513
|
-
context.addIssue({
|
|
514
|
-
code: "custom",
|
|
515
|
-
message: "Module source is missing its compiled binding.",
|
|
516
|
-
path: [...path, "binding"]
|
|
517
|
-
});
|
|
518
|
-
continue;
|
|
519
|
-
}
|
|
520
|
-
if (entry.sourceKind !== "module" && entry.binding !== void 0) {
|
|
521
|
-
context.addIssue({
|
|
522
|
-
code: "custom",
|
|
523
|
-
message: `${entry.sourceKind} source cannot carry a module binding.`,
|
|
524
|
-
path: [...path, "binding"]
|
|
525
|
-
});
|
|
526
|
-
continue;
|
|
527
|
-
}
|
|
528
|
-
if (entry.binding === void 0) continue;
|
|
529
|
-
if (entry.binding.logicalPath !== entry.logicalPath) context.addIssue({
|
|
530
|
-
code: "custom",
|
|
531
|
-
message: "Source and binding logical paths do not match.",
|
|
532
|
-
path: [
|
|
533
|
-
...path,
|
|
534
|
-
"binding",
|
|
535
|
-
"logicalPath"
|
|
536
|
-
]
|
|
537
|
-
});
|
|
538
|
-
if (JSON.stringify(entry.binding.owner) !== JSON.stringify(entry.owner)) context.addIssue({
|
|
539
|
-
code: "custom",
|
|
540
|
-
message: "Source and binding owners do not match.",
|
|
541
|
-
path: [
|
|
542
|
-
...path,
|
|
543
|
-
"binding",
|
|
544
|
-
"owner"
|
|
545
|
-
]
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
function normalizeRoutePattern(path) {
|
|
550
|
-
return path.replace(/^\/+|\/+$/g, "").split("/").map((segment) => segment.startsWith(":") || /^\[[^\]]+\]$/.test(segment) ? ":" : segment).join("/");
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
//#endregion
|
|
554
|
-
//#region src/shared/guards.ts
|
|
555
|
-
function isObject(value) {
|
|
556
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
//#endregion
|
|
560
|
-
//#region src/client/client-error.ts
|
|
561
|
-
var ClientError = class extends Error {
|
|
562
|
-
code;
|
|
563
|
-
status;
|
|
564
|
-
body;
|
|
565
|
-
headers;
|
|
566
|
-
constructor(status, body, headers) {
|
|
567
|
-
const normalizedHeaders = Object.freeze(Object.fromEntries(new Headers(headers).entries()));
|
|
568
|
-
const contentType = normalizedHeaders["content-type"]?.toLowerCase();
|
|
569
|
-
const parsed = parseJsonObject$1(body);
|
|
570
|
-
let message = body || `Server returned ${status}.`;
|
|
571
|
-
if (typeof parsed?.error === "string") message = parsed.error;
|
|
572
|
-
else if (parsed === void 0 && contentType?.includes("text/html")) message = `Server returned ${status} with an HTML response. Check the eve route and development server configuration.`;
|
|
573
|
-
super(message);
|
|
574
|
-
this.name = "ClientError";
|
|
575
|
-
this.code = typeof parsed?.code === "string" ? parsed.code : void 0;
|
|
576
|
-
this.status = status;
|
|
577
|
-
this.body = body;
|
|
578
|
-
this.headers = normalizedHeaders;
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
var ClientSessionStrandedError = class extends ClientError {
|
|
582
|
-
eveVersion;
|
|
583
|
-
constructor(status, body, headers, details) {
|
|
584
|
-
super(status, body, headers);
|
|
585
|
-
this.name = "ClientSessionStrandedError";
|
|
586
|
-
this.eveVersion = details.eveVersion;
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
|
-
function createClientError(status, body, headers) {
|
|
590
|
-
const parsed = status === 409 ? parseJsonObject$1(body) : void 0;
|
|
591
|
-
if (parsed?.code !== "session_stranded") return new ClientError(status, body, headers);
|
|
592
|
-
return new ClientSessionStrandedError(status, body, headers, { eveVersion: typeof parsed.eveVersion === "string" ? parsed.eveVersion : void 0 });
|
|
593
|
-
}
|
|
594
|
-
function parseJsonObject$1(body) {
|
|
595
|
-
try {
|
|
596
|
-
const parsed = JSON.parse(body);
|
|
597
|
-
return isObject(parsed) ? parsed : void 0;
|
|
598
|
-
} catch {
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
//#endregion
|
|
604
|
-
//#region src/internal/attachments/media-metadata.ts
|
|
605
|
-
const PDF_MEDIA_TYPE = "application/pdf";
|
|
606
|
-
const INLINE_IMAGE_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
607
|
-
"image/gif",
|
|
608
|
-
"image/jpeg",
|
|
609
|
-
"image/png",
|
|
610
|
-
"image/webp"
|
|
611
|
-
]);
|
|
612
|
-
const VERIFIABLE_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
613
|
-
...INLINE_IMAGE_MEDIA_TYPES,
|
|
614
|
-
"image/jpg",
|
|
615
|
-
PDF_MEDIA_TYPE
|
|
616
|
-
]);
|
|
617
|
-
|
|
618
|
-
//#endregion
|
|
619
|
-
//#region src/shared/ulid.ts
|
|
620
|
-
const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
621
|
-
const TIME_CHARS = 10;
|
|
622
|
-
const TIME_MAX = 2 ** 48 - 1;
|
|
623
|
-
const RANDOM_BYTES = 10;
|
|
624
|
-
function createUlidFactory() {
|
|
625
|
-
let lastTimeMs = -1;
|
|
626
|
-
const lastRandom = new Uint8Array(RANDOM_BYTES);
|
|
627
|
-
return function createUlidFromFactory() {
|
|
628
|
-
const now = Date.now();
|
|
629
|
-
if (!Number.isInteger(now) || now < 0 || now > TIME_MAX) throw new Error(`Cannot mint a ULID: timestamp must be an integer from 0 to ${TIME_MAX}.`);
|
|
630
|
-
if (now > lastTimeMs) {
|
|
631
|
-
lastTimeMs = now;
|
|
632
|
-
randomFill(lastRandom);
|
|
633
|
-
} else if (!incrementRandom(lastRandom)) {
|
|
634
|
-
if (lastTimeMs === TIME_MAX) throw new Error("Cannot mint a ULID: random component overflowed at the maximum timestamp.");
|
|
635
|
-
lastTimeMs += 1;
|
|
636
|
-
randomFill(lastRandom);
|
|
637
|
-
}
|
|
638
|
-
return `${encodeTime(lastTimeMs)}${encodeRandom(lastRandom)}`;
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
const createUlid = createUlidFactory();
|
|
642
|
-
function randomFill(target) {
|
|
643
|
-
const webCrypto = globalThis.crypto;
|
|
644
|
-
if (typeof webCrypto?.getRandomValues !== "function") throw new Error("Cannot mint a ULID: globalThis.crypto.getRandomValues is unavailable.");
|
|
645
|
-
webCrypto.getRandomValues(target);
|
|
646
|
-
}
|
|
647
|
-
function encodeTime(timeMs) {
|
|
648
|
-
let remaining = timeMs;
|
|
649
|
-
let encoded = "";
|
|
650
|
-
for (let index = 0; index < TIME_CHARS; index += 1) {
|
|
651
|
-
encoded = ENCODING[remaining % 32] + encoded;
|
|
652
|
-
remaining = Math.floor(remaining / 32);
|
|
653
|
-
}
|
|
654
|
-
return encoded;
|
|
655
|
-
}
|
|
656
|
-
function encodeRandom(bytes) {
|
|
657
|
-
let buffer = 0;
|
|
658
|
-
let bufferedBits = 0;
|
|
659
|
-
let encoded = "";
|
|
660
|
-
for (const byte of bytes) {
|
|
661
|
-
buffer = buffer << 8 | byte;
|
|
662
|
-
bufferedBits += 8;
|
|
663
|
-
while (bufferedBits >= 5) {
|
|
664
|
-
bufferedBits -= 5;
|
|
665
|
-
encoded += ENCODING[buffer >>> bufferedBits & 31];
|
|
666
|
-
}
|
|
667
|
-
buffer &= (1 << bufferedBits) - 1;
|
|
668
|
-
}
|
|
669
|
-
return encoded;
|
|
670
|
-
}
|
|
671
|
-
function incrementRandom(bytes) {
|
|
672
|
-
for (let index = bytes.length - 1; index >= 0; index -= 1) {
|
|
673
|
-
const byte = bytes[index] ?? 0;
|
|
674
|
-
if (byte < 255) {
|
|
675
|
-
bytes[index] = byte + 1;
|
|
676
|
-
bytes.fill(0, index + 1);
|
|
677
|
-
return true;
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
return false;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
//#endregion
|
|
684
|
-
//#region src/protocol/message.ts
|
|
685
|
-
const EVE_SESSION_ID_HEADER = "x-eve-session-id";
|
|
686
|
-
const EVE_STREAM_TAIL_INDEX_HEADER = "x-eve-stream-tail-index";
|
|
687
|
-
const EVE_STREAM_VERSION_HEADER = "x-eve-stream-version";
|
|
688
|
-
const EVE_STREAM_CONTROL_VERSION_QUERY = "streamControlVersion";
|
|
689
|
-
const EVE_STREAM_LEASE_ENDED_CONTROL = {
|
|
690
|
-
$eve: "stream.lease-ended",
|
|
691
|
-
version: 1
|
|
692
|
-
};
|
|
693
|
-
const textEncoder = new TextEncoder();
|
|
694
|
-
function isCurrentTurnBoundaryEvent(event) {
|
|
695
|
-
return event.type === "session.completed" || event.type === "session.failed" || event.type === "session.waiting";
|
|
696
|
-
}
|
|
697
|
-
function isTurnFailureEvent(event) {
|
|
698
|
-
return event.type === "session.failed" || event.type === "step.failed" || event.type === "turn.failed";
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
//#endregion
|
|
702
|
-
//#region src/protocol/session-projection.ts
|
|
703
|
-
function initialSessionProjection() {
|
|
704
|
-
return {
|
|
705
|
-
authorizations: {},
|
|
706
|
-
calls: {},
|
|
707
|
-
candidates: {},
|
|
708
|
-
inputs: {},
|
|
709
|
-
nextSequence: 0,
|
|
710
|
-
tasks: {},
|
|
711
|
-
turns: {}
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
function updateTurn(state, turnId, update) {
|
|
715
|
-
const turn = state.turns[turnId];
|
|
716
|
-
if (turn === void 0) return state;
|
|
717
|
-
const next = update(turn);
|
|
718
|
-
return next === turn ? state : {
|
|
719
|
-
...state,
|
|
720
|
-
turns: {
|
|
721
|
-
...state.turns,
|
|
722
|
-
[turnId]: next
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
function putTask(state, task) {
|
|
727
|
-
return state.tasks[task.taskId] === task ? state : {
|
|
728
|
-
...state,
|
|
729
|
-
tasks: {
|
|
730
|
-
...state.tasks,
|
|
731
|
-
[task.taskId]: task
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
function putTaskCall(task, call) {
|
|
736
|
-
return task.calls[call.callId] === call ? task : {
|
|
737
|
-
...task,
|
|
738
|
-
calls: {
|
|
739
|
-
...task.calls,
|
|
740
|
-
[call.callId]: call
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
function putCall(state, call) {
|
|
745
|
-
return state.calls[call.callId] === call ? state : {
|
|
746
|
-
...state,
|
|
747
|
-
calls: {
|
|
748
|
-
...state.calls,
|
|
749
|
-
[call.callId]: call
|
|
750
|
-
}
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
function updateTask(state, taskId, update) {
|
|
754
|
-
const task = state.tasks[taskId];
|
|
755
|
-
if (task === void 0) return state;
|
|
756
|
-
return putTask(state, update(task));
|
|
757
|
-
}
|
|
758
|
-
function updateCall(state, callId, update) {
|
|
759
|
-
const call = state.calls[callId];
|
|
760
|
-
if (call === void 0) return state;
|
|
761
|
-
return putCall(state, update(call));
|
|
762
|
-
}
|
|
763
|
-
const SETTLED_CALL_STATUSES = /* @__PURE__ */ new Set([
|
|
764
|
-
"completed",
|
|
765
|
-
"failed",
|
|
766
|
-
"rejected",
|
|
767
|
-
"cancelled"
|
|
768
|
-
]);
|
|
769
|
-
function isSettledCallStatus(status) {
|
|
770
|
-
return SETTLED_CALL_STATUSES.has(status);
|
|
771
|
-
}
|
|
772
|
-
function settleCall(call, status, error) {
|
|
773
|
-
if (call.taskId !== void 0 || isSettledCallStatus(call.status)) return call;
|
|
774
|
-
const { requestId: _requestId, error: _error, ...rest } = call;
|
|
775
|
-
const settled = {
|
|
776
|
-
...rest,
|
|
777
|
-
status
|
|
778
|
-
};
|
|
779
|
-
if (call.requestId !== void 0) settled.requestId = call.requestId;
|
|
780
|
-
if (error !== void 0) settled.error = error;
|
|
781
|
-
return settled;
|
|
782
|
-
}
|
|
783
|
-
function actionName(action) {
|
|
784
|
-
switch (action.kind) {
|
|
785
|
-
case "load-skill": return action.name;
|
|
786
|
-
case "subagent-call":
|
|
787
|
-
case "remote-agent-call": return action.name;
|
|
788
|
-
case "tool-call":
|
|
789
|
-
case "workflow-tool-call": return action.toolName;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
function resultName(result) {
|
|
793
|
-
switch (result.kind) {
|
|
794
|
-
case "load-skill-result": return result.name;
|
|
795
|
-
case "subagent-result": return result.subagentName;
|
|
796
|
-
default: return result.toolName;
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
function callStatusAfterApproval(outcome) {
|
|
800
|
-
switch (outcome) {
|
|
801
|
-
case "approved": return "running";
|
|
802
|
-
case "denied": return "rejected";
|
|
803
|
-
case "cancelled": return "cancelled";
|
|
804
|
-
default: return;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
const TOOL_EXECUTION_DENIED = "TOOL_EXECUTION_DENIED";
|
|
808
|
-
function foldSession(state, event) {
|
|
809
|
-
const typed = event;
|
|
810
|
-
switch (typed.type) {
|
|
811
|
-
case "session.started": return state.started ? state : {
|
|
812
|
-
...state,
|
|
813
|
-
started: true
|
|
814
|
-
};
|
|
815
|
-
case "turn.started": {
|
|
816
|
-
const { sequence, turnId } = typed.data;
|
|
817
|
-
const turn = {
|
|
818
|
-
turnId,
|
|
819
|
-
sequence,
|
|
820
|
-
status: "active"
|
|
821
|
-
};
|
|
822
|
-
return {
|
|
823
|
-
...state,
|
|
824
|
-
activeTurnId: turnId,
|
|
825
|
-
nextSequence: Math.max(state.nextSequence, sequence + 1),
|
|
826
|
-
turns: {
|
|
827
|
-
...state.turns,
|
|
828
|
-
[turnId]: turn
|
|
829
|
-
}
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
case "step.started": return updateTurn(state, typed.data.turnId, (turn) => {
|
|
833
|
-
if (!turn.waiting && turn.stepIndex === typed.data.stepIndex) return turn;
|
|
834
|
-
const { waiting: _waiting, ...rest } = turn;
|
|
835
|
-
return {
|
|
836
|
-
...rest,
|
|
837
|
-
stepIndex: typed.data.stepIndex
|
|
838
|
-
};
|
|
839
|
-
});
|
|
840
|
-
case "turn.waiting": return updateTurn(state, typed.data.turnId, (turn) => turn.status === "active" && !turn.waiting ? {
|
|
841
|
-
...turn,
|
|
842
|
-
waiting: true
|
|
843
|
-
} : turn);
|
|
844
|
-
case "message.appended":
|
|
845
|
-
case "message.completed":
|
|
846
|
-
case "result.completed":
|
|
847
|
-
if (!(typed.type === "message.appended" ? typed.data.messageDelta.length > 0 : typed.type === "message.completed" ? (typed.data.message?.length ?? 0) > 0 : true)) return state;
|
|
848
|
-
return updateTurn(state, typed.data.turnId, (turn) => turn.outputStarted ? turn : {
|
|
849
|
-
...turn,
|
|
850
|
-
outputStarted: true
|
|
851
|
-
});
|
|
852
|
-
case "turn.completed":
|
|
853
|
-
case "turn.cancelled":
|
|
854
|
-
case "turn.failed": {
|
|
855
|
-
const { turnId } = typed.data;
|
|
856
|
-
const status = typed.type === "turn.completed" ? "completed" : typed.type === "turn.failed" ? "failed" : "cancelled";
|
|
857
|
-
const { waiting: _waiting, ...rest } = state.turns[turnId] ?? {
|
|
858
|
-
turnId,
|
|
859
|
-
sequence: typed.data.sequence
|
|
860
|
-
};
|
|
861
|
-
return {
|
|
862
|
-
...state,
|
|
863
|
-
activeTurnId: state.activeTurnId === turnId ? void 0 : state.activeTurnId,
|
|
864
|
-
turns: {
|
|
865
|
-
...state.turns,
|
|
866
|
-
[turnId]: {
|
|
867
|
-
...rest,
|
|
868
|
-
status
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
}
|
|
873
|
-
case "context.cleared": return {
|
|
874
|
-
...state,
|
|
875
|
-
calls: Object.fromEntries(Object.entries(state.calls).filter(([, call]) => call.taskId !== void 0))
|
|
876
|
-
};
|
|
877
|
-
case "session.waiting": return state.activeTurnId === void 0 ? state : {
|
|
878
|
-
...state,
|
|
879
|
-
activeTurnId: void 0
|
|
880
|
-
};
|
|
881
|
-
case "session.completed":
|
|
882
|
-
case "session.failed": {
|
|
883
|
-
const { activeTurnId: _activeTurnId, ...rest } = state;
|
|
884
|
-
return {
|
|
885
|
-
...rest,
|
|
886
|
-
ended: true
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
case "actions.requested": {
|
|
890
|
-
let calls;
|
|
891
|
-
for (const action of typed.data.actions) {
|
|
892
|
-
if (state.calls[action.callId] !== void 0) continue;
|
|
893
|
-
calls ??= { ...state.calls };
|
|
894
|
-
calls[action.callId] = {
|
|
895
|
-
callId: action.callId,
|
|
896
|
-
name: actionName(action),
|
|
897
|
-
turnId: typed.data.turnId,
|
|
898
|
-
stepIndex: typed.data.stepIndex,
|
|
899
|
-
status: "running"
|
|
900
|
-
};
|
|
901
|
-
}
|
|
902
|
-
return calls === void 0 ? state : {
|
|
903
|
-
...state,
|
|
904
|
-
calls
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
case "action.result": {
|
|
908
|
-
const { result, status, error } = typed.data;
|
|
909
|
-
const call = state.calls[result.callId];
|
|
910
|
-
if (call?.taskId !== void 0) return state;
|
|
911
|
-
const settled = status === "rejected" || error?.code === TOOL_EXECUTION_DENIED ? "rejected" : status === "failed" || result.isError === true ? "failed" : "completed";
|
|
912
|
-
if (call === void 0) {
|
|
913
|
-
const unannounced = {
|
|
914
|
-
callId: result.callId,
|
|
915
|
-
name: resultName(result),
|
|
916
|
-
turnId: typed.data.turnId,
|
|
917
|
-
stepIndex: typed.data.stepIndex,
|
|
918
|
-
status: settled
|
|
919
|
-
};
|
|
920
|
-
if (error !== void 0) unannounced.error = error;
|
|
921
|
-
return putCall(state, unannounced);
|
|
922
|
-
}
|
|
923
|
-
return updateCall(state, result.callId, (current) => settleCall(current, settled, error));
|
|
924
|
-
}
|
|
925
|
-
case "task.started": {
|
|
926
|
-
const { callId, kind, name, taskId, turnId } = typed.data;
|
|
927
|
-
const task = state.tasks[taskId] ?? {
|
|
928
|
-
taskId,
|
|
929
|
-
name,
|
|
930
|
-
kind,
|
|
931
|
-
calls: {}
|
|
932
|
-
};
|
|
933
|
-
let next = state;
|
|
934
|
-
if (task.calls[callId] === void 0) next = putTask(next, putTaskCall(task, {
|
|
935
|
-
callId,
|
|
936
|
-
turnId,
|
|
937
|
-
status: "working"
|
|
938
|
-
}));
|
|
939
|
-
const call = next.calls[callId];
|
|
940
|
-
if (call?.taskId === taskId) return next;
|
|
941
|
-
const linked = {
|
|
942
|
-
callId,
|
|
943
|
-
name: call?.name ?? name,
|
|
944
|
-
stepIndex: call?.stepIndex ?? 0,
|
|
945
|
-
taskId,
|
|
946
|
-
turnId: call?.turnId ?? turnId
|
|
947
|
-
};
|
|
948
|
-
if (call?.requestId !== void 0) linked.requestId = call.requestId;
|
|
949
|
-
return putCall(next, linked);
|
|
950
|
-
}
|
|
951
|
-
case "task.settled": {
|
|
952
|
-
const { callId, error, output, status, taskId } = typed.data;
|
|
953
|
-
return updateTask(state, taskId, (task) => {
|
|
954
|
-
const call = task.calls[callId];
|
|
955
|
-
if (call === void 0 || call.status !== "working") return task;
|
|
956
|
-
const settled = {
|
|
957
|
-
callId,
|
|
958
|
-
turnId: call.turnId,
|
|
959
|
-
status
|
|
960
|
-
};
|
|
961
|
-
return putTaskCall(task, status === "completed" && output !== void 0 ? {
|
|
962
|
-
...settled,
|
|
963
|
-
output
|
|
964
|
-
} : status === "failed" && error !== void 0 ? {
|
|
965
|
-
...settled,
|
|
966
|
-
error
|
|
967
|
-
} : settled);
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
case "input.requested": {
|
|
971
|
-
const inputs = { ...state.inputs };
|
|
972
|
-
let calls;
|
|
973
|
-
for (const request of typed.data.requests) {
|
|
974
|
-
if (inputs[request.requestId] !== void 0) continue;
|
|
975
|
-
const input = {
|
|
976
|
-
request,
|
|
977
|
-
sequence: typed.data.sequence,
|
|
978
|
-
turnId: typed.data.turnId,
|
|
979
|
-
stepIndex: typed.data.stepIndex,
|
|
980
|
-
status: "open"
|
|
981
|
-
};
|
|
982
|
-
if (typed.data.taskId !== void 0) input.taskId = typed.data.taskId;
|
|
983
|
-
if (typed.data.callId !== void 0) input.callId = typed.data.callId;
|
|
984
|
-
inputs[request.requestId] = input;
|
|
985
|
-
if (request.kind !== "tool-approval" || isRelayed(typed.data)) continue;
|
|
986
|
-
const { callId, toolName } = request.action;
|
|
987
|
-
calls ??= { ...state.calls };
|
|
988
|
-
const call = calls[callId];
|
|
989
|
-
if (call?.taskId !== void 0) continue;
|
|
990
|
-
if (call !== void 0 && isSettledCallStatus(call.status)) continue;
|
|
991
|
-
calls[callId] = {
|
|
992
|
-
...call ?? {
|
|
993
|
-
callId,
|
|
994
|
-
name: toolName,
|
|
995
|
-
turnId: typed.data.turnId,
|
|
996
|
-
stepIndex: typed.data.stepIndex
|
|
997
|
-
},
|
|
998
|
-
requestId: request.requestId,
|
|
999
|
-
status: "awaiting-input"
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
return calls === void 0 ? {
|
|
1003
|
-
...state,
|
|
1004
|
-
inputs
|
|
1005
|
-
} : {
|
|
1006
|
-
...state,
|
|
1007
|
-
calls,
|
|
1008
|
-
inputs
|
|
1009
|
-
};
|
|
1010
|
-
}
|
|
1011
|
-
case "approval.candidate": {
|
|
1012
|
-
const { candidateId, outcome, requestId } = typed.data;
|
|
1013
|
-
state = {
|
|
1014
|
-
...state,
|
|
1015
|
-
candidates: {
|
|
1016
|
-
...state.candidates,
|
|
1017
|
-
[candidateId]: {
|
|
1018
|
-
candidateId,
|
|
1019
|
-
outcome,
|
|
1020
|
-
requestId
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
};
|
|
1024
|
-
const current = state.inputs[typed.data.requestId];
|
|
1025
|
-
if (current === void 0 || current.status === "settled") return state;
|
|
1026
|
-
if (typed.data.outcome === "pending" || current.status === "open") return state;
|
|
1027
|
-
const { response: _response, ...rest } = current;
|
|
1028
|
-
return {
|
|
1029
|
-
...state,
|
|
1030
|
-
inputs: {
|
|
1031
|
-
...state.inputs,
|
|
1032
|
-
[typed.data.requestId]: {
|
|
1033
|
-
...rest,
|
|
1034
|
-
status: "open"
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
case "approval.settled": {
|
|
1040
|
-
const current = state.inputs[typed.data.requestId];
|
|
1041
|
-
if (current === void 0 || current.status === "settled") return state;
|
|
1042
|
-
const outcome = typed.data.outcome === "approved" ? "approved" : "denied";
|
|
1043
|
-
return settleApprovalCall({
|
|
1044
|
-
...state,
|
|
1045
|
-
inputs: {
|
|
1046
|
-
...state.inputs,
|
|
1047
|
-
[typed.data.requestId]: {
|
|
1048
|
-
...current,
|
|
1049
|
-
status: "settled",
|
|
1050
|
-
outcome
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
}, current, outcome);
|
|
1054
|
-
}
|
|
1055
|
-
case "input.resolved": {
|
|
1056
|
-
let next = state;
|
|
1057
|
-
for (const resolution of typed.data.resolutions) {
|
|
1058
|
-
const current = next.inputs[resolution.requestId];
|
|
1059
|
-
if (current === void 0 || current.status === "settled") continue;
|
|
1060
|
-
const response = resolution.response ?? current.response;
|
|
1061
|
-
const settled = {
|
|
1062
|
-
...current,
|
|
1063
|
-
status: "settled",
|
|
1064
|
-
outcome: resolution.outcome
|
|
1065
|
-
};
|
|
1066
|
-
if (response !== void 0) settled.response = response;
|
|
1067
|
-
next = {
|
|
1068
|
-
...next,
|
|
1069
|
-
inputs: {
|
|
1070
|
-
...next.inputs,
|
|
1071
|
-
[resolution.requestId]: settled
|
|
1072
|
-
}
|
|
1073
|
-
};
|
|
1074
|
-
next = settleApprovalCall(next, current, resolution.outcome);
|
|
1075
|
-
}
|
|
1076
|
-
return next;
|
|
1077
|
-
}
|
|
1078
|
-
case "authorization.required": {
|
|
1079
|
-
const attemptId = typed.data.attemptId ?? typed.data.name;
|
|
1080
|
-
const authorization = {
|
|
1081
|
-
attemptId,
|
|
1082
|
-
name: typed.data.name,
|
|
1083
|
-
sequence: typed.data.sequence,
|
|
1084
|
-
turnId: typed.data.turnId,
|
|
1085
|
-
stepIndex: typed.data.stepIndex,
|
|
1086
|
-
status: "required"
|
|
1087
|
-
};
|
|
1088
|
-
if (typed.data.taskId !== void 0) authorization.taskId = typed.data.taskId;
|
|
1089
|
-
if (typed.data.principalId !== void 0) authorization.principalId = typed.data.principalId;
|
|
1090
|
-
if (typed.data.candidateId !== void 0) authorization.candidateId = typed.data.candidateId;
|
|
1091
|
-
if (typed.data.grant !== void 0) authorization.grant = typed.data.grant;
|
|
1092
|
-
if (typed.data.principal !== void 0) authorization.principal = typed.data.principal;
|
|
1093
|
-
if (typed.data.webhookUrl !== void 0) authorization.awaitsCallback = true;
|
|
1094
|
-
return {
|
|
1095
|
-
...state,
|
|
1096
|
-
authorizations: {
|
|
1097
|
-
...state.authorizations,
|
|
1098
|
-
[attemptId]: authorization
|
|
1099
|
-
}
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
|
-
case "authorization.completed": {
|
|
1103
|
-
const attemptId = typed.data.attemptId ?? typed.data.name;
|
|
1104
|
-
const completed = {
|
|
1105
|
-
...state.authorizations[attemptId] ?? {
|
|
1106
|
-
attemptId,
|
|
1107
|
-
name: typed.data.name,
|
|
1108
|
-
sequence: typed.data.sequence,
|
|
1109
|
-
turnId: typed.data.turnId,
|
|
1110
|
-
stepIndex: typed.data.stepIndex
|
|
1111
|
-
},
|
|
1112
|
-
status: typed.data.outcome
|
|
1113
|
-
};
|
|
1114
|
-
if (typed.data.grant !== void 0) completed.grant = typed.data.grant;
|
|
1115
|
-
if (typed.data.principal !== void 0) completed.principal = typed.data.principal;
|
|
1116
|
-
if (typed.data.retryable !== void 0) completed.retryable = typed.data.retryable;
|
|
1117
|
-
if (typed.data.reason !== void 0) completed.reason = typed.data.reason;
|
|
1118
|
-
return {
|
|
1119
|
-
...state,
|
|
1120
|
-
authorizations: {
|
|
1121
|
-
...state.authorizations,
|
|
1122
|
-
[attemptId]: completed
|
|
1123
|
-
}
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1126
|
-
default: return state;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
function isRelayed(request) {
|
|
1130
|
-
return request.callId !== void 0 || request.taskId !== void 0;
|
|
1131
|
-
}
|
|
1132
|
-
function settleApprovalCall(state, input, outcome) {
|
|
1133
|
-
if (input.request.kind !== "tool-approval" || isRelayed(input)) return state;
|
|
1134
|
-
const status = callStatusAfterApproval(outcome);
|
|
1135
|
-
if (status === void 0) return state;
|
|
1136
|
-
return updateCall(state, input.request.action.callId, (call) => {
|
|
1137
|
-
if (call.status !== "awaiting-input" || call.requestId !== input.request.requestId) return call;
|
|
1138
|
-
return status === "running" ? {
|
|
1139
|
-
...call,
|
|
1140
|
-
status
|
|
1141
|
-
} : settleCall(call, status);
|
|
1142
|
-
});
|
|
1143
|
-
}
|
|
1144
|
-
function openInputs(state) {
|
|
1145
|
-
return Object.values(state.inputs).filter((input) => input.status !== "settled");
|
|
1146
|
-
}
|
|
1147
|
-
function openSignIns(state) {
|
|
1148
|
-
return Object.values(state.authorizations).filter((attempt) => attempt.status === "required");
|
|
1149
|
-
}
|
|
1150
|
-
function callStatus(state, callId, options = {}) {
|
|
1151
|
-
const call = state.calls[callId];
|
|
1152
|
-
if (call === void 0) return void 0;
|
|
1153
|
-
const status = reportedCallStatus(state, call);
|
|
1154
|
-
if (status !== "running" || call.taskId !== void 0) return status;
|
|
1155
|
-
const turn = state.turns[call.turnId];
|
|
1156
|
-
if (options.streaming === false || turn !== void 0 && turn.status !== "active") return "interrupted";
|
|
1157
|
-
return status;
|
|
1158
|
-
}
|
|
1159
|
-
function reportedCallStatus(state, call) {
|
|
1160
|
-
if (call.taskId === void 0) return call.status;
|
|
1161
|
-
const status = state.tasks[call.taskId]?.calls[call.callId]?.status;
|
|
1162
|
-
return status === void 0 || status === "working" ? "running" : status;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
//#endregion
|
|
1166
|
-
//#region src/client/session-utils.ts
|
|
1167
|
-
function summarizeTurnEvents(events) {
|
|
1168
|
-
const segment = new TurnSegment();
|
|
1169
|
-
let boundary;
|
|
1170
|
-
let failure;
|
|
1171
|
-
let message;
|
|
1172
|
-
for (const event of events) {
|
|
1173
|
-
if (segment.observe(event)) boundary = event;
|
|
1174
|
-
if (isTurnFailureEvent(event)) failure = event;
|
|
1175
|
-
if (isFinalMessageCompleted(event)) message = event.data.message ?? void 0;
|
|
1176
|
-
}
|
|
1177
|
-
return {
|
|
1178
|
-
boundary,
|
|
1179
|
-
failure,
|
|
1180
|
-
inputRequests: segment.inputRequests,
|
|
1181
|
-
message,
|
|
1182
|
-
pendingAuthorizations: segment.pendingAuthorizations,
|
|
1183
|
-
status: summarizeBoundaryStatus(boundary)
|
|
1184
|
-
};
|
|
1185
|
-
}
|
|
1186
|
-
function summarizeBoundaryStatus(boundary) {
|
|
1187
|
-
if (boundary?.type === "session.waiting" || boundary?.type === "turn.waiting") return "waiting";
|
|
1188
|
-
if (boundary?.type === "session.failed") return "failed";
|
|
1189
|
-
return "completed";
|
|
1190
|
-
}
|
|
1191
|
-
function endsTurnSegment(event, open) {
|
|
1192
|
-
if (event.type === "turn.waiting") return open.requests || event.data.on === "input" && !open.callbacks;
|
|
1193
|
-
return isCurrentTurnBoundaryEvent(event) && (event.type !== "session.waiting" || !open.callbacks);
|
|
1194
|
-
}
|
|
1195
|
-
var TurnSegment = class {
|
|
1196
|
-
#projection = initialSessionProjection();
|
|
1197
|
-
#authorizations = /* @__PURE__ */ new Map();
|
|
1198
|
-
#followCallbacks;
|
|
1199
|
-
constructor(options = {}) {
|
|
1200
|
-
this.#followCallbacks = options.followCallbacks === true;
|
|
1201
|
-
}
|
|
1202
|
-
get inputRequests() {
|
|
1203
|
-
return openInputs(this.#projection).map((input) => input.request);
|
|
1204
|
-
}
|
|
1205
|
-
get pendingAuthorizations() {
|
|
1206
|
-
return openSignIns(this.#projection).flatMap((attempt) => this.#authorizations.get(attempt.attemptId) ?? []);
|
|
1207
|
-
}
|
|
1208
|
-
observe(event) {
|
|
1209
|
-
this.#projection = foldSession(this.#projection, event);
|
|
1210
|
-
if (event.type === "authorization.required") this.#authorizations.set(event.data.attemptId ?? event.data.name, event.data);
|
|
1211
|
-
return endsTurnSegment(event, {
|
|
1212
|
-
callbacks: this.#followCallbacks && openSignIns(this.#projection).some((attempt) => attempt.awaitsCallback === true),
|
|
1213
|
-
requests: openInputs(this.#projection).length > 0
|
|
1214
|
-
});
|
|
1215
|
-
}
|
|
1216
|
-
};
|
|
1217
|
-
function isFinalMessageCompleted(event) {
|
|
1218
|
-
return event.type === "message.completed" && event.data.finishReason !== "tool-calls";
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
//#endregion
|
|
1222
|
-
//#region src/protocol/message-version.ts
|
|
1223
|
-
function normalizeMessageStreamEvent(version, event) {
|
|
1224
|
-
return nameSkillLoads(normalizeAppendEvent(version, event));
|
|
1225
|
-
}
|
|
1226
|
-
function normalizeAppendEvent(version, event) {
|
|
1227
|
-
switch (version) {
|
|
1228
|
-
case "21":
|
|
1229
|
-
case "22":
|
|
1230
|
-
case "23":
|
|
1231
|
-
case "24": return normalizeLegacyMessageStreamEvent(version, event);
|
|
1232
|
-
case "25":
|
|
1233
|
-
case "26": return validateDeltaMessageStreamEvent(version, event);
|
|
1234
|
-
default: return assertNever(version);
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
function normalizeLegacyMessageStreamEvent(version, event) {
|
|
1238
|
-
if (event.type === "message.appended") {
|
|
1239
|
-
assertLegacyAppendSnapshot(event.data.messageSoFar, event.data.messageDelta, "message", version);
|
|
1240
|
-
return {
|
|
1241
|
-
data: {
|
|
1242
|
-
messageDelta: event.data.messageDelta,
|
|
1243
|
-
sequence: event.data.sequence,
|
|
1244
|
-
stepIndex: event.data.stepIndex,
|
|
1245
|
-
turnId: event.data.turnId
|
|
1246
|
-
},
|
|
1247
|
-
meta: event.meta,
|
|
1248
|
-
type: "message.appended"
|
|
1249
|
-
};
|
|
1250
|
-
}
|
|
1251
|
-
if (event.type === "reasoning.appended") {
|
|
1252
|
-
assertLegacyAppendSnapshot(event.data.reasoningSoFar, event.data.reasoningDelta, "reasoning", version);
|
|
1253
|
-
return {
|
|
1254
|
-
data: {
|
|
1255
|
-
reasoningDelta: event.data.reasoningDelta,
|
|
1256
|
-
sequence: event.data.sequence,
|
|
1257
|
-
stepIndex: event.data.stepIndex,
|
|
1258
|
-
turnId: event.data.turnId
|
|
1259
|
-
},
|
|
1260
|
-
meta: event.meta,
|
|
1261
|
-
type: "reasoning.appended"
|
|
1262
|
-
};
|
|
1263
|
-
}
|
|
1264
|
-
if (event.type === "action.input.appended") {
|
|
1265
|
-
if (version !== void 0 && version !== "24") throw new TypeError(`Invalid action input append for stream version ${version}.`);
|
|
1266
|
-
assertLegacyActionInputOffset(event.data.inputTextOffset, version);
|
|
1267
|
-
return {
|
|
1268
|
-
data: {
|
|
1269
|
-
callId: event.data.callId,
|
|
1270
|
-
inputTextDelta: event.data.inputTextDelta,
|
|
1271
|
-
sequence: event.data.sequence,
|
|
1272
|
-
stepIndex: event.data.stepIndex,
|
|
1273
|
-
toolName: event.data.toolName,
|
|
1274
|
-
turnId: event.data.turnId
|
|
1275
|
-
},
|
|
1276
|
-
meta: event.meta,
|
|
1277
|
-
type: "action.input.appended"
|
|
1278
|
-
};
|
|
1279
|
-
}
|
|
1280
|
-
return event;
|
|
1281
|
-
}
|
|
1282
|
-
function nameSkillLoads(event) {
|
|
1283
|
-
if (event.type !== "actions.requested" || !event.data.actions.some(isUnnamedSkillLoad)) return event;
|
|
1284
|
-
return {
|
|
1285
|
-
...event,
|
|
1286
|
-
data: {
|
|
1287
|
-
...event.data,
|
|
1288
|
-
actions: event.data.actions.map((action) => isUnnamedSkillLoad(action) ? {
|
|
1289
|
-
...action,
|
|
1290
|
-
name: releasedSkillName(action)
|
|
1291
|
-
} : action)
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
|
-
}
|
|
1295
|
-
function isUnnamedSkillLoad(action) {
|
|
1296
|
-
return action.kind === "load-skill" && typeof Reflect.get(action, "name") !== "string";
|
|
1297
|
-
}
|
|
1298
|
-
function releasedSkillName(action) {
|
|
1299
|
-
const skill = action.input.skill;
|
|
1300
|
-
return typeof skill === "string" ? skill : "load_skill";
|
|
1301
|
-
}
|
|
1302
|
-
function validateDeltaMessageStreamEvent(version, event) {
|
|
1303
|
-
if (event.type === "message.appended") {
|
|
1304
|
-
assertAppendDelta(event.data.messageDelta, "message", version);
|
|
1305
|
-
assertUnsupportedAppendField(event.data, "messageOffset", "message", version);
|
|
1306
|
-
assertUnsupportedAppendField(event.data, "messageSoFar", "message", version);
|
|
1307
|
-
} else if (event.type === "reasoning.appended") {
|
|
1308
|
-
assertAppendDelta(event.data.reasoningDelta, "reasoning", version);
|
|
1309
|
-
assertUnsupportedAppendField(event.data, "reasoningOffset", "reasoning", version);
|
|
1310
|
-
assertUnsupportedAppendField(event.data, "reasoningSoFar", "reasoning", version);
|
|
1311
|
-
} else if (event.type === "action.input.appended") {
|
|
1312
|
-
assertAppendDelta(event.data.inputTextDelta, "action input", version);
|
|
1313
|
-
assertUnsupportedAppendField(event.data, "inputTextOffset", "action input", version);
|
|
1314
|
-
}
|
|
1315
|
-
return event;
|
|
1316
|
-
}
|
|
1317
|
-
function assertAppendDelta(delta, stream, version) {
|
|
1318
|
-
if (typeof delta !== "string") throw new TypeError(`Invalid ${stream} append delta for stream version ${version}.`);
|
|
1319
|
-
}
|
|
1320
|
-
function assertUnsupportedAppendField(data, field, stream, version) {
|
|
1321
|
-
if (field in data) throw new TypeError(`Invalid ${stream} append shape for stream version ${version}.`);
|
|
1322
|
-
}
|
|
1323
|
-
function assertNever(value) {
|
|
1324
|
-
throw new TypeError(`Unsupported message stream version: ${String(value)}.`);
|
|
1325
|
-
}
|
|
1326
|
-
function assertLegacyActionInputOffset(offset, version) {
|
|
1327
|
-
if (!Number.isSafeInteger(offset) || offset < 0) {
|
|
1328
|
-
const source = version === void 0 ? "persisted stream" : `stream version ${version}`;
|
|
1329
|
-
throw new TypeError(`Invalid action input append offset for ${source}.`);
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
function assertLegacyAppendSnapshot(snapshot, delta, stream, version) {
|
|
1333
|
-
const offset = snapshot.length - delta.length;
|
|
1334
|
-
if (offset < 0 || snapshot.slice(offset) !== delta) {
|
|
1335
|
-
const source = version === void 0 ? "persisted stream" : `stream version ${version}`;
|
|
1336
|
-
throw new TypeError(`Invalid cumulative ${stream} append for ${source}.`);
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
//#endregion
|
|
1341
|
-
//#region src/client/ndjson.ts
|
|
1342
|
-
function isStreamDisconnectError(error) {
|
|
1343
|
-
if (error instanceof DOMException) return error.name === "AbortError";
|
|
1344
|
-
if (!(error instanceof Error)) return false;
|
|
1345
|
-
const errorCode = "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
1346
|
-
return error.name === "AbortError" || error.message === "terminated" || errorCode === "UND_ERR_SOCKET" || error instanceof TypeError && /^(?:failed to fetch|fetch failed|load failed|networkerror when attempting to fetch resource\.)$/i.test(error.message) || /abort|cancel|disconnect|premature close|socket|terminated/i.test(error.message);
|
|
1347
|
-
}
|
|
1348
|
-
async function* readNdjsonStream(body, options) {
|
|
1349
|
-
const reader = body.getReader();
|
|
1350
|
-
const decoder = new TextDecoder();
|
|
1351
|
-
let buffer = "";
|
|
1352
|
-
let reachedEof = false;
|
|
1353
|
-
const abort = () => {
|
|
1354
|
-
reader.cancel().catch(() => {});
|
|
1355
|
-
};
|
|
1356
|
-
options.signal?.addEventListener("abort", abort, { once: true });
|
|
1357
|
-
try {
|
|
1358
|
-
while (true) {
|
|
1359
|
-
throwIfAborted(options.signal);
|
|
1360
|
-
const result = await readWithIdleTimeout(reader, options?.idleTimeoutMs);
|
|
1361
|
-
throwIfAborted(options.signal);
|
|
1362
|
-
if (result.done) {
|
|
1363
|
-
reachedEof = true;
|
|
1364
|
-
buffer += decoder.decode();
|
|
1365
|
-
break;
|
|
1366
|
-
}
|
|
1367
|
-
if (result.value) buffer += decoder.decode(result.value, { stream: true });
|
|
1368
|
-
let newlineIndex = buffer.indexOf("\n");
|
|
1369
|
-
while (newlineIndex !== -1) {
|
|
1370
|
-
const line = buffer.slice(0, newlineIndex).trim();
|
|
1371
|
-
buffer = buffer.slice(newlineIndex + 1);
|
|
1372
|
-
if (line.length > 0) {
|
|
1373
|
-
const value = JSON.parse(line);
|
|
1374
|
-
if (options.controlVersion === "1" && isLeaseEndedControl(value)) options.onLeaseEnded?.();
|
|
1375
|
-
else yield parseMessageStreamEvent(value, options.streamVersion);
|
|
1376
|
-
}
|
|
1377
|
-
newlineIndex = buffer.indexOf("\n");
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
const trailing = buffer.trim();
|
|
1381
|
-
if (trailing.length > 0) {
|
|
1382
|
-
const value = JSON.parse(trailing);
|
|
1383
|
-
if (options.controlVersion === "1" && isLeaseEndedControl(value)) options.onLeaseEnded?.();
|
|
1384
|
-
else yield parseMessageStreamEvent(value, options.streamVersion);
|
|
1385
|
-
}
|
|
1386
|
-
} finally {
|
|
1387
|
-
options.signal?.removeEventListener("abort", abort);
|
|
1388
|
-
if (!reachedEof) reader.cancel().catch(() => {});
|
|
1389
|
-
reader.releaseLock();
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
function isLeaseEndedControl(value) {
|
|
1393
|
-
if (value === null || typeof value !== "object") return false;
|
|
1394
|
-
const record = value;
|
|
1395
|
-
return record.$eve === EVE_STREAM_LEASE_ENDED_CONTROL.$eve && record.version === EVE_STREAM_LEASE_ENDED_CONTROL.version;
|
|
1396
|
-
}
|
|
1397
|
-
function parseMessageStreamEvent(value, version) {
|
|
1398
|
-
return normalizeMessageStreamEvent(version, value);
|
|
1399
|
-
}
|
|
1400
|
-
async function readWithIdleTimeout(reader, idleTimeoutMs) {
|
|
1401
|
-
let timeout;
|
|
1402
|
-
try {
|
|
1403
|
-
if (idleTimeoutMs === void 0) return await reader.read();
|
|
1404
|
-
return await Promise.race([reader.read(), new Promise((_resolve, reject) => {
|
|
1405
|
-
timeout = setTimeout(() => reject(new DOMException("Session stream was idle.", "AbortError")), idleTimeoutMs);
|
|
1406
|
-
})]);
|
|
1407
|
-
} catch (error) {
|
|
1408
|
-
if (error instanceof TypeError) throw new Error("Session stream disconnected.", { cause: error });
|
|
1409
|
-
throw error;
|
|
1410
|
-
} finally {
|
|
1411
|
-
if (timeout !== void 0) clearTimeout(timeout);
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
//#endregion
|
|
1416
|
-
//#region src/client/stream-version.ts
|
|
1417
|
-
const supportedMessageStreamVersions = {
|
|
1418
|
-
"21": true,
|
|
1419
|
-
"22": true,
|
|
1420
|
-
"23": true,
|
|
1421
|
-
"24": true,
|
|
1422
|
-
"25": true,
|
|
1423
|
-
"26": true
|
|
1424
|
-
};
|
|
1425
|
-
function readMessageStreamVersion(headers) {
|
|
1426
|
-
const version = headers.get(EVE_STREAM_VERSION_HEADER);
|
|
1427
|
-
if (version !== null && Object.hasOwn(supportedMessageStreamVersions, version)) return version;
|
|
1428
|
-
if (version === null) throw new TypeError(`Missing ${EVE_STREAM_VERSION_HEADER} response header.`);
|
|
1429
|
-
throw new TypeError(`Unsupported message stream version: ${version}.`);
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
//#endregion
|
|
1433
|
-
//#region src/shared/eve-route-path.ts
|
|
1434
|
-
const EVE_NAMED_AGENT_MOUNT_PATTERN = /^\/eve\/[a-z0-9][a-z0-9_-]*$/;
|
|
1435
|
-
const EVE_NAMED_AGENT_PROTOCOL_PATTERN = /^\/eve\/[a-z0-9][a-z0-9_-]*\/v1$/;
|
|
1436
|
-
function joinEveRoutePath(basePath, routePath) {
|
|
1437
|
-
const base = trimTrailingSlash$1(basePath);
|
|
1438
|
-
const route = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
1439
|
-
if (route === "/eve/v1" || route.startsWith(`${"/eve/v1"}/`)) {
|
|
1440
|
-
if (EVE_NAMED_AGENT_MOUNT_PATTERN.test(base)) return `${base}${route.slice(4)}`;
|
|
1441
|
-
if (EVE_NAMED_AGENT_PROTOCOL_PATTERN.test(base)) return `${base}${route.slice(EVE_ROUTE_PREFIX.length)}`;
|
|
1442
|
-
}
|
|
1443
|
-
return `${base}${route}`;
|
|
1444
|
-
}
|
|
1445
|
-
function trimTrailingSlash$1(value) {
|
|
1446
|
-
if (value === "/") return "";
|
|
1447
|
-
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
//#endregion
|
|
1451
|
-
//#region src/client/url.ts
|
|
1452
|
-
function createClientUrl(host, routePath, searchParams) {
|
|
1453
|
-
const queryIndex = routePath.indexOf("?");
|
|
1454
|
-
const pathOnly = queryIndex === -1 ? routePath : routePath.slice(0, queryIndex);
|
|
1455
|
-
const embeddedQuery = queryIndex === -1 ? "" : routePath.slice(queryIndex + 1);
|
|
1456
|
-
const normalizedRoute = pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`;
|
|
1457
|
-
if (isAbsoluteUrl(host)) {
|
|
1458
|
-
const url = new URL(host);
|
|
1459
|
-
const basePath = trimTrailingSlash(url.pathname);
|
|
1460
|
-
url.pathname = joinEveRoutePath(basePath, normalizedRoute);
|
|
1461
|
-
mergeEmbeddedQuery(url.searchParams, embeddedQuery);
|
|
1462
|
-
mergeSearchParams(url.searchParams, searchParams);
|
|
1463
|
-
url.hash = "";
|
|
1464
|
-
return url.toString();
|
|
1465
|
-
}
|
|
1466
|
-
const url = new URL(host, "http://eve.local");
|
|
1467
|
-
const basePath = trimTrailingSlash(url.pathname);
|
|
1468
|
-
mergeEmbeddedQuery(url.searchParams, embeddedQuery);
|
|
1469
|
-
mergeSearchParams(url.searchParams, searchParams);
|
|
1470
|
-
return `${joinEveRoutePath(basePath, normalizedRoute)}${formatSearch(url.searchParams)}`;
|
|
1471
|
-
}
|
|
1472
|
-
function mergeEmbeddedQuery(target, embeddedQuery) {
|
|
1473
|
-
if (embeddedQuery.length === 0) return;
|
|
1474
|
-
for (const [name, value] of new URLSearchParams(embeddedQuery)) target.append(name, value);
|
|
1475
|
-
}
|
|
1476
|
-
function isAbsoluteUrl(value) {
|
|
1477
|
-
return /^[a-z][a-z\d+\-.]*:/i.test(value);
|
|
1478
|
-
}
|
|
1479
|
-
function trimTrailingSlash(value) {
|
|
1480
|
-
if (value === "/") return "";
|
|
1481
|
-
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
1482
|
-
}
|
|
1483
|
-
function mergeSearchParams(target, searchParams) {
|
|
1484
|
-
if (searchParams === void 0) return;
|
|
1485
|
-
for (const [name, value] of Object.entries(searchParams)) target.set(name, value);
|
|
1486
|
-
}
|
|
1487
|
-
function formatSearch(searchParams) {
|
|
1488
|
-
const value = searchParams.toString();
|
|
1489
|
-
return value.length === 0 ? "" : `?${value}`;
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
//#endregion
|
|
1493
|
-
//#region src/client/open-stream.ts
|
|
1494
|
-
const DEFAULT_STREAM_READ_IDLE_TIMEOUT_MS = 15e3;
|
|
1495
|
-
const DEFAULT_STREAM_RECONNECT_POLICY = {
|
|
1496
|
-
retryableErrorStatuses: /* @__PURE__ */ new Set([
|
|
1497
|
-
404,
|
|
1498
|
-
409,
|
|
1499
|
-
425,
|
|
1500
|
-
500,
|
|
1501
|
-
502,
|
|
1502
|
-
503,
|
|
1503
|
-
504
|
|
1504
|
-
]),
|
|
1505
|
-
streamIdleReconnectPolicy: {
|
|
1506
|
-
baseDelayMs: 250,
|
|
1507
|
-
maxAttempts: 5,
|
|
1508
|
-
maxDelayMs: 4e3
|
|
1509
|
-
},
|
|
1510
|
-
streamOpenReconnectPolicy: {
|
|
1511
|
-
baseDelayMs: 250,
|
|
1512
|
-
maxAttempts: 12,
|
|
1513
|
-
maxDelayMs: 5e3
|
|
1514
|
-
}
|
|
1515
|
-
};
|
|
1516
|
-
const NO_STREAM_RECONNECT_POLICY = {
|
|
1517
|
-
...DEFAULT_STREAM_RECONNECT_POLICY,
|
|
1518
|
-
streamIdleReconnectPolicy: {
|
|
1519
|
-
...DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy,
|
|
1520
|
-
maxAttempts: 0
|
|
1521
|
-
},
|
|
1522
|
-
streamOpenReconnectPolicy: {
|
|
1523
|
-
...DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy,
|
|
1524
|
-
maxAttempts: 1
|
|
1525
|
-
}
|
|
1526
|
-
};
|
|
1527
|
-
function resolveRetryPolicy(policy, defaults) {
|
|
1528
|
-
return {
|
|
1529
|
-
...defaults,
|
|
1530
|
-
...policy
|
|
1531
|
-
};
|
|
1532
|
-
}
|
|
1533
|
-
function resolveStreamReconnectPolicy(policy, keepAlive = false) {
|
|
1534
|
-
if (policy && "reconnect" in policy && policy.reconnect === false) return NO_STREAM_RECONNECT_POLICY;
|
|
1535
|
-
const configured = policy;
|
|
1536
|
-
return {
|
|
1537
|
-
retryableErrorStatuses: configured?.retryableErrorStatuses ? new Set(configured.retryableErrorStatuses) : DEFAULT_STREAM_RECONNECT_POLICY.retryableErrorStatuses,
|
|
1538
|
-
streamIdleReconnectPolicy: resolveRetryPolicy(configured?.streamIdleReconnectPolicy, {
|
|
1539
|
-
...DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy,
|
|
1540
|
-
maxAttempts: keepAlive ? Infinity : DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy.maxAttempts
|
|
1541
|
-
}),
|
|
1542
|
-
streamOpenReconnectPolicy: resolveRetryPolicy(configured?.streamOpenReconnectPolicy, DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy)
|
|
1543
|
-
};
|
|
1544
|
-
}
|
|
1545
|
-
async function* followStreamIterable(input) {
|
|
1546
|
-
if (input.follow === false && input.startIndex < 0) throw new Error("stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.");
|
|
1547
|
-
const resolvePolicy = () => resolveStreamReconnectPolicy(input.resolveReconnectPolicy === void 0 ? input.streamReconnectPolicy : input.resolveReconnectPolicy(), input.keepAlive);
|
|
1548
|
-
let retryPolicy = resolvePolicy();
|
|
1549
|
-
let idleRetryPolicy = retryPolicy.streamIdleReconnectPolicy;
|
|
1550
|
-
let startIndex = input.startIndex;
|
|
1551
|
-
let reconnectDelayMs = idleRetryPolicy.baseDelayMs;
|
|
1552
|
-
let idleReconnects = 0;
|
|
1553
|
-
let initialConnection = true;
|
|
1554
|
-
let tailIndex;
|
|
1555
|
-
let caughtUp = false;
|
|
1556
|
-
while (true) {
|
|
1557
|
-
retryPolicy = resolvePolicy();
|
|
1558
|
-
idleRetryPolicy = retryPolicy.streamIdleReconnectPolicy;
|
|
1559
|
-
let connection;
|
|
1560
|
-
try {
|
|
1561
|
-
connection = await openStreamBody({
|
|
1562
|
-
...input,
|
|
1563
|
-
retryPolicy,
|
|
1564
|
-
startIndex,
|
|
1565
|
-
requestTailIndex: (input.follow === false || input.onCaughtUp !== void 0) && tailIndex === void 0
|
|
1566
|
-
});
|
|
1567
|
-
} catch (error) {
|
|
1568
|
-
if (input.signal?.aborted) return;
|
|
1569
|
-
throw error;
|
|
1570
|
-
}
|
|
1571
|
-
if ((input.follow === false || input.onCaughtUp !== void 0) && tailIndex === void 0) {
|
|
1572
|
-
tailIndex = connection.tailIndex;
|
|
1573
|
-
if (tailIndex === void 0) {
|
|
1574
|
-
connection.close();
|
|
1575
|
-
throw new Error(`stream({ follow: false }) requires the server to report the ${EVE_STREAM_TAIL_INDEX_HEADER} header. The agent may be running an older eve version.`);
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
if (!caughtUp && tailIndex !== void 0 && startIndex > tailIndex) {
|
|
1579
|
-
caughtUp = true;
|
|
1580
|
-
input.onCaughtUp?.();
|
|
1581
|
-
}
|
|
1582
|
-
if (input.follow === false && tailIndex !== void 0 && startIndex > tailIndex) {
|
|
1583
|
-
connection.close();
|
|
1584
|
-
return;
|
|
1585
|
-
}
|
|
1586
|
-
let deliveredEvent = false;
|
|
1587
|
-
let leaseEnded = false;
|
|
1588
|
-
try {
|
|
1589
|
-
for await (const event of readNdjsonStream(connection.body, {
|
|
1590
|
-
signal: input.signal,
|
|
1591
|
-
controlVersion: connection.controlVersion,
|
|
1592
|
-
idleTimeoutMs: input.streamReadIdleTimeoutMs ?? DEFAULT_STREAM_READ_IDLE_TIMEOUT_MS,
|
|
1593
|
-
onLeaseEnded: () => {
|
|
1594
|
-
leaseEnded = true;
|
|
1595
|
-
},
|
|
1596
|
-
streamVersion: connection.streamVersion
|
|
1597
|
-
})) {
|
|
1598
|
-
startIndex += 1;
|
|
1599
|
-
deliveredEvent = true;
|
|
1600
|
-
reconnectDelayMs = idleRetryPolicy.baseDelayMs;
|
|
1601
|
-
idleReconnects = 0;
|
|
1602
|
-
yield event;
|
|
1603
|
-
if (!caughtUp && tailIndex !== void 0 && startIndex > tailIndex) {
|
|
1604
|
-
caughtUp = true;
|
|
1605
|
-
input.onCaughtUp?.();
|
|
1606
|
-
}
|
|
1607
|
-
if (event.type === "session.failed" || event.type === "session.completed") return;
|
|
1608
|
-
if (input.follow === false && tailIndex !== void 0 && startIndex > tailIndex) return;
|
|
1609
|
-
}
|
|
1610
|
-
} catch (error) {
|
|
1611
|
-
if (!isStreamDisconnectError(error)) throw error;
|
|
1612
|
-
} finally {
|
|
1613
|
-
connection.close();
|
|
1614
|
-
}
|
|
1615
|
-
idleRetryPolicy = resolvePolicy().streamIdleReconnectPolicy;
|
|
1616
|
-
if (input.signal?.aborted || input.startIndex < 0 || idleRetryPolicy.maxAttempts === 0) return;
|
|
1617
|
-
if (leaseEnded) continue;
|
|
1618
|
-
if (!deliveredEvent && !initialConnection && (idleReconnects += 1) >= idleRetryPolicy.maxAttempts) return;
|
|
1619
|
-
initialConnection = false;
|
|
1620
|
-
await sleep(reconnectDelayMs, input.signal);
|
|
1621
|
-
if (input.signal?.aborted) return;
|
|
1622
|
-
reconnectDelayMs = Math.min(reconnectDelayMs * 2, idleRetryPolicy.maxDelayMs);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
async function openStreamBody(input) {
|
|
1626
|
-
const retryPolicy = input.retryPolicy ?? resolveStreamReconnectPolicy(input.streamReconnectPolicy, input.keepAlive);
|
|
1627
|
-
const openRetryPolicy = retryPolicy.streamOpenReconnectPolicy;
|
|
1628
|
-
let lastStatus;
|
|
1629
|
-
let lastBody;
|
|
1630
|
-
let lastHeaders;
|
|
1631
|
-
let retryDelayMs = openRetryPolicy.baseDelayMs;
|
|
1632
|
-
const controlVersion = input.startIndex >= 0 && retryPolicy.streamIdleReconnectPolicy.maxAttempts > 0 ? "1" : void 0;
|
|
1633
|
-
const searchParams = {};
|
|
1634
|
-
if (controlVersion !== void 0) searchParams[EVE_STREAM_CONTROL_VERSION_QUERY] = controlVersion;
|
|
1635
|
-
if (input.startIndex !== 0) searchParams.startIndex = String(input.startIndex);
|
|
1636
|
-
if (input.requestTailIndex === true) searchParams.includeTailIndex = "1";
|
|
1637
|
-
if (input.follow === false) searchParams.follow = "false";
|
|
1638
|
-
for (let attempt = 0; attempt < openRetryPolicy.maxAttempts; attempt += 1) {
|
|
1639
|
-
throwIfAborted(input.signal);
|
|
1640
|
-
const url = createClientUrl(input.host, input.path, Object.keys(searchParams).length > 0 ? searchParams : void 0);
|
|
1641
|
-
const headers = await input.resolveHeaders();
|
|
1642
|
-
throwIfAborted(input.signal);
|
|
1643
|
-
const connectionController = new AbortController();
|
|
1644
|
-
const signal = input.signal ? AbortSignal.any([input.signal, connectionController.signal]) : connectionController.signal;
|
|
1645
|
-
let response;
|
|
1646
|
-
try {
|
|
1647
|
-
response = await fetch(url, {
|
|
1648
|
-
cache: "no-store",
|
|
1649
|
-
headers,
|
|
1650
|
-
redirect: input.redirect,
|
|
1651
|
-
signal
|
|
1652
|
-
});
|
|
1653
|
-
} catch (error) {
|
|
1654
|
-
if (input.signal?.aborted || !isStreamDisconnectError(error) || attempt === openRetryPolicy.maxAttempts - 1) throw error;
|
|
1655
|
-
await sleep(retryDelayMs, input.signal);
|
|
1656
|
-
retryDelayMs = Math.min(retryDelayMs * 2, openRetryPolicy.maxDelayMs);
|
|
1657
|
-
continue;
|
|
1658
|
-
}
|
|
1659
|
-
if (response.ok) {
|
|
1660
|
-
if (!response.body) throw new ClientError(response.status, "Response body is null.", response.headers);
|
|
1661
|
-
let closed = false;
|
|
1662
|
-
return {
|
|
1663
|
-
body: response.body,
|
|
1664
|
-
close: () => {
|
|
1665
|
-
if (closed) return;
|
|
1666
|
-
closed = true;
|
|
1667
|
-
response.body?.cancel().catch(() => {});
|
|
1668
|
-
connectionController.abort();
|
|
1669
|
-
},
|
|
1670
|
-
controlVersion,
|
|
1671
|
-
streamVersion: readMessageStreamVersion(response.headers),
|
|
1672
|
-
tailIndex: parseTailIndexHeader(response.headers)
|
|
1673
|
-
};
|
|
1674
|
-
}
|
|
1675
|
-
lastStatus = response.status;
|
|
1676
|
-
lastBody = await response.text();
|
|
1677
|
-
lastHeaders = response.headers;
|
|
1678
|
-
const error = createClientError(response.status, lastBody, response.headers);
|
|
1679
|
-
if (error instanceof ClientSessionStrandedError || !retryPolicy.retryableErrorStatuses.has(response.status)) throw error;
|
|
1680
|
-
if (attempt < openRetryPolicy.maxAttempts - 1) {
|
|
1681
|
-
await sleep(retryDelayMs, input.signal);
|
|
1682
|
-
retryDelayMs = Math.min(retryDelayMs * 2, openRetryPolicy.maxDelayMs);
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
throw new ClientError(lastStatus ?? 0, lastBody ?? "Failed to open message stream.", lastHeaders);
|
|
1686
|
-
}
|
|
1687
|
-
function parseTailIndexHeader(headers) {
|
|
1688
|
-
const raw = headers.get(EVE_STREAM_TAIL_INDEX_HEADER);
|
|
1689
|
-
if (raw === null || !/^-?\d+$/.test(raw)) return;
|
|
1690
|
-
const parsed = Number(raw);
|
|
1691
|
-
return Number.isSafeInteger(parsed) ? parsed : void 0;
|
|
1692
|
-
}
|
|
1693
|
-
async function sleep(ms, signal) {
|
|
1694
|
-
if (signal?.aborted) return;
|
|
1695
|
-
await new Promise((resolve) => {
|
|
1696
|
-
const onAbort = () => {
|
|
1697
|
-
clearTimeout(timer);
|
|
1698
|
-
resolve();
|
|
1699
|
-
};
|
|
1700
|
-
const timer = setTimeout(() => {
|
|
1701
|
-
signal?.removeEventListener("abort", onAbort);
|
|
1702
|
-
resolve();
|
|
1703
|
-
}, ms);
|
|
1704
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1705
|
-
});
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
//#endregion
|
|
1709
|
-
//#region src/client/agent-session.ts
|
|
1710
|
-
var ClientAgentSession = class {
|
|
1711
|
-
name;
|
|
1712
|
-
sessionId;
|
|
1713
|
-
taskId;
|
|
1714
|
-
#context;
|
|
1715
|
-
#streamPath;
|
|
1716
|
-
constructor(context, started) {
|
|
1717
|
-
this.#context = context;
|
|
1718
|
-
this.#streamPath = started.data.streamPath;
|
|
1719
|
-
this.name = started.data.name;
|
|
1720
|
-
this.sessionId = started.data.sessionId;
|
|
1721
|
-
this.taskId = started.data.taskId;
|
|
1722
|
-
}
|
|
1723
|
-
stream(options) {
|
|
1724
|
-
const startIndex = options?.startIndex ?? 0;
|
|
1725
|
-
if (options?.follow === false && startIndex < 0) throw new Error("agent(started).stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.");
|
|
1726
|
-
return followStreamIterable({
|
|
1727
|
-
follow: options?.follow,
|
|
1728
|
-
host: this.#context.host,
|
|
1729
|
-
path: this.#streamPath,
|
|
1730
|
-
redirect: this.#context.redirect,
|
|
1731
|
-
resolveHeaders: () => this.#context.resolveHeaders(),
|
|
1732
|
-
signal: options?.signal,
|
|
1733
|
-
startIndex,
|
|
1734
|
-
streamReconnectPolicy: options?.streamReconnectPolicy
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
};
|
|
1738
|
-
|
|
1739
|
-
//#endregion
|
|
1740
|
-
//#region src/client/output-schema.ts
|
|
1741
|
-
function extractCompletedResult(events) {
|
|
1742
|
-
let result;
|
|
1743
|
-
for (const event of events) if (isResultCompletedEvent(event)) result = event.data.result;
|
|
1744
|
-
return result;
|
|
1745
|
-
}
|
|
1746
|
-
function isResultCompletedEvent(event) {
|
|
1747
|
-
return event.type === "result.completed";
|
|
1748
|
-
}
|
|
1749
|
-
|
|
1750
|
-
//#endregion
|
|
1751
|
-
//#region src/client/message-response.ts
|
|
1752
|
-
const consumeResponse = Symbol("consumeMessageResponse");
|
|
1753
|
-
const acceptedDeliveryId = Symbol("acceptedDeliveryId");
|
|
1754
|
-
const sendReceipt = Symbol("sendReceipt");
|
|
1755
|
-
var MessageResponse = class {
|
|
1756
|
-
sessionId;
|
|
1757
|
-
[acceptedDeliveryId];
|
|
1758
|
-
[sendReceipt];
|
|
1759
|
-
#cancelTurn;
|
|
1760
|
-
#cancellation;
|
|
1761
|
-
#consumed = false;
|
|
1762
|
-
#createStream;
|
|
1763
|
-
#resumesTurn;
|
|
1764
|
-
#settled = false;
|
|
1765
|
-
#turnId = Promise.withResolvers();
|
|
1766
|
-
constructor(input) {
|
|
1767
|
-
this.#cancelTurn = input.cancelTurn;
|
|
1768
|
-
this.sessionId = input.sessionId;
|
|
1769
|
-
this[acceptedDeliveryId] = input.deliveryId;
|
|
1770
|
-
this[sendReceipt] = input.receipt;
|
|
1771
|
-
this.#createStream = input.createStream;
|
|
1772
|
-
this.#resumesTurn = input.resumesTurn ?? false;
|
|
1773
|
-
}
|
|
1774
|
-
cancel() {
|
|
1775
|
-
if (this.#settled) return Promise.resolve({ status: "no_active_turn" });
|
|
1776
|
-
if (this.#cancellation !== void 0) return this.#cancellation;
|
|
1777
|
-
const cancellation = this.#turnId.promise.then((turnId) => turnId === void 0 ? { status: "no_active_turn" } : this.#cancelTurn(turnId));
|
|
1778
|
-
this.#cancellation = cancellation;
|
|
1779
|
-
cancellation.catch(() => {
|
|
1780
|
-
if (!this.#settled && this.#cancellation === cancellation) this.#cancellation = void 0;
|
|
1781
|
-
});
|
|
1782
|
-
return cancellation;
|
|
1783
|
-
}
|
|
1784
|
-
async result() {
|
|
1785
|
-
const events = [];
|
|
1786
|
-
for await (const event of this) events.push(event);
|
|
1787
|
-
const summary = summarizeTurnEvents(events);
|
|
1788
|
-
return {
|
|
1789
|
-
data: extractCompletedResult(events),
|
|
1790
|
-
events,
|
|
1791
|
-
inputRequests: summary.inputRequests,
|
|
1792
|
-
message: summary.message,
|
|
1793
|
-
sessionId: this.sessionId,
|
|
1794
|
-
status: summary.status
|
|
1795
|
-
};
|
|
1796
|
-
}
|
|
1797
|
-
[Symbol.asyncIterator]() {
|
|
1798
|
-
return this[consumeResponse]();
|
|
1799
|
-
}
|
|
1800
|
-
[consumeResponse](source) {
|
|
1801
|
-
if (this.#consumed) throw new Error("MessageResponse has already been consumed.");
|
|
1802
|
-
this.#consumed = true;
|
|
1803
|
-
return this.#observeStream(source);
|
|
1804
|
-
}
|
|
1805
|
-
async *#observeStream(source) {
|
|
1806
|
-
try {
|
|
1807
|
-
for await (const event of this.#createStream(source)) {
|
|
1808
|
-
if (event.type === "turn.started" || this.#resumesTurn && event.type === "input.resolved") this.#turnId.resolve(event.data.turnId);
|
|
1809
|
-
else if (isCurrentTurnBoundaryEvent(event)) {
|
|
1810
|
-
this.#settled = true;
|
|
1811
|
-
this.#turnId.resolve(void 0);
|
|
1812
|
-
}
|
|
1813
|
-
yield event;
|
|
1814
|
-
}
|
|
1815
|
-
} finally {
|
|
1816
|
-
this.#turnId.resolve(void 0);
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
};
|
|
1820
|
-
function getMessageResponseDeliveryId(response) {
|
|
1821
|
-
return response[acceptedDeliveryId];
|
|
1822
|
-
}
|
|
1823
|
-
function consumeMessageResponse(response, source) {
|
|
1824
|
-
return response[consumeResponse](source);
|
|
1825
|
-
}
|
|
1826
|
-
|
|
1827
|
-
//#endregion
|
|
1828
|
-
//#region src/protocol/prewarm-session.ts
|
|
1829
|
-
const PrewarmResponseSchema = z.object({
|
|
1830
|
-
ok: z.literal(true),
|
|
1831
|
-
status: z.enum([
|
|
1832
|
-
"ready",
|
|
1833
|
-
"accepted",
|
|
1834
|
-
"unsupported",
|
|
1835
|
-
"no_active_session"
|
|
1836
|
-
])
|
|
1837
|
-
});
|
|
1838
|
-
|
|
1839
|
-
//#endregion
|
|
1840
|
-
//#region src/protocol/cancel-turn.ts
|
|
1841
|
-
const CancelTurnResponseSchema = z.discriminatedUnion("status", [z.strictObject({
|
|
1842
|
-
ok: z.literal(true),
|
|
1843
|
-
sessionId: z.string().min(1),
|
|
1844
|
-
status: z.literal("accepted")
|
|
1845
|
-
}), z.strictObject({
|
|
1846
|
-
ok: z.literal(true),
|
|
1847
|
-
status: z.literal("no_active_turn")
|
|
1848
|
-
})]);
|
|
1849
|
-
|
|
1850
|
-
//#endregion
|
|
1851
|
-
//#region src/protocol/clear-session.ts
|
|
1852
|
-
const ClearResponseSchema = z.discriminatedUnion("status", [z.object({
|
|
1853
|
-
ok: z.literal(true),
|
|
1854
|
-
sessionId: z.string().min(1),
|
|
1855
|
-
status: z.literal("accepted")
|
|
1856
|
-
}), z.object({
|
|
1857
|
-
ok: z.literal(true),
|
|
1858
|
-
status: z.literal("no_active_session")
|
|
1859
|
-
})]);
|
|
1860
|
-
|
|
1861
|
-
//#endregion
|
|
1862
|
-
//#region src/protocol/compact-session.ts
|
|
1863
|
-
const CompactResponseSchema = z.discriminatedUnion("status", [z.object({
|
|
1864
|
-
ok: z.literal(true),
|
|
1865
|
-
sessionId: z.string().min(1),
|
|
1866
|
-
status: z.literal("accepted")
|
|
1867
|
-
}), z.object({
|
|
1868
|
-
ok: z.literal(true),
|
|
1869
|
-
status: z.literal("no_active_session")
|
|
1870
|
-
})]);
|
|
1871
|
-
|
|
1872
|
-
//#endregion
|
|
1873
|
-
//#region src/protocol/reset-session.ts
|
|
1874
|
-
const ResetResponseSchema = z.discriminatedUnion("status", [z.object({
|
|
1875
|
-
ok: z.literal(true),
|
|
1876
|
-
previousSessionId: z.string().min(1),
|
|
1877
|
-
status: z.literal("reset")
|
|
1878
|
-
}), z.object({
|
|
1879
|
-
ok: z.literal(true),
|
|
1880
|
-
status: z.literal("no_active_session")
|
|
1881
|
-
})]);
|
|
1882
|
-
|
|
1883
|
-
//#endregion
|
|
1884
|
-
//#region src/client/session-controls.ts
|
|
1885
|
-
async function prewarmClientSession(input) {
|
|
1886
|
-
const { payload } = await postJson({
|
|
1887
|
-
context: input.context,
|
|
1888
|
-
operation: "Prewarm",
|
|
1889
|
-
path: createEveSessionRoutePath(input.sessionId),
|
|
1890
|
-
signal: input.signal
|
|
1891
|
-
});
|
|
1892
|
-
const result = PrewarmResponseSchema.safeParse(payload);
|
|
1893
|
-
if (!result.success) throw new Error("Prewarm route returned an invalid response.");
|
|
1894
|
-
return { status: result.data.status };
|
|
1895
|
-
}
|
|
1896
|
-
async function cancelClientSession(input) {
|
|
1897
|
-
const { signal, ...body } = input.options ?? {};
|
|
1898
|
-
const { payload, response } = await postJson({
|
|
1899
|
-
body,
|
|
1900
|
-
context: input.context,
|
|
1901
|
-
operation: "Cancel",
|
|
1902
|
-
path: createEveSessionCancelRoutePath(input.sessionId),
|
|
1903
|
-
signal
|
|
1904
|
-
});
|
|
1905
|
-
const result = CancelTurnResponseSchema.safeParse(payload);
|
|
1906
|
-
if (!result.success || result.data.status === "accepted" && result.data.sessionId !== input.sessionId) throw new Error(`Cancel route returned an invalid response (${response.status}).`);
|
|
1907
|
-
return result.data.status === "accepted" ? {
|
|
1908
|
-
sessionId: result.data.sessionId,
|
|
1909
|
-
status: "accepted"
|
|
1910
|
-
} : { status: "no_active_turn" };
|
|
1911
|
-
}
|
|
1912
|
-
async function clearClientSession(input) {
|
|
1913
|
-
const { payload } = await postJson({
|
|
1914
|
-
context: input.context,
|
|
1915
|
-
operation: "Clear",
|
|
1916
|
-
path: createEveSessionClearRoutePath(input.sessionId)
|
|
1917
|
-
});
|
|
1918
|
-
const result = ClearResponseSchema.safeParse(payload);
|
|
1919
|
-
if (!result.success || result.data.status === "accepted" && result.data.sessionId !== input.sessionId) throw new Error("Clear route returned an invalid response.");
|
|
1920
|
-
return result.data.status === "accepted" ? {
|
|
1921
|
-
sessionId: result.data.sessionId,
|
|
1922
|
-
status: "accepted"
|
|
1923
|
-
} : { status: "no_active_session" };
|
|
1924
|
-
}
|
|
1925
|
-
async function compactClientSession(input) {
|
|
1926
|
-
const { payload } = await postJson({
|
|
1927
|
-
context: input.context,
|
|
1928
|
-
operation: "Compact",
|
|
1929
|
-
path: createEveSessionCompactRoutePath(input.sessionId)
|
|
1930
|
-
});
|
|
1931
|
-
const result = CompactResponseSchema.safeParse(payload);
|
|
1932
|
-
if (!result.success || result.data.status === "accepted" && result.data.sessionId !== input.sessionId) throw new Error("Compact route returned an invalid response.");
|
|
1933
|
-
return result.data.status === "accepted" ? {
|
|
1934
|
-
sessionId: result.data.sessionId,
|
|
1935
|
-
status: "accepted"
|
|
1936
|
-
} : { status: "no_active_session" };
|
|
1937
|
-
}
|
|
1938
|
-
async function resetClientSession(input) {
|
|
1939
|
-
const { signal, ...body } = input.options ?? {};
|
|
1940
|
-
const { payload } = await postJson({
|
|
1941
|
-
body,
|
|
1942
|
-
context: input.context,
|
|
1943
|
-
operation: "Reset",
|
|
1944
|
-
path: createEveSessionResetRoutePath(input.sessionId),
|
|
1945
|
-
signal
|
|
1946
|
-
});
|
|
1947
|
-
const result = ResetResponseSchema.safeParse(payload);
|
|
1948
|
-
if (!result.success || result.data.status === "reset" && result.data.previousSessionId !== input.sessionId) throw new Error("Reset route returned an invalid response.");
|
|
1949
|
-
return result.data.status === "reset" ? {
|
|
1950
|
-
previousSessionId: result.data.previousSessionId,
|
|
1951
|
-
status: "reset"
|
|
1952
|
-
} : { status: "no_active_session" };
|
|
1953
|
-
}
|
|
1954
|
-
async function postJson(input) {
|
|
1955
|
-
const headers = await input.context.resolveHeaders();
|
|
1956
|
-
headers.set("content-type", "application/json");
|
|
1957
|
-
const response = await fetch(createClientUrl(input.context.host, input.path), withRedirectPolicy$1({
|
|
1958
|
-
body: input.body === void 0 ? void 0 : JSON.stringify(input.body),
|
|
1959
|
-
headers,
|
|
1960
|
-
method: "POST",
|
|
1961
|
-
signal: input.signal
|
|
1962
|
-
}, input.context.redirect));
|
|
1963
|
-
const text = await response.text();
|
|
1964
|
-
if (!response.ok) throw createClientError(response.status, text, response.headers);
|
|
1965
|
-
try {
|
|
1966
|
-
return {
|
|
1967
|
-
payload: JSON.parse(text),
|
|
1968
|
-
response
|
|
1969
|
-
};
|
|
1970
|
-
} catch {
|
|
1971
|
-
throw new Error(`${input.operation} route returned invalid JSON (${response.status}).`);
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
function withRedirectPolicy$1(init, redirect) {
|
|
1975
|
-
return redirect === void 0 ? init : {
|
|
1976
|
-
...init,
|
|
1977
|
-
redirect
|
|
1978
|
-
};
|
|
1979
|
-
}
|
|
1980
|
-
|
|
1981
|
-
//#endregion
|
|
1982
|
-
//#region src/shared/errors.ts
|
|
1983
|
-
function toErrorMessage(error) {
|
|
1984
|
-
if (error instanceof Error) return error.message;
|
|
1985
|
-
if (typeof error === "string") return error;
|
|
1986
|
-
if (error === null || error === void 0) return String(error);
|
|
1987
|
-
if (isObject(error)) {
|
|
1988
|
-
if (typeof error.message === "string" && error.message.length > 0) return error.message;
|
|
1989
|
-
return safeJsonStringify(error);
|
|
1990
|
-
}
|
|
1991
|
-
return String(error);
|
|
1992
|
-
}
|
|
1993
|
-
function toError(raw) {
|
|
1994
|
-
if (raw instanceof Error) return raw;
|
|
1995
|
-
const error = new Error(toErrorMessage(raw));
|
|
1996
|
-
if (!isObject(raw)) return error;
|
|
1997
|
-
if (typeof raw.name === "string" && raw.name.length > 0) error.name = raw.name;
|
|
1998
|
-
if (typeof raw.stack === "string" && raw.stack.length > 0) error.stack = raw.stack;
|
|
1999
|
-
if ("cause" in raw && raw.cause !== void 0 && raw.cause !== raw) error.cause = raw.cause;
|
|
2000
|
-
return error;
|
|
2001
|
-
}
|
|
2002
|
-
function safeJsonStringify(value) {
|
|
2003
|
-
try {
|
|
2004
|
-
return JSON.stringify(value) ?? String(value);
|
|
2005
|
-
} catch {
|
|
2006
|
-
return String(value);
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
|
|
2010
|
-
//#endregion
|
|
2011
|
-
//#region src/shared/json.ts
|
|
2012
|
-
const INVALID_JSON_VALUE_CANDIDATE = Symbol("invalid-json-value-candidate");
|
|
2013
|
-
const JSON_VALUE_ERROR_MESSAGE = "Expected a JSON-serializable value.";
|
|
2014
|
-
const JSON_OBJECT_ERROR_MESSAGE = "Expected a JSON-serializable object.";
|
|
2015
|
-
function parseJsonValue(value) {
|
|
2016
|
-
const normalized = normalizeJsonValueCandidate(value);
|
|
2017
|
-
if (normalized === INVALID_JSON_VALUE_CANDIDATE) throw new TypeError(JSON_VALUE_ERROR_MESSAGE);
|
|
2018
|
-
return normalized;
|
|
2019
|
-
}
|
|
2020
|
-
function parseJsonObject(value) {
|
|
2021
|
-
const normalized = parseJsonValue(value);
|
|
2022
|
-
if (!isJsonObjectValue(normalized)) throw new TypeError(JSON_OBJECT_ERROR_MESSAGE);
|
|
2023
|
-
return normalized;
|
|
2024
|
-
}
|
|
2025
|
-
function normalizeJsonValueCandidate(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
2026
|
-
if (value === null || typeof value === "boolean" || typeof value === "string") return value;
|
|
2027
|
-
if (typeof value === "number") return Number.isFinite(value) ? value : INVALID_JSON_VALUE_CANDIDATE;
|
|
2028
|
-
if (Array.isArray(value)) {
|
|
2029
|
-
const normalizedItems = [];
|
|
2030
|
-
for (const item of value) {
|
|
2031
|
-
const normalizedItem = normalizeJsonValueCandidate(item, seen);
|
|
2032
|
-
if (normalizedItem === INVALID_JSON_VALUE_CANDIDATE) return INVALID_JSON_VALUE_CANDIDATE;
|
|
2033
|
-
normalizedItems.push(normalizedItem);
|
|
2034
|
-
}
|
|
2035
|
-
return normalizedItems;
|
|
2036
|
-
}
|
|
2037
|
-
if (typeof value !== "object" || value === void 0) return INVALID_JSON_VALUE_CANDIDATE;
|
|
2038
|
-
if (!isPlainObject(value)) return INVALID_JSON_VALUE_CANDIDATE;
|
|
2039
|
-
if (seen.has(value)) return INVALID_JSON_VALUE_CANDIDATE;
|
|
2040
|
-
seen.add(value);
|
|
2041
|
-
const normalized = {};
|
|
2042
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
2043
|
-
if (entry === void 0) continue;
|
|
2044
|
-
const normalizedEntry = normalizeJsonValueCandidate(entry, seen);
|
|
2045
|
-
if (normalizedEntry === INVALID_JSON_VALUE_CANDIDATE) return INVALID_JSON_VALUE_CANDIDATE;
|
|
2046
|
-
normalized[key] = normalizedEntry;
|
|
2047
|
-
}
|
|
2048
|
-
seen.delete(value);
|
|
2049
|
-
return normalized;
|
|
2050
|
-
}
|
|
2051
|
-
function isJsonObjectValue(value) {
|
|
2052
|
-
return value !== null && !Array.isArray(value) && typeof value === "object";
|
|
2053
|
-
}
|
|
2054
|
-
function isPlainObject(value) {
|
|
2055
|
-
const prototype = Object.getPrototypeOf(value);
|
|
2056
|
-
return prototype === null || Object.getPrototypeOf(prototype) === null;
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
//#endregion
|
|
2060
|
-
//#region src/tools/schema-emission.ts
|
|
2061
|
-
const JSON_SCHEMA_TARGET = "draft-07";
|
|
2062
|
-
function serializeOutputSchema(source) {
|
|
2063
|
-
if (source === null || source === void 0) return source;
|
|
2064
|
-
return emitJsonSchema(source, "output");
|
|
2065
|
-
}
|
|
2066
|
-
function emitJsonSchema(source, direction) {
|
|
2067
|
-
const standard = getStandardSchemaProperties(source);
|
|
2068
|
-
if (standard === void 0) return withoutSchemaVersion(parseJsonObject(source));
|
|
2069
|
-
const emit = readJsonSchemaEmitter(standard, direction);
|
|
2070
|
-
if (emit === void 0) throw new Error(describeMissingEmitter(standard));
|
|
2071
|
-
return withoutSchemaVersion(parseJsonObject(emit({ target: JSON_SCHEMA_TARGET })));
|
|
2072
|
-
}
|
|
2073
|
-
function readJsonSchemaEmitter(standard, direction) {
|
|
2074
|
-
const jsonSchema = standard.jsonSchema;
|
|
2075
|
-
if (typeof jsonSchema !== "object" || jsonSchema === null) return void 0;
|
|
2076
|
-
const emit = jsonSchema[direction];
|
|
2077
|
-
return typeof emit === "function" ? emit : void 0;
|
|
2078
|
-
}
|
|
2079
|
-
function getStandardSchemaProperties(value) {
|
|
2080
|
-
if (typeof value !== "object" || value === null || !("~standard" in value)) return void 0;
|
|
2081
|
-
const standard = value["~standard"];
|
|
2082
|
-
return typeof standard === "object" && standard !== null ? standard : void 0;
|
|
2083
|
-
}
|
|
2084
|
-
function describeMissingEmitter(standard) {
|
|
2085
|
-
const vendor = typeof standard.vendor === "string" ? standard.vendor : "unknown";
|
|
2086
|
-
if (vendor === "zod") return "Zod 3 cannot emit an output JSON Schema. Upgrade to Zod 4 or provide a plain JSON Schema object.";
|
|
2087
|
-
return `Standard Schema vendor "${vendor}" does not support JSON Schema conversion. Provide a Standard Schema implementation with JSON Schema conversion or a plain JSON Schema object.`;
|
|
2088
|
-
}
|
|
2089
|
-
function withoutSchemaVersion(schema) {
|
|
2090
|
-
const { $schema: _schemaVersion, ...canonical } = schema;
|
|
2091
|
-
return canonical;
|
|
2092
|
-
}
|
|
2093
|
-
|
|
2094
|
-
//#endregion
|
|
2095
|
-
//#region src/tools/schema.ts
|
|
2096
|
-
function defineJsonSchema(schema, check) {
|
|
2097
|
-
const emit = () => structuredClone(schema);
|
|
2098
|
-
const toolSchema = { "~standard": {
|
|
2099
|
-
version: 1,
|
|
2100
|
-
vendor: "eve",
|
|
2101
|
-
validate: createJsonSchemaValidator(schema, check),
|
|
2102
|
-
jsonSchema: {
|
|
2103
|
-
input: emit,
|
|
2104
|
-
output: emit
|
|
2105
|
-
}
|
|
2106
|
-
} };
|
|
2107
|
-
plainJsonSchemas.add(toolSchema);
|
|
2108
|
-
return toolSchema;
|
|
2109
|
-
}
|
|
2110
|
-
const plainJsonSchemas = /* @__PURE__ */ new WeakSet();
|
|
2111
|
-
const UNSPECIFIED_INPUT_SCHEMA = defineJsonSchema({});
|
|
2112
|
-
function createJsonSchemaValidator(schema, check) {
|
|
2113
|
-
let validator;
|
|
2114
|
-
let warned = false;
|
|
2115
|
-
const passThrough = (value, reason) => {
|
|
2116
|
-
if (!warned) {
|
|
2117
|
-
warned = true;
|
|
2118
|
-
console.warn(`[eve] Tool schema cannot validate values locally; passing them through unvalidated: ${reason}`);
|
|
2119
|
-
}
|
|
2120
|
-
return { value };
|
|
2121
|
-
};
|
|
2122
|
-
return (value) => {
|
|
2123
|
-
if (validator === void 0) {
|
|
2124
|
-
const built = buildValidator(schema);
|
|
2125
|
-
if (typeof built === "string") {
|
|
2126
|
-
validator = null;
|
|
2127
|
-
return passThrough(value, built);
|
|
2128
|
-
}
|
|
2129
|
-
validator = built;
|
|
2130
|
-
}
|
|
2131
|
-
if (validator === null) return { value };
|
|
2132
|
-
let result;
|
|
2133
|
-
try {
|
|
2134
|
-
result = validator.validate(value);
|
|
2135
|
-
} catch (error) {
|
|
2136
|
-
if (value === void 0) return { issues: [{ message: "Expected a JSON value." }] };
|
|
2137
|
-
return passThrough(value, toErrorMessage(error));
|
|
2138
|
-
}
|
|
2139
|
-
if (!result.valid) return { issues: toIssues(result.errors) };
|
|
2140
|
-
const filled = applyDefaults(schema, schema, value);
|
|
2141
|
-
const message = check?.(filled);
|
|
2142
|
-
return message === void 0 ? { value: filled } : { issues: [{ message }] };
|
|
2143
|
-
};
|
|
2144
|
-
}
|
|
2145
|
-
function applyDefaults(root, schema, value) {
|
|
2146
|
-
let result = value;
|
|
2147
|
-
for (const node of followRefs(root, schema)) {
|
|
2148
|
-
const { items, properties } = node;
|
|
2149
|
-
if (isObject(result) && isObject(properties)) result = fillProperties(root, properties, result);
|
|
2150
|
-
else if (Array.isArray(result) && isObject(items)) {
|
|
2151
|
-
const list = result;
|
|
2152
|
-
const next = list.map((item) => applyDefaults(root, items, item));
|
|
2153
|
-
if (next.some((item, index) => item !== list[index])) result = next;
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
return result;
|
|
2157
|
-
}
|
|
2158
|
-
function fillProperties(root, properties, value) {
|
|
2159
|
-
let result = value;
|
|
2160
|
-
for (const [key, property] of Object.entries(properties)) {
|
|
2161
|
-
const current = Object.hasOwn(value, key) ? value[key] : void 0;
|
|
2162
|
-
const next = current === void 0 ? findDefault(root, property) : applyDefaults(root, property, current);
|
|
2163
|
-
if (next === current) continue;
|
|
2164
|
-
if (result === value) result = { ...value };
|
|
2165
|
-
result[key] = next;
|
|
2166
|
-
}
|
|
2167
|
-
return result;
|
|
2168
|
-
}
|
|
2169
|
-
function findDefault(root, schema) {
|
|
2170
|
-
for (const node of followRefs(root, schema)) if ("default" in node) return structuredClone(node.default);
|
|
2171
|
-
}
|
|
2172
|
-
function* followRefs(root, schema) {
|
|
2173
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2174
|
-
let node = schema;
|
|
2175
|
-
while (isObject(node) && !seen.has(node)) {
|
|
2176
|
-
seen.add(node);
|
|
2177
|
-
yield node;
|
|
2178
|
-
node = resolveLocalRef(root, node.$ref);
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
function resolveLocalRef(root, ref) {
|
|
2182
|
-
if (typeof ref !== "string" || ref !== "#" && !ref.startsWith("#/")) return void 0;
|
|
2183
|
-
let node = root;
|
|
2184
|
-
for (const segment of decodePointer(ref)) {
|
|
2185
|
-
if (typeof node !== "object" || node === null || !Object.hasOwn(node, segment)) return;
|
|
2186
|
-
node = node[segment];
|
|
2187
|
-
}
|
|
2188
|
-
return node;
|
|
2189
|
-
}
|
|
2190
|
-
function buildValidator(schema) {
|
|
2191
|
-
try {
|
|
2192
|
-
const copy = structuredClone(schema);
|
|
2193
|
-
return prepareForValidation(copy) ?? new Validator(copy, "2020-12", false);
|
|
2194
|
-
} catch (error) {
|
|
2195
|
-
return toErrorMessage(error);
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2198
|
-
const JSON_TYPES = /* @__PURE__ */ new Set([
|
|
2199
|
-
"array",
|
|
2200
|
-
"boolean",
|
|
2201
|
-
"integer",
|
|
2202
|
-
"null",
|
|
2203
|
-
"number",
|
|
2204
|
-
"object",
|
|
2205
|
-
"string"
|
|
2206
|
-
]);
|
|
2207
|
-
const EXCLUSIVE_BOUNDS = [["exclusiveMinimum", "minimum"], ["exclusiveMaximum", "maximum"]];
|
|
2208
|
-
const SUBSCHEMA_KEYWORDS = [
|
|
2209
|
-
"additionalItems",
|
|
2210
|
-
"additionalProperties",
|
|
2211
|
-
"contains",
|
|
2212
|
-
"else",
|
|
2213
|
-
"if",
|
|
2214
|
-
"not",
|
|
2215
|
-
"propertyNames",
|
|
2216
|
-
"then",
|
|
2217
|
-
"unevaluatedItems",
|
|
2218
|
-
"unevaluatedProperties"
|
|
2219
|
-
];
|
|
2220
|
-
const SUBSCHEMA_LIST_KEYWORDS = [
|
|
2221
|
-
"allOf",
|
|
2222
|
-
"anyOf",
|
|
2223
|
-
"oneOf",
|
|
2224
|
-
"prefixItems"
|
|
2225
|
-
];
|
|
2226
|
-
const SUBSCHEMA_MAP_KEYWORDS = [
|
|
2227
|
-
"$defs",
|
|
2228
|
-
"definitions",
|
|
2229
|
-
"dependencies",
|
|
2230
|
-
"dependentSchemas",
|
|
2231
|
-
"patternProperties",
|
|
2232
|
-
"properties"
|
|
2233
|
-
];
|
|
2234
|
-
function prepareForValidation(schema) {
|
|
2235
|
-
if (typeof schema === "boolean") return void 0;
|
|
2236
|
-
if (typeof schema !== "object" || schema === null || Array.isArray(schema)) return "a subschema is neither an object nor a boolean";
|
|
2237
|
-
const node = schema;
|
|
2238
|
-
delete node.format;
|
|
2239
|
-
for (const [flag, bound] of EXCLUSIVE_BOUNDS) {
|
|
2240
|
-
if (typeof node[flag] !== "boolean") continue;
|
|
2241
|
-
if (node[flag] && typeof node[bound] === "number") {
|
|
2242
|
-
node[flag] = node[bound];
|
|
2243
|
-
delete node[bound];
|
|
2244
|
-
} else delete node[flag];
|
|
2245
|
-
}
|
|
2246
|
-
const { enum: values, pattern, required, type } = node;
|
|
2247
|
-
if (type !== void 0 && !(Array.isArray(type) ? type.every(isJsonType) : isJsonType(type))) return `unsupported type ${JSON.stringify(type)}`;
|
|
2248
|
-
if (values !== void 0 && !Array.isArray(values)) return "`enum` is not an array";
|
|
2249
|
-
if (required !== void 0 && !(Array.isArray(required) && required.every((key) => typeof key === "string"))) return "`required` is not an array of strings";
|
|
2250
|
-
if (pattern !== void 0 && !isRegExpSource(pattern)) return `invalid pattern ${JSON.stringify(pattern)}`;
|
|
2251
|
-
for (const keyword of SUBSCHEMA_KEYWORDS) if (keyword in node) {
|
|
2252
|
-
const problem = prepareForValidation(node[keyword]);
|
|
2253
|
-
if (problem !== void 0) return problem;
|
|
2254
|
-
}
|
|
2255
|
-
const items = node.items;
|
|
2256
|
-
for (const subschema of Array.isArray(items) ? items : items === void 0 ? [] : [items]) {
|
|
2257
|
-
const problem = prepareForValidation(subschema);
|
|
2258
|
-
if (problem !== void 0) return problem;
|
|
2259
|
-
}
|
|
2260
|
-
for (const keyword of SUBSCHEMA_LIST_KEYWORDS) {
|
|
2261
|
-
const list = node[keyword];
|
|
2262
|
-
if (list === void 0) continue;
|
|
2263
|
-
if (!Array.isArray(list)) return `\`${keyword}\` is not an array`;
|
|
2264
|
-
for (const subschema of list) {
|
|
2265
|
-
const problem = prepareForValidation(subschema);
|
|
2266
|
-
if (problem !== void 0) return problem;
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
for (const keyword of SUBSCHEMA_MAP_KEYWORDS) {
|
|
2270
|
-
const map = node[keyword];
|
|
2271
|
-
if (map === void 0) continue;
|
|
2272
|
-
if (typeof map !== "object" || map === null || Array.isArray(map)) return `\`${keyword}\` is not an object`;
|
|
2273
|
-
for (const [key, subschema] of Object.entries(map)) {
|
|
2274
|
-
if (keyword === "patternProperties" && !isRegExpSource(key)) return `invalid pattern ${JSON.stringify(key)}`;
|
|
2275
|
-
if (keyword === "dependencies" && Array.isArray(subschema)) continue;
|
|
2276
|
-
const problem = prepareForValidation(subschema);
|
|
2277
|
-
if (problem !== void 0) return problem;
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
function isJsonType(value) {
|
|
2282
|
-
return typeof value === "string" && JSON_TYPES.has(value);
|
|
2283
|
-
}
|
|
2284
|
-
function isRegExpSource(value) {
|
|
2285
|
-
if (typeof value !== "string") return false;
|
|
2286
|
-
try {
|
|
2287
|
-
new RegExp(value, "u");
|
|
2288
|
-
return true;
|
|
2289
|
-
} catch {
|
|
2290
|
-
return false;
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
const CLOSED_OBJECT_KEYWORD = /\/(?:additional|unevaluated)Properties$/;
|
|
2294
|
-
function toIssues(errors) {
|
|
2295
|
-
const failures = [];
|
|
2296
|
-
for (let index = 0; index < errors.length; index++) {
|
|
2297
|
-
const unit = errors[index];
|
|
2298
|
-
const rejected = errors[index + 1];
|
|
2299
|
-
if (CLOSED_OBJECT_KEYWORD.test(unit.keywordLocation) && rejected?.keyword === "false") {
|
|
2300
|
-
const key = decodePointer(rejected.instanceLocation).at(-1);
|
|
2301
|
-
failures.push({
|
|
2302
|
-
keyword: "false",
|
|
2303
|
-
location: rejected.instanceLocation,
|
|
2304
|
-
message: `Unrecognized key: ${JSON.stringify(key)}`,
|
|
2305
|
-
object: unit.instanceLocation
|
|
2306
|
-
});
|
|
2307
|
-
index++;
|
|
2308
|
-
} else failures.push({
|
|
2309
|
-
keyword: unit.keyword,
|
|
2310
|
-
location: unit.instanceLocation,
|
|
2311
|
-
message: unit.error
|
|
2312
|
-
});
|
|
2313
|
-
}
|
|
2314
|
-
const relevant = failures.filter((failure) => failure.object === void 0 || !failures.some((other) => other.object === void 0 && (other.location === failure.location || other.location.startsWith(`${failure.location}/`))));
|
|
2315
|
-
return relevant.filter((failure, index) => {
|
|
2316
|
-
const next = relevant[index + 1];
|
|
2317
|
-
if (next === void 0) return true;
|
|
2318
|
-
if (next.location.startsWith(`${failure.location}/`)) return false;
|
|
2319
|
-
return !(failure.keyword === "$ref" && next.location === failure.location);
|
|
2320
|
-
}).map(({ location, message, object }) => {
|
|
2321
|
-
const path = decodePointer(object ?? location);
|
|
2322
|
-
return path.length === 0 ? { message } : {
|
|
2323
|
-
message,
|
|
2324
|
-
path
|
|
2325
|
-
};
|
|
2326
|
-
});
|
|
2327
|
-
}
|
|
2328
|
-
function decodePointer(location) {
|
|
2329
|
-
return location.split("/").slice(1).map((segment) => {
|
|
2330
|
-
let decoded = segment;
|
|
2331
|
-
try {
|
|
2332
|
-
decoded = decodeURIComponent(segment);
|
|
2333
|
-
} catch {}
|
|
2334
|
-
return decoded.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
2335
|
-
});
|
|
2336
|
-
}
|
|
2337
|
-
|
|
2338
|
-
//#endregion
|
|
2339
|
-
//#region src/client/session.ts
|
|
2340
|
-
const SESSION_SEND_RETRY_BASE_DELAY_MS = 250;
|
|
2341
|
-
const SESSION_SEND_RETRY_MAX_DELAY_MS = 2e3;
|
|
2342
|
-
const SESSION_SEND_READY_TIMEOUT_MS = 2e4;
|
|
2343
|
-
const followSession = Symbol("followClientSession");
|
|
2344
|
-
var ClientSession = class ClientSession {
|
|
2345
|
-
#context;
|
|
2346
|
-
#state;
|
|
2347
|
-
constructor(context, state) {
|
|
2348
|
-
this.#context = context;
|
|
2349
|
-
this.#state = state;
|
|
2350
|
-
}
|
|
2351
|
-
static async create(context, input) {
|
|
2352
|
-
const startedAt = Date.now();
|
|
2353
|
-
const response = await postTurn(context, EVE_SESSION_ROUTE_PATH, input, true, input.stubs);
|
|
2354
|
-
const acceptedAt = Date.now();
|
|
2355
|
-
const { sessionId, deliveryId } = await readAcceptedMessage(response);
|
|
2356
|
-
const session = new ClientSession(context, {
|
|
2357
|
-
sessionId,
|
|
2358
|
-
streamIndex: 0
|
|
2359
|
-
});
|
|
2360
|
-
const receipt = {
|
|
2361
|
-
deliveryId,
|
|
2362
|
-
startedAt,
|
|
2363
|
-
notReadyMs: 0,
|
|
2364
|
-
acceptedAt
|
|
2365
|
-
};
|
|
2366
|
-
return {
|
|
2367
|
-
response: session.#messageResponse(response, input, 0, void 0, receipt),
|
|
2368
|
-
session
|
|
2369
|
-
};
|
|
2370
|
-
}
|
|
2371
|
-
static async prewarm(context, options = {}) {
|
|
2372
|
-
const { sessionId } = await readAcceptedMessage(await postCreateSession(context, options));
|
|
2373
|
-
return new ClientSession(context, {
|
|
2374
|
-
sessionId,
|
|
2375
|
-
streamIndex: 0
|
|
2376
|
-
});
|
|
2377
|
-
}
|
|
2378
|
-
get state() {
|
|
2379
|
-
return this.#state;
|
|
2380
|
-
}
|
|
2381
|
-
async snapshot(options) {
|
|
2382
|
-
throwIfAborted(options?.signal);
|
|
2383
|
-
const events = [];
|
|
2384
|
-
for await (const event of this.#readStream({
|
|
2385
|
-
follow: false,
|
|
2386
|
-
signal: options?.signal,
|
|
2387
|
-
startIndex: 0
|
|
2388
|
-
})) events.push(event);
|
|
2389
|
-
throwIfAborted(options?.signal);
|
|
2390
|
-
return {
|
|
2391
|
-
events,
|
|
2392
|
-
session: {
|
|
2393
|
-
sessionId: this.#state.sessionId,
|
|
2394
|
-
streamIndex: events.length
|
|
2395
|
-
}
|
|
2396
|
-
};
|
|
2397
|
-
}
|
|
2398
|
-
async send(message, options = {}) {
|
|
2399
|
-
return await this.#send({
|
|
2400
|
-
...options,
|
|
2401
|
-
message
|
|
2402
|
-
}, true);
|
|
2403
|
-
}
|
|
2404
|
-
async respond(inputResponses, options = {}) {
|
|
2405
|
-
if (inputResponses.length === 0) throw new Error("ClientSession.respond() requires at least one input response.");
|
|
2406
|
-
return await this.#send({
|
|
2407
|
-
...options,
|
|
2408
|
-
inputResponses
|
|
2409
|
-
}, false);
|
|
2410
|
-
}
|
|
2411
|
-
async #send(input, retrySessionNotReady) {
|
|
2412
|
-
const initialStreamIndex = this.#state.streamIndex;
|
|
2413
|
-
const path = createEveSessionRoutePath(this.#state.sessionId);
|
|
2414
|
-
const { response, timing } = await postSessionSend(this.#context, path, input, retrySessionNotReady);
|
|
2415
|
-
const { sessionId: responseSessionId, deliveryId } = await readAcceptedMessage(response, this.#state.sessionId);
|
|
2416
|
-
if (responseSessionId !== this.#state.sessionId) throw new Error("Message route returned a different session id.");
|
|
2417
|
-
if (input.message !== void 0 && deliveryId === void 0) throw new Error("Message route did not return a delivery id. Update the server before sending with this client.");
|
|
2418
|
-
return this.#messageResponse(response, input, initialStreamIndex, input.message === void 0 ? void 0 : deliveryId, {
|
|
2419
|
-
...timing,
|
|
2420
|
-
deliveryId
|
|
2421
|
-
});
|
|
2422
|
-
}
|
|
2423
|
-
async prewarm(options) {
|
|
2424
|
-
return await prewarmClientSession({
|
|
2425
|
-
context: this.#context,
|
|
2426
|
-
sessionId: this.#state.sessionId,
|
|
2427
|
-
signal: options?.signal
|
|
2428
|
-
});
|
|
2429
|
-
}
|
|
2430
|
-
async cancel(options) {
|
|
2431
|
-
return await cancelClientSession({
|
|
2432
|
-
context: this.#context,
|
|
2433
|
-
options,
|
|
2434
|
-
sessionId: this.#state.sessionId
|
|
2435
|
-
});
|
|
2436
|
-
}
|
|
2437
|
-
async clear() {
|
|
2438
|
-
return await clearClientSession({
|
|
2439
|
-
context: this.#context,
|
|
2440
|
-
sessionId: this.#state.sessionId
|
|
2441
|
-
});
|
|
2442
|
-
}
|
|
2443
|
-
async compact() {
|
|
2444
|
-
return await compactClientSession({
|
|
2445
|
-
context: this.#context,
|
|
2446
|
-
sessionId: this.#state.sessionId
|
|
2447
|
-
});
|
|
2448
|
-
}
|
|
2449
|
-
async reset(options) {
|
|
2450
|
-
return await resetClientSession({
|
|
2451
|
-
context: this.#context,
|
|
2452
|
-
options,
|
|
2453
|
-
sessionId: this.#state.sessionId
|
|
2454
|
-
});
|
|
2455
|
-
}
|
|
2456
|
-
stream(options) {
|
|
2457
|
-
if (options?.follow === false && (options.startIndex ?? this.#state.streamIndex) < 0) throw new Error("stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.");
|
|
2458
|
-
return this.#streamAndAdvance(options);
|
|
2459
|
-
}
|
|
2460
|
-
agent(started) {
|
|
2461
|
-
return new ClientAgentSession(this.#context, started);
|
|
2462
|
-
}
|
|
2463
|
-
[followSession](options) {
|
|
2464
|
-
return this.#streamAndAdvance({
|
|
2465
|
-
...options,
|
|
2466
|
-
keepAlive: true
|
|
2467
|
-
});
|
|
2468
|
-
}
|
|
2469
|
-
#messageResponse(response, input, initialStreamIndex, deliveryId, receipt) {
|
|
2470
|
-
response.body?.cancel().catch(() => {});
|
|
2471
|
-
return new MessageResponse({
|
|
2472
|
-
cancelTurn: async (turnId) => await this.cancel({ turnId }),
|
|
2473
|
-
createStream: (source) => this.#createEventStream(initialStreamIndex, input, deliveryId, source),
|
|
2474
|
-
deliveryId,
|
|
2475
|
-
receipt,
|
|
2476
|
-
resumesTurn: input.inputResponses !== void 0,
|
|
2477
|
-
sessionId: this.#state.sessionId
|
|
2478
|
-
});
|
|
2479
|
-
}
|
|
2480
|
-
async *#createEventStream(initialStreamIndex, input, deliveryId, source) {
|
|
2481
|
-
let eventCount = 0;
|
|
2482
|
-
let started = deliveryId === void 0;
|
|
2483
|
-
let reachedBoundary = false;
|
|
2484
|
-
const segment = new TurnSegment({ followCallbacks: true });
|
|
2485
|
-
try {
|
|
2486
|
-
for await (const event of source ?? this.#readStream({
|
|
2487
|
-
headers: input.headers,
|
|
2488
|
-
keepAlive: true,
|
|
2489
|
-
signal: input.signal,
|
|
2490
|
-
startIndex: initialStreamIndex,
|
|
2491
|
-
streamReconnectPolicy: input.streamReconnectPolicy
|
|
2492
|
-
})) {
|
|
2493
|
-
eventCount += 1;
|
|
2494
|
-
if (deliveryId !== void 0) {
|
|
2495
|
-
const matches = event.meta?.deliveryIds?.includes(deliveryId) === true;
|
|
2496
|
-
const terminal = event.type === "session.failed" || event.type === "session.completed";
|
|
2497
|
-
if (!matches && terminal && (!started || event.type === "session.completed")) throw new Error("The session ended before the accepted message reached its turn boundary.");
|
|
2498
|
-
if (!started && !matches) continue;
|
|
2499
|
-
const attributed = event.meta?.deliveryIds !== void 0;
|
|
2500
|
-
if (!terminal && attributed && !matches) continue;
|
|
2501
|
-
started = true;
|
|
2502
|
-
}
|
|
2503
|
-
reachedBoundary = segment.observe(event);
|
|
2504
|
-
yield event;
|
|
2505
|
-
if (reachedBoundary) break;
|
|
2506
|
-
}
|
|
2507
|
-
if (deliveryId !== void 0 && !reachedBoundary && !input.signal?.aborted) throw new Error("The response stream ended before the accepted message reached its turn boundary.");
|
|
2508
|
-
} finally {
|
|
2509
|
-
this.#advanceStreamIndex(initialStreamIndex + eventCount);
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
async *#streamAndAdvance(options) {
|
|
2513
|
-
const startIndex = options?.startIndex ?? this.#state.streamIndex;
|
|
2514
|
-
let eventCount = 0;
|
|
2515
|
-
for await (const event of this.#readStream({
|
|
2516
|
-
follow: options?.follow,
|
|
2517
|
-
headers: options?.headers,
|
|
2518
|
-
keepAlive: options?.keepAlive,
|
|
2519
|
-
onCaughtUp: options?.onCaughtUp,
|
|
2520
|
-
resolveHeaders: options?.resolveHeaders,
|
|
2521
|
-
resolveReconnectPolicy: options?.resolveReconnectPolicy,
|
|
2522
|
-
signal: options?.signal,
|
|
2523
|
-
startIndex,
|
|
2524
|
-
streamReconnectPolicy: options?.streamReconnectPolicy
|
|
2525
|
-
})) {
|
|
2526
|
-
eventCount += 1;
|
|
2527
|
-
if (startIndex >= 0) this.#advanceStreamIndex(startIndex + eventCount);
|
|
2528
|
-
yield event;
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
#advanceStreamIndex(streamIndex) {
|
|
2532
|
-
this.#state = {
|
|
2533
|
-
sessionId: this.#state.sessionId,
|
|
2534
|
-
streamIndex: Math.max(this.#state.streamIndex, streamIndex)
|
|
2535
|
-
};
|
|
2536
|
-
}
|
|
2537
|
-
#readStream(input) {
|
|
2538
|
-
return followStreamIterable({
|
|
2539
|
-
onCaughtUp: input.onCaughtUp,
|
|
2540
|
-
follow: input.follow,
|
|
2541
|
-
host: this.#context.host,
|
|
2542
|
-
keepAlive: input.keepAlive,
|
|
2543
|
-
resolveHeaders: () => this.#context.resolveHeaders(input.resolveHeaders?.() ?? input.headers),
|
|
2544
|
-
path: createEveSessionStreamRoutePath(this.#state.sessionId),
|
|
2545
|
-
redirect: this.#context.redirect,
|
|
2546
|
-
signal: input.signal,
|
|
2547
|
-
startIndex: input.startIndex,
|
|
2548
|
-
streamReconnectPolicy: input.streamReconnectPolicy,
|
|
2549
|
-
resolveReconnectPolicy: input.resolveReconnectPolicy
|
|
2550
|
-
});
|
|
2551
|
-
}
|
|
2552
|
-
};
|
|
2553
|
-
function followClientSession(session, options) {
|
|
2554
|
-
return session[followSession](options);
|
|
2555
|
-
}
|
|
2556
|
-
async function postSessionSend(context, path, input, retrySessionNotReady) {
|
|
2557
|
-
const startedAt = Date.now();
|
|
2558
|
-
const readyDeadline = startedAt + SESSION_SEND_READY_TIMEOUT_MS;
|
|
2559
|
-
let retryDelayMs = SESSION_SEND_RETRY_BASE_DELAY_MS;
|
|
2560
|
-
for (;;) {
|
|
2561
|
-
const attemptAt = Date.now();
|
|
2562
|
-
try {
|
|
2563
|
-
return {
|
|
2564
|
-
response: await postTurn(context, path, input, false),
|
|
2565
|
-
timing: {
|
|
2566
|
-
startedAt,
|
|
2567
|
-
notReadyMs: attemptAt - startedAt,
|
|
2568
|
-
acceptedAt: Date.now()
|
|
2569
|
-
}
|
|
2570
|
-
};
|
|
2571
|
-
} catch (error) {
|
|
2572
|
-
if (!retrySessionNotReady || !isSessionNotReady(error)) throw error;
|
|
2573
|
-
const remainingMs = readyDeadline - Date.now();
|
|
2574
|
-
if (remainingMs <= 0) throw error;
|
|
2575
|
-
await sleep(Math.min(retryDelayMs, remainingMs), input.signal);
|
|
2576
|
-
}
|
|
2577
|
-
throwIfAborted(input.signal);
|
|
2578
|
-
retryDelayMs = Math.min(retryDelayMs * 2, SESSION_SEND_RETRY_MAX_DELAY_MS);
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
async function postCreateSession(context, options) {
|
|
2582
|
-
const headers = await context.resolveHeaders(options.headers);
|
|
2583
|
-
const body = options.stubs === void 0 ? void 0 : JSON.stringify({ stubs: options.stubs });
|
|
2584
|
-
if (body !== void 0) headers.set("content-type", "application/json");
|
|
2585
|
-
const response = await fetch(createClientUrl(context.host, EVE_SESSION_ROUTE_PATH), {
|
|
2586
|
-
body,
|
|
2587
|
-
headers,
|
|
2588
|
-
method: "POST",
|
|
2589
|
-
redirect: context.redirect,
|
|
2590
|
-
signal: options.signal ?? null
|
|
2591
|
-
});
|
|
2592
|
-
if (!response.ok) {
|
|
2593
|
-
const responseBody = await response.text();
|
|
2594
|
-
throw new ClientError(response.status, responseBody, response.headers);
|
|
2595
|
-
}
|
|
2596
|
-
return response;
|
|
2597
|
-
}
|
|
2598
|
-
function isSessionNotReady(error) {
|
|
2599
|
-
return error instanceof ClientError && error.status === 409 && error.code === "session_not_ready";
|
|
2600
|
-
}
|
|
2601
|
-
async function postTurn(context, path, input, requireMessage, stubs) {
|
|
2602
|
-
const body = createMessageBody(input, requireMessage);
|
|
2603
|
-
if (body === null) throw new Error(requireMessage ? "Creating a session requires a non-empty message." : "A session turn requires a non-empty message or inputResponses.");
|
|
2604
|
-
if (stubs !== void 0) body.stubs = stubs;
|
|
2605
|
-
const headers = await context.resolveHeaders(input.headers);
|
|
2606
|
-
headers.set("content-type", "application/json");
|
|
2607
|
-
const response = await fetch(createClientUrl(context.host, path), {
|
|
2608
|
-
body: JSON.stringify(body),
|
|
2609
|
-
headers,
|
|
2610
|
-
method: "POST",
|
|
2611
|
-
redirect: context.redirect,
|
|
2612
|
-
signal: input.signal ?? null
|
|
2613
|
-
});
|
|
2614
|
-
if (!response.ok) {
|
|
2615
|
-
const responseBody = await response.text();
|
|
2616
|
-
throw createClientError(response.status, responseBody, response.headers);
|
|
2617
|
-
}
|
|
2618
|
-
return response;
|
|
2619
|
-
}
|
|
2620
|
-
async function readAcceptedMessage(response, expected) {
|
|
2621
|
-
const payload = await response.json();
|
|
2622
|
-
const sessionId = (typeof payload.sessionId === "string" ? payload.sessionId : void 0) ?? response.headers.get("x-eve-session-id")?.trim() ?? expected;
|
|
2623
|
-
if (!sessionId) throw new Error("Message route did not return a session id.");
|
|
2624
|
-
return {
|
|
2625
|
-
sessionId,
|
|
2626
|
-
deliveryId: typeof payload.deliveryId === "string" && payload.deliveryId.length > 0 ? payload.deliveryId : void 0
|
|
2627
|
-
};
|
|
2628
|
-
}
|
|
2629
|
-
function createMessageBody(input, requireMessage) {
|
|
2630
|
-
const body = {};
|
|
2631
|
-
if (input.message !== void 0) body.message = input.message;
|
|
2632
|
-
if (input.inputResponses !== void 0 && input.inputResponses.length > 0) body.inputResponses = input.inputResponses;
|
|
2633
|
-
if (!requireMessage && input.message !== void 0 && input.turnPolicy !== void 0) body.turnPolicy = input.turnPolicy;
|
|
2634
|
-
if (input.clientContext !== void 0) body.clientContext = input.clientContext;
|
|
2635
|
-
const outputSchema = serializeOutputSchema(input.outputSchema);
|
|
2636
|
-
if (outputSchema !== void 0) body.outputSchema = outputSchema;
|
|
2637
|
-
if (requireMessage && body.message === void 0) return null;
|
|
2638
|
-
if (body.message === void 0 && body.inputResponses === void 0) return null;
|
|
2639
|
-
return body;
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
//#endregion
|
|
2643
|
-
//#region src/client/sessions.ts
|
|
2644
|
-
var ClientSessions = class {
|
|
2645
|
-
#context;
|
|
2646
|
-
constructor(context) {
|
|
2647
|
-
this.#context = context;
|
|
2648
|
-
}
|
|
2649
|
-
async create(input = {}) {
|
|
2650
|
-
if ("message" in input) return await ClientSession.create(this.#context, input);
|
|
2651
|
-
return { session: await ClientSession.prewarm(this.#context, input) };
|
|
2652
|
-
}
|
|
2653
|
-
attach(sessionId, options) {
|
|
2654
|
-
if (sessionId.length === 0) throw new Error("sessionId must be a non-empty string.");
|
|
2655
|
-
return new ClientSession(this.#context, {
|
|
2656
|
-
sessionId,
|
|
2657
|
-
streamIndex: options?.streamIndex ?? 0
|
|
2658
|
-
});
|
|
2659
|
-
}
|
|
2660
|
-
};
|
|
2661
|
-
|
|
2662
|
-
//#endregion
|
|
2663
|
-
//#region src/client/types.ts
|
|
2664
|
-
const VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER = "x-vercel-trusted-oidc-idp-token";
|
|
2665
|
-
|
|
2666
|
-
//#endregion
|
|
2667
|
-
//#region src/client/client.ts
|
|
2668
|
-
var Client = class {
|
|
2669
|
-
#auth;
|
|
2670
|
-
#headers;
|
|
2671
|
-
#host;
|
|
2672
|
-
#redirect;
|
|
2673
|
-
sessions;
|
|
2674
|
-
constructor(options) {
|
|
2675
|
-
this.#host = options.host;
|
|
2676
|
-
this.#auth = options.auth;
|
|
2677
|
-
this.#headers = options.headers;
|
|
2678
|
-
this.#redirect = options.redirect;
|
|
2679
|
-
this.sessions = new ClientSessions({
|
|
2680
|
-
host: this.#host,
|
|
2681
|
-
redirect: this.#redirect,
|
|
2682
|
-
resolveHeaders: (perRequest) => this.#resolveHeaders(perRequest)
|
|
2683
|
-
});
|
|
2684
|
-
}
|
|
2685
|
-
async health() {
|
|
2686
|
-
const url = createClientUrl(this.#host, EVE_HEALTH_ROUTE_PATH);
|
|
2687
|
-
const headers = await this.#resolveHeaders();
|
|
2688
|
-
const response = await fetch(url, withRedirectPolicy({ headers }, this.#redirect));
|
|
2689
|
-
if (!response.ok) {
|
|
2690
|
-
const body = await response.text();
|
|
2691
|
-
throw new ClientError(response.status, body, response.headers);
|
|
2692
|
-
}
|
|
2693
|
-
let payload;
|
|
2694
|
-
try {
|
|
2695
|
-
payload = await response.json();
|
|
2696
|
-
} catch {
|
|
2697
|
-
throw new HealthResponseError();
|
|
2698
|
-
}
|
|
2699
|
-
const result = HealthResultSchema.safeParse(payload);
|
|
2700
|
-
if (!result.success) throw new HealthResponseError(result.error.issues.slice(0, 5).map((issue) => {
|
|
2701
|
-
const path = issue.path.join(".");
|
|
2702
|
-
return path.length === 0 ? issue.message : `${path}: ${issue.message}`;
|
|
2703
|
-
}));
|
|
2704
|
-
return result.data;
|
|
2705
|
-
}
|
|
2706
|
-
async info(options = {}) {
|
|
2707
|
-
const response = await this.fetch(EVE_INFO_ROUTE_PATH, options);
|
|
2708
|
-
if (!response.ok) {
|
|
2709
|
-
const body = await response.text();
|
|
2710
|
-
throw new ClientError(response.status, body, response.headers);
|
|
2711
|
-
}
|
|
2712
|
-
let payload;
|
|
2713
|
-
try {
|
|
2714
|
-
payload = await response.json();
|
|
2715
|
-
} catch {
|
|
2716
|
-
throw new AgentInfoResponseError();
|
|
2717
|
-
}
|
|
2718
|
-
const result = AgentInfoResultSchema.safeParse(payload);
|
|
2719
|
-
if (!result.success) throw new AgentInfoResponseError(result.error.issues.slice(0, 5).map((issue) => {
|
|
2720
|
-
const path = issue.path.join(".");
|
|
2721
|
-
return path.length === 0 ? issue.message : `${path}: ${issue.message}`;
|
|
2722
|
-
}));
|
|
2723
|
-
return result.data;
|
|
2724
|
-
}
|
|
2725
|
-
async fetch(path, init = {}) {
|
|
2726
|
-
const url = createClientUrl(this.#host, path);
|
|
2727
|
-
const headers = await this.#resolveHeaders(headersInitToRecord(init.headers));
|
|
2728
|
-
return await fetch(url, withRedirectPolicy({
|
|
2729
|
-
...init,
|
|
2730
|
-
headers
|
|
2731
|
-
}, this.#redirect));
|
|
2732
|
-
}
|
|
2733
|
-
async #resolveHeaders(perRequest) {
|
|
2734
|
-
const headers = new Headers();
|
|
2735
|
-
const [baseHeaders, authHeaders] = await Promise.all([resolveHeadersValue(this.#headers), this.#resolveAuthHeaders()]);
|
|
2736
|
-
for (const [key, value] of Object.entries(baseHeaders)) headers.set(key, value);
|
|
2737
|
-
for (const [key, value] of Object.entries(authHeaders)) headers.set(key, value);
|
|
2738
|
-
if (perRequest) for (const [key, value] of Object.entries(perRequest)) headers.set(key, value);
|
|
2739
|
-
return headers;
|
|
2740
|
-
}
|
|
2741
|
-
async #resolveAuthHeaders() {
|
|
2742
|
-
const auth = this.#auth;
|
|
2743
|
-
if (!auth) return {};
|
|
2744
|
-
if ("vercelOidc" in auth) {
|
|
2745
|
-
const token = (await resolveTokenValue(auth.vercelOidc.token)).trim();
|
|
2746
|
-
if (token.length === 0) return {};
|
|
2747
|
-
return {
|
|
2748
|
-
authorization: `Bearer ${token}`,
|
|
2749
|
-
[VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER]: token
|
|
2750
|
-
};
|
|
2751
|
-
}
|
|
2752
|
-
if ("bearer" in auth) {
|
|
2753
|
-
const token = (await resolveTokenValue(auth.bearer)).trim();
|
|
2754
|
-
return token.length === 0 ? {} : { authorization: `Bearer ${token}` };
|
|
2755
|
-
}
|
|
2756
|
-
if ("basic" in auth) {
|
|
2757
|
-
const password = await resolveTokenValue(auth.basic.password);
|
|
2758
|
-
return { authorization: `Basic ${encodeBasicCredentials(auth.basic.username, password)}` };
|
|
2759
|
-
}
|
|
2760
|
-
return {};
|
|
2761
|
-
}
|
|
2762
|
-
};
|
|
2763
|
-
async function resolveTokenValue(value) {
|
|
2764
|
-
return typeof value === "function" ? value() : value;
|
|
2765
|
-
}
|
|
2766
|
-
async function resolveHeadersValue(value) {
|
|
2767
|
-
if (value === void 0) return {};
|
|
2768
|
-
return typeof value === "function" ? await value() : value;
|
|
2769
|
-
}
|
|
2770
|
-
function headersInitToRecord(headers) {
|
|
2771
|
-
if (headers === void 0) return {};
|
|
2772
|
-
return Object.fromEntries(new Headers(headers).entries());
|
|
2773
|
-
}
|
|
2774
|
-
function withRedirectPolicy(init, redirect) {
|
|
2775
|
-
return redirect === void 0 ? init : {
|
|
2776
|
-
...init,
|
|
2777
|
-
redirect
|
|
2778
|
-
};
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
//#endregion
|
|
2782
|
-
//#region src/client/eve-agent-projection.ts
|
|
2783
|
-
var EveAgentProjection = class {
|
|
2784
|
-
#reducer;
|
|
2785
|
-
#events;
|
|
2786
|
-
#data;
|
|
2787
|
-
constructor(reducer, events) {
|
|
2788
|
-
this.#reducer = reducer;
|
|
2789
|
-
this.#events = [...events];
|
|
2790
|
-
this.#data = this.#reduce();
|
|
2791
|
-
}
|
|
2792
|
-
get data() {
|
|
2793
|
-
return this.#data;
|
|
2794
|
-
}
|
|
2795
|
-
get reducer() {
|
|
2796
|
-
return this.#reducer;
|
|
2797
|
-
}
|
|
2798
|
-
reset() {
|
|
2799
|
-
this.#events = [];
|
|
2800
|
-
this.#data = this.#reducer.initial();
|
|
2801
|
-
}
|
|
2802
|
-
append(event) {
|
|
2803
|
-
this.#events.push(event);
|
|
2804
|
-
this.#data = this.#reducer.reduce(this.#data, event);
|
|
2805
|
-
}
|
|
2806
|
-
remove(predicate) {
|
|
2807
|
-
this.#events = this.#events.filter((event) => !predicate(event));
|
|
2808
|
-
this.#data = this.#reduce();
|
|
2809
|
-
}
|
|
2810
|
-
replace(predicate, replacement) {
|
|
2811
|
-
const index = this.#events.findIndex(predicate);
|
|
2812
|
-
if (index === -1) this.#events.push(replacement);
|
|
2813
|
-
else this.#events[index] = replacement;
|
|
2814
|
-
this.#data = this.#reduce();
|
|
2815
|
-
}
|
|
2816
|
-
#reduce() {
|
|
2817
|
-
let data = this.#reducer.initial();
|
|
2818
|
-
for (const event of this.#events) data = this.#reducer.reduce(data, event);
|
|
2819
|
-
return data;
|
|
2820
|
-
}
|
|
2821
|
-
};
|
|
2822
|
-
|
|
2823
|
-
//#endregion
|
|
2824
|
-
//#region src/client/conversation-projection.ts
|
|
2825
|
-
const projectionKey = Symbol("eve.conversationProjection");
|
|
2826
|
-
function conversationProjection(state) {
|
|
2827
|
-
return state[projectionKey] ?? initialSessionProjection();
|
|
2828
|
-
}
|
|
2829
|
-
function withConversationProjection(state, projection) {
|
|
2830
|
-
if (state[projectionKey] === projection) return state;
|
|
2831
|
-
return Object.defineProperty({ ...state }, projectionKey, { value: projection });
|
|
2832
|
-
}
|
|
2833
|
-
|
|
2834
|
-
//#endregion
|
|
2835
|
-
//#region src/client/conversation-state.ts
|
|
2836
|
-
function openConversationInputs(state) {
|
|
2837
|
-
return Object.values(state.inputs).filter((input) => input.status === "open");
|
|
2838
|
-
}
|
|
2839
|
-
function hasPendingAuthorizations(state) {
|
|
2840
|
-
return openSignIns(conversationProjection(state)).some((attempt) => attempt.awaitsCallback === true);
|
|
2841
|
-
}
|
|
2842
|
-
function agentToolTask(state, agent) {
|
|
2843
|
-
const task = agent.taskId === void 0 ? void 0 : state.tasks[agent.taskId];
|
|
2844
|
-
return task?.kind === "agent" ? task : void 0;
|
|
2845
|
-
}
|
|
2846
|
-
function isAgentSessionCaughtUp(state, agent) {
|
|
2847
|
-
if (agent.observation.status !== "following" && agent.observation.status !== "idle") return false;
|
|
2848
|
-
const task = agentToolTask(state, agent);
|
|
2849
|
-
if (task === void 0) return false;
|
|
2850
|
-
const calls = Object.values(task.calls);
|
|
2851
|
-
if (calls.some((call) => call.status === "working")) return false;
|
|
2852
|
-
const child = agent.observation.conversation;
|
|
2853
|
-
if (child.activeTurnId !== void 0) return false;
|
|
2854
|
-
if (Object.values(child.inputs).some((input) => input.status !== "settled")) return false;
|
|
2855
|
-
if (hasPendingAuthorizations(child)) return false;
|
|
2856
|
-
return child.messages.filter((message) => message.role === "user").length >= calls.filter((call) => call.status === "completed").length;
|
|
2857
|
-
}
|
|
2858
|
-
|
|
2859
|
-
//#endregion
|
|
2860
|
-
//#region src/client/eve-agent-store-helpers.ts
|
|
2861
|
-
function activeTurnForOptimisticFollowUp(events) {
|
|
2862
|
-
const lastTurn = events.findLast((event) => event.type === "turn.started" || event.type === "turn.completed" || event.type === "turn.failed" || event.type === "turn.cancelled" || isCurrentTurnBoundaryEvent(event));
|
|
2863
|
-
return lastTurn?.type === "turn.started" ? lastTurn.data.turnId : void 0;
|
|
2864
|
-
}
|
|
2865
|
-
function isResponseBoundary(event, conversation) {
|
|
2866
|
-
return endsTurnSegment(event, {
|
|
2867
|
-
callbacks: hasPendingAuthorizations(conversation),
|
|
2868
|
-
requests: Object.values(conversation.inputs).some((input) => input.status !== "settled")
|
|
2869
|
-
});
|
|
2870
|
-
}
|
|
2871
|
-
function settledStatus(error, conversation) {
|
|
2872
|
-
if (error !== void 0) return "error";
|
|
2873
|
-
return conversation.activeTurnId === void 0 ? "ready" : "streaming";
|
|
2874
|
-
}
|
|
2875
|
-
function isSettledSessionTail(events, conversation) {
|
|
2876
|
-
const tail = events.at(-1);
|
|
2877
|
-
return tail !== void 0 && isResponseBoundary(tail, conversation);
|
|
2878
|
-
}
|
|
2879
|
-
function assertAnswerable(input, conversation) {
|
|
2880
|
-
for (const { requestId } of input.inputResponses ?? []) {
|
|
2881
|
-
const status = conversation.inputs[requestId]?.status;
|
|
2882
|
-
if (status !== void 0 && status !== "open") throw new Error(`Input request ${requestId} was already answered.`);
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
function assertInFlightFollowUp(input) {
|
|
2886
|
-
if (input.inputResponses !== void 0) return;
|
|
2887
|
-
if (input.message === void 0 || input.turnPolicy !== "steer") throw new Error("eve session is already processing a turn. Send a message with turnPolicy: \"steer\" to guide it at the next boundary, or answer an open input request.");
|
|
2888
|
-
}
|
|
2889
|
-
function validateFollowUp(input) {
|
|
2890
|
-
assertExclusiveTurnInput(input);
|
|
2891
|
-
assertInFlightFollowUp(input);
|
|
2892
|
-
return input;
|
|
2893
|
-
}
|
|
2894
|
-
function assertExclusiveTurnInput(input) {
|
|
2895
|
-
if (input.message !== void 0 === (input.inputResponses !== void 0)) throw new Error("A turn requires exactly one of message or inputResponses.");
|
|
2896
|
-
}
|
|
2897
|
-
let submissionSequence = 0;
|
|
2898
|
-
function createSubmissionId() {
|
|
2899
|
-
const randomUUID = globalThis.crypto?.randomUUID;
|
|
2900
|
-
if (randomUUID !== void 0) return randomUUID.call(globalThis.crypto);
|
|
2901
|
-
submissionSequence += 1;
|
|
2902
|
-
return `submission_${submissionSequence.toString()}`;
|
|
2903
|
-
}
|
|
2904
|
-
function createAbortSignal(first, second) {
|
|
2905
|
-
return first ? AbortSignal.any([first, second]) : second;
|
|
2906
|
-
}
|
|
2907
|
-
function summarizeUserContent(message) {
|
|
2908
|
-
if (typeof message === "string") return message;
|
|
2909
|
-
const parts = [];
|
|
2910
|
-
for (const part of message) if (part.type === "text") parts.push(part.text);
|
|
2911
|
-
else if (part.type === "file") parts.push(part.filename ? `[file: ${part.filename}]` : "[file]");
|
|
2912
|
-
return parts.join("\n");
|
|
2913
|
-
}
|
|
2914
|
-
function isAbortError(error) {
|
|
2915
|
-
return error instanceof Error && error.name === "AbortError";
|
|
2916
|
-
}
|
|
2917
|
-
function toTerminalStreamFailureError(event) {
|
|
2918
|
-
if (event.type !== "session.failed") return void 0;
|
|
2919
|
-
const error = new Error(event.data.message);
|
|
2920
|
-
error.name = event.data.code;
|
|
2921
|
-
return error;
|
|
2922
|
-
}
|
|
2923
|
-
function createActiveTurn(cancel) {
|
|
2924
|
-
const response = Promise.withResolvers();
|
|
2925
|
-
const completion = Promise.withResolvers();
|
|
2926
|
-
const turn = {
|
|
2927
|
-
abortController: new AbortController(),
|
|
2928
|
-
acceptedFollowUps: 0,
|
|
2929
|
-
cancel: () => cancel(turn),
|
|
2930
|
-
completion: completion.promise,
|
|
2931
|
-
followUpDispatches: /* @__PURE__ */ new Set(),
|
|
2932
|
-
receivedFollowUps: 0,
|
|
2933
|
-
receivedFollowUpEvents: /* @__PURE__ */ new Map(),
|
|
2934
|
-
followUpSubmissionIds: /* @__PURE__ */ new Set(),
|
|
2935
|
-
resolveCompletion: completion.resolve,
|
|
2936
|
-
response: response.promise,
|
|
2937
|
-
resolveResponse: response.resolve
|
|
2938
|
-
};
|
|
2939
|
-
return turn;
|
|
2940
|
-
}
|
|
2941
|
-
function countFollowUpDeliveries(turn, reconciliation) {
|
|
2942
|
-
let followed = 0;
|
|
2943
|
-
for (const id of reconciliation.ids) if (turn.followUpSubmissionIds.delete(id)) followed += 1;
|
|
2944
|
-
if (followed === 0) return;
|
|
2945
|
-
if (reconciliation.alreadyProjected) turn.receivedFollowUps += followed;
|
|
2946
|
-
else {
|
|
2947
|
-
const previous = turn.receivedFollowUpEvents.get(reconciliation.event) ?? 0;
|
|
2948
|
-
turn.receivedFollowUpEvents.set(reconciliation.event, previous + followed);
|
|
2949
|
-
}
|
|
2950
|
-
}
|
|
2951
|
-
async function followSteeredTurns(turn, events, isActive) {
|
|
2952
|
-
while (turn.followUpDispatches.size > 0) await Promise.allSettled(turn.followUpDispatches);
|
|
2953
|
-
if (turn.receivedFollowUps >= turn.acceptedFollowUps) return;
|
|
2954
|
-
const segment = new TurnSegment({ followCallbacks: true });
|
|
2955
|
-
for await (const event of events) {
|
|
2956
|
-
if (!isActive()) return;
|
|
2957
|
-
turn.receivedFollowUps += turn.receivedFollowUpEvents.get(event) ?? 0;
|
|
2958
|
-
turn.receivedFollowUpEvents.delete(event);
|
|
2959
|
-
if (segment.observe(event)) {
|
|
2960
|
-
while (turn.followUpDispatches.size > 0) await Promise.allSettled(turn.followUpDispatches);
|
|
2961
|
-
if (turn.receivedFollowUps >= turn.acceptedFollowUps) return;
|
|
2962
|
-
}
|
|
2963
|
-
}
|
|
2964
|
-
}
|
|
2965
|
-
async function waitWithSignal(promise, signal) {
|
|
2966
|
-
if (signal === void 0) return await promise;
|
|
2967
|
-
const aborted = Promise.withResolvers();
|
|
2968
|
-
const onAbort = () => aborted.reject(signal.reason);
|
|
2969
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
2970
|
-
if (signal.aborted) onAbort();
|
|
2971
|
-
try {
|
|
2972
|
-
return await Promise.race([aborted.promise, promise]);
|
|
2973
|
-
} finally {
|
|
2974
|
-
signal.removeEventListener("abort", onAbort);
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
|
|
2978
|
-
//#endregion
|
|
2979
|
-
//#region src/client/optimistic-message-submissions.ts
|
|
2980
|
-
var OptimisticMessageSubmissions = class {
|
|
2981
|
-
#optimistic;
|
|
2982
|
-
#projections;
|
|
2983
|
-
#pending = [];
|
|
2984
|
-
constructor(projections, optimistic) {
|
|
2985
|
-
this.#projections = projections;
|
|
2986
|
-
this.#optimistic = optimistic;
|
|
2987
|
-
}
|
|
2988
|
-
reset() {
|
|
2989
|
-
this.#pending = [];
|
|
2990
|
-
}
|
|
2991
|
-
submit(input, eventStartIndex, turnId) {
|
|
2992
|
-
if (input.message === void 0) return void 0;
|
|
2993
|
-
const pending = {
|
|
2994
|
-
createdAt: Date.now(),
|
|
2995
|
-
eventStartIndex,
|
|
2996
|
-
id: createSubmissionId(),
|
|
2997
|
-
message: summarizeUserContent(input.message),
|
|
2998
|
-
turnId,
|
|
2999
|
-
requiresDeliveryId: true
|
|
3000
|
-
};
|
|
3001
|
-
this.#pending = [...this.#pending, pending];
|
|
3002
|
-
if (this.#optimistic) for (const projection of this.#projections) projection.append({
|
|
3003
|
-
data: {
|
|
3004
|
-
createdAt: pending.createdAt,
|
|
3005
|
-
message: pending.message,
|
|
3006
|
-
submissionId: pending.id,
|
|
3007
|
-
turnId
|
|
3008
|
-
},
|
|
3009
|
-
type: "client.message.submitted"
|
|
3010
|
-
});
|
|
3011
|
-
return pending.id;
|
|
3012
|
-
}
|
|
3013
|
-
resubmit(submissionId, input) {
|
|
3014
|
-
const pending = this.#pending.find((candidate) => candidate.id === submissionId);
|
|
3015
|
-
const message = input.message === void 0 ? void 0 : summarizeUserContent(input.message);
|
|
3016
|
-
if (pending?.message === message) return submissionId;
|
|
3017
|
-
if (pending !== void 0) this.#withdraw([pending.id]);
|
|
3018
|
-
return this.submit(input, pending?.eventStartIndex ?? 0, pending?.turnId);
|
|
3019
|
-
}
|
|
3020
|
-
apply(event) {
|
|
3021
|
-
if (event.type !== "message.received") {
|
|
3022
|
-
for (const projection of this.#projections) projection.append(event);
|
|
3023
|
-
return;
|
|
3024
|
-
}
|
|
3025
|
-
const matching = this.#matching(event);
|
|
3026
|
-
if (matching.length === 0) {
|
|
3027
|
-
for (const projection of this.#projections) projection.append(event);
|
|
3028
|
-
return;
|
|
3029
|
-
}
|
|
3030
|
-
return this.#reconcile(matching, event, false);
|
|
3031
|
-
}
|
|
3032
|
-
correlate(submissionId, deliveryId, events) {
|
|
3033
|
-
if (submissionId === void 0) return void 0;
|
|
3034
|
-
this.#pending = this.#pending.map((pending) => pending.id === submissionId ? {
|
|
3035
|
-
...pending,
|
|
3036
|
-
deliveryId,
|
|
3037
|
-
requiresDeliveryId: deliveryId !== void 0
|
|
3038
|
-
} : pending);
|
|
3039
|
-
const pending = this.#pending.find((candidate) => candidate.id === submissionId);
|
|
3040
|
-
if (pending === void 0) return void 0;
|
|
3041
|
-
for (const event of events.slice(pending.eventStartIndex)) {
|
|
3042
|
-
if (event.type !== "message.received") continue;
|
|
3043
|
-
const matching = this.#matching(event);
|
|
3044
|
-
if (matching.some((candidate) => candidate.id === submissionId)) return this.#reconcile(matching, event, true);
|
|
3045
|
-
}
|
|
3046
|
-
}
|
|
3047
|
-
fail(error, submissionId) {
|
|
3048
|
-
const pending = submissionId === void 0 ? this.#pending[0] : this.#pending.find((candidate) => candidate.id === submissionId);
|
|
3049
|
-
if (pending === void 0) return;
|
|
3050
|
-
this.#pending = this.#pending.filter((candidate) => candidate.id !== pending.id);
|
|
3051
|
-
for (const projection of this.#projections) projection.replace((event) => event.type === "client.message.submitted" && event.data.submissionId === pending.id, {
|
|
3052
|
-
data: {
|
|
3053
|
-
createdAt: pending.createdAt,
|
|
3054
|
-
error: { message: error.message },
|
|
3055
|
-
message: pending.message,
|
|
3056
|
-
submissionId: pending.id,
|
|
3057
|
-
turnId: pending.turnId
|
|
3058
|
-
},
|
|
3059
|
-
type: "client.message.failed"
|
|
3060
|
-
});
|
|
3061
|
-
}
|
|
3062
|
-
failAll(error) {
|
|
3063
|
-
for (const pending of this.#pending) this.fail(error, pending.id);
|
|
3064
|
-
}
|
|
3065
|
-
#matching(event) {
|
|
3066
|
-
return this.#pending.filter((pending) => pending.deliveryId === void 0 ? !pending.requiresDeliveryId : event.meta.deliveryIds?.includes(pending.deliveryId) === true);
|
|
3067
|
-
}
|
|
3068
|
-
#reconcile(submissions, event, alreadyProjected) {
|
|
3069
|
-
const ids = submissions.map((pending) => pending.id);
|
|
3070
|
-
this.#withdraw(ids);
|
|
3071
|
-
if (!alreadyProjected) for (const projection of this.#projections) projection.append(event);
|
|
3072
|
-
return {
|
|
3073
|
-
alreadyProjected,
|
|
3074
|
-
event,
|
|
3075
|
-
ids
|
|
3076
|
-
};
|
|
3077
|
-
}
|
|
3078
|
-
#withdraw(ids) {
|
|
3079
|
-
const idSet = new Set(ids);
|
|
3080
|
-
this.#pending = this.#pending.filter((pending) => !idSet.has(pending.id));
|
|
3081
|
-
for (const projection of this.#projections) projection.remove((candidate) => candidate.type === "client.message.submitted" && idSet.has(candidate.data.submissionId));
|
|
3082
|
-
}
|
|
3083
|
-
};
|
|
3084
|
-
|
|
3085
|
-
//#endregion
|
|
3086
|
-
//#region src/client/agent-stream-follower.ts
|
|
3087
|
-
const agentStreamReconnectPolicy = {
|
|
3088
|
-
streamIdleReconnectPolicy: { maxAttempts: Infinity },
|
|
3089
|
-
streamOpenReconnectPolicy: { maxAttempts: Infinity }
|
|
3090
|
-
};
|
|
3091
|
-
var AgentStreamFollower = class {
|
|
3092
|
-
#options;
|
|
3093
|
-
#started = /* @__PURE__ */ new Map();
|
|
3094
|
-
#controllers = /* @__PURE__ */ new Map();
|
|
3095
|
-
#failed = /* @__PURE__ */ new Set();
|
|
3096
|
-
#disposed = false;
|
|
3097
|
-
constructor(options) {
|
|
3098
|
-
this.#options = options;
|
|
3099
|
-
}
|
|
3100
|
-
acceptParentEvent(event) {
|
|
3101
|
-
if (event.type === "agent.started") this.#started.set(event.data.sessionId, event);
|
|
3102
|
-
}
|
|
3103
|
-
reconcile() {
|
|
3104
|
-
if (this.#disposed) return;
|
|
3105
|
-
const state = this.#options.getState();
|
|
3106
|
-
for (const agent of Object.values(state.agents)) {
|
|
3107
|
-
if (agentToolTask(state, agent) === void 0) continue;
|
|
3108
|
-
const controller = this.#controllers.get(agent.sessionId);
|
|
3109
|
-
const caughtUp = isAgentSessionCaughtUp(state, agent);
|
|
3110
|
-
if (controller !== void 0 && caughtUp) {
|
|
3111
|
-
this.#controllers.delete(agent.sessionId);
|
|
3112
|
-
controller.abort();
|
|
3113
|
-
this.#options.onIdle(agent.sessionId);
|
|
3114
|
-
} else if (controller === void 0 && !caughtUp && !this.#failed.has(agent.sessionId)) this.#follow(agent.sessionId);
|
|
3115
|
-
}
|
|
3116
|
-
}
|
|
3117
|
-
abortAll() {
|
|
3118
|
-
this.#disposed = true;
|
|
3119
|
-
for (const controller of this.#controllers.values()) controller.abort();
|
|
3120
|
-
this.#controllers.clear();
|
|
3121
|
-
}
|
|
3122
|
-
#follow(sessionId) {
|
|
3123
|
-
const started = this.#started.get(sessionId);
|
|
3124
|
-
if (started === void 0) return;
|
|
3125
|
-
const controller = new AbortController();
|
|
3126
|
-
this.#controllers.set(sessionId, controller);
|
|
3127
|
-
this.#options.onFollowing(sessionId);
|
|
3128
|
-
const { cursors } = this.#options;
|
|
3129
|
-
(async () => {
|
|
3130
|
-
let cursor = cursors.get(sessionId) ?? 0;
|
|
3131
|
-
try {
|
|
3132
|
-
for await (const event of this.#options.session.agent(started).stream({
|
|
3133
|
-
signal: controller.signal,
|
|
3134
|
-
startIndex: cursor,
|
|
3135
|
-
streamReconnectPolicy: agentStreamReconnectPolicy
|
|
3136
|
-
})) {
|
|
3137
|
-
if (controller.signal.aborted) return;
|
|
3138
|
-
cursors.set(sessionId, ++cursor);
|
|
3139
|
-
this.#options.onEvent(sessionId, event);
|
|
3140
|
-
this.reconcile();
|
|
3141
|
-
}
|
|
3142
|
-
} catch {}
|
|
3143
|
-
if (controller.signal.aborted || this.#controllers.get(sessionId) !== controller) return;
|
|
3144
|
-
this.#controllers.delete(sessionId);
|
|
3145
|
-
this.#failed.add(sessionId);
|
|
3146
|
-
this.#options.onUnavailable(sessionId);
|
|
3147
|
-
})();
|
|
3148
|
-
}
|
|
3149
|
-
};
|
|
3150
|
-
|
|
3151
|
-
//#endregion
|
|
3152
|
-
//#region src/client/authorization-message-parts.ts
|
|
3153
|
-
function createAuthorizationRequiredPart(event) {
|
|
3154
|
-
const displayName = event.data.authorization?.displayName ?? formatAuthorizationDisplayName(event.data.name);
|
|
3155
|
-
const part = {
|
|
3156
|
-
authorization: event.data.authorization,
|
|
3157
|
-
description: normalizeAuthorizationDescription(event.data.description, event.data.name, displayName),
|
|
3158
|
-
displayName,
|
|
3159
|
-
name: event.data.name,
|
|
3160
|
-
state: "required",
|
|
3161
|
-
stepIndex: event.data.stepIndex,
|
|
3162
|
-
turnId: event.data.turnId,
|
|
3163
|
-
type: "authorization"
|
|
3164
|
-
};
|
|
3165
|
-
if (event.data.attemptId !== void 0) part.attemptId = event.data.attemptId;
|
|
3166
|
-
if (event.data.webhookUrl !== void 0) part.awaitsCallback = true;
|
|
3167
|
-
return part;
|
|
3168
|
-
}
|
|
3169
|
-
function createAuthorizationCompletedPart(event, existing) {
|
|
3170
|
-
const displayName = event.data.authorization?.displayName ?? existing?.displayName ?? formatAuthorizationDisplayName(event.data.name);
|
|
3171
|
-
const part = {
|
|
3172
|
-
authorization: existing?.authorization || event.data.authorization ? {
|
|
3173
|
-
...existing?.authorization,
|
|
3174
|
-
...event.data.authorization
|
|
3175
|
-
} : void 0,
|
|
3176
|
-
description: existing?.description ?? buildCompletedAuthorizationDescription(displayName, event.data.outcome, event.data.reason),
|
|
3177
|
-
displayName,
|
|
3178
|
-
name: event.data.name,
|
|
3179
|
-
outcome: event.data.outcome,
|
|
3180
|
-
state: "completed",
|
|
3181
|
-
stepIndex: existing?.stepIndex ?? event.data.stepIndex,
|
|
3182
|
-
turnId: existing?.turnId ?? event.data.turnId,
|
|
3183
|
-
type: "authorization"
|
|
3184
|
-
};
|
|
3185
|
-
const attemptId = event.data.attemptId ?? existing?.attemptId;
|
|
3186
|
-
if (attemptId !== void 0) part.attemptId = attemptId;
|
|
3187
|
-
if (existing?.awaitsCallback) part.awaitsCallback = true;
|
|
3188
|
-
if (event.data.reason !== void 0) part.reason = event.data.reason;
|
|
3189
|
-
return part;
|
|
3190
|
-
}
|
|
3191
|
-
function buildCompletedAuthorizationDescription(displayName, outcome, reason) {
|
|
3192
|
-
if (outcome === "authorized") return `${displayName} connected.`;
|
|
3193
|
-
return `${displayName} authorization ${outcome}${reason !== void 0 ? ` (${reason})` : ""}.`;
|
|
3194
|
-
}
|
|
3195
|
-
function normalizeAuthorizationDescription(description, name, displayName) {
|
|
3196
|
-
if (description === `Authorization required for ${name}`) return `Authorization required for ${displayName}`;
|
|
3197
|
-
return description;
|
|
3198
|
-
}
|
|
3199
|
-
function formatAuthorizationDisplayName(name) {
|
|
3200
|
-
if (name.length === 0) return name;
|
|
3201
|
-
return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
3202
|
-
}
|
|
3203
|
-
|
|
3204
|
-
//#endregion
|
|
3205
|
-
//#region src/protocol/catalog-tools.ts
|
|
3206
|
-
const SKILL_TOOL_NAME = "eve__skill";
|
|
3207
|
-
|
|
3208
|
-
//#endregion
|
|
3209
|
-
//#region src/shared/action-request-name.ts
|
|
3210
|
-
function actionRequestName(action) {
|
|
3211
|
-
switch (action.kind) {
|
|
3212
|
-
case "load-skill": return action.name;
|
|
3213
|
-
case "subagent-call": return action.subagentName;
|
|
3214
|
-
case "remote-agent-call": return action.remoteAgentName;
|
|
3215
|
-
case "tool-call":
|
|
3216
|
-
case "workflow-tool-call": return action.toolName;
|
|
3217
|
-
}
|
|
3218
|
-
}
|
|
3219
|
-
|
|
3220
|
-
//#endregion
|
|
3221
|
-
//#region src/shared/display-name.ts
|
|
3222
|
-
function displayName(identifier) {
|
|
3223
|
-
const words = lastSegment(identifier).replace(/([a-z0-9])([A-Z])/gu, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/gu, "$1 $2").split(SEPARATORS).filter((word) => word !== "").map((word) => word.length > 1 && word === word.toUpperCase() ? word : word.toLowerCase());
|
|
3224
|
-
return words.length === 0 ? identifier : words.join(" ");
|
|
3225
|
-
}
|
|
3226
|
-
function displayTitle(identifier) {
|
|
3227
|
-
return capitalize(displayName(identifier));
|
|
3228
|
-
}
|
|
3229
|
-
const SEPARATORS = /[\s_-]+/u;
|
|
3230
|
-
function lastSegment(identifier) {
|
|
3231
|
-
return identifier.split("__").findLast((segment) => segment !== "") ?? identifier;
|
|
3232
|
-
}
|
|
3233
|
-
function capitalize(text) {
|
|
3234
|
-
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
3235
|
-
}
|
|
3236
|
-
|
|
3237
|
-
//#endregion
|
|
3238
|
-
//#region src/client/message-action-parts.ts
|
|
3239
|
-
function toMessageInputRequest(request) {
|
|
3240
|
-
return {
|
|
3241
|
-
allowFreeform: request.allowFreeform,
|
|
3242
|
-
display: request.display,
|
|
3243
|
-
kind: request.kind,
|
|
3244
|
-
options: request.options,
|
|
3245
|
-
prompt: request.prompt,
|
|
3246
|
-
requestId: request.requestId
|
|
3247
|
-
};
|
|
3248
|
-
}
|
|
3249
|
-
function createToolMetadata(descriptor, extra) {
|
|
3250
|
-
return { eve: {
|
|
3251
|
-
inputRequest: extra?.inputRequest,
|
|
3252
|
-
kind: descriptor.kind,
|
|
3253
|
-
label: extra?.label,
|
|
3254
|
-
name: descriptor.name
|
|
3255
|
-
} };
|
|
3256
|
-
}
|
|
3257
|
-
function mergeToolMetadata(current, next) {
|
|
3258
|
-
const kind = next.eve?.kind ?? current?.eve?.kind ?? "unknown";
|
|
3259
|
-
const name = next.eve?.name ?? current?.eve?.name ?? "unknown";
|
|
3260
|
-
return { eve: {
|
|
3261
|
-
...current?.eve,
|
|
3262
|
-
...next.eve,
|
|
3263
|
-
inputRequest: next.eve?.inputRequest ?? current?.eve?.inputRequest,
|
|
3264
|
-
inputResponse: next.eve?.inputResponse ?? current?.eve?.inputResponse,
|
|
3265
|
-
kind,
|
|
3266
|
-
label: next.eve?.label ?? current?.eve?.label,
|
|
3267
|
-
name
|
|
3268
|
-
} };
|
|
3269
|
-
}
|
|
3270
|
-
function normalizeActionRequest(action) {
|
|
3271
|
-
const name = actionRequestName(action);
|
|
3272
|
-
switch (action.kind) {
|
|
3273
|
-
case "load-skill": return {
|
|
3274
|
-
kind: "load-skill",
|
|
3275
|
-
name,
|
|
3276
|
-
toolName: SKILL_TOOL_NAME
|
|
3277
|
-
};
|
|
3278
|
-
case "tool-call":
|
|
3279
|
-
case "workflow-tool-call": return {
|
|
3280
|
-
kind: "tool-call",
|
|
3281
|
-
name,
|
|
3282
|
-
toolName: name
|
|
3283
|
-
};
|
|
3284
|
-
case "subagent-call":
|
|
3285
|
-
case "remote-agent-call": return {
|
|
3286
|
-
kind: "subagent-call",
|
|
3287
|
-
name,
|
|
3288
|
-
toolName: `eve:subagent:${name}`
|
|
3289
|
-
};
|
|
3290
|
-
}
|
|
3291
|
-
}
|
|
3292
|
-
function normalizeActionResult(result) {
|
|
3293
|
-
switch (result.kind) {
|
|
3294
|
-
case "load-skill-result": return {
|
|
3295
|
-
kind: "load-skill",
|
|
3296
|
-
name: result.name,
|
|
3297
|
-
toolName: SKILL_TOOL_NAME
|
|
3298
|
-
};
|
|
3299
|
-
case "tool-result": return {
|
|
3300
|
-
kind: "tool-call",
|
|
3301
|
-
name: result.toolName,
|
|
3302
|
-
toolName: result.toolName
|
|
3303
|
-
};
|
|
3304
|
-
case "subagent-result": return {
|
|
3305
|
-
kind: "subagent-call",
|
|
3306
|
-
name: result.subagentName,
|
|
3307
|
-
toolName: `eve:subagent:${result.subagentName}`
|
|
3308
|
-
};
|
|
3309
|
-
}
|
|
3310
|
-
}
|
|
3311
|
-
function settledLabel(current, label, descriptor) {
|
|
3312
|
-
return label ?? current?.eve?.label ?? displayTitle(descriptor.name);
|
|
3313
|
-
}
|
|
3314
|
-
function stringifyUnknown(value) {
|
|
3315
|
-
if (typeof value === "string") return value;
|
|
3316
|
-
try {
|
|
3317
|
-
return JSON.stringify(value);
|
|
3318
|
-
} catch {
|
|
3319
|
-
return "Action failed.";
|
|
3320
|
-
}
|
|
3321
|
-
}
|
|
3322
|
-
|
|
3323
|
-
//#endregion
|
|
3324
|
-
//#region src/client/message-reducer-primitives.ts
|
|
3325
|
-
function projectReceivedParts(parts, message) {
|
|
3326
|
-
return parts?.map((part) => part.type === "text" ? {
|
|
3327
|
-
state: "done",
|
|
3328
|
-
text: part.text,
|
|
3329
|
-
type: "text"
|
|
3330
|
-
} : {
|
|
3331
|
-
filename: part.filename,
|
|
3332
|
-
mediaType: part.mediaType,
|
|
3333
|
-
size: part.size,
|
|
3334
|
-
type: "file",
|
|
3335
|
-
url: part.url
|
|
3336
|
-
}) ?? [{
|
|
3337
|
-
state: "done",
|
|
3338
|
-
text: message,
|
|
3339
|
-
type: "text"
|
|
3340
|
-
}];
|
|
3341
|
-
}
|
|
3342
|
-
function partKey(part) {
|
|
3343
|
-
switch (part.type) {
|
|
3344
|
-
case "text": return `text:${part.stepIndex ?? 0}`;
|
|
3345
|
-
case "reasoning": return `reasoning:${part.stepIndex ?? 0}`;
|
|
3346
|
-
case "file": return `file:${part.stepIndex ?? 0}:${part.filename ?? part.url ?? part.mediaType}`;
|
|
3347
|
-
case "step-start": return "step-start";
|
|
3348
|
-
case "authorization": return part.attemptId === void 0 ? `authorization:${part.turnId}:${part.stepIndex}:${part.name}` : `authorization:${part.attemptId}`;
|
|
3349
|
-
case "dynamic-tool": return `dynamic-tool:${part.toolCallId}`;
|
|
3350
|
-
}
|
|
3351
|
-
}
|
|
3352
|
-
function upsertMessage(data, next, beforeAssistantTurnId) {
|
|
3353
|
-
const index = data.messages.findIndex((message) => message.id === next.id);
|
|
3354
|
-
if (index !== -1) return {
|
|
3355
|
-
...data,
|
|
3356
|
-
messages: [
|
|
3357
|
-
...data.messages.slice(0, index),
|
|
3358
|
-
next,
|
|
3359
|
-
...data.messages.slice(index + 1)
|
|
3360
|
-
]
|
|
3361
|
-
};
|
|
3362
|
-
const before = beforeAssistantTurnId === void 0 ? -1 : data.messages.findIndex((message) => message.role === "assistant" && message.metadata?.turnId === beforeAssistantTurnId);
|
|
3363
|
-
if (before === -1) return {
|
|
3364
|
-
...data,
|
|
3365
|
-
messages: [...data.messages, next]
|
|
3366
|
-
};
|
|
3367
|
-
return {
|
|
3368
|
-
...data,
|
|
3369
|
-
messages: [
|
|
3370
|
-
...data.messages.slice(0, before),
|
|
3371
|
-
next,
|
|
3372
|
-
...data.messages.slice(before)
|
|
3373
|
-
]
|
|
3374
|
-
};
|
|
3375
|
-
}
|
|
3376
|
-
function optimisticUserMessageId(submissionId) {
|
|
3377
|
-
return `optimistic:${submissionId}:user`;
|
|
3378
|
-
}
|
|
3379
|
-
|
|
3380
|
-
//#endregion
|
|
3381
|
-
//#region src/client/message-run-parts.ts
|
|
3382
|
-
function transition(message, input) {
|
|
3383
|
-
const index = message.parts.findLastIndex((part) => part.type === input.type && part.stepIndex === input.stepIndex);
|
|
3384
|
-
const previous = index === -1 ? void 0 : message.parts[index];
|
|
3385
|
-
if (input.kind === "append" && !input.delta) return message;
|
|
3386
|
-
const current = previous?.state === "streaming" ? previous : void 0;
|
|
3387
|
-
const part = {
|
|
3388
|
-
id: current?.id ?? input.id ?? `${message.id}:${input.type}:${message.parts.length}`,
|
|
3389
|
-
state: input.kind === "append" ? "streaming" : "done",
|
|
3390
|
-
stepIndex: input.stepIndex,
|
|
3391
|
-
text: input.kind === "append" ? (current?.text ?? "") + input.delta : input.text,
|
|
3392
|
-
type: input.type
|
|
3393
|
-
};
|
|
3394
|
-
const parts = current ? [
|
|
3395
|
-
...message.parts.slice(0, index),
|
|
3396
|
-
part,
|
|
3397
|
-
...message.parts.slice(index + 1)
|
|
3398
|
-
] : [...message.parts, part];
|
|
3399
|
-
return {
|
|
3400
|
-
...message,
|
|
3401
|
-
metadata: {
|
|
3402
|
-
...message.metadata,
|
|
3403
|
-
status: input.type === "text" && part.state === "done" ? "complete" : "streaming"
|
|
3404
|
-
},
|
|
3405
|
-
parts
|
|
3406
|
-
};
|
|
3407
|
-
}
|
|
3408
|
-
const messageRun = { transition };
|
|
3409
|
-
|
|
3410
|
-
//#endregion
|
|
3411
|
-
//#region src/shared/action-label.ts
|
|
3412
|
-
function actionLabel(action, presentation) {
|
|
3413
|
-
return presentation?.[action.callId]?.label ?? displayTitle(actionRequestName(action));
|
|
3414
|
-
}
|
|
3415
|
-
|
|
3416
|
-
//#endregion
|
|
3417
|
-
//#region src/client/tool-part-state.ts
|
|
3418
|
-
function toolPartState(data, part) {
|
|
3419
|
-
const content = part;
|
|
3420
|
-
const projection = conversationProjection(data);
|
|
3421
|
-
const call = projection.calls[part.toolCallId];
|
|
3422
|
-
const requestId = content.approval?.id;
|
|
3423
|
-
const input = requestId === void 0 ? void 0 : projection.inputs[requestId];
|
|
3424
|
-
const base = {
|
|
3425
|
-
input: part.input,
|
|
3426
|
-
stepIndex: part.stepIndex,
|
|
3427
|
-
toolCallId: part.toolCallId,
|
|
3428
|
-
toolMetadata: part.toolMetadata,
|
|
3429
|
-
toolName: part.toolName,
|
|
3430
|
-
type: "dynamic-tool"
|
|
3431
|
-
};
|
|
3432
|
-
const requested = requestId === void 0 ? void 0 : {
|
|
3433
|
-
id: requestId,
|
|
3434
|
-
...content.approval?.isAutomatic !== void 0 && { isAutomatic: content.approval.isAutomatic }
|
|
3435
|
-
};
|
|
3436
|
-
const responded = (approved, reason) => ({
|
|
3437
|
-
...base,
|
|
3438
|
-
approval: {
|
|
3439
|
-
...requested,
|
|
3440
|
-
...approved && { approved: true },
|
|
3441
|
-
...reason !== void 0 && { reason }
|
|
3442
|
-
},
|
|
3443
|
-
state: "approval-responded"
|
|
3444
|
-
});
|
|
3445
|
-
const approvedTrue = requested === void 0 ? void 0 : {
|
|
3446
|
-
...requested,
|
|
3447
|
-
approved: true
|
|
3448
|
-
};
|
|
3449
|
-
if (requested !== void 0 && input !== void 0 && input.status !== "settled" && (call === void 0 || !isSettledCallStatus(reportedCallStatus(projection, call)))) return {
|
|
3450
|
-
...base,
|
|
3451
|
-
approval: requested,
|
|
3452
|
-
state: "approval-requested"
|
|
3453
|
-
};
|
|
3454
|
-
const task = call?.taskId === void 0 ? void 0 : projection.tasks[call.taskId]?.calls[part.toolCallId];
|
|
3455
|
-
if (call === void 0) {
|
|
3456
|
-
if (input === void 0) return part;
|
|
3457
|
-
return input.response === void 0 ? {
|
|
3458
|
-
...base,
|
|
3459
|
-
output: { status: input.outcome },
|
|
3460
|
-
state: "output-available"
|
|
3461
|
-
} : responded(input.outcome === "approved", input.response.text);
|
|
3462
|
-
}
|
|
3463
|
-
switch (reportedCallStatus(projection, call)) {
|
|
3464
|
-
case "running":
|
|
3465
|
-
case "awaiting-input":
|
|
3466
|
-
if (content.partial === true) return {
|
|
3467
|
-
...base,
|
|
3468
|
-
approval: approvedTrue,
|
|
3469
|
-
output: content.output,
|
|
3470
|
-
partial: true,
|
|
3471
|
-
state: "output-available"
|
|
3472
|
-
};
|
|
3473
|
-
if (input !== void 0 && (input.outcome === "approved" || input.response !== void 0)) return responded(input.outcome === "approved", input.response?.text);
|
|
3474
|
-
return {
|
|
3475
|
-
...base,
|
|
3476
|
-
state: "input-available"
|
|
3477
|
-
};
|
|
3478
|
-
case "completed": return {
|
|
3479
|
-
...base,
|
|
3480
|
-
approval: approvedTrue,
|
|
3481
|
-
output: task?.output ?? content.output,
|
|
3482
|
-
state: "output-available"
|
|
3483
|
-
};
|
|
3484
|
-
case "failed": return {
|
|
3485
|
-
...base,
|
|
3486
|
-
approval: approvedTrue,
|
|
3487
|
-
errorText: task?.error?.message ?? content.errorText ?? call.error?.message ?? (call.taskId === void 0 ? "Action failed." : "Task failed."),
|
|
3488
|
-
state: "output-error"
|
|
3489
|
-
};
|
|
3490
|
-
case "rejected": return {
|
|
3491
|
-
...base,
|
|
3492
|
-
approval: {
|
|
3493
|
-
id: requestId ?? part.toolCallId,
|
|
3494
|
-
approved: false,
|
|
3495
|
-
reason: call.error?.message ?? content.errorText
|
|
3496
|
-
},
|
|
3497
|
-
state: "output-denied"
|
|
3498
|
-
};
|
|
3499
|
-
case "cancelled":
|
|
3500
|
-
if (requestId !== void 0 && input?.outcome === "cancelled") return {
|
|
3501
|
-
...base,
|
|
3502
|
-
approval: {
|
|
3503
|
-
id: requestId,
|
|
3504
|
-
approved: false,
|
|
3505
|
-
reason: "Tool execution was cancelled."
|
|
3506
|
-
},
|
|
3507
|
-
state: "output-denied"
|
|
3508
|
-
};
|
|
3509
|
-
return {
|
|
3510
|
-
...base,
|
|
3511
|
-
approval: approvedTrue,
|
|
3512
|
-
errorText: call.taskId === void 0 ? content.errorText ?? call.error?.message ?? "Action was cancelled." : "Task was cancelled.",
|
|
3513
|
-
state: "output-error"
|
|
3514
|
-
};
|
|
3515
|
-
}
|
|
3516
|
-
}
|
|
3517
|
-
|
|
3518
|
-
//#endregion
|
|
3519
|
-
//#region src/client/message-reducer.ts
|
|
3520
|
-
function receivedMessageEventId(event) {
|
|
3521
|
-
return event.meta.id ?? `${event.data.turnId}:${event.data.sequence}`;
|
|
3522
|
-
}
|
|
3523
|
-
function defaultMessageReducer() {
|
|
3524
|
-
return {
|
|
3525
|
-
initial() {
|
|
3526
|
-
return withConversationProjection({ messages: [] }, initialSessionProjection());
|
|
3527
|
-
},
|
|
3528
|
-
reduce(data, event) {
|
|
3529
|
-
return reduceMessageData(data, event);
|
|
3530
|
-
}
|
|
3531
|
-
};
|
|
3532
|
-
}
|
|
3533
|
-
function reduceMessageData(data, event) {
|
|
3534
|
-
const projection = foldSession(conversationProjection(data), event);
|
|
3535
|
-
const content = withConversationProjection(reduceContent(data, event), projection);
|
|
3536
|
-
const callIds = toolCallIds(content, event);
|
|
3537
|
-
return withConversationProjection(callIds.length === 0 ? content : withToolPartStates(content, callIds), projection);
|
|
3538
|
-
}
|
|
3539
|
-
function reduceContent(data, event) {
|
|
3540
|
-
switch (event.type) {
|
|
3541
|
-
case "client.message.submitted":
|
|
3542
|
-
case "client.message.failed": return upsertMessage(data, {
|
|
3543
|
-
id: optimisticUserMessageId(event.data.submissionId),
|
|
3544
|
-
metadata: {
|
|
3545
|
-
optimistic: true,
|
|
3546
|
-
status: event.type === "client.message.failed" ? "failed" : "submitted"
|
|
3547
|
-
},
|
|
3548
|
-
parts: [{
|
|
3549
|
-
type: "text",
|
|
3550
|
-
text: event.data.message
|
|
3551
|
-
}],
|
|
3552
|
-
role: "user"
|
|
3553
|
-
}, event.data.turnId);
|
|
3554
|
-
case "message.received": return upsertMessage(data, {
|
|
3555
|
-
id: `${receivedMessageEventId(event)}:user`,
|
|
3556
|
-
metadata: {
|
|
3557
|
-
status: "complete",
|
|
3558
|
-
turnId: event.data.turnId
|
|
3559
|
-
},
|
|
3560
|
-
parts: projectReceivedParts(event.data.parts, event.data.message),
|
|
3561
|
-
role: "user"
|
|
3562
|
-
}, event.data.turnId);
|
|
3563
|
-
case "history.imported": return importHistory(data, event);
|
|
3564
|
-
case "step.started": return updateAssistantMessage(data, event.data.turnId, (message) => ensureStepStartPart(message, event.data.stepIndex));
|
|
3565
|
-
case "step.completed":
|
|
3566
|
-
if (data.messages.find((message) => message.role === "assistant" && message.metadata?.turnId === event.data.turnId) === void 0) return data;
|
|
3567
|
-
return updateAssistantMessage(data, event.data.turnId, (message) => ({
|
|
3568
|
-
...message,
|
|
3569
|
-
parts: closeStreamingRuns(message.parts, event.data.stepIndex)
|
|
3570
|
-
}));
|
|
3571
|
-
case "reasoning.appended": return updateAssistantMessage(data, event.data.turnId, (message) => messageRun.transition(ensureStepStartPart(message, event.data.stepIndex), {
|
|
3572
|
-
kind: "append",
|
|
3573
|
-
delta: event.data.reasoningDelta,
|
|
3574
|
-
id: event.meta?.id,
|
|
3575
|
-
stepIndex: event.data.stepIndex,
|
|
3576
|
-
type: "reasoning"
|
|
3577
|
-
}));
|
|
3578
|
-
case "reasoning.completed": return updateAssistantMessage(data, event.data.turnId, (message) => messageRun.transition(ensureStepStartPart(message, event.data.stepIndex), {
|
|
3579
|
-
kind: "complete",
|
|
3580
|
-
stepIndex: event.data.stepIndex,
|
|
3581
|
-
text: event.data.reasoning,
|
|
3582
|
-
id: event.meta?.id,
|
|
3583
|
-
type: "reasoning"
|
|
3584
|
-
}));
|
|
3585
|
-
case "action.input.appended": {
|
|
3586
|
-
const existing = findToolPart(data, event.data.callId);
|
|
3587
|
-
if (existing !== void 0 && existing.state !== "input-streaming") return data;
|
|
3588
|
-
const inputText = (existing?.state === "input-streaming" ? existing.inputText : "") + event.data.inputTextDelta;
|
|
3589
|
-
return upsertToolPart(data, event.data.turnId, event.data.stepIndex, {
|
|
3590
|
-
input: void 0,
|
|
3591
|
-
inputText,
|
|
3592
|
-
state: "input-streaming",
|
|
3593
|
-
stepIndex: event.data.stepIndex,
|
|
3594
|
-
toolCallId: event.data.callId,
|
|
3595
|
-
toolMetadata: existing?.toolMetadata ?? { eve: {
|
|
3596
|
-
kind: "unknown",
|
|
3597
|
-
name: event.data.toolName
|
|
3598
|
-
} },
|
|
3599
|
-
toolName: event.data.toolName,
|
|
3600
|
-
type: "dynamic-tool"
|
|
3601
|
-
});
|
|
3602
|
-
}
|
|
3603
|
-
case "actions.requested": {
|
|
3604
|
-
let next = data;
|
|
3605
|
-
for (const action of event.data.actions) {
|
|
3606
|
-
const existing = findToolPart(next, action.callId);
|
|
3607
|
-
if (existing !== void 0 && existing.state !== "input-streaming") continue;
|
|
3608
|
-
const descriptor = normalizeActionRequest(action);
|
|
3609
|
-
next = updateAssistantMessage(next, event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, event.data.stepIndex), {
|
|
3610
|
-
input: "input" in action ? action.input : void 0,
|
|
3611
|
-
state: "input-available",
|
|
3612
|
-
stepIndex: event.data.stepIndex,
|
|
3613
|
-
toolCallId: action.callId,
|
|
3614
|
-
toolMetadata: createToolMetadata(descriptor, { label: actionLabel(action, event.data.presentation) }),
|
|
3615
|
-
toolName: descriptor.toolName,
|
|
3616
|
-
type: "dynamic-tool"
|
|
3617
|
-
}));
|
|
3618
|
-
}
|
|
3619
|
-
return next;
|
|
3620
|
-
}
|
|
3621
|
-
case "input.requested": {
|
|
3622
|
-
let next = data;
|
|
3623
|
-
for (const request of event.data.requests) {
|
|
3624
|
-
const existing = findToolPart(next, request.action.callId);
|
|
3625
|
-
if (existing?.approval?.id === request.requestId || existing !== void 0 && isSettledToolPart(existing)) continue;
|
|
3626
|
-
const descriptor = normalizeActionRequest(request.action);
|
|
3627
|
-
next = updateAssistantMessage(next, event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, event.data.stepIndex), {
|
|
3628
|
-
...existing,
|
|
3629
|
-
approval: { id: request.requestId },
|
|
3630
|
-
input: request.action.input,
|
|
3631
|
-
state: "approval-requested",
|
|
3632
|
-
stepIndex: existing?.stepIndex ?? event.data.stepIndex,
|
|
3633
|
-
toolCallId: request.action.callId,
|
|
3634
|
-
toolMetadata: createToolMetadata(descriptor, {
|
|
3635
|
-
inputRequest: toMessageInputRequest(request),
|
|
3636
|
-
label: existing?.toolMetadata?.eve?.label ?? actionLabel(request.action, void 0)
|
|
3637
|
-
}),
|
|
3638
|
-
toolName: descriptor.toolName,
|
|
3639
|
-
type: "dynamic-tool"
|
|
3640
|
-
}));
|
|
3641
|
-
}
|
|
3642
|
-
return next;
|
|
3643
|
-
}
|
|
3644
|
-
case "action.result": {
|
|
3645
|
-
if (conversationProjection(data).calls[event.data.result.callId]?.taskId !== void 0) return data;
|
|
3646
|
-
if (event.data.error?.code === "MODEL_CALL_ATTEMPT_RETRIED") return updateAssistantMessage(data, event.data.turnId, (message) => ({
|
|
3647
|
-
...message,
|
|
3648
|
-
parts: message.parts.filter((part) => part.type !== "dynamic-tool" || part.toolCallId !== event.data.result.callId)
|
|
3649
|
-
}));
|
|
3650
|
-
const existing = findToolPart(data, event.data.result.callId);
|
|
3651
|
-
const descriptor = normalizeActionResult(event.data.result);
|
|
3652
|
-
const succeeded = event.data.status === void 0 || event.data.status === "completed" ? event.data.result.isError !== true && event.data.error === void 0 : false;
|
|
3653
|
-
const part = {
|
|
3654
|
-
...existing,
|
|
3655
|
-
input: existing?.input,
|
|
3656
|
-
stepIndex: existing?.stepIndex ?? event.data.stepIndex,
|
|
3657
|
-
toolCallId: event.data.result.callId,
|
|
3658
|
-
toolMetadata: mergeToolMetadata(existing?.toolMetadata, createToolMetadata(descriptor, { label: settledLabel(existing?.toolMetadata, event.data.presentation?.[event.data.result.callId]?.label, descriptor) })),
|
|
3659
|
-
toolName: existing?.toolName ?? descriptor.toolName,
|
|
3660
|
-
type: "dynamic-tool"
|
|
3661
|
-
};
|
|
3662
|
-
const outcome = succeeded ? {
|
|
3663
|
-
errorText: void 0,
|
|
3664
|
-
output: event.data.result.output
|
|
3665
|
-
} : {
|
|
3666
|
-
errorText: event.data.error?.message ?? stringifyUnknown(event.data.result.output),
|
|
3667
|
-
output: void 0
|
|
3668
|
-
};
|
|
3669
|
-
return upsertToolPart(data, event.data.turnId, event.data.stepIndex, {
|
|
3670
|
-
...part,
|
|
3671
|
-
...outcome,
|
|
3672
|
-
partial: void 0
|
|
3673
|
-
});
|
|
3674
|
-
}
|
|
3675
|
-
case "action.partial": {
|
|
3676
|
-
const existing = findToolPart(data, event.data.result.callId);
|
|
3677
|
-
if (existing !== void 0 && isSettledToolPart(existing)) return data;
|
|
3678
|
-
const descriptor = normalizeActionResult(event.data.result);
|
|
3679
|
-
return upsertToolPart(data, event.data.turnId, event.data.stepIndex, {
|
|
3680
|
-
...existing,
|
|
3681
|
-
input: existing?.input,
|
|
3682
|
-
output: event.data.result.output,
|
|
3683
|
-
partial: true,
|
|
3684
|
-
state: "output-available",
|
|
3685
|
-
stepIndex: existing?.stepIndex ?? event.data.stepIndex,
|
|
3686
|
-
toolCallId: event.data.result.callId,
|
|
3687
|
-
toolMetadata: mergeToolMetadata(existing?.toolMetadata, createToolMetadata(descriptor, { label: settledLabel(existing?.toolMetadata, event.data.presentation?.[event.data.result.callId]?.label, descriptor) })),
|
|
3688
|
-
toolName: existing?.toolName ?? descriptor.toolName,
|
|
3689
|
-
type: "dynamic-tool"
|
|
3690
|
-
});
|
|
3691
|
-
}
|
|
3692
|
-
case "input.resolved": {
|
|
3693
|
-
let next = data;
|
|
3694
|
-
for (const { requestId, response } of event.data.resolutions) {
|
|
3695
|
-
const existing = response === void 0 ? void 0 : findToolPartByApprovalId(next, requestId);
|
|
3696
|
-
if (existing === void 0) continue;
|
|
3697
|
-
next = replaceToolPart(next, {
|
|
3698
|
-
...existing,
|
|
3699
|
-
toolMetadata: mergeToolMetadata(existing.toolMetadata, { eve: {
|
|
3700
|
-
inputResponse: response,
|
|
3701
|
-
kind: existing.toolMetadata?.eve?.kind ?? "unknown",
|
|
3702
|
-
name: existing.toolMetadata?.eve?.name ?? existing.toolName
|
|
3703
|
-
} })
|
|
3704
|
-
});
|
|
3705
|
-
}
|
|
3706
|
-
return next;
|
|
3707
|
-
}
|
|
3708
|
-
case "task.settled": {
|
|
3709
|
-
const existing = findToolPart(data, event.data.callId);
|
|
3710
|
-
if (existing === void 0) return data;
|
|
3711
|
-
const { error, output, status } = event.data;
|
|
3712
|
-
const outcome = status === "completed" ? { output } : { errorText: error?.message };
|
|
3713
|
-
return replaceToolPart(data, {
|
|
3714
|
-
...existing,
|
|
3715
|
-
...outcome
|
|
3716
|
-
});
|
|
3717
|
-
}
|
|
3718
|
-
case "authorization.required": return updateAssistantMessage(data, event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, event.data.stepIndex), createAuthorizationRequiredPart(event)));
|
|
3719
|
-
case "authorization.completed": return completeAuthorization(data, event);
|
|
3720
|
-
case "message.appended": return updateAssistantMessage(data, event.data.turnId, (message) => messageRun.transition(ensureStepStartPart(message, event.data.stepIndex), {
|
|
3721
|
-
kind: "append",
|
|
3722
|
-
delta: event.data.messageDelta,
|
|
3723
|
-
id: event.meta?.id,
|
|
3724
|
-
stepIndex: event.data.stepIndex,
|
|
3725
|
-
type: "text"
|
|
3726
|
-
}));
|
|
3727
|
-
case "message.completed": return updateAssistantMessage(data, event.data.turnId, (message) => messageRun.transition(ensureStepStartPart(message, event.data.stepIndex), {
|
|
3728
|
-
kind: "complete",
|
|
3729
|
-
stepIndex: event.data.stepIndex,
|
|
3730
|
-
text: event.data.message,
|
|
3731
|
-
id: event.meta?.id,
|
|
3732
|
-
type: "text"
|
|
3733
|
-
}));
|
|
3734
|
-
case "result.completed": return updateAssistantMessage(data, event.data.turnId, (message) => ({
|
|
3735
|
-
...message,
|
|
3736
|
-
metadata: {
|
|
3737
|
-
...message.metadata,
|
|
3738
|
-
result: event.data.result
|
|
3739
|
-
}
|
|
3740
|
-
}));
|
|
3741
|
-
case "turn.completed":
|
|
3742
|
-
case "turn.cancelled":
|
|
3743
|
-
case "turn.failed":
|
|
3744
|
-
if (event.type === "turn.failed" && !data.messages.some((message) => message.role === "assistant" && message.metadata?.turnId === event.data.turnId)) return data;
|
|
3745
|
-
return updateAssistantMessage(data, event.data.turnId, (message) => ({
|
|
3746
|
-
...message,
|
|
3747
|
-
metadata: {
|
|
3748
|
-
...message.metadata,
|
|
3749
|
-
status: "complete"
|
|
3750
|
-
},
|
|
3751
|
-
parts: removeUnsettledToolParts(closeStreamingRuns(message.parts), conversationProjection(data))
|
|
3752
|
-
}));
|
|
3753
|
-
default: return data;
|
|
3754
|
-
}
|
|
3755
|
-
}
|
|
3756
|
-
function importHistory(data, event) {
|
|
3757
|
-
const eventId = event.meta.id ?? `${event.data.turnId}:${event.data.sequence}`;
|
|
3758
|
-
const imported = event.data.messages.map((message, index) => ({
|
|
3759
|
-
id: `${eventId}:imported:${index}`,
|
|
3760
|
-
metadata: message.id === void 0 ? {
|
|
3761
|
-
imported: true,
|
|
3762
|
-
status: "complete"
|
|
3763
|
-
} : {
|
|
3764
|
-
historyId: message.id,
|
|
3765
|
-
imported: true,
|
|
3766
|
-
status: "complete"
|
|
3767
|
-
},
|
|
3768
|
-
parts: [message.role === "assistant" ? {
|
|
3769
|
-
state: "done",
|
|
3770
|
-
text: message.text,
|
|
3771
|
-
type: "text"
|
|
3772
|
-
} : {
|
|
3773
|
-
text: message.text,
|
|
3774
|
-
type: "text"
|
|
3775
|
-
}],
|
|
3776
|
-
role: message.role
|
|
3777
|
-
}));
|
|
3778
|
-
const ids = new Set(imported.map((message) => message.id));
|
|
3779
|
-
const messages = data.messages.filter((message) => !ids.has(message.id));
|
|
3780
|
-
const before = messages.findIndex((message) => message.metadata?.optimistic === true || message.role === "assistant" && message.metadata?.turnId === event.data.turnId);
|
|
3781
|
-
const at = before === -1 ? messages.length : before;
|
|
3782
|
-
return {
|
|
3783
|
-
...data,
|
|
3784
|
-
messages: [
|
|
3785
|
-
...messages.slice(0, at),
|
|
3786
|
-
...imported,
|
|
3787
|
-
...messages.slice(at)
|
|
3788
|
-
]
|
|
3789
|
-
};
|
|
3790
|
-
}
|
|
3791
|
-
function toolCallIds(data, event) {
|
|
3792
|
-
const byRequest = (requestId) => findToolPartByApprovalId(data, requestId)?.toolCallId ?? [];
|
|
3793
|
-
switch (event.type) {
|
|
3794
|
-
case "actions.requested": return event.data.actions.map((action) => action.callId);
|
|
3795
|
-
case "input.requested": return event.data.requests.map((request) => request.action.callId);
|
|
3796
|
-
case "action.result":
|
|
3797
|
-
case "action.partial": return [event.data.result.callId];
|
|
3798
|
-
case "task.started":
|
|
3799
|
-
case "task.settled": return [event.data.callId];
|
|
3800
|
-
case "input.resolved": return event.data.resolutions.flatMap((resolution) => byRequest(resolution.requestId));
|
|
3801
|
-
case "approval.settled": return [byRequest(event.data.requestId)].flat();
|
|
3802
|
-
default: return [];
|
|
3803
|
-
}
|
|
3804
|
-
}
|
|
3805
|
-
function withToolPartStates(data, callIds) {
|
|
3806
|
-
let next = data;
|
|
3807
|
-
for (const callId of new Set(callIds)) {
|
|
3808
|
-
const part = findToolPart(next, callId);
|
|
3809
|
-
if (part === void 0) continue;
|
|
3810
|
-
const derived = toolPartState(next, part);
|
|
3811
|
-
if (derived !== part) next = withConversationProjection(replaceToolPart(next, derived), conversationProjection(data));
|
|
3812
|
-
}
|
|
3813
|
-
return next;
|
|
3814
|
-
}
|
|
3815
|
-
function closeStreamingRuns(parts, stepIndex) {
|
|
3816
|
-
return parts.map((part) => (part.type === "text" || part.type === "reasoning") && part.state === "streaming" && (stepIndex === void 0 || part.stepIndex === stepIndex) ? {
|
|
3817
|
-
...part,
|
|
3818
|
-
state: "done"
|
|
3819
|
-
} : part);
|
|
3820
|
-
}
|
|
3821
|
-
function removeUnsettledToolParts(parts, projection) {
|
|
3822
|
-
return parts.filter((part) => {
|
|
3823
|
-
if (part.type !== "dynamic-tool") return true;
|
|
3824
|
-
if (part.state === "input-streaming") return false;
|
|
3825
|
-
if (part.state !== "input-available") return true;
|
|
3826
|
-
const call = projection.calls[part.toolCallId];
|
|
3827
|
-
return call === void 0 || call.taskId !== void 0 || reportedCallStatus(projection, call) !== "running";
|
|
3828
|
-
});
|
|
3829
|
-
}
|
|
3830
|
-
function updateAssistantMessage(data, turnId, update) {
|
|
3831
|
-
const message = data.messages.find((message) => message.role === "assistant" && message.metadata?.turnId === turnId) ?? createAssistantMessage(turnId);
|
|
3832
|
-
return upsertMessage(data, update(message));
|
|
3833
|
-
}
|
|
3834
|
-
function createAssistantMessage(turnId) {
|
|
3835
|
-
return {
|
|
3836
|
-
id: `${turnId}:assistant`,
|
|
3837
|
-
metadata: {
|
|
3838
|
-
status: "streaming",
|
|
3839
|
-
turnId
|
|
3840
|
-
},
|
|
3841
|
-
parts: [],
|
|
3842
|
-
role: "assistant"
|
|
3843
|
-
};
|
|
3844
|
-
}
|
|
3845
|
-
function ensureStepStartPart(message, stepIndex) {
|
|
3846
|
-
const stepStartCount = message.parts.filter((part) => part.type === "step-start").length;
|
|
3847
|
-
if (stepStartCount > stepIndex) return message;
|
|
3848
|
-
const missingCount = stepIndex - stepStartCount + 1;
|
|
3849
|
-
return {
|
|
3850
|
-
...message,
|
|
3851
|
-
parts: [...message.parts, ...Array.from({ length: missingCount }, () => ({ type: "step-start" }))]
|
|
3852
|
-
};
|
|
3853
|
-
}
|
|
3854
|
-
function upsertPart(message, next) {
|
|
3855
|
-
const index = message.parts.findIndex((part) => partKey(part) === partKey(next));
|
|
3856
|
-
const parts = index === -1 ? [...message.parts, next] : [
|
|
3857
|
-
...message.parts.slice(0, index),
|
|
3858
|
-
next,
|
|
3859
|
-
...message.parts.slice(index + 1)
|
|
3860
|
-
];
|
|
3861
|
-
return {
|
|
3862
|
-
...message,
|
|
3863
|
-
metadata: {
|
|
3864
|
-
...message.metadata,
|
|
3865
|
-
status: next.type === "text" && next.state === "done" ? "complete" : "streaming"
|
|
3866
|
-
},
|
|
3867
|
-
parts
|
|
3868
|
-
};
|
|
3869
|
-
}
|
|
3870
|
-
function upsertToolPart(data, turnId, stepIndex, part) {
|
|
3871
|
-
const updated = updateToolPart(data, part.toolCallId, part);
|
|
3872
|
-
return updated !== data ? updated : updateAssistantMessage(data, turnId, (message) => upsertPart(ensureStepStartPart(message, stepIndex), part));
|
|
3873
|
-
}
|
|
3874
|
-
function updateToolPart(data, toolCallId, next) {
|
|
3875
|
-
const message = data.messages.find((candidate) => candidate.role === "assistant" && candidate.parts.some((part) => part.type === "dynamic-tool" && part.toolCallId === toolCallId));
|
|
3876
|
-
if (!message) return data;
|
|
3877
|
-
return upsertMessage(data, upsertPart(message, next));
|
|
3878
|
-
}
|
|
3879
|
-
function replaceToolPart(data, next) {
|
|
3880
|
-
const message = data.messages.find((candidate) => candidate.parts.some((part) => part.type === "dynamic-tool" && part.toolCallId === next.toolCallId));
|
|
3881
|
-
if (message === void 0) return data;
|
|
3882
|
-
return upsertMessage(data, {
|
|
3883
|
-
...message,
|
|
3884
|
-
parts: message.parts.map((part) => partKey(part) === partKey(next) ? next : part)
|
|
3885
|
-
});
|
|
3886
|
-
}
|
|
3887
|
-
function completeAuthorization(data, event) {
|
|
3888
|
-
const existing = findPendingAuthorizationPart(data, event.data.name, event.data.attemptId);
|
|
3889
|
-
const next = createAuthorizationCompletedPart(event, existing);
|
|
3890
|
-
return updateAssistantMessage(data, existing?.turnId ?? event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, next.stepIndex), next));
|
|
3891
|
-
}
|
|
3892
|
-
function findToolPart(data, toolCallId) {
|
|
3893
|
-
for (const message of data.messages) for (const part of message.parts) if (part.type === "dynamic-tool" && part.toolCallId === toolCallId) return part;
|
|
3894
|
-
}
|
|
3895
|
-
function isSettledToolPart(part) {
|
|
3896
|
-
return part.state === "output-denied" || part.state === "output-error" || part.state === "output-available" && part.partial !== true;
|
|
3897
|
-
}
|
|
3898
|
-
function findPendingAuthorizationPart(data, name, attemptId) {
|
|
3899
|
-
for (let messageIndex = data.messages.length - 1; messageIndex >= 0; messageIndex -= 1) {
|
|
3900
|
-
const message = data.messages[messageIndex];
|
|
3901
|
-
if (message?.role !== "assistant") continue;
|
|
3902
|
-
for (let partIndex = message.parts.length - 1; partIndex >= 0; partIndex -= 1) {
|
|
3903
|
-
const part = message.parts[partIndex];
|
|
3904
|
-
if (part?.type === "authorization" && part.state === "required" && (attemptId === void 0 ? part.attemptId === void 0 && part.name === name : part.attemptId === attemptId)) return part;
|
|
3905
|
-
}
|
|
3906
|
-
}
|
|
3907
|
-
}
|
|
3908
|
-
function findToolPartByApprovalId(data, approvalId) {
|
|
3909
|
-
for (const message of data.messages) for (const part of message.parts) if (part.type === "dynamic-tool" && part.approval?.id === approvalId) return part;
|
|
3910
|
-
}
|
|
3911
|
-
|
|
3912
|
-
//#endregion
|
|
3913
|
-
//#region src/client/conversation-reducer.ts
|
|
3914
|
-
function initialConversationState() {
|
|
3915
|
-
return withConversationProjection({
|
|
3916
|
-
turns: {},
|
|
3917
|
-
inputs: {},
|
|
3918
|
-
tasks: {},
|
|
3919
|
-
messages: [],
|
|
3920
|
-
agents: {}
|
|
3921
|
-
}, initialSessionProjection());
|
|
3922
|
-
}
|
|
3923
|
-
function updateObservation(state, sessionId, update) {
|
|
3924
|
-
const agent = state.agents[sessionId];
|
|
3925
|
-
if (agent === void 0) return state;
|
|
3926
|
-
const observation = update(agent.observation);
|
|
3927
|
-
if (observation === agent.observation) return state;
|
|
3928
|
-
return {
|
|
3929
|
-
...state,
|
|
3930
|
-
agents: {
|
|
3931
|
-
...state.agents,
|
|
3932
|
-
[sessionId]: {
|
|
3933
|
-
...agent,
|
|
3934
|
-
observation
|
|
3935
|
-
}
|
|
3936
|
-
}
|
|
3937
|
-
};
|
|
3938
|
-
}
|
|
3939
|
-
function observedConversation(observation) {
|
|
3940
|
-
return observation.status === "not-followed" ? void 0 : observation.conversation;
|
|
3941
|
-
}
|
|
3942
|
-
function reduceConversationLifecycle(state, event) {
|
|
3943
|
-
switch (event.type) {
|
|
3944
|
-
case "agent.started": {
|
|
3945
|
-
const { callId, name, sessionId, taskId, turnId } = event.data;
|
|
3946
|
-
if (state.agents[sessionId] !== void 0) return state;
|
|
3947
|
-
const agent = {
|
|
3948
|
-
sessionId,
|
|
3949
|
-
name,
|
|
3950
|
-
callId,
|
|
3951
|
-
turnId,
|
|
3952
|
-
observation: { status: "not-followed" }
|
|
3953
|
-
};
|
|
3954
|
-
if (taskId !== void 0) agent.taskId = taskId;
|
|
3955
|
-
return withConversationProjection({
|
|
3956
|
-
...state,
|
|
3957
|
-
agents: {
|
|
3958
|
-
...state.agents,
|
|
3959
|
-
[sessionId]: agent
|
|
3960
|
-
}
|
|
3961
|
-
}, conversationProjection(state));
|
|
3962
|
-
}
|
|
3963
|
-
case "client.input.responded": {
|
|
3964
|
-
const inputs = { ...state.inputs };
|
|
3965
|
-
for (const response of event.data.responses) {
|
|
3966
|
-
const current = inputs[response.requestId];
|
|
3967
|
-
if (current?.status !== "open") continue;
|
|
3968
|
-
inputs[response.requestId] = {
|
|
3969
|
-
...current,
|
|
3970
|
-
response,
|
|
3971
|
-
status: "responded"
|
|
3972
|
-
};
|
|
3973
|
-
}
|
|
3974
|
-
const projection = conversationProjection(state);
|
|
3975
|
-
const projectedInputs = { ...projection.inputs };
|
|
3976
|
-
for (const response of event.data.responses) {
|
|
3977
|
-
const current = projectedInputs[response.requestId];
|
|
3978
|
-
if (current?.status === "open") projectedInputs[response.requestId] = {
|
|
3979
|
-
...current,
|
|
3980
|
-
response,
|
|
3981
|
-
status: "responded"
|
|
3982
|
-
};
|
|
3983
|
-
}
|
|
3984
|
-
return withConversationProjection({
|
|
3985
|
-
...state,
|
|
3986
|
-
inputs
|
|
3987
|
-
}, {
|
|
3988
|
-
...projection,
|
|
3989
|
-
inputs: projectedInputs
|
|
3990
|
-
});
|
|
3991
|
-
}
|
|
3992
|
-
default: return state;
|
|
3993
|
-
}
|
|
3994
|
-
}
|
|
3995
|
-
const messageReducer = defaultMessageReducer();
|
|
3996
|
-
function reduceConversation(state, event) {
|
|
3997
|
-
const next = reduceConversationEvent(state, event);
|
|
3998
|
-
return event.type.startsWith("client.agent.") ? withConversationProjection(next, conversationProjection(state)) : next;
|
|
3999
|
-
}
|
|
4000
|
-
function reduceConversationEvent(state, event) {
|
|
4001
|
-
switch (event.type) {
|
|
4002
|
-
case "client.agent.following": return updateObservation(state, event.data.sessionId, (observation) => observation.status === "following" ? observation : {
|
|
4003
|
-
status: "following",
|
|
4004
|
-
conversation: observedConversation(observation) ?? initialConversationState()
|
|
4005
|
-
});
|
|
4006
|
-
case "client.agent.observed": return updateObservation(state, event.data.sessionId, (observation) => observation.status === "following" ? {
|
|
4007
|
-
status: "following",
|
|
4008
|
-
conversation: reduceConversation(observation.conversation, event.data.event)
|
|
4009
|
-
} : observation);
|
|
4010
|
-
case "client.agent.idle": return updateObservation(state, event.data.sessionId, (observation) => observation.status === "following" ? {
|
|
4011
|
-
status: "idle",
|
|
4012
|
-
conversation: observation.conversation
|
|
4013
|
-
} : observation);
|
|
4014
|
-
case "client.agent.unavailable": return updateObservation(state, event.data.sessionId, (observation) => {
|
|
4015
|
-
const conversation = observedConversation(observation);
|
|
4016
|
-
return conversation === void 0 ? { status: "unavailable" } : {
|
|
4017
|
-
status: "unavailable",
|
|
4018
|
-
conversation
|
|
4019
|
-
};
|
|
4020
|
-
});
|
|
4021
|
-
default:
|
|
4022
|
-
const messages = messageReducer.reduce(state, event);
|
|
4023
|
-
const projection = conversationProjection(messages);
|
|
4024
|
-
const { activeTurnId: _activeTurnId, ...rest } = state;
|
|
4025
|
-
const { activeTurnId: _messageTurnId, ...messageData } = messages;
|
|
4026
|
-
const conversation = {
|
|
4027
|
-
...rest,
|
|
4028
|
-
...messageData,
|
|
4029
|
-
turns: Object.fromEntries(Object.entries(projection.turns).map(([id, turn]) => {
|
|
4030
|
-
const { turnId, status, waiting } = turn;
|
|
4031
|
-
const publicTurn = {
|
|
4032
|
-
turnId,
|
|
4033
|
-
status
|
|
4034
|
-
};
|
|
4035
|
-
if (waiting !== void 0) publicTurn.waiting = waiting;
|
|
4036
|
-
return [id, publicTurn];
|
|
4037
|
-
})),
|
|
4038
|
-
inputs: Object.fromEntries(Object.entries(projection.inputs).map(([id, input]) => {
|
|
4039
|
-
const { sequence: _sequence, callId: _callId, ...publicInput } = input;
|
|
4040
|
-
return [id, publicInput];
|
|
4041
|
-
})),
|
|
4042
|
-
tasks: projection.tasks
|
|
4043
|
-
};
|
|
4044
|
-
if (projection.activeTurnId !== void 0) conversation.activeTurnId = projection.activeTurnId;
|
|
4045
|
-
return reduceConversationLifecycle(withConversationProjection(conversation, projection), event);
|
|
4046
|
-
}
|
|
4047
|
-
}
|
|
4048
|
-
const canonicalConversationReducer = {
|
|
4049
|
-
initial: initialConversationState,
|
|
4050
|
-
reduce: reduceConversation
|
|
4051
|
-
};
|
|
4052
|
-
const conversationReducer = canonicalConversationReducer;
|
|
4053
|
-
|
|
4054
|
-
//#endregion
|
|
4055
|
-
//#region src/protocol/event-dedupe.ts
|
|
4056
|
-
function createEventDeduper() {
|
|
4057
|
-
const seen = /* @__PURE__ */ new Set();
|
|
4058
|
-
return {
|
|
4059
|
-
admit(event) {
|
|
4060
|
-
const id = event.meta?.id;
|
|
4061
|
-
if (id === void 0) return true;
|
|
4062
|
-
if (seen.has(id)) return false;
|
|
4063
|
-
seen.add(id);
|
|
4064
|
-
return true;
|
|
4065
|
-
},
|
|
4066
|
-
get size() {
|
|
4067
|
-
return seen.size;
|
|
4068
|
-
}
|
|
4069
|
-
};
|
|
4070
|
-
}
|
|
4071
|
-
|
|
4072
|
-
//#endregion
|
|
4073
|
-
//#region src/client/session-event-stream.ts
|
|
4074
|
-
var SessionEventStream = class {
|
|
4075
|
-
#controller = new AbortController();
|
|
4076
|
-
#readers = /* @__PURE__ */ new Set();
|
|
4077
|
-
#caughtUp = Promise.withResolvers();
|
|
4078
|
-
caughtUp = this.#caughtUp.promise;
|
|
4079
|
-
#ended = false;
|
|
4080
|
-
#error;
|
|
4081
|
-
#headers;
|
|
4082
|
-
#reconnectPolicy;
|
|
4083
|
-
constructor(session, options) {
|
|
4084
|
-
this.setOptions(options);
|
|
4085
|
-
this.caughtUp.catch(() => {});
|
|
4086
|
-
if (!options.catchUp) this.#caughtUp.resolve();
|
|
4087
|
-
(async () => {
|
|
4088
|
-
try {
|
|
4089
|
-
for await (const event of followClientSession(session, {
|
|
4090
|
-
signal: this.#controller.signal,
|
|
4091
|
-
resolveHeaders: () => this.#headers,
|
|
4092
|
-
resolveReconnectPolicy: () => this.#reconnectPolicy,
|
|
4093
|
-
startIndex: options.startIndex,
|
|
4094
|
-
onCaughtUp: options.catchUp ? () => this.#caughtUp.resolve() : void 0
|
|
4095
|
-
})) {
|
|
4096
|
-
if (this.#controller.signal.aborted) return;
|
|
4097
|
-
options.onEvent(event);
|
|
4098
|
-
for (const reader of this.#readers) reader.push(event);
|
|
4099
|
-
if (event.type === "session.completed" || event.type === "session.failed") break;
|
|
4100
|
-
}
|
|
4101
|
-
this.#caughtUp.resolve();
|
|
4102
|
-
this.#finish();
|
|
4103
|
-
} catch (error) {
|
|
4104
|
-
this.#caughtUp.reject(error);
|
|
4105
|
-
this.#finish(error);
|
|
4106
|
-
if (!this.#controller.signal.aborted) options.onError(error);
|
|
4107
|
-
}
|
|
4108
|
-
})();
|
|
4109
|
-
}
|
|
4110
|
-
subscribe(signal) {
|
|
4111
|
-
const reader = new SessionEventReader(() => this.#readers.delete(reader), signal);
|
|
4112
|
-
if (this.#ended) reader.end(this.#error);
|
|
4113
|
-
else this.#readers.add(reader);
|
|
4114
|
-
return reader;
|
|
4115
|
-
}
|
|
4116
|
-
get ended() {
|
|
4117
|
-
return this.#ended;
|
|
4118
|
-
}
|
|
4119
|
-
setOptions(options) {
|
|
4120
|
-
if ("headers" in options) this.#headers = options.headers;
|
|
4121
|
-
if ("streamReconnectPolicy" in options) this.#reconnectPolicy = options.streamReconnectPolicy;
|
|
4122
|
-
}
|
|
4123
|
-
close() {
|
|
4124
|
-
const error = new DOMException("Session stream was detached.", "AbortError");
|
|
4125
|
-
this.#controller.abort(error);
|
|
4126
|
-
this.#caughtUp.reject(error);
|
|
4127
|
-
this.#finish(error);
|
|
4128
|
-
}
|
|
4129
|
-
#finish(error) {
|
|
4130
|
-
if (this.#ended) return;
|
|
4131
|
-
this.#ended = true;
|
|
4132
|
-
this.#error = error;
|
|
4133
|
-
for (const reader of this.#readers) reader.end(error);
|
|
4134
|
-
}
|
|
4135
|
-
};
|
|
4136
|
-
var SessionEventReader = class {
|
|
4137
|
-
#events = [];
|
|
4138
|
-
#wake = Promise.withResolvers();
|
|
4139
|
-
#ended = false;
|
|
4140
|
-
#error;
|
|
4141
|
-
#dispose;
|
|
4142
|
-
constructor(unsubscribe, signal) {
|
|
4143
|
-
const abort = () => this.end(signal?.reason);
|
|
4144
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
4145
|
-
this.#dispose = () => {
|
|
4146
|
-
signal?.removeEventListener("abort", abort);
|
|
4147
|
-
unsubscribe();
|
|
4148
|
-
};
|
|
4149
|
-
if (signal?.aborted) abort();
|
|
4150
|
-
}
|
|
4151
|
-
push(event) {
|
|
4152
|
-
if (this.#ended) return;
|
|
4153
|
-
this.#events.push(event);
|
|
4154
|
-
this.#wake.resolve();
|
|
4155
|
-
}
|
|
4156
|
-
end(error) {
|
|
4157
|
-
if (this.#ended) return;
|
|
4158
|
-
this.#ended = true;
|
|
4159
|
-
this.#error = error;
|
|
4160
|
-
this.#wake.resolve();
|
|
4161
|
-
}
|
|
4162
|
-
[Symbol.dispose]() {
|
|
4163
|
-
this.end();
|
|
4164
|
-
this.#events = [];
|
|
4165
|
-
this.#dispose();
|
|
4166
|
-
}
|
|
4167
|
-
discard() {
|
|
4168
|
-
this.#events = [];
|
|
4169
|
-
}
|
|
4170
|
-
async *[Symbol.asyncIterator]() {
|
|
4171
|
-
for (;;) {
|
|
4172
|
-
while (this.#events.length > 0) yield this.#events.shift();
|
|
4173
|
-
if (this.#ended) {
|
|
4174
|
-
if (this.#error !== void 0) throw this.#error;
|
|
4175
|
-
return;
|
|
4176
|
-
}
|
|
4177
|
-
this.#wake = Promise.withResolvers();
|
|
4178
|
-
await this.#wake.promise;
|
|
4179
|
-
}
|
|
4180
|
-
}
|
|
4181
|
-
};
|
|
4182
|
-
|
|
4183
|
-
//#endregion
|
|
4184
|
-
//#region src/client/conversation-client.ts
|
|
4185
|
-
var ConversationClient = class {
|
|
4186
|
-
projection;
|
|
4187
|
-
#conversation;
|
|
4188
|
-
#cursors = /* @__PURE__ */ new Map();
|
|
4189
|
-
#seenEvents = createEventDeduper();
|
|
4190
|
-
#follower;
|
|
4191
|
-
#stream;
|
|
4192
|
-
#onChange;
|
|
4193
|
-
#onConversationChange;
|
|
4194
|
-
constructor(projection, onChange, onConversationChange) {
|
|
4195
|
-
this.projection = projection;
|
|
4196
|
-
this.#conversation = projection.reducer === conversationReducer ? projection : new EveAgentProjection(canonicalConversationReducer, []);
|
|
4197
|
-
this.#onChange = onChange;
|
|
4198
|
-
this.#onConversationChange = onConversationChange;
|
|
4199
|
-
}
|
|
4200
|
-
get data() {
|
|
4201
|
-
return this.projection.data;
|
|
4202
|
-
}
|
|
4203
|
-
get conversation() {
|
|
4204
|
-
return this.#conversation.data;
|
|
4205
|
-
}
|
|
4206
|
-
get projections() {
|
|
4207
|
-
return this.#conversation === this.projection ? [this.projection] : [this.#conversation, this.projection];
|
|
4208
|
-
}
|
|
4209
|
-
get following() {
|
|
4210
|
-
return this.#follower !== void 0;
|
|
4211
|
-
}
|
|
4212
|
-
append(event) {
|
|
4213
|
-
const previous = this.data;
|
|
4214
|
-
const previousConversation = this.conversation;
|
|
4215
|
-
this.#appendRoot(event);
|
|
4216
|
-
if (previous !== this.data) this.#onChange(this.data, previous);
|
|
4217
|
-
else if (previousConversation !== this.conversation) this.#onConversationChange?.(this.conversation, previousConversation);
|
|
4218
|
-
}
|
|
4219
|
-
projectResponses(responses) {
|
|
4220
|
-
if (!responses?.length) return void 0;
|
|
4221
|
-
const event = {
|
|
4222
|
-
data: {
|
|
4223
|
-
createdAt: Date.now(),
|
|
4224
|
-
responses
|
|
4225
|
-
},
|
|
4226
|
-
type: "client.input.responded"
|
|
4227
|
-
};
|
|
4228
|
-
this.append(event);
|
|
4229
|
-
return () => this.#retract(event);
|
|
4230
|
-
}
|
|
4231
|
-
replaceResponses(retract, input) {
|
|
4232
|
-
retract?.();
|
|
4233
|
-
assertAnswerable(input, this.conversation);
|
|
4234
|
-
return this.projectResponses(input.inputResponses);
|
|
4235
|
-
}
|
|
4236
|
-
#retract(event) {
|
|
4237
|
-
const previous = this.data;
|
|
4238
|
-
const previousConversation = this.conversation;
|
|
4239
|
-
for (const projection of this.projections) projection.remove((entry) => entry === event);
|
|
4240
|
-
if (previous !== this.data) this.#onChange(this.data, previous);
|
|
4241
|
-
else if (previousConversation !== this.conversation) this.#onConversationChange?.(this.conversation, previousConversation);
|
|
4242
|
-
}
|
|
4243
|
-
observe(event, options = {}) {
|
|
4244
|
-
if (!this.#seenEvents.admit(event)) return false;
|
|
4245
|
-
options.onAccepted?.(event);
|
|
4246
|
-
const previous = this.data;
|
|
4247
|
-
const previousConversation = this.conversation;
|
|
4248
|
-
if (options.project) options.project(event);
|
|
4249
|
-
else this.#appendRoot(event);
|
|
4250
|
-
if (options.notify !== false) {
|
|
4251
|
-
if (previous !== this.data) this.#onChange(this.data, previous);
|
|
4252
|
-
else if (previousConversation !== this.conversation) this.#onConversationChange?.(this.conversation, previousConversation);
|
|
4253
|
-
}
|
|
4254
|
-
this.#follower?.acceptParentEvent(event);
|
|
4255
|
-
this.#follower?.reconcile();
|
|
4256
|
-
return true;
|
|
4257
|
-
}
|
|
4258
|
-
hydrate(event) {
|
|
4259
|
-
if (!this.#seenEvents.admit(event)) return false;
|
|
4260
|
-
this.#appendRoot(event);
|
|
4261
|
-
return true;
|
|
4262
|
-
}
|
|
4263
|
-
follow(session, events = []) {
|
|
4264
|
-
this.#follower?.abortAll();
|
|
4265
|
-
const follower = new AgentStreamFollower({
|
|
4266
|
-
session,
|
|
4267
|
-
cursors: this.#cursors,
|
|
4268
|
-
getState: () => this.conversation,
|
|
4269
|
-
onFollowing: (sessionId) => this.#appendChild({
|
|
4270
|
-
type: "client.agent.following",
|
|
4271
|
-
data: { sessionId }
|
|
4272
|
-
}),
|
|
4273
|
-
onEvent: (sessionId, event) => this.#appendChild({
|
|
4274
|
-
type: "client.agent.observed",
|
|
4275
|
-
data: {
|
|
4276
|
-
sessionId,
|
|
4277
|
-
event
|
|
4278
|
-
}
|
|
4279
|
-
}),
|
|
4280
|
-
onIdle: (sessionId) => this.#appendChild({
|
|
4281
|
-
type: "client.agent.idle",
|
|
4282
|
-
data: { sessionId }
|
|
4283
|
-
}),
|
|
4284
|
-
onUnavailable: (sessionId) => this.#appendChild({
|
|
4285
|
-
type: "client.agent.unavailable",
|
|
4286
|
-
data: { sessionId }
|
|
4287
|
-
})
|
|
4288
|
-
});
|
|
4289
|
-
this.#follower = follower;
|
|
4290
|
-
for (const event of events) follower.acceptParentEvent(event);
|
|
4291
|
-
follower.reconcile();
|
|
4292
|
-
}
|
|
4293
|
-
#appendRoot(event) {
|
|
4294
|
-
for (const projection of this.projections) projection.append(event);
|
|
4295
|
-
}
|
|
4296
|
-
#appendChild(event) {
|
|
4297
|
-
const previous = this.data;
|
|
4298
|
-
const previousConversation = this.conversation;
|
|
4299
|
-
this.#conversation.append(event);
|
|
4300
|
-
if (previous !== this.data) this.#onChange(this.data, previous);
|
|
4301
|
-
else if (previousConversation !== this.conversation) this.#onConversationChange?.(this.conversation, previousConversation);
|
|
4302
|
-
}
|
|
4303
|
-
stream(session, options) {
|
|
4304
|
-
if (this.#stream !== void 0 && !this.#stream.ended) {
|
|
4305
|
-
this.#stream.setOptions(options);
|
|
4306
|
-
return this.#stream;
|
|
4307
|
-
}
|
|
4308
|
-
this.#stream = new SessionEventStream(session, options);
|
|
4309
|
-
return this.#stream;
|
|
4310
|
-
}
|
|
4311
|
-
closeStream() {
|
|
4312
|
-
this.#stream?.close();
|
|
4313
|
-
this.#stream = void 0;
|
|
4314
|
-
}
|
|
4315
|
-
stop() {
|
|
4316
|
-
this.#follower?.abortAll();
|
|
4317
|
-
this.#follower = void 0;
|
|
4318
|
-
this.closeStream();
|
|
4319
|
-
}
|
|
4320
|
-
reset() {
|
|
4321
|
-
this.stop();
|
|
4322
|
-
this.#cursors.clear();
|
|
4323
|
-
this.#seenEvents = createEventDeduper();
|
|
4324
|
-
for (const projection of this.projections) projection.reset();
|
|
4325
|
-
}
|
|
4326
|
-
};
|
|
4327
|
-
|
|
4328
|
-
//#endregion
|
|
4329
|
-
//#region src/client/session-turn-dispatch.ts
|
|
4330
|
-
async function dispatchSessionTurn(input) {
|
|
4331
|
-
const { client, session, turn, beforeSend } = input;
|
|
4332
|
-
if (session === void 0) {
|
|
4333
|
-
if (client === void 0) throw new Error("An external eve session is required before sending.");
|
|
4334
|
-
if (turn.message === void 0) throw new Error("Cannot answer an input request before the session starts.");
|
|
4335
|
-
const created = await client.sessions.create({
|
|
4336
|
-
...turn,
|
|
4337
|
-
message: turn.message
|
|
4338
|
-
});
|
|
4339
|
-
throwIfAborted(turn.signal);
|
|
4340
|
-
return {
|
|
4341
|
-
...created,
|
|
4342
|
-
created: true
|
|
4343
|
-
};
|
|
4344
|
-
}
|
|
4345
|
-
beforeSend?.();
|
|
4346
|
-
if (turn.inputResponses === void 0) {
|
|
4347
|
-
const { message, ...options } = turn;
|
|
4348
|
-
return {
|
|
4349
|
-
session,
|
|
4350
|
-
response: await session.send(message, options),
|
|
4351
|
-
created: false
|
|
4352
|
-
};
|
|
4353
|
-
}
|
|
4354
|
-
const { inputResponses, ...options } = turn;
|
|
4355
|
-
return {
|
|
4356
|
-
session,
|
|
4357
|
-
response: await session.respond(inputResponses, options),
|
|
4358
|
-
created: false
|
|
4359
|
-
};
|
|
4360
|
-
}
|
|
4361
|
-
|
|
4362
|
-
//#endregion
|
|
4363
|
-
//#region src/client/eve-agent-store.ts
|
|
4364
|
-
const detachStore = Symbol("detachEveAgentStore");
|
|
4365
|
-
const attachStore = Symbol("attachEveAgentStore");
|
|
4366
|
-
var EveAgentStore = class {
|
|
4367
|
-
#client;
|
|
4368
|
-
#autoPrewarm;
|
|
4369
|
-
#attached = false;
|
|
4370
|
-
#conversationClient;
|
|
4371
|
-
#followChildStreams;
|
|
4372
|
-
#followIdle;
|
|
4373
|
-
#externalSession;
|
|
4374
|
-
#subscribers = /* @__PURE__ */ new Set();
|
|
4375
|
-
#activeTurn;
|
|
4376
|
-
#callbacks = {};
|
|
4377
|
-
#error;
|
|
4378
|
-
#events;
|
|
4379
|
-
#messageSubmissions;
|
|
4380
|
-
#prewarmGeneration = 0;
|
|
4381
|
-
#prewarmPromise;
|
|
4382
|
-
#prewarmController;
|
|
4383
|
-
#resumePromise;
|
|
4384
|
-
#session;
|
|
4385
|
-
#snapshot;
|
|
4386
|
-
#status = "ready";
|
|
4387
|
-
constructor(init) {
|
|
4388
|
-
this.#autoPrewarm = init.prewarm ?? false;
|
|
4389
|
-
this.#followChildStreams = init.followSubagents ?? false;
|
|
4390
|
-
this.#followIdle = init.followIdle ?? true;
|
|
4391
|
-
this.#externalSession = init.session !== void 0;
|
|
4392
|
-
this.#client = this.#externalSession ? void 0 : init.client ?? new Client({
|
|
4393
|
-
auth: init.auth,
|
|
4394
|
-
headers: init.headers,
|
|
4395
|
-
host: init.host ?? ""
|
|
4396
|
-
});
|
|
4397
|
-
this.#conversationClient = new ConversationClient(new EveAgentProjection(init.reducer, []), () => this.#publish(), () => this.#publish());
|
|
4398
|
-
this.#events = (init.initialEvents ?? []).filter((event) => this.#conversationClient.hydrate(event));
|
|
4399
|
-
this.#messageSubmissions = new OptimisticMessageSubmissions(this.#conversationClient.projections, init.optimistic ?? true);
|
|
4400
|
-
this.#session = init.session ?? (init.initialSession === void 0 ? void 0 : this.#client?.sessions.attach(init.initialSession.sessionId, { streamIndex: init.initialSession.streamIndex }));
|
|
4401
|
-
this.#snapshot = this.#createSnapshot();
|
|
4402
|
-
}
|
|
4403
|
-
get snapshot() {
|
|
4404
|
-
return this.#snapshot;
|
|
4405
|
-
}
|
|
4406
|
-
setCallbacks(callbacks) {
|
|
4407
|
-
this.#callbacks = callbacks;
|
|
4408
|
-
}
|
|
4409
|
-
subscribe(callback) {
|
|
4410
|
-
this.#subscribers.add(callback);
|
|
4411
|
-
return () => void this.#subscribers.delete(callback);
|
|
4412
|
-
}
|
|
4413
|
-
prewarm() {
|
|
4414
|
-
if (this.#prewarmPromise !== void 0) return this.#prewarmPromise;
|
|
4415
|
-
if (this.#session === void 0 && this.#externalSession) return Promise.resolve();
|
|
4416
|
-
if (this.#activeTurn !== void 0 && this.#session === void 0) return this.#activeTurn.response.then((response) => {
|
|
4417
|
-
if (response === void 0) throw this.#error ?? new DOMException("Session creation was aborted.", "AbortError");
|
|
4418
|
-
});
|
|
4419
|
-
const client = this.#client;
|
|
4420
|
-
const session = this.#session;
|
|
4421
|
-
if (client === void 0 && session === void 0) return Promise.reject(/* @__PURE__ */ new Error("This eve agent store does not own a session client."));
|
|
4422
|
-
const generation = this.#prewarmGeneration;
|
|
4423
|
-
const controller = new AbortController();
|
|
4424
|
-
this.#prewarmController = controller;
|
|
4425
|
-
const promise = (async () => {
|
|
4426
|
-
try {
|
|
4427
|
-
if (session !== void 0) {
|
|
4428
|
-
await session.prewarm({ signal: controller.signal });
|
|
4429
|
-
return;
|
|
4430
|
-
}
|
|
4431
|
-
const created = await client.sessions.create({ signal: controller.signal });
|
|
4432
|
-
if (generation !== this.#prewarmGeneration) return;
|
|
4433
|
-
this.#error = void 0;
|
|
4434
|
-
if (this.#status === "error") this.#status = "ready";
|
|
4435
|
-
this.#adoptSession(created.session);
|
|
4436
|
-
if (this.#followIdle) this.#ensureStream();
|
|
4437
|
-
} catch (error) {
|
|
4438
|
-
if (session === void 0 && generation === this.#prewarmGeneration && this.#activeTurn === void 0 && this.#error === void 0) this.#fail(error);
|
|
4439
|
-
throw error;
|
|
4440
|
-
}
|
|
4441
|
-
})();
|
|
4442
|
-
this.#prewarmPromise = promise;
|
|
4443
|
-
const clear = () => {
|
|
4444
|
-
if (this.#prewarmPromise === promise) {
|
|
4445
|
-
this.#prewarmPromise = void 0;
|
|
4446
|
-
this.#prewarmController = void 0;
|
|
4447
|
-
}
|
|
4448
|
-
};
|
|
4449
|
-
promise.then(clear, clear);
|
|
4450
|
-
return promise;
|
|
4451
|
-
}
|
|
4452
|
-
async send(input) {
|
|
4453
|
-
return await this.#submit(input, this.#callbacks.prepareSend);
|
|
4454
|
-
}
|
|
4455
|
-
async #submit(input, prepareSend) {
|
|
4456
|
-
assertAnswerable(input, this.#conversationClient.conversation);
|
|
4457
|
-
if (this.#activeTurn !== void 0) {
|
|
4458
|
-
if (this.#status === "resuming") throw new Error("eve session is resuming.");
|
|
4459
|
-
return await this.#sendFollowUp(this.#activeTurn, input, prepareSend);
|
|
4460
|
-
}
|
|
4461
|
-
const turn = createActiveTurn((turn) => turn.acceptedFollowUps > 0 && this.#session !== void 0 ? this.#session.cancel() : turn.response.then((response) => response === void 0 ? { status: "no_active_turn" } : response.cancel()));
|
|
4462
|
-
this.#activeTurn = turn;
|
|
4463
|
-
this.#error = void 0;
|
|
4464
|
-
this.#status = "submitted";
|
|
4465
|
-
let reader;
|
|
4466
|
-
let submissionId;
|
|
4467
|
-
let retractResponses;
|
|
4468
|
-
try {
|
|
4469
|
-
assertExclusiveTurnInput(input);
|
|
4470
|
-
submissionId = this.#messageSubmissions.submit(input, this.#events.length);
|
|
4471
|
-
retractResponses = this.#conversationClient.projectResponses(input.inputResponses);
|
|
4472
|
-
this.#publish();
|
|
4473
|
-
const preparedInput = await (prepareSend === void 0 ? input : waitWithSignal(Promise.resolve(prepareSend(input)), createAbortSignal(input.signal, turn.abortController.signal)));
|
|
4474
|
-
assertExclusiveTurnInput(preparedInput);
|
|
4475
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4476
|
-
if (preparedInput !== input) {
|
|
4477
|
-
submissionId = this.#messageSubmissions.resubmit(submissionId, preparedInput);
|
|
4478
|
-
retractResponses = this.#conversationClient.replaceResponses(retractResponses, preparedInput);
|
|
4479
|
-
this.#publish();
|
|
4480
|
-
}
|
|
4481
|
-
const turnInput = {
|
|
4482
|
-
...preparedInput,
|
|
4483
|
-
signal: createAbortSignal(preparedInput.signal, turn.abortController.signal)
|
|
4484
|
-
};
|
|
4485
|
-
const dispatched = await this.#dispatchTurn(turnInput);
|
|
4486
|
-
retractResponses = void 0;
|
|
4487
|
-
const response = dispatched.response;
|
|
4488
|
-
reader = dispatched.reader;
|
|
4489
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4490
|
-
turn.resolveResponse(response);
|
|
4491
|
-
this.#correlate(submissionId, response);
|
|
4492
|
-
for await (const event of consumeMessageResponse(response, reader)) {
|
|
4493
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4494
|
-
turn.receivedFollowUps += turn.receivedFollowUpEvents.get(event) ?? 0;
|
|
4495
|
-
turn.receivedFollowUpEvents.delete(event);
|
|
4496
|
-
}
|
|
4497
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4498
|
-
await followSteeredTurns(turn, reader, () => this.#isActiveTurn(turn));
|
|
4499
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4500
|
-
this.#status = settledStatus(this.#error, this.#conversationClient.conversation);
|
|
4501
|
-
} catch (error) {
|
|
4502
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4503
|
-
retractResponses?.();
|
|
4504
|
-
if (isAbortError(error)) {
|
|
4505
|
-
this.#status = "ready";
|
|
4506
|
-
this.#messageSubmissions.fail(toError(error), submissionId);
|
|
4507
|
-
} else {
|
|
4508
|
-
const reported = this.#error !== void 0;
|
|
4509
|
-
this.#error ??= toError(error);
|
|
4510
|
-
this.#status = "error";
|
|
4511
|
-
this.#messageSubmissions.fail(this.#error, submissionId);
|
|
4512
|
-
if (!reported) this.#callbacks.onError?.(this.#error);
|
|
4513
|
-
}
|
|
4514
|
-
} finally {
|
|
4515
|
-
reader?.[Symbol.dispose]();
|
|
4516
|
-
this.#finishTurn(turn);
|
|
4517
|
-
}
|
|
4518
|
-
}
|
|
4519
|
-
resume() {
|
|
4520
|
-
if (this.#resumePromise !== void 0) return this.#resumePromise;
|
|
4521
|
-
const promise = this.#resume();
|
|
4522
|
-
this.#resumePromise = promise;
|
|
4523
|
-
const clear = () => {
|
|
4524
|
-
if (this.#resumePromise === promise) this.#resumePromise = void 0;
|
|
4525
|
-
};
|
|
4526
|
-
promise.then(clear, clear);
|
|
4527
|
-
return promise;
|
|
4528
|
-
}
|
|
4529
|
-
async #resume() {
|
|
4530
|
-
if (this.#status !== "ready" && this.#status !== "error") throw new Error("eve session is already processing a turn.");
|
|
4531
|
-
if (this.#session === void 0) throw new Error("An eve session is required before resuming.");
|
|
4532
|
-
const session = this.#session;
|
|
4533
|
-
const turn = createActiveTurn(() => session.cancel());
|
|
4534
|
-
this.#activeTurn = turn;
|
|
4535
|
-
turn.resolveResponse(void 0);
|
|
4536
|
-
this.#error = void 0;
|
|
4537
|
-
this.#status = "resuming";
|
|
4538
|
-
this.#publish();
|
|
4539
|
-
let reader;
|
|
4540
|
-
try {
|
|
4541
|
-
const stream = this.#ensureStream({
|
|
4542
|
-
catchUp: true,
|
|
4543
|
-
startIndex: this.#events.length === session.state.streamIndex ? session.state.streamIndex : 0
|
|
4544
|
-
});
|
|
4545
|
-
reader = stream.subscribe(turn.abortController.signal);
|
|
4546
|
-
await stream.caughtUp;
|
|
4547
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4548
|
-
reader.discard();
|
|
4549
|
-
const tail = this.#events.at(-1);
|
|
4550
|
-
if (tail !== void 0) this.#applyTerminalStreamFailure(tail);
|
|
4551
|
-
if (tail && !this.#error && !isSettledSessionTail(this.#events, this.#conversationClient.conversation)) {
|
|
4552
|
-
this.#status = "streaming";
|
|
4553
|
-
this.#publish();
|
|
4554
|
-
for await (const event of reader) {
|
|
4555
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4556
|
-
turn.receivedFollowUps += turn.receivedFollowUpEvents.get(event) ?? 0;
|
|
4557
|
-
turn.receivedFollowUpEvents.delete(event);
|
|
4558
|
-
if (isResponseBoundary(event, this.#conversationClient.conversation)) break;
|
|
4559
|
-
}
|
|
4560
|
-
}
|
|
4561
|
-
await followSteeredTurns(turn, reader, () => this.#isActiveTurn(turn));
|
|
4562
|
-
if (this.#isActiveTurn(turn)) this.#status = settledStatus(this.#error, this.#conversationClient.conversation);
|
|
4563
|
-
} catch (error) {
|
|
4564
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4565
|
-
if (isAbortError(error)) this.#status = "ready";
|
|
4566
|
-
else {
|
|
4567
|
-
this.#error = toError(error);
|
|
4568
|
-
this.#status = "error";
|
|
4569
|
-
this.#callbacks.onError?.(this.#error);
|
|
4570
|
-
}
|
|
4571
|
-
} finally {
|
|
4572
|
-
reader?.[Symbol.dispose]();
|
|
4573
|
-
this.#finishTurn(turn);
|
|
4574
|
-
}
|
|
4575
|
-
}
|
|
4576
|
-
cancel() {
|
|
4577
|
-
const turn = this.#activeTurn;
|
|
4578
|
-
if (turn === void 0) return this.#status === "streaming" && this.#session !== void 0 ? this.#session.cancel() : Promise.resolve({ status: "no_active_turn" });
|
|
4579
|
-
return turn.cancel();
|
|
4580
|
-
}
|
|
4581
|
-
async compact() {
|
|
4582
|
-
return await this.#session?.compact() ?? { status: "no_active_session" };
|
|
4583
|
-
}
|
|
4584
|
-
async clear() {
|
|
4585
|
-
return await this.#session?.clear() ?? { status: "no_active_session" };
|
|
4586
|
-
}
|
|
4587
|
-
async retire() {
|
|
4588
|
-
if (this.#externalSession) throw new Error("retire() needs a store-owned session. Call reset() on the session you supplied, then create a new store for the next session.");
|
|
4589
|
-
const result = await this.#session?.reset() ?? { status: "no_active_session" };
|
|
4590
|
-
this.reset();
|
|
4591
|
-
return result;
|
|
4592
|
-
}
|
|
4593
|
-
[attachStore]() {
|
|
4594
|
-
this.#attached = true;
|
|
4595
|
-
if (this.#followChildStreams && !this.#conversationClient.following) this.#followSubagents();
|
|
4596
|
-
if (this.#autoPrewarm && this.#session === void 0) this.prewarm().catch(() => {});
|
|
4597
|
-
}
|
|
4598
|
-
[detachStore]() {
|
|
4599
|
-
this.#attached = false;
|
|
4600
|
-
this.#conversationClient.stop();
|
|
4601
|
-
this.#activeTurn?.abortController.abort();
|
|
4602
|
-
this.#resetPrewarm();
|
|
4603
|
-
this.#resumePromise = void 0;
|
|
4604
|
-
}
|
|
4605
|
-
reset() {
|
|
4606
|
-
this.#conversationClient.stop();
|
|
4607
|
-
const turn = this.#activeTurn;
|
|
4608
|
-
this.#activeTurn = void 0;
|
|
4609
|
-
turn?.resolveResponse(void 0);
|
|
4610
|
-
turn?.resolveCompletion();
|
|
4611
|
-
turn?.abortController.abort();
|
|
4612
|
-
this.#resetPrewarm();
|
|
4613
|
-
this.#resumePromise = void 0;
|
|
4614
|
-
if (!this.#externalSession) this.#session = void 0;
|
|
4615
|
-
this.#events = [];
|
|
4616
|
-
this.#conversationClient.reset();
|
|
4617
|
-
this.#messageSubmissions.reset();
|
|
4618
|
-
if (this.#followChildStreams && this.#attached) this.#followSubagents();
|
|
4619
|
-
this.#error = void 0;
|
|
4620
|
-
this.#status = "ready";
|
|
4621
|
-
this.#callbacks.onSessionChange?.(this.#session?.state);
|
|
4622
|
-
this.#publish();
|
|
4623
|
-
if (this.#autoPrewarm && this.#attached) this.prewarm().catch(() => {});
|
|
4624
|
-
}
|
|
4625
|
-
async #sendFollowUp(turn, input, prepareSend) {
|
|
4626
|
-
assertInFlightFollowUp(input);
|
|
4627
|
-
const generation = this.#prewarmGeneration;
|
|
4628
|
-
const signal = createAbortSignal(input.signal, turn.abortController.signal);
|
|
4629
|
-
let retractResponses = this.#conversationClient.projectResponses(input.inputResponses);
|
|
4630
|
-
const preparedInput = await waitWithSignal(Promise.resolve(prepareSend?.(input)), signal).then((prepared) => {
|
|
4631
|
-
const next = validateFollowUp(prepared ?? input);
|
|
4632
|
-
if (next === input) return next;
|
|
4633
|
-
retractResponses = this.#conversationClient.replaceResponses(retractResponses, next);
|
|
4634
|
-
return next;
|
|
4635
|
-
}).catch((error) => {
|
|
4636
|
-
retractResponses?.();
|
|
4637
|
-
throw error;
|
|
4638
|
-
});
|
|
4639
|
-
if (generation !== this.#prewarmGeneration) return;
|
|
4640
|
-
if (!this.#isActiveTurn(turn)) {
|
|
4641
|
-
retractResponses?.();
|
|
4642
|
-
return await this.#submit(preparedInput);
|
|
4643
|
-
}
|
|
4644
|
-
const submissionId = this.#messageSubmissions.submit(preparedInput, this.#events.length, activeTurnForOptimisticFollowUp(this.#events));
|
|
4645
|
-
if (submissionId !== void 0) turn.followUpSubmissionIds.add(submissionId);
|
|
4646
|
-
this.#publish();
|
|
4647
|
-
let dispatch;
|
|
4648
|
-
dispatch = (async () => {
|
|
4649
|
-
try {
|
|
4650
|
-
const signal = createAbortSignal(preparedInput.signal, turn.abortController.signal);
|
|
4651
|
-
await waitWithSignal(turn.response, signal);
|
|
4652
|
-
if (!this.#isActiveTurn(turn) || this.#session === void 0) throw new Error("The active eve turn ended before the follow-up could be sent.");
|
|
4653
|
-
this.#ensureStream({
|
|
4654
|
-
headers: preparedInput.headers,
|
|
4655
|
-
streamReconnectPolicy: preparedInput.streamReconnectPolicy
|
|
4656
|
-
});
|
|
4657
|
-
const response = (await dispatchSessionTurn({
|
|
4658
|
-
session: this.#session,
|
|
4659
|
-
turn: {
|
|
4660
|
-
...preparedInput,
|
|
4661
|
-
signal
|
|
4662
|
-
}
|
|
4663
|
-
})).response;
|
|
4664
|
-
retractResponses = void 0;
|
|
4665
|
-
if (preparedInput.message === void 0) return;
|
|
4666
|
-
turn.acceptedFollowUps += 1;
|
|
4667
|
-
this.#correlate(submissionId, response);
|
|
4668
|
-
} catch (error) {
|
|
4669
|
-
if (this.#isActiveTurn(turn)) {
|
|
4670
|
-
this.#messageSubmissions.fail(toError(error), submissionId);
|
|
4671
|
-
retractResponses?.();
|
|
4672
|
-
this.#publish();
|
|
4673
|
-
}
|
|
4674
|
-
throw error;
|
|
4675
|
-
} finally {
|
|
4676
|
-
turn.followUpDispatches.delete(dispatch);
|
|
4677
|
-
}
|
|
4678
|
-
})();
|
|
4679
|
-
turn.followUpDispatches.add(dispatch);
|
|
4680
|
-
await dispatch;
|
|
4681
|
-
await turn.completion;
|
|
4682
|
-
}
|
|
4683
|
-
async #dispatchTurn(input) {
|
|
4684
|
-
const streamOptions = {
|
|
4685
|
-
headers: input.headers,
|
|
4686
|
-
streamReconnectPolicy: input.streamReconnectPolicy
|
|
4687
|
-
};
|
|
4688
|
-
if (this.#session === void 0 && this.#prewarmPromise !== void 0) {
|
|
4689
|
-
await waitWithSignal(this.#prewarmPromise.catch((error) => {
|
|
4690
|
-
if (this.#session !== void 0) throw error;
|
|
4691
|
-
}), input.signal);
|
|
4692
|
-
throwIfAborted(input.signal);
|
|
4693
|
-
}
|
|
4694
|
-
const session = this.#session;
|
|
4695
|
-
let reader;
|
|
4696
|
-
try {
|
|
4697
|
-
const dispatched = await dispatchSessionTurn({
|
|
4698
|
-
client: this.#client,
|
|
4699
|
-
session,
|
|
4700
|
-
turn: input,
|
|
4701
|
-
beforeSend: () => {
|
|
4702
|
-
reader = this.#ensureStream(streamOptions).subscribe(input.signal);
|
|
4703
|
-
}
|
|
4704
|
-
});
|
|
4705
|
-
if (dispatched.created) {
|
|
4706
|
-
this.#adoptSession(dispatched.session);
|
|
4707
|
-
reader = this.#ensureStream(streamOptions).subscribe(input.signal);
|
|
4708
|
-
}
|
|
4709
|
-
return {
|
|
4710
|
-
response: dispatched.response,
|
|
4711
|
-
reader
|
|
4712
|
-
};
|
|
4713
|
-
} catch (error) {
|
|
4714
|
-
reader?.[Symbol.dispose]();
|
|
4715
|
-
throw error;
|
|
4716
|
-
}
|
|
4717
|
-
}
|
|
4718
|
-
#ensureStream(options = {}) {
|
|
4719
|
-
if (this.#session === void 0) throw new Error("A session is required before opening its stream.");
|
|
4720
|
-
const generation = this.#prewarmGeneration;
|
|
4721
|
-
if (this.#followChildStreams && !this.#conversationClient.following) this.#followSubagents();
|
|
4722
|
-
return this.#conversationClient.stream(this.#session, {
|
|
4723
|
-
...options,
|
|
4724
|
-
onEvent: (event) => {
|
|
4725
|
-
if (generation === this.#prewarmGeneration) this.#acceptServerEvent(event);
|
|
4726
|
-
},
|
|
4727
|
-
onError: (error) => {
|
|
4728
|
-
if (generation !== this.#prewarmGeneration || this.#activeTurn !== void 0) return;
|
|
4729
|
-
this.#fail(error);
|
|
4730
|
-
}
|
|
4731
|
-
});
|
|
4732
|
-
}
|
|
4733
|
-
#adoptSession(session) {
|
|
4734
|
-
this.#session = session;
|
|
4735
|
-
if (this.#followChildStreams && this.#attached) this.#followSubagents();
|
|
4736
|
-
this.#callbacks.onSessionChange?.(session.state);
|
|
4737
|
-
this.#publish();
|
|
4738
|
-
}
|
|
4739
|
-
#fail(error) {
|
|
4740
|
-
this.#error = toError(error);
|
|
4741
|
-
this.#status = "error";
|
|
4742
|
-
this.#callbacks.onError?.(this.#error);
|
|
4743
|
-
this.#publish();
|
|
4744
|
-
}
|
|
4745
|
-
#followSubagents() {
|
|
4746
|
-
if (this.#session) this.#conversationClient.follow(this.#session, this.#events);
|
|
4747
|
-
}
|
|
4748
|
-
#resetPrewarm() {
|
|
4749
|
-
this.#prewarmGeneration += 1;
|
|
4750
|
-
this.#prewarmController?.abort();
|
|
4751
|
-
this.#prewarmController = void 0;
|
|
4752
|
-
this.#prewarmPromise = void 0;
|
|
4753
|
-
}
|
|
4754
|
-
#finishTurn(turn) {
|
|
4755
|
-
if (!this.#isActiveTurn(turn)) return;
|
|
4756
|
-
turn.resolveResponse(void 0);
|
|
4757
|
-
this.#activeTurn = void 0;
|
|
4758
|
-
this.#closeStreamWhenIdle();
|
|
4759
|
-
try {
|
|
4760
|
-
this.#callbacks.onSessionChange?.(this.#session?.state);
|
|
4761
|
-
this.#publish();
|
|
4762
|
-
this.#callbacks.onFinish?.(this.#snapshot);
|
|
4763
|
-
} finally {
|
|
4764
|
-
turn.resolveCompletion();
|
|
4765
|
-
}
|
|
4766
|
-
}
|
|
4767
|
-
#isActiveTurn(turn) {
|
|
4768
|
-
return this.#activeTurn === turn;
|
|
4769
|
-
}
|
|
4770
|
-
#acceptServerEvent(event) {
|
|
4771
|
-
const wasStreaming = this.#status === "streaming";
|
|
4772
|
-
if (!this.#conversationClient.observe(event, {
|
|
4773
|
-
onAccepted: () => {
|
|
4774
|
-
this.#events = [...this.#events, event];
|
|
4775
|
-
},
|
|
4776
|
-
project: (accepted) => {
|
|
4777
|
-
this.#handleReconciliation(this.#messageSubmissions.apply(accepted));
|
|
4778
|
-
},
|
|
4779
|
-
notify: false
|
|
4780
|
-
})) return false;
|
|
4781
|
-
this.#callbacks.onEvent?.(event);
|
|
4782
|
-
this.#applyTerminalStreamFailure(event);
|
|
4783
|
-
const { conversation } = this.#conversationClient;
|
|
4784
|
-
const settled = isSettledSessionTail(this.#events, conversation) && conversation.activeTurnId === void 0;
|
|
4785
|
-
if (this.#status !== "resuming" && this.#error === void 0) {
|
|
4786
|
-
if ("data" in event && event.data !== void 0 && "turnId" in event.data) this.#status = "streaming";
|
|
4787
|
-
if (this.#activeTurn === void 0 && settled) this.#status = "ready";
|
|
4788
|
-
}
|
|
4789
|
-
this.#callbacks.onSessionChange?.(this.#session?.state);
|
|
4790
|
-
if (this.#status !== "resuming") this.#publish();
|
|
4791
|
-
if (this.#activeTurn === void 0 && wasStreaming && settled) this.#callbacks.onFinish?.(this.#snapshot);
|
|
4792
|
-
if (this.#activeTurn === void 0) this.#closeStreamWhenIdle();
|
|
4793
|
-
return true;
|
|
4794
|
-
}
|
|
4795
|
-
#closeStreamWhenIdle() {
|
|
4796
|
-
if (this.#followIdle) return;
|
|
4797
|
-
const { conversation } = this.#conversationClient;
|
|
4798
|
-
if (conversation.activeTurnId !== void 0) return;
|
|
4799
|
-
if (this.#events.length > 0 && !isSettledSessionTail(this.#events, conversation)) return;
|
|
4800
|
-
if (!Object.values(conversation.tasks).some((task) => Object.values(task.calls).some((call) => call.status === "working"))) this.#conversationClient.closeStream();
|
|
4801
|
-
}
|
|
4802
|
-
#correlate(submissionId, response) {
|
|
4803
|
-
const deliveryId = getMessageResponseDeliveryId(response);
|
|
4804
|
-
const reconciled = this.#messageSubmissions.correlate(submissionId, deliveryId, this.#events);
|
|
4805
|
-
if (this.#handleReconciliation(reconciled)) this.#publish();
|
|
4806
|
-
}
|
|
4807
|
-
#handleReconciliation(reconciliation) {
|
|
4808
|
-
if (reconciliation === void 0) return false;
|
|
4809
|
-
if (this.#activeTurn !== void 0) countFollowUpDeliveries(this.#activeTurn, reconciliation);
|
|
4810
|
-
return true;
|
|
4811
|
-
}
|
|
4812
|
-
#applyTerminalStreamFailure(event) {
|
|
4813
|
-
const error = toTerminalStreamFailureError(event);
|
|
4814
|
-
if (error === void 0) return;
|
|
4815
|
-
this.#status = "error";
|
|
4816
|
-
this.#messageSubmissions.failAll(error);
|
|
4817
|
-
if (this.#error === void 0) {
|
|
4818
|
-
this.#error = error;
|
|
4819
|
-
this.#callbacks.onError?.(error);
|
|
4820
|
-
}
|
|
4821
|
-
}
|
|
4822
|
-
#createSnapshot() {
|
|
4823
|
-
return {
|
|
4824
|
-
data: this.#conversationClient.data,
|
|
4825
|
-
conversation: this.#conversationClient.conversation,
|
|
4826
|
-
error: this.#error,
|
|
4827
|
-
events: this.#events,
|
|
4828
|
-
session: this.#session?.state,
|
|
4829
|
-
status: this.#status
|
|
4830
|
-
};
|
|
4831
|
-
}
|
|
4832
|
-
#publish() {
|
|
4833
|
-
this.#snapshot = this.#createSnapshot();
|
|
4834
|
-
for (const subscriber of this.#subscribers) subscriber();
|
|
4835
|
-
}
|
|
4836
|
-
};
|
|
4837
|
-
function detachEveAgentStore(store) {
|
|
4838
|
-
store[detachStore]();
|
|
4839
|
-
}
|
|
4840
|
-
function attachEveAgentStore(store) {
|
|
4841
|
-
store[attachStore]();
|
|
4842
|
-
}
|
|
4843
|
-
|
|
4844
|
-
//#endregion
|
|
4845
|
-
//#region src/client/agent-host.ts
|
|
4846
|
-
const AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]*$/;
|
|
4847
|
-
const EVE_NAMED_AGENT_ROUTE_PREFIX = "/eve";
|
|
4848
|
-
function resolveEveAgentHost(input) {
|
|
4849
|
-
if (input.agent === void 0) return input.host ?? "";
|
|
4850
|
-
if (input.host !== void 0) throw new Error("useEveAgent cannot combine agent and host. Use one target option.");
|
|
4851
|
-
assertValidAgentName(input.agent);
|
|
4852
|
-
return `${EVE_NAMED_AGENT_ROUTE_PREFIX}/${input.agent}`;
|
|
4853
|
-
}
|
|
4854
|
-
function assertValidAgentName(name) {
|
|
4855
|
-
if (!AGENT_NAME_PATTERN.test(name)) throw new Error(`eve agent name ${JSON.stringify(name)} is invalid. Use lowercase letters, numbers, underscores, or hyphens, starting with a letter or number.`);
|
|
4856
|
-
}
|
|
4857
|
-
|
|
4858
|
-
//#endregion
|
|
4859
|
-
//#region src/vue/use-eve-agent.ts
|
|
4860
|
-
function useEveAgent(options = {}) {
|
|
4861
|
-
if (options.resume && options.initialSession === void 0 && options.session === void 0) throw new Error("useEveAgent({ resume: true }) requires initialSession or session.");
|
|
4862
|
-
const reducer = options.reducer ?? conversationReducer;
|
|
4863
|
-
const store = new EveAgentStore({
|
|
4864
|
-
auth: options.auth,
|
|
4865
|
-
headers: options.headers,
|
|
4866
|
-
host: resolveEveAgentHost({
|
|
4867
|
-
agent: options.agent,
|
|
4868
|
-
host: options.host
|
|
4869
|
-
}),
|
|
4870
|
-
initialEvents: options.initialEvents,
|
|
4871
|
-
initialSession: options.initialSession,
|
|
4872
|
-
optimistic: options.optimistic,
|
|
4873
|
-
followSubagents: options.followSubagents,
|
|
4874
|
-
followIdle: options.followIdle,
|
|
4875
|
-
prewarm: options.prewarm,
|
|
4876
|
-
reducer,
|
|
4877
|
-
session: options.session
|
|
4878
|
-
});
|
|
4879
|
-
store.setCallbacks({
|
|
4880
|
-
onError: options.onError,
|
|
4881
|
-
onEvent: options.onEvent,
|
|
4882
|
-
onFinish: options.onFinish,
|
|
4883
|
-
onSessionChange: options.onSessionChange,
|
|
4884
|
-
prepareSend: options.prepareSend
|
|
4885
|
-
});
|
|
4886
|
-
const snapshot = shallowRef(store.snapshot);
|
|
4887
|
-
if ("window" in globalThis) {
|
|
4888
|
-
const unsubscribe = store.subscribe(() => {
|
|
4889
|
-
snapshot.value = store.snapshot;
|
|
4890
|
-
});
|
|
4891
|
-
attachEveAgentStore(store);
|
|
4892
|
-
if (options.resume) store.resume();
|
|
4893
|
-
onScopeDispose(() => {
|
|
4894
|
-
unsubscribe();
|
|
4895
|
-
detachEveAgentStore(store);
|
|
4896
|
-
});
|
|
4897
|
-
}
|
|
4898
|
-
return {
|
|
4899
|
-
cancel: () => store.cancel(),
|
|
4900
|
-
data: computed(() => snapshot.value.data),
|
|
4901
|
-
conversation: computed(() => snapshot.value.conversation),
|
|
4902
|
-
error: computed(() => snapshot.value.error),
|
|
4903
|
-
events: computed(() => snapshot.value.events),
|
|
4904
|
-
prewarm: () => store.prewarm(),
|
|
4905
|
-
reset: () => store.reset(),
|
|
4906
|
-
respond: (inputResponses, options) => store.send({
|
|
4907
|
-
...options,
|
|
4908
|
-
inputResponses
|
|
4909
|
-
}),
|
|
4910
|
-
resume: () => store.resume(),
|
|
4911
|
-
send: (message, options) => store.send({
|
|
4912
|
-
...options,
|
|
4913
|
-
message
|
|
4914
|
-
}),
|
|
4915
|
-
session: computed(() => snapshot.value.session),
|
|
4916
|
-
status: computed(() => snapshot.value.status)
|
|
4917
|
-
};
|
|
4918
|
-
}
|
|
4919
|
-
|
|
4920
|
-
//#endregion
|
|
4921
|
-
export { conversationProjection as a, openConversationInputs as i, conversationReducer as n, callStatus as o, defaultMessageReducer as r, useEveAgent as t };
|