@openchambery/web 1.18.3 → 1.18.4-beta.10

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 (113) hide show
  1. package/bin/cli.test.js +25 -0
  2. package/bin/lib/DOCUMENTATION.md +2 -1
  3. package/bin/lib/cli-args.js +19 -0
  4. package/bin/lib/commands-serve.js +73 -4
  5. package/dist/assets/{AgentAvatar-BvhXxFvg.js → AgentAvatar-DAnelAnB.js} +1 -1
  6. package/dist/assets/{AssistantView-DvCGcMdh.js → AssistantView-C7zpkYc-.js} +1 -1
  7. package/dist/assets/{ChatContainer-B8XV-b62.js → ChatContainer-tzO5rvhQ.js} +20 -20
  8. package/dist/assets/{DiagramView-3oWJD3HI.js → DiagramView-D3WjJqff.js} +1 -1
  9. package/dist/assets/{FadeInOnReveal-98buIVdv.js → FadeInOnReveal-QxF1vuqX.js} +1 -1
  10. package/dist/assets/{Icon-BhSwbLaF.js → Icon-D-X70irR.js} +1 -1
  11. package/dist/assets/{MarkdownRendererImpl-ZBTLZ4_Z.js → MarkdownRendererImpl-CBtszecD.js} +1 -1
  12. package/dist/assets/{MobileDetailNavigation-C129Cfy_.js → MobileDetailNavigation-CP3L6x1-.js} +1 -1
  13. package/dist/assets/MobileShareBridge-BCuk5mbi.js +4 -0
  14. package/dist/assets/MobileSurface-Dz_oFrar.js +2 -0
  15. package/dist/assets/{MultiRunWindow-DdnQ8IVy.js → MultiRunWindow-2JHpZSxf.js} +1 -1
  16. package/dist/assets/{OnboardingScreen-C1n_wVb-.js → OnboardingScreen-BhSzVmYo.js} +1 -1
  17. package/dist/assets/{OverlayScrollbar-CXFN6Cqq.js → OverlayScrollbar-CHXk_jvF.js} +1 -1
  18. package/dist/assets/{SettingsView-B7ETzV-K.js → SettingsView-_x5DRAHK.js} +10 -10
  19. package/dist/assets/{SettingsWindow-C4qb5YJp.js → SettingsWindow-jWfQNCAS.js} +1 -1
  20. package/dist/assets/{TerminalView-DZ0003gd.js → TerminalView-DLlxlIWQ.js} +1 -1
  21. package/dist/assets/{ToolOutputDialog-C2KTvp-_.js → ToolOutputDialog-Cy-cG7Vn.js} +1 -1
  22. package/dist/assets/appThemeRegistry-DWUqOAxX.js +2 -0
  23. package/dist/assets/{button-BQY5ugjh.js → button-CwLFtUNT.js} +1 -1
  24. package/dist/assets/{clipboard-BvJ7NunE.js → clipboard-DhOMUCwT.js} +1 -1
  25. package/dist/assets/{collapsible-CqcZGw3W.js → collapsible-CP1-_pY6.js} +1 -1
  26. package/dist/assets/{context-menu-DuFC0HbN.js → context-menu-BOZfQke9.js} +1 -1
  27. package/dist/assets/desktopHosts-Cr3LE55y.js +1 -0
  28. package/dist/assets/desktopRelayRestore-VfMK9fdk.js +1 -0
  29. package/dist/assets/{diagram-B8D9Klct.js → diagram-rYL80jaS.js} +1 -1
  30. package/dist/assets/{dialog-sGFkIKP2.js → dialog-BoAAoL5Z.js} +1 -1
  31. package/dist/assets/{es-BuinIayO.js → es-BXQb1dPR.js} +2 -2
  32. package/dist/assets/{fileQueries-BSE4ycQt.js → fileQueries-CXaw4b1W.js} +1 -1
  33. package/dist/assets/{fr-CT7us58h.js → fr-BTyDIvxw.js} +3 -3
  34. package/dist/assets/{gitApi-7wspWRVB.js → gitApi-BNZDCH9W.js} +1 -1
  35. package/dist/assets/{input-CgIoxUJc.js → input-D52Jicb1.js} +1 -1
  36. package/dist/assets/{insertionBoundaries-DoxhiE_l.js → insertionBoundaries-CFZyQPIS.js} +1 -1
  37. package/dist/assets/{ja-CCuAH4nO.js → ja-fcQgtBFy.js} +2 -2
  38. package/dist/assets/{ko-lXbhGt6P.js → ko-CgoVt1eb.js} +2 -2
  39. package/dist/assets/{main-DcfiRQEP.js → main-5R9S2b57.js} +2 -2
  40. package/dist/assets/{main-DG8UmEpF.js → main-BNYmBvzd.js} +13 -13
  41. package/dist/assets/{markdown-worker-C5Om4TVK.js → markdown-worker-N9d_Z-7s.js} +1 -1
  42. package/dist/assets/{markdownTheme-BdF4C4-o.js → markdownTheme-Bl0Sy0Lf.js} +1 -1
  43. package/dist/assets/{miniChat-BL9ppFy8.js → miniChat-CExPRYpL.js} +2 -2
  44. package/dist/assets/mobile-C7QGpUuZ.js +2 -0
  45. package/dist/assets/{multirun-BXAN6NKd.js → multirun-QU06PjW9.js} +1 -1
  46. package/dist/assets/persistence-vZ7H8WKh.js +3 -0
  47. package/dist/assets/pl-DVDnk2fT.js +15 -0
  48. package/dist/assets/platform-CTaznShj.js +2 -0
  49. package/dist/assets/{projectMeta-Bail3NaE.js → projectMeta-CVVj8TB_.js} +2 -2
  50. package/dist/assets/{pt-BR-DWbGs1bc.js → pt-BR-ofV_Qcd_.js} +2 -2
  51. package/dist/assets/radio-CTMWDitv.js +1 -0
  52. package/dist/assets/{renderElectronMiniChatApp-CU-gCTkr.js → renderElectronMiniChatApp-QBAHpTW_.js} +2 -2
  53. package/dist/assets/{renderMobileApp-BG5Csi9J.js → renderMobileApp-CodaHpQJ.js} +5 -5
  54. package/dist/assets/runtimeConfig-BWMVRpO_.js +2 -0
  55. package/dist/assets/{runtimeEndpointReset-Bwss1HBr.js → runtimeEndpointReset-CqrqWzhd.js} +2 -2
  56. package/dist/assets/{sortable-tabs-strip-pSnPuBXA.js → sortable-tabs-strip-N3j5So4j.js} +1 -1
  57. package/dist/assets/src-Dbdlm5x1.css +2 -0
  58. package/dist/assets/{store-BuXogmxp.js → store-Hr-xvtDJ.js} +2 -2
  59. package/dist/assets/{terminalApi-jfes-HIU.js → terminalApi-KDUc5mh2.js} +1 -1
  60. package/dist/assets/{tooltip-rN8LrxMF.js → tooltip-CaCe-GAm.js} +1 -1
  61. package/dist/assets/{uk-DgOxtvS7.js → uk-Dzob0yMx.js} +2 -2
  62. package/dist/assets/{url-B0Ak7X6b.js → url-B-FWrnxu.js} +1 -1
  63. package/dist/assets/useAppFontEffects-CKhScw6W.js +7 -0
  64. package/dist/assets/{useAssistantUIStore-SPh025NE.js → useAssistantUIStore-ifqNyja4.js} +1 -1
  65. package/dist/assets/{useDesktopWindowControlsLayout-DNU1P1i5.js → useDesktopWindowControlsLayout-D9kVYRmX.js} +1 -1
  66. package/dist/assets/{useEffectiveDirectory-Cc1z5OgH.js → useEffectiveDirectory-srkYLmiC.js} +1 -1
  67. package/dist/assets/{useFontPreferences-Bz3crRRO.js → useFontPreferences-D_LFFhFS.js} +1 -1
  68. package/dist/assets/useMobileNavigationStore-DmXpNTih.js +476 -0
  69. package/dist/assets/useSessionAutoCleanup-BB45s--Y.js +1 -0
  70. package/dist/assets/useUIStore-NfqK-HA7.js +1 -0
  71. package/dist/assets/{useWorkerHighlightedLines-C3FzDa-K.js → useWorkerHighlightedLines-DyP0kh5l.js} +1 -1
  72. package/dist/assets/{utils-DfPDhqys.js → utils-C2P0wcWO.js} +1 -1
  73. package/dist/assets/{zh-CN-BPGatJp9.js → zh-CN-Sndj2nhS.js} +2 -2
  74. package/dist/assets/{zh-TW-qUWWsaxK.js → zh-TW-S24a8EMD.js} +2 -2
  75. package/dist/index.html +9 -9
  76. package/dist/mini-chat.html +9 -9
  77. package/dist/mobile.html +9 -9
  78. package/package.json +1 -1
  79. package/server/index.d.ts +0 -4
  80. package/server/index.js +11 -20
  81. package/server/lib/client-auth/pairing.js +1 -7
  82. package/server/lib/client-auth/pairing.test.js +0 -45
  83. package/server/lib/opencode/DOCUMENTATION.md +4 -4
  84. package/server/lib/opencode/bootstrap-runtime.js +0 -6
  85. package/server/lib/opencode/cli-entry-runtime.js +5 -1
  86. package/server/lib/opencode/cli-entry-runtime.test.js +17 -0
  87. package/server/lib/opencode/core-routes.js +0 -3
  88. package/server/lib/opencode/core-routes.test.js +0 -15
  89. package/server/lib/opencode/openchamber-routes.js +0 -11
  90. package/server/lib/relay/DOCUMENTATION.md +3 -45
  91. package/server/lib/relay/host-client.js +1 -4
  92. package/server/lib/relay/service.js +28 -16
  93. package/server/lib/relay/service.test.js +64 -4
  94. package/server/lib/relay/tunnel-host.js +2 -52
  95. package/server/lib/relay/tunnel-host.test.js +2 -250
  96. package/dist/assets/MobileShareBridge-DMka9_SA.js +0 -4
  97. package/dist/assets/MobileSurface-Bld2FOxI.js +0 -2
  98. package/dist/assets/appThemeRegistry-CscNaEL-.js +0 -2
  99. package/dist/assets/desktopHosts-aA40MHzB.js +0 -1
  100. package/dist/assets/desktopRelayRestore-CxUYRC6v.js +0 -1
  101. package/dist/assets/mobile-BRxbjeRa.js +0 -2
  102. package/dist/assets/persistence-DwXJK4-j.js +0 -3
  103. package/dist/assets/pl-DCsKBRAg.js +0 -15
  104. package/dist/assets/platform-CXJwZIZe.js +0 -2
  105. package/dist/assets/radio-CClZkzaR.js +0 -1
  106. package/dist/assets/runtimeConfig-DC0OJ777.js +0 -2
  107. package/dist/assets/src-DF4hiLrB.css +0 -2
  108. package/dist/assets/useAppFontEffects-DO3Jc7RO.js +0 -7
  109. package/dist/assets/useMobileNavigationStore-Dw9Ibked.js +0 -476
  110. package/dist/assets/useSessionAutoCleanup-Bpf4lLlD.js +0 -1
  111. package/dist/assets/useUIStore-BJpkPwky.js +0 -1
  112. package/server/lib/desktop-hosts/routes.js +0 -157
  113. package/server/lib/desktop-hosts/routes.test.js +0 -227
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-heic2any-CUPf3g2A.js","assets/rolldown-runtime-C0FnF6B9.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,D as n,E as r,F as i,H as a,T as o,X as s,b as c,et as l,j as u,nt as d}from"./useUIStore-BJpkPwky.js";import{$t as f,Mt as p,Pt as m,Xt as h,kn as g,nt as ee,ot as te,pt as ne,r as _,st as v,xn as re,zt as ie}from"./persistence-DwXJK4-j.js";import{a as ae,r as oe}from"./vendor-zustand-B4dlGEM2.js";import{t as se}from"./vendor-opencode-sdk-C07HQypa.js";import{i as ce}from"./vendor-pathe-vBmvQE8f.js";import{o as le}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";var ue=(e,t)=>e!==t,de=new Set([`image/heic`,`image/heif`]),fe=!1,pe=()=>{let e=globalThis.window?.Capacitor;return e&&typeof e==`object`?e:null},me=e=>de.has((e.type||``).toLowerCase()),he=async e=>{let t=new Uint8Array(await e.arrayBuffer()),n=``,r=32768;for(let e=0;e<t.byteLength;e+=r){let i=t.subarray(e,Math.min(e+r,t.byteLength));n+=String.fromCharCode(...i)}return btoa(n)},ge=(e,t)=>{let n=atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return new Blob([r],{type:t})},_e=async e=>{if(!me(e)||fe)return null;let t=pe();if(!t||typeof t.isNativePlatform!=`function`||!t.isNativePlatform())return null;let n=t.Plugins?.OpenChamberMedia?.transcode;if(typeof n!=`function`)return null;try{let t=await n({data:await he(e),mime:e.type.toLowerCase(),quality:.9});if(typeof t?.data!=`string`||!t.data)return null;let r=typeof t.mime==`string`&&t.mime?t.mime:`image/jpeg`;return ge(t.data,r)}catch(e){return fe=!0,console.warn(`Native HEIC transcode failed`,e),null}},ve=e=>e.trim().toLowerCase(),ye=e=>e.source===`local`||e.source===`server`||e.source===`vscode`,be=(e,t)=>{if(!e||!e.includes(`[`)||t.length===0)return[];let n=new Set(t.map(ve)),r=[],i=0;for(;i<e.length;){let t=e.indexOf(`[`,i);if(t===-1)break;let a=e.indexOf(`]`,t+1);if(a===-1)break;if(e[a+1]!==`(`){let i=ne(e.slice(t+1,a)).trim();n.has(ve(i))&&r.push({start:t,end:a+1})}i=a+1}return r},xe=(e,t)=>{let n=t.start,r=t.end;return r<e.length&&/\s/.test(e[r])?r+=1:n>0&&/\s/.test(e[n-1])&&--n,{start:n,end:r}},Se=(e,t,n,r)=>{let i=be(e,t);if(i.length===0)return{text:e,mentions:[...n],composerReferences:r===void 0?void 0:[...r],changed:!1};let a=e,o=[...n],s=r===void 0?[]:[...r];for(let e=i.length-1;e>=0;--e){let{start:t,end:n}=xe(a,i[e]),r=n-t;a=`${a.slice(0,t)}${a.slice(n)}`,o=o.flatMap(e=>e.range.end<=t?[e]:e.range.start>=n?[{...e,range:{start:e.range.start-r,end:e.range.end-r}}]:[]),s=s.flatMap(e=>e.end<=t?[e]:e.start>=n?[{...e,start:e.start-r,end:e.end-r}]:[])}return{text:a,mentions:o,composerReferences:r===void 0?void 0:s,changed:!0}},Ce=new Set([`image`,`screenshot`,`screen-shot`,`clipboard`,`pasted-image`,`pastedimage`,`untitled`,`unknown`,`file`,`blob`]),we={"image/avif":`avif`,"image/bmp":`bmp`,"image/gif":`gif`,"image/heic":`heic`,"image/heif":`heif`,"image/jpeg":`jpg`,"image/jpg":`jpg`,"image/png":`png`,"image/svg+xml":`svg`,"image/tiff":`tiff`,"image/webp":`webp`},y=e=>e.trim().toLowerCase(),Te=e=>e.charCodeAt(0)<32||`<>:"/\\|?*[]`.includes(e),Ee=e=>{let t=e.replace(/\\/g,`/`).split(`/`).pop()??``;return Array.from(t).map(e=>Te(e)?`-`:e).join(``).replace(/\s+/g,` `).replace(/-+/g,`-`).trim()},De=e=>we[e?.trim().toLowerCase()??``]??`png`,Oe=e=>{let t=Ee(e.name),n=De(e.type),r=t.lastIndexOf(`.`);if(r>0&&r<t.length-1){let e=t.slice(r+1).toLowerCase();if(/^[a-z0-9]{1,10}$/.test(e))return{base:t.slice(0,r).trim()||`image`,ext:e}}return{base:t.trim()||`image`,ext:n}},ke=e=>{let{base:t}=Oe({name:e}),n=t.trim().toLowerCase().replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``);if(Ce.has(n))return!0;let r=n.replace(/-\(\d+\)$/g,``);return r!==n&&Ce.has(r)?!0:/^(image|file|unknown|untitled|blob)-\d+$/.test(n)},b=(e,t)=>`${e}.${t}`,Ae=(e,t,n)=>{let r=b(e,t);if(!n.has(y(r)))return r;for(let r=2;r<2**53-1;r+=1){let i=b(`${e}-${r}`,t);if(!n.has(y(i)))return i}return b(`${e}-${Date.now()}`,t)},je=(e,t)=>{for(let n=1;n<2**53-1;n+=1){let r=b(`image-${n}`,e);if(!Array.from(t).some(e=>e.startsWith(`image-${n}.`))&&!t.has(y(r)))return r}return b(`image-${Date.now()}`,e)},Me=(e,t)=>{let n=new Set(t.map(y));return e.map(e=>{let{base:t,ext:r}=Oe(e),i=ke(b(t,r))?je(r,n):Ae(t,r,n);return n.add(y(i)),i})},Ne=e=>e.map(e=>v(e)).join(` `),Pe=(e,t,n)=>{if(t===n)return[];let r=[];for(let i of e){let e=[v(i),`[${i}]`],a=e.some(e=>t.includes(e)),o=e.some(e=>n.includes(e));a&&!o&&r.push(i)}return r},Fe=e=>e.replaceAll(`[${te}`,`[`),Ie=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,Le=e=>{let t=e.trim();return t.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(t)||t.startsWith(`\\\\`)},Re=(e,t)=>{let n=e;for(let e of t){let t=e.filename.trim(),r=e.path.trim();if(!t||!r||t===r||Le(t)||!Ie.test(t)&&!Ie.test(r))continue;let i=`[${r}]`;n=n.split(v(t)).join(i).split(`[${t}]`).join(i)}return n},ze=(e,t)=>{let n=e;for(let e of t??[]){if(e.source!==`vscode`||e.vscodeSource!==`selection`||!e.vscodePath)continue;let t=e.filename.match(/:(\d+(?:-\d+)?)$/)?.[1];if(!t)continue;let r=`[${e.vscodePath}:${t}]`;n=n.split(v(e.filename)).join(r).split(`[${e.filename}]`).join(r)}return n},Be=e=>e.mime===`text/plain`&&typeof e.filename==`string`&&/:\d+(?:-\d+)?$/.test(e.filename),Ve=`application/x-directory`,He=e=>typeof e==`string`&&e.trim().toLowerCase()===`application/x-directory`,Ue=e=>typeof e==`string`&&/[/\\]$/.test(e.trim()),We=(e,t,n)=>{if(t===`Backspace`){let t=n;for(;t>0&&/\s/.test(e[t-1]);)--t;for(;t>0&&!/\s/.test(e[t-1]);)--t;return{start:t,end:n}}let r=n;for(;r<e.length&&/\s/.test(e[r]);)r+=1;for(;r<e.length&&!/\s/.test(e[r]);)r+=1;return{start:n,end:r}},Ge=(e,t,n)=>{let r=Math.max(0,Math.min(n.selectionStart,e.length)),i=Math.max(r,Math.min(n.selectionEnd,e.length)),a;if(a=r===i?n.altKey?We(e,n.key,r):n.key===`Backspace`?{start:Math.max(0,r-1),end:r}:{start:r,end:Math.min(e.length,r+1)}:{start:r,end:i},a.start===a.end)return null;let o=be(e,t).filter(e=>e.start<a.end&&e.end>a.start);if(o.length===0)return null;let s=Math.min(a.start,...o.map(e=>e.start)),c=Math.max(a.end,...o.map(e=>e.end));return c<e.length&&/\s/.test(e[c])&&(s===0||/\s/.test(e[s-1]))?c+=1:c===e.length&&s>0&&/\s/.test(e[s-1])&&--s,{text:`${e.slice(0,s)}${e.slice(c)}`,caret:s,removedFilenames:o.map(t=>ne(e.slice(t.start+1,t.end-1)).trim())}},x=class extends Error{status;code;constructor(e,t,n=`Failed to upload prompt attachment`){super(n),this.name=`PromptAttachmentUploadError`,this.status=e,this.code=t}},S=`file://`,Ke=e=>{let t=e.trim();if(t.toLowerCase().startsWith(S))return t;let n=ce(t).split(`/`).map(e=>/^[A-Za-z]:$/.test(e)?e:encodeURIComponent(e)).join(`/`);return/^[A-Za-z]:/.test(n)?`${S}/${n}`:`${S}${n}`},qe=e=>{let t=e.trim();if(!t.toLowerCase().startsWith(S))return t;let n=t.slice(7);n.toLowerCase().startsWith(`localhost/`)&&(n=n.slice(9));let r=n.split(`/`).map(e=>{if(/^[A-Za-z]:$/.test(e))return e;try{return decodeURIComponent(e)}catch{return e}}).join(`/`);return/^\/[A-Za-z]:/.test(r)?r.slice(1):r},Je=async e=>[...new Uint8Array(await crypto.subtle.digest(`SHA-256`,await e.arrayBuffer()))].map(e=>e.toString(16).padStart(2,`0`)).join(``),Ye=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Xe=async e=>{let t;try{t=await e.json()}catch{throw new x(e.status,`unavailable`)}if(!Ye(t)||typeof t.path!=`string`||!t.path)throw new x(e.status,`unavailable`);let n=typeof t.mime==`string`&&t.mime?t.mime:`application/octet-stream`,r=typeof t.size==`number`&&Number.isSafeInteger(t.size)?t.size:0,i=typeof t.sha256==`string`?t.sha256:``;return{path:t.path,url:Ke(t.path),mime:n,size:r,sha256:i}},Ze=e=>{let t=typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,n=e?.replace(/[^a-z0-9._-]+/gi,`-`).replace(/^-+|-+$/g,``).slice(0,32);return n?`att-${t}-${n}`:`att-${t}`},Qe=(e,t)=>{if(!e.startsWith(`data:`))return null;let n=e.indexOf(`,`);if(n===-1)return null;let r=e.slice(5,n),i=e.slice(n+1),a=r.split(`;`,1)[0]?.trim()||t||`application/octet-stream`;try{if(r.toLowerCase().includes(`;base64`)){let e=atob(i),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return new Blob([t],{type:a})}return new Blob([decodeURIComponent(i)],{type:a})}catch{return null}},$e=e=>e.startsWith(`data:`)||e.startsWith(`blob:`),et=async e=>{let t=e.mime||e.body.type||`application/octet-stream`,n=e.body.type===t?e.body:new Blob([e.body],{type:t});if(!Number.isSafeInteger(n.size)||n.size<0||n.size>26214400)throw new x(413,`too-large`);let r=await Je(n),i=Ze(e.filename),a;try{a=await g(`/api/fs/prompt-attachments/${encodeURIComponent(i)}`,{method:`PUT`,headers:{"Content-Type":t,"Content-Length":String(n.size),"X-OpenChamber-Content-Length":String(n.size),"X-OpenChamber-Sha256":r,"X-OpenChamber-Mime":t,...e.filename?{"X-OpenChamber-Filename":encodeURIComponent(e.filename)}:{}},body:n,signal:e.signal})}catch{throw new x(0,`unavailable`)}if(a.status===413)throw new x(413,`too-large`);if(!a.ok)throw new x(a.status,a.status>=500||a.status===0?`unavailable`:`rejected`);let o=await Xe(a);if(o.size!==n.size)throw new x(a.status,`unavailable`);return{...o,mime:t}},tt=500,nt=()=>{if(typeof window>`u`)return!1;try{return new URLSearchParams(window.location.search).get(`startupTrace`)===`1`||window.localStorage?.getItem(`OPENCHAMBER_STARTUP_TRACE`)===`1`}catch{return!1}},rt=()=>nt(),C=(e,t)=>{if(!nt())return;let n=typeof performance<`u`?performance.now():Date.now();window.__OPENCHAMBER_STARTUP_TRACE_START__??=n,window.__OPENCHAMBER_STARTUP_TRACE__??=[],window.__OPENCHAMBER_STARTUP_TRACE__.push({t:Math.round(n-window.__OPENCHAMBER_STARTUP_TRACE_START__),name:e,...t?{data:t}:{}}),window.__OPENCHAMBER_STARTUP_TRACE__.length>tt&&window.__OPENCHAMBER_STARTUP_TRACE__.splice(0,window.__OPENCHAMBER_STARTUP_TRACE__.length-tt)};typeof window<`u`&&(window.__OPENCHAMBER_STARTUP_TRACE_SUMMARY__=()=>{let e=typeof window<`u`?window.__OPENCHAMBER_STARTUP_TRACE__??[]:[],t=e.findIndex(e=>e.name===`ModelControls:ready`),n=t>=0?Math.min(e.length,t+8):e.length;return e.slice(0,n).filter(e=>e.name.includes(`checkConnection`)||e.name.includes(`checkHealth`)||e.name.includes(`initializeApp`)||e.name.includes(`initApp`)||e.name.includes(`loadProviders`)||e.name.includes(`loadAgents`)||e.name.includes(`config.defaults`)||e.name.includes(`ModelControls`)||e.name.includes(`activateDirectory`)||e.name.includes(`opencodeClient:setDirectory`))});var it=async(e,t,n)=>{let r=typeof performance<`u`?performance.now():Date.now();C(`${e}:start`,n);try{let n=await t(),i=typeof performance<`u`?performance.now():Date.now();return C(`${e}:end`,{durationMs:Math.round(i-r)}),n}catch(t){let n=typeof performance<`u`?performance.now():Date.now();throw C(`${e}:error`,{durationMs:Math.round(n-r),error:t instanceof Error?t.message:String(t)}),t}},at=3,ot=3e4,st=32e3,ct=36e5,lt=6e5,ut=new Set([429,502,503,504]),w=new Map;function dt(){let e=Date.now();for(let[t,n]of w)n.consecutiveErrors===0&&e-n.lastErrorAt>ct&&w.delete(t)}typeof setInterval<`u`&&setInterval(dt,lt).unref?.();function ft(e){let t=w.get(e);return t||(t={consecutiveErrors:0,lastErrorAt:0,circuitOpen:!1,circuitOpenAt:0,circuitCooldownMs:ot},w.set(e,t)),t}function pt(e){if(!e)return;let t=w.get(e);t&&(t.consecutiveErrors=0,t.lastErrorAt=0)}function mt(e,t){if(!e)return;let n=ft(e);n.consecutiveErrors+=1,n.lastErrorAt=Date.now(),ht(t)&&n.consecutiveErrors>=at&&(n.circuitOpen=!0,n.circuitOpenAt=Date.now(),console.warn(`[provider-tracker] Circuit opened for ${e} after ${n.consecutiveErrors} consecutive errors`))}function ht(e){return e!==void 0&&ut.has(e)}function gt(e){let t=w.get(e);return t?.circuitOpen?Date.now()-t.circuitOpenAt>=t.circuitCooldownMs?(t.circuitOpen=!1,t.consecutiveErrors=0,t.circuitCooldownMs=Math.min(t.circuitCooldownMs*2,st*4),!1):!0:!1}function _t(e){if(!(!e||!gt(e)))throw Error(`Provider ${e} is temporarily unavailable after repeated errors. Please retry shortly.`)}var vt=`/api`,yt=1e4,bt=4e3,xt=3e3,St=1e3,Ct=12e3;function T(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;if(e&&typeof e==`object`&&`message`in e&&typeof e.message==`string`)return e.message;try{return JSON.stringify(e)}catch{return String(e)}}function E(e,t){if(e.error){let n=e.response?.status,r=Error(`${t} failed${n?` (${n})`:``}: ${T(e.error)}`);throw n!==void 0&&(r.status=n),r}if(e.data===void 0||e.data===null)throw Error(`${t} failed: empty response`);return e.data}function D(e,t){if(e.error){let n=e.response?.status,r=Error(`${t} failed${n?` (${n})`:``}: ${T(e.error)}`);throw n!==void 0&&(r.status=n),r}return e.data}var wt=/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//,Tt=e=>{let t=typeof e==`string`&&e.trim().length>0?e.trim():`/api`;if(wt.test(t)||typeof window>`u`)return t;let n=window.location?.href||window.location?.origin;if(!n)return t;try{return new URL(t,n).toString()}catch(e){return console.warn(`Failed to normalize OpenCode base URL:`,e),t}},Et=()=>{try{return i().api(`/api`)}catch{return null}},Dt=()=>{try{return i().api(`/`)}catch{return null}},Ot=e=>{let t=typeof AbortSignal<`u`?AbortSignal:void 0;if(typeof t?.timeout==`function`)return{signal:t.timeout(e),cleanup:()=>void 0};let n=new AbortController,r=setTimeout(()=>n.abort(),e);return{signal:n.signal,cleanup:()=>clearTimeout(r)}},kt=e=>{let t=e.filter(e=>e!=null);if(t.length===0)return{signal:new AbortController().signal,cleanup:()=>void 0};if(t.length===1)return{signal:t[0],cleanup:()=>void 0};let n=typeof AbortSignal<`u`?AbortSignal:void 0;if(typeof n?.any==`function`)return{signal:n.any(t),cleanup:()=>void 0};let r=new AbortController,i=()=>r.abort();for(let e of t){if(e.aborted){r.abort();break}e.addEventListener(`abort`,i)}return{signal:r.signal,cleanup:()=>{for(let e of t)e.removeEventListener(`abort`,i)}}},O=e=>se({...e,fetch:g}),At=e=>typeof e.mime==`string`&&e.mime.startsWith(`image/`)?!0:typeof e.filename==`string`&&/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i.test(e.filename),jt=e=>{let t=[];for(let n of e){if(!At(n))continue;let e=typeof n.filename==`string`?n.filename.trim():``,r=typeof n.url==`string`?n.url:``;if(!e||!r.toLowerCase().startsWith(`file://`))continue;let i=qe(r).trim();i&&t.push({filename:e,path:i})}return t},Mt=async(e,t)=>{let n=[],r=e.files?.length?await Promise.all(e.files.map(e=>t(e))):[],i=e.additionalParts?.length?await Promise.all(e.additionalParts.map(async e=>({text:e.text,synthetic:e.synthetic,files:e.files?.length?await Promise.all(e.files.map(e=>t(e))):[]}))):[],a=e=>Re(e,jt([...r,...i.flatMap(e=>e.files)]));if(e.prefaceText&&e.prefaceText.trim()&&n.push({type:`text`,text:a(e.prefaceText),synthetic:e.prefaceTextSynthetic!==!1}),e.text&&e.text.trim()&&n.push({type:`text`,text:a(e.text)}),n.push(...r),i.length>0)for(let e of i){if(e.text&&e.text.trim()){let t={type:`text`,text:a(e.text)};e.synthetic&&(t.synthetic=!0),n.push(t)}n.push(...e.files)}if(e.agentMentions&&e.agentMentions.length>0)for(let t of e.agentMentions){if(!t?.name)continue;let e={type:`agent`,name:t.name};t.source&&(e.source=t.source),n.push(e)}if(n.length===0)throw Error(`Message must have at least one part (text or file)`);return n},k=e=>e.replace(/\\/g,`/`),Nt=400,Pt=()=>{let e=re();return e&&e.runtime?.isDesktop&&e.files?e.files:null},A=new class{client;baseUrl;scopedClients=new Map;currentDirectory=void 0;directoryContextQueue=Promise.resolve();listDirectoryInFlight=new Map;configProvidersInFlight=new Map;listAgentsInFlight=new Map;configInFlight=new Map;configCache=new Map;configCacheGeneration=0;listDirectoryCache=new Map;healthInFlight=new Map;healthCache=new Map;healthCacheGeneration=0;constructor(e=vt){let t=Et()||e;this.baseUrl=Tt(t),this.client=O({baseUrl:this.baseUrl})}getBaseUrl(){return this.baseUrl}reconnectToRuntimeBaseUrl(){let e=Tt(Et()||vt);e!==this.baseUrl&&(this.baseUrl=e,this.client=O({baseUrl:this.baseUrl}),this.scopedClients.clear(),this.listDirectoryInFlight.clear(),this.configProvidersInFlight.clear(),this.listAgentsInFlight.clear(),this.clearConfigCache(),this.listDirectoryCache.clear(),this.clearHealthCache())}getSdkClient(){return this.client}getScopedSdkClient(e){return this.getScopedApiClient(e)}getScopedApiClient(e){let t=this.normalizeCandidatePath(e)??e,n=t||``,r=this.scopedClients.get(n);if(r)return r;let i=O({baseUrl:this.baseUrl,directory:t});return this.scopedClients.set(n,i),i}normalizeCandidatePath(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=t.replace(/\\/g,`/`).replace(/^([a-z]):/,(e,t)=>t.toUpperCase()+`:`);return(n.length>1?n.replace(/\/+$/,``):n)||null}deriveHomeDirectory(e){let t=e.match(/^([A-Za-z]:)(?:\/|$)/);if(t){let n=t[1],r=e.slice(n.length+ +(e.charAt(n.length)===`/`)).split(`/`).filter(Boolean);return r.length>=2?{homeDirectory:`${n}/${r[0]}/${r[1]}`,username:r[1]}:r.length===1?{homeDirectory:`${n}/${r[0]}`,username:r[0]}:{homeDirectory:n,username:void 0}}let n=e.startsWith(`/`),r=e.split(`/`).filter(Boolean);return r.length>=2&&(r[0]===`Users`||r[0]===`home`)?{homeDirectory:`${n?`/`:``}${r[0]}/${r[1]}`,username:r[1]}:n?r.length===0?{homeDirectory:`/`,username:void 0}:{homeDirectory:`/${r.join(`/`)}`,username:r[r.length-1]}:r.length>0?{homeDirectory:`/${r.join(`/`)}`,username:r[r.length-1]}:{homeDirectory:`/`,username:void 0}}setDirectory(e){let t=this.normalizeCandidatePath(e)??e;this.currentDirectory!==t&&C(`opencodeClient:setDirectory`,{previous:this.currentDirectory??null,next:t??null}),this.currentDirectory=t}getDirectory(){return this.currentDirectory}async withDirectory(e,t){let n=async()=>{if(e==null)return t();let n=this.currentDirectory,r=this.normalizeCandidatePath(e)??e;this.currentDirectory=r;try{return await t()}finally{this.currentDirectory===r&&(this.currentDirectory=n)}},r=this.directoryContextQueue.then(n,n);return this.directoryContextQueue=r.then(()=>void 0,()=>void 0),r}getApiClient(){return this.client}async getSystemInfo(){let e=new Set,t=t=>{let n=this.normalizeCandidatePath(t);n&&e.add(n)};try{let e=(await this.client.path.get(this.currentDirectory?{directory:this.currentDirectory}:void 0)).data;e&&(t(e.directory),t(e.worktree),t(e.state))}catch{}if(!e.size)try{t((await this.client.project.current(this.currentDirectory?{directory:this.currentDirectory}:void 0)).data?.worktree)}catch{}if(!e.size)try{(await this.listSessions()).forEach(e=>t(e.directory))}catch{}if(t(this.currentDirectory),typeof window<`u`)try{t(p(`lastDirectory`)),t(p(`homeDirectory`))}catch{}if(!e.size&&typeof process<`u`&&typeof process.cwd==`function`&&t(process.cwd()),!e.size)return{homeDirectory:`/`,username:void 0};let[n]=Array.from(e);return this.deriveHomeDirectory(n)}async probeDirectory(e){let t=this.normalizeCandidatePath(e);if(!t)return!1;try{let e=(await this.client.path.get({directory:t})).data,n=typeof e?.directory==`string`?e.directory:null;return!!(n&&n.trim().length>0)}catch{return!1}}async listSessions(){let e=await this.client.session.list(this.currentDirectory?{directory:this.currentDirectory}:void 0);return Array.isArray(e.data)?e.data:[]}async createSession(e,t){let n=this.normalizeCandidatePath(t)??this.currentDirectory;return E(await this.client.session.create({...n?{directory:n}:{},parentID:e?.parentID,title:e?.title,metadata:e?.metadata}),`session.create`)}async getSession(e,t){let n=this.normalizeCandidatePath(t)??this.currentDirectory;return E(await this.client.session.get({sessionID:e,...n?{directory:n}:{}}),`session.get`)}async deleteSession(e,t){let n=this.normalizeCandidatePath(t)??this.currentDirectory;return D(await this.client.session.delete({sessionID:e,...n?{directory:n}:{}}),`session.delete`)===!0}async deleteSessionMessage(e,t,n){let r=this.normalizeCandidatePath(n)??this.currentDirectory;return D(await this.client.session.deleteMessage({sessionID:e,messageID:t,...r?{directory:r}:{}}),`session.deleteMessage`)===!0}async updateSession(e,t,n){let r=this.normalizeCandidatePath(n)??this.currentDirectory,i={...t.title===void 0?{}:{title:t.title},...t.metadata===void 0?{}:{metadata:t.metadata},...t.time?.archived!==void 0&&t.time.archived!==null?{time:{archived:t.time.archived}}:{}};return E(await this.client.session.update({sessionID:e,...r?{directory:r}:{},...i}),`session.update`)}async getSessionMessages(e,t){return E(await this.client.session.messages({sessionID:e,...this.currentDirectory?{directory:this.currentDirectory}:{},...typeof t==`number`?{limit:t}:{}}),`session.messages`)}async getSessionDiff(e,t){let n=this.normalizeCandidatePath(e.directory)??this.currentDirectory,r=typeof e.messageID==`string`&&e.messageID.trim().length>0?e.messageID.trim():void 0,i={sessionID:e.sessionID,...n?{directory:n}:{},...r?{messageID:r}:{}};return E(t?.signal?await this.client.session.diff(i,{signal:t.signal}):await this.client.session.diff(i),`session.diff`)}async getSessionTodos(e){try{let t=await this.client.session.todo({sessionID:e,...this.currentDirectory?{directory:this.currentDirectory}:{}});if(t.error)return[];let n=t.data;return!n||!Array.isArray(n)?[]:n}catch{return[]}}shouldNormalizeToTextPlain(e){if(!e)return!1;let t=e.toLowerCase();return t.startsWith(`text/`)&&t!==`text/plain`?!0:[`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/yaml`,`application/toml`,`application/x-sh`,`application/x-shellscript`,`application/octet-stream`,`image/svg+xml`].includes(t)}isHeicMime(e){if(!e)return!1;let t=e.toLowerCase();return t===`image/heic`||t===`image/heif`}async convertHeicToJpeg(t){try{let n=Qe(t.url,t.mime);if(!n)return t;let r=await _e(n)??await(await le(async()=>{let{default:t}=await import(`./vendor-heic2any-CUPf3g2A.js`).then(t=>e(t.t(),1));return{default:t}},__vite__mapDeps([0,1]))).default({blob:n,toType:`image/jpeg`,quality:.9}),i=await new Promise((e,t)=>{let n=new FileReader;n.onload=()=>e(n.result),n.onerror=t,n.readAsDataURL(r)}),a=t.filename;return a&&=a.replace(/\.heic$/i,`.jpg`).replace(/\.heif$/i,`.jpg`),{mime:`image/jpeg`,filename:a,url:i}}catch(e){return console.warn(`Failed to convert HEIC to JPEG:`,e),t}}async normalizeFilePart(e){if(this.isHeicMime(e.mime))return this.convertHeicToJpeg(e);if(!this.shouldNormalizeToTextPlain(e.mime))return e;let t=e.url;if(e.url.startsWith(`data:`)){let n=e.url.indexOf(`,`);if(n!==-1){let r=e.url.substring(5,n),i=e.url.substring(n);t=`data:${r.replace(/^[^;,]+/,`text/plain`)}${i}`}}return{mime:`text/plain`,filename:e.filename,url:t}}async toNormalizedFilePartInput(e){let t=await this.normalizeFilePart(e),n=t.url;if($e(n)){let e=Qe(n,t.mime);if(!e)throw Error(`Failed to materialize attachment bytes for ${t.filename??`file`}`);n=(await et({body:e,mime:t.mime,filename:t.filename})).url}return{...e.id?{id:e.id}:{},type:`file`,mime:t.mime,filename:t.filename,url:n}}async buildMessageParts(e){return Mt(e,e=>this.toNormalizedFilePartInput(e))}async sendMessage(e){let t=e.messageId??ee(`msg`),n=await this.buildMessageParts({text:e.text,prefaceText:e.prefaceText,prefaceTextSynthetic:e.prefaceTextSynthetic,files:e.files,additionalParts:e.additionalParts,agentMentions:e.agentMentions}),r=this.normalizeCandidatePath(e.directory??null)??this.currentDirectory;e.format&&(e.id,e.providerID,e.modelID,e.agent,e.variant,this.baseUrl,e.format.type),_t(e.providerID);let i;try{let a=await this.client.session.promptAsync({sessionID:e.id,...r?{directory:r}:{},model:{providerID:e.providerID,modelID:e.modelID},agent:e.agent,variant:e.variant,messageID:t,...e.delivery?{delivery:e.delivery}:{},...e.format?{format:e.format}:{},parts:n});if(a.response instanceof Response)i=a.response;else if(a.error){let e=a.response?.status;if(!e)throw Error(`Message send transport failure: ${T(a.error)}`);i=new Response(JSON.stringify(a.error),{status:e})}else i=new Response(JSON.stringify(a.data??!0),{status:200})}catch(t){throw mt(e.providerID),t}if(i.ok)return pt(e.providerID),t;let a=``;try{a=await i.text()}catch{}let o=a&&a.trim().length>0?`: ${a.trim()}`:``,s=Error(`Failed to send message (${i.status})${o}`);throw s.status=i.status,mt(e.providerID,i.status),s}async sendCommand(e){let t=e.messageId??ee(`msg`),n=[];if(e.files&&e.files.length>0)for(let t of e.files)n.push(await this.toNormalizedFilePartInput(t));let r=this.normalizeCandidatePath(e.directory??null)??this.currentDirectory;return D(await this.client.session.command({sessionID:e.id,...r?{directory:r}:{},command:e.command,arguments:e.arguments??``,model:`${e.providerID}/${e.modelID}`,agent:e.agent,variant:e.variant,...n.length>0?{parts:n}:{},messageID:t}),`session.command`),t}async abortSession(e){return!!(await this.client.session.abort({sessionID:e,...this.currentDirectory?{directory:this.currentDirectory}:{}},{throwOnError:!0})).data}async shellSession(e){let t=this.normalizeCandidatePath(e.directory??null)??this.currentDirectory;return E(await this.client.session.shell({sessionID:e.sessionId,...t?{directory:t}:{},messageID:e.messageId,agent:e.agent,model:e.model,command:e.command}),`session.shell`)}async revertSession(e,t,n,r){let i=this.normalizeCandidatePath(r)??this.currentDirectory;return E(await this.client.session.revert({sessionID:e,...i?{directory:i}:{},messageID:t,partID:n}),`session.revert`)}async summarizeSession(e,t,n,r){let i=this.normalizeCandidatePath(r)??this.currentDirectory;return D(await this.client.session.summarize({sessionID:e,...i?{directory:i}:{},providerID:t,modelID:n}),`session.summarize`)===!0}async unrevertSession(e){return E(await this.client.session.unrevert({sessionID:e,...this.currentDirectory?{directory:this.currentDirectory}:{}}),`session.unrevert`)}async forkSession(e,t,n){let r=this.normalizeCandidatePath(n)??this.currentDirectory,i=E(await this.client.session.fork({sessionID:e,...r?{directory:r}:{},messageID:t}),`session.fork`);return i.id,i}async getSessionStatus(){return await this.getSessionStatusForDirectory(this.currentDirectory??null)??{}}async getSessionStatusForDirectory(e,t){try{let n=typeof e==`string`?e.trim():``,r=await this.client.session.status(n?{directory:n}:void 0,t?{signal:t}:void 0);return r.error||!r.data||typeof r.data!=`object`?null:r.data}catch{return null}}async getSessionActive(e){try{let t=await O({baseUrl:Tt(Dt()||`/`)}).v2.session.active(e?{signal:e}:void 0),n=t.response?.status;if(t.error||n!==void 0&&n!==200)return n===404||n===405||n===501?{state:`unsupported`}:{state:`unknown`};let r=t.data,i=r&&typeof r==`object`&&`data`in r&&r.data!==void 0?r.data:r;if(!i||typeof i!=`object`||Array.isArray(i))return{state:`unknown`};let a={};for(let[e,t]of Object.entries(i)){if(typeof e!=`string`||e.length===0||!t||typeof t!=`object`||t.type!==`running`)return{state:`unknown`};a[e]={type:`running`}}return{state:`supported`,membership:a}}catch{return{state:`unknown`}}}async getGlobalSessionStatus(){return await this.getSessionStatusForDirectory(null)??{}}async getWebServerSessionActivity(){try{let e=await g(`/api/session-activity`,{method:`GET`,headers:{Accept:`application/json`}});if(!e.ok)return null;let t=await e.json().catch(()=>null);return!t||typeof t!=`object`?null:t}catch{return null}}async listToolIds(e){try{let t=typeof e?.directory==`string`?e.directory.trim():this.currentDirectory?this.currentDirectory.trim():``;return((await this.client.tool.ids(t?{directory:t}:void 0)).data||[]).filter(e=>typeof e==`string`&&e!==`invalid`)}catch{return[]}}async replyToPermission(e,t,n){let r=this.normalizeCandidatePath(n?.directory??null)??this.currentDirectory;return D(await this.client.permission.reply({requestID:e,...r?{directory:r}:{},reply:t,...n?.message?{message:n.message}:{}}),`permission.reply`)===!0}async createPermission(e,t,n,r){try{let i=await this.client.v2.session.permission.create({sessionID:e,action:t,resources:n,...r?.id?{id:r.id}:{},...r?.save?{save:r.save}:{},...r?.metadata?{metadata:r.metadata}:{},...r?.source?{source:r.source}:{},...r?.agent?{agent:r.agent}:{}});if(i.error!==void 0)return null;let a=i.data?.data;return a===void 0?null:{id:a.id,effect:a.effect}}catch{return null}}async fetchPermission(e,t){try{let n=await this.client.v2.session.permission.get({sessionID:e,requestID:t});if(n.error===void 0){let e=n.data?.data;if(e!==void 0)return{state:`ok`,permission:e}}return n.response?.status===404?{state:`resolved`}:{state:`unknown`}}catch{return{state:`unknown`}}}async listPendingPermissions(e){let t=[],n=async e=>{let t=typeof e==`string`?e.trim():``,n=await this.client.permission.list(t?{directory:t}:void 0);if(n.error)throw Error(`permission.list failed: ${T(n.error)}`);return n.data||[]};t.push(n(null));let r=new Set;for(let t of e?.directories??[]){let e=this.normalizeCandidatePath(t??null);e&&r.add(e)}for(let e of r)t.push(n(e));let i=await Promise.all(t),a=[],o=new Set;for(let e of i)for(let t of e){if(!t||typeof t!=`object`)continue;let e=t.id;typeof e==`string`&&e.length!==0&&(o.has(e)||(o.add(e),a.push(t)))}return a}async replyToQuestion(e,t,n){let r=!Array.isArray(t)||t.length===0?[]:Array.isArray(t[0])?t:[t],i=this.normalizeCandidatePath(n)??this.currentDirectory;return D(await this.client.question.reply({requestID:e,...i?{directory:i}:{},answers:r}),`question.reply`)===!0}async rejectQuestion(e){return D(await this.client.question.reject({requestID:e,...this.currentDirectory?{directory:this.currentDirectory}:{}}),`question.reject`)===!0}async listPendingQuestions(e){let t=[],n=async e=>{let t=typeof e==`string`?e.trim():``,n=await this.client.question.list(t?{directory:t}:void 0);if(n.error)throw Error(`question.list failed: ${T(n.error)}`);return n.data||[]};t.push(n(null));let r=new Set;for(let t of e?.directories??[]){let e=this.normalizeCandidatePath(t??null);e&&r.add(e)}for(let e of r)t.push(n(e));let i=await Promise.all(t),a=[],o=new Set;for(let e of i)for(let t of e){if(!t||typeof t!=`object`)continue;let e=t.id;typeof e==`string`&&e.length!==0&&(o.has(e)||(o.add(e),a.push(t)))}return a}clearConfigCache(){this.configCacheGeneration+=1,this.configInFlight.clear(),this.configCache.clear()}clearHealthCache(){this.healthCacheGeneration+=1,this.healthInFlight.clear(),this.healthCache.clear()}async getConfig(e){let t=this.normalizeCandidatePath(e)??e??this.currentDirectory??void 0,n=t??``,r=this.configCache.get(n);if(r&&r.expiresAt>Date.now())return C(`opencodeClient.getConfig:cacheHit`,{directory:t??null}),r.config;let i=this.configInFlight.get(n);if(i)return C(`opencodeClient.getConfig:deduped`,{directory:t??null}),i;let a=this.configCacheGeneration,o=(async()=>{C(`opencodeClient.getConfig:start`,{directory:t??null});let e=typeof performance<`u`?performance.now():Date.now(),r=await(t?this.getScopedApiClient(t):this.client).config.get();if(!r.data)throw Error(`Failed to get config`);let i=typeof performance<`u`?performance.now():Date.now();return C(`opencodeClient.getConfig:end`,{directory:t??null,durationMs:Math.round(i-e)}),a===this.configCacheGeneration&&this.configCache.set(n,{config:r.data,expiresAt:Date.now()+yt}),r.data})();this.configInFlight.set(n,o);try{return await o}finally{this.configInFlight.get(n)===o&&this.configInFlight.delete(n)}}async updateConfig(e){let t=E(await this.client.config.update({config:e}),`global.config.update`);return this.clearConfigCache(),t}async updateConfigPartial(e){let t=e(await this.getConfig());return await this.updateConfig(t)}async getProviders(){return this.getProvidersForConfig(this.currentDirectory)}async getProvidersForConfig(e){let t=e===void 0?this.currentDirectory??void 0:this.normalizeCandidatePath(e)??void 0,n=t??``,r=this.configProvidersInFlight.get(n);if(r)return r;let i=(async()=>E(await this.client.config.providers(t?{directory:t}:void 0),`config.providers`))();this.configProvidersInFlight.set(n,i);try{return await i}finally{this.configProvidersInFlight.delete(n)}}async getApp(){return{version:`0.0.3`,config:await this.getConfig()}}async initApp(){try{return await this.checkHealth()}catch{return!1}}async listAgents(e,t){let n=e===void 0?this.currentDirectory??void 0:this.normalizeCandidatePath(e)??void 0,r=n??``;if(!t){let e=this.listAgentsInFlight.get(r);if(e)return e}let i=(async()=>{let e=Ot(Ct),r=kt(t?[t,e.signal]:[e.signal]);try{let e=n?{directory:n}:void 0,t=await this.client.app.agents(e,{signal:r.signal});if(!t.error&&Array.isArray(t.data)&&t.data.length>0)return t.data;let i=await g(`/api/agent`,{...n?{query:{directory:n}}:{},signal:r.signal});if(!i.ok)throw t.error?Error(`app.agents failed${t.response?.status?` (${t.response.status})`:``}: ${T(t.error)}`):Error(`agent.list failed (${i.status})`);let a=await i.json().catch(()=>null);if(!Array.isArray(a))throw Error(`agent.list failed: invalid response`);return a}finally{e.cleanup(),r.cleanup()}})();if(t)return i;this.listAgentsInFlight.set(r,i);try{return await i}finally{this.listAgentsInFlight.delete(r)}}async readFile(e){try{let t=await this.client.file.read({path:e,...this.currentDirectory?{directory:this.currentDirectory}:{}});return String(E(t,`file.read`))}catch{return`// Content of ${e}\n// This would be loaded from the server`}}async listFiles(e){try{let t=e||this.currentDirectory||`/`,n=E(await this.client.file.list({path:t,...this.currentDirectory?{directory:this.currentDirectory}:{}}),`file.list`);return Array.isArray(n)?n:[]}catch{return[]}}async listCommands(){return(E(await this.client.command.list(this.currentDirectory?{directory:this.currentDirectory}:void 0),`command.list`)||[]).map(e=>({name:e.name,description:e.description,agent:e.agent,model:e.model,source:e.source}))}async listCommandsWithDetails(){return(E(await this.client.command.list(this.currentDirectory?{directory:this.currentDirectory}:void 0),`command.list`)||[]).map(e=>({name:e.name,description:e.description,agent:e.agent,model:e.model,source:e.source,template:e.template}))}async listSkillsWithDetails(){try{let e=(await this.client.app.skills(this.currentDirectory?{directory:this.currentDirectory}:void 0)).data;if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=typeof n.name==`string`?n.name.trim():``,r=typeof n.location==`string`?n.location:``;if(!e||!r)continue;let i={name:e,location:r};typeof n.description==`string`&&(i.description=n.description),typeof n.content==`string`&&(i.content=n.content),t.push(i)}return t}catch{return[]}}async getCommandDetails(e){try{let t=await this.client.command.list(this.currentDirectory?{directory:this.currentDirectory}:void 0);if(t.data){let n=t.data.find(t=>t.name===e);if(n)return{name:n.name,template:n.template,description:n.description,agent:n.agent,model:n.model}}return null}catch{return null}}async checkHealth(){let e=r(),t=this.healthCache.get(e);if(t&&t.expiresAt>Date.now())return t.healthy;let n=this.healthInFlight.get(e);if(n)return n;let i=this.healthCacheGeneration,a=(async()=>{let t=!1;try{let e=this.baseUrl.endsWith(`/`)?this.baseUrl.replace(/\/+$/,``):this.baseUrl,n=e===`/api`||e.endsWith(`/api`)?`/api/opencode/health`:`${e}/opencode/health`;C(`opencodeClient.checkHealth:url`,{baseUrl:this.baseUrl,healthUrl:n});let r=Ot(bt),i=await g(n,{signal:r.signal}).finally(r.cleanup);if(C(`opencodeClient.checkHealth:response`,{status:i.status}),i.ok){let e=await i.json();C(`opencodeClient.checkHealth:result`,{healthy:e?.healthy}),t=e?.healthy===!0}}catch{t=!1}return i!==this.healthCacheGeneration||e!==r()?!1:(this.healthCache.set(e,{healthy:t,expiresAt:Date.now()+(t?xt:St)}),t)})();this.healthInFlight.set(e,a);try{return await a}finally{this.healthInFlight.get(e)===a&&this.healthInFlight.delete(e)}}async createDirectory(e,t){let n=Pt();if(n?.createDirectory)try{return await n.createDirectory(e)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(t||`Failed to create directory`)}let r={path:e,...t?.allowOutsideWorkspace?{allowOutsideWorkspace:!0}:{}},i=await g(`${this.baseUrl}/fs/mkdir`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!i.ok){let e=await i.json().catch(()=>({error:`Failed to create directory`}));throw Error(e.error||`Failed to create directory`)}return await i.json()}async cloneRepository(e){let t=await g(`${this.baseUrl}/fs/clone`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)});if(!t.ok){let e=await t.json().catch(()=>({error:`Failed to clone repository`}));throw Error(e.error||`Failed to clone repository`)}return await t.json()}async listLocalDirectory(e,t){let n=`${typeof e==`string`?k(e.trim()):``}|${t?.respectGitignore?`1`:`0`}`,r=Date.now(),i=this.listDirectoryCache.get(n);if(i&&i.expiresAt>r)return i.entries;let a=this.listDirectoryInFlight.get(n);if(a)return a;let o=(async()=>{let r=Pt();if(r)try{let i=await r.listDirectory(e||``,t);if(!i||!Array.isArray(i.entries))return[];let a=i.entries.map(e=>({name:e.name,path:k(e.path),isDirectory:!!e.isDirectory,isFile:!e.isDirectory,isSymbolicLink:!1}));return this.listDirectoryCache.set(n,{entries:a,expiresAt:Date.now()+Nt}),a}catch(e){throw console.error(`Failed to list directory contents:`,e),e}try{let r=new URLSearchParams;e&&e.trim().length>0&&r.set(`path`,e),t?.respectGitignore&&r.set(`respectGitignore`,`true`);let i=r.toString(),a=await g(`${this.baseUrl}/fs/list${i?`?${i}`:``}`);if(!a.ok){let e=await a.json().catch(()=>({})),t=typeof e.error==`string`?e.error:`Failed to list directory`;throw Error(t)}let o=await a.json();if(!o||!Array.isArray(o.entries))return[];let s=o.entries;return this.listDirectoryCache.set(n,{entries:s,expiresAt:Date.now()+Nt}),s}catch(e){throw console.error(`Failed to list directory contents:`,e),e}})().finally(()=>{this.listDirectoryInFlight.get(n)===o&&this.listDirectoryInFlight.delete(n)});return this.listDirectoryInFlight.set(n,o),o}async searchFiles(e,t){let n=typeof t?.directory==`string`&&t.directory.trim().length>0?t.directory.trim():this.currentDirectory,r=n?k(n):null,i=n?this.getScopedApiClient(n):this.client;try{let n=await i.find.files({query:e,limit:typeof t?.limit==`number`&&Number.isFinite(t.limit)?t.limit:void 0,dirs:t?.dirs===!1||t?.type===`file`?`false`:`true`,type:t?.type});return(Array.isArray(n?.data)?n.data:[]).map(e=>{let t=k(e),n=t.split(`/`).filter(Boolean).pop()||t;return{name:n,path:k(r?`${r}/${t}`:t),relativePath:t,extension:n.includes(`.`)?n.split(`.`).pop()?.toLowerCase():void 0}})}catch(e){throw console.error(`Failed to search files:`,e),e}}async getFilesystemHome(){let e=r();if(!e||e===`local`){let e=await ie();if(e)return e}try{let e=await g(`${this.baseUrl}/fs/home`,{method:`GET`,headers:{Accept:`application/json`}});if(!e.ok){let t=await e.json().catch(()=>({})),n=typeof t.error==`string`&&t.error.length>0?t.error:`Failed to resolve home directory`;throw Error(n)}let t=await e.json();return t&&typeof t.home==`string`&&t.home.length>0?t.home:null}catch(e){return console.warn(`Failed to resolve filesystem home directory:`,e),null}}async setOpenCodeWorkingDirectory(e){if(!e||typeof e!=`string`||!e.trim())return console.warn(`[OpencodeClient] setOpenCodeWorkingDirectory: invalid path`,e),null;let t=`${this.baseUrl}/opencode/directory`;try{let n=await g(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e})}),r=await n.json().catch(()=>null);if(!n.ok){let e=r??{},t=typeof e.error==`string`&&e.error.length>0?e.error:`Failed to update OpenCode working directory`;throw Error(t)}return r&&typeof r==`object`?r:{success:!0,restarted:!1,path:e}}catch(e){throw console.warn(`Failed to update OpenCode working directory:`,e),e}}},Ft=3e4,It=40,Lt=60,Rt=(e,t,n,r,i,a)=>{let o=e.trim(),s=t.trim().toLowerCase();return JSON.stringify([o,s,n,r,i,a])},zt=(e,t)=>{try{let n=JSON.parse(e);return Array.isArray(n)&&n[0]===t}catch{return!1}},Bt=ae()(oe((e,t)=>({cache:{},cacheKeys:[],inFlight:{},async searchFiles(n,r,i=Lt,a){if(!n||n.trim().length===0)return[];let o=n.trim(),s=typeof r==`string`?r.trim():``,c=!!a?.includeHidden,l=a?.respectGitignore??!0,u=a?.type===`directory`?`directory`:`file`,d=Rt(o,s,i,c,l,u),f=Date.now(),p=t().cache[d];if(p&&f-p.timestamp<Ft)return p.files;let m=t().inFlight[d];if(m)return m;let h=A.searchFiles(s,{directory:o,limit:i,includeHidden:c,respectGitignore:l,dirs:u!==`file`,type:u}).then(t=>(e(e=>{if(e.inFlight[d]!==h)return e;let n={...e.cache,[d]:{files:t,timestamp:Date.now()}},r=e.cacheKeys.filter(e=>e!==d);for(r.push(d);r.length>It;){let e=r.shift();e&&delete n[e]}return{cache:n,cacheKeys:r}}),t)).finally(()=>{e(e=>{if(e.inFlight[d]!==h)return e;let t={...e.inFlight};return delete t[d],{inFlight:t}})});return e(e=>({inFlight:{...e.inFlight,[d]:h}})),h},invalidateDirectory(t){if(!t||t.trim().length===0){e({cache:{},cacheKeys:[],inFlight:{}});return}let n=t.trim();e(e=>{let t={...e.cache},r=e.cacheKeys.filter(e=>!zt(e,n)||(delete t[e],!1)),i=Object.entries(e.inFlight).filter(([e])=>!zt(e,n));return{cache:t,cacheKeys:r,inFlight:Object.fromEntries(i)}})}}),{name:`file-search-store`})),Vt=()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(`openchamber_stream_debug`)===`1`}catch{return!1}},Ht=`openchamber_stream_perf`,j=()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(Ht)===`1`}catch{return!1}},Ut=()=>typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now(),Wt=()=>{if(!j()||typeof window>`u`)return null;if(!window.__openchamberStreamPerfState){let e=Date.now();window.__openchamberStreamPerfState={counters:new Map,startedAt:e,lastUpdatedAt:e}}return window.__openchamberStreamPerfState},Gt=e=>Array.from(e.entries()).map(([e,t])=>({metric:e,count:t.count,avg:t.count>0?Number((t.total/t.count).toFixed(3)):0,max:Number(t.max.toFixed(3)),total:Number(t.total.toFixed(3)),last:Number(t.last.toFixed(3))})).sort((e,t)=>t.total-e.total||t.count-e.count),Kt=(e,t)=>{let n=Wt();if(!n)return;let r=n.counters.get(e)??{count:0,total:0,max:0,last:0};r.count+=1,r.total+=t,r.max=Math.max(r.max,t),r.last=t,n.counters.set(e,r),n.lastUpdatedAt=Date.now()},qt=e=>{if(!(typeof window>`u`))try{if(e){window.localStorage.setItem(Ht,`1`),window.__openchamberStreamPerfState={counters:new Map,startedAt:Date.now(),lastUpdatedAt:Date.now()};return}window.localStorage.removeItem(Ht),delete window.__openchamberStreamPerfState,delete window.__openchamberVsCodeStreamPerfState}catch{}},Jt=()=>{typeof window>`u`||(j()&&(window.__openchamberStreamPerfState={counters:new Map,startedAt:Date.now(),lastUpdatedAt:Date.now()}),window.__openchamberVsCodeStreamPerfState&&(window.__openchamberVsCodeStreamPerfState={...window.__openchamberVsCodeStreamPerfState,counters:new Map,startedAt:Date.now(),lastUpdatedAt:Date.now()}))},Yt=()=>{if(typeof window>`u`)return{enabled:!1,startedAt:null,lastUpdatedAt:null,durationMs:0,entries:[]};let e=window.__openchamberStreamPerfState;return!j()||!e?{enabled:!1,startedAt:null,lastUpdatedAt:null,durationMs:0,entries:[]}:{enabled:!0,startedAt:e.startedAt,lastUpdatedAt:e.lastUpdatedAt,durationMs:Math.max(0,Date.now()-e.startedAt),entries:Gt(e.counters)}},Xt=()=>{if(typeof window>`u`)return{enabled:!1,startedAt:null,lastUpdatedAt:null,durationMs:0,entries:[]};let e=window.__openchamberVsCodeStreamPerfState;if(!j()||!e)return{enabled:!1,startedAt:null,lastUpdatedAt:null,durationMs:0,entries:[]};let t=typeof e.startedAt==`number`?e.startedAt:null;return{enabled:!0,startedAt:t,lastUpdatedAt:typeof e.lastUpdatedAt==`number`?e.lastUpdatedAt:null,durationMs:t?Math.max(0,Date.now()-t):0,entries:Gt(e.counters)}},Zt=(e,t=1)=>{Kt(e,t)},Qt=(e,t)=>{Kt(e,t)},$t=(e,t)=>{if(!j())return t();let n=Ut();try{return t()}finally{Kt(e,Ut()-n)}},M=null,en=0,N=c(),tn=p(`lastDirectory`,{storage:N}),nn=typeof tn==`string`&&tn.length>0,P=e=>{try{Bt.getState().invalidateDirectory(e)}catch(e){console.warn(`Failed to invalidate file search cache:`,e)}},F=e=>{let t=e.trim();if(!t)return t;let n=t.replace(/\\/g,`/`).replace(/^([a-z]):/,(e,t)=>t.toUpperCase()+`:`);return n.length>1?n.replace(/\/+$/,``):n},rn=(e,t)=>{let n=e.trim();return n.startsWith(`~`)?n===`~`?t||n:(n.startsWith(`~/`)||n.startsWith(`~\\`))&&t?`${t}${n.slice(1)}`:n:n},I=(e,t)=>F(rn(e,t)),an=()=>{let e=p(`homeDirectory`,{storage:N});if(typeof e!=`string`||e.trim().length===0)return null;let t=F(e);return t.length>0?t:null},on=()=>{let e=p(`lastDirectory`,{storage:N});if(typeof e!=`string`||e.trim().length===0)return null;let t=F(e);return t.length>0?t:null},sn=()=>{if(typeof process>`u`)return null;let e={},t=e?.HOME||e?.USERPROFILE||(e?.HOMEDRIVE&&e?.HOMEPATH?`${e.HOMEDRIVE}${e.HOMEPATH}`:void 0);if(typeof t==`string`&&t.trim().length>0){let e=F(t);return e.length>0?e:null}let n=process?.cwd?.();if(typeof n==`string`&&n.trim().length>0){let e=F(n);return e.length>0?e:null}return null},L=()=>{if(typeof window<`u`){if(M)return M;let e=typeof window.__OPENCHAMBER_HOME__==`string`&&window.__OPENCHAMBER_HOME__.length>0?window.__OPENCHAMBER_HOME__:null;if(e&&e.length>0)return M=e,m(`homeDirectory`,e,{storage:N}),e;let t=an();if(t&&!f())return M=t,t}return sn()||`/`},cn=e=>{if(typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=t.replace(/\\/g,`/`);if(n.length>1){let e=n.replace(/\/+$/,``);if(e&&e.length>0)return e===`/`?null:e}return n===`/`||n.length===0?null:n},ln=e=>(M=e,typeof window<`u`&&m(`homeDirectory`,e,{storage:N}),_({homeDirectory:e}),e),un=async()=>{let e=e=>{let t=cn(e);return t?ln(t):null};try{let t=e(await A.getFilesystemHome());if(t)return t}catch(e){console.warn(`Failed to obtain filesystem home directory:`,e)}try{let t=e((await A.getSystemInfo())?.homeDirectory);if(t)return t}catch(e){console.warn(`Failed to get home directory from system info:`,e)}try{let t=e(await ie());if(t)return t}catch(e){console.warn(`Failed to obtain desktop-integrated home directory:`,e)}let t=L();return e(t)||t},R=(()=>{if(!f())return null;let e=window.__VSCODE_CONFIG__?.workspaceFolder;if(typeof e!=`string`||e.trim().length===0)return null;let t=F(e);return t.length>0?t:null})()||L(),z=(()=>{let e=on();return e&&!f()?I(e,R):R})();z&&A.setDirectory(z);var dn=!!(R&&R!==`/`),B=ae()(oe((e,t)=>({currentDirectory:z,directoryHistory:[z],historyIndex:0,homeDirectory:R,hasPersistedDirectory:nn,isHomeReady:dn,isSwitchingDirectory:!1,setDirectory:(n,r)=>{let i=I(n,M||t().homeDirectory||p(`homeDirectory`,{storage:N}));Vt(),ue(t().currentDirectory,i)&&(A.setDirectory(i),P(),e(e=>{let t=[...e.directoryHistory.slice(0,e.historyIndex+1),i];return m(`lastDirectory`,i,{storage:N}),_({lastDirectory:i}),{currentDirectory:i,directoryHistory:t,historyIndex:t.length-1,hasPersistedDirectory:!0,isHomeReady:!0,isSwitchingDirectory:!1}}))},goBack:()=>{let n=t();if(n.historyIndex>0){let t=n.historyIndex-1,r=n.directoryHistory[t];A.setDirectory(r),P(),m(`lastDirectory`,r,{storage:N}),_({lastDirectory:r}),e({currentDirectory:r,historyIndex:t,hasPersistedDirectory:!0,isHomeReady:!0,isSwitchingDirectory:!1})}},goForward:()=>{let n=t();if(n.historyIndex<n.directoryHistory.length-1){let t=n.historyIndex+1,r=n.directoryHistory[t];A.setDirectory(r),P(),m(`lastDirectory`,r,{storage:N}),_({lastDirectory:r}),e({currentDirectory:r,historyIndex:t,hasPersistedDirectory:!0,isHomeReady:!0,isSwitchingDirectory:!1})}},goToParent:()=>{let{currentDirectory:e,setDirectory:n}=t();if(e===(M||t().homeDirectory||L())||e===`/`)return;let r=e.endsWith(`/`)?e.slice(0,-1):e,i=r.lastIndexOf(`/`);n(i===-1?M||L():i===0?`/`:r.substring(0,i))},goHome:async()=>{let e=M||t().homeDirectory||await un();t().setDirectory(e)},synchronizeHomeDirectory:n=>{let r=t(),i=n;M=i;let a=r.homeDirectory!==i,o=p(`lastDirectory`,{storage:N}),s=typeof o==`string`&&o.length>0,c=!s&&(r.currentDirectory===`/`||r.currentDirectory===r.homeDirectory||!r.currentDirectory);if(!a&&!c){r.isHomeReady||e({isHomeReady:!0});return}let l=typeof i==`string`&&i!==``&&i!==`/`,u=r.currentDirectory?I(r.currentDirectory,i):r.currentDirectory,d=r.directoryHistory.map(e=>I(e,i)),f=d.some((e,t)=>e!==r.directoryHistory[t]),h=!!(u&&u!==r.currentDirectory),g={homeDirectory:i,hasPersistedDirectory:s,isHomeReady:l};if(c?(g.currentDirectory=i,g.directoryHistory=[i],g.historyIndex=0,g.isSwitchingDirectory=!1):(h||f)&&(g.currentDirectory=u,g.directoryHistory=d,g.historyIndex=Math.min(r.historyIndex,d.length-1),g.isSwitchingDirectory=!1),e(()=>g),(c||h)&&l){let e=c?i:u;A.setDirectory(e),P(),m(`lastDirectory`,e,{storage:N}),_({lastDirectory:e})}_({homeDirectory:i})}}),{name:`directory-store`}));typeof window<`u`&&(un().then(e=>{B.getState().synchronizeHomeDirectory(e)}),u(e=>{M=null;let n=++en;if(t(e)){let e=an(),t=on(),n=e||`/`,r=t||n;M=e,B.setState({currentDirectory:r,directoryHistory:[r],historyIndex:0,homeDirectory:n,hasPersistedDirectory:!!t,isHomeReady:!!(e&&e!==`/`),isSwitchingDirectory:!1}),r&&(A.setDirectory(r),P())}un().then(e=>{n===en&&B.getState().synchronizeHomeDirectory(e)})}));var fn=`x-openchamber-target-port`,pn=()=>{let e=a();for(let[t,n]of Object.entries(e)){if(t.trim().toLowerCase()!==fn)continue;let e=n.trim();return e?{[fn]:e}:void 0}},mn=(e,t)=>{let n=s();return n?n.openWebSocket(d(e),t,pn()):l(t?new WebSocket(e,t):new WebSocket(e))},V=`/api/git`,hn=1200,gn=5e3,_n=2,vn=5e3,yn=`${V}/worktrees/queue-activation`,bn=`message_queue_activation_pending`,xn=`worktree_lifecycle_busy`,Sn=`worktree_activation_stale`,Cn=5e3,wn=3e4,Tn=[0,500,1e3,2e3,4e3,8e3,14e3],H=new Map,U=new Map,En=new Map,W=new Map,G=new Map,K=new Map,q=new Map,Dn=new Map,J=new Map,On=new Map,kn=new Set,Y=0,An=[],jn=()=>Y<_n?(Y+=1,Promise.resolve()):new Promise(e=>{An.push(e)}),Mn=()=>{let e=An.shift();if(e){e();return}Y=Math.max(0,Y-1)},Nn=async e=>{await jn();try{return await e()}finally{Mn()}},Pn=Symbol.for(`openchamber.git.discoveryGated`),Fn=e=>(Object.defineProperty(e,Pn,{value:!0,configurable:!0}),e),In=e=>typeof e==`function`&&e[Pn]===!0,X=e=>e.trim(),Ln=(e,t)=>t===`light`?`${X(e)}::light`:X(e),Rn=e=>En.get(X(e))??0,Z=e=>{let t=X(e);En.set(t,Rn(e)+1);for(let e of Array.from(H.keys()))(e===t||e.startsWith(`${t}::`))&&H.delete(e);for(let e of Array.from(U.keys()))(e===t||e.startsWith(`${t}::`))&&U.delete(e)},zn=e=>On.get(X(e))??0,Q=e=>{let t=X(e);t&&(On.set(t,zn(e)+1),Dn.delete(t),J.delete(t))};function $(e,t,n){let r={...n};return t&&(r.directory=t),i().api(e,r)}var Bn=(e,t,n)=>{let r=X(e);if(!r)return;let i=Date.now()+vn;W.set(r,{value:t,expiresAt:i});let a=typeof n==`string`&&n?n:e;K.set(r,{value:{root:a},expiresAt:i})};async function Vn(e){let t=Array.from(new Set(e.map(e=>X(e)).filter(Boolean))),n=new Map;if(t.length===0)return n;let r=Date.now(),a=[];for(let e of t){let t=W.get(e),i=K.get(e);if(t&&t.expiresAt>r&&i&&i.expiresAt>r){n.set(e,{isGitRepository:t.value,primaryRoot:i.value.root});continue}a.push(e)}if(a.length===0)return n;let o=e=>{for(let t of e){let e=typeof t.directory==`string`?X(t.directory):``;if(!e)continue;let r=!!t.isGitRepository,i=typeof t.primaryRoot==`string`&&t.primaryRoot?t.primaryRoot:null;Bn(e,r,i),n.set(e,{isGitRepository:r,primaryRoot:i})}},s=async e=>{await Promise.all(e.map(async e=>{try{let[t,r]=await Promise.all([Hn(e),Wn(e).then(e=>e.root).catch(()=>e)]);Bn(e,t,t?r:null),n.set(e,{isGitRepository:t,primaryRoot:t?r:null})}catch{Bn(e,!1,null),n.set(e,{isGitRepository:!1,primaryRoot:null})}}))};try{await Nn(async()=>{let e=new URLSearchParams;for(let t of a)e.append(`directories`,t);let t=i().api(`${V}/discover`),n=e.toString(),r=n?t.includes(`?`)?`${t}&${n}`:`${t}?${n}`:t,s=await g(r);if(s.status===501||!s.ok)throw Error(`Batch git discover unavailable: ${s.status} ${s.statusText}`);let c=await s.json().catch(()=>null),l=Array.isArray(c)?c:[];if(l.length===0&&a.length>0)throw Error(`Batch git discover returned empty payload`);o(l)})}catch{}let c=a.filter(e=>!n.has(e));return c.length>0&&await s(c),n}async function Hn(e){let t=X(e),n=Date.now(),r=W.get(t);if(r&&r.expiresAt>n)return r.value;let i=G.get(t);if(i)return i;let a=(async()=>{let n=await g($(`${V}/check`,e));if(!n.ok)throw Error(`Failed to check git repository: ${n.statusText}`);let r=!!(await n.json()).isGitRepository;return W.set(t,{value:r,expiresAt:Date.now()+gn}),r})();G.set(t,a);try{return await a}finally{G.get(t)===a&&G.delete(t)}}async function Un(e,t){let n=t?.mode,r=Ln(e,n),i=Date.now(),a=H.get(r);if(a&&a.expiresAt>i)return a.value;let o=U.get(r);if(o)return o;let s=(async()=>{let t=Rn(e),i=await g($(`${V}/status`,e,n?{mode:n}:void 0));if(!i.ok)throw Error(`Failed to get git status: ${i.statusText}`);let a=await i.json();return Rn(e)===t&&H.set(r,{value:a,expiresAt:Date.now()+hn}),a})();U.set(r,s);try{return await s}finally{U.get(r)===s&&U.delete(r)}}async function Wn(e){let t=X(e),n=Date.now(),r=K.get(t);if(r&&r.expiresAt>n)return r.value;let i=q.get(t);if(i)return i;let a=Nn(async()=>{let n=await g($(`${V}/primary-root`,e));if(!n.ok)throw Error(`Failed to resolve git primary root: ${n.statusText}`);let r=await n.json().catch(()=>({})),i={root:typeof r.root==`string`&&r.root?r.root:e};return K.set(t,{value:i,expiresAt:Date.now()+vn}),i});q.set(t,a);try{return await a}finally{q.get(t)===a&&q.delete(t)}}async function Gn(e){let t=await g($(`${V}/toplevel`,e));if(!t.ok)throw Error(`Failed to resolve git toplevel: ${t.statusText}`);let n=await t.json().catch(()=>({}));return{root:typeof n.root==`string`&&n.root?n.root:e}}async function Kn(e,t){let{path:n,staged:r,contextLines:i}=t;if(!n)throw Error(`path is required to fetch git diff`);let a=await g($(`${V}/diff`,e,{path:n,staged:r?`true`:void 0,context:i}));if(!a.ok)throw Error(`Failed to get git diff: ${a.statusText}`);return a.json()}async function qn(e,t){let{path:n,staged:r}=t;if(!n)throw Error(`path is required to fetch git file diff`);let i=await g($(`${V}/file-diff`,e,{path:n,staged:r?`true`:void 0}));if(!i.ok)throw Error(`Failed to get git file diff: ${i.statusText}`);return i.json()}async function Jn(e,t,n){if(!t)throw Error(`path is required to revert git changes`);let r=await g($(`${V}/revert`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:t,scope:n?.scope})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to revert git changes`)}Z(e)}async function Yn(e,t){await Xn(e,[t])}async function Xn(e,t){let n=t.map(e=>e.trim()).filter(Boolean);if(n.length===0)throw Error(`path is required to stage git changes`);let r=await g($(`${V}/stage`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({paths:n})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to stage git changes`)}Z(e)}async function Zn(e,t){await Qn(e,[t])}async function Qn(e,t){let n=t.map(e=>e.trim()).filter(Boolean);if(n.length===0)throw Error(`path is required to unstage git changes`);let r=await g($(`${V}/unstage`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({paths:n})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to unstage git changes`)}Z(e)}async function $n(e,t,n){await nr(e,t,n,`stage`)}async function er(e,t,n){await nr(e,t,n,`unstage`)}async function tr(e,t,n){await nr(e,t,n,`discard`)}async function nr(e,t,n,r){if(!t)throw Error(`path is required to apply a git hunk`);if(typeof n!=`string`||!n.trim())throw Error(`patch is required to apply a git hunk`);let i=await g($(`${V}/apply-hunk`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:t,patch:n,action:r})});if(!i.ok){let e=await i.json().catch(()=>({error:i.statusText}));throw Error(e.error||`Failed to apply git hunk`)}Z(e)}async function rr(e){if(!e)return!1;let t=await g($(`${V}/worktree-type`,e));if(!t.ok)throw Error(`Failed to detect worktree type: ${t.statusText}`);return!!(await t.json()).linked}async function ir(e,t){let n=await g($(`${V}/branches`,e),{signal:t?.signal});if(!n.ok)throw Error(`Failed to get branches: ${n.statusText}`);return n.json()}async function ar(e,t){if(!t?.branch)throw Error(`branch is required to delete a branch`);let n=await g($(`${V}/branches`,e),{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to delete branch`)}return n.json()}async function or(e,t){if(!t?.branch)throw Error(`branch is required to delete remote branch`);let n=await g($(`${V}/remote-branches`,e),{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to delete remote branch`)}return n.json()}async function sr(e,t){let n=t?.remote?.trim();if(!n)throw Error(`remote is required to remove a remote`);let r=await g($(`${V}/remotes`,e),{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({remote:n})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to remove remote`)}return r.json()}async function cr(e,t,n){if(!Array.isArray(t)||t.length===0)throw Error(`No files provided to generate commit message`);let r={files:t};n?.zenModel&&(r.zenModel=n.zenModel),n?.providerId&&(r.providerId=n.providerId),n?.modelId&&(r.modelId=n.modelId);let i=await g($(`${V}/commit-message`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!i.ok){let e=await i.json().catch(()=>({error:i.statusText}));console.error(`[git-generation][browser] http error`,{status:i.status,statusText:i.statusText,error:e});let t=typeof e?.traceId==`string`&&e.traceId?` (traceId: ${e.traceId})`:``;throw Error(`${e.error||`Failed to generate commit message`}${t}`)}let a=await i.json();if(!a?.message||typeof a.message!=`object`)throw Error(`Malformed commit generation response`);return{message:{subject:typeof a.message.subject==`string`&&a.message.subject.trim().length>0?a.message.subject.trim():``,highlights:Array.isArray(a.message.highlights)?a.message.highlights.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()):[]}}}async function lr(e,t){let{base:n,head:r,context:i,zenModel:a,providerId:o,modelId:s}=t;if(!n||!r)throw Error(`base and head are required`);let c={base:n,head:r};i?.trim()&&(c.context=i.trim()),a&&(c.zenModel=a),o&&(c.providerId=o),s&&(c.modelId=s);let l=await g($(`${V}/pr-description`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(c)});if(!l.ok){let e=await l.json().catch(()=>({error:l.statusText}));throw Error(e.error||`Failed to generate PR description`)}let u=await l.json().catch(()=>null),d=typeof u?.title==`string`?u.title:``,f=typeof u?.body==`string`?u.body:``;if(!d&&!f)throw Error(`Malformed PR description response`);return{title:d,body:f}}async function ur(e){let t=X(e),n=Date.now(),r=Dn.get(t);if(r&&r.expiresAt>n)return r.value;let i=J.get(t);if(i)return i;let a=zn(e),o=Nn(async()=>{let n=await g($(`${V}/worktrees`,e));if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to list worktrees`)}let r=await n.json();return a===zn(e)&&Dn.set(t,{value:r,expiresAt:Date.now()+vn}),r});J.set(t,o);try{return await o}finally{J.get(t)===o&&J.delete(t)}}Fn(ur);async function dr(e,t){let n=await g($(`${V}/worktrees/validate`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t??{})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to validate worktree`)}return n.json()}async function fr(e){let t=await g($(`${V}/worktrees/bootstrap-status`,e));if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error||`Failed to get worktree bootstrap status`)}return t.json()}async function pr(e,t){let n=await g($(`${V}/worktrees/preview`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t??{})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to preview worktree`)}return n.json()}var mr=e=>typeof e==`string`&&e.length>0,hr=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(!mr(t.name)||!mr(t.path))return null;let n={head:typeof t.head==`string`?t.head:``,name:t.name,branch:typeof t.branch==`string`?t.branch:``,path:t.path};return t.directoryCreated===!0&&(n.directoryCreated=!0),t.bootstrapStatus&&typeof t.bootstrapStatus==`object`&&(n.bootstrapStatus=t.bootstrapStatus),n},gr=(e,t,n)=>{if(e!==503||!t||typeof t!=`object`)return null;let r=t;if(r.code!==bn)return null;let i=hr(r.worktree);if(!i)return null;let a=r.repair;if(!a||typeof a!=`object`)return null;let o=a;if(o.method!==`POST`||o.path!==yn)return null;let s=o.body;if(!s||typeof s!=`object`)return null;let c=s;return c.projectDirectory!==n||c.directory!==i.path?null:i},_r=(e,t,n,r)=>`${e}\u0000${t}\u0000${n}\u0000${r}`,vr=e=>new Promise(t=>{setTimeout(t,e)}),yr=async e=>{if(e.status===409){let t=await e.json().catch(()=>null);return t?.code===xn||t?.code===Sn}return e.status===503&&(await e.json().catch(()=>null))?.code===bn},br=e=>e===400||e===401||e===403||e===501,xr=(e,t)=>{let r=n(),i=o(),a=_r(r,i,e,t);if(kn.has(a))return;kn.add(a);let s=()=>n()===r&&o()===i;(async()=>{let n=Date.now(),r=0;for(;Date.now()-n<wn;){if(!s())return;let i=Tn[Math.min(r,Tn.length-1)]??0;if(i>0){let e=wn-(Date.now()-n);if(e<=0||(await vr(Math.min(i,e)),!s()))return}let a=new AbortController,o=setTimeout(()=>a.abort(),Cn);try{let n=await g($(yn,void 0),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectDirectory:e,directory:t}),signal:a.signal});if(n.ok||br(n.status))return;if(await yr(n)){r+=1;continue}return}catch{r+=1}finally{clearTimeout(o)}}})().catch(()=>{}).finally(()=>{kn.delete(a)})};async function Sr(e,t){let n=await g($(`${V}/worktrees`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t??{})}),r=await n.json().catch(()=>null);if(n.ok){let t=hr(r);if(t)return Q(e),t;if(r&&typeof r==`object`)return Q(e),r;throw Error(`Failed to create worktree`)}let i=gr(n.status,r,e);if(i)return Q(e),xr(e,i.path),i;let a=r&&typeof r==`object`?r:{error:n.statusText};throw Error(a.error||`Failed to create worktree`)}async function Cr(e,t){let n=await g($(`${V}/worktrees`,e),{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t??{})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to delete worktree`)}let r=await n.json();return Q(e),r}async function wr(e,t,n={}){let r=await g($(`${V}/commit`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({message:t,addAll:n.addAll??!1,files:n.files,stageFiles:n.stageFiles})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to create commit`)}let i=await r.json();return Z(e),i}async function Tr(e,t={}){let n=await g($(`${V}/push`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to push`)}let r=await n.json();return Z(e),r}async function Er(e,t={}){let n=await g($(`${V}/pull`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to pull`)}let r=await n.json();return Z(e),r}async function Dr(e,t={}){let n=await g($(`${V}/fetch`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to fetch`)}let r=await n.json();return Z(e),r}async function Or(e){let t=await g($(`${V}/stashes`,e));if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error||`Failed to list stashes`)}return t.json()}async function kr(e,t){let n=await g($(`${V}/stashes/file-counts`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({refs:t})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to count stash files`)}return n.json()}async function Ar(e,t={}){let n=await g($(`${V}/stash`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to stash changes`)}return n.json()}var jr=async(e,t,n)=>{let r=await g($(`${V}/${t}`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to ${t}`)}return r.json()},Mr=(e,t)=>jr(e,`stash/apply`,t),Nr=(e,t)=>jr(e,`stash/pop`,t),Pr=(e,t)=>jr(e,`stash/drop`,t);async function Fr(e,t){let n=await g($(`${V}/checkout`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({branch:t})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to checkout branch`)}return n.json()}async function Ir(e,t,n){let r=await g($(`${V}/branches`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t,startPoint:n})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to create branch`)}return r.json()}async function Lr(e,t,n){let r=await g($(`${V}/branches/rename`,e),{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({oldName:t,newName:n})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to rename branch`)}return r.json()}async function Rr(e,t={}){let n=await g($(`${V}/log`,e,{maxCount:t.maxCount,from:t.from,to:t.to,file:t.file,all:t.all?`true`:void 0}));if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(`Failed to get git log: ${e.error||n.statusText}`)}return n.json()}async function zr(e,t){let n=await g($(`${V}/commit-files`,e,{hash:t}));if(!n.ok)throw Error(`Failed to get commit files: ${n.statusText}`);return n.json()}async function Br(e,t,n,r){let i=await g($(`${V}/commit-file-diff`,e,{hash:t,path:n,binary:r?`true`:void 0}));if(!i.ok)throw Error(`Failed to get commit file diff: ${i.statusText}`);return i.json()}async function Vr(){let e=await g($(`${V}/identities`,void 0));if(!e.ok)throw Error(`Failed to get git identities: ${e.statusText}`);return e.json()}async function Hr(e){let t=await g($(`${V}/identities`,void 0),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error||`Failed to create git identity`)}return t.json()}async function Ur(e,t){let n=await g($(`${V}/identities/${e}`,void 0),{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to update git identity`)}return n.json()}async function Wr(e){let t=await g($(`${V}/identities/${e}`,void 0),{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error||`Failed to delete git identity`)}}async function Gr(e){if(!e)return null;let t=await g($(`${V}/current-identity`,e));if(!t.ok)throw Error(`Failed to get current git identity: ${t.statusText}`);let n=await t.json();return n?{userName:n.userName??null,userEmail:n.userEmail??null,sshCommand:n.sshCommand??null}:null}async function Kr(e){if(!e)return!1;let t=await g($(`${V}/has-local-identity`,e));if(!t.ok)throw Error(`Failed to check local identity: ${t.statusText}`);return(await t.json().catch(()=>null))?.hasLocalIdentity===!0}async function qr(){let e=await g($(`${V}/global-identity`,void 0));if(!e.ok)throw Error(`Failed to get global git identity: ${e.statusText}`);let t=await e.json();return!t||!t.userName&&!t.userEmail?null:{userName:t.userName??null,userEmail:t.userEmail??null,sshCommand:t.sshCommand??null}}async function Jr(e,t){let n=await g($(`${V}/set-identity`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({profileId:t})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to set git identity`)}return n.json()}async function Yr(){let e=await g($(`${V}/discover-credentials`,void 0));if(!e.ok)throw Error(`Failed to discover git credentials: ${e.statusText}`);return e.json()}async function Xr(e,t){let n=await g($(`${V}/remotes`,e),{signal:t?.signal});if(!n.ok)throw Error(`Failed to get remotes: ${n.statusText}`);return n.json()}async function Zr(e,t){let n=await g($(`${V}/rebase`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to rebase`)}return n.json()}async function Qr(e){let t=await g($(`${V}/rebase/abort`,e),{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error||`Failed to abort rebase`)}return t.json()}async function $r(e,t){let n=await g($(`${V}/merge`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to merge`)}return n.json()}async function ei(e,t){let n=await g($(`${V}/checkout-commit`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({hash:t})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to checkout commit`)}return n.json()}async function ti(e,t){let n=await g($(`${V}/cherry-pick`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({hash:t})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to cherry-pick`)}return n.json()}async function ni(e,t){let n=await g($(`${V}/revert-commit`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({hash:t})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to revert commit`)}return n.json()}async function ri(e,t,n,r){let i=await g($(`${V}/reset-to-commit`,e),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({hash:t,mode:n,force:r})});if(!i.ok){let e=await i.json().catch(()=>({error:i.statusText}));throw Error(e.error||`Failed to reset`)}return i.json()}async function ii(e){let t=await g($(`${V}/merge/abort`,e),{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error||`Failed to abort merge`)}return t.json()}async function ai(e){let t=await g($(`${V}/rebase/continue`,e),{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error||`Failed to continue rebase`)}return t.json()}async function oi(e){let t=await g($(`${V}/merge/continue`,e),{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error||`Failed to continue merge`)}return t.json()}async function si(e,t){return await Ar(e,{message:t?.message}),{success:!0}}async function ci(e){return await Nr(e,{ref:`stash@{0}`}),{success:!0}}async function li(e){let t=await g($(`${V}/conflict-details`,e));if(!t.ok)throw Error(`Failed to get conflict details: ${t.statusText}`);return t.json()}async function ui(e,t){let n=await g(`${V}/validate-directory`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({directory:e,worktreeRoot:t})});if(!n.ok)throw Error(`Failed to validate worktree directory: ${n.statusText}`);return n.json()}async function di(e){let t=await g(`${V}/canonicalize-worktree-state`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({directory:e})});if(!t.ok)throw Error(`Failed to canonicalize worktree state: ${t.statusText}`);return t.json()}var fi=()=>typeof window>`u`?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol===`capacitor:`,pi=()=>{if(typeof window>`u`||!fi()||mi()!==`ios`)return!1;let e=navigator.userAgent||``,t=navigator.maxTouchPoints??0;return/iPad/i.test(e)||/Macintosh|MacIntel/i.test(e)&&t>1},mi=()=>{if(typeof window<`u`){let e=window.Capacitor?.getPlatform?.();if(e===`ios`||e===`android`)return e}return f()?`vscode`:h()?`desktop`:`web`};export{Zr as $,li as A,$t as At,Xr as B,Pe as Bt,Yr as C,B as Ct,lr as D,qt as Dt,cr as E,Jt as Et,Vr as F,it as Ft,Q as G,Ge as Gt,Er as H,Be as Ht,Rr as I,rt as It,Or as J,ye as Jt,In as K,Fe as Kt,Un as L,Ve as Lt,ir as M,Bt as Mt,Kn as N,A as Nt,Br as O,Vt as Ot,qn as P,C as Pt,pr as Q,fr as R,Me as Rt,or as S,mn as St,Pr as T,Xt as Tt,Tr as U,He as Ut,Dr as V,ze as Vt,Kr as W,Ue as Wt,$r as X,ur as Y,Se as Yt,Nr as Z,Hr as _,er as _t,Qr as a,ni as at,Wr as b,ui as bt,Hn as c,Jr as ct,ti as d,$n as dt,sr as et,oi as f,si as ft,wr as g,Qn as gt,Ir as h,Zn as ht,ii as i,Gn as it,Gr as j,Qt as jt,zr as k,Zt as kt,Fr as l,Yn as lt,kr as m,ci as mt,fi as n,ri as nt,Mr as o,Jn as ot,ai as p,Ar as pt,rr as q,be as qt,pi as r,Wn as rt,di as s,tr as st,mi as t,Lr as tt,ei as u,Xn as ut,Sr as v,Ur as vt,Vn as w,Yt as wt,Cr as x,Nn as xt,ar as y,dr as yt,qr as z,Ne as zt};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,t as n}from"./useUIStore-BJpkPwky.js";import{Xt as r,d as i,kn as a,u as o,xn as s}from"./persistence-DwXJK4-j.js";import{A as c,D as l,E as u,F as d,I as f,M as p,N as m,P as h,j as g,k as _,nt as v,rt as y,tt as b}from"./vendor-base-ui-CnHfUmDN.js";import{n as x}from"./vendor-react-DLPElpoQ.js";import{s as S}from"./vendor-tanstack-react-query-D7pys_c9.js";import{P as C,V as w,a as T,f as E,l as D}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{c as O,o as k,r as A}from"./vendor-codemirror-lang-angular-DShkBD6m.js";import{n as j,r as M}from"./vendor-codemirror-lang-json-CYJRHck9.js";import{n as N}from"./vendor-codemirror-lang-markdown-WORgx6ZD.js";import{n as P}from"./vendor-codemirror-lang-python-Du6XQ8Zw.js";import{O as F}from"./vendor-codemirror-legacy-modes-DuRAjNvB.js";import{n as I}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ee,r as te}from"./clipboard-BvJ7NunE.js";import{Qa as ne,Xa as re,_o as ie,ia as L,ro as ae}from"./useMobileNavigationStore-Dw9Ibked.js";import{t as R}from"./AgentAvatar-BvhXxFvg.js";import{s as z,t as B}from"./utils-DfPDhqys.js";import{n as V}from"./Icon-BhSwbLaF.js";import{t as H}from"./button-BQY5ugjh.js";import{A as oe,C as U,E as W,O as G,T as K,k as se,w as q}from"./projectMeta-Bail3NaE.js";import{t as ce}from"./input-CgIoxUJc.js";import{t as le}from"./useThemeSystem-DMzWVJaW.js";import{i as ue}from"./OverlayScrollbar-CXFN6Cqq.js";import{t as de}from"./vendor-codemirror-language-data-BfYFhIH1.js";var J=e(y(),1),Y=v(),fe=[.2,.45,.15,.55,.35,.1,.5,.25,.4,.3,.45,.15,.55,.2,.35,.1],pe=[.3,.15,.45,.25,.5,.35,.1,.4,.2,.55,.3,.15,.45,.25,.4,.2],me=(e,t,n,r,i=4)=>{let a=[];for(let o=0;o<i;o++)for(let s=0;s<i;s++){let c=s/i,l=(s+1)/i,u=o/i,d=(o+1)/i,f=(e,t,n)=>e+(t-e)*n,p=(e,t,n,r,i,a)=>{let o=f(e,t,i),s=f(r,n,i);return f(o,s,a)},m={x:p(e.x,t.x,n.x,r.x,c,u),y:p(e.y,t.y,n.y,r.y,c,u)},h={x:p(e.x,t.x,n.x,r.x,l,u),y:p(e.y,t.y,n.y,r.y,l,u)},g={x:p(e.x,t.x,n.x,r.x,l,d),y:p(e.y,t.y,n.y,r.y,l,d)},_={x:p(e.x,t.x,n.x,r.x,c,d),y:p(e.y,t.y,n.y,r.y,c,d)};a.push({path:`M${m.x} ${m.y} L${h.x} ${h.y} L${g.x} ${g.y} L${_.x} ${_.y} Z`,row:o,col:s})}return a},he=({className:e=``,width:t=70,height:n=70,isAnimated:r=!1})=>{let{t:i}=ee(),a=le(),o=!0;a?o=a.currentTheme.metadata.variant!==`light`:typeof window<`u`&&(o=window.matchMedia(`(prefers-color-scheme: dark)`).matches);let s=(0,J.useMemo)(()=>{if(a)return a.currentTheme.colors.surface.foreground;if(typeof window<`u`){let e=getComputedStyle(document.documentElement).getPropertyValue(`--splash-stroke`).trim();if(e)return e}return o?`white`:`black`},[a,o]),c=(0,J.useMemo)(()=>typeof window>`u`||typeof CSS>`u`||typeof CSS.supports!=`function`?!1:CSS.supports(`color`,`color-mix(in srgb, white 50%, transparent)`),[]),l=(0,J.useMemo)(()=>{if(a)return c?`color-mix(in srgb, ${s} 15%, transparent)`:o?`rgba(255,255,255,0.15)`:`rgba(0,0,0,0.15)`;if(typeof window<`u`){let e=getComputedStyle(document.documentElement).getPropertyValue(`--splash-face-fill`).trim();if(e)return e}return o?`rgba(255,255,255,0.15)`:`rgba(0,0,0,0.15)`},[a,c,s,o]),u=(0,J.useMemo)(()=>{if(a)return c?`color-mix(in srgb, ${s} 35%, transparent)`:o?`rgba(255,255,255,0.35)`:`rgba(0,0,0,0.4)`;if(typeof window<`u`){let e=getComputedStyle(document.documentElement).getPropertyValue(`--splash-cell-fill`).trim();if(e)return e}return o?`rgba(255,255,255,0.35)`:`rgba(0,0,0,0.4)`},[a,c,s,o]),d=s,f=.866,p=.5,m={x:50,y:2},h={x:50-48*f,y:50-48*p},g={x:91.568,y:50-48*p},_={x:50,y:50},v={x:50-48*f,y:74},y={x:91.568,y:74},b={x:50,y:98},x=`matrix(0.866, 0.5, -0.866, 0.5, 50, ${(m.y+h.y+_.y+g.y)/4})`,S=me(h,_,b,v),C=me(_,g,y,b);return(0,Y.jsxs)(`svg`,{width:t,height:n,viewBox:`0 0 100 100`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,className:e,role:`img`,"aria-label":i(`openChamberLogo.aria.logo`),children:[r?(0,Y.jsx)(`style`,{children:`@keyframes oc-logo-glow{0%,100%{filter:drop-shadow(0 0 0 transparent)}50%{filter:drop-shadow(0 0 4px var(--oc-glow-color))}}.oc-logo-glow{animation:oc-logo-glow 1.8s ease-in-out infinite}@media (prefers-reduced-motion:reduce){.oc-logo-glow{animation:none}}`}):null,(0,Y.jsx)(`path`,{d:`M${_.x} ${_.y} L${h.x} ${h.y} L${v.x} ${v.y} L${b.x} ${b.y} Z`,fill:l,stroke:s,strokeWidth:`2`,strokeLinejoin:`round`}),S.map((e,t)=>(0,Y.jsx)(`path`,{d:e.path,fill:u,opacity:fe[e.row*4+(3-e.col)]??.35},`left-${t}`)),(0,Y.jsx)(`path`,{d:`M${_.x} ${_.y} L${g.x} ${g.y} L${y.x} ${y.y} L${b.x} ${b.y} Z`,fill:l,stroke:s,strokeWidth:`2`,strokeLinejoin:`round`}),C.map((e,t)=>(0,Y.jsx)(`path`,{d:e.path,fill:u,opacity:pe[e.row*4+e.col]??.35},`right-${t}`)),(0,Y.jsx)(`path`,{d:`M${m.x} ${m.y} L${h.x} ${h.y} L${_.x} ${_.y} L${g.x} ${g.y} Z`,fill:`none`,stroke:s,strokeWidth:`2`,strokeLinejoin:`round`}),(0,Y.jsx)(`g`,{opacity:1,className:r?`oc-logo-glow`:void 0,style:r?{"--oc-glow-color":s}:void 0,children:(0,Y.jsxs)(`g`,{transform:`${x} scale(0.75)`,children:[(0,Y.jsx)(`path`,{fillRule:`evenodd`,clipRule:`evenodd`,d:`M-16 -20 L16 -20 L16 20 L-16 20 Z M-8 -12 L-8 12 L8 12 L8 -12 Z`,fill:d}),(0,Y.jsx)(`path`,{d:`M-8 -4 L8 -4 L8 12 L-8 12 Z`,fill:d,fillOpacity:`0.4`})]})})]})},X=x(),ge=e(b(),1),Z=0,_e=()=>{Z=Date.now()+800},Q=()=>Date.now()<Z,ve=`__unassigned__`,ye={mod:`mod`,shift:`shift`,alt:`alt`,option:`alt`,ctrl:`ctrl`,meta:`mod`,cmd:`mod`,command:`mod`},be={mod:z()&&r()?`⌘`:`Ctrl`,shift:`⇧`,alt:`⌥`,option:`⌥`,ctrl:`⌃`},xe={comma:`,`,period:`.`,enter:`Enter`,escape:`Esc`,tab:`Tab`,space:`Space`,backspace:`⌫`,delete:`⌦`,arrowup:`↑`,arrowdown:`↓`,arrowleft:`←`,arrowright:`→`,home:`Home`,end:`End`,pageup:`Page Up`,pagedown:`Page Down`,backtick:"`",grave:"`","=":`=`,equal:`=`,plus:`+`,minus:`-`,"-":`-`},Se=[`mod`,`ctrl`,`shift`,`alt`],Ce={"{":`[`,"}":`]`,":":`;`,'"':`'`,"<":`,`,">":`.`,"?":`/`,"|":`\\`,"~":"`","!":`1`,"@":`2`,"#":`3`,$:`4`,"%":`5`,"^":`6`,"&":`7`,"*":`8`,"(":`9`,")":`0`};function $(e){return e.trim().toLowerCase()===ve}function we(e){let t=e.toLowerCase();return t===`,`?`comma`:t===`.`?`period`:t===` `?`space`:t===`esc`?`escape`:t===`+`?`plus`:t===`-`||t===`_`?`minus`:t===`arrowup`?`arrowup`:t===`arrowdown`?`arrowdown`:t===`arrowleft`?`arrowleft`:t===`arrowright`?`arrowright`:t==="`"?`backtick`:Ce[t]??t}var Te=[{id:`open_go_to_line`,defaultCombo:`alt+g`,label:`Go to line (files editor)`,description:`Open go to line in the files editor`,customizable:!0},{id:`open_command_palette`,defaultCombo:`mod+p`,label:`Open command palette`,description:`Open the command palette`,customizable:!0},{id:`focus_input`,defaultCombo:`mod+i`,label:`Focus input`,description:`Focus the chat input field`,customizable:!0},{id:`open_status`,defaultCombo:`mod+shift+o`,label:`Open OpenCode status`,description:`Open the OpenCode status dialog`},{id:`open_settings`,defaultCombo:`mod+comma`,label:`Open settings`,description:`Open the settings panel`,customizable:!0},{id:`toggle_terminal`,defaultCombo:`ctrl+backtick`,label:`Toggle terminal`,description:`Toggle the integrated terminal`,customizable:!0},{id:`toggle_bottom_panel`,defaultCombo:`mod+j`,label:`Toggle bottom panel`,description:`Toggle the bottom panel dock`,customizable:!0},{id:`toggle_terminal_expanded`,defaultCombo:`mod+shift+j`,label:`Toggle terminal expanded`,description:`Toggle terminal expanded or collapsed`,customizable:!0},{id:`new_terminal_tab`,defaultCombo:`mod+t`,label:`New terminal tab`,description:`Create a new terminal tab when the terminal is focused`,customizable:!0},{id:`open_new_terminal`,defaultCombo:`mod+shift+backtick`,label:`Open new terminal`,description:`Open the terminal panel and create a new terminal tab`,customizable:!0},{id:`previous_terminal_tab`,defaultCombo:`mod+shift+[`,label:`Previous terminal tab`,description:`Switch to the previous terminal tab when the terminal is focused`,customizable:!0},{id:`next_terminal_tab`,defaultCombo:`mod+shift+]`,label:`Next terminal tab`,description:`Switch to the next terminal tab when the terminal is focused`,customizable:!0},{id:`toggle_files`,defaultCombo:`mod+shift+f`,label:`Toggle files`,description:`Toggle the files panel`},{id:`toggle_sidebar`,defaultCombo:`mod+b`,label:`Toggle sidebar`,description:`Toggle the session sidebar`,customizable:!0},{id:`open_timeline_dialog`,defaultCombo:`mod+t`,label:`Open conversation timeline`,description:`Search and navigate within current conversation`,customizable:!0},{id:`toggle_prompt_navigator`,defaultCombo:`mod+alt+p`,label:`Toggle prompt navigator`,description:`Show or hide the prompt navigator panel in chat`,customizable:!0},{id:`toggle_right_sidebar`,defaultCombo:`mod+alt+b`,defaultAliases:[`mod+\\`],label:`Toggle review panel`,description:`Toggle the review panel (right sidebar)`,customizable:!0},{id:`open_right_sidebar_git`,defaultCombo:`mod+shift+g`,label:`Open right sidebar Git tab`,description:`Open right sidebar and select Git`,customizable:!0},{id:`open_right_sidebar_files`,defaultCombo:`mod+shift+f`,label:`Open right sidebar Files tab`,description:`Open right sidebar and select Files`,customizable:!0},{id:`cycle_right_sidebar_tab`,defaultCombo:`mod+alt+shift+r`,label:`Cycle right sidebar tab`,description:`Cycle through right sidebar tabs`,customizable:!0},{id:`close_context_panel_tab`,defaultCombo:`mod+w`,label:`Close context panel tab`,description:`Close the active context panel tab (closes the panel when empty)`,customizable:!0},{id:`previous_session`,defaultCombo:`mod+shift+[`,defaultAliases:[`mod+arrowup`],label:`Previous session`,description:`Switch to the previous session`,customizable:!0},{id:`next_session`,defaultCombo:`mod+shift+]`,defaultAliases:[`mod+arrowdown`],label:`Next session`,description:`Switch to the next session`,customizable:!0},{id:`new_chat`,defaultCombo:`mod+n`,label:`New session`,description:`Start a new session`,customizable:!0},{id:`new_chat_worktree`,defaultCombo:`mod+shift+alt+n`,label:`New worktree draft`,description:`Create a new worktree and open a draft in it`,customizable:!0},{id:`new_mini_chat`,defaultCombo:`mod+alt+n`,label:`New Mini Chat window`,description:`Open a new Mini Chat draft window`,customizable:!0},{id:`submit_message`,defaultCombo:`mod+enter`,label:`Submit message`,description:`Submit the current message`},{id:`clear_input`,defaultCombo:`escape`,label:`Clear input`,description:`Clear the input field`},{id:`clear_all_messages`,defaultCombo:`ctrl+c`,label:`Clear all messages`,description:`Clear the composer input and queued messages`,customizable:!0},{id:`open_diff_panel`,defaultCombo:`mod+2`,label:`Open diff panel`,description:`Switch to the diff panel`},{id:`open_terminal_panel`,defaultCombo:`mod+3`,label:`Open terminal panel`,description:`Switch to the terminal panel`},{id:`open_git_panel`,defaultCombo:`mod+4`,label:`Open git panel`,description:`Switch to the git panel`},{id:`open_help`,defaultCombo:`mod+.`,label:`Open keyboard shortcuts`,description:`Show the keyboard shortcuts help`,customizable:!0},{id:`toggle_context_plan`,defaultCombo:`mod+shift+p`,label:`Toggle plan context panel`,description:`Open or close plan in the context panel`,customizable:!0},{id:`toggle_services_menu`,defaultCombo:`mod+shift+s`,label:`Toggle services menu`,description:`Open or close the services menu`,customizable:!0},{id:`open_usage`,defaultCombo:`mod+shift+c`,label:`Open usage`,description:`Open the usage panel`,customizable:!0},{id:`cycle_services_tab`,defaultCombo:`mod+alt+shift+s`,label:`Cycle services tab`,description:`Cycle through tabs in the services menu`,customizable:!0},{id:`cycle_theme`,defaultCombo:`mod+/`,label:`Cycle theme`,description:`Cycle between light, dark, and system theme`,customizable:!0},{id:`zoom_in`,defaultCombo:`mod+=`,label:`Zoom in`,description:`Increase the webview zoom level`,customizable:!0},{id:`zoom_out`,defaultCombo:`mod+-`,label:`Zoom out`,description:`Decrease the webview zoom level`,customizable:!0},{id:`zoom_reset`,defaultCombo:`mod+0`,label:`Reset zoom`,description:`Reset the webview zoom level to 100%`,customizable:!0},{id:`leader_key`,defaultCombo:`ctrl+x`,label:`Leader key`,description:`Start an OpenCode-style chord, then press M / A / N / C`,customizable:!0},{id:`open_model_selector`,defaultCombo:`mod+shift+m`,label:`Open model selector`,description:`Open model selector while in chat`,customizable:!0},{id:`cycle_thinking_variant`,defaultCombo:`mod+shift+t`,label:`Cycle thinking variant`,description:`Cycle thinking variant while in chat`},{id:`cycle_agent`,defaultCombo:`tab`,label:`Cycle agent`,description:`Cycle agent while the model selector is open`,customizable:!0},{id:`cycle_favorite_model_forward`,defaultCombo:`ctrl+]`,label:`Cycle favorite model forward`,description:`Cycle forward through starred models without opening the picker`,customizable:!0},{id:`cycle_favorite_model_backward`,defaultCombo:`ctrl+[`,label:`Cycle favorite model backward`,description:`Cycle backward through starred models without opening the picker`,customizable:!0},{id:`expand_input`,defaultCombo:`mod+shift+e`,label:`Expand input`,description:`Toggle focus mode for the chat input`,customizable:!0},{id:`toggle_dictation`,defaultCombo:`mod+alt+v`,label:`Voice input`,description:`Start dictation; press again to confirm and insert the transcript`,customizable:!0},{id:`abort_run`,defaultCombo:`escape`,label:`Abort active run`,description:`Abort the currently running task (double press)`},{id:`switch_tab_1`,defaultCombo:`mod+1`,label:`Switch to visible session 1`,description:`Switch to the first visible sidebar session`},{id:`switch_tab_2`,defaultCombo:`mod+2`,label:`Switch to visible session 2`,description:`Switch to the second visible sidebar session`},{id:`switch_tab_3`,defaultCombo:`mod+3`,label:`Switch to visible session 3`,description:`Switch to the third visible sidebar session`},{id:`switch_tab_4`,defaultCombo:`mod+4`,label:`Switch to visible session 4`,description:`Switch to the fourth visible sidebar session`},{id:`switch_tab_5`,defaultCombo:`mod+5`,label:`Switch to visible session 5`,description:`Switch to the fifth visible sidebar session`},{id:`switch_tab_6`,defaultCombo:`mod+6`,label:`Switch to visible session 6`,description:`Switch to the sixth visible sidebar session`},{id:`switch_tab_7`,defaultCombo:`mod+7`,label:`Switch to visible session 7`,description:`Switch to the seventh visible sidebar session`},{id:`switch_tab_8`,defaultCombo:`mod+8`,label:`Switch to visible session 8`,description:`Switch to the eighth visible sidebar session`},{id:`switch_tab_9`,defaultCombo:`mod+9`,label:`Switch to visible session 9`,description:`Switch to the ninth visible sidebar session`}];function Ee(e){if($(e))return ve;let t=e.toLowerCase().trim().split(`+`).map(e=>e.trim()).filter(Boolean),n=new Set,r=``;for(let e of t){let t=e===`,`?`comma`:e===`.`?`period`:e,i=ye[t];if(i){n.add(i);continue}r=t}return[...Se.filter(e=>n.has(e)),r].filter(Boolean).join(`+`)}function De(e){return $(e)?!0:Oe(e).key.trim().length>0}function Oe(e){if($(e))return{modifiers:new Set,key:ve};let t=Ee(e).split(`+`),n=new Set,r=``;for(let e of t){let t=ye[e];t?n.add(t):r=e}return{modifiers:n,key:r}}function ke(e){if($(e))return`Unassigned`;let t=Oe(e);if(!t.key&&t.modifiers.size===0)return`Unassigned`;let n=[];for(let e of Se)t.modifiers.has(e)&&n.push(be[e]);if(t.key){let e=xe[t.key.toLowerCase()]||t.key.toUpperCase();n.push(e)}return n.join(` + `)}function Ae(e){return Te.find(t=>t.id===e)}function je(){return Te.filter(e=>e.customizable===!0)}function Me(e,t){let n=Ae(e);if(!n)return``;let r=t?.[e];if(typeof r==`string`){if(r.trim().toLowerCase()===`__unassigned__`)return``;let e=Ee(r);if(e===`__unassigned__`)return ve;if(De(e))return e}return n.defaultCombo}function Ne(e,t){let n=Ae(e);if(!n)return[];let r=Me(e,t);return r===n.defaultCombo?[n.defaultCombo,...n.defaultAliases??[]]:r?[r]:[]}function Pe(e){if($(e))return!1;let t=Oe(e);if(!t.modifiers.has(`mod`))return!1;let n=t.key.toLowerCase();return new Set([`w`,`t`,`r`,`p`,`s`,`f`,`l`,`n`]).has(n)&&!t.modifiers.has(`shift`)&&!t.modifiers.has(`alt`)}function Fe(e,t){let n=typeof t==`string`?t:t.defaultCombo;if($(n))return!1;let i=Oe(n),a=i.modifiers.has(`mod`),o=i.modifiers.has(`shift`),s=i.modifiers.has(`alt`),c=i.modifiers.has(`ctrl`),l=z()&&r(),u=z(),d=l?e.metaKey:u&&e.metaKey||e.ctrlKey;if(a&&!d||!a&&e.metaKey||o!==e.shiftKey||s!==e.altKey)return!1;if(c){if(!e.ctrlKey)return!1}else{let t=a&&!l&&e.ctrlKey;if(e.ctrlKey&&!t)return!1}let f=e.key;return(!f||f===`Dead`)&&e.code===`Backquote`&&(f="`"),e.altKey&&(e.code.startsWith(`Key`)&&e.code.length===4?f=e.code.slice(3).toLowerCase():e.code.startsWith(`Digit`)&&e.code.length===6&&(f=e.code.slice(5))),we(f)===we(i.key)}function Ie(){return z()&&r()?`⌘`:`Ctrl`}function Le(e,t,n){if(Fe(e,n))return!0;let i=Ee(n),a=z()&&r(),o=z();return!(a?e.metaKey:o&&e.metaKey||e.ctrlKey)||e.altKey||a&&e.ctrlKey&&!e.metaKey?!1:t===`in`&&i===`mod+=`?e.key===`+`||e.code===`NumpadAdd`:t===`out`&&(i===`mod+-`||i===`mod+minus`)?e.key===`_`||e.code===`NumpadSubtract`:!1}var Re=`app-region-no-drag transition-all duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 z-50 max-h-[var(--available-height)] min-w-[8rem] origin-[var(--transform-origin)] overflow-visible rounded-xl p-1 shadow-[inset_0_1px_0_0_rgba(255,255,255,0.8),inset_0_0_0_1px_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.10),0_1px_2px_-0.5px_rgba(0,0,0,0.08),0_4px_8px_-2px_rgba(0,0,0,0.08),0_12px_20px_-4px_rgba(0,0,0,0.08)] dark:shadow-[inset_0_1px_0_0_rgba(255,255,255,0.12),inset_0_0_0_1px_rgba(255,255,255,0.08),0_0_0_1px_rgba(0,0,0,0.36),0_1px_1px_-0.5px_rgba(0,0,0,0.22),0_3px_3px_-1.5px_rgba(0,0,0,0.20),0_6px_6px_-3px_rgba(0,0,0,0.16)]`,ze=`data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover data-[variant=destructive]:text-destructive data-[variant=destructive]:hover:bg-destructive/10 dark:data-[variant=destructive]:hover:bg-destructive/20 data-[variant=destructive]:hover:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5`,Be=`data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5`,Ve=`bg-border -mx-1 my-0.5 h-px`,He=J.createContext(null),Ue=e=>e?e.closest(`[data-slot="dialog-content"], [role="dialog"]`):null;function We(e,t){return e&&J.isValidElement(t)?{render:t}:{children:t}}function Ge(e){let t=(0,X.c)(9),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let[r,i]=J.useState(null),a;t[2]===r?a=t[3]:(a={portalContainer:r,setPortalContainer:i},t[2]=r,t[3]=a);let o=a,s;t[4]===n?s=t[5]:(s=(0,Y.jsx)(_,{...n}),t[4]=n,t[5]=s);let c;return t[6]!==o||t[7]!==s?(c=(0,Y.jsx)(He.Provider,{value:o,children:s}),t[6]=o,t[7]=s,t[8]=c):c=t[8],c}function Ke(e){let t=(0,X.c)(22),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({asChild:n,children:r,onPointerDownCapture:a,onFocusCapture:i,...o}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s=J.useContext(He),c;t[6]===s?c=t[7]:(c=e=>{if(!s)return;let t=e instanceof HTMLElement?e:null;s.setPortalContainer(Ue(t))},t[6]=s,t[7]=c);let u=c,d;t[8]!==n||t[9]!==r?(d=We(n,r),t[8]=n,t[9]=r,t[10]=d):d=t[10];let f=d,p;t[11]!==a||t[12]!==u?(p=e=>{u(e.currentTarget),a?.(e)},t[11]=a,t[12]=u,t[13]=p):p=t[13];let m;t[14]!==i||t[15]!==u?(m=e=>{u(e.currentTarget),i?.(e)},t[14]=i,t[15]=u,t[16]=m):m=t[16];let h;return t[17]!==o||t[18]!==f||t[19]!==p||t[20]!==m?(h=(0,Y.jsx)(l,{"data-slot":`dropdown-menu-trigger`,onPointerDownCapture:p,onFocusCapture:m,...o,...f}),t[17]=o,t[18]=f,t[19]=p,t[20]=m,t[21]=h):h=t[21],h}function qe(e){let t=(0,X.c)(40),n,r,i,a,o,s,c,l,u,f,p,g,_;if(t[0]!==e){let{className:d,sideOffset:m,align:h,side:v,alignOffset:y,anchor:b,portalToBody:x,positionerClassName:S,style:C,children:w,onCloseAutoFocus:T,collisionPadding:E,collisionAvoidance:D,...O}=e;o=d,f=m,n=h,l=v,r=y,i=b,p=x,s=S,u=C,a=w,g=E,_=D,c=O,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u,t[10]=f,t[11]=p,t[12]=g,t[13]=_}else n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9],f=t[10],p=t[11],g=t[12],_=t[13];let v=f===void 0?4:f,y=p!==void 0&&p,b=g===void 0?8:g,x;t[14]===_?x=t[15]:(x=_===void 0?{side:`shift`,align:`shift`}:_,t[14]=_,t[15]=x);let S=x,C=J.useContext(He),w=y?void 0:C?.portalContainer||void 0,T;t[16]===s?T=t[17]:(T=B(`app-region-no-drag z-50`,s),t[16]=s,t[17]=T);let E;t[18]===u?E=t[19]:(E={backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`,...u},t[18]=u,t[19]=E);let D;t[20]===o?D=t[21]:(D=B(Re,o),t[20]=o,t[21]=D);let O;t[22]!==a||t[23]!==c||t[24]!==E||t[25]!==D?(O=(0,Y.jsx)(d,{"data-slot":`dropdown-menu-content`,style:E,className:D,...c,children:a}),t[22]=a,t[23]=c,t[24]=E,t[25]=D,t[26]=O):O=t[26];let k;t[27]!==n||t[28]!==r||t[29]!==i||t[30]!==S||t[31]!==b||t[32]!==l||t[33]!==v||t[34]!==O||t[35]!==T?(k=(0,Y.jsx)(m,{anchor:i,sideOffset:v,align:n,side:l,alignOffset:r,collisionPadding:b,collisionAvoidance:S,className:T,children:O}),t[27]=n,t[28]=r,t[29]=i,t[30]=S,t[31]=b,t[32]=l,t[33]=v,t[34]=O,t[35]=T,t[36]=k):k=t[36];let A;return t[37]!==k||t[38]!==w?(A=(0,Y.jsx)(h,{container:w,children:k}),t[37]=k,t[38]=w,t[39]=A):A=t[39],A}function Je(e){let t=(0,X.c)(24),n,r,i,a,o,s,c,l;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8]):({className:i,inset:a,variant:l,asChild:n,children:r,onSelect:s,onClick:o,...c}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l);let u=l===void 0?`default`:l,d;t[9]!==n||t[10]!==r?(d=We(n,r),t[9]=n,t[10]=r,t[11]=d):d=t[11];let p=d,m;t[12]!==o||t[13]!==s?(m=e=>{o?.(e),e.defaultPrevented||s?.(e)},t[12]=o,t[13]=s,t[14]=m):m=t[14];let h=m,g;t[15]===i?g=t[16]:(g=B(ze,i),t[15]=i,t[16]=g);let _;return t[17]!==h||t[18]!==a||t[19]!==c||t[20]!==p||t[21]!==g||t[22]!==u?(_=(0,Y.jsx)(f,{"data-slot":`dropdown-menu-item`,"data-inset":a,"data-variant":u,className:g,...c,onClick:h,...p}),t[17]=h,t[18]=a,t[19]=c,t[20]=p,t[21]=g,t[22]=u,t[23]=_):_=t[23],_}function Ye(e){let t=(0,X.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,Y.jsx)(p,{"data-slot":`dropdown-menu-radio-group`,...n}),t[2]=n,t[3]=r),r}function Xe(e){let t=(0,X.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===r?a=t[5]:(a=B(`data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover data-[checked]:bg-interactive-selection data-[checked]:text-interactive-selection-foreground relative flex cursor-pointer items-start gap-2 rounded-lg py-1 pl-2 pr-8 typography-ui-label outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5`,r),t[4]=r,t[5]=a);let o;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Y.jsx)(`span`,{className:`pointer-events-none absolute right-2 flex size-3.5 items-center justify-center text-primary`,children:(0,Y.jsx)(c,{children:(0,Y.jsx)(V,{name:`check`,className:`size-3`})})}),t[6]=o):o=t[6];let s;return t[7]!==n||t[8]!==i||t[9]!==a?(s=(0,Y.jsxs)(g,{"data-slot":`dropdown-menu-radio-item`,className:a,...i,children:[o,n]}),t[7]=n,t[8]=i,t[9]=a,t[10]=s):s=t[10],s}function Ze(e){let t=(0,X.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,inset:r,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=B(`px-2 py-1 typography-ui-label font-medium data-[inset]:pl-8`,n),t[4]=n,t[5]=a);let o;return t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,Y.jsx)(`div`,{"data-slot":`dropdown-menu-label`,"data-inset":r,className:a,...i}),t[6]=r,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function Qe(e){let t=(0,X.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=B(Ve,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,Y.jsx)(u,{"data-slot":`dropdown-menu-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var $e=(e,t)=>{let n=`flex min-h-0 flex-col bg-background shadow-none`;if(e===`page`)return`${n} h-full w-full`;let r=`${n} pwa-overlay-panel`;return t===`top`?`${r} mx-auto mb-auto max-h-[calc(100dvh-0.75rem)] w-full max-w-lg rounded-b-xl border-x border-b border-border/50`:t===`left`?`${r} h-full w-[min(86vw,24rem)] rounded-r-xl border-r border-y border-border/50`:t===`right`?`${r} ml-auto h-full w-[min(86vw,24rem)] rounded-l-xl border-l border-y border-border/50`:`${r} mx-auto mt-auto max-h-[calc(100dvh-0.75rem)] w-full max-w-lg rounded-t-2xl border-x border-t border-border/50 pb-[max(0.5rem,var(--oc-app-bottom-safe,0px),var(--oc-safe-area-bottom,env(safe-area-inset-bottom,0px)))]`},et=e=>Math.min(1,Math.max(0,Number.isFinite(e)?e:0)),tt=(e,t,n)=>{let r=Number.isFinite(t)&&t>0?t:1,i=Math.max(0,Number.isFinite(e)?e:0)/r,a=et(n[0]??1),o=Math.abs(i-a);for(let e=1;e<n.length;e+=1){let t=et(n[e]??a),r=Math.abs(i-t);r<o&&(a=t,o=r)}return a},nt=(e,t)=>{let n=et(t),r=`${(1-n)*100}%`;return{progress:n,scrimOpacity:n,surfaceOpacity:n,surfaceTransform:e===`left`?`translate3d(-${r}, 0, 0)`:e===`right`?`translate3d(${r}, 0, 0)`:e===`top`?`translate3d(0, -${r}, 0)`:`translate3d(0, ${r}, 0)`}},rt=(e,t)=>{let n=et(t);return e===`present`?n:1-n},it=(e,t)=>e===`present`?+(t===`commit`):t===`commit`?0:1,at=e=>+!!e,ot=.72,st=.98,ct=[ot,st],lt=180,ut=`cubic-bezier(0.32, 0.72, 0, 1)`,dt=64,ft=()=>Math.max(1,window.innerHeight),pt=(e,t,n=dt,r)=>e<=ht(t,r)-n,mt=(e,t,n)=>Math.min(t*st,Math.max(n?0:t*ot,e)),ht=(e,t)=>{let n=Math.max(1,e)*ot;return t==null||!Number.isFinite(t)?n:Math.min(n,Math.max(0,t))},gt=(e,t,n)=>{let r=ht(t,n),i=Math.max(1,t)*st;return Math.abs(e-r)<=Math.abs(e-i)?ot:st},_t=({initialSnapPoint:e=ot,fitContent:t=!1,onDismiss:n,dismissThresholdPx:r=dt}={})=>{let i=J.useRef(null),a=J.useRef(null),o=J.useRef(null),s=J.useRef(null),c=J.useRef(null),l=J.useRef(null),u=J.useRef(!1),[d,f]=J.useState(e),p=J.useRef(e),m=J.useRef(n);m.current=n;let h=J.useCallback(()=>{o.current!==null&&window.cancelAnimationFrame(o.current),o.current=null},[]),g=J.useCallback((e,n)=>{let r=i.current,a=p.current;if(p.current=e,f(e),h(),s.current=null,c.current?.cancel(),c.current=null,!r)return;let o=n??r.getBoundingClientRect().height;t&&a===.72&&l.current===null&&(l.current=ht(ft(),o));let u=e===.72?ht(ft(),t?l.current:void 0):ft()*st;if(r.style.height=``,r.style.willChange=``,Math.abs(o-u)<1||typeof r.animate!=`function`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let d=r.animate([{height:`${o}px`},{height:`${u}px`}],{duration:lt,easing:ut,fill:`both`});c.current=d,d.finished.catch(()=>void 0).then(()=>{c.current===d&&(c.current=null,d.cancel())})},[h,t]),_=J.useCallback(e=>{if(!e.isPrimary||e.pointerType===`mouse`&&e.button!==0)return;let n=i.current;if(!n)return;let r=n.getBoundingClientRect().height;t&&p.current===.72&&(l.current=ht(ft(),r)),c.current?.cancel(),c.current=null,n.style.height=`${r}px`,n.style.willChange=`height`,a.current={pointerId:e.pointerId,startY:e.clientY,startHeight:r,startSnapPoint:p.current,viewportHeight:ft()},u.current=!1,e.currentTarget.setPointerCapture(e.pointerId),e.preventDefault()},[t]),v=J.useCallback(e=>{let t=a.current,n=i.current;if(!t||t.pointerId!==e.pointerId||!n)return;let r=t.startY-e.clientY;Math.abs(r)>3&&(u.current=!0),s.current=mt(t.startHeight+r,t.viewportHeight,!!m.current),o.current===null&&(o.current=window.requestAnimationFrame(()=>{o.current=null,i.current&&s.current!==null&&(i.current.style.height=`${s.current}px`)})),e.preventDefault()},[]),y=J.useCallback((e,n)=>{let o=a.current,c=i.current;if(!o||o.pointerId!==e.pointerId||!c)return;a.current=null,h();let u=s.current??c.getBoundingClientRect().height;if(s.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),!n&&m.current&&pt(u,o.viewportHeight,r,t?l.current:void 0)){c.style.willChange=``,m.current(),e.preventDefault();return}let d=n?o.startSnapPoint:t?gt(u,o.viewportHeight,l.current):tt(u,o.viewportHeight,ct);g(d,u),e.preventDefault()},[h,r,t,g]),b=J.useCallback(()=>{if(u.current){u.current=!1;return}g(p.current===.98?ot:st)},[g]),x=J.useCallback(e=>{let t=null;(e.key===`ArrowUp`||e.key===`Home`)&&(t=st),(e.key===`ArrowDown`||e.key===`End`)&&(t=ot),(e.key===`Enter`||e.key===` `)&&(t=p.current===.98?ot:st),t!==null&&(e.preventDefault(),g(t))},[g]),S=J.useCallback(()=>{a.current=null,h(),s.current=null,c.current?.cancel(),c.current=null,l.current=null,p.current=e,f(e),i.current&&(i.current.style.height=``,i.current.style.willChange=``)},[h,e]);return J.useEffect(()=>()=>{h(),c.current?.cancel()},[h]),{surfaceRef:i,snapPoint:d,handlePointerDown:_,handlePointerMove:v,handlePointerUp:e=>y(e,!1),handlePointerCancel:e=>y(e,!0),handleClick:b,handleKeyDown:x,reset:S}},vt=e=>{let t=(0,X.c)(12),{controller:n,ariaLabel:r}=e,i;t[0]===n.snapPoint?i=t[1]:(i=Math.round(n.snapPoint*100),t[0]=n.snapPoint,t[1]=i);let a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Y.jsx)(`div`,{className:`h-1.5 w-11 rounded-full bg-[var(--interactive-border)]`}),t[2]=a):a=t[2];let o;return t[3]!==r||t[4]!==n.handleClick||t[5]!==n.handleKeyDown||t[6]!==n.handlePointerCancel||t[7]!==n.handlePointerDown||t[8]!==n.handlePointerMove||t[9]!==n.handlePointerUp||t[10]!==i?(o=(0,Y.jsx)(`div`,{"data-mobile-sheet-snap-handle":!0,role:`separator`,tabIndex:0,"aria-label":r,"aria-orientation":`horizontal`,"aria-valuemin":ot*100,"aria-valuemax":st*100,"aria-valuenow":i,className:`flex min-h-8 cursor-ns-resize touch-none justify-center pt-2.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]`,onPointerDown:n.handlePointerDown,onPointerMove:n.handlePointerMove,onPointerUp:n.handlePointerUp,onPointerCancel:n.handlePointerCancel,onClick:n.handleClick,onKeyDown:n.handleKeyDown,children:a}),t[3]=r,t[4]=n.handleClick,t[5]=n.handleKeyDown,t[6]=n.handlePointerCancel,t[7]=n.handlePointerDown,t[8]=n.handlePointerMove,t[9]=n.handlePointerUp,t[10]=i,t[11]=o):o=t[11],o},yt=new WeakMap;function bt(e){yt.set(e.currentTarget,!0)}function xt(e){if(yt.delete(e.currentTarget))return!0;if(e.detail!==0)return!1;if(typeof document>`u`)return!0;let t=document.activeElement,n=e.currentTarget;return n instanceof Node&&t instanceof Node&&n.contains(t)}function St(e){e.target===e.currentTarget&&bt(e)}function Ct(e){return e.target===e.currentTarget&&xt(e)}var wt=new class{entries=[];listeners=new Set;previousOverflow=null;getSnapshot=()=>this.entries.at(-1)?.id??null;subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));add(e,t){return this.entries=[...this.entries.filter(t=>t.id!==e.id),e],this.entries.length===1&&t&&(this.previousOverflow=t.style.overflow,t.style.overflow=`hidden`),this.emit(),()=>this.remove(e.id,t)}remove(e,t){let n=this.entries.length;this.entries=this.entries.filter(t=>t.id!==e),n>0&&this.entries.length===0&&t&&this.previousOverflow!==null&&(t.style.overflow=this.previousOverflow,this.previousOverflow=null),this.emit()}closeTop(){this.entries.at(-1)?.onClose()}emit(){for(let e of this.listeners)e()}},Tt=`mobile-sessions`,Et=new Map,Dt=e=>Et.get(e)??null,Ot=(e,t)=>(Et.set(e,t),()=>{Et.get(e)===t&&Et.delete(e)}),kt=`.overlay-scrollbar-container`,At=1,jt=e=>e===`left`||e===`right`?`x`:`y`,Mt=e=>e===`bottom`||e===`right`?1:-1,Nt=(e,t,n)=>{let r=jt(e)===`x`?t:n;return Math.max(0,r*Mt(e))},Pt=(e,t,n,r,i)=>{let a=Nt(e,t,n),o=Math.abs(jt(e)===`x`?n:t);return Math.hypot(t,n)>r&&a>0&&o<a*i},Ft=(e,t)=>Math.min(1,Math.max(0,e/Math.max(1,t))),It=(e,t,n,r)=>Math.min(r,Math.max(n,e*t)),Lt=(e,t,n,r,i)=>e>=n||e>=i&&t>=r,Rt=(e,t,n,r,i)=>t!==0&&n>0?t*i/n:r>80?0:e,zt=(e,t,n=At)=>{if(t===`bottom`)return e.scrollTop<=n;if(t===`top`)return e.scrollTop>=e.scrollHeight-e.clientHeight-n;if(e.matches?.(`:dir(rtl)`)){let r=e.scrollWidth-e.clientWidth;return t===`right`?Math.abs(e.scrollLeft)<=n:Math.abs(e.scrollLeft)>=r-n}return t===`right`?e.scrollLeft<=n:e.scrollLeft>=e.scrollWidth-e.clientWidth-n},Bt=(e,t)=>{for(let n=0;n<e.length;n+=1){let r=e.item(n);if(r?.identifier===t)return r}return null},Vt=(e,t)=>{let n=window.getComputedStyle(e),r=jt(t),i=r===`x`?n.overflowX:n.overflowY,a=r===`x`?e.scrollWidth:e.scrollHeight,o=r===`x`?e.clientWidth:e.clientHeight;return(i===`auto`||i===`scroll`||i===`overlay`)&&a>o},Ht=(e,t,n,r)=>{let i=t instanceof Element?t:null,a=i instanceof HTMLElement?i:i?.parentElement??null;for(;a&&e.contains(a);){if(Vt(a,n))return a;if(a===e)break;a=a.parentElement}let o=i?.closest(r)??null;return o&&e.contains(o)&&Vt(o,n)?o:null},Ut=e=>{let t=J.useRef(e),n=J.useRef(null),r=J.useRef(null);return t.current=e,J.useCallback(e=>{if(n.current?.(),n.current=null,!e)return;let i=()=>{let e=r.current;r.current=null,e?.active&&e.controller?.finish(`cancel`)},a=(e,t,n)=>{let r=jt(e.edge)===`x`?t.clientX:t.clientY,i=n-e.lastTime,a=r-e.lastPrimary;e.velocity=Rt(e.velocity,a,i,n-e.lastVelocityTime,Mt(e.edge)),a!==0&&i>0&&(e.lastVelocityTime=n),e.lastPrimary=r,e.lastTime=n,e.distance=Nt(e.edge,t.clientX-e.startX,t.clientY-e.startY)},o=n=>{i();let a=t.current;if(a.disabled||n.touches.length!==1)return;let o=n.target instanceof Element?n.target:null,s=a.reservedTargetSelector?o?.closest(a.reservedTargetSelector):null;if(s&&e.contains(s)||o?.closest(`input, textarea, select, [contenteditable=""], [contenteditable="true"], [data-mobile-sheet-no-dismiss]`))return;let c=n.touches[0],l=Ht(e,n.target,a.edge,a.scrollContainerSelector??kt);if(l&&!zt(l,a.edge))return;let u=e.getBoundingClientRect(),d=jt(a.edge)===`x`?u.width||window.innerWidth:u.height||window.innerHeight;r.current={edge:a.edge,motionId:a.motionId,touchId:c.identifier,startX:c.clientX,startY:c.clientY,lastPrimary:jt(a.edge)===`x`?c.clientX:c.clientY,lastTime:n.timeStamp,lastVelocityTime:n.timeStamp,velocity:0,distance:0,commitDistance:It(d,a.commitDistanceRatio??.1,a.minCommitDistance??40,a.maxCommitDistance??64),motionDistance:d,intentDistance:a.intentDistance??8,maxOffAxisRatio:a.maxOffAxisRatio??1,flingVelocity:a.flingVelocity??.65,flingMinDistance:a.flingMinDistance??12,controller:null,active:!1}},s=e=>{let n=r.current;if(!n)return;if(t.current.disabled||e.touches.length!==1){i();return}let o=Bt(e.touches,n.touchId);if(!o){i();return}if(a(n,o,e.timeStamp),!n.active){if(Math.hypot(o.clientX-n.startX,o.clientY-n.startY)<=n.intentDistance)return;if(!Pt(n.edge,o.clientX-n.startX,o.clientY-n.startY,n.intentDistance,n.maxOffAxisRatio)){r.current=null;return}let e=Dt(n.motionId);if(!e){r.current=null;return}if(!e.begin(`dismiss`)){r.current=null;return}n.active=!0,n.controller=e}n.controller?.update(Ft(n.distance,n.motionDistance)),e.preventDefault()},c=e=>{let t=r.current;if(!t)return;let n=Bt(e.changedTouches,t.touchId);if(!n){i();return}if(r.current=null,!t.active)return;a(t,n,e.timeStamp),t.controller?.update(Ft(t.distance,t.motionDistance));let o=Lt(t.distance,t.velocity,t.commitDistance,t.flingVelocity,t.flingMinDistance);t.controller?.finish(o?`commit`:`cancel`),e.preventDefault()},l=()=>i();e.addEventListener(`touchstart`,o,{passive:!0,capture:!0}),e.addEventListener(`touchmove`,s,{passive:!1,capture:!0}),e.addEventListener(`touchend`,c,{passive:!1,capture:!0}),e.addEventListener(`touchcancel`,l,{passive:!0,capture:!0}),n.current=()=>{i(),e.removeEventListener(`touchstart`,o,!0),e.removeEventListener(`touchmove`,s,!0),e.removeEventListener(`touchend`,c,!0),e.removeEventListener(`touchcancel`,l,!0)}},[])},Wt=`mobile-overlay-root`,Gt=200,Kt=80,qt=`cubic-bezier(0.32, 0.72, 0, 1)`,Jt=`a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])`,Yt=()=>{if(typeof document>`u`)return null;let e=document.getElementById(Wt);return e||(e=document.createElement(`div`),e.id=Wt,document.body.appendChild(e)),e},Xt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Zt=({id:e,open:t,onOpenChange:n,keepMounted:r=!1,presentation:i=`sheet`,edge:a=`bottom`,children:o,className:s,scrimClassName:c,surfaceClassName:l,surfaceElementRef:u,dismissGesture:d=!1,onExitComplete:f,ariaLabel:p})=>{let m=J.useRef(null),h=J.useRef(null),g=J.useRef(null),_=J.useRef(t),v=J.useRef(n),y=J.useRef(f),b=J.useRef(0),x=J.useRef(0),S=J.useRef(null),C=J.useRef(null),w=J.useRef([]),T=J.useRef(null),E=J.useRef(`standard`),D=J.useRef(`present`),O=J.useRef(0),k=J.useRef(!1),A=J.useRef(t),j=J.useRef(!1),M=J.useRef(t),N=J.useRef(null),[P,F]=J.useState(t),[I,ee]=J.useState(t),[te,ne]=J.useState(`standard`),[re,ie]=J.useState(!1),L=te===`interactive-present`,ae=J.useSyncExternalStore(wt.subscribe,wt.getSnapshot,wt.getSnapshot),R=I&&!L&&ae===e,z=Ut({motionId:e,edge:a,disabled:!d,...typeof d==`object`?d:{}}),V=J.useCallback(e=>{g.current=e,z(e),typeof u==`function`?u(e):u&&typeof u==`object`&&(u.current=e)},[z,u]),H=J.useCallback(()=>{M.current&&(M.current=!1,ee(!1),r||F(!1),y.current?.())},[r]);_.current=t,v.current=n,y.current=f,typeof document<`u`&&!m.current&&(m.current=Yt());let oe=J.useCallback(e=>{let t=nt(a,e);b.current=t.progress,!(!h.current||!g.current)&&(h.current.style.opacity=String(t.scrimOpacity),g.current.style.transform=t.surfaceTransform,g.current.style.opacity=String(t.surfaceOpacity))},[a]),U=J.useCallback(()=>{S.current!==null&&window.cancelAnimationFrame(S.current),S.current=null},[]),W=J.useCallback(()=>{C.current!==null&&window.cancelAnimationFrame(C.current),C.current=null},[]),G=J.useCallback(()=>{h.current&&(h.current.style.willChange=``),g.current&&(g.current.style.willChange=``)},[]),K=J.useCallback((e=w.current)=>{for(let t of e)t.cancel();w.current=[]},[]),se=J.useCallback(()=>{U();let e=T.current;if(e){let t=e.animations[1]?.effect?.getComputedTiming().progress;oe(typeof t==`number`&&Number.isFinite(t)?e.from+(e.target-e.from)*t:b.current),K(e.animations),T.current=null}else K();G(),ie(!1)},[oe,K,U,G]),q=J.useCallback((e,t)=>{if(T.current?.target===e)return;se();let n=b.current,r=h.current,i=g.current;if(ie(!0),!r||!i||Xt()||n===e){oe(e),G(),ie(!1),t?.();return}let o=nt(a,n),s=nt(a,e);r.style.willChange=`opacity`,i.style.willChange=`transform, opacity`;let c=Math.max(Kt,Gt*Math.abs(e-n)),l=[r.animate([{opacity:o.scrimOpacity},{opacity:s.scrimOpacity}],{duration:c,easing:qt,fill:`forwards`}),i.animate([{transform:o.surfaceTransform,opacity:o.surfaceOpacity},{transform:s.surfaceTransform,opacity:s.surfaceOpacity}],{duration:c,easing:qt,fill:`forwards`})];w.current=l;let u={from:n,target:e,animations:l};T.current=u,Promise.all(l.map(e=>e.finished.catch(()=>void 0))).then(()=>{T.current===u&&(oe(e),K(l),T.current=null,G(),ie(!1),t?.())})},[oe,K,G,a,se]);if(J.useLayoutEffect(()=>{j.current=P,P&&oe(x.current)},[oe,P]),J.useLayoutEffect(()=>{M.current=I},[I]),J.useEffect(()=>{W(),t&&!j.current&&(x.current=b.current,F(!0)),t&&!M.current&&(M.current=!0,ee(!0)),j.current&&E.current===`standard`&&q(at(t),()=>{!_.current&&E.current===`standard`&&H()})},[W,H,t,q]),J.useLayoutEffect(()=>{!P||E.current!==`standard`||C.current!==null||q(+!!t,()=>{!_.current&&E.current===`standard`&&H()})},[H,P,t,q]),J.useEffect(()=>{if(!(!I||L))return window.dispatchEvent(new Event(`oc:mobile-overlay-opened`)),()=>{window.dispatchEvent(new Event(`oc:mobile-overlay-closed`))}},[I,L]),J.useEffect(()=>{if(!(!I||L))return wt.add({id:e,onClose:()=>v.current(!1)},document.body)},[I,e,L]),J.useEffect(()=>{if(!I||L||!R)return;let e=g.current,t=document.activeElement instanceof HTMLElement?document.activeElement:null;e?.focus({preventScroll:!0});let n=t=>{if(t.key===`Escape`&&wt.closeTop(),t.key!==`Tab`||!e)return;let n=Array.from(e.querySelectorAll(Jt)).filter(e=>!e.closest(`[data-mobile-sheet-snap-handle]`)),r=n[0]??e,i=n.at(-1)??e;t.shiftKey&&document.activeElement===r&&(t.preventDefault(),i.focus({preventScroll:!0})),!t.shiftKey&&document.activeElement===i&&(t.preventDefault(),r.focus({preventScroll:!0}))};return document.addEventListener(`keydown`,n),()=>{document.removeEventListener(`keydown`,n),Q()||t?.focus({preventScroll:!0})}},[I,L,R]),N.current={begin:e=>{if(e===`dismiss`&&(!M.current||E.current===`interactive-present`))return!1;W(),se(),O.current+=1,k.current=!0,D.current=e;let t=e===`present`?`interactive-present`:`interactive-dismiss`;return E.current=t,ne(t),ie(!0),e===`present`&&(x.current=b.current,M.current=!0,ee(!0),F(!0)),!0},update:e=>{k.current&&(x.current=rt(D.current,e),S.current===null&&(S.current=window.requestAnimationFrame(()=>{S.current=null,k.current&&oe(x.current)})))},finish:e=>{if(!k.current)return;k.current=!1;let t=O.current,n=D.current,r=it(n,e);S.current!==null&&(U(),oe(x.current)),q(r,()=>{t===O.current&&(e===`commit`&&v.current(n===`present`),n===`present`&&e===`cancel`&&!_.current&&H(),E.current=`standard`,ne(`standard`),C.current=window.requestAnimationFrame(()=>{if(C.current=null,t!==O.current)return;let e=at(_.current);q(e,()=>{t===O.current&&!_.current&&H()})}))})},interrupt:()=>{W(),O.current+=1,k.current=!1;let e=E.current===`interactive-present`&&!_.current;e||(E.current=`standard`,ne(`standard`)),se(),q(at(_.current),()=>{_.current||H(),e&&(E.current=`standard`,ne(`standard`))})}},J.useLayoutEffect(()=>{let e=A.current;A.current=t,e&&!t&&E.current!==`standard`&&N.current?.interrupt()},[t]),J.useEffect(()=>{let t=Ot(e,{begin:e=>N.current?.begin(e)??!1,update:e=>N.current?.update(e),finish:e=>N.current?.finish(e),interrupt:()=>N.current?.interrupt()});return()=>{t(),W(),U(),K(),T.current=null,G(),N.current=null}},[K,U,W,G,e]),!P||!m.current)return null;let ce=(0,Y.jsx)(`div`,{ref:h,className:B(`oc-mobile-window-motion oc-keyboard-inset-surface fixed inset-0 z-[60] flex flex-col bg-[rgb(0_0_0_/_0.45)]`,re&&`oc-mobile-window-motion-active`,!I&&!L&&`pointer-events-none invisible`,c,s),"data-mobile-overlay-active":String(I),role:L?void 0:`dialog`,"aria-label":L?void 0:p,"aria-modal":I&&R?`true`:void 0,"aria-hidden":L||!I||!R||void 0,inert:L||!I||!R||void 0,onPointerDown:St,onClick:e=>{!I||L||!R||Ct(e)&&v.current(!1)},children:(0,Y.jsx)(`div`,{ref:V,tabIndex:-1,className:B(`oc-mobile-floating-shell`,$e(i,a),l),style:{contain:`layout paint style`},onClick:e=>e.stopPropagation(),children:o})});return(0,ge.createPortal)(ce,m.current)},Qt=J.createContext(null),$t=e=>{let t=(0,X.c)(5),{children:n}=e,r=J.useContext(Qt);if(!r)return null;let i;t[0]===n?i=t[1]:(i=(0,Y.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:n}),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a=(0,ge.createPortal)(i,r),t[2]=r,t[3]=i,t[4]=a):a=t[4],a},en=e=>{let t=(0,X.c)(40),{id:n,open:r,onOpenChange:i,title:a,leading:o,trailing:s,ariaLabel:c,closeAriaLabel:l,resizeAriaLabel:u,initiallyExpanded:d,fitContent:f,bodyClassName:p,children:m}=e,h=d!==void 0&&d,g=f!==void 0&&f,_=h?st:void 0,v;t[0]===i?v=t[1]:(v=()=>i(!1),t[0]=i,t[1]=v);let y;t[2]!==g||t[3]!==_||t[4]!==v?(y={initialSnapPoint:_,fitContent:g,onDismiss:v},t[2]=g,t[3]=_,t[4]=v,t[5]=y):y=t[5];let b=_t(y),[x,S]=J.useState(null),C=a!=null||o!=null||s!=null,w;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(w={reservedTargetSelector:`[data-mobile-sheet-snap-handle]`},t[6]=w):w=t[6];let T=b.snapPoint===.98?`h-[98dvh] max-h-[98dvh]`:g?`h-auto max-h-[72dvh]`:`h-[72dvh] max-h-[98dvh]`,E=b.surfaceRef,D=b.reset,O;t[7]!==u||t[8]!==b?(O=(0,Y.jsx)(vt,{controller:b,ariaLabel:u}),t[7]=u,t[8]=b,t[9]=O):O=t[9];let k;t[10]!==l||t[11]!==C||t[12]!==o||t[13]!==i||t[14]!==a||t[15]!==s?(k=C?(0,Y.jsxs)(`div`,{className:`flex min-h-10 items-center gap-2 px-4 pb-2`,children:[o?(0,Y.jsx)(`div`,{className:`flex shrink-0 items-center`,children:o}):null,(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:a}),s?(0,Y.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:s}):null,(0,Y.jsx)(`div`,{ref:S,className:`contents`}),(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>i(!1),"aria-label":l,className:`shrink-0 text-muted-foreground`,style:{touchAction:`manipulation`},children:(0,Y.jsx)(V,{name:`close`,className:`size-5`})})]}):null,t[10]=l,t[11]=C,t[12]=o,t[13]=i,t[14]=a,t[15]=s,t[16]=k):k=t[16];let A;t[17]!==O||t[18]!==k?(A=(0,Y.jsxs)(`div`,{className:`shrink-0`,children:[O,k]}),t[17]=O,t[18]=k,t[19]=A):A=t[19];let j;t[20]===p?j=t[21]:(j=B(`flex min-h-0 flex-1 flex-col overflow-hidden`,p),t[20]=p,t[21]=j);let M;t[22]!==m||t[23]!==j?(M=(0,Y.jsx)(`div`,{className:j,"data-page-scroll-lock":`true`,children:m}),t[22]=m,t[23]=j,t[24]=M):M=t[24];let N;t[25]!==A||t[26]!==M?(N=(0,Y.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[A,M]}),t[25]=A,t[26]=M,t[27]=N):N=t[27];let P;t[28]!==c||t[29]!==n||t[30]!==i||t[31]!==r||t[32]!==b.reset||t[33]!==b.surfaceRef||t[34]!==N||t[35]!==T?(P=(0,Y.jsx)(Zt,{id:n,open:r,onOpenChange:i,presentation:`sheet`,edge:`bottom`,dismissGesture:w,ariaLabel:c,surfaceClassName:T,surfaceElementRef:E,onExitComplete:D,children:N}),t[28]=c,t[29]=n,t[30]=i,t[31]=r,t[32]=b.reset,t[33]=b.surfaceRef,t[34]=N,t[35]=T,t[36]=P):P=t[36];let F;return t[37]!==x||t[38]!==P?(F=(0,Y.jsx)(Qt.Provider,{value:x,children:P}),t[37]=x,t[38]=P,t[39]=F):F=t[39],F};function tn(){let e=(0,X.c)(5),t=L(on),n=L(an),r=L(rn),i=L(nn),a=t||i,o=!a&&r===`init_error`,s=!a&&!o,c;return e[0]!==n||e[1]!==a||e[2]!==o||e[3]!==s?(c={isReady:a,isLoading:s,isUnavailable:o,connectionPhase:n},e[0]=n,e[1]=a,e[2]=o,e[3]=s,e[4]=c):c=e[4],c}function nn(e){return e.providers.length>0}function rn(e){return e.lastDisconnectReason}function an(e){return e.connectionPhase}function on(e){return e.isInitialized}var sn=e=>{let t=(0,X.c)(41),{agentName:r,onChange:i,className:a,filter:o,dropdownPortalToBody:s,showIcon:c,agents:l}=e,u=s!==void 0&&s,d=c===void 0||c,{t:f}=ee(),{isReady:p,isUnavailable:m}=tn(),h=L(cn),g=ae(ln),_=L(un),{data:v}=ie(),y;t[0]===v?y=t[1]:(y=v===void 0?[]:v,t[0]=v,t[1]=y);let b=y,x;bb0:{if(l){x=l;break bb0}if(Array.isArray(h)&&h.length>0){x=h;break bb0}x=b}let S=x,C;if(t[2]!==o||t[3]!==S){let e=ne(S);C=o?e.filter(o):e,t[2]=o,t[3]=S,t[4]=C}else C=t[4];let w=C,T=n(dn),{isMobile:E}=ue(),D=T||E,[O,k]=J.useState(!1),A;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(A=()=>{k(!0),L.getState().refreshCatalogsOnPickerOpen({source:`agentSelector:mobilePanel`})},t[5]=A):A=t[5];let j=I(A),M=I(fn),N=J.useId(),P,F;t[6]!==l||t[7]!==g||t[8]!==_||t[9]!==S.length?(P=()=>{l||S.length>0||(_(),g())},F=[l,S.length,_,g],t[6]=l,t[7]=g,t[8]=_,t[9]=S.length,t[10]=P,t[11]=F):(P=t[10],F=t[11]),J.useEffect(P,F);let te;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(te=()=>k(!1),t[12]=te):te=t[12];let re=te,z;t[13]===i?z=t[14]:(z=e=>{i(e)},t[13]=i,t[14]=z);let H=z,U;t[15]!==r||t[16]!==w||t[17]!==H||t[18]!==D||t[19]!==O||t[20]!==N||t[21]!==f?(U=()=>D?(0,Y.jsx)(en,{id:`mobile-agent-selector-sheet-${N}`,open:O,onOpenChange:e=>{e||re()},ariaLabel:f(`settings.commands.agentSelector.title`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),bodyClassName:`px-2`,children:(0,Y.jsxs)(oe,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`flex flex-col gap-1 overscroll-contain`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:B(`grid w-full grid-cols-[1rem_minmax(0,1fr)_auto] items-center gap-x-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left`,r?`text-foreground`:`bg-primary/10 text-primary`),onClick:()=>{H(``),re()},children:[(0,Y.jsx)(R,{name:`default`,size:16}),(0,Y.jsx)(`span`,{className:B(`min-w-0 typography-meta`,r?`text-muted-foreground`:`font-medium`),children:f(`settings.commands.agentSelector.notSelected`)}),!r&&(0,Y.jsx)(`div`,{className:`h-2 w-2 rounded-full bg-primary`})]}),w.map(e=>{let t=e.name===r;return(0,Y.jsxs)(`button`,{type:`button`,className:B(`grid w-full grid-cols-[1rem_minmax(0,1fr)_auto] items-start gap-x-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left`,t?`bg-primary/10 text-primary`:`text-foreground`),onClick:()=>{H(e.name),re()},children:[(0,Y.jsx)(R,{name:e.name,size:16,className:`mt-1.5`}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`span`,{className:`typography-meta font-medium`,children:e.name}),e.description&&(0,Y.jsx)(`span`,{className:`mt-0.5 block whitespace-normal break-words typography-micro text-muted-foreground`,children:e.description})]}),t&&(0,Y.jsx)(`div`,{className:`mt-2 h-2 w-2 rounded-full bg-primary`})]},e.name)})]})}):null,t[15]=r,t[16]=w,t[17]=H,t[18]=D,t[19]=O,t[20]=N,t[21]=f,t[22]=U):U=t[22];let W=U,G;t[23]!==r||t[24]!==w||t[25]!==a||t[26]!==u||t[27]!==H||t[28]!==M||t[29]!==D||t[30]!==p||t[31]!==m||t[32]!==j||t[33]!==d||t[34]!==f?(G=D?(0,Y.jsxs)(`button`,{type:`button`,onClick:p?j:void 0,disabled:!p,className:B(`flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left`,!p&&`opacity-60 cursor-not-allowed`,a),children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-2`,children:p?(0,Y.jsxs)(Y.Fragment,{children:[d?(0,Y.jsx)(R,{name:r||`default`,size:14}):null,(0,Y.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:r||f(`settings.commands.agentSelector.selectAgentPlaceholder`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(V,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:f(m?`common.unavailable`:`common.loading`)})]})}),(0,Y.jsx)(V,{name:`arrow-down-s`,className:`h-3 w-3 text-muted-foreground`})]}):p?(0,Y.jsxs)(Ge,{onOpenChange:M,children:[(0,Y.jsx)(Ke,{asChild:!0,children:(0,Y.jsxs)(`div`,{className:B(`flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 cursor-pointer hover:bg-interactive-hover/30 h-6 w-fit`,a),children:[d?(0,Y.jsx)(R,{name:r||`default`,size:14}):null,(0,Y.jsx)(`span`,{className:`typography-micro font-medium whitespace-nowrap`,children:r||f(`settings.commands.agentSelector.notSelected`)}),(0,Y.jsx)(V,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0 text-muted-foreground`})]})}),(0,Y.jsxs)(qe,{className:`max-w-[300px]`,portalToBody:u,children:[(0,Y.jsxs)(Je,{className:`typography-meta`,onSelect:()=>H(``),children:[(0,Y.jsx)(R,{name:`default`,size:14}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:f(`settings.commands.agentSelector.notSelected`)})]}),w.map(e=>(0,Y.jsxs)(Je,{className:`typography-meta`,onSelect:()=>H(e.name),children:[(0,Y.jsx)(R,{name:e.name,size:14}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.name})]},e.name))]})]}):(0,Y.jsxs)(`div`,{className:B(`flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60`,a),children:[(0,Y.jsx)(V,{name:`loader-4`,className:`h-3 w-3 animate-spin text-muted-foreground flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`typography-micro font-medium whitespace-nowrap text-muted-foreground`,children:f(m?`common.unavailable`:`common.loading`)})]}),t[23]=r,t[24]=w,t[25]=a,t[26]=u,t[27]=H,t[28]=M,t[29]=D,t[30]=p,t[31]=m,t[32]=j,t[33]=d,t[34]=f,t[35]=G):G=t[35];let K;t[36]===W?K=t[37]:(K=W(),t[36]=W,t[37]=K);let se;return t[38]!==G||t[39]!==K?(se=(0,Y.jsxs)(Y.Fragment,{children:[G,K]}),t[38]=G,t[39]=K,t[40]=se):se=t[40],se};function cn(e){return e.agents}function ln(e){return e.loadAgents}function un(e){return e.loadAgents}function dn(e){return e.isMobile}function fn(e){e&&L.getState().refreshCatalogsOnPickerOpen({source:`agentSelector:desktopMenu`})}var pn=8,mn=e=>typeof e!=`number`||Number.isNaN(e)?``:new Intl.NumberFormat(te(),{notation:`compact`,compactDisplay:`short`,maximumFractionDigits:1}).format(e),hn=(e,t,n)=>{let r=e.find(e=>e.id===t)?.models?.find(e=>e.id===n);return r?.variants?Object.keys(r.variants):[]},gn=e=>{let t=(0,X.c)(160),{open:n,onClose:r,selectedProviderID:i,selectedModelID:a,resolveSelectedVariant:o,onSelect:s,providers:c,favoriteModels:l,recentModels:u,hiddenModels:d,allowedProviderIds:f,allowedModelIdsByProvider:p,providerOrder:m,variantSelectionEnabled:h,isFavorite:g,onToggleFavorite:_,getMetadata:v,view:y,onViewChange:b}=e,x;t[0]===d?x=t[1]:(x=d===void 0?[]:d,t[0]=d,t[1]=x);let S=x,C=h===void 0||h,{t:w}=ee(),T=J.useId(),[E,D]=J.useState(``),O;t[2]===i?O=t[3]:(O=()=>new Set(i?[i]:[]),t[2]=i,t[3]=O);let[k,A]=J.useState(O),[j,M]=J.useState(null),[N,P]=J.useState(`model`),[F,I]=J.useState(null),te=J.useRef(!1),ne=y??N,ie,L;t[4]!==n||t[5]!==i?(ie=()=>{n&&!te.current&&A(new Set(i?[i]:[])),n||(D(``),M(null),P(`model`),I(null)),te.current=n},L=[n,i],t[4]=n,t[5]=i,t[6]=ie,t[7]=L):(ie=t[6],L=t[7]),J.useEffect(ie,L);let ae;t[8]===b?ae=t[9]:(ae=e=>{P(e),b?.(e)},t[8]=b,t[9]=ae);let R=ae,z;t[10]===f?z=t[11]:(z=f&&f.length>0?new Set(f):null,t[10]=f,t[11]=z);let U=z,G;t[12]===p?G=t[13]:(G=p?new Map(Object.entries(p).map(_n)):null,t[12]=p,t[13]=G);let le=G,ue;t[14]===S?ue=t[15]:(ue=new Set(S.map(vn)),t[14]=S,t[15]=ue);let de=ue,fe;t[16]===c?fe=t[17]:(fe=new Map(c.map(yn)),t[16]=c,t[17]=fe);let pe=fe,me;bb0:{if(!m?.length){me=c;break bb0}let e;t[18]===m?e=t[19]:(e=new Map(m.map(bn)),t[18]=m,t[19]=e);let n=e,r;if(t[20]!==c||t[21]!==n){let e;t[23]===n?e=t[24]:(e=(e,t)=>{let r=n.get(e.id),i=n.get(t.id);return r===void 0&&i===void 0?0:r===void 0?1:i===void 0?-1:r-i},t[23]=n,t[24]=e),r=[...c].sort(e),t[20]=c,t[21]=n,t[22]=r}else r=t[22];me=r}let he=me,ge;t[25]!==le||t[26]!==U||t[27]!==de?(ge=(e,t)=>U&&!U.has(e)||le&&le.get(e)?.has(t)!==!0?!1:!de.has(`${e}:${t}`),t[25]=le,t[26]=U,t[27]=de,t[28]=ge):ge=t[28];let Z=ge,_e;t[29]!==pe||t[30]!==E?(_e=e=>{let t=E.trim();if(!t)return!0;let n=pe.get(e.providerID)?.name||e.providerID,r=re(e.model,e.modelID,{maxLength:40});return q(r,t)||q(e.modelID,t)||q(n,t)},t[29]=pe,t[30]=E,t[31]=_e):_e=t[31];let Q=_e,ve;if(t[32]!==l||t[33]!==Z||t[34]!==Q){let e;t[36]!==Z||t[37]!==Q?(e=e=>Z(e.providerID,e.modelID)&&Q(e),t[36]=Z,t[37]=Q,t[38]=e):e=t[38],ve=l.filter(e),t[32]=l,t[33]=Z,t[34]=Q,t[35]=ve}else ve=t[35];let ye=ve,be;if(t[39]!==Z||t[40]!==Q||t[41]!==u){let e;t[43]!==Z||t[44]!==Q?(e=e=>Z(e.providerID,e.modelID)&&Q(e),t[43]=Z,t[44]=Q,t[45]=e):e=t[45],be=u.filter(e),t[39]=Z,t[40]=Q,t[41]=u,t[42]=be}else be=t[42];let xe=be,Se;if(t[46]!==U||t[47]!==Z||t[48]!==he||t[49]!==E){let e;t[51]===U?e=t[52]:(e=e=>!U||U.has(e.id),t[51]=U,t[52]=e);let n;t[53]!==Z||t[54]!==E?(n=e=>{let t=E.trim().length>0&&(q(e.name||e.id,E.trim())||q(e.id,E.trim()));return{provider:e,models:(e.models??[]).filter(n=>{let r=typeof n.id==`string`?n.id:``;return!r||!Z(e.id,r)?!1:t||!E.trim()?!0:q(re(n,r,{maxLength:40}),E.trim())||q(r,E.trim())})}},t[53]=Z,t[54]=E,t[55]=n):n=t[55],Se=he.filter(e).map(n).filter(xn),t[46]=U,t[47]=Z,t[48]=he,t[49]=E,t[50]=Se}else Se=t[50];let Ce=Se,$;t[56]===w?$=t[57]:($=e=>{if(!e?.trim())return w(`chat.modelControls.default`);let t=e.trim();return/^\d+(\.\d+)?$/.test(t)?t:t.charAt(0).toUpperCase()+t.slice(1)},t[56]=w,t[57]=$);let we=$,Te;t[58]===w?Te=t[59]:(Te=e=>{let t=[];e?.tool_call&&t.push({key:`tool_call`,icon:`tools`,label:w(`chat.modelControls.capability.toolCalling`)}),e?.reasoning&&t.push({key:`reasoning`,icon:`brain-ai-3`,label:w(`chat.modelControls.capability.reasoning`)});let n={text:{icon:`text`,label:w(`chat.modelControls.modality.text`)},image:{icon:`file-image`,label:w(`chat.modelControls.modality.image`)},video:{icon:`file-video`,label:w(`chat.modelControls.modality.video`)},audio:{icon:`file-music`,label:w(`chat.modelControls.modality.audio`)},pdf:{icon:`file-pdf`,label:w(`chat.modelControls.modality.pdf`)}};for(let r of[...e?.modalities?.input??[],...e?.modalities?.output??[]]){let e=r.trim().toLowerCase(),i=n[e];i&&!t.some(t=>t.key===e)&&t.push({key:e,...i})}return t},t[58]=w,t[59]=Te);let Ee=Te,De;t[60]===R?De=t[61]:(De=(e,t,n)=>{I(n===void 0?{providerID:e,modelID:t}:{providerID:e,modelID:t,variant:n}),R(`variant`)},t[60]=R,t[61]=De);let Oe=De,ke;t[62]===Symbol.for(`react.memo_cache_sentinel`)?(ke={onPointerDown:bt,onClickCapture:Sn},t[62]=ke):ke=t[62];let Ae=ke,je;t[63]!==j||t[64]!==we||t[65]!==v||t[66]!==Ee||t[67]!==g||t[68]!==s||t[69]!==_||t[70]!==Oe||t[71]!==pe||t[72]!==c||t[73]!==o||t[74]!==a||t[75]!==i||t[76]!==w||t[77]!==C?(je=(e,t)=>{let n=t===void 0?{}:t,{model:r,providerID:l,modelID:u}=e,d=`${l}:${u}`,f=l===i&&u===a,p=K(l,r,v?.(l,u)),m=C?hn(c,l,u):[],h=o(l,u),y=n.preferRememberedVariant&&e.variant!==void 0&&m.includes(e.variant)?e.variant:void 0,b=y===void 0?h:y,x=f||y===void 0?h:y,S=[void 0,...m].slice(0,pn),T=j===d,E=Ee(p),D=p?.limit?.context?`${mn(p.limit.context)} ctx`:null;return(0,Y.jsxs)(`div`,{className:B(`border-b border-border/30 last:border-b-0`,f&&`bg-interactive-selection/15 text-interactive-selection-foreground`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5`,children:[(0,Y.jsx)(`button`,{type:`button`,...Ae,onClick:()=>s(l,u,b),className:`flex min-w-0 flex-1 items-start gap-2 rounded-lg text-left focus:outline-none focus-visible:ring-1 focus-visible:ring-primary`,children:(0,Y.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[n.showProvider?(0,Y.jsx)(`span`,{className:`truncate text-[10px] leading-none text-muted-foreground/60`,children:pe.get(l)?.name||l}):null,(0,Y.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,Y.jsx)(se,{modelId:u,providerId:l,className:`size-3.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate typography-meta font-medium text-foreground`,children:re(r,u,{maxLength:40})}),f?(0,Y.jsx)(V,{name:`check`,className:`size-4 flex-shrink-0 text-primary`}):null]}),D||E.length>0?(0,Y.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden typography-micro text-muted-foreground`,children:[D?(0,Y.jsx)(`span`,{className:`flex-shrink-0 whitespace-nowrap`,children:D}):null,D&&E.length>0?(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`h-3 w-px flex-shrink-0 bg-border/50`}):null,(0,Y.jsx)(`div`,{className:`flex min-w-0 items-center gap-1 overflow-hidden whitespace-nowrap pl-0.5`,children:E.map(e=>{let{key:t,icon:n,label:r}=e;return(0,Y.jsx)(`span`,{className:`flex size-4 flex-shrink-0 items-center justify-center text-muted-foreground`,title:r,"aria-label":r,children:(0,Y.jsx)(V,{name:n,className:`size-3`})},`${d}-${t}`)})})]}):null]})}),m.length>0?(0,Y.jsxs)(`button`,{type:`button`,...Ae,onClick:()=>M(e=>e===d?null:d),className:`flex flex-shrink-0 items-center gap-0.5 typography-micro font-medium text-muted-foreground hover:text-foreground`,"aria-expanded":T,"aria-label":w(T?`chat.modelControls.hideThinkingModes`:`chat.modelControls.showThinkingModes`),children:[(0,Y.jsx)(`span`,{className:`whitespace-nowrap`,children:we(x)}),(0,Y.jsx)(V,{name:T?`arrow-down-s`:`arrow-right-s`,className:`size-3.5`})]}):null,(0,Y.jsx)(`button`,{type:`button`,...Ae,onClick:e=>{e.preventDefault(),e.stopPropagation(),_(l,u)},className:B(`model-favorite-button flex size-5 flex-shrink-0 items-center justify-center hover:text-primary/80`,g(l,u)?`text-primary`:`text-muted-foreground`),"aria-label":g(l,u)?w(`chat.modelControls.unfavoriteAria`):w(`chat.modelControls.favoriteAria`),title:g(l,u)?w(`chat.modelControls.removeFromFavorites`):w(`chat.modelControls.addToFavorites`),children:(0,Y.jsx)(V,{name:g(l,u)?`star-fill`:`star`,className:`size-4`})})]}),T&&m.length>0?(0,Y.jsx)(`div`,{className:`border-t border-border/30 p-2`,children:(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[S.map(e=>{let t=e===x||!e&&!x;return(0,Y.jsx)(`button`,{type:`button`,...Ae,onClick:()=>s(l,u,e),className:B(`inline-flex items-center rounded-full border px-2.5 py-1 typography-meta font-medium`,t?`border-primary/30 bg-primary/10 text-foreground`:`border-border/40 text-muted-foreground hover:bg-interactive-hover/50`),"aria-pressed":t,children:we(e)},`${d}-${e??`default`}`)}),S.length<m.length+1?(0,Y.jsx)(`button`,{type:`button`,...Ae,onClick:()=>Oe(l,u,x),className:`inline-flex items-center rounded-full border border-border/40 px-2.5 py-1 typography-meta font-medium text-muted-foreground hover:bg-interactive-hover/50`,"aria-label":w(`chat.modelControls.moreThinkingModes`),children:w(`inlineComment.actions.showMore`)}):null]})}):null]},`mobile-model-${d}`)},t[63]=j,t[64]=we,t[65]=v,t[66]=Ee,t[67]=g,t[68]=s,t[69]=_,t[70]=Oe,t[71]=pe,t[72]=c,t[73]=o,t[74]=a,t[75]=i,t[76]=w,t[77]=C,t[78]=je):je=t[78];let Me=je,Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge,Ke,qe,Je,Ye,Xe,Ze;if(t[79]!==ne||t[80]!==k||t[81]!==ye||t[82]!==Ce||t[83]!==xe||t[84]!==we||t[85]!==T||t[86]!==r||t[87]!==s||t[88]!==n||t[89]!==c||t[90]!==E||t[91]!==Me||t[92]!==o||t[93]!==a||t[94]!==i||t[95]!==R||t[96]!==w||t[97]!==F){let e=F??(ne===`variant`&&i&&a?{providerID:i,modelID:a}:null),l=e?hn(c,e.providerID,e.modelID):[],u;bb1:{if(!e){u=void 0;break bb1}if(e.providerID===i&&e.modelID===a){u=o(e.providerID,e.modelID);break bb1}u=(e.variant!==void 0&&l.includes(e.variant)?e.variant:void 0)??o(e.providerID,e.modelID)}let d=u,f=ye.length>0||xe.length>0||Ce.length>0,p=ne===`variant`&&!!e;Pe=en,We=`mobile-model-picker-sheet-${T}`,Ge=n,t[117]===r?Ke=t[118]:(Ke=e=>{e||r()},t[117]=r,t[118]=Ke),t[119]!==p||t[120]!==R||t[121]!==w?(qe=p?(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>R(`model`),"aria-label":w(`onboarding.common.actions.back`),children:(0,Y.jsx)(V,{name:`arrow-left`,className:`size-5`})}):void 0,t[119]=p,t[120]=R,t[121]=w,t[122]=qe):qe=t[122],t[123]!==p||t[124]!==w?(Je=w(p?`chat.modelControls.thinking`:`chat.modelControls.selectModel`),t[123]=p,t[124]=w,t[125]=Je):Je=t[125],t[126]===w?Ye=t[127]:(Ye=w(`mobile.surface.closeAria`),t[126]=w,t[127]=Ye),t[128]===w?Xe=t[129]:(Xe=w(`mobile.sessions.sheet.resizeAria`),t[128]=w,t[129]=Xe),Ze=`px-2`,He=`flex min-h-0 flex-1 flex-col gap-2`,t[130]!==p||t[131]!==E||t[132]!==w?(Ue=p?null:(0,Y.jsxs)(`div`,{className:`relative z-10 shrink-0`,"data-mobile-sheet-no-dismiss":``,"data-mobile-sheet-search":``,children:[(0,Y.jsx)(V,{name:`search`,className:`pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(ce,{type:`text`,value:E,onChange:e=>{D(e.target.value),M(null)},onPointerUp:Cn,placeholder:w(`chat.modelControls.searchProvidersOrModels`),className:`h-9 rounded-xl border-border/40 bg-[var(--surface-elevated)] pl-7 typography-meta`,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,enterKeyHint:`search`,inputMode:`search`}),E?(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{D(``),M(null)},className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,"aria-label":w(`chat.modelControls.clearSearch`),children:(0,Y.jsx)(V,{name:`close-circle`,className:`size-4`})}):null]}),t[130]=p,t[131]=E,t[132]=w,t[133]=Ue):Ue=t[133],Ne=oe,Le=!0,Re=!0,ze=!0,Be=`min-h-0 flex-1`,Ve=`overscroll-contain`,Fe=`flex flex-col gap-2`,Ie=p&&e?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:[void 0,...l].map(t=>{let n=t===d||!t&&!d;return(0,Y.jsxs)(`button`,{type:`button`,className:B(`flex w-full items-center justify-between gap-2 rounded-xl border px-2 py-1.5 text-left focus:outline-none focus-visible:ring-1 focus-visible:ring-primary`,n?`border-primary/30 bg-primary/10`:`border-border/40`),...Ae,onClick:()=>s(e.providerID,e.modelID,t),children:[(0,Y.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:we(t)}),n?(0,Y.jsx)(V,{name:`check`,className:`size-4 flex-shrink-0 text-primary`}):null]},t??`default`)})}):(0,Y.jsxs)(Y.Fragment,{children:[f?null:(0,Y.jsx)(`div`,{className:`px-3 py-8 text-center typography-meta text-muted-foreground`,children:w(`chat.modelControls.noProvidersOrModelsFound`)}),ye.length>0?(0,Y.jsxs)(`div`,{className:`overflow-hidden rounded-xl border border-border/40 bg-[var(--surface-elevated)]`,children:[(0,Y.jsxs)(`div`,{className:`px-2 py-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(V,{name:`star-fill`,className:`mr-1.5 inline-block size-3 text-primary`}),w(`chat.modelControls.favorites`)]}),(0,Y.jsx)(`div`,{className:`flex flex-col border-t border-border/30`,children:ye.map(e=>Me(e,{showProvider:!0,preferRememberedVariant:!0}))})]}):null,xe.length>0?(0,Y.jsxs)(`div`,{className:`overflow-hidden rounded-xl border border-border/40 bg-[var(--surface-elevated)]`,children:[(0,Y.jsxs)(`div`,{className:`px-2 py-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(V,{name:`time`,className:`mr-1.5 inline-block size-3`}),w(`chat.modelControls.recent`)]}),(0,Y.jsx)(`div`,{className:`flex flex-col border-t border-border/30`,children:xe.map(e=>Me(e,{showProvider:!0,preferRememberedVariant:!0}))})]}):null,Ce.map(e=>{let{provider:t,models:n}=e,r=k.has(t.id)||E.trim().length>0;return(0,Y.jsxs)(`div`,{className:`overflow-hidden rounded-xl border border-border/40 bg-[var(--surface-elevated)]`,children:[(0,Y.jsxs)(`button`,{type:`button`,...Ae,onClick:()=>{E.trim()||A(e=>{let n=new Set(e);return n.has(t.id)?n.delete(t.id):n.add(t.id),n})},className:`flex w-full items-center justify-between gap-1.5 px-2 py-1.5 text-left`,"aria-expanded":r,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(W,{providerId:t.id,className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:t.name||t.id}),t.id===i?(0,Y.jsx)(`span`,{className:`typography-micro text-primary/80`,children:w(`chat.modelControls.current`)}):null]}),(0,Y.jsx)(V,{name:r?`arrow-down-s`:`arrow-right-s`,className:`size-3 text-muted-foreground`})]}),r?(0,Y.jsx)(`div`,{className:`flex flex-col border-t border-border/30`,children:n.map(e=>Me({model:e,providerID:t.id,modelID:e.id}))}):null]},t.id)})]}),t[79]=ne,t[80]=k,t[81]=ye,t[82]=Ce,t[83]=xe,t[84]=we,t[85]=T,t[86]=r,t[87]=s,t[88]=n,t[89]=c,t[90]=E,t[91]=Me,t[92]=o,t[93]=a,t[94]=i,t[95]=R,t[96]=w,t[97]=F,t[98]=Ne,t[99]=Pe,t[100]=Fe,t[101]=Ie,t[102]=Le,t[103]=Re,t[104]=ze,t[105]=Be,t[106]=Ve,t[107]=He,t[108]=Ue,t[109]=We,t[110]=Ge,t[111]=Ke,t[112]=qe,t[113]=Je,t[114]=Ye,t[115]=Xe,t[116]=Ze}else Ne=t[98],Pe=t[99],Fe=t[100],Ie=t[101],Le=t[102],Re=t[103],ze=t[104],Be=t[105],Ve=t[106],He=t[107],Ue=t[108],We=t[109],Ge=t[110],Ke=t[111],qe=t[112],Je=t[113],Ye=t[114],Xe=t[115],Ze=t[116];let Qe;t[134]!==Fe||t[135]!==Ie?(Qe=(0,Y.jsx)(`div`,{className:Fe,children:Ie}),t[134]=Fe,t[135]=Ie,t[136]=Qe):Qe=t[136];let $e;t[137]!==Ne||t[138]!==Le||t[139]!==Re||t[140]!==ze||t[141]!==Be||t[142]!==Ve||t[143]!==Qe?($e=(0,Y.jsx)(Ne,{useScrollShadow:Le,disableHorizontal:Re,preventOverscroll:ze,outerClassName:Be,className:Ve,children:Qe}),t[137]=Ne,t[138]=Le,t[139]=Re,t[140]=ze,t[141]=Be,t[142]=Ve,t[143]=Qe,t[144]=$e):$e=t[144];let et;t[145]!==He||t[146]!==Ue||t[147]!==$e?(et=(0,Y.jsxs)(`div`,{className:He,children:[Ue,$e]}),t[145]=He,t[146]=Ue,t[147]=$e,t[148]=et):et=t[148];let tt;return t[149]!==Pe||t[150]!==We||t[151]!==Ge||t[152]!==Ke||t[153]!==qe||t[154]!==Je||t[155]!==Ye||t[156]!==Xe||t[157]!==Ze||t[158]!==et?(tt=(0,Y.jsx)(Pe,{id:We,open:Ge,onOpenChange:Ke,leading:qe,ariaLabel:Je,closeAriaLabel:Ye,resizeAriaLabel:Xe,bodyClassName:Ze,children:et}),t[149]=Pe,t[150]=We,t[151]=Ge,t[152]=Ke,t[153]=qe,t[154]=Je,t[155]=Ye,t[156]=Xe,t[157]=Ze,t[158]=et,t[159]=tt):tt=t[159],tt};function _n(e){let[t,n]=e;return[t,new Set(n)]}function vn(e){return`${e.providerID}:${e.modelID}`}function yn(e){return[e.id,e]}function bn(e,t){return[e,t]}function xn(e){return e.models.length>0}function Sn(e){xt(e)||(e.preventDefault(),e.stopPropagation())}function Cn(e){e.currentTarget.focus({preventScroll:!0})}var wn=e=>{let t=(0,X.c)(217),{providerId:r,modelId:i,variant:a,onChange:o,className:s,allowedProviderIds:c,allowedModelIdsByProvider:l,placeholder:u,tooltipsEnabled:d,dropdownPortalToBody:f,showIcon:p,providers:m}=e,h=d===void 0||d,g=f!==void 0&&f,_=p===void 0||p,{t:v}=ee(),{isReady:y,isUnavailable:b}=tn(),x=L(Tn),S=m??x,C=L(En),w=n(Dn),T=n(On),E=n(kn),D=n(An),O=n(jn),k=n(Mn),A;t[0]!==i||t[1]!==r?(A={currentProviderID:r,currentModelID:i},t[0]=i,t[1]=r,t[2]=A):A=t[2];let{favoriteModelsList:j,recentModelsList:M}=G(A),{isMobile:N}=ue(),P=w||N,[F,te]=J.useState(!1),[ne,re]=J.useState(!1),ie;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(ie=()=>{te(!0),L.getState().refreshCatalogsOnPickerOpen({source:`modelSelector:mobilePanel`})},t[3]=ie):ie=t[3];let ae=I(ie),R;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(R=e=>{re(e),e&&L.getState().refreshCatalogsOnPickerOpen({source:`modelSelector:desktopMenu`})},t[4]=R):R=t[4];let z=I(R),[H,oe]=J.useState(``),[W,K]=J.useState(null),q=a!==void 0,ce;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(ce=()=>{te(!1),re(!1),oe(``),K(null)},t[5]=ce):ce=t[5];let le=ce,de;t[6]===S?de=t[7]:(de=e=>{let t=S.find(t=>t.id===e.providerID)?.models?.find(t=>t.id===e.modelID);return t?.variants?Object.keys(t.variants):[]},t[6]=S,t[7]=de);let fe=de,pe;t[8]!==O||t[9]!==fe||t[10]!==i||t[11]!==o||t[12]!==r||t[13]!==a||t[14]!==q?(pe=e=>{let t=fe(e),n=e.providerID===r&&e.modelID===i,s=e.variant!==void 0&&t.includes(e.variant)?e.variant:void 0,c=n&&a&&t.includes(a)?a:s??``;o(e.providerID,e.modelID,q?c:void 0),O(e.providerID,e.modelID,q&&c||void 0),le()},t[8]=O,t[9]=fe,t[10]=i,t[11]=o,t[12]=r,t[13]=a,t[14]=q,t[15]=pe):pe=t[15];let me=pe,he;t[16]!==o||t[17]!==q?(he=()=>{o(``,``,q?``:void 0),le()},t[16]=o,t[17]=q,t[18]=he):he=t[18];let ge=he,Z;t[19]!==O||t[20]!==o||t[21]!==W?(Z=e=>{W&&(o(W.providerID,W.modelID,e),O(W.providerID,W.modelID,e||void 0),le())},t[19]=O,t[20]=o,t[21]=W,t[22]=Z):Z=t[22];let _e=Z,Q;t[23]===v?Q=t[24]:(Q=v(`settings.agents.modelSelector.searchPlaceholder`),t[23]=v,t[24]=Q);let ve;t[25]===v?ve=t[26]:(ve=v(`settings.agents.modelSelector.state.noModelsFound`),t[25]=v,t[26]=ve);let ye;t[27]===v?ye=t[28]:(ye=v(`settings.agents.modelSelector.section.favorites`),t[27]=v,t[28]=ye);let be;t[29]===v?be=t[30]:(be=v(`settings.agents.modelSelector.section.recent`),t[29]=v,t[30]=be);let xe;t[31]===v?xe=t[32]:(xe=v(`settings.agents.modelSelector.keyboardHints`),t[31]=v,t[32]=xe);let Se;t[33]!==u||t[34]!==v?(Se=u||v(`settings.agents.modelSelector.notSelected`),t[33]=u,t[34]=v,t[35]=Se):Se=t[35];let Ce;t[36]===v?Ce=t[37]:(Ce=v(`settings.agents.modelSelector.actions.favorite`),t[36]=v,t[37]=Ce);let $;t[38]===v?$=t[39]:($=v(`settings.agents.modelSelector.actions.unfavorite`),t[38]=v,t[39]=$);let we;t[40]===v?we=t[41]:(we=v(`chat.modelControls.provider`),t[40]=v,t[41]=we);let Te;t[42]===v?Te=t[43]:(Te=v(`chat.modelControls.capabilities`),t[42]=v,t[43]=Te);let Ee;t[44]===v?Ee=t[45]:(Ee=v(`chat.modelControls.capability.toolCalling`),t[44]=v,t[45]=Ee);let De;t[46]===v?De=t[47]:(De=v(`chat.modelControls.capability.reasoning`),t[46]=v,t[47]=De);let Oe;t[48]===v?Oe=t[49]:(Oe=v(`chat.modelControls.modality.image`),t[48]=v,t[49]=Oe);let ke;t[50]===v?ke=t[51]:(ke=v(`chat.modelControls.modality.video`),t[50]=v,t[51]=ke);let Ae;t[52]===v?Ae=t[53]:(Ae=v(`chat.modelControls.modality.audio`),t[52]=v,t[53]=Ae);let je;t[54]===v?je=t[55]:(je=v(`chat.modelControls.costPerMillion`),t[54]=v,t[55]=je);let Me;t[56]===v?Me=t[57]:(Me=v(`chat.modelControls.costInput`),t[56]=v,t[57]=Me);let Ne;t[58]===v?Ne=t[59]:(Ne=v(`chat.modelControls.costOutput`),t[58]=v,t[59]=Ne);let Pe;t[60]!==Q||t[61]!==ve||t[62]!==ye||t[63]!==be||t[64]!==xe||t[65]!==Se||t[66]!==Ce||t[67]!==$||t[68]!==we||t[69]!==Te||t[70]!==Ee||t[71]!==De||t[72]!==Oe||t[73]!==ke||t[74]!==Ae||t[75]!==je||t[76]!==Me||t[77]!==Ne?(Pe={searchPlaceholder:Q,noResults:ve,favorites:ye,recent:be,keyboardHint:xe,notSelected:Se,favorite:Ce,unfavorite:$,provider:we,capabilities:Te,capabilityToolCalling:Ee,capabilityReasoning:De,modalityImage:Oe,modalityVideo:ke,modalityAudio:Ae,costPerMillion:je,costInput:Me,costOutput:Ne},t[60]=Q,t[61]=ve,t[62]=ye,t[63]=be,t[64]=xe,t[65]=Se,t[66]=Ce,t[67]=$,t[68]=we,t[69]=Te,t[70]=Ee,t[71]=De,t[72]=Oe,t[73]=ke,t[74]=Ae,t[75]=je,t[76]=Me,t[77]=Ne,t[78]=Pe):Pe=t[78];let Fe=Pe,Ie;t[79]!==i||t[80]!==r?(Ie=r&&i?{providerID:r,modelID:i}:null,t[79]=i,t[80]=r,t[81]=Ie):Ie=t[81];let Le=Ie,Re;t[82]!==i||t[83]!==u||t[84]!==r||t[85]!==v?(Re=r&&i?`${r}/${i}`:u||v(`settings.agents.modelSelector.notSelected`),t[82]=i,t[83]=u,t[84]=r,t[85]=v,t[86]=Re):Re=t[86];let ze=Re,Be;t[87]!==v||t[88]!==a||t[89]!==q?(Be=q?a||v(`chat.modelControls.default`):null,t[87]=v,t[88]=a,t[89]=q,t[90]=Be):Be=t[90];let Ve=Be,He;t[91]!==i||t[92]!==r||t[93]!==a||t[94]!==q?(He=(e,t)=>{if(!(!q||e!==r||t!==i))return a||void 0},t[91]=i,t[92]=r,t[93]=a,t[94]=q,t[95]=He):He=t[95];let Ue=He,We;t[96]!==O||t[97]!==o||t[98]!==q?(We=(e,t,n)=>{o(e,t,q?n??``:void 0),O(e,t,q&&n||void 0),le()},t[96]=O,t[97]=o,t[98]=q,t[99]=We):We=t[99];let Je=We,Ye;t[100]!==fe||t[101]!==v||t[102]!==a||t[103]!==q?(Ye=(e,t)=>{let n=fe(e);if(!q||n.length===0)return null;let r=e.variant!==void 0&&n.includes(e.variant)?e.variant:void 0,i=t.isSelected?a:r??``;return(0,Y.jsxs)(`button`,{type:`button`,className:`flex min-h-9 shrink-0 items-center gap-0.5 rounded-md px-1.5 typography-micro font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,onClick:t=>{t.preventDefault(),t.stopPropagation(),K(e)},"aria-label":v(`chat.modelControls.showThinkingModes`),children:[(0,Y.jsx)(`span`,{className:`max-w-24 truncate`,children:i||v(`chat.modelControls.default`)}),(0,Y.jsx)(V,{name:`arrow-right-s`,className:`size-3.5`})]})},t[100]=fe,t[101]=v,t[102]=a,t[103]=q,t[104]=Ye):Ye=t[104];let Xe=Ye,Ze=P?`max-h-none flex-1`:void 0,Qe=h&&(P?F:ne),$e;t[105]===D?$e=t[106]:($e=e=>D(e.providerID,e.modelID),t[105]=D,t[106]=$e);let et;t[107]!==i||t[108]!==r||t[109]!==E||t[110]!==a?(et=e=>E(e.providerID,e.modelID,e.providerID===r&&e.modelID===i?a||void 0:e.variant),t[107]=i,t[108]=r,t[109]=E,t[110]=a,t[111]=et):et=t[111];let tt;t[112]!==l||t[113]!==c||t[114]!==j||t[115]!==C||t[116]!==me||t[117]!==ge||t[118]!==T||t[119]!==Fe||t[120]!==k||t[121]!==S||t[122]!==M||t[123]!==Xe||t[124]!==H||t[125]!==Le||t[126]!==Ze||t[127]!==Qe||t[128]!==$e||t[129]!==et?(tt=(0,Y.jsx)(U,{providers:S,providerOrder:k,favoriteModels:j,recentModels:M,getMetadata:C,searchQuery:H,onSearchQueryChange:oe,onSelect:me,labels:Fe,selectedModel:Le,hiddenModels:T,allowedProviderIds:c,allowedModelIdsByProvider:l,includeNotSelected:!0,onSelectNone:ge,onEscape:le,maxHeightClassName:Ze,tooltipsEnabled:Qe,isFavorite:$e,onToggleFavorite:et,renderRowEnd:Xe}),t[112]=l,t[113]=c,t[114]=j,t[115]=C,t[116]=me,t[117]=ge,t[118]=T,t[119]=Fe,t[120]=k,t[121]=S,t[122]=M,t[123]=Xe,t[124]=H,t[125]=Le,t[126]=Ze,t[127]=Qe,t[128]=$e,t[129]=et,t[130]=tt):tt=t[130];let nt=tt,rt;t[131]!==fe||t[132]!==W?(rt=W?fe(W):[],t[131]=fe,t[132]=W,t[133]=rt):rt=t[133];let it=rt,at;bb0:{if(!W){at=``;break bb0}if(W.providerID===r&&W.modelID===i){at=a||``;break bb0}at=W.variant!==void 0&&it.includes(W.variant)?W.variant:``}let ot=at,st;t[134]!==_e||t[135]!==v||t[136]!==W||t[137]!==ot||t[138]!==it?(st=W?(0,Y.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`flex min-h-11 items-center gap-2 border-b border-border/40 px-3 text-left typography-ui-label font-medium text-foreground hover:bg-interactive-hover`,onClick:()=>K(null),"aria-label":v(`header.actions.backAria`),children:[(0,Y.jsx)(V,{name:`arrow-left`,className:`size-4`}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:W.modelID})]}),(0,Y.jsx)(`div`,{className:`space-y-1 p-2`,role:`listbox`,"aria-label":v(`chat.modelControls.thinking`),children:[``,...it].map(e=>{let t=ot===e;return(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,className:B(`flex min-h-11 w-full items-center justify-between rounded-lg px-3 text-left typography-ui-label transition-colors`,t?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),onClick:()=>_e(e),children:[(0,Y.jsx)(`span`,{className:`truncate`,children:e||v(`chat.modelControls.default`)}),t?(0,Y.jsx)(V,{name:`check`,className:`size-4 shrink-0`}):null]},e||`__default`)})})]}):null,t[134]=_e,t[135]=v,t[136]=W,t[137]=ot,t[138]=it,t[139]=st):st=t[139];let ct=st||nt;if(P){let e=y?ae:void 0,n=!y,o=!y&&`opacity-60 cursor-not-allowed`,u;t[140]!==s||t[141]!==o?(u=B(`flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left`,o,s),t[140]=s,t[141]=o,t[142]=u):u=t[142];let d;t[143]!==y||t[144]!==b||t[145]!==i||t[146]!==r||t[147]!==_||t[148]!==v?(d=y?_&&(r||i)?(0,Y.jsx)(se,{modelId:i,providerId:r,className:`h-3.5 w-3.5 flex-shrink-0`}):_?(0,Y.jsx)(V,{name:`pencil-ai`,className:`h-3 w-3 text-muted-foreground`}):null:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(V,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:v(b?`common.unavailable`:`common.loading`)})]}),t[143]=y,t[144]=b,t[145]=i,t[146]=r,t[147]=_,t[148]=v,t[149]=d):d=t[149];let f;t[150]!==y||t[151]!==ze?(f=y?(0,Y.jsx)(`span`,{className:`typography-meta font-medium text-foreground truncate`,children:ze}):null,t[150]=y,t[151]=ze,t[152]=f):f=t[152];let p;t[153]!==y||t[154]!==Ve?(p=y&&Ve?(0,Y.jsx)(`span`,{className:`shrink-0 typography-micro text-muted-foreground`,children:Ve}):null,t[153]=y,t[154]=Ve,t[155]=p):p=t[155];let m;t[156]!==d||t[157]!==f||t[158]!==p?(m=(0,Y.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[d,f,p]}),t[156]=d,t[157]=f,t[158]=p,t[159]=m):m=t[159];let h;t[160]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Y.jsx)(V,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0 text-muted-foreground`}),t[160]=h):h=t[160];let g;t[161]!==e||t[162]!==n||t[163]!==u||t[164]!==m?(g=(0,Y.jsxs)(`button`,{type:`button`,onClick:e,disabled:n,className:u,children:[m,h]}),t[161]=e,t[162]=n,t[163]=u,t[164]=m,t[165]=g):g=t[165];let x;t[166]!==j||t[167]!==i||t[168]!==r||t[169]!==M||t[170]!==E||t[171]!==a?(x=(e,t)=>E(e,t,e===r&&t===i?a||void 0:j.find(n=>n.providerID===e&&n.modelID===t)?.variant??M.find(n=>n.providerID===e&&n.modelID===t)?.variant),t[166]=j,t[167]=i,t[168]=r,t[169]=M,t[170]=E,t[171]=a,t[172]=x):x=t[172];let w;t[173]!==l||t[174]!==c||t[175]!==j||t[176]!==C||t[177]!==Je||t[178]!==T||t[179]!==D||t[180]!==F||t[181]!==i||t[182]!==r||t[183]!==k||t[184]!==S||t[185]!==M||t[186]!==Ue||t[187]!==x||t[188]!==q?(w=(0,Y.jsx)(gn,{open:F,onClose:le,selectedProviderID:r,selectedModelID:i,resolveSelectedVariant:Ue,onSelect:Je,providers:S,favoriteModels:j,recentModels:M,getMetadata:C,hiddenModels:T,allowedProviderIds:c,allowedModelIdsByProvider:l,providerOrder:k,variantSelectionEnabled:q,isFavorite:D,onToggleFavorite:x}),t[173]=l,t[174]=c,t[175]=j,t[176]=C,t[177]=Je,t[178]=T,t[179]=D,t[180]=F,t[181]=i,t[182]=r,t[183]=k,t[184]=S,t[185]=M,t[186]=Ue,t[187]=x,t[188]=q,t[189]=w):w=t[189];let O;return t[190]!==g||t[191]!==w?(O=(0,Y.jsxs)(Y.Fragment,{children:[g,w]}),t[190]=g,t[191]=w,t[192]=O):O=t[192],O}let lt=y&&ne,ut=y?z:void 0,dt=!y&&`opacity-60 cursor-not-allowed`,ft;t[193]!==s||t[194]!==dt?(ft=B(`border-input data-[placeholder]:text-muted-foreground flex min-w-0 items-center justify-between gap-2 rounded-lg border bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover data-[popup-open]:bg-interactive-active h-6 w-fit`,dt,s),t[193]=s,t[194]=dt,t[195]=ft):ft=t[195];let pt;t[196]!==y||t[197]!==b||t[198]!==i||t[199]!==r||t[200]!==_||t[201]!==v||t[202]!==ze||t[203]!==Ve?(pt=y?(0,Y.jsxs)(Y.Fragment,{children:[_?r||i?(0,Y.jsx)(se,{modelId:i,providerId:r,className:`h-3.5 w-3.5 flex-shrink-0`}):(0,Y.jsx)(V,{name:`pencil-ai`,className:`h-3.5 w-3.5 flex-shrink-0 text-muted-foreground`}):null,(0,Y.jsx)(`span`,{className:`typography-ui-label min-w-0 flex-1 truncate text-left font-normal text-foreground`,children:ze}),Ve?(0,Y.jsx)(`span`,{className:`shrink-0 typography-micro text-muted-foreground`,children:Ve}):null]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(V,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`typography-ui-label font-normal whitespace-nowrap text-muted-foreground`,children:v(b?`common.unavailable`:`common.loading`)})]}),t[196]=y,t[197]=b,t[198]=i,t[199]=r,t[200]=_,t[201]=v,t[202]=ze,t[203]=Ve,t[204]=pt):pt=t[204];let mt;t[205]===Symbol.for(`react.memo_cache_sentinel`)?(mt=(0,Y.jsx)(V,{name:`arrow-down-s`,className:`h-4 w-4 flex-shrink-0 text-muted-foreground/50`}),t[205]=mt):mt=t[205];let ht;t[206]!==ft||t[207]!==pt?(ht=(0,Y.jsx)(Ke,{asChild:!0,children:(0,Y.jsxs)(`div`,{className:ft,children:[pt,mt]})}),t[206]=ft,t[207]=pt,t[208]=ht):ht=t[208];let gt;t[209]!==g||t[210]!==ct?(gt=(0,Y.jsx)(qe,{className:`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,align:`start`,portalToBody:g,children:ct}),t[209]=g,t[210]=ct,t[211]=gt):gt=t[211];let _t;return t[212]!==lt||t[213]!==ut||t[214]!==ht||t[215]!==gt?(_t=(0,Y.jsxs)(Ge,{open:lt,onOpenChange:ut,children:[ht,gt]}),t[212]=lt,t[213]=ut,t[214]=ht,t[215]=gt,t[216]=_t):_t=t[216],_t};function Tn(e){return e.providers}function En(e){return e.getModelMetadata}function Dn(e){return e.isMobile}function On(e){return e.hiddenModels}function kn(e){return e.toggleFavoriteModel}function An(e){return e.isFavoriteModel}function jn(e){return e.addRecentModel}function Mn(e){return e.providerOrder}var Nn=e=>e??s()?.github,Pn=(e=t())=>i.github.auth(e),Fn=async(e,t)=>{if(e)return e.authStatus();let n=await a(`/api/github/auth/status`,{method:`GET`,headers:{Accept:`application/json`},signal:t}),r=await n.json().catch(()=>null);if(!n.ok||!r)throw Error(r?.error||n.statusText||`Failed to load GitHub status`);return r},In=(e,n=t())=>{let r=Nn(e);return{queryKey:Pn(n),queryFn:async({signal:e})=>Fn(r,e),retry:2}},Ln=e=>!!e&&typeof e==`object`&&`authStatus`in e,Rn=e=>{let t=(0,X.c)(5),n=Ln(e)?e:void 0,r=Ln(e)?void 0:e?.enabled,i;t[0]===n?i=t[1]:(i=In(n),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a={...i,enabled:r},t[2]=r,t[3]=i,t[4]=a):a=t[4],S(a)},zn=(e=o,n=t())=>e.getQueryData(Pn(n))??null,Bn=async(e,n,r)=>t()===r?e.fetchQuery({...In(n,r),staleTime:0}):e.getQueryData(Pn(r))??null,Vn=(e=o,n,r=t())=>{e.setQueryData(Pn(r),n)},Hn=E.define(F),Un=M.data.of({commentTokens:{line:`//`,block:{open:`/*`,close:`*/`}}});function Wn(e){let t=e.trim().toLowerCase();switch(t){case`bash`:case`sh`:case`zsh`:case`shell`:case`shellsession`:case`console`:return Hn;case`json`:case`jsonc`:case`json5`:return j().language;case`js`:case`javascript`:return k().language;case`jsx`:return k({jsx:!0}).language;case`ts`:case`typescript`:return k({typescript:!0}).language;case`tsx`:return k({typescript:!0,jsx:!0}).language;case`html`:return A().language;case`css`:return O().language;case`py`:case`python`:return P().language;case`md`:case`markdown`:case`mdown`:case`mkd`:return N().language;case`heex`:case`eex`:case`leex`:return A().language;default:return D.matchLanguageName(de,t,!0)}}var Gn=e=>e.split(`/`).pop()?.toLowerCase()??``,Kn=e=>{let t=Gn(e);return t?D.matchFilename(de,t):null},qn=()=>C(T.define([{tag:[w.heading1,w.heading2,w.heading3,w.heading4,w.heading5,w.heading6],fontWeight:`600`},{tag:w.strong,fontWeight:`600`},{tag:w.emphasis,fontStyle:`italic`},{tag:w.strikethrough,textDecoration:`line-through`},{tag:[w.link,w.url],color:`var(--markdown-link, currentColor)`,textDecoration:`underline`},{tag:w.monospace,color:`var(--markdown-inline-code, currentColor)`,backgroundColor:`var(--markdown-inline-code-bg, transparent)`},{tag:w.quote,color:`var(--markdown-blockquote, currentColor)`,fontStyle:`italic`},{tag:w.list,color:`color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)`},{tag:w.heading,color:`var(--markdown-heading1, currentColor)`}]));function Jn(e){let t=e.toLowerCase();switch(Gn(t)){case`makefile`:case`gnumakefile`:return Hn}let n=t.lastIndexOf(`.`),r=n>=0?t.slice(n+1):``;switch(r){case`ts`:case`tsx`:case`mts`:case`cts`:return k({typescript:!0,jsx:r===`tsx`});case`js`:case`jsx`:case`mjs`:case`cjs`:return k({typescript:!1,jsx:r===`jsx`});case`jsonc`:case`json5`:return[j(),Un];case`json`:case`jsonl`:case`ndjson`:case`geojson`:return j();case`css`:case`scss`:case`sass`:case`less`:return O();case`html`:case`htm`:case`xml`:case`drawio`:case`dio`:return A();case`md`:case`mdx`:case`markdown`:case`mdown`:case`mkd`:return[N({codeLanguages:Wn}),qn()];case`sh`:case`bash`:case`zsh`:case`fish`:case`env`:return Hn;case`py`:case`pyw`:case`pyi`:return P();default:return null}}async function Yn(e){let t=Kn(e);if(!t)return null;if(t.support)return t.support;try{return await t.load()}catch{return null}}var Xn=60,Zn=400;function Qn(e){let t=e.replace(/\s+/g,` `).trim();if(!t)return[];let n=t.match(/[^.!?…]+[.!?…]+["')\]]*\s*|[^.!?…]+$/g)??[t],r=[],i=``;for(let e of n)for(let t=0;t<e.length;t+=Zn){let n=e.slice(t,t+Zn);i&&i.length+n.length>Zn&&(r.push(i.trim()),i=``),i+=n,i.length>=Xn&&/[.!?…]["')\]]*\s*$/.test(i)&&(r.push(i.trim()),i=``)}if(i.trim()&&r.push(i.trim()),r.length>0&&r[0].length>120){let e=r[0],t=/[,;:]\s/g,n=-1,i;for(;(i=t.exec(e))!==null;){let e=i.index+1;if(!(e<40)){if(e>160)break;n=e;break}}if(n>0){let t=e.slice(0,n).trim(),i=e.slice(n).trim();r.splice(0,1,t,i)}}return r}var $n=null;function er(){return $n||=new(window.AudioContext||window.webkitAudioContext),$n}function tr(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(null),i=(0,J.useRef)(null),o=(0,J.useRef)(null),s=(0,J.useCallback)(async()=>{try{let e=er();e.state===`suspended`&&await e.resume();let t=e.createBuffer(1,1,22050),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0)}catch{}},[]),c=(0,J.useCallback)(()=>{let e=o.current;if(e&&(e.cancelled=!0,e.abort.abort(),o.current=null),i.current){try{i.current.onended=null,i.current.stop()}catch{}i.current=null}t(!1)},[]),l=(0,J.useCallback)(async(e,n)=>{c();let s=Qn(e);if(s.length===0){r(`No text to speak`),n?.onError?.(`No text to speak`);return}r(null);let l={cancelled:!1,abort:new AbortController};o.current=l;let u=async e=>{let t=await a(`/api/dictation/tts/speak`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e,...typeof n?.speakerId==`number`?{speakerId:n.speakerId}:{},...typeof n?.speed==`number`?{speed:n.speed}:{}}),signal:l.abort.signal});if(!t.ok){let e=await t.json().catch(()=>({error:`Unknown error`}));throw Error(e.error||`HTTP ${t.status}`)}return(await t.blob()).arrayBuffer()},d=async e=>{let t=er();t.state===`suspended`&&await t.resume();let n=await t.decodeAudioData(e);l.cancelled||await new Promise(e=>{let r=t.createBufferSource();r.buffer=n,r.connect(t.destination),i.current=r,r.onended=()=>{i.current===r&&(i.current=null),e()},r.start(0)})};try{t(!0),n?.onStart?.();let e=u(s[0]);for(let t=0;t<s.length;t+=1){let n=await e;if(l.cancelled||(t+1<s.length&&(e=u(s[t+1])),await d(n),l.cancelled))return}t(!1),n?.onEnd?.()}catch(e){if(e.name===`AbortError`||l.cancelled)return;let i=e instanceof Error?e.message:`Failed to speak`;r(i),n?.onError?.(i),t(!1)}finally{o.current===l&&(o.current=null)}},[c]);return(0,J.useEffect)(()=>()=>{c()},[c]),{isPlaying:e,error:n,speak:l,stop:c,unlockAudio:s}}var nr=new class{recognition=null;isListening=!1;currentLang=`en-US`;onResultCallback=null;onErrorCallback=null;restartOnEnd=!1;conversationMode=!1;isSpeaking=!1;audioContext=null;audioUnlockRequired=!1;isSupported(){let e=`SpeechRecognition`in window||`webkitSpeechRecognition`in window,t=`speechSynthesis`in window;return e&&t}getSupportDetails(){return{recognition:`SpeechRecognition`in window||`webkitSpeechRecognition`in window,synthesis:`speechSynthesis`in window,prefixed:!(`SpeechRecognition`in window)&&`webkitSpeechRecognition`in window,secureContext:window.isSecureContext}}setConversationMode(e){this.conversationMode=e,e||(this.restartOnEnd=!1)}isConversationMode(){return this.conversationMode}pauseListening(){if(this.restartOnEnd=!1,this.recognition)try{this.recognition.stop()}catch{}this.isListening=!1}resumeListening(){if(this.conversationMode,this.onResultCallback,this.isSpeaking,this.currentLang,this.conversationMode&&this.onResultCallback&&!this.isSpeaking)try{this.startListeningSync(this.currentLang,this.onResultCallback,this.onErrorCallback||void 0)}catch(e){console.error(`[BrowserVoiceService] Failed to resume listening:`,e)}}async checkMicrophonePermission(){try{return`permissions`in navigator&&(await navigator.permissions.query({name:`microphone`})).state===`granted`}catch{return!1}}async prepareListening(){if(!this.isSupported())throw Error(`Web Speech API not supported in this browser`);if(typeof navigator>`u`||typeof navigator.mediaDevices?.getUserMedia!=`function`)return!0;try{return(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),!0}catch(e){let t=typeof e==`object`&&e&&`name`in e?String(e.name):``;if(t===`NotAllowedError`)throw Error(`Microphone permission denied`);if(t===`NotFoundError`)throw Error(`No microphone found`);let n=e instanceof Error?e.message:`Unable to access microphone`;throw Error(n)}}startListeningSync(e,t,n){if(!this.isSupported()){let e=`Web Speech API not supported in this browser`;throw n?.(e),Error(e)}this.stopListening();let r=window.SpeechRecognition||window.webkitSpeechRecognition;if(!r){let e=`Web Speech API not supported in this browser`;throw n?.(e),Error(e)}let i=new r;this.recognition=i,this.currentLang=e,this.onResultCallback=t,this.onErrorCallback=n||null,i.continuous=!0,i.interimResults=!0,i.lang=e,i.onstart=()=>{this.isListening=!0,this.restartOnEnd=!0},i.onaudiostart=()=>{},i.onsoundstart=()=>{},i.onresult=e=>{e.results.length;let t=``,n=``;for(let r=e.resultIndex;r<e.results.length;r++){let i=e.results[r];i.isFinal?t+=i[0].transcript:n+=i[0].transcript}n&&this.onResultCallback?.(n,!1),t&&this.onResultCallback?.(t,!0)},i.onerror=e=>{if(e.error===`aborted`)return;let t=this.getErrorMessage(e.error);this.onErrorCallback?.(t),(e.error===`not-allowed`||e.error===`service-not-allowed`||e.error===`network`)&&(this.restartOnEnd=!1,this.isListening=!1)},i.onend=()=>{if(this.isListening=!1,this.restartOnEnd&&this.recognition&&!this.isSpeaking)try{this.recognition.start()}catch{}};try{i.start()}catch(e){let t=e instanceof Error?e.message:`Failed to start speech recognition`;throw n?.(t),Error(t)}}async startListening(e,t,n){this.startListeningSync(e,t,n)}stopListening(){if(this.restartOnEnd=!1,this.recognition){try{this.recognition.stop()}catch{}this.recognition=null}this.isListening=!1}getIsListening(){return this.isListening}getCurrentLang(){return this.currentLang}async resumeAudioContext(){this.audioContext||=new(window.AudioContext||window.webkitAudioContext),this.audioContext.state===`suspended`&&await this.audioContext.resume()}isAudioUnlockRequired(){return this.audioUnlockRequired}async unlockAudio(){try{let e=new Audio;if(e.src=`data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA`,e.volume=.01,await e.play(),await this.resumeAudioContext(),this.isMobileDevice()&&`speechSynthesis`in window){let e=new SpeechSynthesisUtterance(``);e.volume=0,window.speechSynthesis.speak(e),window.speechSynthesis.cancel()}return this.audioUnlockRequired=!1,!0}catch(e){return console.error(`[BrowserVoiceService] Failed to unlock audio:`,e),!1}}async speakText(e,t,n,r){if(!(`speechSynthesis`in window))throw Error(`Speech synthesis not supported`);await this.resumeAudioContext();let i=await this.waitForVoices();await new Promise(e=>setTimeout(e,50)),this.isSpeaking=!0,this.pauseListening(),window.speechSynthesis.cancel();let a=new SpeechSynthesisUtterance(e);a.lang=t,a.rate=r?.rate??1,a.pitch=r?.pitch??1,a.volume=r?.volume??1;let o=null;return r?.voiceName&&(o=i.find(e=>e.name===r.voiceName)||null,o?`${o.name}${o.lang}`:console.warn(`[BrowserVoiceService] Selected voice "${r.voiceName}" not found, falling back to language match`)),o||(o=this.findBestVoice(i,t),o?`${o.name}${o.lang}`:console.warn(`[BrowserVoiceService] No voice found for language: ${t}, using default`)),o&&(a.voice=o),`${e.length}${t}`,new Promise((e,t)=>{let r=!1;a.onstart=()=>{r=!0,e()},a.onend=()=>{this.isSpeaking=!1,n?.()},a.onerror=e=>{this.isSpeaking=!1,console.error(`[BrowserVoiceService] Speech synthesis error:`,e.error),(e.error===`not-allowed`||e.error===`interrupted`)&&(this.audioUnlockRequired=!0);let n=`Speech synthesis error: ${e.error||`unknown`}`;e.error===`not-allowed`?n=`Audio blocked by browser autoplay policy. Please interact with the page first.`:e.error===`interrupted`&&(n=`Speech was interrupted. Please try again.`),t(Error(n))},setTimeout(()=>{r||(console.warn(`[BrowserVoiceService] Speech start timeout - audio may be blocked`),this.audioUnlockRequired=!0)},2e3),window.speechSynthesis.speak(a)})}cancelSpeech(){`speechSynthesis`in window&&window.speechSynthesis.cancel()}getVoices(){return`speechSynthesis`in window?window.speechSynthesis.getVoices():[]}async waitForVoices(){if(!(`speechSynthesis`in window))return[];let e=window.speechSynthesis.getVoices();return e.length>0?e:new Promise(e=>{let t=()=>{e(window.speechSynthesis.getVoices()),window.speechSynthesis.onvoiceschanged=null};window.speechSynthesis.onvoiceschanged=t,setTimeout(()=>{e(window.speechSynthesis.getVoices()),window.speechSynthesis.onvoiceschanged=null},1e3)})}findBestVoice(e,t){let n=e.find(e=>e.lang===t);if(!n){let r=t.split(`-`)[0];n=e.find(e=>e.lang.startsWith(r))}return n||=e.find(e=>e.lang.startsWith(t.split(`-`)[0])&&e.localService),n||null}isMobileDevice(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return/iphone|ipad|ipod|android|mobile|webos|blackberry|iemobile|opera mini/i.test(e)}isIOSSafari(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase(),t=/iphone|ipad|ipod/i.test(e),n=/safari/i.test(e)&&!/chrome|crios|crmo/i.test(e);return t&&n}getErrorMessage(e){let t=this.isMobileDevice(),n=this.isIOSSafari();return{"no-speech":`No speech detected`,aborted:`Speech recognition aborted`,"audio-capture":`No microphone found`,network:`Network error - check connection`,"not-allowed":t?`Microphone permission denied. Check Settings > Safari > Microphone`:`Microphone permission denied`,"service-not-allowed":n?`Speech recognition requires a user gesture. Please tap the microphone button again.`:`Speech recognition service not allowed`,"bad-grammar":`Grammar error`,"language-not-supported":`Language not supported`}[e]||`Speech recognition error: ${e}`}},rr=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},ir=(e,t,n={})=>{let r=e instanceof Date?e:new Date(e);return Number.isFinite(r.getTime())?r.toLocaleTimeString(te(),{hour:n.hour??`numeric`,minute:`2-digit`,second:n.precision===`second`?`2-digit`:void 0,hour12:rr(t)}):n.fallback??``},ar=(e,t,n)=>{let r=e instanceof Date?e:new Date(e);return Number.isFinite(r.getTime())?r.toLocaleString(te(),{...n,hour12:n.hour?rr(t):n.hour12}):``},or=J.memo(function(e){let t=(0,X.c)(24),{checked:n,onChange:r,disabled:i,ariaLabel:a,className:o,iconClassName:s}=e,c=i!==void 0&&i,l;t[0]!==n||t[1]!==c||t[2]!==r?(l=e=>{e.preventDefault(),e.stopPropagation(),!c&&!n&&r()},t[0]=n,t[1]=c,t[2]=r,t[3]=l):l=t[3];let u=l,d;t[4]!==n||t[5]!==c||t[6]!==r?(d=e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),!c&&!n&&r())},t[4]=n,t[5]=c,t[6]=r,t[7]=d):d=t[7];let f=d,p=n?`bg-[color-mix(in_srgb,var(--primary-base)_80%,transparent)] shadow-none hover:bg-[var(--primary-base)]`:`bg-[var(--surface-muted)] shadow-[inset_0_0_0_1px_var(--interactive-border)] hover:bg-[var(--interactive-hover)]`,m;t[8]!==o||t[9]!==p?(m=B(`group/radio relative flex h-[14px] w-[14px] min-h-[14px] min-w-[14px] shrink-0 self-center items-center justify-center rounded-full outline-none`,`transition-[background-color,box-shadow] duration-200 ease-out`,p,`focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background`,`disabled:cursor-not-allowed disabled:opacity-50`,o),t[8]=o,t[9]=p,t[10]=m):m=t[10];let h=!n&&`opacity-0`,g;t[11]!==s||t[12]!==h?(g=B(`block h-[5px] w-[5px] rounded-full bg-white`,h,s),t[11]=s,t[12]=h,t[13]=g):g=t[13];let _;t[14]===g?_=t[15]:(_=(0,Y.jsx)(`span`,{"aria-hidden":!0,className:g}),t[14]=g,t[15]=_);let v;return t[16]!==a||t[17]!==n||t[18]!==c||t[19]!==u||t[20]!==f||t[21]!==m||t[22]!==_?(v=(0,Y.jsx)(`button`,{type:`button`,role:`radio`,onClick:u,onKeyDown:f,disabled:c,"aria-checked":n,"aria-label":a,className:m,children:_}),t[16]=a,t[17]=n,t[18]=c,t[19]=u,t[20]=f,t[21]=m,t[22]=_,t[23]=v):v=t[23],v});export{he as $,Ze as A,Fe as B,Ct as C,Ge as D,_t as E,ze as F,Ne as G,ke as H,Re as I,Pe as J,Ie as K,Ve as L,Xe as M,Qe as N,qe as O,Ke as P,_e as Q,Be as R,St as S,st as T,je as U,Le as V,Me as W,Ee as X,we as Y,Q as Z,en as _,tr as a,Tt as b,Yn as c,Vn as d,Rn as f,tn as g,sn as h,nr as i,Ye as j,Je as k,zn as l,gn as m,ar as n,Wn as o,wn as p,Ae as q,ir as r,Jn as s,or as t,Bn as u,$t as v,vt as w,Dt as x,Zt as y,ve as z};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-capacitor-app-PzT84wSx.js","assets/rolldown-runtime-C0FnF6B9.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js"])))=>i.map(i=>d[i]);
2
- import{F as e,G as t,H as n,I as r,K as i,N as a,O as o,P as s,U as c,W as l}from"./useUIStore-BJpkPwky.js";import{On as u,et as d,kn as f}from"./persistence-DwXJK4-j.js";import{t as ee}from"./desktopRelayRestore-CxUYRC6v.js";import{$ as te,A as ne,B as re,Ct as ie,D as ae,E as oe,F as se,H as ce,I as le,J as ue,L as de,M as fe,N as pe,P as me,Q as he,R as ge,S as _e,T as ve,U as ye,V as be,W as xe,X as Se,Y as p,Z as Ce,_ as we,_t as Te,a as Ee,at as De,b as Oe,bt as ke,c as Ae,ct as je,d as Me,dt as Ne,et as m,f as h,ft as g,g as _,gt as v,h as y,ht as b,i as Pe,j as Fe,k as Ie,l as Le,lt as Re,m as ze,mt as Be,n as x,nt as Ve,o as He,ot as Ue,p as We,pt as Ge,q as Ke,s as qe,st as Je,t as Ye,tt as Xe,u as Ze,ut as Qe,v as S,vt as $e,x as C,y as et,yt as w}from"./platform-CXJwZIZe.js";import{n as T,o as E}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{a as tt,c as nt,l as rt,n as it,r as at,s as ot,t as st}from"./terminalApi-jfes-HIU.js";import{t as D}from"./types-BuiqMmh_.js";import{n as O,t as k}from"./capgoAdapter-DCowZ2ab.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var ct=e=>{let t=e?.retry;return{maxRetries:t?.maxRetries??3,initialRetryDelay:t?.initialDelayMs??1e3,maxRetryDelay:t?.maxDelayMs??8e3,connectionTimeout:e?.connectionTimeoutMs??1e4}},lt=()=>({async createSession(e){return at(e)},connect(e,t,n){let r=it(e,t.onEvent,t.onError,ct(n));return{close:()=>r()}},async sendInput(e,t){await rt(e,t)},async resize(e){await ot(e.sessionId,e.cols,e.rows)},async close(e){await st(e)},async restartSession(e,t){return nt(e,{cwd:t.cwd??``,cols:t.cols,rows:t.rows})},async forceKill(e){await tt(e)}}),ut=()=>({checkIsGitRepository:Ae,getGitStatus:de,getGitDiff:pe,getGitFileDiff:me,revertGitFile:Ue,stageGitFile:Re,stageGitFiles:Qe,unstageGitFile:b,unstageGitFiles:v,stageGitHunk:Ne,unstageGitHunk:Te,revertGitHunk:Je,isLinkedWorktree:Ke,getGitBranches:fe,deleteGitBranch:et,deleteRemoteBranch:_e,removeRemote:m,generateCommitMessage:oe,generatePullRequestDescription:ae,listGitWorktrees:p,validateGitWorktree:w,createGitWorktree:S,deleteGitWorktree:C,validateWorktreeDirectory:ke,canonicalizeWorktreeState:qe,createGitCommit(e,t,n){return _(e,t,n)},gitPush:ye,gitPull:ce,gitFetch:be,listGitStashes:ue,countGitStashFiles:ze,stashGitChanges:Ge,applyGitStash:He,popGitStash:Ce,dropGitStash:ve,checkoutBranch:Le,createBranch:y,renameBranch:Xe,getGitLog(e,t){return le(e,t)},getCommitFiles:Ie,getCurrentGitIdentity:Fe,hasLocalIdentity:xe,setGitIdentity:je,getGitIdentities:se,createGitIdentity:we,updateGitIdentity:$e,deleteGitIdentity:Oe,getRemotes:re,rebase:te,abortRebase:Ee,continueRebase:We,merge:Se,abortMerge:Pe,continueMerge:h,checkoutCommit:Ze,cherryPick:Me,revertCommit:De,resetToCommit:Ve,stash:g,stashPop:Be,getConflictDetails:ne,worktree:{list:p,validate:w,bootstrapStatus:ge,preview:he,create:S,remove:C}}),A=e=>e.replace(/\\/g,`/`),dt=(e,t)=>({directory:A(t?.directory||t?.path||e),entries:(Array.isArray(t?.entries)?t.entries:[]).filter(e=>!!(e&&typeof e.name==`string`&&typeof e.path==`string`)).map(e=>({name:e.name,path:A(e.path),isDirectory:!!e.isDirectory}))}),j=(e,t)=>{let n=t||e?.();return n?{"x-opencode-directory":n}:void 0},ft=({getDirectory:e})=>({async listDirectory(t,n){let r=A(t),i=new URLSearchParams;r&&i.set(`path`,r),n?.respectGitignore&&i.set(`respectGitignore`,`true`);let a=await f(`/api/fs/list`,{query:i,headers:j(e)});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error||`Failed to list directory`)}return dt(r,await a.json())},async search(t){let n=new URLSearchParams,r=A(t.directory);r&&n.set(`directory`,r),n.set(`query`,t.query),n.set(`dirs`,`false`),n.set(`type`,`file`),typeof t.maxResults==`number`&&Number.isFinite(t.maxResults)&&n.set(`limit`,String(t.maxResults));let i=await f(`/api/find/file`,{query:n,headers:j(e)});if(!i.ok){let e=await i.json().catch(()=>({error:i.statusText}));throw Error(e.error||`Failed to search files`)}let a=await i.json();return(Array.isArray(a)?a:[]).map(e=>({path:A(`${r}/${e}`),preview:[A(e)]}))},async createDirectory(t){let n=A(t),r=await f(`/api/fs/mkdir`,{method:`POST`,headers:{"Content-Type":`application/json`,...j(e)},body:JSON.stringify({path:n})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to create directory`)}let i=await r.json();return{success:!!i?.success,path:typeof i?.path==`string`?A(i.path):n}},async statFile(t,n){let r=A(t),i=new URLSearchParams({path:r});n?.allowOutsideWorkspace&&i.set(`allowOutsideWorkspace`,`true`),n?.outsideFileGrant&&i.set(`outsideFileGrant`,n.outsideFileGrant);let a=await f(`/api/fs/stat`,{query:i,headers:j(e,n?.directory)});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error||`Failed to stat file`)}let o=await a.json().catch(()=>({}));return{path:typeof o.path==`string`?A(o.path):r,isFile:!!o.isFile,size:typeof o.size==`number`?o.size:0,mtimeMs:typeof o.mtimeMs==`number`?o.mtimeMs:void 0,isBinary:typeof o.isBinary==`boolean`?o.isBinary:void 0}},async readFile(t,n){let r=A(t),i=new URLSearchParams({path:r});n?.allowOutsideWorkspace&&i.set(`allowOutsideWorkspace`,`true`),n?.outsideFileGrant&&i.set(`outsideFileGrant`,n.outsideFileGrant),n?.optional&&i.set(`optional`,`true`);let a=await f(`/api/fs/read`,{query:i,cache:n?.optional?`no-store`:`default`,headers:j(e,n?.directory)});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error||`Failed to read file`)}let o=await a.text();if(n?.optional){let e=a.headers.get(`x-openchamber-file-exists`);if(e!==`true`&&e!==`false`)throw Error(`Optional file read requires an existence response header`);return{content:o,path:r,exists:e===`true`}}return{content:o,path:r,exists:!0}},async writeFile(t,n){let r=A(t),i=await f(`/api/fs/write`,{method:`POST`,headers:{"Content-Type":`application/json`,...j(e)},body:JSON.stringify({path:r,content:n})});if(!i.ok){let e=await i.json().catch(()=>({error:i.statusText}));throw Error(e.error||`Failed to write file`)}let a=await i.json().catch(()=>({}));return{success:!!a.success,path:typeof a.path==`string`?A(a.path):r}},async delete(t){let n=A(t),r=await f(`/api/fs/delete`,{method:`POST`,headers:{"Content-Type":`application/json`,...j(e)},body:JSON.stringify({path:n})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to delete file`)}return{success:!!(await r.json().catch(()=>({}))).success}},async rename(t,n){let r=await f(`/api/fs/rename`,{method:`POST`,headers:{"Content-Type":`application/json`,...j(e)},body:JSON.stringify({oldPath:t,newPath:n})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error||`Failed to rename file`)}let i=await r.json().catch(()=>({}));return{success:!!i.success,path:typeof i.path==`string`?A(i.path):n}},async revealPath(t){let n=await f(`/api/fs/reveal`,{method:`POST`,headers:{"Content-Type":`application/json`,...j(e)},body:JSON.stringify({path:A(t)})});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error||`Failed to reveal path`)}return{success:!!(await n.json().catch(()=>({}))).success}},async downloadFile(t){let n=A(t),r=await f(`/api/fs/raw`,{query:{path:n,download:!0},headers:j(e)});if(!r.ok)throw Error(`Download failed (${r.status})`);let i=await r.blob(),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=n.split(`/`).pop()||`file`,document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>URL.revokeObjectURL(a),100)}}),M=`/api/config/settings`,pt=`/api/config/reload`,N=e=>!e||typeof e!=`object`?{}:e,mt=()=>({async load(){let e=await f(M,{method:`GET`,headers:{Accept:`application/json`}});if(!e.ok)throw Error(`Failed to load settings: ${e.statusText}`);return{settings:N(await e.json().catch(()=>({}))),source:`web`}},async save(e){let t=await f(M,{method:`PUT`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)});if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error||`Failed to save settings`)}return N(await t.json().catch(()=>({})))},async restartOpenCode(){let e=await f(pt,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({error:e.statusText}));throw Error(t.error||`Failed to restart OpenCode`)}return{restarted:!0}}}),ht=()=>({async requestDirectoryAccess(e){return{success:!0,path:e.path}},async startAccessingDirectory(e){return{success:!0}},async stopAccessingDirectory(e){return{success:!0}}}),gt=1500,P=5e3,_t=`openchamber-notification-claim:`,F=new Map,vt=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus(),yt=e=>(typeof e?.tag==`string`?e.tag.trim():``)||[e?.sessionId,e?.kind,e?.title,e?.body].filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()).join(`|`),bt=e=>{for(let[t,n]of F)e-n>P&&F.delete(t)},xt=e=>{let t=yt(e);if(!t)return!0;let n=Date.now();if(bt(n),n-(F.get(t)??0)<P)return!1;try{if(typeof window<`u`&&window.localStorage){let e=`${_t}${t}`,r=Number(window.localStorage.getItem(e)??`0`);if(Number.isFinite(r)&&n-r<P)return F.set(t,r),!1;Number.isFinite(r)&&r>0&&window.localStorage.removeItem(e),window.localStorage.setItem(e,String(n))}}catch{}return F.set(t,n),!0},I=async()=>{if(typeof navigator>`u`||!(`serviceWorker`in navigator))return null;let e=null;try{e=await navigator.serviceWorker.getRegistration()??null}catch{e=null}if(e?.active)return e;if(!e)return null;try{return await Promise.race([navigator.serviceWorker.ready,new Promise(e=>{setTimeout(()=>e(null),gt)})])??e}catch{return e}},St=async e=>{let t=await I();if(!t||typeof t.showNotification!=`function`)return!1;try{return await t.showNotification(e?.title??`OpenChamber`,{body:e?.body,tag:e?.tag}),!0}catch(e){return console.warn(`Failed to send notification via service worker`,e),!1}},Ct=async()=>{let e=await I();if(!e||!(`pushManager`in e)||!e.pushManager)return!1;try{return!!await e.pushManager.getSubscription()}catch{return!1}},wt=async e=>{if(e?.requireHidden&&typeof document<`u`&&document.hasFocus())return!0;if(typeof Notification>`u`)return!1;if(Notification.permission==="default"&&await Notification.requestPermission()!==`granted`||Notification.permission!==`granted`)return console.warn(`Notification permission not granted`),!1;if(!vt()&&await Ct()||!xt(e))return!0;try{return await St(e)||new Notification(e?.title??`OpenChamber`,{body:e?.body,tag:e?.tag}),!0}catch(e){return console.warn(`Failed to send notification`,e),!1}},Tt=async e=>{if(typeof window>`u`)return!1;let t=window.__OPENCHAMBER_DESKTOP__;if(!t?.invoke)return!1;try{return await t.invoke(`desktop_notify`,{payload:{title:e?.title,body:e?.body,tag:e?.tag,kind:e?.kind,sessionId:e?.sessionId,directory:e?.directory,requireHidden:e?.requireHidden}}),!0}catch(e){return console.warn(`Failed to send native notification (desktop)`,e),!1}},Et=()=>({async notifyAgentCompletion(e){return await Tt(e)||await wt(e)},canNotify:()=>typeof window<`u`&&window.__OPENCHAMBER_DESKTOP__?.invoke?!0:typeof Notification<`u`&&Notification.permission===`granted`}),Dt=()=>({async getAvailableTools(){let e=await f(`/api/experimental/tool/ids`);if(!e.ok)throw Error(`Tools API returned ${e.status} ${e.statusText}`);let t=await e.json();if(!Array.isArray(t))throw Error(`Tools API returned invalid data format`);return t.filter(e=>typeof e==`string`&&e!==`invalid`).sort()}}),L=async(e,t)=>{try{let n=await f(e,{...t,credentials:`include`,headers:{Accept:`application/json`,...t?.headers??{}}});return n.ok?await n.json():null}catch{return null}},Ot=()=>({async getVapidPublicKey(){return L(`/api/push/vapid-public-key`)},async subscribe(e){return L(`/api/push/subscribe`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})},async unsubscribe(e){return L(`/api/push/subscribe`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})},async setVisibility(e){return L(`/api/push/visibility`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),keepalive:!0})},async registerApnsToken(e){return L(`/api/push/apns-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})},async unregisterApnsToken(e){return L(`/api/push/apns-token`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})}}),R=async e=>await e.json().catch(()=>null),kt=({urls:e})=>({async authStatus(){let e=await f(`/api/github/auth/status`,{method:`GET`,headers:{Accept:`application/json`}}),t=await R(e);if(!e.ok||!t)throw Error(t?.error||e.statusText||`Failed to load GitHub status`);return t},async authStart(){let e=await f(`/api/github/auth/start`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({})}),t=await R(e);if(!e.ok||!t||!(`deviceCode`in t))throw Error(t?.error||e.statusText||`Failed to start GitHub auth`);return t},async authComplete(e){let t=await f(`/api/github/auth/complete`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({deviceCode:e})}),n=await R(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to complete GitHub auth`);return n},async authDisconnect(){let e=await f(`/api/github/auth`,{method:`DELETE`,headers:{Accept:`application/json`}}),t=await R(e);if(!e.ok)throw Error(t?.error||e.statusText||`Failed to disconnect GitHub`);return{removed:!!t?.removed}},async authActivate(e){let t=await f(`/api/github/auth/activate`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({accountId:e})}),n=await R(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to activate GitHub account`);return n},async authSetGhCliDisabled(e){let t=await f(`/api/github/auth/gh-cli`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({disabled:e})}),n=await R(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to update gh CLI setting`);return{disabled:!!n.disabled}},async me(){let e=await f(`/api/github/me`,{method:`GET`,headers:{Accept:`application/json`}}),t=await R(e);if(!e.ok||!t)throw Error(t?.error||e.statusText||`Failed to fetch GitHub user`);return t},async prStatus(e,t,n,r){let i=new URLSearchParams({directory:e,branch:t,...n?{remote:n}:{},...r?.force?{force:`true`}:{}}),a=await f(`/api/github/pr/status?${i.toString()}`,{method:`GET`,headers:{Accept:`application/json`}}),o=await R(a);if(!a.ok||!o)throw Error(o?.error||a.statusText||`Failed to load PR status`);return o},async prCreate(e){let t=await f(`/api/github/pr/create`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)}),n=await R(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to create PR`);return n},async prUpdate(e){let t=await f(`/api/github/pr/update`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)}),n=await R(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to update PR`);return n},async prMerge(e){let t=await f(`/api/github/pr/merge`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)}),n=await R(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to merge PR`);return n},async prReady(e){let t=await f(`/api/github/pr/ready`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)}),n=await R(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to mark PR ready`);return n},async repoUpstream(e){let t=await f(`/api/github/repo/upstream?directory=${encodeURIComponent(e)}`,{method:`GET`,headers:{Accept:`application/json`}}),n=await R(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to detect upstream repo`);return n},async repoBranches(e,t){let n=await f(`/api/github/repo/branches?owner=${encodeURIComponent(e)}&repo=${encodeURIComponent(t)}`,{method:`GET`,headers:{Accept:`application/json`}}),r=await R(n);if(!n.ok||!r)throw Error(r?.error||n.statusText||`Failed to fetch repo branches`);return r.branches??[]},async prsList(e,t){let n=t?.page??1,r=new URLSearchParams({directory:e,page:String(n)});t?.query&&r.set(`query`,t.query);let i=await f(`/api/github/pulls/list?${r.toString()}`,{method:`GET`,headers:{Accept:`application/json`}}),a=await R(i);if(!i.ok||!a)throw Error(a?.error||i.statusText||`Failed to load pull requests`);return a},async prContext(t,n,r){let i=new URLSearchParams({directory:t,number:String(n)});r?.includeDiff&&i.set(`diff`,`1`),r?.includeCheckDetails&&i.set(`checkDetails`,`1`),r?.sourceRepo?.owner&&r.sourceRepo.repo&&(i.set(`owner`,r.sourceRepo.owner),i.set(`repo`,r.sourceRepo.repo));let a=await f(e.api(`/api/github/pulls/context`,i),{method:`GET`,headers:{Accept:`application/json`}}),o=await R(a);if(!a.ok||!o)throw Error(o?.error||a.statusText||`Failed to load pull request context`);return o},async issuesList(e,t){let n=t?.page??1,r=new URLSearchParams({directory:e,page:String(n)});t?.query&&r.set(`query`,t.query);let i=await f(`/api/github/issues/list?${r.toString()}`,{method:`GET`,headers:{Accept:`application/json`}}),a=await R(i);if(!i.ok||!a)throw Error(a?.error||i.statusText||`Failed to load issues`);return a},async issueGet(t,n,r){let i=new URLSearchParams({directory:t,number:String(n)});r?.sourceRepo?.owner&&r.sourceRepo.repo&&(i.set(`owner`,r.sourceRepo.owner),i.set(`repo`,r.sourceRepo.repo));let a=await f(e.api(`/api/github/issues/get`,i),{method:`GET`,headers:{Accept:`application/json`}}),o=await R(a);if(!a.ok||!o)throw Error(o?.error||a.statusText||`Failed to load issue`);return o},async issueComments(t,n,r){let i=new URLSearchParams({directory:t,number:String(n)});r?.sourceRepo?.owner&&r.sourceRepo.repo&&(i.set(`owner`,r.sourceRepo.owner),i.set(`repo`,r.sourceRepo.repo));let a=await f(e.api(`/api/github/issues/comments`,i),{method:`GET`,headers:{Accept:`application/json`}}),o=await R(a);if(!a.ok||!o)throw Error(o?.error||a.statusText||`Failed to load issue comments`);return o}}),z=async e=>await e.json().catch(()=>null),At=()=>({async listClients(){let e=await f(`/api/client-auth/clients`,{method:`GET`,headers:{Accept:`application/json`}}),t=await z(e);if(!e.ok||!t)throw Error(t?.error||e.statusText||`Failed to load remote clients`);return Array.isArray(t.clients)?t.clients:[]},async createClient(e={}){let t=await f(`/api/client-auth/clients`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({label:e.label??``})}),n=await z(t);if(!t.ok||!n?.client||typeof n.token!=`string`)throw Error(n?.error||t.statusText||`Failed to create remote client token`);return n},async createPairingSession(e={}){let t=await f(`/api/client-auth/pairing/sessions`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({label:e.label??``,...e.allowedClientKinds?{allowedClientKinds:e.allowedClientKinds}:{},...e.serverUrl?{serverUrl:e.serverUrl}:{},...typeof e.includeRelay==`boolean`?{includeRelay:e.includeRelay}:{},...typeof e.includeDirect==`boolean`?{includeDirect:e.includeDirect}:{},...e.relayUrl?{relayUrl:e.relayUrl}:{},...e.sshHostId?{sshHostId:e.sshHostId}:{}})}),n=await z(t);if(!t.ok||typeof n?.pairing?.secret!=`string`||!n?.server)throw Error(n?.error||t.statusText||`Failed to create pairing session`);return n},async listPendingPairings(){let e=await f(`/api/client-auth/pairing/sessions`,{method:`GET`,headers:{Accept:`application/json`}}),t=await z(e);if(!e.ok||!t)throw Error(t?.error||e.statusText||`Failed to load pending pairings`);return Array.isArray(t.pending)?t.pending:[]},async getPairingTransports(){let e=await f(`/api/client-auth/pairing/transports`,{method:`GET`,headers:{Accept:`application/json`}}),t=await z(e);if(!e.ok||!t)throw Error(t?.error||e.statusText||`Failed to load pairing transports`);return{local:t.local??null,lan:t.lan??null,relayAvailable:t.relayAvailable===!0,...typeof t.relayUrl==`string`?{relayUrl:t.relayUrl}:{},...typeof t.relayUrlLocked==`boolean`?{relayUrlLocked:t.relayUrlLocked}:{}}},async cancelPairing(e){let t=await f(`/api/client-auth/pairing/sessions/${encodeURIComponent(e)}`,{method:`DELETE`,headers:{Accept:`application/json`}}),n=await z(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to cancel pairing`);return{cancelled:n.cancelled===!0}},async revokeClient(e){let t=await f(`/api/client-auth/clients/${encodeURIComponent(e)}`,{method:`DELETE`,headers:{Accept:`application/json`}}),n=await z(t);if(!t.ok||!n)throw Error(n?.error||t.statusText||`Failed to revoke remote client`);return n},async purgeRevokedClients(){let e=await f(`/api/client-auth/clients`,{method:`DELETE`,headers:{Accept:`application/json`}}),t=await z(e);if(!e.ok||!t)throw Error(t?.error||e.statusText||`Failed to clear revoked clients`);return t}}),B=e=>typeof e==`object`&&!!e&&!Array.isArray(e),V=e=>typeof e==`number`&&Number.isFinite(e),jt=e=>{if(!B(e)||typeof e.ok!=`boolean`)return!1;if(e.ok===!0)return B(e.session)&&typeof e.session.id==`string`&&typeof e.messageID==`string`;let t=e.phase;if(typeof t!=`string`)return!1;switch(t){case`validate`:return typeof e.error==`string`&&Array.isArray(e.errors)&&e.errors.every(e=>typeof e==`string`);case`create`:return!(typeof e.error!=`string`||`status`in e&&e.status!==void 0&&!V(e.status));case`prompt`:return B(e.session)&&typeof e.session.id==`string`&&typeof e.messageID==`string`&&typeof e.ambiguous==`boolean`&&typeof e.error==`string`&&(!(`status`in e)||e.status===void 0||V(e.status));case`conflict`:return typeof e.error==`string`;case`unavailable`:return typeof e.error==`string`;case`internal`:return typeof e.error==`string`;default:return!1}},Mt=()=>({async createWithPrompt(e,t){let n;try{n=await f(`/api/openchamber/conversations`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:t})}catch{throw Error(`Conversation request failed`)}let r;try{r=await n.json()}catch{throw Error(`Unexpected server response: invalid JSON`)}if(!jt(r))throw Error(`Unexpected server response: result shape mismatch`);return r}}),Nt=`https://openchamber.xiaobe.top/v1/mobile/update/check`,Pt=`https://openchamber-update.vercel.app/v1/mobile/update/check`,Ft=1e4,H=`openchamber.mobile-ota.device-id.v1`,U=e=>typeof e==`string`&&e.trim().length>0?e.trim():null,W=()=>{try{let e=T;return((typeof e.getConfig==`function`?e.getConfig():void 0)??e.config)?.OpenChamberOTA??{}}catch{return{}}},G=()=>W().channel===`stable`?`stable`:`beta`,It=()=>{let e=W().shellApiVersion;return typeof e==`number`&&Number.isFinite(e)&&e>0?Math.floor(e):1},Lt=()=>{let e=Ye();if(e===`ios`||e===`android`)return e;try{let e=T.getPlatform();if(e===`ios`||e===`android`)return e}catch{}return`android`},Rt=()=>{if(typeof window>`u`)return null;try{return U(window.localStorage.getItem(H))}catch{return null}},K=e=>{if(!(typeof window>`u`))try{window.localStorage.setItem(H,e)}catch{}},zt=async e=>{if(e)try{let t=U((await e.getDeviceId()).deviceId);if(t)return K(t),t}catch{}let t=Rt();if(t)return t;let n=d();return K(n),n},Bt=async()=>{let e=U(`1.18.3`);if(x())try{let{App:t}=await E(async()=>{let{App:e}=await import(`./vendor-capacitor-app-PzT84wSx.js`).then(e=>e.t);return{App:e}},__vite__mapDeps([0,1,2])),n=await t.getInfo(),r=U(n.version)??e??`0.0.0`,i=U(n.build),a=i?Number.parseInt(i,10):0;return{version:r,build:Number.isFinite(a)?a:0}}catch{}return{version:e??`0.0.0`,build:0}},q=(e,t,n)=>{let r=U(e?.version),i=U(t);if(n===`beta`&&i)return i;if(r&&r!==`builtin`)return i&&i!==r&&i.startsWith(`${r}-`)?i:r;let a=U(e?.id);return a&&a!==`builtin`?a:i??`builtin`},Vt=()=>U(`1.18.3`),Ht=async e=>{let t=Vt(),n=G();if(!e)return q(null,t,n);try{return q((await e.current()).bundle,t,n)}catch{return q(null,t,n)}},Ut=()=>[Nt,Pt],Wt=(e,t,n)=>{let r=e-n();return r<=0||t<=0?null:Math.max(1,Math.ceil(r/t))};async function Gt(e,t,n,r){try{if(x())try{let{CapacitorHttp:r}=await E(async()=>{let{CapacitorHttp:e}=await import(`./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js`).then(e=>e.i);return{CapacitorHttp:e}},__vite__mapDeps([2,1])),i=Object.fromEntries(new Headers(t.headers).entries()),a;if(typeof t.body==`string`)try{a=JSON.parse(t.body)}catch{a=t.body}let o=await Promise.race([r.request({url:e,method:t.method||`GET`,headers:i,data:a,connectTimeout:n,readTimeout:n}),new Promise(e=>{window.setTimeout(()=>e(null),n)})]);return o?{ok:o.status>=200&&o.status<300,status:o.status,json:async()=>{if(typeof o.data==`string`)try{return JSON.parse(o.data)}catch{return o.data}return o.data}}:null}catch{}let i=await r(e,{...t,signal:AbortSignal.timeout(n)});return{ok:i.ok,status:i.status,json:()=>i.json()}}catch{return null}}var J=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return!(t.status!==`ok`||t.primaryAction!==`none`&&t.primaryAction!==`apply_ota`&&t.primaryAction!==`install_native_required`||!t.ota||typeof t.ota!=`object`||!t.native||typeof t.native!=`object`||typeof t.nextCheckInSec!=`number`||!Number.isFinite(t.nextCheckInSec))};async function Kt(e,t,n,r){let i=await Gt(e,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(t)},n,r);if(!i?.ok)return null;let a;try{a=await i.json()}catch{return null}return J(a)?a:null}async function qt(e={}){let t=e.updater===void 0?await k():e.updater;if(!t&&!x())throw new D;let n=e.fetchImpl??fetch,r=e.now??Date.now,[i,a,o]=await Promise.all([zt(t),Bt(),Ht(t)]),s={channel:G(),platform:Lt(),deviceId:i,nativeVersion:a.version,nativeBuild:a.build,shellApiVersion:It(),currentBundleId:o},c=Ut(),l=r()+Ft,u=null;for(let[e,t]of c.entries()){let i=Wt(l,c.length-e,r);if(i===null)break;try{let e=await Kt(t,s,i,n);if(e)return e;u=Error(`Mobile OTA check failed at ${t}`)}catch(e){u=e instanceof Error?e:Error(`Mobile OTA check failed`)}}throw u??Error(`Unable to check for mobile OTA updates`)}async function Jt(e){let t=await k();if(!t)return null;try{let{bundles:n}=await t.list();return n.find(t=>t.checksum===e.checksum&&t.version===e.releaseVersion&&(t.status===`success`||t.status===`pending`))?.id??null}catch{return null}}async function Yt(e){let t=await k();if(!t)throw new D;return(await t.download({url:e.url,version:e.releaseVersion,checksum:e.checksum,...e.sessionKey?{sessionKey:e.sessionKey}:{}})).id}async function Xt(){let e=await k();if(!e)throw new D;await e.reload()}async function Zt(e){let t=await k();if(!t)throw new D;await t.next({id:e})}var Y=null,X=e=>typeof e==`string`&&e.trim().length>0?e.trim():null,Z=async()=>{let e=X(`1.18.3`);try{if(T.isNativePlatform()){let{App:t}=await E(async()=>{let{App:e}=await import(`./vendor-capacitor-app-PzT84wSx.js`).then(e=>e.t);return{App:e}},__vite__mapDeps([0,1,2]));return X((await t.getInfo()).version)??e??`unknown`}}catch{}return e??`unknown`},Qt=()=>({async checkForOtaUpdate(){if(!O()&&!T.isNativePlatform())throw new D;return qt()},async downloadOtaUpdate(e){if(!O())throw new D;let t=await Jt(e);return t?(Y=t,{skipped:!0}):(Y=await Yt(e),{skipped:!1})},async applyOtaUpdateNow(){if(!O())throw new D;await Xt()},async queueOtaUpdateForNextLaunch(){if(!O())throw new D;let e=Y;if(!e)throw Error(`No downloaded OTA bundle to queue`);await Zt(e)},async getOtaStatus(){if(!O())return{supported:!1,currentBundleId:`builtin`,nativeVersion:await Z()};let e=await k();if(!e)return{supported:!1,currentBundleId:`builtin`,nativeVersion:await Z()};try{let[t,n]=await Promise.all([e.current(),Z()]);return{supported:!0,currentBundleId:X(t.bundle?.id)||`builtin`,nativeVersion:n}}catch{return{supported:!0,currentBundleId:`builtin`,nativeVersion:await Z()}}}}),$t=()=>({api:(...t)=>e().api(...t),authenticatedAsset:(...t)=>e().authenticatedAsset(...t),auth:(...t)=>e().auth(...t),health:(...t)=>e().health(...t),rawFile:(...t)=>e().rawFile(...t),sse:(...t)=>e().sse(...t),websocket:(...t)=>e().websocket(...t)}),en=(e={})=>{let t=e.urls??s();r(t);let n=$t();return{runtime:{platform:`web`,isDesktop:!1,isVSCode:!1,label:`web`},terminal:lt(),git:ut(),files:ft({urls:n,getDirectory:()=>ie.getState().currentDirectory}),settings:mt(),permissions:ht(),notifications:Et(),github:kt({urls:n}),push:Ot(),mobileUpdates:Qt(),clientAuth:At(),tools:Dt(),conversations:Mt()}},Q=(e,t)=>{if(!e||!t)return!1;try{return new URL(e).origin===new URL(t).origin}catch{return!1}},$=Promise.resolve(),tn=()=>$,nn=()=>{let e=typeof window.__OPENCHAMBER_API_BASE_URL__==`string`?window.__OPENCHAMBER_API_BASE_URL__.trim():``,r=typeof window.__OPENCHAMBER_CLIENT_TOKEN__==`string`?window.__OPENCHAMBER_CLIENT_TOKEN__.trim():``,s=typeof window.__OPENCHAMBER_LOCAL_ORIGIN__==`string`?window.__OPENCHAMBER_LOCAL_ORIGIN__.trim():``,d=a({apiBaseUrl:e||void 0,realtimeBaseUrl:e||void 0});o({apiBaseUrl:e,runtimeKey:Q(e,s)?`local`:null}),t(r||null),i(window.__OPENCHAMBER_RUNTIME_HEADERS__||null),l(e||void 0).catch(()=>{}),s&&!Q(e,s)&&Object.keys(n()).length>0&&c(s).catch(()=>{}),u();let f=window.__OPENCHAMBER_RELAY_HOST_ID__;return $=Promise.race([ee(typeof f==`string`&&f?f:void 0).catch(()=>{}),new Promise(e=>{window.setTimeout(e,1e4)})]),en({urls:d})};export{tn as n,nn as t};