@robota-sdk/agent-transport 3.0.0-beta.71 → 3.0.0-beta.72

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.
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunk-Bmb41Sf3.cjs`);const e=require(`./headless-DCtHvyVf.cjs`),t=require(`./http-Da6Kw4oy.cjs`),n=require(`./ws-tCjj2gPu.cjs`),r=require(`./mcp-Bl8jUfev.cjs`),i=require(`./tui-DULGN7sr.cjs`);let a=require(`@robota-sdk/agent-framework`);var o=class{entries=new Map;settingsPath;constructor(e){this.settingsPath=e}register(e){this.entries.set(e.name,e)}getAll(){let e=this.readTransportSettings();return Array.from(this.entries.values()).map(t=>({transport:t,config:this.resolveConfig(t,e[t.name])}))}getEnabled(){return this.getAll().filter(e=>e.config.enabled).map(e=>e.transport)}async setEnabled(e,t){let n=(0,a.readSettings)(this.settingsPath),r=n.transports??{};r[e]={...r[e]??{},enabled:t},n.transports=r,(0,a.writeSettings)(this.settingsPath,n)}async setOptions(e,t){let n=(0,a.readSettings)(this.settingsPath),r=n.transports??{};r[e]={...r[e]??{},options:t},n.transports=r,(0,a.writeSettings)(this.settingsPath,n)}async startAll(e){let t=this.getEnabled();for(let n of t)n.attach(e),await n.start()}async stopAll(){for(let e of this.entries.values())await e.stop()}resolveConfig(e,t){return{enabled:t?.enabled??e.defaultEnabled,options:t?.options??{}}}readTransportSettings(){let e=(0,a.readSettings)(this.settingsPath).transports;return!e||typeof e!=`object`||Array.isArray(e)?{}:e}};function s(){let e=new o((0,a.getUserSettingsPath)());return e.register(new n.t),e}exports.HeadlessInteractionChannel=e.t,exports.PrintTerminal=e.a,exports.TransportRegistry=o,exports.TuiTransport=i.n,exports.WsTransport=n.t,exports.createAgentMcpServer=r.n,exports.createAgentRoutes=t.n,exports.createDefaultTransportRegistry=s,exports.createDefaultTuiCliAdapter=i.t,exports.createHeadlessRunner=e.r,exports.createHeadlessTransport=e.n,exports.createHttpTransport=t.t,exports.createMcpTransport=r.t,exports.createWsHandler=n.r,exports.createWsTransport=n.n,exports.promptInput=e.i,exports.renderApp=i.r;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunk-Bmb41Sf3.cjs`);const e=require(`./headless-DCtHvyVf.cjs`),t=require(`./http-Da6Kw4oy.cjs`),n=require(`./ws-tCjj2gPu.cjs`),r=require(`./mcp-Bl8jUfev.cjs`),i=require(`./tui-CcLmEJ1r.cjs`);let a=require(`@robota-sdk/agent-framework`);var o=class{entries=new Map;settingsPath;constructor(e){this.settingsPath=e}register(e){this.entries.set(e.name,e)}getAll(){let e=this.readTransportSettings();return Array.from(this.entries.values()).map(t=>({transport:t,config:this.resolveConfig(t,e[t.name])}))}getEnabled(){return this.getAll().filter(e=>e.config.enabled).map(e=>e.transport)}async setEnabled(e,t){let n=(0,a.readSettings)(this.settingsPath),r=n.transports??{};r[e]={...r[e]??{},enabled:t},n.transports=r,(0,a.writeSettings)(this.settingsPath,n)}async setOptions(e,t){let n=(0,a.readSettings)(this.settingsPath),r=n.transports??{};r[e]={...r[e]??{},options:t},n.transports=r,(0,a.writeSettings)(this.settingsPath,n)}async startAll(e){let t=this.getEnabled();for(let n of t)n.attach(e),await n.start()}async stopAll(){for(let e of this.entries.values())await e.stop()}resolveConfig(e,t){return{enabled:t?.enabled??e.defaultEnabled,options:t?.options??{}}}readTransportSettings(){let e=(0,a.readSettings)(this.settingsPath).transports;return!e||typeof e!=`object`||Array.isArray(e)?{}:e}};function s(){let e=new o((0,a.getUserSettingsPath)());return e.register(new n.t),e}exports.HeadlessInteractionChannel=e.t,exports.PrintTerminal=e.a,exports.TransportRegistry=o,exports.TuiTransport=i.n,exports.WsTransport=n.t,exports.createAgentMcpServer=r.n,exports.createAgentRoutes=t.n,exports.createDefaultTransportRegistry=s,exports.createDefaultTuiCliAdapter=i.t,exports.createHeadlessRunner=e.r,exports.createHeadlessTransport=e.n,exports.createHttpTransport=t.t,exports.createMcpTransport=r.t,exports.createWsHandler=n.r,exports.createWsTransport=n.n,exports.promptInput=e.i,exports.renderApp=i.r;
@@ -1,2 +1,2 @@
1
- import{a as e,i as t,n,r,t as i}from"./headless-C6tj35h3.js";import{n as a,t as o}from"./http-Br10Ps8m.js";import{n as s,r as c,t as l}from"./ws-BWel8nzl.js";import{n as u,t as d}from"./mcp-BAujHOMr.js";import{n as f,r as p,t as m}from"./tui-Bl-bm9iA.js";import{getUserSettingsPath as h,readSettings as g,writeSettings as _}from"@robota-sdk/agent-framework";var v=class{entries=new Map;settingsPath;constructor(e){this.settingsPath=e}register(e){this.entries.set(e.name,e)}getAll(){let e=this.readTransportSettings();return Array.from(this.entries.values()).map(t=>({transport:t,config:this.resolveConfig(t,e[t.name])}))}getEnabled(){return this.getAll().filter(e=>e.config.enabled).map(e=>e.transport)}async setEnabled(e,t){let n=g(this.settingsPath),r=n.transports??{};r[e]={...r[e]??{},enabled:t},n.transports=r,_(this.settingsPath,n)}async setOptions(e,t){let n=g(this.settingsPath),r=n.transports??{};r[e]={...r[e]??{},options:t},n.transports=r,_(this.settingsPath,n)}async startAll(e){let t=this.getEnabled();for(let n of t)n.attach(e),await n.start()}async stopAll(){for(let e of this.entries.values())await e.stop()}resolveConfig(e,t){return{enabled:t?.enabled??e.defaultEnabled,options:t?.options??{}}}readTransportSettings(){let e=g(this.settingsPath).transports;return!e||typeof e!=`object`||Array.isArray(e)?{}:e}};function y(){let e=new v(h());return e.register(new l),e}export{i as HeadlessInteractionChannel,e as PrintTerminal,v as TransportRegistry,f as TuiTransport,l as WsTransport,u as createAgentMcpServer,a as createAgentRoutes,y as createDefaultTransportRegistry,m as createDefaultTuiCliAdapter,r as createHeadlessRunner,n as createHeadlessTransport,o as createHttpTransport,d as createMcpTransport,c as createWsHandler,s as createWsTransport,t as promptInput,p as renderApp};
1
+ import{a as e,i as t,n,r,t as i}from"./headless-C6tj35h3.js";import{n as a,t as o}from"./http-Br10Ps8m.js";import{n as s,r as c,t as l}from"./ws-BWel8nzl.js";import{n as u,t as d}from"./mcp-BAujHOMr.js";import{n as f,r as p,t as m}from"./tui-4hA-SMtS.js";import{getUserSettingsPath as h,readSettings as g,writeSettings as _}from"@robota-sdk/agent-framework";var v=class{entries=new Map;settingsPath;constructor(e){this.settingsPath=e}register(e){this.entries.set(e.name,e)}getAll(){let e=this.readTransportSettings();return Array.from(this.entries.values()).map(t=>({transport:t,config:this.resolveConfig(t,e[t.name])}))}getEnabled(){return this.getAll().filter(e=>e.config.enabled).map(e=>e.transport)}async setEnabled(e,t){let n=g(this.settingsPath),r=n.transports??{};r[e]={...r[e]??{},enabled:t},n.transports=r,_(this.settingsPath,n)}async setOptions(e,t){let n=g(this.settingsPath),r=n.transports??{};r[e]={...r[e]??{},options:t},n.transports=r,_(this.settingsPath,n)}async startAll(e){let t=this.getEnabled();for(let n of t)n.attach(e),await n.start()}async stopAll(){for(let e of this.entries.values())await e.stop()}resolveConfig(e,t){return{enabled:t?.enabled??e.defaultEnabled,options:t?.options??{}}}readTransportSettings(){let e=g(this.settingsPath).transports;return!e||typeof e!=`object`||Array.isArray(e)?{}:e}};function y(){let e=new v(h());return e.register(new l),e}export{i as HeadlessInteractionChannel,e as PrintTerminal,v as TransportRegistry,f as TuiTransport,l as WsTransport,u as createAgentMcpServer,a as createAgentRoutes,y as createDefaultTransportRegistry,m as createDefaultTuiCliAdapter,r as createHeadlessRunner,n as createHeadlessTransport,o as createHttpTransport,d as createMcpTransport,c as createWsHandler,s as createWsTransport,t as promptInput,p as renderApp};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../tui-DULGN7sr.cjs`);exports.TuiTransport=e.n,exports.createDefaultTuiCliAdapter=e.t,exports.renderApp=e.r;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../tui-CcLmEJ1r.cjs`);exports.TuiTransport=e.n,exports.createDefaultTuiCliAdapter=e.t,exports.renderApp=e.r;
@@ -1 +1 @@
1
- import{n as e,r as t,t as n}from"../tui-Bl-bm9iA.js";export{e as TuiTransport,n as createDefaultTuiCliAdapter,t as renderApp};
1
+ import{n as e,r as t,t as n}from"../tui-4hA-SMtS.js";export{e as TuiTransport,n as createDefaultTuiCliAdapter,t as renderApp};
@@ -21,5 +21,5 @@ _(interrupted)_`:``)):t})})]})});function Sn({entry:e}){let t=e.data,n=t?.tools,
21
21
  | |_) | | | | _ \\| | | || | / _ \\
22
22
  | _ <| |_| | |_) | |_| || |/ ___ \\
23
23
  |_| \\_\\\\___/|____/ \\___/ |_/_/ \\_\\
24
- `}),B(g,{dimColor:!0,children:[` v`,e.version]})]},`logo`)}),W&&z(dr,{message:W}),B(m,{flexDirection:`column`,paddingX:1,flexGrow:1,children:[J&&J.kind!==`main_thread`?z(me,{entry:J,page:re,loading:se,error:ae}):z(Tn,{history:o}),p&&z(m,{marginBottom:1,children:z(g,{color:`yellow`,children:`Shutting down...`})}),(d||u.length>0)&&z(m,{flexDirection:`column`,marginBottom:1,children:z(sr,{text:c,activeTools:u,isThinking:d})}),z(fe,{entries:q})]}),G&&z(_e,{snapshot:b,selectedEntryId:x,onSelect:S,onClose:()=>K(!1)}),w&&z(Mn,{request:w}),X&&z(Lt,{prompt:X,onSubmit:xe,onCancel:Se}),Z&&z(Gn,{callbacks:H,onClose:()=>ve(!1),addMessage:e=>s(L(j(e.content)))}),$&&e.transportRegistry&&z(ur,{registry:e.transportRegistry,onClose:()=>be(!1)}),Q&&z(Kn,{sessions:l(e.sessionStore,e.cwd),onSelect:t=>{ye(!1),e.onSessionSwitch(t)},onCancel:()=>{ye(!1),s(L(j(`Session resume cancelled.`)))}}),z(pe,{percentage:E.percentage}),z(rr,{cwd:t,permissionMode:je,modelId:e.modelId,providerType:e.providerType,sessionId:Me,isThinking:d,activeToolCount:u.length,activeBackgroundTaskCount:ge,hasPendingPrompt:_!==null,contextState:E,sessionName:I,settings:le,activeAgentLabel:Te,gitRefreshToken:de}),z(kt,{onSubmit:Oe,onCancelQueue:P,isDisabled:!!w||Z||$||Q||G||p||X!==null||d&&!!_||!we,isAborting:f,pendingPrompt:_,registry:i,sessionName:I,history:o}),z(m,{position:`absolute`,children:z(g,{children:` `})})]})}var mr=class{queue=[];enqueueInteraction(e){this.queue.push({type:`interaction`,interaction:e})}enqueueEffects(e){e.length!==0&&this.queue.push({type:`effects`,effects:[...e]})}drain(){return this.queue.shift()}clear(){this.queue.length=0}};function hr(e,t,n,r,i,a){let o=gr(e.effects,n,r,a);if(r.addEntry(L(j(e.message))),e.interaction!==void 0&&i.enqueueInteraction(e.interaction),o.length>0&&i.enqueueEffects(o),t.isInitialized){let e=t.getContextState();r.setContextState({percentage:e.usedPercentage,usedTokens:e.usedTokens,maxTokens:e.maxTokens})}}function gr(e,t,n,r){if(e===void 0||e.length===0)return[];let i=[];for(let a of e){if(a.type===`conversation-history-cleared`){n.clearHistory();continue}if(a.type===`plugin-registry-reload-requested`){r?.(t);continue}i.push(a)}return i}function _r(e){return e.toLowerCase().replace(/[^a-z0-9\s-]/g,``).trim().replace(/\s+/g,`-`).replace(/-+/g,`-`).slice(0,60)}async function vr(e,t){let n=t.slice(0,200),r=await e.chat([j(`You generate short session titles. Respond with ONLY a 3-5 word lowercase-hyphenated title (e.g. refactor-auth-middleware). No explanation, no punctuation, no quotes.`),M(n)],{maxTokens:20}),i=_r(typeof r.content==`string`?r.content:``);return!i||i.length<3?_r(t):i}function yr(e,t){let n=null;return{schedule(){n||=setTimeout(()=>{n=null,e()},t)},flush(){n&&=(clearTimeout(n),null)}}}var br=class{history=[];streamingText=``;activeTools=[];isThinking=!1;isAborting=!1;pendingPrompt=null;contextState={percentage:0,usedTokens:0,maxTokens:0};executionWorkspaceSnapshot=null;selectedExecutionEntryId;onChange=null;streamBuf=``;debouncedStreamNotify=yr(()=>this.notify(),300);notify(){this.onChange?.()}onTextDelta=e=>{this.streamBuf+=e,this.streamingText=this.streamBuf,this.debouncedStreamNotify.schedule()};onToolStart=e=>{this.activeTools=[...this.activeTools,e],this.notify()};onToolEnd=e=>{let t=this.activeTools.findLastIndex(t=>t.toolName===e.toolName&&t.isRunning);if(t!==-1){let n=[...this.activeTools];n[t]=e,this.activeTools=n}this.notify()};onThinking=e=>{this.isThinking=e,e?(this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[]):(this.isAborting=!1,this.activeTools=[]),this.notify()};onComplete=e=>{this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[],this.contextState={percentage:e.contextState.usedPercentage,usedTokens:e.contextState.usedTokens,maxTokens:e.contextState.maxTokens},this.notify()};onInterrupted=()=>{this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[],this.notify()};onError=()=>{this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[],this.notify()};onContextUpdate=e=>{this.setContextState({percentage:e.usedPercentage,usedTokens:e.usedTokens,maxTokens:e.maxTokens})};syncHistory(e){e.length!==0&&(this.history=e.length>100?e.slice(-100):[...e],this.notify())}addEntry(e){let t=[...this.history,e];this.history=t.length>100?t.slice(-100):t,this.notify()}clearHistory(){this.history=[],this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[],this.notify()}setPendingPrompt(e){this.pendingPrompt=e,this.notify()}setAborting(e){this.isAborting=e,this.notify()}setContextState(e){this.contextState=e,this.notify()}syncExecutionWorkspaceSnapshot(e){let t=this.selectedExecutionEntryId,n=t!==void 0&&e.entries.some(e=>e.id===t)?t:e.selectedEntryId??e.entries[0]?.id;this.executionWorkspaceSnapshot={...e,...n?{selectedEntryId:n}:{}},this.selectedExecutionEntryId=n,this.notify()}selectExecutionWorkspaceEntry(e){this.executionWorkspaceSnapshot?.entries.some(t=>t.id===e)&&(this.selectedExecutionEntryId=e,this.executionWorkspaceSnapshot={...this.executionWorkspaceSnapshot,selectedEntryId:e},this.notify())}},xr=class{stateManager;interactiveSession;registry;commandEffectQueue;opts;submitHandler=null;actionQueue=[];processingAction=!1;permissionRequest=null;pendingAction=null;availableCommands=[];isShuttingDown=!1;sessionName;autoNameTriggered=!1;sessionStarted=!1;initCheckInterval=null;permissionQueue=[];processingPermission=!1;onChange=null;constructor(e){this.opts=e,this.sessionName=e.sessionName,this.stateManager=new br,this.stateManager.onChange=()=>this.onChange?.(),this.interactiveSession=this.createSession(),this.registry=this.createRegistry(),this.commandEffectQueue=new mr}createSession(){let e=this.opts;return new n({cwd:e.cwd,provider:e.provider,permissionMode:e.permissionMode,maxTurns:e.maxTurns,permissionHandler:(e,t)=>this.handlePermissionRequest(e,t),sessionStore:e.sessionStore,resumeSessionId:e.resumeSessionId,forkSession:e.forkSession,sessionName:e.sessionName,backgroundTaskRunners:e.backgroundTaskRunners,subagentRunnerFactory:e.subagentRunnerFactory,commandModules:e.commandModules,commandHostAdapters:e.commandHostAdapters,shellExec:e.shellExec,language:e.language,agentName:e.agentName,systemPrompt:e.systemPrompt,appendSystemPrompt:e.appendSystemPrompt,allowedTools:e.allowedTools,deniedTools:e.deniedTools})}createRegistry(){let t=new e;for(let e of this.opts.commandModules??[])t.addModule(e);return this.opts.reloadPluginCommandSource?.(t),t}onSubmit(e){this.submitHandler=e}write(e){}async requestAction(e){return new Promise(t=>{this.actionQueue.push({action:e,resolve:t}),this.processNextAction()})}setAvailableCommands(e){this.availableCommands=e,this.onChange?.()}setBusy(e){this.stateManager.onThinking(e)}async start(){this.sessionStarted||(this.sessionStarted=!0,this.wireSessionEvents(),this.syncRestoredHistory(),this.startInitCheck(),this.opts.transportRegistry&&await this.opts.transportRegistry.startAll(this.interactiveSession))}async stop(){this.onChange=null,this.sessionStarted=!1,this.stopInitCheck(),this.opts.transportRegistry&&await this.opts.transportRegistry.stopAll()}getSession(){return this.interactiveSession}getRegistry(){return this.registry}getCommandEffectQueue(){return this.commandEffectQueue}abort(){this.stateManager.setAborting(!0),this.interactiveSession.abort()}cancelQueue(){this.interactiveSession.cancelQueue(),this.stateManager.setPendingPrompt(null)}async shutdown(e){this.isShuttingDown||(this.isShuttingDown=!0,this.stateManager.addEntry(L(j(`Shutting down...`))),this.onChange?.(),await this.interactiveSession.shutdown({reason:e?.reason??`prompt_input_exit`,message:`CLI shutdown`}))}selectExecutionWorkspaceEntry(e){this.stateManager.selectExecutionWorkspaceEntry(e)}async readExecutionWorkspaceDetail(e){return this.interactiveSession.readExecutionWorkspaceDetail(e)}async sendAgentJob(e,t){await this.interactiveSession.sendAgentJob(e,t)}setSessionName(e){this.sessionName=e,this.interactiveSession.setName(e),this.onChange?.()}resolveAction(e){let t=this.actionQueue[0];t&&(this.actionQueue.shift(),this.processingAction=!1,this.pendingAction=null,this.onChange?.(),t.resolve(e),this.processNextAction())}async handleInput(e){if(!e.startsWith(`/`)){await this.interactiveSession.submit(e),this.stateManager.setPendingPrompt(this.interactiveSession.getPendingPrompt());return}await this.handleSlashCommand(e)}async handleSlashCommand(e){let t=e.slice(1).split(/\s+/),n=t[0]?.toLowerCase()??``,r=t.slice(1).join(` `),i=await this.interactiveSession.executeCommand(n,r);if(i){if(i.effects?.some(e=>e.type===`session-execution-started`)){this.stateManager.setPendingPrompt(this.interactiveSession.getPendingPrompt());return}hr(i,this.interactiveSession,this.registry,this.stateManager,this.commandEffectQueue,this.opts.reloadPluginCommandSource);return}this.stateManager.addEntry(L(j(`Unknown command "/${n}". Type /help for help.`)))}processNextAction(){if(this.processingAction)return;let e=this.actionQueue[0];if(!e){this.pendingAction=null,this.onChange?.();return}this.processingAction=!0,this.pendingAction=e.action,this.onChange?.()}handlePermissionRequest(e,t){return new Promise(n=>{this.permissionQueue.push({toolName:e,toolArgs:t,resolve:n}),this.processNextPermission()})}processNextPermission(){if(this.processingPermission)return;let e=this.permissionQueue[0];if(!e){this.permissionRequest=null,this.onChange?.();return}this.processingPermission=!0,this.permissionRequest={toolName:e.toolName,toolArgs:e.toolArgs,resolve:t=>{this.permissionQueue.shift(),this.processingPermission=!1,this.permissionRequest=null,e.resolve(t),setTimeout(()=>this.processNextPermission(),0)}},this.onChange?.()}wireSessionEvents(){let e=this.interactiveSession,t=this.stateManager;e.on(`user_message`,e=>{this.handleAutoNaming(e),t.addEntry(L(M(e)))}),e.on(`text_delta`,t.onTextDelta),e.on(`tool_start`,t.onToolStart),e.on(`tool_end`,t.onToolEnd),e.on(`thinking`,t.onThinking),e.on(`complete`,n=>{t.onComplete(n),t.syncHistory(e.getFullHistory())}),e.on(`interrupted`,t.onInterrupted),e.on(`error`,()=>{t.onError(),t.syncHistory(e.getFullHistory())}),e.on(`context_update`,t.onContextUpdate),e.on(`compact`,()=>{t.syncHistory(e.getFullHistory())}),e.on(`skill_activation`,()=>{t.syncHistory(e.getFullHistory())}),e.on(`execution_workspace_event`,e=>{t.syncExecutionWorkspaceSnapshot(e.snapshot)})}handleAutoNaming(e){this.autoNameTriggered||this.opts.sessionName||this.interactiveSession.getName()||(this.autoNameTriggered=!0,vr(this.opts.provider,e).then(e=>{this.interactiveSession.setName(e),this.sessionName=e,this.opts.onAutoNamed?.(e),this.onChange?.()}).catch(()=>{this.autoNameTriggered=!1}))}syncRestoredHistory(){if(this.stateManager.history.length===0){let e=this.interactiveSession.getFullHistory();e.length>0&&this.stateManager.syncHistory(e)}}startInitCheck(){this.initCheckInterval=setInterval(()=>{this.runInitCheck()},200)}runInitCheck(){try{let e=this.interactiveSession.getContextState();this.stateManager.setContextState({percentage:e.usedPercentage,usedTokens:e.usedTokens,maxTokens:e.maxTokens});let t=this.interactiveSession.getFullHistory();t.length>0&&this.stateManager.syncHistory(t),this.syncExecutionWorkspace(),this.stopInitCheck()}catch{}}stopInitCheck(){this.initCheckInterval!==null&&(clearInterval(this.initCheckInterval),this.initCheckInterval=null)}syncExecutionWorkspace(){try{this.stateManager.syncExecutionWorkspaceSnapshot(this.interactiveSession.getExecutionWorkspaceSnapshot({selectedEntryId:this.stateManager.selectedExecutionEntryId}))}catch{}}};async function Sr(e){process.on(`unhandledRejection`,e=>{process.stderr.write(`\n[UNHANDLED REJECTION] ${e}\n`),e instanceof Error&&process.stderr.write(`${e.stack}\n`)});let t=t=>new xr({cwd:e.cwd,provider:e.provider,permissionMode:e.permissionMode,maxTurns:e.maxTurns,sessionStore:e.sessionStore,resumeSessionId:t,forkSession:e.forkSession,sessionName:e.sessionName,backgroundTaskRunners:e.backgroundTaskRunners,subagentRunnerFactory:e.subagentRunnerFactory,commandModules:e.commandModules,commandHostAdapters:e.commandHostAdapters,shellExec:e.shellExec,transportRegistry:e.transportRegistry,language:e.language,reloadPluginCommandSource:e.reloadPluginCommandSource,agentName:e.agentName}),n=t(e.resumeSessionId);await _(z(fr,{cwd:e.cwd,channel:n,createChannel:t,providerOverride:e.providerOverride,providerType:e.providerType,modelId:e.modelId,permissionMode:e.permissionMode,version:e.version,sessionStore:e.sessionStore,resumeSessionId:e.resumeSessionId,showSessionPickerOnStart:e.showSessionPickerOnStart,startupUpdateNotice:e.startupUpdateNotice,transportRegistry:e.transportRegistry,cliAdapter:e.cliAdapter}),{exitOnCtrlC:!1}).waitUntilExit()}var Cr=class{name=`tui`;defaultEnabled=!0;optionsSchema={};options;constructor(e){this.options=e}attach(e){}async start(){await Sr(this.options)}async stop(){}validateOptions(e){return!0}};function wr({providerDefinitions:e,reloadPluginCommandSource:t}){return{getUserSettingsPath:()=>o(),readSettings:e=>u(e),writeSettings:(e,t)=>p(e,t),deleteSettings:e=>a(e),applyStatusLineSettings:(e,t)=>i(e,t),reloadPluginCommandSource:e=>{t(e)},applyActiveModelChange:(e,t,n)=>(r(e,t,n),{applied:!0}),getGitBranch:e=>d(e),getProviderDisplayName:t=>N(e,t)?.displayName??t}}export{Cr as n,Sr as r,wr as t};
25
- //# sourceMappingURL=tui-Bl-bm9iA.js.map
24
+ `}),B(g,{dimColor:!0,children:[` v`,e.version]})]},`logo`)}),W&&z(dr,{message:W}),B(m,{flexDirection:`column`,paddingX:1,flexGrow:1,children:[J&&J.kind!==`main_thread`?z(me,{entry:J,page:re,loading:se,error:ae}):z(Tn,{history:o}),p&&z(m,{marginBottom:1,children:z(g,{color:`yellow`,children:`Shutting down...`})}),(d||u.length>0)&&z(m,{flexDirection:`column`,marginBottom:1,children:z(sr,{text:c,activeTools:u,isThinking:d})}),z(fe,{entries:q})]}),G&&z(_e,{snapshot:b,selectedEntryId:x,onSelect:S,onClose:()=>K(!1)}),w&&z(Mn,{request:w}),X&&z(Lt,{prompt:X,onSubmit:xe,onCancel:Se}),Z&&z(Gn,{callbacks:H,onClose:()=>ve(!1),addMessage:e=>s(L(j(e.content)))}),$&&e.transportRegistry&&z(ur,{registry:e.transportRegistry,onClose:()=>be(!1)}),Q&&z(Kn,{sessions:l(e.sessionStore,e.cwd),onSelect:t=>{ye(!1),e.onSessionSwitch(t)},onCancel:()=>{ye(!1),s(L(j(`Session resume cancelled.`)))}}),z(pe,{percentage:E.percentage}),z(rr,{cwd:t,permissionMode:je,modelId:e.modelId,providerType:e.providerType,sessionId:Me,isThinking:d,activeToolCount:u.length,activeBackgroundTaskCount:ge,hasPendingPrompt:_!==null,contextState:E,sessionName:I,settings:le,activeAgentLabel:Te,gitRefreshToken:de}),z(kt,{onSubmit:Oe,onCancelQueue:P,isDisabled:!!w||Z||$||Q||G||p||X!==null||d&&!!_||!we,isAborting:f,pendingPrompt:_,registry:i,sessionName:I,history:o}),z(g,{children:` `})]})}var mr=class{queue=[];enqueueInteraction(e){this.queue.push({type:`interaction`,interaction:e})}enqueueEffects(e){e.length!==0&&this.queue.push({type:`effects`,effects:[...e]})}drain(){return this.queue.shift()}clear(){this.queue.length=0}};function hr(e,t,n,r,i,a){let o=gr(e.effects,n,r,a);if(r.addEntry(L(j(e.message))),e.interaction!==void 0&&i.enqueueInteraction(e.interaction),o.length>0&&i.enqueueEffects(o),t.isInitialized){let e=t.getContextState();r.setContextState({percentage:e.usedPercentage,usedTokens:e.usedTokens,maxTokens:e.maxTokens})}}function gr(e,t,n,r){if(e===void 0||e.length===0)return[];let i=[];for(let a of e){if(a.type===`conversation-history-cleared`){n.clearHistory();continue}if(a.type===`plugin-registry-reload-requested`){r?.(t);continue}i.push(a)}return i}function _r(e){return e.toLowerCase().replace(/[^a-z0-9\s-]/g,``).trim().replace(/\s+/g,`-`).replace(/-+/g,`-`).slice(0,60)}async function vr(e,t){let n=t.slice(0,200),r=await e.chat([j(`You generate short session titles. Respond with ONLY a 3-5 word lowercase-hyphenated title (e.g. refactor-auth-middleware). No explanation, no punctuation, no quotes.`),M(n)],{maxTokens:20}),i=_r(typeof r.content==`string`?r.content:``);return!i||i.length<3?_r(t):i}function yr(e,t){let n=null;return{schedule(){n||=setTimeout(()=>{n=null,e()},t)},flush(){n&&=(clearTimeout(n),null)}}}var br=class{history=[];streamingText=``;activeTools=[];isThinking=!1;isAborting=!1;pendingPrompt=null;contextState={percentage:0,usedTokens:0,maxTokens:0};executionWorkspaceSnapshot=null;selectedExecutionEntryId;onChange=null;streamBuf=``;debouncedStreamNotify=yr(()=>this.notify(),300);notify(){this.onChange?.()}onTextDelta=e=>{this.streamBuf+=e,this.streamingText=this.streamBuf,this.debouncedStreamNotify.schedule()};onToolStart=e=>{this.activeTools=[...this.activeTools,e],this.notify()};onToolEnd=e=>{let t=this.activeTools.findLastIndex(t=>t.toolName===e.toolName&&t.isRunning);if(t!==-1){let n=[...this.activeTools];n[t]=e,this.activeTools=n}this.notify()};onThinking=e=>{this.isThinking=e,e?(this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[]):(this.isAborting=!1,this.activeTools=[]),this.notify()};onComplete=e=>{this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[],this.contextState={percentage:e.contextState.usedPercentage,usedTokens:e.contextState.usedTokens,maxTokens:e.contextState.maxTokens},this.notify()};onInterrupted=()=>{this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[],this.notify()};onError=()=>{this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[],this.notify()};onContextUpdate=e=>{this.setContextState({percentage:e.usedPercentage,usedTokens:e.usedTokens,maxTokens:e.maxTokens})};syncHistory(e){e.length!==0&&(this.history=e.length>100?e.slice(-100):[...e],this.notify())}addEntry(e){let t=[...this.history,e];this.history=t.length>100?t.slice(-100):t,this.notify()}clearHistory(){this.history=[],this.debouncedStreamNotify.flush(),this.streamBuf=``,this.streamingText=``,this.activeTools=[],this.notify()}setPendingPrompt(e){this.pendingPrompt=e,this.notify()}setAborting(e){this.isAborting=e,this.notify()}setContextState(e){this.contextState=e,this.notify()}syncExecutionWorkspaceSnapshot(e){let t=this.selectedExecutionEntryId,n=t!==void 0&&e.entries.some(e=>e.id===t)?t:e.selectedEntryId??e.entries[0]?.id;this.executionWorkspaceSnapshot={...e,...n?{selectedEntryId:n}:{}},this.selectedExecutionEntryId=n,this.notify()}selectExecutionWorkspaceEntry(e){this.executionWorkspaceSnapshot?.entries.some(t=>t.id===e)&&(this.selectedExecutionEntryId=e,this.executionWorkspaceSnapshot={...this.executionWorkspaceSnapshot,selectedEntryId:e},this.notify())}},xr=class{stateManager;interactiveSession;registry;commandEffectQueue;opts;submitHandler=null;actionQueue=[];processingAction=!1;permissionRequest=null;pendingAction=null;availableCommands=[];isShuttingDown=!1;sessionName;autoNameTriggered=!1;sessionStarted=!1;initCheckInterval=null;permissionQueue=[];processingPermission=!1;onChange=null;constructor(e){this.opts=e,this.sessionName=e.sessionName,this.stateManager=new br,this.stateManager.onChange=()=>this.onChange?.(),this.interactiveSession=this.createSession(),this.registry=this.createRegistry(),this.commandEffectQueue=new mr}createSession(){let e=this.opts;return new n({cwd:e.cwd,provider:e.provider,permissionMode:e.permissionMode,maxTurns:e.maxTurns,permissionHandler:(e,t)=>this.handlePermissionRequest(e,t),sessionStore:e.sessionStore,resumeSessionId:e.resumeSessionId,forkSession:e.forkSession,sessionName:e.sessionName,backgroundTaskRunners:e.backgroundTaskRunners,subagentRunnerFactory:e.subagentRunnerFactory,commandModules:e.commandModules,commandHostAdapters:e.commandHostAdapters,shellExec:e.shellExec,language:e.language,agentName:e.agentName,systemPrompt:e.systemPrompt,appendSystemPrompt:e.appendSystemPrompt,allowedTools:e.allowedTools,deniedTools:e.deniedTools})}createRegistry(){let t=new e;for(let e of this.opts.commandModules??[])t.addModule(e);return this.opts.reloadPluginCommandSource?.(t),t}onSubmit(e){this.submitHandler=e}write(e){}async requestAction(e){return new Promise(t=>{this.actionQueue.push({action:e,resolve:t}),this.processNextAction()})}setAvailableCommands(e){this.availableCommands=e,this.onChange?.()}setBusy(e){this.stateManager.onThinking(e)}async start(){this.sessionStarted||(this.sessionStarted=!0,this.wireSessionEvents(),this.syncRestoredHistory(),this.startInitCheck(),this.opts.transportRegistry&&await this.opts.transportRegistry.startAll(this.interactiveSession))}async stop(){this.onChange=null,this.sessionStarted=!1,this.stopInitCheck(),this.opts.transportRegistry&&await this.opts.transportRegistry.stopAll()}getSession(){return this.interactiveSession}getRegistry(){return this.registry}getCommandEffectQueue(){return this.commandEffectQueue}abort(){this.stateManager.setAborting(!0),this.interactiveSession.abort()}cancelQueue(){this.interactiveSession.cancelQueue(),this.stateManager.setPendingPrompt(null)}async shutdown(e){this.isShuttingDown||(this.isShuttingDown=!0,this.stateManager.addEntry(L(j(`Shutting down...`))),this.onChange?.(),await this.interactiveSession.shutdown({reason:e?.reason??`prompt_input_exit`,message:`CLI shutdown`}))}selectExecutionWorkspaceEntry(e){this.stateManager.selectExecutionWorkspaceEntry(e)}async readExecutionWorkspaceDetail(e){return this.interactiveSession.readExecutionWorkspaceDetail(e)}async sendAgentJob(e,t){await this.interactiveSession.sendAgentJob(e,t)}setSessionName(e){this.sessionName=e,this.interactiveSession.setName(e),this.onChange?.()}resolveAction(e){let t=this.actionQueue[0];t&&(this.actionQueue.shift(),this.processingAction=!1,this.pendingAction=null,this.onChange?.(),t.resolve(e),this.processNextAction())}async handleInput(e){if(!e.startsWith(`/`)){await this.interactiveSession.submit(e),this.stateManager.setPendingPrompt(this.interactiveSession.getPendingPrompt());return}await this.handleSlashCommand(e)}async handleSlashCommand(e){let t=e.slice(1).split(/\s+/),n=t[0]?.toLowerCase()??``,r=t.slice(1).join(` `),i=await this.interactiveSession.executeCommand(n,r);if(i){if(i.effects?.some(e=>e.type===`session-execution-started`)){this.stateManager.setPendingPrompt(this.interactiveSession.getPendingPrompt());return}hr(i,this.interactiveSession,this.registry,this.stateManager,this.commandEffectQueue,this.opts.reloadPluginCommandSource);return}this.stateManager.addEntry(L(j(`Unknown command "/${n}". Type /help for help.`)))}processNextAction(){if(this.processingAction)return;let e=this.actionQueue[0];if(!e){this.pendingAction=null,this.onChange?.();return}this.processingAction=!0,this.pendingAction=e.action,this.onChange?.()}handlePermissionRequest(e,t){return new Promise(n=>{this.permissionQueue.push({toolName:e,toolArgs:t,resolve:n}),this.processNextPermission()})}processNextPermission(){if(this.processingPermission)return;let e=this.permissionQueue[0];if(!e){this.permissionRequest=null,this.onChange?.();return}this.processingPermission=!0,this.permissionRequest={toolName:e.toolName,toolArgs:e.toolArgs,resolve:t=>{this.permissionQueue.shift(),this.processingPermission=!1,this.permissionRequest=null,e.resolve(t),setTimeout(()=>this.processNextPermission(),0)}},this.onChange?.()}wireSessionEvents(){let e=this.interactiveSession,t=this.stateManager;e.on(`user_message`,e=>{this.handleAutoNaming(e),t.addEntry(L(M(e)))}),e.on(`text_delta`,t.onTextDelta),e.on(`tool_start`,t.onToolStart),e.on(`tool_end`,t.onToolEnd),e.on(`thinking`,t.onThinking),e.on(`complete`,n=>{t.onComplete(n),t.syncHistory(e.getFullHistory())}),e.on(`interrupted`,t.onInterrupted),e.on(`error`,()=>{t.onError(),t.syncHistory(e.getFullHistory())}),e.on(`context_update`,t.onContextUpdate),e.on(`compact`,()=>{t.syncHistory(e.getFullHistory())}),e.on(`skill_activation`,()=>{t.syncHistory(e.getFullHistory())}),e.on(`execution_workspace_event`,e=>{t.syncExecutionWorkspaceSnapshot(e.snapshot)})}handleAutoNaming(e){this.autoNameTriggered||this.opts.sessionName||this.interactiveSession.getName()||(this.autoNameTriggered=!0,vr(this.opts.provider,e).then(e=>{this.interactiveSession.setName(e),this.sessionName=e,this.opts.onAutoNamed?.(e),this.onChange?.()}).catch(()=>{this.autoNameTriggered=!1}))}syncRestoredHistory(){if(this.stateManager.history.length===0){let e=this.interactiveSession.getFullHistory();e.length>0&&this.stateManager.syncHistory(e)}}startInitCheck(){this.initCheckInterval=setInterval(()=>{this.runInitCheck()},200)}runInitCheck(){try{let e=this.interactiveSession.getContextState();this.stateManager.setContextState({percentage:e.usedPercentage,usedTokens:e.usedTokens,maxTokens:e.maxTokens});let t=this.interactiveSession.getFullHistory();t.length>0&&this.stateManager.syncHistory(t),this.syncExecutionWorkspace(),this.stopInitCheck()}catch{}}stopInitCheck(){this.initCheckInterval!==null&&(clearInterval(this.initCheckInterval),this.initCheckInterval=null)}syncExecutionWorkspace(){try{this.stateManager.syncExecutionWorkspaceSnapshot(this.interactiveSession.getExecutionWorkspaceSnapshot({selectedEntryId:this.stateManager.selectedExecutionEntryId}))}catch{}}};async function Sr(e){process.on(`unhandledRejection`,e=>{process.stderr.write(`\n[UNHANDLED REJECTION] ${e}\n`),e instanceof Error&&process.stderr.write(`${e.stack}\n`)});let t=t=>new xr({cwd:e.cwd,provider:e.provider,permissionMode:e.permissionMode,maxTurns:e.maxTurns,sessionStore:e.sessionStore,resumeSessionId:t,forkSession:e.forkSession,sessionName:e.sessionName,backgroundTaskRunners:e.backgroundTaskRunners,subagentRunnerFactory:e.subagentRunnerFactory,commandModules:e.commandModules,commandHostAdapters:e.commandHostAdapters,shellExec:e.shellExec,transportRegistry:e.transportRegistry,language:e.language,reloadPluginCommandSource:e.reloadPluginCommandSource,agentName:e.agentName}),n=t(e.resumeSessionId);await _(z(fr,{cwd:e.cwd,channel:n,createChannel:t,providerOverride:e.providerOverride,providerType:e.providerType,modelId:e.modelId,permissionMode:e.permissionMode,version:e.version,sessionStore:e.sessionStore,resumeSessionId:e.resumeSessionId,showSessionPickerOnStart:e.showSessionPickerOnStart,startupUpdateNotice:e.startupUpdateNotice,transportRegistry:e.transportRegistry,cliAdapter:e.cliAdapter}),{exitOnCtrlC:!1}).waitUntilExit()}var Cr=class{name=`tui`;defaultEnabled=!0;optionsSchema={};options;constructor(e){this.options=e}attach(e){}async start(){await Sr(this.options)}async stop(){}validateOptions(e){return!0}};function wr({providerDefinitions:e,reloadPluginCommandSource:t}){return{getUserSettingsPath:()=>o(),readSettings:e=>u(e),writeSettings:(e,t)=>p(e,t),deleteSettings:e=>a(e),applyStatusLineSettings:(e,t)=>i(e,t),reloadPluginCommandSource:e=>{t(e)},applyActiveModelChange:(e,t,n)=>(r(e,t,n),{applied:!0}),getGitBranch:e=>d(e),getProviderDisplayName:t=>N(e,t)?.displayName??t}}export{Cr as n,Sr as r,wr as t};
25
+ //# sourceMappingURL=tui-4hA-SMtS.js.map