@openchamber/web 1.16.0 → 1.16.1

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 (54) hide show
  1. package/README.md +5 -5
  2. package/dist/assets/{DiagramView-he_RFVx5.js → DiagramView-Elkp8b4l.js} +1 -1
  3. package/dist/assets/{MarkdownRendererImpl-CdBIHSPZ.js → MarkdownRendererImpl-DLhrL6oX.js} +4 -4
  4. package/dist/assets/{MultiRunWindow-B_C-tvVq.js → MultiRunWindow-DVpNCqnE.js} +1 -1
  5. package/dist/assets/{OnboardingScreen-BBnTt-9w.js → OnboardingScreen-CpcR0gyq.js} +1 -1
  6. package/dist/assets/SessionSwitcherDropdown-DHO5Je6v.js +1 -0
  7. package/dist/assets/{SettingsWindow-CjqLdpTE.js → SettingsWindow-Bewo7vwh.js} +1 -1
  8. package/dist/assets/{TerminalView-DQcdegHp.js → TerminalView-D9C7fNLm.js} +1 -1
  9. package/dist/assets/es-D9nOo8Wx.js +15 -0
  10. package/dist/assets/fr-DEF71lgt.js +13 -0
  11. package/dist/assets/index-BklNmnVr.js +2 -0
  12. package/dist/assets/index-C3uMIExE.css +1 -0
  13. package/dist/assets/ja-CpNfaEje.js +15 -0
  14. package/dist/assets/ko-DLS_rnE-.js +15 -0
  15. package/dist/assets/main-B0CxEOP5.js +237 -0
  16. package/dist/assets/{main-Dfm-VKZ9.js → main-Ck3ZNw8-.js} +2 -2
  17. package/dist/assets/miniChat-BAJj2Ome.js +2 -0
  18. package/dist/assets/mobile-CJoX4Cdj.js +2 -0
  19. package/dist/assets/pl-BjtFn5-n.js +15 -0
  20. package/dist/assets/pt-BR-C0_4Rnzn.js +15 -0
  21. package/dist/assets/renderElectronMiniChatApp-D4-OXCXM.js +2 -0
  22. package/dist/assets/{renderMobileApp-o7Fs9EBx.js → renderMobileApp-DHWdI195.js} +3 -3
  23. package/dist/assets/runtimeEndpointReset-B0P2DED1.js +167 -0
  24. package/dist/assets/uk-BDu4E0s0.js +15 -0
  25. package/dist/assets/{useAppFontEffects-DkPuAMXD.js → useAppFontEffects-9LFMCKYW.js} +127 -127
  26. package/dist/assets/zh-CN-BcwMqxIR.js +15 -0
  27. package/dist/assets/zh-TW-bNDQjKEu.js +15 -0
  28. package/dist/index.html +3 -3
  29. package/dist/mini-chat.html +3 -3
  30. package/dist/mobile.html +3 -3
  31. package/package.json +1 -1
  32. package/server/lib/opencode/settings-helpers.js +9 -0
  33. package/server/lib/package-manager.js +1 -1
  34. package/server/lib/small-model/DOCUMENTATION.md +3 -1
  35. package/server/lib/small-model/call.js +45 -8
  36. package/server/lib/small-model/call.test.js +338 -0
  37. package/server/lib/small-model/index.js +1 -0
  38. package/dist/assets/SessionSwitcherDropdown-CWWrCFzr.js +0 -1
  39. package/dist/assets/es-r0_jT91q.js +0 -15
  40. package/dist/assets/fr-Bo8rtAJ1.js +0 -13
  41. package/dist/assets/index-8J6waVO6.js +0 -2
  42. package/dist/assets/index-DEMqM4Lz.css +0 -1
  43. package/dist/assets/ja-BPWtkG-c.js +0 -15
  44. package/dist/assets/ko-Bv0k-0E3.js +0 -15
  45. package/dist/assets/main-B-GA5Tg5.js +0 -237
  46. package/dist/assets/miniChat-CfmCFFfu.js +0 -2
  47. package/dist/assets/mobile-CXJqeDlm.js +0 -2
  48. package/dist/assets/pl-CiTP50bz.js +0 -15
  49. package/dist/assets/pt-BR-DadIjX5L.js +0 -15
  50. package/dist/assets/renderElectronMiniChatApp-DS7Dy2ii.js +0 -2
  51. package/dist/assets/runtimeEndpointReset-MTaPPm4F.js +0 -167
  52. package/dist/assets/uk-2RpsWGoZ.js +0 -15
  53. package/dist/assets/zh-CN-BwKWaTuz.js +0 -15
  54. package/dist/assets/zh-TW--f_BqBpD.js +0 -15
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-9LFMCKYW.js","assets/vendor-.bun-BE757pvp.js","assets/index-BklNmnVr.js","assets/index-C3uMIExE.css"])))=>i.map(i=>d[i]);
2
+ import{b as q,j as c,R as p,_ as Et,I as Mt,r as At}from"./vendor-.bun-BE757pvp.js";import{e as me,ae as Rt,J as we,u as ht,D as Lt,o as vt,m as It,p as Nt,q as Bt}from"./index-BklNmnVr.js";import{eY as Ot,c as jt,dU as Tt,G as g,b as Ye,Y as I,cl as yt,ah as zt,d as Wt,j as _t,aU as $t,aW as Ut,v as Gt,I as qe,B as xt,a_ as V,ai as Ft,aY as Ht,$ as Vt,a0 as qt,a1 as Yt,a7 as Jt,a9 as Kt,a6 as Zt,a4 as Qt,a5 as Xt,eZ as en,cV as tn,U as nn,aa as rn,at as sn,au as on,av as an,aw as cn,ax as ln,ay as dn,az as un,aA as fn,aB as mn}from"./useAppFontEffects-9LFMCKYW.js";import{u as pn,C as hn,W as St,S as yn}from"./SessionSwitcherDropdown-DHO5Je6v.js";const wn=t=>{const e=q.c(3),{mode:r,children:s}=t;let n;return e[0]!==s||e[1]!==r?(n=c.jsx(Ot.Provider,{value:r,children:s}),e[0]=s,e[1]=r,e[2]=n):n=e[2],n},gn=t=>{const e=typeof t=="string"?t.trim():"";if(!e)return"";const r=typeof window<"u"?window.__OPENCHAMBER_HOME__:"";if(r&&e===r)return"~";if(r&&e.startsWith(`${r}/`))return`~/${e.slice(r.length+1)}`;const s=e.split("/").filter(Boolean);return s.length<=3?e:`.../${s.slice(-3).join("/")}`},U=t=>{const e=typeof t=="string"?t.trim():"";if(!e)return"";const r=e.replace(/\\/g,"/");return r==="/"?"/":r.replace(/\/+$/,"")},vn=t=>{const e=q.c(133),{mode:r}=t,{t:s}=jt(),n=g(Sn),l=g(bn),a=g(In),u=me(jn),f=Ye(_n),d=Ye(Dn),y=I(kn),_=I(Cn),D=yt(),v=zt(n??""),w=Wt(),S=_t(Pn);let T;e[0]!==n?(T=o=>n?o.worktreeMetadata.get(n)?.path??"":"",e[0]=n,e[1]=T):T=e[1];const A=g(T);let R;e[2]!==n?(R=o=>n?o.worktreeMetadata.get(n)?.branch?.trim()??null:null,e[2]=n,e[3]=R):R=e[3];const B=g(R);let z;e[4]!==n?(z=o=>n?o.getAttachment(n):void 0,e[4]=n,e[5]=z):z=e[5];const i=$t(z),L=g(En),[m,j]=p.useState(!1),W=typeof window<"u"?window.__OPENCHAMBER_MACOS_MAJOR__??0:0,G=Number.isFinite(W)&&W>0,{usesFramelessChrome:N,side:pe}=pn(),wt=G?W>=26?"h-12":W<=15?"h-14":"":"";let $;e[6]!==n||e[7]!==D?($=n?D.find(o=>o.id===n)??null:null,e[6]=n,e[7]=D,e[8]=$):$=e[8];const E=$,Y=E?.worktreeMetadata??null;let ge,ve;e[9]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>{Rt()&&we("desktop_get_window_pinned").then(o=>{typeof o?.pinned=="boolean"&&j(o.pinned)})},ve=[],e[9]=ge,e[10]=ve):(ge=e[9],ve=e[10]),p.useEffect(ge,ve);let xe;e[11]!==l||e[12]!==r||e[13]!==E?.title||e[14]!==s?(xe=E?.title?.trim()||s(l||r==="draft"?"miniChat.header.newSession":"miniChat.header.session"),e[11]=l,e[12]=r,e[13]=E?.title,e[14]=s,e[15]=xe):xe=e[15];const Je=xe,Ke=E?.directory??null;let Se;e[16]!==Ke?(Se=U(Ke),e[16]=Ke,e[17]=Se):Se=e[17];const be=Se,Ze=A||Y?.path||i?.cwd||i?.worktreeRoot||"";let Ie;e[18]!==Ze?(Ie=U(Ze),e[18]=Ze,e[19]=Ie):Ie=e[19];const je=Ie;let _e;e[20]!==u?(_e=U(u),e[20]=u,e[21]=_e):_e=e[21];const k=je||be||L||_e;let De;e[22]!==k?(De=gn(k),e[22]=k,e[23]=De):De=e[23];const Dt=De;let ke;e[24]!==be||e[25]!==je?(ke=o=>{const h=U(je||be||"");if(!h)return null;for(const P of o.availableWorktreesByProject.values()){const b=P.find(O=>U(O.path)===h)?.branch?.trim();if(b)return b}return null},e[24]=be,e[25]=je,e[26]=ke):ke=e[26];const Qe=g(ke);let Ce,Pe;e[27]!==S||e[28]!==k||e[29]!==w.git?(Ce=()=>{k&&S(k,w.git).catch(Mn)},Pe=[S,k,w.git],e[27]=S,e[28]=k,e[29]=w.git,e[30]=Ce,e[31]=Pe):(Ce=e[30],Pe=e[31]),p.useEffect(Ce,Pe),Y?.projectDirectory,i?.worktreeRoot;let Xe;e:{const o=Y?.projectDirectory??i?.worktreeRoot??null;let h;e[32]!==o?(h=U(o),e[32]=o,e[33]=h):h=e[33];const x=h||k;if(!x){Xe=null;break e}let b;e[34]!==x||e[35]!==f?(b=f.map(An).filter(O=>O.normalizedPath&&(O.normalizedPath===x||x.startsWith(`${O.normalizedPath}/`))).sort(Rn)[0]??null,e[34]=x,e[35]=f,e[36]=b):b=e[36],Xe=b}const kt=Xe;let Ee;e:{const o=kt??d;if(!o){Ee=Dt||"OpenChamber";break e}let h;e[37]!==o.label?(h=o.label?.trim(),e[37]=o.label,e[38]=h):h=e[38];const P=h;if(P){Ee=P;break e}let x;e[39]!==o.path?(x=o.path.split(/[\\/]/).filter(Boolean).at(-1)??o.path,e[39]=o.path,e[40]=x):x=e[40],Ee=x}const et=Ee,tt=Ut(k||null);let Me;e[41]!==Qe||e[42]!==tt||e[43]!==Y?.branch||e[44]!==i?.branch||e[45]!==B?(Me=tt||B||Y?.branch?.trim()||i?.branch?.trim()||Qe,e[41]=Qe,e[42]=tt,e[43]=Y?.branch,e[44]=i?.branch,e[45]=B,e[46]=Me):Me=e[46];const nt=Me,Ae=nt&&nt!=="HEAD"?nt:null;let Re;e[47]!==y?(Re=y(),e[47]=y,e[48]=Re):Re=e[48];const gt=Re;let rt;e:{for(let o=v.length-1;o>=0;o=o-1,o){const h=v[o];if(h.role!=="assistant"||typeof h.providerID!="string"||typeof h.modelID!="string")continue;const x=_.find(b=>b.id===h.providerID)?.models.find(b=>b.id===h.modelID);if(x){rt=x;break e}}rt=void 0}const Ct=rt,Le=gt?.limit?gt:Ct,J=Le&&typeof Le.limit=="object"&&Le.limit!==null?Le.limit:null,F=J&&typeof J.context=="number"?J.context:0,he=J&&typeof J.output=="number"?J.output:0;let Ne;e:{if(!n||v.length===0){Ne=null;break e}let o,h;for(let ye=v.length-1;ye>=0;ye=ye-1,ye){const pt=v[ye];if(pt.role!=="assistant")continue;const H=pt.tokens;if(!H)continue;if(H.input+H.output+H.reasoning+(H.cache?.read??0)+(H.cache?.write??0)>0){o=H,h=pt.id;break}}if(!o){Ne=null;break e}const P=o.input+o.output+o.reasoning+(o.cache?.read??0)+(o.cache?.write??0),x=F>0?F:2e5;let b;e[49]!==F||e[50]!==P?(b=F>0?Math.round(P/F*100):0,e[49]=F,e[50]=P,e[51]=b):b=e[51];const O=b;let He;e[52]!==o.output||e[53]!==he?(He=he>0?Math.round(o.output/he*100):void 0,e[52]=o.output,e[53]=he,e[54]=He):He=e[54];const ut=He,ft=F||0,mt=he||void 0;let Ve;e[55]!==h||e[56]!==ut||e[57]!==O||e[58]!==ft||e[59]!==mt||e[60]!==x||e[61]!==P?(Ve={totalTokens:P,percentage:O,contextLimit:ft,outputLimit:mt,normalizedOutput:ut,thresholdLimit:x,lastMessageId:h},e[55]=h,e[56]=ut,e[57]=O,e[58]=ft,e[59]=mt,e[60]=x,e[61]=P,e[62]=Ve):Ve=e[62],Ne=Ve}const C=Ne,[M,st]=p.useState(null);let Be;e[63]===Symbol.for("react.memo_cache_sentinel")?(Be={WebkitAppRegion:"drag"},e[63]=Be):Be=e[63];const Pt=Be;let Oe;e[64]===Symbol.for("react.memo_cache_sentinel")?(Oe={WebkitAppRegion:"no-drag"},e[64]=Oe):Oe=e[64];const ot=Oe;let Te,ze;e[65]!==C||e[66]!==n?(Te=()=>{if(!n){st(Ln);return}if(C&&C.totalTokens>0){st(o=>o&&o.totalTokens===C.totalTokens&&o.percentage===C.percentage&&o.contextLimit===C.contextLimit&&(o.outputLimit??0)===(C.outputLimit??0)&&(o.normalizedOutput??0)===(C.normalizedOutput??0)&&o.thresholdLimit===C.thresholdLimit&&o.lastMessageId===C.lastMessageId?o:C);return}st(Nn)},ze=[C,n],e[65]=C,e[66]=n,e[67]=Te,e[68]=ze):(Te=e[67],ze=e[68]),p.useEffect(Te,ze);const it=M&&M.contextLimit>0?Math.min(999,M.totalTokens/M.contextLimit*100):0;let We;e[69]!==m?(We=()=>{const o=!m;j(o),we("desktop_set_window_pinned",{pinned:o}).catch(()=>{j(!o)})},e[69]=m,e[70]=We):We=e[70];const at=We;let $e;e[71]!==u||e[72]!==n||e[73]!==a||e[74]!==k||e[75]!==E?($e=()=>{const o=n?{sessionId:n,directory:E?.directory??u??""}:{mode:"draft",directory:k||u||"",projectId:a};we("desktop_focus_main_window",o).then(Bn)},e[71]=u,e[72]=n,e[73]=a,e[74]=k,e[75]=E,e[76]=$e):$e=e[76];const ct=$e,lt=N?"h-12":wt||"min-h-14";let K;e[77]!==lt?(K=Gt("flex items-center gap-3 bg-background pr-3",G?"pl-[5.5rem]":"pl-3",lt),e[77]=lt,e[78]=K):K=e[78];let Z;e[79]!==N||e[80]!==pe?(Z=N&&pe==="left"?c.jsx(St,{visible:!0,position:"left"}):null,e[79]=N,e[80]=pe,e[81]=Z):Z=e[81];let Q;e[82]!==s?(Q=s("sessions.switcher.openAria"),e[82]=s,e[83]=Q):Q=e[83];let X;e[84]!==Je?(X=c.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:Je}),e[84]=Je,e[85]=X):X=e[85];let ee;e[86]!==et?(ee=c.jsx("span",{className:"truncate",children:et}),e[86]=et,e[87]=ee):ee=e[87];let te;e[88]!==Ae?(te=Ae?c.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[c.jsx(qe,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),c.jsx("span",{className:"truncate",children:Ae})]}):null,e[88]=Ae,e[89]=te):te=e[89];let ne;e[90]!==ee||e[91]!==te?(ne=c.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[ee,te]}),e[90]=ee,e[91]=te,e[92]=ne):ne=e[92];let re;e[93]!==Q||e[94]!==X||e[95]!==ne?(re=c.jsx(yn,{children:c.jsxs("button",{type:"button","aria-label":Q,style:ot,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[X,ne]})}),e[93]=Q,e[94]=X,e[95]=ne,e[96]=re):re=e[96];let Ue;e[97]===Symbol.for("react.memo_cache_sentinel")?(Ue=c.jsx("div",{className:"min-w-0 flex-1"}),e[97]=Ue):Ue=e[97];let se;e[98]!==it||e[99]!==M?(se=M&&M.totalTokens>0?c.jsx(hn,{totalTokens:M.totalTokens,percentage:it,colorPercentage:M.percentage,contextLimit:M.contextLimit,outputLimit:M.outputLimit??0,className:"h-9 shrink-0 pl-1 pr-1 typography-ui-label",valueClassName:"font-semibold leading-none",hideIcon:!0,showPercentIcon:!0,percentIconClassName:"h-4.5 w-4.5"}):null,e[98]=it,e[99]=M,e[100]=se):se=e[100];let oe;e[101]!==m||e[102]!==s?(oe=s(m?"miniChat.actions.unpinAria":"miniChat.actions.pinAria"),e[101]=m,e[102]=s,e[103]=oe):oe=e[103];let ie;e[104]!==m||e[105]!==s?(ie=s(m?"miniChat.actions.unpin":"miniChat.actions.pin"),e[104]=m,e[105]=s,e[106]=ie):ie=e[106];let ae;e[107]!==m?(ae=m?c.jsx(qe,{name:"pushpin-2-fill",className:"h-4 w-4"}):c.jsx(qe,{name:"pushpin-2",className:"h-4 w-4"}),e[107]=m,e[108]=ae):ae=e[108];let ce;e[109]!==at||e[110]!==oe||e[111]!==ie||e[112]!==ae?(ce=c.jsx(xt,{type:"button",variant:"ghost",size:"icon",onClick:at,"aria-label":oe,title:ie,style:ot,children:ae}),e[109]=at,e[110]=oe,e[111]=ie,e[112]=ae,e[113]=ce):ce=e[113];let le;e[114]!==s?(le=s("miniChat.actions.openMainAria"),e[114]=s,e[115]=le):le=e[115];let de;e[116]!==s?(de=s("miniChat.actions.openMain"),e[116]=s,e[117]=de):de=e[117];let Ge;e[118]===Symbol.for("react.memo_cache_sentinel")?(Ge=c.jsx(qe,{name:"external-link",className:"h-4 w-4"}),e[118]=Ge):Ge=e[118];let ue;e[119]!==ct||e[120]!==le||e[121]!==de?(ue=c.jsx(xt,{type:"button",variant:"ghost",size:"icon",onClick:ct,"aria-label":le,title:de,style:ot,children:Ge}),e[119]=ct,e[120]=le,e[121]=de,e[122]=ue):ue=e[122];const dt=N&&pe==="right";let fe;e[123]!==dt?(fe=c.jsx(St,{visible:dt,position:"right"}),e[123]=dt,e[124]=fe):fe=e[124];let Fe;return e[125]!==K||e[126]!==Z||e[127]!==re||e[128]!==se||e[129]!==ce||e[130]!==ue||e[131]!==fe?(Fe=c.jsxs("header",{className:K,style:Pt,children:[Z,re,Ue,se,ce,ue,fe]}),e[125]=K,e[126]=Z,e[127]=re,e[128]=se,e[129]=ce,e[130]=ue,e[131]=fe,e[132]=Fe):Fe=e[132],Fe},xn=t=>{const e=q.c(9),{mode:r,autoOpenDraft:s,unavailable:n}=t,l=s===void 0?!1:s,a=n===void 0?!1:n,{t:u}=jt();let f;e[0]!==r?(f=c.jsx(vn,{mode:r}),e[0]=r,e[1]=f):f=e[1];let d;e[2]!==l||e[3]!==u||e[4]!==a?(d=c.jsx("main",{className:"min-h-0 flex-1",children:a?c.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center typography-ui-label text-muted-foreground",children:c.jsxs("div",{className:"max-w-sm rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-3",children:[c.jsx("div",{className:"font-medium text-foreground",children:u("miniChat.unavailable.title")}),c.jsx("div",{className:"mt-1 typography-small text-muted-foreground",children:u("miniChat.unavailable.description")})]})}):c.jsx(wn,{mode:"mini-chat",children:c.jsx(Tt,{autoOpenDraft:l})})}),e[2]=l,e[3]=u,e[4]=a,e[5]=d):d=e[5];let y;return e[6]!==f||e[7]!==d?(y=c.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[f,d]}),e[6]=f,e[7]=d,e[8]=y):y=e[8],y};function Sn(t){return t.currentSessionId}function bn(t){return!!t.newSessionDraft?.open}function In(t){return t.newSessionDraft?.selectedProjectId??null}function jn(t){return t.currentDirectory}function _n(t){return t.projects}function Dn(t){return t.getActiveProject()}function kn(t){return t.getCurrentModel}function Cn(t){return t.providers}function Pn(t){return t.ensureStatus}function En(t){return t.newSessionDraft?.open?U(t.newSessionDraft.bootstrapPendingDirectory??t.newSessionDraft.directoryOverride??""):""}function Mn(){}function An(t){return{...t,normalizedPath:U(t.path)}}function Rn(t,e){return e.path.length-t.path.length}function Ln(t){return t===null?t:null}function Nn(t){return t===null?t:null}function Bn(t){return t?.focused===!0?we("desktop_close_current_window"):null}const bt=()=>{document.querySelector('textarea[data-chat-input="true"]')?.focus()},On=()=>{const t=ht(n=>n.shortcutOverrides),e=me(n=>n.currentDirectory),r=Ye(n=>n.getActiveProject()),s=g(n=>n.openNewSessionDraft);p.useEffect(()=>{const n=a=>Ht(a,t),l=a=>{if(V(a,n("focus_input"))){a.preventDefault(),bt();return}if(Lt()&&V(a,n("new_mini_chat"))){a.preventDefault(),we("desktop_open_draft_mini_chat_window",{directory:e||r?.path||"",projectId:r?.id??null})?.catch(d=>{console.warn("[mini-chat-shortcuts] failed to open draft mini chat window",d)});return}if(V(a,n("new_chat"))){a.preventDefault(),s({selectedProjectId:r?.id??null,directoryOverride:e||r?.path||null,preserveDirectoryOverride:!!(e||r?.path)}),bt();return}if(V(a,n("open_model_selector"))){a.preventDefault();const{isModelSelectorOpen:d,setModelSelectorOpen:y}=ht.getState();y(!d);return}if(V(a,n("cycle_thinking_variant"))){const d=I.getState();if(d.getCurrentModelVariants().length===0)return;a.preventDefault(),d.cycleCurrentVariant();const _=I.getState().currentVariant,D=g.getState().currentSessionId,v=I.getState().currentAgentName,w=I.getState().currentProviderId,S=I.getState().currentModelId;D&&v&&w&&S&&Ft.getState().saveAgentModelVariantForSession(D,v,w,S,_);return}const u=V(a,n("cycle_favorite_model_forward")),f=V(a,n("cycle_favorite_model_backward"));if(u||f){const{favoriteModels:d,addRecentModel:y}=ht.getState();if(d.length===0)return;a.preventDefault();const{currentProviderId:_,currentModelId:D,setProvider:v,setModel:w}=I.getState(),S=d.findIndex(R=>R.providerID===_&&R.modelID===D),A=d[(S+(u?1:-1)+d.length)%d.length];v(A.providerID),w(A.modelID),y(A.providerID,A.modelID)}};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[r?.id,r?.path,e,s,t])},Tn="openchamber:mini-chat-presence",zn=()=>{const t=typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,e=t.get("mode")==="session"?"session":"draft",r=t.get("sessionId")?.trim()||null,s=t.get("directory")?.trim()||null,n=t.get("projectId")?.trim()||null;return{mode:e,sessionId:r,directory:s,projectId:n}},Wn=({config:t})=>{const e=yt(),r=me(i=>i.currentDirectory),s=me(i=>i.setDirectory),n=Ye(i=>i.projects),l=g(i=>i.currentSessionId),a=g(i=>!!i.newSessionDraft?.open),u=g(i=>i.newSessionDraft?.open?i.newSessionDraft.bootstrapPendingDirectory??i.newSessionDraft.directoryOverride??"":""),f=g(i=>i.setCurrentSession),d=g(i=>i.openNewSessionDraft),y=I(i=>i.initializeApp),_=I(i=>i.isInitialized),D=I(i=>i.isConnected),v=I(i=>i.loadProviders),w=I(i=>i.loadAgents),S=I(i=>i.providers.length),T=I(i=>i.agents.length),A=tn();p.useEffect(()=>{y()},[y]),p.useEffect(()=>{if(_)return;let i=!0,L=0;const m=window.setInterval(()=>{if(i){if(L+=1,L>10){window.clearInterval(m);return}I.getState().isInitialized||I.getState().initializeApp()}},1e3);return()=>{i=!1,window.clearInterval(m)}},[_]);const R=p.useRef(!1);p.useEffect(()=>{if(!R.current&&t.mode==="session"&&t.directory){if(r===t.directory){R.current=!0;return}s(t.directory,{showOverlay:!1}),R.current=!0}},[t.directory,t.mode,r,s]),p.useEffect(()=>{t.mode!=="draft"||!a||l||!u||r===u||s(u,{showOverlay:!1})},[t.mode,r,l,u,a,s]),p.useEffect(()=>{D&&(S===0&&v({source:"electronMiniChat:recovery"}),T===0&&w({source:"electronMiniChat:recovery"}))},[T,D,w,v,S]);const B=p.useRef(!1);p.useEffect(()=>{if(B.current||t.mode!=="session"||!t.sessionId)return;if(l===t.sessionId){B.current=!0;return}if(l){B.current=!0;return}const i=e.find(m=>m.id===t.sessionId);if(!i){A.ensureSessionRenderable(t.sessionId);return}const L=i.directory??t.directory;f(t.sessionId,L),B.current=!0},[t,l,e,f,A]),p.useEffect(()=>{const i=L=>{const m=L.detail,j=typeof m?.sessionId=="string"?m.sessionId.trim():"";if(!j||g.getState().currentSessionId===j)return;const W=typeof m?.directory=="string"&&m.directory.trim().length>0?m.directory.trim():e.find(G=>G.id===j)?.directory??null;A.ensureSessionRenderable(j),f(j,W),B.current=!0};return window.addEventListener("openchamber:open-session",i),()=>window.removeEventListener("openchamber:open-session",i)},[e,f,A]),p.useEffect(()=>{t.mode!=="draft"||a||l||d({selectedProjectId:t.projectId,directoryOverride:t.directory,preserveDirectoryOverride:!!t.directory})},[t,l,a,d]),p.useEffect(()=>{if(n.length===0)return;let i=!1;return(async()=>{const m=new Map,j=[];if(await Promise.all(n.map(async G=>{const N=G.path.replace(/\\/g,"/").replace(/\/+$/,"");if(N)try{if(!(_t.getState().directories.get(N)?.isGitRepo??await Et(()=>import("./useAppFontEffects-9LFMCKYW.js").then(E=>E.fe),__vite__mapDeps([0,1,2,3])).then(E=>E.checkIsGitRepository(N))))return;const $=await nn({id:G.id,path:N});if(i||$.length===0)return;m.set(N,$),j.push(...$)}catch{}})),i)return;const W=g.getState().availableWorktreesByProject;rn(m,W)||g.setState({availableWorktrees:j,availableWorktreesByProject:m})})(),()=>{i=!0}},[n]);const z=p.useRef(!1);return p.useEffect(()=>{if(z.current||!_)return;const i=()=>{if(z.current)return;z.current=!0;const j=typeof document<"u"?document.getElementById("initial-loading"):null;j&&(j.classList.add("fade-out"),window.setTimeout(()=>j.remove(),300))},L=t.mode==="session"?l===t.sessionId:a,m=window.setTimeout(i,L?100:1500);return()=>window.clearTimeout(m)},[_,t.mode,t.sessionId,l,a]),null},$n=()=>{const t=q.c(4),e=g(qn),r=me(Yn);let s,n;return t[0]!==r||t[1]!==e?(s=()=>{if(!e||!r||typeof BroadcastChannel>"u")return;const l=new BroadcastChannel(Tn),a=d=>{l.postMessage({type:"mini-chat-session-presence",sessionId:e,directory:r,viewed:d})};a(!0);const u=window.setInterval(()=>a(!0),5e3),f=()=>a(!1);return window.addEventListener("beforeunload",f),()=>{window.clearInterval(u),window.removeEventListener("beforeunload",f),a(!1),l.close()}},n=[r,e],t[0]=r,t[1]=e,t[2]=s,t[3]=n):(s=t[2],n=t[3]),p.useEffect(s,n),null},Un=t=>{const e=q.c(6),r=yt(),s=g(Jn),[n,l]=p.useState(!1);let a,u;return e[0]!==t.mode||e[1]!==t.sessionId||e[2]!==s||e[3]!==r?(a=()=>{if(t.mode!=="session"||!t.sessionId||s===t.sessionId){l(!1);return}if(r.some(d=>d.id===t.sessionId)){l(!1);return}const f=window.setTimeout(()=>l(!0),5e3);return()=>window.clearTimeout(f)},u=[t.mode,t.sessionId,s,r],e[0]=t.mode,e[1]=t.sessionId,e[2]=s,e[3]=r,e[4]=a,e[5]=u):(a=e[4],u=e[5]),p.useEffect(a,u),n};function Gn(t){const e=q.c(15),{apis:r}=t;let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=zn(),e[0]=s):s=e[0];const n=s,l=me(Hn);let a,u;e[1]!==l?(a=()=>{vt.setDirectory(l||n.directory||void 0)},u=[n.directory,l],e[1]=l,e[2]=a,e[3]=u):(a=e[2],u=e[3]),p.useEffect(a,u);let f,d;e[4]!==r?(f=()=>(It(r),Fn),d=[r],e[4]=r,e[5]=f,e[6]=d):(f=e[5],d=e[6]),p.useEffect(f,d),Vt(),On();let y;e[7]===Symbol.for("react.memo_cache_sentinel")?(y={enabled:!0},e[7]=y):y=e[7],qt(y),Yt();let _;e[8]===Symbol.for("react.memo_cache_sentinel")?(_=vt.getSdkClient(),e[8]=_):_=e[8];const D=l||n.directory||"";let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=c.jsx(Jt,{delayDuration:300,skipDelayDuration:150,children:c.jsxs("div",{className:"h-full text-foreground bg-background",children:[c.jsx(Vn,{config:n}),c.jsx(Kt,{})]})}),e[9]=v):v=e[9];let w;e[10]!==r?(w=c.jsx(Zt,{apis:r,children:v}),e[10]=r,e[11]=w):w=e[11];let S;return e[12]!==w||e[13]!==D?(S=c.jsx(Qt,{children:c.jsx(Xt,{sdk:_,directory:D,children:w})}),e[12]=w,e[13]=D,e[14]=S):S=e[14],S}function Fn(){return It(null)}function Hn(t){return t.currentDirectory}const Vn=t=>{const e=q.c(11),{config:r}=t,s=Un(r);let n;e[0]!==r?(n=c.jsx(Wn,{config:r}),e[0]=r,e[1]=n):n=e[1];let l,a;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=c.jsx($n,{}),a=c.jsx(en,{embeddedBackgroundWorkEnabled:!0}),e[2]=l,e[3]=a):(l=e[2],a=e[3]);const u=r.mode==="draft";let f;e[4]!==r.mode||e[5]!==s||e[6]!==u?(f=c.jsx(xn,{mode:r.mode,autoOpenDraft:u,unavailable:s}),e[4]=r.mode,e[5]=s,e[6]=u,e[7]=f):f=e[7];let d;return e[8]!==n||e[9]!==f?(d=c.jsxs(c.Fragment,{children:[n,l,a,f]}),e[8]=n,e[9]=f,e[10]=d):d=e[10],d};function qn(t){return t.currentSessionId}function Yn(t){return t.currentDirectory}function Jn(t){return t.currentSessionId}const Kn=()=>{ln(),Nt().then(()=>{Promise.all([Bt(),dn()]).catch(t=>{console.error("[mini-chat-main] settings init failed:",t)}),un(),fn(),mn()}).catch(t=>{console.error("[mini-chat-main] appearance init failed:",t)})};function rr(t){Kn();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");Mt.createRoot(e).render(c.jsx(At.StrictMode,{children:c.jsx(sn,{children:c.jsx(on,{children:c.jsx(an,{children:c.jsx(cn,{children:c.jsx(Gn,{apis:t})})})})})}))}export{rr as renderElectronMiniChatApp};
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-DkPuAMXD.js","assets/vendor-.bun-BE757pvp.js","assets/index-8J6waVO6.js","assets/index-DEMqM4Lz.css"])))=>i.map(i=>d[i]);
2
- import{b as de,r as rs,j as t,R as c,P as Ct,K as ms,e as jr,f as Sn,B as kr,Q as Sr,g as Nr,i as Cr,F as Er,U as Pr,Z as Ir,a as hs,p as Nn,k as Tr,u as Cn,l as zt,s as En,m as Pn,n as In,o as os,D as Tn,q as An,S as Rn,v as Dn,t as Mn,w as _n,C as zn,M as Ln,x as is,J as On,y as Ar,z as Ms,A as ps,E as _s,V as Rr,G as Dr,H as Mr,_ as ze,I as _r}from"./vendor-.bun-BE757pvp.js";import{u as mt,a as zs,b as zr,r as Lr,d as We,e as lt,s as jt,f as Bn,i as kt,h as gs,j as Or,k as Fn,l as Ls,m as Os,n as Br,o as Bs,p as Fr,q as $r}from"./index-8J6waVO6.js";import{u as Ut,a as Ur,b as Te,r as $n,c as ue,g as Un,t as ie,o as Wr,I as re,d as Wt,e as bs,f as xs,h as Wn,i as Vr,j as Ae,s as Gr,k as Hr,l as Kr,m as qr,n as Jr,p as Vn,B as pe,q as ot,S as Ze,v as X,w as ys,x as Yr,y as Fs,z as vs,A as $s,F as Xr,C as Us,D as Qr,J as Zr,E as Gn,G as be,H as eo,K as to,M as Hn,P as Kn,L as qn,N as Jn,O as so,Q as no,R as ro,T as oo,U as Yn,V as Ne,W as io,X as ao,Y as Ie,Z as lo,_ as co,$ as uo,a0 as fo,a1 as mo,a2 as xt,a3 as ho,a4 as Oe,a5 as po,a6 as go,a7 as bo,a8 as xo,a9 as yo,aa as vo,ab as Xn,ac as wo,ad as jo,ae as ko,af as So,ag as No,ah as Co,ai as Eo,aj as Po,ak as Ws,al as Vs,am as Io,an as To,ao as Ao,ap as Ro,aq as Do,ar as Mo,as as _o,at as zo,au as Lo,av as Oo,aw as Bo,ax as Fo,ay as $o,az as Uo,aA as Wo,aB as Vo}from"./useAppFontEffects-DkPuAMXD.js";import{u as it,S as Go,C as Ho,a as Ko,P as qo,b as Jo,D as Yo,N as Xo,p as Qo,r as Zo,c as ei,d as ti,e as si,O as ni,f as ri,g as Rt,h as oi,M as ii,i as ai,j as li,k as ci,A as di,l as Je,m as ui,Q as fi,n as mi,o as hi}from"./runtimeEndpointReset-MTaPPm4F.js";import"./mobileLayoutPreference-Dio-WWkI.js";let Qn=null,Gs=!1;const pi=new Promise(s=>{Qn=s});function gi(){Gs||(Gs=!0,Qn?.())}const bi=6,xi=s=>s.parentID??null,Hs=s=>{const e=s.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},yi=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),vi=(s,e)=>{if(!s)return"";let n=null,r=-1;for(const i of e){const o=yi(i.path);(s===o||s.startsWith(`${o}/`))&&o.length>r&&(n=i,r=o.length)}return n?n.label?.trim()||Hs(n.path):Hs(s)},wi=()=>{const s=Ut.getState().activeSessions,e=Ur.getState().index.session.unseenCount,n=mt.getState().notifyOnSubtasks,r=Te.getState().projects;let i=0;const o=[];for(const l of s){const d=xi(l)!==null,f=(e[l.id]??0)>0&&(!d||n);f&&(i+=1),d||o.push({id:l.id,title:l.title??"",updated:l.time?.updated??l.time?.created??0,unread:f,project:vi($n(l),r)})}o.sort((l,d)=>d.updated-l.updated);const a=o.slice(0,bi).map(({id:l,title:d,unread:u,project:f})=>({id:l,title:d,unread:u,project:f}));return{attentionCount:i,recentSessions:a}},ji="__OPENCHAMBER_WIDGET_SNAPSHOT__",ki=()=>{typeof window>"u"||(window[ji]=()=>{try{return JSON.stringify(wi())}catch{return null}})},Xt="mobile-app-update-available",Ks="mobile-app-update-toast-dismissed-version",Si=()=>{const s=de.c(8),{t:e}=ue(),n=it(Ni),r=it(Ci),i=it(Ei),o=it(Pi);let a;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,s[0]=a):a=s[0];const l=rs.useRef(a);let d,u;return s[1]!==n||s[2]!==o||s[3]!==r||s[4]!==e||s[5]!==i?(d=()=>{if(Un()!=="android"||r!=="mobile"||!n||!i||!o){ie.dismiss(Xt);return}zs().getItem(Ks)!==i&&(l.current.has(i)||(l.current.add(i),ie.info(e("mobileUpdate.toast.available.title"),{id:Xt,description:e("mobileUpdate.toast.available.description",{version:i}),duration:1/0,icon:t.jsx(re,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{Wr(o)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{zs().setItem(Ks,i),ie.dismiss(Xt)}}})))},u=[n,o,r,e,i],s[1]=n,s[2]=o,s[3]=r,s[4]=e,s[5]=i,s[6]=d,s[7]=u):(d=s[6],u=s[7]),rs.useEffect(d,u),null};function Ni(s){return s.available}function Ci(s){return s.runtimeType}function Ei(s){return s.info?.version}function Pi(s){return s.info?.downloadUrl}const Ii=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),Ti=s=>{const e=s.index?.trim();return!!(e&&e!=="?")},Ai=s=>{const e=s.working_dir?.trim(),n=s.index?.trim();return!!(e||n==="?")},qs=(s,e)=>e?`${s}\0staged`:s,Js=({onClose:s,initialDiffPath:e,initialDiffStaged:n=!1})=>{const{t:r}=ue(),{git:i}=Wt(),o=Ii(bs()??null),a=xs(o||null),l=Wn(o||null),d=Vr(o||null),u=Ae(z=>z.setActiveDirectory),f=Ae(z=>z.ensureAll),m=Ae(z=>z.fetchStatus),p=Ae(z=>z.fetchBranches),g=Ae(z=>z.prefetchDiffs),k=Ae(z=>z.getDiff),S=Ae(z=>z.setDiff),[y,P]=c.useState(()=>e?{type:"diff",path:e,staged:n}:{type:"list"});c.useEffect(()=>{e&&P(z=>z.type==="diff"&&z.path===e&&z.staged===n?z:{type:"diff",path:e,staged:n})},[e,n]);const[I,D]=c.useState(null),[A,R]=c.useState(null),[w,j]=c.useState(""),[T,E]=c.useState(new Set),[b,N]=c.useState(!1),[x,_]=c.useState(!1),[L,G]=c.useState([]),[M,J]=c.useState([]),[C,q]=c.useState([]),[B,O]=c.useState(null),[V,K]=c.useState(null),[Z,te]=c.useState(0),oe=c.useMemo(()=>{const z=a?.files??[],F=new Map;for(const Y of z)F.set(Y.path,Y);return Array.from(F.values()).sort((Y,Se)=>Y.path.localeCompare(Se.path))},[a?.files]),v=c.useMemo(()=>oe.filter(Ti),[oe]),W=c.useMemo(()=>oe.filter(Ai),[oe]),ee=c.useMemo(()=>{if(C.length>0)return C;const z=a?.tracking?.includes("/")?a.tracking.split("/")[0]:null;return z||B?[{name:z||"origin",fetchUrl:B??"",pushUrl:B??""}]:[]},[B,C,a?.tracking]),se=Ae(c.useCallback(z=>!o||y.type!=="diff"?null:z.directories.get(o)?.diffCache.get(qs(y.path,y.staged))??null,[o,y])),je=c.useMemo(()=>y.type!=="diff"?null:oe.find(z=>z.path===y.path)??null,[oe,y]),le=c.useCallback(async(z=!0)=>{if(o)try{await Promise.all([m(o,i),p(o,i)])}catch(F){z&&ie.error(F instanceof Error?F.message:r("gitView.toast.refreshRepositoryFailed"))}},[o,p,m,i,r]),ce=c.useCallback(async()=>{if(!o){q([]),O(null);return}try{const[z,F]=await Promise.all([i.getRemotes(o).catch(()=>[]),i.getRemoteUrl?i.getRemoteUrl(o).catch(()=>null):Promise.resolve(null)]);q(z),O(F)}catch{q([]),O(null)}},[o,i]);c.useEffect(()=>{o&&(u(o),f(o,i))},[o,f,i,u]),c.useEffect(()=>{ce()},[ce]),c.useEffect(()=>{if(!o||oe.length===0)return;const z=Array.from(new Set([...v.map(Y=>Y.path),...M,...oe.slice(0,20).map(Y=>Y.path)])).filter(Boolean);if(z.length===0)return;const F=window.setTimeout(()=>{g(o,i,z,{maxFiles:40})},120);return()=>window.clearTimeout(F)},[oe,o,i,g,v,M]),c.useEffect(()=>{if(y.type!=="diff"){K(null);return}const z=qs(y.path,y.staged);if(!o||k(o,z)){K(null);return}let F=!1;return K(null),i.getGitFileDiff(o,{path:y.path,staged:y.staged||void 0}).then(Y=>{F||S(o,z,{original:Y.original??"",modified:Y.modified??"",isBinary:Y.isBinary})}).catch(Y=>{F||K(Y instanceof Error?Y.message:String(Y))}),()=>{F=!0}},[o,Z,k,i,y,S]);const ke=async(z,F)=>{if(o){D(z);try{const Y=Se=>{const Me=`${Se.name}/`,qe=a?.tracking?.startsWith(Me)?a.tracking.slice(Me.length):void 0;return{remote:Se.name,branch:qe,rebase:!0}};if(z==="fetch"){if(!F)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:F.name}),ie.success(r("gitView.toast.fetchedFromRemote",{name:F.name}))}else if(z==="sync"){if(!F)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:F.name});const Se=await i.getGitStatus(o);if((Se.behind??0)>0){if((Se.files?.length??0)>0){ie.error(r("gitView.toast.commitOrStashBeforeSync"));return}await i.gitPull(o,Y(F))}((await i.getGitStatus(o)).ahead??0)>0&&await i.gitPush(o),ie.success(r("gitView.toast.alreadyUpToDate"))}await le(!1),await ce()}catch(Y){ie.error(Y instanceof Error?Y.message:r("gitView.toast.syncActionFailed",{action:r("gitView.sync.syncChanges")}))}finally{D(null)}}},ae=c.useCallback(async(z,F)=>{if(!(!o||z.length===0))try{F==="stage"?z.length>1?await Gr(o,z):await Hr(o,z[0]):z.length>1?await Kr(o,z):await qr(o,z[0]),await le(!1)}catch(Y){ie.error(Y instanceof Error?Y.message:r(F==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[o,le,r]),me=c.useCallback((z,F=!1)=>{P({type:"diff",path:z,staged:F})},[]),ge=c.useCallback(async z=>{if(o){E(F=>new Set(F).add(z));try{await i.revertGitFile(o,z),ie.success(r("gitView.toast.revertedFile",{path:z})),await le(!1)}catch(F){ie.error(F instanceof Error?F.message:r("gitView.toast.revertFailed"))}finally{E(F=>{const Y=new Set(F);return Y.delete(z),Y})}}},[o,i,le,r]),Fe=c.useCallback(async z=>{if(!o||z.length===0||b)return;const F=Array.from(new Set(z));N(!0),E(new Set(F));try{await Promise.all(F.map(Y=>i.revertGitFile(o,Y))),await le(!1),ie.success(F.length===1?r("gitView.toast.revertedFilesSingle",{count:F.length}):r("gitView.toast.revertedFilesPlural",{count:F.length}))}catch(Y){ie.error(Y instanceof Error?Y.message:r("gitView.toast.revertFailed"))}finally{E(new Set),N(!1)}},[o,i,b,le,r]),De=c.useCallback(z=>{const F=z.map(Y=>Y.trim()).filter(Boolean);if(F.length===0){G([]);return}j(Y=>`${Y.trim()}${Y.trim()?`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-9LFMCKYW.js","assets/vendor-.bun-BE757pvp.js","assets/index-BklNmnVr.js","assets/index-C3uMIExE.css"])))=>i.map(i=>d[i]);
2
+ import{b as de,r as rs,j as t,R as c,P as Ct,K as ms,e as jr,f as Sn,B as kr,Q as Sr,g as Nr,i as Cr,F as Er,U as Pr,Z as Ir,a as hs,p as Nn,k as Tr,u as Cn,l as zt,s as En,m as Pn,n as In,o as os,D as Tn,q as An,S as Rn,v as Dn,t as Mn,w as _n,C as zn,M as Ln,x as is,J as On,y as Ar,z as Ms,A as ps,E as _s,V as Rr,G as Dr,H as Mr,_ as ze,I as _r}from"./vendor-.bun-BE757pvp.js";import{u as mt,a as zs,b as zr,r as Lr,d as We,e as lt,s as jt,f as Bn,i as kt,h as gs,j as Or,k as Fn,l as Ls,m as Os,n as Br,o as Bs,p as Fr,q as $r}from"./index-BklNmnVr.js";import{u as Ut,a as Ur,b as Te,r as $n,c as ue,g as Un,t as ie,o as Wr,I as re,d as Wt,e as bs,f as xs,h as Wn,i as Vr,j as Ae,s as Gr,k as Hr,l as Kr,m as qr,n as Jr,p as Vn,B as pe,q as ot,S as Ze,v as X,w as ys,x as Yr,y as Fs,z as vs,A as $s,F as Xr,C as Us,D as Qr,J as Zr,E as Gn,G as be,H as eo,K as to,M as Hn,P as Kn,L as qn,N as Jn,O as so,Q as no,R as ro,T as oo,U as Yn,V as Ne,W as io,X as ao,Y as Ie,Z as lo,_ as co,$ as uo,a0 as fo,a1 as mo,a2 as xt,a3 as ho,a4 as Oe,a5 as po,a6 as go,a7 as bo,a8 as xo,a9 as yo,aa as vo,ab as Xn,ac as wo,ad as jo,ae as ko,af as So,ag as No,ah as Co,ai as Eo,aj as Po,ak as Ws,al as Vs,am as Io,an as To,ao as Ao,ap as Ro,aq as Do,ar as Mo,as as _o,at as zo,au as Lo,av as Oo,aw as Bo,ax as Fo,ay as $o,az as Uo,aA as Wo,aB as Vo}from"./useAppFontEffects-9LFMCKYW.js";import{u as it,S as Go,C as Ho,a as Ko,P as qo,b as Jo,D as Yo,N as Xo,p as Qo,r as Zo,c as ei,d as ti,e as si,O as ni,f as ri,g as Rt,h as oi,M as ii,i as ai,j as li,k as ci,A as di,l as Je,m as ui,Q as fi,n as mi,o as hi}from"./runtimeEndpointReset-B0P2DED1.js";import"./mobileLayoutPreference-Dio-WWkI.js";let Qn=null,Gs=!1;const pi=new Promise(s=>{Qn=s});function gi(){Gs||(Gs=!0,Qn?.())}const bi=6,xi=s=>s.parentID??null,Hs=s=>{const e=s.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},yi=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),vi=(s,e)=>{if(!s)return"";let n=null,r=-1;for(const i of e){const o=yi(i.path);(s===o||s.startsWith(`${o}/`))&&o.length>r&&(n=i,r=o.length)}return n?n.label?.trim()||Hs(n.path):Hs(s)},wi=()=>{const s=Ut.getState().activeSessions,e=Ur.getState().index.session.unseenCount,n=mt.getState().notifyOnSubtasks,r=Te.getState().projects;let i=0;const o=[];for(const l of s){const d=xi(l)!==null,f=(e[l.id]??0)>0&&(!d||n);f&&(i+=1),d||o.push({id:l.id,title:l.title??"",updated:l.time?.updated??l.time?.created??0,unread:f,project:vi($n(l),r)})}o.sort((l,d)=>d.updated-l.updated);const a=o.slice(0,bi).map(({id:l,title:d,unread:u,project:f})=>({id:l,title:d,unread:u,project:f}));return{attentionCount:i,recentSessions:a}},ji="__OPENCHAMBER_WIDGET_SNAPSHOT__",ki=()=>{typeof window>"u"||(window[ji]=()=>{try{return JSON.stringify(wi())}catch{return null}})},Xt="mobile-app-update-available",Ks="mobile-app-update-toast-dismissed-version",Si=()=>{const s=de.c(8),{t:e}=ue(),n=it(Ni),r=it(Ci),i=it(Ei),o=it(Pi);let a;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,s[0]=a):a=s[0];const l=rs.useRef(a);let d,u;return s[1]!==n||s[2]!==o||s[3]!==r||s[4]!==e||s[5]!==i?(d=()=>{if(Un()!=="android"||r!=="mobile"||!n||!i||!o){ie.dismiss(Xt);return}zs().getItem(Ks)!==i&&(l.current.has(i)||(l.current.add(i),ie.info(e("mobileUpdate.toast.available.title"),{id:Xt,description:e("mobileUpdate.toast.available.description",{version:i}),duration:1/0,icon:t.jsx(re,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{Wr(o)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{zs().setItem(Ks,i),ie.dismiss(Xt)}}})))},u=[n,o,r,e,i],s[1]=n,s[2]=o,s[3]=r,s[4]=e,s[5]=i,s[6]=d,s[7]=u):(d=s[6],u=s[7]),rs.useEffect(d,u),null};function Ni(s){return s.available}function Ci(s){return s.runtimeType}function Ei(s){return s.info?.version}function Pi(s){return s.info?.downloadUrl}const Ii=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),Ti=s=>{const e=s.index?.trim();return!!(e&&e!=="?")},Ai=s=>{const e=s.working_dir?.trim(),n=s.index?.trim();return!!(e||n==="?")},qs=(s,e)=>e?`${s}\0staged`:s,Js=({onClose:s,initialDiffPath:e,initialDiffStaged:n=!1})=>{const{t:r}=ue(),{git:i}=Wt(),o=Ii(bs()??null),a=xs(o||null),l=Wn(o||null),d=Vr(o||null),u=Ae(z=>z.setActiveDirectory),f=Ae(z=>z.ensureAll),m=Ae(z=>z.fetchStatus),p=Ae(z=>z.fetchBranches),g=Ae(z=>z.prefetchDiffs),k=Ae(z=>z.getDiff),S=Ae(z=>z.setDiff),[y,P]=c.useState(()=>e?{type:"diff",path:e,staged:n}:{type:"list"});c.useEffect(()=>{e&&P(z=>z.type==="diff"&&z.path===e&&z.staged===n?z:{type:"diff",path:e,staged:n})},[e,n]);const[I,D]=c.useState(null),[A,R]=c.useState(null),[w,j]=c.useState(""),[T,E]=c.useState(new Set),[b,N]=c.useState(!1),[x,_]=c.useState(!1),[L,G]=c.useState([]),[M,J]=c.useState([]),[C,q]=c.useState([]),[B,O]=c.useState(null),[V,K]=c.useState(null),[Z,te]=c.useState(0),oe=c.useMemo(()=>{const z=a?.files??[],F=new Map;for(const Y of z)F.set(Y.path,Y);return Array.from(F.values()).sort((Y,Se)=>Y.path.localeCompare(Se.path))},[a?.files]),v=c.useMemo(()=>oe.filter(Ti),[oe]),W=c.useMemo(()=>oe.filter(Ai),[oe]),ee=c.useMemo(()=>{if(C.length>0)return C;const z=a?.tracking?.includes("/")?a.tracking.split("/")[0]:null;return z||B?[{name:z||"origin",fetchUrl:B??"",pushUrl:B??""}]:[]},[B,C,a?.tracking]),se=Ae(c.useCallback(z=>!o||y.type!=="diff"?null:z.directories.get(o)?.diffCache.get(qs(y.path,y.staged))??null,[o,y])),je=c.useMemo(()=>y.type!=="diff"?null:oe.find(z=>z.path===y.path)??null,[oe,y]),le=c.useCallback(async(z=!0)=>{if(o)try{await Promise.all([m(o,i),p(o,i)])}catch(F){z&&ie.error(F instanceof Error?F.message:r("gitView.toast.refreshRepositoryFailed"))}},[o,p,m,i,r]),ce=c.useCallback(async()=>{if(!o){q([]),O(null);return}try{const[z,F]=await Promise.all([i.getRemotes(o).catch(()=>[]),i.getRemoteUrl?i.getRemoteUrl(o).catch(()=>null):Promise.resolve(null)]);q(z),O(F)}catch{q([]),O(null)}},[o,i]);c.useEffect(()=>{o&&(u(o),f(o,i))},[o,f,i,u]),c.useEffect(()=>{ce()},[ce]),c.useEffect(()=>{if(!o||oe.length===0)return;const z=Array.from(new Set([...v.map(Y=>Y.path),...M,...oe.slice(0,20).map(Y=>Y.path)])).filter(Boolean);if(z.length===0)return;const F=window.setTimeout(()=>{g(o,i,z,{maxFiles:40})},120);return()=>window.clearTimeout(F)},[oe,o,i,g,v,M]),c.useEffect(()=>{if(y.type!=="diff"){K(null);return}const z=qs(y.path,y.staged);if(!o||k(o,z)){K(null);return}let F=!1;return K(null),i.getGitFileDiff(o,{path:y.path,staged:y.staged||void 0}).then(Y=>{F||S(o,z,{original:Y.original??"",modified:Y.modified??"",isBinary:Y.isBinary})}).catch(Y=>{F||K(Y instanceof Error?Y.message:String(Y))}),()=>{F=!0}},[o,Z,k,i,y,S]);const ke=async(z,F)=>{if(o){D(z);try{const Y=Se=>{const Me=`${Se.name}/`,qe=a?.tracking?.startsWith(Me)?a.tracking.slice(Me.length):void 0;return{remote:Se.name,branch:qe,rebase:!0}};if(z==="fetch"){if(!F)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:F.name}),ie.success(r("gitView.toast.fetchedFromRemote",{name:F.name}))}else if(z==="sync"){if(!F)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:F.name});const Se=await i.getGitStatus(o);if((Se.behind??0)>0){if((Se.files?.length??0)>0){ie.error(r("gitView.toast.commitOrStashBeforeSync"));return}await i.gitPull(o,Y(F))}((await i.getGitStatus(o)).ahead??0)>0&&await i.gitPush(o),ie.success(r("gitView.toast.alreadyUpToDate"))}await le(!1),await ce()}catch(Y){ie.error(Y instanceof Error?Y.message:r("gitView.toast.syncActionFailed",{action:r("gitView.sync.syncChanges")}))}finally{D(null)}}},ae=c.useCallback(async(z,F)=>{if(!(!o||z.length===0))try{F==="stage"?z.length>1?await Gr(o,z):await Hr(o,z[0]):z.length>1?await Kr(o,z):await qr(o,z[0]),await le(!1)}catch(Y){ie.error(Y instanceof Error?Y.message:r(F==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[o,le,r]),me=c.useCallback((z,F=!1)=>{P({type:"diff",path:z,staged:F})},[]),ge=c.useCallback(async z=>{if(o){E(F=>new Set(F).add(z));try{await i.revertGitFile(o,z),ie.success(r("gitView.toast.revertedFile",{path:z})),await le(!1)}catch(F){ie.error(F instanceof Error?F.message:r("gitView.toast.revertFailed"))}finally{E(F=>{const Y=new Set(F);return Y.delete(z),Y})}}},[o,i,le,r]),Fe=c.useCallback(async z=>{if(!o||z.length===0||b)return;const F=Array.from(new Set(z));N(!0),E(new Set(F));try{await Promise.all(F.map(Y=>i.revertGitFile(o,Y))),await le(!1),ie.success(F.length===1?r("gitView.toast.revertedFilesSingle",{count:F.length}):r("gitView.toast.revertedFilesPlural",{count:F.length}))}catch(Y){ie.error(Y instanceof Error?Y.message:r("gitView.toast.revertFailed"))}finally{E(new Set),N(!1)}},[o,i,b,le,r]),De=c.useCallback(z=>{const F=z.map(Y=>Y.trim()).filter(Boolean);if(F.length===0){G([]);return}j(Y=>`${Y.trim()}${Y.trim()?`
3
3
 
4
4
  `:""}${F.join(`
5
5
  `)}`.trim()),G([])},[]),pt=c.useCallback(async()=>{if(!o)return;const z=v.map(F=>F.path).sort();if(z.length===0){ie.error(r("gitView.toast.selectFileToDescribe"));return}_(!0);try{const{message:F}=await Jr(o,z);j(F.subject?.trim()??""),G(Array.isArray(F.highlights)?F.highlights:[])}catch(F){ie.error(F instanceof Error?F.message:r("gitView.toast.generateCommitMessageFailed"))}finally{_(!1)}},[o,v,r]),$e=async(z={})=>{if(!o)return;if(!w.trim()){ie.error(r("gitView.toast.enterCommitMessage"));return}const F=v.map(Y=>Y.path).sort();if(F.length===0){ie.error(r("gitView.toast.selectFileToCommit"));return}R(z.pushAfter?"commitAndPush":"commit");try{if(await i.createGitCommit(o,w.trim(),{files:F}),ie.success(r("gitView.toast.commitCreated")),j(""),G([]),z.pushAfter){const Y=a?.tracking?.split("/")[0],Se=ee.find(xe=>xe.name===Y)??ee[0];if(!Se)throw new Error(r("mobile.changes.noRemote"));D("sync");const Me=`${Se.name}/`,qe=a?.tracking?.startsWith(Me)?a.tracking.slice(Me.length):void 0;await i.gitFetch(o,{remote:Se.name}),((await i.getGitStatus(o)).behind??0)>0&&await i.gitPull(o,{remote:Se.name,branch:qe,rebase:!0}),((await i.getGitStatus(o)).ahead??0)>0&&await i.gitPush(o),await le(!1),await ce()}else await le(!1)}catch(Y){ie.error(Y instanceof Error?Y.message:r("gitView.toast.createCommitFailed"))}finally{R(null),z.pushAfter&&D(null)}},st=c.useMemo(()=>{const z=[];return v.length>0&&z.push({id:"staged",title:r("gitView.changes.stagedTitle"),entries:v,actionSymbol:"-",actionAllLabel:r("gitView.changes.unstageAllAria"),getActionLabel:F=>r("gitView.changes.unstageFileAria",{path:F}),onActionFile:F=>{ae([F],"unstage")},onActionAll:F=>{ae(F,"unstage")},onViewDiff:F=>me(F,!0),onRevertFile:ge,showRevertActions:!1,accent:!0}),W.length>0&&z.push({id:"unstaged",title:r("gitView.changes.title"),entries:W,actionSymbol:"+",actionAllLabel:r("gitView.changes.stageAllAria"),getActionLabel:F=>r("gitView.changes.stageFileAria",{path:F}),onActionFile:F=>{ae([F],"stage")},onActionAll:F=>{ae(F,"stage")},onViewDiff:F=>me(F,!1),onRevertFile:ge}),z},[ge,me,ae,v,r,W]),Le=z=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:r("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:a?.current||o||""})]})]}),t.jsx("div",{className:"min-h-0 flex-1",children:z})]});return o?d&&l===null?Le(t.jsx(Ve,{loading:!0,message:r("gitView.loading.checkingRepository")})):l===!1?Le(t.jsx(Ve,{icon:!0,message:r("gitView.empty.notGitRepository"),description:r("gitView.empty.notGitRepositoryDescription")})):y.type==="diff"?t.jsx(Ri,{path:y.path,diff:se,fileExists:!!je,error:V,onBack:()=>P({type:"list"}),onRetry:()=>te(z=>z+1)}):t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:r("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:a?.current||o})]}),t.jsx(Go,{syncAction:I,remotes:ee,onFetch:z=>{ke("fetch",z)},onSync:z=>{ke("sync",z)},disabled:A!==null||d,aheadCount:a?.ahead??0,behindCount:a?.behind??0,trackingRemoteName:a?.tracking?.split("/")[0],hasUncommittedChanges:oe.length>0})]}),oe.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-4 pt-4",children:t.jsx(Ho,{groups:st,diffStats:a?.diffStats,revertingPaths:T,onRevertAll:Fe,isRevertingAll:b,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:J})}),t.jsx("div",{className:"shrink-0 border-t border-border/50 px-4 pb-4 pt-3",children:t.jsx(Ko,{stagedCount:v.length,commitMessage:w,onCommitMessageChange:j,generatedHighlights:L,onInsertHighlights:De,onGenerateMessage:pt,isGeneratingMessage:x,onCommit:()=>{$e({pushAfter:!1})},onCommitAndPush:()=>{$e({pushAfter:!0})},commitAction:A,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Ve,{icon:!0,message:r("gitView.empty.cleanTitle"),description:r("mobile.changes.cleanDescription")})})]}):Le(t.jsx(Ve,{message:r("gitView.empty.selectSessionOrDirectory")}))},Ve=s=>{const e=de.c(13),{message:n,description:r,loading:i,icon:o}=s,a=i===void 0?!1:i,l=o===void 0?!1:o;let d;e[0]!==a?(d=a?t.jsx(re,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=a,e[1]=d):d=e[1];let u;e[2]!==l?(u=l?t.jsx(re,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=l,e[3]=u):u=e[3];let f;e[4]!==n?(f=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:n}),e[4]=n,e[5]=f):f=e[5];let m;e[6]!==r?(m=r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r}):null,e[6]=r,e[7]=m):m=e[7];let p;return e[8]!==d||e[9]!==u||e[10]!==f||e[11]!==m?(p=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[d,u,f,m]})}),e[8]=d,e[9]=u,e[10]=f,e[11]=m,e[12]=p):p=e[12],p},Ri=s=>{const e=de.c(24),{path:n,diff:r,fileExists:i,error:o,onBack:a,onRetry:l}=s,{t:d}=ue();let u;e[0]!==n?(u=Vn(n)||"text",e[0]=n,e[1]=u):u=e[1];const f=u;let m;e[2]!==d?(m=d("header.actions.backAria"),e[2]=d,e[3]=m):m=e[3];let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(re,{name:"arrow-left",className:"size-5"}),e[4]=p):p=e[4];let g;e[5]!==a||e[6]!==m?(g=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":m,onClick:a,children:p}),e[5]=a,e[6]=m,e[7]=g):g=e[7];let k;e[8]!==n?(k=t.jsx("div",{className:"min-w-0 flex-1 px-2",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:n})}),e[8]=n,e[9]=k):k=e[9];let S;e[10]!==g||e[11]!==k?(S=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/50 px-3 text-foreground",children:[g,k]}),e[10]=g,e[11]=k,e[12]=S):S=e[12];let y;e[13]!==r||e[14]!==o||e[15]!==i||e[16]!==f||e[17]!==l||e[18]!==n||e[19]!==d?(y=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:i?o?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:d("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}),t.jsx(pe,{type:"button",size:"sm",variant:"outline",onClick:l,children:d("diffView.actions.retry")})]})}):r?r.isBinary?t.jsx(Ve,{icon:!0,message:d("diffView.binary.unavailable")}):ot(n)?t.jsx(Ve,{icon:!0,message:d("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(Ze,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(qo,{original:r.original,modified:r.modified,language:f,fileName:n,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(Ve,{loading:!0,message:d("diffView.state.loadingDiff")}):t.jsx(Ve,{icon:!0,message:d("mobile.changes.diffDetail.missingTitle"),description:d("mobile.changes.diffDetail.missingDescription")})}),e[13]=r,e[14]=o,e[15]=i,e[16]=f,e[17]=l,e[18]=n,e[19]=d,e[20]=y):y=e[20];let P;return e[21]!==S||e[22]!==y?(P=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[S,y]}),e[21]=S,e[22]=y,e[23]=P):P=e[23],P},Ys=25e4,ct=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),Ge=s=>{const e=ct(s);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},Di=s=>{const e=ct(s);if(!e||e==="/")return null;const n=e.lastIndexOf("/");return n<=0?e.startsWith("/")?"/":null:e.slice(0,n)},Mi=(s,e)=>{const n=ct(s),r=ct(e);return!r||n===r?Ge(n):n.startsWith(`${r}/`)?n.slice(r.length+1):n},_i=s=>{if(typeof s!="number"||!Number.isFinite(s)||s<0)return"";if(s<1024)return`${s} B`;const e=["KB","MB","GB"];let n=s/1024;for(const r of e){if(n<1024||r===e[e.length-1])return`${n.toFixed(n>=10?0:1)} ${r}`;n/=1024}return""},zi=s=>s.toLowerCase().endsWith(".svg")?"":zr().authenticatedAsset("/api/fs/raw",{path:s}),Li=s=>/\.(md|mdx|markdown)$/i.test(s),Oi=s=>/\.(json|jsonc)$/i.test(s),Xs=({onClose:s})=>{const{t:e}=ue(),{files:n}=Wt(),r=ct(bs()??null),[i,o]=c.useState(()=>({type:"browser",directory:r})),[a,l]=c.useState([]),[d,u]=c.useState(!1),[f,m]=c.useState(null),[p,g]=c.useState(""),[k,S]=c.useState([]),[y,P]=c.useState(!1),[I,D]=c.useState(""),[A,R]=c.useState(null),[w,j]=c.useState(!1),T=c.useRef(0);c.useEffect(()=>{r&&o(O=>O.type==="browser"&&O.directory?O:{type:"browser",directory:r})},[r]);const E=i.type==="browser"?i.directory:i.returnDirectory,b=c.useCallback(async O=>{if(!O)return;const V=T.current+1;T.current=V,u(!0),m(null);try{const K=await n.listDirectory(O);if(T.current!==V)return;l(K.entries.slice().sort((Z,te)=>Z.isDirectory!==te.isDirectory?Z.isDirectory?-1:1:Z.name.localeCompare(te.name)))}catch(K){if(T.current!==V)return;l([]),m(K instanceof Error?K.message:e("mobile.files.error.listFailed"))}finally{T.current===V&&u(!1)}},[n,e]);c.useEffect(()=>{i.type==="browser"&&b(i.directory)},[b,i]),c.useEffect(()=>{if(i.type!=="browser")return;const O=p.trim();if(!O){S([]),P(!1);return}let V=!1;const K=window.setTimeout(()=>{P(!0),n.search({directory:i.directory,query:O,maxResults:40}).then(Z=>{V||S(Z)}).catch(()=>{V||S([])}).finally(()=>{V||P(!1)})},250);return()=>{V=!0,window.clearTimeout(K)}},[n,p,i]),c.useEffect(()=>{if(i.type!=="file")return;if(D(""),R(null),ot(i.path)&&!i.path.toLowerCase().endsWith(".svg")){j(!1);return}if(!n.readFile){R(e("mobile.files.error.readUnavailable")),j(!1);return}let O=!1;return j(!0),n.readFile(i.path).then(V=>{O||D(V.content.length>Ys?`${V.content.slice(0,Ys)}
@@ -13,4 +13,4 @@ ${e("mobile.files.file.truncated")}`:V.content)}).catch(V=>{O||R(V instanceof Er
13
13
  from { opacity: 1; transform: translateY(0) scale(1); }
14
14
  to { opacity: 0; transform: translateY(-6px) scale(0.985); }
15
15
  }
16
- `}),e[52]=W):W=e[52];let ee;return e[53]!==v?(ee=t.jsxs("div",{ref:D,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[v,W]}),e[53]=v,e[54]=ee):ee=e[54],ee},Sl=s=>{const e=de.c(30),{groups:n,displayMode:r,isLoading:i,timeFormatPreference:o}=s,{t:a}=ue();let l;e[0]!==r||e[1]!==a?(l=a(r==="remaining"?"header.services.remaining":"header.services.used"),e[0]=r,e[1]=a,e[2]=l):l=e[2];const d=l;if(n.length===0)return null;let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t.jsx(re,{name:"timer",className:"size-[18px]"})}),e[3]=u):u=e[3];let f;e[4]!==a?(f=a("mobile.header.metadata.usage"),e[4]=a,e[5]=f):f=e[5];let m;e[6]!==f?(m=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:f}),e[6]=f,e[7]=m):m=e[7];let p;e[8]!==i?(p=i?t.jsx(re,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[8]=i,e[9]=p):p=e[9];let g;e[10]!==d?(g=t.jsx("span",{className:"truncate",children:d}),e[10]=d,e[11]=g):g=e[11];let k;e[12]!==p||e[13]!==g?(k=t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-center justify-end gap-1.5 typography-ui-label text-muted-foreground",children:[p,g]}),e[12]=p,e[13]=g,e[14]=k):k=e[14];let S;e[15]!==m||e[16]!==k?(S=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[u,m,k]}),e[15]=m,e[16]=k,e[17]=S):S=e[17];let y;if(e[18]!==r||e[19]!==n||e[20]!==o){let D;e[22]!==r||e[23]!==o?(D=A=>t.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-2.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(Ao,{providerId:A.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:A.providerName}),A.status&&A.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:A.status}):null]}),A.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:A.rows.map(R=>{const w=r==="remaining"?R.window.remainingPercent:R.window.usedPercent,j=Ro(R.window.valueLabel,w),T=Do(R.window.resetAt,R.window.resetAfterFormatted??R.window.resetAtFormatted,o);return t.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-3",children:[t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-baseline gap-1.5",children:[t.jsx("span",{className:"truncate typography-ui-label text-muted-foreground",children:R.subtitle?`${R.subtitle} · ${R.label}`:R.label}),T?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground/70",children:T}):null]}),t.jsx("span",{className:X("shrink-0 typography-ui-label font-semibold tabular-nums",wl(R.window)),children:j==="-"?"":j})]},R.key)})}):null,A.status&&A.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:A.status}):null]},A.providerId),e[22]=r,e[23]=o,e[24]=D):D=e[24],y=n.map(D),e[18]=r,e[19]=n,e[20]=o,e[21]=y}else y=e[21];let P;e[25]!==y?(P=t.jsx("div",{className:"space-y-1.5",children:y}),e[25]=y,e[26]=P):P=e[26];let I;return e[27]!==P||e[28]!==S?(I=t.jsxs("div",{className:"pt-2.5",children:[S,P]}),e[27]=P,e[28]=S,e[29]=I):I=e[29],I},Nl=s=>{const e=de.c(26),{open:n,onClose:r,items:i,rightOffset:o}=s,a=o===void 0?0:o,{t:l}=ue();let d,u;if(e[0]!==r||e[1]!==n?(d=()=>{if(!n)return;const D=A=>{A.key==="Escape"&&r()};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},u=[r,n],e[0]=r,e[1]=n,e[2]=d,e[3]=u):(d=e[2],u=e[3]),c.useEffect(d,u),!n)return null;let f;e[4]!==l?(f=l("mobile.menu.titleAria"),e[4]=l,e[5]=f):f=e[5];let m;e[6]!==l?(m=l("mobile.surface.closeAria"),e[6]=l,e[7]=m):m=e[7];let p;e[8]!==r||e[9]!==m?(p=t.jsx("button",{type:"button",className:"absolute inset-0 cursor-default","aria-label":m,onClick:r}),e[8]=r,e[9]=m,e[10]=p):p=e[10];const g=`${8+a}px`;let k;e[11]!==g?(k={right:g,animation:"mobile-menu-in 160ms cubic-bezier(0.32, 0.72, 0, 1)"},e[11]=g,e[12]=k):k=e[12];let S;if(e[13]!==i||e[14]!==r){let D;e[16]!==r?(D=(A,R)=>t.jsxs("button",{type:"button",role:"menuitem",className:X("flex w-full items-center gap-3 px-4 py-3 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",R>0&&"border-t border-border/30"),style:{touchAction:"manipulation"},onClick:()=>{A.onSelect(),r()},children:[A.iconNode??(A.icon?t.jsx(re,{name:A.icon,className:"size-5 shrink-0 text-muted-foreground"}):null),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:A.label}),A.badge&&A.badge>0?t.jsx("span",{className:"inline-flex size-2 shrink-0 rounded-full bg-primary","aria-hidden":!0}):null]},A.key),e[16]=r,e[17]=D):D=e[17],S=i.map(D),e[13]=i,e[14]=r,e[15]=S}else S=e[15];let y;e[18]!==k||e[19]!==S?(y=t.jsx("div",{className:"absolute top-[calc(var(--oc-safe-area-top,0px)+56px+4px)] w-[min(220px,calc(100vw-1rem))] origin-top-right overflow-hidden rounded-2xl border border-border/40 bg-background shadow-[0_18px_60px_rgb(0_0_0_/_0.35)]",role:"menu",style:k,children:S}),e[18]=k,e[19]=S,e[20]=y):y=e[20];let P;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx("style",{children:"@keyframes mobile-menu-in { from { opacity: 0; transform: translateY(-6px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }"}),e[21]=P):P=e[21];let I;return e[22]!==y||e[23]!==f||e[24]!==p?(I=t.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":f,children:[p,y,P]}),e[22]=y,e[23]=f,e[24]=p,e[25]=I):I=e[25],I},Cl=c.memo(function({open:e,onOpenChange:n,currentSessionId:r,effectiveDirectory:i,gitDirectory:o,isNewSessionDraftOpen:a,primaryLabel:l,secondaryLabel:d}){const{t:u}=ue(),{git:f}=Wt(),m=c.useRef(null),p=Co(r??"",i||void 0),g=Wn(o),k=xs(o),S=Ae(v=>v.ensureStatus),y=Ae(v=>v.fetchStatus),P=Ie(v=>v.providers),I=Ie(v=>v.currentProviderId),D=Ie(v=>v.currentModelId),A=Ie(v=>v.getModelMetadata);Ie(v=>v.modelsMetadata.size);const R=Eo(c.useCallback(v=>r?v.sessionModelSelections.get(r)??null:null,[r])),w=Je(v=>v.results),j=Je(v=>v.loadSettings),T=Je(v=>v.fetchAllQuotas),E=Je(v=>v.isLoading),b=Je(v=>v.displayMode),N=Je(v=>v.dropdownProviderIds),x=Je(v=>v.selectedModels),_=mt(v=>v.timeFormatPreference);ui(),c.useEffect(()=>{o&&S(o,f)},[S,f,o]),c.useEffect(()=>{if(o)return Po.onGitRefreshHint(v=>{Nt(v.directory)===o&&y(o,f)})},[y,f,o]),c.useEffect(()=>{j()},[j]),c.useEffect(()=>{Ws(N)},[N]),c.useEffect(()=>{!e||E||!N.some(W=>!w.some(ee=>ee.providerId===W))||T()},[N,T,E,e,w]);const G=c.useMemo(()=>{for(let v=p.length-1;v>=0;v-=1){const W=p[v];if(W.role!=="user")continue;const ee=typeof W.model?.providerID=="string"&&W.model.providerID.trim().length>0?W.model.providerID:void 0,se=typeof W.model?.modelID=="string"&&W.model.modelID.trim().length>0?W.model.modelID:void 0;if(ee&&se)return{providerID:ee,modelID:se}}return null},[p])??(R?{providerID:R.providerId,modelID:R.modelId}:null)??(I&&D?{providerID:I,modelID:D}:null),J=(G?P.find(v=>v.id===G.providerID):void 0)?.models.find(v=>v.id===G?.modelID),C=G?A(G.providerID,G.modelID):void 0,q=gl(J?.limit,"context")??C?.limit?.context??0,B=c.useMemo(()=>{for(let v=p.length-1;v>=0;v-=1){const W=p[v];if(W.role!=="assistant"||!W.tokens)continue;const ee=bt(W.tokens.input)+bt(W.tokens.output)+bt(W.tokens.reasoning)+bt(W.tokens.cache?.read)+bt(W.tokens.cache?.write);if(ee>0)return ee}return 0},[p]),O=!a&&B>0&&q>0?Math.min(B/q*100,999):null,V=O!==null?`${wn(B)}/${wn(q)}`:null,K=O===null?"":O>=90?"text-[var(--status-error)]":O>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",Z=O!==null&&V?{percentage:O,tokens:V,colorClass:K}:null,te=g===!0?k?.current?.trim()||u("gitView.branch.detachedHead"):u("common.unavailable"),oe=c.useMemo(()=>{const v=new Map(w.map(W=>[W.providerId,W]));return fi.filter(W=>N.includes(W.id)).filter(W=>v.get(W.id)?.configured===!0).map(W=>{const ee=v.get(W.id),se=[];for(const[ae,me]of Object.entries(ee?.usage?.windows??{}))se.push({key:`window-${ae}`,label:Vs(ae),window:me});const je=Object.entries(ee?.usage?.models??{}),le=x[W.id]??[],ce=le.length>0?je.filter(([ae])=>le.includes(ae)):je;for(const[ae,me]of ce){const ge=Object.entries(me.windows??{});if(ge.length===0)continue;const[Fe,De]=ge[0];se.push({key:`model-${ae}-${Fe}`,label:Vs(Fe),subtitle:mi(ae),window:De})}const ke=!ee.ok&&ee.error?ee.error:se.length===0?u("header.services.noRateLimitsReported"):null;return{providerId:W.id,providerName:W.name,rows:se,status:ke}})},[N,w,x,u]);return c.useEffect(()=>{!e||oe.length===0||Ws(oe.map(v=>v.providerId))},[e,oe]),t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex min-w-0 flex-1 items-center px-2 py-1.5 text-left",children:t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col leading-tight",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:l}),d?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:d}):null]})}),t.jsx("button",{ref:m,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":u("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>n(v=>!v),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"apps-2-ai",className:"size-5"})}),t.jsx(kl,{open:e,onClose:()=>n(!1),anchorRef:m,contextDisplay:Z,branchLabel:te,usageGroups:oe,usageDisplayMode:b,isUsageLoading:E,timeFormatPreference:_})]})}),El=({onOpenSessions:s,onOpenMenu:e,surfaceShortcuts:n})=>{const{t:r}=ue(),[i,o]=c.useState(!1),a=lt(w=>w.currentDirectory),l=be(w=>w.currentSessionId),u=be(c.useCallback(w=>l?w.getDirectoryForSession(l):null,[l]))||a,f=Nt(u)||null,m=Te(w=>w.projects),p=be(w=>w.availableWorktreesByProject),g=be(c.useCallback(w=>l?w.worktreeMetadata.get(l)??null:null,[l])),k=ko(l,u||void 0),S=be(w=>!!w.newSessionDraft?.open),y=c.useMemo(()=>{const w=Nt(u);if(!w)return r("mobile.header.noProject");const T=(g?.projectDirectory?So(m,g.projectDirectory):null)??No(m,p,w);return xl(T,w)||r("mobile.header.noProject")},[p,g?.projectDirectory,u,m,r]),I=k?.title?.trim()||(l?r("mobile.sessions.untitled"):y),D=l?y:"";c.useEffect(()=>{o(!1)},[l,u]);const A=c.useCallback(()=>{o(!1),s()},[s]),R=c.useCallback(()=>{o(!1),e()},[e]);return t.jsx(t.Fragment,{children:t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 border-b border-border/30 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.sessions.openSheetAria"),onClick:A,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"folders",className:"size-5"})}),t.jsx(Cl,{open:i,onOpenChange:o,currentSessionId:l,effectiveDirectory:u,gitDirectory:f,isNewSessionDraftOpen:S,primaryLabel:I,secondaryLabel:D}),n?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:X("flex size-10 shrink-0 items-center justify-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",n.activePanel==="files"?"bg-[var(--interactive-selection)] text-[var(--interactive-selectionForeground)]":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),"aria-label":r("mobile.menu.files"),"aria-pressed":n.activePanel==="files",onClick:n.onToggleFiles,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"file-text",className:"size-5"})}),t.jsxs("button",{type:"button",className:X("relative flex size-10 shrink-0 items-center justify-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",n.activePanel==="changes"?"bg-[var(--interactive-selection)] text-[var(--interactive-selectionForeground)]":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),"aria-label":r("mobile.menu.changes"),"aria-pressed":n.activePanel==="changes",onClick:n.onToggleChanges,style:{touchAction:"manipulation"},children:[t.jsx(re,{name:"git-branch",className:"size-5"}),n.changesDirty?t.jsx("span",{className:"absolute right-2 top-2 inline-flex size-2 rounded-full bg-primary","aria-hidden":!0}):null]})]}):null,t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.header.openMenuAria"),onClick:R,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"more-2",className:"size-5"})})]})})})},Pl=({onActiveConnectionDeleted:s})=>{const{t:e}=ue(),[n,r]=c.useState(!1),[i,o]=c.useState(!1),[a,l]=c.useState(!1),[d,u]=c.useState(!1),[f,m]=c.useState(!1),[p,g]=c.useState(!1),[k,S]=c.useState(!1),[y,P]=c.useState(!1),[I,D]=c.useState("nav"),[A,R]=c.useState(!1),[w,j]=c.useState(null),T=lt($=>$.currentDirectory),E=mt($=>$.setSettingsPage),b=it($=>$.available),N=it($=>$.runtimeType),x=c.useMemo(()=>Et(),[]),_=Rt($=>$.mcpServers),L=Rt($=>$.setMcpDraft),G=Rt($=>$.setSelectedMcp),M=oi($=>$.refresh),J=Rt($=>$.loadMcpConfigs),q=xs(Nt(T)||null)?.files?.length??0,B=c.useMemo(()=>Xn(),[]),V=wo()==="portrait",[K,Z]=c.useState(B&&!V),[te,oe]=c.useState(null),v=c.useCallback(()=>{const $=!K;$&&V&&oe(null),Z($)},[K,V]),W=c.useCallback(()=>{if(B){j(null),oe("files"),V&&Z(!1);return}o(!0)},[B,V]),ee=c.useCallback(($=null)=>{if(j($),B){oe("changes"),V&&Z(!1);return}l(!0)},[B,V]),se=c.useCallback(()=>{oe(null),j(null)},[]),je=c.useCallback($=>{if(te===$){se();return}$==="files"?W():ee()},[se,te,ee,W]),le=c.useRef("changes");te&&(le.current=te);const[ce,ke]=c.useState(!1);c.useEffect(()=>{if(!B)return;if(te){ke(!0);return}const $=window.setTimeout(()=>ke(!1),240);return()=>window.clearTimeout($)},[te,B]);const ae=te??le.current,me=yn("left","openchamber.ipad.leftSidebarWidth",dl),ge=yn("right","openchamber.ipad.rightSidebarWidth",ul),Fe=c.useMemo(()=>({openChanges:({diffPath:$,staged:xe}={})=>{ee($?{path:$,staged:xe===!0}:null)},openFiles:()=>W(),openSettings:()=>{D("nav"),S(!0)}}),[ee,W]),De=c.useCallback(()=>{l(!1),j(null)},[]),pt=c.useMemo(()=>({openSessions:()=>{B?Z(!0):r(!0)},openView:$=>{$==="files"?W():$==="mcp"?u(!0):$==="instances"?m(!0):$==="update"&&P(!0)},openChanges:({path:$,staged:xe}={})=>{ee($?{path:$,staged:xe===!0}:null)},openSettings:$=>{$&&E($),D($?"page-content":"nav"),S(!0)}}),[B,ee,W,E]);Za(pt);const $e=c.useRef(null),st=c.useRef(null),Le=c.useRef(null),z=be($=>$.currentSessionId),F=c.useCallback($=>{Le.current=$},[]);il($e,{onSwitch:F}),c.useLayoutEffect(()=>{const $=Le.current;if(Le.current=null,!$)return;const xe=st.current;if(!xe||typeof xe.animate!="function")return;xe.getAnimations().forEach(It=>It.cancel());const Ue=$==="prev"?-70:70;xe.animate([{opacity:.1,transform:`translateX(${Ue}px)`},{opacity:1,transform:"translateX(0)"}],{duration:300,easing:"cubic-bezier(0.22, 1, 0.36, 1)"})},[z]);const Y=c.useCallback(()=>A?(R(!1),!0):n?(r(!1),!0):i?(o(!1),!0):a?(De(),!0):d?(u(!1),!0):f?(m(!1),!0):k?(S(!1),!0):y?(P(!1),!0):!1,[a,De,i,f,d,A,n,k,y]);pl(Y);const Se=b&&(N==="desktop"||N==="web"),Me=c.useCallback(()=>{const $="new-mcp-server";let xe=$,Ue=1;for(;_.some(qt=>qt.name===xe);)xe=`${$}-${Ue}`,Ue+=1;L({name:xe,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),G(xe),E("mcp"),u(!1),D("page-content"),S(!0)},[_,L,G,E]),qe=c.useCallback(()=>{if(p)return;g(!0);const $=T||null,xe=new Promise(Ue=>window.setTimeout(Ue,500));Promise.all([M({directory:$,silent:!0}),J({force:!0}),xe]).finally(()=>g(!1))},[T,p,J,M]),Pt=c.useMemo(()=>{const $=[];return B||$.push({key:"files",icon:"file-text",label:e("mobile.menu.files"),onSelect:()=>W()},{key:"changes",icon:"git-branch",label:e("mobile.menu.changes"),badge:q,onSelect:()=>ee()}),$.push({key:"mcp",iconNode:t.jsx(ii,{className:"size-5 shrink-0 text-muted-foreground"}),label:e("mobile.menu.mcp"),onSelect:()=>u(!0)}),x&&$.push({key:"instances",icon:"server",label:e("mobile.menu.instances"),onSelect:()=>m(!0)}),Se&&$.push({key:"update",icon:"download",label:e("mobile.menu.update"),onSelect:()=>P(!0)}),$.push({key:"settings",icon:"settings-3",label:e("mobile.menu.settings"),onSelect:()=>{D("nav"),S(!0)}}),$},[q,B,ee,W,x,Se,e]);return t.jsx(jo,{actions:Fe,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[B?t.jsxs("aside",{ref:me.asideRef,className:X("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/50 bg-sidebar will-change-[width] motion-reduce:transition-none",!K&&"border-r-0"),style:{width:K?me.width:0,minWidth:K?me.width:0,maxWidth:K?me.width:0,"--oc-ipad-sidebar-width":`${me.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:me.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!K,"data-page-scroll-lock":"true",children:[K?t.jsx(vn,{side:"left",isResizing:me.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:me.handleProps}):null,t.jsx("div",{className:X("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",me.isResizing&&"pointer-events-none",!K&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Oe,{children:t.jsx(on,{open:!0,variant:"sidebar",onOpenChange:$=>{!$&&V&&Z(!1)}})})})]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(El,{onOpenSessions:()=>B?v():r(!0),onOpenMenu:()=>R(!0),surfaceShortcuts:B?{activePanel:te,changesDirty:q>0,onToggleFiles:()=>je("files"),onToggleChanges:()=>je("changes")}:void 0}),t.jsx("main",{ref:$e,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{ref:st,className:"h-full w-full",children:t.jsx(Oe,{children:t.jsx(ai,{})})})})]}),B?t.jsxs("aside",{ref:ge.asideRef,className:X("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/50 bg-background will-change-[width] motion-reduce:transition-none",!te&&"border-l-0"),style:{width:te?ge.width:0,minWidth:te?ge.width:0,maxWidth:te?ge.width:0,"--oc-ipad-sidebar-width":`${ge.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:ge.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!te,"data-page-scroll-lock":"true",children:[te?t.jsx(vn,{side:"right",isResizing:ge.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:ge.handleProps}):null,t.jsx("div",{className:X("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",ge.isResizing&&"pointer-events-none",!te&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:ce?t.jsx(Oe,{children:ae==="files"?t.jsx(Xs,{onClose:se}):t.jsx(Js,{onClose:se,initialDiffPath:w?.path??null,initialDiffStaged:w?.staged===!0})}):null})]}):null,t.jsx(Nl,{open:A,onClose:()=>R(!1),items:Pt,rightOffset:B&&te?ge.width:0}),n?t.jsx(on,{open:n,onOpenChange:r}):null,i?t.jsx(Ye,{open:!0,onClose:()=>o(!1),ariaLabel:e("mobile.menu.files"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(Xs,{onClose:()=>o(!1)})})}):null,a?t.jsx(Ye,{open:!0,onClose:De,ariaLabel:e("mobile.menu.changes"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(Js,{onClose:De,initialDiffPath:w?.path??null,initialDiffStaged:w?.staged===!0})})}):null,d?t.jsx(Hn,{open:!0,onClose:()=>u(!1),title:e("mcpDropdown.title"),className:"h-[72vh]",contentMaxHeightClassName:"max-h-full",renderHeader:$=>t.jsxs("div",{className:"shrink-0",children:[t.jsx("div",{className:"flex justify-center pt-2.5 pb-1",children:t.jsx("div",{className:"h-1 w-9 rounded-full bg-[color-mix(in_srgb,var(--surface-mutedForeground)_40%,transparent)]"})}),t.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 pb-2",children:[t.jsx("h2",{className:"text-[16px] font-semibold text-[var(--surface-foreground)]",children:e("mcpDropdown.title")}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{type:"button",className:"flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]",onClick:Me,"aria-label":e("settings.mcp.sidebar.actions.addServerTitle"),title:e("settings.mcp.sidebar.actions.addServerTitle"),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"add",className:"h-5 w-5"})}),t.jsx("button",{type:"button",className:"flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] disabled:opacity-60",onClick:qe,disabled:p,"aria-label":e("mcpDropdown.actions.refreshAria"),title:e("mcpDropdown.actions.refreshAria"),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"refresh",className:X("h-5 w-5",p&&"animate-spin")})}),$]})]})]}),children:t.jsx(Oe,{children:t.jsx(li,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})})}):null,f&&x?t.jsx(Ye,{open:!0,onClose:()=>m(!1),ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(vl,{onConnect:()=>m(!1),onActiveConnectionDeleted:s})}):null,k?t.jsx(Ye,{open:!0,onClose:()=>S(!1),ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(ci,{forceMobile:!0,isWindowed:!0,initialMobileStage:I,visiblePageSlugs:[...cl],onClose:()=>S(!1)})})}):null,y?t.jsx(Ye,{open:!0,onClose:()=>P(!1),ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Oe,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(di,{initialUpdateDialogOpen:!0})})})}):null]})})};function Il({apis:s}){const{t:e}=ue(),n=Ie(C=>C.initializeApp),r=Ie(C=>C.isInitialized),i=Ie(C=>C.isConnected),o=Ie(C=>C.connectionPhase),a=Ie(C=>C.providers.length),l=Ie(C=>C.agents.length),d=Ie(C=>C.loadProviders),u=Ie(C=>C.loadAgents),f=lt(C=>C.currentDirectory),m=be(C=>C.error),p=be(C=>C.clearError),g=mt(C=>C.setIsMobile),k=lo(C=>C.refreshStatus),S=co(C=>C.setPlanModeEnabled),y=Te(C=>C.projects),[P,I]=c.useState(0),[D,A]=c.useState(0),[R,w]=c.useState(!1),[j,T]=c.useState("pending"),E=c.useMemo(()=>Pa(),[]),[,b]=c.useReducer(C=>C+1,0),N=c.useMemo(()=>Et(),[]),x=c.useRef(0),_=c.useRef(0),L=c.useCallback(()=>{const C=We(),q=_.current+1;if(_.current=q,!C){fn();return}const B=()=>{n(),k(s.github,{force:!0}),a===0&&d({source:"mobileApp:nativeResume"}),l===0&&u({source:"mobileApp:nativeResume"})},O=()=>{jt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),I(K=>K+1)};us().then(K=>{if(_.current===q){if(K==="no-connection"){O();return}if(K==="unreachable"){window.setTimeout(()=>{_.current===q&&us().then(Z=>{if(_.current===q&&Z!=="switched"){if(Z==="unchanged"){B();return}O()}})},4e3);return}K!=="switched"&&B()}});const V=Date.now();V-x.current>=bl&&(x.current=V,window.dispatchEvent(new Event("openchamber:system-resume")))},[l,s.github,n,u,d,a,k]);ml(),hl(L),c.useEffect(()=>{if(!N)return;let C;const q=()=>{window.clearTimeout(C),C=window.setTimeout(()=>L(),1500)};return window.addEventListener("online",q),()=>{window.removeEventListener("online",q),window.clearTimeout(C)}},[N,L]),c.useEffect(()=>(Os(s),()=>Os(null)),[s]),c.useEffect(()=>Br(C=>{if(!!C.runtimeKey&&C.runtimeKey===C.previousRuntimeKey){Zo(),b();return}ei(C),A(B=>B+1),I(B=>B+1)}),[]),c.useEffect(()=>{if(!N||i||We()){T("done");return}let C=!1;return T("attempting"),fn().catch(()=>!1).then(()=>{C||T("done")}),()=>{C=!0}},[]),c.useEffect(()=>{g(!0)},[g]),c.useEffect(()=>{N&&!We()||n()},[P,n,N]),c.useEffect(()=>{i&&(a===0&&d({source:"mobileApp:recovery"}),l===0&&u({source:"mobileApp:recovery"}))},[l,i,u,d,a]),c.useEffect(()=>{i&&Bs.setDirectory(f)},[f,i]),c.useEffect(()=>{i&&k(s.github,{force:!0})},[s.github,i,k]),c.useEffect(()=>{if(!i||y.length===0)return;let C=!1;return(async()=>{const B=new Map(be.getState().availableWorktreesByProject);if(await Promise.all(y.map(async K=>{const Z=K.path.replace(/\\/g,"/").replace(/\/+$/,"");if(Z)try{if(!(Ae.getState().directories.get(Z)?.isGitRepo??await ze(()=>import("./useAppFontEffects-DkPuAMXD.js").then(W=>W.fc),__vite__mapDeps([0,1,2,3])).then(W=>W.checkIsGitRepository(Z))))return;const v=await Yn({id:K.id,path:Z});if(C)return;B.set(Z,v)}catch{}})),C)return;const O=Array.from(B.values()).flat(),V=be.getState().availableWorktreesByProject;vo(B,V)||be.setState({availableWorktrees:O,availableWorktreesByProject:B})})(),()=>{C=!0}},[i,y]),c.useEffect(()=>{let C=!1;return(async()=>{const B=await gs("/health",{method:"GET"}).catch(()=>null);if(!B||!B.ok||C)return;const O=await B.json().catch(()=>null);if(!O||C)return;const V=O.planModeExperimentalEnabled;S(V===!0||V===1||V==="1"||V==="true")})(),()=>{C=!0}},[S]),c.useEffect(()=>{if(!m)return;const C=window.setTimeout(()=>p(),5e3);return()=>window.clearTimeout(C)},[p,m]),c.useEffect(()=>{if(!(!i&&(N?!!We():!0))){w(!1);return}const q=window.setTimeout(()=>w(!0),8e3);return()=>window.clearTimeout(q)},[i,N,P,D]),uo(),fo({enabled:!0}),ti(),mo(),si(),ll({enabled:N&&i}),el({ready:N&&i&&r});const G=$a(),M=!i&&o==="reconnecting";if(!G)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(xt,{width:120,height:120,isAnimated:!0})});const J=!!We();return N&&(!J||!i&&!M)?J?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(xt,{width:120,height:120,isAnimated:!R}),R?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]}),t.jsx(pe,{type:"button",variant:"outline",onClick:()=>{jt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),I(C=>C+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):j!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(xt,{width:120,height:120,isAnimated:!0}),E?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:e("mobile.connect.splash.connectingTo")}),t.jsxs("p",{className:"typography-small text-foreground",children:[E,t.jsx(ho,{})]})]}):null]}):t.jsx(yl,{onConnected:()=>I(C=>C+1)}):!i&&!M?R?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(xt,{width:120,height:120,isAnimated:!0})}):t.jsx(Oe,{children:t.jsx(po,{sdk:Bs.getSdkClient(),directory:f||"",children:t.jsx(go,{apis:s,children:t.jsx(bo,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[t.jsx(xo,{embeddedBackgroundWorkEnabled:r}),t.jsx(ni,{}),t.jsx(Si,{}),t.jsx(Pl,{onActiveConnectionDeleted:()=>{jt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),I(C=>C+1)}}),t.jsx(yo,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),r?t.jsx(ri,{}):null]})})})},D)})}const Tl=()=>{Fo(),Fr().then(()=>{Promise.all([$r(),$o()]).catch(s=>{console.error("[mobile-main] settings init failed:",s)}),Uo(),Wo(),Vo()}).catch(s=>{console.error("[mobile-main] appearance init failed:",s)}).finally(()=>{gi()})};function Ol(s){Mo(),Tl(),ki(),_o();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const r=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",i=r?{...s,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:s,o=t.jsx(Il,{apis:i});_r.createRoot(e).render(t.jsx(rs.StrictMode,{children:t.jsx(zo,{children:t.jsx(Lo,{children:t.jsx(Oo,{children:t.jsx(hi,{children:r?o:t.jsx(Bo,{children:o})})})})})}))}export{Ol as renderMobileApp};
16
+ `}),e[52]=W):W=e[52];let ee;return e[53]!==v?(ee=t.jsxs("div",{ref:D,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[v,W]}),e[53]=v,e[54]=ee):ee=e[54],ee},Sl=s=>{const e=de.c(30),{groups:n,displayMode:r,isLoading:i,timeFormatPreference:o}=s,{t:a}=ue();let l;e[0]!==r||e[1]!==a?(l=a(r==="remaining"?"header.services.remaining":"header.services.used"),e[0]=r,e[1]=a,e[2]=l):l=e[2];const d=l;if(n.length===0)return null;let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t.jsx(re,{name:"timer",className:"size-[18px]"})}),e[3]=u):u=e[3];let f;e[4]!==a?(f=a("mobile.header.metadata.usage"),e[4]=a,e[5]=f):f=e[5];let m;e[6]!==f?(m=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:f}),e[6]=f,e[7]=m):m=e[7];let p;e[8]!==i?(p=i?t.jsx(re,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[8]=i,e[9]=p):p=e[9];let g;e[10]!==d?(g=t.jsx("span",{className:"truncate",children:d}),e[10]=d,e[11]=g):g=e[11];let k;e[12]!==p||e[13]!==g?(k=t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-center justify-end gap-1.5 typography-ui-label text-muted-foreground",children:[p,g]}),e[12]=p,e[13]=g,e[14]=k):k=e[14];let S;e[15]!==m||e[16]!==k?(S=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[u,m,k]}),e[15]=m,e[16]=k,e[17]=S):S=e[17];let y;if(e[18]!==r||e[19]!==n||e[20]!==o){let D;e[22]!==r||e[23]!==o?(D=A=>t.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-2.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(Ao,{providerId:A.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:A.providerName}),A.status&&A.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:A.status}):null]}),A.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:A.rows.map(R=>{const w=r==="remaining"?R.window.remainingPercent:R.window.usedPercent,j=Ro(R.window.valueLabel,w),T=Do(R.window.resetAt,R.window.resetAfterFormatted??R.window.resetAtFormatted,o);return t.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-3",children:[t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-baseline gap-1.5",children:[t.jsx("span",{className:"truncate typography-ui-label text-muted-foreground",children:R.subtitle?`${R.subtitle} · ${R.label}`:R.label}),T?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground/70",children:T}):null]}),t.jsx("span",{className:X("shrink-0 typography-ui-label font-semibold tabular-nums",wl(R.window)),children:j==="-"?"":j})]},R.key)})}):null,A.status&&A.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:A.status}):null]},A.providerId),e[22]=r,e[23]=o,e[24]=D):D=e[24],y=n.map(D),e[18]=r,e[19]=n,e[20]=o,e[21]=y}else y=e[21];let P;e[25]!==y?(P=t.jsx("div",{className:"space-y-1.5",children:y}),e[25]=y,e[26]=P):P=e[26];let I;return e[27]!==P||e[28]!==S?(I=t.jsxs("div",{className:"pt-2.5",children:[S,P]}),e[27]=P,e[28]=S,e[29]=I):I=e[29],I},Nl=s=>{const e=de.c(26),{open:n,onClose:r,items:i,rightOffset:o}=s,a=o===void 0?0:o,{t:l}=ue();let d,u;if(e[0]!==r||e[1]!==n?(d=()=>{if(!n)return;const D=A=>{A.key==="Escape"&&r()};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},u=[r,n],e[0]=r,e[1]=n,e[2]=d,e[3]=u):(d=e[2],u=e[3]),c.useEffect(d,u),!n)return null;let f;e[4]!==l?(f=l("mobile.menu.titleAria"),e[4]=l,e[5]=f):f=e[5];let m;e[6]!==l?(m=l("mobile.surface.closeAria"),e[6]=l,e[7]=m):m=e[7];let p;e[8]!==r||e[9]!==m?(p=t.jsx("button",{type:"button",className:"absolute inset-0 cursor-default","aria-label":m,onClick:r}),e[8]=r,e[9]=m,e[10]=p):p=e[10];const g=`${8+a}px`;let k;e[11]!==g?(k={right:g,animation:"mobile-menu-in 160ms cubic-bezier(0.32, 0.72, 0, 1)"},e[11]=g,e[12]=k):k=e[12];let S;if(e[13]!==i||e[14]!==r){let D;e[16]!==r?(D=(A,R)=>t.jsxs("button",{type:"button",role:"menuitem",className:X("flex w-full items-center gap-3 px-4 py-3 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",R>0&&"border-t border-border/30"),style:{touchAction:"manipulation"},onClick:()=>{A.onSelect(),r()},children:[A.iconNode??(A.icon?t.jsx(re,{name:A.icon,className:"size-5 shrink-0 text-muted-foreground"}):null),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:A.label}),A.badge&&A.badge>0?t.jsx("span",{className:"inline-flex size-2 shrink-0 rounded-full bg-primary","aria-hidden":!0}):null]},A.key),e[16]=r,e[17]=D):D=e[17],S=i.map(D),e[13]=i,e[14]=r,e[15]=S}else S=e[15];let y;e[18]!==k||e[19]!==S?(y=t.jsx("div",{className:"absolute top-[calc(var(--oc-safe-area-top,0px)+56px+4px)] w-[min(220px,calc(100vw-1rem))] origin-top-right overflow-hidden rounded-2xl border border-border/40 bg-background shadow-[0_18px_60px_rgb(0_0_0_/_0.35)]",role:"menu",style:k,children:S}),e[18]=k,e[19]=S,e[20]=y):y=e[20];let P;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx("style",{children:"@keyframes mobile-menu-in { from { opacity: 0; transform: translateY(-6px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }"}),e[21]=P):P=e[21];let I;return e[22]!==y||e[23]!==f||e[24]!==p?(I=t.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":f,children:[p,y,P]}),e[22]=y,e[23]=f,e[24]=p,e[25]=I):I=e[25],I},Cl=c.memo(function({open:e,onOpenChange:n,currentSessionId:r,effectiveDirectory:i,gitDirectory:o,isNewSessionDraftOpen:a,primaryLabel:l,secondaryLabel:d}){const{t:u}=ue(),{git:f}=Wt(),m=c.useRef(null),p=Co(r??"",i||void 0),g=Wn(o),k=xs(o),S=Ae(v=>v.ensureStatus),y=Ae(v=>v.fetchStatus),P=Ie(v=>v.providers),I=Ie(v=>v.currentProviderId),D=Ie(v=>v.currentModelId),A=Ie(v=>v.getModelMetadata);Ie(v=>v.modelsMetadata.size);const R=Eo(c.useCallback(v=>r?v.sessionModelSelections.get(r)??null:null,[r])),w=Je(v=>v.results),j=Je(v=>v.loadSettings),T=Je(v=>v.fetchAllQuotas),E=Je(v=>v.isLoading),b=Je(v=>v.displayMode),N=Je(v=>v.dropdownProviderIds),x=Je(v=>v.selectedModels),_=mt(v=>v.timeFormatPreference);ui(),c.useEffect(()=>{o&&S(o,f)},[S,f,o]),c.useEffect(()=>{if(o)return Po.onGitRefreshHint(v=>{Nt(v.directory)===o&&y(o,f)})},[y,f,o]),c.useEffect(()=>{j()},[j]),c.useEffect(()=>{Ws(N)},[N]),c.useEffect(()=>{!e||E||!N.some(W=>!w.some(ee=>ee.providerId===W))||T()},[N,T,E,e,w]);const G=c.useMemo(()=>{for(let v=p.length-1;v>=0;v-=1){const W=p[v];if(W.role!=="user")continue;const ee=typeof W.model?.providerID=="string"&&W.model.providerID.trim().length>0?W.model.providerID:void 0,se=typeof W.model?.modelID=="string"&&W.model.modelID.trim().length>0?W.model.modelID:void 0;if(ee&&se)return{providerID:ee,modelID:se}}return null},[p])??(R?{providerID:R.providerId,modelID:R.modelId}:null)??(I&&D?{providerID:I,modelID:D}:null),J=(G?P.find(v=>v.id===G.providerID):void 0)?.models.find(v=>v.id===G?.modelID),C=G?A(G.providerID,G.modelID):void 0,q=gl(J?.limit,"context")??C?.limit?.context??0,B=c.useMemo(()=>{for(let v=p.length-1;v>=0;v-=1){const W=p[v];if(W.role!=="assistant"||!W.tokens)continue;const ee=bt(W.tokens.input)+bt(W.tokens.output)+bt(W.tokens.reasoning)+bt(W.tokens.cache?.read)+bt(W.tokens.cache?.write);if(ee>0)return ee}return 0},[p]),O=!a&&B>0&&q>0?Math.min(B/q*100,999):null,V=O!==null?`${wn(B)}/${wn(q)}`:null,K=O===null?"":O>=90?"text-[var(--status-error)]":O>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",Z=O!==null&&V?{percentage:O,tokens:V,colorClass:K}:null,te=g===!0?k?.current?.trim()||u("gitView.branch.detachedHead"):u("common.unavailable"),oe=c.useMemo(()=>{const v=new Map(w.map(W=>[W.providerId,W]));return fi.filter(W=>N.includes(W.id)).filter(W=>v.get(W.id)?.configured===!0).map(W=>{const ee=v.get(W.id),se=[];for(const[ae,me]of Object.entries(ee?.usage?.windows??{}))se.push({key:`window-${ae}`,label:Vs(ae),window:me});const je=Object.entries(ee?.usage?.models??{}),le=x[W.id]??[],ce=le.length>0?je.filter(([ae])=>le.includes(ae)):je;for(const[ae,me]of ce){const ge=Object.entries(me.windows??{});if(ge.length===0)continue;const[Fe,De]=ge[0];se.push({key:`model-${ae}-${Fe}`,label:Vs(Fe),subtitle:mi(ae),window:De})}const ke=!ee.ok&&ee.error?ee.error:se.length===0?u("header.services.noRateLimitsReported"):null;return{providerId:W.id,providerName:W.name,rows:se,status:ke}})},[N,w,x,u]);return c.useEffect(()=>{!e||oe.length===0||Ws(oe.map(v=>v.providerId))},[e,oe]),t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex min-w-0 flex-1 items-center px-2 py-1.5 text-left",children:t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col leading-tight",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:l}),d?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:d}):null]})}),t.jsx("button",{ref:m,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":u("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>n(v=>!v),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"apps-2-ai",className:"size-5"})}),t.jsx(kl,{open:e,onClose:()=>n(!1),anchorRef:m,contextDisplay:Z,branchLabel:te,usageGroups:oe,usageDisplayMode:b,isUsageLoading:E,timeFormatPreference:_})]})}),El=({onOpenSessions:s,onOpenMenu:e,surfaceShortcuts:n})=>{const{t:r}=ue(),[i,o]=c.useState(!1),a=lt(w=>w.currentDirectory),l=be(w=>w.currentSessionId),u=be(c.useCallback(w=>l?w.getDirectoryForSession(l):null,[l]))||a,f=Nt(u)||null,m=Te(w=>w.projects),p=be(w=>w.availableWorktreesByProject),g=be(c.useCallback(w=>l?w.worktreeMetadata.get(l)??null:null,[l])),k=ko(l,u||void 0),S=be(w=>!!w.newSessionDraft?.open),y=c.useMemo(()=>{const w=Nt(u);if(!w)return r("mobile.header.noProject");const T=(g?.projectDirectory?So(m,g.projectDirectory):null)??No(m,p,w);return xl(T,w)||r("mobile.header.noProject")},[p,g?.projectDirectory,u,m,r]),I=k?.title?.trim()||(l?r("mobile.sessions.untitled"):y),D=l?y:"";c.useEffect(()=>{o(!1)},[l,u]);const A=c.useCallback(()=>{o(!1),s()},[s]),R=c.useCallback(()=>{o(!1),e()},[e]);return t.jsx(t.Fragment,{children:t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 border-b border-border/30 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.sessions.openSheetAria"),onClick:A,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"folders",className:"size-5"})}),t.jsx(Cl,{open:i,onOpenChange:o,currentSessionId:l,effectiveDirectory:u,gitDirectory:f,isNewSessionDraftOpen:S,primaryLabel:I,secondaryLabel:D}),n?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:X("flex size-10 shrink-0 items-center justify-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",n.activePanel==="files"?"bg-[var(--interactive-selection)] text-[var(--interactive-selectionForeground)]":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),"aria-label":r("mobile.menu.files"),"aria-pressed":n.activePanel==="files",onClick:n.onToggleFiles,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"file-text",className:"size-5"})}),t.jsxs("button",{type:"button",className:X("relative flex size-10 shrink-0 items-center justify-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",n.activePanel==="changes"?"bg-[var(--interactive-selection)] text-[var(--interactive-selectionForeground)]":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),"aria-label":r("mobile.menu.changes"),"aria-pressed":n.activePanel==="changes",onClick:n.onToggleChanges,style:{touchAction:"manipulation"},children:[t.jsx(re,{name:"git-branch",className:"size-5"}),n.changesDirty?t.jsx("span",{className:"absolute right-2 top-2 inline-flex size-2 rounded-full bg-primary","aria-hidden":!0}):null]})]}):null,t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.header.openMenuAria"),onClick:R,style:{touchAction:"manipulation"},children:t.jsx(re,{name:"more-2",className:"size-5"})})]})})})},Pl=({onActiveConnectionDeleted:s})=>{const{t:e}=ue(),[n,r]=c.useState(!1),[i,o]=c.useState(!1),[a,l]=c.useState(!1),[d,u]=c.useState(!1),[f,m]=c.useState(!1),[p,g]=c.useState(!1),[k,S]=c.useState(!1),[y,P]=c.useState(!1),[I,D]=c.useState("nav"),[A,R]=c.useState(!1),[w,j]=c.useState(null),T=lt($=>$.currentDirectory),E=mt($=>$.setSettingsPage),b=it($=>$.available),N=it($=>$.runtimeType),x=c.useMemo(()=>Et(),[]),_=Rt($=>$.mcpServers),L=Rt($=>$.setMcpDraft),G=Rt($=>$.setSelectedMcp),M=oi($=>$.refresh),J=Rt($=>$.loadMcpConfigs),q=xs(Nt(T)||null)?.files?.length??0,B=c.useMemo(()=>Xn(),[]),V=wo()==="portrait",[K,Z]=c.useState(B&&!V),[te,oe]=c.useState(null),v=c.useCallback(()=>{const $=!K;$&&V&&oe(null),Z($)},[K,V]),W=c.useCallback(()=>{if(B){j(null),oe("files"),V&&Z(!1);return}o(!0)},[B,V]),ee=c.useCallback(($=null)=>{if(j($),B){oe("changes"),V&&Z(!1);return}l(!0)},[B,V]),se=c.useCallback(()=>{oe(null),j(null)},[]),je=c.useCallback($=>{if(te===$){se();return}$==="files"?W():ee()},[se,te,ee,W]),le=c.useRef("changes");te&&(le.current=te);const[ce,ke]=c.useState(!1);c.useEffect(()=>{if(!B)return;if(te){ke(!0);return}const $=window.setTimeout(()=>ke(!1),240);return()=>window.clearTimeout($)},[te,B]);const ae=te??le.current,me=yn("left","openchamber.ipad.leftSidebarWidth",dl),ge=yn("right","openchamber.ipad.rightSidebarWidth",ul),Fe=c.useMemo(()=>({openChanges:({diffPath:$,staged:xe}={})=>{ee($?{path:$,staged:xe===!0}:null)},openFiles:()=>W(),openSettings:()=>{D("nav"),S(!0)}}),[ee,W]),De=c.useCallback(()=>{l(!1),j(null)},[]),pt=c.useMemo(()=>({openSessions:()=>{B?Z(!0):r(!0)},openView:$=>{$==="files"?W():$==="mcp"?u(!0):$==="instances"?m(!0):$==="update"&&P(!0)},openChanges:({path:$,staged:xe}={})=>{ee($?{path:$,staged:xe===!0}:null)},openSettings:$=>{$&&E($),D($?"page-content":"nav"),S(!0)}}),[B,ee,W,E]);Za(pt);const $e=c.useRef(null),st=c.useRef(null),Le=c.useRef(null),z=be($=>$.currentSessionId),F=c.useCallback($=>{Le.current=$},[]);il($e,{onSwitch:F}),c.useLayoutEffect(()=>{const $=Le.current;if(Le.current=null,!$)return;const xe=st.current;if(!xe||typeof xe.animate!="function")return;xe.getAnimations().forEach(It=>It.cancel());const Ue=$==="prev"?-70:70;xe.animate([{opacity:.1,transform:`translateX(${Ue}px)`},{opacity:1,transform:"translateX(0)"}],{duration:300,easing:"cubic-bezier(0.22, 1, 0.36, 1)"})},[z]);const Y=c.useCallback(()=>A?(R(!1),!0):n?(r(!1),!0):i?(o(!1),!0):a?(De(),!0):d?(u(!1),!0):f?(m(!1),!0):k?(S(!1),!0):y?(P(!1),!0):!1,[a,De,i,f,d,A,n,k,y]);pl(Y);const Se=b&&(N==="desktop"||N==="web"),Me=c.useCallback(()=>{const $="new-mcp-server";let xe=$,Ue=1;for(;_.some(qt=>qt.name===xe);)xe=`${$}-${Ue}`,Ue+=1;L({name:xe,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),G(xe),E("mcp"),u(!1),D("page-content"),S(!0)},[_,L,G,E]),qe=c.useCallback(()=>{if(p)return;g(!0);const $=T||null,xe=new Promise(Ue=>window.setTimeout(Ue,500));Promise.all([M({directory:$,silent:!0}),J({force:!0}),xe]).finally(()=>g(!1))},[T,p,J,M]),Pt=c.useMemo(()=>{const $=[];return B||$.push({key:"files",icon:"file-text",label:e("mobile.menu.files"),onSelect:()=>W()},{key:"changes",icon:"git-branch",label:e("mobile.menu.changes"),badge:q,onSelect:()=>ee()}),$.push({key:"mcp",iconNode:t.jsx(ii,{className:"size-5 shrink-0 text-muted-foreground"}),label:e("mobile.menu.mcp"),onSelect:()=>u(!0)}),x&&$.push({key:"instances",icon:"server",label:e("mobile.menu.instances"),onSelect:()=>m(!0)}),Se&&$.push({key:"update",icon:"download",label:e("mobile.menu.update"),onSelect:()=>P(!0)}),$.push({key:"settings",icon:"settings-3",label:e("mobile.menu.settings"),onSelect:()=>{D("nav"),S(!0)}}),$},[q,B,ee,W,x,Se,e]);return t.jsx(jo,{actions:Fe,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[B?t.jsxs("aside",{ref:me.asideRef,className:X("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/50 bg-sidebar will-change-[width] motion-reduce:transition-none",!K&&"border-r-0"),style:{width:K?me.width:0,minWidth:K?me.width:0,maxWidth:K?me.width:0,"--oc-ipad-sidebar-width":`${me.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:me.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!K,"data-page-scroll-lock":"true",children:[K?t.jsx(vn,{side:"left",isResizing:me.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:me.handleProps}):null,t.jsx("div",{className:X("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",me.isResizing&&"pointer-events-none",!K&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Oe,{children:t.jsx(on,{open:!0,variant:"sidebar",onOpenChange:$=>{!$&&V&&Z(!1)}})})})]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(El,{onOpenSessions:()=>B?v():r(!0),onOpenMenu:()=>R(!0),surfaceShortcuts:B?{activePanel:te,changesDirty:q>0,onToggleFiles:()=>je("files"),onToggleChanges:()=>je("changes")}:void 0}),t.jsx("main",{ref:$e,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{ref:st,className:"h-full w-full",children:t.jsx(Oe,{children:t.jsx(ai,{})})})})]}),B?t.jsxs("aside",{ref:ge.asideRef,className:X("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/50 bg-background will-change-[width] motion-reduce:transition-none",!te&&"border-l-0"),style:{width:te?ge.width:0,minWidth:te?ge.width:0,maxWidth:te?ge.width:0,"--oc-ipad-sidebar-width":`${ge.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:ge.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!te,"data-page-scroll-lock":"true",children:[te?t.jsx(vn,{side:"right",isResizing:ge.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:ge.handleProps}):null,t.jsx("div",{className:X("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",ge.isResizing&&"pointer-events-none",!te&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:ce?t.jsx(Oe,{children:ae==="files"?t.jsx(Xs,{onClose:se}):t.jsx(Js,{onClose:se,initialDiffPath:w?.path??null,initialDiffStaged:w?.staged===!0})}):null})]}):null,t.jsx(Nl,{open:A,onClose:()=>R(!1),items:Pt,rightOffset:B&&te?ge.width:0}),n?t.jsx(on,{open:n,onOpenChange:r}):null,i?t.jsx(Ye,{open:!0,onClose:()=>o(!1),ariaLabel:e("mobile.menu.files"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(Xs,{onClose:()=>o(!1)})})}):null,a?t.jsx(Ye,{open:!0,onClose:De,ariaLabel:e("mobile.menu.changes"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(Js,{onClose:De,initialDiffPath:w?.path??null,initialDiffStaged:w?.staged===!0})})}):null,d?t.jsx(Hn,{open:!0,onClose:()=>u(!1),title:e("mcpDropdown.title"),className:"h-[72vh]",contentMaxHeightClassName:"max-h-full",renderHeader:$=>t.jsxs("div",{className:"shrink-0",children:[t.jsx("div",{className:"flex justify-center pt-2.5 pb-1",children:t.jsx("div",{className:"h-1 w-9 rounded-full bg-[color-mix(in_srgb,var(--surface-mutedForeground)_40%,transparent)]"})}),t.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 pb-2",children:[t.jsx("h2",{className:"text-[16px] font-semibold text-[var(--surface-foreground)]",children:e("mcpDropdown.title")}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{type:"button",className:"flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]",onClick:Me,"aria-label":e("settings.mcp.sidebar.actions.addServerTitle"),title:e("settings.mcp.sidebar.actions.addServerTitle"),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"add",className:"h-5 w-5"})}),t.jsx("button",{type:"button",className:"flex size-8 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] disabled:opacity-60",onClick:qe,disabled:p,"aria-label":e("mcpDropdown.actions.refreshAria"),title:e("mcpDropdown.actions.refreshAria"),style:{touchAction:"manipulation"},children:t.jsx(re,{name:"refresh",className:X("h-5 w-5",p&&"animate-spin")})}),$]})]})]}),children:t.jsx(Oe,{children:t.jsx(li,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})})}):null,f&&x?t.jsx(Ye,{open:!0,onClose:()=>m(!1),ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(vl,{onConnect:()=>m(!1),onActiveConnectionDeleted:s})}):null,k?t.jsx(Ye,{open:!0,onClose:()=>S(!1),ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(ci,{forceMobile:!0,isWindowed:!0,initialMobileStage:I,visiblePageSlugs:[...cl],onClose:()=>S(!1)})})}):null,y?t.jsx(Ye,{open:!0,onClose:()=>P(!1),ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Oe,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(di,{initialUpdateDialogOpen:!0})})})}):null]})})};function Il({apis:s}){const{t:e}=ue(),n=Ie(C=>C.initializeApp),r=Ie(C=>C.isInitialized),i=Ie(C=>C.isConnected),o=Ie(C=>C.connectionPhase),a=Ie(C=>C.providers.length),l=Ie(C=>C.agents.length),d=Ie(C=>C.loadProviders),u=Ie(C=>C.loadAgents),f=lt(C=>C.currentDirectory),m=be(C=>C.error),p=be(C=>C.clearError),g=mt(C=>C.setIsMobile),k=lo(C=>C.refreshStatus),S=co(C=>C.setPlanModeEnabled),y=Te(C=>C.projects),[P,I]=c.useState(0),[D,A]=c.useState(0),[R,w]=c.useState(!1),[j,T]=c.useState("pending"),E=c.useMemo(()=>Pa(),[]),[,b]=c.useReducer(C=>C+1,0),N=c.useMemo(()=>Et(),[]),x=c.useRef(0),_=c.useRef(0),L=c.useCallback(()=>{const C=We(),q=_.current+1;if(_.current=q,!C){fn();return}const B=()=>{n(),k(s.github,{force:!0}),a===0&&d({source:"mobileApp:nativeResume"}),l===0&&u({source:"mobileApp:nativeResume"})},O=()=>{jt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),I(K=>K+1)};us().then(K=>{if(_.current===q){if(K==="no-connection"){O();return}if(K==="unreachable"){window.setTimeout(()=>{_.current===q&&us().then(Z=>{if(_.current===q&&Z!=="switched"){if(Z==="unchanged"){B();return}O()}})},4e3);return}K!=="switched"&&B()}});const V=Date.now();V-x.current>=bl&&(x.current=V,window.dispatchEvent(new Event("openchamber:system-resume")))},[l,s.github,n,u,d,a,k]);ml(),hl(L),c.useEffect(()=>{if(!N)return;let C;const q=()=>{window.clearTimeout(C),C=window.setTimeout(()=>L(),1500)};return window.addEventListener("online",q),()=>{window.removeEventListener("online",q),window.clearTimeout(C)}},[N,L]),c.useEffect(()=>(Os(s),()=>Os(null)),[s]),c.useEffect(()=>Br(C=>{if(!!C.runtimeKey&&C.runtimeKey===C.previousRuntimeKey){Zo(),b();return}ei(C),A(B=>B+1),I(B=>B+1)}),[]),c.useEffect(()=>{if(!N||i||We()){T("done");return}let C=!1;return T("attempting"),fn().catch(()=>!1).then(()=>{C||T("done")}),()=>{C=!0}},[]),c.useEffect(()=>{g(!0)},[g]),c.useEffect(()=>{N&&!We()||n()},[P,n,N]),c.useEffect(()=>{i&&(a===0&&d({source:"mobileApp:recovery"}),l===0&&u({source:"mobileApp:recovery"}))},[l,i,u,d,a]),c.useEffect(()=>{i&&Bs.setDirectory(f)},[f,i]),c.useEffect(()=>{i&&k(s.github,{force:!0})},[s.github,i,k]),c.useEffect(()=>{if(!i||y.length===0)return;let C=!1;return(async()=>{const B=new Map(be.getState().availableWorktreesByProject);if(await Promise.all(y.map(async K=>{const Z=K.path.replace(/\\/g,"/").replace(/\/+$/,"");if(Z)try{if(!(Ae.getState().directories.get(Z)?.isGitRepo??await ze(()=>import("./useAppFontEffects-9LFMCKYW.js").then(W=>W.fe),__vite__mapDeps([0,1,2,3])).then(W=>W.checkIsGitRepository(Z))))return;const v=await Yn({id:K.id,path:Z});if(C)return;B.set(Z,v)}catch{}})),C)return;const O=Array.from(B.values()).flat(),V=be.getState().availableWorktreesByProject;vo(B,V)||be.setState({availableWorktrees:O,availableWorktreesByProject:B})})(),()=>{C=!0}},[i,y]),c.useEffect(()=>{let C=!1;return(async()=>{const B=await gs("/health",{method:"GET"}).catch(()=>null);if(!B||!B.ok||C)return;const O=await B.json().catch(()=>null);if(!O||C)return;const V=O.planModeExperimentalEnabled;S(V===!0||V===1||V==="1"||V==="true")})(),()=>{C=!0}},[S]),c.useEffect(()=>{if(!m)return;const C=window.setTimeout(()=>p(),5e3);return()=>window.clearTimeout(C)},[p,m]),c.useEffect(()=>{if(!(!i&&(N?!!We():!0))){w(!1);return}const q=window.setTimeout(()=>w(!0),8e3);return()=>window.clearTimeout(q)},[i,N,P,D]),uo(),fo({enabled:!0}),ti(),mo(),si(),ll({enabled:N&&i}),el({ready:N&&i&&r});const G=$a(),M=!i&&o==="reconnecting";if(!G)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(xt,{width:120,height:120,isAnimated:!0})});const J=!!We();return N&&(!J||!i&&!M)?J?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(xt,{width:120,height:120,isAnimated:!R}),R?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]}),t.jsx(pe,{type:"button",variant:"outline",onClick:()=>{jt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),I(C=>C+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):j!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(xt,{width:120,height:120,isAnimated:!0}),E?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:e("mobile.connect.splash.connectingTo")}),t.jsxs("p",{className:"typography-small text-foreground",children:[E,t.jsx(ho,{})]})]}):null]}):t.jsx(yl,{onConnected:()=>I(C=>C+1)}):!i&&!M?R?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(xt,{width:120,height:120,isAnimated:!0})}):t.jsx(Oe,{children:t.jsx(po,{sdk:Bs.getSdkClient(),directory:f||"",children:t.jsx(go,{apis:s,children:t.jsx(bo,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[t.jsx(xo,{embeddedBackgroundWorkEnabled:r}),t.jsx(ni,{}),t.jsx(Si,{}),t.jsx(Pl,{onActiveConnectionDeleted:()=>{jt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),I(C=>C+1)}}),t.jsx(yo,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),r?t.jsx(ri,{}):null]})})})},D)})}const Tl=()=>{Fo(),Fr().then(()=>{Promise.all([$r(),$o()]).catch(s=>{console.error("[mobile-main] settings init failed:",s)}),Uo(),Wo(),Vo()}).catch(s=>{console.error("[mobile-main] appearance init failed:",s)}).finally(()=>{gi()})};function Ol(s){Mo(),Tl(),ki(),_o();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const r=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",i=r?{...s,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:s,o=t.jsx(Il,{apis:i});_r.createRoot(e).render(t.jsx(rs.StrictMode,{children:t.jsx(zo,{children:t.jsx(Lo,{children:t.jsx(Oo,{children:t.jsx(hi,{children:r?o:t.jsx(Bo,{children:o})})})})})}))}export{Ol as renderMobileApp};