eve 0.66.3 → 0.67.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 +28 -0
- package/dist/src/channel/channel-address.d.ts +0 -2
- package/dist/src/channel/channel-address.js +1 -1
- package/dist/src/channel/channel-operations.d.ts +0 -5
- package/dist/src/channel/channel-operations.js +1 -1
- package/dist/src/channel/compiled-channel.d.ts +8 -0
- package/dist/src/channel/compiled-channel.js +2 -2
- package/dist/src/channel/conversation-context.js +1 -1
- package/dist/src/channel/routes.d.ts +1 -2
- package/dist/src/channel/schedule.d.ts +2 -2
- package/dist/src/channel/schedule.js +1 -1
- package/dist/src/channel/types.d.ts +8 -13
- package/dist/src/chunks/{use-eve-agent-PbSMyJ6e.js → use-eve-agent-DzdyI97Z.js} +0 -5
- package/dist/src/chunks/{use-eve-agent-Di1u2zKu.js → use-eve-agent-OCHP4s0z.js} +0 -5
- package/dist/src/cli/acp/command.js +3 -3
- package/dist/src/cli/commands/logs.d.ts +3 -3
- package/dist/src/cli/commands/logs.js +1 -1
- package/dist/src/cli/commands/register-integration-commands.js +1 -1
- package/dist/src/cli/commands/trace.js +1 -1
- package/dist/src/cli/dev/command.d.ts +9 -5
- package/dist/src/cli/dev/command.js +1 -3
- package/dist/src/cli/dev/run-interactive-ui.d.ts +0 -1
- package/dist/src/cli/dev/run-interactive-ui.js +1 -1
- package/dist/src/cli/dev/tui/blocks.js +1 -1
- package/dist/src/cli/dev/tui/prompt-command-handler.js +1 -1
- package/dist/src/cli/dev/tui/question-panel.d.ts +4 -4
- package/dist/src/cli/dev/tui/question-panel.js +1 -1
- package/dist/src/cli/dev/tui/runner.js +2 -2
- package/dist/src/cli/dev/tui/terminal-renderer.js +8 -9
- package/dist/src/cli/dev/tui/theme.d.ts +1 -1
- package/dist/src/cli/dev/url-target.js +1 -1
- package/dist/src/cli/invoke/command.d.ts +2 -5
- package/dist/src/cli/invoke/command.js +1 -1
- package/dist/src/cli/invoke/invoke.d.ts +2 -2
- package/dist/src/cli/invoke/invoke.js +1 -1
- package/dist/src/cli/invoke/result.d.ts +14 -194
- package/dist/src/cli/invoke/result.js +1 -1
- package/dist/src/cli/run.d.ts +0 -4
- package/dist/src/cli/run.js +2 -2
- package/dist/src/cli/telemetry/index.js +1 -1
- package/dist/src/client/message-reducer.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +1 -1
- package/dist/src/compiler/compile-from-memory.d.ts +0 -1
- package/dist/src/compiler/compile-from-memory.js +1 -1
- package/dist/src/compiler/extension-compatibility.d.ts +25 -18
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/manifest.d.ts +48 -14
- package/dist/src/compiler/manifest.js +1 -1
- package/dist/src/compiler/normalize-agent-config.js +1 -1
- package/dist/src/compiler/normalize-channel.js +1 -1
- package/dist/src/compiler/normalize-connection.js +1 -1
- package/dist/src/compiler/normalize-manifest-helpers.js +1 -1
- package/dist/src/compiler/normalize-subagent.d.ts +0 -2
- package/dist/src/compiler/normalize-subagent.js +1 -1
- package/dist/src/compiler/remote-agent-node.d.ts +0 -2
- package/dist/src/compiler/remote-agent-node.js +1 -1
- package/dist/src/compiler/workspace-resources.js +1 -1
- package/dist/src/context/dynamic-subagent-lifecycle.js +1 -1
- package/dist/src/context/keys.d.ts +0 -3
- package/dist/src/context/keys.js +1 -1
- package/dist/src/context/memory-lifecycle.d.ts +1 -0
- package/dist/src/context/memory-lifecycle.js +1 -1
- package/dist/src/discover/project.js +1 -1
- package/dist/src/eve-channel/create-request.d.ts +0 -3
- package/dist/src/eve-channel/create-request.js +1 -1
- package/dist/src/eve-channel/index.js +1 -1
- package/dist/src/eve-channel/request.js +1 -1
- package/dist/src/eve-channel/types.d.ts +1 -1
- package/dist/src/execution/delegated-session-context.d.ts +2 -0
- package/dist/src/execution/delegated-session-context.js +1 -0
- package/dist/src/execution/dynamic-connections.d.ts +4 -1
- package/dist/src/execution/dynamic-connections.js +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/effective-agent-config.js +1 -1
- package/dist/src/execution/legacy-session/input.d.ts +0 -2
- package/dist/src/execution/legacy-session/input.js +1 -1
- package/dist/src/execution/legacy-session/prepare-step.d.ts +0 -1
- package/dist/src/execution/legacy-session/turn-workflow.js +1 -1
- package/dist/src/execution/node-step.d.ts +4 -2
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/proxied-deliver-step.js +1 -1
- package/dist/src/execution/publish-channel-event.d.ts +23 -0
- package/dist/src/execution/publish-channel-event.js +1 -0
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/session/entry.js +1 -1
- package/dist/src/execution/session/event-sink.d.ts +1 -1
- package/dist/src/execution/session/event-sink.js +1 -1
- package/dist/src/execution/session/finalization.d.ts +1 -4
- package/dist/src/execution/session/finalization.js +1 -1
- package/dist/src/execution/session/handoff.d.ts +1 -3
- package/dist/src/execution/session/handoff.js +1 -1
- package/dist/src/execution/session/input-queue.d.ts +0 -1
- package/dist/src/execution/session/input-queue.js +1 -1
- package/dist/src/execution/session/next-input.d.ts +0 -1
- package/dist/src/execution/session/next-input.js +1 -1
- package/dist/src/execution/session/program.d.ts +0 -3
- package/dist/src/execution/session/program.js +1 -1
- package/dist/src/execution/session/turn-step-result.d.ts +1 -2
- package/dist/src/execution/session/turn-step-result.js +1 -1
- package/dist/src/execution/session/turn-step.js +1 -1
- package/dist/src/execution/session/turn.d.ts +2 -2
- package/dist/src/execution/session/turn.js +1 -1
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/tasks/parent/hitl-proxy-steps.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/execution/tools/agent-router.d.ts +0 -2
- package/dist/src/execution/tools/agent-router.js +1 -1
- package/dist/src/execution/tools/ask-question-workflow.js +1 -1
- package/dist/src/execution/tools/connection-search.d.ts +1 -0
- package/dist/src/execution/tools/connection-search.js +1 -1
- package/dist/src/execution/tools/sleep-workflow.js +1 -1
- package/dist/src/execution/tools/subagent/invoke-preparation.js +1 -1
- package/dist/src/extensions/code/extension/lib/connect-authentication.js +1 -1
- package/dist/src/extensions/code/extension/lib/github-shell.js +1 -1
- package/dist/src/extensions/code/extension/lib/prwatch-github.js +1 -1
- package/dist/src/framework/sources/registry.js +1 -1
- package/dist/src/harness/approval-delivery-coordinator.d.ts +3 -13
- package/dist/src/harness/approval-delivery-coordinator.js +1 -1
- package/dist/src/harness/emission.d.ts +2 -3
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/input-request-resolution.d.ts +2 -0
- package/dist/src/harness/input-request-resolution.js +1 -1
- package/dist/src/harness/input-requests.d.ts +3 -3
- package/dist/src/harness/input-requests.js +1 -1
- package/dist/src/harness/pending-input-batches.d.ts +3 -3
- package/dist/src/harness/pending-input-batches.js +1 -1
- package/dist/src/harness/proxy-input-requests.d.ts +2 -0
- package/dist/src/harness/proxy-input-requests.js +1 -1
- package/dist/src/harness/session-limit-enforcement.d.ts +2 -3
- package/dist/src/harness/session-limit-enforcement.js +1 -1
- package/dist/src/harness/tool-loop.js +2 -2
- package/dist/src/harness/tools.js +1 -1
- package/dist/src/harness/types.d.ts +11 -13
- package/dist/src/instrumentation/session-context.js +1 -1
- package/dist/src/instrumentation/session-init.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-definition/core.js +1 -1
- package/dist/src/internal/authored-module-loader.js +1 -2
- package/dist/src/internal/authored-package-boundary.d.ts +0 -1
- package/dist/src/internal/authored-package-boundary.js +1 -1
- package/dist/src/internal/authored-relative-extension-resolver.js +1 -1
- package/dist/src/internal/external-resources-snapshot.d.ts +46 -0
- package/dist/src/internal/external-resources-snapshot.js +1 -0
- package/dist/src/internal/external-resources.d.ts +20 -0
- package/dist/src/internal/external-resources.js +1 -0
- package/dist/src/internal/invocation/workflow-execution.d.ts +0 -2
- package/dist/src/internal/invocation/workflow-execution.js +1 -1
- package/dist/src/internal/nitro/host/build-application.js +1 -1
- package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
- package/dist/src/internal/nitro/host/instrumentation-entry.d.ts +3 -0
- package/dist/src/internal/nitro/host/instrumentation-entry.js +2 -0
- package/dist/src/internal/nitro/host/start-development-server.d.ts +0 -8
- package/dist/src/internal/nitro/host/start-development-server.js +2 -2
- package/dist/src/internal/nitro/host.d.ts +1 -1
- package/dist/src/internal/nitro/host.js +1 -1
- package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.js +1 -1
- package/dist/src/internal/nitro/routes/index.js +72 -3
- package/dist/src/node_modules/.pnpm/{@vercel_cli-config@0.2.7 → @vercel_cli-config@0.3.0}/node_modules/@vercel/cli-config/dist/index.js +1 -1
- package/dist/src/node_modules/.pnpm/{@vercel_connect@2.2.0_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_3fe44d656b2dcd93a04011e80966afff → @vercel_connect@2.3.3_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_a37674779346d612fa7d2ca9bd316494}/node_modules/@vercel/connect/dist/authorization.js +1 -1
- package/dist/src/node_modules/.pnpm/@vercel_connect@2.3.3_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_a37674779346d612fa7d2ca9bd316494/node_modules/@vercel/connect/dist/connector.js +1 -0
- package/dist/src/node_modules/.pnpm/{@vercel_connect@2.2.0_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_3fe44d656b2dcd93a04011e80966afff → @vercel_connect@2.3.3_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_a37674779346d612fa7d2ca9bd316494}/node_modules/@vercel/connect/dist/installation.js +1 -1
- package/dist/src/node_modules/.pnpm/{@vercel_connect@2.2.0_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_3fe44d656b2dcd93a04011e80966afff → @vercel_connect@2.3.3_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_a37674779346d612fa7d2ca9bd316494}/node_modules/@vercel/connect/dist/token.js +1 -1
- package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/token-util.js +1 -1
- package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/token.js +1 -1
- package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/version.js +1 -1
- package/dist/src/protocol/message.d.ts +4 -0
- package/dist/src/protocol/message.js +1 -1
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.d.ts +0 -1
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.js +1 -1
- package/dist/src/public/channels/mcp.js +1 -1
- package/dist/src/public/channels/slack/app-manifest.d.ts +9 -0
- package/dist/src/public/channels/slack/app-manifest.js +1 -0
- package/dist/src/public/channels/slack/inbound-content.js +6 -3
- package/dist/src/public/channels/slack/slackChannel.d.ts +4 -1
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/definitions/remote-agent.d.ts +0 -9
- package/dist/src/public/definitions/workspace-agent.d.ts +0 -3
- package/dist/src/public/definitions/workspace-agent.js +1 -1
- package/dist/src/runtime/agent/bootstrap.d.ts +0 -1
- package/dist/src/runtime/agent/bootstrap.js +1 -1
- package/dist/src/runtime/connections/mcp-client.js +1 -1
- package/dist/src/runtime/connections/mcp-tracing.d.ts +27 -0
- package/dist/src/runtime/connections/mcp-tracing.js +1 -0
- package/dist/src/runtime/resolve-agent-graph.js +1 -1
- package/dist/src/runtime/resolve-agent.js +1 -1
- package/dist/src/runtime/subagents/dynamic-agent-config.d.ts +0 -2
- package/dist/src/runtime/subagents/dynamic-agent-config.js +1 -1
- package/dist/src/runtime/subagents/dynamic-remote-agent-config.d.ts +0 -2
- package/dist/src/runtime/subagents/dynamic-remote-agent-config.js +1 -1
- package/dist/src/runtime/types.d.ts +1 -2
- package/dist/src/services/dev-client/vercel-auth-error.d.ts +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/setup/verified-remote-agent.d.ts +1 -0
- package/dist/src/setup/verified-remote-agent.js +1 -1
- package/dist/src/shared/action-types.d.ts +2 -2
- package/dist/src/shared/agent-definition.d.ts +0 -9
- package/dist/src/shared/agent-turn-outcome.d.ts +1 -1
- package/dist/src/shared/channel-definition.d.ts +2 -2
- package/dist/src/shared/conversation-context.d.ts +0 -4
- package/dist/src/shared/conversation-context.js +1 -1
- package/dist/src/shared/validate-authorization.js +1 -1
- package/dist/src/shared/vercel-connect-metadata.d.ts +12 -0
- package/dist/src/shared/vercel-connect-metadata.js +1 -0
- package/dist/src/subagents/agent-handle-errors.d.ts +0 -4
- package/dist/src/subagents/agent-handle-errors.js +1 -1
- package/dist/src/subagents/callback-route.js +1 -1
- package/dist/src/subagents/callback-step.d.ts +0 -22
- package/dist/src/subagents/callback-step.js +1 -1
- package/dist/src/subagents/event-proxy-step.js +1 -1
- package/dist/src/subagents/hitl-proxy.d.ts +3 -5
- package/dist/src/subagents/hitl-proxy.js +1 -1
- package/dist/src/subagents/invocation.d.ts +5 -6
- package/dist/src/subagents/parent-notification.d.ts +1 -18
- package/dist/src/subagents/parent-notification.js +1 -1
- package/dist/src/subagents/remote-dispatch.js +1 -1
- package/dist/src/subagents/tool.d.ts +0 -3
- package/dist/src/subagents/tool.js +1 -1
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/tools/framework/agent-contract.d.ts +0 -2
- package/dist/src/tools/framework/agent-contract.js +1 -1
- package/dist/src/tracing/agent-action-instrumentation.js +1 -1
- package/dist/src/tracing/agent-approval-instrumentation.js +1 -1
- package/dist/src/tracing/agent-memory-instrumentation.js +1 -1
- package/dist/src/tracing/agent-otel-provider.js +2 -2
- package/dist/src/tracing/agent-otel-session-context.js +1 -1
- package/dist/src/tracing/agent-tool-instrumentation.js +1 -1
- package/dist/src/tracing/agent-tool-span-context.d.ts +15 -0
- package/dist/src/tracing/agent-tool-span-context.js +1 -0
- package/dist/src/tracing/otel-declaration.d.ts +4 -9
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/agent-config.md +12 -13
- package/docs/channels/chat-sdk.mdx +1 -1
- package/docs/channels/custom.mdx +1 -1
- package/docs/channels/eve.mdx +4 -4
- package/docs/channels/mcp.mdx +10 -10
- package/docs/channels/slack.mdx +1 -1
- package/docs/concepts/sessions-runs-and-streaming.md +5 -6
- package/docs/connections/overview.mdx +22 -0
- package/docs/guides/deployment/overview.md +1 -1
- package/docs/guides/deployment/self-hosting.md +1 -1
- package/docs/guides/deployment/vercel.mdx +2 -2
- package/docs/guides/dev-tui.md +6 -6
- package/docs/guides/dynamic-capabilities.md +2 -2
- package/docs/guides/frontend/overview.mdx +5 -3
- package/docs/guides/hooks.md +4 -2
- package/docs/guides/instrumentation/agent-runs.mdx +7 -7
- package/docs/guides/instrumentation/instrumentation.mdx +22 -5
- package/docs/guides/instrumentation/otel.mdx +30 -0
- package/docs/guides/remote-agents.md +3 -4
- package/docs/guides/self-modification.md +1 -1
- package/docs/memory/custom-provider.md +1 -1
- package/docs/protocols/acp.md +1 -1
- package/docs/reference/cli.md +91 -97
- package/docs/schedules.mdx +4 -5
- package/docs/subagents/index.mdx +5 -7
- package/docs/tools/human-in-the-loop.md +4 -0
- package/docs/tools/overview.mdx +2 -0
- package/docs/tools/workflows.mdx +1 -1
- package/docs/tutorial/remember-definitions.mdx +1 -1
- package/docs/tutorial/ship-it.mdx +1 -1
- package/package.json +3 -2
- package/dist/src/cli/commands/channels.d.ts +0 -9
- package/dist/src/cli/commands/channels.js +0 -1
- package/dist/src/execution/effective-output-schema.d.ts +0 -22
- package/dist/src/execution/effective-output-schema.js +0 -1
- package/dist/src/node_modules/.pnpm/@vercel_connect@2.2.0_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_3fe44d656b2dcd93a04011e80966afff/node_modules/@vercel/connect/dist/connector.js +0 -1
- package/dist/src/shared/run-mode.d.ts +0 -7
- package/dist/src/shared/run-mode.js +0 -1
- package/dist/src/subagents/parent-result.d.ts +0 -14
- package/dist/src/subagents/parent-result.js +0 -1
- /package/dist/src/node_modules/.pnpm/{@vercel_connect@2.2.0_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_3fe44d656b2dcd93a04011e80966afff → @vercel_connect@2.3.3_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_a37674779346d612fa7d2ca9bd316494}/node_modules/@vercel/connect/dist/index.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_connect@2.2.0_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_3fe44d656b2dcd93a04011e80966afff → @vercel_connect@2.3.3_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_a37674779346d612fa7d2ca9bd316494}/node_modules/@vercel/connect/dist/internal/base-url.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_connect@2.2.0_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_3fe44d656b2dcd93a04011e80966afff → @vercel_connect@2.3.3_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_a37674779346d612fa7d2ca9bd316494}/node_modules/@vercel/connect/dist/internal/default-scopes.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_connect@2.2.0_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_3fe44d656b2dcd93a04011e80966afff → @vercel_connect@2.3.3_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_a37674779346d612fa7d2ca9bd316494}/node_modules/@vercel/connect/dist/internal/env.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_connect@2.2.0_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_3fe44d656b2dcd93a04011e80966afff → @vercel_connect@2.3.3_@ai-sdk_mcp@2.0.52_zod@4.5.4__@auth_core@0.41.2_@chat-adapter_sla_a37674779346d612fa7d2ca9bd316494}/node_modules/@vercel/connect/dist/internal/url-validation.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/auth-errors.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/exchange-vercel-oidc-token.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/get-context.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/get-vercel-oidc-token-sync.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/get-vercel-oidc-token-with-refresh.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/index.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/oauth.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/token-error.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/token-io.js +0 -0
- /package/dist/src/node_modules/.pnpm/{@vercel_oidc@3.8.8 → @vercel_oidc@3.8.9}/node_modules/@vercel/oidc/dist/verify-vercel-oidc-token.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import{PROMPT_COMMANDS,formatPromptCommandHelp,parsePromptCommand}from"./prompt-commands.js";import{failureKey,formatFailureDetail,formatFailureHint,formatFailureMessage,isInterruptedError,localFailureHint}from"./errors.js";import{parseLogDisplayMode}from"./log-display-mode.js";import{createMcpConnectionStatusTracker}from"./mcp-connection-status.js";import{describeRemoteAuthCompletedMutations}from"./remote-auth-result.js";import{createRemoteConnectionController}from"./remote-connection.js";import{prepareRemoteTuiAccess}from"./remote-startup.js";import{SubagentPump}from"./subagent-pump.js";import{BOOT_DETECTIONS,CLI_MISSING_SETUP_ISSUE,LOGIN_SETUP_ISSUE,detectSetupIssues,formatSetupIssuesLine,normalizeLocalModelEndpoint,orderedSetupIssues}from"./setup-issues.js";import{TerminalRenderer}from"./terminal-renderer.js";import{createVercelStatusTracker}from"./vercel-status.js";import"#client/index.js";import{loadDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{getVercelAuthStatus}from"#setup/vercel-project.js";import{inspectApplication}from"#services/inspect-application.js";import{devBootPhase}from"#internal/dev-boot-progress.js";import{toErrorMessage}from"#shared/errors.js";import{probeAgentInfo}from"#services/dev-client/agent-info-probe.js";import{isJsonObjectValue}from"#shared/json.js";import{SteeringStream}from"#cli/dev/tui/steering-stream.js";import{renderApplicationInfo}from"#cli/commands/info.js";import{createEventDeduper}from"#protocol/event-dedupe.js";import{isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{createDevelopmentRuntimeArtifactRefresher}from"#services/dev-client.js";async function delayMs(e){await new Promise(t=>{setTimeout(t,e).unref?.()})}async function abortableDelay(e,t){t.aborted||await new Promise(n=>{let r=setTimeout(done,e);r.unref?.(),t.addEventListener(`abort`,done,{once:!0});function done(){clearTimeout(r),t.removeEventListener(`abort`,done),n()}})}function authIssueForStatus(e){if(e===`logged-out`)return LOGIN_SETUP_ISSUE;if(e===`cli-missing`)return CLI_MISSING_SETUP_ISSUE}var EveTUIRunner=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v=!1;#y;#b;#x=!0;#S;#C;#w;#T;#E;#D;#O;#k;#A;#j=!1;#M=new AbortController;#N=!1;#P=0;#F=0;#I=[];#L;#R;#z;#B;#V=new Map;#H;#U=[];#W;#G=!1;#K;#q=new Map;#J=new Set;#Y;#X;constructor(e){this.#e=e.session,e.client!==void 0&&(this.#t=e.client),e.lifecycle!==void 0&&(this.#X=e.lifecycle),this.#n=createRenderer(e);let t={formatActionResultError};if(this.#t!==void 0&&(t.client=this.#t),this.#n.subagents!==void 0&&(t.view=this.#n.subagents),e.appRoot!==void 0&&(t.onToolCompleted=async(e,t,n)=>{let r=registryHandoffAddress(e,t,n);r!==void 0&&this.#pe(r)}),this.#K=new SubagentPump(t),this.#r=e.name??`eve`,this.#w=e.withExclusiveTerminal,this.#i=e.tools??`full`,this.#a=e.reasoning??`full`,this.#o=e.subagents??`full`,this.#s=e.connectionAuth??`full`,this.#c=e.assistantResponseStats??`tokensPerSecond`,this.#l=e.contextSize,this.#u=e.formatTransportError??toErrorMessage,e.initialInput!==void 0&&(this.#m=e.initialInput),e.startup!==void 0&&(this.#h=e.startup),this.#_=e.onboard===!0,this.#y=e.onOnboardingStep,this.#b=e.onOnboardingTerminal,e.appRoot!==void 0){this.#p=e.appRoot;let t={appRoot:e.appRoot,onChange:e=>this.#n.setVercelStatus?.(e)};e.detectProjectIdentity!==void 0&&(t.detectIdentity=e.detectProjectIdentity),this.#R=createVercelStatusTracker(t),e.probeMcpConnection!==void 0&&(this.#z=createMcpConnectionStatusTracker({onChange:()=>{},probe:e.probeMcpConnection}))}if(e.promptCommandHandler!==void 0&&(this.#S=e.promptCommandHandler),this.#C=e.availablePromptCommands??PROMPT_COMMANDS,e.remote!==void 0){if(this.#E=e.remote.runAuthFlow,this.#t===void 0)throw Error(`A remote TUI requires a configured development client.`);this.#T=createRemoteConnectionController({client:this.#t,credentials:e.remote.credentials,target:e.remote.target,onChange:e=>this.#n.setRemoteConnectionStatus?.(e),resolveOidcToken:e.remote.resolveOidcToken,resolveDeployment:e.remote.resolveDeployment})}this.#D=e.bootDetections??BOOT_DETECTIONS,this.#O=e.getVercelAuthStatus??getVercelAuthStatus,this.#k=e.inspectApplication??inspectApplication,e.onBootProgress!==void 0&&(this.#A=e.onBootProgress),e.serverUrl!==void 0&&(this.#f=e.serverUrl),e.serverUrl!==void 0&&e.remote===void 0&&(this.#d=createDevelopmentRuntimeArtifactRefresher({serverUrl:e.serverUrl}))}async#Z(){if(this.#f===void 0){this.#ee(),this.#_||await this.#he(void 0);return}let e;if(this.#T!==void 0){let t=await this.#T.check();t.state===`ready`&&(e=t.info)}else{let t=this.#t;if(t!==void 0)try{let n=await devBootPhase(`connecting to agent`,()=>probeAgentInfo({client:t,timeoutMs:2e3}),this.#A);n.kind===`ready`&&(e=n.info)}catch{e=void 0}}this.#ee();let t=this.#$(e);this.#_||await this.#he(t)}#Q(){let e=this.#h?.finish();return this.#g=e?.queuedPrompt,e?.draft??this.#m}#$(e){let t=this.#p===void 0?e:normalizeLocalModelEndpoint(e,process.env);this.#B=t;let n=this.#f;if(n===void 0||this.#x)return t;let r={name:this.#r,serverUrl:n};return t!==void 0&&(r.info=t),this.#n.renderAgentHeader?.(r),t}#ee(){let e=this.#A;this.#A=void 0,e?.({type:`before-first-paint`})}async run(){let onStop=()=>this.#n.requestInterrupt?.();this.#X?.signal.aborted===!0?onStop():this.#X?.signal.addEventListener(`abort`,onStop,{once:!0});try{await this.#te()}finally{this.#X?.signal.removeEventListener(`abort`,onStop),this.#j=!0,this.#M.abort(),this.#K.abortAll(),this.#n.shutdown?.(),this.#R?.dispose(),this.#z?.dispose(),this.#T?.dispose()}}async#te(){let e=this.#r,t,n,r=!1,i=!1,a=!1;this.#n.setStartupPhase?.(`starting`),await this.#Z(),this.#R?.refreshIdentity(),this.#z?.refresh();let o=(this.#_||this.#B?.agent.model.endpoint?.kind===`gateway`&&!this.#B.agent.model.endpoint.connected)&&this.#p!==void 0&&this.#S!==void 0&&this.#n.setupFlow!==void 0,s;if(this.#T!==void 0&&this.#n.setupFlow!==void 0){let e=await prepareRemoteTuiAccess({connection:this.#T,renderer:this.#n.setupFlow,signal:this.#X?.signal,runAuthFlow:this.#E});if(e?.kind===`authenticated`){let e=this.#T.current().connection;e.state===`ready`&&this.#$(e.info)}else e?.kind===`failed`||e?.kind===`unavailable`?s={failed:!0,message:e.kind===`failed`?e.message:e.failure.message}:e?.kind===`cancelled`&&(s={cancelled:!0},e.completedMutations.length>0&&(s.message=`Completed before cancellation: ${describeRemoteAuthCompletedMutations(e.completedMutations).join(`, `)}.`))}o&&(this.#n.setStartupPhase?.(`connecting`),s=await this.#we(e));let c=this.#Q();for(s?.cancelled||s?.failed?c=[this.#g,c].filter(Boolean).join(`
|
|
2
2
|
|
|
3
|
-
`)||void 0:t=this.#g,this.#x=!1,this.#$(this.#B),this.#ge(),this.#n.setStartupPhase?.(void 0),(!o||s?.cancelled||s?.failed)&&s?.message!==void 0&&this.#ye({kind:`result`,message:s.message});;){if(this.#X?.signal.aborted===!0||this.#n.exitRequested?.()===!0)return;let o=this.#U[0];if(o!==void 0&&n===void 0&&this.#H===void 0){this.#U.shift(),this.#W=o;try{await this.#me(o)}finally{this.#W=void 0}i=!1,a=!1,t=void 0;continue}if(!a){if(t==null){if(!this.#n.readPrompt){if(r)return;throw Error(`No prompt was provided and the renderer does not support prompt input.`)}let n={title:e};c!==void 0&&(n.initialDraft=c,c=void 0);try{this.#G=!0,t=await this.#se(n)}catch(e){if(isInterruptedError(e)){if(this.#H===void 0&&this.#U.length===0)return;a=!0,t=``}else throw e}finally{this.#G=!1}if(this.#U.length>0&&this.#H===void 0){t=void 0;continue}if(t==null&&this.#H===void 0)return}let o=this.#H===void 0?parsePromptCommand(t):null;if(o?.type===`exit`){this.#ye({kind:`dismiss`}),this.#X?.requestStop();return}if(o?.type===`cancel`&&(i=await this.#ie({absent:`No active turn to cancel`,accepted:`Cancellation requested`,failed:`Couldn't cancel the turn`,invoke:e=>e.cancel()}),n=void 0,a=!1,t=void 0,!i))continue;if(o?.type===`reset`){if(!await this.#ae()){n=void 0,a=!1,t=void 0;continue}this.#ye({kind:`dismiss`}),n=void 0,a=!1,t=void 0;continue}if(o?.type===`compact`&&(i=await this.#ie({absent:`No active session to compact`,accepted:`Compaction requested`,failed:`Couldn't compact the session`,invoke:e=>e.compact()}),n=void 0,a=!1,t=void 0,!i)||o?.type===`clear`&&(i=await this.#ie({absent:`No active session to clear`,failed:`Couldn't clear the session`,dismissOnAccepted:!0,invoke:e=>e.clear()}),n=void 0,a=!1,t=void 0,!i))continue;if(o?.type===`help`){if(this.#n.choosePromptCommand!==void 0){let e=await this.#n.choosePromptCommand(this.#C);e!==void 0&&(c=e)}else this.#ye({kind:`result`,message:formatPromptCommandHelp(this.#C)});n=void 0,a=!1,t=void 0;continue}if(o?.type===`info`){await this.#De(),n=void 0,a=!1,t=void 0;continue}if(o?.type===`loglevel`){let e=this.#Oe(o.argument),r=e.startsWith(`/loglevel is not available`)||e.startsWith(`Unknown log level`);this.#ye(r?{kind:`result`,message:e}:{kind:`result`,summary:e}),n=void 0,a=!1,t=void 0;continue}if(o?.type===`traces`){await this.#Ee(o.argument),n=void 0,a=!1,t=void 0;continue}if(o?.type===`extension`){try{await this.#Ce(o,e,{trigger:`command`})}catch(e){if(isInterruptedError(e))return;throw e}n=void 0,t=void 0,a=!1;continue}r=!0}let s=this.#H;this.#H=void 0;let l=s??(i?this.#de():await(async()=>(this.#re(),await this.#le({prompt:a?void 0:t,inputResponses:n})))()),u=this.#e?.state.sessionId;u!==void 0&&this.#n.setSessionId?.(u);let d=t,f=!1;try{for(;;){await this.#n.renderStream(l,{title:e,submittedPrompt:d,continueSession:!!this.#n.readPrompt,tools:this.#i,reasoning:this.#a,subagents:this.#o,connectionAuth:this.#s,assistantResponseStats:this.#c,contextSize:this.#l});let r=l.turnState?.pendingApprovals??[],i=l.turnState?.pendingQuestions??[];if(r.length>0||i.length>0){let o=[];if(r.length>0){if(!this.#n.readToolApproval)throw Error(`Tool approval was requested, but the renderer does not support tool approval input.`);for(let t of r){let n=await this.#n.readToolApproval(t,{title:e});o.push({requestId:t.approvalId,optionId:n.approved?`approve`:`cancel`}),this.#V.delete(t.approvalId)}}if(i.length>0){if(!this.#n.readInputQuestion)throw Error(`An interactive question was requested, but the renderer does not support input questions.`);for(let t of i){let n=toAgentTUIInputQuestion(t),r=await this.#n.readInputQuestion(n,{title:e});if(r===void 0)continue;let i={requestId:t.requestId};r.optionId!==void 0&&(i.optionId=r.optionId),r.text!==void 0&&(i.text=r.text),o.push(i),this.#V.delete(t.requestId)}}if(o.length===0)break;a=!0,n=o,t=void 0,f=!0;break}if(this.#Pe(l)){l=this.#de(),d=void 0;continue}if(l.turnState&&l.turnState.boundaryEvent===void 0&&!l.turnState.aborted){let e=this.#e?.state.sessionId;this.#n.renderNotice?.(e?`Lost the event stream — the turn may still be running on the server (session ${e}). Your next message resumes this session; use /cancel to stop the turn.`:`Lost the connection to the running turn.`)}break}}catch(e){if(isInterruptedError(e))return;throw e}if(f)continue;i=!1,a=!1,n=void 0,t=void 0;let p=l.turnState?.boundaryEvent;this.#Y!==this.#e&&(p===`session.waiting`||p===`session.completed`)&&(t=this.#n.takeQueuedPrompt?.()),this.#re(l.turnState?.aborted===!0)}}#ne(){this.#K.abortAll(),this.#V.clear(),this.#q.clear(),this.#J.clear(),this.#n.setConnectionAuthPendingCount?.(0),this.#e=void 0,this.#d?.clear()}#re(e=!1){let t=this.#Y;t!==void 0&&(this.#Y=void 0,this.#e===t&&(this.#ne(),e?this.#n.renderNotice?.(`Stopped following the turn and started a new session. Earlier context was cleared; the interrupted turn may still be running on the server.`):this.#n.renderSessionBoundary===void 0?this.#n.renderNotice?.(`Session ended — started a new session. Earlier context was cleared.`):this.#n.renderSessionBoundary()))}async#ie(e){let t=this.#e;if(t===void 0)return this.#ye({kind:`result`,summary:e.absent}),!1;try{return(await e.invoke(t)).status===`accepted`?(this.#ye(e.dismissOnAccepted===!0?{kind:`dismiss`}:{kind:`result`,summary:e.accepted}),!0):(this.#ye({kind:`result`,summary:e.absent}),!1)}catch(t){return this.#ye({kind:`result`,message:toErrorMessage(t),summary:e.failed}),!1}}async#ae(){if(this.#e===void 0)return this.#ne(),this.#n.reset?.(),!0;try{await this.#e.reset()}catch(e){return this.#ye({kind:`result`,message:`Couldn't reset the session: ${toErrorMessage(e)}`}),!1}return this.#ne(),this.#n.reset?.(),!0}async#oe(e){if(!this.#n.readPrompt)return;let t=this.#n.readPrompt(e),n=this.#d;if(n===void 0)return await t;let r=!1,i=!1,a,o=!1,s=0,refresh=async()=>{if(!(r||i)){i=!0;try{await n.refreshIdle({onRuntimeArtifactsChanged:()=>this.#Me()}),this.#p!==void 0&&this.#B===void 0&&!o&&(o=!0,this.#Ae().finally(()=>{o=!1}));let e=this.#B?.agent.model.endpoint,t=e?.kind===`chatgpt`&&(e.state===`signed-out`||e.state===`reauth-required`),r=Date.now();t&&r-s>=5e3&&(s=r,this.#Ae())}finally{i=!1}}},startRefresh=()=>{if(r||i)return;let e=refresh().finally(()=>{a===e&&(a=void 0)});a=e};startRefresh();let c=setInterval(()=>{startRefresh()},500);c.unref?.();try{return await t}finally{r=!0,clearInterval(c),await a}}async#se(e){let t=this.#oe(e);if(this.#n.renderIdleStream===void 0||this.#e?.state.sessionId===void 0)return await t;let n=new AbortController,r=this.#ce(n.signal,e).catch(e=>{n.signal.aborted||this.#n.renderNotice?.(`Stopped following session updates: ${toErrorMessage(e)}`)});try{return await t}finally{n.abort(),await r}}async#ce(e,t){let n=this.#e;if(n===void 0)return;let r=100;for(;!e.aborted;){let i=n.stream({signal:e})[Symbol.asyncIterator](),a=!1;try{for(;!e.aborted;){let r=!1,o={async*[Symbol.asyncIterator](){for(;!e.aborted;){let e=await i.next();if(e.done===!0||(r=!0,a=!0,yield e.value,isCurrentTurnBoundaryEvent(e.value)))return}}},s=this.#fe(o,()=>{},n);if(await this.#n.renderIdleStream(s,{...t,continueSession:!0}),this.#Pe(s),(s.turnState?.pendingApprovals.length??0)>0||(s.turnState?.pendingQuestions.length??0)>0){this.#H={events:(async function*(){})(),turnState:s.turnState},this.#n.suspendPromptForInput?.();return}if(s.turnState?.boundaryEvent===`session.completed`||s.turnState?.boundaryEvent===`session.failed`)return;if(!r)break}}finally{await i.return?.()}r=a?100:Math.min(r*2,2e3),e.aborted||await abortableDelay(r,e)}}async#le(e){let t=new AbortController,n={signal:t.signal};e.prompt!==void 0&&(n.message=e.prompt),e.inputResponses!==void 0&&e.inputResponses.length>0&&(n.inputResponses=e.inputResponses);let r,i=this.#e;try{if(this.#d!==void 0&&await this.#d.refresh({inputResponses:n.inputResponses,message:n.message,onRuntimeArtifactsChanged:()=>this.#Me()}),n.message!==void 0&&(n.inputResponses?.length??0)===0&&this.#n.flushDelayedDevBuildErrors?.(),this.#e===void 0){if(this.#t===void 0)throw Error(`Cannot create a session without an eve client.`);if(n.message===void 0)throw Error(`Cannot answer an input request before the session starts.`);let e=await this.#t.sessions.create({...n,message:n.message});this.#e=e.session,r=e.response}else r=n.inputResponses===void 0?await this.#e.send(n.message,{signal:n.signal,turnPolicy:`queue`}):await this.#e.respond(n.inputResponses,{signal:n.signal})}catch(e){if(isInterruptedError(e))throw e;return this.#T?.reportFailure(e),this.#Y=i,{events:errorOnlyTUIStream({errorText:this.#u(e)}),turnState:createTurnState()}}return this.#fe(r,()=>t.abort(),this.#e)}async#ue(e,t){if(e.cancelInFlight!==!0){e.cancelInFlight=!0;try{for(let n=0;n<8;n+=1){if(e.boundaryEvent!==void 0||e.aborted===!0)return;let n=e.turnId;try{if((await t?.cancel(n===void 0?void 0:{turnId:n}))?.status===`accepted`)return}catch{}await delayMs(250)}}finally{e.cancelInFlight=!1}}}#de(){if(this.#e===void 0)throw Error(`Cannot stream a session before its first turn is accepted.`);let e=new AbortController,t=this.#e;return this.#fe(t.stream({signal:e.signal}),()=>e.abort(),t)}#fe(e,t,n){let r=createTurnState(),i=n===void 0?void 0:new SteeringStream(e,n);return{steer:i===void 0?void 0:e=>i.send(e),abort:()=>{r.aborted=!0,this.#Y=n,i?.abort(),t()},cancel:()=>{this.#ue(r,n)},events:eveEventsToTUIStream({onAssistantResponse:()=>{this.#_&&!this.#v&&(this.#v=!0,this.#y?.({flow:`onboarding`,step:`first_response`}))},events:i??e,pendingInputRequests:this.#V,turnState:r,onSubagentCalled:e=>this.#K.begin(e),onSubagentBackgrounded:e=>this.#K.background(e),onSubagentCompleted:e=>this.#K.settle(e),onTurnCancelled:e=>this.#K.settleCancelledTurn(e),onConnectionAuthRequired:e=>this.#Ne(e),onConnectionAuthCompleted:e=>this.#Fe(e),onRegistryHandoff:this.#p===void 0?void 0:async e=>this.#pe(e),onTerminalFailure:()=>{this.#Y=n},failureHintOverride:this.#p===void 0?void 0:localFailureHint}),turnState:r}}#pe(e){this.#W===e||this.#U.includes(e)||(this.#U.push(e),this.#G&&this.#n.suspendPromptForInput?.())}async#me(e){this.#n.renderCommandInvocation?.(`/add ${e}`),await this.#Ce({type:`extension`,name:`add`,argument:e},`Add to your agent`,{trigger:`command`})}async#he(e){if(this.#p===void 0)return;let t={appRoot:this.#p,env:process.env};e!==void 0&&(t.info=e),this.#I=await detectSetupIssues(t,this.#D),this.#n.renderSetupWarning!==void 0&&(this.#ge(),this.#_e())}#ge(){if(this.#x)return;let e=orderedSetupIssues(this.#I,this.#L);e.length>0?this.#n.renderSetupWarning?.(formatSetupIssuesLine(e)):this.#n.clearSetupWarning?.()}async#_e(){let e=this.#p;if(e===void 0||process.env.EVE_MODEL_CONNECTION!==`ai-gateway-project`)return;let t;try{t=await this.#O(e,{signal:this.#M.signal})}catch{return}this.#j||this.#N||(this.#L=authIssueForStatus(t),this.#ge())}async#ve(e){let t=this.#p;if(t===void 0||this.#n.renderSetupWarning===void 0)return;let n=++this.#P,r={appRoot:t,env:process.env};e!==void 0&&(r.info=e);try{let[e,i]=await Promise.all([detectSetupIssues(r,this.#D),process.env.EVE_MODEL_CONNECTION===`ai-gateway-project`?this.#O(t,{signal:this.#M.signal}):void 0]);if(this.#j||n!==this.#P)return;this.#I=e,this.#L=i===void 0?void 0:authIssueForStatus(i),this.#ge()}catch{return}}#ye(e){if(this.#n.finishCommand!==void 0){this.#n.finishCommand(e);return}if(e.kind===`result`){let t=[e.summary,e.message].filter(Boolean).join(`
|
|
4
|
-
`);t!==``&&this.#n.renderNotice?.(t)}}async#be(e,t){let n=this.#S;if(n===void 0)return{message:`/${e.name} is not available in this session.`};let r=this.#B?.agent.model.endpoint,i={...t,renderer:this.#n,settleOutcome:e=>this.#Se(e),chatGptAccountLabel:r?.kind===`chatgpt`&&r.state===`ready`?r.accountLabel:void 0,withExclusiveTerminal:this.#w},a=this.#z?.current(),o=a!==void 0&&Object.keys(a).length>0?{...i,disabledConnectionReasons:a}:i;return await n.handle(e,o)}async#xe(e){if(e?.kind===`model-access-changed`){this.#R?.applyEffect({kind:`refresh-identity`}),this.#N=!0,await this.#ke(e);return}e!==void 0&&(this.#R?.applyEffect(e),this.#N=!0,this.#ve(this.#B))}async#Se(e){if(e.effect===void 0)return e;let t=e.effect.kind===`model-access-changed`&&e.effect.reload?setTimeout(()=>{this.#x&&this.#n.setStartupPhase?.(`updating`),this.#n.setupFlow?.setStatus(`Loading selected model…`)},150):void 0;try{await this.#xe(e.effect);let{effect:t,...n}=e;return n}catch{return{failed:!0,message:`Settings were saved, but the agent could not reload. Retry the command or restart eve dev.`}}finally{clearTimeout(t)}}async#Ce(e,t,n){let r=await this.#be(e,{...n,title:t}),i=r===void 0?void 0:await this.#Se(r);return!(n.suppressSuccessfulTranscript===!0&&i?.failed!==!0||n.suppressCancelledTranscript===!0&&i?.cancelled===!0)&&n.trigger!==`startup`&&(i===void 0?this.#ye({kind:`result`}):this.#ye({kind:`result`,message:i.message,summary:i.summary})),this.#Te(),i}async#we(e){this.#y?.({flow:`onboarding`,step:`model_provider`});let t=await this.#Ce({type:`extension`,name:`login`,argument:``},e,{trigger:`startup`,initialModelStep:`provider`});return!t?.cancelled&&t?.failed!==!0&&this.#y?.({flow:`onboarding`,step:`connection_ready`}),this.#b?.({flow:`onboarding`,step:`model_provider`,result:t?.cancelled?`cancelled`:t?.failed===!0?`error`:`completed`}),t}#Te(){if(this.#x)return;let e=this.#T?.current().connection;e?.state===`ready`&&e.info!==this.#B&&(this.#B=e.info,this.#f!==void 0&&this.#n.renderAgentHeader?.({info:e.info,name:this.#r,serverUrl:this.#f}))}async#Ee(e){if(this.#p===void 0||this.#n.traceViewer===void 0){this.#ye({kind:`result`,message:`/traces is only available in local dev sessions.`});return}try{await this.#n.traceViewer.open({appRoot:this.#p,sessionId:this.#e?.state.sessionId,reference:e===``?void 0:e})}catch(e){if(isInterruptedError(e))return;throw e}finally{this.#ye({kind:`dismiss`})}}async#De(){let e=this.#p;if(e===void 0){this.#ye({kind:`result`,message:`/info is only available in local dev sessions.`});return}try{let t=renderApplicationInfo(await this.#k(e));this.#n.showInfoPanel===void 0?this.#ye({kind:`result`,message:t}):await this.#n.showInfoPanel(t)}catch(e){this.#ye({kind:`result`,message:`Couldn't inspect the application: ${toErrorMessage(e)}`})}}#Oe(e){let t=this.#n;if(t.logDisplayMode===void 0||t.setLogDisplayMode===void 0)return`/loglevel is not available in this session.`;if(e===``)return`Logs: ${t.logDisplayMode()}. Use /loglevel all|stderr|sandbox|none — logs stay buffered, so switching also hides or restores past lines.`;let n=parseLogDisplayMode(e);if(n===void 0)return`Unknown log level "${e}". Use all, stderr, sandbox, or none.`;if(n===t.logDisplayMode())return`Logs already set to ${n}.`;switch(t.setLogDisplayMode(n),n){case`none`:return`Logs hidden. Output stays buffered — /loglevel all restores it.`;case`stderr`:return`Showing stderr logs only.`;case`sandbox`:return`Showing sandbox logs only.`;case`all`:return`Showing all logs.`}}async#ke(e){let t=this.#p;t!==void 0&&(++this.#F,++this.#P,await loadDevelopmentEnvironmentFiles(t),e.reload&&await this.#d?.refreshAfterSourceChange({}),e.model&&this.#B?this.#$({...this.#B,agent:{...this.#B.agent,model:{...this.#B.agent.model,...e.model}}}):this.#$(this.#B),this.#I=[],this.#L=void 0,this.#ge(),this.#Ae())}async#Ae(e=!1){let t=this.#B,n=++this.#F,r=await this.#je();this.#j||n!==this.#F||r===void 0||(this.#$(r),e&&!this.#n.renderAgentHeader&&this.#n.renderNotice?.(formatAgentUpdateNotice(t,r)),this.#ve(this.#B))}async#je(){let e=this.#t;if(e===void 0)return;let t=await probeAgentInfo({client:e});return t.kind===`ready`?t.info:void 0}#Me(){this.#Ae(!0)}#Ne(e){let t={name:e.data.name,description:e.data.description,state:`required`};e.data.authorization!==void 0&&(t.challenge=e.data.authorization),e.data.webhookUrl!==void 0&&(t.webhookUrl=e.data.webhookUrl),this.#q.set(e.data.name,t),this.#Ie(t)}#Pe(e){if(e.turnState?.boundaryEvent!==`session.waiting`)return!1;let t=!1;for(let e of this.#q.values())e.state===`required`&&e.webhookUrl!==void 0&&(e.state=`pending`,this.#J.add(e.name),this.#Ie(e),t=!0);return t&&this.#n.setConnectionAuthPendingCount?.(this.#J.size),this.#J.size>0}#Fe(e){let t=this.#q.get(e.data.name)??{name:e.data.name,description:``,state:e.data.outcome};t.state=e.data.outcome,e.data.reason!==void 0&&(t.reason=e.data.reason),this.#q.set(e.data.name,t),this.#J.delete(e.data.name),this.#Ie(t),this.#n.setConnectionAuthPendingCount?.(this.#J.size)}#Ie(e){let t={name:e.name,description:e.description,state:e.state};e.challenge!==void 0&&(t.challenge=e.challenge),e.reason!==void 0&&(t.reason=e.reason),this.#n.upsertConnectionAuth?.(t)}};function createRenderer(e){return e.renderer?e.renderer:new TerminalRenderer({tools:e.tools,reasoning:e.reasoning,subagents:e.subagents,connectionAuth:e.connectionAuth,assistantResponseStats:e.assistantResponseStats,contextSize:e.contextSize,logs:e.logs,availablePromptCommands:e.availablePromptCommands,argumentSuggestions:e.argumentSuggestions,input:e.userInput,output:e.screen,diagnostics:e.diagnostics,onExitRequest:e.lifecycle?.requestStop})}function formatAgentUpdateNotice(e,t){let n=e?.agent.model.id,r=t?.agent.model.id;return n!==void 0&&r!==void 0&&n!==r?`Agent updated: Model ${n} -> ${r}`:`Agent updated.`}function registryHandoffAddress(e,t,n){if((e!==`self-modification__agent`||t!==`registry_add`)&&(e!==void 0||t!==`selfmod__registry_add`)||typeof n!=`object`||!n)return;let r=n;return r.status===`needs-terminal`&&typeof r.address==`string`?r.address:void 0}async function*eveEventsToTUIStream(e){let{events:t,pendingInputRequests:n,turnState:r,onSubagentCalled:i,onSubagentBackgrounded:a,onSubagentCompleted:o,onTurnCancelled:s,onConnectionAuthRequired:c,onConnectionAuthCompleted:l,onRegistryHandoff:u,onTerminalFailure:d,failureHintOverride:f}=e,p=new Map,m=new Map,h=new Map,g=createEventDeduper(),_=0,v=new Set,y=new Set,b=new Set,x=!1,S=!1,C;for await(let w of t)if(g.admit(w)&&!(S&&isPostTurnVisibleEvent(w)))switch(w.type){case`session.started`:case`message.received`:break;case`turn.started`:w.data.turnId!==r.turnId&&(S=!1),r.turnId=w.data.turnId,yield{type:`turn-start`,turnId:w.data.turnId};break;case`step.started`:_+=1,yield{type:`step-start`,modelId:w.data.modelId};break;case`step.completed`:{let e=w;C=e.data.usage,yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`step-finish`,usage:e.data.usage};break}case`message.appended`:{let t=w,n=textPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(p,n);if(r.completed){if(_<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}let i=t.data.messageDelta;if(i.length===0)break;r.text+=i,i&&e.onAssistantResponse?.(),yield{type:`assistant-delta`,id:partGenerationId(n,r.generation),delta:i};break}case`message.completed`:{let t=textPartId(w.data.turnId,w.data.stepIndex),n=partStateFor(p,t),r=w.data.message;if(n.completed){if(r===null||_<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=_,yield{type:`assistant-complete`,id:partGenerationId(t,n.generation),text:r};break}let i=partGenerationId(t,n.generation);if(r!==null){if(n.text.length===0)n.text=r,n.completed=!0,n.completedEpoch=_,yield{type:`assistant-complete`,id:i,text:r};else if(r.startsWith(n.text)){let t=r.slice(n.text.length);t.length>0&&(t&&e.onAssistantResponse?.(),yield{type:`assistant-delta`,id:i,delta:t}),n.text=r,n.completed=!0,n.completedEpoch=_,yield{type:`assistant-complete`,id:i}}else n.text=r,n.completed=!0,n.completedEpoch=_,yield{type:`assistant-complete`,id:i,text:r}}else n.text.length>0&&(n.completed=!0,n.completedEpoch=_,yield{type:`assistant-complete`,id:i});break}case`reasoning.appended`:{let e=w,t=reasoningPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(m,t);if(n.completed){if(_<=n.completedEpoch)break;n.generation+=1,n.text=``,n.completed=!1}let r=e.data.reasoningDelta;if(r.length===0)break;n.text+=r,yield{type:`reasoning-delta`,id:partGenerationId(t,n.generation),delta:r};break}case`reasoning.completed`:{let e=reasoningPartId(w.data.turnId,w.data.stepIndex),t=partStateFor(m,e),n=w.data.reasoning;if(t.completed){if(n.length===0||_<=t.completedEpoch)break;t.generation+=1,t.text=n,t.completedEpoch=_;let r=partGenerationId(e,t.generation);yield{type:`reasoning-delta`,id:r,delta:n},yield{type:`reasoning-complete`,id:r};break}let r=partGenerationId(e,t.generation);if(t.text.length===0&&n.length>0)t.text=n,yield{type:`reasoning-delta`,id:r,delta:n};else if(n.length>0&&!n.startsWith(t.text)){yield{type:`reasoning-complete`,id:r},t.generation+=1,t.text=n,t.completed=!0,t.completedEpoch=_;let i=partGenerationId(e,t.generation);yield{type:`reasoning-delta`,id:i,delta:n},yield{type:`reasoning-complete`,id:i};break}t.completed=!0,t.completedEpoch=_,yield{type:`reasoning-complete`,id:r};break}case`actions.requested`:{let e=w.data.actions.filter(e=>e.kind===`tool-call`);if(e.length===0)break;for(let t of e)h.set(t.callId,t.toolName),!v.has(t.callId)&&(v.add(t.callId),yield{type:`tool-call`,toolCallId:t.callId,toolName:t.toolName,input:t.input});break}case`input.requested`:{let e=w.data.requests.filter(e=>e.action.kind===`tool-call`);if(e.length===0)break;for(let t of e){let e=t.action.callId;if(h.set(e,t.action.toolName),t.kind!==`session-limit`&&!v.has(e)&&(v.add(e),yield{type:`tool-call`,toolCallId:e,toolName:t.action.toolName,input:t.action.input}),!y.has(t.requestId)){if(y.add(t.requestId),n.set(t.requestId,t),t.kind!==`tool-approval`){upsertPendingQuestion(r,t);continue}upsertPendingApproval(r,t),yield{type:`tool-approval-request`,approvalId:t.requestId,toolCallId:e}}}break}case`action.result`:{let e=w,t=e.data.result,n=`output`in t?t.output:void 0;if(e.data.status===`completed`&&isJsonObjectValue(n)&&n.status===`working`&&typeof n.taskId==`string`&&typeof n.agentId==`string`&&a?.(t.callId),e.data.result.kind!==`tool-result`)break;let r=e.data.result.callId;if(!v.has(r))break;switch(e.data.status){case`completed`:{let t=e.data.result.output;yield{type:`tool-result`,toolCallId:r,output:t};let n=registryHandoffAddress(void 0,h.get(r),t);n!==void 0&&await u?.(n);break}case`failed`:yield{type:`tool-error`,toolCallId:r,errorText:formatActionResultError(e)};break;case`rejected`:yield{type:`tool-rejected`,toolCallId:r,reason:formatActionResultError(e)}}break}case`step.failed`:case`turn.failed`:{let e=toFailureEvent(w,b,f);e&&(yield e);break}case`session.failed`:{r.sawSessionFailure=!0,d?.(w);let e=toFailureEvent(w,b,f);e&&(yield e),r.boundaryEvent=w.type,yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`finish`,usage:C},x=!0;return}case`session.waiting`:case`session.completed`:r.boundaryEvent=w.type,yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`finish`,usage:C},x=!0;return;case`turn.completed`:S=!0,yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_);break;case`turn.cancelled`:s?.(w.data.turnId),yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`turn-cancelled`};break;case`subagent.called`:i?.(w);break;case`subagent.started`:case`subagent.event`:break;case`subagent.completed`:{let e=w;e.data.backgroundTask===void 0?o?.(e.data.callId):a?.(e.data.callId);break}case`authorization.required`:c?.(w);break;case`authorization.completed`:l?.(w)}x||(yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`finish`,usage:C})}async function*errorOnlyTUIStream(e){yield{type:`error`,errorText:e.errorText},yield{type:`finish`}}function createTurnState(){return{aborted:!1,pendingApprovals:[],pendingQuestions:[],sawSessionFailure:!1}}function upsertPendingApproval(e,t){let n=toAgentTUIToolApprovalRequest(t),r=e.pendingApprovals.findIndex(e=>e.approvalId===n.approvalId);r===-1?e.pendingApprovals.push(n):e.pendingApprovals[r]=n}function toAgentTUIToolApprovalRequest(e){return{approvalId:e.requestId,toolCallId:e.action.callId,toolName:e.action.toolName,input:e.action.input}}function upsertPendingQuestion(e,t){let n=e.pendingQuestions.findIndex(e=>e.requestId===t.requestId);n===-1?e.pendingQuestions.push(t):e.pendingQuestions[n]=t}function textPartId(e,t){return`text:${e}:${t}`}function reasoningPartId(e,t){return`reasoning:${e}:${t}`}function partStateFor(e,t){let n=e.get(t);return n===void 0&&(n={generation:0,text:``,completed:!1,completedEpoch:0},e.set(t,n)),n}function partGenerationId(e,t){return t===0?e:`${e}#${t}`}function*closeOpenParts(e,t,n){for(let[r,i]of e)i.completed||i.text.length===0||(i.completed=!0,i.completedEpoch=n,yield{type:t,id:partGenerationId(r,i.generation)})}function isPostTurnVisibleEvent(e){switch(e.type){case`actions.requested`:case`authorization.completed`:case`authorization.required`:case`input.requested`:case`message.appended`:case`message.completed`:case`reasoning.appended`:case`reasoning.completed`:case`result.completed`:case`step.completed`:case`step.failed`:case`step.started`:case`subagent.called`:case`subagent.completed`:case`subagent.event`:case`subagent.started`:case`turn.completed`:case`turn.failed`:return!0;default:return!1}}function formatActionResultError(e){if(e.data.error?.message)return e.data.error.message;let t=e.data.result.output;if(typeof t==`string`)return t;try{return JSON.stringify(t)}catch{return`Tool execution failed.`}}function toFailureEvent(e,t,n){let r=failureKey(e);if(t.has(r))return;t.add(r);let i={type:`error`,errorText:formatFailureMessage(e)},a=n?.(e)??formatFailureHint(e);a!==void 0&&(i.hint=a);let o=formatFailureDetail(e);return o!==void 0&&(i.detail=o),i}function toAgentTUIInputQuestion(e){let t=e.display===`text`?`text`:e.display===`select`||e.options!==void 0&&e.options.length>0?`select`:`text`,n={requestId:e.requestId,prompt:e.prompt,display:t};return e.options!==void 0&&(n.options=e.options.map(e=>{let t={id:e.id,label:e.label};return e.description!==void 0&&(t.description=e.description),e.style!==void 0&&(t.style=e.style),t})),e.allowFreeform!==void 0&&(n.allowFreeform=e.allowFreeform),n}export{EveTUIRunner,parsePromptCommand,registryHandoffAddress};
|
|
3
|
+
`)||void 0:t=this.#g,this.#x=!1,this.#$(this.#B),this.#ge(),this.#n.setStartupPhase?.(void 0),(!o||s?.cancelled||s?.failed)&&s?.message!==void 0&&this.#ye({kind:`result`,message:s.message});;){if(this.#X?.signal.aborted===!0||this.#n.exitRequested?.()===!0)return;let o=this.#U[0];if(o!==void 0&&n===void 0&&this.#H===void 0){this.#U.shift(),this.#W=o;try{await this.#me(o)}finally{this.#W=void 0}i=!1,a=!1,t=void 0;continue}if(!a){if(t==null){if(!this.#n.readPrompt){if(r)return;throw Error(`No prompt was provided and the renderer does not support prompt input.`)}let n={title:e};c!==void 0&&(n.initialDraft=c,c=void 0);try{this.#G=!0,t=await this.#se(n)}catch(e){if(isInterruptedError(e)){if(this.#H===void 0&&this.#U.length===0)return;a=!0,t=``}else throw e}finally{this.#G=!1}if(this.#U.length>0&&this.#H===void 0){t=void 0;continue}if(t==null&&this.#H===void 0)return}let o=this.#H===void 0?parsePromptCommand(t):null;if(o?.type===`exit`){this.#ye({kind:`dismiss`}),this.#X?.requestStop();return}if(o?.type===`cancel`&&(i=await this.#ie({absent:`No active turn to cancel`,accepted:`Cancellation requested`,failed:`Couldn't cancel the turn`,invoke:e=>e.cancel()}),n=void 0,a=!1,t=void 0,!i))continue;if(o?.type===`reset`){if(!await this.#ae()){n=void 0,a=!1,t=void 0;continue}this.#ye({kind:`dismiss`}),n=void 0,a=!1,t=void 0;continue}if(o?.type===`compact`&&(i=await this.#ie({absent:`No active session to compact`,accepted:`Compaction requested`,failed:`Couldn't compact the session`,invoke:e=>e.compact()}),n=void 0,a=!1,t=void 0,!i)||o?.type===`clear`&&(i=await this.#ie({absent:`No active session to clear`,failed:`Couldn't clear the session`,dismissOnAccepted:!0,invoke:e=>e.clear()}),n=void 0,a=!1,t=void 0,!i))continue;if(o?.type===`help`){if(this.#n.choosePromptCommand!==void 0){let e=await this.#n.choosePromptCommand(this.#C);e!==void 0&&(c=e)}else this.#ye({kind:`result`,message:formatPromptCommandHelp(this.#C)});n=void 0,a=!1,t=void 0;continue}if(o?.type===`info`){await this.#De(),n=void 0,a=!1,t=void 0;continue}if(o?.type===`loglevel`){let e=this.#Oe(o.argument),r=e.startsWith(`/loglevel is not available`)||e.startsWith(`Unknown log level`);this.#ye(r?{kind:`result`,message:e}:{kind:`result`,summary:e}),n=void 0,a=!1,t=void 0;continue}if(o?.type===`traces`){await this.#Ee(o.argument),n=void 0,a=!1,t=void 0;continue}if(o?.type===`extension`){try{await this.#Ce(o,e,{trigger:`command`})}catch(e){if(isInterruptedError(e))return;throw e}n=void 0,t=void 0,a=!1;continue}r=!0}let s=this.#H;this.#H=void 0;let l=s??(i?this.#de():await(async()=>(this.#re(),await this.#le({prompt:a?void 0:t,inputResponses:n})))()),u=this.#e?.state.sessionId;u!==void 0&&this.#n.setSessionId?.(u);let d=t,f=!1;try{for(;;){await this.#n.renderStream(l,{title:e,submittedPrompt:d,continueSession:!!this.#n.readPrompt,tools:this.#i,reasoning:this.#a,subagents:this.#o,connectionAuth:this.#s,assistantResponseStats:this.#c,contextSize:this.#l});let r=l.turnState?.pendingApprovals??[],i=l.turnState?.pendingQuestions??[];if(r.length>0||i.length>0){let o=[];if(r.length>0){if(!this.#n.readToolApproval)throw Error(`Tool approval was requested, but the renderer does not support tool approval input.`);for(let t of r){let n=await this.#n.readToolApproval(t,{title:e});o.push({requestId:t.approvalId,optionId:n.approved?`approve`:`cancel`})}}if(i.length>0){if(!this.#n.readInputQuestion)throw Error(`An interactive question was requested, but the renderer does not support input questions.`);for(let t of i){let n=toAgentTUIInputQuestion(t),r=await this.#n.readInputQuestion(n,{title:e});if(r===void 0)continue;let i={requestId:t.requestId};r.optionId!==void 0&&(i.optionId=r.optionId),r.text!==void 0&&(i.text=r.text),o.push(i)}}if(o.length===0)break;a=!0,n=o,t=void 0,f=!0;break}if(this.#Pe(l)){l=this.#de(),d=void 0;continue}if(l.turnState&&l.turnState.boundaryEvent===void 0&&!l.turnState.aborted){let e=this.#e?.state.sessionId;this.#n.renderNotice?.(e?`Lost the event stream — the turn may still be running on the server (session ${e}). Your next message resumes this session; use /cancel to stop the turn.`:`Lost the connection to the running turn.`)}break}}catch(e){if(isInterruptedError(e))return;throw e}if(f)continue;i=!1,a=!1,n=void 0,t=void 0;let p=l.turnState?.boundaryEvent;this.#Y!==this.#e&&(p===`session.waiting`||p===`session.completed`)&&(t=this.#n.takeQueuedPrompt?.()),this.#re(l.turnState?.aborted===!0)}}#ne(){this.#K.abortAll(),this.#V.clear(),this.#q.clear(),this.#J.clear(),this.#n.setConnectionAuthPendingCount?.(0),this.#e=void 0,this.#d?.clear()}#re(e=!1){let t=this.#Y;t!==void 0&&(this.#Y=void 0,this.#e===t&&(this.#ne(),e?this.#n.renderNotice?.(`Stopped following the turn and started a new session. Earlier context was cleared; the interrupted turn may still be running on the server.`):this.#n.renderSessionBoundary===void 0?this.#n.renderNotice?.(`Session ended — started a new session. Earlier context was cleared.`):this.#n.renderSessionBoundary()))}async#ie(e){let t=this.#e;if(t===void 0)return this.#ye({kind:`result`,summary:e.absent}),!1;try{return(await e.invoke(t)).status===`accepted`?(this.#ye(e.dismissOnAccepted===!0?{kind:`dismiss`}:{kind:`result`,summary:e.accepted}),!0):(this.#ye({kind:`result`,summary:e.absent}),!1)}catch(t){return this.#ye({kind:`result`,message:toErrorMessage(t),summary:e.failed}),!1}}async#ae(){if(this.#e===void 0)return this.#ne(),this.#n.reset?.(),!0;try{await this.#e.reset()}catch(e){return this.#ye({kind:`result`,message:`Couldn't reset the session: ${toErrorMessage(e)}`}),!1}return this.#ne(),this.#n.reset?.(),!0}async#oe(e){if(!this.#n.readPrompt)return;let t=this.#n.readPrompt(e),n=this.#d;if(n===void 0)return await t;let r=!1,i=!1,a,o=!1,s=0,refresh=async()=>{if(!(r||i)){i=!0;try{await n.refreshIdle({onRuntimeArtifactsChanged:()=>this.#Me()}),this.#p!==void 0&&this.#B===void 0&&!o&&(o=!0,this.#Ae().finally(()=>{o=!1}));let e=this.#B?.agent.model.endpoint,t=e?.kind===`chatgpt`&&(e.state===`signed-out`||e.state===`reauth-required`),r=Date.now();t&&r-s>=5e3&&(s=r,this.#Ae())}finally{i=!1}}},startRefresh=()=>{if(r||i)return;let e=refresh().finally(()=>{a===e&&(a=void 0)});a=e};startRefresh();let c=setInterval(()=>{startRefresh()},500);c.unref?.();try{return await t}finally{r=!0,clearInterval(c),await a}}async#se(e){let t=this.#oe(e);if(this.#n.renderIdleStream===void 0||this.#e?.state.sessionId===void 0)return await t;let n=new AbortController,r=this.#ce(n.signal,e).catch(e=>{n.signal.aborted||this.#n.renderNotice?.(`Stopped following session updates: ${toErrorMessage(e)}`)});try{return await t}finally{n.abort(),await r}}async#ce(e,t){let n=this.#e;if(n===void 0)return;let r=100;for(;!e.aborted;){let i=n.stream({signal:e})[Symbol.asyncIterator](),a=!1;try{for(;!e.aborted;){let r=!1,o={async*[Symbol.asyncIterator](){for(;!e.aborted;){let e=await i.next();if(e.done===!0||(r=!0,a=!0,yield e.value,isCurrentTurnBoundaryEvent(e.value)))return}}},s=this.#fe(o,()=>{},n);if(await this.#n.renderIdleStream(s,{...t,continueSession:!0}),this.#Pe(s),(s.turnState?.pendingApprovals.length??0)>0||(s.turnState?.pendingQuestions.length??0)>0){this.#H={events:(async function*(){})(),turnState:s.turnState},this.#n.suspendPromptForInput?.();return}if(s.turnState?.boundaryEvent===`session.completed`||s.turnState?.boundaryEvent===`session.failed`)return;if(!r)break}}finally{await i.return?.()}r=a?100:Math.min(r*2,2e3),e.aborted||await abortableDelay(r,e)}}async#le(e){let t=new AbortController,n={signal:t.signal};e.prompt!==void 0&&(n.message=e.prompt),e.inputResponses!==void 0&&e.inputResponses.length>0&&(n.inputResponses=e.inputResponses);let r,i=this.#e;try{if(this.#d!==void 0&&await this.#d.refresh({inputResponses:n.inputResponses,message:n.message,onRuntimeArtifactsChanged:()=>this.#Me()}),n.message!==void 0&&(n.inputResponses?.length??0)===0&&this.#n.flushDelayedDevBuildErrors?.(),this.#e===void 0){if(this.#t===void 0)throw Error(`Cannot create a session without an eve client.`);if(n.message===void 0)throw Error(`Cannot answer an input request before the session starts.`);let e=await this.#t.sessions.create({...n,message:n.message});this.#e=e.session,r=e.response}else r=n.inputResponses===void 0?await this.#e.send(n.message,{signal:n.signal,turnPolicy:`queue`}):await this.#e.respond(n.inputResponses,{signal:n.signal})}catch(e){if(isInterruptedError(e))throw e;return this.#T?.reportFailure(e),this.#Y=i,{events:errorOnlyTUIStream({errorText:this.#u(e)}),turnState:createTurnState()}}return this.#fe(r,()=>t.abort(),this.#e)}async#ue(e,t){if(e.cancelInFlight!==!0){e.cancelInFlight=!0;try{for(let n=0;n<8;n+=1){if(e.boundaryEvent!==void 0||e.aborted===!0)return;let n=e.turnId;try{if((await t?.cancel(n===void 0?void 0:{turnId:n}))?.status===`accepted`)return}catch{}await delayMs(250)}}finally{e.cancelInFlight=!1}}}#de(){if(this.#e===void 0)throw Error(`Cannot stream a session before its first turn is accepted.`);let e=new AbortController,t=this.#e;return this.#fe(t.stream({signal:e.signal}),()=>e.abort(),t)}#fe(e,t,n){let r=createTurnState(),i=n===void 0?void 0:new SteeringStream(e,n);return{steer:i===void 0?void 0:e=>i.send(e),abort:()=>{r.aborted=!0,this.#Y=n,i?.abort(),t()},cancel:()=>{this.#ue(r,n)},events:eveEventsToTUIStream({onAssistantResponse:()=>{this.#_&&!this.#v&&(this.#v=!0,this.#y?.({flow:`onboarding`,step:`first_response`}))},events:i??e,pendingInputRequests:this.#V,turnState:r,onSubagentCalled:e=>this.#K.begin(e),onSubagentBackgrounded:e=>this.#K.background(e),onSubagentCompleted:e=>this.#K.settle(e),onTurnCancelled:e=>this.#K.settleCancelledTurn(e),onConnectionAuthRequired:e=>this.#Ne(e),onConnectionAuthCompleted:e=>this.#Fe(e),onRegistryHandoff:this.#p===void 0?void 0:async e=>this.#pe(e),onTerminalFailure:()=>{this.#Y=n},failureHintOverride:this.#p===void 0?void 0:localFailureHint}),turnState:r}}#pe(e){this.#W===e||this.#U.includes(e)||(this.#U.push(e),this.#G&&this.#n.suspendPromptForInput?.())}async#me(e){this.#n.renderCommandInvocation?.(`/add ${e}`),await this.#Ce({type:`extension`,name:`add`,argument:e},`Add to your agent`,{trigger:`command`})}async#he(e){if(this.#p===void 0)return;let t={appRoot:this.#p,env:process.env};e!==void 0&&(t.info=e),this.#I=await detectSetupIssues(t,this.#D),this.#n.renderSetupWarning!==void 0&&(this.#ge(),this.#_e())}#ge(){if(this.#x)return;let e=orderedSetupIssues(this.#I,this.#L);e.length>0?this.#n.renderSetupWarning?.(formatSetupIssuesLine(e)):this.#n.clearSetupWarning?.()}async#_e(){let e=this.#p;if(e===void 0||process.env.EVE_MODEL_CONNECTION!==`ai-gateway-project`)return;let t;try{t=await this.#O(e,{signal:this.#M.signal})}catch{return}this.#j||this.#N||(this.#L=authIssueForStatus(t),this.#ge())}async#ve(e){let t=this.#p;if(t===void 0||this.#n.renderSetupWarning===void 0)return;let n=++this.#P,r={appRoot:t,env:process.env};e!==void 0&&(r.info=e);try{let[e,i]=await Promise.all([detectSetupIssues(r,this.#D),process.env.EVE_MODEL_CONNECTION===`ai-gateway-project`?this.#O(t,{signal:this.#M.signal}):void 0]);if(this.#j||n!==this.#P)return;this.#I=e,this.#L=i===void 0?void 0:authIssueForStatus(i),this.#ge()}catch{return}}#ye(e){if(this.#n.finishCommand!==void 0){this.#n.finishCommand(e);return}if(e.kind===`result`){let t=[e.summary,e.message].filter(Boolean).join(`
|
|
4
|
+
`);t!==``&&this.#n.renderNotice?.(t)}}async#be(e,t){let n=this.#S;if(n===void 0)return{message:`/${e.name} is not available in this session.`};let r=this.#B?.agent.model.endpoint,i={...t,renderer:this.#n,settleOutcome:e=>this.#Se(e),chatGptAccountLabel:r?.kind===`chatgpt`&&r.state===`ready`?r.accountLabel:void 0,withExclusiveTerminal:this.#w},a=this.#z?.current(),o=a!==void 0&&Object.keys(a).length>0?{...i,disabledConnectionReasons:a}:i;return await n.handle(e,o)}async#xe(e){if(e?.kind===`model-access-changed`){this.#R?.applyEffect({kind:`refresh-identity`}),this.#N=!0,await this.#ke(e);return}e!==void 0&&(this.#R?.applyEffect(e),this.#N=!0,this.#ve(this.#B))}async#Se(e){if(e.effect===void 0)return e;let t=e.effect.kind===`model-access-changed`&&e.effect.reload?setTimeout(()=>{this.#x&&this.#n.setStartupPhase?.(`updating`),this.#n.setupFlow?.setStatus(`Loading selected model…`)},150):void 0;try{await this.#xe(e.effect);let{effect:t,...n}=e;return n}catch{return{failed:!0,message:`Settings were saved, but the agent could not reload. Retry the command or restart eve dev.`}}finally{clearTimeout(t)}}async#Ce(e,t,n){let r=await this.#be(e,{...n,title:t}),i=r===void 0?void 0:await this.#Se(r);return!(n.suppressSuccessfulTranscript===!0&&i?.failed!==!0||n.suppressCancelledTranscript===!0&&i?.cancelled===!0)&&n.trigger!==`startup`&&(i===void 0?this.#ye({kind:`result`}):this.#ye({kind:`result`,message:i.message,summary:i.summary})),this.#Te(),i}async#we(e){this.#y?.({flow:`onboarding`,step:`model_provider`});let t=await this.#Ce({type:`extension`,name:`login`,argument:``},e,{trigger:`startup`,initialModelStep:`provider`});return!t?.cancelled&&t?.failed!==!0&&this.#y?.({flow:`onboarding`,step:`connection_ready`}),this.#b?.({flow:`onboarding`,step:`model_provider`,result:t?.cancelled?`cancelled`:t?.failed===!0?`error`:`completed`}),t}#Te(){if(this.#x)return;let e=this.#T?.current().connection;e?.state===`ready`&&e.info!==this.#B&&(this.#B=e.info,this.#f!==void 0&&this.#n.renderAgentHeader?.({info:e.info,name:this.#r,serverUrl:this.#f}))}async#Ee(e){if(this.#p===void 0||this.#n.traceViewer===void 0){this.#ye({kind:`result`,message:`/traces is only available in local dev sessions.`});return}try{await this.#n.traceViewer.open({appRoot:this.#p,sessionId:this.#e?.state.sessionId,reference:e===``?void 0:e})}catch(e){if(isInterruptedError(e))return;throw e}finally{this.#ye({kind:`dismiss`})}}async#De(){let e=this.#p;if(e===void 0){this.#ye({kind:`result`,message:`/info is only available in local dev sessions.`});return}try{let t=renderApplicationInfo(await this.#k(e));this.#n.showInfoPanel===void 0?this.#ye({kind:`result`,message:t}):await this.#n.showInfoPanel(t)}catch(e){this.#ye({kind:`result`,message:`Couldn't inspect the application: ${toErrorMessage(e)}`})}}#Oe(e){let t=this.#n;if(t.logDisplayMode===void 0||t.setLogDisplayMode===void 0)return`/loglevel is not available in this session.`;if(e===``)return`Logs: ${t.logDisplayMode()}. Use /loglevel all|stderr|sandbox|none — logs stay buffered, so switching also hides or restores past lines.`;let n=parseLogDisplayMode(e);if(n===void 0)return`Unknown log level "${e}". Use all, stderr, sandbox, or none.`;if(n===t.logDisplayMode())return`Logs already set to ${n}.`;switch(t.setLogDisplayMode(n),n){case`none`:return`Logs hidden. Output stays buffered — /loglevel all restores it.`;case`stderr`:return`Showing stderr logs only.`;case`sandbox`:return`Showing sandbox logs only.`;case`all`:return`Showing all logs.`}}async#ke(e){let t=this.#p;t!==void 0&&(++this.#F,++this.#P,await loadDevelopmentEnvironmentFiles(t),e.reload&&await this.#d?.refreshAfterSourceChange({}),e.model&&this.#B?this.#$({...this.#B,agent:{...this.#B.agent,model:{...this.#B.agent.model,...e.model}}}):this.#$(this.#B),this.#I=[],this.#L=void 0,this.#ge(),this.#Ae())}async#Ae(e=!1){let t=this.#B,n=++this.#F,r=await this.#je();this.#j||n!==this.#F||r===void 0||(this.#$(r),e&&!this.#n.renderAgentHeader&&this.#n.renderNotice?.(formatAgentUpdateNotice(t,r)),this.#ve(this.#B))}async#je(){let e=this.#t;if(e===void 0)return;let t=await probeAgentInfo({client:e});return t.kind===`ready`?t.info:void 0}#Me(){this.#Ae(!0)}#Ne(e){let t={name:e.data.name,description:e.data.description,state:`required`};e.data.authorization!==void 0&&(t.challenge=e.data.authorization),e.data.webhookUrl!==void 0&&(t.webhookUrl=e.data.webhookUrl),this.#q.set(e.data.name,t),this.#Ie(t)}#Pe(e){if(e.turnState?.boundaryEvent!==`session.waiting`)return!1;let t=!1;for(let e of this.#q.values())e.state===`required`&&e.webhookUrl!==void 0&&(e.state=`pending`,this.#J.add(e.name),this.#Ie(e),t=!0);return t&&this.#n.setConnectionAuthPendingCount?.(this.#J.size),this.#J.size>0}#Fe(e){let t=this.#q.get(e.data.name)??{name:e.data.name,description:``,state:e.data.outcome};t.state=e.data.outcome,e.data.reason!==void 0&&(t.reason=e.data.reason),this.#q.set(e.data.name,t),this.#J.delete(e.data.name),this.#Ie(t),this.#n.setConnectionAuthPendingCount?.(this.#J.size)}#Ie(e){let t={name:e.name,description:e.description,state:e.state};e.challenge!==void 0&&(t.challenge=e.challenge),e.reason!==void 0&&(t.reason=e.reason),this.#n.upsertConnectionAuth?.(t)}};function createRenderer(e){return e.renderer?e.renderer:new TerminalRenderer({tools:e.tools,reasoning:e.reasoning,subagents:e.subagents,connectionAuth:e.connectionAuth,assistantResponseStats:e.assistantResponseStats,contextSize:e.contextSize,logs:e.logs,availablePromptCommands:e.availablePromptCommands,argumentSuggestions:e.argumentSuggestions,input:e.userInput,output:e.screen,diagnostics:e.diagnostics,onExitRequest:e.lifecycle?.requestStop})}function formatAgentUpdateNotice(e,t){let n=e?.agent.model.id,r=t?.agent.model.id;return n!==void 0&&r!==void 0&&n!==r?`Agent updated: Model ${n} -> ${r}`:`Agent updated.`}function registryHandoffAddress(e,t,n){if((e!==`self-modification__agent`||t!==`registry_add`)&&(e!==void 0||t!==`selfmod__registry_add`)||typeof n!=`object`||!n)return;let r=n;return r.status===`needs-terminal`&&typeof r.address==`string`?r.address:void 0}async function*eveEventsToTUIStream(e){let{events:t,pendingInputRequests:n,turnState:r,onSubagentCalled:i,onSubagentBackgrounded:a,onSubagentCompleted:o,onTurnCancelled:s,onConnectionAuthRequired:c,onConnectionAuthCompleted:l,onRegistryHandoff:u,onTerminalFailure:d,failureHintOverride:f}=e,p=new Map,m=new Map,h=new Map,g=createEventDeduper(),_=0,v=new Set,y=new Set,b=new Set,x=!1,S=!1,C;for await(let w of t)if(g.admit(w)&&!(S&&isPostTurnVisibleEvent(w)))switch(w.type){case`session.started`:case`message.received`:break;case`turn.started`:w.data.turnId!==r.turnId&&(S=!1),r.turnId=w.data.turnId,yield{type:`turn-start`,turnId:w.data.turnId};break;case`step.started`:_+=1,yield{type:`step-start`,modelId:w.data.modelId};break;case`step.completed`:{let e=w;C=e.data.usage,yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`step-finish`,usage:e.data.usage};break}case`message.appended`:{let t=w,n=textPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(p,n);if(r.completed){if(_<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}let i=t.data.messageDelta;if(i.length===0)break;r.text+=i,i&&e.onAssistantResponse?.(),yield{type:`assistant-delta`,id:partGenerationId(n,r.generation),delta:i};break}case`message.completed`:{let t=textPartId(w.data.turnId,w.data.stepIndex),n=partStateFor(p,t),r=w.data.message;if(n.completed){if(r===null||_<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=_,yield{type:`assistant-complete`,id:partGenerationId(t,n.generation),text:r};break}let i=partGenerationId(t,n.generation);if(r!==null){if(n.text.length===0)n.text=r,n.completed=!0,n.completedEpoch=_,yield{type:`assistant-complete`,id:i,text:r};else if(r.startsWith(n.text)){let t=r.slice(n.text.length);t.length>0&&(t&&e.onAssistantResponse?.(),yield{type:`assistant-delta`,id:i,delta:t}),n.text=r,n.completed=!0,n.completedEpoch=_,yield{type:`assistant-complete`,id:i}}else n.text=r,n.completed=!0,n.completedEpoch=_,yield{type:`assistant-complete`,id:i,text:r}}else n.text.length>0&&(n.completed=!0,n.completedEpoch=_,yield{type:`assistant-complete`,id:i});break}case`reasoning.appended`:{let e=w,t=reasoningPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(m,t);if(n.completed){if(_<=n.completedEpoch)break;n.generation+=1,n.text=``,n.completed=!1}let r=e.data.reasoningDelta;if(r.length===0)break;n.text+=r,yield{type:`reasoning-delta`,id:partGenerationId(t,n.generation),delta:r};break}case`reasoning.completed`:{let e=reasoningPartId(w.data.turnId,w.data.stepIndex),t=partStateFor(m,e),n=w.data.reasoning;if(t.completed){if(n.length===0||_<=t.completedEpoch)break;t.generation+=1,t.text=n,t.completedEpoch=_;let r=partGenerationId(e,t.generation);yield{type:`reasoning-delta`,id:r,delta:n},yield{type:`reasoning-complete`,id:r};break}let r=partGenerationId(e,t.generation);if(t.text.length===0&&n.length>0)t.text=n,yield{type:`reasoning-delta`,id:r,delta:n};else if(n.length>0&&!n.startsWith(t.text)){yield{type:`reasoning-complete`,id:r},t.generation+=1,t.text=n,t.completed=!0,t.completedEpoch=_;let i=partGenerationId(e,t.generation);yield{type:`reasoning-delta`,id:i,delta:n},yield{type:`reasoning-complete`,id:i};break}t.completed=!0,t.completedEpoch=_,yield{type:`reasoning-complete`,id:r};break}case`actions.requested`:{let e=w.data.actions.filter(e=>e.kind===`tool-call`);if(e.length===0)break;for(let t of e)h.set(t.callId,t.toolName),!v.has(t.callId)&&(v.add(t.callId),yield{type:`tool-call`,toolCallId:t.callId,toolName:t.toolName,input:t.input});break}case`input.requested`:{let e=w.data.requests.filter(e=>e.action.kind===`tool-call`);if(e.length===0)break;for(let t of e){let e=t.action.callId;if(h.set(e,t.action.toolName),t.kind!==`session-limit`&&!v.has(e)&&(v.add(e),yield{type:`tool-call`,toolCallId:e,toolName:t.action.toolName,input:t.action.input}),!y.has(t.requestId)){if(y.add(t.requestId),n.set(t.requestId,t),t.kind!==`tool-approval`){upsertPendingQuestion(r,t);continue}upsertPendingApproval(r,t),yield{type:`tool-approval-request`,approvalId:t.requestId,toolCallId:e}}}break}case`approval.candidate`:{if(w.data.outcome===`pending`)break;let e=n.get(w.data.requestId);e!==void 0&&upsertPendingApproval(r,e);break}case`approval.settled`:case`input.resolved`:{let e=new Set(w.type===`input.resolved`?w.data.resolutions.map(e=>e.requestId):[w.data.requestId]);for(let t of e)n.delete(t);r.pendingApprovals=r.pendingApprovals.filter(t=>!e.has(t.approvalId)),r.pendingQuestions=r.pendingQuestions.filter(t=>!e.has(t.requestId));break}case`action.result`:{let e=w,t=e.data.result,n=`output`in t?t.output:void 0;if(e.data.status===`completed`&&isJsonObjectValue(n)&&n.status===`working`&&typeof n.taskId==`string`&&typeof n.agentId==`string`&&a?.(t.callId),e.data.result.kind!==`tool-result`)break;let r=e.data.result.callId;if(!v.has(r))break;switch(e.data.status){case`completed`:{let t=e.data.result.output;yield{type:`tool-result`,toolCallId:r,output:t};let n=registryHandoffAddress(void 0,h.get(r),t);n!==void 0&&await u?.(n);break}case`failed`:yield{type:`tool-error`,toolCallId:r,errorText:formatActionResultError(e)};break;case`rejected`:yield{type:`tool-rejected`,toolCallId:r,reason:formatActionResultError(e)}}break}case`step.failed`:case`turn.failed`:{let e=toFailureEvent(w,b,f);e&&(yield e);break}case`session.failed`:{r.sawSessionFailure=!0,d?.(w);let e=toFailureEvent(w,b,f);e&&(yield e),r.boundaryEvent=w.type,yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`finish`,usage:C},x=!0;return}case`session.waiting`:case`session.completed`:r.boundaryEvent=w.type,yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`finish`,usage:C},x=!0;return;case`turn.completed`:S=!0,yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_);break;case`turn.cancelled`:s?.(w.data.turnId),yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`turn-cancelled`};break;case`subagent.called`:i?.(w);break;case`subagent.started`:case`subagent.event`:break;case`subagent.completed`:{let e=w;e.data.backgroundTask===void 0?o?.(e.data.callId):a?.(e.data.callId);break}case`authorization.required`:c?.(w);break;case`authorization.completed`:l?.(w)}x||(yield*closeOpenParts(p,`assistant-complete`,_),yield*closeOpenParts(m,`reasoning-complete`,_),yield{type:`finish`,usage:C})}async function*errorOnlyTUIStream(e){yield{type:`error`,errorText:e.errorText},yield{type:`finish`}}function createTurnState(){return{aborted:!1,pendingApprovals:[],pendingQuestions:[],sawSessionFailure:!1}}function upsertPendingApproval(e,t){let n=toAgentTUIToolApprovalRequest(t),r=e.pendingApprovals.findIndex(e=>e.approvalId===n.approvalId);r===-1?e.pendingApprovals.push(n):e.pendingApprovals[r]=n}function toAgentTUIToolApprovalRequest(e){return{approvalId:e.requestId,toolCallId:e.action.callId,toolName:e.action.toolName,input:e.action.input}}function upsertPendingQuestion(e,t){let n=e.pendingQuestions.findIndex(e=>e.requestId===t.requestId);n===-1?e.pendingQuestions.push(t):e.pendingQuestions[n]=t}function textPartId(e,t){return`text:${e}:${t}`}function reasoningPartId(e,t){return`reasoning:${e}:${t}`}function partStateFor(e,t){let n=e.get(t);return n===void 0&&(n={generation:0,text:``,completed:!1,completedEpoch:0},e.set(t,n)),n}function partGenerationId(e,t){return t===0?e:`${e}#${t}`}function*closeOpenParts(e,t,n){for(let[r,i]of e)i.completed||i.text.length===0||(i.completed=!0,i.completedEpoch=n,yield{type:t,id:partGenerationId(r,i.generation)})}function isPostTurnVisibleEvent(e){switch(e.type){case`actions.requested`:case`authorization.completed`:case`authorization.required`:case`input.requested`:case`message.appended`:case`message.completed`:case`reasoning.appended`:case`reasoning.completed`:case`result.completed`:case`step.completed`:case`step.failed`:case`step.started`:case`subagent.called`:case`subagent.completed`:case`subagent.event`:case`subagent.started`:case`turn.completed`:case`turn.failed`:return!0;default:return!1}}function formatActionResultError(e){if(e.data.error?.message)return e.data.error.message;let t=e.data.result.output;if(typeof t==`string`)return t;try{return JSON.stringify(t)}catch{return`Tool execution failed.`}}function toFailureEvent(e,t,n){let r=failureKey(e);if(t.has(r))return;t.add(r);let i={type:`error`,errorText:formatFailureMessage(e)},a=n?.(e)??formatFailureHint(e);a!==void 0&&(i.hint=a);let o=formatFailureDetail(e);return o!==void 0&&(i.detail=o),i}function toAgentTUIInputQuestion(e){let t=e.display===`text`?`text`:e.display===`select`||e.options!==void 0&&e.options.length>0?`select`:`text`,n={requestId:e.requestId,prompt:e.prompt,display:t};return e.options!==void 0&&(n.options=e.options.map(e=>{let t={id:e.id,label:e.label};return e.description!==void 0&&(t.description=e.description),e.style!==void 0&&(t.style=e.style),t})),e.allowFreeform!==void 0&&(n.allowFreeform=e.allowFreeform),n}export{EveTUIRunner,parsePromptCommand,registryHandoffAddress};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import{buildAgentHeader}from"./agent-header.js";import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand,promptCommandSpec}from"./prompt-commands.js";import{argumentTypeaheadCompletion,argumentTypeaheadFor,argumentTypeaheadLoadingLabel,argumentTypeaheadQuery,moveArgumentTypeaheadSelection,renderArgumentSuggestions,selectedArgumentSuggestion}from"./argument-typeahead.js";import{detectMarkdownRendering}from"./markdown.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{copyTextToClipboard}from"./clipboard.js";import{dismissTypeahead,inlineCommandHint,isTypeaheadOpen,moveTypeaheadSelection,renderCommandSuggestions,selectedTypeaheadCommand,typeaheadCompletion,typeaheadFor}from"./command-typeahead.js";import{formatDevRebuildStatus,summarizeChangedFiles}from"./dev-rebuild-status.js";import{formatStoredDiagnostic,presentDiagnostic}from"./diagnostic-presentation.js";import{interruptedError}from"./errors.js";import{FileContentCache}from"./file-content-cache.js";import{EMPTY_LINE,KillRing,PromptHistory,applyLineEditorKey,deleteForward,layoutPromptInput,lineOf,movePromptLine,visibleLine}from"./line-editor.js";import{enterBadge,flowMessageRows,renderAcknowledgeQuestion,renderSelectQuestion,renderTextQuestion}from"./setup-panel.js";import{renderFlowDrawer,renderTransientDrawer}from"./flow-drawer.js";import{nextLogDisplayMode}from"./log-display-mode.js";import{MessageQueue,renderMessageQueueRows}from"./message-queue.js";import{initialProviderPickerState,transitionProviderPicker}from"./provider-picker.js";import{renderQuestionPanel}from"./question-panel.js";import{formatAssistantResponseStats,formatTokenFlow,formatTurnDuration,isIncompleteOsc,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil}from"./stream-format.js";import{TraceViewerSession}from"./traces/trace-viewer-session.js";import{buildStatusLine}from"./status-line.js";import{createTheme,detectUnicode}from"./theme.js";import{isPanelRoutedTool,presentPreparingTool,presentTool,readWriteFileInput,toolBaseName}from"./tool-presentation.js";import{groupToolBlocksForDisplay}from"./tool-block-groups.js";import{TurnClock}from"./turn-clock.js";import{reduceSetupSelectInput,setupSelectionIntent}from"./setup-selection-input.js";import{BACKGROUND_COLOR_QUERY,parseBackgroundColorReply}from"./terminal-background.js";import{inspectError}from"#internal/logging.js";import{eveVersionTag}from"#cli/banner.js";import{clipVisible,renderInputText,renderInputWithBlockCursor,stripAnsi,stripTerminalControls,wrapVisibleLine}from"#cli/ui/terminal-text.js";import{
|
|
2
|
-
`);if(this.#P){t!==this.#F&&(this.#F=t,this.#_n({kind:`agent-header`,body:t,live:!1})),this.#zn();return}this.#P=!0,this.#F=t,this.#n.flush(this.#Wn(),this.#Yn(this.#
|
|
1
|
+
import{buildAgentHeader}from"./agent-header.js";import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand,promptCommandSpec}from"./prompt-commands.js";import{argumentTypeaheadCompletion,argumentTypeaheadFor,argumentTypeaheadLoadingLabel,argumentTypeaheadQuery,moveArgumentTypeaheadSelection,renderArgumentSuggestions,selectedArgumentSuggestion}from"./argument-typeahead.js";import{detectMarkdownRendering}from"./markdown.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{copyTextToClipboard}from"./clipboard.js";import{dismissTypeahead,inlineCommandHint,isTypeaheadOpen,moveTypeaheadSelection,renderCommandSuggestions,selectedTypeaheadCommand,typeaheadCompletion,typeaheadFor}from"./command-typeahead.js";import{formatDevRebuildStatus,summarizeChangedFiles}from"./dev-rebuild-status.js";import{formatStoredDiagnostic,presentDiagnostic}from"./diagnostic-presentation.js";import{interruptedError}from"./errors.js";import{FileContentCache}from"./file-content-cache.js";import{EMPTY_LINE,KillRing,PromptHistory,applyLineEditorKey,deleteForward,layoutPromptInput,lineOf,movePromptLine,visibleLine}from"./line-editor.js";import{enterBadge,flowMessageRows,renderAcknowledgeQuestion,renderSelectQuestion,renderTextQuestion}from"./setup-panel.js";import{renderFlowDrawer,renderTransientDrawer}from"./flow-drawer.js";import{nextLogDisplayMode}from"./log-display-mode.js";import{MessageQueue,renderMessageQueueRows}from"./message-queue.js";import{initialProviderPickerState,transitionProviderPicker}from"./provider-picker.js";import{renderQuestionChoices,renderQuestionPanel}from"./question-panel.js";import{formatAssistantResponseStats,formatTokenFlow,formatTurnDuration,isIncompleteOsc,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil}from"./stream-format.js";import{TraceViewerSession}from"./traces/trace-viewer-session.js";import{buildStatusLine}from"./status-line.js";import{createTheme,detectUnicode}from"./theme.js";import{isPanelRoutedTool,presentPreparingTool,presentTool,readWriteFileInput,toolBaseName}from"./tool-presentation.js";import{groupToolBlocksForDisplay}from"./tool-block-groups.js";import{TurnClock}from"./turn-clock.js";import{reduceSetupSelectInput,setupSelectionIntent}from"./setup-selection-input.js";import{BACKGROUND_COLOR_QUERY,parseBackgroundColorReply}from"./terminal-background.js";import{inspectError}from"#internal/logging.js";import{eveVersionTag}from"#cli/banner.js";import{clipVisible,renderInputText,renderInputWithBlockCursor,stripAnsi,stripTerminalControls,wrapVisibleLine}from"#cli/ui/terminal-text.js";import{initialSelectState,orderedSelection,reduceSelect,searchActionQuery,selectValueAtCursor}from"#setup/cli/select-state.js";import{toErrorMessage}from"#shared/errors.js";import{StringDecoder}from"node:string_decoder";import{summarizeKnownError}from"#harness/semantic-errors/index.js";import{parseDevRebuildLogLine}from"#internal/nitro/host/dev-watcher-log.js";import{LiveRegion}from"#cli/ui/live-region.js";import{AltScreen}from"#cli/ui/alt-screen.js";import{PROGRESS_PULSE_ASCII_GLYPH,PROGRESS_PULSE_GLYPH,isProgressPulseVisible}from"#cli/ui/progress-pulse.js";import{readGatewayServiceTier}from"#shared/gateway-service-tier.js";function isMultiSelectRequest(e){return e.kind===`multi`||e.kind===`searchable-multi`}function moveActionCursor(e,t,n){return n===0?void 0:e===void 0?t===`down`?0:n-1:(e+(t===`down`?1:-1)+n)%n}function completedTurnStatus(e){return e.interrupted?`Interrupted`:e.cancelled?`Cancelled`:e.continueSession?`Ready`:`Done`}function turnActivityLabel(e){return e===void 0?`Thinking`:e.runningTools.size>0?`Running`:e.modelActivity}function updateTurnActivity(e,t){switch(t.type){case`turn-start`:case`step-start`:case`reasoning-delta`:e.modelActivity=`Thinking`;break;case`assistant-delta`:case`tool-call-preparing`:e.modelActivity=`Generating`;break;case`assistant-complete`:t.text?.trim()&&(e.modelActivity=`Generating`);break;case`tool-call`:e.runningTools.add(t.toolCallId),e.modelActivity=`Thinking`;break;case`tool-result`:case`tool-error`:case`tool-rejected`:e.runningTools.delete(t.toolCallId)}}const incompletePasteFlushMs=1e3,STATUS={processing:`Thinking`,connectionAuth:`Waiting for connection authorization…`};var TerminalRenderer=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h=[];#g=new Map;#_;#v=new Set;#y=[];#b=new Set;#x=new Map;#S=0;#C=new Map;#w=new Set;#T=new Set;#E=new FileContentCache;#D=new Set;#O;#k;#A;#j;#M=0;#N;#P=!1;#F;#I=[];#L;#R=0;#z;#B;#V=``;#H=0;#U=new PromptHistory;#W=new KillRing;#G=!1;#K;#q;#J;#Y=new Map;#X=new Map;#Z=!1;#Q=!1;#$=new TurnClock;#ee;#te=EMPTY_LINE;#ne=!1;#re={kind:`idle`};#ie;#ae=STATUS.processing;#oe;#se=`eve`;#ce=!1;#le=!1;#ue=!1;#de=!1;#fe=!1;#pe=!1;#me=!1;#he;#ge=!0;#_e=0;#ve=Date.now();#ye;#be;#xe;#Se=!1;#Ce;#we=``;#Te=new StringDecoder(`utf8`);#Ee;#De;#Oe;#ke=!1;#Ae=!1;#je;#Me;#Ne;#Pe;#Fe;#Ie;#Le;#Re=``;#ze=``;#Be;#Ve;#He;#Ue=!1;#We;#Ge=0;#Ke;#qe;#Je;#Ye;#Xe;#Ze;#Qe;#$e;#et=new MessageQueue;#tt;#nt;#rt=!1;#it;#at;#ot=!1;#st;#ct;#lt;#ut;#dt;setupFlow={begin:e=>this.#wt(e),setNavigation:e=>this.#Tt(e),end:e=>this.#Et(e?.preserveDiagnostics??!0),readSelect:e=>this.#Dt(e),readEditableSelect:e=>this.#kt(e),readProviderPicker:e=>this.#At(e),readText:e=>this.#jt(e),readAcknowledge:e=>this.#Mt(e),readChoice:e=>this.#Ot(e),setStatus:e=>this.#Bt(e),renderLine:(e,t)=>this.#Vt(e,t),replaceContent:e=>this.#Ht(e),renderOutput:e=>this.#Ut(e),withInheritedStdio:e=>this.#Wt(e),withExclusiveTerminal:e=>this.#Wt(e),waitForInterrupt:e=>this.#Lt(e)};traceViewer={open:e=>this.#Kt(e)};constructor(e){this.#e=e?.input??process.stdin,this.#t=e?.output??process.stdout,this.#n=new LiveRegion(this.#t),this.#r=new AltScreen(this.#t),this.#i=createTheme({color:e?.color??!0,unicode:e?.unicode??detectUnicode()}),this.#a=e?.renderMarkdown??detectMarkdownRendering(),this.#o=e?.tools??`auto-collapsed`,this.#s=e?.reasoning??`auto-collapsed`,this.#c=e?.subagents??`auto-collapsed`,this.#l=e?.connectionAuth??`full`,this.#u=e?.assistantResponseStats??`tokensPerSecond`,this.#Ne=e?.contextSize,this.#d=e?.captureForeignOutput??this.#t===process.stdout,this.#f=e?.diagnostics,this.#he=e?.onExitRequest,this.#J=e?.argumentSuggestions,this.#m=e?.logs??`none`,this.#p=e?.availablePromptCommands??PROMPT_COMMANDS}#ft(e){this.#K=typeaheadFor(this.#p,e,this.#K);let t=argumentTypeaheadQuery(e);if(t===void 0||this.#J===void 0){this.#q=void 0;return}let n=this.#Y.get(t.command);if(n===void 0){this.#Y.set(t.command,{kind:`loading`,visible:!1});let e=t.command;this.#X.set(e,setTimeout(()=>{this.#X.delete(e),this.#Y.get(e)?.kind===`loading`&&(this.#Y.set(e,{kind:`loading`,visible:!0}),this.#zn())},500)),this.#J(e).catch(()=>[]).then(t=>{let n=this.#X.get(e);n!==void 0&&clearTimeout(n),this.#X.delete(e),this.#Y.set(e,{kind:`ready`,suggestions:t}),this.#G&&this.#ft(this.#V),this.#zn()}),this.#q=void 0;return}if(n.kind===`loading`){this.#q=void 0;return}this.#q=argumentTypeaheadFor(t,n.suggestions,this.#q)}#pt(e){let t=argumentTypeaheadQuery(this.#V),n=t===void 0?void 0:this.#Y.get(t.command);return n?.kind===`loading`&&n.visible&&t!==void 0?[clip(this.#i.colors.dim(`Loading ${argumentTypeaheadLoadingLabel(t.command)}…`),e)]:this.#q===void 0?(this.#K===void 0?void 0:inlineCommandHint(this.#K))===void 0&&this.#K!==void 0&&isTypeaheadOpen(this.#K)?renderCommandSuggestions(this.#K,this.#i,e):[]:renderArgumentSuggestions(this.#q,this.#i,e)}setStartupPhase(e){this.#k=e,e===void 0?this.#pn():this.#dn(),this.#zn()}renderAgentHeader(e){this.#N=void 0,this.#se=e.name,(this.#O?.info?.agent.model.routing.kind!==`dynamic`||e.info?.agent.model.routing.kind!==`dynamic`)&&(this.#Qe=void 0),this.#O=e,this.#Yt();let t=this.#Wn().join(`
|
|
2
|
+
`);if(this.#P){t!==this.#F&&(this.#F=t,this.#_n({kind:`agent-header`,body:t,live:!1})),this.#zn();return}this.#P=!0,this.#F=t,this.#n.flush(this.#Wn(),this.#Yn(this.#rr()))}beginStartupDraft(e){this.#Yt({title:e.title}),this.#G=!0,this.#Z=!0,this.#k=`starting`,this.#N={name:e.title},this.#M=Date.now();let t=lineOf(stripPromptControlCharacters(e.initialDraft??``));this.#A=t,this.#ht(t),this.#cn(),this.#dn(),this.#zn();let apply=e=>{t=e,this.#A=e,this.#un(),this.#ht(t),this.#zn()};this.#j=e=>{if(e.type===`escape`&&this.#ct!==void 0){this.#ct(`escape`);return}if(e.type===`ctrl-c`&&this.#ct!==void 0){this.#Gt(),this.#ct(`ctrl-c`);return}let n=this.#W.apply(t,e,{multiline:!0});if(n!==void 0){apply(n);return}if(e.type===`enter`&&t.text.trim().length>0){this.#et.enqueue(t.text)&&apply(EMPTY_LINE);return}e.type===`ctrl-c`&&this.#he?.()},this.#mt()}#mt(){this.#A!==void 0&&this.#j!==void 0&&(this.#an(),this.#ht(this.#A),this.#G=!0,this.#Ce=this.#j,this.#Qt())}finishStartupDraft(){let e={draft:this.#A?.text??this.#V,queuedPrompt:this.#et.takePrompt()};return this.#A=void 0,this.#j=void 0,this.#$t(),this.#ln(),this.#G=!1,this.#Z=!1,e}async readPrompt(e){this.#Yt(e),this.#gn(),this.#yn(),this.#G=!0,this.#Z=!0,this.#re={kind:`idle`},this.#ae=``,this.#pe=this.#me,this.#me=!1;let t=this.#et.restoreDraft()?.split(`
|
|
3
3
|
`).map(stripPromptControlCharacters).join(`
|
|
4
|
-
`),n=stripPromptControlCharacters(e?.initialDraft??this.#te.text),r=t===void 0?n:n.length===0?t:`${t}\n\n${n}`,i=lineOf(r);return this.#te=EMPTY_LINE,this.#U.begin(i.text),this.#ht(i),this.#ft(i.text),this.#cn(),this.#zn(),await new Promise((e,t)=>{this.#ie=t;let apply=e=>{i=e,this.#un(),this.#ht(i),this.#ft(e.text),this.#zn()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#K=void 0,this.#ln(),this.#Zt(),t(interruptedError())},suggestions=()=>this.#K!==void 0&&isTypeaheadOpen(this.#K)?this.#K:void 0,argumentSuggestions=()=>this.#q?.suggestions.length?this.#q:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#Ce=t=>{t.type!==`ctrl-c`&&this.#pe&&(this.#pe=!1,this.#zn());let n=this.#W.apply(i,t,{multiline:!0});if(n!==void 0){apply(n);return}switch(t.type){case`up`:case`ctrl-p`:{let e=argumentSuggestions();if(e!==void 0){this.#q=moveArgumentTypeaheadSelection(e,-1),this.#zn();break}let t=suggestions();if(t!==void 0){this.#K=moveTypeaheadSelection(t,-1),this.#zn();break}let n=movePromptLine(i,`up`);n===void 0?recall(this.#U.previous(i.text)):apply(n);break}case`down`:case`ctrl-n`:{let e=argumentSuggestions();if(e!==void 0){this.#q=moveArgumentTypeaheadSelection(e,1),this.#zn();break}let t=suggestions();if(t!==void 0){this.#K=moveTypeaheadSelection(t,1),this.#zn();break}let n=movePromptLine(i,`down`);n===void 0?recall(this.#U.next()):apply(n);break}case`tab`:{let e=argumentSuggestions(),t=e===void 0?void 0:selectedArgumentSuggestion(e);if(e!==void 0&&t!==void 0){apply(lineOf(argumentTypeaheadCompletion(e,t)));break}let n=highlighted();n!==void 0&&apply(lineOf(typeaheadCompletion(n)));break}case`escape`:{if(this.#q!==void 0){this.#q=void 0,this.#zn();break}let e=suggestions();e!==void 0&&(this.#K=dismissTypeahead(e),this.#zn());break}case`enter`:{let t=argumentSuggestions(),n=t===void 0?void 0:selectedArgumentSuggestion(t),r=highlighted();if(t!==void 0&&n?.next!==void 0&&t.completed.length===0){apply(lineOf(`${argumentTypeaheadCompletion(t,n)} `));break}if(t===void 0&&r!==void 0&&this.#J!==void 0&&(r.name===`add`||r.name===`login`||r.name===`loglevel`||r.name===`model`)){apply(lineOf(typeaheadCompletion(r)));break}let a=t!==void 0&&n!==void 0?argumentTypeaheadCompletion(t,n):r!==void 0&&parsePromptCommand(i.text)===null?typeaheadCompletion(r).trimEnd():i.text;if(a.trim().length===0)break;this.#K=void 0,this.#q=void 0,promptCommandSpec(a)?.spec.history!==`omit`&&this.#U.add(a),this.#G=!1,this.#ln(),this.#ae=STATUS.processing,isPromptControlCommand(a)?this.#St(stripTerminalControls(a.trim())):(this.#fn(),this.#vn(a),this.#Ke=a,this.#$.arm()),this.#ht(EMPTY_LINE),this.#zn(),this.#$t(),e(a);break}case`ctrl-d`:i.text.length===0?(this.#Gt(),interrupt()):apply(deleteForward(i));break;case`ctrl-l`:this.#Hn();break;case`ctrl-r`:this.#zn();break;case`ctrl-c`:if(this.#pe){this.#Gt(),interrupt();break}this.#pe=!0,apply(EMPTY_LINE)}},this.#Qt()})}#ht(e){this.#V=e.text,this.#H=e.cursor}takeQueuedPrompt(){let e=this.#et.view().steering,t=this.#et.takePrompt();return t!==void 0&&(this.#at=e?`steer`:`queue`),t}async renderStream(e,t){this.#Yt(t),this.#v.clear(),this.#G=!1,this.#re.kind!==`waiting`&&(this.#re={kind:`waiting`,startedAtMs:Date.now()}),this.#ae=this.#R>0?STATUS.connectionAuth:STATUS.processing,this.#bn(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#f?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#$.armed&&this.#$.arm(),this.#de=!1,this.#rt=!1,this.#ot=!1,this.#st=t?.submittedPrompt,this.#et.beginTurn(),this.#tt=e.cancel,this.#nt=e.steer,this.#je=void 0,this.#Me=void 0,this.#Pe=void 0,this.#Fe=void 0,this.#Ie=Date.now();let n={text:new Map,reasoning:new Map,tools:new Map,modelActivity:`Thinking`,runningTools:new Set,cancelled:!1,restoreCancelledPrompt:!0};this.#ee=n;let r={tools:t?.tools??this.#o,reasoning:t?.reasoning??this.#s,assistantResponseStats:t?.assistantResponseStats??this.#u};this.#dn(),this.#ne=!0,this.#zn();let i=new Promise(e=>{this.#Oe=e});this.#Ce=e=>this.#on(e),this.#Qt();try{for await(let t of takeUntil(iterateTUIStream(e.events),i)){if(this.#de)break;this.#On(t,r,n)}}catch(e){let t=summarizeKnownError(e);t===null?this.#xn(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#xn(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#Oe=void 0,this.#de&&e.abort?.(),this.#tt=void 0,this.#nt=void 0,this.#$t(),this.#ne=!1,this.#ee=void 0,this.#re.kind===`waiting`&&(this.#re={kind:`idle`}),this.#gn(),this.#ae=completedTurnStatus({interrupted:this.#de,cancelled:this.#rt,continueSession:t?.continueSession===!0}),this.#Fn(n),(this.#de||n.cancelled)&&this.#Pn(n),this.#Dn(),this.#gn(),this.#f?.reportStats(),this.#zn(),t?.continueSession||this.#Zt()}}async renderIdleStream(e,t){let n={tools:t?.tools??this.#o,reasoning:t?.reasoning??this.#s,assistantResponseStats:t?.assistantResponseStats??this.#u},r={text:new Map,reasoning:new Map,tools:new Map,modelActivity:`Thinking`,runningTools:new Set,cancelled:!1,restoreCancelledPrompt:!1};try{for await(let t of iterateTUIStream(e.events))this.#On(t,n,r)}catch(e){let t=summarizeKnownError(e);t===null?this.#xn(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#xn(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#Fn(r),r.cancelled&&this.#Pn(r),this.#Dn(),this.#gn(),this.#f?.reportStats(),this.#zn()}}async readToolApproval(e,t){return this.#Yt(t),this.#pn(),this.#G=!1,this.#re={kind:`idle`},this.#ae=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#de=!1,this.#zn(),await new Promise((t,n)=>{this.#ie=n,this.#Ce=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#fn(),this.#ae=STATUS.processing,this.#$t(),this.#zn(),t({approved:!0})):n===`n`&&(this.#fn(),this.#ae=STATUS.processing,this.#_t(e.toolCallId),this.#$t(),this.#zn(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#zn();break;case`ctrl-c`:this.#de=!0,this.#Zt(),n(interruptedError())}},this.#Qt()})}async readInputQuestion(e,t){this.#Yt(t),this.#pn(),this.#G=!1,this.#Z=!1,this.#re={kind:`idle`},this.#de=!1;let n=e.options??[],r=n.length>0,i=(e.allowFreeform===!0||!r)&&r,a=n.length+ +!!i,o=questionSectionId(e.requestId),s=r?`overlay`:`text`,c=0,l=EMPTY_LINE,isOnFreeformRow=()=>i&&c===n.length,overlayPanel=t=>renderQuestionPanel({prompt:stripTerminalControls(e.prompt),options:n,cursor:c,allowFreeform:i,editor:l,caretVisible:this.#ge},this.#i,t),renderTextSection=()=>{this.#Cn({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#i),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#cn():(this.#ln(),this.#un())};s===`overlay`?(s=`overlay`,this.#G=!1,this.#Tn(o),this.#qe=overlayPanel,this.#ae=``,syncFreeformCaret(),this.#zn()):(s=`text`,this.#qe=void 0,renderTextSection(),this.#G=!0,this.#ht(l),this.#ae=``,this.#cn(),this.#zn());let finalize=t=>{this.#qe=void 0,this.#Cn({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#G=!1,this.#fn(),this.#ae=STATUS.processing,this.#ln(),this.#$t(),this.#zn();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#qe=void 0,this.#Cn({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${this.#i.colors.dim(`Skipped. The question stays open.`)}`,preformatted:!0,live:!1}),this.#G=!1,this.#ae=``,this.#ln(),this.#$t(),this.#zn(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#zn())},selectOptionAt=e=>{let t=n[e];t&&u(finalize({optionId:t.id,label:t.label}))},u;return await new Promise((t,r)=>{this.#ie=r,u=t,this.#Ce=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#un(),s===`text`&&this.#ht(l),this.#zn();return}this.#de=!0,this.#qe=void 0,this.#ln(),this.#Zt(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#zn();return}if(s===`overlay`){let r=setupSelectionIntent(t,{textNavigation:!isOnFreeformRow()});if(r?.kind===`move`){moveCursor(r.direction===`up`?-1:1);return}switch(t.type){case`up`:case`ctrl-p`:moveCursor(-1);break;case`down`:case`ctrl-n`:moveCursor(1);break;case`enter`:if(isOnFreeformRow()){let t=resolveQuestionText(l.text,e);t!==void 0&&u(finalize(t));break}selectOptionAt(c);break;case`escape`:if(isOnFreeformRow()&&l.text.length>0){l=EMPTY_LINE,this.#un(),this.#zn();break}dismiss();break;default:if(isOnFreeformRow()){let e=this.#W.apply(l,t);e!==void 0&&(l=e,this.#un(),this.#zn());break}if(t.type===`text`&&/^[1-9]$/u.test(t.value)){let e=Number(t.value)-1;e<n.length?selectOptionAt(e):e===n.length&&i&&(c=e,syncFreeformCaret(),this.#zn())}}return}let a=this.#W.apply(l,t,{multiline:!0});if(a!==void 0){l=a,this.#un(),this.#ht(l),this.#zn();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#un(),this.#ht(l),this.#zn());break}case`enter`:{let t=resolveQuestionText(l.text,e);if(t===void 0)break;u(finalize(t));break}case`escape`:if(l.text.length>0){l=EMPTY_LINE,this.#un(),this.#ht(l),this.#zn();break}dismiss()}},this.#Qt()})}upsertSubagentStep(e){if(this.#f?.recordSubagentDispatch(e.callId),this.#c===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(t.length!==0||n.length!==0){if(this.#Sn(e.callId,e.subagentName),this.#c===`collapsed`){this.#zn();return}this.#wn({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,subagentCallId:e.callId,depth:1,reasoning:t,body:n,collapsed:this.#c!==`full`,live:!e.finalized}),this.#zn()}}upsertSubagentTool(e){if(this.#f?.recordSubagentDispatch(e.callId),e.status===`failed`&&e.errorText!==void 0&&this.#f?.append({source:`tool`,summary:`${e.toolName} failed (subagent ${e.subagentName})`,detail:e.errorText}),this.#c===`hidden`)return;if(this.#Sn(e.callId,e.subagentName),this.#c===`collapsed`){this.#zn();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#Mn({input:e.input,output:e.output,toolCallId:e.childCallId,toolName:e.toolName})),r={id:subagentToolSectionId(e.callId,e.childCallId),kind:`subagent-tool`,subagentCallId:e.callId,depth:1,title:stripTerminalControls(n.title),subtitle:stripTerminalControls(n.subtitle),status:t,live:t===`running`||t===`approval`,expanded:this.#c===`full`,toolName:e.toolName,toolGroup:n.group,toolInput:e.input};n.doneTitle!==void 0&&(r.doneTitle=stripTerminalControls(n.doneTitle)),n.detail!==void 0&&(r.detailLines=n.detail,r.keepDetailWhenDone=n.keepDetailWhenDone===!0),e.output===void 0?e.errorText!==void 0&&(r.result=stripTerminalControls(e.errorText)):(r.result=n.summarizeResult(e.output),r.toolOutput=e.output),this.#wn(r),this.#gt(e.callId),this.#zn()}#gt(e){applyCohortLiveness(this.#h.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#Tn(subagentToolSectionId(e.callId,e.childCallId)),this.#zn()}subagents={begin:e=>this.beginSubagent(e),background:e=>this.backgroundSubagent(e),upsertStep:e=>this.upsertSubagentStep(e),upsertTool:e=>this.upsertSubagentTool(e),removeTool:e=>this.removeSubagentTool(e),complete:e=>this.completeSubagent(e),markChildToolCallId:e=>this.markChildToolCallId(e)};beginSubagent(e){if(this.#c===`hidden`)return;this.#Sn(e.callId,e.name);let t=this.#g.get(subagentHeaderId(e.callId));t!==void 0&&(t.status===`done`&&delete t.status,t.live=!0),this.#T.delete(e.callId),this.#zn()}backgroundSubagent(e){let t=this.#g.get(subagentHeaderId(e.callId));if(t===void 0||this.#v.has(subagentHeaderId(e.callId)))return;t.status=`running`,t.live=!0,t.updateSeq=++this.#S;let n=this.#w.has(e.callId);this.#w.add(e.callId),n||this.#En(e.callId),this.#gn(),this.#zn()}completeSubagent(e){let t=this.#g.get(subagentHeaderId(e.callId));if(t!==void 0){if(t.status=`done`,e.authoritative){this.#w.delete(e.callId),this.#T.delete(e.callId);for(let t of this.#h)t.subagentCallId===e.callId&&(t.live=!1)}else{this.#T.add(e.callId);for(let t of this.#h)t.subagentCallId===e.callId&&(t.live=!0)}this.#gn(),this.#zn()}}markChildToolCallId(e){this.#b.add(e);let t=this.#x.get(e);t!==void 0&&(this.#Tn(t),this.#x.delete(e),this.#zn())}#_t(e){let t=this.#g.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#l===`hidden`)return;let t=connectionAuthTerminalMessage(e.state);this.#Cn({id:connectionAuthSectionId(e.name),kind:`connection-auth`,title:`${stripTerminalControls(e.name)} · authorization · ${e.state}`,body:formatConnectionAuthContent(e,t),preformatted:!0,live:t===void 0}),this.#zn()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#R)return;let n=this.#R>0;this.#R=t,t>0?(this.#ae=STATUS.connectionAuth,this.#zn()):n&&(this.#ae=STATUS.processing,this.#zn())}setVercelStatus(e){this.#z=e,this.#zn()}setRemoteConnectionStatus(e){this.#B=e,this.#zn()}reset(){this.#h=[],this.#g.clear(),this.#v.clear(),this.#L=void 0,this.#I.length=0,this.#y.length=0,this.#P=!1,this.#F=void 0,this.#vt(),this.#Q=!1,this.#Ke=void 0,this.#Ve=void 0,this.#R=0,this.#je=void 0,this.#Me=void 0,this.#Pe=void 0,this.#Fe=void 0,this.#Ie=void 0,this.#ce&&(this.#n.clearAll(),this.#zn())}renderSessionBoundary(){this.#yn(),this.#vt();let e=this.#i.colors,t=this.#i.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#_n({kind:`session-boundary`,body:n,live:!1}),this.#zn()}#vt(){this.#Qe=void 0,this.#$e=void 0,this.#b.clear(),this.#x.clear(),this.#D.clear(),this.#w.clear(),this.#T.clear(),this.#C.clear(),this.#et.reset(),this.#at=void 0,this.#E.clear(),this.#$.reset(),this.#gn()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#Yt(),this.#_n({kind:`notice`,body:t,live:!1}),this.#zn())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#yt();return}this.#Yt(),this.#Ze=t,this.#zn()}clearSetupWarning(){this.#yt()}#yt(){this.#Ze!==void 0&&(this.#Ze=void 0,this.#zn())}renderCommandInvocation(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#Yt(),this.#St(t),this.#zn())}async choosePromptCommand(e){this.#Yt(),this.#G=!1;let t=typeaheadFor(e,`/`);return this.#Je=e=>{let n=renderCommandSuggestions(t,this.#i,e),r=Math.max(1,this.#ar()-7),i=Math.max(0,Math.min(t.selectedIndex-r+1,n.length-r));return renderTransientDrawer(n.slice(i,i+r),[`↑/↓ move · Enter select · Esc close`],this.#i,e)},this.#ae=``,this.#zn(),await new Promise(e=>{this.#Ye=()=>e(void 0),this.#Ce=n=>{if(n.type===`up`||n.type===`ctrl-p`)t=moveTypeaheadSelection(t,-1),this.#zn();else if(n.type===`down`||n.type===`ctrl-n`)t=moveTypeaheadSelection(t,1),this.#zn();else if(n.type===`enter`){let n=selectedTypeaheadCommand(t);this.#bt(),e(n===void 0?void 0:typeaheadCompletion(n))}else(n.type===`escape`||n.type===`ctrl-c`)&&(this.#bt(),e(void 0))},this.#Qt()})}async showInfoPanel(e){this.#Yt(),this.#G=!1;let t=stripAnsi(e),n=0,infoRows=e=>t.split(`
|
|
5
|
-
`).flatMap(t=>wrapVisibleLine(t,Math.max(1,e-4)).map(e=>` ${e}`));this.#Je=e=>{let t=infoRows(e),r=Math.max(1,this.#
|
|
6
|
-
`),live:!1}),this.#_n({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#zn()}}async#Dt(e){let t=this.#Nt(e.message),n=isMultiSelectRequest(e),r=e.kind===`search`?e.searchAction:void 0,i=e.kind===`search`&&e.layout===void 0,a=e.options,o=e.navigation?.kind===`planner`,s={options:a,searchAction:r,submitRow:n&&!o};`initialValue`in e&&e.initialValue!==void 0&&(s.defaultValue=e.initialValue),`initialValues`in e&&e.initialValues!==void 0&&(s.initialValues=e.initialValues);let c=initialSelectState(s),l,u=!1,d=0,isCurrentSearch=e=>e===d,clearSearch=()=>{d+=1,u=!1,c=reduceSelect(c,{type:`clear`},{options:a,searchAction:r,submitRow:n&&!o}),this.#zn()},loadSearch=async(e,t)=>{u=!0,l=void 0;let i=++d;this.#zn();try{let s=await t(e);if(!isCurrentSearch(i))return;let l=c.filter;a=s,c={...initialSelectState({options:s,searchAction:r,submitRow:n&&!o}),filter:l}}catch(e){isCurrentSearch(i)&&(l=toErrorMessage(e))}finally{isCurrentSearch(i)&&(u=!1,this.#zn())}},f=e.notices;if(e.kind===`task-list`||e.kind===`search`&&e.layout===`task-list`){let n=t.taskListLineStart??t.lines.length,r=t.lines.slice(n).filter(e=>e.tone===`success`||e.tone===`warning`||e.tone===`error`).map(e=>({tone:e.tone,text:e.text}));f=e.notices??r,t.taskListLineStart=t.lines.length,t.hideLinesWhileQuestion=!0}let panelState=()=>{let t={...e,message:``,options:a,select:c};return f!==void 0&&f.length>0&&(t.notices=f),l!==void 0&&(t.error=l),u&&(t.loadingFrame=this.#Kn()),i&&(t.caretVisible=this.#ge),t};return t.question=e=>renderSelectQuestion(panelState(),this.#i,e),i&&this.#cn(),this.#zn(),await this.#It((t,s)=>{let close=e=>{d+=1,s(e)};if(u){t.type===`ctrl-c`?close(void 0):t.type===`escape`?clearSearch():t.type===`ctrl-r`&&this.#zn();return}let f=e.navigation?.kind===`planner`?e.navigation:void 0,p=t.type===`left`&&(f?.activeStep??0)>(f?.firstNavigableStep??0)?`back`:t.type===`right`&&f!==void 0&&f.activeStep>=(f.firstNavigableStep??0)&&f.activeStep<f.steps.length-1?`forward`:void 0;if(p!==void 0){close({kind:`navigate`,direction:p,values:n?orderedSelection(a,c.selected):[]});return}let m={key:t,options:a,searchAction:r,select:c},h=reduceSetupSelectInput(n?{...m,kind:e.kind,required:e.required,plannerNavigation:o||void 0}:{...m,kind:e.kind});switch(h.kind){case`cancel`:close(void 0);return;case`repaint`:this.#zn();return;case`update`:c=h.select,l=void 0,i&&this.#un(),this.#zn();return;case`submit`:{let e=searchActionQuery(h.values[0]??``),t=r?.load;if(e===void 0||t===void 0){close(h.values);return}loadSearch(e,t);return}case`error`:l=h.message,this.#zn();return;case`ignore`:return}},i?()=>this.#ln():void 0).promise}#Ot(e){this.#Yt();let t=this.#Pt();t.status={text:stripTerminalControls(e.status),startedAtMs:Date.now()};let n;t.question=t=>renderSelectQuestion({kind:`actions`,context:e.context,actions:e.actions,cursor:n},this.#i,t),this.#zn();let r=this.#It((t,r)=>{let i=setupSelectionIntent(t,{textNavigation:!0});switch(i?.kind){case`cancel`:r(void 0);return;case`move`:n=moveActionCursor(n,i.direction,e.actions.length),this.#zn();return;case`repaint`:this.#zn();return;case`submit`:n!==void 0&&r(e.actions[n].value);return;case void 0:return}},()=>{t.status=void 0});return{choice:r.promise,close:()=>r.settle(void 0)}}async#kt(e){let t=this.#Nt(e.message),n={options:e.options};e.initialValue!==void 0&&(n.defaultValue=e.initialValue);let r=initialSelectState(n),i=lineOf(``),a;t.question=t=>{let n={kind:`inline-edit`,layout:`task-list`,message:``,options:e.options,select:r,edit:{optionValue:e.editable.value,caretVisible:this.#ge,editor:{kind:`rename`,editor:i,defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint}}};return a!==void 0&&(n.error=a),renderSelectQuestion(n,this.#i,t)};let onEditableRow=()=>selectValueAtCursor([...e.options],r.cursor)===e.editable.value,syncEditableRow=()=>{onEditableRow()?this.#cn():(i=lineOf(``),this.#ln())};return syncEditableRow(),this.#zn(),await this.#It((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#un(),this.#zn()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#zn()},submit=()=>{let t=selectValueAtCursor([...e.options],r.cursor);if(t===void 0)return;if(t!==e.editable.value){n({kind:`selected`,value:t});return}let o=(i.text||e.editable.defaultValue).trim(),s=e.editable.validate?.(o);if(s!==void 0){a=s,this.#zn();return}n(o===e.editable.defaultValue?{kind:`selected`,value:t}:{kind:`edited`,value:t,text:o})},o=setupSelectionIntent(t,{textNavigation:!onEditableRow()});switch(o?.kind){case`cancel`:n(void 0);return;case`move`:applySelect({type:o.direction});return;case`submit`:submit();return;case`repaint`:this.#zn();return;case void 0:}if(!onEditableRow())return;let s=this.#W.apply(i,t);s!==void 0&&applyEditor(s)},()=>this.#ln()).promise}async#At(e){this.#W.clear();let t=this.#Nt(e.message),n=initialProviderPickerState(e.options,e.initialValue),r,cursorBadge=()=>{if(n.phase.kind!==`inactive`)return;let t=selectValueAtCursor([...e.options],n.select.cursor),r=e.options.find(e=>e.value===t);if(r!==void 0)return enterBadge(this.#i,r.checked===!0?`change`:void 0)};t.question=t=>{let r=cursorBadge(),i={kind:`inline-edit`,layout:`stacked`,message:``,options:e.options,select:n.select,edit:{optionValue:`ai-gateway-key`,caretVisible:this.#ge,editor:{kind:`key`,phase:n.phase}}};return r!==void 0&&(i.cursorBadge=r),renderSelectQuestion(i,this.#i,t)};let syncCaret=()=>{n.phase.kind===`editing`||n.phase.kind===`invalid`?this.#cn():this.#ln()};return syncCaret(),this.#zn(),await this.#It((t,i,a)=>{let dispatch=t=>{let o=transitionProviderPicker(n,t,e.options);switch(o.kind){case`ignore`:return;case`clear`:r?.abort(),r=void 0,n=o.state,syncCaret(),this.#zn();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#zn();return;case`validate`:{n=o.state,syncCaret(),this.#zn();let t=new AbortController;r=t;let i;try{i=e.validateInlineKey(o.key,t.signal)}catch(e){a(e);return}i.then(e=>{r!==t||t.signal.aborted||(r=void 0,dispatch({type:`validated`,validation:e}))},e=>{r!==t||t.signal.aborted||(r=void 0,a(e))});return}case`settle`:i(o.result);return}},o=setupSelectionIntent(t,{textNavigation:n.phase.kind===`inactive`});switch(o?.kind){case`cancel`:dispatch({type:`cancel`});return;case`move`:dispatch({type:`move`,direction:o.direction});return;case`submit`:dispatch({type:`submit`});return;case`repaint`:this.#zn();return;case void 0:}if(n.phase.kind!==`editing`&&n.phase.kind!==`invalid`)return;let s=applyLineEditorKey(n.phase.editor,t);s!==void 0&&(this.#un(),dispatch({type:`edit`,editor:s}))},()=>{r?.abort(),r=void 0,this.#ln()}).promise}async#jt(e){e.mask===!0&&this.#W.clear();let t=this.#Nt(e.message),n=lineOf(``),r;return t.question=t=>{let i={message:``,editor:n,mask:e.mask===!0};return e.placeholder===void 0?e.defaultValue!==void 0&&(i.placeholder=e.defaultValue):i.placeholder=e.placeholder,e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#i,t,this.#ge)},this.#cn(),this.#zn(),await this.#It((t,i)=>{let apply=e=>{n=e,r=void 0,this.#un(),this.#zn()},a=e.mask?applyLineEditorKey(n,t):this.#W.apply(n,t);if(a!==void 0){apply(a);return}switch(t.type){case`ctrl-c`:case`escape`:i(void 0);return;case`ctrl-r`:this.#zn();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#zn();return}i(t);return}default:return}},()=>this.#ln()).promise}async#Mt(e){let t=this.#Nt(e.message);return t.question=t=>renderAcknowledgeQuestion({message:``,lines:e.lines},this.#i,t),this.#zn(),await this.#It((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#zn();return;default:return}}).promise}#Nt(e){this.#Yt(),this.#G=!1,this.#re={kind:`idle`},this.#ae=``;let t=this.#Pt();return t.questionTitle=stripTerminalControls(e),t.status!==void 0&&(t.status=void 0,t.summary=void 0,t.preview=void 0),t}#Pt(){return this.#Xe===void 0&&(this.#Xe={title:``,startedAtMs:Date.now(),lines:[],outputBuffer:[],implicit:!0}),this.#Xe}#Ft(){this.#Xe?.implicit===!0?this.#Xe=void 0:this.#Xe!==void 0&&(this.#Xe.question=void 0,this.#Xe.questionTitle=void 0,this.#Xe.hideLinesWhileQuestion=!1),this.#Ce=void 0,this.#$t(),this.#A===void 0?this.#Xe!==void 0&&this.#Rt():this.#mt(),this.#Xe===void 0&&this.#zn()}#It(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#Ft(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#Ft(),i(e))};return this.#an(),this.#Ce=t=>{t.type===`ctrl-c`&&this.#Gt(),e(t,settle,reject)},this.#Qt(),{promise:a,settle}}#Lt(e){let t,n=new Promise(e=>{t=e});return this.#ct=t,this.#Rt(e?.interruptible??!0),{promise:n,dispose:()=>{this.#ct===t&&(this.#ct=void 0,this.#zt())}}}#Rt(e=!0){if(this.#A!==void 0){this.#mt();return}if(this.#ct===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#Gt();let e=this.#ct;this.#ct=void 0,this.#zt(),e?.(t.type===`ctrl-c`?`ctrl-c`:`escape`);return}t.type===`ctrl-r`&&this.#zn()};this.#lt=consumer,this.#an(),this.#Ce=consumer,this.#Qt()}#zt(){this.#lt!==void 0&&(this.#Ce===this.#lt&&this.#$t(),this.#lt=void 0)}#Bt(e){let t=e===void 0?void 0:{text:stripTerminalControls(e),startedAtMs:Date.now()};if(this.#Xe!==void 0){this.#Xe.status=t,t===void 0&&(this.#Xe.preview=void 0),this.#zn();return}if(!(this.#G||this.#ne)){if(t===void 0){this.#re={kind:`idle`},this.#oe=void 0,this.#pn(),this.#zn();return}this.#Yt(),this.#fn(),this.#oe=t.text,this.#zn()}}#Vt(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#Xe;if(r!==void 0){if(r.preview=void 0,t===`warning`||t===`error`)for(let e of r.outputBuffer)r.lines.push({text:e,tone:`info`,evidence:!0});r.outputBuffer=[],r.lines.push({text:n,tone:t}),this.#zn();return}this.#Yt(),this.#_n({kind:`flow`,title:t,body:n,live:!1}),this.#zn()}#Ht(e){let t=this.#Xe;t!==void 0&&(t.lines=[],t.outputBuffer=[],t.preview=void 0,t.status=void 0,t.summary=e===void 0?void 0:{headline:stripTerminalControls(e.headline),facts:e.facts.map(e=>({label:stripTerminalControls(e.label),value:stripTerminalControls(e.value)}))},this.#zn())}#Ut(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#Xe;if(n===void 0){this.#Vt(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#zn()}async#Wt(e){this.#we=``,this.#an(),this.#ct=void 0,this.#zt(),this.#$t(),this.#mn(),this.#n.clear(),this.#sr(),this.#r.enter({cursor:`visible`,mouse:!1}),this.#e.isTTY&&this.#e.setRawMode?.(!1),this.#e.pause();try{return await e()}finally{this.#r.exit(),this.#e.isTTY&&this.#e.setRawMode?.(!0),this.#e.resume(),this.#we=``,this.#an(),this.#n.hideCursor(),this.#or(),this.#Xe===void 0?this.#gn():(this.#dn(),this.#Rt()),this.#n.reset(),this.#zn()}}setSessionId(e){this.#it=e}shutdown(){this.#Zt();for(let e of this.#X.values())clearTimeout(e);if(this.#X.clear(),this.#le&&!this.#ue){this.#ue=!0;let e=this.#it===void 0?``:` ${this.#i.glyph.dot} session ${this.#it}`;this.#t.write(`${this.#i.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}suspendPromptForInput(){this.#te={cursor:this.#H,text:this.#V},this.#Zt()}requestInterrupt(){this.#de=!0,this.#Xe!==void 0&&this.#Ce?.({type:`ctrl-c`}),this.#Oe?.(),this.#Zt()}exitRequested(){return this.#fe}#Gt(){this.#fe=!0,this.#he?.()}async#Kt(e){if(this.#ut!==void 0||!this.#ce)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#ir(),height:this.#ar()}),paint:e=>this.#r.paint(e,this.#ar()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e)),terminalBackground:this.#dt});this.#ut=t,this.#r.enter(),this.#i.color&&this.#r.writeRaw(BACKGROUND_COLOR_QUERY),await new Promise(e=>{this.#Jt=e,this.#Ce=e=>{t.handleKey(e)===`close`&&this.#qt()},this.#Qt(),t.start()})}#qt(){let e=this.#ut;if(e===void 0)return;this.#ut=void 0,e.dispose(),this.#$t(),this.#r.exit(),this.#n.hideCursor(),this.#zn(),this.#n.showCursor();let t=this.#Jt;this.#Jt=void 0,t?.()}#Jt;#Yt(e){this.#se=e?.title??this.#se,e?.contextSize!==void 0&&(this.#Ne=e.contextSize),!this.#ce&&(this.#ce=!0,this.#le=!0,this.#n.reset(),this.#n.hideCursor(),this.#or(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#De=()=>this.#zn(),this.#t.on(`resize`,this.#De),process.on(`exit`,this.#Xt))}#Xt=()=>{this.#ce&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#Zt(){let e=this.#Ye;e!==void 0&&(this.#Ye=void 0,this.#Je=void 0,this.finishCommand({kind:`dismiss`}),this.#Ce=void 0,e()),this.#qt();let t=this.#ie;if(this.#ie=void 0,t?.(interruptedError()),this.#$t(),this.#ln(),this.#mn(),this.#xe!==void 0&&(clearTimeout(this.#xe),this.#xe=void 0),this.#Se=!1,this.#hr(),this.#ce){this.#_r(),this.#Ct();for(let e of this.#h)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#zn(),this.#n.clear(),this.#n.showCursor(),this.#sr(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#De&&=(this.#t.off(`resize`,this.#De),void 0),process.off(`exit`,this.#Xt),this.#ce=!1}}#Qt(){this.#e.off(`data`,this.#en),this.#e.on(`data`,this.#en),this.#we.length>0&&queueMicrotask(()=>{this.#Ce!==void 0&&this.#we.length>0&&(this.#rn(),this.#tn())})}#$t(){this.#e.off(`data`,this.#en),this.#an(),this.#Ce=void 0}#en=e=>{this.#an(),this.#we+=this.#Te.write(e),this.#rn(),this.#tn()};#tn(){if(this.#we===`\x1B`){this.#Ee=setTimeout(()=>{this.#we===`\x1B`&&(this.#we=``,this.#nn({type:`escape`}))},30),this.#Ee.unref?.();return}if(isIncompletePaste(this.#we)){let e=this.#we;this.#Ee=setTimeout(()=>{if(this.#we!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#we=``,t.length>0&&this.#nn({type:`text`,value:t,framing:`bracketed-paste`})},incompletePasteFlushMs),this.#Ee.unref?.();return}if(isIncompleteOsc(this.#we)){let e=this.#we;this.#Ee=setTimeout(()=>{this.#we===e&&(this.#we=``)},incompletePasteFlushMs),this.#Ee.unref?.()}}#nn(e){this.#W.interruptYank(e),this.#Ce?.(e)}#rn(){for(;this.#we.length>0;){let e=nextKey(this.#we);if(e.incomplete)return;if(this.#we=this.#we.slice(e.consumed),e.key!==void 0&&e.key.type!==`ignore`){if(e.key.type===`osc`){this.#in(e.key.value);continue}this.#nn(e.key)}}}#in(e){let t=parseBackgroundColorReply(e);t!==void 0&&(this.#dt=t,this.#ut?.setTerminalBackground(t))}#an(){this.#Ee&&=(clearTimeout(this.#Ee),void 0)}#on(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#zn();break;case`enter`:{let e=this.#te.text;if(e.trim().length===0)break;if(parsePromptCommand(e)?.type===`cancel`&&this.#tt!==void 0){this.#te=EMPTY_LINE,this.#et.requestCancellation(),this.#ot=!0,this.renderCommandInvocation(e.trim()),this.finishCommand({kind:`result`,summary:`Cancellation requested`}),this.#tt(),this.#zn();break}let t=this.#nt;t!==void 0&&parsePromptCommand(e)===null?(this.#te=EMPTY_LINE,this.#sn(e,t)):this.#et.enqueue(e)&&(this.#te=EMPTY_LINE),this.#zn();break}case`ctrl-c`:case`escape`:if(e.type===`ctrl-c`&&this.#et.view().cancelling){this.#de=!0,this.#me=!0,this.#re={kind:`idle`},this.#ae=`Interrupted`,this.#Oe?.(),this.#zn();break}if(this.#et.idle&&this.#tt===void 0)break;if(this.#et.handleEscape()===`steer`){let e=this.#nt;if(e!==void 0){let t=this.#et.takeSteering();this.#sn(t,e)}}else this.#ot=!0,this.#tt?.();this.#zn();break;default:{let t=this.#W.apply(this.#te,e,{multiline:!0});t!==void 0&&(this.#te=t,this.#zn());break}}}#sn(e,t){this.#at=`steer`,this.#bn(e),t(e).catch(t=>{this.#et.restoreSteering(e),this.#xn(`Steering failed`,toErrorMessage(t)),this.#zn()})}#cn(){this.#ln(),this.#un(),this.#ye=setInterval(()=>{this.#ge=!this.#ge,this.#zn()},500),this.#ye.unref?.()}#ln(){this.#ye&&=(clearInterval(this.#ye),void 0),this.#ge=!0}#un(){this.#ge=!0}#dn(){this.#mn(),this.#be=setInterval(()=>{this.#_e+=1,this.#zn()},90),this.#be.unref?.()}#fn(){let e=Date.now();this.#ve=e,this.#re={kind:`waiting`,startedAtMs:e},this.#dn()}#pn(){this.#hn()||this.#mn()}#mn(){this.#be&&=(clearInterval(this.#be),void 0)}#hn(){return this.#h.some(e=>e.live&&e.subagentCallId!==void 0&&(this.#w.has(e.subagentCallId)||this.#T.has(e.subagentCallId)))}#gn(){this.#hn()?this.#dn():!this.#ne&&this.#re.kind===`idle`&&this.#mn()}#_n(e){e.id!==this.#Ve?.id&&this.#_r(),e.updateSeq=++this.#S;let t=e.subagentCallId!==void 0&&this.#w.has(e.subagentCallId)?-1:this.#h.findIndex(e=>e.subagentCallId!==void 0&&this.#w.has(e.subagentCallId));t<0?this.#h.push(e):this.#h.splice(t,0,e),e.id&&this.#g.set(e.id,e)}#vn(e){this.#Q=!0,this.#_n({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#zn()}#yn(){let e=this.#$.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#Zn(e.elapsedMs)}`,n=this.#Me??0;if(this.#Ne!==void 0&&this.#Ne>0&&n>0){let e=Math.round(n/this.#Ne*100);t+=` ${this.#i.glyph.dot} ${e}% context`}this.#_n({kind:`turn-stats`,body:t,live:!1})}#bn(e){if(e==null)return;let t=this.#at;if(this.#at=void 0,this.#Ke===e){this.#Ke=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#_n(n)}#xn(e,t,n={}){let r=stripTerminalControls(e),i=stripTerminalControls(t),a=n.detail===void 0?void 0:stripTerminalControls(n.detail),o=n.hint===void 0?void 0:stripTerminalControls(n.hint),s={source:`workflow`,summary:`${r}: ${i}`,detail:a??i};this.#f?.append(o===void 0?s:{...s,hint:o});let c={kind:`error`,title:r,body:i,live:!1};o!==void 0&&(c.hint=o),a!==void 0&&(c.detail=this.#f===void 0?a:`details: ${this.#f.displayPath}`),this.#_n(c),this.#zn()}#Sn(e,t){if(this.#D.has(e))return;this.#D.add(e);let n=stripTerminalControls(t),r=this.#C.get(n)??[];if(r.push(e),this.#C.set(n,r),r.length===2){let e=this.#g.get(subagentHeaderId(r[0]));e!==void 0&&(e.subtitle=`#1`)}let i={id:subagentHeaderId(e),kind:`subagent`,subagentCallId:e,title:n,live:!0};r.length>1&&(i.subtitle=`#${r.length}`),this.#_n(i)}#Cn(e){if(e.id&&this.#v.has(e.id))return;let t=e.id?this.#g.get(e.id):void 0;if(t){Object.assign(t,e),t.updateSeq=++this.#S;return}this.#_n(e)}#wn(e){if(e.id&&this.#v.has(e.id))return;let t=e.id?this.#g.get(e.id):void 0;if(t!==void 0){Object.assign(t,e),t.updateSeq=++this.#S;return}let n=e.subagentCallId;if(n===void 0){this.#_n(e);return}e.id!==this.#Ve?.id&&this.#_r(),e.updateSeq=++this.#S;let r=-1;for(let e=0;e<this.#h.length;e+=1)this.#h[e]?.subagentCallId===n&&(r=e);this.#h.splice(r<0?this.#h.length:r+1,0,e),e.id!==void 0&&this.#g.set(e.id,e)}#Tn(e){this.#h=this.#h.filter(t=>t.id!==e),this.#g.delete(e)}#En(e){let t=this.#h.filter(t=>t.subagentCallId===e);t.length!==0&&(this.#h=this.#h.filter(t=>t.subagentCallId!==e),this.#h.push(...t))}#Dn(){for(let e of this.#h)e.subagentCallId!==void 0&&this.#T.has(e.subagentCallId)||e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||e===this.#_||(e.live=!1)}#On(e,t,n){let r=turnActivityLabel(n);switch(updateTurnActivity(n,e),e.type){case`turn-start`:e.turnId!==this.#$e&&(this.#$e=e.turnId,this.#Qe=void 0,this.#zn());break;case`step-start`:this.#Qe=typeof e.modelId==`string`&&stripTerminalControls(e.modelId.slice(0,256)).replace(/\s+/gu,` `).trim()||void 0,this.#zn();break;case`step-finish`:this.#f?.recordStepUsage(e.usage),e.usage!==void 0&&this.#$.addUsage(e.usage),this.#Fn(n),this.#Rn(e.usage),this.#zn();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#kn(e.id,t,!0);break}case`assistant-complete`:{let t=n.text.get(e.id)??``,r=typeof e.text==`string`?stripTerminalControls(e.text):t;n.text.set(e.id,r),this.#kn(e.id,r,!1);break}case`reasoning-delta`:{if(t.reasoning===`hidden`)break;let r=(n.reasoning.get(e.id)??``)+stripTerminalControls(e.delta);if(n.reasoning.set(e.id,r),t.reasoning===`full`){this.#An(e.id,r,!0,t);break}break}case`reasoning-complete`:{if(t.reasoning===`hidden`)break;let r=n.reasoning.get(e.id)??``;if(t.reasoning===`full`){this.#An(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#jn({input:void 0,preparing:!0,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-call`:if(this.#f?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#jn({input:e.input,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-approval-request`:{if(t.tools===`hidden`)break;let r=n.tools.get(e.toolCallId);if(r===void 0)break;this.#jn({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#Ln(e.toolCallId,n);if(r===void 0)break;this.#jn({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#Ln(e.toolCallId,n);if(this.#f?.append({source:`tool`,summary:`${r?.toolName??e.toolCallId} failed`,detail:e.errorText}),t.tools===`hidden`||r===void 0)break;this.#jn({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#Ln(e.toolCallId,n);if(r===void 0)break;this.#jn({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#xn(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:if(n.cancelled=!0,!n.restoreCancelledPrompt)break;this.#rt=!0,!this.#ot&&this.#st!==void 0&&this.#te.text.length===0&&(this.#te=lineOf(this.#st),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#Rn(e.usage),this.#zn()}n===this.#ee&&turnActivityLabel(n)!==r&&this.#zn()}#kn(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Cn({id:e,kind:`assistant`,body:r,live:n}),this.#zn())}#An(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Cn({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#zn())}#jn(e,t,n){if(n.tools.set(e.toolCallId,e),this.#b.has(e.toolCallId)||isPanelRoutedTool(e.toolName))return;let r=toolSectionId(e.toolCallId);this.#x.set(e.toolCallId,r);let i=this.#Mn(e);this.#Cn(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#In(n),this.#zn()}#Mn(e){e.output!==void 0&&this.#E.observeRead(e.output);let t={};this.#Nn(e.toolName)&&(t.isSubagent=!0);let n=readWriteFileInput(e.toolName,e.input);if(n===void 0)return t.isSubagent===!0?t:void 0;let r=this.#E.observeWrite({path:n.path,content:n.content,callId:e.toolCallId});r!==void 0&&(t.previousContent=r);let i=writeExistedFlag(e.output);return i!==void 0&&(t.existed=i),t}#Nn(e){let t=this.#O?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#Pn(e){for(let t of e.tools.keys()){if(this.#b.has(t))continue;let e=this.#x.get(t)??toolSectionId(t),n=this.#g.get(e);n?.kind===`tool`&&n.status===`running`&&(n.status=`error`,n.result=`interrupted`,n.live=!1)}}#Fn(e){for(let[t,n]of e.tools){if(n.preparing!==!0)continue;e.tools.delete(t);let r=this.#x.get(t)??toolSectionId(t);this.#Tn(r),this.#x.delete(t)}}#In(e){let t=[];for(let n of e.tools.values()){if(this.#b.has(n.toolCallId))continue;let e=this.#x.get(n.toolCallId)??toolSectionId(n.toolCallId),r=this.#g.get(e);r?.kind===`tool`&&t.push({block:r,active:isActiveToolStatus(n.status)})}applyCohortLiveness(t)}#Ln(e,t){let n=t.tools.get(e);if(n!==void 0)return n;let r=this.#x.get(e)??toolSectionId(e),i=this.#g.get(r);if(i!==void 0&&i.kind===`tool`)return{errorText:i.status===`error`&&typeof i.result==`string`?i.result:void 0,input:i.toolInput,output:i.toolOutput,status:i.status??`running`,toolCallId:e,toolName:i.toolName??i.title??`tool`}}#Rn(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#je=(t??0)+(n??0)),this.#Me=t??this.#Me,this.#Pe=n??this.#Pe,this.#Pe!=null&&this.#Ie!==void 0){let e=(Date.now()-this.#Ie)/1e3;e>0&&(this.#Fe=this.#Pe/e)}}#zn(){if(this.#ce){if(this.#ke){this.#Ae=!0;return}this.#ke=!0;try{do this.#Ae=!1,this.#Bn();while(this.#Ae)}finally{this.#ke=!1}}}#Bn(){if(!this.#ce)return;if(this.#ut!==void 0){this.#ut.repaint();return}let e=this.#ir(),t=this.#Yn(e),n=this.#N===void 0?[]:this.#Wn(),r=Math.max(1,this.#ar()-n.length-t.length),i=[],a=this.#L,o=groupToolBlocksForDisplay(this.#h),s=0;for(;s<o.length&&o[s].display.live===!1;)s+=1;if(s>0){let e=new Set(o.slice(0,s).flatMap(e=>e.members));for(let t=this.#h.length-1;t>=0;--t)e.has(this.#h[t])&&this.#h.splice(t,1)}for(let t of o.slice(0,s)){for(let e of t.members)this.#y.push(e),e.id&&(this.#v.add(e.id),this.#g.delete(e.id));if(this.#yr(t.display))continue;let n=this.#Gn(t.display,e,a);a=previousBlockOf(t.display),this.#L=a,i.push(...n),this.#I.push(...n)}let c=[];for(let{display:t}of o.slice(s)){if(this.#yr(t))continue;let n=this.#Gn(t,e,a);a=previousBlockOf(t);for(let e=0;e<n.length;e+=1)c.push({block:t,row:n[e]})}let l=[...n,...clipLiveRows(c.map(e=>e.row),r,e,this.#i),...t];i.length>0?this.#n.flush(i,l):this.#n.update(l)}#Vn(){if(!this.#ce)return;let e=this.#ir(),t=this.#Yn(e),n=Math.max(1,this.#ar()-t.length),r=this.#L,i=[];for(let{display:t}of groupToolBlocksForDisplay(this.#h)){if(this.#yr(t))continue;let n=this.#Gn(t,e,r);r=previousBlockOf(t),i.push(...n)}let a=[...clipLiveRows(i,n,e,this.#i),...t];this.#n.clearAll(),this.#n.flush([...this.#Wn(),...this.#I],a)}logDisplayMode(){return this.#m}setLogDisplayMode(e){e!==this.#m&&(this.#m=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#Un(),this.#ce&&this.#Vn())}flushDelayedDevBuildErrors(){let e=this.#Be;e!==void 0&&(this.#Be=void 0,this.#_n({kind:`log`,title:`stderr`,body:e,live:!0}),this.#zn())}#Hn(){this.#Se=!0,this.#xe!==void 0&&clearTimeout(this.#xe),this.#xe=setTimeout(()=>{this.#Se=!1,this.#xe=void 0,this.#zn()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#m)),this.#zn()}#Un(){let e=this.#ir();this.#I.length=0;let t;for(let{display:n}of groupToolBlocksForDisplay(this.#y,{logCoalescing:`runs`})){if(this.#yr(n))continue;let r=this.#Gn(n,e,t);t=previousBlockOf(n),this.#I.push(...r)}this.#L=t}#Wn(){let e=this.#O,t=this.#N;if(e===void 0&&t===void 0)return[];let n={name:e?.name??t?.name,theme:this.#i,width:this.#ir()};return e?.info!==void 0&&(n.info=e.info),buildAgentHeader(n)}#Gn(e,t,n){let r={renderMarkdown:this.#a,activityPulse:this.#qn(this.#ve,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)};n!==void 0&&(r.previous=n),this.#Xe!==void 0&&(r.setupFlowOpen=!0),this.#Je!==void 0&&(r.transientPanelOpen=!0);let i=renderBlockLines(e,t,this.#i,r);return(e.depth??0)===0&&leadsWithGap(e,n)?[``,...i]:i}#Kn(){return this.#i.spinner[this.#_e%this.#i.spinner.length]??``}#qn(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#Jn(e){return{glyph:this.#qn(e.startedAtMs,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)}}#Yn(e){let t=this.#i.colors,n=[``];if(this.#Je!==void 0){let t=this.#Je(e);return[...t.rows,...t.controls]}if(this.#qe!==void 0)return n.push(...this.#qe(e),``),this.#tr(n,e),n;let r=this.#Xe;if(r!==void 0&&(this.#A===void 0||r.question!==void 0)){let t=this.#Jn(r),i;if(r.status!==void 0){let{startedAtMs:e,...n}=r.status,a=Date.now()-e,o=a>=5e3?` ${formatTurnDuration(a)}`:``;i={...n,text:`${n.text}${o}`,indicator:t}}let a;if(r.question!==void 0){let t=r.question(e);a={kind:`question`,title:r.questionTitle,rows:t},i!==void 0&&(a={kind:`question`,title:r.questionTitle,rows:t,status:i})}else i===void 0?a=r.preview===void 0?{kind:`idle`,indicator:t}:{kind:`preview`,text:r.preview,indicator:t}:(a={kind:`status`,status:i},r.preview!==void 0&&(a={kind:`status`,status:i,preview:r.preview}));let o={title:r.title,navigation:r.navigation,lines:r.summary===void 0?r.hideLinesWhileQuestion===!0?[]:r.lines:[{text:r.summary.headline,tone:`success`},...r.summary.facts.map(e=>({text:`${e.label}: ${e.value}`,tone:`info`}))],content:a},s=renderFlowDrawer(o,this.#i,e);return n.length===1&&n[0]===``&&(n.length=0),n.push(...s.rows),s.controls.length>0&&n.push(...s.controls),this.#nr(n,e),n}r!==void 0&&n.push(...flowMessageRows(r.lines,this.#i).map(t=>t.length===0?``:clip(` ${t}`,e))),this.#k===void 0&&this.#Ze!==void 0&&n.push(...renderAttentionRows(this.#Ze,e,this.#i),``);let i=renderMessageQueueRows({view:this.#et.view(),width:e,theme:this.#i,working:this.#ne});if(i.length>0&&n.push(...i,``),this.#G){let r=this.#K===void 0?void 0:inlineCommandHint(this.#K),i=this.#pt(e);this.#pe&&n.push(clip(t.dim(`Press Ctrl+C again to exit`),e),``);let a=r?t.dim(` ${r}`):``,o=[];this.#tr(o,e);let s=Math.max(1,this.#ar()-1-n.length-1-i.length-o.length-(i.length>0?2:0)),c={text:this.#V,cursor:this.#H,width:e,theme:this.#i,caretVisible:this.#ge,ghost:a,maxRows:s};this.#Z&&this.#V.length===0&&(c.placeholder=this.#A===void 0?this.#Q?``:`Send a message…`:`Message · Enter to queue`);let l=promptInputRows(c);return i.length>0&&l.at(-1)===``&&l.pop(),n.push(...l),i.length>0&&n.push(t.dim(this.#i.glyph.dash.repeat(e))),n.push(...i),i.length>0&&o.length>0&&n.push(t.dim(this.#i.glyph.dash.repeat(e))),n.push(...o),n}let a=this.#re.kind===`waiting`&&this.#oe===void 0;if(this.#ne||a){n.push(this.#Xn(e)),this.#$n(n,e);let t=[];return this.#tr(t,e),!this.#ne&&t.length>0&&n.push(``),n.push(...t),n}if(this.#te.text.length>0)return this.#er(n,e,{inert:!1}),this.#tr(n,e),n;let o=this.#oe??(this.#ae.length>0?this.#ae:`Ready`),s=this.#rr(),c=t.dim(this.#i.glyph.dot),l=s?`${c} ${o} ${t.dim(this.#i.glyph.dot)} ${s}`:`${c} ${o}`;return n.push(clip(l,e)),this.#tr(n,e),n}#Xn(e){let t=this.#i.colors,n=this.#re,r=this.#$.startedAtMs??this.#Ie??(n.kind===`waiting`?n.startedAtMs:Date.now()),i=Math.max(0,Date.now()-r),a=i%1e3<500?this.#i.unicode?`•`:`*`:` `,o=i<1e3?`0s`:formatTurnDuration(Math.floor(i/1e3)*1e3),s=`${turnActivityLabel(this.#ee)} (${o})`,{inputTokens:c,outputTokens:l}=this.#$.usage;return clip(`${a} ${s}${c>0||l>0?t.dim(` (${formatTokenFlow({inputTokens:c,outputTokens:l},this.#i.glyph)})`):``}`,e)}#Zn(e){return`${formatTurnDuration(e)}${this.#Qn()}`}#Qn(){let{inputTokens:e,outputTokens:t}=this.#$.usage;return e===0&&t===0?``:` ${this.#i.glyph.dash.repeat(2)} ${formatTokenFlow({inputTokens:e,outputTokens:t},this.#i.glyph)}`}#$n(e,t){this.#ne&&this.#er(e,t,{inert:!0})}#er(e,t,n){e.push(``);let r={text:this.#te.text,cursor:this.#te.cursor,width:t,theme:this.#i,caretVisible:!0,ghost:``,maxRows:4,inert:n.inert};n.inert&&this.#te.text.length===0&&(r.placeholder=``),e.push(...promptInputRows(r))}#tr(e,t){if(this.#k!==void 0){let n=this.#Xe?.status?.text??{starting:`Starting agent…`,connecting:`Reading saved connection…`,updating:`Loading selected model…`}[this.#k],r=this.#qn(this.#M,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH);e.push(clip(this.#i.colors.dim(`${r} ${n}`),t));return}let n=this.#B===void 0?``:` `,r=Math.max(1,t-n.length),i={theme:this.#i,width:r};this.#Ue&&this.#He!==void 0&&(i.devBuild=this.#He),this.#Se&&(i.logLevel=this.#m);let a=this.#O?.info?.agent.model;a?.routing.kind===`dynamic`?i.model=this.#Qe===void 0?`dynamic model`:`dynamic model · ${this.#Qe}`:a?.id!==void 0&&(i.model=a.id),a?.reasoning!==void 0&&a.reasoning!==`provider-default`&&(i.reasoning=a.reasoning),readGatewayServiceTier(a?.providerOptions).kind===`priority`&&(i.fastMode=!0);let o=a?.endpoint;o!==void 0&&(i.endpoint=o),this.#z!==void 0&&(i.vercel=this.#z),this.#B!==void 0&&(i.remote=this.#B);let s=buildStatusLine(i);s!==void 0&&e.push(clip(`${n}${s}`,t))}#nr(e,t){if(this.#B===void 0)return;let n=Math.max(1,t-2),r=buildStatusLine({remote:this.#B,theme:this.#i,width:n});r!==void 0&&e.push(``,clip(` ${r}`,t))}#rr(){let e=this.#i.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#je,outputTokens:this.#Pe,tokensPerSecond:this.#Fe},this.#u);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#i.glyph.dot} `)):``}#ir(){return Math.max(20,this.#t.columns||80)}#ar(){return Math.max(8,this.#t.rows||24)}#or(){if(this.#Le!==void 0||!this.#d)return;this.#Re=``,this.#ze=``;let capture=(e,t)=>{let n=e.write.bind(e);return e.write=((e,n,r)=>{let i=typeof n==`string`?n:void 0,a=typeof n==`function`?n:r;return this.#lr(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#f?.subscribeLogRecords(e=>this.#cr(e)),this.#Le=()=>{this.#f?.unsubscribeLogRecords(),e(),t()}}#sr(){let e=this.#Le;e!==void 0&&(this.#Le=void 0,e(),this.#Re.length>0&&(this.#f?.append({source:`stdout`,detail:this.#Re}),this.#vr(`stdout`)&&process.stdout.write(`${this.#Re}\n`),this.#Re=``),this.#ze.length>0&&(this.#f?.append({source:`stderr`,detail:this.#ze}),this.#vr(`stderr`)&&process.stderr.write(`${this.#ze}\n`),this.#ze=``))}#cr(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#dr(`[eve:${e.namespace}] ${e.message}${t}`),this.#zn()}#lr(e,t){let n=(e===`stdout`?this.#Re:this.#ze)+t;if(e===`stdout`&&parseDevRebuildLogLine(n.trimEnd())!==void 0){this.#Re=``,this.#f?.append({source:e,detail:n.trimEnd()}),this.#ur(n.trimEnd()),this.#zn();return}let r=n.lastIndexOf(`
|
|
7
|
-
`),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#Re=i:this.#ze=i,r===-1)return;let a=stripAnsi(n.slice(0,r)).replace(/\s+$/u,``);a.trim().length!==0&&(this.#f?.append({source:e,detail:a}),e===`stdout`?this.#
|
|
4
|
+
`),n=stripPromptControlCharacters(e?.initialDraft??this.#te.text),r=t===void 0?n:n.length===0?t:`${t}\n\n${n}`,i=lineOf(r);return this.#te=EMPTY_LINE,this.#U.begin(i.text),this.#ht(i),this.#ft(i.text),this.#cn(),this.#zn(),await new Promise((e,t)=>{this.#ie=t;let apply=e=>{i=e,this.#un(),this.#ht(i),this.#ft(e.text),this.#zn()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#K=void 0,this.#ln(),this.#Zt(),t(interruptedError())},suggestions=()=>this.#K!==void 0&&isTypeaheadOpen(this.#K)?this.#K:void 0,argumentSuggestions=()=>this.#q?.suggestions.length?this.#q:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#Ce=t=>{t.type!==`ctrl-c`&&this.#pe&&(this.#pe=!1,this.#zn());let n=this.#W.apply(i,t,{multiline:!0});if(n!==void 0){apply(n);return}switch(t.type){case`up`:case`ctrl-p`:{let e=argumentSuggestions();if(e!==void 0){this.#q=moveArgumentTypeaheadSelection(e,-1),this.#zn();break}let t=suggestions();if(t!==void 0){this.#K=moveTypeaheadSelection(t,-1),this.#zn();break}let n=movePromptLine(i,`up`);n===void 0?recall(this.#U.previous(i.text)):apply(n);break}case`down`:case`ctrl-n`:{let e=argumentSuggestions();if(e!==void 0){this.#q=moveArgumentTypeaheadSelection(e,1),this.#zn();break}let t=suggestions();if(t!==void 0){this.#K=moveTypeaheadSelection(t,1),this.#zn();break}let n=movePromptLine(i,`down`);n===void 0?recall(this.#U.next()):apply(n);break}case`tab`:{let e=argumentSuggestions(),t=e===void 0?void 0:selectedArgumentSuggestion(e);if(e!==void 0&&t!==void 0){apply(lineOf(argumentTypeaheadCompletion(e,t)));break}let n=highlighted();n!==void 0&&apply(lineOf(typeaheadCompletion(n)));break}case`escape`:{if(this.#q!==void 0){this.#q=void 0,this.#zn();break}let e=suggestions();e!==void 0&&(this.#K=dismissTypeahead(e),this.#zn());break}case`enter`:{let t=argumentSuggestions(),n=t===void 0?void 0:selectedArgumentSuggestion(t),r=highlighted();if(t!==void 0&&n?.next!==void 0&&t.completed.length===0){apply(lineOf(`${argumentTypeaheadCompletion(t,n)} `));break}if(t===void 0&&r!==void 0&&this.#J!==void 0&&(r.name===`add`||r.name===`login`||r.name===`loglevel`||r.name===`model`)){apply(lineOf(typeaheadCompletion(r)));break}let a=t!==void 0&&n!==void 0?argumentTypeaheadCompletion(t,n):r!==void 0&&parsePromptCommand(i.text)===null?typeaheadCompletion(r).trimEnd():i.text;if(a.trim().length===0)break;this.#K=void 0,this.#q=void 0,promptCommandSpec(a)?.spec.history!==`omit`&&this.#U.add(a),this.#G=!1,this.#ln(),this.#ae=STATUS.processing,isPromptControlCommand(a)?this.#St(stripTerminalControls(a.trim())):(this.#fn(),this.#vn(a),this.#Ke=a,this.#$.arm()),this.#ht(EMPTY_LINE),this.#zn(),this.#$t(),e(a);break}case`ctrl-d`:i.text.length===0?(this.#Gt(),interrupt()):apply(deleteForward(i));break;case`ctrl-l`:this.#Hn();break;case`ctrl-r`:this.#zn();break;case`ctrl-c`:if(this.#pe){this.#Gt(),interrupt();break}this.#pe=!0,apply(EMPTY_LINE)}},this.#Qt()})}#ht(e){this.#V=e.text,this.#H=e.cursor}takeQueuedPrompt(){let e=this.#et.view().steering,t=this.#et.takePrompt();return t!==void 0&&(this.#at=e?`steer`:`queue`),t}async renderStream(e,t){this.#Yt(t),this.#v.clear(),this.#G=!1,this.#re.kind!==`waiting`&&(this.#re={kind:`waiting`,startedAtMs:Date.now()}),this.#ae=this.#R>0?STATUS.connectionAuth:STATUS.processing,this.#bn(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#f?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#$.armed&&this.#$.arm(),this.#de=!1,this.#rt=!1,this.#ot=!1,this.#st=t?.submittedPrompt,this.#et.beginTurn(),this.#tt=e.cancel,this.#nt=e.steer,this.#je=void 0,this.#Me=void 0,this.#Pe=void 0,this.#Fe=void 0,this.#Ie=Date.now();let n={text:new Map,reasoning:new Map,tools:new Map,modelActivity:`Thinking`,runningTools:new Set,cancelled:!1,restoreCancelledPrompt:!0};this.#ee=n;let r={tools:t?.tools??this.#o,reasoning:t?.reasoning??this.#s,assistantResponseStats:t?.assistantResponseStats??this.#u};this.#dn(),this.#ne=!0,this.#zn();let i=new Promise(e=>{this.#Oe=e});this.#Ce=e=>this.#on(e),this.#Qt();try{for await(let t of takeUntil(iterateTUIStream(e.events),i)){if(this.#de)break;this.#On(t,r,n)}}catch(e){let t=summarizeKnownError(e);t===null?this.#xn(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#xn(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#Oe=void 0,this.#de&&e.abort?.(),this.#tt=void 0,this.#nt=void 0,this.#$t(),this.#ne=!1,this.#ee=void 0,this.#re.kind===`waiting`&&(this.#re={kind:`idle`}),this.#gn(),this.#ae=completedTurnStatus({interrupted:this.#de,cancelled:this.#rt,continueSession:t?.continueSession===!0}),this.#Fn(n),(this.#de||n.cancelled)&&this.#Pn(n),this.#Dn(),this.#gn(),this.#f?.reportStats(),this.#zn(),t?.continueSession||this.#Zt()}}async renderIdleStream(e,t){let n={tools:t?.tools??this.#o,reasoning:t?.reasoning??this.#s,assistantResponseStats:t?.assistantResponseStats??this.#u},r={text:new Map,reasoning:new Map,tools:new Map,modelActivity:`Thinking`,runningTools:new Set,cancelled:!1,restoreCancelledPrompt:!1};try{for await(let t of iterateTUIStream(e.events))this.#On(t,n,r)}catch(e){let t=summarizeKnownError(e);t===null?this.#xn(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#xn(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#Fn(r),r.cancelled&&this.#Pn(r),this.#Dn(),this.#gn(),this.#f?.reportStats(),this.#zn()}}async readToolApproval(e,t){this.#Yt(t),this.#pn(),this.#G=!1,this.#re={kind:`idle`},this.#de=!1;let n=0;return this.#qe=t=>renderTransientDrawer([` ${this.#i.colors.bold(`Approve ${formatToolApprovalTitle(e)}?`)}`,``,...renderQuestionChoices([{id:`yes`,label:`Yes`},{id:`no`,label:`No`}],n,this.#i)],[`y yes · n no · Ctrl-C cancel`],this.#i,t),this.#zn(),await new Promise((t,r)=>{let approve=()=>{this.#qe=void 0,this.#fn(),this.#ae=STATUS.processing,this.#$t(),this.#zn(),t({approved:!0})},deny=()=>{this.#qe=void 0,this.#fn(),this.#ae=STATUS.processing,this.#_t(e.toolCallId),this.#$t(),this.#zn(),t({approved:!1,reason:`Denied by user.`})};this.#ie=r,this.#Ce=e=>{switch(e.type){case`text`:{if(e.framing!==`unframed`)break;let t=e.value.toLowerCase();t===`y`?approve():t===`n`&&deny();break}case`up`:case`ctrl-p`:n=0,this.#zn();break;case`down`:case`ctrl-n`:n=1,this.#zn();break;case`enter`:n===0?approve():deny();break;case`ctrl-r`:this.#zn();break;case`ctrl-c`:this.#de=!0,this.#qe=void 0,this.#Zt(),r(interruptedError())}},this.#Qt()})}async readInputQuestion(e,t){this.#Yt(t),this.#pn(),this.#G=!1,this.#Z=!1,this.#re={kind:`idle`},this.#de=!1;let n=e.options??[],r=n.length>0,i=(e.allowFreeform===!0||!r)&&r,a=n.length+ +!!i,o=questionSectionId(e.requestId),s=r?`select`:`text`,c=0,l=EMPTY_LINE,isOnFreeformRow=()=>i&&c===n.length,selectDrawer=t=>renderTransientDrawer(renderQuestionPanel({prompt:stripTerminalControls(e.prompt),options:n,cursor:c,allowFreeform:i,editor:l,caretVisible:this.#ge},this.#i,t),[`↑/↓ move · enter to select · esc to dismiss`],this.#i,t),textPanel=t=>{let n=promptInputRows({text:l.text,cursor:l.cursor,width:Math.max(1,t-2),theme:this.#i,caretVisible:this.#ge,ghost:``,maxRows:3});return n.at(-1)===``&&n.pop(),renderTransientDrawer([` ${this.#i.colors.bold(stripTerminalControls(e.prompt))}`,``,...n.map(e=>` ${e}`)],[`Enter submit · Esc dismiss`],this.#i,t)},syncFreeformCaret=()=>{isOnFreeformRow()?this.#cn():(this.#ln(),this.#un())};s===`select`?(s=`select`,this.#G=!1,this.#Tn(o),this.#qe=selectDrawer,this.#ae=``,syncFreeformCaret(),this.#zn()):(s=`text`,this.#qe=textPanel,this.#G=!0,this.#ht(l),this.#ae=``,this.#cn(),this.#zn());let finalize=t=>{this.#qe=void 0,this.#Cn({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#G=!1,this.#fn(),this.#ae=STATUS.processing,this.#ln(),this.#$t(),this.#zn();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#qe=void 0,this.#Cn({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${this.#i.colors.dim(`Skipped. The question stays open.`)}`,preformatted:!0,live:!1}),this.#G=!1,this.#ae=``,this.#ln(),this.#$t(),this.#zn(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#zn())},selectOptionAt=e=>{let t=n[e];t&&u(finalize({optionId:t.id,label:t.label}))},u;return await new Promise((t,n)=>{this.#ie=n,u=t,this.#Ce=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#un(),s===`text`&&this.#ht(l),this.#zn();return}this.#de=!0,this.#qe=void 0,this.#ln(),this.#Zt(),n(interruptedError());return}if(t.type===`ctrl-r`){this.#zn();return}if(s===`select`){let n=setupSelectionIntent(t,{textNavigation:!isOnFreeformRow()});if(n?.kind===`move`){moveCursor(n.direction===`up`?-1:1);return}switch(t.type){case`up`:case`ctrl-p`:moveCursor(-1);break;case`down`:case`ctrl-n`:moveCursor(1);break;case`enter`:if(isOnFreeformRow()){let t=resolveQuestionText(l.text,e);t!==void 0&&u(finalize(t));break}selectOptionAt(c);break;case`escape`:if(isOnFreeformRow()&&l.text.length>0){l=EMPTY_LINE,this.#un(),this.#zn();break}dismiss();break;default:if(isOnFreeformRow()){let e=this.#W.apply(l,t);e!==void 0&&(l=e,this.#un(),this.#zn())}}return}let r=this.#W.apply(l,t,{multiline:!0});if(r!==void 0){l=r,this.#un(),this.#ht(l),this.#zn();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#un(),this.#ht(l),this.#zn());break}case`enter`:{let t=resolveQuestionText(l.text,e);if(t===void 0)break;u(finalize(t));break}case`escape`:if(l.text.length>0){l=EMPTY_LINE,this.#un(),this.#ht(l),this.#zn();break}dismiss()}},this.#Qt()})}upsertSubagentStep(e){if(this.#f?.recordSubagentDispatch(e.callId),this.#c===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(t.length!==0||n.length!==0){if(this.#Sn(e.callId,e.subagentName),this.#c===`collapsed`){this.#zn();return}this.#wn({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,subagentCallId:e.callId,depth:1,reasoning:t,body:n,collapsed:this.#c!==`full`,live:!e.finalized}),this.#zn()}}upsertSubagentTool(e){if(this.#f?.recordSubagentDispatch(e.callId),e.status===`failed`&&e.errorText!==void 0&&this.#f?.append({source:`tool`,summary:`${e.toolName} failed (subagent ${e.subagentName})`,detail:e.errorText}),this.#c===`hidden`)return;if(this.#Sn(e.callId,e.subagentName),this.#c===`collapsed`){this.#zn();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#Mn({input:e.input,output:e.output,toolCallId:e.childCallId,toolName:e.toolName})),r={id:subagentToolSectionId(e.callId,e.childCallId),kind:`subagent-tool`,subagentCallId:e.callId,depth:1,title:stripTerminalControls(n.title),subtitle:stripTerminalControls(n.subtitle),status:t,live:t===`running`||t===`approval`,expanded:this.#c===`full`,toolName:e.toolName,toolGroup:n.group,toolInput:e.input};n.doneTitle!==void 0&&(r.doneTitle=stripTerminalControls(n.doneTitle)),n.detail!==void 0&&(r.detailLines=n.detail,r.keepDetailWhenDone=n.keepDetailWhenDone===!0),e.output===void 0?e.errorText!==void 0&&(r.result=stripTerminalControls(e.errorText)):(r.result=n.summarizeResult(e.output),r.toolOutput=e.output),this.#wn(r),this.#gt(e.callId),this.#zn()}#gt(e){applyCohortLiveness(this.#h.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#Tn(subagentToolSectionId(e.callId,e.childCallId)),this.#zn()}subagents={begin:e=>this.beginSubagent(e),background:e=>this.backgroundSubagent(e),upsertStep:e=>this.upsertSubagentStep(e),upsertTool:e=>this.upsertSubagentTool(e),removeTool:e=>this.removeSubagentTool(e),complete:e=>this.completeSubagent(e),markChildToolCallId:e=>this.markChildToolCallId(e)};beginSubagent(e){if(this.#c===`hidden`)return;this.#Sn(e.callId,e.name);let t=this.#g.get(subagentHeaderId(e.callId));t!==void 0&&(t.status===`done`&&delete t.status,t.live=!0),this.#T.delete(e.callId),this.#zn()}backgroundSubagent(e){let t=this.#g.get(subagentHeaderId(e.callId));if(t===void 0||this.#v.has(subagentHeaderId(e.callId)))return;t.status=`running`,t.live=!0,t.updateSeq=++this.#S;let n=this.#w.has(e.callId);this.#w.add(e.callId),n||this.#En(e.callId),this.#gn(),this.#zn()}completeSubagent(e){let t=this.#g.get(subagentHeaderId(e.callId));if(t!==void 0){if(t.status=`done`,e.authoritative){this.#w.delete(e.callId),this.#T.delete(e.callId);for(let t of this.#h)t.subagentCallId===e.callId&&(t.live=!1)}else{this.#T.add(e.callId);for(let t of this.#h)t.subagentCallId===e.callId&&(t.live=!0)}this.#gn(),this.#zn()}}markChildToolCallId(e){this.#b.add(e);let t=this.#x.get(e);t!==void 0&&(this.#Tn(t),this.#x.delete(e),this.#zn())}#_t(e){let t=this.#g.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#l===`hidden`)return;let t=connectionAuthTerminalMessage(e.state);this.#Cn({id:connectionAuthSectionId(e.name),kind:`connection-auth`,title:`${stripTerminalControls(e.name)} · authorization · ${e.state}`,body:formatConnectionAuthContent(e,t),preformatted:!0,live:t===void 0}),this.#zn()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#R)return;let n=this.#R>0;this.#R=t,t>0?(this.#ae=STATUS.connectionAuth,this.#zn()):n&&(this.#ae=STATUS.processing,this.#zn())}setVercelStatus(e){this.#z=e,this.#zn()}setRemoteConnectionStatus(e){this.#B=e,this.#zn()}reset(){this.#h=[],this.#g.clear(),this.#v.clear(),this.#L=void 0,this.#I.length=0,this.#y.length=0,this.#P=!1,this.#F=void 0,this.#vt(),this.#Q=!1,this.#Ke=void 0,this.#Ve=void 0,this.#R=0,this.#je=void 0,this.#Me=void 0,this.#Pe=void 0,this.#Fe=void 0,this.#Ie=void 0,this.#ce&&(this.#n.clearAll(),this.#zn())}renderSessionBoundary(){this.#yn(),this.#vt();let e=this.#i.colors,t=this.#i.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#_n({kind:`session-boundary`,body:n,live:!1}),this.#zn()}#vt(){this.#Qe=void 0,this.#$e=void 0,this.#b.clear(),this.#x.clear(),this.#D.clear(),this.#w.clear(),this.#T.clear(),this.#C.clear(),this.#et.reset(),this.#at=void 0,this.#E.clear(),this.#$.reset(),this.#gn()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#Yt(),this.#_n({kind:`notice`,body:t,live:!1}),this.#zn())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#yt();return}this.#Yt(),this.#Ze=t,this.#zn()}clearSetupWarning(){this.#yt()}#yt(){this.#Ze!==void 0&&(this.#Ze=void 0,this.#zn())}renderCommandInvocation(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#Yt(),this.#St(t),this.#zn())}async choosePromptCommand(e){this.#Yt(),this.#G=!1;let t=typeaheadFor(e,`/`);return this.#Je=e=>{let n=renderCommandSuggestions(t,this.#i,e),r=Math.max(1,this.#ir()-7),i=Math.max(0,Math.min(t.selectedIndex-r+1,n.length-r));return renderTransientDrawer(n.slice(i,i+r),[`↑/↓ move · Enter select · Esc close`],this.#i,e)},this.#ae=``,this.#zn(),await new Promise(e=>{this.#Ye=()=>e(void 0),this.#Ce=n=>{if(n.type===`up`||n.type===`ctrl-p`)t=moveTypeaheadSelection(t,-1),this.#zn();else if(n.type===`down`||n.type===`ctrl-n`)t=moveTypeaheadSelection(t,1),this.#zn();else if(n.type===`enter`){let n=selectedTypeaheadCommand(t);this.#bt(),e(n===void 0?void 0:typeaheadCompletion(n))}else(n.type===`escape`||n.type===`ctrl-c`)&&(this.#bt(),e(void 0))},this.#Qt()})}async showInfoPanel(e){this.#Yt(),this.#G=!1;let t=stripAnsi(e),n=0,infoRows=e=>t.split(`
|
|
5
|
+
`).flatMap(t=>wrapVisibleLine(t,Math.max(1,e-4)).map(e=>` ${e}`));this.#Je=e=>{let t=infoRows(e),r=Math.max(1,this.#ir()-7);return n=Math.min(n,Math.max(0,t.length-r)),renderTransientDrawer(t.slice(n,n+r),[t.length>r?`↑/↓ scroll · Esc close`:`Esc to close`],this.#i,e)},this.#ae=``,this.#zn(),await new Promise(e=>{this.#Ye=e,this.#Ce=t=>{if(t.type===`up`||t.type===`ctrl-p`)n=Math.max(0,n-1),this.#zn();else if(t.type===`down`||t.type===`ctrl-n`){let e=Math.max(1,this.#ir()-7);n=Math.min(n+1,Math.max(0,infoRows(this.#rr()).length-e)),this.#zn()}else(t.type===`escape`||t.type===`ctrl-c`||t.type===`enter`)&&(this.#bt(),e())},this.#Qt()})}#bt(){this.#Je=void 0,this.finishCommand({kind:`dismiss`}),this.#Ce=void 0,this.#Ye=void 0,this.#$t(),this.#zn()}finishCommand(e){if(e.kind===`dismiss`){this.#xt()&&this.#zn();return}let t=this.#Ct(e.summary);t!==void 0&&(t.status=`done`);let n=e.message===void 0?``:stripAnsi(e.message);if(n.trim().length===0){t!==void 0&&this.#zn();return}this.#Yt(),this.#_n({kind:`result`,body:n,live:!1}),this.#zn()}#xt(){let e=this.#_;return e!==void 0&&(this.#_=void 0,this.#h=this.#h.filter(t=>t!==e),!0)}#St(e){this.#_!==void 0&&this.#Ct();let t={kind:`command`,body:e,live:!0};this.#_=t,this.#_n(t)}#Ct(e){let t=this.#_;if(t!==void 0)return this.#_=void 0,t.live=!1,e!==void 0&&(t.result=stripTerminalControls(e)),t}#wt(e){this.#Yt(),this.#A===void 0&&(this.#G=!1),this.#re={kind:`idle`},this.#ae=``,this.#Xe={title:stripTerminalControls(e),startedAtMs:Date.now(),lines:[],outputBuffer:[]},this.#dn(),this.#zn()}#Tt(e){this.#Xe!==void 0&&(this.#Xe.navigation=e,this.#zn())}#Et(e){this.#ct=void 0,this.#zt();let t=this.#Xe;if(t!==void 0){if(this.#Xe=void 0,this.#A===void 0?this.#pn():this.#mt(),e){let e=[];for(let n of t.lines){if(n.evidence===!0){e.push(n.text);continue}(n.tone===`warning`||n.tone===`error`)&&(e.length>0&&this.#_n({kind:`flow`,title:`info`,body:e.join(`
|
|
6
|
+
`),live:!1}),this.#_n({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#zn()}}async#Dt(e){let t=this.#Nt(e.message),n=isMultiSelectRequest(e),r=e.kind===`search`?e.searchAction:void 0,i=e.kind===`search`&&e.layout===void 0,a=e.options,o=e.navigation?.kind===`planner`,s={options:a,searchAction:r,submitRow:n&&!o};`initialValue`in e&&e.initialValue!==void 0&&(s.defaultValue=e.initialValue),`initialValues`in e&&e.initialValues!==void 0&&(s.initialValues=e.initialValues);let c=initialSelectState(s),l,u=!1,d=0,isCurrentSearch=e=>e===d,clearSearch=()=>{d+=1,u=!1,c=reduceSelect(c,{type:`clear`},{options:a,searchAction:r,submitRow:n&&!o}),this.#zn()},loadSearch=async(e,t)=>{u=!0,l=void 0;let i=++d;this.#zn();try{let s=await t(e);if(!isCurrentSearch(i))return;let l=c.filter;a=s,c={...initialSelectState({options:s,searchAction:r,submitRow:n&&!o}),filter:l}}catch(e){isCurrentSearch(i)&&(l=toErrorMessage(e))}finally{isCurrentSearch(i)&&(u=!1,this.#zn())}},f=e.notices;if(e.kind===`task-list`||e.kind===`search`&&e.layout===`task-list`){let n=t.taskListLineStart??t.lines.length,r=t.lines.slice(n).filter(e=>e.tone===`success`||e.tone===`warning`||e.tone===`error`).map(e=>({tone:e.tone,text:e.text}));f=e.notices??r,t.taskListLineStart=t.lines.length,t.hideLinesWhileQuestion=!0}let panelState=()=>{let t={...e,message:``,options:a,select:c};return f!==void 0&&f.length>0&&(t.notices=f),l!==void 0&&(t.error=l),u&&(t.loadingFrame=this.#Kn()),i&&(t.caretVisible=this.#ge),t};return t.question=e=>renderSelectQuestion(panelState(),this.#i,e),i&&this.#cn(),this.#zn(),await this.#It((t,s)=>{let close=e=>{d+=1,s(e)};if(u){t.type===`ctrl-c`?close(void 0):t.type===`escape`?clearSearch():t.type===`ctrl-r`&&this.#zn();return}let f=e.navigation?.kind===`planner`?e.navigation:void 0,p=t.type===`left`&&(f?.activeStep??0)>(f?.firstNavigableStep??0)?`back`:t.type===`right`&&f!==void 0&&f.activeStep>=(f.firstNavigableStep??0)&&f.activeStep<f.steps.length-1?`forward`:void 0;if(p!==void 0){close({kind:`navigate`,direction:p,values:n?orderedSelection(a,c.selected):[]});return}let m={key:t,options:a,searchAction:r,select:c},h=reduceSetupSelectInput(n?{...m,kind:e.kind,required:e.required,plannerNavigation:o||void 0}:{...m,kind:e.kind});switch(h.kind){case`cancel`:close(void 0);return;case`repaint`:this.#zn();return;case`update`:c=h.select,l=void 0,i&&this.#un(),this.#zn();return;case`submit`:{let e=searchActionQuery(h.values[0]??``),t=r?.load;if(e===void 0||t===void 0){close(h.values);return}loadSearch(e,t);return}case`error`:l=h.message,this.#zn();return;case`ignore`:return}},i?()=>this.#ln():void 0).promise}#Ot(e){this.#Yt();let t=this.#Pt();t.status={text:stripTerminalControls(e.status),startedAtMs:Date.now()};let n;t.question=t=>renderSelectQuestion({kind:`actions`,context:e.context,actions:e.actions,cursor:n},this.#i,t),this.#zn();let r=this.#It((t,r)=>{let i=setupSelectionIntent(t,{textNavigation:!0});switch(i?.kind){case`cancel`:r(void 0);return;case`move`:n=moveActionCursor(n,i.direction,e.actions.length),this.#zn();return;case`repaint`:this.#zn();return;case`submit`:n!==void 0&&r(e.actions[n].value);return;case void 0:return}},()=>{t.status=void 0});return{choice:r.promise,close:()=>r.settle(void 0)}}async#kt(e){let t=this.#Nt(e.message),n={options:e.options};e.initialValue!==void 0&&(n.defaultValue=e.initialValue);let r=initialSelectState(n),i=lineOf(``),a;t.question=t=>{let n={kind:`inline-edit`,layout:`task-list`,message:``,options:e.options,select:r,edit:{optionValue:e.editable.value,caretVisible:this.#ge,editor:{kind:`rename`,editor:i,defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint}}};return a!==void 0&&(n.error=a),renderSelectQuestion(n,this.#i,t)};let onEditableRow=()=>selectValueAtCursor([...e.options],r.cursor)===e.editable.value,syncEditableRow=()=>{onEditableRow()?this.#cn():(i=lineOf(``),this.#ln())};return syncEditableRow(),this.#zn(),await this.#It((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#un(),this.#zn()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#zn()},submit=()=>{let t=selectValueAtCursor([...e.options],r.cursor);if(t===void 0)return;if(t!==e.editable.value){n({kind:`selected`,value:t});return}let o=(i.text||e.editable.defaultValue).trim(),s=e.editable.validate?.(o);if(s!==void 0){a=s,this.#zn();return}n(o===e.editable.defaultValue?{kind:`selected`,value:t}:{kind:`edited`,value:t,text:o})},o=setupSelectionIntent(t,{textNavigation:!onEditableRow()});switch(o?.kind){case`cancel`:n(void 0);return;case`move`:applySelect({type:o.direction});return;case`submit`:submit();return;case`repaint`:this.#zn();return;case void 0:}if(!onEditableRow())return;let s=this.#W.apply(i,t);s!==void 0&&applyEditor(s)},()=>this.#ln()).promise}async#At(e){this.#W.clear();let t=this.#Nt(e.message),n=initialProviderPickerState(e.options,e.initialValue),r,cursorBadge=()=>{if(n.phase.kind!==`inactive`)return;let t=selectValueAtCursor([...e.options],n.select.cursor),r=e.options.find(e=>e.value===t);if(r!==void 0)return enterBadge(this.#i,r.checked===!0?`change`:void 0)};t.question=t=>{let r=cursorBadge(),i={kind:`inline-edit`,layout:`stacked`,message:``,options:e.options,select:n.select,edit:{optionValue:`ai-gateway-key`,caretVisible:this.#ge,editor:{kind:`key`,phase:n.phase}}};return r!==void 0&&(i.cursorBadge=r),renderSelectQuestion(i,this.#i,t)};let syncCaret=()=>{n.phase.kind===`editing`||n.phase.kind===`invalid`?this.#cn():this.#ln()};return syncCaret(),this.#zn(),await this.#It((t,i,a)=>{let dispatch=t=>{let o=transitionProviderPicker(n,t,e.options);switch(o.kind){case`ignore`:return;case`clear`:r?.abort(),r=void 0,n=o.state,syncCaret(),this.#zn();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#zn();return;case`validate`:{n=o.state,syncCaret(),this.#zn();let t=new AbortController;r=t;let i;try{i=e.validateInlineKey(o.key,t.signal)}catch(e){a(e);return}i.then(e=>{r!==t||t.signal.aborted||(r=void 0,dispatch({type:`validated`,validation:e}))},e=>{r!==t||t.signal.aborted||(r=void 0,a(e))});return}case`settle`:i(o.result);return}},o=setupSelectionIntent(t,{textNavigation:n.phase.kind===`inactive`});switch(o?.kind){case`cancel`:dispatch({type:`cancel`});return;case`move`:dispatch({type:`move`,direction:o.direction});return;case`submit`:dispatch({type:`submit`});return;case`repaint`:this.#zn();return;case void 0:}if(n.phase.kind!==`editing`&&n.phase.kind!==`invalid`)return;let s=applyLineEditorKey(n.phase.editor,t);s!==void 0&&(this.#un(),dispatch({type:`edit`,editor:s}))},()=>{r?.abort(),r=void 0,this.#ln()}).promise}async#jt(e){e.mask===!0&&this.#W.clear();let t=this.#Nt(e.message),n=lineOf(``),r;return t.question=t=>{let i={message:``,editor:n,mask:e.mask===!0};return e.placeholder===void 0?e.defaultValue!==void 0&&(i.placeholder=e.defaultValue):i.placeholder=e.placeholder,e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#i,t,this.#ge)},this.#cn(),this.#zn(),await this.#It((t,i)=>{let apply=e=>{n=e,r=void 0,this.#un(),this.#zn()},a=e.mask?applyLineEditorKey(n,t):this.#W.apply(n,t);if(a!==void 0){apply(a);return}switch(t.type){case`ctrl-c`:case`escape`:i(void 0);return;case`ctrl-r`:this.#zn();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#zn();return}i(t);return}default:return}},()=>this.#ln()).promise}async#Mt(e){let t=this.#Nt(e.message);return t.question=t=>renderAcknowledgeQuestion({message:``,lines:e.lines},this.#i,t),this.#zn(),await this.#It((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#zn();return;default:return}}).promise}#Nt(e){this.#Yt(),this.#G=!1,this.#re={kind:`idle`},this.#ae=``;let t=this.#Pt();return t.questionTitle=stripTerminalControls(e),t.status!==void 0&&(t.status=void 0,t.summary=void 0,t.preview=void 0),t}#Pt(){return this.#Xe===void 0&&(this.#Xe={title:``,startedAtMs:Date.now(),lines:[],outputBuffer:[],implicit:!0}),this.#Xe}#Ft(){this.#Xe?.implicit===!0?this.#Xe=void 0:this.#Xe!==void 0&&(this.#Xe.question=void 0,this.#Xe.questionTitle=void 0,this.#Xe.hideLinesWhileQuestion=!1),this.#Ce=void 0,this.#$t(),this.#A===void 0?this.#Xe!==void 0&&this.#Rt():this.#mt(),this.#Xe===void 0&&this.#zn()}#It(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#Ft(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#Ft(),i(e))};return this.#an(),this.#Ce=t=>{t.type===`ctrl-c`&&this.#Gt(),e(t,settle,reject)},this.#Qt(),{promise:a,settle}}#Lt(e){let t,n=new Promise(e=>{t=e});return this.#ct=t,this.#Rt(e?.interruptible??!0),{promise:n,dispose:()=>{this.#ct===t&&(this.#ct=void 0,this.#zt())}}}#Rt(e=!0){if(this.#A!==void 0){this.#mt();return}if(this.#ct===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#Gt();let e=this.#ct;this.#ct=void 0,this.#zt(),e?.(t.type===`ctrl-c`?`ctrl-c`:`escape`);return}t.type===`ctrl-r`&&this.#zn()};this.#lt=consumer,this.#an(),this.#Ce=consumer,this.#Qt()}#zt(){this.#lt!==void 0&&(this.#Ce===this.#lt&&this.#$t(),this.#lt=void 0)}#Bt(e){let t=e===void 0?void 0:{text:stripTerminalControls(e),startedAtMs:Date.now()};if(this.#Xe!==void 0){this.#Xe.status=t,t===void 0&&(this.#Xe.preview=void 0),this.#zn();return}if(!(this.#G||this.#ne)){if(t===void 0){this.#re={kind:`idle`},this.#oe=void 0,this.#pn(),this.#zn();return}this.#Yt(),this.#fn(),this.#oe=t.text,this.#zn()}}#Vt(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#Xe;if(r!==void 0){if(r.preview=void 0,t===`warning`||t===`error`)for(let e of r.outputBuffer)r.lines.push({text:e,tone:`info`,evidence:!0});r.outputBuffer=[],r.lines.push({text:n,tone:t}),this.#zn();return}this.#Yt(),this.#_n({kind:`flow`,title:t,body:n,live:!1}),this.#zn()}#Ht(e){let t=this.#Xe;t!==void 0&&(t.lines=[],t.outputBuffer=[],t.preview=void 0,t.status=void 0,t.summary=e===void 0?void 0:{headline:stripTerminalControls(e.headline),facts:e.facts.map(e=>({label:stripTerminalControls(e.label),value:stripTerminalControls(e.value)}))},this.#zn())}#Ut(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#Xe;if(n===void 0){this.#Vt(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#zn()}async#Wt(e){this.#we=``,this.#an(),this.#ct=void 0,this.#zt(),this.#$t(),this.#mn(),this.#n.clear(),this.#or(),this.#r.enter({cursor:`visible`,mouse:!1}),this.#e.isTTY&&this.#e.setRawMode?.(!1),this.#e.pause();try{return await e()}finally{this.#r.exit(),this.#e.isTTY&&this.#e.setRawMode?.(!0),this.#e.resume(),this.#we=``,this.#an(),this.#n.hideCursor(),this.#ar(),this.#Xe===void 0?this.#gn():(this.#dn(),this.#Rt()),this.#n.reset(),this.#zn()}}setSessionId(e){this.#it=e}shutdown(){this.#Zt();for(let e of this.#X.values())clearTimeout(e);if(this.#X.clear(),this.#le&&!this.#ue){this.#ue=!0;let e=this.#it===void 0?``:` ${this.#i.glyph.dot} session ${this.#it}`;this.#t.write(`${this.#i.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}suspendPromptForInput(){this.#te={cursor:this.#H,text:this.#V},this.#Zt()}requestInterrupt(){this.#de=!0,this.#Xe!==void 0&&this.#Ce?.({type:`ctrl-c`}),this.#Oe?.(),this.#Zt()}exitRequested(){return this.#fe}#Gt(){this.#fe=!0,this.#he?.()}async#Kt(e){if(this.#ut!==void 0||!this.#ce)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#rr(),height:this.#ir()}),paint:e=>this.#r.paint(e,this.#ir()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e)),terminalBackground:this.#dt});this.#ut=t,this.#r.enter(),this.#i.color&&this.#r.writeRaw(BACKGROUND_COLOR_QUERY),await new Promise(e=>{this.#Jt=e,this.#Ce=e=>{t.handleKey(e)===`close`&&this.#qt()},this.#Qt(),t.start()})}#qt(){let e=this.#ut;if(e===void 0)return;this.#ut=void 0,e.dispose(),this.#$t(),this.#r.exit(),this.#n.hideCursor(),this.#zn(),this.#n.showCursor();let t=this.#Jt;this.#Jt=void 0,t?.()}#Jt;#Yt(e){this.#se=e?.title??this.#se,e?.contextSize!==void 0&&(this.#Ne=e.contextSize),!this.#ce&&(this.#ce=!0,this.#le=!0,this.#n.reset(),this.#n.hideCursor(),this.#ar(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#De=()=>this.#zn(),this.#t.on(`resize`,this.#De),process.on(`exit`,this.#Xt))}#Xt=()=>{this.#ce&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#Zt(){this.#qe=void 0;let e=this.#Ye;e!==void 0&&(this.#Ye=void 0,this.#Je=void 0,this.finishCommand({kind:`dismiss`}),this.#Ce=void 0,e()),this.#qt();let t=this.#ie;if(this.#ie=void 0,t?.(interruptedError()),this.#$t(),this.#ln(),this.#mn(),this.#xe!==void 0&&(clearTimeout(this.#xe),this.#xe=void 0),this.#Se=!1,this.#mr(),this.#ce){this.#gr(),this.#Ct();for(let e of this.#h)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#zn(),this.#n.clear(),this.#n.showCursor(),this.#or(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#De&&=(this.#t.off(`resize`,this.#De),void 0),process.off(`exit`,this.#Xt),this.#ce=!1}}#Qt(){this.#e.off(`data`,this.#en),this.#e.on(`data`,this.#en),this.#we.length>0&&queueMicrotask(()=>{this.#Ce!==void 0&&this.#we.length>0&&(this.#rn(),this.#tn())})}#$t(){this.#e.off(`data`,this.#en),this.#an(),this.#Ce=void 0}#en=e=>{this.#an(),this.#we+=this.#Te.write(e),this.#rn(),this.#tn()};#tn(){if(this.#we===`\x1B`){this.#Ee=setTimeout(()=>{this.#we===`\x1B`&&(this.#we=``,this.#nn({type:`escape`}))},30),this.#Ee.unref?.();return}if(isIncompletePaste(this.#we)){let e=this.#we;this.#Ee=setTimeout(()=>{if(this.#we!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#we=``,t.length>0&&this.#nn({type:`text`,value:t,framing:`bracketed-paste`})},incompletePasteFlushMs),this.#Ee.unref?.();return}if(isIncompleteOsc(this.#we)){let e=this.#we;this.#Ee=setTimeout(()=>{this.#we===e&&(this.#we=``)},incompletePasteFlushMs),this.#Ee.unref?.()}}#nn(e){this.#W.interruptYank(e),this.#Ce?.(e)}#rn(){for(;this.#we.length>0;){let e=nextKey(this.#we);if(e.incomplete)return;if(this.#we=this.#we.slice(e.consumed),e.key!==void 0&&e.key.type!==`ignore`){if(e.key.type===`osc`){this.#in(e.key.value);continue}this.#nn(e.key)}}}#in(e){let t=parseBackgroundColorReply(e);t!==void 0&&(this.#dt=t,this.#ut?.setTerminalBackground(t))}#an(){this.#Ee&&=(clearTimeout(this.#Ee),void 0)}#on(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#zn();break;case`enter`:{let e=this.#te.text;if(e.trim().length===0)break;if(parsePromptCommand(e)?.type===`cancel`&&this.#tt!==void 0){this.#te=EMPTY_LINE,this.#et.requestCancellation(),this.#ot=!0,this.renderCommandInvocation(e.trim()),this.finishCommand({kind:`result`,summary:`Cancellation requested`}),this.#tt(),this.#zn();break}let t=this.#nt;t!==void 0&&parsePromptCommand(e)===null?(this.#te=EMPTY_LINE,this.#sn(e,t)):this.#et.enqueue(e)&&(this.#te=EMPTY_LINE),this.#zn();break}case`ctrl-c`:case`escape`:if(e.type===`ctrl-c`&&this.#et.view().cancelling){this.#de=!0,this.#me=!0,this.#re={kind:`idle`},this.#ae=`Interrupted`,this.#Oe?.(),this.#zn();break}if(this.#et.idle&&this.#tt===void 0)break;if(this.#et.handleEscape()===`steer`){let e=this.#nt;if(e!==void 0){let t=this.#et.takeSteering();this.#sn(t,e)}}else this.#ot=!0,this.#tt?.();this.#zn();break;default:{let t=this.#W.apply(this.#te,e,{multiline:!0});t!==void 0&&(this.#te=t,this.#zn());break}}}#sn(e,t){this.#at=`steer`,this.#bn(e),t(e).catch(t=>{this.#et.restoreSteering(e),this.#xn(`Steering failed`,toErrorMessage(t)),this.#zn()})}#cn(){this.#ln(),this.#un(),this.#ye=setInterval(()=>{this.#ge=!this.#ge,this.#zn()},500),this.#ye.unref?.()}#ln(){this.#ye&&=(clearInterval(this.#ye),void 0),this.#ge=!0}#un(){this.#ge=!0}#dn(){this.#mn(),this.#be=setInterval(()=>{this.#_e+=1,this.#zn()},90),this.#be.unref?.()}#fn(){let e=Date.now();this.#ve=e,this.#re={kind:`waiting`,startedAtMs:e},this.#dn()}#pn(){this.#hn()||this.#mn()}#mn(){this.#be&&=(clearInterval(this.#be),void 0)}#hn(){return this.#h.some(e=>e.live&&e.subagentCallId!==void 0&&(this.#w.has(e.subagentCallId)||this.#T.has(e.subagentCallId)))}#gn(){this.#hn()?this.#dn():!this.#ne&&this.#re.kind===`idle`&&this.#mn()}#_n(e){e.id!==this.#Ve?.id&&this.#gr(),e.updateSeq=++this.#S;let t=e.subagentCallId!==void 0&&this.#w.has(e.subagentCallId)?-1:this.#h.findIndex(e=>e.subagentCallId!==void 0&&this.#w.has(e.subagentCallId));t<0?this.#h.push(e):this.#h.splice(t,0,e),e.id&&this.#g.set(e.id,e)}#vn(e){this.#Q=!0,this.#_n({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#zn()}#yn(){let e=this.#$.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#Zn(e.elapsedMs)}`,n=this.#Me??0;if(this.#Ne!==void 0&&this.#Ne>0&&n>0){let e=Math.round(n/this.#Ne*100);t+=` ${this.#i.glyph.dot} ${e}% context`}this.#_n({kind:`turn-stats`,body:t,live:!1})}#bn(e){if(e==null)return;let t=this.#at;if(this.#at=void 0,this.#Ke===e){this.#Ke=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#_n(n)}#xn(e,t,n={}){let r=stripTerminalControls(e),i=stripTerminalControls(t),a=n.detail===void 0?void 0:stripTerminalControls(n.detail),o=n.hint===void 0?void 0:stripTerminalControls(n.hint),s={source:`workflow`,summary:`${r}: ${i}`,detail:a??i};this.#f?.append(o===void 0?s:{...s,hint:o});let c={kind:`error`,title:r,body:i,live:!1};o!==void 0&&(c.hint=o),a!==void 0&&(c.detail=this.#f===void 0?a:`details: ${this.#f.displayPath}`),this.#_n(c),this.#zn()}#Sn(e,t){if(this.#D.has(e))return;this.#D.add(e);let n=stripTerminalControls(t),r=this.#C.get(n)??[];if(r.push(e),this.#C.set(n,r),r.length===2){let e=this.#g.get(subagentHeaderId(r[0]));e!==void 0&&(e.subtitle=`#1`)}let i={id:subagentHeaderId(e),kind:`subagent`,subagentCallId:e,title:n,live:!0};r.length>1&&(i.subtitle=`#${r.length}`),this.#_n(i)}#Cn(e){if(e.id&&this.#v.has(e.id))return;let t=e.id?this.#g.get(e.id):void 0;if(t){Object.assign(t,e),t.updateSeq=++this.#S;return}this.#_n(e)}#wn(e){if(e.id&&this.#v.has(e.id))return;let t=e.id?this.#g.get(e.id):void 0;if(t!==void 0){Object.assign(t,e),t.updateSeq=++this.#S;return}let n=e.subagentCallId;if(n===void 0){this.#_n(e);return}e.id!==this.#Ve?.id&&this.#gr(),e.updateSeq=++this.#S;let r=-1;for(let e=0;e<this.#h.length;e+=1)this.#h[e]?.subagentCallId===n&&(r=e);this.#h.splice(r<0?this.#h.length:r+1,0,e),e.id!==void 0&&this.#g.set(e.id,e)}#Tn(e){this.#h=this.#h.filter(t=>t.id!==e),this.#g.delete(e)}#En(e){let t=this.#h.filter(t=>t.subagentCallId===e);t.length!==0&&(this.#h=this.#h.filter(t=>t.subagentCallId!==e),this.#h.push(...t))}#Dn(){for(let e of this.#h)e.subagentCallId!==void 0&&this.#T.has(e.subagentCallId)||e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||e===this.#_||(e.live=!1)}#On(e,t,n){let r=turnActivityLabel(n);switch(updateTurnActivity(n,e),e.type){case`turn-start`:e.turnId!==this.#$e&&(this.#$e=e.turnId,this.#Qe=void 0,this.#zn());break;case`step-start`:this.#Qe=typeof e.modelId==`string`&&stripTerminalControls(e.modelId.slice(0,256)).replace(/\s+/gu,` `).trim()||void 0,this.#zn();break;case`step-finish`:this.#f?.recordStepUsage(e.usage),e.usage!==void 0&&this.#$.addUsage(e.usage),this.#Fn(n),this.#Rn(e.usage),this.#zn();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#kn(e.id,t,!0);break}case`assistant-complete`:{let t=n.text.get(e.id)??``,r=typeof e.text==`string`?stripTerminalControls(e.text):t;n.text.set(e.id,r),this.#kn(e.id,r,!1);break}case`reasoning-delta`:{if(t.reasoning===`hidden`)break;let r=(n.reasoning.get(e.id)??``)+stripTerminalControls(e.delta);if(n.reasoning.set(e.id,r),t.reasoning===`full`){this.#An(e.id,r,!0,t);break}break}case`reasoning-complete`:{if(t.reasoning===`hidden`)break;let r=n.reasoning.get(e.id)??``;if(t.reasoning===`full`){this.#An(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#jn({input:void 0,preparing:!0,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-call`:if(this.#f?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#jn({input:e.input,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-approval-request`:{if(t.tools===`hidden`)break;let r=n.tools.get(e.toolCallId);if(r===void 0)break;this.#jn({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#Ln(e.toolCallId,n);if(r===void 0)break;this.#jn({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#Ln(e.toolCallId,n);if(this.#f?.append({source:`tool`,summary:`${r?.toolName??e.toolCallId} failed`,detail:e.errorText}),t.tools===`hidden`||r===void 0)break;this.#jn({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#Ln(e.toolCallId,n);if(r===void 0)break;this.#jn({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#xn(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:if(n.cancelled=!0,!n.restoreCancelledPrompt)break;this.#rt=!0,!this.#ot&&this.#st!==void 0&&this.#te.text.length===0&&(this.#te=lineOf(this.#st),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#Rn(e.usage),this.#zn()}n===this.#ee&&turnActivityLabel(n)!==r&&this.#zn()}#kn(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Cn({id:e,kind:`assistant`,body:r,live:n}),this.#zn())}#An(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Cn({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#zn())}#jn(e,t,n){if(n.tools.set(e.toolCallId,e),this.#b.has(e.toolCallId)||isPanelRoutedTool(e.toolName))return;let r=toolSectionId(e.toolCallId);this.#x.set(e.toolCallId,r);let i=this.#Mn(e);this.#Cn(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#In(n),this.#zn()}#Mn(e){e.output!==void 0&&this.#E.observeRead(e.output);let t={};this.#Nn(e.toolName)&&(t.isSubagent=!0);let n=readWriteFileInput(e.toolName,e.input);if(n===void 0)return t.isSubagent===!0?t:void 0;let r=this.#E.observeWrite({path:n.path,content:n.content,callId:e.toolCallId});r!==void 0&&(t.previousContent=r);let i=writeExistedFlag(e.output);return i!==void 0&&(t.existed=i),t}#Nn(e){let t=this.#O?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#Pn(e){for(let t of e.tools.keys()){if(this.#b.has(t))continue;let e=this.#x.get(t)??toolSectionId(t),n=this.#g.get(e);n?.kind===`tool`&&n.status===`running`&&(n.status=`error`,n.result=`interrupted`,n.live=!1)}}#Fn(e){for(let[t,n]of e.tools){if(n.preparing!==!0)continue;e.tools.delete(t);let r=this.#x.get(t)??toolSectionId(t);this.#Tn(r),this.#x.delete(t)}}#In(e){let t=[];for(let n of e.tools.values()){if(this.#b.has(n.toolCallId))continue;let e=this.#x.get(n.toolCallId)??toolSectionId(n.toolCallId),r=this.#g.get(e);r?.kind===`tool`&&t.push({block:r,active:isActiveToolStatus(n.status)})}applyCohortLiveness(t)}#Ln(e,t){let n=t.tools.get(e);if(n!==void 0)return n;let r=this.#x.get(e)??toolSectionId(e),i=this.#g.get(r);if(i!==void 0&&i.kind===`tool`)return{errorText:i.status===`error`&&typeof i.result==`string`?i.result:void 0,input:i.toolInput,output:i.toolOutput,status:i.status??`running`,toolCallId:e,toolName:i.toolName??i.title??`tool`}}#Rn(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#je=(t??0)+(n??0)),this.#Me=t??this.#Me,this.#Pe=n??this.#Pe,this.#Pe!=null&&this.#Ie!==void 0){let e=(Date.now()-this.#Ie)/1e3;e>0&&(this.#Fe=this.#Pe/e)}}#zn(){if(this.#ce){if(this.#ke){this.#Ae=!0;return}this.#ke=!0;try{do this.#Ae=!1,this.#Bn();while(this.#Ae)}finally{this.#ke=!1}}}#Bn(){if(!this.#ce)return;if(this.#ut!==void 0){this.#ut.repaint();return}let e=this.#rr(),t=this.#Yn(e),n=this.#N===void 0?[]:this.#Wn(),r=Math.max(1,this.#ir()-n.length-t.length),i=[],a=this.#L,o=groupToolBlocksForDisplay(this.#h),s=0;for(;s<o.length&&o[s].display.live===!1;)s+=1;if(s>0){let e=new Set(o.slice(0,s).flatMap(e=>e.members));for(let t=this.#h.length-1;t>=0;--t)e.has(this.#h[t])&&this.#h.splice(t,1)}for(let t of o.slice(0,s)){for(let e of t.members)this.#y.push(e),e.id&&(this.#v.add(e.id),this.#g.delete(e.id));if(this.#vr(t.display))continue;let n=this.#Gn(t.display,e,a);a=previousBlockOf(t.display),this.#L=a,i.push(...n),this.#I.push(...n)}let c=[];for(let{display:t}of o.slice(s)){if(this.#vr(t))continue;let n=this.#Gn(t,e,a);a=previousBlockOf(t);for(let e=0;e<n.length;e+=1)c.push({block:t,row:n[e]})}let l=[...n,...clipLiveRows(c.map(e=>e.row),r,e,this.#i),...t];i.length>0?this.#n.flush(i,l):this.#n.update(l)}#Vn(){if(!this.#ce)return;let e=this.#rr(),t=this.#Yn(e),n=Math.max(1,this.#ir()-t.length),r=this.#L,i=[];for(let{display:t}of groupToolBlocksForDisplay(this.#h)){if(this.#vr(t))continue;let n=this.#Gn(t,e,r);r=previousBlockOf(t),i.push(...n)}let a=[...clipLiveRows(i,n,e,this.#i),...t];this.#n.clearAll(),this.#n.flush([...this.#Wn(),...this.#I],a)}logDisplayMode(){return this.#m}setLogDisplayMode(e){e!==this.#m&&(this.#m=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#Un(),this.#ce&&this.#Vn())}flushDelayedDevBuildErrors(){let e=this.#Be;e!==void 0&&(this.#Be=void 0,this.#_n({kind:`log`,title:`stderr`,body:e,live:!0}),this.#zn())}#Hn(){this.#Se=!0,this.#xe!==void 0&&clearTimeout(this.#xe),this.#xe=setTimeout(()=>{this.#Se=!1,this.#xe=void 0,this.#zn()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#m)),this.#zn()}#Un(){let e=this.#rr();this.#I.length=0;let t;for(let{display:n}of groupToolBlocksForDisplay(this.#y,{logCoalescing:`runs`})){if(this.#vr(n))continue;let r=this.#Gn(n,e,t);t=previousBlockOf(n),this.#I.push(...r)}this.#L=t}#Wn(){let e=this.#O,t=this.#N;if(e===void 0&&t===void 0)return[];let n={name:e?.name??t?.name,theme:this.#i,width:this.#rr()};return e?.info!==void 0&&(n.info=e.info),buildAgentHeader(n)}#Gn(e,t,n){let r={renderMarkdown:this.#a,activityPulse:this.#qn(this.#ve,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)};n!==void 0&&(r.previous=n),this.#Xe!==void 0&&(r.setupFlowOpen=!0),this.#Je!==void 0&&(r.transientPanelOpen=!0);let i=renderBlockLines(e,t,this.#i,r);return(e.depth??0)===0&&leadsWithGap(e,n)?[``,...i]:i}#Kn(){return this.#i.spinner[this.#_e%this.#i.spinner.length]??``}#qn(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#Jn(e){return{glyph:this.#qn(e.startedAtMs,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)}}#Yn(e){let t=this.#i.colors,n=[``];if(this.#Je!==void 0){let t=this.#Je(e);return[...t.rows,...t.controls]}if(this.#qe!==void 0){let t=this.#qe(e);return[...n,...t.rows,...t.controls]}let r=this.#Xe;if(r!==void 0&&(this.#A===void 0||r.question!==void 0)){let t=this.#Jn(r),i;if(r.status!==void 0){let{startedAtMs:e,...n}=r.status,a=Date.now()-e,o=a>=5e3?` ${formatTurnDuration(a)}`:``;i={...n,text:`${n.text}${o}`,indicator:t}}let a;if(r.question!==void 0){let t=r.question(e);a={kind:`question`,title:r.questionTitle,rows:t},i!==void 0&&(a={kind:`question`,title:r.questionTitle,rows:t,status:i})}else i===void 0?a=r.preview===void 0?{kind:`idle`,indicator:t}:{kind:`preview`,text:r.preview,indicator:t}:(a={kind:`status`,status:i},r.preview!==void 0&&(a={kind:`status`,status:i,preview:r.preview}));let o={title:r.title,navigation:r.navigation,lines:r.summary===void 0?r.hideLinesWhileQuestion===!0?[]:r.lines:[{text:r.summary.headline,tone:`success`},...r.summary.facts.map(e=>({text:`${e.label}: ${e.value}`,tone:`info`}))],content:a},s=renderFlowDrawer(o,this.#i,e);return n.length===1&&n[0]===``&&(n.length=0),n.push(...s.rows),s.controls.length>0&&n.push(...s.controls),this.#tr(n,e),n}r!==void 0&&n.push(...flowMessageRows(r.lines,this.#i).map(t=>t.length===0?``:clip(` ${t}`,e))),this.#k===void 0&&this.#Ze!==void 0&&n.push(...renderAttentionRows(this.#Ze,e,this.#i),``);let i=renderMessageQueueRows({view:this.#et.view(),width:e,theme:this.#i,working:this.#ne});if(i.length>0&&n.push(...i,``),this.#G){let r=this.#K===void 0?void 0:inlineCommandHint(this.#K),i=this.#pt(e);this.#pe&&n.push(clip(t.dim(`Press Ctrl+C again to exit`),e),``);let a=r?t.dim(` ${r}`):``,o=[];this.#er(o,e);let s=Math.max(1,this.#ir()-1-n.length-1-i.length-o.length-(i.length>0?2:0)),c={text:this.#V,cursor:this.#H,width:e,theme:this.#i,caretVisible:this.#ge,ghost:a,maxRows:s};this.#Z&&this.#V.length===0&&(c.placeholder=this.#A===void 0?this.#Q?``:`Send a message…`:`Message · Enter to queue`);let l=promptInputRows(c);return i.length>0&&l.at(-1)===``&&l.pop(),n.push(...l),i.length>0&&n.push(t.dim(this.#i.glyph.dash.repeat(e))),n.push(...i),i.length>0&&o.length>0&&n.push(t.dim(this.#i.glyph.dash.repeat(e))),n.push(...o),n}let a=this.#re.kind===`waiting`&&this.#oe===void 0;if(this.#ne||a){n.push(this.#Xn(e)),this.#Qn(n,e);let t=[];return this.#er(t,e),!this.#ne&&t.length>0&&n.push(``),n.push(...t),n}if(this.#te.text.length>0)return this.#$n(n,e,{inert:!1}),this.#er(n,e),n;let o=this.#oe??(this.#ae.length>0?this.#ae:`Ready`),s=this.#nr(),c=t.dim(this.#i.glyph.dot),l=s?`${c} ${o} ${t.dim(this.#i.glyph.dot)} ${s}`:`${c} ${o}`;return n.push(clip(l,e)),this.#er(n,e),n}#Xn(e){let t=this.#i.colors,n=this.#re,r=this.#$.startedAtMs??this.#Ie??(n.kind===`waiting`?n.startedAtMs:Date.now()),i=Math.max(0,Date.now()-r),a=i%1e3<500?this.#i.unicode?`•`:`*`:` `,o=i<1e3?`0s`:formatTurnDuration(Math.floor(i/1e3)*1e3),s=`${turnActivityLabel(this.#ee)} (${o})`,{inputTokens:c,outputTokens:l}=this.#$.usage;return clip(`${a} ${s}${c>0||l>0?t.dim(` (${formatTokenFlow({inputTokens:c,outputTokens:l},this.#i.glyph)})`):``}`,e)}#Zn(e){let{inputTokens:t,outputTokens:n}=this.#$.usage,r=t===0&&n===0?``:` (${formatTokenFlow({inputTokens:t,outputTokens:n},this.#i.glyph)})`;return`${formatTurnDuration(e)}${r}`}#Qn(e,t){this.#ne&&this.#$n(e,t,{inert:!0})}#$n(e,t,n){e.push(``);let r={text:this.#te.text,cursor:this.#te.cursor,width:t,theme:this.#i,caretVisible:!0,ghost:``,maxRows:4,inert:n.inert};n.inert&&this.#te.text.length===0&&(r.placeholder=``),e.push(...promptInputRows(r))}#er(e,t){if(this.#k!==void 0){let n=this.#Xe?.status?.text??{starting:`Starting agent…`,connecting:`Reading saved connection…`,updating:`Loading selected model…`}[this.#k],r=this.#qn(this.#M,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH);e.push(clip(this.#i.colors.dim(`${r} ${n}`),t));return}let n=this.#B===void 0?``:` `,r=Math.max(1,t-n.length),i={theme:this.#i,width:r};this.#Ue&&this.#He!==void 0&&(i.devBuild=this.#He),this.#Se&&(i.logLevel=this.#m);let a=this.#O?.info?.agent.model;a?.routing.kind===`dynamic`?i.model=this.#Qe===void 0?`dynamic model`:`dynamic model · ${this.#Qe}`:a?.id!==void 0&&(i.model=a.id),a?.reasoning!==void 0&&a.reasoning!==`provider-default`&&(i.reasoning=a.reasoning),readGatewayServiceTier(a?.providerOptions).kind===`priority`&&(i.fastMode=!0);let o=a?.endpoint;o!==void 0&&(i.endpoint=o),this.#z!==void 0&&(i.vercel=this.#z),this.#B!==void 0&&(i.remote=this.#B);let s=buildStatusLine(i);s!==void 0&&e.push(clip(`${n}${s}`,t))}#tr(e,t){if(this.#B===void 0)return;let n=Math.max(1,t-2),r=buildStatusLine({remote:this.#B,theme:this.#i,width:n});r!==void 0&&e.push(``,clip(` ${r}`,t))}#nr(){let e=this.#i.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#je,outputTokens:this.#Pe,tokensPerSecond:this.#Fe},this.#u);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#i.glyph.dot} `)):``}#rr(){return Math.max(20,this.#t.columns||80)}#ir(){return Math.max(8,this.#t.rows||24)}#ar(){if(this.#Le!==void 0||!this.#d)return;this.#Re=``,this.#ze=``;let capture=(e,t)=>{let n=e.write.bind(e);return e.write=((e,n,r)=>{let i=typeof n==`string`?n:void 0,a=typeof n==`function`?n:r;return this.#cr(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#f?.subscribeLogRecords(e=>this.#sr(e)),this.#Le=()=>{this.#f?.unsubscribeLogRecords(),e(),t()}}#or(){let e=this.#Le;e!==void 0&&(this.#Le=void 0,e(),this.#Re.length>0&&(this.#f?.append({source:`stdout`,detail:this.#Re}),this.#_r(`stdout`)&&process.stdout.write(`${this.#Re}\n`),this.#Re=``),this.#ze.length>0&&(this.#f?.append({source:`stderr`,detail:this.#ze}),this.#_r(`stderr`)&&process.stderr.write(`${this.#ze}\n`),this.#ze=``))}#sr(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#ur(`[eve:${e.namespace}] ${e.message}${t}`),this.#zn()}#cr(e,t){let n=(e===`stdout`?this.#Re:this.#ze)+t;if(e===`stdout`&&parseDevRebuildLogLine(n.trimEnd())!==void 0){this.#Re=``,this.#f?.append({source:e,detail:n.trimEnd()}),this.#lr(n.trimEnd()),this.#zn();return}let r=n.lastIndexOf(`
|
|
7
|
+
`),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#Re=i:this.#ze=i,r===-1)return;let a=stripAnsi(n.slice(0,r)).replace(/\s+$/u,``);a.trim().length!==0&&(this.#f?.append({source:e,detail:a}),e===`stdout`?this.#lr(a):this.#ur(a),this.#zn())}#lr(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
|
|
8
8
|
`);t=[],e.trim().length!==0&&this.#_n({kind:`log`,title:`stdout`,body:e,live:!0})};for(let n of e.split(`
|
|
9
|
-
`)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#_n({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#
|
|
9
|
+
`)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#_n({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#fr(r,n.trimEnd())}flushPending()}#ur(e){let t=e.split(`
|
|
10
10
|
`),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#f===void 0){this.#_n({kind:`log`,title:`stderr`,body:e,live:!0});return}let t=presentDiagnostic(e,this.#f.displayPath);if(t.kind===`inline`){this.#_n({kind:`log`,title:`stderr`,body:t.text,live:!0});return}this.#_n({kind:`log`,title:`stderr`,body:formatStoredDiagnostic(t),logVisibility:`stderr-only`,live:!0}),this.#_n({kind:`log`,title:`stderr`,body:e,logVisibility:`all-only`,live:!0});return}let r=t.slice(0,n).join(`
|
|
11
11
|
`);r.trim().length>0&&this.#_n({kind:`log`,title:`stderr`,body:r,live:!0});let i=t.slice(n).join(`
|
|
12
|
-
`);this.#
|
|
13
|
-
`)}function formatQuestionContent(e,t,n){let r=n.colors,i=[],a=e.options??[];if(a.length>0){for(let[e,o]of a.entries()){let a=stripTerminalControls(o.label),s=o.description===void 0?``:stripTerminalControls(o.description),c=t===e,l=s.length>0?`${c?` `:` `}${r.dim(`— ${s}`)}`:``,u=c?`${n.glyph.selectedPointer} ${a}`:` ${a}`,d=renderCursorRow(u,c,r);i.push(`${d}${l}`)}if(e.allowFreeform===!0){let e=t===a.length,o=`Type your own answer`,s=e?`${n.glyph.selectedPointer} ${o}`:` ${r.dim(o)}`;i.push(renderCursorRow(s,e,r))}}else i.push(r.dim(` (type your answer)`));return i.join(`
|
|
12
|
+
`);this.#dr(i)}#dr(e){if(this.#mr(),this.#m===`all`){if(e.trim().length===0)return;this.#_n({kind:`log`,title:`stderr`,body:e,live:!0});return}this.#Be=e}#fr(e,t){let n=this.#hr();if(e.kind===`failed`){this.#dr(t);return}if(e.kind===`rebuilding`){let t=summarizeChangedFiles(e.events,e.more);if(this.#pr({phase:`building`,summary:t}),n!==void 0){n.state.summary=t,n.block.body=formatDevRebuildStatus(t,`rebuilding`);return}let r=`dev-rebuild:${this.#Ge}`;this.#Ge+=1,this.#Ve={id:r,summary:t},this.#_n({kind:`log`,id:r,title:`stdout`,body:formatDevRebuildStatus(t,`rebuilding`),live:!0});return}let r=n?.state.summary??this.#He?.summary;if(r!==void 0&&this.#pr({phase:`complete`,summary:r}),n!==void 0){n.block.body=formatDevRebuildStatus(n.state.summary,e.kind),e.kind===`rebuilt`&&(this.#Be=void 0);return}e.kind===`rebuilt`&&(this.#Be=void 0),this.#_n({kind:`log`,title:`stdout`,body:t,live:!0})}#pr(e){this.#We!==void 0&&clearTimeout(this.#We),this.#He=e,this.#Ue=e.phase===`complete`,this.#We=setTimeout(()=>{e.phase===`building`?(this.#Ue=!0,this.#We=void 0):this.#mr(),this.#zn()},e.phase===`building`?250:4e3)}#mr(){this.#We!==void 0&&clearTimeout(this.#We),this.#He=void 0,this.#Ue=!1,this.#We=void 0}#hr(){let e=this.#Ve;if(e===void 0)return;let t=this.#g.get(e.id);if(t!==void 0&&t.live===!0)return{state:e,block:t}}#gr(){let e=this.#Ve;if(e===void 0)return;this.#Ve=void 0;let t=this.#g.get(e.id);t!==void 0&&(t.live=!1)}#_r(e){switch(this.#m){case`none`:return!1;case`stderr`:return e===`stderr`;case`sandbox`:return e===`sandbox`;case`all`:return!0}}#vr(e){return e.kind===`sandbox`?!this.#_r(`sandbox`):e.kind===`log`?e.logVisibility===`stderr-only`?this.#m!==`stderr`:e.logVisibility===`all-only`?this.#m!==`all`:!this.#_r(e.title===`stderr`?`stderr`:`stdout`):!1}};function chunkToString(e,t){return typeof e==`string`?e:Buffer.from(e).toString(t)}async function*iterateTUIStream(e){if(e instanceof ReadableStream){let t=e.getReader();try{for(;;){let{done:e,value:n}=await t.read();if(e)return;yield n}}finally{t.releaseLock()}return}yield*e}function clip(e,t){return clipVisible(e,t)}function promptInputRows({text:e,cursor:t,width:n,theme:r,caretVisible:i,ghost:a,maxRows:o,placeholder:s,inert:c}){let l=r.colors;if(e.length===0&&s!==void 0){let e=renderInputWithBlockCursor({...visibleLine({text:s,cursor:0},Math.max(1,n-3),r.glyph.ellipsis),visible:i,inverse:l.inverse,render:e=>l.dim(renderInputText(e))});return[clip(`${r.glyph.prompt} ${e}`,n),``]}let u=renderInputText,d=layoutPromptInput({text:e,cursor:t}),f=Math.min(Math.max(1,o),d.rows.length),p=Math.max(0,Math.min(d.caretRow-f+1,d.rows.length-f)),m=c===!0?l.dim(r.glyph.prompt):e.startsWith(`/`)?r.glyph.user:r.glyph.prompt,h=l.dim(r.glyph.ellipsis),g=Math.max(1,n-3),_=[];for(let e=p;e<p+f;e+=1){let t=d.rows[e],o=e===0?m:` `;(e===p&&p>0||e===p+f-1&&p+f<d.rows.length)&&(o=h);let s;if(e===d.caretRow){let{before:e,under:n,after:o}=visibleLine({text:t.text,cursor:d.caretOffset},g,r.glyph.ellipsis);s=renderInputWithBlockCursor({before:e,under:n,after:o,visible:i,inverse:l.inverse,render:u}),a.length>0&&d.rows.length===1&&(s+=a)}else s=u(t.text);_.push(clip(`${o} ${s}`,n))}return _.push(``),_}function previousBlockOf(e){let t={kind:e.kind};return e.title!==void 0&&(t.title=e.title),t}function isActiveToolStatus(e){return e===`running`||e===`approval`}function applyCohortLiveness(e){let t=e.some(e=>e.active);for(let n of e)n.block.live=t||n.active}function leadsWithGap(e,t){if(e.kind===`tool`&&(t?.kind===`user`||t?.kind===`assistant`||t?.kind===`question`))return!0;if(e.kind===`sandbox`&&t?.kind===`sandbox`)return!1;if(t?.kind===`sandbox`&&e.kind!==`sandbox`||t?.kind===`log`)return!0;switch(e.kind){case`user`:case`assistant`:case`reasoning`:case`subagent`:case`error`:case`notice`:case`question`:case`connection-auth`:case`sandbox`:case`log`:case`command`:case`warning`:case`flow`:case`turn-stats`:case`session-boundary`:case`agent-header`:return!0;default:return!1}}function parseSandboxLogLine(e){let t=e.trim();if(!t.startsWith(`eve: `))return;let n=t.slice(5);return/\bsandbox\b/i.test(n)&&!isLowValueSandboxLogLine(n)?n:void 0}function isLowValueSandboxLogLine(e){return/^initializing (?:\d+ )?sandbox templates?\b/i.test(e)||/^initialized \d+ sandbox\b/i.test(e)||/^reused cached sandbox template\b/i.test(e)||/^sandbox template "[^"]+" \([^)]+\): (checking|reusing|loading microsandbox runtime|microsandbox runtime ready)\b/i.test(e)}function clipLiveRows(e,t,n,r){if(e.length<=t)return[...e];if(t<=1)return[clip(hiddenRowsMarker(e.length,r),n)];let i=t-1;return[clip(hiddenRowsMarker(e.length-i,r),n),...e.slice(e.length-i)]}function hiddenRowsMarker(e,t){let n=e.toLocaleString(),r=e===1?`row`:`rows`;return t.colors.dim(`${t.glyph.dot} ${t.glyph.ellipsis} ${n} earlier ${r} hidden while streaming`)}function collapseReasoning(e,t){switch(e){case`collapsed`:return!0;case`auto-collapsed`:return!t;default:return!1}}function renderNativeToolBlock(e,t,n,r){let i=e.preparing===!0?presentPreparingTool(e.toolName,r):presentTool(e.toolName,e.input,r),a={id:t,kind:`tool`,title:stripTerminalControls(i.title),subtitle:stripTerminalControls(i.subtitle),status:e.status,live:e.status===`running`||e.status===`approval`,expanded:n,toolInput:e.input,toolName:e.toolName,toolGroup:i.group};return i.doneTitle!==void 0&&(a.doneTitle=stripTerminalControls(i.doneTitle)),i.detail!==void 0&&(a.detailLines=i.detail,a.keepDetailWhenDone=i.keepDetailWhenDone===!0),e.output===void 0?e.errorText!==void 0&&(a.result=stripTerminalControls(e.errorText)):(a.result=i.summarizeResult(e.output),a.toolOutput=e.output),a}function writeExistedFlag(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e.existed;return typeof t==`boolean`?t:void 0}function subagentToolStatus(e){switch(e){case`preparing`:return`running`;case`approval-requested`:return`approval`;case`executing`:return`running`;case`done`:return`done`;case`failed`:return`error`;case`rejected`:return`denied`}}function formatToolApprovalTitle(e){return stripTerminalControls(e.title??e.toolName)}function toolSectionId(e){return`tool:${e}`}function questionSectionId(e){return`question:${e}`}function subagentHeaderId(e){return`subagent:${e}:header`}function subagentStepSectionId(e,t){return`subagent:${e}:step:${t}`}function subagentToolSectionId(e,t){return`subagent:${e}:tool:${t}`}function connectionAuthSectionId(e){return`connection-auth:${e}`}function connectionAuthTerminalMessage(e){switch(e){case`authorized`:return`Authorization complete`;case`declined`:return`Authorization declined`;case`failed`:return`Authorization failed`;case`timed-out`:return`Authorization timed out`;case`required`:case`pending`:return}}function formatConnectionAuthContent(e,t){let n=[];if(t!==void 0)n.push(t);else{let t=stripTerminalControls(e.description);t.length>0&&n.push(t);let r=e.challenge;r?.url&&n.push(`URL: ${stripTerminalControls(r.url)}`),r?.userCode&&n.push(`Code: ${stripTerminalControls(r.userCode)}`),r?.expiresAt&&n.push(`Expires: ${stripTerminalControls(r.expiresAt)}`),r?.instructions&&n.push(stripTerminalControls(r.instructions))}if(e.reason!==void 0){let t=stripTerminalControls(e.reason);t.length>0&&n.push(`Reason: ${t}`)}return n.join(`
|
|
14
13
|
`)}function resolveQuestionText(e,t){let n=e.trim();if(n.length===0)return;let r=n.toLowerCase(),i=t.options??[];if(i.length>0){let e=matchQuestionOption(r,i);if(e!==void 0)return{optionId:e.id,label:e.label}}if(t.allowFreeform===!0||i.length===0)return{text:n,label:n}}function matchQuestionOption(e,t){let n=t.find(t=>t.id.toLowerCase()===e);if(n!==void 0)return n;let r=t.find(t=>t.label.toLowerCase()===e);if(r!==void 0)return r;let i=Number(e);if(Number.isInteger(i)&&i>0&&i<=t.length)return t[i-1]}export{TerminalRenderer};
|
|
@@ -80,7 +80,7 @@ export interface ThemeGlyphs {
|
|
|
80
80
|
elbow: string;
|
|
81
81
|
/** `▔` — strong full-width rule opening the bottom question panel. */
|
|
82
82
|
hrule: string;
|
|
83
|
-
/** `─` — light rule segment framing
|
|
83
|
+
/** `─` — light rule segment framing drawers and panel boundaries. */
|
|
84
84
|
dash: string;
|
|
85
85
|
/** `▏` — the synthetic input caret. */
|
|
86
86
|
caret: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{InvalidArgumentError}from"#compiled/commander/index.js";import{encodeBasicCredentials}from"#internal/http/basic-auth.js";function parseDevelopmentHeaderOption(e,t={}){let n=e.indexOf(`:`);if(n<1)throw new InvalidArgumentError(`Expected header in "Name: value" format, received "${e}".`);let r=e.slice(0,n).trim(),i=e.slice(n+1).trim();try{new Headers([[r,i]])}catch{throw new InvalidArgumentError(`Expected a valid HTTP header, received "${e}".`)}return mergeDevelopmentHeaders(t,{[r]:i})??{}}function resolveDevelopmentUrlTarget(e,t){if(e.url!==void 0&&t!==void 0)throw new InvalidArgumentError(`Pass either --url or a bare URL, not both.`);let n=e.url??t;if(n===void 0){if(e.header!==void 0)throw new InvalidArgumentError(`The --header option can only be used with --url or a bare URL.`);return}if(e.host!==void 0)throw new InvalidArgumentError(`The --host option cannot be used with --url.`);if(e.port!==void 0)throw new InvalidArgumentError(`The --port option cannot be used with --url.`);if(e.ui===!1)throw new InvalidArgumentError(`The --no-ui option cannot be used with --url.`);let r=URL.parse(n);if(r===null)throw new InvalidArgumentError(`Expected an absolute http(s) URL, received "${n}".`);let i=mergeDevelopmentHeaders(extractDevelopmentUrlHeaders(r),e.header),a=r.toString();return i===void 0?{serverUrl:a}:{headers:i,serverUrl:a}}function mergeDevelopmentHeaders(e,t){if(e===void 0)return t;if(t===void 0)return e;let n={},r=new Set(Object.keys(t).map(e=>e.toLowerCase()));for(let[t,i]of Object.entries(e))r.has(t.toLowerCase())||(n[t]=i);for(let[e,r]of Object.entries(t))n[e]=r;return n}function extractDevelopmentUrlHeaders(e){if(e.username===``&&e.password===``)return;let t=decodeUrlUserInfo(e.username,`username`),n=decodeUrlUserInfo(e.password,`password`);return e.username=``,e.password=``,{Authorization:`Basic ${encodeBasicCredentials(t,n)}`}}function decodeUrlUserInfo(e,t){try{return decodeURIComponent(e)}catch{throw new InvalidArgumentError(`Expected a valid URL-encoded ${t} in URL userinfo.`)}}export{parseDevelopmentHeaderOption,resolveDevelopmentUrlTarget};
|
|
1
|
+
import{parseDevelopmentServerUrl}from"./url.js";import{InvalidArgumentError}from"#compiled/commander/index.js";import{encodeBasicCredentials}from"#internal/http/basic-auth.js";function parseDevelopmentHeaderOption(e,t={}){let n=e.indexOf(`:`);if(n<1)throw new InvalidArgumentError(`Expected header in "Name: value" format, received "${e}".`);let r=e.slice(0,n).trim(),i=e.slice(n+1).trim();try{new Headers([[r,i]])}catch{throw new InvalidArgumentError(`Expected a valid HTTP header, received "${e}".`)}return mergeDevelopmentHeaders(t,{[r]:i})??{}}function resolveDevelopmentUrlTarget(e,t){if(e.url!==void 0&&t!==void 0)throw new InvalidArgumentError(`Pass either --url or a bare URL, not both.`);let n=e.url??t;if(n===void 0){if(e.header!==void 0)throw new InvalidArgumentError(`The --header option can only be used with --url or a bare URL.`);return}if(e.host!==void 0)throw new InvalidArgumentError(`The --host option cannot be used with --url.`);if(e.port!==void 0)throw new InvalidArgumentError(`The --port option cannot be used with --url.`);if(e.ui===!1)throw new InvalidArgumentError(`The --no-ui option cannot be used with --url.`);let r=URL.parse(parseDevelopmentServerUrl(n));if(r===null)throw new InvalidArgumentError(`Expected an absolute http(s) URL, received "${n}".`);let i=mergeDevelopmentHeaders(extractDevelopmentUrlHeaders(r),e.header),a=r.toString();return i===void 0?{serverUrl:a}:{headers:i,serverUrl:a}}function mergeDevelopmentHeaders(e,t){if(e===void 0)return t;if(t===void 0)return e;let n={},r=new Set(Object.keys(t).map(e=>e.toLowerCase()));for(let[t,i]of Object.entries(e))r.has(t.toLowerCase())||(n[t]=i);for(let[e,r]of Object.entries(t))n[e]=r;return n}function extractDevelopmentUrlHeaders(e){if(e.username===``&&e.password===``)return;let t=decodeUrlUserInfo(e.username,`username`),n=decodeUrlUserInfo(e.password,`password`);return e.username=``,e.password=``,{Authorization:`Basic ${encodeBasicCredentials(t,n)}`}}function decodeUrlUserInfo(e,t){try{return decodeURIComponent(e)}catch{throw new InvalidArgumentError(`Expected a valid URL-encoded ${t} in URL userinfo.`)}}export{parseDevelopmentHeaderOption,resolveDevelopmentUrlTarget};
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { type Command } from "#compiled/commander/index.js";
|
|
2
2
|
import type { CliApplicationContext } from "#cli/application-command.js";
|
|
3
|
-
import type { DevelopmentServer, DevelopmentServerOptions } from "#internal/nitro/host/types.js";
|
|
4
3
|
import { type RunInvokeInput } from "./invoke.js";
|
|
5
4
|
import { type InvokeResult } from "./result.js";
|
|
6
5
|
export interface InvokeCommandDependencies {
|
|
7
6
|
readonly loadEnvironment: (appRoot: string) => void | Promise<void>;
|
|
8
7
|
readonly runInvoke: (input: RunInvokeInput) => Promise<InvokeResult>;
|
|
9
|
-
readonly startHost: (appRoot: string) => DevelopmentServer | Promise<DevelopmentServer>;
|
|
10
8
|
}
|
|
11
|
-
/** Runtime overrides used when wiring `eve invoke` into the
|
|
9
|
+
/** Runtime overrides used when wiring `eve remote invoke` into the CLI. */
|
|
12
10
|
export interface InvokeCliRuntimeDependencies {
|
|
13
11
|
readonly runInvoke: (input: RunInvokeInput) => Promise<InvokeResult>;
|
|
14
|
-
readonly startHost: (appRoot: string, options?: DevelopmentServerOptions) => DevelopmentServer;
|
|
15
12
|
}
|
|
16
13
|
interface InvokeCommandLogger {
|
|
17
14
|
log(message: string): void;
|
|
@@ -23,7 +20,7 @@ export declare function registerRuntimeInvokeCommand(input: {
|
|
|
23
20
|
readonly program: Command;
|
|
24
21
|
readonly runtime: Partial<InvokeCliRuntimeDependencies>;
|
|
25
22
|
}): void;
|
|
26
|
-
/** Registers the non-interactive
|
|
23
|
+
/** Registers the non-interactive remote invocation command. */
|
|
27
24
|
export declare function registerInvokeCommand(input: {
|
|
28
25
|
readonly applicationContext: CliApplicationContext;
|
|
29
26
|
readonly deps: InvokeCommandDependencies;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{parseInvokeResumeInput}from"./result.js";import{resolveInvokeOperation}from"./invoke.js";import{InvalidArgumentError}from"#compiled/commander/index.js";import{parseDevelopmentHeaderOption,resolveDevelopmentUrlTarget}from"#cli/dev/url-target.js";import{parseDevelopmentServerUrl}from"#cli/dev/url.js";function registerRuntimeInvokeCommand(e){registerInvokeCommand({...e,deps:{loadEnvironment:async e=>await(await import(`#cli/dev/environment.js`)).loadDevelopmentEnvironmentFiles(e),runInvoke:async t=>await(e.runtime.runInvoke??(await import(`./invoke.js`)).runInvoke)(t)}})}function registerInvokeCommand(e){e.program.command(`invoke [prompt]`).description(`Invoke an existing eve agent without a terminal UI.`).requiredOption(`-u, --url <url>`,`Existing eve agent URL`,parseDevelopmentServerUrl).option(`-H, --header <header>`,`Request header for a URL target, in "Name: value" form (repeatable)`,parseDevelopmentHeaderOption).option(`--resume`,`Read a previous resumable result from stdin`).option(`--scope <team>`,`Vercel team that owns the URL target`).action((t,n)=>runInvokeCommand({...e,options:n,prompt:t,url:n.url}))}async function runInvokeCommand(e){let{options:t}=e,n=t.resume===!0?parseInvokeResumeInput(await readJsonFromStdin()):void 0,r=n?.resume.target,i=resolveDevelopmentUrlTarget({header:t.header,url:e.url},void 0);if(r?.serverUrl!==void 0&&r.serverUrl!==i.serverUrl)throw Error(`Session target ${r.serverUrl} does not match ${i.serverUrl}.`);let a=resolveInvokeOperation({previous:n,prompt:e.prompt});await e.deps.loadEnvironment(e.applicationContext.root),await executeWithSignals(e,{kind:`remote`,serverUrl:i.serverUrl,workspaceRoot:e.applicationContext.root},i.headers,a,t.scope)}async function executeWithSignals(e,t,n,r,i){let a=new AbortController,o,handleSigint=()=>{o=130,a.abort()},handleSigterm=()=>{o=143,a.abort()};process.once(`SIGINT`,handleSigint),process.once(`SIGTERM`,handleSigterm);try{let s=n===void 0?{operation:r,signal:a.signal,target:t}:{headers:n,operation:r,signal:a.signal,target:t},c=i===void 0?s:{...s,vercelScope:i},l=await e.deps.runInvoke(c);e.logger.log(JSON.stringify(l,null,2)),process.exitCode=o??invokeExitCode(l)}finally{process.off(`SIGINT`,handleSigint),process.off(`SIGTERM`,handleSigterm)}}async function readJsonFromStdin(){let e=``;process.stdin.setEncoding(`utf8`);for await(let t of process.stdin)e+=t;if(e.trim().length===0)throw new InvalidArgumentError(`--resume expected a resumable eve remote invoke result on stdin.`);try{return JSON.parse(e)}catch{throw new InvalidArgumentError(`--resume received invalid JSON on stdin.`)}}function invokeExitCode(e){return e.status===`failed`||e.status===`authentication-required`||e.status===`ready`&&e.outcome.status===`failed`?1:e.status===`input-required`||e.status===`authorization-required`?3:0}export{registerInvokeCommand,registerRuntimeInvokeCommand};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SendTurnPayload } from "#client/types.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { RemoteDevelopmentTarget } from "#services/dev-client/target.js";
|
|
3
3
|
import { type InvokeResult, type InvokeResume } from "./result.js";
|
|
4
4
|
export type InvokeOperation = {
|
|
5
5
|
readonly kind: "send";
|
|
@@ -13,7 +13,7 @@ export interface RunInvokeInput {
|
|
|
13
13
|
readonly headers?: Readonly<Record<string, string>>;
|
|
14
14
|
readonly operation: InvokeOperation;
|
|
15
15
|
readonly signal?: AbortSignal;
|
|
16
|
-
readonly target:
|
|
16
|
+
readonly target: RemoteDevelopmentTarget;
|
|
17
17
|
readonly vercelScope?: string;
|
|
18
18
|
}
|
|
19
19
|
/** Runs one non-interactive eve invocation. */
|