@x-otto/tui 0.0.1-alpha.1 → 0.0.1-alpha.2
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.
|
@@ -6,5 +6,5 @@ import{n as e}from"./i18n-Dju4J1Q-.js";import{createRequire as t}from"node:modul
|
|
|
6
6
|
`}}let r=this.text.slice(n,this.offset);return{cursor:new e(new Z(this.text.slice(0,n)+this.text.slice(this.offset),this.columns),n),killed:r}}killWordBefore(){let t=yt(this.text,this.offset);if(t)return{cursor:new e(new Z(this.text.slice(0,t.start)+this.text.slice(t.end),this.columns),t.start),killed:t.text};let n=this.prevWord(),r=this.text.slice(n.offset,this.offset);return{cursor:new e(new Z(this.text.slice(0,n.offset)+this.text.slice(this.offset),this.columns),n.offset),killed:r}}modifyText(t,n=``){return new e(new Z(this.text.slice(0,this.offset)+n+this.text.slice(t),this.columns),this.offset+n.length)}deleteTokenBefore(){return this.offset<=0?null:this.backspace()}getViewportStartLine(e){let t=this.position,n=Math.floor(e/2);return Math.max(0,Math.min(t.line-n,this.measuredText.lineCount-e))}toEnd(){return new e(this.measuredText,this.text.length)}toStart(){return new e(this.measuredText,0)}toLineStart(){let t=0,n=this.position;for(let e=0;e<n.line;e++)t+=this.measuredText.lines[e].length+1;return new e(this.measuredText,t)}toLineEnd(){let t=0,n=this.position;for(let e=0;e<n.line;e++)t+=this.measuredText.lines[e].length+1;return new e(this.measuredText,t+this.measuredText.lines[n.line].length)}};function Tt(e){if(e.length===0||e.length>2)return!1;let t=e.codePointAt(0)??0;return t<32||t===127?!1:e.length===2?e.charCodeAt(0)>=55296&&e.charCodeAt(0)<=56319:!0}function Et(e,t){let{name:n,ctrl:r,shift:i,alt:a,meta:o}=t;if(r&&n===`a`)return{cursor:e.toStart(),action:`move_to_start`};if(r&&n===`e`)return{cursor:e.toEnd(),action:`move_to_end`};if(r&&n===`b`){let t=e.left();return t.offset===e.offset?null:{cursor:t,action:`move_left`}}if(r&&n===`f`){let t=e.right();return t.offset===e.offset?null:{cursor:t,action:`move_right`}}if((a||o)&&n===`b`){let t=e.prevWord();return t.offset===e.offset?null:{cursor:t,action:`move_word_left`}}if((a||o)&&n===`f`){let t=e.nextWord();return t.offset===e.offset?null:{cursor:t,action:`move_word_right`}}if(r&&n===`h`||n===`backspace`){let t=e.backspace();return t.offset!==e.offset||t.text!==e.text?{cursor:t,action:`delete_backward`,killed:e.text.slice(t.offset,e.offset)}:null}if(r&&n===`d`){if(e.offset>=e.text.length)return null;let t=e.delete();return t.text===e.text?null:{cursor:t,action:`delete_forward`}}if(n===`delete`){let t=e.delete();return t.text===e.text?null:{cursor:t,action:`delete_forward`}}if(r&&n===`k`){let t=e.killToLineEnd();return t.killed.length>0?{cursor:t.cursor,action:`kill_to_end`,killed:t.killed}:null}if(r&&n===`u`){let t=e.killToLineStart();return t.killed.length>0?{cursor:t.cursor,action:`kill_to_start`,killed:t.killed}:null}if(r&&n===`w`){let t=e.killWordBefore();return t.killed.length>0?{cursor:t.cursor,action:`kill_word_before`,killed:t.killed}:null}return n===`return`||n===`enter`?r||o||a||i?{cursor:e,action:`submit_force`}:{cursor:e,action:`submit`}:Tt(n)?r?null:{cursor:e.insert(n),action:`insert`}:n===` `?{cursor:e.insert(` `),action:`insert`}:null}const Q={entries:[],index:-1,lastAction:`other`,lastYankOffset:0,lastYankLength:0};function Dt(){return Q.entries}function Ot(){Q.entries=[],Q.index=-1,Q.lastAction=`other`}function kt(e,t){t&&Q.entries.length>0&&Q.lastAction===`kill`?Q.entries[0]=e+Q.entries[0]:!t&&Q.entries.length>0&&Q.lastAction===`kill`?Q.entries[0]+=e:(Q.entries.unshift(e),Q.entries.length>10&&(Q.entries.length=10)),Q.lastAction=`kill`,Q.index=-1}function At(){Q.lastAction=`other`,Q.index=-1}function jt(e,t){let{name:n,ctrl:r,alt:i,meta:a,shift:o}=t;if(r&&n===`y`){if(Q.entries.length===0)return null;let t=Q.entries[0];return Q.lastAction=`yank`,Q.index=0,Q.lastYankOffset=e.offset,Q.lastYankLength=t.length,{cursor:e.insert(t),action:`insert`}}if((i||a)&&n===`y`){if(Q.lastAction!==`yank`&&Q.lastAction!==`kill`||Q.entries.length<=1)return null;Q.index=(Q.index+1)%Q.entries.length;let t=Q.entries[Q.index],n=wt.fromText(e.text,e.columns,Q.lastYankOffset).modifyText(Q.lastYankOffset+Q.lastYankLength,t);return Q.lastYankLength=t.length,Q.lastAction=`yank`,{cursor:n,action:`insert`}}if(n===`escape`){if(e.text.length===0)return null;let t=e.position,n=0;for(let r=0;r<t.line;r++)n+=e.measuredText.lines[r].length+1;let r=n+e.measuredText.lines[t.line].length,i=t.line>=e.measuredText.lineCount-1?r:r+1,a=e.text.slice(0,n)+e.text.slice(i),o=Math.min(n,a.length);return{cursor:wt.fromText(a,e.columns,o),action:`clear_text`}}if(n===`return`||n===`enter`){if(e.offset>0&&e.text[e.offset-1]===`\\`&&!o){let t=e.backspace();return At(),{cursor:t.insert(`
|
|
7
7
|
`),action:`insert`}}return At(),{cursor:e,action:i||a||r||o?`submit_force`:`submit`}}let s=Et(e,t);return s?(s.action===`kill_to_end`&&s.killed?kt(s.killed,!1):s.action===`kill_to_start`&&s.killed||s.action===`kill_word_before`&&s.killed?kt(s.killed,!0):(s.action===`delete_backward`||s.action===`insert`)&&At(),s):null}function Mt(e){return e.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g,``).replace(/\x1b\][^\x1b]*$/g,``).replace(/\x1b\[[0-9;]*[~a-zA-Z]/g,``).replace(/\r\n?/g,`
|
|
8
8
|
`).replace(/[\x00-\x08\x0b-\x1f\x7f]/g,``)}function Nt(e){return e.measuredText.lineCount>10}function Pt(e,t){let n=e.measuredText.lineCount;if(n<=t)return null;let r=e.position,i=e.getViewportStartLine(t),a=Math.min(i+t,n);return{startLine:i,endLine:a,visibleLines:e.measuredText.lines.slice(i,a),cursorLine:r.line-i}}function Ft(e,t,n){return{x:e,y:t,lastChangeAt:n,targetX:e,targetY:t}}function It(e,t,n,r,i){let a=t!==e.targetX||n!==e.targetY;return i?a?r-e.lastChangeAt<150?{...e,targetX:t,targetY:n,lastChangeAt:r}:{x:t,y:n,targetX:t,targetY:n,lastChangeAt:r}:(e.x!==t||e.y!==n)&&r-e.lastChangeAt>=150?{...e,x:t,y:n}:e:!a&&e.x===t&&e.y===n?e:{x:t,y:n,targetX:t,targetY:n,lastChangeAt:r}}function Lt(e){if(!e?.yogaNode)return null;let t=0,n=0,r=e;for(;r?.yogaNode;)t+=r.yogaNode.getComputedLeft(),n+=r.yogaNode.getComputedTop(),r=r.parentNode;return{x:Math.round(t),y:Math.round(n)}}function Rt(e){let t=e??void 0;for(;t;){if(!t.parentNode)return t.nodeName===`ink-root`?t:void 0;t=t.parentNode}}let zt=0;function Bt(e){if(!e)return`NULL`;let t=[],n=e;for(let e=0;e<4&&n;e++)t.push(n.nodeName??`?`),n=n.parentNode;let r=e.childNodes?.[0]?.nodeValue;return`${t.join(`<`)}${r?`:${JSON.stringify(r.slice(0,12))}`:``}`}function Vt(e){let[t,n]=f(null),r=i.useRef(0);r.current===0&&(r.current=++zt);let a=s(()=>{if(!e.current)return;let t=Lt(e.current);n(n=>{let i=b()?void 0:process.env.OTTO_TUI_CURSOR_DEBUG;if(i)try{x(`node:fs`).appendFileSync(i,`[ORG#${r.current}] t=${Date.now()%1e5} next=${t?`${t.x},${t.y}`:`NULL`} prev=${n?`${n.x},${n.y}`:`NULL`} node=${Bt(e.current)}\n`)}catch{}return t===null||n!==null&&n.x===t.x&&n.y===t.y?n:t})},[e]);return l(a),l(()=>{let t=Rt(e.current);if(t)return t.internal_layoutListeners??=new Set,t.internal_layoutListeners.add(a),()=>{t.internal_layoutListeners?.delete(a)}}),t}let Ht=0;function Ut({active:e,containerRef:t,text:n,inline:r,deleteKeyAt:i}){let{setCursorPosition:a}=v(),o=Vt(t),s=d(0);s.current===0&&(s.current=++Ht);let c=d(null),u=d(null),p=d(n.length),m=d(0);n.length<p.current&&(m.current=Date.now()),p.current=n.length;let[,h]=f(0);if(e&&o){let e=Date.now(),t=e-i<300,l=n.length===0,d=!t&&!l&&e-m.current<300,f=It(c.current??Ft(r.column,r.lineOffset,e),r.column,r.lineOffset,e,d);c.current=f;let p=o.x+f.x,h=o.y+f.y,g=u.current;g!==null&&f.y>g.inlineOffset&&o.y===g.originY&&(h=g.y),u.current={y:h,originY:o.y,inlineOffset:f.y},a({x:p,y:h});let _=b()?void 0:process.env.OTTO_TUI_CURSOR_DEBUG;if(_)try{x(`node:fs`).appendFileSync(_,`[ON #${s.current}] t=${e%1e5} out=${p},${h} target=${o.x+r.column},${o.y+r.lineOffset} origin=${o.x},${o.y} inline=${r.column},${r.lineOffset} frozenInline=${f.x},${f.y} armed=${d?1:0} byDel=${t?1:0} byClr=${l?1:0} len=${n.length}\n`)}catch{}}else{c.current=null,u.current=null,a(void 0);let t=b()?void 0:process.env.OTTO_TUI_CURSOR_DEBUG;if(t)try{x(`node:fs`).appendFileSync(t,`[OFF#${s.current}] t=${Date.now()%1e5} active=${e?1:0} origin=${o?`${o.x},${o.y}`:`NULL`} len=${n.length}\n`)}catch{}}l(()=>{let e=c.current;if(!e||e.x===e.targetX&&e.y===e.targetY)return;let t=setTimeout(()=>h(e=>e+1),160);return()=>clearTimeout(t)})}const Wt=new Intl.Segmenter(`en`,{granularity:`grapheme`});function Gt(e,t,n){let r=0,i=e,a=t;if(e>n){let o=Math.floor(n/2);r=Math.max(0,t-o),Math.min(e,r+n)-r<n&&(r=Math.max(0,e-n)),i=n,a=t-r}return{startLine:r,visibleRows:i,cursorLineInWindow:a}}const Kt={send:`> `,bash:`! `,bash_async:`!! `,memory:`# `,steer:`» `,dialog:``};function qt(e,t){return e===`bash`||e===`bash_async`?t.warning:e===`memory`?t.special:e===`steer`?t.success:t.suggestion}function Jt(e,t,n){if(!e)return{lines:[``],cursorLine:0,cursorCharInLine:0};let r=[...Wt.segment(e)],i=[],a=``,o=0,s=0,c=0,l=0;for(let e=0;e<r.length;e++){let u=r[e],d=mt(u.segment);if(l===n&&(s=i.length,c=a.length),u.segment===`
|
|
9
|
-
`){i.push(a),a=``,o=0,l+=u.segment.length;continue}o+d>t&&a.length>0&&(i.push(a),a=``,o=0),a+=u.segment,o+=d,l+=u.segment.length}return n>=l&&(s=i.length,c=a.length),i.push(a),{lines:i,cursorLine:s,cursorCharInLine:c}}function Yt(e){X.lastIndex=0;let t=[],n=0,r;for(;(r=X.exec(e))!==null;){r.index>n&&t.push({chunk:e.slice(n,r.index),isChip:!1});let i=r[0],a=_t(i);t.push({chunk:i,isChip:!0,kind:a,pasteId:a===`paste`?vt(i):void 0}),n=r.index+i.length}return n<e.length&&t.push({chunk:e.slice(n),isChip:!1}),t}function Xt(e,t){switch(e){case`file`:return t.suggestion;case`agent`:return t.accent;case`skill`:case`mcp`:case`plugin`:return t.special;case`person`:return t.success;case`paste`:return t.inactive;default:return}}function Zt(e,t){return e.kind===`paste`&&e.pasteId!==void 0&&(t?.has(e.pasteId)??!1)}function Qt(e,t){X.lastIndex=0;let n;for(;(n=X.exec(e))!==null;)if(t>n.index&&t<n.index+n[0].length){let e=_t(n[0]);return{kind:e,pasteId:e===`paste`?vt(n[0]):void 0}}}function $t(e,t){let n=xt(e,t);if(!n)return;let r=_t(n.text);return{text:n.text,kind:r,pasteId:r===`paste`?vt(n.text):void 0}}function en(e){return`•`.repeat(e.length)}const tn=i.memo(function({value:t,offset:n,columns:r,mode:a=`send`,placeholder:o=``,maxVisibleLines:s=10,focused:c,tabIndex:l=-1,mask:u=!1,noPrefix:d=!1,ghostSuffix:f,invalidPasteIds:p,containerRef:v,physicalCursor:y=!1,deleteKeyAt:b=0}){let x=K(),{focused:S}=Ue({tabIndex:l,disabled:l<0}),C=c??S,w=d?``:a===`dialog`&&!u?`> `:Kt[a],T=mt(w),E=w,D=Math.max(20,r-T),O=C,{lines:k,cursorLine:A,cursorCharInLine:j}=i.useMemo(()=>Jt(t,D,n),[t,D,n]),M=i.useRef(null),ee=i.useCallback(e=>{M.current=e,typeof v==`function`?v(e):v&&(v.current=e)},[v]),N=Gt(k.length,A,s),P=N.startLine>0?1:0,F={column:T+mt((k[A]??``).slice(0,j)),lineOffset:P+N.cursorLineInWindow};if(Ut({active:y&&C,containerRef:M,text:t,inline:F,deleteKeyAt:b}),t.length===0&&o)return h(g,{ref:ee,flexDirection:`row`,children:[m(_,{color:C?qt(a,x):x.inactive,children:E}),C&&m(_,{inverse:O,children:` `}),m(_,{dimColor:!0,children:o})]});let I=k.length,{startLine:L,visibleRows:te}=Gt(I,A,s),R=L+te,z=k.slice(L,R);return h(g,{ref:ee,flexDirection:`column`,children:[L>0&&m(_,{dimColor:!0,children:` … ${L} ${e.t(`scroll.viewportLinesAbove`)}`}),z.map((e,t)=>{let n=L+t,r=n===A,i=u?en(e):e;if(!r||!C){let r=u?[{chunk:i,isChip:!1}]:Yt(i);return h(g,{flexDirection:`row`,children:[n===0&&E?m(_,{color:C?qt(a,x):x.inactive,children:E}):T>0&&m(_,{dimColor:!0,children:` `.repeat(T)}),r.length===0?m(_,{children:` `}):r.map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},t)})]},`${t}-${e.slice(0,10)}`)}let o=Math.max(0,Math.min(j,i.length)),s=!u&&o<i.length?$t(i,o):void 0;if(s){let r=i.slice(0,o),c=i.slice(o+s.text.length),l=s.kind===`paste`&&s.pasteId!==void 0&&(p?.has(s.pasteId)??!1);return h(g,{flexDirection:`row`,children:[n===0&&E?m(_,{color:C?qt(a,x):x.inactive,children:E}):T>0&&m(_,{dimColor:!0,children:` `.repeat(T)}),Yt(r).map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},`b-${t}`)}),m(_,{inverse:!0,color:l?x.error:void 0,strikethrough:l,children:s.text}),Yt(c).map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},`a-${t}`)}),f?m(_,{dimColor:!0,children:f}):null]},`${t}-${e.slice(0,10)}`)}let c=i.slice(0,o),l=i.slice(o),d=l.length>0?[...l][0]??` `:` `,v=l.length>0?l.slice(d.length):``,y=!u&&l.length>0?Qt(i,o):void 0,b=y?.kind===`paste`&&y.pasteId!==void 0&&(p?.has(y.pasteId)??!1);return h(g,{flexDirection:`row`,children:[n===0&&E?m(_,{color:C?qt(a,x):x.inactive,children:E}):T>0&&m(_,{dimColor:!0,children:` `.repeat(T)}),(u?[{chunk:c,isChip:!1}]:Yt(c)).map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},`b-${t}`)}),m(_,{inverse:O,color:b?x.error:y==null?void 0:Xt(y.kind,x),strikethrough:b,children:d}),(u?[{chunk:v,isChip:!1}]:Yt(v)).map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},`a-${t}`)}),f?m(_,{dimColor:!0,children:f}):null]},`${t}-${e.slice(0,10)}`)}),R<I&&m(_,{dimColor:!0,children:` … ${I-R} ${e.t(`scroll.viewportLinesBelow`)}`})]})}),nn=[{commandId:`cycle-permission-mode`,description:`循环切换权限模式`,predicate:{shift:!0,key:`tab`},scopes:`*`},{commandId:`toggle-notifications`,description:`打开/关闭通知中心`,predicate:{ctrl:!0,input:`n`},scopes:`*`},{commandId:`toggle-edited-files`,description:`打开/关闭编辑文件面板`,predicate:{ctrl:!0,input:`v`},scopes:`*`},{commandId:`toggle-subagents`,description:`打开/关闭子代理面板`,predicate:{ctrl:!0,input:`t`},scopes:`*`},{commandId:`toggle-delegates`,description:`打开/关闭委派面板`,predicate:{ctrl:!0,input:`p`},scopes:`*`},{commandId:`toggle-draft-pane`,description:`打开/关闭草稿面板`,predicate:{ctrl:!0,input:`o`},scopes:`*`},{commandId:`toggle-queue-pane`,description:`打开/关闭队列面板`,predicate:{ctrl:!0,input:`q`},scopes:`*`},{commandId:`smart-close`,description:`智能关闭当前最上层面板`,predicate:{ctrl:!0,input:`k`},scopes:`*`},{commandId:`save-draft`,description:`保存当前输入为草稿`,predicate:{ctrl:!0,input:`s`},scopes:[`prompt`]},{commandId:`open-keybinding-panel`,description:`打开快捷键面板:浏览、搜索、重映射、重置快捷键`,predicate:{ctrl:!0,input:`/`},scopes:`*`}];function rn(e){return e.ctrl===void 0&&e.shift===void 0&&e.meta===void 0&&e.input===void 0&&e.key===void 0&&e.upArrow===void 0&&e.downArrow===void 0}function an(e,t,n){let r=n?.[e];return r===void 0?t:r}function on(e,t,n){if(e.ctrl!==void 0&&!!n.ctrl!==e.ctrl||e.shift!==void 0&&!!n.shift!==e.shift||e.meta!==void 0&&!!n.meta!==e.meta||e.input!==void 0&&t!==e.input)return!1;if(e.key!==void 0)switch(e.key){case`tab`:if(!n.tab)return!1;break;case`escape`:if(!n.escape)return!1;break;case`return`:if(!n.return)return!1;break}return!(e.upArrow!==void 0&&n.upArrow!==e.upArrow||e.downArrow!==void 0&&n.downArrow!==e.downArrow)}function sn(e,t){return e===`*`?!0:e.includes(t)}function cn(e,t,n,r,i){for(let a of e){if(!sn(a.scopes,t))continue;let e=an(a.commandId,a.predicate,i);if(!rn(e)&&on(e,n,r))return a.commandId}}const ln=[{commandId:`list-nav-up`,description:`列表选中项上移`,predicate:{upArrow:!0},scopes:`*`},{commandId:`list-nav-up`,description:`列表选中项上移(vim k)`,predicate:{input:`k`,ctrl:!1,meta:!1},scopes:[`editedFiles`,`subagents`,`taskFocus`,`draft`,`queue`,`schedule`,`select`,`questions`]},{commandId:`list-nav-down`,description:`列表选中项下移`,predicate:{downArrow:!0},scopes:`*`},{commandId:`list-nav-down`,description:`列表选中项下移(vim j)`,predicate:{input:`j`,ctrl:!1,meta:!1},scopes:[`editedFiles`,`subagents`,`taskFocus`,`draft`,`queue`,`schedule`,`select`,`questions`]}];function un(e,t,n,r,i){for(let a of ln){if(r!==void 0&&!dn(a.scopes,r))continue;let o=an(a.commandId,a.predicate,i);if(!rn(o)&&on(o,t,n))return a.commandId===e}return!1}function dn(e,t){return e===`*`?!0:e.includes(t)}function fn(e,t,n,r){let i=[...nn,...ln];for(let a of i){if(a.commandId===e)continue;let i=an(a.commandId,a.predicate,r);if(!rn(i)&&sn(a.scopes,n)&&pn(i,t))return{conflictsWith:a.commandId}}return null}function pn(e,t){return e.ctrl===t.ctrl&&e.shift===t.shift&&e.meta===t.meta&&e.input===t.input&&e.key===t.key&&e.upArrow===t.upArrow&&e.downArrow===t.downArrow}function mn(){let e=new Set(nn.map(e=>e.commandId)),t=new Set(ln.map(e=>e.commandId));for(let n of e)if(t.has(n))throw Error(`[keybindings] duplicate commandId '${n}' found across KEY_BINDINGS and CONTROL_BINDINGS`)}mn();function hn(e,t,n){if(!t)return!1;let r=e.get(t);return r?n.tab?!!(r.onTab&&r.onTab(n.shift??!1)):n.escape?!!(r.onEscape&&r.onEscape()):n.return?!!(r.onAction&&r.onAction()):!1:!1}function gn(e,t,n,r,i){if(i.tab){let a=t;if(e.getTabable(n).length===0)return!1;if(a){let t=i.shift?e.prev(a,n):e.next(a,n);t&&r(t)}else if(!i.shift){let t=e.getInitialFocus(n);t&&r(t)}return!0}return!1}let _n=null;function vn(e){_n=e}function yn(){return _n}const bn=a(null);function xn(){let e=c(bn);if(!e)throw Error(`useRouter() must be used inside <Router>`);return e}function Sn(){return c(bn)}function Cn(){let{stack:e}=xn(),t=e[e.length-1];return t?{path:t.path,params:t.params,state:t.state}:{path:`/`,params:{},state:void 0}}function wn(e){let{stack:t}=xn();for(let n=t.length-1;n>=0;n--){let r=t[n];if(r.path===e&&r.state!==void 0)return r.state}}function Tn(e,t){let n=e.split(`/`),r=t.split(`/`);if(n.length!==r.length)return null;let i={};for(let e=0;e<n.length;e++){let t=n[e],a=r[e];if(t.startsWith(`:`))i[t.slice(1)]=a;else if(t!==a)return null}return i}function En({children:e,initialPath:t=`/`}){let n=u(()=>new Be,[]),[r,i]=f(()=>({entries:[{path:t,params:{}}],index:0})),[a,o]=f(null),c=d(null);c.current=a;let p=r.entries[r.index]?.path??t,h=r.entries.slice(0,r.index+1),g=d(h);g.current=h;let _=s(e=>{o(e)},[]),v=s(e=>{setTimeout(()=>{e?.lastFocusId?o(e.lastFocusId):o(n.getInitialFocus(e?.path??`/`))},0)},[n]),y=s(e=>{setTimeout(()=>{o(n.getInitialFocus(e))},0)},[n]),b=s((e,t)=>{if(typeof e==`number`){i(t=>{if(e===0||t.entries.length===0)return t;let n=t.index+e;return n<0||n>=t.entries.length?t:(v(t.entries[n]),{...t,index:n})});return}let r={path:e,params:{},state:t?.state};i(e=>{if(t?.reset)return{entries:[r],index:0};let i=c.current,a=[...e.entries];if(a.length>0&&i){let t=a[e.index];t&&(n.rememberFocus(t.path,i),a[e.index]={...t,lastFocusId:i})}if(t?.replace&&a.length>0)return a[e.index]=r,{entries:a,index:e.index};let o=[...a.slice(0,e.index+1),r];return{entries:o,index:o.length-1}}),y(e)},[y,n,v]),x=s(()=>{b(-1)},[b]),S=s(e=>{i(t=>{if(t.entries.slice(0,t.index+1).some(t=>t.path===e))return t;let r=c.current,i=[...t.entries],a=i[t.index];a&&r&&(n.rememberFocus(a.path,r),i[t.index]={...a,lastFocusId:r});let o=[...i.slice(0,t.index+1),{path:e,params:{}}];return y(e),{entries:o,index:o.length-1}})},[y,n]),C=s(e=>{i(t=>{if(t.entries.length<=1)return t;let n=-1;for(let r=t.index;r>=0;r--)if(t.entries[r].path===e){n=r;break}if(n<=0)return t;let r=[...t.entries.slice(0,n),...t.entries.slice(n+1)],i=n<=t.index?Math.max(0,t.index-1):t.index;return n===t.index&&v(r[i]),{entries:r,index:Math.min(i,r.length-1)}})},[v]),w=s(e=>{o(e)},[]),T=s((e,t)=>hn(n,c.current,t),[n]),E=s((e,t)=>gn(n,c.current,p,o,t)?!0:t.escape&&h.length>1?(x(),!0):!1,[n,p,h.length,x]),D=s((e,t)=>T(e,t)||E(e,t),[T,E]);l(()=>(vn({navigate:b,goBack:x,ensure:S,dismiss:C,get stack(){return g.current},get currentPath(){return g.current[g.current.length-1]?.path??`/`}}),()=>vn(null)),[b,x,S,C]);let O=Qe(),k=d(T);k.current=T;let A=d(E);A.current=E,l(()=>{let e=O.register(`router-intercept`,(e,t)=>k.current(e,t),50),t=O.register(`router-default`,(e,t)=>A.current(e,t),5);return()=>{e(),t()}},[O]),l(()=>{let e=n.getInitialFocus(p);e&&!c.current&&o(e)},[p]);let j=u(()=>({routePath:p,currentPath:p,activeId:a,registry:n,onFocusFallback:_,hasRouter:!0}),[p,a,n,_]),M=u(()=>({stack:h,currentPath:p,activeId:a,navigate:b,goBack:x,ensure:S,dismiss:C,focus:w,handleKey:D}),[h,p,a,b,x,S,C,w,D]);return m(bn.Provider,{value:M,children:m(Ve.Provider,{value:j,children:e})})}function Dn(e,t){return t===e||t.startsWith(e+`/`)}function On({path:e,prefix:t,inStack:n,element:r,children:i}){let{currentPath:a,stack:o,activeId:s}=xn(),l=c(Ve),u=e=>l?h(Ve.Provider,{value:{...l,routePath:e,activeId:s},children:[r,i]}):h(p,{children:[r,i]});return e===`*`?u(a):n?o.some(t=>t.path===e)?u(e):null:t?Dn(e,a)?u(e):null:Tn(e,a)?u(e):null}function kn({hasMore:t,count:n,indent:r=` `}){let i=K();return t?h(_,{color:i.inactive,dimColor:!0,children:[r,n===void 0?`▲ ${e.t(`common.more`)}`:e.t(`scroll.above`,{n})]}):null}function An({hasMore:t,count:n,indent:r=` `}){let i=K();return t?h(_,{color:i.inactive,dimColor:!0,children:[r,n===void 0?`▼ ${e.t(`common.more`)}`:e.t(`scroll.below`,{n})]}):null}function jn(e,t){switch(e){case`primary`:return t.text;case`secondary`:return t.inactive;case`danger`:return t.error;case`success`:return t.success;case`warning`:return t.warning;case`accent`:return t.accent}}function $({children:e,type:t=`primary`,bold:n,italic:r,dim:i,wrap:a}){return m(_,{color:jn(t,K()),bold:n,italic:r,dimColor:i,wrap:a,children:e})}function Mn(e){return e.leftArrow?-1:e.rightArrow?1:e.tab?e.shift?-1:1:0}function Nn(e,t,n){return n<=0?0:(e+t+n)%n}function Pn({children:e,type:t=`secondary`,leadingSpace:n=!1}){let r=K();return h(_,{children:[n?` `:``,h(_,{color:jn(t,r),backgroundColor:r.tagBg,children:[` `,`[`,e,`]`,` `]})]})}function Fn(e,t,n=0){return Math.max(3,e-t-3-2-Math.max(0,n))}function In(e){return Math.max(14,Math.floor((Number.isFinite(e)&&e>0?e:24)*.3333333333333333))}function Ln(e,t){let n=Number.isFinite(e)&&e>0?e:0;return Math.min(In(t),Math.max(15,n))}function Rn(e){return Math.max(14,Math.floor((Number.isFinite(e)&&e>0?e:24)/3))}function zn(e,t,n=0){let r=Math.min(Number.isFinite(e)&&e>0?Math.floor(e):0,5),i=Math.max(1,In(t)-n);return Math.min(r,i)}function Bn(e,t){let n=R(V.ellipsis);if(t<=1)return V.ellipsis;if(R(e)<=t)return e;let r=t-n,i=``;for(let t of e){let e=R(t);if(e>r)break;i+=t,r-=e}return`${i}${V.ellipsis}`}function Vn(e,t){let n=R(e);return n<=0||t<=0?``:e.repeat(Math.max(0,Math.floor(t/n)))}function Hn(e,t){let n=R(e);return n>=t?e:e+` `.repeat(t-n)}function Un(e){return Number.isFinite(e)?Math.max(0,Math.min(100,e)):0}function Wn(e){let t=Math.round(Un(e.percent)),n=Math.max(0,Math.floor(e.width));if(n===0)return{pct:t,filledCount:0,cells:[]};let r=e.segments?.filter(e=>e.width>0)??[],i=r.length>0,a,o;if(i){a=[];for(let e of r)for(let t=0;t<e.width;t++)a.push({filled:!0,segmentKey:e.key});for(o=a.length;a.length<n;)a.push({filled:!1})}else o=Math.max(0,Math.min(n,Math.round(t/100*n))),a=Array.from({length:n},(e,t)=>({filled:t<o}));if(e.markers)for(let[t,r]of Object.entries(e.markers)){if(!Number.isFinite(r))continue;let e=Math.max(0,Math.min(n-1,Math.round(r/100*n))),i=a[e];i&&(i.markerKey=t)}return{pct:t,filledCount:o,cells:a}}const Gn={ascii:{filled:`=`,empty:`.`},block:{filled:`█`,empty:`░`},dot:{filled:`▰`,empty:`▱`}};function Kn(e){return e?typeof e==`string`?Gn[e]:e:Gn.block}function qn({label:e,indent:t=` `}){let n=K(),r=typeof e==`string`?e:String(e??``);return h(_,{color:n.inactive,bold:!0,children:[t,r.toUpperCase()]})}function Jn(e,t,n,r){let i=e.length;if(!Number.isFinite(n))return{rows:[...e],fillerCount:0,hasMoreAbove:!1,hasMoreBelow:!1,scrollTop:0};if(n<=0||i===0)return{rows:[],fillerCount:Math.max(0,n),hasMoreAbove:!1,hasMoreBelow:!1,scrollTop:0};let a=t>=0?t:0,o=r;a<o?o=a:a>=o+n&&(o=a-n+1);let s=Math.max(0,i-n);o=Math.min(Math.max(0,o),s);let c=Math.min(i,o+n),l=e.slice(o,c);return{rows:l,fillerCount:Math.max(0,n-l.length),hasMoreAbove:o>0,hasMoreBelow:c<i,scrollTop:o}}function Yn(e,t=`below`){let n=[],r,i=0;return e.forEach((e,a)=>{e.group&&e.group!==r&&(i>0&&n.push({kind:`spacer`}),n.push({kind:`divider`,label:e.group}),i++),r=e.group,n.push({kind:`item`,option:e,optionIndex:a}),e.detail&&t===`below`&&n.push({kind:`detail`,option:e,optionIndex:a})}),n}function Xn(e,t,n,r){return Jn(e,e.findIndex(e=>e.kind===`item`&&e.optionIndex===t),n,r)}function Zn(){let e=process.env.OTTO_TUI_REDUCED_MOTION;return e===`1`||e===`true`}function Qn(e){return Math.max(1,Math.round(e/80))*80}const $n={now:()=>Date.now(),setTimer:(e,t)=>{let n=setTimeout(e,t);return n.unref?.(),n},clearTimer:e=>clearTimeout(e)};function er(e={}){let t=e.clock??$n,n=e.reducedMotion??(()=>{let e=process.env.OTTO_TUI_REDUCED_MOTION;return e===`1`||e===`true`}),r=new Set,i=null,a=t.now(),o=e=>e.startedAtElapsed+(e.lastFrame+1)*e.periodMs,s=()=>{if(i!==null&&(t.clearTimer(i),i=null),r.size===0)return;let e=t.now()-a,n=1/0;for(let e of r){let t=o(e);t<n&&(n=t)}let s=Math.max(0,n-e);i=t.setTimer(c,s)},c=()=>{i=null;let e=t.now()-a;for(let t of r){let n=Math.floor((e-t.startedAtElapsed)/t.periodMs);if(n!==t.lastFrame){t.lastFrame=n;try{t.onFrame(n)}catch{}}}s()};return{subscribe(e,i){if(!Number.isFinite(e)||e<=0||n())return()=>{};let o=Qn(e),c=t.now()-a,l={periodMs:o,onFrame:i,lastFrame:0,startedAtElapsed:Math.floor(c/80)*80};return r.add(l),s(),()=>{r.delete(l),s()}},minPeriodMs(){let e;for(let t of r)e=e===void 0?t.periodMs:Math.min(e,t.periodMs);return e},size:()=>r.size,dispose(){r.clear(),i!==null&&(t.clearTimer(i),i=null)}}}const tr=er();function nr(e,t){let n=d(t);n.current=t,l(()=>{if(e!=null)return tr.subscribe(e,e=>n.current(e))},[e])}function rr(e,t={}){let n=t.maxVisible??10,r=e.findIndex(e=>!e.disabled);r<0&&(r=0);let i=0;function a(){r<i?i=r:r>=i+n&&(i=r-n+1);let t=Math.max(0,e.length-n);i<0&&(i=0),i>t&&(i=t)}function o(n){if(n<0){t.onBoundary?.(`top`);return}if(n>=e.length){t.onBoundary?.(`bottom`);return}let i=n>r?1:-1,o=n;for(;o>=0&&o<e.length&&e[o]?.disabled;)o+=i;if(o<0){t.onBoundary?.(`top`);return}if(o>=e.length){t.onBoundary?.(`bottom`);return}r=o,a(),o===0&&t.onBoundary?.(`top`),o===e.length-1&&t.onBoundary?.(`bottom`)}return a(),{get selectedIndex(){return r},get scrollOffset(){return i},getVisibleOptions(){return e.slice(i,i+n)},getOptionAt(t){return e[t]},hasMoreAbove(){return i>0},hasMoreBelow(){return i+n<e.length},getSelected(){return e[r]??null},moveUp(){o(r-1)},moveDown(){o(r+1)},accept(){return e[r]??null},selectByHotkey(t){let n=e.findIndex(e=>e.hotkey===t);return n>=0&&!e[n]?.disabled?(r=n,a(),e[n]):null},selectByIndex(t){t>=0&&t<e.length&&!e[t]?.disabled&&(r=t,a())}}}function ir(e,t){return t.escape?{type:`cancel`}:t.return?{type:`accept`}:un(`list-nav-up`,e,t)?{type:`up`}:un(`list-nav-down`,e,t)?{type:`down`}:/^[1-9]$/.test(e)?{type:`index`,index:Number(e)-1}:null}const ar={black:0,red:.3,green:.55,yellow:.93,blue:.2,magenta:.4,cyan:.7,white:1,gray:.5,grey:.5};function or(e){if(e.startsWith(`#`)){let t=e.slice(1),[n,r,i]=(t.length===3?[t[0]+t[0],t[1]+t[1],t[2]+t[2]]:[t.slice(0,2),t.slice(2,4),t.slice(4,6)]).map(e=>parseInt(e,16)/255);return .299*n+.587*r+.114*i}return ar[e.toLowerCase()]??.5}function sr(e){return e&&or(e)>.55?`black`:`white`}function cr(e,t){switch(e){case`accent`:return t.selection;case`amber`:return t.warning;case`red`:return t.error;case`green`:return t.success;case`gray`:return t.panelBorder}}function lr(e,t){return cr(e,t)}function ur(e,t=w){let{label:n,variant:r=`ghost`,color:i=`accent`,focused:a=!1,disabled:o=!1}=e,s=e.brackets??r===`outline`,c=`[ ${n} ]`;if(o)return{label:c,color:t.inactive,bold:!1,dim:!0};if(r===`ghost`){let e=` ${n} `;if(a){let n=cr(i,t);return{label:s?c:e,color:sr(n),backgroundColor:n,bold:!0,dim:!1}}return{label:s?c:e,color:t.inactive,bold:!1,dim:!1}}let l=cr(i,t),u=lr(i,t);if(r===`solid`){let e=` ${n} `;return a?{label:s?c:e,color:sr(l),backgroundColor:l,bold:!0,dim:!1}:{label:s?c:e,color:s?t.inactive:u,bold:!1,dim:!1}}return a?{label:s?c:` ${n} `,color:u,bold:!0,dim:!1}:{label:s?c:` ${n} `,color:t.inactive,bold:!1,dim:!1}}function dr({label:e,variant:t=`ghost`,color:n=`accent`,focused:r,disabled:i=!1,brackets:a,tabIndex:o=-1,onAction:s}){let c=K(),{focused:l}=Ue({tabIndex:o,disabled:i||o<0,onAction:s}),u=ur({label:e,variant:t,color:n,focused:r??l,disabled:i,brackets:a},c);return m(_,{color:u.color,backgroundColor:u.backgroundColor,bold:u.bold,dimColor:u.dim||void 0,children:u.label})}function fr(e){return null}fr.displayName=`Select.Item`;function pr(e){return null}pr.displayName=`Select.Label`;function mr(e){return null}mr.displayName=`Select.Group`;function hr(){return null}hr.displayName=`Select.Separator`;function gr({children:e}){return m(p,{children:e})}gr.displayName=`Select.Content`;function _r(e){return null}_r.displayName=`Select.Trigger`;function vr(e){if(typeof e==`string`||typeof e==`number`)return String(e);if(Array.isArray(e))return e.map(vr).join(``);if(i.isValidElement(e)){let t=e.props;return vr(t.children)}return``}function yr(e){let t=[],n=0;function r(e,a){i.Children.forEach(e,e=>{if(!i.isValidElement(e))return;let o=e.type;if(o.displayName===`Select.Item`){let r=e.props;n+=1,t.push({value:r.value,label:vr(r.children),disabled:r.disabled,detail:r.detail,indent:r.indent,marker:r.marker,ordinal:n,trailingLabel:r.trailingLabel,trailingColor:r.trailingColor,labelColor:r.labelColor,group:a});return}if(o.displayName===`Select.Group`){let t=e.props,n;i.Children.forEach(t.children,e=>{i.isValidElement(e)&&e.type.displayName===`Select.Label`&&(n=vr(e.props.children))}),r(t.children,n);return}if(o.displayName===`Select.Label`||o.displayName===`Select.Separator`||o.displayName===`Select.Trigger`)return;let s=e.props;s.children!==void 0&&r(s.children,a)})}return r(e,void 0),t}function br({title:t,subtitle:n,headerAction:r,defaultValue:i,onValueChange:a,onCancel:o,maxVisible:s=10,footer:c,active:l=!0,onKey:v,frame:y=!0,highlightSelection:b=!0,rows:x=24,extensionHeightBudget:S=!1,detailPlacement:C=`below`,children:w}){let T=K(),E=u(()=>yr(w),[w]),D=u(()=>C===`inline`?Math.max(0,...E.map(e=>R(e.label))):0,[C,E]),O=u(()=>C===`inline`?Math.max(0,...E.map(e=>R(e.trailingLabel??``))):0,[C,E]),k=d(null);if(!k.current){let e=i?E.findIndex(e=>e.value===i):-1;k.current=rr(E,{maxVisible:s}),e>=0&&k.current.selectByIndex(e)}let A=k.current,[j,M]=f(!1);nr(2e3,e=>M(e%2==1));let[,ee]=f(0),N=()=>ee(e=>e+1),[P,F]=f(()=>!!r&&!E.some(e=>!e.disabled));J(`select-primitive`,(e,t)=>{if(v?.(e,t,A.getSelected())){N();return}if(r&&P){if(t.return){r.onPress();return}if(t.downArrow){F(!1),N();return}if(t.escape){o?.();return}return}let n=ir(e,t);if(n)switch(n.type){case`cancel`:o?.();return;case`up`:{let e=A.selectedIndex;A.moveUp(),r&&A.selectedIndex===e&&F(!0),N();return}case`down`:A.moveDown(),N();return;case`index`:{A.selectByIndex(n.index);let e=A.getSelected();e&&!e.disabled&&a?.(e.value);return}case`accept`:{let e=A.accept();e&&!e.disabled&&a?.(e.value);return}}},{isActive:l});let I=u(()=>Yn(E,C),[E,C]),L=d(0),te=y?S?Math.max(1,Math.min(I.length,Rn(x)-9)):Ln(I.length+9,x)-9:1/0,z=Xn(I,A.selectedIndex,te,L.current);L.current=z.scrollTop;let ne=E[A.selectedIndex]??null,B=h(p,{children:[t&&m(Ne,{children:t}),t&&m(g,{marginTop:W.tight}),n&&m($,{type:`secondary`,children:n}),r&&h(g,{flexDirection:`row`,alignSelf:`flex-start`,marginTop:n?W.tight:W.none,...ue,borderColor:T.accent,paddingX:W.tight,children:[h(_,{color:T.accent,children:[r.hint,` `]}),m(dr,{variant:`ghost`,brackets:!0,color:`accent`,label:r.label,focused:P,tabIndex:-1})]})]}),re=h(p,{children:[m(g,{height:1,children:m(kn,{hasMore:z.hasMoreAbove})}),z.rows.map((t,n)=>{if(t.kind===`spacer`)return m(_,{children:` `},`spacer-${n}`);if(t.kind===`divider`)return m(g,{flexDirection:`column`,children:m(qn,{label:t.label,indent:``})},`div-${n}`);let r=t.option;if(t.kind===`detail`){let e=r.indent??` `,n=r.detail??``,i=r.marker===`number`?` `.repeat(`${r.ordinal}. `.length):r.marker?` `.repeat(`${r.marker} `.length):``,a=/^● (.+?) · /u.exec(n),o=a?.[1],s=a?n.slice(a[0].length):n;return h(_,{wrap:`truncate-end`,children:[h($,{type:`secondary`,dim:!0,children:[` `,e,i]}),o?h(_,{color:T.accent,children:[j?V.breatheBright:V.breatheDim,` `,o]}):null,m($,{type:`secondary`,dim:!0,children:o?` · ${s}`:s})]},`detail-${t.optionIndex}`)}let i=r.indent??` `,a=r.marker===`number`?`${r.ordinal}. `:r.marker?`${r.marker} `:``,o=b&&r===ne&&!P,s=C===`inline`&&r.detail;return h(g,{flexDirection:`row`,children:[h(_,{color:r.disabled?T.inactive:o?T.selection:r.labelColor??T.inactive,dimColor:r.disabled,bold:o&&!r.disabled,children:[o&&!r.disabled?`${V.pointer} `:` `,i,a,s?`${Hn(r.label,D)} ${Hn(r.trailingLabel??``,O)} ${r.detail}`:r.label,r.disabled?` (${e.t(`common.disabled`)})`:``]}),r.trailingLabel&&!s&&h(p,{children:[m($,{type:`secondary`,children:` `}),m(_,{color:r.trailingColor??T.inactive,dimColor:!r.trailingColor,children:r.trailingLabel})]})]},`item-${t.optionIndex}`)}),Array.from({length:z.fillerCount},(e,t)=>m(_,{children:` `},`filler-${t}`)),m(g,{height:1,children:m(An,{hasMore:z.hasMoreBelow})})]});return y?m(Me,{header:B,footer:c??m(Fe,{items:[[`${q.up}${q.down}`,e.t(`hint.select`)],[q.enter,e.t(`hint.confirm`)],[q.esc,e.t(`hint.cancel`)]]}),maxHeight:S&&y?Rn(x):void 0,children:re}):h(g,{flexDirection:`column`,children:[B,re]})}const xr={Root:br,Trigger:_r,Content:gr,Group:mr,Label:pr,Item:fr,Separator:hr};function Sr({title:t,message:n,confirmLabel:r,cancelLabel:i,confirmColor:a=`accent`,dangerous:o=!1,extraLabel:c,extraColor:l=`amber`,checkLabel:u,checked:d=!1,onConfirm:p,onCancel:v,onExtra:y,onCheckChange:b}){let x=!!c,S=x?2:1,[C,w]=f(o?S:0),[T,E]=f(d),D=Array.isArray(n)?n:[n],O=s(()=>{let e=!T;E(e),b?.(e)},[T,b]);Ue({onEscape:()=>(v(),!0)}),J(`confirm-dialog-buttons`,(e,t)=>{if(t.escape)return v(),!0;let n=Mn(t);return n===0?t.return?(w(e=>(e===0?p():x&&e===1?y?.():v(),e)),!0):u&&e===` `&&!t.ctrl&&!t.meta?(O(),!0):!1:(w(e=>Nn(e,n,S+1)),!0)});let k=r??e.t(`common.confirmButton`),A=i??e.t(`common.genericCancelButton`);return h(Me,{header:m(Ne,{children:t}),footer:m(Fe,{items:[[`${q.left}${q.right}`,e.t(`hint.switch`)],[q.enter,e.t(`hint.confirm`)],[q.esc,e.t(`hint.cancel`)]]}),children:[m(g,{marginTop:W.tight,flexDirection:`column`,children:D.map((e,t)=>m(_,{wrap:`truncate-end`,children:e===``?` `:e},t))}),u&&h(g,{marginTop:W.tight,children:[h($,{type:`secondary`,children:[T?V.bullet:V.todoPending,` `]}),m($,{type:`secondary`,children:u})]}),h(g,{marginTop:W.tight,flexDirection:`row`,gap:W.section,children:[m(dr,{variant:`solid`,brackets:!0,color:a,label:k,focused:C===0}),x&&m(dr,{variant:`solid`,brackets:!0,color:l,label:c,focused:C===1}),m(dr,{variant:`solid`,brackets:!0,color:`gray`,label:A,focused:C===S})]})]})}function Cr({tabIndex:e=0,autoFocus:t=!1,options:n,onSelect:r,initialIndex:i=0,maxVisible:a=8,id:o,compact:s=!1}){let c=K(),{focused:l}=Ue({tabIndex:e,autoFocus:t,id:o}),[u,d]=f(Math.min(i,n.length-1));et(l,(e,t)=>{if(t.upArrow)return d(e=>{let t=e;for(let r=1;r<=n.length;r++){let i=(e-r+n.length)%n.length;if(!n[i]?.disabled){t=i;break}}return t}),!0;if(t.downArrow)return d(e=>{let t=e;for(let r=1;r<=n.length;r++){let i=(e+r)%n.length;if(!n[i]?.disabled){t=i;break}}return t}),!0;if(t.return){let e=n[u];return e&&!e.disabled&&r(e.value),!0}for(let t=0;t<Math.min(n.length,9);t++)if(e===String(t+1)&&n[t]&&!n[t].disabled)return r(n[t].value),!0;return!1});let p=n.length,v=p<=a?0:Math.min(Math.max(0,u-Math.floor(a/2)),p-a),y=n.slice(v,v+a);return h(g,{flexDirection:`column`,children:[v>0&&m(g,{children:h(_,{color:c.inactive,dimColor:!0,children:[` ▲ `,v]})}),y.map((e,t)=>{let n=v+t===u,r=n&&l,i=e.disabled?c.inactive:r||n?c.selection:c.inactive,a=n&&!e.disabled;return h(g,{marginBottom:s?W.none:W.tight,flexDirection:`column`,children:[h(_,{color:i,bold:a,children:[r?`${V.pointer} `:` `,e.label]}),e.detail&&m(g,{marginLeft:W.section,children:m(_,{color:c.inactive,children:e.detail})})]},e.value)}),v+a<p&&m(g,{children:h(_,{color:c.inactive,dimColor:!0,children:[` ▼ `,p-v-a]})})]})}function wr({label:e,detail:t,disabled:n,children:r}){let i=K();return h(g,{flexDirection:`column`,children:[m(_,{color:n?i.inactive:void 0,children:e}),t&&m(_,{color:i.inactive,dimColor:!0,children:t}),r]})}function Tr(e,t){switch(e){case`success`:return t.success;case`warning`:return t.warning;case`error`:return t.error;case`muted`:return t.inactive;case`secondary`:return t.secondary}}function Er(e){let t=[],n=[];for(let r of e)r.kind===`group`?(n.length>0&&t.push(n),n=[r]):n.push(r);return n.length>0&&t.push(n),t}function Dr({entries:e}){let t=K();return m(g,{flexDirection:`column`,children:Er(e).map((e,n)=>{let r=e.filter(e=>e.kind===`row`),i=Math.max(0,...r.map(e=>R(e.label)));return m(g,{flexDirection:`column`,marginTop:n>0?W.tight:W.none,children:e.map((e,n)=>{if(e.kind===`group`)return m(qn,{label:e.title},n);if(e.kind===`blank`)return m(_,{children:` `},n);if(e.kind===`text`)return m(_,{color:e.tone?Tr(e.tone,t):void 0,dimColor:e.tone===`muted`,children:e.value},n);let r=` `.repeat(Math.max(0,i-R(e.label)));return h(_,{children:[` `,m(_,{color:t.inactive,children:e.label}),r,` `,m(_,{color:e.tone?Tr(e.tone,t):void 0,children:e.value})]},n)})},n)})})}function Or(t){switch(t){case`retry`:return e.t(`retry.nowButton`);case`login`:return e.t(`model.goToLoginButton`);case`extension`:return e.t(`model.goToExtensionButton`)}}function kr(e,t){switch(e){case`success`:return t.success;case`muted`:return t.inactive;case`warning`:return t.warning}}function Ar({title:t,lines:n,lineTones:r,onDismiss:i,action:a,dataListEntries:o}){let s=K();J(`info-dialog`,(e,t)=>t.escape?(i(),!0):t.return&&a?(i(),queueMicrotask(()=>a.run()),!0):!1);let c=a?Or(a.kind):void 0;return h(Me,{header:m(Ne,{children:t}),footer:m(Fe,{items:a?[[q.enter,c],[q.esc,e.t(`hint.close`)]]:[[q.esc,e.t(`hint.close`)]]}),children:[m(g,{marginTop:W.tight,flexDirection:`column`,children:o?m(Dr,{entries:o}):n.map((e,t)=>{let n=r?.[t];return m(_,{color:n?kr(n,s):void 0,dimColor:n===`muted`,wrap:`truncate-end`,children:e===``?` `:e},t)})}),a&&m(g,{marginTop:W.tight,children:m(dr,{variant:`solid`,brackets:!0,color:`accent`,label:c,focused:!0})})]})}function jr({percent:e,width:t,chars:n,color:r,segments:i,markers:a,labelPosition:o=`suffix`,labelPrefix:s=``}){let c=K(),{filled:l,empty:u}=Kn(n),d=Wn({percent:e,width:t,segments:i?.map(e=>({key:e.key,width:e.width}))}),f=new Map((i??[]).map(e=>[e.key,e.color])),p=new Map((i??[]).map(e=>[e.key,e.dimColor??!1])),g=new Map(Object.entries(a??{}).map(([e,t])=>[t.pos,{name:e,color:t.color}])),v=(e=>typeof r==`function`?r(e):typeof r==`string`?r:c.inactive)(d.pct),y=`${s}${d.pct}%`;return h(_,{children:[o===`prefix`?h(_,{color:v,bold:!0,children:[y,` `]}):null,d.cells.map((e,t)=>{let n=g.get(t),r=c.inactive;e.filled&&(r=e.segmentKey?f.get(e.segmentKey)??v:v),n&&e.filled&&(r=n.color);let i=e.filled&&e.segmentKey?p.get(e.segmentKey)??!1:!1;return m(_,{color:r,dimColor:i,children:e.filled?l:u},t)}),o===`suffix`?h(_,{children:[` `,y]}):null]})}const Mr={pending:V.todoPending,active:V.todoActive,done:V.check,error:V.cross};function Nr(e,t){let n=[];return e.forEach((e,r)=>{let i=t[r]??`pending`;i!==`pending`&&n.push({label:e,status:i})}),n}function Pr({title:t,phases:n,phaseStatuses:r,percent:a,detail:o,subProgress:s,status:c,errorMessage:u,nextStep:v,onDismiss:y}){let b=K(),x=c===`running`,S=d(null);l(()=>{if(c===`success`)return S.current=setTimeout(y,2e3),()=>{S.current&&clearTimeout(S.current)}},[c,y]);let[C,w]=f(0);return nr(c===`running`?160:null,e=>{w(e%H.length)}),J(`progress-dialog`,(e,t)=>(t.return||t.escape)&&c!==`running`?(y(),!0):!1),m(Me,{header:m(Ne,{children:t}),footer:c===`partial`||c===`error`?m(Fe,{items:[[`${q.enter}/${q.esc}`,e.t(`hint.close`)]]}):void 0,children:h(g,{flexDirection:`column`,paddingX:W.tight,children:[m(g,{height:1}),x?n.map((e,t)=>{let n=r[t]??`pending`,i=n===`active`,a=n===`error`,s=n===`done`,c=b.inactive;return i?c=b.accent:a?c=b.error:s&&(c=b.success),h(g,{children:[h(_,{color:c,children:[Mr[n]??` `,` `]}),m(_,{color:i?b.accent:a?b.error:s?b.success:b.inactive,children:e}),i?h(p,{children:[h(_,{color:b.accent,children:[` `,H[C],` `]}),m($,{type:`secondary`,children:o})]}):null]},t)}):null,!x&&c!==`success`?m(g,{children:Nr(n,r).map((e,t)=>h(i.Fragment,{children:[t>0?m($,{type:`secondary`,children:` · `}):null,h(_,{color:e.status===`error`?b.error:e.status===`done`?b.success:b.accent,children:[Mr[e.status],` `]}),m($,{type:`secondary`,children:e.label})]},t))}):null,s&&c===`running`?m(g,{marginTop:W.tight,children:h(Pn,{children:[s.current,`/`,s.total]})}):null,x?m(g,{marginTop:W.tight,marginBottom:W.tight,children:m(jr,{percent:a,width:40,chars:`ascii`,color:b.accent})}):null,x?null:h(g,{marginTop:c===`success`?W.none:W.tight,flexDirection:`column`,children:[m(g,{children:h(_,{bold:!0,color:c===`success`?b.success:c===`partial`?b.warning:b.error,children:[c===`success`?V.check:c===`partial`?V.warn:V.cross,` `,c===`success`?e.t(`install.done`):c===`partial`?e.t(`install.summaryPartial`):e.t(`install.summaryFailed`)]})}),c!==`success`&&u?m(g,{marginTop:W.tight,children:m($,{type:`secondary`,wrap:`wrap`,children:u})}):null,v?m(g,{marginTop:W.tight,children:m($,{type:`secondary`,children:v.label})}):null]})]})})}function Fr(e){return e.some(e=>e.freeformInput===!0)}function Ir(e){return{tab:0,cursor:0,selected:e.map(()=>[]),freeformText:``,freeformOffset:0}}function Lr(e,t,n=!1){return t.escape?{type:`cancel`}:t.tab?{type:t.shift?`tabPrev`:`tabNext`}:un(`list-nav-up`,e,t)?{type:`cursorPrev`}:un(`list-nav-down`,e,t)?{type:`cursorNext`}:!n&&(e===` `||t.return)?{type:`choose`}:null}function Rr(e,t,n){let r=Fr(n),i=n.length+(r?1:0),a=r?n.length:-1;switch(t?.type){case`cancel`:return{state:e,done:`cancel`};case`tabPrev`:return{state:{...e,tab:(e.tab-1+i+1)%(i+1),cursor:0}};case`tabNext`:return{state:{...e,tab:(e.tab+1)%(i+1),cursor:0}};case`cursorPrev`:return e.tab===i||e.tab===a?{state:e}:{state:{...e,cursor:Math.max(0,e.cursor-1)}};case`cursorNext`:{if(e.tab===i||e.tab===a)return{state:e};let t=n[e.tab].options.length;return{state:{...e,cursor:Math.min(t-1,e.cursor+1)}}}case`choose`:{if(e.tab===i)return{state:e,done:`submit`};if(e.tab===a)return{state:{...e,tab:i}};let t=n[e.tab],r=e.selected[e.tab]??[],o=t.multiSelect?r.includes(e.cursor)?r.filter(t=>t!==e.cursor):[...r,e.cursor]:[e.cursor],s=e.selected.map((t,n)=>n===e.tab?o:t),c=t.multiSelect?e.tab:Math.min(i,e.tab+1);return{state:{...e,selected:s,tab:c,cursor:0}}}default:return{state:e}}}function zr(e,t){let n={};return t.forEach((t,r)=>{n[t.header]=(e.selected[r]??[]).map(e=>t.options[e]?.label).filter(e=>typeof e==`string`)}),n}function Br(e,t){return t.every((t,n)=>(e.selected[n]?.length??0)>0)}function Vr(e){return Bn(e,23)}function Hr({title:t,questions:n,onSubmit:r,onCancel:a,columns:o=60}){let s=K(),c=Fr(n),l=d(null);l.current??=Ir(n);let[,u]=f(0),v=c?n.length:-1,y=n.length+(c?1:0),b=e=>{let t=l.current,i=Lr(``,{tab:!0,shift:e},t.tab===v);if(!i)return!1;let{state:o,done:s}=Rr(t,i,n);return l.current=o,s===`cancel`?(a?.(),!0):s===`submit`?(r(zr(o,n),o.freeformText||void 0),!0):(u(e=>e+1),!0)};Ue({onEscape:()=>(a?.(),!0),onTab:e=>b(e)}),J(`questions-dialog`,(e,t)=>{let i=l.current;if(i.tab===v){if(t.escape&&i.freeformText.length===0){a?.();return}if(t.tab){b(t.shift??!1);return}if(t.leftArrow){let e=wt.fromText(i.freeformText,o,i.freeformOffset).left();l.current={...i,freeformText:e.text,freeformOffset:e.offset},u(e=>e+1);return}if(t.rightArrow){let e=wt.fromText(i.freeformText,o,i.freeformOffset).right();l.current={...i,freeformText:e.text,freeformOffset:e.offset},u(e=>e+1);return}if(e.length>1&&!t.ctrl&&!t.meta&&!t.return&&!t.escape&&!t.backspace&&!t.delete&&!t.leftArrow&&!t.rightArrow){let t=Mt(e);if(t){let e=i.freeformText,n=i.freeformOffset;l.current={...i,freeformText:e.slice(0,n)+t+e.slice(n),freeformOffset:n+t.length},u(e=>e+1)}return}if(t.return){let{state:e,done:t}=Rr(i,Lr(``,{tab:!0},!0),n);if(l.current=e,t===`submit`){r(zr(e,n),e.freeformText||void 0);return}u(e=>e+1);return}let s={name:t.escape?`escape`:t.backspace?`backspace`:t.delete?`delete`:e||`unknown`,ctrl:t.ctrl??!1,shift:!1,alt:t.meta??!1,meta:t.meta??!1},c=jt(wt.fromText(i.freeformText,o,i.freeformOffset),s);if(!c)return;l.current={...i,freeformText:c.cursor.text,freeformOffset:c.cursor.offset},u(e=>e+1);return}let s=Lr(e,t);if(!s)return;let{state:c,done:d}=Rr(i,s,n);if(l.current=c,d===`cancel`){a?.();return}if(d===`submit`){r(zr(c,n),c.freeformText||void 0);return}u(e=>e+1)});let x=l.current,S=x.tab===y,C=x.tab===v?m(Fe,{items:[[q.enter,e.t(`freeform.advance`)],[q.esc,e.t(`hint.cancel`)]]}):m(Fe,{items:[[`${q.up}${q.down}`,e.t(`hint.option`)],[q.tab,e.t(`hint.question`)],S?[q.enter,e.t(`hint.submit`)]:[`space/${q.enter}`,e.t(`hint.choose`)],[q.esc,e.t(`hint.cancel`)]]});return h(Me,{header:t?m(Ne,{children:t}):void 0,footer:C,children:[h(g,{flexDirection:`row`,marginTop:W.tight,children:[n.map((e,t)=>{let n=(x.selected[t]?.length??0)>0,r=x.tab===t,a=r?s.selection:n?s.success:s.inactive;return h(i.Fragment,{children:[t>0&&m($,{type:`secondary`,dim:!0,children:` · `}),m(_,{color:a,bold:r,children:Vr(e.header)})]},t)}),c&&h(p,{children:[m($,{type:`secondary`,dim:!0,children:` · `}),m(_,{color:x.tab===v?s.selection:x.freeformText?s.success:s.inactive,bold:x.tab===v,children:e.t(`freeform.tab`)})]}),m($,{type:`secondary`,dim:!0,children:` · `}),m(_,{color:S?s.selection:s.inactive,bold:S,children:e.t(`prompt.submit`)})]}),S?h(g,{flexDirection:`column`,marginTop:W.tight,children:[m(_,{color:Br(x,n)?s.success:s.warning,children:Br(x,n)?e.t(`questions.readyToSubmit`):e.t(`questions.someUnanswered`)}),m(g,{marginTop:W.tight,children:m(dr,{variant:`solid`,brackets:!0,color:`accent`,label:e.t(`prompt.submit`),focused:!0})})]}):x.tab===v?h(g,{flexDirection:`column`,marginTop:W.tight,children:[m(_,{color:s.secondary,children:e.t(`freeform.label`)}),m(g,{marginTop:W.tight,children:m(tn,{value:x.freeformText,offset:x.freeformOffset,columns:o,mode:`dialog`,placeholder:e.t(`freeform.placeholder`),focused:!0,physicalCursor:!0})})]}):h(g,{flexDirection:`column`,marginTop:W.tight,children:[n[x.tab].question!==t&&m(_,{color:s.text,children:n[x.tab].question}),m(g,{flexDirection:`column`,marginTop:W.tight,children:n[x.tab].options.map((e,t)=>{let n=t===x.cursor,r=(x.selected[x.tab]??[]).includes(t),i=r?V.bullet:V.todoPending;return h(g,{flexDirection:`column`,children:[h(g,{flexDirection:`row`,children:[m(_,{color:n?s.selection:s.inactive,bold:n,children:n?`${V.pointer} `:` `}),m(_,{color:n?s.selection:r?s.success:s.inactive,bold:n,children:i}),m(_,{children:` `}),m(_,{color:n?s.selection:r?s.success:s.inactive,bold:n,children:e.label})]}),e.description&&m(g,{marginLeft:W.loose,children:m($,{type:`secondary`,dim:!0,children:e.description})})]},t)})})]})]})}const Ur=[`Resolving`,`Installing`,`Authorizing`,`Reloading`],Wr={pending:V.todoPending,active:V.todoActive,done:V.check};function Gr(e){return e?Ur.findIndex(t=>e.includes(t)):-1}function Kr(e,t,n,r){return h(g,{flexDirection:`row`,marginBottom:W.tight,children:[n.map((n,a)=>{let o=t.has(a),s=a===e,c=o?V.check:s?V.todoDone:V.todoPending,l=o?r.inactive:s?r.text:r.inactive;return h(i.Fragment,{children:[a>0&&m($,{type:`secondary`,children:` · `}),h(_,{color:l,bold:s,children:[c,` `,n]})]},a)}),h(g,{marginLeft:W.section,children:[m($,{type:`secondary`,children:`Step `}),m(_,{color:r.text,bold:!0,children:e+1}),h($,{type:`secondary`,children:[`/`,4]})]})]})}function qr(){return m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,dim:!0,children:Vn(V.hr,60)})})}function Jr({request:t}){let n=K(),[r,i]=f(!1),[a,o]=f(!1),[c,u]=f(()=>Math.min(t.initialCurrent,3)),[p,v]=f(()=>new Set(t.initialCompleted)),[y,b]=f(null),[x,S]=f(null),[C,w]=f(null),[T,E]=f(null),[D,O]=f(null),[k,A]=f(null),[j,M]=f([]),[ee,N]=f(!1),P=d(null),[F,I]=f(`select`),[L,te]=f(null),[R,z]=f(null),[ne,B]=f(null),[re,ie]=f(``),ae=d(``),[oe,se]=f(t.authProviderName??``),H=s(e=>{ae.current=e,ie(e)},[]),U=d(null),ce=d(!1),le=s(()=>{ce.current=!0,U.current?.cancel(),P.current&&=(clearTimeout(P.current),null),t.onDismiss()},[t]),ue=s(()=>{if(F!==`select`&&c===1){U.current?.cancel(),I(`select`),te(null),z(null),B(null),H(``),ae.current=``,b(null);return}if(D){O(null),b(null);return}c===0?le():(v(e=>{let t=new Set(e);return t.delete(c-1),t}),u(e=>e-1),b(null),I(`select`),te(null),z(null),B(null),H(``),E(null),M([]),N(!1),O(null),P.current&&=(clearTimeout(P.current),null))},[c,le,F,D]);l(()=>()=>{U.current?.cancel(),P.current&&clearTimeout(P.current)},[]);let G=s(()=>{v(e=>new Set([...e,c])),b(null),S(null),E(null),M([]),N(!1),O(null),I(`select`),A(null),te(null),z(null),B(null),H(``),ae.current=``,U.current=null,c>=3?(le(),t.onComplete()):u(e=>e+1)},[c,le,t]),de=d(null),fe=s(async e=>{S(e),w(null),b(null);let n=await t.onInstallProvider(e,e=>{ce.current||w(e)});ce.current||(S(null),w(null),n.ok?(se(n.providerId??e),M(n.capabilities??[]),N(n.pendingCapabilities===!0),E(e),P.current=setTimeout(()=>{P.current=null,G()},900)):(O(e),b(n.error)))},[t,G]);de.current=fe;let pe=s(()=>{let e=D;e&&(O(null),b(null),de.current?.(e))},[D]),me=s(()=>{O(null),b(null)},[]),he=d(null),ge=s(async()=>{if(!t.onProviderOAuthStart)return;b(null),I(`oauth-wait`);let e=await t.onProviderOAuthStart(oe);if(!e){I(`select`),b(`OAuth flow not available for this provider.`);return}U.current=e,te(e.authorizationUrl),z(e.code??null),B(e.instructions??null);let n=async()=>{if(ce.current)return;let t=await e.poll();if(ce.current)return;let r=typeof t==`string`?t:t.status,i=typeof t==`string`?void 0:t.reason;r===`pending`?setTimeout(()=>{n().catch(()=>{})},1500):r===`done`?G():i===`cancelled`?I(`select`):A(i===`network`?`network`:`rejected`)};n().catch(()=>{})},[t,G,oe]),_e=s(()=>{A(null),b(null),he.current?.()},[]),ve=s(()=>{A(null),t.onOpenProxySettings?.()},[t]);he.current=ge;let ye=s(()=>{U.current?.openAgain?.()},[]),be=s(()=>{U.current?.cancel(),U.current=null,te(null),z(null),B(null),b(null),H(``),I(`key-input`)},[H]),xe=s(async()=>{if(!t.onSubmitProviderApiKey||!ae.current.trim())return;b(null),I(`logging-in`);let e=await t.onSubmitProviderApiKey(oe,ae.current.trim());e.ok?G():(I(`key-input`),b(e.error))},[t,G,re,oe]),Se=s(async e=>{b(null);try{await t.onSelectModel(e),G()}catch(e){b(e instanceof Error?e.message:String(e))}},[t,G]),Ce=s(()=>G(),[G]);J(`wizard-dialog`,(e,n)=>{if(!r){if(n.return){t.onDontShowAgain(a),i(!0);return}if(n.escape){le();return}if(e===` `){o(e=>!e);return}return}if(n.escape){ue();return}});let we=(()=>{if(!r)return[[q.enter,t.welcomeStartLabel],[q.esc,t.welcomeCancelLabel],[`Space`,t.welcomeDontShowAgainLabel]];let n=c===0&&!D?`exit`:`back`;switch(c){case 0:{let r=Math.min(t.providerOptions.length,9);return[[`${q.up}${q.down}`,e.t(`hint.select`)],[`1-${r}`,e.t(`hint.quick`)],[q.enter,e.t(`setup.actionInstall`)],[q.esc,n]]}case 1:return F===`key-input`?[[q.enter,`submit`],[q.esc,n]]:F===`oauth-wait`?[[q.esc,`cancel`]]:[[`1-${Math.min(t.providerAuthOptions(oe).length,9)}`,e.t(`hint.quick`)],[q.enter,e.t(`setup.actionLogin`)],[q.esc,n]];case 2:{let r=Math.min(t.modelOptions.length,9);return[[`${q.up}${q.down}`,e.t(`hint.select`)],[`1-${r}`,e.t(`hint.quick`)],[q.enter,e.t(`hint.confirm`)],[q.esc,n]]}case 3:return[[q.enter,e.t(`hint.confirm`)]];default:return[[q.esc,n]]}})();return m(Me,{header:m(Ne,{children:t.title}),footer:m(Fe,{items:we}),children:r?h(g,{flexDirection:`column`,marginTop:W.tight,paddingX:W.section,children:[Kr(c,p,t.stepNames,n),m(g,{marginBottom:W.tight,flexDirection:`column`,children:m(_,{bold:!0,children:t.stepSubtitles[c]})}),m(qr,{}),y&&h(g,{marginBottom:W.tight,flexDirection:`column`,children:[h(_,{color:n.error,children:[e.t(`setup.errorTitle`),`:`]}),m(_,{color:n.error,children:y})]}),m(Yr,{step:c,request:t,installing:x,installPhase:C,installSucceeded:T,installedCapabilities:j,installPendingCaps:ee,installFailed:D,onRetryInstall:pe,onChooseAnother:me,authMode:F,setAuthMode:I,oauthUrl:L,oauthCode:R,oauthInstructions:ne,apiKey:re,apiKeyRef:ae,setApiKey:H,onInstall:fe,onOAuthStart:ge,onApiKeySubmit:xe,onOpenAgain:ye,onSwitchToApiKey:be,onRetryAuth:_e,onOpenProxySettings:ve,authFailure:k,onModel:Se,onComplete:Ce,selectedProvider:oe})]}):h(g,{flexDirection:`column`,marginTop:W.tight,paddingX:W.section,children:[m(g,{marginBottom:W.tight,children:m(_,{bold:!0,children:t.welcomeTitle})}),t.welcomeGreeting&&m(g,{marginBottom:W.tight,children:m(_,{children:t.welcomeGreeting})}),m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:t.welcomeDescription})}),m(qr,{}),m(g,{marginBottom:W.tight,children:h(_,{color:a?n.text:n.inactive,children:[a?V.bullet:V.todoPending,` `,t.welcomeDontShowAgainLabel]})})]})})}function Yr(e){switch(e.step){case 0:return m(Zr,{request:e.request,installing:e.installing,installPhase:e.installPhase,installSucceeded:e.installSucceeded,installedCapabilities:e.installedCapabilities,installPendingCaps:e.installPendingCaps,installFailed:e.installFailed,onRetryInstall:e.onRetryInstall,onChooseAnother:e.onChooseAnother,onInstall:e.onInstall});case 1:return m(Qr,{request:e.request,authMode:e.authMode,setAuthMode:e.setAuthMode,oauthUrl:e.oauthUrl,oauthCode:e.oauthCode,oauthInstructions:e.oauthInstructions,apiKey:e.apiKey,apiKeyRef:e.apiKeyRef,setApiKey:e.setApiKey,onOAuthStart:e.onOAuthStart,onApiKeySubmit:e.onApiKeySubmit,onOpenAgain:e.onOpenAgain,onSwitchToApiKey:e.onSwitchToApiKey,onRetryAuth:e.onRetryAuth,onOpenProxySettings:e.onOpenProxySettings,authFailure:e.authFailure,selectedProvider:e.selectedProvider});case 2:return m($r,{request:e.request,onModel:e.onModel});case 3:return m(ei,{request:e.request,onComplete:e.onComplete});default:return m(_,{children:`Unknown step`})}}function Xr(){let e=K(),t=Zn(),[n,r]=f(0);return nr(160,e=>r(e%H.length)),t?null:h(_,{color:e.accent,children:[` `,H[n]]})}function Zr({request:t,installing:n,installPhase:r,installSucceeded:i,installedCapabilities:a,installPendingCaps:o,installFailed:s,onRetryInstall:c,onChooseAnother:l,onInstall:u}){let d=K(),[p,v]=f(0),y=t.providerOptions,b=n!==null;if(i)return h(g,{flexDirection:`column`,children:[Ur.map(e=>h(g,{children:[h(_,{color:d.success,children:[Wr.done,` `]}),m(_,{color:d.success,children:e})]},e)),m(g,{marginTop:W.tight,children:h(_,{color:d.success,bold:!0,children:[V.check,` Installed `,i]})}),o&&m(g,{marginTop:W.tight,children:m(_,{color:d.warning,children:e.t(`setup.installPendingCapabilities`)})}),a.length>0&&h(g,{marginTop:W.tight,flexDirection:`column`,children:[m($,{type:`secondary`,children:e.t(`setup.capabilityGranted`,{caps:a.join(`, `)})}),m($,{type:`secondary`,children:e.t(`setup.capabilityRevokeHint`)})]})]});if(s)return h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:e.t(`setup.installFailedRecovery`,{provider:s})})}),h(Y.Root,{id:`wizard-install-failed`,onPick:e=>{e===0?c():l()},children:[m(Y.Item,{label:e.t(`setup.actionRetryInstall`)}),m(Y.Item,{label:e.t(`setup.actionChooseAnotherProvider`)})]})]});if(b){let e=Gr(r);return m(g,{flexDirection:`column`,children:Ur.map((t,r)=>{let i=e>=0&&r<e,a=r===e||e<0&&r===0,o=i?Wr.done:a?Wr.active:Wr.pending,s=i?d.success:a?d.accent:d.inactive;return h(g,{children:[h(_,{color:s,children:[o,` `]}),h(_,{color:a?d.text:s,children:[t,` `,n]}),a?m(Xr,{}):null]},t)})})}return m(Y.Root,{id:`wizard-dialog-2`,onPick:e=>{!b&&y[e]&&u(y[e].value)},activeIndex:p,onActiveChange:v,children:y.map(e=>m(Y.Item,{label:e.label,detail:e.detail,color:d.selection},e.value))})}function Qr({request:t,authMode:n,setAuthMode:r,oauthUrl:i,oauthCode:a,oauthInstructions:o,apiKey:s,apiKeyRef:c,setApiKey:l,onOAuthStart:u,onApiKeySubmit:d,onOpenAgain:v,onSwitchToApiKey:y,onRetryAuth:b,onOpenProxySettings:x,authFailure:S,selectedProvider:C}){let w=K(),[T,E]=f(0),D=n,O=t.providerAuthOptions(C);if(J(`wizard-dialog-3`,(e,n)=>{if(D===`key-input`){if(n.return&&c.current.trim()){d();return}if(n.escape){r(`select`);return}if(e&&e.length>0){l(c.current+e);return}if(n.backspace||n.delete){l(c.current.slice(0,-1));return}return}if(D!==`select`)return;if((n.upArrow||n.downArrow)&&E(e=>(e+1)%Math.max(O.length,1)),n.return&&O[T]){let e=O[T];e.value===`oauth`&&t.onProviderOAuthStart?u():e.value===`key`&&(l(``),r(`key-input`))}let i=e?Number(e):NaN;if(Number.isInteger(i)&&i>=1&&i<=O.length){let e=O[i-1];e.value===`oauth`&&t.onProviderOAuthStart?u():e.value===`key`&&(l(``),r(`key-input`))}}),S){let t=S===`network`;return h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m(_,{color:w.error,children:e.t(t?`setup.authFailedNetwork`:`setup.authFailedRejected`)})}),h(Y.Root,{id:`wizard-auth-failed`,onPick:e=>{if(t&&e===0){x();return}(t?e-1:e)===0?b():y()},children:[t?m(Y.Item,{label:e.t(`setup.actionOpenProxySettings`)}):null,m(Y.Item,{label:e.t(`setup.actionRetryAuth`)}),m(Y.Item,{label:e.t(`setup.actionUseApiKeyInstead`)})]})]})}return t.onProviderOAuthStart&&n===`oauth-wait`?h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m(_,{children:a?`Complete device authorization`:`Sign in via OAuth`})}),a?h(p,{children:[m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`1. Open this page:`})}),i&&m(g,{marginBottom:W.tight,children:h($,{type:`secondary`,children:[` `,i]})}),m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`2. Enter this code:`})}),m(g,{marginBottom:W.tight,children:h(_,{bold:!0,color:w.text,children:[` `,a]})}),o&&m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:o})})]}):h(p,{children:[m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`Open this URL in your browser to authorize:`})}),i&&m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:i})})]}),m(g,{marginBottom:W.tight,children:m(_,{color:w.text,children:e.t(`setup.oauthWaiting`)})}),h(Y.Root,{id:`wizard-oauth-wait`,onPick:e=>{e===0?v():y()},children:[m(Y.Item,{label:e.t(`setup.actionOpenAgain`)}),m(Y.Item,{label:e.t(`setup.actionUseApiKeyInstead`)})]})]}):n===`key-input`?h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m(_,{children:`Paste your API key`})}),m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`Generate a key on your provider dashboard and paste it below.`})}),m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:e.t(`setup.apiKeyStorageNote`)})}),m(g,{marginBottom:W.tight,children:m(tn,{value:s,offset:0,columns:60,mode:`dialog`,mask:!0,placeholder:e.t(`setup.wizardApiKeyPlaceholder`),focused:!0})})]}):n===`logging-in`?m(g,{flexDirection:`column`,children:m(_,{color:w.text,children:e.t(`setup.loggingIn`)})}):h(g,{flexDirection:`column`,children:[C&&m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:C})}),m(g,{flexDirection:`column`,children:O.map((e,t)=>h(g,{marginBottom:W.tight,flexDirection:`column`,children:[h(_,{color:t===T?w.selection:w.inactive,bold:t===T,children:[t===T?V.pointer:` `,` `,e.label]}),e.detail&&m(g,{marginLeft:W.section,children:m($,{type:`secondary`,children:e.detail})})]},e.value))})]})}function $r({request:t,onModel:n}){let r=t=>t===`unauthenticated`?e.t(`setup.modelUnusableUnauthenticated`):t===`oauth-429-risk`?e.t(`setup.modelUnusableOauthRisk`):``;return h(g,{flexDirection:`column`,children:[t.modelOptions.some(e=>e.recommended)&&m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:e.t(`setup.modelRecommendedHint`)})}),m(xr.Root,{maxVisible:8,frame:!1,onValueChange:e=>{n(e)},children:t.modelOptions.map(t=>{let n=r(t.unusableReason),i=[t.recommended?e.t(`setup.modelRecommendedTag`):``,n,t.detail??``].filter(Boolean).join(` · `);return m(xr.Item,{value:t.value,detail:i||void 0,children:t.label},t.value)})})]})}function ei({request:e,onComplete:t}){let n=K();return J(`wizard-dialog-4`,(e,n)=>{n.return&&t()}),h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`Try asking something like:`})}),m(g,{flexDirection:`column`,marginBottom:W.tight,children:e.examplePrompts.map((e,t)=>h($,{type:`secondary`,children:[` "`,e,`"`]},t))}),m(_,{color:n.text,children:`Press Enter to start chatting`})]})}export{nn as $,ue as $t,zn as A,We as At,Sn as B,je as Bt,Hn as C,J as Ct,In as D,it as Dt,Rn as E,at as Et,kn as F,Pe as Ft,hn as G,Se as Gt,Cn as H,De as Ht,An as I,Ne as It,ln as J,be as Jt,gn as K,K as Kt,On as L,Me as Lt,Nn as M,Ue as Mt,Mn as N,Le as Nt,Fn as O,et as Ot,$ as P,Fe as Pt,an as Q,W as Qt,En as R,q as Rt,Wn as S,ot as St,Bn as T,tt as Tt,xn as U,Te as Ut,wn as V,Ae as Vt,yn as W,we as Wt,cn as X,_e as Xt,un as Y,ge as Yt,rn as Z,G as Zt,Yn as _,Ke as _t,Ar as a,oe as an,jt as at,qn as b,qe as bt,wr as c,ne as cn,Nt as ct,dr as d,C as dn,Z as dt,ce as en,tn as et,ir as f,w as fn,xt as ft,Zn as g,Y as gt,nr as h,mt as ht,jr as i,R as in,Et as it,Pn as j,Be as jt,Ln as k,Ve as kt,Sr as l,B as ln,X as lt,tr as m,x as mn,vt as mt,Hr as n,V as nn,Pt as nt,Dr as o,ae as on,Ot as ot,rr as p,T as pn,_t as pt,fn as q,Ce as qt,Pr as r,H as rn,Dt as rt,Cr as s,se as sn,Mt as st,Jr as t,le as tn,Ut as tt,xr as u,S as un,wt as ut,Jn as v,Ze as vt,Vn as w,Qe as wt,Kn as x,Je as xt,Xn as y,Ye as yt,Tn as z,ke as zt};
|
|
10
|
-
//# sourceMappingURL=WizardDialog-
|
|
9
|
+
`){i.push(a),a=``,o=0,l+=u.segment.length;continue}o+d>t&&a.length>0&&(i.push(a),a=``,o=0),a+=u.segment,o+=d,l+=u.segment.length}return n>=l&&(s=i.length,c=a.length),i.push(a),{lines:i,cursorLine:s,cursorCharInLine:c}}function Yt(e){X.lastIndex=0;let t=[],n=0,r;for(;(r=X.exec(e))!==null;){r.index>n&&t.push({chunk:e.slice(n,r.index),isChip:!1});let i=r[0],a=_t(i);t.push({chunk:i,isChip:!0,kind:a,pasteId:a===`paste`?vt(i):void 0}),n=r.index+i.length}return n<e.length&&t.push({chunk:e.slice(n),isChip:!1}),t}function Xt(e,t){switch(e){case`file`:return t.suggestion;case`agent`:return t.accent;case`skill`:case`mcp`:case`plugin`:return t.special;case`person`:return t.success;case`paste`:return t.inactive;default:return}}function Zt(e,t){return e.kind===`paste`&&e.pasteId!==void 0&&(t?.has(e.pasteId)??!1)}function Qt(e,t){X.lastIndex=0;let n;for(;(n=X.exec(e))!==null;)if(t>n.index&&t<n.index+n[0].length){let e=_t(n[0]);return{kind:e,pasteId:e===`paste`?vt(n[0]):void 0}}}function $t(e,t){let n=xt(e,t);if(!n)return;let r=_t(n.text);return{text:n.text,kind:r,pasteId:r===`paste`?vt(n.text):void 0}}function en(e){return`•`.repeat(e.length)}const tn=i.memo(function({value:t,offset:n,columns:r,mode:a=`send`,placeholder:o=``,maxVisibleLines:s=10,focused:c,tabIndex:l=-1,mask:u=!1,noPrefix:d=!1,ghostSuffix:f,invalidPasteIds:p,containerRef:v,physicalCursor:y=!1,deleteKeyAt:b=0}){let x=K(),{focused:S}=Ue({tabIndex:l,disabled:l<0}),C=c??S,w=d?``:a===`dialog`&&!u?`> `:Kt[a],T=mt(w),E=w,D=Math.max(20,r-T),O=C,{lines:k,cursorLine:A,cursorCharInLine:j}=i.useMemo(()=>Jt(t,D,n),[t,D,n]),M=i.useRef(null),ee=i.useCallback(e=>{M.current=e,typeof v==`function`?v(e):v&&(v.current=e)},[v]),N=Gt(k.length,A,s),P=N.startLine>0?1:0,F={column:T+mt((k[A]??``).slice(0,j)),lineOffset:P+N.cursorLineInWindow};if(Ut({active:y&&C,containerRef:M,text:t,inline:F,deleteKeyAt:b}),t.length===0&&o)return h(g,{ref:ee,flexDirection:`row`,children:[m(_,{color:C?qt(a,x):x.inactive,children:E}),C&&m(_,{inverse:O,children:` `}),m(_,{dimColor:!0,children:o})]});let I=k.length,{startLine:L,visibleRows:te}=Gt(I,A,s),R=L+te,z=k.slice(L,R);return h(g,{ref:ee,flexDirection:`column`,children:[L>0&&m(_,{dimColor:!0,children:` … ${L} ${e.t(`scroll.viewportLinesAbove`)}`}),z.map((e,t)=>{let n=L+t,r=n===A,i=u?en(e):e;if(!r||!C){let r=u?[{chunk:i,isChip:!1}]:Yt(i);return h(g,{flexDirection:`row`,children:[n===0&&E?m(_,{color:C?qt(a,x):x.inactive,children:E}):T>0&&m(_,{dimColor:!0,children:` `.repeat(T)}),r.length===0?m(_,{children:` `}):r.map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},t)})]},`${t}-${e.slice(0,10)}`)}let o=Math.max(0,Math.min(j,i.length)),s=!u&&o<i.length?$t(i,o):void 0;if(s){let r=i.slice(0,o),c=i.slice(o+s.text.length),l=s.kind===`paste`&&s.pasteId!==void 0&&(p?.has(s.pasteId)??!1);return h(g,{flexDirection:`row`,children:[n===0&&E?m(_,{color:C?qt(a,x):x.inactive,children:E}):T>0&&m(_,{dimColor:!0,children:` `.repeat(T)}),Yt(r).map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},`b-${t}`)}),m(_,{inverse:!0,color:l?x.error:void 0,strikethrough:l,children:s.text}),Yt(c).map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},`a-${t}`)}),f?m(_,{dimColor:!0,children:f}):null]},`${t}-${e.slice(0,10)}`)}let c=i.slice(0,o),l=i.slice(o),d=l.length>0?[...l][0]??` `:` `,v=l.length>0?l.slice(d.length):``,y=!u&&l.length>0?Qt(i,o):void 0,b=y?.kind===`paste`&&y.pasteId!==void 0&&(p?.has(y.pasteId)??!1);return h(g,{flexDirection:`row`,children:[n===0&&E?m(_,{color:C?qt(a,x):x.inactive,children:E}):T>0&&m(_,{dimColor:!0,children:` `.repeat(T)}),(u?[{chunk:c,isChip:!1}]:Yt(c)).map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},`b-${t}`)}),m(_,{inverse:O,color:b?x.error:y==null?void 0:Xt(y.kind,x),strikethrough:b,children:d}),(u?[{chunk:v,isChip:!1}]:Yt(v)).map((e,t)=>{let n=e.isChip&&Zt(e,p);return m(_,{color:n?x.error:e.isChip?Xt(e.kind,x):void 0,strikethrough:n,children:e.chunk},`a-${t}`)}),f?m(_,{dimColor:!0,children:f}):null]},`${t}-${e.slice(0,10)}`)}),R<I&&m(_,{dimColor:!0,children:` … ${I-R} ${e.t(`scroll.viewportLinesBelow`)}`})]})}),nn=[{commandId:`cycle-permission-mode`,description:`循环切换权限模式`,predicate:{shift:!0,key:`tab`},scopes:`*`},{commandId:`toggle-notifications`,description:`打开/关闭通知中心`,predicate:{ctrl:!0,input:`n`},scopes:`*`},{commandId:`toggle-edited-files`,description:`打开/关闭编辑文件面板`,predicate:{ctrl:!0,input:`v`},scopes:`*`},{commandId:`toggle-subagents`,description:`打开/关闭子代理面板`,predicate:{ctrl:!0,input:`t`},scopes:`*`},{commandId:`toggle-delegates`,description:`打开/关闭委派面板`,predicate:{ctrl:!0,input:`p`},scopes:`*`},{commandId:`toggle-draft-pane`,description:`打开/关闭草稿面板`,predicate:{ctrl:!0,input:`o`},scopes:`*`},{commandId:`toggle-queue-pane`,description:`打开/关闭队列面板`,predicate:{ctrl:!0,input:`q`},scopes:`*`},{commandId:`smart-close`,description:`智能关闭当前最上层面板`,predicate:{ctrl:!0,input:`k`},scopes:`*`},{commandId:`save-draft`,description:`保存当前输入为草稿`,predicate:{ctrl:!0,input:`s`},scopes:[`prompt`]},{commandId:`open-keybinding-panel`,description:`打开快捷键面板:浏览、搜索、重映射、重置快捷键`,predicate:{ctrl:!0,input:`/`},scopes:`*`}];function rn(e){return e.ctrl===void 0&&e.shift===void 0&&e.meta===void 0&&e.input===void 0&&e.key===void 0&&e.upArrow===void 0&&e.downArrow===void 0}function an(e,t,n){let r=n?.[e];return r===void 0?t:r}function on(e,t,n){if(e.ctrl!==void 0&&!!n.ctrl!==e.ctrl||e.shift!==void 0&&!!n.shift!==e.shift||e.meta!==void 0&&!!n.meta!==e.meta||e.input!==void 0&&t!==e.input)return!1;if(e.key!==void 0)switch(e.key){case`tab`:if(!n.tab)return!1;break;case`escape`:if(!n.escape)return!1;break;case`return`:if(!n.return)return!1;break}return!(e.upArrow!==void 0&&n.upArrow!==e.upArrow||e.downArrow!==void 0&&n.downArrow!==e.downArrow)}function sn(e,t){return e===`*`?!0:e.includes(t)}function cn(e,t,n,r,i){for(let a of e){if(!sn(a.scopes,t))continue;let e=an(a.commandId,a.predicate,i);if(!rn(e)&&on(e,n,r))return a.commandId}}const ln=[{commandId:`list-nav-up`,description:`列表选中项上移`,predicate:{upArrow:!0},scopes:`*`},{commandId:`list-nav-up`,description:`列表选中项上移(vim k)`,predicate:{input:`k`,ctrl:!1,meta:!1},scopes:[`editedFiles`,`subagents`,`taskFocus`,`draft`,`queue`,`schedule`,`select`,`questions`]},{commandId:`list-nav-down`,description:`列表选中项下移`,predicate:{downArrow:!0},scopes:`*`},{commandId:`list-nav-down`,description:`列表选中项下移(vim j)`,predicate:{input:`j`,ctrl:!1,meta:!1},scopes:[`editedFiles`,`subagents`,`taskFocus`,`draft`,`queue`,`schedule`,`select`,`questions`]}];function un(e,t,n,r,i){for(let a of ln){if(r!==void 0&&!dn(a.scopes,r))continue;let o=an(a.commandId,a.predicate,i);if(!rn(o)&&on(o,t,n))return a.commandId===e}return!1}function dn(e,t){return e===`*`?!0:e.includes(t)}function fn(e,t,n,r){let i=[...nn,...ln];for(let a of i){if(a.commandId===e)continue;let i=an(a.commandId,a.predicate,r);if(!rn(i)&&sn(a.scopes,n)&&pn(i,t))return{conflictsWith:a.commandId}}return null}function pn(e,t){return e.ctrl===t.ctrl&&e.shift===t.shift&&e.meta===t.meta&&e.input===t.input&&e.key===t.key&&e.upArrow===t.upArrow&&e.downArrow===t.downArrow}function mn(){let e=new Set(nn.map(e=>e.commandId)),t=new Set(ln.map(e=>e.commandId));for(let n of e)if(t.has(n))throw Error(`[keybindings] duplicate commandId '${n}' found across KEY_BINDINGS and CONTROL_BINDINGS`)}mn();function hn(e,t,n){if(!t)return!1;let r=e.get(t);return r?n.tab?!!(r.onTab&&r.onTab(n.shift??!1)):n.escape?!!(r.onEscape&&r.onEscape()):n.return?!!(r.onAction&&r.onAction()):!1:!1}function gn(e,t,n,r,i){if(i.tab){let a=t;if(e.getTabable(n).length===0)return!1;if(a){let t=i.shift?e.prev(a,n):e.next(a,n);t&&r(t)}else if(!i.shift){let t=e.getInitialFocus(n);t&&r(t)}return!0}return!1}let _n=null;function vn(e){_n=e}function yn(){return _n}const bn=a(null);function xn(){let e=c(bn);if(!e)throw Error(`useRouter() must be used inside <Router>`);return e}function Sn(){return c(bn)}function Cn(){let{stack:e}=xn(),t=e[e.length-1];return t?{path:t.path,params:t.params,state:t.state}:{path:`/`,params:{},state:void 0}}function wn(e){let{stack:t}=xn();for(let n=t.length-1;n>=0;n--){let r=t[n];if(r.path===e&&r.state!==void 0)return r.state}}function Tn(e,t){let n=e.split(`/`),r=t.split(`/`);if(n.length!==r.length)return null;let i={};for(let e=0;e<n.length;e++){let t=n[e],a=r[e];if(t.startsWith(`:`))i[t.slice(1)]=a;else if(t!==a)return null}return i}function En({children:e,initialPath:t=`/`}){let n=u(()=>new Be,[]),[r,i]=f(()=>({entries:[{path:t,params:{}}],index:0})),[a,o]=f(null),c=d(null);c.current=a;let p=r.entries[r.index]?.path??t,h=r.entries.slice(0,r.index+1),g=d(h);g.current=h;let _=s(e=>{o(e)},[]),v=s(e=>{setTimeout(()=>{e?.lastFocusId?o(e.lastFocusId):o(n.getInitialFocus(e?.path??`/`))},0)},[n]),y=s(e=>{setTimeout(()=>{o(n.getInitialFocus(e))},0)},[n]),b=s((e,t)=>{if(typeof e==`number`){i(t=>{if(e===0||t.entries.length===0)return t;let n=t.index+e;return n<0||n>=t.entries.length?t:(v(t.entries[n]),{...t,index:n})});return}let r={path:e,params:{},state:t?.state};i(e=>{if(t?.reset)return{entries:[r],index:0};let i=c.current,a=[...e.entries];if(a.length>0&&i){let t=a[e.index];t&&(n.rememberFocus(t.path,i),a[e.index]={...t,lastFocusId:i})}if(t?.replace&&a.length>0)return a[e.index]=r,{entries:a,index:e.index};let o=[...a.slice(0,e.index+1),r];return{entries:o,index:o.length-1}}),y(e)},[y,n,v]),x=s(()=>{b(-1)},[b]),S=s(e=>{i(t=>{if(t.entries.slice(0,t.index+1).some(t=>t.path===e))return t;let r=c.current,i=[...t.entries],a=i[t.index];a&&r&&(n.rememberFocus(a.path,r),i[t.index]={...a,lastFocusId:r});let o=[...i.slice(0,t.index+1),{path:e,params:{}}];return y(e),{entries:o,index:o.length-1}})},[y,n]),C=s(e=>{i(t=>{if(t.entries.length<=1)return t;let n=-1;for(let r=t.index;r>=0;r--)if(t.entries[r].path===e){n=r;break}if(n<=0)return t;let r=[...t.entries.slice(0,n),...t.entries.slice(n+1)],i=n<=t.index?Math.max(0,t.index-1):t.index;return n===t.index&&v(r[i]),{entries:r,index:Math.min(i,r.length-1)}})},[v]),w=s(e=>{o(e)},[]),T=s((e,t)=>hn(n,c.current,t),[n]),E=s((e,t)=>gn(n,c.current,p,o,t)?!0:t.escape&&h.length>1?(x(),!0):!1,[n,p,h.length,x]),D=s((e,t)=>T(e,t)||E(e,t),[T,E]);l(()=>(vn({navigate:b,goBack:x,ensure:S,dismiss:C,get stack(){return g.current},get currentPath(){return g.current[g.current.length-1]?.path??`/`}}),()=>vn(null)),[b,x,S,C]);let O=Qe(),k=d(T);k.current=T;let A=d(E);A.current=E,l(()=>{let e=O.register(`router-intercept`,(e,t)=>k.current(e,t),50),t=O.register(`router-default`,(e,t)=>A.current(e,t),5);return()=>{e(),t()}},[O]),l(()=>{let e=n.getInitialFocus(p);e&&!c.current&&o(e)},[p]);let j=u(()=>({routePath:p,currentPath:p,activeId:a,registry:n,onFocusFallback:_,hasRouter:!0}),[p,a,n,_]),M=u(()=>({stack:h,currentPath:p,activeId:a,navigate:b,goBack:x,ensure:S,dismiss:C,focus:w,handleKey:D}),[h,p,a,b,x,S,C,w,D]);return m(bn.Provider,{value:M,children:m(Ve.Provider,{value:j,children:e})})}function Dn(e,t){return t===e||t.startsWith(e+`/`)}function On({path:e,prefix:t,inStack:n,element:r,children:i}){let{currentPath:a,stack:o,activeId:s}=xn(),l=c(Ve),u=e=>l?h(Ve.Provider,{value:{...l,routePath:e,activeId:s},children:[r,i]}):h(p,{children:[r,i]});return e===`*`?u(a):n?o.some(t=>t.path===e)?u(e):null:t?Dn(e,a)?u(e):null:Tn(e,a)?u(e):null}function kn({hasMore:t,count:n,indent:r=` `}){let i=K();return t?h(_,{color:i.inactive,dimColor:!0,children:[r,n===void 0?`▲ ${e.t(`common.more`)}`:e.t(`scroll.above`,{n})]}):null}function An({hasMore:t,count:n,indent:r=` `}){let i=K();return t?h(_,{color:i.inactive,dimColor:!0,children:[r,n===void 0?`▼ ${e.t(`common.more`)}`:e.t(`scroll.below`,{n})]}):null}function jn(e,t){switch(e){case`primary`:return t.text;case`secondary`:return t.inactive;case`danger`:return t.error;case`success`:return t.success;case`warning`:return t.warning;case`accent`:return t.accent}}function $({children:e,type:t=`primary`,bold:n,italic:r,dim:i,wrap:a}){return m(_,{color:jn(t,K()),bold:n,italic:r,dimColor:i,wrap:a,children:e})}function Mn(e){return e.leftArrow?-1:e.rightArrow?1:e.tab?e.shift?-1:1:0}function Nn(e,t,n){return n<=0?0:(e+t+n)%n}function Pn({children:e,type:t=`secondary`,leadingSpace:n=!1}){let r=K();return h(_,{children:[n?` `:``,h(_,{color:jn(t,r),backgroundColor:r.tagBg,children:[` `,`[`,e,`]`,` `]})]})}function Fn(e,t,n=0){return Math.max(3,e-t-3-2-Math.max(0,n))}function In(e){return Math.max(14,Math.floor((Number.isFinite(e)&&e>0?e:24)*.3333333333333333))}function Ln(e,t){let n=Number.isFinite(e)&&e>0?e:0;return Math.min(In(t),Math.max(15,n))}function Rn(e){return Math.max(14,Math.floor((Number.isFinite(e)&&e>0?e:24)/3))}function zn(e,t,n=0){let r=Math.min(Number.isFinite(e)&&e>0?Math.floor(e):0,5),i=Math.max(1,In(t)-n);return Math.min(r,i)}function Bn(e,t){let n=R(V.ellipsis);if(t<=1)return V.ellipsis;if(R(e)<=t)return e;let r=t-n,i=``;for(let t of e){let e=R(t);if(e>r)break;i+=t,r-=e}return`${i}${V.ellipsis}`}function Vn(e,t){let n=R(e);return n<=0||t<=0?``:e.repeat(Math.max(0,Math.floor(t/n)))}function Hn(e,t){let n=R(e);return n>=t?e:e+` `.repeat(t-n)}function Un(e){return Number.isFinite(e)?Math.max(0,Math.min(100,e)):0}function Wn(e){let t=Math.round(Un(e.percent)),n=Math.max(0,Math.floor(e.width));if(n===0)return{pct:t,filledCount:0,cells:[]};let r=e.segments?.filter(e=>e.width>0)??[],i=r.length>0,a,o;if(i){a=[];for(let e of r)for(let t=0;t<e.width;t++)a.push({filled:!0,segmentKey:e.key});for(o=a.length;a.length<n;)a.push({filled:!1})}else o=Math.max(0,Math.min(n,Math.round(t/100*n))),a=Array.from({length:n},(e,t)=>({filled:t<o}));if(e.markers)for(let[t,r]of Object.entries(e.markers)){if(!Number.isFinite(r))continue;let e=Math.max(0,Math.min(n-1,Math.round(r/100*n))),i=a[e];i&&(i.markerKey=t)}return{pct:t,filledCount:o,cells:a}}const Gn={ascii:{filled:`=`,empty:`.`},block:{filled:`█`,empty:`░`},dot:{filled:`▰`,empty:`▱`}};function Kn(e){return e?typeof e==`string`?Gn[e]:e:Gn.block}function qn({label:e,indent:t=` `}){let n=K(),r=typeof e==`string`?e:String(e??``);return h(_,{color:n.inactive,bold:!0,children:[t,r.toUpperCase()]})}function Jn(e,t,n,r){let i=e.length;if(!Number.isFinite(n))return{rows:[...e],fillerCount:0,hasMoreAbove:!1,hasMoreBelow:!1,scrollTop:0};if(n<=0||i===0)return{rows:[],fillerCount:Math.max(0,n),hasMoreAbove:!1,hasMoreBelow:!1,scrollTop:0};let a=t>=0?t:0,o=r;a<o?o=a:a>=o+n&&(o=a-n+1);let s=Math.max(0,i-n);o=Math.min(Math.max(0,o),s);let c=Math.min(i,o+n),l=e.slice(o,c);return{rows:l,fillerCount:Math.max(0,n-l.length),hasMoreAbove:o>0,hasMoreBelow:c<i,scrollTop:o}}function Yn(e,t=`below`){let n=[],r,i=0;return e.forEach((e,a)=>{e.group&&e.group!==r&&(i>0&&n.push({kind:`spacer`}),n.push({kind:`divider`,label:e.group}),i++),r=e.group,n.push({kind:`item`,option:e,optionIndex:a}),e.detail&&t===`below`&&n.push({kind:`detail`,option:e,optionIndex:a})}),n}function Xn(e,t,n,r){return Jn(e,e.findIndex(e=>e.kind===`item`&&e.optionIndex===t),n,r)}function Zn(){let e=process.env.OTTO_TUI_REDUCED_MOTION;return e===`1`||e===`true`}function Qn(e){return Math.max(1,Math.round(e/80))*80}const $n={now:()=>Date.now(),setTimer:(e,t)=>{let n=setTimeout(e,t);return n.unref?.(),n},clearTimer:e=>clearTimeout(e)};function er(e={}){let t=e.clock??$n,n=e.reducedMotion??(()=>{let e=process.env.OTTO_TUI_REDUCED_MOTION;return e===`1`||e===`true`}),r=new Set,i=null,a=t.now(),o=e=>e.startedAtElapsed+(e.lastFrame+1)*e.periodMs,s=()=>{if(i!==null&&(t.clearTimer(i),i=null),r.size===0)return;let e=t.now()-a,n=1/0;for(let e of r){let t=o(e);t<n&&(n=t)}let s=Math.max(0,n-e);i=t.setTimer(c,s)},c=()=>{i=null;let e=t.now()-a;for(let t of r){let n=Math.floor((e-t.startedAtElapsed)/t.periodMs);if(n!==t.lastFrame){t.lastFrame=n;try{t.onFrame(n)}catch{}}}s()};return{subscribe(e,i){if(!Number.isFinite(e)||e<=0||n())return()=>{};let o=Qn(e),c=t.now()-a,l={periodMs:o,onFrame:i,lastFrame:0,startedAtElapsed:Math.floor(c/80)*80};return r.add(l),s(),()=>{r.delete(l),s()}},minPeriodMs(){let e;for(let t of r)e=e===void 0?t.periodMs:Math.min(e,t.periodMs);return e},size:()=>r.size,dispose(){r.clear(),i!==null&&(t.clearTimer(i),i=null)}}}const tr=er();function nr(e,t){let n=d(t);n.current=t,l(()=>{if(e!=null)return tr.subscribe(e,e=>n.current(e))},[e])}function rr(e,t={}){let n=t.maxVisible??10,r=e.findIndex(e=>!e.disabled);r<0&&(r=0);let i=0;function a(){r<i?i=r:r>=i+n&&(i=r-n+1);let t=Math.max(0,e.length-n);i<0&&(i=0),i>t&&(i=t)}function o(n){if(n<0){t.onBoundary?.(`top`);return}if(n>=e.length){t.onBoundary?.(`bottom`);return}let i=n>r?1:-1,o=n;for(;o>=0&&o<e.length&&e[o]?.disabled;)o+=i;if(o<0){t.onBoundary?.(`top`);return}if(o>=e.length){t.onBoundary?.(`bottom`);return}r=o,a(),o===0&&t.onBoundary?.(`top`),o===e.length-1&&t.onBoundary?.(`bottom`)}return a(),{get selectedIndex(){return r},get scrollOffset(){return i},getVisibleOptions(){return e.slice(i,i+n)},getOptionAt(t){return e[t]},hasMoreAbove(){return i>0},hasMoreBelow(){return i+n<e.length},getSelected(){return e[r]??null},moveUp(){o(r-1)},moveDown(){o(r+1)},accept(){return e[r]??null},selectByHotkey(t){let n=e.findIndex(e=>e.hotkey===t);return n>=0&&!e[n]?.disabled?(r=n,a(),e[n]):null},selectByIndex(t){t>=0&&t<e.length&&!e[t]?.disabled&&(r=t,a())}}}function ir(e,t){return t.escape?{type:`cancel`}:t.return?{type:`accept`}:un(`list-nav-up`,e,t)?{type:`up`}:un(`list-nav-down`,e,t)?{type:`down`}:/^[1-9]$/.test(e)?{type:`index`,index:Number(e)-1}:null}const ar={black:0,red:.3,green:.55,yellow:.93,blue:.2,magenta:.4,cyan:.7,white:1,gray:.5,grey:.5};function or(e){if(e.startsWith(`#`)){let t=e.slice(1),[n,r,i]=(t.length===3?[t[0]+t[0],t[1]+t[1],t[2]+t[2]]:[t.slice(0,2),t.slice(2,4),t.slice(4,6)]).map(e=>parseInt(e,16)/255);return .299*n+.587*r+.114*i}return ar[e.toLowerCase()]??.5}function sr(e){return e&&or(e)>.55?`black`:`white`}function cr(e,t){switch(e){case`accent`:return t.selection;case`amber`:return t.warning;case`red`:return t.error;case`green`:return t.success;case`gray`:return t.panelBorder}}function lr(e,t){return cr(e,t)}function ur(e,t=w){let{label:n,variant:r=`ghost`,color:i=`accent`,focused:a=!1,disabled:o=!1}=e,s=e.brackets??r===`outline`,c=`[ ${n} ]`;if(o)return{label:c,color:t.inactive,bold:!1,dim:!0};if(r===`ghost`){let e=` ${n} `;if(a){let n=cr(i,t);return{label:s?c:e,color:sr(n),backgroundColor:n,bold:!0,dim:!1}}return{label:s?c:e,color:t.inactive,bold:!1,dim:!1}}let l=cr(i,t),u=lr(i,t);if(r===`solid`){let e=` ${n} `;return a?{label:s?c:e,color:sr(l),backgroundColor:l,bold:!0,dim:!1}:{label:s?c:e,color:s?t.inactive:u,bold:!1,dim:!1}}return a?{label:s?c:` ${n} `,color:u,bold:!0,dim:!1}:{label:s?c:` ${n} `,color:t.inactive,bold:!1,dim:!1}}function dr({label:e,variant:t=`ghost`,color:n=`accent`,focused:r,disabled:i=!1,brackets:a,tabIndex:o=-1,onAction:s}){let c=K(),{focused:l}=Ue({tabIndex:o,disabled:i||o<0,onAction:s}),u=ur({label:e,variant:t,color:n,focused:r??l,disabled:i,brackets:a},c);return m(_,{color:u.color,backgroundColor:u.backgroundColor,bold:u.bold,dimColor:u.dim||void 0,children:u.label})}function fr(e){return null}fr.displayName=`Select.Item`;function pr(e){return null}pr.displayName=`Select.Label`;function mr(e){return null}mr.displayName=`Select.Group`;function hr(){return null}hr.displayName=`Select.Separator`;function gr({children:e}){return m(p,{children:e})}gr.displayName=`Select.Content`;function _r(e){return null}_r.displayName=`Select.Trigger`;function vr(e){if(typeof e==`string`||typeof e==`number`)return String(e);if(Array.isArray(e))return e.map(vr).join(``);if(i.isValidElement(e)){let t=e.props;return vr(t.children)}return``}function yr(e){let t=[],n=0;function r(e,a){i.Children.forEach(e,e=>{if(!i.isValidElement(e))return;let o=e.type;if(o.displayName===`Select.Item`){let r=e.props;n+=1,t.push({value:r.value,label:vr(r.children),disabled:r.disabled,detail:r.detail,indent:r.indent,marker:r.marker,ordinal:n,trailingLabel:r.trailingLabel,trailingColor:r.trailingColor,labelColor:r.labelColor,group:a});return}if(o.displayName===`Select.Group`){let t=e.props,n;i.Children.forEach(t.children,e=>{i.isValidElement(e)&&e.type.displayName===`Select.Label`&&(n=vr(e.props.children))}),r(t.children,n);return}if(o.displayName===`Select.Label`||o.displayName===`Select.Separator`||o.displayName===`Select.Trigger`)return;let s=e.props;s.children!==void 0&&r(s.children,a)})}return r(e,void 0),t}function br({title:t,subtitle:n,headerAction:r,defaultValue:i,onValueChange:a,onCancel:o,maxVisible:s=10,footer:c,active:l=!0,onKey:v,frame:y=!0,highlightSelection:b=!0,rows:x=24,extensionHeightBudget:S=!1,detailPlacement:C=`below`,children:w}){let T=K(),E=u(()=>yr(w),[w]),D=u(()=>C===`inline`?Math.max(0,...E.map(e=>R(e.label))):0,[C,E]),O=u(()=>C===`inline`?Math.max(0,...E.map(e=>R(e.trailingLabel??``))):0,[C,E]),k=d(null);if(!k.current){let e=i?E.findIndex(e=>e.value===i):-1;k.current=rr(E,{maxVisible:s}),e>=0&&k.current.selectByIndex(e)}let A=k.current,[j,M]=f(!1);nr(2e3,e=>M(e%2==1));let[,ee]=f(0),N=()=>ee(e=>e+1),[P,F]=f(()=>!!r&&!E.some(e=>!e.disabled));J(`select-primitive`,(e,t)=>{if(v?.(e,t,A.getSelected())){N();return}if(r&&P){if(t.return){r.onPress();return}if(t.downArrow){F(!1),N();return}if(t.escape){o?.();return}return}let n=ir(e,t);if(n)switch(n.type){case`cancel`:o?.();return;case`up`:{let e=A.selectedIndex;A.moveUp(),r&&A.selectedIndex===e&&F(!0),N();return}case`down`:A.moveDown(),N();return;case`index`:{A.selectByIndex(n.index);let e=A.getSelected();e&&!e.disabled&&a?.(e.value);return}case`accept`:{let e=A.accept();e&&!e.disabled&&a?.(e.value);return}}},{isActive:l});let I=u(()=>Yn(E,C),[E,C]),L=d(0),te=y?S?Math.max(1,Math.min(I.length,Rn(x)-9)):Ln(I.length+9,x)-9:1/0,z=Xn(I,A.selectedIndex,te,L.current);L.current=z.scrollTop;let ne=E[A.selectedIndex]??null,B=h(p,{children:[t&&m(Ne,{children:t}),t&&m(g,{marginTop:W.tight}),n&&m($,{type:`secondary`,children:n}),r&&h(g,{flexDirection:`row`,alignSelf:`flex-start`,marginTop:n?W.tight:W.none,...ue,borderColor:T.accent,paddingX:W.tight,children:[h(_,{color:T.accent,children:[r.hint,` `]}),m(dr,{variant:`ghost`,brackets:!0,color:`accent`,label:r.label,focused:P,tabIndex:-1})]})]}),re=h(p,{children:[m(g,{height:1,children:m(kn,{hasMore:z.hasMoreAbove})}),z.rows.map((t,n)=>{if(t.kind===`spacer`)return m(_,{children:` `},`spacer-${n}`);if(t.kind===`divider`)return m(g,{flexDirection:`column`,children:m(qn,{label:t.label,indent:``})},`div-${n}`);let r=t.option;if(t.kind===`detail`){let e=r.indent??` `,n=r.detail??``,i=r.marker===`number`?` `.repeat(`${r.ordinal}. `.length):r.marker?` `.repeat(`${r.marker} `.length):``,a=/^● (.+?) · /u.exec(n),o=a?.[1],s=a?n.slice(a[0].length):n;return h(_,{wrap:`truncate-end`,children:[h($,{type:`secondary`,dim:!0,children:[` `,e,i]}),o?h(_,{color:T.accent,children:[j?V.breatheBright:V.breatheDim,` `,o]}):null,m($,{type:`secondary`,dim:!0,children:o?` · ${s}`:s})]},`detail-${t.optionIndex}`)}let i=r.indent??` `,a=r.marker===`number`?`${r.ordinal}. `:r.marker?`${r.marker} `:``,o=b&&r===ne&&!P,s=C===`inline`&&r.detail;return h(g,{flexDirection:`row`,children:[h(_,{color:r.disabled?T.inactive:o?T.selection:r.labelColor??T.inactive,dimColor:r.disabled,bold:o&&!r.disabled,children:[o&&!r.disabled?`${V.pointer} `:` `,i,a,s?`${Hn(r.label,D)} ${Hn(r.trailingLabel??``,O)} ${r.detail}`:r.label,r.disabled?` (${e.t(`common.disabled`)})`:``]}),r.trailingLabel&&!s&&h(p,{children:[m($,{type:`secondary`,children:` `}),m(_,{color:r.trailingColor??T.inactive,dimColor:!r.trailingColor,children:r.trailingLabel})]})]},`item-${t.optionIndex}`)}),Array.from({length:z.fillerCount},(e,t)=>m(_,{children:` `},`filler-${t}`)),m(g,{height:1,children:m(An,{hasMore:z.hasMoreBelow})})]});return y?m(Me,{header:B,footer:c??m(Fe,{items:[[`${q.up}${q.down}`,e.t(`hint.select`)],[q.enter,e.t(`hint.confirm`)],[q.esc,e.t(`hint.cancel`)]]}),maxHeight:S&&y?Rn(x):void 0,children:re}):h(g,{flexDirection:`column`,children:[B,re]})}const xr={Root:br,Trigger:_r,Content:gr,Group:mr,Label:pr,Item:fr,Separator:hr};function Sr({title:t,message:n,confirmLabel:r,cancelLabel:i,confirmColor:a=`accent`,dangerous:o=!1,extraLabel:c,extraColor:l=`amber`,checkLabel:u,checked:d=!1,onConfirm:p,onCancel:v,onExtra:y,onCheckChange:b}){let x=!!c,S=x?2:1,[C,w]=f(o?S:0),[T,E]=f(d),D=Array.isArray(n)?n:[n],O=s(()=>{let e=!T;E(e),b?.(e)},[T,b]);Ue({onEscape:()=>(v(),!0)}),J(`confirm-dialog-buttons`,(e,t)=>{if(t.escape)return v(),!0;let n=Mn(t);return n===0?t.return?(w(e=>(e===0?p():x&&e===1?y?.():v(),e)),!0):u&&e===` `&&!t.ctrl&&!t.meta?(O(),!0):!1:(w(e=>Nn(e,n,S+1)),!0)});let k=r??e.t(`common.confirmButton`),A=i??e.t(`common.genericCancelButton`);return h(Me,{header:m(Ne,{children:t}),footer:m(Fe,{items:[[`${q.left}${q.right}`,e.t(`hint.switch`)],[q.enter,e.t(`hint.confirm`)],[q.esc,e.t(`hint.cancel`)]]}),children:[m(g,{marginTop:W.tight,flexDirection:`column`,children:D.map((e,t)=>m(_,{wrap:`truncate-end`,children:e===``?` `:e},t))}),u&&h(g,{marginTop:W.tight,children:[h($,{type:`secondary`,children:[T?V.bullet:V.todoPending,` `]}),m($,{type:`secondary`,children:u})]}),h(g,{marginTop:W.tight,flexDirection:`row`,gap:W.section,children:[m(dr,{variant:`solid`,brackets:!0,color:a,label:k,focused:C===0}),x&&m(dr,{variant:`solid`,brackets:!0,color:l,label:c,focused:C===1}),m(dr,{variant:`solid`,brackets:!0,color:`gray`,label:A,focused:C===S})]})]})}function Cr({tabIndex:e=0,autoFocus:t=!1,options:n,onSelect:r,initialIndex:i=0,maxVisible:a=8,id:o,compact:s=!1}){let c=K(),{focused:l}=Ue({tabIndex:e,autoFocus:t,id:o}),[u,d]=f(Math.min(i,n.length-1));et(l,(e,t)=>{if(t.upArrow)return d(e=>{let t=e;for(let r=1;r<=n.length;r++){let i=(e-r+n.length)%n.length;if(!n[i]?.disabled){t=i;break}}return t}),!0;if(t.downArrow)return d(e=>{let t=e;for(let r=1;r<=n.length;r++){let i=(e+r)%n.length;if(!n[i]?.disabled){t=i;break}}return t}),!0;if(t.return){let e=n[u];return e&&!e.disabled&&r(e.value),!0}for(let t=0;t<Math.min(n.length,9);t++)if(e===String(t+1)&&n[t]&&!n[t].disabled)return r(n[t].value),!0;return!1});let p=n.length,v=p<=a?0:Math.min(Math.max(0,u-Math.floor(a/2)),p-a),y=n.slice(v,v+a);return h(g,{flexDirection:`column`,children:[v>0&&m(g,{children:h(_,{color:c.inactive,dimColor:!0,children:[` ▲ `,v]})}),y.map((e,t)=>{let n=v+t===u,r=n&&l,i=e.disabled?c.inactive:r||n?c.selection:c.inactive,a=n&&!e.disabled;return h(g,{marginBottom:s?W.none:W.tight,flexDirection:`column`,children:[h(_,{color:i,bold:a,children:[r?`${V.pointer} `:` `,e.label]}),e.detail&&m(g,{marginLeft:W.section,children:m(_,{color:c.inactive,children:e.detail})})]},e.value)}),v+a<p&&m(g,{children:h(_,{color:c.inactive,dimColor:!0,children:[` ▼ `,p-v-a]})})]})}function wr({label:e,detail:t,disabled:n,children:r}){let i=K();return h(g,{flexDirection:`column`,children:[m(_,{color:n?i.inactive:void 0,children:e}),t&&m(_,{color:i.inactive,dimColor:!0,children:t}),r]})}function Tr(e,t){switch(e){case`success`:return t.success;case`warning`:return t.warning;case`error`:return t.error;case`muted`:return t.inactive;case`secondary`:return t.secondary}}function Er(e){let t=[],n=[];for(let r of e)r.kind===`group`?(n.length>0&&t.push(n),n=[r]):n.push(r);return n.length>0&&t.push(n),t}function Dr({entries:e}){let t=K();return m(g,{flexDirection:`column`,children:Er(e).map((e,n)=>{let r=e.filter(e=>e.kind===`row`),i=Math.max(0,...r.map(e=>R(e.label)));return m(g,{flexDirection:`column`,marginTop:n>0?W.tight:W.none,children:e.map((e,n)=>{if(e.kind===`group`)return m(qn,{label:e.title},n);if(e.kind===`blank`)return m(_,{children:` `},n);if(e.kind===`text`)return m(_,{color:e.tone?Tr(e.tone,t):void 0,dimColor:e.tone===`muted`,children:e.value},n);let r=` `.repeat(Math.max(0,i-R(e.label)));return h(_,{children:[` `,m(_,{color:t.inactive,children:e.label}),r,` `,m(_,{color:e.tone?Tr(e.tone,t):void 0,children:e.value})]},n)})},n)})})}function Or(t){switch(t){case`retry`:return e.t(`retry.nowButton`);case`login`:return e.t(`model.goToLoginButton`);case`extension`:return e.t(`model.goToExtensionButton`)}}function kr(e,t){switch(e){case`success`:return t.success;case`muted`:return t.inactive;case`warning`:return t.warning}}function Ar({title:t,lines:n,lineTones:r,onDismiss:i,action:a,dataListEntries:o}){let s=K();J(`info-dialog`,(e,t)=>t.escape?(i(),!0):t.return&&a?(i(),queueMicrotask(()=>a.run()),!0):!1);let c=a?Or(a.kind):void 0;return h(Me,{header:m(Ne,{children:t}),footer:m(Fe,{items:a?[[q.enter,c],[q.esc,e.t(`hint.close`)]]:[[q.esc,e.t(`hint.close`)]]}),children:[m(g,{marginTop:W.tight,flexDirection:`column`,children:o?m(Dr,{entries:o}):n.map((e,t)=>{let n=r?.[t];return m(_,{color:n?kr(n,s):void 0,dimColor:n===`muted`,wrap:`truncate-end`,children:e===``?` `:e},t)})}),a&&m(g,{marginTop:W.tight,children:m(dr,{variant:`solid`,brackets:!0,color:`accent`,label:c,focused:!0})})]})}function jr({percent:e,width:t,chars:n,color:r,segments:i,markers:a,labelPosition:o=`suffix`,labelPrefix:s=``}){let c=K(),{filled:l,empty:u}=Kn(n),d=Wn({percent:e,width:t,segments:i?.map(e=>({key:e.key,width:e.width}))}),f=new Map((i??[]).map(e=>[e.key,e.color])),p=new Map((i??[]).map(e=>[e.key,e.dimColor??!1])),g=new Map(Object.entries(a??{}).map(([e,t])=>[t.pos,{name:e,color:t.color}])),v=(e=>typeof r==`function`?r(e):typeof r==`string`?r:c.inactive)(d.pct),y=`${s}${d.pct}%`;return h(_,{children:[o===`prefix`?h(_,{color:v,bold:!0,children:[y,` `]}):null,d.cells.map((e,t)=>{let n=g.get(t),r=c.inactive;e.filled&&(r=e.segmentKey?f.get(e.segmentKey)??v:v),n&&e.filled&&(r=n.color);let i=e.filled&&e.segmentKey?p.get(e.segmentKey)??!1:!1;return m(_,{color:r,dimColor:i,children:e.filled?l:u},t)}),o===`suffix`?h(_,{children:[` `,y]}):null]})}const Mr={pending:V.todoPending,active:V.todoActive,done:V.check,error:V.cross};function Nr(e,t){let n=[];return e.forEach((e,r)=>{let i=t[r]??`pending`;i!==`pending`&&n.push({label:e,status:i})}),n}function Pr({title:t,phases:n,phaseStatuses:r,percent:a,detail:o,subProgress:s,status:c,errorMessage:u,nextStep:v,onDismiss:y}){let b=K(),x=c===`running`,S=d(null);l(()=>{if(c===`success`)return S.current=setTimeout(y,2e3),()=>{S.current&&clearTimeout(S.current)}},[c,y]);let[C,w]=f(0);return nr(c===`running`?160:null,e=>{w(e%H.length)}),J(`progress-dialog`,(e,t)=>(t.return||t.escape)&&c!==`running`?(y(),!0):!1),m(Me,{header:m(Ne,{children:t}),footer:c===`partial`||c===`error`?m(Fe,{items:[[`${q.enter}/${q.esc}`,e.t(`hint.close`)]]}):void 0,children:h(g,{flexDirection:`column`,paddingX:W.tight,children:[m(g,{height:1}),x?n.map((e,t)=>{let n=r[t]??`pending`,i=n===`active`,a=n===`error`,s=n===`done`,c=b.inactive;return i?c=b.accent:a?c=b.error:s&&(c=b.success),h(g,{children:[h(_,{color:c,children:[Mr[n]??` `,` `]}),m(_,{color:i?b.accent:a?b.error:s?b.success:b.inactive,children:e}),i?h(p,{children:[h(_,{color:b.accent,children:[` `,H[C],` `]}),m($,{type:`secondary`,children:o})]}):null]},t)}):null,!x&&c!==`success`?m(g,{children:Nr(n,r).map((e,t)=>h(i.Fragment,{children:[t>0?m($,{type:`secondary`,children:` · `}):null,h(_,{color:e.status===`error`?b.error:e.status===`done`?b.success:b.accent,children:[Mr[e.status],` `]}),m($,{type:`secondary`,children:e.label})]},t))}):null,s&&c===`running`?m(g,{marginTop:W.tight,children:h(Pn,{children:[s.current,`/`,s.total]})}):null,x?m(g,{marginTop:W.tight,marginBottom:W.tight,children:m(jr,{percent:a,width:40,chars:`ascii`,color:b.accent})}):null,x?null:h(g,{marginTop:c===`success`?W.none:W.tight,flexDirection:`column`,children:[m(g,{children:h(_,{bold:!0,color:c===`success`?b.success:c===`partial`?b.warning:b.error,children:[c===`success`?V.check:c===`partial`?V.warn:V.cross,` `,c===`success`?e.t(`install.done`):c===`partial`?e.t(`install.summaryPartial`):e.t(`install.summaryFailed`)]})}),c!==`success`&&u?m(g,{marginTop:W.tight,children:m($,{type:`secondary`,wrap:`wrap`,children:u})}):null,v?m(g,{marginTop:W.tight,children:m($,{type:`secondary`,children:v.label})}):null]})]})})}function Fr(e){return e.some(e=>e.freeformInput===!0)}function Ir(e){return{tab:0,cursor:0,selected:e.map(()=>[]),freeformText:``,freeformOffset:0}}function Lr(e,t,n=!1){return t.escape?{type:`cancel`}:t.tab?{type:t.shift?`tabPrev`:`tabNext`}:un(`list-nav-up`,e,t)?{type:`cursorPrev`}:un(`list-nav-down`,e,t)?{type:`cursorNext`}:!n&&(e===` `||t.return)?{type:`choose`}:null}function Rr(e,t,n){let r=Fr(n),i=n.length+(r?1:0),a=r?n.length:-1;switch(t?.type){case`cancel`:return{state:e,done:`cancel`};case`tabPrev`:return{state:{...e,tab:(e.tab-1+i+1)%(i+1),cursor:0}};case`tabNext`:return{state:{...e,tab:(e.tab+1)%(i+1),cursor:0}};case`cursorPrev`:return e.tab===i||e.tab===a?{state:e}:{state:{...e,cursor:Math.max(0,e.cursor-1)}};case`cursorNext`:{if(e.tab===i||e.tab===a)return{state:e};let t=n[e.tab].options.length;return{state:{...e,cursor:Math.min(t-1,e.cursor+1)}}}case`choose`:{if(e.tab===i)return{state:e,done:`submit`};if(e.tab===a)return{state:{...e,tab:i}};let t=n[e.tab],r=e.selected[e.tab]??[],o=t.multiSelect?r.includes(e.cursor)?r.filter(t=>t!==e.cursor):[...r,e.cursor]:[e.cursor],s=e.selected.map((t,n)=>n===e.tab?o:t),c=t.multiSelect?e.tab:Math.min(i,e.tab+1);return{state:{...e,selected:s,tab:c,cursor:0}}}default:return{state:e}}}function zr(e,t){let n={};return t.forEach((t,r)=>{n[t.header]=(e.selected[r]??[]).map(e=>t.options[e]?.label).filter(e=>typeof e==`string`)}),n}function Br(e,t){return t.every((t,n)=>(e.selected[n]?.length??0)>0)}function Vr(e){return Bn(e,23)}function Hr({title:t,questions:n,onSubmit:r,onCancel:a,columns:o=60}){let s=K(),c=Fr(n),l=d(null);l.current??=Ir(n);let[,u]=f(0),v=c?n.length:-1,y=n.length+(c?1:0),b=e=>{let t=l.current,i=Lr(``,{tab:!0,shift:e},t.tab===v);if(!i)return!1;let{state:o,done:s}=Rr(t,i,n);return l.current=o,s===`cancel`?(a?.(),!0):s===`submit`?(r(zr(o,n),o.freeformText||void 0),!0):(u(e=>e+1),!0)};Ue({onEscape:()=>(a?.(),!0),onTab:e=>b(e)}),J(`questions-dialog`,(e,t)=>{let i=l.current;if(i.tab===v){if(t.escape&&i.freeformText.length===0){a?.();return}if(t.tab){b(t.shift??!1);return}if(t.leftArrow){let e=wt.fromText(i.freeformText,o,i.freeformOffset).left();l.current={...i,freeformText:e.text,freeformOffset:e.offset},u(e=>e+1);return}if(t.rightArrow){let e=wt.fromText(i.freeformText,o,i.freeformOffset).right();l.current={...i,freeformText:e.text,freeformOffset:e.offset},u(e=>e+1);return}if(e.length>1&&!t.ctrl&&!t.meta&&!t.return&&!t.escape&&!t.backspace&&!t.delete&&!t.leftArrow&&!t.rightArrow){let t=Mt(e);if(t){let e=i.freeformText,n=i.freeformOffset;l.current={...i,freeformText:e.slice(0,n)+t+e.slice(n),freeformOffset:n+t.length},u(e=>e+1)}return}if(t.return){let{state:e,done:t}=Rr(i,Lr(``,{tab:!0},!0),n);if(l.current=e,t===`submit`){r(zr(e,n),e.freeformText||void 0);return}u(e=>e+1);return}let s={name:t.escape?`escape`:t.backspace?`backspace`:t.delete?`delete`:e||`unknown`,ctrl:t.ctrl??!1,shift:!1,alt:t.meta??!1,meta:t.meta??!1},c=jt(wt.fromText(i.freeformText,o,i.freeformOffset),s);if(!c)return;l.current={...i,freeformText:c.cursor.text,freeformOffset:c.cursor.offset},u(e=>e+1);return}let s=Lr(e,t);if(!s)return;let{state:c,done:d}=Rr(i,s,n);if(l.current=c,d===`cancel`){a?.();return}if(d===`submit`){r(zr(c,n),c.freeformText||void 0);return}u(e=>e+1)});let x=l.current,S=x.tab===y,C=x.tab===v?m(Fe,{items:[[q.enter,e.t(`freeform.advance`)],[q.esc,e.t(`hint.cancel`)]]}):m(Fe,{items:[[`${q.up}${q.down}`,e.t(`hint.option`)],[q.tab,e.t(`hint.question`)],S?[q.enter,e.t(`hint.submit`)]:[`space/${q.enter}`,e.t(`hint.choose`)],[q.esc,e.t(`hint.cancel`)]]});return h(Me,{header:t?m(Ne,{children:t}):void 0,footer:C,children:[h(g,{flexDirection:`row`,marginTop:W.tight,children:[n.map((e,t)=>{let n=(x.selected[t]?.length??0)>0,r=x.tab===t,a=r?s.selection:n?s.success:s.inactive;return h(i.Fragment,{children:[t>0&&m($,{type:`secondary`,dim:!0,children:` · `}),m(_,{color:a,bold:r,children:Vr(e.header)})]},t)}),c&&h(p,{children:[m($,{type:`secondary`,dim:!0,children:` · `}),m(_,{color:x.tab===v?s.selection:x.freeformText?s.success:s.inactive,bold:x.tab===v,children:e.t(`freeform.tab`)})]}),m($,{type:`secondary`,dim:!0,children:` · `}),m(_,{color:S?s.selection:s.inactive,bold:S,children:e.t(`prompt.submit`)})]}),S?h(g,{flexDirection:`column`,marginTop:W.tight,children:[m(_,{color:Br(x,n)?s.success:s.warning,children:Br(x,n)?e.t(`questions.readyToSubmit`):e.t(`questions.someUnanswered`)}),m(g,{marginTop:W.tight,children:m(dr,{variant:`solid`,brackets:!0,color:`accent`,label:e.t(`prompt.submit`),focused:!0})})]}):x.tab===v?h(g,{flexDirection:`column`,marginTop:W.tight,children:[m(_,{color:s.secondary,children:e.t(`freeform.label`)}),m(g,{marginTop:W.tight,children:m(tn,{value:x.freeformText,offset:x.freeformOffset,columns:o,mode:`dialog`,placeholder:e.t(`freeform.placeholder`),focused:!0,physicalCursor:!0})})]}):h(g,{flexDirection:`column`,marginTop:W.tight,children:[n[x.tab].question!==t&&m(_,{color:s.text,children:n[x.tab].question}),m(g,{flexDirection:`column`,marginTop:W.tight,children:n[x.tab].options.map((e,t)=>{let n=t===x.cursor,r=(x.selected[x.tab]??[]).includes(t),i=r?V.bullet:V.todoPending;return h(g,{flexDirection:`column`,children:[h(g,{flexDirection:`row`,children:[m(_,{color:n?s.selection:s.inactive,bold:n,children:n?`${V.pointer} `:` `}),m(_,{color:n?s.selection:r?s.success:s.inactive,bold:n,children:i}),m(_,{children:` `}),m(_,{color:n?s.selection:r?s.success:s.inactive,bold:n,children:e.label})]}),e.description&&m(g,{marginLeft:W.loose,children:m($,{type:`secondary`,dim:!0,children:e.description})})]},t)})})]})]})}const Ur=[`Resolving`,`Installing`,`Authorizing`,`Reloading`],Wr={pending:V.todoPending,active:V.todoActive,done:V.check};function Gr(e){return e?Ur.findIndex(t=>e.includes(t)):-1}function Kr(e,t,n,r){return h(g,{flexDirection:`row`,marginBottom:W.tight,children:[n.map((n,a)=>{let o=t.has(a),s=a===e,c=o?V.check:s?V.todoDone:V.todoPending,l=o?r.inactive:s?r.text:r.inactive;return h(i.Fragment,{children:[a>0&&m($,{type:`secondary`,children:` · `}),h(_,{color:l,bold:s,children:[c,` `,n]})]},a)}),h(g,{marginLeft:W.section,children:[m($,{type:`secondary`,children:`Step `}),m(_,{color:r.text,bold:!0,children:e+1}),h($,{type:`secondary`,children:[`/`,4]})]})]})}function qr(){return m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,dim:!0,children:Vn(V.hr,60)})})}function Jr({request:t}){let n=K(),[r,i]=f(!1),[a,o]=f(!1),[c,u]=f(()=>Math.min(t.initialCurrent,3)),[p,v]=f(()=>new Set(t.initialCompleted)),[y,b]=f(null),[x,S]=f(null),[C,w]=f(null),[T,E]=f(null),[D,O]=f(null),[k,A]=f(null),[j,M]=f([]),[ee,N]=f(!1),P=d(null),[F,I]=f(`select`),[L,te]=f(null),[R,z]=f(null),[ne,B]=f(null),[re,ie]=f(``),ae=d(``),[oe,se]=f(t.authProviderName??``),H=s(e=>{ae.current=e,ie(e)},[]),U=d(null),ce=d(!1),le=s(()=>{ce.current=!0,U.current?.cancel(),P.current&&=(clearTimeout(P.current),null),t.onDismiss()},[t]),ue=s(()=>{if(F!==`select`&&c===1){U.current?.cancel(),I(`select`),te(null),z(null),B(null),H(``),ae.current=``,b(null);return}if(D){O(null),b(null);return}c===0?le():(v(e=>{let t=new Set(e);return t.delete(c-1),t}),u(e=>e-1),b(null),I(`select`),te(null),z(null),B(null),H(``),E(null),M([]),N(!1),O(null),P.current&&=(clearTimeout(P.current),null))},[c,le,F,D]);l(()=>()=>{U.current?.cancel(),P.current&&clearTimeout(P.current)},[]);let G=s(()=>{v(e=>new Set([...e,c])),b(null),S(null),E(null),M([]),N(!1),O(null),I(`select`),A(null),te(null),z(null),B(null),H(``),ae.current=``,U.current=null,c>=3?(le(),t.onComplete()):u(e=>e+1)},[c,le,t]),de=d(null),fe=s(async e=>{S(e),w(null),b(null);let n=await t.onInstallProvider(e,e=>{ce.current||w(e)});ce.current||(S(null),w(null),n.ok?(se(n.providerId??e),M(n.capabilities??[]),N(n.pendingCapabilities===!0),E(e),P.current=setTimeout(()=>{P.current=null,G()},900)):(O(e),b(n.error)))},[t,G]);de.current=fe;let pe=s(()=>{let e=D;e&&(O(null),b(null),de.current?.(e))},[D]),me=s(()=>{O(null),b(null)},[]),he=d(null),ge=s(async()=>{if(!t.onProviderOAuthStart)return;b(null),I(`oauth-wait`);let e=await t.onProviderOAuthStart(oe);if(!e){I(`select`),b(`OAuth flow not available for this provider.`);return}U.current=e,te(e.authorizationUrl),z(e.code??null),B(e.instructions??null);let n=async()=>{if(ce.current)return;let t=await e.poll();if(ce.current)return;let r=typeof t==`string`?t:t.status,i=typeof t==`string`?void 0:t.reason;r===`pending`?setTimeout(()=>{n().catch(()=>{})},1500):r===`done`?G():i===`cancelled`?I(`select`):A(i===`network`?`network`:`rejected`)};n().catch(()=>{})},[t,G,oe]),_e=s(()=>{A(null),b(null),he.current?.()},[]),ve=s(()=>{A(null),t.onOpenProxySettings?.()},[t]);he.current=ge;let ye=s(()=>{U.current?.openAgain?.()},[]),be=s(()=>{U.current?.cancel(),U.current=null,te(null),z(null),B(null),b(null),H(``),I(`key-input`)},[H]),xe=s(async()=>{if(!t.onSubmitProviderApiKey||!ae.current.trim())return;b(null),I(`logging-in`);let e=await t.onSubmitProviderApiKey(oe,ae.current.trim());e.ok?G():(I(`key-input`),b(e.error))},[t,G,re,oe]),Se=s(async e=>{b(null);try{await t.onSelectModel(e),G()}catch(e){b(e instanceof Error?e.message:String(e))}},[t,G]),Ce=s(()=>G(),[G]);J(`wizard-dialog`,(e,n)=>r?n.escape?(ue(),!0):!1:n.return?(t.onDontShowAgain(a),i(!0),!0):n.escape?(le(),!0):e===` `?(o(e=>!e),!0):!1);let we=(()=>{if(!r)return[[q.enter,t.welcomeStartLabel],[q.esc,t.welcomeCancelLabel],[`Space`,t.welcomeDontShowAgainLabel]];let n=c===0&&!D?`exit`:`back`;switch(c){case 0:{let r=Math.min(t.providerOptions.length,9);return[[`${q.up}${q.down}`,e.t(`hint.select`)],[`1-${r}`,e.t(`hint.quick`)],[q.enter,e.t(`setup.actionInstall`)],[q.esc,n]]}case 1:return F===`key-input`?[[q.enter,`submit`],[q.esc,n]]:F===`oauth-wait`?[[q.esc,`cancel`]]:[[`1-${Math.min(t.providerAuthOptions(oe).length,9)}`,e.t(`hint.quick`)],[q.enter,e.t(`setup.actionLogin`)],[q.esc,n]];case 2:{let r=Math.min(t.modelOptions.length,9);return[[`${q.up}${q.down}`,e.t(`hint.select`)],[`1-${r}`,e.t(`hint.quick`)],[q.enter,e.t(`hint.confirm`)],[q.esc,n]]}case 3:return[[q.enter,e.t(`hint.confirm`)]];default:return[[q.esc,n]]}})();return m(Me,{header:m(Ne,{children:t.title}),footer:m(Fe,{items:we}),children:r?h(g,{flexDirection:`column`,marginTop:W.tight,paddingX:W.section,children:[Kr(c,p,t.stepNames,n),m(g,{marginBottom:W.tight,flexDirection:`column`,children:m(_,{bold:!0,children:t.stepSubtitles[c]})}),m(qr,{}),y&&h(g,{marginBottom:W.tight,flexDirection:`column`,children:[h(_,{color:n.error,children:[e.t(`setup.errorTitle`),`:`]}),m(_,{color:n.error,children:y})]}),m(Yr,{step:c,request:t,installing:x,installPhase:C,installSucceeded:T,installedCapabilities:j,installPendingCaps:ee,installFailed:D,onRetryInstall:pe,onChooseAnother:me,authMode:F,setAuthMode:I,oauthUrl:L,oauthCode:R,oauthInstructions:ne,apiKey:re,apiKeyRef:ae,setApiKey:H,onInstall:fe,onOAuthStart:ge,onApiKeySubmit:xe,onOpenAgain:ye,onSwitchToApiKey:be,onRetryAuth:_e,onOpenProxySettings:ve,authFailure:k,onModel:Se,onComplete:Ce,selectedProvider:oe})]}):h(g,{flexDirection:`column`,marginTop:W.tight,paddingX:W.section,children:[m(g,{marginBottom:W.tight,children:m(_,{bold:!0,children:t.welcomeTitle})}),t.welcomeGreeting&&m(g,{marginBottom:W.tight,children:m(_,{children:t.welcomeGreeting})}),m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:t.welcomeDescription})}),m(qr,{}),m(g,{marginBottom:W.tight,children:h(_,{color:a?n.text:n.inactive,children:[a?V.bullet:V.todoPending,` `,t.welcomeDontShowAgainLabel]})})]})})}function Yr(e){switch(e.step){case 0:return m(Zr,{request:e.request,installing:e.installing,installPhase:e.installPhase,installSucceeded:e.installSucceeded,installedCapabilities:e.installedCapabilities,installPendingCaps:e.installPendingCaps,installFailed:e.installFailed,onRetryInstall:e.onRetryInstall,onChooseAnother:e.onChooseAnother,onInstall:e.onInstall});case 1:return m(Qr,{request:e.request,authMode:e.authMode,setAuthMode:e.setAuthMode,oauthUrl:e.oauthUrl,oauthCode:e.oauthCode,oauthInstructions:e.oauthInstructions,apiKey:e.apiKey,apiKeyRef:e.apiKeyRef,setApiKey:e.setApiKey,onOAuthStart:e.onOAuthStart,onApiKeySubmit:e.onApiKeySubmit,onOpenAgain:e.onOpenAgain,onSwitchToApiKey:e.onSwitchToApiKey,onRetryAuth:e.onRetryAuth,onOpenProxySettings:e.onOpenProxySettings,authFailure:e.authFailure,selectedProvider:e.selectedProvider});case 2:return m($r,{request:e.request,onModel:e.onModel});case 3:return m(ei,{request:e.request,onComplete:e.onComplete});default:return m(_,{children:`Unknown step`})}}function Xr(){let e=K(),t=Zn(),[n,r]=f(0);return nr(160,e=>r(e%H.length)),t?null:h(_,{color:e.accent,children:[` `,H[n]]})}function Zr({request:t,installing:n,installPhase:r,installSucceeded:i,installedCapabilities:a,installPendingCaps:o,installFailed:s,onRetryInstall:c,onChooseAnother:l,onInstall:u}){let d=K(),[p,v]=f(0),y=t.providerOptions,b=n!==null;if(i)return h(g,{flexDirection:`column`,children:[Ur.map(e=>h(g,{children:[h(_,{color:d.success,children:[Wr.done,` `]}),m(_,{color:d.success,children:e})]},e)),m(g,{marginTop:W.tight,children:h(_,{color:d.success,bold:!0,children:[V.check,` Installed `,i]})}),o&&m(g,{marginTop:W.tight,children:m(_,{color:d.warning,children:e.t(`setup.installPendingCapabilities`)})}),a.length>0&&h(g,{marginTop:W.tight,flexDirection:`column`,children:[m($,{type:`secondary`,children:e.t(`setup.capabilityGranted`,{caps:a.join(`, `)})}),m($,{type:`secondary`,children:e.t(`setup.capabilityRevokeHint`)})]})]});if(s)return h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:e.t(`setup.installFailedRecovery`,{provider:s})})}),h(Y.Root,{id:`wizard-install-failed`,onPick:e=>{e===0?c():l()},children:[m(Y.Item,{label:e.t(`setup.actionRetryInstall`)}),m(Y.Item,{label:e.t(`setup.actionChooseAnotherProvider`)})]})]});if(b){let e=Gr(r);return m(g,{flexDirection:`column`,children:Ur.map((t,r)=>{let i=e>=0&&r<e,a=r===e||e<0&&r===0,o=i?Wr.done:a?Wr.active:Wr.pending,s=i?d.success:a?d.accent:d.inactive;return h(g,{children:[h(_,{color:s,children:[o,` `]}),h(_,{color:a?d.text:s,children:[t,` `,n]}),a?m(Xr,{}):null]},t)})})}return m(Y.Root,{id:`wizard-dialog-2`,onPick:e=>{!b&&y[e]&&u(y[e].value)},activeIndex:p,onActiveChange:v,children:y.map(e=>m(Y.Item,{label:e.label,detail:e.detail,color:d.selection},e.value))})}function Qr({request:t,authMode:n,setAuthMode:r,oauthUrl:i,oauthCode:a,oauthInstructions:o,apiKey:s,apiKeyRef:c,setApiKey:l,onOAuthStart:u,onApiKeySubmit:d,onOpenAgain:v,onSwitchToApiKey:y,onRetryAuth:b,onOpenProxySettings:x,authFailure:S,selectedProvider:C}){let w=K(),[T,E]=f(0),D=n,O=t.providerAuthOptions(C);if(J(`wizard-dialog-3`,(e,n)=>{if(D===`key-input`)return n.return&&c.current.trim()?(d(),!0):n.escape?(r(`select`),!0):e&&e.length>0?(l(c.current+e),!0):((n.backspace||n.delete)&&l(c.current.slice(0,-1)),!0);if(D!==`select`)return!1;if(n.upArrow||n.downArrow)return E(e=>(e+1)%Math.max(O.length,1)),!0;if(n.return&&O[T]){let e=O[T];return e.value===`oauth`&&t.onProviderOAuthStart?u():e.value===`key`&&(l(``),r(`key-input`)),!0}let i=e?Number(e):NaN;if(Number.isInteger(i)&&i>=1&&i<=O.length){let e=O[i-1];return e.value===`oauth`&&t.onProviderOAuthStart?u():e.value===`key`&&(l(``),r(`key-input`)),!0}return!1}),S){let t=S===`network`;return h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m(_,{color:w.error,children:e.t(t?`setup.authFailedNetwork`:`setup.authFailedRejected`)})}),h(Y.Root,{id:`wizard-auth-failed`,onPick:e=>{if(t&&e===0){x();return}(t?e-1:e)===0?b():y()},children:[t?m(Y.Item,{label:e.t(`setup.actionOpenProxySettings`)}):null,m(Y.Item,{label:e.t(`setup.actionRetryAuth`)}),m(Y.Item,{label:e.t(`setup.actionUseApiKeyInstead`)})]})]})}return t.onProviderOAuthStart&&n===`oauth-wait`?h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m(_,{children:a?`Complete device authorization`:`Sign in via OAuth`})}),a?h(p,{children:[m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`1. Open this page:`})}),i&&m(g,{marginBottom:W.tight,children:h($,{type:`secondary`,children:[` `,i]})}),m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`2. Enter this code:`})}),m(g,{marginBottom:W.tight,children:h(_,{bold:!0,color:w.text,children:[` `,a]})}),o&&m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:o})})]}):h(p,{children:[m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`Open this URL in your browser to authorize:`})}),i&&m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:i})})]}),m(g,{marginBottom:W.tight,children:m(_,{color:w.text,children:e.t(`setup.oauthWaiting`)})}),h(Y.Root,{id:`wizard-oauth-wait`,onPick:e=>{e===0?v():y()},children:[m(Y.Item,{label:e.t(`setup.actionOpenAgain`)}),m(Y.Item,{label:e.t(`setup.actionUseApiKeyInstead`)})]})]}):n===`key-input`?h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m(_,{children:`Paste your API key`})}),m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`Generate a key on your provider dashboard and paste it below.`})}),m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:e.t(`setup.apiKeyStorageNote`)})}),m(g,{marginBottom:W.tight,children:m(tn,{value:s,offset:0,columns:60,mode:`dialog`,mask:!0,placeholder:e.t(`setup.wizardApiKeyPlaceholder`),focused:!0})})]}):n===`logging-in`?m(g,{flexDirection:`column`,children:m(_,{color:w.text,children:e.t(`setup.loggingIn`)})}):h(g,{flexDirection:`column`,children:[C&&m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:C})}),m(g,{flexDirection:`column`,children:O.map((e,t)=>h(g,{marginBottom:W.tight,flexDirection:`column`,children:[h(_,{color:t===T?w.selection:w.inactive,bold:t===T,children:[t===T?V.pointer:` `,` `,e.label]}),e.detail&&m(g,{marginLeft:W.section,children:m($,{type:`secondary`,children:e.detail})})]},e.value))})]})}function $r({request:t,onModel:n}){let r=t=>t===`unauthenticated`?e.t(`setup.modelUnusableUnauthenticated`):t===`oauth-429-risk`?e.t(`setup.modelUnusableOauthRisk`):``;return h(g,{flexDirection:`column`,children:[t.modelOptions.some(e=>e.recommended)&&m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:e.t(`setup.modelRecommendedHint`)})}),m(xr.Root,{maxVisible:8,frame:!1,onValueChange:e=>{n(e)},children:t.modelOptions.map(t=>{let n=r(t.unusableReason),i=[t.recommended?e.t(`setup.modelRecommendedTag`):``,n,t.detail??``].filter(Boolean).join(` · `);return m(xr.Item,{value:t.value,detail:i||void 0,children:t.label},t.value)})})]})}function ei({request:e,onComplete:t}){let n=K();return J(`wizard-dialog-4`,(e,n)=>n.return?(t(),!0):!1),h(g,{flexDirection:`column`,children:[m(g,{marginBottom:W.tight,children:m($,{type:`secondary`,children:`Try asking something like:`})}),m(g,{flexDirection:`column`,marginBottom:W.tight,children:e.examplePrompts.map((e,t)=>h($,{type:`secondary`,children:[` "`,e,`"`]},t))}),m(_,{color:n.text,children:`Press Enter to start chatting`})]})}export{nn as $,ue as $t,zn as A,We as At,Sn as B,je as Bt,Hn as C,J as Ct,In as D,it as Dt,Rn as E,at as Et,kn as F,Pe as Ft,hn as G,Se as Gt,Cn as H,De as Ht,An as I,Ne as It,ln as J,be as Jt,gn as K,K as Kt,On as L,Me as Lt,Nn as M,Ue as Mt,Mn as N,Le as Nt,Fn as O,et as Ot,$ as P,Fe as Pt,an as Q,W as Qt,En as R,q as Rt,Wn as S,ot as St,Bn as T,tt as Tt,xn as U,Te as Ut,wn as V,Ae as Vt,yn as W,we as Wt,cn as X,_e as Xt,un as Y,ge as Yt,rn as Z,G as Zt,Yn as _,Ke as _t,Ar as a,oe as an,jt as at,qn as b,qe as bt,wr as c,ne as cn,Nt as ct,dr as d,C as dn,Z as dt,ce as en,tn as et,ir as f,w as fn,xt as ft,Zn as g,Y as gt,nr as h,mt as ht,jr as i,R as in,Et as it,Pn as j,Be as jt,Ln as k,Ve as kt,Sr as l,B as ln,X as lt,tr as m,x as mn,vt as mt,Hr as n,V as nn,Pt as nt,Dr as o,ae as on,Ot as ot,rr as p,T as pn,_t as pt,fn as q,Ce as qt,Pr as r,H as rn,Dt as rt,Cr as s,se as sn,Mt as st,Jr as t,le as tn,Ut as tt,xr as u,S as un,wt as ut,Jn as v,Ze as vt,Vn as w,Qe as wt,Kn as x,Je as xt,Xn as y,Ye as yt,Tn as z,ke as zt};
|
|
10
|
+
//# sourceMappingURL=WizardDialog-BG-t6UJT.js.map
|