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

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-re-S-CGS.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-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,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-Cf1-zocr.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-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};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../tui-re-S-CGS.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-DULGN7sr.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-Cf1-zocr.js";export{e as TuiTransport,n as createDefaultTuiCliAdapter,t as renderApp};
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};
@@ -15,11 +15,11 @@ import{CommandRegistry as e,DEFAULT_STATUS_LINE_COMMAND_SETTINGS as t,Interactiv
15
15
 
16
16
  _(interrupted)_`:``)):t})})]})});function Sn({entry:e}){let t=e.data,n=t?.tools,r=t?.summary?.split(`
17
17
  `)??[];return n&&n.length>0?B(m,{flexDirection:`column`,marginBottom:1,children:[z(m,{children:B(g,{color:`white`,bold:!0,children:[`Tool:`,` `]})}),z(g,{children:` `}),n.map((e,t)=>B(m,{flexDirection:`column`,children:[B(g,{color:_n(e),children:[` `,vn(e)]}),z(cn,{tool:e}),e.diffLines&&e.diffLines.length>0&&z(pn,{file:e.diffFile,lines:e.diffLines})]},t))]}):B(m,{flexDirection:`column`,marginBottom:1,children:[z(m,{children:B(g,{color:`white`,bold:!0,children:[`Tool:`,` `]})}),z(g,{children:` `}),r.map((e,t)=>B(g,{color:`green`,children:[` `,e]},t))]})}function Cn({entry:e}){let t=e.data,n=typeof t?.message==`string`?t.message:typeof t?.content==`string`?t.content:e.type;return B(m,{flexDirection:`column`,marginBottom:1,children:[z(m,{children:B(g,{color:`yellow`,bold:!0,children:[`System:`,` `]})}),z(g,{children:` `}),z(m,{marginLeft:2,children:z(g,{wrap:`wrap`,children:n})})]})}function wn({entry:e}){if(e.category===`chat`){let t=e.data;return z(xn,{message:t})}return e.type===`tool-summary`?z(Sn,{entry:e}):e.type===`usage-summary`?z(mn,{entry:e}):e.type===`tool-start`||e.type===`tool-end`?z(R,{}):z(Cn,{entry:e})}function Tn({history:e}){return z(m,{flexDirection:`column`,children:e.map(e=>z(wn,{entry:e},e.id))})}const En=[`Allow [y]`,`Allow always (this session) [s]`,`Allow always (this project) [p]`,`Deny [n]`];function Dn(e,t){let n=J({...t,escape:!1});if(n!==void 0)return n;if(e===`y`||e===`1`)return{type:`shortcut`,index:0};if(e===`s`||e===`a`||e===`2`)return{type:`shortcut`,index:1};if(e===`p`||e===`3`)return{type:`shortcut`,index:2};if(e===`n`||e===`d`||e===`4`)return{type:`shortcut`,index:3}}function On(e,t){if(e.resolved)return{state:e,effect:{type:`none`}};if(typeof t!=`string`)return An(e,t.index);let n=Y(e,t,{itemCount:En.length});return n.effect.type===`select`?{state:n.state,effect:{type:`resolve`,decision:kn(n.effect.index)}}:{state:n.state,effect:{type:`none`}}}function kn(e){return e===0?!0:e===1?`allow-session`:e===2?`allow-project`:!1}function An(e,t){return{state:{...e,selectedIndex:t,resolved:!0},effect:{type:`resolve`,decision:kn(t)}}}function jn(e){let t=Object.entries(e);return t.length===0?`(no arguments)`:t.map(([e,t])=>`${e}: ${typeof t==`string`?t:JSON.stringify(t)}`).join(`, `)}function Mn({request:e}){let[t,n]=C.useState(()=>q()),r=C.useRef(t),i=C.useRef(e);if(i.current!==e){i.current=e;let t=q();r.current=t,n(t)}let a=C.useCallback(t=>{let i=On(r.current,t);r.current=i.state,n(i.state),i.effect.type===`resolve`&&e.resolve(i.effect.decision)},[e]);return y((e,t)=>{let n=Dn(e,t);n!==void 0&&a(n)}),B(m,{flexDirection:`column`,borderStyle:`round`,borderColor:`yellow`,paddingX:1,children:[z(g,{color:`yellow`,bold:!0,children:`[Permission Required]`}),B(g,{children:[`Tool:`,` `,z(g,{color:`cyan`,bold:!0,children:e.toolName})]}),B(g,{dimColor:!0,children:[` `,jn(e.toolArgs)]}),z(m,{marginTop:1,children:En.map((e,n)=>z(m,{marginRight:2,children:B(g,{color:n===t.selectedIndex?`cyan`:void 0,bold:n===t.selectedIndex,children:[n===t.selectedIndex?`> `:` `,e]})},e))}),z(g,{dimColor:!0,children:` left/right to select, Enter to confirm`})]})}function Nn(e,t,n){let r=J({...t,escape:!1});if(r!==void 0)return r;if(n===2&&e===`y`)return{type:`shortcut`,index:0};if(n===2&&e===`n`)return{type:`shortcut`,index:1}}function Pn(e,t,n){return e.resolved?{state:e,effect:{type:`none`}}:typeof t==`string`?Y(e,t,{itemCount:n}):{state:{...e,selectedIndex:t.index,resolved:!0},effect:{type:`select`,index:t.index}}}function Fn({message:e,options:t=[`Yes`,`No`],onSelect:n}){let[r,i]=A(()=>q()),a=k(r),o=T(e=>{let r=Pn(a.current,e,t.length);a.current=r.state,i(r.state),r.effect.type===`select`&&n(r.effect.index)},[n,t.length]);return y((e,n)=>{let r=Nn(e,n,t.length);r!==void 0&&o(r)}),B(m,{flexDirection:`column`,borderStyle:`round`,borderColor:`yellow`,paddingX:1,children:[z(g,{color:`yellow`,children:e}),z(m,{marginTop:1,children:t.map((e,t)=>z(m,{marginRight:2,children:B(g,{color:t===r.selectedIndex?`cyan`:void 0,bold:t===r.selectedIndex,children:[t===r.selectedIndex?`> `:` `,e]})},e))}),z(g,{dimColor:!0,children:` arrow keys to select, Enter to confirm`})]})}function In(e,t,n,r,i){let[a,o]=A([]),[s,c]=A(!1),[l,u]=A();return D(()=>{if(o([]),u(void 0),e===`marketplace-list`)c(!0),n.marketplaceList().then(e=>{let t=[{label:`Add Marketplace`,value:`__add__`}],n=e.map(e=>({label:e.name,value:e.name,hint:e.type}));o([...t,...n]),c(!1)}).catch(e=>{u(e instanceof Error?e.message:String(e)),c(!1)});else if(e===`marketplace-browse`){let e=t??``;c(!0),n.listAvailablePlugins(e).then(e=>{o(e.map(e=>({label:e.name,value:e.name,hint:e.installed?`installed`:e.description}))),c(!1)}).catch(e=>{u(e instanceof Error?e.message:String(e)),c(!1)})}else e===`installed-list`&&(c(!0),n.listInstalled().then(e=>{o(e.map(e=>({label:e.name,value:e.name,hint:e.description}))),c(!1)}).catch(e=>{u(e instanceof Error?e.message:String(e)),c(!1)}))},[i,e,t,n,r]),{items:a,loading:s,error:l}}function Ln({title:e,items:t,onSelect:n,onBack:r,loading:i,error:a}){let[o,s]=A(()=>q()),c=k(o),l=!i&&!a,u=T(e=>{let i=Y(c.current,e,{itemCount:t.length,enabled:l});if(c.current=i.state,s(i.state),i.effect.type===`cancel`)r();else if(i.effect.type===`select`){let e=t[i.effect.index];e!==void 0&&n(e.value)}},[l,t,r,n]);y((e,t)=>{let n=ge(t);n!==void 0&&u(n)});let d=X(o,{itemCount:t.length});d!==o&&(c.current=d);let f=d.selectedIndex;return B(m,{flexDirection:`column`,borderStyle:`round`,borderColor:`yellow`,paddingX:1,children:[z(g,{color:`yellow`,bold:!0,children:e}),i&&z(m,{marginTop:1,children:z(g,{dimColor:!0,children:`Loading...`})}),a&&B(m,{marginTop:1,flexDirection:`column`,children:[z(g,{color:`red`,children:a}),z(g,{dimColor:!0,children:`Press Esc to go back`})]}),!i&&!a&&z(m,{flexDirection:`column`,marginTop:1,children:t.map((e,t)=>B(m,{children:[B(g,{color:t===f?`cyan`:void 0,bold:t===f,children:[t===f?`> `:` `,e.label]}),e.hint&&B(g,{dimColor:!0,children:[` `,e.hint]})]},e.value))}),z(g,{dimColor:!0,children:i||a?``:` ↑↓ Navigate Enter Select Esc Back`})]})}function Rn(e,t){e===`marketplace`?t.push({screen:`marketplace-list`}):e===`installed`&&t.push({screen:`installed-list`})}function zn(e,t){e===`__add__`?t.push({screen:`marketplace-add`}):t.push({screen:`marketplace-action`,context:{marketplace:e}})}function Bn(e,t,n,r){e===`browse`?r.push({screen:`marketplace-browse`,context:{marketplace:t}}):e===`update`?n.marketplaceUpdate(t).then(()=>{r.notify(`Updated marketplace "${t}".`),r.pop()}).catch(e=>{r.notify(`Error: ${e instanceof Error?e.message:String(e)}`)}):e===`remove`&&r.setConfirm({message:`Remove marketplace "${t}" and all its plugins?`,onConfirm:()=>{r.setConfirm(void 0),n.marketplaceRemove(t).then(()=>{r.notify(`Removed marketplace "${t}".`),r.popN(2)}).catch(e=>{r.notify(`Error: ${e instanceof Error?e.message:String(e)}`)})},onCancel:()=>r.setConfirm(void 0)})}function Vn(e,t,n,r){let i=`${e}@${t}`;n.find(t=>t.value===e)?.hint===`installed`?r.push({screen:`installed-action`,context:{pluginId:i}}):r.push({screen:`marketplace-install-scope`,context:{marketplace:t,pluginId:i}})}function Hn(e,t,n,r){let i=e;n.install(t,i).then(()=>{r.notify(`Installed plugin "${t}" (${i} scope).`),r.popN(2)}).catch(e=>{r.notify(`Error: ${e instanceof Error?e.message:String(e)}`)})}function Un(e,t,n){n.setConfirm({message:`Uninstall plugin "${e}"?`,onConfirm:()=>{n.setConfirm(void 0),t.uninstall(e).then(()=>{n.notify(`Uninstalled plugin "${e}".`),n.refresh()}).catch(e=>{n.notify(`Error: ${e instanceof Error?e.message:String(e)}`)})},onCancel:()=>n.setConfirm(void 0)})}function Wn(e,t,n,r){e===`uninstall`&&r.setConfirm({message:`Uninstall plugin "${t}"?`,onConfirm:()=>{r.setConfirm(void 0),n.uninstall(t).then(()=>{r.notify(`Uninstalled plugin "${t}".`),r.popN(2)}).catch(e=>{r.notify(`Error: ${e instanceof Error?e.message:String(e)}`)})},onCancel:()=>r.setConfirm(void 0)})}function Gn({callbacks:e,onClose:t,addMessage:n}){let[r,i]=A([{screen:`main`}]),[a,o]=A(),[s,c]=A(0),l=r[r.length-1]??{screen:`main`},u=T(e=>{i(t=>[...t,e])},[]),d=T(()=>{i(e=>e.length<=1?(t(),e):e.slice(0,-1))},[t]),f=T(e=>{i(n=>{let r=n.slice(0,Math.max(1,n.length-e));return r.length===0?(t(),n):r})},[t]),p=T(e=>{n?.({role:`system`,content:e})},[n]),m=T(()=>{c(e=>e+1)},[]),h=T(e=>o(e),[o]),g={push:T(e=>u({screen:e.screen,context:e.context}),[u]),pop:d,popN:f,notify:p,setConfirm:h,refresh:m},{items:_,loading:v,error:y}=In(l.screen,l.context?.marketplace,e,s,r.length),b=T(t=>{let n=l.screen,r=l.context;n===`main`?Rn(t,g):n===`marketplace-list`?zn(t,g):n===`marketplace-action`?Bn(t,r?.marketplace??``,e,g):n===`marketplace-browse`?Vn(t,r?.marketplace??``,_,g):n===`marketplace-install-scope`?Hn(t,r?.pluginId??``,e,g):n===`installed-list`?Un(t,e,g):n===`installed-action`&&Wn(t,r?.pluginId??``,e,g)},[l,_,e,u,d,f,p,o,m]),x=T(t=>{l.screen===`marketplace-add`&&e.marketplaceAdd(t).then(e=>{p(`Added marketplace "${e}" from ${t}.`),d()}).catch(e=>{p(`Error: ${e instanceof Error?e.message:String(e)}`),d()})},[l.screen,e,p,d]);if(a)return z(Fn,{message:a.message,onSelect:e=>{e===0?a.onConfirm():a.onCancel()}});let S=l.screen;return S===`marketplace-add`?z(Ft,{title:`Add Marketplace Source`,placeholder:`owner/repo or git URL`,onSubmit:x,onCancel:d,validate:e=>e.includes(`/`)?void 0:`Must be owner/repo or a git URL`}):S===`marketplace-action`?z(Ln,{title:`Marketplace: ${l.context?.marketplace??``}`,items:[{label:`Browse plugins`,value:`browse`},{label:`Update`,value:`update`},{label:`Remove`,value:`remove`}],onSelect:b,onBack:d},r.length):S===`marketplace-install-scope`?z(Ln,{title:`Install scope for "${l.context?.pluginId??``}"`,items:[{label:`User scope`,value:`user`},{label:`Project scope`,value:`project`}],onSelect:b,onBack:d},r.length):S===`installed-action`?z(Ln,{title:`Plugin: ${l.context?.pluginId??``}`,items:[{label:`Uninstall`,value:`uninstall`}],onSelect:b,onBack:d},r.length):z(Ln,{title:{main:`Plugin Management`,"marketplace-list":`Marketplace`,"marketplace-browse":`Browse: ${l.context?.marketplace??``}`,"installed-list":`Installed Plugins`}[S]??`Plugin Management`,items:{main:[{label:`Marketplace`,value:`marketplace`},{label:`Installed Plugins`,value:`installed`}]}[S]??_,onSelect:b,onBack:d,loading:v,error:y},`${S}-${r.length}-${s}`)}function Kn({sessions:e,onSelect:t,onCancel:n}){return B(m,{flexDirection:`column`,paddingX:1,marginBottom:1,children:[z(g,{bold:!0,color:`cyan`,children:`Select a session to resume (ESC to cancel):`}),z(At,{items:[...e],renderItem:(e,t)=>{let n=e.preview?e.preview.slice(0,60)+(e.preview.length>60?`...`:``):``;return B(g,{children:[t?`> `:` `,z(g,{bold:!0,children:e.name??e.id.slice(0,8)}),` `,z(g,{dimColor:!0,children:new Date(e.updatedAt).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}),` `,B(g,{dimColor:!0,children:[`msgs: `,e.messageCount]}),n?B(R,{children:[`
18
- `,z(g,{color:`gray`,children:n})]}):null]})},onSelect:e=>t(e.id),onCancel:n})]})}function qn(e){let t=Jn(e),n=e.hasPendingPrompt&&t.kind!==`queued`?[`queued`]:[],r=[t.label,...n].join(` · `);return{...t,segments:n,text:r}}function Jn(e){return e.activeToolCount>0?{kind:`tools`,label:`Tools x${e.activeToolCount}`,color:`cyan`}:e.isThinking?{kind:`thinking`,label:`Thinking`,color:`yellow`}:e.activeBackgroundTaskCount>0?{kind:`background`,label:`Background x${e.activeBackgroundTaskCount}`,color:`cyan`}:e.hasPendingPrompt?{kind:`queued`,label:`Queued`,color:`yellow`}:{kind:`idle`,label:`Idle`,color:`gray`}}function Yn(e){return e>=90?`red`:e>=70?`yellow`:`green`}function Xn({isThinking:e,activeToolCount:t,activeBackgroundTaskCount:n,hasPendingPrompt:r}){let i=qn({isThinking:e,activeToolCount:t,activeBackgroundTaskCount:n,hasPendingPrompt:r});return z(g,{color:i.color,bold:i.kind!==`idle`,children:i.text})}function Zn({percentage:e,usedTokens:t,maxTokens:n}){return B(g,{color:Yn(e),children:[`Context: `,Math.round(e),`% (`,P(t),`/`,P(n),` tokens)`]})}function Qn({permissionMode:e}){return B(R,{children:[z(g,{color:`cyan`,bold:!0,children:`Mode:`}),` `,z(g,{children:e})]})}function $n(e){return e!==`default`}function er({modelName:e,providerDisplayName:t}){return t===void 0?z(g,{dimColor:!0,children:e}):B(g,{dimColor:!0,children:[t,` `,e]})}function tr(e){let t=e.showGitBranch&&e.gitBranch!==void 0&&e.gitBranch.length>0,n=$n(e.permissionMode);return B(g,{children:[z(Xn,{isThinking:e.isThinking,activeToolCount:e.activeToolCount,activeBackgroundTaskCount:e.activeBackgroundTaskCount,hasPendingPrompt:e.hasPendingPrompt}),n&&B(R,{children:[` | `,z(Qn,{permissionMode:e.permissionMode})]}),e.sessionName&&B(R,{children:[` | `,z(g,{color:`magenta`,children:e.sessionName})]}),t&&B(R,{children:[` | `,B(g,{dimColor:!0,children:[`git: `,e.gitBranch]})]}),` | `,z(er,{modelName:e.modelName,providerDisplayName:e.providerDisplayName}),` | `,z(Zn,{percentage:e.contextPercentage,usedTokens:e.contextUsedTokens,maxTokens:e.contextMaxTokens})]})}function nr({permissionMode:e,modelName:t,providerDisplayName:n,sessionId:r,isThinking:i,activeToolCount:a=0,activeBackgroundTaskCount:o=0,hasPendingPrompt:s=!1,contextPercentage:c,contextUsedTokens:l,contextMaxTokens:u,sessionName:d,gitBranch:f,showGitBranch:p=!0,activeAgentLabel:h}){return B(m,{borderStyle:`single`,borderColor:`gray`,paddingLeft:1,paddingRight:1,justifyContent:`space-between`,children:[z(tr,{permissionMode:e,modelName:t,providerDisplayName:n,isThinking:i,activeToolCount:a,activeBackgroundTaskCount:o,hasPendingPrompt:s,contextPercentage:c,contextUsedTokens:l,contextMaxTokens:u,sessionName:d,gitBranch:f,showGitBranch:p}),h!==void 0&&B(g,{color:`yellow`,bold:!0,children:[`[`,h,`]`]})]})}function rr({cwd:e,permissionMode:t,modelId:n,providerType:r,sessionId:i,isThinking:a,activeToolCount:o,activeBackgroundTaskCount:s,hasPendingPrompt:c,contextState:l,sessionName:u,settings:d,activeAgentLabel:f,gitRefreshToken:p}){let m=ke(),h=O(()=>m.getGitBranch(e),[m,e,p]),g=O(()=>r===void 0?void 0:m.getProviderDisplayName(r),[m,r]);return d.enabled?z(nr,{permissionMode:t,modelName:n??``,providerDisplayName:g,sessionId:i,isThinking:a,activeToolCount:o,activeBackgroundTaskCount:s,hasPendingPrompt:c,contextPercentage:l.percentage,contextUsedTokens:l.usedTokens,contextMaxTokens:l.maxTokens,sessionName:u,gitBranch:h,showGitBranch:d.gitBranch,activeAgentLabel:f}):null}function ir(e){return e.isRunning?{color:`yellow`,icon:`⟳`,strikethrough:!1}:e.result===`error`?{color:`red`,icon:`✗`,strikethrough:!0}:e.result===`denied`?{color:`yellowBright`,icon:`⊘`,strikethrough:!0}:{color:`green`,icon:`✓`,strikethrough:!1}}function ar(e){return e?z(m,{marginBottom:1,children:z(g,{color:`yellow`,children:`Thinking...`})}):z(R,{})}function or(e){return B(m,{flexDirection:`column`,marginBottom:1,children:[z(g,{color:`white`,bold:!0,children:`Tools:`}),z(g,{children:` `}),e.map((e,t)=>{let{color:n,icon:r,strikethrough:i}=ir(e);return B(m,{flexDirection:`column`,children:[B(g,{color:n,strikethrough:i,children:[` `,r,` `,e.toolName,`(`,e.firstArg,`)`]}),e.diffLines&&e.diffLines.length>0&&z(pn,{file:e.diffFile,lines:e.diffLines})]},`${e.toolName}-${t}`)})]})}function sr({text:e,activeTools:t,isThinking:n=!1}){let r=t.length>0,i=e.length>0;return!r&&!i?ar(n):B(m,{flexDirection:`column`,children:[r&&or(t),i&&B(m,{flexDirection:`column`,marginBottom:1,children:[z(g,{color:`cyan`,bold:!0,children:`Robota:`}),z(g,{children:` `}),z(m,{marginLeft:2,children:z(g,{wrap:`wrap`,children:sn(e)})})]})]})}function cr({entry:e,selected:t}){let n=e.config.enabled,r=n?`●`:`○`,i=n?`[enabled] `:`[disabled]`,a=e.config.options?.port,o=typeof a==`number`?`port: ${a}`:``;return z(m,{children:z(g,{color:t?`cyan`:void 0,bold:t,children:`${r} ${e.transport.name.padEnd(18)} ${i} ${o}`})})}function lr(e,t,n,r,i,a,o,s){y(T((c,l)=>{if(!n){if(l.upArrow){i(e=>Math.max(0,e-1));return}if(l.downArrow){i(t=>Math.min(e.length-1,t+1));return}if(l.escape||l.return){o();return}if(c===` `){let n=e[t];if(!n)return;a(!0),r.setEnabled(n.transport.name,!n.config.enabled).then(()=>{s(),a(!1)}).catch(()=>a(!1))}}},[n,e,t,r,o,s,i,a]))}function ur({registry:e,onClose:t}){let[n,r]=A(()=>e.getAll()),[i,a]=A(0),[o,s]=A(!1);return lr(n,i,o,e,a,s,t,T(()=>{r(e.getAll())},[e])),B(m,{flexDirection:`column`,paddingX:2,paddingY:1,children:[z(g,{bold:!0,children:`Settings › Transports`}),z(m,{marginTop:1,flexDirection:`column`,children:n.map((e,t)=>z(cr,{entry:e,selected:t===i},e.transport.name))}),z(m,{marginTop:1,children:z(g,{dimColor:!0,children:`↑↓ select space toggle enter/esc close`})}),o&&z(m,{marginTop:1,children:z(g,{color:`yellow`,children:`Saving…`})})]})}function dr({message:e}){return z(m,{paddingX:1,marginBottom:1,children:z(g,{color:`yellow`,children:e})})}function fr(e){let[t,n]=A(e.resumeSessionId),[r,i]=A(e.showSessionPickerOnStart??!1);return z(Oe,{value:e.cliAdapter,children:z(pr,{...e,showSessionPickerOnStart:r,resumeSessionId:t,onSessionSwitch:e=>{i(!1),n(e)}},t??`__new__`)})}function pr(e){let t=e.cwd,{channel:n}=e,{interactiveSession:r,registry:i,commandEffectQueue:a,history:o,addEntry:s,streamingText:c,activeTools:u,isThinking:d,isAborting:f,isShuttingDown:p,pendingPrompt:_,executionWorkspaceSnapshot:b,selectedExecutionEntryId:x,selectExecutionWorkspaceEntry:S,readExecutionWorkspaceDetail:C,permissionRequest:w,contextState:E,handleSubmit:M,handleAbort:N,handleCancelQueue:P,handleShutdown:F}=Pe(n),[I,R]=A(n.sessionName),V=Ce(t),H=r?void 0:V,{exit:U}=v(),[W,ee]=A(),[G,K]=A(!1),[re,ie]=A(null),[ae,oe]=A(),[se,ce]=A(!1),[le,ue]=Ne(),[de,he]=A(0),q=O(()=>te(b),[b]),ge=ne(b),J=O(()=>b?.entries.find(e=>e.id===x),[b,x]),{handleSubmit:Y,pendingInteractionPrompt:X,showPluginTUI:Z,showSessionPicker:Q,showTransportTUI:$,setShowPluginTUI:ve,setShowSessionPicker:ye,setShowTransportTUI:be,handleInteractionSubmit:xe,handleInteractionCancel:Se}=Ae({cwd:t,providerOverride:e.providerOverride,interactiveSession:r,commandEffectQueue:a,addEntry:s,baseHandleSubmit:M,setSessionName:R,setStatusLineSettings:ue,showSessionPickerOnStart:e.showSessionPickerOnStart,openAgentSwitcher:()=>K(!0)});D(()=>(n.start(),()=>{n.stop()}),[n]);let we=!J||J.kind===`main_thread`||J.controls.includes(`send`),Te=J&&J.kind!==`main_thread`?J.title:void 0,Ee=O(()=>b?.entries.find(e=>e.kind===`main_thread`)?.id,[b]),De=T(async e=>{J&&J.kind!==`main_thread`&&J.controls.includes(`send`)?await r.sendAgentJob(J.sourceId,e):await Y(e)},[J,Y,r]),Oe=T(async e=>{he(e=>e+1),await De(e)},[De]),ke=k(!1);D(()=>{ke.current&&!d&&he(e=>e+1),ke.current=d},[d]),D(()=>{let e=r?.getName?.();e&&!I&&R(e)},[r,I]),D(()=>{let t=!0;return e.startupUpdateNotice?.then(e=>{t&&e!==void 0&&ee(e)}).catch(()=>{}),()=>{t=!1}},[e.startupUpdateNotice]),D(()=>{let e=I?`Robota — ${I}`:`Robota`;process.stdout.write(`\x1b]0;${e}\x07`)},[I]),y((e,t)=>{!t.escape||!d||w||Z||$||Q||G||N()}),y((e,t)=>{!t.ctrl||e!==`b`||w||Z||Q||p||K(e=>!e)}),y((e,t)=>{!t.escape||d||w||Z||$||Q||G||J&&J.kind!==`main_thread`&&Ee!==void 0&&S(Ee)}),y((e,t)=>{!t.ctrl||e!==`c`||p||F(`prompt_input_exit`).finally(()=>U())}),D(()=>{let e=()=>{p||F(`other`).finally(()=>U())};return process.once(`SIGINT`,e),process.once(`SIGTERM`,e),()=>{process.off(`SIGINT`,e),process.off(`SIGTERM`,e)}},[F,U,p]),D(()=>{if(!J||J.kind===`main_thread`){ie(null),oe(void 0),ce(!1);return}let e=!0;return ce(!0),oe(void 0),C(J.id).then(t=>{e&&(ie(t),ce(!1))}).catch(t=>{e&&(oe(t.message),ce(!1))}),()=>{e=!1}},[b,C,J]);let je=e.permissionMode??`default`,Me=``;try{let e=r.getSession();je=e.getPermissionMode(),Me=e.getSessionId()}catch{}return B(m,{flexDirection:`column`,children:[z(h,{items:[{version:e.version??`0.0.0`}],children:e=>B(m,{flexDirection:`column`,paddingX:1,marginBottom:1,children:[z(g,{color:`cyan`,bold:!0,children:`
18
+ `,z(g,{color:`gray`,children:n})]}):null]})},onSelect:e=>t(e.id),onCancel:n})]})}function qn(e){let t=Jn(e),n=e.hasPendingPrompt&&t.kind!==`queued`?[`queued`]:[],r=[t.label,...n].join(` · `);return{...t,segments:n,text:r}}function Jn(e){return e.activeToolCount>0?{kind:`tools`,label:`Tools x${e.activeToolCount}`,color:`cyan`}:e.isThinking?{kind:`thinking`,label:`Thinking`,color:`yellow`}:e.activeBackgroundTaskCount>0?{kind:`background`,label:`Background x${e.activeBackgroundTaskCount}`,color:`cyan`}:e.hasPendingPrompt?{kind:`queued`,label:`Queued`,color:`yellow`}:{kind:`idle`,label:`Idle`,color:`gray`}}function Yn(e){return e>=90?`red`:e>=70?`yellow`:`green`}function Xn({isThinking:e,activeToolCount:t,activeBackgroundTaskCount:n,hasPendingPrompt:r}){let i=qn({isThinking:e,activeToolCount:t,activeBackgroundTaskCount:n,hasPendingPrompt:r});return z(g,{color:i.color,bold:i.kind!==`idle`,children:i.text})}function Zn({percentage:e,usedTokens:t,maxTokens:n}){return B(g,{color:Yn(e),children:[`Context: `,Math.round(e),`% (`,P(t),`/`,P(n),` tokens)`]})}function Qn({permissionMode:e}){return B(R,{children:[z(g,{color:`cyan`,bold:!0,children:`Mode:`}),` `,z(g,{children:e})]})}function $n(e){return e!==`default`}function er({modelName:e,providerDisplayName:t}){return t===void 0?z(g,{dimColor:!0,children:e}):B(g,{dimColor:!0,children:[t,` `,e]})}function tr(e){let t=e.showGitBranch&&e.gitBranch!==void 0&&e.gitBranch.length>0,n=$n(e.permissionMode);return B(g,{children:[z(Xn,{isThinking:e.isThinking,activeToolCount:e.activeToolCount,activeBackgroundTaskCount:e.activeBackgroundTaskCount,hasPendingPrompt:e.hasPendingPrompt}),n&&B(R,{children:[` | `,z(Qn,{permissionMode:e.permissionMode})]}),e.sessionName&&B(R,{children:[` | `,z(g,{color:`magenta`,children:e.sessionName})]}),t&&B(R,{children:[` | `,B(g,{dimColor:!0,children:[`git: `,e.gitBranch]})]}),` | `,z(er,{modelName:e.modelName,providerDisplayName:e.providerDisplayName}),` | `,z(Zn,{percentage:e.contextPercentage,usedTokens:e.contextUsedTokens,maxTokens:e.contextMaxTokens})]})}function nr({permissionMode:e,modelName:t,providerDisplayName:n,sessionId:r,isThinking:i,activeToolCount:a=0,activeBackgroundTaskCount:o=0,hasPendingPrompt:s=!1,contextPercentage:c,contextUsedTokens:l,contextMaxTokens:u,sessionName:d,gitBranch:f,showGitBranch:p=!0,activeAgentLabel:h}){return B(m,{borderStyle:`single`,borderColor:`gray`,paddingLeft:1,paddingRight:1,justifyContent:`space-between`,children:[z(tr,{permissionMode:e,modelName:t,providerDisplayName:n,isThinking:i,activeToolCount:a,activeBackgroundTaskCount:o,hasPendingPrompt:s,contextPercentage:c,contextUsedTokens:l,contextMaxTokens:u,sessionName:d,gitBranch:f,showGitBranch:p}),h!==void 0&&B(g,{color:`yellow`,bold:!0,children:[`[`,h,`]`]})]})}function rr({cwd:e,permissionMode:t,modelId:n,providerType:r,sessionId:i,isThinking:a,activeToolCount:o,activeBackgroundTaskCount:s,hasPendingPrompt:c,contextState:l,sessionName:u,settings:d,activeAgentLabel:f,gitRefreshToken:p}){let m=ke(),h=O(()=>m.getGitBranch(e),[m,e,p]),g=O(()=>r===void 0?void 0:m.getProviderDisplayName(r),[m,r]);return d.enabled?z(nr,{permissionMode:t,modelName:n??``,providerDisplayName:g,sessionId:i,isThinking:a,activeToolCount:o,activeBackgroundTaskCount:s,hasPendingPrompt:c,contextPercentage:l.percentage,contextUsedTokens:l.usedTokens,contextMaxTokens:l.maxTokens,sessionName:u,gitBranch:h,showGitBranch:d.gitBranch,activeAgentLabel:f}):null}function ir(e){return e.isRunning?{color:`yellow`,icon:`⟳`,strikethrough:!1}:e.result===`error`?{color:`red`,icon:`✗`,strikethrough:!0}:e.result===`denied`?{color:`yellowBright`,icon:`⊘`,strikethrough:!0}:{color:`green`,icon:`✓`,strikethrough:!1}}function ar(e){return e?z(m,{marginBottom:1,children:z(g,{color:`yellow`,children:`Thinking...`})}):z(R,{})}function or(e){return B(m,{flexDirection:`column`,marginBottom:1,children:[z(g,{color:`white`,bold:!0,children:`Tools:`}),z(g,{children:` `}),e.map((e,t)=>{let{color:n,icon:r,strikethrough:i}=ir(e);return B(m,{flexDirection:`column`,children:[B(g,{color:n,strikethrough:i,children:[` `,r,` `,e.toolName,`(`,e.firstArg,`)`]}),e.diffLines&&e.diffLines.length>0&&z(pn,{file:e.diffFile,lines:e.diffLines})]},`${e.toolName}-${t}`)})]})}function sr({text:e,activeTools:t,isThinking:n=!1}){let r=t.length>0,i=e.length>0;return!r&&!i?ar(n):B(m,{flexDirection:`column`,children:[r&&or(t),i&&B(m,{flexDirection:`column`,marginBottom:1,children:[z(g,{color:`cyan`,bold:!0,children:`Robota:`}),z(g,{children:` `}),z(m,{marginLeft:2,children:z(g,{wrap:`wrap`,children:sn(e)})})]})]})}function cr({entry:e,selected:t}){let n=e.config.enabled,r=n?`●`:`○`,i=n?`[enabled] `:`[disabled]`,a=e.config.options?.port,o=typeof a==`number`?`port: ${a}`:``;return z(m,{children:z(g,{color:t?`cyan`:void 0,bold:t,children:`${r} ${e.transport.name.padEnd(18)} ${i} ${o}`})})}function lr(e,t,n,r,i,a,o,s){y(T((c,l)=>{if(!n){if(l.upArrow){i(e=>Math.max(0,e-1));return}if(l.downArrow){i(t=>Math.min(e.length-1,t+1));return}if(l.escape||l.return){o();return}if(c===` `){let n=e[t];if(!n)return;a(!0),r.setEnabled(n.transport.name,!n.config.enabled).then(()=>{s(),a(!1)}).catch(()=>a(!1))}}},[n,e,t,r,o,s,i,a]))}function ur({registry:e,onClose:t}){let[n,r]=A(()=>e.getAll()),[i,a]=A(0),[o,s]=A(!1);return lr(n,i,o,e,a,s,t,T(()=>{r(e.getAll())},[e])),B(m,{flexDirection:`column`,paddingX:2,paddingY:1,children:[z(g,{bold:!0,children:`Settings › Transports`}),z(m,{marginTop:1,flexDirection:`column`,children:n.map((e,t)=>z(cr,{entry:e,selected:t===i},e.transport.name))}),z(m,{marginTop:1,children:z(g,{dimColor:!0,children:`↑↓ select space toggle enter/esc close`})}),o&&z(m,{marginTop:1,children:z(g,{color:`yellow`,children:`Saving…`})})]})}function dr({message:e}){return z(m,{paddingX:1,marginBottom:1,children:z(g,{color:`yellow`,children:e})})}function fr(e){let[t,n]=A({channel:e.channel,sessionId:e.resumeSessionId}),[r,i]=A(e.showSessionPickerOnStart??!1);return z(Oe,{value:e.cliAdapter,children:z(pr,{...e,channel:t.channel,showSessionPickerOnStart:r,resumeSessionId:t.sessionId,onSessionSwitch:r=>{i(!1);let a=t.channel;n({channel:e.createChannel?e.createChannel(r):e.channel,sessionId:r}),a.stop()}},t.sessionId??`__new__`)})}function pr(e){let t=e.cwd,{channel:n}=e,{interactiveSession:r,registry:i,commandEffectQueue:a,history:o,addEntry:s,streamingText:c,activeTools:u,isThinking:d,isAborting:f,isShuttingDown:p,pendingPrompt:_,executionWorkspaceSnapshot:b,selectedExecutionEntryId:x,selectExecutionWorkspaceEntry:S,readExecutionWorkspaceDetail:C,permissionRequest:w,contextState:E,handleSubmit:M,handleAbort:N,handleCancelQueue:P,handleShutdown:F}=Pe(n),[I,R]=A(n.sessionName),V=Ce(t),H=r?void 0:V,{exit:U}=v(),[W,ee]=A(),[G,K]=A(!1),[re,ie]=A(null),[ae,oe]=A(),[se,ce]=A(!1),[le,ue]=Ne(),[de,he]=A(0),q=O(()=>te(b),[b]),ge=ne(b),J=O(()=>b?.entries.find(e=>e.id===x),[b,x]),{handleSubmit:Y,pendingInteractionPrompt:X,showPluginTUI:Z,showSessionPicker:Q,showTransportTUI:$,setShowPluginTUI:ve,setShowSessionPicker:ye,setShowTransportTUI:be,handleInteractionSubmit:xe,handleInteractionCancel:Se}=Ae({cwd:t,providerOverride:e.providerOverride,interactiveSession:r,commandEffectQueue:a,addEntry:s,baseHandleSubmit:M,setSessionName:R,setStatusLineSettings:ue,showSessionPickerOnStart:e.showSessionPickerOnStart,openAgentSwitcher:()=>K(!0)});D(()=>(n.start(),()=>{n.stop()}),[n]);let we=!J||J.kind===`main_thread`||J.controls.includes(`send`),Te=J&&J.kind!==`main_thread`?J.title:void 0,Ee=O(()=>b?.entries.find(e=>e.kind===`main_thread`)?.id,[b]),De=T(async e=>{J&&J.kind!==`main_thread`&&J.controls.includes(`send`)?await r.sendAgentJob(J.sourceId,e):await Y(e)},[J,Y,r]),Oe=T(async e=>{he(e=>e+1),await De(e)},[De]),ke=k(!1);D(()=>{ke.current&&!d&&he(e=>e+1),ke.current=d},[d]),D(()=>{let e=r?.getName?.();e&&!I&&R(e)},[r,I]),D(()=>{let t=!0;return e.startupUpdateNotice?.then(e=>{t&&e!==void 0&&ee(e)}).catch(()=>{}),()=>{t=!1}},[e.startupUpdateNotice]),D(()=>{let e=I?`Robota — ${I}`:`Robota`;process.stdout.write(`\x1b]0;${e}\x07`)},[I]),y((e,t)=>{!t.escape||!d||w||Z||$||Q||G||N()}),y((e,t)=>{!t.ctrl||e!==`b`||w||Z||Q||p||K(e=>!e)}),y((e,t)=>{!t.escape||d||w||Z||$||Q||G||J&&J.kind!==`main_thread`&&Ee!==void 0&&S(Ee)}),y((e,t)=>{!t.ctrl||e!==`c`||p||F(`prompt_input_exit`).finally(()=>U())}),D(()=>{let e=()=>{p||F(`other`).finally(()=>U())};return process.once(`SIGINT`,e),process.once(`SIGTERM`,e),()=>{process.off(`SIGINT`,e),process.off(`SIGTERM`,e)}},[F,U,p]),D(()=>{if(!J||J.kind===`main_thread`){ie(null),oe(void 0),ce(!1);return}let e=!0;return ce(!0),oe(void 0),C(J.id).then(t=>{e&&(ie(t),ce(!1))}).catch(t=>{e&&(oe(t.message),ce(!1))}),()=>{e=!1}},[b,C,J]);let je=e.permissionMode??`default`,Me=``;try{let e=r.getSession();je=e.getPermissionMode(),Me=e.getSessionId()}catch{}return B(m,{flexDirection:`column`,children:[z(h,{items:[{version:e.version??`0.0.0`}],children:e=>B(m,{flexDirection:`column`,paddingX:1,marginBottom:1,children:[z(g,{color:`cyan`,bold:!0,children:`
19
19
  ____ ___ ____ ___ _____ _
20
20
  | _ \\ / _ \\| __ ) / _ \\_ _|/ \\
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=new xr({cwd:e.cwd,provider:e.provider,permissionMode:e.permissionMode,maxTurns:e.maxTurns,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,transportRegistry:e.transportRegistry,language:e.language,reloadPluginCommandSource:e.reloadPluginCommandSource,agentName:e.agentName});await _(z(fr,{cwd:e.cwd,channel: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-Cf1-zocr.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(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