@yuriai/web 0.2.27-beta.8 → 0.2.27

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 (196) hide show
  1. package/dist/assets/{AgentAvatar-BJ42lGZD.js → AgentAvatar-DNm_jMna.js} +1 -1
  2. package/dist/assets/AssistantContactStatus-BPRpgMFh.js +3 -0
  3. package/dist/assets/{AssistantUnreadBadge-QwhBfXpC.js → AssistantUnreadBadge-BssH-RvV.js} +1 -1
  4. package/dist/assets/{AssistantView-D7ryIKL0.js → AssistantView-CxQv-9Ms.js} +1 -1
  5. package/dist/assets/{DiagramView-ERrGEBDp.js → DiagramView-DPpG0fwx.js} +1 -1
  6. package/dist/assets/{FadeInOnReveal-Bu2GvaM9.js → FadeInOnReveal-S6UbimjB.js} +1 -1
  7. package/dist/assets/{GuiPluginSurface-MzQgEZNr.js → GuiPluginSurface-BOf0JA1T.js} +1 -1
  8. package/dist/assets/{GuiPluginWindow-DZMmlQzx.js → GuiPluginWindow-OrYkfQ4m.js} +1 -1
  9. package/dist/assets/{Icon-Dj4CCqCP.js → Icon-BE4mEwzV.js} +1 -1
  10. package/dist/assets/{ImageLoadingPlaceholder-BnFXgUuO.js → ImageLoadingPlaceholder-CBFJC_KD.js} +1 -1
  11. package/dist/assets/{LoadingImage-PBnivDKv.js → LoadingImage-NLq7_P-i.js} +1 -1
  12. package/dist/assets/MarkdownRenderer-BaMotAOQ.js +2 -0
  13. package/dist/assets/{MarkdownRendererImpl-CfyXL4rg.js → MarkdownRendererImpl-Cv6UnGG7.js} +1 -1
  14. package/dist/assets/{MarkstreamRendererImpl-BGadklK1.js → MarkstreamRendererImpl-Rb9O6wkW.js} +1 -1
  15. package/dist/assets/{MobileDetailNavigation-DqajQdB4.js → MobileDetailNavigation-CK4KbkeS.js} +1 -1
  16. package/dist/assets/{MobileResizableSheet-BvdUgwA3.js → MobileResizableSheet-Deidw1br.js} +1 -1
  17. package/dist/assets/{MobileShareBridge-3oPoYnry.js → MobileShareBridge-CO_OWEfq.js} +2 -2
  18. package/dist/assets/MobileTabPageHeader-DbC8L6A4.js +2 -0
  19. package/dist/assets/{MultiRunWindow-yhs0Ih5_.js → MultiRunWindow-DtVW9NTV.js} +1 -1
  20. package/dist/assets/{OnboardingScreen-Bi1VWFQC.js → OnboardingScreen-C8ld4wO7.js} +1 -1
  21. package/dist/assets/{OverlayScrollbar-BBDwGvGO.js → OverlayScrollbar-B3auC2WH.js} +1 -1
  22. package/dist/assets/{SettingsView-BSf-SJUA.js → SettingsView-Cm7woZWl.js} +14 -14
  23. package/dist/assets/{SettingsWindow-BvSXVMTm.js → SettingsWindow-CdL4PFxW.js} +1 -1
  24. package/dist/assets/{TerminalView-DhL01N7e.js → TerminalView-CwRB6Yyr.js} +1 -1
  25. package/dist/assets/{ToolOutputDialog-C8lnH4Ky.js → ToolOutputDialog-B4BfmoVH.js} +1 -1
  26. package/dist/assets/{YuriLogo-D8asj1CS.js → YuriLogo-BOx0s0Ue.js} +1 -1
  27. package/dist/assets/{appThemeRegistry-C-maYSdv.js → appThemeRegistry-B6woJIX5.js} +1 -1
  28. package/dist/assets/{button-vXOdzd8x.js → button-BXxwtxsG.js} +1 -1
  29. package/dist/assets/{capgoAdapter-DJ_h2x5D.js → capgoAdapter-C5HFS-rx.js} +1 -1
  30. package/dist/assets/{collapsible-DwDQs3Wa.js → collapsible-BEm0787p.js} +1 -1
  31. package/dist/assets/{context-menu-BabBujQ-.js → context-menu-DUwvVUDY.js} +1 -1
  32. package/dist/assets/device-BcRP6Tjd.js +2 -0
  33. package/dist/assets/{diagram-HwgrQxY5.js → diagram-DyY8dxjZ.js} +1 -1
  34. package/dist/assets/{dialog-Dnf626tb.js → dialog-CLca6ojn.js} +1 -1
  35. package/dist/assets/{dropdown-menu.styles-CBc_a-Nv.js → dropdown-menu.styles-DGaALKP0.js} +1 -1
  36. package/dist/assets/{es-BQkO-Odr.js → es-CrsHvgue.js} +2 -2
  37. package/dist/assets/fileMentionAutocompleteState-BZJqfgae.js +2 -0
  38. package/dist/assets/{fileMentionTouchSelection-CKPnEetl.js → fileMentionTouchSelection-C4dvP8GY.js} +2 -2
  39. package/dist/assets/{fileReferenceActions-g7KZLi_G.js → fileReferenceActions-CrIAce3K.js} +1 -1
  40. package/dist/assets/{fr-C852roK5.js → fr-CEgiRlfa.js} +2 -2
  41. package/dist/assets/{gitApi-CVq5oKCd.js → gitApi-D2G9ny2O.js} +1 -1
  42. package/dist/assets/{gitApiHttp-BYOIbYIh.js → gitApiHttp-B7vYwgBh.js} +4 -4
  43. package/dist/assets/{gui-M_Rbwkyu.js → gui-CJjEj3l4.js} +1 -1
  44. package/dist/assets/host-CnVx34Dh.js +1 -0
  45. package/dist/assets/{input-BtM712b1.js → input-D59Q2pm8.js} +1 -1
  46. package/dist/assets/insertionBoundaries-CedfTSM5.js +1 -0
  47. package/dist/assets/{ja-BqC39qK6.js → ja-CX-_p9jZ.js} +2 -2
  48. package/dist/assets/{ko-BMaChAWh.js → ko-D5xlLYJM.js} +2 -2
  49. package/dist/assets/main-CxpUooVS.js +2 -0
  50. package/dist/assets/{main-Mey7bCWf.js → main-Dpm4KxWX.js} +12 -12
  51. package/dist/assets/{markdownHeightCache-Bf8iisO4.js → markdownHeightCache-D2VWb_4E.js} +1 -1
  52. package/dist/assets/{mcpQueries-DpXqegX5.js → mcpQueries-DQ3KthDF.js} +1 -1
  53. package/dist/assets/miniChat-CTdj8Ug9.js +2 -0
  54. package/dist/assets/mobile-ChbA3Q8j.js +2 -0
  55. package/dist/assets/{mobileBackNavigation-DZcI7aZg.js → mobileBackNavigation-BJqt3oHk.js} +1 -1
  56. package/dist/assets/{multirun-hzspPepd.js → multirun-BILeETbd.js} +1 -1
  57. package/dist/assets/{native-H7K64Ulc.js → native-BYMhr-xH.js} +1 -1
  58. package/dist/assets/{native-config-CddZtLQ1.js → native-config-BIY0Cr-l.js} +1 -1
  59. package/dist/assets/{persistence-BT8045Ue.js → persistence-CWuLIq1J.js} +2 -2
  60. package/dist/assets/{pl-Ubs8p28T.js → pl-BjH81A_q.js} +2 -2
  61. package/dist/assets/{projectMeta-CEf0QPmD.js → projectMeta-B9_Uh8YH.js} +1 -1
  62. package/dist/assets/{pt-BR-8rAOjJrs.js → pt-BR-Dp5oK2x3.js} +2 -2
  63. package/dist/assets/queue-abort-optimistic-CS5jTJq-.js +1 -0
  64. package/dist/assets/{readiness-Dyr7314z.js → readiness-BNIgH81X.js} +1 -1
  65. package/dist/assets/renderElectronMiniChatApp-asOqV7FB.js +2 -0
  66. package/dist/assets/renderMobileApp-DAfque7-.js +28 -0
  67. package/dist/assets/{runtimeConfig-B8VHHNxj.js → runtimeConfig-BX8JirIc.js} +1 -1
  68. package/dist/assets/runtimeEndpointReset-CFQgUiUr.js +149 -0
  69. package/dist/assets/{scheduledTaskNavigation-Zm87Nydi.js → scheduledTaskNavigation-EomDNVu2.js} +1 -1
  70. package/dist/assets/sessionLookup-BxAaxPOw.js +1 -0
  71. package/dist/assets/{sortable-tabs-strip-D4pVoodN.js → sortable-tabs-strip-DpbW5MqX.js} +1 -1
  72. package/dist/assets/{speechSettingsQueries-RlCLMBtr.js → speechSettingsQueries-CC0fusUo.js} +2 -2
  73. package/dist/assets/src-BMKjN2ip.css +2 -0
  74. package/dist/assets/{store-ME7oHni1.js → store-CkIHVrmT.js} +4 -3
  75. package/dist/assets/{terminalApi-BSaclMDJ.js → terminalApi-rl9mZAlB.js} +1 -1
  76. package/dist/assets/{textarea-B98rsLs7.js → textarea-7eTptEtD.js} +1 -1
  77. package/dist/assets/{tooltip-B9810jbK.js → tooltip-BPwoSTzO.js} +1 -1
  78. package/dist/assets/types-CUtSV1V8.js +2 -0
  79. package/dist/assets/{uk-LzwzUApL.js → uk-BEfkaLtM.js} +2 -2
  80. package/dist/assets/{useAppFontEffects-D2C1sBYM.js → useAppFontEffects-Ck2PdQRx.js} +37 -37
  81. package/dist/assets/{useAssistantUIStore-TUN_ycy5.js → useAssistantUIStore-CfaQV3ID.js} +1 -1
  82. package/dist/assets/useDesktopWindowControlsLayout-DxxOUZj1.js +1 -0
  83. package/dist/assets/useEffectiveDirectory-CNCQfN_x.js +1 -0
  84. package/dist/assets/{useFontPreferences-BlhlCJCX.js → useFontPreferences-DeqW9nRx.js} +1 -1
  85. package/dist/assets/useMobileNavigationStore-BmVr5a5c.js +17 -0
  86. package/dist/assets/{useUIStore-DRx6OgCp.js → useUIStore-C6CE42oh.js} +1 -1
  87. package/dist/assets/{useWorkerHighlightedLines-D093jNsH.js → useWorkerHighlightedLines-CN_RGaSw.js} +1 -1
  88. package/dist/assets/{vendor-effect-DV9F8PTZ.js → vendor-effect-X1Hqc7ba.js} +13 -13
  89. package/dist/assets/vendor-opencode-client-cQ47ywrT.js +23 -0
  90. package/dist/assets/{vendor-opencode-plugin-BBOP6WNx.js → vendor-opencode-plugin-BmdTE4Te.js} +1 -1
  91. package/dist/assets/vendor-opencode-schema-DWT45VBX.js +1 -0
  92. package/dist/assets/vendor-solid-js-D98iXT7C.js +1 -0
  93. package/dist/assets/vendor-zod-DZzbCm1s.js +55 -0
  94. package/dist/assets/{zh-CN-D-FVCeks.js → zh-CN-DipfA56P.js} +2 -2
  95. package/dist/assets/{zh-TW-B9iH_NXL.js → zh-TW-B7pXMVjt.js} +2 -2
  96. package/dist/index.html +12 -12
  97. package/dist/mini-chat.html +12 -12
  98. package/dist/mobile.html +12 -12
  99. package/package.json +1 -1
  100. package/server/index.js +2 -145
  101. package/server/lib/assistants/DOCUMENTATION.md +56 -10
  102. package/server/lib/assistants/cards.js +1 -1
  103. package/server/lib/assistants/channel-image.js +92 -0
  104. package/server/lib/assistants/channel-image.test.js +76 -0
  105. package/server/lib/assistants/channel-output-store.test.js +41 -0
  106. package/server/lib/assistants/channel-output.integration.test.js +114 -0
  107. package/server/lib/assistants/channel-output.js +90 -0
  108. package/server/lib/assistants/channel-output.test.js +79 -0
  109. package/server/lib/assistants/channels/DOCUMENTATION.md +52 -14
  110. package/server/lib/assistants/channels/PROTOCOLS.md +23 -1
  111. package/server/lib/assistants/channels/dingtalk-chat-adapter.js +19 -7
  112. package/server/lib/assistants/channels/dingtalk-chat-adapter.test.js +8 -0
  113. package/server/lib/assistants/channels/routes.js +12 -0
  114. package/server/lib/assistants/channels/routes.test.js +34 -0
  115. package/server/lib/assistants/channels/runtime.js +117 -26
  116. package/server/lib/assistants/channels/runtime.test.js +179 -5
  117. package/server/lib/assistants/channels/sdk-adapters.js +15 -3
  118. package/server/lib/assistants/channels/sdk-adapters.test.js +17 -0
  119. package/server/lib/assistants/channels/store.js +9 -6
  120. package/server/lib/assistants/channels/store.test.js +21 -11
  121. package/server/lib/assistants/channels/transport.js +2 -1
  122. package/server/lib/assistants/channels/wecom-chat-adapter.js +16 -2
  123. package/server/lib/assistants/channels/wecom-chat-adapter.test.js +21 -0
  124. package/server/lib/assistants/contact-store.js +9 -3
  125. package/server/lib/assistants/contact-store.test.js +27 -0
  126. package/server/lib/assistants/contact-tools.js +65 -75
  127. package/server/lib/assistants/contact-tools.test.js +114 -22
  128. package/server/lib/assistants/harness.js +79 -34
  129. package/server/lib/assistants/harness.test.js +52 -20
  130. package/server/lib/assistants/resource-reference.integration.test.js +284 -0
  131. package/server/lib/assistants/routes.js +0 -3
  132. package/server/lib/assistants/service.js +116 -69
  133. package/server/lib/assistants/service.test.js +31 -17
  134. package/server/lib/assistants/weixin/DOCUMENTATION.md +34 -9
  135. package/server/lib/assistants/weixin/api.js +43 -1
  136. package/server/lib/assistants/weixin/api.test.js +28 -0
  137. package/server/lib/assistants/weixin/chat-adapter.js +8 -2
  138. package/server/lib/assistants/weixin/inbound.js +5 -3
  139. package/server/lib/assistants/weixin/inbound.test.js +20 -0
  140. package/server/lib/assistants/weixin/runtime.js +27 -18
  141. package/server/lib/assistants/weixin/runtime.test.js +36 -0
  142. package/server/lib/assistants/weixin/store.js +8 -4
  143. package/server/lib/assistants/weixin/store.test.js +21 -0
  144. package/server/lib/assistants/yuri-project.http.test.js +9 -3
  145. package/server/lib/notifications/DOCUMENTATION.md +6 -0
  146. package/server/lib/notifications/runtime.js +26 -15
  147. package/server/lib/notifications/runtime.test.js +14 -13
  148. package/server/lib/opencode/DOCUMENTATION.md +9 -0
  149. package/server/lib/opencode/auth.d.ts +6 -2
  150. package/server/lib/opencode/core-routes.js +0 -1
  151. package/server/lib/opencode/feature-routes-runtime.js +0 -24
  152. package/server/lib/opencode/location-release.d.ts +5 -1
  153. package/server/lib/opencode/managed-capabilities/scheduled-task.js +1 -1
  154. package/server/lib/opencode/managed-capabilities-runtime.test.js +1 -1
  155. package/server/lib/opencode/native-goal.js +15 -0
  156. package/server/lib/opencode/native-goal.test.js +17 -0
  157. package/server/lib/opencode/settings-helpers.js +0 -6
  158. package/server/lib/opencode/shutdown-runtime.js +0 -2
  159. package/server/lib/projects/project-config.js +3 -6
  160. package/server/lib/scheduled-tasks/DOCUMENTATION.md +10 -35
  161. package/server/lib/scheduled-tasks/managed-tool-route.js +1 -30
  162. package/server/lib/scheduled-tasks/routes.js +0 -26
  163. package/server/lib/scheduled-tasks/runtime.js +33 -257
  164. package/server/lib/scheduled-tasks/runtime.test.js +24 -65
  165. package/server/lib/session-metadata/DOCUMENTATION.md +9 -12
  166. package/server/lib/session-metadata/routes.js +4 -38
  167. package/server/lib/session-metadata/routes.test.js +2 -2
  168. package/dist/assets/AssistantContactStatus-dtkObamV.js +0 -3
  169. package/dist/assets/MarkdownRenderer-BajF4gUU.js +0 -2
  170. package/dist/assets/MobileTabPageHeader-B6cRyIRH.js +0 -2
  171. package/dist/assets/device-BjRYYXNT.js +0 -2
  172. package/dist/assets/host-BW3FEJdU.js +0 -1
  173. package/dist/assets/insertionBoundaries-Dx3WAY6i.js +0 -1
  174. package/dist/assets/main-9uP2z1qT.js +0 -2
  175. package/dist/assets/miniChat-DqZvVkme.js +0 -2
  176. package/dist/assets/mobile-DXAWjYcN.js +0 -2
  177. package/dist/assets/renderElectronMiniChatApp-DoOq8Cuo.js +0 -2
  178. package/dist/assets/renderMobileApp-TTxtOb8b.js +0 -28
  179. package/dist/assets/runtimeEndpointReset-BC6XWntz.js +0 -149
  180. package/dist/assets/sessionLookup-De53jDwM.js +0 -1
  181. package/dist/assets/src-lE4uqaHS.css +0 -2
  182. package/dist/assets/types-DFf9vd1b.js +0 -2
  183. package/dist/assets/useDesktopWindowControlsLayout-BjKaHN0x.js +0 -1
  184. package/dist/assets/useEffectiveDirectory-TEvyiQSC.js +0 -1
  185. package/dist/assets/useMobileNavigationStore-DTvJV9s-.js +0 -23
  186. package/dist/assets/vendor-opencode-client-ZeOZ4Efz.js +0 -23
  187. package/dist/assets/vendor-solid-js-9wmPZH9g.js +0 -1
  188. package/dist/assets/vendor-zod-Dzk5kdUU.js +0 -39
  189. package/server/lib/session-goal/DOCUMENTATION.md +0 -371
  190. package/server/lib/session-goal/capability.js +0 -57
  191. package/server/lib/session-goal/capability.test.js +0 -33
  192. package/server/lib/session-goal/objectives.js +0 -61
  193. package/server/lib/session-goal/routes.js +0 -274
  194. package/server/lib/session-goal/routes.test.js +0 -211
  195. package/server/lib/session-goal/runtime.js +0 -2452
  196. package/server/lib/session-goal/runtime.test.js +0 -2125
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/rolldown-runtime-hePW80VL.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n,n as r,o as i}from"./runtime-switch-DEZ1K7qW.js";import{n as a}from"./runtime-fetch-D0YWp3FJ.js";import{D as o,E as s,L as c,S as l,T as u,b as d,i as f,n as p,w as m,x as h}from"./desktop-JwYqThiw.js";import{t as g}from"./runtimeAPIRegistry-C2VogTny.js";import{a as _,i as v,r as y}from"./vendor-zustand-B43HCgwC.js";import{at as b,it as x,o as S,rt as C,s as w}from"./vendor-base-ui-BQjbsJ43.js";import{At as T,bt as E}from"./gitApiHttp-BYOIbYIh.js";import{b as D,n as O}from"./useUIStore-DRx6OgCp.js";import{$ as k,d as A,i as j}from"./persistence-BT8045Ue.js";import{n as M}from"./vendor-react-D5d-V1vN.js";import{l as N,n as P,o as F,s as I}from"./vendor-tanstack-react-query-C4SG3JZB.js";import{a as L,i as R,o as z,r as B,t as ee}from"./queryRuntime-CTcigFdj.js";import{o as te}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as V}from"./pathNormalization-ewtPqJWn.js";import{n as H,t as U}from"./platform-DFJEtBlo.js";import{a as ne,t as W}from"./types-DFf9vd1b.js";import{$ as re,A as ie,B as ae,G as oe,H as se,J as ce,L as le,P as ue,T as de,U as fe,W as pe,X as me,Y as he,a as ge,at as G,dt as _e,f as ve,ft as ye,g as be,l as xe,pt as Se,st as Ce,z as K}from"./vendor-codemirror-autocomplete-7c2L_4dM.js";import{c as we,o as Te,r as Ee}from"./vendor-codemirror-lang-angular-DXOgWEVj.js";import{n as De,r as Oe}from"./vendor-codemirror-lang-json-mLulNbwB.js";import{n as ke}from"./vendor-codemirror-lang-markdown-CV1IO6Qs.js";import{n as Ae}from"./vendor-codemirror-lang-python-YM2WVLHF.js";import{O as je}from"./vendor-codemirror-legacy-modes-DwltVFbT.js";import{r as Me}from"./vendor-reactuses-core-BcebBLwF.js";import{a as Ne,d as Pe,f as Fe,p as Ie,r as q,t as J}from"./button-vXOdzd8x.js";import{Ba as Le,Bi as Re,Ni as ze,Pa as Be,Sn as Ve,Ui as He,Yn as Ue,ao as We,di as Ge,eo as Ke,f as qe,li as Je,mi as Ye,no as Xe,pi as Ze,qi as Y,qr as Qe,si as $e,so as et,ui as tt,ya as nt}from"./useMobileNavigationStore-DTvJV9s-.js";import{t as rt}from"./AgentAvatar-BJ42lGZD.js";import{n as it}from"./useThemeSystem-CGF5jnIh.js";import{n as X,r as at}from"./Icon-Dj4CCqCP.js";import{a as ot,n as st,o as ct,r as lt,t as ut}from"./dialog-Dnf626tb.js";import{L as dt,_ as ft,b as pt,c as mt,n as ht,s as gt,u as _t}from"./gitApi-CVq5oKCd.js";import{A as vt,C as yt,O as bt,S as xt,_ as St,a as Ct,b as wt,c as Tt,h as Et,m as Dt,n as Ot,r as kt,t as At,x as jt}from"./projectMeta-CEf0QPmD.js";import{t as Mt}from"./input-BtM712b1.js";import{i as Nt,n as Pt,t as Ft}from"./tooltip-B9810jbK.js";import{F as It,G as Lt,Gt as Rt,Ht as zt,J as Bt,Kt as Vt,M as Ht,P as Ut,U as Wt,Ut as Gt,W as Kt,Wt as qt,Xt as Jt,a as Yt,ct as Xt,et as Zt,k as Qt,nt as $t,q as en,qt as tn,rt as nn,tn as rn,tt as an,v as on}from"./speechSettingsQueries-RlCLMBtr.js";import{r as sn,t as cn}from"./device-BjRYYXNT.js";import{t as ln}from"./MobileResizableSheet-BvdUgwA3.js";import{n as un}from"./MarkdownRenderer-BajF4gUU.js";import{a as dn}from"./url-MRa-FtQa.js";import{i as fn}from"./react-DRe85o5s.js";import{n as pn,t as mn}from"./textarea-B98rsLs7.js";import{r as hn}from"./markdown-worker-oBGEB9Eg.js";import{i as gn,n as _n,o as vn}from"./mcpQueries-DpXqegX5.js";import{n as yn,r as bn,t as xn}from"./collapsible-DwDQs3Wa.js";import{a as Sn,d as Cn,o as wn,s as Tn}from"./vendor-codemirror-commands-B8KrBQ9B.js";import{a as En,c as Dn,i as On,l as kn,o as An,r as jn,s as Mn}from"./vendor-codemirror-search-DiPwvA-6.js";import{n as Nn,t as Pn}from"./vendor-replit-codemirror-vim-DCdAdxvE.js";import{t as Fn}from"./vendor-codemirror-language-data-Ctd4WxgW.js";import{i as In,n as Ln,r as Rn,t as zn}from"./projectActions-BX0cjZoq.js";var Bn=[{id:`claude`,name:`Claude`},{id:`codex`,name:`Codex`},{id:`cursor`,name:`Cursor`},{id:`github-copilot`,name:`GitHub Copilot`},{id:`google`,name:`Google`},{id:`kimi-for-coding`,name:`Kimi for Coding`},{id:`nano-gpt`,name:`NanoGPT`},{id:`openrouter`,name:`OpenRouter`},{id:`zai-coding-plan`,name:`z.ai`},{id:`zhipuai-coding-plan`,name:`Zhipu AI Coding Plan`},{id:`minimax-cn-coding-plan`,name:`MiniMax Coding Plan (minimaxi.com)`},{id:`minimax-coding-plan`,name:`MiniMax Coding Plan (minimax.io)`},{id:`ollama-cloud`,name:`Ollama Cloud`},{id:`wafer`,name:`Wafer.ai`},{id:`opencode-go`,name:`OpenCode Go`},{id:`xai`,name:`Grok`}],Vn=e=>[...Bn,...e.filter(e=>e.source===`magpie`).map(e=>({id:e.providerId,name:e.providerName}))],Z=M(),Q=x();function Hn(e){let t=(0,Z.c)(4),n,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Q.jsx)(`path`,{d:`M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z`}),r=(0,Q.jsx)(`path`,{d:`M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z`}),t[0]=n,t[1]=r):(n=t[0],r=t[1]);let i;return t[2]===e?i=t[3]:(i=(0,Q.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,fill:`currentColor`,stroke:`currentColor`,strokeWidth:`0.5`,fillRule:`evenodd`,viewBox:`-0.5 -0.5 25 25`,...e,children:[n,r]}),t[2]=e,t[3]=i),i}var $=e(b(),1),Un=$.forwardRef((e,t)=>{let n=(0,Z.c)(11),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]`,r),n[3]=r,n[4]=a);let o;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(o={width:`36px`,height:`20px`,minWidth:`36px`,minHeight:`20px`},n[5]=o):o=n[5];let s;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Q.jsx)(S,{className:q(`pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0`),style:{width:`16px`,height:`16px`,minWidth:`16px`,minHeight:`16px`}}),n[6]=s):s=n[6];let c;return n[7]!==i||n[8]!==t||n[9]!==a?(c=(0,Q.jsx)(w,{className:a,style:o,...i,ref:t,children:s}),n[7]=i,n[8]=t,n[9]=a,n[10]=c):c=n[10],c});Un.displayName=`Switch`;var Wn={},Gn=(e,t=n())=>JSON.stringify([t,_n(e)]),Kn=(e,t,n)=>{if(!e[t]?.[n])return e;let r={...e[t]};return delete r[n],{...e,[t]:r}},qn=e=>{let t=_n(e);return t?T.getScopedApiClient(t):T.getApiClient()},Jn=e=>e?{location:{directory:e}}:void 0,Yn=new Map,Xn=(e,t)=>JSON.stringify([r(),Gn(t),e]),Zn=async(e,t,n)=>{let r=(await e.mcp.list(Jn(n))).data.find(e=>e.name===t)?.integrationID;if(!r)throw Error(`MCP server "${t}" has no authentication integration`);return(await e.integration.get({integrationID:r,...Jn(n)})).data},Qn=e=>_n(e===void 0?E.getState().currentDirectory:e),$n=_()(y((e,t)=>({diagnosticsByDirectory:{},getDiagnosticForDirectory:e=>{let n=Gn(Qn(e));return t().diagnosticsByDirectory[n]??Wn},clearDiagnostic:(t,n,r)=>{let i=Gn(Qn(n),r);e(e=>({diagnosticsByDirectory:Kn(e.diagnosticsByDirectory,i,t)}))},connect:async(t,r)=>{let i=Qn(r),a=n(),o=Gn(i,a),s=qn(i);try{await s.mcp.connect({server:t,...Jn(i)})}catch(n){let r=n instanceof Error?n.message:`Connection failed`;throw e(e=>({diagnosticsByDirectory:{...e.diagnosticsByDirectory,[o]:{...e.diagnosticsByDirectory[o]??{},[t]:{status:`failed`,error:r}}}})),n}await vn(L,i,a),e(e=>({diagnosticsByDirectory:Kn(e.diagnosticsByDirectory,o,t)}))},disconnect:async(t,r)=>{let i=Qn(r),a=n(),o=Gn(i,a);await qn(i).mcp.disconnect({server:t,...Jn(i)}),await vn(L,i,a),e(e=>({diagnosticsByDirectory:Kn(e.diagnosticsByDirectory,o,t)}))},startAuth:async(e,t)=>{let n=Qn(t),r=Xn(e,n),i=qn(n),a=await Zn(i,e,n),o=a.methods.find(e=>e.type===`oauth`);if(!o)throw Error(`MCP server "${e}" has no OAuth method`);if(r!==Xn(e,n))throw Error(`MCP authorization runtime changed`);let s=Yn.get(r);if(s&&(await i.integration.oauth.cancel({integrationID:s.integrationID,attemptID:s.attempt.attemptID,...Jn(n)}),Yn.delete(r)),r!==Xn(e,n))throw Error(`MCP authorization runtime changed`);let{data:c}=await i.integration.oauth.connect({integrationID:a.id,methodID:o.id,...Jn(n)});if(r!==Xn(e,n))throw Error(`MCP authorization runtime changed`);for(let[e,t]of Yn)t.attempt.time.expires<=Date.now()&&Yn.delete(e);return Yn.set(r,{integrationID:a.id,attempt:c}),c},authStatus:async(e,t)=>{let n=Qn(t),r=Xn(e,n),i=Yn.get(r);if(!i)throw Error(`MCP authorization attempt not found`);let{data:a}=await qn(n).integration.oauth.status({integrationID:i.integrationID,attemptID:i.attempt.attemptID,...Jn(n)});if(r!==Xn(e,n))throw Error(`MCP authorization runtime changed`);return a.status!==`pending`&&Yn.get(r)===i&&Yn.delete(r),a},completeAuth:async(e,t,r)=>{let i=Qn(r),a=n(),o=Xn(e,i),s=Yn.get(o);if(!s||s.attempt.mode!==`code`)throw Error(`MCP authorization requires the browser callback`);if(!t.trim())throw Error(`MCP authorization code is empty`);if(await qn(i).integration.oauth.complete({integrationID:s.integrationID,attemptID:s.attempt.attemptID,code:t.trim(),...Jn(i)}),Yn.get(o)===s&&Yn.delete(o),o!==Xn(e,i))throw Error(`MCP authorization runtime changed`);await vn(L,i,a)},clearAuth:async(e,t)=>{let r=Qn(t),i=n(),a=Xn(e,r),o=qn(r),s=await Zn(o,e,r);if(a!==Xn(e,r))throw Error(`MCP authorization runtime changed`);let c=Yn.get(a);c&&(await o.integration.oauth.cancel({integrationID:c.integrationID,attemptID:c.attempt.attemptID,...Jn(r)}),Yn.delete(a));let l=new Set(s.connections.flatMap(e=>e.type===`credential`?[e.id]:[]));for(let t of l){if(a!==Xn(e,r))throw Error(`MCP authorization runtime changed`);await o.credential.remove({credentialID:t})}if(a!==Xn(e,r))throw Error(`MCP authorization runtime changed`);await vn(L,r,i)},testConnection:async(t,r)=>{let i=Qn(r),a=n(),o=Gn(i,a),s=qn(i),c=gn(L,i,a)[t]?.status===`connected`,l,u;try{await s.mcp.connect({server:t,...Jn(i)})}catch(n){l=n instanceof Error?n.message:`Connection failed`,e(e=>({diagnosticsByDirectory:{...e.diagnosticsByDirectory,[o]:{...e.diagnosticsByDirectory[o]??{},[t]:{status:`failed`,error:l??`Connection failed`}}}}))}let d=(await vn(L,i,a))[t],f=d;if(!c&&d?.status===`connected`){try{await s.mcp.disconnect({server:t,...Jn(i)})}catch(e){u=`Connection test succeeded, but cleanup disconnect failed: ${e instanceof Error?e.message:`Disconnect failed`}`}await vn(L,i,a)}return l||e(e=>({diagnosticsByDirectory:Kn(e.diagnosticsByDirectory,o,t)})),{status:f??gn(L,i,a)[t],error:l,warning:u}}}))),er=`https://yuri-updates.xiaobe.top/v1/update/check`,tr=`https://yuri-origin.xiaobe.top/v1/update/check`,nr=`https://github.com/yee94/yuri/releases/latest`,rr=`https://github.com/yee94/yuri/releases`,ir=`https://testflight.apple.com/join/pN5SSHeg`,ar=1e4;function or(e){let t=String(e||``).replace(/^v/,``).split(`+`)[0]??``,n=t.indexOf(`-`);return{parts:(n>=0?t.slice(0,n):t).split(`.`).map(e=>{let t=Number.parseInt(e||`0`,10);return Number.isFinite(t)?t:0}),prerelease:n>=0}}function sr(e,t){let n=or(e),r=or(t),i=Math.max(n.parts.length,r.parts.length);for(let e=0;e<i;e+=1){let t=(n.parts[e]||0)-(r.parts[e]||0);if(t!==0)return t}return n.prerelease===r.prerelease?0:n.prerelease?-1:1}function cr(){return[er,tr]}function lr(e,t,n=Date.now){let r=e-n();return r<=0||t<=0?null:Math.max(1,Math.ceil(r/t))}function ur(e){return{appType:`mobile-capacitor`,deviceClass:e.deviceClass||`mobile`,platform:e.platform===`ios`||e.platform===`android`?e.platform:`android`,arch:e.arch||`unknown`,channel:`stable`,currentVersion:e.currentVersion,instanceMode:`remote`,reportUsage:e.reportUsage===!0}}async function dr(e,t,n,r){try{if(H())try{let{CapacitorHttp:r}=await te(async()=>{let{CapacitorHttp:e}=await import(`./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js`).then(e=>e.i);return{CapacitorHttp:e}},__vite__mapDeps([0,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,url:typeof o.url==`string`?o.url:e,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,url:i.url,json:()=>i.json()}}catch{return null}}function fr(e,t){return e===`ios`?ir:`${rr}/download/v${t}/app-release.apk`}function pr(e,t,n){if(typeof e.latestVersion!=`string`||e.latestVersion.trim().length===0)return null;let r=e.latestVersion.trim(),i=sr(r,t);if(i<0)return null;let a=typeof e.releaseNotesUrl==`string`&&e.releaseNotesUrl.trim().length>0?e.releaseNotesUrl.trim():`${rr}/tag/v${r}`,o=typeof e.downloadUrl==`string`&&e.downloadUrl.trim().length>0?e.downloadUrl.trim():typeof e.download?.url==`string`&&e.download.url.trim().length>0?e.download.url.trim():fr(n,r);return{available:!!e.updateAvailable&&i>0,version:r,currentVersion:t,body:typeof e.releaseNotes==`string`?e.releaseNotes:void 0,releaseUrl:a,downloadUrl:o,nextSuggestedCheckInSec:typeof e.nextSuggestedCheckInSec==`number`&&Number.isFinite(e.nextSuggestedCheckInSec)?e.nextSuggestedCheckInSec:void 0}}async function mr(e,t,n,r){let i=await dr(e,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(ur(t))},n,r);if(!i?.ok)return null;let a;try{a=await i.json()}catch{return null}return pr(a,t.currentVersion,t.platform)}async function hr(e,t,n,r){let i=await dr(nr,{method:`GET`,headers:{Accept:`text/html`},redirect:`follow`},n,r);if(!i?.ok)return null;let a=typeof i.url==`string`&&i.url.length>0?i.url:nr,o=null;try{o=new URL(a).pathname.match(/\/releases\/tag\/v(\d+\.\d+\.\d+(?:-[\w.]+)?)/)}catch{return null}if(!o?.[1])return null;let s=o[1],c=sr(s,e),l=`${rr}/tag/v${s}`;return{available:c>0,version:s,currentVersion:e,releaseUrl:l,downloadUrl:fr(t,s)}}async function gr(e){let t=e.currentVersion?.trim()||`unknown`;if(t===`unknown`)return{available:!1,currentVersion:t,error:`Unable to check for mobile updates`};let n=e.fetchImpl??fetch,r=e.now??Date.now,i=cr(),a=r()+ar;for(let[t,o]of i.entries()){let s=lr(a,i.length-t+1,r);if(s===null)break;let c=await mr(o,e,s,n);if(c)return c}let o=lr(a,1,r);if(o!==null){let r=await hr(t,e.platform,o,n);if(r)return r}return{available:!1,currentVersion:t,error:`Unable to check for mobile updates`}}function _r(){if(typeof window>`u`)return`unknown`;try{let{deviceType:e}=cn();return e}catch{return`unknown`}}function vr(){let e=typeof window<`u`?window.__VSCODE_CONFIG__?.arch?.toLowerCase?.():void 0;if(e===`arm64`||e===`aarch64`)return`arm64`;if(e===`x64`||e===`amd64`||e===`x86_64`)return`x64`;let t=(typeof navigator<`u`?navigator.userAgentData:void 0)?.architecture?.toLowerCase?.();if(t===`arm`||t===`arm64`||t===`aarch64`)return`arm64`;if(t===`x86`||t===`x64`||t===`amd64`)return`x64`;let n=typeof navigator<`u`?navigator.userAgent.toLowerCase():``;return n.includes(`aarch64`)||n.includes(`arm64`)||n.includes(`armv`)?`arm64`:n.includes(`x86_64`)||n.includes(`x64`)||n.includes(`amd64`)||n.includes(`win64`)?`x64`:`unknown`}function yr(){let e=U();if(e===`android`||e===`ios`)return e;if(typeof navigator>`u`)return`web`;let t=(navigator.platform||``).toLowerCase();return t.includes(`mac`)?`macos`:t.includes(`win`)?`windows`:t.includes(`linux`)?`linux`:`web`}function br(e){let t=O.getState().reportUsage,n=new URLSearchParams({reportUsage:t?`true`:`false`});return n.set(`deviceClass`,_r()),n.set(`arch`,vr()),n.set(`platform`,yr()),e===`desktop`?(n.set(`appType`,`desktop-electron`),n.set(`instanceMode`,d()?`local`:`remote`),n):e===`vscode`?(n.set(`appType`,`vscode`),n.set(`instanceMode`,`local`),n):e===`mobile`?(n.set(`appType`,`mobile-capacitor`),n.set(`instanceMode`,`remote`),n):(n.set(`appType`,`web`),n.set(`instanceMode`,`unknown`),n)}async function xr(e,t){let n=t??`unknown`;try{let r=br(e),i=typeof window<`u`?window.__VSCODE_CONFIG__?.extensionVersion:void 0;t?r.set(`currentVersion`,t):e===`vscode`&&i&&r.set(`currentVersion`,i);let o=await a(`/api/yuri/update-check?${r.toString()}`,{method:`GET`,headers:{Accept:`application/json`}}),s=null;try{s=await o.json()}catch{s=null}if(!o.ok)return{available:!1,currentVersion:n,error:typeof s?.error==`string`&&s.error.trim().length>0?s.error.trim():`Server responded with ${o.status}`};if(!s)return{available:!1,currentVersion:n,error:`Update check returned an invalid response`};let c=typeof s.error==`string`&&s.error.trim().length>0?s.error.trim():void 0;return{available:s.available===!0,version:typeof s.version==`string`?s.version:void 0,currentVersion:typeof s.currentVersion==`string`?s.currentVersion:n,body:typeof s.body==`string`?s.body:void 0,releaseUrl:typeof s.releaseUrl==`string`?s.releaseUrl:void 0,downloadUrl:typeof s.downloadUrl==`string`?s.downloadUrl:void 0,nextSuggestedCheckInSec:typeof s.nextSuggestedCheckInSec==`number`&&Number.isFinite(s.nextSuggestedCheckInSec)?s.nextSuggestedCheckInSec:void 0,packageManager:typeof s.packageManager==`string`?s.packageManager:void 0,updateCommand:typeof s.updateCommand==`string`?s.updateCommand:void 0,error:c}}catch(e){return console.warn(`Failed to check for updates:`,e),{available:!1,currentVersion:n,error:e instanceof Error?e.message:`Failed to check for updates`}}}function Sr(){return H()?`mobile`:l()?`desktop`:m()?`vscode`:u()?`web`:null}var Cr={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null,otaDecision:null,otaPhase:`idle`,otaDownloadSkipped:!1,lastOtaChannelOverride:null};function wr(e,t){let n=e.isChannelRollback===!0?{isChannelRollback:!0}:{};if(e.primaryAction===`apply_ota`&&e.ota.bundle)return e.ota.bundle.releaseVersion===t?{available:!1,otaPhase:`idle`,info:{available:!1,currentVersion:t,nextSuggestedCheckInSec:e.nextCheckInSec,...n}}:{available:!0,otaPhase:`available`,info:{available:!0,version:e.ota.bundle.releaseVersion,currentVersion:t,downloadUrl:e.ota.bundle.url,nextSuggestedCheckInSec:e.nextCheckInSec,inAppApply:!0,...e.releaseNotes?{body:e.releaseNotes}:{},...n}};if(e.primaryAction===`install_native_required`){if(!e.native.version?.trim()||!e.native.installUrl?.trim())throw Error(`Native update required, but the update service supplied no complete installation target`);return{available:e.native.state===`required`||e.native.state===`available`,otaPhase:`idle`,info:{available:e.native.state===`required`||e.native.state===`available`,version:e.native.version,currentVersion:t,downloadUrl:e.native.installUrl,nextSuggestedCheckInSec:e.nextCheckInSec,manualUpdate:!0,...e.releaseNotes?{body:e.releaseNotes}:{},...n}}}return{available:!1,otaPhase:`idle`,info:{available:!1,currentVersion:t,nextSuggestedCheckInSec:e.nextCheckInSec,...n}}}var Tr=0,Er=_()((e,t)=>({...Cr,checkForUpdates:async()=>{let n=Sr();if(!n)return null;let r=++Tr;e({checking:!0,error:null,runtimeType:n});try{let i=null,a=null;if(n===`desktop`){let n=O.getState().otaChannelOverride;t().lastOtaChannelOverride!==n&&e({downloaded:!1,downloading:!1,available:!1,info:null,otaDecision:null,progress:null,otaPhase:`checking`});let i=await p(n);if(r!==Tr||O.getState().otaChannelOverride!==n)return null;let a=i?.downloaded===!0;return e({checking:!1,available:i?.available??!1,downloaded:a,...a?{downloading:!1,progress:null}:{},info:i,error:null,lastChecked:Date.now(),nextCheckInSec:i?.nextSuggestedCheckInSec??null,otaDecision:i?.otaDecision??null,otaPhase:a?`pending_restart`:i?.inAppApply?`available`:`idle`,lastOtaChannelOverride:n}),i?.nextSuggestedCheckInSec??null}if(n===`web`)i=await xr(`web`),a=i?.nextSuggestedCheckInSec??null;else if(n===`vscode`)a=(await xr(`vscode`))?.nextSuggestedCheckInSec??null;else if(n===`mobile`){let n=await ne()??`unknown`,r=H()?g()?.mobileUpdates:void 0,o=O.getState().otaChannelOverride;if(r)try{let i=t().lastOtaChannelOverride!==o;e(i?{otaDecision:null,otaPhase:`checking`,downloaded:!1,otaDownloadSkipped:!1,progress:null,available:!1,info:null}:{otaPhase:`checking`});let a=await r.checkForOtaUpdate(o===`beta`||o===`stable`?{channelOverride:o}:void 0),s=wr(a,n),c=(i?void 0:t().otaDecision?.ota.bundle?.bundleId)!==a.ota.bundle?.bundleId,l=!i&&t().downloaded&&!c;return e({checking:!1,available:s.available,info:s.info,error:s.info.error??null,lastChecked:Date.now(),nextCheckInSec:a.nextCheckInSec,otaDecision:a,otaPhase:l?`pending_restart`:s.otaPhase,lastOtaChannelOverride:o,...c||i?{downloaded:!1,otaDownloadSkipped:!1,progress:null}:{}}),a.nextCheckInSec}catch(t){if(!(t instanceof W)){let r=t instanceof Error?t.message:`Mobile OTA check failed`;return e({checking:!1,available:!1,info:{available:!1,currentVersion:n},error:r,lastChecked:Date.now(),otaDecision:null,otaPhase:`error`,lastOtaChannelOverride:o}),null}}return i=await gr({currentVersion:n,platform:yr()===`ios`?`ios`:`android`,deviceClass:_r(),arch:vr(),reportUsage:O.getState().reportUsage}),a=i?.nextSuggestedCheckInSec??null,e({checking:!1,available:i?.available??!1,info:i,error:i?.error??null,lastChecked:Date.now(),nextCheckInSec:a,otaDecision:null,otaPhase:`idle`}),a}return e({checking:!1,available:n===`vscode`?!1:i?.available??!1,info:n===`vscode`?null:i,error:n===`vscode`?null:i?.error??null,lastChecked:Date.now(),nextCheckInSec:a}),a}catch(i){return r===Tr&&e({checking:!1,error:i instanceof Error?i.message:`Failed to check for updates`,...n===`desktop`&&!t().downloaded?{otaPhase:`error`}:{}}),null}},downloadUpdate:async()=>{let{available:n,runtimeType:r,otaDecision:i,downloading:a,downloaded:o}=t();if(r===`mobile`&&i?.primaryAction===`apply_ota`&&i.ota.bundle){if(a||o)return;let t=g()?.mobileUpdates;if(!t){e({error:`Mobile OTA updates are unavailable in this runtime`,otaPhase:`error`});return}e({downloading:!0,error:null,progress:null,otaPhase:`downloading`,otaDownloadSkipped:!1});try{let{skipped:n}=await t.downloadOtaUpdate(i.ota.bundle);await t.queueOtaUpdateForNextLaunch(),e({downloading:!1,downloaded:!0,progress:null,otaPhase:`pending_restart`,otaDownloadSkipped:n})}catch(t){e({downloading:!1,error:t instanceof Error?t.message:`Failed to download update`,otaPhase:`error`})}return}if(!(r!==`desktop`||!n)){e({downloading:!0,error:null,progress:null});try{let n=O.getState().otaChannelOverride,r=await p(n);if(n!==O.getState().otaChannelOverride)throw Error(`OTA channel changed`);if(!r?.available||r.manualUpdate)throw Error(`Update detected, but desktop package is not ready yet. Retry in a moment.`);if(e(e=>({info:e.info?{...e.info,...r,body:r.body||e.info.body,available:e.info.available}:r})),r.downloaded||t().downloaded){e({downloading:!1,downloaded:!0,progress:null});return}if(r.downloading&&e({downloading:!0,progress:r.progress??{downloaded:0}}),!await f(t=>{e({progress:t})}))throw Error(`Failed to download update`);e({downloading:!1,downloaded:!0,progress:null,otaPhase:`pending_restart`})}catch(t){e({downloading:!1,error:t instanceof Error?t.message:`Failed to download update`})}}},subscribeDesktopUpdateEvents:async()=>{if(!l())return()=>{};let n=[],r=await s(n=>{let r=n.event,i=n.data??null;if(r===`Started`){if(!t().downloading)return;e({error:null,progress:{downloaded:0,total:typeof i?.contentLength==`number`?i.contentLength:void 0}});return}if(r===`Progress`){if(!t().downloading)return;e({progress:{downloaded:typeof i?.downloaded==`number`?i.downloaded:0,total:typeof i?.total==`number`?i.total:void 0}});return}r===`Finished`&&e({downloading:!1,downloaded:!0,progress:null})});r&&n.push(r);let i=await o(t=>{t.downloaded&&e({downloading:!1,downloaded:!0,available:!0,progress:null})});return i&&n.push(i),async()=>{for(let e of n)try{let t=e();t instanceof Promise&&await t}catch{}}},restartToUpdate:async()=>{let{downloaded:n,runtimeType:r,otaDecision:i}=t();if(r===`mobile`&&i?.primaryAction===`apply_ota`){if(!n)return;let t=g()?.mobileUpdates;if(!t){e({error:`Mobile OTA updates are unavailable in this runtime`,otaPhase:`error`});return}try{await t.applyOtaUpdateNow()}catch(t){e({error:t instanceof Error?t.message:`Failed to restart`,otaPhase:`error`})}return}if(!(r!==`desktop`||!n))try{if(!await c())throw Error(`Failed to restart`)}catch(t){e({error:t instanceof Error?t.message:`Failed to restart`})}},setOtaPhase:(t,n=null)=>{e({otaPhase:t,...n===void 0?{}:{error:n}})},setOtaDownloadPercent:n=>{if(!Number.isFinite(n)||n<0||n>100)return;let r=t();if(!r.downloading)return;let i=Math.round(n);if((r.progress?.total?Math.round(r.progress.downloaded/r.progress.total*100):null)===i)return;let a=r.otaDecision?.ota.bundle?.size;if(typeof a==`number`&&Number.isFinite(a)&&a>0){e({progress:{downloaded:Math.round(a*n/100),total:a}});return}e({progress:{downloaded:n,total:100}})},setOtaDownloadFailed:t=>{e({downloading:!1,downloaded:!1,error:t??`Failed to download update`,otaPhase:`error`})},dismiss:()=>{t().otaPhase!==`pending_restart`&&e({available:!1,downloaded:!1,info:null,otaDecision:null,otaPhase:`idle`,otaDownloadSkipped:!1})},reset:()=>{e(Cr)}})),Dr=8e3,Or=e=>!!(e&&![`succeeded`,`failed`].includes(e.status));function kr(e,t){if(e!==n()||t!==r())throw Error(`Stale update runtime`)}var Ar=(e=n(),t=r(),i)=>({queryKey:[e,`host-update`,t,i??`current`],queryFn:async({signal:n})=>{kr(e,t);let r=new AbortController,o=()=>r.abort();n.addEventListener(`abort`,o,{once:!0});let s;try{return await Promise.race([(async()=>{let n=await a(`/api/system/update${i?`?channel=${i}`:``}`,{headers:{Accept:`application/json`},signal:r.signal});if([404,501].includes(n.status))throw Error(`host_update_unsupported`);let o=await n.json();if(kr(e,t),!n.ok&&n.status!==502||typeof o.serverId!=`string`||typeof o.supported!=`boolean`||![`cli`,`electron`].includes(o.host))throw Error(`Host update check failed`);return o})(),new Promise((e,t)=>{s=setTimeout(()=>{r.abort(),t(Error(`host_update_timeout`))},Dr)})])}finally{s!==void 0&&clearTimeout(s),n.removeEventListener(`abort`,o)}},staleTime:6e4,retry:!1}),jr=(e=n(),t=r(),i)=>L.getQueryData(Ar(e,t,i).queryKey),Mr=(e=n(),t=r(),i)=>{let a=jr(e,t,i);return L.fetchQuery({...Ar(e,t,i),staleTime:a?.checkError||Or(a?.operation)?0:6e4})},Nr=(e=n(),t=r(),i)=>L.fetchQuery({...Ar(e,t,i),staleTime:0}),Pr=(e,t,n)=>{let r=(0,Z.c)(6),i;r[0]!==n||r[1]!==t||r[2]!==e?(i=Ar(e,t,n),r[0]=n,r[1]=t,r[2]=e,r[3]=i):i=r[3];let a;return r[4]===i?a=r[5]:(a={...i,refetchInterval:Ir,refetchIntervalInBackground:!1},r[4]=i,r[5]=a),I(a)};async function Fr(e,t,n){if(kr(t,n),!e.update)throw Error(`No update plan`);let r=await a(`/api/system/update`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({version:e.update.version,channel:e.channel,planId:e.update.planId,allowDowngrade:e.update.rollback===!0})});if(kr(t,n),!r.ok)throw Error(`Host update was not accepted`);let i=await r.json();if(typeof i.operation?.id!=`string`)throw Error(`Invalid update operation`);return i.operation}function Ir(e){return Or(e.state.data?.operation)?2e3:e.state.error?.message===`host_update_unsupported`?!1:e.state.error?15e3:3e5}function Lr(e){let t=new Date(`${e}T00:00:00`);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat(Ie(),{year:`numeric`,month:`short`,day:`numeric`}).format(t)}function Rr(e){return e.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,``).trim()}function zr(e){return e.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,`$1[@$2](https://github.com/$2)`)}function Br(e,t){let n=e.split(`.`).map(e=>Number.parseInt(e,10)),r=t.split(`.`).map(e=>Number.parseInt(e,10));for(let e=0;e<3;e+=1){let t=Number.isFinite(n[e])?n[e]:0,i=Number.isFinite(r[e])?r[e]:0;if(t!==i)return i-t}return 0}function Vr(e){let t=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[],r;for(;(r=t.exec(e))!==null;)n.push({version:r[1]??``,date:r[2]??``,start:r.index});return n.map((t,r)=>{let i=n[r+1]?.start??e.length;return{version:t.version,date:t.date,start:t.start,end:i,raw:e.slice(t.start,i).trim()}})}function Hr(e){let t=(0,Z.c)(67),{open:n,onOpenChange:r,model:i,onAction:a}=e,{t:o}=Fe(),[s,c]=(0,$.useState)(!1),l=Me(Wr),u;t[0]===l?u=t[1]:(u=e=>{let t=e.target.closest(`a`);t?.href&&(e.preventDefault(),e.stopPropagation(),l(t.href))},t[0]=l,t[1]=u);let d=Me(u),f;t[2]===i.fallbackCommand?f=t[3]:(f=async()=>{i.fallbackCommand&&(await Pe(i.fallbackCommand)).ok&&(c(!0),setTimeout(()=>c(!1),2e3))},t[2]=i.fallbackCommand,t[3]=f);let p=Me(f),m;if(t[4]!==i.body||t[5]!==o){bb0:{let e=i.body?.trim();if(!e){m=null;break bb0}let n=Vr(e);if(!n.length){m={kind:`raw`,title:o(`updateDialog.changelog.title`),content:zr(e)};break bb0}let r;t[7]===o?r=t[8]:(r=o(`updateDialog.changelog.title`),t[7]=o,t[8]=r),m={kind:`sections`,title:r,sections:[...n].sort(Ur).map(t=>({version:t.version,dateLabel:Lr(t.date),content:zr(Rr(t.raw)||e)}))}}t[4]=i.body,t[5]=o,t[6]=m}else m=t[6];let h=m,g=i.dismissible===!1?void 0:r,_=i.stableLayout&&`h-[min(38rem,calc(100dvh-2rem))] overflow-hidden transition-[opacity,transform,filter]`,v;t[9]===_?v=t[10]:(v=q(`max-w-4xl gap-0 p-4 sm:p-5 bg-background border-[var(--interactive-border)]`,_),t[9]=_,t[10]=v);let y;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Q.jsx)(X,{name:`download-cloud`,className:`h-5 w-5 text-[var(--primary-base)]`}),t[11]=y):y=t[11];let b;t[12]===i.title?b=t[13]:(b=(0,Q.jsxs)(ct,{className:`flex items-center gap-2`,children:[y,(0,Q.jsx)(`span`,{className:`font-semibold text-foreground`,children:i.title})]}),t[12]=i.title,t[13]=b);let x;t[14]!==i.currentVersion||t[15]!==i.methodLabel||t[16]!==i.version?(x=(i.currentVersion||i.version)&&(0,Q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1.5 pl-7 font-mono text-[11px] leading-4 tracking-[-0.01em] tabular-nums sm:text-xs`,children:[i.currentVersion&&(0,Q.jsx)(`span`,{className:`text-muted-foreground/75`,children:i.currentVersion}),i.currentVersion&&i.version&&(0,Q.jsx)(`span`,{className:`text-muted-foreground/40`,children:`→`}),i.version&&(0,Q.jsx)(`span`,{className:`font-medium text-[var(--primary-base)]`,children:i.version}),i.methodLabel&&(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,i.methodLabel]})]}),t[14]=i.currentVersion,t[15]=i.methodLabel,t[16]=i.version,t[17]=x):x=t[17];let S;t[18]===i.description?S=t[19]:(S=i.description&&(0,Q.jsx)(lt,{className:`mt-2`,children:i.description}),t[18]=i.description,t[19]=S);let C;t[20]!==S||t[21]!==b||t[22]!==x?(C=(0,Q.jsxs)(`div`,{className:`mb-3 shrink-0 pr-8 sm:mb-4`,children:[b,x,S]}),t[20]=S,t[21]=b,t[22]=x,t[23]=C):C=t[23];let w=i.stableLayout?`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto`:`space-y-3 sm:space-y-4`,T;t[24]===i.message?T=t[25]:(T=i.message&&(0,Q.jsx)(`p`,{role:`status`,className:`typography-ui-label text-muted-foreground`,children:i.message}),t[24]=i.message,t[25]=T);let E;t[26]===i.warning?E=t[27]:(E=i.warning&&(0,Q.jsx)(`p`,{className:`typography-meta text-[var(--status-warning)]`,children:i.warning}),t[26]=i.warning,t[27]=E);let D;t[28]!==h||t[29]!==d||t[30]!==i.hideChangelog||t[31]!==i.stableLayout?(D=h&&!i.hideChangelog&&(0,Q.jsxs)(`section`,{className:q(`overflow-hidden rounded-xl border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20`,i.stableLayout&&`flex min-h-0 flex-1 flex-col`),children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-[var(--surface-subtle)] px-3.5 py-2.5 sm:px-4 sm:py-3`,children:[(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-[var(--primary-base)]`,"aria-hidden":`true`}),(0,Q.jsx)(`h3`,{className:`typography-ui-caption font-medium text-muted-foreground`,children:h.title})]}),(0,Q.jsx)(pn,{className:i.stableLayout?`p-0`:`max-h-[min(42dvh,22rem)] p-0 sm:max-h-[400px]`,outerClassName:i.stableLayout?`flex-1`:void 0,fillContainer:!!i.stableLayout,children:h.kind===`raw`?(0,Q.jsx)(`div`,{className:`break-words p-3.5 text-[13px] leading-[1.65] text-foreground sm:p-4 sm:text-sm [&_.markdown-content]:leading-[1.65] [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline`,onClickCapture:d,children:(0,Q.jsx)(un,{content:h.content,disableLinkSafety:!0,enableFileReferences:!1})}):(0,Q.jsx)(`div`,{className:`divide-y divide-[var(--surface-subtle)]`,children:h.sections.map(e=>(0,Q.jsxs)(`div`,{className:`p-3.5 sm:p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-2.5 flex flex-wrap items-center gap-x-2 gap-y-1 sm:mb-3`,children:[(0,Q.jsxs)(`span`,{className:`rounded-md bg-[var(--primary-base)]/10 px-1.5 py-0.5 font-mono text-[11px] font-medium leading-4 text-[var(--primary-base)] tabular-nums sm:text-xs`,children:[`v`,e.version]}),(0,Q.jsx)(`span`,{className:`text-[11px] leading-4 text-muted-foreground/75 sm:text-xs`,children:e.dateLabel})]}),(0,Q.jsx)(`div`,{className:`break-words text-[13px] leading-[1.65] text-foreground sm:text-sm [&_.markdown-content]:leading-[1.65] [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline`,onClickCapture:d,children:(0,Q.jsx)(un,{content:e.content,disableLinkSafety:!0,enableFileReferences:!1})})]},e.version))})})]}),t[28]=h,t[29]=d,t[30]=i.hideChangelog,t[31]=i.stableLayout,t[32]=D):D=t[32];let O;t[33]!==s||t[34]!==p||t[35]!==i.fallbackCommand||t[36]!==o?(O=i.fallbackCommand&&(0,Q.jsxs)(`div`,{className:`space-y-2 mt-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 typography-meta text-muted-foreground`,children:[(0,Q.jsx)(X,{name:`terminal`,className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:o(`updateDialog.fallback.updateViaTerminal`)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]`,children:[(0,Q.jsx)(`code`,{className:`flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap`,children:i.fallbackCommand}),(0,Q.jsx)(`button`,{onClick:p,className:q(`flex items-center justify-center p-2 rounded`,`text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]`,`transition-colors`,s&&`text-[var(--status-success)]`),title:o(s?`updateDialog.actions.copied`:`updateDialog.actions.copyCommand`),children:(0,Q.jsx)(X,{name:s?`check`:`clipboard`,className:`h-4 w-4`})})]})]}),t[33]=s,t[34]=p,t[35]=i.fallbackCommand,t[36]=o,t[37]=O):O=t[37];let k;t[38]!==i.stableLayout||t[39]!==i.status?(k=i.status&&(0,Q.jsxs)(`div`,{role:`status`,className:q(`space-y-2`,i.stableLayout&&`min-h-9 shrink-0`),children:[(0,Q.jsxs)(`div`,{className:`flex h-5 items-center justify-between gap-3`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-xs font-medium text-muted-foreground sm:text-[13px]`,children:[i.status.kind===`activity`&&(0,Q.jsx)(X,{name:`loader`,className:`h-3.5 w-3.5 shrink-0 animate-spin text-[var(--primary-base)]`}),(0,Q.jsx)(`span`,{className:`truncate`,title:i.status.label,children:i.status.label})]}),i.status.progress!=null&&(0,Q.jsxs)(`span`,{className:`shrink-0 font-mono text-[11px] leading-4 text-foreground tabular-nums sm:text-xs`,children:[Math.round(i.status.progress),`%`]})]}),(0,Q.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-[var(--surface-subtle)] sm:h-1.5`,children:i.status.progress==null?(0,Q.jsx)(`div`,{className:`h-full w-1/3 animate-pulse rounded-full bg-[var(--primary-base)]/60`}):(0,Q.jsx)(`div`,{className:`h-full rounded-full bg-[var(--primary-base)] transition-[width] duration-500`,style:{width:`${i.status.progress}%`}})}),i.status.detail&&(0,Q.jsx)(`p`,{className:`text-xs leading-4 text-muted-foreground`,children:i.status.detail})]}),t[38]=i.stableLayout,t[39]=i.status,t[40]=k):k=t[40];let A;t[41]===i.error?A=t[42]:(A=i.error&&(0,Q.jsx)(`div`,{role:`alert`,className:`p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg`,children:(0,Q.jsx)(`p`,{className:`text-sm text-[var(--status-error)]`,children:i.error})}),t[41]=i.error,t[42]=A);let j;t[43]!==w||t[44]!==T||t[45]!==E||t[46]!==D||t[47]!==O||t[48]!==k||t[49]!==A?(j=(0,Q.jsxs)(`div`,{className:w,children:[T,E,D,O,k,A]}),t[43]=w,t[44]=T,t[45]=E,t[46]=D,t[47]=O,t[48]=k,t[49]=A,t[50]=j):j=t[50];let M;t[51]===i.notice?M=t[52]:(M=i.notice&&(0,Q.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-lg border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-3 py-2.5 text-sm text-[var(--status-success)]`,children:[(0,Q.jsx)(X,{name:`check`,className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`span`,{children:i.notice})]}),t[51]=i.notice,t[52]=M);let N;t[53]!==i.actions||t[54]!==i.releaseLink||t[55]!==a?(N=(i.releaseLink||i.actions.length>0)&&(0,Q.jsxs)(`div`,{className:`mt-4 flex shrink-0 items-center justify-between gap-4`,children:[i.releaseLink&&(0,Q.jsxs)(`a`,{href:i.releaseLink.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1.5 typography-ui-label text-muted-foreground hover:text-foreground transition-colors shrink-0`,children:[(0,Q.jsx)(X,{name:`external-link`,className:`h-4 w-4`}),i.releaseLink.label]}),(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-nowrap items-center justify-end gap-2`,children:i.actions.map(e=>(0,Q.jsxs)(J,{onClick:()=>a(e.id),disabled:e.disabled,variant:e.variant??`default`,size:`default`,className:`min-w-0 shrink`,title:e.label,children:[e.icon&&(0,Q.jsx)(X,{name:e.icon,className:q(`h-4 w-4`,e.loading&&`animate-spin`)}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id))})]}),t[53]=i.actions,t[54]=i.releaseLink,t[55]=a,t[56]=N):N=t[56];let P;t[57]!==C||t[58]!==j||t[59]!==M||t[60]!==N||t[61]!==v?(P=(0,Q.jsxs)(st,{className:v,showCloseButton:!0,children:[C,j,M,N]}),t[57]=C,t[58]=j,t[59]=M,t[60]=N,t[61]=v,t[62]=P):P=t[62];let F;return t[63]!==n||t[64]!==P||t[65]!==g?(F=(0,Q.jsx)(ut,{open:n,onOpenChange:g,children:P}),t[63]=n,t[64]=P,t[65]=g,t[66]=F):F=t[66],F}function Ur(e,t){return Br(e.version,t.version)}function Wr(e){dn(e)}var Gr=`https://github.com/yee94/yuri/releases`,Kr=2e3,qr=6e5,Jr=e=>e.transport===n()&&e.generation===r();async function Yr(e,t){try{if(!Jr(t))return{success:!1};let n=await Mr(t.transport,t.generation);return!Jr(t)||!e||!n.supported||n.update?.version!==e||n.update.rollback?{success:!1}:(await Fr(n,t.transport,t.generation),{success:!0,autoRestart:!0})}catch(e){return{success:!1,error:e instanceof Error?e.message:void 0}}}async function Xr(e,t,n=Math.ceil(qr/Kr),r=Kr){for(let i=0;i<n;i++){if(!Jr(t))return!1;try{let n=await Nr(t.transport,t.generation);if(n.operation?.status===`failed`)return!1;if(n.currentVersion===e&&n.operation?.status===`succeeded`&&Jr(t))return!0}catch{}await new Promise(e=>setTimeout(e,r))}return!1}var Zr=e=>{let t=(0,Z.c)(108),{open:i,onOpenChange:a,info:o,downloading:s,downloaded:c,progress:l,error:u,onDownload:d,onRestart:f,runtimeType:p}=e,m=p===void 0?`desktop`:p,{t:h}=Fe(),[g,_]=(0,$.useState)(`idle`),[v,y]=(0,$.useState)(null),b=Er(Qr),x=o?.releaseUrl||(o?.version?`${Gr}/tag/v${o.version}`:Gr),S=o?.downloadUrl,C=m===`web`,w=m===`mobile`,T=w&&o?.manualUpdate===!0&&!!S,E=w&&o?.inAppApply===!0,D=m===`desktop`&&o?.manualUpdate===!0,O=g!==`idle`&&g!==`error`,k=w?S:x,A;t[0]!==c||t[1]!==E||t[2]!==a?(A=e=>{!e&&E&&c&&Er.getState().dismiss(),a(e)},t[0]=c,t[1]=E,t[2]=a,t[3]=A):A=t[3];let j=Me(A),M,N;t[4]===i?(M=t[5],N=t[6]):(M=()=>{i||(_(`idle`),y(null))},N=[i],t[4]=i,t[5]=M,t[6]=N),(0,$.useEffect)(M,N);let P;t[7]!==o?.version||t[8]!==h?(P=async()=>{let e={transport:n(),generation:r()};_(`updating`),y(null);let t=await Yr(o?.version,e);if(!Jr(e))return;if(!t.success){_(`error`),y(t.error||h(`updateDialog.error.updateFailed`));return}t.autoRestart&&(_(`restarting`),await new Promise($r)),_(`reconnecting`);let i=await Xr(o?.version,e);Jr(e)&&(i?window.location.reload():(_(`error`),y(h(`updateDialog.error.takingLonger`))))},t[7]=o?.version,t[8]=h,t[9]=P):P=t[9];let F=Me(P),I;t[10]!==F||t[11]!==w||t[12]!==d||t[13]!==a||t[14]!==f||t[15]!==S||t[16]!==x||t[17]!==m?(I=e=>{bb107:switch(e){case`download`:d(),m===`desktop`&&a(!1);break bb107;case`restart`:f();break bb107;case`later`:Er.getState().dismiss(),a(!1);break bb107;case`open-external`:{let e=w?S:x;e&&dn(e);break bb107}case`web-update`:F()}},t[10]=F,t[11]=w,t[12]=d,t[13]=a,t[14]=f,t[15]=S,t[16]=x,t[17]=m,t[18]=I):I=t[18];let L=Me(I),R;if(t[19]!==c||t[20]!==s||t[21]!==E||t[22]!==D||t[23]!==w||t[24]!==C||t[25]!==O||t[26]!==T||t[27]!==h){if(R=[],!C&&(!w||E)){if(!D&&!c&&!s){let e;t[29]!==E||t[30]!==h?(e=h(E?`updateDialog.actions.applyOtaNow`:`updateDialog.actions.downloadUpdate`),t[29]=E,t[30]=h,t[31]=e):e=t[31];let n;t[32]===e?n=t[33]:(n={id:`download`,icon:`download`,label:e},t[32]=e,t[33]=n),R.push(n)}if(D&&!c&&!s){let e;t[34]===h?e=t[35]:(e=h(`updateDialog.actions.openMobileUpdate`),t[34]=h,t[35]=e);let n;t[36]===e?n=t[37]:(n={id:`open-external`,icon:`external-link`,label:e},t[36]=e,t[37]=n),R.push(n)}if(s){let e;t[38]===h?e=t[39]:(e=h(`updateDialog.status.downloading`),t[38]=h,t[39]=e);let n;t[40]===e?n=t[41]:(n={id:`downloading`,icon:`loader`,loading:!0,disabled:!0,label:e},t[40]=e,t[41]=n),R.push(n)}if(c){if(E){let e;t[42]===h?e=t[43]:(e=h(`updateDialog.actions.later`),t[42]=h,t[43]=e);let n;t[44]===e?n=t[45]:(n={id:`later`,variant:`ghost`,label:e},t[44]=e,t[45]=n),R.push(n)}let e;t[46]===h?e=t[47]:(e=h(`updateDialog.actions.restartToUpdate`),t[46]=h,t[47]=e);let n;t[48]===e?n=t[49]:(n={id:`restart`,icon:`restart`,label:e},t[48]=e,t[49]=n),R.push(n)}}if(w&&!E&&T){let e;t[50]===h?e=t[51]:(e=h(`updateDialog.actions.openMobileUpdate`),t[50]=h,t[51]=e);let n;t[52]===e?n=t[53]:(n={id:`open-external`,icon:`external-link`,label:e},t[52]=e,t[53]=n),R.push(n)}if(C){let e;t[54]!==O||t[55]!==h?(e=O?{id:`updating`,icon:`loader`,loading:!0,disabled:!0,label:h(`updateDialog.status.updating`)}:{id:`web-update`,icon:`download`,label:h(`updateDialog.actions.updateNow`)},t[54]=O,t[55]=h,t[56]=e):e=t[56],R.push(e)}t[19]=c,t[20]=s,t[21]=E,t[22]=D,t[23]=w,t[24]=C,t[25]=O,t[26]=T,t[27]=h,t[28]=R}else R=t[28];let z;t[57]!==h||t[58]!==g?(z=h(g===`restarting`||g===`reconnecting`?`updateDialog.header.updating`:`updateDialog.header.updateAvailable`),t[57]=h,t[58]=g,t[59]=z):z=t[59];let B=o?.currentVersion,ee=o?.version,te=o?.body,V=!O,H=u||v,U=C&&g===`error`?o?.updateCommand||`yuri update`:void 0,ne;t[60]!==c||t[61]!==E||t[62]!==b||t[63]!==h?(ne=E&&c&&b?h(`updateDialog.status.otaBundleReused`):void 0,t[60]=c,t[61]=E,t[62]=b,t[63]=h,t[64]=ne):ne=t[64];let W;t[65]!==w||t[66]!==k||t[67]!==T?(W=(!w||T)&&k?{url:k,label:`GitHub`}:void 0,t[65]=w,t[66]=k,t[67]=T,t[68]=W):W=t[68];let re;if(t[69]!==R||t[70]!==s||t[71]!==E||t[72]!==w||t[73]!==C||t[74]!==O||t[75]!==l||t[76]!==h||t[77]!==te||t[78]!==V||t[79]!==H||t[80]!==U||t[81]!==ne||t[82]!==W||t[83]!==z||t[84]!==B||t[85]!==ee||t[86]!==g){if(re={title:z,currentVersion:B,version:ee,body:te,hideChangelog:O,dismissible:V,error:H,fallbackCommand:U,notice:ne,releaseLink:W,actions:R},C&&O){let e;t[88]!==h||t[89]!==g?(e=h(g===`updating`?`updateDialog.status.installingUpdate`:g===`restarting`?`updateDialog.status.serverRestarting`:`updateDialog.status.waitingForServer`),t[88]=h,t[89]=g,t[90]=e):e=t[90];let n;t[91]===h?n=t[92]:(n=h(`updateDialog.status.autoReloadHint`),t[91]=h,t[92]=n);let r;t[93]!==e||t[94]!==n?(r={kind:`activity`,label:e,detail:n},t[93]=e,t[94]=n,t[95]=r):r=t[95],re.status=r}if(!C&&(!w||E)&&s){let e;t[96]===h?e=t[97]:(e=h(`updateDialog.status.downloadingPayload`),t[96]=h,t[97]=e);let n;t[98]===l?n=t[99]:(n=l?.total?Math.round(l.downloaded/l.total*100):0,t[98]=l,t[99]=n);let r;t[100]!==e||t[101]!==n?(r={kind:`download`,label:e,progress:n},t[100]=e,t[101]=n,t[102]=r):r=t[102],re.status=r}t[69]=R,t[70]=s,t[71]=E,t[72]=w,t[73]=C,t[74]=O,t[75]=l,t[76]=h,t[77]=te,t[78]=V,t[79]=H,t[80]=U,t[81]=ne,t[82]=W,t[83]=z,t[84]=B,t[85]=ee,t[86]=g,t[87]=re}else re=t[87];let ie;return t[103]!==L||t[104]!==j||t[105]!==re||t[106]!==i?(ie=(0,Q.jsx)(Hr,{open:i,onOpenChange:j,model:re,onAction:L}),t[103]=L,t[104]=j,t[105]=re,t[106]=i,t[107]=ie):ie=t[107],ie};function Qr(e){return e.otaDownloadSkipped}function $r(e){return setTimeout(e,2e3)}var ei=e(C(),1);function ti(e){let t=(0,Z.c)(10),{children:n,actions:r,className:i}=e,a;t[0]===i?a=t[1]:(a=q(`flex shrink-0 items-center justify-between gap-3 py-3`,i),t[0]=i,t[1]=a);let o;t[2]===n?o=t[3]:(o=(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:n}),t[2]=n,t[3]=o);let s;t[4]===r?s=t[5]:(s=(0,Q.jsx)(`div`,{className:`flex max-w-[70%] shrink-0 flex-wrap items-center justify-end gap-2 [&_button]:max-w-full [&_button]:whitespace-normal`,children:r}),t[4]=r,t[5]=s);let c;return t[6]!==a||t[7]!==o||t[8]!==s?(c=(0,Q.jsxs)(`header`,{"data-settings-action-header":``,className:a,children:[o,s]}),t[6]=a,t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function ni(e){let t=(0,Z.c)(21),{label:n,actions:r,children:i,description:a,itemId:o,ariaLabel:s,className:c,cardClassName:l,cardId:u}=e,d=typeof n==`string`&&/^[\p{Script=Latin}\p{Number}\p{Punctuation}\p{Separator}]+$/u.test(n)?`latin`:void 0,f;t[0]===c?f=t[1]:(f=q(`yuri-settings-group`,c),t[0]=c,t[1]=f);let p;t[2]!==r||t[3]!==n||t[4]!==d?(p=r?(0,Q.jsx)(ti,{className:`py-0`,actions:r,children:n?(0,Q.jsx)(`div`,{className:`yuri-settings-group-label`,"data-settings-label-script":d,children:n}):null}):n?(0,Q.jsx)(`div`,{className:`yuri-settings-group-label`,"data-settings-label-script":d,children:n}):null,t[2]=r,t[3]=n,t[4]=d,t[5]=p):p=t[5];let m;t[6]===l?m=t[7]:(m=q(`yuri-settings-group-card`,l),t[6]=l,t[7]=m);let h;t[8]!==u||t[9]!==i||t[10]!==o||t[11]!==m?(h=(0,Q.jsx)(`div`,{id:u,"data-settings-item":o,className:m,children:i}),t[8]=u,t[9]=i,t[10]=o,t[11]=m,t[12]=h):h=t[12];let g;t[13]===a?g=t[14]:(g=a?(0,Q.jsx)(`p`,{className:`yuri-settings-group-description text-muted-foreground`,children:a}):null,t[13]=a,t[14]=g);let _;return t[15]!==s||t[16]!==f||t[17]!==p||t[18]!==h||t[19]!==g?(_=(0,Q.jsxs)(`section`,{className:f,"aria-label":s,children:[p,h,g]}),t[15]=s,t[16]=f,t[17]=p,t[18]=h,t[19]=g,t[20]=_):_=t[20],_}function ri(e){let t=(0,Z.c)(20),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]):({label:s,description:a,descriptionPlacement:l,ariaLabel:n,groupClassName:o,cardClassName:r,children:i,...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?`inside`:l,d=u===`outside`?a:void 0,f=u===`inside`?a:void 0,p;t[9]!==i||t[10]!==s||t[11]!==c||t[12]!==f?(p=(0,Q.jsx)(ii,{label:s,description:f,...c,children:i}),t[9]=i,t[10]=s,t[11]=c,t[12]=f,t[13]=p):p=t[13];let m;return t[14]!==n||t[15]!==r||t[16]!==o||t[17]!==d||t[18]!==p?(m=(0,Q.jsx)(ni,{ariaLabel:n,className:o,cardClassName:r,description:d,children:p}),t[14]=n,t[15]=r,t[16]=o,t[17]=d,t[18]=p,t[19]=m):m=t[19],m}function ii(e){let t=(0,Z.c)(22),{label:n,children:r,description:i,itemId:a,className:o,copyClassName:s,controlClassName:c}=e,l;t[0]===o?l=t[1]:(l=q(`yuri-settings-group-row yuri-settings-split-row`,o),t[0]=o,t[1]=l);let u;t[2]===s?u=t[3]:(u=q(`yuri-settings-split-row-copy`,s),t[2]=s,t[3]=u);let d;t[4]===n?d=t[5]:(d=n?(0,Q.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n}):null,t[4]=n,t[5]=d);let f;t[6]===i?f=t[7]:(f=i?(0,Q.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i}):null,t[6]=i,t[7]=f);let p;t[8]!==u||t[9]!==d||t[10]!==f?(p=(0,Q.jsxs)(`div`,{className:u,children:[d,f]}),t[8]=u,t[9]=d,t[10]=f,t[11]=p):p=t[11];let m;t[12]===c?m=t[13]:(m=q(`yuri-settings-split-row-control`,c),t[12]=c,t[13]=m);let h;t[14]!==r||t[15]!==m?(h=(0,Q.jsx)(`div`,{"data-settings-value":``,className:m,children:r}),t[14]=r,t[15]=m,t[16]=h):h=t[16];let g;return t[17]!==a||t[18]!==l||t[19]!==p||t[20]!==h?(g=(0,Q.jsxs)(`div`,{"data-settings-item":a,className:l,children:[p,h]}),t[17]=a,t[18]=l,t[19]=p,t[20]=h,t[21]=g):g=t[21],g}function ai(e){let t=(0,Z.c)(32),{checked:n,onChange:r,label:i,ariaLabel:a,description:o,itemId:s,disabled:c,className:l}=e,u=c!==void 0&&c,d;t[0]!==n||t[1]!==u||t[2]!==r?(d=()=>{u||r(!n)},t[0]=n,t[1]=u,t[2]=r,t[3]=d):d=t[3];let f=d,p=oi,m=u?`cursor-not-allowed`:`cursor-pointer`,h;t[4]!==l||t[5]!==m?(h=q(`yuri-settings-group-row yuri-settings-split-row group`,m,l),t[4]=l,t[5]=m,t[6]=h):h=t[6];let g=u?-1:0,_=u||void 0,v,y;t[7]===f?(v=t[8],y=t[9]):(v=e=>{p(e.target)||f()},y=e=>{p(e.target)||(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),f())},t[7]=f,t[8]=v,t[9]=y);let b;t[10]===i?b=t[11]:(b=(0,Q.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:i}),t[10]=i,t[11]=b);let x;t[12]===o?x=t[13]:(x=o?(0,Q.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:o}):null,t[12]=o,t[13]=x);let S;t[14]!==x||t[15]!==b?(S=(0,Q.jsxs)(`div`,{className:`yuri-settings-split-row-copy`,children:[b,x]}),t[14]=x,t[15]=b,t[16]=S):S=t[16];let C;t[17]!==a||t[18]!==n||t[19]!==u||t[20]!==r?(C=(0,Q.jsx)(`div`,{"data-settings-value":``,className:`yuri-settings-split-row-control`,children:(0,Q.jsx)(vt,{checked:n,onChange:r,disabled:u,ariaLabel:a})}),t[17]=a,t[18]=n,t[19]=u,t[20]=r,t[21]=C):C=t[21];let w;return t[22]!==n||t[23]!==s||t[24]!==S||t[25]!==C||t[26]!==h||t[27]!==g||t[28]!==_||t[29]!==v||t[30]!==y?(w=(0,Q.jsxs)(`div`,{"data-settings-item":s,className:h,role:`button`,tabIndex:g,"aria-pressed":n,"aria-disabled":_,onClick:v,onKeyDown:y,children:[S,C]}),t[22]=n,t[23]=s,t[24]=S,t[25]=C,t[26]=h,t[27]=g,t[28]=_,t[29]=v,t[30]=y,t[31]=w):w=t[31],w}function oi(e){return e instanceof HTMLElement&&e.closest(`button, a, input, select, textarea`)!==null}function si(e,t){return e===`checking`?5:e===`downloading`?5+Math.min(Math.max(t??0,0),100)*.75:e===`installing`?85:e===`restarting`?95:100}function ci(e,t,n){let r=e?.operation,i=e?.update,a=i??(r&&t.updateDetails&&r.planId===t.updateDetails.planId&&r.version===t.updateDetails.version?t.updateDetails:void 0),o=Or(r),s=e?.supported===!1||t.failure===`unsupported`,c={title:n(`settings.yuri.about.hostUpdate.title`),stableLayout:!0,description:n(`settings.yuri.about.hostUpdate.description`),currentVersion:e?.currentVersion??t.versionFallback,version:i?.version??r?.version,body:a||r?a?.releaseNotes||n(`settings.yuri.about.hostUpdate.noNotes`):void 0,warning:!o&&i?.rollback?n(`settings.yuri.about.hostUpdate.downgrade`):void 0,actions:o||t.submitting||t.completed||!i?[]:[{id:`confirm`,icon:`download`,label:n(`settings.yuri.about.hostUpdate.confirm`),disabled:!e?.supported||!!t.failure||!!t.checking}]};return o&&r?c.status={kind:r.status===`downloading`?`download`:`activity`,label:n(t.failure===`disconnected`?`settings.yuri.about.hostUpdate.reconnecting`:`settings.yuri.about.hostUpdate.status.${r.status}`),progress:si(r.status,r.progress)}:t.completed&&!i?c.status={kind:`download`,label:n(`settings.yuri.about.hostUpdate.status.succeeded`),progress:100}:t.submitting?c.status={kind:`activity`,label:n(`settings.yuri.about.state.checking`),progress:0}:t.checking===`initial`?c.status={kind:`activity`,label:n(`settings.yuri.about.state.checking`)}:s?c.message=n(`settings.yuri.about.hostUpdate.unsupported`):t.failure?c.error=n(t.failure===`disconnected`?`settings.yuri.about.hostUpdate.reconnecting`:`settings.yuri.about.toast.checkFailed`):!i&&e?.supported&&(c.message=r?.status===`succeeded`?n(`settings.yuri.about.hostUpdate.status.succeeded`):n(`settings.yuri.about.toast.latestVersion`)),r?.status===`failed`&&(c.error=n(`settings.yuri.about.hostUpdate.status.failed`)),c}function li(){let e=(0,Z.c)(7),{t:i}=Fe(),a=$.useSyncExternalStore(t,n,n),o=$.useSyncExternalStore(t,r,r),s=`${a}:${o}`,c;e[0]===i?c=e[1]:(c=i(`settings.yuri.about.state.unknown`),e[0]=i,e[1]=c);let l;return e[2]!==o||e[3]!==s||e[4]!==c||e[5]!==a?(l=(0,Q.jsx)(ui,{transport:a,generation:o,version:c},s),e[2]=o,e[3]=s,e[4]=c,e[5]=a,e[6]=l):l=e[6],l}function ui({version:e,transport:t,generation:i,itemId:a,channel:o}){let{t:s}=Fe(),c=N(),[l,u]=$.useState(!1),d=O(e=>e.otaChannelOverride),f=o??d??void 0,p=Pr(t,i,f),m=p.data,h=m?.operation,g=Or(h),_=JSON.stringify([t,i,f??`current`]),[v,y]=$.useState(null);m?.update&&(v?.scope!==_||v.update!==m.update)&&y({scope:_,update:m.update});let b=P({mutationFn:({plan:e})=>Fr(e,t,i),onSuccess:(e,a)=>{t===n()&&i===r()&&c.setQueryData(Ar(t,i,a.channel).queryKey,t=>t&&{...t,operation:e})},onSettled:(e,a,o)=>{t===n()&&i===r()&&c.invalidateQueries({queryKey:Ar(t,i,o.channel).queryKey,exact:!0})}}),[x,S]=$.useState(null);l&&g&&h&&h.id!==x&&S(h.id);let C=h?.status===`succeeded`&&h.id===x,w=s(`settings.yuri.about.hostUpdate.status.succeeded`);$.useEffect(()=>{!C||p.isError||t!==n()||i!==r()||(S(null),u(!1),Y.success(w,{id:`host-update:${t}:${i}:${x}`}))},[C,p.isError,t,i,x,w]);let T=$.useRef(null),E=Me(()=>_),D=Me(async()=>{if(g){u(!0),p.refetch({cancelRefetch:!1});return}if(T.current===_)return;let e=_;T.current=e;try{let a=await p.refetch({cancelRefetch:!1});if(e!==E()||t!==n()||i!==r())return;if(a.isError||!a.data||a.data.checkError){a.error?.message===`host_update_unsupported`?Y.info(s(`settings.yuri.about.hostUpdate.unsupported`)):Y.error(s(`settings.yuri.about.toast.checkFailed`));return}Or(a.data.operation)?u(!0):a.data.supported?a.data.update?u(!0):(u(!1),Y.success(s(`settings.yuri.about.toast.latestVersion`))):Y.info(s(`settings.yuri.about.hostUpdate.unsupported`))}finally{T.current===e&&(T.current=null)}}),k=m?.supported===!1||!g&&p.error?.message===`host_update_unsupported`,A=p.isError||!!m?.checkError,j=b.isError&&b.variables?.channel===f,M=ci(m,{versionFallback:e,checking:p.isPending?`initial`:p.isFetching?`refresh`:!1,submitting:b.isPending,failure:k?`unsupported`:p.isError&&(g||j)?`disconnected`:A||j?`check`:null,completed:C,updateDetails:v?.scope===_?v.update:void 0},s),F=Me(e=>{e===`confirm`&&m?.update&&b.mutate({plan:m,channel:f})});return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,"data-settings-item":a,children:[(0,Q.jsxs)(`span`,{className:`relative typography-ui-label font-mono text-foreground text-right`,children:[m?.currentVersion??e,m?.update&&!g&&(0,Q.jsx)(`span`,{"aria-label":s(`settings.yuri.about.hostUpdate.available`),className:`absolute -right-1.5 -top-0.5 size-1.5 rounded-full bg-[var(--status-error)]`})]}),(0,Q.jsx)(J,{type:`button`,size:`icon`,variant:`ghost`,onClick:D,disabled:p.isFetching&&!g,"aria-label":s(`settings.yuri.about.hostUpdate.title`),title:s(`settings.yuri.about.hostUpdate.title`),children:(0,Q.jsx)(X,{name:g||p.isFetching?`loader`:m?.update?`download`:`refresh`,className:g||p.isFetching?`size-4 animate-spin`:`size-4`})})]}),(0,Q.jsx)(Hr,{open:l,onOpenChange:u,model:M,onAction:F})]})}var di=e=>{let t=e?.trim();return t?{location:{directory:t}}:void 0},fi=()=>{let e=T.getSdkClient().plugin;if(!e?.list||!e.check||!e.update)throw Error(`OpenCode plugin status is not available`);return e},pi=e=>{switch(e.type){case`package`:return{kind:`package`,target:e.target,version:e.version??null,outdated:e.outdated===!0,updating:e.updating===!0};case`local`:return{kind:`local`,path:e.path};case`builtin`:case`sdk`:return{kind:`builtin`};default:throw Error(`Unexpected plugin source: ${JSON.stringify(e)}`)}},mi=e=>{if(e.status===`active`)return{kind:`active`};if(e.status===`failed`)return{kind:`failed`,error:e.error,ref:e.ref??null};throw Error(`Unexpected plugin state: ${JSON.stringify(e)}`)},hi=e=>({source:pi(e.source),state:mi(e.state)}),gi=e=>{if(!Array.isArray(e))throw Error(`OpenCode plugin status payload is invalid`);return e.map(e=>hi(e))};async function _i(e,t){return gi((await fi().list(di(e),t?{signal:t}:void 0))?.data)}async function vi(e,t){return gi((await fi().check(di(e),t?{signal:t}:void 0))?.data)}async function yi(e,t,n){let r=t.trim();if(!r)throw Error(`plugin.update requires a target`);await fi().update({...di(e),targets:[r]},n?{signal:n}:void 0)}function bi(e){return e instanceof Error&&e.message.trim()?e.message:typeof e==`string`&&e.trim()?e:`plugin operation failed`}var xi=1500,Si=e=>e?.trim()||null,Ci=(e,t=n())=>z.plugins.list(e,t),wi=(e,t,r=!1,i=n())=>z.plugins.registry(e,t,r,i),Ti=(e,t=n())=>z.plugins.runtime(e,t),Ei=0,Di=()=>(Ei+=1,Ei),Oi=()=>{Ei+=1},ki=(e,t,n)=>e.getQueryData(Ti(t,n)),Ai=(e=We(),t=n())=>{let r=Si(e);return{queryKey:Ci(r,t),queryFn:async({signal:e})=>{let t=await a(Vi(`/api/config/plugins`,r),{headers:Wi(r),signal:e});if(!t.ok)throw Error(`Failed to load plugins`);let n=await t.json();return{entries:n.entries??[],files:n.files??[]}},staleTime:5e3,retry:2}},ji=(e,t,r=!1,i=n())=>{let o=Si(e),s=R(t);return{queryKey:wi(o,s,r,i),queryFn:async({signal:e})=>{let t={};for(let n of Ui(s)){let i=await a(Hi(n,r,o),{headers:Wi(o),signal:e});if(!i.ok)throw Error(`Failed to load plugin registry info`);let s=await i.json();for(let e of s.results??[])t[e.spec]=e}return t},staleTime:r?0:3e5,retry:2}},Mi=(e=We(),t=n())=>{let r=Si(e);return{queryKey:Ti(r,t),queryFn:async({signal:e})=>{let n=Di(),i=await _i(r,e);if(n!==Ei){let e=ki(L,r,t);if(e)return e;throw Error(`Stale plugin runtime read`)}return i},staleTime:5e3,retry:!1}},Ni=e=>{let t=(0,Z.c)(7),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let r=n,i=et(Gi),a;t[2]===i?a=t[3]:(a=Ai(Si(i)??Si(T.getDirectory())),t[2]=i,t[3]=a);let o;return t[4]!==r.enabled||t[5]!==a?(o={...a,enabled:r.enabled},t[4]=r.enabled,t[5]=a,t[6]=o):o=t[6],I(o)},Pi=(e,t)=>{let n=(0,Z.c)(6),r=t!==void 0&&t,i=et(Ki),a;n[0]!==i||n[1]!==r||n[2]!==e?(a=ji(Si(i)??Si(T.getDirectory()),e,r),n[0]=i,n[1]=r,n[2]=e,n[3]=a):a=n[3];let o;return n[4]===a?o=n[5]:(o={...a},n[4]=a,n[5]=o),I(o)},Fi=()=>{let e=(0,Z.c)(2),t=et(qi),n;return e[0]===t?n=e[1]:(n=Si(t)??Si(T.getDirectory()),e[0]=t,e[1]=n),n},Ii=e=>{let t=(0,Z.c)(7),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let r=n,i=Fi(),a;t[2]===i?a=t[3]:(a=Mi(i),t[2]=i,t[3]=a);let o;return t[4]!==r.enabled||t[5]!==a?(o={...a,enabled:r.enabled},t[4]=r.enabled,t[5]=a,t[6]=o):o=t[6],I(o)},Li=async(e,t,r)=>{let i=Si(t);return n()===r?e.fetchQuery({...Ai(i,r),staleTime:0}):e.getQueryData(Ci(i,r))??{entries:[],files:[]}},Ri=async(e=L,t,r)=>{let i=Si(t),a=n(),o=await ji(i,r,!0,a).queryFn({signal:new AbortController().signal});return e.setQueryData(wi(i,r,!1,a),o),o},zi=async(e,t,r)=>{let i=Si(t);if(n()!==r)return ki(e,i,r);let a=Di(),o=await _i(i);return a!==Ei||n()!==r?ki(e,i,r):(e.setQueryData(Ti(i,r),o),o)},Bi=async(e=We(),t=L)=>{let r=Si(e),i=n(),a=await vi(r);return Oi(),n()===i&&t.setQueryData(Ti(r,i),a),a};function Vi(e,t){return`${e}${t?`?directory=${encodeURIComponent(t)}`:``}`}function Hi(e,t,n){let r=new URLSearchParams;t&&r.set(`refresh`,`true`),n&&r.set(`directory`,n);let i=r.toString();return`/api/config/plugins/registry?${`specs=${e.map(encodeURIComponent).join(`,`)}`}${i?`&${i}`:``}`}function Ui(e){let t=[],n=[],r=0;for(let i of e){let e=encodeURIComponent(i),a=n.length===0?e.length:r+1+e.length;if(n.length>0&&a>xi){t.push(n),n=[i],r=e.length;continue}n.push(i),r=a}return n.length>0&&t.push(n),t}function Wi(e){return e?{"x-opencode-directory":e}:void 0}function Gi(e){return e.getActiveProject?.()?.path??null}function Ki(e){return e.getActiveProject?.()?.path??null}function qi(e){return e.getActiveProject?.()?.path??null}var Ji=()=>{try{let e=et.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();let t=T.getDirectory();if(t?.trim())return t.trim()}catch(e){console.warn(`[PluginsStore] Error resolving config directory:`,e)}return null},Yi=5e3,Xi=`__default__`,Zi=new Map,Qi=new Map,$i=1500,ea=e=>e?.trim()||Xi,ta=e=>{Zi.delete(ea(e))},na=_()(y(v((e,t)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:t=>e({selectedId:t}),setDraft:t=>e({draft:t}),loadPlugins:async i=>{let a=Ji(),o=n(),s=r(),c=()=>o===n()&&s===r()&&a===Ji(),l=ea(a),u=Date.now(),d=Zi.get(l)??0,f=t().entries.length>0||t().files.length>0;if(!i?.force&&f&&u-d<Yi)return!0;let p=Qi.get(l);if(!i?.force&&p)return p;let m=(async()=>{e({isLoading:!0});try{let n=i?.force?await Li(L,a,o):await L.fetchQuery(Ai(a,o));return c()?(e({entries:n.entries??[],files:n.files??[],isLoading:!1}),Zi.set(l,Date.now()),i?.force||t().loadRegistryInfo(),!0):!1}catch(t){return console.error(`[PluginsStore] Failed to load plugins:`,t),c()&&e({isLoading:!1}),!1}})();Qi.set(l,m);try{return await m}finally{Qi.delete(l)}},loadRegistryInfo:async n=>{let r=aa(n?.specs??t().entries.map(e=>e.spec));if(r.length===0){e({isLoadingRegistry:!1});return}e({isLoadingRegistry:!0});try{let i=Ji(),o={...t().registryInfo};for(let e of oa(r)){let t=await a(ia(e,n?.force===!0,i),{headers:sa(i)});if(!t.ok)throw Error(`Failed to load plugin registry info`);let r=await da(t);for(let e of r.results??[])o[e.spec]=e}e({registryInfo:o,isLoadingRegistry:!1})}catch(t){console.error(`[PluginsStore] Failed to load plugin registry info:`,t),e({isLoadingRegistry:!1})}},updateToLatest:async e=>{let n=t().entries.find(t=>t.id===e);if(!n)return{ok:!1};let r=t().registryInfo[n.spec];return!r||r.kind!==`npm-ok`||!r.hasUpdate||!r.latestVersion?{ok:!1}:await t().updateEntry(e,{spec:`${r.name}@${r.latestVersion}`})},createEntry:async e=>{let n=await ua(async t=>await a(ra(`/api/config/plugins/entry`,t),{method:`POST`,headers:ca(t),body:JSON.stringify(la(e))}));return n.ok&&t().loadRegistryInfo({specs:[e.spec],force:!0}),n},updateEntry:async(e,r)=>{let i=(L.getQueryData(Ai(Ji(),n()).queryKey)?.entries??t().entries).find(t=>t.id===e),o=i?.spec,s=r.spec??o,c=await ua(async t=>await a(ra(`/api/config/plugins/entry/${encodeURIComponent(e)}`,t),{method:`PATCH`,headers:ca(t),body:JSON.stringify(la(r))}),i&&s?{...i,spec:s}:void 0);return c.ok&&s&&t().loadRegistryInfo({specs:[s],force:!0}),c},deleteEntry:async n=>{let r=t().entries.find(e=>e.id===n),i=await ua(async e=>await a(ra(`/api/config/plugins/entry/${encodeURIComponent(n)}`,e),{method:`DELETE`,headers:sa(e)}));if(i.ok&&t().selectedId===n&&e({selectedId:null}),i.ok&&r){let n={...t().registryInfo};delete n[r.spec],e({registryInfo:n})}return i},readFile:async e=>{try{let t=Ji(),n=await a(ra(`/api/config/plugins/file/${encodeURIComponent(e)}`,t),{headers:sa(t)});if(!n.ok)throw Error(`Failed to read plugin file`);return await da(n)}catch(e){return console.error(`[PluginsStore] Failed to read plugin file:`,e),null}},createFile:async e=>ua(async t=>await a(ra(`/api/config/plugins/file`,t),{method:`POST`,headers:ca(t),body:JSON.stringify(e)})),updateFile:async(e,t)=>ua(async n=>await a(ra(`/api/config/plugins/file/${encodeURIComponent(e)}`,n),{method:`PUT`,headers:ca(n),body:JSON.stringify(t)})),deleteFile:async n=>{let r=await ua(async e=>await a(ra(`/api/config/plugins/file/${encodeURIComponent(n)}`,e),{method:`DELETE`,headers:sa(e)}));return r.ok&&t().selectedId===n&&e({selectedId:null}),r},getById:e=>t().entries.find(t=>t.id===e)??t().files.find(t=>t.id===e)}),{name:`plugins-store`,storage:D(),partialize:e=>({selectedId:e.selectedId})}),{name:`plugins-store`}));function ra(e,t){return`${e}${t?`?directory=${encodeURIComponent(t)}`:``}`}function ia(e,t,n){let r=new URLSearchParams;t&&r.set(`refresh`,`true`),n&&r.set(`directory`,n);let i=r.toString();return`/api/config/plugins/registry?${`specs=${e.map(encodeURIComponent).join(`,`)}`}${i?`&${i}`:``}`}function aa(e){return Array.from(new Set(e.map(e=>e.trim()).filter(Boolean)))}function oa(e){let t=[],n=[],r=0;for(let i of e){let e=encodeURIComponent(i),a=n.length===0?e.length:r+1+e.length;n.length>0&&a>$i?(t.push(n),n=[i],r=e.length):(n.push(i),r=a)}return n.length>0&&t.push(n),t}function sa(e){return e?{"x-opencode-directory":e}:void 0}function ca(e){return{"Content-Type":`application/json`,...e?{"x-opencode-directory":e}:{}}}function la(e){let t={};return e.spec!==void 0&&(t.spec=e.spec),e.options!==void 0&&(t.options=e.options),e.scope!==void 0&&(t.scope=e.scope),t}async function ua(e,t){let i=n(),a=r();try{let o=Ji(),s=await e(o),c=await da(s).catch(()=>null);if(!s.ok)throw Error(c?.error||`Failed to update plugin configuration`);if(i!==n()||a!==r())return{ok:!0};ta(o);let l=await Li(L,o,i);if(o===Ji()&&i===n()&&a===r()){let e=t&&na.getState().selectedId===t.id?l.entries.find(e=>e.spec===t.spec&&e.scope===t.scope&&e.sourcePath===t.sourcePath):void 0;na.setState({entries:l.entries,files:l.files,...e?{selectedId:e.id}:{}}),Zi.set(ea(o),Date.now())}return{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}}catch(e){return console.error(`[PluginsStore] Failed to update plugin configuration:`,e),{ok:!1}}}async function da(e){return await e.json()}var fa=e=>e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e),pa=e=>{let t=e.replace(/\\/g,`/`),n=[],[r,...i]=t.split(`/`);for(let e of i)if(e!==``&&e!==`.`){if(e===`..`){n.pop();continue}n.push(e)}return`${/^[A-Za-z]:$/.test(r)?`${r.toUpperCase()}/`:`/`}${n.join(`/`)}`},ma=e=>pa(`${e.replace(/\\/g,`/`)}/..`),ha=e=>{try{let t=decodeURIComponent(new URL(e).pathname);return/^\/[A-Za-z]:\//.test(t)?t.slice(1):t}catch{return null}};function ga(e,t){if(e.startsWith(`file://`)){let t=ha(e);return t?{kind:`local`,path:pa(t)}:null}return e.startsWith(`./`)||e.startsWith(`../`)?t?{kind:`local`,path:pa(`${ma(t)}/${e}`)}:null:fa(e)?{kind:`local`,path:pa(e)}:{kind:`package`,target:e}}function _a(e){return e?{kind:`local`,path:pa(e)}:null}var va=(e,t)=>{if(e.kind===`package`)return t.source.kind===`package`&&t.source.target===e.target;if(t.source.kind!==`local`)return!1;let n=pa(t.source.path);return n===e.path||n.startsWith(`${e.path}/`)};function ya(e,t){return t.filter(t=>va(e,t))}function ba(e){for(let t of e)if(t.state.kind===`active`&&t.source.kind===`package`&&t.source.version?.trim())return t.source.version.trim();return null}function xa(e){let t=e.find(e=>e.state.kind===`failed`);if(t&&t.state.kind===`failed`)return{kind:`failed`,error:t.state.error,ref:t.state.ref};let n=e[0];return n?{kind:`active`,version:n.source.kind===`package`?n.source.version:null}:{kind:`notReported`}}function Sa(e){let t=e.flatMap(e=>e.source.kind===`package`?[e.source]:[]);return t.some(e=>e.updating)?`updating`:t.some(e=>e.outdated)?`available`:`none`}function Ca(){let e=(0,Z.c)(5),t=Ni(),n=Ii(),r=t.data?.entries,i=t.data?.files,a=n.data,o;bb0:{if(!a){let t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],o=t;break bb0}let t;if(e[1]!==r||e[2]!==i||e[3]!==a){t=[];let n=(e,n,r)=>{if(!r)return;let i=xa(ya(r,a));i.kind===`failed`&&t.push({id:e,label:n,error:i.error})};for(let e of r??[])n(e.id,e.spec,ga(e.spec,e.sourcePath));for(let e of i??[])n(e.id,e.fileName,_a(e.absolutePath));e[1]=r,e[2]=i,e[3]=a,e[4]=t}else t=e[4];o=t}return o}var wa=e=>{let t=(0,Z.c)(217),{providerId:n,modelId:r,variant:i,onChange:a,className:o,allowedProviderIds:s,allowedModelIdsByProvider:c,placeholder:l,tooltipsEnabled:u,dropdownPortalToBody:d,showIcon:f,providers:p}=e,m=u===void 0||u,h=d!==void 0&&d,g=f===void 0||f,{t:_}=Fe(),{isReady:v,isUnavailable:y}=en(),b=nt(Ta),x=p??b,S=nt(Ea),C=O(Da),w=O(Oa),T=O(ka),E=O(Aa),D=O(ja),k=O(Ma),A;t[0]!==r||t[1]!==n?(A={currentProviderID:n,currentModelID:r},t[0]=r,t[1]=n,t[2]=A):A=t[2];let{favoriteModelsList:j,recentModelsList:M}=xt(A),{isMobile:N}=sn(),P=C||N,[F,I]=$.useState(!1),[L,R]=$.useState(!1),z;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(z=()=>{I(!0),nt.getState().refreshCatalogsOnPickerOpen({source:`modelSelector:mobilePanel`})},t[3]=z):z=t[3];let B=Me(z),ee;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(ee=e=>{R(e),e&&nt.getState().refreshCatalogsOnPickerOpen({source:`modelSelector:desktopMenu`})},t[4]=ee):ee=t[4];let te=Me(ee),[V,H]=$.useState(``),[U,ne]=$.useState(null),W=i!==void 0,re;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(re=()=>{I(!1),R(!1),H(``),ne(null)},t[5]=re):re=t[5];let ie=re,ae;t[6]===x?ae=t[7]:(ae=e=>{let t=x.find(t=>t.id===e.providerID)?.models?.find(t=>t.id===e.modelID);return t?.variants?Object.keys(t.variants):[]},t[6]=x,t[7]=ae);let oe=ae,se;t[8]!==D||t[9]!==oe||t[10]!==r||t[11]!==a||t[12]!==n||t[13]!==i||t[14]!==W?(se=e=>{let t=oe(e),o=e.providerID===n&&e.modelID===r,s=e.variant!==void 0&&t.includes(e.variant)?e.variant:void 0,c=o&&i&&t.includes(i)?i:s??``;a(e.providerID,e.modelID,W?c:void 0),D(e.providerID,e.modelID,W&&c||void 0),ie()},t[8]=D,t[9]=oe,t[10]=r,t[11]=a,t[12]=n,t[13]=i,t[14]=W,t[15]=se):se=t[15];let ce=se,le;t[16]!==a||t[17]!==W?(le=()=>{a(``,``,W?``:void 0),ie()},t[16]=a,t[17]=W,t[18]=le):le=t[18];let ue=le,de;t[19]!==D||t[20]!==a||t[21]!==U?(de=e=>{U&&(a(U.providerID,U.modelID,e),D(U.providerID,U.modelID,e||void 0),ie())},t[19]=D,t[20]=a,t[21]=U,t[22]=de):de=t[22];let fe=de,pe;t[23]===_?pe=t[24]:(pe=_(`settings.agents.modelSelector.searchPlaceholder`),t[23]=_,t[24]=pe);let me;t[25]===_?me=t[26]:(me=_(`settings.agents.modelSelector.state.noModelsFound`),t[25]=_,t[26]=me);let he;t[27]===_?he=t[28]:(he=_(`settings.agents.modelSelector.section.favorites`),t[27]=_,t[28]=he);let ge;t[29]===_?ge=t[30]:(ge=_(`settings.agents.modelSelector.section.recent`),t[29]=_,t[30]=ge);let G;t[31]===_?G=t[32]:(G=_(`settings.agents.modelSelector.keyboardHints`),t[31]=_,t[32]=G);let _e;t[33]!==l||t[34]!==_?(_e=l||_(`settings.agents.modelSelector.notSelected`),t[33]=l,t[34]=_,t[35]=_e):_e=t[35];let ve;t[36]===_?ve=t[37]:(ve=_(`settings.agents.modelSelector.actions.favorite`),t[36]=_,t[37]=ve);let ye;t[38]===_?ye=t[39]:(ye=_(`settings.agents.modelSelector.actions.unfavorite`),t[38]=_,t[39]=ye);let be;t[40]===_?be=t[41]:(be=_(`chat.modelControls.provider`),t[40]=_,t[41]=be);let xe;t[42]===_?xe=t[43]:(xe=_(`chat.modelControls.capabilities`),t[42]=_,t[43]=xe);let Se;t[44]===_?Se=t[45]:(Se=_(`chat.modelControls.capability.toolCalling`),t[44]=_,t[45]=Se);let Ce;t[46]===_?Ce=t[47]:(Ce=_(`chat.modelControls.capability.reasoning`),t[46]=_,t[47]=Ce);let K;t[48]===_?K=t[49]:(K=_(`chat.modelControls.modality.image`),t[48]=_,t[49]=K);let we;t[50]===_?we=t[51]:(we=_(`chat.modelControls.modality.video`),t[50]=_,t[51]=we);let Te;t[52]===_?Te=t[53]:(Te=_(`chat.modelControls.modality.audio`),t[52]=_,t[53]=Te);let Ee;t[54]===_?Ee=t[55]:(Ee=_(`chat.modelControls.costPerMillion`),t[54]=_,t[55]=Ee);let De;t[56]===_?De=t[57]:(De=_(`chat.modelControls.costInput`),t[56]=_,t[57]=De);let Oe;t[58]===_?Oe=t[59]:(Oe=_(`chat.modelControls.costOutput`),t[58]=_,t[59]=Oe);let ke;t[60]!==pe||t[61]!==me||t[62]!==he||t[63]!==ge||t[64]!==G||t[65]!==_e||t[66]!==ve||t[67]!==ye||t[68]!==be||t[69]!==xe||t[70]!==Se||t[71]!==Ce||t[72]!==K||t[73]!==we||t[74]!==Te||t[75]!==Ee||t[76]!==De||t[77]!==Oe?(ke={searchPlaceholder:pe,noResults:me,favorites:he,recent:ge,keyboardHint:G,notSelected:_e,favorite:ve,unfavorite:ye,provider:be,capabilities:xe,capabilityToolCalling:Se,capabilityReasoning:Ce,modalityImage:K,modalityVideo:we,modalityAudio:Te,costPerMillion:Ee,costInput:De,costOutput:Oe},t[60]=pe,t[61]=me,t[62]=he,t[63]=ge,t[64]=G,t[65]=_e,t[66]=ve,t[67]=ye,t[68]=be,t[69]=xe,t[70]=Se,t[71]=Ce,t[72]=K,t[73]=we,t[74]=Te,t[75]=Ee,t[76]=De,t[77]=Oe,t[78]=ke):ke=t[78];let Ae=ke,je;t[79]!==r||t[80]!==n?(je=n&&r?{providerID:n,modelID:r}:null,t[79]=r,t[80]=n,t[81]=je):je=t[81];let Ne=je,Pe;t[82]!==r||t[83]!==l||t[84]!==n||t[85]!==_?(Pe=n&&r?`${n}/${r}`:l||_(`settings.agents.modelSelector.notSelected`),t[82]=r,t[83]=l,t[84]=n,t[85]=_,t[86]=Pe):Pe=t[86];let Ie=Pe,J;t[87]!==_||t[88]!==i||t[89]!==W?(J=W?i||_(`chat.modelControls.default`):null,t[87]=_,t[88]=i,t[89]=W,t[90]=J):J=t[90];let Le=J,Re;t[91]!==r||t[92]!==n||t[93]!==i||t[94]!==W?(Re=(e,t)=>{if(!(!W||e!==n||t!==r))return i||void 0},t[91]=r,t[92]=n,t[93]=i,t[94]=W,t[95]=Re):Re=t[95];let ze=Re,Be;t[96]!==D||t[97]!==a||t[98]!==W?(Be=(e,t,n)=>{a(e,t,W?n??``:void 0),D(e,t,W&&n||void 0),ie()},t[96]=D,t[97]=a,t[98]=W,t[99]=Be):Be=t[99];let Ve=Be,He;t[100]!==oe||t[101]!==_||t[102]!==i||t[103]!==W?(He=(e,t)=>{let n=oe(e);if(!W||n.length===0)return null;let r=e.variant!==void 0&&n.includes(e.variant)?e.variant:void 0,a=t.isSelected?i:r??``;return(0,Q.jsxs)(`button`,{type:`button`,className:`flex shrink-0 items-center gap-0.5 rounded-md px-1.5 py-0.5 typography-micro font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,onClick:t=>{t.preventDefault(),t.stopPropagation(),ne(e)},"aria-label":_(`chat.modelControls.showThinkingModes`),children:[(0,Q.jsx)(`span`,{className:`max-w-24 truncate`,children:a||_(`chat.modelControls.default`)}),(0,Q.jsx)(X,{name:`arrow-right-s`,className:`size-3.5`})]})},t[100]=oe,t[101]=_,t[102]=i,t[103]=W,t[104]=He):He=t[104];let Ue=He,We=P?`max-h-none flex-1`:void 0,Ge=m&&(P?F:L),Ke;t[105]===E?Ke=t[106]:(Ke=e=>E(e.providerID,e.modelID),t[105]=E,t[106]=Ke);let qe;t[107]!==r||t[108]!==n||t[109]!==T||t[110]!==i?(qe=e=>T(e.providerID,e.modelID,e.providerID===n&&e.modelID===r?i||void 0:e.variant),t[107]=r,t[108]=n,t[109]=T,t[110]=i,t[111]=qe):qe=t[111];let Je;t[112]!==c||t[113]!==s||t[114]!==j||t[115]!==S||t[116]!==ce||t[117]!==ue||t[118]!==w||t[119]!==Ae||t[120]!==k||t[121]!==x||t[122]!==M||t[123]!==Ue||t[124]!==V||t[125]!==Ne||t[126]!==We||t[127]!==Ge||t[128]!==Ke||t[129]!==qe?(Je=(0,Q.jsx)(yt,{providers:x,providerOrder:k,favoriteModels:j,recentModels:M,getMetadata:S,searchQuery:V,onSearchQueryChange:H,onSelect:ce,labels:Ae,selectedModel:Ne,hiddenModels:w,allowedProviderIds:s,allowedModelIdsByProvider:c,includeNotSelected:!0,onSelectNone:ue,onEscape:ie,maxHeightClassName:We,tooltipsEnabled:Ge,isFavorite:Ke,onToggleFavorite:qe,renderRowEnd:Ue}),t[112]=c,t[113]=s,t[114]=j,t[115]=S,t[116]=ce,t[117]=ue,t[118]=w,t[119]=Ae,t[120]=k,t[121]=x,t[122]=M,t[123]=Ue,t[124]=V,t[125]=Ne,t[126]=We,t[127]=Ge,t[128]=Ke,t[129]=qe,t[130]=Je):Je=t[130];let Ye=Je,Xe;t[131]!==oe||t[132]!==U?(Xe=U?oe(U):[],t[131]=oe,t[132]=U,t[133]=Xe):Xe=t[133];let Ze=Xe,Y;bb0:{if(!U){Y=``;break bb0}if(U.providerID===n&&U.modelID===r){Y=i||``;break bb0}Y=U.variant!==void 0&&Ze.includes(U.variant)?U.variant:``}let Qe=Y,$e;t[134]!==fe||t[135]!==_||t[136]!==U||t[137]!==Qe||t[138]!==Ze?($e=U?(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Q.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:()=>ne(null),"aria-label":_(`header.actions.backAria`),children:[(0,Q.jsx)(X,{name:`arrow-left`,className:`size-4`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:U.modelID})]}),(0,Q.jsx)(`div`,{className:`space-y-1 p-2`,role:`listbox`,"aria-label":_(`chat.modelControls.thinking`),children:[``,...Ze].map(e=>{let t=Qe===e;return(0,Q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,className:q(`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:()=>fe(e),children:[(0,Q.jsx)(`span`,{className:`truncate`,children:e||_(`chat.modelControls.default`)}),t?(0,Q.jsx)(X,{name:`check`,className:`size-4 shrink-0`}):null]},e||`__default`)})})]}):null,t[134]=fe,t[135]=_,t[136]=U,t[137]=Qe,t[138]=Ze,t[139]=$e):$e=t[139];let et=$e||Ye;if(P){let e=v?B:void 0,a=!v,l=!v&&`opacity-60 cursor-not-allowed`,u;t[140]!==o||t[141]!==l?(u=q(`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`,l,o),t[140]=o,t[141]=l,t[142]=u):u=t[142];let d;t[143]!==v||t[144]!==y||t[145]!==r||t[146]!==n||t[147]!==g||t[148]!==_?(d=v?g&&(n||r)?(0,Q.jsx)(bt,{modelId:r,providerId:n,className:`h-3.5 w-3.5 flex-shrink-0`}):g?(0,Q.jsx)(X,{name:`pencil-ai`,className:`h-3 w-3 text-muted-foreground`}):null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:_(y?`common.unavailable`:`common.loading`)})]}),t[143]=v,t[144]=y,t[145]=r,t[146]=n,t[147]=g,t[148]=_,t[149]=d):d=t[149];let f;t[150]!==v||t[151]!==Ie?(f=v?(0,Q.jsx)(`span`,{className:`typography-meta font-medium text-foreground truncate`,children:Ie}):null,t[150]=v,t[151]=Ie,t[152]=f):f=t[152];let p;t[153]!==v||t[154]!==Le?(p=v&&Le?(0,Q.jsx)(`span`,{className:`shrink-0 typography-micro text-muted-foreground`,children:Le}):null,t[153]=v,t[154]=Le,t[155]=p):p=t[155];let m;t[156]!==d||t[157]!==f||t[158]!==p?(m=(0,Q.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,Q.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0 text-muted-foreground`}),t[160]=h):h=t[160];let b;t[161]!==e||t[162]!==a||t[163]!==u||t[164]!==m?(b=(0,Q.jsxs)(`button`,{type:`button`,onClick:e,disabled:a,className:u,children:[m,h]}),t[161]=e,t[162]=a,t[163]=u,t[164]=m,t[165]=b):b=t[165];let C;t[166]!==j||t[167]!==r||t[168]!==n||t[169]!==M||t[170]!==T||t[171]!==i?(C=(e,t)=>T(e,t,e===n&&t===r?i||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]=r,t[168]=n,t[169]=M,t[170]=T,t[171]=i,t[172]=C):C=t[172];let D;t[173]!==c||t[174]!==s||t[175]!==j||t[176]!==S||t[177]!==Ve||t[178]!==w||t[179]!==E||t[180]!==F||t[181]!==r||t[182]!==n||t[183]!==k||t[184]!==x||t[185]!==M||t[186]!==ze||t[187]!==C||t[188]!==W?(D=(0,Q.jsx)(Bt,{open:F,onClose:ie,selectedProviderID:n,selectedModelID:r,resolveSelectedVariant:ze,onSelect:Ve,providers:x,favoriteModels:j,recentModels:M,getMetadata:S,hiddenModels:w,allowedProviderIds:s,allowedModelIdsByProvider:c,providerOrder:k,variantSelectionEnabled:W,isFavorite:E,onToggleFavorite:C}),t[173]=c,t[174]=s,t[175]=j,t[176]=S,t[177]=Ve,t[178]=w,t[179]=E,t[180]=F,t[181]=r,t[182]=n,t[183]=k,t[184]=x,t[185]=M,t[186]=ze,t[187]=C,t[188]=W,t[189]=D):D=t[189];let O;return t[190]!==b||t[191]!==D?(O=(0,Q.jsxs)(Q.Fragment,{children:[b,D]}),t[190]=b,t[191]=D,t[192]=O):O=t[192],O}let tt=v&&L,rt=v?te:void 0,it=!v&&`opacity-60 cursor-not-allowed`,at;t[193]!==o||t[194]!==it?(at=q(`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`,it,o),t[193]=o,t[194]=it,t[195]=at):at=t[195];let ot;t[196]!==v||t[197]!==y||t[198]!==r||t[199]!==n||t[200]!==g||t[201]!==_||t[202]!==Ie||t[203]!==Le?(ot=v?(0,Q.jsxs)(Q.Fragment,{children:[g?n||r?(0,Q.jsx)(bt,{modelId:r,providerId:n,className:`h-3.5 w-3.5 flex-shrink-0`}):(0,Q.jsx)(X,{name:`pencil-ai`,className:`h-3.5 w-3.5 flex-shrink-0 text-muted-foreground`}):null,(0,Q.jsx)(`span`,{className:`typography-ui-label min-w-0 flex-1 truncate text-left font-normal text-foreground`,children:Ie}),Le?(0,Q.jsx)(`span`,{className:`shrink-0 typography-micro text-muted-foreground`,children:Le}):null]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0`}),(0,Q.jsx)(`span`,{className:`typography-ui-label font-normal whitespace-nowrap text-muted-foreground`,children:_(y?`common.unavailable`:`common.loading`)})]}),t[196]=v,t[197]=y,t[198]=r,t[199]=n,t[200]=g,t[201]=_,t[202]=Ie,t[203]=Le,t[204]=ot):ot=t[204];let st;t[205]===Symbol.for(`react.memo_cache_sentinel`)?(st=(0,Q.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 flex-shrink-0 text-muted-foreground/50`}),t[205]=st):st=t[205];let ct;t[206]!==at||t[207]!==ot?(ct=(0,Q.jsx)(Xt,{asChild:!0,children:(0,Q.jsxs)(`div`,{className:at,children:[ot,st]})}),t[206]=at,t[207]=ot,t[208]=ct):ct=t[208];let lt;t[209]!==h||t[210]!==et?(lt=(0,Q.jsx)($t,{className:`w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col`,align:`start`,portalToBody:h,children:et}),t[209]=h,t[210]=et,t[211]=lt):lt=t[211];let ut;return t[212]!==tt||t[213]!==rt||t[214]!==ct||t[215]!==lt?(ut=(0,Q.jsxs)(an,{open:tt,onOpenChange:rt,children:[ct,lt]}),t[212]=tt,t[213]=rt,t[214]=ct,t[215]=lt,t[216]=ut):ut=t[216],ut};function Ta(e){return e.providers}function Ea(e){return e.getModelMetadata}function Da(e){return e.isMobile}function Oa(e){return e.hiddenModels}function ka(e){return e.toggleFavoriteModel}function Aa(e){return e.isFavoriteModel}function ja(e){return e.addRecentModel}function Ma(e){return e.providerOrder}var Na=e=>{let t=(0,Z.c)(41),{agentName:n,onChange:r,className:i,filter:a,dropdownPortalToBody:o,showIcon:s,agents:c}=e,l=o!==void 0&&o,u=s===void 0||s,{t:d}=Fe(),{isReady:f,isUnavailable:p}=en(),m=nt(Pa),h=Le(Fa),g=nt(Ia),{data:_}=Ke(),v;t[0]===_?v=t[1]:(v=_===void 0?[]:_,t[0]=_,t[1]=v);let y=v,b;bb0:{if(c){b=c;break bb0}if(Array.isArray(m)&&m.length>0){b=m;break bb0}b=y}let x=b,S;if(t[2]!==a||t[3]!==x){let e=Be(x);S=a?e.filter(a):e,t[2]=a,t[3]=x,t[4]=S}else S=t[4];let C=S,w=O(La),{isMobile:T}=sn(),E=w||T,[D,k]=$.useState(!1),A;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(A=()=>{k(!0),nt.getState().refreshCatalogsOnPickerOpen({source:`agentSelector:mobilePanel`})},t[5]=A):A=t[5];let j=Me(A),M=Me(Ra),N=$.useId(),P,F;t[6]!==c||t[7]!==h||t[8]!==g||t[9]!==x.length?(P=()=>{c||x.length>0||(g(),h())},F=[c,x.length,g,h],t[6]=c,t[7]=h,t[8]=g,t[9]=x.length,t[10]=P,t[11]=F):(P=t[10],F=t[11]),$.useEffect(P,F);let I;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(I=()=>k(!1),t[12]=I):I=t[12];let L=I,R;t[13]===r?R=t[14]:(R=e=>{r(e)},t[13]=r,t[14]=R);let z=R,B;t[15]!==n||t[16]!==C||t[17]!==z||t[18]!==E||t[19]!==D||t[20]!==N||t[21]!==d?(B=()=>E?(0,Q.jsx)(ln,{id:`mobile-agent-selector-sheet-${N}`,open:D,onOpenChange:e=>{e||L()},ariaLabel:d(`settings.commands.agentSelector.title`),closeAriaLabel:d(`mobile.surface.closeAria`),resizeAriaLabel:d(`mobile.sessions.sheet.resizeAria`),bodyClassName:`px-2`,children:(0,Q.jsxs)(pn,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`flex flex-col gap-1 overscroll-contain`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:q(`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`,n?`text-foreground`:`bg-primary/10 text-primary`),onClick:()=>{z(``),L()},children:[(0,Q.jsx)(rt,{name:`default`,size:16}),(0,Q.jsx)(`span`,{className:q(`min-w-0 typography-meta`,n?`text-muted-foreground`:`font-medium`),children:d(`settings.commands.agentSelector.notSelected`)}),!n&&(0,Q.jsx)(`div`,{className:`h-2 w-2 rounded-full bg-primary`})]}),C.map(e=>{let t=e.name===n;return(0,Q.jsxs)(`button`,{type:`button`,className:q(`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:()=>{z(e.name),L()},children:[(0,Q.jsx)(rt,{name:e.name,size:16,className:`mt-1.5`}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`typography-meta font-medium`,children:e.name}),e.description&&(0,Q.jsx)(`span`,{className:`mt-0.5 block whitespace-normal break-words typography-micro text-muted-foreground`,children:e.description})]}),t&&(0,Q.jsx)(`div`,{className:`mt-2 h-2 w-2 rounded-full bg-primary`})]},e.name)})]})}):null,t[15]=n,t[16]=C,t[17]=z,t[18]=E,t[19]=D,t[20]=N,t[21]=d,t[22]=B):B=t[22];let ee=B,te;t[23]!==n||t[24]!==C||t[25]!==i||t[26]!==l||t[27]!==z||t[28]!==M||t[29]!==E||t[30]!==f||t[31]!==p||t[32]!==j||t[33]!==u||t[34]!==d?(te=E?(0,Q.jsxs)(`button`,{type:`button`,onClick:f?j:void 0,disabled:!f,className:q(`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`,!f&&`opacity-60 cursor-not-allowed`,i),children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:f?(0,Q.jsxs)(Q.Fragment,{children:[u?(0,Q.jsx)(rt,{name:n||`default`,size:14}):null,(0,Q.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:n||d(`settings.commands.agentSelector.selectAgentPlaceholder`)})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:d(p?`common.unavailable`:`common.loading`)})]})}),(0,Q.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 text-muted-foreground`})]}):f?(0,Q.jsxs)(an,{onOpenChange:M,children:[(0,Q.jsx)(Xt,{asChild:!0,children:(0,Q.jsxs)(`div`,{className:q(`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`,i),children:[u?(0,Q.jsx)(rt,{name:n||`default`,size:14}):null,(0,Q.jsx)(`span`,{className:`typography-micro font-medium whitespace-nowrap`,children:n||d(`settings.commands.agentSelector.notSelected`)}),(0,Q.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3 flex-shrink-0 text-muted-foreground`})]})}),(0,Q.jsxs)($t,{className:`max-w-[300px]`,portalToBody:l,children:[(0,Q.jsxs)(nn,{className:`typography-meta`,onSelect:()=>z(``),children:[(0,Q.jsx)(rt,{name:`default`,size:14}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:d(`settings.commands.agentSelector.notSelected`)})]}),C.map(e=>(0,Q.jsxs)(nn,{className:`typography-meta`,onSelect:()=>z(e.name),children:[(0,Q.jsx)(rt,{name:e.name,size:14}),(0,Q.jsx)(`span`,{className:`font-medium`,children:e.name})]},e.name))]})]}):(0,Q.jsxs)(`div`,{className:q(`flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60`,i),children:[(0,Q.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin text-muted-foreground flex-shrink-0`}),(0,Q.jsx)(`span`,{className:`typography-micro font-medium whitespace-nowrap text-muted-foreground`,children:d(p?`common.unavailable`:`common.loading`)})]}),t[23]=n,t[24]=C,t[25]=i,t[26]=l,t[27]=z,t[28]=M,t[29]=E,t[30]=f,t[31]=p,t[32]=j,t[33]=u,t[34]=d,t[35]=te):te=t[35];let V;t[36]===ee?V=t[37]:(V=ee(),t[36]=ee,t[37]=V);let H;return t[38]!==te||t[39]!==V?(H=(0,Q.jsxs)(Q.Fragment,{children:[te,V]}),t[38]=te,t[39]=V,t[40]=H):H=t[40],H};function Pa(e){return e.agents}function Fa(e){return e.loadAgents}function Ia(e){return e.loadAgents}function La(e){return e.isMobile}function Ra(e){e&&nt.getState().refreshCatalogsOnPickerOpen({source:`agentSelector:desktopMenu`})}var za=`/mcp/oauth/callback`,Ba=e=>{if(typeof window>`u`)return null;try{let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t.length%4==0?``:`=`.repeat(4-t.length%4),r=window.atob(t+n),i=Uint8Array.from(r,e=>e.charCodeAt(0));return new TextDecoder().decode(i)}catch{return null}},Va=e=>{let t=Ua(e.get(`state`));if(t)return t;let n=e.get(`server`);if(typeof n!=`string`||!n.trim())return null;let r=e.get(`directory`);return{name:n.trim(),directory:typeof r==`string`&&r.trim()?r.trim():null}},Ha=e=>{let t=e.get(`state`);return typeof t==`string`&&t.trim()||null},Ua=e=>{if(typeof e!=`string`||!e.trim())return null;let t=Ba(e.trim());if(!t)return null;try{let e=JSON.parse(t);return e?.v!==1||typeof e.n!=`string`||!e.n.trim()?null:{name:e.n.trim(),directory:typeof e.d==`string`&&e.d.trim()?e.d.trim():null}}catch{return null}},Wa=e=>typeof e==`object`&&!!e&&`updateStatus`in e&&typeof e.updateStatus==`function`,Ga=e=>{let t=document.createElement(`div`);t.className=`cm-vim-panel`;let n=Pn(e);if(!n)return{top:!1,dom:t};n.state.statusbar=t;let r=n.state.vimPlugin;return Wa(r)&&r.updateStatus(),{top:!1,dom:t,destroy(){n.state.statusbar===t&&(n.state.statusbar=null)}}};function Ka(e){return e?[Nn(),re.of(Ga),oe()]:[]}var qa={next:`Next match`,prev:`Previous match`,select:`Select all matches`,replace:`Replace`,replaceAll:`Replace all`,close:`Close`},Ja={case:`Match case`,re:`Regular expression`,word:`Match whole word`};function Ya(e){let t=e.querySelector(`.cm-search`);if(t){for(let[e,n]of Object.entries(qa)){let r=t.querySelector(`button[name="${e}"]`);r&&!r.title&&(r.title=n)}for(let[e,n]of Object.entries(Ja)){let r=t.querySelector(`input[name="${e}"]`)?.parentElement;r&&!r.title&&(r.title=n)}}}var Xa=new WeakMap;function Za(e,t){let n=On(e.state);if(!n.valid)return Xa.delete(e),0;let r=Xa.get(e);if(!t&&r?.doc===e.state.doc&&r.query.eq(n))return r.total;let i=n.getCursor(e.state),a=0;for(let e=i.next();!e.done;e=i.next())a+=1;return Xa.set(e,{query:n,doc:e.state.doc,total:a}),a}function Qa(e){let t=On(e.state);if(!t.valid)return 0;let n=e.state.selection.main,r=t.getCursor(e.state),i=0,a=0;for(let e=r.next();!e.done;e=r.next()){let t=e.value;if(i+=1,a===0&&(a=i),n.from===t.from&&n.to===t.to||n.from<t.to&&n.to>t.from||t.from>=n.head)return i}return a}function $a(e,t,n=!1){let r=e.querySelector(`.cm-search`);if(!r)return;let i=r.querySelector(`.cm-search-message`);if(!i){i=document.createElement(`span`),i.className=`cm-search-message`,i.setAttribute(`aria-live`,`polite`);let e=r.querySelector(`button[name="next"]`),t=e?.parentNode===r?e:r.firstChild;r.insertBefore(i,t)}let a=Za(t,n),o=a===0?0:Qa(t);i.textContent=a===0?``:`${o}/${a}`}var eo=new G,to=new G,no=new G,ro=new G,io=new G,ao=new G,oo=new G,so=(e=>e)(Dn.filter(e=>e.run!==En)),co=de,lo=An,uo=jn,fo=class extends pe{id;containerMap;constructor(e,t){super(),this.id=e,this.containerMap=t}toDOM(){let e=this.containerMap.get(this.id);return e||(e=document.createElement(`div`),e.className=`yuri-block-widget`,e.dataset.widgetId=this.id,this.containerMap.set(this.id,e)),e}eq(e){return e.id===this.id}destroy(){}},po=(e,t)=>!e||e.length===0?[]:Se.define({create(n){let r=new _e,i=[...e].sort((e,t)=>e.afterLine-t.afterLine);for(let e of i){let i=n.doc.lines;if(e.afterLine>i)continue;let a=n.doc.line(e.afterLine);r.add(a.to,a.to,ae.widget({widget:new fo(e.id,t),block:!0,side:1}))}return r.finish()},update(e,t){return e.map(t.changes)},provide:e=>se.decorations.from(e)}),mo=e=>{if(!e)return[];let t=Math.max(1,e.start),n=Math.max(t,e.end);return fe.fromClass(class{decorations;constructor(e){this.decorations=this.build(e)}update(e){(e.docChanged||e.viewportChanged)&&(this.decorations=this.build(e.view))}build(e){let r=new _e;for(let i=t;i<=n&&i<=e.state.doc.lines;i+=1){let t=e.state.doc.line(i);r.add(t.from,t.from,ae.line({class:`yuri-cm-selected-line`}))}return r.finish()}},{decorations:e=>e.decorations})};function ho({value:e,onChange:t,extensions:n,className:r,readOnly:i,lineNumbersConfig:a,highlightLines:o,onViewReady:s,onViewDestroy:c,blockWidgets:l,enableSearch:u,searchOpen:d,onSearchOpenChange:f,vimMode:p}){let m=$.useRef(null),h=$.useRef(null),g=$.useRef(e),_=$.useRef(t),v=$.useRef(s),y=$.useRef(c),b=$.useRef(f),x=$.useRef(l),S=$.useRef(p),C=$.useRef(new Map),[w,T]=$.useState([]),E=$.useCallback(e=>{let t=(e??[]).map(e=>{let t=C.current.get(e.id);return t?{id:e.id,content:e.content,container:t}:null}).filter(e=>e!==null);T(e=>e.length===t.length&&e.every((e,n)=>{let r=t[n];return e.id===r.id&&e.content===r.content&&e.container===r.container})?e:t)},[]),D=$.useCallback(e=>{let t=m.current,n=e??h.current;if(!t||!n)return;let r=n.dom.querySelector(`.cm-gutters`),i=r instanceof HTMLElement?r.getBoundingClientRect().width:0;t.style.setProperty(`--yuri-editor-gutter-width`,`${i}px`)},[]);return $.useEffect(()=>{g.current=e},[e]),$.useEffect(()=>{_.current=t},[t]),$.useEffect(()=>{v.current=s,y.current=c},[s,c]),$.useEffect(()=>{b.current=f},[f]),$.useEffect(()=>{x.current=l,E(l)},[l,E]),$.useEffect(()=>{if(!m.current)return;let e=(()=>{if(typeof document>`u`)return null;let e=document.querySelector(`meta[name="csp-nonce"]`)?.getAttribute(`content`);if(e)return e;let t=window.__YURI_CSP_NONCE__;return typeof t==`string`&&t.length>0?t:null})(),t=Ce.create({doc:g.current,extensions:[...e?[se.cspNonce.of(e)]:[],ce({fixed:!0}),eo.of(me(a)),wn(),ie.of(` `),oo.of(Ka(p)),he.of([Cn,...Sn,...Tn]),se.updateListener.of(e=>{D(e.view),(e.viewportChanged||e.geometryChanged)&&E(x.current);let t=kn(e.startState),n=kn(e.state);t!==n&&b.current?.(n);let r=!On(e.startState).eq(On(e.state));if(n&&(t!==n||r||e.docChanged||e.selectionSet)&&$a(e.view.dom,e.view,t!==n||r||e.docChanged),!e.docChanged)return;let i=e.state.doc.toString();g.current=i,_.current(i),E(x.current)}),to.of(se.editable.of(!i)),no.of(n??[]),ro.of(mo(o)),io.of(po(l,C.current)),ao.of(u?[Mn({top:!0}),he.of(so)]:[])]});return h.current=new se({state:t,parent:m.current}),co(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{D(h.current),E(x.current)}),h.current&&v.current?.(h.current),()=>{y.current?.(),h.current?.destroy(),h.current=null,T([])}},[x,D,E]),$.useEffect(()=>{let e=h.current;e&&(e.dispatch({effects:[eo.reconfigure(me(a)),to.reconfigure(se.editable.of(!i)),no.reconfigure(n??[]),ro.reconfigure(mo(o)),io.reconfigure(po(l,C.current)),ao.reconfigure(u?[Mn({top:!0}),he.of(so)]:[])]}),co(e,e.state.doc.length,200),e.requestMeasure(),requestAnimationFrame(()=>{D(e),E(x.current)}))},[n,o,a,i,l,u,D,E]),$.useEffect(()=>{let e=h.current;if(!e){S.current=p;return}S.current!==p&&(S.current=p,e.dispatch({effects:oo.reconfigure(Ka(p))}))},[p]),$.useEffect(()=>{let e=h.current;!e||u===!1||(d?(lo(e),requestAnimationFrame(()=>{Ya(e.dom),$a(e.dom,e,!0)})):uo(e))},[d,u]),$.useEffect(()=>{let t=h.current;if(!t)return;let n=t.state.doc.toString();n!==e&&(t.dispatch({changes:{from:0,to:n.length,insert:e}}),co(t,t.state.doc.length,300),t.requestMeasure(),requestAnimationFrame(()=>D(t)))},[e,D]),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{ref:m,className:q(`h-full w-full`,`[&_.cm-editor]:h-full [&_.cm-editor]:w-full`,`[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6`,`[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]`,r)}),w.map(e=>(0,ei.createPortal)(e.content,e.container,e.id))]})}var go=ve.define(je),_o=Oe.data.of({commentTokens:{line:`//`,block:{open:`/*`,close:`*/`}}});function vo(e){let t=e.trim().toLowerCase();switch(t){case`bash`:case`sh`:case`zsh`:case`shell`:case`shellsession`:case`console`:return go;case`json`:case`jsonc`:case`json5`:return De().language;case`js`:case`javascript`:return Te().language;case`jsx`:return Te({jsx:!0}).language;case`ts`:case`typescript`:return Te({typescript:!0}).language;case`tsx`:return Te({typescript:!0,jsx:!0}).language;case`html`:return Ee().language;case`css`:return we().language;case`py`:case`python`:return Ae().language;case`md`:case`markdown`:case`mdown`:case`mkd`:return ke().language;case`heex`:case`eex`:case`leex`:return Ee().language;default:return xe.matchLanguageName(Fn,t,!0)}}var yo=e=>e.split(`/`).pop()?.toLowerCase()??``,bo=e=>{let t=yo(e);return t?xe.matchFilename(Fn,t):null},xo=()=>ue(ge.define([{tag:[K.heading1,K.heading2,K.heading3,K.heading4,K.heading5,K.heading6],fontWeight:`600`},{tag:K.strong,fontWeight:`600`},{tag:K.emphasis,fontStyle:`italic`},{tag:K.strikethrough,textDecoration:`line-through`},{tag:[K.link,K.url],color:`var(--markdown-link, currentColor)`,textDecoration:`underline`},{tag:K.monospace,color:`var(--markdown-inline-code, currentColor)`,backgroundColor:`var(--markdown-inline-code-bg, transparent)`},{tag:K.quote,color:`var(--markdown-blockquote, currentColor)`,fontStyle:`italic`},{tag:K.list,color:`color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)`},{tag:K.heading,color:`var(--markdown-heading1, currentColor)`}]));function So(e){let t=e.toLowerCase();switch(yo(t)){case`makefile`:case`gnumakefile`:return go}let n=t.lastIndexOf(`.`),r=n>=0?t.slice(n+1):``;switch(r){case`ts`:case`tsx`:case`mts`:case`cts`:return Te({typescript:!0,jsx:r===`tsx`});case`js`:case`jsx`:case`mjs`:case`cjs`:return Te({typescript:!1,jsx:r===`jsx`});case`jsonc`:case`json5`:return[De(),_o];case`json`:case`jsonl`:case`ndjson`:case`geojson`:return De();case`css`:case`scss`:case`sass`:case`less`:return we();case`html`:case`htm`:case`xml`:case`drawio`:case`dio`:return Ee();case`md`:case`mdx`:case`markdown`:case`mdown`:case`mkd`:return[ke({codeLanguages:vo}),xo()];case`sh`:case`bash`:case`zsh`:case`fish`:case`env`:return go;case`py`:case`pyw`:case`pyi`:return Ae();default:return null}}async function Co(e){let t=bo(e);if(!t)return null;if(t.support)return t.support;try{return await t.load()}catch{return null}}function wo(e,t){let n=e.metadata.variant===`dark`,r=e.config?.fonts?.mono||`monospace`,i=e.colors.syntax.highlights||{},a=e.colors.syntax.tokens||{},o=t?.fontSize?`${t.fontSize}px`:`var(--text-code)`,s=se.theme({"&":{backgroundColor:`var(--background)`,color:e.colors.syntax.base.foreground,fontSize:o,lineHeight:`1.5`,position:`relative`},".cm-scroller":{fontFamily:r,backgroundColor:`var(--background)`},".cm-comment":{color:e.colors.syntax.base.comment},".cm-keyword":{color:e.colors.syntax.base.keyword},".cm-string":{color:e.colors.syntax.base.string},".cm-string-2":{color:a.stringEscape||e.colors.syntax.base.string},".cm-number":{color:e.colors.syntax.base.number},".cm-operator":{color:e.colors.syntax.base.operator},".cm-punctuation":{color:a.punctuation||e.colors.syntax.base.comment},".cm-atom":{color:a.boolean||e.colors.syntax.base.number},".cm-builtin":{color:a.functionCall||e.colors.syntax.base.function},".cm-def":{color:a.variableGlobal||e.colors.syntax.base.variable},".cm-attribute":{color:a.variableOther||a.variableProperty||e.colors.syntax.base.operator},".cm-meta":{color:e.colors.syntax.base.comment},".cm-property":{color:a.variableProperty||e.colors.syntax.base.keyword},".cm-variable":{color:e.colors.syntax.base.variable},".cm-variable-2":{color:a.variableOther||e.colors.syntax.base.function},".cm-variable-3":{color:a.variableGlobal||e.colors.syntax.base.type},".cm-tag":{color:a.tag||e.colors.syntax.base.keyword},".cm-link":{color:a.url||e.colors.syntax.base.keyword,textDecoration:`underline`},".cm-content":{caretColor:e.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:e.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:e.colors.interactive.selection},".cm-gutters":{backgroundColor:`var(--background)`,color:i.lineNumber||e.colors.syntax.base.comment,borderRight:`1px solid ${e.colors.interactive.border}`,position:`sticky`,paddingRight:`8px`,left:0,zIndex:2,boxShadow:`0 0 0 var(--background)`},".cm-gutter":{backgroundColor:`var(--background)`},".cm-gutterElement":{backgroundColor:`var(--background)`},".cm-lineNumbers":{backgroundColor:`var(--background)`},".cm-lineNumbers .cm-gutterElement":{paddingLeft:`8px`,paddingRight:`8px`,minWidth:`42px`},".cm-activeLineGutter":{color:i.lineNumberActive||e.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:e.colors.surface.overlay},".cm-panels":{backgroundColor:`transparent`,color:e.colors.surface.foreground,position:`absolute`,top:`0`,right:`0`,left:`auto`,width:`auto`,zIndex:10,pointerEvents:`none`},".cm-panels-top":{borderBottom:`none`,position:`absolute`,top:`6px`,right:`14px`,left:`auto`,width:`auto`},".cm-panels-bottom":{position:`static`,width:`100%`,pointerEvents:`auto`},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${e.colors.interactive.border}`,backgroundColor:e.colors.surface.elevated,color:e.colors.surface.mutedForeground,fontFamily:`var(--font-mono)`,fontSize:`12px`,minHeight:`22px`,padding:`2px 8px`},".cm-panel.cm-search":{pointerEvents:`auto`,padding:`4px`,backgroundColor:`color-mix(in srgb, ${e.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${e.colors.interactive.border}`,borderRadius:`10px`,boxShadow:`0 2px 8px color-mix(in srgb, ${e.colors.surface.background} 60%, transparent)`,width:`auto`,minWidth:`360px`,maxWidth:`480px`},".cm-search":{display:`flex`,flexWrap:`wrap`,alignItems:`center`,gap:`0`,width:`100%`,color:e.colors.surface.foreground,fontFamily:`inherit`,fontSize:`13px`,lineHeight:`1`},".cm-search br":{display:`none`},".cm-search .cm-textfield":{appearance:`none`,height:`26px`,margin:0,padding:`0 8px`,borderRadius:`6px !important`,border:`1px solid ${e.colors.interactive.border}`,backgroundColor:e.colors.surface.background,color:e.colors.surface.foreground,fontFamily:`inherit`,fontSize:`12px`,lineHeight:`1`,outline:`none`,transition:`border-color 150ms ease`},".cm-search .cm-textfield::placeholder":{color:e.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:e.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:`1 1 120px`,maxWidth:`calc(100% - 142px)`,minWidth:`100px`},".cm-search label":{order:2,display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:`26px`,height:`26px`,minWidth:`26px`,flexShrink:`0`,margin:0,marginLeft:`1px`,padding:0,borderRadius:`4px`,border:`1px solid transparent`,backgroundColor:`transparent`,color:`transparent`,cursor:`pointer`,userSelect:`none`,fontSize:`1px`,lineHeight:`0`,overflow:`hidden`,position:`relative`,transition:`background-color 120ms ease, border-color 120ms ease`},".cm-search label:hover":{backgroundColor:e.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:e.colors.interactive.hover,borderColor:e.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:`none`,WebkitAppearance:`none`,width:`0`,height:`0`,margin:`0`,padding:`0`,border:`none`,position:`absolute`,opacity:`0`,pointerEvents:`none`},".cm-search label::after":{position:`absolute`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,fontSize:`13px`,fontWeight:`600`,lineHeight:`1`,fontFamily:`inherit`,color:e.colors.surface.mutedForeground,pointerEvents:`none`},".cm-search label:hover::after":{color:e.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:e.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:`"Aa"`,fontSize:`12px`,letterSpacing:`-0.5px`},'.cm-search label:has(input[name="re"])::after':{content:`".*"`,fontSize:`13px`,fontFamily:`monospace`},'.cm-search label:has(input[name="word"])::after':{content:`"ab"`,fontSize:`12px`,textDecoration:`underline`,textUnderlineOffset:`2px`},".cm-search .cm-search-message":{order:3,color:e.colors.surface.mutedForeground,backgroundColor:`transparent`,border:`none`,borderRadius:`0`,padding:`0 6px`,fontSize:`11px`,whiteSpace:`nowrap`,lineHeight:`26px`},".cm-search .cm-button":{appearance:`none`,WebkitAppearance:`none`,display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:`26px`,height:`26px`,minWidth:`26px`,flexShrink:`0`,margin:0,marginLeft:`1px`,padding:0,borderRadius:`4px`,border:`none`,backgroundColor:`transparent`,backgroundImage:`none`,color:`transparent`,cursor:`pointer`,fontSize:`1px`,fontWeight:`400`,lineHeight:`0`,overflow:`hidden`,position:`relative`,boxShadow:`none`,transition:`background-color 120ms ease`},".cm-search .cm-button::after":{position:`absolute`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,fontSize:`15px`,lineHeight:`1`,color:e.colors.surface.mutedForeground,pointerEvents:`none`},".cm-search .cm-button:hover":{backgroundColor:e.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:e.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:e.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:`none`,boxShadow:`0 0 0 1px ${e.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:`default`,pointerEvents:`none`},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:`2px`},'.cm-search .cm-button[name="prev"]::after':{content:`"↑"`},'.cm-search .cm-button[name="next"]':{order:22,marginTop:`2px`},'.cm-search .cm-button[name="next"]::after':{content:`"↓"`},'.cm-search .cm-button[name="select"]':{order:23,marginTop:`2px`},'.cm-search .cm-button[name="select"]::after':{content:`"≡"`,fontSize:`17px`},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:`none`,WebkitAppearance:`none`,display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:`26px`,height:`26px`,minWidth:`26px`,flexShrink:`0`,margin:`0 0 0 auto`,padding:`0`,borderRadius:`4px`,border:`none`,backgroundColor:`transparent`,backgroundImage:`none`,color:e.colors.surface.mutedForeground,cursor:`pointer`,fontSize:`16px`,lineHeight:`1`,boxShadow:`none`,position:`relative`,overflow:`visible`,transition:`background-color 120ms ease, color 120ms ease`},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:e.colors.interactive.hover,color:e.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:`2px`},'.cm-search .cm-button[name="replace"]::after':{content:`"⇄"`},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:`2px`},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:`"⇉"`},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:`1 1 100%`,maxWidth:`calc(100% - 142px)`,minWidth:`80px`,marginTop:`2px`},".cm-searchMatch":{backgroundColor:e.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${e.colors.status.infoBorder}`,borderRadius:`2px`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:e.colors.interactive.selection,color:e.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${e.colors.interactive.borderFocus}`},"&.cm-focused":{outline:`none`}},{dark:n}),c=ge.define([{tag:[K.comment,K.docComment,K.meta,K.documentMeta],class:`cm-comment`},{tag:[K.keyword,K.controlKeyword,K.moduleKeyword,K.definitionKeyword,K.modifier],class:`cm-keyword`},{tag:[K.operatorKeyword,K.operator,K.derefOperator,K.updateOperator,K.definitionOperator,K.typeOperator,K.controlOperator,K.logicOperator,K.bitwiseOperator,K.arithmeticOperator,K.compareOperator],class:`cm-operator`},{tag:[K.punctuation,K.separator,K.bracket,K.paren,K.brace,K.squareBracket,K.angleBracket],class:`cm-punctuation`},{tag:[K.string,K.regexp,K.attributeValue,K.special(K.string),K.monospace],class:`cm-string`},{tag:K.escape,class:`cm-string-2`},{tag:[K.number,K.bool,K.atom,K.null,K.self],class:`cm-number`},{tag:[K.function(K.variableName),K.function(K.definition(K.variableName)),K.function(K.propertyName),K.standard(K.variableName),K.special(K.variableName)],class:`cm-builtin`},{tag:K.definition(K.variableName),class:`cm-def`},{tag:[K.variableName,K.local(K.variableName),K.constant(K.variableName),K.literal],class:`cm-variable`},{tag:K.propertyName,class:`cm-property`},{tag:K.attributeName,class:`cm-attribute`},{tag:[K.className,K.typeName,K.namespace],class:`cm-variable-3`},{tag:[K.tagName,K.labelName,K.annotation,K.macroName],class:`cm-tag`},{tag:K.link,class:`cm-link`},{tag:[K.heading,K.heading1,K.heading2,K.heading3,K.heading4,K.heading5,K.heading6],class:`cm-keyword`}]),l=ge.define([{tag:[K.comment,K.docComment,K.meta,K.documentMeta],color:e.colors.syntax.base.comment},{tag:[K.keyword,K.controlKeyword,K.moduleKeyword,K.definitionKeyword,K.modifier],color:e.colors.syntax.base.keyword},{tag:[K.operatorKeyword,K.operator,K.derefOperator,K.updateOperator,K.definitionOperator,K.typeOperator,K.controlOperator,K.logicOperator,K.bitwiseOperator,K.arithmeticOperator,K.compareOperator],color:e.colors.syntax.base.operator},{tag:[K.string,K.regexp,K.attributeValue,K.special(K.string),K.monospace],color:e.colors.syntax.base.string},{tag:K.escape,color:a.stringEscape||e.colors.syntax.base.string},{tag:[K.number,K.bool,K.atom,K.null,K.self],color:e.colors.syntax.base.number},{tag:[K.function(K.variableName),K.function(K.definition(K.variableName)),K.function(K.propertyName),K.standard(K.variableName),K.special(K.variableName)],color:e.colors.syntax.base.function},{tag:K.definition(K.variableName),color:a.variableGlobal||e.colors.syntax.base.variable},{tag:[K.variableName,K.local(K.variableName),K.constant(K.variableName),K.literal],color:e.colors.syntax.base.variable},{tag:K.propertyName,color:a.variableProperty||e.colors.syntax.base.variable},{tag:K.attributeName,color:a.variableOther||e.colors.syntax.base.variable},{tag:[K.className,K.typeName,K.namespace],color:e.colors.syntax.base.type},{tag:[K.tagName,K.labelName,K.annotation,K.macroName],color:a.tag||e.colors.syntax.base.keyword},{tag:K.link,color:a.url||e.colors.syntax.base.function,textDecoration:`underline`},{tag:[K.punctuation,K.separator,K.bracket,K.paren,K.brace,K.squareBracket,K.angleBracket],color:a.punctuation||e.colors.syntax.base.comment}]);return t?.syntaxColors===!1?[s]:[s,ue(be,{fallback:!0}),ue(le),ue(c),ue(l)]}var To=180,Eo=ye.define(),Do=1,Oo=2,ko=4,Ao=new Map,jo=(e,t)=>{let n=`${e}|${t}`,r=Ao.get(n);if(r)return r;let i=``;e&&(i+=`color:${e};`),t&Do&&(i+=`font-style:italic;`),t&Oo&&(i+=`font-weight:bold;`),t&ko&&(i+=`text-decoration:underline;`);let a=ae.mark({attributes:{style:i}});return Ao.set(n,a),a},Mo=(e,t)=>{let n=new _e,r=e.state.doc,i=Math.min(t.length,r.lines);for(let e=0;e<i;e+=1){let i=t[e];if(!i||i.length===0)continue;let a=r.line(e+1),o=a.from;for(let[e,t,r]of i){if(e<=0)continue;let i=o,s=Math.min(o+e,a.to);o+=e,!(s<=i)&&(!t&&!r||n.add(i,s,jo(t,r)))}}return n.finish()},No=Se.define({create(){return ae.none},update(e,t){let n=e.map(t.changes);for(let e of t.effects)e.is(Eo)&&(n=e.value);return n},provide:e=>se.decorations.from(e)}),Po=e=>fe.fromClass(class{timer;generation=0;abortController;constructor(e){this.tokenize(e)}update(e){e.docChanged&&this.schedule(e.view)}schedule(e){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.tokenize(e)},To)}async tokenize(t){let n=++this.generation;this.abortController?.abort();let r=new AbortController;this.abortController=r;let i=t.state.doc.toString(),a=await hn(i,e.language,e.themeName,e.theme,{signal:r.signal,priority:`visible`});a&&(r.signal.aborted||n===this.generation&&t.state.doc.length===i.length&&t.dispatch({effects:Eo.of(Mo(t,a))}))}destroy(){this.timer&&clearTimeout(this.timer),this.abortController?.abort(),this.abortController=void 0}}),Fo=e=>[No,Po(e)],Io=e=>{let t=(0,Z.c)(11),{currentMode:n,onToggle:r}=e,i=n===`preview`,a=i?`Switch to edit mode`:`Switch to preview mode`,o=i?`Edit`:`Preview`,s;t[0]===i?s=t[1]:(s=i?(0,Q.jsx)(X,{name:`eye`,className:`size-4`,"aria-hidden":`true`}):(0,Q.jsx)(X,{name:`eye-off`,className:`size-4`,"aria-hidden":`true`}),t[0]=i,t[1]=s);let c;t[2]!==a||t[3]!==r||t[4]!==s?(c=(0,Q.jsx)(Nt,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`sm`,onClick:r,"aria-label":a,className:`h-5 w-5 p-0`,children:s})}),t[2]=a,t[3]=r,t[4]=s,t[5]=c):c=t[5];let l;t[6]===o?l=t[7]:(l=(0,Q.jsx)(Pt,{sideOffset:8,children:o}),t[6]=o,t[7]=l);let u;return t[8]!==c||t[9]!==l?(u=(0,Q.jsxs)(Ft,{children:[c,l]}),t[8]=c,t[9]=l,t[10]=u):u=t[10],u},Lo=_()(y(v((e,t)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:t=>{e({selectedProfileId:t})},loadProfiles:async()=>{e({isLoading:!0});let n=t().profiles;try{return e({profiles:await ft(),isLoading:!1}),!0}catch(t){return console.error(`Failed to load git identity profiles:`,t),e({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{let t=await pt();return t&&t.userName&&t.userEmail?e({globalIdentity:{id:`global`,name:`Global Identity`,userName:t.userName,userEmail:t.userEmail,authType:t.sshCommand?`ssh`:void 0,sshKey:t.sshCommand?t.sshCommand.replace(`ssh -i `,``):null,color:`info`,icon:`house`}}):e({globalIdentity:null}),!0}catch(t){return console.error(`Failed to load global git identity:`,t),e({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{return e({discoveredCredentials:await _t()}),!0}catch(t){return console.error(`Failed to discover git credentials:`,t),e({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{let t=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};try{let n=null;if(n===null){let e=g()?.settings;if(e)try{n=t(((await e.load())?.settings||{}).defaultGitIdentityId)}catch{}}if(n===null)try{let e=await a(`/api/config/settings`,{method:`GET`,headers:{Accept:`application/json`}});e.ok&&(n=t((await e.json().catch(()=>null))?.defaultGitIdentityId))}catch{}return e({defaultGitIdentityId:n}),!0}catch(e){return console.error(`Failed to load default git identity setting:`,e),!1}},setDefaultGitIdentityId:async t=>{try{let n=typeof t==`string`?t.trim():``,r=n.length>0?n:``;return await j({defaultGitIdentityId:r}),e({defaultGitIdentityId:r.length>0?r:null}),!0}catch(e){return console.error(`Failed to save default git identity setting:`,e),!1}},createProfile:async e=>{try{let n={...e,id:e.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:e.color||`keyword`,icon:e.icon||`branch`};return await gt(n),await t().loadProfiles(),!0}catch(e){return console.error(`Failed to create git identity profile:`,e),!1}},updateProfile:async(e,n)=>{try{let r=t().profiles.find(t=>t.id===e);if(!r)throw Error(`Profile not found`);let i={...r,...n};return await dt(e,i),await t().loadProfiles(),!0}catch(e){return console.error(`Failed to update git identity profile:`,e),!1}},deleteProfile:async n=>{try{return await mt(n),t().selectedProfileId===n&&e({selectedProfileId:null}),await t().loadProfiles(),!0}catch(e){return console.error(`Failed to delete git identity profile:`,e),!1}},getProfileById:e=>{let{profiles:n,globalIdentity:r}=t();return e===`global`?r||void 0:n.find(t=>t.id===e)},getUnimportedCredentials:()=>{let{profiles:e,discoveredCredentials:n}=t();return n.filter(t=>!e.some(e=>e.authType===`token`&&e.host===t.host))}}),{name:`git-identities-store`,storage:D(),partialize:e=>({selectedProfileId:e.selectedProfileId})}),{name:`git-identities-store`}));typeof window<`u`&&(window.__zustand_git_identities_store__=Lo);var Ro=`w-full max-w-[30rem]`,zo=e=>{let t=(0,Z.c)(23),{title:n,description:r,settingsItem:i,titleAccessory:a,headerAction:o,children:s,className:c,contentClassName:l}=e,u;t[0]===n?u=t[1]:(u=(0,Q.jsx)(`span`,{className:`truncate`,children:n}),t[0]=n,t[1]=u);let d;t[2]!==u||t[3]!==a?(d=(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[u,a]}),t[2]=u,t[3]=a,t[4]=d):d=t[4];let f;t[5]===o?f=t[6]:(f=o?(0,Q.jsx)(`div`,{className:`shrink-0`,children:o}):null,t[5]=o,t[6]=f);let p;t[7]!==d||t[8]!==f?(p=(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[d,f]}),t[7]=d,t[8]=f,t[9]=p):p=t[9];let m;t[10]===l?m=t[11]:(m=q(`yuri-settings-group-row`,l),t[10]=l,t[11]=m);let h;t[12]!==s||t[13]!==m?(h=(0,Q.jsx)(`div`,{className:m,children:s}),t[12]=s,t[13]=m,t[14]=h):h=t[14];let g;t[15]!==r||t[16]!==p||t[17]!==h?(g=(0,Q.jsx)(ni,{className:`yuri-settings-detail-group`,label:p,description:r,children:h}),t[15]=r,t[16]=p,t[17]=h,t[18]=g):g=t[18];let _;return t[19]!==c||t[20]!==i||t[21]!==g?(_=(0,Q.jsx)(`div`,{"data-settings-item":i,className:c,children:g}),t[19]=c,t[20]=i,t[21]=g,t[22]=_):_=t[22],_},Bo=450,Vo=({projectRef:e=null})=>{let{t}=Fe(),{isMobile:n,isTablet:r}=sn(),i=n||r,a=et(e=>e.getActiveProject()),o=e?.path??a?.path??null,s=qe(e=>e.getWorktreeMetadata),c=Ve(),l=E(e=>e.homeDirectory),[u,d]=$.useState([]),[f,p]=$.useState(!1),[m,h]=$.useState(!1),[g,_]=$.useState(null),[v,y]=$.useState(null),[b,x]=$.useState([]),[S,C]=$.useState(!1),w=$.useRef(!1),T=$.useMemo(()=>e?.id&&e?.path?{id:e.id,path:e.path}:!a?.id||!o?null:{id:a.id,path:o},[a?.id,o,e?.id,e?.path]),D=$.useCallback(async()=>{if(!(!T||v===!1))try{let e=await Tt(T);x(e)}catch{}},[T,v]);$.useEffect(()=>{if(!o)return;let e=!1;return y(null),(async()=>{try{let t=await ht(o);if(e)return;y(t)}catch{}})(),()=>{e=!0}},[o]),$.useEffect(()=>{if(!T){x([]),C(!1);return}if(v===!1){x([]),C(!1);return}let e=!1;return C(!0),x([]),(async()=>{try{let t=await Tt(T);if(e)return;x(t)}catch{}finally{e||C(!1)}})(),()=>{e=!0}},[T,v]),$.useEffect(()=>{if(!T)return;let e=!1;return h(!0),(async()=>{try{let[t,n]=await Promise.all([Je(T),tt(T)]);if(!e){let e=t.length>0?t:[``];d(e),_(JSON.stringify(e)),p(n)}}catch{e||(d([``]),_(JSON.stringify([``])),p(!1))}finally{e||h(!1)}})(),()=>{e=!0}},[T]);let O=$.useCallback(async e=>{if(!T)return!1;let n=e.filter(e=>e.trim().length>0);try{return await Ze(T,n)?(_(JSON.stringify(e)),!0):(Y.error(t(`settings.yuri.worktrees.setup.toast.saveFailed`)),!1)}catch{return Y.error(t(`settings.yuri.worktrees.setup.toast.saveFailed`)),!1}},[T,t]),k=$.useMemo(()=>g!==null&&g!==JSON.stringify(u),[g,u]);$.useEffect(()=>{if(!k||m||w.current)return;let e=window.setTimeout(()=>{w.current||(w.current=!0,(async()=>{try{await O(u)}finally{w.current=!1}})())},Bo);return()=>{window.clearTimeout(e)}},[k,m,O,u]);let A=$.useCallback((e,t)=>{d(n=>{let r=[...n];return r[e]=t,r})},[]),j=$.useCallback(()=>{d(e=>[...e,``])},[]),M=$.useCallback(e=>{d(t=>{let n=t.filter((t,n)=>n!==e);return n.length>0?n:[``]})},[]),N=$.useCallback(()=>{!k||w.current||(w.current=!0,(async()=>{try{await O(u)}finally{w.current=!1}})())},[k,O,u]),P=$.useCallback(e=>{p(e),T&&Ye(T,e)},[T]),F=$.useCallback(e=>{let t=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``),n=t(e.path),r=c.filter(e=>{let r=s(e.id);if(r?.path&&t(r.path)===n)return!0;let i=e.directory;return!!(i&&t(i)===n)}),i=new Set(r.map(e=>e.id)),a=[...He.getState().activeSessions,...He.getState().archivedSessions],o=e=>{let t=a.filter(t=>{let n=t.parentID;return n&&e.has(n)});if(t.length===0)return[];let n=new Set(t.map(e=>e.id));return[...t,...o(n)]},l=o(i),u=new Set,d=[...r,...l].filter(e=>!u.has(e.id)&&(u.add(e.id),!0));Qe.requestDelete({sessions:d,mode:`worktree`,worktree:e})},[c,s]),I=$.useMemo(()=>c.map(e=>e.id).join(`,`),[c]);$.useEffect(()=>{v&&o&&D()},[I,v,o,D]);let L=(0,Q.jsxs)(Ft,{children:[(0,Q.jsx)(Nt,{asChild:!0,children:(0,Q.jsx)(X,{name:`information`,className:`h-3.5 w-3.5 text-muted-foreground/60 cursor-help`})}),(0,Q.jsxs)(Pt,{sideOffset:8,className:`max-w-xs`,children:[t(`settings.yuri.worktrees.setup.tooltipPrefix`),` `,(0,Q.jsx)(`code`,{className:`font-mono text-xs bg-sidebar-accent/50 px-1 rounded`,children:`$ROOT_PROJECT_PATH`}),` `,t(`settings.yuri.worktrees.setup.tooltipSuffix`)]})]}),R=(0,Q.jsxs)(Ft,{children:[(0,Q.jsx)(Nt,{asChild:!0,children:(0,Q.jsx)(X,{name:`information`,className:`h-3.5 w-3.5 text-muted-foreground/60 cursor-help`})}),(0,Q.jsx)(Pt,{sideOffset:8,className:`max-w-xs`,children:t(`settings.yuri.worktrees.list.tooltip`)})]});return o?v===!1?(0,Q.jsx)(zo,{title:t(`settings.projects.page.section.worktree`),settingsItem:`projects.worktree`,children:(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(`settings.yuri.worktrees.state.gitOnly`)})}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(zo,{title:t(`settings.projects.page.section.worktree`),settingsItem:`projects.worktree`,titleAccessory:L,children:m?(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(`settings.yuri.worktrees.setup.loading`)}):(0,Q.jsxs)(`div`,{className:q(`flex flex-col gap-2`,Ro),children:[u.map((e,n)=>(0,Q.jsxs)(`div`,{className:`yuri-settings-group-row flex w-full items-center gap-2`,children:[(0,Q.jsx)(Mt,{value:e,onChange:e=>A(n,e.target.value),onBlur:N,placeholder:t(`settings.yuri.worktrees.setup.commandPlaceholder`),className:`min-w-0 flex-1 font-mono text-xs`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>M(n),className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,"aria-label":t(`settings.yuri.worktrees.setup.removeCommandAria`),children:(0,Q.jsx)(X,{name:`close`,className:`h-4 w-4`})})]},n)),(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`xs`,className:`!font-normal`,onClick:j,children:[(0,Q.jsx)(X,{name:`add`,className:`h-3.5 w-3.5`}),t(`settings.yuri.worktrees.setup.addCommand`)]}),(0,Q.jsxs)(`label`,{"data-settings-item":`projects.worktree.setup.wait`,className:`flex cursor-pointer items-center gap-2 py-1`,children:[(0,Q.jsx)(vt,{checked:f,onChange:P,ariaLabel:t(`settings.yuri.worktrees.setup.waitForCommandsAria`)}),(0,Q.jsx)(`span`,{className:q(`typography-ui-label font-normal`,f?`text-foreground`:`text-foreground/60`),children:t(`settings.yuri.worktrees.setup.waitForCommands`)})]})]})}),(0,Q.jsx)(zo,{title:t(`settings.yuri.worktrees.list.title`),titleAccessory:R,children:S?(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(`settings.yuri.worktrees.list.loading`)}):b.length===0?(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground/70`,children:t(`settings.yuri.worktrees.list.empty`)}):(0,Q.jsx)(`div`,{className:q(`space-y-1`,Ro),children:b.map(e=>(0,Q.jsxs)(`div`,{className:`group flex w-full items-center gap-2 py-1.5`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`typography-meta min-w-0 truncate text-foreground`,children:e.label||e.branch||t(`settings.yuri.worktrees.list.detachedHead`)}),(0,Q.jsx)(`span`,{className:`typography-micro flex-shrink-0 self-center rounded bg-sidebar-accent/40 px-1.5 py-[1px] leading-none text-muted-foreground/60`,children:`OpenCode`})]}),(0,Q.jsx)(`p`,{className:`typography-micro truncate text-muted-foreground/60`,children:Ne(e.path,l)})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>F(e),className:q(`flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground/50 transition-opacity hover:bg-destructive/10 hover:text-destructive focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,i?`opacity-100`:`opacity-0 group-hover:opacity-100`),"aria-label":t(`settings.yuri.worktrees.list.deleteWorktreeAria`,{name:e.branch||e.label||e.path}),children:(0,Q.jsx)(X,{name:`delete-bin`,className:`h-4 w-4`})})]},e.path))})})]}):(0,Q.jsx)(zo,{title:t(`settings.projects.page.section.worktree`),settingsItem:`projects.worktree`,children:(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(`settings.yuri.worktrees.state.selectProject`)})})},Ho=(e,t)=>t.updatedAtMs-e.updatedAtMs,Uo=_((e,t)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!t().isLoading){e({isLoading:!0,error:null});try{let[n,r]=await Promise.all([Vt(),Jt()]),i={};for(let e of r.sort(Ho))i[e.id]=e;t().listenerReady||await rn(t=>{e(e=>({statusesById:{...e.statusesById,[t.id]:t}}))}),e({instances:n.instances,statusesById:i,isLoading:!1,initialized:!0,listenerReady:!0})}catch(t){e({isLoading:!1,error:t instanceof Error?t.message:String(t)})}}},loadImports:async()=>{if(!t().isImportsLoading){e({isImportsLoading:!0,error:null});try{e({importCandidates:await Rt(),isImportsLoading:!1})}catch(t){e({isImportsLoading:!1,error:t instanceof Error?t.message:String(t)})}}},refreshStatuses:async()=>{try{let t=await Jt(),n={};for(let e of t.sort(Ho))n[e.id]=e;e({statusesById:n})}catch(t){e({error:t instanceof Error?t.message:String(t)})}},setInstances:async n=>{e({isSaving:!0,error:null});try{await tn({instances:n}),e({instances:n,isSaving:!1}),await t().refreshStatuses()}catch(t){throw e({isSaving:!1,error:t instanceof Error?t.message:String(t)}),t}},upsertInstance:async e=>{let n=t().instances,r=n.some(t=>t.id===e.id)?n.map(t=>t.id===e.id?e:t):[e,...n];await t().setInstances(r)},createFromCommand:async(e,n,r)=>{let i=zt(e,n);r&&r.trim()&&(i.nickname=r.trim()),await t().upsertInstance(i)},removeInstance:async n=>{await qt(n).catch(()=>void 0);let r=t().instances.filter(e=>e.id!==n);await t().setInstances(r),e(e=>{let t={...e.statusesById};return delete t[n],{statusesById:t}})},connect:async n=>{e({error:null});try{await Gt(n),await t().refreshStatuses()}catch(t){throw e({error:t instanceof Error?t.message:String(t)}),t}},disconnect:async n=>{e({error:null});try{await qt(n),await t().refreshStatuses()}catch(t){throw e({error:t instanceof Error?t.message:String(t)}),t}},retry:async e=>{await t().connect(e)},getStatus:e=>t().statusesById[e]||null,clearError:()=>e({error:null})})),Wo=450,Go=()=>k(),Ko=()=>({id:Go(),name:``,command:``,icon:`play`}),qo=({projectRef:e})=>{let{t}=Fe(),n=$.useMemo(()=>h(),[]),r=Uo(e=>e.instances),i=Uo(e=>e.load),[a,o]=$.useState([]),[s,c]=$.useState(!1),[l,u]=$.useState(null),[d,f]=$.useState({}),p=$.useRef(!1),m=$.useRef(null);$.useEffect(()=>{n&&i().catch(()=>void 0)},[n,i]),$.useEffect(()=>{let t=!1;return c(!0),(async()=>{try{let n=await $e(e);if(t)return;o(n.actions),u(JSON.stringify({actions:n.actions}))}catch{if(t)return;o([]),u(JSON.stringify({actions:[]}))}finally{t||c(!1)}})(),()=>{t=!0}},[e]);let g=$.useMemo(()=>n?In(r):[],[r,n]),_=$.useMemo(()=>a.some(e=>e.name.trim().length===0||e.command.trim().length===0)?t(`settings.projects.actions.validation.fillNameAndCommand`):null,[a,t]),v=$.useMemo(()=>l!==null&&l!==JSON.stringify({actions:a}),[a,l]),y=$.useCallback(async n=>await Ge(e,{actions:n,primaryActionId:null})?(u(JSON.stringify({actions:n})),typeof window<`u`&&window.dispatchEvent(new CustomEvent(zn,{detail:{projectId:e.id}})),!0):(Y.error(t(`settings.projects.actions.toast.saveFailed`)),!1),[e,t]);$.useEffect(()=>{if(!v||s||_||p.current)return;let e=window.setTimeout(()=>{p.current||(p.current=!0,(async()=>{try{await y(a)}finally{p.current=!1}})())},Wo);return()=>{window.clearTimeout(e)}},[a,v,s,y,_]),$.useEffect(()=>{if(!v||!_||s){_||(m.current=null);return}let e=window.setTimeout(()=>{m.current!==_&&(m.current=_,Y.error(_))},1e3);return()=>{window.clearTimeout(e)}},[v,s,_]);let b=$.useCallback(()=>{let e=Ko();o(t=>[...t,e]),f(t=>({...t,[e.id]:!0}))},[]),x=$.useCallback(e=>{o(t=>t.filter(t=>t.id!==e)),f(t=>{let n={...t};return delete n[e],n})},[]),S=$.useCallback((e,t)=>{o(n=>n.map(n=>n.id===e?t(n):n))},[]);return(0,Q.jsxs)(zo,{title:t(`settings.projects.actions.title`),description:t(`settings.projects.actions.description`),settingsItem:`projects.actions`,headerAction:(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`xs`,className:`!font-normal`,onClick:b,children:[(0,Q.jsx)(X,{name:`add`,className:`h-3.5 w-3.5`}),t(`settings.projects.actions.actions.add`)]}),contentClassName:`space-y-0`,children:[s?(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(`settings.projects.actions.state.loading`)}):a.length===0?(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(`settings.projects.actions.state.empty`)}):(0,Q.jsx)(`div`,{className:q(`space-y-0`,Ro),children:a.map(e=>{let r=e.icon||`play`,i=Rn[r]||`play`,a=d[e.id]??!1,o=e.name.trim()||t(`settings.projects.actions.state.untitled`);return(0,Q.jsxs)(xn,{open:a,onOpenChange:t=>{f(n=>({...n,[e.id]:t}))},className:`py-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsxs)(bn,{className:`group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,children:[a?(0,Q.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 text-muted-foreground`}):(0,Q.jsx)(X,{name:`arrow-right-s`,className:`h-4 w-4 text-muted-foreground`}),(0,Q.jsx)(X,{name:i,className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:o})})]}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`xs`,className:`!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]`,onClick:()=>x(e.id),children:(0,Q.jsx)(X,{name:`delete-bin`,className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(yn,{className:`pt-1.5`,children:(0,Q.jsxs)(`div`,{className:`space-y-2 pb-4 pl-3 pr-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,Q.jsxs)(an,{children:[(0,Q.jsx)(Xt,{asChild:!0,children:(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]`,"aria-label":t(`settings.projects.actions.field.selectIconAria`),children:(0,Q.jsx)(X,{name:i,className:`h-4 w-4`})})}),(0,Q.jsx)($t,{align:`start`,className:`w-56 p-2`,children:(0,Q.jsx)(`div`,{className:`grid grid-cols-6 gap-1`,children:Ln.map(n=>{let r=n.Icon,i=(e.icon||`play`)===n.key;return(0,Q.jsx)(`button`,{type:`button`,onClick:()=>S(e.id,e=>({...e,icon:n.key})),className:q(`inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]`,i&&`border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]`),"aria-label":t(`settings.projects.actions.field.iconAria`,{icon:n.label}),children:(0,Q.jsx)(X,{name:r,className:`h-4 w-4`})},n.key)})})})]}),(0,Q.jsx)(Mt,{value:e.name,onChange:t=>S(e.id,e=>({...e,name:t.target.value})),placeholder:t(`settings.projects.actions.field.actionNamePlaceholder`),className:`h-7 flex-1 min-w-0`})]}),(0,Q.jsxs)(`div`,{className:`py-1`,children:[(0,Q.jsx)(`p`,{className:`typography-meta mb-0.5 text-muted-foreground`,children:t(`settings.projects.actions.field.command`)}),(0,Q.jsx)(mn,{embedded:!0,value:e.command,onChange:t=>S(e.id,e=>({...e,command:t.target.value})),placeholder:t(`settings.projects.actions.field.commandPlaceholder`),className:`min-h-[88px] w-full font-mono text-xs`})]}),(0,Q.jsxs)(`div`,{className:`py-1`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,Q.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:t(`settings.projects.actions.field.autoOpenUrl`)}),(0,Q.jsxs)(`div`,{className:`group flex cursor-pointer items-center gap-2`,role:`button`,tabIndex:0,"aria-pressed":e.autoOpenUrl===!0,onClick:()=>S(e.id,e=>({...e,...e.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:t=>{(t.key===` `||t.key===`Enter`)&&(t.preventDefault(),S(e.id,e=>({...e,...e.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[(0,Q.jsx)(vt,{checked:e.autoOpenUrl===!0,onChange:t=>S(e.id,e=>({...e,...t?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:t(`settings.projects.actions.field.autoOpenUrlForAria`,{title:o})}),(0,Q.jsx)(`span`,{className:`typography-ui-label font-normal text-foreground/80`,children:t(`settings.projects.actions.field.autoOpenUrlDescription`)})]})]}),e.autoOpenUrl===!0?(0,Q.jsxs)(`div`,{className:`mt-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Mt,{value:e.openUrl||``,onChange:t=>S(e.id,e=>({...e,openUrl:t.target.value})),placeholder:t(`settings.projects.actions.field.overrideUrlPlaceholder`),className:`h-7 w-full max-w-[24rem]`}),(0,Q.jsxs)(Ft,{children:[(0,Q.jsx)(Nt,{asChild:!0,children:(0,Q.jsx)(X,{name:`information`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help`})}),(0,Q.jsx)(Pt,{sideOffset:8,className:`max-w-xs`,children:t(`settings.projects.actions.field.overrideUrlTooltip`)})]})]}),n?(0,Q.jsxs)(`div`,{className:`mt-2`,children:[(0,Q.jsx)(`p`,{className:`typography-meta mb-0.5 text-muted-foreground`,children:t(`settings.projects.actions.field.desktopSshForward`)}),g.length>0?(0,Q.jsxs)(Dt,{value:e.desktopOpenSshForward&&g.some(t=>t.id===e.desktopOpenSshForward)?e.desktopOpenSshForward:`__none__`,onValueChange:t=>{S(e.id,e=>({...e,...t===`__none__`?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:t}}))},children:[(0,Q.jsx)(wt,{className:`h-7 w-full`,children:(0,Q.jsx)(jt,{placeholder:t(`settings.projects.actions.field.useOutputManualUrl`)})}),(0,Q.jsxs)(Et,{children:[(0,Q.jsx)(St,{value:`__none__`,children:t(`settings.projects.actions.field.useOutputManualUrl`)}),g.map(e=>(0,Q.jsx)(St,{value:e.id,children:e.label},e.id))]})]}):(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(`settings.projects.actions.state.noDesktopSshForwards`)})]}):null]}):null]})]})})]},e.id)})}),_&&a.length>0?(0,Q.jsx)(`p`,{className:`typography-meta text-[var(--status-warning)]`,children:_}):null]})},Jo=e=>{let t=(0,Z.c)(123),{form:n}=e,{t:r}=Fe(),{currentTheme:i}=it(),{name:a,setName:o,icon:s,setIcon:c,color:l,setColor:u,iconBackground:d,setIconBackground:f,parsedDefaultModel:p,handleDefaultModelChange:m,isUploadingIcon:h,isRemovingCustomIcon:g,isDiscoveringIcon:_,pendingRemoveImageIcon:v,setPendingRemoveImageIcon:y,pendingUploadIconPreviewUrl:b,setPreviewImageFailed:x,hasPendingUploadImageIcon:S,hasCustomIcon:C,effectiveHasImageIcon:w,hasRemovableImageIcon:T,showImagePreview:E,fileInputRef:D,handleUploadIcon:O,handleRemoveImageIcon:k,handleDiscoverIcon:A,currentIconImage:j,project:M}=n;if(!M)return null;let N=l?Ot[l]??null:null,P;t[0]===r?P=t[1]:(P=r(`settings.projects.page.field.projectName`),t[0]=r,t[1]=P);let F;t[2]===o?F=t[3]:(F=e=>o(e.target.value),t[2]=o,t[3]=F);let I;t[4]===r?I=t[5]:(I=r(`settings.projects.page.field.projectNamePlaceholder`),t[4]=r,t[5]=I);let L;t[6]!==a||t[7]!==F||t[8]!==I?(L=(0,Q.jsx)(Mt,{value:a,onChange:F,placeholder:I}),t[6]=a,t[7]=F,t[8]=I,t[9]=L):L=t[9];let R;t[10]!==P||t[11]!==L?(R=(0,Q.jsx)(ri,{label:P,itemId:`projects.name`,children:L}),t[10]=P,t[11]=L,t[12]=R):R=t[12];let z;t[13]===r?z=t[14]:(z=r(`settings.projects.page.field.defaultModel`),t[13]=r,t[14]=z);let B;t[15]===r?B=t[16]:(B=r(`settings.projects.page.field.defaultModelDescription`),t[15]=r,t[16]=B);let ee;t[17]!==m||t[18]!==p.modelId||t[19]!==p.providerId?(ee=(0,Q.jsx)(wa,{providerId:p.providerId,modelId:p.modelId,onChange:m,className:`yuri-settings-inline-value`}),t[17]=m,t[18]=p.modelId,t[19]=p.providerId,t[20]=ee):ee=t[20];let te;t[21]!==z||t[22]!==B||t[23]!==ee?(te=(0,Q.jsx)(ri,{label:z,description:B,descriptionPlacement:`outside`,itemId:`projects.default-model`,children:ee}),t[21]=z,t[22]=B,t[23]=ee,t[24]=te):te=t[24];let V;t[25]===r?V=t[26]:(V=r(`settings.projects.page.field.accentColor`),t[25]=r,t[26]=V);let H;t[27]===u?H=t[28]:(H=()=>u(null),t[27]=u,t[28]=H);let U=l===null?`border-2 border-foreground bg-[var(--primary-base)]/10`:`border-border/40 hover:border-border hover:bg-[var(--surface-muted)]`,ne;t[29]===U?ne=t[30]:(ne=q(`h-7 w-7 rounded-md border transition-colors flex items-center justify-center`,U),t[29]=U,t[30]=ne);let W;t[31]===r?W=t[32]:(W=r(`settings.projects.page.field.none`),t[31]=r,t[32]=W);let re;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,Q.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`}),t[33]=re):re=t[33];let ie;t[34]!==H||t[35]!==ne||t[36]!==W?(ie=(0,Q.jsx)(`button`,{type:`button`,onClick:H,className:ne,title:W,children:re}),t[34]=H,t[35]=ne,t[36]=W,t[37]=ie):ie=t[37];let ae;t[38]!==l||t[39]!==u?(ae=At.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>u(e.key),className:q(`h-7 w-7 rounded-md border transition-colors`,l===e.key?`border-2 border-foreground ring-1 ring-[var(--primary-base)]/40`:`border-transparent hover:border-border/70`),style:{backgroundColor:e.cssVar},title:e.label},e.key)),t[38]=l,t[39]=u,t[40]=ae):ae=t[40];let oe;t[41]!==ie||t[42]!==ae?(oe=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[ie,ae]}),t[41]=ie,t[42]=ae,t[43]=oe):oe=t[43];let se;t[44]!==V||t[45]!==oe?(se=(0,Q.jsx)(ri,{label:V,itemId:`projects.accent-color`,children:oe}),t[44]=V,t[45]=oe,t[46]=se):se=t[46];let ce;t[47]===r?ce=t[48]:(ce=r(`settings.projects.page.field.projectIcon`),t[47]=r,t[48]=ce);let le;t[49]===O?le=t[50]:(le=e=>{let t=e.target.files?.[0]??null;O(t),e.currentTarget.value=``},t[49]=O,t[50]=le);let ue;t[51]!==D||t[52]!==le?(ue=(0,Q.jsx)(`input`,{ref:D,type:`file`,accept:`image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg`,className:`hidden`,onChange:le}),t[51]=D,t[52]=le,t[53]=ue):ue=t[53];let de;t[54]===c?de=t[55]:(de=()=>c(null),t[54]=c,t[55]=de);let fe=s===null?`border-2 border-foreground bg-[var(--primary-base)]/10`:`border-border/40 hover:border-border hover:bg-[var(--surface-muted)]`,pe;t[56]===fe?pe=t[57]:(pe=q(`h-7 w-7 rounded-md border transition-colors flex items-center justify-center`,fe),t[56]=fe,t[57]=pe);let me;t[58]===r?me=t[59]:(me=r(`settings.projects.page.field.none`),t[58]=r,t[59]=me);let he;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(he=(0,Q.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`}),t[60]=he):he=t[60];let ge;t[61]!==de||t[62]!==pe||t[63]!==me?(ge=(0,Q.jsx)(`button`,{type:`button`,onClick:de,className:pe,title:me,children:he}),t[61]=de,t[62]=pe,t[63]=me,t[64]=ge):ge=t[64];let G;t[65]!==N||t[66]!==s||t[67]!==c?(G=kt.map(e=>{let t=e.Icon;return(0,Q.jsx)(`button`,{type:`button`,onClick:()=>c(e.key),className:q(`h-7 w-7 rounded-md border transition-colors flex items-center justify-center`,s===e.key?`border-2 border-foreground bg-[var(--primary-base)]/10`:`border-transparent hover:border-border hover:bg-[var(--surface-muted)]`),title:e.label,children:(0,Q.jsx)(X,{name:t,className:`w-4 h-4`,style:N&&s===e.key?{color:N}:void 0})},e.key)}),t[65]=N,t[66]=s,t[67]=c,t[68]=G):G=t[68];let _e;t[69]!==ge||t[70]!==G?(_e=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[ge,G]}),t[69]=ge,t[70]=G,t[71]=_e):_e=t[71];let ve;t[72]!==j||t[73]!==i||t[74]!==w||t[75]!==S||t[76]!==d||t[77]!==b||t[78]!==M||t[79]!==x||t[80]!==E||t[81]!==r?(ve=w&&E&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Q.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:r(`settings.projects.page.field.preview`)}),(0,Q.jsx)(`span`,{className:`inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/60 bg-[var(--surface-elevated)] p-1`,children:(0,Q.jsx)(`span`,{className:`inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]`,style:d?{backgroundColor:d}:void 0,children:S&&b?(0,Q.jsx)(`img`,{src:b,alt:``,className:`h-full w-full object-contain`,draggable:!1,onError:()=>x(!0)}):(0,Q.jsx)(Ct,{project:{...M,iconImage:j??M.iconImage},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:`h-full w-full object-contain`,onError:()=>x(!0)})})})]}),t[72]=j,t[73]=i,t[74]=w,t[75]=S,t[76]=d,t[77]=b,t[78]=M,t[79]=x,t[80]=E,t[81]=r,t[82]=ve):ve=t[82];let ye;t[83]!==w||t[84]!==d||t[85]!==f||t[86]!==r?(ye=w&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,Q.jsx)(`input`,{type:`color`,value:d??`#000000`,onChange:e=>f(e.target.value),className:`h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1`,"aria-label":r(`settings.projects.page.field.projectIconBackgroundAria`)}),(0,Q.jsx)(Mt,{value:d??``,onChange:e=>f(e.target.value),placeholder:`#000000`,className:`h-7 w-[8rem]`}),(0,Q.jsx)(J,{type:`button`,size:`xs`,variant:`outline`,onClick:()=>f(null),className:`h-7 w-7 p-0`,"aria-label":r(`settings.projects.page.field.clearIconBackgroundAria`),title:r(`settings.projects.page.field.clearBackground`),disabled:!d,children:(0,Q.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),t[83]=w,t[84]=d,t[85]=f,t[86]=r,t[87]=ye):ye=t[87];let be;t[88]!==D||t[89]!==A||t[90]!==C||t[91]!==_||t[92]!==h||t[93]!==r?(be=!C&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(J,{size:`xs`,className:`h-6 !font-normal`,onClick:()=>D.current?.click(),disabled:h,children:r(h?`settings.projects.page.actions.uploading`:`settings.projects.page.actions.uploadIcon`)}),(0,Q.jsx)(J,{size:`xs`,className:`h-6 !font-normal`,variant:`outline`,onClick:()=>void A(),disabled:_,children:r(_?`settings.projects.page.actions.discovering`:`settings.projects.page.actions.discoverFavicon`)})]}),t[88]=D,t[89]=A,t[90]=C,t[91]=_,t[92]=h,t[93]=r,t[94]=be):be=t[94];let xe;t[95]!==k||t[96]!==T||t[97]!==g||t[98]!==r?(xe=T&&(0,Q.jsx)(J,{size:`xs`,className:`!font-normal`,variant:`outline`,onClick:()=>void k(),disabled:g,children:r(g?`settings.projects.page.actions.removing`:`settings.projects.page.actions.removeProjectIcon`)}),t[95]=k,t[96]=T,t[97]=g,t[98]=r,t[99]=xe):xe=t[99];let Se;t[100]!==g||t[101]!==v||t[102]!==y||t[103]!==r?(Se=v&&(0,Q.jsx)(J,{size:`xs`,className:`!font-normal`,variant:`outline`,onClick:()=>y(!1),disabled:g,children:r(`settings.projects.page.actions.undoRemove`)}),t[100]=g,t[101]=v,t[102]=y,t[103]=r,t[104]=Se):Se=t[104];let Ce;t[105]!==be||t[106]!==xe||t[107]!==Se?(Ce=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[be,xe,Se]}),t[105]=be,t[106]=xe,t[107]=Se,t[108]=Ce):Ce=t[108];let K;t[109]!==ue||t[110]!==_e||t[111]!==ve||t[112]!==ye||t[113]!==Ce?(K=(0,Q.jsxs)(`div`,{className:`flex w-full flex-col items-end gap-2`,children:[ue,_e,ve,ye,Ce]}),t[109]=ue,t[110]=_e,t[111]=ve,t[112]=ye,t[113]=Ce,t[114]=K):K=t[114];let we;t[115]!==ce||t[116]!==K?(we=(0,Q.jsx)(ri,{label:ce,itemId:`projects.icon`,children:K}),t[115]=ce,t[116]=K,t[117]=we):we=t[117];let Te;return t[118]!==se||t[119]!==we||t[120]!==R||t[121]!==te?(Te=(0,Q.jsxs)(`div`,{className:`yuri-settings-section-stack`,children:[R,te,se,we]}),t[118]=se,t[119]=we,t[120]=R,t[121]=te,t[122]=Te):Te=t[122],Te},Yo=/^#(?:[\da-fA-F]{3}|[\da-fA-F]{6})$/,Xo=e=>{if(!e)return null;let t=e.trim();return t&&Yo.test(t)?t.toLowerCase():null},Zo=e=>{let{t}=Fe(),n=et(e=>e.uploadProjectIcon),r=et(e=>e.removeProjectIcon),i=et(e=>e.discoverProjectIcon),a=et(t=>e?t.projects.find(t=>t.id===e.id)?.iconImage??null:null),[o,s]=$.useState(``),[c,l]=$.useState(null),[u,d]=$.useState(null),[f,p]=$.useState(null),[m,h]=$.useState(void 0),[g,_]=$.useState(!1),[v,y]=$.useState(!1),[b,x]=$.useState(!1),[S,C]=$.useState(!1),[w,T]=$.useState(null),[E,D]=$.useState(null),[O,k]=$.useState(!1),A=$.useRef(null),j=$.useCallback(()=>{T(null),D(e=>(e&&URL.revokeObjectURL(e),null))},[]),M=e?.id??null;$.useEffect(()=>{if(!e){s(``),l(null),d(null),p(null),h(void 0);return}s(e.label??``),l(e.icon??null),d(e.color??null),p(e.iconBackground??null),h(e.defaultModel),C(!1),j(),k(!1)},[e,j]),$.useEffect(()=>()=>{j()},[j]);let N=$.useMemo(()=>Xe(m)??{providerId:``,modelId:``},[m]),P=!!e?.iconImage,F=!!(w&&E),I=e?.iconImage?.source===`custom`,L=P&&!S||F,R=L,z=!!(e&&P&&!S),B=!O&&(F||z),ee=!!e&&(o.trim()!==(e?.label??``).trim()||c!==(e?.icon??null)||u!==(e?.color??null)||f!==(e?.iconBackground??null)||(m??void 0)!==(e?.defaultModel??void 0)||S||!!w),te=$.useCallback((e,t)=>{h(e&&t?`${e}/${t}`:void 0)},[]),V=$.useCallback(t=>{!e||!t||g||(C(!1),k(!1),T(t),D(e=>(e&&URL.revokeObjectURL(e),URL.createObjectURL(t))))},[g,e]),H=$.useCallback(()=>{!e||!R||v||(F&&j(),C(!!P),k(!1))},[j,F,R,P,v,e]),U=$.useCallback(async()=>{if(!(!e||b)){j(),C(!1),k(!1),x(!0);try{let n=await i(e.id);if(!n.ok){Y.error(n.error||t(`settings.projects.page.toast.discoverIconFailed`));return}if(n.skipped){Y.success(t(`settings.projects.page.toast.customIconAlreadySet`));return}Y.success(t(`settings.projects.page.toast.iconDiscovered`))}finally{x(!1)}}},[j,i,b,e,t]),ne=$.useCallback(async i=>{let a=i?.silent===!0;if(!e)return null;let s=o.trim();if(!s)return null;if(w){_(!0);let r=await n(e.id,w);if(_(!1),!r.ok)return Y.error(r.error||t(`settings.projects.page.toast.uploadIconFailed`)),null;a||Y.success(t(`settings.projects.page.toast.iconUpdated`)),j(),C(!1)}let l=S&&!!e.iconImage;if(l){y(!0);let n=await r(e.id);if(y(!1),!n.ok)return Y.error(n.error||t(`settings.projects.page.toast.removeIconFailed`)),null;a||Y.success(t(`settings.projects.page.toast.iconRemoved`)),C(!1),p(null)}return{label:s,icon:c,color:u,iconBackground:Xo(l?null:f),defaultModel:m??null}},[j,u,m,c,f,o,S,w,e,r,t,n]);return $.useEffect(()=>{k(!1)},[M,a?.updatedAt]),{name:o,setName:s,icon:c,setIcon:l,color:u,setColor:d,iconBackground:f,setIconBackground:p,defaultModel:m,parsedDefaultModel:N,handleDefaultModelChange:te,isUploadingIcon:g,isRemovingCustomIcon:v,isDiscoveringIcon:b,pendingRemoveImageIcon:S,setPendingRemoveImageIcon:C,pendingUploadIconFile:w,pendingUploadIconPreviewUrl:E,previewImageFailed:O,setPreviewImageFailed:k,hasStoredImageIcon:P,hasPendingUploadImageIcon:F,hasCustomIcon:I,effectiveHasImageIcon:L,hasRemovableImageIcon:R,showStoredImagePreview:z,showImagePreview:B,fileInputRef:A,clearPendingUploadIcon:j,handleUploadIcon:V,handleRemoveImageIcon:H,handleDiscoverIcon:U,hasChanges:ee,prepareSaveData:ne,currentIconImage:a,project:e}},Qo=450,$o=(e,t)=>{let{t:n}=Fe(),{hasChanges:r,name:i,icon:a,color:o,iconBackground:s,defaultModel:c,pendingRemoveImageIcon:l,pendingUploadIconFile:u,isUploadingIcon:d,isRemovingCustomIcon:f,prepareSaveData:p}=e,m=$.useRef(!1);$.useEffect(()=>{if(!r||!i.trim()||d||f||m.current)return;let e=window.setTimeout(()=>{m.current||(m.current=!0,(async()=>{try{let e=await p({silent:!0});if(e)try{await t(e)}catch{Y.error(n(`settings.projects.page.toast.saveFailed`))}}finally{m.current=!1}})())},Qo);return()=>{window.clearTimeout(e)}},[o,c,r,a,s,f,d,i,t,l,u,p,n])},es=e=>{let t=(0,Z.c)(25),{project:n,onIdentitySave:r}=e,{t:i}=Fe(),a=Zo(n),o;bb0:{if(!n){o=null;break bb0}let e;t[0]!==n.id||t[1]!==n.path?(e={id:n.id,path:n.path},t[0]=n.id,t[1]=n.path,t[2]=e):e=t[2],o=e}let s=o,c;if(t[3]===r?c=t[4]:(c=async e=>{await r(e)},t[3]=r,t[4]=c),$o(a,c),!n||!s)return null;let l;t[5]!==n.path||t[6]!==i?(l=n.path.split(/[\\/]/).filter(Boolean).at(-1)??i(`settings.projects.page.title.default`),t[5]=n.path,t[6]=i,t[7]=l):l=t[7];let u=l,d;t[8]===u?d=t[9]:(d=(0,Q.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:u}),t[8]=u,t[9]=d);let f;t[10]===n.path?f=t[11]:(f=(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground truncate`,title:n.path,children:n.path}),t[10]=n.path,t[11]=f);let p;t[12]!==d||t[13]!==f?(p=(0,Q.jsxs)(`div`,{className:`px-1`,children:[d,f]}),t[12]=d,t[13]=f,t[14]=p):p=t[14];let m;t[15]===a?m=t[16]:(m=(0,Q.jsx)(Jo,{form:a}),t[15]=a,t[16]=m);let h,g;t[17]===s?(h=t[18],g=t[19]):(h=(0,Q.jsx)(qo,{projectRef:s}),g=(0,Q.jsx)(Vo,{projectRef:s}),t[17]=s,t[18]=h,t[19]=g);let _;return t[20]!==p||t[21]!==m||t[22]!==h||t[23]!==g?(_=(0,Q.jsxs)(`div`,{className:`yuri-settings-section-stack`,children:[p,m,h,g]}),t[20]=p,t[21]=m,t[22]=h,t[23]=g,t[24]=_):_=t[24],_};function ts(e,t,n){return Math.min(n,Math.max(t,e))}function ns(e){if(!Number.isFinite(e))return 0;let t=String(e);if(t.includes(`e-`)){let[,e]=t.split(`e-`);return Number(e)||0}let n=t.split(`.`);return n.length===2?n[1].length:0}function rs(e,t){let n=ns(t);return n<=0?e:Number(e.toFixed(n))}var is=$.forwardRef(({value:e,onValueChange:t,min:n=-1/0,max:r=1/0,step:i=1,className:a,containerClassName:o,onBlur:s,disabled:c,fallbackValue:l,onClear:u,emptyLabel:d=`—`,...f},p)=>{let{t:m}=Fe(),[h,g]=$.useState(()=>e===void 0?``:String(e)),{isMobile:_}=sn(),v=$.useRef(!1),y=$.useRef(null),b=$.useCallback(()=>{if(typeof document>`u`||typeof window>`u`)return;y.current?.();let e=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation?.(),y.current?.()},t=window.setTimeout(()=>{y.current?.()},700);y.current=()=>{window.clearTimeout(t),document.removeEventListener(`click`,e,!0),y.current=null},document.addEventListener(`click`,e,!0)},[]);$.useEffect(()=>()=>{y.current?.()},[]),$.useEffect(()=>{g(e===void 0?``:String(e))},[e]);let x=$.useMemo(()=>e===void 0?l===void 0?Number.isFinite(n)?n:0:l:e,[l,n,e]),S=$.useRef(x);$.useEffect(()=>{S.current=x},[x]);let C=$.useCallback(e=>{let a=rs(ts(e,n,r),i);S.current=a,t(a)},[r,n,t,i]),w=$.useCallback(e=>{let t=e.target.value;if(g(t),t.trim()===``){u?.();return}let n=Number(t);Number.isFinite(n)&&C(n)},[C,u]),T=$.useCallback(t=>{if(h.trim()===``){u||g(e===void 0?``:String(e)),s?.(t);return}let a=Number(h);if(!Number.isFinite(a))g(e===void 0?``:String(e));else{let t=rs(ts(a,n,r),i);t===e?S.current=t:C(a),g(String(t))}s?.(t)},[C,h,r,n,s,u,i,e]),E=!!(c||x>=r),D=!!(c||x<=n),O=()=>{D||C(S.current-i)},k=()=>{E||C(S.current+i)},A=e=>t=>{t.preventDefault(),t.stopPropagation(),v.current=!0,b(),e()},j=e=>t=>{if(v.current){v.current=!1,t.preventDefault(),t.stopPropagation();return}e()};return _?(0,Q.jsxs)(`div`,{"data-slot":`number-input`,className:q(`flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain`,`[-webkit-user-select:none] [-webkit-touch-callout:none]`,`disabled:pointer-events-none disabled:opacity-50`,o),children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":m(`numberInput.actions.decreaseAria`),disabled:D,onTouchStart:A(O),onClick:j(O),className:q(`grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none`,`text-muted-foreground`,`disabled:pointer-events-none disabled:opacity-50`,!D&&`active:bg-interactive-hover`),children:(0,Q.jsx)(X,{name:`subtract`,className:`block h-4 w-4`})}),(0,Q.jsx)(`div`,{"data-slot":`number-input-value`,className:q(`flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5`,`text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]`,a),"aria-live":`polite`,children:e===void 0?d:h}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":m(`numberInput.actions.increaseAria`),disabled:E,onTouchStart:A(k),onClick:j(k),className:q(`grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none`,`text-muted-foreground`,`disabled:pointer-events-none disabled:opacity-50`,!E&&`active:bg-interactive-hover`),children:(0,Q.jsx)(X,{name:`add`,className:`block h-4 w-4`})})]}):(0,Q.jsxs)(`div`,{"data-slot":`number-input`,className:q(`flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent`,`disabled:pointer-events-none disabled:opacity-50`,o),children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":m(`numberInput.actions.decreaseAria`),disabled:D,onClick:()=>C(S.current-i),className:q(`flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation`,`text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,`disabled:pointer-events-none disabled:opacity-50`),children:(0,Q.jsx)(X,{name:`subtract`,className:`block h-3.5 w-3.5`})}),(0,Q.jsx)(`input`,{...f,"data-slot":`number-input-value`,ref:p,type:`text`,inputMode:f.inputMode??`numeric`,value:h,onChange:w,onBlur:T,disabled:c,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,className:q(`h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]`,`placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground`,`appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,`disabled:pointer-events-none disabled:cursor-not-allowed`,a)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":m(`numberInput.actions.increaseAria`),disabled:E,onClick:()=>C(S.current+i),className:q(`flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation`,`text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,`disabled:pointer-events-none disabled:opacity-50`),children:(0,Q.jsx)(X,{name:`add`,className:`block h-3.5 w-3.5`})})]})});is.displayName=`NumberInput`;function as(e){let t=e.indexOf(`/`);if(t!==-1){let n=e.substring(0,t);if(n===`gemini`||n===`antigravity`)return e.substring(t+1)}return e}var os={google:[{id:`gemini-auth`,label:`Gemini`,matcher:e=>e.startsWith(`gemini/`),order:1},{id:`antigravity-auth`,label:`Antigravity`,matcher:e=>e.startsWith(`antigravity/`),order:2}]};function ss(e,t){let n=os[t]??[];for(let t of n)if(t.matcher(e))return t;return null}function cs(e){return os[e]??[]}function ls(e){return[...e].sort((e,t)=>e.order-t.order)}function us(e,t){let n=new Map;for(let r of Object.keys(e)){let e=ss(r,t)?.id??null;n.has(e)||n.set(e,[]),n.get(e).push(r)}return n}function ds(e,t,n){let r=new Map;for(let i of e){let e=ss(t(i),n)?.id??null;r.has(e)||r.set(e,[]),r.get(e).push(i)}return r}function fs(e,t){return t.filter(e=>{let t=e.toLowerCase(),n=t.includes(`/`)?t.split(`/`)[1]:t;return!!(n.startsWith(`gemini-3-`)||n.startsWith(`claude-`))})}var ps=(e,t=``,n=!1)=>F({queryKey:z.scoped(`magpie-quotas`,e,t,n),staleTime:0,retry:!1,queryFn:async({signal:t})=>{let r=await a(`/api/quota/magpie`,{signal:t,query:{...e?{directory:e}:{},...n?{refresh:`1`}:{}}});if(!r.ok)throw Error(`Unable to discover Magpie quota sources`);let i=await r.json();if(!i||!Array.isArray(i.sources)||!i.sources.every(e=>e&&typeof e.id==`string`&&typeof e.name==`string`&&Array.isArray(e.results)&&e.results.every(t=>B(t)&&t.source===`magpie`&&t.sourceId===e.id&&t.providerId.startsWith(`magpie:${e.id}:`))))throw Error(`Invalid Magpie quota response`);return i}}),ms=6e4,hs=0,gs=0,_s,vs=0,ys=0,bs=0,xs=new Map,Ss=e=>{let t=Bn.map(e=>e.id),n=typeof e?.usageAutoRefresh==`boolean`&&e.usageAutoRefresh,r=typeof e?.usageRefreshIntervalMs==`number`&&Number.isFinite(e.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(e.usageRefreshIntervalMs))):ms,i=e?.usageDisplayMode===`remaining`?`remaining`:`usage`,a=typeof e?.usageShowPredValues==`boolean`&&e.usageShowPredValues,o=Array.isArray(e?.usageDropdownProviders)?e?.usageDropdownProviders:null,s=o?o.filter(e=>typeof e==`string`&&(e.startsWith(`magpie:`)||t.includes(e))):t,c={},l=e?.usageSelectedModels;if(l&&typeof l==`object`)for(let[e,t]of Object.entries(l))Array.isArray(t)&&(c[e]=t.filter(e=>typeof e==`string`));let u={},d=e?.usageExpandedFamilies;if(d&&typeof d==`object`)for(let[e,t]of Object.entries(d))Array.isArray(t)&&(u[e]=t.filter(e=>typeof e==`string`));return{magpieUsageUrl:typeof e?.magpieUsageUrl==`string`?e.magpieUsageUrl:``,magpieHiddenProviders:Array.isArray(e?.magpieHiddenProviders)?e.magpieHiddenProviders.filter(e=>typeof e==`string`&&e.startsWith(`magpie:`)):[],autoRefresh:n,refreshIntervalMs:r,displayMode:i,showPredValues:a,dropdownProviderIds:s,selectedModels:c,expandedFamilies:u}},Cs=async()=>{let e=g()?.settings;if(e)try{let t=(await e.load())?.settings;return Ss(t??null)}catch{}if(!m()){let e=await a(`/api/config/settings`,{method:`GET`,headers:{Accept:`application/json`}});if(e.ok)return Ss(await e.json().catch(()=>null))}return{magpieUsageUrl:``,magpieHiddenProviders:[],autoRefresh:!1,refreshIntervalMs:ms,displayMode:`usage`,showPredValues:!1,dropdownProviderIds:Bn.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},ws=(e,t,n)=>{let r=e.filter(e=>e?.providerId&&e.providerId!==t);return B(n)&&r.push(n),r},Ts=async(e,t)=>{let n=gs;xs.set(e,(xs.get(e)??0)+1),t(t=>({isFetchingProvider:{...t.isFetchingProvider,[e]:!0}}));try{let r=await L.fetchQuery({queryKey:z.quota(e),queryFn:({signal:t})=>ee(e,t),staleTime:0,retry:!1});if(n!==gs)return{providerId:e,stale:!0};if(!B(r))throw Error(`Invalid quota response`);return t(t=>({results:ws(t.results,e,r)})),{providerId:e,result:r}}catch(r){return n===gs?(t(e=>e.results.every(e=>e?.providerId)?{}:{results:e.results.filter(e=>e?.providerId)}),{providerId:e,error:r instanceof Error?r.message:`Failed to fetch quota`}):{providerId:e,stale:!0}}finally{if(n===gs){let n=(xs.get(e)??1)-1;n>0?xs.set(e,n):xs.delete(e),t(t=>({isFetchingProvider:{...t.isFetchingProvider,[e]:n>0}}))}}},Es=()=>{_s=void 0,vs+=1,gs+=1,hs+=1,xs.clear(),Ds.setState({magpieUsageUrl:``,magpieHiddenProviders:[],magpieSources:[],magpieError:null,results:[],isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null})},Ds=_()(y((e,t)=>({magpieSources:[],magpieError:null,magpieHiddenProviders:[],magpieUsageUrl:``,results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:ms,displayMode:`usage`,showPredValues:!1,dropdownProviderIds:Bn.map(e=>e.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{let t=gs;try{let n=await Cs();if(t!==gs)return;e(e=>({...n,dropdownProviderIds:[...n.dropdownProviderIds.filter(e=>!e.startsWith(`magpie:`)),...e.results.filter(e=>e.source===`magpie`&&!n.magpieHiddenProviders.includes(e.providerId)).map(e=>e.providerId)]}))}catch(e){console.warn(`Failed to load usage settings:`,e)}},fetchAllQuotas:async()=>{let n=++hs;e({isLoading:!0,error:null});let r=Bn.map(e=>e.id),[i]=await Promise.all([Promise.all(r.map(t=>Ts(t,e))),t().fetchMagpieQuotas(!0)]);if(n===hs){let t=i.find(e=>`error`in e);e({isLoading:!1,...i.some(e=>`result`in e)?{lastUpdated:Date.now()}:{},error:t?.error??null})}},fetchProviderQuota:async n=>{if(n.startsWith(`magpie:`))return t().fetchMagpieQuotas(!0);let r=await Ts(n,e);`stale`in r||e({error:`error`in r?r.error:null})},fetchMagpieQuotas:async(n=!1)=>{let r=gs,i=E.getState().currentDirectory,a=t().magpieUsageUrl,o=JSON.stringify([i,a]);_s!==o&&(_s=o,vs+=1,e(e=>({results:e.results.filter(e=>e?.source!==`magpie`),magpieSources:[],magpieError:null})));let s=vs,c=++ys;try{let{sources:o,incomplete:l}=await L.fetchQuery(ps(i,a,n));if(r!==gs||s!==vs||c<bs||i!==E.getState().currentDirectory||a!==t().magpieUsageUrl)return;bs=c,e(e=>{let t=new Map(o.filter(e=>e.error&&!e.clearPrevious&&e.results.length===0).map(e=>[e.id,e.error]));if(l){let n=new Set(o.map(e=>e.id));for(let r of e.results)r.sourceId&&!n.has(r.sourceId)&&t.set(r.sourceId,`Magpie discovery is incomplete`)}let n=e.results.filter(e=>e?.providerId&&(e.source!==`magpie`||t.has(e.sourceId??``))).map(e=>e.source===`magpie`&&t.has(e.sourceId??``)?{...e,ok:!1,error:t.get(e.sourceId??``)}:e);n.push(...o.flatMap(e=>e.results));let r=n.filter(e=>e.source===`magpie`).map(e=>e.providerId);return{results:n,magpieSources:o,magpieError:null,dropdownProviderIds:[...e.dropdownProviderIds.filter(e=>!e.startsWith(`magpie:`)),...r.filter(t=>!e.magpieHiddenProviders.includes(t))]}})}catch(n){if(r!==gs||s!==vs||c<bs||i!==E.getState().currentDirectory||a!==t().magpieUsageUrl)return;bs=c,e({magpieError:n instanceof Error?n.message:`Unable to read Magpie quotas`})}},setSelectedProvider:t=>e({selectedProviderId:t}),setAutoRefresh:t=>e({autoRefresh:t}),setRefreshInterval:t=>{e({refreshIntervalMs:Math.max(3e4,Math.min(3e5,Math.round(t)))})},setDisplayMode:t=>e({displayMode:t}),setShowPredValues:t=>e({showPredValues:t}),setDropdownProviderIds:n=>{let r=t().results.filter(e=>e.source===`magpie`),i=new Set(r.map(e=>e.providerId));e({dropdownProviderIds:n,magpieHiddenProviders:[...t().magpieHiddenProviders.filter(e=>!i.has(e)),...r.filter(e=>!n.includes(e.providerId)).map(e=>e.providerId)]})},setSelectedModels:(t,n)=>{e(e=>({selectedModels:{...e.selectedModels,[t]:n}}))},toggleModelSelected:(t,n)=>{e(e=>{let r=e.selectedModels[t]??[],i=r.includes(n)?r.filter(e=>e!==n):[...r,n];return{selectedModels:{...e.selectedModels,[t]:i}}})},setExpandedFamilies:(n,r)=>{e(e=>({expandedFamilies:{...e.expandedFamilies,[n]:r}})),j({usageExpandedFamilies:t().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{e(e=>{let t=e.expandedFamilies[n]??[],i=t.includes(r)?t.filter(e=>e!==r):[...t,r];return{expandedFamilies:{...e.expandedFamilies,[n]:i}}}),j({usageExpandedFamilies:t().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((t().selectedModels[n]?.length??0)>0)return;let i=fs(n,r);i.length!==0&&(e(e=>({selectedModels:{...e.selectedModels,[n]:i}})),j({usageSelectedModels:t().selectedModels}))}}),{name:`quota-store`})),Os=()=>{let e=(0,Z.c)(11),t=E(ks),n=Ds(As),r=Ds(js),i;e[0]===r?i=e[1]:(i=()=>{r()},e[0]=r,e[1]=i);let a;e[2]!==t||e[3]!==r||e[4]!==n?(a=[t,n,r],e[2]=t,e[3]=r,e[4]=n,e[5]=a):a=e[5],$.useEffect(i,a);let o=Ds(Ms),s=Ds(Ns),c=Ds(Ps),l,u;e[6]!==o||e[7]!==c||e[8]!==s?(l=()=>{if(!o)return;let e=window.setInterval(()=>{c()},s);return()=>window.clearInterval(e)},u=[o,s,c],e[6]=o,e[7]=c,e[8]=s,e[9]=l,e[10]=u):(l=e[9],u=e[10]),$.useEffect(l,u)};function ks(e){return e.currentDirectory}function As(e){return e.magpieUsageUrl}function js(e){return e.fetchMagpieQuotas}function Ms(e){return e.autoRefresh}function Ns(e){return e.refreshIntervalMs}function Ps(e){return e.fetchAllQuotas}var Fs=e=>{let t=(0,Z.c)(20),{percent:n,tonePercent:r,className:i,expectedMarkerPercent:a}=e,o;t[0]===n?o=t[1]:(o=Qt(n)??0,t[0]=n,t[1]=o);let s=o,c=r??n,l;t[2]===c?l=t[3]:(l=It(c),t[2]=c,t[3]=l);let u=l,d=a==null?null:Math.max(0,Math.min(100,a)),f;t[4]===u?f=t[5]:(f=u===`critical`?{backgroundColor:`var(--status-error)`}:u===`warn`?{backgroundColor:`var(--status-warning)`}:{backgroundColor:`var(--status-success)`},t[4]=u,t[5]=f);let p=f,m;t[6]===i?m=t[7]:(m=q(`relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden`,i),t[6]=i,t[7]=m);let h=`${s}%`,g;t[8]!==p||t[9]!==h?(g={...p,width:h},t[8]=p,t[9]=h,t[10]=g):g=t[10];let _;t[11]!==s||t[12]!==g?(_=(0,Q.jsx)(`div`,{className:`h-full transition-all duration-300`,style:g,role:`progressbar`,"aria-valuenow":s,"aria-valuemin":0,"aria-valuemax":100}),t[11]=s,t[12]=g,t[13]=_):_=t[13];let v;t[14]===d?v=t[15]:(v=d!=null&&d>0&&d<100&&(0,Q.jsx)(`div`,{className:`absolute top-0 h-full w-0.5 bg-foreground`,style:{left:`${d}%`},title:`Expected usage if spread evenly: ${Math.round(d)}% of quota`,"aria-hidden":`true`}),t[14]=d,t[15]=v);let y;return t[16]!==m||t[17]!==_||t[18]!==v?(y=(0,Q.jsxs)(`div`,{className:m,children:[_,v]}),t[16]=m,t[17]=_,t[18]=v,t[19]=y):y=t[19],y},Is=e=>{let t=(0,Z.c)(67),{paceInfo:n,className:r,compact:i}=e,a=i!==void 0&&i,{t:o}=Fe(),s;t[0]===n.status?s=t[1]:(s=Ut(n.status),t[0]=n.status,t[1]=s);let c=s,l;bb0:{switch(n.status){case`on-track`:{let e;t[2]===o?e=t[3]:(e=o(`settings.usage.pace.status.onTrack`),t[2]=o,t[3]=e),l=e;break bb0}case`slightly-fast`:{let e;t[4]===o?e=t[5]:(e=o(`settings.usage.pace.status.slightlyFast`),t[4]=o,t[5]=e),l=e;break bb0}case`too-fast`:{let e;t[6]===o?e=t[7]:(e=o(`settings.usage.pace.status.tooFast`),t[6]=o,t[7]=e),l=e;break bb0}case`exhausted`:{let e;t[8]===o?e=t[9]:(e=o(`settings.usage.pace.status.usedUp`),t[8]=o,t[9]=e),l=e;break bb0}}l=void 0}let u=l,d;t[10]!==n.predictText||t[11]!==o?(d=o(`settings.usage.pace.predictionTooltip`,{prediction:n.predictText}),t[10]=n.predictText,t[11]=o,t[12]=d):d=t[12];let f=d;if(a){let e;t[13]===r?e=t[14]:(e=q(`flex items-center gap-1.5`,r),t[13]=r,t[14]=e);let i;t[15]===c?i=t[16]:(i={backgroundColor:c},t[15]=c,t[16]=i);let a;t[17]!==u||t[18]!==i?(a=(0,Q.jsx)(`div`,{className:`h-2 w-2 rounded-full flex-shrink-0`,style:i,title:u}),t[17]=u,t[18]=i,t[19]=a):a=t[19];let s;t[20]===c?s=t[21]:(s={color:c},t[20]=c,t[21]=s);let l=n.isExhausted?void 0:f,d;t[22]!==n.isExhausted||t[23]!==n.predictText||t[24]!==n.remainingSeconds||t[25]!==o?(d=n.isExhausted?(0,Q.jsx)(Q.Fragment,{children:o(`settings.usage.pace.wait`,{duration:Ht(n.remainingSeconds)})}):(0,Q.jsx)(Q.Fragment,{children:o(`settings.usage.pace.prediction`,{prediction:n.predictText})}),t[22]=n.isExhausted,t[23]=n.predictText,t[24]=n.remainingSeconds,t[25]=o,t[26]=d):d=t[26];let p;t[27]!==d||t[28]!==s||t[29]!==l?(p=(0,Q.jsx)(`span`,{className:`typography-micro tabular-nums`,style:s,title:l,children:d}),t[27]=d,t[28]=s,t[29]=l,t[30]=p):p=t[30];let m;return t[31]!==p||t[32]!==e||t[33]!==a?(m=(0,Q.jsxs)(`div`,{className:e,children:[a,p]}),t[31]=p,t[32]=e,t[33]=a,t[34]=m):m=t[34],m}let p;t[35]===r?p=t[36]:(p=q(`flex items-center justify-between gap-2`,r),t[35]=r,t[36]=p);let m;t[37]!==n.isExhausted||t[38]!==n.paceRateText||t[39]!==o?(m=!n.isExhausted&&(0,Q.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:o(`settings.usage.pace.rate`,{rate:n.paceRateText})}),t[37]=n.isExhausted,t[38]=n.paceRateText,t[39]=o,t[40]=m):m=t[40];let h;t[41]===m?h=t[42]:(h=(0,Q.jsx)(`div`,{className:`flex items-center gap-1.5`,children:m}),t[41]=m,t[42]=h);let g;t[43]===c?g=t[44]:(g={color:c},t[43]=c,t[44]=g);let _;t[45]!==n.isExhausted||t[46]!==n.predictText||t[47]!==n.remainingSeconds||t[48]!==f||t[49]!==u||t[50]!==o?(_=n.isExhausted?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:u}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:o(`settings.usage.pace.waitSeparator`)}),(0,Q.jsx)(`span`,{className:`font-medium`,children:Ht(n.remainingSeconds)})]}):(0,Q.jsxs)(`span`,{title:f,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:o(`settings.usage.pace.predictionLabel`)}),(0,Q.jsx)(`span`,{className:`font-medium`,children:n.predictText})]}),t[45]=n.isExhausted,t[46]=n.predictText,t[47]=n.remainingSeconds,t[48]=f,t[49]=u,t[50]=o,t[51]=_):_=t[51];let v;t[52]!==g||t[53]!==_?(v=(0,Q.jsx)(`span`,{className:`typography-micro tabular-nums`,style:g,children:_}),t[52]=g,t[53]=_,t[54]=v):v=t[54];let y;t[55]===c?y=t[56]:(y={backgroundColor:c},t[55]=c,t[56]=y);let b;t[57]!==u||t[58]!==y?(b=(0,Q.jsx)(`div`,{className:`h-2 w-2 rounded-full flex-shrink-0`,style:y,title:u}),t[57]=u,t[58]=y,t[59]=b):b=t[59];let x;t[60]!==v||t[61]!==b?(x=(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[v,b]}),t[60]=v,t[61]=b,t[62]=x):x=t[62];let S;return t[63]!==x||t[64]!==p||t[65]!==h?(S=(0,Q.jsxs)(`div`,{className:p,children:[h,x]}),t[63]=x,t[64]=p,t[65]=h,t[66]=S):S=t[66],S},Ls=e=>e instanceof Error&&e.name===`CancelledError`,Rs=_(()=>({setStatus:e=>Lt(L,e),refreshStatus:async(e,t)=>{let r=n();t?.force&&await L.cancelQueries({queryKey:z.github.auth(r),exact:!0});try{return await Kt(L,e,r)}catch(e){if(Ls(e))return Wt(L,r);throw e}}})),zs={displayMode:`browser`,installed:!1,browserTab:!0},Bs=new Set,Vs=zs,Hs=!1,Us,Ws=()=>{let e=Yt();return{displayMode:e,installed:e!==`browser`,browserTab:e===`browser`}},Gs=()=>(!Hs&&typeof window<`u`&&(Vs=Ws(),Hs=!0),Vs),Ks=()=>{let e=Ws();Hs=!0,e.displayMode!==Vs.displayMode&&(Vs=e,Bs.forEach(e=>e()))},qs=()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=[window.matchMedia(`(display-mode: standalone)`),window.matchMedia(`(display-mode: minimal-ui)`),window.matchMedia(`(display-mode: fullscreen)`),window.matchMedia(`(display-mode: window-controls-overlay)`)];for(let t of e)typeof t.addEventListener==`function`?t.addEventListener(`change`,Ks):typeof t.addListener==`function`&&t.addListener(Ks);return window.addEventListener(`appinstalled`,Ks),window.addEventListener(`focus`,Ks),()=>{for(let t of e)typeof t.removeEventListener==`function`?t.removeEventListener(`change`,Ks):typeof t.removeListener==`function`&&t.removeListener(Ks);window.removeEventListener(`appinstalled`,Ks),window.removeEventListener(`focus`,Ks)}},Js=e=>(Bs.add(e),Us??=qs(),Ks(),()=>{Bs.delete(e),Bs.size===0&&(Us?.(),Us=void 0)}),Ys=()=>$.useSyncExternalStore(Js,Gs,Xs);function Xs(){return zs}var Zs=`Yuri`,Qs=_()(v(e=>({sidebarBrandName:Zs,setSidebarBrandName:t=>{let n=t.slice(0,64);e(e=>e.sidebarBrandName===n?e:{sidebarBrandName:n})}}),{name:`sidebar-brand-store`,storage:A(),version:3,migrate:(e,t)=>{if(!e||typeof e!=`object`)return e;let n={...e};return t<1&&n.sidebarBrandName===`YEE CODE`&&(n.sidebarBrandName=Zs),t<2&&n.sidebarBrandName===`Open Chamber`&&(n.sidebarBrandName=Zs),t<3&&(n.sidebarBrandName===`OPEN CHAMBER`||n.sidebarBrandName===`Open Chamber`)&&(n.sidebarBrandName=Zs),n}}));typeof window<`u`&&t(e=>{i(e)&&Qs.persist.rehydrate()});var $s=(e,t)=>e?t.kind===e.kind?t.projectRoot.length===e.projectRoot.length?t.projectId.localeCompare(e.projectId)<0:t.projectRoot.length>e.projectRoot.length:t.kind===`project`:!0,ec=(e,t,n)=>{$s(e.get(t),n)&&e.set(t,n)},tc=e=>{let t=e;return V(t.directory)??V(t.project?.worktree)},nc=e=>{if(e===`/`||/^[A-Z]:$/.test(e))return null;let t=e.lastIndexOf(`/`);return t<0?null:t===0?`/`:t===2&&/^[A-Z]:\//.test(e)?e.slice(0,2):e.slice(0,t)},rc=(e,t,n,r,i=[])=>{let a=new Map,o=new Map;for(let e of t){let t=V(e.normalizedPath);if(!t)continue;let n=o.get(t);(!n||e.id.localeCompare(n.id)<0)&&o.set(t,e),ec(a,t,{projectId:e.id,projectRoot:t,scopeDirectory:t,kind:`project`})}if(!r)for(let[e,t]of n){let n=V(e),r=n?o.get(n):void 0;if(!(!r||!n))for(let e of t){let t=V(e.path);t&&ec(a,t,{projectId:r.id,projectRoot:n,scopeDirectory:t,kind:`worktree`})}}let s=new Map,c=new Map,l=new Map,u=new Map,d=new Map,f=e=>{if(!e)return null;if(s.has(e))return s.get(e)??null;if(r){let t=a.get(e)??null;return s.set(e,t),t}let t=[],n=e,i=null;for(;n;){if(s.has(n)){i=s.get(n)??null;break}if(t.push(n),i=a.get(n)??null,i)break;n=nc(n)}for(let e of t)s.set(e,i);return i},p=(e,t,n)=>{for(let r of e){let e=f(tc(r));if(!e)continue;c.set(r.id,e);let i=t.get(e.projectId);if(i?i.push(r):t.set(e.projectId,[r]),!n)continue;let a=n.get(e.scopeDirectory);a?a.add(r.id):n.set(e.scopeDirectory,new Set([r.id]))}};return p(e,l,d),p(i,u),{bySessionId:c,sessionsByProject:l,archivedSessionsByProject:u,sessionsByScope:d,directoryResolutions:s.size}},ic=`__other__`;function ac(e){return e.time?.updated??e.time?.archived??e.time?.created??0}function oc({mode:e=`dialog`}){let{t}=Fe(),{isMobile:n,isTablet:r,hasTouchInput:i}=sn(),a=n||r||i,o=e===`page`,s=O(e=>e.isArchivedSessionsDialogOpen),c=O(e=>e.setArchivedSessionsDialogOpen),l=o||s,u=et(e=>e.projects),d=He(e=>e.archivedSessions),f=qe(e=>e.setCurrentSession),p=O(e=>e.setSettingsDialogOpen),[h,g]=$.useState(!1),[_,v]=$.useState(null),[y,b]=$.useState(null);$.useEffect(()=>{if(!l){v(null),b(null);return}let e=!1;return g(!0),ze().catch(()=>{e||Y.error(t(`settings.yuri.archivedSessions.toast.loadFailed`))}).finally(()=>{e||g(!1)}),()=>{e=!0}},[l,t]);let x=$.useMemo(()=>{let e=rc([],u.map(e=>({id:e.id,normalizedPath:e.path})),new Map,m(),d),n=new Map;for(let[t,r]of e.archivedSessionsByProject)n.set(t,[...r].sort((e,t)=>ac(t)-ac(e)));let r=new Set;for(let e of n.values())for(let t of e)r.add(t.id);let i=d.filter(e=>!r.has(e.id)).sort((e,t)=>ac(t)-ac(e));i.length>0&&n.set(ic,i);let a=[];for(let e of u){let t=n.get(e.id)??[];t.length!==0&&a.push({projectId:e.id,label:e.label||e.path,path:e.path,sessions:t})}let o=n.get(ic);return o&&o.length>0&&a.push({projectId:ic,label:t(`settings.yuri.archivedSessions.otherProjects`),path:null,sessions:o}),a.sort((e,t)=>t.sessions.length-e.sessions.length||e.label.localeCompare(t.label)),a},[d,u,t]),S=d.length,C=_?x.find(e=>e.projectId===_)??null:null,w=$.useCallback(async e=>{b(e.id);try{await Ue(e.id)?Y.success(t(`settings.yuri.archivedSessions.toast.restored`)):Y.error(t(`settings.yuri.archivedSessions.toast.restoreFailed`))}finally{b(null)}},[t]),T=$.useCallback(e=>{let t=Re(e);f(e.id,t),c(!1),p(!1)},[f,c,p]),E=C?C.label:t(`settings.yuri.archivedSessions.dialog.title`),D=C?C.sessions.length===1?t(`settings.yuri.archivedSessions.dialog.sessionCountSingle`,{count:C.sessions.length}):t(`settings.yuri.archivedSessions.dialog.sessionCountPlural`,{count:C.sessions.length}):t(`settings.yuri.archivedSessions.dialog.description`),k=(0,Q.jsxs)(`div`,{className:`yuri-picker-list space-y-3`,children:[C?(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:`!h-7 !px-2 !font-normal text-muted-foreground`,onClick:()=>v(null),children:[(0,Q.jsx)(X,{name:`arrow-left-s`,className:`mr-1 h-4 w-4`}),t(`settings.yuri.archivedSessions.dialog.backToProjects`)]}):null,h?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 typography-meta text-muted-foreground py-6`,children:[(0,Q.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),t(`settings.yuri.archivedSessions.dialog.loading`)]}):C?C.sessions.length===0?(0,Q.jsx)(`div`,{className:`yuri-picker-empty rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground`,children:t(`settings.yuri.archivedSessions.dialog.emptyProject`)}):(0,Q.jsx)(`div`,{className:`yuri-picker-rows space-y-1.5`,children:C.sessions.map(e=>{let n=Re(e),r=ac(e),i=y===e.id;return(0,Q.jsxs)(`div`,{className:`yuri-picker-row flex flex-col gap-2 rounded-lg border border-border/60 px-3 py-2.5 sm:flex-row sm:items-center sm:gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`yuri-picker-label typography-ui-label font-medium text-foreground truncate`,children:e.title||t(`sessions.sidebar.session.untitled`)}),(0,Q.jsxs)(`div`,{className:`yuri-picker-meta typography-meta text-muted-foreground truncate`,children:[r>0?on(r):null,r>0&&n?` · `:null,n?Ne(n):null]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,size:`xs`,className:`!font-normal`,disabled:i,onClick:()=>T(e),children:t(`settings.yuri.archivedSessions.actions.preview`)}),(0,Q.jsxs)(J,{type:`button`,variant:`default`,size:`xs`,className:`!font-normal`,disabled:i,onClick:()=>void w(e),children:[i?(0,Q.jsx)(X,{name:`loader-4`,className:`mr-1 h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(X,{name:`inbox-unarchive`,className:`mr-1 h-3.5 w-3.5`}),t(`settings.yuri.archivedSessions.actions.restore`)]})]})]},e.id)})}):x.length===0?(0,Q.jsx)(`div`,{className:`yuri-picker-empty rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground`,children:t(`settings.yuri.archivedSessions.dialog.empty`)}):(0,Q.jsx)(`div`,{className:`yuri-picker-rows space-y-1.5`,children:x.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>v(e.projectId),className:q(`yuri-picker-row flex w-full items-center gap-3 rounded-lg border border-border/60 px-3 py-2.5 text-left`,`hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`),children:[(0,Q.jsx)(X,{name:`folder`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`yuri-picker-label typography-ui-label font-medium text-foreground truncate`,children:e.label}),e.path?(0,Q.jsx)(`div`,{className:`yuri-picker-meta typography-meta text-muted-foreground truncate`,children:Ne(e.path)}):null]}),(0,Q.jsx)(`span`,{className:`typography-meta tabular-nums text-muted-foreground shrink-0`,children:e.sessions.length===1?t(`settings.yuri.archivedSessions.dialog.sessionCountSingle`,{count:e.sessions.length}):t(`settings.yuri.archivedSessions.dialog.sessionCountPlural`,{count:e.sessions.length})}),(0,Q.jsx)(X,{name:`arrow-right-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]},e.projectId))}),!C&&!h&&S>0?(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(S===1?`settings.yuri.archivedSessions.summarySingle`:`settings.yuri.archivedSessions.summaryPlural`,{count:S})}):null]});return o?(0,Q.jsxs)(`div`,{"data-settings-item":`archived-sessions.manage`,className:`yuri-settings-section-stack`,children:[(0,Q.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:t(`settings.yuri.archivedSessions.description`)}),k]}):a?(0,Q.jsx)(Zt,{open:s,title:E,onClose:()=>c(!1),contentMaxHeightClassName:`max-h-[min(80vh,640px)]`,renderHeader:e=>(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 border-b border-border/40 px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:E}),e]}),(0,Q.jsx)(`p`,{className:`typography-micro text-muted-foreground`,children:D})]}),children:k}):(0,Q.jsx)(ut,{open:s,onOpenChange:c,children:(0,Q.jsxs)(st,{presentation:`picker`,children:[(0,Q.jsx)(ot,{className:`yuri-picker-header`,children:(0,Q.jsx)(ct,{className:`yuri-picker-title truncate`,children:E})}),k]})})}function sc(){let e=(0,Z.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(oc,{mode:`dialog`}),e[0]=t):t=e[0],t}var cc={globe:`global`,server:`server`,"circle-check":`checkbox-circle`,"circle-x":`close-circle`,"window-analytics":`bar-chart-box`};function lc(e){let t=(0,Z.c)(14),{mobile:n,sidebar:r}=e,i=n!==void 0&&n,a=r!==void 0&&r,{host:o,snapshot:s}=fn();if(!o||s.titlebarItems.length===0)return null;let c=!a||void 0,l=a||void 0,u=a?`app-region-no-drag space-y-0.5`:`app-region-no-drag flex min-w-0 max-w-32 items-center gap-1 overflow-x-auto scrollbar-hidden`,d;if(t[0]!==o||t[1]!==i||t[2]!==a||t[3]!==s.titlebarItems){let e;t[5]!==o||t[6]!==i||t[7]!==a?(e=e=>{let t=e.icon&&(cc[e.icon]??(Object.hasOwn(at,e.icon)?e.icon:void 0)),n=(0,Q.jsxs)(Q.Fragment,{children:[e.busy?(0,Q.jsx)(X,{name:`loader-4`,className:q(a?`size-4`:`size-3.5`,`shrink-0 animate-spin motion-reduce:animate-none`)}):t?(0,Q.jsx)(X,{name:t,className:a?`size-4 shrink-0`:`size-3.5`}):a?(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`size-4 shrink-0`}):null,a||!t?(0,Q.jsx)(`span`,{className:a?`truncate`:`max-w-24 truncate`,children:e.label}):null]});return e.actionable?(0,Q.jsx)(J,{size:a||i?`sm`:`xs`,variant:a?`ghost`:`default`,className:q(`aria-pressed:bg-interactive-selection aria-pressed:text-interactive-selection-foreground`,a&&`w-full justify-start px-2 font-normal`,a&&i&&`h-11`),title:e.label,"aria-label":e.title??e.label,"aria-pressed":e.pressed,"aria-busy":!!e.busy,disabled:!!e.busy,onClick:()=>void o.runTitlebarItem(e.key),children:n},e.key):(0,Q.jsx)(`span`,{role:`status`,title:e.label,"aria-label":e.title??e.label,"aria-busy":!!e.busy,className:q(`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-muted-foreground`,a?`w-full text-sm`:`bg-muted text-xs`),children:n},e.key)},t[5]=o,t[6]=i,t[7]=a,t[8]=e):e=t[8],d=s.titlebarItems.map(e),t[0]=o,t[1]=i,t[2]=a,t[3]=s.titlebarItems,t[4]=d}else d=t[4];let f;return t[9]!==c||t[10]!==l||t[11]!==u||t[12]!==d?(f=(0,Q.jsx)(`div`,{"data-gui-titlebar-items":c,"data-gui-sidebar-items":l,className:u,children:d}),t[9]=c,t[10]=l,t[11]=u,t[12]=d,t[13]=f):f=t[13],f}var uc=48;function dc({title:e,eyebrow:t,trailing:n,className:r}){let i=(0,$.useRef)(null),a=(0,$.useRef)(null),o=(0,$.useRef)(null),s=(0,$.useRef)(null),c=(0,$.useRef)(null),l=Me(()=>{s.current=null;let e=i.current,t=a.current;if(!e||!t)return;let n=Math.min(1,Math.max(0,t.scrollTop/uc)),r=o.current?.matches?Number(n>=.5):n;c.current!==null&&Math.abs(c.current-r)<.001||(c.current=r,e.style.setProperty(`--yuri-mobile-title-collapse`,r.toFixed(4)))}),u=Me(()=>{s.current===null&&(s.current=window.requestAnimationFrame(l))});return(0,$.useEffect)(()=>{let e=i.current;if(!e)return;let t=e.closest(`.yuri-mobile-settings-root-surface, [role="tabpanel"]`);if(!t)return;let n=window.matchMedia(`(prefers-reduced-motion: reduce)`);return a.current=t,o.current=n,c.current=null,t.addEventListener(`scroll`,u,{passive:!0}),n.addEventListener(`change`,u),l(),()=>{t.removeEventListener(`scroll`,u),n.removeEventListener(`change`,u),s.current!==null&&window.cancelAnimationFrame(s.current),s.current=null,a.current=null,o.current=null,c.current=null}},[]),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`header`,{ref:i,className:q(`yuri-mobile-collapsing-header flex shrink-0 items-start gap-4`,r),children:(0,Q.jsxs)(`div`,{className:`yuri-mobile-collapsing-header-inner`,children:[(0,Q.jsxs)(`div`,{className:`yuri-mobile-collapsing-header-title-block min-w-0 flex-1`,children:[t?(0,Q.jsx)(`p`,{className:`yuri-mobile-collapsing-header-eyebrow truncate typography-micro font-medium text-muted-foreground`,children:t}):null,(0,Q.jsx)(`h1`,{className:`yuri-mobile-root-page-title truncate font-semibold text-foreground`,children:e})]}),(0,Q.jsxs)(`div`,{className:`yuri-mobile-collapsing-header-trailing flex min-h-10 shrink-0 items-center gap-3.5`,children:[(0,Q.jsx)(lc,{mobile:!0}),n]})]})}),(0,Q.jsx)(`div`,{className:`yuri-mobile-collapsing-header-spacer`,"aria-hidden":`true`})]})}export{ui as $,Va as A,Sa as B,Io as C,Co as D,So as E,ga as F,zi as G,Bi as H,ya as I,Ii as J,Fi as K,_a as L,Na as M,wa as N,ho as O,Ca as P,li as Q,ba as R,Lo as S,wo as T,Ai as U,na as V,Ri as W,bi as X,Ni as Y,yi as Z,ds as _,rc as a,Zr as at,es as b,Rs as c,Un as ct,Es as d,Vn as dt,ri as et,Os as f,us as g,as as h,oc as i,ti as it,Ha as j,za as k,Is as l,Hn as lt,cs as m,lc as n,ii as nt,Qs as o,Er as ot,Ds as p,Pi as q,sc as r,ai as rt,Ys as s,$n as st,dc as t,ni as tt,Fs as u,Bn as ut,ls as v,Fo as w,Uo as x,is as y,xa as z};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/rolldown-runtime-hePW80VL.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{w as t,x as n}from"./desktop-JwYqThiw.js";import{at as r}from"./vendor-base-ui-BQjbsJ43.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{n as i}from"./vendor-react-D5d-V1vN.js";import{o as a}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as o}from"./platform-DFJEtBlo.js";var s=e(r(),1),c=i(),l=.85,u=1.2,d=10/9,f=.9,p=.98,m=p/f,h=`yuri.designPtScale.v8`;function g(e){return!Number.isFinite(e)||e<=0?1:Math.min(u,Math.max(l,e))}function _(e){if(!e)return p;let t=e.density,n=(e.xdpi+e.ydpi)/2;if(!(t>0)||!(n>=50)||n>800)return p;let r=g(n/t/163);return Math.min(p,r*m)}function v(){if(typeof window>`u`)return 1;try{let e=Number.parseFloat(window.localStorage.getItem(`yuri.designPtScale.v8`)??``),t=window.Capacitor?.getPlatform?.();return t===`android`?Math.min(p,g(e)):t===`ios`?d:g(e)}catch{return 1}}function y(e){if(!(typeof window>`u`))try{window.localStorage.setItem(h,String(e))}catch{}}function b(e,t=document.documentElement){let n=g(e);t.style.setProperty(`--dpt`,`${n}px`),t.style.setProperty(`--dpt-n`,String(n))}async function x(){if(typeof document>`u`)return 1;b(v());let{Capacitor:e,registerPlugin:t}=await a(async()=>{let{Capacitor:e,registerPlugin:t}=await import(`./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js`).then(e=>e.i);return{Capacitor:e,registerPlugin:t}},__vite__mapDeps([0,1]));if(!e.isNativePlatform())return b(1),1;if(e.getPlatform()===`ios`)return b(d),y(d),d;if(e.getPlatform()!==`android`)return b(1),1;if(!e.isPluginAvailable(`YuriPhysicalScale`))return b(p),y(p),p;try{let e=_(await t(`YuriPhysicalScale`).getMetrics());return y(e),b(e),e}catch{return b(p),y(p),p}}var S={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536},C={isMobile:!1,isTablet:!1,isDesktop:!0,deviceType:`desktop`,screenWidth:1024,breakpoint:`lg`,hasTouchInput:!1,hasTouchOnlyPointer:!1},w=()=>typeof window>`u`?!1:new URLSearchParams(window.location.search).get(`surface`)===`desktop`,T=e=>{if(typeof navigator>`u`)return{isExplicitTablet:!1};let t=navigator.userAgent||``,n=navigator.platform||``,r=/iPad/i.test(t)||(/Macintosh|MacIntel/i.test(t)||/MacIntel/i.test(n))&&e>1,i=/Android/i.test(t)&&!/Mobile/i.test(t),a=/Tablet/i.test(t);return{isExplicitTablet:r||i||a}},E=(e,t,n)=>{if(typeof window>`u`)return;let r=document.documentElement,i=t===`mobile`,a=t===`tablet`;r.classList.remove(`device-mobile`,`device-tablet`,`device-desktop`),r.classList.add(t===`mobile`?`device-mobile`:t===`tablet`?`device-tablet`:`device-desktop`),e?(r.classList.add(`desktop-runtime`),r.style.setProperty(`--is-mobile`,`0`),r.style.setProperty(`--device-type`,`desktop`),r.style.setProperty(`--font-scale`,`1`),r.style.setProperty(`--has-coarse-pointer`,`0`),r.style.setProperty(`--has-touch-input`,`0`),r.classList.remove(`mobile-pointer`)):(r.classList.remove(`desktop-runtime`),r.style.setProperty(`--is-mobile`,i?`1`:`0`),r.style.setProperty(`--device-type`,t),r.style.setProperty(`--font-scale`,i?`0.9`:a?`0.95`:`1`),r.style.setProperty(`--has-coarse-pointer`,n?`1`:`0`),r.style.setProperty(`--has-touch-input`,n?`1`:`0`),n?r.classList.add(`mobile-pointer`):r.classList.remove(`mobile-pointer`)),b(e?1:v(),r)};function D(){let e=window.innerWidth,r=typeof window.matchMedia==`function`,i=r?window.matchMedia(`(pointer: coarse)`):null,a=r?window.matchMedia(`(hover: none)`):null,s=i?.matches??!1,c=a?.matches??!1,l=typeof navigator<`u`?navigator.maxTouchPoints??0:0,u=n()||t()||w(),{isExplicitTablet:d}=T(l),f=s||c||l>0,p=s||c,m=e>S.md&&e<=S.lg,h=e<=S.md,g=f&&h,_=f&&!g&&(m||d),v=!f||!_&&e>S.lg,y=`desktop`;u?(g=!1,_=!1,v=!0,y=`desktop`):o()?(g=!0,_=!1,v=!1,y=`mobile`):g?y=`mobile`:_?y=`tablet`:(v=!0,y=`desktop`),E(u,y,f);let b=`xs`;for(let[t,n]of Object.entries(S))e>=n&&(b=t);return{isMobile:g,isTablet:_,isDesktop:v,deviceType:y,screenWidth:e,breakpoint:b,hasTouchInput:f,hasTouchOnlyPointer:p}}var O=(e,t)=>e.isMobile===t.isMobile&&e.isTablet===t.isTablet&&e.isDesktop===t.isDesktop&&e.deviceType===t.deviceType&&e.screenWidth===t.screenWidth&&e.breakpoint===t.breakpoint&&e.hasTouchInput===t.hasTouchInput&&e.hasTouchOnlyPointer===t.hasTouchOnlyPointer,k=new Set,A=null,j,M=null,N=()=>typeof window>`u`?C:(A||=D(),A),P=()=>{for(let e of k)e()},F=()=>{j=void 0;let e=D();A&&O(A,e)||(A=e,P())},I=()=>{typeof window>`u`||j!==void 0||(j=window.requestAnimationFrame(F))},L=(e,t)=>e?typeof e.addEventListener==`function`?(e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)):typeof e.addListener==`function`?(e.addListener(t),()=>e.removeListener(t)):()=>{}:()=>{},R=()=>{if(typeof window>`u`)return()=>{};A=D(),window.addEventListener(`resize`,I);let e=typeof window.matchMedia==`function`?window.matchMedia(`(pointer: coarse)`):null,t=typeof window.matchMedia==`function`?window.matchMedia(`(hover: none)`):null,n=L(e,I),r=L(t,I);return()=>{window.removeEventListener(`resize`,I),n(),r(),j!==void 0&&(window.cancelAnimationFrame(j),j=void 0)}},z=e=>typeof window>`u`?()=>{}:(k.add(e),M||=R(),()=>{k.delete(e),k.size===0&&M&&(M(),M=null,A=null)});function B(){if(typeof window>`u`||typeof window<`u`&&n())return!1;let e=document.documentElement,t=e.style.getPropertyValue(`--is-mobile`)||getComputedStyle(e).getPropertyValue(`--is-mobile`);return t===`1`||t===`true`}var V=()=>typeof window>`u`?!1:!!(navigator.standalone===!0||window.matchMedia?.(`(display-mode: standalone)`)?.matches||window.matchMedia?.(`(display-mode: fullscreen)`)?.matches),H=()=>{if(typeof window>`u`||n())return!1;let e=typeof navigator<`u`?navigator.maxTouchPoints??0:0;return V()&&e>0&&window.innerWidth>S.md};function U(){let e=(0,c.c)(2),[t,n]=s.useState(W),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{if(typeof window>`u`)return;let e=()=>n(H()),t=window.matchMedia?.(`(display-mode: standalone)`),r=window.matchMedia?.(`(display-mode: fullscreen)`);e(),window.addEventListener(`resize`,e),window.addEventListener(`focus`,e);let i=t=>{t&&(typeof t.addEventListener==`function`?t.addEventListener(`change`,e):typeof t.addListener==`function`&&t.addListener(e))},a=t=>{t&&(typeof t.removeEventListener==`function`?t.removeEventListener(`change`,e):typeof t.removeListener==`function`&&t.removeListener(e))};return i(t),i(r),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`focus`,e),a(t),a(r)}},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),s.useEffect(r,i),t}function W(){return H()}var G=()=>typeof window>`u`?`portrait`:window.matchMedia?.(`(orientation: landscape)`)?.matches?`landscape`:`portrait`;function K(){let e=(0,c.c)(2),[t,n]=s.useState(G),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(orientation: landscape)`),t=()=>n(e.matches?`landscape`:`portrait`);return t(),L(e,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),s.useEffect(r,i),t}function q(){return s.useSyncExternalStore(z,N,J)}function J(){return C}export{U as a,K as i,B as n,x as o,q as r,D as t};
@@ -1 +0,0 @@
1
- import{A as e,C as t,E as n,F as r,L as i,M as a,P as o,S as s,T as c,_ as l,a as u,b as d,g as f,h as p,i as m,k as h,n as g,o as _,r as v,t as y,v as ee,x as b}from"./vendor-opencode-client-ZeOZ4Efz.js";import{i as te}from"./vendor-tanstack-query-core-BWz0ose6.js";import{n as ne,r as re}from"./fileQueries-BeXkd3o6.js";import{o as ie}from"./path-utils-jGozTg9d.js";import{a as ae,n as oe}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as se}from"./pathNormalization-ewtPqJWn.js";import{n as ce}from"./platform-DFJEtBlo.js";import{t as x}from"./native-errors-06if6eu-.js";import{i as le,o as ue}from"./fileReferenceParser-1HHDBUum.js";import{n as de,t as fe}from"./vendor-solid-js-9wmPZH9g.js";import{a as pe,c as me,d as he,f as ge,g as S,h as C,i as _e,l as w,m as ve,n as ye,o as T,p as E,r as be,s as D,t as O,u as k}from"./vendor-opencode-plugin-BBOP6WNx.js";import{Et as A,mt as j,pt as M,y as N}from"./vendor-effect-DV9F8PTZ.js";var P={"@opencode/plugin/gui":T,"@opencode/plugin/gui/main":T,"@opencode/plugin/gui/file":pe,"@opencode/plugin/gui/review":_e,"@opencode/plugin/gui/browser":be,"@opencode/plugin/rpc":O,"@opencode/schema/rpc":ye,"@opencode/client":i,"@opencode/client/effect":g,"@opencode/client/solid":y,effect:N,"solid-js":a,"solid-js/web":de,"solid-js/store":u},xe=new Set(`assert assert/strict async_hooks buffer child_process cluster console constants crypto dgram diagnostics_channel dns dns/promises domain events fs fs/promises http http2 https inspector inspector/promises module net os path path/posix path/win32 perf_hooks process punycode querystring readline readline/promises repl stream stream/consumers stream/promises stream/web string_decoder sys timers timers/promises tls trace_events tty url util util/types v8 vm wasi worker_threads zlib`.split(` `));function Se(){let e=new Proxy(function(){},{get:(t,n)=>n===`then`?void 0:n===Symbol.hasInstance?()=>!1:n===Symbol.toPrimitive||n===`toString`?()=>`[main-only module]`:e,apply:()=>e,construct:()=>e,set:()=>!0});return e}function Ce(e,t){if(e.length>16777216)throw Error(`GUI bundle exceeds 16 MiB`);let n={exports:{}};Function(`require`,`module`,`exports`,e)(e=>{if(Object.hasOwn(P,e))return P[e];if(e===`electron`||e.startsWith(`node:`)||xe.has(e))return Se();throw Error(`Unsupported GUI shared module: ${e}`)},n,n.exports);let r=n.exports,i=r&&typeof r==`object`&&`default`in r?r.default:r;if(!i||typeof i!=`object`)throw Error(`GUI bundle must default-export Plugin.define`);if((!(`setup`in i)||typeof i.setup!=`function`)&&!(t&&`main`in i&&typeof i.main==`function`))throw new x(`GUI_PLUGIN_UNSUPPORTED`,`This host requires a window setup; main-only plugins are unsupported`);if(`os`in i&&i.os!==void 0){if(!t)throw new x(`GUI_PLUGIN_UNSUPPORTED`,`OS-restricted plugins require the native GUI host`);if(!Array.isArray(i.os)||!i.os.includes(t))throw new x(`GUI_PLUGIN_UNSUPPORTED`,`GUI plugin is unavailable on this OS`)}if(`main`in i&&i.main!==void 0&&typeof i.main!=`function`)throw Error(`Invalid GUI main entry`);if(`stores`in i&&i.stores!==void 0){if(!i.stores||typeof i.stores!=`object`||Array.isArray(i.stores))throw Error(`Invalid GUI stores`);for(let e of Object.values(i.stores))if(!e||typeof e!=`object`||!(`schema`in e)||!A(e.schema)||!(`scope`in e)||![`global`,`session`].includes(String(e.scope))||!(`initial`in e))throw Error(`Invalid GUI store declaration`)}if(`i18n`in i&&i.i18n!==void 0){if(!i.i18n||typeof i.i18n!=`object`||Array.isArray(i.i18n))throw Error(`Invalid GUI locale catalog`);for(let e of Object.values(i.i18n))if(!e||typeof e!=`object`||Array.isArray(e)||Object.values(e).some(e=>typeof e!=`string`))throw Error(`GUI locales must be inline string dictionaries`)}return i}function F(e){let t=e;if(/^file:/i.test(t)){let e=new URL(t);t=`${e.hostname&&e.hostname!==`localhost`?`//${e.hostname}`:``}${decodeURIComponent(e.pathname)}`,/^\/[a-z]:\//i.test(t)&&(t=t.slice(1))}let n=se(t)??``;return n===`.`?``:n}var I=e=>/^(?:\/|[a-z]:\/)/i.test(e),L=()=>{throw Error(`Unsupported GUI file API: tree`)},R=class extends Error{},z=e=>new TextEncoder().encode(e).byteLength,we=class{files;query;transport;root;api;ended=!1;states=new Map;inflight=new Map;watches=new Map;apiLeases=new Map;registeredOwners=new WeakSet;endedOwners=new WeakSet;leaseCount=0;rerun=new Set;selections=new Map;scrolls=new Map;subscriptions=new Map;constructor(e,t,r,i){this.files=e,this.query=t,this.transport=r,this.root=i,this.root=F(i),this.api={root:this.root,ready:()=>!this.ended,resolve:e=>this.resolve(e),absolute:I,get:e=>{let t=this.track(e,`file`);return this.states.get(t)},missing:e=>{let t=this.track(e,`missing`);return this.states.get(t)?.notFound===!0},sync:(e,t)=>{let r=n();return this.ended||r&&this.endedOwners.has(r)?Promise.resolve():(this.acquireApiLease(e),this.sync(e,t?.force))},unwatch:e=>this.releaseApiLease(n(),this.resolve(e)),exists:async e=>{try{if(this.files.statFile)return(await this.query.fetchQuery(this.statOptions(e))).isFile;let t=this.full(e);return(await this.files.listDirectory(t.slice(0,t.lastIndexOf(`/`)))).entries.some(e=>!e.isDirectory&&F(e.path)===t)}catch{return!1}},search:async(e,t)=>{if(t?.kind===`any`)throw Error(`Unsupported GUI file search: directories`);t?.signal?.throwIfAborted();let n=await this.query.fetchQuery({queryKey:[`gui-plugin-files`,r,this.root,`search`,e,t?.limit],gcTime:3e4,queryFn:async({signal:n})=>(n.throwIfAborted(),this.files.search({directory:this.root,query:e,maxResults:t?.limit??100}))});if(t?.signal?.throwIfAborted(),this.ended)throw new DOMException(`GUI file model was disposed`,`AbortError`);return n.map(e=>this.resolve(e.path))},selection:{get:e=>this.selections.get(this.track(e,`selection`)),set:(e,t)=>{let n=this.resolve(e),r=this.selections.get(n);r===t||r&&t&&r.start===t.start&&r.end===t.end&&r.side===t.side&&r.endSide===t.endSide||(this.selections.set(n,t),this.trim(this.selections,`selection`),this.changed(n,`selection`))}},scroll:{get:e=>this.scrolls.get(this.track(e,`scroll`))??{},set:(e,t)=>{let n=this.resolve(e),r=this.scrolls.get(n),i={...r,...t};(r?.top!==i.top||r?.left!==i.left)&&(this.scrolls.set(n,i),this.trim(this.scrolls,`scroll`),this.changed(n,`scroll`))}},tree:{list:L,state:L,sync:L,expand:L,collapse:L}}}resolve(e){let t=F(e);if(!I(t))return t;if(t===this.root)return``;let n=this.root.endsWith(`/`)?this.root:`${this.root}/`;return t.startsWith(n)?t.slice(n.length):t}full(e){let t=this.resolve(e);return I(t)?t:F(`${this.root}/${t}`)}input(e){return{scopeDirectory:this.root,path:this.full(e),options:{directory:this.root}}}statOptions(e){return{...re(this.files,this.input(e),this.transport),gcTime:3e4}}track(n,r){let i=this.resolve(n),a=c();if(!a||this.ended)return i;let o=`${r}:${i}`,s=this.subscriptions.get(o);s||(s={revision:t(0),listeners:new Set},this.subscriptions.set(o,s));let l=s;return l.listeners.has(a)||(l.listeners.add(a),e(a,()=>h(()=>{l.listeners.delete(a),!l.listeners.size&&this.subscriptions.get(o)===l&&this.subscriptions.delete(o)}))),l.revision[0](),i}changed(e,t){this.ended||this.subscriptions.get(`${t}:${e}`)?.revision[1](e=>e+1)}trim(e,t){for(;e.size>64;){let n=e.keys().next().value;e.delete(n),this.changed(n,t)}}setState(e,t){let n=this.states.get(e);n?.content?.content===t.content?.content&&n?.content?.type===t.content?.type&&(t.content=n?.content),!(n&&n.loaded===t.loaded&&n.loading===t.loading&&n.error===t.error&&n.notFound===t.notFound&&n.content===t.content)&&(this.states.set(e,t),p(()=>{this.changed(e,`file`),n?.notFound===!0!=(t.notFound===!0)&&this.changed(e,`missing`)}))}acquireApiLease(e){let t=n();if(this.ended||t&&this.endedOwners.has(t)||!this.files.statFile)return;let r=this.resolve(e),i=this.apiLeases.get(t);if(i?.has(r))return;if(this.leaseCount>=256)throw Error(`GUI file consumer limit exceeded`);let a=this.watch(r);i||(i=new Map,this.apiLeases.set(t,i)),i.set(r,a),this.leaseCount++,t&&!this.registeredOwners.has(t)&&(this.registeredOwners.add(t),h(()=>{`fn`in t||this.endedOwners.add(t),this.registeredOwners.delete(t);for(let e of[...this.apiLeases.get(t)?.keys()??[]])this.releaseApiLease(t,e)}))}releaseApiLease(e,t){let n=this.apiLeases.get(e),r=n?.get(t);r&&(n.delete(t),this.leaseCount--,n.size||this.apiLeases.delete(e),r())}reserve(e){if(!this.states.has(e)){if(this.states.size>=64){let e=[...this.states.keys()].find(e=>!this.watches.has(e)&&!this.inflight.has(e));if(!e)throw Error(`GUI file cache limit exceeded`);let t=this.states.get(e)?.notFound===!0;this.states.delete(e),p(()=>{this.changed(e,`file`),t&&this.changed(e,`missing`)})}this.states.set(e,{path:e,name:e.split(`/`).at(-1)??e})}}async sync(e,t=!1){if(this.ended)return;let n=this.resolve(e);if(this.inflight.has(n))return t&&this.rerun.add(n),this.inflight.get(n);if(!t&&this.states.get(n)?.loaded&&!this.states.get(n)?.error)return;this.reserve(n);let r=this.states.get(n);this.setState(n,{...r,path:n,name:n.split(`/`).at(-1)??n,loading:!r?.loaded&&!this.watches.get(n)?.failed});let i=(async()=>{try{do{this.rerun.delete(n);let e=this.watches.get(n),r=e?.epoch;try{let i=ne(this.files,this.input(n),this.transport),a=await this.query.fetchQuery({...i,gcTime:3e4,staleTime:t?0:3e4,queryFn:async()=>{if(!this.files.readFile)throw Error(`File content reads are unavailable in this runtime`);let e=await this.files.readFile(this.full(n),{directory:this.root});if(e.exists===!1)throw new R(`File does not exist`);let t=e.content;if(z(t)>131072)throw Error(`GUI file preview exceeds 128 KiB`);return t}});if(this.ended)return;if(z(a)>131072)throw Error(`GUI file preview exceeds 128 KiB`);(!e||e.epoch===r&&!e.failed)&&this.setState(n,{path:n,name:n.split(`/`).at(-1)??n,loaded:!0,loading:!1,content:{type:`text`,content:a}})}catch(t){if(this.ended)return;if((!e||e.epoch===r&&!e.failed)&&this.setState(n,{...this.states.get(n),loading:!1,...t instanceof R?{notFound:!0}:{},error:String(t)}),!this.rerun.has(n))throw t}t=!0}while(!this.ended&&this.rerun.has(n))}finally{this.inflight.delete(n),this.rerun.delete(n)}})();return this.inflight.set(n,i),i}watch(e){if(this.ended||!this.files.statFile)return()=>{};let t=this.resolve(e),n=this.watches.get(t);if(!n){if(this.watches.size>=64)throw Error(`GUI file watch limit exceeded`);this.reserve(t),n={count:0,epoch:0,failed:!1,stop:()=>{}};let e=n;this.watches.set(t,e);let r,i=new te(this.query,{...this.statOptions(t),refetchInterval:2e3,refetchIntervalInBackground:!1}),a=i.subscribe(n=>{if(this.ended||this.watches.get(t)!==e||n.isFetching)return;if(n.isError||n.isSuccess&&!n.data.isFile){e.failed=!0,e.epoch++,this.setState(t,{...this.states.get(t),loading:!1,notFound:n.isSuccess?!0:this.states.get(t)?.notFound,error:n.isError?String(n.error):`File does not exist`});return}if(!n.data||!n.isSuccess)return;let i=`${n.data.size}:${n.data.mtimeMs??``}`,a=e.failed||r!==void 0&&i!==r;e.failed=!1,r=i,a&&(e.epoch++,this.sync(t,!0).catch(()=>{}))});e.stop=()=>{a(),i.destroy()},this.states.get(t)?.loaded&&this.sync(t,!0).catch(()=>{})}n.count++;let r=!0;return()=>{r&&(r=!1,--n.count===0&&this.watches.get(t)===n&&this.stopWatch(t))}}stopWatch(e){this.watches.get(e)?.stop(),this.watches.delete(e)}dispose(){this.ended=!0;for(let e of this.watches.values())e.stop();this.watches.clear(),this.apiLeases.clear(),this.leaseCount=0,this.rerun.clear(),this.states.clear(),this.inflight.clear(),this.selections.clear(),this.scrolls.clear(),this.subscriptions.clear()}},B=256,V=2097152,H=e=>structuredClone(_(e)),Te=class{backend;transport;memory=new Map;resets=new Map;constructor(e,t){this.backend=e,this.transport=t}forPlugin(e,n){let r=(t,n=`global`)=>{if(typeof n==`object`&&`session`in n&&!n.session.location)throw Error(`Unsupported GUI storage: session location is unknown`);let r=n===`global`?n:`session`in n?[n.session.server.id,n.session.id,n.session.location]:[n.server,n.directory];return`yuri.gui-plugin.${JSON.stringify([this.transport,e,r,t])}`},i=e=>{if(n.aborted)throw Error(`GUI plugin has been disposed`);if(e!==void 0)throw Error(`Unsupported GUI storage migration: from`)},a=new Map;return{store:(e,o)=>{i(o.from);let s=r(e,o.scope),c=a.get(s);if(c)return c;if(a.size>=B)throw Error(`GUI plugin store limit exceeded`);let l=M(o.schema),u=j(o.schema),d=l(u(H(o.initial)));if(JSON.stringify(u(d)).length>V)throw Error(`GUI plugin store exceeds 2 MiB`);let f=d,p=this.backend.getItem(s);if(p!==null&&p.length<=V)try{f=l(JSON.parse(p))}catch{f=d}let[m,h]=t(f),g=e=>{i();let t=JSON.stringify(u(H(e)));if(t.length>V)throw Error(`GUI plugin store exceeds 2 MiB`);let n=l(JSON.parse(t));this.backend.setItem(s,t),h(()=>n)},_={get value(){return m()},ready:()=>!0,set:g,update:e=>{let t=H(m());if(e(t)!==void 0)throw Error(`Store update must not return a replacement`);g(t)}},v=()=>h(()=>H(d)),y=this.resets.get(s)??new Set;return y.add(v),this.resets.set(s,y),n.addEventListener(`abort`,()=>{y.delete(v),y.size||this.resets.delete(s),a.clear()},{once:!0}),a.set(s,_),_},memory:(e,t)=>{i();let n=r(e),a=this.memory.get(n);if(a)return[a[0],e=>{i(),a[1](e)}];if(this.memory.size>=B)throw Error(`GUI plugin memory store limit exceeded`);if(JSON.stringify(t.initial).length>V)throw Error(`GUI plugin memory exceeds 2 MiB`);let[o,s]=v(H(t.initial)),c=[o,e=>{i();let t=H(_(o));if(e(t)!==void 0)throw Error(`Memory update must not return a replacement`);if(JSON.stringify(t).length>V)throw Error(`GUI plugin memory exceeds 2 MiB`);s(m(t))}];return this.memory.set(n,[o,e=>{let t=H(_(o));if(e(t)!==void 0)throw Error(`Memory update must not return a replacement`);if(JSON.stringify(t).length>V)throw Error(`GUI plugin memory exceeds 2 MiB`);s(m(t))}]),c},remove:(e,t)=>{i(t?.from);let n=r(e,t?.scope);this.backend.removeItem(n);for(let e of this.resets.get(n)??[])e()}}}dispose(){this.memory.clear(),this.resets.clear()}},Ee=`yuri.file-icon`,U=`http://www.w3.org/2000/svg`,De=new Set([`svg`,`g`,`path`,`rect`,`circle`,`ellipse`,`line`,`polyline`,`polygon`,`defs`,`linearGradient`,`radialGradient`,`stop`,`clipPath`,`mask`,`use`,`title`,`desc`]),W=e=>e.trim().replace(/^\./,``).toLowerCase();function G(e,t){if(typeof e!=`string`)throw Error(`GUI file icon requires SVG text`);let n=t.get(e);if(n)return n;if(e.length>16384)throw Error(`GUI file icon SVG exceeds 16 KiB`);let r=new TextEncoder().encode(e).byteLength;if(r>16384)throw Error(`GUI file icon SVG exceeds 16 KiB`);if(!/^\s*<svg[\s>]/.test(e)||/<!|<\?/.test(e))throw Error(`Invalid GUI file icon SVG`);let i=new DOMParser().parseFromString(e,`image/svg+xml`),a=i.documentElement;if(a?.localName!==`svg`||a.namespaceURI!==U||i.querySelector(`parsererror`))throw Error(`Invalid GUI file icon SVG`);for(let e of[a,...a.querySelectorAll(`*`)]){if(e.namespaceURI!==U||!De.has(e.localName))throw Error(`Unsupported GUI file icon SVG element`);for(let t of e.attributes){let e=t.name.toLowerCase(),n=t.value.trim();if(e.startsWith(`on`)||e===`style`||e===`xml:base`||n.includes(`\\`)||Array.from(n).some(e=>e.charCodeAt(0)<32)||(e===`href`||e.endsWith(`:href`))&&!/^#[\w.-]+$/.test(n)||/url\s*\(/i.test(n)&&!/^url\(\s*#[\w.-]+\s*\)$/.test(n))throw Error(`Unsupported GUI file icon SVG reference or attribute`)}}let o={source:e,bytes:r,uri:`data:image/svg+xml,${encodeURIComponent(e)}`};return t.set(e,o),o}var Oe=class{plugins=new Map;index=new Map;listeners=new Set;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});get(e,t){if(t?.isDirectory)return;let n=e.split(/[\\/]/).at(-1)??``,r=t?.extension??(n.includes(`.`)?n.slice(n.lastIndexOf(`.`)+1):``),i=this.index.get(W(r));return t?.themeVariant===`light`?i?.light.uri:i?.dark.uri}replace(e,t){if(t.length>64)throw Error(`GUI file icon per-plugin limit exceeded`);if(!t.length){this.remove(e);return}let n=new Map;for(let t of this.plugins.get(e)??[])for(let e of[t.dark,t.light])n.set(e.source,e);let r=new Set,i=t.map(e=>{if(!e||typeof e!=`object`||!(`id`in e)||typeof e.id!=`string`||!e.id.trim()||e.id.length>128||r.has(e.id))throw Error(`Invalid or duplicate GUI file icon id`);if(r.add(e.id),!(`extensions`in e)||!Array.isArray(e.extensions)||!e.extensions.length||e.extensions.length>64)throw Error(`GUI file icon requires 1–64 extensions`);let t=e.extensions.map(e=>{if(typeof e!=`string`)throw Error(`Invalid GUI file icon extension`);let t=W(e);if(!/^[a-z0-9][a-z0-9_+-]{0,63}$/.test(t))throw Error(`Invalid GUI file icon extension`);return t}),i=G(`svg`in e?e.svg:void 0,n),a=`lightSvg`in e&&e.lightSvg!==void 0?G(e.lightSvg,n):i;return{id:e.id,extensions:[...new Set(t)],dark:i,light:a}}),a=i.length,o=i.reduce((e,t)=>e+t.dark.bytes+t.light.bytes,0);for(let[t,n]of this.plugins)t!==e&&(a+=n.length,o+=n.reduce((e,t)=>e+t.dark.bytes+t.light.bytes,0));if(a>512||o>8388608)throw Error(`GUI file icon total limit exceeded`);this.plugins.set(e,i),this.publish()}remove(e){this.plugins.delete(e)&&this.publish()}dispose(){this.plugins.clear(),this.publish(),this.listeners.clear()}publish(){let e=new Map;for(let t of this.plugins.values())for(let n of t)for(let t of n.extensions)e.set(t,n);let t=e.size!==this.index.size||[...e].some(([e,t])=>{let n=this.index.get(e);return n?.dark.uri!==t.dark.uri||n?.light.uri!==t.light.uri});if(this.index=e,t)for(let e of this.listeners)e()}},K=e=>e===`yuri.exportPDF`||e===`yuri.exportLongImage`,ke=class{api;probe;clients=new Map;ended=!1;constructor(e){this.api=e}use(e,n){let r=this.clients.get(n),i=r?.get(e);if(i)return i.live;let[a,o]=t(this.api&&!n.aborted&&!this.ended?{status:`pending`}:{status:`inactive`,reason:`disabled`}),s=()=>{o({status:`inactive`,reason:`disabled`}),n.removeEventListener(`abort`,s),this.clients.delete(n)},c={live:S(a),stop:s};if(this.ended||n.aborted||(r||(r=new Map,this.clients.set(n,r)),r.set(e,c),n.addEventListener(`abort`,s,{once:!0}),!this.api))return c.live;let l=this.api;return this.probe??=Promise.resolve().then(()=>l.capabilities()),this.probe.then(t=>{if(this.ended||n.aborted)return;let r=e===`yuri.exportPDF`?`exportPDF`:`exportLongImage`;if(t.version!==1||!t[r]){o({status:`inactive`,reason:`disabled`});return}let i=async(e,t={})=>{if(this.ended||n.aborted||a().status!==`active`)return{status:`cancelled`};let i=AbortSignal.any([n,...t.signal?[t.signal]:[]]);try{return await l[r](e,{...t,signal:i})}catch(e){throw e&&typeof e==`object`&&`code`in e&&e.code===`EXPORT_UNSUPPORTED`&&o({status:`inactive`,reason:`failed`}),e}},s=Object.freeze(e===`yuri.exportPDF`?{version:1,limits:t.limits,exportPDF:i}:{version:1,limits:t.limits,exportLongImage:i});o({status:`active`,generation:1,value:s})}).catch(()=>{!this.ended&&!n.aborted&&o({status:`inactive`,reason:`failed`})}),c.live}dispose(){this.ended=!0;for(let e of this.clients.values())for(let t of e.values())t.stop();this.clients.clear()}};function Ae(e,t){let n=new Map,r=Object.freeze({dismiss(){}});return e.addEventListener(`abort`,()=>{for(let e of[...n.values()])e.handle.dismiss()},{once:!0}),Object.freeze({show(i){if(e.aborted)return r;if(!t)throw new x(`GUI_PLUGIN_UNSUPPORTED`,`GUI toast is unavailable`);if(!i||typeof i!=`object`)throw new x(`GUI_PLUGIN_INVALID_INPUT`,`Expected toast options`);let{title:a,description:o,variant:s=`default`,duration:c=5e3,persistent:l=!1,icon:u,actions:d}=i;if(typeof a!=`string`||o!==void 0&&typeof o!=`string`||![`default`,`success`,`error`,`loading`].includes(s)||typeof l!=`boolean`||typeof c!=`number`||!Number.isFinite(c)||c<0)throw new x(`GUI_PLUGIN_INVALID_INPUT`,`Invalid toast options`);if(u!==void 0||d!==void 0)throw new x(`GUI_PLUGIN_UNSUPPORTED`,`GUI toast icon/actions are unsupported`);if(e.aborted)return r;let f=JSON.stringify([a,o??null,s,c,l]),p=n.get(f),m=()=>{let e=n.get(f);!e||e.id!==h||(clearTimeout(e.timer),n.delete(f))},h=(s==="default"?t:t[s])(a,{id:p?.id,description:o,duration:l?1/0:c,onDismiss:m,onAutoClose:m}),g=p?.handle??Object.freeze({dismiss(){m(),t.dismiss(h)}});clearTimeout(p?.timer);let _=s===`loading`&&!l?setTimeout(()=>g.dismiss(),c):void 0;return n.set(f,{id:h,handle:g,timer:_}),g}})}var je=ae(`YuriMedia`);async function Me(e){let t=/\.html?$/i.test(e.name)?`text/html`:`text/plain`,n=new Blob([e.content],{type:t});if(ce()){if(!oe.isPluginAvailable(`YuriMedia`))throw new x(`GUI_PLUGIN_UNSUPPORTED`,`Native file saving is unavailable`);if(n.size>33554432)throw new x(`GUI_PLUGIN_INVALID_INPUT`,`File exceeds maximum size`);let r=await new Promise((e,t)=>{let r=new FileReader;r.onload=()=>{if(typeof r.result!=`string`){t(Error(`Failed to encode file`));return}e(r.result.slice(r.result.indexOf(`,`)+1))},r.onerror=()=>t(r.error??Error(`Failed to encode file`)),r.readAsDataURL(n)});return!(await je.saveFile({dataBase64:r,mimeType:t,filename:e.name})).cancelled}let r=URL.createObjectURL(n),i=document.createElement(`a`);try{return i.href=r,i.download=e.name,document.body.append(i),i.click(),!0}finally{i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}}var q=ee();function J(e){return{version:1,register(t){let n=r(q);if(!n||n.plugin!==e||n.signal.aborted||e.aborted)throw Error(`Preview actions require the owning mounted panel`);let i=new AbortController,a=AbortSignal.any([e,n.signal,i.signal]),o,s=()=>{a.removeEventListener(`abort`,s),i.abort(),o?.remove()};h(s),a.addEventListener(`abort`,s,{once:!0});try{o=t.render({element:t.element,signal:a,async snapshot(e={}){let r=AbortSignal.any([a,...e.signal?[e.signal]:[]]);if(r.throwIfAborted(),!n.content.contains(t.element)||n.target.contains(t.element))throw Error(`Preview capture region is no longer in its owning panel`);let i=await t.capture({...e,signal:r});if(r.throwIfAborted(),!n.content.contains(t.element))throw Error(`Preview capture region was replaced`);return i}}),a.throwIfAborted(),n.target.append(o)}catch(e){throw s(),e}return s}}}function Y(e,t){return JSON.stringify([e,t])}function Ne(e){if(!e||typeof e!=`object`||!(`id`in e)||typeof e.id!=`string`||!e.id.trim()||e.id.length>128||!(`title`in e)||typeof e.title!=`string`||!(`render`in e)||typeof e.render!=`function`)throw Error(`Invalid yuri.page contribution`);return e}var X=e=>{throw new x(`GUI_PLUGIN_UNSUPPORTED`,`Unsupported GUI host API: ${e}`)};function Z(e,t){return new Proxy(t,{get:(t,n)=>n in t?Reflect.get(t,n):X(`${e}.${String(n)}`)})}var Q=e=>Object.freeze(e.map(e=>Object.freeze(e)));function Pe(e,t){if(!e.fields||!t.fields)return!1;let n=Reflect.ownKeys(e.fields);return n.length===Reflect.ownKeys(t.fields).length&&n.every(n=>{let r=e.fields[n],i=t.fields[n];return i!==void 0&&`value`in r&&`value`in i&&Object.is(r.value,i.value)&&r.enumerable===i.enumerable&&r.configurable===i.configurable&&r.writable===i.writable})}function $(e,t){if(e){for(let n of e.owned??[])$(n,t);e.cleanups&&=e.cleanups.map(e=>()=>{try{Promise.resolve(e()).catch(t)}catch(e){t(e)}})}}var Fe=class{options;fileIcons=new Oe;instances=new Map;listeners=new Set;panelMounts=new Set;fileViews=new Map;changes=t(0);views=t(0);session=t();currentPage=t();appearance;layouts=new Map;files;storage;ended=!1;contracts=new Map;snapshot=Object.freeze({plugins:Object.freeze([]),commands:Object.freeze([]),titlebarItems:Object.freeze([]),panels:Object.freeze([]),pages:Object.freeze([]),settings:Object.freeze([]),menuItems:Object.freeze([]),activePanel:null});screen;viewExports;constructor(e){this.options=e,this.viewExports=new ke(e.viewExport),this.appearance=t({locale:e.locale,mode:e.mode,narrow:e.narrow}),this.storage=new Te(e.storage,e.transport);let n=()=>(this.session[0](),this.files?.api??X(`screen.file without a session`));this.screen=Z(`screen`,{get file(){return n()}})}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.snapshot;changed(e=!1){let t=this.snapshot;this.changes[1](e=>e+1),e&&t===this.snapshot&&this.publish()}setSession(e){if(this.ended)return;let t=this.session[0]();if(t?.id===e?.id&&t?.directory===e?.directory)return;if(!e)for(let e of[...this.panelMounts])e();this.files?.dispose(),this.files=e?new we(this.options.files,this.options.queryClient,this.options.transport,e.directory):void 0;let n=Z(`session.server`,{id:this.options.transport,name:this.options.transport,client:this.options.client}),r=e?Object.freeze(Z(`session`,{id:e.id,directory:e.directory,key:`${this.options.transport}\n${e.id}`,tab:e.id,server:n,pending:!1,visit:{},location:{directory:e.directory}})):void 0,i=this.snapshot;this.session[1](r),i===this.snapshot&&this.publish()}setAppearance(e){if(this.ended)return;let t=this.appearance[0]();(t.locale!==e.locale||t.mode!==e.mode||t.narrow!==e.narrow)&&this.appearance[1]({...e})}setPage(e){this.ended||this.currentPage[1](e)}install(r,i,a){let c=this.instances.get(r);if(this.ended||c?.status===`active`&&c.revision===i.revision&&c.native?.active!==!1){a?.dispose();return}c&&(this.instances.delete(r),this.release(c));let u={id:r,native:a,revision:i.revision,controller:new AbortController,status:`active`,cleanups:new Set,contributions:new Set,iconChanges:t(0),commands:[],titlebarItems:[],panels:[],pages:[],settings:[],menus:[]};this.instances.set(r,u);try{if(r===`yuri`||r.startsWith(`yuri.`))throw Error(`The yuri namespace is reserved to the host`);let t=Ce(i.code,a?.activation.os);s(r=>{u.dispose=r,u.root=n(),f(()=>l(C.Provider,{value:u.context=this.context(u,t,i.options),get children(){u.owner=n();let e=o(()=>t.setup?.(u.context));if(typeof e==`function`)u.cleanups.add(()=>{Promise.resolve(e()).catch(e=>{u.error=String(e)})});else if(e!==void 0)throw e&&typeof e==`object`&&`then`in e&&Promise.resolve(e).catch(()=>{}),Error(`GUI setup must be synchronous and return only cleanup`);return null}}),e=>this.fail(u,e)),u.controller.signal.aborted||e(u.owner,()=>b(()=>{if(u.iconChanges[0](),!u.controller.signal.aborted)try{let e=[...u.contributions].filter(e=>e.registry===Ee).map(e=>e.read()).filter(e=>e!==void 0);this.fileIcons.replace(u.id,e),u.iconError!==void 0&&o(()=>{u.iconError=void 0,this.publish()})}catch(e){o(()=>{this.fileIcons.remove(u.id),u.iconError=e instanceof Error?e.message:String(e),this.publish()})}})),u.controller.signal.aborted||e(u.owner,()=>b(()=>{this.changes[0](),this.session[0](),this.appearance[0]();try{this.derive(u)}catch(e){o(()=>this.fail(u,e))}o(()=>this.publish())}))})}catch(e){this.fail(u,e)}this.changed(!0)}release(e){e.controller.abort(),e.native?.dispose();for(let t of[...e.cleanups])try{t()}catch(t){e.error??=String(t)}e.cleanups.clear(),$(e.root,t=>{e.error??=String(t)});try{e.dispose?.()}catch(t){e.error??=String(t)}e.contributions.clear(),e.commands=[],e.titlebarItems=[],e.panels=[],e.pages=[],e.settings=[],e.menus=[],this.fileIcons.remove(e.id);for(let t of this.contracts.values())t.provider===e&&(t.provider=void 0,t.live[1]({status:`inactive`,reason:e.status===`failed`?`failed`:`disabled`}))}fail(e,t){e.status!==`failed`&&this.instances.get(e.id)===e&&(e.status=`failed`,e.error=t instanceof Error?t.message:String(t),t instanceof x&&(e.errorCode=t.code),this.release(e),this.publish())}uninstall(e){let t=this.instances.get(e);if(t){this.instances.delete(e),this.release(t);for(let t of this.layouts.values())t.open=t.open.filter(t=>!t.startsWith(`${e}:`)),t.active?.startsWith(`${e}:`)&&(t.active=null);this.changed(!0)}}dispose(){this.ended||(this.ended=!0,p(()=>{for(let e of[...this.instances.keys()])this.uninstall(e)}),this.viewExports.dispose(),this.files?.dispose(),this.fileIcons.dispose(),this.storage.dispose(),this.layouts.clear(),this.fileViews.clear(),this.contracts.clear(),this.listeners.clear())}own(e,t){let i=!0,a=()=>{i&&(i=!1,e.cleanups.delete(a),t())};return e.controller.signal.aborted||r(E)?.ended?(a(),a):(e.cleanups.add(a),n()&&h(a),a)}list(e){this.changes[0]();let t=[];for(let n of this.instances.values())if(n.status===`active`){for(let r of n.contributions)if(r.registry===e.id){let e=r.read();e!==void 0&&t.push(e)}}return t}context(e,t,i){let a=this.storage.forPlugin(e.id,e.controller.signal),c=Object.fromEntries(Object.entries(t.stores??{}).map(([e,t])=>[e,t.scope===`global`?a.store(e,{...t,scope:`global`}):n=>a.store(e,{...t,scope:{session:n}})])),l=(e,n)=>{let r=this.appearance[0]().locale;return(t.i18n?.[r]?.[e]??t.i18n?.[r.split(`-`)[0]]?.[e]??t.i18n?.en?.[e]??e).replace(/\{\{(\w+)\}\}/g,(e,t)=>String(n?.[t]??e))},u=Z(`layout`,{narrow:()=>this.appearance[0]().narrow,ready:()=>!!this.session[0](),open:(t,n,r)=>{e.controller.signal.aborted||this.openPanel(t,n,r)},close:(t,n)=>{e.controller.signal.aborted||this.closeFor(t,n)},toggle:(e,t)=>u.state(e,t)===`visible`?u.close(e,t):u.open(e,t),hide:(t,n)=>{if(e.controller.signal.aborted)return;let r=this.layout(n);r.active===t&&r.shown&&(r.shown=!1,this.changed())},state:(e,t)=>{this.changes[0]();let n=this.layout(t);return n.active===e?n.shown?`visible`:`active`:n.open.includes(e)?`open`:`closed`},stored:t=>(this.changes[0](),this.layout(t).open.filter(t=>t.startsWith(`${e.id}:`)).map(t=>t.slice(e.id.length+1))),side:{opened:e=>(this.changes[0](),this.layout(e).shown),toggle:t=>{if(e.controller.signal.aborted)return;let n=this.layout(t);n.shown=!n.shown,this.changed()},menu:()=>this.list(w).filter(e=>e.menu===`session.panel`).sort((e,t)=>(e.order??0)-(t.order??0))},scroll:{get:(e,t)=>(this.changes[0](),this.layout(e).scroll.get(t)),set:(t,n,r)=>{if(e.controller.signal.aborted)return;let i=this.layout(t).scroll;if(!i.has(n)&&i.size>=128)throw Error(`GUI layout scroll limit exceeded`);i.set(n,{...r}),this.changed()}}}),f=J(e.controller.signal),p=S(()=>e.controller.signal.aborted?{status:`inactive`,reason:`disabled`}:{status:`active`,generation:1,value:f}),m={open:t=>e.controller.signal.aborted||this.appearance[0]().narrow||!e.pages.some(e=>e.id===t)?!1:this.options.openPage?.(Y(e.id,t))??!1,current:()=>{let t=this.currentPage[0]();return e.pages.find(n=>Y(e.id,n.id)===t)?.id}},g=S(()=>e.controller.signal.aborted||!this.options.openPage||this.appearance[0]().narrow?{status:`inactive`,reason:`disabled`}:{status:`active`,generation:1,value:m});return Z(`ctx`,{id:e.id,options:i,signal:e.controller.signal,client:this.options.client,storage:a,stores:c,toast:Ae(e.controller.signal,this.options.toast),app:{name:`yuri`,version:e.native?.activation.app.version??``,channel:e.native?.activation.app.packaged?`prod`:`local`,platform:e.native?`desktop`:`web`,packaged:e.native?.activation.app.packaged??!1},desktop:e.native?Z(`desktop`,{os:e.native.activation.os}):void 0,t:l,plural:(e,t,n)=>{let r=`${e}.${new Intl.PluralRules(this.appearance[0]().locale).select(t)}`;return l(r,{...n,count:t})===r?l(`${e}.other`,{...n,count:t}):l(r,{...n,count:t})},add:(t,i)=>{if(e.controller.signal.aborted||r(E)?.ended)return()=>{};if([`server`,`composer-pill`,`slot`,`file.viewer`,`menubar-item`].includes(t.id)&&X(`registry.${t.id}`),e.contributions.size>=256)throw Error(`GUI contribution limit exceeded`);let a=()=>{},c,l=s(e=>{a=e,c=n();let r=()=>typeof i==`function`?i():i,o;if(t.id===`yuri.file-icon`){let e=d(()=>{try{return{ok:!0,value:r()}}catch(e){return{ok:!1,error:e}}});o=()=>{let t=e();if(!t.ok)throw t.error;return t.value}}else o=d(r);if(t.id===`style`){let e=document.createElement(`style`);document.head.append(e),h(()=>e.remove()),b(()=>{let t=o();e.textContent=t===void 0?``:String(t)})}return{registry:t.id,read:o}},n()??e.owner);e.contributions.add(l);let u=()=>{t.id===`yuri.file-icon`&&e.iconChanges[1](e=>e+1)};return o(u),o(()=>this.changed()),this.own(e,()=>{$(c,t=>{e.error??=String(t)}),a(),e.contributions.delete(l),o(u),o(()=>this.changed())})},list:e=>this.list(e),provide:(t,n)=>{if(e.controller.signal.aborted||r(E)?.ended)return()=>{};if(K(t.id)||t.id===`yuri.previewActions`||t.id===`yuri.pages`)throw Error(`Preview/export/page contracts are provided only by the Yuri host`);if(t.kind!==`contract`||!(t.id===e.id||t.id.startsWith(`${e.id}.`)))throw Error(`Contract must belong to the providing plugin`);let i=this.contract(t.id);if(i.provider)throw Error(`Contract already provided: ${t.id}`);return i.provider=e,i.live[1]({status:`active`,value:n,generation:++i.generation}),this.own(e,()=>{i.provider===e&&(i.provider=void 0,i.live[1]({status:`inactive`,reason:e.status===`failed`?`failed`:`disabled`}))})},use:t=>t.id===`yuri.pages`?t.kind===`contract`?g:X(`pages token must be a Contract`):t.id===`yuri.previewActions`?t.kind===`contract`?p:X(`preview actions token must be a Contract`):K(t.id)?t.kind===`contract`?this.viewExports.use(t.id,e.controller.signal):X(`export token must be a Contract`):t.kind===`ipc`&&e.native?e.native.token(t).live:this.contract(t.id,t.kind===`ipc`).live[0],main:t=>{if(!(t.id===e.id||t.id.startsWith(`${e.id}.`)))throw new x(`GUI_PLUGIN_FORBIDDEN`,`IPC must belong to the plugin`);return e.native?e.native.token(t).value:new Proxy({state:()=>void 0},{get:(e,t)=>t===`state`?e.state:t===`on`?()=>{throw new x(`GUI_PLUGIN_UNSUPPORTED`)}:()=>Promise.reject(new x(`GUI_PLUGIN_UNSUPPORTED`))})},sessions:{current:this.session[0],list:()=>{let e=this.session[0]();return e?[e]:[]}},screen:{current:()=>this.session[0]()?this.screen:void 0},layout:u,appearance:{mode:()=>this.appearance[0]().mode,font:()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||`monospace`},locale:{locale:()=>this.appearance[0]().locale,direction:()=>/^(ar|fa|he|ur)(-|$)/i.test(this.appearance[0]().locale)?`rtl`:`ltr`},system:{copy:e=>navigator.clipboard.writeText(e),openExternal:e=>{let t=new URL(e);[`https:`,`http:`,`mailto:`].includes(t.protocol)||X(`system.openExternal protocol`),window.open(e,`_blank`,`noopener,noreferrer`)},save:Me},commands:{run:t=>e.controller.signal.aborted||!this.command(t)?!1:(this.runCommand(t),!0)},links:{open:t=>!e.controller.signal.aborted&&this.navigateLink(e,t),exists:t=>o(()=>{if(e.controller.signal.aborted)return!1;let n=this.linkHandler(t);try{return Promise.resolve(n?.value.exists?.(t)??!1).catch(()=>!1)}catch{return!1}})}})}contract(e,n=!1){let r=this.contracts.get(e);if(!r){if(this.contracts.size>=256)throw Error(`GUI contract limit exceeded`);let n=t({status:`inactive`,reason:`disabled`});r={live:[S(n[0]),n[1]],generation:0},this.contracts.set(e,r)}return n&&r.provider&&X(`IPC contract collision`),r}derive(e){if(e.status!==`active`)return;let t=[],n=[],r=[],i=[],a=[],s=[],c=this.session[0]();for(let o of e.contributions){if(o.registry===`yuri.file-icon`)continue;let l=o.read();if(l!==void 0){if(o.registry===`yuri.page`){let e=Ne(l);if(s.some(t=>t.id===e.id))throw Error(`Duplicate yuri.page id`);s.push(e)}else if(o.registry===D.id){let n=l;n.enabled!==!1&&t.push({key:`${e.id}.${n.id}`,pluginId:e.id,title:n.title,description:n.description,bind:n.bind,hidden:n.hidden,run:()=>this.invoke(e,()=>n.run())})}else if(o.registry===ge.id){let t=l;a.push({key:JSON.stringify([e.id,t.id]),pluginId:e.id,label:t.label,title:t.title,icon:t.icon,busy:t.busy,pressed:t.pressed,actionable:!!t.run,run:t.run})}else if(o.registry===k.id&&c){let t=l,r=`${e.id}:`,i=this.layout(c).open.filter(e=>e.startsWith(r)).map(e=>e.slice(r.length));for(let r of t.list({session:c,screen:this.screen,open:i}))n.push({plugin:e,panel:t,tab:r})}else if(o.registry===he.id){let e=l;(e.page||e.section)&&X(`SettingsPage host sections`),e.title,r.push(e)}else if(o.registry===w.id){let e=l;e.menu===`session.panel`?(e.title,i.push(e)):X(`MenuItem.${e.menu}`)}}}for(let e of n)e.tab.title;e.commands=t,e.titlebarItems=a,e.panels=n,e.pages=s,e.settings=r,e.menus=i,o(()=>this.views[1](e=>e+1))}publish(){let e=o(this.session[0]),t=e?this.layouts.get(e.key):void 0,n=[...this.instances.values()],r=n.filter(e=>e.status===`active`),i=r.flatMap(e=>e.panels.map(({tab:n})=>{let r=n.file?this.filePath(n.file):void 0;return{key:`${e.id}:${n.id}`,pluginId:e.id,title:n.title,file:r,inline:!!(r&&this.fileViews.has(r)),active:t?.shown===!0&&t.active===`${e.id}:${n.id}`}}));this.snapshot=Object.freeze({plugins:Q(n.map(({id:e,revision:t,status:n,error:r,errorCode:i,iconError:a})=>({id:e,revision:t,status:n,error:r??a,...i?{errorCode:i}:{}}))),commands:Q(r.flatMap(e=>e.commands.filter(e=>!e.hidden))),panels:Q(i),titlebarItems:Q(r.flatMap(e=>e.titlebarItems.map(({run:e,...t})=>t))),pages:Q(r.flatMap(e=>e.pages.map(t=>({key:Y(e.id,t.id),pluginId:e.id,title:t.title,icon:t.icon})))),settings:Q(r.flatMap(e=>e.settings.map(t=>({key:`${e.id}:${t.id}`,pluginId:e.id,title:t.title})))),menuItems:Q(r.flatMap(e=>e.menus.map(t=>({key:`${e.id}:${t.id}`,pluginId:e.id,title:t.title,description:t.description,run:()=>{this.invoke(e,()=>t.run())}})))),activePanel:t?.shown&&i.some(e=>e.key===t.active)?t.active:null,sessionKey:e?.key});for(let e of this.listeners)e()}invoke(t,n){if(!t.controller.signal.aborted)try{let r=e(t.owner??null,n);if(r instanceof Promise)return r.catch(e=>this.fail(t,e))}catch(e){this.fail(t,e)}}command(e){return[...this.instances.values()].flatMap(e=>e.commands).find(t=>t.key===e)}runCommand(e){return this.command(e)?.run()}runTitlebarItem(e){for(let t of this.instances.values()){let n=t.titlebarItems.find(t=>t.key===e);if(n?.run&&!n.busy)return this.invoke(t,n.run)}}linkHandler(e){let t=[];for(let e of this.instances.values())for(let n of e.contributions)if(n.registry===me.id){let r=n.read();r&&t.push({instance:e,value:r})}for(let n of t.sort((e,t)=>(t.value.priority??0)-(e.value.priority??0)))try{if(n.value.match(e))return n}catch(e){this.fail(n.instance,e)}}navigateLink(e,t){if(this.ended)return!1;let n=ue(t.href);if(!n||!le(n.path))return this.openLink(t);let r=this.session[0]();if(!r||t.session&&(t.session.key!==r.key||t.session.server.id!==r.server.id))return!1;if(!this.options.focusFile)return this.openLink(t);let i=ie(t.base??r.directory,n.path),a=n.line===void 0?``:`:${n.line}${n.column===void 0?``:`:${n.column}`}`;return this.invoke(e,()=>this.options.focusFile(i+a,r.directory)),!0}openLink(e){if(this.ended)return!1;let t={...e,session:e.session??this.session[0]()},n=this.linkHandler(t);return n?(this.invoke(n.instance,()=>n.value.open(t)),!0):!1}filePath(e,t=this.session[0]()?.directory){let n=F(e);return/^(?:\/|[a-z]:\/)/i.test(n)||!t?n:F(`${t}/${n}`)}registerFileView(e,t){if(this.ended)return()=>{};let n=this.filePath(e,t),r=this.fileViews.get(n)??0;this.fileViews.set(n,r+1),r===0&&this.changed(!0);let i=!1;return()=>{if(i||this.ended)return;i=!0;let e=(this.fileViews.get(n)??1)-1;if(e){this.fileViews.set(n,e);return}{let e=this.session[0](),t=e&&this.layouts.get(e.key);t?.active&&this.snapshot.panels.some(e=>e.key===t.active&&e.file===n)&&(t.shown=!1),this.fileViews.delete(n)}this.changed(!0)}}filePanel(e,t){let n=this.filePath(e,t);return this.snapshot.panels.find(e=>e.file===n&&e.inline)}panelVisible(e){let t=this.session[0]();if(!t)return!1;let n=this.panel(e)?.tab.file;if(n&&this.fileViews.has(this.filePath(n)))return!0;let r=this.layouts.get(t.key);return!!(r?.shown&&r.active===e)}layout(e){let t=this.layouts.get(e.key);if(!t){if(this.layouts.size>=128)throw Error(`GUI session layout limit exceeded`);t={open:[],active:null,shown:!1,scroll:new Map},this.layouts.set(e.key,t)}return t}openPanel(e,t,n){if(this.ended)return;let r=this.layout(t),i=r.active,a=r.shown,o=r.open.length;if(!r.open.includes(e)){if(r.open.length>=64)throw Error(`GUI panel tab limit exceeded`);r.open=[...r.open,e]}n?.tab!==`append`&&(r.active=e,r.shown=!(this.appearance[0]().narrow&&n?.background)),(i!==r.active||a!==r.shown||o!==r.open.length)&&this.changed(!0);let s=this.panel(e);t.key===this.session[0]()?.key&&s&&n?.tab!==`append`&&this.invoke(s.plugin,()=>s.panel.focus?.({...this.props(e),restored:!1}))}selectPanel(e){let t=this.session[0]();t&&this.openPanel(e,t)}closeFor(e,t){let n=this.layout(t),r=t.key===this.session[0]()?.key?this.panel(e):void 0;if(!n.open.includes(e)||r?.tab.pinned||r?.tab.closable===!1)return;let i=this.session[0](),a=r&&i?{tab:r.tab,session:i,screen:this.screen}:void 0;n.open=n.open.filter(t=>t!==e),n.active===e&&(n.active=n.open.at(-1)??null),this.changed(!0),r&&a&&this.invoke(r.plugin,()=>r.panel.close?.(a))}closePanel(e){let t=this.session[0]();t&&this.closeFor(e,t)}hidePanel(){let e=this.session[0]();if(!e)return;let t=this.layout(e);t.shown&&(t.shown=!1,this.changed(!0))}panel(e){return[...this.instances.values()].flatMap(e=>e.panels).find(t=>`${t.plugin.id}:${t.tab.id}`===e)}props(e,t=!1){let n=this.panel(e)?.tab,r=()=>(this.views[0](),this.panel(e)?.tab??n??X(`panel no longer listed`)),i=t?d(()=>{let e=r();return{tab:e,fields:Object.getPrototypeOf(e)===Object.prototype?Object.getOwnPropertyDescriptors(e):void 0}},void 0,{equals:Pe}):void 0,a=i?()=>i().tab:r,o=()=>this.session[0]()??X(`panel without session`);return{get tab(){return a()},get session(){return o()},screen:this.screen}}mountPanel(e,t,n){let r=this.panel(e);if(!r)return()=>{};let i=new AbortController,a=()=>{let a=d(()=>{this.session[0](),this.changes[0](),this.views[0]();let t=this.panel(e)?.tab.file;return t&&this.files&&this.panelVisible(e)?{model:this.files,file:t}:void 0},void 0,{equals:(e,t)=>e?.model===t?.model&&e?.file===t?.file});b(()=>{let e=a();e&&(h(e.model.watch(e.file)),e.model.sync(e.file).catch(()=>{}))});let s=()=>o(()=>r.panel.render(this.props(e,!0)));return l(q.Provider,{value:n?{plugin:r.plugin.controller.signal,signal:i.signal,content:t,target:n}:void 0,get children(){return s()}})},s=this.mount(r.plugin,t,()=>l(ve.Provider,{value:{visible:()=>(this.changes[0](),this.panelVisible(e)),present:()=>(this.changes[0](),this.panelVisible(e)),placement:()=>this.appearance[0]().narrow?`mobile`:`side`,reserve:()=>!1,animate:()=>!1,sidebar:Z(`panel.sidebar`,{}),open:()=>{let e=this.session[0]();return e?r.plugin.context.layout.stored(e):[]}},get children(){return a()}})),c=()=>{this.panelMounts.delete(c),i.abort(),s()};return this.panelMounts.add(c),this.own(r.plugin,c)}mountSettings(e,t){for(let n of this.instances.values()){let r=n.settings.find(t=>`${n.id}:${t.id}`===e);if(r)return this.mount(n,t,()=>r.render({}))}return()=>{}}mountPage(e,t){if(this.appearance[0]().narrow)return()=>{};for(let n of this.instances.values()){let r=n.pages.find(t=>Y(n.id,t.id)===e);if(r)return this.mount(n,t,()=>r.render())}return()=>{}}mount(e,t,r){if(e.controller.signal.aborted)return()=>{};let i=()=>{},a,s=t=>{queueMicrotask(()=>this.fail(e,t))};try{i=fe(()=>l(C.Provider,{value:e.context,get children(){return a=n(),f(()=>o(r),s)}}),t)}catch(t){this.fail(e,t)}return this.own(e,()=>{$(a,t=>{e.error??=String(t)}),i(),t.replaceChildren()})}};export{Fe as GuiPluginHost};