eve 0.62.0 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/src/cli/dev/tui/model-picker.d.ts +48 -0
- package/dist/src/cli/dev/tui/model-picker.js +1 -0
- package/dist/src/cli/dev/tui/prompt-commands.js +1 -1
- package/dist/src/cli/dev/tui/runner.js +2 -2
- package/dist/src/cli/dev/tui/setup-commands.d.ts +1 -1
- package/dist/src/cli/dev/tui/setup-commands.js +1 -1
- package/dist/src/cli/dev/tui/setup-flow.d.ts +2 -2
- package/dist/src/cli/dev/tui/setup-panel.d.ts +1 -26
- package/dist/src/cli/dev/tui/setup-panel.js +3 -3
- package/dist/src/cli/dev/tui/stream-format.d.ts +0 -7
- package/dist/src/cli/dev/tui/stream-format.js +1 -1
- package/dist/src/cli/dev/tui/subagent-pump.js +1 -1
- package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
- package/dist/src/cli/dev/tui/test/fake-setup-flow-renderer.js +1 -1
- package/dist/src/cli/dev/tui/test/mock-terminal.js +1 -1
- package/dist/src/cli/dev/tui/theme.d.ts +0 -8
- package/dist/src/cli/dev/tui/theme.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +1 -1
- package/dist/src/compiler/extension-compatibility.d.ts +25 -6
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/normalize-agent-config.js +1 -1
- package/dist/src/compiler/normalize-tool.js +1 -1
- package/dist/src/context/build-dynamic-tools.js +1 -1
- package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
- package/dist/src/evals/runner/derive-run-facts.js +1 -1
- package/dist/src/evals/types.d.ts +4 -3
- package/dist/src/eve-channel/request.js +1 -1
- package/dist/src/execution/cancel-descendant-turns-step.js +1 -1
- package/dist/src/execution/cancel-indexed-session-tasks-step.d.ts +2 -1
- package/dist/src/execution/cancel-indexed-session-tasks-step.js +1 -1
- package/dist/src/execution/coordination-dispatch-shared.d.ts +1 -6
- package/dist/src/execution/coordination-dispatch-shared.js +1 -1
- package/dist/src/execution/coordination-dispatch-step.js +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/legacy-session/interrupt-step.js +1 -1
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/proxied-deliver-step.js +1 -1
- package/dist/src/execution/route-child-delivery.js +3 -1
- package/dist/src/execution/session/admission.js +1 -1
- package/dist/src/execution/session/handoff-steps.js +1 -1
- package/dist/src/execution/session/handoff.d.ts +2 -1
- package/dist/src/execution/session/handoff.js +1 -1
- package/dist/src/execution/session/input-queue.d.ts +2 -0
- package/dist/src/execution/session/input-queue.js +1 -1
- package/dist/src/execution/session/next-input.js +1 -1
- package/dist/src/execution/session/turn.js +1 -1
- package/dist/src/execution/session-workflow-tool-run.js +1 -1
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/stable-workflow-names.d.ts +0 -1
- package/dist/src/execution/stable-workflow-names.js +1 -1
- package/dist/src/execution/tasks/child/notify.d.ts +44 -0
- package/dist/src/execution/tasks/child/notify.js +1 -0
- package/dist/src/execution/tasks/parent/control-shared.d.ts +2 -5
- package/dist/src/execution/tasks/parent/control-shared.js +1 -1
- package/dist/src/execution/tasks/parent/delegate.d.ts +8 -36
- package/dist/src/execution/tasks/parent/delegate.js +1 -1
- package/dist/src/execution/tasks/parent/dispatch.d.ts +3 -5
- package/dist/src/execution/tasks/parent/dispatch.js +1 -1
- package/dist/src/execution/tasks/parent/hitl-proxy-steps.d.ts +4 -1
- package/dist/src/execution/tasks/parent/hitl-proxy-steps.js +1 -1
- package/dist/src/execution/tasks/parent/run-parent.d.ts +5 -19
- package/dist/src/execution/tasks/parent/run-parent.js +1 -1
- package/dist/src/execution/tasks/parent/task-cancel.d.ts +6 -5
- package/dist/src/execution/tasks/parent/task-cancel.js +1 -1
- package/dist/src/execution/tasks/parent/tool-execution.js +1 -1
- package/dist/src/execution/tool-auth.d.ts +3 -9
- package/dist/src/execution/tool-auth.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/execution/tools/sleep-workflow.js +1 -1
- package/dist/src/execution/tools/subagent/accept-event-step.js +1 -1
- package/dist/src/execution/tools/subagent/emit-event-step.d.ts +11 -0
- package/dist/src/execution/tools/subagent/emit-event-step.js +1 -0
- package/dist/src/execution/tools/subagent/invoke-agent.d.ts +5 -7
- package/dist/src/execution/tools/subagent/invoke-agent.js +1 -1
- package/dist/src/execution/tools/subagent/invoke-preparation.js +1 -1
- package/dist/src/execution/tools/subagent/invoke-step.d.ts +3 -2
- package/dist/src/execution/tools/subagent/invoke-step.js +1 -1
- package/dist/src/execution/tools/subagent/task-agent-requests.d.ts +0 -1
- package/dist/src/execution/tools/subagent/task-agent-requests.js +1 -1
- package/dist/src/execution/tools/subagent/task-cancel.d.ts +1 -1
- package/dist/src/execution/tools/subagent/task-cancel.js +1 -1
- package/dist/src/execution/tools/workflow/background.d.ts +1 -1
- package/dist/src/execution/tools/workflow/background.js +1 -1
- package/dist/src/execution/tools/workflow/body.d.ts +0 -2
- package/dist/src/execution/tools/workflow/body.js +1 -1
- package/dist/src/execution/tools/workflow/cancel.d.ts +4 -3
- package/dist/src/execution/tools/workflow/cancel.js +1 -1
- package/dist/src/execution/tools/workflow/cancellation-policy.d.ts +2 -0
- package/dist/src/execution/tools/workflow/cancellation-policy.js +1 -0
- package/dist/src/execution/tools/workflow/messages.d.ts +0 -1
- package/dist/src/execution/tools/workflow/owner-channels.d.ts +6 -6
- package/dist/src/execution/tools/workflow/owner-inbox.d.ts +5 -9
- package/dist/src/execution/tools/workflow/owner-inbox.js +1 -1
- package/dist/src/execution/tools/workflow/owner.d.ts +6 -2
- package/dist/src/execution/tools/workflow/owner.js +1 -1
- package/dist/src/execution/tools/workflow/start.js +1 -1
- package/dist/src/execution/tools/workflow/types.d.ts +11 -19
- package/dist/src/execution/tools/workflow/types.js +1 -1
- package/dist/src/execution/tools/workflow/workflow-owner-background.d.ts +13 -0
- package/dist/src/execution/tools/workflow/workflow-owner-background.js +1 -0
- package/dist/src/execution/tools/workflow/workflow-owner-blocking.d.ts +12 -0
- package/dist/src/execution/tools/workflow/workflow-owner-blocking.js +1 -0
- package/dist/src/execution/tools/workflow/workflow.d.ts +3 -3
- package/dist/src/execution/tools/workflow/workflow.js +1 -1
- package/dist/src/execution/workflow-runtime.d.ts +0 -4
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/harness/background-tools.d.ts +3 -5
- package/dist/src/harness/coordination.js +1 -1
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/execute-tool.d.ts +2 -29
- package/dist/src/harness/tool-loop.js +1 -1
- package/dist/src/harness/tool-model-output.js +1 -1
- package/dist/src/harness/tools.js +1 -1
- package/dist/src/harness/workflow-tool-runs.d.ts +53 -18
- package/dist/src/harness/workflow-tool-runs.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/protocol/message.d.ts +4 -4
- package/dist/src/public/tools/index.d.ts +2 -2
- package/dist/src/runtime/agent/resolve-model.js +1 -1
- package/dist/src/runtime/connections/scoped-authorization.js +1 -1
- package/dist/src/runtime/sessions/turn.d.ts +10 -8
- package/dist/src/runtime/subagents/registry.js +1 -1
- package/dist/src/runtime/subagents/workflow.js +1 -1
- package/dist/src/runtime/tools/registry.js +1 -1
- package/dist/src/setup/flows/model.d.ts +5 -5
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/shared/action-types.d.ts +0 -4
- package/dist/src/shared/action-types.js +1 -1
- package/dist/src/tasks/delivery-context.js +2 -2
- package/dist/src/tasks/notification.d.ts +4 -0
- package/dist/src/tasks/notification.js +1 -0
- package/dist/src/tasks/session-task-cohorts.d.ts +1 -12
- package/dist/src/tasks/session-task-cohorts.js +1 -1
- package/dist/src/tasks/transitions.d.ts +5 -2
- package/dist/src/tasks/transitions.js +1 -1
- package/dist/src/tasks/types.d.ts +2 -52
- package/dist/src/tasks/types.js +1 -1
- package/dist/src/tools/definition.d.ts +1 -25
- package/dist/src/tools/definition.js +1 -1
- package/dist/src/tools/dynamic.d.ts +1 -3
- package/dist/src/tools/framework/agent.d.ts +16 -22
- package/dist/src/tools/framework/agent.js +1 -1
- package/dist/src/tools/workflow-definition.d.ts +16 -5
- package/dist/src/tracing/agent-invocation-coordinator.js +1 -1
- package/dist/src/tracing/agent-trace-context-store.js +1 -1
- package/docs/concepts/execution-model-and-durability.mdx +4 -5
- package/docs/concepts/sessions-runs-and-streaming.md +2 -2
- package/docs/evals/assertions.mdx +5 -1
- package/docs/guides/dev-tui.md +21 -9
- package/docs/guides/frontend/overview.mdx +1 -1
- package/docs/subagents/index.mdx +12 -9
- package/docs/tools/overview.mdx +26 -34
- package/docs/tools/workflows.mdx +31 -24
- package/package.json +1 -1
- package/dist/src/cli/dev/tui/model-editor.d.ts +0 -103
- package/dist/src/cli/dev/tui/model-editor.js +0 -1
- package/dist/src/execution/tasks/child/steps.d.ts +0 -81
- package/dist/src/execution/tasks/child/steps.js +0 -1
- package/dist/src/execution/tasks/child/workflow.d.ts +0 -28
- package/dist/src/execution/tasks/child/workflow.js +0 -1
- package/dist/src/execution/tools/subagent/emit-called-step.d.ts +0 -9
- package/dist/src/execution/tools/subagent/emit-called-step.js +0 -1
- package/dist/src/execution/tools/workflow/run-control.d.ts +0 -14
- package/dist/src/execution/tools/workflow/run-control.js +0 -1
- package/dist/src/tasks/session-index.d.ts +0 -65
- package/dist/src/tasks/session-index.js +0 -1
- package/dist/src/tools/task.d.ts +0 -55
- package/dist/src/tools/task.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# eve
|
|
2
2
|
|
|
3
|
+
## 0.63.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d2c92df: Require durable background tools to use `defineWorkflowTool`. Remove background execution from `defineTool` and dynamic tools, including the `TaskExec` and `postMessage` authoring APIs, and deliver each background cohort's completed, failed, and cancelled outcomes in one automatic report.
|
|
8
|
+
|
|
9
|
+
Background invocations share workflow execution and cancellation cleanup. Agent settlement records usage once before its enclosing workflow returns a tool result. Parent sessions retain task outcomes, and late results cannot overwrite a recorded cancellation; channel task views no longer include executor bindings. Background workflow yields are consumed without publishing progress or retaining a task-progress stream.
|
|
10
|
+
|
|
11
|
+
Align `subagent.completed` for blocking and background agents: emit the actual output only after the parent records success. Background receipts remain `action.result` tool outputs; completion events no longer announce admission or wait for cohort reporting.
|
|
12
|
+
|
|
13
|
+
Use task lifecycle values in subagent eval assertions: replace `status: "pending"` with `"working"` and `"rejected"` with `"failed"`. Explicit cancelled child outcomes now retain `"cancelled"` instead of appearing as failures.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- a042a9a: Choose a model, speed, and reasoning through separate steps in the terminal UI, with clear defaults and changes applied together after the final choice. The slash menu now puts model selection and session controls first, and a steady Thinking, Generating, or Running label with a blinking dot replaces the animated Working label during turns.
|
|
18
|
+
- f240baa: Fix local development snapshots for extension subagents mounted from hoisted workspace dependencies.
|
|
19
|
+
|
|
3
20
|
## 0.62.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ReasoningLevel } from "#setup/boxes/model-capabilities.js";
|
|
2
|
+
import { type SelectState } from "#setup/cli/select-state.js";
|
|
3
|
+
import type { ModelSettingsRequest, ModelSettingsResult } from "#setup/flows/model.js";
|
|
4
|
+
import type { Theme } from "./theme.js";
|
|
5
|
+
type ModelPickerStep = "model" | "speed" | "reasoning";
|
|
6
|
+
interface ModelPickerDraft {
|
|
7
|
+
model: string | null;
|
|
8
|
+
speed: "standard" | "priority";
|
|
9
|
+
reasoning: "default" | ReasoningLevel;
|
|
10
|
+
}
|
|
11
|
+
interface ModelPickerPage {
|
|
12
|
+
step: ModelPickerStep;
|
|
13
|
+
select: SelectState;
|
|
14
|
+
draft: ModelPickerDraft;
|
|
15
|
+
}
|
|
16
|
+
export interface ModelPickerState extends ModelPickerPage {
|
|
17
|
+
history: readonly Pick<ModelPickerPage, "step" | "select">[];
|
|
18
|
+
}
|
|
19
|
+
export type ModelPickerEvent = {
|
|
20
|
+
type: "up";
|
|
21
|
+
} | {
|
|
22
|
+
type: "down";
|
|
23
|
+
} | {
|
|
24
|
+
type: "back";
|
|
25
|
+
} | {
|
|
26
|
+
type: "cancel";
|
|
27
|
+
} | {
|
|
28
|
+
type: "submit";
|
|
29
|
+
} | {
|
|
30
|
+
type: "backspace";
|
|
31
|
+
} | {
|
|
32
|
+
type: "char";
|
|
33
|
+
char: string;
|
|
34
|
+
};
|
|
35
|
+
export type ModelPickerTransition = {
|
|
36
|
+
kind: "render";
|
|
37
|
+
state: ModelPickerState;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "cancel";
|
|
40
|
+
} | {
|
|
41
|
+
kind: "settle";
|
|
42
|
+
result: ModelSettingsResult;
|
|
43
|
+
};
|
|
44
|
+
export declare function initialModelPickerState(request: ModelSettingsRequest): ModelPickerState;
|
|
45
|
+
export declare function transitionModelPicker(state: ModelPickerState, event: ModelPickerEvent, request: ModelSettingsRequest): ModelPickerTransition;
|
|
46
|
+
export declare function modelPickerTitle(state: ModelPickerState): string;
|
|
47
|
+
export declare function renderModelPicker(request: ModelSettingsRequest, state: ModelPickerState, theme: Theme, width: number): string[];
|
|
48
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{renderSelectQuestion}from"./setup-panel.js";import{ALL_REASONING_LEVELS}from"#setup/boxes/model-capabilities.js";import{filterOptions,initialSelectState,reduceSelect,selectValueAtCursor}from"#setup/cli/select-state.js";const SPEED_OPTIONS=[{value:`standard`,label:`Standard`,hint:`Normal speed and pricing`},{value:`priority`,label:`Fast`,hint:`Priority processing, higher cost`}],REASONING_COPY={none:{label:`None`,hint:`No reasoning`},minimal:{label:`Minimal`,hint:`The least thinking`},low:{label:`Low`,hint:`Less thinking, quicker answers`},medium:{label:`Medium`,hint:`Balance thinking and response time`},high:{label:`High`,hint:`More thinking for harder tasks`},xhigh:{label:`Extra high`,hint:`The most thinking, slower answers`}},REASONING_OPTIONS=[{value:`default`,label:`Provider default`,hint:`Use the model's default reasoning`},...ALL_REASONING_LEVELS.map(e=>({value:e,...REASONING_COPY[e]}))];function modelOptions(e){if(e.model.kind===`fixed`)return[{value:`fixed`,label:e.model.current??`Configured in agent.ts`}];let{options:t,current:n}=e.model;return n===null||t.some(e=>e.value===n)?t:[{value:n,label:n,hint:`Current model`},...t]}function stepOptions(e,t,n){switch(n){case`model`:return modelOptions(e);case`speed`:return SPEED_OPTIONS;case`reasoning`:{let n=reasoningLevels(e,t);return REASONING_OPTIONS.filter(e=>e.value==="default"||n.includes(e.value))}}}function reasoningLevels(e,t){let n=e.capabilitiesFor(t.model);return n===void 0?t.model===e.model.current&&e.reasoning!==null?[e.reasoning]:[]:n.reasoning?n.reasoningLevels:[]}function nextStep(e,t,n){if(!e.settingsEditable)return;let r=e.capabilitiesFor(t.model);if(n===`model`&&!e.externalRouting&&e.serviceTier.kind!==`custom`&&(r?.fastMode||r===void 0&&t.model===e.model.current&&e.serviceTier.kind===`priority`))return`speed`;if(n!==`reasoning`&&reasoningLevels(e,t).length>0)return`reasoning`}function initialModelPickerState(e){let t={model:e.model.current,speed:e.serviceTier.kind===`priority`?`priority`:`standard`,reasoning:e.reasoning??`default`};return{step:`model`,draft:t,select:initialSelectState({options:modelOptions(e),defaultValue:t.model??void 0}),history:[]}}function selectionDraft(e,t,n){let r={...t.draft};switch(t.step){case`model`:{if(e.model.kind===`fixed`)return r;r.model=n;let t=e.capabilitiesFor(n);return t!==void 0&&(t.fastMode||(r.speed=`standard`),r.reasoning!=="default"&&(!t.reasoning||!t.reasoningLevels.includes(r.reasoning))&&(r.reasoning=`default`)),r}case`speed`:return r.speed=SPEED_OPTIONS.find(e=>e.value===n).value,r;case`reasoning`:return r.reasoning=REASONING_OPTIONS.find(e=>e.value===n).value,r}}function selectionResult(e,t){let n={};if(e.model.kind===`pick`&&t.model!==null&&t.model!==e.model.current&&(n.model=t.model),e.settingsEditable){t.reasoning!==(e.reasoning??`default`)&&(n.reasoning=t.reasoning);let r=e.serviceTier.kind===`priority`?`priority`:`standard`;!e.externalRouting&&e.serviceTier.kind!==`custom`&&t.speed!==r&&(n.serviceTier=t.speed)}return n}function transitionModelPicker(e,t,n){if(t.type===`cancel`)return{kind:`cancel`};if(t.type===`back`){let t=e.history.at(-1);return t===void 0?{kind:`cancel`}:{kind:`render`,state:{...t,draft:e.draft,history:e.history.slice(0,-1)}}}let r=stepOptions(n,e.draft,e.step);if(t.type!==`submit`)return(e.step!==`model`||n.model.kind!==`pick`)&&(t.type===`char`||t.type===`backspace`)?{kind:`render`,state:e}:{kind:`render`,state:{...e,select:reduceSelect(e.select,t,{options:r})}};let i=selectValueAtCursor(filterOptions(r,e.select.filter),e.select.cursor);if(i===void 0)return{kind:`render`,state:e};let a=selectionDraft(n,e,i),o=nextStep(n,a,e.step);return o===void 0?{kind:`settle`,result:selectionResult(n,a)}:{kind:`render`,state:{step:o,draft:a,select:initialSelectState({options:stepOptions(n,a,o),defaultValue:a[o]}),history:[...e.history,{step:e.step,select:e.select}]}}}function modelPickerTitle(e){return{model:`Select model`,speed:`Select speed`,reasoning:`Select reasoning`}[e.step]}function renderModelPicker(e,t,n,r){let i=stepOptions(e,t.draft,t.step),a=selectValueAtCursor(filterOptions(i,t.select.filter),t.select.cursor),o=nextStep(e,a===void 0?t.draft:selectionDraft(e,t,a),t.step)===void 0,s=modelOptions(e).find(e=>e.value===t.draft.model)?.label??t.draft.model,c=t.step===`model`?e.model.kind===`fixed`?e.model.reason:void 0:[s,...t.step===`reasoning`&&t.history.some(e=>e.step===`speed`)?[t.draft.speed===`priority`?`Fast`:`Standard`]:[]].filter(Boolean).join(` · `);return renderSelectQuestion({kind:t.step===`model`&&e.model.kind===`pick`?`search`:`single`,message:``,description:c,options:i,select:t.select,footerHints:[`↑/↓ move`,o?`Enter apply`:`Enter next`,t.history.length>0?`Esc/← back`:`Esc cancel`]},n,r)}export{initialModelPickerState,modelPickerTitle,renderModelPicker,transitionModelPicker};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const PROMPT_COMMAND_DEFINITIONS=[{name:`
|
|
1
|
+
const PROMPT_COMMAND_DEFINITIONS=[{name:`model`,aliases:[],description:`Choose a model, speed, and reasoning`,argumentHint:`[provider/model]`,takesArgument:!0,build:e=>({type:`extension`,name:`model`,argument:e}),targets:[`local`]},{name:`reset`,aliases:[],description:`Start a fresh session`,takesArgument:!1,build:()=>({type:`reset`}),targets:[`local`,`remote`]},{name:`clear`,aliases:[`new`],description:`Clear the current session context`,takesArgument:!1,build:()=>({type:`clear`}),targets:[`local`,`remote`]},{name:`compact`,aliases:[],description:`Compact the current session context`,takesArgument:!1,build:()=>({type:`compact`}),targets:[`local`,`remote`]},{name:`cancel`,aliases:[],description:`Cancel the running turn`,takesArgument:!1,build:()=>({type:`cancel`}),targets:[`local`,`remote`]},{name:`login`,aliases:[],description:`Connect a model provider`,takesArgument:!1,build:()=>({type:`extension`,name:`login`,argument:``}),targets:[`local`]},{name:`add`,aliases:[],description:`Add an integration from the registry`,takesArgument:!0,build:e=>({type:`extension`,name:`add`,argument:e}),targets:[`local`]},{name:`deploy`,aliases:[],description:`Deploy the agent to Vercel`,takesArgument:!1,build:()=>({type:`extension`,name:`deploy`,argument:``}),targets:[`local`]},{name:`traces`,aliases:[],description:`Open the local trace viewer`,argumentHint:`[trace]`,takesArgument:!0,build:e=>({type:`traces`,argument:e}),targets:[`local`]},{name:`loglevel`,aliases:[],description:`Show or hide captured stdout/stderr/sandbox logs`,argumentHint:`[all|stderr|sandbox|none]`,takesArgument:!0,build:e=>({type:`loglevel`,argument:e}),targets:[`local`,`remote`]},{name:`info`,aliases:[],description:`Show application and messaging information`,takesArgument:!1,build:()=>({type:`info`}),targets:[`local`]},{name:`help`,aliases:[],description:`Show available commands`,takesArgument:!1,build:()=>({type:`help`}),targets:[`local`,`remote`]},{name:`exit`,aliases:[`quit`],description:`Quit the TUI`,takesArgument:!1,build:()=>({type:`exit`}),targets:[`local`,`remote`]}],PROMPT_COMMANDS=PROMPT_COMMAND_DEFINITIONS;function promptCommandsFor(e){let t=PROMPT_COMMAND_DEFINITIONS.filter(t=>t.targets.some(t=>t===e));return e===`remote`?[...t.filter(e=>e.name===`help`),...t.filter(e=>e.name!==`help`)]:t}function isPromptCommandAvailableFor(e,t){return(PROMPT_COMMAND_DEFINITIONS.find(t=>t.name===e)?.targets)?.includes(t)??!1}function parsePromptCommand(e){let t=e.trim();if(!t.startsWith(`/`))return null;for(let e of PROMPT_COMMANDS)for(let n of[e.name,...e.aliases]){let r=`/${n}`;if(t===r)return e.build(``);if(e.takesArgument&&t.startsWith(`${r} `))return e.build(t.slice(r.length).trim())}return null}function isPromptControlCommand(e){return parsePromptCommand(e)!==null}function formatPromptCommandHelp(e=PROMPT_COMMANDS){let t=e.map(e=>{let t=e.argumentHint===void 0?``:` ${e.argumentHint}`,n=e.aliases.map(e=>` (/${e})`).join(``);return{invocation:`/${e.name}${t}${n}`,description:e.description}}),n=Math.max(...t.map(e=>e.invocation.length))+2;return t.map(e=>e.invocation.padEnd(n)+e.description).join(`
|
|
2
2
|
`)}export{PROMPT_COMMANDS,formatPromptCommandHelp,isPromptCommandAvailableFor,isPromptControlCommand,parsePromptCommand,promptCommandsFor};
|
|
@@ -1,3 +1,3 @@
|
|
|
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{inspectApplication}from"#services/inspect-application.js";import{devBootPhase}from"#internal/dev-boot-progress.js";import{toErrorMessage}from"#shared/errors.js";import{getVercelAuthStatus}from"#setup/vercel-project.js";import{probeAgentInfo}from"#services/dev-client/agent-info-probe.js";import{SteeringStream}from"#cli/dev/tui/steering-stream.js";import{renderApplicationInfo}from"#cli/commands/info.js";import{subscribeDevelopmentSandboxPrewarmLogs}from"#execution/sandbox/development-prewarm.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;#Z;constructor(e){this.#e=e.session,e.client!==void 0&&(this.#t=e.client),e.lifecycle!==void 0&&(this.#Z=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#Q(){if(this.#f===void 0){this.#te(),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.#te();let t=this.#ee(e);this.#_||await this.#he(t)}#$(){let e=this.#h?.finish();return this.#g=e?.queuedPrompt,e?.draft??this.#m}#ee(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}#te(){let e=this.#A;this.#A=void 0,e?.({type:`before-first-paint`})}async run(){let onStop=()=>this.#n.requestInterrupt?.();this.#Z?.signal.aborted===!0?onStop():this.#Z?.signal.addEventListener(`abort`,onStop,{once:!0});try{await this.#ne()}finally{this.#Z?.signal.removeEventListener(`abort`,onStop),this.#j=!0,this.#M.abort(),this.#K.abortAll(),this.#X?.(),this.#X=void 0,this.#n.shutdown?.(),this.#R?.dispose(),this.#z?.dispose(),this.#T?.dispose()}}async#ne(){let e=this.#r,t,n,r=!1,i=!1,a=!1;this.#n.setStartupPhase?.(`starting`),await this.#Q(),this.#ye(),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.#Z?.signal,runAuthFlow:this.#E});if(e?.kind===`authenticated`){let e=this.#T.current().connection;e.state===`ready`&&this.#ee(e.info)}else e?.kind===`failed`||e?.kind===`unavailable`?s={tone:`error`,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.#Te(e));let c=this.#$();for(s?.cancelled||s?.tone===`error`?c=[this.#g,c].filter(Boolean).join(`
|
|
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{inspectApplication}from"#services/inspect-application.js";import{devBootPhase}from"#internal/dev-boot-progress.js";import{toErrorMessage}from"#shared/errors.js";import{getVercelAuthStatus}from"#setup/vercel-project.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{subscribeDevelopmentSandboxPrewarmLogs}from"#execution/sandbox/development-prewarm.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;#Z;constructor(e){this.#e=e.session,e.client!==void 0&&(this.#t=e.client),e.lifecycle!==void 0&&(this.#Z=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#Q(){if(this.#f===void 0){this.#te(),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.#te();let t=this.#ee(e);this.#_||await this.#he(t)}#$(){let e=this.#h?.finish();return this.#g=e?.queuedPrompt,e?.draft??this.#m}#ee(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}#te(){let e=this.#A;this.#A=void 0,e?.({type:`before-first-paint`})}async run(){let onStop=()=>this.#n.requestInterrupt?.();this.#Z?.signal.aborted===!0?onStop():this.#Z?.signal.addEventListener(`abort`,onStop,{once:!0});try{await this.#ne()}finally{this.#Z?.signal.removeEventListener(`abort`,onStop),this.#j=!0,this.#M.abort(),this.#K.abortAll(),this.#X?.(),this.#X=void 0,this.#n.shutdown?.(),this.#R?.dispose(),this.#z?.dispose(),this.#T?.dispose()}}async#ne(){let e=this.#r,t,n,r=!1,i=!1,a=!1;this.#n.setStartupPhase?.(`starting`),await this.#Q(),this.#ye(),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.#Z?.signal,runAuthFlow:this.#E});if(e?.kind===`authenticated`){let e=this.#T.current().connection;e.state===`ready`&&this.#ee(e.info)}else e?.kind===`failed`||e?.kind===`unavailable`?s={tone:`error`,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.#Te(e));let c=this.#$();for(s?.cancelled||s?.tone===`error`?c=[this.#g,c].filter(Boolean).join(`
|
|
2
2
|
|
|
3
|
-
`)||void 0:t=this.#g,this.#x=!1,this.#ee(this.#B),this.#ge(),this.#n.setStartupPhase?.(void 0),(!o||s?.cancelled||s?.tone===`error`)&&this.#be(s?.message,s?.tone);;){if(this.#Z?.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.#Z?.requestStop();return}if(o?.type===`cancel`){if(this.#e===void 0){this.#be(`No active turn to cancel.`),n=void 0,i=!1,a=!1,t=void 0;continue}try{let e=await this.#e.cancel();if(this.#be(e.status===`accepted`?`Turn cancellation requested.`:`No active turn to cancel.`),e.status===`no_active_turn`){n=void 0,i=!1,a=!1,t=void 0;continue}}catch(e){this.#be(`Couldn't cancel the turn: ${toErrorMessage(e)}`),n=void 0,i=!1,a=!1,t=void 0;continue}n=void 0,i=!0,a=!1,t=void 0}if(o?.type===`reset`){if(!await this.#ae()){n=void 0,a=!1,t=void 0;continue}n=void 0,a=!1,t=void 0;continue}if(o?.type===`compact`){if(this.#e===void 0){this.#be(`No active session to compact.`),n=void 0,i=!1,a=!1,t=void 0;continue}try{let e=await this.#e.compact();if(this.#be(e.status===`accepted`?`Compaction requested.`:`No active session to compact.`),e.status===`no_active_session`){n=void 0,i=!1,a=!1,t=void 0;continue}}catch(e){this.#be(`Couldn't compact the session: ${toErrorMessage(e)}`),n=void 0,i=!1,a=!1,t=void 0;continue}n=void 0,i=!0,a=!1,t=void 0}if(o?.type===`clear`){if(this.#e===void 0){this.#be(`No active session to clear.`),n=void 0,i=!1,a=!1,t=void 0;continue}try{let e=await this.#e.clear();if(this.#be(e.status===`accepted`?`Context clear requested.`:`No active session to clear.`),e.status===`no_active_session`){n=void 0,i=!1,a=!1,t=void 0;continue}}catch(e){this.#be(`Couldn't clear the session: ${toErrorMessage(e)}`),n=void 0,i=!1,a=!1,t=void 0;continue}n=void 0,i=!0,a=!1,t=void 0}if(o?.type===`help`){this.#be(formatPromptCommandHelp(this.#C)),n=void 0,a=!1,t=void 0;continue}if(o?.type===`info`){await this.#Oe(),n=void 0,a=!1,t=void 0;continue}if(o?.type===`loglevel`){this.#be(this.#ke(o.argument)),n=void 0,a=!1,t=void 0;continue}if(o?.type===`traces`){await this.#De(o.argument),n=void 0,a=!1,t=void 0;continue}if(o?.type===`extension`){try{await this.#we(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.#ie(),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.#Fe(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.#ie(l.turnState?.aborted===!0)}}#re(){this.#K.abortAll(),this.#V.clear(),this.#q.clear(),this.#J.clear(),this.#n.setConnectionAuthPendingCount?.(0),this.#e=void 0,this.#d?.clear()}#ie(e=!1){let t=this.#Y;t!==void 0&&(this.#Y=void 0,this.#e===t&&(this.#re(),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#ae(){if(this.#e===void 0)return this.#re(),this.#n.reset?.(),!0;try{await this.#e.reset()}catch(e){return this.#n.renderNotice?.(`Couldn't reset the session: ${toErrorMessage(e)}`),!1}return this.#re(),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.#Ne()}),this.#p!==void 0&&this.#B===void 0&&!o&&(o=!0,this.#je().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.#je())}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.#Fe(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.#Ne()}),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.#Pe(e),onConnectionAuthCompleted:e=>this.#Ie(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){await this.#we({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(){this.#p!==void 0&&this.#n.renderSandboxLog!==void 0&&this.#X===void 0&&(this.#X=subscribeDevelopmentSandboxPrewarmLogs({appRoot:this.#p,log:e=>this.#n.renderSandboxLog?.(e)}))}#be(e,t){if(e!==void 0){if(this.#n.renderCommandResult!==void 0){this.#n.renderCommandResult(e,t);return}this.#n.renderNotice?.(e)}}async#xe(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.#Ce(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#Se(e){if(e?.kind===`model-access-changed`){this.#R?.applyEffect({kind:`refresh-identity`}),this.#N=!0,await this.#Ae(e);return}e!==void 0&&(this.#R?.applyEffect(e),this.#N=!0,this.#ve(this.#B))}async#Ce(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.#Se(e.effect);let{effect:t,...n}=e;return n}catch{return{tone:`error`,message:`Settings were saved, but the agent could not reload. Retry the command or restart eve dev.`}}finally{clearTimeout(t)}}async#we(e,t,n){let r=await this.#xe(e,{...n,title:t}),i=r===void 0?void 0:await this.#Ce(r);return!(n.suppressSuccessfulTranscript===!0&&i?.tone!==`error`||n.suppressCancelledTranscript===!0&&i?.cancelled===!0)&&n.trigger!==`startup`&&this.#be(i?.message,i?.tone),this.#Ee(),i}async#Te(e){this.#y?.({flow:`onboarding`,step:`model_provider`});let t=await this.#we({type:`extension`,name:`login`,argument:``},e,{trigger:`startup`,initialModelStep:`provider`});return!t?.cancelled&&t?.tone!==`error`&&this.#y?.({flow:`onboarding`,step:`connection_ready`}),this.#b?.({flow:`onboarding`,step:`model_provider`,result:t?.cancelled?`cancelled`:t?.tone===`error`?`error`:`completed`}),t}#Ee(){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#De(e){if(this.#p===void 0||this.#n.traceViewer===void 0){this.#be(`/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}}async#Oe(){let e=this.#p;if(e===void 0){this.#be(`/info is only available in local dev sessions.`);return}try{this.#be(renderApplicationInfo(await this.#k(e)))}catch(e){this.#be(`Couldn't inspect the application: ${toErrorMessage(e)}`,`error`)}}#ke(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#Ae(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.#ee({...this.#B,agent:{...this.#B.agent,model:{...this.#B.agent.model,...e.model}}}):this.#ee(this.#B),this.#I=[],this.#L=void 0,this.#ge(),this.#je())}async#je(e=!1){let t=this.#B,n=++this.#F,r=await this.#Me();this.#j||n!==this.#F||r===void 0||(this.#ee(r),e&&!this.#n.renderAgentHeader&&this.#n.renderNotice?.(formatAgentUpdateNotice(t,r)),this.#ve(this.#B))}async#Me(){let e=this.#t;if(e===void 0)return;let t=await probeAgentInfo({client:e});return t.kind===`ready`?t.info:void 0}#Ne(){this.#je(!0)}#Pe(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.#Le(t)}#Fe(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.#Le(e),t=!0);return t&&this.#n.setConnectionAuthPendingCount?.(this.#J.size),this.#J.size>0}#Ie(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.#Le(t),this.#n.setConnectionAuthPendingCount?.(this.#J.size)}#Le(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,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;if(e.data.result.kind!==`tool-result`)break;let t=e.data.result.callId;if(!v.has(t))break;switch(e.data.status){case`completed`:{let n=e.data.result.output;yield{type:`tool-result`,toolCallId:t,output:n};let r=registryHandoffAddress(void 0,h.get(t),n);r!==void 0&&await u?.(r);break}case`failed`:yield{type:`tool-error`,toolCallId:t,errorText:formatActionResultError(e)};break;case`rejected`:yield{type:`tool-rejected`,toolCallId:t,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.#ee(this.#B),this.#ge(),this.#n.setStartupPhase?.(void 0),(!o||s?.cancelled||s?.tone===`error`)&&this.#be(s?.message,s?.tone);;){if(this.#Z?.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.#Z?.requestStop();return}if(o?.type===`cancel`){if(this.#e===void 0){this.#be(`No active turn to cancel.`),n=void 0,i=!1,a=!1,t=void 0;continue}try{let e=await this.#e.cancel();if(this.#be(e.status===`accepted`?`Turn cancellation requested.`:`No active turn to cancel.`),e.status===`no_active_turn`){n=void 0,i=!1,a=!1,t=void 0;continue}}catch(e){this.#be(`Couldn't cancel the turn: ${toErrorMessage(e)}`),n=void 0,i=!1,a=!1,t=void 0;continue}n=void 0,i=!0,a=!1,t=void 0}if(o?.type===`reset`){if(!await this.#ae()){n=void 0,a=!1,t=void 0;continue}n=void 0,a=!1,t=void 0;continue}if(o?.type===`compact`){if(this.#e===void 0){this.#be(`No active session to compact.`),n=void 0,i=!1,a=!1,t=void 0;continue}try{let e=await this.#e.compact();if(this.#be(e.status===`accepted`?`Compaction requested.`:`No active session to compact.`),e.status===`no_active_session`){n=void 0,i=!1,a=!1,t=void 0;continue}}catch(e){this.#be(`Couldn't compact the session: ${toErrorMessage(e)}`),n=void 0,i=!1,a=!1,t=void 0;continue}n=void 0,i=!0,a=!1,t=void 0}if(o?.type===`clear`){if(this.#e===void 0){this.#be(`No active session to clear.`),n=void 0,i=!1,a=!1,t=void 0;continue}try{let e=await this.#e.clear();if(this.#be(e.status===`accepted`?`Context clear requested.`:`No active session to clear.`),e.status===`no_active_session`){n=void 0,i=!1,a=!1,t=void 0;continue}}catch(e){this.#be(`Couldn't clear the session: ${toErrorMessage(e)}`),n=void 0,i=!1,a=!1,t=void 0;continue}n=void 0,i=!0,a=!1,t=void 0}if(o?.type===`help`){this.#be(formatPromptCommandHelp(this.#C)),n=void 0,a=!1,t=void 0;continue}if(o?.type===`info`){await this.#Oe(),n=void 0,a=!1,t=void 0;continue}if(o?.type===`loglevel`){this.#be(this.#ke(o.argument)),n=void 0,a=!1,t=void 0;continue}if(o?.type===`traces`){await this.#De(o.argument),n=void 0,a=!1,t=void 0;continue}if(o?.type===`extension`){try{await this.#we(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.#ie(),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.#Fe(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.#ie(l.turnState?.aborted===!0)}}#re(){this.#K.abortAll(),this.#V.clear(),this.#q.clear(),this.#J.clear(),this.#n.setConnectionAuthPendingCount?.(0),this.#e=void 0,this.#d?.clear()}#ie(e=!1){let t=this.#Y;t!==void 0&&(this.#Y=void 0,this.#e===t&&(this.#re(),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#ae(){if(this.#e===void 0)return this.#re(),this.#n.reset?.(),!0;try{await this.#e.reset()}catch(e){return this.#n.renderNotice?.(`Couldn't reset the session: ${toErrorMessage(e)}`),!1}return this.#re(),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.#Ne()}),this.#p!==void 0&&this.#B===void 0&&!o&&(o=!0,this.#je().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.#je())}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.#Fe(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.#Ne()}),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.#Pe(e),onConnectionAuthCompleted:e=>this.#Ie(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){await this.#we({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(){this.#p!==void 0&&this.#n.renderSandboxLog!==void 0&&this.#X===void 0&&(this.#X=subscribeDevelopmentSandboxPrewarmLogs({appRoot:this.#p,log:e=>this.#n.renderSandboxLog?.(e)}))}#be(e,t){if(e!==void 0){if(this.#n.renderCommandResult!==void 0){this.#n.renderCommandResult(e,t);return}this.#n.renderNotice?.(e)}}async#xe(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.#Ce(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#Se(e){if(e?.kind===`model-access-changed`){this.#R?.applyEffect({kind:`refresh-identity`}),this.#N=!0,await this.#Ae(e);return}e!==void 0&&(this.#R?.applyEffect(e),this.#N=!0,this.#ve(this.#B))}async#Ce(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.#Se(e.effect);let{effect:t,...n}=e;return n}catch{return{tone:`error`,message:`Settings were saved, but the agent could not reload. Retry the command or restart eve dev.`}}finally{clearTimeout(t)}}async#we(e,t,n){let r=await this.#xe(e,{...n,title:t}),i=r===void 0?void 0:await this.#Ce(r);return!(n.suppressSuccessfulTranscript===!0&&i?.tone!==`error`||n.suppressCancelledTranscript===!0&&i?.cancelled===!0)&&n.trigger!==`startup`&&this.#be(i?.message,i?.tone),this.#Ee(),i}async#Te(e){this.#y?.({flow:`onboarding`,step:`model_provider`});let t=await this.#we({type:`extension`,name:`login`,argument:``},e,{trigger:`startup`,initialModelStep:`provider`});return!t?.cancelled&&t?.tone!==`error`&&this.#y?.({flow:`onboarding`,step:`connection_ready`}),this.#b?.({flow:`onboarding`,step:`model_provider`,result:t?.cancelled?`cancelled`:t?.tone===`error`?`error`:`completed`}),t}#Ee(){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#De(e){if(this.#p===void 0||this.#n.traceViewer===void 0){this.#be(`/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}}async#Oe(){let e=this.#p;if(e===void 0){this.#be(`/info is only available in local dev sessions.`);return}try{this.#be(renderApplicationInfo(await this.#k(e)))}catch(e){this.#be(`Couldn't inspect the application: ${toErrorMessage(e)}`,`error`)}}#ke(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#Ae(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.#ee({...this.#B,agent:{...this.#B.agent,model:{...this.#B.agent.model,...e.model}}}):this.#ee(this.#B),this.#I=[],this.#L=void 0,this.#ge(),this.#je())}async#je(e=!1){let t=this.#B,n=++this.#F,r=await this.#Me();this.#j||n!==this.#F||r===void 0||(this.#ee(r),e&&!this.#n.renderAgentHeader&&this.#n.renderNotice?.(formatAgentUpdateNotice(t,r)),this.#ve(this.#B))}async#Me(){let e=this.#t;if(e===void 0)return;let t=await probeAgentInfo({client:e});return t.kind===`ready`?t.info:void 0}#Ne(){this.#je(!0)}#Pe(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.#Le(t)}#Fe(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.#Le(e),t=!0);return t&&this.#n.setConnectionAuthPendingCount?.(this.#J.size),this.#J.size>0}#Ie(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.#Le(t),this.#n.setConnectionAuthPendingCount?.(this.#J.size)}#Le(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,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};
|
|
@@ -33,7 +33,7 @@ export declare const SETUP_FLOW_CONFIG: {
|
|
|
33
33
|
indicator: "spinner";
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
export type TuiSetupCommandRenderer = TuiPrompterRenderer & Pick<SetupFlowRenderer, "readProviderPicker" | "
|
|
36
|
+
export type TuiSetupCommandRenderer = TuiPrompterRenderer & Pick<SetupFlowRenderer, "readProviderPicker" | "readModelPicker" | "setNavigation" | "waitForInterrupt">;
|
|
37
37
|
export type OnboardingScreenEvent = {
|
|
38
38
|
screen: "model_provider" | "model_settings" | "registry_channels" | "registry_integrations" | "registry_review" | "registry_install";
|
|
39
39
|
registrySelectedCount?: number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{formatRegistrySessionResult,registryItemProgress,registryResultTone}from"./registry-result-message.js";import{createTuiPrompter}from"./tui-prompter.js";import{runDeployFlow}from"#setup/flows/deploy.js";import{WizardCancelledError}from"#setup/step.js";import{runModelLogin}from"#setup/flows/model-login.js";import{HumanActionRequiredError}from"#setup/human-action.js";import{runInstallVercelCliFlow}from"#setup/flows/install-vercel-cli.js";import{runModelFlow}from"#setup/flows/model.js";import{RegistryFlowFailedError,runRegistryFlow}from"#setup/flows/registry.js";const SETUP_FLOW_CONFIG={login:{title:`Connecting your model`,indicator:`pulse`},model:{title:`Configure the agent model`,indicator:`pulse`},add:{title:`Add to your agent`,indicator:`pulse`},deploy:{title:`Deploy to Vercel`,indicator:`spinner`}};function muteableRenderer(e,t,n){return{readSelect:n=>t()?Promise.resolve(void 0):e.readSelect(n),readEditableSelect:n=>t()?Promise.resolve(void 0):e.readEditableSelect(n),readProviderPicker:n=>t()?Promise.resolve(void 0):e.readProviderPicker(n),
|
|
1
|
+
import{formatRegistrySessionResult,registryItemProgress,registryResultTone}from"./registry-result-message.js";import{createTuiPrompter}from"./tui-prompter.js";import{runDeployFlow}from"#setup/flows/deploy.js";import{WizardCancelledError}from"#setup/step.js";import{runModelLogin}from"#setup/flows/model-login.js";import{HumanActionRequiredError}from"#setup/human-action.js";import{runInstallVercelCliFlow}from"#setup/flows/install-vercel-cli.js";import{runModelFlow}from"#setup/flows/model.js";import{RegistryFlowFailedError,runRegistryFlow}from"#setup/flows/registry.js";const SETUP_FLOW_CONFIG={login:{title:`Connecting your model`,indicator:`pulse`},model:{title:`Configure the agent model`,indicator:`pulse`},add:{title:`Add to your agent`,indicator:`pulse`},deploy:{title:`Deploy to Vercel`,indicator:`spinner`}};function muteableRenderer(e,t,n){return{readSelect:n=>t()?Promise.resolve(void 0):e.readSelect(n),readEditableSelect:n=>t()?Promise.resolve(void 0):e.readEditableSelect(n),readProviderPicker:n=>t()?Promise.resolve(void 0):e.readProviderPicker(n),readModelPicker:n=>t()?Promise.resolve(void 0):e.readModelPicker(n),readText:n=>t()?Promise.resolve(void 0):e.readText(n),readAcknowledge:n=>t()?Promise.resolve():e.readAcknowledge(n),readChoice:n=>t()?{choice:Promise.resolve(void 0),close:()=>{}}:e.readChoice(n),setNavigation:n=>{t()||e.setNavigation?.(n)},setStatus:n=>{t()||e.setStatus(n)},renderLine:(n,r)=>{(!t()||r===`warning`||r===`error`)&&e.renderLine(n,r)},replaceContent:n=>{t()||e.replaceContent?.(n)},renderOutput:n=>{t()||e.renderOutput(n)},withInheritedStdio:t=>e.withInheritedStdio(t),withExclusiveTerminal:e=>n?.(e)??e()}}function cancelledSetupResult(){return{message:``,cancelled:!0,preserveFlowDiagnostics:!1}}async function runTuiSetupCommand(e){let{command:t}=e,n=!1,r=new AbortController,i=muteableRenderer(e.renderer,()=>n,e.withExclusiveTerminal),a=(e.createPrompter??createTuiPrompter)(i),cancelActiveRegistryItem,runRegistryItem=async e=>{let t=new AbortController;cancelActiveRegistryItem=()=>t.abort(new WizardCancelledError);try{return await e(AbortSignal.any([r.signal,t.signal]))}finally{cancelActiveRegistryItem=void 0}},o=e.renderer.waitForInterrupt(),s=executeSetupCommand(e,a,i,r.signal,runRegistryItem),c=s.then(e=>({kind:`outcome`,value:e}));try{for(;;){let i=!1;try{let e=await Promise.race([c,o.promise.then(e=>({kind:`interrupt`,interrupt:e}))]);if(e.kind===`outcome`)return e.value;if(t===`add`&&e.interrupt===`escape`&&cancelActiveRegistryItem!==void 0)cancelActiveRegistryItem(),i=!0;else{n=!0,r.abort(new WizardCancelledError);let e=await s;return e.partial===!0?e:{...e,...cancelledSetupResult(),tone:void 0}}}finally{o.dispose()}i&&(o=e.renderer.waitForInterrupt())}}finally{e.renderer.setStatus(void 0)}}async function executeSetupCommand(e,t,n,r,i){let{command:a,appRoot:o}=e,s={runInstallVercelCliFlow,runModelFlow,runRegistryFlow,runDeployFlow,...e.flows};try{switch(a){case`login`:{let n=await(s.runModelLogin??runModelLogin)({appRoot:o,agentRoot:e.agentRoot,prompter:t,signal:r,automatic:e.initialModelStep===`provider`,withConnectionUpdate:e.withExclusiveTerminal});return n.kind===`cancelled`?{message:`Connect a model with /login when you’re ready.`,cancelled:!0,preserveFlowDiagnostics:!1}:{message:`Connected. Start chatting · /add to extend your agent`,effect:{kind:`model-access-changed`,reload:n.reload,...n.model&&{model:n.model}},preserveFlowDiagnostics:!1}}case`model`:{let i={appRoot:e.agentRoot??o,environmentRoot:o,prompter:t,signal:r,chatGptAccountLabel:e.chatGptAccountLabel,deps:{pickModelSettings:e=>n.readModelPicker(e)}};e.initialModelStep!==void 0&&(i.initialStep=e.initialModelStep),e.onOnboardingScreen!==void 0&&(i.onScreen=t=>e.onOnboardingScreen?.({screen:t}));let a=await s.runModelFlow(i);if(a.kind===`cancelled`)return cancelledSetupResult();let c=[];a.modelMessage!==void 0&&c.push(a.modelMessage),a.providerSelection!==void 0&&c.push(providerSelectionMessage(a.providerSelection));let l={message:c.join(`
|
|
2
2
|
`),preserveFlowDiagnostics:!1};return a.accessChanged&&(l.effect={kind:`model-access-changed`,reload:!0}),l}case`add`:{let a=await s.runRegistryFlow({appRoot:o,installRoot:e.agentRoot,prompter:t,signal:r,initialAddress:e.initialRegistryAddress,onScreen:e.onOnboardingScreen,onItemStart:registryItemProgress(n),runItem:i});if(a.kind===`cancelled`)return cancelledSetupResult();let c=a.result,l=registryResultTone(c),u=c.items.length>0||c.failures.length>0||c.outcomes!==void 0?formatRegistrySessionResult(c):`No integrations selected.`,d={message:l===`error`?`/add failed — ${u}`:u,preserveFlowDiagnostics:!0};return c.cancelled===!0?(d.partial=!0,d.tone=`error`):l!==void 0&&(d.tone=l),c.deployed===`production`&&(d.effect={kind:`deployed`}),d}case`deploy`:{let e=await s.runDeployFlow({appRoot:o,prompter:t,interactive:!0,signal:r});return e.kind===`cancelled`?cancelledSetupResult():e.kind===`needs-link`?{message:`Not linked to a Vercel project. Run eve deploy in an interactive terminal to link it.`,preserveFlowDiagnostics:!0}:e.kind===`local-model`?{message:`ChatGPT subscription models are local-only. Switch to an AI Gateway or server-authenticated model before deploying.`,preserveFlowDiagnostics:!0}:{message:e.productionUrl===void 0?`Deployed.`:`Deployed: ${e.productionUrl}`,preserveFlowDiagnostics:!0,effect:{kind:`deployed`}}}}}catch(e){if(e instanceof WizardCancelledError)return cancelledSetupResult();let n=e instanceof RegistryFlowFailedError?e.cause:e,i=await vercelCliUpgradeOutcome(n,a,s,{appRoot:o,prompter:t,signal:r});if(i!==void 0)return withRegistryResults(i,e);let c=vercelActionOutcome(n,a);return c===void 0?e instanceof RegistryFlowFailedError?{message:`${formatRegistrySessionResult(e.completed)}\n\n${e.message}`,partial:!0,tone:`error`,preserveFlowDiagnostics:!0}:{message:`/${a} failed: ${e instanceof Error?e.message:String(e)}`,tone:`error`,preserveFlowDiagnostics:!0}:withRegistryResults(c,e)}}function withRegistryResults(e,t){return t instanceof RegistryFlowFailedError?{...e,message:`${formatRegistrySessionResult(t.completed)}\n\n${e.message}`,partial:!0,tone:`error`,preserveFlowDiagnostics:!0}:e}async function vercelCliUpgradeOutcome(e,t,n,r){if(!(e instanceof HumanActionRequiredError)||e.action.kind!==`vercel-cli-upgrade`)return;let i;try{i=await r.prompter.select({message:`Your Vercel CLI needs an update to list your teams. Upgrade now?`,options:[{value:`upgrade`,label:`Upgrade Vercel CLI`,description:`Run the Vercel CLI's native upgrader`},{value:`later`,label:`Not now`}],initialValue:`upgrade`})}catch{i=`later`}if(i===`later`)return{message:`The Vercel CLI needs an update — run \`vercel upgrade\`, then retry /${t}.`,tone:`error`,preserveFlowDiagnostics:!0};let a;try{a=await n.runInstallVercelCliFlow({appRoot:r.appRoot,prompter:r.prompter,signal:r.signal,upgrade:!0})}catch(e){return{message:vercelCliUpgradeFailureMessage(t,errorMessage(e)),tone:`error`,preserveFlowDiagnostics:!0}}switch(a.kind){case`installed`:return{message:`Upgraded the Vercel CLI. Retry /${t}.`,tone:`error`,preserveFlowDiagnostics:!1};case`failed`:return{message:vercelCliUpgradeFailureMessage(t,a.reason),tone:`error`,preserveFlowDiagnostics:!0};case`cancelled`:return{message:`Vercel CLI upgrade cancelled — run \`vercel upgrade\`, then retry /${t}.`,tone:`error`,preserveFlowDiagnostics:!0};case`already`:return{message:`The Vercel CLI is already up to date. Retry /${t}.`,tone:`error`,preserveFlowDiagnostics:!1}}}function errorMessage(e){let t=(e instanceof Error?e.message:String(e)).replace(/\s+/gu,` `).trim();return t.length<=240?t:`${t.slice(0,239)}…`}function vercelCliUpgradeFailureMessage(e,t){return`Couldn't upgrade the Vercel CLI${t===void 0||t===``?``:` (${t})`} — run \`vercel upgrade\`, then retry /${e}.`}function vercelActionOutcome(e,t){if(!(e instanceof HumanActionRequiredError))return;let n=vercelActionMessage(e.action.kind,t);return n===void 0?void 0:{message:n,tone:`error`,preserveFlowDiagnostics:!0}}function vercelActionMessage(e,t){switch(e){case`vercel-login`:return`You're not logged in to Vercel — run /deploy to connect your Vercel account, then retry /${t}.`;case`vercel-forbidden`:return`Vercel denied access to that team — check your team access and SSO, then retry /${t}.`;case`vercel-cli-missing`:return`The Vercel CLI isn't installed — run /deploy to install it, then retry /${t}.`;case`vercel-cli-upgrade`:return`The Vercel CLI needs an update — run \`vercel upgrade\`, then retry /${t}.`;default:return}}function providerSelectionMessage(e){return e===`chatgpt`?`ChatGPT subscription selected.`:e===`ai-gateway-project`?`AI Gateway via Project selected.`:`AI Gateway via API key selected.`}export{SETUP_FLOW_CONFIG,runTuiSetupCommand};
|
|
@@ -87,8 +87,8 @@ export interface SetupFlowRenderer {
|
|
|
87
87
|
}): Promise<SetupEditableSelectResult | undefined>;
|
|
88
88
|
/** Provider-only picker with masked async validation. Not part of Prompter. */
|
|
89
89
|
readProviderPicker(options: ProviderPickerRequest): Promise<ProviderPickerChoice | undefined>;
|
|
90
|
-
/**
|
|
91
|
-
|
|
90
|
+
/** Model, speed, and reasoning picker. Not part of Prompter. */
|
|
91
|
+
readModelPicker(options: ModelSettingsRequest): Promise<ModelSettingsResult | undefined>;
|
|
92
92
|
readText(options: {
|
|
93
93
|
message: string;
|
|
94
94
|
placeholder?: string;
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
import type { ChannelSetupAction, PromptOption } from "#setup/cli/index.js";
|
|
3
3
|
import { type SearchActionOption, type SelectState } from "#setup/cli/select-state.js";
|
|
4
4
|
import type { PlannerNavigation, SelectMetadata, SelectNotice } from "#setup/prompter.js";
|
|
5
|
-
import type { ModelSettingsRequest } from "#setup/flows/model.js";
|
|
6
|
-
import { type ModelEditorState } from "./model-editor.js";
|
|
7
5
|
import type { ProviderPickerPhase } from "./provider-picker.js";
|
|
8
6
|
import { type LineState } from "./line-editor.js";
|
|
9
7
|
import type { Theme } from "./theme.js";
|
|
@@ -29,6 +27,7 @@ interface SetupSelectPanelBase extends SetupQuestionPanelBase {
|
|
|
29
27
|
loadingFrame?: string;
|
|
30
28
|
/** A dim-inverse affordance appended to the cursor row, e.g. ` ↵ change `. */
|
|
31
29
|
cursorBadge?: string;
|
|
30
|
+
footerHints?: readonly string[];
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
33
|
* A menu row that turns into an inline editor while the cursor rests on it.
|
|
@@ -170,35 +169,11 @@ export declare function renderFlowPanel(state: FlowPanelState, theme: Theme, wid
|
|
|
170
169
|
* the cursor and advertises the rest with a count footer.
|
|
171
170
|
*/
|
|
172
171
|
export declare function renderSelectQuestion(state: SetupSelectPanelState, theme: Theme, width: number): string[];
|
|
173
|
-
/** The composite Change-model screen's inputs: the resolved request plus live state. */
|
|
174
|
-
export interface ModelEditorPanelInput {
|
|
175
|
-
request: ModelSettingsRequest;
|
|
176
|
-
state: ModelEditorState;
|
|
177
|
-
}
|
|
178
172
|
/**
|
|
179
173
|
* A dim, background-free selection badge carrying the Enter affordance, e.g.
|
|
180
174
|
* `↵`, `↵ change`, `↵ validate`.
|
|
181
175
|
*/
|
|
182
176
|
export declare function enterBadge(theme: Theme, label?: string): string;
|
|
183
|
-
/**
|
|
184
|
-
* A discrete reasoning track: `●` below the current notch, `◉` on it, `○`
|
|
185
|
-
* above, joined by `─` connectors. `accent` paints the covered stretch —
|
|
186
|
-
* notches and connectors up to the current position — blue. `index` -1 means
|
|
187
|
-
* unset: an all-`○` track with no fill.
|
|
188
|
-
*/
|
|
189
|
-
export declare function reasoningTrack(input: {
|
|
190
|
-
count: number;
|
|
191
|
-
index: number;
|
|
192
|
-
connectorWidth: number;
|
|
193
|
-
accent: boolean;
|
|
194
|
-
theme: Theme;
|
|
195
|
-
}): string;
|
|
196
|
-
/**
|
|
197
|
-
* Paints the Change-model screen: a value menu whose reasoning and tier rows
|
|
198
|
-
* adjust inline with left/right, and whose Model row opens the searchable
|
|
199
|
-
* catalog.
|
|
200
|
-
*/
|
|
201
|
-
export declare function renderModelEditorQuestion(input: ModelEditorPanelInput, theme: Theme, width: number, message?: string): string[];
|
|
202
177
|
/** Paints a text question section: message, a block-cursor input line, hints. */
|
|
203
178
|
export declare function renderTextQuestion(state: SetupTextPanelState, theme: Theme, width: number, caretVisible: boolean): string[];
|
|
204
179
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{maskLine,visibleLine}from"./line-editor.js";import{
|
|
1
|
+
import{maskLine,visibleLine}from"./line-editor.js";import{clipVisible,renderInputText,renderInputWithBlockCursor,visibleLength,wrapVisibleLine}from"#cli/ui/terminal-text.js";import{renderCursorRow,renderOptionRow,resolveOptionRowState}from"#setup/cli/option-row.js";import{filterOptions,submitRowIndex}from"#setup/cli/select-state.js";function clip(e,t){return clipVisible(e,t)}function questionFooter(e,t,n){let r=t.colors,i=e.join(` ${t.glyph.dot} `);return[``,...(n===void 0?[i]:wrapVisibleLine(i,Math.max(1,n-3))).map(e=>` ${r.dim(e)}`)]}function solidWithinDim(e,t){return t.color?`[22m${e}[2m`:e}function toneGlyph(e,t){let n=t.colors;switch(e){case`success`:return n.green(t.glyph.success);case`warning`:return n.yellow(t.glyph.warning);case`error`:return n.red(t.glyph.error);case`info`:return n.dim(t.glyph.dot)}}function renderIndicator(e,t){return e.color===`green`?t.colors.green(e.glyph):t.colors.yellow(e.glyph)}function renderStatusText(e,t){if(e.kind===`progress`)return t.colors.dim(e.text);let n=e.text.indexOf(e.emphasis);if(n===-1)return t.colors.dim(e.text);let r=n+e.emphasis.length;return`${t.colors.dim(e.text.slice(0,n))}${t.colors.yellow(e.text.slice(n,r))}${t.colors.dim(e.text.slice(r))}`}function renderFlowPanelStatus(e,t){return`${renderIndicator(e.indicator,t)} ${renderStatusText(e,t)}`}function flowMessageRows(e,t){let n=t.colors,r=[],i=e.slice(-6);for(let e of i){let i=e.text.split(`
|
|
2
2
|
`);for(let[a,o]of i.entries()){let i=e.tone===`info`?n.dim(o):o,s=a===0?`${toneGlyph(e.tone,t)} `:` `;r.push(` ${s}${i}`)}}return i.length>0&&r.push(``),r}function renderFlowPanel(e,t,n){let r=t.colors,i=[],a=e.content.kind===`question`?e.content.title??e.title:e.title;if(a.length>0){for(let e of a.split(`
|
|
3
3
|
`)){if(e.length===0){i.push(``);continue}for(let t of wrapVisibleLine(e,Math.max(1,n-3)))i.push(` ${r.bold(t)}`)}i.push(``)}switch(e.navigation?.kind===`planner`&&i.push(...plannerStepRows(e.navigation,void 0,t)),i.push(...flowMessageRows(e.lines,t)),e.content.kind){case`question`:e.content.status!==void 0&&i.push(` ${renderFlowPanelStatus(e.content.status,t)}`,``),i.push(...e.content.rows);break;case`status`:if(i.push(` ${renderFlowPanelStatus(e.content.status,t)}`),e.content.preview!==void 0)for(let t of e.content.preview.split(`
|
|
4
4
|
`))i.push(` ${r.dim(t)}`);break;case`preview`:{let[n,...a]=e.content.text.split(`
|
|
5
5
|
`);i.push(` ${renderIndicator(e.content.indicator,t)} ${r.dim(n??``)}`);for(let e of a)i.push(` ${r.dim(e)}`);break}case`idle`:i.push(` ${renderIndicator(e.content.indicator,t)} ${r.dim(`Working…`)}`)}return i.map(e=>e.length===0?clip(e,n):clip(` ${e}`,n))}function optionRow(e){let{option:t,theme:n}=e,r=e.railed===!0;return renderOptionRow({colors:n.colors,glyphs:{pointer:n.glyph.pointer,selectedPointer:n.glyph.selectedPointer,success:n.glyph.success,placeholder:n.glyph.option,dot:r?``:n.glyph.dot,warning:n.glyph.warning},label:t.label,hint:t.hint,focusHint:t.focusHint,accent:t.accent,isCursor:e.isCursor,state:resolveOptionRowState(t,e.isChecked),placeholder:e.placeholder,hintPadding:e.hintPadding})}function selectPresentation(e){switch(e.kind){case`single`:return{selection:`single`,filter:void 0,layout:`plain`,edit:void 0};case`search`:return{selection:`single`,filter:{placeholder:e.placeholder},layout:e.layout??`plain`,edit:void 0};case`multi`:return{selection:`multiple`,filter:void 0,layout:`plain`,edit:void 0};case`searchable-multi`:return{selection:`multiple`,filter:{placeholder:e.placeholder},layout:e.layout??`plain`,edit:void 0};case`stacked`:return{selection:`single`,filter:void 0,layout:`stacked`,edit:void 0};case`task-list`:return{selection:`single`,filter:void 0,layout:`task-list`,edit:void 0};case`inline-edit`:return{selection:`single`,filter:void 0,layout:e.layout,edit:e.edit}}}function canNavigateBack(e){return e.activeStep>(e.firstNavigableStep??0)}function canNavigateForward(e){return e.activeStep>=(e.firstNavigableStep??0)&&e.activeStep<e.steps.length-1}function plannerStepRows(e,t,n){let r=e.steps.map((r,i)=>{let a=i===e.activeStep?t:r.count,o=a===void 0||a===0?``:` (${a})`,s=`${r.complete===!0?`${n.glyph.success} `:``}${r.label}${o}`;return i===e.activeStep?n.colors.bold(` ${s}`):r.complete===!0?n.colors.green(s):n.colors.dim(s)});return[` ${r.flatMap((t,i)=>{if(i===r.length-1)return[t];let a=e.activeStep===i&&canNavigateForward(e)?` → `:e.activeStep===i+1&&canNavigateBack(e)?` ← `:` · `;return[t,n.colors.dim(a)]}).join(``)}`,``]}function selectMessageRows(e,t,n,r){if(e===``)return[];let i=e.split(`
|
|
6
|
-
`).flatMap((e,i)=>{let a=t===`stacked`||i>0;return wrapVisibleLine(e,Math.max(1,r-4)).map(e=>` ${a?n.colors.bold(e):e}`)});return i.push(``),i}function searchFilter(e,t,n,r,i){let a=r.colors.dim(r.glyph.caret),o=a;return i?o=e.length>0?e+a:r.colors.dim(t??`type to filter`):e.length>0?o=e+a:t!==void 0&&(o=r.colors.dim(`> ${t}`)),n===void 0?o:`${o} ${r.colors.yellow(n)}`}function isRailedSearch(e){return e.filter!==void 0&&e.layout===`plain`&&e.selection===`single`&&e.edit===void 0}function selectViewSize(e){return e.search?e.railed?5:e.stacked?Math.min(e.optionCount,8):8:e.optionCount}function noticeBody(e,t,n){return e.tone===`info`?n.colors.dim(e.text):e.tone===`success`&&t===`task-list`?n.colors.bold(e.text):e.text}function renameHint(e,t,n,r){let i={text:n.editor.text||n.defaultValue,cursor:n.editor.cursor},a=renderInputWithBlockCursor({...visibleLine(i,1/0),visible:t,inverse:r.colors.inverse});return n.editor.text.length>0&&(a=solidWithinDim(a,r)),{...e,hint:n.formatHint(a)}}function keyHint(e,t,n,r,i){let a=n.phase;if(a.kind===`inactive`)return e;let o=r.colors,s=maskLine(a.editor),c=a.kind!==`validating`&&a.kind!==`invalid`,l=``;a.kind===`editing`?l=` ${enterBadge(r,`validate`)}`:a.kind===`validating`?l=` ${o.yellow(r.glyph.validating)} ${o.dim(`validating`)}`:a.kind===`invalid`&&(l=` ${o.red(`${r.glyph.error} API key is not valid`)}`);let u=`${r.glyph.elbow} `,d=a.editor.text.length===0?`type your key`:void 0,f=d===void 0?s:{text:d,cursor:0},p=Math.max(1,i-visibleLength(`${u}${l}`)),m=visibleLine(f,p,r.glyph.ellipsis),h=c?renderInputWithBlockCursor({...m,visible:t,inverse:r.colors.inverse}):renderInputText(`${m.before}${m.under}${m.after}`);return{...e,hint:`${u}${h}${l}`}}function inlineEditOption(e,t,n,r,i){if(!t||n===void 0||e.value!==n.optionValue)return e;switch(n.editor.kind){case`rename`:return renameHint(e,n.caretVisible,n.editor,r);case`key`:return keyHint(e,n.caretVisible,n.editor,r,i)}}function optionUsesPlaceholder(e,t){let n=e.filter!==void 0&&e.layout!==`task-list`,r=e.selection===`multiple`,i=e.layout!==`plain`;return!n&&!t&&(r||i)}function appendSelectOptionRows(e){let{rows:t,state:n,presentation:r,visible:i,start:a,end:o,cursor:s,visibleLabelWidth:c,width:l,theme:u}=e,d=!1;for(let e=a;e<o;e+=1){let o=i[e],f=e===s,p=r.layout===`task-list`&&o.trailingAction===!0;p&&(appendSelectNotices(t,n.notices,r.layout,u,l),d=!0),p&&(e>a||(n.notices?.length??0)>0)&&t.push(``);let m=r.layout===`stacked`?Math.max(1,l-6):Math.max(1,l-Math.max(c,o.label.length)-9),h=inlineEditOption(o,f,r.edit,u,m),g=r.edit?.editor.kind===`key`&&f,_={...h,hint:(h.hint??(f||o.disabled?o.description:void 0))?.replace(/\s*\n\s*/gu,` `)};g&&(_.hint=void 0);let v=isRailedSearch(r),y=n.cursorBadge??(v&&!p?enterBadge(u):void 0),b=f&&y!==void 0?` ${y}`:``;t.push(` ${optionRow({option:_,isCursor:f,isChecked:r.selection===`multiple`?n.select.selected.has(o.value):o.checked===!0,placeholder:v||optionUsesPlaceholder(r,p),railed:v,hintPadding:Math.max(0,c-_.label.length),theme:u})}${b}`),g&&h.hint&&t.push(` ${h.hint}`)}return d}function appendSubmitRow(e,t,n,r){if(n<0)return;let i=t===n,a=i?`${r.glyph.selectedPointer} ${r.colors.bold(`Submit`)}`:` Submit`;e.push(``,` ${renderCursorRow(a,i,r.colors)}`)}function appendSelectNotices(e,t,n,r,i){if(t!==void 0&&t.length!==0){e.push(``);for(let a of t){let t=toneGlyph(a.tone,r),o=` `.repeat(visibleLength(t)+1),s=Math.max(1,i-2-visibleLength(t)-1),c=wrapVisibleLine(a.text,s);for(let[i,s]of c.entries()){let c=noticeBody({...a,text:s},n,r);e.push(i===0?` ${t} ${c}`:` ${o}${c}`)}}}}function selectFooterHints(e,t,n,r){let i=[],a=`esc to cancel`,o=e.edit;if(o!==void 0&&t[n]?.value===o.optionValue){if(o.editor.kind===`key`){let e=o.editor.phase;if(e.kind!==`inactive`&&e.editor.text.length>0&&(a=`esc to clear`),e.kind===`validating`)return[a];i.push(`type your key`)}else i.push(`type to rename`)}if(e.filter!==void 0&&i.push(`type to filter`),i.push(`↑/↓ move`),r!==void 0){let t=canNavigateBack(r),n=canNavigateForward(r);return i.push(e.selection===`multiple`?`space/enter toggle`:`enter to select`),t&&n?i.push(`←/→ steps`):t?i.push(`← back`):n&&i.push(`→ next`),i.push(a),i}return i.push(e.selection===`multiple`?`space to toggle`:`enter to select`),e.selection===`multiple`&&i.push(`enter on Submit to confirm`),i.push(a),i}function renderActionQuestion(e,t,n){let r=[` ${t.colors.dim(`${t.glyph.dot} ${e.context}`)}`,``];for(let[n,i]of e.actions.entries())r.push(` ${optionRow({option:i,isCursor:n===e.cursor,isChecked:!1,placeholder:!0,hintPadding:0,theme:t})}`);return r.push(...questionFooter([`↑/↓ move`,`enter to select`,`esc to cancel`],t)),r.map(e=>clip(e,n))}function renderSelectQuestion(e,t,n){if(e.kind===`actions`)return renderActionQuestion(e,t,n);let r=t.colors,i=selectPresentation(e),a=i.filter?filterOptions(e.options,e.select.filter,e.searchAction):e.options,o=e.navigation?.kind===`planner`?e.navigation:void 0,s=i.selection===`multiple`&&o===void 0?submitRowIndex(a):-1,c=e.select.cursor,l=isRailedSearch(i),u=[...e.navigation?.kind===`planner`?plannerStepRows(e.navigation,i.selection===`multiple`?e.select.selected.size:void 0,t):[],...selectMessageRows(e.message,i.layout,t,n)];if(e.description!==void 0||e.metadata!==void 0){if(u.at(-1)===``&&u.pop(),e.description!==void 0)for(let t of wrapVisibleLine(e.description,Math.max(1,n-4)))u.push(` ${r.dim(t)}`);for(let{label:t,value:i}of e.metadata??[]){let e=`${t}: `,a=wrapVisibleLine(i,Math.max(1,n-4-e.length));u.push(` ${r.dim(`${e}${a[0]??``}`)}`);for(let t of a.slice(1))u.push(` ${r.dim(`${` `.repeat(e.length)}${t}`)}`)}u.push(``)}i.filter!==void 0&&u.push(` ${l?` `:``}${searchFilter(e.select.filter,i.filter.placeholder,e.loadingFrame,t,l)}`);let d=selectViewSize({search:i.filter!==void 0,filter:e.select.filter,optionCount:a.length,railed:l,stacked:i.layout===`stacked`}),f=Math.max(0,Math.min(c-Math.floor(d/2),Math.max(0,a.length-d))),p=Math.min(f+d,a.length),m=a.slice(f,p).filter(e=>e.hint!==void 0||e.focusHint!==void 0).reduce((e,t)=>Math.max(e,t.label.length),0);a.length===0&&u.push(` ${r.dim(`(no matches)`)}`);let h=appendSelectOptionRows({rows:u,state:e,presentation:i,visible:a,start:f,end:p,cursor:c,visibleLabelWidth:m,width:n,theme:t});if(appendSubmitRow(u,c,s,t),o!==void 0&&i.selection===`multiple`){let t=e.select.selected.size;u.push(``,` ${r.dim(`${t} selected`)}`)}return!l&&a.length>p-f&&u.push(` ${r.dim(`↑↓ ${a.length} options, showing ${f+1}–${p}`)}`),h||appendSelectNotices(u,e.notices,i.layout,t,n),e.error!==void 0&&u.push(``,` ${r.red(e.error)}`),u.push(...questionFooter(l?[`Enter select`,`Esc back`]:selectFooterHints(i,a,c,o),t,n)),u.map(e=>clip(e,n))}function enterBadge(e,t){return e.colors.dim(t===void 0?e.glyph.enter:`${e.glyph.enter} ${t}`)}function
|
|
7
|
-
`).map(e=>` ${i.bold(e)}`));let o=Math.max(4,n-4),s=e.mask?maskLine(e.editor):e.editor,c=e.editor.text.length===0?e.placeholder:void 0,l=renderInputWithBlockCursor({...visibleLine(c===void 0?s:{text:c,cursor:0},o,t.glyph.ellipsis),visible:r,inverse:i.inverse,render:c===void 0?renderInputText:e=>i.dim(renderInputText(e))});return a.push(` ${l}`),e.error!==void 0&&a.push(``,` ${i.red(e.error)}`),a.push(...questionFooter([`enter to submit`,`esc to cancel`],t)),a.map(e=>clip(e,n))}function renderAcknowledgeQuestion(e,t,n){let r=t.colors,i=e.message===``?[]:[` ${r.bold(e.message)}`];if(e.lines.length>0){i.push(``);for(let t of e.lines)i.push(` ${r.dim(t)}`)}return i.push(...questionFooter([`enter to continue`],t)),i.map(e=>clip(e,n))}export{enterBadge,flowMessageRows,
|
|
6
|
+
`).flatMap((e,i)=>{let a=t===`stacked`||i>0;return wrapVisibleLine(e,Math.max(1,r-4)).map(e=>` ${a?n.colors.bold(e):e}`)});return i.push(``),i}function searchFilter(e,t,n,r,i){let a=r.colors.dim(r.glyph.caret),o=a;return i?o=e.length>0?e+a:r.colors.dim(t??`type to filter`):e.length>0?o=e+a:t!==void 0&&(o=r.colors.dim(`> ${t}`)),n===void 0?o:`${o} ${r.colors.yellow(n)}`}function isRailedSearch(e){return e.filter!==void 0&&e.layout===`plain`&&e.selection===`single`&&e.edit===void 0}function selectViewSize(e){return e.search?e.railed?5:e.stacked?Math.min(e.optionCount,8):8:e.optionCount}function noticeBody(e,t,n){return e.tone===`info`?n.colors.dim(e.text):e.tone===`success`&&t===`task-list`?n.colors.bold(e.text):e.text}function renameHint(e,t,n,r){let i={text:n.editor.text||n.defaultValue,cursor:n.editor.cursor},a=renderInputWithBlockCursor({...visibleLine(i,1/0),visible:t,inverse:r.colors.inverse});return n.editor.text.length>0&&(a=solidWithinDim(a,r)),{...e,hint:n.formatHint(a)}}function keyHint(e,t,n,r,i){let a=n.phase;if(a.kind===`inactive`)return e;let o=r.colors,s=maskLine(a.editor),c=a.kind!==`validating`&&a.kind!==`invalid`,l=``;a.kind===`editing`?l=` ${enterBadge(r,`validate`)}`:a.kind===`validating`?l=` ${o.yellow(r.glyph.validating)} ${o.dim(`validating`)}`:a.kind===`invalid`&&(l=` ${o.red(`${r.glyph.error} API key is not valid`)}`);let u=`${r.glyph.elbow} `,d=a.editor.text.length===0?`type your key`:void 0,f=d===void 0?s:{text:d,cursor:0},p=Math.max(1,i-visibleLength(`${u}${l}`)),m=visibleLine(f,p,r.glyph.ellipsis),h=c?renderInputWithBlockCursor({...m,visible:t,inverse:r.colors.inverse}):renderInputText(`${m.before}${m.under}${m.after}`);return{...e,hint:`${u}${h}${l}`}}function inlineEditOption(e,t,n,r,i){if(!t||n===void 0||e.value!==n.optionValue)return e;switch(n.editor.kind){case`rename`:return renameHint(e,n.caretVisible,n.editor,r);case`key`:return keyHint(e,n.caretVisible,n.editor,r,i)}}function optionUsesPlaceholder(e,t){let n=e.filter!==void 0&&e.layout!==`task-list`,r=e.selection===`multiple`,i=e.layout!==`plain`;return!n&&!t&&(r||i)}function appendSelectOptionRows(e){let{rows:t,state:n,presentation:r,visible:i,start:a,end:o,cursor:s,visibleLabelWidth:c,width:l,theme:u}=e,d=!1;for(let e=a;e<o;e+=1){let o=i[e],f=e===s,p=r.layout===`task-list`&&o.trailingAction===!0;p&&(appendSelectNotices(t,n.notices,r.layout,u,l),d=!0),p&&(e>a||(n.notices?.length??0)>0)&&t.push(``);let m=r.layout===`stacked`?Math.max(1,l-6):Math.max(1,l-Math.max(c,o.label.length)-9),h=inlineEditOption(o,f,r.edit,u,m),g=r.edit?.editor.kind===`key`&&f,_={...h,hint:(h.hint??(f||o.disabled?o.description:void 0))?.replace(/\s*\n\s*/gu,` `)};g&&(_.hint=void 0);let v=isRailedSearch(r),y=n.cursorBadge??(v&&!p?enterBadge(u):void 0),b=f&&y!==void 0?` ${y}`:``;t.push(` ${optionRow({option:_,isCursor:f,isChecked:r.selection===`multiple`?n.select.selected.has(o.value):o.checked===!0,placeholder:v||optionUsesPlaceholder(r,p),railed:v,hintPadding:Math.max(0,c-_.label.length),theme:u})}${b}`),g&&h.hint&&t.push(` ${h.hint}`)}return d}function appendSubmitRow(e,t,n,r){if(n<0)return;let i=t===n,a=i?`${r.glyph.selectedPointer} ${r.colors.bold(`Submit`)}`:` Submit`;e.push(``,` ${renderCursorRow(a,i,r.colors)}`)}function appendSelectNotices(e,t,n,r,i){if(t!==void 0&&t.length!==0){e.push(``);for(let a of t){let t=toneGlyph(a.tone,r),o=` `.repeat(visibleLength(t)+1),s=Math.max(1,i-2-visibleLength(t)-1),c=wrapVisibleLine(a.text,s);for(let[i,s]of c.entries()){let c=noticeBody({...a,text:s},n,r);e.push(i===0?` ${t} ${c}`:` ${o}${c}`)}}}}function selectFooterHints(e,t,n,r){let i=[],a=`esc to cancel`,o=e.edit;if(o!==void 0&&t[n]?.value===o.optionValue){if(o.editor.kind===`key`){let e=o.editor.phase;if(e.kind!==`inactive`&&e.editor.text.length>0&&(a=`esc to clear`),e.kind===`validating`)return[a];i.push(`type your key`)}else i.push(`type to rename`)}if(e.filter!==void 0&&i.push(`type to filter`),i.push(`↑/↓ move`),r!==void 0){let t=canNavigateBack(r),n=canNavigateForward(r);return i.push(e.selection===`multiple`?`space/enter toggle`:`enter to select`),t&&n?i.push(`←/→ steps`):t?i.push(`← back`):n&&i.push(`→ next`),i.push(a),i}return i.push(e.selection===`multiple`?`space to toggle`:`enter to select`),e.selection===`multiple`&&i.push(`enter on Submit to confirm`),i.push(a),i}function renderActionQuestion(e,t,n){let r=[` ${t.colors.dim(`${t.glyph.dot} ${e.context}`)}`,``];for(let[n,i]of e.actions.entries())r.push(` ${optionRow({option:i,isCursor:n===e.cursor,isChecked:!1,placeholder:!0,hintPadding:0,theme:t})}`);return r.push(...questionFooter([`↑/↓ move`,`enter to select`,`esc to cancel`],t)),r.map(e=>clip(e,n))}function renderSelectQuestion(e,t,n){if(e.kind===`actions`)return renderActionQuestion(e,t,n);let r=t.colors,i=selectPresentation(e),a=i.filter?filterOptions(e.options,e.select.filter,e.searchAction):e.options,o=e.navigation?.kind===`planner`?e.navigation:void 0,s=i.selection===`multiple`&&o===void 0?submitRowIndex(a):-1,c=e.select.cursor,l=isRailedSearch(i),u=[...e.navigation?.kind===`planner`?plannerStepRows(e.navigation,i.selection===`multiple`?e.select.selected.size:void 0,t):[],...selectMessageRows(e.message,i.layout,t,n)];if(e.description!==void 0||e.metadata!==void 0){if(u.at(-1)===``&&u.pop(),e.description!==void 0)for(let t of wrapVisibleLine(e.description,Math.max(1,n-4)))u.push(` ${r.dim(t)}`);for(let{label:t,value:i}of e.metadata??[]){let e=`${t}: `,a=wrapVisibleLine(i,Math.max(1,n-4-e.length));u.push(` ${r.dim(`${e}${a[0]??``}`)}`);for(let t of a.slice(1))u.push(` ${r.dim(`${` `.repeat(e.length)}${t}`)}`)}u.push(``)}i.filter!==void 0&&u.push(` ${l?` `:``}${searchFilter(e.select.filter,i.filter.placeholder,e.loadingFrame,t,l)}`);let d=selectViewSize({search:i.filter!==void 0,filter:e.select.filter,optionCount:a.length,railed:l,stacked:i.layout===`stacked`}),f=Math.max(0,Math.min(c-Math.floor(d/2),Math.max(0,a.length-d))),p=Math.min(f+d,a.length),m=a.slice(f,p).filter(e=>e.hint!==void 0||e.focusHint!==void 0).reduce((e,t)=>Math.max(e,t.label.length),0);a.length===0&&u.push(` ${r.dim(`(no matches)`)}`);let h=appendSelectOptionRows({rows:u,state:e,presentation:i,visible:a,start:f,end:p,cursor:c,visibleLabelWidth:m,width:n,theme:t});if(appendSubmitRow(u,c,s,t),o!==void 0&&i.selection===`multiple`){let t=e.select.selected.size;u.push(``,` ${r.dim(`${t} selected`)}`)}return!l&&a.length>p-f&&u.push(` ${r.dim(`↑↓ ${a.length} options, showing ${f+1}–${p}`)}`),h||appendSelectNotices(u,e.notices,i.layout,t,n),e.error!==void 0&&u.push(``,` ${r.red(e.error)}`),u.push(...questionFooter(e.footerHints??(l?[`Enter select`,`Esc back`]:selectFooterHints(i,a,c,o)),t,n)),u.map(e=>clip(e,n))}function enterBadge(e,t){return e.colors.dim(t===void 0?e.glyph.enter:`${e.glyph.enter} ${t}`)}function renderTextQuestion(e,t,n,r){let i=t.colors,a=[];for(let n of e.notices??[]){let e=n.tone===`info`?i.dim(n.text):n.text;a.push(`${toneGlyph(n.tone,t)} ${e}`)}e.message!==``&&a.push(...e.message.split(`
|
|
7
|
+
`).map(e=>` ${i.bold(e)}`));let o=Math.max(4,n-4),s=e.mask?maskLine(e.editor):e.editor,c=e.editor.text.length===0?e.placeholder:void 0,l=renderInputWithBlockCursor({...visibleLine(c===void 0?s:{text:c,cursor:0},o,t.glyph.ellipsis),visible:r,inverse:i.inverse,render:c===void 0?renderInputText:e=>i.dim(renderInputText(e))});return a.push(` ${l}`),e.error!==void 0&&a.push(``,` ${i.red(e.error)}`),a.push(...questionFooter([`enter to submit`,`esc to cancel`],t)),a.map(e=>clip(e,n))}function renderAcknowledgeQuestion(e,t,n){let r=t.colors,i=e.message===``?[]:[` ${r.bold(e.message)}`];if(e.lines.length>0){i.push(``);for(let t of e.lines)i.push(` ${r.dim(t)}`)}return i.push(...questionFooter([`enter to continue`],t)),i.map(e=>clip(e,n))}export{enterBadge,flowMessageRows,renderAcknowledgeQuestion,renderFlowPanel,renderSelectQuestion,renderTextQuestion};
|
|
@@ -129,13 +129,6 @@ export interface AssistantResponseStats {
|
|
|
129
129
|
export declare function takeUntil<T>(source: AsyncIterable<T>, stop: Promise<void>): AsyncIterable<T>;
|
|
130
130
|
/** `394.4K`-style compact count: plain below 1000, then K/M with one trimmed decimal. */
|
|
131
131
|
export declare function formatCompactTokenCount(count: number): string;
|
|
132
|
-
/**
|
|
133
|
-
* Reveals `text` one character per `stepMs` of elapsed time, typewriter
|
|
134
|
-
* style: the first character shows immediately, the full text after
|
|
135
|
-
* `(length - 1) * stepMs`. Painted on the shared ticker beat, so no timer
|
|
136
|
-
* of its own.
|
|
137
|
-
*/
|
|
138
|
-
export declare function typewriterText(text: string, elapsedMs: number, stepMs: number): string;
|
|
139
132
|
/**
|
|
140
133
|
* Formats a turn's wall-clock duration for the end-of-turn stats line:
|
|
141
134
|
* `42s`, `3min 24s`, `1h 12min`. Sub-second turns round up to `1s` — a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
const CSI_FINAL=/[\u0040-\u007e]/u,PASTE_START=`\x1B[200~`,PASTE_END=`\x1B[201~`;function sanitizePastedText(e){let t=``;for(let n of e.replace(/\r\n?/gu,`
|
|
2
2
|
`)){if(n===`
|
|
3
3
|
`||n===` `){t+=n;continue}let e=n.codePointAt(0);e!==void 0&&(e<32||e===127||e>=128&&e<=159||(t+=n))}return t}function isIncompletePaste(e){return e.startsWith(PASTE_START)&&!e.includes(PASTE_END,6)}function stripPasteStart(e){return e.startsWith(PASTE_START)?e.slice(6):e}function isIncompleteOsc(e){return e.startsWith(`\x1B]`)&&!e.includes(`\x07`,2)&&!e.includes(`\x1B\\`,2)}function stripPromptControlCharacters(e){let t=``;for(let n of e)n>=` `&&n!==``&&(t+=n);return t}function nextKey(e){let t=e[0];if(t===void 0)return{consumed:0,incomplete:!0};if(t===`\x1B`){if(e.length===1)return{consumed:0,incomplete:!0};let t=e[1];if(t===`O`)return e.length<3?{consumed:0,incomplete:!0}:{key:parseKey(Buffer.from(e.slice(0,3))),consumed:3};if(t===`[`){if(e.startsWith(PASTE_START)){let t=e.indexOf(PASTE_END,6);return t===-1?{consumed:0,incomplete:!0}:{key:{type:`text`,value:sanitizePastedText(e.slice(6,t)),framing:`bracketed-paste`},consumed:t+6}}for(let t=2;t<e.length;t+=1)if(CSI_FINAL.test(e[t]))return{key:parseKey(Buffer.from(e.slice(0,t+1))),consumed:t+1};return{consumed:0,incomplete:!0}}if(t===`]`){let t=e.indexOf(`\x07`,2),n=e.indexOf(`\x1B\\`,2);if(t===-1&&n===-1)return{consumed:0,incomplete:!0};let r=t===-1?n:n===-1?t:Math.min(t,n);return{key:{type:`osc`,value:e.slice(2,r)},consumed:r+(r===t?1:2)}}return t===`b`||t===`B`?{key:{type:`alt-b`},consumed:2}:t===`f`||t===`F`?{key:{type:`alt-f`},consumed:2}:{key:{type:`escape`},consumed:1}}if(t<` `||t===``)return{key:parseKey(Buffer.from(t)),consumed:1};let n=1;for(;n<e.length;){let t=e[n];if(t===`\x1B`||t<` `||t===``)break;n+=1}return{key:parseKey(Buffer.from(e.slice(0,n))),consumed:n}}const SGR_MOUSE=RegExp(`^\x1B\\[<(\\d+);(\\d+);(\\d+)([Mm])$`,`u`);function parseKey(e){let t=e.toString(`utf8`),n=SGR_MOUSE.exec(t);if(n!==null)return{type:`mouse`,action:n[4]===`M`?`press`:`release`,button:Number(n[1]),x:Number(n[2]),y:Number(n[3])};switch(t){case``:return{type:`ctrl-a`};case``:return{type:`ctrl-b`};case``:return{type:`ctrl-e`};case``:return{type:`ctrl-f`};case``:return{type:`ctrl-d`};case`\v`:return{type:`ctrl-k`};case``:return{type:`ctrl-n`};case``:return{type:`ctrl-p`};case`\f`:return{type:`ctrl-l`};case``:return{type:`ctrl-r`};case``:return{type:`ctrl-u`};case``:return{type:`ctrl-w`};case``:return{type:`ctrl-c`};case`\r`:case`
|
|
4
|
-
`:return{type:`enter`};case`\x1B[27;2;13~`:case`\x1B[13;2u`:return{type:`newline`};case``:case`\b`:return{type:`backspace`};case`\x1B[A`:case`\x1BOA`:return{type:`up`};case`\x1B[B`:case`\x1BOB`:return{type:`down`};case`\x1B[C`:case`\x1BOC`:return{type:`right`};case`\x1B[D`:case`\x1BOD`:return{type:`left`};case`\x1B[1;3C`:case`\x1B[1;5C`:case`\x1B[5C`:return{type:`alt-f`};case`\x1B[1;3D`:case`\x1B[1;5D`:case`\x1B[5D`:return{type:`alt-b`};case`\x1B[H`:case`\x1BOH`:case`\x1B[1~`:return{type:`home`};case`\x1B[F`:case`\x1BOF`:case`\x1B[4~`:return{type:`end`};case`\x1B[3~`:return{type:`delete`};case` `:return{type:`tab`};case`\x1B`:return{type:`escape`};default:{let e=stripPromptControlCharacters(t);return e.length>0?{type:`text`,value:e,framing:`unframed`}:{type:`ignore`}}}}async function*takeUntil(e,t){let n=e[Symbol.asyncIterator](),r=t.then(()=>({done:!0,value:void 0}));try{for(;;){let e=n.next();e.catch(()=>{});let t=await Promise.race([e,r]);if(t.done)break;yield t.value}}finally{n.return?.()?.catch(()=>{})}}function formatCompactTokenCount(e){if(e<1e3)return`${e}`;let t=e<1e6?e/1e3:e/1e6,n=e<1e6?`K`:`M`;return`${t.toFixed(1).replace(/\.0$/,``)}${n}`}function
|
|
4
|
+
`:return{type:`enter`};case`\x1B[27;2;13~`:case`\x1B[13;2u`:return{type:`newline`};case``:case`\b`:return{type:`backspace`};case`\x1B[A`:case`\x1BOA`:return{type:`up`};case`\x1B[B`:case`\x1BOB`:return{type:`down`};case`\x1B[C`:case`\x1BOC`:return{type:`right`};case`\x1B[D`:case`\x1BOD`:return{type:`left`};case`\x1B[1;3C`:case`\x1B[1;5C`:case`\x1B[5C`:return{type:`alt-f`};case`\x1B[1;3D`:case`\x1B[1;5D`:case`\x1B[5D`:return{type:`alt-b`};case`\x1B[H`:case`\x1BOH`:case`\x1B[1~`:return{type:`home`};case`\x1B[F`:case`\x1BOF`:case`\x1B[4~`:return{type:`end`};case`\x1B[3~`:return{type:`delete`};case` `:return{type:`tab`};case`\x1B`:return{type:`escape`};default:{let e=stripPromptControlCharacters(t);return e.length>0?{type:`text`,value:e,framing:`unframed`}:{type:`ignore`}}}}async function*takeUntil(e,t){let n=e[Symbol.asyncIterator](),r=t.then(()=>({done:!0,value:void 0}));try{for(;;){let e=n.next();e.catch(()=>{});let t=await Promise.race([e,r]);if(t.done)break;yield t.value}}finally{n.return?.()?.catch(()=>{})}}function formatCompactTokenCount(e){if(e<1e3)return`${e}`;let t=e<1e6?e/1e3:e/1e6,n=e<1e6?`K`:`M`;return`${t.toFixed(1).replace(/\.0$/,``)}${n}`}function formatTurnDuration(e){let t=Math.max(1,Math.round(e/1e3)),n=t%60,r=Math.floor(t/60);if(r===0)return`${n}s`;let i=r%60,a=Math.floor(r/60);return a===0?n===0?`${i}min`:`${i}min ${n}s`:i===0?`${a}h`:`${a}h ${i}min`}function formatTokenFlow(e,t){let n=formatCompactTokenCount(e.inputTokens),r=formatCompactTokenCount(e.outputTokens),i=`${t.arrowUp} ${n} ${t.arrowDown} ${r}`,a=formatContextPercentage(e.inputTokens,e.contextSize);return a==null?i:`${i} ${a}`}function formatContextPercentage(e,t){if(!(t==null||t<=0||!Number.isFinite(t)))return`${Math.round(e/t*100).toLocaleString()}%`}function formatAssistantResponseStats(e,t){if(t===`tokensPerSecond`)return formatTokensPerSecond(e.tokensPerSecond);if(e.outputTokens!=null)return`${e.outputTokens.toLocaleString()} output tokens`}function formatTokensPerSecond(e){if(e!=null)return`${formatNumber(e)} tok/s`}function formatNumber(e){return Number.isInteger(e)?e.toLocaleString():e.toLocaleString(void 0,{maximumFractionDigits:1})}export{formatAssistantResponseStats,formatCompactTokenCount,formatTokenFlow,formatTurnDuration,isIncompleteOsc,isIncompletePaste,nextKey,parseKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createEventDeduper}from"#protocol/event-dedupe.js";import{isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{readNdjsonStream}from"#client/ndjson.js";import{readMessageStreamVersion}from"#client/stream-version.js";var SubagentPump=class{#e;#t;#n;#r;#i=new Map;#a=new
|
|
1
|
+
import{createEventDeduper}from"#protocol/event-dedupe.js";import{isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{readNdjsonStream}from"#client/ndjson.js";import{readMessageStreamVersion}from"#client/stream-version.js";var SubagentPump=class{#e;#t;#n;#r;#i=new Map;#a=new Set;#o=new Map;#s=new Map;#c=new Map;#l=new Map;constructor(e){this.#e=e.client,this.#t=e.view,this.#n=e.formatActionResultError,this.#r=e.onToolCompleted}begin(e){let t=e.data.callId,n=this.#i.get(t);n===void 0?this.#i.set(t,{name:e.data.name,childSessionId:e.data.childSessionId,parentTurnId:e.data.turnId,background:!1,status:`open`,childStreamPath:e.data.childStreamPath,childStreamIndex:this.#s.get(e.data.childSessionId)??0,steps:new Map,currentSectionKey:null,nextSectionKey:0,tools:new Map,seenChildEvents:createEventDeduper()}):n.name=e.data.name,this.#t?.markChildToolCallId(t),(n===void 0||n.status===`open`)&&(this.#t?.begin({callId:t,name:e.data.name}),this.#a.delete(t)&&this.background(t),n===void 0&&this.#u(t))}settle(e){this.#p(e,!1)}background(e){let t=this.#i.get(e);if(t===void 0){this.#a.add(e);return}t.background=!0,t.status!==`authoritative`&&this.#t?.background({callId:e})}abortAll(){for(let e of this.#o.values())e.abort();this.#o.clear(),this.#i.clear(),this.#a.clear(),this.#s.clear(),this.#c.clear(),this.#l.clear()}settleCancelledTurn(e){for(let[t,n]of this.#i)n.parentTurnId!==e||n.background||(this.#p(t,!0),this.#o.get(t)?.abort(),this.#o.delete(t))}#u(e){let t=this.#i.get(e);if(t===void 0||t.status===`authoritative`)return;let n=this.#c.get(t.childSessionId);if(n===void 0){t.childStreamIndex=this.#s.get(t.childSessionId)??0,this.#c.set(t.childSessionId,e),this.#d(e);return}if(n===e)return;let r=this.#l.get(t.childSessionId)??[];r.includes(e)||r.push(e),this.#l.set(t.childSessionId,r)}#d(e){if(this.#o.has(e))return;let t=this.#e;if(!t)return;let n=this.#i.get(e);if(n===void 0||n.status===`authoritative`)return;let r=new AbortController;this.#o.set(e,r),(async()=>{let i=100;try{for(;!r.signal.aborted&&n.status!==`authoritative`;){let a=!1;try{let i=await t.fetch(streamPathAt(n.childStreamPath,n.childStreamIndex),{cache:`no-store`,signal:r.signal});if(!i.ok||i.body===null)throw await i.body?.cancel().catch(()=>{}),Error(`Child stream returned ${i.status}.`);for await(let t of readNdjsonStream(i.body,{streamVersion:readMessageStreamVersion(i.headers)})){if(r.signal.aborted)return;a=!0,n.childStreamIndex+=1,this.#s.set(n.childSessionId,n.childStreamIndex);let i=this.#g(e,t);if(i!==void 0&&await i,isCurrentTurnBoundaryEvent(t)){if(t.type===`session.waiting`&&hasPendingChildApproval(n))continue;this.#p(e,!0);return}}}catch{if(r.signal.aborted)return}i=a?100:Math.min(i*2,2e3),await abortableDelay(i,r.signal)}}finally{r.abort(),this.#o.get(e)===r&&this.#o.delete(e)}})()}#f(e,t,n){let r=t.tools.get(n.childCallId),i=r??{toolName:n.toolName,input:n.input,status:n.status};if(r){let e=r.status===`done`||r.status===`failed`||r.status===`rejected`;if(n.status===`approval-requested`&&!e)r.status=n.status;else{let e={preparing:0,"approval-requested":1,executing:2,done:3,failed:3,rejected:3};e[n.status]>e[r.status]&&(r.status=n.status)}n.input!==void 0&&(r.input=n.input)}else t.tools.set(n.childCallId,i);this.#t?.markChildToolCallId(n.childCallId),this.#t?.upsertTool({callId:e,subagentName:t.name,childCallId:n.childCallId,toolName:i.toolName,input:i.input,status:i.status})}#p(e,t){let n=this.#i.get(e);if(n&&n.status!==`authoritative`&&(t||n.status!==`provisional`)){n.status=t?`authoritative`:`provisional`;for(let[t,r]of n.steps)r.finalized||(r.finalized=!0,this.#t?.upsertStep({callId:e,subagentName:n.name,sectionKey:t,reasoning:r.reasoning,message:r.message,finalized:!0}));n.currentSectionKey=null,this.#h(e,n),this.#t?.complete({authoritative:t,callId:e}),t&&this.#m(e,n.childSessionId)}}#m(e,t){let n=(this.#l.get(t)??[]).filter(t=>t!==e);if(this.#c.get(t)!==e){n.length===0?this.#l.delete(t):this.#l.set(t,n);return}for(this.#c.delete(t);n.length>0;){let e=n.shift(),r=this.#i.get(e);if(r!==void 0&&r.status!==`authoritative`){n.length===0?this.#l.delete(t):this.#l.set(t,n),r.childStreamIndex=this.#s.get(t)??0,this.#c.set(t,e),this.#d(e);return}}this.#l.delete(t)}#h(e,t){for(let[n,r]of t.tools)r.status===`preparing`&&(t.tools.delete(n),this.#t?.removeTool({callId:e,childCallId:n}))}#g(e,t){let n=this.#i.get(e);if(!n||!n.seenChildEvents.admit(t))return;n.status===`provisional`&&(n.status=`open`,this.#t?.begin({callId:e,name:n.name}));let r=this.#t,emit=(t,i)=>{r?.upsertStep({callId:e,subagentName:n.name,sectionKey:t,reasoning:i.reasoning,message:i.message,finalized:i.finalized})},finalizeCurrent=()=>{if(n.currentSectionKey===null)return;let e=n.steps.get(n.currentSectionKey);e&&(e.finalized=!0,emit(n.currentSectionKey,e)),n.currentSectionKey=null};switch(t.type){case`reasoning.appended`:{let{key:e,step:r}=openCurrentSubagentSection(n);r.reasoning+=t.data.reasoningDelta,emit(e,r);break}case`reasoning.completed`:break;case`message.appended`:{let{key:e,step:r}=openCurrentSubagentSection(n);r.message+=t.data.messageDelta,emit(e,r);break}case`message.completed`:{let{key:e,step:r}=openCurrentSubagentSection(n);t.data.message!==null&&r.message.length===0&&(r.message=t.data.message),r.finalized=!0,emit(e,r),n.currentSectionKey=null;break}case`step.completed`:finalizeCurrent(),this.#h(e,n);break;case`actions.requested`:finalizeCurrent();for(let r of t.data.actions)r.kind===`tool-call`&&this.#f(e,n,{childCallId:r.callId,toolName:r.toolName,input:r.input,status:`executing`});break;case`input.requested`:finalizeCurrent();for(let r of t.data.requests)r.action.kind===`tool-call`&&this.#f(e,n,{childCallId:r.action.callId,toolName:r.action.toolName,input:r.action.input,status:`approval-requested`});break;case`action.result`:{let i=t.data.result;if(i.kind!==`tool-result`)break;let a=n.tools.get(i.callId);if(!a)break;switch(t.data.status){case`completed`:a.status=`done`,a.output=i.output;break;case`failed`:a.status=`failed`,a.errorText=this.#n(t);break;case`rejected`:a.status=`rejected`,a.errorText=this.#n(t)}let o={callId:e,subagentName:n.name,childCallId:i.callId,toolName:a.toolName,input:a.input,status:a.status};if(a.output!==void 0&&(o.output=a.output),a.errorText!==void 0&&(o.errorText=a.errorText),r?.upsertTool(o),t.data.status===`completed`)return this.#r?.(n.name,a.toolName,i.output);break}}}};function hasPendingChildApproval(e){return[...e.tools.values()].some(e=>e.status===`approval-requested`)}function streamPathAt(e,t){return t===0?e:`${e}${e.includes(`?`)?`&`:`?`}startIndex=${t}`}async function abortableDelay(e,t){t.aborted||await new Promise(n=>{let onAbort=()=>{clearTimeout(r),n()},r=setTimeout(()=>{t.removeEventListener(`abort`,onAbort),n()},e);r.unref?.(),t.addEventListener(`abort`,onAbort,{once:!0})})}function openCurrentSubagentSection(e){e.currentSectionKey===null&&(e.currentSectionKey=e.nextSectionKey++,e.steps.set(e.currentSectionKey,{reasoning:``,message:``,finalized:!1}));let t=e.steps.get(e.currentSectionKey);if(!t)throw Error(`invariant: subagent section state missing for current key`);return{key:e.currentSectionKey,step:t}}export{SubagentPump};
|