@robota-sdk/agent-transport 3.0.0-beta.69 → 3.0.0-beta.70
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/headless/index.cjs +1 -1
- package/dist/node/headless/index.d.ts +2 -2
- package/dist/node/headless/index.js +1 -1
- package/dist/node/headless-C6tj35h3.js +15 -0
- package/dist/node/headless-C6tj35h3.js.map +1 -0
- package/dist/node/headless-DCtHvyVf.cjs +14 -0
- package/dist/node/http/index.d.ts +1 -1
- package/dist/node/index-27HV5PJB.d.ts +68 -0
- package/dist/node/index-27HV5PJB.d.ts.map +1 -0
- package/dist/node/index-BRchlFBE.d.ts +68 -0
- package/dist/node/index-BRchlFBE.d.ts.map +1 -0
- package/dist/node/{index-C7DvsmEg.d.ts → index-BRgV_MPB.d.ts} +2 -2
- package/dist/node/{index-C7DvsmEg.d.ts.map → index-BRgV_MPB.d.ts.map} +1 -1
- package/dist/node/{index-D-aT_t_N.d.ts → index-BVNhOeeU.d.ts} +3 -2
- package/dist/node/{index-D-aT_t_N.d.ts.map → index-BVNhOeeU.d.ts.map} +1 -1
- package/dist/node/{index-yvGShbDx.d.ts → index-COWvtBa2.d.ts} +2 -2
- package/dist/node/{index-yvGShbDx.d.ts.map → index-COWvtBa2.d.ts.map} +1 -1
- package/dist/node/{index-ioN9mYAD.d.ts → index-TMAlNHuM.d.ts} +5 -4
- package/dist/node/{index-ioN9mYAD.d.ts.map → index-TMAlNHuM.d.ts.map} +1 -1
- package/dist/node/{index-DOA2KIYt.d.ts → index-nBlMTFkZ.d.ts} +2 -2
- package/dist/node/{index-DOA2KIYt.d.ts.map → index-nBlMTFkZ.d.ts.map} +1 -1
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.d.ts +7 -7
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/mcp/index.d.ts +1 -1
- package/dist/node/tui/index.cjs +1 -1
- package/dist/node/tui/index.d.ts +2 -2
- package/dist/node/tui/index.js +1 -1
- package/dist/node/tui-Cf1-zocr.js +25 -0
- package/dist/node/tui-Cf1-zocr.js.map +1 -0
- package/dist/node/tui-re-S-CGS.cjs +24 -0
- package/dist/node/ws/index.d.ts +1 -1
- package/package.json +6 -6
- package/src/headless/HeadlessInteractionChannel.ts +84 -0
- package/src/headless/index.ts +2 -0
- package/src/tui/App.tsx +26 -56
- package/src/tui/InputArea.tsx +3 -59
- package/src/tui/StatusBar.tsx +1 -1
- package/src/tui/TuiInteractionChannel.ts +461 -0
- package/src/tui/__tests__/TuiInteractionChannel.display-contract.test.ts +239 -0
- package/src/tui/__tests__/TuiInteractionChannel.lifecycle.test.ts +294 -0
- package/src/tui/__tests__/TuiInteractionChannel.requestAction.test.ts +124 -0
- package/src/tui/__tests__/compact-event-bridge.test.ts +1 -1
- package/src/tui/__tests__/input-area-flow.test.ts +5 -12
- package/src/tui/flows/input-area-flow.ts +10 -15
- package/src/tui/hooks/use-interactive-session-init.ts +37 -2
- package/src/tui/hooks/useSlashRouting.ts +1 -1
- package/src/tui/hooks/useTuiChannel.ts +95 -0
- package/src/tui/index.ts +2 -1
- package/src/tui/interactions/__tests__/CommandConfirm.test.tsx +124 -0
- package/src/tui/interactions/__tests__/CommandPicker.test.tsx +138 -0
- package/src/tui/render.tsx +39 -1
- package/src/tui/tui-state-manager.ts +2 -1
- package/src/tui/tui-transport.ts +1 -1
- package/dist/node/headless-C-Ezlo9U.js +0 -15
- package/dist/node/headless-C-Ezlo9U.js.map +0 -1
- package/dist/node/headless-Cv-igy49.cjs +0 -14
- package/dist/node/index-CP7kaYMg.d.ts +0 -41
- package/dist/node/index-CP7kaYMg.d.ts.map +0 -1
- package/dist/node/index-Gby9H4q2.d.ts +0 -41
- package/dist/node/index-Gby9H4q2.d.ts.map +0 -1
- package/dist/node/tui-87G6pg3z.js +0 -25
- package/dist/node/tui-87G6pg3z.js.map +0 -1
- package/dist/node/tui-BAtwGilM.cjs +0 -24
- package/src/tui/command-interaction-registry.ts +0 -66
- package/src/tui/hooks/useInteractiveSession.ts +0 -299
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const e=require(`./chunk-Bmb41Sf3.cjs`);let t=require(`@robota-sdk/agent-framework`),n=require(`ink`),r=require(`react`),i=e.t(r,1);r=e.t(r);let a=require(`@robota-sdk/agent-core`),o=require(`react/jsx-runtime`),s=require(`chalk`);s=e.t(s);let c=require(`string-width`);c=e.t(c,1);let l=require(`marked`),u=require(`marked-terminal`);u=e.t(u,1);const d=[`active`,`queued`,`running`,`waiting_permission`,`sleeping`],f=/\s+/g;function p(e){return(e?.entries??[]).filter(e=>e.kind===`background_task`&&e.visibility===`default`)}function m(e){return p(e).filter(e=>d.includes(e.status)).length}function h(e,t={}){let n=e.id===t.selectedEntryId,r={id:e.id,radio:n?`●`:`○`,title:_(e),subtitle:v(e),statusLabel:y(e.status),preview:x(e.preview??e.currentAction),color:b(e),isSelected:n};return{...r,accessibleText:S(r)}}function g(e){let t=e.text.trim().replace(f,` `);return t?t.length>160?`${t.slice(0,160)}...`:t:e.kind}function _(e){return e.kind===`main_thread`?e.title:e.kind===`background_group`?`${e.title} group`:e.taskKind===`agent`?`${e.title} agent`:e.taskKind===`process`?e.title||`Process`:e.taskKind===`scheduled`?e.title||`Scheduled`:e.title}function v(e){return e.kind===`main_thread`?e.subtitle:[e.taskKind,e.subtitle,e.attention===`none`?void 0:e.attention].filter(e=>typeof e==`string`&&e.length>0).join(` · `)||void 0}function y(e){return e.replace(/_/g,` `)}function b(e){return e.attention===`failed`||e.status===`failed`?`red`:e.attention===`permission`||e.status===`waiting_permission`?`yellow`:e.status===`completed`?`green`:e.status===`cancelled`?`yellow`:d.includes(e.status)?`cyan`:`white`}function x(e){return e?.trim().replace(f,` `)||void 0}function S(e){return[e.radio,e.title,e.statusLabel,e.subtitle,e.preview].filter(e=>typeof e==`string`&&e.length>0).join(` · `)}function C(e,t={}){let n=h(e),r=w(e)?`□`:`■`,i=[n.statusLabel,n.subtitle].filter(e=>typeof e==`string`&&e.length>0);return{connector:t.isLast===!1?`├`:`└`,marker:r,color:n.color,label:n.title,segments:i,preview:n.preview,accessibleText:[`${t.isLast===!1?`├`:`└`} ${r} ${n.title}`,...i,n.preview].filter(e=>typeof e==`string`&&e.length>0).join(` · `)}}function w(e){return e.status===`active`||e.status===`queued`||e.status===`running`||e.status===`waiting_permission`||e.status===`sleeping`}function T({entries:e}){return e.length===0?null:(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:`Background work`}),e.map((t,r)=>{let i=C(t,{isLast:r===e.length-1});return(0,o.jsxs)(n.Text,{children:[`${i.connector} `,(0,o.jsx)(n.Text,{color:i.color,children:i.marker}),` ${i.label}`,i.segments.map((e,t)=>(0,o.jsx)(n.Text,{dimColor:!0,children:` · ${e}`},`${e}-${t}`)),i.preview?(0,o.jsx)(n.Text,{dimColor:!0,children:` · ${i.preview}`}):null]},t.id)})]})}function E({percentage:e}){return e>=90?(0,o.jsx)(n.Box,{borderStyle:`single`,borderColor:`red`,paddingX:1,children:(0,o.jsxs)(n.Text,{color:`red`,bold:!0,children:[`⚠ Context at `,Math.round(e),`% — window nearly full. Run /compact to summarize the conversation.`]})}):e>=70?(0,o.jsx)(n.Box,{paddingX:1,children:(0,o.jsxs)(n.Text,{color:`yellow`,children:[`Context at `,Math.round(e),`% — consider running /compact to free up space.`]})}):null}function D({entry:e,page:t,loading:r,error:i}){let a=h(e,{selectedEntryId:e.id}),s=t?.records.slice(-12)??[];return(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:`Viewing ${a.title}`}),(0,o.jsxs)(n.Text,{dimColor:!0,children:[a.statusLabel,a.subtitle?` · ${a.subtitle}`:``,a.preview?` · ${a.preview}`:``]}),r?(0,o.jsx)(n.Text,{dimColor:!0,children:`Loading workspace detail...`}):null,i?(0,o.jsx)(n.Text,{color:`red`,children:i}):null,!r&&!i&&s.length===0?(0,o.jsx)(n.Text,{dimColor:!0,children:`No detail yet`}):null,!r&&!i&&s.map(e=>(0,o.jsx)(n.Text,{color:O(e.kind),children:g(e)},e.id)),t?.nextCursor?(0,o.jsx)(n.Text,{dimColor:!0,children:`... more detail available`}):null]})}function O(e){if(e===`error`)return`red`;if(e===`result`)return`green`;if(e===`process_output`)return`white`;if(e===`group_summary`)return`cyan`}function k(){return{selectedIndex:0,scrollOffset:0,resolved:!1}}function A(e){if(e.escape===!0)return`cancel`;if(e.upArrow===!0)return`previous`;if(e.downArrow===!0)return`next`;if(e.return===!0)return`select`}function j(e){if(e.escape===!0)return`cancel`;if(e.leftArrow===!0||e.upArrow===!0)return`previous`;if(e.rightArrow===!0||e.downArrow===!0)return`next`;if(e.return===!0)return`select`}function M(e,t,n){if(e.resolved)return{state:e,effect:{type:`none`}};if(t===`cancel`)return{state:{...e,resolved:!0},effect:{type:`cancel`}};if(n.enabled===!1||n.itemCount===0)return{state:e,effect:{type:`none`}};if(t===`select`){let t=I(e.selectedIndex,n.itemCount);return{state:{...e,selectedIndex:t,resolved:!0},effect:{type:`select`,index:t}}}let r=P(e.selectedIndex,t,n),i=F(r,e.scrollOffset,n);return{state:{...e,selectedIndex:r,scrollOffset:i},effect:{type:`none`}}}function N(e,t){if(t.itemCount===0)return{...e,selectedIndex:0,scrollOffset:0};let n=I(e.selectedIndex,t.itemCount),r=F(n,e.scrollOffset,t);return n===e.selectedIndex&&r===e.scrollOffset?e:{...e,selectedIndex:n,scrollOffset:r}}function P(e,t,n){return t===`previous`?n.wrap===!0&&e===0?n.itemCount-1:Math.max(0,e-1):n.wrap===!0&&e===n.itemCount-1?0:Math.min(n.itemCount-1,e+1)}function F(e,t,n){let r=n.maxVisible??n.itemCount;return r<=0?0:e<t?e:e>=t+r?e-r+1:Math.max(0,t)}function I(e,t){return Math.min(Math.max(e,0),t-1)}function ee({snapshot:e,selectedEntryId:t,onSelect:r,onClose:i}){let{normalized:a,visibleEntries:s,applyAction:c}=te({entries:[...e?.entries??[]],selectedEntryId:t,onSelect:r,onClose:i});return(0,n.useInput)((e,t)=>{let n=A(t);n!==void 0&&c(n)}),(0,o.jsxs)(n.Box,{flexDirection:`column`,borderStyle:`round`,borderColor:`cyan`,paddingX:1,children:[(0,o.jsx)(n.Text,{color:`cyan`,bold:!0,children:`Execution workspace`}),(0,o.jsx)(n.Box,{flexDirection:`column`,marginTop:1,children:s.length===0?(0,o.jsx)(n.Text,{dimColor:!0,children:`No workspace entries`}):s.map((e,n)=>(0,o.jsx)(z,{entry:e,isFocused:a.scrollOffset+n===a.selectedIndex,selectedEntryId:t},e.id))}),(0,o.jsx)(n.Text,{dimColor:!0,children:`Ctrl+B Close ↑↓ Navigate Enter Switch Esc Close`})]})}function te({entries:e,selectedEntryId:t,onSelect:n,onClose:i}){let[a,o]=(0,r.useState)(()=>k()),s=(0,r.useRef)(a);(0,r.useEffect)(()=>{let n=R({selectedIndex:Math.max(0,e.findIndex(e=>e.id===t)),itemCount:e.length});s.current=n,o(n)},[e.length,t]);let c=R({selectedIndex:a.selectedIndex,scrollOffset:a.scrollOffset,itemCount:e.length});return c!==a&&(s.current=c),{normalized:c,visibleEntries:e.slice(c.scrollOffset,c.scrollOffset+8),applyAction:L({entries:e,stateRef:s,setState:o,onSelect:n,onClose:i})}}function L({entries:e,stateRef:t,setState:n,onSelect:r,onClose:i}){return a=>{let o=M(t.current,a,{itemCount:e.length,maxVisible:8}),s=o.effect.type===`select`||o.effect.type===`cancel`?{...o.state,resolved:!1}:o.state;if(t.current=s,n(s),o.effect.type===`cancel`)i();else if(o.effect.type===`select`){let t=e[o.effect.index];t&&r(t.id)}}}function R(e){return N({selectedIndex:e.selectedIndex,scrollOffset:e.scrollOffset??0,resolved:!1},{itemCount:e.itemCount,maxVisible:8})}function z({entry:e,isFocused:t,selectedEntryId:r}){let i=h(e,{selectedEntryId:r});return(0,o.jsxs)(n.Text,{children:[(0,o.jsx)(n.Text,{color:t?`cyan`:void 0,bold:t,children:t?`> `:` `}),(0,o.jsx)(n.Text,{color:i.color,children:i.radio}),(0,o.jsx)(n.Text,{color:t?`cyan`:void 0,bold:t,children:` ${i.title}`}),(0,o.jsx)(n.Text,{dimColor:!0,children:` · ${i.statusLabel}`}),i.subtitle?(0,o.jsx)(n.Text,{dimColor:!0,children:` · ${i.subtitle}`}):null,i.preview?(0,o.jsx)(n.Text,{dimColor:!0,children:` · ${i.preview}`}):null]})}function B(){return{listInstalled:async()=>[],listAvailablePlugins:async()=>[],install:async()=>void 0,uninstall:async()=>void 0,enable:async()=>void 0,disable:async()=>void 0,marketplaceAdd:async()=>``,marketplaceRemove:async()=>void 0,marketplaceUpdate:async()=>void 0,marketplaceList:async()=>[],reloadPlugins:async()=>({loadedPluginCount:0})}}function ne(e){return(0,i.useMemo)(()=>B(),[])}function V(e,n){for(let r of e){if(r.type===`language-change-requested`)return re(r.language,n),!0;if(r.type===`settings-reset-requested`)return ie(n),!0;if(r.type===`session-exit-requested`)return n.requestShutdown(r.reason??`prompt_input_exit`,r.message??`User requested exit`),!0;if(r.type===`session-restart-requested`)return n.requestShutdown(r.reason,r.message),!0;if(r.type===`plugin-tui-requested`)return n.openPluginTUI(),!0;if(r.type===`settings-tui-requested`)return n.openTransportTUI(),!0;if(r.type===`agent-switcher-requested`)return n.openAgentSwitcher(),!0;if(r.type===`session-picker-requested`)return n.openSessionPicker(),!0;if(r.type===`session-renamed`)return n.renameSession(r.name),!0;if(r.type===`statusline-settings-patch`&&(0,t.isStatusLineCommandSettingsPatch)(r.patch))return n.applyStatusLinePatch(r.patch)}return!1}function re(e,t){let n=t.cliAdapter.getUserSettingsPath(),r=t.cliAdapter.readSettings(n);r.language=e,t.cliAdapter.writeSettings(n,r),t.addEntry((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`Language set to "${e}". Restarting...`))),t.requestShutdown(`other`,`Language change restart`)}function ie(e){let t=e.cliAdapter.getUserSettingsPath();e.cliAdapter.deleteSettings(t)?e.addEntry((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`Deleted ${t}. Exiting...`))):e.addEntry((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`No user settings found.`))),e.requestShutdown(`other`,`Reset settings restart`)}const ae=(0,r.createContext)(null),H=ae.Provider;function U(){let e=(0,r.useContext)(ae);if(!e)throw Error(`TuiCliAdapterContext not provided`);return e}function oe({cwd:e,providerOverride:t,interactiveSession:r,commandEffectQueue:o,addEntry:s,baseHandleSubmit:c,setSessionName:l,setStatusLineSettings:u,showSessionPickerOnStart:d,openAgentSwitcher:f}){let{exit:p}=(0,n.useApp)(),m=U(),[h,g]=(0,i.useState)(null),_=(0,i.useRef)(null),[v,y]=(0,i.useState)(!1),[b,x]=(0,i.useState)(d??!1),[S,C]=(0,i.useState)(!1),w=(0,i.useCallback)((e,t)=>{s((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`Shutting down...`))),setTimeout(()=>{r.shutdown({reason:e,message:t}).finally(()=>p())},500)},[r,s,p]),T=(0,i.useCallback)(e=>V(e,{addEntry:s,requestShutdown:w,openPluginTUI:()=>y(!0),openSessionPicker:()=>x(!0),openTransportTUI:()=>C(!0),openAgentSwitcher:()=>f?.(),renameSession:e=>{r.setName(e),l(e)},applyStatusLinePatch:e=>(u(m.applyStatusLineSettings(m.getUserSettingsPath(),e)),!0),cliAdapter:m}),[s,m,r,w,l,u]),E=(0,i.useCallback)(e=>{if(e.message.length>0&&s((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(e.message))),e.interaction!==void 0){_.current=e.interaction,g(e.interaction.prompt);return}_.current=null,g(null),e.effects!==void 0&&e.effects.length>0&&T(e.effects)},[s,T]),D=(0,i.useCallback)(()=>{let e=o.drain();if(e===void 0)return!1;if(e.type===`interaction`){let{interaction:t}=e;return _.current=t,g(t.prompt),!0}return T(e.effects)},[T,o]);return{handleSubmit:(0,i.useCallback)(async e=>{await c(e),D()},[c,D]),pendingInteractionPrompt:h,showPluginTUI:v,showSessionPicker:b,showTransportTUI:S,setShowPluginTUI:y,setShowSessionPicker:x,setShowTransportTUI:C,handleInteractionSubmit:(0,i.useCallback)(async e=>{let t=_.current;if(t===null){g(null);return}try{E(await t.submit(e))}catch(e){_.current=null,g(null),s((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`Failed: ${e instanceof Error?e.message:String(e)}`)))}},[s,E]),handleInteractionCancel:(0,i.useCallback)(()=>{let e=_.current;if(_.current=null,g(null),e?.cancel===void 0){s((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`Command interaction cancelled.`)));return}Promise.resolve(e.cancel()).then(e=>E(e)).catch(e=>{s((0,a.messageToHistoryEntry)((0,a.createSystemMessage)(`Failed: ${e instanceof Error?e.message:String(e)}`)))})},[s,E])}}function W(e){let n={...t.DEFAULT_STATUS_LINE_COMMAND_SETTINGS},r=e.statusline;return se(r)?{enabled:typeof r.enabled==`boolean`?r.enabled:n.enabled,gitBranch:typeof r.gitBranch==`boolean`?r.gitBranch:n.gitBranch}:n}function se(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Date)}function ce(){let e=U();return(0,i.useState)(()=>W(e.readSettings(e.getUserSettingsPath())))}function le(e){let[,t]=(0,i.useState)(0);(0,i.useEffect)(()=>(e.onChange=()=>t(e=>e+1),()=>{e.onChange=null}),[e]);let n=e.stateManager;return{interactiveSession:e.getSession(),registry:e.getRegistry(),commandEffectQueue:e.getCommandEffectQueue(),history:n.history,addEntry:e=>n.addEntry(e),streamingText:n.streamingText,activeTools:n.activeTools,isThinking:n.isThinking,isAborting:n.isAborting,isShuttingDown:e.isShuttingDown,pendingPrompt:n.pendingPrompt,executionWorkspaceSnapshot:n.executionWorkspaceSnapshot,selectedExecutionEntryId:n.selectedExecutionEntryId,permissionRequest:e.permissionRequest,contextState:n.contextState,handleSubmit:t=>e.handleInput(t),handleAbort:()=>e.abort(),handleCancelQueue:()=>e.cancelQueue(),handleShutdown:t=>e.shutdown({reason:t}),selectExecutionWorkspaceEntry:t=>e.selectExecutionWorkspaceEntry(t),readExecutionWorkspaceDetail:t=>e.readExecutionWorkspaceDetail(t)}}const ue=`[200~`,G=`[201~`;function de(e){return{value:e,cursor:e.length,isPasting:!1,pasteBuffer:``}}function fe(e,t,n){return t===e.value?e:{...e,value:t,cursor:n==null?t.length:Math.min(n,t.length)}}function pe(e,t,n,r){let i=me(e,t,r);if(i!==void 0)return i;let a=q(e,t,n,r);if(a!==void 0)return a;let o=J(e,n,r);return o===void 0?Z(e,t):o}function K(e,t,n){let r=t.replace(/\r\n?/g,`
|
|
2
|
+
`);return r.length===0?{state:e,effect:{type:`none`}}:r.includes(`
|
|
3
|
+
`)&&n.canPaste?{state:e,effect:{type:`paste`,text:r,cursor:e.cursor}}:Z(e,r)}function me(e,t,n){if(t===ue||t.startsWith(ue))return _e(e,t);if(e.isPasting)return ve(e,t,n)}function q(e,t,n,r){if(n.ctrl===!0&&t===`c`||n.tab===!0)return{state:e,effect:{type:`none`}};if(n.return===!0)return{state:e,effect:{type:`submit`,value:e.value}};if(t.length>1&&(t.includes(`
|
|
4
|
+
`)||t.includes(`\r`))&&r.canPaste)return{state:e,effect:{type:`paste`,text:t.replace(/\r\n?/g,`
|
|
5
|
+
`),cursor:e.cursor}}}function J(e,t,n){if(t.upArrow===!0||t.downArrow===!0)return n.enableVerticalNavigation===!1?{state:e,effect:{type:`none`}}:ye(e,t.upArrow===!0?`up`:`down`,n.availableWidth);if(t.leftArrow===!0)return be(e,`left`);if(t.rightArrow===!0)return be(e,`right`);if(t.backspace===!0||t.delete===!0)return xe(e)}function Y(e){if(!e||e.length===0)return``;let t=``;for(let n of e){let e=n.charCodeAt(0);e>31&&e!==127&&(t+=n)}return t}function X(e,t,n){return{value:e.slice(0,t)+n+e.slice(t),cursor:t+n.length}}function he(e,t,n){let r=0;for(let i=0;i<t&&i<e.length;i++){let t=(0,c.default)(e[i]),a=r%n;a+t>n&&(r+=n-a),r+=t}return r}function ge(e,t,n){let r=0;for(let i=0;i<e.length;i++){if(r>=t)return i;let a=(0,c.default)(e[i]),o=r%n;o+a>n&&(r+=n-o),r+=a}return e.length}function _e(e,t){return{state:{...e,isPasting:!0,pasteBuffer:t.slice(5)},effect:{type:`none`}}}function ve(e,t,n){if(t!==G&&!t.includes(G))return{state:{...e,pasteBuffer:e.pasteBuffer+t},effect:{type:`none`}};let r=t.split(G)[0]??``;return K({...e,isPasting:!1,pasteBuffer:``},e.pasteBuffer+r,n)}function ye(e,t,n){if(!n||n<=0)return{state:e,effect:{type:`none`}};let r=[...e.value],i=he(r,e.cursor,n),a=t===`up`?i-n:i+n;if(a<0)return{state:e,effect:{type:`none`}};let o=ge(r,a,n);return o===e.cursor?{state:e,effect:{type:`none`}}:{state:{...e,cursor:o},effect:{type:`render`}}}function be(e,t){return t===`left`&&e.cursor>0?{state:{...e,cursor:e.cursor-1},effect:{type:`render`}}:t===`right`&&e.cursor<e.value.length?{state:{...e,cursor:e.cursor+1},effect:{type:`render`}}:{state:e,effect:{type:`none`}}}function xe(e){if(e.cursor===0)return{state:e,effect:{type:`none`}};let t=e.value.slice(0,e.cursor-1)+e.value.slice(e.cursor);return{state:{...e,value:t,cursor:e.cursor-1},effect:{type:`change`,value:t}}}function Z(e,t){let n=Y(t);if(n.length===0)return{state:e,effect:{type:`none`}};let r=X(e.value,e.cursor,n);return{state:{...e,value:r.value,cursor:r.cursor},effect:{type:`change`,value:r.value}}}function Se({value:e,onChange:t,onSubmit:i,onPaste:a,placeholder:s=``,focus:c=!0,showCursor:l=!0,availableWidth:u,cursorHint:d=null,enableVerticalNavigation:f=!0}){let p=(0,r.useRef)(de(e)),[,m]=(0,r.useState)(0);return p.current=fe(p.current,e,d),Ce({stateRef:p,onChange:t,onSubmit:i,onPaste:a,availableWidth:u,focus:c,enableVerticalNavigation:f,forceRender:m}),(0,o.jsx)(n.Text,{children:Te(p.current.value,p.current.cursor,s,l&&c)})}function Ce(e){(0,n.usePaste)(t=>{$(e,()=>K(e.stateRef.current,t,Q(e)))},{isActive:e.focus}),(0,n.useInput)((t,n)=>{$(e,()=>pe(e.stateRef.current,t,n,Q(e)))},{isActive:e.focus})}function Q(e){return{availableWidth:e.availableWidth,canPaste:e.onPaste!==void 0,enableVerticalNavigation:e.enableVerticalNavigation}}function $(e,t){try{let n=t();e.stateRef.current=n.state,we(n.effect,e.onChange,e.onSubmit,e.onPaste,e.forceRender)}catch{}}function we(e,t,n,r,i){e.type===`change`?t(e.value):e.type===`submit`?n?.(e.value):e.type===`paste`?r?.(e.text,e.cursor):e.type===`render`&&i(e=>e+1)}function Te(e,t,n,r){if(!r)return e.length>0?e:n?s.default.gray(n):``;if(e.length===0)return n.length>0?s.default.inverse(n[0])+s.default.gray(n.slice(1)):s.default.inverse(` `);let i=[...e],a=``;for(let e=0;e<i.length;e++){let n=i[e]??``;a+=e===t?s.default.inverse(n):n}return t>=i.length&&(a+=s.default.inverse(` `)),a}function Ee(e){if(e.upArrow===!0)return`previous`;if(e.downArrow===!0)return`next`;if(e.escape===!0)return`close`;if(e.tab===!0)return`complete`}function De(e){if(e.backspace===!0||e.delete===!0)return`cancelQueue`}function Oe(e){if(e.upArrow===!0)return`previous`;if(e.downArrow===!0)return`next`}function ke(){return{selectedIndex:null,draft:``}}function Ae(e,t,n,r){if(t.length===0)return{value:e,cursorHint:e.length,state:n};if(r===`previous`){let r=n.selectedIndex===null?t.length-1:Math.max(0,n.selectedIndex-1),i=t[r]??e;return{value:i,cursorHint:i.length,state:{selectedIndex:r,draft:n.selectedIndex===null?e:n.draft}}}if(n.selectedIndex===null)return{value:e,cursorHint:e.length,state:n};if(n.selectedIndex<t.length-1){let r=n.selectedIndex+1,i=t[r]??e;return{value:i,cursorHint:i.length,state:{...n,selectedIndex:r}}}return{value:n.draft,cursorHint:n.draft.length,state:ke()}}function je(e,t){let n=t.trim();return n.length===0||e[e.length-1]===n?[...e]:[...e,n]}function Me(e){let t=[];for(let n of e){if(n.category!==`chat`||n.type!==`user`)continue;let e=n.data;typeof e?.content==`string`&&(t=je(t,e.content))}return t}function Ne(e,t,n){return t===0?0:n===`previous`?e>0?e-1:t-1:e<t-1?e+1:0}function Pe(e,n){if((0,t.isSlashCommand)(e)&&e.slice(1).includes(` `)){let{name:r}=(0,t.tokeniseSlashCommand)(e);return{type:`insert`,value:`/${r} ${n.name} `}}return n.subcommands&&n.subcommands.length>0?{type:`insert`,value:`/${n.name} `,selectedIndex:0}:{type:`insert`,value:`/${n.name} `}}function Fe(e,n){if((0,t.isSlashCommand)(e)&&e.slice(1).includes(` `)){let{name:r}=(0,t.tokeniseSlashCommand)(e);return{type:`submit`,value:`/${r} ${n.name}`}}return n.subcommands&&n.subcommands.length>0?{type:`insert`,value:`/${n.name} `,selectedIndex:0}:{type:`submit`,value:`/${n.name}`}}function Ie(e,t,n,r){let i=r.split(`
|
|
6
|
+
`).length,a=`[Pasted text #${n} +${i} lines]`;return{value:e.slice(0,t)+a+e.slice(t),cursorHint:t+a.length,label:a,lineCount:i}}function Le(e){return e.trim().length>0}function Re(e){if(!e.startsWith(`/`))return{isSlash:!1,parentCommand:``,filter:``};let t=e.slice(1),n=t.indexOf(` `);return n===-1?{isSlash:!0,parentCommand:``,filter:t}:{isSlash:!0,parentCommand:t.slice(0,n),filter:t.slice(n+1)}}function ze(e,t){let[n,r]=(0,i.useState)(0),[a,o]=(0,i.useState)(!1),s=i.default.useRef(e);s.current!==e&&(s.current=e,a&&o(!1));let c=Re(e),l=c.isSlash&&c.parentCommand.length>0,u=(0,i.useMemo)(()=>{if(!t||!c.isSlash||a)return[];if(l){let e=t.getSubcommands(c.parentCommand);if(e.length===0)return[];if(!c.filter)return e;let n=c.filter.toLowerCase();return e.filter(e=>e.name.toLowerCase().startsWith(n))}return t.getCommands(c.filter)},[t,c.isSlash,c.parentCommand,c.filter,a,l]),d=c.isSlash&&u.length>0&&!a;return n>=u.length&&u.length>0&&r(u.length-1),{showPopup:d,filteredCommands:u,selectedIndex:n,setSelectedIndex:r,isSubcommandMode:l,setShowPopup:e=>{o(typeof e==`function`?t=>!e(!t):!e)}}}function Be(){let{stdout:e}=(0,n.useStdout)(),t=()=>Math.max(40,(e.columns??80)-4),[i,a]=(0,r.useState)(t);return(0,r.useEffect)(()=>{let n=()=>a(t());return e.on(`resize`,n),()=>{e.off(`resize`,n)}},[e]),i}function Ve(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e.padEnd(t)}function He(e){let{cmd:t,isSelected:r,showSlash:i,rowWidth:a,nameColWidth:s}=e,c=r?`▸ `:` `,l=r?`cyan`:void 0,u=!r,d=Ve(t.name,s);return(0,o.jsx)(n.Box,{width:a,children:(0,o.jsx)(n.Text,{color:l,dimColor:u,wrap:`truncate-end`,children:i?`${c}/${d} ${t.description??``}`:`${c}${d} ${t.description??``}`})})}function Ue({commands:e,selectedIndex:t,visible:r,isSubcommandMode:i}){let a=Be();if(!r||e.length===0)return null;let s=We(t,e.length),c=e.slice(s,s+8),l=Math.min(20,Math.max(...c.map(e=>e.name.length)));return(0,o.jsx)(n.Box,{flexDirection:`column`,borderStyle:`round`,borderColor:`gray`,paddingX:1,children:c.map((e,n)=>(0,o.jsx)(He,{cmd:e,isSelected:s+n===t,showSlash:!i,rowWidth:a,nameColWidth:l},e.name))})}function We(e,t){if(t<=8||e<8)return 0;let n=t-8;return Math.min(e-8+1,n)}const Ge=/\[Pasted text #(\d+)(?: \+\d+ lines)?\]/g;function Ke(e,t){return e.replace(Ge,(e,n)=>t.get(Number(n))??``)}const qe=[`#666666`,`#888888`,`#aaaaaa`,`#888888`];function Je({text:e}){let[t,i]=(0,r.useState)(0);return(0,r.useEffect)(()=>{let e=setInterval(()=>{i(e=>e+1)},400);return()=>clearInterval(e)},[]),(0,o.jsx)(n.Text,{children:[...e].map((e,r)=>(0,o.jsx)(n.Text,{color:qe[(t+Math.floor(r/4))%qe.length],children:e},r))})}function Ye({onSubmit:e,onCancelQueue:t,isDisabled:i,isAborting:a,pendingPrompt:s,registry:c,sessionName:l,history:u}){let[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(null),[h,g]=(0,r.useState)(ke),[_,v]=(0,r.useState)([]),y=(0,r.useMemo)(()=>Me(u??[]),[u]),b=(0,r.useMemo)(()=>_.reduce((e,t)=>je(e,t),y),[y,_]),x=(0,r.useRef)(new Map),{columns:S}=(0,n.useWindowSize)(),C=S>0?S:80,w=Math.max(1,C-5),T=(0,r.useRef)(0),{showPopup:E,filteredCommands:D,selectedIndex:O,setSelectedIndex:k,isSubcommandMode:A,setShowPopup:j}=ze(d,c),M=(0,r.useCallback)((e,t)=>{T.current+=1;let n=T.current;x.current.set(n,e),f(r=>{let i=Ie(r,t,n,e);return m(i.cursorHint),i.value})},[]),N=(0,r.useCallback)(()=>{g(ke())},[]),P=(0,r.useCallback)(e=>{v(t=>je(t,e))},[]),F=(0,r.useCallback)(t=>{P(t),N(),e(t)},[e,P,N]),I=(0,r.useCallback)(e=>{let t=Pe(d,e);t.type===`insert`&&(f(t.value),t.selectedIndex!==void 0&&k(t.selectedIndex))},[d,k]),ee=(0,r.useCallback)(e=>{let t=Fe(d,e);if(t.type===`insert`){f(t.value),t.selectedIndex!==void 0&&k(t.selectedIndex);return}t.type===`submit`&&(f(``),F(t.value))},[d,F,k]),te=(0,r.useCallback)(e=>{if(!Le(e))return;if(E&&D[O]){ee(D[O]);return}let t=Ke(e.trim(),x.current);f(``),x.current.clear(),T.current=0,F(t)},[E,D,O,ee,F]);(0,n.useInput)((e,t)=>{if(!E)return;let n=Ee(t);if(n===`previous`||n===`next`)k(e=>Ne(e,D.length,n));else if(n===`close`)j(!1);else if(n===`complete`){let e=D[O];e&&I(e)}},{isActive:E&&!i}),(0,n.useInput)((e,t)=>{let n=Oe(t);if(!n)return;let r=Ae(d,b,h,n);f(r.value),m(r.cursorHint),g(r.state)},{isActive:!E&&!i&&!s}),(0,n.useInput)((e,n)=>{De(n)===`cancelQueue`&&s&&t?.()},{isActive:!!s});let L=a?`yellow`:s?`cyan`:i?`gray`:`green`,R=Math.max(1,C-2),z=(()=>{if(l){let e=` "${l}" `,t=Math.max(0,R-e.length-2);return{left:`┌`+`─`.repeat(t),label:e,right:`─`.repeat(2)+`┐`}}return{left:`┌`+`─`.repeat(R),label:``,right:`┐`}})();return(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[E&&(0,o.jsx)(Ue,{commands:D,selectedIndex:O,visible:E,isSubcommandMode:A}),(0,o.jsxs)(n.Text,{color:L,children:[z.left,z.label?(0,o.jsx)(n.Text,{backgroundColor:L,color:`black`,bold:!0,children:z.label}):null,z.right]}),(0,o.jsx)(n.Box,{borderStyle:`single`,borderTop:!1,borderColor:L,paddingLeft:1,children:a?(0,o.jsx)(n.Text,{color:`yellow`,children:` Interrupting...`}):s?(0,o.jsxs)(n.Text,{color:`cyan`,children:[` `,`Queued:`,` `,s.length>50?s.slice(0,47)+`...`:s,` `,(0,o.jsx)(n.Text,{dimColor:!0,children:`(Backspace to cancel)`})]}):i?(0,o.jsx)(Je,{text:` Waiting for response... (ESC to interrupt)`}):(0,o.jsxs)(n.Box,{children:[(0,o.jsx)(n.Text,{color:`green`,bold:!0,children:`> `}),(0,o.jsx)(Se,{value:d,onChange:e=>{f(e),N(),m(null)},onSubmit:te,onPaste:M,placeholder:`Type a message or /help`,availableWidth:w,cursorHint:p,enableVerticalNavigation:!1})]})})]})}function Xe({items:e,renderItem:t,onSelect:i,onCancel:a,maxVisible:s=3}){let[c,l]=(0,r.useState)(()=>k()),u=(0,r.useRef)(c),d=(0,r.useCallback)(t=>{let n=M(u.current,t,{itemCount:e.length,maxVisible:s});if(u.current=n.state,l(n.state),n.effect.type===`cancel`)a();else if(n.effect.type===`select`){let t=e[n.effect.index];t!==void 0&&i(t)}},[e,s,a,i]);if((0,n.useInput)((e,t)=>{let n=A(t);n!==void 0&&d(n)}),e.length===0)return(0,o.jsx)(n.Box,{});let f=N(c,{itemCount:e.length,maxVisible:s});f!==c&&(u.current=f);let{selectedIndex:p,scrollOffset:m}=f,h=e.slice(m,m+s),g=m+s<e.length;return(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[m>0&&(0,o.jsxs)(n.Text,{dimColor:!0,children:[` ↑ `,m,` more above`]}),h.map((e,r)=>(0,o.jsx)(n.Box,{marginBottom:1,children:t(e,m+r===p)},m+r)),g&&(0,o.jsxs)(n.Text,{dimColor:!0,children:[` ↓ `,e.length-m-s,` more below`]})]})}function Ze(){return{value:``,resolved:!1}}function Qe(e,t){if(t.escape===!0)return{type:`cancel`};if(t.return===!0)return{type:`submit`};if(t.backspace===!0||t.delete===!0)return{type:`delete`};if(e&&t.ctrl!==!0&&t.meta!==!0)return{type:`insert`,value:e}}function $e(e,t,n){return e.resolved?{state:e,effect:{type:`none`}}:t.type===`cancel`?{state:{...e,resolved:!0},effect:{type:`cancel`}}:t.type===`delete`?{state:{...e,value:e.value.slice(0,-1),error:void 0},effect:{type:`none`}}:t.type===`insert`?{state:{...e,value:e.value+t.value,error:void 0},effect:{type:`none`}}:et(e,n)}function et(e,t){let n=e.value.trim();if(!n&&!t.allowEmpty){let r=t.validate?.(n);return{state:r?{...e,error:r}:e,effect:{type:`none`}}}let r=t.validate?.(n);return r===void 0?{state:{...e,resolved:!0},effect:{type:`submit`,value:n}}:{state:{...e,error:r},effect:{type:`none`}}}function tt({title:e,description:t,placeholder:i,onSubmit:a,onCancel:s,validate:c,allowEmpty:l=!1,masked:u=!1}){let[d,f]=(0,r.useState)(()=>Ze()),p=(0,r.useRef)(d),m=(0,r.useCallback)(e=>{let t=$e(p.current,e,{allowEmpty:l,validate:c});p.current=t.state,f(t.state),t.effect.type===`cancel`?s():t.effect.type===`submit`&&a(t.effect.value)},[l,c,s,a]);return(0,n.useInput)((e,t)=>{let n=Qe(e,t);n!==void 0&&m(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:e}),(0,o.jsx)(nt,{description:t}),(0,o.jsxs)(n.Box,{marginTop:1,children:[(0,o.jsx)(n.Text,{color:`cyan`,children:`> `}),d.value?(0,o.jsx)(n.Text,{children:u?`*`.repeat(d.value.length):d.value}):i?(0,o.jsx)(n.Text,{dimColor:!0,children:i}):null,(0,o.jsx)(n.Text,{color:`cyan`,children:`█`})]}),d.error&&(0,o.jsx)(n.Text,{color:`red`,children:d.error}),(0,o.jsx)(n.Text,{dimColor:!0,children:` Enter Submit Esc Cancel`})]})}function nt({description:e}){return e===void 0||e.length===0?null:(0,o.jsx)(n.Text,{dimColor:!0,children:e})}function rt({prompt:e,onSubmit:t,onCancel:r}){return e.kind===`text`?(0,o.jsx)(tt,{title:e.title,description:e.description,placeholder:e.placeholder,allowEmpty:e.allowEmpty,masked:e.masked,validate:e.validate,onSubmit:t,onCancel:r},`text:${e.title}`):(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[(0,o.jsx)(n.Text,{bold:!0,children:e.title}),e.description!==void 0&&e.description.length>0&&(0,o.jsx)(n.Text,{dimColor:!0,children:e.description}),(0,o.jsx)(Xe,{items:[...e.options],maxVisible:e.maxVisible,renderItem:(e,t)=>(0,o.jsxs)(n.Text,{color:t?`cyan`:void 0,children:[t?`> `:` `,e.label]}),onSelect:e=>t(e.value),onCancel:r})]})}const it=new Set([`Bash`,`BackgroundProcess`]);function at(e){if(!it.has(e.toolName)||!e.toolResultData)return;let t=ot(e.toolResultData),n=mt(t,`exitCode`),r=ht(t,`success`),i=ut(lt(st(e.toolResultData,t))),a=i.slice(0,4),o=Math.max(0,i.length-a.length),s=e.result===`error`||r===!1||n!==void 0&&n!==0;return{status:s?`error`:`success`,statusLabel:ct(s,n),previewLines:a,omittedLineCount:o,transcriptHint:o>0?`... +${o} lines (full output in session transcript)`:void 0}}function ot(e){try{return JSON.parse(e)}catch{return e}}function st(e,t){if(!ft(t))return e;let n=pt(t,`output`);if(n!==void 0)return n;let r=pt(t,`stdout`),i=pt(t,`stderr`),a=pt(t,`error`),o=[];return r&&o.push(r),i&&o.push(dt(i,`[stderr] `)),!r&&!i&&a&&o.push(a),o.join(`
|
|
7
|
+
`)}function ct(e,t){return t!==void 0&&t!==0?`exit ${t}`:e?`error`:`ok`}function lt(e){return e?e.replace(/\r\n/g,`
|
|
8
|
+
`).split(`
|
|
9
|
+
`):[]}function ut(e){let t=e.length;for(;t>0&&e[t-1].trim().length===0;)--t;return e.slice(0,t)}function dt(e,t){return lt(e).map(e=>`${t}${e}`).join(`
|
|
10
|
+
`)}function ft(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Date)}function pt(e,t){if(!ft(e))return;let n=e[t];return typeof n==`string`?n:void 0}function mt(e,t){if(!ft(e))return;let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function ht(e,t){if(!ft(e))return;let n=e[t];return typeof n==`boolean`?n:void 0}const gt=`\x1B[0m`,_t=` `,vt=u.default;function yt(e){return e===void 0?process.env.NO_COLOR||process.env.FORCE_COLOR===`0`?!1:process.env.FORCE_COLOR?!0:!!process.stdout.isTTY:e}function bt(e){return e?.trim().toLowerCase()===`diff`}function xt(e,t,n){let r=`${_t}${e}`.padEnd(t);return n?e.startsWith(`+`)?`[48;5;22m[38;5;120m${r}${gt}`:e.startsWith(`-`)?`[48;5;52m[38;5;210m${r}${gt}`:r.trimEnd():r.trimEnd()}function St(e,t,n){if(e.startsWith(`+`)||e.startsWith(`-`))return xt(e,n,t);let r=`${_t}${e}`;return t?e.startsWith(`@@`)?`[36m${r}${gt}`:e.startsWith(`diff `)||e.startsWith(`index `)?`[2m${r}${gt}`:r:r}function Ct(e,t){let n=e.reduce((e,t)=>Math.max(e,4+t.length),0);return t===void 0?n:Math.max(n,t)}function wt(e,t,n){let r=e.split(`
|
|
11
|
+
`),i=Ct(r,n);return`${r.map(e=>St(e,t,i)).join(`
|
|
12
|
+
`)}\n\n`}function Tt(e,t){let n=new vt(void 0,{ignoreIllegals:!0}),r=n.code.bind(n);return n.code=(n,i,a)=>bt(i)?wt(n,e,t):r(n,i,a),n}function Et(e,t={}){let n=l.marked.parse(e,{renderer:Tt(yt(t.color),t.codeBlockWidth)});return typeof n==`string`?n.trimEnd():e}function Dt({tool:e}){let t=at(e);if(!t||t.statusLabel===`ok`&&t.previewLines.length===0&&!t.transcriptHint)return null;let r=t.status===`error`?`red`:`white`;return(0,o.jsxs)(n.Box,{flexDirection:`column`,marginLeft:4,children:[t.statusLabel!==`ok`&&(0,o.jsx)(n.Text,{color:r,dimColor:!0,children:t.statusLabel}),t.previewLines.map((e,t)=>(0,o.jsx)(n.Text,{color:r,dimColor:!0,children:e},`${e}-${t}`)),t.transcriptHint&&(0,o.jsx)(n.Text,{dimColor:!0,children:t.transcriptHint})]})}function Ot(e){let t=e.lines.length>12?At(e.lines):e.lines,n=Math.max(...t.map(e=>e.lineNumber),0).toString().length,r=t.map(e=>kt(e,n)),i=e.lines.length>12;return{file:e.file,markdown:["```diff",...r,"```"].join(`
|
|
13
|
+
`),truncated:i,remainingLineCount:i?e.lines.length-t.length:0}}function kt(e,t){if(e.type===`hunk`)return e.text;let n=e.lineNumber.toString().padStart(t,` `);return e.type===`remove`?`- ${n} | ${e.text}`:e.type===`add`?`+ ${n} | ${e.text}`:` ${n} | ${e.text}`}function At(e){let t=jt(e),n=[];for(let e of t){if(n.length===0&&e.length>10)return e.slice(0,10);if(n.length+e.length>10)break;n.push(...e)}return n.length>0?n:e.slice(0,10)}function jt(e){let t=[],n=[];for(let r of e){if(r.type===`hunk`&&n.length>0){t.push(n),n=[r];continue}n.push(r)}return n.length>0&&t.push(n),t}function Mt({file:e,lines:t}){let r=Ot({file:e,lines:t});return(0,o.jsxs)(n.Box,{flexDirection:`column`,marginLeft:4,children:[r.file&&(0,o.jsxs)(n.Text,{color:`white`,dimColor:!0,children:[`│ `,r.file]}),(0,o.jsx)(n.Text,{children:Et(r.markdown)}),r.truncated&&(0,o.jsxs)(n.Text,{color:`white`,dimColor:!0,children:[`│ ... and `,r.remainingLineCount,` more lines`]})]})}function Nt({entry:e}){let t=e.data;if(!t)return(0,o.jsx)(o.Fragment,{});let r=t.promptTokens===void 0?`?`:Pt(t.promptTokens),i=t.completionTokens===void 0?`?`:Pt(t.completionTokens),s=Pt(t.totalTokens),c=`${Math.round(t.contextUsedPercentage)}% (${(0,a.formatTokenCount)(t.contextUsedTokens)}/${(0,a.formatTokenCount)(t.contextMaxTokens)})`,l=t.costStatus===`unknown`?`cost unknown`:`cost ${t.costStatus}`;return(0,o.jsx)(n.Box,{flexDirection:`column`,marginBottom:1,children:(0,o.jsxs)(n.Box,{children:[(0,o.jsxs)(n.Text,{color:`white`,bold:!0,children:[`Usage:`,` `]}),(0,o.jsxs)(n.Text,{dimColor:!0,children:[t.kind,` `,s,` tokens (in `,r,` / out `,i,`) · Context `,c,` ·`,` `,l]})]})})}function Pt(e){return e<1e3?e.toLocaleString():(0,a.formatTokenCount)(e)}function Ft(e){return at(e)?.status===`error`?`✗`:e.isRunning?`⟳`:e.result===`error`?`✗`:e.result===`denied`?`⊘`:`✓`}function It(e){return at(e)?.status===`error`||e.result===`error`?`red`:e.isRunning||e.result===`denied`?`yellow`:`green`}function Lt(e){return`${Ft(e)} ${e.toolName}${e.firstArg?`(${e.firstArg})`:``}`}function Rt({role:e}){switch(e){case`user`:return(0,o.jsxs)(n.Text,{color:`green`,bold:!0,children:[`You:`,` `]});case`assistant`:return(0,o.jsxs)(n.Text,{color:`cyan`,bold:!0,children:[`Robota:`,` `]});case`system`:return(0,o.jsxs)(n.Text,{color:`yellow`,bold:!0,children:[`System:`,` `]});case`tool`:return(0,o.jsxs)(n.Text,{color:`white`,bold:!0,children:[`Tool:`,` `]})}}function zt({message:e}){if(!(0,a.isToolMessage)(e))return(0,o.jsx)(o.Fragment,{});let t=e.name,r=e.content,i=null;try{let e=JSON.parse(r);Array.isArray(e)&&e.length>0&&typeof e[0].line==`string`&&(i=e)}catch{}if(i)return(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsxs)(n.Box,{children:[(0,o.jsxs)(n.Text,{color:`white`,bold:!0,children:[`Tool:`,` `]}),t&&(0,o.jsxs)(n.Text,{color:`white`,dimColor:!0,children:[`[`,t,`]`]})]}),(0,o.jsx)(n.Text,{children:` `}),i.map((e,t)=>(0,o.jsxs)(n.Box,{flexDirection:`column`,children:[(0,o.jsxs)(n.Text,{color:`green`,children:[` `,`✓`,` `,e.line]}),e.diffLines&&e.diffLines.length>0&&(0,o.jsx)(Mt,{file:e.diffFile,lines:e.diffLines})]},t))]});let s=r.split(`
|
|
14
|
+
`).filter(e=>e.trim());return(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsxs)(n.Box,{children:[(0,o.jsxs)(n.Text,{color:`white`,bold:!0,children:[`Tool:`,` `]}),t&&(0,o.jsxs)(n.Text,{color:`white`,dimColor:!0,children:[`[`,t,`]`]})]}),(0,o.jsx)(n.Text,{children:` `}),s.map((e,t)=>(0,o.jsxs)(n.Text,{color:`green`,children:[` `,`✓`,` `,e]},t))]})}const Bt=r.default.memo(function({message:e}){if((0,a.isToolMessage)(e))return(0,o.jsx)(zt,{message:e});let t=e.content??``,r=e.state===`interrupted`;return(0,o.jsxs)(n.Box,{flexDirection:`column`,marginBottom:1,children:[(0,o.jsx)(n.Box,{children:(0,o.jsx)(Rt,{role:e.role})}),(0,o.jsx)(n.Text,{children:` `}),(0,o.jsx)(n.Box,{marginLeft:2,children:(0,o.jsx)(n.Text,{wrap:`wrap`,children:(0,a.isAssistantMessage)(e)?Et(t+(r?`
|
|
15
|
+
|
|
16
|
+
_(interrupted)_`:``)):t})})]})});function Vt({entry:e}){let t=e.data,r=t?.tools,i=t?.summary?.split(`
|
|
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:`
|
|
19
|
+
____ ___ ____ ___ _____ _
|
|
20
|
+
| _ \\ / _ \\| __ ) / _ \\_ _|/ \\
|
|
21
|
+
| |_) | | | | _ \\| | | || | / _ \\
|
|
22
|
+
| _ <| |_| | |_) | |_| || |/ ___ \\
|
|
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}});
|
package/dist/node/ws/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as IWsTransportConfig, c as createWsTransport, d as TClientMessage, f as TServerMessage, i as TExecutionWorkspaceStatus, l as IWsHandlerOptions, n as IExecutionWorkspaceSnapshot, o as WsTransport, r as TExecutionAttention, s as IWsTransportOptions, t as IExecutionWorkspaceEntry, u as createWsHandler } from "../index-
|
|
1
|
+
import { a as IWsTransportConfig, c as createWsTransport, d as TClientMessage, f as TServerMessage, i as TExecutionWorkspaceStatus, l as IWsHandlerOptions, n as IExecutionWorkspaceSnapshot, o as WsTransport, r as TExecutionAttention, s as IWsTransportOptions, t as IExecutionWorkspaceEntry, u as createWsHandler } from "../index-COWvtBa2.js";
|
|
2
2
|
export { type IExecutionWorkspaceEntry, type IExecutionWorkspaceSnapshot, type IWsHandlerOptions, type IWsTransportConfig, type IWsTransportOptions, type TClientMessage, type TExecutionAttention, type TExecutionWorkspaceStatus, type TServerMessage, WsTransport, createWsHandler, createWsTransport };
|
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.70",
|
|
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-
|
|
113
|
-
"@robota-sdk/agent-
|
|
114
|
-
"@robota-sdk/agent-
|
|
111
|
+
"@robota-sdk/agent-core": "3.0.0-beta.70",
|
|
112
|
+
"@robota-sdk/agent-interface-transport": "3.0.0-beta.70",
|
|
113
|
+
"@robota-sdk/agent-interface-tui": "3.0.0-beta.70",
|
|
114
|
+
"@robota-sdk/agent-framework": "3.0.0-beta.70"
|
|
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.70"
|
|
128
128
|
},
|
|
129
129
|
"license": "MIT",
|
|
130
130
|
"publishConfig": {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HeadlessInteractionChannel — owns session lifecycle for non-interactive (print) mode.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors TuiInteractionChannel's ownership pattern: session creation lives here,
|
|
5
|
+
* not in the caller. print-mode.ts constructs this and calls run().
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { execSync } from 'node:child_process';
|
|
9
|
+
|
|
10
|
+
import { InteractiveSession } from '@robota-sdk/agent-framework';
|
|
11
|
+
|
|
12
|
+
import { createHeadlessRunner, type TOutputFormat } from './headless-runner.js';
|
|
13
|
+
|
|
14
|
+
import type { IAIProvider, TPermissionMode } from '@robota-sdk/agent-core';
|
|
15
|
+
import type {
|
|
16
|
+
IBackgroundTaskRunner,
|
|
17
|
+
ICommandHostAdapters,
|
|
18
|
+
ICommandModule,
|
|
19
|
+
IInteractiveSessionStore,
|
|
20
|
+
TSubagentRunnerFactory,
|
|
21
|
+
TShellExecFn,
|
|
22
|
+
} from '@robota-sdk/agent-framework';
|
|
23
|
+
|
|
24
|
+
export interface IHeadlessInteractionChannelOptions {
|
|
25
|
+
cwd: string;
|
|
26
|
+
provider: IAIProvider;
|
|
27
|
+
outputFormat: TOutputFormat;
|
|
28
|
+
permissionMode?: TPermissionMode;
|
|
29
|
+
maxTurns?: number;
|
|
30
|
+
sessionStore?: IInteractiveSessionStore;
|
|
31
|
+
sessionName?: string;
|
|
32
|
+
bare?: boolean;
|
|
33
|
+
allowedTools?: string[];
|
|
34
|
+
appendSystemPrompt?: string;
|
|
35
|
+
systemPrompt?: string;
|
|
36
|
+
backgroundTaskRunners?: IBackgroundTaskRunner[];
|
|
37
|
+
subagentRunnerFactory?: TSubagentRunnerFactory;
|
|
38
|
+
commandModules?: readonly ICommandModule[];
|
|
39
|
+
commandHostAdapters?: ICommandHostAdapters;
|
|
40
|
+
shellExec?: TShellExecFn;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class HeadlessInteractionChannel {
|
|
44
|
+
private readonly opts: IHeadlessInteractionChannelOptions;
|
|
45
|
+
private exitCode = 0;
|
|
46
|
+
|
|
47
|
+
constructor(options: IHeadlessInteractionChannelOptions) {
|
|
48
|
+
this.opts = options;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async run(prompt: string): Promise<void> {
|
|
52
|
+
const shellExec: TShellExecFn =
|
|
53
|
+
this.opts.shellExec ??
|
|
54
|
+
((command: string) =>
|
|
55
|
+
execSync(command, { timeout: 5000, encoding: 'utf-8', stdio: 'pipe' }).trimEnd());
|
|
56
|
+
|
|
57
|
+
const session = new InteractiveSession({
|
|
58
|
+
cwd: this.opts.cwd,
|
|
59
|
+
provider: this.opts.provider,
|
|
60
|
+
permissionMode: this.opts.permissionMode ?? 'bypassPermissions',
|
|
61
|
+
maxTurns: this.opts.maxTurns,
|
|
62
|
+
sessionStore: this.opts.sessionStore,
|
|
63
|
+
sessionName: this.opts.sessionName,
|
|
64
|
+
bare: this.opts.bare || undefined,
|
|
65
|
+
allowedTools: this.opts.allowedTools,
|
|
66
|
+
appendSystemPrompt: this.opts.appendSystemPrompt,
|
|
67
|
+
...(this.opts.systemPrompt ? { systemPrompt: this.opts.systemPrompt } : {}),
|
|
68
|
+
backgroundTaskRunners: this.opts.backgroundTaskRunners,
|
|
69
|
+
subagentRunnerFactory: this.opts.subagentRunnerFactory,
|
|
70
|
+
commandModules: this.opts.commandModules,
|
|
71
|
+
commandHostAdapters: this.opts.commandHostAdapters,
|
|
72
|
+
shellExec,
|
|
73
|
+
agentName: 'robota-cli',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const runner = createHeadlessRunner({ session, outputFormat: this.opts.outputFormat });
|
|
77
|
+
this.exitCode = await runner.run(prompt);
|
|
78
|
+
await session.shutdown({ reason: 'prompt_input_exit', message: 'Headless transport complete' });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getExitCode(): number {
|
|
82
|
+
return this.exitCode;
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/headless/index.ts
CHANGED
|
@@ -4,3 +4,5 @@ export { createHeadlessRunner } from './headless-runner.js';
|
|
|
4
4
|
export type { IHeadlessRunnerOptions, TOutputFormat } from './headless-runner.js';
|
|
5
5
|
export { createHeadlessTransport } from './headless-transport.js';
|
|
6
6
|
export type { IHeadlessTransportOptions } from './headless-transport.js';
|
|
7
|
+
export { HeadlessInteractionChannel } from './HeadlessInteractionChannel.js';
|
|
8
|
+
export type { IHeadlessInteractionChannelOptions } from './HeadlessInteractionChannel.js';
|
package/src/tui/App.tsx
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createSystemMessage, messageToHistoryEntry } from '@robota-sdk/agent-core';
|
|
2
2
|
import { listResumableSessionSummaries } from '@robota-sdk/agent-framework';
|
|
3
|
-
import { Box, Text, useApp, useInput } from 'ink';
|
|
3
|
+
import { Box, Static, Text, useApp, useInput } from 'ink';
|
|
4
4
|
import React, { useState, useEffect, useMemo, useCallback, useRef } from 'react';
|
|
5
5
|
|
|
6
6
|
import BackgroundTaskPanel from './BackgroundTaskPanel.js';
|
|
7
|
-
import ConfirmPrompt from './ConfirmPrompt.js';
|
|
8
7
|
import { ContextWarningBanner } from './ContextWarningBanner.js';
|
|
9
8
|
import {
|
|
10
9
|
countActiveBackgroundWorkspaceEntries,
|
|
@@ -12,10 +11,10 @@ import {
|
|
|
12
11
|
} from './execution-workspace-view-model.js';
|
|
13
12
|
import ExecutionWorkspaceDetailPane from './ExecutionWorkspaceDetailPane.js';
|
|
14
13
|
import ExecutionWorkspaceSwitcher from './ExecutionWorkspaceSwitcher.js';
|
|
15
|
-
import { useInteractiveSession } from './hooks/useInteractiveSession.js';
|
|
16
14
|
import { usePluginCallbacks } from './hooks/usePluginCallbacks.js';
|
|
17
15
|
import { useSideEffects } from './hooks/useSideEffects.js';
|
|
18
16
|
import { useStatusLineSettings } from './hooks/useStatusLineSettings.js';
|
|
17
|
+
import { useTuiChannel } from './hooks/useTuiChannel.js';
|
|
19
18
|
import InputArea from './InputArea.js';
|
|
20
19
|
import InteractivePrompt from './InteractivePrompt.js';
|
|
21
20
|
import MessageList from './MessageList.js';
|
|
@@ -29,50 +28,29 @@ import { TuiCliAdapterProvider } from './tui-cli-adapter-context.js';
|
|
|
29
28
|
import UpdateNotice from './UpdateNotice.js';
|
|
30
29
|
|
|
31
30
|
import type { ITuiCliAdapter } from './tui-cli-adapter.js';
|
|
31
|
+
import type { TuiInteractionChannel } from './TuiInteractionChannel.js';
|
|
32
32
|
import type { TPermissionMode } from '@robota-sdk/agent-core';
|
|
33
|
-
import type { IAIProvider } from '@robota-sdk/agent-core';
|
|
34
33
|
import type {
|
|
35
|
-
IBackgroundTaskRunner,
|
|
36
|
-
ICommandHostAdapters,
|
|
37
|
-
ICommandModule,
|
|
38
34
|
IInteractiveSession,
|
|
39
35
|
IInteractiveSessionStore,
|
|
40
|
-
TSubagentRunnerFactory,
|
|
41
|
-
TShellExecFn,
|
|
42
36
|
IExecutionDetailPage,
|
|
43
37
|
} from '@robota-sdk/agent-framework';
|
|
44
|
-
import type { CommandRegistry } from '@robota-sdk/agent-framework';
|
|
45
38
|
import type { ITransportRegistryView } from '@robota-sdk/agent-interface-transport';
|
|
46
39
|
|
|
47
40
|
interface IProps {
|
|
48
41
|
cwd: string;
|
|
49
|
-
|
|
42
|
+
channel: TuiInteractionChannel;
|
|
50
43
|
providerOverride?: string | undefined;
|
|
51
44
|
providerType?: string | undefined;
|
|
52
45
|
modelId?: string;
|
|
53
|
-
language?: string;
|
|
54
46
|
permissionMode?: TPermissionMode;
|
|
55
|
-
maxTurns?: number;
|
|
56
47
|
version?: string;
|
|
57
48
|
sessionStore?: IInteractiveSessionStore;
|
|
58
49
|
resumeSessionId?: string;
|
|
59
50
|
showSessionPickerOnStart?: boolean;
|
|
60
|
-
forkSession?: boolean;
|
|
61
|
-
sessionName?: string;
|
|
62
|
-
backgroundTaskRunners?: IBackgroundTaskRunner[];
|
|
63
|
-
subagentRunnerFactory?: TSubagentRunnerFactory;
|
|
64
|
-
commandModules?: readonly ICommandModule[];
|
|
65
|
-
commandHostAdapters?: ICommandHostAdapters;
|
|
66
|
-
shellExec?: TShellExecFn;
|
|
67
51
|
startupUpdateNotice?: Promise<string | undefined>;
|
|
68
52
|
transportRegistry?: ITransportRegistryView<IInteractiveSession>;
|
|
69
53
|
cliAdapter: ITuiCliAdapter;
|
|
70
|
-
reloadPluginCommandSource?: (registry: CommandRegistry) => void;
|
|
71
|
-
agentName?: string;
|
|
72
|
-
systemPrompt?: string;
|
|
73
|
-
appendSystemPrompt?: string;
|
|
74
|
-
allowedTools?: string[];
|
|
75
|
-
deniedTools?: string[];
|
|
76
54
|
}
|
|
77
55
|
|
|
78
56
|
export default function App(props: IProps): React.ReactElement {
|
|
@@ -101,7 +79,7 @@ function AppInner(
|
|
|
101
79
|
props: IProps & { onSessionSwitch: (sessionId: string) => void },
|
|
102
80
|
): React.ReactElement {
|
|
103
81
|
const cwd = props.cwd;
|
|
104
|
-
const
|
|
82
|
+
const { channel } = props;
|
|
105
83
|
|
|
106
84
|
const {
|
|
107
85
|
interactiveSession,
|
|
@@ -125,33 +103,14 @@ function AppInner(
|
|
|
125
103
|
handleAbort,
|
|
126
104
|
handleCancelQueue,
|
|
127
105
|
handleShutdown,
|
|
128
|
-
} =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
permissionMode: props.permissionMode,
|
|
132
|
-
maxTurns: props.maxTurns,
|
|
133
|
-
sessionStore: props.sessionStore,
|
|
134
|
-
resumeSessionId: props.resumeSessionId,
|
|
135
|
-
forkSession: props.forkSession,
|
|
136
|
-
sessionName: props.sessionName,
|
|
137
|
-
onAutoNamed: setSessionName,
|
|
138
|
-
backgroundTaskRunners: props.backgroundTaskRunners,
|
|
139
|
-
subagentRunnerFactory: props.subagentRunnerFactory,
|
|
140
|
-
commandModules: props.commandModules,
|
|
141
|
-
commandHostAdapters: props.commandHostAdapters,
|
|
142
|
-
shellExec: props.shellExec,
|
|
143
|
-
transportRegistry: props.transportRegistry,
|
|
144
|
-
language: props.language,
|
|
145
|
-
reloadPluginCommandSource: props.reloadPluginCommandSource,
|
|
146
|
-
agentName: props.agentName,
|
|
147
|
-
systemPrompt: props.systemPrompt,
|
|
148
|
-
appendSystemPrompt: props.appendSystemPrompt,
|
|
149
|
-
allowedTools: props.allowedTools,
|
|
150
|
-
deniedTools: props.deniedTools,
|
|
151
|
-
});
|
|
106
|
+
} = useTuiChannel(channel);
|
|
107
|
+
|
|
108
|
+
const [sessionName, setSessionName] = useState<string | undefined>(channel.sessionName);
|
|
152
109
|
|
|
153
110
|
const fallbackPluginCallbacks = usePluginCallbacks(cwd);
|
|
154
|
-
const pluginCallbacks =
|
|
111
|
+
const pluginCallbacks = interactiveSession
|
|
112
|
+
? (undefined as unknown as ReturnType<typeof usePluginCallbacks>)
|
|
113
|
+
: fallbackPluginCallbacks;
|
|
155
114
|
const { exit } = useApp();
|
|
156
115
|
const [updateNotice, setUpdateNotice] = useState<string | undefined>();
|
|
157
116
|
const [showExecutionWorkspaceSwitcher, setShowExecutionWorkspaceSwitcher] = useState(false);
|
|
@@ -197,6 +156,13 @@ function AppInner(
|
|
|
197
156
|
openAgentSwitcher: () => setShowExecutionWorkspaceSwitcher(true),
|
|
198
157
|
});
|
|
199
158
|
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
void channel.start();
|
|
161
|
+
return () => {
|
|
162
|
+
void channel.stop();
|
|
163
|
+
};
|
|
164
|
+
}, [channel]);
|
|
165
|
+
|
|
200
166
|
const isSelectedEntryInteractive =
|
|
201
167
|
!selectedExecutionEntry ||
|
|
202
168
|
selectedExecutionEntry.kind === 'main_thread' ||
|
|
@@ -377,16 +343,20 @@ function AppInner(
|
|
|
377
343
|
|
|
378
344
|
return (
|
|
379
345
|
<Box flexDirection="column">
|
|
380
|
-
<
|
|
381
|
-
|
|
346
|
+
<Static items={[{ version: props.version ?? '0.0.0' }]}>
|
|
347
|
+
{(item) => (
|
|
348
|
+
<Box key="logo" flexDirection="column" paddingX={1} marginBottom={1}>
|
|
349
|
+
<Text color="cyan" bold>{`
|
|
382
350
|
____ ___ ____ ___ _____ _
|
|
383
351
|
| _ \\ / _ \\| __ ) / _ \\_ _|/ \\
|
|
384
352
|
| |_) | | | | _ \\| | | || | / _ \\
|
|
385
353
|
| _ <| |_| | |_) | |_| || |/ ___ \\
|
|
386
354
|
|_| \\_\\\\___/|____/ \\___/ |_/_/ \\_\\
|
|
387
355
|
`}</Text>
|
|
388
|
-
|
|
389
|
-
|
|
356
|
+
<Text dimColor> v{item.version}</Text>
|
|
357
|
+
</Box>
|
|
358
|
+
)}
|
|
359
|
+
</Static>
|
|
390
360
|
{updateNotice && <UpdateNotice message={updateNotice} />}
|
|
391
361
|
<Box flexDirection="column" paddingX={1} flexGrow={1}>
|
|
392
362
|
{selectedExecutionEntry && selectedExecutionEntry.kind !== 'main_thread' ? (
|
package/src/tui/InputArea.tsx
CHANGED
|
@@ -5,13 +5,6 @@ const PENDING_PROMPT_TAIL_KEEP = 47;
|
|
|
5
5
|
import { Box, Text, useInput, useWindowSize } from 'ink';
|
|
6
6
|
|
|
7
7
|
import CjkTextInput from './CjkTextInput.js';
|
|
8
|
-
import { resolveCommandInteraction } from './command-interaction-registry.js';
|
|
9
|
-
import {
|
|
10
|
-
isPickerInteraction,
|
|
11
|
-
isConfirmInteraction,
|
|
12
|
-
type ITuiCommandInteraction,
|
|
13
|
-
type ITuiPickerItem,
|
|
14
|
-
} from './command-interaction.js';
|
|
15
8
|
import {
|
|
16
9
|
appendPromptHistory,
|
|
17
10
|
createPasteLabelChange,
|
|
@@ -27,8 +20,6 @@ import {
|
|
|
27
20
|
shouldSubmitInput,
|
|
28
21
|
} from './flows/input-area-flow.js';
|
|
29
22
|
import { useAutocomplete } from './hooks/useAutocomplete.js';
|
|
30
|
-
import CommandConfirm from './interactions/CommandConfirm.js';
|
|
31
|
-
import CommandPicker from './interactions/CommandPicker.js';
|
|
32
23
|
import SlashAutocomplete from './SlashAutocomplete.js';
|
|
33
24
|
import { expandPasteLabels } from './utils/paste-labels.js';
|
|
34
25
|
import WaveText from './WaveText.js';
|
|
@@ -36,11 +27,6 @@ import WaveText from './WaveText.js';
|
|
|
36
27
|
import type { IHistoryEntry } from '@robota-sdk/agent-core';
|
|
37
28
|
import type { CommandRegistry, ICommand } from '@robota-sdk/agent-framework';
|
|
38
29
|
|
|
39
|
-
interface IActiveInteraction {
|
|
40
|
-
commandName: string;
|
|
41
|
-
interaction: ITuiCommandInteraction;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
30
|
interface IProps {
|
|
45
31
|
onSubmit: (value: string) => void;
|
|
46
32
|
onCancelQueue?: () => void;
|
|
@@ -84,7 +70,6 @@ export default function InputArea({
|
|
|
84
70
|
}: IProps): React.ReactElement {
|
|
85
71
|
const [value, setValue] = useState('');
|
|
86
72
|
const [cursorHint, setCursorHint] = useState<number | null>(null);
|
|
87
|
-
const [activeInteraction, setActiveInteraction] = useState<IActiveInteraction | null>(null);
|
|
88
73
|
const [historyState, setHistoryState] = useState(createPromptHistoryNavigationState);
|
|
89
74
|
const [localPromptHistory, setLocalPromptHistory] = useState<string[]>([]);
|
|
90
75
|
const restoredPromptHistory = useMemo(() => extractPromptHistory(history ?? []), [history]);
|
|
@@ -156,8 +141,7 @@ export default function InputArea({
|
|
|
156
141
|
/** Enter: insert and execute command immediately */
|
|
157
142
|
const enterSelectCommand = useCallback(
|
|
158
143
|
(cmd: ICommand): void => {
|
|
159
|
-
const
|
|
160
|
-
const result = resolveEnterCommandSelection(value, cmd, interaction);
|
|
144
|
+
const result = resolveEnterCommandSelection(value, cmd);
|
|
161
145
|
if (result.type === 'insert') {
|
|
162
146
|
setValue(result.value);
|
|
163
147
|
if (result.selectedIndex !== undefined) {
|
|
@@ -165,17 +149,12 @@ export default function InputArea({
|
|
|
165
149
|
}
|
|
166
150
|
return;
|
|
167
151
|
}
|
|
168
|
-
if (result.type === 'open-interaction' && interaction?.onMissingArgs) {
|
|
169
|
-
setShowPopup(false);
|
|
170
|
-
setActiveInteraction({ commandName: result.commandName, interaction });
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
152
|
if (result.type === 'submit') {
|
|
174
153
|
setValue('');
|
|
175
154
|
submitPrompt(result.value);
|
|
176
155
|
}
|
|
177
156
|
},
|
|
178
|
-
[value, submitPrompt, setSelectedIndex
|
|
157
|
+
[value, submitPrompt, setSelectedIndex],
|
|
179
158
|
);
|
|
180
159
|
|
|
181
160
|
const handleSubmit = useCallback(
|
|
@@ -263,44 +242,9 @@ export default function InputArea({
|
|
|
263
242
|
return { left: '┌' + '─'.repeat(innerWidth), label: '', right: '┐' };
|
|
264
243
|
})();
|
|
265
244
|
|
|
266
|
-
const handlePickerSelect = useCallback(
|
|
267
|
-
(item: ITuiPickerItem): void => {
|
|
268
|
-
if (!activeInteraction) return;
|
|
269
|
-
setActiveInteraction(null);
|
|
270
|
-
submitPrompt(`/${activeInteraction.commandName} ${item.value}`);
|
|
271
|
-
},
|
|
272
|
-
[activeInteraction, submitPrompt],
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
const handleConfirm = useCallback((): void => {
|
|
276
|
-
if (!activeInteraction) return;
|
|
277
|
-
setActiveInteraction(null);
|
|
278
|
-
submitPrompt(`/${activeInteraction.commandName}`);
|
|
279
|
-
}, [activeInteraction, submitPrompt]);
|
|
280
|
-
|
|
281
|
-
const handleInteractionCancel = useCallback((): void => {
|
|
282
|
-
setActiveInteraction(null);
|
|
283
|
-
}, []);
|
|
284
|
-
|
|
285
245
|
return (
|
|
286
246
|
<Box flexDirection="column">
|
|
287
|
-
{
|
|
288
|
-
<CommandPicker
|
|
289
|
-
commandName={activeInteraction.commandName}
|
|
290
|
-
interaction={activeInteraction.interaction}
|
|
291
|
-
onSelect={handlePickerSelect}
|
|
292
|
-
onCancel={handleInteractionCancel}
|
|
293
|
-
/>
|
|
294
|
-
)}
|
|
295
|
-
{activeInteraction && isConfirmInteraction(activeInteraction.interaction) && (
|
|
296
|
-
<CommandConfirm
|
|
297
|
-
commandName={activeInteraction.commandName}
|
|
298
|
-
interaction={activeInteraction.interaction}
|
|
299
|
-
onConfirm={handleConfirm}
|
|
300
|
-
onCancel={handleInteractionCancel}
|
|
301
|
-
/>
|
|
302
|
-
)}
|
|
303
|
-
{!activeInteraction && showPopup && (
|
|
247
|
+
{showPopup && (
|
|
304
248
|
<SlashAutocomplete
|
|
305
249
|
commands={filteredCommands}
|
|
306
250
|
selectedIndex={selectedIndex}
|
package/src/tui/StatusBar.tsx
CHANGED