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