eve 0.29.4 → 0.29.5

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.
Files changed (128) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/src/channel/clear-session.d.ts +4 -0
  3. package/dist/src/channel/clear-session.js +1 -0
  4. package/dist/src/channel/compact-session.d.ts +4 -0
  5. package/dist/src/channel/compact-session.js +1 -0
  6. package/dist/src/channel/routes.d.ts +34 -6
  7. package/dist/src/channel/types.d.ts +61 -9
  8. package/dist/src/chunks/{use-eve-agent-8mofdZcO.js → use-eve-agent-BXMIf5fR.js} +85 -1
  9. package/dist/src/chunks/{use-eve-agent-bKJbH0k4.js → use-eve-agent-k-XHfrJT.js} +85 -1
  10. package/dist/src/cli/dev/tui/message-queue.d.ts +9 -13
  11. package/dist/src/cli/dev/tui/message-queue.js +1 -1
  12. package/dist/src/cli/dev/tui/prompt-commands.d.ts +13 -5
  13. package/dist/src/cli/dev/tui/prompt-commands.js +1 -1
  14. package/dist/src/cli/dev/tui/runner.d.ts +7 -7
  15. package/dist/src/cli/dev/tui/runner.js +1 -1
  16. package/dist/src/cli/dev/tui/subagent-pump.d.ts +5 -5
  17. package/dist/src/cli/dev/tui/terminal-renderer.js +1 -1
  18. package/dist/src/client/agent-info-schema.d.ts +2 -2
  19. package/dist/src/client/agent-info-schema.js +1 -1
  20. package/dist/src/client/index.d.ts +1 -1
  21. package/dist/src/client/session.d.ts +15 -1
  22. package/dist/src/client/session.js +1 -1
  23. package/dist/src/client/types.d.ts +20 -0
  24. package/dist/src/compiler/extension-compatibility.d.ts +8 -8
  25. package/dist/src/compiler/extension-compatibility.js +1 -1
  26. package/dist/src/compiler/manifest.d.ts +11 -22
  27. package/dist/src/compiler/manifest.js +1 -1
  28. package/dist/src/compiler/normalize-agent-config.d.ts +3 -1
  29. package/dist/src/compiler/normalize-agent-config.js +1 -1
  30. package/dist/src/compiler/normalize-manifest.js +1 -1
  31. package/dist/src/compiler/normalize-subagent.d.ts +1 -0
  32. package/dist/src/compiler/normalize-subagent.js +1 -1
  33. package/dist/src/compiler/remote-agent-node.d.ts +3 -0
  34. package/dist/src/context/dynamic-subagent-lifecycle.d.ts +22 -0
  35. package/dist/src/context/dynamic-subagent-lifecycle.js +1 -0
  36. package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
  37. package/dist/src/context/keys.d.ts +13 -2
  38. package/dist/src/context/keys.js +1 -1
  39. package/dist/src/context/run-step.js +1 -1
  40. package/dist/src/execution/create-session-step.d.ts +2 -0
  41. package/dist/src/execution/create-session-step.js +1 -1
  42. package/dist/src/execution/delegation-tool.d.ts +3 -0
  43. package/dist/src/execution/delegation-tool.js +1 -0
  44. package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
  45. package/dist/src/execution/dispatch-workflow-runtime-actions-step.js +1 -1
  46. package/dist/src/execution/effective-agent-config.d.ts +12 -0
  47. package/dist/src/execution/effective-agent-config.js +1 -0
  48. package/dist/src/execution/node-step.d.ts +4 -0
  49. package/dist/src/execution/node-step.js +1 -1
  50. package/dist/src/execution/runtime-context.d.ts +2 -0
  51. package/dist/src/execution/runtime-context.js +1 -1
  52. package/dist/src/execution/session-callback-request.d.ts +5 -0
  53. package/dist/src/execution/session-callback-request.js +1 -0
  54. package/dist/src/execution/session-delivery-hook.d.ts +1 -0
  55. package/dist/src/execution/session-delivery-hook.js +1 -1
  56. package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
  57. package/dist/src/execution/subagent-event-proxy-step.js +1 -1
  58. package/dist/src/execution/workflow-entry.js +1 -1
  59. package/dist/src/execution/workflow-runtime.d.ts +2 -0
  60. package/dist/src/execution/workflow-runtime.js +1 -1
  61. package/dist/src/execution/workflow-steps.js +1 -1
  62. package/dist/src/harness/agent-handles.d.ts +238 -0
  63. package/dist/src/harness/agent-handles.js +2 -0
  64. package/dist/src/harness/compaction.d.ts +1 -1
  65. package/dist/src/harness/compaction.js +1 -1
  66. package/dist/src/harness/tool-loop.js +2 -2
  67. package/dist/src/harness/types.d.ts +16 -0
  68. package/dist/src/internal/application/package.js +1 -1
  69. package/dist/src/internal/authored-definition/core.js +1 -1
  70. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response-from-manifest.js +1 -1
  71. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.d.ts +1 -1
  72. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.js +1 -1
  73. package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
  74. package/dist/src/internal/vercel-agent-summary.d.ts +1 -1
  75. package/dist/src/protocol/clear-session.d.ts +14 -0
  76. package/dist/src/protocol/clear-session.js +1 -0
  77. package/dist/src/protocol/compact-session.d.ts +14 -0
  78. package/dist/src/protocol/compact-session.js +1 -0
  79. package/dist/src/protocol/message.d.ts +19 -1
  80. package/dist/src/protocol/message.js +1 -1
  81. package/dist/src/protocol/routes.d.ts +10 -0
  82. package/dist/src/protocol/routes.js +1 -1
  83. package/dist/src/public/channels/eve.js +1 -1
  84. package/dist/src/public/channels/index.d.ts +1 -1
  85. package/dist/src/public/definitions/agent.d.ts +32 -1
  86. package/dist/src/public/definitions/agent.js +1 -1
  87. package/dist/src/public/definitions/channel.d.ts +5 -2
  88. package/dist/src/public/definitions/channel.js +1 -1
  89. package/dist/src/public/definitions/hook.d.ts +1 -0
  90. package/dist/src/public/definitions/tool.d.ts +4 -1
  91. package/dist/src/public/index.d.ts +1 -2
  92. package/dist/src/public/index.js +1 -1
  93. package/dist/src/runtime/framework-tools/connection-search-dynamic.d.ts +2 -18
  94. package/dist/src/runtime/framework-tools/connection-search-dynamic.js +2 -2
  95. package/dist/src/runtime/framework-tools/index.d.ts +7 -2
  96. package/dist/src/runtime/framework-tools/index.js +1 -1
  97. package/dist/src/runtime/resolve-agent-graph.js +1 -1
  98. package/dist/src/runtime/resolve-agent.js +1 -1
  99. package/dist/src/runtime/resolve-dynamic-subagent.d.ts +12 -0
  100. package/dist/src/runtime/resolve-dynamic-subagent.js +1 -0
  101. package/dist/src/runtime/resolve-dynamic-tool.d.ts +15 -0
  102. package/dist/src/runtime/resolve-dynamic-tool.js +1 -1
  103. package/dist/src/runtime/subagents/dynamic-agent-config.d.ts +22 -0
  104. package/dist/src/runtime/subagents/dynamic-agent-config.js +1 -0
  105. package/dist/src/runtime/subagents/registry.d.ts +10 -2
  106. package/dist/src/runtime/subagents/registry.js +1 -1
  107. package/dist/src/runtime/types.d.ts +11 -2
  108. package/dist/src/setup/flows/registry.js +1 -1
  109. package/dist/src/setup/scaffold/create/project.js +1 -1
  110. package/dist/src/shared/agent-definition.d.ts +7 -0
  111. package/dist/src/shared/agent-turn-outcome.d.ts +47 -0
  112. package/dist/src/shared/agent-turn-outcome.js +1 -0
  113. package/dist/src/shared/dynamic-tool-definition.d.ts +1 -5
  114. package/dist/src/shared/dynamic-tool-definition.js +1 -1
  115. package/dist/src/svelte/index.js +1 -1
  116. package/dist/src/svelte/use-eve-agent.js +1 -1
  117. package/dist/src/vue/index.js +1 -1
  118. package/dist/src/vue/use-eve-agent.js +1 -1
  119. package/docs/channels/custom.mdx +41 -1
  120. package/docs/channels/eve.mdx +26 -1
  121. package/docs/concepts/default-harness.md +4 -0
  122. package/docs/guides/client/streaming.mdx +14 -0
  123. package/docs/guides/dev-tui.md +10 -7
  124. package/docs/guides/dynamic-capabilities.md +49 -6
  125. package/docs/reference/project-layout.md +1 -1
  126. package/docs/reference/typescript-api.md +48 -48
  127. package/docs/subagents.mdx +32 -2
  128. package/package.json +2 -2
@@ -1 +1 @@
1
- import{PROMPT_COMMANDS,formatPromptCommandHelp,parsePromptCommand}from"./prompt-commands.js";import{pickAgentHeaderTip}from"./agent-header.js";import{failureKey,formatFailureDetail,formatFailureHint,formatFailureMessage,isInterruptedError,localFailureHint}from"./errors.js";import{parseLogDisplayMode}from"./log-display-mode.js";import{createMcpConnectionStatusTracker}from"./mcp-connection-status.js";import{createRemoteConnectionController}from"./remote-connection.js";import{SubagentPump}from"./subagent-pump.js";import{BOOT_DETECTIONS,CLI_MISSING_SETUP_ISSUE,LOGIN_SETUP_ISSUE,detectSetupIssues,formatSetupIssuesLine,orderedSetupIssues,resolveModelProviderState}from"./setup-issues.js";import{TerminalRenderer}from"./terminal-renderer.js";import{createVercelStatusTracker}from"./vercel-status.js";import"#client/index.js";import{loadDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{toErrorMessage}from"#shared/errors.js";import{getVercelAuthStatus}from"#setup/vercel-project.js";import{probeAgentInfo}from"#services/dev-client/agent-info-probe.js";import{subscribeDevelopmentSandboxPrewarmLogs}from"#execution/sandbox/development-prewarm.js";import{createEventDeduper}from"#protocol/event-dedupe.js";import{createDevelopmentRuntimeArtifactRefresher}from"#services/dev-client.js";import{devBootPhase}from"#internal/dev-boot-progress.js";async function delayMs(e){await new Promise(t=>{setTimeout(t,e).unref?.()})}function authIssueForStatus(e){if(e===`logged-out`)return LOGIN_SETUP_ISSUE;if(e===`cli-missing`)return CLI_MISSING_SETUP_ISSUE}var EveTUIRunner=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S=!1;#C=new AbortController;#w=!1;#T=[];#E;#D;#O;#k=pickAgentHeaderTip();#A;#j=new Map;#M;#N=new Map;#P=new Set;#F=!1;#I;#L;constructor(t){this.#e=t.session,t.client!==void 0&&(this.#t=t.client),t.lifecycle!==void 0&&(this.#L=t.lifecycle),this.#n=createRenderer(t);let n={formatActionResultError};if(this.#t!==void 0&&(n.client=this.#t),this.#n.subagents!==void 0&&(n.view=this.#n.subagents),this.#M=new SubagentPump(n),this.#r=t.name??`eve`,this.#_=t.withExclusiveTerminal,this.#i=t.tools??`full`,this.#a=t.reasoning??`full`,this.#o=t.subagents??`full`,this.#s=t.connectionAuth??`full`,this.#c=t.assistantResponseStats??`tokensPerSecond`,this.#l=t.contextSize,this.#u=t.formatTransportError??toErrorMessage,t.initialInput!==void 0&&(this.#m=t.initialInput),t.appRoot!==void 0){this.#p=t.appRoot;let e={appRoot:t.appRoot,onChange:e=>this.#n.setVercelStatus?.(e)};t.detectProjectIdentity!==void 0&&(e.detectIdentity=t.detectProjectIdentity),this.#D=createVercelStatusTracker(e),t.probeMcpConnection!==void 0&&(this.#O=createMcpConnectionStatusTracker({onChange:()=>{},probe:t.probeMcpConnection}))}if(t.promptCommandHandler!==void 0&&(this.#h=t.promptCommandHandler),this.#g=t.availablePromptCommands??PROMPT_COMMANDS,t.remote!==void 0){if(this.#t===void 0)throw Error(`A remote TUI requires a configured development client.`);this.#v=createRemoteConnectionController({client:this.#t,credentials:t.remote.credentials,target:t.remote.target,onChange:e=>this.#n.setRemoteConnectionStatus?.(e),resolveOidcToken:t.remote.resolveOidcToken,resolveDeployment:t.remote.resolveDeployment})}this.#y=t.bootDetections??BOOT_DETECTIONS,this.#b=t.getVercelAuthStatus??getVercelAuthStatus,t.onBootProgress!==void 0&&(this.#x=t.onBootProgress),t.serverUrl!==void 0&&(this.#f=t.serverUrl),t.serverUrl!==void 0&&t.remote===void 0&&(this.#d=createDevelopmentRuntimeArtifactRefresher({serverUrl:t.serverUrl}))}async#R(){if(this.#f===void 0){this.#B(),await this.#Y(void 0);return}let e;if(this.#v!==void 0){let t=await this.#v.check();t.state===`ready`&&(e=t.info)}else{let t=this.#t;if(t!==void 0)try{let n=await devBootPhase(`connecting to agent`,()=>probeAgentInfo({client:t}),this.#x);n.kind===`ready`&&(e=n.info)}catch{e=void 0}}this.#B();let t=this.#z(e);await this.#Y(t)}#z(e){let t=this.#p===void 0?e:resolveModelProviderState(e,process.env);this.#A=t;let n=this.#f;if(n===void 0)return t;let r={name:this.#r,serverUrl:n};return t!==void 0&&(r.info=t),this.#p!==void 0&&(r.tip=this.#k),this.#n.renderAgentHeader?.(r),t}#B(){let e=this.#x;this.#x=void 0,e?.({type:`before-first-paint`})}async run(){let onStop=()=>this.#n.requestInterrupt?.();this.#L?.signal.aborted===!0?onStop():this.#L?.signal.addEventListener(`abort`,onStop,{once:!0});try{await this.#V()}finally{this.#L?.signal.removeEventListener(`abort`,onStop),this.#S=!0,this.#C.abort(),this.#M.abortAll(),this.#I?.(),this.#I=void 0,this.#n.shutdown?.(),this.#D?.dispose(),this.#O?.dispose(),this.#v?.dispose()}}async#V(){let e=this.#r,r,i,a=!1,o=!1,s=this.#m;await this.#R(),this.#v?.current().connection.state===`auth-required`&&await this.#ie({type:`extension`,name:`vc:login`,argument:``},e,{trigger:`startup`}),this.#$(),this.#D?.refreshIdentity(),this.#O?.refresh();let l=this.#m===void 0?void 0:parsePromptCommand(this.#m);for(l?.type===`extension`&&l.name===`model`&&l.argument===``&&this.#p!==void 0&&this.#h!==void 0&&this.#n.setupFlow!==void 0&&(s=void 0,await this.#ae(e));;){if(this.#L?.signal.aborted===!0||this.#n.exitRequested?.()===!0)return;if(!o){if(r==null){if(!this.#n.readPrompt){if(a)return;throw Error(`No prompt was provided and the renderer does not support prompt input.`)}let t={title:e};s!==void 0&&(t.initialDraft=s,s=void 0);try{r=await this.#W(t)}catch(e){if(isInterruptedError(e))return;throw e}if(r==null)return}let l=parsePromptCommand(r);if(l?.type===`exit`){this.#L?.requestStop();return}if(l?.type===`new`){if(!await this.#U()){i=void 0,o=!1,r=void 0;continue}i=void 0,o=!1,r=void 0;continue}if(l?.type===`help`){this.#ee(formatPromptCommandHelp(this.#g)),i=void 0,o=!1,r=void 0;continue}if(l?.type===`loglevel`){this.#ee(this.#ce(l.argument)),i=void 0,o=!1,r=void 0;continue}if(l?.type===`traces`){await this.#se(l.argument),i=void 0,o=!1,r=void 0;continue}if(l?.type===`extension`){try{await this.#ie(l,e,{trigger:`command`})}catch(e){if(isInterruptedError(e))return;throw e}i=void 0,r=void 0,o=!1;continue}a=!0}let l=await this.#G({prompt:o?void 0:r,inputResponses:i}),u=this.#e.state.sessionId;u!==void 0&&this.#n.setSessionId?.(u);let d=r,f=!1;try{for(;;){await this.#n.renderStream(l,{title:e,submittedPrompt:d,continueSession:!!this.#n.readPrompt,tools:this.#i,reasoning:this.#a,subagents:this.#o,connectionAuth:this.#s,assistantResponseStats:this.#c,contextSize:this.#l});let t=l.turnState?.pendingApprovals??[],n=l.turnState?.pendingQuestions??[];if(t.length>0||n.length>0){let a=[];if(t.length>0){if(!this.#n.readToolApproval)throw Error(`Tool approval was requested, but the renderer does not support tool approval input.`);for(let n of t){let t=await this.#n.readToolApproval(n,{title:e});a.push({requestId:n.approvalId,optionId:t.approved?`approve`:`deny`}),this.#j.delete(n.approvalId)}}if(n.length>0){if(!this.#n.readInputQuestion)throw Error(`An interactive question was requested, but the renderer does not support input questions.`);for(let t of n){let n=toAgentTUIInputQuestion(t),r=await this.#n.readInputQuestion(n,{title:e});if(r===void 0)continue;let i={requestId:t.requestId};r.optionId!==void 0&&(i.optionId=r.optionId),r.text!==void 0&&(i.text=r.text),a.push(i),this.#j.delete(t.requestId)}}if(a.length===0)break;o=!0,i=a,r=void 0,f=!0;break}if(this.#pe(l)){l=this.#q(),d=void 0;continue}if(l.turnState&&l.turnState.boundaryEvent===void 0)if(l.turnState.aborted)this.#F=!0;else{let e=this.#e.state.sessionId;this.#n.renderNotice?.(e?`Lost the event stream — the turn may still be running on the server (session ${e}). Your next message resumes this session; use /cancel to stop the turn.`:`Lost the connection to the running turn.`)}break}}catch(e){if(isInterruptedError(e))return;throw e}if(f)continue;o=!1,i=void 0,r=void 0;let p=l.turnState?.boundaryEvent;!this.#F&&(p===`session.waiting`||p===`session.completed`)&&(r=this.#n.takeQueuedPrompt?.()),this.#F&&(this.#F=!1,this.#H(),l.turnState?.aborted?this.#n.renderNotice?.(`Stopped following the turn and started a new session. Earlier context was cleared; the interrupted turn may still be running on the server.`):this.#n.renderSessionBoundary===void 0?this.#n.renderNotice?.(`Session ended — started a new session. Earlier context was cleared.`):this.#n.renderSessionBoundary())}}#H(){this.#M.abortAll(),this.#j.clear(),this.#N.clear(),this.#P.clear(),this.#n.setConnectionAuthPendingCount?.(0),this.#t&&(this.#e=this.#t.session()),this.#d?.clear()}async#U(){try{await this.#e.reset()}catch(e){return this.#n.renderNotice?.(`Couldn't reset the session: ${toErrorMessage(e)}`),!1}return this.#H(),this.#n.reset?.(),!0}async#W(e){if(!this.#n.readPrompt)return;let t=this.#n.readPrompt(e),n=this.#d;if(n===void 0)return await t;let r=!1,i=!1,a,refresh=async()=>{if(!(r||i)){i=!0;try{await n.refreshIdle({onRuntimeArtifactsChanged:()=>this.#de()})}finally{i=!1}}},startRefresh=()=>{if(r||i)return;let e=refresh().finally(()=>{a===e&&(a=void 0)});a=e};startRefresh();let o=setInterval(()=>{startRefresh()},500);o.unref?.();try{return await t}finally{r=!0,clearInterval(o),await a}}async#G(e){let t=new AbortController,n={signal:t.signal};e.prompt!==void 0&&(n.message=e.prompt),e.inputResponses!==void 0&&e.inputResponses.length>0&&(n.inputResponses=e.inputResponses);let r;try{this.#d!==void 0&&await this.#d.refresh({inputResponses:n.inputResponses,message:n.message,onRuntimeArtifactsChanged:()=>this.#de()}),n.message!==void 0&&(n.inputResponses?.length??0)===0&&this.#n.flushDelayedDevBuildErrors?.(),r=await this.#e.send(n)}catch(e){if(isInterruptedError(e))throw e;return this.#v?.reportFailure(e),this.#F=!0,{events:errorOnlyTUIStream({errorText:this.#u(e)}),turnState:createTurnState()}}return this.#J(r,()=>t.abort())}async#K(e){if(e.cancelInFlight!==!0){e.cancelInFlight=!0;try{for(let t=0;t<8;t+=1){if(e.boundaryEvent!==void 0||e.aborted===!0)return;let t=e.turnId;try{if((await this.#e.cancel(t===void 0?void 0:{turnId:t})).status===`accepted`)return}catch{}await delayMs(250)}}finally{e.cancelInFlight=!1}}}#q(){let e=new AbortController;return this.#J(this.#e.stream({signal:e.signal}),()=>e.abort())}#J(e,t){let n=createTurnState();return{abort:()=>{n.aborted=!0,t()},cancel:()=>{this.#K(n)},events:eveEventsToTUIStream({events:e,pendingInputRequests:this.#j,turnState:n,onSubagentCalled:e=>this.#M.begin(e),onSubagentCompleted:e=>this.#M.settle(e),onTurnCancelled:()=>this.#M.settleAll(),onConnectionAuthRequired:e=>this.#fe(e),onConnectionAuthCompleted:e=>this.#me(e),onTerminalFailure:()=>{this.#F=!0},failureHintOverride:this.#p===void 0?void 0:localFailureHint}),turnState:n}}async#Y(e){if(this.#p===void 0)return;let t={appRoot:this.#p,env:process.env};e!==void 0&&(t.info=e),this.#T=await detectSetupIssues(t,this.#y),this.#n.renderSetupWarning!==void 0&&(this.#X(),this.#Z())}#X(){let e=orderedSetupIssues(this.#T,this.#E);e.length>0?this.#n.renderSetupWarning?.(formatSetupIssuesLine(e)):this.#n.clearSetupWarning?.()}async#Z(){let e=this.#p;if(e===void 0)return;let t;try{t=await this.#b(e,{signal:this.#C.signal})}catch{return}this.#S||this.#w||(this.#E=authIssueForStatus(t),this.#X())}async#Q(e){let t=this.#p;if(t===void 0||this.#n.renderSetupWarning===void 0)return;let n={appRoot:t,env:process.env};e!==void 0&&(n.info=e);try{this.#T=await detectSetupIssues(n,this.#y);let e=await this.#b(t,{signal:this.#C.signal});this.#E=authIssueForStatus(e)}catch{return}this.#S||this.#X()}#$(){this.#p===void 0||this.#n.renderSandboxLog===void 0||this.#I===void 0&&(this.#I=subscribeDevelopmentSandboxPrewarmLogs({appRoot:this.#p,log:e=>this.#n.renderSandboxLog?.(e)}))}#ee(e,t){if(e!==void 0){if(this.#n.renderCommandResult!==void 0){this.#n.renderCommandResult(e,t);return}this.#n.renderNotice?.(e)}}async#te(e,t){let n=this.#h;if(n===void 0)return{message:`/${e.name} is not available in this session.`};let r={renderer:this.#n,title:t.title,initialModelStep:t.initialModelStep,remoteConnection:this.#v,withExclusiveTerminal:this.#_},i=this.#O?.current(),a=i!==void 0&&Object.keys(i).length>0?{...r,disabledConnectionReasons:i}:r;return t.keepSetupFlowOpen===!0?await n.handle(e,{...a,keepSetupFlowOpen:!0}):await n.handle(e,a)}#ne(e,t){if(t!==`startup`)return;let n=this.#v?.current().connection.state,r=n===`auth-failed`||n===`unavailable`?`failed`:void 0,i=e.argument.length===0?``:` ${e.argument}`;this.#n.renderCommandInvocation?.(`/${e.name}${i}`,r)}async#re(e){if(e?.kind===`model-access-changed`){this.#D?.applyEffect({kind:`refresh-identity`}),this.#w=!0,await this.#le();return}e!==void 0&&(this.#D?.applyEffect(e),this.#w=!0,this.#Q(this.#A))}async#ie(e,t,n){let r=await this.#te(e,{initialModelStep:n.initialModelStep,keepSetupFlowOpen:n.keepSetupFlowOpen,title:t});this.#ne(e,n.trigger),this.#ee(r?.message,r?.tone),await this.#re(r?.effect),this.#oe()}async#ae(e){let t=this.#p;if(t===void 0)return;let authStatus=async()=>{try{return await this.#b(t,{signal:this.#C.signal})}catch{return}},n=await authStatus();if(n===`cli-missing`&&(await this.#ie({type:`extension`,name:`vc:install`,argument:``},e,{trigger:`startup`,keepSetupFlowOpen:!0}),n=await authStatus(),n===`cli-missing`)){this.#n.setupFlow?.end();return}if(n===`logged-out`&&(await this.#ie({type:`extension`,name:`vc:login`,argument:``},e,{trigger:`startup`,keepSetupFlowOpen:!0}),n=await authStatus(),n===`cli-missing`||n===`logged-out`)){this.#n.setupFlow?.end();return}await this.#ie({type:`extension`,name:`model`,argument:``},e,{trigger:`startup`,initialModelStep:`provider`}),await this.#ie({type:`extension`,name:`add`,argument:``},e,{trigger:`startup`})}#oe(){let e=this.#v?.current().connection;e?.state!==`ready`||e.info===this.#A||(this.#A=e.info,this.#f!==void 0&&this.#n.renderAgentHeader?.({info:e.info,name:this.#r,serverUrl:this.#f}))}async#se(e){if(this.#p===void 0||this.#n.traceViewer===void 0){this.#ee(`/traces is only available in local dev sessions.`);return}try{await this.#n.traceViewer.open({appRoot:this.#p,sessionId:this.#e.state.sessionId,reference:e===``?void 0:e})}catch(e){if(isInterruptedError(e))return;throw e}}#ce(e){let t=this.#n;if(t.logDisplayMode===void 0||t.setLogDisplayMode===void 0)return`/loglevel is not available in this session.`;if(e===``)return`Logs: ${t.logDisplayMode()}. Use /loglevel all|stderr|sandbox|none — logs stay buffered, so switching also hides or restores past lines.`;let n=parseLogDisplayMode(e);if(n===void 0)return`Unknown log level "${e}". Use all, stderr, sandbox, or none.`;if(n===t.logDisplayMode())return`Logs already set to ${n}.`;switch(t.setLogDisplayMode(n),n){case`none`:return`Logs hidden. Output stays buffered — /loglevel all restores it.`;case`stderr`:return`Showing stderr logs only.`;case`sandbox`:return`Showing sandbox logs only.`;case`all`:return`Showing all logs.`}}async#le(){let e=this.#p;if(e===void 0)return;loadDevelopmentEnvironmentFiles(e);let t=this.#z(await this.#ue());this.#Q(t)}async#ue(){let e=this.#t;if(e===void 0)return;let t=await probeAgentInfo({client:e});return t.kind===`ready`?t.info:void 0}async#de(){let e=this.#A,t=await this.#ue();t!==void 0&&this.#z(t),(!this.#n.renderAgentHeader||t===void 0)&&this.#n.renderNotice?.(formatAgentUpdateNotice(e,t))}#fe(e){let t={name:e.data.name,description:e.data.description,state:`required`};e.data.authorization!==void 0&&(t.challenge=e.data.authorization),e.data.webhookUrl!==void 0&&(t.webhookUrl=e.data.webhookUrl),this.#N.set(e.data.name,t),this.#he(t)}#pe(e){if(e.turnState?.boundaryEvent!==`session.waiting`)return!1;let t=!1;for(let e of this.#N.values())e.state!==`required`||e.webhookUrl===void 0||(e.state=`pending`,this.#P.add(e.name),this.#he(e),t=!0);return t&&this.#n.setConnectionAuthPendingCount?.(this.#P.size),this.#P.size>0}#me(e){let t=this.#N.get(e.data.name)??{name:e.data.name,description:``,state:e.data.outcome};t.state=e.data.outcome,e.data.reason!==void 0&&(t.reason=e.data.reason),this.#N.set(e.data.name,t),this.#P.delete(e.data.name),this.#he(t),this.#n.setConnectionAuthPendingCount?.(this.#P.size)}#he(e){let t={name:e.name,description:e.description,state:e.state};e.challenge!==void 0&&(t.challenge=e.challenge),e.reason!==void 0&&(t.reason=e.reason),this.#n.upsertConnectionAuth?.(t)}};function createRenderer(e){return e.renderer?e.renderer:new TerminalRenderer({tools:e.tools,reasoning:e.reasoning,subagents:e.subagents,connectionAuth:e.connectionAuth,assistantResponseStats:e.assistantResponseStats,contextSize:e.contextSize,logs:e.logs,availablePromptCommands:e.availablePromptCommands,input:e.userInput,output:e.screen,diagnostics:e.diagnostics,onExitRequest:e.lifecycle?.requestStop})}function formatAgentUpdateNotice(e,t){let n=e?.agent.model.id,r=t?.agent.model.id;return n!==void 0&&r!==void 0&&n!==r?`Agent updated: Model ${n} -> ${r}`:`Agent updated.`}async function*eveEventsToTUIStream(e){let{events:t,pendingInputRequests:n,turnState:r,onSubagentCalled:i,onSubagentCompleted:a,onTurnCancelled:o,onConnectionAuthRequired:s,onConnectionAuthCompleted:c,onTerminalFailure:l,failureHintOverride:u}=e,d=new Map,f=new Map,p=createEventDeduper(),m=0,h=new Set,g=new Set,_=new Set,v=!1,y=!1,b;for await(let e of t)if(p.admit(e)&&!(y&&isPostTurnVisibleEvent(e)))switch(e.type){case`session.started`:case`message.received`:break;case`turn.started`:r.turnId=e.data.turnId;break;case`step.started`:m+=1,yield{type:`step-start`};break;case`step.completed`:{let t=e;b=t.data.usage,yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`step-finish`,usage:t.data.usage};break}case`message.appended`:{let t=e,n=textPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(d,n),i=t.data.messageSoFar;if(r.completed){if(m<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}if(!i.startsWith(r.text)||i.length<=r.text.length)break;let a=i.slice(r.text.length);r.text=i,yield{type:`assistant-delta`,id:partGenerationId(n,r.generation),delta:a};break}case`message.completed`:{let t=textPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(d,t),r=e.data.message;if(n.completed){if(r===null||m<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=m,yield{type:`assistant-complete`,id:partGenerationId(t,n.generation),text:r};break}let i=partGenerationId(t,n.generation);if(r!==null){if(n.text.length===0)n.text=r,n.completed=!0,n.completedEpoch=m,yield{type:`assistant-complete`,id:i,text:r};else if(r.startsWith(n.text)){let e=r.slice(n.text.length);e.length>0&&(yield{type:`assistant-delta`,id:i,delta:e}),n.text=r,n.completed=!0,n.completedEpoch=m,yield{type:`assistant-complete`,id:i}}}else n.text.length>0&&(n.completed=!0,n.completedEpoch=m,yield{type:`assistant-complete`,id:i});break}case`reasoning.appended`:{let t=e,n=reasoningPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(f,n),i=t.data.reasoningSoFar;if(r.completed){if(m<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}if(!i.startsWith(r.text)||i.length<=r.text.length)break;let a=i.slice(r.text.length);r.text=i,yield{type:`reasoning-delta`,id:partGenerationId(n,r.generation),delta:a};break}case`reasoning.completed`:{let t=reasoningPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(f,t),r=e.data.reasoning;if(n.completed){if(r.length===0||m<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=m;let e=partGenerationId(t,n.generation);yield{type:`reasoning-delta`,id:e,delta:r},yield{type:`reasoning-complete`,id:e};break}let i=partGenerationId(t,n.generation);if(n.text.length===0&&r.length>0)n.text=r,yield{type:`reasoning-delta`,id:i,delta:r};else if(r.length>0&&!r.startsWith(n.text))break;n.completed=!0,n.completedEpoch=m,yield{type:`reasoning-complete`,id:i};break}case`actions.requested`:{let t=e.data.actions.filter(e=>e.kind===`tool-call`);if(t.length===0)break;for(let e of t)h.has(e.callId)||(h.add(e.callId),yield{type:`tool-call`,toolCallId:e.callId,toolName:e.toolName,input:e.input});break}case`input.requested`:{let t=e.data.requests.filter(e=>e.action.kind===`tool-call`);if(t.length===0)break;for(let e of t){let t=e.action.callId;if(e.kind!==`session-limit`&&!h.has(t)&&(h.add(t),yield{type:`tool-call`,toolCallId:t,toolName:e.action.toolName,input:e.action.input}),!g.has(e.requestId)){if(g.add(e.requestId),n.set(e.requestId,e),e.kind!==`tool-approval`){upsertPendingQuestion(r,e);continue}upsertPendingApproval(r,e),yield{type:`tool-approval-request`,approvalId:e.requestId,toolCallId:t}}}break}case`action.result`:{let t=e;if(t.data.result.kind!==`tool-result`)break;let n=t.data.result.callId;if(!h.has(n))break;switch(t.data.status){case`completed`:yield{type:`tool-result`,toolCallId:n,output:t.data.result.output};break;case`failed`:yield{type:`tool-error`,toolCallId:n,errorText:formatActionResultError(t)};break;case`rejected`:yield{type:`tool-rejected`,toolCallId:n,reason:formatActionResultError(t)};break}break}case`step.failed`:case`turn.failed`:{let t=toFailureEvent(e,_,u);t&&(yield t);break}case`session.failed`:{r.sawSessionFailure=!0,l?.(e);let t=toFailureEvent(e,_,u);t&&(yield t),r.boundaryEvent=e.type,yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`finish`,usage:b},v=!0;return}case`session.waiting`:case`session.completed`:r.boundaryEvent=e.type,yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`finish`,usage:b},v=!0;return;case`turn.completed`:y=!0,yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m);break;case`turn.cancelled`:o?.(),yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`turn-cancelled`};break;case`subagent.called`:i?.(e);break;case`subagent.started`:case`subagent.event`:break;case`subagent.completed`:a?.(e.data.callId);break;case`authorization.required`:s?.(e);break;case`authorization.completed`:c?.(e);break;default:break}v||(yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`finish`,usage:b})}async function*errorOnlyTUIStream(e){yield{type:`error`,errorText:e.errorText},yield{type:`finish`}}function createTurnState(){return{aborted:!1,pendingApprovals:[],pendingQuestions:[],sawSessionFailure:!1}}function upsertPendingApproval(e,t){let n=toAgentTUIToolApprovalRequest(t),r=e.pendingApprovals.findIndex(e=>e.approvalId===n.approvalId);r===-1?e.pendingApprovals.push(n):e.pendingApprovals[r]=n}function toAgentTUIToolApprovalRequest(e){return{approvalId:e.requestId,toolCallId:e.action.callId,toolName:e.action.toolName,input:e.action.input}}function upsertPendingQuestion(e,t){let n=e.pendingQuestions.findIndex(e=>e.requestId===t.requestId);n===-1?e.pendingQuestions.push(t):e.pendingQuestions[n]=t}function textPartId(e,t){return`text:${e}:${t}`}function reasoningPartId(e,t){return`reasoning:${e}:${t}`}function partStateFor(e,t){let n=e.get(t);return n===void 0&&(n={generation:0,text:``,completed:!1,completedEpoch:0},e.set(t,n)),n}function partGenerationId(e,t){return t===0?e:`${e}#${t}`}function*closeOpenParts(e,t,n){for(let[r,i]of e)i.completed||i.text.length===0||(i.completed=!0,i.completedEpoch=n,yield{type:t,id:partGenerationId(r,i.generation)})}function isPostTurnVisibleEvent(e){switch(e.type){case`actions.requested`:case`authorization.completed`:case`authorization.required`:case`input.requested`:case`message.appended`:case`message.completed`:case`reasoning.appended`:case`reasoning.completed`:case`result.completed`:case`step.completed`:case`step.failed`:case`step.started`:case`subagent.called`:case`subagent.completed`:case`subagent.event`:case`subagent.started`:case`turn.completed`:case`turn.failed`:return!0;default:return!1}}function formatActionResultError(e){if(e.data.error?.message)return e.data.error.message;let t=e.data.result.output;if(typeof t==`string`)return t;try{return JSON.stringify(t)}catch{return`Tool execution failed.`}}function toFailureEvent(e,t,n){let r=failureKey(e);if(t.has(r))return;t.add(r);let c={type:`error`,errorText:formatFailureMessage(e)},l=n?.(e)??formatFailureHint(e);l!==void 0&&(c.hint=l);let u=formatFailureDetail(e);return u!==void 0&&(c.detail=u),c}function toAgentTUIInputQuestion(e){let t=e.display===`text`?`text`:e.display===`select`||e.options!==void 0&&e.options.length>0?`select`:`text`,n={requestId:e.requestId,prompt:e.prompt,display:t};return e.options!==void 0&&(n.options=e.options.map(e=>{let t={id:e.id,label:e.label};return e.description!==void 0&&(t.description=e.description),e.style!==void 0&&(t.style=e.style),t})),e.allowFreeform!==void 0&&(n.allowFreeform=e.allowFreeform),n}export{EveTUIRunner,parsePromptCommand};
1
+ import{PROMPT_COMMANDS,formatPromptCommandHelp,parsePromptCommand}from"./prompt-commands.js";import{pickAgentHeaderTip}from"./agent-header.js";import{failureKey,formatFailureDetail,formatFailureHint,formatFailureMessage,isInterruptedError,localFailureHint}from"./errors.js";import{parseLogDisplayMode}from"./log-display-mode.js";import{createMcpConnectionStatusTracker}from"./mcp-connection-status.js";import{createRemoteConnectionController}from"./remote-connection.js";import{SubagentPump}from"./subagent-pump.js";import{BOOT_DETECTIONS,CLI_MISSING_SETUP_ISSUE,LOGIN_SETUP_ISSUE,detectSetupIssues,formatSetupIssuesLine,orderedSetupIssues,resolveModelProviderState}from"./setup-issues.js";import{TerminalRenderer}from"./terminal-renderer.js";import{createVercelStatusTracker}from"./vercel-status.js";import"#client/index.js";import{loadDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{toErrorMessage}from"#shared/errors.js";import{getVercelAuthStatus}from"#setup/vercel-project.js";import{probeAgentInfo}from"#services/dev-client/agent-info-probe.js";import{subscribeDevelopmentSandboxPrewarmLogs}from"#execution/sandbox/development-prewarm.js";import{createEventDeduper}from"#protocol/event-dedupe.js";import{createDevelopmentRuntimeArtifactRefresher}from"#services/dev-client.js";import{devBootPhase}from"#internal/dev-boot-progress.js";async function delayMs(e){await new Promise(t=>{setTimeout(t,e).unref?.()})}function authIssueForStatus(e){if(e===`logged-out`)return LOGIN_SETUP_ISSUE;if(e===`cli-missing`)return CLI_MISSING_SETUP_ISSUE}var EveTUIRunner=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S=!1;#C=new AbortController;#w=!1;#T=[];#E;#D;#O;#k=pickAgentHeaderTip();#A;#j=new Map;#M;#N=new Map;#P=new Set;#F=!1;#I;#L;constructor(t){this.#e=t.session,t.client!==void 0&&(this.#t=t.client),t.lifecycle!==void 0&&(this.#L=t.lifecycle),this.#n=createRenderer(t);let n={formatActionResultError};if(this.#t!==void 0&&(n.client=this.#t),this.#n.subagents!==void 0&&(n.view=this.#n.subagents),this.#M=new SubagentPump(n),this.#r=t.name??`eve`,this.#_=t.withExclusiveTerminal,this.#i=t.tools??`full`,this.#a=t.reasoning??`full`,this.#o=t.subagents??`full`,this.#s=t.connectionAuth??`full`,this.#c=t.assistantResponseStats??`tokensPerSecond`,this.#l=t.contextSize,this.#u=t.formatTransportError??toErrorMessage,t.initialInput!==void 0&&(this.#m=t.initialInput),t.appRoot!==void 0){this.#p=t.appRoot;let e={appRoot:t.appRoot,onChange:e=>this.#n.setVercelStatus?.(e)};t.detectProjectIdentity!==void 0&&(e.detectIdentity=t.detectProjectIdentity),this.#D=createVercelStatusTracker(e),t.probeMcpConnection!==void 0&&(this.#O=createMcpConnectionStatusTracker({onChange:()=>{},probe:t.probeMcpConnection}))}if(t.promptCommandHandler!==void 0&&(this.#h=t.promptCommandHandler),this.#g=t.availablePromptCommands??PROMPT_COMMANDS,t.remote!==void 0){if(this.#t===void 0)throw Error(`A remote TUI requires a configured development client.`);this.#v=createRemoteConnectionController({client:this.#t,credentials:t.remote.credentials,target:t.remote.target,onChange:e=>this.#n.setRemoteConnectionStatus?.(e),resolveOidcToken:t.remote.resolveOidcToken,resolveDeployment:t.remote.resolveDeployment})}this.#y=t.bootDetections??BOOT_DETECTIONS,this.#b=t.getVercelAuthStatus??getVercelAuthStatus,t.onBootProgress!==void 0&&(this.#x=t.onBootProgress),t.serverUrl!==void 0&&(this.#f=t.serverUrl),t.serverUrl!==void 0&&t.remote===void 0&&(this.#d=createDevelopmentRuntimeArtifactRefresher({serverUrl:t.serverUrl}))}async#R(){if(this.#f===void 0){this.#B(),await this.#Y(void 0);return}let e;if(this.#v!==void 0){let t=await this.#v.check();t.state===`ready`&&(e=t.info)}else{let t=this.#t;if(t!==void 0)try{let n=await devBootPhase(`connecting to agent`,()=>probeAgentInfo({client:t}),this.#x);n.kind===`ready`&&(e=n.info)}catch{e=void 0}}this.#B();let t=this.#z(e);await this.#Y(t)}#z(e){let t=this.#p===void 0?e:resolveModelProviderState(e,process.env);this.#A=t;let n=this.#f;if(n===void 0)return t;let r={name:this.#r,serverUrl:n};return t!==void 0&&(r.info=t),this.#p!==void 0&&(r.tip=this.#k),this.#n.renderAgentHeader?.(r),t}#B(){let e=this.#x;this.#x=void 0,e?.({type:`before-first-paint`})}async run(){let onStop=()=>this.#n.requestInterrupt?.();this.#L?.signal.aborted===!0?onStop():this.#L?.signal.addEventListener(`abort`,onStop,{once:!0});try{await this.#V()}finally{this.#L?.signal.removeEventListener(`abort`,onStop),this.#S=!0,this.#C.abort(),this.#M.abortAll(),this.#I?.(),this.#I=void 0,this.#n.shutdown?.(),this.#D?.dispose(),this.#O?.dispose(),this.#v?.dispose()}}async#V(){let e=this.#r,r,i,a=!1,o=!1,s=!1,l=this.#m;await this.#R(),this.#v?.current().connection.state===`auth-required`&&await this.#ie({type:`extension`,name:`vc:login`,argument:``},e,{trigger:`startup`}),this.#$(),this.#D?.refreshIdentity(),this.#O?.refresh();let u=this.#m===void 0?void 0:parsePromptCommand(this.#m);for(u?.type===`extension`&&u.name===`model`&&u.argument===``&&this.#p!==void 0&&this.#h!==void 0&&this.#n.setupFlow!==void 0&&(l=void 0,await this.#ae(e));;){if(this.#L?.signal.aborted===!0||this.#n.exitRequested?.()===!0)return;if(!s){if(r==null){if(!this.#n.readPrompt){if(a)return;throw Error(`No prompt was provided and the renderer does not support prompt input.`)}let t={title:e};l!==void 0&&(t.initialDraft=l,l=void 0);try{r=await this.#W(t)}catch(e){if(isInterruptedError(e))return;throw e}if(r==null)return}let u=parsePromptCommand(r);if(u?.type===`exit`){this.#L?.requestStop();return}if(u?.type===`cancel`){if(this.#e.state.sessionId===void 0){this.#ee(`No active turn to cancel.`),i=void 0,o=!1,s=!1,r=void 0;continue}try{let e=await this.#e.cancel();if(this.#ee(e.status===`accepted`?`Turn cancellation requested.`:`No active turn to cancel.`),e.status===`no_active_turn`){i=void 0,o=!1,s=!1,r=void 0;continue}}catch(e){this.#ee(`Couldn't cancel the turn: ${toErrorMessage(e)}`),i=void 0,o=!1,s=!1,r=void 0;continue}i=void 0,o=!0,s=!1,r=void 0}if(u?.type===`reset`){if(!await this.#U()){i=void 0,s=!1,r=void 0;continue}i=void 0,s=!1,r=void 0;continue}if(u?.type===`compact`){try{let e=await this.#e.compact();if(this.#ee(e.status===`accepted`?`Compaction requested.`:`No active session to compact.`),e.status===`no_active_session`){i=void 0,o=!1,s=!1,r=void 0;continue}}catch(e){this.#ee(`Couldn't compact the session: ${toErrorMessage(e)}`),i=void 0,o=!1,s=!1,r=void 0;continue}i=void 0,o=!0,s=!1,r=void 0}if(u?.type===`clear`){try{let e=await this.#e.clear();if(this.#ee(e.status===`accepted`?`Context clear requested.`:`No active session to clear.`),e.status===`no_active_session`){i=void 0,o=!1,s=!1,r=void 0;continue}}catch(e){this.#ee(`Couldn't clear the session: ${toErrorMessage(e)}`),i=void 0,o=!1,s=!1,r=void 0;continue}i=void 0,o=!0,s=!1,r=void 0}if(u?.type===`help`){this.#ee(formatPromptCommandHelp(this.#g)),i=void 0,s=!1,r=void 0;continue}if(u?.type===`loglevel`){this.#ee(this.#ce(u.argument)),i=void 0,s=!1,r=void 0;continue}if(u?.type===`traces`){await this.#se(u.argument),i=void 0,s=!1,r=void 0;continue}if(u?.type===`extension`){try{await this.#ie(u,e,{trigger:`command`})}catch(e){if(isInterruptedError(e))return;throw e}i=void 0,r=void 0,s=!1;continue}a=!0}let u=o?this.#q():await this.#G({prompt:s?void 0:r,inputResponses:i}),d=this.#e.state.sessionId;d!==void 0&&this.#n.setSessionId?.(d);let f=r,p=!1;try{for(;;){await this.#n.renderStream(u,{title:e,submittedPrompt:f,continueSession:!!this.#n.readPrompt,tools:this.#i,reasoning:this.#a,subagents:this.#o,connectionAuth:this.#s,assistantResponseStats:this.#c,contextSize:this.#l});let t=u.turnState?.pendingApprovals??[],n=u.turnState?.pendingQuestions??[];if(t.length>0||n.length>0){let a=[];if(t.length>0){if(!this.#n.readToolApproval)throw Error(`Tool approval was requested, but the renderer does not support tool approval input.`);for(let n of t){let t=await this.#n.readToolApproval(n,{title:e});a.push({requestId:n.approvalId,optionId:t.approved?`approve`:`deny`}),this.#j.delete(n.approvalId)}}if(n.length>0){if(!this.#n.readInputQuestion)throw Error(`An interactive question was requested, but the renderer does not support input questions.`);for(let t of n){let n=toAgentTUIInputQuestion(t),r=await this.#n.readInputQuestion(n,{title:e});if(r===void 0)continue;let i={requestId:t.requestId};r.optionId!==void 0&&(i.optionId=r.optionId),r.text!==void 0&&(i.text=r.text),a.push(i),this.#j.delete(t.requestId)}}if(a.length===0)break;s=!0,i=a,r=void 0,p=!0;break}if(this.#pe(u)){u=this.#q(),f=void 0;continue}if(u.turnState&&u.turnState.boundaryEvent===void 0)if(u.turnState.aborted)this.#F=!0;else{let e=this.#e.state.sessionId;this.#n.renderNotice?.(e?`Lost the event stream — the turn may still be running on the server (session ${e}). Your next message resumes this session; use /cancel to stop the turn.`:`Lost the connection to the running turn.`)}break}}catch(e){if(isInterruptedError(e))return;throw e}if(p)continue;o=!1,s=!1,i=void 0,r=void 0;let m=u.turnState?.boundaryEvent;!this.#F&&(m===`session.waiting`||m===`session.completed`)&&(r=this.#n.takeQueuedPrompt?.()),this.#F&&(this.#F=!1,this.#H(),u.turnState?.aborted?this.#n.renderNotice?.(`Stopped following the turn and started a new session. Earlier context was cleared; the interrupted turn may still be running on the server.`):this.#n.renderSessionBoundary===void 0?this.#n.renderNotice?.(`Session ended — started a new session. Earlier context was cleared.`):this.#n.renderSessionBoundary())}}#H(){this.#M.abortAll(),this.#j.clear(),this.#N.clear(),this.#P.clear(),this.#n.setConnectionAuthPendingCount?.(0),this.#t&&(this.#e=this.#t.session()),this.#d?.clear()}async#U(){try{await this.#e.reset()}catch(e){return this.#n.renderNotice?.(`Couldn't reset the session: ${toErrorMessage(e)}`),!1}return this.#H(),this.#n.reset?.(),!0}async#W(e){if(!this.#n.readPrompt)return;let t=this.#n.readPrompt(e),n=this.#d;if(n===void 0)return await t;let r=!1,i=!1,a,refresh=async()=>{if(!(r||i)){i=!0;try{await n.refreshIdle({onRuntimeArtifactsChanged:()=>this.#de()})}finally{i=!1}}},startRefresh=()=>{if(r||i)return;let e=refresh().finally(()=>{a===e&&(a=void 0)});a=e};startRefresh();let o=setInterval(()=>{startRefresh()},500);o.unref?.();try{return await t}finally{r=!0,clearInterval(o),await a}}async#G(e){let t=new AbortController,n={signal:t.signal};e.prompt!==void 0&&(n.message=e.prompt),e.inputResponses!==void 0&&e.inputResponses.length>0&&(n.inputResponses=e.inputResponses);let r;try{this.#d!==void 0&&await this.#d.refresh({inputResponses:n.inputResponses,message:n.message,onRuntimeArtifactsChanged:()=>this.#de()}),n.message!==void 0&&(n.inputResponses?.length??0)===0&&this.#n.flushDelayedDevBuildErrors?.(),r=await this.#e.send(n)}catch(e){if(isInterruptedError(e))throw e;return this.#v?.reportFailure(e),this.#F=!0,{events:errorOnlyTUIStream({errorText:this.#u(e)}),turnState:createTurnState()}}return this.#J(r,()=>t.abort())}async#K(e){if(e.cancelInFlight!==!0){e.cancelInFlight=!0;try{for(let t=0;t<8;t+=1){if(e.boundaryEvent!==void 0||e.aborted===!0)return;let t=e.turnId;try{if((await this.#e.cancel(t===void 0?void 0:{turnId:t})).status===`accepted`)return}catch{}await delayMs(250)}}finally{e.cancelInFlight=!1}}}#q(){let e=new AbortController;return this.#J(this.#e.stream({signal:e.signal}),()=>e.abort())}#J(e,t){let n=createTurnState();return{abort:()=>{n.aborted=!0,t()},cancel:()=>{this.#K(n)},events:eveEventsToTUIStream({events:e,pendingInputRequests:this.#j,turnState:n,onSubagentCalled:e=>this.#M.begin(e),onSubagentCompleted:e=>this.#M.settle(e),onTurnCancelled:()=>this.#M.settleAll(),onConnectionAuthRequired:e=>this.#fe(e),onConnectionAuthCompleted:e=>this.#me(e),onTerminalFailure:()=>{this.#F=!0},failureHintOverride:this.#p===void 0?void 0:localFailureHint}),turnState:n}}async#Y(e){if(this.#p===void 0)return;let t={appRoot:this.#p,env:process.env};e!==void 0&&(t.info=e),this.#T=await detectSetupIssues(t,this.#y),this.#n.renderSetupWarning!==void 0&&(this.#X(),this.#Z())}#X(){let e=orderedSetupIssues(this.#T,this.#E);e.length>0?this.#n.renderSetupWarning?.(formatSetupIssuesLine(e)):this.#n.clearSetupWarning?.()}async#Z(){let e=this.#p;if(e===void 0)return;let t;try{t=await this.#b(e,{signal:this.#C.signal})}catch{return}this.#S||this.#w||(this.#E=authIssueForStatus(t),this.#X())}async#Q(e){let t=this.#p;if(t===void 0||this.#n.renderSetupWarning===void 0)return;let n={appRoot:t,env:process.env};e!==void 0&&(n.info=e);try{this.#T=await detectSetupIssues(n,this.#y);let e=await this.#b(t,{signal:this.#C.signal});this.#E=authIssueForStatus(e)}catch{return}this.#S||this.#X()}#$(){this.#p===void 0||this.#n.renderSandboxLog===void 0||this.#I===void 0&&(this.#I=subscribeDevelopmentSandboxPrewarmLogs({appRoot:this.#p,log:e=>this.#n.renderSandboxLog?.(e)}))}#ee(e,t){if(e!==void 0){if(this.#n.renderCommandResult!==void 0){this.#n.renderCommandResult(e,t);return}this.#n.renderNotice?.(e)}}async#te(e,t){let n=this.#h;if(n===void 0)return{message:`/${e.name} is not available in this session.`};let r={renderer:this.#n,title:t.title,initialModelStep:t.initialModelStep,remoteConnection:this.#v,withExclusiveTerminal:this.#_},i=this.#O?.current(),a=i!==void 0&&Object.keys(i).length>0?{...r,disabledConnectionReasons:i}:r;return t.keepSetupFlowOpen===!0?await n.handle(e,{...a,keepSetupFlowOpen:!0}):await n.handle(e,a)}#ne(e,t){if(t!==`startup`)return;let n=this.#v?.current().connection.state,r=n===`auth-failed`||n===`unavailable`?`failed`:void 0,i=e.argument.length===0?``:` ${e.argument}`;this.#n.renderCommandInvocation?.(`/${e.name}${i}`,r)}async#re(e){if(e?.kind===`model-access-changed`){this.#D?.applyEffect({kind:`refresh-identity`}),this.#w=!0,await this.#le();return}e!==void 0&&(this.#D?.applyEffect(e),this.#w=!0,this.#Q(this.#A))}async#ie(e,t,n){let r=await this.#te(e,{initialModelStep:n.initialModelStep,keepSetupFlowOpen:n.keepSetupFlowOpen,title:t});this.#ne(e,n.trigger),this.#ee(r?.message,r?.tone),await this.#re(r?.effect),this.#oe()}async#ae(e){let t=this.#p;if(t===void 0)return;let authStatus=async()=>{try{return await this.#b(t,{signal:this.#C.signal})}catch{return}},n=await authStatus();if(n===`cli-missing`&&(await this.#ie({type:`extension`,name:`vc:install`,argument:``},e,{trigger:`startup`,keepSetupFlowOpen:!0}),n=await authStatus(),n===`cli-missing`)){this.#n.setupFlow?.end();return}if(n===`logged-out`&&(await this.#ie({type:`extension`,name:`vc:login`,argument:``},e,{trigger:`startup`,keepSetupFlowOpen:!0}),n=await authStatus(),n===`cli-missing`||n===`logged-out`)){this.#n.setupFlow?.end();return}await this.#ie({type:`extension`,name:`model`,argument:``},e,{trigger:`startup`,initialModelStep:`provider`}),await this.#ie({type:`extension`,name:`add`,argument:``},e,{trigger:`startup`})}#oe(){let e=this.#v?.current().connection;e?.state!==`ready`||e.info===this.#A||(this.#A=e.info,this.#f!==void 0&&this.#n.renderAgentHeader?.({info:e.info,name:this.#r,serverUrl:this.#f}))}async#se(e){if(this.#p===void 0||this.#n.traceViewer===void 0){this.#ee(`/traces is only available in local dev sessions.`);return}try{await this.#n.traceViewer.open({appRoot:this.#p,sessionId:this.#e.state.sessionId,reference:e===``?void 0:e})}catch(e){if(isInterruptedError(e))return;throw e}}#ce(e){let t=this.#n;if(t.logDisplayMode===void 0||t.setLogDisplayMode===void 0)return`/loglevel is not available in this session.`;if(e===``)return`Logs: ${t.logDisplayMode()}. Use /loglevel all|stderr|sandbox|none — logs stay buffered, so switching also hides or restores past lines.`;let n=parseLogDisplayMode(e);if(n===void 0)return`Unknown log level "${e}". Use all, stderr, sandbox, or none.`;if(n===t.logDisplayMode())return`Logs already set to ${n}.`;switch(t.setLogDisplayMode(n),n){case`none`:return`Logs hidden. Output stays buffered — /loglevel all restores it.`;case`stderr`:return`Showing stderr logs only.`;case`sandbox`:return`Showing sandbox logs only.`;case`all`:return`Showing all logs.`}}async#le(){let e=this.#p;if(e===void 0)return;loadDevelopmentEnvironmentFiles(e);let t=this.#z(await this.#ue());this.#Q(t)}async#ue(){let e=this.#t;if(e===void 0)return;let t=await probeAgentInfo({client:e});return t.kind===`ready`?t.info:void 0}async#de(){let e=this.#A,t=await this.#ue();t!==void 0&&this.#z(t),(!this.#n.renderAgentHeader||t===void 0)&&this.#n.renderNotice?.(formatAgentUpdateNotice(e,t))}#fe(e){let t={name:e.data.name,description:e.data.description,state:`required`};e.data.authorization!==void 0&&(t.challenge=e.data.authorization),e.data.webhookUrl!==void 0&&(t.webhookUrl=e.data.webhookUrl),this.#N.set(e.data.name,t),this.#he(t)}#pe(e){if(e.turnState?.boundaryEvent!==`session.waiting`)return!1;let t=!1;for(let e of this.#N.values())e.state!==`required`||e.webhookUrl===void 0||(e.state=`pending`,this.#P.add(e.name),this.#he(e),t=!0);return t&&this.#n.setConnectionAuthPendingCount?.(this.#P.size),this.#P.size>0}#me(e){let t=this.#N.get(e.data.name)??{name:e.data.name,description:``,state:e.data.outcome};t.state=e.data.outcome,e.data.reason!==void 0&&(t.reason=e.data.reason),this.#N.set(e.data.name,t),this.#P.delete(e.data.name),this.#he(t),this.#n.setConnectionAuthPendingCount?.(this.#P.size)}#he(e){let t={name:e.name,description:e.description,state:e.state};e.challenge!==void 0&&(t.challenge=e.challenge),e.reason!==void 0&&(t.reason=e.reason),this.#n.upsertConnectionAuth?.(t)}};function createRenderer(e){return e.renderer?e.renderer:new TerminalRenderer({tools:e.tools,reasoning:e.reasoning,subagents:e.subagents,connectionAuth:e.connectionAuth,assistantResponseStats:e.assistantResponseStats,contextSize:e.contextSize,logs:e.logs,availablePromptCommands:e.availablePromptCommands,input:e.userInput,output:e.screen,diagnostics:e.diagnostics,onExitRequest:e.lifecycle?.requestStop})}function formatAgentUpdateNotice(e,t){let n=e?.agent.model.id,r=t?.agent.model.id;return n!==void 0&&r!==void 0&&n!==r?`Agent updated: Model ${n} -> ${r}`:`Agent updated.`}async function*eveEventsToTUIStream(e){let{events:t,pendingInputRequests:n,turnState:r,onSubagentCalled:i,onSubagentCompleted:a,onTurnCancelled:o,onConnectionAuthRequired:s,onConnectionAuthCompleted:c,onTerminalFailure:l,failureHintOverride:u}=e,d=new Map,f=new Map,p=createEventDeduper(),m=0,h=new Set,g=new Set,_=new Set,v=!1,y=!1,b;for await(let e of t)if(p.admit(e)&&!(y&&isPostTurnVisibleEvent(e)))switch(e.type){case`session.started`:case`message.received`:break;case`turn.started`:r.turnId=e.data.turnId;break;case`step.started`:m+=1,yield{type:`step-start`};break;case`step.completed`:{let t=e;b=t.data.usage,yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`step-finish`,usage:t.data.usage};break}case`message.appended`:{let t=e,n=textPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(d,n),i=t.data.messageSoFar;if(r.completed){if(m<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}if(!i.startsWith(r.text)||i.length<=r.text.length)break;let a=i.slice(r.text.length);r.text=i,yield{type:`assistant-delta`,id:partGenerationId(n,r.generation),delta:a};break}case`message.completed`:{let t=textPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(d,t),r=e.data.message;if(n.completed){if(r===null||m<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=m,yield{type:`assistant-complete`,id:partGenerationId(t,n.generation),text:r};break}let i=partGenerationId(t,n.generation);if(r!==null){if(n.text.length===0)n.text=r,n.completed=!0,n.completedEpoch=m,yield{type:`assistant-complete`,id:i,text:r};else if(r.startsWith(n.text)){let e=r.slice(n.text.length);e.length>0&&(yield{type:`assistant-delta`,id:i,delta:e}),n.text=r,n.completed=!0,n.completedEpoch=m,yield{type:`assistant-complete`,id:i}}}else n.text.length>0&&(n.completed=!0,n.completedEpoch=m,yield{type:`assistant-complete`,id:i});break}case`reasoning.appended`:{let t=e,n=reasoningPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(f,n),i=t.data.reasoningSoFar;if(r.completed){if(m<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}if(!i.startsWith(r.text)||i.length<=r.text.length)break;let a=i.slice(r.text.length);r.text=i,yield{type:`reasoning-delta`,id:partGenerationId(n,r.generation),delta:a};break}case`reasoning.completed`:{let t=reasoningPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(f,t),r=e.data.reasoning;if(n.completed){if(r.length===0||m<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=m;let e=partGenerationId(t,n.generation);yield{type:`reasoning-delta`,id:e,delta:r},yield{type:`reasoning-complete`,id:e};break}let i=partGenerationId(t,n.generation);if(n.text.length===0&&r.length>0)n.text=r,yield{type:`reasoning-delta`,id:i,delta:r};else if(r.length>0&&!r.startsWith(n.text))break;n.completed=!0,n.completedEpoch=m,yield{type:`reasoning-complete`,id:i};break}case`actions.requested`:{let t=e.data.actions.filter(e=>e.kind===`tool-call`);if(t.length===0)break;for(let e of t)h.has(e.callId)||(h.add(e.callId),yield{type:`tool-call`,toolCallId:e.callId,toolName:e.toolName,input:e.input});break}case`input.requested`:{let t=e.data.requests.filter(e=>e.action.kind===`tool-call`);if(t.length===0)break;for(let e of t){let t=e.action.callId;if(e.kind!==`session-limit`&&!h.has(t)&&(h.add(t),yield{type:`tool-call`,toolCallId:t,toolName:e.action.toolName,input:e.action.input}),!g.has(e.requestId)){if(g.add(e.requestId),n.set(e.requestId,e),e.kind!==`tool-approval`){upsertPendingQuestion(r,e);continue}upsertPendingApproval(r,e),yield{type:`tool-approval-request`,approvalId:e.requestId,toolCallId:t}}}break}case`action.result`:{let t=e;if(t.data.result.kind!==`tool-result`)break;let n=t.data.result.callId;if(!h.has(n))break;switch(t.data.status){case`completed`:yield{type:`tool-result`,toolCallId:n,output:t.data.result.output};break;case`failed`:yield{type:`tool-error`,toolCallId:n,errorText:formatActionResultError(t)};break;case`rejected`:yield{type:`tool-rejected`,toolCallId:n,reason:formatActionResultError(t)};break}break}case`step.failed`:case`turn.failed`:{let t=toFailureEvent(e,_,u);t&&(yield t);break}case`session.failed`:{r.sawSessionFailure=!0,l?.(e);let t=toFailureEvent(e,_,u);t&&(yield t),r.boundaryEvent=e.type,yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`finish`,usage:b},v=!0;return}case`session.waiting`:case`session.completed`:r.boundaryEvent=e.type,yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`finish`,usage:b},v=!0;return;case`turn.completed`:y=!0,yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m);break;case`turn.cancelled`:o?.(),yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`turn-cancelled`};break;case`subagent.called`:i?.(e);break;case`subagent.started`:case`subagent.event`:break;case`subagent.completed`:a?.(e.data.callId);break;case`authorization.required`:s?.(e);break;case`authorization.completed`:c?.(e);break;default:break}v||(yield*closeOpenParts(d,`assistant-complete`,m),yield*closeOpenParts(f,`reasoning-complete`,m),yield{type:`finish`,usage:b})}async function*errorOnlyTUIStream(e){yield{type:`error`,errorText:e.errorText},yield{type:`finish`}}function createTurnState(){return{aborted:!1,pendingApprovals:[],pendingQuestions:[],sawSessionFailure:!1}}function upsertPendingApproval(e,t){let n=toAgentTUIToolApprovalRequest(t),r=e.pendingApprovals.findIndex(e=>e.approvalId===n.approvalId);r===-1?e.pendingApprovals.push(n):e.pendingApprovals[r]=n}function toAgentTUIToolApprovalRequest(e){return{approvalId:e.requestId,toolCallId:e.action.callId,toolName:e.action.toolName,input:e.action.input}}function upsertPendingQuestion(e,t){let n=e.pendingQuestions.findIndex(e=>e.requestId===t.requestId);n===-1?e.pendingQuestions.push(t):e.pendingQuestions[n]=t}function textPartId(e,t){return`text:${e}:${t}`}function reasoningPartId(e,t){return`reasoning:${e}:${t}`}function partStateFor(e,t){let n=e.get(t);return n===void 0&&(n={generation:0,text:``,completed:!1,completedEpoch:0},e.set(t,n)),n}function partGenerationId(e,t){return t===0?e:`${e}#${t}`}function*closeOpenParts(e,t,n){for(let[r,i]of e)i.completed||i.text.length===0||(i.completed=!0,i.completedEpoch=n,yield{type:t,id:partGenerationId(r,i.generation)})}function isPostTurnVisibleEvent(e){switch(e.type){case`actions.requested`:case`authorization.completed`:case`authorization.required`:case`input.requested`:case`message.appended`:case`message.completed`:case`reasoning.appended`:case`reasoning.completed`:case`result.completed`:case`step.completed`:case`step.failed`:case`step.started`:case`subagent.called`:case`subagent.completed`:case`subagent.event`:case`subagent.started`:case`turn.completed`:case`turn.failed`:return!0;default:return!1}}function formatActionResultError(e){if(e.data.error?.message)return e.data.error.message;let t=e.data.result.output;if(typeof t==`string`)return t;try{return JSON.stringify(t)}catch{return`Tool execution failed.`}}function toFailureEvent(e,t,n){let r=failureKey(e);if(t.has(r))return;t.add(r);let c={type:`error`,errorText:formatFailureMessage(e)},l=n?.(e)??formatFailureHint(e);l!==void 0&&(c.hint=l);let u=formatFailureDetail(e);return u!==void 0&&(c.detail=u),c}function toAgentTUIInputQuestion(e){let t=e.display===`text`?`text`:e.display===`select`||e.options!==void 0&&e.options.length>0?`select`:`text`,n={requestId:e.requestId,prompt:e.prompt,display:t};return e.options!==void 0&&(n.options=e.options.map(e=>{let t={id:e.id,label:e.label};return e.description!==void 0&&(t.description=e.description),e.style!==void 0&&(t.style=e.style),t})),e.allowFreeform!==void 0&&(n.allowFreeform=e.allowFreeform),n}export{EveTUIRunner,parsePromptCommand};
@@ -131,11 +131,11 @@ export declare class SubagentPump {
131
131
  abortAll(): void;
132
132
  /**
133
133
  * Settles every live run and stops its child stream. Called when the
134
- * parent turn is cancelled (an Esc steer or Esc Esc): the server cancels
135
- * the pending descendants, so their sections must close now — a child
136
- * still flushing reasoning would otherwise keep painting stale sections
137
- * into the next (steered) turn's transcript. Runs stay registered so a
138
- * late parent `subagent.completed` settles as a no-op.
134
+ * parent turn is cancelled (`/cancel`, an Esc steer, or an empty-queue
135
+ * Esc): the server cancels the pending descendants, so their sections must
136
+ * close now. A child still flushing reasoning would otherwise keep painting
137
+ * stale sections into the next (steered) turn's transcript. Runs stay
138
+ * registered so a late parent `subagent.completed` settles as a no-op.
139
139
  */
140
140
  settleAll(): void;
141
141
  }
@@ -3,7 +3,7 @@ import{PROMPT_COMMANDS,isPromptControlCommand,parsePromptCommand}from"./prompt-c
3
3
  `).map(stripPromptControlCharacters).join(`
4
4
  `),i=stripPromptControlCharacters(e?.initialDraft??this.#V.text),a=lineOf(r===void 0?i:i.length===0?r:`${r}\n\n${i}`);return this.#V=EMPTY_LINE,this.#P.begin(a.text),this.#We(a),this.#I=typeaheadFor(this.#f,a.text),this.#At(),this.#rn(),await new Promise((e,r)=>{this.#W=r;let apply=e=>{a=e,this.#Mt(),this.#We(a),this.#I=typeaheadFor(this.#f,e.text,this.#I),this.#rn()},recall=e=>{e!==void 0&&apply(lineOf(e))},interrupt=()=>{this.#I=void 0,this.#jt(),this.#xt(),r(interruptedError())},suggestions=()=>this.#I!==void 0&&isTypeaheadOpen(this.#I)?this.#I:void 0,highlighted=()=>{let e=suggestions();return e===void 0?void 0:selectedTypeaheadCommand(e)};this.#se=r=>{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.#I=moveTypeaheadSelection(e,-1),this.#rn();break}let t=movePromptLine(a,`up`);t===void 0?recall(this.#P.previous(a.text)):apply(t);break}case`down`:case`ctrl-n`:{let e=suggestions();if(e!==void 0){this.#I=moveTypeaheadSelection(e,1),this.#rn();break}let t=movePromptLine(a,`down`);t===void 0?recall(this.#P.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.#I=dismissTypeahead(e),this.#rn());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.#I=void 0,this.#P.add(i),this.#F=!1,this.#jt(),this.#G=STATUS.processing,isPromptControlCommand(i)?this.#It({kind:`command`,body:stripTerminalControls(i.trim()),live:!1}):(this.#Pt(),this.#Lt(i),this.#De=i,this.#B.arm()),this.#We(EMPTY_LINE),this.#rn(),this.#Ct(),e(i);break}case`ctrl-d`:a.text.length===0?(this.#ht(),interrupt()):apply(deleteForward(a));break;case`ctrl-l`:this.#on();break;case`ctrl-r`:this.#rn();break;case`ctrl-c`:a.text.length===0?(this.#ht(),interrupt()):apply(EMPTY_LINE);break;default:break}},this.#St()})}#We(e){this.#M=e.text,this.#N=e.cursor}takeQueuedPrompt(){let e=this.#Ne.view().steering,t=this.#Ne.takePrompt();return t!==void 0&&(this.#Le=e?`steer`:`queue`),t}async renderStream(e,t){this.#yt(t),this.#g.clear(),this.#F=!1,this.#U.kind!==`waiting`&&(this.#U={kind:`waiting`,startedAtMs:Date.now()}),this.#G=this.#k>0?STATUS.connectionAuth:STATUS.processing,this.#zt(t?.submittedPrompt),t?.submittedPrompt!==void 0&&this.#d?.recordPrompt(),t?.submittedPrompt!==void 0&&!this.#B.armed&&this.#B.arm(),this.#Z=!1,this.#Fe=!1,this.#Re=!1,this.#ze=t?.submittedPrompt,this.#Ne.beginTurn(),this.#Pe=e.cancel,this.#he=void 0,this.#ge=void 0,this.#ve=void 0,this.#ye=void 0,this.#be=Date.now();let n={tools:t?.tools??this.#a,reasoning:t?.reasoning??this.#o,assistantResponseStats:t?.assistantResponseStats??this.#l};this.#Nt(),this.#H=!0,this.#rn();let r=new Promise(e=>{this.#fe=e});this.#se=e=>this.#kt(e),this.#St();let i={text:new Map,reasoning:new Map,tools:new Map};try{for await(let t of takeUntil(iterateTUIStream(e.events),r)){if(this.#Z)break;this.#Gt(t,n,i)}}catch(e){let t=summarizeKnownError(e);t===null?this.#Bt(`Error`,toErrorMessage(e),{detail:inspectError(e)}):this.#Bt(t.name,t.message,{detail:inspectError(e),hint:t.hint})}finally{this.#fe=void 0,this.#Z&&e.abort?.(),this.#Pe=void 0,this.#Ct(),this.#Ft(),this.#H=!1,this.#U.kind===`waiting`&&(this.#U={kind:`idle`}),this.#G=completedTurnStatus({interrupted:this.#Z,cancelled:this.#Fe,continueSession:t?.continueSession===!0}),this.#Qt(i),(this.#Z||this.#Fe)&&this.#Zt(),this.#Wt(),this.#d?.reportStats(),this.#rn(),t?.continueSession||this.#xt()}}async readToolApproval(e,t){return this.#yt(t),this.#Ft(),this.#F=!1,this.#U={kind:`idle`},this.#G=`Approve ${formatToolApprovalTitle(e)}? (y/n)`,this.#Z=!1,this.#rn(),await new Promise((t,n)=>{this.#W=n,this.#se=r=>{switch(r.type){case`text`:{if(r.framing!==`unframed`)break;let n=r.value.toLowerCase();n===`y`?(this.#Pt(),this.#G=STATUS.processing,this.#Ct(),this.#rn(),t({approved:!0})):n===`n`&&(this.#Pt(),this.#G=STATUS.processing,this.#Ke(e.toolCallId),this.#Ct(),this.#rn(),t({approved:!1,reason:`Denied by user.`}));break}case`ctrl-r`:this.#rn();break;case`ctrl-c`:this.#Z=!0,this.#xt(),n(interruptedError());break;default:break}},this.#St()})}async readInputQuestion(e,t){this.#yt(t),this.#Ft(),this.#F=!1,this.#L=!1,this.#U={kind:`idle`},this.#Z=!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.#ee},this.#i,t),renderTextSection=()=>{this.#Ht({id:o,kind:`question`,title:stripTerminalControls(e.prompt),body:formatQuestionContent(e,void 0,this.#i),preformatted:!0,live:!0})},syncFreeformCaret=()=>{isOnFreeformRow()?this.#At():(this.#jt(),this.#Mt())};s===`overlay`?(s=`overlay`,this.#F=!1,this.#Ut(o),this.#Oe=overlayPanel,this.#G=``,syncFreeformCaret(),this.#rn()):(s=`text`,this.#Oe=void 0,renderTextSection(),this.#F=!0,this.#We(l),this.#G=``,this.#At(),this.#rn());let finalize=t=>{this.#Oe=void 0,this.#Ht({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.#F=!1,this.#Pt(),this.#G=STATUS.processing,this.#jt(),this.#Ct(),this.#rn();let n={};return t.optionId!==void 0&&(n.optionId=t.optionId),t.text!==void 0&&(n.text=t.text),n},dismiss=()=>{this.#Oe=void 0,this.#Ht({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.#F=!1,this.#G=``,this.#jt(),this.#Ct(),this.#rn(),u(void 0)},moveCursor=e=>{a!==0&&(c=(c+e+a)%a,syncFreeformCaret(),this.#rn())},selectOptionAt=e=>{let t=n[e];t&&u(finalize({optionId:t.id,label:t.label}))},u;return await new Promise((t,r)=>{this.#W=r,u=t,this.#se=t=>{if(t.type===`ctrl-c`){if((s===`text`||isOnFreeformRow())&&l.text.length>0){l=EMPTY_LINE,this.#Mt(),s===`text`&&this.#We(l),this.#rn();return}this.#Z=!0,this.#Oe=void 0,this.#jt(),this.#xt(),r(interruptedError());return}if(t.type===`ctrl-r`){this.#rn();return}if(s===`overlay`){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.#Mt(),this.#rn();break}dismiss();break;default:if(isOnFreeformRow()){let e=applyLineEditorKey(l,t);e!==void 0&&(l=e,this.#Mt(),this.#rn());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.#rn())}break}return}let a=applyLineEditorKey(l,t,{multiline:!0});if(a!==void 0){l=a,this.#Mt(),this.#We(l),this.#rn();return}switch(t.type){case`up`:case`down`:{let e=movePromptLine(l,t.type);e!==void 0&&(l=e,this.#Mt(),this.#We(l),this.#rn());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.#Mt(),this.#We(l),this.#rn();break}dismiss();break;default:break}},this.#St()})}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.#Vt(e.callId,e.subagentName),this.#s===`collapsed`){this.#rn();return}this.#Ht({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.#rn()}}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.#Vt(e.callId,e.subagentName),this.#s===`collapsed`){this.#rn();return}let t=subagentToolStatus(e.status),n=e.status===`preparing`?presentPreparingTool(e.toolName):presentTool(e.toolName,e.input,this.#Yt({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.#Ht(r),this.#Ge(e.callId),this.#rn()}#Ge(e){applyCohortLiveness(this.#m.filter(t=>t.kind===`subagent-tool`&&t.subagentCallId===e).map(e=>({block:e,active:isActiveToolStatus(e.status)})))}removeSubagentTool(e){this.#Ut(subagentToolSectionId(e.callId,e.childCallId)),this.#rn()}subagents={begin:e=>this.beginSubagent(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.#Vt(e.callId,e.name);let t=this.#h.get(subagentHeaderId(e.callId));t?.status===`done`&&delete t.status,this.#rn()}completeSubagent(e){let t=this.#h.get(subagentHeaderId(e.callId));t!==void 0&&(t.status=`done`,this.#rn())}markChildToolCallId(e){this.#v.add(e);let t=this.#y.get(e);t!==void 0&&(this.#Ut(t),this.#y.delete(e),this.#rn())}#Ke(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.#Ht({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.#rn()}setConnectionAuthPendingCount(e){let t=Math.max(0,e);if(t===this.#k)return;let n=this.#k>0;this.#k=t,t>0?(this.#G=STATUS.connectionAuth,this.#rn()):n&&(this.#G=STATUS.processing,this.#rn())}setVercelStatus(e){this.#A=e,this.#rn()}setRemoteConnectionStatus(e){this.#j=e,this.#rn()}reset(){this.#m=[],this.#h.clear(),this.#g.clear(),this.#O=void 0,this.#D.length=0,this.#_.length=0,this.#T=!1,this.#E=void 0,this.#qe(),this.#z=!1,this.#De=void 0,this.#Te=void 0,this.#k=0,this.#he=void 0,this.#ge=void 0,this.#ve=void 0,this.#ye=void 0,this.#be=void 0,this.#J&&(this.#n.clearAll(),this.#rn())}renderSessionBoundary(){this.#Rt(),this.#qe();let e=this.#i.colors,t=this.#i.glyph,n=e.dim(`${t.cornerOpen}${t.dash.repeat(2)} Session restarted, clear context.`);this.#It({kind:`session-boundary`,body:n,live:!1}),this.#rn()}#qe(){this.#v.clear(),this.#y.clear(),this.#C.clear(),this.#x.clear(),this.#je=void 0,this.#Me=void 0,this.#Ne.reset(),this.#Le=void 0,this.#S.clear(),this.#B.reset()}renderNotice(e){let t=stripTerminalControls(e);t.trim().length!==0&&(this.#yt(),this.#It({kind:`notice`,body:t,live:!1}),this.#rn())}renderSandboxLog(e){let t=parseSandboxLogLine(stripTerminalControls(e));t!==void 0&&(this.#d?.append({source:`sandbox`,detail:t}),this.#yt(),this.#It({kind:`sandbox`,body:t,live:!1}),this.#rn())}renderSetupWarning(e){let t=stripTerminalControls(e);if(t.trim().length===0){this.#Je();return}this.#yt(),this.#Ae=t,this.#rn()}clearSetupWarning(){this.#Je()}#Je(){this.#Ae!==void 0&&(this.#Ae=void 0,this.#rn())}renderCommandInvocation(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;this.#yt();let r={kind:`command`,body:n,live:!1};t===`failed`&&(r.status=`error`),this.#It(r),this.#rn()}renderCommandResult(e,t){let n=stripTerminalControls(e);n.trim().length!==0&&(this.#yt(),this.#It(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.#rn())}#Ye(e,t=`spinner`){this.#yt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``;let n=t===`pulse`?{kind:`pulse`,startedAtMs:Date.now()}:{kind:`spinner`};this.#ke={title:stripTerminalControls(e),indicator:n,lines:[],outputBuffer:[]},this.#Nt(),this.#rn()}#Xe(e){this.#Be=void 0,this.#ut();let t=this.#ke;if(t!==void 0){if(this.#ke=void 0,this.#Ft(),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.#It({kind:`flow`,title:`info`,body:e.join(`
5
5
  `),live:!1}),this.#It({kind:`flow`,title:n.tone,body:n.text,live:!1})),e=[]}}this.#rn()}}async#Ze(e){let t=this.#it(),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.#rn()},loadSearch=async(e,t)=>{c=!0,s=void 0;let a=++l;this.#rn();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.#rn())}},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.#un()),t};return t.question=e=>renderSelectQuestion(panelState(),this.#i,e),this.#rn(),await this.#st((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.#rn();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.#rn();return;case`update`:o=d.select,s=void 0,this.#rn();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.#rn();return;case`ignore`:return}}).promise}#Qe(e){this.#yt();let t=this.#at();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.#rn();let r=this.#st((t,r)=>{let i=setupSelectionIntent(t);switch(i?.kind){case`cancel`:r(void 0);return;case`move`:n=moveActionCursor(n,i.direction,e.actions.length),this.#rn();return;case`repaint`:this.#rn();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#$e(e){let t=this.#it(),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.#ee,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.#At():(i=lineOf(``),this.#jt())};return syncEditableRow(),this.#rn(),await this.#st((t,n)=>{let applyEditor=e=>{i=e,a=void 0,this.#Mt(),this.#rn()},applySelect=t=>{r=reduceSelect(r,t,{options:e.options}),a=void 0,syncEditableRow(),this.#rn()},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.#rn();return}n(o===e.editable.defaultValue?{kind:`selected`,value:t}:{kind:`edited`,value:t,text:o})},o=setupSelectionIntent(t);switch(o?.kind){case`cancel`:n(void 0);return;case`move`:applySelect({type:o.direction});return;case`submit`:submit();return;case`repaint`:this.#rn();return;case void 0:break}if(!onEditableRow())return;let s=applyLineEditorKey(i,t);s!==void 0&&applyEditor(s)},()=>this.#jt()).promise}async#et(e){let t=this.#it(),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:`own-key`,caretVisible:this.#ee,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.#At():this.#jt()};return syncCaret(),this.#rn(),await this.#st((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.#rn();return;case`cancel`:i(void 0);return;case`render`:n=o.state,syncCaret(),this.#rn();return;case`validate`:{n=o.state,syncCaret(),this.#rn();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);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.#rn();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.#Mt(),dispatch({type:`edit`,editor:s}))},()=>{r?.abort(),r=void 0,this.#jt()}).promise}async#tt(e){let t=this.#it(),n=initialModelEditorState(e);return t.question=t=>renderModelEditorQuestion({request:e,state:n},this.#i,t),this.#rn(),await this.#st((t,r)=>{let dispatch=t=>{let i=transitionModelEditor(n,t,e);switch(i.kind){case`ignore`:return;case`render`:n=i.state,this.#rn();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.#rn();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#nt(e){let t=this.#it(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder!==void 0&&(i.placeholder=e.placeholder),e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#i,t,this.#ee)},this.#At(),this.#rn(),await this.#st((t,i)=>{let apply=e=>{n=e,r=void 0,this.#Mt(),this.#rn()},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.#rn();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#rn();return}i(t);return}default:return}},()=>this.#jt()).promise}async#rt(e){let t=this.#it();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#i,t),this.#rn(),await this.#st((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#rn();return;default:return}}).promise}#it(){return this.#yt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``,this.#at()}#at(){return this.#ke===void 0&&(this.#ke={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#ke}#ot(){this.#ke?.implicit===!0?this.#ke=void 0:this.#ke!==void 0&&(this.#ke.question=void 0,this.#ke.hideLinesWhileQuestion=!1),this.#se=void 0,this.#Ct(),this.#ke!==void 0&&this.#lt(),this.#rn()}#st(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#ot(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#ot(),i(e))};return this.#Ot(),this.#se=t=>{t.type===`ctrl-c`&&this.#ht(),e(t,settle,reject)},this.#St(),{promise:a,settle}}#ct(e){let t,n=new Promise(e=>{t=e});return this.#Be=t,this.#lt(e?.interruptible??!0),{promise:n,dispose:()=>{this.#Be===t&&(this.#Be=void 0,this.#ut())}}}#lt(e=!0){if(this.#Be===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#ht();let e=this.#Be;this.#Be=void 0,this.#ut(),e?.();return}t.type===`ctrl-r`&&this.#rn()};this.#Ve=consumer,this.#Ot(),this.#se=consumer,this.#St()}#ut(){this.#Ve!==void 0&&(this.#se===this.#Ve&&this.#Ct(),this.#Ve=void 0)}#dt(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.#ke!==void 0){this.#ke.status=t,t===void 0&&(this.#ke.preview=void 0),this.#rn();return}if(!(this.#F||this.#H)){if(t===void 0){this.#U={kind:`idle`},this.#K=void 0,this.#Ft(),this.#rn();return}this.#yt(),this.#Pt(),this.#K=t.text,this.#rn()}}#ft(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#ke;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.#rn();return}this.#yt(),this.#It({kind:`flow`,title:t,body:n,live:!1}),this.#rn()}#pt(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#ke;if(n===void 0){this.#ft(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#rn()}async#mt(e){this.#ce=``,this.#Ot(),this.#Be=void 0,this.#ut(),this.#Ct(),this.#Ft(),this.#n.clear(),this.#n.showCursor(),this.#Tn(),this.#e.isTTY&&this.#e.setRawMode?.(!1),this.#e.pause();try{return await e()}finally{this.#e.isTTY&&this.#e.setRawMode?.(!0),this.#e.resume(),this.#ce=``,this.#Ot(),this.#n.hideCursor(),this.#wn(),this.#ke!==void 0&&(this.#Nt(),this.#lt()),this.#n.reset(),this.#rn()}}setSessionId(e){this.#Ie=e}shutdown(){if(this.#xt(),this.#Y&&!this.#X){this.#X=!0;let e=this.#Ie===void 0?``:` ${this.#i.glyph.dot} session ${this.#Ie}`;this.#t.write(`${this.#i.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}requestInterrupt(){this.#Z=!0,this.#ke!==void 0&&this.#se?.({type:`ctrl-c`}),this.#fe?.(),this.#xt()}exitRequested(){return this.#Q}#ht(){this.#Q=!0,this.#$?.()}async#gt(e){if(this.#He!==void 0||!this.#J)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#Sn(),height:this.#Cn()}),paint:e=>this.#r.paint(e,this.#Cn()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e)),terminalBackground:this.#Ue});this.#He=t,this.#r.enter(),this.#i.color&&this.#r.writeRaw(BACKGROUND_COLOR_QUERY),await new Promise(e=>{this.#vt=e,this.#se=e=>{t.handleKey(e)===`close`&&this.#_t()},this.#St(),t.start()})}#_t(){let e=this.#He;if(e===void 0)return;this.#He=void 0,e.dispose(),this.#Ct(),this.#r.exit(),this.#n.hideCursor(),this.#rn(),this.#n.showCursor();let t=this.#vt;this.#vt=void 0,t?.()}#vt;#yt(e){this.#q=e?.title??this.#q,e?.contextSize!==void 0&&(this.#_e=e.contextSize),!this.#J&&(this.#J=!0,this.#Y=!0,this.#n.reset(),this.#n.hideCursor(),this.#wn(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#de=()=>this.#rn(),this.#t.on(`resize`,this.#de),process.on(`exit`,this.#bt))}#bt=()=>{this.#J&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#xt(){this.#_t();let e=this.#W;if(this.#W=void 0,e?.(interruptedError()),this.#Ct(),this.#jt(),this.#Ft(),this.#ae!==void 0&&(clearTimeout(this.#ae),this.#ae=void 0),this.#oe=!1,this.#J){this.#Nn();for(let e of this.#m)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#rn(),this.#n.clear(),this.#n.showCursor(),this.#Tn(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#de&&=(this.#t.off(`resize`,this.#de),void 0),process.off(`exit`,this.#bt),this.#J=!1}}#St(){this.#e.off(`data`,this.#wt),this.#e.on(`data`,this.#wt),this.#ce.length>0&&queueMicrotask(()=>{this.#se!==void 0&&this.#ce.length>0&&(this.#Et(),this.#Tt())})}#Ct(){this.#e.off(`data`,this.#wt),this.#Ot(),this.#se=void 0}#wt=e=>{this.#Ot(),this.#ce+=this.#le.write(e),this.#Et(),this.#Tt()};#Tt(){if(this.#ce===`\x1B`){this.#ue=setTimeout(()=>{this.#ce===`\x1B`&&(this.#ce=``,this.#se?.({type:`escape`}))},30),this.#ue.unref?.();return}if(isIncompletePaste(this.#ce)){let e=this.#ce;this.#ue=setTimeout(()=>{if(this.#ce!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#ce=``,t.length>0&&this.#se?.({type:`text`,value:t,framing:`bracketed-paste`})},incompletePasteFlushMs),this.#ue.unref?.();return}if(isIncompleteOsc(this.#ce)){let e=this.#ce;this.#ue=setTimeout(()=>{this.#ce===e&&(this.#ce=``)},incompletePasteFlushMs),this.#ue.unref?.()}}#Et(){for(;this.#ce.length>0;){let e=nextKey(this.#ce);if(e.incomplete)return;if(this.#ce=this.#ce.slice(e.consumed),!(e.key===void 0||e.key.type===`ignore`)){if(e.key.type===`osc`){this.#Dt(e.key.value);continue}this.#se?.(e.key)}}}#Dt(e){let t=parseBackgroundColorReply(e);t!==void 0&&(this.#Ue=t,this.#He?.setTerminalBackground(t))}#Ot(){this.#ue&&=(clearTimeout(this.#ue),void 0)}#kt(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#rn();break;case`ctrl-c`:this.#Z||(this.#Z=!0,this.#U={kind:`idle`},this.#G=`Interrupted`,this.#fe?.(),this.#rn());break;case`enter`:{let e=this.#V.text;if(e.trim().length===0)break;this.#Ne.enqueue(e)&&(this.#V=EMPTY_LINE),this.#rn();break}case`escape`:{if(this.#Ne.idle&&this.#Pe===void 0)break;let e=this.#Ne.handleEscape();(e===`steer`||e===`cancel`)&&(this.#Re=!0,this.#Pe?.()),this.#rn();break}default:{this.#Ne.disarm();let t=applyLineEditorKey(this.#V,e,{multiline:!0});t!==void 0&&(this.#V=t,this.#rn());break}}}#At(){this.#jt(),this.#Mt(),this.#re=setInterval(()=>{this.#ee=!this.#ee,this.#rn()},500),this.#re.unref?.()}#jt(){this.#re&&=(clearInterval(this.#re),void 0),this.#ee=!0}#Mt(){this.#ee=!0}#Nt(){this.#Ft(),this.#ie=setInterval(()=>{this.#te+=1,this.#rn()},90),this.#ie.unref?.()}#Pt(){let e=Date.now();this.#ne=e,this.#U={kind:`waiting`,startedAtMs:e},this.#Nt()}#Ft(){this.#ie&&=(clearInterval(this.#ie),void 0)}#It(e){e.id!==this.#Te?.id&&this.#Nn(),e.updateSeq=++this.#b,this.#m.push(e),e.id&&this.#h.set(e.id,e)}#Lt(e){this.#z=!0,this.#It({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#rn()}#Rt(){let e=this.#B.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#hn(e.elapsedMs)}`,n=this.#ge??0;if(this.#_e!==void 0&&this.#_e>0&&n>0){let e=Math.round(n/this.#_e*100);t+=` ${this.#i.glyph.dot} ${e}% context`}this.#It({kind:`turn-stats`,body:t,live:!1})}#zt(e){if(e==null)return;let t=this.#Le;if(this.#Le=void 0,this.#De===e){this.#De=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#It(n)}#Bt(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.#It(c),this.#rn()}#Vt(e,t){if(this.#C.has(e))return;this.#C.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.#It(i)}#Ht(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.#It(e)}#Ut(e){this.#m=this.#m.filter(t=>t.id!==e),this.#h.delete(e)}#Wt(){for(let e of this.#m)e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#Gt(e,t,n){switch(e.type){case`step-finish`:this.#d?.recordStepUsage(e.usage),e.usage!==void 0&&this.#B.addUsage(e.usage),this.#Qt(n),this.#nn(e.usage),this.#rn();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#Kt(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.#Kt(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.#qt(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.#qt(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#Jt({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.#Jt({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.#Jt({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#tn(e.toolCallId,n);if(r===void 0)break;this.#Jt({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#tn(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.#Jt({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#tn(e.toolCallId,n);if(r===void 0)break;this.#Jt({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#Bt(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:this.#Fe=!0,!this.#Re&&this.#ze!==void 0&&this.#V.text.length===0&&(this.#V=lineOf(this.#ze),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#nn(e.usage),this.#rn();break}}#Kt(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Ht({id:e,kind:`assistant`,body:r,live:n}),this.#rn())}#qt(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Ht({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#rn())}#Jt(e,t,n){if(n.tools.set(e.toolCallId,e),this.#v.has(e.toolCallId)||this.#$t(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#y.set(e.toolCallId,r);let i=this.#Yt(e);this.#Ht(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#en(n),this.#rn()}#Yt(e){e.output!==void 0&&this.#S.observeRead(e.output);let t={};this.#Xt(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.#S.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}#Xt(e){let t=this.#w?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#Zt(){for(let e of this.#m)e.kind!==`tool`&&e.kind!==`subagent-tool`||e.status===`running`&&(e.status=`error`,e.result=`interrupted`,e.live=!1)}#Qt(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.#Ut(r),this.#y.delete(t)}}#$t(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.#Me!==e&&(this.#Me=e,this.#It({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#Sn(),this.#i).join(`
6
+ `,` `))e>=` `&&e!==``&&dispatch({type:`char`,char:e})}).promise}async#nt(e){let t=this.#it(),n=lineOf(``),r;return t.question=t=>{let i={message:e.message,editor:n,mask:e.mask===!0};return e.placeholder!==void 0&&(i.placeholder=e.placeholder),e.notices!==void 0&&(i.notices=e.notices),r!==void 0&&(i.error=r),renderTextQuestion(i,this.#i,t,this.#ee)},this.#At(),this.#rn(),await this.#st((t,i)=>{let apply=e=>{n=e,r=void 0,this.#Mt(),this.#rn()},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.#rn();return;case`enter`:{let t=n.text.length>0?n.text:e.defaultValue??``,a=e.validate?.(t);if(a!==void 0){r=a,this.#rn();return}i(t);return}default:return}},()=>this.#jt()).promise}async#rt(e){let t=this.#it();return t.question=t=>renderAcknowledgeQuestion({message:e.message,lines:e.lines},this.#i,t),this.#rn(),await this.#st((e,t)=>{switch(e.type){case`enter`:case`escape`:case`ctrl-c`:t();return;case`ctrl-r`:this.#rn();return;default:return}}).promise}#it(){return this.#yt(),this.#F=!1,this.#U={kind:`idle`},this.#G=``,this.#at()}#at(){return this.#ke===void 0&&(this.#ke={title:``,indicator:{kind:`spinner`},lines:[],outputBuffer:[],implicit:!0}),this.#ke}#ot(){this.#ke?.implicit===!0?this.#ke=void 0:this.#ke!==void 0&&(this.#ke.question=void 0,this.#ke.hideLinesWhileQuestion=!1),this.#se=void 0,this.#Ct(),this.#ke!==void 0&&this.#lt(),this.#rn()}#st(e,t){let n=!1,r,i,a=new Promise((e,t)=>{r=e,i=t}),settle=e=>{n||(n=!0,t?.(),this.#ot(),r(e))},reject=e=>{n||(n=!0,t?.(),this.#ot(),i(e))};return this.#Ot(),this.#se=t=>{t.type===`ctrl-c`&&this.#ht(),e(t,settle,reject)},this.#St(),{promise:a,settle}}#ct(e){let t,n=new Promise(e=>{t=e});return this.#Be=t,this.#lt(e?.interruptible??!0),{promise:n,dispose:()=>{this.#Be===t&&(this.#Be=void 0,this.#ut())}}}#lt(e=!0){if(this.#Be===void 0)return;let consumer=t=>{if(e&&(t.type===`ctrl-c`||t.type===`escape`)){t.type===`ctrl-c`&&this.#ht();let e=this.#Be;this.#Be=void 0,this.#ut(),e?.();return}t.type===`ctrl-r`&&this.#rn()};this.#Ve=consumer,this.#Ot(),this.#se=consumer,this.#St()}#ut(){this.#Ve!==void 0&&(this.#se===this.#Ve&&this.#Ct(),this.#Ve=void 0)}#dt(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.#ke!==void 0){this.#ke.status=t,t===void 0&&(this.#ke.preview=void 0),this.#rn();return}if(!(this.#F||this.#H)){if(t===void 0){this.#U={kind:`idle`},this.#K=void 0,this.#Ft(),this.#rn();return}this.#yt(),this.#Pt(),this.#K=t.text,this.#rn()}}#ft(e,t){let n=stripTerminalControls(e);if(n.trim().length===0)return;let r=this.#ke;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.#rn();return}this.#yt(),this.#It({kind:`flow`,title:t,body:n,live:!1}),this.#rn()}#pt(e){let t=stripTerminalControls(e);if(t.trim().length===0)return;let n=this.#ke;if(n===void 0){this.#ft(t,`info`);return}n.preview=t,n.outputBuffer.push(t),n.outputBuffer.length>40&&n.outputBuffer.shift(),this.#rn()}async#mt(e){this.#ce=``,this.#Ot(),this.#Be=void 0,this.#ut(),this.#Ct(),this.#Ft(),this.#n.clear(),this.#n.showCursor(),this.#Tn(),this.#e.isTTY&&this.#e.setRawMode?.(!1),this.#e.pause();try{return await e()}finally{this.#e.isTTY&&this.#e.setRawMode?.(!0),this.#e.resume(),this.#ce=``,this.#Ot(),this.#n.hideCursor(),this.#wn(),this.#ke!==void 0&&(this.#Nt(),this.#lt()),this.#n.reset(),this.#rn()}}setSessionId(e){this.#Ie=e}shutdown(){if(this.#xt(),this.#Y&&!this.#X){this.#X=!0;let e=this.#Ie===void 0?``:` ${this.#i.glyph.dot} session ${this.#Ie}`;this.#t.write(`${this.#i.colors.dim(`${eveVersionTag()}${e}`)}\n`)}}requestInterrupt(){this.#Z=!0,this.#ke!==void 0&&this.#se?.({type:`ctrl-c`}),this.#fe?.(),this.#xt()}exitRequested(){return this.#Q}#ht(){this.#Q=!0,this.#$?.()}async#gt(e){if(this.#He!==void 0||!this.#J)return;let t=new TraceViewerSession({...e,theme:this.#i,dimensions:()=>({width:this.#Sn(),height:this.#Cn()}),paint:e=>this.#r.paint(e,this.#Cn()),tracingDisabled:process.env.EVE_TRACES===`off`,copyText:e=>copyTextToClipboard(e,e=>this.#r.writeRaw(e)),terminalBackground:this.#Ue});this.#He=t,this.#r.enter(),this.#i.color&&this.#r.writeRaw(BACKGROUND_COLOR_QUERY),await new Promise(e=>{this.#vt=e,this.#se=e=>{t.handleKey(e)===`close`&&this.#_t()},this.#St(),t.start()})}#_t(){let e=this.#He;if(e===void 0)return;this.#He=void 0,e.dispose(),this.#Ct(),this.#r.exit(),this.#n.hideCursor(),this.#rn(),this.#n.showCursor();let t=this.#vt;this.#vt=void 0,t?.()}#vt;#yt(e){this.#q=e?.title??this.#q,e?.contextSize!==void 0&&(this.#_e=e.contextSize),!this.#J&&(this.#J=!0,this.#Y=!0,this.#n.reset(),this.#n.hideCursor(),this.#wn(),this.#e.isTTY&&(this.#e.setRawMode?.(!0),this.#e.resume(),this.#n.emitBracketedPaste(!0)),this.#de=()=>this.#rn(),this.#t.on(`resize`,this.#de),process.on(`exit`,this.#bt))}#bt=()=>{this.#J&&(this.#r.exit(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1)),this.#n.showCursor())};#xt(){this.#_t();let e=this.#W;if(this.#W=void 0,e?.(interruptedError()),this.#Ct(),this.#jt(),this.#Ft(),this.#ae!==void 0&&(clearTimeout(this.#ae),this.#ae=void 0),this.#oe=!1,this.#J){this.#Nn();for(let e of this.#m)e.kind===`log`&&e.id===void 0&&(e.live=!1);this.#rn(),this.#n.clear(),this.#n.showCursor(),this.#Tn(),this.#n.newline(),this.#e.isTTY&&(this.#n.emitBracketedPaste(!1),this.#e.setRawMode?.(!1),this.#e.pause()),this.#de&&=(this.#t.off(`resize`,this.#de),void 0),process.off(`exit`,this.#bt),this.#J=!1}}#St(){this.#e.off(`data`,this.#wt),this.#e.on(`data`,this.#wt),this.#ce.length>0&&queueMicrotask(()=>{this.#se!==void 0&&this.#ce.length>0&&(this.#Et(),this.#Tt())})}#Ct(){this.#e.off(`data`,this.#wt),this.#Ot(),this.#se=void 0}#wt=e=>{this.#Ot(),this.#ce+=this.#le.write(e),this.#Et(),this.#Tt()};#Tt(){if(this.#ce===`\x1B`){this.#ue=setTimeout(()=>{this.#ce===`\x1B`&&(this.#ce=``,this.#se?.({type:`escape`}))},30),this.#ue.unref?.();return}if(isIncompletePaste(this.#ce)){let e=this.#ce;this.#ue=setTimeout(()=>{if(this.#ce!==e)return;let t=sanitizePastedText(stripPasteStart(e));this.#ce=``,t.length>0&&this.#se?.({type:`text`,value:t,framing:`bracketed-paste`})},incompletePasteFlushMs),this.#ue.unref?.();return}if(isIncompleteOsc(this.#ce)){let e=this.#ce;this.#ue=setTimeout(()=>{this.#ce===e&&(this.#ce=``)},incompletePasteFlushMs),this.#ue.unref?.()}}#Et(){for(;this.#ce.length>0;){let e=nextKey(this.#ce);if(e.incomplete)return;if(this.#ce=this.#ce.slice(e.consumed),!(e.key===void 0||e.key.type===`ignore`)){if(e.key.type===`osc`){this.#Dt(e.key.value);continue}this.#se?.(e.key)}}}#Dt(e){let t=parseBackgroundColorReply(e);t!==void 0&&(this.#Ue=t,this.#He?.setTerminalBackground(t))}#Ot(){this.#ue&&=(clearTimeout(this.#ue),void 0)}#kt(e){switch(e.type){case`ctrl-l`:case`ctrl-r`:this.#rn();break;case`ctrl-c`:this.#Z||(this.#Z=!0,this.#U={kind:`idle`},this.#G=`Interrupted`,this.#fe?.(),this.#rn());break;case`enter`:{let e=this.#V.text;if(e.trim().length===0)break;if(parsePromptCommand(e)?.type===`cancel`&&this.#Pe!==void 0){this.#V=EMPTY_LINE,this.#Ne.requestCancellation(),this.#Re=!0,this.renderCommandInvocation(e.trim()),this.renderCommandResult(`Turn cancellation requested.`),this.#Pe(),this.#rn();break}this.#Ne.enqueue(e)&&(this.#V=EMPTY_LINE),this.#rn();break}case`escape`:if(this.#Ne.idle&&this.#Pe===void 0)break;this.#Ne.handleEscape(),this.#Re=!0,this.#Pe?.(),this.#rn();break;default:{let t=applyLineEditorKey(this.#V,e,{multiline:!0});t!==void 0&&(this.#V=t,this.#rn());break}}}#At(){this.#jt(),this.#Mt(),this.#re=setInterval(()=>{this.#ee=!this.#ee,this.#rn()},500),this.#re.unref?.()}#jt(){this.#re&&=(clearInterval(this.#re),void 0),this.#ee=!0}#Mt(){this.#ee=!0}#Nt(){this.#Ft(),this.#ie=setInterval(()=>{this.#te+=1,this.#rn()},90),this.#ie.unref?.()}#Pt(){let e=Date.now();this.#ne=e,this.#U={kind:`waiting`,startedAtMs:e},this.#Nt()}#Ft(){this.#ie&&=(clearInterval(this.#ie),void 0)}#It(e){e.id!==this.#Te?.id&&this.#Nn(),e.updateSeq=++this.#b,this.#m.push(e),e.id&&this.#h.set(e.id,e)}#Lt(e){this.#z=!0,this.#It({kind:`user`,body:stripTerminalControls(e),live:!1}),this.#rn()}#Rt(){let e=this.#B.settle();if(e===void 0||e.elapsedMs<=1e4&&e.inputTokens<=2e4)return;let t=`Done in ${this.#hn(e.elapsedMs)}`,n=this.#ge??0;if(this.#_e!==void 0&&this.#_e>0&&n>0){let e=Math.round(n/this.#_e*100);t+=` ${this.#i.glyph.dot} ${e}% context`}this.#It({kind:`turn-stats`,body:t,live:!1})}#zt(e){if(e==null)return;let t=this.#Le;if(this.#Le=void 0,this.#De===e){this.#De=void 0;return}let n={kind:`user`,body:stripTerminalControls(e),live:!1};t!==void 0&&(n.promptOrigin=t),this.#It(n)}#Bt(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.#It(c),this.#rn()}#Vt(e,t){if(this.#C.has(e))return;this.#C.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.#It(i)}#Ht(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.#It(e)}#Ut(e){this.#m=this.#m.filter(t=>t.id!==e),this.#h.delete(e)}#Wt(){for(let e of this.#m)e.status===`approval`||e.status===`running`||e.kind===`connection-auth`&&e.live||(e.live=!1)}#Gt(e,t,n){switch(e.type){case`step-finish`:this.#d?.recordStepUsage(e.usage),e.usage!==void 0&&this.#B.addUsage(e.usage),this.#Qt(n),this.#nn(e.usage),this.#rn();break;case`assistant-delta`:{let t=(n.text.get(e.id)??``)+stripTerminalControls(e.delta);n.text.set(e.id,t),this.#Kt(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.#Kt(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.#qt(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.#qt(e.id,r,!1,t);break}break}case`tool-call-preparing`:if(t.tools===`hidden`||isPanelRoutedTool(e.toolName))break;this.#Jt({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.#Jt({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.#Jt({...r,status:`approval`},t,n);break}case`tool-result`:{if(t.tools===`hidden`)break;let r=this.#tn(e.toolCallId,n);if(r===void 0)break;this.#Jt({...r,output:e.output,status:`done`},t,n);break}case`tool-error`:{let r=this.#tn(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.#Jt({...r,errorText:e.errorText,status:`error`},t,n);break}case`tool-rejected`:{if(t.tools===`hidden`)break;let r=this.#tn(e.toolCallId,n);if(r===void 0)break;this.#Jt({...r,errorText:e.reason,status:`denied`},t,n);break}case`error`:this.#Bt(`Error`,e.errorText,{detail:e.detail,hint:e.hint});break;case`turn-cancelled`:this.#Fe=!0,!this.#Re&&this.#ze!==void 0&&this.#V.text.length===0&&(this.#V=lineOf(this.#ze),this.renderNotice(`The turn was cancelled from outside this prompt — the message was restored to the input.`));break;case`finish`:this.#nn(e.usage),this.#rn();break}}#Kt(e,t,n){let r=stripTerminalControls(t).trim();r.length!==0&&(this.#Ht({id:e,kind:`assistant`,body:r,live:n}),this.#rn())}#qt(e,t,n,r){let i=stripTerminalControls(t).trim();i.length!==0&&(this.#Ht({id:e,kind:`reasoning`,body:i,collapsed:collapseReasoning(r.reasoning,n),live:n}),this.#rn())}#Jt(e,t,n){if(n.tools.set(e.toolCallId,e),this.#v.has(e.toolCallId)||this.#$t(e)||toolBaseName(e.toolName)===`ask_question`)return;let r=toolSectionId(e.toolCallId);this.#y.set(e.toolCallId,r);let i=this.#Yt(e);this.#Ht(renderNativeToolBlock(e,r,t.tools===`full`,i)),this.#en(n),this.#rn()}#Yt(e){e.output!==void 0&&this.#S.observeRead(e.output);let t={};this.#Xt(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.#S.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}#Xt(e){let t=this.#w?.info?.subagents.local;if(t===void 0||t.length===0)return!1;let n=toolBaseName(e);return t.some(e=>e.name===n)}#Zt(){for(let e of this.#m)e.kind!==`tool`&&e.kind!==`subagent-tool`||e.status===`running`&&(e.status=`error`,e.result=`interrupted`,e.live=!1)}#Qt(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.#Ut(r),this.#y.delete(t)}}#$t(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.#Me!==e&&(this.#Me=e,this.#It({kind:`todo-list`,body:renderFinishedTodoRows(t,this.#Sn(),this.#i).join(`
7
7
  `),live:!1})),this.#je=void 0}else this.#je=t.length>0?t:void 0,this.#Me=void 0;return this.#rn(),!0}#en(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)}#tn(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`}}#nn(e){if(e===void 0)return;let{inputTokens:t,outputTokens:n}=e;if((t!=null||n!=null)&&(this.#he=(t??0)+(n??0)),this.#ge=t??this.#ge,this.#ve=n??this.#ve,this.#ve!=null&&this.#be!==void 0){let e=(Date.now()-this.#be)/1e3;e>0&&(this.#ye=this.#ve/e)}}#rn(){if(this.#J){if(this.#pe){this.#me=!0;return}this.#pe=!0;try{do this.#me=!1,this.#in();while(this.#me)}finally{this.#pe=!1}}}#in(){if(!this.#J)return;if(this.#He!==void 0){this.#He.repaint();return}let e=this.#Sn(),t=this.#pn(e),n=Math.max(1,this.#Cn()-t.length),r=[],i=this.#O,a=groupToolBlocksForDisplay(this.#m),o=0;for(;o<a.length&&a[o].display.live===!1;)o+=1;if(o>0){let e=new Set(a.slice(0,o).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 a.slice(0,o)){for(let e of t.members)this.#_.push(e),e.id&&(this.#g.add(e.id),this.#h.delete(e.id));if(this.#Fn(t.display))continue;let n=this.#ln(t.display,e,i);i=previousBlockOf(t.display),this.#O=i,r.push(...n),this.#D.push(...n)}let s=[];for(let{display:t}of a.slice(o)){if(this.#Fn(t))continue;let n=this.#ln(t,e,i);i=previousBlockOf(t);for(let e=0;e<n.length;e+=1)s.push({block:t,row:n[e]})}let c=[...clipLiveRows(s.map(e=>e.row),n,e,this.#i),...t];r.length>0?this.#n.flush(r,c):this.#n.update(c)}#an(){if(!this.#J)return;let e=this.#Sn(),t=this.#pn(e),n=Math.max(1,this.#Cn()-t.length),r=this.#O,i=[];for(let{display:t}of groupToolBlocksForDisplay(this.#m)){if(this.#Fn(t))continue;let n=this.#ln(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.#cn(),...this.#D],a)}logDisplayMode(){return this.#p}setLogDisplayMode(e){e!==this.#p&&(this.#p=e,e===`all`&&this.flushDelayedDevBuildErrors(),this.#sn(),this.#J&&this.#an())}flushDelayedDevBuildErrors(){let e=this.#we;e!==void 0&&(this.#we=void 0,this.#It({kind:`log`,title:`stderr`,body:e,live:!0}),this.#rn())}#on(){this.#oe=!0,this.#ae!==void 0&&clearTimeout(this.#ae),this.#ae=setTimeout(()=>{this.#oe=!1,this.#ae=void 0,this.#rn()},5e3),this.setLogDisplayMode(nextLogDisplayMode(this.#p)),this.#rn()}#sn(){let e=this.#Sn();this.#D.length=0;let t;for(let{display:n}of groupToolBlocksForDisplay(this.#_,{logCoalescing:`runs`})){if(this.#Fn(n))continue;let r=this.#ln(n,e,t);t=previousBlockOf(n),this.#D.push(...r)}this.#O=t}#cn(){let e=this.#w;if(e===void 0)return[];let t={name:e.name,theme:this.#i,width:this.#Sn()};return e.info!==void 0&&(t.info=e.info),e.tip!==void 0&&(t.tip=e.tip),buildAgentHeader(t)}#ln(e,t,n){let r={activityPulse:this.#dn(this.#ne,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}#un(){return this.#i.spinner[this.#te%this.#i.spinner.length]??``}#dn(e,t){return isProgressPulseVisible(Date.now()-e)?t:` `}#fn(e,t){return e.indicator.kind===`spinner`?{glyph:this.#un(),color:`yellow`}:{glyph:this.#dn(e.indicator.startedAtMs,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),color:t?.kind===`external-action`?`yellow`:`green`}}#pn(e){let n=this.#i.colors,r=[``];if(this.#Oe!==void 0)return r.push(...this.#Oe(e),``),this.#yn(r,e),r;let a=this.#ke;if(a!==void 0){let t=this.#fn(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.hideLinesWhileQuestion===!0?[]:a.lines,content:i};return r.push(...renderFlowPanel(o,this.#i,e)),this.#bn(r,e),r}this.#Ae!==void 0&&r.push(...renderAttentionRows(this.#Ae,e,this.#i),``),this.#je!==void 0&&r.push(...renderTodoPanelRows({items:this.#je,width:e,theme:this.#i,working:this.#H||this.#U.kind===`waiting`,pulse:this.#dn(this.#ne,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH)}),``);let o=renderMessageQueueRows({view:this.#Ne.view(),width:e,theme:this.#i,working:this.#H});if(o.length>0&&r.push(...o,``),this.#F){let i=this.#I===void 0?void 0:inlineCommandHint(this.#I);i===void 0&&this.#I!==void 0&&isTypeaheadOpen(this.#I)&&r.push(...renderCommandSuggestions(this.#I,this.#i,e));let a=isPromptControlCommand(this.#M),o=i?n.dim(` ${i}`):``,s=[];this.#yn(s,e);let u=Math.max(1,this.#Cn()-1-r.length-1-s.length),f={text:this.#M,cursor:this.#N,width:e,theme:this.#i,caretVisible:this.#ee,isCommand:a,ghost:o,maxRows:u};return this.#L&&this.#M.length===0&&(f.placeholder=this.#z?``:promptPlaceholder(Date.now()-this.#R)),r.push(...promptInputRows(f)),r.push(...s),r}let s=this.#U.kind===`waiting`&&this.#K===void 0;if(this.#H||s){r.push(this.#mn(e)),this.#_n(r,e);let t=[];return this.#yn(t,e),!this.#H&&t.length>0&&r.push(``),r.push(...t),r}if(this.#V.text.length>0)return this.#vn(r,e,{inert:!1}),this.#yn(r,e),r;let u=this.#K??(this.#G.length>0?this.#G:`Ready`),f=this.#xn(),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.#yn(r,e),r}#mn(e){let t=this.#i.colors,n=this.#dn(this.#ne,this.#i.unicode?PROGRESS_PULSE_GLYPH:PROGRESS_PULSE_ASCII_GLYPH),r=this.#U,i=this.#B.startedAtMs??this.#be??(r.kind===`waiting`?r.startedAtMs:Date.now()),a=Date.now()-i,o=`${typewriterText(`Working for`,a,80)} ${this.#hn(a)}`;return clip(`${t.yellow(n)} ${t.dim(o)}`,e)}#hn(e){return`${formatTurnDuration(e)}${this.#gn()}`}#gn(){let{inputTokens:e,outputTokens:t}=this.#B.usage;return e===0&&t===0?``:` ${this.#i.glyph.dash.repeat(2)} ${formatTokenFlow({inputTokens:e,outputTokens:t},this.#i.glyph)}`}#_n(e,t){this.#H&&this.#vn(e,t,{inert:!0})}#vn(e,t,n){e.push(``);let r={text:this.#V.text,cursor:this.#V.cursor,width:t,theme:this.#i,caretVisible:!0,isCommand:!1,ghost:``,maxRows:4,inert:n.inert};n.inert&&this.#V.text.length===0&&(r.placeholder=``),e.push(...promptInputRows(r))}#yn(e,t){let n=this.#j===void 0?``:` `,r=Math.max(1,t-n.length),i={theme:this.#i,width:r};this.#oe&&(i.logLevel=this.#p);let a=this.#w?.serverUrl;if(a!==void 0&&this.#j===void 0){let e=new URL(a).port;e.length>0&&(i.serverPort=e)}let o=this.#w?.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.#A!==void 0&&(i.vercel=this.#A),this.#j!==void 0&&(i.remote=this.#j);let c=buildStatusLine(i);c!==void 0&&e.push(clip(`${n}${c}`,t))}#bn(e,t){if(this.#j===void 0)return;let n=Math.max(1,t-2),r=buildStatusLine({remote:this.#j,theme:this.#i,width:n});r!==void 0&&e.push(``,clip(` ${r}`,t))}#xn(){let e=this.#i.colors,t=[],n=formatAssistantResponseStats({totalTokens:this.#he,outputTokens:this.#ve,tokensPerSecond:this.#ye},this.#l);return n&&t.push(n),t.length>0?e.dim(t.join(` ${this.#i.glyph.dot} `)):``}#Sn(){return Math.max(20,this.#t.columns||80)}#Cn(){return Math.max(8,this.#t.rows||24)}#wn(){if(this.#xe!==void 0||!this.#u)return;this.#Se=``,this.#Ce=``;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.#Dn(t,chunkToString(e,i)),a?.(),!0}),()=>{e.write=n}},e=capture(process.stdout,`stdout`),t=capture(process.stderr,`stderr`);this.#d?.subscribeLogRecords(e=>this.#En(e)),this.#xe=()=>{this.#d?.unsubscribeLogRecords(),e(),t()}}#Tn(){let e=this.#xe;e!==void 0&&(this.#xe=void 0,e(),this.#Se.length>0&&(this.#d?.append({source:`stdout`,detail:this.#Se}),this.#Pn(`stdout`)&&process.stdout.write(`${this.#Se}\n`),this.#Se=``),this.#Ce.length>0&&(this.#d?.append({source:`stderr`,detail:this.#Ce}),this.#Pn(`stderr`)&&process.stderr.write(`${this.#Ce}\n`),this.#Ce=``))}#En(e){let t=e.fields===void 0?``:` ${JSON.stringify(e.fields)}`;this.#kn(`[eve:${e.namespace}] ${e.message}${t}`),this.#rn()}#Dn(e,t){let n=(e===`stdout`?this.#Se:this.#Ce)+t;if(e===`stdout`&&parseDevRebuildLogLine(n.trimEnd())!==void 0){this.#Se=``,this.#d?.append({source:e,detail:n.trimEnd()}),this.#On(n.trimEnd()),this.#rn();return}let r=n.lastIndexOf(`
8
8
  `),i=r===-1?n:n.slice(r+1);if(e===`stdout`?this.#Se=i:this.#Ce=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.#On(a):this.#kn(a),this.#rn())}#On(e){let t=[],flushPending=()=>{if(t.length===0)return;let e=t.join(`
9
9
  `);t=[],e.trim().length!==0&&this.#It({kind:`log`,title:`stdout`,body:e,live:!0})};for(let n of e.split(`
@@ -106,7 +106,7 @@ declare const subagent: z.ZodObject<{
106
106
  sourceId: z.ZodOptional<z.ZodString>;
107
107
  sourceKind: z.ZodString;
108
108
  name: z.ZodString;
109
- description: z.ZodString;
109
+ description: z.ZodOptional<z.ZodString>;
110
110
  entryPath: z.ZodString;
111
111
  nodeId: z.ZodString;
112
112
  rootPath: z.ZodString;
@@ -408,7 +408,7 @@ export declare const AgentInfoResultSchema: z.ZodObject<{
408
408
  sourceId: z.ZodOptional<z.ZodString>;
409
409
  sourceKind: z.ZodString;
410
410
  name: z.ZodString;
411
- description: z.ZodString;
411
+ description: z.ZodOptional<z.ZodString>;
412
412
  entryPath: z.ZodString;
413
413
  nodeId: z.ZodString;
414
414
  rootPath: z.ZodString;
@@ -1 +1 @@
1
- import{z}from"#compiled/zod/index.js";const source=z.object({exportName:z.string().optional(),logicalPath:z.string(),sourceId:z.string().optional(),sourceKind:z.string()}),entry=source.extend({name:z.string()}),modelRouting=z.discriminatedUnion(`kind`,[z.object({kind:z.literal(`gateway`),target:z.string(),byok:z.string().optional()}),z.object({kind:z.literal(`external`),provider:z.string()})]),modelEndpoint=z.union([z.object({kind:z.literal(`external`),provider:z.string()}),z.object({kind:z.literal(`gateway`),connected:z.literal(!0),credential:z.enum([`api-key`,`oidc`])}),z.object({kind:z.literal(`gateway`),connected:z.literal(!1)})]),tool=entry.extend({description:z.string(),hasAuth:z.boolean(),hasExecute:z.boolean(),hasModelOutputProjection:z.boolean(),hasOutputSchema:z.boolean(),inputSchema:z.unknown(),origin:z.enum([`authored`,`framework`]),outputSchema:z.unknown().optional(),replacesFrameworkTool:z.boolean(),requiresApproval:z.boolean()}),frameworkTool=tool.extend({disabledByAuthor:z.boolean(),replacedByAuthoredTool:z.boolean(),status:z.enum([`active`,`disabled`,`replaced`])}),dynamicResolver=source.extend({eventNames:z.array(z.string()),origin:z.enum([`authored`,`framework`]),slug:z.string()}),skill=entry.extend({description:z.string(),license:z.string().optional(),markdown:z.string(),metadata:z.record(z.string(),z.string()).optional()}),instructions=entry.extend({markdown:z.string()}),schedule=entry.extend({cron:z.string(),hasRun:z.boolean(),markdown:z.string().optional()}),subagent=entry.extend({description:z.string(),entryPath:z.string(),nodeId:z.string(),rootPath:z.string(),summary:z.object({channels:z.number(),connections:z.number(),hooks:z.number(),instructions:z.boolean(),schedules:z.number(),skills:z.number(),tools:z.number()})}),channel=entry.extend({adapterKind:z.string().optional(),method:z.string(),origin:z.enum([`authored`,`framework`]),urlPath:z.string()}),frameworkChannel=channel.extend({disabledByAuthor:z.boolean(),replacedByAuthoredChannel:z.boolean(),status:z.enum([`active`,`disabled`,`replaced`])}),connection=source.extend({connectionName:z.string(),description:z.string(),hasApproval:z.boolean(),hasAuthorization:z.boolean(),hasHeaders:z.boolean(),protocol:z.string(),toolFilter:z.unknown().optional(),url:z.string()}),hook=source.extend({eventNames:z.array(z.string()),slug:z.string()}),sandbox=source.extend({backendKind:z.string().optional(),description:z.string().optional(),hasBootstrap:z.boolean(),hasOnSession:z.boolean(),revalidationKey:z.string().optional(),sourceHash:z.string().optional()}),AgentInfoResultSchema=z.object({agent:z.object({agentRoot:z.string(),appRoot:z.string(),configSource:source.optional(),description:z.string().optional(),model:z.object({contextWindowTokens:z.number().optional(),id:z.string(),providerOptions:z.unknown().optional(),reasoning:z.enum([`provider-default`,`none`,`minimal`,`low`,`medium`,`high`,`xhigh`]).optional().catch(void 0),source:source.optional(),routing:modelRouting.optional(),endpoint:modelEndpoint.optional()}),name:z.string(),outputSchema:z.unknown().optional()}),capabilities:z.object({devRoutes:z.boolean()}),channels:z.object({authored:z.array(channel),available:z.array(channel),disabledFramework:z.array(z.string()),framework:z.array(frameworkChannel)}),connections:z.array(connection),diagnostics:z.object({discoveryErrors:z.number(),discoveryWarnings:z.number()}),hooks:z.array(hook),instructions:z.object({dynamic:z.array(dynamicResolver),static:instructions.nullable()}),kind:z.literal(`eve-agent-info`),mode:z.enum([`development`,`production`]),sandbox:sandbox.nullable(),schedules:z.array(schedule),skills:z.object({dynamic:z.array(dynamicResolver),static:z.array(skill)}),subagents:z.object({local:z.array(subagent),total:z.number()}),tools:z.object({authored:z.array(tool),available:z.array(tool),disabledFramework:z.array(z.string()),dynamic:z.array(dynamicResolver),framework:z.array(frameworkTool),reserved:z.array(z.string())}),version:z.literal(1),workflow:z.object({enabled:z.boolean(),toolName:z.string()}),workspace:z.object({resourceRoot:z.unknown(),rootEntries:z.array(z.string())})});export{AgentInfoResultSchema};
1
+ import{z}from"#compiled/zod/index.js";const source=z.object({exportName:z.string().optional(),logicalPath:z.string(),sourceId:z.string().optional(),sourceKind:z.string()}),entry=source.extend({name:z.string()}),modelRouting=z.discriminatedUnion(`kind`,[z.object({kind:z.literal(`gateway`),target:z.string(),byok:z.string().optional()}),z.object({kind:z.literal(`external`),provider:z.string()})]),modelEndpoint=z.union([z.object({kind:z.literal(`external`),provider:z.string()}),z.object({kind:z.literal(`gateway`),connected:z.literal(!0),credential:z.enum([`api-key`,`oidc`])}),z.object({kind:z.literal(`gateway`),connected:z.literal(!1)})]),tool=entry.extend({description:z.string(),hasAuth:z.boolean(),hasExecute:z.boolean(),hasModelOutputProjection:z.boolean(),hasOutputSchema:z.boolean(),inputSchema:z.unknown(),origin:z.enum([`authored`,`framework`]),outputSchema:z.unknown().optional(),replacesFrameworkTool:z.boolean(),requiresApproval:z.boolean()}),frameworkTool=tool.extend({disabledByAuthor:z.boolean(),replacedByAuthoredTool:z.boolean(),status:z.enum([`active`,`disabled`,`replaced`])}),dynamicResolver=source.extend({eventNames:z.array(z.string()),origin:z.enum([`authored`,`framework`]),slug:z.string()}),skill=entry.extend({description:z.string(),license:z.string().optional(),markdown:z.string(),metadata:z.record(z.string(),z.string()).optional()}),instructions=entry.extend({markdown:z.string()}),schedule=entry.extend({cron:z.string(),hasRun:z.boolean(),markdown:z.string().optional()}),subagent=entry.extend({description:z.string().optional(),entryPath:z.string(),nodeId:z.string(),rootPath:z.string(),summary:z.object({channels:z.number(),connections:z.number(),hooks:z.number(),instructions:z.boolean(),schedules:z.number(),skills:z.number(),tools:z.number()})}),channel=entry.extend({adapterKind:z.string().optional(),method:z.string(),origin:z.enum([`authored`,`framework`]),urlPath:z.string()}),frameworkChannel=channel.extend({disabledByAuthor:z.boolean(),replacedByAuthoredChannel:z.boolean(),status:z.enum([`active`,`disabled`,`replaced`])}),connection=source.extend({connectionName:z.string(),description:z.string(),hasApproval:z.boolean(),hasAuthorization:z.boolean(),hasHeaders:z.boolean(),protocol:z.string(),toolFilter:z.unknown().optional(),url:z.string()}),hook=source.extend({eventNames:z.array(z.string()),slug:z.string()}),sandbox=source.extend({backendKind:z.string().optional(),description:z.string().optional(),hasBootstrap:z.boolean(),hasOnSession:z.boolean(),revalidationKey:z.string().optional(),sourceHash:z.string().optional()}),AgentInfoResultSchema=z.object({agent:z.object({agentRoot:z.string(),appRoot:z.string(),configSource:source.optional(),description:z.string().optional(),model:z.object({contextWindowTokens:z.number().optional(),id:z.string(),providerOptions:z.unknown().optional(),reasoning:z.enum([`provider-default`,`none`,`minimal`,`low`,`medium`,`high`,`xhigh`]).optional().catch(void 0),source:source.optional(),routing:modelRouting.optional(),endpoint:modelEndpoint.optional()}),name:z.string(),outputSchema:z.unknown().optional()}),capabilities:z.object({devRoutes:z.boolean()}),channels:z.object({authored:z.array(channel),available:z.array(channel),disabledFramework:z.array(z.string()),framework:z.array(frameworkChannel)}),connections:z.array(connection),diagnostics:z.object({discoveryErrors:z.number(),discoveryWarnings:z.number()}),hooks:z.array(hook),instructions:z.object({dynamic:z.array(dynamicResolver),static:instructions.nullable()}),kind:z.literal(`eve-agent-info`),mode:z.enum([`development`,`production`]),sandbox:sandbox.nullable(),schedules:z.array(schedule),skills:z.object({dynamic:z.array(dynamicResolver),static:z.array(skill)}),subagents:z.object({local:z.array(subagent),total:z.number()}),tools:z.object({authored:z.array(tool),available:z.array(tool),disabledFramework:z.array(z.string()),dynamic:z.array(dynamicResolver),framework:z.array(frameworkTool),reserved:z.array(z.string())}),version:z.literal(1),workflow:z.object({enabled:z.boolean(),toolName:z.string()}),workspace:z.object({resourceRoot:z.unknown(),rootEntries:z.array(z.string())})});export{AgentInfoResultSchema};
@@ -7,7 +7,7 @@ export { createDataUrlFilePart, createTextWithFileContent } from "#client/file-p
7
7
  export { MessageResponse } from "#client/message-response.js";
8
8
  export { ClientSession } from "#client/session.js";
9
9
  export type { EveAgentStoreCallbacks, EveAgentStoreInit, EveAgentStoreSnapshot, EveAgentStoreStatus, PrepareSend, } from "#client/eve-agent-store.js";
10
- export type { AgentInfoEntry, AgentInfoChannelEntry, AgentInfoChannels, AgentInfoConnectionEntry, AgentInfoDynamicResolverEntry, AgentInfoFrameworkChannelEntry, AgentInfoFrameworkToolEntry, AgentInfoHookEntry, AgentInfoInstructions, AgentInfoInstructionsEntry, AgentInfoResult, AgentInfoSandboxEntry, AgentInfoScheduleEntry, AgentInfoSkillEntry, AgentInfoSource, AgentInfoSubagentEntry, AgentInfoToolEntry, AgentInfoTools, CancelSessionResult, ClientAuth, ClientOptions, ClientRedirectPolicy, HeadersValue, HealthResult, MessageResult, ResetResult, ResolvedStreamReconnectPolicy, SendTurnInput, SendTurnPayload, SessionSnapshot, SessionState, StreamOptions, StreamReconnectPolicy, StreamReconnectRetryPolicy, TokenValue, } from "#client/types.js";
10
+ export type { AgentInfoEntry, AgentInfoChannelEntry, AgentInfoChannels, AgentInfoConnectionEntry, AgentInfoDynamicResolverEntry, AgentInfoFrameworkChannelEntry, AgentInfoFrameworkToolEntry, AgentInfoHookEntry, AgentInfoInstructions, AgentInfoInstructionsEntry, AgentInfoResult, AgentInfoSandboxEntry, AgentInfoScheduleEntry, AgentInfoSkillEntry, AgentInfoSource, AgentInfoSubagentEntry, AgentInfoToolEntry, AgentInfoTools, CancelSessionResult, ClearResult, CompactResult, ClientAuth, ClientOptions, ClientRedirectPolicy, HeadersValue, HealthResult, MessageResult, ResetResult, ResolvedStreamReconnectPolicy, SendTurnInput, SendTurnPayload, SessionSnapshot, SessionState, StreamOptions, StreamReconnectPolicy, StreamReconnectRetryPolicy, TokenValue, } from "#client/types.js";
11
11
  export type { EveAgentReducer, EveAgentReducerEvent, ClientInputRespondedEvent, ClientMessageFailedEvent, ClientMessageSubmittedEvent, } from "#client/reducer.js";
12
12
  export type { EveAuthorizationChallenge, EveAuthorizationOutcome, EveAuthorizationPart, EveMessageData, EveDynamicToolPart, EveMessageInputRequest, EveMessage, EveMessageMetadata, EveMessagePart, EveMessageToolMetadata, } from "#client/message-reducer.js";
13
13
  export type { ActionResultStreamEvent, ActionsRequestedStreamEvent, AssistantStepFinishReason, AuthorizationOutcome, CompactionCompletedStreamEvent, CompactionRequestedStreamEvent, AuthorizationCompletedStreamEvent, ConnectionAuthorizationOutcome, AuthorizationRequiredStreamEvent, HandleMessageStreamEvent, MessageStreamEventMeta, InputRequestedStreamEvent, MessageAppendedStreamEvent, MessageCompletedStreamEvent, MessageReceivedPart, MessageReceivedStreamEvent, ReasoningAppendedStreamEvent, ReasoningCompletedStreamEvent, ResultCompletedStreamEvent, SessionCompletedStreamEvent, SessionFailedStreamEvent, SessionStartedStreamEvent, SessionWaitingStreamEvent, MessageStreamEvent, StepCompletedStreamEvent, StepFailedStreamEvent, StepStartedStreamEvent, SubagentCalledStreamEvent, SubagentChildEventStreamEvent, SubagentCompletedStreamEvent, SubagentStartedStreamEvent, TurnCancelledStreamEvent, TurnCompletedStreamEvent, TurnFailedStreamEvent, TurnStartedStreamEvent, TurnFailureStreamEvent, } from "#protocol/message.js";
@@ -1,6 +1,6 @@
1
1
  import type { MessageStreamEvent } from "#protocol/message.js";
2
2
  import { MessageResponse } from "#client/message-response.js";
3
- import type { CancelSessionResult, ClientRedirectPolicy, ResetResult, SendTurnInput, SessionSnapshot, SessionState, StreamOptions } from "#client/types.js";
3
+ import type { CancelSessionResult, ClearResult, CompactResult, ClientRedirectPolicy, ResetResult, SendTurnInput, SessionSnapshot, SessionState, StreamOptions } from "#client/types.js";
4
4
  /**
5
5
  * Internal interface that a {@link ClientSession} uses to access client-level
6
6
  * configuration without depending on the full {@link Client} class.
@@ -65,6 +65,20 @@ export declare class ClientSession {
65
65
  cancel(options?: {
66
66
  turnId?: string;
67
67
  }): Promise<CancelSessionResult>;
68
+ /**
69
+ * Queues removal of this session's durable model-message history. The
70
+ * session identity, agent configuration, state, limits, and sandbox remain.
71
+ * Consume the durable stream through `context.cleared` and its following
72
+ * `session.waiting` boundary before sending another turn.
73
+ */
74
+ clear(): Promise<ClearResult>;
75
+ /**
76
+ * Queues context compaction without sending model input. The request is
77
+ * asynchronous; consume the durable event stream through its next session
78
+ * boundary before sending another turn. `compaction.completed` confirms that
79
+ * summarization succeeded. A never-started handle is a successful no-op.
80
+ */
81
+ compact(): Promise<CompactResult>;
68
82
  /**
69
83
  * Terminally retires the session that owns this handle's continuation token.
70
84
  *
@@ -1 +1 @@
1
- import{EVE_CREATE_SESSION_ROUTE_PATH,EVE_RESET_SESSION_ROUTE_PATH,createEveCancelTurnRoutePath,createEveContinueSessionRoutePath}from"#protocol/routes.js";import{EVE_SESSION_ID_HEADER,isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{advanceSession,createInitialSessionState}from"#client/session-utils.js";import{ClientError}from"#client/client-error.js";import{createClientUrl}from"#client/url.js";import{MessageResponse}from"#client/message-response.js";import{CancelTurnResponseSchema}from"#protocol/cancel-turn.js";import{ResetResponseSchema}from"#protocol/reset-session.js";import{followStreamIterable}from"#client/open-stream.js";import{serializeOutputSchema}from"#shared/tool-schema.js";var ClientSession=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get state(){return this.#t}async snapshot(e){e?.signal?.throwIfAborted();let t=this.#t,n=t.sessionId;if(!n)throw Error(`Session has no session ID. Send a message first.`);let r=[];for await(let t of this.#a({follow:!1,sessionId:n,signal:e?.signal,startIndex:0}))r.push(t);e?.signal?.throwIfAborted();let i=r.at(-1),a=i?.type===`session.waiting`?i.data.continuationToken:i?.type===`session.completed`&&this.#e.preserveCompletedSessions?t.continuationToken:void 0;return{events:r,session:a===void 0?{sessionId:n,streamIndex:r.length}:{continuationToken:a,sessionId:n,streamIndex:r.length}}}async send(e){let t=normalizeSendTurnInput(e),n=this.#t,{continuationToken:r,sessionId:i}=await this.#n(t,n);if(this.#t===n){let e={...n,sessionId:i};r!==void 0&&(e.continuationToken=r),this.#t=e}return new MessageResponse({continuationToken:r,createStream:()=>this.#r(i,r,n,t),sessionId:i})}async cancel(e){let t=this.#t.sessionId;if(!t)throw Error(`Session has no session ID. Send a message first.`);let r=createClientUrl(this.#e.host,createEveCancelTurnRoutePath(t)),i=await this.#e.resolveHeaders();i.set(`content-type`,`application/json`);let a=await fetch(r,withRedirectPolicy({headers:i,method:`POST`,body:e?JSON.stringify(e):void 0},this.#e.redirect)),o=await a.text();if(!a.ok)throw new ClientError(a.status,o,a.headers);let s;try{s=JSON.parse(o)}catch{throw Error(`Cancel route returned invalid JSON (${a.status}).`)}let l=CancelTurnResponseSchema.safeParse(s);if(!l.success||l.data.sessionId!==t)throw Error(`Cancel route returned an invalid response (${a.status}).`);return{sessionId:l.data.sessionId,status:l.data.status}}async reset(){let e=this.#t,n=e.continuationToken;if(n===void 0){if(e.sessionId!==void 0)throw Error(`Session has no continuation token. Consume its event stream before resetting.`);return this.#t=createInitialSessionState(),{status:`no_active_session`}}let r=createClientUrl(this.#e.host,EVE_RESET_SESSION_ROUTE_PATH),i=await this.#e.resolveHeaders();i.set(`content-type`,`application/json`);let a=await fetch(r,withRedirectPolicy({body:JSON.stringify({continuationToken:n}),headers:i,method:`POST`},this.#e.redirect)),o=await a.text();if(!a.ok)throw new ClientError(a.status,o,a.headers);let l;try{l=JSON.parse(o)}catch{throw Error(`Reset route returned invalid JSON (${a.status}).`)}let u=ResetResponseSchema.safeParse(l);if(!u.success||u.data.status===`reset`&&e.sessionId!==void 0&&u.data.previousSessionId!==e.sessionId)throw Error(`Reset route returned an invalid response (${a.status}).`);return this.#t===e&&(this.#t=createInitialSessionState()),u.data.status===`reset`?{previousSessionId:u.data.previousSessionId,status:`reset`}:{status:`no_active_session`}}stream(e){let t=this.#t.sessionId;if(!t)throw Error(`Session has no session ID. Send a message first.`);if(e?.follow===!1&&(e.startIndex??this.#t.streamIndex)<0)throw Error(`stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.`);return this.#i(t,e)}async#n(t,n){let a=n.sessionId?createEveContinueSessionRoutePath(n.sessionId):EVE_CREATE_SESSION_ROUTE_PATH,o=createClientUrl(this.#e.host,a),s=await this.#e.resolveHeaders(t.headers);s.set(`content-type`,`application/json`);let c=createHandleMessageBody({input:t,outputSchema:serializeOutputSchema(t.outputSchema),session:n});if(c===null)throw Error(`Session.send requires a non-empty message, inputResponses, or both.`);let l=await postTurnWithRetry({body:JSON.stringify(c),headers:s,mustDeliver:(t.inputResponses?.length??0)>0,redirect:this.#e.redirect,signal:t.signal,url:o}),u=await l.json(),d=(typeof u.sessionId==`string`?u.sessionId:void 0)??l.headers.get(EVE_SESSION_ID_HEADER)?.trim()??n.sessionId;if(!d)throw Error(`Message route did not return a session id.`);return{continuationToken:typeof u.continuationToken==`string`?u.continuationToken:void 0,sessionId:d}}async*#r(e,t,n,r){let i=[];try{for await(let t of this.#a({headers:r.headers,streamReconnectPolicy:r.streamReconnectPolicy,sessionId:e,signal:r.signal,startIndex:n.sessionId===e?n.streamIndex:0}))if(i.push(t),yield t,isCurrentTurnBoundaryEvent(t))break}finally{this.#t=advanceSession({continuationToken:t,events:i,preserveCompletedSessions:this.#e.preserveCompletedSessions,sessionId:e,session:n})}}async*#i(e,t){let n=this.#t,r=t?.startIndex??n.streamIndex,i=[];try{for await(let n of this.#a({follow:t?.follow,sessionId:e,signal:t?.signal,startIndex:r,streamReconnectPolicy:t?.streamReconnectPolicy}))i.push(n),yield n}finally{r>=0&&(this.#t=advanceSession({continuationToken:n.continuationToken,events:i,preserveCompletedSessions:this.#e.preserveCompletedSessions,session:{...n,sessionId:e,streamIndex:r},sessionId:e}))}}#a(e){return followStreamIterable({follow:e.follow,host:this.#e.host,resolveHeaders:()=>this.#e.resolveHeaders(e.headers),redirect:this.#e.redirect,streamReconnectPolicy:e.streamReconnectPolicy,sessionId:e.sessionId,signal:e.signal,startIndex:e.startIndex})}};async function postTurnWithRetry(e){let t=e.mustDeliver?10:1,n,r,i;for(let a=0;a<t;a+=1){let o=await fetch(e.url,{body:e.body,headers:e.headers,method:`POST`,redirect:e.redirect,signal:e.signal??null});if(o.ok)return o;if(n=o.status,r=await o.text(),i=o.headers,!isRetryableDeliveryFailure(o.status,r))throw new ClientError(o.status,r,o.headers);a<t-1&&await sleep(200)}throw new ClientError(n??0,r??`Failed to deliver session turn.`,i)}function isRetryableDeliveryFailure(e,t){return e===500&&/target session was not found/i.test(t)}async function sleep(e){await new Promise(t=>setTimeout(t,e))}function normalizeSendTurnInput(e){return typeof e==`string`?{message:e}:e}function createHandleMessageBody(e){let t={};return e.input.message!==void 0&&(t.message=e.input.message),e.input.inputResponses!==void 0&&e.input.inputResponses.length>0&&(t.inputResponses=e.input.inputResponses),e.input.clientContext!==void 0&&(t.clientContext=e.input.clientContext),e.outputSchema!==void 0&&(t.outputSchema=e.outputSchema),e.session.continuationToken!==void 0&&(t.continuationToken=e.session.continuationToken),Object.keys(t).length===0||e.session.continuationToken===void 0&&t.message===void 0||e.session.continuationToken!==void 0&&t.message===void 0&&t.inputResponses===void 0?null:t}function withRedirectPolicy(e,t){return t===void 0?e:{...e,redirect:t}}export{ClientSession};
1
+ import{EVE_CLEAR_SESSION_ROUTE_PATH,EVE_COMPACT_SESSION_ROUTE_PATH,EVE_CREATE_SESSION_ROUTE_PATH,EVE_RESET_SESSION_ROUTE_PATH,createEveCancelTurnRoutePath,createEveContinueSessionRoutePath}from"#protocol/routes.js";import{EVE_SESSION_ID_HEADER,isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{advanceSession,createInitialSessionState}from"#client/session-utils.js";import{ClientError}from"#client/client-error.js";import{createClientUrl}from"#client/url.js";import{MessageResponse}from"#client/message-response.js";import{CancelTurnResponseSchema}from"#protocol/cancel-turn.js";import{ClearResponseSchema}from"#protocol/clear-session.js";import{CompactResponseSchema}from"#protocol/compact-session.js";import{ResetResponseSchema}from"#protocol/reset-session.js";import{followStreamIterable}from"#client/open-stream.js";import{serializeOutputSchema}from"#shared/tool-schema.js";var ClientSession=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get state(){return this.#t}async snapshot(e){e?.signal?.throwIfAborted();let t=this.#t,n=t.sessionId;if(!n)throw Error(`Session has no session ID. Send a message first.`);let r=[];for await(let t of this.#a({follow:!1,sessionId:n,signal:e?.signal,startIndex:0}))r.push(t);e?.signal?.throwIfAborted();let i=r.at(-1),a=i?.type===`session.waiting`?i.data.continuationToken:i?.type===`session.completed`&&this.#e.preserveCompletedSessions?t.continuationToken:void 0;return{events:r,session:a===void 0?{sessionId:n,streamIndex:r.length}:{continuationToken:a,sessionId:n,streamIndex:r.length}}}async send(e){let t=normalizeSendTurnInput(e),n=this.#t,{continuationToken:r,sessionId:i}=await this.#n(t,n);if(this.#t===n){let e={...n,sessionId:i};r!==void 0&&(e.continuationToken=r),this.#t=e}return new MessageResponse({continuationToken:r,createStream:()=>this.#r(i,r,n,t),sessionId:i})}async cancel(e){let t=this.#t.sessionId;if(!t)throw Error(`Session has no session ID. Send a message first.`);let n=createClientUrl(this.#e.host,createEveCancelTurnRoutePath(t)),r=await this.#e.resolveHeaders();r.set(`content-type`,`application/json`);let a=await fetch(n,withRedirectPolicy({headers:r,method:`POST`,body:e?JSON.stringify(e):void 0},this.#e.redirect)),o=await a.text();if(!a.ok)throw new ClientError(a.status,o,a.headers);let s;try{s=JSON.parse(o)}catch{throw Error(`Cancel route returned invalid JSON (${a.status}).`)}let c=CancelTurnResponseSchema.safeParse(s);if(!c.success||c.data.sessionId!==t)throw Error(`Cancel route returned an invalid response (${a.status}).`);return{sessionId:c.data.sessionId,status:c.data.status}}async clear(){let t=this.#t,n=t.continuationToken;if(n===void 0){if(t.sessionId!==void 0)throw Error(`Session has no continuation token. Consume its event stream before clearing.`);return{status:`no_active_session`}}let r=createClientUrl(this.#e.host,EVE_CLEAR_SESSION_ROUTE_PATH),i=await this.#e.resolveHeaders();i.set(`content-type`,`application/json`);let a=await fetch(r,withRedirectPolicy({body:JSON.stringify({continuationToken:n}),headers:i,method:`POST`},this.#e.redirect)),o=await a.text();if(!a.ok)throw new ClientError(a.status,o,a.headers);let s;try{s=JSON.parse(o)}catch{throw Error(`Clear route returned invalid JSON (${a.status}).`)}let c=ClearResponseSchema.safeParse(s);if(!c.success||c.data.status===`accepted`&&t.sessionId!==void 0&&c.data.sessionId!==t.sessionId)throw Error(`Clear route returned an invalid response (${a.status}).`);return c.data.status===`accepted`?{sessionId:c.data.sessionId,status:`accepted`}:{status:`no_active_session`}}async compact(){let e=this.#t,n=e.continuationToken;if(n===void 0){if(e.sessionId!==void 0)throw Error(`Session has no continuation token. Consume its event stream before compacting.`);return{status:`no_active_session`}}let r=createClientUrl(this.#e.host,EVE_COMPACT_SESSION_ROUTE_PATH),i=await this.#e.resolveHeaders();i.set(`content-type`,`application/json`);let a=await fetch(r,withRedirectPolicy({body:JSON.stringify({continuationToken:n}),headers:i,method:`POST`},this.#e.redirect)),o=await a.text();if(!a.ok)throw new ClientError(a.status,o,a.headers);let s;try{s=JSON.parse(o)}catch{throw Error(`Compact route returned invalid JSON (${a.status}).`)}let c=CompactResponseSchema.safeParse(s);if(!c.success||c.data.status===`accepted`&&e.sessionId!==void 0&&c.data.sessionId!==e.sessionId)throw Error(`Compact route returned an invalid response (${a.status}).`);return c.data.status===`accepted`?{sessionId:c.data.sessionId,status:`accepted`}:{status:`no_active_session`}}async reset(){let e=this.#t,t=e.continuationToken;if(t===void 0){if(e.sessionId!==void 0)throw Error(`Session has no continuation token. Consume its event stream before resetting.`);return this.#t=createInitialSessionState(),{status:`no_active_session`}}let n=createClientUrl(this.#e.host,EVE_RESET_SESSION_ROUTE_PATH),i=await this.#e.resolveHeaders();i.set(`content-type`,`application/json`);let a=await fetch(n,withRedirectPolicy({body:JSON.stringify({continuationToken:t}),headers:i,method:`POST`},this.#e.redirect)),o=await a.text();if(!a.ok)throw new ClientError(a.status,o,a.headers);let s;try{s=JSON.parse(o)}catch{throw Error(`Reset route returned invalid JSON (${a.status}).`)}let c=ResetResponseSchema.safeParse(s);if(!c.success||c.data.status===`reset`&&e.sessionId!==void 0&&c.data.previousSessionId!==e.sessionId)throw Error(`Reset route returned an invalid response (${a.status}).`);return this.#t===e&&(this.#t=createInitialSessionState()),c.data.status===`reset`?{previousSessionId:c.data.previousSessionId,status:`reset`}:{status:`no_active_session`}}stream(e){let t=this.#t.sessionId;if(!t)throw Error(`Session has no session ID. Send a message first.`);if(e?.follow===!1&&(e.startIndex??this.#t.streamIndex)<0)throw Error(`stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.`);return this.#i(t,e)}async#n(e,t){let r=t.sessionId?createEveContinueSessionRoutePath(t.sessionId):EVE_CREATE_SESSION_ROUTE_PATH,i=createClientUrl(this.#e.host,r),s=await this.#e.resolveHeaders(e.headers);s.set(`content-type`,`application/json`);let c=createHandleMessageBody({input:e,outputSchema:serializeOutputSchema(e.outputSchema),session:t});if(c===null)throw Error(`Session.send requires a non-empty message, inputResponses, or both.`);let l=await postTurnWithRetry({body:JSON.stringify(c),headers:s,mustDeliver:(e.inputResponses?.length??0)>0,redirect:this.#e.redirect,signal:e.signal,url:i}),u=await l.json(),d=(typeof u.sessionId==`string`?u.sessionId:void 0)??l.headers.get(EVE_SESSION_ID_HEADER)?.trim()??t.sessionId;if(!d)throw Error(`Message route did not return a session id.`);return{continuationToken:typeof u.continuationToken==`string`?u.continuationToken:void 0,sessionId:d}}async*#r(e,t,n,r){let i=[];try{for await(let t of this.#a({headers:r.headers,streamReconnectPolicy:r.streamReconnectPolicy,sessionId:e,signal:r.signal,startIndex:n.sessionId===e?n.streamIndex:0}))if(i.push(t),yield t,isCurrentTurnBoundaryEvent(t))break}finally{this.#t=advanceSession({continuationToken:t,events:i,preserveCompletedSessions:this.#e.preserveCompletedSessions,sessionId:e,session:n})}}async*#i(e,t){let n=this.#t,r=t?.startIndex??n.streamIndex,i=[];try{for await(let n of this.#a({follow:t?.follow,sessionId:e,signal:t?.signal,startIndex:r,streamReconnectPolicy:t?.streamReconnectPolicy}))i.push(n),yield n}finally{r>=0&&(this.#t=advanceSession({continuationToken:n.continuationToken,events:i,preserveCompletedSessions:this.#e.preserveCompletedSessions,session:{...n,sessionId:e,streamIndex:r},sessionId:e}))}}#a(e){return followStreamIterable({follow:e.follow,host:this.#e.host,resolveHeaders:()=>this.#e.resolveHeaders(e.headers),redirect:this.#e.redirect,streamReconnectPolicy:e.streamReconnectPolicy,sessionId:e.sessionId,signal:e.signal,startIndex:e.startIndex})}};async function postTurnWithRetry(e){let t=e.mustDeliver?10:1,n,r,i;for(let a=0;a<t;a+=1){let o=await fetch(e.url,{body:e.body,headers:e.headers,method:`POST`,redirect:e.redirect,signal:e.signal??null});if(o.ok)return o;if(n=o.status,r=await o.text(),i=o.headers,!isRetryableDeliveryFailure(o.status,r))throw new ClientError(o.status,r,o.headers);a<t-1&&await sleep(200)}throw new ClientError(n??0,r??`Failed to deliver session turn.`,i)}function isRetryableDeliveryFailure(e,t){return e===500&&/target session was not found/i.test(t)}async function sleep(e){await new Promise(t=>setTimeout(t,e))}function normalizeSendTurnInput(e){return typeof e==`string`?{message:e}:e}function createHandleMessageBody(e){let t={};return e.input.message!==void 0&&(t.message=e.input.message),e.input.inputResponses!==void 0&&e.input.inputResponses.length>0&&(t.inputResponses=e.input.inputResponses),e.input.clientContext!==void 0&&(t.clientContext=e.input.clientContext),e.outputSchema!==void 0&&(t.outputSchema=e.outputSchema),e.session.continuationToken!==void 0&&(t.continuationToken=e.session.continuationToken),Object.keys(t).length===0||e.session.continuationToken===void 0&&t.message===void 0||e.session.continuationToken!==void 0&&t.message===void 0&&t.inputResponses===void 0?null:t}function withRedirectPolicy(e,t){return t===void 0?e:{...e,redirect:t}}export{ClientSession};
@@ -2,6 +2,8 @@ import type { UserContent } from "ai";
2
2
  import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
3
3
  import type { MessageStreamEvent } from "#protocol/message.js";
4
4
  import type { CancelTurnStatus } from "#protocol/cancel-turn.js";
5
+ import type { ClearStatus } from "#protocol/clear-session.js";
6
+ import type { CompactStatus } from "#protocol/compact-session.js";
5
7
  import type { ResetStatus } from "#protocol/reset-session.js";
6
8
  import type { InputRequest, InputResponse } from "#runtime/input/types.js";
7
9
  import type { JsonObject } from "#shared/json.js";
@@ -190,6 +192,24 @@ export interface CancelSessionResult {
190
192
  /** Both outcomes are successful; `no_active_turn` means there was nothing left to cancel. */
191
193
  readonly status: CancelTurnStatus;
192
194
  }
195
+ /** Result of requesting a context clear for a client session. */
196
+ export type ClearResult = {
197
+ /** Session whose clear request was queued. */
198
+ readonly sessionId: string;
199
+ readonly status: Extract<ClearStatus, "accepted">;
200
+ } | {
201
+ /** The client had no continuation token or the token was already free. */
202
+ readonly status: Extract<ClearStatus, "no_active_session">;
203
+ };
204
+ /** Result of requesting context compaction for a client session. */
205
+ export type CompactResult = {
206
+ /** Session whose compaction request was queued. */
207
+ readonly sessionId: string;
208
+ readonly status: Extract<CompactStatus, "accepted">;
209
+ } | {
210
+ /** The client had no continuation token or the token was already free. */
211
+ readonly status: Extract<CompactStatus, "no_active_session">;
212
+ };
193
213
  /** Result of terminally resetting a client session. */
194
214
  export type ResetResult = {
195
215
  /** The prior session was retired and its continuation token released. */
@@ -16,8 +16,8 @@ declare const EXTENSION_CAPABILITY_CONTRACTS: {
16
16
  readonly dropped: {};
17
17
  };
18
18
  readonly dynamicTool: {
19
- readonly current: 6;
20
- readonly supported: readonly [1, 2, 3, 4, 5, 6];
19
+ readonly current: 7;
20
+ readonly supported: readonly [1, 2, 3, 4, 5, 6, 7];
21
21
  readonly dropped: {};
22
22
  };
23
23
  readonly connection: {
@@ -26,8 +26,8 @@ declare const EXTENSION_CAPABILITY_CONTRACTS: {
26
26
  readonly dropped: {};
27
27
  };
28
28
  readonly hook: {
29
- readonly current: 4;
30
- readonly supported: readonly [1, 2, 3, 4];
29
+ readonly current: 5;
30
+ readonly supported: readonly [1, 2, 3, 4, 5];
31
31
  readonly dropped: {};
32
32
  };
33
33
  readonly skill: {
@@ -36,8 +36,8 @@ declare const EXTENSION_CAPABILITY_CONTRACTS: {
36
36
  readonly dropped: {};
37
37
  };
38
38
  readonly dynamicSkill: {
39
- readonly current: 3;
40
- readonly supported: readonly [1, 2, 3];
39
+ readonly current: 4;
40
+ readonly supported: readonly [1, 2, 3, 4];
41
41
  readonly dropped: {};
42
42
  };
43
43
  readonly instructions: {
@@ -46,8 +46,8 @@ declare const EXTENSION_CAPABILITY_CONTRACTS: {
46
46
  readonly dropped: {};
47
47
  };
48
48
  readonly dynamicInstructions: {
49
- readonly current: 3;
50
- readonly supported: readonly [1, 2, 3];
49
+ readonly current: 4;
50
+ readonly supported: readonly [1, 2, 3, 4];
51
51
  readonly dropped: {};
52
52
  };
53
53
  readonly config: {
@@ -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=1,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME=`_manifest.json`,EXTENSION_CAPABILITY_CONTRACTS={extension:{current:1,supported:[1],dropped:{}},tool:{current:3,supported:[1,2,3],dropped:{}},dynamicTool:{current:6,supported:[1,2,3,4,5,6],dropped:{}},connection:{current:2,supported:[1,2],dropped:{}},hook:{current:4,supported:[1,2,3,4],dropped:{}},skill:{current:1,supported:[1],dropped:{}},dynamicSkill:{current:3,supported:[1,2,3],dropped:{}},instructions:{current:1,supported:[1],dropped:{}},dynamicInstructions:{current:3,supported:[1,2,3],dropped:{}},config:{current:1,supported:[1],dropped:{}},state:{current:2,supported:[1,2],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),{}),extensionCompatibilityManifestSchema=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();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
+ 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=1,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME=`_manifest.json`,EXTENSION_CAPABILITY_CONTRACTS={extension:{current:1,supported:[1],dropped:{}},tool:{current:3,supported:[1,2,3],dropped:{}},dynamicTool:{current:7,supported:[1,2,3,4,5,6,7],dropped:{}},connection:{current:2,supported:[1,2],dropped:{}},hook:{current:5,supported:[1,2,3,4,5],dropped:{}},skill:{current:1,supported:[1],dropped:{}},dynamicSkill:{current:4,supported:[1,2,3,4],dropped:{}},instructions:{current:1,supported:[1],dropped:{}},dynamicInstructions:{current:4,supported:[1,2,3,4],dropped:{}},config:{current:1,supported:[1],dropped:{}},state:{current:2,supported:[1,2],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),{}),extensionCompatibilityManifestSchema=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();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,6 +1,6 @@
1
1
  import { z } from "#compiled/zod/index.js";
2
2
  import { type DiscoverDiagnosticsSummary } from "#discover/diagnostics.js";
3
- import { type CompiledRemoteAgentNode } from "#compiler/remote-agent-node.js";
3
+ import { type CompiledDynamicSubagentDefinition, type CompiledRemoteAgentNode } from "#compiler/remote-agent-node.js";
4
4
  import type { ChannelRouteMethod } from "#public/definitions/channel.js";
5
5
  import type { NormalizedChannelCorsOptions } from "#channel/cors.js";
6
6
  import type { InternalInstructionsDefinition } from "#shared/instructions-definition.js";
@@ -20,7 +20,7 @@ export declare const ROOT_COMPILED_AGENT_NODE_ID = "__root__";
20
20
  /**
21
21
  * Current compiled manifest schema version.
22
22
  */
23
- export declare const COMPILED_AGENT_MANIFEST_VERSION = 37;
23
+ export declare const COMPILED_AGENT_MANIFEST_VERSION = 38;
24
24
  /**
25
25
  * Compiled channel entry preserved in the compiled manifest.
26
26
  */
@@ -197,17 +197,18 @@ export interface CompiledHookDefinition extends ModuleSourceRef {
197
197
  * every flattened subagent node.
198
198
  */
199
199
  export type CompiledAgentNodeManifest = z.infer<typeof compiledAgentNodeManifestSchema>;
200
- /**
201
- * Flattened compiled subagent node emitted by the compiler. `name` and
202
- * `description` are copied from `agent.config` for fast registry lookup.
203
- */
204
200
  export type CompiledSubagentNode = Readonly<ModuleSourceRef & Node & {
205
201
  agent: CompiledAgentNodeManifest;
206
- description: string;
207
202
  entryPath: string;
208
203
  name: string;
209
204
  rootPath: string;
210
- }>;
205
+ } & ({
206
+ description: string;
207
+ dynamic?: never;
208
+ } | {
209
+ description?: never;
210
+ dynamic: CompiledDynamicSubagentDefinition;
211
+ })>;
211
212
  export type { CompiledRemoteAgentNode } from "#compiler/remote-agent-node.js";
212
213
  /**
213
214
  * Parent-child edge connecting two compiled agent nodes.
@@ -464,19 +465,7 @@ export declare const compiledAgentManifestSchema: z.ZodObject<{
464
465
  }, z.core.$strict>>;
465
466
  skills: z.ZodReadonly<z.ZodArray<z.ZodType<CompiledSkillDefinition, unknown, z.core.$ZodTypeInternals<CompiledSkillDefinition, unknown>>>>;
466
467
  subagentEdges: z.ZodArray<z.ZodType<CompiledSubagentEdge, unknown, z.core.$ZodTypeInternals<CompiledSubagentEdge, unknown>>>;
467
- subagents: z.ZodArray<z.ZodType<Readonly<ModuleSourceRef & Node & {
468
- agent: CompiledAgentNodeManifest;
469
- description: string;
470
- entryPath: string;
471
- name: string;
472
- rootPath: string;
473
- }>, unknown, z.core.$ZodTypeInternals<Readonly<ModuleSourceRef & Node & {
474
- agent: CompiledAgentNodeManifest;
475
- description: string;
476
- entryPath: string;
477
- name: string;
478
- rootPath: string;
479
- }>, unknown>>>;
468
+ subagents: z.ZodArray<z.ZodType<CompiledSubagentNode, unknown, z.core.$ZodTypeInternals<CompiledSubagentNode, unknown>>>;
480
469
  instructions: z.ZodOptional<z.ZodType<CompiledInstructionsDefinition, unknown, z.core.$ZodTypeInternals<CompiledInstructionsDefinition, unknown>>>;
481
470
  tools: z.ZodArray<z.ZodObject<{
482
471
  description: z.ZodString;
@@ -488,7 +477,7 @@ export declare const compiledAgentManifestSchema: z.ZodObject<{
488
477
  sourceId: z.ZodString;
489
478
  sourceKind: z.ZodLiteral<"module">;
490
479
  }, z.core.$strict>>;
491
- version: z.ZodLiteral<37>;
480
+ version: z.ZodLiteral<38>;
492
481
  workspaceResourceRoot: z.ZodObject<{
493
482
  contentHash: z.ZodOptional<z.ZodString>;
494
483
  logicalPath: z.ZodString;