@openchamber/web 1.14.0 → 1.14.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 (55) hide show
  1. package/dist/assets/{DiagramView-CIaZCGUT.js → DiagramView-Cb58svCq.js} +1 -1
  2. package/dist/assets/MarkdownRendererImpl-D2yCDL5A.js +7 -0
  3. package/dist/assets/{MultiRunWindow-Bsbr3i8y.js → MultiRunWindow-BPSxV_B7.js} +1 -1
  4. package/dist/assets/{OnboardingScreen-3IAKkM5k.js → OnboardingScreen-Sl-6JgaP.js} +1 -1
  5. package/dist/assets/{SessionSwitcherDropdown-CLm6tF5n.js → SessionSwitcherDropdown-4FWg9xMC.js} +1 -1
  6. package/dist/assets/{SettingsWindow-K-ErjehP.js → SettingsWindow-CY8q4msv.js} +1 -1
  7. package/dist/assets/{TerminalView-DF7-jlam.js → TerminalView-fTYjnQkh.js} +1 -1
  8. package/dist/assets/{es-DQIFCjC2.js → es-bWcuDy_2.js} +1 -1
  9. package/dist/assets/{fr-CJRav0LS.js → fr-DzRs3OzV.js} +2 -2
  10. package/dist/assets/index-KnWk9fmM.css +1 -0
  11. package/dist/assets/index-ZJTzZ0_U.js +2 -0
  12. package/dist/assets/{ja-CjAaqvHO.js → ja-BqUX_UD3.js} +2 -2
  13. package/dist/assets/{ko-BEbFxvrd.js → ko-BQo10SNx.js} +2 -2
  14. package/dist/assets/main-BDoqLlQB.js +236 -0
  15. package/dist/assets/{main-C2put7uQ.js → main-DUGyTrDt.js} +2 -2
  16. package/dist/assets/miniChat-DNDiX8GA.js +2 -0
  17. package/dist/assets/mobile-DnghtOCb.js +2 -0
  18. package/dist/assets/pl-Bgx_ATJT.js +15 -0
  19. package/dist/assets/{pt-BR-9Sk3esQZ.js → pt-BR-B1yXRvoX.js} +1 -1
  20. package/dist/assets/{renderElectronMiniChatApp-CdDj0ms1.js → renderElectronMiniChatApp-BB4C1K7t.js} +2 -2
  21. package/dist/assets/renderMobileApp-CZgaXKi5.js +16 -0
  22. package/dist/assets/runtimeEndpointReset-By39StyB.js +167 -0
  23. package/dist/assets/{uk-DW_dTfoO.js → uk-C9k8SP8q.js} +1 -1
  24. package/dist/assets/{useAppFontEffects-DTO332li.js → useAppFontEffects-BUUJYbAZ.js} +129 -117
  25. package/dist/assets/{zh-CN-r2_euV7U.js → zh-CN-Bri-Vo5y.js} +1 -1
  26. package/dist/assets/{zh-TW-BdPx3NWh.js → zh-TW-DAUGzmYG.js} +1 -1
  27. package/dist/index.html +3 -3
  28. package/dist/mini-chat.html +3 -3
  29. package/dist/mobile.html +3 -3
  30. package/package.json +1 -1
  31. package/server/index.js +27 -5
  32. package/server/lib/opencode/core-routes.js +1 -0
  33. package/server/lib/opencode/feature-routes-runtime.js +10 -0
  34. package/server/lib/opencode/models-metadata.js +61 -0
  35. package/server/lib/opencode/openchamber-routes.js +7 -40
  36. package/server/lib/opencode/settings-helpers.js +13 -0
  37. package/server/lib/opencode/shutdown-runtime.js +2 -0
  38. package/server/lib/session-assist/DOCUMENTATION.md +66 -0
  39. package/server/lib/session-assist/runtime.js +394 -0
  40. package/server/lib/small-model/DOCUMENTATION.md +78 -0
  41. package/server/lib/small-model/call.js +380 -0
  42. package/server/lib/small-model/catalog.js +13 -0
  43. package/server/lib/small-model/index.js +167 -0
  44. package/server/lib/small-model/resolve.js +131 -0
  45. package/server/lib/small-model/resolve.test.js +197 -0
  46. package/server/lib/small-model/routes.js +44 -0
  47. package/dist/assets/MarkdownRendererImpl-DWgOeIpO.js +0 -7
  48. package/dist/assets/index-5eUDDB6w.js +0 -2
  49. package/dist/assets/index-CgpE7F8T.css +0 -1
  50. package/dist/assets/main-DuQEoz31.js +0 -214
  51. package/dist/assets/miniChat-o3AAQ-8r.js +0 -2
  52. package/dist/assets/mobile-X0421aWz.js +0 -2
  53. package/dist/assets/pl-D4kzai5T.js +0 -15
  54. package/dist/assets/renderMobileApp-cZ_HZKSe.js +0 -16
  55. package/dist/assets/runtimeEndpointReset-BYLVW9e7.js +0 -167
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-DTO332li.js","assets/vendor-.bun-C6iL44L9.js","assets/index-5eUDDB6w.js","assets/index-CgpE7F8T.css"])))=>i.map(i=>d[i]);
2
- import{b as V,j as c,R as p,_ as jt,G as Dt,H as kt}from"./vendor-.bun-C6iL44L9.js";import{b as le,a6 as Ct,z as fe,u as ut,x as Pt,o as ht,e as gt,i as Et,j as Mt}from"./index-5eUDDB6w.js";import{eS as Rt,c as St,dM as At,D as v,b as Fe,X as _,cl as ft,a8 as Nt,d as Lt,i as vt,aU as Ot,aW as Bt,p as Tt,I as He,B as yt,a_ as F,a9 as zt,aY as Wt,_ as $t,$ as Ut,a0 as Gt,a5 as Ht,a7 as Ft,a4 as Vt,a2 as qt,a3 as Kt,eT as Jt,cR as Xt,R as Yt,ao as Qt,ap as Zt,aq as en,ar as tn,as as nn,at as rn,au as sn,av as on,aw as an}from"./useAppFontEffects-DTO332li.js";import{C as cn,S as ln,W as dn}from"./SessionSwitcherDropdown-CLm6tF5n.js";const un=t=>{const e=V.c(3),{mode:r,children:s}=t;let n;return e[0]!==s||e[1]!==r?(n=c.jsx(Rt.Provider,{value:r,children:s}),e[0]=s,e[1]=r,e[2]=n):n=e[2],n},fn=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(/\/+$/,"")},mn=t=>{const e=V.c(125),{mode:r}=t,{t:s}=St(),n=v(hn),l=v(yn),a=v(wn),u=le(gn),f=Fe(Sn),d=Fe(vn),y=_(xn),j=_(bn),D=ft(),g=Nt(n??""),w=Lt(),x=vt(_n);let z;e[0]!==n?(z=o=>n?o.worktreeMetadata.get(n)?.path??"":"",e[0]=n,e[1]=z):z=e[1];const R=v(z);let A;e[2]!==n?(A=o=>n?o.worktreeMetadata.get(n)?.branch?.trim()??null:null,e[2]=n,e[3]=A):A=e[3];const O=v(A);let W;e[4]!==n?(W=o=>n?o.getAttachment(n):void 0,e[4]=n,e[5]=W):W=e[5];const i=Ot(W),N=v(In),[m,I]=p.useState(!1),B=typeof window<"u"?window.__OPENCHAMBER_MACOS_MAJOR__??0:0,L=Number.isFinite(B)&&B>0,Ve=typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__&&window.__OPENCHAMBER_PLATFORM__==="win32",mt=L?B>=26?"h-12":B<=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=$,q=E?.worktreeMetadata??null;let me,pe;e[9]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{Ct()&&fe("desktop_get_window_pinned").then(o=>{typeof o?.pinned=="boolean"&&I(o.pinned)})},pe=[],e[9]=me,e[10]=pe):(me=e[9],pe=e[10]),p.useEffect(me,pe);let he;e[11]!==l||e[12]!==r||e[13]!==E?.title||e[14]!==s?(he=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]=he):he=e[15];const qe=he,Ke=E?.directory??null;let ye;e[16]!==Ke?(ye=U(Ke),e[16]=Ke,e[17]=ye):ye=e[17];const we=ye,Je=R||q?.path||i?.cwd||i?.worktreeRoot||"";let ge;e[18]!==Je?(ge=U(Je),e[18]=Je,e[19]=ge):ge=e[19];const Se=ge;let ve;e[20]!==u?(ve=U(u),e[20]=u,e[21]=ve):ve=e[21];const k=Se||we||N||ve;let xe;e[22]!==k?(xe=fn(k),e[22]=k,e[23]=xe):xe=e[23];const xt=xe;let be;e[24]!==we||e[25]!==Se?(be=o=>{const h=U(Se||we||"");if(!h)return null;for(const P of o.availableWorktreesByProject.values()){const b=P.find(T=>U(T.path)===h)?.branch?.trim();if(b)return b}return null},e[24]=we,e[25]=Se,e[26]=be):be=e[26];const Xe=v(be);let _e,Ie;e[27]!==x||e[28]!==k||e[29]!==w.git?(_e=()=>{k&&x(k,w.git).catch(jn)},Ie=[x,k,w.git],e[27]=x,e[28]=k,e[29]=w.git,e[30]=_e,e[31]=Ie):(_e=e[30],Ie=e[31]),p.useEffect(_e,Ie),q?.projectDirectory,i?.worktreeRoot;let Ye;e:{const o=q?.projectDirectory??i?.worktreeRoot??null;let h;e[32]!==o?(h=U(o),e[32]=o,e[33]=h):h=e[33];const S=h||k;if(!S){Ye=null;break e}let b;e[34]!==S||e[35]!==f?(b=f.map(Dn).filter(T=>T.normalizedPath&&(T.normalizedPath===S||S.startsWith(`${T.normalizedPath}/`))).sort(kn)[0]??null,e[34]=S,e[35]=f,e[36]=b):b=e[36],Ye=b}const bt=Ye;let je;e:{const o=bt??d;if(!o){je=xt||"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){je=P;break e}let S;e[39]!==o.path?(S=o.path.split(/[\\/]/).filter(Boolean).at(-1)??o.path,e[39]=o.path,e[40]=S):S=e[40],je=S}const Qe=je,Ze=Bt(k||null);let De;e[41]!==Xe||e[42]!==Ze||e[43]!==q?.branch||e[44]!==i?.branch||e[45]!==O?(De=Ze||O||q?.branch?.trim()||i?.branch?.trim()||Xe,e[41]=Xe,e[42]=Ze,e[43]=q?.branch,e[44]=i?.branch,e[45]=O,e[46]=De):De=e[46];const et=De,ke=et&&et!=="HEAD"?et:null;let Ce;e[47]!==y?(Ce=y(),e[47]=y,e[48]=Ce):Ce=e[48];const pt=Ce;let tt;e:{for(let o=g.length-1;o>=0;o=o-1,o){const h=g[o];if(h.role!=="assistant"||typeof h.providerID!="string"||typeof h.modelID!="string")continue;const S=j.find(b=>b.id===h.providerID)?.models.find(b=>b.id===h.modelID);if(S){tt=S;break e}}tt=void 0}const _t=tt,Pe=pt?.limit?pt:_t,K=Pe&&typeof Pe.limit=="object"&&Pe.limit!==null?Pe.limit:null,G=K&&typeof K.context=="number"?K.context:0,de=K&&typeof K.output=="number"?K.output:0;let Ee;e:{if(!n||g.length===0){Ee=null;break e}let o,h;for(let ue=g.length-1;ue>=0;ue=ue-1,ue){const dt=g[ue];if(dt.role!=="assistant")continue;const H=dt.tokens;if(!H)continue;if(H.input+H.output+H.reasoning+(H.cache?.read??0)+(H.cache?.write??0)>0){o=H,h=dt.id;break}}if(!o){Ee=null;break e}const P=o.input+o.output+o.reasoning+(o.cache?.read??0)+(o.cache?.write??0),S=G>0?G:2e5;let b;e[49]!==G||e[50]!==P?(b=G>0?Math.round(P/G*100):0,e[49]=G,e[50]=P,e[51]=b):b=e[51];const T=b;let Ue;e[52]!==o.output||e[53]!==de?(Ue=de>0?Math.round(o.output/de*100):void 0,e[52]=o.output,e[53]=de,e[54]=Ue):Ue=e[54];const at=Ue,ct=G||0,lt=de||void 0;let Ge;e[55]!==h||e[56]!==at||e[57]!==T||e[58]!==ct||e[59]!==lt||e[60]!==S||e[61]!==P?(Ge={totalTokens:P,percentage:T,contextLimit:ct,outputLimit:lt,normalizedOutput:at,thresholdLimit:S,lastMessageId:h},e[55]=h,e[56]=at,e[57]=T,e[58]=ct,e[59]=lt,e[60]=S,e[61]=P,e[62]=Ge):Ge=e[62],Ee=Ge}const C=Ee,[M,nt]=p.useState(null);let Me;e[63]===Symbol.for("react.memo_cache_sentinel")?(Me={WebkitAppRegion:"drag"},e[63]=Me):Me=e[63];const It=Me;let Re;e[64]===Symbol.for("react.memo_cache_sentinel")?(Re={WebkitAppRegion:"no-drag"},e[64]=Re):Re=e[64];const rt=Re;let Ae,Ne;e[65]!==C||e[66]!==n?(Ae=()=>{if(!n){nt(Cn);return}if(C&&C.totalTokens>0){nt(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}nt(Pn)},Ne=[C,n],e[65]=C,e[66]=n,e[67]=Ae,e[68]=Ne):(Ae=e[67],Ne=e[68]),p.useEffect(Ae,Ne);const st=M&&M.contextLimit>0?Math.min(999,M.totalTokens/M.contextLimit*100):0;let Le;e[69]!==m?(Le=()=>{const o=!m;I(o),fe("desktop_set_window_pinned",{pinned:o}).catch(()=>{I(!o)})},e[69]=m,e[70]=Le):Le=e[70];const ot=Le;let Oe;e[71]!==u||e[72]!==n||e[73]!==a||e[74]!==k||e[75]!==E?(Oe=()=>{const o=n?{sessionId:n,directory:E?.directory??u??""}:{mode:"draft",directory:k||u||"",projectId:a};fe("desktop_focus_main_window",o).then(En)},e[71]=u,e[72]=n,e[73]=a,e[74]=k,e[75]=E,e[76]=Oe):Oe=e[76];const it=Oe;let Be;e[77]===Symbol.for("react.memo_cache_sentinel")?(Be=Tt("flex items-center gap-3 bg-background pr-3",L?"pl-[5.5rem]":"pl-3",Ve?"h-12":mt||"min-h-14"),e[77]=Be):Be=e[77];let J;e[78]!==s?(J=s("sessions.switcher.openAria"),e[78]=s,e[79]=J):J=e[79];let X;e[80]!==qe?(X=c.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:qe}),e[80]=qe,e[81]=X):X=e[81];let Y;e[82]!==Qe?(Y=c.jsx("span",{className:"truncate",children:Qe}),e[82]=Qe,e[83]=Y):Y=e[83];let Q;e[84]!==ke?(Q=ke?c.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[c.jsx(He,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),c.jsx("span",{className:"truncate",children:ke})]}):null,e[84]=ke,e[85]=Q):Q=e[85];let Z;e[86]!==Y||e[87]!==Q?(Z=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:[Y,Q]}),e[86]=Y,e[87]=Q,e[88]=Z):Z=e[88];let ee;e[89]!==J||e[90]!==X||e[91]!==Z?(ee=c.jsx(ln,{children:c.jsxs("button",{type:"button","aria-label":J,style:rt,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,Z]})}),e[89]=J,e[90]=X,e[91]=Z,e[92]=ee):ee=e[92];let Te;e[93]===Symbol.for("react.memo_cache_sentinel")?(Te=c.jsx("div",{className:"min-w-0 flex-1"}),e[93]=Te):Te=e[93];let te;e[94]!==st||e[95]!==M?(te=M&&M.totalTokens>0?c.jsx(cn,{totalTokens:M.totalTokens,percentage:st,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[94]=st,e[95]=M,e[96]=te):te=e[96];let ne;e[97]!==m||e[98]!==s?(ne=s(m?"miniChat.actions.unpinAria":"miniChat.actions.pinAria"),e[97]=m,e[98]=s,e[99]=ne):ne=e[99];let re;e[100]!==m||e[101]!==s?(re=s(m?"miniChat.actions.unpin":"miniChat.actions.pin"),e[100]=m,e[101]=s,e[102]=re):re=e[102];let se;e[103]!==m?(se=m?c.jsx(He,{name:"pushpin-2-fill",className:"h-4 w-4"}):c.jsx(He,{name:"pushpin-2",className:"h-4 w-4"}),e[103]=m,e[104]=se):se=e[104];let oe;e[105]!==ot||e[106]!==ne||e[107]!==re||e[108]!==se?(oe=c.jsx(yt,{type:"button",variant:"ghost",size:"icon",onClick:ot,"aria-label":ne,title:re,style:rt,children:se}),e[105]=ot,e[106]=ne,e[107]=re,e[108]=se,e[109]=oe):oe=e[109];let ie;e[110]!==s?(ie=s("miniChat.actions.openMainAria"),e[110]=s,e[111]=ie):ie=e[111];let ae;e[112]!==s?(ae=s("miniChat.actions.openMain"),e[112]=s,e[113]=ae):ae=e[113];let ze;e[114]===Symbol.for("react.memo_cache_sentinel")?(ze=c.jsx(He,{name:"external-link",className:"h-4 w-4"}),e[114]=ze):ze=e[114];let ce;e[115]!==it||e[116]!==ie||e[117]!==ae?(ce=c.jsx(yt,{type:"button",variant:"ghost",size:"icon",onClick:it,"aria-label":ie,title:ae,style:rt,children:ze}),e[115]=it,e[116]=ie,e[117]=ae,e[118]=ce):ce=e[118];let We;e[119]===Symbol.for("react.memo_cache_sentinel")?(We=c.jsx(dn,{visible:Ve}),e[119]=We):We=e[119];let $e;return e[120]!==ee||e[121]!==te||e[122]!==oe||e[123]!==ce?($e=c.jsxs("header",{className:Be,style:It,children:[ee,Te,te,oe,ce,We]}),e[120]=ee,e[121]=te,e[122]=oe,e[123]=ce,e[124]=$e):$e=e[124],$e},pn=t=>{const e=V.c(9),{mode:r,autoOpenDraft:s,unavailable:n}=t,l=s===void 0?!1:s,a=n===void 0?!1:n,{t:u}=St();let f;e[0]!==r?(f=c.jsx(mn,{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(un,{mode:"mini-chat",children:c.jsx(At,{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 hn(t){return t.currentSessionId}function yn(t){return!!t.newSessionDraft?.open}function wn(t){return t.newSessionDraft?.selectedProjectId??null}function gn(t){return t.currentDirectory}function Sn(t){return t.projects}function vn(t){return t.getActiveProject()}function xn(t){return t.getCurrentModel}function bn(t){return t.providers}function _n(t){return t.ensureStatus}function In(t){return t.newSessionDraft?.open?U(t.newSessionDraft.bootstrapPendingDirectory??t.newSessionDraft.directoryOverride??""):""}function jn(){}function Dn(t){return{...t,normalizedPath:U(t.path)}}function kn(t,e){return e.path.length-t.path.length}function Cn(t){return t===null?t:null}function Pn(t){return t===null?t:null}function En(t){return t?.focused===!0?fe("desktop_close_current_window"):null}const wt=()=>{document.querySelector('textarea[data-chat-input="true"]')?.focus()},Mn=()=>{const t=ut(n=>n.shortcutOverrides),e=le(n=>n.currentDirectory),r=Fe(n=>n.getActiveProject()),s=v(n=>n.openNewSessionDraft);p.useEffect(()=>{const n=a=>Wt(a,t),l=a=>{if(F(a,n("focus_input"))){a.preventDefault(),wt();return}if(Pt()&&F(a,n("new_mini_chat"))){a.preventDefault(),fe("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(F(a,n("new_chat"))){a.preventDefault(),s({selectedProjectId:r?.id??null,directoryOverride:e||r?.path||null,preserveDirectoryOverride:!!(e||r?.path)}),wt();return}if(F(a,n("open_model_selector"))){a.preventDefault();const{isModelSelectorOpen:d,setModelSelectorOpen:y}=ut.getState();y(!d);return}if(F(a,n("cycle_thinking_variant"))){const d=_.getState();if(d.getCurrentModelVariants().length===0)return;a.preventDefault(),d.cycleCurrentVariant();const j=_.getState().currentVariant,D=v.getState().currentSessionId,g=_.getState().currentAgentName,w=_.getState().currentProviderId,x=_.getState().currentModelId;D&&g&&w&&x&&zt.getState().saveAgentModelVariantForSession(D,g,w,x,j);return}const u=F(a,n("cycle_favorite_model_forward")),f=F(a,n("cycle_favorite_model_backward"));if(u||f){const{favoriteModels:d,addRecentModel:y}=ut.getState();if(d.length===0)return;a.preventDefault();const{currentProviderId:j,currentModelId:D,setProvider:g,setModel:w}=_.getState(),x=d.findIndex(A=>A.providerID===j&&A.modelID===D),R=d[(x+(u?1:-1)+d.length)%d.length];g(R.providerID),w(R.modelID),y(R.providerID,R.modelID)}};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[r?.id,r?.path,e,s,t])},Rn="openchamber:mini-chat-presence",An=()=>{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}},Nn=({config:t})=>{const e=ft(),r=le(i=>i.currentDirectory),s=le(i=>i.setDirectory),n=Fe(i=>i.projects),l=v(i=>i.currentSessionId),a=v(i=>!!i.newSessionDraft?.open),u=v(i=>i.newSessionDraft?.open?i.newSessionDraft.bootstrapPendingDirectory??i.newSessionDraft.directoryOverride??"":""),f=v(i=>i.setCurrentSession),d=v(i=>i.openNewSessionDraft),y=_(i=>i.initializeApp),j=_(i=>i.isInitialized),D=_(i=>i.isConnected),g=_(i=>i.loadProviders),w=_(i=>i.loadAgents),x=_(i=>i.providers.length),z=_(i=>i.agents.length),R=Xt();p.useEffect(()=>{y()},[y]),p.useEffect(()=>{if(j)return;let i=!0,N=0;const m=window.setInterval(()=>{if(i){if(N+=1,N>10){window.clearInterval(m);return}_.getState().isInitialized||_.getState().initializeApp()}},1e3);return()=>{i=!1,window.clearInterval(m)}},[j]);const A=p.useRef(!1);p.useEffect(()=>{if(!A.current&&t.mode==="session"&&t.directory){if(r===t.directory){A.current=!0;return}s(t.directory,{showOverlay:!1}),A.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&&(x===0&&g({source:"electronMiniChat:recovery"}),z===0&&w({source:"electronMiniChat:recovery"}))},[z,D,w,g,x]);const O=p.useRef(!1);p.useEffect(()=>{if(O.current||t.mode!=="session"||!t.sessionId)return;if(l===t.sessionId){O.current=!0;return}if(l){O.current=!0;return}const i=e.find(m=>m.id===t.sessionId);if(!i){R.ensureSessionRenderable(t.sessionId);return}const N=i.directory??t.directory;f(t.sessionId,N),O.current=!0},[t,l,e,f,R]),p.useEffect(()=>{const i=N=>{const m=N.detail,I=typeof m?.sessionId=="string"?m.sessionId.trim():"";if(!I||v.getState().currentSessionId===I)return;const B=typeof m?.directory=="string"&&m.directory.trim().length>0?m.directory.trim():e.find(L=>L.id===I)?.directory??null;R.ensureSessionRenderable(I),f(I,B),O.current=!0};return window.addEventListener("openchamber:open-session",i),()=>window.removeEventListener("openchamber:open-session",i)},[e,f,R]),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,I=[];await Promise.all(n.map(async B=>{const L=B.path.replace(/\\/g,"/").replace(/\/+$/,"");if(L)try{if(!(vt.getState().directories.get(L)?.isGitRepo??await jt(()=>import("./useAppFontEffects-DTO332li.js").then(E=>E.f9),__vite__mapDeps([0,1,2,3])).then(E=>E.checkIsGitRepository(L))))return;const $=await Yt({id:B.id,path:L});if(i||$.length===0)return;m.set(L,$),I.push(...$)}catch{}})),!i&&v.setState({availableWorktrees:I,availableWorktreesByProject:m})})(),()=>{i=!0}},[n]);const W=p.useRef(!1);return p.useEffect(()=>{if(W.current||!j)return;const i=()=>{if(W.current)return;W.current=!0;const I=typeof document<"u"?document.getElementById("initial-loading"):null;I&&(I.classList.add("fade-out"),window.setTimeout(()=>I.remove(),300))},N=t.mode==="session"?l===t.sessionId:a,m=window.setTimeout(i,N?100:1500);return()=>window.clearTimeout(m)},[j,t.mode,t.sessionId,l,a]),null},Ln=()=>{const t=V.c(4),e=v($n),r=le(Un);let s,n;return t[0]!==r||t[1]!==e?(s=()=>{if(!e||!r||typeof BroadcastChannel>"u")return;const l=new BroadcastChannel(Rn),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},On=t=>{const e=V.c(6),r=ft(),s=v(Gn),[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 Bn(t){const e=V.c(15),{apis:r}=t;let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=An(),e[0]=s):s=e[0];const n=s,l=le(zn);let a,u;e[1]!==l?(a=()=>{ht.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=()=>(gt(r),Tn),d=[r],e[4]=r,e[5]=f,e[6]=d):(f=e[5],d=e[6]),p.useEffect(f,d),$t(),Mn();let y;e[7]===Symbol.for("react.memo_cache_sentinel")?(y={enabled:!0},e[7]=y):y=e[7],Ut(y),Gt();let j;e[8]===Symbol.for("react.memo_cache_sentinel")?(j=ht.getSdkClient(),e[8]=j):j=e[8];const D=l||n.directory||"";let g;e[9]===Symbol.for("react.memo_cache_sentinel")?(g=c.jsx(Ht,{delayDuration:300,skipDelayDuration:150,children:c.jsxs("div",{className:"h-full text-foreground bg-background",children:[c.jsx(Wn,{config:n}),c.jsx(Ft,{})]})}),e[9]=g):g=e[9];let w;e[10]!==r?(w=c.jsx(Vt,{apis:r,children:g}),e[10]=r,e[11]=w):w=e[11];let x;return e[12]!==w||e[13]!==D?(x=c.jsx(qt,{children:c.jsx(Kt,{sdk:j,directory:D,children:w})}),e[12]=w,e[13]=D,e[14]=x):x=e[14],x}function Tn(){return gt(null)}function zn(t){return t.currentDirectory}const Wn=t=>{const e=V.c(11),{config:r}=t,s=On(r);let n;e[0]!==r?(n=c.jsx(Nn,{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(Ln,{}),a=c.jsx(Jt,{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(pn,{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 $n(t){return t.currentSessionId}function Un(t){return t.currentDirectory}function Gn(t){return t.currentSessionId}const Hn=()=>{nn(),Et().then(()=>{Promise.all([Mt(),rn()]).catch(t=>{console.error("[mini-chat-main] settings init failed:",t)}),sn(),on(),an()}).catch(t=>{console.error("[mini-chat-main] appearance init failed:",t)})};function Yn(t){Hn();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");Dt.createRoot(e).render(c.jsx(kt.StrictMode,{children:c.jsx(Qt,{children:c.jsx(Zt,{children:c.jsx(en,{children:c.jsx(tn,{children:c.jsx(Bn,{apis:t})})})})})}))}export{Yn as renderElectronMiniChatApp};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-BUUJYbAZ.js","assets/vendor-.bun-C6iL44L9.js","assets/index-ZJTzZ0_U.js","assets/index-KnWk9fmM.css"])))=>i.map(i=>d[i]);
2
+ import{b as V,j as c,R as p,_ as jt,G as Dt,H as kt}from"./vendor-.bun-C6iL44L9.js";import{b as le,a6 as Ct,z as fe,u as ut,x as Pt,o as ht,e as gt,i as Et,j as Mt}from"./index-ZJTzZ0_U.js";import{eS as Rt,c as St,dM as At,D as v,b as Fe,X as _,cl as ft,a8 as Nt,d as Lt,i as vt,aU as Ot,aW as Bt,p as Tt,I as He,B as yt,a_ as F,a9 as zt,aY as Wt,_ as $t,$ as Ut,a0 as Gt,a5 as Ht,a7 as Ft,a4 as Vt,a2 as qt,a3 as Kt,eT as Jt,cR as Xt,R as Yt,ao as Qt,ap as Zt,aq as en,ar as tn,as as nn,at as rn,au as sn,av as on,aw as an}from"./useAppFontEffects-BUUJYbAZ.js";import{C as cn,S as ln,W as dn}from"./SessionSwitcherDropdown-4FWg9xMC.js";const un=t=>{const e=V.c(3),{mode:r,children:s}=t;let n;return e[0]!==s||e[1]!==r?(n=c.jsx(Rt.Provider,{value:r,children:s}),e[0]=s,e[1]=r,e[2]=n):n=e[2],n},fn=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(/\/+$/,"")},mn=t=>{const e=V.c(125),{mode:r}=t,{t:s}=St(),n=v(hn),l=v(yn),a=v(wn),u=le(gn),f=Fe(Sn),d=Fe(vn),y=_(xn),j=_(bn),D=ft(),g=Nt(n??""),w=Lt(),x=vt(_n);let z;e[0]!==n?(z=o=>n?o.worktreeMetadata.get(n)?.path??"":"",e[0]=n,e[1]=z):z=e[1];const R=v(z);let A;e[2]!==n?(A=o=>n?o.worktreeMetadata.get(n)?.branch?.trim()??null:null,e[2]=n,e[3]=A):A=e[3];const O=v(A);let W;e[4]!==n?(W=o=>n?o.getAttachment(n):void 0,e[4]=n,e[5]=W):W=e[5];const i=Ot(W),N=v(In),[m,I]=p.useState(!1),B=typeof window<"u"?window.__OPENCHAMBER_MACOS_MAJOR__??0:0,L=Number.isFinite(B)&&B>0,Ve=typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__&&window.__OPENCHAMBER_PLATFORM__==="win32",mt=L?B>=26?"h-12":B<=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=$,q=E?.worktreeMetadata??null;let me,pe;e[9]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{Ct()&&fe("desktop_get_window_pinned").then(o=>{typeof o?.pinned=="boolean"&&I(o.pinned)})},pe=[],e[9]=me,e[10]=pe):(me=e[9],pe=e[10]),p.useEffect(me,pe);let he;e[11]!==l||e[12]!==r||e[13]!==E?.title||e[14]!==s?(he=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]=he):he=e[15];const qe=he,Ke=E?.directory??null;let ye;e[16]!==Ke?(ye=U(Ke),e[16]=Ke,e[17]=ye):ye=e[17];const we=ye,Je=R||q?.path||i?.cwd||i?.worktreeRoot||"";let ge;e[18]!==Je?(ge=U(Je),e[18]=Je,e[19]=ge):ge=e[19];const Se=ge;let ve;e[20]!==u?(ve=U(u),e[20]=u,e[21]=ve):ve=e[21];const k=Se||we||N||ve;let xe;e[22]!==k?(xe=fn(k),e[22]=k,e[23]=xe):xe=e[23];const xt=xe;let be;e[24]!==we||e[25]!==Se?(be=o=>{const h=U(Se||we||"");if(!h)return null;for(const P of o.availableWorktreesByProject.values()){const b=P.find(T=>U(T.path)===h)?.branch?.trim();if(b)return b}return null},e[24]=we,e[25]=Se,e[26]=be):be=e[26];const Xe=v(be);let _e,Ie;e[27]!==x||e[28]!==k||e[29]!==w.git?(_e=()=>{k&&x(k,w.git).catch(jn)},Ie=[x,k,w.git],e[27]=x,e[28]=k,e[29]=w.git,e[30]=_e,e[31]=Ie):(_e=e[30],Ie=e[31]),p.useEffect(_e,Ie),q?.projectDirectory,i?.worktreeRoot;let Ye;e:{const o=q?.projectDirectory??i?.worktreeRoot??null;let h;e[32]!==o?(h=U(o),e[32]=o,e[33]=h):h=e[33];const S=h||k;if(!S){Ye=null;break e}let b;e[34]!==S||e[35]!==f?(b=f.map(Dn).filter(T=>T.normalizedPath&&(T.normalizedPath===S||S.startsWith(`${T.normalizedPath}/`))).sort(kn)[0]??null,e[34]=S,e[35]=f,e[36]=b):b=e[36],Ye=b}const bt=Ye;let je;e:{const o=bt??d;if(!o){je=xt||"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){je=P;break e}let S;e[39]!==o.path?(S=o.path.split(/[\\/]/).filter(Boolean).at(-1)??o.path,e[39]=o.path,e[40]=S):S=e[40],je=S}const Qe=je,Ze=Bt(k||null);let De;e[41]!==Xe||e[42]!==Ze||e[43]!==q?.branch||e[44]!==i?.branch||e[45]!==O?(De=Ze||O||q?.branch?.trim()||i?.branch?.trim()||Xe,e[41]=Xe,e[42]=Ze,e[43]=q?.branch,e[44]=i?.branch,e[45]=O,e[46]=De):De=e[46];const et=De,ke=et&&et!=="HEAD"?et:null;let Ce;e[47]!==y?(Ce=y(),e[47]=y,e[48]=Ce):Ce=e[48];const pt=Ce;let tt;e:{for(let o=g.length-1;o>=0;o=o-1,o){const h=g[o];if(h.role!=="assistant"||typeof h.providerID!="string"||typeof h.modelID!="string")continue;const S=j.find(b=>b.id===h.providerID)?.models.find(b=>b.id===h.modelID);if(S){tt=S;break e}}tt=void 0}const _t=tt,Pe=pt?.limit?pt:_t,K=Pe&&typeof Pe.limit=="object"&&Pe.limit!==null?Pe.limit:null,G=K&&typeof K.context=="number"?K.context:0,de=K&&typeof K.output=="number"?K.output:0;let Ee;e:{if(!n||g.length===0){Ee=null;break e}let o,h;for(let ue=g.length-1;ue>=0;ue=ue-1,ue){const dt=g[ue];if(dt.role!=="assistant")continue;const H=dt.tokens;if(!H)continue;if(H.input+H.output+H.reasoning+(H.cache?.read??0)+(H.cache?.write??0)>0){o=H,h=dt.id;break}}if(!o){Ee=null;break e}const P=o.input+o.output+o.reasoning+(o.cache?.read??0)+(o.cache?.write??0),S=G>0?G:2e5;let b;e[49]!==G||e[50]!==P?(b=G>0?Math.round(P/G*100):0,e[49]=G,e[50]=P,e[51]=b):b=e[51];const T=b;let Ue;e[52]!==o.output||e[53]!==de?(Ue=de>0?Math.round(o.output/de*100):void 0,e[52]=o.output,e[53]=de,e[54]=Ue):Ue=e[54];const at=Ue,ct=G||0,lt=de||void 0;let Ge;e[55]!==h||e[56]!==at||e[57]!==T||e[58]!==ct||e[59]!==lt||e[60]!==S||e[61]!==P?(Ge={totalTokens:P,percentage:T,contextLimit:ct,outputLimit:lt,normalizedOutput:at,thresholdLimit:S,lastMessageId:h},e[55]=h,e[56]=at,e[57]=T,e[58]=ct,e[59]=lt,e[60]=S,e[61]=P,e[62]=Ge):Ge=e[62],Ee=Ge}const C=Ee,[M,nt]=p.useState(null);let Me;e[63]===Symbol.for("react.memo_cache_sentinel")?(Me={WebkitAppRegion:"drag"},e[63]=Me):Me=e[63];const It=Me;let Re;e[64]===Symbol.for("react.memo_cache_sentinel")?(Re={WebkitAppRegion:"no-drag"},e[64]=Re):Re=e[64];const rt=Re;let Ae,Ne;e[65]!==C||e[66]!==n?(Ae=()=>{if(!n){nt(Cn);return}if(C&&C.totalTokens>0){nt(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}nt(Pn)},Ne=[C,n],e[65]=C,e[66]=n,e[67]=Ae,e[68]=Ne):(Ae=e[67],Ne=e[68]),p.useEffect(Ae,Ne);const st=M&&M.contextLimit>0?Math.min(999,M.totalTokens/M.contextLimit*100):0;let Le;e[69]!==m?(Le=()=>{const o=!m;I(o),fe("desktop_set_window_pinned",{pinned:o}).catch(()=>{I(!o)})},e[69]=m,e[70]=Le):Le=e[70];const ot=Le;let Oe;e[71]!==u||e[72]!==n||e[73]!==a||e[74]!==k||e[75]!==E?(Oe=()=>{const o=n?{sessionId:n,directory:E?.directory??u??""}:{mode:"draft",directory:k||u||"",projectId:a};fe("desktop_focus_main_window",o).then(En)},e[71]=u,e[72]=n,e[73]=a,e[74]=k,e[75]=E,e[76]=Oe):Oe=e[76];const it=Oe;let Be;e[77]===Symbol.for("react.memo_cache_sentinel")?(Be=Tt("flex items-center gap-3 bg-background pr-3",L?"pl-[5.5rem]":"pl-3",Ve?"h-12":mt||"min-h-14"),e[77]=Be):Be=e[77];let J;e[78]!==s?(J=s("sessions.switcher.openAria"),e[78]=s,e[79]=J):J=e[79];let X;e[80]!==qe?(X=c.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:qe}),e[80]=qe,e[81]=X):X=e[81];let Y;e[82]!==Qe?(Y=c.jsx("span",{className:"truncate",children:Qe}),e[82]=Qe,e[83]=Y):Y=e[83];let Q;e[84]!==ke?(Q=ke?c.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[c.jsx(He,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),c.jsx("span",{className:"truncate",children:ke})]}):null,e[84]=ke,e[85]=Q):Q=e[85];let Z;e[86]!==Y||e[87]!==Q?(Z=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:[Y,Q]}),e[86]=Y,e[87]=Q,e[88]=Z):Z=e[88];let ee;e[89]!==J||e[90]!==X||e[91]!==Z?(ee=c.jsx(ln,{children:c.jsxs("button",{type:"button","aria-label":J,style:rt,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,Z]})}),e[89]=J,e[90]=X,e[91]=Z,e[92]=ee):ee=e[92];let Te;e[93]===Symbol.for("react.memo_cache_sentinel")?(Te=c.jsx("div",{className:"min-w-0 flex-1"}),e[93]=Te):Te=e[93];let te;e[94]!==st||e[95]!==M?(te=M&&M.totalTokens>0?c.jsx(cn,{totalTokens:M.totalTokens,percentage:st,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[94]=st,e[95]=M,e[96]=te):te=e[96];let ne;e[97]!==m||e[98]!==s?(ne=s(m?"miniChat.actions.unpinAria":"miniChat.actions.pinAria"),e[97]=m,e[98]=s,e[99]=ne):ne=e[99];let re;e[100]!==m||e[101]!==s?(re=s(m?"miniChat.actions.unpin":"miniChat.actions.pin"),e[100]=m,e[101]=s,e[102]=re):re=e[102];let se;e[103]!==m?(se=m?c.jsx(He,{name:"pushpin-2-fill",className:"h-4 w-4"}):c.jsx(He,{name:"pushpin-2",className:"h-4 w-4"}),e[103]=m,e[104]=se):se=e[104];let oe;e[105]!==ot||e[106]!==ne||e[107]!==re||e[108]!==se?(oe=c.jsx(yt,{type:"button",variant:"ghost",size:"icon",onClick:ot,"aria-label":ne,title:re,style:rt,children:se}),e[105]=ot,e[106]=ne,e[107]=re,e[108]=se,e[109]=oe):oe=e[109];let ie;e[110]!==s?(ie=s("miniChat.actions.openMainAria"),e[110]=s,e[111]=ie):ie=e[111];let ae;e[112]!==s?(ae=s("miniChat.actions.openMain"),e[112]=s,e[113]=ae):ae=e[113];let ze;e[114]===Symbol.for("react.memo_cache_sentinel")?(ze=c.jsx(He,{name:"external-link",className:"h-4 w-4"}),e[114]=ze):ze=e[114];let ce;e[115]!==it||e[116]!==ie||e[117]!==ae?(ce=c.jsx(yt,{type:"button",variant:"ghost",size:"icon",onClick:it,"aria-label":ie,title:ae,style:rt,children:ze}),e[115]=it,e[116]=ie,e[117]=ae,e[118]=ce):ce=e[118];let We;e[119]===Symbol.for("react.memo_cache_sentinel")?(We=c.jsx(dn,{visible:Ve}),e[119]=We):We=e[119];let $e;return e[120]!==ee||e[121]!==te||e[122]!==oe||e[123]!==ce?($e=c.jsxs("header",{className:Be,style:It,children:[ee,Te,te,oe,ce,We]}),e[120]=ee,e[121]=te,e[122]=oe,e[123]=ce,e[124]=$e):$e=e[124],$e},pn=t=>{const e=V.c(9),{mode:r,autoOpenDraft:s,unavailable:n}=t,l=s===void 0?!1:s,a=n===void 0?!1:n,{t:u}=St();let f;e[0]!==r?(f=c.jsx(mn,{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(un,{mode:"mini-chat",children:c.jsx(At,{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 hn(t){return t.currentSessionId}function yn(t){return!!t.newSessionDraft?.open}function wn(t){return t.newSessionDraft?.selectedProjectId??null}function gn(t){return t.currentDirectory}function Sn(t){return t.projects}function vn(t){return t.getActiveProject()}function xn(t){return t.getCurrentModel}function bn(t){return t.providers}function _n(t){return t.ensureStatus}function In(t){return t.newSessionDraft?.open?U(t.newSessionDraft.bootstrapPendingDirectory??t.newSessionDraft.directoryOverride??""):""}function jn(){}function Dn(t){return{...t,normalizedPath:U(t.path)}}function kn(t,e){return e.path.length-t.path.length}function Cn(t){return t===null?t:null}function Pn(t){return t===null?t:null}function En(t){return t?.focused===!0?fe("desktop_close_current_window"):null}const wt=()=>{document.querySelector('textarea[data-chat-input="true"]')?.focus()},Mn=()=>{const t=ut(n=>n.shortcutOverrides),e=le(n=>n.currentDirectory),r=Fe(n=>n.getActiveProject()),s=v(n=>n.openNewSessionDraft);p.useEffect(()=>{const n=a=>Wt(a,t),l=a=>{if(F(a,n("focus_input"))){a.preventDefault(),wt();return}if(Pt()&&F(a,n("new_mini_chat"))){a.preventDefault(),fe("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(F(a,n("new_chat"))){a.preventDefault(),s({selectedProjectId:r?.id??null,directoryOverride:e||r?.path||null,preserveDirectoryOverride:!!(e||r?.path)}),wt();return}if(F(a,n("open_model_selector"))){a.preventDefault();const{isModelSelectorOpen:d,setModelSelectorOpen:y}=ut.getState();y(!d);return}if(F(a,n("cycle_thinking_variant"))){const d=_.getState();if(d.getCurrentModelVariants().length===0)return;a.preventDefault(),d.cycleCurrentVariant();const j=_.getState().currentVariant,D=v.getState().currentSessionId,g=_.getState().currentAgentName,w=_.getState().currentProviderId,x=_.getState().currentModelId;D&&g&&w&&x&&zt.getState().saveAgentModelVariantForSession(D,g,w,x,j);return}const u=F(a,n("cycle_favorite_model_forward")),f=F(a,n("cycle_favorite_model_backward"));if(u||f){const{favoriteModels:d,addRecentModel:y}=ut.getState();if(d.length===0)return;a.preventDefault();const{currentProviderId:j,currentModelId:D,setProvider:g,setModel:w}=_.getState(),x=d.findIndex(A=>A.providerID===j&&A.modelID===D),R=d[(x+(u?1:-1)+d.length)%d.length];g(R.providerID),w(R.modelID),y(R.providerID,R.modelID)}};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[r?.id,r?.path,e,s,t])},Rn="openchamber:mini-chat-presence",An=()=>{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}},Nn=({config:t})=>{const e=ft(),r=le(i=>i.currentDirectory),s=le(i=>i.setDirectory),n=Fe(i=>i.projects),l=v(i=>i.currentSessionId),a=v(i=>!!i.newSessionDraft?.open),u=v(i=>i.newSessionDraft?.open?i.newSessionDraft.bootstrapPendingDirectory??i.newSessionDraft.directoryOverride??"":""),f=v(i=>i.setCurrentSession),d=v(i=>i.openNewSessionDraft),y=_(i=>i.initializeApp),j=_(i=>i.isInitialized),D=_(i=>i.isConnected),g=_(i=>i.loadProviders),w=_(i=>i.loadAgents),x=_(i=>i.providers.length),z=_(i=>i.agents.length),R=Xt();p.useEffect(()=>{y()},[y]),p.useEffect(()=>{if(j)return;let i=!0,N=0;const m=window.setInterval(()=>{if(i){if(N+=1,N>10){window.clearInterval(m);return}_.getState().isInitialized||_.getState().initializeApp()}},1e3);return()=>{i=!1,window.clearInterval(m)}},[j]);const A=p.useRef(!1);p.useEffect(()=>{if(!A.current&&t.mode==="session"&&t.directory){if(r===t.directory){A.current=!0;return}s(t.directory,{showOverlay:!1}),A.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&&(x===0&&g({source:"electronMiniChat:recovery"}),z===0&&w({source:"electronMiniChat:recovery"}))},[z,D,w,g,x]);const O=p.useRef(!1);p.useEffect(()=>{if(O.current||t.mode!=="session"||!t.sessionId)return;if(l===t.sessionId){O.current=!0;return}if(l){O.current=!0;return}const i=e.find(m=>m.id===t.sessionId);if(!i){R.ensureSessionRenderable(t.sessionId);return}const N=i.directory??t.directory;f(t.sessionId,N),O.current=!0},[t,l,e,f,R]),p.useEffect(()=>{const i=N=>{const m=N.detail,I=typeof m?.sessionId=="string"?m.sessionId.trim():"";if(!I||v.getState().currentSessionId===I)return;const B=typeof m?.directory=="string"&&m.directory.trim().length>0?m.directory.trim():e.find(L=>L.id===I)?.directory??null;R.ensureSessionRenderable(I),f(I,B),O.current=!0};return window.addEventListener("openchamber:open-session",i),()=>window.removeEventListener("openchamber:open-session",i)},[e,f,R]),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,I=[];await Promise.all(n.map(async B=>{const L=B.path.replace(/\\/g,"/").replace(/\/+$/,"");if(L)try{if(!(vt.getState().directories.get(L)?.isGitRepo??await jt(()=>import("./useAppFontEffects-BUUJYbAZ.js").then(E=>E.f9),__vite__mapDeps([0,1,2,3])).then(E=>E.checkIsGitRepository(L))))return;const $=await Yt({id:B.id,path:L});if(i||$.length===0)return;m.set(L,$),I.push(...$)}catch{}})),!i&&v.setState({availableWorktrees:I,availableWorktreesByProject:m})})(),()=>{i=!0}},[n]);const W=p.useRef(!1);return p.useEffect(()=>{if(W.current||!j)return;const i=()=>{if(W.current)return;W.current=!0;const I=typeof document<"u"?document.getElementById("initial-loading"):null;I&&(I.classList.add("fade-out"),window.setTimeout(()=>I.remove(),300))},N=t.mode==="session"?l===t.sessionId:a,m=window.setTimeout(i,N?100:1500);return()=>window.clearTimeout(m)},[j,t.mode,t.sessionId,l,a]),null},Ln=()=>{const t=V.c(4),e=v($n),r=le(Un);let s,n;return t[0]!==r||t[1]!==e?(s=()=>{if(!e||!r||typeof BroadcastChannel>"u")return;const l=new BroadcastChannel(Rn),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},On=t=>{const e=V.c(6),r=ft(),s=v(Gn),[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 Bn(t){const e=V.c(15),{apis:r}=t;let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=An(),e[0]=s):s=e[0];const n=s,l=le(zn);let a,u;e[1]!==l?(a=()=>{ht.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=()=>(gt(r),Tn),d=[r],e[4]=r,e[5]=f,e[6]=d):(f=e[5],d=e[6]),p.useEffect(f,d),$t(),Mn();let y;e[7]===Symbol.for("react.memo_cache_sentinel")?(y={enabled:!0},e[7]=y):y=e[7],Ut(y),Gt();let j;e[8]===Symbol.for("react.memo_cache_sentinel")?(j=ht.getSdkClient(),e[8]=j):j=e[8];const D=l||n.directory||"";let g;e[9]===Symbol.for("react.memo_cache_sentinel")?(g=c.jsx(Ht,{delayDuration:300,skipDelayDuration:150,children:c.jsxs("div",{className:"h-full text-foreground bg-background",children:[c.jsx(Wn,{config:n}),c.jsx(Ft,{})]})}),e[9]=g):g=e[9];let w;e[10]!==r?(w=c.jsx(Vt,{apis:r,children:g}),e[10]=r,e[11]=w):w=e[11];let x;return e[12]!==w||e[13]!==D?(x=c.jsx(qt,{children:c.jsx(Kt,{sdk:j,directory:D,children:w})}),e[12]=w,e[13]=D,e[14]=x):x=e[14],x}function Tn(){return gt(null)}function zn(t){return t.currentDirectory}const Wn=t=>{const e=V.c(11),{config:r}=t,s=On(r);let n;e[0]!==r?(n=c.jsx(Nn,{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(Ln,{}),a=c.jsx(Jt,{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(pn,{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 $n(t){return t.currentSessionId}function Un(t){return t.currentDirectory}function Gn(t){return t.currentSessionId}const Hn=()=>{nn(),Et().then(()=>{Promise.all([Mt(),rn()]).catch(t=>{console.error("[mini-chat-main] settings init failed:",t)}),sn(),on(),an()}).catch(t=>{console.error("[mini-chat-main] appearance init failed:",t)})};function Yn(t){Hn();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");Dt.createRoot(e).render(c.jsx(kt.StrictMode,{children:c.jsx(Qt,{children:c.jsx(Zt,{children:c.jsx(en,{children:c.jsx(tn,{children:c.jsx(Bn,{apis:t})})})})})}))}export{Yn as renderElectronMiniChatApp};
@@ -0,0 +1,16 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useAppFontEffects-BUUJYbAZ.js","assets/vendor-.bun-C6iL44L9.js","assets/index-ZJTzZ0_U.js","assets/index-KnWk9fmM.css"])))=>i.map(i=>d[i]);
2
+ import{R as l,j as t,b as ce,P as Rt,K as ss,e as In,f as qs,B as Rn,Q as Mn,r as Ln,g as zn,F as Bn,U as On,Z as Fn,a as ns,p as Ks,i as $n,u as Qs,k as Ft,s as Ys,l as Js,m as Xs,n as Yt,D as Zs,o as en,S as tn,v as sn,q as nn,t as rn,C as on,M as an,w as Jt,J as ln,x as Wn,y as gs,z as rs,A as bs,V as Un,_ as Be,E as Vn,G as Gn,H as Hn}from"./vendor-.bun-C6iL44L9.js";import{u as wt,g as qn,r as Kn,a as ft,b as bt,s as ht,d as xs,e as vs,f as Qn,o as ys,h as Yn,i as Jn,j as Xn}from"./index-ZJTzZ0_U.js";import{u as $t,a as Zn,b as Ce,r as cn,c as ue,d as Wt,e as os,f as is,g as un,h as er,i as Ie,t as se,s as tr,j as sr,k as nr,l as rr,m as or,I as ie,n as dn,B as he,o as mt,S as at,p as te,q as as,v as ir,w as ws,x as ls,y as js,F as ar,z as ks,A as lr,J as cr,C as fn,D as be,E as ur,G as dr,M as mn,P as hn,H as pn,K as gn,L as fr,N as mr,O as hr,Q as pr,R as bn,T as ye,U as gr,V as br,W as xr,X as Ne,Y as vr,Z as yr,_ as wr,$ as jr,a0 as kr,a1 as Et,a2 as rt,a3 as Sr,a4 as Nr,a5 as Cr,a6 as Er,a7 as Pr,a8 as Ar,a9 as _r,aa as Tr,ab as Ss,ac as Ns,ad as Dr,ae as Ir,af as Rr,ag as Mr,ah as Lr,ai as zr,aj as Br,ak as Or,al as Fr,am as $r,an as Wr,ao as Ur,ap as Vr,aq as Gr,ar as Hr,as as qr,at as Kr,au as Qr,av as Yr,aw as Jr}from"./useAppFontEffects-BUUJYbAZ.js";import{S as Xr,C as Zr,a as eo,P as to,b as so,D as no,N as ro,r as oo,u as io,c as ao,O as lo,d as co,e as Cs,f as Lt,g as uo,M as fo,h as mo,A as ho,i as st,j as po,Q as go,k as bo,l as xo,m as vo,n as yo}from"./runtimeEndpointReset-By39StyB.js";import"./mobileLayoutPreference-Dio-WWkI.js";let xn=null,Es=!1;const wo=new Promise(n=>{xn=n});function jo(){Es||(Es=!0,xn?.())}const ko=6,So=n=>n.parentID??null,Ps=n=>{const e=n.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},No=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Co=(n,e)=>{if(!n)return"";let s=null,r=-1;for(const i of e){const o=No(i.path);(n===o||n.startsWith(`${o}/`))&&o.length>r&&(s=i,r=o.length)}return s?s.label?.trim()||Ps(s.path):Ps(n)},Eo=()=>{const n=$t.getState().activeSessions,e=Zn.getState().index.session.unseenCount,s=wt.getState().notifyOnSubtasks,r=Ce.getState().projects;let i=0;const o=[];for(const u of n){const c=So(u)!==null,f=(e[u.id]??0)>0&&(!c||s);f&&(i+=1),c||o.push({id:u.id,title:u.title??"",updated:u.time?.updated??u.time?.created??0,unread:f,project:Co(cn(u),r)})}o.sort((u,c)=>c.updated-u.updated);const a=o.slice(0,ko).map(({id:u,title:c,unread:m,project:f})=>({id:u,title:c,unread:m,project:f}));return{attentionCount:i,recentSessions:a}},Po="__OPENCHAMBER_WIDGET_SNAPSHOT__",Ao=()=>{typeof window>"u"||(window[Po]=()=>{try{return JSON.stringify(Eo())}catch{return null}})},_o=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),To=n=>{const e=n.index?.trim();return!!(e&&e!=="?")},Do=n=>{const e=n.working_dir?.trim(),s=n.index?.trim();return!!(e||s==="?")},As=(n,e)=>e?`${n}\0staged`:n,Io=({onClose:n,initialDiffPath:e,initialDiffStaged:s=!1})=>{const{t:r}=ue(),{git:i}=Wt(),o=_o(os()??null),a=is(o||null),u=un(o||null),c=er(o||null),m=Ie(I=>I.setActiveDirectory),f=Ie(I=>I.ensureAll),h=Ie(I=>I.fetchStatus),p=Ie(I=>I.fetchBranches),v=Ie(I=>I.prefetchDiffs),y=Ie(I=>I.getDiff),S=Ie(I=>I.setDiff),[x,N]=l.useState(()=>e?{type:"diff",path:e,staged:s}:{type:"list"});l.useEffect(()=>{e&&N(I=>I.type==="diff"&&I.path===e&&I.staged===s?I:{type:"diff",path:e,staged:s})},[e,s]);const[_,D]=l.useState(null),[T,b]=l.useState(null),[w,C]=l.useState(""),[P,E]=l.useState(new Set),[g,k]=l.useState(!1),[M,V]=l.useState(!1),[$,j]=l.useState([]),[A,W]=l.useState([]),[U,q]=l.useState([]),[G,z]=l.useState(null),[Y,R]=l.useState(null),[X,Ee]=l.useState(0),ne=l.useMemo(()=>{const I=a?.files??[],L=new Map;for(const Q of I)L.set(Q.path,Q);return Array.from(L.values()).sort((Q,pe)=>Q.path.localeCompare(pe.path))},[a?.files]),O=l.useMemo(()=>ne.filter(To),[ne]),ee=l.useMemo(()=>ne.filter(Do),[ne]),ae=l.useMemo(()=>{if(U.length>0)return U;const I=a?.tracking?.includes("/")?a.tracking.split("/")[0]:null;return I||G?[{name:I||"origin",fetchUrl:G??"",pushUrl:G??""}]:[]},[G,U,a?.tracking]),xe=Ie(l.useCallback(I=>!o||x.type!=="diff"?null:I.directories.get(o)?.diffCache.get(As(x.path,x.staged))??null,[o,x])),je=l.useMemo(()=>x.type!=="diff"?null:ne.find(I=>I.path===x.path)??null,[ne,x]),oe=l.useCallback(async(I=!0)=>{if(o)try{await Promise.all([h(o,i),p(o,i)])}catch(L){I&&se.error(L instanceof Error?L.message:r("gitView.toast.refreshRepositoryFailed"))}},[o,p,h,i,r]),ve=l.useCallback(async()=>{if(!o){q([]),z(null);return}try{const[I,L]=await Promise.all([i.getRemotes(o).catch(()=>[]),i.getRemoteUrl?i.getRemoteUrl(o).catch(()=>null):Promise.resolve(null)]);q(I),z(L)}catch{q([]),z(null)}},[o,i]);l.useEffect(()=>{o&&(m(o),f(o,i))},[o,f,i,m]),l.useEffect(()=>{ve()},[ve]),l.useEffect(()=>{if(!o||ne.length===0)return;const I=Array.from(new Set([...O.map(Q=>Q.path),...A,...ne.slice(0,20).map(Q=>Q.path)])).filter(Boolean);if(I.length===0)return;const L=window.setTimeout(()=>{v(o,i,I,{maxFiles:40})},120);return()=>window.clearTimeout(L)},[ne,o,i,v,O,A]),l.useEffect(()=>{if(x.type!=="diff"){R(null);return}const I=As(x.path,x.staged);if(!o||y(o,I)){R(null);return}let L=!1;return R(null),i.getGitFileDiff(o,{path:x.path,staged:x.staged||void 0}).then(Q=>{L||S(o,I,{original:Q.original??"",modified:Q.modified??"",isBinary:Q.isBinary})}).catch(Q=>{L||R(Q instanceof Error?Q.message:String(Q))}),()=>{L=!0}},[o,X,y,i,x,S]);const de=async(I,L)=>{if(o){D(I);try{const Q=pe=>{const Pe=`${pe.name}/`,Ae=a?.tracking?.startsWith(Pe)?a.tracking.slice(Pe.length):void 0;return{remote:pe.name,branch:Ae,rebase:!0}};if(I==="fetch"){if(!L)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:L.name}),se.success(r("gitView.toast.fetchedFromRemote",{name:L.name}))}else if(I==="sync"){if(!L)throw new Error(r("mobile.changes.noRemote"));await i.gitFetch(o,{remote:L.name});const pe=await i.getGitStatus(o);if((pe.behind??0)>0){if((pe.files?.length??0)>0){se.error(r("gitView.toast.commitOrStashBeforeSync"));return}await i.gitPull(o,Q(L))}((await i.getGitStatus(o)).ahead??0)>0&&await i.gitPush(o),se.success(r("gitView.toast.alreadyUpToDate"))}await oe(!1),await ve()}catch(Q){se.error(Q instanceof Error?Q.message:r("gitView.toast.syncActionFailed",{action:r("gitView.sync.syncChanges")}))}finally{D(null)}}},fe=l.useCallback(async(I,L)=>{if(!(!o||I.length===0))try{L==="stage"?I.length>1?await tr(o,I):await sr(o,I[0]):I.length>1?await nr(o,I):await rr(o,I[0]),await oe(!1)}catch(Q){se.error(Q instanceof Error?Q.message:r(L==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[o,oe,r]),ke=l.useCallback((I,L=!1)=>{N({type:"diff",path:I,staged:L})},[]),Se=l.useCallback(async I=>{if(o){E(L=>new Set(L).add(I));try{await i.revertGitFile(o,I),se.success(r("gitView.toast.revertedFile",{path:I})),await oe(!1)}catch(L){se.error(L instanceof Error?L.message:r("gitView.toast.revertFailed"))}finally{E(L=>{const Q=new Set(L);return Q.delete(I),Q})}}},[o,i,oe,r]),Ve=l.useCallback(async I=>{if(!o||I.length===0||g)return;const L=Array.from(new Set(I));k(!0),E(new Set(L));try{await Promise.all(L.map(Q=>i.revertGitFile(o,Q))),await oe(!1),se.success(L.length===1?r("gitView.toast.revertedFilesSingle",{count:L.length}):r("gitView.toast.revertedFilesPlural",{count:L.length}))}catch(Q){se.error(Q instanceof Error?Q.message:r("gitView.toast.revertFailed"))}finally{E(new Set),k(!1)}},[o,i,g,oe,r]),Me=l.useCallback(I=>{const L=I.map(Q=>Q.trim()).filter(Boolean);if(L.length===0){j([]);return}C(Q=>`${Q.trim()}${Q.trim()?`
3
+
4
+ `:""}${L.join(`
5
+ `)}`.trim()),j([])},[]),Oe=l.useCallback(async()=>{if(!o)return;const I=O.map(L=>L.path).sort();if(I.length===0){se.error(r("gitView.toast.selectFileToDescribe"));return}V(!0);try{const{message:L}=await or(o,I);C(L.subject?.trim()??""),j(Array.isArray(L.highlights)?L.highlights:[])}catch(L){se.error(L instanceof Error?L.message:r("gitView.toast.generateCommitMessageFailed"))}finally{V(!1)}},[o,O,r]),Fe=async(I={})=>{if(!o)return;if(!w.trim()){se.error(r("gitView.toast.enterCommitMessage"));return}const L=O.map(Q=>Q.path).sort();if(L.length===0){se.error(r("gitView.toast.selectFileToCommit"));return}b(I.pushAfter?"commitAndPush":"commit");try{if(await i.createGitCommit(o,w.trim(),{files:L}),se.success(r("gitView.toast.commitCreated")),C(""),j([]),I.pushAfter){const Q=a?.tracking?.split("/")[0],pe=ae.find(Le=>Le.name===Q)??ae[0];if(!pe)throw new Error(r("mobile.changes.noRemote"));D("sync");const Pe=`${pe.name}/`,Ae=a?.tracking?.startsWith(Pe)?a.tracking.slice(Pe.length):void 0;await i.gitFetch(o,{remote:pe.name}),((await i.getGitStatus(o)).behind??0)>0&&await i.gitPull(o,{remote:pe.name,branch:Ae,rebase:!0}),((await i.getGitStatus(o)).ahead??0)>0&&await i.gitPush(o),await oe(!1),await ve()}else await oe(!1)}catch(Q){se.error(Q instanceof Error?Q.message:r("gitView.toast.createCommitFailed"))}finally{b(null),I.pushAfter&&D(null)}},Ge=l.useMemo(()=>{const I=[];return O.length>0&&I.push({id:"staged",title:r("gitView.changes.stagedTitle"),entries:O,actionSymbol:"-",actionAllLabel:r("gitView.changes.unstageAllAria"),getActionLabel:L=>r("gitView.changes.unstageFileAria",{path:L}),onActionFile:L=>{fe([L],"unstage")},onActionAll:L=>{fe(L,"unstage")},onViewDiff:L=>ke(L,!0),onRevertFile:Se,showRevertActions:!1,accent:!0}),ee.length>0&&I.push({id:"unstaged",title:r("gitView.changes.title"),entries:ee,actionSymbol:"+",actionAllLabel:r("gitView.changes.stageAllAria"),getActionLabel:L=>r("gitView.changes.stageFileAria",{path:L}),onActionFile:L=>{fe([L],"stage")},onActionAll:L=>{fe(L,"stage")},onViewDiff:L=>ke(L,!1),onRevertFile:Se}),I},[Se,ke,fe,O,r,ee]),et=I=>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:[n?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:n,style:{touchAction:"manipulation"},children:t.jsx(ie,{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:I})]});return o?c&&u===null?et(t.jsx(Xe,{loading:!0,message:r("gitView.loading.checkingRepository")})):u===!1?et(t.jsx(Xe,{icon:!0,message:r("gitView.empty.notGitRepository"),description:r("gitView.empty.notGitRepositoryDescription")})):x.type==="diff"?t.jsx(Ro,{path:x.path,diff:xe,fileExists:!!je,error:Y,onBack:()=>N({type:"list"}),onRetry:()=>Ee(I=>I+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:[n?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:n,style:{touchAction:"manipulation"},children:t.jsx(ie,{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(Xr,{syncAction:_,remotes:ae,onFetch:I=>{de("fetch",I)},onSync:I=>{de("sync",I)},disabled:T!==null||c,aheadCount:a?.ahead??0,behindCount:a?.behind??0,trackingRemoteName:a?.tracking?.split("/")[0],hasUncommittedChanges:ne.length>0})]}),ne.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(Zr,{groups:Ge,diffStats:a?.diffStats,revertingPaths:P,onRevertAll:Ve,isRevertingAll:g,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:W})}),t.jsx("div",{className:"shrink-0 border-t border-border/50 px-4 pb-4 pt-3",children:t.jsx(eo,{stagedCount:O.length,commitMessage:w,onCommitMessageChange:C,generatedHighlights:$,onInsertHighlights:Me,onGenerateMessage:Oe,isGeneratingMessage:M,onCommit:()=>{Fe({pushAfter:!1})},onCommitAndPush:()=>{Fe({pushAfter:!0})},commitAction:T,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Xe,{icon:!0,message:r("gitView.empty.cleanTitle"),description:r("mobile.changes.cleanDescription")})})]}):et(t.jsx(Xe,{message:r("gitView.empty.selectSessionOrDirectory")}))},Xe=n=>{const e=ce.c(13),{message:s,description:r,loading:i,icon:o}=n,a=i===void 0?!1:i,u=o===void 0?!1:o;let c;e[0]!==a?(c=a?t.jsx(ie,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=a,e[1]=c):c=e[1];let m;e[2]!==u?(m=u?t.jsx(ie,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=u,e[3]=m):m=e[3];let f;e[4]!==s?(f=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[4]=s,e[5]=f):f=e[5];let h;e[6]!==r?(h=r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r}):null,e[6]=r,e[7]=h):h=e[7];let p;return e[8]!==c||e[9]!==m||e[10]!==f||e[11]!==h?(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:[c,m,f,h]})}),e[8]=c,e[9]=m,e[10]=f,e[11]=h,e[12]=p):p=e[12],p},Ro=n=>{const e=ce.c(24),{path:s,diff:r,fileExists:i,error:o,onBack:a,onRetry:u}=n,{t:c}=ue();let m;e[0]!==s?(m=dn(s)||"text",e[0]=s,e[1]=m):m=e[1];const f=m;let h;e[2]!==c?(h=c("header.actions.backAria"),e[2]=c,e[3]=h):h=e[3];let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(ie,{name:"arrow-left",className:"size-5"}),e[4]=p):p=e[4];let v;e[5]!==a||e[6]!==h?(v=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":h,onClick:a,children:p}),e[5]=a,e[6]=h,e[7]=v):v=e[7];let y;e[8]!==s?(y=t.jsx("div",{className:"min-w-0 flex-1 px-2",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:s})}),e[8]=s,e[9]=y):y=e[9];let S;e[10]!==v||e[11]!==y?(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:[v,y]}),e[10]=v,e[11]=y,e[12]=S):S=e[12];let x;e[13]!==r||e[14]!==o||e[15]!==i||e[16]!==f||e[17]!==u||e[18]!==s||e[19]!==c?(x=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:c("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}),t.jsx(he,{type:"button",size:"sm",variant:"outline",onClick:u,children:c("diffView.actions.retry")})]})}):r?r.isBinary?t.jsx(Xe,{icon:!0,message:c("diffView.binary.unavailable")}):mt(s)?t.jsx(Xe,{icon:!0,message:c("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(at,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(to,{original:r.original,modified:r.modified,language:f,fileName:s,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(Xe,{loading:!0,message:c("diffView.state.loadingDiff")}):t.jsx(Xe,{icon:!0,message:c("mobile.changes.diffDetail.missingTitle"),description:c("mobile.changes.diffDetail.missingDescription")})}),e[13]=r,e[14]=o,e[15]=i,e[16]=f,e[17]=u,e[18]=s,e[19]=c,e[20]=x):x=e[20];let N;return e[21]!==S||e[22]!==x?(N=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[S,x]}),e[21]=S,e[22]=x,e[23]=N):N=e[23],N},_s=25e4,xt=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),Ze=n=>{const e=xt(n);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},Mo=n=>{const e=xt(n);if(!e||e==="/")return null;const s=e.lastIndexOf("/");return s<=0?e.startsWith("/")?"/":null:e.slice(0,s)},Lo=(n,e)=>{const s=xt(n),r=xt(e);return!r||s===r?Ze(s):s.startsWith(`${r}/`)?s.slice(r.length+1):s},zo=n=>{if(typeof n!="number"||!Number.isFinite(n)||n<0)return"";if(n<1024)return`${n} B`;const e=["KB","MB","GB"];let s=n/1024;for(const r of e){if(s<1024||r===e[e.length-1])return`${s.toFixed(s>=10?0:1)} ${r}`;s/=1024}return""},Bo=n=>n.toLowerCase().endsWith(".svg")?"":qn().authenticatedAsset("/api/fs/raw",{path:n}),Oo=n=>/\.(md|mdx|markdown)$/i.test(n),Fo=n=>/\.(json|jsonc)$/i.test(n),$o=({onClose:n})=>{const{t:e}=ue(),{files:s}=Wt(),r=xt(os()??null),[i,o]=l.useState(()=>({type:"browser",directory:r})),[a,u]=l.useState([]),[c,m]=l.useState(!1),[f,h]=l.useState(null),[p,v]=l.useState(""),[y,S]=l.useState([]),[x,N]=l.useState(!1),[_,D]=l.useState(""),[T,b]=l.useState(null),[w,C]=l.useState(!1),P=l.useRef(0);l.useEffect(()=>{r&&o(z=>z.type==="browser"&&z.directory?z:{type:"browser",directory:r})},[r]);const E=i.type==="browser"?i.directory:i.returnDirectory,g=l.useCallback(async z=>{if(!z)return;const Y=P.current+1;P.current=Y,m(!0),h(null);try{const R=await s.listDirectory(z);if(P.current!==Y)return;u(R.entries.slice().sort((X,Ee)=>X.isDirectory!==Ee.isDirectory?X.isDirectory?-1:1:X.name.localeCompare(Ee.name)))}catch(R){if(P.current!==Y)return;u([]),h(R instanceof Error?R.message:e("mobile.files.error.listFailed"))}finally{P.current===Y&&m(!1)}},[s,e]);l.useEffect(()=>{i.type==="browser"&&g(i.directory)},[g,i]),l.useEffect(()=>{if(i.type!=="browser")return;const z=p.trim();if(!z){S([]),N(!1);return}let Y=!1;const R=window.setTimeout(()=>{N(!0),s.search({directory:i.directory,query:z,maxResults:40}).then(X=>{Y||S(X)}).catch(()=>{Y||S([])}).finally(()=>{Y||N(!1)})},250);return()=>{Y=!0,window.clearTimeout(R)}},[s,p,i]),l.useEffect(()=>{if(i.type!=="file")return;if(D(""),b(null),mt(i.path)&&!i.path.toLowerCase().endsWith(".svg")){C(!1);return}if(!s.readFile){b(e("mobile.files.error.readUnavailable")),C(!1);return}let z=!1;return C(!0),s.readFile(i.path).then(Y=>{z||D(Y.content.length>_s?`${Y.content.slice(0,_s)}
6
+
7
+ ${e("mobile.files.file.truncated")}`:Y.content)}).catch(Y=>{z||b(Y instanceof Error?Y.message:e("filesView.error.readFileFailed"))}).finally(()=>{z||C(!1)}),()=>{z=!0}},[s,i,e]);const k=z=>{v(""),o({type:"browser",directory:z})},M=z=>{o({type:"file",path:z,returnDirectory:E||r})},V=async z=>{(await ws(z)).ok?se.success(e("mobile.files.toast.pathCopied")):se.error(e("mobile.files.toast.copyFailed"))},$=async()=>{(await ws(_)).ok?se.success(e("mobile.files.toast.contentCopied")):se.error(e("mobile.files.toast.copyFailed"))};if(!r)return t.jsx(vt,{message:e("mobile.files.empty.noDirectory")});if(i.type==="file")return t.jsx(Uo,{path:i.path,content:_,error:T,isLoading:w,onBack:()=>o({type:"browser",directory:i.returnDirectory}),onCopyPath:()=>{V(i.path)},onCopyContent:()=>{$()}});const j=i.directory===r?e("mobile.files.rootDirectory"):Ze(i.directory),A=p.trim()?y:[],W=Mo(i.directory),U=i.directory!==r&&W!==null&&(W===r||W.startsWith(`${r}/`)),q=U&&!p.trim(),G=U?W:null;return 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:[n?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":e("mobile.surface.closeAria"),onClick:n,style:{touchAction:"manipulation"},children:t.jsx(Rt,{className:"size-5"})}):null,q&&G?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":e("mobile.files.backToParentAria",{name:Ze(G)}),onClick:()=>k(G),style:{touchAction:"manipulation"},children:t.jsx(ss,{className:"size-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:j})}),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":e("mobile.files.refreshAria"),onClick:()=>{g(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(In,{className:te("size-5",c&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-4 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(qs,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(as,{value:p,onChange:z=>v(z.target.value),placeholder:e("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(at,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:f?t.jsx(vt,{message:f}):p.trim()?t.jsx(Wo,{results:A,isSearching:x,onOpenFile:M}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",children:[a.length===0&&!c?t.jsx("div",{className:"px-4 py-8 text-center typography-body text-muted-foreground",children:e("mobile.files.empty.directory")}):null,a.map(z=>t.jsx(vn,{name:z.name,path:z.path,directory:z.isDirectory,meta:z.isDirectory?void 0:zo(z.size),onClick:()=>z.isDirectory?k(z.path):M(z.path)},z.path))]})})]})},vn=n=>{const e=ce.c(16),{name:s,path:r,directory:i,meta:o,onClick:a}=n;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={touchAction:"manipulation"},e[0]=u):u=e[0];let c;e[1]!==i||e[2]!==r?(c=i?t.jsx(Mn,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(ar,{filePath:r,className:"size-5 shrink-0"}),e[1]=i,e[2]=r,e[3]=c):c=e[3];let m;e[4]!==s?(m=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s}),e[4]=s,e[5]=m):m=e[5];let f;e[6]!==o?(f=o?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:o}):null,e[6]=o,e[7]=f):f=e[7];let h;e[8]!==i?(h=i?t.jsx(Ln,{className:"size-4 shrink-0 text-muted-foreground/60"}):null,e[8]=i,e[9]=h):h=e[9];let p;return e[10]!==a||e[11]!==c||e[12]!==m||e[13]!==f||e[14]!==h?(p=t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/30 px-3 py-2.5 text-left transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:a,style:u,children:[c,m,f,h]}),e[10]=a,e[11]=c,e[12]=m,e[13]=f,e[14]=h,e[15]=p):p=e[15],p},Wo=n=>{const e=ce.c(10),{results:s,isSearching:r,onOpenFile:i}=n,{t:o}=ue(),a=xt(os()??null);if(r){let f;e[0]!==o?(f=o("common.loading"),e[0]=o,e[1]=f):f=e[1];let h;return e[2]!==f?(h=t.jsx(vt,{loading:!0,message:f}),e[2]=f,e[3]=h):h=e[3],h}if(s.length===0){let f;e[4]!==o?(f=o("mobile.files.search.empty"),e[4]=o,e[5]=f):f=e[5];let h;return e[6]!==f?(h=t.jsx(vt,{message:f}),e[6]=f,e[7]=h):h=e[7],h}const u="overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",c=s.map(f=>t.jsx(vn,{name:Ze(f.path),path:f.path,directory:!1,meta:Lo(f.path,a),onClick:()=>i(f.path)},f.path));let m;return e[8]!==c?(m=t.jsx("div",{className:u,children:c}),e[8]=c,e[9]=m):m=e[9],m},Uo=n=>{const e=ce.c(42),{path:s,content:r,error:i,isLoading:o,onBack:a,onCopyPath:u,onCopyContent:c}=n,{t:m}=ue(),f=mt(s)&&!s.toLowerCase().endsWith(".svg")?s:"",[h,p]=l.useState("");let v,y;e[0]!==f?(v=()=>{if(!f){p("");return}let $=!1;return p(""),Kn(ft()).then(j=>{!$&&j&&p(f)}).catch(Go),()=>{$=!0}},y=[f],e[0]=f,e[1]=v,e[2]=y):(v=e[1],y=e[2]),l.useEffect(v,y);const S=!!(f&&h!==f);let x;e[3]!==S||e[4]!==s?(x=S?"":Bo(s),e[3]=S,e[4]=s,e[5]=x):x=e[5];const N=x;let _;e[6]!==m?(_=m("header.actions.backAria"),e[6]=m,e[7]=_):_=e[7];let D;e[8]===Symbol.for("react.memo_cache_sentinel")?(D=t.jsx(ss,{className:"size-5"}),e[8]=D):D=e[8];let T;e[9]!==a||e[10]!==_?(T=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":_,onClick:a,children:D}),e[9]=a,e[10]=_,e[11]=T):T=e[11];let b;e[12]!==s?(b=Ze(s),e[12]=s,e[13]=b):b=e[13];let w;e[14]!==b?(w=t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:b})}),e[14]=b,e[15]=w):w=e[15];let C;e[16]!==c||e[17]!==s||e[18]!==m?(C=mt(s)?null:t.jsx(he,{type:"button",variant:"ghost",size:"icon",onClick:c,"aria-label":m("mobile.files.copyContentAria"),children:t.jsx(Rn,{className:"size-4"})}),e[16]=c,e[17]=s,e[18]=m,e[19]=C):C=e[19];let P;e[20]!==m?(P=m("mobile.files.copyPathAria"),e[20]=m,e[21]=P):P=e[21];let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=t.jsx(zn,{className:"size-4"}),e[22]=E):E=e[22];let g;e[23]!==u||e[24]!==P?(g=t.jsx(he,{type:"button",variant:"ghost",size:"icon",onClick:u,"aria-label":P,children:E}),e[23]=u,e[24]=P,e[25]=g):g=e[25];let k;e[26]!==g||e[27]!==T||e[28]!==w||e[29]!==C?(k=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:[T,w,C,g]}),e[26]=g,e[27]=T,e[28]=w,e[29]=C,e[30]=k):k=e[30];let M;e[31]!==r||e[32]!==i||e[33]!==S||e[34]!==N||e[35]!==o||e[36]!==s||e[37]!==m?(M=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:o||S?t.jsx(vt,{loading:!0,message:m("filesView.state.loading")}):i?t.jsx(vt,{message:i}):mt(s)&&N?t.jsx(at,{className:"h-full overflow-auto p-4",children:t.jsx("img",{src:N,alt:Ze(s),className:"mx-auto max-h-full max-w-full rounded-lg object-contain"})}):mt(s)?t.jsx(at,{className:"h-full overflow-auto p-4",children:t.jsx("img",{src:`data:${ir(s)};utf8,${encodeURIComponent(r)}`,alt:Ze(s),className:"mx-auto max-h-full max-w-full rounded-lg object-contain"})}):t.jsx(Vo,{path:s,content:r})}),e[31]=r,e[32]=i,e[33]=S,e[34]=N,e[35]=o,e[36]=s,e[37]=m,e[38]=M):M=e[38];let V;return e[39]!==k||e[40]!==M?(V=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[k,M]}),e[39]=k,e[40]=M,e[41]=V):V=e[41],V},Vo=n=>{const e=ce.c(32),{path:s,content:r}=n,{currentTheme:i,availableThemes:o,lightThemeId:a,darkThemeId:u}=ls();let c;e[0]!==o||e[1]!==a?(c=o.find(C=>C.metadata.id===a)??js(!1),e[0]=o,e[1]=a,e[2]=c):c=e[2];const m=c;let f;e[3]!==o||e[4]!==u?(f=o.find(C=>C.metadata.id===u)??js(!0),e[3]=o,e[4]=u,e[5]=f):f=e[5];const h=f;let p,v;e[6]!==h||e[7]!==m?(p=()=>{ks(m),ks(h)},v=[h,m],e[6]=h,e[7]=m,e[8]=p,e[9]=v):(p=e[8],v=e[9]),l.useEffect(p,v);let y;e[10]!==h.metadata.id||e[11]!==m.metadata.id?(y={light:m.metadata.id,dark:h.metadata.id},e[10]=h.metadata.id,e[11]=m.metadata.id,e[12]=y):y=e[12];const S=y;if(Oo(s)){let C;return e[13]!==r?(C=t.jsx(at,{className:"h-full overflow-y-auto px-4 py-4",children:t.jsx(lr,{content:r,enableFileReferences:!1})}),e[13]=r,e[14]=C):C=e[14],C}if(Fo(s)){let C;return e[15]!==r?(C=t.jsx(cr,{jsonString:r,className:"h-full overflow-auto"}),e[15]=r,e[16]=C):C=e[16],C}let x;e[17]!==s?(x=Ze(s),e[17]=s,e[18]=x):x=e[18];let N;e[19]!==s?(N=dn(s)||void 0,e[19]=s,e[20]=N):N=e[20];let _;e[21]!==r||e[22]!==x||e[23]!==N?(_={name:x,contents:r,lang:N},e[21]=r,e[22]=x,e[23]=N,e[24]=_):_=e[24];const D=i.metadata.variant==="dark"?"dark":"light";let T;e[25]!==S||e[26]!==D?(T={disableFileHeader:!0,overflow:"wrap",theme:S,themeType:D,unsafeCSS:so},e[25]=S,e[26]=D,e[27]=T):T=e[27];let b;e[28]===Symbol.for("react.memo_cache_sentinel")?(b={minHeight:"100%"},e[28]=b):b=e[28];let w;return e[29]!==T||e[30]!==_?(w=t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx(at,{className:"min-h-0 flex-1 overflow-auto bg-[var(--syntax-base-background)]",children:t.jsx(Bn,{file:_,options:T,className:"block min-h-full w-full",style:b})})}),e[29]=T,e[30]=_,e[31]=w):w=e[31],w},vt=n=>{const e=ce.c(7),{message:s,loading:r}=n,i=r===void 0?!1:r;let o;e[0]!==i?(o=i?t.jsx(On,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(Fn,{className:"size-6 text-muted-foreground"}),e[0]=i,e[1]=o):o=e[1];let a;e[2]!==s?(a=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[2]=s,e[3]=a):a=e[3];let u;return e[4]!==o||e[5]!==a?(u=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:[o,a]})}),e[4]=o,e[5]=a,e[6]=u):u=e[6],u};function Go(){}const Ts=ns(n=>({expandedParents:{},toggleParent:e=>n(s=>{const r={...s.expandedParents};return r[e]?delete r[e]:r[e]=!0,{expandedParents:r}})})),zt=ns()(Ks(n=>({projectExpanded:{},worktreeExpanded:{},setProjectExpanded:(e,s)=>n(r=>({projectExpanded:{...r.projectExpanded,[e]:s}})),setWorktreeExpanded:(e,s)=>n(r=>({worktreeExpanded:{...r.worktreeExpanded,[e]:s}}))}),{name:"mobile-session-tree"})),yn=ns()(Ks(n=>({orderByProject:{},setWorktreeOrder:(e,s)=>n(r=>({orderByProject:{...r.orderByProject,[e]:s}}))}),{name:"mobile-worktree-order"})),Ds=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Ho=(n,e)=>{if(!n||n.length===0)return e;const s=new Map(n.map((i,o)=>[Ds(i),o])),r=i=>s.get(Ds(i.path))??Number.MAX_SAFE_INTEGER;return e.map((i,o)=>({worktree:i,index:o})).sort((i,o)=>{const a=r(i.worktree)-r(o.worktree);return a!==0?a:i.index-o.index}).map(i=>i.worktree)},Pt=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),qo=n=>{const e=n;return Pt(e.directory??e.project?.worktree??null)},Ko=({open:n,project:e,worktree:s,onClose:r,onDeleted:i})=>{const{t:o}=ue(),a=fn(),u=$t(E=>E.activeSessions),c=be(E=>E.archiveSessions),m=bt(E=>E.currentDirectory),[f,h]=l.useState(!1),[p,v]=l.useState(!1),[y,S]=l.useState(!1),[x,N]=l.useState(!1),_=Pt(s?.path),D=typeof s?.branch=="string"&&s.branch.trim().length>0,T=l.useMemo(()=>{if(!_)return[];const E=new Map;for(const g of[...u,...a])qo(g)===_&&E.set(g.id,g);return Array.from(E.values())},[u,a,_]);l.useEffect(()=>{if(!n){h(!1),v(!1),S(!1),N(!1);return}if(!s?.path)return;let E=!1;return ur(s.path).then(g=>{E||S(!!g?.isDirty)}).catch(()=>{E||S(!!s.status?.isDirty)}),()=>{E=!0}},[n,s?.path,s?.status?.isDirty]);const b=l.useCallback(E=>{(async()=>{try{await dr(e,E,{deleteRemoteBranch:D&&p,deleteLocalBranch:D&&f}),Pt(m)===_&&Pt(e.path)&&bt.getState().setDirectory(Pt(e.path),{showOverlay:!1}),se.success(o("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:o(D&&p?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),i?.()}catch(g){se.error(o("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:g instanceof Error?g.message:o("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[m,f,p,D,i,e,o,_]),w=async()=>{if(!(!s||x)){N(!0);try{if(T.length>0){const{archivedIds:E,failedIds:g}=await c(T.map(k=>k.id));if(g.length>0){E.length>0&&se.success(E.length===1?o("sessions.sidebar.bulkActions.archivedSingle",{count:E.length}):o("sessions.sidebar.bulkActions.archivedPlural",{count:E.length})),se.error(g.length===1?o("sessions.sidebar.bulkActions.failedArchiveSingle",{count:g.length}):o("sessions.sidebar.bulkActions.failedArchivePlural",{count:g.length}),{description:o("sessions.sidebar.dialogs.deleteResult.tryAgain")}),N(!1);return}}b(s),r()}catch(E){se.error(o("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:E instanceof Error?E.message:o("sessions.sidebar.dialogs.deleteResult.tryAgain")}),N(!1)}finally{n||N(!1)}}};if(!s)return null;const C=s.branch||s.label||s.path,P=(E,g,k,M)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":E,disabled:M,onClick:()=>g(!E),className:te("flex w-full items-center justify-between gap-3 rounded-xl border border-border/50 px-3.5 py-3 text-left transition-colors","hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",M&&"pointer-events-none opacity-40"),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:k}),t.jsx("span",{className:te("relative h-6 w-10 shrink-0 rounded-full transition-colors",E?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:te("absolute top-0.5 size-5 rounded-full bg-white transition-transform",E?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx(mn,{open:n,onClose:r,title:o("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(he,{variant:"ghost",className:"flex-1",onClick:r,disabled:x,children:o("projectEditDialog.actions.cancel")}),t.jsx(he,{variant:"destructive",className:"flex-1",onClick:()=>{w()},disabled:x,children:o("mobile.projectEdit.deleteWorktreeConfirmButton")})]}),children:t.jsxs("div",{className:"flex flex-col gap-4 px-1 py-1",children:[t.jsx("p",{className:"typography-ui-body text-foreground",children:o("mobile.projectEdit.deleteWorktreeConfirm",{name:C})}),y?t.jsx("p",{className:"rounded-xl border border-[var(--warning)]/40 bg-[color-mix(in_srgb,var(--warning)_10%,transparent)] px-3.5 py-3 typography-meta text-foreground",children:o("mobile.projectEdit.deleteWorktreeDirty")}):null,T.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o("mobile.projectEdit.deleteWorktreeArchiveNote",{count:T.length})}):null,D?t.jsxs("div",{className:"flex flex-col gap-2",children:[P(f,h,o("mobile.projectEdit.deleteLocalBranch"),x),P(p,v,o("mobile.projectEdit.deleteRemoteBranch"),x)]}):null]})})},Is="mobile-surface-root",Qo=90,Gt=16,Rs=100,Yo=48,Jo=8,Xo=()=>{if(typeof document>"u")return null;let n=document.getElementById(Is);return n||(n=document.createElement("div"),n.id=Is,document.body.appendChild(n)),n},ot=({open:n,onClose:e,title:s,subtitle:r,trailing:i,onBack:o,disableSwipeDismiss:a=!1,headerless:u=!1,ariaLabel:c,children:m})=>{const{t:f}=ue(),h=l.useRef(null),[p,v]=l.useState(!1),[y,S]=l.useState(!1),[x,N]=l.useState(!1),[_,D]=l.useState(0),T=l.useRef(null),b=l.useRef(!1),w=l.useRef(null),C=l.useRef(null),P=l.useRef(e);l.useEffect(()=>{P.current=e},[e]),typeof document<"u"&&!h.current&&(h.current=Xo()),l.useEffect(()=>{if(n){v(!0);const j=window.setTimeout(()=>S(!0),Gt);return()=>window.clearTimeout(j)}S(!1);const $=window.setTimeout(()=>v(!1),300);return()=>window.clearTimeout($)},[n]),l.useEffect(()=>{if(!n){N(!1);return}const $=window.setTimeout(()=>N(!0),Gt+Rs+80);return()=>window.clearTimeout($)},[n]),l.useEffect(()=>{if(!n)return;const $=document.body.style.overflow;C.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const j=()=>{const U=w.current;if(!U)return;(U.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??U).focus({preventScroll:!0})},A=window.setTimeout(j,Gt),W=U=>{if(U.key==="Escape"){P.current();return}if(U.key!=="Tab")return;const q=w.current;if(!q)return;const G=Array.from(q.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(X=>!X.hasAttribute("disabled")&&X.getAttribute("aria-hidden")!=="true");if(G.length===0){U.preventDefault(),q.focus({preventScroll:!0});return}const z=G[0],Y=G[G.length-1],R=document.activeElement;U.shiftKey&&R===z?(U.preventDefault(),Y.focus({preventScroll:!0})):!U.shiftKey&&R===Y&&(U.preventDefault(),z.focus({preventScroll:!0}))};return document.addEventListener("keydown",W),()=>{window.clearTimeout(A),document.body.style.overflow=$,document.removeEventListener("keydown",W),C.current?.focus?.({preventScroll:!0}),C.current=null}},[n]);const E=$=>{a||(T.current=$.touches[0]?.clientY??null,b.current=!0)},g=$=>{if(!b.current||T.current==null)return;const A=($.touches[0]?.clientY??T.current)-T.current;D(A>0?A:0)},k=()=>{b.current&&(b.current=!1,T.current=null,_>=Qo?(D(0),e()):D(0))};if(!p||!h.current)return null;const M=o?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":f("header.actions.backAria"),onClick:o,style:{touchAction:"manipulation"},children:t.jsx(ss,{className:"size-5"})}):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":f("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(Rt,{className:"size-5"})}),V=y?_>0?`translateY(${_}px)`:"none":`translateY(${Yo}px)`;return $n.createPortal(t.jsxs("div",{className:te("oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-[rgb(0_0_0_/_0.45)]","transition-opacity duration-200 ease-out",y?"opacity-100":"opacity-0"),role:"dialog","aria-modal":"true","aria-label":c,onClick:e,children:[t.jsxs("section",{ref:w,className:"mt-auto flex min-h-0 w-full flex-col overflow-hidden rounded-t-[20px] border-t border-border/40 bg-background text-foreground",tabIndex:-1,onClick:$=>$.stopPropagation(),onTransitionEnd:$=>{y&&$.target===$.currentTarget&&$.propertyName==="transform"&&N(!0)},style:{height:`calc(100% - var(--oc-safe-area-top, 0px) - ${Jo}px)`,transform:V,transition:b.current?"none":`transform ${Rs}ms cubic-bezier(0.32, 0.72, 0, 1)`},children:[t.jsxs("div",{className:"shrink-0 select-none",onTouchStart:E,onTouchMove:g,onTouchEnd:k,onTouchCancel:k,children:[t.jsx("div",{className:"flex items-center justify-center pt-2 pb-1",children:t.jsx("span",{className:"h-1 w-10 rounded-full bg-[var(--surface-muted)]","aria-hidden":!0})}),u?null:t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] items-center gap-2 px-3",children:[M,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[s?typeof s=="string"?t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:s}):s:null,r?typeof r=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:r}):r:null]}),i?t.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:i}):null]})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:x?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:m}):null})]}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]}),h.current)},Zo=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),ei=n=>{const e=ce.c(36),{worktree:s,onDelete:r}=n,{t:i}=ue();let o;e[0]!==s.path?(o={id:s.path},e[0]=s.path,e[1]=o):o=e[1];const{attributes:a,listeners:u,setNodeRef:c,transform:m,transition:f,isDragging:h}=rn(o);let p;e[2]!==m?(p=on.Transform.toString(m),e[2]=m,e[3]=p):p=e[3];const v=h?10:1;let y;e[4]!==p||e[5]!==v||e[6]!==f?(y={transform:p,transition:f,zIndex:v},e[4]=p,e[5]=v,e[6]=f,e[7]=y):y=e[7];const S=y,x=s.branch||s.label||s.path,N=h&&"shadow-lg shadow-black/20";let _;e[8]!==N?(_=te("flex items-center gap-1 rounded-2xl border border-border/40 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",N),e[8]=N,e[9]=_):_=e[9];let D;e[10]!==x||e[11]!==i?(D=i("mobile.projectEdit.dragWorktreeAria",{label:x}),e[10]=x,e[11]=i,e[12]=D):D=e[12];let T;e[13]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(an,{className:"size-4"}),e[13]=T):T=e[13];let b;e[14]!==a||e[15]!==u||e[16]!==D?(b=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":D,...a,...u,children:T}),e[14]=a,e[15]=u,e[16]=D,e[17]=b):b=e[17];let w;e[18]===Symbol.for("react.memo_cache_sentinel")?(w=t.jsx(ie,{name:"node-tree",className:"size-4 shrink-0 text-muted-foreground"}),e[18]=w):w=e[18];let C;e[19]!==x?(C=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:x}),e[19]=x,e[20]=C):C=e[20];let P;e[21]!==x||e[22]!==i?(P=i("mobile.projectEdit.deleteWorktreeAria",{label:x}),e[21]=x,e[22]=i,e[23]=P):P=e[23];let E,g;e[24]===Symbol.for("react.memo_cache_sentinel")?(E={touchAction:"manipulation"},g=t.jsx(Jt,{className:"size-4"}),e[24]=E,e[25]=g):(E=e[24],g=e[25]);let k;e[26]!==r||e[27]!==P?(k=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":P,onClick:r,style:E,children:g}),e[26]=r,e[27]=P,e[28]=k):k=e[28];let M;return e[29]!==c||e[30]!==S||e[31]!==C||e[32]!==k||e[33]!==_||e[34]!==b?(M=t.jsxs("div",{ref:c,style:S,className:_,children:[b,w,C,k]}),e[29]=c,e[30]=S,e[31]=C,e[32]=k,e[33]=_,e[34]=b,e[35]=M):M=e[35],M},ti=({open:n,project:e,onClose:s,onWorktreesChanged:r})=>{const{t:i}=ue(),{currentTheme:o}=ls(),a=Ce(A=>A.updateProjectMeta),u=Ce(A=>A.discoverProjectIcon),c=Ce(A=>A.removeProjectIcon),m=yn(A=>A.setWorktreeOrder),f=Ce(A=>e?A.projects.find(W=>W.id===e.id)?.iconImage??null:null),[h,p]=l.useState(""),[v,y]=l.useState(null),[S,x]=l.useState(null),[N,_]=l.useState(!1),[D,T]=l.useState([]),[b,w]=l.useState(null),C=e?.id??null;l.useEffect(()=>{!n||!e||(p(e.label),y(e.icon??null),x(e.color??null),T(e.worktrees))},[n,C]),l.useEffect(()=>{!n||!e||T(A=>{const W=e.worktrees.map(G=>G.path),U=A.map(G=>G.path);return W.length===U.length&&W.every(G=>U.includes(G))?A:e.worktrees})},[e?.worktrees]);const P=Qs(Ft(Xs,{activationConstraint:{distance:8}}),Ft(Js,{coordinateGetter:Ys})),E=()=>{if(!e)return;const A=h.trim();a(e.id,{label:A||e.label,icon:v,color:S}),s()},g=()=>{!e||N||(_(!0),u(e.id).then(A=>{if(!A.ok){se.error(A.error||i("projectEditDialog.toast.failedToDiscoverIcon"));return}if(A.skipped){se.success(i("projectEditDialog.toast.customIconAlreadySet"));return}se.success(i("projectEditDialog.toast.iconDiscovered"))}).finally(()=>_(!1)))},k=()=>{e&&c(e.id).then(A=>{if(!A.ok){se.error(A.error||i("projectEditDialog.toast.failedToRemoveIcon"));return}se.success(i("projectEditDialog.toast.iconRemoved"))})},M=A=>{const{active:W,over:U}=A;if(!U||W.id===U.id||!e)return;const q=D.findIndex(R=>R.path===W.id),G=D.findIndex(R=>R.path===U.id);if(q<0||G<0)return;const z=[...D],[Y]=z.splice(q,1);z.splice(G,0,Y),T(z),m(e.id,z.map(R=>Zo(R.path)))},V=S?hn[S]??null:null,$=v?pn[v]:null,j=!!f;return t.jsxs(t.Fragment,{children:[t.jsx(ot,{open:n,onClose:s,onBack:s,title:i("projectEditDialog.title"),ariaLabel:i("projectEditDialog.title"),trailing:t.jsxs(he,{type:"button",variant:"default",size:"sm","aria-label":i("projectEditDialog.actions.save"),onClick:E,disabled:!h.trim(),style:{touchAction:"manipulation"},children:[t.jsx(nn,{className:"size-4"}),i("projectEditDialog.actions.save")]}),children:e?t.jsxs("div",{className:"h-full space-y-6 overflow-y-auto px-4 pb-8 pt-2",children:[t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx("span",{className:"flex size-16 items-center justify-center overflow-hidden rounded-2xl bg-[var(--surface-muted)] text-muted-foreground",style:e.iconBackground?{backgroundColor:e.iconBackground}:void 0,children:j?t.jsx(gn,{project:{id:e.id,iconImage:f},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(Yt,{className:"size-7"})}):$?t.jsx(ie,{name:$,className:"size-7",style:V?{color:V}:void 0}):t.jsx(Yt,{className:"size-7",style:V?{color:V}:void 0})})}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:i("projectEditDialog.field.name")}),t.jsx(as,{value:h,onChange:A=>p(A.target.value),placeholder:i("projectEditDialog.field.namePlaceholder"),className:"h-11"}),t.jsx("p",{className:"truncate typography-meta text-muted-foreground",title:e.path,children:e.path})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:i("projectEditDialog.field.color")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>x(null),"aria-label":i("projectEditDialog.option.none"),className:te("flex size-9 items-center justify-center rounded-xl border-2 transition-all",S===null?"border-foreground":"border-border hover:border-border/80"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),fr.map(A=>t.jsx("button",{type:"button",onClick:()=>x(A.key),"aria-label":A.label,title:A.label,className:te("size-9 rounded-xl border-2 transition-all",S===A.key?"border-foreground":"border-transparent hover:border-border"),style:{backgroundColor:A.cssVar,touchAction:"manipulation"}},A.key))]})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:i("projectEditDialog.field.icon")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>y(null),"aria-label":i("projectEditDialog.option.none"),className:te("flex size-9 items-center justify-center rounded-xl border-2 transition-all",v===null?"border-foreground bg-[var(--surface-elevated)]":"border-border hover:border-border/80"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),mr.map(A=>t.jsx("button",{type:"button",onClick:()=>y(A.key),"aria-label":A.label,title:A.label,className:te("flex size-9 items-center justify-center rounded-xl border-2 transition-all",v===A.key?"border-foreground bg-[var(--surface-elevated)]":"border-border hover:border-border/80"),style:{touchAction:"manipulation"},children:t.jsx(ie,{name:A.Icon,className:"size-4",style:V?{color:V}:void 0})},A.key))]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[t.jsx(he,{size:"sm",variant:"outline",onClick:g,disabled:N,children:i(N?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),j?t.jsx(he,{size:"sm",variant:"outline",onClick:k,children:i("projectEditDialog.actions.removeProjectIcon")}):null]})]}),e.isGitRepo?t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:i("mobile.projectEdit.worktreesTitle")}),D.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("mobile.projectEdit.worktreesEmpty")}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("mobile.projectEdit.reorderHint")}),t.jsx(Zs,{sensors:P,collisionDetection:en,onDragEnd:M,children:t.jsx(tn,{items:D.map(A=>A.path),strategy:sn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:D.map(A=>t.jsx(ei,{worktree:A,onDelete:()=>w(A)},A.path))})})})]})]}):null]}):null}),e?t.jsx(Ko,{open:!!b,project:{id:e.id,path:e.path},worktree:b,onClose:()=>w(null),onDeleted:()=>{T(A=>A.filter(W=>W.path!==b?.path)),r?.()}}):null]})},Ht=7,si=36,ni=52,ri=18,Bt=n=>n.parentID??null,we=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),dt=n=>{const e=n;return we(e.directory??e.project?.worktree??null)},qt=n=>{const e=we(n);if(!e)return"";const s=e.split("/").filter(Boolean);return s[s.length-1]?.replace(/[-_]/g," ")||e},At=n=>{const e=n.time?.updated??n.time?.created,s=typeof e=="number"?e:Number(e);return Number.isFinite(s)&&s>0?s:0},oi=n=>{if(n<=0)return"";const e=Date.now()-n;if(e<6e4)return"now";const s=Math.floor(e/6e4);if(s<60)return`${s}m`;const r=Math.floor(s/60);if(r<24)return`${r}h`;const i=Math.floor(r/24);return i<7?`${i}d`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(n))},ii=(n,e)=>{const s=we(n),r=we(e);return!!(s&&r&&(s===r||s.startsWith(`${r}/`)))},Xt=(n,e)=>n.worktrees.find(s=>we(s.path)===e)??null,Zt=(n,e)=>e===n.path||!!Xt(n,e),Kt=(n,e)=>{const s=we(e);return s?n.find(r=>Zt(r,s))??null:null},Qt=(n,e,s)=>s?`${n.title??""} ${n.id} ${dt(n)} ${e}`.toLowerCase().includes(s):!0,es=n=>{const e=ce.c(17),{project:s,size:r}=n,i=r===void 0?"md":r,{currentTheme:o}=ls(),a=s.icon?pn[s.icon]:null,u=s.color?hn[s.color]??null:null,c=i==="sm"?"size-6 rounded-md":"size-8 rounded-lg",m=i==="sm"?"size-3.5":"size-4";let f;e[0]!==a||e[1]!==u||e[2]!==m?(f=a?t.jsx(ie,{name:a,className:m,style:u?{color:u}:void 0}):t.jsx(Yt,{className:m,style:u?{color:u}:void 0}),e[0]=a,e[1]=u,e[2]=m,e[3]=f):f=e[3];const h=f;let p;e[4]!==c?(p=te("flex shrink-0 items-center justify-center overflow-hidden bg-[var(--surface-muted)] text-muted-foreground",c),e[4]=c,e[5]=p):p=e[5];let v;e[6]!==s.iconBackground?(v=s.iconBackground?{backgroundColor:s.iconBackground}:void 0,e[6]=s.iconBackground,e[7]=v):v=e[7];let y;e[8]!==o||e[9]!==h||e[10]!==s.iconImage||e[11]!==s.id?(y=s.iconImage?t.jsx(gn,{project:{id:s.id,iconImage:s.iconImage??null},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"size-full object-contain",fallback:h}):h,e[8]=o,e[9]=h,e[10]=s.iconImage,e[11]=s.id,e[12]=y):y=e[12];let S;return e[13]!==p||e[14]!==v||e[15]!==y?(S=t.jsx("span",{className:p,style:v,children:y}),e[13]=p,e[14]=v,e[15]=y,e[16]=S):S=e[16],S},ai=n=>{const e=ce.c(5),{expanded:s}=n,r=s?"rotate-0":"-rotate-90";let i;e[0]!==r?(i=te("flex size-5 shrink-0 items-center justify-center text-muted-foreground/70 transition-transform duration-150",r),e[0]=r,e[1]=i):i=e[1];let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx(rs,{className:"size-4"}),e[2]=o):o=e[2];let a;return e[3]!==i?(a=t.jsx("span",{"aria-hidden":!0,className:i,children:o}),e[3]=i,e[4]=a):a=e[4],a},Ms=n=>{const e=ce.c(2),{ariaLabel:s}=n;let r;return e[0]!==s?(r=t.jsx("span",{className:"inline-block size-1.5 shrink-0 rounded-full bg-primary","aria-label":s}),e[0]=s,e[1]=r):r=e[1],r},Ls=n=>{const e=ce.c(12),{onClick:s,className:r}=n,{t:i}=ue();let o;e[0]!==i?(o=i("sessions.sidebar.project.actions.newWorktree"),e[0]=i,e[1]=o):o=e[1];const a=o;let u;e[2]!==r?(u=te("flex size-9 shrink-0 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",r),e[2]=r,e[3]=u):u=e[3];let c;e[4]!==s?(c=p=>{p.stopPropagation(),s()},e[4]=s,e[5]=c):c=e[5];let m,f;e[6]===Symbol.for("react.memo_cache_sentinel")?(m={touchAction:"manipulation"},f=t.jsx(ie,{name:"node-tree",className:"size-4"}),e[6]=m,e[7]=f):(m=e[6],f=e[7]);let h;return e[8]!==a||e[9]!==u||e[10]!==c?(h=t.jsx("button",{type:"button",className:u,"aria-label":a,title:a,onClick:c,style:m,children:f}),e[8]=a,e[9]=u,e[10]=c,e[11]=h):h=e[11],h},zs=n=>{const e=ce.c(55),{session:s,active:r,indent:i,contextLabel:o,confirmingArchive:a,hasChildren:u,expanded:c,onToggleChildren:m,onSelect:f,onRequestArchive:h,onConfirmArchive:p}=n,v=a===void 0?!1:a,y=u===void 0?!1:u,S=c===void 0?!1:c,{t:x}=ue();let N;e[0]!==s?(N=oi(At(s)),e[0]=s,e[1]=N):N=e[1];const _=N;let D;e[2]!==s.title||e[3]!==x?(D=s.title?.trim()||x("mobile.sessions.untitled"),e[2]=s.title,e[3]=x,e[4]=D):D=e[4];const T=D,b=r&&!v&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]",w=v&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]";let C;e[5]!==b||e[6]!==w?(C=te("relative flex items-center gap-1 transition-colors",b,w),e[5]=b,e[6]=w,e[7]=C):C=e[7];let P;e[8]!==S||e[9]!==y||e[10]!==i||e[11]!==m||e[12]!==x?(P=y&&m?t.jsx("button",{type:"button",className:"absolute z-10 flex w-6 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",style:{left:Math.max(i-32,2),top:0,bottom:0,touchAction:"manipulation"},"aria-label":x(S?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),onClick:Ee=>{Ee.stopPropagation(),m()},children:t.jsx(rs,{className:te("size-[18px] transition-transform duration-150",S?"rotate-0":"-rotate-90")})}):null,e[8]=S,e[9]=y,e[10]=i,e[11]=m,e[12]=x,e[13]=P):P=e[13];const E=v&&"opacity-50";let g;e[14]!==E?(g=te("flex min-h-12 min-w-0 flex-1 items-center gap-2.5 py-2 pr-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",E),e[14]=E,e[15]=g):g=e[15];let k;e[16]!==i?(k={paddingLeft:i,touchAction:"manipulation"},e[16]=i,e[17]=k):k=e[17];const M=r?"bg-primary":"bg-muted-foreground/30";let V;e[18]!==M?(V=te("size-1.5 shrink-0 rounded-full",M),e[18]=M,e[19]=V):V=e[19];let $;e[20]!==V?($=t.jsx("span",{className:V,"aria-hidden":!0}),e[20]=V,e[21]=$):$=e[21];const j=r?"text-primary":"text-foreground";let A;e[22]!==j?(A=te("block min-w-0 flex-1 truncate typography-ui-label",j),e[22]=j,e[23]=A):A=e[23];let W;e[24]!==A||e[25]!==T?(W=t.jsx("span",{className:A,children:T}),e[24]=A,e[25]=T,e[26]=W):W=e[26];let U;e[27]!==_?(U=_?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:_}):null,e[27]=_,e[28]=U):U=e[28];let q;e[29]!==$||e[30]!==W||e[31]!==U?(q=t.jsxs("span",{className:"flex items-center gap-2.5",children:[$,W,U]}),e[29]=$,e[30]=W,e[31]=U,e[32]=q):q=e[32];let G;e[33]!==o?(G=o?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground pl-4",children:o}):null,e[33]=o,e[34]=G):G=e[34];let z;e[35]!==q||e[36]!==G?(z=t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[q,G]}),e[35]=q,e[36]=G,e[37]=z):z=e[37];let Y;e[38]!==v||e[39]!==f||e[40]!==g||e[41]!==k||e[42]!==z?(Y=t.jsx("button",{type:"button",className:g,style:k,onClick:f,disabled:v,children:z}),e[38]=v,e[39]=f,e[40]=g,e[41]=k,e[42]=z,e[43]=Y):Y=e[43];let R;e[44]!==v||e[45]!==p||e[46]!==h||e[47]!==x||e[48]!==T?(R=h?t.jsxs(t.Fragment,{children:[v?t.jsxs("button",{type:"button",className:"flex h-9 shrink-0 items-center gap-1.5 rounded-xl bg-destructive px-3 text-destructive-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":x("mobile.sessions.archiveSessionAria",{title:T}),onClick:p,style:{touchAction:"manipulation"},children:[t.jsx(bs,{className:"size-4"}),t.jsx("span",{className:"typography-ui-label",children:x("sessions.sidebar.bulkActions.archive")})]}):null,t.jsx("button",{type:"button",className:"mr-1.5 flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":v?x("mobile.sessions.cancelArchiveAria",{title:T}):x("mobile.sessions.archiveSessionAria",{title:T}),onClick:h,style:{touchAction:"manipulation"},children:v?t.jsx(Rt,{className:"size-4"}):t.jsx(bs,{className:"size-4"})})]}):null,e[44]=v,e[45]=p,e[46]=h,e[47]=x,e[48]=T,e[49]=R):R=e[49];let X;return e[50]!==Y||e[51]!==R||e[52]!==C||e[53]!==P?(X=t.jsxs("div",{className:C,children:[P,Y,R]}),e[50]=Y,e[51]=R,e[52]=C,e[53]=P,e[54]=X):X=e[54],X},li=n=>{const e=ce.c(11),{indent:s,onClick:r}=n,{t:i}=ue();let o;e[0]!==s?(o={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(rs,{className:"size-4"}),e[2]=a):a=e[2];let u;e[3]!==i?(u=i("sessions.sidebar.group.showMore"),e[3]=i,e[4]=u):u=e[4];let c;e[5]!==u?(c=t.jsx("span",{className:"typography-micro",children:u}),e[5]=u,e[6]=c):c=e[6];let m;return e[7]!==r||e[8]!==o||e[9]!==c?(m=t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 py-1.5 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",style:o,onClick:r,children:[a,c]}),e[7]=r,e[8]=o,e[9]=c,e[10]=m):m=e[10],m},ci=n=>{const e=ce.c(11),{indent:s,onClick:r}=n,{t:i}=ue();let o;e[0]!==s?(o={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(Un,{className:"size-4"}),e[2]=a):a=e[2];let u;e[3]!==i?(u=i("sessions.sidebar.group.showFewer"),e[3]=i,e[4]=u):u=e[4];let c;e[5]!==u?(c=t.jsx("span",{className:"typography-micro",children:u}),e[5]=u,e[6]=c):c=e[6];let m;return e[7]!==r||e[8]!==o||e[9]!==c?(m=t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 py-1.5 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",style:o,onClick:r,children:[a,c]}),e[7]=r,e[8]=o,e[9]=c,e[10]=m):m=e[10],m},ui=n=>{const e=ce.c(53),{project:s,totalSessions:r,confirmingDelete:i,onEdit:o,onRequestRemove:a,onConfirmRemove:u}=n,{t:c}=ue();let m;e[0]!==s.id?(m={id:s.id},e[0]=s.id,e[1]=m):m=e[1];const{attributes:f,listeners:h,setNodeRef:p,transform:v,transition:y,isDragging:S}=rn(m);let x;e[2]!==v?(x=on.Transform.toString(v),e[2]=v,e[3]=x):x=e[3];const N=S?10:1;let _;e[4]!==x||e[5]!==N||e[6]!==y?(_={transform:x,transition:y,zIndex:N},e[4]=x,e[5]=N,e[6]=y,e[7]=_):_=e[7];const D=_,T=S&&"shadow-lg shadow-black/20",b=i&&"border-destructive/50 bg-[color-mix(in_srgb,var(--destructive)_8%,var(--surface-elevated))]";let w;e[8]!==T||e[9]!==b?(w=te("flex items-center gap-1 rounded-2xl border border-border/40 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",T,b),e[8]=T,e[9]=b,e[10]=w):w=e[10];let C;e[11]!==s.label||e[12]!==c?(C=c("mobile.sessions.dragHandleAria",{label:s.label}),e[11]=s.label,e[12]=c,e[13]=C):C=e[13];let P;e[14]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(an,{className:"size-4"}),e[14]=P):P=e[14];let E;e[15]!==f||e[16]!==h||e[17]!==C?(E=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":C,...f,...h,children:P}),e[15]=f,e[16]=h,e[17]=C,e[18]=E):E=e[18];let g;e[19]!==s?(g=t.jsx(es,{project:s}),e[19]=s,e[20]=g):g=e[20];let k;e[21]!==s.label?(k=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s.label}),e[21]=s.label,e[22]=k):k=e[22];let M;e[23]!==i||e[24]!==u||e[25]!==o||e[26]!==s.label||e[27]!==c||e[28]!==r?(M=i?t.jsxs("button",{type:"button",className:"flex h-9 shrink-0 items-center gap-1.5 rounded-xl bg-destructive px-3 text-destructive-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":c("mobile.sessions.confirmRemoveProjectAria",{label:s.label}),onClick:u,style:{touchAction:"manipulation"},children:[t.jsx(Jt,{className:"size-4"}),t.jsx("span",{className:"typography-ui-label",children:c("mobile.sessions.confirmRemoveProject")})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:r}),t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl 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":c("mobile.sessions.editProjectAria",{label:s.label}),onClick:o,style:{touchAction:"manipulation"},children:t.jsx(ln,{className:"size-4"})})]}),e[23]=i,e[24]=u,e[25]=o,e[26]=s.label,e[27]=c,e[28]=r,e[29]=M):M=e[29];const V=i?"text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:ring-primary":"text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:ring-destructive";let $;e[30]!==V?($=te("flex size-9 shrink-0 items-center justify-center rounded-xl transition-colors focus-visible:outline-none focus-visible:ring-2",V),e[30]=V,e[31]=$):$=e[31];let j;e[32]!==i||e[33]!==s.label||e[34]!==c?(j=i?c("mobile.sessions.cancelRemoveProjectAria",{label:s.label}):c("mobile.sessions.removeProjectAria",{label:s.label}),e[32]=i,e[33]=s.label,e[34]=c,e[35]=j):j=e[35];let A;e[36]===Symbol.for("react.memo_cache_sentinel")?(A={touchAction:"manipulation"},e[36]=A):A=e[36];let W;e[37]!==i?(W=i?t.jsx(Rt,{className:"size-4"}):t.jsx(Jt,{className:"size-4"}),e[37]=i,e[38]=W):W=e[38];let U;e[39]!==a||e[40]!==$||e[41]!==j||e[42]!==W?(U=t.jsx("button",{type:"button",className:$,"aria-label":j,onClick:a,style:A,children:W}),e[39]=a,e[40]=$,e[41]=j,e[42]=W,e[43]=U):U=e[43];let q;return e[44]!==p||e[45]!==D||e[46]!==E||e[47]!==g||e[48]!==k||e[49]!==M||e[50]!==U||e[51]!==w?(q=t.jsxs("div",{ref:p,style:D,className:w,children:[E,g,k,M,U]}),e[44]=p,e[45]=D,e[46]=E,e[47]=g,e[48]=k,e[49]=M,e[50]=U,e[51]=w,e[52]=q):q=e[52],q},di=({open:n,onOpenChange:e})=>{const{t:s}=ue(),{git:r}=Wt(),i=fn(),o=$t(d=>d.activeSessions),a=Ce(d=>d.projects),u=Ce(d=>d.activeProjectId),c=bt(d=>d.currentDirectory),m=be(d=>d.currentSessionId),f=be(d=>d.setCurrentSession),h=be(d=>d.archiveSession),p=be(d=>d.openNewSessionDraft),v=Ce(d=>d.setActiveProject),y=Ce(d=>d.setActiveProjectIdOnly),S=Ce(d=>d.reorderProjects),x=Ce(d=>d.removeProject),N=zt(d=>d.projectExpanded),_=zt(d=>d.worktreeExpanded),D=zt(d=>d.setProjectExpanded),T=zt(d=>d.setWorktreeExpanded),b=yn(d=>d.orderByProject),w=Ts(d=>d.expandedParents),C=Ts(d=>d.toggleParent),[P,E]=l.useState(""),[g,k]=l.useState(null),[M,V]=l.useState(null),[$,j]=l.useState(0),[A,W]=l.useState(!1),[U,q]=l.useState(!1),[G,z]=l.useState(null),[Y,R]=l.useState(new Map),[X,Ee]=l.useState(new Set),[ne,O]=l.useState(!1),[ee,ae]=l.useState(null),[xe,je]=l.useState(new Map);l.useEffect(()=>{if(!n){E(""),O(!1),ae(null),je(new Map),k(null),V(null);return}hr(i)},[n]),l.useEffect(()=>{ne||ae(null)},[ne]),l.useEffect(()=>{if(!n||a.length===0)return;let d=!1;return(async()=>{const F=await Promise.all(a.map(async Z=>{const H=we(Z.path);if(!H)return null;const J=await r.checkIsGitRepository(H).catch(()=>!1),le=J?await bn({id:Z.id,path:H}).catch(()=>[]):[];return[H,le,J]}));if(d)return;const K=new Map,re=new Set;for(const Z of F)Z&&(K.set(Z[0],Z[1]),Z[2]&&re.add(Z[0]));R(K),Ee(re)})(),()=>{d=!0}},[r,n,a,$]);const oe=l.useMemo(()=>a.map(d=>({id:d.id,label:d.label?.trim()||qt(d.path),path:we(d.path),icon:d.icon,color:d.color,iconImage:d.iconImage,iconBackground:d.iconBackground,isGitRepo:X.has(we(d.path)),worktrees:Ho(b[d.id],Y.get(we(d.path))??[])})),[X,a,b,Y]),ve=l.useMemo(()=>{const d=new Map(i.map(K=>[K.id,K])),B=o.map(K=>{const re=d.get(K.id);return re?pr(re,K):K}),F=new Set(B.map(K=>K.id));for(const K of i)F.has(K.id)||B.push(K);return B},[o,i]),de=P.trim().toLowerCase(),fe=l.useMemo(()=>{const d=oe.map(F=>({project:F,buckets:[],totalSessions:0,isActive:F.id===u})),B=(F,K,re)=>{const Z=we(K)||F.project.path,H=Z||"__root__";let J=F.buckets.find(le=>le.key===H);return J||(J={key:H,label:re?.branch||qt(Z),path:Z,worktree:re,sessions:[]},F.buckets.push(J)),J};for(const F of d){B(F,F.project.path,null);for(const K of F.project.worktrees)B(F,K.path,K)}for(const F of ve){const K=dt(F);if(!K)continue;const re=we(K),Z=d.find(le=>Zt(le.project,re));if(!Z)continue;const H=Xt(Z.project,re);(H?B(Z,H.path,H):B(Z,Z.project.path,null)).sessions.push(F)}for(const F of d)for(const K of F.buckets){K.sessions.sort((re,Z)=>At(Z)-At(re));for(const re of K.sessions)Bt(re)||(F.totalSessions+=1)}return d},[u,oe,ve]),ke=we(c),Se=d=>d.isActive?ke===d.project.path?d.project.path:d.project.worktrees.find(F=>ii(ke,F.path))?.path??d.project.path:null,Ve=d=>N[d.project.id]??!0,Me=(d,B)=>_[`${d.project.id}::${B.key}`]??!1,Oe=d=>{je(B=>{if(!B.has(d))return B;const F=new Map(B);return F.delete(d),F})},Fe=d=>{je(B=>{let F=!1;const K=new Map(B),re=`${d}::`;for(const Z of K.keys())Z.startsWith(re)&&(K.delete(Z),F=!0);return F?K:B})},Ge=(d,B)=>{je(F=>{const K=new Map(F);return K.set(d,B+Ht),K})},et=(d,B,F)=>{const K=`${d.project.id}::${B.key}`,re=new Set(B.sessions.map(ge=>ge.id)),Z=new Map;for(const ge of B.sessions){const ze=Bt(ge);if(ze&&re.has(ze)){const Nt=Z.get(ze)??[];Nt.push(ge),Z.set(ze,Nt)}}const H=B.sessions.filter(ge=>{const ze=Bt(ge);return!ze||!re.has(ze)}),J=xe.get(K)??Ht,le=H.slice(0,J),me=H.length-le.length,De=H.length>Ht&&me===0,Te=(ge,ze)=>{const Nt=Z.get(ge.id)??[],Vt=Nt.length>0,ps=!!w[ge.id];return t.jsxs(l.Fragment,{children:[t.jsx(zs,{session:ge,active:m===ge.id,indent:ze,hasChildren:Vt,expanded:ps,onToggleChildren:Vt?()=>C(ge.id):void 0,confirmingArchive:M===ge.id,onSelect:()=>Q(ge),onRequestArchive:()=>pe(ge.id),onConfirmArchive:()=>{Pe(ge)}}),Vt&&ps?Nt.map(Dn=>Te(Dn,ze+ri)):null]},ge.id)};return t.jsxs("div",{children:[le.map(ge=>Te(ge,F)),me>0?t.jsx(li,{indent:F,onClick:()=>Ge(K,le.length)}):null,De?t.jsx(ci,{indent:F,onClick:()=>Oe(K)}):null]})},I=(d,B)=>{D(d,!B),Fe(d)},L=(d,B,F)=>{T(`${d}::${B}`,!F),Oe(`${d}::${B}`)},Q=d=>{const B=dt(d)||null,F=Kt(oe,B??"");F&&y(F.id),f(d.id,B),e(!1)},pe=d=>{V(B=>B===d?null:d)},Pe=async d=>{V(null),await h(d.id)?se.success(s("sessions.sidebar.session.archive.success")):se.error(s("sessions.sidebar.session.archive.error"))},Ae=()=>{p(),e(!1)},He=d=>{z(d),y(d),q(!0)},$e=Qs(Ft(Xs,{activationConstraint:{distance:8}}),Ft(Js,{coordinateGetter:Ys})),Le=d=>{const{active:B,over:F}=d;if(ae(null),!F||B.id===F.id)return;const K=oe.findIndex(Z=>Z.id===B.id),re=oe.findIndex(Z=>Z.id===F.id);K<0||re<0||S(K,re)},lt=d=>{ae(B=>B===d?null:d)},qe=d=>{x(d.id),ae(null),se.success(s("mobile.sessions.toast.projectRemoved",{label:d.label}))},ct=l.useCallback(d=>{const B=dt(d),F=Kt(oe,B);if(!F)return qt(B)||B;const K=Xt(F,we(B));return K?.branch?`${F.label} · ${K.branch}`:F.label},[oe]),Ke=d=>{v(d.id),e(!1)},Qe=l.useMemo(()=>de?fe.filter(d=>`${d.project.label} ${d.project.path}`.toLowerCase().includes(de)?!0:d.buckets.some(B=>B.sessions.some(F=>Qt(F,d.project.label,de)))):fe,[de,fe]),_e=l.useMemo(()=>de?ve.filter(d=>{const B=dt(d),F=Kt(oe,B);return Qt(d,F?.label??"",de)}).sort((d,B)=>At(B)-At(d)):[],[de,oe,ve]),Ye=l.useMemo(()=>de?oe.filter(d=>`${d.label} ${d.path}`.toLowerCase().includes(de)).map(d=>({...d,sessionCount:ve.filter(B=>{if(Bt(B))return!1;const F=we(dt(B));return Zt(d,F)}).length})):[],[de,oe,ve]),ut=de&&_e.length===0&&Ye.length===0,tt=!de&&oe.length>1?t.jsx(he,{type:"button",variant:"chip",size:"sm","aria-label":s(ne?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":ne,onClick:()=>O(d=>!d),style:{touchAction:"manipulation"},children:ne?t.jsx(nn,{className:"size-4"}):t.jsx(ln,{className:"size-4"})}):null,We=!ne&&oe.length>0?t.jsxs(he,{type:"button",variant:"default",size:"sm","aria-label":s("mobile.sessions.newChat"),onClick:Ae,style:{touchAction:"manipulation"},children:[t.jsx(Wn,{className:"size-4"}),s("mobile.sessions.newChat")]}):null,Ue=ne?null:t.jsx(he,{type:"button",variant:"chip",size:"sm","aria-label":s("sessions.sidebar.header.actions.addProject"),title:s("sessions.sidebar.header.actions.addProject"),onClick:()=>W(!0),style:{touchAction:"manipulation"},children:t.jsx(gs,{className:"size-4"})}),Je=We||Ue||tt?t.jsxs(t.Fragment,{children:[We,Ue,tt]}):null;return t.jsx(ot,{open:n,onClose:()=>e(!1),ariaLabel:s("mobile.sessions.sheet.title"),title:s("mobile.sessions.sheet.title"),trailing:Je,children:t.jsxs("div",{className:"flex h-full flex-col",children:[t.jsx("div",{className:te("shrink-0 px-4 pb-2 pt-1",ne&&"hidden"),children:t.jsxs("div",{className:"relative",children:[t.jsx(qs,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(as,{value:P,onChange:d=>E(d.target.value),placeholder:s("mobile.sessions.search.placeholder"),className:te("h-11 pl-9",P&&"pr-10")}),P?t.jsx("button",{type:"button",className:"absolute right-1.5 top-1/2 flex size-8 -translate-y-1/2 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":s("mobile.sessions.clearSearchAria"),onClick:()=>E(""),style:{touchAction:"manipulation"},children:t.jsx(Rt,{className:"size-4"})}):null]})}),t.jsx(at,{className:"min-h-0 flex-1 overflow-y-auto pb-4",children:oe.length===0?t.jsx(Bs,{title:s("mobile.sessions.empty.noProjectsTitle"),description:s("mobile.sessions.empty.noProjectsDescription"),action:t.jsxs("button",{type:"button",className:"flex items-center justify-center gap-2 rounded-2xl bg-primary px-5 py-3 typography-ui-label text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>W(!0),children:[t.jsx(gs,{className:"size-4"}),s("sessions.sidebar.header.actions.addProject")]})}):ut?t.jsx(Bs,{title:s("mobile.sessions.empty.searchTitle"),description:s("mobile.sessions.empty.searchDescription")}):de&&!ne?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[_e.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:s("mobile.sessions.search.section.sessions")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:_e.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",children:_e.map((d,B)=>t.jsx("div",{className:te(B>0&&"border-t border-border/30"),children:t.jsx(zs,{session:d,active:m===d.id,indent:12,contextLabel:ct(d),onSelect:()=>Q(d)})},d.id))})]}):null,Ye.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:s("mobile.sessions.search.section.projects")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:Ye.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/40 bg-[var(--surface-elevated)]",children:Ye.map((d,B)=>t.jsxs("div",{className:te("flex items-center",B>0&&"border-t border-border/30"),children:[t.jsxs("button",{type:"button",className:"flex min-h-14 min-w-0 flex-1 items-center gap-3 px-3 py-2 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>Ke(d),style:{touchAction:"manipulation"},children:[t.jsx(es,{project:d}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:d.label}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:d.sessionCount})]}),d.isGitRepo?t.jsx(Ls,{className:"mr-2",onClick:()=>He(d.id)}):null]},d.id))})]}):null]}):ne?t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2",children:[t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:s("mobile.sessions.editOrderHint")}),t.jsx(Zs,{sensors:$e,collisionDetection:en,onDragEnd:Le,children:t.jsx(tn,{items:oe.map(d=>d.id),strategy:sn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:oe.map(d=>{const B=fe.find(F=>F.project.id===d.id);return t.jsx(ui,{project:d,totalSessions:B?.totalSessions??0,confirmingDelete:ee===d.id,onEdit:()=>k(d.id),onRequestRemove:()=>lt(d.id),onConfirmRemove:()=>qe(d)},d.id)})})})})]}):t.jsx("div",{className:"flex flex-col",children:Qe.map((d,B)=>{const F=Ve(d),K=de?d.buckets.filter(Z=>Z.sessions.some(H=>Qt(H,d.project.label,de))):d.buckets,re=Se(d);return t.jsxs("section",{className:te(B>0&&"border-t border-border/30"),children:[t.jsxs("div",{className:"flex min-h-14 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-14 min-w-0 flex-1 items-center gap-2 px-3 py-2 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>I(d.project.id,F),"aria-expanded":F,"aria-label":F?s("sessions.sidebar.group.collapseAria",{label:d.project.label}):s("sessions.sidebar.group.expandAria",{label:d.project.label}),style:{touchAction:"manipulation"},children:[t.jsx(es,{project:d.project}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:d.project.label}),d.isActive?t.jsx(Ms,{ariaLabel:s("mobile.sessions.activeProjectAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:d.totalSessions})]}),d.project.isGitRepo?t.jsx(Ls,{className:"mr-2",onClick:()=>He(d.project.id)}):null]}),F?t.jsx("div",{className:"pb-2",children:(()=>{const Z=K.find(J=>J.worktree===null),H=K.filter(J=>J.worktree!==null);return t.jsxs(t.Fragment,{children:[Z&&Z.sessions.length>0?et(d,Z,si):null,H.map(J=>{const le=Me(d,J),me=re===J.path;return t.jsxs("div",{children:[t.jsxs("button",{type:"button",className:"flex min-h-11 w-full items-center gap-2 py-1.5 pl-4 pr-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",onClick:()=>L(d.project.id,J.key,le),"aria-expanded":le,"aria-label":le?s("sessions.sidebar.group.collapseAria",{label:J.label}):s("sessions.sidebar.group.expandAria",{label:J.label}),style:{touchAction:"manipulation"},children:[t.jsx(ai,{expanded:le}),t.jsx(ie,{name:"node-tree",className:te("size-4 shrink-0",me?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:te("block min-w-0 flex-1 truncate typography-ui-label font-semibold",me?"text-foreground":"text-foreground/90"),children:J.label}),me?t.jsx(Ms,{ariaLabel:s("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:J.sessions.length})]}),le?et(d,J,ni):null]},J.key)})]})})()}):null]},d.project.id)})})}),t.jsx(no,{open:A,onOpenChange:W}),t.jsx(ro,{open:U,onOpenChange:d=>{q(d),d||z(null)},onWorktreeCreated:(d,B)=>{B?.sessionId?f(B.sessionId,d):p({selectedProjectId:G,directoryOverride:d,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(ti,{open:g!==null,project:oe.find(d=>d.id===g)??null,onClose:()=>k(null),onWorktreesChanged:()=>j(d=>d+1)})]})})},Bs=n=>{const e=ce.c(10),{title:s,description:r,action:i}=n;let o;e[0]!==s?(o=t.jsx("p",{className:"typography-ui-label text-foreground",children:s}),e[0]=s,e[1]=o):o=e[1];let a;e[2]!==r?(a=r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r}):null,e[2]=r,e[3]=a):a=e[3];let u;e[4]!==i?(u=i?t.jsx("div",{className:"pt-2",children:i}):null,e[4]=i,e[5]=u):u=e[5];let c;return e[6]!==o||e[7]!==a||e[8]!==u?(c=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[o,a,u]}),e[6]=o,e[7]=a,e[8]=u,e[9]=c):c=e[9],c},cs="openchamber.mobile.connections.v1",fi="openchamber.mobile.",wn=12,Os=8e3,mi=2500,hi=3e3,Dt=n=>{const e=n.trim();if(!e)return"";const s=/^https?:\/\//i.test(e)?e:`http://${e}`,r=new URL(s);return r.hash="",r.search="",r.pathname=r.pathname.replace(/\/+$/,""),r.toString().replace(/\/+$/,"")},ts=n=>{try{return new URL(n).host}catch{return n}},pt=n=>{try{return Dt(n)}catch{return n.trim().replace(/\/+$/g,"")}},Ot=(n,e)=>pt(n)===pt(e),nt=(n,e={})=>{console.info("[mobile-connect]",n,e)},yt=(n,e={})=>{console.info("[mobile-storage]",n,e)},pi=n=>{if(typeof n!="string")return n;try{return JSON.parse(n)}catch{return n}},gi=n=>{if(typeof n!="string")return n??void 0;try{return JSON.parse(n)}catch{return n}},bi=async(n,e)=>{if(!ye())return null;try{const{CapacitorHttp:s}=await Be(async()=>{const{CapacitorHttp:o}=await import("./vendor-.bun-C6iL44L9.js").then(a=>a.cq);return{CapacitorHttp:o}},[]),r=Object.fromEntries(new Headers(e?.headers).entries()),i=await s.request({url:n,method:e?.method||"GET",headers:r,data:gi(e?.body)});return{ok:i.status>=200&&i.status<300,status:i.status,source:"native-http",json:async()=>pi(i.data)}}catch(s){return console.warn("[mobile-connect] native-http failed",{url:n,error:s}),null}},xi=async(n,e)=>{const s=await fetch(n,e).catch(r=>(console.warn("[mobile-connect] browser-fetch failed",{url:n,error:r}),null));return s?{ok:s.ok,status:s.status,source:"browser-fetch",json:()=>s.json()}:null},Fs=async(n,e,s)=>{let r;const i=new Promise(o=>{r=window.setTimeout(()=>{s?.(),o(null)},n)});try{return await Promise.race([e,i])}catch{return null}finally{r!==void 0&&window.clearTimeout(r)}},it=async(n,e)=>{const s=Date.now(),r=await Fs(Math.min(mi,Os),bi(n,e));if(r)return r;const i=new AbortController,o=Math.max(1e3,Os-(Date.now()-s));return Fs(o,xi(n,{...e,signal:i.signal}),()=>i.abort())},us=async n=>{if(!n)return null;const e=await n.json().catch(()=>null);if(!e||typeof e!="object")return null;const s=e;return{authenticated:typeof s.authenticated=="boolean"?s.authenticated:void 0,disabled:typeof s.disabled=="boolean"?s.disabled:void 0,scope:typeof s.scope=="string"?s.scope:void 0}},jt=()=>{if(typeof window>"u")return[];let n;try{n=JSON.parse(window.localStorage.getItem(cs)||"[]")}catch{return[]}if(!Array.isArray(n))return[];const e=ye();return n.flatMap(s=>{if(!s||typeof s!="object")return[];const r=s;if(typeof r.id!="string"||typeof r.url!="string")return[];const i=typeof r.clientToken=="string"&&r.clientToken.trim()?r.clientToken:void 0,o={id:r.id,label:typeof r.label=="string"&&r.label.trim()?r.label:ts(r.url),url:r.url,lastUsedAt:typeof r.lastUsedAt=="number"?r.lastUsedAt:0};return e?[{...o,hasToken:!!r.hasToken||!!i}]:[{...o,clientToken:i,hasToken:!!i}]}).sort((s,r)=>r.lastUsedAt-s.lastUsedAt)},Ut=n=>{if(typeof window>"u")return;const e=ye(),s=n.slice(0,wn).map(r=>e?{id:r.id,label:r.label,url:r.url,lastUsedAt:r.lastUsedAt,hasToken:!!(r.hasToken||r.clientToken)}:{id:r.id,label:r.label,url:r.url,lastUsedAt:r.lastUsedAt,clientToken:r.clientToken});try{window.localStorage.setItem(cs,JSON.stringify(s))}catch(r){console.warn("[mobile-storage] failed to persist connection metadata",r)}},jn=(n,e)=>{const s=pt(e.url),r=n.find(a=>pt(a.url)===s),i=ye(),o={id:r?.id||crypto.randomUUID(),label:e.label,url:e.url,lastUsedAt:Date.now(),...i?{hasToken:e.hasToken??(!!e.clientToken||r?.hasToken||!1)}:{clientToken:e.clientToken??r?.clientToken,hasToken:!!(e.clientToken??r?.clientToken)}};return[o,...n.filter(a=>a.id!==o.id&&pt(a.url)!==s)].slice(0,wn)},ds=Vn,vi=0,fs=n=>`${fi}token.${encodeURIComponent(pt(n))}`,yi=async(n,e)=>{let s;const r=new Promise(i=>{s=window.setTimeout(()=>i(e),hi)});try{return await Promise.race([n.catch(()=>e),r])}finally{s!==void 0&&window.clearTimeout(s)}},ms=async(n,e,s)=>ye()?yi(e().catch(r=>(console.warn(`[mobile-storage] ${n} failed`,r),s)),s):s,kn=async n=>{yt("secure:read-start",{url:n});const e=await ms("secure:read",async()=>(await ds.internalGetItem({prefixedKey:fs(n),sync:!1})).data,null),s=typeof e=="string"&&e.trim()?e:void 0;return yt("secure:read",{url:n,hasToken:!!s}),s},Tt=async(n,e)=>{yt("secure:write-start",{url:n});const s=await ms("secure:write",async()=>(await ds.internalSetItem({prefixedKey:fs(n),data:e,sync:!1,access:vi}),!0),!1);return yt("secure:write",{url:n,ok:s}),s},wi=async n=>{await ms("secure:delete",async()=>(await ds.internalRemoveItem({prefixedKey:fs(n),sync:!1}),!0),!1)},Sn=async()=>{if(typeof window>"u"||!ye())return;let n;try{n=JSON.parse(window.localStorage.getItem(cs)||"[]")}catch{return}if(!Array.isArray(n))return;const e=n.filter(s=>!!s&&typeof s=="object"&&typeof s.url=="string"&&typeof s.clientToken=="string"&&!!s.clientToken.trim());if(e.length!==0){yt("secure:migrate-start",{count:e.length});for(const{url:s,clientToken:r}of e)await Tt(s,r);Ut(jt()),yt("secure:migrate-done",{count:e.length})}},ji=async()=>(await Sn(),jt()),ki=async n=>{const e=jn(jt(),n);return Ut(e),ye()&&n.clientToken&&await Tt(n.url,n.clientToken),e},Si=async n=>{const e=jt(),s=e.find(i=>i.id===n)??null,r=e.filter(i=>i.id!==n);return Ut(r),s&&ye()&&await wi(s.url),r},Ni=async()=>{await Sn();const n=jt()[0];if(!n)return!1;const e=Dt(n.url);if(!e)return!1;let s;if(ye()){if(!n.hasToken||(s=await kn(e),!s))return!1}else s=n.clientToken;const r=s?{Authorization:`Bearer ${s}`}:void 0;if(!(await it(`${e}/health`,{method:"GET",headers:r}))?.ok)return!1;const o=await it(`${e}/auth/session`,{method:"GET",credentials:"include",headers:r});if(!o||!o.ok&&o.status!==404)return!1;const a=await us(o);return a&&a.disabled!==!0&&a.authenticated===!1?!1:(await ki({label:n.label,url:e}),ht({apiBaseUrl:e,clientToken:s??null}),!0)},Ci=async n=>{let e="";try{e=Dt(n.url)}catch{return!1}if(!e)return!1;const s=n.clientToken?.trim()||void 0,r=s?{Authorization:`Bearer ${s}`}:void 0;if(!(await it(`${e}/health`,{method:"GET",headers:r}))?.ok)return!1;const o=await it(`${e}/auth/session`,{method:"GET",credentials:"include",headers:r});if(!o||!o.ok&&o.status!==404)return!1;const a=await us(o);return!(a&&a.disabled!==!0&&a.authenticated===!1)},Nn=n=>{const{t:e}=ue(),[s,r]=l.useState(()=>jt()),[i,o]=l.useState(null),[a,u]=l.useState(null),[c,m]=l.useState(null),f=l.useRef(s),h=l.useRef(null),p=l.useCallback(b=>{f.current=b,r(b)},[]),v=l.useCallback(b=>{h.current=b,o(b)},[]),y=l.useCallback(b=>{h.current===b&&(h.current=null,o(null))},[]);l.useEffect(()=>{let b=!1;return ji().then(w=>{b||p(w)}),()=>{b=!0}},[p]);const S=l.useCallback(b=>{const w=jn(f.current,b);return p(w),Ut(w),w},[p]),x=l.useCallback(async b=>{u(null),v("connect");try{const w=Dt(b.url);if(!w){u(e("mobile.connect.error.urlRequired"));return}const C=b.label?.trim()||f.current.find(j=>Ot(j.url,w))?.label||ts(w);let P=b.clientToken?.trim()||void 0;const E=!!P;!P&&ye()&&f.current.find(A=>Ot(A.url,w))?.hasToken&&(P=await kn(w));const g=P?{Authorization:`Bearer ${P}`}:void 0;nt("health:start",{url:w});const k=await it(`${w}/health`,{method:"GET",headers:g});if(nt("health:done",{ok:k?.ok===!0,source:k?.source??null,status:k?.status??null}),!k?.ok){u(e("mobile.connect.error.unreachable"));return}nt("session:start",{url:w,hasToken:!!P});const M=await it(`${w}/auth/session`,{method:"GET",credentials:"include",headers:g}),V=await us(M);nt("session:done",{ok:M?.ok===!0,status:M?.status??null,scope:V?.scope??null,disabled:V?.disabled===!0});const $=ye()&&M?.ok===!0&&!P&&V?.authenticated===!0&&V.disabled!==!0&&V.scope!=="client";if(!P&&(M?.status===401||$)){S({label:C,url:w}),m({label:C,url:w});return}if(!M||!M.ok&&M.status!==404){u(e("mobile.connect.error.authRequired"));return}P&&E&&ye()&&await Tt(w,P),S({label:C,url:w,clientToken:P}),ht({apiBaseUrl:w,clientToken:P??null}),n()}catch(w){console.warn("[mobile-connect] connect threw",w),u(e("mobile.connect.error.invalidUrl"))}finally{y("connect")}},[v,y,n,S,e]),N=l.useCallback(async b=>{if(!c||!b.trim()||h.current==="password")return;u(null),v("password");const{url:w,label:C}=c;try{nt("password:start",{url:w});const P=await it(`${w}/auth/session`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:b,trustDevice:!0,issueClientToken:!0,clientLabel:"OpenChamber Mobile"})});if(nt("password:done",{ok:P?.ok===!0,status:P?.status??null}),!P?.ok){u(e("mobile.connect.error.passwordFailed"));return}const E=await P.json().catch(()=>null),g=typeof E?.clientToken=="string"?E.clientToken.trim():"";if(nt("password:token",{issued:!!g}),ye()&&!g){u(e("mobile.connect.error.authRequired"));return}ye()&&g&&await Tt(w,g),S({label:C,url:w,clientToken:g||void 0}),m(null),ht({apiBaseUrl:w,clientToken:g||null}),n()}catch(P){console.warn("[mobile-connect] password threw",P),u(e("mobile.connect.error.passwordFailed"))}finally{y("password")}},[v,y,n,c,S,e]),_=l.useCallback(()=>{m(null),u(null)},[]),D=l.useCallback(async b=>{u(null);const w=Dt(b.url);if(!w)return u(e("mobile.connect.error.urlRequired")),null;const C=b.clientToken?.trim()||void 0,P=b.label?.trim()||ts(w);return ye()&&C&&await Tt(w,C),S({label:P,url:w,clientToken:C}).find(g=>Ot(g.url,w))??null},[S,e]),T=l.useCallback(async b=>{const w=f.current.find(P=>P.id===b)??null,C=await Si(b);return p(C),w},[p]);return{connections:s,isBusy:i!==null,isPasswordBusy:i==="password",error:a,pendingConnection:c,connect:x,submitPassword:N,cancelPassword:_,saveConnection:D,removeConnection:T,setError:u}},Ei=4,Pi=3,Ai=5,_i=9e4,Ti=async n=>{window.Capacitor?.getPlatform?.()!=="android"||!n.isGoogleBarcodeScannerModuleAvailable||!n.installGoogleBarcodeScannerModule||(await n.isGoogleBarcodeScannerModuleAvailable().catch(()=>{}))?.available||await new Promise((r,i)=>{let o;const a=c=>{window.clearTimeout(u),o?.remove(),c()},u=window.setTimeout(()=>a(()=>i(new Error("module install timed out"))),_i);Promise.resolve(n.addListener?.("googleBarcodeScannerModuleInstallProgress",c=>{c?.state===Ei?a(r):(c?.state===Pi||c?.state===Ai)&&a(()=>i(new Error("module install failed")))})).then(c=>{o=c}).catch(()=>{}),Promise.resolve(n.installGoogleBarcodeScannerModule?.()).catch(c=>a(()=>i(c instanceof Error?c:new Error("module install failed"))))})},Cn=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&typeof e.scan=="function"?e:null},En=n=>{const e=n.trim();if(!e)return null;if(/^openchamber:\/\//i.test(e))try{const s=new URL(e),r=s.searchParams.get("server")?.trim();if(!r)return null;const i=s.searchParams.get("token")?.trim(),o=s.searchParams.get("label")?.trim();return{url:r,clientToken:i||void 0,label:o||void 0}}catch{return null}return/^https?:\/\//i.test(e)?{url:e}:null},Di=n=>{const e=typeof n=="object"&&n&&"message"in n?String(n.message??""):String(n??"");return/module/i.test(e)&&/not\s*available|unavailable/i.test(e)},Pn=()=>Cn()!==null,An=async()=>{const n=Cn();if(!n?.scan)return{status:"unsupported"};try{if(n.requestPermissions){const s=(await n.requestPermissions())?.camera;if(s&&s!=="granted"&&s!=="limited")return{status:"permission-denied"}}for(let e=0;e<3;e++)try{await Ti(n);const r=(await n.scan({formats:["QR_CODE"]}))?.barcodes?.[0],i=(r?.rawValue??r?.displayValue??"").trim();if(!i)return{status:"cancelled"};const o=En(i);return o?{status:"ok",...o}:{status:"invalid"}}catch(s){if(!Di(s)||e===2)return{status:"failed"};await new Promise(r=>window.setTimeout(r,600))}return{status:"failed"}}catch{return{status:"failed"}}};function Ii(n){const e=ce.c(4),s=2500,{uiFont:r}=gr(),[i,o]=l.useState(!1);let a,u;return e[0]!==s||e[1]!==r?(a=()=>{let c=!1;const m=()=>{c||o(!0)},f=()=>{requestAnimationFrame(()=>requestAnimationFrame(m))},h=Promise.all([br(r).catch(Bi),document.fonts?.ready?.then(zi).catch(Li)??Promise.resolve(),wo.catch(Mi)]).then(Ri),p=new Promise(v=>{window.setTimeout(v,s)});return Promise.race([h,p]).then(f),()=>{c=!0}},u=[r,s],e[0]=s,e[1]=r,e[2]=a,e[3]=u):(a=e[2],u=e[3]),l.useEffect(a,u),i}function Ri(){}function Mi(){}function Li(){}function zi(){}function Bi(){}const Oi="openchamber",Fi=n=>n.replace(/^\/+|\/+$/g,""),$i=n=>{const e=Fi(n.pathname).split("/").filter(Boolean);return n.host?[n.host,...e]:e};function Wi(n){if(typeof n!="string"||n.length===0)return null;let e;try{e=new URL(n)}catch{return null}if(e.protocol!==`${Oi}:`)return null;const s=$i(e),r=(s[0]??"").toLowerCase(),i=s.slice(1),o=e.searchParams;switch(r){case"session":{const a=i[0]||o.get("id")||"";return a?{type:"session",sessionId:a,directory:o.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:o.get("dir")??void 0,projectId:o.get("project")??void 0,agent:o.get("agent")??void 0,model:o.get("model")??void 0};case"sessions":{const a=o.get("filter");return{type:"sessions",filter:a==="attention"||a==="recent"||a==="all"?a:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:i[0]||o.get("section")||void 0};case"changes":return{type:"changes",path:i.join("/")||o.get("path")||void 0,staged:o.get("staged")==="true"};case"view":{const a=(i[0]||"").toLowerCase();return a==="changes"?{type:"changes"}:a==="files"||a==="mcp"||a==="instances"||a==="update"?{type:"view",target:a}:null}default:return null}}let Re={},_n=!1,_t=null;const Ui=n=>{switch(n.type){case"session":return be.getState().setCurrentSession(n.sessionId,n.directory??null),!0;case"new-session":{const e=be.getState();return e.openNewSessionDraft(),(n.directory||n.projectId)&&e.setNewSessionDraftTarget({directoryOverride:n.directory??null,projectId:n.projectId??null,selectedProjectId:n.projectId??null}),!0}case"sessions":return Re.openSessions?(Re.openSessions(n.filter),!0):!1;case"status":return wt.getState().setMobileSessionPanelOpen(!0),!0;case"view":return Re.openView?(Re.openView(n.target),!0):!1;case"changes":return Re.openChanges?(Re.openChanges({path:n.path,staged:n.staged}),!0):!1;case"settings":return Re.openSettings?(Re.openSettings(n.section),!0):!1}},hs=()=>{if(!_n||!_t)return;const n=_t;_t=null,Ui(n)||(_t=n)},Tn=n=>{_t=n,hs()},$s=n=>{const e=Wi(n);e&&Tn(e)},Vi=n=>{_n=n,hs()},Gi=n=>{const e=ce.c(3);let s,r;e[0]!==n?(s=()=>(Re=n,hs(),()=>{Re===n&&(Re={})}),r=[n],e[0]=n,e[1]=s,e[2]=r):(s=e[1],r=e[2]),l.useEffect(s,r)},Hi=n=>{const{ready:e}=n;l.useEffect(()=>{Vi(e)},[e]),l.useEffect(()=>{if(!ye())return;let s=!1;const r=[];return Be(()=>import("./vendor-.bun-C6iL44L9.js").then(i=>i.cr),[]).then(async({App:i})=>{if(s)return;const o=await i.addListener("appUrlOpen",a=>{$s(a?.url)});if(s){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),Be(()=>import("./vendor-.bun-C6iL44L9.js").then(i=>i.cs),[]).then(async({PushNotifications:i})=>{if(s)return;const o=await i.addListener("pushNotificationActionPerformed",a=>{const u=a?.notification?.data,c=typeof u?.url=="string"?u.url:typeof u?.deeplink=="string"?u.deeplink:void 0;if(c){$s(c);return}const m=typeof u?.sessionId=="string"?u.sessionId:void 0;m&&Tn({type:"session",sessionId:m})});if(s){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),()=>{s=!0,r.forEach(i=>i())}},[])},Ws=32,qi=64,Ki=.7,Qi=n=>n.parentID??null,Us=n=>n.time?.updated??n.time?.created??0,Yi=()=>$t.getState().activeSessions.filter(n=>Qi(n)===null).slice().sort((n,e)=>Us(e)-Us(n)),Ji=n=>{const e=Yi();if(e.length<2)return!1;const s=be.getState().currentSessionId,r=e.findIndex(a=>a.id===s);if(r<0)return!1;const i=r+n;if(i<0||i>=e.length)return!1;const o=e[i];return be.getState().setCurrentSession(o.id,cn(o)),!0},Xi=(n,e)=>{const s=l.useRef(e?.onSwitch);s.current=e?.onSwitch,l.useEffect(()=>{const r=n.current;if(!r)return;let i=!1,o=!1,a=0,u=0;const c=f=>{if(f.touches.length!==1){i=!1;return}const h=f.touches[0],p=r.clientWidth,v=h.clientX<=Ws,y=h.clientX>=p-Ws;i=v||y,o=v,a=h.clientX,u=h.clientY},m=f=>{if(!i)return;i=!1;const h=f.changedTouches[0];if(!h)return;const p=h.clientX-a,v=h.clientY-u;if(Math.abs(p)<qi||Math.abs(v)>Math.abs(p)*Ki||o&&p<=0||!o&&p>=0)return;const y=o?-1:1;Ji(y)&&s.current?.(y<0?"prev":"next")};return r.addEventListener("touchstart",c,{passive:!0}),r.addEventListener("touchend",m,{passive:!0}),()=>{r.removeEventListener("touchstart",c),r.removeEventListener("touchend",m)}},[n])},Zi=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},ea=n=>{const{enabled:e}=n,s=wt(i=>i.nativeNotificationsEnabled),r=l.useRef(null);l.useEffect(()=>{if(!e||!s||!Zi())return;let i=!1;const o=[];return Be(()=>import("./vendor-.bun-C6iL44L9.js").then(a=>a.cs),[]).then(async({PushNotifications:a})=>{if(i)return;let u=await a.checkPermissions().catch(()=>null);if(u?.receive!=="granted"&&(u=await a.requestPermissions().catch(()=>null)),u?.receive!=="granted")return;const c=await a.addListener("registration",f=>{r.current=f.value,xs()?.push?.registerApnsToken?.({token:f.value,platform:xr()})}),m=await a.addListener("registrationError",f=>{console.warn("[Push] APNs registration error:",f)});if(await a.register().catch(()=>{}),i){c.remove(),m.remove();return}o.push(()=>{c.remove()},()=>{m.remove()})}).catch(()=>{}),()=>{i=!0,o.forEach(a=>a())}},[e,s]),l.useEffect(()=>{if(s)return;const i=r.current;if(!i)return;r.current=null,xs()?.push?.unregisterApnsToken?.({token:i})},[s])},ta=["appearance","chat","notifications","sessions","git","magic-prompts","behavior","mcp","providers","usage","voice","about"],Mt=()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0?!0:window.location.protocol==="capacitor:",sa=()=>{l.useEffect(()=>{if(!Mt())return;let n=!1;const e=[],s=document.documentElement;s.classList.add("oc-capacitor-app"),window.Capacitor?.getPlatform?.()==="android"&&s.classList.add("oc-platform-android");const i=o=>{s.style.setProperty("--oc-keyboard-inset",`${Math.max(0,Math.round(o))}px`)};return Be(()=>import("./vendor-.bun-C6iL44L9.js").then(o=>o.ct),[]).then(async({StatusBar:o,Style:a})=>{if(n)return;const u=window.Capacitor?.getPlatform?.(),c=async()=>{if(u==="android"){const p=document.documentElement.classList.contains("dark"),v=(p?localStorage.getItem("splashBgDark"):localStorage.getItem("splashBgLight"))||(p?"#171515":"#fffdf4");await o.setOverlaysWebView({overlay:!1}).catch(()=>{}),await o.setBackgroundColor({color:v}).catch(()=>{}),await o.setStyle({style:p?a.Dark:a.Light}).catch(()=>{}),await o.show().catch(()=>{});return}await o.setStyle({style:a.Default}).catch(()=>{}),await o.setOverlaysWebView({overlay:!0}).catch(()=>{}),await o.show().catch(()=>{})};await c();const m=window.setTimeout(()=>{c()},400);e.push(()=>window.clearTimeout(m));const{App:f}=await Be(async()=>{const{App:p}=await import("./vendor-.bun-C6iL44L9.js").then(v=>v.cr);return{App:p}},[]),h=await f.addListener("appStateChange",({isActive:p})=>{p&&c()});if(n){h.remove();return}e.push(()=>{h.remove()})}).catch(()=>{}),Be(()=>import("./vendor-.bun-C6iL44L9.js").then(o=>o.cu),[]).then(async({Keyboard:o})=>{if(n)return;if(window.Capacitor?.getPlatform?.()==="android"){const g=await o.addListener("keyboardWillShow",()=>{s.classList.add("oc-keyboard-open"),window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),k=await o.addListener("keyboardDidShow",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),M=await o.addListener("keyboardWillHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-intent",{detail:{open:!1}})),s.classList.remove("oc-keyboard-open")}),V=await o.addListener("keyboardDidHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!1}}))}),$=()=>{g.remove(),k.remove(),M.remove(),V.remove()};if(n){$();return}e.push($);return}await o.setAccessoryBarVisible({isVisible:!1}).catch(()=>{});const u=250,c=200,m="cubic-bezier(0.38, 0.7, 0.125, 1)";let f=null,h=null,p=0,v=!1,y=0,S=!1;const x=(g,k)=>{s.style.setProperty(g,`${Math.max(0,Math.round(k))}px`)},N=()=>{f!==null&&(window.clearTimeout(f),f=null)},_=(g,k)=>{window.dispatchEvent(new CustomEvent(g,{detail:k}))},D=()=>{const g=[],k=document.querySelector(".oc-mobile-composer");k&&g.push({el:k,factor:1});const M=document.querySelector(".oc-draft-center");return M&&g.push({el:M,factor:.5}),g},T=()=>{for(const{el:g}of D())g.style.transition="",g.style.transform=""},b=await o.addListener("keyboardWillShow",g=>{if(N(),S=!0,p=g.keyboardHeight,!v){const M=document.querySelector(".oc-mobile-app-shell");y=M&&parseFloat(getComputedStyle(M).paddingBottom)||0}const k=Math.max(0,p-y);s.classList.remove("oc-kb-hide"),h!==null&&(window.clearTimeout(h),h=null),s.classList.add("oc-keyboard-open","oc-kb-animating","oc-kb-caret-hold"),i(p);for(const{el:M,factor:V}of D())M.style.transition=`transform ${u}ms ${m}`,M.style.transform=`translateY(${-k*V}px)`;x("--oc-kb-scroll-inset",k),_("oc:keyboard-settled",{open:!0}),_("oc:keyboard-anim",{phase:"show",slide:k,durationMs:u,easing:m}),f=window.setTimeout(()=>{f=null,s.classList.remove("oc-kb-animating"),x("--oc-kb-layout",p),v=!0,T(),_("oc:keyboard-settled",{open:!0}),h=window.setTimeout(()=>{h=null,s.classList.remove("oc-kb-caret-hold")},250)},u+20)}),w=()=>{if(!S)return;S=!1,N(),_("oc:keyboard-intent",{open:!1}),h!==null&&(window.clearTimeout(h),h=null),s.classList.remove("oc-kb-caret-hold");const g=Math.max(0,p-y);if(s.classList.remove("oc-keyboard-open"),i(0),x("--oc-kb-scroll-inset",0),v){s.classList.remove("oc-kb-animating"),x("--oc-kb-layout",0),v=!1;for(const{el:k,factor:M}of D())k.style.transition="none",k.style.transform=`translateY(${-g*M}px)`;document.querySelector(".oc-mobile-app-shell")?.offsetHeight}_("oc:keyboard-anim",{phase:"hide",slide:g,durationMs:c,easing:m}),s.classList.add("oc-kb-animating","oc-kb-hide");for(const{el:k}of D())k.style.transition=`transform ${c}ms ${m}`,k.style.transform="translateY(0px)";f=window.setTimeout(()=>{f=null,s.classList.remove("oc-kb-animating","oc-kb-hide"),T(),_("oc:keyboard-settled",{open:!1})},c+20)},C=await o.addListener("keyboardWillHide",w),P=g=>g instanceof HTMLElement&&(g.tagName==="TEXTAREA"||g.tagName==="INPUT"||g.isContentEditable),E=g=>{S&&P(g.target)&&(P(g.relatedTarget)||window.setTimeout(()=>{S&&(P(document.activeElement)||w())},0))};if(document.addEventListener("focusout",E,!0),n){N(),document.removeEventListener("focusout",E,!0),b.remove(),C.remove();return}e.push(N,()=>{h!==null&&(window.clearTimeout(h),h=null)},()=>document.removeEventListener("focusout",E,!0),()=>{b.remove()},()=>{C.remove()})}).catch(()=>{}),()=>{n=!0,e.forEach(o=>o()),s.classList.remove("oc-capacitor-app","oc-keyboard-open","oc-kb-animating","oc-kb-hide","oc-kb-caret-hold","oc-platform-android"),s.style.removeProperty("--oc-keyboard-inset"),s.style.removeProperty("--oc-kb-shift"),s.style.removeProperty("--oc-kb-layout"),s.style.removeProperty("--oc-kb-scroll-inset")}},[])},na=n=>{const e=l.useRef(!1);l.useEffect(()=>{if(!Mt())return;let s=!1;const r=[],i=()=>{e.current&&(e.current=!1,n())};return Be(()=>import("./vendor-.bun-C6iL44L9.js").then(o=>o.cr),[]).then(async({App:o})=>{if(s)return;const a=await o.addListener("appStateChange",({isActive:c})=>{if(document.documentElement.classList.toggle("oc-native-app-active",c),!c){e.current=!0;return}i()}),u=await o.addListener("resume",i);if(s){a.remove(),u.remove();return}r.push(()=>{a.remove()},()=>{u.remove()})}).catch(()=>{}),()=>{s=!0,r.forEach(o=>o())}},[n])},ra=n=>{l.useEffect(()=>{if(!Mt())return;let e=!1,s=null;return Be(()=>import("./vendor-.bun-C6iL44L9.js").then(r=>r.cr),[]).then(async({App:r})=>{if(e)return;const i=await r.addListener("backButton",()=>{n()||r.minimizeApp().catch(()=>{})});if(e){i.remove();return}s=()=>{i.remove()}}).catch(()=>{}),()=>{e=!0,s?.()}},[n])},It=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),oa=(n,e)=>{if(!n||typeof n!="object")return;const s=n[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},Ct=n=>typeof n=="number"&&Number.isFinite(n)?n:0,Vs=n=>n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}K`:String(n),gt={autoComplete:"off",autoCorrect:"off",spellCheck:!1},ia=1e3,aa=()=>{if(typeof window>"u")return"";const n=window.__OPENCHAMBER_CLIENT_TOKEN__;return typeof n=="string"?n.trim():""},Gs=n=>{const e=It(n);if(!e)return"";const s=e.split("/").filter(Boolean);return s[s.length-1]?.replace(/[-_]/g," ")||e},la=(n,e)=>n?n.label?.trim()||Gs(n.path):Gs(e),ca=({onConnected:n})=>{const{t:e}=ue(),s=Nn(n),{connections:r,isBusy:i,isPasswordBusy:o,error:a,pendingConnection:u}=s,[c,m]=l.useState(""),[f,h]=l.useState(""),[p,v]=l.useState(""),[y,S]=l.useState(!1),[x,N]=l.useState(!1),_=l.useMemo(()=>Pn(),[]),[D,T]=l.useState(""),b=l.useCallback(g=>{g.preventDefault(),s.connect({url:c,clientToken:p,label:f})},[p,s,f,c]),w=l.useCallback(g=>{if(/^openchamber:\/\//i.test(g.trim())){const k=En(g);if(k){m(k.url),k.label&&h(k.label),k.clientToken&&v(k.clientToken),(k.label||k.clientToken)&&N(!0);return}}m(g)},[]),C=l.useCallback(async()=>{if(!(y||i)){s.setError(null),S(!0);try{const g=await An();switch(g.status){case"ok":m(g.url),g.label&&h(g.label),g.clientToken&&v(g.clientToken),(g.label||g.clientToken)&&N(!0),await s.connect({url:g.url,clientToken:g.clientToken,label:g.label});break;case"permission-denied":s.setError(e("mobile.connect.scan.permissionDenied"));break;case"invalid":s.setError(e("mobile.connect.scan.invalid"));break;case"unsupported":s.setError(e("mobile.connect.scan.unsupported"));break;case"failed":s.setError(e("mobile.connect.scan.failed"));break;default:break}}finally{S(!1)}}},[s,i,y,e]),P=l.useCallback(g=>{g.preventDefault(),s.submitPassword(D)},[s,D]),E=l.useCallback(()=>{T(""),s.cancelPassword()},[s]);return t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(env(safe-area-inset-bottom)+28px)] pt-[calc(env(safe-area-inset-top)+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx(Et,{width:72,height:72,className:"size-[72px]"}),t.jsx("h1",{className:"typography-h2 text-foreground",children:e("mobile.connect.welcome.title")})]}),u?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:P,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(ie,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:u.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:u.url})]})]}),t.jsx("input",{...gt,value:D,onChange:g=>T(g.target.value),placeholder:e("mobile.connect.password.placeholder"),"aria-label":e("mobile.connect.password.label"),type:"password",autoFocus:!0,className:"h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20"}),a?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:a}):null,t.jsx(he,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:o||!D.trim(),children:e(o?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(he,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:E,children:e("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-3",children:[t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:b,children:[t.jsx("input",{value:f,onChange:g=>h(g.target.value),placeholder:e("mobile.instances.label.placeholder"),"aria-label":e("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:"h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-center text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20"}),t.jsx("input",{...gt,value:c,onChange:g=>w(g.target.value),placeholder:e("mobile.connect.url.placeholder"),"aria-label":e("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",className:"h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-center text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20"}),t.jsxs("div",{children:[t.jsxs("button",{type:"button",onClick:()=>N(g=>!g),"aria-expanded":x,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:[t.jsx("span",{children:e("mobile.connect.advanced")}),t.jsx(ie,{name:"arrow-down-s",className:te("size-4 transition-transform duration-200",x&&"rotate-180")})]}),t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:x?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("div",{className:"space-y-1.5 pt-2 text-left",children:[t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:e("mobile.connect.token.label")}),t.jsx("input",{...gt,value:p,onChange:g=>v(g.target.value),placeholder:e("mobile.connect.token.placeholder"),tabIndex:x?void 0:-1,autoCapitalize:"none",className:"h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20"})]}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:e("mobile.connect.token.hint")})]})})})]}),a?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:a}):null,t.jsx(he,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:i||y||!c.trim(),children:e(i?"mobile.connect.connecting":"mobile.connect.connectButton")})]}),t.jsxs(he,{type:"button",variant:"ghost",size:"lg",className:"h-12 w-full",onClick:()=>{C()},disabled:!_||y||i,children:[t.jsx(ie,{name:"scan-2",className:te("size-[18px]",y&&"animate-pulse")}),e("mobile.connect.scanQr")]}),_?null:t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:e("mobile.connect.scan.unsupported")})]}),!u&&r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:e("mobile.connect.saved.title")}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(g=>t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/60 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",onClick:()=>{s.connect({url:g.url,clientToken:g.clientToken,label:g.label})},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(ie,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:g.label}),t.jsx("span",{className:"block truncate typography-small text-muted-foreground",children:g.url})]}),t.jsx(ie,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},g.id))})]}):null]})})},ua=({onActiveConnectionDeleted:n,onConnect:e})=>{const{t:s}=ue(),r=Nn(e),{connections:i,isBusy:o,isPasswordBusy:a,error:u,pendingConnection:c,connect:m,submitPassword:f,cancelPassword:h,saveConnection:p,removeConnection:v,setError:y}=r,[S,x]=l.useState(null),N=S?i.find(R=>R.id===S)??null:null,[_,D]=l.useState(null),[T,b]=l.useState(""),[w,C]=l.useState(""),[P,E]=l.useState(""),[g,k]=l.useState(""),[M,V]=l.useState(!1),$=l.useMemo(()=>Pn(),[]),j=l.useCallback(()=>{x(null),b(""),C(""),E(""),y(null)},[y]),A=l.useCallback(R=>{R.preventDefault(),p({url:T,label:w,clientToken:P}).then(X=>{X&&j()})},[P,w,j,p,T]),W=l.useCallback(async()=>{if(!M){y(null),V(!0);try{const R=await An();switch(R.status){case"ok":b(R.url),R.label&&C(R.label),R.clientToken&&E(R.clientToken);break;case"permission-denied":y(s("mobile.connect.scan.permissionDenied"));break;case"invalid":y(s("mobile.connect.scan.invalid"));break;case"unsupported":y(s("mobile.connect.scan.unsupported"));break;case"failed":y(s("mobile.connect.scan.failed"));break;default:break}}finally{V(!1)}}},[M,y,s]),U=l.useCallback(R=>{R.preventDefault(),f(g)},[g,f]),q=l.useCallback(()=>{k(""),h()},[h]),G=l.useCallback(R=>{D(X=>X===R?null:R)},[]),z=l.useCallback(R=>{D(null),S===R&&j(),v(R).then(X=>{X&&Ot(X.url,ft())&&n()})},[S,n,v,j]),Y="h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20";return c?t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:U,children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(ie,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.url})]})]}),t.jsx("input",{...gt,value:g,onChange:R=>k(R.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:Y}),u?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:u}):null,t.jsx(he,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!g.trim(),children:s(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(he,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:q,children:s("mobile.connect.cancelPassword")})]})})}):t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-7",children:[i.length>0?t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:i.map(R=>{const X=_===R.id;return t.jsxs("div",{className:te("flex items-center border-b border-border/60 transition-colors last:border-b-0",X&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-60",onClick:()=>{m({url:R.url,clientToken:R.clientToken,label:R.label})},disabled:o||X,children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(ie,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:R.label}),t.jsx("span",{className:"block truncate typography-small text-muted-foreground",children:R.url})]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[X?t.jsxs("button",{type:"button","aria-label":s("mobile.instances.confirmDeleteAria",{label:R.label}),className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>z(R.id),style:{touchAction:"manipulation"},children:[t.jsx(ie,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:s("mobile.instances.delete")})]}):t.jsx("button",{type:"button","aria-label":s("mobile.instances.edit"),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>{x(R.id),b(R.url),C(R.label),E(R.clientToken||""),y(null)},style:{touchAction:"manipulation"},children:t.jsx(ie,{name:"edit",className:"size-[18px]"})}),t.jsx("button",{type:"button","aria-label":X?s("mobile.instances.cancelDeleteAria",{label:R.label}):s("mobile.instances.deleteAria",{label:R.label}),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>G(R.id),style:{touchAction:"manipulation"},children:t.jsx(ie,{name:X?"close":"delete-bin",className:"size-[18px]"})})]})]},R.id)})}):t.jsx("p",{className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:s("mobile.connect.saved.empty")}),t.jsxs("form",{className:"space-y-3",onSubmit:A,children:[t.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:s(N?"mobile.instances.editTitle":"mobile.instances.addTitle")}),N?t.jsx(he,{type:"button",variant:"ghost",size:"xs",onClick:j,children:s("mobile.instances.cancelEdit")}):null]}),t.jsxs("div",{children:[t.jsxs(he,{type:"button",variant:"outline",size:"lg",className:"h-12 w-full",onClick:()=>{W()},disabled:!$||M,children:[t.jsx(ie,{name:"scan-2",className:te("size-[18px]",M&&"animate-pulse")}),s("mobile.connect.scanQr")]}),$?null:t.jsx("p",{className:"px-1 pt-1.5 typography-micro text-muted-foreground",children:s("mobile.connect.scan.unsupported")})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.instances.label.label")}),t.jsx("input",{value:w,onChange:R=>C(R.target.value),placeholder:s("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:Y})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.url.label")}),t.jsx("input",{...gt,value:T,onChange:R=>b(R.target.value),placeholder:s("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:Y})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.token.label")}),t.jsx("input",{...gt,value:P,onChange:R=>E(R.target.value),placeholder:s("mobile.connect.token.placeholder"),autoCapitalize:"none",className:Y}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")})]}),u?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:u}):null,t.jsx(he,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:s(N?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})},da=n=>{const e=n.usedPercent;return typeof e!="number"||!Number.isFinite(e)?"text-foreground":e>=80?"text-[var(--status-error)]":e>=50?"text-[var(--status-warning)]":"text-foreground"},fa=n=>{const e=ce.c(19),{percentage:s}=n;let r,i,o,a,u,c,m;if(e[0]!==s){o=Lr(s)??0;const y=zr(s);i=y==="critical"?"var(--status-error)":y==="warn"?"var(--status-warning)":"var(--status-success)",r=2*Math.PI*7.5,a="0 0 18 18",u="size-[18px] -rotate-90",c="progressbar",m=Math.round(o),e[0]=s,e[1]=r,e[2]=i,e[3]=o,e[4]=a,e[5]=u,e[6]=c,e[7]=m}else r=e[1],i=e[2],o=e[3],a=e[4],u=e[5],c=e[6],m=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=f):f=e[8];const h=r*(1-o/100);let p;e[9]!==r||e[10]!==i||e[11]!==h?(p=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:i,strokeWidth:3,strokeLinecap:"round",strokeDasharray:r,strokeDashoffset:h,className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=r,e[10]=i,e[11]=h,e[12]=p):p=e[12];let v;return e[13]!==a||e[14]!==u||e[15]!==c||e[16]!==m||e[17]!==p?(v=t.jsxs("svg",{viewBox:a,className:u,role:c,"aria-valuenow":m,"aria-valuemin":0,"aria-valuemax":100,children:[f,p]}),e[13]=a,e[14]=u,e[15]=c,e[16]=m,e[17]=p,e[18]=v):v=e[18],v},Hs=n=>{const e=ce.c(13),{icon:s,iconNode:r,label:i,children:o}=n;let a;e[0]!==s||e[1]!==r?(a=r??(s?t.jsx(ie,{name:s,className:"size-[18px]"}):null),e[0]=s,e[1]=r,e[2]=a):a=e[2];let u;e[3]!==a?(u=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:a}),e[3]=a,e[4]=u):u=e[4];let c;e[5]!==i?(c=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:i}),e[5]=i,e[6]=c):c=e[6];let m;e[7]!==o?(m=t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:o}),e[7]=o,e[8]=m):m=e[8];let f;return e[9]!==u||e[10]!==c||e[11]!==m?(f=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[u,c,m]}),e[9]=u,e[10]=c,e[11]=m,e[12]=f):f=e[12],f},ma=n=>{const e=ce.c(44),{open:s,onClose:r,anchorRef:i,contextDisplay:o,branchLabel:a,usageGroups:u,usageDisplayMode:c,isUsageLoading:m,timeFormatPreference:f}=n,{t:h}=ue(),p=l.useRef(null),[v,y]=l.useState(s),[S,x]=l.useState(!1);let N,_;e[0]!==s||e[1]!==v?(N=()=>{if(s){y(!0),x(!1);return}if(!v)return;x(!0);const G=window.setTimeout(()=>{y(!1),x(!1)},140);return()=>window.clearTimeout(G)},_=[s,v],e[0]=s,e[1]=v,e[2]=N,e[3]=_):(N=e[2],_=e[3]),l.useEffect(N,_);let D,T;e[4]!==r||e[5]!==s?(D=()=>{if(!s)return;const G=z=>{z.key==="Escape"&&r()};return document.addEventListener("keydown",G),()=>document.removeEventListener("keydown",G)},T=[r,s],e[4]=r,e[5]=s,e[6]=D,e[7]=T):(D=e[6],T=e[7]),l.useEffect(D,T);let b,w;if(e[8]!==i||e[9]!==r||e[10]!==s?(b=()=>{if(!s)return;const G=z=>{const Y=z.target;if(!(Y instanceof Node)){r();return}p.current?.contains(Y)||i.current?.contains(Y)||r()};return document.addEventListener("pointerdown",G,!0),document.addEventListener("wheel",G,!0),()=>{document.removeEventListener("pointerdown",G,!0),document.removeEventListener("wheel",G,!0)}},w=[i,r,s],e[8]=i,e[9]=r,e[10]=s,e[11]=b,e[12]=w):(b=e[11],w=e[12]),l.useEffect(b,w),!v)return null;let C;e[13]!==h?(C=h("mobile.header.openMetadataAria"),e[13]=h,e[14]=C):C=e[14];const P=S?"pointer-events-none":"pointer-events-auto";let E;e[15]!==P?(E=te("mx-3 mt-2 overflow-y-auto overscroll-contain rounded-[20px] border border-border/40 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",P),e[15]=P,e[16]=E):E=e[16];const g=`${S?"session-metadata-out":"session-metadata-in"} ${S?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let k;e[17]!==g?(k={animation:g,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))"},e[17]=g,e[18]=k):k=e[18];let M;e[19]!==h?(M=h("mobile.header.metadata.branch"),e[19]=h,e[20]=M):M=e[20];let V;e[21]!==a||e[22]!==M?(V=t.jsx(Hs,{icon:"git-branch",label:M,children:a}),e[21]=a,e[22]=M,e[23]=V):V=e[23];let $;e[24]!==o||e[25]!==h?($=o?t.jsx(Hs,{iconNode:t.jsx(fa,{percentage:o.percentage}),label:h("mobile.header.metadata.context"),children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:te("font-semibold",o.colorClass),children:[o.percentage.toFixed(1),"%"]}),t.jsx("span",{className:"text-muted-foreground",children:o.tokens})]})}):null,e[24]=o,e[25]=h,e[26]=$):$=e[26];let j;e[27]!==m||e[28]!==f||e[29]!==c||e[30]!==u?(j=t.jsx(ha,{groups:u,displayMode:c,isLoading:m,timeFormatPreference:f}),e[27]=m,e[28]=f,e[29]=c,e[30]=u,e[31]=j):j=e[31];let A;e[32]!==V||e[33]!==$||e[34]!==j?(A=t.jsxs("div",{className:"space-y-1",children:[V,$,j]}),e[32]=V,e[33]=$,e[34]=j,e[35]=A):A=e[35];let W;e[36]!==k||e[37]!==A||e[38]!==C||e[39]!==E?(W=t.jsx("div",{ref:p,role:"dialog","aria-label":C,className:E,style:k,children:A}),e[36]=k,e[37]=A,e[38]=C,e[39]=E,e[40]=W):W=e[40];let U;e[41]===Symbol.for("react.memo_cache_sentinel")?(U=t.jsx("style",{children:`
8
+ @keyframes session-metadata-in {
9
+ from { opacity: 0; transform: translateY(-8px) scale(0.985); }
10
+ to { opacity: 1; transform: translateY(0) scale(1); }
11
+ }
12
+ @keyframes session-metadata-out {
13
+ from { opacity: 1; transform: translateY(0) scale(1); }
14
+ to { opacity: 0; transform: translateY(-6px) scale(0.985); }
15
+ }
16
+ `}),e[41]=U):U=e[41];let q;return e[42]!==W?(q=t.jsxs("div",{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:[W,U]}),e[42]=W,e[43]=q):q=e[43],q},ha=n=>{const e=ce.c(30),{groups:s,displayMode:r,isLoading:i,timeFormatPreference:o}=n,{t:a}=ue();let u;e[0]!==r||e[1]!==a?(u=a(r==="remaining"?"header.services.remaining":"header.services.used"),e[0]=r,e[1]=a,e[2]=u):u=e[2];const c=u;if(s.length===0)return null;let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t.jsx(ie,{name:"timer",className:"size-[18px]"})}),e[3]=m):m=e[3];let f;e[4]!==a?(f=a("mobile.header.metadata.usage"),e[4]=a,e[5]=f):f=e[5];let h;e[6]!==f?(h=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:f}),e[6]=f,e[7]=h):h=e[7];let p;e[8]!==i?(p=i?t.jsx(ie,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[8]=i,e[9]=p):p=e[9];let v;e[10]!==c?(v=t.jsx("span",{className:"truncate",children:c}),e[10]=c,e[11]=v):v=e[11];let y;e[12]!==p||e[13]!==v?(y=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,v]}),e[12]=p,e[13]=v,e[14]=y):y=e[14];let S;e[15]!==h||e[16]!==y?(S=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[m,h,y]}),e[15]=h,e[16]=y,e[17]=S):S=e[17];let x;if(e[18]!==r||e[19]!==s||e[20]!==o){let D;e[22]!==r||e[23]!==o?(D=T=>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(Br,{providerId:T.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:T.providerName}),T.status&&T.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:T.status}):null]}),T.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:T.rows.map(b=>{const w=r==="remaining"?b.window.remainingPercent:b.window.usedPercent,C=Or(b.window.valueLabel,w),P=Fr(b.window.resetAt,b.window.resetAfterFormatted??b.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:b.subtitle?`${b.subtitle} · ${b.label}`:b.label}),P?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground/70",children:P}):null]}),t.jsx("span",{className:te("shrink-0 typography-ui-label font-semibold tabular-nums",da(b.window)),children:C==="-"?"":C})]},b.key)})}):null,T.status&&T.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:T.status}):null]},T.providerId),e[22]=r,e[23]=o,e[24]=D):D=e[24],x=s.map(D),e[18]=r,e[19]=s,e[20]=o,e[21]=x}else x=e[21];let N;e[25]!==x?(N=t.jsx("div",{className:"space-y-1.5",children:x}),e[25]=x,e[26]=N):N=e[26];let _;return e[27]!==N||e[28]!==S?(_=t.jsxs("div",{className:"pt-2.5",children:[S,N]}),e[27]=N,e[28]=S,e[29]=_):_=e[29],_},pa=n=>{const e=ce.c(24),{open:s,onClose:r,items:i}=n,{t:o}=ue();let a,u;if(e[0]!==r||e[1]!==s?(a=()=>{if(!s)return;const x=N=>{N.key==="Escape"&&r()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},u=[r,s],e[0]=r,e[1]=s,e[2]=a,e[3]=u):(a=e[2],u=e[3]),l.useEffect(a,u),!s)return null;let c;e[4]!==o?(c=o("mobile.menu.titleAria"),e[4]=o,e[5]=c):c=e[5];let m;e[6]!==o?(m=o("mobile.surface.closeAria"),e[6]=o,e[7]=m):m=e[7];let f;e[8]!==r||e[9]!==m?(f=t.jsx("button",{type:"button",className:"absolute inset-0 cursor-default","aria-label":m,onClick:r}),e[8]=r,e[9]=m,e[10]=f):f=e[10];let h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h={animation:"mobile-menu-in 160ms cubic-bezier(0.32, 0.72, 0, 1)"},e[11]=h):h=e[11];let p;if(e[12]!==i||e[13]!==r){let x;e[15]!==r?(x=(N,_)=>t.jsxs("button",{type:"button",role:"menuitem",className:te("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",_>0&&"border-t border-border/30"),style:{touchAction:"manipulation"},onClick:()=>{N.onSelect(),r()},children:[N.iconNode??(N.icon?t.jsx(ie,{name:N.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:N.label}),N.badge&&N.badge>0?t.jsx("span",{className:"inline-flex size-2 shrink-0 rounded-full bg-primary","aria-hidden":!0}):null]},N.key),e[15]=r,e[16]=x):x=e[16],p=i.map(x),e[12]=i,e[13]=r,e[14]=p}else p=e[14];let v;e[17]!==p?(v=t.jsx("div",{className:"absolute right-2 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:h,children:p}),e[17]=p,e[18]=v):v=e[18];let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=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[19]=y):y=e[19];let S;return e[20]!==c||e[21]!==f||e[22]!==v?(S=t.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":c,children:[f,v,y]}),e[20]=c,e[21]=f,e[22]=v,e[23]=S):S=e[23],S},ga=l.memo(function({open:e,onOpenChange:s,currentSessionId:r,effectiveDirectory:i,gitDirectory:o,isNewSessionDraftOpen:a,primaryLabel:u,secondaryLabel:c}){const{t:m}=ue(),{git:f}=Wt(),h=l.useRef(null),p=Ar(r??"",i||void 0),v=un(o),y=is(o),S=Ie(O=>O.ensureStatus),x=Ie(O=>O.fetchStatus),N=Ne(O=>O.providers),_=Ne(O=>O.currentProviderId),D=Ne(O=>O.currentModelId),T=Ne(O=>O.getModelMetadata);Ne(O=>O.modelsMetadata.size);const b=_r(l.useCallback(O=>r?O.sessionModelSelections.get(r)??null:null,[r])),w=st(O=>O.results),C=st(O=>O.loadSettings),P=st(O=>O.fetchAllQuotas),E=st(O=>O.isLoading),g=st(O=>O.displayMode),k=st(O=>O.dropdownProviderIds),M=st(O=>O.selectedModels),V=wt(O=>O.timeFormatPreference);po(),l.useEffect(()=>{o&&S(o,f)},[S,f,o]),l.useEffect(()=>{if(o)return Tr.onGitRefreshHint(O=>{It(O.directory)===o&&x(o,f)})},[x,f,o]),l.useEffect(()=>{C()},[C]),l.useEffect(()=>{Ss(k)},[k]),l.useEffect(()=>{!e||E||!k.some(ee=>!w.some(ae=>ae.providerId===ee))||P()},[k,P,E,e,w]);const j=l.useMemo(()=>{for(let O=p.length-1;O>=0;O-=1){const ee=p[O];if(ee.role!=="user")continue;const ae=typeof ee.model?.providerID=="string"&&ee.model.providerID.trim().length>0?ee.model.providerID:void 0,xe=typeof ee.model?.modelID=="string"&&ee.model.modelID.trim().length>0?ee.model.modelID:void 0;if(ae&&xe)return{providerID:ae,modelID:xe}}return null},[p])??(b?{providerID:b.providerId,modelID:b.modelId}:null)??(_&&D?{providerID:_,modelID:D}:null),W=(j?N.find(O=>O.id===j.providerID):void 0)?.models.find(O=>O.id===j?.modelID),U=j?T(j.providerID,j.modelID):void 0,q=oa(W?.limit,"context")??U?.limit?.context??0,G=l.useMemo(()=>{for(let O=p.length-1;O>=0;O-=1){const ee=p[O];if(ee.role!=="assistant"||!ee.tokens)continue;const ae=Ct(ee.tokens.input)+Ct(ee.tokens.output)+Ct(ee.tokens.reasoning)+Ct(ee.tokens.cache?.read)+Ct(ee.tokens.cache?.write);if(ae>0)return ae}return 0},[p]),z=!a&&G>0&&q>0?Math.min(G/q*100,999):null,Y=z!==null?`${Vs(G)}/${Vs(q)}`:null,R=z===null?"":z>=90?"text-[var(--status-error)]":z>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",X=z!==null&&Y?{percentage:z,tokens:Y,colorClass:R}:null,Ee=v===!0?y?.current?.trim()||m("gitView.branch.detachedHead"):m("common.unavailable"),ne=l.useMemo(()=>{const O=new Map(w.map(ee=>[ee.providerId,ee]));return go.filter(ee=>k.includes(ee.id)).filter(ee=>O.get(ee.id)?.configured===!0).map(ee=>{const ae=O.get(ee.id),xe=[];for(const[fe,ke]of Object.entries(ae?.usage?.windows??{}))xe.push({key:`window-${fe}`,label:Ns(fe),window:ke});const je=Object.entries(ae?.usage?.models??{}),oe=M[ee.id]??[],ve=oe.length>0?je.filter(([fe])=>oe.includes(fe)):je;for(const[fe,ke]of ve){const Se=Object.entries(ke.windows??{});if(Se.length===0)continue;const[Ve,Me]=Se[0];xe.push({key:`model-${fe}-${Ve}`,label:Ns(Ve),subtitle:bo(fe),window:Me})}const de=!ae.ok&&ae.error?ae.error:xe.length===0?m("header.services.noRateLimitsReported"):null;return{providerId:ee.id,providerName:ee.name,rows:xe,status:de}})},[k,w,M,m]);return l.useEffect(()=>{!e||ne.length===0||Ss(ne.map(O=>O.providerId))},[e,ne]),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:u}),c?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:c}):null]})}),t.jsx("button",{ref:h,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":m("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>s(O=>!O),style:{touchAction:"manipulation"},children:t.jsx(ie,{name:"apps-2-ai",className:"size-5"})}),t.jsx(ma,{open:e,onClose:()=>s(!1),anchorRef:h,contextDisplay:X,branchLabel:Ee,usageGroups:ne,usageDisplayMode:g,isUsageLoading:E,timeFormatPreference:V})]})}),ba=({onOpenSessions:n,onOpenMenu:e})=>{const{t:s}=ue(),[r,i]=l.useState(!1),o=bt(b=>b.currentDirectory),a=be(b=>b.currentSessionId),c=be(l.useCallback(b=>a?b.getDirectoryForSession(a):null,[a]))||o,m=It(c)||null,f=Ce(b=>b.projects),h=be(b=>b.availableWorktreesByProject),p=be(l.useCallback(b=>a?b.worktreeMetadata.get(a)??null:null,[a])),v=Ir(a,c||void 0),y=be(b=>!!b.newSessionDraft?.open),S=l.useMemo(()=>{const b=It(c);if(!b)return s("mobile.header.noProject");const C=(p?.projectDirectory?Rr(f,p.projectDirectory):null)??Mr(f,h,b);return la(C,b)||s("mobile.header.noProject")},[h,p?.projectDirectory,c,f,s]),N=v?.title?.trim()||(a?s("mobile.sessions.untitled"):S),_=a?S:"";l.useEffect(()=>{i(!1)},[a,c]);const D=l.useCallback(()=>{i(!1),n()},[n]),T=l.useCallback(()=>{i(!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":s("mobile.sessions.openSheetAria"),onClick:D,style:{touchAction:"manipulation"},children:t.jsx(ie,{name:"folders",className:"size-5"})}),t.jsx(ga,{open:r,onOpenChange:i,currentSessionId:a,effectiveDirectory:c,gitDirectory:m,isNewSessionDraftOpen:y,primaryLabel:N,secondaryLabel:_}),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":s("mobile.header.openMenuAria"),onClick:T,style:{touchAction:"manipulation"},children:t.jsx(ie,{name:"more-2",className:"size-5"})})]})})})},xa=n=>{const e=ce.c(114),{onActiveConnectionDeleted:s}=n,{t:r}=ue(),[i,o]=l.useState(!1),[a,u]=l.useState(!1),[c,m]=l.useState(!1),[f,h]=l.useState(!1),[p,v]=l.useState(!1),[y,S]=l.useState(!1),[x,N]=l.useState(!1),[_,D]=l.useState(!1),[T,b]=l.useState("nav"),[w,C]=l.useState(!1),[P,E]=l.useState(null),g=bt(ya),k=wt(wa),M=Cs(ja),V=Cs(ka);let $;e[0]===Symbol.for("react.memo_cache_sentinel")?($=Mt(),e[0]=$):$=e[0];const j=$,A=Lt(Sa),W=Lt(Na),U=Lt(Ca),q=uo(Ea),G=Lt(Pa);let z;e[1]!==g?(z=It(g)||null,e[1]=g,e[2]=z):z=e[2];const R=is(z)?.files?.length??0;let X;e[3]===Symbol.for("react.memo_cache_sentinel")?(X={openChanges:H=>{const{diffPath:J,staged:le}=H===void 0?{}:H;E(J?{path:J,staged:le===!0}:null),m(!0)},openFiles:()=>u(!0),openSettings:()=>{b("nav"),N(!0)}},e[3]=X):X=e[3];const Ee=X;let ne;e[4]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>{m(!1),E(null)},e[4]=ne):ne=e[4];const O=ne;let ee,ae,xe;e[5]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>o(!0),ae=H=>{H==="files"?u(!0):H==="mcp"?h(!0):H==="instances"?v(!0):H==="update"&&D(!0)},xe=H=>{const{path:J,staged:le}=H===void 0?{}:H;E(J?{path:J,staged:le===!0}:null),m(!0)},e[5]=ee,e[6]=ae,e[7]=xe):(ee=e[5],ae=e[6],xe=e[7]);let je;e[8]!==k?(je={openSessions:ee,openView:ae,openChanges:xe,openSettings:H=>{H&&k(H),b(H?"page-content":"nav"),N(!0)}},e[8]=k,e[9]=je):je=e[9],Gi(je);const ve=l.useRef(null),de=l.useRef(null),fe=l.useRef(null),ke=be(Aa);let Se;e[10]===Symbol.for("react.memo_cache_sentinel")?(Se=H=>{fe.current=H},e[10]=Se):Se=e[10];const Ve=Se;let Me;e[11]===Symbol.for("react.memo_cache_sentinel")?(Me={onSwitch:Ve},e[11]=Me):Me=e[11],Xi(ve,Me);let Oe;e[12]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>{const H=fe.current;if(fe.current=null,!H)return;const J=de.current;if(!J||typeof J.animate!="function")return;J.getAnimations().forEach(_a);const le=H==="prev"?-70:70;J.animate([{opacity:.1,transform:`translateX(${le}px)`},{opacity:1,transform:"translateX(0)"}],{duration:300,easing:"cubic-bezier(0.22, 1, 0.36, 1)"})},e[12]=Oe):Oe=e[12];let Fe;e[13]!==ke?(Fe=[ke],e[13]=ke,e[14]=Fe):Fe=e[14],l.useLayoutEffect(Oe,Fe);let Ge;e[15]!==c||e[16]!==a||e[17]!==p||e[18]!==f||e[19]!==w||e[20]!==i||e[21]!==x||e[22]!==_?(Ge=()=>w?(C(!1),!0):i?(o(!1),!0):a?(u(!1),!0):c?(O(),!0):f?(h(!1),!0):p?(v(!1),!0):x?(N(!1),!0):_?(D(!1),!0):!1,e[15]=c,e[16]=a,e[17]=p,e[18]=f,e[19]=w,e[20]=i,e[21]=x,e[22]=_,e[23]=Ge):Ge=e[23],ra(Ge);const I=M&&(V==="desktop"||V==="web");let L;e[24]!==A||e[25]!==W||e[26]!==U||e[27]!==k?(L=()=>{let H="new-mcp-server",J=1;for(;A.some(me=>me.name===H);)H=`new-mcp-server-${J}`,J=J+1;W({name:H,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),U(H),k("mcp"),h(!1),b("page-content"),N(!0)},e[24]=A,e[25]=W,e[26]=U,e[27]=k,e[28]=L):L=e[28];const Q=L;let pe;e[29]!==g||e[30]!==y||e[31]!==G||e[32]!==q?(pe=()=>{if(y)return;S(!0);const H=g||null,J=new Promise(Ta);Promise.all([q({directory:H,silent:!0}),G({force:!0}),J]).finally(()=>S(!1))},e[29]=g,e[30]=y,e[31]=G,e[32]=q,e[33]=pe):pe=e[33];const Pe=pe;let Ae;e[34]!==r?(Ae=r("mobile.menu.files"),e[34]=r,e[35]=Ae):Ae=e[35];let He;e[36]===Symbol.for("react.memo_cache_sentinel")?(He=()=>u(!0),e[36]=He):He=e[36];let $e;e[37]!==Ae?($e={key:"files",icon:"file-text",label:Ae,onSelect:He},e[37]=Ae,e[38]=$e):$e=e[38];let Le;e[39]!==r?(Le=r("mobile.menu.changes"),e[39]=r,e[40]=Le):Le=e[40];let lt;e[41]===Symbol.for("react.memo_cache_sentinel")?(lt=()=>m(!0),e[41]=lt):lt=e[41];let qe;e[42]!==R||e[43]!==Le?(qe={key:"changes",icon:"git-branch",label:Le,badge:R,onSelect:lt},e[42]=R,e[43]=Le,e[44]=qe):qe=e[44];let ct;e[45]===Symbol.for("react.memo_cache_sentinel")?(ct=t.jsx(xo,{className:"size-5 shrink-0 text-muted-foreground"}),e[45]=ct):ct=e[45];let Ke;e[46]!==r?(Ke=r("mobile.menu.mcp"),e[46]=r,e[47]=Ke):Ke=e[47];let kt;e[48]===Symbol.for("react.memo_cache_sentinel")?(kt=()=>h(!0),e[48]=kt):kt=e[48];let Qe;e[49]!==Ke?(Qe={key:"mcp",iconNode:ct,label:Ke,onSelect:kt},e[49]=Ke,e[50]=Qe):Qe=e[50];let _e;if(e[51]!==I||e[52]!==r||e[53]!==$e||e[54]!==qe||e[55]!==Qe){if(_e=[$e,qe,Qe],j){let me;e[57]!==r?(me=r("mobile.menu.instances"),e[57]=r,e[58]=me):me=e[58];let De;e[59]===Symbol.for("react.memo_cache_sentinel")?(De=()=>v(!0),e[59]=De):De=e[59];let Te;e[60]!==me?(Te={key:"instances",icon:"server",label:me,onSelect:De},e[60]=me,e[61]=Te):Te=e[61],_e.push(Te)}if(I){let me;e[62]!==r?(me=r("mobile.menu.update"),e[62]=r,e[63]=me):me=e[63];let De;e[64]===Symbol.for("react.memo_cache_sentinel")?(De=()=>D(!0),e[64]=De):De=e[64];let Te;e[65]!==me?(Te={key:"update",icon:"download",label:me,onSelect:De},e[65]=me,e[66]=Te):Te=e[66],_e.push(Te)}let H;e[67]!==r?(H=r("mobile.menu.settings"),e[67]=r,e[68]=H):H=e[68];let J;e[69]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{b("nav"),N(!0)},e[69]=J):J=e[69];let le;e[70]!==H?(le={key:"settings",icon:"settings-3",label:H,onSelect:J},e[70]=H,e[71]=le):le=e[71],_e.push(le),e[51]=I,e[52]=r,e[53]=$e,e[54]=qe,e[55]=Qe,e[56]=_e}else _e=e[56];const Ye=_e;let ut;e[72]===Symbol.for("react.memo_cache_sentinel")?(ut=t.jsx(ba,{onOpenSessions:()=>o(!0),onOpenMenu:()=>C(!0)}),e[72]=ut):ut=e[72];let St;e[73]===Symbol.for("react.memo_cache_sentinel")?(St=t.jsx("main",{ref:ve,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{ref:de,className:"h-full w-full",children:t.jsx(rt,{children:t.jsx(vo,{})})})}),e[73]=St):St=e[73];let tt;e[74]===Symbol.for("react.memo_cache_sentinel")?(tt=()=>C(!1),e[74]=tt):tt=e[74];let We;e[75]!==Ye||e[76]!==w?(We=t.jsx(pa,{open:w,onClose:tt,items:Ye}),e[75]=Ye,e[76]=w,e[77]=We):We=e[77];let Ue;e[78]!==i?(Ue=i?t.jsx(di,{open:i,onOpenChange:o}):null,e[78]=i,e[79]=Ue):Ue=e[79];let Je;e[80]!==a||e[81]!==r?(Je=a?t.jsx(ot,{open:!0,onClose:()=>u(!1),ariaLabel:r("mobile.menu.files"),headerless:!0,children:t.jsx(rt,{children:t.jsx($o,{onClose:()=>u(!1)})})}):null,e[80]=a,e[81]=r,e[82]=Je):Je=e[82];let d;e[83]!==c||e[84]!==P?.path||e[85]!==P?.staged||e[86]!==r?(d=c?t.jsx(ot,{open:!0,onClose:O,ariaLabel:r("mobile.menu.changes"),headerless:!0,children:t.jsx(rt,{children:t.jsx(Io,{onClose:O,initialDiffPath:P?.path??null,initialDiffStaged:P?.staged===!0})})}):null,e[83]=c,e[84]=P?.path,e[85]=P?.staged,e[86]=r,e[87]=d):d=e[87];let B;e[88]!==y||e[89]!==f||e[90]!==Q||e[91]!==Pe||e[92]!==r?(B=f?t.jsx(mn,{open:!0,onClose:()=>h(!1),title:r("mcpDropdown.title"),className:"h-[72vh]",contentMaxHeightClassName:"max-h-full",renderHeader:H=>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:r("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:Q,"aria-label":r("settings.mcp.sidebar.actions.addServerTitle"),title:r("settings.mcp.sidebar.actions.addServerTitle"),style:{touchAction:"manipulation"},children:t.jsx(ie,{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:Pe,disabled:y,"aria-label":r("mcpDropdown.actions.refreshAria"),title:r("mcpDropdown.actions.refreshAria"),style:{touchAction:"manipulation"},children:t.jsx(ie,{name:"refresh",className:te("h-5 w-5",y&&"animate-spin")})}),H]})]})]}),children:t.jsx(rt,{children:t.jsx(fo,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})})}):null,e[88]=y,e[89]=f,e[90]=Q,e[91]=Pe,e[92]=r,e[93]=B):B=e[93];let F;e[94]!==p||e[95]!==s||e[96]!==r?(F=p&&j?t.jsx(ot,{open:!0,onClose:()=>v(!1),ariaLabel:r("mobile.menu.instances"),title:r("mobile.menu.instances"),children:t.jsx(ua,{onConnect:()=>v(!1),onActiveConnectionDeleted:s})}):null,e[94]=p,e[95]=s,e[96]=r,e[97]=F):F=e[97];let K;e[98]!==T||e[99]!==x||e[100]!==r?(K=x?t.jsx(ot,{open:!0,onClose:()=>N(!1),ariaLabel:r("mobile.menu.settings"),headerless:!0,children:t.jsx(rt,{children:t.jsx(mo,{forceMobile:!0,isWindowed:!0,initialMobileStage:T,visiblePageSlugs:[...ta],onClose:()=>N(!1)})})}):null,e[98]=T,e[99]=x,e[100]=r,e[101]=K):K=e[101];let re;e[102]!==r||e[103]!==_?(re=_?t.jsx(ot,{open:!0,onClose:()=>D(!1),ariaLabel:r("mobile.menu.update"),title:r("mobile.menu.update"),children:t.jsx(rt,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(ho,{initialUpdateDialogOpen:!0})})})}):null,e[102]=r,e[103]=_,e[104]=re):re=e[104];let Z;return e[105]!==We||e[106]!==Ue||e[107]!==Je||e[108]!==d||e[109]!==B||e[110]!==F||e[111]!==K||e[112]!==re?(Z=t.jsx(Dr,{actions:Ee,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-col bg-background text-foreground","data-page-scroll-lock":"true",children:[ut,St,We,Ue,Je,d,B,F,K,re]})}),e[105]=We,e[106]=Ue,e[107]=Je,e[108]=d,e[109]=B,e[110]=F,e[111]=K,e[112]=re,e[113]=Z):Z=e[113],Z};function va({apis:n}){const{t:e}=ue(),s=Ne(j=>j.initializeApp),r=Ne(j=>j.isInitialized),i=Ne(j=>j.isConnected),o=Ne(j=>j.connectionPhase),a=Ne(j=>j.providers.length),u=Ne(j=>j.agents.length),c=Ne(j=>j.loadProviders),m=Ne(j=>j.loadAgents),f=bt(j=>j.currentDirectory),h=be(j=>j.error),p=be(j=>j.clearError),v=wt(j=>j.setIsMobile),y=vr(j=>j.refreshStatus),S=yr(j=>j.setPlanModeEnabled),x=Ce(j=>j.projects),[N,_]=l.useState(0),[D,T]=l.useState(0),[b,w]=l.useState(!1),[C,P]=l.useState("pending"),E=l.useMemo(()=>Mt(),[]),g=l.useRef(0),k=l.useRef(0),M=l.useCallback(()=>{const j=ft();if(!j)return;const A=k.current+1;k.current=A,Ci({url:j,clientToken:aa()}).then(U=>{if(k.current===A){if(!U){ht({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),_(q=>q+1);return}s(),y(n.github,{force:!0}),a===0&&c({source:"mobileApp:nativeResume"}),u===0&&m({source:"mobileApp:nativeResume"})}});const W=Date.now();W-g.current>=ia&&(g.current=W,window.dispatchEvent(new Event("openchamber:system-resume")))},[u,n.github,s,m,c,a,y]);sa(),na(M),l.useEffect(()=>(vs(n),()=>vs(null)),[n]),l.useEffect(()=>Qn(j=>{oo(j),T(A=>A+1),_(A=>A+1)}),[]),l.useEffect(()=>{if(!E||i||ft()){P("done");return}let j=!1;return P("attempting"),Ni().catch(()=>!1).then(()=>{j||P("done")}),()=>{j=!0}},[]),l.useEffect(()=>{v(!0)},[v]),l.useEffect(()=>{s()},[N,s]),l.useEffect(()=>{i&&(a===0&&c({source:"mobileApp:recovery"}),u===0&&m({source:"mobileApp:recovery"}))},[u,i,m,c,a]),l.useEffect(()=>{i&&ys.setDirectory(f)},[f,i]),l.useEffect(()=>{i&&y(n.github,{force:!0})},[n.github,i,y]),l.useEffect(()=>{if(!i||x.length===0)return;let j=!1;return(async()=>{const W=new Map(be.getState().availableWorktreesByProject);if(await Promise.all(x.map(async q=>{const G=q.path.replace(/\\/g,"/").replace(/\/+$/,"");if(G)try{if(!(Ie.getState().directories.get(G)?.isGitRepo??await Be(()=>import("./useAppFontEffects-BUUJYbAZ.js").then(X=>X.f9),__vite__mapDeps([0,1,2,3])).then(X=>X.checkIsGitRepository(G))))return;const R=await bn({id:q.id,path:G});if(j)return;W.set(G,R)}catch{}})),j)return;const U=Array.from(W.values()).flat();be.setState({availableWorktrees:U,availableWorktreesByProject:W})})(),()=>{j=!0}},[i,x]),l.useEffect(()=>{let j=!1;return(async()=>{const W=await Yn("/health",{method:"GET"}).catch(()=>null);if(!W||!W.ok||j)return;const U=await W.json().catch(()=>null);if(!U||j)return;const q=U.planModeExperimentalEnabled;S(q===!0||q===1||q==="1"||q==="true")})(),()=>{j=!0}},[S]),l.useEffect(()=>{if(!h)return;const j=window.setTimeout(()=>p(),5e3);return()=>window.clearTimeout(j)},[p,h]),l.useEffect(()=>{if(!(!i&&(E?!!ft():!0))){w(!1);return}const A=window.setTimeout(()=>w(!0),8e3);return()=>window.clearTimeout(A)},[i,E,N,D]),wr(),jr({enabled:!0}),io(),kr(),ao(),ea({enabled:E&&i}),Hi({ready:E&&i&&r});const V=Ii(),$=!i&&o==="reconnecting";return V?!i&&!$&&E?ft()?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(Et,{width:120,height:120,isAnimated:!b}),b?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(he,{type:"button",variant:"outline",onClick:()=>{ht({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),_(j=>j+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):C!=="done"?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Et,{width:120,height:120,isAnimated:!0})}):t.jsx(ca,{onConnected:()=>_(j=>j+1)}):!i&&!$?b?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(Et,{width:120,height:120,isAnimated:!0})}):t.jsx(rt,{children:t.jsx(Sr,{sdk:ys.getSdkClient(),directory:f||"",children:t.jsx(Nr,{apis:n,children:t.jsx(Cr,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[t.jsx(Er,{embeddedBackgroundWorkEnabled:r}),t.jsx(lo,{}),t.jsx(xa,{onActiveConnectionDeleted:()=>{ht({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),_(j=>j+1)}}),t.jsx(Pr,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),r?t.jsx(co,{}):null]})})})},D)}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Et,{width:120,height:120,isAnimated:!0})})}function ya(n){return n.currentDirectory}function wa(n){return n.setSettingsPage}function ja(n){return n.available}function ka(n){return n.runtimeType}function Sa(n){return n.mcpServers}function Na(n){return n.setMcpDraft}function Ca(n){return n.setSelectedMcp}function Ea(n){return n.refresh}function Pa(n){return n.loadMcpConfigs}function Aa(n){return n.currentSessionId}function _a(n){return n.cancel()}function Ta(n){return window.setTimeout(n,500)}const Da=()=>{qr(),Jn().then(()=>{Promise.all([Xn(),Kr()]).catch(n=>{console.error("[mobile-main] settings init failed:",n)}),Qr(),Yr(),Jr()}).catch(n=>{console.error("[mobile-main] appearance init failed:",n)}).finally(()=>{jo()})};function Ba(n){$r(),Da(),Ao(),Wr();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?{...n,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:n,o=t.jsx(va,{apis:i});Gn.createRoot(e).render(t.jsx(Hn.StrictMode,{children:t.jsx(Ur,{children:t.jsx(Vr,{children:t.jsx(Gr,{children:t.jsx(yo,{children:r?o:t.jsx(Hr,{children:o})})})})})}))}export{Ba as renderMobileApp};