@openchamber/web 1.17.0 → 1.17.1

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