fluxflow-cli 4.47.0 → 4.49.0

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.
Files changed (39) hide show
  1. package/README.md +2 -0
  2. package/dist/chunks/{ai-IQMYBYU6.js → ai-QEMKCYGG.js} +1 -1
  3. package/dist/chunks/app-6TAUOS56.js +333 -0
  4. package/dist/chunks/{auto_completion-HIR5DVL5.js → auto_completion-33R46AFF.js} +1 -1
  5. package/dist/chunks/chunk-2XQIWDKW.js +1 -0
  6. package/dist/chunks/{chunk-OSSZ4LIE.js → chunk-2YDU2B2F.js} +1 -1
  7. package/dist/chunks/chunk-36FKJWXK.js +949 -0
  8. package/dist/chunks/{chunk-XDY4KWTM.js → chunk-AIWOSKP3.js} +1 -1
  9. package/dist/chunks/{chunk-MS33ZWST.js → chunk-IMX3PWYO.js} +1 -1
  10. package/dist/chunks/{chunk-ER3SNTS7.js → chunk-TNA3R7TS.js} +1 -1
  11. package/dist/chunks/{chunk-U2GX6WT2.js → chunk-ZCM4J7JT.js} +1 -1
  12. package/dist/chunks/{click-R35XTYKT.js → click-HMFVJIQN.js} +2 -2
  13. package/dist/chunks/{computer_action-WNXZNAIZ.js → computer_action-6AYM3W7D.js} +1 -1
  14. package/dist/chunks/{custom_openai-YS5EV6DG.js → custom_openai-HY6EEQI2.js} +1 -1
  15. package/dist/chunks/{drag-IB5WSI6F.js → drag-H53TOSDP.js} +1 -1
  16. package/dist/chunks/{generate_image-VW5VG6VI.js → generate_image-JS7J4FLD.js} +1 -1
  17. package/dist/chunks/{invoke-QXYLLM2W.js → invoke-WGWAIYZH.js} +3 -3
  18. package/dist/chunks/{invokeSync-UYRKSUNO.js → invokeSync-DCL3EMVV.js} +2 -2
  19. package/dist/chunks/{key_press-XDYBP7DW.js → key_press-NF322TXF.js} +1 -1
  20. package/dist/chunks/{keyboard_typing-YHYH7O66.js → keyboard_typing-OADL5LPA.js} +1 -1
  21. package/dist/chunks/{ollama-QB7WX7VD.js → ollama-NWY2XLYF.js} +1 -1
  22. package/dist/chunks/{recapture_screen-F6ZPZU56.js → recapture_screen-IXVMQR5C.js} +1 -1
  23. package/dist/chunks/{screen_grid-IWNA3DA2.js → screen_grid-DGIDOOQD.js} +1 -1
  24. package/dist/chunks/{scroll-GIP2J2QN.js → scroll-B3HCFDTS.js} +1 -1
  25. package/dist/chunks/{search_keyword-O52M65TB.js → search_keyword-UXNKLCGC.js} +1 -1
  26. package/dist/chunks/{secrets-YIWFP4S2.js → secrets-NGDMM5RJ.js} +1 -1
  27. package/dist/chunks/{secrets_v2-TEUFHDI7.js → secrets_v2-R5GMXRT3.js} +1 -1
  28. package/dist/chunks/{settings-HSQ2K6DN.js → settings-JME7GCEU.js} +1 -1
  29. package/dist/chunks/{update_file-QKDDZKOX.js → update_file-YXW37NRJ.js} +1 -1
  30. package/dist/chunks/{usage-6V4XZT3Q.js → usage-URT2EC23.js} +1 -1
  31. package/dist/chunks/{usageServer-4XHUFY7X.js → usageServer-RJDE5QDZ.js} +1 -1
  32. package/dist/chunks/write_file-WMLWKQKI.js +32 -0
  33. package/dist/cli.js +3 -3
  34. package/dist/package.json +2 -2
  35. package/package.json +2 -2
  36. package/dist/chunks/app-IPNLGJWQ.js +0 -333
  37. package/dist/chunks/chunk-45DLFA4C.js +0 -1
  38. package/dist/chunks/chunk-UNOUKPFA.js +0 -944
  39. package/dist/chunks/write_file-D7QA2LB2.js +0 -29
@@ -1,333 +0,0 @@
1
- import{a as xa}from"./chunk-UEV335RW.js";import{b as ea,c as ta,d as oa}from"./chunk-IHDJDAG3.js";import{c as Vl,e as jn,f as uo,g as Yl}from"./chunk-GM5VNNTU.js";import{A as fo,C as da,D as ua,E as ma,a as Kl,b as xt,c as yt,d as br,e as ii,f as zl,g as Bn,h as es,i as ts,j as Ql,r as ra,t as sa,w as ia,x as la,y as aa,z as ca}from"./chunk-UNOUKPFA.js";import{a as oo,b as jl,c as ql}from"./chunk-HFTI3R3Q.js";import"./chunk-52STSLCN.js";import{a as na}from"./chunk-56EJGQU3.js";import"./chunk-4BLSASW6.js";import{a as Wt,b as At,d as Wl,e as Lt,f as Xl,j as ri,k as si,l as pr,m as Gl,n as Go}from"./chunk-AMFNIFF3.js";import"./chunk-UIL6OCU4.js";import{a as Rl}from"./chunk-YX4X2ZTX.js";import{a as Tr,b as Ko,c as En,e as os,f as li,g as Jl,i as Zl,j as yr}from"./chunk-Z5D4VQSG.js";import{a as wr}from"./chunk-6EYQQ7GQ.js";import{a as vn}from"./chunk-Y5JU726N.js";import{b as on,c as ti}from"./chunk-XDY4KWTM.js";import{A as Al,C as Ll,D as Pl,E as Ol,H as Nl,c as Cl,e as Js,g as Ml,k as Sl,l as vl,m as Bl,n as El,o as Dl,q as Il,r as kl,u as Zs,v as Rs,w as ei}from"./chunk-U2GX6WT2.js";import{a as $l,b as Ul,i as _l,j as Zr,k as Rr,m as Et,n as Sn,o as ni,u as Hl}from"./chunk-OSSZ4LIE.js";import{a as Fl,b as oi,c as Kt}from"./chunk-45DLFA4C.js";import{d as gl,e as Qs,f as hl,g as pl,h as bl,i as wl,j as Tl,l as Jr,n as tn,o as co,p as hr,q as yl}from"./chunk-HTOLY3HR.js";import{c as zr,d as fl,e as Qr}from"./chunk-P5HBJA23.js";import{a as So,b as Mn,c as Ao,d as qs,e as zs,k as gr,y as xl}from"./chunk-26BQ45XP.js";import Bi from"os";import e,{useState as J,useEffect as gt,useRef as Ze,useMemo as Jn}from"react";import{Box as m,Text as l,useInput as su,useStdout as iu,Static as lu}from"ink";import au from"ink-spinner";import pt from"fs-extra";import Ct from"path";import{exec as Uo}from"child_process";import{fileURLToPath as cu}from"url";import Qt,{useState as ns,useEffect as ai,useMemo as Cr,useCallback as Ic,useRef as Vo}from"react";import{Box as kc,Text as vo,useInput as Ac}from"ink";function Lc(t,g){return t.replace(/\t/g," ".repeat(g))}function rs(t){return t==null?"":t.replace(/\r\n/g,`
2
- `).replace(/\r/g,`
3
- `)}function Dn(t,g,d){let S=t,w=[...g].sort((r,y)=>r.start-y.start),p=0;for(let r of w){let y=r.start-p,b=rs(r.text).split(`
4
- `).length,C=r.text.length,L=(b>3?`[Pasted ${b} lines]`:`[Pasted ${C} chars]`).length,F=y+L;if(t<=y)break;if(t<F){S=r.end;break}else{let B=r.text.length-L;S+=B,p+=B}}return Math.min(S,d.length)}function ci(t,g,d,S,w=[]){let p=(t||"").slice(0,g),r=S(p).length,y=S(t||""),b=[...w].sort((X,_)=>_.start-X.start);for(let X of b){let _=S(t.slice(0,X.start)).length,Y=S(X.text),j=_+Y.length,le=rs(X.text).split(`
5
- `).length,ue=X.text.length,ne=le>3?`[Pasted ${le} lines]`:`[Pasted ${ue} chars]`;y=y.slice(0,_)+ne+y.slice(j),r>_&&r<j?r=_+ne.length:r>=j&&(r=r-(j-_)+ne.length)}let C=y.split(`
6
- `),L=[],F=0,B=0,A=0,W=!1;for(let X=0;X<C.length;X++){let _=C[X];if(_.length===0){!W&&r===F&&(B=L.length,A=0,W=!0),L.push({text:"",globalStart:Dn(F,w,t),formattedStart:F}),F+=1;continue}let j=At(_,d).split(`
7
- `),le=0,ue=[];for(let ne=0;ne<j.length;ne++){let H=j[ne],pe=H.trim();if(pe.length===0){let Le=H.length||1;ue.push({text:H,start:le,length:Le}),le+=Le}else{let Le=_.indexOf(pe,le);if(Le!==-1){let Pe=le,rt=ne<j.length-1?j[ne+1].trim():"",Me=_.length;if(rt.length>0){let xe=_.indexOf(rt,Le+pe.length);xe!==-1&&(Me=xe)}ue.push({text:_.slice(Pe,Me),start:Pe,length:Me-Pe}),le=Me}else ue.push({text:H,start:le,length:H.length}),le+=H.length}}for(let ne=0;ne<ue.length;ne++){let H=ue[ne],pe=H.text,Le=F+H.start,Pe=Le+H.length;!W&&r>=Le&&(r<Pe||r===Pe&&ne===ue.length-1)&&(B=L.length,A=r-Le,W=!0),L.push({text:pe,globalStart:Dn(Le,w,t),formattedStart:Le})}F+=_.length+1}return W||(L.length===0?L.push({text:"",globalStart:0,formattedStart:0}):y.endsWith(`
8
- `)?(L.push({text:"",globalStart:Dn(F,w,t),formattedStart:F}),B=L.length-1,A=0):(B=L.length-1,A=L[B].text.length)),{visualLines:L,cursorLine:B,cursorCol:A}}var Pc=({value:t,rows:g,maxRows:d,highlightStyle:S,textStyle:w,placeholder:p="",mask:r,showCursor:y=!0,focus:b=!0,tabSize:C=4,cursorIndex:L=0,highlight:F,columns:B=80,pasteBlocks:A=[],cursorColor:W})=>{let X=Vo(0),_=Cr(()=>Math.max(20,B-10),[B]),Y=Ic((He,ke=!1)=>{let Te=rs(He);if(!ke&&r)return Te.replace(/[^\n]/g,r);let Q=Lc(Te,C);return ke?Q:Q.replace(/@\[(.*?)\]/g,(me,be)=>{let Z=be.indexOf("#"),fe=be.indexOf(":L"),q=be,Ye="";Z!==-1?(q=be.slice(0,Z),Ye=be.slice(Z)):fe!==-1&&(q=be.slice(0,fe),Ye=be.slice(fe));let $e=q.replace(/\\/g,"/"),Tt=(process.cwd()||"").replace(/\\/g,"/");Tt&&$e.toLowerCase().startsWith(Tt.toLowerCase()+"/")?$e=$e.slice(Tt.length+1):$e.startsWith("./")&&($e=$e.slice(2));let ct=$e.split("/");return`[${ct[ct.length-1]}${Ye}]`})},[C,r]),{visualLines:j,cursorLine:le,cursorCol:ue}=Cr(()=>ci(t,L,_,Y,A),[t,L,_,Y,A]),ne=j.length,H=Cr(()=>Math.max(g??d??1,Math.min(d??g??1,ne)),[g,d,ne]),pe=le+1,Le=X.current+H,Pe=X.current;pe<=X.current?Pe=Math.max(0,pe-1):pe>Le?Pe=pe-H:ne&&(ne<H?Pe=0:ne<Le&&(Pe=ne-H)),X.current=Pe;let rt=Cr(()=>j.slice(Pe,Pe+H),[j,Pe,H]),[Me,xe]=ns(!0);ai(()=>{if(xe(!0),!b||!y)return;let He=setInterval(()=>{xe(ke=>!ke)},530);return()=>clearInterval(He)},[b,y,t,L]);let ye=Cr(()=>({...w,color:y&&b&&Me?W||"white":void 0,bold:y&&b&&Me,inverse:y&&b&&Me}),[w,y,b,Me,W]),Mt=(He,ke,Te,Q)=>{if(!He){let q=p&&t.length===0?Y(p,!0):"";if(ke){let Ye=q[0]||" ",$e=q.slice(1);return Qt.createElement(vo,null,Qt.createElement(vo,{...Q},Ye),Qt.createElement(vo,{color:"gray",dimColor:!0},$e))}return Qt.createElement(vo,{color:"gray",dimColor:!0},q||" ")}let me=/(\[Pasted \d+ (?:lines|chars)\])/g,be=He.split(me),Z=0,fe=[];for(let q=0;q<be.length;q++){let Ye=be[q];if(Ye==="")continue;let $e=Ye.match(/^\[Pasted \d+ (?:lines|chars)\]$/),Tt=Ye.length,ct=Z+Tt;if(ke&&Te>=Z&&Te<ct){let wt=Te-Z,st=Ye.slice(0,wt),qe=Ye[wt]||" ",se=Ye.slice(wt+1);fe.push(Qt.createElement(vo,{key:q},Qt.createElement(vo,{color:$e?"magenta":void 0},st),Qt.createElement(vo,{...Q},qe),Qt.createElement(vo,{color:$e?"magenta":void 0},se)))}else fe.push(Qt.createElement(vo,{key:q,color:$e?"magenta":void 0},Ye));Z=ct}return ke&&Te>=He.length&&fe.push(Qt.createElement(vo,{key:"cursor-end",...Q}," ")),Qt.createElement(Qt.Fragment,null,fe)};return Qt.createElement(kc,{height:H,width:_+1,overflow:"hidden",flexDirection:"column",flexGrow:0,flexShrink:0},rt.map((He,ke)=>{let Te=Pe+ke,Q=Te===le&&b&&y;return Qt.createElement(vo,{key:Te,...w,wrap:"truncate"},Mt(He.text,Q,ue,ye))}))},fa=({value:t,onChange:g,onSubmit:d,keyBindings:S,showCursor:w=!0,highlightPastedText:p=!1,focus:r=!0,columns:y=80,useCustomInput:b=(_,Y)=>Ac(_,{isActive:Y}),onPasteStateChange:C,cursorColor:L,historyEnabled:F=!1,isBrowsingHistory:B=!1,onHistoryPrev:A,onHistoryNext:W,...X})=>{let[_,Y]=ns(t.length),[j,le]=ns(0),[ue,ne]=ns([]),H=Vo(t.length),pe=Vo(t),Le=Vo(0),Pe=Vo([]),rt=Vo(""),Me=Vo(-1),xe=Vo(null),ye=Vo(0);H.current=_,pe.current=t,Le.current=j,Pe.current=ue,ai(()=>{H.current>t.length&&(H.current=t.length,Y(t.length)),t?ne(ke=>ke.filter(Te=>Te.end<=t.length&&Te.start<=t.length)):(ne([]),le(0))},[t]),ai(()=>{C?.(ue.length>0)},[ue,C]);let Mt=()=>{let ke=rt.current,Te=Me.current,Q=Te+ke.length,me=pe.current,be=me.slice(0,Te)+ke+me.slice(Te);g(be),H.current=Q,Y(Q),le(ke.length>1?ke.length:0);let Z=rs(ke).split(`
9
- `).length,fe=ke.length;if(fe>50&&(Z>3||Z<=3&&fe>200)){let q={start:Te,end:Q,text:ke};ne(Ye=>{let $e=ke.length;return[...Ye.map(ct=>Te<=ct.start?{...ct,start:ct.start+$e,end:ct.end+$e}:ct),q]})}rt.current="",Me.current=-1,xe.current=null},He=()=>{xe.current&&(clearTimeout(xe.current),Mt())};return b((ke,Te)=>{if(ke==="\x1B[I"||ke==="\x1B[O"||ke==="[I"||ke==="[O")return;let Q=ke,me=!1,be=!1;Q&&typeof Q=="string"&&(Q.includes("\x1B[200~")&&(me=!0,Q=Q.replace(/\x1b\[200~/g,"")),Q.includes("\x1B[201~")&&(be=!0,Q=Q.replace(/\x1b\[201~/g,"")));let Z=H.current,fe=pe.current,q=Pe.current,Ye=Math.max(20,y-10),$e=(se,Be)=>{if(q.length===0)return;let ut=q.map(mt=>se<=mt.start?{...mt,start:mt.start+Be,end:mt.end+Be}:se>mt.start&&se<mt.end?null:mt).filter(Boolean);ne(ut)},Tt=se=>{for(let Be of q)if(se>Be.start&&se<Be.end)return Be.start;return se};if(Te.ctrl&&(Q==="o"||Q==="")){ne([]);return}if(Te.ctrl&&(Q.toLowerCase()==="r"||Q===""||Q===""))return;if(Te.upArrow||Te.downArrow||Te.leftArrow||Te.rightArrow){He();let se=Date.now();if(se-ye.current<33)return;ye.current=se}let wt=S?.submit??(se=>se.return&&se.ctrl),st=S?.newline??(se=>se.return);if(wt(Te)){He(),d?.(fe);return}else if(st(Te)){He(),$e(Z,1);let se=fe.slice(0,Z)+`
10
- `+fe.slice(Z);g(se),H.current=Z+1,Y(Z+1),le(0);return}if(Te.tab||Te.shift&&Te.tab||Te.ctrl&&Q==="c")return;let qe=se=>se;if(Te.upArrow||Te.downArrow){if(He(),F){if(Te.upArrow&&(fe===""||B)){A?.();return}if(Te.downArrow&&B){W?.();return}}if(w){let{visualLines:se,cursorLine:Be,cursorCol:ut}=ci(fe,Z,Ye,qe,q),mt=Te.upArrow?Be-1:Be+1;if(mt>=0&&mt<se.length){let _e=se[mt],Bt=Math.min(ut,_e.text.length),Xe=_e.formattedStart+Bt,ro=Dn(Xe,q,fe);ro=Tt(ro),H.current=ro,Y(ro),le(0)}else if(Te.upArrow&&Be===0)H.current=0,Y(0),le(0);else if(Te.downArrow&&Be===se.length-1){let _e=se[se.length-1],Bt=_e.formattedStart+_e.text.length,Xe=Dn(Bt,q,fe);Xe=Tt(Xe),H.current=Xe,Y(Xe),le(0)}}}else if(Te.leftArrow){if(He(),w){let se=Math.max(0,Z-1),Be=q.find(ut=>Z===ut.end);Be&&(se=Be.start),H.current=se,Y(se),le(0)}}else if(Te.rightArrow){if(He(),w){let se=Math.min(fe.length,Z+1),Be=q.find(ut=>Z===ut.start);Be&&(se=Be.end),H.current=se,Y(se),le(0)}}else if(Te.backspace){He();let se=q.findIndex(Be=>Z===Be.end);if(se!==-1){let Be=q[se],ut=-(Be.end-Be.start),mt=fe.slice(0,Be.start)+fe.slice(Be.end);g(mt),H.current=Be.start,Y(Be.start),le(0);let _e=q.filter((Bt,Xe)=>Xe!==se).map(Bt=>Bt.start>=Be.end?{...Bt,start:Bt.start+ut,end:Bt.end+ut}:Bt);ne(_e)}else if(Z>0){$e(Z-1,-1);let Be=fe.slice(0,Z-1)+fe.slice(Z);g(Be),H.current=Z-1,Y(Z-1),le(0)}}else if(Te.delete){He();let se=q.findIndex(Be=>Z===Be.start);if(se!==-1){let Be=q[se],ut=-(Be.end-Be.start),mt=fe.slice(0,Be.start)+fe.slice(Be.end);g(mt),le(0);let _e=q.filter((Bt,Xe)=>Xe!==se).map(Bt=>Bt.start>=Be.end?{...Bt,start:Bt.start+ut,end:Bt.end+ut}:Bt);ne(_e)}else if($e(Z,-1),Z<fe.length){let Be=fe.slice(0,Z)+fe.slice(Z+1);g(Be),le(0)}}else if(Te.home||Te.end){if(He(),w){let{visualLines:se,cursorLine:Be}=ci(fe,Z,Ye,qe,q),ut=se[Be];if(ut){let mt;Te.home?mt=Dn(ut.formattedStart,q,fe):Te.end&&(mt=Dn(ut.formattedStart+ut.text.length,q,fe)),mt=Tt(mt),H.current=mt,Y(mt),le(0)}}}else if(Q!==""||me||be)if(me||be||Q.length>1||xe.current!==null)xe.current?(clearTimeout(xe.current),rt.current+=Q):(Me.current=Z,rt.current=Q),be?(xe.current=null,Mt()):xe.current=setTimeout(()=>{Mt()},80);else{$e(Z,Q.length);let Be=fe.slice(0,Z)+Q+fe.slice(Z);g(Be);let ut=Z+Q.length;H.current=ut,Y(ut),le(0)}},r),Qt.createElement(Pc,{...X,value:t,cursorIndex:_,showCursor:w,focus:r,columns:y,pasteBlocks:ue,cursorColor:L})};import Zn from"ink-text-input";import"ink-select-input";import i from"react";import{Box as E,Text as ie}from"ink";import $t,{useState as ga,useEffect as Oc}from"react";import{Box as Yo,Text as Bo,useInput as Nc}from"ink";var ss=$t.memo(({command:t,output:g,completed:d=!1,isFocused:S=!1,columns:w=80,isPty:p=!1,terminalHeight:r=24,theme:y="Dark"})=>{let b=xt(y),L=(Q=>{if(!Q)return"";let me=[[]],be=0,Z=0,fe="",q=/\x1b\[([0-9;]*?)([a-zA-Z])/g,Ye=0,$e,Tt=wt=>{for(let st=0;st<wt.length;st++){let qe=wt[st];if(qe===`
11
- `)for(be++,Z=0;be>=me.length;)me.push([]);else if(qe==="\r")Z=0;else{for(;be>=me.length;)me.push([]);let se=me[be];for(;Z>se.length;)se.push({char:" ",style:""});se[Z]={char:qe,style:fe},Z++}}};for(;($e=q.exec(Q))!==null;){Tt(Q.substring(Ye,$e.index));let wt=$e[1],st=$e[2],qe=wt?wt.split(";").map(Number):[];if(st==="A"){let se=qe[0]||1;be=Math.max(0,be-se)}else if(st==="B"){let se=qe[0]||1;for(be=be+se;be>=me.length;)me.push([])}else if(st==="C"){let se=qe[0]||1;Z=Z+se}else if(st==="D"){let se=qe[0]||1;Z=Math.max(0,Z-se)}else if(st==="G"){let se=(qe[0]||1)-1;Z=Math.max(0,se)}else if(st==="H"||st==="f"){let se=(qe[0]||1)-1,Be=(qe[1]||1)-1;for(be=Math.max(0,se),Z=Math.max(0,Be);be>=me.length;)me.push([])}else if(st==="K"){let se=qe[0]||0;if(be<me.length){let Be=me[be];if(se===0)Be.length=Z;else if(se===1)for(let ut=0;ut<Z&&ut<Be.length;ut++)Be[ut]={char:" ",style:""};else se===2&&(Be.length=0)}}else if(st==="J"){let se=qe[0]||0;(se===2||se===3)&&(me.length=0,me.push([]),be=0,Z=0)}else if(st==="m"){let se=$e[0];se==="\x1B[0m"?fe="":fe=se}Ye=q.lastIndex}Tt(Q.substring(Ye));let ct=me.map(wt=>{let st="",qe="";for(let se=0;se<wt.length;se++){let Be=wt[se]||{char:" ",style:""};Be.style!==qe&&(qe&&(st+="\x1B[0m"),st+=Be.style,qe=Be.style),st+=Be.char}return qe&&(st+="\x1B[0m"),st});for(;ct.length>0&&ct[ct.length-1]==="";)ct.pop();return ct.join(`
12
- `)})(g).replace(/\n{3,}/g,`
13
-
14
- `),F=Math.max(10,(w||80)-6),B=L?L.split(`
15
- `).flatMap(Q=>Q?At(Q,F).split(`
16
- `):[""]):[],[A,W]=ga(!1),[X,_]=ga(0);Oc(()=>{S||_(0)},[S]);let Y=r&&r>0?r:process.stdout.rows||24,j=Y<=24,ue=Math.max(1,Y-(j?11:14)),ne=Y<=16?4:Y<=22?5:Y<=28?6:10,H=Math.min(ne,ue),pe=B.length>H,Le=Math.max(0,B.length-H);Nc((Q,me)=>{if(!S)return;let be=me.pageUp||Q==="\x1B[5~"||Q==="[5~",Z=me.pageDown||Q==="\x1B[6~"||Q==="[6~";me.ctrl&&(Q==="o"||Q==="")?(W(fe=>!fe),_(0)):be?_(fe=>Math.min(Le,fe+5)):Z&&_(fe=>Math.max(0,fe-5))},{isActive:S});let Pe;if(!pe||A)Pe=B;else{let Q=Math.max(0,B.length-H-X),me=Q+H;Pe=B.slice(Q,me)}let rt=(Pe||[]).join(`
17
- `).trim(),Me=(Pe||[]).join(`
18
- `),xe=pe&&!A?Math.max(0,B.length-H-X):0,ye=pe&&!A?X:0,Mt=d?"\u{1F3C1} FINISHED: ":"\u26A1 EXECUTING: ",He=Math.max(10,(w||80)-(p?24:14)),ke=At((t||"").replace(/\r?\n/g," ").trim(),He).split(`
19
- `),Te=(t||"").replace(/\r?\n/g," ").trim();return ke.length>1&&(Te=ke[0].length>3?ke[0].slice(0,-3)+"...":ke[0]+"..."),$t.createElement(Yo,{flexDirection:"column",borderStyle:S?"double":"single",borderLeft:!1,borderRight:!1,borderTop:!0,borderBottom:!0,borderColor:b.codeBorder,paddingLeft:2,paddingRight:0,paddingTop:j?0:1,paddingBottom:1,marginY:j?0:1,width:w-2},$t.createElement(Yo,{marginBottom:j?0:1,justifyContent:"space-between",width:"100%"},$t.createElement(Yo,{flexShrink:1,paddingRight:2},$t.createElement(Bo,null,$t.createElement(Bo,{color:b.text,bold:!0},Mt),$t.createElement(Bo,{color:b.text},Te))),p&&$t.createElement(Yo,{flexShrink:0,paddingX:1},$t.createElement(Bo,{color:"green",bold:!0},"ADVANCE"))),rt?$t.createElement(Yo,{flexDirection:"column",marginTop:0,backgroundColor:p?void 0:b.codeBg,paddingX:1,width:"100%"},xe>0&&$t.createElement(Yo,{marginBottom:0},$t.createElement(Bo,{color:"magenta"},"\u25B2 ...",xe," lines above (Use PageUp to scroll)...")),$t.createElement(Bo,{color:b.text},Me),ye>0&&$t.createElement(Yo,{marginTop:0},$t.createElement(Bo,{color:"magenta"},"\u25BC ...",ye," lines below (Use PageDown to scroll)..."))):!d&&$t.createElement(Yo,{marginTop:j?0:1,backgroundColor:p?void 0:b.codeBg,paddingX:1,width:"100%"},$t.createElement(Bo,{color:b.textMuted,italic:!0},"Waiting for output...")),$t.createElement(Yo,{justifyContent:"space-between",marginTop:j?0:1},d?$t.createElement(Bo,{color:b.textMuted,italic:!0},S?"Use PgUp/PgDn to scroll \u2022 Ctrl+O to expand/collapse \u2022 TAB to unfocus.":"Press TAB to focus & scroll."):$t.createElement(Bo,{color:b.textMuted,italic:!0},S?"Use PgUp/PgDn to scroll \u2022 Ctrl+O to expand \u2022 TAB to unfocus \u2022 CTRL+C to stop.":"Press TAB to focus \u2022 CTRL+C to terminate."),$t.createElement(Bo,{color:b.textMuted,bold:!0},d?S?"\u25CF ARCHIVED (FOCUSED) ":"\u25CF ARCHIVED ":S?"\u25B6 TERMINAL FOCUSED ":"\u25CF LIVE (Press TAB to focus) ")))});import{diffWordsWithSpace as Fc}from"diff";var Mr=null,ba=t=>{Mr=t!==!1},wa=()=>{if(Mr===null)try{Mr=Qr(Mn,{})?.systemSettings?.preserveThinking!==!1}catch{Mr=!0}return Mr},ha=(t,g,d)=>t,$c=(t,g=80)=>{if(!t)return null;let d=t.replaceAll(" "," "),S=g-10,w=d.trim();if(!w.includes("```"))return i.createElement(E,{width:"100%",flexDirection:"column"},i.createElement(zn,{text:w,color:"#969696",columns:S,italic:!0}));let p=w.split(/(```\w*\n?[\s\S]*?(?:```|$))/g);return i.createElement(E,{width:"100%",flexDirection:"column"},p.map((r,y)=>{if(r.startsWith("```")){let C=r.match(/```(\w*)\n?([\s\S]*?)(?:```|$)/),L=C?C[2]:r.replace(/^```\w*\n?/,"").replace(/```$/,""),F=At(L.trimEnd(),S);return i.createElement(E,{key:y,flexDirection:"column",width:"100%"},F.split(`
20
- `).map((B,A)=>i.createElement(ie,{key:A,color:"cyan"},B)))}let b=r;return y>0&&(b=b.replace(/^[\r\n]+/,"")),y<p.length-1&&(b=b.replace(/[\r\n]+$/,"")),b?i.createElement(zn,{key:y,text:b,color:"gray",columns:S,italic:!0}):null}))},Uc=/(```[\s\S]*?```|`[^`\r\n]+`|@\[.*?\]|\*\*.*?\*\*|\*.*?\*|\\\(.*?\\\)|\\\[.*?\\\]|\$.*?\$|\[.*?\]\s*\(.*?\)|\[[^\x1b\[\]\r\n]+\]\s*\[(?:https?:\/\/[^\s\]]+|#[^\s\]]+)\]|https?:\/\/[^\s)]+)/g;var _c=/\\frac\s*\{([^{}]*)\}\s*\{([^{}]*)\}/g,Hc=/(\\(?:mathbf|textbf|textit|underline|texttt)\{[^{}]*\})/g,Wc=/^(#{1,6})\s+(.*)/,Xc=/\\multiply|\\mul|\\times/g,Gc=/\\div/g,Kc=/\\cdot/g,Vc=/\\infty/g,Yc=/\\pm/g,jc=/\\leq/g,qc=/\\geq/g,zc=/\\neq/g,Qc=/\\sqrt\s*\{([^}]+)\}/g,Jc=/\\sqrt\s*(\w+|\d+)/g,Zc=/\\alpha/g,Rc=/\\beta/g,ed=/\\theta/g,td=/\\pi/g,od=/\\approx/g,nd=/\\Delta/g,rd=/\\sigma/g,sd=/\\sum/g,id=/\\prod/g,ld=/\\rightarrow|\\to/g,ad=/\\left\b|\\right\b/g,cd=/\\left\(|\\right\)/g,dd=/\\left\[|\\right\]/g,ud=/\\\{|\\\}/g,md=/\\text\s*\{([^}]+)\}/g,xd=/\\text\s+(\w+)/g,fd=/\\%/g,gd=/\\\(|\\\)/g,hd=/\\\[|\\\]/g,pd=/@\[(.*?)\]/g,pa=/:L/gi,bd=/\[(.*?)\]\s*\((.*?)\)/,wd=/\[([^\x1b\[\]\r\n]+)\]\s*\[(https?:\/\/[^\s\]]+|#[^\s\]]+)\]/,Td=/\\(\w+)\{([^{}]*)\}/,yd=t=>t.replace(gd,g=>g.includes("(")?"(":")").replace(hd,g=>g.includes("[")?"[":"]").replace(Xc,"\xD7").replace(Gc,"\xF7").replace(Kc,"\u22C5").replace(Vc,"\u221E").replace(Yc,"\xB1").replace(jc,"\u2264").replace(qc,"\u2265").replace(zc,"\u2260").replace(Qc,"\u221A($1)").replace(Jc,"\u221A($1)").replace(Zc,"\u03B1").replace(Rc,"\u03B2").replace(ed,"\u03B8").replace(td,"\u03C0").replace(od,"\u2248").replace(nd,"\u0394").replace(rd,"\u03C3").replace(sd,"\u03A3").replace(id,"\u03A0").replace(ld,"\u2192").replace(ad,"").replace(cd,g=>g.includes("left")?"(":")").replace(dd,g=>g.includes("left")?"[":"]").replace(ud,g=>g.includes("{")?"{":"}").replace(md,"$1").replace(xd,"$1").replace(fd,"%"),Cd=/\b(const|let|var|function|return|if|else|for|while|do|switch|case|break|continue|import|export|from|default|class|extends|new|this|typeof|instanceof|try|catch|finally|throw|async|await|yield|public|private|protected|static|void|int|float|double|char|bool|boolean|def|elif|fn|pub|mut|struct|impl|enum|type|interface|package|namespace|using|include|define|nil|None|self|lambda)\b/,Md=[/((?<=\binclude\s+)(?:<[^>]+>|"[^"]+"))/.source,/((?<=\b(?:from|import|require\s*\(\s*)\s*)(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"))/.source,/(\/\/.*|#.*)/.source,/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^\`\\])*`)/.source,Cd.source,/\b([a-zA-Z_][a-zA-Z0-9_]*)(?=\s*\()/.source,/\b(true|false|null|undefined|nil|None)\b/.source,/\b(\d+(?:\.\d+)?|0x[0-9a-fA-F]+)\b/.source],di=new RegExp(Md.join("|"),"g"),qn=new Map,Sd=1e3,vd=(t,g)=>{if(!t)return[];let d=`${g}:${t}`;if(qn.has(d))return qn.get(d);let S=0,w=[],p;for(di.lastIndex=0;(p=di.exec(t))!==null;){let r=p[0],y=p.index;y>S&&w.push({text:Wt(t.substring(S,y))});let b,C=!1;p[1]||p[2]?b="#ce9178":p[3]?b="#9ece6a":p[4]?b="#fcfca4":p[5]?(b="#ff7b72",C=!0):p[6]?b="#b392f0":(p[7]||p[8])&&(b="#ff9e64"),w.push({text:Wt(r),color:b,bold:C}),S=di.lastIndex}if(S<t.length&&w.push({text:Wt(t.substring(S))}),qn.size>=Sd){let r=qn.keys().next().value;qn.delete(r)}return qn.set(d,w),w},vt=(t,g,d=void 0,S=void 0)=>{if(!t)return i.createElement(ie,{backgroundColor:S}," ");let w=vd(t,g);return i.createElement(ie,{color:d,backgroundColor:S},w.map((p,r)=>i.createElement(ie,{key:r,color:p.color||d,backgroundColor:S,bold:p.bold},p.text)))},ui=(t,g)=>{if(!t)return null;let d=t.replace(_c,"($1/$2)");d=yd(d);let S=d.split(Hc);return i.createElement(i.Fragment,{key:g},S.map((w,p)=>{if(w.startsWith("\\")){let r=w.match(Td);if(r){let y=r[1],b=r[2];return i.createElement(ie,{key:p,bold:y==="mathbf"||y==="textbf",italic:y==="textit",underline:y==="underline",color:y==="texttt"?"cyan":void 0},b)}}return w}))},Jt=i.memo(({text:t,color:g,italic:d,theme:S="Dark"})=>{if(!t)return null;let w=t.replaceAll(" "," "),p=xt(S),r=g||p.text,y=p.codeText||p.logoGradient&&p.logoGradient[0]||p.info||p.secondary||"cyan",b=w.split(Uc);return i.createElement(ie,{color:r,wrap:"anywhere",italic:d},b.map((C,L)=>{if(!C)return null;if(C.startsWith("```")&&C.endsWith("```")){let F=C.slice(3,-3);return i.createElement(ie,{key:L,color:y},F)}if(C.startsWith("**")&&C.endsWith("**"))return i.createElement(ie,{key:L,bold:!0,color:r},i.createElement(Jt,{text:C.slice(2,-2),color:r,theme:S}));if(C.startsWith("*")&&C.endsWith("*"))return i.createElement(ie,{key:L,italic:!0,color:r},i.createElement(Jt,{text:C.slice(1,-1),color:r,italic:d,theme:S}));if(C.startsWith("`"))if(C.endsWith("`")&&C.length>1){let F=C.slice(1,-1),B=F.replace(pd,(W,X)=>X.split("/").pop().split("\\").pop().replace(pa,"#L")),A=F.includes("@[");return i.createElement(ie,{key:L,color:y,bold:A},B)}else return i.createElement(ie,{key:L,color:y},C.slice(1));if(C.startsWith("@[")&&C.endsWith("]")){let B=C.slice(2,-1).split("/").pop().split("\\").pop().replace(pa,"#L");return i.createElement(ie,{key:L,color:y,bold:!0},B)}if(C.startsWith("\\(")&&C.endsWith("\\)")||C.startsWith("\\[")&&C.endsWith("\\]")){let F=C.slice(2,-2);return i.createElement(ie,{key:L,color:"yellow"},ui(F,L))}if(C.startsWith("$")&&C.endsWith("$")){let F=C.slice(1,-1);return i.createElement(ie,{key:L,color:"yellow"},ui(F,L))}if(C.startsWith("[")&&(C.includes("](")||C.includes("] ("))){let F=C.match(bd);if(F){let B=F[1]||F[2],W=`\x1B]8;;${F[2]||F[1]}\x07${B}\x1B]8;;\x07`;return i.createElement(ie,{key:L,color:y,underline:!0,italic:!0},W)}}if(C.startsWith("[")&&(C.includes("][")||C.includes("] ["))){let F=C.match(wd);if(F){let B=F[1]||F[2],W=`\x1B]8;;${F[2]||F[1]}\x07${B}\x1B]8;;\x07`;return i.createElement(ie,{key:L,color:y,underline:!0,italic:!0},W)}}return C.startsWith("http")?i.createElement(ie,{key:L,color:y,underline:!0,italic:!0},C):ui(C,L)}))}),Ta=i.memo(({buffer:t,terminalWidth:g=80,theme:d="Dark"})=>{if(t.length<2)return null;let S=xt(d),w=S.codeText||S.secondary||S.info||"cyan",p=t.map(F=>{let B=F.split("|");return B[0]!==void 0&&B[0].trim()===""&&B.shift(),B.length>0&&B[B.length-1].trim()===""&&B.pop(),B.map(A=>A.trim())}),r=p[0],y=p.slice(2),b=Math.floor(100/r.length),C=g-8,L=Math.floor(C/r.length)-2;return i.createElement(E,{flexDirection:"column",borderStyle:"round",borderColor:S.borderMuted,paddingX:1,marginY:0,width:g-2},i.createElement(E,{flexDirection:"row",borderStyle:"single",borderBottom:!0,borderTop:!1,borderLeft:!1,borderRight:!1,borderColor:S.borderMuted,marginBottom:1,paddingBottom:0,width:"100%"},r.map((F,B)=>i.createElement(E,{key:B,flexBasis:`${b}%`,flexGrow:1,flexShrink:0,paddingRight:2},i.createElement(Jt,{text:At(F,L),color:w,theme:d})))),y.map((F,B)=>i.createElement(E,{key:B,flexDirection:"row",marginBottom:B===y.length-1?0:1,width:"100%"},F.map((A,W)=>i.createElement(E,{key:W,flexBasis:`${b}%`,flexGrow:1,flexShrink:0,paddingRight:2,flexDirection:"column"},i.createElement(Jt,{text:At(A,L),color:S.text,theme:d}))))))}),zn=i.memo(({text:t,color:g,columns:d=80,italic:S=!1,theme:w="Dark"})=>{if(!t)return null;let p=t.replaceAll(" "," "),r=xt(w),y=g||r.text,b=p.split(`
21
- `),C=[],L=[],F=[],B=A=>{if(L.length>0&&(C.push(i.createElement(Ta,{key:`table-${A}`,buffer:[...L],terminalWidth:d,theme:w})),L=[]),F.length>0){let W=d-6,X=F.flatMap(_=>At(_,W).split(`
22
- `));C.push(i.createElement(E,{key:`quote-${A}`,borderStyle:"bold",borderLeft:!0,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:r.borderMuted,paddingLeft:1,marginY:1,flexDirection:"column"},X.map((_,Y)=>i.createElement(Jt,{key:Y,text:_,color:r.textMuted,italic:S,theme:w})))),F=[]}};return b.forEach((A,W)=>{let X=A.trim(),_=X.startsWith("|"),Y=X.startsWith(">");if(_)F.length>0&&B(W),L.push(A);else if(Y)L.length>0&&B(W),F.push(X.replace(/^>\s*/,""));else{if(B(W),X===""){C.push(i.createElement(E,{key:W,height:1}));return}if(X==="---"||X==="***"||X==="___"){C.push(i.createElement(E,{key:W,marginY:0,borderStyle:"single",borderTop:!0,borderBottom:!1,borderLeft:!1,borderRight:!1,width:"100%",borderColor:r.borderMuted}));return}let j=X.match(/^(#{1,6})\s+(.*)/);if(j){let pe=j[1].length,Le=j[2];C.push(i.createElement(E,{key:W,marginTop:1,marginBottom:0,width:"100%"},i.createElement(ie,{bold:!0,color:pe===1?"yellow":pe===2?"magenta":pe===3?r.info||"cyan":pe===4?"green":pe===5?"blue":r.text,underline:!0},Le)));return}let le=/^[\*\-\+]\s/.test(X),ue=/^\d+\.\s/.test(X),ne=A.includes("\u2588")||A.includes("\u2554")||A.includes("\u255A")||A.includes("\u2550"),H="";if(ne)H=A;else if(le||ue){let pe=le?" \u2022 ":X.match(/^\d+\.\s/)[0],Le=" ".repeat(pe.length),Pe=At(X.replace(/^[\*\-\d+\.]+\s/,""),d-(pe.length+6));H=pe+Pe.split(`
23
- `).join(`
24
- `+Le)}else H=At(X,d-4);C.push(i.createElement(E,{key:W,flexDirection:"column",width:"100%"},i.createElement(Jt,{text:H,color:y,italic:S,theme:w})))}}),B("final"),i.createElement(E,{flexDirection:"column",width:d-2},C)}),ya=i.memo(({line:t,pairContent:g,parentText:d,columns:S=80,extension:w,theme:p="Dark"})=>{let r=xt(p),y=(t||"").replaceAll(" "," "),b=y.includes("[UI_CONTEXT]"),C=y.replace("[UI_CONTEXT]","");if(b&&C.trim().startsWith("@@")){let rt=C.trim().split(/\s+/);return i.createElement(E,{backgroundColor:r.codeBg,paddingX:1,width:S,marginY:0},i.createElement(E,{width:S-2,flexDirection:"row"},rt.map((Me,xe)=>{let ye=r.info||"cyan";return Me.startsWith("+")?ye=r.diffAdditionNum||"green":Me.startsWith("-")&&(ye=r.diffRemovalNum||"red"),i.createElement(ie,{key:xe,color:ye,bold:Me.startsWith("+")||Me.startsWith("-")},Me,xe<rt.length-1?" ":"")})))}if(b&&C.includes("\u2550"))return i.createElement(E,{backgroundColor:r.codeBg,paddingX:1,width:S},i.createElement(ie,{color:"gray"},"\u2550".repeat(Math.max(10,S-4))));let F=ri(y);if(!F)return i.createElement(E,{backgroundColor:r.codeBg,paddingX:1,width:S},i.createElement(E,{width:3,flexShrink:0}),i.createElement(E,{width:1,flexShrink:0,marginLeft:1}),i.createElement(E,{flexGrow:1,marginLeft:1},i.createElement(ie,{color:"gray"},At(C,S-14))));let{isR:B,isA:A,num:W,content:X}=F,_=g&&g.replaceAll(" "," "),Y=[];if(_!=null){let Pe=B?X:_,rt=B?_:X;try{Y=Fc(Pe,rt)}catch{Y=[]}}let j=Y.some(Pe=>B&&Pe.removed||A&&Pe.added),le=!_&&(B||A),ue=B?r.diffRemovalBg:A?r.diffAdditionBg:void 0,ne=B||A?B?r.diffRemovalNum:r.diffAdditionNum:r.textMuted,H=B?r.diffRemovalPrefix:r.diffAdditionPrefix,pe=B?"-":A?"+":" ",Le=()=>{if(le){let Q=B?r.diffRemovalHighlightBg:r.diffAdditionHighlightBg;return i.createElement(E,{flexDirection:"column"},vt(At(X,S-15),w,void 0,Q))}if(!(B||A)||Y.length===0||!j)return i.createElement(E,{flexDirection:"column"},vt(At(X,S-15),w,void 0,void 0));let Pe=Math.max(10,S-15),rt=At(X,Pe).split(`
25
- `),Me=[];if(Y.forEach((Q,me)=>{let be=/^\s+$/.test(Q.value);if(B){let Z=Y[me-1]?.removed||Y[me+1]?.removed;Q.removed||be&&Z?Me.push({text:Q.value,isHighlight:!0}):Q.added||Me.push({text:Q.value,isHighlight:!1})}else if(A){let Z=Y[me-1]?.added||Y[me+1]?.added;Q.added||be&&Z?Me.push({text:Q.value,isHighlight:!0}):Q.removed||Me.push({text:Q.value,isHighlight:!1})}}),rt.length<=1)return i.createElement(ie,{wrap:"wrap"},Me.map((Q,me)=>B?Q.isHighlight?i.createElement(i.Fragment,{key:me},vt(Q.text,w,void 0,r.diffRemovalHighlightBg)):i.createElement(i.Fragment,{key:me},vt(Q.text,w,void 0)):A?Q.isHighlight?i.createElement(i.Fragment,{key:me},vt(Q.text,w,void 0,r.diffAdditionHighlightBg)):i.createElement(i.Fragment,{key:me},vt(Q.text,w,void 0)):i.createElement(i.Fragment,{key:me},vt(Q.text,w,void 0))));let xe=0,ye=0,Mt=X.match(/^(\s*)/),He=Mt?Mt[1]:"",ke=He.substring(0,Math.min(He.length,8)),Te=rt.map((Q,me)=>{let be=[],Z=Q;me>0&&ke&&Q.startsWith(ke)&&((Me[xe]?Me[xe].text.substring(ye):"").startsWith(ke)||(be.push({text:ke,isHighlight:!1}),Z=Q.substring(ke.length)));let fe=Z.length;for(;fe>0&&xe<Me.length;){let q=Me[xe],Ye=q.text.length-ye;if(Ye<=0){xe++,ye=0;continue}let $e=Math.min(fe,Ye);be.push({text:q.text.substring(ye,ye+$e),isHighlight:q.isHighlight}),ye+=$e,fe-=$e,ye>=q.text.length&&(xe++,ye=0)}for(;xe<Me.length;){let q=Me[xe],Ye=q.text.substring(ye);if(/^\s+$/.test(Ye))xe++,ye=0;else if(Ye.startsWith(" ")||Ye.startsWith(" ")){let $e=0;for(;$e<Ye.length&&(Ye[$e]===" "||Ye[$e]===" ");)$e++;ye+=$e,ye>=q.text.length&&(xe++,ye=0);break}else break}return be});if(xe<Me.length){let Q=Te[Te.length-1];for(;xe<Me.length;){let me=Me[xe];Q.push({text:me.text.substring(ye),isHighlight:me.isHighlight}),xe++,ye=0}}return i.createElement(E,{flexDirection:"column"},Te.map((Q,me)=>i.createElement(E,{key:me},i.createElement(ie,{wrap:"wrap"},Q.map((be,Z)=>B?be.isHighlight?i.createElement(i.Fragment,{key:Z},vt(be.text,w,void 0,r.diffRemovalHighlightBg)):i.createElement(i.Fragment,{key:Z},vt(be.text,w,void 0)):A?be.isHighlight?i.createElement(i.Fragment,{key:Z},vt(be.text,w,void 0,r.diffAdditionHighlightBg)):i.createElement(i.Fragment,{key:Z},vt(be.text,w,void 0)):i.createElement(i.Fragment,{key:Z},vt(be.text,w,void 0)))))))};return i.createElement(E,{backgroundColor:r.codeBg,paddingX:1,width:S},i.createElement(E,{width:4,flexShrink:0,justifyContent:"flex-end"},i.createElement(ie,{color:ne},W)),i.createElement(E,{width:1,flexShrink:0,marginLeft:1},i.createElement(ie,{color:H},pe)),i.createElement(E,{marginLeft:1,backgroundColor:ue,flexGrow:1},Le()))}),Bd=i.memo(({text:t,columns:g=80,extension:d,theme:S="Dark"})=>{let w=xt(S),p=t.match(/\[DIFF_START\]([\s\S]*?)(?:\[DIFF_END\]|$)/),b=(p?p[1].trim():"").split(`
26
- `).map(L=>{let F=L.replaceAll(" "," ");return{line:F,parsed:ri(F),pairContent:null}}),C=[];for(let L=0;L<b.length;L++){let F=b[L];F.parsed&&(F.parsed.isR||F.parsed.isA)?C.push(F):C.length>0&&(si(C),C=[])}return C.length>0&&si(C),i.createElement(E,{flexDirection:"column",width:g-3,marginBottom:1},i.createElement(E,{flexDirection:"column",paddingY:0,width:"100%"},i.createElement(E,{backgroundColor:w.codeBg,paddingX:1,width:"100%"},i.createElement(E,{width:3,flexShrink:0}),i.createElement(E,{width:1,flexShrink:0,marginLeft:1}),i.createElement(E,{flexGrow:1,marginLeft:1},i.createElement(ie,null," "))),b.map((L,F)=>i.createElement(ya,{key:F,line:L.line,pairContent:L.pairContent,columns:g-3,extension:d,theme:S})),i.createElement(E,{backgroundColor:w.codeBg,paddingX:1,width:"100%"},i.createElement(E,{width:3,flexShrink:0}),i.createElement(E,{width:1,flexShrink:0,marginLeft:1}),i.createElement(E,{flexGrow:1,marginLeft:1},i.createElement(ie,null," ")))))}),is=i.memo(({text:t,columns:g=80,theme:d="Dark"})=>{if(!t)return null;let S=xt(d),w="",p=t.match(/File\s+\[(.*?)\]/i);if(p&&(w=p[1].split(".").pop().toLowerCase()),t.includes("[DIFF_START]"))return i.createElement(Bd,{text:t,columns:g,extension:w,theme:d});if(t.includes("- Content Preview:")){let r=t.split("- Content Preview:"),y=r[0],b=r[1]||"",C="[SYSTEM] Check the content preview for verification [/SYSTEM]",L=b.split(C),F=(L[0]?.trim()||"").replaceAll(" "," "),B=L[1]?`${C}${L[1]}`:"",A=F.split(`
27
- `),W=String(A.length).length;return i.createElement(E,{flexDirection:"column",width:g-3},i.createElement(E,{flexDirection:"column",borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:S.codeBorder,paddingLeft:2,paddingRight:0,width:"100%",marginBottom:1,backgroundColor:S.codeBg},i.createElement(E,{flexDirection:"column",width:"100%"},i.createElement(E,{width:"100%"},i.createElement(E,{width:W+2,flexShrink:0},i.createElement(ie,null," ")),i.createElement(E,{flexGrow:1},i.createElement(ie,null," "))),A.map((X,_)=>i.createElement(E,{key:_,width:"100%"},i.createElement(E,{width:W+2,flexShrink:0},i.createElement(ie,{color:"gray",dimColor:!0},String(_+1).padStart(W," ")," ")),i.createElement(E,{flexGrow:1},vt(X,w,S.text)))),i.createElement(E,{width:"100%"},i.createElement(E,{width:W+2,flexShrink:0},i.createElement(ie,null," ")),i.createElement(E,{flexGrow:1},i.createElement(ie,null," "))))))}if(t.includes("```")){let r=t.split(/(```\w*\n?[\s\S]*?(?:```|$))/g);return i.createElement(E,{flexDirection:"column",width:g-3},r.map((y,b)=>{if(y.startsWith("```")){let L=y.match(/```(\w*)\n?([\s\S]*?)(?:```|$)/),F=L?L[1]:"code",B=(L?L[2]:y.replace(/^```\w*\n?/,"").replace(/```$/,"")).replaceAll(" "," "),A=B.trimEnd().split(`
28
- `),W=String(A.length).length,X=g-7-W,Y=(X>5?At(B,X):B).trimEnd().split(`
29
- `);return i.createElement(E,{key:b,flexDirection:"column",marginY:0,paddingLeft:2,paddingRight:0,width:"100%"},i.createElement(E,null,i.createElement(ie,{color:"gray",bold:!0},"\u25B6_ ",F.toUpperCase()||"TEXT")),i.createElement(E,{flexDirection:"column",width:"100%"},Y.map((j,le)=>{let ne=At(j,Math.max(10,X)).split(`
30
- `);return i.createElement(E,{key:le,flexDirection:"column",width:"100%"},ne.map((H,pe)=>i.createElement(E,{key:pe,width:"100%"},i.createElement(E,{width:W+2,flexShrink:0},i.createElement(ie,{color:"gray"},pe===0?String(le+1).padStart(W," ")+" ":" ".repeat(W+1))),i.createElement(E,{flexGrow:1},vt(H,F,S.text)))))})))}let C=y;return b>0&&(C=C.replace(/^[\r\n]+/,"")),b<r.length-1&&(C=C.replace(/[\r\n]+$/,"")),C?i.createElement(zn,{key:b,text:C,columns:g-3,theme:d}):null}))}return i.createElement(zn,{text:t,columns:g-3,theme:d})}),ls=t=>{let g=Math.round(t/1e3);if(g<=0)return"0s";let d=Math.floor(g/60),S=g%60;return d>0?`${d}m ${S}s`:`${g}s`},Ca=i.memo(({msg:t,showFullThinking:g,columns:d=80,aiProvider:S,version:w,theme:p="Dark"})=>{let r=xt(p),y=t.role==="system"&&(t.text?.includes("[DIFF_START]")||t.text?.includes("- Content Preview:")),b=t.role==="system"&&(t.text?.includes("[ACTION RESULT]: ERROR:")||t.text?.includes("[TOOL RESULT]: ERROR:"))&&!t.text?.includes("[DIFF_START]")&&(t.toolName==="update_file"||t.text?.includes("Could not find exact match")),C=t.isTerminalRecord;if(t.isHomeWarning)return i.createElement(E,{marginBottom:1,paddingX:1,width:"100%"},i.createElement(E,{flexDirection:"column",borderStyle:"round",borderColor:r.border,dimColor:!0,padding:0,width:"100%"},i.createElement(E,{paddingX:1},i.createElement(ie,{color:r.text,bold:!0},t.text)),i.createElement(E,{paddingX:1,marginTop:0,marginBottom:0},i.createElement(ie,{color:r.text},t.subText))));if(t.isLogo)return i.createElement(E,{flexDirection:"column",alignItems:"flex-start",width:"100%",marginY:1},i.createElement(ie,null,br(w,S,p)));if(t.id&&String(t.id).startsWith("welcome"))return i.createElement(E,{flexDirection:"column",alignItems:"center",width:"100%",marginY:1},i.createElement(E,{borderStyle:"round",borderColor:r.borderMuted,paddingX:3,paddingY:0},i.createElement(ie,{color:r.text,bold:!0},t.text.trim())));if(t.isVisualFeedback)return i.createElement(E,{marginBottom:0,marginTop:0,paddingX:1,width:"100%"},i.createElement(ie,{color:r.text},t.text));if(t.isSteeringHint||t.role==="user"&&(t.text?.startsWith("[STEERING HINT]")||t.text?.startsWith("[QUESTION]"))){let X=t.hintContent||(t.text||"").replace(/^\[(?:STEERING HINT|QUESTION)\]\s*/i,"").trim();return i.createElement(E,{flexDirection:"column",width:d-1,marginBottom:0,marginTop:0},i.createElement(E,{width:d-1,height:1,overflow:"hidden"},i.createElement(ie,{color:r.userMsgBorder},"\u2584".repeat(Math.max(1,d-1)))),i.createElement(E,{backgroundColor:r.userMsgBg,paddingX:1,paddingY:0,width:d-1,flexDirection:"column"},At(X.replace(/\r\n/g,`
31
- `).replace(/\r/g,`
32
- `).replace(/\\\n/g,`
33
- `).replace(/\\$/,""),d-7).split(`
34
- `).map((_,Y)=>i.createElement(E,{key:Y,flexDirection:"row",width:"100%"},i.createElement(E,{flexShrink:0,width:2},i.createElement(ie,{bold:!0,color:r.userMsgText},Y===0?"\u2726":" ")),i.createElement(E,{flexGrow:1,marginLeft:1},i.createElement(Jt,{text:_,color:r.userMsgText,theme:p}))))),i.createElement(E,{width:d-1,height:1,overflow:"hidden"},i.createElement(ie,{color:r.userMsgBorder},"\u2580".repeat(Math.max(1,d-1)))))}if(b)return i.createElement(E,{marginBottom:1},i.createElement(E,{flexDirection:"column",borderStyle:"round",borderColor:r.border,paddingX:1,paddingY:0},i.createElement(ie,{color:r.text,bold:!0,underline:!0},"\u2717 PATCH FAILED"),i.createElement(E,{marginTop:1},i.createElement(ie,{color:r.textMuted,bold:!0},"Model generated malformed edit."))));if(t.role==="system"&&(t.text?.includes("[ACTION RESULT]")||t.text?.includes("[TOOL RESULT]"))&&!y&&!C&&!b)return null;if(t.isImageStats)return i.createElement(E,{marginBottom:1,paddingX:1,width:"100%"},i.createElement(E,{flexDirection:"column",borderStyle:"round",borderColor:r.borderMuted,padding:0,width:"100%"},i.createElement(E,{paddingX:1,backgroundColor:r.codeBg},i.createElement(ie,{color:r.text,bold:!0},"IMAGE STATS")),i.createElement(E,{paddingX:1,marginTop:1,marginBottom:1,flexDirection:"column"},t.text.split(`
35
- `).map((X,_)=>i.createElement(ie,{key:_,color:r.textMuted},X)))));if(t.isAskRecord){let X=t.text.match(/Selection: (.*)/),_=X?X[1]:"No selection",Y=t.text.match(/Question: (.*)/),j=Y?Y[1]:null,le=j==="Agent has been running for a long time. Do you want to continue execution?";return i.createElement(E,{marginBottom:0,paddingX:1,width:"100%"},i.createElement(E,{flexDirection:"column",borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!0,borderBottom:!0,borderColor:r.codeBorder,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,marginY:1,width:d-2},i.createElement(E,{paddingX:1},i.createElement(ie,{color:r.success,bold:!0},le?"TURN SAFETY SYSTEM: RESOLVED":"AGENT REQUEST: RESOLVED")),j&&i.createElement(E,{paddingX:1,marginTop:1},i.createElement(ie,{color:r.secondary},j)),i.createElement(E,{paddingX:1,marginTop:1,marginBottom:0},i.createElement(ie,{color:r.text},"Selection: ",i.createElement(ie,{color:r.textMuted,bold:!0},_)))))}if(t.isAboutRecord)return i.createElement(E,{marginBottom:0,paddingX:1,width:"100%"},i.createElement(E,{flexDirection:"column",borderStyle:"round",border:!0,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,backgroundColor:r.codeBg,width:"100%"},i.createElement(E,{paddingX:1},i.createElement(ie,{color:r.text,bold:!0},"ABOUT FLUX FLOW")),i.createElement(E,{paddingX:1,marginTop:1,marginBottom:1},i.createElement(ie,{color:r.text},t.text))));if(t.isUpdateNotification)return i.createElement(E,{marginBottom:1,paddingX:1,width:"100%"},i.createElement(E,{flexDirection:"column",borderStyle:"round",border:!0,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,backgroundColor:r.codeBg,width:"100%"},i.createElement(E,{paddingX:1},i.createElement(ie,{color:r.text,bold:!0},"UPDATE AVAILABLE")),i.createElement(E,{paddingX:1,marginTop:1,marginBottom:1},i.createElement(is,{text:t.text,columns:d,theme:p}))));if(t.isHelpRecord){let X=[{cmd:"/quit",desc:"Exit and shutdown Flux"},{cmd:"/kill",desc:"Kill a process by PID or list active processes"},{cmd:"/help",desc:"Show all available commands"},{cmd:"/compress",desc:"Summarize and compress chat history"},{cmd:"/truncate",desc:"Truncate tool results in chat history"},{cmd:"/clear",desc:"Clear terminal screen"},{cmd:"/resume",desc:"Load previous session"},{cmd:"/revert",desc:"Revert codebase to checkpoint"},{cmd:"/save",desc:"Force save current chat"},{cmd:"/export",desc:"Export current chat or error logs"},{cmd:"/chats",desc:"List all chat sessions"},{cmd:"/btw",desc:"Send raw inquiry mid-turn"},{cmd:"/budget",desc:"Set or View budget limits"},{cmd:"/mode",desc:"Toggle Flux/Flow modes"},{cmd:"/thinking",desc:"Set AI reasoning depth"},{cmd:"/model",desc:"Switch AI model"},{cmd:"/wildcard-tooling",desc:"Use if the model lacks Tooling Capability"},{cmd:"/wildercard-tooling",desc:"Extended version of /wildcard-tooling"},{cmd:"/provider",desc:"Select AI Provider"},{cmd:"/settings",desc:"Configure system prefs"},{cmd:"/theme",desc:"Customize UI color theme"},{cmd:"/key",desc:"Manage API keys (list/add/remove/use/clean)"},{cmd:"/memory",desc:"Manage agent memory"},{cmd:"/stats",desc:"Show session usage"},{cmd:"/usage",desc:"Open graphical token usage & analytics in browser"},{cmd:"/reset",desc:"Wipe all saved FluxFlow AppData"},{cmd:"/about",desc:"Project info & credits"},{cmd:"/changelog",desc:"View latest updates"},{cmd:"/docs",desc:"View documentation"},{cmd:"/fluxflow",desc:"Project management"},{cmd:"/update",desc:"Check/Install updates"}];return i.createElement(E,{marginBottom:1,paddingX:1,width:"100%"},i.createElement(E,{flexDirection:"column",borderStyle:"round",borderColor:r.borderMuted,paddingX:2,paddingY:1,width:"100%"},i.createElement(ie,{color:r.text,bold:!0,underline:!0},"AVAILABLE COMMANDS IN FLUX-FLOW"),i.createElement(E,{flexDirection:"column",marginTop:1},X.map((_,Y)=>i.createElement(E,{key:Y,flexDirection:"row"},i.createElement(E,{width:20},i.createElement(ie,{color:r.text,bold:!0},_.cmd)),i.createElement(ie,{color:r.textMuted}," - ",_.desc))))))}if(t.isTerminalRecord){let X=t.text.match(/COMMAND: (.*)/),_=t.text.match(/PTY: (true|false)/),Y=t.text.match(/OUTPUT: ([\s\S]*)/),j=X?X[1]:"No Command",le=_?_[1]==="true":!1,ue=Y?Y[1]:"";return i.createElement(E,{marginBottom:0,paddingX:1,width:"100%"},i.createElement(ss,{command:j,output:ue,completed:!0,columns:d,isPty:le,theme:p}))}let[F,B]=i.useState(!t.isStreaming),A=i.useMemo(()=>(Gl(t.text,t.role)||"").replaceAll(" "," "),[t.text,t.role]);i.useEffect(()=>{t.isStreaming&&B(!1)},[t.id]);let W=i.useMemo(()=>t.role==="think"&&!g?"Thinking...":t.isStreaming?A:A.trimEnd(),[A,t.role,g,t.isStreaming]);return t.role==="think"&&!wa()||t.role==="agent"&&W.trim()===""?null:i.createElement(E,{marginBottom:(t.role==="think"||t.role==="user"||t.role==="agent",0),marginTop:(t.role==="think"||t.role==="user"||t.role==="agent",0),flexDirection:"column",flexShrink:0,width:"100%",flexGrow:1},t.role==="user"?i.createElement(E,{flexDirection:"column",width:d-1},i.createElement(E,{width:d-1,height:1,overflow:"hidden"},i.createElement(ie,{color:r.userMsgBorder},"\u2584".repeat(Math.max(1,d-1)))),i.createElement(E,{backgroundColor:r.userMsgBg,paddingX:1,paddingY:0,width:d-1,flexDirection:"column"},At(W.replace(/\r\n/g,`
36
- `).replace(/\r/g,`
37
- `).replace(/\\\n/g,`
38
- `).replace(/\\$/,""),d-7).split(`
39
- `).map((X,_)=>i.createElement(E,{key:_,flexDirection:"row",width:"100%"},i.createElement(E,{flexShrink:0,width:2},i.createElement(ie,{bold:!0,color:r.userMsgText},_===0?">":" ")),i.createElement(E,{flexGrow:1,marginLeft:1},i.createElement(Jt,{text:X,color:t.color||r.userMsgText,theme:p}))))),i.createElement(E,{width:d-1,height:1,overflow:"hidden"},i.createElement(ie,{color:r.userMsgBorder},"\u2580".repeat(Math.max(1,d-1))))):t.role==="think"?i.createElement(E,{flexDirection:"column",marginTop:0,marginBottom:0,paddingX:0,width:"100%"},t.isStreaming&&!t.duration?i.createElement(ie,{bold:!0,color:r.text},"\u2727 Thinking..."):i.createElement(ie,{bold:!0,color:r.text},"\u2726 Thought",t.duration?i.createElement(ie,{color:r.textMuted}," for ",i.createElement(ie,{bold:!0,color:r.text},ls(t.duration))):"s..."),i.createElement(E,{borderStyle:"single",borderLeft:!0,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:r.borderMuted,paddingLeft:2,paddingTop:0,paddingBottom:0,flexDirection:"column",width:"100%"},$c(W,d))):i.createElement(E,{flexDirection:"column",paddingX:1,marginTop:0,width:"100%"},i.createElement(is,{text:W.replace(/ \|\n\n/g,` |
40
- `),columns:d,theme:p}),t.memoryUpdated&&i.createElement(E,{marginTop:1,width:"100%"},i.createElement(ie,{color:r.text,italic:!0},"[Memory Updated]")),t.role==="agent"&&t.workedDuration?i.createElement(E,{marginTop:1,marginBottom:2,width:"100%"},i.createElement(ie,{color:r.textMuted},"["),i.createElement(ie,{color:r.textMuted},"Worked for ",i.createElement(ie,{bold:!0,color:r.text},ls(t.workedDuration))),i.createElement(ie,{color:r.textMuted},"]")):null))}),as=i.memo(({block:t,columns:g=80,showFullThinking:d,aiProvider:S,version:w,theme:p="Dark"})=>{let r=xt(p),{msg:y,type:b,text:C,isStreamingMsg:L,workedDuration:F}=t;if((b==="think-header"||b==="think-line"||b==="think-footer-padding")&&!wa())return null;if(b==="chunk")return i.createElement(E,{flexDirection:"column",width:"100%"},t.blocks.map(B=>i.createElement(as,{key:B.key,block:B,columns:g,showFullThinking:d,aiProvider:S,version:w,theme:p})));if(b==="full-message")return i.createElement(Ca,{msg:y,showFullThinking:d,columns:g,aiProvider:S,version:w,theme:p});if(b==="think-header")return i.createElement(E,{flexDirection:"column",paddingX:1,width:"100%",marginTop:0,marginBottom:0},(()=>{let B=t.duration||y?.duration||F;return L&&!B?i.createElement(ie,{bold:!0,color:r.text},"\u2727 Thinking..."):i.createElement(ie,{bold:!0,color:r.text},"\u2726 Thought",B?i.createElement(ie,{color:r.textMuted}," for ",i.createElement(ie,{bold:!0,color:r.text},ls(B)),"..."):"s...")})(),d&&i.createElement(E,{flexDirection:"row",width:"100%"},i.createElement(ie,{color:r.textMuted},"\u2502 ")));if(b==="think-line"){if(!d)return null;if(!C||C.trim()==="")return i.createElement(E,{flexDirection:"row",width:"100%",paddingX:1},i.createElement(ie,{color:r.textMuted},"\u2502 "));let B=ha(C,L,t.isActiveBlock)?.replaceAll(" "," ")||"";return i.createElement(E,{flexDirection:"row",width:"100%",paddingX:1},i.createElement(ie,{color:r.textMuted},"\u2502 "),i.createElement(E,{flexGrow:1,marginLeft:1},i.createElement(Jt,{text:B,color:r.textMuted,italic:!0,theme:p})))}if(b==="think-footer-padding")return d?i.createElement(E,{flexDirection:"row",width:"100%",paddingX:1},i.createElement(ie,{color:r.textMuted},"\u2502 ")):null;if(b==="agent-line"){if(!C||C.trim()==="")return i.createElement(E,{height:1});let B=ha(C,L,t.isActiveBlock)?.replaceAll(" "," ")||"",A=B.trim();if(A==="---"||A==="***"||A==="___")return i.createElement(E,{flexDirection:"column",paddingX:1,width:"100%",marginY:0},i.createElement(E,{borderStyle:"single",borderTop:!0,borderBottom:!1,borderLeft:!1,borderRight:!1,width:"100%",borderColor:r.borderMuted}));let W=A.match(Wc);if(W){let Y=W[1].length,j=W[2],ue=["yellow",r.secondary||"magenta",r.info||"cyan","green","blue",r.text][Y-1]||r.text;return i.createElement(E,{flexDirection:"column",paddingX:1,width:"100%",marginTop:0,marginBottom:0},i.createElement(ie,{bold:!0,color:ue,underline:!0},i.createElement(Jt,{text:j,color:ue,theme:p})))}if(A.startsWith(">")){let Y=A.replace(/^>\s*/,"");return i.createElement(E,{flexDirection:"column",paddingX:1,width:"100%"},i.createElement(E,{borderStyle:"bold",borderLeft:!0,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:r.borderMuted,paddingLeft:1,marginY:0},i.createElement(Jt,{text:Y,color:r.textMuted,italic:!0,theme:p})))}let X=/^[\*\-\+]\s/.test(A),_=/^\d+\.\s/.test(A);if(X||_){let Y=X?" \u2022 ":A.match(/^\d+\.\s/)[0],j=A.replace(/^[\*\-\+\d+\.]+\s*/,"");return i.createElement(E,{flexDirection:"row",paddingX:1,width:"100%"},i.createElement(ie,{color:r.info||r.textMuted},Y),i.createElement(E,{flexGrow:1},i.createElement(Jt,{text:j,color:r.text,theme:p})))}return i.createElement(E,{flexDirection:"column",paddingX:1,width:"100%"},i.createElement(Jt,{text:B,color:r.text,theme:p}))}if(b==="table-header"||b==="table-row"){let B=b==="table-header",A=r.codeText||r.secondary||r.info||"cyan",W=t.colHeaders||[],X=B?W:t.cells||[],_=Math.max(1,t.colCount||W.length||X.length||1),Y=Array.from({length:_},(Me,xe)=>X[xe]||""),j=Math.max(20,(g||80)-8),le=_>=4,ue=/^(#|no\.?|num\.?|status|state|type|ok|done|✔|✘|active)$/i,ne=[],H=0,pe=0;for(let Me=0;Me<_;Me++){let xe=(W[Me]||"").trim();if(le&&(ue.test(xe)||xe==="#")){let ye=Math.max(xe.length+4,8);ne.push(ye),H+=ye}else ne.push(null),pe++}let Le=Math.max(pe*12,j-H),Pe=pe>0?Math.max(10,Math.floor(Le/pe)):10;for(let Me=0;Me<_;Me++)ne[Me]===null&&(ne[Me]=Pe);let rt=ne.reduce((Me,xe)=>Me+xe,0);return B?i.createElement(E,{flexDirection:"column",paddingX:1,width:"100%",marginTop:0,marginBottom:1},i.createElement(E,{flexDirection:"row",borderStyle:"single",borderBottom:!0,borderTop:!1,borderLeft:!1,borderRight:!1,borderColor:r.borderMuted,paddingBottom:0,width:rt},W.map((Me,xe)=>{let ye=ne[xe]||6;return i.createElement(E,{key:xe,width:ye,paddingRight:1,flexDirection:"column"},i.createElement(Jt,{text:At(Me,Math.max(2,ye-1)),color:A,theme:p}))}))):i.createElement(E,{flexDirection:"row",paddingX:1,width:"100%",marginBottom:1},Y.map((Me,xe)=>{let ye=ne[xe]||6;return i.createElement(E,{key:xe,width:ye,paddingRight:1,flexDirection:"column"},i.createElement(Jt,{text:At(Me,Math.max(2,ye-1)),color:r.text,theme:p}))}))}if(b==="table-close")return i.createElement(E,{height:0});if(b==="table")return i.createElement(E,{flexDirection:"column",paddingX:1,width:"100%"},i.createElement(Ta,{buffer:C.split(`
41
- `),terminalWidth:g,theme:p}));if(b==="diff-line"){let{isFirstLine:B,isLastLine:A}=t,W=(X=!1)=>i.createElement(E,{backgroundColor:r.codeBg,paddingX:1,width:g,marginBottom:X?1:0},i.createElement(E,{width:3,flexShrink:0}),i.createElement(E,{width:1,flexShrink:0,marginLeft:1}),i.createElement(E,{flexGrow:1,marginLeft:1},i.createElement(ie,null," ")));return i.createElement(E,{flexDirection:"column"},B&&W(!1),i.createElement(ya,{line:C,pairContent:t.pairContent,parentText:void 0,columns:g,theme:p}),A&&W(!0))}if(b==="code-fence-open"){let B={paddingLeft:2,width:"100%"};return i.createElement(E,{flexDirection:"column",marginTop:0,marginBottom:0,width:"100%"},i.createElement(E,{flexDirection:"row",...B},i.createElement(ie,null," ")),i.createElement(E,{flexDirection:"row",...B},i.createElement(ie,{color:"gray",bold:!0},"\u25B6_ ",(C||"TEXT").toUpperCase())))}if(b==="code-line"){let{lineNum:B,lang:A}=t,W=g-12,X=(C||"").replaceAll(" "," "),Y=At(X,Math.max(10,W)).split(`
42
- `);return i.createElement(E,{flexDirection:"column",width:"100%"},Y.map((j,le)=>i.createElement(E,{key:le,flexDirection:"row",borderColor:r.codeBorder,paddingLeft:2,width:"100%"},i.createElement(E,{width:5,flexShrink:0},i.createElement(ie,{color:"gray",dimColor:!0},le===0?String(B).padStart(4," ")+" ":" ")),i.createElement(E,{flexGrow:1},vt(j,A,r.text)))))}if(b==="code-fence-close")return i.createElement(E,{flexDirection:"row",paddingLeft:2,marginBottom:1,width:"100%"},i.createElement(ie,null," "));if(b==="write-header")return i.createElement(E,{flexDirection:"column",paddingX:1,width:g},i.createElement(zn,{text:C,columns:g,theme:p}));if(b==="write-line"){let{gutterWidth:B,lineNum:A,isFirstLine:W,isLastLine:X,extension:_,wrappedLines:Y}=t,j=(le=!1)=>i.createElement(E,{flexDirection:"row",width:g,borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:r.codeBorder,paddingLeft:2,paddingRight:0,backgroundColor:r.codeBg,marginBottom:le?1:0},i.createElement(E,{width:B+2,flexShrink:0},i.createElement(ie,null," ".repeat(B+2))),i.createElement(E,{flexGrow:1},i.createElement(ie,null," ")));return i.createElement(E,{flexDirection:"column"},W&&j(!1),i.createElement(E,{flexDirection:"row",width:g,borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:r.codeBorder,paddingLeft:2,paddingRight:0,backgroundColor:r.codeBg},i.createElement(E,{width:B+2,flexShrink:0},i.createElement(ie,{color:"gray",dimColor:!0},String(A).padStart(B," ")," ")),i.createElement(E,{flexGrow:1,flexDirection:"column"},(Y||[C]).map((le,ue)=>i.createElement(E,{key:ue},vt((le||"").replaceAll(" "," "),_,r.text))))),X&&j(!0))}return b==="write-footer"?i.createElement(E,{flexDirection:"column",paddingX:1,width:g,marginTop:1,marginBottom:1},i.createElement(zn,{text:C,columns:g,theme:p})):b==="worked-duration"?i.createElement(E,{marginTop:1,marginBottom:2,paddingX:1,width:"100%"},i.createElement(ie,{color:r.textMuted},"["),i.createElement(ie,{color:r.textMuted},"Worked for ",i.createElement(ie,{bold:!0,color:r.text},ls(F))),i.createElement(ie,{color:r.textMuted},"]")):null}),nm=i.memo(({messages:t,showFullThinking:g,columns:d=80,aiProvider:S,version:w,theme:p="Dark"})=>i.createElement(E,{flexDirection:"column",width:"100%"},t.map((r,y)=>i.createElement(Ca,{key:r.id||y,msg:r,showFullThinking:g,columns:d,aiProvider:S,version:w,theme:p}))));import Pt from"react";import{Box as nn,Text as Lo}from"ink";import{useState as Sr,useEffect as vr,useRef as cs}from"react";var Br=null;function Ma(){Br&&Br()}var Ed=t=>{if(t<=370)return"#00a564";if(t>=5e3)return"#ff0000";let g=[{t:370,r:0,g:165,b:100},{t:550,r:40,g:195,b:80},{t:800,r:120,g:220,b:50},{t:1100,r:190,g:225,b:20},{t:1500,r:250,g:210,b:15},{t:2e3,r:255,g:170,b:0},{t:2800,r:255,g:110,b:0},{t:3800,r:255,g:50,b:0},{t:5e3,r:255,g:0,b:0}];for(let d=0;d<g.length-1;d++){let S=g[d],w=g[d+1];if(t>=S.t&&t<=w.t){let p=(t-S.t)/(w.t-S.t);p=p*p*(3-2*p);let r=Math.round(S.r+(w.r-S.r)*p),y=Math.round(S.g+(w.g-S.g)*p),b=Math.round(S.b+(w.b-S.b)*p);return`#${((1<<24)+(r<<16)+(y<<8)+b).toString(16).slice(1)}`}}return"#ff0000"},Dd=Pt.memo(({mode:t,thinkingLevel:g,tokens:d="0.0k",tokensTotal:S="0.0k",cachedTokens:w=0,promptTokens:p=0,chatCacheTokenLatest:r=0,cacheCalculateMode:y="Session",chatId:b="NEW-SESSION",isMemoryEnabled:C=!0,apiTier:L="Free",aiProvider:F="Google",activeModel:B="",isProcessing:A=!1,lastChunkTime:W=0,theme:X="Dark",wps:_=0,showTPMEstimate:Y=!1})=>{let j=xt(X),le="",[ue,ne]=Sr(0),[H,pe]=Sr(0),[Le,Pe]=Sr("MB"),[rt,Me]=Sr("green"),[xe,ye]=Sr(0),Mt=cs([]),He=cs(370),ke=cs([]),Te=cs(W);vr(()=>{Te.current=W},[W]),vr(()=>{if(!A){ke.current=[];return}if(_>0){let me=ke.current;me.push(_),me.length>3&&me.shift()}},[A,_,W]),vr(()=>{if(!A){ye(0);return}let me=setInterval(()=>{let be=Te.current,Z=be>0?Date.now()-be:0;if(be>0&&Z>=1e3)ke.current=[],ye(0);else if(be>0&&Z>500){ke.current.length>0&&ke.current.shift();let fe=ke.current;if(fe.length>0){let q=fe.reduce((Ye,$e)=>Ye+$e,0);ye(Math.round(q/fe.length))}else ye(0)}else{let fe=ke.current;if(fe.length>0){let q=fe.reduce((Ye,$e)=>Ye+$e,0);ye(Math.round(q/fe.length))}else _>0&&ye(Math.round(_))}},750);return()=>clearInterval(me)},[A]),vr(()=>{if(!A){Mt.current=[];return}if(W>0){let Z=Mt.current;(Z.length===0||Z[Z.length-1]!==W)&&(Z.push(W),Z.length>10&&Z.shift())}let me=()=>{if(!W){Me("#00a564");return}let Z=Mt.current,fe=0;if(Z.length>1){let st=0;for(let qe=1;qe<Z.length;qe++)st+=Z[qe]-Z[qe-1];fe=st/(Z.length-1)}let q=Date.now()-W,$e=q>=2500,Tt=!$e&&fe>0?Math.min(q,fe*3):q,ct=Math.max(fe,Tt),wt=$e?.4:.2;He.current=He.current*(1-wt)+ct*wt,Me(Ed(He.current))};me();let be=setInterval(me,100);return()=>clearInterval(be)},[A,W]);let Q=()=>{let me=process.memoryUsage(),be=me.heapTotal/(1024*1024)>=1024,Z=be?"GB":"MB",fe=(q,Ye)=>{let $e=q/(1048576*(Ye?1024:1));return Ye?parseFloat($e.toFixed(2)):Math.round($e)};Pe(Z),pe(fe(me.heapTotal,be)),ne(fe(me.heapUsed,be))};return vr(()=>{Br=Q,Q();let me=setInterval(()=>{Q()},6e4);return()=>{clearInterval(me),Br===Q&&(Br=null)}},[]),Pt.createElement(nn,{flexDirection:"row",justifyContent:"space-between",paddingX:1,width:"100%"},Pt.createElement(nn,null,Pt.createElement(nn,{marginRight:1},Pt.createElement(Lo,{color:j.textMuted},t.toLowerCase()==="flow"?"Studio":t.toLowerCase()==="icu"?"Computer Use":t.toLowerCase()==="flux"?"Workspace":"Omni")),Pt.createElement(Lo,{color:j.textMuted,dimColor:!0},"\u2503 "),Pt.createElement(nn,null,Pt.createElement(Lo,{color:j.text,italic:!0},Xl(process.cwd(),35)))),Pt.createElement(nn,null,A&&!Y?Pt.createElement(nn,null,Pt.createElement(Lo,{color:rt},"\u25CF ")):null,A&&Y&&Pt.createElement(Pt.Fragment,null,Pt.createElement(Lo,{color:j.textMuted},"~",xe," tok/s"),Pt.createElement(Lo,{color:j.textMuted,dimColor:!0}," \u2503")),d>0&&Pt.createElement(Pt.Fragment,null,Pt.createElement(nn,{marginX:1},Pt.createElement(Lo,{color:j.text},Lt(S)," tok",(()=>{let me=0;if(y==="Current")me=typeof r=="number"?r:0;else{let be=typeof p=="number"?p:0,Z=typeof w=="number"?w:0;me=be>0?Z/be*100:0}return me<1?null:Pt.createElement(Lo,{color:j.success||"green",dimColor:!0}," [",me.toFixed(0),"% cached]")})())),Pt.createElement(Lo,{color:j.textMuted,dimColor:!0},"\u2503")),Pt.createElement(nn,{marginLeft:1},Pt.createElement(Lo,{color:j.textMuted,bold:!0},ue," ",Le))))}),Sa=Dd;import ft,{useState as ds,useMemo as Id,useEffect as va}from"react";import{Box as Zt,Text as Rt,useInput as kd}from"ink";import Ad from"ink-select-input";var Ld=({label:t,isSelected:g,theme:d="Dark"})=>{let S=xt(d),w=t==="Cancel"||t==="Back"||t.toLowerCase().includes("exit")||t.toLowerCase().includes("back");return ft.createElement(Zt,{marginTop:w?1:0,backgroundColor:g?S.highlightBg:void 0,paddingX:1,width:"100%"},ft.createElement(Rt,{color:g?S.text:S.textMuted,bold:g},g?"\u276F ":" ",t))},Pd=8;function Ut({title:t,subtitle:g,items:d=[],onSelect:S,theme:w="Dark",searchable:p=!1,maxVisible:r=Pd}){let y=xt(w),[b,C]=ds(""),[L,F]=ds(0),[B,A]=ds("list"),W=Id(()=>{if(!p||!b.trim())return d;let ue=b.toLowerCase().trim();return d.filter(ne=>ne.label&&ne.label.toLowerCase().includes(ue))},[d,b,p]);va(()=>{F(0)},[b]);let[X,_]=ds(0);va(()=>{_(ue=>W.length<=r?0:L<ue?L:L>=ue+r?L-r+1:ue)},[L,W.length,r]),kd((ue,ne)=>{if(p){if(ne.upArrow){A("list"),F(H=>W.length===0?0:H>0?H-1:W.length-1);return}if(ne.downArrow){A("list"),F(H=>W.length===0?0:H<W.length-1?H+1:0);return}if(ne.return){W.length>0&&W[L]&&S(W[L]);return}if(ne.escape){if(b)C(""),A("list"),F(0);else{let H=d.find(pe=>pe.value==="Back"||pe.label==="Back"||pe.value==="Cancel"||pe.label==="Cancel");H&&S(H)}return}if(ne.backspace||ne.delete){A("search"),C(H=>H.slice(0,-1));return}if(ue&&!ne.ctrl&&!ne.meta&&!ne.tab){A("search"),C(H=>H+ue);return}}},{isActive:p});let Y=W.length,j=X;Y<=r?j=0:j=Math.max(0,Math.min(X,Y-r));let le=W.slice(j,j+r);return p?ft.createElement(Zt,{flexDirection:"column",borderStyle:"round",borderColor:y.borderMuted,padding:0,marginTop:0,flexShrink:0,width:"100%"},ft.createElement(Zt,{paddingX:1,paddingY:0,marginBottom:0,flexDirection:"row",justifyContent:"space-between"},t?ft.createElement(Rt,{color:y.text,bold:!0},typeof t=="string"?t.toUpperCase():t):ft.createElement(Zt,null),Y>0&&ft.createElement(Rt,{color:y.textMuted},L+1,"/",Y)),g&&ft.createElement(Zt,{paddingX:1,marginBottom:0},ft.createElement(Rt,{color:y.textMuted,italic:!0}," ",g)),ft.createElement(Zt,{paddingX:1,marginTop:1,marginBottom:1,flexDirection:"row"},ft.createElement(Rt,{color:B==="search"?y.primary||"cyan":y.textMuted,bold:B==="search"},"\u{1F50D} Search:"),ft.createElement(Rt,{color:y.text,bold:!0}," ",b),B==="search"?ft.createElement(Rt,{color:y.primary||"cyan"},"\u2588"):b?null:ft.createElement(Rt,{color:y.textMuted,italic:!0}," (type to search...)")),ft.createElement(Zt,{flexDirection:"column",width:"100%"},W.length===0?ft.createElement(Zt,{paddingX:1,marginY:0},ft.createElement(Rt,{color:y.warning||"yellow",italic:!0}," No matching items found")):le.map((ue,ne)=>{let H=j+ne,pe=H===L,Le=ue.label==="Cancel"||ue.label==="Back"||ue.label.toLowerCase().includes("exit")||ue.label.toLowerCase().includes("back");return ft.createElement(Zt,{key:ue.value??ue.label??H,marginTop:Le?1:0,backgroundColor:pe?y.highlightBg:void 0,paddingX:1,width:"100%"},ft.createElement(Rt,{color:pe?y.text:y.textMuted,bold:pe},pe?"\u276F ":" ",ue.label))})),ft.createElement(Zt,{paddingX:1,marginTop:1},ft.createElement(Rt,{color:y.textMuted,italic:!0},B==="search"?"(Type letters to search \u2022 Arrows for list mode \u2022 Enter to select)":"(Arrows to navigate \u2022 Type letters to search \u2022 Enter to select)"))):ft.createElement(Zt,{flexDirection:"column",borderStyle:"round",borderColor:y.borderMuted,padding:0,marginTop:0,flexShrink:0,width:"100%"},t&&ft.createElement(Zt,{paddingX:1,paddingY:0,marginBottom:g?0:1,flexDirection:"row",justifyContent:"space-between"},ft.createElement(Rt,{color:y.text,bold:!0},typeof t=="string"?t.toUpperCase():t),d.length>r&&ft.createElement(Rt,{color:y.textMuted,italic:!0},d.length," options")),g&&ft.createElement(Zt,{paddingX:1,marginBottom:1},ft.createElement(Rt,{color:y.textMuted,italic:!0}," ",g)),ft.createElement(Zt,{flexDirection:"column",width:"100%"},ft.createElement(Ad,{items:d,onSelect:S,limit:r,itemComponent:ue=>ft.createElement(Ld,{...ue,theme:w}),indicatorComponent:()=>null})),ft.createElement(Zt,{paddingX:1,marginTop:1},ft.createElement(Rt,{color:y.textMuted,italic:!0},"(Arrows to select \u2022 Enter to confirm)")))}import D,{useState as Xt,useEffect as Er}from"react";import{Box as Fe,Text as ee,useInput as Od}from"ink";import Nd from"ink-text-input";import Fd from"v8";import Ba from"os";var Po=[...Object.keys(Kl),"Mystery"],Oo=[{id:"appearance",label:"Appearance",desc:"Customize UI theme & rendering options"},{id:"memory",label:"Personalization",desc:"Manage system context & agent's memory"},{id:"secondaryModels",label:"Secondary Models",desc:"Sub-agents & auto-completion models"},{id:"other",label:"Miscellaneous",desc:"Miscellaneous preferences"},{id:"providers",label:"Providers",desc:"Configure AI models"},{id:"security",label:"Security",desc:"Configure permissions & data safety"},{id:"updater",label:"Updater",desc:"Manage application updates"},{id:"exit",label:"Exit Settings",desc:"Return to chat view"}],Ea=t=>{let g=t.autoApproveCommands||"",d=t.autoDisallowCommands||"",S=t.alwaysAskCommands||"",w=t.autoExec===!1&&t.allowExternalAccess===!1&&t.networkAccess===!1&&g===""&&d==="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c"&&S==="killall, pkill, taskkill, shutdown, reboot, init 0, init 6, Stop-Process, Stop-Service, mv /*, move c:\\*, chmod 000, chmod -R 777, chown, icacls, netsh advfirewall, iptables -F, ufw disable, git reset --hard, git clean -fd, npm r, npm uninstall"&&t.autoApproveGit===!1,p=t.autoExec===!0&&t.allowExternalAccess===!1&&t.networkAccess!==!1&&g==="ls, dir, cat, type, echo, pwd, cd, git status, git log, git diff, git branch, git show, help, mkdir, touch, md, whoami, hostname, ps, Get-Process, date, time, mkdir"&&d==="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c"&&S==="killall, pkill, taskkill, Stop-Process, mv /*, move c:\\*, chmod 000, chmod -R 777, chown, icacls, shutdown, reboot, init 0, init 6, git reset --hard, git clean -fd, npm r, npm uninstall"&&t.autoApproveGit===!1,r=t.autoExec===!0&&t.allowExternalAccess===!0&&t.networkAccess!==!1&&g==="ls, dir, cat, type, echo, pwd, cd, git status, git log, git diff, git branch, git show, help, mkdir, touch, md, whoami, hostname, ps, Get-Process, date, time, mkdir"&&d===""&&S==="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c"&&t.autoApproveGit===!0;return w?"Strict":p?"Balanced":r?"Autonomous":t.sandboxPreset||"Custom"},Dr=t=>!t||t.trim()===""?"None":t.length>40?t.substring(0,40)+"...":t;function us({systemSettings:t,setSystemSettings:g,apiTier:d,setActiveView:S,setInputConfig:w,saveSettings:p,quotas:r,setMessages:y,aiProvider:b,autoCompletion:C,setAutoCompletion:L,profileData:F,setProfileData:B,initialSelectingTheme:A=!1,onCloseTheme:W=null,setProviderReturnView:X=null,setApiKey:_=null,initAI:Y=null}){let j=t.theme==="Chaos"||t.theme==="Mystery"?"Mystery":t.theme||"Dark",le=Po.indexOf(j),[ue,ne]=Xt("categories"),[H,pe]=Xt(0),[Le,Pe]=Xt(0),[rt,Me]=Xt("Sandbox"),[xe,ye]=Xt(null),[Mt,He]=Xt(""),[ke,Te]=Xt(A),[Q,me]=Xt(le>=0?le:0),[be,Z]=Xt(t.theme||"Dark"),[fe,q]=Xt(!1),[Ye,$e]=Xt("subAgent"),[Tt,ct]=Xt(0),[wt,st]=Xt(0),[qe,se]=Xt(""),[Be,ut]=Xt("list"),[mt,_e]=Xt({});Er(()=>{(async()=>{let T=["Google","DeepSeek","OpenRouter","NVIDIA","Mistral","Ollama","InferX","SenseNova","AIHubMix","Poolside","9router","ExpLabs","TokenHarbor","Infron","APInex","xKiro","c_openai"],k={};for(let ve of T)try{await on(ve,{silent:!0})&&(k[ve]=!0)}catch{}_e(k)})()},[]);let Bt=D.useMemo(()=>{let ae=["Google","DeepSeek","OpenRouter","NVIDIA","Mistral","Ollama","InferX","SenseNova","AIHubMix","Poolside","9router","ExpLabs","TokenHarbor","Infron","APInex","xKiro","c_openai"],k=!!(process.env.SUBAGENT_MODEL&&process.env.SUBAGENT_MODEL.trim())?`ENV (${process.env.SUBAGENT_MODEL.trim()})`:"ENV",ve=[{label:"Default (use the current model)",value:"Default",isHeader:!1},{label:k,value:"ENV",isHeader:!1}],Ne=r?.providerTiers?.[b]||d||"Free",at=tn(b,Ne,t?.customOpenAIBaseUrl)||[];at.length>0&&(ve.push({label:`\u2500\u2500 ${b.toUpperCase()}${Ne!=="Free"?` (${Ne})`:""} \u2500\u2500`,isHeader:!0}),at.forEach(dt=>{let et=typeof dt=="string"?dt:dt.cmd||dt.name||dt.id||String(dt);et&&!et.trim().startsWith("---")&&!et.startsWith(`
43
- ---`)&&ve.push({label:et,value:et,isHeader:!1,provider:b})}));for(let dt of ae)if(dt!==b&&mt[dt]){let et=r?.providerTiers?.[dt]||"Free",so=tn(dt,et)||[];so.length>0&&(ve.push({label:`\u2500\u2500 ${dt.toUpperCase()}${et!=="Free"?` (${et})`:""} \u2500\u2500`,isHeader:!0}),so.forEach(Ke=>{let Ot=typeof Ke=="string"?Ke:Ke.cmd||Ke.name||Ke.id||String(Ke);Ot&&!Ot.trim().startsWith("---")&&!Ot.startsWith(`
44
- ---`)&&ve.push({label:Ot,value:Ot,isHeader:!1,provider:dt})}))}return ve},[b,d,r,mt]),Xe=D.useMemo(()=>{if(!qe.trim())return Bt;let ae=qe.trim().toLowerCase(),T=[],k=null;for(let ve of Bt)ve.isHeader?k=ve:(ve.label.toLowerCase().includes(ae)||ve.value&&ve.value.toLowerCase().includes(ae))&&(k&&!T.includes(k)&&T.push(k),T.push(ve));return T},[Bt,qe]);Er(()=>{if(fe){let ae=Xe.findIndex(T=>!T.isHeader);ct(ae>=0?ae:0),st(0)}},[qe]),Er(()=>{if(fe){if(Xe.length===0){ct(0),st(0);return}if(Tt>=Xe.length||Xe[Tt]?.isHeader){let ae=Xe.findIndex(T=>!T.isHeader);ct(ae>=0?ae:0)}}},[Xe,fe]);let[ro,N]=Xt(0),[Qo,er]=Xt(0),[Ar,dn]=Xt("MB"),[Lr,un]=Xt(!1);Er(()=>{let ae=!1;return import("./exec_command-6V5SM6WI.js").then(T=>{ae||un(!!T.isPtyAvailable)}).catch(()=>{}),()=>{ae=!0}},[]),Er(()=>{let ae=Fd.getHeapStatistics().heap_size_limit,T=ae>=1024*1024*1024,k=T?"GB":"MB",ve=T?1024*1024*1024:1024*1024;er(parseFloat((ae/ve).toFixed(2))),dn(k);let Ne=()=>{let so=process.memoryUsage().rss/ve,Ke=T?parseFloat(so.toFixed(2)):Math.round(so);N(Ke)};Ne();let at=setInterval(()=>{Ne()},3e4);return()=>clearInterval(at)},[]);let ys=ae=>{switch(ae){case"providers":{let T=[{label:"Current Provider",value:"aiProvider",status:b==="c_openai"?"Custom (OpenAI)":b}];return b==="Ollama"&&T.push({label:"Endpoint",value:"ollamaEndpoint",status:t.ollamaEndpoint||"Cloud"}),(b==="c_openai"||b==="Custom (OpenAI)")&&(T.push({label:"Base URL",value:"customOpenAIBaseUrl",status:t.customOpenAIBaseUrl||"Not Configured"}),T.push({label:"API Key (if needed)",value:"customOpenAIKey",status:mt.c_openai?"Set":"None"})),T}case"appearance":return[{label:"Theme",value:"theme",status:t.theme||"Dark"},{label:"Loading Phrases",value:"loadingPhrases",status:t.loadingPhrases!==!1?"ON":"OFF"},{label:"Progressive Rendering [EXPERIMENTAL]",value:"progressiveRendering",status:t.progressiveRendering?"ON":"OFF"},{label:"Show TPM Estimate",value:"showTPMEstimate",status:t.showTPMEstimate?"ON":"OFF"},{label:"Verbose Thinking",value:"preserveThinking",status:t.preserveThinking!==!1?"ON":"OFF"}];case"memory":return[{label:"Base Personality",value:"profilePreset",status:F?.preset||"Default"},{label:"Nickname",value:"profileNickname",status:F?.nickname||"None"},{label:"Custom Instructions",value:"profileInstructions",status:Dr(F?.instructions)},{label:"Toggle Memory [Legacy]",value:"memory",status:t.memory?"ON":"OFF"}];case"security":return[{label:"Sandbox Preset",value:"sandboxPreset",status:Ea(t),section:"Sandbox"},{label:"YOLO Mode",value:"autoExec",status:t.autoExec?"ON":"OFF",section:"Sandbox"},{label:"External Workspace Access",value:"externalAccess",status:t.allowExternalAccess?"ON":"OFF",section:"Sandbox"},{label:"Network Access (Terminal)",value:"networkAccess",status:t.networkAccess!==!1?"ON":"OFF",section:"Sandbox"},{label:"Always Ask Commands",value:"alwaysAsk",status:Dr(t.alwaysAskCommands),section:"Sandbox"},{label:"Always Ask Files/Paths",value:"alwaysAskFiles",status:Dr(t.alwaysAskFiles||".env, .env.*, *.env"),section:"Sandbox"},{label:"Auto Approve Commands",value:"autoApprove",status:Dr(t.autoApproveCommands),section:"Sandbox"},{label:"Auto Disapprove Commands",value:"autoDisallow",status:Dr(t.autoDisallowCommands),section:"Sandbox"},{label:"Auto Approve Git Commits",value:"autoApproveGit",status:t.autoApproveGit?"ON":"OFF",section:"Sandbox"},{label:"Advanced Recovery [EXPERIMENTAL]",value:"advanceRollback",status:t.advanceRollback?"ON":"OFF",section:"Other"},{label:"Auto-Delete History",value:"autoDelete",status:t.autoDeleteHistory||"30d",section:"Other"},{label:"Save AppData Externally",value:"externalData",status:t.useExternalData?"ON":"OFF",section:"Other"},{label:"Agent Clipboard Context",value:"clipboardContext",status:t.clipboardContext?"ON":"OFF",section:"Other"}].filter(ve=>ve.section.toLowerCase()===rt.toLowerCase());case"updater":return[{label:"Auto-Update",value:"autoUpdate",status:t.autoUpdate?"ON":"OFF"},{label:"Preferred Package Manager",value:"updateManager",status:(t.updateManager||"npm")==="custom"?"Custom":(t.updateManager||"npm").toUpperCase()}];case"secondaryModels":return[{label:"Sub-Agents",value:"subAgents",status:t.subAgents!==!1?"ON":"OFF"},{label:"Sub-Agent Model",value:"subAgentModel",status:t.CustomSubAgent&&t.SubAgentModel?t.SubAgentModel:"Default"},{label:"Enable Auto-Completion",value:"autoCompletionEnabled",status:C?.enabled?"ON":"OFF"},{label:"Auto-Completion Model",value:"autoCompletionModel",status:C?.model&&C.model!=="Default"?C.model:"Default"}];case"other":return[{label:"Directory Tree Design",value:"indentationTree",status:t.indentationTree!==!1?"Modern":"Legacy"},{label:"Compact Large Tool Results",value:"compressToolResults",status:t.compressToolResults?"ON":"OFF"},{label:"Auto Truncate Results",value:"autoTruncateResults",status:t.autoTruncateResults?"ON":"OFF"},{label:"Agent Finish Notification",value:"agentFinishSound",status:t.agentFinishSound?"ON":"OFF"},{label:"Image History for CU",value:"imageHistoryCU",status:t.imageHistoryCU||"Standard"},{label:"Context Length",value:"contextLength",status:t.contextLength||"256k"},{label:"Keep Reasoning Context",value:"keepReasoningContext",status:t.keepReasoningContext?"ON":"OFF"},{label:"Auto Exclude Metadata",value:"autoExcludeMetadata",status:t.autoExcludeMetadata?"ON":"OFF"},{label:"Disable Todo",value:"disableTodo",status:t.disableTodo?"ON":"OFF"},...process.platform==="win32"?[{label:"Prefer Bash",value:"preferBash",status:t.preferBash!==!1?"ON":"OFF"}]:[],{label:"Cache Calculate Mode",value:"cacheCalculateMode",status:t.cacheCalculateMode||"Session"}];default:return[]}},je=Oo[H].id,Gt=ys(je);Od((ae,T)=>{if(fe){if(T.tab){ut(k=>k==="search"?"list":"search");return}if(Be==="search"){T.escape?q(!1):T.downArrow||T.return?ut("list"):T.backspace||T.delete?se(k=>k.slice(0,-1)):ae&&!T.ctrl&&!T.meta&&ae.length===1&&se(k=>k+ae);return}if(T.upArrow)ct(k=>{if(Xe.length===0)return 0;let ve=(k-1+Xe.length)%Xe.length,Ne=0;for(;Xe[ve]?.isHeader&&Ne<Xe.length;)ve=(ve-1+Xe.length)%Xe.length,Ne++;return ve});else if(T.downArrow)ct(k=>{if(Xe.length===0)return 0;let ve=(k+1)%Xe.length,Ne=0;for(;Xe[ve]?.isHeader&&Ne<Xe.length;)ve=(ve+1)%Xe.length,Ne++;return ve});else if(T.return){let k=Xe[Tt];if(k&&!k.isHeader){let ve=k.value==="Default";Ye==="autoCompletion"?L(Ne=>{let at=ve?"":k.provider||"",dt={...Ne,model:k.value,provider:at,baseUrl:ve?"":Fl[at]||""};return p({autoCompletion:dt,apiTier:d,quotas:r}),dt}):g(Ne=>{let at={...Ne,CustomSubAgent:!ve,SubAgentModel:k.value,SubAgentProvider:ve?"":k.provider||""};return p({systemSettings:at,apiTier:d,quotas:r}),at}),q(!1)}}else T.escape?q(!1):ae&&!T.ctrl&&!T.meta&&ae.length===1&&(se(k=>k+ae),ut("search"));return}if(ke){if(T.upArrow){let k=(Q-1+Po.length)%Po.length;me(k)}else if(T.downArrow){let k=(Q+1)%Po.length;me(k)}else if(T.return){let k=Po[Q];g(ve=>{let Ne={...ve,theme:k};return p({systemSettings:Ne,apiTier:d,quotas:r}),Ne}),W?W():Te(!1)}else T.escape&&(W?W():Te(!1));return}if(xe){T.escape&&ye(null);return}if(ue==="categories")T.upArrow?pe(k=>(k-1+Oo.length)%Oo.length):T.downArrow?pe(k=>(k+1)%Oo.length):T.return||T.rightArrow?Oo[H].id==="exit"?S("chat"):(ne("items"),Pe(0)):T.escape&&S("chat");else if(ue==="items"){if(je==="security"&&(T.tab||ae===" ")){Me(k=>k==="Sandbox"?"Other":"Sandbox"),Pe(0);return}if(T.upArrow)Pe(k=>(k-1+Gt.length)%Gt.length);else if(T.downArrow)Pe(k=>(k+1)%Gt.length);else if(T.leftArrow)je==="security"&&rt==="Other"?(Me("Sandbox"),Pe(0)):ne("categories");else if(T.rightArrow&&je==="security"&&rt==="Sandbox")Me("Other"),Pe(0);else if(T.escape)ne("categories");else if(T.return){let k=Gt[Le];Pr(k)}}});let Pr=ae=>{if(ae.value==="profilePreset"){let T=["Default","Sassy","Friendly","Playful","Efficient","Professional"],k=F?.preset||"Default",Ne=(T.indexOf(k)+1)%T.length,at=T[Ne>=0?Ne:0],dt={...F||{},preset:at};B&&B(dt),p({profileData:dt,systemSettings:t,apiTier:d,quotas:r})}else if(ae.value==="profileNickname")ye("profileNickname"),He(F?.nickname||"");else if(ae.value==="profileInstructions")ye("profileInstructions"),He(F?.instructions||"");else if(ae.value==="memory")g(T=>({...T,memory:!T.memory}));else if(ae.value==="sandboxPreset"){let T=Ea(t),k=["Autonomous","Balanced","Strict"],Ne=(k.indexOf(T)+1)%k.length,at=k[Ne];g(dt=>{let et={...dt,sandboxPreset:at};return at==="Strict"?(et.autoExec=!1,et.allowExternalAccess=!1,et.networkAccess=!1,et.autoApproveCommands="",et.autoDisallowCommands="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c",et.alwaysAskCommands="killall, pkill, taskkill, shutdown, reboot, init 0, init 6, Stop-Process, Stop-Service, mv /*, move c:\\*, chmod 000, chmod -R 777, chown, icacls, netsh advfirewall, iptables -F, ufw disable, git reset --hard, git clean -fd, npm r, npm uninstall",et.autoApproveGit=!1):at==="Balanced"?(et.autoExec=!0,et.allowExternalAccess=!1,et.networkAccess=!0,et.autoApproveCommands="ls, dir, cat, type, echo, pwd, cd, git status, git log, git diff, git branch, git show, help, mkdir, touch, md, whoami, hostname, ps, Get-Process, date, time",et.autoDisallowCommands="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c",et.alwaysAskCommands="killall, pkill, taskkill, Stop-Process, mv /*, move c:\\*, chmod 000, chmod -R 777, chown, icacls, shutdown, reboot, init 0, init 6, git reset --hard, git clean -fd, npm r, npm uninstall",et.autoApproveGit=!1):at==="Autonomous"&&(et.autoExec=!0,et.allowExternalAccess=!0,et.networkAccess=!0,et.autoApproveCommands="ls, dir, cat, type, echo, pwd, cd, git status, git log, git diff, git branch, git show, help, mkdir, touch, md, whoami, hostname, ps, Get-Process, date, time",et.autoDisallowCommands="",et.alwaysAskCommands="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c",et.autoApproveGit=!0),et})}else if(ae.value==="autoExec")t.autoExec?g(T=>({...T,autoExec:!1,sandboxPreset:"Custom"})):t.allowExternalAccess?S("doubleDanger"):S("autoExecDanger");else if(ae.value==="externalAccess")t.allowExternalAccess?g(T=>({...T,allowExternalAccess:!1,sandboxPreset:"Custom"})):t.autoExec?S("doubleDanger"):S("externalDanger");else if(ae.value==="networkAccess")g(T=>({...T,networkAccess:T.networkAccess===!1,sandboxPreset:"Custom"}));else if(ae.value==="alwaysAsk")ye("alwaysAskCommands"),He(t.alwaysAskCommands||"");else if(ae.value==="alwaysAskFiles")ye("alwaysAskFiles"),He(t.alwaysAskFiles||".env, .env.*, *.env");else if(ae.value==="autoApprove")ye("autoApproveCommands"),He(t.autoApproveCommands||"");else if(ae.value==="autoDisallow")ye("autoDisallowCommands"),He(t.autoDisallowCommands||"");else if(ae.value==="autoApproveGit")g(T=>({...T,autoApproveGit:!T.autoApproveGit,sandboxPreset:"Custom"}));else if(ae.value==="customOpenAIBaseUrl")ye("customOpenAIBaseUrl"),He(t.customOpenAIBaseUrl||"");else if(ae.value==="customOpenAIKey")ye("customOpenAIKey"),He("");else if(ae.value==="ollamaEndpoint")g(T=>{let k=T.ollamaEndpoint==="Local"?"Cloud":"Local",ve={...T,ollamaEndpoint:k};return p({systemSettings:ve,apiTier:d,quotas:r}),ve});else if(ae.value==="apiTier")S("apiTier");else if(ae.value==="aiProvider")X&&X("settings"),S("selectProvider");else if(ae.value==="advanceRollback")t.advanceRollback?g(T=>{let k={...T,advanceRollback:!1};return p({systemSettings:k,apiTier:d,quotas:r}),k}):S("advanceRollbackDanger");else if(ae.value==="autoDelete"){let T=["1d","7d","30d"],ve=(T.indexOf(t.autoDeleteHistory||"30d")+1)%T.length;g(Ne=>({...Ne,autoDeleteHistory:T[ve]}))}else if(ae.value==="autoUpdate")g(T=>({...T,autoUpdate:!T.autoUpdate}));else if(ae.value==="externalData")if(!t.useExternalData)w({label:"Enter absolute path for External AppData:",note:"All history, logs and secrets will be stored here. ~/.fluxflow/settings.json stays as anchor.",key:"externalDataPath",value:t.externalDataPath||""}),S("input");else{let T={...t,useExternalData:!1};g(T),p({systemSettings:T,apiTier:d,quotas:r}),y(k=>[...k,{id:Date.now(),role:"system",text:"[STORAGE RESET] Flux Flow will return to default ~/.fluxflow after restart."}]),S("chat")}else if(ae.value==="updateManager")S("updateManager");else if(ae.value==="parserDownload")S("parserDownload");else if(ae.value==="indentationTree")g(T=>{let k={...T,indentationTree:T.indentationTree===!1};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="compressToolResults")g(T=>{let k={...T,compressToolResults:!T.compressToolResults};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="autoTruncateResults")g(T=>{let k={...T,autoTruncateResults:!T.autoTruncateResults};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="agentFinishSound")g(T=>{let k={...T,agentFinishSound:!T.agentFinishSound};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="imageHistoryCU"){let T=["Low","Standard","Extended","Max"],ve=(T.indexOf(t.imageHistoryCU||"Standard")+1)%T.length;g(Ne=>{let at={...Ne,imageHistoryCU:T[ve]};return p({systemSettings:at,apiTier:d,quotas:r}),at})}else if(ae.value==="contextLength"){let T=["16k","32k","64k","128k","256k","512k","1M"],ve=(T.indexOf(t.contextLength||"256k")+1)%T.length;g(Ne=>{let at={...Ne,contextLength:T[ve]};return p({systemSettings:at,apiTier:d,quotas:r}),at})}else if(ae.value==="keepReasoningContext")g(T=>{let k={...T,keepReasoningContext:!T.keepReasoningContext};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="autoExcludeMetadata")g(T=>{let k={...T,autoExcludeMetadata:!T.autoExcludeMetadata};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="disableTodo")g(T=>{let k={...T,disableTodo:!T.disableTodo};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="preferBash")g(T=>{let k=T.preferBash!==!1,ve={...T,preferBash:!k};return p({systemSettings:ve,apiTier:d,quotas:r}),ve});else if(ae.value==="cacheCalculateMode"){let T=["Session","Current"],ve=(T.indexOf(t.cacheCalculateMode||"Session")+1)%T.length;g(Ne=>{let at={...Ne,cacheCalculateMode:T[ve]};return p({systemSettings:at,apiTier:d,quotas:r}),at})}else if(ae.value==="subAgents")g(T=>{let k={...T,subAgents:T.subAgents===!1};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="subAgentModel"){let T=t.CustomSubAgent&&t.SubAgentModel?t.SubAgentModel:"Default",k=Xe.findIndex(ve=>ve.value===T);ct(k>=0?k:0),$e("subAgent"),q(!0)}else if(ae.value==="autoCompletionEnabled")L(T=>{let k={...T,enabled:!T.enabled};return p({autoCompletion:k,apiTier:d,quotas:r}),k});else if(ae.value==="clipboardContext")g(T=>{let k={...T,clipboardContext:!T.clipboardContext};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="autoCompletionModel"){let T=C?.model||"Default",k=Xe.findIndex(ve=>ve.value===T);ct(k>=0?k:0),$e("autoCompletion"),q(!0)}else if(ae.value==="preserveThinking")g(T=>{let k={...T,preserveThinking:T.preserveThinking===!1};return ba(k.preserveThinking),p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="loadingPhrases")g(T=>{let k={...T,loadingPhrases:T.loadingPhrases===!1};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="progressiveRendering")g(T=>{let k={...T,progressiveRendering:!T.progressiveRendering};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="showTPMEstimate")g(T=>{let k={...T,showTPMEstimate:!T.showTPMEstimate};return p({systemSettings:k,apiTier:d,quotas:r}),k});else if(ae.value==="theme"){let T=t.theme==="Chaos"||t.theme==="Mystery"?"Mystery":t.theme||"Dark",k=Po.indexOf(T);me(k>=0?k:0),Z(t.theme||"Dark"),Te(!0)}},Se=xt(t.theme);if(fe){let ae=Ye==="autoCompletion"?C?.model||"Default":t.CustomSubAgent&&t.SubAgentModel?t.SubAgentModel:"Default",T=15,k=wt;Tt<k?k=Tt:Tt>=k+T&&(k=Tt-T+1),k=Math.max(0,Math.min(k,Math.max(0,Xe.length-T))),k!==wt&&st(k);let ve=Xe.slice(k,k+T);return D.createElement(Fe,{flexDirection:"column",borderStyle:"round",borderColor:Se.border,padding:1,width:"100%",minHeight:32},D.createElement(Fe,{marginBottom:1,flexDirection:"row",justifyContent:"space-between"},D.createElement(ee,{color:Se.text,bold:!0,underline:!0},Ye==="autoCompletion"?"Select Auto-Completion Model:":"Select Sub-Agent Model:"),Xe.length>0&&D.createElement(ee,{color:"gray"},Tt+1,"/",Xe.length)),D.createElement(Fe,{borderStyle:"single",borderColor:Be==="search"?Se.primary||"cyan":"gray",paddingX:1,marginBottom:1},D.createElement(ee,{color:Be==="search"?Se.primary||"cyan":"gray",bold:!0},"\u{1F50D} Search: "," "),D.createElement(ee,{color:Se.text},qe),Be==="search"&&D.createElement(ee,{color:Se.primary||"cyan"},"\u2588"),!qe&&Be!=="search"&&D.createElement(ee,{color:"gray",italic:!0},"(Press TAB or type to filter models...)")),D.createElement(Fe,{flexDirection:"column",flexGrow:1,height:T},ve.length>0?ve.map((Ne,at)=>{let dt=k+at;if(Ne.isHeader)return D.createElement(Fe,{key:`hdr-${dt}`,paddingX:1},D.createElement(ee,{color:"gray",bold:!0,underline:!0},Ne.label));let et=Tt===dt&&Be==="list",so=ae===Ne.value;return D.createElement(Fe,{key:`item-${Ne.value}-${dt}`,paddingX:1,backgroundColor:et?Se.highlightBg:void 0},D.createElement(ee,{color:et?Se.text:Se.textDim,bold:et},et?"\u276F ":" ",Ne.label,so?D.createElement(ee,{color:Se.primary||"cyan",italic:!0}," (active)"):""))}):D.createElement(Fe,{paddingX:1},D.createElement(ee,{color:"gray",italic:!0},'No models matching "',qe,'"'))),D.createElement(Fe,{paddingX:1,marginTop:1,flexDirection:"row",justifyContent:"space-between"},D.createElement(ee,{color:"gray",italic:!0},"TAB to switch search/list \u2022 \u25B2\u25BC Navigate \u2022 ENTER to Select \u2022 ESC to Cancel"),D.createElement(ee,{color:Be==="search"?Se.primary||"cyan":"gray",bold:!0},"[",Be.toUpperCase()," MODE]")))}if(ke){let ae=Po[Q],T=xt(ae);return D.createElement(Fe,{flexDirection:"column",borderStyle:"round",borderColor:T.border,padding:1,width:"100%",minHeight:32},D.createElement(Fe,{marginBottom:1},D.createElement(ee,{color:T.text,bold:!0},"Choose your color scheme:")),D.createElement(Fe,{flexDirection:"row",width:"100%",flexGrow:1},D.createElement(Fe,{flexDirection:"column",width:"30%",paddingRight:1},Po.map((k,ve)=>{let Ne=Q===ve,at=(t.theme||"Dark")===k,dt=k==="Forest Sprite"||k==="Spookfest";return D.createElement(Fe,{key:k,paddingX:0},D.createElement(ee,{color:Ne?T.text:T.textDim,bold:Ne},Ne?"> ":" ",k,dt&&D.createElement(ee,{color:Ne?T.success||"#52b788":"green",bold:!0}," \u2605"),at?D.createElement(ee,{color:T.primary||"cyan",italic:!0}," (saved)"):""))})),D.createElement(Fe,{flexDirection:"column",flexGrow:1,borderStyle:"round",borderColor:T.borderMuted,paddingX:2,paddingY:1,backgroundColor:T.cardBg},D.createElement(Fe,{marginBottom:1},D.createElement(ee,{color:T.secondary||"cyan",bold:!0},"> ","you: "),D.createElement(ee,{color:T.text},"add a greeting function")),D.createElement(Fe,{marginBottom:1},D.createElement(ee,{color:T.success||"green"}," Here's the change:")),D.createElement(Fe,{flexDirection:"column",marginLeft:2,marginBottom:1},D.createElement(ee,null,D.createElement(ee,{color:T.textDim},"3 "),vt(' import "fmt"',".go",void 0)),D.createElement(ee,{color:T.textDim},"4"),D.createElement(Fe,{backgroundColor:T.diffRemovalBg},D.createElement(ee,null,D.createElement(ee,{color:T.diffRemovalNum||T.diffRemovalText},"5 "),D.createElement(ee,{color:T.diffRemovalPrefix||T.diffRemovalText},"- "),vt("func ",".go",void 0),vt("main()",".go",void 0,T.diffRemovalHighlightBg),vt(" {",".go",void 0))),D.createElement(Fe,{backgroundColor:T.diffAdditionBg},D.createElement(ee,null,D.createElement(ee,{color:T.diffAdditionNum||T.diffAdditionText},"5 "),D.createElement(ee,{color:T.diffAdditionPrefix||T.diffAdditionText},"+ "),vt("func ",".go",void 0),vt("greet(name string)",".go",void 0,T.diffAdditionHighlightBg),vt(" {",".go",void 0))),D.createElement(Fe,{backgroundColor:T.diffAdditionBg},D.createElement(ee,null,D.createElement(ee,{color:T.diffAdditionNum||T.diffAdditionText},"6 "),D.createElement(ee,{color:T.diffAdditionPrefix||T.diffAdditionText},"+ "),D.createElement(ee,null," "),vt('fmt.Printf("Hello, %s!\\n", name)',".go",void 0,T.diffAdditionHighlightBg))),D.createElement(ee,null,"7 }")),D.createElement(Fe,{flexDirection:"column",marginTop:1,marginBottom:1},D.createElement(ee,{color:T.textDim},"\u25BE Thought Process"),D.createElement(ee,{color:T.textMuted}," I need to add a greeting function. I'll use fmt.Printf.")),D.createElement(Fe,{flexDirection:"column"},D.createElement(ee,null,D.createElement(ee,{color:T.warning||"yellow"},"\u2699 tool: "),D.createElement(ee,{color:T.text},"write_file main.go")),D.createElement(ee,null,D.createElement(ee,{color:T.accent||"magenta"},"\u29BF task: "),D.createElement(ee,{color:T.text},"Implementing greeting")),D.createElement(ee,null,D.createElement(ee,{color:T.danger||"red"},"X error: "),D.createElement(ee,{color:T.text},"compilation failed")),D.createElement(ee,null,D.createElement(ee,{color:T.warning||"yellow"},"\u26A0 warning: "),D.createElement(ee,{color:T.text},"deprecation warning")),D.createElement(ee,null,D.createElement(ee,{color:T.info||"blue"},"\u2192 link: "),D.createElement(ee,{color:T.info||"blue",underline:!0},"file:///path/to/main.go")),D.createElement(ee,null,D.createElement(ee,{color:T.accent||"magenta"},"\u2605 accent: "),D.createElement(ee,{color:T.text},"highlighted text")),D.createElement(ee,{color:T.textDim},"\xB7 dim: press Enter to continue")))),D.createElement(Fe,{paddingX:1,marginTop:1,flexDirection:"row",justifyContent:"space-between"},D.createElement(ee,{color:"gray",italic:!0},"\u25B2\u25BC Navigate \u2022 ENTER to Select \u2022 ESC to Cancel"),D.createElement(ee,{color:"gray"},"Previewing: ",Po[Q],Po[Q]==="Forest Sprite"?" \u2605":"")))}return D.createElement(Fe,{flexDirection:"column",borderStyle:"round",borderColor:Se.border,padding:0,width:"100%",minHeight:26},D.createElement(Fe,{paddingX:1,paddingY:0,marginBottom:0,borderStyle:"single",borderColor:Se.borderMuted,width:"100%"},D.createElement(ee,{color:Se.text,bold:!0},"SYSTEM CONFIGURATION")),D.createElement(Fe,{flexDirection:"row",width:"100%",minHeight:20},D.createElement(Fe,{flexDirection:"column",width:"30%",maxWidth:40,borderStyle:"round",borderColor:ue==="categories"?Se.border:Se.borderMuted,padding:1,paddingY:0},D.createElement(Fe,{marginBottom:1},D.createElement(ee,{color:ue==="categories"?Se.text:Se.textDim,bold:!0,underline:!0},"CATEGORIES")),Oo.map((ae,T)=>{let k=H===T,ve=ae.id==="exit";return D.createElement(Fe,{key:ae.id,marginTop:ve?9:0,backgroundColor:k?ue==="categories"?Se.highlightBg:Se.cardBg:void 0,paddingX:1},D.createElement(ee,{color:k&&ue==="categories"?Se.text:Se.textDim,bold:k},k?"\u276F ":" ",ae.label))})),D.createElement(Fe,{flexDirection:"column",flexGrow:1,borderStyle:"round",borderColor:ue==="items"?Se.border:Se.borderMuted,paddingX:1,marginLeft:1,paddingY:0},D.createElement(Fe,{marginBottom:1,flexDirection:"row",justifyContent:"space-between",alignItems:"center"},D.createElement(ee,{color:ue==="items"?Se.text:Se.textDim,bold:!0,underline:!0},Oo[H].label.toUpperCase().includes("EXIT")?"Runtime Information":`${Oo[H].label} Settings`),je==="security"&&D.createElement(Fe,{flexDirection:"row"},D.createElement(Fe,{paddingX:1,backgroundColor:rt==="Sandbox"?ue==="items"?Se.highlightBg:Se.cardBg:void 0},D.createElement(ee,{bold:rt==="Sandbox",color:rt==="Sandbox"?Se.primary||"cyan":Se.textDim},"[ Sandbox ]")),D.createElement(Fe,{paddingX:1,backgroundColor:rt==="Other"?ue==="items"?Se.highlightBg:Se.cardBg:void 0},D.createElement(ee,{bold:rt==="Other",color:rt==="Other"?Se.primary||"cyan":Se.textDim},"[ Others ]")))),Gt.length>0?(()=>{let ae=null,T=[],k=Ke=>(Ke||"").split(",").map(Ot=>Ot.trim().toLowerCase()).filter(Boolean),ve=k(t.autoApproveCommands),Ne=k(t.autoDisallowCommands),at=k(t.alwaysAskCommands),dt=[...ve,...Ne,...at],et=new Set(dt),so=je==="security"&&dt.length!==et.size;return Gt.forEach((Ke,Ot)=>{let mn=ue==="items"&&Le===Ot,xn=Ke.label.length,Cs=Math.max(2,38-xn),St=".".repeat(Cs),re=tt=>je==="security"?(tt.value==="autoExec"||tt.value==="externalAccess")&&tt.status==="ON"?Se.statusOn:Se.statusOff:tt.status?.startsWith("\u2713")?Se.statusOn:tt.status?.startsWith("\u26A0")?Se.statusOff:tt.status==="ON"?Se.statusOn:tt.status==="OFF"?Se.statusOff:Se.text;Ke.section&&Ke.section!==ae&&je!=="security"&&(ae=Ke.section,T.push(D.createElement(Fe,{key:`sec-hdr-${Ke.section}`,marginTop:T.length>0?1:0,marginBottom:0,paddingX:1},D.createElement(ee,{color:"gray",bold:!0,underline:!0},Ke.section.toUpperCase()))));let In=mn&&xe&&(xe==="alwaysAskCommands"&&Ke.value==="alwaysAsk"||xe==="alwaysAskFiles"&&Ke.value==="alwaysAskFiles"||xe==="autoApproveCommands"&&Ke.value==="autoApprove"||xe==="autoDisallowCommands"&&Ke.value==="autoDisallow"||xe==="customOpenAIBaseUrl"&&Ke.value==="customOpenAIBaseUrl"||xe==="customOpenAIKey"&&Ke.value==="customOpenAIKey"||xe==="profileNickname"&&Ke.value==="profileNickname"||xe==="profileInstructions"&&Ke.value==="profileInstructions"),Or=Ke.value==="alwaysAsk"||Ke.value==="alwaysAskFiles"||Ke.value==="autoApprove"||Ke.value==="autoDisallow"||Ke.value==="profileInstructions",Nr=Ke.value==="parserDownload";T.push(D.createElement(Fe,{key:Ke.value,flexDirection:"column"},D.createElement(Fe,{backgroundColor:mn&&!In?Se.highlightBg:void 0,paddingX:2},D.createElement(ee,{color:mn?Se.text:Se.textDim,bold:mn},mn?"\u276F ":" ",Ke.label),!Or&&!Nr&&D.createElement(D.Fragment,null,D.createElement(ee,{color:"gray"},St),D.createElement(ee,{color:re(Ke),bold:!0},Ke.value==="aiProvider"?Ke.status:`[ ${Ke.status} ]`))),Or&&!In&&Ke.status!=="None"&&D.createElement(Fe,{paddingX:4,marginBottom:1},D.createElement(ee,{color:"gray"},"\u21B3 ",Ke.status)),In&&D.createElement(Fe,{flexDirection:"column",marginLeft:4,marginBottom:1},D.createElement(Fe,{paddingX:1,borderStyle:"single",borderColor:"gray",flexDirection:"row"},D.createElement(ee,{color:"gray",bold:!0},"> "," "),D.createElement(Nd,{value:Mt,onChange:tt=>{let It=xe==="profileNickname"?20:xe==="profileInstructions"?250:1/0;He(tt.slice(0,It))},onSubmit:async tt=>{if(xe==="customOpenAIBaseUrl"){let It=tt.trim().replace(/\/+$/,""),Ie={...t,customOpenAIBaseUrl:It};g(Ie),p({systemSettings:Ie,apiTier:d,quotas:r})}else if(xe==="customOpenAIKey"){let It=tt.trim(),{replaceActiveProviderKey:Ie}=await import("./secrets-YIWFP4S2.js"),eo=await Ie("c_openai",It);It&&(!eo||eo.ok!==!1)&&(_e(Do=>({...Do,c_openai:!0})),b==="c_openai"&&(_&&_(It),Y&&Y(It,{aiProvider:"c_openai"})))}else if(xe==="profileNickname"){let It=tt.trim().slice(0,20),Ie={...F||{},nickname:It};B&&B(Ie),p({profileData:Ie,systemSettings:t,apiTier:d,quotas:r})}else if(xe==="profileInstructions"){let It=tt.trim().slice(0,250),Ie={...F||{},instructions:It};B&&B(Ie),p({profileData:Ie,systemSettings:t,apiTier:d,quotas:r})}else{let It={...t,[xe]:tt.trim(),sandboxPreset:"Custom"};g(It),p({systemSettings:It,apiTier:d,quotas:r})}ye(null)}})),D.createElement(ee,{color:"gray",italic:!0}," ",xe==="customOpenAIBaseUrl"?"Enter Base URL (.../v1) \u2022 Press Enter to save, Esc to cancel":xe==="customOpenAIKey"?"Enter API Key \u2022 Press Enter to save, Esc to cancel":xe==="profileNickname"?`Enter Nickname (${Mt.length}/20) \u2022 Press Enter to save, Esc to cancel`:xe==="profileInstructions"?`Enter Custom Instructions (${Mt.length}/250) \u2022 Press Enter to save, Esc to cancel`:"Comma separated \u2022 Press Enter to save, Esc to cancel"))))}),so&&T.push(D.createElement(Fe,{key:"conflict-warning",marginTop:1,paddingX:1},D.createElement(ee,{color:Se.text,italic:!0},"* Conflicting commands will be ignored and defaulted to highest priority"))),T})():D.createElement(Fe,{paddingX:1,flexDirection:"column",width:"100%"},je==="exit"?D.createElement(D.Fragment,null,D.createElement(Fe,{flexDirection:"column",marginBottom:1},D.createElement(Fe,{flexDirection:"row"},D.createElement(ee,{color:Se.textDim},"OS"," "),D.createElement(ee,{color:"gray"},"..................... "),D.createElement(ee,{color:Se.text},process.env.OS||process.platform||"N/A")),D.createElement(Fe,{flexDirection:"row"},D.createElement(ee,{color:Se.textDim},"Computer Name"," "),D.createElement(ee,{color:"gray"},".......... "),D.createElement(ee,{color:Se.text},process.env.COMPUTERNAME||process.env.HOSTNAME||"N/A")),D.createElement(Fe,{flexDirection:"row"},D.createElement(ee,{color:Se.textDim},"Processor Count"," "),D.createElement(ee,{color:"gray"},"........ "),D.createElement(ee,{color:Se.text},process.env.NUMBER_OF_PROCESSORS||"N/A")),D.createElement(Fe,{flexDirection:"row"},D.createElement(ee,{color:Se.textDim},"Node.js Version"," "),D.createElement(ee,{color:"gray"},"........ "),D.createElement(ee,{color:Se.text},"v",process.versions.node)),D.createElement(Fe,{flexDirection:"row"},D.createElement(ee,{color:Se.textDim},"V8 Version"," "),D.createElement(ee,{color:"gray"},"...... ...... "),D.createElement(ee,{color:Se.text},"v",process.versions.v8)),D.createElement(Fe,{flexDirection:"row"},D.createElement(ee,{color:Se.textDim},"Data Directory"," "),D.createElement(ee,{color:"gray"},"......... "),So===Ao?"":D.createElement(ee,{color:Se.text},So.replaceAll(Ba.homedir(),"~").replaceAll("\\\\","/").replaceAll("\\","/"),", "),D.createElement(ee,{color:Se.text},Ao.replaceAll(Ba.homedir(),"~").replaceAll("\\\\","/").replaceAll("\\","/"))),D.createElement(Fe,{flexDirection:"row"},D.createElement(ee,{color:Se.textDim},"Viewport"," "),D.createElement(ee,{color:"gray"},"............... "),D.createElement(ee,{color:Se.text},process.stdout.rows||"?"," rows \xD7 ",process.stdout.columns||"?"," cols ",process.stdout.columns<90?"(too small width)":"")),D.createElement(Fe,{flexDirection:"row",marginBottom:0},D.createElement(ee,{color:Se.textDim},"Memory Load"," "),D.createElement(ee,{color:"gray"},"............ "),D.createElement(ee,{color:Se.text},ro,"/",Qo," ",Ar))),D.createElement(Fe,{key:"pty-notice",paddingX:0,marginTop:0},D.createElement(ee,{color:Lr?Se.statusOn:Se.warning},Lr?"\u2713 Advance Interactive Terminal Supported":"\u26A0 Interactive Terminal is Limited"))):D.createElement(ee,{color:"gray",italic:!0},Oo[H].desc)))),D.createElement(Fe,{paddingX:1,marginTop:0,flexDirection:"row",justifyContent:"space-between"},D.createElement(ee,{color:"gray",italic:!0},ue==="categories"?"\u25B2\u25BC Select Category \u2022 Enter/\u25BA to configure":je==="security"?"\u25B2\u25BC Select Option \u2022 TAB/\u25C4\u25BA Switch Tab \u2022 Enter to Edit/Toggle \u2022 ESC to go back":"\u25B2\u25BC Select Option \u2022 Enter to Toggle \u2022 \u25C4/ESC to go back"),ue==="categories"&&D.createElement(ee,{color:"gray"},Oo[H].desc)))}import _t,{useState as mi}from"react";import{Box as go,Text as rn,useInput as $d}from"ink";import Ud from"ink-text-input";var _d=({question:t,options:g,onResolve:d,theme:S="Dark"})=>{let w=xt(S),[p,r]=mi(!1),[y,b]=mi(""),[C,L]=mi(0),F=!1,B=[],A=Array.isArray(g)&&g.length>0,W=t==="Agent has been running for a long time. Do you want to continue execution?";try{W&&A?B=[...g]:B=[...A?g:[],A?{id:"CUSTOM",label:"Suggest something else...",description:"Provide a custom response"}:{id:"CUSTOM",label:"Your Answer",description:""}]}catch{F=!0}$d((_,Y)=>{if(!p&&((Y.leftArrow||Y.upArrow)&&L(j=>Math.max(0,j-1)),(Y.rightArrow||Y.downArrow)&&L(j=>Math.min(B.length-1,j+1)),Y.return)){let j=B[C];j?.id==="CUSTOM"?r(!0):d(F?"Selected Nothing":j.label)}});let X=yt(2);return p?_t.createElement(go,{flexDirection:"column",borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!1,borderBottom:!1,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,backgroundColor:w.codeBg,width:"100%"},_t.createElement(go,{paddingX:1},_t.createElement(rn,{color:w.text,bold:!0},"SUGGEST SOMETHING")),_t.createElement(go,{marginTop:1,paddingX:1},_t.createElement(rn,{italic:!0,color:w.textMuted},"Replying to: ",t)),_t.createElement(go,{marginTop:1,paddingX:1,flexDirection:"row"},_t.createElement(Ud,{value:y,onChange:b,onSubmit:()=>d(y)})),_t.createElement(go,{marginTop:1,paddingX:1,marginBottom:1},_t.createElement(rn,{color:w.textMuted,italic:!0},"(Press Enter to send)"))):_t.createElement(go,{flexDirection:"column",border:!0,borderStyle:"round",borderColor:w.codeBorder,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,marginY:1,marginRight:1,width:"100%"},_t.createElement(go,{paddingX:1,marginBottom:1},_t.createElement(rn,{color:"yellow",bold:!0},W?"TURN SAFETY SYSTEM: EXECUTION LIMIT":"AGENT REQUEST: ACTION REQUIRED")),_t.createElement(go,{paddingX:1,marginBottom:1},_t.createElement(rn,{color:w.text},t)),_t.createElement(go,{flexDirection:"column",width:"100%"},B.map((_,Y)=>{let j=Y===C;return _t.createElement(go,{key:_.id,flexDirection:"column",width:"100%",backgroundColor:j?w.highlightBg:void 0,paddingX:1,marginBottom:Y===B.length-1?0:1},_t.createElement(rn,{color:j?w.text:w.textMuted,bold:j},j?"\u276F ":" ",_.label),_.description&&_t.createElement(go,{marginLeft:4},_t.createElement(rn,{color:w.textMuted,italic:!0},_.description)))})),_t.createElement(go,{paddingX:1,marginTop:1,marginBottom:1},_t.createElement(rn,{color:w.textMuted,italic:!0},"(Use Arrows to navigate, Enter to confirm)")))},Da=_d;import du from"gradient-string";var Hd=t=>{let g=String(t||"").trim().split(/\s+/).filter(Boolean),d={sub:null,args:[],provider:null,providerBare:!1,index:null,url:null,temp:!1,all:!1,unmask:!1,nullMode:!1},S=[];for(let w=0;w<g.length;w++){let p=g[w];if(p==="--provider"){let r=g[w+1];r&&!r.startsWith("--")?(d.provider=r,w++):d.providerBare=!0}else if(p==="--index"){let r=g[w+1];r&&/^\d+$/.test(r)&&(d.index=parseInt(r,10)-1,w++)}else if(p==="--url"){let r=g[w+1];r&&!r.startsWith("--")&&(d.url=r,w++)}else p==="--temp"?d.temp=!0:p==="--null"?d.nullMode=!0:p==="--all"?d.all=!0:p==="--unmask"||p==="--reveal"?d.unmask=!0:p==="--mask"?d.unmask=!1:S.push(p)}return d.sub=S.length?S[0].toLowerCase():null,d.args=S.slice(1),d},Ia=["\u2726 API KEY MANAGEMENT","\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m /key list [--provider <name>] [--unmask]","\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m /key add <key> [--index <n>] [--provider <name>] [--url <endpoint>]","\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m /key remove [<index>|<key>|--all] [--provider <name>]","\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m /key use <index>|<key> | /key use <key> --temp","\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m /key use --null (no key sent; c_openai / Ollama only)","\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m /key clean [--provider <name>]","\u2800"],ka=async(t,g={})=>{let d=Hd(t),S=g.currentProvider||"Google",w=[],p=(b={})=>({lines:w,...b}),r=S;if(d.provider){let b=Cl(d.provider);if(!b)return{lines:[`\u2726 Unknown provider: ${d.provider}`]};r=b}let y=d.sub;if(!y)return{lines:Ia};if(y==="list"){if(d.providerBare){let C=Sl();w.push("\u2726 SAVED API KEYS");for(let L of C)w.push(`- ${L.provider} (${L.hasKeys?L.count:"No Saved Keys"})`);return w.push("\u2800"),p()}let b=await Nl(r,{unmask:d.unmask});return w.push(`\u2726 ${Ml(r.replace("c_openai","Custom Endpoints"))} API KEYS`),w.push(...b),w.push("\u2800"),p()}if(y==="add"||y==="new"){let b=d.args.join(" ").trim();if(!b)return p({promptNewKey:!0});let C=await Al(r,b,{index:d.index!==null?d.index:void 0,baseUrl:d.url!==null?d.url:void 0});return C.ok?(await vl(r)===null&&await Bl(r,C.index),w.push(`\u2726 Key added to ${r.replace("c_openai","Custom Endpoints")} slot ${C.index+1}.`),d.url!==null&&Js(r)&&w.push(`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Using URL: ${d.url}`),p()):C.full?{lines:[`\u2726 ${C.error}`,"\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Use /key add <key> --index <n> to overwrite a slot."]}:{lines:[`\u2726 Failed to add key: ${C.error}`]}}if(y==="remove"){let b;if(d.all)b=void 0;else if(d.args.length){let L=d.args.join(" ");b=/^\d+$/.test(L)?parseInt(L,10)-1:L}let C=await Ll(r,b,{all:d.all});return C.ok?C.all?(w.push(`\u2726 Cleared all keys for ${r.replace("c_openai","Custom Endpoints")}.`),p({promptNewKey:!0})):(w.push(`\u2726 Removed key from ${r.replace("c_openai","Custom Endpoints")} slot ${C.removedIndex+1}.`),C.needsNewKey?(w.push(`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m No keys remain for ${r}. Please enter a new key.`),p({promptNewKey:!0})):p()):{lines:[`\u2726 ${C.error}`]}}if(y==="use"){let b=d.args.join(" ").trim();if(d.nullMode){if(!Dl(r))return{lines:["\u2726 --null is only supported for Custom Endpoints and Ollama."]};await Il(r,!0),Rs(r);let F=r.replace("c_openai","Custom Endpoints");return w.push(`\u2726 ${F} now using NO API key (persisted).`),w.push("\u2800\u2800\u2514\u2500 Saved key slots were kept, they are just ignored."),r==="c_openai"&&w.push("\u2800\u2800\u2514\u2500 No Authorization header will be sent. Base URL is unchanged."),p({switchedKey:El})}if(!b)return{lines:["\u2726 Usage: /key use <index> | <key> [--temp] | /key use --null"]};if(d.temp)return kl(r,b),w.push(`\u2726 Temporary key set for ${r.replace("c_openai","Custom Endpoints")} (session only).`),Js(r)&&w.push("\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Will use the current Custom base URL."),p({switchedKey:b});let C=/^\d+$/.test(b)?parseInt(b,10)-1:b,L=await Pl(r,C);return L.ok?(Rs(r),w.push(`\u2726 ${r.replace("c_openai","Custom Endpoints")} now using slot ${L.index+1}.`),L.switchedBaseUrl&&w.push(`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Switched Base URL to: ${L.switchedBaseUrl}`),p({switchedBaseUrl:L.switchedBaseUrl,switchedKey:L.key})):{lines:[`\u2726 ${L.error}`]}}if(y==="clean"){let b=d.provider?r:null,C=await Ol(b);return w.push(b?`\u2726 Compacted ${b.replace("c_openai","Custom Endpoints")} key slots.`:`\u2726 Compacted all key stores (${C.touched} provider(s) touched).`),p()}return{lines:[`\u2726 Unknown subcommand: ${y}`,...Ia]}};import Pa from"node-notifier";import jo from"path";import Aa from"fs";import{execSync as Wd}from"child_process";import{fileURLToPath as Xd}from"url";var ms=jo.dirname(Xd(import.meta.url)),Ir=t=>{let g=[jo.resolve(ms,"../assets",t),jo.resolve(ms,"../../assets",t),jo.resolve(ms,"../../src/assets",t),jo.resolve(process.cwd(),"src/assets",t),jo.resolve(process.cwd(),"dist/assets",t)];for(let d of g)if(Aa.existsSync(d))return d;return g[0]},La=jo.join(process.env.APPDATA,"Microsoft","Windows","Start Menu","Programs","FluxFlow"),Gm=jo.join(La,"FluxFlow.lnk"),Km=jo.resolve(ms,"../../node_modules/node-notifier/vendor/snoreToast/snoretoast-x64.exe"),xi=()=>{if(process.platform==="win32")try{let t=Ir("logo.png"),g=Ir("logo.ico"),S=`
45
- $key = 'HKCU:\\Software\\Classes\\AppUserModelId\\FluxFlow'
46
- New-Item -Path $key -Force | Out-Null
47
- Set-ItemProperty -Path $key -Name 'DisplayName' -Value 'FluxFlow'
48
- Set-ItemProperty -Path $key -Name 'IconUri' -Value '${(Aa.existsSync(t)?t:g).replace(/'/g,"''")}'
49
- Set-ItemProperty -Path $key -Name 'IconBackgroundColor' -Value '00000000'
50
- Set-ItemProperty -Path $key -Name 'ShowInSettings' -Value 0 -Type DWord -ErrorAction SilentlyContinue
51
- Remove-Item -Path '${La.replace(/'/g,"''")}' -Recurse -Force -ErrorAction SilentlyContinue
52
- `.replace(/\r?\n\s*/g,"; ");Wd(`powershell -NoProfile -Command "${S}"`,{stdio:"ignore"})}catch{}},fi=()=>"FluxFlow";var xs=!1,gi=(t="")=>{let g="FluxFlow",d=`Agent finished - ${t||"Session"}`;try{xs||(xi(),xs=!0);let S=process.platform==="win32"?fi():"FluxFlow",w=Ir("logo.png");Pa.notify({title:g,message:d,appID:S,icon:w,contentImage:w,wait:!1})}catch{}},fs=(t="User action required")=>{let g="FluxFlow";try{xs||(xi(),xs=!0);let d=process.platform==="win32"?fi():"FluxFlow",S=Ir("logo.png");Pa.notify({title:g,message:t,appID:d,icon:S,contentImage:S,wait:!1})}catch{}};import Yt,{useState as hi,useEffect as Gd}from"react";import{Box as No,Text as sn,useInput as Kd}from"ink";function pi({onSelect:t,onDelete:g,onClose:d,theme:S="Dark"}){let w=xt(S),[p,r]=hi({}),[y,b]=hi([]),[C,L]=hi(0);Gd(()=>{(async()=>{let _=await Ko();r(_),b(Object.keys(_).sort((Y,j)=>(_[j].updatedAt||0)-(_[Y].updatedAt||0)))})()},[]),Kd((X,_)=>{if(_.escape&&d(),_.upArrow&&L(Y=>Math.max(0,Y-1)),_.downArrow&&L(Y=>Math.min(y.length-1,Y+1)),_.return&&y[C]&&t(y[C]),X==="x"&&y[C]){let Y=y[C];g(Y).then(j=>{let le=j||{};r(le);let ue=Object.keys(le).sort((ne,H)=>(le[H]?.updatedAt||0)-(le[ne]?.updatedAt||0));b(ue),L(ne=>Math.max(0,Math.min(ue.length-1,ne)))})}});let F=yt(2),B=15,A=0;if(y.length>B){let X=Math.floor(B/2);A=C-X,A<0?A=0:A+B>y.length&&(A=y.length-B)}let W=y.slice(A,A+B);return Yt.createElement(No,{flexDirection:"column",borderStyle:"round",borderColor:w.borderMuted,padding:0,width:"100%"},Yt.createElement(No,{paddingX:1,marginBottom:1},Yt.createElement(sn,{color:w.text,bold:!0},"CHAT HISTORY: RESUME CONVERSATION")),y.length===0?Yt.createElement(No,{paddingX:2,paddingY:1},Yt.createElement(sn,{italic:!0,color:w.textMuted},"No saved chats found.")):Yt.createElement(No,{flexDirection:"column",width:"100%"},A>0&&Yt.createElement(No,{paddingX:2,marginBottom:1},Yt.createElement(sn,{color:w.textMuted},"\u25B2 (+",A," more chats above)")),W.map((X,_)=>{let Y=p[X],le=A+_===C,ue=Vd(Y?.updatedAt);return Yt.createElement(No,{key:X,paddingX:1,backgroundColor:le?w.highlightBg:void 0,width:"100%"},Yt.createElement(No,{flexGrow:1},Yt.createElement(sn,{color:le?w.text:w.textMuted,bold:le},le?"\u276F ":" ",Tr(Y,X),Yt.createElement(sn,{color:w.textMuted}," [",ue," \u2022 ",X,"]"))),le&&Yt.createElement(No,{flexShrink:0},Yt.createElement(sn,{color:w.danger,bold:!0},"[X] DELETE ")))}),A+B<y.length&&Yt.createElement(No,{paddingX:2,marginTop:1},Yt.createElement(sn,{color:w.textMuted},"\u25BC (+",y.length-(A+B)," more chats below)"))),Yt.createElement(No,{marginTop:1,paddingX:1,borderStyle:"single",borderLeft:!1,borderRight:!1,borderBottom:!1,borderColor:w.borderMuted},Yt.createElement(sn,{color:w.textMuted,italic:!0},"\u2191\u2193 navigate \u2022 Enter select \u2022 x delete \u2022 Esc close")))}function Vd(t){if(!t)return"N/A";let g=new Date(t);if(isNaN(g.getTime()))return"N/A";let d=y=>String(y).padStart(2,"0"),S=d(g.getMonth()+1),w=d(g.getDate()),p=d(g.getHours()),r=d(g.getMinutes());return`${S}-${w} ${p}:${r}`}import Ht,{useState as bi,useEffect as Yd}from"react";import{Box as Fo,Text as Eo,useInput as jd,useStdout as qd}from"ink";function wi({onClose:t,theme:g="Dark"}){let d=xt(g),{stdout:S}=qd(),w=S?.columns||80,[p,r]=bi([]),[y,b]=bi(0),[C,L]=bi(!0),F=()=>{let ne=zr(gr,[]);r(ne);try{let pe=Qr(Mn,{}).systemSettings?.memory!==!1;L(pe)}catch{L(!0)}};Yd(()=>{F()},[]),jd((ne,H)=>{if(H.escape&&t(),H.upArrow&&b(pe=>Math.max(0,pe-1)),H.downArrow&&b(pe=>Math.min(p.length-1,pe+1)),ne==="x"&&p.length>0){let pe=p[y].id,Le=p.filter(Pe=>Pe.id!==pe);fl(gr,Le),r(Le),y>=Le.length&&Le.length>0&&b(Le.length-1)}});let B=(ne,H,pe)=>{if(!ne)return"";let Le=ne.replace(/\[Saved on: .*?\]/g,"").replace(/\\+'/g,"'").trim(),rt=`${pe?"\u276F ":" "}${H+1}. `.length,Me=pe?22:2;return Le.split(`
53
- `).map((ye,Mt)=>{let He=Mt===0,ke=Math.max(10,w-4-(He?rt:3)-Me),Te=Math.max(10,w-4-3-Me),Q=ye.split(/(\s+)/),me=[],be="";if(Q.forEach(fe=>{if(fe.length===0)return;let q=me.length===0?ke:Te;be.length+fe.length>q?be.trim().length>0?(me.push(be.trimEnd()),be=fe):(me.push(fe.substring(0,q)),be=fe.substring(q)):be+=fe}),be.trimEnd().length>0&&me.push(be.trimEnd()),me.length===0)return"";let Z=me.join(`
54
- `);return He?Z:" "+Z}).join(`
55
- `)},A=4*1024*2,W=p.reduce((ne,H)=>ne+(H.memory?.length||0),0),X=Math.min(100,Math.round(W/A*100)),_=12,Y=Math.round(X/100*_),j="\u2588".repeat(Y)+"\u2591".repeat(Math.max(0,_-Y)),le=()=>X<50?d.textMuted:X<90?d.warning:d.danger,ue=yt(2);return Ht.createElement(Fo,{flexDirection:"column",borderStyle:"round",borderColor:d.borderMuted,padding:0,width:"100%"},Ht.createElement(Fo,{paddingX:1,marginBottom:1,justifyContent:"space-between"},Ht.createElement(Eo,{color:d.text,bold:!0},"SAVED MEMORIES"),Ht.createElement(Fo,null,Ht.createElement(Eo,{color:d.textMuted},"Vault: "),Ht.createElement(Eo,{color:le()},j),Ht.createElement(Eo,{color:d.text,bold:!0}," ",X,"%"))),!C&&p.length>0?Ht.createElement(Fo,{paddingX:2,paddingY:1},Ht.createElement(Eo,{italic:!0,color:d.textMuted},"Memory is currently Off...")):p.length===0?Ht.createElement(Fo,{paddingX:2,paddingY:1},Ht.createElement(Eo,{italic:!0,color:d.textMuted},C?"Learning...":"Memory not available...")):Ht.createElement(Fo,{flexDirection:"column"},p.map((ne,H)=>{let pe=H===y;return Ht.createElement(Fo,{key:ne.id,paddingX:1,backgroundColor:pe?d.highlightBg:void 0,width:"100%"},Ht.createElement(Fo,{flexGrow:1},Ht.createElement(Eo,{color:pe?d.text:d.textMuted,bold:pe},pe?"\u276F ":" ",H+1,". ",B(ne.memory,H,pe))),pe&&Ht.createElement(Fo,{flexShrink:0},Ht.createElement(Eo,{color:d.textMuted,dimColor:!0}," [",Ht.createElement(Eo,{italic:!0},ne.score),"] "),Ht.createElement(Eo,{color:d.danger,bold:!0},"[X] WIPE ")))})),Ht.createElement(Fo,{marginTop:1,paddingX:1,borderStyle:"single",borderLeft:!1,borderRight:!1,borderBottom:!1,borderColor:d.borderMuted},Ht.createElement(Eo,{color:d.textMuted,italic:!0},"\u2191\u2193 navigate \u2022 x wipe memory \u2022 Esc close")))}import Dt,{useState as gs,useEffect as Oa}from"react";import{Box as ln,Text as qt}from"ink";import{spawn as Na}from"child_process";var Fa=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],zd=({latest:t,current:g,settings:d,theme:S="Dark",onClose:w,onUpdateSettings:p,onSuccess:r})=>{let y=xt(S),[b,C]=gs("initializing"),[L,F]=gs(""),[B,A]=gs(null),[W,X]=gs(0);if(Oa(()=>{let _=setInterval(()=>{X(Y=>(Y+1)%1e3)},33);return()=>clearInterval(_)},[]),Oa(()=>{let _;return(async()=>{let j=d?.updateManager||"npm";if(!d?.updateManager){p();return}let le="";j==="pnpm"?le=`pnpm add -g fluxflow-cli@${t}`:j==="bun"?le=`bun add -g fluxflow-cli@${t}`:j==="yarn"?le=`yarn global add fluxflow-cli@${t}`:j==="custom"?le=d.customUpdateCommand:le=`npm install -g fluxflow-cli@${t}`,C("downloading"),F(`Running: ${le}...`);let ue=process.platform==="win32",ne=pe=>new Promise(Le=>{let Pe=ue?pe?"powershell.exe":"cmd.exe":process.env.SHELL||"bash",rt=ue?pe?["-NoProfile","-Command",le]:["/c",le]:["-c",le],Me=ye=>{let He=ye.toString().replace(/\x1B\[[0-?]*[ -/]*[@-~]|\x1B\][^\x07\x1B]*[\x07\x1B]|\b|\x07/g,"").replace(/\r/g,"").trim();He&&F(ke=>{let Te=ke.split(`
56
- `);return Te[Te.length-1]?.startsWith("Progress:")&&He.startsWith("Progress:")?(Te[Te.length-1]=He,Te.slice(-5).join(`
57
- `)):(ke+`
58
- `+He).split(`
59
- `).slice(-10).join(`
60
- `)})},xe=ue?Na(Pe,rt,{cwd:process.cwd(),env:process.env}):Na(le,{shell:!0,cwd:process.cwd(),env:process.env});_=xe,xe.stdout.on("data",Me),xe.stderr.on("data",Me),xe.on("close",ye=>{_=null,Le(ye!==0?{error:`Process exited with code ${ye}`}:{success:!0})}),xe.on("error",ye=>{ue&&pe&&ye.code==="ENOENT"?Le({retryCmd:!0}):(_=null,Le({error:ye.message}))})}),H={};ue?(H=await ne(!0),H.retryCmd&&(H=await ne(!1))):H=await ne(!1),H.error?(A(H.error),C("error")):H.success&&(C("success"),r&&r())})(),()=>{if(_)try{typeof _.destroy=="function"?_.destroy():typeof _.kill=="function"&&_.kill()}catch{}}},[]),b==="initializing"||b==="downloading"){let _=Fa[Math.floor(W/3)%Fa.length];return Dt.createElement(ln,{flexDirection:"column",borderStyle:"round",borderColor:y.border,paddingX:2,paddingY:1},Dt.createElement(ln,null,Dt.createElement(qt,{color:y.accent||y.primary},_),Dt.createElement(qt,{marginLeft:1,bold:!0,color:y.text}," Updating Flux Flow to v",t,"...")),Dt.createElement(ln,{marginTop:1,paddingX:1,borderStyle:"single",borderColor:y.borderMuted},Dt.createElement(qt,{color:y.textMuted,italic:!0},L||"Preparing environment...")),Dt.createElement(qt,{marginTop:1,color:y.textDim||y.textMuted},"(Please do not close the terminal)"))}return b==="success"?Dt.createElement(ln,{flexDirection:"column",borderStyle:"round",borderColor:y.success||y.border,paddingX:2,paddingY:1},Dt.createElement(qt,{color:y.success||y.text,bold:!0},"\u2705 UPDATE SUCCESSFUL!"),Dt.createElement(qt,{marginTop:1,color:y.text},"Flux Flow has been updated to ",Dt.createElement(qt,{color:y.accent||y.primary},"v",t),"."),Dt.createElement(qt,{marginTop:1,color:y.text,bold:!0},"Please restart your terminal session to apply changes."),Dt.createElement(ln,{marginTop:1},Dt.createElement(qt,{color:y.textMuted},"(Press ESC to return to chat)"))):b==="error"?Dt.createElement(ln,{flexDirection:"column",borderStyle:"round",borderColor:y.danger||y.border,paddingX:2,paddingY:1},Dt.createElement(qt,{color:y.danger||y.text,bold:!0},"\u274C UPDATE FAILED"),Dt.createElement(ln,{marginTop:1,paddingX:1,borderStyle:"single",borderColor:y.borderMuted},Dt.createElement(qt,{color:y.danger||y.text},B)),Dt.createElement(qt,{marginTop:1,color:y.text,bold:!0},"Possible causes:"),Dt.createElement(qt,{color:y.textMuted},"\u2022 Missing permissions (Try running as Administrator/Sudo)"),Dt.createElement(qt,{color:y.textMuted},"\u2022 Package manager (",d?.updateManager,") not found"),Dt.createElement(qt,{color:y.textMuted},"\u2022 Network failure"),Dt.createElement(ln,{marginTop:1},Dt.createElement(qt,{color:y.textDim||y.textMuted},"(Press ESC to return to chat)"))):null},$a=zd;import no,{useState as Ua,useEffect as Qd}from"react";import{Box as an,Text as Qn,useInput as Jd}from"ink";var hs=[{label:"JavaScript",file:"tree-sitter-javascript.wasm",exts:["js","jsx"]},{label:"TypeScript",file:"tree-sitter-typescript.wasm",exts:["ts"]},{label:"TSX",file:"tree-sitter-tsx.wasm",exts:["tsx"]},{label:"Python",file:"tree-sitter-python.wasm",exts:["py"]},{label:"C",file:"tree-sitter-c.wasm",exts:["c"]},{label:"C++",file:"tree-sitter-cpp.wasm",exts:["cpp"]},{label:"Java",file:"tree-sitter-java.wasm",exts:["java"]},{label:"HTML",file:"tree-sitter-html.wasm",exts:["html"]}];function Ti({onClose:t}){let[g,d]=Ua(0),[S,w]=Ua({});return Qd(()=>{let p={};hs.forEach(r=>{ta(r.file)?p[r.file]="ready":p[r.file]="idle"}),w(p)},[]),Jd(async(p,r)=>{r.escape&&t(),r.upArrow&&d(b=>Math.max(0,b-1)),r.downArrow&&d(b=>Math.min(hs.length-1,b+1));let y=hs[g];if(p==="x"||p==="X"){if(S[y.file]==="downloading")return;try{await oa(y.file),w(b=>({...b,[y.file]:"idle"}))}catch(b){w(C=>({...C,[y.file]:`error: ${b.message}`}))}}if(r.return){if(S[y.file]==="downloading")return;w(b=>({...b,[y.file]:"downloading"}));try{await ea(y.file),w(b=>({...b,[y.file]:"ready"}))}catch(b){w(C=>({...C,[y.file]:`error: ${b.message}`}))}}}),no.createElement(an,{flexDirection:"column",borderStyle:"round",borderColor:"gray",padding:0,width:"100%"},no.createElement(an,{paddingX:1,marginBottom:1},no.createElement(Qn,{color:"white",bold:!0},"LANGUAGE PARSER MANAGER")),no.createElement(an,{flexDirection:"column"},hs.map((p,r)=>{let y=r===g,b=S[p.file]||"idle",C="[ DOWNLOAD ]",L="gray";b==="downloading"?(C="[ DOWNLOADING... ]",L="yellow"):b==="ready"?(C="[ READY ]",L="green"):b.startsWith("error")&&(C=`[ ${b.toUpperCase()} ]`,L="red");let F=`${p.label} (${p.exts.join(", ")})`,B=Math.max(2,45-F.length),A=".".repeat(B);return no.createElement(an,{key:p.file,paddingX:1,backgroundColor:y?"#2a2a2a":void 0,width:"100%"},no.createElement(an,null,no.createElement(Qn,{color:y?"white":"grey",bold:y},y?"\u276F ":" ",p.label," ",no.createElement(Qn,{dimColor:!0},"(",p.exts.join(", "),")"))),no.createElement(an,{flexGrow:1},no.createElement(Qn,{color:"gray",dimColor:!0},A)),no.createElement(an,{width:20},no.createElement(Qn,{color:L,bold:!0},C)))})),no.createElement(an,{marginTop:1,paddingX:1,borderStyle:"single",borderLeft:!1,borderRight:!1,borderBottom:!1,borderColor:"gray"},no.createElement(Qn,{color:"grey",italic:!0},"\u2191\u2193 navigate \u2022 Enter download \u2022 x delete \u2022 Esc close")))}import Vt,{useState as Zd}from"react";import{Box as $o,Text as qo,useInput as Rd}from"ink";function yi({prompts:t,onSelect:g,onClose:d,theme:S="Dark"}){let w=xt(S),[p,r]=Zd(0);Rd((F,B)=>{B.escape&&d(),B.upArrow&&r(A=>Math.max(0,A-1)),B.downArrow&&r(A=>Math.min(t.length-1,A+1)),B.return&&t[p]&&g(t[p].id)});let y=yt(2),b=10,C=0;if(t.length>b){let F=Math.floor(b/2);C=p-F,C<0?C=0:C+b>t.length&&(C=t.length-b)}let L=t.slice(C,C+b);return Vt.createElement($o,{flexDirection:"column",borderStyle:"round",borderColor:w.borderMuted,padding:0,width:"100%"},Vt.createElement($o,{paddingX:1,marginBottom:1},Vt.createElement(qo,{color:w.text,bold:!0},"CODEBASE TIME TRAVEL: SELECT UNDO POINT")),Vt.createElement($o,{paddingX:2,marginBottom:1},Vt.createElement(qo,{color:w.text},"Select a prompt to revert the codebase back to the state ",Vt.createElement(qo,{bold:!0,color:w.secondary||"cyan"},"immediately before")," it was executed:")),t.length===0?Vt.createElement($o,{paddingX:2,paddingY:1},Vt.createElement(qo,{italic:!0,color:w.textMuted},"No prompt checkpoints found for this session.")):Vt.createElement($o,{flexDirection:"column",width:"100%"},C>0&&Vt.createElement($o,{paddingX:2,marginBottom:1},Vt.createElement(qo,{color:w.textMuted},"\u25B2 (+",C," more prompts above)")),L.map((F,B)=>{let W=C+B===p,X=tu(F.timestamp),_=F.changes?F.changes.length:0;return Vt.createElement($o,{key:F.id,paddingX:1,backgroundColor:W?w.highlightBg:void 0,width:"100%"},Vt.createElement($o,{flexGrow:1},Vt.createElement(qo,{color:W?w.text:w.textMuted,bold:W},W?"\u276F ":" ",'"',eu(F.prompt),'"',Vt.createElement(qo,{color:w.textMuted}," [",X," \u2022 ",_," file(s) changed]"))))}),C+b<t.length&&Vt.createElement($o,{paddingX:2,marginTop:1},Vt.createElement(qo,{color:w.textMuted},"\u25BC (+",t.length-(C+b)," more prompts below)"))),Vt.createElement($o,{marginTop:1,paddingX:1,borderStyle:"single",borderLeft:!1,borderRight:!1,borderBottom:!1,borderColor:w.borderMuted},Vt.createElement(qo,{color:w.textMuted,italic:!0},"\u2191\u2193 navigate \u2022 Enter select undo point \u2022 Esc close")))}function eu(t){if(!t)return"";let d=(t.split(`
61
- `)[0]||"").replace(/@\[(.*?)\]/g,(S,w)=>{let p=w.replace(/\\/g,"/").split("/");return`[${p[p.length-1]}]`});return d.length>69?d.slice(0,67)+"...":t.includes(`
62
- `)?d+"...":d}function tu(t){if(!t)return"N/A";let g=new Date(t);if(isNaN(g.getTime()))return"N/A";let d=r=>String(r).padStart(2,"0"),S=d(g.getHours()),w=d(g.getMinutes()),p=d(g.getSeconds());return`${S}:${w}:${p}`}import{exec as ou}from"child_process";import{promisify as nu}from"util";import _a from"fs";var Ha=nu(ou),Wa=async()=>{try{let t=Rl();if(t.executablePath&&_a.existsSync(t.executablePath))return!0;let{default:g}=await import("puppeteer"),d=g.executablePath();if(d&&_a.existsSync(d))return!0}catch{return!1}return!1},Xa=async t=>{t&&t("\u{1F4E5} Downloading Chromium engine (chrome@148)...");try{try{await Ha("pnpm exec puppeteer browsers install chrome@148")}catch{await Ha("npx -y puppeteer browsers install chrome@148")}return await new Promise(g=>setTimeout(g,1e3)),{success:!0}}catch(g){return console.error("[SETUP ERROR]",g),{success:!1,error:g.message}}};import Ga,{useState as Ka,useEffect as Va}from"react";import{Text as Ya}from"ink";var ru=({text:t,baseColor:g="grey",glintColor:d="gray",speed:S=200,glintWidth:w=6,typeSpeed:p=30,...r})=>{let[y,b]=Ka(-w),[C,L]=Ka(t);return Va(()=>{let F=setInterval(()=>{b(B=>B>C.length+w?-w-40:B+1)},S);return()=>clearInterval(F)},[C.length,S,w]),Va(()=>{if(t&&(t.includes("Trying to reach")&&C&&C.includes("Trying to reach")||t.includes("Error Occurred")&&C&&C.includes("Error Occurred"))){L(t);return}if(C===t)return;let F=setTimeout(()=>{let B=0,A=Math.min(C.length,t.length);for(;B<A&&C[B]===t[B];)B++;C.length>B?L(W=>W.slice(0,-1)):C.length<t.length&&L(t.slice(0,C.length+1))},p);return()=>clearTimeout(F)},[t,C,p]),Ga.createElement(Ya,null,C.split("").map((F,B)=>{let W=Math.abs(B-y)<=w/2?d:g;return Ga.createElement(Ya,{key:B,color:W,...r},F)}))},kr=ru;var ps=null,Rn=null,bs=null,ws=null,ho=t=>{let g=String(t);return g.startsWith("999")&&g.endsWith("9")},Ci=async()=>{let t=process.env["9ROUTER_URL"]||process.env.NINEROUTER_URL||process.env["9ROUTER_BASE_URL"]||"http://127.0.0.1:20128",g=t;try{let d=new URL(t);g=`${d.protocol}//${d.host}`}catch{g=t.replace(/\/v1(\/chat\/completions)?\/?$/,"")}try{let d=await fetch(g,{method:"GET",signal:AbortSignal.timeout(800)});return{ok:!0,url:g}}catch(d){return{ok:!1,url:g,error:d.message}}},zo=t=>t==null||t===0||ho(t)?"":String(t),cn=()=>{let t=(process.env.TERM_PROGRAM||"").toLowerCase(),g=(process.env.VSCODE_CWD||"").toLowerCase(),d=(process.env.VSCODE_CODE_CACHE_PATH||"").toLowerCase(),S=(process.env.GIT_ASKPASS||"").toLowerCase(),w=(process.env.VSCODE_GIT_ASKPASS_NODE||"").toLowerCase(),p=(process.env.VSCODE_GIT_ASKPASS_MAIN||"").toLowerCase();return t==="antigravity"||process.env.ANTIGRAVITY_AGENT||process.env.ANTIGRAVITY_PID||process.env.ANTIGRAVITY_EDITOR_APP_ROOT||process.env.ANTIGRAVITY_CLI_ALIAS||g.includes("antigravity")||d.includes("antigravity")||S.includes("antigravity")||w.includes("antigravity")||p.includes("antigravity")?"Antigravity":t==="cursor"||process.env.CURSOR_SETTINGS_DIR||process.env.CURSOR_CONFIG_DIR||g.includes("cursor")||d.includes("cursor")||S.includes("cursor")||w.includes("cursor")?"Cursor":t==="windsurf"||process.env.WINDSURF_SETTINGS_DIR||g.includes("windsurf")||d.includes("windsurf")||S.includes("windsurf")||w.includes("windsurf")?"Windsurf":t==="trae"||process.env.TRAE_SETTINGS_DIR||g.includes("trae")||w.includes("trae")?"Trae":t==="positron"||g.includes("positron")||w.includes("positron")?"Positron":t==="codium"||t==="vscode-oss"||g.includes("codium")||d.includes("codium")||w.includes("codium")?"VSCodium":t==="vscode-insiders"||g.includes("code - insiders")||d.includes("code - insiders")||w.includes("code - insiders")?"VS Code Insiders":t==="vscode"||process.env.VSCODE_GIT_IPC_HANDLE||process.env.VSCODE_PID||process.env.VSCODE_INJECTION||g.includes("code")||d.includes("code")||w.includes("code")?"VS Code":process.env.INTELLIJ_TERMINAL_COMMAND_BLOCKS||process.env.TERMINAL_EMULATOR?.toLowerCase().includes("jetbrains")?"JetBrains":process.env.WT_SESSION?"Windows Terminal":"Terminal"},uu=t=>{switch(t){case"VS Code":return"Code";case"VS Code Insiders":return"Code - Insiders";case"Antigravity":return"Antigravity IDE";default:return t}},ja={Flux:"Workspace",Flow:"Studio",ICU:"Computer Use",FluxCU:"Omni"},Mi=t=>{if(!t)return"Workspace";let g=Object.keys(ja).find(d=>d.toLowerCase()===t.toLowerCase());return g?ja[g]:t},qa=t=>{let g=uu(t),d=Bi.homedir();if(process.platform==="win32"){let S=process.env.APPDATA;return S?Ct.join(S,g,"User","keybindings.json"):null}else return process.platform==="darwin"?Ct.join(d,"Library","Application Support",g,"User","keybindings.json"):Ct.join(d,".config",g,"User","keybindings.json")},za=t=>{let g=t.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,"$1");return JSON.parse(g)},mu=t=>Array.isArray(t)?t.some(g=>g&&typeof g.key=="string"&&g.key.toLowerCase().replace(/\s+/g,"")==="shift+enter"&&g.command==="workbench.action.terminal.sendSequence"&&g.args&&g.args.text==="\x1B[13;2u"&&typeof g.when=="string"&&g.when.includes("terminalFocus")):!1,Ja=t=>{let g=t==="VS Code",d=[];return g?(d.push({label:"Install Manually (VSIX)",url:"https://github.com/KushalRoyChowdhury/fluxflow-cli/releases"}),d.push({label:"Install from VS Code Marketplace",url:"https://marketplace.visualstudio.com/items?itemName=fluxflow-cli.fluxflow-cli-companion"})):d.push({label:`Download for ${t} (GitHub)`,url:"https://github.com/KushalRoyChowdhury/fluxflow-cli/releases"}),d.push({label:"Continue to CLI only",action:"dismiss"}),d},xu=({width:t,height:g,selectedIndex:d,aiProvider:S,theme:w="Dark"})=>{let p=cn(),r=Ja(p);return e.createElement(m,{flexDirection:"column",alignItems:"center",justifyContent:"center",width:t,height:g},e.createElement(m,{marginBottom:1,width:Math.min(80,t-4),justifyContent:"flex-start"},e.createElement(l,null,br(po,S,w))),e.createElement(m,{flexDirection:"column",borderStyle:"double",borderColor:"grey",paddingX:3,paddingY:1,width:Math.min(80,t-4)},e.createElement(l,{bold:!0,color:"white",textAlign:"center"},"\u{1F680} UPGRADE YOUR WORKFLOW"),e.createElement(m,{marginY:1,flexDirection:"column",alignItems:"left"},e.createElement(l,null,"You're in ",e.createElement(l,{bold:!0,color:"cyan"},p),", but the ",e.createElement(l,{bold:!0,color:"white"},"FluxFlow-CLI Companion")," is not installed."),e.createElement(m,{flexDirection:"column",marginY:1},e.createElement(l,{color:"gray"}," \u2705 Real-time IDE context & Error Resolution"),e.createElement(l,{color:"gray"}," \u2705 Auto-open files created by agent"),e.createElement(l,{color:"gray"}," \u2705 Native DIFFing for AI edits"),e.createElement(l,{color:"gray"}," \u2705 Direct IDE context sharing"),e.createElement(l,{color:"gray"}," \u2705 Surgical Diagnostic Sync"),e.createElement(l,{color:"gray"}," \u2705 Native Right-Click \u276F Chat integration"),e.createElement(l,{color:"gray"}," \u2705 Live Status in IDE"),e.createElement(l,{color:"gray"}," \u2705 Clickable terminal-to-code links"))),e.createElement(m,{flexDirection:"column",marginTop:1},r.map((y,b)=>e.createElement(m,{key:b},e.createElement(l,{color:d===b?"yellow":"white",bold:d===b},d===b?" \u276F ":" ",y.label)))),e.createElement(m,{marginTop:1,alignItems:"center",justifyContent:"center"},e.createElement(l,{dimColor:!0,italic:!0},"(Use arrows to navigate, Enter to select)"))))},fu=({width:t,height:g,aiProvider:d,theme:S="Dark",reason:w})=>{let p=cn(),r=w==="version_mismatch";return e.createElement(m,{flexDirection:"column",alignItems:"center",justifyContent:"center",width:t,height:g},e.createElement(m,{marginBottom:1,width:Math.min(80,t-4),justifyContent:"flex-start"},e.createElement(l,null,br(po,d,S))),e.createElement(m,{flexDirection:"column",borderStyle:"double",paddingX:3,paddingY:1,width:Math.min(80,t-4)},e.createElement(l,{bold:!0,color:"yellow",textAlign:"center"},r?"\u26A0 VERSION MISMATCH":"\u26A0 CWD MISMATCH"),e.createElement(m,{marginY:1,flexDirection:"column",alignItems:"left"},e.createElement(l,null,r?"Your FluxFlow CLI version is not supported by the ":"CWD mismatch from ",!r&&e.createElement(l,{bold:!0,color:"white"},p),!r&&" workspace. ","IDE features aren't available right now."),!r&&e.createElement(m,{marginTop:1},e.createElement(l,{dimColor:!0},"Tip: Launch FluxFlow CLI from the same folder open in ",p,"."))),e.createElement(m,{marginTop:1},e.createElement(l,{color:"yellow",bold:!0}," \u276F Understood")),e.createElement(m,{marginTop:1,alignItems:"center",justifyContent:"center"},e.createElement(l,{dimColor:!0,italic:!0},"(Press Enter to dismiss)"))))},Si=Date.now(),Qa="https://fluxflow-cli.onrender.com/changelog",vi="https://fluxflow-cli.onrender.com/",gu=Ct.join(Ct.dirname(cu(import.meta.url)),"../package.json"),Za=JSON.parse(pt.readFileSync(gu,"utf8")),po=Za.version,hu=Za.date||"2026-05-20";var pu=({data:t,onResolve:g,onEdit:d,theme:S="Dark"})=>{let w=xt(S);return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:w.borderMuted,padding:0,width:"100%"},e.createElement(m,{paddingX:1},e.createElement(l,{color:w.text,bold:!0,underline:!0},t.startsWith("/btw")?"QUESTION":"STEERING HINT"," RESOLUTION")),e.createElement(m,{paddingX:1,marginTop:1},e.createElement(l,{color:w.text},"The agent already finished the task before your ",t.startsWith("/btw")?"question":"hint"," was consumed.")),e.createElement(m,{marginTop:1,backgroundColor:w.cardBg||w.codeBg||"#222",paddingX:2,width:"100%"},e.createElement(l,{italic:!0,color:w.textMuted},'"',t.replace("/btw","").trim(),'"')),e.createElement(m,{paddingX:1,marginTop:1},e.createElement(l,{color:w.textDim||w.textMuted},"How would you like to proceed?")),e.createElement(m,{marginTop:0},e.createElement(Ut,{title:"Select Action",items:[{label:"Send Anyway",value:"send"},{label:"Edit Prompt",value:"edit"}],onSelect:p=>{(typeof p=="object"&&p!==null?p.value:p)==="send"?g(t):d(t)},theme:S})))};var bu=(()=>{let t=null,g=0;return d=>{let S=Date.now();if(t&&S-g<1e4)return t;let w=[],p=r=>{if(!(w.length>=2e3))try{let y=pt.readdirSync(r);for(let b of y){if(w.length>=2e3)return;if(["node_modules",".git",".gemini","dist","build",".next",".cache","out"].includes(b))continue;let C=Ct.join(r,b);pt.statSync(C).isDirectory()?p(C):w.push({name:Wt(b),relativePath:Wt(Ct.relative(process.cwd(),C))})}}catch{}};return p(d),t=w,g=S,w}})(),Ts="Ctrl + Enter",wu=t=>{if(t<=370)return"#00a564";if(t>=5e3)return"#ff0000";let g=[{t:370,r:0,g:165,b:100},{t:550,r:40,g:195,b:80},{t:800,r:120,g:220,b:50},{t:1100,r:190,g:225,b:20},{t:1500,r:250,g:210,b:15},{t:2e3,r:255,g:170,b:0},{t:2800,r:255,g:110,b:0},{t:3800,r:255,g:50,b:0},{t:5e3,r:255,g:0,b:0}];for(let d=0;d<g.length-1;d++){let S=g[d],w=g[d+1];if(t>=S.t&&t<=w.t){let p=(t-S.t)/(w.t-S.t);p=p*p*(3-2*p);let r=Math.round(S.r+(w.r-S.r)*p),y=Math.round(S.g+(w.g-S.g)*p),b=Math.round(S.b+(w.b-S.b)*p);return`#${((1<<24)+(r<<16)+(y<<8)+b).toString(16).slice(1)}`}}return"#ff0000"},Tu=e.memo(({sa:t,showTPMEstimate:g=!1})=>{let[d,S]=J("green"),[w,p]=J(0),r=Ze([]),y=Ze(370),b=Ze([]),C=Ze(t.lastChunkTime);return gt(()=>{C.current=t.lastChunkTime},[t.lastChunkTime]),gt(()=>{if(t.status!=="running"){b.current=[];return}if(t.wps>0){let L=b.current;L.push(t.wps),L.length>3&&L.shift()}},[t.status,t.wps,t.lastChunkTime]),gt(()=>{if(t.status!=="running"){p(0);return}let L=setInterval(()=>{let F=C.current,B=F>0?Date.now()-F:0;if(F>0&&B>=1e3)b.current=[],p(0);else if(F>0&&B>500){b.current.length>0&&b.current.shift();let A=b.current;if(A.length>0){let W=A.reduce((X,_)=>X+_,0);p(Math.round(W/A.length))}else p(0)}else{let A=b.current;if(A.length>0){let W=A.reduce((X,_)=>X+_,0);p(Math.round(W/A.length))}else t.wps>0&&p(Math.round(t.wps))}},750);return()=>clearInterval(L)},[t.status]),gt(()=>{if(t.status!=="running"){r.current=[];return}let L=t.lastChunkTime;if(L>0){let A=r.current;(A.length===0||A[A.length-1]!==L)&&(A.push(L),A.length>10&&A.shift())}let F=()=>{if(!L){S("#00a564");return}let A=r.current,W=0;if(A.length>1){let ne=0;for(let H=1;H<A.length;H++)ne+=A[H]-A[H-1];W=ne/(A.length-1)}let X=Date.now()-L,Y=X>=2500,j=!Y&&W>0?Math.min(X,W*3):X,le=Math.max(W,j),ue=Y?.4:.2;y.current=y.current*(1-ue)+le*ue,S(wu(y.current))};F();let B=setInterval(F,100);return()=>clearInterval(B)},[t.status,t.lastChunkTime]),e.createElement(m,{justifyContent:"space-between",width:"100%"},e.createElement(l,{color:"white"}," \u2022 ",t.title," ",e.createElement(l,{color:"white",dimColor:!0},"(",t.id,")")),e.createElement(l,{color:"white"},e.createElement(l,{color:"white",dimColor:!0,bold:!0},t.currentTool||"Active"),!g&&e.createElement(l,{color:d}," \u25CF"),g&&e.createElement(l,{color:"white",dimColor:!0,bold:!0}," ~",w," tok/s")))});function yu({args:t=[]}){let g=Ze(1),[d,S]=J(!1),[w,p]=J(10),{stdout:r}=iu(),[y,b]=J(""),[C,L]=J(0),F=Ze([]),[B,A]=J(-1),W=Ze(""),X=Ze(null),[_,Y]=J(!1),[j,le]=J("Flux"),[ue,ne]=J(0),[H,pe]=J({columns:r?.columns||80,rows:r?.rows||24}),[Le,Pe]=J(0),[rt,Me]=J(!1),[xe,ye]=J(!1),[Mt,He]=J(null),[ke,Te]=J(0),Q=Ze(null),me=Ze(!1),be=Ze(0),Z=Ze(0),fe=Ze(null),q=Ze(null),Ye=Ze(0),[$e,Tt]=J(0),ct=()=>Tt(n=>n+1),wt=Ze([]),st=Ze(null),qe=()=>{let n=wt.current;if(n.length>0&&q.current){let o=n.join("");n.length=0,q.current.text=Wt(q.current.text+o),ct()}},se=()=>{if(qe(),q.current){let n=Wt(q.current.text||""),o="";if(q.current.role==="agent"&&n){let f=aa(n);f.inside&&typeof f.startIndex=="number"&&f.startIndex>=0?(o=n.substring(f.startIndex),n=n.substring(0,f.startIndex)):n=ra(n)}let c=n;if(q.current.role==="think"&&(c=c.replace(/^\r?\n+/,"").replace(/\r?\n+$/,"")),c.trim().length>0||q.current.role!=="agent"){let f={...q.current,text:c,isStreaming:!1};I(x=>[...x,f]),P(x=>x+1)}o?q.current={id:"agent-"+Date.now(),role:"agent",text:o,isStreaming:!0}:q.current=null}ki.current=0,Ds.current={totalWords:0,startTime:0,wps:0,chunks:[]}},Be=()=>{st.current&&clearInterval(st.current),wt.current=[],st.current=setInterval(()=>{try{let n=wt.current;if(n.length>0&&q.current){let o=1;n.length>85?o=30:n.length>80?o=25:n.length>75?o=20:n.length>65?o=16:n.length>50?o=12:n.length>35?o=8:n.length>15?o=6:n.length>5?o=4:n.length>3&&(o=2);let c="";for(let f=0;f<o&&n.length>0;f++)c+=n.shift();q.current.text=Wt(q.current.text+c),ct()}}catch{}},80)},ut=async()=>{for(;ce.progressiveRendering&&wt.current.length>0;)await new Promise(n=>setTimeout(n,10))},mt=n=>{if(ce.progressiveRendering&&st.current){let o=n.trim();if((o.startsWith("[action:")||o.startsWith("[tool:"))&&o.endsWith("]")){wt.current.push(n);return}let f=Wl(n);for(let x of f)wt.current.push(x)}else q.current?q.current.text=Wt(q.current.text+n):q.current={id:"agent-"+Date.now(),role:"agent",text:Wt(n),isStreaming:!0},ct()};gt(()=>{let n=cn(),o=!["Terminal","Windows Terminal"].includes(n)||!!process.env.VSC_TERMINAL_URL,c=setTimeout(()=>{o&&!Bn()&&!Q.current&&ye(!0)},500),f=setInterval(()=>{Bn()&&(ye(!1),He(null),Q.current=null,me.current=!1)},1e3);g.current=Date.now();let x=setInterval(()=>{g.current&&(Date.now()-g.current||0)>3e4&&global.gc&&(async()=>{for(let a=0;a<1;a++)global.gc(),await new Promise(h=>setImmediate(h));g.current=Date.now()})()},3e3);return()=>{clearTimeout(c),clearInterval(f),clearInterval(x)}},[]),gt(()=>{(async()=>{try{let o=await oi(),c=o?.systemSettings||{},f=c.CustomSubAgent,x=c.SubAgentModel;if(!f||!x||x==="Default")return;let v=process.env.SUBAGENT_MODEL?process.env.SUBAGENT_MODEL.trim():null,u=process.env.SUBAGENT_PROVIDER?process.env.SUBAGENT_PROVIDER.trim():null,a=["Google","DeepSeek","OpenRouter","NVIDIA","Mistral","Ollama","InferX","SenseNova","AIHubMix","Poolside","9router","ExpLabs","TokenHarbor","Infron","APInex","xKiro"],M=(oe=>{if(!oe)return null;let $=oe.toLowerCase();return $==="google"?"Google":$==="deepseek"?"DeepSeek":$==="openrouter"?"OpenRouter":$==="nvidia"?"NVIDIA":$==="mistral"?"Mistral":$==="ollama"?"Ollama":$==="inferx"?"InferX":$==="sensenova"?"SenseNova":$==="poolside"?"Poolside":$==="9router"?"9router":$==="aihubmix"||$==="aihub"?"AIHubMix":$==="explabs"||$==="experientiallabs"||$==="experimentallabs"||$==="experiential labs"||$==="experimental labs"||$==="experiential"||$==="experimental"?"ExpLabs":$==="tokenharbor"||$==="token harbor"||$==="token_harbor"||$==="thk"?"TokenHarbor":$==="apinex"||$==="apx"?"APInex":$==="xkiro"||$==="kiro"?"xKiro":$==="infron"?"Infron":null})(u);if(v&&!M){let oe=o.aiProvider||N||"Google";I($=>(P($.length+1),[...$,{id:"subagent-env-noprov-"+Date.now(),role:"system",text:`[SUBAGENT CONFIG] SUBAGENT_MODEL found in ENV but SUBAGENT_PROVIDER is missing/invalid. Active provider (${oe}) will be used.`,isMeta:!0}]))}if(x==="ENV"){v||I(oe=>(P(oe.length+1),[...oe,{id:"subagent-model-noenv-"+Date.now(),role:"system",text:"No SubAgent model is found in ENV, Using Deafult until changed",isMeta:!0}]));return}let O=o.aiProvider||N||"Google",U=o.apiTier||tt||"Free",K=o.quotas||Ie||{},z=new Set;(tn(O,U)||[]).forEach(oe=>{let $=typeof oe=="string"?oe:oe.cmd||oe.name||oe.id||String(oe);$&&z.add($)});for(let oe of a)try{if(await on(oe,{silent:!0})){let Re=K?.providerTiers?.[oe]||"Free";(tn(oe,Re)||[]).forEach(We=>{let ze=typeof We=="string"?We:We.cmd||We.name||We.id||String(We);ze&&z.add(ze)})}}catch{}let te=z.has(x);v?v!==x&&I(oe=>(P(oe.length+1),[...oe,{id:"subagent-model-env-"+Date.now(),role:"system",text:"Current Seleted Sub-Agent model is not available in this provider. Using model from ENV unless changed.",isMeta:!0}])):te||I(oe=>(P(oe.length+1),[...oe,{id:"subagent-model-err-"+Date.now(),role:"system",text:"Current Seleted Sub-Agent model is not available in this provider. Using Default until changed",isMeta:!0}]))}catch{}})()},[]);let _e=Jn(()=>{let n={};for(let o=0;o<t.length;o++)if(t[o]==="--key"&&t[o+1]){let f=t[o+1];if(n.key=f,f.includes("@")){let x=f.split("@"),v=x[0],u=x[1].toLowerCase();if(["google","deepseek","openrouter","nvidia","mistral","ollama","inferx","sensenova","aihubmix","aihub","poolside","pool","9router","9r","explabs","tokenharbor","token_harbor","thk","infron","apinex","apx","xkiro","kiro"].includes(u)){let a="Google";u==="google"?a="Google":u==="deepseek"?a="DeepSeek":u==="openrouter"?a="OpenRouter":u==="nvidia"?a="NVIDIA":u==="mistral"?a="Mistral":u==="ollama"?a="Ollama":u==="inferx"?a="InferX":u==="sensenova"?a="SenseNova":u==="poolside"||u==="pool"?a="Poolside":u==="9router"||u==="9r"?a="9router":u==="aihubmix"||u==="aihub"?a="AIHubMix":u==="explabs"?a="ExpLabs":u==="tokenharbor"||u==="token_harbor"||u==="thk"?a="TokenHarbor":u==="infron"?a="Infron":u==="apinex"||u==="apx"?a="APInex":(u==="xkiro"||u==="kiro")&&(a="xKiro"),n.key=v,n.provider=a}}}for(let o=0;o<t.length;o++){let c=t[o];if(c==="--key"){o++;continue}if(c==="--model"&&t[o+1])n.model=t[o+1],o++;else if(c==="--memory"&&t[o+1])n.memory=t[o+1].toLowerCase(),o++;else if(c==="--resume"&&t[o+1])n.resume=t[o+1],o++;else if(c==="--package"&&t[o+1]){let f=t[o+1].toLowerCase();["npm","pnpm","yarn","bun"].includes(f)&&(n.package=f),o++}else if(c==="--auto-del"&&t[o+1]){let f=t[o+1].toLowerCase();["1d","7d","30d"].includes(f)&&(n.autoDel=f),o++}else if(c==="--auto-exec"&&t[o+1])n.autoExec=t[o+1].toLowerCase(),o++;else if(c==="--yolo"&&t[o+1])n.autoExec=t[o+1].toLowerCase(),o++;else if(c==="--external-access"&&t[o+1])n.externalAccess=t[o+1].toLowerCase(),o++;else if(c==="--mode"&&t[o+1]){let x=t[o+1].toLowerCase();if(["flux","flow","icu","computer","fluxcu"].includes(x)){let v="Flux";x==="flux"?v="Flux":x==="flow"?v="Flow":x==="icu"||x==="computer"?v="ICU":x==="fluxcu"&&(v="FluxCU"),n.mode=v}o++}else if(c==="--thinking"&&t[o+1]){let x=t[o+1].toLowerCase();if(["fast","low","medium","high","xhigh","standard"].includes(x)){let v="Medium";x==="fast"?v="Fast":x==="low"?v="Low":x==="standard"?v="Standard":x==="medium"?v="Medium":x==="high"?v="High":x==="xhigh"&&(v="xHigh"),n.thinking=v}o++}else if(c==="--provider"&&t[o+1]){let f=t[o+1].toLowerCase();if(["google","deepseek","openrouter","nvidia","mistral","ollama","inferx","sensenova","aihubmix","aihub","poolside","pool","9router","9r","explabs","tokenharbor","token_harbor","thk","infron","apinex","apx","xkiro","kiro"].includes(f)){let x="Google";f==="google"?x="Google":f==="deepseek"?x="DeepSeek":f==="openrouter"?x="OpenRouter":f==="nvidia"?x="NVIDIA":f==="mistral"?x="Mistral":f==="ollama"?x="Ollama":f==="inferx"?x="InferX":f==="sensenova"?x="SenseNova":f==="poolside"||f==="pool"?x="Poolside":f==="9router"||f==="9r"?x="9router":f==="aihubmix"||f==="aihub"?x="AIHubMix":f==="explabs"?x="ExpLabs":f==="tokenharbor"||f==="token_harbor"||f==="thk"?x="TokenHarbor":f==="infron"?x="Infron":f==="apinex"||f==="apx"?x="APInex":(f==="xkiro"||f==="kiro")&&(x="xKiro"),n.provider=x}o++}else(c==="--resume"||c==="-r")&&t[o+1]?(n.resume=t[o+1],o++):c==="--playground"?n.playground=!0:(c==="--original-cwd"||c==="--orginal-cwd")&&t[o+1]&&(n.originalCwd=t[o+1],o++)}return n},[t]),Bt=async(n=!1,o=null)=>{let c=o||ce;n&&I(f=>(P(f.length+1),[...f,{id:"check-"+Date.now(),role:"system",text:"\u2726 Checking for updates...",isMeta:!0}]));try{let x=await(await fetch("https://registry.npmjs.org/fluxflow-cli",{cache:"no-store"})).json(),v=x["dist-tags"]?.latest,u=x["dist-tags"]?.stable;if(v&&Lr(v),v&&v!==po){let a=v===u?`v${v}`:`v${v}`;!n&&c.autoUpdate?re("update"):I(h=>{let M=[...h],O=n?M.length:Math.min(M.length,3);return M.splice(O,0,{id:"update-"+Date.now(),role:"system",text:`A new version (${a}) is here.
63
-
64
- \u2022 Type \`/update latest\` to apply the update.
65
- \u2022 Type \`/changelog\` to view the release notes.`,isUpdateNotification:!0,isMeta:!0}),M})}else n&&I(a=>{P(a.length+1);let h=v&&v===u?`${po}`:po;return[...a,{id:"uptodate-"+Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Already up to date (${h}).
66
- \u2800`,isMeta:!0}]})}catch(f){n&&I(x=>(P(x.length+1),[...x,{id:"check-err-"+Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Failed to check for updates: ${f.message}.
67
- \u2800`,isMeta:!0}]))}};gt(()=>{let n=r?.columns||80,o=()=>{let c=r?.columns||80,f=r?.rows||24;c!==n&&(n=c,r.write("\x1B[2J\x1B[3J\x1B[H")),pe({columns:c,rows:f})};return r.on("resize",o),()=>{r.off("resize",o)}},[r]);let[Xe,ro]=J("Medium"),[N,Qo]=J("Google"),[er,Ar]=J(0),[dn,Lr]=J(null),[un,ys]=J(!1),[je,Gt]=J(co("Google","Free")||"gemma-4-31b-it"),[Pr,Se]=J(!1),[ae,T]=J(!1),[k,ve]=J(yl("gemma_janitor_fallback_google")||"gemma-4-26b-a4b-it"),[Ne,at]=J(!0),[dt,et]=J(!0),so=Ze(0),[Ke,Ot]=J(null),[mn,xn]=J(""),Cs=async n=>{let o=qa(n);if(o)try{await pt.ensureDir(Ct.dirname(o));let c=[];if(pt.existsSync(o)){let f=pt.readFileSync(o,"utf8").trim();if(f)try{c=za(f)}catch{c=[]}}Array.isArray(c)||(c=[]),c.push({key:"shift+enter",command:"workbench.action.terminal.sendSequence",args:{text:"\x1B[13;2u"},when:"terminalFocus"}),pt.writeFileSync(o,JSON.stringify(c,null,4),"utf8"),Ts="Shift + Enter",I(f=>(P(f.length+1),[...f,{id:"kb-success-"+Date.now(),role:"system",text:`\u2726 Successfully configured Shift+Enter in your ${n} keybindings!
68
- `,isMeta:!0}]))}catch(c){I(f=>(P(f.length+1),[...f,{id:"kb-error-"+Date.now(),role:"system",text:`\u2726 Failed to update keybindings: ${c.message}.
69
- \u2800`,isMeta:!0}]))}},[St,re]=J("chat"),[In,Or]=J([]),Nr=y.startsWith("/k");gt(()=>{if(!Nr)return;let n=!0,o=async()=>{try{let f=await xa(process.pid);n&&Or(f||[])}catch{}};o();let c=setInterval(o,5e3);return()=>{n=!1,clearInterval(c)}},[Nr]);let[tt,It]=J("Free"),[Ie,eo]=J({limitMode:"Daily",agentLimit:99999999,tokenLimit:99999999999999,backgroundLimit:999999,searchLimit:100,customModelId:"",customLimit:0,providerBudgets:{}}),[Do,io]=J(null),[_o,Ra]=J("chat"),[Jo,Ms]=J("settings"),[kn,ec]=J([]),[Cu,tc]=J(0),[Ei,Fr]=J(0),[Ss,Di]=J({}),[tr,or]=J({}),[An,bo]=J(0),[ce,Nt]=J({memory:!0,theme:"Dark",compression:0,autoExec:!1,autoDeleteHistory:"7d",autoUpdate:!1,updateManager:"npm",customUpdateCommand:"",clipboardContext:!1}),s=Jn(()=>xt(ce.theme),[ce.theme]),[fn,vs]=J({preset:"Default",name:null,nickname:null,instructions:null}),[Ho,$r]=J({keyType:"Default",quality:"Low-High",apiKey:""}),[nr,Bs]=J({enabled:!1,model:"Default",provider:"",baseUrl:""}),[Io,Zo]=J({tokens:0}),[Ii,Es]=J(0),ki=Ze(0),Ds=Ze({totalWords:0,startTime:0,wps:0,chunks:[]}),[Ai,Li]=J(0),[Pi,oc]=J(0),[lo,Oi]=J(0),[nc,Ln]=J(0),Pn=Ze(0),[rc,On]=J(0),[sc,gn]=J(0),zt=Ze([]),Nn=Ze(0),[ic,Fn]=J(0),$n=Ze(0),[hn,Ni]=J(0),[wo,Fi]=J(0),[Un,$i]=J(0),[Mu,lc]=J(0),[Su,ac]=J(0),[vu,cc]=J(0),[Ur,dc]=J(0),[_r,uc]=J(0),[Hr,mc]=J(0),[Ui,xc]=J(0),[_n,Is]=J(null),[rr,ks]=J(null),[Wr,_i]=J(null),[Hn,sr]=J("daily"),[fc,To]=J(0),[ir,lr]=J(""),Wn="flow-playground",[bt,Xr]=J(t.includes("--playground")?Wn:li());gt(()=>{if(Wo.current)return;let n=lo-Pn.current,o=wo-Nn.current,c=hn-$n.current;Ln(n),On(o),Fn(Math.max(0,c)),bt&&Zl(bt,n,Io.tokens).catch(()=>{})},[lo,wo,hn,bt,Io.tokens]),gt(()=>{St==="apiTier"&&(async()=>{let o=await Zr();Is(o);let c=await Rr();ks(c);let f=await ni(Ie.resetDay||1);_i(f)})()},[St,Ie.resetDay]);let[yo,Hi]=J(null),[Xn,Gn]=J(""),[ar,Wi]=J(!1),[As,gc]=J([]),[Bu,Eu]=J(0),Ls=Ze(!0),Xi=Ze(!0),Ps=Ze(N),Os=Ze(!1),Ns=Ze(!0);gt(()=>{(Pr||ae)&&(I(n=>(P(n.length+1),[...n,{id:Date.now(),role:"system",text:`\u2726 Wild${ae?"er":""}Card Tooling:
70
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Status: Disabled.
71
- \u2800`,isMeta:!0}])),Se(!1),T(!1)),process.env.forcedReasoning&&(I(n=>(P(n.length+1),[...n,{id:Date.now(),role:"system",text:`\u2726 Forced Reasoning:
72
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Status: Disabled.
73
- \u2800`,isMeta:!0}])),process.env.forcedReasoning=!1),Xe==="xHigh"&&!Ls.current&&ro("Medium")},[je]);let Gi;gt(()=>{if(Xi.current){Gi=setTimeout(()=>{Xi.current=!1,Ps.current=N},1e3);return}return Ps.current!==N&&(Ps.current=N,ro(N==="SenseNova"||N==="Poolside"?"High":"Low")),()=>{clearTimeout(Gi)}},[N,je]);let Ki;gt(()=>{if(!Ke)return;if(Ls.current){Ki=setTimeout(()=>{Ls.current=!1},1500);return}let n=co(N,tt),o=n;return n.includes("gemma")?o="Gemma":n.includes("deepseek")?o="DeepSeek Flash":n.includes("devstral")?o="Devstral":n.includes("mistral")?o="Mistral":n.includes("gemini")&&(o="Gemini Flash"),Gt(n),Kt({apiTier:tt,activeModel:n}),()=>{clearTimeout(Ki)}},[tt,N,Ke]);let hc=Jn(()=>{let n=cn();return{isIDE:!["Terminal","Windows Terminal"].includes(n)||!!process.env.VSC_TERMINAL_URL||!!process.env.INTELLIJ_TERMINAL_COMMAND_BLOCKS,get shortcut(){return Ts}}},[]),Fs=Ze(null),$s=Ze("");gt(()=>{Fs.current=yo},[yo]),gt(()=>{$s.current=Xn},[Xn]);let[Vi,Us]=J(!1),Yi=Ze(new Set),ji=Ze(new Set),qi=Ze(new Set),[to,Kn]=J(null),[pn,_s]=J(null),ko=n=>{Kn(null),re("chat")},zi=n=>{let o=Math.floor(n/3600),c=Math.floor(n%3600/60),f=n%60,x=[];return o>0&&x.push(`${o}h`),(c>0||o>0)&&x.push(`${c}m`),x.push(`${f}s`),x.join(" ")},bn=n=>n<1e3?`${n}ms`:zi(Math.floor(n/1e3)),[Ro,Hs]=J(null),[Ws,Qi]=J(""),[pc,bc]=J(!1),[Ji,cr]=J(0),dr;gt(()=>{let n;if(Ro&&ce.loadingPhrases!==!1){let o=f=>{Qi(f[Math.floor(Math.random()*f.length)])},c=()=>{Rn?o(Rn):process.env.HALLOWEEN_EEGG==="true"||process.env.HALLOWEEN_EEGG===!0?import("./halloween_witty_phrases-IJGE3RWX.js").then(({HALLOWEEN_WITTY_PHRASES:x})=>{Rn=x,o(Rn)}):import("./witty_phrases-EEDEYYAH.js").then(({WITTY_LOADING_PHRASES:x})=>{Rn=x,o(Rn)})};Ws||c(),n=setInterval(c,1e4)}else Qi("");return()=>{clearInterval(n)}},[Ro,ce]);let[Du,wc]=J(!0),[Vn,Xs]=J(!1),[ur,Zi]=J(!1),[Tc,yc]=J(!1),[Ri,Iu]=J(null),[el,mr]=J(0),[Cc,tl]=J([]),wn=Ze(null),Wo=Ze(!1);gt(()=>()=>{wn.current&&clearTimeout(wn.current)},[]);let Gs=Ze(!1),[xr,Ks]=J(null),[Mc,Vs]=J(null),[ku,Sc]=J(null);gt(()=>mr(0),[y]);let[Ft,vc]=J(()=>{let n={id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0},o=process.cwd()===Bi.homedir(),c=(()=>{let x=process.cwd().toLowerCase();if(process.platform==="win32"){let v=process.env.SystemRoot?.toLowerCase()||"c:\\windows",u=process.env.ProgramFiles?.toLowerCase()||"c:\\program files",a=process.env["ProgramFiles(x86)"]?.toLowerCase()||"c:\\program files (x86)";return x.startsWith(v)||x.startsWith(u)||x.startsWith(a)}else return x==="/"||["/bin","/sbin","/etc","/usr","/var","/root"].some(u=>x.startsWith(u))})(),f=[n];return c?f.push({id:"system-warning",role:"system",text:"[CRITICAL SECURITY ALERT] SYSTEM DIRECTORY DETECTED",subText:`You are currently in a PROTECTED SYSTEM DIRECTORY (${process.cwd()}). Operating here is EXTREMELY dangerous as the agent could accidentally corrupt your OS or installed applications. Open FluxFlow in project folder to work safely.`,isHomeWarning:!0}):o&&f.push({id:"home-warning",role:"system",text:"[SECURITY ALERT] HOME DIRECTORY DETECTED",subText:`You are currently in ${Bi.homedir()}. Working here is high-risk as the agent may modify system-sensitive configurations. Please open FluxFlow in project folder.`,isHomeWarning:!0}),f}),I=n=>{vc(o=>{let c=typeof n=="function"?n(o):n;if(c.length>1){let f=c[c.length-1],x=c[c.length-2];if(f?.text?.includes("Request Cancelled")&&x?.text?.includes("Request Cancelled"))return c.slice(0,-1)}return c})},Xo=Ze(null),[ol,Bc]=J(""),[nl,rl]=J(!1),sl=Ze(""),il=Ze(null);gt(()=>{if(Ft.length===0)return;let n=Ft[Ft.length-1];if(n&&(n.role==="agent"||n.role==="assistant")){let c=(n.text||"").match(/\[ANSWER\]([\s\S]*?)(?:\[\/ANSWER\]|$)/i);if(c){let f=c[1].trim();f&&f!==sl.current&&(Bc(f),sl.current=f,il.current!==n.id&&rl(!0))}}},[Ft]);let[en,P]=J(Ft.length),[Tn,Ys]=J(0),Au=Ze([]),ao=Ze({completedIndex:0,columns:0,historicalBlocks:[],seenSelections:new Set,chatId:"",clearKey:0,theme:""}),ll=Jn(()=>{let n=H.columns||80,o=/Selection: (.*)/,c=[],f=new Set,x=ao.current.columns!==n,v=en<ao.current.completedIndex,u=ao.current.chatId!==bt,a=ao.current.clearKey!==Tn,h=ao.current.theme!==ce.theme;if(x||v||u||a||h){let z=Ft.slice(0,en);for(let V=0;V<z.length;V++){let te=z[V];if(te.isAskRecord&&te.text){let $=te.text.match(o);if($&&$[1].trim()){let Re=$[1].trim();if(f.has(Re))continue;f.add(Re)}}let oe=pr(te,n);for(let $=0;$<oe.completed.length;$++)c.push(oe.completed[$]);for(let $=0;$<oe.active.length;$++)c.push(oe.active[$])}ao.current={completedIndex:en,columns:n,historicalBlocks:c,seenSelections:new Set(f),chatId:bt,clearKey:Tn,theme:ce.theme}}else if(c=ao.current.historicalBlocks,f=ao.current.seenSelections,en>ao.current.completedIndex){c=[...c],f=new Set(f);let z=Ft.slice(ao.current.completedIndex,en);for(let V=0;V<z.length;V++){let te=z[V];if(te.isAskRecord&&te.text){let $=te.text.match(o);if($&&$[1].trim()){let Re=$[1].trim();if(f.has(Re))continue;f.add(Re)}}let oe=pr(te,n);for(let $=0;$<oe.completed.length;$++)c.push(oe.completed[$]);for(let $=0;$<oe.active.length;$++)c.push(oe.active[$])}ao.current={completedIndex:en,columns:n,historicalBlocks:c,seenSelections:f,chatId:bt,clearKey:Tn}}let M=Ft.slice(en),O=[],U=[];for(let z=0;z<M.length;z++){let V=M[z];if(V.isAskRecord&&V.text){let oe=V.text.match(o);if(oe&&oe[1].trim()){let $=oe[1].trim();if(f.has($))continue}}let te=pr(V,n);for(let oe=0;oe<te.completed.length;oe++)O.push(te.completed[oe]);for(let oe=0;oe<te.active.length;oe++)U.push(te.active[oe])}if(q.current){let z=pr(q.current,n);for(let V=0;V<z.completed.length;V++)O.push(z.completed[V]);for(let V=0;V<z.active.length;V++)U.push(z.active[V])}let K=O.length===0?c:c.concat(O);return K.length>=75e3&&(K=[...K],K.push({key:`memory-warning-block-${K.length}`,msg:{role:"system",text:"\u26A0\uFE0F MEMORY WARNING: CHAT IS GETTING VERY LONG",subText:`This session has reached ${K.length} blocks. To maintain optimal performance and prevent high memory usage, it is highly recommended to save and start a clean chat with /clear.`,isHomeWarning:!0},type:"full-message"})),{completed:K,active:U}},[Ft,en,H.columns,Tn,bt,$e]),Ec=Jn(()=>{if(!yo||!Xn)return!1;let n=Xn.trim();return n.endsWith("?")||n.endsWith(":")||/\[[yYnN/]+\]\s*$/.test(n)||/\([yYnN]\)\s*$/.test(n)},[yo,Xn]);su((n,o)=>{if(!(n==="\x1B[I"||n==="\x1B[O"||n==="[I"||n==="[O")){if(o.ctrl&&(n.toLowerCase()==="r"||n===""||n==="")){Ma();return}if(St==="stats"){if(Hn==="dailyModelBreakdown"||Hn==="modelBreakdown"){if(o.tab&&!o.shift){sr(f=>f==="dailyModelBreakdown"?"modelBreakdown":"dailyModelBreakdown"),To(0);return}if(o.space||n===" "){sr(f=>f==="dailyModelBreakdown"?"daily":"monthly"),To(0),lr("");return}if(o.escape){if(ir){lr(""),To(0);return}re("chat");return}if(o.upArrow){To(f=>Math.max(0,f-1));return}if(o.downArrow){To(f=>Math.min(Z.current,f+1));return}if(o.backspace||o.delete){lr(f=>f.slice(0,-1)),To(0);return}if(n&&n!==" "&&!o.space&&!o.ctrl&&!o.meta&&n.length===1&&n.charCodeAt(0)>=32){lr(f=>f+n),To(0);return}return}if(o.tab&&!o.shift){sr(f=>f==="daily"?"monthly":"daily"),To(0);return}if(o.space||n===" "){sr(f=>f==="daily"?"dailyModelBreakdown":"modelBreakdown"),To(0),lr("");return}if(o.upArrow){To(f=>Math.max(0,f-1));return}if(o.downArrow){To(f=>Math.min(Z.current,f+1));return}}if(Mt){(o.return||o.escape)&&(me.current=!0,He(null));return}if(xe){let c=cn(),f=Ja(c);if(o.upArrow)Te(x=>x>0?x-1:f.length-1);else if(o.downArrow)Te(x=>x<f.length-1?x+1:0);else if(o.return){let x=f[ke];if(x.action==="dismiss")ye(!1);else if(x.url){let v=process.platform==="win32"?`start ${x.url}`:process.platform==="darwin"?`open ${x.url}`:`xdg-open ${x.url}`;Uo(v),ye(!1)}}return}if(o.tab&&yo){Wi(c=>!c);return}if(ar&&yo){let c=o.pageUp||n==="\x1B[5~"||n==="[5~",f=o.pageDown||n==="\x1B[6~"||n==="[6~",x=o.ctrl&&(n==="o"||n==="");if(c||f||x)return;if(o.return)if(jn)uo("\r");else{let v=process.platform==="win32";uo(v?`\r
74
- `:`
75
- `),Gn(u=>u+`
76
- `)}else if(o.backspace||o.delete)jn?uo("\x7F"):(uo("\b \b"),Gn(v=>v.slice(0,-1)));else if(o.upArrow)uo(o.shift?"\x1B[1;2A":"\x1B[A");else if(o.downArrow)uo(o.shift?"\x1B[1;2B":"\x1B[B");else if(o.rightArrow)uo(o.shift?"\x1B[1;2C":"\x1B[C");else if(o.leftArrow)uo(o.shift?"\x1B[1;2D":"\x1B[D");else if(o.escape)uo("\x1B");else if(o.ctrl&&n){let v=n.toLowerCase().charCodeAt(0);v>=97&&v<=122?uo(String.fromCharCode(v-96)):uo(n)}else n&&(uo(n),jn||Gn(v=>v+n));return}if(St==="providerBudgetSelect"){let c=["Google","DeepSeek","Mistral","NVIDIA","OpenRouter","Ollama","InferX","SenseNova","AIHubMix","Poolside","ExpLabs","TokenHarbor","Infron","APInex","xKiro"];if(o.upArrow){Fr(f=>(f-1+c.length)%c.length);return}else if(o.downArrow){Fr(f=>(f+1)%c.length);return}else if(n===" "){let f=c[Ei];Di(x=>({...x,[f]:!x[f]}));return}else if(o.return){let f=c.filter(v=>Ss[v]);if(f.length===0)return;let x={...Ie,providerBudgets:{...Ie.providerBudgets||{},__useProvider:!0}};eo(x),ec(f),tc(0),Fr(0),re("providerBudgetFlow");return}else if(o.escape){re("budgetTypeSelect");return}return}if(St==="providerBudgetFlow"){let c=kn.length,f=c*4+1;if(o.upArrow){bo(x=>x===f-1?Math.max(0,(c-1)*4):x>=4?x-4:x);return}else if(o.downArrow){bo(x=>x===f-1?x:x+4<f-1?x+4:f-1);return}else if(o.leftArrow){bo(x=>x===f-1?x:x%4>0?x-1:x);return}else if(o.rightArrow||o.tab){bo(x=>x===f-1?x:x+1<f?x+1:x);return}else if(o.return){if(An===f-1){let x=Ie.providerBudgets||{},v={__useProvider:!0};for(let h of kn){let M=tr[h]||{};v[h]={agentLimit:9999999999,tokenLimit:parseInt(M.tokenLimit,10)||0,monthlyTokenLimit:parseInt(M.monthlyTokenLimit,10)||0,dailyCostLimit:parseFloat(M.dailyCostLimit)||0,monthlyCostLimit:parseFloat(M.monthlyCostLimit)||0}}let u={...Ie,providerBudgets:v};eo(u),Kt({apiTier:tt,quotas:u}),re(_o==="settings"?"resetMode":"budgetResetMode")}else bo(x=>Math.min(f-1,x+1));return}else if(o.escape){re("providerBudgetSelect");return}return}if(o.escape){if(nl){if(rl(!1),Ft.length>0){let c=Ft[Ft.length-1];c&&(il.current=c.id)}return}if(lt.length>0&&St==="chat"){Me(!0);return}if(d){S(!1);return}if(Vn||yo||to||pn)Gs.current=!0,sa(),Yl(),to&&(to.resolve("deny"),Kn(null)),pn&&(pn.resolve(null),_s(null)),yc(!1),Ri&&clearTimeout(Ri);else if(St==="revert")re("chat"),mr(0);else if(St!=="chat"&&St!=="settings")re("chat");else{if(!Ke&&er===1){Ar(0),xn("");return}mr(c=>{let f=c+1;return f===1?(wn.current&&clearTimeout(wn.current),wn.current=setTimeout(()=>mr(0),2e3)):f===2&&(wn.current&&clearTimeout(wn.current),mr(0),y.length>0?b(""):wr.getChatHistory(bt).then(x=>{x.length>0?(tl(x.reverse()),re("revert")):I(v=>(P(v.length+1),[...v,{id:"revert-empty-"+Date.now(),role:"system",text:`\u2726 Nothing to revert to.
77
- \u2800`,isMeta:!0}]))})),f})}}if(lt.length>0&&St==="chat"&&B===-1){if(o.upArrow){Pe(c=>{let f=c>0?c-1:lt.length-1,x=0;for(;f!==c&&x<lt.length;){let v=lt[f],u=v?.cmd||v||"";if(typeof u=="string"&&u.trimStart().startsWith("---"))f=f>0?f-1:lt.length-1,x++;else break}return f});return}if(o.downArrow){Pe(c=>{let f=c<lt.length-1?c+1:0,x=0;for(;f!==c&&x<lt.length;){let v=lt[f],u=v?.cmd||v||"";if(typeof u=="string"&&u.trimStart().startsWith("---"))f=f<lt.length-1?f+1:0,x++;else break}return f});return}if(o.return)return}if(o.tab&&St==="chat"){if(lt.length>0){let c=lt[Le]||lt[0],f=y.split(" ");if(f.length===1)b(c.cmd+" ");else{let x=f.slice(0,-1);b(x.join(" ")+" "+c.cmd+" ")}Pe(0),L(x=>x+1);return}else if(y.trim()===""){let c=Date.now();if(c-Ye.current<500)return;Ye.current=c;let f=["Flux","Flow","ICU","FluxCU"],x=(f.indexOf(j)+1)%f.length,v=f[x>=0?x:0];le(v),I(u=>[...u,{id:Date.now(),role:"system",text:`\u2726 Mode switched to ${Mi(v)}
78
- \u2800`,isMeta:!0}]);return}}if(o.ctrl&&n==="c"&&St!=="exit"){if(y.length>0){b("");return}if(o.shift){re("exit"),S(!1);return}d?(re("exit"),S(!1)):S(!0)}o.return&&(o.shift||o.ctrl||o.meta||o.leftAlt||o.rightAlt)&&b(c=>c.replace(/\\\r?$/,"").replace(/\r?$/,"")+`
79
- `)}}),gt(()=>{process.stdout.write("\x1B[?1004h");let n=o=>{let c=o.toString();c.includes("\x1B[I")?(et(!0),so.current=Date.now()):c.includes("\x1B[O")&&(et(!1),so.current=Date.now())};return process.stdin.on("data",n),()=>{process.stdout.write("\x1B[?1004l"),process.stdin.off("data",n)}},[]);let Gr=Ze(ce.theme);gt(()=>{Gr.current&&Gr.current!==ce.theme?(Gr.current=ce.theme,r&&(r.write("\x1B[2J\x1B[3J\x1B[H"),r.isTTY&&r.write("\x1B[?2004h")),Ys(n=>n+1),Go()):Gr.current=ce.theme},[ce.theme,r]),gt(()=>{async function n(){zl(M=>{let O=M?.reason||"cwd_mismatch";Q.current=O,ye(!1),me.current||He(O)});try{let M=JSON.parse(pt.readFileSync(Ct.join(process.cwd(),"package.json"),"utf8"));ii(po||M.version||"2.0.0")}catch{ii("2.0.0")}process.stdout.isTTY&&(process.stdout.write("\x1B]0;FluxFlow\x07"),process.stdout.write("\x1B]633;P;TerminalTitle=FluxFlow\x07")),await Wa()||(I(M=>(P(M.length+1),[...M,{id:"setup-"+Date.now(),role:"system",text:"\u2726 Installing Required dependencies... (One-time setup)",isMeta:!0}])),await Xa(),I(M=>(P(M.length+1),[...M,{id:"setup-done-"+Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m All dependencies installed successfully.
80
- \u2800`,isMeta:!0}])));let o=await oi();Os.current=o.systemSettings?.allowExternalAccess??!1,Ns.current=o.systemSettings?.memory??!0,_e.mode?le(_e.mode):le(o.mode),ne(o.display??0),_e.thinking?ro(_e.thinking):ro(o.thinkingLevel);let c=_e.provider||o.aiProvider||"Google";Qo(c);let x=(o.quotas?.providerTiers||{})[c]||o.apiTier||"Free";if(fe.current=o.activeModel,_e.model)Gt(_e.model);else if(_e.provider){let M=co(c,x);Gt(M)}else Gt(o.activeModel);ys(o.showFullThinking),It(x),eo(o.quotas||{limitMode:"Daily",agentLimit:99999999,tokenLimit:99999999999999,backgroundLimit:999999,searchLimit:100,customModelId:"",customLimit:0,providerBudgets:{}});let v={memory:!0,compression:0,autoExec:!1,autoDeleteHistory:"7d",autoUpdate:!1,updateManager:"npm",customUpdateCommand:"",...o.systemSettings||{}};_e.memory==="on"?v.memory=!0:_e.memory==="off"&&(v.memory=!1),c==="NVIDIA"&&process.env.NVIDIA_BASE_URL&&(v.memory=!1,I(M=>[...M,{role:"system",text:`\u2726 MEMORY
81
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Currently not available.
82
- \u2800`,isMeta:!0}])),_e.package&&(v.updateManager=_e.package),_e.autoDel&&(v.autoDeleteHistory=_e.autoDel),_e.autoExec==="on"?v.autoExec=!0:_e.autoExec==="off"&&(v.autoExec=!1),_e.externalAccess==="on"?v.allowExternalAccess=!0:_e.externalAccess==="off"&&(v.allowExternalAccess=!1),_e.playground&&(v.allowExternalAccess=!1,v.memory=!1),Nt(v),vs(o.profileData),$r(o.imageSettings||{keyType:"Default",quality:"Low-High",apiKey:""}),Bs({enabled:!1,model:"Default",provider:"",baseUrl:"",...o.autoCompletion||{}});let u=_e.key;if(u||(u=await on(c)),c==="c_openai"){let M=u||"";Ot(M),fo(M,{aiProvider:c,onIDEApproval:ko})}else u&&(Ot(u),fo(u,{aiProvider:c,onIDEApproval:ko}));if(o.systemSettings?.autoDeleteHistory&&Jl(o.systemSettings.autoDeleteHistory),_e.playground||(os(Wn).catch(()=>{}),pt.remove(Ct.join(Ao,"playground")).catch(()=>{})),Bt(!1,v),await Promise.all([_l(),wr.recoverCrashedTransaction()]),_e.resume){let M=await Ko(),O=_e.resume;if(M[O]){Wo.current=!0,Xr(O);let U=await yr(O);Pn.current=lo-U.total,Nn.current=wo,$n.current=hn,zt.current=[],Ln(U.total),On(0),gn(0),Fn(0),Zo({tokens:U.context}),Wo.current=!1;let K=[...M[O].messages];K[0]?.text?.includes("\u2591\u2591\u2591\u2588\u2588\u2588")||K.unshift({id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}),I(K),re("chat"),I(V=>{let te=[...V,{id:"sys-"+Date.now(),role:"system",text:`\u2726 SESSION RESUMED
83
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m '${O}'.
84
- \u2800`,isMeta:!0}];return P(te.length),te})}else I(U=>[...U,{id:"sys-err-"+Date.now(),role:"system",text:`\u2726 Chat session [${O}] not found. Started new session.
85
- \u2800`,isMeta:!0}])}if(_e.playground){let M=Ct.join(Ao,"playground");try{pt.ensureDirSync(M),process.chdir(M)}catch{}let O=await Ko();if(O[Wn]){Wo.current=!0;let U=await yr(Wn);Pn.current=lo-U.total,Nn.current=wo,$n.current=hn,zt.current=[],Ln(U.total),On(0),gn(0),Fn(0),Zo({tokens:U.context}),Wo.current=!1;let K=[...O[Wn].messages];K[0]?.isLogo||K.unshift({id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}),I(K),I(z=>{let V=[...z,{id:"playground-"+Date.now(),role:"system",text:`\u2726 PLAYGROUND Session restored
86
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m CWD locked to: '${M}'.
87
- \u2800`,isMeta:!0}];return P(V.length),V})}else I(U=>{let K=[...U,{id:"playground-"+Date.now(),role:"system",text:`\u2726 PLAYGROUND Mode active
88
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m CWD locked to: 'FluxFlow/playground'.
89
- \u2800`,isMeta:!0}];return P(K.length),K})}let a=cn();if(!["Terminal","Windows Terminal"].includes(a)){let M=qa(a);if(M)try{let O=[];if(pt.existsSync(M)){let U=pt.readFileSync(M,"utf8").trim();U&&(O=za(U))}mu(O)?Ts="Shift + Enter":re("keybindingsPrompt")}catch{}}at(!1)}n()},[]),gt(()=>{let n;return d&&(p(10),n=setInterval(()=>{p(o=>o<=1?(S(!1),0):o-1)},1e3)),()=>{n&&clearInterval(n)}},[d]),gt(()=>{if(!Ne){let n=_e.model&&je===_e.model?fe.current:je,o=ce;_e.playground&&(o={...ce,allowExternalAccess:Os.current,memory:Ns.current}),Kt({mode:j,thinkingLevel:Xe,aiProvider:N,activeModel:n||je,showFullThinking:un,systemSettings:o,profileData:fn,imageSettings:Ho,autoCompletion:nr,apiTier:tt})}},[j,Xe,N,je,un,ce,fn,Ho,nr,Ne,_e,tt]);let al=async n=>{let o=n.trim(),c={Google:{prefix:"",minLength:0},OpenRouter:{prefix:"",minLength:0},DeepSeek:{prefix:"",minLength:0},Mistral:{prefix:"",minLength:0},NVIDIA:{prefix:"",minLength:0},Ollama:{prefix:"",minLength:0},InferX:{prefix:"",minLength:0},SenseNova:{prefix:"",minLength:0},AIHubMix:{prefix:"",minLength:0},Poolside:{prefix:"",minLength:0},"9router":{prefix:"",minLength:0},ExpLabs:{prefix:"",minLength:0},TokenHarbor:{prefix:"",minLength:0},Infron:{prefix:"",minLength:0},APInex:{prefix:"",minLength:0},xKiro:{prefix:"",minLength:0}},{prefix:f,minLength:x}=c[N]??{prefix:"",minLength:0},v=(N==="Ollama"||N==="9router")&&(o.trim()==="LOCAL"||o.trim()===""),u=N==="c_openai",a=v?"LOCAL":o;if(u){let h=o.trim().replace(/\/+$/,""),M={...ce,customOpenAIBaseUrl:h,memory:!1};Nt(M);let U=await on("c_openai")||"";Ot(U),fo(U,{aiProvider:"c_openai",onIDEApproval:ko});let K=co("c_openai",tt)||"";Gt(K),await Kt({mode:j,thinkingLevel:Xe,aiProvider:"c_openai",activeModel:K,showFullThinking:un,systemSettings:M,profileData:fn,imageSettings:Ho,autoCompletion:nr,apiTier:tt}),I(z=>[...z,{role:"system",text:`\u2726 Custom (OpenAI) Base URL saved!
90
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Endpoint: ${h}${K?`
91
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model: ${K}`:""}
92
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available with Custom (OpenAI).
93
- \u2800`,isMeta:!0}]),xn("");return}if(v||o.startsWith(f)&&o.length>=x){await ti(N,a),Ot(a),fo(a,{aiProvider:N,onIDEApproval:ko});let h="gemma-4-31b-it";N==="OpenRouter"?h="google/gemma-4-31b-it:free":N==="DeepSeek"?h="deepseek-v4-flash":N==="NVIDIA"?h="deepseek-ai/deepseek-v4-flash":N==="Ollama"||N==="9router"?h=je||"":(N==="InferX"||N==="SenseNova"||N==="AIHubMix"||N==="Poolside"||N==="ExpLabs"||N==="TokenHarbor"||N==="Infron"||N==="APInex"||N==="xKiro")&&(h=co(N,tt)||""),Gt(h);let M={...ce};v&&N==="Ollama"&&(M={...M,ollamaEndpoint:"Local"},Nt(M)),(N==="Ollama"||N==="InferX"||N==="SenseNova"||N==="AIHubMix"||N==="Poolside"||N==="9router"||N==="ExpLabs"||N==="TokenHarbor"||N==="Infron"||N==="APInex"||N==="xKiro")&&(M={...M,memory:!1},Nt(M));let O="";if(N==="9router"){let U=await Ci();U.ok||(O=`
94
-
95
- \x1B[33m\u2726 WARNING: 9router does not appear to be running on ${U.url}.\x1B[39m
96
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m To start 9router: \x1B[36mnpx 9router\x1B[39m or \x1B[36mnpm i -g 9router && 9router\x1B[39m`)}I(U=>[...U,{role:"system",text:`\u2726 ${N} API Key saved successfully! ${h?`
97
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model set to ${h}.`:""}${v&&N==="Ollama"?`
98
- \u2726 Ollama Endpoint switched to Local.
99
- \u2514\u2500\u2800`:`
100
-
101
- \u2726\u2800`}${N==="Ollama"||N==="InferX"||N==="SenseNova"||N==="AIHubMix"||N==="Poolside"||N==="9router"||N==="ExpLabs"||N==="TokenHarbor"||N==="Infron"||N==="APInex"||N==="xKiro"?`Memory is not available with ${N}.
102
- \u2514\u2500\u2800`:""}Initialization complete.${O}
103
- \u2800`,isMeta:!0}])}else I(h=>[...h,{role:"system",text:`\u2726 INVALID KEY
104
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${N} API key must start with "${f}" and be at least ${x} characters long.`,isMeta:!0}]),xn("")},Kr=Ze(Si);gt(()=>{if(St==="exit"){(async()=>{let c=Date.now(),f=Math.floor((c-Kr.current)/1e3);f>=1&&(await Sn("duration",f),Kr.current+=f*1e3),await Ul()})();let o=setTimeout(()=>{process.exit(0)},50);return()=>clearTimeout(o)}},[St]),gt(()=>{try{ei(n=>{I(o=>(P(o.length+1),[...o,{id:"keynotice-"+Date.now(),role:"system",text:`\u2726 ${n}
105
- \u2800`,isMeta:!0}]))})}catch{}return()=>{try{ei(null)}catch{}}},[]),gt(()=>{let n=setInterval(async()=>{if(!Ne){let o=Date.now(),c=Math.floor((o-Kr.current)/1e3);c>=1&&(await Sn("duration",c),Kr.current+=c*1e3),$l()}},5e3);return()=>clearInterval(n)},[Ne]);let cl=[{cmd:"/quit",desc:"Exit and shutdown Flux"},{cmd:"/kill",desc:"Kill a process by PID",subs:In.map(n=>{let o;return n.isRoot?o="FluxFlow":n.url&&(n.url.includes(":52991")||n.url.includes(":52145")||n.url.includes(":52140"))?o="Internal":o=n.url||n.name,{cmd:String(n.pid),display:`PID: ${n.pid}`,rightDesc:o,desc:o}})},{cmd:"/help",desc:"Show all available commands"},..._e.playground?[{cmd:"/move",desc:"Move playground directory to original CWD/playground-export"}]:[],{cmd:"/resume",desc:"Load previous session"},{cmd:"/clear",desc:"Clear terminal screen"},{cmd:"/compress",desc:"Summarize and compress chat history"},{cmd:"/truncate",desc:"Truncate tool results in chat history"},{cmd:"/revert",desc:"Revert codebase back to a checkpoint"},{cmd:"/gemini",desc:"Get a happy message from Gemini CLI"},{cmd:"/meow",desc:"Cat nonsense, delivered straight to the terminal"},...process.env.HALLOWEEN_EEGG==="true"||process.env.HALLOWEEN_EEGG===!0?[{cmd:"/trick-or-treat",desc:"Halloween surprise: Trick or Treat!"}]:[],{cmd:"/save",desc:"Force save current chat"},{cmd:"/export",desc:"Export current chat or error logs",subs:[{cmd:"chat",desc:"Export current active chat"},{cmd:"logs",desc:"Export error logs"}]},{cmd:"/chats",desc:"List all chat sessions"},{cmd:"/btw",desc:"Ask a question without intefering with ongoing tasks"},{cmd:"/thinking",desc:"Set AI reasoning depth",subs:[{cmd:"Low",display:oo(N,je,"Low")!==null?`Low (${oo(N,je,"Low")})`:"Low",desc:"Quick Reasoning"},{cmd:"Medium",display:oo(N,je,"Medium")!==null?`Medium (${oo(N,je,"Medium")})`:"Medium",desc:"Balanced Reasoning"},{cmd:"High",display:oo(N,je,"High")!==null?`High (${oo(N,je,"High")})`:"High",desc:"Deep Reasoning"},{cmd:"custom",display:oo(N,je,"xHigh")!==null?`Custom (${oo(N,je,"xHigh")})`:"Custom",desc:"Custom Reasoning Value"}]},{cmd:"/model",desc:"Select Agent Model",subs:j==="ICU"||j.toLowerCase()==="fluxcu"?tn(N,tt,ce?.customOpenAIBaseUrl).filter(n=>Jr(n.cmd||n)):tn(N,tt,ce?.customOpenAIBaseUrl)},{cmd:"/wildcard-tooling",desc:"Use if the model lacks Tooling Capability"},{cmd:"/provider",desc:"Select AI Provider"},{cmd:"/mode",desc:"Switch execution mode",subs:[{cmd:"flux",display:"workspace",desc:"Workspace, files & terminal tools"},{cmd:"flow",display:"studio",desc:"Creative studio, documents, PDF & conversation"},{cmd:"icu",display:"computer use",desc:"Interactive desktop & OS automation"},{cmd:"fluxcu",display:"omni",desc:"Autonomous tools & desktop execution"}]},{cmd:"/display",desc:"Select Active Display (Computer Use)",subs:[{cmd:"primary",desc:"Primary Display (Display 1)"},{cmd:"secondary",desc:"Secondary Display (Display 2)"}]},{cmd:"/settings",desc:"Configure system prefs"},{cmd:"/theme",desc:"Customize UI color theme"},{cmd:"/key",desc:"Manage API keys",subs:[{cmd:"list",desc:"List saved keys"},{cmd:"add",desc:"Add a key"},{cmd:"remove",desc:"Remove a key"},{cmd:"use",desc:"Select active key"},{cmd:"clean",desc:"Remove gaps between slots"}]},{cmd:"/files",desc:"List loaded instruction and skill files"},{cmd:"/memory",desc:"Manage agent memory",subs:[{cmd:"view",desc:"View and manage agent persistent memory"},{cmd:"migrate",desc:"Migrate persistent memories to AGENTS.md"}]},{cmd:"/stats",desc:"Show session usage"},{cmd:"/usage",desc:"Open graphical token usage & analytics dashboard in browser"},{cmd:"/target",desc:"Show current provider and model"},{cmd:"/reset",desc:"Wipe all project data"},{cmd:"/about",desc:"Project info & credits"},{cmd:"/changelog",desc:"View latest updates"},{cmd:"/docs",desc:"View Documentation"},{cmd:"/fluxflow",desc:"Project management",subs:[{cmd:"global",desc:"Opens the Global FluxFlow Directory in File Explorer"},{cmd:"saves",desc:"Opens FluxFlow AppData Directory in File Explorer"}]},{cmd:"/budget",desc:"Set or View budget limits",subs:[{cmd:"view",desc:"View current usage budget bars"},{cmd:"web",desc:"Open graphical usage and budget dashboard in browser"},{cmd:"set",desc:"Configure budgets (Daily/Monthly limits)"},{cmd:"reset",desc:"Reset budgets to default limits"}]},{cmd:"/update",desc:"Check/Install updates",subs:[{cmd:"latest",desc:"Install latest release"},{cmd:"check",desc:"Check for new version"}]}],dl=async(n,o=!1)=>{if(!o&&lt.length>0){let x=lt[Le]||lt[0],v=n.split(" "),u=v.length===1?x.cmd:v.slice(0,-1).join(" ")+" "+x.cmd;if(u.trim()!==n.trim()){b(u+" "),Pe(0),L(a=>a+1);return}}Gs.current=!1;let c=n.replace(/\r\n/g,`
106
- `).replace(/\r/g,`
107
- `).trimEnd();if(c.endsWith("\\")){b(c.slice(0,-1)+`
108
- `);return}let f=c.replace(/\\\s*\n/g,`
109
- `).split(/\r?\n/).map(x=>x.replace(/\\$/,"")).join(`
110
- `);if(f.trim()){if(!o)try{let x=F.current;x[x.length-1]!==f&&x.push(f),x.length>200&&x.shift(),A(-1),W.current=""}catch{}if(Vn){let x=f.trim();if(x.startsWith("/btw")){if(x.replace(/^\/btw\s*/,"").trim().length<=3){I(u=>(P(u.length+1),[...u,{id:"hint-err-"+Date.now(),role:"system",text:`\u2726 RESTRICTED
111
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Inquiry question must be more than 3 characters.
112
- \u2800`,isMeta:!0}])),b("");return}}else if(x.startsWith("/")){I(v=>(P(v.length+1),[...v,{id:"hint-err-"+Date.now(),role:"system",text:`\u2726 RESTRICTED
113
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Steering Hints cannot start with '/'.
114
- \u2800`,isMeta:!0}])),b("");return}Ks(x),Xo.current=x,b("");return}if(!Ke&&!(N==="c_openai"&&ce.customOpenAIBaseUrl)){al(f),xn("");return}if(f.startsWith("/")){b("");let x=f.split(" "),v=x[0]?.toLowerCase();switch(v){case"/quit":{re("exit");break}case"/resume":{if(x[1]){let u=x[1];(async()=>{let h=await Ko(),M=h[u]||Object.values(h).find(O=>O.name.toLowerCase()===u.toLowerCase());if(M){if(r.write("\x1B[2J\x1B[3J\x1B[H"),process.stdout.isTTY){let z=M?.name||"",V=z&&!z.startsWith("flow-")&&!z.startsWith("Session ")?z:"FluxFlow | Resumed";process.stdout.write(`\x1B]0;${V}\x07`),process.stdout.write(`\x1B]633;P;TerminalTitle=${V}\x07`)}Go(),Wo.current=!0,Xr(u);let O=await yr(u);Pn.current=lo-O.total,Nn.current=wo,$n.current=hn,zt.current=[],Ln(O.total),On(0),gn(0),Fn(0),Zo({tokens:O.context}),Wo.current=!1;let U=[...M.messages];U[0]?.text?.includes("\u2591\u2591\u2591\u2588\u2588\u2588")||U.unshift({id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}),I(U),I(z=>[...z,{id:"sys-"+Date.now(),role:"system",text:`\u2726 SESSION RESUMED
115
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${u}.
116
- \u2800`,isMeta:!0}]),P(0)}else I(O=>[...O,{id:"err-"+Date.now(),role:"system",text:`\u2726 ERROR: Session [${u}] not found.
117
- \u2800`,isMeta:!0}])})()}else re("resume");break}case"/move":{if(!_e.playground){I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u2726 RESTRICTED
118
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m '/move' is only available in playground mode.
119
- \u2800`,isMeta:!0}]));break}if(!_e.originalCwd){I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u2726 RESTRICTED
120
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Original CWD not found.
121
- \u2800`,isMeta:!0}]));break}let u=Ct.join(Ao,"playground"),a=Ct.join(_e.originalCwd,"playground-export");(async()=>{try{I(O=>(P(O.length+1),[...O,{id:Date.now(),role:"system",text:`\u2726 EXPORTING PLAYGROUND CONTENT
122
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${a}
123
- `,isMeta:!0}])),await pt.ensureDir(a);let M=["node_modules",".git",".venv","venv","env",".next","dist","build",".cache"];await pt.copy(u,a,{overwrite:!0,filter:O=>{let U=Ct.relative(u,O);return U?!U.split(Ct.sep).some(z=>M.includes(z)):!0}}),I(O=>(P(O.length+1),[...O,{id:Date.now(),role:"system",text:`\u2726 SUCCESS
124
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m playground content copied to ${a}
125
- `,isMeta:!0}]))}catch(M){I(O=>(P(O.length+1),[...O,{id:Date.now(),role:"system",text:`\u2726 FAILED TO MOVE CONTENT
126
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${M.message}
127
- `,isMeta:!0}]))}})();break}case"/clear":{if(r&&(r.write("\x1B[2J\x1B[3J\x1B[H"),r.isTTY&&(r.write("\x1B[?2004h"),process.stdout.write("\x1B]0;FluxFlow\x07"),process.stdout.write("\x1B]633;P;TerminalTitle=FluxFlow\x07"))),I([{id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}]),P(1),Ys(u=>u+1),Go(),ao.current={completedIndex:0,columns:H.columns,historicalBlocks:[],seenSelections:new Set,chatId:bt,clearKey:Tn+1},_e.playground){if(_e.playground=!1,os(Wn).catch(()=>{}),_e.originalCwd)try{process.chdir(_e.originalCwd),I(u=>{let a=[...u,{id:"playground-"+Date.now(),role:"system",text:`\u2726 PLAYGROUND
128
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Restored Working Directory to ${_e.originalCwd}
129
- \u2800`,isMeta:!0}];return P(a.length),a})}catch{}setTimeout(()=>{pt.emptyDir(Ct.join(Ao,"playground")).catch(u=>{I(a=>{let h=[...a,{id:"playground-"+Date.now(),role:"system",text:`\u2726 PLAYGROUND
130
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Failed to clear session: ${Ao+"/playground"}`,isMeta:!0}];return P(h.length),h})})},500),Nt(u=>({...u,allowExternalAccess:Os.current,memory:Ns.current}))}Xr(li()),Zo({tokens:0}),Y(!1),Ln(0),On(0),gn(0),Fn(0),zt.current=[],Pn.current=lo,Nn.current=wo,$n.current=hn,setTimeout(()=>{global.gc&&(async()=>{for(let a=0;a<3;a++)global.gc(),await new Promise(h=>setImmediate(h));g.current=Date.now()})()},500);break}case"/revert":{wr.getChatHistory(bt).then(u=>{if(u.length>0)tl(u.reverse()),re("revert");else{let a=yt(2);I(h=>(P(h.length+1),[...h,{id:"revert-empty-"+Date.now(),role:"system",text:`\u2726 Nothing to revert to.
131
- \u2800`,isMeta:!0}]))}}),setTimeout(()=>{global.gc&&(async()=>{for(let a=0;a<3;a++)global.gc(),await new Promise(h=>setImmediate(h));g.current=Date.now()})()},500);break}case"/mode":{if(x[1]){let u=x[1].toLowerCase(),a="Flux";u==="flow"?a="Flow":u==="icu"?a="ICU":u==="fluxcu"?a="FluxCU":u==="flux"&&(a="Flux"),le(a);let h=yt(2);I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u2726 Mode switched to ${Mi(a)}.
132
- \u2800`,isMeta:!0}]))}else re("mode");break}case"/display":{if(x[1]){let u=x[1].toLowerCase(),a=0;u==="secondary"||u==="1"||u==="2"?a=1:a=0,ne(a),Kt({display:a}).catch(()=>{});let h=a===0?"Primary (Display 1)":"Secondary (Display 2)";I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u2726 Active Computer Use display set to: ${h}.
133
- \u2800`,isMeta:!0}]))}else re("display");break}case"/image_deprecated":{if(x[1]?.toLowerCase()==="stats"){let u=yt(2);if(Ho.keyType==="Custom")I(a=>(P(a.length+1),[...a,{id:Date.now(),role:"system",text:"[SYSTEM] Key strategy is Custom. Redirecting to Pollinations dashboard (https://enter.pollinations.ai/#pollen)...",isMeta:!0}])),Uo("start https://enter.pollinations.ai/#pollen");else try{let a=await Hl();I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",isImageStats:!0,text:`\u2022 Hourly Limit: ${Number((a.limit*1e3).toFixed(0))} credits
134
- \u2022 Spent (Last 1hr): ${Number((a.totalSpent*1e3).toFixed(0))} credits
135
- \u2022 Remaining: ${Number((a.remaining*1e3).toFixed(0))} credits
136
- \u2022 Requests (Last 1hr): ${a.activeCallsCount} requests
137
- `+(a.nextResetMin>0?`\u2022 Refreshes in: ${a.nextResetMin}m`:""),isMeta:!0}]))}catch{I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:"[SYSTEM] Failed to load image quota stats.",isMeta:!0}]))}}else if(x[1]?.toLowerCase()==="setup")if(x[2]?.toLowerCase()==="key")if(x[3]){let u=["default","custom"].find(a=>a===x[3].toLowerCase());if(u){let a=u==="default"?"Default":"Custom";$r(M=>({...M,keyType:a}));let h=yt(2);I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`[SYSTEM] Image key strategy set to ${a}`,isMeta:!0}])),a==="Custom"&&(io({label:"Enter Pollinations API key (starting with sk_):",note:"Get a key from https://enter.pollinations.ai",key:"imageSettings",subKey:"apiKey",value:Ho.apiKey||"",returnView:"chat"}),re("input"))}else{let a=yt(2);I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:"[SYSTEM] Invalid key option. Choose: Default or Custom.",isMeta:!0}]))}}else{let u=yt(2);I(a=>(P(a.length+1),[...a,{id:Date.now(),role:"system",text:"[SYSTEM] Usage: /image setup Key <Default|Custom>",isMeta:!0}]))}else if(x[2]?.toLowerCase()==="quality")if(x[3]){let u=["low","low-high","medium","medium-high","high","ultra","premium"].find(a=>a===x[3].toLowerCase());if(u){let h={low:"Low","low-high":"Low-High",medium:"Medium","medium-high":"Medium-High",high:"High",ultra:"Ultra",premium:"Premium"}[u];$r(O=>({...O,quality:h}));let M=yt(2);I(O=>(P(O.length+1),[...O,{id:Date.now(),role:"system",text:`[SYSTEM] Image quality set to ${h}`,isMeta:!0}]))}else{let a=yt(2);I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:"[SYSTEM] Invalid quality level. Choose from: Low, Low-High, Medium, Medium-High, High, Ultra, Premium.",isMeta:!0}]))}}else{let u=yt(2);I(a=>(P(a.length+1),[...a,{id:Date.now(),role:"system",text:"[SYSTEM] Usage: /image setup Quality <Low|Low-High|Medium|Medium-High|High|Ultra>",isMeta:!0}]))}else{let u=yt(2);I(a=>(P(a.length+1),[...a,{id:Date.now(),role:"system",text:"[SYSTEM] Usage: /image setup <Key|Quality> ...",isMeta:!0}]))}else{let u=yt(2);I(a=>(P(a.length+1),[...a,{id:Date.now(),role:"system",text:"[SYSTEM] Usage: /image setup <Key|Quality> ...",isMeta:!0}]))}break}case"/thinking":{let u;if(x[1]){let a=x.slice(1),h=a.includes("--bypass")||a.includes("-b"),M=a.includes("--force")||a.includes("-f"),O=a.findIndex(V=>V==="--map"||V==="-m");if(O!==-1){let V=a.slice(0,O).join(" ").trim(),te=a.slice(O+1).join(" ").trim(),oe=["fast","low","medium","standard","high","xhigh","custom","max"];if(!V||!te)I($=>(P($.length+1),[...$,{id:Date.now(),role:"system",text:`\u2726 \x1B[31mINVALID USAGE\x1B[0m
138
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Usage: \x1B[36m/thinking <level> --map <target_value>\x1B[0m (e.g. \x1B[33m/thinking Custom --map high\x1B[0m)
139
- \u2800`,isMeta:!0}]));else if(!oe.includes(V.toLowerCase()))I($=>(P($.length+1),[...$,{id:Date.now(),role:"system",text:`\u2726 \x1B[31mUNKNOWN LEVEL\x1B[0m
140
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Unknown level "\x1B[33m${V}\x1B[0m" to map. Available: \x1B[36mLow, Medium, High, Custom\x1B[0m.
141
- \u2800`,isMeta:!0}]));else if(te.toLowerCase()==="rm"||te.toLowerCase()==="--remove"||te.toLowerCase()==="-rm"){let $=V.toLowerCase()==="custom"?"xHigh":V,Re=ql(N,je,$);Re.success?I(Ue=>(P(Ue.length+1),[...Ue,{id:Date.now(),role:"system",text:`\u2726 Thinking Level Mapping Removed:
142
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Target: \x1B[36m${N}::${je}\x1B[0m
143
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Removed mapping for: \x1B[33m${V}\x1B[0m
144
- \u2800`,isMeta:!0}])):I(Ue=>(P(Ue.length+1),[...Ue,{id:Date.now(),role:"system",text:`\u2726 \x1B[31mFAILED TO REMOVE MAPPING\x1B[0m
145
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${Re.reason}
146
- \u2800`,isMeta:!0}]))}else{let $=V.toLowerCase()==="custom"?"xHigh":V,Re=isNaN(Number(te))?te:Number(te),Ue=jl(N,je,$,Re);Ue.success?I(We=>(P(We.length+1),[...We,{id:Date.now(),role:"system",text:`\u2726 Thinking Level Mapped:
147
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Target: \x1B[36m${N}::${je}\x1B[0m
148
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Mapping: \x1B[33m${V}\x1B[0m \u2794 \x1B[32m${te}\x1B[0m
149
- \u2800`,isMeta:!0}])):I(We=>(P(We.length+1),[...We,{id:Date.now(),role:"system",text:`\u2726 \x1B[31mFAILED TO SAVE MAPPING\x1B[0m
150
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${Ue.reason}
151
- \u2800`,isMeta:!0}]))}break}let U=a[0].toLowerCase();if(!["fast","low","medium","standard","high","xhigh","custom","max"].includes(U)){I(V=>(P(V.length+1),[...V,{id:Date.now(),role:"system",text:`\u2726 \x1B[31mUNKNOWN THINKING LEVEL\x1B[0m
152
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Level "\x1B[33m${a[0]}\x1B[0m" is not supported. Available levels: \x1B[36mLow, Medium, High, Custom\x1B[0m.
153
- \u2800`,isMeta:!0}]));break}if(U==="standard"&&(U="medium"),U==="custom"&&(U="xhigh"),u=U.charAt(0).toUpperCase()+U.slice(1),U==="xhigh"&&(u="xHigh"),u==="xHigh"&&!(oo(N,je,"xHigh")!==null)){I(te=>(P(te.length+1),[...te,{id:Date.now(),role:"system",text:`\u2726 \x1B[31mCUSTOM LEVEL NOT MAPPED\x1B[0m
154
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Custom Effort level is not mapped. Use \x1B[36m/thinking custom --map <target_value>\x1B[0m first.
155
- \u2800`,isMeta:!0}]));break}let z="";if(M&&(process.env.NVIDIA_BASE_URL,z=`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Enabled Forced Reasoning.
156
- \u2800`,process.env.forcedReasoning="true"),!h&&j==="Flow"&&u==="xHigh")I(V=>(P(V.length+1),[...V,{id:Date.now(),role:"system",text:`\u2726 RESTRICTED
157
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m"${u}" is restricted in Flow mode. Switch to Flux to enable Higher Thinking Levels.
158
- \u2800${z}.`,isMeta:!0}]));else{ro(u);let V=yt(1),te=u==="xHigh"?oo(N,je,"xHigh")!==null?`Custom (${oo(N,je,"xHigh")})`:"Custom":u;I(oe=>(P(oe.length+1),[...oe,{id:Date.now(),role:"system",text:`\u2726 ${N}
159
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${je}.
160
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Thinking Level: ${te}.
161
- ${z} \u2800`,isMeta:!0}]))}}else re("thinking");break}case"/model":{if(x[1]){let u=x.slice(1).join(" "),a=null,h=!1,M=null,O=u,U=/(?:^|\s)(?:--info|-i)(?:\s+(?:"([^"]*)"|'([^']*)'|\{([^}]*)\}|((?:(?!--[a-z]|-[a-z]\b).)+)))?(?=\s+--|\s+-[a-z]\b|$)/i,K=O.match(U);if(K){if(M=(K[1]??K[2]??K[3]??K[4]??"").trim(),O=(O.slice(0,K.index)+" "+O.slice(K.index+K[0].length)).trim(),M==="0")h=!0,a=null;else if(a={},M){let de=M.split(",");for(let he of de){let Je=he.trim().match(/^(IN|OUT|CR|CW)\s+([0-9]*\.?[0-9]+)$/i);Je&&(a[Je[1].toUpperCase()]=parseFloat(Je[2]))}}}let z=O.split(/\s+/).filter(Boolean),V=z.some(de=>de==="--multimodal"||de==="-m"||de==="--vision"||de==="-v"),te=z.some(de=>de==="--save"||de==="-sv"||de==="--add"),oe=z.some(de=>de==="--remove"||de==="-rm"),$=z.some(de=>de==="--rename"||de==="-rn"||de==="-mv"),Re=z.some(de=>de==="--default"||de==="-df"),Ue=z.some(de=>de==="--price"||de==="-p"),We=z.some(de=>de==="--raw"||de==="-r"),ze=z.filter(de=>!de.startsWith("-")),Ve=(de=a)=>h?`
162
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Pricing: \x1B[33mReset (info removed)\x1B[0m`:de?Object.keys(de).length>0?`
163
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Pricing:
164
- `+Object.entries(de).map(([he,Qe])=>` \x1B[2m\u2022\x1B[22m \x1B[36m${he}\x1B[0m: $${Qe}`).join(`
165
- `):M?`
166
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Pricing: \x1B[33mNo valid IN, OUT, CR, CW tokens parsed from: "${M}"\x1B[0m`:"":"";if(te||oe||$||Re){if(Re){let de=ze.join(" ").trim();if(!de)I(he=>(P(he.length+1),[...he,{id:Date.now(),role:"system",text:"\x1B[31m[Error]\x1B[0m Please provide a model ID to set as default. Example: /model my-model --default",isMeta:!0}]));else{let he=pl(N,de,V,a);he.success?I(Qe=>{P(Qe.length+1);let Je=N==="c_openai"?ce?.customOpenAIBaseUrl||"Custom Endpoint":N.replace("c_openai","Custom Endpoint");return[...Qe,{id:Date.now(),role:"system",text:`\u2726 Default Model Set:
167
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Provider: ${Je}
168
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Default Model: \x1B[32m${de}\x1B[0m
169
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Multimodal: ${V?"ON":"OFF"}${Ve()}
170
- \u2800`,isMeta:!0}]}):I(Qe=>(P(Qe.length+1),[...Qe,{id:Date.now(),role:"system",text:`\x1B[31m[Error]\x1B[0m Failed to set default model: ${he.reason}`,isMeta:!0}]))}}else if(te){let de=ze.join(" ").trim();if(!de)I(he=>(P(he.length+1),[...he,{id:Date.now(),role:"system",text:"\x1B[31m[Error]\x1B[0m Please provide a model ID to save. Example: /model my-custom-model --save",isMeta:!0}]));else{let he=N==="c_openai"?ce.customOpenAIBaseUrl:null,Qe=gl(N,de,V,a,he);Qe.success?I(Je=>(P(Je.length+1),[...Je,{id:Date.now(),role:"system",text:`\u2726 Model Saved:
171
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Provider: ${N}
172
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model: \x1B[32m${de}\x1B[0m
173
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Multimodal: ${V?"ON":"OFF"}${Ve()}
174
- \u2800`,isMeta:!0}])):I(Je=>(P(Je.length+1),[...Je,{id:Date.now(),role:"system",text:`\x1B[31m[Error]\x1B[0m Failed to save model: ${Qe.reason}`,isMeta:!0}]))}}else if(oe){let de=ze.join(" ").trim();if(!de)I(he=>(P(he.length+1),[...he,{id:Date.now(),role:"system",text:"\x1B[31m[Error]\x1B[0m Please provide a model ID to remove. Example: /model my-custom-model --remove",isMeta:!0}]));else{let he=bl(N,de);he.success?I(Qe=>(P(Qe.length+1),[...Qe,{id:Date.now(),role:"system",text:`\u2726 Model Removed:
175
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Provider: ${N}
176
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model: \x1B[31m${de}\x1B[0m
177
- \u2800`,isMeta:!0}])):I(Qe=>(P(Qe.length+1),[...Qe,{id:Date.now(),role:"system",text:`\x1B[31m[Error]\x1B[0m Failed to remove model: ${he.reason}`,isMeta:!0}]))}}else if($)if(ze.length<2)I(de=>(P(de.length+1),[...de,{id:Date.now(),role:"system",text:"\x1B[31m[Error]\x1B[0m Please provide both old and new model IDs. Example: /model old-model-id new-model-id --rename",isMeta:!0}]));else{let de=ze[0].trim(),he=ze.slice(1).join(" ").trim(),Qe=wl(N,de,he);Qe.success?I(Je=>(P(Je.length+1),[...Je,{id:Date.now(),role:"system",text:`\u2726 Model Renamed:
178
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Provider: ${N}
179
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Old Model: \x1B[31m${de}\x1B[0m
180
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m New Model: \x1B[32m${he}\x1B[0m
181
- \u2800`,isMeta:!0}])):I(Je=>(P(Je.length+1),[...Je,{id:Date.now(),role:"system",text:`\x1B[31m[Error]\x1B[0m Failed to rename model: ${Qe.reason}`,isMeta:!0}]))}break}if(Ue){let de=ze.join(" ").trim()||je,he=hr(N,de),Qe=N==="c_openai"?ce?.customOpenAIBaseUrl||"Custom Endpoint":N.replace("c_openai","Custom Endpoint"),Je=he&&Object.keys(he).length>0;if(We){let Ce=Je?Object.entries(he).map(([we,De])=>`${we}=${De}`).join(" "):`Price not set for ${de}`;I(we=>(P(we.length+1),[...we,{id:Date.now(),role:"system",text:Ce,isMeta:!0}]));break}let G=Je?`
182
- `+Object.entries(he).map(([Ce,we])=>`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m \x1B[36m${Ce}\x1B[0m: $${we}`).join(`
183
- `):`
184
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m \x1B[33mPrice not set\x1B[0m
185
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m \x1B[2mHint: /model ${de} -i 'IN 0.15, OUT 0.6, CR 0.05, CW 0.1'
186
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m \x1B[2mNote: CR = Cache Read, CW = Cache Write\x1B[0m`;I(Ce=>(P(Ce.length+1),[...Ce,{id:Date.now(),role:"system",text:`\u2726 Model Price:
187
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Provider: ${Qe}
188
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model ID: \x1B[32m${de}\x1B[0m${G}
189
- \u2800`,isMeta:!0}]));break}if(a!==null||h){let de=ze.join(" ").trim();if(!de)I(he=>(P(he.length+1),[...he,{id:Date.now(),role:"system",text:'\x1B[31m[Error]\x1B[0m Please provide a model ID. Example: /model <id> -i "IN 0.15, OUT 0.6, CR 0.05, CW 0.1"',isMeta:!0}]));else{h?Qs(N,de,null):Object.keys(a).length>0&&Qs(N,de,a);let he=h?null:hr(N,de),Qe=N==="c_openai"?ce?.customOpenAIBaseUrl||"Custom Endpoint":N.replace("c_openai","Custom Endpoint");I(Je=>(P(Je.length+1),[...Je,{id:Date.now(),role:"system",text:`\u2726 Model Info ${h?"Reset":"Saved"}:
190
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Provider: ${Qe}
191
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model ID: \x1B[32m${de}\x1B[0m${Ve(he||a)}
192
- \u2800`,isMeta:!0}]))}break}let it=ze.join(" ").trim();if(Tl(V),it){V&&hl(N,it,!0);let de=co("Google","Free"),he=co("Google","Paid");{Gt(it);let Qe=V||Jr(it),Je=Xe==="xHigh"?oo(N,it,"xHigh")!==null?`Custom (${oo(N,it,"xHigh")})`:"Custom":Xe,G=N==="c_openai"?ce?.customOpenAIBaseUrl||"Custom Endpoint":N.replace("c_openai","Custom Endpoint");I(Ce=>(P(Ce.length+1),[...Ce,{id:Date.now(),role:"system",text:`\u2726 ${G}
193
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${it}
194
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Thinking Level: ${Je}
195
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Multimodal: ${Qe?"ON":"OFF"}
196
- \u2800`,isMeta:!0}]))}}}else re("model");break}case"/wildcard-tooling":{Se(u=>{let a=!u;return I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 Wildcard Tooling:
197
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Status: ${a?"Enabled":"Disabled"}
198
- \u2800`,isMeta:!0}])),a});break}case"/wildercard-tooling":{T(u=>{let a=!u;return I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 Wildercard Tooling:
199
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Status: ${a?"Enabled":"Disabled"}
200
- \u2800`,isMeta:!0}])),a});break}case"/settings":{re("settings");break}case"/provider":case"/providers":{Ms("chat"),re("selectProvider");break}case"/theme":{re("theme");break}case"/key":{(async()=>{try{let a=x.slice(1).join(" "),h=await ka(a,{currentProvider:N}),M=(h.lines||[]).join(`
201
- `);M&&I(O=>(P(O.length+1),[...O,{id:Date.now(),role:"system",text:M,isMeta:!0}])),h.switchedBaseUrl&&Nt(O=>({...O,customOpenAIBaseUrl:h.switchedBaseUrl,memory:!1})),h.switchedKey!==void 0&&(Ot(h.switchedKey),fo(h.switchedKey,{aiProvider:N,onIDEApproval:ko})),h.promptNewKey&&(Ot(null),re("chat"))}catch(a){I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 Key command error: ${a.message}`,isMeta:!0}]))}})();break}case"/stats":{(async()=>{let a=await Zr(),h=await Rr();Is(a),ks(h),sr("daily"),re("stats")})();break}case"/usage":{(async()=>{try{let{openUsageDashboard:a}=await import("./usageServer-4XHUFY7X.js"),{url:h}=await a();I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u2726 Launching Token Analytics Dashboard
202
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Serving at ${h}
203
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Opening in your default browser...
204
- \u2800`,isMeta:!0}]))}catch(a){I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 ERROR
205
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Failed to launch dashboard: ${a.message}
206
- \u2800`,isMeta:!0}]))}})();break}case"/save":{let u,a=Ft.find(M=>M.role==="user");if(a&&a.text){let M=a.text.replace(/\s*\n+\s*\[Prompted on:.*?\]/g,"").trim(),O=M.split(/\s+/),U;O.length>7?U=O.slice(0,7).join(" ")+"...":M.length>45?U=M.substring(0,45).trimEnd()+"...":U=M,u=U}let h=x.slice(1).join(" ")||u||`Session ${new Date().toLocaleTimeString()}`;En(bt,h,Ft),I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u2726 Saved
207
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m "${h}" (ID: ${bt})
208
- \u2800`,isMeta:!0}]));break}case"/export":{(async()=>{try{let{handleExport:a}=await import("./export-RU6LCZUB.js"),h=await a(x,{chatId:bt,messages:Ft});I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:h.message,isMeta:!0}]))}catch(a){I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`[EXPORT ERROR] Failed to export: ${a.message}`,isMeta:!0}]))}})();break}case"/chats":{(async()=>{let a=await Ko(),h=Object.entries(a).sort((M,O)=>(O[1].updatedAt||0)-(M[1].updatedAt||0)).map(([M,O])=>`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${M}: ${Tr(O,M)}${M===bt?" (current)":""}`).join(`
209
- `);I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u2726 Saved Chats:
210
- ${h||"\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m No saved chats found."}
211
- \u2800`,isMeta:!0}]))})();break}case"/memory":{if((x[1]||"view").toLowerCase()==="migrate")try{let a=zr(gr,[]);if(!a||a.length===0){I(te=>(P(te.length+1),[...te,{id:Date.now(),role:"system",text:`\u2726 Memory Migration
212
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m No persistent memories found in memories.json to migrate.
213
- \u2800`,isMeta:!0}]));break}let h=a.map(te=>`- ${(te.memory||"").replace(/\[Saved on: .*?\]/g,"").replace(/\\+'/g,"'").trim()}`).filter(te=>te!=="- ").join(`
214
- `);if(!h){I(te=>(P(te.length+1),[...te,{id:Date.now(),role:"system",text:`\u2726 Memory Migration
215
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m No valid memory entries found to migrate.
216
- \u2800`,isMeta:!0}]));break}pt.existsSync(So)||pt.mkdirSync(So,{recursive:!0});let M=Ct.join(So,"AGENTS.md"),O="";pt.existsSync(M)&&(O=pt.readFileSync(M,"utf8"));let U=O.trimEnd(),z=`${U.length>0?`
217
-
218
- `:""}User Memories:
219
- ${h}
220
- `,V=`${U}${z}`;pt.writeFileSync(M,V,"utf8"),I(te=>(P(te.length+1),[...te,{id:Date.now(),role:"system",text:`\u2726 Memory Migration
221
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Successfully migrated ${a.length} memories to ${M.replaceAll("\\\\","/").replaceAll("\\","/")}
222
- \u2800`,isMeta:!0}]))}catch(a){I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 Memory Migration Failed
223
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Error: ${a.message}
224
- \u2800`,isMeta:!0}]))}else re("memory");break}case"/files":{I(u=>(P(u.length+1),[...u,{id:"files-"+Date.now(),role:"system",text:Ql(),isMeta:!0}]));break}case"/target":{I(u=>(P(u.length+1),[...u,{id:"target-"+Date.now(),role:"system",text:`\u2726 Unique Model Id for FluxFlow
225
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${N}@${je}
226
- \u2800`,isMeta:!0}]));break}case"/reset":{(async()=>{try{I(a=>(P(a.length+1),[...a,{id:Date.now(),role:"system",text:`\u2726 Initiating reset...
227
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Clearing logs, secrets, and settings.
228
- \u2800`,isMeta:!0}])),pt.existsSync(qs)&&pt.removeSync(qs),pt.existsSync(zs)&&pt.removeSync(zs),pt.existsSync(Mn)&&pt.removeSync(Mn);try{pt.readdirSync(So).length===0&&pt.removeSync(So)}catch{}setTimeout(()=>{re("exit"),setTimeout(()=>process.exit(0),500)},500)}catch(a){I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 ERROR
229
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Failed to clear data: ${a.message}.
230
- \u2800`}]))}})();break}case"/about":{let u=yt(2),a=`\u2022 FluxFlow Version: v${po}
231
- \u2022 Status: ${dn&&dn!==po?`Update Available [v${dn}]`:"Up to date"}
232
- \u2022 Released on: ${hu}`;I(h=>(P(h.length+1),[...h,{id:"about-"+Date.now(),role:"system",text:a,isAboutRecord:!0,isMeta:!0}]));break}case"/changelog":{let u=process.platform;Uo(`${u==="win32"?"start":u==="darwin"?"open":"xdg-open"} ${Qa}`),I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 Opening Changelog
233
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${Qa}.`,isMeta:!0}]));break}case"/docs":{if(!vi){I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 ERROR
234
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Documentation URL is not configured.`,isMeta:!0}]));break}let u=process.platform;Uo(`${u==="win32"?"start":u==="darwin"?"open":"xdg-open"} ${vi}`),I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 Opening Documentation
235
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${vi}.
236
- \u2800`,isMeta:!0}]));break}case"/budget":{let u=x[1]?.toLowerCase();if(u==="web"||u==="gui"||u==="dashboard")(async()=>{try{let{openUsageDashboard:h}=await import("./usageServer-4XHUFY7X.js"),{url:M}=await h();I(O=>(P(O.length+1),[...O,{id:Date.now(),role:"system",text:`\u2726 Token Usage & Budget Dashboard
237
- \u2800\u2800\u2514\u2500 Opened at ${M}
238
- \u2800`,isMeta:!0}]))}catch(h){I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u2726 ERROR: Failed to launch dashboard: ${h.message}
239
- \u2800`,isMeta:!0}]))}})();else if(u==="set")Ra("chat"),re("budgetTypeSelect");else if(u==="view")(async()=>{let h=await Zr(),M=await Rr(),O=await ni(Ie.resetDay||1);Is(h),ks(M),_i(O),re("budgetView")})();else if(u==="reset"){let a={limitMode:"Daily",agentLimit:99999999,tokenLimit:99999999999999,backgroundLimit:999999,searchLimit:100,customModelId:"",customLimit:0,providerBudgets:{},providerTiers:{Google:"Free",DeepSeek:"Free",NVIDIA:"Free",OpenRouter:"Free",InferX:"Free",SenseNova:"Free",AIHubMix:"Free",Poolside:"Free",ExpLabs:"Free",TokenHarbor:"Free",Infron:"Free",APInex:"Free",xKiro:"Free"}};eo(a),It("Free"),Kt({apiTier:"Free",quotas:a}),I(h=>(P(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 Budgets reset successfully.
240
- \u2800`,isMeta:!0}]))}else I(a=>(P(a.length+1),[...a,{id:Date.now(),role:"system",text:`\u2726 ERROR
241
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Usage: /budget <View|Web|Set|Reset>.
242
- \u2800`,isMeta:!0}]));break}case"/fluxflow":{let a=x.slice(1)[0]?.toLowerCase()?.trim();if(a==="global"){let h=Ct.normalize(So);try{pt.ensureDirSync(h)}catch{}let M=process.platform;M==="win32"?Uo(`explorer "${h}"`):M==="darwin"?Uo(`open "${h}"`):Uo(`xdg-open "${h}"`)}else if(a==="saves"){let h=Ct.normalize(Ao);try{pt.ensureDirSync(h)}catch{h=Ct.normalize(So);try{pt.ensureDirSync(h)}catch{}}let M=process.platform;M==="win32"?Uo(`explorer "${h}"`):M==="darwin"?Uo(`open "${h}"`):Uo(`xdg-open "${h}"`)}else I(h=>(P(h.length+1),[...h,{id:"ff-err-"+Date.now(),role:"system",text:"Usage: /fluxflow global/saves",isMeta:!0}]));break}case"/update":{if(x[1]?.toLowerCase()==="check"){Bt(!0);break}let a=x.includes("--latest");re("update");break}case"/gemini":{let u=a=>{let h=a[Math.floor(Math.random()*a.length)];I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u2728 GEMINI CLI
243
- \u2800\u2800 \x1B[2m\u2514\u2500\x1B[22m ${h}
244
- \u2800`}]))};ps?u(ps):import("./gemini_quotes-B5IXNP2I.js").then(({GEMINI_QUOTES:a})=>{ps=a,u(ps)}),b("");break}case"/meow":{let u=a=>{let h=a[Math.floor(Math.random()*a.length)];I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u{1F431} MEOW
245
- \u2800\u2800 \x1B[2m\u2514\u2500\x1B[22m ${h}
246
- \u2800`}]))};bs?u(bs):import("./meow-SQBRZB7H.js").then(({MEOW_LINES:a})=>{bs=a,u(bs)}),b("");break}case"/halloween":case"/trick-or-treat":{let u=a=>{let h=a[Math.floor(Math.random()*a.length)];I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:`\u{1F383} TRICK OR TREAT
247
- \u2800\u2800 \x1B[2m\u2514\u2500\x1B[22m ${h}
248
- \u2800`}]))};ws?u(ws):import("./halloween-EZTJXDUW.js").then(({SPOOKY_LINES:a})=>{ws=a,u(ws)}),b("");break}case"/compress":{b("");let u=Ft.filter(M=>(M.role==="user"||M.role==="agent"||M.role==="system")&&!String(M.id).startsWith("welcome")&&!M.isMeta).length,a=Io?.tokens||0;if(u<64||a<16384){let M=yt(2);I(O=>(P(O.length+1),[...O,{id:Date.now(),role:"system",text:`\u2726 Compression skipped
249
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m History requires at least 64 messages and 16k tokens
250
- \u2800\u2800 \u2514\u2500 Current: ${u}/64 msgs, ${a}/16384 tokens.
251
- \u2800`,isMeta:!0}]));break}(async()=>{Zi(!0);let M=yt(2);I(O=>(P(O.length+1),[...O,{id:Date.now(),role:"system",text:"\u2726 Compacting session history...",isMeta:!0}]));try{if(await da({chatId:bt,aiProvider:N,apiKey:Ke,thinkingLevel:Xe,mode:j,janitorModel:k,systemSettings:ce,sessionStats:Io},Ft)){let K=yt(2);I(z=>{let V=[...z,{id:Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Chat History compacted saving tokens.
252
- \u2800`,isMeta:!0}];return P(V.length),V})}else I(K=>(P(K.length+1),[...K,{id:Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Compaction failed.
253
- \u2800`,isMeta:!0}]))}catch(O){I(U=>(P(U.length+1),[...U,{id:Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Error during compaction: ${O.message}
254
- \u2800`,isMeta:!0}]))}finally{Zi(!1)}})();break}case"/truncate":{b("");let u=0;I(a=>{let M=[...a.map(O=>{let U=O.fullText||O.text||"";return!U.startsWith("[ACTION RESULT]:")&&!U.startsWith("[TOOL RESULT]:")||U.startsWith("[ACTION RESULT]: Goal")||U.startsWith("[ACTION RESULT]: USER CHOOSE")||U.startsWith("[ACTION RESULT]: Background subagent started. Task ID:")||U.includes("...Success result truncated to save tokens")?O:(u++,{...O,fullText:"[ACTION RESULT]: ...Success result truncated to save tokens"})}),{id:Date.now(),role:"system",text:`\u2726 Tool Truncation...
255
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Truncated ${u} tool result(s).
256
- \u2800`,isMeta:!0}];return En(bt,null,M),P(M.length),M});break}case"/kill":{(async()=>{let a=x[1]?parseInt(x[1],10):null,{getProcessTree:h,killProcess:M}=await import("./process-6Y7LS2MS.js");if(!a||isNaN(a))I(O=>(P(O.length+1),[...O,{id:Date.now(),role:"system",text:`\u2726 Usage: \x1B[36m/kill <pid>\x1B[0m
257
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Select an active process PID from the autocomplete list.
258
- \u2800`,isMeta:!0}]));else{let O=a===process.pid,U=In.some(K=>K.pid===a&&(K.isRoot||K.url&&K.url.includes(":52991")||K.cmd&&K.cmd.includes("usage-daemon-worker")));if(O||U){let K=O?"FluxFlow (Main Process)":"Internal Process";I(z=>(P(z.length+1),[...z,{id:Date.now(),role:"system",text:`\u2726 \x1B[31mPROTECTED PROCESS\x1B[0m
259
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m PID: \x1B[33m${a}\x1B[0m (${K})
260
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Unable to kill protected core process. Use \x1B[36m/quit\x1B[0m to safely shutdown FluxFlow.
261
- \u2800`,isMeta:!0}]));return}try{let K=await M(a);K.success?I(z=>(P(z.length+1),[...z,{id:Date.now(),role:"system",text:`\u2726 Process Terminated:
262
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m PID: \x1B[31m${a}\x1B[0m (${K.message})
263
- \u2800`,isMeta:!0}])):I(z=>(P(z.length+1),[...z,{id:Date.now(),role:"system",text:`\u2726 \x1B[31mFAILED TO KILL PROCESS\x1B[0m
264
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m PID: ${a}
265
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Reason: ${K.message}
266
- \u2800`,isMeta:!0}]))}catch(K){I(z=>(P(z.length+1),[...z,{id:Date.now(),role:"system",text:`\u2726 \x1B[31mERROR\x1B[0m
267
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${K.message}
268
- \u2800`,isMeta:!0}]))}}})();break}case"/help":{I(u=>(P(u.length+1),[...u,{id:Date.now(),role:"system",isHelpRecord:!0,isMeta:!0}]));break}case"/btw":{I(u=>(P(u.length+1),[...u,{id:Date.now(),role:"system",text:`\u2726 RESTRICTED
269
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m '/btw' only available when agent is working
270
- \u2800`,isMeta:!0}]));break}default:I(u=>(P(u.length+1),[...u,{id:Date.now(),role:"system",text:`\u2726 ERROR
271
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Unknown command: '${v}'
272
- \u2800`,isMeta:!0}]))}}else{let x=`[Prompted on: ${new Date().toLocaleString(void 0,{year:"numeric",month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"})}]`,v={id:"user-"+Date.now(),role:"user",text:`${f}
273
-
274
- ${x}`};I(a=>{let h=[...a,v];return P(h.length),En(bt,null,h),h}),(async()=>{let a=!1,h=()=>{a||(a=!0,I(K=>{let z=K[K.length-1];if(z&&z.text&&z.text.includes("Request Cancelled"))return K;let te=[...K.map(oe=>oe.isStreaming?{...oe,isStreaming:!1}:oe),{id:"cancel-"+Date.now(),role:"agent",text:`
275
-
276
- \x1B[33m\u24D8 Request Cancelled\x1B[0m`,isMeta:!1}];return P(te.length),te}))},M=!1;Xs(!0),Es(Date.now()),Y(!1);let O=Date.now(),U=!0;try{let K=[...Ft,v].filter(G=>G.role!=="think"&&!G.isVisualFeedback&&!G.isMeta&&!G.isTerminalRecord&&!(G.text&&G.text.includes("[TERMINAL_RECORD]"))&&!String(G.id).startsWith("welcome")),z=[],V=K.map((G,Ce)=>{let we=G.fullText||G.text||"";if(G.role==="user"&&Ce<K.length-1)if(we.includes("**CONTEXT SUMMARY OF PREVIOUS TURNS")){let De=we.indexOf("**CONTEXT SUMMARY OF PREVIOUS TURNS");if(De!==-1){let Ae=we.substring(0,De).lastIndexOf("[SYSTEM METADATA]");Ae!==-1?we=we.substring(Ae).trim():we=we.substring(De).trim()}}else{let De=we.lastIndexOf("[USER]"),ot=we.lastIndexOf("[USER PROMPT]");De!==-1?we=we.substring(De+6).trim():ot!==-1&&(we=we.substring(ot).trim())}return{...G,text:we}}),te=0;for(;te<V.length;){let G=V[te];if(G.role==="user")z.push(G),te++;else{let Ce=[];for(;te<V.length&&V[te].role!=="user";)Ce.push(V[te]),te++;let we=[],De=[],ot=null,Ae=!1,nt=()=>{we.length>0&&(z.push({role:"agent",text:we.join(`
277
- `).trim()}),we=[]),De.length>0&&(z.push({role:"system",text:De.join(`
278
-
279
- `),...ot?{binaryPart:ot}:{}}),De=[],ot=null),Ae=!1};for(let ht=0;ht<Ce.length;ht++){let R=Ce[ht],ge=R.role==="system"&&(R.text?.startsWith("[ACTION RESULT]")||R.text?.startsWith("[TOOL RESULT]")||R.text?.startsWith("SUCCESS:")||R.text?.startsWith("ERROR:")||R.fullText?.startsWith("[ACTION RESULT]")||R.fullText?.startsWith("[TOOL RESULT]")||R.fullText?.startsWith("SUCCESS:")||R.fullText?.startsWith("ERROR:")),Ee=R.fullText||R.text||"",Ge=Ee.trim();if(!(!Ge&&!R.binaryPart)){if(ge){let Oe=!Ge.startsWith("[ACTION RESULT]")&&!Ge.startsWith("[TOOL RESULT]")?`[ACTION RESULT]: ${Ge}`:Ge;De.push(Oe),R.binaryPart&&(ot=R.binaryPart)}else if(R.role==="agent"){!Ae&&De.length>0&&nt();let Oe=Ge,kt=la(Oe),Co=/\[\s*(?:tool:(?:functions\.)?|action:(?:functions\.)?|action:)([a-zA-Z0-9_]+)\s*\(/gi,jt=[],Mo;for(;(Mo=Co.exec(kt))!==null;)jt.push(Mo.index);if(jt.length>0){let yn=ca(Oe),Cn=[];for(let xo=0;xo<jt.length;xo++){let Yn=jt[xo],qr=xo+1<jt.length?jt[xo+1]:Oe.length;yn.find(ml=>ml.fullMatch&&Oe.startsWith(ml.fullMatch,Yn))||Cn.push({start:Yn,end:qr})}if(Cn.length>0){let xo="",Yn=0;for(let qr of Cn)xo+=Oe.substring(Yn,qr.start),Yn=qr.end;xo+=Oe.substring(Yn),Oe=xo.trim()}}if(!Oe)continue;let fr=Ee.endsWith(`
280
- `),js=Oe.toLowerCase().includes("tool:")||Oe.toLowerCase().includes("action:"),jr=!1;for(let yn=ht+1;yn<Ce.length;yn++){let Cn=Ce[yn];if(Cn.role==="agent"){let xo=(Cn.fullText||Cn.text||"").trim();if(xo){jr=xo.startsWith("[");break}}}we.push(Oe),js&&fr&&jr?Ae=!0:Ae=!1}}}nt()}}let oe=ma(je,z,{profile:fn,thinkingLevel:Xe,mode:j,systemSettings:ce,janitorModel:k,sessionStats:Io,chatId:bt,isPlayground:!!_e.playground,aiProvider:N,apiKey:Ke,apiTier:tt,wildcardTooling:Pr,wildercardTooling:ae,cols:H.columns-6,rows:30,onTokenChunk:(G,Ce)=>{let we=Date.now();if(Es(we),typeof Ce=="number"){ki.current=Ce;let De=Ds.current;De.startTime||(De.startTime=we,De.totalWords=0,De.chunks=[]),De.totalWords+=Ce,De.chunks||(De.chunks=[]),De.chunks.push({time:we,words:Ce});let Ae=we-400;if(De.chunks=De.chunks.filter(nt=>nt.time>=Ae),De.chunks.length>0){let nt=De.chunks.reduce((ge,Ee)=>ge+Ee.words,0),ht=De.chunks[0].time,R=Math.max(.4,(we-ht)/1e3);De.wps=Math.round(nt/R*10)/10}}},onVisualFeedback:G=>{I(Ce=>[...Ce.map(De=>De.isStreaming?{...De,isStreaming:!1}:De),{id:"visual-"+Date.now()+"-"+Math.random().toString(36).substring(2,9),role:"system",text:G,isVisualFeedback:!0}])},onSubagentUpdate:()=>{gc(na.map(G=>({...G})))},onExecStart:G=>{qe(),se(),Hi(G),Gn("")},onExecChunk:G=>{Gn(Ce=>Ce+G)},onExecEnd:()=>{let G=Fs.current,Ce=$s.current||"";Fs.current=null,$s.current="",I(we=>{if(!G)return we;let De=Vl(Ce),ot=`[TERMINAL_RECORD]
281
- COMMAND: ${G}
282
- PTY: ${jn}
283
- OUTPUT: ${De.replace(/\n{3,}/g,`
284
-
285
- `)}`,nt=[...we.map(ht=>ht.isStreaming?{...ht,isStreaming:!1}:ht),{id:"term-"+Date.now(),role:"system",text:ot,isTerminalRecord:!0}];return P(nt.length),nt}),Hi(null),Wi(!1),Gn("")},onToolResult:(G,Ce)=>{if(G==="success"){if(lc(we=>we+1),Ce==="generate_image"){mc(ot=>ot+1);let De={Low:.001,"Low-High":.002,Medium:.008,"Medium-High":.01,High:.045,Ultra:.0488,Premium:.1}[Ho.quality]||.002;xc(ot=>ot+De)}}else G==="denied"?cc(we=>we+1):ac(we=>we+1)},onIDEApproval:ko,onToolApproval:async(G,Ce,we={})=>{let De=vn(Ce||"{}"),ot=De.path||De.targetPath||De.file||"",Ae=ce?.alwaysAskFiles||".env, .env.*, *.env",nt=(G==="view_file"||G==="write_file"||G==="update_file")&&xl(ot,Ae),ht=ot?Ct.resolve(ot).toLowerCase():"",R=ot?Ct.extname(ot).toLowerCase():"",ge=!nt&&(ce.autoExec||Vi||G==="write_file"&&R&&Yi.current.has(R)||G==="update_file"&&ht&&ji.current.has(ht));if(G==="exec_command"){let{command:Ee}=De,Ge=(Ee||"").trim(),Oe=/^(echo|ls|dir|pwd|cd|git status|git log|git diff|type|cat|help)\b/i;return ce.autoExec||Vi||qi.current.has(Ge)||Ge&&Oe.test(Ge)?"allow":we.checkOnly?null:new Promise(kt=>{fs(),Kn({tool:G,args:Ce,resolve:kt}),re("terminalApproval")})}return ge?"allow":we.checkOnly?null:new Promise(Ee=>{fs(),Kn({tool:G,args:Ce,resolve:Ee}),re("approval")})},onAskUser:async(G,Ce)=>(qe(),se(),fs(),new Promise(we=>{let De=!1;_s({question:G,options:Ce,resolve:ot=>{De||(De=!0,I(Ae=>{if(Ae.some(R=>R.isAskRecord&&R.text?.includes(`Selection: ${ot}`)))return Ae;let ht=[...Ae,{id:"ask-"+Date.now(),role:"system",text:`\u{1F4AC} **Ask User**
286
- Question: ${G}
287
- Selection: ${ot}`,isAskRecord:!0}];return P(ht.length),ht}),we(ot))}}),re("ask")})),onUsage:G=>{let Ce=G.totalTokenCount||0,we=G.cachedContentTokenCount||0,De=G.candidatesTokenCount||0,ot=Math.max(0,Ce-De);if(Zo({tokens:Ce}),Oi(Ae=>Ae+Ce),ot>0&&Ni(Ae=>Ae+ot),we>0&&Fi(Ae=>Ae+we),De>0&&$i(Ae=>Ae+De),ot>0||we>0){zt.current.push({input:ot,cached:we}),zt.current.length>3&&zt.current.shift();let Ae=zt.current.reduce((R,ge)=>R+ge.input,0),nt=zt.current.reduce((R,ge)=>R+ge.cached,0),ht=Ae>0?nt/Ae*100:0;gn(ht)}Li(Ae=>Ae+1)}},async()=>Xo.current?Xo.current:null,po),$=!1,Re=null,Ue=null,We=!1,ze=!1,Ve=!1,it=!1,de=0,he=null,Qe=/\[?\s*turn\s*:\s*.*?\s*\]?/gi;for await(let G of oe){if(await new Promise(R=>setTimeout(R,3)),G.type==="text"&&Es(Date.now()),U&&G.type==="text"&&(O=Date.now(),U=!1,ce.progressiveRendering&&Be()),G.type==="status"){if(G.content&&(G.content.includes("Steering Hint Injected")||G.content.includes("Question Forwarded"))){let R=Xo.current;R&&(I(ge=>{P(ge.length+1);let Ee=R.startsWith("/btw"),Ge=Ee?R.replace(/^\/btw\s*/,""):R,Oe=Ee?"[QUESTION]":"[STEERING HINT]";return[...ge,{id:"hint-"+Date.now(),role:"user",text:`${Oe}
288
- ${Ge}`,color:"cyan",isSteeringHint:!0,hintType:Ee?"QUESTION":"STEERING HINT",hintContent:Ge}]}),Ks(null),Xo.current=null)}G.content?.includes("[start]")||Hs(G.content),G.content?.includes("[start]")?(clearInterval(dr),cr(0),dr=setInterval(()=>{cr(R=>R+1)},1e3)):G.content?.includes("[end]")&&(cr(0),clearInterval(dr)),Bn()&&es(G.content),G.content==="Request Cancelled"&&(qe(),se(),h());continue}if(G.type==="status_history"){Hs(G.content),Bn()&&es(G.content),I(R=>[...R,{id:"condense-"+Date.now(),role:"system",text:`\u2726 ${G.content}
289
- \u2800`,isMeta:!0}]);continue}if(G.type==="summary_injected"){I(R=>R.map(ge=>ge.id===G.content.id?{...ge,fullText:G.content.text}:ge));continue}if(G.type==="spinner"){wc(G.content);continue}if(G.type==="model_update"){Sc(G.content);continue}if(G.type==="turn_reset"){if(qe(),se(),Re=null,Ue=null,$=!1,We=!1,ze=!1,it=!1,Ve=!1,I(R=>{let ge=R.map(Ee=>{if(Ee.isStreaming){let Ge=Ee.text?Wt(Ee.text):Ee.text,Oe=Ee.fullText?Wt(Ee.fullText):Ee.fullText;return{...Ee,isStreaming:!1,text:Ge,fullText:Oe}}return Ee});return P(ge.length),ge}),Go(),global.gc){for(let R=0;R<2;R++)global.gc(),await new Promise(ge=>setImmediate(ge));g.current=Date.now()}continue}if(G.type==="interactive_turn_finished"){Xs(!1),cr(0),clearInterval(dr),Bn()&&es(null),M=!0,ce?.agentFinishSound&&(async()=>{try{let ge=(await Ko())[bt],Ee=Tr(ge,String(bt));gi(Ee)}catch{gi(String(bt))}})(),Go(),ce?.autoTruncateResults&&I(R=>{let ge=R.map(Ee=>{let Ge=Ee.fullText||Ee.text||"";return!Ge.startsWith("[ACTION RESULT]:")&&!Ge.startsWith("[TOOL RESULT]:")||Ge.startsWith("[ACTION RESULT]: Goal")||Ge.includes("...Success result truncated to save tokens")||Ge.startsWith("[ACTION RESULT]: USER CHOOSE")||Ge.startsWith("[ACTION RESULT]: Skill:")||Ge.startsWith("[ACTION RESULT]: DOCs:")||Ge.startsWith("[ACTION RESULT]: Markdown parsed")||Ge.startsWith("[ACTION RESULT]: Search results for [")||Ge.startsWith("[ACTION RESULT]: AI Mode temporarily failed")||Ge.startsWith("[ACTION RESULT]: Background subagent started. Task ID:")||/^\[ACTION RESULT\]: File \[.*?\] saved/s.test(Ge)?Ee:{...Ee,fullText:"[ACTION RESULT]: ...Success result truncated to save tokens"}});return En(bt,null,ge),P(ge.length),ge}),ia({profile:fn,thinkingLevel:Xe,mode:j,janitorModel:k,chatId:bt,systemSettings:ce,sessionStats:Io,aiProvider:N,apiKey:Ke},G.data.agentText,G.data.fullAgentTextRaw,G.data.history,{onMemoryUpdated:()=>I(R=>{let ge=[...R];return ge.length>0&&(ge[ge.length-1].memoryUpdated=!0),ge}),onBackgroundIncrement:()=>oc(R=>R+1)});continue}if(G.type==="visual_feedback"){qe(),se(),I(R=>{let ge=[...R,{id:"feedback-"+Date.now()+"-"+Math.random().toString(36).substring(2,9),role:"system",text:Wt(G.content),isVisualFeedback:!0}];return P(ge.length),ge});continue}if(G.type==="exec_start"){qe(),se();continue}if(G.type==="liveTokens"){Zo({tokens:G.content});continue}if(G.type==="usage"){let R=G.content.totalTokenCount||0,ge=G.content.cachedContentTokenCount||0,Ee=G.content.candidatesTokenCount||0,Ge=Math.max(0,R-Ee);if(Zo({tokens:R}),Oi(Oe=>Oe+R),Ge>0&&Ni(Oe=>Oe+Ge),ge>0&&Fi(Oe=>Oe+ge),Ee>0&&$i(Oe=>Oe+Ee),Ge>0||ge>0){zt.current.push({input:Ge,cached:ge}),zt.current.length>3&&zt.current.shift();let Oe=zt.current.reduce((jt,Mo)=>jt+Mo.input,0),kt=zt.current.reduce((jt,Mo)=>jt+Mo.cached,0),Co=Oe>0?kt/Oe*100:0;gn(Co)}Li(Oe=>Oe+1);continue}if(G.type==="tool_time"){uc(R=>R+G.content);continue}if(G.type==="tool_result"){if(se(),Re=null,Ue=null,$=!1,We=!1,ze=!1,it=!1,Ve=!1,de=0,he=null,I(R=>{let ge=[...R,{id:"tool-"+Date.now()+"-"+Math.random().toString(36).substring(2,7),role:"system",text:Wt(G.content),fullText:Wt(G.aiContent),binaryPart:G.binaryPart,toolName:G.toolName}];return P(ge.length),ge}),q.current&&(Ue=q.current.id,ze=!0),G.toolName==="update_file"&&G.aiContent){let R=G.aiContent.split(`
290
- `),ge=0,Ee=0,Ge=!1;for(let Oe of R){if(Oe.includes("[DIFF_START]")){Ge=!0;continue}if(Oe.includes("[DIFF_END]")){Ge=!1;continue}Ge&&(/^\+\s*\d+/.test(Oe)?ge++:/^\-\s*\d+/.test(Oe)&&Ee++)}Sn("linesAdded",ge),Sn("linesRemoved",Ee)}else if(G.toolName==="write_file"&&G.aiContent){let R=G.aiContent.match(/- Stats: \[(\d+) lines/),ge=R?parseInt(R[1]):0,Ee=0;if(G.aiContent.includes("Old File contents:")){let Ge=G.aiContent.split(`
291
- `),Oe=!1;for(let kt of Ge){if(kt.includes("Old File contents:")){Oe=!0;continue}Oe&&(kt.startsWith("- Content Preview:")||kt.startsWith("- Stats:")?Oe=!1:/^\s*\d+\s*\|/.test(kt)&&Ee++)}}(ge>0||Ee>0)&&(Sn("linesAdded",ge),Sn("linesRemoved",Ee))}continue}let Ce=G.content;if(G.type==="text"&&Ce.includes("Request Cancelled")){if(global.gc){for(let R=0;R<3;R++)global.gc(),await new Promise(ge=>setImmediate(ge));g.current=Date.now()}continue}let we=Ce.toLowerCase();if(Ce.includes("```")&&(We=!We),(we.includes("tool:")||we.includes("action:"))&&(ze=!0,de=0,he=null,(Ce.includes("[tool:")||Ce.includes("[action:"))&&(de=0)),ze){for(let R=0;R<Ce.length;R++){let ge=Ce[R];!he&&(ge==="'"||ge==='"'||ge==="`")?he=ge:he&&ge===he&&Ce[R-1]!=="\\"&&(he=null),he||(ge==="("||ge==="["?de++:(ge===")"||ge==="]")&&de--)}de<=0&&!he&&(ze=!1)}let De=/^\s*(?:<think_fluxflow[^>]*>|<\|channel>thought|\[think_fluxflow\])/i,ot=(R,ge,Ee=1)=>{let Ge=ge>0?R[ge-1]:"",Oe=ge+Ee<R.length?R[ge+Ee]:"";return Ge==="`"&&Oe==="`"},Ae=R=>{let ge=/(?:<\/think_fluxflow>|<channel\|>|\[\/think_fluxflow\])/gi,Ee;for(;(Ee=ge.exec(R))!==null;)if(!ot(R,Ee.index,Ee[0].length))return{index:Ee.index,length:Ee[0].length};return{index:-1,length:0}},nt=q.current?.role==="agent"&&q.current.text||"",ht=!Ve&&nt.trim().length===0;if(!$&&ht&&(De.test(Ce)||De.test(nt+Ce))){let R=De.test(Ce)?Ce:nt+Ce,ge=R.match(De),Ee=ge.index,Ge=ge[0].length,Oe=R.substring(Ee+Ge);qe(),q.current=null,$=!0,Ve=!0,Re="think-"+Date.now(),q.current={id:Re,role:"think",text:"",isStreaming:!0,startTime:Date.now()};let kt=Ae(Oe);if(kt.index!==-1){let jt=Oe.substring(0,kt.index).replace(/^\r?\n+/,"").replace(/\r?\n+$/,""),Mo=Oe.substring(kt.index+kt.length);q.current.text=Wt(jt);let fr=q.current.startTime||Date.now();q.current.duration=Date.now()-fr,se(),$=!1,Ue="agent-"+Date.now(),q.current={id:Ue,role:"agent",text:"",isStreaming:!0},Mo&&mt(Mo)}else{let Co=Oe.replace(/^\r?\n+/,"");Co&&mt(Co)}continue}if(!$&&!Ve&&Ce.trim().length>0&&(Ve=!0),$&&q.current?.role==="think"){qe();let ge=(q.current.text||"")+Ce,Ee=Ae(ge);if(Ee.index!==-1){let Ge=ge.substring(0,Ee.index),Oe=ge.substring(Ee.index+Ee.length);q.current.text=Wt(Ge);let kt=q.current.startTime||Date.now();q.current.duration=Date.now()-kt,se(),$=!1,Ue="agent-"+Date.now(),q.current={id:Ue,role:"agent",text:"",isStreaming:!0},Oe&&mt(Oe)}else mt(Ce);continue}else if(!$){let R=Ce.toLowerCase();!it&&(R.includes("tool:")||R.includes("action:"))&&(it=!0),!q.current||q.current.role!=="agent"?(Ue="agent-"+Date.now(),q.current={id:Ue,role:"agent",text:Wt(Ce),isStreaming:!0},ct()):mt(Ce)}}let Je=Date.now();dc(G=>G+(Je-O))}catch(K){I(z=>(P(z.length+1),[...z,{id:"error-"+Date.now(),role:"system",text:`\u274C ERROR: ${K.message}`}]))}finally{let K=Date.now()-O;if(q.current&&(q.current.workedDuration=K),st.current&&(await ut(),clearInterval(st.current),st.current=null),Xs(!1),Hs(null),cr(0),clearInterval(dr),se(),Gs.current&&h(),Go(),global.gc)try{for(let z=0;z<3;z++)global.gc(),await new Promise(V=>setImmediate(V));g.current=Date.now()}catch{}if(M||process.stdout.isTTY&&(process.stdout.write("\x1B]0;FluxFlow | Idle\x07"),process.stdout.write("\x1B]633;P;TerminalTitle=FluxFlow | Idle\x07")),Xo.current){Vs(Xo.current),Ks(null);let z=Xo.current;Xo.current=null,I(V=>{let te=[...V],oe=te.reverse().find($=>$.text?.includes("[STEERING HINT: QUEUED]")||$.text?.includes("[QUESTION: QUEUED]"));return oe&&(oe.text.includes("[STEERING HINT: QUEUED]")?oe.text=oe.text.replace("[STEERING HINT: QUEUED]","[STEERING HINT: FINISHED_TURN]"):oe.text.includes("[QUESTION: QUEUED]")&&(oe.text=oe.text.replace("[QUESTION: QUEUED]","[QUESTION: FINISHED_TURN]"))),te.reverse()}),re("resolution")}I(z=>{let V=Date.now()-O,te=!1,oe=[...z].reverse().map(Ue=>{let We=Ue.isStreaming?{...Ue,isStreaming:!1}:Ue;return We.text&&(We.text=(" "+We.text).slice(1)),!te&&We.role==="agent"&&(te=!0,We={...We,workedDuration:V}),We}).reverse();if(!oe.some(Ue=>Ue.role==="agent"&&Ue.text?.trim().length>0)){let Ue=[...oe].reverse().find(We=>We.role==="think"&&We.text?.trim().length>0);Ue&&oe.push({id:"agent-fallback-"+Date.now(),role:"agent",text:Ue.text,isStreaming:!1,workedDuration:V})}let Re=oe.filter(Ue=>!String(Ue.id).startsWith("welcome")&&(!Ue.isMeta||Ue.text&&Ue.text.includes("Request Cancelled")));return En(bt,null,Re),P(oe.length),oe})}})()}b(""),Y(!1)}},lt=Jn(()=>{if(y.startsWith("/")&&!rt){let x=y.split(" "),v=x[x.length-1].toLowerCase();if(x.length===1){let a=v.startsWith("/")?v.slice(1):v;return cl.filter(h=>(h.cmd.startsWith("/")?h.cmd.slice(1):h.cmd).toLowerCase().includes(a))}let u=cl;for(let a=0;a<x.length-1;a++){let h=x[a].toLowerCase(),M=u.find(O=>O.cmd.toLowerCase()===h);if(M&&M.subs)u=M.subs;else return[]}return u.filter(a=>a.cmd.toLowerCase().includes(v))}let n=y.split(" "),o=n[n.length-1],c=o&&o.startsWith("\\@");if((o&&o.startsWith("@")||c)&&!rt){let x=o.indexOf("#"),v=x!==-1,u=c?2:1,a=v?o.substring(u,x).toLowerCase():o.slice(u).toLowerCase(),h=v?o.substring(x):"";return bu(process.cwd()).filter(U=>U.name.toLowerCase().includes(a)).map(U=>{let K=U.relativePath.replace(/\\/g,"/"),z=K.startsWith(".")?K:"./"+K;return{cmd:(c?"\\@":"@")+"["+z+h+"]",desc:U.relativePath}})}return[]},[y,rt]);gt(()=>{let n=0;for(;n<lt.length;){let o=lt[n],c=o?.cmd||o||"";if(typeof c=="string"&&c.trimStart().startsWith("---"))n++;else break}Pe(n<lt.length?n:0)},[lt]);let[Vr,Yr]=J(0),ul=Ze(0);gt(()=>{let n=ul.current>0,o=lt.length>0;if(ul.current=lt.length,!o){Yr(0);return}if(!n){Yr(1);return}Yr(lt.length)},[lt]),gt(()=>{if(Vr>0&&Vr<lt.length){let n=setTimeout(()=>{Yr(o=>Math.min(o+1,lt.length))},1);return()=>clearTimeout(n)}},[Vr,lt.length]),gt(()=>{if(St!=="providerBudgetSelect")return;let n=["Google","DeepSeek","Mistral","NVIDIA","OpenRouter","Ollama","InferX","SenseNova","AIHubMix","Poolside","ExpLabs","TokenHarbor","Infron","APInex","xKiro"],o=Ie.providerBudgets||{},c=n.reduce((f,x)=>(f[x]=!!(o[x]&&(o[x].agentLimit||o[x].tokenLimit||o[x].monthlyTokenLimit||o[x].dailyCostLimit||o[x].monthlyCostLimit)),f),{});Di(c),Fr(0)},[St]),gt(()=>{if(St!=="providerBudgetFlow")return;let n={},o=Ie.providerBudgets||{};for(let c of kn){let f=o[c]||{};n[c]={agentLimit:zo(f.agentLimit),tokenLimit:zo(f.tokenLimit),monthlyTokenLimit:zo(f.monthlyTokenLimit),dailyCostLimit:zo(f.dailyCostLimit),monthlyCostLimit:zo(f.monthlyCostLimit)}}or(n),bo(0)},[St,kn]);let Lu=({label:n,isSelected:o})=>{let c=n==="Cancel"||n==="Back"||n.toLowerCase().includes("exit")||n.toLowerCase().includes("back");return e.createElement(m,{marginTop:c?1:0,backgroundColor:o?"#2a2a2a":void 0,paddingX:1,width:"100%"},e.createElement(l,{color:o?"white":"gray",bold:o},o?"\u276F ":" ",n))},mo=(n,o,c,f=10,x=2,v=9)=>{let u=ho(c),a=!u&&c>0?Math.min(100,o/c*100):0,h=Math.round(a),M=Math.round(h/100*f),O="\u2588".repeat(M)+"\u2591".repeat(Math.max(0,f-M)),U=s.success||"green";h>=40&&h<=80?U=s.warning||"yellow":h>80&&(U=s.danger||"red");let K=n.toLowerCase().includes("cost")||n.toLowerCase().includes("spend"),z=!K&&(n.toLowerCase().includes("token")||n.toLowerCase().includes("daily")||n.toLowerCase().includes("monthly")),V=u?"\u221E":K?`$${Number(c).toFixed(2)}`:z?Lt(c):c,te=Number(o)||0,oe=K?`$${te.toFixed(te<.01&&te>0?4:2)}`:z?Lt(o):o,$;return u||a===0?$="0%":a>0&&a<1?$="<1%":$=`${h}%`,e.createElement(m,{flexDirection:"row",paddingLeft:x,key:n},e.createElement(m,{width:v},e.createElement(l,{color:s.textMuted},n,": ")),e.createElement(l,{color:U},O),e.createElement(l,{color:s.textMuted}," ",$," (",oe,"/",V,")"))},Dc=()=>{switch(St){case"settings":return e.createElement(us,{systemSettings:ce,setSystemSettings:Nt,apiTier:tt,setActiveView:re,setInputConfig:io,saveSettings:Kt,quotas:Ie,setMessages:I,aiProvider:N,autoCompletion:nr,setAutoCompletion:Bs,profileData:fn,setProfileData:vs,setProviderReturnView:Ms,setApiKey:Ot,initAI:fo});case"theme":return e.createElement(us,{systemSettings:ce,setSystemSettings:Nt,apiTier:tt,setActiveView:re,setInputConfig:io,saveSettings:Kt,quotas:Ie,setMessages:I,aiProvider:N,autoCompletion:nr,setAutoCompletion:Bs,profileData:fn,setProfileData:vs,initialSelectingTheme:!0,onCloseTheme:()=>re("chat"),setProviderReturnView:Ms,setApiKey:Ot,initAI:fo});case"selectProvider":return e.createElement(Ut,{title:"SELECT AI PROVIDER",searchable:!0,items:[{label:"Google",value:"Google"},{label:"Nvidia",value:"NVIDIA"},{label:"DeepSeek",value:"DeepSeek"},{label:"InferX",value:"InferX"},{label:"SenseNova",value:"SenseNova"},{label:"Poolside",value:"Poolside"},{label:"Experiential Labs",value:"ExpLabs"},{label:"Token Harbor",value:"TokenHarbor"},{label:"Infron",value:"Infron"},{label:"APInex",value:"APInex"},{label:"xKiro",value:"xKiro"},{label:"Ollama",value:"Ollama"},...process.env.ENABLE_9ROUTER==="true"||process.env.ENABLE_9ROUTER===!0?[{label:"9router [Local Proxy]",value:"9router"}]:[],{label:"AIHubMix [Experimental]",value:"AIHubMix"},{label:"Mistral [Experimental]",value:"Mistral"},{label:"OpenRouter [Experimental]",value:"OpenRouter"},{label:"Custom [OpenAI Chat Completion]",value:"c_openai"},{label:"Back",value:Jo}],theme:ce.theme,onSelect:async n=>{if(n.value===Jo||n.value==="settings"||n.value==="Back"){re(Jo);return}let o=n.value,c=await on(o),f="";if(o==="9router"){let x=await Ci();x.ok||(f=`
292
-
293
- \x1B[33m\u2726 WARNING: 9router does not appear to be running on ${x.url}.\x1B[39m
294
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m To start 9router: \x1B[36mnpx 9router\x1B[39m or \x1B[36mnpm i -g 9router && 9router\x1B[39m`)}if(o==="c_openai"){if(!ce.customOpenAIBaseUrl){io({label:"Enter Custom OpenAI Base URL (.../v1):",key:"customOpenAIBaseUrl",value:"",returnView:Jo}),re("input");return}let x=c||"";try{Zs()}catch{}Qo(o),Ot(x),fo(x,{aiProvider:o,onIDEApproval:ko});let v=(Ie.providerTiers||{})[o]||"Free",u=co(o,v)||"";Gt(u),It(v),Nt(a=>({...a,memory:!1})),Kt({aiProvider:o,activeModel:u,apiTier:v,quotas:Ie,systemSettings:{...ce,memory:!1}}),I(a=>[...a,{role:"system",text:`\u2726 Switched to Custom (OpenAI)!${u?`
295
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model: ${u}.`:""}
296
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Endpoint: ${ce.customOpenAIBaseUrl}${ce.memory?`
297
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available with Custom (OpenAI).`:""}
298
- \u2800`,isMeta:!0}]),re(Jo);return}if(c){try{Zs()}catch{}Qo(o),Ot(c),fo(c,{aiProvider:o,onIDEApproval:ko});let x=(Ie.providerTiers||{})[o]||"Free",v=co(o,x);Gt(v),It(x),o==="NVIDIA"&&process.env.NVIDIA_BASE_URL||o==="Ollama"||o==="InferX"||o==="SenseNova"||o==="Poolside"||o==="9router"||o==="ExpLabs"||o==="TokenHarbor"||o==="Infron"||o==="APInex"||o==="xKiro"||o==="c_openai"?(Nt(a=>({...a,memory:!1})),Kt({aiProvider:o,activeModel:v,apiTier:x,quotas:Ie,systemSettings:{...ce,memory:!1}})):Kt({aiProvider:o,activeModel:v,apiTier:x,quotas:Ie});let u=o==="c_openai"?"Custom (OpenAI)":o;I(a=>[...a,{role:"system",text:`\u2726 Switched to ${u} (cached)!${v?`
299
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model: ${v}.`:""}${(o==="Ollama"||o==="InferX"||o==="SenseNova"||o==="AIHubMix"||o==="Poolside"||o==="9router"||o==="ExpLabs"||o==="TokenHarbor"||o==="Infron"||o==="APInex"||o==="xKiro"||o==="c_openai")&&ce.memory?`
300
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available with ${u}.`:""}${o==="NVIDIA"&&process.env.NVIDIA_BASE_URL&&ce.memory?`
301
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available with Custom Endpoints.`:""}${f}
302
- \u2800`,isMeta:!0}]),re(Jo)}else io({label:`Enter ${o==="c_openai"?"Custom (OpenAI)":o} API Key:`,key:"providerKey",provider:o,value:"",returnView:Jo}),re("input")},onClose:()=>re(Jo)});case"apiTier":return e.createElement(Ut,{title:`Show Paid models from ${N.toUpperCase()}?`,subtitle:"Curated model list. Can use anything if typed manually.",items:[{label:"No (For Free APIs) [Shows Free model list]",value:"Free"},{label:`Yes (For Billing APIs) [Shows Paid model list] ${tt==="Paid"?"\u25CF":""}`,value:"Paid"},{label:"Back",value:"settings"}],theme:ce.theme,onSelect:n=>{if(n.value==="settings"||n.value==="Back"){re("settings");return}let o=n.value;It(o);let c={...Ie.providerTiers||{},[N]:o},f={...Ie,providerTiers:c};eo(f),Kt({apiTier:o,quotas:f}),re("settings")}});case"resetMode":return e.createElement(Ut,{title:"SELECT MONTHLY RESET MODE",items:[{label:"Default (Rolling 30-Day Window)",value:"Rolling"},{label:"Custom (Set reset day of month)",value:"Custom"},{label:"Back",value:"apiTier"}],theme:ce.theme,onSelect:n=>{if(n.value==="apiTier"||n.value==="Back"){re("apiTier");return}let o=n.value,c={...Ie,resetMode:o};eo(c),o==="Custom"?(io({label:"Enter monthly reset day (1-30):",key:"quotas",subKey:"resetDay",value:String(Ie.resetDay||1),returnView:"settings"}),re("input")):(Kt({apiTier:tt,quotas:c}),re("settings"))},onClose:()=>re("apiTier")});case"budgetTypeSelect":return e.createElement(Ut,{title:"SELECT BUDGET TYPE",items:[{label:`Global Budget (single limit for all providers) ${tt==="Paid"&&!Ie.providerBudgets?.__useProvider?"\u25CF":""}`,value:"global"},{label:`Provider Budgets (set limits per provider individually) ${Ie.providerBudgets?.__useProvider?"\u25CF":""}`,value:"provider"},{label:"Back",value:_o}],theme:ce.theme,onSelect:n=>{if(n.value===_o||n.value==="Back"){re(_o);return}if(n.value==="global"){let o={...Ie,agentLimit:99999999,tokenLimit:99999999999999,monthlyTokenLimit:99999999999999,providerBudgets:{__useProvider:!1}};eo(o);let c=_o==="settings"?"resetMode":"budgetResetMode";io({label:"Enter Agent daily budget (tokens used):",key:"quotas",subKey:"tokenLimit",value:zo(o.tokenLimit),returnView:_o,next:f=>({label:"Enter Agent monthly budget (tokens used):",key:"quotas",subKey:"monthlyTokenLimit",value:zo(f.monthlyTokenLimit),returnView:_o,next:x=>({label:"Enter Daily Cost Limit ($ or 0 for unlimited):",key:"quotas",subKey:"dailyCostLimit",value:zo(x.dailyCostLimit),returnView:_o,next:v=>({label:"Enter Monthly Cost Limit ($ or 0 for unlimited):",key:"quotas",subKey:"monthlyCostLimit",value:zo(v.monthlyCostLimit),returnView:c})})})}),re("input")}else if(n.value==="provider"){let o={...Ie,agentLimit:99999999,tokenLimit:99999999999999,monthlyTokenLimit:99999999999999,providerBudgets:{...Ie.providerBudgets||{},__useProvider:!0}};eo(o),re("providerBudgetSelect")}},onClose:()=>re(_o)});case"providerBudgetSelect":{let n=["Google","DeepSeek","Mistral","NVIDIA","OpenRouter","Ollama","InferX","SenseNova","AIHubMix","Poolside","ExpLabs","TokenHarbor","Infron","APInex","xKiro"],o=n.some(c=>Ss[c]);return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,padding:0,width:"100%"},e.createElement(m,{paddingX:1,marginBottom:1},e.createElement(l,{color:s.text,bold:!0},"SELECT PROVIDERS TO SET LIMITS FOR")),n.map((c,f)=>{let x=f===Ei,v=!!Ss[c];return e.createElement(m,{key:c,backgroundColor:x?s.highlightBg||"#2a2a2a":void 0,paddingX:1,width:"100%",flexDirection:"row"},e.createElement(l,{color:x?s.text:s.textMuted,bold:x},x?"\u276F ":" "),e.createElement(l,{color:v?s.success||"green":s.textMuted},v?"\u2611":"\u2610"),e.createElement(l,{color:x?s.text:s.textMuted,bold:x}," ",c),v&&(Ie.providerBudgets?.[c]?.agentLimit||Ie.providerBudgets?.[c]?.tokenLimit||Ie.providerBudgets?.[c]?.monthlyTokenLimit||Ie.providerBudgets?.[c]?.dailyCostLimit||Ie.providerBudgets?.[c]?.monthlyCostLimit)?e.createElement(l,{color:s.primary||"cyan"}," (budget set)"):null)}),e.createElement(m,{paddingX:1,marginTop:1,flexDirection:"column"},e.createElement(l,{color:s.textMuted,italic:!0},"\u2191\u2193 Navigate \u2022 Space to toggle \u2022 Enter to confirm \u2022 ESC to go back"),!o&&e.createElement(l,{color:s.warning||"yellow",italic:!0}," Select at least one provider to continue")))}case"providerBudgetFlow":{let n=kn.length,o=n*4;return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,padding:0,width:"100%"},e.createElement(m,{paddingX:1,marginBottom:0,justifyContent:"space-between",flexDirection:"row"},e.createElement(l,{color:s.text,bold:!0},"PROVIDER BUDGET CONFIGURATION"),e.createElement(l,{color:s.textMuted,italic:!0},"(0 or blank = unlimited)")),e.createElement(m,{paddingX:1,marginTop:1,flexDirection:"row"},e.createElement(m,{width:13},e.createElement(l,{color:s.textMuted,bold:!0},"PROVIDER")),e.createElement(m,{width:20,paddingLeft:1},e.createElement(l,{color:s.textMuted,bold:!0},"DAILY TOKENS")),e.createElement(m,{width:22,paddingLeft:1},e.createElement(l,{color:s.textMuted,bold:!0},"MONTHLY TOKENS")),e.createElement(m,{width:18,paddingLeft:1},e.createElement(l,{color:s.textMuted,bold:!0},"DAILY COST ($)")),e.createElement(m,{width:20,paddingLeft:1},e.createElement(l,{color:s.textMuted,bold:!0},"MONTHLY COST ($)"))),e.createElement(m,{paddingX:1},e.createElement(l,{color:s.borderMuted},"\u2500".repeat(93))),kn.map((c,f)=>{let x=f*4,v=f*4+1,u=f*4+2,a=f*4+3,h=An===x,M=An===v,O=An===u,U=An===a,K=h||M||O||U,z=tr[c]?.tokenLimit??"",V=tr[c]?.monthlyTokenLimit??"",te=tr[c]?.dailyCostLimit??"",oe=tr[c]?.monthlyCostLimit??"";return e.createElement(m,{key:c,flexDirection:"row",paddingX:1,marginY:0,backgroundColor:K?s.highlightBg||"#2a2a2a":void 0},e.createElement(m,{width:13,flexDirection:"row"},e.createElement(l,{color:K?s.primary||"cyan":s.text,bold:K},K?"\u276F ":" ",c)),e.createElement(m,{width:20,paddingLeft:1,flexDirection:"row"},h?e.createElement(m,{flexDirection:"row"},e.createElement(l,{color:s.primary||"cyan",bold:!0},"[ "),e.createElement(Zn,{value:z,onChange:$=>{or(Re=>({...Re,[c]:{...Re[c]||{},tokenLimit:$}}))},onSubmit:()=>bo(v)}),e.createElement(l,{color:s.primary||"cyan",bold:!0}," ]")):e.createElement(l,{color:z?s.text:s.textMuted},"[ ",z||"0 (\u221E)"," ]")),e.createElement(m,{width:22,paddingLeft:1,flexDirection:"row"},M?e.createElement(m,{flexDirection:"row"},e.createElement(l,{color:s.primary||"cyan",bold:!0},"[ "),e.createElement(Zn,{value:V,onChange:$=>{or(Re=>({...Re,[c]:{...Re[c]||{},monthlyTokenLimit:$}}))},onSubmit:()=>bo(u)}),e.createElement(l,{color:s.primary||"cyan",bold:!0}," ]")):e.createElement(l,{color:V?s.text:s.textMuted},"[ ",V||"0 (\u221E)"," ]")),e.createElement(m,{width:18,paddingLeft:1,flexDirection:"row"},O?e.createElement(m,{flexDirection:"row"},e.createElement(l,{color:s.primary||"cyan",bold:!0},"[ $"),e.createElement(Zn,{value:te,onChange:$=>{or(Re=>({...Re,[c]:{...Re[c]||{},dailyCostLimit:$}}))},onSubmit:()=>bo(a)}),e.createElement(l,{color:s.primary||"cyan",bold:!0}," ]")):e.createElement(l,{color:te?s.warning||"yellow":s.textMuted},"[ ",te?`$${te}`:"0 (\u221E)"," ]")),e.createElement(m,{width:20,paddingLeft:1,flexDirection:"row"},U?e.createElement(m,{flexDirection:"row"},e.createElement(l,{color:s.primary||"cyan",bold:!0},"[ $"),e.createElement(Zn,{value:oe,onChange:$=>{or(Re=>({...Re,[c]:{...Re[c]||{},monthlyCostLimit:$}}))},onSubmit:()=>{f+1<n?bo((f+1)*4):bo(o)}}),e.createElement(l,{color:s.primary||"cyan",bold:!0}," ]")):e.createElement(l,{color:oe?s.warning||"yellow":s.textMuted},"[ ",oe?`$${oe}`:"0 (\u221E)"," ]")))}),e.createElement(m,{paddingX:1,marginTop:1},An===o?e.createElement(m,{backgroundColor:s.highlightBg||"#2a2a2a",paddingX:1},e.createElement(l,{color:s.success||"green",bold:!0},"\u276F [ Save & Apply Budgets ]")):e.createElement(l,{color:s.textMuted}," [ Save & Apply Budgets ]")),e.createElement(m,{paddingX:1,marginTop:1,flexDirection:"column"},e.createElement(l,{color:s.textMuted,italic:!0},"\u2191\u2193/\u2190\u2192 Navigate \u2022 Enter next / save \u2022 ESC to go back")))}case"budgetResetMode":return e.createElement(Ut,{title:"SELECT MONTHLY RESET MODE",items:[{label:"Default (Rolling 30-Day Window)",value:"Rolling"},{label:"Custom (Set reset day of month)",value:"Custom"},{label:"Back",value:"chat"}],theme:ce.theme,onSelect:n=>{if(n.value==="chat"||n.value==="Back"){re("chat");return}let o=n.value,c={...Ie,resetMode:o};eo(c),o==="Custom"?(io({label:"Enter monthly reset day (1-30):",key:"quotas",subKey:"resetDay",value:String(Ie.resetDay||1),returnView:"chat"}),re("input")):(Kt({apiTier:tt,quotas:c}),re("chat"))},onClose:()=>re("chat")});case"budgetView":{let n=_n?.agent||0,o=Ie.agentLimit||99999999,c=_n?.tokens||0,f=Ie.tokenLimit||99999999999999,x=Ie.resetMode==="Custom"?Wr?.tokens||0:rr?.tokens||0,v=Ie.monthlyTokenLimit||99999999999999,u=_n?.cost||0,a=Ie.dailyCostLimit||99999999999999,h=Ie.resetMode==="Custom"?Wr?.cost||0:rr?.cost||0,M=Ie.monthlyCostLimit||99999999999999,O=tt!=="Paid",U=!!Ie.providerBudgets?.__useProvider,K=Ie.providerBudgets||{},z=["Google","DeepSeek","Mistral","NVIDIA","OpenRouter","Ollama","InferX","SenseNova","AIHubMix","Poolside","ExpLabs","TokenHarbor","Infron","APInex","xKiro"].filter($=>K[$]&&(K[$].agentLimit||K[$].tokenLimit||K[$].monthlyTokenLimit||K[$].dailyCostLimit||K[$].monthlyCostLimit)),V=!U&&(ho(f)||ho(v))&&(ho(a)||ho(M)),te="",oe="";if(Ie.resetMode==="Custom"){let $=new Date,Re=Ie.resetDay||1,Ue=$.getFullYear(),We=$.getMonth();$.getDate()>=Re&&(We+=1,We>11&&(We=0,Ue+=1));let ze=new Date(Ue,We,Re,0,0,0);te=`${ze.toLocaleString("default",{month:"short"}).toUpperCase()}-${Re}`;let it=Math.max(0,ze.getTime()-$.getTime()),de=Math.floor(it/(1e3*60*60)),he=Math.floor(de/24),Qe=de%24;oe=`(${he} days: ${Qe} hrs left)`}return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,padding:1,paddingBottom:0,paddingTop:0,width:"100%"},e.createElement(m,{marginBottom:1,justifyContent:"space-between",width:"100%"},e.createElement(l,{color:s.text,bold:!0,underline:!0},"USAGE LIMITS"),e.createElement(l,{color:s.textMuted},"[ ESC to Close ]")),V?e.createElement(m,{padding:1,justifyContent:"center",alignItems:"center",width:"100%"},e.createElement(l,{color:s.text,bold:!0},"LIMITS NOT SET")):U&&z.length>0?e.createElement(m,{flexDirection:"column",gap:0,width:"100%"},(()=>{let $=r?.columns||H?.columns||80;if($<115){let We=Math.max(5,Math.min(30,$-50));return z.map(ze=>{let Ve=K[ze],it=0,de=_n?.models?.[ze]||{};for(let we in de)it+=de[we]?.tokens||0;let he=0,Je=(Ie.resetMode==="Custom"?Wr:rr)?.models?.[ze]||{};for(let we in Je)he+=Je[we]?.tokens||0;let G=0;for(let we in de)G+=de[we]?.cost||0;let Ce=0;for(let we in Je)Ce+=Je[we]?.cost||0;return e.createElement(m,{key:ze,flexDirection:"column",borderStyle:"single",borderColor:s.borderMuted,paddingX:1,width:"100%"},e.createElement(m,{marginBottom:0},e.createElement(l,{color:s.primary,bold:!0},"\u25C6 ",ze)),mo("Daily",it,Ve.tokenLimit||99999999999999,We,2,9),mo("Monthly",he,Ve.monthlyTokenLimit||99999999999999,We,2,9),(!ho(Ve.dailyCostLimit)||!ho(Ve.monthlyCostLimit))&&e.createElement(e.Fragment,null,mo("Daily Cost",G,Ve.dailyCostLimit||99999999999999,We,2,11),mo("Monthly Cost",Ce,Ve.monthlyCostLimit||99999999999999,We,2,11)))})}let Ue=[];for(let We=0;We<z.length;We+=2)Ue.push(z.slice(We,We+2));return Ue.map((We,ze)=>e.createElement(m,{key:ze,flexDirection:"row",width:"100%"},We.map(Ve=>{let it=K[Ve],de=0,he=_n?.models?.[Ve]||{};for(let nt in he)de+=he[nt]?.tokens||0;let Qe=0,G=(Ie.resetMode==="Custom"?Wr:rr)?.models?.[Ve]||{};for(let nt in G)Qe+=G[nt]?.tokens||0;let Ce=0;for(let nt in he)Ce+=he[nt]?.cost||0;let we=0;for(let nt in G)we+=G[nt]?.cost||0;let De=We.length===1,ot=De?$:Math.floor($/2),Ae=Math.max(5,Math.min(25,ot-36));return e.createElement(m,{key:Ve,flexDirection:"column",borderStyle:"single",borderColor:s.borderMuted,paddingX:1,width:De?"100%":"50%"},e.createElement(m,{marginBottom:0},e.createElement(l,{color:s.primary,bold:!0},"\u25C6 ",Ve)),mo("Daily",de,it.tokenLimit||99999999999999,Ae,2,9),mo("Monthly",Qe,it.monthlyTokenLimit||99999999999999,Ae,2,9),(!ho(it.dailyCostLimit)||!ho(it.monthlyCostLimit))&&e.createElement(e.Fragment,null,mo("Daily Cost",Ce,it.dailyCostLimit||99999999999999,Ae,2,11),mo("Monthly Cost",we,it.monthlyCostLimit||99999999999999,Ae,2,11)))})))})(),te?e.createElement(m,{marginLeft:2,marginTop:1},e.createElement(l,{color:s.textMuted},"Monthly Reset: "),e.createElement(l,{color:s.accent||"magenta",bold:!0},te),oe?e.createElement(l,{color:s.textMuted},` ${oe}`):null):e.createElement(m,{marginLeft:2,marginTop:1},e.createElement(l,{color:s.textMuted},"Monthly Reset: "),e.createElement(l,{color:s.secondary||"blue",bold:!0},"Rolling 30-Day Window"))):e.createElement(m,{flexDirection:"column",borderStyle:"single",borderColor:s.borderMuted,paddingX:1,width:"100%"},mo("Daily Tokens",c,f,"green"),mo("Monthly Tokens",x,v,"yellow"),(!ho(a)||!ho(M))&&e.createElement(e.Fragment,null,mo("Daily Cost",u,a,"cyan"),mo("Monthly Cost",h,M,"magenta")),te?e.createElement(m,{marginLeft:4,marginTop:1},e.createElement(l,{color:s.textMuted},"Monthly Reset: "),e.createElement(l,{color:s.accent||"magenta",bold:!0},te),oe?e.createElement(l,{color:s.textMuted},` ${oe}`):null):e.createElement(m,{marginLeft:4,marginTop:1},e.createElement(l,{color:s.textMuted},"Monthly Reset: "),e.createElement(l,{color:s.secondary||"blue",bold:!0},"Rolling 30-Day Window"))))}case"input":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,padding:0,width:"100%"},e.createElement(m,{paddingX:1},e.createElement(l,{color:s.text,bold:!0},"DATA CONFIGURATION")),Do?.note&&e.createElement(m,{paddingX:1,marginBottom:1},e.createElement(l,{color:s.textMuted,italic:!0},Do.note)),e.createElement(m,{paddingX:1,flexDirection:"row"},e.createElement(l,{color:s.text,bold:!0},Do?.label," "),e.createElement(Zn,{value:Do?.value||"",onChange:n=>io(o=>({...o,value:n})),onSubmit:async n=>{let{key:o,subKey:c,next:f,onDone:x}=Do,v={...Ie},u={};if(o==="quotas"){let a;c.toLowerCase().includes("costlimit")?a=parseFloat(n)||0:c.toLowerCase().includes("limit")||c==="resetDay"?a=parseInt(n)||0:a=n,c==="resetDay"&&(a=Math.max(1,Math.min(30,a))),v[c]=a,eo(v),u.quotas=v}else if(o==="providerBudgets"){let a=Do.providerKey,h=c.toLowerCase().includes("limit")?parseInt(n)||0:n,M=v.providerBudgets||{};v.providerBudgets={...M,[a]:{...M[a]||{},[c]:h}},eo(v),u.quotas=v}else if(o==="activeModel")Gt(n),u.activeModel=n;else if(o==="janitorModel")ve(n),u.janitorModel=n;else if(o==="autoApproveCommands"||o==="autoDisallowCommands"||o==="alwaysAskCommands"){let a={...ce,[o]:n.trim(),sandboxPreset:"Custom"};Nt(a),u.systemSettings=a}else if(o==="externalDataPath"){let a={...ce,useExternalData:!0,externalDataPath:n.trim()};Nt(a),u.systemSettings=a,I(h=>[...h,{id:Date.now(),role:"system",text:"[EXTERNAL STORAGE] Flux Flow will use "+n.trim()+" for data after restart."}])}else if(o==="customOpenAIBaseUrl"){let a=n.trim().replace(/\/+$/,""),h={...ce,customOpenAIBaseUrl:a,memory:!1};Nt(h),u.systemSettings=h;let M=(Ie.providerTiers||{}).c_openai||"Free",O=co("c_openai",M)||"";Qo("c_openai"),Gt(O),It(M),u.aiProvider="c_openai",u.activeModel=O,u.apiTier=M;let K=await on("c_openai")||"";Ot(K),fo(K,{aiProvider:"c_openai",onIDEApproval:ko}),I(z=>[...z,{id:Date.now(),role:"system",text:`\u2726 Custom OpenAI Base URL saved!
303
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Switched to Custom (OpenAI)
304
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Endpoint: ${a}${O?`
305
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model: ${O}`:""}
306
- \u2800`,isMeta:!0}])}else if(o==="imageSettings"){let a=n.trim();if(a.startsWith("sk_")){let h={...Ho,apiKey:a};$r(h),u.imageSettings=h,I(M=>(P(M.length+1),[...M,{id:Date.now(),role:"system",text:"[IMAGE KEY] Custom API key saved successfully.",isMeta:!0}]))}}else if(o==="providerKey"){let a=n.trim(),h=Do.provider;(h==="Ollama"||h==="9router")&&(a==="LOCAL"||a==="")&&(a="LOCAL",h==="Ollama"&&(Nt(K=>({...K,ollamaEndpoint:"Local"})),u.systemSettings={...ce,ollamaEndpoint:"Local"}));let M="";if(h==="9router"){let K=await Ci();K.ok||(M=`
307
-
308
- \x1B[33m\u2726 WARNING: 9router does not appear to be running on ${K.url}.\x1B[39m
309
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m To start 9router: \x1B[36mnpx 9router\x1B[39m or \x1B[36mnpm i -g 9router && 9router\x1B[39m`)}await ti(h,a),Qo(h),Ot(a),fo(a,{aiProvider:h,onIDEApproval:ko});let O=(Ie.providerTiers||{})[h]||"Free",U=co(h,O);Gt(U),It(O),u.aiProvider=h,u.activeModel=U,u.apiTier=O,(h==="NVIDIA"&&process.env.NVIDIA_BASE_URL||h==="Ollama"||h==="CrofAI"||h==="InferX"||h==="SenseNova"||h==="AIHubMix"||h==="Poolside"||h==="9router"||h==="ExpLabs"||h==="TokenHarbor"||h==="Infron"||h==="APInex"||h==="xKiro")&&(Nt(K=>({...K,memory:!1})),u.systemSettings={...ce,memory:!1}),I(K=>(P(K.length+1),[...K,{id:Date.now(),role:"system",text:`\u2726 ${h} API Key saved successfully! ${U?`
310
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model: ${U}`:""}${h==="Ollama"&&a==="LOCAL"?`
311
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Ollama Endpoint automatically switched to Local`:""}${h==="Ollama"||h==="CrofAI"||h==="InferX"||h==="SenseNova"||h==="AIHubMix"||h==="Poolside"||h==="9router"||h==="ExpLabs"||h==="TokenHarbor"||h==="Infron"||h==="APInex"||h==="xKiro"?`
312
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available with ${h}`:""}${h==="NVIDIA"&&process.env.NVIDIA_BASE_URL?`
313
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available`:""}${M}
314
- \u2800\u2800`,isMeta:!0}]))}if(f){let a=f(o==="quotas"||o==="providerBudgets"?v:n);io(a)}else x?(Kt({...u,apiTier:tt,quotas:v,imageSettings:u.imageSettings||Ho}),io(null),x(v)):(Kt({...u,apiTier:tt,quotas:v,imageSettings:u.imageSettings||Ho}),io(null),re(Do?.returnView||"settings"))}})),e.createElement(m,{paddingX:1,marginTop:1},e.createElement(l,{color:s.textMuted,dimColor:!0,italic:!0},"(Press Enter to confirm selection)")));case"stats":{let n=Hn==="modelBreakdown"||Hn==="dailyModelBreakdown",o=Hn==="daily"||Hn==="dailyModelBreakdown",c=o?_n:rr,f=o?"TODAY's USAGE":"LAST 30 DAYS USAGE",x=o?"TODAY'S MODEL TOKEN BREAKDOWN":"30-DAY MODEL TOKEN BREAKDOWN",v="Wall Time:",u="Tokens Used:",a="Images Made:",h="Image Credits:",M="Code Changes:",O="Tool Calls:",U=Math.max(4,(r?.rows||H?.rows||24)-15),K=(ze,Ve,it,de,he,Qe=0,Je=!1)=>{let G=r?.columns||H?.columns||80,Ce=Math.min(125,G-2),we=Math.max(20,Ce-6),De=Math.max(5,we-Qe-it.length-5),ot=Ve;ot.length>De&&(ot=ot.substring(0,De-1)+"\u2026");let Ae=Math.max(2,we-Qe-ot.length-it.length-2),nt=" "+".".repeat(Ae)+" ",ht=" ".repeat(Qe);return e.createElement(m,{key:ze,width:we},e.createElement(l,{wrap:"truncate"},e.createElement(l,null,ht),e.createElement(l,{color:de,bold:Je},ot),e.createElement(l,{color:s.textMuted,dimColor:!0},nt),e.createElement(l,{color:he,bold:Je},it)))},z=ze=>{let Ve=Number(ze)||0;return Ve<=0?"":Ve<.001?" [<$0.001]":` [$${Ve.toFixed(Ve<.01?4:3)}]`},V=ze=>{let Ve=Number(ze)||0;return Ve<=0?"":Ve<.001?"<$0.001":`$${Ve.toFixed(Ve<.01?4:3)}`},te=[],oe=c?.models;if(!oe||Object.keys(oe).length===0)te.push(e.createElement(m,{key:"empty",marginTop:1},e.createElement(l,{color:s.textMuted,italic:!0},"No model token usage recorded for ",o?"today":"the last 30 days",".")));else{let ze=(ir||"").trim(),Ve="",it="";if(ze.includes(":")){let he=ze.indexOf(":");Ve=ze.substring(0,he).trim().toLowerCase(),it=ze.substring(he+1).trim().toLowerCase()}else Ve=ze.toLowerCase();let de=Object.entries(oe).sort(([he],[Qe])=>he.localeCompare(Qe,void 0,{sensitivity:"base"})).filter(([he,Qe])=>Ve&&!he.toLowerCase().includes(Ve)?!1:it?Object.keys(Qe).some(Je=>Je.toLowerCase().includes(it)):!0);de.length===0?te.push(e.createElement(m,{key:"no-matches",marginTop:1},e.createElement(l,{color:s.textMuted,italic:!0},'No results found matching "',ir,'".'))):de.forEach(([he,Qe],Je)=>{let G=Object.entries(Qe).sort(([Ae],[nt])=>Ae.localeCompare(nt,void 0,{sensitivity:"base"})).filter(([Ae])=>!it||Ae.toLowerCase().includes(it));if(G.length===0)return;let Ce=G.reduce((Ae,[,nt])=>Ae+(nt.tokens||0),0),we=G.reduce((Ae,[nt,ht])=>{if((ht.cost||0)>0)return Ae+ht.cost;let R=hr(he,nt);if(!R)return Ae;let ge=(ht.tokens||0)-(ht.candidateTokens||0),Ee=ht.cachedTokens||0,Ge=Math.max(0,ge-Ee),Oe=ht.candidateTokens||0,kt=Ge/1e6*R.IN+Ee/1e6*R.CR+Oe/1e6*R.OUT;return Ae+kt},0),De=c?.providerRequests&&c.providerRequests[he]||0;Je>0&&te.length>0&&te.push(e.createElement(m,{key:`space-prov-${he}`},e.createElement(l,null," ")));let ot=z(we);te.push(K(`prov-${he}`,`${he}:`,`${Lt(Ce)} (${De})${ot}`,s.primary,s.text,0,!0)),G.forEach(([Ae,nt],ht)=>{ht>0&&te.push(e.createElement(m,{key:`space-mod-${he}-${Ae}`},e.createElement(l,null," ")));let R=hr(he,Ae),ge=(nt.tokens||0)-(nt.candidateTokens||0),Ee=nt.cachedTokens||0,Ge=Math.max(0,ge-Ee),Oe=nt.candidateTokens||0,kt=0,Co=0,jt=0;R&&(kt=Ge/1e6*R.IN,Co=Ee/1e6*R.CR,jt=Oe/1e6*R.OUT);let Mo=(nt.cost||0)>0?nt.cost:kt+Co+jt,fr=z(Mo);te.push(K(`mod-${he}-${Ae}`,`\xBB ${Ae}:`,`${Lt(nt.tokens||0)}${fr}`,s.secondary,s.text,2,!0));let js=z(kt),jr=z(Co),yn=z(jt);te.push(K(`in-${he}-${Ae}`,"\xBB Input Tokens:",`${Lt(ge)}${js}`,s.textMuted,s.text,5,!1)),Ee>0&&te.push(K(`cache-${he}-${Ae}`,"\xBB Cached:",`${Lt(Ee)}${jr}`,s.textMuted,s.text,7,!1)),te.push(K(`out-${he}-${Ae}`,"\xBB Output Tokens:",`${Lt(Oe)}${yn}`,s.textMuted,s.text,5,!1))})})}let $=te.length,Re=Math.max(0,$-U);Z.current=Re;let Ue=Math.min(fc,Re),We=te.slice(Ue,Ue+U);return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:3,paddingY:1,paddingBottom:0,width:Math.min(125,(r?.columns||100)-2)},n?e.createElement(m,{flexDirection:"column"},e.createElement(m,{justifyContent:"space-between"},e.createElement(l,{color:s.text,bold:!0,underline:!0},x),$>U&&e.createElement(l,{color:s.textMuted,dimColor:!0},"[",Ue+1,"-",Math.min($,Ue+U)," of ",$,"] \u25B2\u25BC")),e.createElement(m,{marginTop:1},e.createElement(l,{color:s.secondary,bold:!0},"Filter (provider:model): "),e.createElement(l,{color:s.text},ir),e.createElement(l,{color:s.primary,bold:!0},"\u258A"),ir.length>0&&e.createElement(l,{color:s.textMuted,dimColor:!0,italic:!0}," (Type to search, Esc/Backspace to clear)")),e.createElement(m,{flexDirection:"column",height:U,marginTop:1},We)):e.createElement(e.Fragment,null,e.createElement(m,{marginBottom:1},e.createElement(l,{color:s.text,bold:!0,underline:!0},"SESSION TELEMETRY")),e.createElement(m,{flexDirection:"column"},e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Session Duration:")),e.createElement(l,{color:s.text},bn(Date.now()-Si))),Ai>0&&e.createElement(e.Fragment,null,e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Model Requests:")),e.createElement(l,{color:s.text},Ai)),e.createElement(m,{marginLeft:2},e.createElement(m,{width:23},e.createElement(l,{color:s.textMuted},"\xBB API Time:")),e.createElement(l,{color:s.text},bn(Ur))),e.createElement(m,{marginLeft:2},e.createElement(m,{width:23},e.createElement(l,{color:s.textMuted},"\xBB Tool Time:")),e.createElement(l,{color:s.text},bn(_r)))),Pi>0&&e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Memory Agent:")),e.createElement(l,{color:s.text},Pi)),lo>0&&e.createElement(e.Fragment,null,e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Tokens Consumed:")),e.createElement(l,{color:s.text},Lt(lo))),(Et?.cost||0)>0&&e.createElement(m,{marginLeft:2},e.createElement(m,{width:23},e.createElement(l,{color:s.textMuted},"\xBB Cost Estimate:")),e.createElement(l,{color:s.success||"green"},V(Et.cost))),e.createElement(m,{marginLeft:2},e.createElement(m,{width:23},e.createElement(l,{color:s.textMuted},"\xBB Input Tokens:")),e.createElement(l,{color:s.text},Lt(lo-Un))),wo>0&&e.createElement(m,{marginLeft:4},e.createElement(m,{width:21},e.createElement(l,{color:s.textMuted},"\xBB Cached:")),e.createElement(l,{color:s.text},Lt(wo))),Un>0&&e.createElement(m,{marginLeft:2},e.createElement(m,{width:23},e.createElement(l,{color:s.textMuted},"\xBB Output Tokens:")),e.createElement(l,{color:s.text},Lt(Un)))),Io?.tokens>0&&e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Active Context:")),e.createElement(l,{color:s.text},Lt(Io.tokens)," ",(()=>{let Ve={"16k":16e3,"32k":32e3,"64k":64e3,"128k":128e3,"256k":256e3,"512k":512e3,"1M":1e6}[ce?.contextLength]||256e3,it=process.env.HIGH_CONTEXT,de=process.env.GOOGLE_GEMMA_NONSENSE==="true"||process.env.GOOGLE_GEMMA_NONSENSE===!0||!1;if(it&&it!=="false"){let Je=parseInt(it,10);!isNaN(Je)&&Je>=0&&Je<=1e6&&(Ve=Je)}(N==="NVIDIA"&&(je?.includes("gpt")||je?.includes("qwen")||je?.includes("medium")||je.includes("muse"))||N==="Mistral")&&(Ve=126e3),N==="Google"&&je?.includes("gemma")&&de&&(Ve=16e3);let he=Io.tokens/Ve*100,Qe=he<60?s.text:he<80?s.warning:s.danger;return e.createElement(l,{color:Qe,dimColor:!0},"(",he.toFixed(0),"%)")})())),Hr>0&&e.createElement(e.Fragment,null,e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Images Made:")),e.createElement(l,{color:s.text},Hr)),e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Image Credits:")),e.createElement(l,{color:s.text},Number(((Ui||0)*1e3).toFixed(0))," credits"))),e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Code Changes (Sess):")),e.createElement(l,{color:s.text},e.createElement(l,{color:s.success||"green"},"+",Et.linesAdded)," ",e.createElement(l,{color:s.danger||"red"},"-",Et.linesRemoved))),e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Tool Calls (Sess):")),e.createElement(l,{color:s.text},Et.toolSuccess+Et.toolFailure+Et.toolDenied," ( "),e.createElement(l,{color:s.success||"green"},"\u2714 ",Et.toolSuccess),e.createElement(l,{color:s.text}," "),e.createElement(l,{color:s.warning||"yellow"},"\u{1F6C7} ",Et.toolDenied),e.createElement(l,{color:s.text}," "),e.createElement(l,{color:s.danger||"red"},"\u2718 ",Et.toolFailure),e.createElement(l,{color:s.text}," )"))),e.createElement(m,{flexDirection:"column",marginTop:1},e.createElement(l,{color:s.text,bold:!0,underline:!0},f),e.createElement(m,{marginTop:1},e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},v)),e.createElement(l,{color:s.text},zi(c?.duration||0))),(c?.agent||0)>0&&e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Model Requests:")),e.createElement(l,{color:s.text},c?.agent||0)),(c?.background||0)>0&&e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},"Memory Agent:")),e.createElement(l,{color:s.text},c?.background||0)),(c?.tokens||0)>0&&e.createElement(e.Fragment,null,e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},u)),e.createElement(l,{color:s.text},Lt(c?.tokens||0))),(c?.cost||0)>0&&e.createElement(m,{marginLeft:2},e.createElement(m,{width:23},e.createElement(l,{color:s.textMuted},"\xBB Cost Estimate:")),e.createElement(l,{color:s.success||"green"},V(c.cost))),e.createElement(m,{marginLeft:2},e.createElement(m,{width:23},e.createElement(l,{color:s.textMuted},"\xBB Input Tokens:")),e.createElement(l,{color:s.text},Lt((c?.tokens||0)-(c?.candidateTokens||0)))),(c?.cachedTokens||0)>0&&e.createElement(m,{marginLeft:4},e.createElement(m,{width:21},e.createElement(l,{color:s.textMuted},"\xBB Cached:")),e.createElement(l,{color:s.text},Lt(c.cachedTokens))),(c?.candidateTokens||0)>0&&e.createElement(m,{marginLeft:2},e.createElement(m,{width:23},e.createElement(l,{color:s.textMuted},"\xBB Output Tokens:")),e.createElement(l,{color:s.text},Lt(c.candidateTokens)))),(c?.imageCalls?.length||0)>0&&e.createElement(e.Fragment,null,e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},a)),e.createElement(l,{color:s.text},c.imageCalls.length)),e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},h)),e.createElement(l,{color:s.text},Number(((c.imageCalls.reduce((ze,Ve)=>ze+Ve.cost,0)||0)*1e3).toFixed(0))," credits"))),e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},M)),e.createElement(l,{color:s.text},e.createElement(l,{color:s.success||"green"},"+",c?.linesAdded||0)," ",e.createElement(l,{color:s.danger||"red"},"-",c?.linesRemoved||0))),e.createElement(m,null,e.createElement(m,{width:25},e.createElement(l,{color:s.secondary},O)),e.createElement(l,{color:s.text},(c?.toolSuccess||0)+(c?.toolFailure||0)+(c?.toolDenied||0)," ( "),e.createElement(l,{color:s.success||"green"},"\u2714 ",c?.toolSuccess||0),e.createElement(l,{color:s.text}," "),e.createElement(l,{color:s.warning||"yellow"},"\u{1F6C7} ",c?.toolDenied||0),e.createElement(l,{color:s.text}," "),e.createElement(l,{color:s.danger||"red"},"\u2718 ",c?.toolFailure||0),e.createElement(l,{color:s.text}," )")))),e.createElement(l,{color:s.textMuted,dimColor:!0,italic:!0},`
315
- `,"(Press TAB to toggle Today/30-Day views, SPACE to toggle Model Breakdown, ESC to return)"))}case"dynamicDirDanger":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(l,{color:s.warning||"yellow",bold:!0,underline:!0},"DYNAMIC DIRECTORY AWARENESS"),e.createElement(l,{marginTop:1,color:s.text},"Enabling this keeps the agent aware of filesystem state in real time, but may reduce prompt cache efficiency."),e.createElement(l,{color:s.text},`
316
- `,"RECOMMENDED SCENARIOS TO TURN ON:"),e.createElement(l,{color:s.textMuted},"\u2022 Repo is small."),e.createElement(l,{color:s.textMuted},"\u2022 The task benefits from real-time filesystem awareness."),e.createElement(l,{color:s.textMuted},"\u2022 Files are often created, renamed, or deleted."),e.createElement(l,{color:s.textMuted},"\u2022 You know exactly what you're signing up for."),e.createElement(l,{color:s.textMuted},"\u2022 You don't have conflicting decisions regarding token bills."),e.createElement(l,{color:s.textMuted},"\u2022 You want to see your wallet crying at 3am."),e.createElement(m,{marginTop:1},e.createElement(Ut,{title:"Confirm Intent",theme:ce.theme,items:[{label:"Turn On Dynamic Directory Awareness",value:"on"},{label:"Keep Off (Recommended)",value:"off"}],onSelect:n=>{n.value==="on"&&Nt(o=>{let c={...o,dynamicDirAwareness:!0};return Kt({systemSettings:c,apiTier:tt,quotas:Ie}),c}),re("settings")}})));case"dynamicDirHelp":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(l,{color:s.text,bold:!0,underline:!0},"DYNAMIC DIRECTORY AWARENESS \u2014 HELP & EXPLANATION"),e.createElement(l,{color:s.text,bold:!0},`
317
- `,"OFF (Default):"),e.createElement(l,{color:s.textMuted},"\u2022 Takes a static directory snapshot at conversation/session start and places it in System Context."),e.createElement(l,{color:s.textMuted},"\u2022 Prompt cache remains stable across user turns, saving tokens and money."),e.createElement(l,{color:s.text,bold:!0},`
318
- `,"ON:"),e.createElement(l,{color:s.textMuted},"\u2022 Rescans and updates the directory's state dynamically on every single user turn."),e.createElement(l,{color:s.textMuted},"\u2022 Provides real-time filesystem awareness if files are continuously created, renamed, or removed."),e.createElement(l,{color:s.textMuted},"\u2022 Changes Prompt Context on each turn, invalidating part of prompt caches and increasing token usage."),e.createElement(m,{marginTop:1},e.createElement(Ut,{title:"Actions",theme:ce.theme,items:[{label:"Back to Settings",value:"back"}],onSelect:()=>re("settings")})));case"autoExecDanger":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(l,{color:s.warning||"yellow",bold:!0,underline:!0},"SECURITY WARNING: YOLO MODE"),e.createElement(l,{marginTop:1,color:s.text},"Turning this ON allows the agent to execute terminal commands automatically without requiring your approval for each step."),e.createElement(l,{marginTop:1,color:s.text,bold:!0},"RISKS INVOLVED:"),e.createElement(l,{color:s.textMuted},"\u2022 The agent may execute destructive commands (rm -rf, etc.) by mistake unless specified in sandbox rules."),e.createElement(l,{color:s.textMuted},"\u2022 Unintended system changes if the agent hallucinates a path or command."),e.createElement(l,{color:s.textMuted},"\u2022 Reduced control over the agent's step-by-step decision making."),e.createElement(m,{marginTop:1},e.createElement(Ut,{title:"Confirm Intent",theme:ce.theme,items:[{label:"I know the risk and turning on intentionally",value:"on"},{label:"Keep Off (Recommended)",value:"off"}],onSelect:n=>{n.value==="on"&&Nt(o=>({...o,autoExec:!0})),re("settings")}})));case"advanceRollbackDanger":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:2,paddingY:1,paddingTop:0,width:"100%"},e.createElement(l,{color:s.warning||"yellow",bold:!0},"\u26A0 Emergency Rollback Notice"),e.createElement(l,{marginTop:1,color:s.text},"When enabled, full repo snapshots exist only during active AI turns."),e.createElement(l,{marginTop:1,color:s.text},"If catastrophic changes occur during a turn, avoid abruptly stopping the agent unless absolutely necessary (external damages out of codebase)."),e.createElement(l,{color:s.textMuted},"The agent may be able to automatically restore the repo to a safe state."),e.createElement(l,{marginTop:1,color:s.textMuted},"Once the turn ends, emergency snapshots are deleted and standard /revert takes over which may not retain full repo content."),e.createElement(l,{marginTop:1,color:s.textMuted},"(Requires Restart to take effect)"),e.createElement(m,{marginTop:1},e.createElement(Ut,{title:"Confirm",theme:ce.theme,items:[{label:"I understand and wish to enable",value:"on"},{label:"Keep Off",value:"off"}],onSelect:n=>{n.value==="on"&&Nt(o=>({...o,advanceRollback:!0})),re("settings")}})));case"externalDanger":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(l,{color:s.warning||"yellow",bold:!0,underline:!0},"SECURITY WARNING: EXTERNAL WORKSPACE ACCESS"),e.createElement(l,{marginTop:1,color:s.text},"Turning this ON allows the agent to execute tools (Read/Write/Exec) outside of the current active workspace directory."),e.createElement(l,{marginTop:1,color:s.text,bold:!0},"RISKS INVOLVED:"),e.createElement(l,{color:s.textMuted},"\u2022 Access to sensitive system files (SSH keys, Browser data, etc.)"),e.createElement(l,{color:s.textMuted},"\u2022 Potential for accidental or malicious deletion of OS-critical files."),e.createElement(l,{color:s.textMuted},"\u2022 Unauthorized script execution across your entire file system."),e.createElement(m,{marginTop:1},e.createElement(Ut,{title:"Confirm Intent",theme:ce.theme,items:[{label:"I know the risk and turning on intentionally",value:"on"},{label:"Keep Off (Recommended)",value:"off"}],onSelect:n=>{n.value==="on"&&Nt(o=>({...o,allowExternalAccess:!0})),re("settings")}})));case"doubleDanger":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(l,{color:s.danger||"red",bold:!0,underline:!0},"CRITICAL SECURITY WARNING: COMBINED SYSTEM RISK"),e.createElement(l,{marginTop:1,color:s.text},"You are attempting to enable BOTH [YOLO Mode] and [External Workspace Access] simultaneously."),e.createElement(l,{marginTop:1,color:s.danger||"red",bold:!0},"THIS IS NOT RECOMMENDED."),e.createElement(l,{marginTop:1,color:s.text,bold:!0},"THE CRITICAL RISK:"),e.createElement(l,{color:s.textMuted},"The agent will have the power to execute any command across your entire system WITHOUT your approval or supervision."),e.createElement(l,{color:s.danger||"red",italic:!0,marginTop:1},"A single hallucination or error could result in full system wipe or data theft."),e.createElement(m,{marginTop:1},e.createElement(Ut,{title:"Final Confirmation",theme:ce.theme,items:[{label:"I agree knowing the consequences",value:"on"},{label:"Keep Off",value:"off"}],onSelect:n=>{n.value==="on"&&Nt(o=>({...o,autoExec:!0,allowExternalAccess:!0})),re("settings")}})));case"key":case"deleteKey":return null;case"exit":return null;case"ask":return e.createElement(m,{width:"100%"},e.createElement(Da,{question:pn?.question,options:pn?.options,onResolve:n=>{pn?.resolve&&pn.resolve(n),_s(null),re("chat")},theme:ce.theme}));case"revert":return e.createElement(m,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(yi,{prompts:Cc,onSelect:async n=>{r&&(r.write("\x1B[2J\x1B[3J\x1B[H"),r.isTTY&&r.write("\x1B[?2004h"));try{let o=await wr.rollbackToBefore(n);if(o.success){let{targetPrompt:c}=o;ua(bt),Ys(a=>a+1),Go(),ao.current={completedIndex:0,columns:H.columns,historicalBlocks:[],seenSelections:new Set,chatId:bt,clearKey:Tn+1};let f=Ft.findLastIndex(a=>a.role==="user"&&a.text&&(a.text.startsWith(c)||a.text.includes(c))),x=[...Ft];f!==-1&&(x=Ft.slice(0,f)),I(x),P(x.length),b(c),Y(c.split(`
319
- `).length>2);let v=x.filter(a=>!String(a.id).startsWith("welcome")&&(!a.isMeta||a.text&&a.text.includes("Request Cancelled")));await En(bt,null,v);let u=yt(2);I(a=>{let h=[...a,{id:"revert-ok-"+Date.now(),role:"system",text:`\u2726 Rollback Successful
320
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Reverted prompt loaded to input box.
321
- \u2800`,isMeta:!0}];return P(h.length),h}),re("chat")}}catch(o){let c=yt(2);I(f=>{let x=[...f,{id:"revert-err-"+Date.now(),role:"system",text:`\u2726 ERROR
322
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${o.message}
323
- \u2800`,isMeta:!0}];return P(x.length),x}),re("chat")}},onClose:()=>re("chat"),theme:ce.theme}));case"resume":return e.createElement(m,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(pi,{onSelect:async n=>{let o=await Ko();if(o[n]){if(r.write("\x1B[2J\x1B[3J\x1B[H"),process.stdout.isTTY){let v=o[n]?.name||"",u=v&&!v.startsWith("flow-")&&!v.startsWith("Session ")?v:"FluxFlow | Resumed";process.stdout.write(`\x1B]0;${u}\x07`),process.stdout.write(`\x1B]633;P;TerminalTitle=${u}\x07`)}Go(),Wo.current=!0,Xr(n);let c=await yr(n);Pn.current=lo-c.total,Nn.current=wo,$n.current=hn,zt.current=[],Ln(c.total),On(0),gn(0),Fn(0),Zo({tokens:c.context}),Wo.current=!1;let f=[...o[n].messages];f[0]?.text?.includes("\u2591\u2591\u2591\u2588\u2588\u2588")||f.unshift({id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}),I(f),re("chat"),I(v=>{let u=[...v,{id:"sys-"+Date.now(),role:"system",text:`\u2726 SESSION RESUMED
324
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${n}
325
- \u2800`,isMeta:!0}];return P(u.length),u})}},onDelete:async n=>await os(n),onClose:()=>re("chat"),theme:ce.theme}));case"keybindingsPrompt":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:"grey",paddingX:2,paddingY:1,width:"100%"},e.createElement(l,{color:"white",bold:!0,underline:!0},"CONFIGURE SHIFT+ENTER NEWLINE"),e.createElement(l,null,`
326
- `,"To support multi-line inputs with ",e.createElement(l,{bold:!0,color:"white"},"Shift + Enter")," for newline, a terminal sequence keybinding needs to be added to your IDE configuration.",`
327
-
328
- `,"Would you like FluxFlow to automatically add this to your ",cn()," keybindings?"),e.createElement(m,{marginTop:1},e.createElement(Ut,{title:"Add Keybinding?",items:[{label:"Yes, configure automatically",value:"yes"},{label:"No, skip",value:"no"}],onSelect:async n=>{n.value==="yes"?await Cs(cn()):Ts="\\ + Enter",re("chat")},theme:ce.theme})));case"memory":return e.createElement(m,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(wi,{onClose:()=>re("chat"),theme:ce.theme}));case"parserDownload":return e.createElement(m,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(Ti,{onClose:()=>re("settings")}));case"resolution":return e.createElement(m,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(pu,{data:Mc,theme:ce.theme,onResolve:n=>{Vs(null),re("chat"),setTimeout(()=>{dl(n,!0)},500)},onEdit:n=>{Vs(null),re("chat"),b(n)}}));case"approval":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:"white",paddingX:2,paddingY:1,width:"100%"},e.createElement(l,{color:"white",bold:!0,underline:!0},to?.tool==="view_file"?"FILE READ PERMISSION":"FILE WRITE PERMISSION"),e.createElement(l,{marginTop:1},"The agent is attempting to ",to?.tool==="view_file"?"read":"modify",": ",e.createElement(l,{color:"cyan"},vn(to?.args||"{}").path||"Unknown File")),to?.tool==="view_file"?null:Bn()?e.createElement(m,{marginTop:1,paddingX:1},e.createElement(l,{color:"cyan",italic:!0},"FluxFlow Companion is active. Review the changes in your editor.")):e.createElement(m,{marginTop:1,borderStyle:"single",borderColor:"#333",paddingX:1,flexDirection:"column"},e.createElement(l,{color:"gray"},"--- PROPOSED CONTENT ---"),(()=>{let n=vn(to?.args||"{}"),o=[],c=new Set;if(Object.keys(n).forEach(v=>{let u=v.match(/^(searchContent|replaceContent|newContent|content_to_replace|content_to_add|TargetContent|ReplacementContent|replacementContent)(\d+)?$/);if(u){let a=u[2]?parseInt(u[2]):1;c.add(a)}}),Array.from(c).sort((v,u)=>v-u).forEach(v=>{let u,a;v===1?(u=n.searchContent1??n.searchContent??n.replaceContent1??n.content_to_replace1??n.replaceContent??n.content_to_replace??n.TargetContent??null,a=n.newContent1??n.content_to_add1??n.newContent??n.content_to_add??n.ReplacementContent??n.replacementContent??null):(u=n[`searchContent${v}`]??n[`replaceContent${v}`]??n[`content_to_replace${v}`]??null,a=n[`newContent${v}`]??n[`content_to_add${v}`]??null),(u!==null||a!==null)&&o.push({replace:u,new:a})}),o.length>0)return e.createElement(m,{flexDirection:"column",marginTop:1},o.map((v,u)=>{let a=v.replace!==null,h=v.new!==null;return e.createElement(m,{key:u,flexDirection:"column",marginTop:u>0?1:0},o.length>1&&e.createElement(l,{color:"gray"},"Block ",u+1,":"),a&&e.createElement(m,null,e.createElement(l,{color:"red",wrap:"anywhere",bold:!0},"- ",v.replace)),h&&e.createElement(m,{marginTop:0},e.createElement(l,{color:"green",wrap:"anywhere",bold:!0},"+ ",v.new.replace(/\[\/n\]?/g,"\\n"))))}));let x=n.content||n.ReplacementContent||n.content_to_add||n.replacementContent||n.newContent||null;return e.createElement(l,{color:"white",wrap:"anywhere"},(x?x.replace(/\[\/n\]?/g,"\\n"):null)||"Updating file content...")})()),e.createElement(m,{marginTop:1},(()=>{let n=to?.tool,o=vn(to?.args||"{}"),c=o.path||o.targetPath||o.file||"",f=c?Ct.extname(c).toLowerCase():"",x=c?Ct.basename(c):"this file",v="Accept for this session";return n==="write_file"&&f?v=`Accept for this session (*${f})`:n==="update_file"&&x&&(v=`Accept for this session (${x})`),e.createElement(Ut,{title:"Action Required",items:[{label:"Accept this time",value:"allow"},...n==="view_file"?[]:[{label:v,value:"always"}],{label:"Don't accept",value:"deny"}],onSelect:u=>{u.value==="always"&&(n==="write_file"?f?Yi.current.add(f):Us(!0):n==="update_file"&&c?ji.current.add(Ct.resolve(c).toLowerCase()):Us(!0));let a=u.value==="deny"?"deny":"allow";to.resolve(a),Kn(null),re("chat")},theme:ce.theme})})()));case"mode":return e.createElement(Ut,{title:"SELECT EXECUTION MODE",items:[{label:`Flux (Dev Toolset Mode) ${j==="Flux"?"\u25CF":""}`,value:"Flux"},{label:`Flow (Chat / Conversation Mode) ${j==="Flow"?"\u25CF":""}`,value:"Flow"},{label:`ICU (Interactive Computer Use) ${j==="ICU"?"\u25CF":""}`,value:"ICU"},{label:`FluxCU (Autonomous Flux Computer Use) ${j==="FluxCU"?"\u25CF":""}`,value:"FluxCU"},{label:"Back",value:"chat"}],theme:ce.theme,onSelect:n=>{if(n.value==="chat"||n.value==="Back"){re("chat");return}let o=n.value;le(o),I(c=>(P(c.length+1),[...c,{id:Date.now(),role:"system",text:`\u2726 Mode switched to ${Mi(o)}
329
- \u2800`,isMeta:!0}])),re("chat")},onClose:()=>re("chat")});case"display":return e.createElement(Ut,{title:"SELECT ACTIVE DISPLAY FOR COMPUTER USE",items:[{label:`Primary Display (Display 1) ${ue===0?"\u25CF":""}`,value:0},{label:`Secondary Display (Display 2) ${ue===1?"\u25CF":""}`,value:1},{label:"Back",value:"chat"}],theme:ce.theme,onSelect:n=>{if(n.value==="chat"||n.value==="Back"){re("chat");return}let o=Number(n.value);ne(o),Kt({display:o}).catch(()=>{});let c=o===0?"Primary (Display 1)":"Secondary (Display 2)";I(f=>(P(f.length+1),[...f,{id:Date.now(),role:"system",text:`\u2726 Active Computer Use display set to: ${c}`,isMeta:!0}])),re("chat")},onClose:()=>re("chat")});case"updateManager":return e.createElement(Ut,{title:"Select Preferred Update Manager",subtitle:"NOTE: If you are unsure about these, go with NPM",items:[{label:"NPM (Standard)",value:"npm"},{label:"PNPM (Recommended)",value:"pnpm"},{label:"BUN (Ultra Fast)",value:"bun"},{label:"YARN (Classic)",value:"yarn"},{label:"Custom Command",value:"custom"},{label:"Back",value:"settings"}],onSelect:n=>{if(n.value==="settings"||n.value==="Back"){re("settings");return}n.value==="custom"?(io({label:"Enter Custom Update Command (Global install recommended):",key:"customUpdateCommand",value:ce.customUpdateCommand,next:o=>(Nt(c=>({...c,updateManager:"custom",customUpdateCommand:o})),null)}),re("input")):(Nt(o=>({...o,updateManager:n.value})),re("settings"))},theme:ce.theme});case"update":return e.createElement($a,{latest:dn,current:po,settings:ce,theme:ce.theme,onClose:()=>re("chat"),onSuccess:()=>{I(n=>(P(n.length+1),[...n,{id:"update-success-"+Date.now(),role:"system",text:`**[UPDATE COMPLETED]** Flux Flow successfully updated to v${dn}.
330
- **Restart to see changes.**`,isMeta:!0}])),re("chat")},onUpdateSettings:n=>{re("updateManager")}});case"terminalApproval":return e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:"white",paddingX:2,paddingY:1,width:"100%"},e.createElement(l,{color:"white",bold:!0,underline:!0},"TERMINAL COMMAND OVERSIGHT"),e.createElement(m,{marginTop:1},e.createElement(l,null,"Agent requested to run: ",e.createElement(l,{color:"yellow",bold:!0},vn(to?.args||"{}").command||"Unknown Command"))),e.createElement(m,{marginTop:1},(()=>{let o=(vn(to?.args||"{}").command||"").trim();return e.createElement(Ut,{title:"Risk Assessment Required",items:[{label:"Run",value:"allow"},{label:"Accept for this session",value:"always"},{label:"Deny",value:"deny"}],onSelect:c=>{c.value==="always"&&o&&qi.current.add(o);let f=c.value==="deny"?"deny":"allow";to.resolve(f),Kn(null),re("chat")},theme:ce.theme})})()));default:return e.createElement(m,{flexDirection:"column",marginTop:1,flexShrink:0,width:"100%"},nl&&ol&&e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:2,paddingY:1,width:"100%",marginBottom:1},e.createElement(m,{justifyContent:"space-between",width:"100%"},e.createElement(l,{color:s.text,bold:!0,underline:!0},"INQUIRY RESPONSE"),e.createElement(l,{color:s.textMuted},"[ ESC to Close ]")),e.createElement(m,{marginTop:1,width:"100%"},e.createElement(is,{text:ol,columns:H.columns-6,theme:ce.theme}))),As.filter(n=>n.status==="running").length>0&&e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:2,paddingY:0,width:"100%",marginBottom:1},e.createElement(m,{justifyContent:"space-between",width:"100%"},e.createElement(l,{color:s.text,bold:!0},"ACTIVE SUBAGENTS")),e.createElement(m,{flexDirection:"column",marginTop:1,width:"100%"},As.filter(n=>n.status==="running").map(n=>e.createElement(Tu,{key:n.id,sa:n,showTPMEstimate:ce.showTPMEstimate})))),xr&&e.createElement(m,{flexDirection:"column",borderStyle:"round",borderColor:s.borderMuted,paddingX:2,paddingY:0,width:"100%",marginBottom:0},e.createElement(m,{justifyContent:"space-between",width:"100%"},e.createElement(m,{flexDirection:"row",gap:1},e.createElement(l,{color:s.warning||"yellow",bold:!0},"\u2726 ",xr.startsWith("/btw")?"Question Queued":"Steering Hint Queued"))),e.createElement(m,{marginTop:0,paddingLeft:2},e.createElement(l,{color:s.text,bold:!0},"\u2514\u2500 ",xr.startsWith("/btw")?xr.replace(/^\/btw\s*/,""):xr))),e.createElement(m,{paddingX:1,marginBottom:0,justifyContent:"space-between",width:"100%"},e.createElement(m,null,Ro?e.createElement(m,{gap:1},e.createElement(au,null),e.createElement(kr,{text:Ro.trim().length>40&&!Ro.toLowerCase().includes("trying")?`${Ro.trim().slice(0,40)}...`:Ro.trim(),baseColor:s.textExclusive||s.text,glintColor:s.textMutedExclusive||s.textMuted,speed:60,italic:!0,glintWidth:2,typeSpeed:10}),e.createElement(l,{color:s.textMuted},Ji>0?`(${Ji.toFixed(0)}s)`:"")):e.createElement(l,{color:s.textMuted,italic:!0},y.length>0&&el?"Press ESC again to clear input":pc?"Press CTRL + O to expand":process.env.HALLOWEEN_EEGG==="true"?"Listening for shadows...":"Waiting for input...")),e.createElement(m,null,(()=>{let n=Ro?.toLowerCase()??"";return Vn&&Date.now()-Ii>15e3&&As.length===0&&(n.includes("connecting")||n.includes("consulting")||n.includes("working")||n.includes("haunting")||n.includes("queue"))?e.createElement(m,null,e.createElement(kr,{text:"Waiting for API Response",baseColor:s.text,glintColor:s.textMuted,glintWidth:4,speed:100}),e.createElement(l,{color:s.textMuted,dimColor:!0}," \u2503 ")):Ws?e.createElement(m,null,e.createElement(kr,{text:Ws,baseColor:s.text,glintColor:s.textMuted,italic:!0,speed:85,typeSpeed:15}),e.createElement(l,{color:s.textMuted,dimColor:!0}," \u2503 ")):null})(),e.createElement(kr,{text:Ct.basename(je)||(je.length>1?je:"Use '/model model-id' to select model"),baseColor:s.text,glintColor:s.textMuted,glintWidth:3,speed:80}),e.createElement(l,{color:s.textMuted},je.length>0?Xe.toLocaleLowerCase().includes("xhigh")?"":` (${Xe})`:""),ts>0&&e.createElement(l,{color:s.textMuted}," [",ts," ",ts===1?"file":"files","]"))),e.createElement(m,{flexDirection:"column",width:"100%"},e.createElement(m,{width:"100%",height:1,overflow:"hidden"},e.createElement(l,{color:s.inputBorder},"\u2500".repeat(Math.max(1,H.columns)))),e.createElement(m,{paddingX:1,paddingY:0,width:"100%",flexDirection:"column"},e.createElement(m,{flexDirection:"column",width:"100%"},e.createElement(m,{flexDirection:"row",width:"100%",paddingY:0},e.createElement(m,{flexShrink:0,width:4},e.createElement(l,{color:s.inputPrompt,bold:!0},Vn||ur?"\u2726 ":" \u276F ")),e.createElement(m,{flexGrow:1},e.createElement(m,{flexGrow:1,position:"relative"},y===""&&e.createElement(m,{position:"absolute",paddingLeft:0},yo&&!ar?e.createElement(l,{color:"yellow"},Ec?" Terminal is waiting for user input. Press TAB to interact":" Press TAB to interact with terminal..."):yo&&ar?e.createElement(l,{color:"yellow",bold:!0}," [ TERMINAL FOCUSED ] Type to interact, press TAB to exit..."):el===1?e.createElement(l,{color:s.inputPrompt,bold:!0}," Press ESC again to ",y.length>0?"clear input":"revert codebase to checkpoint","..."):e.createElement(l,{color:s.inputPlaceholder},Tc?" Press ESC again to cancel the request.":ur?" Compacting session history, please wait...":Vn?" Enter a prompt to steer the agent.":Ft.filter(n=>n.role==="user").length===0?` Send message, @file or /cmd (${hc.shortcut} for newline)`:" Ask Follow-ups")),e.createElement(fa,{key:`input-${C}`,onPasteStateChange:bc,focus:!ar&&!ur,showCursor:dt&&!ur,cursorColor:s.inputText,lastFocusEventTime:so.current,value:y,textStyle:{bold:!0,color:s.inputText},columns:H.columns,onChange:n=>{let o=n.replace(/\r\n/g,`
331
- `).replace(/\r/g,`
332
- `).replace(/\\\s*\n/g,`
333
- `);b(o),Me(!1),X.current!==null&&o===X.current?X.current=null:B!==-1&&A(-1)},historyEnabled:St==="chat"&&!ur&&(lt.length===0||B!==-1),isBrowsingHistory:B!==-1,onHistoryPrev:()=>{let n=F.current;if(n.length!==0){if(B===-1){W.current=y;let o=n.length-1;X.current=n[o],A(o),b(n[o]),L(c=>c+1)}else if(B>0){let o=B-1;X.current=n[o],A(o),b(n[o]),L(c=>c+1)}}},onHistoryNext:()=>{let n=F.current;if(B!==-1)if(B<n.length-1){let o=B+1;X.current=n[o],A(o),b(n[o]),L(c=>c+1)}else{let o=W.current||"";X.current=o,A(-1),b(o),L(c=>c+1)}},onSubmit:dl,rows:1,maxRows:10,keyBindings:{submit:n=>n.return&&!n.shift&&!n.ctrl,newline:n=>n.return&&n.shift||n.return&&n.ctrl}})))))),e.createElement(m,{width:"100%",height:1,overflow:"hidden"},e.createElement(l,{color:s.inputBorder},"\u2500".repeat(Math.max(1,H.columns))))))}};return e.createElement(m,{flexDirection:"column",width:"100%"},Ne?null:Mt?e.createElement(fu,{width:r?.columns||80,height:r?.rows||24,aiProvider:N,theme:ce.theme,reason:Mt}):xe?e.createElement(xu,{width:r?.columns||80,height:r?.rows||24,selectedIndex:ke,aiProvider:N,theme:ce.theme}):e.createElement(e.Fragment,null,e.createElement(m,{paddingX:1,flexDirection:"column",width:"100%"},e.createElement(lu,{key:`static-${Tn}-${bt}-${H.columns}-${ce.theme}`,items:ll.completed},n=>e.createElement(as,{key:n.key,block:n,columns:(r?.columns||80)-2,showFullThinking:un,aiProvider:N,version:po,theme:ce.theme}))),e.createElement(m,{flexDirection:"column",paddingX:1,paddingBottom:0,width:"100%"},(St==="chat"||["ask","approval","terminalApproval"].includes(St))&&e.createElement(m,{flexDirection:"column",width:"100%"},ll.active.map(n=>e.createElement(as,{key:n.key,block:n,columns:Math.max(20,(r?.columns||80)-2),showFullThinking:un,aiProvider:N,version:po,theme:ce.theme})),yo&&e.createElement(m,{marginTop:1},e.createElement(ss,{command:yo,output:Xn,isFocused:ar,isPty:jn,terminalHeight:H.rows,columns:H.columns}))),Ne?e.createElement(m,{borderStyle:"double",borderColor:"grey",padding:1,flexShrink:0},e.createElement(l,{color:"white"},"Starting Flux Flow...")):!Ke&&!(N==="c_openai"&&ce.customOpenAIBaseUrl)?e.createElement(m,{borderStyle:"round",borderColor:"white",padding:0,flexDirection:"column",flexShrink:0,width:"100%"},e.createElement(m,{paddingX:1,marginBottom:1},e.createElement(l,{color:"gray",bold:!0},N==="c_openai"?"CUSTOM BASE URL REQUIRED":"API KEY REQUIRED")),e.createElement(m,{paddingX:1,flexDirection:"column"},er===0?e.createElement(e.Fragment,null,e.createElement(l,{color:"white"},"Select your Preferred Provider:"),e.createElement(m,{marginTop:1},e.createElement(Ut,{searchable:!0,items:[{label:"Google",value:"Google"},{label:"Nvidia",value:"NVIDIA"},{label:"DeepSeek",value:"DeepSeek"},{label:"InferX",value:"InferX"},{label:"SenseNova",value:"SenseNova"},{label:"Poolside",value:"Poolside"},{label:"Experiential Labs",value:"ExpLabs"},{label:"Token Harbor",value:"TokenHarbor"},{label:"Infron",value:"Infron"},{label:"APInex",value:"APInex"},{label:"xKiro",value:"xKiro"},{label:"Ollama",value:"Ollama"},...process.env.ENABLE_9ROUTER==="true"||process.env.ENABLE_9ROUTER===!0?[{label:"9router [Local Proxy]",value:"9router"}]:[],{label:"AIHubMix [Experimental]",value:"AIHubMix"},{label:"Mistral [Experimental]",value:"Mistral"},{label:"OpenRouter [Experimental]",value:"OpenRouter"},{label:"Custom [OpenAI Chat Completion]",value:"c_openai"}],onSelect:n=>{Qo(n.value),Ar(1)}}))):e.createElement(e.Fragment,null,e.createElement(l,{color:"white"},N==="Ollama"?"Enter Ollama API Key (or type LOCAL to use local host):":N==="c_openai"?"Enter Custom OpenAI Base URL (.../v1):":`Enter your ${N} API Key:`),e.createElement(m,{marginTop:1},e.createElement(l,{color:"gray",bold:!0}," ",">"," "),e.createElement(Zn,{value:mn,onChange:xn,onSubmit:al,mask:N==="c_openai"?void 0:"*"})))),e.createElement(m,{paddingX:1,marginTop:1},e.createElement(l,{color:"gray",italic:!0},er===0?"(Use arrows to select and Enter to confirm, ESC to go back)":"(Press Enter to confirm and initialize, ESC to go back)"))):Dc(),d&&e.createElement(m,{borderStyle:"round",borderColor:s.borderMuted,paddingX:1,marginY:0,width:"100%"},e.createElement(l,null,e.createElement(l,{color:"red",bold:!0},"\u{1F534} EXIT: "),e.createElement(l,{color:s.text},"Press "),e.createElement(l,{color:s.text,bold:!0},"CTRL+C"),e.createElement(l,{color:s.text}," again to exit (",w,"s) \u2022 Press "),e.createElement(l,{color:s.textMuted,bold:!0},"ESC"),e.createElement(l,{color:s.text}," to cancel"))),lt.length>0&&(()=>{let o=be.current,c=0;for(;c<lt.length;){let U=lt[c],K=U?.cmd||U||"";if(typeof K=="string"&&K.trimStart().startsWith("---"))c++;else break}Le<=c?o=0:Le<o?o=Le:Le>=o+5&&(o=Le-5+1),o=Math.max(0,Math.min(o,Math.max(0,lt.length-5))),be.current=o;let f=lt.slice(o,o+5),x=lt.length-(o+f.length),v=lt[0]?.cmd?.startsWith("@")||lt[0]?.cmd?.startsWith("\\@"),u=y.startsWith("/model"),a=y.startsWith("/kill"),h=y.startsWith("/thinking"),M=lt.length,O=Math.min(M,Le+1);return e.createElement(m,{flexDirection:"column",width:"100%",marginBottom:1,marginTop:0},e.createElement(m,{paddingX:1,marginBottom:0,justifyContent:"space-between",width:"100%"},e.createElement(m,{flexDirection:"row"},e.createElement(l,{color:s.primary||s.text,bold:!0},v?"WORKSPACE FILES":u?"SAVED MODELS":a?"ACTIVE PROCESSES":h?"THINKING LEVELS":"COMMANDS"),e.createElement(l,{color:s.textMuted}," (",M,")")),e.createElement(m,{flexDirection:"row"},v?e.createElement(l,{color:s.textMuted,italic:!0},"Use #Lstart-Lend for line range \u2022 Tab to select"):e.createElement(l,{color:s.textMuted,italic:!0},"\u2191/\u2193 navigate \u2022 Tab / Enter select \u2022 Esc dismiss"))),e.createElement(m,{width:"100%",height:1,overflow:"hidden"},e.createElement(l,{color:s.borderDim||s.inputBorder||s.textDim},"\u2500".repeat(Math.max(1,H.columns)))),f.slice(0,Vr).map((U,K)=>{let V=o+K===Le,te=typeof U.cmd=="string"&&U.cmd.trimStart().startsWith("---"),oe=U.cmd===co("Google","Free")&&tt!=="Free",$=U.display||(U.cmd&&(U.cmd.startsWith("@[")||U.cmd.startsWith("\\@["))&&U.cmd.endsWith("]")?(()=>{let Ue=(U.cmd.startsWith("\\@[")?U.cmd.slice(3,-1):U.cmd.slice(2,-1)).split(/[\/\\]/);return Ue[Ue.length-1]})():!u&&!a&&U.cmd&&U.cmd.includes("/")?U.cmd.split("/").pop():U.cmd);if(u){let Ue=U.multimodal===!0||Jr(U.cmd||U)?"Vision":"Text Only";return e.createElement(m,{key:U.cmd||K,flexDirection:"row",backgroundColor:V?s.highlightBg:void 0,paddingX:1,height:1,alignItems:"center",justifyContent:"space-between"},e.createElement(m,{flexDirection:"row",alignItems:"center",flexGrow:1,overflow:"hidden"},e.createElement(m,{width:3,flexShrink:0},e.createElement(l,{color:V?s.primary||s.text:s.textMuted,bold:V},V?"\u276F ":" ")),e.createElement(l,{color:te?s.textDim:oe?s.textMuted:V&&s.inputText||s.text,bold:V},$)),e.createElement(m,{flexShrink:0,marginLeft:2},e.createElement(l,{color:V?s.text:s.textMuted,italic:!V},Ue)))}return a&&U.rightDesc?e.createElement(m,{key:U.cmd||K,flexDirection:"row",backgroundColor:V?s.highlightBg:void 0,paddingX:1,height:1,alignItems:"center",justifyContent:"space-between"},e.createElement(m,{flexDirection:"row",alignItems:"center",flexGrow:1,overflow:"hidden"},e.createElement(m,{width:3,flexShrink:0},e.createElement(l,{color:V?s.primary||s.text:s.textMuted,bold:V},V?"\u276F ":" ")),e.createElement(l,{color:V&&s.inputText||s.text,bold:V},$)),e.createElement(m,{flexShrink:0,marginLeft:2},e.createElement(l,{color:V?s.text:s.textMuted,italic:!V},U.rightDesc))):e.createElement(m,{key:U.cmd||K,flexDirection:"row",backgroundColor:V?s.highlightBg:void 0,paddingX:1,height:1,alignItems:"center"},e.createElement(m,{width:3,flexShrink:0},e.createElement(l,{color:V?s.primary||s.text:s.textMuted,bold:V},V?"\u276F ":" ")),e.createElement(m,{width:26,flexShrink:0},e.createElement(l,{color:te?s.textDim:oe?s.textMuted:V&&s.inputText||s.text,bold:V},$)),e.createElement(m,{flexGrow:1,overflow:"hidden"},e.createElement(l,{color:V?s.text:s.textMuted,italic:!V},U.desc)))}),lt.length>5&&e.createElement(m,{paddingX:1,height:1,justifyContent:"space-between",width:"100%"},e.createElement(l,{color:s.textMuted,dimColor:!0,italic:!0},x>0?`... ${x} more available`:"(End of list)"),e.createElement(l,{color:s.textMuted,dimColor:!0},`${O}/${M}`)))})(),e.createElement(m,{flexShrink:0,width:"100%"},e.createElement(Sa,{mode:j,thinkingLevel:Xe,tokens:Io.tokens,tokensTotal:nc,cachedTokens:rc,promptTokens:ic,chatCacheTokenLatest:sc,cacheCalculateMode:ce.cacheCalculateMode||"Session",chatId:bt,isMemoryEnabled:ce.memory,apiTier:tt,aiProvider:N,activeModel:je,isProcessing:Vn,lastChunkTime:Ii,theme:ce.theme,wps:Ds.current.wps,showTPMEstimate:ce.showTPMEstimate})),St==="exit"&&(()=>{let n=Date.now()-Si,o=Et.toolSuccess+Et.toolFailure,c=o>0?(Et.toolSuccess/o*100).toFixed(1):"0.0",f=Ur+_r,x=f>0?(Ur/f*100).toFixed(1):"0.0",v=f>0?(_r/f*100).toFixed(1):"0.0";return e.createElement(m,{flexDirection:"column",borderStyle:"round",paddingX:3,paddingY:1,borderColor:s.borderMuted,width:Math.min(100,(r?.columns||100)-2),marginTop:0,marginBottom:0},e.createElement(m,{marginBottom:1},e.createElement(l,{bold:!0},du(s.logoGradient||["blue","purple"])("Agent powering down. Goodbye!"))),e.createElement(m,{flexDirection:"column"},e.createElement(l,{color:s.text,bold:!0,underline:!0},"Interaction Summary"),e.createElement(m,{marginTop:1},e.createElement(m,{width:20},e.createElement(l,{color:s.secondary},"Session ID:")),e.createElement(l,{color:s.text},bt)),e.createElement(m,null,e.createElement(m,{width:20},e.createElement(l,{color:s.secondary},"Tool Calls:")),e.createElement(l,{color:s.text},Et.toolSuccess+Et.toolFailure+Et.toolDenied," ( ",e.createElement(l,{color:"green"},"\u2714 ",Et.toolSuccess)," ",e.createElement(l,{color:"yellow"},"\u{1F6C7} ",Et.toolDenied)," ",e.createElement(l,{color:"red"},"\u2718 ",Et.toolFailure)," )")),e.createElement(m,null,e.createElement(m,{width:20},e.createElement(l,{color:s.secondary},"Success Rate:")),e.createElement(l,{color:s.text},c,"%")),e.createElement(m,null,e.createElement(m,{width:20},e.createElement(l,{color:s.secondary},"Code Changes:")),e.createElement(l,{color:s.text},e.createElement(l,{color:"green"},"+",Et.linesAdded)," ",e.createElement(l,{color:"red"},"-",Et.linesRemoved))),lo>0&&e.createElement(e.Fragment,null,e.createElement(m,null,e.createElement(m,{width:20},e.createElement(l,{color:s.secondary},"Tokens Consumed:")),e.createElement(l,{color:s.text},Lt(lo))),(Et?.cost||0)>0&&e.createElement(m,{marginLeft:2},e.createElement(m,{width:18},e.createElement(l,{color:s.textMuted},"\xBB Cost Estimate:")),e.createElement(l,{color:s.success||"green"},(()=>{let u=Number(Et.cost)||0;return u<=0?"":u<.001?"<$0.001":`$${u.toFixed(u<.01?4:3)}`})())),e.createElement(m,{marginLeft:2},e.createElement(m,{width:18},e.createElement(l,{color:s.textMuted},"\xBB Input Tokens:")),e.createElement(l,{color:s.text},Lt(lo-Un))),wo>0&&e.createElement(m,{marginLeft:4},e.createElement(m,{width:16},e.createElement(l,{color:s.textMuted},"\xBB Cached:")),e.createElement(l,{color:s.text},Lt(wo))),Un>0&&e.createElement(m,{marginLeft:2},e.createElement(m,{width:18},e.createElement(l,{color:s.textMuted},"\xBB Output Tokens:")),e.createElement(l,{color:s.text},Lt(Un)))),Hr>0&&e.createElement(e.Fragment,null,e.createElement(m,null,e.createElement(m,{width:20},e.createElement(l,{color:s.secondary},"Images Made:")),e.createElement(l,{color:s.text},Hr)),e.createElement(m,null,e.createElement(m,{width:20},e.createElement(l,{color:s.secondary},"Image Credits:")),e.createElement(l,{color:s.text},Number(((Ui||0)*1e3).toFixed(0))," credits")))),e.createElement(m,{flexDirection:"column",marginTop:1},e.createElement(l,{color:s.text,bold:!0,underline:!0},"Performance"),e.createElement(m,{marginTop:1},e.createElement(m,{width:20},e.createElement(l,{color:s.secondary},"Wall Time:")),e.createElement(l,{color:s.text},bn(n))),e.createElement(m,null,e.createElement(m,{width:20},e.createElement(l,{color:s.secondary},"Agent Active:")),e.createElement(l,{color:s.text},bn(f))),e.createElement(m,{marginLeft:2},e.createElement(m,{width:18},e.createElement(l,{color:s.textMuted},"\xBB API Time:")),e.createElement(l,{color:s.text},bn(Ur)," (",x,"%)")),e.createElement(m,{marginLeft:2},e.createElement(m,{width:18},e.createElement(l,{color:s.textMuted},"\xBB Tool Time:")),e.createElement(l,{color:s.text},bn(_r)," (",v,"%)"))))})())))}export{Ci as check9RouterReachable,yu as default};