@rexvane/piweb 0.3.18 → 0.3.19

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 (261) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +8 -6
  3. package/.next/build-manifest.json +3 -3
  4. package/.next/prerender-manifest.json +4 -4
  5. package/.next/react-loadable-manifest.json +23 -9
  6. package/.next/required-server-files.js +2 -1
  7. package/.next/required-server-files.json +2 -1
  8. package/.next/routes-manifest.json +12 -0
  9. package/.next/server/app/_global-error/page.js +2 -2
  10. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  11. package/.next/server/app/_global-error.html +1 -1
  12. package/.next/server/app/_global-error.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  14. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  15. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  16. package/.next/server/app/_not-found/page.js +1 -1
  17. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  18. package/.next/server/app/_not-found.html +1 -1
  19. package/.next/server/app/_not-found.rsc +2 -2
  20. package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  21. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  22. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  23. package/.next/server/app/api/agent/[id]/events/route.js +3 -3
  24. package/.next/server/app/api/agent/[id]/events/route.js.nft.json +1 -1
  25. package/.next/server/app/api/agent/[id]/route.js +1 -1
  26. package/.next/server/app/api/agent/[id]/route.js.nft.json +1 -1
  27. package/.next/server/app/api/agent/[id]/tree/route.js +1 -1
  28. package/.next/server/app/api/agent/[id]/tree/route.js.nft.json +1 -1
  29. package/.next/server/app/api/agent/new/route.js +1 -1
  30. package/.next/server/app/api/agent/new/route.js.nft.json +1 -1
  31. package/.next/server/app/api/config/route.js +1 -1
  32. package/.next/server/app/api/config/route.js.nft.json +1 -1
  33. package/.next/server/app/api/files/route.js +1 -1
  34. package/.next/server/app/api/files/route.js.nft.json +1 -1
  35. package/.next/server/app/api/fs/route.js +1 -0
  36. package/.next/server/app/api/fs/route.js.nft.json +1 -0
  37. package/.next/server/app/api/fs/route_client-reference-manifest.js +1 -0
  38. package/.next/server/app/api/git/route.js +2 -2
  39. package/.next/server/app/api/git/route.js.nft.json +1 -1
  40. package/.next/server/app/api/growth/route.js +1 -1
  41. package/.next/server/app/api/growth/route.js.nft.json +1 -1
  42. package/.next/server/app/api/health/route.js +1 -1
  43. package/.next/server/app/api/models/route.js +1 -1
  44. package/.next/server/app/api/models/route.js.nft.json +1 -1
  45. package/.next/server/app/api/pi-settings/route.js +1 -1
  46. package/.next/server/app/api/pi-settings/route.js.nft.json +1 -1
  47. package/.next/server/app/api/plugins/route.js +1 -1
  48. package/.next/server/app/api/plugins/route.js.nft.json +1 -1
  49. package/.next/server/app/api/prompts/route.js +1 -1
  50. package/.next/server/app/api/prompts/route.js.nft.json +1 -1
  51. package/.next/server/app/api/remote/route.js +8 -0
  52. package/.next/server/app/api/remote/route.js.nft.json +1 -0
  53. package/.next/server/app/api/remote/route_client-reference-manifest.js +1 -0
  54. package/.next/server/app/api/security/route.js +1 -1
  55. package/.next/server/app/api/security/route.js.nft.json +1 -1
  56. package/.next/server/app/api/sessions/[id]/export/route.js +1 -1
  57. package/.next/server/app/api/sessions/[id]/export/route.js.nft.json +1 -1
  58. package/.next/server/app/api/sessions/[id]/route.js +1 -1
  59. package/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -1
  60. package/.next/server/app/api/sessions/import/route.js +2 -2
  61. package/.next/server/app/api/sessions/import/route.js.nft.json +1 -1
  62. package/.next/server/app/api/sessions/route.js +1 -1
  63. package/.next/server/app/api/sessions/route.js.nft.json +1 -1
  64. package/.next/server/app/api/skills/route.js +1 -1
  65. package/.next/server/app/api/skills/route.js.nft.json +1 -1
  66. package/.next/server/app/api/update/route.js +2 -2
  67. package/.next/server/app/api/update/route.js.nft.json +1 -1
  68. package/.next/server/app/api/version/route.js +1 -1
  69. package/.next/server/app/api/version/route.js.nft.json +1 -1
  70. package/.next/server/app/api/web-auth/route.js +3 -1
  71. package/.next/server/app/api/workspaces/route.js +1 -1
  72. package/.next/server/app/api/workspaces/route.js.nft.json +1 -1
  73. package/.next/server/app/icon.svg/route.js +1 -1
  74. package/.next/server/app/index.html +1 -1
  75. package/.next/server/app/index.rsc +4 -4
  76. package/.next/server/app/index.segments/__PAGE__.segment.rsc +4 -4
  77. package/.next/server/app/index.segments/_full.segment.rsc +4 -4
  78. package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  79. package/.next/server/app/login/page.js +1 -1
  80. package/.next/server/app/login/page_client-reference-manifest.js +1 -1
  81. package/.next/server/app/login.html +1 -1
  82. package/.next/server/app/login.rsc +3 -3
  83. package/.next/server/app/login.segments/_full.segment.rsc +3 -3
  84. package/.next/server/app/login.segments/_tree.segment.rsc +2 -2
  85. package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +3 -3
  86. package/.next/server/app/page.js +1 -1
  87. package/.next/server/app/page.js.nft.json +1 -1
  88. package/.next/server/app/page_client-reference-manifest.js +1 -1
  89. package/.next/server/app-paths-manifest.json +8 -6
  90. package/.next/server/chunks/229.js +1 -1
  91. package/.next/server/chunks/243.js +1 -0
  92. package/.next/server/chunks/393.js +1 -0
  93. package/.next/server/chunks/496.js +1 -1
  94. package/.next/server/chunks/538.js +1 -0
  95. package/.next/server/chunks/686.js +1 -4
  96. package/.next/server/chunks/802.js +2 -0
  97. package/.next/server/chunks/807.js +1 -0
  98. package/.next/server/chunks/920.js +4 -0
  99. package/.next/server/chunks/924.js +6 -0
  100. package/.next/server/instrumentation.js +1 -0
  101. package/.next/server/instrumentation.js.nft.json +1 -0
  102. package/.next/server/middleware-build-manifest.js +1 -1
  103. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  104. package/.next/server/middleware.js +4 -3
  105. package/.next/server/pages/404.html +1 -1
  106. package/.next/server/pages/500.html +1 -1
  107. package/.next/server/server-reference-manifest.json +1 -1
  108. package/.next/static/JDGSR-TIbk9qZWcUNYIX3/_buildManifest.js +1 -0
  109. package/.next/static/chunks/2716.7ad073038e94a802.js +1 -0
  110. package/.next/static/chunks/316-5ea443ee6b512aa9.js +1 -0
  111. package/.next/static/chunks/4673.8a5a9e6855350e34.js +1 -0
  112. package/.next/static/chunks/4686-e3825f3b6a384aa1.js +1 -0
  113. package/.next/static/chunks/4778.e4c9ed093a413bc4.js +1 -0
  114. package/.next/static/chunks/5173.91ddb803785009f8.js +1 -0
  115. package/.next/static/chunks/839.7403c6bdace4c56c.js +1 -0
  116. package/.next/static/chunks/8552.6bfe3e101250b20f.js +1 -0
  117. package/.next/static/chunks/app/_global-error/page-b179d9f7f6f2daf9.js +1 -0
  118. package/.next/static/chunks/app/api/agent/[id]/events/route-b179d9f7f6f2daf9.js +1 -0
  119. package/.next/static/chunks/app/api/agent/[id]/route-b179d9f7f6f2daf9.js +1 -0
  120. package/.next/static/chunks/app/api/agent/[id]/tree/route-b179d9f7f6f2daf9.js +1 -0
  121. package/.next/static/chunks/app/api/agent/new/route-b179d9f7f6f2daf9.js +1 -0
  122. package/.next/static/chunks/app/api/config/route-b179d9f7f6f2daf9.js +1 -0
  123. package/.next/static/chunks/app/api/files/route-b179d9f7f6f2daf9.js +1 -0
  124. package/.next/static/chunks/app/api/fs/route-b179d9f7f6f2daf9.js +1 -0
  125. package/.next/static/chunks/app/api/git/route-b179d9f7f6f2daf9.js +1 -0
  126. package/.next/static/chunks/app/api/growth/route-b179d9f7f6f2daf9.js +1 -0
  127. package/.next/static/chunks/app/api/health/route-b179d9f7f6f2daf9.js +1 -0
  128. package/.next/static/chunks/app/api/models/route-b179d9f7f6f2daf9.js +1 -0
  129. package/.next/static/chunks/app/api/pi-settings/route-b179d9f7f6f2daf9.js +1 -0
  130. package/.next/static/chunks/app/api/plugins/route-b179d9f7f6f2daf9.js +1 -0
  131. package/.next/static/chunks/app/api/prompts/route-b179d9f7f6f2daf9.js +1 -0
  132. package/.next/static/chunks/app/api/remote/route-b179d9f7f6f2daf9.js +1 -0
  133. package/.next/static/chunks/app/api/security/route-b179d9f7f6f2daf9.js +1 -0
  134. package/.next/static/chunks/app/api/sessions/[id]/export/route-b179d9f7f6f2daf9.js +1 -0
  135. package/.next/static/chunks/app/api/sessions/[id]/route-b179d9f7f6f2daf9.js +1 -0
  136. package/.next/static/chunks/app/api/sessions/import/route-b179d9f7f6f2daf9.js +1 -0
  137. package/.next/static/chunks/app/api/sessions/route-b179d9f7f6f2daf9.js +1 -0
  138. package/.next/static/chunks/app/api/skills/route-b179d9f7f6f2daf9.js +1 -0
  139. package/.next/static/chunks/app/api/update/route-b179d9f7f6f2daf9.js +1 -0
  140. package/.next/static/chunks/app/api/version/route-b179d9f7f6f2daf9.js +1 -0
  141. package/.next/static/chunks/app/api/web-auth/route-b179d9f7f6f2daf9.js +1 -0
  142. package/.next/static/chunks/app/api/workspaces/route-b179d9f7f6f2daf9.js +1 -0
  143. package/.next/static/chunks/app/login/page-5e276a1eeb8867df.js +1 -0
  144. package/.next/static/chunks/app/page-2e425ef83fba0782.js +1 -0
  145. package/.next/static/chunks/next/dist/client/components/builtin/app-error-b179d9f7f6f2daf9.js +1 -0
  146. package/.next/static/chunks/next/dist/client/components/builtin/forbidden-b179d9f7f6f2daf9.js +1 -0
  147. package/.next/static/chunks/next/dist/client/components/builtin/not-found-b179d9f7f6f2daf9.js +1 -0
  148. package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-b179d9f7f6f2daf9.js +1 -0
  149. package/.next/static/chunks/webpack-bd2b9202ecbcdcaa.js +1 -0
  150. package/.next/static/css/7391c42e1ae617f9.css +1 -0
  151. package/.next/types/app/api/fs/route.ts +353 -0
  152. package/.next/types/app/api/remote/route.ts +353 -0
  153. package/.next/types/routes.d.ts +3 -1
  154. package/.next/types/validator.ts +18 -0
  155. package/README.md +56 -10
  156. package/next.config.ts +3 -2
  157. package/package.json +3 -3
  158. package/scripts/launcher.mjs +194 -13
  159. package/scripts/release.mjs +0 -2
  160. package/src/app/api/agent/[id]/events/route.ts +11 -6
  161. package/src/app/api/fs/route.ts +119 -0
  162. package/src/app/api/growth/route.ts +11 -6
  163. package/src/app/api/models/route.ts +21 -9
  164. package/src/app/api/remote/route.ts +67 -0
  165. package/src/app/api/sessions/[id]/export/route.ts +11 -1
  166. package/src/app/api/sessions/route.ts +3 -1
  167. package/src/app/api/web-auth/route.ts +45 -49
  168. package/src/app/api/workspaces/route.ts +16 -0
  169. package/src/app/globals.css +6 -0
  170. package/src/app/login/page.tsx +8 -60
  171. package/src/components/AppShell.tsx +202 -155
  172. package/src/components/ChatInput.tsx +61 -6
  173. package/src/components/ChatWindow.tsx +274 -132
  174. package/src/components/DirectoryPicker.tsx +189 -0
  175. package/src/components/DrawerPanel.tsx +164 -0
  176. package/src/components/FileViewer.tsx +2 -2
  177. package/src/components/GrowthTree.tsx +6 -5
  178. package/src/components/MarkdownBlock.tsx +134 -0
  179. package/src/components/OutlineRail.tsx +22 -1
  180. package/src/components/ProjectPanel.tsx +197 -14
  181. package/src/components/RemoteSection.tsx +232 -0
  182. package/src/components/SessionImportSection.tsx +60 -38
  183. package/src/components/SettingsPanel.tsx +104 -57
  184. package/src/components/icons.tsx +23 -0
  185. package/src/hooks/useGrowth.ts +47 -25
  186. package/src/hooks/usePiWeb.ts +100 -14
  187. package/src/i18n.tsx +115 -28
  188. package/src/instrumentation-node.ts +35 -0
  189. package/src/instrumentation.ts +18 -0
  190. package/src/lib/agent-config.ts +134 -0
  191. package/src/lib/agent-manager.ts +243 -61
  192. package/src/lib/auth-throttle.ts +102 -0
  193. package/src/lib/auth.ts +35 -27
  194. package/src/lib/files-service.ts +61 -1
  195. package/src/lib/font.ts +84 -0
  196. package/src/lib/git-service.ts +5 -3
  197. package/src/lib/growth-service.ts +78 -30
  198. package/src/lib/growth-tracker.ts +91 -9
  199. package/src/lib/models-service.ts +36 -11
  200. package/src/lib/pi-settings.ts +10 -12
  201. package/src/lib/pi.ts +145 -18
  202. package/src/lib/plugins-service.ts +67 -35
  203. package/src/lib/remote/assets.json +4 -0
  204. package/src/lib/remote/mobile-proxy.ts +149 -0
  205. package/src/lib/remote/supervisor.ts +482 -0
  206. package/src/lib/security-service.ts +6 -11
  207. package/src/lib/session-import/claude.ts +45 -21
  208. package/src/lib/session-reader.ts +106 -3
  209. package/src/lib/skills-service.ts +34 -12
  210. package/src/lib/text-sanitize.ts +12 -0
  211. package/src/lib/theme.ts +3 -0
  212. package/src/lib/types.ts +16 -2
  213. package/src/lib/update-service.ts +0 -1
  214. package/src/lib/web-auth-shared.ts +5 -1
  215. package/src/lib/web-auth.ts +139 -22
  216. package/src/lib/web-launch-token.ts +55 -0
  217. package/src/lib/web-secret.ts +182 -0
  218. package/src/lib/workspace-store.ts +91 -7
  219. package/src/proxy.ts +46 -12
  220. package/.next/server/chunks/532.js +0 -1
  221. package/.next/static/chunks/2155.2f27fe7098987699.js +0 -1
  222. package/.next/static/chunks/2608.ec8ff1f5767c9056.js +0 -1
  223. package/.next/static/chunks/2716.93be8ad5c970c516.js +0 -1
  224. package/.next/static/chunks/4632.112d2e893d48d188.js +0 -1
  225. package/.next/static/chunks/4673.c1fb1580efc6ace7.js +0 -1
  226. package/.next/static/chunks/4686-f4a037d609cea3f2.js +0 -1
  227. package/.next/static/chunks/692-7992db0ae9cc3021.js +0 -1
  228. package/.next/static/chunks/app/_global-error/page-f77e9ede9808b18e.js +0 -1
  229. package/.next/static/chunks/app/api/agent/[id]/events/route-f77e9ede9808b18e.js +0 -1
  230. package/.next/static/chunks/app/api/agent/[id]/route-f77e9ede9808b18e.js +0 -1
  231. package/.next/static/chunks/app/api/agent/[id]/tree/route-f77e9ede9808b18e.js +0 -1
  232. package/.next/static/chunks/app/api/agent/new/route-f77e9ede9808b18e.js +0 -1
  233. package/.next/static/chunks/app/api/config/route-f77e9ede9808b18e.js +0 -1
  234. package/.next/static/chunks/app/api/files/route-f77e9ede9808b18e.js +0 -1
  235. package/.next/static/chunks/app/api/git/route-f77e9ede9808b18e.js +0 -1
  236. package/.next/static/chunks/app/api/growth/route-f77e9ede9808b18e.js +0 -1
  237. package/.next/static/chunks/app/api/health/route-f77e9ede9808b18e.js +0 -1
  238. package/.next/static/chunks/app/api/models/route-f77e9ede9808b18e.js +0 -1
  239. package/.next/static/chunks/app/api/pi-settings/route-f77e9ede9808b18e.js +0 -1
  240. package/.next/static/chunks/app/api/plugins/route-f77e9ede9808b18e.js +0 -1
  241. package/.next/static/chunks/app/api/prompts/route-f77e9ede9808b18e.js +0 -1
  242. package/.next/static/chunks/app/api/security/route-f77e9ede9808b18e.js +0 -1
  243. package/.next/static/chunks/app/api/sessions/[id]/export/route-f77e9ede9808b18e.js +0 -1
  244. package/.next/static/chunks/app/api/sessions/[id]/route-f77e9ede9808b18e.js +0 -1
  245. package/.next/static/chunks/app/api/sessions/import/route-f77e9ede9808b18e.js +0 -1
  246. package/.next/static/chunks/app/api/sessions/route-f77e9ede9808b18e.js +0 -1
  247. package/.next/static/chunks/app/api/skills/route-f77e9ede9808b18e.js +0 -1
  248. package/.next/static/chunks/app/api/update/route-f77e9ede9808b18e.js +0 -1
  249. package/.next/static/chunks/app/api/version/route-f77e9ede9808b18e.js +0 -1
  250. package/.next/static/chunks/app/api/web-auth/route-f77e9ede9808b18e.js +0 -1
  251. package/.next/static/chunks/app/api/workspaces/route-f77e9ede9808b18e.js +0 -1
  252. package/.next/static/chunks/app/login/page-52ef4841cbd199a8.js +0 -1
  253. package/.next/static/chunks/app/page-b51087831582ee37.js +0 -1
  254. package/.next/static/chunks/next/dist/client/components/builtin/app-error-f77e9ede9808b18e.js +0 -1
  255. package/.next/static/chunks/next/dist/client/components/builtin/forbidden-f77e9ede9808b18e.js +0 -1
  256. package/.next/static/chunks/next/dist/client/components/builtin/not-found-f77e9ede9808b18e.js +0 -1
  257. package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-f77e9ede9808b18e.js +0 -1
  258. package/.next/static/chunks/webpack-c31263fd83d75ce6.js +0 -1
  259. package/.next/static/css/0cd968b9b62035b5.css +0 -1
  260. package/.next/static/en03hnPiuro0rnf8QkFEe/_buildManifest.js +0 -1
  261. /package/.next/static/{en03hnPiuro0rnf8QkFEe → JDGSR-TIbk9qZWcUNYIX3}/_ssgManifest.js +0 -0
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[839],{839:(e,a,t)=>{"use strict";t.r(a),t.d(a,{SettingsPanel:()=>P});var s=t(5155),l=t(2115),r=t(7650),i=t(560),n=t(9992);let o=[[/^amazon-bedrock$/,"bedrock-color"],[/^ant-ling$/,"antgroup-color"],[/^anthropic$/,"anthropic"],[/^azure-/,"azure-color"],[/^baseten$/,"baseten"],[/^cerebras$/,"cerebras-color"],[/^cloudflare-/,"cloudflare-color"],[/^deepseek$/,"deepseek-color"],[/^fireworks$/,"fireworks-color"],[/^github-copilot$/,"githubcopilot"],[/^google-vertex(?:-|$)/,"googlecloud-color"],[/^google$/,"google-color"],[/^groq$/,"groq"],[/^huggingface$/,"huggingface-color"],[/^kimi(?:-|$)/,"kimi-color"],[/^minimax/,"minimax-color"],[/^mistral$/,"mistral-color"],[/^moonshot(?:ai)?(?:-|$)/,"moonshot"],[/^nvidia$/,"nvidia-color"],[/^openai/,"openai"],[/^opencode(?:-|$)/,"opencode"],[/^openrouter$/,"openrouter-color"],[/^qwen(?:-|$)/,"qwen-color"],[/^together$/,"together-color"],[/^vercel(?:-|$)/,"vercel"],[/^xai$/,"xai"],[/^xiaomi(?:-|$)/,"xiaomimimo"],[/^zai(?:-|$)/,"zai"]];[...new Set(o.map(([,e])=>e))];let d=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,c=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function u(e){let a=new Set(c);return[...c,...[...new Set(e.filter(e=>e&&!a.has(e)))].sort()]}function p({id:e,name:a,size:t=36}){let l,r=o.find(([a])=>a.test(e))?.[1]??null;return(0,s.jsx)("span",{"aria-hidden":"true",className:"inline-flex flex-none items-center justify-center overflow-hidden",style:{width:t,height:t,borderRadius:Math.max(10,Math.round(.3*t)),background:"#f7f7f5",border:"0.5px solid rgba(0,0,0,.09)",color:"#18191b",fontSize:Math.max(10,Math.round(.32*t)),fontWeight:750,letterSpacing:"-0.03em"},children:r?(0,s.jsx)("img",{src:`/provider-icons/${r}.svg`,alt:"",width:Math.round(.66*t),height:Math.round(.66*t)}):(l=a.trim().split(/[\s_-]+/).filter(Boolean)).length>=2?(l[0][0]+l[1][0]).toUpperCase():(l[0]??e).slice(0,2).toUpperCase()})}var m=t(1859);function h(e){let a=e&&"object"==typeof e&&!Array.isArray(e)?e:{id:"string"==typeof e?e:""};return{id:String(a.id??""),name:"string"==typeof a.name?a.name:"",contextWindow:"number"==typeof a.contextWindow?a.contextWindow:void 0,maxTokens:"number"==typeof a.maxTokens?a.maxTokens:void 0,source:a}}function x(e){let a=new Set;for(let t=0;t<e.length;t+=1){let s=e[t],l=s.id.trim();if(!l||a.has(l))return{index:t,reason:"id"};if(a.add(l),[s.contextWindow,s.maxTokens].some(e=>void 0!==e&&(!Number.isSafeInteger(e)||e<=0)))return{index:t,reason:"capacity"}}}function v(e){let a={...e.source},t=e.source?h(e.source):void 0;for(let s of["id","name","contextWindow","maxTokens"]){if(t&&Object.is(e[s],t[s]))continue;let l=e[s];if("id"===s||"name"===s){let e="string"==typeof l?l.trim():"";"id"===s||e?a[s]=e:delete a[s]}else"number"==typeof l&&Number.isSafeInteger(l)&&l>0?a[s]=l:delete a[s]}return a}function f(e,a,t){let s={...e};for(let t of["baseUrl","name","api"]){let l=a[t];void 0!==l&&l!==("string"==typeof e[t]?e[t]:"")&&(l.trim()?s[t]=l.trim():delete s[t])}return a.apiKey?.trim()&&(s.apiKey=a.apiKey.trim()),(a.models.length||Object.prototype.hasOwnProperty.call(e,"models"))&&(s.models=a.models.map(v)),a.models.length&&void 0===e.models&&void 0===s.api&&t&&(s.api=t),s}var g=t(901),b=t.n(g);function y({mode:e,providers:a,existingIds:t,onClose:r,onSaveBuiltin:i,onSaveCustom:o,onOAuthLogin:c}){let{t:h}=(0,m.s)(),[f,g]=(0,l.useState)(a[0]?.id??""),[j,S]=(0,l.useState)(!1),[N,k]=(0,l.useState)(""),[_,C]=(0,l.useState)("api_key"),[z,P]=(0,l.useState)(""),[M,E]=(0,l.useState)(!1),[T,R]=(0,l.useState)(""),[$,D]=(0,l.useState)(""),[L,F]=(0,l.useState)(""),W=u(a.flatMap(e=>e.apis)),[O,U]=(0,l.useState)(W.includes("openai-completions")?"openai-completions":W[0]??"openai-completions"),[A,I]=(0,l.useState)([]),[B,K]=(0,l.useState)(!1),[H,J]=(0,l.useState)(""),q=(0,l.useRef)(null),V=a.find(e=>e.id===f),Z=a.filter(e=>{let a=N.trim().toLocaleLowerCase();return!a||e.name.toLocaleLowerCase().includes(a)||e.id.toLocaleLowerCase().includes(a)});(0,l.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),j?S(!1):r())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[r,j]),(0,l.useEffect)(()=>{if(!j)return;let e=e=>{q.current?.contains(e.target)||S(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[j]);let X=(e,a)=>{I(t=>t.map((t,s)=>s===e?{...t,...a}:t))},G=x(A),Q=$.trim(),Y=d.test(Q),ee=Y&&!t.includes(Q)&&!!T.trim()&&A.length>0&&!G,ea=!!V&&("oauth"===_||!G),et=(0,l.useRef)(!1),es=async()=>{if(!et.current&&("builtin"===e?ea:ee)){et.current=!0,K(!0),J("");try{let a;if("builtin"===e&&V)if("oauth"===_&&c)a=await c(V.id);else{let e={};T.trim()&&(e.baseUrl=T.trim()),A.length&&(e.api=V.apis[0]??"openai-completions",e.models=A.map(v)),a=await i({providerId:V.id,apiKey:z.trim(),config:e})}else a=await o({providerId:Q,config:{name:L.trim()||Q,baseUrl:T.trim(),api:O,...z.trim()?{apiKey:z.trim()}:{},models:A.map(v)}});a.success?r():J(a.error||h.toastError)}catch(e){J(e instanceof Error?e.message:h.toastError)}finally{et.current=!1,K(!1)}}},el=async a=>{if(!T.trim())throw Error(h.apiAddress);let t=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"discoverModels",baseUrl:T.trim(),api:"builtin"===e?V?.apis[0]:O,apiKey:z.trim(),providerId:"builtin"===e?V?.id:void 0,allowPrivate:a})}),s=await t.json();if(!t.ok||!s.success)throw Error(s.error||h.toastError);return(s.data.models??[]).map(e=>({id:e.id,name:e.name??""}))};return(0,s.jsx)("div",{className:b().mask,"data-provider-modal":"true",onMouseDown:e=>{e.target===e.currentTarget&&r()},children:(0,s.jsxs)("section",{className:`${b().dialog} ${"builtin"===e?b().builtinDialog:""}`,role:"dialog","aria-modal":"true","aria-labelledby":"provider-setup-title",children:[(0,s.jsxs)("header",{className:b().header,children:[(0,s.jsx)("h2",{id:"provider-setup-title",className:b().title,children:"builtin"===e?h.addProvider:h.customProviderTitle}),(0,s.jsx)("button",{className:"icon-btn",title:h.close,"aria-label":h.close,onClick:r,children:(0,s.jsx)(n.Bh,{size:17})})]}),(0,s.jsxs)("div",{className:`${b().body} ${"builtin"===e?b().builtinBody:""}`,children:["builtin"===e?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.providerLabel}),(0,s.jsxs)("div",{className:b().picker,ref:q,children:[(0,s.jsxs)("button",{className:b().providerTrigger,"data-open":j,onClick:()=>S(e=>!e),children:[V?(0,s.jsx)(p,{id:V.id,name:V.name,size:34}):null,(0,s.jsxs)("span",{className:b().providerText,children:[(0,s.jsx)("span",{className:b().providerName,children:V?.name??h.selectProvider}),V?(0,s.jsx)("span",{className:b().providerMeta,children:V.id}):null]}),(0,s.jsx)(n.Cd,{size:15})]}),j?(0,s.jsxs)("div",{className:b().menu,children:[(0,s.jsxs)("div",{className:b().searchWrap,children:[(0,s.jsx)("span",{className:b().searchIcon,children:(0,s.jsx)(n.FG,{size:15})}),(0,s.jsx)("input",{autoFocus:!0,className:b().search,value:N,onChange:e=>k(e.target.value),placeholder:h.searchProviders})]}),(0,s.jsxs)("div",{className:b().providerList,children:[Z.map(e=>(0,s.jsxs)("button",{className:b().providerRow,"data-selected":e.id===f,onClick:()=>{g(e.id),C("api_key"),P(""),U(e.apis[0]??"openai-completions"),R(""),I([]),S(!1)},children:[(0,s.jsx)(p,{id:e.id,name:e.name,size:38}),(0,s.jsxs)("span",{className:b().providerText,children:[(0,s.jsx)("span",{className:b().providerName,children:e.name}),(0,s.jsxs)("span",{className:b().providerMeta,children:[e.id," \xb7 ",h.modelCount.replace("{count}",String(e.modelCount))]})]}),e.id===f?(0,s.jsx)("span",{className:b().selectedMark,children:(0,s.jsx)(n.df,{size:16})}):null]},e.id)),0===Z.length?(0,s.jsx)("div",{className:b().empty,children:h.noProviderMatches}):null]})]}):null]})]}),V?.authTypes.includes("oauth")&&c?(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.authMethod}),(0,s.jsxs)("select",{className:b().select,value:_,onChange:e=>C(e.target.value),children:[(0,s.jsx)("option",{value:"api_key",children:h.authMethodApiKey}),(0,s.jsx)("option",{value:"oauth",children:h.oauthLogin})]})]}):null,"api_key"===_?(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:V?.apiKeyLabel??h.apiKey}),(0,s.jsx)("input",{className:b().input,type:"password",value:z,onChange:e=>P(e.target.value),placeholder:h.apiKeyOptional})]}):null,(0,s.jsxs)("div",{className:b().advanced,children:[(0,s.jsxs)("button",{className:b().advancedButton,"data-open":M,onClick:()=>E(e=>!e),children:[(0,s.jsx)(n.Cd,{size:15}),h.customSettings]}),M?(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.apiAddress}),(0,s.jsx)("input",{className:b().input,value:T,onChange:e=>R(e.target.value),placeholder:V?.baseUrl||h.providerDefault})]}),(0,s.jsx)(w,{models:A,setModels:I,updateModel:X,inheritedCount:V?.modelCount??0,discover:el,discoverDisabled:!T.trim()})]}):null]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.providerId}),(0,s.jsx)("input",{className:b().input,autoFocus:!0,value:$,onChange:e=>D(e.target.value.toLocaleLowerCase()),placeholder:"acme-gateway"}),(0,s.jsx)("div",{className:b().hint,children:h.providerIdHint}),Q&&!Y?(0,s.jsx)("div",{className:b().hint,style:{color:"var(--dsw-danger)"},children:h.providerIdInvalid}):null,Q&&t.includes(Q)?(0,s.jsx)("div",{className:b().hint,style:{color:"var(--dsw-danger)"},children:h.providerIdTaken}):null]}),(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.displayName}),(0,s.jsx)("input",{className:b().input,value:L,onChange:e=>F(e.target.value),placeholder:h.displayName})]}),(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.apiAddress}),(0,s.jsx)("input",{className:b().input,value:T,onChange:e=>R(e.target.value),placeholder:"https://gateway.example/v1"})]}),(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.apiProtocol}),(0,s.jsx)("select",{className:b().select,value:O,onChange:e=>U(e.target.value),children:W.map(e=>(0,s.jsx)("option",{value:e,children:e},e))})]}),(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.apiKey}),(0,s.jsx)("input",{className:b().input,type:"password",value:z,onChange:e=>P(e.target.value),placeholder:h.apiKeyOptional}),(0,s.jsx)("div",{className:b().hint,children:h.customApiKeyHint})]}),(0,s.jsx)(w,{models:A,setModels:I,updateModel:X,discover:el,discoverDisabled:!T.trim()})]}),H?(0,s.jsx)("div",{className:b().error,children:H}):null]}),(0,s.jsxs)("footer",{className:b().footer,children:[(0,s.jsx)("button",{className:b().footerButton,onClick:r,children:h.cancel}),(0,s.jsx)("button",{className:`${b().footerButton} ${b().primary}`,disabled:B||("builtin"===e?!ea:!ee),onClick:es,children:B?h.saving:"builtin"===e?h.save:h.createProvider})]})]})})}function w({models:e,setModels:a,updateModel:t,inheritedCount:r,discover:i,discoverDisabled:o}){let{t:d}=(0,m.s)(),[c,u]=(0,l.useState)(new Set),[p,h]=(0,l.useState)(!1),[v,f]=(0,l.useState)(""),[g,y]=(0,l.useState)(!1),[j,S]=(0,l.useState)(null),[N,k]=(0,l.useState)(new Set),[_,C]=(0,l.useState)({}),z=(e,a,t)=>{var s;return _[`${a}:${t}`]??(void 0===(s=e[t])||!Number.isFinite(s)||s<=0?"":s>=1e6&&s%1e6==0?`${s/1e6}M`:s>=1e3&&s%1e3==0?`${s/1e3}K`:String(s))},P=(e,a,s)=>{C(t=>({...t,[`${e}:${a}`]:s})),t(e,{[a]:function(e){let a=e.trim().toLowerCase();if(!a)return;let t=/^(\d+(?:\.\d+)?)\s*([km]?)$/.exec(a);if(!t)return NaN;let s=Math.round(Number(t[1])*("k"===t[2]?1e3:"m"===t[2]?1e6:1));return Number.isSafeInteger(s)&&s>0?s:NaN}(s)})},M=async()=>{if(i&&!p){h(!0),f("");try{let a=await i(g);if(!a.length)return void f(d.discoverEmpty);let t=new Set(e.map(e=>e.id.trim()).filter(Boolean));S(a),k(new Set(a.filter(e=>!t.has(e.id.trim())).map(e=>e.id)))}catch(e){f(e instanceof Error?e.message:d.toastError)}finally{h(!1)}}},E=()=>{S(null),k(new Set)},T=j??[],R=T.length>0&&T.every(e=>N.has(e.id)),$=x(e);return(0,s.jsxs)("div",{className:b().catalog,children:[(0,s.jsxs)("div",{className:b().catalogHeader,children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:b().label,children:d.modelCatalog}),(0,s.jsx)("div",{className:b().catalogStatus,children:r?d.usingDefaultModels.replace("{count}",String(r)):d.customModelsRequired})]}),i?(0,s.jsxs)("div",{className:b().discoverControls,children:[(0,s.jsxs)("label",{className:b().allowPrivate,title:d.allowPrivateHint,children:[(0,s.jsx)("input",{type:"checkbox",checked:g,onChange:e=>y(e.target.checked)}),d.allowPrivateDiscovery]}),(0,s.jsx)("button",{className:b().discoverButton,disabled:o||p,onClick:()=>void M(),children:p?d.discoveringModels:d.discoverModels})]}):null]}),v?(0,s.jsx)("div",{className:b().catalogError,children:v}):null,e.length?(0,s.jsx)("div",{className:b().modelList,children:e.map((e,l)=>{let r=c.has(l),i=Number.isNaN(e.contextWindow)||Number.isNaN(e.maxTokens);return(0,s.jsxs)("div",{className:b().modelEntry,children:[(0,s.jsxs)("div",{className:b().modelRow,children:[(0,s.jsx)("button",{type:"button",className:b().rowToggle,title:d.capacityFields,onClick:()=>u(e=>{let a=new Set(e);return a.delete(l)||a.add(l),a}),children:(0,s.jsx)(n.Cd,{size:13,style:{transform:r?"rotate(0deg)":"rotate(-90deg)",transition:"transform 120ms ease"}})}),(0,s.jsx)("input",{className:b().input,style:{borderColor:e.id.trim()||$?.index!==l?void 0:"var(--dsw-danger)"},value:e.id,onChange:e=>t(l,{id:e.target.value}),placeholder:d.modelId}),(0,s.jsx)("input",{className:b().input,value:e.name,onChange:e=>t(l,{name:e.target.value}),placeholder:d.displayNameOptional}),(0,s.jsx)("button",{className:b().removeModel,title:d.delete,onClick:()=>{a(e=>e.filter((e,a)=>a!==l)),u(e=>{let a=new Set;for(let t of e)t!==l&&a.add(t>l?t-1:t);return a}),C(e=>{let a={};for(let[t,s]of Object.entries(e)){let e=Number(t.slice(0,t.indexOf(":")));e!==l&&(a[e>l?`${e-1}${t.slice(t.indexOf(":"))}`:t]=s)}return a})},children:(0,s.jsx)(n.Vd,{size:15})})]}),r?(0,s.jsxs)("div",{className:b().capacityRow,children:[(0,s.jsxs)("label",{className:b().capacityField,children:[(0,s.jsx)("span",{children:d.contextWindowLabel}),(0,s.jsx)("input",{className:b().input,style:{borderColor:Number.isNaN(e.contextWindow)?"var(--dsw-danger)":void 0},value:z(e,l,"contextWindow"),onChange:e=>P(l,"contextWindow",e.target.value),placeholder:"128K"})]}),(0,s.jsxs)("label",{className:b().capacityField,children:[(0,s.jsx)("span",{children:d.maxTokensLabel}),(0,s.jsx)("input",{className:b().input,style:{borderColor:Number.isNaN(e.maxTokens)?"var(--dsw-danger)":void 0},value:z(e,l,"maxTokens"),onChange:e=>P(l,"maxTokens",e.target.value),placeholder:"16K"})]}),(0,s.jsx)("span",{className:b().capacityHint,children:d.capacityHint})]}):null,i?(0,s.jsx)("div",{className:b().rowError,children:d.capacityInvalid.replace("{n}",String(l+1))}):null]},l)})}):(0,s.jsx)("div",{className:b().modelEmpty,children:r?d.modelCatalogEmptyBuiltin:d.modelCatalogEmptyCustom}),(0,s.jsxs)("button",{className:b().addModel,onClick:()=>a(e=>[...e,{id:"",name:""}]),children:[(0,s.jsx)(n.Xh,{size:14}),d.addModel]}),j?(0,s.jsx)("div",{className:b().candidateMask,children:(0,s.jsxs)("div",{className:b().candidateDialog,role:"dialog","aria-modal":"true","aria-label":d.discoverModels,children:[(0,s.jsx)("div",{className:b().candidateHeader,children:(0,s.jsx)("span",{children:d.candidateTitle.replace("{count}",String(j.length))})}),(0,s.jsxs)("div",{className:b().candidateList,children:[T.map(e=>(0,s.jsxs)("label",{className:b().candidateRow,children:[(0,s.jsx)("input",{type:"checkbox",checked:N.has(e.id),onChange:()=>{let a;return a=e.id,k(e=>{let t=new Set(e);return t.delete(a)||t.add(a),t})}}),(0,s.jsx)("span",{className:b().candidateId,children:e.id}),e.name?(0,s.jsx)("span",{className:b().candidateName,children:e.name}):null]},e.id)),0===T.length?(0,s.jsx)("div",{className:b().modelEmpty,children:"—"}):null]}),(0,s.jsxs)("div",{className:b().candidateActions,children:[(0,s.jsxs)("label",{className:b().candidateAll,children:[(0,s.jsx)("input",{type:"checkbox",checked:R,onChange:()=>k(e=>{let a=new Set(e);return T.every(e=>a.has(e.id))?T.forEach(e=>a.delete(e.id)):T.forEach(e=>a.add(e.id)),a})}),d.candidateAll]}),(0,s.jsx)("span",{className:b().candidatePicked,children:d.candidatePicked.replace("{n}",String(N.size))}),(0,s.jsx)("button",{className:b().footerButton,onClick:E,children:d.cancel}),(0,s.jsx)("button",{className:`${b().footerButton} ${b().primary}`,disabled:0===N.size,onClick:()=>{j&&(a(e=>{let a=new Map(e.map(e=>[e.id.trim(),e]));for(let e of j){let t=e.id.trim();!t||!N.has(t)||a.has(t)||a.set(t,{id:t,name:e.name??""})}return[...a.values()]}),E())},children:d.candidateAdopt.replace("{n}",String(N.size))})]})]})}):null]})}function j({tone:e}){return(0,s.jsx)("span",{className:"inline-block h-[7px] w-[7px] flex-none rounded-full",style:{background:"on"===e?"var(--dsw-success)":"pending"===e?"var(--dsw-accent)":"var(--dsw-label-caption)"}})}function S({title:e,hint:a,children:t}){return(0,s.jsxs)("div",{className:"hairline-b flex flex-wrap items-start justify-between gap-4 pb-5",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",style:{minWidth:"45%"},children:[(0,s.jsx)("div",{style:{fontSize:14},children:e}),a?(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-label-caption)",lineHeight:1.55,marginTop:2},children:a}):null]}),(0,s.jsx)("div",{className:"flex-none",children:t})]})}function N(){let{t:e}=(0,m.s)(),[a,t]=(0,l.useState)(null),[r,i]=(0,l.useState)(!1),[n,o]=(0,l.useState)(""),d=(0,l.useRef)(!0),c=(0,l.useCallback)(async()=>{try{let a=await fetch("/api/remote",{cache:"no-store"}),s=await a.json();if(!d.current)return;s?.success?(t(s.data),o("")):o(s?.error??e.remoteFailed)}catch{d.current&&o(e.remoteFailed)}},[e]);(0,l.useEffect)(()=>(d.current=!0,c(),()=>{d.current=!1}),[c]);let u=!!(a?.public.running&&!a.public.ready);(0,l.useEffect)(()=>{if(!u)return;let e=setInterval(()=>void c(),2500);return()=>clearInterval(e)},[u,c]);let p=async a=>{if(!r){i(!0),o("");try{let s=await fetch("/api/remote",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:a})}),l=await s.json();l?.success?t(l.data):o(l?.error??e.remoteFailed)}catch{o(e.remoteFailed)}finally{d.current&&i(!1)}}},[h,x]=(0,l.useState)(!1);(0,l.useEffect)(()=>{if(!h)return;let e=setTimeout(()=>x(!1),4e3);return()=>clearTimeout(e)},[h]);let v=async()=>{if(!h)return void x(!0);x(!1),o("");try{let a=await fetch("/api/web-auth?scope=all",{method:"DELETE"}),t=await a.json().catch(()=>null);if(!a.ok||!t?.success)throw Error(t?.error??e.remoteFailed);window.location.href="/login"}catch(a){d.current&&o(a instanceof Error?a.message:e.remoteFailed)}},f=a?.lan,g=a?.public,b=a?.blocked??null,y=f?.running?"on":"off",w=g?.running?g.ready?"on":"pending":"off";return(0,s.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,s.jsx)("div",{style:{fontSize:15,fontWeight:500},children:e.setRemote}),(0,s.jsx)("span",{className:"rounded-md px-2 py-[2px]",style:{fontSize:11,background:"var(--dsw-hover)",color:"var(--dsw-label-secondary)"},children:e.remoteBuiltin})]}),(0,s.jsx)(S,{title:e.remoteLanTitle,hint:e.remoteLanHint,children:(0,s.jsxs)("div",{className:"flex flex-col items-end gap-1.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",style:{fontSize:13},children:[(0,s.jsx)(j,{tone:y}),(0,s.jsx)("span",{style:{color:f?.running?"var(--dsw-label-primary)":"var(--dsw-label-caption)"},children:f?.running?e.remoteRunning:e.remoteStopped})]}),(f?.urls??[]).map(e=>(0,s.jsx)("a",{href:e,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline",style:{fontSize:12},children:e},e)),f?.error?(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-danger)"},children:f.error}):null]})}),(0,s.jsx)(S,{title:e.remotePublicTitle,hint:e.remotePublicHint,children:(0,s.jsxs)("div",{className:"flex flex-col items-end gap-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",style:{fontSize:13},children:[(0,s.jsx)(j,{tone:w}),(0,s.jsx)("span",{style:{color:g?.running?"var(--dsw-label-primary)":"var(--dsw-label-caption)"},children:g?.running?g.ready?e.remoteRunning:e.remotePending:e.remoteStopped})]}),g?.url?(0,s.jsx)("a",{href:g.url,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline",style:{fontSize:12},children:g.url}):null,(0,s.jsx)("div",{className:"flex items-center gap-2",children:g?.running?(0,s.jsx)("button",{className:"btn-outline",style:{height:30,fontSize:13},disabled:r,onClick:()=>void p("stop"),children:e.remoteStop}):(0,s.jsx)("button",{className:"btn-primary-white",style:{height:30,fontSize:13},disabled:r||null!==b,onClick:()=>void p("start"),children:r?e.remoteWorking:e.remoteStart})})]})}),a&&"auth"!==b?(0,s.jsx)(S,{title:e.remoteSessionsTitle,hint:e.remoteSessionsHint,children:(0,s.jsx)("button",{className:"btn-outline",style:{height:30,fontSize:13,color:h?"var(--dsw-danger)":void 0},onClick:()=>void v(),children:h?e.remoteSignOutAllConfirm:e.remoteSignOutAll})}):null,b?(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-label-secondary)",lineHeight:1.6},children:"auth"===b?e.remoteBlockedAuth:e.remoteBlockedDev}):null,g&&!g.engineAvailable?(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-danger)",lineHeight:1.6},children:e.remoteEngineMissing}):null,g?.error?(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-danger)",lineHeight:1.6},children:g.error}):null,n?(0,s.jsx)("div",{role:"alert",style:{fontSize:12,color:"var(--dsw-danger)"},children:n}):null]})}var k=t(6540),_=t(922);let C=["xai","openai-codex","anthropic","deepseek","openrouter","moonshotai","moonshotai-cn","kimi-coding","github-copilot","vercel-ai-gateway","opencode-go"];function z(e){return C.includes(e)}function P({open:e,onClose:a,cwd:t,toolPreset:r,onToolPresetChange:i,tools:o,onSetTools:d,onOpenFileContent:c}){let{t:u,lang:p,setLang:h}=(0,m.s)(),[x,v]=(0,l.useState)("general");if((0,l.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"!==e.key||document.querySelector('[data-provider-modal="true"]')||a()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,a]),!e)return null;let f=[{id:"general",label:u.setGeneral,icon:(0,s.jsx)(n.Ec,{size:15})},{id:"models",label:u.setModels,icon:(0,s.jsx)(n.se,{size:15})},{id:"tools",label:u.toolsSection,icon:(0,s.jsx)(n.DI,{size:15})},{id:"plugins",label:u.setPlugins,icon:(0,s.jsx)(n.q2,{size:15})},{id:"skills",label:u.setSkills,icon:(0,s.jsx)(n.i7,{size:15})},{id:"remote",label:u.setRemote,icon:(0,s.jsx)(n.an,{size:15})}];return(0,s.jsx)("div",{className:"modal-mask fixed inset-0 z-[100] flex items-center justify-center",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,s.jsxs)("div",{className:"settings-dialog glass-modal flex overflow-hidden",style:{width:800,maxWidth:"calc(100vw - 48px)",height:"min(800px, calc(100vh - 48px))",borderRadius:32,boxShadow:"var(--dsw-elevation-prominent)"},children:[(0,s.jsxs)("div",{className:"settings-nav flex w-52 flex-none flex-col gap-0.5 py-4 pl-4 pr-3",children:[(0,s.jsx)("div",{className:"settings-title px-2 pb-3",style:{fontSize:16,fontWeight:500},children:u.settings}),f.map(e=>(0,s.jsxs)("button",{className:"flex h-[42px] items-center gap-2 rounded-xl px-3 text-left transition-colors",style:{paddingLeft:8,paddingRight:10,fontSize:14,background:x===e.id?"var(--dsw-active)":"transparent",color:x===e.id?"var(--dsw-label-primary)":"var(--dsw-label-secondary)"},onMouseEnter:a=>{x!==e.id&&(a.currentTarget.style.background="var(--dsw-hover)")},onMouseLeave:a=>{x!==e.id&&(a.currentTarget.style.background="transparent")},onClick:()=>v(e.id),children:[x===e.id?(0,s.jsx)("span",{style:{color:"var(--dsw-accent)"},children:e.icon}):e.icon,e.label]},e.id))]}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 px-6 py-3.5",children:[(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsxs)("button",{className:"btn-outline",style:{height:32,fontSize:13},onClick:()=>window.open("/api/config","_blank"),children:[(0,s.jsx)(n.FQ,{size:14})," ",u.openConfigFile]}),(0,s.jsx)("button",{className:"icon-btn",onClick:a,children:(0,s.jsx)(n.Bh,{size:15})})]}),(0,s.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5",children:["general"===x&&(0,s.jsx)(M,{lang:p,setLang:h}),"models"===x&&(0,s.jsx)(W,{}),"skills"===x&&(0,s.jsx)(H,{cwd:t,onOpenFileContent:c}),"tools"===x&&(0,s.jsx)(K,{toolPreset:r,onToolPresetChange:i,tools:o,onSetTools:d}),"plugins"===x&&(0,s.jsx)(J,{cwd:t}),"remote"===x&&(0,s.jsx)(N,{})]})]})]})})}function M({lang:e,setLang:a}){let{t}=(0,m.s)(),[r,n]=(0,l.useState)("dsh"),[o,d]=(0,l.useState)("system"),[c,u]=(0,l.useState)(14),[p,h]=(0,l.useState)(14),[x,v]=(0,l.useState)("steer"),[f,g]=(0,l.useState)(null),[b,y]=(0,l.useState)(null),[w,j]=(0,l.useState)(null),[S,N]=(0,l.useState)(!0),[_,C]=(0,l.useState)(!1),[z,P]=(0,l.useState)(null),[W,O]=(0,l.useState)({reserveTokens:"",keepRecentTokens:"",maxRetries:"",baseDelayMs:""}),U=async()=>{N(!0),P(null);let e=async e=>{let a=await fetch(e),t=await a.json();if(!a.ok||!t.success)throw Error(t.error||`request failed (${a.status})`);return t.data},[a,t,s,l]=await Promise.allSettled([e("/api/security"),e("/api/pi-settings"),e("/api/version"),e("/api/web-auth")]);"fulfilled"===t.status?(g(t.value),O({reserveTokens:String(t.value.compaction.reserveTokens),keepRecentTokens:String(t.value.compaction.keepRecentTokens),maxRetries:String(t.value.retry.maxRetries),baseDelayMs:String(t.value.retry.baseDelayMs)})):g(null),"fulfilled"===s.status&&s.value?.piWeb?y({piWeb:s.value.piWeb,piEngine:s.value.piEngine}):y(null),"fulfilled"===l.status&&"boolean"==typeof l.value?.enabled?j({enabled:l.value.enabled,authenticated:!0===l.value.authenticated}):j(null),[a,t,s].some(e=>"rejected"===e.status)&&P("load"),N(!1)};(0,l.useEffect)(()=>{n((0,k.m6)()),d((0,k.Xf)());let e=parseInt(localStorage.getItem("piweb.fontSize")??"14",10);Number.isNaN(e)||u(e);let a=parseInt(localStorage.getItem("piweb.chatFontSize")??"14",10);Number.isNaN(a)||h(a),v((0,i.$h)()),U()},[]);let A=async e=>{if(!f||_)return!1;C(!0),P(null);try{let a=await fetch("/api/pi-settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),t=await a.json();if(!a.ok||!t.success)throw Error(t.error||"save failed");return g(t.data),!0}catch{return P("save"),!1}finally{C(!1)}},I=async(e,a)=>{if(!f)return;let t=W[a].trim(),s=Number(t);!t||!Number.isSafeInteger(s)||s<0||s>1e9?P("save"):s!==f[e][a]&&await A({[e]:{[a]:s}})},B=(e,a,t)=>(0,s.jsx)("input",{type:"number",min:0,value:W[a],disabled:!f||S||_,onChange:e=>O(t=>({...t,[a]:e.target.value})),onBlur:()=>void I(e,a),onKeyDown:e=>{"Enter"===e.key&&e.currentTarget.blur()},className:"rounded-lg px-2 py-1",title:t,style:{width:90,textAlign:"right",background:"var(--dsw-hover)"}}),K=[{id:"dsh",label:t.themeDsh,light:"#F9FAFB",dark:"#151517",accent:"#4176E6"},{id:"silver-steel",label:t.themeSilverSteel,light:"#F3F4F6",dark:"#1A1C24",accent:"#94A3B8"},{id:"limestone-coal",label:t.themeLimestoneCoal,light:"#F0EFEB",dark:"#171717",accent:"#CEB27E"},{id:"linen-moss",label:t.themeLinenMoss,light:"#F2F2EC",dark:"#1E211E",accent:"#A3B3A3"},{id:"nord-paper",label:t.themeNordPaper,light:"#FCFBF9",dark:"#2E3440",accent:"#88C0D0"},{id:"pebrel",label:t.themePebrel,light:"#F3F4F6",dark:"#0F111A",accent:"#52A8FF"}];return(0,s.jsxs)("div",{className:"flex flex-col gap-6",children:[(S||z)&&(0,s.jsxs)("div",{role:z?"alert":"status",className:"flex items-center gap-3 rounded-lg px-3 py-2",style:{background:"var(--dsw-hover)",color:z?"var(--dsw-danger)":"var(--dsw-label-secondary)"},children:[(0,s.jsx)("span",{className:"flex-1",children:"load"===z?t.settingsLoadFailed:"save"===z?t.settingsSaveFailed:t.settingsLoading}),"load"===z&&(0,s.jsx)("button",{type:"button",className:"pw-chip",onClick:()=>void U(),children:t.settingsRetry})]}),(0,s.jsx)($,{title:t.language,children:(0,s.jsx)(R,{value:e,options:[{value:"zh",label:"中文"},{value:"en",label:"English"}],onChange:e=>a(e)})}),(0,s.jsx)(D,{title:t.appearance,children:(0,s.jsx)("div",{className:"flex w-full flex-wrap gap-2",children:K.map(e=>(0,s.jsxs)("button",{className:"flex flex-col items-center justify-center gap-1 transition-colors",style:{flex:"1 1 150px",padding:"20px 32px",borderRadius:20,border:`0.5px solid ${r===e.id?"var(--dsw-border-strong)":"var(--dsw-border-l4)"}`,background:r===e.id?"var(--dsw-module-platform)":"transparent",color:"var(--dsw-label-primary)",fontSize:14,lineHeight:"22px"},"aria-pressed":r===e.id,onClick:()=>{var a;n(a=e.id),(0,k.kK)(a,o)},children:[(0,s.jsxs)("span",{className:"flex items-center overflow-hidden rounded-md",style:{border:"0.5px solid var(--dsw-border-l3)",width:42,height:20},children:[(0,s.jsx)("span",{style:{background:e.light,flex:1,height:"100%"}}),(0,s.jsx)("span",{style:{background:e.dark,flex:1,height:"100%"}})]}),(0,s.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:"inline-block rounded-full",style:{width:8,height:8,background:e.accent}}),e.label]})]},e.id))})}),(0,s.jsx)(D,{title:t.appearanceMode,children:(0,s.jsx)("div",{className:"flex w-full flex-wrap gap-2",children:[{id:"light",label:t.themeLight},{id:"dark",label:t.themeDark},{id:"system",label:t.themeSystem}].map(e=>(0,s.jsx)("button",{className:"flex flex-col items-center justify-center gap-1 transition-colors",style:{flex:"1 1 120px",padding:"16px 24px",borderRadius:20,border:`0.5px solid ${o===e.id?"var(--dsw-border-strong)":"var(--dsw-border-l4)"}`,background:o===e.id?"var(--dsw-module-platform)":"transparent",color:"var(--dsw-label-primary)",fontSize:14,lineHeight:"22px"},"aria-pressed":o===e.id,onClick:()=>{var a;d(a=e.id),(0,k.kK)(r,a)},children:e.label},e.id))})}),(0,s.jsx)($,{title:t.fontUiSize,desc:t.fontUiSizeDesc,children:(0,s.jsx)(L,{value:c,onChange:e=>{let a=Math.max(12,Math.min(18,e));u(a),localStorage.setItem("piweb.fontSize",String(a)),document.documentElement.style.setProperty("--dsh-content-font-size",`${a}px`),document.documentElement.style.setProperty("--dsh-content-font-delta",`${a-14}px`)},max:18})}),(0,s.jsx)($,{title:t.fontChatSize,desc:t.fontChatSizeDesc,children:(0,s.jsx)(L,{value:p,onChange:e=>{let a=Math.max(12,Math.min(20,e));h(a),localStorage.setItem("piweb.chatFontSize",String(a)),document.documentElement.style.setProperty("--piweb-chat-font-size",`${a}px`)},max:20})}),(0,s.jsx)($,{title:t.fontUiFamily,desc:t.fontUiFamilyDesc,children:(0,s.jsx)(F,{scope:"ui"})}),(0,s.jsx)($,{title:t.fontMonoFamily,desc:t.fontMonoFamilyDesc,children:(0,s.jsx)(F,{scope:"mono"})}),(0,s.jsx)($,{title:t.enterBehavior,desc:t.enterBehaviorDesc,children:(0,s.jsx)(R,{value:x,options:[{value:"steer",label:t.enterSteer},{value:"queue",label:t.enterQueue}],onChange:e=>{v(e),(0,i.vf)(e)}})}),(0,s.jsx)($,{title:t.autoCompact,desc:t.autoCompactDesc,children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("button",{disabled:!f||_,className:"relative h-5 w-9 flex-none rounded-full transition-colors",style:{background:f?.compaction.enabled?"var(--dsw-accent)":"var(--dsw-border-l3)"},role:"switch","aria-checked":f?.compaction.enabled??!1,onClick:()=>void A({compaction:{enabled:!f?.compaction.enabled}}),children:(0,s.jsx)("span",{className:"absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all",style:{left:f?.compaction.enabled?18:2}})}),B("compaction","reserveTokens",t.reserveTokens),B("compaction","keepRecentTokens",t.keepRecentTokens)]})}),(0,s.jsx)($,{title:t.autoRetry,desc:t.autoRetryDesc,children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("button",{disabled:!f||_,className:"relative h-5 w-9 flex-none rounded-full transition-colors",style:{background:f?.retry.enabled?"var(--dsw-accent)":"var(--dsw-border-l3)"},role:"switch","aria-checked":f?.retry.enabled??!1,onClick:()=>void A({retry:{enabled:!f?.retry.enabled}}),children:(0,s.jsx)("span",{className:"absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all",style:{left:f?.retry.enabled?18:2}})}),B("retry","maxRetries",t.maxRetries),B("retry","baseDelayMs",t.baseDelayMs)]})}),(0,s.jsx)($,{title:t.versionPiweb,desc:t.versionPiwebDesc,children:(0,s.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,s.jsx)(E,{href:"https://github.com/RexVane/PiWeb",value:b?.piWeb}),(0,s.jsx)(T,{target:"piweb"})]})}),(0,s.jsx)($,{title:t.versionPi,desc:t.versionPiDesc,children:(0,s.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,s.jsx)(E,{href:"https://github.com/earendil-works/pi",value:b?.piEngine}),(0,s.jsx)(T,{target:"pi"})]})}),w?.enabled?(0,s.jsx)($,{title:t.webAuth,desc:t.webAuthTokenOn,children:(0,s.jsx)("button",{className:"btn-outline",style:{height:30,padding:"0 14px",fontSize:12.5},onClick:async()=>{await fetch("/api/web-auth",{method:"DELETE"}).catch(()=>{}),window.location.href="/login"},children:t.logout})}):null]})}function E({href:e,value:a}){return(0,s.jsx)("a",{href:e,target:"_blank",rel:"noreferrer",style:{fontFamily:"var(--font-mono)",fontSize:13,color:"var(--dsw-label-secondary)",textDecoration:"none"},onMouseEnter:e=>e.currentTarget.style.color="var(--dsw-accent)",onMouseLeave:e=>e.currentTarget.style.color="var(--dsw-label-secondary)",children:a??"—"})}function T({target:e}){let{t:a}=(0,m.s)(),[t,r]=(0,l.useState)("idle"),[i,n]=(0,l.useState)(""),[o,d]=(0,l.useState)(""),[c,u]=(0,l.useState)(""),p=async a=>(await fetch("/api/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:e,action:a})})).json(),h=async()=>{r("checking"),u("");try{let e=await p("check");if(!e.success)throw Error(e.error);e.data.canUpdate?(n(e.data.latest),d(e.data.command??""),r("available")):r("latest")}catch(e){u(String(e?.message??e)),r("error")}},x=async()=>{r("updating");try{let e=await p("update");if(!e.success)throw Error(e.error);n(e.data.version??i),r("updated")}catch(e){u(String(e?.message??e)),r("error")}};if("idle"===t||"latest"===t||"error"===t){let e="latest"===t?a.upToDate:"error"===t?a.updateFailed:a.checkUpdate;return(0,s.jsx)("button",{type:"button",className:"btn-outline",style:{height:26,padding:"0 10px",fontSize:12,color:"latest"===t?"var(--dsw-label-tertiary)":"error"===t?"var(--dsw-danger)":"var(--dsw-label-primary)"},title:c||void 0,disabled:"checking"===t||"updating"===t,onClick:()=>void h(),children:e})}return"available"===t?o?(0,s.jsxs)("span",{className:"flex flex-col items-end gap-0.5",style:{maxWidth:300},children:[(0,s.jsx)("code",{style:{fontSize:11,color:"var(--dsw-label-primary)",whiteSpace:"nowrap",overflowX:"auto",maxWidth:"100%"},children:o}),(0,s.jsx)("span",{style:{fontSize:11,color:"var(--dsw-label-tertiary)",textAlign:"right"},children:a.updateManualHint})]}):(0,s.jsx)("button",{type:"button",className:"btn-primary-white",style:{height:26,padding:"0 12px",fontSize:12},onClick:()=>void x(),children:a.updateTo.replace("{v}",i)}):"updated"===t?(0,s.jsx)("span",{style:{fontSize:12,color:"var(--dsw-success)",maxWidth:260,textAlign:"right"},children:a.updatedTo.replace("{v}",i)}):(0,s.jsxs)("span",{className:"flex items-center gap-1.5",style:{fontSize:12,color:"var(--dsw-label-tertiary)"},children:[(0,s.jsx)("span",{className:"h-3 w-3 flex-none animate-spin rounded-full border-2 border-current border-t-transparent"}),"updating"===t?a.updatingNow:a.checkingUpdate]})}function R({value:e,options:a,onChange:t,width:i,disabled:o}){let[d,c]=(0,l.useState)(!1),[u,p]=(0,l.useState)(null),m=(0,l.useRef)(null),h=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(!d)return;let e=m.current?.getBoundingClientRect();e&&p({left:e.left,top:e.bottom+6,bottom:e.top-6});let a=e=>{m.current?.contains(e.target)||h.current?.contains(e.target)||c(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[d]),(0,l.useEffect)(()=>{o&&c(!1)},[o]);let x=a.find(a=>a.value===e);return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsxs)("button",{ref:m,className:"select-chip","data-open":d,disabled:o,onClick:()=>c(e=>!e),children:[x?.label??e,(0,s.jsx)("span",{className:"chevron",children:(0,s.jsx)(n.Cd,{size:14})})]}),d&&!o&&u&&(0,r.createPortal)((0,s.jsx)("div",{ref:h,className:"popover fixed z-[130] p-1.5 shadow-xl",style:{left:u.left,top:Math.min(u.top,window.innerHeight-40),minWidth:i??140,width:"max-content",maxHeight:280,overflowY:"auto"},children:a.map(a=>{let l=a.value===e;return(0,s.jsxs)("button",{className:"flex w-full items-center justify-between gap-3 rounded-xl px-3.5 py-2 text-left transition-colors",style:{background:l?"var(--dsw-accent-soft)":"transparent"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--dsw-hover)")},onMouseLeave:e=>{l||(e.currentTarget.style.background="transparent")},onClick:()=>{t(a.value),c(!1)},children:[(0,s.jsx)("span",{style:{fontSize:13.5,color:l?"var(--dsw-accent)":"var(--dsw-label-primary)",whiteSpace:"nowrap"},children:a.label}),l&&(0,s.jsx)("span",{style:{display:"inline-flex",color:"var(--dsw-accent)",flex:"none"},children:(0,s.jsx)(n.df,{size:14})})]},a.value)})}),document.body)]})}function $({title:e,desc:a,children:t}){return(0,s.jsxs)("div",{className:"hairline-b flex items-center justify-between gap-6 pb-5",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("div",{style:{fontSize:14,fontWeight:400},children:e}),a&&(0,s.jsx)("div",{className:"mt-0.5",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:a})]}),(0,s.jsx)("div",{className:"flex-none",children:t})]})}function D({title:e,desc:a,children:t}){return(0,s.jsxs)("div",{className:"hairline-b flex flex-col gap-3 pb-5",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{style:{fontSize:14,fontWeight:400},children:e}),a&&(0,s.jsx)("div",{className:"mt-0.5",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:a})]}),t]})}function L({value:e,onChange:a,max:t}){return(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("button",{className:"icon-btn",style:{width:26,height:26,border:"0.5px solid var(--dsw-border-l3)",borderRadius:8},disabled:e<=12,onClick:()=>a(e-1),"aria-label":"decrease font size",children:"−"}),(0,s.jsxs)("button",{style:{minWidth:48,textAlign:"center",fontSize:13,color:14===e?"var(--dsw-label-tertiary)":"var(--dsw-label-primary)"},title:"reset",onClick:()=>a(14),children:[e," px"]}),(0,s.jsx)("button",{className:"icon-btn",style:{width:26,height:26,border:"0.5px solid var(--dsw-border-l3)",borderRadius:8},disabled:e>=t,onClick:()=>a(e+1),"aria-label":"increase font size",children:"+"})]})}function F({scope:e}){let{t:a,lang:t}=(0,m.s)(),[r,i]=(0,l.useState)(null),[n,o]=(0,l.useState)(""),[d,c]=(0,l.useState)(!1);(0,l.useEffect)(()=>{let a=(0,_.ll)(e),t=a?.startsWith(_.D8)?a.slice(_.D8.length):null;i(a),c(null!==t),o(t??"")},[e]);let u=a=>{o(a);let t=a.trim()?_.D8+a.trim():null;i(t),(0,_.di)(e,t)},p=d?_.D8:r??_.Z$[e][0].id;return(0,s.jsxs)("div",{className:"flex flex-col items-end gap-2",children:[(0,s.jsx)(R,{value:p,width:220,options:[..._.Z$[e].map(e=>({value:e.id,label:"zh"===t?e.label.zh:e.label.en})),{value:_.D8,label:a.fontCustom}],onChange:a=>{if(a===_.D8){c(!0),u(n);return}c(!1),i(a),(0,_.di)(e,a)}}),d&&(0,s.jsx)("input",{value:n,onChange:e=>u(e.target.value),placeholder:a.fontCustomPlaceholder,style:{height:30,width:260,padding:"0 10px",fontSize:13,background:"var(--dsw-input-major)",border:"0.5px solid var(--dsw-border-l3)",borderRadius:8,color:"var(--dsw-label-primary)"}})]})}function W(){let{t:e}=(0,m.s)(),[a,t]=(0,l.useState)([]),[r,i]=(0,l.useState)({providers:{}}),[o,d]=(0,l.useState)(null),[c,v]=(0,l.useState)(new Set),[g,b]=(0,l.useState)(null),[j,S]=(0,l.useState)(""),[N,k]=(0,l.useState)(null),[_,C]=(0,l.useState)(""),[P,M]=(0,l.useState)(""),[E,T]=(0,l.useState)("openai-completions"),[$,D]=(0,l.useState)(""),[L,F]=(0,l.useState)([]),[W,B]=(0,l.useState)(""),[K,H]=(0,l.useState)(""),[J,q]=(0,l.useState)([]),[V,Z]=(0,l.useState)(!1),[X,G]=(0,l.useState)(!1),[Q,Y]=(0,l.useState)(null),[ee,ea]=(0,l.useState)(null),[et,es]=(0,l.useState)(null),[el,er]=(0,l.useState)([]),[ei,en]=(0,l.useState)(""),[eo,ed]=(0,l.useState)(null),[ec,eu]=(0,l.useState)(!1),ep=(0,l.useMemo)(()=>{for(let e=el.length-1;e>=0;e--){let a=el[e];if(a.startsWith("{"))try{let e=JSON.parse(a);if("device_code"===e.type&&"string"==typeof e.verificationUri)return{userCode:"string"==typeof e.userCode?e.userCode:"",verificationUri:e.verificationUri,instructions:""};if("auth_url"===e.type&&"string"==typeof e.url)return{userCode:"",verificationUri:e.url,instructions:"string"==typeof e.instructions?e.instructions:""}}catch{}}return null},[el]),em=(0,l.useRef)(null);(0,l.useEffect)(()=>{ep?.verificationUri&&em.current!==ep.verificationUri&&(em.current=ep.verificationUri,window.open(ep.verificationUri,"_blank","noopener"))},[ep]);let eh=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/models?custom=1"),a=await e.json();if(!e.ok||!a.success)throw Error(a.error||"failed to load model configuration");let s=JSON.parse(a.data.customProviders?.content??"{}");if(!s||"object"!=typeof s||Array.isArray(s)||void 0!==s.providers&&(!s.providers||"object"!=typeof s.providers||Array.isArray(s.providers)))throw Error("invalid model configuration");t(a.data.providers),v(new Set(a.data.customProviders?.secretProviderIds??[])),i({...s,providers:s.providers??{}}),d("string"==typeof a.data.customProviders?.revision?a.data.customProviders.revision:null)}catch(e){d(null),Y({ok:!1,msg:e instanceof Error?e.message:"failed to load model configuration"})}},[]);(0,l.useEffect)(()=>{eh()},[eh]),(0,l.useEffect)(()=>{let e;if(!ee)return;let a=!0,t=!1,s=async()=>{try{let e=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"loginState",providerId:ee})}),s=await e.json();if(!a||!s.success)return;es(s.data.prompt),er(s.data.notifyLog??[]),s.data.done&&(t=!0,ed({ok:!s.data.error,msg:s.data.error??ee+" ✓"}),s.data.error||eh())}catch{}finally{a&&!t&&(e=setTimeout(s,1500))}};return s(),()=>{a=!1,e&&clearTimeout(e)}},[ee,eh]);let[ex,ev]=(0,l.useState)(null),[ef,eg]=(0,l.useState)(!1),[eb,ey]=(0,l.useState)(!1),ew=(0,l.useCallback)(async e=>{eg(!0),ey(!1);try{let a=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"providerUsage",providerId:"xai",force:e})}),t=await a.json();if(!a.ok||!t.success)throw Error(t.error||"usage probe failed");ev(t.data.usage??null)}catch{ey(!0)}finally{eg(!1)}},[]),[ej,eS]=(0,l.useState)({}),[eN,ek]=(0,l.useState)(null),[e_,eC]=(0,l.useState)({}),ez=(0,l.useCallback)(async(e,a)=>{ek(e),eC(a=>({...a,[e]:!1}));try{let t=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"providerUsage",providerId:e,force:a})}),s=await t.json();if(!t.ok||!s.success)throw Error(s.error||"usage probe failed");eS(a=>({...a,[e]:s.data.usage??null}))}catch{eC(a=>({...a,[e]:!0}))}finally{ek(a=>a===e?null:a)}},[]),eP=(0,l.useRef)(new Set);(0,l.useEffect)(()=>{for(let e of a)!e.authReady||!z(e.id)||"xai"===e.id||eP.current.has(e.id)||(eP.current.add(e.id),ez(e.id,!1))},[a,ez]);let eM=e=>`${"USD"===e.currency?"$":"CNY"===e.currency?"\xa5":""}${e.amount}${e.currency&&"USD"!==e.currency&&"CNY"!==e.currency?` ${e.currency}`:""}`,eE=(a,t)=>{Y({ok:a,msg:t??(a?e.toastSaved:e.toastError)}),setTimeout(()=>Y(null),2400)},eT=async a=>{try{let e=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),t=await e.json();return e.ok?t:{...t,success:!1,error:t.error||`request failed (${e.status})`}}catch(a){return{success:!1,error:a instanceof Error?a.message:e.toastError}}},eR=async a=>{let t=await eT(a);return eE(t.success,t.success&&t.data?.requiresSessionReopen?e.modelConfigReopen:t.error),t.success&&await eh(),t},e$=async a=>{if(ee)try{let t=await eT({action:"loginAnswer",providerId:ee,text:a});if(!t.success||t.data?.delivered!==!0)throw Error(t.error||e.toastError);en("")}catch(a){eE(!1,a instanceof Error?a.message:e.toastError)}},eD=async()=>{if(ee)try{let a=await eT({action:"loginCancel",providerId:ee});if(!a.success)throw Error(a.error||e.toastError);ea(null)}catch(a){eE(!1,a instanceof Error?a.message:e.toastError)}},eL=new Set(Object.keys(r.providers??{})),eF=a.filter(e=>e.authReady||e.authConfigured||e.keyManaged||eL.has(e.id)),eW=a.filter(e=>e.builtIn&&!eF.some(a=>a.id===e.id)),eO=async e=>{if(null===o){let e={success:!1,error:"Reload model configuration before saving."};return eE(!1,e.error),e}return eR({action:"saveCustomProviders",revision:o,content:JSON.stringify({...r,providers:e},null,2)})},eU=e=>a.find(a=>a.id===e)?.name??e,eA=async()=>{if(!V&&!x(L)&&P.trim()){Z(!0);try{let e={...r.providers},a=g??_.trim(),t=e[a]??{};a!==_.trim()&&delete e[a],e[_.trim()]=f(t,{name:W,baseUrl:P,api:E,apiKey:$,models:L}),(await eO(e)).success&&b(null)}finally{Z(!1)}}},eI=async e=>{if(!V&&!x(J)){Z(!0);try{let a={...r.providers};a[e.id]=f(a[e.id]??{},{baseUrl:K,models:J},e.apis[0]??"openai-completions");let t=await eO(a);t.success&&j.trim()&&(eR({action:"setKey",providerId:e.id,apiKey:j.trim()}),ed(null),ea(e.id)),t.success&&b(null)}finally{Z(!1)}}},eB=async t=>{if(!window.confirm(e.confirmRemoveProvider.replace("{name}",eU(t))))return;let s={...r.providers};delete s[t];let l=a.find(e=>e.id===t);if(l?.builtIn)try{await eR({action:"removeKey",providerId:t})}catch{}(await eO(s)).success&&b(null)},eK=async({providerId:e,apiKey:a,config:t})=>{let s={...r.providers,[e]:{...r.providers[e],...t}},l=await eO(s);return l.success&&a&&(eT({action:"setKey",providerId:e,apiKey:a}),ed(null),ea(e)),l},eH=async({providerId:e,config:a})=>eO({...r.providers,[e]:a}),eJ=async e=>{let a=await eT({action:"loginStart",providerId:e});return a.success?(ed(null),ea(e),{success:!0}):{success:!1,error:a.error}};return(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{style:{fontSize:14,fontWeight:400},children:e.modelsTitle}),(0,s.jsx)("div",{className:"mt-0.5",style:{fontSize:12.5,color:"var(--dsw-label-caption)"},children:e.modelsDesc}),(0,s.jsx)("div",{className:"mt-1",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:e.customModelIdentityNotice})]}),Q&&(0,s.jsx)("div",{className:"rounded-xl px-3 py-2",style:{fontSize:12.5,background:Q.ok?"rgba(34,197,94,.1)":"rgba(236,19,19,.1)",color:Q.ok?"var(--dsw-success)":"var(--dsw-danger)"},children:Q.msg}),(0,s.jsx)("div",{className:"flex flex-col gap-2.5",children:eF.map(t=>{var l;let i,d,m,v,f=eL.has(t.id)&&!t.builtIn,y=g===t.id;return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex min-w-0 flex-col overflow-hidden rounded-2xl px-4 py-3",style:{border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2",children:[(0,s.jsx)(p,{id:t.id,name:eU(t.id),size:34}),(0,s.jsxs)("div",{className:"min-w-[132px] flex-1",children:[(0,s.jsx)("div",{className:"truncate",style:{fontSize:14,fontWeight:500},children:eU(t.id)}),(0,s.jsxs)("div",{className:"truncate",style:{fontSize:11.5,color:"var(--dsw-label-caption)"},children:[t.id,t.baseUrl?` \xb7 ${t.baseUrl}`:""]})]}),f&&(0,s.jsx)("span",{className:"flex-none rounded-md px-1.5 py-0.5",style:{fontSize:10.5,border:"0.5px solid var(--dsw-border-l3)",color:"var(--dsw-label-tertiary)"},children:e.customBadge}),(0,s.jsx)("span",{className:"inline-block h-2 w-2 flex-none rounded-full",style:{background:t.authReady?"var(--dsw-success)":"var(--dsw-danger)"},title:t.authError||(t.authReady?e.providerReady:e.authUnavailable)}),(0,s.jsx)("span",{className:"flex-none rounded-md px-1.5 py-0.5",style:{fontSize:10.5,border:"0.5px solid var(--dsw-border-l3)",color:"var(--dsw-label-tertiary)"},children:e.credentialSource.replace("{source}","stored"===(i=t.authSource)?"auth.json":"runtime"===i?e.authSourceRuntime:"environment"===i?e.authSourceEnvironment:"models_json_key"===i?"models.json":"models_json_command"===i?e.authSourceCommand:"fallback"===i?e.authSourceProvider:t.resolvedAuthSource||e.authUnavailable)}),(0,s.jsx)("button",{className:"btn-outline flex-none whitespace-nowrap",style:{height:28,padding:"0 12px",fontSize:12},onClick:()=>{var e;let s;return b(g===(e=t.id)?null:e),S(""),Z(!1),G(!1),s=r.providers[e],void(eL.has(e)&&!a.find(a=>a.id===e)?.builtIn?(C(e),M(s?.baseUrl??""),T(s?.api??"openai-completions"),D(""),B("string"==typeof s?.name?s.name:""),F((s?.models??[]).map(h))):(H("string"==typeof s?.baseUrl?s.baseUrl:""),q((s?.models??[]).map(h))))},children:e.edit}),"oauth"===t.storedAuthType&&(0,s.jsx)("button",{className:"flex-none whitespace-nowrap",style:{height:28,padding:"0 12px",fontSize:12,color:"var(--dsw-danger)"},onClick:async()=>{window.confirm(e.confirmRemoveOAuth.replace("{name}",eU(t.id)))&&await eR({action:"removeKey",providerId:t.id})},children:e.removeOAuth}),t.authTypes?.includes("oauth")&&(0,s.jsx)("button",{className:"btn-outline flex-none whitespace-nowrap",style:{height:28,padding:"0 12px",fontSize:12},onClick:()=>{ed(null),eR({action:"loginStart",providerId:t.id}),ea(t.id)},children:e.oauthLogin}),eL.has(t.id)&&(0,s.jsx)("button",{className:"flex-none whitespace-nowrap",style:{fontSize:12.5,color:"var(--dsw-danger)"},onClick:()=>eB(t.id),children:e.delete})]}),"xai"===t.id&&t.authReady&&(0,s.jsxs)("div",{className:"mt-3 flex items-center gap-2 pt-3",style:{borderTop:"0.5px solid var(--dsw-border-l2)",fontSize:11.5,color:"var(--dsw-label-tertiary)"},children:[ex?(0,s.jsxs)("span",{children:[e.usageQuotaLabel," \xb7 ",ex.model," \xb7 ",e.usageRequests," ",ex.requestRemaining.toLocaleString(),"/",ex.requestLimit.toLocaleString()," \xb7 Tokens ",U(ex.tokenRemaining),"/",U(ex.tokenLimit)]}):(0,s.jsx)("span",{children:eb?e.usageProbeFailed:e.usageProbeDisclosure}),(0,s.jsx)("button",{type:"button",className:"pw-chip",disabled:ef,title:e.usageProbeDisclosure,onClick:()=>void ew(!0),children:ef?e.usageProbing:ex?e.usageRefresh:e.usageProbe})]}),z(t.id)&&"xai"!==t.id&&t.authReady&&(0,s.jsx)("div",{className:"mt-3 flex flex-col gap-1.5 pt-3",style:{borderTop:"0.5px solid var(--dsw-border-l2)",fontSize:11.5,color:"var(--dsw-label-tertiary)"},children:(d=ej[l=t.id],m=eN===l,v=e_[l],(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[!d&&(0,s.jsx)("span",{children:v?e.usageProbeFailed:m?e.queryingQuota:e.usageReadOnlyDisclosure}),d?.kind==="quota"&&d.planType&&(0,s.jsxs)("span",{children:[e.usagePlan," ",A(d.planType)]}),d?.kind==="balance"&&d.primary&&(0,s.jsxs)("span",{children:["used"===d.primaryKey?e.usageBalanceUsed:e.usageQuotaRemaining," ",(0,s.jsx)("span",{style:{color:"var(--dsw-label-secondary)"},children:eM(d.primary)})]}),(0,s.jsx)("button",{type:"button",className:"pw-chip",disabled:m,title:e.usageReadOnlyDisclosure,onClick:()=>void ez(l,!0),children:m?e.usageProbing:d?e.usageRefresh:e.usageProbe})]}),d?.kind==="balance"&&d.details.length>0&&(0,s.jsx)("span",{children:d.details.map(a=>{var t;return`${"granted"===(t=a.key)?e.usageBalanceGranted:"toppedUp"===t?e.usageBalanceToppedUp:"voucher"===t?e.usageBalanceVoucher:"cash"===t?e.usageBalanceCash:"used"===t?e.usageBalanceUsed:e.usageBalanceLimit} ${eM(a)}`}).join(" \xb7 ")}),d?.kind==="quota"&&0===d.windows.length&&(0,s.jsxs)("span",{children:[e.usageQuotaRemaining," —"]}),d?.kind==="quota"&&d.windows.map((a,t)=>{var l;return(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{style:{width:84,flex:"none"},children:(a=>{var t,s,l,r;if(void 0!==a.limitWindowSeconds){let r;return`${"weekly"==(r=604800===(s=t=a.limitWindowSeconds)?"weekly":2592e3===s?"monthly":s<86400?"hours":"days")?e.usageWindowWeekly:"monthly"===r?e.usageWindowMonthly:("hours"===r?e.usageWindowHours:e.usageWindowDays).replace("{n}",String(Math.round(t/("hours"===r?3600:86400))))}${a.variant?` (${"opus"===(l=a.variant)?e.usageVariantOpus:"code"===l?e.usageVariantCode:A(l)})`:""}`}return a.name?"premium"===(r=a.name)?e.usageWindowPremium:"chat"===r?e.usageWindowChat:"completions"===r?e.usageWindowCompletions:"rolling"===r?e.usageWindowRolling:A(r):""})(a)}),(0,s.jsxs)("span",{style:{width:92,flex:"none"},children:[e.usageQuotaRemaining," ",a.remainingPercent,"%"]}),(0,s.jsxs)("span",{children:[e.usageReset," ",function(e){if(!e)return"—";let a=new Date(e);return Number.isNaN(a.getTime())?"—":a.toLocaleString()}(a.resetAt)]}),(0,s.jsx)("div",{className:"h-1 overflow-hidden rounded-full",style:{width:120,flex:"none",background:"var(--dsw-border-l2)"},children:(0,s.jsx)("div",{className:"h-full rounded-full",style:{width:`${a.remainingPercent}%`,background:(l=a.remainingPercent)<30?"var(--dsw-danger)":l<=60?"var(--dsw-warning)":"var(--dsw-success)"}})})]},`${a.limitWindowSeconds??a.name??"window"}-${a.variant??""}-${t}`)})]}))})]}),y&&(0,s.jsx)("div",{className:"mt-2 rounded-2xl p-4",style:{border:"0.5px solid var(--dsw-border-l2)"},children:f?(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)(I,{label:e.apiKey,children:(0,s.jsx)("input",{type:"password",value:$,onChange:e=>D(e.target.value),className:O,placeholder:c.has(t.id)?e.apiKeyStored:e.apiKeyOptional})}),(0,s.jsx)(I,{label:e.displayName,children:(0,s.jsx)("input",{value:W,onChange:e=>B(e.target.value),className:O,placeholder:t.id})}),(0,s.jsx)(I,{label:e.baseUrl,children:(0,s.jsx)("input",{value:P,onChange:e=>M(e.target.value),className:O,placeholder:"https://api.example.com/v1"})}),(0,s.jsx)(I,{label:e.apiType,children:(0,s.jsx)(R,{value:E,options:u([E,...t.apis]).map(e=>({value:e,label:e})),onChange:T})}),(0,s.jsx)(w,{models:L,setModels:F,updateModel:(e,a)=>F(t=>t.map((t,s)=>s===e?{...t,...a}:t)),discover:async a=>{let s=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"discoverModels",providerId:t.id,baseUrl:P.trim(),api:E,apiKey:$.trim(),allowPrivate:a})}),l=await s.json();if(!l.success)throw Error(l.error||e.toastError);return(l.data.models??[]).map(e=>({id:e.id,name:e.name??""}))},discoverDisabled:!P.trim()}),(0,s.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,s.jsx)("button",{className:"btn-outline",style:{height:32},disabled:V,onClick:()=>b(null),children:e.cancel}),(0,s.jsx)("button",{className:"btn-primary-white",disabled:V||!P.trim()||!!x(L)||!L.some(e=>e.id.trim()),onClick:()=>void eA(),children:V?e.saving:e.save})]})]}):(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)(I,{label:e.apiKey,children:(0,s.jsx)("input",{type:"password",value:j,onChange:e=>S(e.target.value),className:O,placeholder:t.keyManaged?e.apiKeyStored:t.apiKeyLabel??e.apiKey})}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{className:"flex w-full items-center gap-2 rounded-xl px-2 py-2 text-left transition-colors",style:{fontSize:13,color:"var(--dsw-label-secondary)",background:X?"var(--dsw-hover)":"transparent"},onClick:()=>G(e=>!e),children:[(0,s.jsx)("span",{style:{display:"inline-flex",transform:X?"none":"rotate(-90deg)",transition:"transform 120ms ease"},children:(0,s.jsx)(n.Cd,{size:13})}),e.customSettings]}),X?(0,s.jsxs)("div",{className:"flex flex-col gap-3 pl-1 pt-2",children:[(0,s.jsx)(I,{label:e.baseUrl,children:(0,s.jsx)("input",{value:K,onChange:e=>H(e.target.value),className:O,placeholder:t.baseUrl??e.providerDefault})}),(0,s.jsx)(w,{models:J,setModels:q,updateModel:(e,a)=>q(t=>t.map((t,s)=>s===e?{...t,...a}:t)),inheritedCount:t.modelCount,discover:async a=>{let s=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"discoverModels",providerId:t.id,baseUrl:K.trim()||t.baseUrl||"",api:t.apis[0],apiKey:j.trim(),allowPrivate:a})}),l=await s.json();if(!l.success)throw Error(l.error||e.toastError);return(l.data.models??[]).map(e=>({id:e.id,name:e.name??""}))},discoverDisabled:!(K.trim()||t.baseUrl)})]}):null]}),(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[t.keyManaged&&(0,s.jsx)("button",{style:{fontSize:12.5,color:"var(--dsw-danger)"},disabled:V,onClick:async()=>{if("oauth"===t.storedAuthType){if(!window.confirm(e.confirmRemoveOAuth.replace("{name}",t.name)))return}else if(!window.confirm(e.confirmRemoveKey.replace("{name}",t.name)))return;(await eR({action:"removeKey",providerId:t.id})).success&&b(null)},children:"oauth"===t.storedAuthType?e.removeOAuth:e.removeKey}),(0,s.jsx)("button",{className:"btn-outline",style:{height:32},disabled:V,onClick:()=>b(null),children:e.cancel}),(0,s.jsx)("button",{className:"btn-primary-white",disabled:V||null===o||!!x(J),onClick:()=>void eI({id:t.id,apis:t.apis}),children:V?e.saving:e.save})]})]})})]},t.id)})}),(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsxs)("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-2xl px-4 py-3.5 transition-colors",style:{border:"0.5px solid var(--dsw-border-l3)",fontSize:14},onMouseEnter:e=>e.currentTarget.style.background="var(--dsw-hover)",onMouseLeave:e=>e.currentTarget.style.background="transparent",onClick:()=>k("builtin"),children:[(0,s.jsx)(n.Xh,{size:15}),e.addProvider]}),(0,s.jsxs)("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-2xl px-4 py-3.5 transition-colors",style:{border:"0.5px solid var(--dsw-border-l3)",fontSize:14},onMouseEnter:e=>e.currentTarget.style.background="var(--dsw-hover)",onMouseLeave:e=>e.currentTarget.style.background="transparent",onClick:()=>k("custom"),children:[(0,s.jsx)(n.Xh,{size:15}),e.addCustomProvider]})]}),N?(0,s.jsx)(y,{mode:N,providers:eW,existingIds:a.map(e=>e.id),onClose:()=>k(null),onSaveBuiltin:eK,onSaveCustom:eH,onOAuthLogin:eJ}):null,ee&&(0,s.jsx)("div",{className:"modal-mask fixed inset-0 z-[120] flex items-center justify-center",onMouseDown:e=>{e.target===e.currentTarget&&eD()},children:(0,s.jsxs)("div",{className:"glass-modal flex flex-col gap-4 p-6",style:{width:460,maxWidth:"92vw",borderRadius:24,boxShadow:"var(--dsw-elevation-prominent)"},children:[(0,s.jsxs)("div",{style:{fontSize:15,fontWeight:600},children:[e.oauthLogin," \xb7 ",ee]}),ep&&!eo?(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)("div",{style:{fontSize:13,color:"var(--dsw-label-primary)"},children:e.oauthDevicePrompt}),ep.instructions?(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-label-tertiary)"},children:ep.instructions}):null,(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("a",{href:ep.verificationUri,target:"_blank",rel:"noreferrer",className:"btn-primary-white",style:{fontSize:12.5,textDecoration:"none"},children:e.oauthOpenAuth}),ep.userCode?(0,s.jsx)("button",{className:"btn-outline",style:{height:32},onClick:()=>{if(!ep?.userCode)return;let e=ep.userCode,a=()=>{eu(!0),setTimeout(()=>eu(!1),2e3)};navigator.clipboard.writeText(e).then(a).catch(()=>{let t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),t.remove(),a()})},children:ec?e.oauthCodeCopied:`${e.oauthDeviceCode}: ${ep.userCode}`}):null]})]}):el.length>0?(0,s.jsx)("div",{className:"flex flex-col gap-0.5",style:{fontSize:12,color:"var(--dsw-label-tertiary)"},children:el.slice(-3).map((e,a)=>(0,s.jsx)("div",{className:"truncate",children:e},a))}):null,eo?(0,s.jsx)("div",{style:{fontSize:13,color:eo.ok?"var(--dsw-success)":"var(--dsw-danger)"},children:eo.ok?ee+" ✓":eo.msg}):et?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{style:{fontSize:13.5,color:"var(--dsw-label-primary)"},children:et.message}),et.message.match(/https?:\/\/[^\s)]+/)&&(0,s.jsx)("a",{href:et.message.match(/https?:\/\/[^\s)]+/)[0],target:"_blank",rel:"noreferrer",className:"break-all",style:{fontSize:12.5,color:"var(--dsw-accent)"},children:et.message.match(/https?:\/\/[^\s)]+/)[0]}),et.options?.length?(0,s.jsx)("div",{className:"flex flex-col gap-1.5",children:et.options.map(e=>(0,s.jsx)("button",{className:"btn-outline",style:{height:34,justifyContent:"flex-start",textAlign:"left"},onClick:()=>{e$(e.value)},children:e.label},e.value))}):(0,s.jsx)("input",{autoFocus:!0,type:"secret"===et.type?"password":"text",value:ei,onChange:e=>en(e.target.value),placeholder:et.placeholder??"",className:"w-full rounded-xl px-3 py-2",style:{fontSize:13,background:"var(--dsw-hover)"},onKeyDown:e=>{"Enter"===e.key&&!e.nativeEvent.isComposing&&ei.trim()&&e$(ei.trim())}}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)("span",{style:{fontSize:12,color:"var(--dsw-label-caption)"},children:e.oauthWait}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("button",{className:"btn-outline",style:{height:32},onClick:()=>{eD()},children:e.oauthCancel}),!et.options?.length&&(0,s.jsx)("button",{className:"btn-primary-white",disabled:!ei.trim(),style:{opacity:ei.trim()?1:.5},onClick:()=>{e$(ei.trim())},children:e.confirm})]})]})]}):(0,s.jsx)("div",{style:{fontSize:13,color:"var(--dsw-label-tertiary)"},children:e.oauthWait}),eo&&(0,s.jsx)("div",{className:"flex justify-end",children:(0,s.jsx)("button",{className:"btn-primary-white",onClick:()=>ea(null),children:e.close})})]})})]})}let O="w-full rounded-xl px-3 py-2";function U(e){return e>=1e6?`${Math.round(e/1e5)/10}M`:e.toLocaleString()}function A(e){return 0===e.length?e:e[0].toUpperCase()+e.slice(1)}function I({label:e,children:a}){return(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"mb-1",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:e}),a]})}let B={read:{zh:"读取文件",en:"Read files"},bash:{zh:"执行 Shell 命令",en:"Run shell commands"},powershell:{zh:"执行 PowerShell",en:"Run PowerShell"},edit:{zh:"编辑文件",en:"Edit files"},write:{zh:"写入文件",en:"Write files"},grep:{zh:"搜索文件内容",en:"Search file contents"},find:{zh:"按名称查找文件",en:"Find files by name"},ls:{zh:"列出目录内容",en:"List directories"}};function K({toolPreset:e,onToolPresetChange:a,tools:t,onSetTools:l}){let{t:r,lang:i}=(0,m.s)(),n=new Set(t?.active??[]),o=t?.all??[];return(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{style:{fontSize:14,fontWeight:400},children:r.toolsSection}),(0,s.jsx)("div",{className:"mt-0.5",style:{fontSize:12.5,color:"var(--dsw-label-caption)"},children:r.toolsSectionDesc})]}),(0,s.jsx)($,{title:r.securityToolPreset,desc:r.securityToolPresetDesc,children:(0,s.jsx)(R,{value:e,options:[{value:"readonly",label:r.toolReadonly},{value:"standard",label:r.toolStandard},{value:"full",label:r.toolFull}],onChange:e=>a(e)})}),0===o.length?(0,s.jsx)("div",{className:"rounded-2xl p-4",style:{border:"0.5px dashed var(--dsw-border-l3)",fontSize:12.5,color:"var(--dsw-label-caption)"},children:r.toolsNoSession}):(0,s.jsxs)("div",{className:"flex flex-col gap-2.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:[(0,s.jsx)("span",{style:{fontWeight:600},children:r.toolsCurrentSession}),(0,s.jsx)("span",{children:r.toolsActiveCount.replace("{n}",String(n.size)).replace("{total}",String(o.length))})]}),o.map(e=>{let a,t=n.has(e.name),r=e.description||((a=B[e.name])?"zh"===i?a.zh:a.en:"");return(0,s.jsxs)("div",{className:"flex items-center gap-3 rounded-2xl px-4 py-2.5",style:{border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("div",{style:{fontSize:13.5,fontWeight:500,fontFamily:"var(--font-mono)"},children:e.name}),r&&(0,s.jsx)("div",{className:"truncate",style:{fontSize:11.5,color:"var(--dsw-label-caption)"},children:r})]}),(0,s.jsx)("button",{className:"relative h-5 w-9 flex-none rounded-full transition-colors",style:{background:t?"var(--dsw-accent)":"var(--dsw-border-l3)"},role:"switch","aria-checked":t,"aria-label":e.name,disabled:!l||t&&n.size<=1,onClick:()=>{var a;return a=e.name,void(!l||l(n.has(a)?[...n].filter(e=>e!==a):[...n,a]))},children:(0,s.jsx)("span",{className:"absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all",style:{left:t?18:2}})})]},e.name)})]})]})}function H({cwd:e,onOpenFileContent:a}){let{t}=(0,m.s)(),[r,i]=(0,l.useState)([]),n=(0,l.useCallback)(async()=>{let a=await fetch(`/api/skills${e?`?cwd=${encodeURIComponent(e)}`:""}`),t=await a.json();t.success&&i(t.data.skills)},[e]);(0,l.useEffect)(()=>{n()},[n]);let o=async a=>{let t=await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"toggle",filePath:a.filePath,disabled:!a.disabled,cwd:e})});(await t.json()).success&&n()},d=async t=>{let s=await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"read",filePath:t.filePath,cwd:e})}),l=await s.json();l.success&&a?.(t.filePath,l.data.content)},[c,u]=(0,l.useState)(null),p=async a=>{if(!window.confirm(t.confirmDeleteSkill.replace("{name}",a.name)))return;u(null);let s=await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"delete",filePath:a.filePath,cwd:e})}),l=await s.json();l.success?n():u(l.error||t.toastError)};return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-label-caption)"},children:t.skillsDesc}),c&&(0,s.jsx)("div",{role:"alert",className:"rounded-lg px-3 py-2",style:{fontSize:12.5,background:"var(--dsw-hover)",color:"var(--dsw-danger)"},children:c}),0===r.length&&(0,s.jsx)("div",{style:{fontSize:13,color:"var(--dsw-label-caption)"},children:"—"}),(0,s.jsx)("div",{className:"flex flex-col gap-2",children:r.map(e=>{let a;return(0,s.jsx)("div",{className:"rounded-2xl px-4 py-3",style:{border:"0.5px solid var(--dsw-border-l2)"},children:(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{style:{fontSize:13.5,fontWeight:500},children:e.name}),(0,s.jsx)("span",{className:"rounded-full px-2 py-0.5",style:{fontSize:10,background:"var(--dsw-hover)",color:"var(--dsw-label-tertiary)"},children:"global"===(a=e.scope)?t.scopeGlobal:"project"===a?t.scopeProject:t.scopePackage})]}),(0,s.jsx)("div",{className:"mt-0.5 truncate",style:{fontSize:12,color:"var(--dsw-label-caption)"},title:e.description,children:e.description})]}),(0,s.jsx)("button",{className:"rounded-lg px-2.5 py-1",style:{fontSize:11.5,color:"var(--dsw-label-tertiary)"},onClick:()=>d(e),children:t.viewSkillFile}),"package"!==e.scope&&(0,s.jsx)("button",{className:"rounded-lg px-2.5 py-1",style:{fontSize:11.5,color:"var(--dsw-danger)"},title:t.deleteSkillHint,onClick:()=>void p(e),children:t.delete}),"package"===e.scope&&(0,s.jsx)("span",{style:{fontSize:10.5,color:"var(--dsw-label-caption)"},title:t.skillDeletePackageHint,children:t.skillDeletePackageHint}),(0,s.jsx)("button",{className:"relative h-5 w-9 flex-none rounded-full transition-colors",style:{background:e.disabled?"var(--dsw-border-l3)":"var(--dsw-accent)"},role:"switch","aria-checked":!e.disabled,onClick:()=>o(e),children:(0,s.jsx)("span",{className:"absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all",style:{left:e.disabled?2:18}})})]})},e.filePath)})})]})}function J({cwd:e}){let{t:a,lang:t}=(0,m.s)(),r=e=>window.confirm(a.confirmUninstallPackage.replace("{source}",e)),[i,o]=(0,l.useState)("config"),[d,c]=(0,l.useState)([]),[u,p]=(0,l.useState)([]),[h,x]=(0,l.useState)(""),[v,f]=(0,l.useState)(new Set),[g,b]=(0,l.useState)(""),[y,w]=(0,l.useState)(!1),[j,S]=(0,l.useState)(!1),[N,k]=(0,l.useState)(null),[_,C]=(0,l.useState)(null),[z,P]=(0,l.useState)(null),M=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=e=>{e.target instanceof Node&&M.current?.contains(e.target)||P(null)};return window.addEventListener("pointerdown",e),()=>window.removeEventListener("pointerdown",e)},[]);let E=(0,l.useCallback)(async()=>{let a=await fetch(`/api/plugins${e?`?cwd=${encodeURIComponent(e)}`:""}`),t=await a.json();t.success&&(c(t.data.packages),p(t.data.extensions))},[e]);(0,l.useEffect)(()=>{E()},[E]);let T=(e,t)=>{C({ok:e,msg:t??(e?a.toastSaved:a.toastError),loading:!1}),setTimeout(()=>C(null),2600)},R=async(t,s={},l,r,i)=>{S(!0),l&&k(l),r&&C({ok:!0,msg:r,loading:!0});try{let l=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,cwd:e,...s})}),r=await l.json();if(r.success)return T(!0,i??("toggle"===t?s.disabled?a.disabled:a.enabled:a.toastSaved)),await E(),!0;return T(!1,r.error??a.toastError),!1}catch(e){return T(!1,e?.message??a.toastError),!1}finally{S(!1),k(null)}},$=e=>f(a=>{let t=new Set(a);return t.has(e)?t.delete(e):t.add(e),t}),D=e=>{if(e.startsWith("builtin:"))return"builtin";let a=e.replace(/\\/g,"/");return a.includes("/.pi/agent/npm/")||a.includes("/.pi/agent/git/")?"package":a.includes("/.pi/agent/")?"global":(a.includes("/.pi/"),"project")},L=u.filter(e=>"package"!==D(e.path)),F=h.trim().toLowerCase(),W=[...d.map(e=>({key:`pkg:${e.scope}:${e.source}`,kind:"package",name:e.source.replace(/^npm:/,"").replace(/^git[^:]*:/,""),p:e})),...L.map(e=>({key:`ext:${e.path}`,kind:"extension",name:e.name,e}))].filter(e=>!F||e.name.toLowerCase().includes(F)),O=(0,s.jsxs)("span",{className:"flex flex-none items-center gap-1.5 rounded-md px-1.5 py-0.5",style:{fontSize:10.5,background:"rgba(34,197,94,.12)",color:"var(--dsw-success)"},children:[(0,s.jsx)("span",{className:"h-1.5 w-1.5 rounded-full",style:{background:"var(--dsw-success)"}}),a.enabled]});return(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{style:{fontSize:20,fontWeight:600,color:"var(--dsw-label-primary)"},children:a.setPlugins}),(0,s.jsx)("div",{className:"mt-1",style:{fontSize:13,color:"var(--dsw-label-tertiary)"},children:a.pluginPageDesc})]}),_&&(0,s.jsxs)("div",{className:"fixed top-6 left-1/2 -translate-x-1/2 z-[9999] flex items-center gap-2.5 px-4 py-2 rounded-xl shadow-2xl transition-all pointer-events-none",style:{fontSize:13,fontWeight:500,background:"var(--dsw-surface-l1, #1e2025)",border:_.loading?"1px solid var(--dsw-border-l3)":_.ok?"1px solid rgba(34,197,94,.4)":"1px solid rgba(236,19,19,.4)",color:_.loading?"var(--dsw-label-primary)":_.ok?"var(--dsw-success)":"var(--dsw-danger)",backdropFilter:"blur(12px)",boxShadow:"0 10px 30px rgba(0,0,0,0.5)"},children:[_.loading&&(0,s.jsx)("span",{className:"h-3.5 w-3.5 flex-none animate-spin rounded-full border-2 border-current border-t-transparent"}),(0,s.jsx)("span",{children:_.msg})]}),(0,s.jsxs)("div",{className:"hairline-b flex items-center gap-6",children:[(0,s.jsx)("button",{className:"settings-tab-underline","data-active":"config"===i,onClick:()=>o("config"),children:a.pluginConfig}),(0,s.jsx)("button",{className:"settings-tab-underline","data-active":"list"===i,onClick:()=>o("list"),children:a.pluginList})]}),"config"===i&&(0,s.jsxs)("div",{className:"flex flex-col gap-2.5",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2 rounded-2xl px-4 py-3",style:{border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsx)("div",{style:{fontSize:13.5,fontWeight:500},children:a.addPackage}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("input",{value:g,onChange:e=>b(e.target.value),placeholder:a.addPackagePlaceholder,className:"min-w-0 flex-1 rounded-xl px-3 py-2",style:{fontSize:13,background:"var(--dsw-hover)",border:"0.5px solid var(--dsw-border-l2)",fontFamily:"var(--font-mono)"},onKeyDown:e=>{"Enter"===e.key&&g.trim()&&!j&&R("install",{source:g.trim(),local:y},void 0,a.installing,a.installSuccess).then(e=>{e&&b("")})}}),(0,s.jsxs)("label",{className:"flex items-center gap-1.5",style:{fontSize:12.5,color:"var(--dsw-label-secondary)"},children:[(0,s.jsx)("input",{type:"checkbox",checked:y,onChange:e=>w(e.target.checked),disabled:!e}),a.installLocal]}),(0,s.jsx)("button",{className:"btn-primary-white",style:{height:32,padding:"0 14px"},disabled:!g.trim()||j,onClick:()=>void R("install",{source:g.trim(),local:y},void 0,a.installing,a.installSuccess).then(e=>{e&&b("")}),children:a.install})]})]}),(0,s.jsx)("div",{className:"flex justify-end",children:(0,s.jsxs)("button",{className:"btn-outline",style:{height:30,fontSize:12.5},disabled:j,onClick:async()=>{S(!0);try{let t=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"reload",cwd:e})}),s=await t.json();T(s.success,s.success?a.reloadedSessions.replace("{loaders}",String(s.data?.loaders??0)).replace("{sessions}",String(s.data?.sessions??0)):s.error),s.success&&await E()}finally{S(!1)}},children:[(0,s.jsx)(n.Ct,{size:13})," ",a.reloadExtensions]})}),0===L.length&&(0,s.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)"},children:a.extensionsEmpty}),L.map(e=>{let t=`ext:${e.path}`,l=v.has(t),r=D(e.path);return(0,s.jsxs)("div",{className:"rounded-2xl",style:{border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsxs)("button",{className:"flex w-full items-center gap-3 px-4 py-3.5 text-left",onClick:()=>$(t),children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",style:{fontSize:14,fontWeight:500},children:[(0,s.jsx)("span",{children:e.name}),e.error&&(0,s.jsx)("span",{className:"rounded px-1.5 py-0.5",style:{fontSize:10.5,color:"var(--dsw-danger)",background:"var(--pw-danger-soft, rgba(236,19,19,.12))"},children:a.extensionLoadError}),e.disabled&&!e.error&&(0,s.jsx)("span",{className:"rounded px-1.5 py-0.5",style:{fontSize:10.5,color:"var(--dsw-label-tertiary)",background:"var(--dsw-selector)"},children:a.disabled})]}),(0,s.jsx)("div",{className:"truncate",style:{fontSize:12,color:e.error?"var(--dsw-danger)":"var(--dsw-label-caption)"},title:e.error??e.path,children:e.error??e.path})]}),(0,s.jsx)("span",{className:"chevron",style:{color:"var(--dsw-label-tertiary)",display:"inline-flex",transform:l?"rotate(180deg)":"none",transition:"transform 120ms var(--ds-ease-in-out)"},children:(0,s.jsx)(n.Cd,{size:14})})]}),l&&(0,s.jsxs)("div",{className:"hairline-t flex flex-col gap-1.5 px-4 py-3",style:{fontSize:12,color:"var(--dsw-label-secondary)"},children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"rounded-md px-1.5 py-0.5",style:{fontSize:10.5,border:"0.5px solid var(--dsw-border-l3)",color:"var(--dsw-label-tertiary)"},children:"global"===r?a.scopeGlobal:"project"===r?a.scopeProject:"builtin"===r?a.promptToolBuiltin:a.scopePackage}),O]}),(0,s.jsx)("div",{className:"break-all",style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--dsw-label-caption)"},children:e.path})]})]},t)})]}),"list"===i&&(0,s.jsxs)("div",{className:"flex flex-col gap-3.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2.5 rounded-xl px-3.5 py-2.5 transition-colors",style:{background:"var(--dsw-hover)",border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsx)(n.FG,{size:15,style:{color:"var(--dsw-label-caption)"}}),(0,s.jsx)("input",{value:h,onChange:e=>x(e.target.value),placeholder:a.searchPlugins,className:"w-full bg-transparent outline-none",style:{fontSize:13,color:"var(--dsw-label-primary)"}})]}),(0,s.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,s.jsx)("span",{style:{fontSize:13.5,fontWeight:600,color:"var(--dsw-label-primary)"},children:a.pluginList}),(0,s.jsx)("span",{style:{fontSize:12,color:"var(--dsw-label-caption)"},children:W.length})]}),0===W.length?(0,s.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)"},children:a.packagesEmpty}):(0,s.jsx)("div",{className:"grid grid-cols-1 items-start sm:grid-cols-2 gap-2.5",children:W.map(e=>{let l=v.has(e.key),i="package"===e.kind?!0===e.p.disabled:!0===e.e.disabled,o=z===e.key,d=N===e.key;return(0,s.jsxs)("div",{className:"flex flex-col rounded-xl transition-colors",style:{background:"var(--dsw-hover)",border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsxs)("div",{className:"flex min-w-0 items-center justify-between gap-2 px-3.5",style:{height:44},children:[(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate font-medium text-[var(--dsw-label-primary)] cursor-pointer select-none",style:{fontSize:13.5},onClick:()=>$(e.key),title:e.name,children:e.name}),(0,s.jsxs)("div",{ref:o?M:void 0,className:"relative flex-none",children:[(0,s.jsxs)("button",{type:"button",className:"flex min-w-[86px] items-center justify-center rounded-lg px-3 transition-colors cursor-pointer select-none disabled:cursor-wait",style:{gap:7,height:30,background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.08)"},"aria-haspopup":"menu","aria-expanded":o,disabled:d,onClick:a=>{a.stopPropagation(),P(a=>a===e.key?null:e.key)},children:[d?(0,s.jsx)("span",{className:"h-3 w-3 flex-none animate-spin rounded-full border border-[var(--dsw-label-tertiary)] border-t-transparent"}):i?null:(0,s.jsx)("span",{className:"h-2 w-2 flex-none rounded-full",style:{background:"#22c55e",boxShadow:"0 0 5px rgba(34, 197, 94, 0.4)"}}),(0,s.jsx)("span",{style:{fontSize:12,fontWeight:500,color:i?"var(--dsw-label-tertiary)":"var(--dsw-success)",lineHeight:1},children:i?a.disabled:a.enabled}),(0,s.jsx)(n.Cd,{size:13,style:{color:"var(--dsw-label-tertiary)",transform:o?"rotate(180deg)":"none",transition:"transform 140ms ease"}})]}),o&&(0,s.jsxs)("div",{className:"popover absolute right-0 top-full mt-1.5 z-50 w-36 py-1 rounded-xl shadow-xl",role:"menu",style:{background:"var(--dsw-surface-l1, #1e2025)",border:"0.5px solid var(--dsw-border-l3)",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5)"},children:[(0,s.jsx)("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors hover:bg-[var(--dsw-hover)] cursor-pointer",style:{color:i?"var(--dsw-success)":"var(--dsw-label-primary)"},disabled:j,onClick:()=>{P(null),R("toggle","package"===e.kind?{kind:"package",source:e.p.source,scope:e.p.scope,disabled:!i}:{kind:"extension",path:e.e.path,disabled:!i},e.key,i?"zh"===t?"正在启用...":"Enabling...":"zh"===t?"正在停用...":"Disabling...",i?a.enabled:a.disabled)},children:i?a.enablePlugin:a.disablePlugin}),"package"===e.kind&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors hover:bg-[var(--dsw-hover)] cursor-pointer disabled:opacity-50",style:{color:"var(--dsw-label-secondary)"},disabled:j,onClick:()=>{P(null),R("update",{source:e.p.source},e.key,a.updating,a.updateSuccess)},children:a.update}),(0,s.jsx)("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors hover:bg-[var(--dsw-hover)] cursor-pointer disabled:opacity-50",style:{color:"var(--dsw-danger)"},disabled:j,onClick:()=>{P(null),r(e.p.source)&&R("remove",{source:e.p.source,local:"project"===e.p.scope},e.key,a.uninstalling,a.uninstallSuccess)},children:a.uninstall})]}),(0,s.jsx)("div",{className:"my-1 border-t border-[var(--dsw-border-l1)]"}),(0,s.jsx)("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors hover:bg-[var(--dsw-hover)] cursor-pointer",style:{color:"var(--dsw-label-tertiary)"},onClick:()=>{$(e.key),P(null)},children:l?"zh"===t?"收起详情":"Hide details":"zh"===t?"查看详情":"View details"})]})]})]}),l&&(0,s.jsx)("div",{className:"hairline-t flex flex-col gap-2 px-3.5 py-3",style:{fontSize:12},children:"package"===e.kind?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"break-all",style:{color:"var(--dsw-label-tertiary)",fontSize:11.5},children:e.p.source}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"rounded-md px-1.5 py-0.5",style:{fontSize:10.5,border:"0.5px solid var(--dsw-border-l3)",color:"var(--dsw-label-tertiary)"},children:"user"===e.p.scope?a.scopeGlobal:a.scopeProject}),(0,s.jsxs)("span",{style:{color:"var(--dsw-label-caption)",fontSize:11.5},children:[a.resources,": ",e.p.resources.extensions," ext \xb7 ",e.p.resources.skills," skills \xb7 ",e.p.resources.prompts," prompts"]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-end gap-3 pt-1",children:[(0,s.jsx)("button",{disabled:j,style:{fontSize:12,color:"var(--dsw-label-secondary)"},className:"hover:underline cursor-pointer disabled:opacity-50",onClick:()=>void R("update",{source:e.p.source},e.key,a.updating,a.updateSuccess),children:a.update}),(0,s.jsx)("button",{disabled:j,style:{fontSize:12,color:"var(--dsw-danger)"},className:"hover:underline cursor-pointer disabled:opacity-50",onClick:()=>{r(e.p.source)&&R("remove",{source:e.p.source,local:"project"===e.p.scope},e.key,a.uninstalling,a.uninstallSuccess)},children:a.uninstall})]})]}):(0,s.jsx)("div",{className:"break-all",style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--dsw-label-caption)"},children:e.e.path})})]},e.key)})})]})]})}},901:e=>{e.exports={mask:"ProviderSetupModal_mask__wwU3u",dialog:"ProviderSetupModal_dialog__BxSeI",builtinDialog:"ProviderSetupModal_builtinDialog__vA7_B",header:"ProviderSetupModal_header__Nvgmb",title:"ProviderSetupModal_title__ZIIXp",body:"ProviderSetupModal_body__QAlNu",builtinBody:"ProviderSetupModal_builtinBody___4EFo",field:"ProviderSetupModal_field__ZMO8M",label:"ProviderSetupModal_label__4_BYS",hint:"ProviderSetupModal_hint__yCwPV",input:"ProviderSetupModal_input__YZYV5",select:"ProviderSetupModal_select___PTpP",providerTrigger:"ProviderSetupModal_providerTrigger__TXtau",picker:"ProviderSetupModal_picker__VQdQc",providerText:"ProviderSetupModal_providerText__l9bwJ",providerName:"ProviderSetupModal_providerName__Hwwfg",providerMeta:"ProviderSetupModal_providerMeta____3za",menu:"ProviderSetupModal_menu__zO5CU",searchWrap:"ProviderSetupModal_searchWrap__5yw1r",searchIcon:"ProviderSetupModal_searchIcon__BZeD1",search:"ProviderSetupModal_search__j_n_8",providerList:"ProviderSetupModal_providerList__bMnFj",providerRow:"ProviderSetupModal_providerRow__Zf7fg",selectedMark:"ProviderSetupModal_selectedMark___8UDb",empty:"ProviderSetupModal_empty__4V1WK",advanced:"ProviderSetupModal_advanced__kWaTH",advancedButton:"ProviderSetupModal_advancedButton__efHwl",catalog:"ProviderSetupModal_catalog__mXakU",catalogHeader:"ProviderSetupModal_catalogHeader__0MDA4",catalogStatus:"ProviderSetupModal_catalogStatus__JRz0P",discoverButton:"ProviderSetupModal_discoverButton__GGuZX",discoverControls:"ProviderSetupModal_discoverControls___0_l8",allowPrivate:"ProviderSetupModal_allowPrivate__zZyZi",modelEmpty:"ProviderSetupModal_modelEmpty__h1N_8",modelList:"ProviderSetupModal_modelList__jkYVz",modelRow:"ProviderSetupModal_modelRow__mHfRv",removeModel:"ProviderSetupModal_removeModel___LjE1",addModel:"ProviderSetupModal_addModel__Q3KOU",error:"ProviderSetupModal_error__EAOK6",footer:"ProviderSetupModal_footer__zVp_c",footerButton:"ProviderSetupModal_footerButton__FL58k",primary:"ProviderSetupModal_primary__ArzeF",modelEntry:"ProviderSetupModal_modelEntry__G067u",rowToggle:"ProviderSetupModal_rowToggle__kc_Za",capacityRow:"ProviderSetupModal_capacityRow__0miDX",capacityField:"ProviderSetupModal_capacityField___TX70",capacityHint:"ProviderSetupModal_capacityHint__z_5re",rowError:"ProviderSetupModal_rowError__2vHrG",catalogError:"ProviderSetupModal_catalogError__ZL5D7",candidateMask:"ProviderSetupModal_candidateMask__YUZn7",candidateDialog:"ProviderSetupModal_candidateDialog__upECk",candidateHeader:"ProviderSetupModal_candidateHeader__bUvHV",candidateList:"ProviderSetupModal_candidateList__JRufC",candidateRow:"ProviderSetupModal_candidateRow__Omm_o",candidateId:"ProviderSetupModal_candidateId__7Hy7u",candidateName:"ProviderSetupModal_candidateName__D4rXE",candidateActions:"ProviderSetupModal_candidateActions__iptOe",candidateAll:"ProviderSetupModal_candidateAll__yhD_R",candidatePicked:"ProviderSetupModal_candidatePicked__cJ78H"}}}]);
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8552],{8552:(e,t,n)=>{n.r(t),n.d(t,{MarkdownBlock:()=>m,StreamingMarkdownBlock:()=>h,default:()=>p});var r=n(5155),s=n(2115),l=n(8426),i=n(3437),c=n(7890),o=n(9992),u=n(8155),a=n(1859);function d({text:e}){let[t,n]=(0,s.useState)(!1),[l,i]=(0,s.useState)(!1),{t:c}=(0,a.s)();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"icon-btn",title:l?c.copyFailed:c.copy,"aria-label":c.copy,onClick:()=>{(0,u.D)(e).then(e=>{n(e),i(!e),setTimeout(()=>{n(!1),i(!1)},1200)})},children:t?(0,r.jsx)(o.df,{size:14}):(0,r.jsx)(o.sS,{size:14})}),l&&(0,r.jsx)("span",{role:"alert",style:{fontSize:11,color:"var(--dsw-danger)"},children:c.copyFailed})]})}function f({src:e,alt:t,title:n}){let[l,i]=(0,s.useState)(!1),{t:c}=(0,a.s)(),o="string"==typeof e?e:"";if(!o)return null;if(l||function(e){try{return new URL(e,window.location.href).origin===window.location.origin}catch{return!1}}(o))return(0,r.jsx)("img",{src:o,alt:t??"",title:n});let u=o;try{u=new URL(o).host||o}catch{}return(0,r.jsxs)("button",{type:"button",className:"btn-outline",style:{height:26,padding:"0 10px",fontSize:12},title:o,onClick:()=>i(!0),children:[c.externalImage,t?`:${t}`:"","(",u,")"]})}let m=(0,s.memo)(function({text:e}){return(0,r.jsx)("div",{className:"md",children:(0,r.jsx)(l.oz,{remarkPlugins:[c.A],rehypePlugins:[[i.A,{detect:!1,ignoreMissing:!0}]],components:{a:({node:e,...t})=>(0,r.jsx)("a",{...t,target:"_blank",rel:"noopener noreferrer"}),img:({src:e,alt:t,title:n})=>(0,r.jsx)(f,{src:e,alt:t,title:n}),pre:({node:e,children:t,...n})=>(0,r.jsxs)("div",{className:"md-code-block",children:[(0,r.jsx)("div",{className:"md-code-copy",children:(0,r.jsx)(d,{text:function e(t){return t?"string"==typeof t.value?t.value:t.children?.map(e).join("")??"":""}(e)})}),(0,r.jsx)("pre",{...n,children:t})]})},children:e})})}),h=(0,s.memo)(function({text:e}){let[t,n]=(0,s.useState)(e),l=(0,s.useRef)(e),i=(0,s.useRef)(null);return(0,s.useEffect)(()=>{l.current=e,e===t||i.current||(i.current=setTimeout(()=>{i.current=null,n(l.current)},100))},[e,t]),(0,s.useEffect)(()=>()=>{i.current&&clearTimeout(i.current),i.current=null},[]),(0,r.jsx)(m,{text:t})}),p=m}}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[552,635,1097,2138,2164,2437,2772,2836,2922,4459,4896,5221,5368,5907,6031,6450,6819,6849,6884,6988,7822,7844,7851,8091,8167,8651,9223,9742,9799,9968],{4441:()=>{}},_=>{_.O(0,[8441,3794,7358],()=>_(_.s=4441)),_N_E=_.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4520],{1965:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>c});var n=s(5155),a=s(2115),r=s(4645),i=s(1859),l=s(2576);function c(){return(0,n.jsx)(i.I18nProvider,{children:(0,n.jsx)(a.Suspense,{fallback:(0,n.jsx)("div",{className:"flex min-h-screen items-center justify-center","aria-busy":"true",children:(0,n.jsx)(l.N,{size:40})}),children:(0,n.jsx)(o,{})})})}function o(){let{t:e}=(0,i.s)(),t=(0,r.useRouter)(),s=function(e){if(!e||!e.startsWith("/")||e.startsWith("//")||e.includes("\\"))return"/";try{let t=new URL(e,"http://localhost");return"http://localhost"===t.origin?`${t.pathname}${t.search}`:"/"}catch{return"/"}}((0,r.useSearchParams)().get("next"));return(0,a.useEffect)(()=>{let e=!0;return(async()=>{try{let n=await fetch("/api/web-auth"),a=await n.json();if(!e||!a?.success)return;(!a.data.enabled||a.data.authenticated)&&t.replace(s)}catch{}})(),()=>{e=!1}},[t,s]),(0,n.jsx)("div",{className:"flex min-h-screen items-center justify-center px-4",style:{background:"var(--dsw-bg-base)"},children:(0,n.jsx)("div",{className:"glass-modal flex w-[min(92vw,380px)] flex-col gap-4 p-7",style:{borderRadius:24,boxShadow:"var(--dsw-elevation-prominent)"},children:(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,n.jsx)(l.N,{size:40}),(0,n.jsx)("div",{style:{fontSize:16,fontWeight:600},children:e.loginTokenTitle}),(0,n.jsx)("div",{className:"text-center",style:{fontSize:12.5,color:"var(--dsw-label-caption)",lineHeight:1.55},children:e.loginTokenDesc})]})})})}},4407:(e,t,s)=>{Promise.resolve().then(s.bind(s,1965))}},e=>{e.O(0,[4686,8441,3794,7358],()=>e(e.s=4407)),_N_E=e.O()}]);