@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.
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/tui/index.cjs +1 -1
- package/dist/node/tui/index.js +1 -1
- package/dist/node/{tui-Cf1-zocr.js → tui-Bl-bm9iA.js} +3 -3
- package/dist/node/{tui-Cf1-zocr.js.map → tui-Bl-bm9iA.js.map} +1 -1
- package/dist/node/{tui-re-S-CGS.cjs → tui-DULGN7sr.cjs} +2 -2
- package/package.json +6 -6
- package/src/tui/App.tsx +12 -4
- package/src/tui/render.tsx +23 -19
|
@@ -15,10 +15,10 @@ const e=require(`./chunk-Bmb41Sf3.cjs`);let t=require(`@robota-sdk/agent-framewo
|
|
|
15
15
|
|
|
16
16
|
_(interrupted)_`:``)):t})})]})});function Vt({entry:e}){let t=e.data,r=t?.tools,i=t?.summary?.split(`
|
|
17
17
|
`)??[];return r&&r.length>0?(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Box,{children:(0,o.jsxs)(n.Text,{color:`white`,bold:!0,children:[`Tool:`,` `]})}),(0,o.jsx)(n.Text,{children:` `}),r.map((e,t)=>(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[(0,o.jsxs)(n.Text,{color:It(e),children:[` `,Lt(e)]}),(0,o.jsx)(Dt,{tool:e}),e.diffLines&&e.diffLines.length>0&&(0,o.jsx)(Mt,{file:e.diffFile,lines:e.diffLines})]},t))]}):(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Box,{children:(0,o.jsxs)(n.Text,{color:`white`,bold:!0,children:[`Tool:`,` `]})}),(0,o.jsx)(n.Text,{children:` `}),i.map((e,t)=>(0,o.jsxs)(n.Text,{color:`green`,children:[` `,e]},t))]})}function Ht({entry:e}){let t=e.data,r=typeof t?.message==`string`?t.message:typeof t?.content==`string`?t.content:e.type;return(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Box,{children:(0,o.jsxs)(n.Text,{color:`yellow`,bold:!0,children:[`System:`,` `]})}),(0,o.jsx)(n.Text,{children:` `}),(0,o.jsx)(n.Box,{marginLeft:2,children:(0,o.jsx)(n.Text,{wrap:`wrap`,children:r})})]})}function Ut({entry:e}){if(e.category===`chat`){let t=e.data;return(0,o.jsx)(Bt,{message:t})}return e.type===`tool-summary`?(0,o.jsx)(Vt,{entry:e}):e.type===`usage-summary`?(0,o.jsx)(Nt,{entry:e}):e.type===`tool-start`||e.type===`tool-end`?(0,o.jsx)(o.Fragment,{}):(0,o.jsx)(Ht,{entry:e})}function Wt({history:e}){return(0,o.jsx)(n.Box,{flexDirection:`column`,children:e.map(e=>(0,o.jsx)(Ut,{entry:e},e.id))})}const Gt=[`Allow [y]`,`Allow always (this session) [s]`,`Allow always (this project) [p]`,`Deny [n]`];function Kt(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 qt(e,t){if(e.resolved)return{state:e,effect:{type:`none`}};if(typeof t!=`string`)return Yt(e,t.index);let n=M(e,t,{itemCount:Gt.length});return n.effect.type===`select`?{state:n.state,effect:{type:`resolve`,decision:Jt(n.effect.index)}}:{state:n.state,effect:{type:`none`}}}function Jt(e){return e===0?!0:e===1?`allow-session`:e===2?`allow-project`:!1}function Yt(e,t){return{state:{...e,selectedIndex:t,resolved:!0},effect:{type:`resolve`,decision:Jt(t)}}}function Xt(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 Zt({request:e}){let[t,i]=r.default.useState(()=>k()),a=r.default.useRef(t),s=r.default.useRef(e);if(s.current!==e){s.current=e;let t=k();a.current=t,i(t)}let c=r.default.useCallback(t=>{let n=qt(a.current,t);a.current=n.state,i(n.state),n.effect.type===`resolve`&&e.resolve(n.effect.decision)},[e]);return(0,n.useInput)((e,t)=>{let n=Kt(e,t);n!==void 0&&c(n)}),(0,o.jsxs)(n.Box,{flexDirection:`column`,borderStyle:`round`,borderColor:`yellow`,paddingX:1,children:[(0,o.jsx)(n.Text,{color:`yellow`,bold:!0,children:`[Permission Required]`}),(0,o.jsxs)(n.Text,{children:[`Tool:`,` `,(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:e.toolName})]}),(0,o.jsxs)(n.Text,{dimColor:!0,children:[` `,Xt(e.toolArgs)]}),(0,o.jsx)(n.Box,{marginTop:1,children:Gt.map((e,r)=>(0,o.jsx)(n.Box,{marginRight:2,children:(0,o.jsxs)(n.Text,{color:r===t.selectedIndex?`cyan`:void 0,bold:r===t.selectedIndex,children:[r===t.selectedIndex?`> `:` `,e]})},e))}),(0,o.jsx)(n.Text,{dimColor:!0,children:` left/right to select, Enter to confirm`})]})}function Qt(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 $t(e,t,n){return e.resolved?{state:e,effect:{type:`none`}}:typeof t==`string`?M(e,t,{itemCount:n}):{state:{...e,selectedIndex:t.index,resolved:!0},effect:{type:`select`,index:t.index}}}function en({message:e,options:t=[`Yes`,`No`],onSelect:i}){let[a,s]=(0,r.useState)(()=>k()),c=(0,r.useRef)(a),l=(0,r.useCallback)(e=>{let n=$t(c.current,e,t.length);c.current=n.state,s(n.state),n.effect.type===`select`&&i(n.effect.index)},[i,t.length]);return(0,n.useInput)((e,n)=>{let r=Qt(e,n,t.length);r!==void 0&&l(r)}),(0,o.jsxs)(n.Box,{flexDirection:`column`,borderStyle:`round`,borderColor:`yellow`,paddingX:1,children:[(0,o.jsx)(n.Text,{color:`yellow`,children:e}),(0,o.jsx)(n.Box,{marginTop:1,children:t.map((e,t)=>(0,o.jsx)(n.Box,{marginRight:2,children:(0,o.jsxs)(n.Text,{color:t===a.selectedIndex?`cyan`:void 0,bold:t===a.selectedIndex,children:[t===a.selectedIndex?`> `:` `,e]})},e))}),(0,o.jsx)(n.Text,{dimColor:!0,children:` arrow keys to select, Enter to confirm`})]})}function tn(e,t,n,r,a){let[o,s]=(0,i.useState)([]),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)();return(0,i.useEffect)(()=>{if(s([]),d(void 0),e===`marketplace-list`)l(!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}));s([...t,...n]),l(!1)}).catch(e=>{d(e instanceof Error?e.message:String(e)),l(!1)});else if(e===`marketplace-browse`){let e=t??``;l(!0),n.listAvailablePlugins(e).then(e=>{s(e.map(e=>({label:e.name,value:e.name,hint:e.installed?`installed`:e.description}))),l(!1)}).catch(e=>{d(e instanceof Error?e.message:String(e)),l(!1)})}else e===`installed-list`&&(l(!0),n.listInstalled().then(e=>{s(e.map(e=>({label:e.name,value:e.name,hint:e.description}))),l(!1)}).catch(e=>{d(e instanceof Error?e.message:String(e)),l(!1)}))},[a,e,t,n,r]),{items:o,loading:c,error:u}}function nn({title:e,items:t,onSelect:i,onBack:a,loading:s,error:c}){let[l,u]=(0,r.useState)(()=>k()),d=(0,r.useRef)(l),f=!s&&!c,p=(0,r.useCallback)(e=>{let n=M(d.current,e,{itemCount:t.length,enabled:f});if(d.current=n.state,u(n.state),n.effect.type===`cancel`)a();else if(n.effect.type===`select`){let e=t[n.effect.index];e!==void 0&&i(e.value)}},[f,t,a,i]);(0,n.useInput)((e,t)=>{let n=A(t);n!==void 0&&p(n)});let m=N(l,{itemCount:t.length});m!==l&&(d.current=m);let h=m.selectedIndex;return(0,o.jsxs)(n.Box,{flexDirection:`column`,borderStyle:`round`,borderColor:`yellow`,paddingX:1,children:[(0,o.jsx)(n.Text,{color:`yellow`,bold:!0,children:e}),s&&(0,o.jsx)(n.Box,{marginTop:1,children:(0,o.jsx)(n.Text,{dimColor:!0,children:`Loading...`})}),c&&(0,o.jsxs)(n.Box,{marginTop:1,flexDirection:`column`,children:[(0,o.jsx)(n.Text,{color:`red`,children:c}),(0,o.jsx)(n.Text,{dimColor:!0,children:`Press Esc to go back`})]}),!s&&!c&&(0,o.jsx)(n.Box,{flexDirection:`column`,marginTop:1,children:t.map((e,t)=>(0,o.jsxs)(n.Box,{children:[(0,o.jsxs)(n.Text,{color:t===h?`cyan`:void 0,bold:t===h,children:[t===h?`> `:` `,e.label]}),e.hint&&(0,o.jsxs)(n.Text,{dimColor:!0,children:[` `,e.hint]})]},e.value))}),(0,o.jsx)(n.Text,{dimColor:!0,children:s||c?``:` ↑↓ Navigate Enter Select Esc Back`})]})}function rn(e,t){e===`marketplace`?t.push({screen:`marketplace-list`}):e===`installed`&&t.push({screen:`installed-list`})}function an(e,t){e===`__add__`?t.push({screen:`marketplace-add`}):t.push({screen:`marketplace-action`,context:{marketplace:e}})}function on(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 sn(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 cn(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 ln(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 un(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 dn({callbacks:e,onClose:t,addMessage:n}){let[i,a]=(0,r.useState)([{screen:`main`}]),[s,c]=(0,r.useState)(),[l,u]=(0,r.useState)(0),d=i[i.length-1]??{screen:`main`},f=(0,r.useCallback)(e=>{a(t=>[...t,e])},[]),p=(0,r.useCallback)(()=>{a(e=>e.length<=1?(t(),e):e.slice(0,-1))},[t]),m=(0,r.useCallback)(e=>{a(n=>{let r=n.slice(0,Math.max(1,n.length-e));return r.length===0?(t(),n):r})},[t]),h=(0,r.useCallback)(e=>{n?.({role:`system`,content:e})},[n]),g=(0,r.useCallback)(()=>{u(e=>e+1)},[]),_=(0,r.useCallback)(e=>c(e),[c]),v={push:(0,r.useCallback)(e=>f({screen:e.screen,context:e.context}),[f]),pop:p,popN:m,notify:h,setConfirm:_,refresh:g},{items:y,loading:b,error:x}=tn(d.screen,d.context?.marketplace,e,l,i.length),S=(0,r.useCallback)(t=>{let n=d.screen,r=d.context;n===`main`?rn(t,v):n===`marketplace-list`?an(t,v):n===`marketplace-action`?on(t,r?.marketplace??``,e,v):n===`marketplace-browse`?sn(t,r?.marketplace??``,y,v):n===`marketplace-install-scope`?cn(t,r?.pluginId??``,e,v):n===`installed-list`?ln(t,e,v):n===`installed-action`&&un(t,r?.pluginId??``,e,v)},[d,y,e,f,p,m,h,c,g]),C=(0,r.useCallback)(t=>{d.screen===`marketplace-add`&&e.marketplaceAdd(t).then(e=>{h(`Added marketplace "${e}" from ${t}.`),p()}).catch(e=>{h(`Error: ${e instanceof Error?e.message:String(e)}`),p()})},[d.screen,e,h,p]);if(s)return(0,o.jsx)(en,{message:s.message,onSelect:e=>{e===0?s.onConfirm():s.onCancel()}});let w=d.screen;return w===`marketplace-add`?(0,o.jsx)(tt,{title:`Add Marketplace Source`,placeholder:`owner/repo or git URL`,onSubmit:C,onCancel:p,validate:e=>e.includes(`/`)?void 0:`Must be owner/repo or a git URL`}):w===`marketplace-action`?(0,o.jsx)(nn,{title:`Marketplace: ${d.context?.marketplace??``}`,items:[{label:`Browse plugins`,value:`browse`},{label:`Update`,value:`update`},{label:`Remove`,value:`remove`}],onSelect:S,onBack:p},i.length):w===`marketplace-install-scope`?(0,o.jsx)(nn,{title:`Install scope for "${d.context?.pluginId??``}"`,items:[{label:`User scope`,value:`user`},{label:`Project scope`,value:`project`}],onSelect:S,onBack:p},i.length):w===`installed-action`?(0,o.jsx)(nn,{title:`Plugin: ${d.context?.pluginId??``}`,items:[{label:`Uninstall`,value:`uninstall`}],onSelect:S,onBack:p},i.length):(0,o.jsx)(nn,{title:{main:`Plugin Management`,"marketplace-list":`Marketplace`,"marketplace-browse":`Browse: ${d.context?.marketplace??``}`,"installed-list":`Installed Plugins`}[w]??`Plugin Management`,items:{main:[{label:`Marketplace`,value:`marketplace`},{label:`Installed Plugins`,value:`installed`}]}[w]??y,onSelect:S,onBack:p,loading:b,error:x},`${w}-${i.length}-${l}`)}function fn({sessions:e,onSelect:t,onCancel:r}){return(0,o.jsxs)(n.Box,{flexDirection:`column`,paddingX:1,marginBottom:1,children:[(0,o.jsx)(n.Text,{bold:!0,color:`cyan`,children:`Select a session to resume (ESC to cancel):`}),(0,o.jsx)(Xe,{items:[...e],renderItem:(e,t)=>{let r=e.preview?e.preview.slice(0,60)+(e.preview.length>60?`...`:``):``;return(0,o.jsxs)(n.Text,{children:[t?`> `:` `,(0,o.jsx)(n.Text,{bold:!0,children:e.name??e.id.slice(0,8)}),` `,(0,o.jsx)(n.Text,{dimColor:!0,children:new Date(e.updatedAt).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}),` `,(0,o.jsxs)(n.Text,{dimColor:!0,children:[`msgs: `,e.messageCount]}),r?(0,o.jsxs)(o.Fragment,{children:[`
|
|
18
|
-
`,(0,o.jsx)(n.Text,{color:`gray`,children:r})]}):null]})},onSelect:e=>t(e.id),onCancel:r})]})}function pn(e){let t=mn(e),n=e.hasPendingPrompt&&t.kind!==`queued`?[`queued`]:[],r=[t.label,...n].join(` · `);return{...t,segments:n,text:r}}function mn(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 hn(e){return e>=90?`red`:e>=70?`yellow`:`green`}function gn({isThinking:e,activeToolCount:t,activeBackgroundTaskCount:r,hasPendingPrompt:i}){let a=pn({isThinking:e,activeToolCount:t,activeBackgroundTaskCount:r,hasPendingPrompt:i});return(0,o.jsx)(n.Text,{color:a.color,bold:a.kind!==`idle`,children:a.text})}function _n({percentage:e,usedTokens:t,maxTokens:r}){return(0,o.jsxs)(n.Text,{color:hn(e),children:[`Context: `,Math.round(e),`% (`,(0,a.formatTokenCount)(t),`/`,(0,a.formatTokenCount)(r),` tokens)`]})}function vn({permissionMode:e}){return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:`Mode:`}),` `,(0,o.jsx)(n.Text,{children:e})]})}function yn(e){return e!==`default`}function bn({modelName:e,providerDisplayName:t}){return t===void 0?(0,o.jsx)(n.Text,{dimColor:!0,children:e}):(0,o.jsxs)(n.Text,{dimColor:!0,children:[t,` `,e]})}function xn(e){let t=e.showGitBranch&&e.gitBranch!==void 0&&e.gitBranch.length>0,r=yn(e.permissionMode);return(0,o.jsxs)(n.Text,{children:[(0,o.jsx)(gn,{isThinking:e.isThinking,activeToolCount:e.activeToolCount,activeBackgroundTaskCount:e.activeBackgroundTaskCount,hasPendingPrompt:e.hasPendingPrompt}),r&&(0,o.jsxs)(o.Fragment,{children:[` | `,(0,o.jsx)(vn,{permissionMode:e.permissionMode})]}),e.sessionName&&(0,o.jsxs)(o.Fragment,{children:[` | `,(0,o.jsx)(n.Text,{color:`magenta`,children:e.sessionName})]}),t&&(0,o.jsxs)(o.Fragment,{children:[` | `,(0,o.jsxs)(n.Text,{dimColor:!0,children:[`git: `,e.gitBranch]})]}),` | `,(0,o.jsx)(bn,{modelName:e.modelName,providerDisplayName:e.providerDisplayName}),` | `,(0,o.jsx)(_n,{percentage:e.contextPercentage,usedTokens:e.contextUsedTokens,maxTokens:e.contextMaxTokens})]})}function Sn({permissionMode:e,modelName:t,providerDisplayName:r,sessionId:i,isThinking:a,activeToolCount:s=0,activeBackgroundTaskCount:c=0,hasPendingPrompt:l=!1,contextPercentage:u,contextUsedTokens:d,contextMaxTokens:f,sessionName:p,gitBranch:m,showGitBranch:h=!0,activeAgentLabel:g}){return(0,o.jsxs)(n.Box,{borderStyle:`single`,borderColor:`gray`,paddingLeft:1,paddingRight:1,justifyContent:`space-between`,children:[(0,o.jsx)(xn,{permissionMode:e,modelName:t,providerDisplayName:r,isThinking:a,activeToolCount:s,activeBackgroundTaskCount:c,hasPendingPrompt:l,contextPercentage:u,contextUsedTokens:d,contextMaxTokens:f,sessionName:p,gitBranch:m,showGitBranch:h}),g!==void 0&&(0,o.jsxs)(n.Text,{color:`yellow`,bold:!0,children:[`[`,g,`]`]})]})}function Cn({cwd:e,permissionMode:t,modelId:n,providerType:i,sessionId:a,isThinking:s,activeToolCount:c,activeBackgroundTaskCount:l,hasPendingPrompt:u,contextState:d,sessionName:f,settings:p,activeAgentLabel:m,gitRefreshToken:h}){let g=U(),_=(0,r.useMemo)(()=>g.getGitBranch(e),[g,e,h]),v=(0,r.useMemo)(()=>i===void 0?void 0:g.getProviderDisplayName(i),[g,i]);return p.enabled?(0,o.jsx)(Sn,{permissionMode:t,modelName:n??``,providerDisplayName:v,sessionId:a,isThinking:s,activeToolCount:c,activeBackgroundTaskCount:l,hasPendingPrompt:u,contextPercentage:d.percentage,contextUsedTokens:d.usedTokens,contextMaxTokens:d.maxTokens,sessionName:f,gitBranch:_,showGitBranch:p.gitBranch,activeAgentLabel:m}):null}function wn(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 Tn(e){return e?(0,o.jsx)(n.Box,{marginBottom:1,children:(0,o.jsx)(n.Text,{color:`yellow`,children:`Thinking...`})}):(0,o.jsx)(o.Fragment,{})}function En(e){return(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Text,{color:`white`,bold:!0,children:`Tools:`}),(0,o.jsx)(n.Text,{children:` `}),e.map((e,t)=>{let{color:r,icon:i,strikethrough:a}=wn(e);return(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[(0,o.jsxs)(n.Text,{color:r,strikethrough:a,children:[` `,i,` `,e.toolName,`(`,e.firstArg,`)`]}),e.diffLines&&e.diffLines.length>0&&(0,o.jsx)(Mt,{file:e.diffFile,lines:e.diffLines})]},`${e.toolName}-${t}`)})]})}function Dn({text:e,activeTools:t,isThinking:r=!1}){let i=t.length>0,a=e.length>0;return!i&&!a?Tn(r):(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[i&&En(t),a&&(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:`Robota:`}),(0,o.jsx)(n.Text,{children:` `}),(0,o.jsx)(n.Box,{marginLeft:2,children:(0,o.jsx)(n.Text,{wrap:`wrap`,children:Et(e)})})]})]})}function On({entry:e,selected:t}){let r=e.config.enabled,i=r?`●`:`○`,a=r?`[enabled] `:`[disabled]`,s=e.config.options?.port,c=typeof s==`number`?`port: ${s}`:``;return(0,o.jsx)(n.Box,{children:(0,o.jsx)(n.Text,{color:t?`cyan`:void 0,bold:t,children:`${i} ${e.transport.name.padEnd(18)} ${a} ${c}`})})}function kn(e,t,i,a,o,s,c,l){(0,n.useInput)((0,r.useCallback)((n,r)=>{if(!i){if(r.upArrow){o(e=>Math.max(0,e-1));return}if(r.downArrow){o(t=>Math.min(e.length-1,t+1));return}if(r.escape||r.return){c();return}if(n===` `){let n=e[t];if(!n)return;s(!0),a.setEnabled(n.transport.name,!n.config.enabled).then(()=>{l(),s(!1)}).catch(()=>s(!1))}}},[i,e,t,a,c,l,o,s]))}function An({registry:e,onClose:t}){let[i,a]=(0,r.useState)(()=>e.getAll()),[s,c]=(0,r.useState)(0),[l,u]=(0,r.useState)(!1);return kn(i,s,l,e,c,u,t,(0,r.useCallback)(()=>{a(e.getAll())},[e])),(0,o.jsxs)(n.Box,{flexDirection:`column`,paddingX:2,paddingY:1,children:[(0,o.jsx)(n.Text,{bold:!0,children:`Settings › Transports`}),(0,o.jsx)(n.Box,{marginTop:1,flexDirection:`column`,children:i.map((e,t)=>(0,o.jsx)(On,{entry:e,selected:t===s},e.transport.name))}),(0,o.jsx)(n.Box,{marginTop:1,children:(0,o.jsx)(n.Text,{dimColor:!0,children:`↑↓ select space toggle enter/esc close`})}),l&&(0,o.jsx)(n.Box,{marginTop:1,children:(0,o.jsx)(n.Text,{color:`yellow`,children:`Saving…`})})]})}function jn({message:e}){return(0,o.jsx)(n.Box,{paddingX:1,marginBottom:1,children:(0,o.jsx)(n.Text,{color:`yellow`,children:e})})}function Mn(e){let[t,n]=(0,r.useState)(e.resumeSessionId),[i,a]=(0,r.useState)(e.showSessionPickerOnStart??!1);return(0,o.jsx)(H,{value:e.cliAdapter,children:(0,o.jsx)(Nn,{...e,showSessionPickerOnStart:i,resumeSessionId:t,onSessionSwitch:e=>{a(!1),n(e)}},t??`__new__`)})}function Nn(e){let i=e.cwd,{channel:s}=e,{interactiveSession:c,registry:l,commandEffectQueue:u,history:d,addEntry:f,streamingText:h,activeTools:g,isThinking:_,isAborting:v,isShuttingDown:y,pendingPrompt:b,executionWorkspaceSnapshot:x,selectedExecutionEntryId:S,selectExecutionWorkspaceEntry:C,readExecutionWorkspaceDetail:w,permissionRequest:O,contextState:k,handleSubmit:A,handleAbort:j,handleCancelQueue:M,handleShutdown:N}=le(s),[P,F]=(0,r.useState)(s.sessionName),I=ne(i),te=c?void 0:I,{exit:L}=(0,n.useApp)(),[R,z]=(0,r.useState)(),[B,V]=(0,r.useState)(!1),[re,ie]=(0,r.useState)(null),[ae,H]=(0,r.useState)(),[U,W]=(0,r.useState)(!1),[se,ue]=ce(),[G,de]=(0,r.useState)(0),fe=(0,r.useMemo)(()=>p(x),[x]),pe=m(x),K=(0,r.useMemo)(()=>x?.entries.find(e=>e.id===S),[x,S]),{handleSubmit:me,pendingInteractionPrompt:q,showPluginTUI:J,showSessionPicker:Y,showTransportTUI:X,setShowPluginTUI:he,setShowSessionPicker:ge,setShowTransportTUI:_e,handleInteractionSubmit:ve,handleInteractionCancel:ye}=oe({cwd:i,providerOverride:e.providerOverride,interactiveSession:c,commandEffectQueue:u,addEntry:f,baseHandleSubmit:A,setSessionName:F,setStatusLineSettings:ue,showSessionPickerOnStart:e.showSessionPickerOnStart,openAgentSwitcher:()=>V(!0)});(0,r.useEffect)(()=>(s.start(),()=>{s.stop()}),[s]);let be=!K||K.kind===`main_thread`||K.controls.includes(`send`),xe=K&&K.kind!==`main_thread`?K.title:void 0,Z=(0,r.useMemo)(()=>x?.entries.find(e=>e.kind===`main_thread`)?.id,[x]),Se=(0,r.useCallback)(async e=>{K&&K.kind!==`main_thread`&&K.controls.includes(`send`)?await c.sendAgentJob(K.sourceId,e):await me(e)},[K,me,c]),Ce=(0,r.useCallback)(async e=>{de(e=>e+1),await Se(e)},[Se]),Q=(0,r.useRef)(!1);(0,r.useEffect)(()=>{Q.current&&!_&&de(e=>e+1),Q.current=_},[_]),(0,r.useEffect)(()=>{let e=c?.getName?.();e&&!P&&F(e)},[c,P]),(0,r.useEffect)(()=>{let t=!0;return e.startupUpdateNotice?.then(e=>{t&&e!==void 0&&z(e)}).catch(()=>{}),()=>{t=!1}},[e.startupUpdateNotice]),(0,r.useEffect)(()=>{let e=P?`Robota — ${P}`:`Robota`;process.stdout.write(`\x1b]0;${e}\x07`)},[P]),(0,n.useInput)((e,t)=>{!t.escape||!_||O||J||X||Y||B||j()}),(0,n.useInput)((e,t)=>{!t.ctrl||e!==`b`||O||J||Y||y||V(e=>!e)}),(0,n.useInput)((e,t)=>{!t.escape||_||O||J||X||Y||B||K&&K.kind!==`main_thread`&&Z!==void 0&&C(Z)}),(0,n.useInput)((e,t)=>{!t.ctrl||e!==`c`||y||N(`prompt_input_exit`).finally(()=>L())}),(0,r.useEffect)(()=>{let e=()=>{y||N(`other`).finally(()=>L())};return process.once(`SIGINT`,e),process.once(`SIGTERM`,e),()=>{process.off(`SIGINT`,e),process.off(`SIGTERM`,e)}},[N,L,y]),(0,r.useEffect)(()=>{if(!K||K.kind===`main_thread`){ie(null),H(void 0),W(!1);return}let e=!0;return W(!0),H(void 0),w(K.id).then(t=>{e&&(ie(t),W(!1))}).catch(t=>{e&&(H(t.message),W(!1))}),()=>{e=!1}},[x,w,K]);let $=e.permissionMode??`default`,we=``;try{let e=c.getSession();$=e.getPermissionMode(),we=e.getSessionId()}catch{}return(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[(0,o.jsx)(n.Static,{items:[{version:e.version??`0.0.0`}],children:e=>(0,o.jsxs)(n.Box,{flexDirection:`column`,paddingX:1,marginBottom:1,children:[(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:`
|
|
18
|
+
`,(0,o.jsx)(n.Text,{color:`gray`,children:r})]}):null]})},onSelect:e=>t(e.id),onCancel:r})]})}function pn(e){let t=mn(e),n=e.hasPendingPrompt&&t.kind!==`queued`?[`queued`]:[],r=[t.label,...n].join(` · `);return{...t,segments:n,text:r}}function mn(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 hn(e){return e>=90?`red`:e>=70?`yellow`:`green`}function gn({isThinking:e,activeToolCount:t,activeBackgroundTaskCount:r,hasPendingPrompt:i}){let a=pn({isThinking:e,activeToolCount:t,activeBackgroundTaskCount:r,hasPendingPrompt:i});return(0,o.jsx)(n.Text,{color:a.color,bold:a.kind!==`idle`,children:a.text})}function _n({percentage:e,usedTokens:t,maxTokens:r}){return(0,o.jsxs)(n.Text,{color:hn(e),children:[`Context: `,Math.round(e),`% (`,(0,a.formatTokenCount)(t),`/`,(0,a.formatTokenCount)(r),` tokens)`]})}function vn({permissionMode:e}){return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:`Mode:`}),` `,(0,o.jsx)(n.Text,{children:e})]})}function yn(e){return e!==`default`}function bn({modelName:e,providerDisplayName:t}){return t===void 0?(0,o.jsx)(n.Text,{dimColor:!0,children:e}):(0,o.jsxs)(n.Text,{dimColor:!0,children:[t,` `,e]})}function xn(e){let t=e.showGitBranch&&e.gitBranch!==void 0&&e.gitBranch.length>0,r=yn(e.permissionMode);return(0,o.jsxs)(n.Text,{children:[(0,o.jsx)(gn,{isThinking:e.isThinking,activeToolCount:e.activeToolCount,activeBackgroundTaskCount:e.activeBackgroundTaskCount,hasPendingPrompt:e.hasPendingPrompt}),r&&(0,o.jsxs)(o.Fragment,{children:[` | `,(0,o.jsx)(vn,{permissionMode:e.permissionMode})]}),e.sessionName&&(0,o.jsxs)(o.Fragment,{children:[` | `,(0,o.jsx)(n.Text,{color:`magenta`,children:e.sessionName})]}),t&&(0,o.jsxs)(o.Fragment,{children:[` | `,(0,o.jsxs)(n.Text,{dimColor:!0,children:[`git: `,e.gitBranch]})]}),` | `,(0,o.jsx)(bn,{modelName:e.modelName,providerDisplayName:e.providerDisplayName}),` | `,(0,o.jsx)(_n,{percentage:e.contextPercentage,usedTokens:e.contextUsedTokens,maxTokens:e.contextMaxTokens})]})}function Sn({permissionMode:e,modelName:t,providerDisplayName:r,sessionId:i,isThinking:a,activeToolCount:s=0,activeBackgroundTaskCount:c=0,hasPendingPrompt:l=!1,contextPercentage:u,contextUsedTokens:d,contextMaxTokens:f,sessionName:p,gitBranch:m,showGitBranch:h=!0,activeAgentLabel:g}){return(0,o.jsxs)(n.Box,{borderStyle:`single`,borderColor:`gray`,paddingLeft:1,paddingRight:1,justifyContent:`space-between`,children:[(0,o.jsx)(xn,{permissionMode:e,modelName:t,providerDisplayName:r,isThinking:a,activeToolCount:s,activeBackgroundTaskCount:c,hasPendingPrompt:l,contextPercentage:u,contextUsedTokens:d,contextMaxTokens:f,sessionName:p,gitBranch:m,showGitBranch:h}),g!==void 0&&(0,o.jsxs)(n.Text,{color:`yellow`,bold:!0,children:[`[`,g,`]`]})]})}function Cn({cwd:e,permissionMode:t,modelId:n,providerType:i,sessionId:a,isThinking:s,activeToolCount:c,activeBackgroundTaskCount:l,hasPendingPrompt:u,contextState:d,sessionName:f,settings:p,activeAgentLabel:m,gitRefreshToken:h}){let g=U(),_=(0,r.useMemo)(()=>g.getGitBranch(e),[g,e,h]),v=(0,r.useMemo)(()=>i===void 0?void 0:g.getProviderDisplayName(i),[g,i]);return p.enabled?(0,o.jsx)(Sn,{permissionMode:t,modelName:n??``,providerDisplayName:v,sessionId:a,isThinking:s,activeToolCount:c,activeBackgroundTaskCount:l,hasPendingPrompt:u,contextPercentage:d.percentage,contextUsedTokens:d.usedTokens,contextMaxTokens:d.maxTokens,sessionName:f,gitBranch:_,showGitBranch:p.gitBranch,activeAgentLabel:m}):null}function wn(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 Tn(e){return e?(0,o.jsx)(n.Box,{marginBottom:1,children:(0,o.jsx)(n.Text,{color:`yellow`,children:`Thinking...`})}):(0,o.jsx)(o.Fragment,{})}function En(e){return(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Text,{color:`white`,bold:!0,children:`Tools:`}),(0,o.jsx)(n.Text,{children:` `}),e.map((e,t)=>{let{color:r,icon:i,strikethrough:a}=wn(e);return(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[(0,o.jsxs)(n.Text,{color:r,strikethrough:a,children:[` `,i,` `,e.toolName,`(`,e.firstArg,`)`]}),e.diffLines&&e.diffLines.length>0&&(0,o.jsx)(Mt,{file:e.diffFile,lines:e.diffLines})]},`${e.toolName}-${t}`)})]})}function Dn({text:e,activeTools:t,isThinking:r=!1}){let i=t.length>0,a=e.length>0;return!i&&!a?Tn(r):(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[i&&En(t),a&&(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:`Robota:`}),(0,o.jsx)(n.Text,{children:` `}),(0,o.jsx)(n.Box,{marginLeft:2,children:(0,o.jsx)(n.Text,{wrap:`wrap`,children:Et(e)})})]})]})}function On({entry:e,selected:t}){let r=e.config.enabled,i=r?`●`:`○`,a=r?`[enabled] `:`[disabled]`,s=e.config.options?.port,c=typeof s==`number`?`port: ${s}`:``;return(0,o.jsx)(n.Box,{children:(0,o.jsx)(n.Text,{color:t?`cyan`:void 0,bold:t,children:`${i} ${e.transport.name.padEnd(18)} ${a} ${c}`})})}function kn(e,t,i,a,o,s,c,l){(0,n.useInput)((0,r.useCallback)((n,r)=>{if(!i){if(r.upArrow){o(e=>Math.max(0,e-1));return}if(r.downArrow){o(t=>Math.min(e.length-1,t+1));return}if(r.escape||r.return){c();return}if(n===` `){let n=e[t];if(!n)return;s(!0),a.setEnabled(n.transport.name,!n.config.enabled).then(()=>{l(),s(!1)}).catch(()=>s(!1))}}},[i,e,t,a,c,l,o,s]))}function An({registry:e,onClose:t}){let[i,a]=(0,r.useState)(()=>e.getAll()),[s,c]=(0,r.useState)(0),[l,u]=(0,r.useState)(!1);return kn(i,s,l,e,c,u,t,(0,r.useCallback)(()=>{a(e.getAll())},[e])),(0,o.jsxs)(n.Box,{flexDirection:`column`,paddingX:2,paddingY:1,children:[(0,o.jsx)(n.Text,{bold:!0,children:`Settings › Transports`}),(0,o.jsx)(n.Box,{marginTop:1,flexDirection:`column`,children:i.map((e,t)=>(0,o.jsx)(On,{entry:e,selected:t===s},e.transport.name))}),(0,o.jsx)(n.Box,{marginTop:1,children:(0,o.jsx)(n.Text,{dimColor:!0,children:`↑↓ select space toggle enter/esc close`})}),l&&(0,o.jsx)(n.Box,{marginTop:1,children:(0,o.jsx)(n.Text,{color:`yellow`,children:`Saving…`})})]})}function jn({message:e}){return(0,o.jsx)(n.Box,{paddingX:1,marginBottom:1,children:(0,o.jsx)(n.Text,{color:`yellow`,children:e})})}function Mn(e){let[t,n]=(0,r.useState)({channel:e.channel,sessionId:e.resumeSessionId}),[i,a]=(0,r.useState)(e.showSessionPickerOnStart??!1);return(0,o.jsx)(H,{value:e.cliAdapter,children:(0,o.jsx)(Nn,{...e,channel:t.channel,showSessionPickerOnStart:i,resumeSessionId:t.sessionId,onSessionSwitch:r=>{a(!1);let i=t.channel;n({channel:e.createChannel?e.createChannel(r):e.channel,sessionId:r}),i.stop()}},t.sessionId??`__new__`)})}function Nn(e){let i=e.cwd,{channel:s}=e,{interactiveSession:c,registry:l,commandEffectQueue:u,history:d,addEntry:f,streamingText:h,activeTools:g,isThinking:_,isAborting:v,isShuttingDown:y,pendingPrompt:b,executionWorkspaceSnapshot:x,selectedExecutionEntryId:S,selectExecutionWorkspaceEntry:C,readExecutionWorkspaceDetail:w,permissionRequest:O,contextState:k,handleSubmit:A,handleAbort:j,handleCancelQueue:M,handleShutdown:N}=le(s),[P,F]=(0,r.useState)(s.sessionName),I=ne(i),te=c?void 0:I,{exit:L}=(0,n.useApp)(),[R,z]=(0,r.useState)(),[B,V]=(0,r.useState)(!1),[re,ie]=(0,r.useState)(null),[ae,H]=(0,r.useState)(),[U,W]=(0,r.useState)(!1),[se,ue]=ce(),[G,de]=(0,r.useState)(0),fe=(0,r.useMemo)(()=>p(x),[x]),pe=m(x),K=(0,r.useMemo)(()=>x?.entries.find(e=>e.id===S),[x,S]),{handleSubmit:me,pendingInteractionPrompt:q,showPluginTUI:J,showSessionPicker:Y,showTransportTUI:X,setShowPluginTUI:he,setShowSessionPicker:ge,setShowTransportTUI:_e,handleInteractionSubmit:ve,handleInteractionCancel:ye}=oe({cwd:i,providerOverride:e.providerOverride,interactiveSession:c,commandEffectQueue:u,addEntry:f,baseHandleSubmit:A,setSessionName:F,setStatusLineSettings:ue,showSessionPickerOnStart:e.showSessionPickerOnStart,openAgentSwitcher:()=>V(!0)});(0,r.useEffect)(()=>(s.start(),()=>{s.stop()}),[s]);let be=!K||K.kind===`main_thread`||K.controls.includes(`send`),xe=K&&K.kind!==`main_thread`?K.title:void 0,Z=(0,r.useMemo)(()=>x?.entries.find(e=>e.kind===`main_thread`)?.id,[x]),Se=(0,r.useCallback)(async e=>{K&&K.kind!==`main_thread`&&K.controls.includes(`send`)?await c.sendAgentJob(K.sourceId,e):await me(e)},[K,me,c]),Ce=(0,r.useCallback)(async e=>{de(e=>e+1),await Se(e)},[Se]),Q=(0,r.useRef)(!1);(0,r.useEffect)(()=>{Q.current&&!_&&de(e=>e+1),Q.current=_},[_]),(0,r.useEffect)(()=>{let e=c?.getName?.();e&&!P&&F(e)},[c,P]),(0,r.useEffect)(()=>{let t=!0;return e.startupUpdateNotice?.then(e=>{t&&e!==void 0&&z(e)}).catch(()=>{}),()=>{t=!1}},[e.startupUpdateNotice]),(0,r.useEffect)(()=>{let e=P?`Robota — ${P}`:`Robota`;process.stdout.write(`\x1b]0;${e}\x07`)},[P]),(0,n.useInput)((e,t)=>{!t.escape||!_||O||J||X||Y||B||j()}),(0,n.useInput)((e,t)=>{!t.ctrl||e!==`b`||O||J||Y||y||V(e=>!e)}),(0,n.useInput)((e,t)=>{!t.escape||_||O||J||X||Y||B||K&&K.kind!==`main_thread`&&Z!==void 0&&C(Z)}),(0,n.useInput)((e,t)=>{!t.ctrl||e!==`c`||y||N(`prompt_input_exit`).finally(()=>L())}),(0,r.useEffect)(()=>{let e=()=>{y||N(`other`).finally(()=>L())};return process.once(`SIGINT`,e),process.once(`SIGTERM`,e),()=>{process.off(`SIGINT`,e),process.off(`SIGTERM`,e)}},[N,L,y]),(0,r.useEffect)(()=>{if(!K||K.kind===`main_thread`){ie(null),H(void 0),W(!1);return}let e=!0;return W(!0),H(void 0),w(K.id).then(t=>{e&&(ie(t),W(!1))}).catch(t=>{e&&(H(t.message),W(!1))}),()=>{e=!1}},[x,w,K]);let $=e.permissionMode??`default`,we=``;try{let e=c.getSession();$=e.getPermissionMode(),we=e.getSessionId()}catch{}return(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[(0,o.jsx)(n.Static,{items:[{version:e.version??`0.0.0`}],children:e=>(0,o.jsxs)(n.Box,{flexDirection:`column`,paddingX:1,marginBottom:1,children:[(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:`
|
|
19
19
|
____ ___ ____ ___ _____ _
|
|
20
20
|
| _ \\ / _ \\| __ ) / _ \\_ _|/ \\
|
|
21
21
|
| |_) | | | | _ \\| | | || | / _ \\
|
|
22
22
|
| _ <| |_| | |_) | |_| || |/ ___ \\
|
|
23
23
|
|_| \\_\\\\___/|____/ \\___/ |_/_/ \\_\\
|
|
24
|
-
`}),(0,o.jsxs)(n.Text,{dimColor:!0,children:[` v`,e.version]})]},`logo`)}),R&&(0,o.jsx)(jn,{message:R}),(0,o.jsxs)(n.Box,{flexDirection:`column`,paddingX:1,flexGrow:1,children:[K&&K.kind!==`main_thread`?(0,o.jsx)(D,{entry:K,page:re,loading:U,error:ae}):(0,o.jsx)(Wt,{history:d}),y&&(0,o.jsx)(n.Box,{marginBottom:1,children:(0,o.jsx)(n.Text,{color:`yellow`,children:`Shutting down...`})}),(_||g.length>0)&&(0,o.jsx)(n.Box,{flexDirection:`column`,marginBottom:1,children:(0,o.jsx)(Dn,{text:h,activeTools:g,isThinking:_})}),(0,o.jsx)(T,{entries:fe})]}),B&&(0,o.jsx)(ee,{snapshot:x,selectedEntryId:S,onSelect:C,onClose:()=>V(!1)}),O&&(0,o.jsx)(Zt,{request:O}),q&&(0,o.jsx)(rt,{prompt:q,onSubmit:ve,onCancel:ye}),J&&(0,o.jsx)(dn,{callbacks:te,onClose:()=>he(!1),addMessage:e=>f((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(e.content)))}),X&&e.transportRegistry&&(0,o.jsx)(An,{registry:e.transportRegistry,onClose:()=>_e(!1)}),Y&&(0,o.jsx)(fn,{sessions:(0,t.listResumableSessionSummaries)(e.sessionStore,e.cwd),onSelect:t=>{ge(!1),e.onSessionSwitch(t)},onCancel:()=>{ge(!1),f((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`Session resume cancelled.`)))}}),(0,o.jsx)(E,{percentage:k.percentage}),(0,o.jsx)(Cn,{cwd:i,permissionMode:$,modelId:e.modelId,providerType:e.providerType,sessionId:we,isThinking:_,activeToolCount:g.length,activeBackgroundTaskCount:pe,hasPendingPrompt:b!==null,contextState:k,sessionName:P,settings:se,activeAgentLabel:xe,gitRefreshToken:G}),(0,o.jsx)(Ye,{onSubmit:Ce,onCancelQueue:M,isDisabled:!!O||J||X||Y||B||y||q!==null||_&&!!b||!be,isAborting:v,pendingPrompt:b,registry:l,sessionName:P,history:d}),(0,o.jsx)(n.Box,{position:`absolute`,children:(0,o.jsx)(n.Text,{children:` `})})]})}var Pn=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 Fn(e,t,n,r,i,o){let s=In(e.effects,n,r,o);if(r.addEntry((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(e.message))),e.interaction!==void 0&&i.enqueueInteraction(e.interaction),s.length>0&&i.enqueueEffects(s),t.isInitialized){let e=t.getContextState();r.setContextState({percentage:e.usedPercentage,usedTokens:e.usedTokens,maxTokens:e.maxTokens})}}function In(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 Ln(e){return e.toLowerCase().replace(/[^a-z0-9\s-]/g,``).trim().replace(/\s+/g,`-`).replace(/-+/g,`-`).slice(0,60)}async function Rn(e,t){let n=t.slice(0,200),r=await e.chat([(0,a.createSystemMessage)(`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.`),(0,a.createUserMessage)(n)],{maxTokens:20}),i=Ln(typeof r.content==`string`?r.content:``);return!i||i.length<3?Ln(t):i}function zn(e,t){let n=null;return{schedule(){n||=setTimeout(()=>{n=null,e()},t)},flush(){n&&=(clearTimeout(n),null)}}}var Bn=class{history=[];streamingText=``;activeTools=[];isThinking=!1;isAborting=!1;pendingPrompt=null;contextState={percentage:0,usedTokens:0,maxTokens:0};executionWorkspaceSnapshot=null;selectedExecutionEntryId;onChange=null;streamBuf=``;debouncedStreamNotify=zn(()=>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())}},Vn=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 Bn,this.stateManager.onChange=()=>this.onChange?.(),this.interactiveSession=this.createSession(),this.registry=this.createRegistry(),this.commandEffectQueue=new Pn}createSession(){let e=this.opts;return new t.InteractiveSession({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 e=new t.CommandRegistry;for(let t of this.opts.commandModules??[])e.addModule(t);return this.opts.reloadPluginCommandSource?.(e),e}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((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`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}Fn(i,this.interactiveSession,this.registry,this.stateManager,this.commandEffectQueue,this.opts.reloadPluginCommandSource);return}this.stateManager.addEntry((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`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((0,a.messageToHistoryEntry)((0,a.createUserMessage)(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,Rn(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 Hn(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 Vn({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(0,n.render)((0,o.jsx)(Mn,{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 Un=class{name=`tui`;defaultEnabled=!0;optionsSchema={};options;constructor(e){this.options=e}attach(e){}async start(){await Hn(this.options)}async stop(){}validateOptions(e){return!0}};function Wn({providerDefinitions:e,reloadPluginCommandSource:n}){return{getUserSettingsPath:()=>(0,t.getUserSettingsPath)(),readSettings:e=>(0,t.readSettings)(e),writeSettings:(e,n)=>(0,t.writeSettings)(e,n),deleteSettings:e=>(0,t.deleteSettings)(e),applyStatusLineSettings:(e,n)=>(0,t.applyStatusLineSettings)(e,n),reloadPluginCommandSource:e=>{n(e)},applyActiveModelChange:(e,n,r)=>((0,t.applyActiveModelChange)(e,n,r),{applied:!0}),getGitBranch:e=>(0,t.resolveGitBranch)(e),getProviderDisplayName:t=>(0,a.findProviderDefinition)(e,t)?.displayName??t}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return Un}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return Hn}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return Wn}});
|
|
24
|
+
`}),(0,o.jsxs)(n.Text,{dimColor:!0,children:[` v`,e.version]})]},`logo`)}),R&&(0,o.jsx)(jn,{message:R}),(0,o.jsxs)(n.Box,{flexDirection:`column`,paddingX:1,flexGrow:1,children:[K&&K.kind!==`main_thread`?(0,o.jsx)(D,{entry:K,page:re,loading:U,error:ae}):(0,o.jsx)(Wt,{history:d}),y&&(0,o.jsx)(n.Box,{marginBottom:1,children:(0,o.jsx)(n.Text,{color:`yellow`,children:`Shutting down...`})}),(_||g.length>0)&&(0,o.jsx)(n.Box,{flexDirection:`column`,marginBottom:1,children:(0,o.jsx)(Dn,{text:h,activeTools:g,isThinking:_})}),(0,o.jsx)(T,{entries:fe})]}),B&&(0,o.jsx)(ee,{snapshot:x,selectedEntryId:S,onSelect:C,onClose:()=>V(!1)}),O&&(0,o.jsx)(Zt,{request:O}),q&&(0,o.jsx)(rt,{prompt:q,onSubmit:ve,onCancel:ye}),J&&(0,o.jsx)(dn,{callbacks:te,onClose:()=>he(!1),addMessage:e=>f((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(e.content)))}),X&&e.transportRegistry&&(0,o.jsx)(An,{registry:e.transportRegistry,onClose:()=>_e(!1)}),Y&&(0,o.jsx)(fn,{sessions:(0,t.listResumableSessionSummaries)(e.sessionStore,e.cwd),onSelect:t=>{ge(!1),e.onSessionSwitch(t)},onCancel:()=>{ge(!1),f((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`Session resume cancelled.`)))}}),(0,o.jsx)(E,{percentage:k.percentage}),(0,o.jsx)(Cn,{cwd:i,permissionMode:$,modelId:e.modelId,providerType:e.providerType,sessionId:we,isThinking:_,activeToolCount:g.length,activeBackgroundTaskCount:pe,hasPendingPrompt:b!==null,contextState:k,sessionName:P,settings:se,activeAgentLabel:xe,gitRefreshToken:G}),(0,o.jsx)(Ye,{onSubmit:Ce,onCancelQueue:M,isDisabled:!!O||J||X||Y||B||y||q!==null||_&&!!b||!be,isAborting:v,pendingPrompt:b,registry:l,sessionName:P,history:d}),(0,o.jsx)(n.Box,{position:`absolute`,children:(0,o.jsx)(n.Text,{children:` `})})]})}var Pn=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 Fn(e,t,n,r,i,o){let s=In(e.effects,n,r,o);if(r.addEntry((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(e.message))),e.interaction!==void 0&&i.enqueueInteraction(e.interaction),s.length>0&&i.enqueueEffects(s),t.isInitialized){let e=t.getContextState();r.setContextState({percentage:e.usedPercentage,usedTokens:e.usedTokens,maxTokens:e.maxTokens})}}function In(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 Ln(e){return e.toLowerCase().replace(/[^a-z0-9\s-]/g,``).trim().replace(/\s+/g,`-`).replace(/-+/g,`-`).slice(0,60)}async function Rn(e,t){let n=t.slice(0,200),r=await e.chat([(0,a.createSystemMessage)(`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.`),(0,a.createUserMessage)(n)],{maxTokens:20}),i=Ln(typeof r.content==`string`?r.content:``);return!i||i.length<3?Ln(t):i}function zn(e,t){let n=null;return{schedule(){n||=setTimeout(()=>{n=null,e()},t)},flush(){n&&=(clearTimeout(n),null)}}}var Bn=class{history=[];streamingText=``;activeTools=[];isThinking=!1;isAborting=!1;pendingPrompt=null;contextState={percentage:0,usedTokens:0,maxTokens:0};executionWorkspaceSnapshot=null;selectedExecutionEntryId;onChange=null;streamBuf=``;debouncedStreamNotify=zn(()=>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())}},Vn=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 Bn,this.stateManager.onChange=()=>this.onChange?.(),this.interactiveSession=this.createSession(),this.registry=this.createRegistry(),this.commandEffectQueue=new Pn}createSession(){let e=this.opts;return new t.InteractiveSession({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 e=new t.CommandRegistry;for(let t of this.opts.commandModules??[])e.addModule(t);return this.opts.reloadPluginCommandSource?.(e),e}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((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`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}Fn(i,this.interactiveSession,this.registry,this.stateManager,this.commandEffectQueue,this.opts.reloadPluginCommandSource);return}this.stateManager.addEntry((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`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((0,a.messageToHistoryEntry)((0,a.createUserMessage)(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,Rn(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 Hn(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 Vn({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}),r=t(e.resumeSessionId);await(0,n.render)((0,o.jsx)(Mn,{cwd:e.cwd,channel:r,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 Un=class{name=`tui`;defaultEnabled=!0;optionsSchema={};options;constructor(e){this.options=e}attach(e){}async start(){await Hn(this.options)}async stop(){}validateOptions(e){return!0}};function Wn({providerDefinitions:e,reloadPluginCommandSource:n}){return{getUserSettingsPath:()=>(0,t.getUserSettingsPath)(),readSettings:e=>(0,t.readSettings)(e),writeSettings:(e,n)=>(0,t.writeSettings)(e,n),deleteSettings:e=>(0,t.deleteSettings)(e),applyStatusLineSettings:(e,n)=>(0,t.applyStatusLineSettings)(e,n),reloadPluginCommandSource:e=>{n(e)},applyActiveModelChange:(e,n,r)=>((0,t.applyActiveModelChange)(e,n,r),{applied:!0}),getGitBranch:e=>(0,t.resolveGitBranch)(e),getProviderDisplayName:t=>(0,a.findProviderDefinition)(e,t)?.displayName??t}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return Un}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return Hn}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return Wn}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robota-sdk/agent-transport",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.71",
|
|
4
4
|
"description": "Consolidated transport package for Robota SDK — headless, HTTP, WebSocket, and MCP adapters",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/node/index.js",
|
|
@@ -108,10 +108,10 @@
|
|
|
108
108
|
"string-width": "^8.2.0",
|
|
109
109
|
"ws": "^8.18.3",
|
|
110
110
|
"zod": "^3.24.4",
|
|
111
|
-
"@robota-sdk/agent-core": "3.0.0-beta.
|
|
112
|
-
"@robota-sdk/agent-interface-transport": "3.0.0-beta.
|
|
113
|
-
"@robota-sdk/agent-
|
|
114
|
-
"@robota-sdk/agent-
|
|
111
|
+
"@robota-sdk/agent-core": "3.0.0-beta.71",
|
|
112
|
+
"@robota-sdk/agent-interface-transport": "3.0.0-beta.71",
|
|
113
|
+
"@robota-sdk/agent-framework": "3.0.0-beta.71",
|
|
114
|
+
"@robota-sdk/agent-interface-tui": "3.0.0-beta.71"
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
117
|
"@homebridge/node-pty-prebuilt-multiarch": "^0.13.1",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
"tsx": "^4.7.0",
|
|
125
125
|
"typescript": "^5.3.3",
|
|
126
126
|
"vitest": "^1.6.1",
|
|
127
|
-
"@robota-sdk/agent-command": "3.0.0-beta.
|
|
127
|
+
"@robota-sdk/agent-command": "3.0.0-beta.71"
|
|
128
128
|
},
|
|
129
129
|
"license": "MIT",
|
|
130
130
|
"publishConfig": {
|
package/src/tui/App.tsx
CHANGED
|
@@ -40,6 +40,7 @@ import type { ITransportRegistryView } from '@robota-sdk/agent-interface-transpo
|
|
|
40
40
|
interface IProps {
|
|
41
41
|
cwd: string;
|
|
42
42
|
channel: TuiInteractionChannel;
|
|
43
|
+
createChannel?: (resumeSessionId?: string) => TuiInteractionChannel;
|
|
43
44
|
providerOverride?: string | undefined;
|
|
44
45
|
providerType?: string | undefined;
|
|
45
46
|
modelId?: string;
|
|
@@ -54,7 +55,10 @@ interface IProps {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
export default function App(props: IProps): React.ReactElement {
|
|
57
|
-
const [
|
|
58
|
+
const [sessionState, setSessionState] = useState<{
|
|
59
|
+
channel: TuiInteractionChannel;
|
|
60
|
+
sessionId: string | undefined;
|
|
61
|
+
}>({ channel: props.channel, sessionId: props.resumeSessionId });
|
|
58
62
|
const [showInitialSessionPicker, setShowInitialSessionPicker] = useState(
|
|
59
63
|
props.showSessionPickerOnStart ?? false,
|
|
60
64
|
);
|
|
@@ -62,13 +66,17 @@ export default function App(props: IProps): React.ReactElement {
|
|
|
62
66
|
return (
|
|
63
67
|
<TuiCliAdapterProvider value={props.cliAdapter}>
|
|
64
68
|
<AppInner
|
|
65
|
-
key={
|
|
69
|
+
key={sessionState.sessionId ?? '__new__'}
|
|
66
70
|
{...props}
|
|
71
|
+
channel={sessionState.channel}
|
|
67
72
|
showSessionPickerOnStart={showInitialSessionPicker}
|
|
68
|
-
resumeSessionId={
|
|
73
|
+
resumeSessionId={sessionState.sessionId}
|
|
69
74
|
onSessionSwitch={(sessionId) => {
|
|
70
75
|
setShowInitialSessionPicker(false);
|
|
71
|
-
|
|
76
|
+
const oldChannel = sessionState.channel;
|
|
77
|
+
const newChannel = props.createChannel ? props.createChannel(sessionId) : props.channel;
|
|
78
|
+
setSessionState({ channel: newChannel, sessionId });
|
|
79
|
+
void oldChannel.stop();
|
|
72
80
|
}}
|
|
73
81
|
/>
|
|
74
82
|
</TuiCliAdapterProvider>
|
package/src/tui/render.tsx
CHANGED
|
@@ -58,30 +58,34 @@ export async function renderApp(options: IRenderOptions): Promise<void> {
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
61
|
+
const createChannel = (resumeSessionId?: string): TuiInteractionChannel =>
|
|
62
|
+
new TuiInteractionChannel({
|
|
63
|
+
cwd: options.cwd,
|
|
64
|
+
provider: options.provider,
|
|
65
|
+
permissionMode: options.permissionMode,
|
|
66
|
+
maxTurns: options.maxTurns,
|
|
67
|
+
sessionStore: options.sessionStore,
|
|
68
|
+
resumeSessionId,
|
|
69
|
+
forkSession: options.forkSession,
|
|
70
|
+
sessionName: options.sessionName,
|
|
71
|
+
backgroundTaskRunners: options.backgroundTaskRunners,
|
|
72
|
+
subagentRunnerFactory: options.subagentRunnerFactory,
|
|
73
|
+
commandModules: options.commandModules,
|
|
74
|
+
commandHostAdapters: options.commandHostAdapters,
|
|
75
|
+
shellExec: options.shellExec,
|
|
76
|
+
transportRegistry: options.transportRegistry,
|
|
77
|
+
language: options.language,
|
|
78
|
+
reloadPluginCommandSource: options.reloadPluginCommandSource,
|
|
79
|
+
agentName: options.agentName,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const channel = createChannel(options.resumeSessionId);
|
|
80
83
|
|
|
81
84
|
const instance = render(
|
|
82
85
|
<App
|
|
83
86
|
cwd={options.cwd}
|
|
84
87
|
channel={channel}
|
|
88
|
+
createChannel={createChannel}
|
|
85
89
|
providerOverride={options.providerOverride}
|
|
86
90
|
providerType={options.providerType}
|
|
87
91
|
modelId={options.modelId}
|