eve 0.47.1 → 0.47.3
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 +21 -0
- package/dist/src/channel/activity-renderer.d.ts +21 -0
- package/dist/src/channel/activity-renderer.js +1 -0
- package/dist/src/channel/activity-sink.d.ts +2 -0
- package/dist/src/channel/activity-sink.js +1 -0
- package/dist/src/channel/auth/oidc.js +1 -1
- package/dist/src/channel/channel-address.js +1 -1
- package/dist/src/channel/compiled-channel.d.ts +2 -0
- package/dist/src/channel/compiled-channel.js +2 -2
- package/dist/src/channel/forwarded-principal.js +1 -1
- package/dist/src/channel/session.d.ts +3 -2
- package/dist/src/channel/session.js +1 -1
- package/dist/src/channel/types.d.ts +11 -0
- package/dist/src/chunks/{use-eve-agent-CacMaX4P.js → use-eve-agent-DjYwFJF7.js} +1 -0
- package/dist/src/chunks/{use-eve-agent-kmlFdOBB.js → use-eve-agent-DkUB0Ok4.js} +1 -0
- package/dist/src/cli/dev/tui/status-line.d.ts +6 -0
- package/dist/src/cli/dev/tui/status-line.js +1 -1
- package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
- package/dist/src/cli/dev/tui/tui.js +1 -1
- package/dist/src/compiler/extension-compatibility.d.ts +4 -4
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/normalize-subagent.js +1 -1
- package/dist/src/context/keys.d.ts +2 -1
- package/dist/src/context/keys.js +1 -1
- package/dist/src/eve-channel/activity-observer-request.d.ts +7 -0
- package/dist/src/eve-channel/activity-observer-request.js +1 -0
- package/dist/src/eve-channel/index.js +1 -1
- package/dist/src/eve-channel/request.d.ts +3 -1
- package/dist/src/eve-channel/request.js +1 -1
- package/dist/src/execution/activity-collector.d.ts +12 -0
- package/dist/src/execution/activity-collector.js +1 -0
- package/dist/src/execution/activity-events.d.ts +7 -0
- package/dist/src/execution/activity-events.js +1 -0
- package/dist/src/execution/activity-route.d.ts +2 -0
- package/dist/src/execution/activity-route.js +1 -0
- package/dist/src/execution/activity-text.d.ts +3 -0
- package/dist/src/execution/activity-text.js +1 -0
- package/dist/src/execution/activity-work-id.d.ts +9 -0
- package/dist/src/execution/activity-work-id.js +1 -0
- package/dist/src/execution/activity-work.d.ts +20 -0
- package/dist/src/execution/activity-work.js +1 -0
- package/dist/src/execution/agent-handle-dispatch.d.ts +3 -1
- package/dist/src/execution/agent-handle-dispatch.js +1 -1
- package/dist/src/execution/delegated-parent-notification.js +1 -1
- package/dist/src/execution/dispatch-runtime-actions-shared.d.ts +8 -0
- package/dist/src/execution/dispatch-runtime-actions-shared.js +1 -1
- package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
- package/dist/src/execution/eve-workflow-attributes.js +1 -1
- package/dist/src/execution/remote-agent-dispatch.d.ts +3 -1
- package/dist/src/execution/remote-agent-dispatch.js +1 -1
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/sandbox/bindings/vercel-credentials.js +1 -1
- package/dist/src/execution/session-activity-projection.d.ts +14 -0
- package/dist/src/execution/session-activity-projection.js +1 -0
- package/dist/src/execution/session-activity-renderer-step.d.ts +15 -0
- package/dist/src/execution/session-activity-renderer-step.js +1 -0
- package/dist/src/execution/session-activity.d.ts +6 -0
- package/dist/src/execution/session-activity.js +1 -0
- package/dist/src/execution/session-callback-request.d.ts +1 -0
- package/dist/src/execution/session-callback-request.js +1 -1
- package/dist/src/execution/session-callback-route.js +1 -1
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/subagent-start-local.d.ts +1 -0
- package/dist/src/execution/subagent-start-local.js +1 -1
- package/dist/src/execution/subagent-start-remote.d.ts +1 -0
- package/dist/src/execution/subagent-start-remote.js +1 -1
- package/dist/src/execution/subagent-tool.d.ts +2 -1
- package/dist/src/execution/subagent-tool.js +1 -1
- package/dist/src/execution/submit-activity.d.ts +7 -0
- package/dist/src/execution/submit-activity.js +1 -0
- package/dist/src/execution/tasks/child/steps.d.ts +8 -0
- package/dist/src/execution/tasks/child/steps.js +1 -1
- package/dist/src/execution/tasks/child/update.js +1 -1
- package/dist/src/execution/tasks/child/workflow.d.ts +3 -0
- package/dist/src/execution/tasks/child/workflow.js +1 -1
- package/dist/src/execution/tasks/parent/delegate.d.ts +3 -0
- package/dist/src/execution/tasks/parent/delegate.js +1 -1
- package/dist/src/execution/tasks/parent/dispatch-task-step.js +1 -1
- package/dist/src/execution/tasks/parent/hitl-proxy-steps.js +1 -1
- package/dist/src/execution/tasks/parent/tool-execution.js +1 -1
- package/dist/src/execution/terminate-child-sessions-step.js +1 -1
- package/dist/src/execution/tools/connection-search.js +1 -1
- package/dist/src/execution/tools/subagent/local.js +1 -1
- package/dist/src/execution/turn-control-receiver.js +1 -1
- package/dist/src/execution/turn-workflow.js +1 -1
- package/dist/src/execution/web-fetch/request.js +1 -1
- package/dist/src/execution/wire/session-inbox-contract.d.ts +2 -2
- package/dist/src/execution/wire/session-inbox-contract.js +1 -1
- package/dist/src/execution/wire/session-inbox-encoder.d.ts +6 -2
- package/dist/src/execution/wire/session-inbox-encoder.js +1 -1
- package/dist/src/execution/wire/session-inbox-wire.js +1 -1
- package/dist/src/execution/wire/session-inbox-wire.v2-migration.d.ts +4 -0
- package/dist/src/execution/wire/session-inbox-wire.v2-migration.js +1 -0
- package/dist/src/execution/wire/session-inbox-wire.v2.d.ts +478 -0
- package/dist/src/execution/wire/session-inbox-wire.v2.js +1 -0
- package/dist/src/execution/workflow-entry.js +1 -1
- package/dist/src/execution/workflow-runtime.d.ts +4 -0
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/execution/workflow-steps.js +1 -1
- package/dist/src/harness/ai-sdk-telemetry.d.ts +5 -1
- package/dist/src/harness/ai-sdk-telemetry.js +1 -1
- package/dist/src/harness/approval-delivery-coordinator.js +1 -1
- package/dist/src/harness/authorization.js +1 -1
- package/dist/src/harness/channel-delivery-instrumentation.js +1 -1
- package/dist/src/harness/instrumentation/content-policy.d.ts +3 -5
- package/dist/src/harness/instrumentation/content-policy.js +1 -1
- package/dist/src/harness/instrumentation/dispatch.js +1 -1
- package/dist/src/harness/instrumentation/lifecycle.d.ts +10 -4
- package/dist/src/harness/instrumentation/runtime-context.js +1 -1
- package/dist/src/harness/instrumentation/runtime.d.ts +3 -3
- package/dist/src/harness/prepare-trace-context.d.ts +3 -3
- package/dist/src/harness/prepare-trace-context.js +1 -1
- package/dist/src/harness/tool-loop.js +2 -2
- package/dist/src/harness/tool-model-output.js +1 -1
- package/dist/src/internal/application/compiled-artifacts.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
- package/dist/src/internal/user-agent.d.ts +2 -0
- package/dist/src/internal/user-agent.js +1 -1
- package/dist/src/protocol/activity.d.ts +105 -0
- package/dist/src/protocol/activity.js +1 -0
- package/dist/src/protocol/message.js +2 -2
- package/dist/src/protocol/routes.d.ts +4 -0
- package/dist/src/protocol/routes.js +1 -1
- package/dist/src/public/channels/auth.js +1 -1
- package/dist/src/public/channels/slack/defaults.js +1 -1
- package/dist/src/runtime/channels/registry.js +1 -1
- package/dist/src/runtime/connections/openapi-client.js +1 -1
- package/dist/src/runtime/subagents/dynamic-remote-agent-config.js +1 -1
- package/dist/src/setup/boxes/select-model.js +1 -1
- package/dist/src/setup/gateway-models.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/setup/scaffold/create/web-template.d.ts +1 -1
- package/dist/src/setup/scaffold/create/web-template.js +9 -5
- package/dist/src/shared/default-agent-model.d.ts +1 -1
- package/dist/src/shared/default-agent-model.js +1 -1
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/tracing/agent-approval-instrumentation.d.ts +0 -2
- package/dist/src/tracing/agent-approval-instrumentation.js +1 -1
- package/dist/src/tracing/agent-otel-provider.d.ts +3 -3
- package/dist/src/tracing/agent-otel-provider.js +2 -2
- package/dist/src/tracing/agent-otel-session-context.d.ts +3 -3
- package/dist/src/tracing/agent-otel-session-context.js +1 -1
- package/dist/src/tracing/agent-trace-context-store.d.ts +3 -0
- package/dist/src/tracing/agent-trace-context-store.js +1 -1
- package/dist/src/tracing/agent-trace-state.d.ts +2 -0
- package/dist/src/tracing/otel-declaration.d.ts +7 -3
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/agent-config.md +1 -3
- package/docs/concepts/state.md +7 -5
- package/docs/memory.md +210 -125
- package/docs/patterns/multi-tenant-memory.md +45 -111
- package/docs/reference/cli.md +5 -5
- package/package.json +1 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-commands.js";import{buildAgentHeader}from"./agent-header.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{copyTextToClipboard}from"./clipboard.js";import{dismissTypeahead,inlineCommandHint,isTypeaheadOpen,moveTypeaheadSelection,renderCommandSuggestions,selectedTypeaheadCommand,typeaheadCompletion,typeaheadFor}from"./command-typeahead.js";import{formatDevRebuildStatus,summarizeChangedFiles}from"./dev-rebuild-status.js";import{formatStoredDiagnostic,presentDiagnostic}from"./diagnostic-presentation.js";import{interruptedError}from"./errors.js";import{FileContentCache}from"./file-content-cache.js";import{EMPTY_LINE,PromptHistory,applyLineEditorKey,deleteForward,layoutPromptInput,lineOf,movePromptLine,visibleLine}from"./line-editor.js";import{nextLogDisplayMode}from"./log-display-mode.js";import{MessageQueue,renderMessageQueueRows}from"./message-queue.js";import{initialModelEditorState,transitionModelEditor}from"./model-editor.js";import{promptPlaceholder}from"./prompt-placeholder.js";import{initialProviderPickerState,transitionProviderPicker}from"./provider-picker.js";import{renderQuestionPanel}from"./question-panel.js";import{enterBadge,renderAcknowledgeQuestion,renderFlowPanel,renderModelEditorQuestion,renderSelectQuestion,renderTextQuestion}from"./setup-panel.js";import{formatAssistantResponseStats,formatTokenFlow,formatTurnDuration,isIncompleteOsc,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil,typewriterText}from"./stream-format.js";import{TraceViewerSession}from"./traces/trace-viewer-session.js";import{buildStatusLine}from"./status-line.js";import{createTheme,detectUnicode}from"./theme.js";import{isPanelRoutedTool,presentPreparingTool,presentTool,readWriteFileInput,toolBaseName}from"./tool-presentation.js";import{groupToolBlocksForDisplay}from"./tool-block-groups.js";import{TurnClock}from"./turn-clock.js";import{allTodoItemsSettled,readTodoToolItems,renderFinishedTodoRows,renderTodoPanelRows}from"./todo-panel.js";import{reduceSetupSelectInput,setupSelectionIntent}from"./setup-selection-input.js";import{BACKGROUND_COLOR_QUERY,parseBackgroundColorReply}from"./terminal-background.js";import{inspectError}from"#internal/logging.js";import{eveVersionTag}from"#cli/banner.js";import{clipVisible,renderInputText,renderInputWithBlockCursor,stripAnsi,stripTerminalControls}from"#cli/ui/terminal-text.js";import{renderCursorRow}from"#setup/cli/option-row.js";import{initialSelectState,reduceSelect,searchActionQuery,selectValueAtCursor}from"#setup/cli/select-state.js";import{toErrorMessage}from"#shared/errors.js";import{StringDecoder}from"node:string_decoder";import{summarizeKnownError}from"#harness/semantic-errors/index.js";import{parseDevRebuildLogLine}from"#internal/nitro/host/dev-watcher-log.js";import{LiveRegion}from"#cli/ui/live-region.js";import{AltScreen}from"#cli/ui/alt-screen.js";import{PROGRESS_PULSE_ASCII_GLYPH,PROGRESS_PULSE_GLYPH,isProgressPulseVisible}from"#cli/ui/progress-pulse.js";import{readGatewayServiceTier}from"#shared/gateway-service-tier.js";function isMultiSelectRequest(e){return e.kind===`multi`||e.kind===`searchable-multi`}function moveActionCursor(e,t,n){return n===0?void 0:e===void 0?t===`down`?0:n-1:(e+(t===`down`?1:-1)+n)%n}function completedTurnStatus(e){return e.interrupted?`Interrupted`:e.cancelled?`Cancelled`:e.continueSession?`Ready`:`Done`}const incompletePasteFlushMs=1e3,STATUS={processing:`Working…`,connectionAuth:`Waiting for connection authorization…`};var TerminalRenderer=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m=[];#h=new Map;#g=new Set;#_=[];#v=new Set;#y=new Map;#b=0;#x=new Map;#S=new Set;#C=new Set;#w=new FileContentCache;#T=new Set;#E;#D;#O=!1;#k;#A=[];#j;#M=0;#N;#P;#F=``;#I=0;#L=new PromptHistory;#R=!1;#z;#B=!1;#V=Date.now();#H=!1;#U=new TurnClock;#W=EMPTY_LINE;#G=!1;#K={kind:`idle`};#q;#J=STATUS.processing;#Y;#X=`eve`;#Z=!1;#Q=!1;#$=!1;#ee=!1;#te=!1;#ne=!1;#re;#ie=!0;#ae=0;#oe=Date.now();#se;#ce;#le;#ue=!1;#de;#fe=``;#pe=new StringDecoder(`utf8`);#me;#he;#ge;#_e=!1;#ve=!1;#ye;#be;#xe;#Se;#Ce;#we;#Te;#Ee=``;#De=``;#Oe;#ke;#Ae
|
|
2
|
-
`);if(this.#O){t!==this.#k&&(this.#k=t,this.#
|
|
1
|
+
import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-commands.js";import{buildAgentHeader}from"./agent-header.js";import{renderAttentionRows,renderBlockLines}from"./blocks.js";import{copyTextToClipboard}from"./clipboard.js";import{dismissTypeahead,inlineCommandHint,isTypeaheadOpen,moveTypeaheadSelection,renderCommandSuggestions,selectedTypeaheadCommand,typeaheadCompletion,typeaheadFor}from"./command-typeahead.js";import{formatDevRebuildStatus,summarizeChangedFiles}from"./dev-rebuild-status.js";import{formatStoredDiagnostic,presentDiagnostic}from"./diagnostic-presentation.js";import{interruptedError}from"./errors.js";import{FileContentCache}from"./file-content-cache.js";import{EMPTY_LINE,PromptHistory,applyLineEditorKey,deleteForward,layoutPromptInput,lineOf,movePromptLine,visibleLine}from"./line-editor.js";import{nextLogDisplayMode}from"./log-display-mode.js";import{MessageQueue,renderMessageQueueRows}from"./message-queue.js";import{initialModelEditorState,transitionModelEditor}from"./model-editor.js";import{promptPlaceholder}from"./prompt-placeholder.js";import{initialProviderPickerState,transitionProviderPicker}from"./provider-picker.js";import{renderQuestionPanel}from"./question-panel.js";import{enterBadge,renderAcknowledgeQuestion,renderFlowPanel,renderModelEditorQuestion,renderSelectQuestion,renderTextQuestion}from"./setup-panel.js";import{formatAssistantResponseStats,formatTokenFlow,formatTurnDuration,isIncompleteOsc,isIncompletePaste,nextKey,sanitizePastedText,stripPasteStart,stripPromptControlCharacters,takeUntil,typewriterText}from"./stream-format.js";import{TraceViewerSession}from"./traces/trace-viewer-session.js";import{buildStatusLine}from"./status-line.js";import{createTheme,detectUnicode}from"./theme.js";import{isPanelRoutedTool,presentPreparingTool,presentTool,readWriteFileInput,toolBaseName}from"./tool-presentation.js";import{groupToolBlocksForDisplay}from"./tool-block-groups.js";import{TurnClock}from"./turn-clock.js";import{allTodoItemsSettled,readTodoToolItems,renderFinishedTodoRows,renderTodoPanelRows}from"./todo-panel.js";import{reduceSetupSelectInput,setupSelectionIntent}from"./setup-selection-input.js";import{BACKGROUND_COLOR_QUERY,parseBackgroundColorReply}from"./terminal-background.js";import{inspectError}from"#internal/logging.js";import{eveVersionTag}from"#cli/banner.js";import{clipVisible,renderInputText,renderInputWithBlockCursor,stripAnsi,stripTerminalControls}from"#cli/ui/terminal-text.js";import{renderCursorRow}from"#setup/cli/option-row.js";import{initialSelectState,reduceSelect,searchActionQuery,selectValueAtCursor}from"#setup/cli/select-state.js";import{toErrorMessage}from"#shared/errors.js";import{StringDecoder}from"node:string_decoder";import{summarizeKnownError}from"#harness/semantic-errors/index.js";import{parseDevRebuildLogLine}from"#internal/nitro/host/dev-watcher-log.js";import{LiveRegion}from"#cli/ui/live-region.js";import{AltScreen}from"#cli/ui/alt-screen.js";import{PROGRESS_PULSE_ASCII_GLYPH,PROGRESS_PULSE_GLYPH,isProgressPulseVisible}from"#cli/ui/progress-pulse.js";import{readGatewayServiceTier}from"#shared/gateway-service-tier.js";function isMultiSelectRequest(e){return e.kind===`multi`||e.kind===`searchable-multi`}function moveActionCursor(e,t,n){return n===0?void 0:e===void 0?t===`down`?0:n-1:(e+(t===`down`?1:-1)+n)%n}function completedTurnStatus(e){return e.interrupted?`Interrupted`:e.cancelled?`Cancelled`:e.continueSession?`Ready`:`Done`}const incompletePasteFlushMs=1e3,STATUS={processing:`Working…`,connectionAuth:`Waiting for connection authorization…`};var TerminalRenderer=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m=[];#h=new Map;#g=new Set;#_=[];#v=new Set;#y=new Map;#b=0;#x=new Map;#S=new Set;#C=new Set;#w=new FileContentCache;#T=new Set;#E;#D;#O=!1;#k;#A=[];#j;#M=0;#N;#P;#F=``;#I=0;#L=new PromptHistory;#R=!1;#z;#B=!1;#V=Date.now();#H=!1;#U=new TurnClock;#W=EMPTY_LINE;#G=!1;#K={kind:`idle`};#q;#J=STATUS.processing;#Y;#X=`eve`;#Z=!1;#Q=!1;#$=!1;#ee=!1;#te=!1;#ne=!1;#re;#ie=!0;#ae=0;#oe=Date.now();#se;#ce;#le;#ue=!1;#de;#fe=``;#pe=new StringDecoder(`utf8`);#me;#he;#ge;#_e=!1;#ve=!1;#ye;#be;#xe;#Se;#Ce;#we;#Te;#Ee=``;#De=``;#Oe;#ke;#Ae;#je=!1;#Me;#Ne=0;#Pe;#Fe;#Ie;#Le;#Re;#ze;#Be=new MessageQueue;#Ve;#He=!1;#Ue;#We;#Ge=!1;#Ke;#qe;#Je;#Ye;#Xe;setupFlow={begin:(e,t)=>this.#nt(e,t),end:e=>this.#rt(e?.preserveDiagnostics??!0),readSelect:e=>this.#it(e),readEditableSelect:e=>this.#ot(e),readProviderPicker:e=>this.#st(e),readModelEditor:e=>this.#ct(e),readText:e=>this.#lt(e),readAcknowledge:e=>this.#ut(e),readChoice:e=>this.#at(e),setStatus:e=>this.#vt(e),renderLine:(e,t)=>this.#yt(e,t),replaceContent:e=>this.#bt(e),renderOutput:e=>this.#xt(e),withInheritedStdio:e=>this.#St(e),withExclusiveTerminal:e=>this.#St(e),waitForInterrupt:e=>this.#ht(e)};traceViewer={open:e=>this.#wt(e)};constructor(t){this.#e=t?.input??process.stdin,this.#t=t?.output??process.stdout,this.#n=new LiveRegion(this.#t),this.#r=new AltScreen(this.#t),this.#i=createTheme({color:t?.color??!0,unicode:t?.unicode??detectUnicode()}),this.#a=t?.tools??`auto-collapsed`,this.#o=t?.reasoning??`auto-collapsed`,this.#s=t?.subagents??`auto-collapsed`,this.#c=t?.connectionAuth??`full`,this.#l=t?.assistantResponseStats??`tokensPerSecond`,this.#xe=t?.contextSize,this.#u=t?.captureForeignOutput??this.#t===process.stdout,this.#d=t?.diagnostics,this.#re=t?.onExitRequest,this.#p=t?.logs??`none`,this.#f=t?.availablePromptCommands??PROMPT_COMMANDS}renderAgentHeader(e){this.#X=e.name,this.#E=e,this.#Dt();let t=this.#_n().join(`
|
|
2
|
+
`);if(this.#O){t!==this.#k&&(this.#k=t,this.#Wt({kind:`agent-header`,body:t,live:!1})),this.#fn();return}this.#O=!0,this.#k=t,this.#n.flush(this.#_n(),[])}beginStartupDraft(e){this.#Dt({title:e.title}),this.#R=!0,this.#B=!0,this.#D={name:e.title,tip:e.tip};let t=lineOf(stripPromptControlCharacters(e.initialDraft??``));this.#Ze(t),this.#Rt(),this.#fn();let apply=e=>{t=e,this.#Bt(),this.#Ze(t),this.#fn()};this.#de=e=>{let n=applyLineEditorKey(t,e,{multiline:!0});if(n!==void 0){apply(n);return}e.type===`ctrl-c`&&this.#re?.()},this.#At()}finishStartupDraft(){let e=this.#F;return this.#jt(),this.#zt(),this.#R=!1,this.#D=void 0,this.#B=!1,e}async readPrompt(e){this.#Dt(e),this.#Ut(),this.#Kt(),this.#R=!0,this.#B=!0,this.#K={kind:`idle`},this.#J=``,this.#ne=!1;let r=this.#Be.restoreDraft()?.split(`
|
|
3
3
|
`).map(stripPromptControlCharacters).join(`
|
|
4
|
-
`),i=stripPromptControlCharacters(e?.initialDraft??this.#W.text),a=lineOf(r===void 0?i:i.length===0?r:`${r}\n\n${i}`);return this.#W=EMPTY_LINE,this.#L.begin(a.text),this.#Je(a),this.#z=typeaheadFor(this.#f,a.text),this.#Ft(),this.#ln(),await new Promise((e,r)=>{this.#q=r;let apply=e=>{a=e,this.#Lt(),this.#Je(a),this.#z=typeaheadFor(this.#f,e.text,this.#z),this.#ln()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#z=void 0,this.#It(),this.#Et(),r(interruptedError())},suggestions=()=>this.#z!==void 0&&isTypeaheadOpen(this.#z)?this.#z:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#de=r=>{r.type!==`ctrl-c`&&this.#ne&&(this.#ne=!1,this.#ln());let i=applyLineEditorKey(a,r,{multiline:!0});if(i!==void 0){apply(i);return}switch(r.type){case`up`:case`ctrl-p`:{let e=suggestions();if(e!==void 0){this.#z=moveTypeaheadSelection(e,-1),this.#ln();break}let t=movePromptLine(a,`up`);t===void 0?recall(this.#L.previous(a.text)):apply(t);break}case`down`:case`ctrl-n`:{let e=suggestions();if(e!==void 0){this.#z=moveTypeaheadSelection(e,1),this.#ln();break}let t=movePromptLine(a,`down`);t===void 0?recall(this.#L.next()):apply(t);break}case`tab`:{let e=highlighted();e!==void 0&&apply(lineOf(typeaheadCompletion(e)));break}case`escape`:{let e=suggestions();e!==void 0&&(this.#z=dismissTypeahead(e),this.#ln());break}case`enter`:{let r=highlighted(),i=r!==void 0&&parsePromptCommand(a.text)===null?typeaheadCompletion(r).trimEnd():a.text;if(i.trim().length===0)break;this.#z=void 0,this.#L.add(i),this.#R=!1,this.#It(),this.#J=STATUS.processing,isPromptControlCommand(i)?this.#Vt({kind:`command`,body:stripTerminalControls(i.trim()),live:!1}):(this.#zt(),this.#Ht(i),this.#je=i,this.#U.arm()),this.#Je(EMPTY_LINE),this.#ln(),this.#Ot(),e(i);break}case`ctrl-d`:a.text.length===0?(this.#bt(),interrupt()):apply(deleteForward(a));break;case`ctrl-l`:this.#fn();break;case`ctrl-r`:this.#ln();break;case`ctrl-c`:if(this.#ne){this.#bt(),interrupt();break}this.#ne=!0,apply(EMPTY_LINE);break;default:break}},this.#Dt()})}#Je(e){this.#F=e.text,this.#I=e.cursor}takeQueuedPrompt(){let e=this.#Le.view().steering,t=this.#Le.takePrompt();return t!==void 0&&(this.#Ve=e?`steer`:`queue`),t}async renderStream(e,t){this.#wt(t),this.#g.clear(),this.#R=!1,this.#K.kind!==`waiting`&&(this.#K={kind:`waiting`,startedAtMs:Date.now()}),this.#J=this.#M>0?STATUS.connectionAuth:STATUS.processing,this.#Wt(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#d?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#U.armed&&this.#U.arm(),this.#ee=!1,this.#ze=!1,this.#He=!1,this.#Ue=t?.submittedPrompt,this.#Le.beginTurn(),this.#Re=e.cancel,this.#ye=void 0,this.#be=void 0,this.#Se=void 0,this.#Ce=void 0,this.#we=Date.now();let n={tools:t?.tools??this.#a,reasoning:t?.reasoning??this.#o,assistantResponseStats:t?.assistantResponseStats??this.#l};this.#Rt(),this.#G=!0,this.#ln();let r=new Promise(e=>{this.#ge=e});this.#de=e=>this.#Pt(e),this.#Dt();let i={text:new Map,reasoning:new Map,tools:new Map,cancelled:!1,restoreCancelledPrompt:!0};try{for await(let t of takeUntil(iterateTUIStream(e.events),r)){if(this.#ee)break;this.#Zt(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#Gt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Gt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#ge=void 0,this.#ee&&e.abort?.(),this.#Re=void 0,this.#Ot(),this.#Bt(),this.#G=!1,this.#K.kind===`waiting`&&(this.#K={kind:`idle`}),this.#J=completedTurnStatus({interrupted:this.#ee,cancelled:this.#ze,continueSession:t?.continueSession===!0}),this.#in(i),(this.#ee||i.cancelled)&&this.#rn(i),this.#Xt(),this.#d?.reportStats(),this.#ln(),t?.continueSession||this.#Et()}}async renderIdleStream(e,t){let n={tools:t?.tools??this.#a,reasoning:t?.reasoning??this.#o,assistantResponseStats:t?.assistantResponseStats??this.#l},r={text:new Map,reasoning:new Map,tools:new Map,cancelled:!1,restoreCancelledPrompt:!1};try{for await(let t of iterateTUIStream(e.events))this.#Zt(t,n,r)}catch(e){let t=summarizeKnownError(e);t===null?this.#Gt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Gt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#in(r),r.cancelled&&this.#rn(r),this.#Xt(),this.#d?.reportStats(),this.#ln()}}async readToolApproval(e,t){return this.#wt(t),this.#Bt(),this.#R=!1,this.#K={kind:`idle`},this.#J=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#ee=!1,this.#ln(),await new Promise((t,n)=>{this.#q=n,this.#de=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#zt(),this.#J=STATUS.processing,this.#Ot(),this.#ln(),t({approved:!0})):n===`n`&&(this.#zt(),this.#J=STATUS.processing,this.#Xe(e.toolCallId),this.#Ot(),this.#ln(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#ln();break;case`ctrl-c`:this.#ee=!0,this.#Et(),n(interruptedError());break;default:break}},this.#Dt()})}async readInputQuestion(e,t){this.#wt(t),this.#Bt(),this.#R=!1,this.#B=!1,this.#K={kind:`idle`},this.#ee=!1;let n=e.options??[],r=n.length>0,i=(e.allowFreeform===!0||!r)&&r,a=n.length+ +!!i,o=questionSectionId(e.requestId),s=r?`overlay`:`text`,c=0,l=EMPTY_LINE,isOnFreeformRow=()=>i&&c===n.length,overlayPanel=t=>renderQuestionPanel({prompt:stripTerminalControls(e.prompt),options:n,cursor:c,allowFreeform:i,editor:l,caretVisible:this.#ie},this.#i,t),renderTextSection=()=>{this.#qt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#i),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#Ft():(this.#It(),this.#Lt())};s===`overlay`?(s=`overlay`,this.#R=!1,this.#Yt(o),this.#Me=overlayPanel,this.#J=``,syncFreeformCaret(),this.#ln()):(s=`text`,this.#Me=void 0,renderTextSection(),this.#R=!0,this.#Je(l),this.#J=``,this.#Ft(),this.#ln());let finalize=t=>{this.#Me=void 0,this.#qt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#R=!1,this.#zt(),this.#J=STATUS.processing,this.#It(),this.#Ot(),this.#ln();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#Me=void 0,this.#qt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${this.#i.colors.dim(`Dismissed.`)}`,preformatted:!0,live:!1}),this.#R=!1,this.#J=``,this.#It(),this.#Ot(),this.#ln(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#ln())},selectOptionAt=e=>{let t=n[e];t&&u(finalize({optionId:t.id,label:t.label}))},u;return await new Promise((t,r)=>{this.#q=r,u=t,this.#de=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#Lt(),s===`text`&&this.#Je(l),this.#ln();return}this.#ee=!0,this.#Me=void 0,this.#It(),this.#Et(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#ln();return}if(s===`overlay`){let r=setupSelectionIntent(t,{textNavigation:!isOnFreeformRow()});if(r?.kind===`move`){moveCursor(r.direction===`up`?-1:1);return}switch(t.type){case`up`:case`ctrl-p`:moveCursor(-1);break;case`down`:case`ctrl-n`:moveCursor(1);break;case`enter`:if(isOnFreeformRow()){let t=resolveQuestionText(l.text,e);t!==void 0&&u(finalize(t));break}selectOptionAt(c);break;case`escape`:if(isOnFreeformRow()&&l.text.length>0){l=EMPTY_LINE,this.#Lt(),this.#ln();break}dismiss();break;default:if(isOnFreeformRow()){let e=applyLineEditorKey(l,t);e!==void 0&&(l=e,this.#Lt(),this.#ln());break}if(t.type===`text`&&/^[1-9]$/u.test(t.value)){let e=Number(t.value)-1;e<n.length?selectOptionAt(e):e===n.length&&i&&(c=e,syncFreeformCaret(),this.#ln())}break}return}let a=applyLineEditorKey(l,t,{multiline:!0});if(a!==void 0){l=a,this.#Lt(),this.#Je(l),this.#ln();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#Lt(),this.#Je(l),this.#ln());break}case`enter`:{let t=resolveQuestionText(l.text,e);if(t===void 0)break;u(finalize(t));break}case`escape`:if(l.text.length>0){l=EMPTY_LINE,this.#Lt(),this.#Je(l),this.#ln();break}dismiss();break;default:break}},this.#Dt()})}upsertSubagentStep(e){if(this.#d?.recordSubagentDispatch(e.callId),this.#s===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(!(t.length===0&&n.length===0)){if(this.#Kt(e.callId,e.subagentName),this.#s===`collapsed`){this.#ln();return}this.#Jt({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,subagentCallId:e.callId,depth:1,reasoning:t,body:n,collapsed:this.#s!==`full`,live:!e.finalized}),this.#ln()}}upsertSubagentTool(e){if(this.#d?.recordSubagentDispatch(e.callId),e.status===`failed`&&e.errorText!==void 0&&this.#d?.append({source:`tool`,summary:`${e.toolName} failed (subagent ${e.subagentName})`,detail:e.errorText}),this.#s===`hidden`)return;if(this.#Kt(e.callId,e.subagentName),this.#s===`collapsed`){this.#ln();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#tn({input:e.input,output:e.output,toolCallId:e.childCallId,toolName:e.toolName})),r={id:subagentToolSectionId(e.callId,e.childCallId),kind:`subagent-tool`,subagentCallId:e.callId,depth:1,title:stripTerminalControls(n.title),subtitle:stripTerminalControls(n.subtitle),status:t,live:t===`running`||t===`approval`,expanded:this.#s===`full`,toolName:e.toolName,toolGroup:n.group,toolInput:e.input};n.doneTitle!==void 0&&(r.doneTitle=stripTerminalControls(n.doneTitle)),n.detail!==void 0&&(r.detailLines=n.detail,r.keepDetailWhenDone=n.keepDetailWhenDone===!0),e.output===void 0?e.errorText!==void 0&&(r.result=stripTerminalControls(e.errorText)):(r.result=n.summarizeResult(e.output),r.toolOutput=e.output),this.#Jt(r),this.#Ye(e.callId),this.#ln()}#Ye(e){applyCohortLiveness(this.#m.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#Yt(subagentToolSectionId(e.callId,e.childCallId)),this.#ln()}subagents={begin:e=>this.beginSubagent(e),background:e=>this.backgroundSubagent(e),upsertStep:e=>this.upsertSubagentStep(e),upsertTool:e=>this.upsertSubagentTool(e),removeTool:e=>this.removeSubagentTool(e),complete:e=>this.completeSubagent(e),markChildToolCallId:e=>this.markChildToolCallId(e)};beginSubagent(e){if(this.#s===`hidden`)return;this.#Kt(e.callId,e.name);let t=this.#h.get(subagentHeaderId(e.callId));t!==void 0&&(t.status===`done`&&delete t.status,t.live=!0),this.#C.delete(e.callId),this.#ln()}backgroundSubagent(e){let t=this.#h.get(subagentHeaderId(e.callId));t===void 0||this.#g.has(subagentHeaderId(e.callId))||(t.status=`running`,t.live=!0,t.updateSeq=++this.#b,this.#S.add(e.callId),this.#ln())}completeSubagent(e){let t=this.#h.get(subagentHeaderId(e.callId));if(t!==void 0){if(t.status=`done`,e.authoritative){this.#S.delete(e.callId),this.#C.delete(e.callId);for(let t of this.#m)t.subagentCallId===e.callId&&(t.live=!1)}else{this.#C.add(e.callId);for(let t of this.#m)t.subagentCallId===e.callId&&(t.live=!0)}this.#ln()}}markChildToolCallId(e){this.#v.add(e);let t=this.#y.get(e);t!==void 0&&(this.#Yt(t),this.#y.delete(e),this.#ln())}#Xe(e){let t=this.#h.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#c===`hidden`)return;let t=connectionAuthTerminalMessage(e.state);this.#qt({id:connectionAuthSectionId(e.name),kind:`connection-auth`,title:`${stripTerminalControls(e.name)} · authorization · ${e.state}`,body:formatConnectionAuthContent(e,t),preformatted:!0,live:t===void 0}),this.#ln()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#M)return;let n=this.#M>0;this.#M=t,t>0?(this.#J=STATUS.connectionAuth,this.#ln()):n&&(this.#J=STATUS.processing,this.#ln())}setVercelStatus(e){this.#N=e,this.#ln()}setRemoteConnectionStatus(e){this.#P=e,this.#ln()}reset(){this.#m=[],this.#h.clear(),this.#g.clear(),this.#j=void 0,this.#A.length=0,this.#_.length=0,this.#O=!1,this.#k=void 0,this.#Ze(),this.#H=!1,this.#je=void 0,this.#ke=void 0,this.#M=0,this.#ye=void 0,this.#be=void 0,this.#Se=void 0,this.#Ce=void 0,this.#we=void 0,this.#Z&&(this.#n.clearAll(),this.#ln())}renderSessionBoundary(){this.#Ut(),this.#Ze();let e=this.#i.colors,t=this.#i.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#Vt({kind:`session-boundary`,body:n,live:!1}),this.#ln()}#Ze(){this.#v.clear(),this.#y.clear(),this.#T.clear(),this.#S.clear(),this.#C.clear(),this.#x.clear(),this.#Fe=void 0,this.#Ie=void 0,this.#Le.reset(),this.#Ve=void 0,this.#w.clear(),this.#U.reset()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#wt(),this.#Vt({kind:`notice`,body:t,live:!1}),this.#ln())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#d?.append({source:`sandbox`,detail:t}),this.#wt(),this.#Vt({kind:`sandbox`,body:t,live:!1}),this.#ln())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#Qe();return}this.#wt(),this.#Pe=t,this.#ln()}clearSetupWarning(){this.#Qe()}#Qe(){this.#Pe!==void 0&&(this.#Pe=void 0,this.#ln())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#wt();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#Vt(r),this.#ln()}renderCommandResult(e,t){let n=stripAnsi(e);n.trim().length!==0&&(this.#wt(),this.#Vt(t===`success`?{kind:`result`,body:n,live:!1,status:`done`}:t===`error`?{kind:`flow`,title:t,body:n,live:!1}:{kind:`result`,body:n,live:!1}),this.#ln())}#$e(e,t=`spinner`){this.#wt(),this.#R=!1,this.#K={kind:`idle`},this.#J=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#Ne={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#Rt(),this.#ln()}#et(e){this.#We=void 0,this.#mt();let t=this.#Ne;if(t!==void 0){if(this.#Ne=void 0,this.#Bt(),e){let e=[];for(let n of t.lines){if(n.evidence===!0){e.push(n.text);continue}(n.tone===`warning`||n.tone===`error`)&&(e.length>0&&this.#Vt({kind:`flow`,title:`info`,body:e.join(`
|
|
5
|
-
`),live:!1}),this.#
|
|
6
|
-
`,` `))e>=` `&&e!==``&&dispatch({type:`char`,char:e})}).promise}async#ot(e){let t=this.#ct(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder===void 0?e.defaultValue!==void 0&&(i.placeholder=e.defaultValue):i.placeholder=e.placeholder,e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#i,t,this.#ie)},this.#Ft(),this.#ln(),await this.#dt((t,i)=>{let apply=e=>{n=e,r=void 0,this.#Lt(),this.#ln()},a=applyLineEditorKey(n,t);if(a!==void 0){apply(a);return}switch(t.type){case`ctrl-c`:case`escape`:i(void 0);return;case`ctrl-r`:this.#ln();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#ln();return}i(t);return}default:return}},()=>this.#It()).promise}async#st(e){let t=this.#ct();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#i,t),this.#ln(),await this.#dt((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#ln();return;default:return}}).promise}#ct(){return this.#wt(),this.#R=!1,this.#K={kind:`idle`},this.#J=``,this.#lt()}#lt(){return this.#Ne===void 0&&(this.#Ne={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#Ne}#ut(){this.#Ne?.implicit===!0?this.#Ne=void 0:this.#Ne!==void 0&&(this.#Ne.question=void 0,this.#Ne.hideLinesWhileQuestion=!1),this.#de=void 0,this.#Ot(),this.#Ne!==void 0&&this.#pt(),this.#ln()}#dt(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#ut(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#ut(),i(e))};return this.#Nt(),this.#de=t=>{t.type===`ctrl-c`&&this.#bt(),e(t,settle,reject)},this.#Dt(),{promise:a,settle}}#ft(e){let t,n=new Promise(e=>{t=e});return this.#We=t,this.#pt(e?.interruptible??!0),{promise:n,dispose:()=>{this.#We===t&&(this.#We=void 0,this.#mt())}}}#pt(e=!0){if(this.#We===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#bt();let e=this.#We;this.#We=void 0,this.#mt(),e?.();return}t.type===`ctrl-r`&&this.#ln()};this.#Ge=consumer,this.#Nt(),this.#de=consumer,this.#Dt()}#mt(){this.#Ge!==void 0&&(this.#de===this.#Ge&&this.#Ot(),this.#Ge=void 0)}#ht(e){let t=e===void 0?void 0:typeof e==`string`?{kind:`progress`,text:stripTerminalControls(e),startedAtMs:Date.now()}:{kind:`external-action`,text:stripTerminalControls(e.text),emphasis:stripTerminalControls(e.emphasis),startedAtMs:Date.now()};if(this.#Ne!==void 0){this.#Ne.status=t,t===void 0&&(this.#Ne.preview=void 0),this.#ln();return}if(!(this.#R||this.#G)){if(t===void 0){this.#K={kind:`idle`},this.#Y=void 0,this.#Bt(),this.#ln();return}this.#wt(),this.#zt(),this.#Y=t.text,this.#ln()}}#gt(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#Ne;if(r!==void 0){if(r.preview=void 0,t===`warning`||t===`error`)for(let e of r.outputBuffer)r.lines.push({text:e,tone:`info`,evidence:!0});r.outputBuffer=[],r.lines.push({text:n,tone:t}),this.#ln();return}this.#wt(),this.#Vt({kind:`flow`,title:t,body:n,live:!1}),this.#ln()}#_t(e){let t=this.#Ne;t!==void 0&&(t.lines=[],t.outputBuffer=[],t.preview=void 0,t.summary=e===void 0?void 0:{headline:stripTerminalControls(e.headline),facts:e.facts.map(e=>({label:stripTerminalControls(e.label),value:stripTerminalControls(e.value)}))},this.#ln())}#vt(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#Ne;if(n===void 0){this.#gt(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#ln()}async#yt(e){this.#fe=``,this.#Nt(),this.#We=void 0,this.#mt(),this.#Ot(),this.#Bt(),this.#n.clear(),this.#jn(),this.#r.enter({cursor:`visible`,mouse:!1}),this.#e.isTTY&&this.#e.setRawMode?.(!1),this.#e.pause();try{return await e()}finally{this.#r.exit(),this.#e.isTTY&&this.#e.setRawMode?.(!0),this.#e.resume(),this.#fe=``,this.#Nt(),this.#n.hideCursor(),this.#An(),this.#Ne!==void 0&&(this.#Rt(),this.#pt()),this.#n.reset(),this.#ln()}}setSessionId(e){this.#Be=e}shutdown(){if(this.#Et(),this.#Q&&!this.#$){this.#$=!0;let e=this.#Be===void 0?``:` ${this.#i.glyph.dot} session ${this.#Be}`;this.#t.write(`${this.#i.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}suspendPromptForInput(){this.#W={cursor:this.#I,text:this.#F},this.#Et()}requestInterrupt(){this.#ee=!0,this.#Ne!==void 0&&this.#de?.({type:`ctrl-c`}),this.#ge?.(),this.#Et()}exitRequested(){return this.#te}#bt(){this.#te=!0,this.#re?.()}async#xt(e){if(this.#Ke!==void 0||!this.#Z)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#On(),height:this.#kn()}),paint:e=>this.#r.paint(e,this.#kn()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e)),terminalBackground:this.#qe});this.#Ke=t,this.#r.enter(),this.#i.color&&this.#r.writeRaw(BACKGROUND_COLOR_QUERY),await new Promise(e=>{this.#Ct=e,this.#de=e=>{t.handleKey(e)===`close`&&this.#St()},this.#Dt(),t.start()})}#St(){let e=this.#Ke;if(e===void 0)return;this.#Ke=void 0,e.dispose(),this.#Ot(),this.#r.exit(),this.#n.hideCursor(),this.#ln(),this.#n.showCursor();let t=this.#Ct;this.#Ct=void 0,t?.()}#Ct;#wt(e){this.#X=e?.title??this.#X,e?.contextSize!==void 0&&(this.#xe=e.contextSize),!this.#Z&&(this.#Z=!0,this.#Q=!0,this.#n.reset(),this.#n.hideCursor(),this.#An(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#he=()=>this.#ln(),this.#t.on(`resize`,this.#he),process.on(`exit`,this.#Tt))}#Tt=()=>{this.#Z&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#Et(){this.#St();let e=this.#q;if(this.#q=void 0,e?.(interruptedError()),this.#Ot(),this.#It(),this.#Bt(),this.#le!==void 0&&(clearTimeout(this.#le),this.#le=void 0),this.#ue=!1,this.#Z){this.#zn();for(let e of this.#m)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#ln(),this.#n.clear(),this.#n.showCursor(),this.#jn(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#he&&=(this.#t.off(`resize`,this.#he),void 0),process.off(`exit`,this.#Tt),this.#Z=!1}}#Dt(){this.#e.off(`data`,this.#kt),this.#e.on(`data`,this.#kt),this.#fe.length>0&&queueMicrotask(()=>{this.#de!==void 0&&this.#fe.length>0&&(this.#jt(),this.#At())})}#Ot(){this.#e.off(`data`,this.#kt),this.#Nt(),this.#de=void 0}#kt=e=>{this.#Nt(),this.#fe+=this.#pe.write(e),this.#jt(),this.#At()};#At(){if(this.#fe===`\x1B`){this.#me=setTimeout(()=>{this.#fe===`\x1B`&&(this.#fe=``,this.#de?.({type:`escape`}))},30),this.#me.unref?.();return}if(isIncompletePaste(this.#fe)){let e=this.#fe;this.#me=setTimeout(()=>{if(this.#fe!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#fe=``,t.length>0&&this.#de?.({type:`text`,value:t,framing:`bracketed-paste`})},incompletePasteFlushMs),this.#me.unref?.();return}if(isIncompleteOsc(this.#fe)){let e=this.#fe;this.#me=setTimeout(()=>{this.#fe===e&&(this.#fe=``)},incompletePasteFlushMs),this.#me.unref?.()}}#jt(){for(;this.#fe.length>0;){let e=nextKey(this.#fe);if(e.incomplete)return;if(this.#fe=this.#fe.slice(e.consumed),!(e.key===void 0||e.key.type===`ignore`)){if(e.key.type===`osc`){this.#Mt(e.key.value);continue}this.#de?.(e.key)}}}#Mt(e){let t=parseBackgroundColorReply(e);t!==void 0&&(this.#qe=t,this.#Ke?.setTerminalBackground(t))}#Nt(){this.#me&&=(clearTimeout(this.#me),void 0)}#Pt(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#ln();break;case`enter`:{let e=this.#W.text;if(e.trim().length===0)break;if(parsePromptCommand(e)?.type===`cancel`&&this.#Re!==void 0){this.#W=EMPTY_LINE,this.#Le.requestCancellation(),this.#He=!0,this.renderCommandInvocation(e.trim()),this.renderCommandResult(`Turn cancellation requested.`),this.#Re(),this.#ln();break}this.#Le.enqueue(e)&&(this.#W=EMPTY_LINE),this.#ln();break}case`ctrl-c`:case`escape`:if(this.#Le.idle&&this.#Re===void 0)break;this.#Le.handleEscape(),this.#He=!0,this.#Re?.(),this.#ln();break;default:{let t=applyLineEditorKey(this.#W,e,{multiline:!0});t!==void 0&&(this.#W=t,this.#ln());break}}}#Ft(){this.#It(),this.#Lt(),this.#se=setInterval(()=>{this.#ie=!this.#ie,this.#ln()},500),this.#se.unref?.()}#It(){this.#se&&=(clearInterval(this.#se),void 0),this.#ie=!0}#Lt(){this.#ie=!0}#Rt(){this.#Bt(),this.#ce=setInterval(()=>{this.#ae+=1,this.#ln()},90),this.#ce.unref?.()}#zt(){let e=Date.now();this.#oe=e,this.#K={kind:`waiting`,startedAtMs:e},this.#Rt()}#Bt(){this.#ce&&=(clearInterval(this.#ce),void 0)}#Vt(e){e.id!==this.#ke?.id&&this.#zn(),e.updateSeq=++this.#b;let t=e.subagentCallId!==void 0&&this.#S.has(e.subagentCallId)?-1:this.#m.findIndex(e=>e.subagentCallId!==void 0&&this.#S.has(e.subagentCallId));t<0?this.#m.push(e):this.#m.splice(t,0,e),e.id&&this.#h.set(e.id,e)}#Ht(e){this.#H=!0,this.#Vt({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#ln()}#Ut(){let e=this.#U.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#xn(e.elapsedMs)}`,n=this.#be??0;if(this.#xe!==void 0&&this.#xe>0&&n>0){let e=Math.round(n/this.#xe*100);t+=` ${this.#i.glyph.dot} ${e}% context`}this.#Vt({kind:`turn-stats`,body:t,live:!1})}#Wt(e){if(e==null)return;let t=this.#Ve;if(this.#Ve=void 0,this.#je===e){this.#je=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#Vt(n)}#Gt(e,t,n={}){let r=stripTerminalControls(e),i=stripTerminalControls(t),a=n.detail===void 0?void 0:stripTerminalControls(n.detail),o=n.hint===void 0?void 0:stripTerminalControls(n.hint),s={source:`workflow`,summary:`${r}: ${i}`,detail:a??i};this.#d?.append(o===void 0?s:{...s,hint:o});let c={kind:`error`,title:r,body:i,live:!1};o!==void 0&&(c.hint=o),a!==void 0&&(c.detail=this.#d===void 0?a:`details: ${this.#d.displayPath}`),this.#Vt(c),this.#ln()}#Kt(e,t){if(this.#T.has(e))return;this.#T.add(e);let n=stripTerminalControls(t),r=this.#x.get(n)??[];if(r.push(e),this.#x.set(n,r),r.length===2){let e=this.#h.get(subagentHeaderId(r[0]));e!==void 0&&(e.subtitle=`#1`)}let i={id:subagentHeaderId(e),kind:`subagent`,subagentCallId:e,title:n,live:!0};r.length>1&&(i.subtitle=`#${r.length}`),this.#Vt(i)}#qt(e){if(e.id&&this.#g.has(e.id))return;let t=e.id?this.#h.get(e.id):void 0;if(t){Object.assign(t,e),t.updateSeq=++this.#b;return}this.#Vt(e)}#Jt(e){if(e.id&&this.#g.has(e.id))return;let t=e.id?this.#h.get(e.id):void 0;if(t!==void 0){Object.assign(t,e),t.updateSeq=++this.#b;return}let n=e.subagentCallId;if(n===void 0){this.#Vt(e);return}e.id!==this.#ke?.id&&this.#zn(),e.updateSeq=++this.#b;let r=-1;for(let e=0;e<this.#m.length;e+=1)this.#m[e]?.subagentCallId===n&&(r=e);this.#m.splice(r<0?this.#m.length:r+1,0,e),e.id!==void 0&&this.#h.set(e.id,e)}#Yt(e){this.#m=this.#m.filter(t=>t.id!==e),this.#h.delete(e)}#Xt(){for(let e of this.#m)e.subagentCallId!==void 0&&this.#C.has(e.subagentCallId)||e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#Zt(e,t,n){switch(e.type){case`step-finish`:this.#d?.recordStepUsage(e.usage),e.usage!==void 0&&this.#U.addUsage(e.usage),this.#in(n),this.#cn(e.usage),this.#ln();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#Qt(e.id,t,!0);break}case`assistant-complete`:{let t=n.text.get(e.id)??``,r=e.text!==void 0&&t.length===0?stripTerminalControls(e.text??``):t;n.text.set(e.id,r),this.#Qt(e.id,r,!1);break}case`reasoning-delta`:{if(t.reasoning===`hidden`)break;let r=(n.reasoning.get(e.id)??``)+stripTerminalControls(e.delta);if(n.reasoning.set(e.id,r),t.reasoning===`full`){this.#$t(e.id,r,!0,t);break}break}case`reasoning-complete`:{if(t.reasoning===`hidden`)break;let r=n.reasoning.get(e.id)??``;if(t.reasoning===`full`){this.#$t(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#en({input:void 0,preparing:!0,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-call`:if(this.#d?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#en({input:e.input,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-approval-request`:{if(t.tools===`hidden`)break;let r=n.tools.get(e.toolCallId);if(r===void 0)break;this.#en({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#sn(e.toolCallId,n);if(r===void 0)break;this.#en({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#sn(e.toolCallId,n);if(this.#d?.append({source:`tool`,summary:`${r?.toolName??e.toolCallId} failed`,detail:e.errorText}),t.tools===`hidden`||r===void 0)break;this.#en({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#sn(e.toolCallId,n);if(r===void 0)break;this.#en({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#Gt(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:if(n.cancelled=!0,!n.restoreCancelledPrompt)break;this.#ze=!0,!this.#He&&this.#Ue!==void 0&&this.#W.text.length===0&&(this.#W=lineOf(this.#Ue),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#cn(e.usage),this.#ln();break}}#Qt(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#qt({id:e,kind:`assistant`,body:r,live:n}),this.#ln())}#$t(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#qt({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#ln())}#en(e,t,n){if(n.tools.set(e.toolCallId,e),this.#v.has(e.toolCallId)||this.#an(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#y.set(e.toolCallId,r);let i=this.#tn(e);this.#qt(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#on(n),this.#ln()}#tn(e){e.output!==void 0&&this.#w.observeRead(e.output);let t={};this.#nn(e.toolName)&&(t.isSubagent=!0);let n=readWriteFileInput(e.toolName,e.input);if(n===void 0)return t.isSubagent===!0?t:void 0;let r=this.#w.observeWrite({path:n.path,content:n.content,callId:e.toolCallId});r!==void 0&&(t.previousContent=r);let i=writeExistedFlag(e.output);return i!==void 0&&(t.existed=i),t}#nn(e){let t=this.#E?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#rn(e){for(let t of e.tools.keys()){if(this.#v.has(t))continue;let e=this.#y.get(t)??toolSectionId(t),n=this.#h.get(e);n?.kind===`tool`&&n.status===`running`&&(n.status=`error`,n.result=`interrupted`,n.live=!1)}}#in(e){for(let[t,n]of e.tools){if(n.preparing!==!0)continue;e.tools.delete(t);let r=this.#y.get(t)??toolSectionId(t);this.#Yt(r),this.#y.delete(t)}}#an(e){let t=readTodoToolItems(e.toolName,e.input);if(t===void 0)return!1;if(t.length>0&&allTodoItemsSettled(t)){let e=JSON.stringify(t);this.#Ie!==e&&(this.#Ie=e,this.#Vt({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#On(),this.#i).join(`
|
|
7
|
-
`),live:!1})),this.#
|
|
8
|
-
`),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#Ee=i:this.#De=i,r===-1)return;let a=stripAnsi(n.slice(0,r)).replace(/\s+$/u,``);a.trim().length!==0&&(this.#d?.append({source:e,detail:a}),e===`stdout`?this.#
|
|
9
|
-
`);t=[],e.trim().length!==0&&this.#
|
|
10
|
-
`)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#
|
|
11
|
-
`),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#d===void 0){this.#
|
|
12
|
-
`);r.trim().length>0&&this.#
|
|
13
|
-
`);this.#
|
|
4
|
+
`),i=stripPromptControlCharacters(e?.initialDraft??this.#W.text),a=lineOf(r===void 0?i:i.length===0?r:`${r}\n\n${i}`);return this.#W=EMPTY_LINE,this.#L.begin(a.text),this.#Ze(a),this.#z=typeaheadFor(this.#f,a.text),this.#Rt(),this.#fn(),await new Promise((e,r)=>{this.#q=r;let apply=e=>{a=e,this.#Bt(),this.#Ze(a),this.#z=typeaheadFor(this.#f,e.text,this.#z),this.#fn()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#z=void 0,this.#zt(),this.#kt(),r(interruptedError())},suggestions=()=>this.#z!==void 0&&isTypeaheadOpen(this.#z)?this.#z:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#de=r=>{r.type!==`ctrl-c`&&this.#ne&&(this.#ne=!1,this.#fn());let i=applyLineEditorKey(a,r,{multiline:!0});if(i!==void 0){apply(i);return}switch(r.type){case`up`:case`ctrl-p`:{let e=suggestions();if(e!==void 0){this.#z=moveTypeaheadSelection(e,-1),this.#fn();break}let t=movePromptLine(a,`up`);t===void 0?recall(this.#L.previous(a.text)):apply(t);break}case`down`:case`ctrl-n`:{let e=suggestions();if(e!==void 0){this.#z=moveTypeaheadSelection(e,1),this.#fn();break}let t=movePromptLine(a,`down`);t===void 0?recall(this.#L.next()):apply(t);break}case`tab`:{let e=highlighted();e!==void 0&&apply(lineOf(typeaheadCompletion(e)));break}case`escape`:{let e=suggestions();e!==void 0&&(this.#z=dismissTypeahead(e),this.#fn());break}case`enter`:{let r=highlighted(),i=r!==void 0&&parsePromptCommand(a.text)===null?typeaheadCompletion(r).trimEnd():a.text;if(i.trim().length===0)break;this.#z=void 0,this.#L.add(i),this.#R=!1,this.#zt(),this.#J=STATUS.processing,isPromptControlCommand(i)?this.#Wt({kind:`command`,body:stripTerminalControls(i.trim()),live:!1}):(this.#Ht(),this.#Gt(i),this.#Pe=i,this.#U.arm()),this.#Ze(EMPTY_LINE),this.#fn(),this.#jt(),e(i);break}case`ctrl-d`:a.text.length===0?(this.#Ct(),interrupt()):apply(deleteForward(a));break;case`ctrl-l`:this.#hn();break;case`ctrl-r`:this.#fn();break;case`ctrl-c`:if(this.#ne){this.#Ct(),interrupt();break}this.#ne=!0,apply(EMPTY_LINE);break;default:break}},this.#At()})}#Ze(e){this.#F=e.text,this.#I=e.cursor}takeQueuedPrompt(){let e=this.#Be.view().steering,t=this.#Be.takePrompt();return t!==void 0&&(this.#We=e?`steer`:`queue`),t}async renderStream(e,t){this.#Dt(t),this.#g.clear(),this.#R=!1,this.#K.kind!==`waiting`&&(this.#K={kind:`waiting`,startedAtMs:Date.now()}),this.#J=this.#M>0?STATUS.connectionAuth:STATUS.processing,this.#qt(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#d?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#U.armed&&this.#U.arm(),this.#ee=!1,this.#He=!1,this.#Ge=!1,this.#Ke=t?.submittedPrompt,this.#Be.beginTurn(),this.#Ve=e.cancel,this.#ye=void 0,this.#be=void 0,this.#Se=void 0,this.#Ce=void 0,this.#we=Date.now();let n={tools:t?.tools??this.#a,reasoning:t?.reasoning??this.#o,assistantResponseStats:t?.assistantResponseStats??this.#l};this.#Vt(),this.#G=!0,this.#fn();let r=new Promise(e=>{this.#ge=e});this.#de=e=>this.#Lt(e),this.#At();let i={text:new Map,reasoning:new Map,tools:new Map,cancelled:!1,restoreCancelledPrompt:!0};try{for await(let t of takeUntil(iterateTUIStream(e.events),r)){if(this.#ee)break;this.#en(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#Jt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Jt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#ge=void 0,this.#ee&&e.abort?.(),this.#Ve=void 0,this.#jt(),this.#Ut(),this.#G=!1,this.#K.kind===`waiting`&&(this.#K={kind:`idle`}),this.#J=completedTurnStatus({interrupted:this.#ee,cancelled:this.#He,continueSession:t?.continueSession===!0}),this.#sn(i),(this.#ee||i.cancelled)&&this.#on(i),this.#$t(),this.#d?.reportStats(),this.#fn(),t?.continueSession||this.#kt()}}async renderIdleStream(e,t){let n={tools:t?.tools??this.#a,reasoning:t?.reasoning??this.#o,assistantResponseStats:t?.assistantResponseStats??this.#l},r={text:new Map,reasoning:new Map,tools:new Map,cancelled:!1,restoreCancelledPrompt:!1};try{for await(let t of iterateTUIStream(e.events))this.#en(t,n,r)}catch(e){let t=summarizeKnownError(e);t===null?this.#Jt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Jt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#sn(r),r.cancelled&&this.#on(r),this.#$t(),this.#d?.reportStats(),this.#fn()}}async readToolApproval(e,t){return this.#Dt(t),this.#Ut(),this.#R=!1,this.#K={kind:`idle`},this.#J=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#ee=!1,this.#fn(),await new Promise((t,n)=>{this.#q=n,this.#de=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#Ht(),this.#J=STATUS.processing,this.#jt(),this.#fn(),t({approved:!0})):n===`n`&&(this.#Ht(),this.#J=STATUS.processing,this.#$e(e.toolCallId),this.#jt(),this.#fn(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#fn();break;case`ctrl-c`:this.#ee=!0,this.#kt(),n(interruptedError());break;default:break}},this.#At()})}async readInputQuestion(e,t){this.#Dt(t),this.#Ut(),this.#R=!1,this.#B=!1,this.#K={kind:`idle`},this.#ee=!1;let n=e.options??[],r=n.length>0,i=(e.allowFreeform===!0||!r)&&r,a=n.length+ +!!i,o=questionSectionId(e.requestId),s=r?`overlay`:`text`,c=0,l=EMPTY_LINE,isOnFreeformRow=()=>i&&c===n.length,overlayPanel=t=>renderQuestionPanel({prompt:stripTerminalControls(e.prompt),options:n,cursor:c,allowFreeform:i,editor:l,caretVisible:this.#ie},this.#i,t),renderTextSection=()=>{this.#Xt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#i),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#Rt():(this.#zt(),this.#Bt())};s===`overlay`?(s=`overlay`,this.#R=!1,this.#Qt(o),this.#Fe=overlayPanel,this.#J=``,syncFreeformCaret(),this.#fn()):(s=`text`,this.#Fe=void 0,renderTextSection(),this.#R=!0,this.#Ze(l),this.#J=``,this.#Rt(),this.#fn());let finalize=t=>{this.#Fe=void 0,this.#Xt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${stripTerminalControls(t.label)}`,preformatted:!0,live:!1}),this.#R=!1,this.#Ht(),this.#J=STATUS.processing,this.#zt(),this.#jt(),this.#fn();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#Fe=void 0,this.#Xt({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:`${this.#i.colors.dim(this.#i.glyph.elbow)} ${this.#i.colors.dim(`Dismissed.`)}`,preformatted:!0,live:!1}),this.#R=!1,this.#J=``,this.#zt(),this.#jt(),this.#fn(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#fn())},selectOptionAt=e=>{let t=n[e];t&&u(finalize({optionId:t.id,label:t.label}))},u;return await new Promise((t,r)=>{this.#q=r,u=t,this.#de=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#Bt(),s===`text`&&this.#Ze(l),this.#fn();return}this.#ee=!0,this.#Fe=void 0,this.#zt(),this.#kt(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#fn();return}if(s===`overlay`){let r=setupSelectionIntent(t,{textNavigation:!isOnFreeformRow()});if(r?.kind===`move`){moveCursor(r.direction===`up`?-1:1);return}switch(t.type){case`up`:case`ctrl-p`:moveCursor(-1);break;case`down`:case`ctrl-n`:moveCursor(1);break;case`enter`:if(isOnFreeformRow()){let t=resolveQuestionText(l.text,e);t!==void 0&&u(finalize(t));break}selectOptionAt(c);break;case`escape`:if(isOnFreeformRow()&&l.text.length>0){l=EMPTY_LINE,this.#Bt(),this.#fn();break}dismiss();break;default:if(isOnFreeformRow()){let e=applyLineEditorKey(l,t);e!==void 0&&(l=e,this.#Bt(),this.#fn());break}if(t.type===`text`&&/^[1-9]$/u.test(t.value)){let e=Number(t.value)-1;e<n.length?selectOptionAt(e):e===n.length&&i&&(c=e,syncFreeformCaret(),this.#fn())}break}return}let a=applyLineEditorKey(l,t,{multiline:!0});if(a!==void 0){l=a,this.#Bt(),this.#Ze(l),this.#fn();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#Bt(),this.#Ze(l),this.#fn());break}case`enter`:{let t=resolveQuestionText(l.text,e);if(t===void 0)break;u(finalize(t));break}case`escape`:if(l.text.length>0){l=EMPTY_LINE,this.#Bt(),this.#Ze(l),this.#fn();break}dismiss();break;default:break}},this.#At()})}upsertSubagentStep(e){if(this.#d?.recordSubagentDispatch(e.callId),this.#s===`hidden`)return;let t=stripTerminalControls(e.reasoning??``).trim(),n=stripTerminalControls(e.message??``).trim();if(!(t.length===0&&n.length===0)){if(this.#Yt(e.callId,e.subagentName),this.#s===`collapsed`){this.#fn();return}this.#Zt({id:subagentStepSectionId(e.callId,e.sectionKey),kind:`subagent-step`,subagentCallId:e.callId,depth:1,reasoning:t,body:n,collapsed:this.#s!==`full`,live:!e.finalized}),this.#fn()}}upsertSubagentTool(e){if(this.#d?.recordSubagentDispatch(e.callId),e.status===`failed`&&e.errorText!==void 0&&this.#d?.append({source:`tool`,summary:`${e.toolName} failed (subagent ${e.subagentName})`,detail:e.errorText}),this.#s===`hidden`)return;if(this.#Yt(e.callId,e.subagentName),this.#s===`collapsed`){this.#fn();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#in({input:e.input,output:e.output,toolCallId:e.childCallId,toolName:e.toolName})),r={id:subagentToolSectionId(e.callId,e.childCallId),kind:`subagent-tool`,subagentCallId:e.callId,depth:1,title:stripTerminalControls(n.title),subtitle:stripTerminalControls(n.subtitle),status:t,live:t===`running`||t===`approval`,expanded:this.#s===`full`,toolName:e.toolName,toolGroup:n.group,toolInput:e.input};n.doneTitle!==void 0&&(r.doneTitle=stripTerminalControls(n.doneTitle)),n.detail!==void 0&&(r.detailLines=n.detail,r.keepDetailWhenDone=n.keepDetailWhenDone===!0),e.output===void 0?e.errorText!==void 0&&(r.result=stripTerminalControls(e.errorText)):(r.result=n.summarizeResult(e.output),r.toolOutput=e.output),this.#Zt(r),this.#Qe(e.callId),this.#fn()}#Qe(e){applyCohortLiveness(this.#m.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#Qt(subagentToolSectionId(e.callId,e.childCallId)),this.#fn()}subagents={begin:e=>this.beginSubagent(e),background:e=>this.backgroundSubagent(e),upsertStep:e=>this.upsertSubagentStep(e),upsertTool:e=>this.upsertSubagentTool(e),removeTool:e=>this.removeSubagentTool(e),complete:e=>this.completeSubagent(e),markChildToolCallId:e=>this.markChildToolCallId(e)};beginSubagent(e){if(this.#s===`hidden`)return;this.#Yt(e.callId,e.name);let t=this.#h.get(subagentHeaderId(e.callId));t!==void 0&&(t.status===`done`&&delete t.status,t.live=!0),this.#C.delete(e.callId),this.#fn()}backgroundSubagent(e){let t=this.#h.get(subagentHeaderId(e.callId));t===void 0||this.#g.has(subagentHeaderId(e.callId))||(t.status=`running`,t.live=!0,t.updateSeq=++this.#b,this.#S.add(e.callId),this.#fn())}completeSubagent(e){let t=this.#h.get(subagentHeaderId(e.callId));if(t!==void 0){if(t.status=`done`,e.authoritative){this.#S.delete(e.callId),this.#C.delete(e.callId);for(let t of this.#m)t.subagentCallId===e.callId&&(t.live=!1)}else{this.#C.add(e.callId);for(let t of this.#m)t.subagentCallId===e.callId&&(t.live=!0)}this.#fn()}}markChildToolCallId(e){this.#v.add(e);let t=this.#y.get(e);t!==void 0&&(this.#Qt(t),this.#y.delete(e),this.#fn())}#$e(e){let t=this.#h.get(toolSectionId(e));t!==void 0&&(t.status=`denied`,t.live=!1)}upsertConnectionAuth(e){if(this.#c===`hidden`)return;let t=connectionAuthTerminalMessage(e.state);this.#Xt({id:connectionAuthSectionId(e.name),kind:`connection-auth`,title:`${stripTerminalControls(e.name)} · authorization · ${e.state}`,body:formatConnectionAuthContent(e,t),preformatted:!0,live:t===void 0}),this.#fn()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#M)return;let n=this.#M>0;this.#M=t,t>0?(this.#J=STATUS.connectionAuth,this.#fn()):n&&(this.#J=STATUS.processing,this.#fn())}setVercelStatus(e){this.#N=e,this.#fn()}setRemoteConnectionStatus(e){this.#P=e,this.#fn()}reset(){this.#m=[],this.#h.clear(),this.#g.clear(),this.#j=void 0,this.#A.length=0,this.#_.length=0,this.#O=!1,this.#k=void 0,this.#et(),this.#H=!1,this.#Pe=void 0,this.#ke=void 0,this.#M=0,this.#ye=void 0,this.#be=void 0,this.#Se=void 0,this.#Ce=void 0,this.#we=void 0,this.#Z&&(this.#n.clearAll(),this.#fn())}renderSessionBoundary(){this.#Kt(),this.#et();let e=this.#i.colors,t=this.#i.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#Wt({kind:`session-boundary`,body:n,live:!1}),this.#fn()}#et(){this.#v.clear(),this.#y.clear(),this.#T.clear(),this.#S.clear(),this.#C.clear(),this.#x.clear(),this.#Re=void 0,this.#ze=void 0,this.#Be.reset(),this.#We=void 0,this.#w.clear(),this.#U.reset()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#Dt(),this.#Wt({kind:`notice`,body:t,live:!1}),this.#fn())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#d?.append({source:`sandbox`,detail:t}),this.#Dt(),this.#Wt({kind:`sandbox`,body:t,live:!1}),this.#fn())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#tt();return}this.#Dt(),this.#Le=t,this.#fn()}clearSetupWarning(){this.#tt()}#tt(){this.#Le!==void 0&&(this.#Le=void 0,this.#fn())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#Dt();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#Wt(r),this.#fn()}renderCommandResult(e,t){let n=stripAnsi(e);n.trim().length!==0&&(this.#Dt(),this.#Wt(t===`success`?{kind:`result`,body:n,live:!1,status:`done`}:t===`error`?{kind:`flow`,title:t,body:n,live:!1}:{kind:`result`,body:n,live:!1}),this.#fn())}#nt(e,t=`spinner`){this.#Dt(),this.#R=!1,this.#K={kind:`idle`},this.#J=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#Ie={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#Vt(),this.#fn()}#rt(e){this.#qe=void 0,this.#_t();let t=this.#Ie;if(t!==void 0){if(this.#Ie=void 0,this.#Ut(),e){let e=[];for(let n of t.lines){if(n.evidence===!0){e.push(n.text);continue}(n.tone===`warning`||n.tone===`error`)&&(e.length>0&&this.#Wt({kind:`flow`,title:`info`,body:e.join(`
|
|
5
|
+
`),live:!1}),this.#Wt({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#fn()}}async#it(e){let t=this.#dt(),n=isMultiSelectRequest(e),r=e.kind===`search`?e.searchAction:void 0,i=e.options,a={options:i,searchAction:r,submitRow:n};`initialValue`in e&&e.initialValue!==void 0&&(a.defaultValue=e.initialValue),`initialValues`in e&&e.initialValues!==void 0&&(a.initialValues=e.initialValues);let o=initialSelectState(a),s,c=!1,l=0,isCurrentSearch=e=>e===l,clearSearch=()=>{l+=1,c=!1,o=reduceSelect(o,{type:`clear`},{options:i,searchAction:r,submitRow:n}),this.#fn()},loadSearch=async(e,t)=>{c=!0,s=void 0;let a=++l;this.#fn();try{let s=await t(e);if(!isCurrentSearch(a))return;let c=o.filter;i=s,o={...initialSelectState({options:s,searchAction:r,submitRow:n}),filter:c}}catch(e){isCurrentSearch(a)&&(s=toErrorMessage(e))}finally{isCurrentSearch(a)&&(c=!1,this.#fn())}},u=e.notices;if(e.kind===`task-list`||e.kind===`search`&&e.layout===`task-list`){let n=t.taskListLineStart??t.lines.length,r=t.lines.slice(n).filter(e=>e.tone===`success`||e.tone===`warning`||e.tone===`error`).map(e=>({tone:e.tone,text:e.text}));u=e.notices??r,t.taskListLineStart=t.lines.length,t.hideLinesWhileQuestion=!0}let panelState=()=>{let t={...e,options:i,select:o};return u!==void 0&&u.length>0&&(t.notices=u),s!==void 0&&(t.error=s),c&&(t.loadingFrame=this.#yn()),t};return t.question=e=>renderSelectQuestion(panelState(),this.#i,e),this.#fn(),await this.#mt((t,a)=>{let close=e=>{l+=1,a(e)};if(c){t.type===`ctrl-c`?close(void 0):t.type===`escape`?clearSearch():t.type===`ctrl-r`&&this.#fn();return}let u={key:t,options:i,searchAction:r,select:o},d=reduceSetupSelectInput(n?{...u,kind:e.kind,required:e.required}:{...u,kind:e.kind});switch(d.kind){case`cancel`:close(void 0);return;case`repaint`:this.#fn();return;case`update`:o=d.select,s=void 0,this.#fn();return;case`submit`:{let e=searchActionQuery(d.values[0]??``),t=r?.load;if(e===void 0||t===void 0){close(d.values);return}loadSearch(e,t);return}case`error`:s=d.message,this.#fn();return;case`ignore`:return}}).promise}#at(e){this.#Dt();let t=this.#ft();t.status={kind:`progress`,text:stripTerminalControls(e.status),startedAtMs:Date.now()};let n;t.question=t=>renderSelectQuestion({kind:`actions`,context:e.context,actions:e.actions,cursor:n},this.#i,t),this.#fn();let r=this.#mt((t,r)=>{let i=setupSelectionIntent(t,{textNavigation:!0});switch(i?.kind){case`cancel`:r(void 0);return;case`move`:n=moveActionCursor(n,i.direction,e.actions.length),this.#fn();return;case`repaint`:this.#fn();return;case`submit`:n!==void 0&&r(e.actions[n].value);return;case void 0:return}},()=>{t.status=void 0});return{choice:r.promise,close:()=>r.settle(void 0)}}async#ot(e){let t=this.#dt(),n={options:e.options};e.initialValue!==void 0&&(n.defaultValue=e.initialValue);let r=initialSelectState(n),i=lineOf(``),a;t.question=t=>{let n={kind:`inline-edit`,layout:`task-list`,message:e.message,options:e.options,select:r,edit:{optionValue:e.editable.value,caretVisible:this.#ie,editor:{kind:`rename`,editor:i,defaultValue:e.editable.defaultValue,formatHint:e.editable.formatHint}}};return a!==void 0&&(n.error=a),renderSelectQuestion(n,this.#i,t)};let onEditableRow=()=>selectValueAtCursor([...e.options],r.cursor)===e.editable.value,syncEditableRow=()=>{onEditableRow()?this.#Rt():(i=lineOf(``),this.#zt())};return syncEditableRow(),this.#fn(),await this.#mt((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#Bt(),this.#fn()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#fn()},submit=()=>{let t=selectValueAtCursor([...e.options],r.cursor);if(t===void 0)return;if(t!==e.editable.value){n({kind:`selected`,value:t});return}let o=(i.text||e.editable.defaultValue).trim(),s=e.editable.validate?.(o);if(s!==void 0){a=s,this.#fn();return}n(o===e.editable.defaultValue?{kind:`selected`,value:t}:{kind:`edited`,value:t,text:o})},o=setupSelectionIntent(t,{textNavigation:!onEditableRow()});switch(o?.kind){case`cancel`:n(void 0);return;case`move`:applySelect({type:o.direction});return;case`submit`:submit();return;case`repaint`:this.#fn();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#zt()).promise}async#st(e){let t=this.#dt(),n=initialProviderPickerState(e.options,e.initialValue),r,cursorBadge=()=>{if(n.phase.kind!==`inactive`)return;let t=selectValueAtCursor([...e.options],n.select.cursor),r=e.options.find(e=>e.value===t);if(r!==void 0)return enterBadge(this.#i,r.checked===!0?`change`:void 0)};t.question=t=>{let r=cursorBadge(),i={kind:`inline-edit`,layout:`stacked`,message:e.message,options:e.options,select:n.select,edit:{optionValue:`ai-gateway-key`,caretVisible:this.#ie,editor:{kind:`key`,phase:n.phase}}};return r!==void 0&&(i.cursorBadge=r),renderSelectQuestion(i,this.#i,t)};let syncCaret=()=>{n.phase.kind===`editing`||n.phase.kind===`invalid`?this.#Rt():this.#zt()};return syncCaret(),this.#fn(),await this.#mt((t,i,a)=>{let dispatch=t=>{let o=transitionProviderPicker(n,t,e.options);switch(o.kind){case`ignore`:return;case`clear`:r?.abort(),r=void 0,n=o.state,syncCaret(),this.#fn();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#fn();return;case`validate`:{n=o.state,syncCaret(),this.#fn();let t=new AbortController;r=t;let i;try{i=e.validateInlineKey(o.key,t.signal)}catch(e){a(e);return}i.then(e=>{r!==t||t.signal.aborted||(r=void 0,dispatch({type:`validated`,validation:e}))},e=>{r!==t||t.signal.aborted||(r=void 0,a(e))});return}case`settle`:i(o.result);return}},o=setupSelectionIntent(t,{textNavigation:n.phase.kind===`inactive`});switch(o?.kind){case`cancel`:dispatch({type:`cancel`});return;case`move`:dispatch({type:`move`,direction:o.direction});return;case`submit`:dispatch({type:`submit`});return;case`repaint`:this.#fn();return;case void 0:break}if(n.phase.kind!==`editing`&&n.phase.kind!==`invalid`)return;let s=applyLineEditorKey(n.phase.editor,t);s!==void 0&&(this.#Bt(),dispatch({type:`edit`,editor:s}))},()=>{r?.abort(),r=void 0,this.#zt()}).promise}async#ct(e){let t=this.#dt(),n=initialModelEditorState(e);return t.question=t=>renderModelEditorQuestion({request:e,state:n},this.#i,t),this.#fn(),await this.#mt((t,r)=>{let dispatch=t=>{let i=transitionModelEditor(n,t,e);switch(i.kind){case`ignore`:return;case`render`:n=i.state,this.#fn();return;case`cancel`:r(void 0);return;case`settle`:r(i.result);return}},i=setupSelectionIntent(t);switch(i?.kind){case`cancel`:dispatch({type:`cancel`});return;case`move`:dispatch({type:`move`,direction:i.direction});return;case`submit`:dispatch({type:`submit`});return;case`repaint`:this.#fn();return;case void 0:break}if(t.type===`left`||t.type===`right`){dispatch({type:`adjust`,direction:t.type});return}if(t.type===`tab`){dispatch({type:`adjust`,direction:`right`});return}if(t.type===`backspace`){dispatch({type:`backspace`});return}if(t.type===`text`)for(let e of t.value.replaceAll(`
|
|
6
|
+
`,` `))e>=` `&&e!==``&&dispatch({type:`char`,char:e})}).promise}async#lt(e){let t=this.#dt(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder===void 0?e.defaultValue!==void 0&&(i.placeholder=e.defaultValue):i.placeholder=e.placeholder,e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#i,t,this.#ie)},this.#Rt(),this.#fn(),await this.#mt((t,i)=>{let apply=e=>{n=e,r=void 0,this.#Bt(),this.#fn()},a=applyLineEditorKey(n,t);if(a!==void 0){apply(a);return}switch(t.type){case`ctrl-c`:case`escape`:i(void 0);return;case`ctrl-r`:this.#fn();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#fn();return}i(t);return}default:return}},()=>this.#zt()).promise}async#ut(e){let t=this.#dt();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#i,t),this.#fn(),await this.#mt((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#fn();return;default:return}}).promise}#dt(){return this.#Dt(),this.#R=!1,this.#K={kind:`idle`},this.#J=``,this.#ft()}#ft(){return this.#Ie===void 0&&(this.#Ie={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#Ie}#pt(){this.#Ie?.implicit===!0?this.#Ie=void 0:this.#Ie!==void 0&&(this.#Ie.question=void 0,this.#Ie.hideLinesWhileQuestion=!1),this.#de=void 0,this.#jt(),this.#Ie!==void 0&&this.#gt(),this.#fn()}#mt(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#pt(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#pt(),i(e))};return this.#It(),this.#de=t=>{t.type===`ctrl-c`&&this.#Ct(),e(t,settle,reject)},this.#At(),{promise:a,settle}}#ht(e){let t,n=new Promise(e=>{t=e});return this.#qe=t,this.#gt(e?.interruptible??!0),{promise:n,dispose:()=>{this.#qe===t&&(this.#qe=void 0,this.#_t())}}}#gt(e=!0){if(this.#qe===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#Ct();let e=this.#qe;this.#qe=void 0,this.#_t(),e?.();return}t.type===`ctrl-r`&&this.#fn()};this.#Je=consumer,this.#It(),this.#de=consumer,this.#At()}#_t(){this.#Je!==void 0&&(this.#de===this.#Je&&this.#jt(),this.#Je=void 0)}#vt(e){let t=e===void 0?void 0:typeof e==`string`?{kind:`progress`,text:stripTerminalControls(e),startedAtMs:Date.now()}:{kind:`external-action`,text:stripTerminalControls(e.text),emphasis:stripTerminalControls(e.emphasis),startedAtMs:Date.now()};if(this.#Ie!==void 0){this.#Ie.status=t,t===void 0&&(this.#Ie.preview=void 0),this.#fn();return}if(!(this.#R||this.#G)){if(t===void 0){this.#K={kind:`idle`},this.#Y=void 0,this.#Ut(),this.#fn();return}this.#Dt(),this.#Ht(),this.#Y=t.text,this.#fn()}}#yt(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#Ie;if(r!==void 0){if(r.preview=void 0,t===`warning`||t===`error`)for(let e of r.outputBuffer)r.lines.push({text:e,tone:`info`,evidence:!0});r.outputBuffer=[],r.lines.push({text:n,tone:t}),this.#fn();return}this.#Dt(),this.#Wt({kind:`flow`,title:t,body:n,live:!1}),this.#fn()}#bt(e){let t=this.#Ie;t!==void 0&&(t.lines=[],t.outputBuffer=[],t.preview=void 0,t.summary=e===void 0?void 0:{headline:stripTerminalControls(e.headline),facts:e.facts.map(e=>({label:stripTerminalControls(e.label),value:stripTerminalControls(e.value)}))},this.#fn())}#xt(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#Ie;if(n===void 0){this.#yt(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#fn()}async#St(e){this.#fe=``,this.#It(),this.#qe=void 0,this.#_t(),this.#jt(),this.#Ut(),this.#n.clear(),this.#Pn(),this.#r.enter({cursor:`visible`,mouse:!1}),this.#e.isTTY&&this.#e.setRawMode?.(!1),this.#e.pause();try{return await e()}finally{this.#r.exit(),this.#e.isTTY&&this.#e.setRawMode?.(!0),this.#e.resume(),this.#fe=``,this.#It(),this.#n.hideCursor(),this.#Nn(),this.#Ie!==void 0&&(this.#Vt(),this.#gt()),this.#n.reset(),this.#fn()}}setSessionId(e){this.#Ue=e}shutdown(){if(this.#kt(),this.#Q&&!this.#$){this.#$=!0;let e=this.#Ue===void 0?``:` ${this.#i.glyph.dot} session ${this.#Ue}`;this.#t.write(`${this.#i.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}suspendPromptForInput(){this.#W={cursor:this.#I,text:this.#F},this.#kt()}requestInterrupt(){this.#ee=!0,this.#Ie!==void 0&&this.#de?.({type:`ctrl-c`}),this.#ge?.(),this.#kt()}exitRequested(){return this.#te}#Ct(){this.#te=!0,this.#re?.()}async#wt(e){if(this.#Ye!==void 0||!this.#Z)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#jn(),height:this.#Mn()}),paint:e=>this.#r.paint(e,this.#Mn()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e)),terminalBackground:this.#Xe});this.#Ye=t,this.#r.enter(),this.#i.color&&this.#r.writeRaw(BACKGROUND_COLOR_QUERY),await new Promise(e=>{this.#Et=e,this.#de=e=>{t.handleKey(e)===`close`&&this.#Tt()},this.#At(),t.start()})}#Tt(){let e=this.#Ye;if(e===void 0)return;this.#Ye=void 0,e.dispose(),this.#jt(),this.#r.exit(),this.#n.hideCursor(),this.#fn(),this.#n.showCursor();let t=this.#Et;this.#Et=void 0,t?.()}#Et;#Dt(e){this.#X=e?.title??this.#X,e?.contextSize!==void 0&&(this.#xe=e.contextSize),!this.#Z&&(this.#Z=!0,this.#Q=!0,this.#n.reset(),this.#n.hideCursor(),this.#Nn(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#he=()=>this.#fn(),this.#t.on(`resize`,this.#he),process.on(`exit`,this.#Ot))}#Ot=()=>{this.#Z&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#kt(){this.#Tt();let e=this.#q;if(this.#q=void 0,e?.(interruptedError()),this.#jt(),this.#zt(),this.#Ut(),this.#le!==void 0&&(clearTimeout(this.#le),this.#le=void 0),this.#ue=!1,this.#Hn(),this.#Z){this.#Wn();for(let e of this.#m)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#fn(),this.#n.clear(),this.#n.showCursor(),this.#Pn(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#he&&=(this.#t.off(`resize`,this.#he),void 0),process.off(`exit`,this.#Ot),this.#Z=!1}}#At(){this.#e.off(`data`,this.#Mt),this.#e.on(`data`,this.#Mt),this.#fe.length>0&&queueMicrotask(()=>{this.#de!==void 0&&this.#fe.length>0&&(this.#Pt(),this.#Nt())})}#jt(){this.#e.off(`data`,this.#Mt),this.#It(),this.#de=void 0}#Mt=e=>{this.#It(),this.#fe+=this.#pe.write(e),this.#Pt(),this.#Nt()};#Nt(){if(this.#fe===`\x1B`){this.#me=setTimeout(()=>{this.#fe===`\x1B`&&(this.#fe=``,this.#de?.({type:`escape`}))},30),this.#me.unref?.();return}if(isIncompletePaste(this.#fe)){let e=this.#fe;this.#me=setTimeout(()=>{if(this.#fe!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#fe=``,t.length>0&&this.#de?.({type:`text`,value:t,framing:`bracketed-paste`})},incompletePasteFlushMs),this.#me.unref?.();return}if(isIncompleteOsc(this.#fe)){let e=this.#fe;this.#me=setTimeout(()=>{this.#fe===e&&(this.#fe=``)},incompletePasteFlushMs),this.#me.unref?.()}}#Pt(){for(;this.#fe.length>0;){let e=nextKey(this.#fe);if(e.incomplete)return;if(this.#fe=this.#fe.slice(e.consumed),!(e.key===void 0||e.key.type===`ignore`)){if(e.key.type===`osc`){this.#Ft(e.key.value);continue}this.#de?.(e.key)}}}#Ft(e){let t=parseBackgroundColorReply(e);t!==void 0&&(this.#Xe=t,this.#Ye?.setTerminalBackground(t))}#It(){this.#me&&=(clearTimeout(this.#me),void 0)}#Lt(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#fn();break;case`enter`:{let e=this.#W.text;if(e.trim().length===0)break;if(parsePromptCommand(e)?.type===`cancel`&&this.#Ve!==void 0){this.#W=EMPTY_LINE,this.#Be.requestCancellation(),this.#Ge=!0,this.renderCommandInvocation(e.trim()),this.renderCommandResult(`Turn cancellation requested.`),this.#Ve(),this.#fn();break}this.#Be.enqueue(e)&&(this.#W=EMPTY_LINE),this.#fn();break}case`ctrl-c`:case`escape`:if(this.#Be.idle&&this.#Ve===void 0)break;this.#Be.handleEscape(),this.#Ge=!0,this.#Ve?.(),this.#fn();break;default:{let t=applyLineEditorKey(this.#W,e,{multiline:!0});t!==void 0&&(this.#W=t,this.#fn());break}}}#Rt(){this.#zt(),this.#Bt(),this.#se=setInterval(()=>{this.#ie=!this.#ie,this.#fn()},500),this.#se.unref?.()}#zt(){this.#se&&=(clearInterval(this.#se),void 0),this.#ie=!0}#Bt(){this.#ie=!0}#Vt(){this.#Ut(),this.#ce=setInterval(()=>{this.#ae+=1,this.#fn()},90),this.#ce.unref?.()}#Ht(){let e=Date.now();this.#oe=e,this.#K={kind:`waiting`,startedAtMs:e},this.#Vt()}#Ut(){this.#ce&&=(clearInterval(this.#ce),void 0)}#Wt(e){e.id!==this.#ke?.id&&this.#Wn(),e.updateSeq=++this.#b;let t=e.subagentCallId!==void 0&&this.#S.has(e.subagentCallId)?-1:this.#m.findIndex(e=>e.subagentCallId!==void 0&&this.#S.has(e.subagentCallId));t<0?this.#m.push(e):this.#m.splice(t,0,e),e.id&&this.#h.set(e.id,e)}#Gt(e){this.#H=!0,this.#Wt({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#fn()}#Kt(){let e=this.#U.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#wn(e.elapsedMs)}`,n=this.#be??0;if(this.#xe!==void 0&&this.#xe>0&&n>0){let e=Math.round(n/this.#xe*100);t+=` ${this.#i.glyph.dot} ${e}% context`}this.#Wt({kind:`turn-stats`,body:t,live:!1})}#qt(e){if(e==null)return;let t=this.#We;if(this.#We=void 0,this.#Pe===e){this.#Pe=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#Wt(n)}#Jt(e,t,n={}){let r=stripTerminalControls(e),i=stripTerminalControls(t),a=n.detail===void 0?void 0:stripTerminalControls(n.detail),o=n.hint===void 0?void 0:stripTerminalControls(n.hint),s={source:`workflow`,summary:`${r}: ${i}`,detail:a??i};this.#d?.append(o===void 0?s:{...s,hint:o});let c={kind:`error`,title:r,body:i,live:!1};o!==void 0&&(c.hint=o),a!==void 0&&(c.detail=this.#d===void 0?a:`details: ${this.#d.displayPath}`),this.#Wt(c),this.#fn()}#Yt(e,t){if(this.#T.has(e))return;this.#T.add(e);let n=stripTerminalControls(t),r=this.#x.get(n)??[];if(r.push(e),this.#x.set(n,r),r.length===2){let e=this.#h.get(subagentHeaderId(r[0]));e!==void 0&&(e.subtitle=`#1`)}let i={id:subagentHeaderId(e),kind:`subagent`,subagentCallId:e,title:n,live:!0};r.length>1&&(i.subtitle=`#${r.length}`),this.#Wt(i)}#Xt(e){if(e.id&&this.#g.has(e.id))return;let t=e.id?this.#h.get(e.id):void 0;if(t){Object.assign(t,e),t.updateSeq=++this.#b;return}this.#Wt(e)}#Zt(e){if(e.id&&this.#g.has(e.id))return;let t=e.id?this.#h.get(e.id):void 0;if(t!==void 0){Object.assign(t,e),t.updateSeq=++this.#b;return}let n=e.subagentCallId;if(n===void 0){this.#Wt(e);return}e.id!==this.#ke?.id&&this.#Wn(),e.updateSeq=++this.#b;let r=-1;for(let e=0;e<this.#m.length;e+=1)this.#m[e]?.subagentCallId===n&&(r=e);this.#m.splice(r<0?this.#m.length:r+1,0,e),e.id!==void 0&&this.#h.set(e.id,e)}#Qt(e){this.#m=this.#m.filter(t=>t.id!==e),this.#h.delete(e)}#$t(){for(let e of this.#m)e.subagentCallId!==void 0&&this.#C.has(e.subagentCallId)||e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#en(e,t,n){switch(e.type){case`step-finish`:this.#d?.recordStepUsage(e.usage),e.usage!==void 0&&this.#U.addUsage(e.usage),this.#sn(n),this.#dn(e.usage),this.#fn();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#tn(e.id,t,!0);break}case`assistant-complete`:{let t=n.text.get(e.id)??``,r=e.text!==void 0&&t.length===0?stripTerminalControls(e.text??``):t;n.text.set(e.id,r),this.#tn(e.id,r,!1);break}case`reasoning-delta`:{if(t.reasoning===`hidden`)break;let r=(n.reasoning.get(e.id)??``)+stripTerminalControls(e.delta);if(n.reasoning.set(e.id,r),t.reasoning===`full`){this.#nn(e.id,r,!0,t);break}break}case`reasoning-complete`:{if(t.reasoning===`hidden`)break;let r=n.reasoning.get(e.id)??``;if(t.reasoning===`full`){this.#nn(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#rn({input:void 0,preparing:!0,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-call`:if(this.#d?.recordToolCall(e.toolName),t.tools===`hidden`)break;this.#rn({input:e.input,status:`running`,toolCallId:e.toolCallId,toolName:e.toolName},t,n);break;case`tool-approval-request`:{if(t.tools===`hidden`)break;let r=n.tools.get(e.toolCallId);if(r===void 0)break;this.#rn({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#un(e.toolCallId,n);if(r===void 0)break;this.#rn({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#un(e.toolCallId,n);if(this.#d?.append({source:`tool`,summary:`${r?.toolName??e.toolCallId} failed`,detail:e.errorText}),t.tools===`hidden`||r===void 0)break;this.#rn({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#un(e.toolCallId,n);if(r===void 0)break;this.#rn({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#Jt(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:if(n.cancelled=!0,!n.restoreCancelledPrompt)break;this.#He=!0,!this.#Ge&&this.#Ke!==void 0&&this.#W.text.length===0&&(this.#W=lineOf(this.#Ke),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#dn(e.usage),this.#fn();break}}#tn(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Xt({id:e,kind:`assistant`,body:r,live:n}),this.#fn())}#nn(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Xt({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#fn())}#rn(e,t,n){if(n.tools.set(e.toolCallId,e),this.#v.has(e.toolCallId)||this.#cn(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#y.set(e.toolCallId,r);let i=this.#in(e);this.#Xt(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#ln(n),this.#fn()}#in(e){e.output!==void 0&&this.#w.observeRead(e.output);let t={};this.#an(e.toolName)&&(t.isSubagent=!0);let n=readWriteFileInput(e.toolName,e.input);if(n===void 0)return t.isSubagent===!0?t:void 0;let r=this.#w.observeWrite({path:n.path,content:n.content,callId:e.toolCallId});r!==void 0&&(t.previousContent=r);let i=writeExistedFlag(e.output);return i!==void 0&&(t.existed=i),t}#an(e){let t=this.#E?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#on(e){for(let t of e.tools.keys()){if(this.#v.has(t))continue;let e=this.#y.get(t)??toolSectionId(t),n=this.#h.get(e);n?.kind===`tool`&&n.status===`running`&&(n.status=`error`,n.result=`interrupted`,n.live=!1)}}#sn(e){for(let[t,n]of e.tools){if(n.preparing!==!0)continue;e.tools.delete(t);let r=this.#y.get(t)??toolSectionId(t);this.#Qt(r),this.#y.delete(t)}}#cn(e){let t=readTodoToolItems(e.toolName,e.input);if(t===void 0)return!1;if(t.length>0&&allTodoItemsSettled(t)){let e=JSON.stringify(t);this.#ze!==e&&(this.#ze=e,this.#Wt({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#jn(),this.#i).join(`
|
|
7
|
+
`),live:!1})),this.#Re=void 0}else this.#Re=t.length>0?t:void 0,this.#ze=void 0;return this.#fn(),!0}#ln(e){let t=[];for(let n of e.tools.values()){if(this.#v.has(n.toolCallId))continue;let e=this.#y.get(n.toolCallId)??toolSectionId(n.toolCallId),r=this.#h.get(e);r?.kind===`tool`&&t.push({block:r,active:isActiveToolStatus(n.status)})}applyCohortLiveness(t)}#un(e,t){let n=t.tools.get(e);if(n!==void 0)return n;let r=this.#y.get(e)??toolSectionId(e),i=this.#h.get(r);if(!(i===void 0||i.kind!==`tool`))return{errorText:i.status===`error`&&typeof i.result==`string`?i.result:void 0,input:i.toolInput,output:i.toolOutput,status:i.status??`running`,toolCallId:e,toolName:i.toolName??i.title??`tool`}}#dn(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#ye=(t??0)+(n??0)),this.#be=t??this.#be,this.#Se=n??this.#Se,this.#Se!=null&&this.#we!==void 0){let e=(Date.now()-this.#we)/1e3;e>0&&(this.#Ce=this.#Se/e)}}#fn(){if(this.#Z){if(this.#_e){this.#ve=!0;return}this.#_e=!0;try{do this.#ve=!1,this.#pn();while(this.#ve)}finally{this.#_e=!1}}}#pn(){if(!this.#Z)return;if(this.#Ye!==void 0){this.#Ye.repaint();return}let e=this.#jn(),t=this.#Sn(e),n=this.#D===void 0?[]:this.#_n(),r=Math.max(1,this.#Mn()-n.length-t.length),i=[],a=this.#j,o=groupToolBlocksForDisplay(this.#m),s=0;for(;s<o.length&&o[s].display.live===!1;)s+=1;if(s>0){let e=new Set(o.slice(0,s).flatMap(e=>e.members));for(let t=this.#m.length-1;t>=0;--t)e.has(this.#m[t])&&this.#m.splice(t,1)}for(let t of o.slice(0,s)){for(let e of t.members)this.#_.push(e),e.id&&(this.#g.add(e.id),this.#h.delete(e.id));if(this.#Kn(t.display))continue;let n=this.#vn(t.display,e,a);a=previousBlockOf(t.display),this.#j=a,i.push(...n),this.#A.push(...n)}let c=[];for(let{display:t}of o.slice(s)){if(this.#Kn(t))continue;let n=this.#vn(t,e,a);a=previousBlockOf(t);for(let e=0;e<n.length;e+=1)c.push({block:t,row:n[e]})}let l=[...n,...clipLiveRows(c.map(e=>e.row),r,e,this.#i),...t];i.length>0?this.#n.flush(i,l):this.#n.update(l)}#mn(){if(!this.#Z)return;let e=this.#jn(),t=this.#Sn(e),n=Math.max(1,this.#Mn()-t.length),r=this.#j,i=[];for(let{display:t}of groupToolBlocksForDisplay(this.#m)){if(this.#Kn(t))continue;let n=this.#vn(t,e,r);r=previousBlockOf(t),i.push(...n)}let a=[...clipLiveRows(i,n,e,this.#i),...t];this.#n.clearAll(),this.#n.flush([...this.#_n(),...this.#A],a)}logDisplayMode(){return this.#p}setLogDisplayMode(e){e!==this.#p&&(this.#p=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#gn(),this.#Z&&this.#mn())}flushDelayedDevBuildErrors(){let e=this.#Oe;e!==void 0&&(this.#Oe=void 0,this.#Wt({kind:`log`,title:`stderr`,body:e,live:!0}),this.#fn())}#hn(){this.#ue=!0,this.#le!==void 0&&clearTimeout(this.#le),this.#le=setTimeout(()=>{this.#ue=!1,this.#le=void 0,this.#fn()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#p)),this.#fn()}#gn(){let e=this.#jn();this.#A.length=0;let t;for(let{display:n}of groupToolBlocksForDisplay(this.#_,{logCoalescing:`runs`})){if(this.#Kn(n))continue;let r=this.#vn(n,e,t);t=previousBlockOf(n),this.#A.push(...r)}this.#j=t}#_n(){let e=this.#E,t=this.#D;if(e===void 0&&t===void 0)return[];let n={name:e?.name??t?.name,theme:this.#i,width:this.#jn()};e?.info!==void 0&&(n.info=e.info);let i=e?.tip??t?.tip;return i!==void 0&&(n.tip=i),buildAgentHeader(n)}#vn(e,t,n){let r={activityPulse:this.#bn(this.#oe,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)};n!==void 0&&(r.previous=n);let i=renderBlockLines(e,t,this.#i,r);return(e.depth??0)===0&&leadsWithGap(e,n)?[``,...i]:i}#yn(){return this.#i.spinner[this.#ae%this.#i.spinner.length]??``}#bn(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#xn(e,t){return e.indicator.kind===`spinner`?{glyph:this.#yn(),color:`yellow`}:{glyph:this.#bn(e.indicator.startedAtMs,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),color:t?.kind===`external-action`?`yellow`:`green`}}#Sn(e){let n=this.#i.colors,r=[``];if(this.#Fe!==void 0)return r.push(...this.#Fe(e),``),this.#On(r,e),r;let a=this.#Ie;if(a!==void 0){let t=this.#xn(a,a.status),n;if(a.status!==void 0){let{startedAtMs:e,...r}=a.status,i=Date.now()-e,o=i>=5e3?` ${formatTurnDuration(i)}`:``;n={...r,text:`${r.text}${o}`,indicator:t}}let i;if(a.question!==void 0){let t=a.question(e);i={kind:`question`,rows:t},n!==void 0&&(i={kind:`question`,rows:t,status:n})}else n===void 0?i=a.preview===void 0?{kind:`idle`,indicator:t}:{kind:`preview`,text:a.preview,indicator:t}:(i={kind:`status`,status:n},a.preview!==void 0&&(i={kind:`status`,status:n,preview:a.preview}));let o={title:a.title,lines:a.summary===void 0?a.hideLinesWhileQuestion===!0?[]:a.lines:[{text:a.summary.headline,tone:`success`},...a.summary.facts.map(e=>({text:`${e.label}: ${e.value}`,tone:`info`}))],content:i};return r.push(...renderFlowPanel(o,this.#i,e)),this.#kn(r,e),r}this.#Le!==void 0&&r.push(...renderAttentionRows(this.#Le,e,this.#i),``),this.#Re!==void 0&&r.push(...renderTodoPanelRows({items:this.#Re,width:e,theme:this.#i,working:this.#G||this.#K.kind===`waiting`,pulse:this.#bn(this.#oe,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)}),``);let o=renderMessageQueueRows({view:this.#Be.view(),width:e,theme:this.#i,working:this.#G});if(o.length>0&&r.push(...o,``),this.#R){let i=this.#z===void 0?void 0:inlineCommandHint(this.#z);i===void 0&&this.#z!==void 0&&isTypeaheadOpen(this.#z)&&r.push(...renderCommandSuggestions(this.#z,this.#i,e)),this.#ne&&r.push(clip(n.dim(`Press Ctrl+C again to exit`),e),``);let a=isPromptControlCommand(this.#F),o=i?n.dim(` ${i}`):``,s=[];this.#D!==void 0&&s.push(clip(n.dim(`${this.#i.glyph.dot} Building your agent…`),e)),this.#On(s,e);let u=Math.max(1,this.#Mn()-1-r.length-1-s.length),f={text:this.#F,cursor:this.#I,width:e,theme:this.#i,caretVisible:this.#ie,isCommand:a,ghost:o,maxRows:u};return this.#B&&this.#F.length===0&&(f.placeholder=this.#H?``:promptPlaceholder(Date.now()-this.#V)),r.push(...promptInputRows(f)),r.push(...s),r}let s=this.#K.kind===`waiting`&&this.#Y===void 0;if(this.#G||s){r.push(this.#Cn(e)),this.#En(r,e);let t=[];return this.#On(t,e),!this.#G&&t.length>0&&r.push(``),r.push(...t),r}if(this.#W.text.length>0)return this.#Dn(r,e,{inert:!1}),this.#On(r,e),r;let u=this.#Y??(this.#J.length>0?this.#J:`Ready`),f=this.#An(),p=n.dim(this.#i.glyph.dot),m=f?`${p} ${u} ${n.dim(this.#i.glyph.dot)} ${f}`:`${p} ${u}`;return r.push(clip(m,e)),this.#On(r,e),r}#Cn(e){let t=this.#i.colors,n=this.#bn(this.#oe,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),r=this.#K,i=this.#U.startedAtMs??this.#we??(r.kind===`waiting`?r.startedAtMs:Date.now()),a=Date.now()-i,o=`${typewriterText(`Working for`,a,80)} ${this.#wn(a)}`;return clip(`${t.yellow(n)} ${t.dim(o)}`,e)}#wn(e){return`${formatTurnDuration(e)}${this.#Tn()}`}#Tn(){let{inputTokens:e,outputTokens:t}=this.#U.usage;return e===0&&t===0?``:` ${this.#i.glyph.dash.repeat(2)} ${formatTokenFlow({inputTokens:e,outputTokens:t},this.#i.glyph)}`}#En(e,t){this.#G&&this.#Dn(e,t,{inert:!0})}#Dn(e,t,n){e.push(``);let r={text:this.#W.text,cursor:this.#W.cursor,width:t,theme:this.#i,caretVisible:!0,isCommand:!1,ghost:``,maxRows:4,inert:n.inert};n.inert&&this.#W.text.length===0&&(r.placeholder=``),e.push(...promptInputRows(r))}#On(e,t){let n=this.#P===void 0?``:` `,r=Math.max(1,t-n.length),i={theme:this.#i,width:r};this.#je&&this.#Ae!==void 0&&(i.devBuild=this.#Ae),this.#ue&&(i.logLevel=this.#p);let a=this.#E?.serverUrl;if(a!==void 0&&this.#P===void 0){let e=new URL(a).port;e.length>0&&(i.serverPort=e)}let o=this.#E?.info?.agent.model;o?.id!==void 0&&(i.model=o.id),o?.reasoning!==void 0&&o.reasoning!==`provider-default`&&(i.reasoning=o.reasoning),readGatewayServiceTier(o?.providerOptions).kind===`priority`&&(i.fastMode=!0);let s=o?.endpoint;s!==void 0&&(i.endpoint=s),this.#N!==void 0&&(i.vercel=this.#N),this.#P!==void 0&&(i.remote=this.#P);let c=buildStatusLine(i);c!==void 0&&e.push(clip(`${n}${c}`,t))}#kn(e,t){if(this.#P===void 0)return;let n=Math.max(1,t-2),r=buildStatusLine({remote:this.#P,theme:this.#i,width:n});r!==void 0&&e.push(``,clip(` ${r}`,t))}#An(){let e=this.#i.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#ye,outputTokens:this.#Se,tokensPerSecond:this.#Ce},this.#l);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#i.glyph.dot} `)):``}#jn(){return Math.max(20,this.#t.columns||80)}#Mn(){return Math.max(8,this.#t.rows||24)}#Nn(){if(this.#Te!==void 0||!this.#u)return;this.#Ee=``,this.#De=``;let capture=(e,t)=>{let n=e.write.bind(e);return e.write=((e,n,r)=>{let i=typeof n==`string`?n:void 0,a=typeof n==`function`?n:r;return this.#In(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#d?.subscribeLogRecords(e=>this.#Fn(e)),this.#Te=()=>{this.#d?.unsubscribeLogRecords(),e(),t()}}#Pn(){let e=this.#Te;e!==void 0&&(this.#Te=void 0,e(),this.#Ee.length>0&&(this.#d?.append({source:`stdout`,detail:this.#Ee}),this.#Gn(`stdout`)&&process.stdout.write(`${this.#Ee}\n`),this.#Ee=``),this.#De.length>0&&(this.#d?.append({source:`stderr`,detail:this.#De}),this.#Gn(`stderr`)&&process.stderr.write(`${this.#De}\n`),this.#De=``))}#Fn(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#Rn(`[eve:${e.namespace}] ${e.message}${t}`),this.#fn()}#In(e,t){let n=(e===`stdout`?this.#Ee:this.#De)+t;if(e===`stdout`&&parseDevRebuildLogLine(n.trimEnd())!==void 0){this.#Ee=``,this.#d?.append({source:e,detail:n.trimEnd()}),this.#Ln(n.trimEnd()),this.#fn();return}let r=n.lastIndexOf(`
|
|
8
|
+
`),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#Ee=i:this.#De=i,r===-1)return;let a=stripAnsi(n.slice(0,r)).replace(/\s+$/u,``);a.trim().length!==0&&(this.#d?.append({source:e,detail:a}),e===`stdout`?this.#Ln(a):this.#Rn(a),this.#fn())}#Ln(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
|
|
9
|
+
`);t=[],e.trim().length!==0&&this.#Wt({kind:`log`,title:`stdout`,body:e,live:!0})};for(let n of e.split(`
|
|
10
|
+
`)){let e=parseSandboxLogLine(n.trimEnd());if(e!==void 0){flushPending(),this.#Wt({kind:`sandbox`,body:e,live:!1});continue}let r=parseDevRebuildLogLine(n.trimEnd());if(r===void 0){t.push(n);continue}flushPending(),this.#Bn(r,n.trimEnd())}flushPending()}#Rn(e){let t=e.split(`
|
|
11
|
+
`),n=t.findIndex(e=>parseDevRebuildLogLine(e.trimEnd())?.kind===`failed`);if(n===-1){if(this.#d===void 0){this.#Wt({kind:`log`,title:`stderr`,body:e,live:!0});return}let t=presentDiagnostic(e,this.#d.displayPath);if(t.kind===`inline`){this.#Wt({kind:`log`,title:`stderr`,body:t.text,live:!0});return}this.#Wt({kind:`log`,title:`stderr`,body:formatStoredDiagnostic(t),logVisibility:`stderr-only`,live:!0}),this.#Wt({kind:`log`,title:`stderr`,body:e,logVisibility:`all-only`,live:!0});return}let r=t.slice(0,n).join(`
|
|
12
|
+
`);r.trim().length>0&&this.#Wt({kind:`log`,title:`stderr`,body:r,live:!0});let i=t.slice(n).join(`
|
|
13
|
+
`);this.#zn(i)}#zn(e){if(this.#Hn(),this.#p===`all`){if(e.trim().length===0)return;this.#Wt({kind:`log`,title:`stderr`,body:e,live:!0});return}this.#Oe=e}#Bn(e,t){let n=this.#Un();if(e.kind===`failed`){this.#zn(t);return}if(e.kind===`rebuilding`){let t=summarizeChangedFiles(e.events,e.more);if(this.#Vn({phase:`building`,summary:t}),n!==void 0){n.state.summary=t,n.block.body=formatDevRebuildStatus(t,`rebuilding`);return}let r=`dev-rebuild:${this.#Ne}`;this.#Ne+=1,this.#ke={id:r,summary:t},this.#Wt({kind:`log`,id:r,title:`stdout`,body:formatDevRebuildStatus(t,`rebuilding`),live:!0});return}let r=n?.state.summary??this.#Ae?.summary;if(r!==void 0&&this.#Vn({phase:`complete`,summary:r}),n!==void 0){n.block.body=formatDevRebuildStatus(n.state.summary,e.kind),e.kind===`rebuilt`&&(this.#Oe=void 0);return}e.kind===`rebuilt`&&(this.#Oe=void 0),this.#Wt({kind:`log`,title:`stdout`,body:t,live:!0})}#Vn(e){this.#Me!==void 0&&clearTimeout(this.#Me),this.#Ae=e,this.#je=e.phase===`complete`,this.#Me=setTimeout(()=>{e.phase===`building`?(this.#je=!0,this.#Me=void 0):this.#Hn(),this.#fn()},e.phase===`building`?250:4e3)}#Hn(){this.#Me!==void 0&&clearTimeout(this.#Me),this.#Ae=void 0,this.#je=!1,this.#Me=void 0}#Un(){let e=this.#ke;if(e===void 0)return;let t=this.#h.get(e.id);if(!(t===void 0||t.live!==!0))return{state:e,block:t}}#Wn(){let e=this.#ke;if(e===void 0)return;this.#ke=void 0;let t=this.#h.get(e.id);t!==void 0&&(t.live=!1)}#Gn(e){switch(this.#p){case`none`:return!1;case`stderr`:return e===`stderr`;case`sandbox`:return e===`sandbox`;case`all`:return!0}}#Kn(e){return e.kind===`sandbox`?!this.#Gn(`sandbox`):e.kind===`log`?e.logVisibility===`stderr-only`?this.#p!==`stderr`:e.logVisibility===`all-only`?this.#p!==`all`:!this.#Gn(e.title===`stderr`?`stderr`:`stdout`):!1}};function chunkToString(e,t){return typeof e==`string`?e:Buffer.from(e).toString(t)}async function*iterateTUIStream(e){if(e instanceof ReadableStream){let t=e.getReader();try{for(;;){let{done:e,value:n}=await t.read();if(e)return;yield n}}finally{t.releaseLock()}return}yield*e}function clip(e,t){return clipVisible(e,t)}function promptInputRows({text:e,cursor:t,width:n,theme:r,caretVisible:i,isCommand:a,ghost:o,maxRows:s,placeholder:c,inert:l}){let u=r.colors;if(e.length===0&&c!==void 0){let e=renderInputWithBlockCursor({...visibleLine({text:c,cursor:0},Math.max(1,n-3),r.glyph.ellipsis),visible:i,inverse:u.inverse,render:e=>u.dim(renderInputText(e))});return[clip(`${u.dim(r.glyph.promptIdle)} ${e}`,n),``]}let style=e=>{let t=renderInputText(e);return a&&t.length>0?u.blue(t):t},d=layoutPromptInput({text:e,cursor:t}),f=Math.min(Math.max(1,s),d.rows.length),p=Math.max(0,Math.min(d.caretRow-f+1,d.rows.length-f)),m=l===!0?u.dim(r.glyph.prompt):u.cyan(r.glyph.prompt),h=u.dim(r.glyph.ellipsis),g=Math.max(1,n-3),_=[];for(let e=p;e<p+f;e+=1){let t=d.rows[e],a=e===0?m:` `;(e===p&&p>0||e===p+f-1&&p+f<d.rows.length)&&(a=h);let s;if(e===d.caretRow){let{before:e,under:n,after:a}=visibleLine({text:t.text,cursor:d.caretOffset},g,r.glyph.ellipsis);s=renderInputWithBlockCursor({before:e,under:n,after:a,visible:i,inverse:u.inverse,render:style}),o.length>0&&d.rows.length===1&&(s+=o)}else s=style(t.text);_.push(clip(`${a} ${s}`,n))}return _.push(``),_}function previousBlockOf(e){let t={kind:e.kind};return e.title!==void 0&&(t.title=e.title),t}function isActiveToolStatus(e){return e===`running`||e===`approval`}function applyCohortLiveness(e){let t=e.some(e=>e.active);for(let n of e)n.block.live=t||n.active}function leadsWithGap(e,t){if(e.kind===`tool`&&(t?.kind===`user`||t?.kind===`assistant`||t?.kind===`question`))return!0;if(e.kind===`sandbox`&&t?.kind===`sandbox`)return!1;if(t?.kind===`sandbox`&&e.kind!==`sandbox`||t?.kind===`log`)return!0;switch(e.kind){case`user`:case`assistant`:case`reasoning`:case`subagent`:case`error`:case`notice`:case`question`:case`connection-auth`:case`sandbox`:case`log`:case`command`:case`warning`:case`flow`:case`turn-stats`:case`session-boundary`:case`todo-list`:case`agent-header`:return!0;default:return!1}}function parseSandboxLogLine(e){let t=e.trim();if(!t.startsWith(`eve: `))return;let n=t.slice(5);return/\bsandbox\b/i.test(n)&&!isLowValueSandboxLogLine(n)?n:void 0}function isLowValueSandboxLogLine(e){return/^initializing (?:\d+ )?sandbox templates?\b/i.test(e)||/^initialized \d+ sandbox\b/i.test(e)||/^reused cached sandbox template\b/i.test(e)||/^sandbox template "[^"]+" \([^)]+\): (checking|reusing|loading microsandbox runtime|microsandbox runtime ready)\b/i.test(e)}function clipLiveRows(e,t,n,r){if(e.length<=t)return[...e];if(t<=1)return[clip(hiddenRowsMarker(e.length,r),n)];let i=t-1;return[clip(hiddenRowsMarker(e.length-i,r),n),...e.slice(e.length-i)]}function hiddenRowsMarker(e,t){let n=e.toLocaleString(),r=e===1?`row`:`rows`;return t.colors.dim(`${t.glyph.dot} ${t.glyph.ellipsis} ${n} earlier ${r} hidden while streaming`)}function collapseReasoning(e,t){switch(e){case`collapsed`:return!0;case`auto-collapsed`:return!t;default:return!1}}function renderNativeToolBlock(e,t,n,r){let i=e.preparing===!0?presentPreparingTool(e.toolName,r):presentTool(e.toolName,e.input,r),a={id:t,kind:`tool`,title:stripTerminalControls(i.title),subtitle:stripTerminalControls(i.subtitle),status:e.status,live:e.status===`running`||e.status===`approval`,expanded:n,toolInput:e.input,toolName:e.toolName,toolGroup:i.group};return i.doneTitle!==void 0&&(a.doneTitle=stripTerminalControls(i.doneTitle)),i.detail!==void 0&&(a.detailLines=i.detail,a.keepDetailWhenDone=i.keepDetailWhenDone===!0),e.output===void 0?e.errorText!==void 0&&(a.result=stripTerminalControls(e.errorText)):(a.result=i.summarizeResult(e.output),a.toolOutput=e.output),a}function writeExistedFlag(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e.existed;return typeof t==`boolean`?t:void 0}function subagentToolStatus(e){switch(e){case`preparing`:return`running`;case`approval-requested`:return`approval`;case`executing`:return`running`;case`done`:return`done`;case`failed`:return`error`;case`rejected`:return`denied`}}function formatToolApprovalTitle(e){return stripTerminalControls(e.title??e.toolName)}function toolSectionId(e){return`tool:${e}`}function questionSectionId(e){return`question:${e}`}function subagentHeaderId(e){return`subagent:${e}:header`}function subagentStepSectionId(e,t){return`subagent:${e}:step:${t}`}function subagentToolSectionId(e,t){return`subagent:${e}:tool:${t}`}function connectionAuthSectionId(e){return`connection-auth:${e}`}function connectionAuthTerminalMessage(e){switch(e){case`authorized`:return`Authorization complete`;case`declined`:return`Authorization declined`;case`failed`:return`Authorization failed`;case`timed-out`:return`Authorization timed out`;case`required`:case`pending`:return}}function formatConnectionAuthContent(e,t){let n=[];if(t!==void 0)n.push(t);else{let t=stripTerminalControls(e.description);t.length>0&&n.push(t);let r=e.challenge;r?.url&&n.push(`URL: ${stripTerminalControls(r.url)}`),r?.userCode&&n.push(`Code: ${stripTerminalControls(r.userCode)}`),r?.expiresAt&&n.push(`Expires: ${stripTerminalControls(r.expiresAt)}`),r?.instructions&&n.push(stripTerminalControls(r.instructions))}if(e.reason!==void 0){let t=stripTerminalControls(e.reason);t.length>0&&n.push(`Reason: ${t}`)}return n.join(`
|
|
14
14
|
`)}function formatQuestionContent(e,t,n){let r=n.colors,i=[],a=e.options??[];if(a.length>0){for(let[e,o]of a.entries()){let a=stripTerminalControls(o.label),s=o.description===void 0?``:stripTerminalControls(o.description),c=t===e,l=s.length>0?`${c?` `:` `}${r.dim(`— ${s}`)}`:``,u=renderCursorRow(c?`${n.glyph.selectedPointer} ${a}`:` ${a}`,c,r);i.push(`${u}${l}`)}if(e.allowFreeform===!0){let e=t===a.length,o=`Type your own answer`,s=e?`${n.glyph.selectedPointer} ${o}`:` ${r.dim(o)}`;i.push(renderCursorRow(s,e,r))}}else i.push(r.dim(` (type your answer)`));return i.join(`
|
|
15
15
|
`)}function resolveQuestionText(e,t){let n=e.trim();if(n.length===0)return;let r=n.toLowerCase(),i=t.options??[];if(i.length>0){let e=matchQuestionOption(r,i);if(e!==void 0)return{optionId:e.id,label:e.label}}if(t.allowFreeform===!0||i.length===0)return{text:n,label:n}}function matchQuestionOption(e,t){let n=t.find(t=>t.id.toLowerCase()===e);if(n!==void 0)return n;let r=t.find(t=>t.label.toLowerCase()===e);if(r!==void 0)return r;let i=Number(e);if(Number.isInteger(i)&&i>0&&i<=t.length)return t[i-1]}export{TerminalRenderer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDevDiagnostics}from"../diagnostics.js";import{remoteHost}from"./target.js";import{promptCommandsFor}from"./prompt-commands.js";import{pickAgentHeaderTip}from"./agent-header.js";import{probeMcpConnection}from"./mcp-connection-status.js";import{createPromptCommandHandler}from"./prompt-command-handler.js";import{formatRemoteAuthChallengeMessage}from"./remote-auth-result.js";import{TerminalRenderer}from"./terminal-renderer.js";import{EveTUIRunner}from"./runner.js";import{Client}from"#client/index.js";import{toErrorMessage}from"#shared/errors.js";import{resolveDevelopmentOidcToken,resolveLinkedDevelopmentOidcToken}from"#services/dev-client/request-headers.js";import{isVercelAuthChallenge}from"#services/dev-client/vercel-auth-error.js";import{resolveVercelDeployment}from"#setup/vercel-deployment.js";import{resolveLocalDevelopmentClientOptions,resolveRemoteDevelopmentClientOptions}from"#services/dev-client/client-options.js";import{createDevelopmentCredentialGate}from"#services/dev-client/credential-gate.js";async function startDevelopmentTuiStartup(t){let n=await createDevDiagnostics(t.appRoot).catch(()=>void 0),i=pickAgentHeaderTip(),a=new TerminalRenderer({...t,diagnostics:n,onExitRequest:t.onExitRequest});return a.beginStartupDraft({initialDraft:t.initialInput,tip:i,title:t.name??`eve`}),{diagnostics:n,headerTip:i,renderer:a,finish:()=>a.finishStartupDraft(),async shutdown(){a.shutdown(),await n?.close()}}}function prepareRemoteTarget(e){return{target:e,credentials:createDevelopmentCredentialGate(e.serverUrl),resolveOidcToken:resolveDevelopmentOidcToken,resolveDeployment:n=>resolveVercelDeployment({workspaceRoot:e.workspaceRoot,host:remoteHost(e),signal:n})}}function prepareDevelopmentTarget(e){return e.kind===`local`?{kind:`local`,target:e}:{kind:`remote`,target:e,remote:prepareRemoteTarget(e)}}async function runDevelopmentTui(t){let{target:r,headers:o,initialInput:s,onBootProgress:c,lifecycle:l,startup:u,withExclusiveTerminal:d,...f}=t,p=prepareDevelopmentTarget(r),{serverUrl:m}=r,h=
|
|
1
|
+
import{createDevDiagnostics}from"../diagnostics.js";import{remoteHost}from"./target.js";import{promptCommandsFor}from"./prompt-commands.js";import{pickAgentHeaderTip}from"./agent-header.js";import{probeMcpConnection}from"./mcp-connection-status.js";import{createPromptCommandHandler}from"./prompt-command-handler.js";import{formatRemoteAuthChallengeMessage}from"./remote-auth-result.js";import{TerminalRenderer}from"./terminal-renderer.js";import{EveTUIRunner}from"./runner.js";import{Client}from"#client/index.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{toErrorMessage}from"#shared/errors.js";import{resolveDevelopmentOidcToken,resolveLinkedDevelopmentOidcToken}from"#services/dev-client/request-headers.js";import{isVercelAuthChallenge}from"#services/dev-client/vercel-auth-error.js";import{resolveVercelDeployment}from"#setup/vercel-deployment.js";import{appendUserAgentProduct}from"#internal/user-agent.js";import{resolveLocalDevelopmentClientOptions,resolveRemoteDevelopmentClientOptions}from"#services/dev-client/client-options.js";import{createDevelopmentCredentialGate}from"#services/dev-client/credential-gate.js";async function startDevelopmentTuiStartup(t){let n=await createDevDiagnostics(t.appRoot).catch(()=>void 0),i=pickAgentHeaderTip(),a=new TerminalRenderer({...t,diagnostics:n,onExitRequest:t.onExitRequest});return a.beginStartupDraft({initialDraft:t.initialInput,tip:i,title:t.name??`eve`}),{diagnostics:n,headerTip:i,renderer:a,finish:()=>a.finishStartupDraft(),async shutdown(){a.shutdown(),await n?.close()}}}function prepareRemoteTarget(e){return{target:e,credentials:createDevelopmentCredentialGate(e.serverUrl),resolveOidcToken:resolveDevelopmentOidcToken,resolveDeployment:n=>resolveVercelDeployment({workspaceRoot:e.workspaceRoot,host:remoteHost(e),signal:n})}}function prepareDevelopmentTarget(e){return e.kind===`local`?{kind:`local`,target:e}:{kind:`remote`,target:e,remote:prepareRemoteTarget(e)}}function withTuiUserAgent(e){let t=new Headers(e);return appendUserAgentProduct(t,`eve-tui/${resolveInstalledPackageInfo().version}`),Object.fromEntries(t.entries())}async function runDevelopmentTui(t){let{target:r,headers:o,initialInput:s,onBootProgress:c,lifecycle:l,startup:u,withExclusiveTerminal:d,...f}=t,p=prepareDevelopmentTarget(r),{serverUrl:m}=r,h={headers:withTuiUserAgent(o)},g=new Client(p.kind===`local`?resolveLocalDevelopmentClientOptions({...h,serverUrl:m,token:()=>resolveLinkedDevelopmentOidcToken(p.target.workspaceRoot)}):resolveRemoteDevelopmentClientOptions({...h,serverUrl:m,credentials:p.remote.credentials})),_={...f,client:g,serverUrl:m,promptCommandHandler:createPromptCommandHandler({target:r}),availablePromptCommands:promptCommandsFor(r.kind),formatTransportError:e=>isVercelAuthChallenge(e)?formatRemoteAuthChallengeMessage(m):toErrorMessage(e)};p.kind===`local`?(_.appRoot=p.target.workspaceRoot,_.probeMcpConnection=probeMcpConnection):_.remote=p.remote,s!==void 0&&(_.initialInput=s),u!==void 0&&(_.renderer=u.renderer,_.startup=u),c!==void 0&&(_.onBootProgress=c),l!==void 0&&(_.lifecycle=l),d!==void 0&&(_.withExclusiveTerminal=d);let v=u?.diagnostics??(p.kind===`local`?await createDevDiagnostics(p.target.workspaceRoot).catch(()=>void 0):void 0);v!==void 0&&(_.diagnostics=v);try{await new EveTUIRunner(_).run()}finally{await v?.close()}}export{runDevelopmentTui,startDevelopmentTuiStartup};
|
|
@@ -23,13 +23,13 @@ declare const EXTENSION_CAPABILITY_CONTRACTS: {
|
|
|
23
23
|
readonly dropped: {};
|
|
24
24
|
};
|
|
25
25
|
readonly channel: {
|
|
26
|
-
readonly current:
|
|
27
|
-
readonly supported: readonly [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
26
|
+
readonly current: 12;
|
|
27
|
+
readonly supported: readonly [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
28
28
|
readonly dropped: {};
|
|
29
29
|
};
|
|
30
30
|
readonly schedule: {
|
|
31
|
-
readonly current:
|
|
32
|
-
readonly supported: readonly [1, 2, 3, 4];
|
|
31
|
+
readonly current: 5;
|
|
32
|
+
readonly supported: readonly [1, 2, 3, 4, 5];
|
|
33
33
|
readonly dropped: {};
|
|
34
34
|
};
|
|
35
35
|
readonly subagent: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFile,writeFile}from"node:fs/promises";import{z}from"#compiled/zod/index.js";import{join}from"node:path";import{formatValidationError}from"#runtime/validation.js";const EXTENSION_COMPATIBILITY_MANIFEST_KIND=`eve-extension`,EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION=2,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME=`_manifest.json`,EXTENSION_CAPABILITY_CONTRACTS={extension:{current:1,supported:[1],dropped:{}},tool:{current:21,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20,21],dropped:{15:`TaskExec replaces stageEffect with send`}},dynamicTool:{current:21,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21],dropped:{}},channel:{current:
|
|
1
|
+
import{readFile,writeFile}from"node:fs/promises";import{z}from"#compiled/zod/index.js";import{join}from"node:path";import{formatValidationError}from"#runtime/validation.js";const EXTENSION_COMPATIBILITY_MANIFEST_KIND=`eve-extension`,EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION=2,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME=`_manifest.json`,EXTENSION_CAPABILITY_CONTRACTS={extension:{current:1,supported:[1],dropped:{}},tool:{current:21,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20,21],dropped:{15:`TaskExec replaces stageEffect with send`}},dynamicTool:{current:21,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21],dropped:{}},channel:{current:12,supported:[1,2,3,4,5,6,7,8,9,10,11,12],dropped:{}},schedule:{current:5,supported:[1,2,3,4,5],dropped:{}},subagent:{current:5,supported:[3,4,5],dropped:{1:`Persistent subagent sessions are now the default and the experimental opt-in was removed`,2:`Persistent subagent sessions are now the default and the experimental opt-in was removed`}},connection:{current:8,supported:[1,2,3,4,5,6,7,8],dropped:{}},hook:{current:16,supported:[10,11,12,13,14,15,16],dropped:{1:`Model identity moved from session.started runtime metadata to step.started call attribution.`,2:`Model identity moved from session.started runtime metadata to step.started call attribution.`,3:`Model identity moved from session.started runtime metadata to step.started call attribution.`,4:`Model identity moved from session.started runtime metadata to step.started call attribution.`,5:`Model identity moved from session.started runtime metadata to step.started call attribution.`,6:`Model identity moved from session.started runtime metadata to step.started call attribution.`,7:`Model identity moved from session.started runtime metadata to step.started call attribution.`,8:`Model identity moved from session.started runtime metadata to step.started call attribution.`,9:`Model identity moved from session.started runtime metadata to step.started call attribution.`}},skill:{current:1,supported:[1],dropped:{}},dynamicSkill:{current:13,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13],dropped:{}},instructions:{current:2,supported:[1,2],dropped:{}},dynamicInstructions:{current:14,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13,14],dropped:{}},config:{current:1,supported:[1],dropped:{}},state:{current:4,supported:[1,2,3,4],dropped:{}}},EXTENSION_CAPABILITY_VERSIONS=Object.fromEntries(Object.entries(EXTENSION_CAPABILITY_CONTRACTS).map(([e,t])=>[e,t.current])),EXTENSION_CAPABILITY_SUPPORT=Object.keys(EXTENSION_CAPABILITY_CONTRACTS).reduce((e,t)=>(e[t]=EXTENSION_CAPABILITY_CONTRACTS[t].supported,e),{}),extensionCompatibilityManifestV1Schema=z.object({kind:z.literal(EXTENSION_COMPATIBILITY_MANIFEST_KIND),formatVersion:z.literal(1),builtWithEve:z.string().min(1),requires:z.record(z.string(),z.number().int().positive())}).strict(),extensionCompatibilityManifestV2Schema=extensionCompatibilityManifestV1Schema.extend({formatVersion:z.literal(2),build:z.object({externalDependencies:z.array(z.string().min(1)).readonly()}).strict().optional()}),extensionCompatibilityManifestSchema=z.union([extensionCompatibilityManifestV1Schema,extensionCompatibilityManifestV2Schema]);function serializeExtensionCompatibilityManifest(e){return`${JSON.stringify(e,null,2)}\n`}function parseExtensionCompatibilityManifest(e,t){let n;try{n=JSON.parse(e)}catch(e){throw Error(`Extension compatibility manifest "${t}" is not valid JSON: ${e instanceof Error?e.message:String(e)}`)}let r=extensionCompatibilityManifestSchema.safeParse(n);if(!r.success)throw Error(`Extension compatibility manifest "${t}" is invalid. ${formatValidationError(r.error)}`);return r.data}async function readExtensionCompatibilityManifest(t){return parseExtensionCompatibilityManifest(await readFile(t,`utf8`),t)}async function writeExtensionCompatibilityManifest(e,n){await writeFile(join(e,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME),serializeExtensionCompatibilityManifest(n),`utf8`)}function findUnsupportedExtensionCapabilities(e,t=EXTENSION_CAPABILITY_SUPPORT){return Object.entries(e.requires).flatMap(([e,n])=>{let r=Object.hasOwn(t,e)?t[e]??[]:[];return r.includes(n)?[]:[{capability:e,requiredVersion:n,supportedVersions:r}]}).sort((e,t)=>e.capability.localeCompare(t.capability))}export{EXTENSION_CAPABILITY_SUPPORT,EXTENSION_CAPABILITY_VERSIONS,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME,EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION,EXTENSION_COMPATIBILITY_MANIFEST_KIND,findUnsupportedExtensionCapabilities,parseExtensionCompatibilityManifest,readExtensionCompatibilityManifest,serializeExtensionCompatibilityManifest,writeExtensionCompatibilityManifest};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{expectBoolean,expectFunction,expectObjectRecord,expectOnlyKnownKeys,expectString}from"#internal/authored-module.js";import{
|
|
1
|
+
import{EVE_SESSION_ROUTE_PATH}from"#protocol/routes.js";import{expectBoolean,expectFunction,expectObjectRecord,expectOnlyKnownKeys,expectString}from"#internal/authored-module.js";import{serializeOutputSchema}from"#tools/schema.js";import{isDynamicSentinel}from"#dynamic/definition.js";const ALLOWED_DYNAMIC_SUBAGENT_EVENTS=new Set([`session.started`,`turn.started`]);function normalizeSubagentConfig(s,c){if(isDynamicSentinel(s)){let e=expectObjectRecord(s,c);expectOnlyKnownKeys(e,[`build`,`events`,`kind`],c);let t=expectObjectRecord(e.events,c),i=[];for(let[e,r]of Object.entries(t)){if(!ALLOWED_DYNAMIC_SUBAGENT_EVENTS.has(e))throw Error(`${c} Dynamic subagents support only "session.started" and "turn.started" handlers.`);expectFunction(r,c),i.push(e)}let a=e.build===void 0?void 0:normalizeDynamicSubagentBuild(e.build,c);return a===void 0?{eventNames:i,kind:`dynamic`}:{build:a,eventNames:i,kind:`dynamic`}}if(typeof s==`object`&&s&&s.kind===`remote`){let n=expectObjectRecord(s,c);expectOnlyKnownKeys(n,[`auth`,`description`,`forwardPrincipal`,`headers`,`kind`,`outputSchema`,`path`,`url`],c),n.forwardPrincipal!==void 0&&expectBoolean(n.forwardPrincipal,`${c} Expected "forwardPrincipal" to be a boolean.`);let o=serializeOutputSchema(n.outputSchema);return{description:expectString(n.description,c),kind:`remote`,outputSchema:o,path:n.path===void 0?EVE_SESSION_ROUTE_PATH:expectString(n.path,c),url:typeof n.url==`function`?void 0:expectString(n.url,c)}}return{definition:s,kind:`local`}}function assertRemoteAgentDefinitionHasNoLocalPackageEntries(e){let t=e.manifest,n=[t.connections.length>0?`connections/`:void 0,t.hooks.length>0?`hooks/`:void 0,t.instructions.length>0?`instructions`:void 0,t.lib.length>0?`lib/`:void 0,t.sandbox===null?void 0:`sandbox/`,t.sandboxWorkspaces.length>0?`sandbox/workspace/`:void 0,t.schedules.length>0?`schedules/`:void 0,t.skills.length>0?`skills/`:void 0,t.subagents.length>0?`subagents/`:void 0,t.tools.length>0?`tools/`:void 0].filter(e=>e!==void 0);if(n.length>0)throw Error(`Remote subagent definition "${e.logicalPath}" cannot include local package entries. Remove unsupported entries: ${n.join(`, `)}.`)}function normalizeDynamicSubagentBuild(e,t){let n=expectObjectRecord(e,t);if(expectOnlyKnownKeys(n,[`externalDependencies`],t),n.externalDependencies===void 0)return{};if(!Array.isArray(n.externalDependencies))throw Error(t);return{externalDependencies:n.externalDependencies.map(e=>expectString(e,t))}}export{assertRemoteAgentDefinitionHasNoLocalPackageEntries,normalizeSubagentConfig};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import type { LanguageModel, ModelMessage, SystemModelMessage } from "ai";
|
|
7
7
|
import type { JsonObject } from "#shared/json.js";
|
|
8
8
|
import type { InstrumentationDecision } from "#shared/instrumentation-decision.js";
|
|
9
|
-
import type {
|
|
9
|
+
import type { ActivityObserverConfig, ChannelDeliveryMetadata, ChannelInstrumentationProjection, SessionAuthContext, SessionCallback, SessionCapabilities, SessionParent, SessionTraceContext, SessionTurn } from "#channel/types.js";
|
|
10
10
|
import { ContextKey } from "#context/key.js";
|
|
11
11
|
import type { InstrumentationChannelDeliveryRef } from "#harness/instrumentation/lifecycle.js";
|
|
12
12
|
import type { HandleEventFn } from "#harness/types.js";
|
|
@@ -84,6 +84,7 @@ export declare const SubagentDepthKey: ContextKey<number>;
|
|
|
84
84
|
* dispatch so HITL readiness flows through a conversation chain.
|
|
85
85
|
*/
|
|
86
86
|
export declare const CapabilitiesKey: ContextKey<SessionCapabilities>;
|
|
87
|
+
export declare const ActivityObserverKey: ContextKey<ActivityObserverConfig>;
|
|
87
88
|
/**
|
|
88
89
|
* Optional framework-owned caller callback captured when the session is created.
|
|
89
90
|
*/
|
package/dist/src/context/keys.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ContextKey}from"#context/key.js";import{SESSION_CALLBACK_CONTEXT_KEY_NAME}from"#context/key-names.js";const AuthKey=new ContextKey(`eve.auth`),InitiatorAuthKey=new ContextKey(`eve.initiatorAuth`),SessionIdKey=new ContextKey(`eve.sessionId`),ContinuationTokenKey=new ContextKey(`eve.continuationToken`),ChannelRequestIdKey=new ContextKey(`eve.channelRequestId`),ScheduleIdKey=new ContextKey(`eve.scheduleId`),ChannelDeliveryKey=new ContextKey(`eve.channelDelivery`),TurnTaskDeliveryKey=new ContextKey(`eve.turnTaskDelivery`),TurnTaskStateKey=new ContextKey(`eve.turnTaskState`),ActiveChannelDeliveriesKey=new ContextKey(`eve.activeChannelDeliveries`),ChannelInstrumentationKey=new ContextKey(`eve.channelInstrumentation`),ModeKey=new ContextKey(`eve.mode`),ParentSessionKey=new ContextKey(`eve.parentSession`),ParentTraceContextKey=new ContextKey(`eve.parentTraceContext`),SessionTraceSeedKey=new ContextKey(`eve.sessionTraceSeed`),OtelTraceEnabledKey=new ContextKey(`eve.otelTraceEnabled`),SubagentDepthKey=new ContextKey(`eve.subagentDepth`),CapabilitiesKey=new ContextKey(`eve.capabilities`),SessionCallbackKey=new ContextKey(SESSION_CALLBACK_CONTEXT_KEY_NAME),SessionKey=new ContextKey(`eve.session`),SandboxKey=new ContextKey(`eve.sandbox`),HandleEventKey=new ContextKey(`eve.internal.handleEvent`),SessionDynamicModelReferenceKey=new ContextKey(`eve.sessionDynamicModelReference`),TurnDynamicModelReferenceKey=new ContextKey(`eve.turnDynamicModelReference`),RuntimeModelMetadataCacheKey=new ContextKey(`eve.runtimeModelMetadataCache`),LiveStepDynamicModelSelectionKey=new ContextKey(`eve.liveStepDynamicModelSelection`),SessionDynamicToolMetadataKey=new ContextKey(`eve.sessionDynamicToolMetadata`),SessionDynamicToolRuntimeRevisionKey=new ContextKey(`eve.sessionDynamicToolRuntimeRevision`),TurnDynamicToolMetadataKey=new ContextKey(`eve.turnDynamicToolMetadata`),TurnMemoryLocksKey=new ContextKey(`eve.memory.turnLocks`),PreparedMemoryPreambleKey=new ContextKey(`eve.memory.preparedPreamble`),PendingMemoryCommitKey=new ContextKey(`eve.memory.pendingCommit`),PreparedMemoryCompactionKey=new ContextKey(`eve.memory.preparedCompaction`),StepDynamicToolMetadataKey=new ContextKey(`eve.stepDynamicToolMetadata`),TasksEnabledKey=new ContextKey(`eve.tasksEnabled`),SessionDynamicSubagentSelectionsKey=new ContextKey(`eve.sessionDynamicSubagentSelections`),TurnDynamicSubagentSelectionsKey=new ContextKey(`eve.turnDynamicSubagentSelections`),SessionDynamicSubagentRuntimeRevisionKey=new ContextKey(`eve.sessionDynamicSubagentRuntimeRevision`),DynamicSubagentAgentConfigKey=new ContextKey(`eve.dynamicSubagentAgentConfig`),DynamicSkillManifestKey=new ContextKey(`eve.dynamicSkillManifest`),SessionDynamicInstructionsKey=new ContextKey(`eve.sessionDynamicInstructions`),TurnDynamicInstructionsKey=new ContextKey(`eve.turnDynamicInstructions`),DynamicInstructionResolveMessagesKey=new ContextKey(`eve.dynamicInstructionResolveMessages`),PendingDynamicInstructionUserMessagesKey=new ContextKey(`eve.pendingDynamicInstructionUserMessages`);export{ActiveChannelDeliveriesKey,AuthKey,CapabilitiesKey,ChannelDeliveryKey,ChannelInstrumentationKey,ChannelRequestIdKey,ContinuationTokenKey,DynamicInstructionResolveMessagesKey,DynamicSkillManifestKey,DynamicSubagentAgentConfigKey,HandleEventKey,InitiatorAuthKey,LiveStepDynamicModelSelectionKey,ModeKey,OtelTraceEnabledKey,ParentSessionKey,ParentTraceContextKey,PendingDynamicInstructionUserMessagesKey,PendingMemoryCommitKey,PreparedMemoryCompactionKey,PreparedMemoryPreambleKey,RuntimeModelMetadataCacheKey,SandboxKey,ScheduleIdKey,SessionCallbackKey,SessionDynamicInstructionsKey,SessionDynamicModelReferenceKey,SessionDynamicSubagentRuntimeRevisionKey,SessionDynamicSubagentSelectionsKey,SessionDynamicToolMetadataKey,SessionDynamicToolRuntimeRevisionKey,SessionIdKey,SessionKey,SessionTraceSeedKey,StepDynamicToolMetadataKey,SubagentDepthKey,TasksEnabledKey,TurnDynamicInstructionsKey,TurnDynamicModelReferenceKey,TurnDynamicSubagentSelectionsKey,TurnDynamicToolMetadataKey,TurnMemoryLocksKey,TurnTaskDeliveryKey,TurnTaskStateKey};
|
|
1
|
+
import{ContextKey}from"#context/key.js";import{SESSION_CALLBACK_CONTEXT_KEY_NAME}from"#context/key-names.js";const AuthKey=new ContextKey(`eve.auth`),InitiatorAuthKey=new ContextKey(`eve.initiatorAuth`),SessionIdKey=new ContextKey(`eve.sessionId`),ContinuationTokenKey=new ContextKey(`eve.continuationToken`),ChannelRequestIdKey=new ContextKey(`eve.channelRequestId`),ScheduleIdKey=new ContextKey(`eve.scheduleId`),ChannelDeliveryKey=new ContextKey(`eve.channelDelivery`),TurnTaskDeliveryKey=new ContextKey(`eve.turnTaskDelivery`),TurnTaskStateKey=new ContextKey(`eve.turnTaskState`),ActiveChannelDeliveriesKey=new ContextKey(`eve.activeChannelDeliveries`),ChannelInstrumentationKey=new ContextKey(`eve.channelInstrumentation`),ModeKey=new ContextKey(`eve.mode`),ParentSessionKey=new ContextKey(`eve.parentSession`),ParentTraceContextKey=new ContextKey(`eve.parentTraceContext`),SessionTraceSeedKey=new ContextKey(`eve.sessionTraceSeed`),OtelTraceEnabledKey=new ContextKey(`eve.otelTraceEnabled`),SubagentDepthKey=new ContextKey(`eve.subagentDepth`),CapabilitiesKey=new ContextKey(`eve.capabilities`),ActivityObserverKey=new ContextKey(`eve.activityObserver`),SessionCallbackKey=new ContextKey(SESSION_CALLBACK_CONTEXT_KEY_NAME),SessionKey=new ContextKey(`eve.session`),SandboxKey=new ContextKey(`eve.sandbox`),HandleEventKey=new ContextKey(`eve.internal.handleEvent`),SessionDynamicModelReferenceKey=new ContextKey(`eve.sessionDynamicModelReference`),TurnDynamicModelReferenceKey=new ContextKey(`eve.turnDynamicModelReference`),RuntimeModelMetadataCacheKey=new ContextKey(`eve.runtimeModelMetadataCache`),LiveStepDynamicModelSelectionKey=new ContextKey(`eve.liveStepDynamicModelSelection`),SessionDynamicToolMetadataKey=new ContextKey(`eve.sessionDynamicToolMetadata`),SessionDynamicToolRuntimeRevisionKey=new ContextKey(`eve.sessionDynamicToolRuntimeRevision`),TurnDynamicToolMetadataKey=new ContextKey(`eve.turnDynamicToolMetadata`),TurnMemoryLocksKey=new ContextKey(`eve.memory.turnLocks`),PreparedMemoryPreambleKey=new ContextKey(`eve.memory.preparedPreamble`),PendingMemoryCommitKey=new ContextKey(`eve.memory.pendingCommit`),PreparedMemoryCompactionKey=new ContextKey(`eve.memory.preparedCompaction`),StepDynamicToolMetadataKey=new ContextKey(`eve.stepDynamicToolMetadata`),TasksEnabledKey=new ContextKey(`eve.tasksEnabled`),SessionDynamicSubagentSelectionsKey=new ContextKey(`eve.sessionDynamicSubagentSelections`),TurnDynamicSubagentSelectionsKey=new ContextKey(`eve.turnDynamicSubagentSelections`),SessionDynamicSubagentRuntimeRevisionKey=new ContextKey(`eve.sessionDynamicSubagentRuntimeRevision`),DynamicSubagentAgentConfigKey=new ContextKey(`eve.dynamicSubagentAgentConfig`),DynamicSkillManifestKey=new ContextKey(`eve.dynamicSkillManifest`),SessionDynamicInstructionsKey=new ContextKey(`eve.sessionDynamicInstructions`),TurnDynamicInstructionsKey=new ContextKey(`eve.turnDynamicInstructions`),DynamicInstructionResolveMessagesKey=new ContextKey(`eve.dynamicInstructionResolveMessages`),PendingDynamicInstructionUserMessagesKey=new ContextKey(`eve.pendingDynamicInstructionUserMessages`);export{ActiveChannelDeliveriesKey,ActivityObserverKey,AuthKey,CapabilitiesKey,ChannelDeliveryKey,ChannelInstrumentationKey,ChannelRequestIdKey,ContinuationTokenKey,DynamicInstructionResolveMessagesKey,DynamicSkillManifestKey,DynamicSubagentAgentConfigKey,HandleEventKey,InitiatorAuthKey,LiveStepDynamicModelSelectionKey,ModeKey,OtelTraceEnabledKey,ParentSessionKey,ParentTraceContextKey,PendingDynamicInstructionUserMessagesKey,PendingMemoryCommitKey,PreparedMemoryCompactionKey,PreparedMemoryPreambleKey,RuntimeModelMetadataCacheKey,SandboxKey,ScheduleIdKey,SessionCallbackKey,SessionDynamicInstructionsKey,SessionDynamicModelReferenceKey,SessionDynamicSubagentRuntimeRevisionKey,SessionDynamicSubagentSelectionsKey,SessionDynamicToolMetadataKey,SessionDynamicToolRuntimeRevisionKey,SessionIdKey,SessionKey,SessionTraceSeedKey,StepDynamicToolMetadataKey,SubagentDepthKey,TasksEnabledKey,TurnDynamicInstructionsKey,TurnDynamicModelReferenceKey,TurnDynamicSubagentSelectionsKey,TurnDynamicToolMetadataKey,TurnMemoryLocksKey,TurnTaskDeliveryKey,TurnTaskStateKey};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ActivityObserverConfig, SessionCallback } from "#channel/types.js";
|
|
2
|
+
type BoundActivityObserverConfig = ActivityObserverConfig & {
|
|
3
|
+
readonly workIdentity: NonNullable<ActivityObserverConfig["workIdentity"]>;
|
|
4
|
+
};
|
|
5
|
+
export declare function parseActivityObserverField(value: unknown): BoundActivityObserverConfig | Response | undefined;
|
|
6
|
+
export declare function validateActivityObserverBinding(activityObserver: BoundActivityObserverConfig, callback: SessionCallback | undefined): Response | undefined;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseActivitySink}from"#channel/activity-sink.js";import{parseActivityWorkIdentityV1}from"#protocol/activity.js";function parseActivityObserverField(n){if(n!==void 0){if(typeof n!=`object`||!n)return invalidActivityObserver();try{let r=parseActivitySink(Reflect.get(n,`sink`)),i=parseActivityWorkIdentityV1(Reflect.get(n,`workIdentity`));return r===void 0||i===void 0?invalidActivityObserver():{sink:r,workIdentity:i}}catch(e){return invalidActivityObserver(e instanceof Error?e.message:`Invalid activity observer configuration.`)}}}function validateActivityObserverBinding(e,t){if(t===void 0)return invalidBinding(`Activity observer configuration requires a delegated session callback.`);if(e.workIdentity.callId!==t.callId)return invalidBinding(`Activity observer callId must match the delegated session callback.`);if(e.workIdentity.name!==t.subagentName)return invalidBinding(`Activity observer name must match the delegated session callback.`);if(new URL(e.sink.url).origin!==new URL(t.url).origin)return invalidBinding(`Activity observer sink must share the delegated callback origin.`)}function invalidActivityObserver(e=`Invalid activity observer configuration.`){return Response.json({error:e,ok:!1},{status:400})}function invalidBinding(e){return Response.json({error:e,ok:!1},{status:400})}export{parseActivityObserverField,validateActivityObserverBinding};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createLogger,logError}from"#internal/logging.js";import{isRuntimeSessionOwnershipConflictError}from"#execution/runtime-errors.js";import{EVE_CALLBACK_ROUTE_PATTERN,EVE_CONNECTION_CALLBACK_ROUTE_PATTERN,EVE_HEALTH_ROUTE_PATH,EVE_INFO_ROUTE_PATH,EVE_LEGACY_CONNECTION_CALLBACK_ROUTE_PATTERN,EVE_SESSION_CANCEL_ROUTE_PATTERN,EVE_SESSION_CLEAR_ROUTE_PATTERN,EVE_SESSION_COMPACT_ROUTE_PATTERN,EVE_SESSION_RESET_ROUTE_PATTERN,EVE_SESSION_ROUTE_PATH,EVE_SESSION_ROUTE_PATTERN,EVE_SESSION_STREAM_ROUTE_PATTERN,EVE_SUBAGENT_STREAM_ROUTE_PATTERN,EVE_TASK_INPUT_ROUTE_PATTERN,createEveSessionStreamRoutePath,createEveSubagentStreamRoutePath}from"#protocol/routes.js";import{EVE_SESSION_ID_HEADER,EVE_STREAM_FORMAT_HEADER,EVE_STREAM_TAIL_INDEX_HEADER,EVE_STREAM_VERSION_HEADER}from"#protocol/message.js";import{GET,HEAD,POST,defineChannel}from"#public/definitions/channel.js";import{resolveForwardedPrincipal}from"#channel/forwarded-principal.js";import{handleConnectionCallbackRequest,handleLegacyConnectionCallbackRequest}from"#execution/connections/callback-route.js";import{handleSessionCallbackRequest}from"#execution/session-callback-route.js";import{handleTaskInputResponseRequest}from"#execution/task-input-response-route.js";import{readAgentInfoRouteResponse,readRemoteAgentStreamHeadersResolver,readRouteSessionCreator}from"#internal/nitro/routes/channel-route-context.js";import{parseTraceparent}from"#protocol/traceparent.js";import{routeAuth}from"#public/channels/auth.js";import{mergeUploadPolicy}from"#public/channels/upload-policy.js";import{checkUploadPolicy,createSessionStreamResponse,deriveOperationContinuationToken,mergeContext,parseCancelTurnBody,parseCreateBody,parseIncludeTailIndex,parseJsonRequest,parseResetBody,parseSessionControlBody,parseSessionMessageBody,parseStartIndex,rejectSessionContinuationToken,requireSessionId}from"#eve-channel/request.js";import{findRemoteSubagentBinding,healthResponse,normalizeEveCors,resolveOnMessage}from"#eve-channel/support.js";export*from"#eve-channel/types.js";const log=createLogger(`eve.channel`);function eveChannel(e){let g=mergeUploadPolicy(e.uploadPolicy);return defineChannel({cors:normalizeEveCors(e.cors),turnPolicy:e.turnPolicy,routes:[GET(EVE_HEALTH_ROUTE_PATH,async()=>healthResponse()),HEAD(EVE_HEALTH_ROUTE_PATH,async()=>healthResponse()),GET(EVE_INFO_ROUTE_PATH,async(t,n)=>{let r=await routeAuth(t,e.auth);if(r instanceof Response)return r;let i=readAgentInfoRouteResponse(n);return i===void 0?Response.json({error:`Agent info route requires internal channel dispatch context.`,ok:!1},{status:500}):await i()}),GET(EVE_CONNECTION_CALLBACK_ROUTE_PATTERN,handleConnectionCallbackRequest),POST(EVE_CONNECTION_CALLBACK_ROUTE_PATTERN,handleConnectionCallbackRequest),GET(EVE_LEGACY_CONNECTION_CALLBACK_ROUTE_PATTERN,handleLegacyConnectionCallbackRequest),POST(EVE_LEGACY_CONNECTION_CALLBACK_ROUTE_PATTERN,handleLegacyConnectionCallbackRequest),POST(EVE_CALLBACK_ROUTE_PATTERN,handleSessionCallbackRequest),POST(EVE_TASK_INPUT_ROUTE_PATTERN,handleTaskInputResponseRequest),POST(EVE_SESSION_ROUTE_PATH,async(r,i)=>{let a=await routeAuth(r,e.auth);if(a instanceof Response)return a;let o=await parseJsonRequest(r);if(o instanceof Response)return o;let s=rejectSessionContinuationToken(o);if(s!==null)return s;let c=await resolveForwardedPrincipal({trustedForwarders:e.trustedForwarders,forwarder:a,payload:o});if(c instanceof Response)return c;let l=parseCreateBody(o);if(l instanceof Response)return l;let u=l.callback===void 0?void 0:parseTraceparent(r.headers.get(`traceparent`)),d=checkUploadPolicy(l,g);if(d!==null)return d;if(l.operationId!==void 0&&c.auth.principalType===`anonymous`)return Response.json({error:`operationId requires an authenticated principal.`,ok:!1},{status:400});let f=l.operationId===void 0?void 0:await deriveOperationContinuationToken({auth:c.auth,operationId:l.operationId});if(f!==void 0){let e=await i.resolveSession(f);if(e!==void 0)return Response.json({ok:!0,sessionId:e.id,status:`accepted`},{headers:{"cache-control":`no-store`,[EVE_SESSION_ID_HEADER]:e.id},status:202})}let p=await resolveOnMessage({auth:c.auth,config:e,message:l.message,request:r});if(p instanceof Response)return p;let m=readRouteSessionCreator(i);if(m===void 0)return Response.json({error:`Session creation requires internal channel dispatch context.`,ok:!1},{status:500});let h;try{h=await m({auth:p.auth,capabilities:l.capabilities??(l.mode===`task`?void 0:{requestInput:!0}),callback:l.callback,continuationToken:f,initiatorAuth:c.accepted?c.initiatorAuth:void 0,input:{message:l.message,context:mergeContext(l.context,p.context),outputSchema:l.outputSchema},mode:l.mode??`conversation`,parentTraceContext:u,title:p.title})}catch(e){if(f!==void 0&&isRuntimeSessionOwnershipConflictError(e))return Response.json({ok:!0,sessionId:e.ownerSessionId,status:`accepted`},{headers:{"cache-control":`no-store`,[EVE_SESSION_ID_HEADER]:e.ownerSessionId},status:202});let r=logError(log,`session-create request failed`,e);return Response.json({error:`Failed to create the session.`,errorId:r,ok:!1},{status:500})}return Response.json({ok:!0,sessionId:h.sessionId,status:`accepted`},{headers:{"cache-control":`no-store`,[EVE_SESSION_ID_HEADER]:h.sessionId},status:202})}),POST(EVE_SESSION_ROUTE_PATTERN,async(n,{attachSession:r,params:i})=>{let a=await routeAuth(n,e.auth);if(a instanceof Response)return a;let o=requireSessionId(i);if(o instanceof Response)return o;let s=await parseJsonRequest(n);if(s instanceof Response)return s;let c=await resolveForwardedPrincipal({trustedForwarders:e.trustedForwarders,forwarder:a,payload:s});if(c instanceof Response)return c;let l=parseSessionMessageBody(s);if(l instanceof Response)return l;let u=checkUploadPolicy(l,g);if(u!==null)return u;let d=l.context,f=c.auth;if(l.message!==void 0){let t=await resolveOnMessage({auth:c.auth,config:e,message:l.message,request:n,sessionId:o});if(t instanceof Response)return t;d=mergeContext(l.context,t.context),f=t.auth}let p;try{let e=r(o),t={auth:f,callback:l.callback,context:d,outputSchema:l.outputSchema,turnPolicy:l.turnPolicy};p=l.inputResponses===void 0?await e.send(l.message,t):await e.respond(l.inputResponses,t)}catch(e){let n=logError(log,`session-message request failed`,e,{sessionId:o});return Response.json({error:`Failed to send the session message.`,errorId:n,ok:!1},{status:500})}return p.status===`session_not_active`?Response.json({code:`session_not_active`,error:`The session is no longer active.`,ok:!1},{headers:{"cache-control":`no-store`},status:409}):Response.json({ok:!0,sessionId:p.sessionId,status:`accepted`},{headers:{"cache-control":`no-store`,[EVE_SESSION_ID_HEADER]:p.sessionId},status:202})}),POST(EVE_SESSION_CANCEL_ROUTE_PATTERN,async(n,{attachSession:r,params:i})=>{let a=await routeAuth(n,e.auth);if(a instanceof Response)return a;let o=requireSessionId(i);if(o instanceof Response)return o;let s=await parseCancelTurnBody(n);if(s instanceof Response)return s;let c;try{c=await r(o).cancel({taskId:s.taskId,turnId:s.turnId})}catch(e){let n=logError(log,`cancel-turn request failed`,e,{sessionId:o});return Response.json({error:`Failed to cancel the turn.`,errorId:n,ok:!1},{status:500})}return Response.json(c.status===`accepted`?{ok:!0,sessionId:c.sessionId,status:`accepted`}:{ok:!0,status:`no_active_turn`},{headers:{"cache-control":`no-store`},status:c.status===`accepted`?202:200})}),POST(EVE_SESSION_COMPACT_ROUTE_PATTERN,async(n,{attachSession:r,params:i})=>{let a=await routeAuth(n,e.auth);if(a instanceof Response)return a;let o=requireSessionId(i);if(o instanceof Response)return o;let s=await parseSessionControlBody(n);if(s instanceof Response)return s;let c;try{c=await r(o).compact()}catch(e){let n=logError(log,`session-compaction request failed`,e,{sessionId:o});return Response.json({error:`Failed to compact the session.`,errorId:n,ok:!1},{status:500})}return Response.json(c.status===`accepted`?{ok:!0,sessionId:c.sessionId,status:`accepted`}:{ok:!0,status:`no_active_session`},{headers:{"cache-control":`no-store`},status:c.status===`accepted`?202:200})}),POST(EVE_SESSION_CLEAR_ROUTE_PATTERN,async(n,{attachSession:r,params:i})=>{let a=await routeAuth(n,e.auth);if(a instanceof Response)return a;let o=requireSessionId(i);if(o instanceof Response)return o;let s=await parseSessionControlBody(n);if(s instanceof Response)return s;let c;try{c=await r(o).clear()}catch(e){let n=logError(log,`session-clear request failed`,e,{sessionId:o});return Response.json({error:`Failed to clear the session context.`,errorId:n,ok:!1},{status:500})}return Response.json(c.status===`accepted`?{ok:!0,sessionId:c.sessionId,status:`accepted`}:{ok:!0,status:`no_active_session`},{headers:{"cache-control":`no-store`},status:c.status===`accepted`?202:200})}),POST(EVE_SESSION_RESET_ROUTE_PATTERN,async(n,{attachSession:r,params:i})=>{let a=await routeAuth(n,e.auth);if(a instanceof Response)return a;let o=requireSessionId(i);if(o instanceof Response)return o;let s=await parseResetBody(n);if(s instanceof Response)return s;let c;try{c=await r(o).reset({reason:s.reason})}catch(e){let n=logError(log,`session-reset request failed`,e,{sessionId:o});return Response.json({error:`Failed to reset the session.`,errorId:n,ok:!1},{status:500})}return Response.json(c.status===`reset`?{ok:!0,previousSessionId:c.previousSessionId,status:`reset`}:{ok:!0,status:`no_active_session`},{headers:{"cache-control":`no-store`}})}),GET(EVE_SESSION_STREAM_ROUTE_PATTERN,async(t,{attachSession:n,params:r})=>{let i=await routeAuth(t,e.auth);if(i instanceof Response)return i;let a=requireSessionId(r);return a instanceof Response?a:await createSessionStreamResponse(t,n(a))}),GET(EVE_SUBAGENT_STREAM_ROUTE_PATTERN,async(t,n)=>{let r=await routeAuth(t,e.auth);if(r instanceof Response)return r;let i=n.params.parentSessionId,a=n.params.callId,o=n.params.childSessionId;if(!i||!a||!o)return Response.json({error:`Missing subagent stream coordinates.`,ok:!1},{status:400});let s=parseStartIndex(t);if(s instanceof Response)return s;let c=parseIncludeTailIndex(t),l=createEveSubagentStreamRoutePath({callId:a,childSessionId:o,parentSessionId:i}),u;try{let e=await findRemoteSubagentBinding({callId:a,childSessionId:o,childStreamPath:l,parentSessionId:i,parent:n.attachSession(i)});if(e===void 0)throw Error(`Remote subagent binding not found.`);u=e}catch{return Response.json({error:`Subagent stream not found.`,ok:!1},{status:404})}let d=readRemoteAgentStreamHeadersResolver(n);if(d===void 0)return Response.json({error:`Subagent stream proxy requires internal channel dispatch context.`,ok:!1},{status:500});let f;try{f=await d({name:u.data.toolName,resolverId:u.data.remote.resolverId,url:u.data.remote.url})}catch{return Response.json({error:`Subagent stream not found.`,ok:!1},{status:404})}let p=new URL(createEveSessionStreamRoutePath(o).replace(/^\/+/,``),`${u.data.remote.url.replace(/\/+$/,``)}/`);s!==void 0&&p.searchParams.set(`startIndex`,String(s)),c&&p.searchParams.set(`includeTailIndex`,`1`);let m=await fetch(p,{cache:`no-store`,headers:f,redirect:`manual`,signal:t.signal}),h=new Headers;for(let e of[`cache-control`,`content-type`,`x-accel-buffering`,EVE_SESSION_ID_HEADER,EVE_STREAM_FORMAT_HEADER,EVE_STREAM_TAIL_INDEX_HEADER,EVE_STREAM_VERSION_HEADER]){let t=m.headers.get(e);t!==null&&h.set(e,t)}return new Response(m.body,{headers:h,status:m.status,statusText:m.statusText})})],events:e.events})}export{eveChannel};
|
|
1
|
+
import{EVE_ACTIVITY_ROUTE_PATTERN,EVE_CALLBACK_ROUTE_PATTERN,EVE_CONNECTION_CALLBACK_ROUTE_PATTERN,EVE_HEALTH_ROUTE_PATH,EVE_INFO_ROUTE_PATH,EVE_LEGACY_CONNECTION_CALLBACK_ROUTE_PATTERN,EVE_SESSION_CANCEL_ROUTE_PATTERN,EVE_SESSION_CLEAR_ROUTE_PATTERN,EVE_SESSION_COMPACT_ROUTE_PATTERN,EVE_SESSION_RESET_ROUTE_PATTERN,EVE_SESSION_ROUTE_PATH,EVE_SESSION_ROUTE_PATTERN,EVE_SESSION_STREAM_ROUTE_PATTERN,EVE_SUBAGENT_STREAM_ROUTE_PATTERN,EVE_TASK_INPUT_ROUTE_PATTERN,createEveSessionStreamRoutePath,createEveSubagentStreamRoutePath}from"#protocol/routes.js";import{createLogger,logError}from"#internal/logging.js";import{isRuntimeSessionOwnershipConflictError}from"#execution/runtime-errors.js";import{EVE_SESSION_ID_HEADER,EVE_STREAM_FORMAT_HEADER,EVE_STREAM_TAIL_INDEX_HEADER,EVE_STREAM_VERSION_HEADER}from"#protocol/message.js";import{GET,HEAD,POST,defineChannel}from"#public/definitions/channel.js";import{resolveForwardedPrincipal}from"#channel/forwarded-principal.js";import{handleConnectionCallbackRequest,handleLegacyConnectionCallbackRequest}from"#execution/connections/callback-route.js";import{handleActivityRequest}from"#execution/activity-route.js";import{handleSessionCallbackRequest}from"#execution/session-callback-route.js";import{handleTaskInputResponseRequest}from"#execution/task-input-response-route.js";import{readAgentInfoRouteResponse,readRemoteAgentStreamHeadersResolver,readRouteSessionCreator}from"#internal/nitro/routes/channel-route-context.js";import{parseTraceparent}from"#protocol/traceparent.js";import{routeAuth}from"#public/channels/auth.js";import{mergeUploadPolicy}from"#public/channels/upload-policy.js";import{checkUploadPolicy,createSessionStreamResponse,deriveOperationContinuationToken,mergeContext,parseCancelTurnBody,parseCreateBody,parseIncludeTailIndex,parseJsonRequest,parseResetBody,parseSessionControlBody,parseSessionMessageBody,parseStartIndex,rejectSessionContinuationToken,requireSessionId}from"#eve-channel/request.js";import{findRemoteSubagentBinding,healthResponse,normalizeEveCors,resolveOnMessage}from"#eve-channel/support.js";export*from"#eve-channel/types.js";const log=createLogger(`eve.channel`);function eveChannel(h){let g=mergeUploadPolicy(h.uploadPolicy);return defineChannel({cors:normalizeEveCors(h.cors),turnPolicy:h.turnPolicy,routes:[GET(EVE_HEALTH_ROUTE_PATH,async()=>healthResponse()),HEAD(EVE_HEALTH_ROUTE_PATH,async()=>healthResponse()),GET(EVE_INFO_ROUTE_PATH,async(e,t)=>{let n=await routeAuth(e,h.auth);if(n instanceof Response)return n;let r=readAgentInfoRouteResponse(t);return r===void 0?Response.json({error:`Agent info route requires internal channel dispatch context.`,ok:!1},{status:500}):await r()}),GET(EVE_CONNECTION_CALLBACK_ROUTE_PATTERN,handleConnectionCallbackRequest),POST(EVE_CONNECTION_CALLBACK_ROUTE_PATTERN,handleConnectionCallbackRequest),GET(EVE_LEGACY_CONNECTION_CALLBACK_ROUTE_PATTERN,handleLegacyConnectionCallbackRequest),POST(EVE_LEGACY_CONNECTION_CALLBACK_ROUTE_PATTERN,handleLegacyConnectionCallbackRequest),POST(EVE_ACTIVITY_ROUTE_PATTERN,handleActivityRequest),POST(EVE_CALLBACK_ROUTE_PATTERN,handleSessionCallbackRequest),POST(EVE_TASK_INPUT_ROUTE_PATTERN,handleTaskInputResponseRequest),POST(EVE_SESSION_ROUTE_PATH,async(e,t)=>{let n=await routeAuth(e,h.auth);if(n instanceof Response)return n;let r=await parseJsonRequest(e);if(r instanceof Response)return r;let i=rejectSessionContinuationToken(r);if(i!==null)return i;let a=await resolveForwardedPrincipal({trustedForwarders:h.trustedForwarders,forwarder:n,payload:r});if(a instanceof Response)return a;let o=parseCreateBody(r);if(o instanceof Response)return o;let s=o.callback===void 0?void 0:parseTraceparent(e.headers.get(`traceparent`)),c=checkUploadPolicy(o,g);if(c!==null)return c;if(o.operationId!==void 0&&a.auth.principalType===`anonymous`)return Response.json({error:`operationId requires an authenticated principal.`,ok:!1},{status:400});let l=o.operationId===void 0?void 0:await deriveOperationContinuationToken({auth:a.auth,operationId:o.operationId});if(l!==void 0){let e=await t.resolveSession(l);if(e!==void 0)return Response.json({ok:!0,sessionId:e.id,status:`accepted`},{headers:{"cache-control":`no-store`,[EVE_SESSION_ID_HEADER]:e.id},status:202})}let u=await resolveOnMessage({auth:a.auth,config:h,message:o.message,request:e});if(u instanceof Response)return u;let d=readRouteSessionCreator(t);if(d===void 0)return Response.json({error:`Session creation requires internal channel dispatch context.`,ok:!1},{status:500});let f;try{f=await d({activityObserver:o.activityObserver,auth:u.auth,capabilities:o.capabilities??(o.mode===`task`?void 0:{requestInput:!0}),callback:o.callback,continuationToken:l,initiatorAuth:a.accepted?a.initiatorAuth:void 0,input:{message:o.message,context:mergeContext(o.context,u.context),outputSchema:o.outputSchema},mode:o.mode??`conversation`,parentTraceContext:s,title:u.title})}catch(e){if(l!==void 0&&isRuntimeSessionOwnershipConflictError(e))return Response.json({ok:!0,sessionId:e.ownerSessionId,status:`accepted`},{headers:{"cache-control":`no-store`,[EVE_SESSION_ID_HEADER]:e.ownerSessionId},status:202});let t=logError(log,`session-create request failed`,e);return Response.json({error:`Failed to create the session.`,errorId:t,ok:!1},{status:500})}return Response.json({ok:!0,sessionId:f.sessionId,status:`accepted`},{headers:{"cache-control":`no-store`,[EVE_SESSION_ID_HEADER]:f.sessionId},status:202})}),POST(EVE_SESSION_ROUTE_PATTERN,async(e,{attachSession:t,params:n})=>{let r=await routeAuth(e,h.auth);if(r instanceof Response)return r;let i=requireSessionId(n);if(i instanceof Response)return i;let a=await parseJsonRequest(e);if(a instanceof Response)return a;let o=await resolveForwardedPrincipal({trustedForwarders:h.trustedForwarders,forwarder:r,payload:a});if(o instanceof Response)return o;let s=parseSessionMessageBody(a);if(s instanceof Response)return s;let c=checkUploadPolicy(s,g);if(c!==null)return c;let l=s.context,u=o.auth;if(s.message!==void 0){let t=await resolveOnMessage({auth:o.auth,config:h,message:s.message,request:e,sessionId:i});if(t instanceof Response)return t;l=mergeContext(s.context,t.context),u=t.auth}let d;try{let e=t(i),n={activityObserver:s.activityObserver,auth:u,callback:s.callback,context:l,outputSchema:s.outputSchema,turnPolicy:s.turnPolicy};d=s.inputResponses===void 0?await e.send(s.message,n):await e.respond(s.inputResponses,n)}catch(e){let t=logError(log,`session-message request failed`,e,{sessionId:i});return Response.json({error:`Failed to send the session message.`,errorId:t,ok:!1},{status:500})}return d.status===`session_not_active`?Response.json({code:`session_not_active`,error:`The session is no longer active.`,ok:!1},{headers:{"cache-control":`no-store`},status:409}):Response.json({ok:!0,sessionId:d.sessionId,status:`accepted`},{headers:{"cache-control":`no-store`,[EVE_SESSION_ID_HEADER]:d.sessionId},status:202})}),POST(EVE_SESSION_CANCEL_ROUTE_PATTERN,async(e,{attachSession:t,params:n})=>{let r=await routeAuth(e,h.auth);if(r instanceof Response)return r;let i=requireSessionId(n);if(i instanceof Response)return i;let a=await parseCancelTurnBody(e);if(a instanceof Response)return a;let o;try{o=await t(i).cancel({taskId:a.taskId,turnId:a.turnId})}catch(e){let t=logError(log,`cancel-turn request failed`,e,{sessionId:i});return Response.json({error:`Failed to cancel the turn.`,errorId:t,ok:!1},{status:500})}return Response.json(o.status===`accepted`?{ok:!0,sessionId:o.sessionId,status:`accepted`}:{ok:!0,status:`no_active_turn`},{headers:{"cache-control":`no-store`},status:o.status===`accepted`?202:200})}),POST(EVE_SESSION_COMPACT_ROUTE_PATTERN,async(e,{attachSession:t,params:n})=>{let r=await routeAuth(e,h.auth);if(r instanceof Response)return r;let i=requireSessionId(n);if(i instanceof Response)return i;let a=await parseSessionControlBody(e);if(a instanceof Response)return a;let o;try{o=await t(i).compact()}catch(e){let t=logError(log,`session-compaction request failed`,e,{sessionId:i});return Response.json({error:`Failed to compact the session.`,errorId:t,ok:!1},{status:500})}return Response.json(o.status===`accepted`?{ok:!0,sessionId:o.sessionId,status:`accepted`}:{ok:!0,status:`no_active_session`},{headers:{"cache-control":`no-store`},status:o.status===`accepted`?202:200})}),POST(EVE_SESSION_CLEAR_ROUTE_PATTERN,async(e,{attachSession:t,params:n})=>{let r=await routeAuth(e,h.auth);if(r instanceof Response)return r;let i=requireSessionId(n);if(i instanceof Response)return i;let a=await parseSessionControlBody(e);if(a instanceof Response)return a;let o;try{o=await t(i).clear()}catch(e){let t=logError(log,`session-clear request failed`,e,{sessionId:i});return Response.json({error:`Failed to clear the session context.`,errorId:t,ok:!1},{status:500})}return Response.json(o.status===`accepted`?{ok:!0,sessionId:o.sessionId,status:`accepted`}:{ok:!0,status:`no_active_session`},{headers:{"cache-control":`no-store`},status:o.status===`accepted`?202:200})}),POST(EVE_SESSION_RESET_ROUTE_PATTERN,async(e,{attachSession:t,params:n})=>{let r=await routeAuth(e,h.auth);if(r instanceof Response)return r;let i=requireSessionId(n);if(i instanceof Response)return i;let a=await parseResetBody(e);if(a instanceof Response)return a;let o;try{o=await t(i).reset({reason:a.reason})}catch(e){let t=logError(log,`session-reset request failed`,e,{sessionId:i});return Response.json({error:`Failed to reset the session.`,errorId:t,ok:!1},{status:500})}return Response.json(o.status===`reset`?{ok:!0,previousSessionId:o.previousSessionId,status:`reset`}:{ok:!0,status:`no_active_session`},{headers:{"cache-control":`no-store`}})}),GET(EVE_SESSION_STREAM_ROUTE_PATTERN,async(e,{attachSession:t,params:n})=>{let r=await routeAuth(e,h.auth);if(r instanceof Response)return r;let i=requireSessionId(n);return i instanceof Response?i:await createSessionStreamResponse(e,t(i))}),GET(EVE_SUBAGENT_STREAM_ROUTE_PATTERN,async(e,t)=>{let n=await routeAuth(e,h.auth);if(n instanceof Response)return n;let r=t.params.parentSessionId,i=t.params.callId,a=t.params.childSessionId;if(!r||!i||!a)return Response.json({error:`Missing subagent stream coordinates.`,ok:!1},{status:400});let o=parseStartIndex(e);if(o instanceof Response)return o;let s=parseIncludeTailIndex(e),c=createEveSubagentStreamRoutePath({callId:i,childSessionId:a,parentSessionId:r}),l;try{let e=await findRemoteSubagentBinding({callId:i,childSessionId:a,childStreamPath:c,parentSessionId:r,parent:t.attachSession(r)});if(e===void 0)throw Error(`Remote subagent binding not found.`);l=e}catch{return Response.json({error:`Subagent stream not found.`,ok:!1},{status:404})}let u=readRemoteAgentStreamHeadersResolver(t);if(u===void 0)return Response.json({error:`Subagent stream proxy requires internal channel dispatch context.`,ok:!1},{status:500});let d;try{d=await u({name:l.data.toolName,resolverId:l.data.remote.resolverId,url:l.data.remote.url})}catch{return Response.json({error:`Subagent stream not found.`,ok:!1},{status:404})}let f=new URL(createEveSessionStreamRoutePath(a).replace(/^\/+/,``),`${l.data.remote.url.replace(/\/+$/,``)}/`);o!==void 0&&f.searchParams.set(`startIndex`,String(o)),s&&f.searchParams.set(`includeTailIndex`,`1`);let p=await fetch(f,{cache:`no-store`,headers:d,redirect:`manual`,signal:e.signal}),m=new Headers;for(let e of[`cache-control`,`content-type`,`x-accel-buffering`,EVE_SESSION_ID_HEADER,EVE_STREAM_FORMAT_HEADER,EVE_STREAM_TAIL_INDEX_HEADER,EVE_STREAM_VERSION_HEADER]){let t=p.headers.get(e);t!==null&&m.set(e,t)}return new Response(p.body,{headers:m,status:p.status,statusText:p.statusText})})],events:h.events})}export{eveChannel};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { UserContent } from "ai";
|
|
2
|
-
import type { SessionAuthContext, SessionCallback, SessionCapabilities, TurnPolicy } from "#channel/types.js";
|
|
2
|
+
import type { ActivityObserverConfig, SessionAuthContext, SessionCallback, SessionCapabilities, TurnPolicy } from "#channel/types.js";
|
|
3
3
|
import type { Session } from "#channel/session.js";
|
|
4
4
|
import { type UploadPolicy } from "#public/channels/upload-policy.js";
|
|
5
5
|
import { type ValidatedInputResponse } from "#shared/input.js";
|
|
6
6
|
import { type JsonObject } from "#shared/json.js";
|
|
7
7
|
import type { RunMode } from "#shared/run-mode.js";
|
|
8
8
|
interface ParsedCreateBody {
|
|
9
|
+
activityObserver?: ActivityObserverConfig;
|
|
9
10
|
callback?: SessionCallback;
|
|
10
11
|
capabilities?: SessionCapabilities;
|
|
11
12
|
message: string | UserContent;
|
|
@@ -21,6 +22,7 @@ export declare function deriveOperationContinuationToken(input: {
|
|
|
21
22
|
}): Promise<string>;
|
|
22
23
|
export declare function parseCreateBody(payload: Record<string, unknown>): ParsedCreateBody | Response;
|
|
23
24
|
interface ParsedSessionMessageBody {
|
|
25
|
+
activityObserver?: ActivityObserverConfig;
|
|
24
26
|
callback?: SessionCallback;
|
|
25
27
|
message?: string | UserContent;
|
|
26
28
|
inputResponses?: readonly ValidatedInputResponse[];
|