@fudrouter/fsrouter 0.6.71 → 0.6.73

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 (439) hide show
  1. package/dist/open-sse/config/appConstants.js +23 -79
  2. package/dist/open-sse/config/cliFingerprints.js +1 -1
  3. package/dist/open-sse/config/errorConfig.js +0 -11
  4. package/dist/open-sse/config/grokCli.js +10 -0
  5. package/dist/open-sse/config/kiroConstants.js +99 -46
  6. package/dist/open-sse/config/runtimeConfig.js +2 -0
  7. package/dist/open-sse/config/ttsModels.js +2 -0
  8. package/dist/open-sse/executors/antigravity.js +250 -164
  9. package/dist/open-sse/executors/base.js +16 -11
  10. package/dist/open-sse/executors/codex.js +269 -1108
  11. package/dist/open-sse/executors/commandCode.js +1 -1
  12. package/dist/open-sse/executors/commandcode.js +10 -4
  13. package/dist/open-sse/executors/cursor.js +96 -203
  14. package/dist/open-sse/executors/default.js +146 -244
  15. package/dist/open-sse/executors/github.js +128 -73
  16. package/dist/open-sse/executors/grok-cli.js +527 -94
  17. package/dist/open-sse/executors/grok-web.js +5 -7
  18. package/dist/open-sse/executors/index.js +12 -0
  19. package/dist/open-sse/executors/kiro.js +150 -61
  20. package/dist/open-sse/executors/opencode-go.js +12 -4
  21. package/dist/open-sse/executors/opencode.js +1 -1
  22. package/dist/open-sse/executors/perplexity-web.js +20 -96
  23. package/dist/open-sse/executors/qoder.js +28 -18
  24. package/dist/open-sse/executors/vertex.js +53 -7
  25. package/dist/open-sse/executors/xiaomi-tokenplan.js +6 -5
  26. package/dist/open-sse/handlers/chatCore/nonStreamingHandler.js +97 -85
  27. package/dist/open-sse/handlers/chatCore/requestDetail.js +32 -8
  28. package/dist/open-sse/handlers/chatCore/sseToJsonHandler.js +13 -7
  29. package/dist/open-sse/handlers/chatCore/streamingHandler.js +74 -25
  30. package/dist/open-sse/handlers/chatCore.js +35 -41
  31. package/dist/open-sse/handlers/embeddingProviders/index.js +1 -0
  32. package/dist/open-sse/handlers/embeddingProviders/openai.js +8 -16
  33. package/dist/open-sse/handlers/imageProviders/blackForestLabs.js +2 -21
  34. package/dist/open-sse/handlers/imageProviders/cloudflareAi.js +2 -30
  35. package/dist/open-sse/handlers/imageProviders/codex.js +2 -20
  36. package/dist/open-sse/handlers/imageProviders/comfyui.js +5 -18
  37. package/dist/open-sse/handlers/imageProviders/falAi.js +2 -22
  38. package/dist/open-sse/handlers/imageProviders/gemini.js +2 -16
  39. package/dist/open-sse/handlers/imageProviders/huggingface.js +2 -17
  40. package/dist/open-sse/handlers/imageProviders/index.js +3 -4
  41. package/dist/open-sse/handlers/imageProviders/leonardo.js +1 -1
  42. package/dist/open-sse/handlers/imageProviders/nanobanana.js +4 -23
  43. package/dist/open-sse/handlers/imageProviders/openai.js +15 -43
  44. package/dist/open-sse/handlers/imageProviders/runwayml.js +2 -26
  45. package/dist/open-sse/handlers/imageProviders/sdwebui.js +4 -20
  46. package/dist/open-sse/handlers/imageProviders/stabilityAi.js +2 -26
  47. package/dist/open-sse/handlers/imageProviders/weavy.js +1 -1
  48. package/dist/open-sse/handlers/search/chatSearch.js +60 -14
  49. package/dist/open-sse/handlers/ttsProviders/gemini.js +14 -3
  50. package/dist/open-sse/handlers/ttsProviders/index.js +4 -2
  51. package/dist/open-sse/handlers/ttsProviders/openai.js +4 -1
  52. package/dist/open-sse/handlers/ttsProviders/openrouter.js +7 -4
  53. package/dist/open-sse/handlers/videoCore.js +166 -0
  54. package/dist/open-sse/handlers/videoProviders/weavy.js +1 -1
  55. package/dist/open-sse/mcp-server/catalog.js +1 -1
  56. package/dist/open-sse/mcp-server/server.js +2 -2
  57. package/dist/open-sse/mcp-server/tools/advancedTools.js +2 -2
  58. package/dist/open-sse/mcp-server/tools/agentSkillTools.js +1 -1
  59. package/dist/open-sse/mcp-server/tools/compressionTools.js +4 -4
  60. package/dist/open-sse/mcp-server/tools/gamificationTools.js +10 -10
  61. package/dist/open-sse/mcp-server/tools/githubSkillTools.js +1 -1
  62. package/dist/open-sse/mcp-server/tools/memoryTools.js +3 -3
  63. package/dist/open-sse/mcp-server/tools/notionTools.js +2 -2
  64. package/dist/open-sse/mcp-server/tools/obsidianTools.js +2 -2
  65. package/dist/open-sse/mcp-server/tools/pickFastestModel.js +1 -1
  66. package/dist/open-sse/mcp-server/tools/pluginTools.js +4 -4
  67. package/dist/open-sse/mcp-server/tools/skillTools.js +2 -2
  68. package/dist/open-sse/providers/capabilities.js +24 -4
  69. package/dist/open-sse/providers/registry/alicode-intl.js +1 -1
  70. package/dist/open-sse/providers/registry/anthropic.js +1 -8
  71. package/dist/open-sse/providers/registry/codex.js +0 -9
  72. package/dist/open-sse/providers/registry/cohere.js +0 -2
  73. package/dist/open-sse/providers/registry/gemini.js +0 -2
  74. package/dist/open-sse/providers/registry/github.js +9 -6
  75. package/dist/open-sse/providers/registry/grok-cli.js +28 -18
  76. package/dist/open-sse/providers/registry/index.js +74 -80
  77. package/dist/open-sse/providers/registry/kiro.js +12 -0
  78. package/dist/open-sse/providers/registry/mistral.js +0 -3
  79. package/dist/open-sse/providers/registry/openai.js +0 -3
  80. package/dist/open-sse/providers/registry/perplexity.js +0 -2
  81. package/dist/open-sse/providers/registry/xai.js +5 -3
  82. package/dist/open-sse/rtk/autodetect.js +10 -2
  83. package/dist/open-sse/rtk/caveman.js +2 -93
  84. package/dist/open-sse/rtk/cavemanPrompts.js +34 -2
  85. package/dist/open-sse/rtk/constants.js +7 -2
  86. package/dist/open-sse/rtk/headroom.js +133 -0
  87. package/dist/open-sse/rtk/ponytail.js +1 -1
  88. package/dist/open-sse/rtk/registry.js +2 -0
  89. package/dist/open-sse/services/accountFallback.js +0 -108
  90. package/dist/open-sse/services/combo/quotaExhaustionCutoff.js +2 -2
  91. package/dist/open-sse/services/combo/quotaShareStrategy.js +1 -1
  92. package/dist/open-sse/services/combo/resolveAutoStrategy.js +1 -1
  93. package/dist/open-sse/services/combo/sessionStickiness.js +1 -1
  94. package/dist/open-sse/services/combo/targetSorters.js +2 -2
  95. package/dist/open-sse/services/combo/validateQuality.js +1 -1
  96. package/dist/open-sse/services/comboConfig.js +1 -1
  97. package/dist/open-sse/services/emergencyFallback.js +1 -1
  98. package/dist/open-sse/services/grokCliModels.js +127 -0
  99. package/dist/open-sse/services/model.js +7 -1
  100. package/dist/open-sse/services/provider.js +1 -1
  101. package/dist/open-sse/services/proxyAutoSelector.js +1 -1
  102. package/dist/open-sse/services/tokenRefresh/providers.js +3 -3
  103. package/dist/open-sse/services/usage/codex.js +148 -214
  104. package/dist/open-sse/services/usage/grok-cli.js +61 -7
  105. package/dist/open-sse/services/usage/misc.js +0 -19
  106. package/dist/open-sse/services/usage.js +0 -2
  107. package/dist/open-sse/translator/concerns/paramSupport.js +2 -2
  108. package/dist/open-sse/translator/concerns/thinkingUnified.js +6 -0
  109. package/dist/open-sse/translator/index.js +97 -59
  110. package/dist/open-sse/translator/request/claude-to-kiro.js +67 -40
  111. package/dist/open-sse/translator/request/openai-responses.js +1 -0
  112. package/dist/open-sse/translator/request/openai-to-commandcode.js +0 -4
  113. package/dist/open-sse/translator/request/openai-to-kiro.js +49 -20
  114. package/dist/open-sse/translator/response/commandcode-to-openai.js +0 -4
  115. package/dist/open-sse/utils/bypassHandler.js +18 -3
  116. package/dist/open-sse/utils/claudeCloaking.js +15 -5
  117. package/dist/open-sse/utils/cursorImages.js +1 -1
  118. package/dist/open-sse/utils/error.js +0 -17
  119. package/dist/open-sse/utils/keepaliveThreshold.js +4 -4
  120. package/dist/open-sse/utils/kiroSessionReplay.js +125 -0
  121. package/dist/open-sse/utils/noThinkingAlias.js +1 -1
  122. package/dist/open-sse/utils/proxyFetch.js +0 -1
  123. package/dist/open-sse/utils/reasoningContentInjector.js +4 -7
  124. package/dist/open-sse/utils/responsesStatePolicy.js +1 -1
  125. package/dist/open-sse/utils/responsesStreamHelpers.js +1 -0
  126. package/dist/open-sse/utils/sessionManager.js +49 -22
  127. package/dist/open-sse/utils/stream.js +54 -77
  128. package/dist/open-sse/utils/streamHandler.js +19 -15
  129. package/dist/open-sse/utils/streamHelpers.js +2 -17
  130. package/dist/open-sse/utils/usageTracking.js +103 -12
  131. package/open-sse/config/appConstants.js +23 -79
  132. package/open-sse/config/errorConfig.js +0 -11
  133. package/open-sse/config/grokCli.js +10 -0
  134. package/open-sse/config/kiroConstants.js +99 -46
  135. package/open-sse/config/runtimeConfig.js +2 -0
  136. package/open-sse/config/ttsModels.js +2 -0
  137. package/open-sse/executors/antigravity.js +250 -164
  138. package/open-sse/executors/base.js +16 -11
  139. package/open-sse/executors/codex.js +269 -1108
  140. package/open-sse/executors/commandcode.js +10 -4
  141. package/open-sse/executors/cursor.js +96 -203
  142. package/open-sse/executors/default.js +146 -244
  143. package/open-sse/executors/github.js +128 -73
  144. package/open-sse/executors/grok-cli.js +527 -94
  145. package/open-sse/executors/grok-web.js +5 -7
  146. package/open-sse/executors/index.js +12 -0
  147. package/open-sse/executors/kiro.js +150 -61
  148. package/open-sse/executors/opencode-go.js +12 -4
  149. package/open-sse/executors/opencode.js +1 -1
  150. package/open-sse/executors/perplexity-web.js +20 -96
  151. package/open-sse/executors/qoder.js +28 -18
  152. package/open-sse/executors/vertex.js +53 -7
  153. package/open-sse/executors/xiaomi-tokenplan.js +6 -5
  154. package/open-sse/handlers/chatCore/nonStreamingHandler.js +97 -85
  155. package/open-sse/handlers/chatCore/requestDetail.js +32 -8
  156. package/open-sse/handlers/chatCore/sseToJsonHandler.js +13 -7
  157. package/open-sse/handlers/chatCore/streamingHandler.js +74 -25
  158. package/open-sse/handlers/chatCore.js +35 -41
  159. package/open-sse/handlers/embeddingProviders/index.js +1 -0
  160. package/open-sse/handlers/embeddingProviders/openai.js +8 -16
  161. package/open-sse/handlers/imageProviders/blackForestLabs.js +2 -21
  162. package/open-sse/handlers/imageProviders/cloudflareAi.js +2 -30
  163. package/open-sse/handlers/imageProviders/codex.js +2 -20
  164. package/open-sse/handlers/imageProviders/comfyui.js +5 -18
  165. package/open-sse/handlers/imageProviders/falAi.js +2 -22
  166. package/open-sse/handlers/imageProviders/gemini.js +2 -16
  167. package/open-sse/handlers/imageProviders/huggingface.js +2 -17
  168. package/open-sse/handlers/imageProviders/index.js +3 -4
  169. package/open-sse/handlers/imageProviders/leonardo.js +1 -1
  170. package/open-sse/handlers/imageProviders/nanobanana.js +4 -23
  171. package/open-sse/handlers/imageProviders/openai.js +15 -43
  172. package/open-sse/handlers/imageProviders/runwayml.js +2 -26
  173. package/open-sse/handlers/imageProviders/sdwebui.js +4 -20
  174. package/open-sse/handlers/imageProviders/stabilityAi.js +2 -26
  175. package/open-sse/handlers/imageProviders/weavy.js +1 -1
  176. package/open-sse/handlers/search/chatSearch.js +60 -14
  177. package/open-sse/handlers/ttsProviders/gemini.js +14 -3
  178. package/open-sse/handlers/ttsProviders/index.js +4 -2
  179. package/open-sse/handlers/ttsProviders/openai.js +4 -1
  180. package/open-sse/handlers/ttsProviders/openrouter.js +7 -4
  181. package/open-sse/handlers/videoCore.js +166 -0
  182. package/open-sse/handlers/videoProviders/weavy.js +1 -1
  183. package/open-sse/mcp-server/audit.js +1 -1
  184. package/open-sse/mcp-server/catalog.js +2 -2
  185. package/open-sse/mcp-server/descriptionCompressor.js +1 -1
  186. package/open-sse/mcp-server/mcpCallerIdentity.js +1 -1
  187. package/open-sse/mcp-server/schemas/tools.js +1 -1
  188. package/open-sse/mcp-server/server.js +4 -4
  189. package/open-sse/mcp-server/tools/advancedTools.js +5 -5
  190. package/open-sse/mcp-server/tools/agentSkillTools.js +1 -1
  191. package/open-sse/mcp-server/tools/compressionTools.js +4 -4
  192. package/open-sse/mcp-server/tools/gamificationTools.js +10 -10
  193. package/open-sse/mcp-server/tools/githubSkillTools.js +1 -1
  194. package/open-sse/mcp-server/tools/memoryTools.js +3 -3
  195. package/open-sse/mcp-server/tools/notionTools.js +2 -2
  196. package/open-sse/mcp-server/tools/obsidianTools.js +2 -2
  197. package/open-sse/mcp-server/tools/pickFastestModel.js +3 -3
  198. package/open-sse/mcp-server/tools/pluginTools.js +4 -4
  199. package/open-sse/mcp-server/tools/skillTools.js +2 -2
  200. package/open-sse/providers/capabilities.js +24 -4
  201. package/open-sse/providers/registry/alicode-intl.js +1 -1
  202. package/open-sse/providers/registry/anthropic.js +1 -8
  203. package/open-sse/providers/registry/codex.js +0 -9
  204. package/open-sse/providers/registry/cohere.js +0 -2
  205. package/open-sse/providers/registry/gemini.js +0 -2
  206. package/open-sse/providers/registry/github.js +9 -6
  207. package/open-sse/providers/registry/grok-cli.js +28 -18
  208. package/open-sse/providers/registry/index.js +74 -80
  209. package/open-sse/providers/registry/kiro.js +12 -0
  210. package/open-sse/providers/registry/mistral.js +0 -3
  211. package/open-sse/providers/registry/openai.js +0 -3
  212. package/open-sse/providers/registry/perplexity.js +0 -2
  213. package/open-sse/providers/registry/xai.js +5 -3
  214. package/open-sse/rtk/autodetect.js +10 -2
  215. package/open-sse/rtk/caveman.js +2 -93
  216. package/open-sse/rtk/cavemanPrompts.js +34 -2
  217. package/open-sse/rtk/constants.js +7 -2
  218. package/open-sse/rtk/headroom.js +133 -0
  219. package/open-sse/rtk/ponytail.js +1 -1
  220. package/open-sse/rtk/registry.js +2 -0
  221. package/open-sse/services/accountFallback.js +0 -108
  222. package/open-sse/services/combo/quotaExhaustionCutoff.js +2 -2
  223. package/open-sse/services/combo/quotaShareStrategy.js +1 -1
  224. package/open-sse/services/combo/resolveAutoStrategy.js +1 -1
  225. package/open-sse/services/combo/sessionStickiness.js +1 -1
  226. package/open-sse/services/combo/shadowRouting.js +1 -1
  227. package/open-sse/services/combo/targetSorters.js +4 -4
  228. package/open-sse/services/combo/validateQuality.js +1 -1
  229. package/open-sse/services/evalRouting.js +1 -1
  230. package/open-sse/services/grokCliModels.js +127 -0
  231. package/open-sse/services/model.js +7 -1
  232. package/open-sse/services/modelCapabilities.js +1 -1
  233. package/open-sse/services/modelFamilyFallback.js +1 -1
  234. package/open-sse/services/provider.js +1 -1
  235. package/open-sse/services/providerCooldownTracker.js +1 -1
  236. package/open-sse/services/rateLimitManager.js +1 -1
  237. package/open-sse/services/tokenRefresh/providers.js +3 -3
  238. package/open-sse/services/usage/codex.js +148 -214
  239. package/open-sse/services/usage/grok-cli.js +61 -7
  240. package/open-sse/services/usage/misc.js +0 -19
  241. package/open-sse/services/usage.js +0 -2
  242. package/open-sse/translator/concerns/paramSupport.js +2 -2
  243. package/open-sse/translator/concerns/thinkingUnified.js +6 -0
  244. package/open-sse/translator/index.js +97 -59
  245. package/open-sse/translator/request/claude-to-kiro.js +67 -40
  246. package/open-sse/translator/request/openai-responses.js +1 -0
  247. package/open-sse/translator/request/openai-to-commandcode.js +0 -4
  248. package/open-sse/translator/request/openai-to-kiro.js +49 -20
  249. package/open-sse/translator/response/commandcode-to-openai.js +0 -4
  250. package/open-sse/utils/bypassHandler.js +18 -3
  251. package/open-sse/utils/claudeCloaking.js +15 -5
  252. package/open-sse/utils/error.js +0 -17
  253. package/open-sse/utils/kiroSessionReplay.js +125 -0
  254. package/open-sse/utils/logger.js +1 -1
  255. package/open-sse/utils/proxyFetch.js +0 -1
  256. package/open-sse/utils/reasoningContentInjector.js +4 -7
  257. package/open-sse/utils/responsesStreamHelpers.js +1 -0
  258. package/open-sse/utils/sessionManager.js +49 -22
  259. package/open-sse/utils/stream.js +54 -77
  260. package/open-sse/utils/streamHandler.js +19 -15
  261. package/open-sse/utils/streamHelpers.js +2 -17
  262. package/open-sse/utils/usageTracking.js +103 -12
  263. package/package.json +4 -7
  264. package/public/assets/{EndpointPageClient.CGB3HjDe.js → EndpointPageClient.LyNNvZ4z.js} +3 -3
  265. package/public/assets/{Loading.BhEzHe-X.js → Loading.Bj-WGl4k.js} +1 -1
  266. package/public/assets/{NoAuthProxyCard.Buvt0BVH.js → NoAuthProxyCard.qAv57b-0.js} +1 -1
  267. package/public/assets/{index.B-zMpSp_.js → index.CShjRV_B.js} +41 -41
  268. package/public/assets/{page.BINfJPNt.js → page.1qjqvrwX.js} +1 -1
  269. package/public/assets/{page.CfDkX9XZ.js → page.BSLJ4tx5.js} +1 -1
  270. package/public/assets/{page.D6TULIkh.js → page.BbO1pspY.js} +1 -1
  271. package/public/assets/page.BdmJ3yY3.js +5 -0
  272. package/public/assets/{page.Amtgxj_r.js → page.BnmTC5jG.js} +1 -1
  273. package/public/assets/{page.3QwV1pLl.js → page.C72FTTJr.js} +1 -1
  274. package/public/assets/{page.CdbMx9XI.js → page.CPZav1_c.js} +1 -1
  275. package/public/assets/{page.BONoTspJ.js → page.CQlVGoXg.js} +1 -1
  276. package/public/assets/{page.DgnlzpNx.js → page.CSs3-gdt.js} +1 -1
  277. package/public/assets/{page.BV28PqHr.js → page.CXd_R9yU.js} +1 -1
  278. package/public/assets/{page.5Aj6RvuD.js → page.CbkENBd5.js} +1 -1
  279. package/public/assets/{page.BAjUiqtJ.js → page.ChX1NqmC.js} +1 -1
  280. package/public/assets/page.Cj5h09Zo.js +1 -0
  281. package/public/assets/{page.CB__T51y.js → page.CnTop8Zt.js} +1 -1
  282. package/public/assets/{page.BMf0BFTW.js → page.CssmrzTT.js} +1 -1
  283. package/public/assets/{page.CVu_9TAu.js → page.CsxWmPoI.js} +1 -1
  284. package/public/assets/{page.ClXnUNhb.js → page.CzlQTyAL.js} +1 -1
  285. package/public/assets/{page.DAgwiopx.js → page.D1oKew1j.js} +1 -1
  286. package/public/assets/{page.BIG_uMBA.js → page.D5gj98Oe.js} +1 -1
  287. package/public/assets/{page.BW6Rv-_k.js → page.DBhu4Arl.js} +1 -1
  288. package/public/assets/page.DD_czjjP.js +1 -0
  289. package/public/assets/{page.BmOXfa4k.js → page.DPyOkPVo.js} +1 -1
  290. package/public/assets/{page.CTdMdgI4.js → page.DUI8kqOY.js} +1 -1
  291. package/public/assets/{page.BdPGDnx0.js → page.DVIHRbxB.js} +1 -1
  292. package/public/assets/{page.B9r7QI90.js → page.DX4Nno6M.js} +1 -1
  293. package/public/assets/{page.BCPmNscX.js → page.Dh5f0XJC.js} +1 -1
  294. package/public/assets/{page.u7XFxplU.js → page.DibhF7f-.js} +1 -1
  295. package/public/assets/{page.CDVZIbSe.js → page.DxMDTbSx.js} +1 -1
  296. package/public/assets/{page.Bb3E5EzI.js → page.Dx_GRRdT.js} +1 -1
  297. package/public/assets/{page.DhcizW_i.js → page.DzZLqI5Q.js} +1 -1
  298. package/public/assets/{page.CF5pD5lz.js → page.Ir7KvKcF.js} +1 -1
  299. package/public/assets/{page.Bj0au_ka.js → page.O2ddJYoT.js} +3 -3
  300. package/public/assets/{page.DIrcssm-.js → page.Qkkv8roc.js} +1 -1
  301. package/public/assets/{page.CrzjUbZg.js → page.i4KDuWcM.js} +1 -1
  302. package/public/assets/{page.1gncE-Vr.js → page.sOFOrxqq.js} +1 -1
  303. package/public/assets/{page.DskvkVIF.js → page.vla5Mzki.js} +1 -1
  304. package/public/index.html +1 -1
  305. package/public/assets/EndpointPageClient.Cee8kfmV.js +0 -6
  306. package/public/assets/EndpointPageClient.DdAfxJoK.js +0 -6
  307. package/public/assets/EndpointPageClient.GpJ_FKds.js +0 -6
  308. package/public/assets/Loading.DFkQ-Ly9.js +0 -1
  309. package/public/assets/Loading.DaQG3sHF.js +0 -1
  310. package/public/assets/Loading.QMOYJhLu.js +0 -1
  311. package/public/assets/NoAuthProxyCard.C18iZ3Fk.js +0 -89
  312. package/public/assets/NoAuthProxyCard.DyEjms20.js +0 -89
  313. package/public/assets/NoAuthProxyCard.VRP7gDcs.js +0 -89
  314. package/public/assets/index.CoYbjSIL.js +0 -89
  315. package/public/assets/index.DQDDDpp7.js +0 -89
  316. package/public/assets/index.KMEObSAk.js +0 -89
  317. package/public/assets/page.A7FRfarX.js +0 -1
  318. package/public/assets/page.B1a01Vfg.js +0 -1
  319. package/public/assets/page.B7h6EPVo.js +0 -1
  320. package/public/assets/page.BBMJAyy7.js +0 -1
  321. package/public/assets/page.BBSUQskO.js +0 -64
  322. package/public/assets/page.BFENid_V.js +0 -31
  323. package/public/assets/page.BJzBUr1v.js +0 -2
  324. package/public/assets/page.BKM5Up2Y.js +0 -1
  325. package/public/assets/page.BLUEyope.js +0 -1
  326. package/public/assets/page.BMeBT03D.js +0 -5
  327. package/public/assets/page.BQwH91-m.js +0 -1
  328. package/public/assets/page.BRgXbpJe.js +0 -1
  329. package/public/assets/page.BXq7Sixg.js +0 -1
  330. package/public/assets/page.Bbf1xxJj.js +0 -1
  331. package/public/assets/page.BcuklMLO.js +0 -2
  332. package/public/assets/page.Bi5OEfgq.js +0 -1
  333. package/public/assets/page.Bi9gIWN0.js +0 -1
  334. package/public/assets/page.BiLGOe6j.js +0 -1
  335. package/public/assets/page.BicDCwTa.js +0 -1
  336. package/public/assets/page.Bjd38gaf.js +0 -1
  337. package/public/assets/page.Bqk4tX-5.js +0 -1
  338. package/public/assets/page.BrrSjbBJ.js +0 -1
  339. package/public/assets/page.BsUeE2Y_.js +0 -1
  340. package/public/assets/page.BthVvW1e.js +0 -64
  341. package/public/assets/page.BxAWh20c.js +0 -1
  342. package/public/assets/page.C-2GmPmS.js +0 -4
  343. package/public/assets/page.C27wrrub.js +0 -1
  344. package/public/assets/page.C3FwsCq_.js +0 -23
  345. package/public/assets/page.C4RMU4Xv.js +0 -23
  346. package/public/assets/page.C7SC9vwX.js +0 -1
  347. package/public/assets/page.C8gTAwsH.js +0 -5
  348. package/public/assets/page.CECQKY1y.js +0 -5
  349. package/public/assets/page.CEN8xgCA.js +0 -1
  350. package/public/assets/page.CHG9mx5l.js +0 -1
  351. package/public/assets/page.CMUOu9fe.js +0 -1
  352. package/public/assets/page.CRex977Y.js +0 -5
  353. package/public/assets/page.CUsb0F5t.js +0 -1
  354. package/public/assets/page.CXE5AWV3.js +0 -1
  355. package/public/assets/page.CXIP8Wzi.js +0 -4
  356. package/public/assets/page.CXOuLQhq.js +0 -1
  357. package/public/assets/page.CXPMjDX9.js +0 -1
  358. package/public/assets/page.CXPPlybJ.js +0 -6
  359. package/public/assets/page.CYfjd9SF.js +0 -1
  360. package/public/assets/page.CZtbttgE.js +0 -1
  361. package/public/assets/page.CbOSwuwi.js +0 -1
  362. package/public/assets/page.CbWWyTC4.js +0 -1
  363. package/public/assets/page.CfXJWUgA.js +0 -1
  364. package/public/assets/page.CfdTLncK.js +0 -1
  365. package/public/assets/page.ChqEg6y-.js +0 -1
  366. package/public/assets/page.CmbatQd6.js +0 -4
  367. package/public/assets/page.Cp7XaHGI.js +0 -1
  368. package/public/assets/page.CqR-Z0pY.js +0 -1
  369. package/public/assets/page.CsLBZFbk.js +0 -1
  370. package/public/assets/page.CyqTG9Kn.js +0 -2
  371. package/public/assets/page.CzKSjT-r.js +0 -1
  372. package/public/assets/page.D1S50DvR.js +0 -1
  373. package/public/assets/page.D3b1o69R.js +0 -5
  374. package/public/assets/page.D5B_p_2E.js +0 -31
  375. package/public/assets/page.D8X-8LSd.js +0 -2
  376. package/public/assets/page.DA2dX7iN.js +0 -1
  377. package/public/assets/page.DBNjxgJS.js +0 -6
  378. package/public/assets/page.DEBBy5qz.js +0 -1
  379. package/public/assets/page.DEOXc6iv.js +0 -6
  380. package/public/assets/page.DG46DZcu.js +0 -1
  381. package/public/assets/page.DGAKp9YS.js +0 -1
  382. package/public/assets/page.DGico7sP.js +0 -1
  383. package/public/assets/page.DHBHS2oS.js +0 -1
  384. package/public/assets/page.DKdtfq8E.js +0 -2
  385. package/public/assets/page.DKj8qFYb.js +0 -1
  386. package/public/assets/page.DNofNt4p.js +0 -1
  387. package/public/assets/page.DVdv-E5d.js +0 -1
  388. package/public/assets/page.Da-kutqN.js +0 -1
  389. package/public/assets/page.DaW7T6nt.js +0 -1
  390. package/public/assets/page.DhPzWwGm.js +0 -1
  391. package/public/assets/page.Dju6Kwa5.js +0 -1
  392. package/public/assets/page.Dlh3Q_rt.js +0 -1
  393. package/public/assets/page.DmNhmYKk.js +0 -64
  394. package/public/assets/page.Dmvhu2ua.js +0 -1
  395. package/public/assets/page.Dp30ZzXE.js +0 -1
  396. package/public/assets/page.DsY8qNEU.js +0 -1
  397. package/public/assets/page.DtGEStU7.js +0 -1
  398. package/public/assets/page.DuXsnK8A.js +0 -1
  399. package/public/assets/page.DwU6Ubqf.js +0 -1
  400. package/public/assets/page.FmrKiZlG.js +0 -2
  401. package/public/assets/page.GSAm83Cv.js +0 -6
  402. package/public/assets/page.IgH-AWcu.js +0 -1
  403. package/public/assets/page.Ii8wGSnt.js +0 -1
  404. package/public/assets/page.KtURQA9Q.js +0 -1
  405. package/public/assets/page.NFGJtdfx.js +0 -1
  406. package/public/assets/page.QPaIzKAa.js +0 -1
  407. package/public/assets/page.QuBXfL80.js +0 -1
  408. package/public/assets/page.S02TdGZT.js +0 -1
  409. package/public/assets/page.V3CmUOJF.js +0 -1
  410. package/public/assets/page.VClP2n2B.js +0 -1
  411. package/public/assets/page.Vo9Oe8DJ.js +0 -1
  412. package/public/assets/page.WIMFvXoG.js +0 -1
  413. package/public/assets/page.XUya1XZj.js +0 -23
  414. package/public/assets/page.XqKIvnmq.js +0 -31
  415. package/public/assets/page.aAUPKg0H.js +0 -1
  416. package/public/assets/page.aRQdaBbf.js +0 -1
  417. package/public/assets/page.e-Zxfi03.js +0 -1
  418. package/public/assets/page.e-cA5aB5.js +0 -6
  419. package/public/assets/page.eNXd9f58.js +0 -6
  420. package/public/assets/page.gj2B5h2d.js +0 -1
  421. package/public/assets/page.gvZgqycR.js +0 -1
  422. package/public/assets/page.jvowBQYJ.js +0 -1
  423. package/public/assets/page.k_WzlZwU.js +0 -5
  424. package/public/assets/page.qK1RUb_S.js +0 -1
  425. package/public/assets/page.ryYPRTww.js +0 -1
  426. package/public/assets/page.xm98_0dX.js +0 -5
  427. package/public/assets/page.yjCJ-4Uh.js +0 -1
  428. package/public/providers/agentrouter.webp +0 -0
  429. package/public/providers/codebuddy-cn.webp +0 -0
  430. package/public/providers/gigachat.webp +0 -0
  431. package/public/providers/heroku.webp +0 -0
  432. package/public/providers/kimchi.webp +0 -0
  433. package/public/providers/llamagate.webp +0 -0
  434. package/public/providers/mimo-free.webp +0 -0
  435. package/public/providers/nanogpt.webp +0 -0
  436. package/public/providers/nscale.webp +0 -0
  437. package/public/providers/ovhcloud.webp +0 -0
  438. package/public/providers/predibase.webp +0 -0
  439. package/public/providers/zcode.webp +0 -0
@@ -1,6 +1,6 @@
1
- import{p as Lt,q as Us,u as As,j as e,B as c,M as B,C as Rs,f as Is}from"./index.DQDDDpp7.js";import{b as a}from"./router.Cjj1--8t.js";import{C as Ze,I as G,T as L}from"./NoAuthProxyCard.C18iZ3Fk.js";import{C as _t}from"./Loading.DaQG3sHF.js";const Ds=["zh-CN","zh-TW"],Os=[{icon:"public",title:"Access Anywhere",desc:"Use your API from any network"},{icon:"group",title:"Share Endpoint",desc:"Share URL with team members"},{icon:"code",title:"Use in Cursor/Cline",desc:"Connect AI tools remotely"},{icon:"lock",title:"Encrypted",desc:"End-to-end TLS via Cloudflare"}],et=2e3,Ut=3e5,Hs=5e3,tt=5,Ms=1e4,Fs=5e3;async function At(h){if(!h)return!1;try{return(await fetch(`${h}/api/health`,{mode:"cors",cache:"no-store",signal:AbortSignal.timeout(Fs)})).ok}catch{return!1}}async function Ks(...h){const d=h.filter(Boolean).map(At);return d.length?new Promise(x=>{let j=d.length;d.forEach(R=>R.then(g=>{g?x(!0):--j===0&&x(!1)}))}):!1}const ve=[{id:"lite",label:"Lite",desc:"Drop filler, keep grammar"},{id:"full",label:"Full",desc:"Drop articles, fragments OK"},{id:"ultra",label:"Ultra",desc:"Telegraphic, max compression"},{id:"wenyan-lite",label:"文 Lite",desc:"Classical Chinese, light compression",wenyan:!0},{id:"wenyan",label:"文 Full",desc:"Maximum 文言文, 80-90% reduction",wenyan:!0},{id:"wenyan-ultra",label:"文 Ultra",desc:"Extreme classical compression",wenyan:!0}];function Ws({machineId:h}){var Pt;const[d,x]=a.useState([]),[j,R]=a.useState(!0),[g,C]=a.useState(!1),[ne,le]=a.useState(""),[Te,Se]=a.useState(null),[w,J]=a.useState(null),[re,st]=a.useState(!1),[V,Rt]=a.useState(!0),[at,It]=a.useState(!0),[nt,lt]=a.useState(!1),[rt,it]=a.useState(!0),[Ee,ot]=a.useState(!1),[ie,Pe]=a.useState("full"),[Le,ct]=a.useState(!1),[_e,Ue]=a.useState(""),[Dt,dt]=a.useState(!1),[I,Ae]=a.useState({installed:!1,running:!1,python:null,loading:!0}),[Bs,Gs]=a.useState(!1),[oe,ce]=a.useState(!1),[Js,mt]=a.useState(""),[Re,ut]=a.useState(!1),[Ie,ht]=a.useState("full"),[De,xt]=a.useState(!1),[Oe,pt]=a.useState("full"),[Ot,ft]=a.useState("en"),[Ht,He]=a.useState(!0),[p,de]=a.useState(!1),[D,me]=a.useState(!1),[O,ue]=a.useState(""),[H,Me]=a.useState(""),[_,T]=a.useState(!1),[Mt,S]=a.useState(""),[he,N]=a.useState(null),[Ft,Y]=a.useState(!1),[Kt,X]=a.useState(!1),[f,M]=a.useState(!1),[F,xe]=a.useState(!1),[K,W]=a.useState(""),[U,Q]=a.useState(!1),[Wt,A]=a.useState(""),[q,m]=a.useState(null),[bt,gt]=a.useState(""),[qt,yt]=a.useState(""),[Fe,pe]=a.useState(null),[fe,Ke]=a.useState(!1),[We,qe]=a.useState([]),[$t,jt]=a.useState(""),[zt,$e]=a.useState(!1),[Bt,$]=a.useState(!1),[Gt,Z]=a.useState(!1),be=a.useRef(null),ee=a.useRef(0),te=a.useRef(0),ge=a.useRef(!1),ye=a.useRef(!1),je=a.useRef(!1),we=a.useRef(!1),[Jt,ze]=a.useState(!1),[Vt,Be]=a.useState(!1),[Ge,wt]=a.useState(new Set),[Yt,Xt]=a.useState(!1);a.useEffect(()=>{typeof window<"u"&&Xt(!["localhost","127.0.0.1","::1"].includes(window.location.hostname))},[]),a.useEffect(()=>(ft(Lt()),Us(()=>ft(Lt()))),[]);const Je=Ds.includes(Ot),Qt=Je?ve:ve.filter(t=>!t.wenyan);a.useEffect(()=>{const t=ve.find(s=>s.id===ie);t!=null&&t.wenyan&&!Je&&(Pe("ultra"),k({cavemanLevel:"ultra"}))},[Je,ie]);const{copied:z,copy:se}=As(),Zt=!V||!at,es=V?"Change the default dashboard password before activating the tunnel.":'Enable "Require login" and set a custom password before activating the tunnel.';a.useEffect(()=>{be.current&&(be.current.scrollTop=be.current.scrollHeight)},[We]),a.useEffect(()=>{kt(),ts()},[]),a.useEffect(()=>{if(!(p||f))return;const n=(!p||D)&&(!f||F),r=()=>{document.hidden||Nt()};if(document.addEventListener("visibilitychange",r),n)return()=>document.removeEventListener("visibilitychange",r);const o=setInterval(()=>{document.hidden||Nt()},Hs);return()=>{clearInterval(o),document.removeEventListener("visibilitychange",r)}},[p,f,D,F]),a.useEffect(()=>{const t=async()=>{if(!document.hidden){if(p&&(O||H)){const o=await Ks(H,O);ge.current=o,o?(ee.current=0,me(!0),je.current||(je.current=!0,ze(!0))):(ee.current+=1,ee.current>=tt&&me(!1))}else ge.current=!1;if(f&&K){const o=await At(K);ye.current=o,o?(te.current=0,xe(!0),we.current||(we.current=!0,Be(!0))):(te.current+=1,te.current>=tt&&xe(!1))}else ye.current=!1}};if(!(p&&(O||H)||f&&K)||(t(),(!p||D)&&(!f||F)))return;const r=setInterval(t,Ms);return()=>clearInterval(r)},[p,O,H,f,K,D,F]);const Ne=a.useCallback((t,s,l,n,r,o)=>{s.current?(l.current=0,n(!0),r.current||(r.current=!0,o(!0))):(l.current+=1,l.current>=tt&&n(!1))},[]),Nt=async()=>{var t,s,l,n,r,o,u;try{const y=await fetch("/api/tunnel/status",{cache:"no-store"});if(!y.ok)return;const b=await y.json(),i=((t=b.tunnel)==null?void 0:t.settingsEnabled)??((s=b.tunnel)==null?void 0:s.enabled)??!1,P=((l=b.tunnel)==null?void 0:l.tunnelUrl)||"";ue(P),Me(((n=b.tunnel)==null?void 0:n.publicUrl)||""),de(i),Ne(null,ge,ee,me,je,ze);const v=((r=b.tailscale)==null?void 0:r.settingsEnabled)??((o=b.tailscale)==null?void 0:o.enabled)??!1,Qe=((u=b.tailscale)==null?void 0:u.tunnelUrl)||"";W(Qe),M(v),Ne(null,ye,te,xe,we,Be)}catch{}},ts=async()=>{var t,s,l,n,r,o,u;He(!0);try{const[y,b]=await Promise.all([fetch("/api/settings"),fetch("/api/tunnel/status",{cache:"no-store"})]);if(y.ok){const i=await y.json();st(i.requireApiKey||!1),Rt(i.requireLogin!==!1),It(i.hasPassword||!1),lt(i.tunnelDashboardAccess||!1),it(i.rtkEnabled!==!1),ot(!!i.cavemanEnabled),Pe(i.cavemanLevel||"full"),ct(!!i.headroomEnabled),Ue(i.headroomUrl||""),dt(!!i.headroomCompressUserMessages),ut(!!i.ponytailEnabled),ht(i.ponytailLevel||"full"),xt(!!i.paleoEnabled),pt(i.paleoLevel||"full"),ae()}if(b.ok){const i=await b.json(),P=((t=i.tunnel)==null?void 0:t.settingsEnabled)??((s=i.tunnel)==null?void 0:s.enabled)??!1,v=((l=i.tunnel)==null?void 0:l.tunnelUrl)||"";ue(v),Me(((n=i.tunnel)==null?void 0:n.publicUrl)||""),de(P),Ne(null,ge,ee,me,je,ze);const Qe=((r=i.tailscale)==null?void 0:r.settingsEnabled)??((o=i.tailscale)==null?void 0:o.enabled)??!1,_s=((u=i.tailscale)==null?void 0:u.tunnelUrl)||"";W(_s),M(Qe),Ne(null,ye,te,xe,we,Be)}}catch(y){console.log("Error loading settings:",y)}finally{He(!1)}},ss=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tunnelDashboardAccess:t})})).ok&&lt(t)}catch(s){console.log("Error updating tunnelDashboardAccess:",s)}},as=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({requireApiKey:t})})).ok&&st(t)}catch(s){console.log("Error updating requireApiKey:",s)}},ns=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({rtkEnabled:t})})).ok&&it(t)}catch(s){console.log("Error updating rtkEnabled:",s)}},k=async t=>{try{await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(s){console.log("Error updating setting:",s)}},ls=t=>{ot(t),k({cavemanEnabled:t})},rs=t=>{Pe(t),k({cavemanLevel:t})},is=t=>{ct(t),k({headroomEnabled:t})},os=t=>{Ue(t),k({headroomUrl:t})},cs=t=>{dt(t),k({headroomCompressUserMessages:t})},ae=a.useCallback(async()=>{Ae(t=>({...t,loading:!0}));try{const s=await(await fetch("/api/headroom/status",{headers:{"Cache-Control":"no-store"}})).json();Ae({...s,loading:!1}),s.url&&!_e&&Ue(s.url)}catch{Ae({installed:!1,running:!1,python:null,loading:!1})}},[_e]),ds=a.useCallback(async()=>{mt(""),ce(!0);try{const t=await fetch("/api/headroom/start",{method:"POST"}),s=await t.json().catch(()=>({}));if(!t.ok)throw new Error(s.error||"Failed to start proxy");await ae()}catch(t){mt(t.message)}finally{ce(!1)}},[ae]),ms=a.useCallback(async()=>{ce(!0);try{await fetch("/api/headroom/stop",{method:"POST"}),await ae()}finally{ce(!1)}},[ae]),us=t=>{ut(t),k({ponytailEnabled:t})},hs=t=>{ht(t),k({ponytailLevel:t})},xs=t=>{xt(t),k({paleoEnabled:t})},ps=t=>{pt(t),k({paleoLevel:t})},kt=async()=>{try{const t=await fetch("/api/keys"),s=await t.json();t.ok&&x(s.keys||[])}catch(t){console.log("Error fetching data:",t)}finally{R(!1)}},fs=async(...t)=>{var n;T(!0),S("Waiting for tunnel ready...");const s=t.filter(Boolean).map(r=>`${r}/api/health`),l=Date.now();for(;Date.now()-l<Ut;){if(await new Promise(o=>setTimeout(o,et)),await Promise.any(s.map(async o=>{if((await fetch(o,{mode:"cors",cache:"no-store"})).ok)return!0;throw new Error("not ready")})).catch(()=>!1))return de(!0),T(!1),S(""),!0;if((Date.now()-l)%1e4<et)try{const o=await fetch("/api/tunnel/status");if(o.ok&&!((n=(await o.json()).tunnel)!=null&&n.enabled))return N({type:"error",message:"Tunnel process stopped unexpectedly."}),T(!1),S(""),!1}catch{}}return N({type:"error",message:"Tunnel created but not reachable. Please try again."}),T(!1),S(""),!1},bs=async()=>{Y(!1),T(!0),N(null),S("Creating tunnel...");let t=!0;(async()=>{var l;for(;t;){try{const n=await fetch("/api/tunnel/status");if(n.ok){const r=await n.json();(l=r.download)!=null&&l.downloading?S(`Downloading cloudflared... ${r.download.progress}%`):t&&S("Creating tunnel...")}}catch{}await new Promise(n=>setTimeout(n,1e3))}})();try{const l=await fetch("/api/tunnel/enable",{method:"POST"});t=!1;const n=await l.json();if(!l.ok){N({type:"error",message:n.error||"Failed to enable tunnel"});return}const r=n.tunnelUrl;if(!r){N({type:"error",message:"No tunnel URL returned"});return}ue(r),Me(n.publicUrl||""),await fs(n.publicUrl,r)}catch(l){N({type:"error",message:l.message})}finally{t=!1,T(!1),S("")}},gs=async()=>{T(!0),N(null);try{const t=await fetch("/api/tunnel/disable",{method:"POST"}),s=await t.json();t.ok?(de(!1),ue(""),X(!1),N({type:"success",message:"Tunnel disabled"})):N({type:"error",message:s.error||"Failed to disable tunnel"})}catch(t){N({type:"error",message:t.message})}finally{T(!1)}},ys=async()=>{pe(null);try{const t=await fetch("/api/tunnel/tailscale-check");if(t.ok){const s=await t.json();return pe(s.installed),s}}catch{}return pe(!1),{installed:!1}},js=async()=>{Ke(!0),m(null),qe([]);try{const t=await fetch("/api/tunnel/tailscale-install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sudoPassword:$t})});jt("");const s=t.body.getReader(),l=new TextDecoder;let n="";for(;;){const{done:r,value:o}=await s.read();if(r)break;n+=l.decode(o,{stream:!0});const u=n.split(`
1
+ import{r as Lt,v as Us,u as As,j as e,B as c,M as B,C as Rs,f as Is}from"./index.CShjRV_B.js";import{b as a}from"./router.Cjj1--8t.js";import{C as Ze,I as G,T as L}from"./NoAuthProxyCard.qAv57b-0.js";import{C as _t}from"./Loading.Bj-WGl4k.js";const Ds=["zh-CN","zh-TW"],Os=[{icon:"public",title:"Access Anywhere",desc:"Use your API from any network"},{icon:"group",title:"Share Endpoint",desc:"Share URL with team members"},{icon:"code",title:"Use in Cursor/Cline",desc:"Connect AI tools remotely"},{icon:"lock",title:"Encrypted",desc:"End-to-end TLS via Cloudflare"}],et=2e3,Ut=3e5,Hs=5e3,tt=5,Ms=1e4,Fs=5e3;async function At(h){if(!h)return!1;try{return(await fetch(`${h}/api/health`,{mode:"cors",cache:"no-store",signal:AbortSignal.timeout(Fs)})).ok}catch{return!1}}async function Ks(...h){const d=h.filter(Boolean).map(At);return d.length?new Promise(x=>{let j=d.length;d.forEach(R=>R.then(g=>{g?x(!0):--j===0&&x(!1)}))}):!1}const ke=[{id:"lite",label:"Lite",desc:"Drop filler, keep grammar"},{id:"full",label:"Full",desc:"Drop articles, fragments OK"},{id:"ultra",label:"Ultra",desc:"Telegraphic, max compression"},{id:"wenyan-lite",label:"文 Lite",desc:"Classical Chinese, light compression",wenyan:!0},{id:"wenyan",label:"文 Full",desc:"Maximum 文言文, 80-90% reduction",wenyan:!0},{id:"wenyan-ultra",label:"文 Ultra",desc:"Extreme classical compression",wenyan:!0}];function Ws({machineId:h}){var Pt;const[d,x]=a.useState([]),[j,R]=a.useState(!0),[g,C]=a.useState(!1),[ne,le]=a.useState(""),[Te,Se]=a.useState(null),[w,J]=a.useState(null),[re,st]=a.useState(!1),[V,Rt]=a.useState(!0),[at,It]=a.useState(!0),[nt,lt]=a.useState(!1),[rt,it]=a.useState(!0),[Ee,ot]=a.useState(!1),[ie,Pe]=a.useState("full"),[Le,ct]=a.useState(!1),[_e,Ue]=a.useState(""),[Dt,dt]=a.useState(!1),[I,Ae]=a.useState({installed:!1,running:!1,python:null,loading:!0}),[Bs,Gs]=a.useState(!1),[oe,ce]=a.useState(!1),[Js,mt]=a.useState(""),[Re,ut]=a.useState(!1),[Ie,ht]=a.useState("full"),[De,xt]=a.useState(!1),[Oe,pt]=a.useState("full"),[Ot,ft]=a.useState("en"),[Ht,He]=a.useState(!0),[p,de]=a.useState(!1),[D,me]=a.useState(!1),[O,ue]=a.useState(""),[H,Me]=a.useState(""),[_,T]=a.useState(!1),[Mt,S]=a.useState(""),[he,N]=a.useState(null),[Ft,Y]=a.useState(!1),[Kt,X]=a.useState(!1),[f,M]=a.useState(!1),[F,xe]=a.useState(!1),[K,W]=a.useState(""),[U,Q]=a.useState(!1),[Wt,A]=a.useState(""),[q,m]=a.useState(null),[bt,gt]=a.useState(""),[qt,yt]=a.useState(""),[Fe,pe]=a.useState(null),[fe,Ke]=a.useState(!1),[We,qe]=a.useState([]),[$t,jt]=a.useState(""),[zt,$e]=a.useState(!1),[Bt,$]=a.useState(!1),[Gt,Z]=a.useState(!1),be=a.useRef(null),ee=a.useRef(0),te=a.useRef(0),ge=a.useRef(!1),ye=a.useRef(!1),je=a.useRef(!1),we=a.useRef(!1),[Jt,ze]=a.useState(!1),[Vt,Be]=a.useState(!1),[Ge,wt]=a.useState(new Set),[Yt,Xt]=a.useState(!1);a.useEffect(()=>{typeof window<"u"&&Xt(!["localhost","127.0.0.1","::1"].includes(window.location.hostname))},[]),a.useEffect(()=>(ft(Lt()),Us(()=>ft(Lt()))),[]);const Je=Ds.includes(Ot),Qt=Je?ke:ke.filter(t=>!t.wenyan);a.useEffect(()=>{const t=ke.find(s=>s.id===ie);t!=null&&t.wenyan&&!Je&&(Pe("ultra"),v({cavemanLevel:"ultra"}))},[Je,ie]);const{copied:z,copy:se}=As(),Zt=!V||!at,es=V?"Change the default dashboard password before activating the tunnel.":'Enable "Require login" and set a custom password before activating the tunnel.';a.useEffect(()=>{be.current&&(be.current.scrollTop=be.current.scrollHeight)},[We]),a.useEffect(()=>{vt(),ts()},[]),a.useEffect(()=>{if(!(p||f))return;const n=(!p||D)&&(!f||F),r=()=>{document.hidden||Nt()};if(document.addEventListener("visibilitychange",r),n)return()=>document.removeEventListener("visibilitychange",r);const o=setInterval(()=>{document.hidden||Nt()},Hs);return()=>{clearInterval(o),document.removeEventListener("visibilitychange",r)}},[p,f,D,F]),a.useEffect(()=>{const t=async()=>{if(!document.hidden){if(p&&(O||H)){const o=await Ks(H,O);ge.current=o,o?(ee.current=0,me(!0),je.current||(je.current=!0,ze(!0))):(ee.current+=1,ee.current>=tt&&me(!1))}else ge.current=!1;if(f&&K){const o=await At(K);ye.current=o,o?(te.current=0,xe(!0),we.current||(we.current=!0,Be(!0))):(te.current+=1,te.current>=tt&&xe(!1))}else ye.current=!1}};if(!(p&&(O||H)||f&&K)||(t(),(!p||D)&&(!f||F)))return;const r=setInterval(t,Ms);return()=>clearInterval(r)},[p,O,H,f,K,D,F]);const Ne=a.useCallback((t,s,l,n,r,o)=>{s.current?(l.current=0,n(!0),r.current||(r.current=!0,o(!0))):(l.current+=1,l.current>=tt&&n(!1))},[]),Nt=async()=>{var t,s,l,n,r,o,u;try{const y=await fetch("/api/tunnel/status",{cache:"no-store"});if(!y.ok)return;const b=await y.json(),i=((t=b.tunnel)==null?void 0:t.settingsEnabled)??((s=b.tunnel)==null?void 0:s.enabled)??!1,P=((l=b.tunnel)==null?void 0:l.tunnelUrl)||"";ue(P),Me(((n=b.tunnel)==null?void 0:n.publicUrl)||""),de(i),Ne(null,ge,ee,me,je,ze);const k=((r=b.tailscale)==null?void 0:r.settingsEnabled)??((o=b.tailscale)==null?void 0:o.enabled)??!1,Qe=((u=b.tailscale)==null?void 0:u.tunnelUrl)||"";W(Qe),M(k),Ne(null,ye,te,xe,we,Be)}catch{}},ts=async()=>{var t,s,l,n,r,o,u;He(!0);try{const[y,b]=await Promise.all([fetch("/api/settings"),fetch("/api/tunnel/status",{cache:"no-store"})]);if(y.ok){const i=await y.json();st(i.requireApiKey||!1),Rt(i.requireLogin!==!1),It(i.hasPassword||!1),lt(i.tunnelDashboardAccess||!1),it(i.rtkEnabled!==!1),ot(!!i.cavemanEnabled),Pe(i.cavemanLevel||"full"),ct(!!i.headroomEnabled),Ue(i.headroomUrl||""),dt(!!i.headroomCompressUserMessages),ut(!!i.ponytailEnabled),ht(i.ponytailLevel||"full"),xt(!!i.paleoEnabled),pt(i.paleoLevel||"full"),ae()}if(b.ok){const i=await b.json(),P=((t=i.tunnel)==null?void 0:t.settingsEnabled)??((s=i.tunnel)==null?void 0:s.enabled)??!1,k=((l=i.tunnel)==null?void 0:l.tunnelUrl)||"";ue(k),Me(((n=i.tunnel)==null?void 0:n.publicUrl)||""),de(P),Ne(null,ge,ee,me,je,ze);const Qe=((r=i.tailscale)==null?void 0:r.settingsEnabled)??((o=i.tailscale)==null?void 0:o.enabled)??!1,_s=((u=i.tailscale)==null?void 0:u.tunnelUrl)||"";W(_s),M(Qe),Ne(null,ye,te,xe,we,Be)}}catch(y){console.log("Error loading settings:",y)}finally{He(!1)}},ss=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tunnelDashboardAccess:t})})).ok&&lt(t)}catch(s){console.log("Error updating tunnelDashboardAccess:",s)}},as=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({requireApiKey:t})})).ok&&st(t)}catch(s){console.log("Error updating requireApiKey:",s)}},ns=async t=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({rtkEnabled:t})})).ok&&it(t)}catch(s){console.log("Error updating rtkEnabled:",s)}},v=async t=>{try{await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(s){console.log("Error updating setting:",s)}},ls=t=>{ot(t),v({cavemanEnabled:t})},rs=t=>{Pe(t),v({cavemanLevel:t})},is=t=>{ct(t),v({headroomEnabled:t})},os=t=>{Ue(t),v({headroomUrl:t})},cs=t=>{dt(t),v({headroomCompressUserMessages:t})},ae=a.useCallback(async()=>{Ae(t=>({...t,loading:!0}));try{const s=await(await fetch("/api/headroom/status",{headers:{"Cache-Control":"no-store"}})).json();Ae({...s,loading:!1}),s.url&&!_e&&Ue(s.url)}catch{Ae({installed:!1,running:!1,python:null,loading:!1})}},[_e]),ds=a.useCallback(async()=>{mt(""),ce(!0);try{const t=await fetch("/api/headroom/start",{method:"POST"}),s=await t.json().catch(()=>({}));if(!t.ok)throw new Error(s.error||"Failed to start proxy");await ae()}catch(t){mt(t.message)}finally{ce(!1)}},[ae]),ms=a.useCallback(async()=>{ce(!0);try{await fetch("/api/headroom/stop",{method:"POST"}),await ae()}finally{ce(!1)}},[ae]),us=t=>{ut(t),v({ponytailEnabled:t})},hs=t=>{ht(t),v({ponytailLevel:t})},xs=t=>{xt(t),v({paleoEnabled:t})},ps=t=>{pt(t),v({paleoLevel:t})},vt=async()=>{try{const t=await fetch("/api/keys"),s=await t.json();t.ok&&x(s.keys||[])}catch(t){console.log("Error fetching data:",t)}finally{R(!1)}},fs=async(...t)=>{var n;T(!0),S("Waiting for tunnel ready...");const s=t.filter(Boolean).map(r=>`${r}/api/health`),l=Date.now();for(;Date.now()-l<Ut;){if(await new Promise(o=>setTimeout(o,et)),await Promise.any(s.map(async o=>{if((await fetch(o,{mode:"cors",cache:"no-store"})).ok)return!0;throw new Error("not ready")})).catch(()=>!1))return de(!0),T(!1),S(""),!0;if((Date.now()-l)%1e4<et)try{const o=await fetch("/api/tunnel/status");if(o.ok&&!((n=(await o.json()).tunnel)!=null&&n.enabled))return N({type:"error",message:"Tunnel process stopped unexpectedly."}),T(!1),S(""),!1}catch{}}return N({type:"error",message:"Tunnel created but not reachable. Please try again."}),T(!1),S(""),!1},bs=async()=>{Y(!1),T(!0),N(null),S("Creating tunnel...");let t=!0;(async()=>{var l;for(;t;){try{const n=await fetch("/api/tunnel/status");if(n.ok){const r=await n.json();(l=r.download)!=null&&l.downloading?S(`Downloading cloudflared... ${r.download.progress}%`):t&&S("Creating tunnel...")}}catch{}await new Promise(n=>setTimeout(n,1e3))}})();try{const l=await fetch("/api/tunnel/enable",{method:"POST"});t=!1;const n=await l.json();if(!l.ok){N({type:"error",message:n.error||"Failed to enable tunnel"});return}const r=n.tunnelUrl;if(!r){N({type:"error",message:"No tunnel URL returned"});return}ue(r),Me(n.publicUrl||""),await fs(n.publicUrl,r)}catch(l){N({type:"error",message:l.message})}finally{t=!1,T(!1),S("")}},gs=async()=>{T(!0),N(null);try{const t=await fetch("/api/tunnel/disable",{method:"POST"}),s=await t.json();t.ok?(de(!1),ue(""),X(!1),N({type:"success",message:"Tunnel disabled"})):N({type:"error",message:s.error||"Failed to disable tunnel"})}catch(t){N({type:"error",message:t.message})}finally{T(!1)}},ys=async()=>{pe(null);try{const t=await fetch("/api/tunnel/tailscale-check");if(t.ok){const s=await t.json();return pe(s.installed),s}}catch{}return pe(!1),{installed:!1}},js=async()=>{Ke(!0),m(null),qe([]);try{const t=await fetch("/api/tunnel/tailscale-install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sudoPassword:$t})});jt("");const s=t.body.getReader(),l=new TextDecoder;let n="";for(;;){const{done:r,value:o}=await s.read();if(r)break;n+=l.decode(o,{stream:!0});const u=n.split(`
2
2
 
3
3
  `);n=u.pop()||"";for(const y of u){const b=y.split(`
4
- `);let i="progress",P=null;for(const v of b)if(v.startsWith("event: ")&&(i=v.slice(7).trim()),v.startsWith("data: "))try{P=JSON.parse(v.slice(6))}catch{}if(P)if(i==="progress")qe(v=>[...v.slice(-50),P.message]);else if(i==="done"){pe(!0),Ke(!1),$(!1),Ye();return}else i==="error"&&m({type:"error",message:P.error||"Install failed"})}}}catch(t){m({type:"error",message:t.message})}finally{Ke(!1)}},Ve=async t=>{A("Waiting for Tailscale ready...");const s=`${t}/api/health`,l=Date.now();for(;Date.now()-l<Ut;){await new Promise(n=>setTimeout(n,et));try{const n=await fetch(s,{mode:"no-cors",cache:"no-store"});if(n.ok||n.type==="opaque")return!0}catch{}}return!1},vt=(t,s)=>{gt(t),yt(s)},E=()=>{gt(""),yt("")},Ye=async()=>{$(!1),$e(!0),Q(!0),m(null),A("Connecting..."),E();try{const t=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),s=await t.json();if(t.ok&&s.success){W(s.tunnelUrl||"");const l=await Ve(s.tunnelUrl);M(!0),m(l?null:{type:"warning",message:"Connected but not reachable yet."});return}if(s.needsLogin&&s.authUrl){vt(s.authUrl,"Open Login Page"),A('Login required — click "Open Login Page" to continue');for(let l=0;l<40;l++){await new Promise(n=>setTimeout(n,3e3));try{const n=await fetch("/api/tunnel/tailscale-check");if(n.ok&&(await n.json()).loggedIn){E(),A("Starting funnel...");const o=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),u=await o.json();if(o.ok&&u.success){W(u.tunnelUrl||"");const y=await Ve(u.tunnelUrl);M(!0),m(y?null:{type:"warning",message:"Connected but not reachable yet."})}else u.funnelNotEnabled&&u.enableUrl?await Ct(u.enableUrl):m({type:"error",message:u.error||"Failed to start funnel"});return}}catch{}}E(),m({type:"error",message:"Login timed out. Please try again."});return}if(s.funnelNotEnabled&&s.enableUrl){await Ct(s.enableUrl);return}m({type:"error",message:s.error||"Failed to connect"})}catch(t){m({type:"error",message:t.message})}finally{Q(!1),$e(!1),A(""),E()}},Ct=async t=>{vt(t,"Open Funnel Settings"),A('Click "Open Funnel Settings" to enable Funnel...');for(let s=0;s<40;s++){await new Promise(l=>setTimeout(l,3e3));try{const l=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),n=await l.json();if(l.ok&&n.success){E(),W(n.tunnelUrl||"");const r=await Ve(n.tunnelUrl);M(!0),m(r?null:{type:"warning",message:"Connected but not reachable yet."});return}if(n.funnelNotEnabled)continue;if(n.error){E(),m({type:"error",message:n.error});return}}catch{}}E(),m({type:"error",message:"Timed out waiting for Funnel to be enabled."})},ws=async()=>{Q(!0),m(null);try{const t=await fetch("/api/tunnel/tailscale-disable",{method:"POST"}),s=await t.json();t.ok?(M(!1),W(""),Z(!1),m({type:"success",message:"Tailscale disabled"})):m({type:"error",message:s.error||"Failed to disable Tailscale"})}catch(t){m({type:"error",message:t.message})}finally{Q(!1)}},Tt=async()=>{m(null),qe([]);const t=await ys();t!=null&&t.installed&&(t!=null&&t.hasCachedPassword)?Ye():$(!0)},Ns=async()=>{if(ne.trim())try{const t=await fetch("/api/keys",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ne})}),s=await t.json();t.ok&&(Se(s.key),await kt(),le(""),C(!1))}catch(t){console.log("Error creating key:",t)}},ks=async t=>{J({title:"Delete API Key",message:"Delete this API key?",onConfirm:async()=>{J(null);try{(await fetch(`/api/keys/${t}`,{method:"DELETE"})).ok&&(x(d.filter(l=>l.id!==t)),wt(l=>{const n=new Set(l);return n.delete(t),n}))}catch(s){console.log("Error deleting key:",s)}}})},St=async(t,s)=>{try{(await fetch(`/api/keys/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:s})})).ok&&x(n=>n.map(r=>r.id===t?{...r,isActive:s}:r))}catch(l){console.log("Error toggling key:",l)}},vs=t=>t?t.length>8?t.slice(0,8)+"...":t:"",Cs=t=>{wt(s=>{const l=new Set(s);return l.has(t)?l.delete(t):l.add(t),l})},[Ts,Ss]=a.useState("/v1");if(a.useEffect(()=>{typeof window<"u"&&Ss(`${window.location.origin}/v1`)},[]),j)return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(_t,{}),e.jsx(_t,{})]});const Es=Ts,ke=!!I.running,Xe=I.localUrl!==!1,Et=!!I.canStart,Ps=Xe&&!!I.managedPid,Ls=I.loading?"Checking…":ke?"Running":Xe&&!I.installed?"Not installed":Xe?"Proxy off":"Unreachable";return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsxs(Ze,{children:[e.jsxs("h2",{className:"text-lg font-semibold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"api"}),"API Endpoint"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qs,{label:"Local",url:Es,copyId:"local_url",copied:z,onCopy:se}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${p?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:"Tunnel"}),p&&!_&&D?e.jsxs(e.Fragment,{children:[e.jsx(G,{value:`${H||O}/v1`,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>se(`${H||O}/v1`,"tunnel_url"),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:z==="tunnel_url"?"check":"content_copy"})}),e.jsx("button",{onClick:()=>X(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tunnel",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):p&&!_&&!D?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-amber-300 dark:border-amber-800 bg-amber-500/5 text-sm text-amber-600 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Jt?"Tunnel reconnecting...":"Tunnel checking..."]}),e.jsx("button",{onClick:()=>X(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tunnel",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):_?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Mt||"Creating tunnel..."]}),e.jsx("button",{onClick:()=>{T(!1),S("")},className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):(he==null?void 0:he.type)==="error"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-red-300 dark:border-red-800 bg-red-500/5 text-sm text-red-600 dark:text-red-400",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),he.message]}),e.jsx(c,{size:"sm",icon:"cloud_upload",onClick:()=>Y(!0),children:"Enable"})]}):Ht?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Checking..."]}),e.jsx("button",{onClick:()=>He(!1),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):e.jsx(c,{size:"sm",icon:"cloud_upload",onClick:()=>{Y(!0)},children:"Enable"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${f?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:"Tailscale"}),f&&!U&&F?e.jsxs(e.Fragment,{children:[e.jsx(G,{value:`${K}/v1`,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>se(`${K}/v1`,"ts_url"),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:z==="ts_url"?"check":"content_copy"})}),e.jsx("button",{onClick:()=>Z(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tailscale",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):f&&!U&&!F?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-amber-300 dark:border-amber-800 bg-amber-500/5 text-sm text-amber-600 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Vt?"Tailscale reconnecting...":"Tailscale checking..."]}),e.jsx("button",{onClick:()=>Z(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tailscale",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):U||zt?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Wt||"Connecting..."]}),bt&&e.jsx(c,{size:"sm",icon:"open_in_new",onClick:()=>window.open(bt,"tailscale_auth","width=600,height=700,noopener,noreferrer"),children:qt||"Open"}),e.jsx("button",{onClick:()=>{Q(!1),$e(!1),A(""),E()},className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):(q==null?void 0:q.type)==="error"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-red-300 dark:border-red-800 bg-red-500/5 text-sm text-red-600 dark:text-red-400",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),q.message]}),e.jsx(c,{size:"sm",icon:"vpn_lock",onClick:Tt,children:"Enable"})]}):e.jsx(c,{size:"sm",icon:"vpn_lock",onClick:()=>{Tt()},className:"bg-linear-to-r from-indigo-500 to-purple-500 hover:from-indigo-600 hover:to-purple-600 text-white!",children:"Enable"})]})]}),Zt&&!p&&!f&&e.jsx("div",{className:"mt-4",children:e.jsx(Ce,{message:es,action:{label:"Open settings",href:"/dashboard/profile"}})}),(p||f)&&e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[!re&&e.jsx(Ce,{message:"Require API key is disabled — your endpoint is publicly accessible without authentication.",action:{label:"Enable",href:"#require-api-key"}}),(!V||!at)&&e.jsx(Ce,{message:V?"Dashboard uses the default password — change it in Profile settings.":"Require login is disabled — anyone can access your dashboard via tunnel.",action:{label:V?"Change password":"Enable",href:"/dashboard/profile"}})]}),(p||f)&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex items-center gap-3",children:[e.jsx(L,{checked:nt,onChange:()=>ss(!nt)}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"font-medium text-sm",children:"Allow dashboard access via tunnel"}),e.jsx(zs,{text:"When enabled, the dashboard can be accessed through your tunnel or Tailscale URL (login still required). When disabled, dashboard access via tunnel/Tailscale is completely blocked."})]})]})]}),e.jsxs(Ze,{id:"rtk",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"bolt"}),"Token Saver"]})}),e.jsxs("div",{className:"flex items-center justify-between pt-2 pb-4 border-b border-border gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Compress tool output"," ",e.jsx("a",{href:"https://github.com/rtk-ai/rtk",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(RTK)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"git/grep/ls/tree/logs → 60-90% fewer input tokens"})]}),e.jsx(L,{checked:rt,onChange:()=>ns(!rt)})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Compress LLM output"," ",e.jsx("a",{href:"https://github.com/JuliusBrussee/caveman",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Caveman)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Terse-style system prompt → ~65% fewer output tokens (up to 87%)"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[Ee&&e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:Qt.map(t=>e.jsx("button",{onClick:()=>rs(t.id),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${ie===t.id?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:t.desc,children:t.label},t.id))}),e.jsx("p",{className:"text-xs text-primary",children:(Pt=ve.find(t=>t.id===ie))==null?void 0:Pt.desc})]}),e.jsx(L,{checked:Ee,onChange:()=>ls(!Ee)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 pb-4 border-t border-border gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Code minimalism"," ",e.jsx("a",{href:"https://github.com/DietrichGebert/ponytail",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Ponytail)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Lazy senior dev system prompt → YAGNI / stdlib-first / shortest diff"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[Re&&e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:["lite","full","ultra"].map(t=>e.jsx("button",{onClick:()=>hs(t),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${Ie===t?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:t==="lite"?"Build what's asked, name lazier alternative":t==="full"?"Enforce ladder, shortest diff":"YAGNI extremist, deletion before addition",children:t==="lite"?"Lite":t==="full"?"Full":"Ultra"},t))}),e.jsx("p",{className:"text-xs text-primary",children:Ie==="lite"?"Build what's asked, name lazier alternative":Ie==="full"?"Enforce ladder, shortest diff":"YAGNI extremist, deletion before addition"})]}),e.jsx(L,{checked:Re,onChange:()=>us(!Re)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Token Saver"," ",e.jsx("a",{href:"https://github.com/mocasus/paleo",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Paleo)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Compress LLM output → ~50-80% fewer output tokens"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[De&&e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:["lite","full","ultra"].map(t=>e.jsx("button",{onClick:()=>ps(t),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${Oe===t?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:t==="lite"?"Gentle hints, keep grammar":t==="full"?"Strong compression, fragments OK":"Telegraphic, max savings",children:t==="lite"?"Lite":t==="full"?"Full":"Ultra"},t))}),e.jsx("p",{className:"text-xs text-primary",children:Oe==="lite"?"Gentle hints, keep grammar":Oe==="full"?"Strong compression, fragments OK":"Telegraphic, max savings"})]}),e.jsx(L,{checked:De,onChange:()=>xs(!De)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Context compression"," ",e.jsx("a",{href:"https://github.com/jerhadf/headroom",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Headroom)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"External proxy compresses input messages → fewer prompt tokens"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[Le&&e.jsxs("div",{className:"flex flex-col items-end gap-2 min-w-[200px]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{value:_e,onChange:t=>os(t.target.value),placeholder:"http://localhost:8787",className:"text-xs"}),!ke&&Et&&e.jsx("button",{onClick:ds,disabled:oe,className:"px-2 py-1.5 rounded text-xs font-medium bg-primary text-white hover:opacity-80 disabled:opacity-50",children:oe?"...":"Start"}),ke&&Ps&&e.jsx("button",{onClick:ms,disabled:oe,className:"px-2 py-1.5 rounded text-xs font-medium bg-red-500 text-white hover:opacity-80 disabled:opacity-50",children:oe?"...":"Stop"})]}),e.jsx("p",{className:`text-xs ${ke?"text-green-500":Et?"text-yellow-500":"text-red-500"}`,children:Ls}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-text-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:Dt,onChange:t=>cs(t.target.checked),className:"rounded"}),"Compress user messages"]})]}),e.jsx(L,{checked:Le,onChange:()=>is(!Le)})]})]})]}),e.jsxs(Ze,{id:"require-api-key",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"vpn_key"}),"API Keys"]}),e.jsx(c,{icon:"add",onClick:()=>C(!0),children:"Create Key"})]}),e.jsxs("div",{className:"flex items-center justify-between pb-4 mb-4 border-b border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Require API key"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Requests without a valid key will be rejected"})]}),e.jsx(L,{checked:re,onChange:()=>as(!re)})]}),Yt&&!re&&e.jsx("div",{className:"mb-4 -mt-2",children:e.jsx(Ce,{message:"Endpoint is exposed without an API key."})}),d.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"vpn_key"})}),e.jsx("p",{className:"text-text-main font-medium mb-1",children:"No API keys yet"}),e.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Create your first API key to get started"}),e.jsx(c,{icon:"add",onClick:()=>C(!0),children:"Create Key"})]}):e.jsx("div",{className:"flex flex-col",children:d.map(t=>e.jsxs("div",{className:`group flex items-center justify-between py-3 border-b border-black/[0.03] dark:border-white/[0.03] last:border-b-0 ${t.isActive===!1?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("code",{className:"text-xs text-text-muted font-mono",children:Ge.has(t.id)?t.key:vs(t.key)}),e.jsx("button",{onClick:()=>Cs(t.id),className:"p-1 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",title:Ge.has(t.id)?"Hide key":"Show key",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:Ge.has(t.id)?"visibility_off":"visibility"})}),e.jsx("button",{onClick:()=>se(t.key,t.id),className:"p-1 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:z===t.id?"check":"content_copy"})})]}),e.jsxs("p",{className:"text-xs text-text-muted mt-1",children:["Created ",new Date(t.createdAt).toLocaleDateString()]}),t.isActive===!1&&e.jsx("p",{className:"text-xs text-orange-500 mt-1",children:"Paused"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{size:"sm",checked:t.isActive??!0,onChange:s=>{t.isActive&&!s?J({title:"Pause API Key",message:`Pause API key "${t.name}"?
4
+ `);let i="progress",P=null;for(const k of b)if(k.startsWith("event: ")&&(i=k.slice(7).trim()),k.startsWith("data: "))try{P=JSON.parse(k.slice(6))}catch{}if(P)if(i==="progress")qe(k=>[...k.slice(-50),P.message]);else if(i==="done"){pe(!0),Ke(!1),$(!1),Ye();return}else i==="error"&&m({type:"error",message:P.error||"Install failed"})}}}catch(t){m({type:"error",message:t.message})}finally{Ke(!1)}},Ve=async t=>{A("Waiting for Tailscale ready...");const s=`${t}/api/health`,l=Date.now();for(;Date.now()-l<Ut;){await new Promise(n=>setTimeout(n,et));try{const n=await fetch(s,{mode:"no-cors",cache:"no-store"});if(n.ok||n.type==="opaque")return!0}catch{}}return!1},kt=(t,s)=>{gt(t),yt(s)},E=()=>{gt(""),yt("")},Ye=async()=>{$(!1),$e(!0),Q(!0),m(null),A("Connecting..."),E();try{const t=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),s=await t.json();if(t.ok&&s.success){W(s.tunnelUrl||"");const l=await Ve(s.tunnelUrl);M(!0),m(l?null:{type:"warning",message:"Connected but not reachable yet."});return}if(s.needsLogin&&s.authUrl){kt(s.authUrl,"Open Login Page"),A('Login required — click "Open Login Page" to continue');for(let l=0;l<40;l++){await new Promise(n=>setTimeout(n,3e3));try{const n=await fetch("/api/tunnel/tailscale-check");if(n.ok&&(await n.json()).loggedIn){E(),A("Starting funnel...");const o=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),u=await o.json();if(o.ok&&u.success){W(u.tunnelUrl||"");const y=await Ve(u.tunnelUrl);M(!0),m(y?null:{type:"warning",message:"Connected but not reachable yet."})}else u.funnelNotEnabled&&u.enableUrl?await Ct(u.enableUrl):m({type:"error",message:u.error||"Failed to start funnel"});return}}catch{}}E(),m({type:"error",message:"Login timed out. Please try again."});return}if(s.funnelNotEnabled&&s.enableUrl){await Ct(s.enableUrl);return}m({type:"error",message:s.error||"Failed to connect"})}catch(t){m({type:"error",message:t.message})}finally{Q(!1),$e(!1),A(""),E()}},Ct=async t=>{kt(t,"Open Funnel Settings"),A('Click "Open Funnel Settings" to enable Funnel...');for(let s=0;s<40;s++){await new Promise(l=>setTimeout(l,3e3));try{const l=await fetch("/api/tunnel/tailscale-enable",{method:"POST"}),n=await l.json();if(l.ok&&n.success){E(),W(n.tunnelUrl||"");const r=await Ve(n.tunnelUrl);M(!0),m(r?null:{type:"warning",message:"Connected but not reachable yet."});return}if(n.funnelNotEnabled)continue;if(n.error){E(),m({type:"error",message:n.error});return}}catch{}}E(),m({type:"error",message:"Timed out waiting for Funnel to be enabled."})},ws=async()=>{Q(!0),m(null);try{const t=await fetch("/api/tunnel/tailscale-disable",{method:"POST"}),s=await t.json();t.ok?(M(!1),W(""),Z(!1),m({type:"success",message:"Tailscale disabled"})):m({type:"error",message:s.error||"Failed to disable Tailscale"})}catch(t){m({type:"error",message:t.message})}finally{Q(!1)}},Tt=async()=>{m(null),qe([]);const t=await ys();t!=null&&t.installed&&(t!=null&&t.hasCachedPassword)?Ye():$(!0)},Ns=async()=>{if(ne.trim())try{const t=await fetch("/api/keys",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ne})}),s=await t.json();t.ok&&(Se(s.key),await vt(),le(""),C(!1))}catch(t){console.log("Error creating key:",t)}},vs=async t=>{J({title:"Delete API Key",message:"Delete this API key?",onConfirm:async()=>{J(null);try{(await fetch(`/api/keys/${t}`,{method:"DELETE"})).ok&&(x(d.filter(l=>l.id!==t)),wt(l=>{const n=new Set(l);return n.delete(t),n}))}catch(s){console.log("Error deleting key:",s)}}})},St=async(t,s)=>{try{(await fetch(`/api/keys/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:s})})).ok&&x(n=>n.map(r=>r.id===t?{...r,isActive:s}:r))}catch(l){console.log("Error toggling key:",l)}},ks=t=>t?t.length>8?t.slice(0,8)+"...":t:"",Cs=t=>{wt(s=>{const l=new Set(s);return l.has(t)?l.delete(t):l.add(t),l})},[Ts,Ss]=a.useState("/v1");if(a.useEffect(()=>{typeof window<"u"&&Ss(`${window.location.origin}/v1`)},[]),j)return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(_t,{}),e.jsx(_t,{})]});const Es=Ts,ve=!!I.running,Xe=I.localUrl!==!1,Et=!!I.canStart,Ps=Xe&&!!I.managedPid,Ls=I.loading?"Checking…":ve?"Running":Xe&&!I.installed?"Not installed":Xe?"Proxy off":"Unreachable";return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsxs(Ze,{children:[e.jsxs("h2",{className:"text-lg font-semibold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"api"}),"API Endpoint"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qs,{label:"Local",url:Es,copyId:"local_url",copied:z,onCopy:se}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${p?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:"Tunnel"}),p&&!_&&D?e.jsxs(e.Fragment,{children:[e.jsx(G,{value:`${H||O}/v1`,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>se(`${H||O}/v1`,"tunnel_url"),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:z==="tunnel_url"?"check":"content_copy"})}),e.jsx("button",{onClick:()=>X(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tunnel",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):p&&!_&&!D?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-amber-300 dark:border-amber-800 bg-amber-500/5 text-sm text-amber-600 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Jt?"Tunnel reconnecting...":"Tunnel checking..."]}),e.jsx("button",{onClick:()=>X(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tunnel",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):_?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Mt||"Creating tunnel..."]}),e.jsx("button",{onClick:()=>{T(!1),S("")},className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):(he==null?void 0:he.type)==="error"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-red-300 dark:border-red-800 bg-red-500/5 text-sm text-red-600 dark:text-red-400",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),he.message]}),e.jsx(c,{size:"sm",icon:"cloud_upload",onClick:()=>Y(!0),children:"Enable"})]}):Ht?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Checking..."]}),e.jsx("button",{onClick:()=>He(!1),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):e.jsx(c,{size:"sm",icon:"cloud_upload",onClick:()=>{Y(!0)},children:"Enable"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${f?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:"Tailscale"}),f&&!U&&F?e.jsxs(e.Fragment,{children:[e.jsx(G,{value:`${K}/v1`,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>se(`${K}/v1`,"ts_url"),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:z==="ts_url"?"check":"content_copy"})}),e.jsx("button",{onClick:()=>Z(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tailscale",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):f&&!U&&!F?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-amber-300 dark:border-amber-800 bg-amber-500/5 text-sm text-amber-600 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Vt?"Tailscale reconnecting...":"Tailscale checking..."]}),e.jsx("button",{onClick:()=>Z(!0),className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Disable Tailscale",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):U||zt?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-border bg-input text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),Wt||"Connecting..."]}),bt&&e.jsx(c,{size:"sm",icon:"open_in_new",onClick:()=>window.open(bt,"tailscale_auth","width=600,height=700,noopener,noreferrer"),children:qt||"Open"}),e.jsx("button",{onClick:()=>{Q(!1),$e(!1),A(""),E()},className:"p-2 hover:bg-red-500/10 rounded text-red-500 transition-colors shrink-0",title:"Stop",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"power_settings_new"})})]}):(q==null?void 0:q.type)==="error"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-1.5 rounded border border-red-300 dark:border-red-800 bg-red-500/5 text-sm text-red-600 dark:text-red-400",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),q.message]}),e.jsx(c,{size:"sm",icon:"vpn_lock",onClick:Tt,children:"Enable"})]}):e.jsx(c,{size:"sm",icon:"vpn_lock",onClick:()=>{Tt()},className:"bg-linear-to-r from-indigo-500 to-purple-500 hover:from-indigo-600 hover:to-purple-600 text-white!",children:"Enable"})]})]}),Zt&&!p&&!f&&e.jsx("div",{className:"mt-4",children:e.jsx(Ce,{message:es,action:{label:"Open settings",href:"/dashboard/profile"}})}),(p||f)&&e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[!re&&e.jsx(Ce,{message:"Require API key is disabled — your endpoint is publicly accessible without authentication.",action:{label:"Enable",href:"#require-api-key"}}),(!V||!at)&&e.jsx(Ce,{message:V?"Dashboard uses the default password — change it in Profile settings.":"Require login is disabled — anyone can access your dashboard via tunnel.",action:{label:V?"Change password":"Enable",href:"/dashboard/profile"}})]}),(p||f)&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex items-center gap-3",children:[e.jsx(L,{checked:nt,onChange:()=>ss(!nt)}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"font-medium text-sm",children:"Allow dashboard access via tunnel"}),e.jsx(zs,{text:"When enabled, the dashboard can be accessed through your tunnel or Tailscale URL (login still required). When disabled, dashboard access via tunnel/Tailscale is completely blocked."})]})]})]}),e.jsxs(Ze,{id:"rtk",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"bolt"}),"Token Saver"]})}),e.jsxs("div",{className:"flex items-center justify-between pt-2 pb-4 border-b border-border gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Compress tool output"," ",e.jsx("a",{href:"https://github.com/rtk-ai/rtk",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(RTK)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"git/grep/ls/tree/logs → 60-90% fewer input tokens"})]}),e.jsx(L,{checked:rt,onChange:()=>ns(!rt)})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Compress LLM output"," ",e.jsx("a",{href:"https://github.com/JuliusBrussee/caveman",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Caveman)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Terse-style system prompt → ~65% fewer output tokens (up to 87%)"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[Ee&&e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:Qt.map(t=>e.jsx("button",{onClick:()=>rs(t.id),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${ie===t.id?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:t.desc,children:t.label},t.id))}),e.jsx("p",{className:"text-xs text-primary",children:(Pt=ke.find(t=>t.id===ie))==null?void 0:Pt.desc})]}),e.jsx(L,{checked:Ee,onChange:()=>ls(!Ee)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 pb-4 border-t border-border gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Code minimalism"," ",e.jsx("a",{href:"https://github.com/DietrichGebert/ponytail",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Ponytail)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Lazy senior dev system prompt → YAGNI / stdlib-first / shortest diff"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[Re&&e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:["lite","full","ultra"].map(t=>e.jsx("button",{onClick:()=>hs(t),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${Ie===t?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:t==="lite"?"Build what's asked, name lazier alternative":t==="full"?"Enforce ladder, shortest diff":"YAGNI extremist, deletion before addition",children:t==="lite"?"Lite":t==="full"?"Full":"Ultra"},t))}),e.jsx("p",{className:"text-xs text-primary",children:Ie==="lite"?"Build what's asked, name lazier alternative":Ie==="full"?"Enforce ladder, shortest diff":"YAGNI extremist, deletion before addition"})]}),e.jsx(L,{checked:Re,onChange:()=>us(!Re)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Token Saver"," ",e.jsx("a",{href:"https://github.com/mocasus/paleo",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Paleo)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Compress LLM output → ~50-80% fewer output tokens"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[De&&e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:["lite","full","ultra"].map(t=>e.jsx("button",{onClick:()=>ps(t),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${Oe===t?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:t==="lite"?"Gentle hints, keep grammar":t==="full"?"Strong compression, fragments OK":"Telegraphic, max savings",children:t==="lite"?"Lite":t==="full"?"Full":"Ultra"},t))}),e.jsx("p",{className:"text-xs text-primary",children:Oe==="lite"?"Gentle hints, keep grammar":Oe==="full"?"Strong compression, fragments OK":"Telegraphic, max savings"})]}),e.jsx(L,{checked:De,onChange:()=>xs(!De)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"font-medium",children:["Context compression"," ",e.jsx("a",{href:"https://github.com/jerhadf/headroom",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Headroom)"})]}),e.jsx("p",{className:"text-sm text-text-muted",children:"External proxy compresses input messages → fewer prompt tokens"})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[Le&&e.jsxs("div",{className:"flex flex-col items-end gap-2 min-w-[200px]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{value:_e,onChange:t=>os(t.target.value),placeholder:"http://localhost:8787",className:"text-xs"}),!ve&&Et&&e.jsx("button",{onClick:ds,disabled:oe,className:"px-2 py-1.5 rounded text-xs font-medium bg-primary text-white hover:opacity-80 disabled:opacity-50",children:oe?"...":"Start"}),ve&&Ps&&e.jsx("button",{onClick:ms,disabled:oe,className:"px-2 py-1.5 rounded text-xs font-medium bg-red-500 text-white hover:opacity-80 disabled:opacity-50",children:oe?"...":"Stop"})]}),e.jsx("p",{className:`text-xs ${ve?"text-green-500":Et?"text-yellow-500":"text-red-500"}`,children:Ls}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-text-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:Dt,onChange:t=>cs(t.target.checked),className:"rounded"}),"Compress user messages"]})]}),e.jsx(L,{checked:Le,onChange:()=>is(!Le)})]})]})]}),e.jsxs(Ze,{id:"require-api-key",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"vpn_key"}),"API Keys"]}),e.jsx(c,{icon:"add",onClick:()=>C(!0),children:"Create Key"})]}),e.jsxs("div",{className:"flex items-center justify-between pb-4 mb-4 border-b border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Require API key"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Requests without a valid key will be rejected"})]}),e.jsx(L,{checked:re,onChange:()=>as(!re)})]}),Yt&&!re&&e.jsx("div",{className:"mb-4 -mt-2",children:e.jsx(Ce,{message:"Endpoint is exposed without an API key."})}),d.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"vpn_key"})}),e.jsx("p",{className:"text-text-main font-medium mb-1",children:"No API keys yet"}),e.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Create your first API key to get started"}),e.jsx(c,{icon:"add",onClick:()=>C(!0),children:"Create Key"})]}):e.jsx("div",{className:"flex flex-col",children:d.map(t=>e.jsxs("div",{className:`group flex items-center justify-between py-3 border-b border-black/[0.03] dark:border-white/[0.03] last:border-b-0 ${t.isActive===!1?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("code",{className:"text-xs text-text-muted font-mono",children:Ge.has(t.id)?t.key:ks(t.key)}),e.jsx("button",{onClick:()=>Cs(t.id),className:"p-1 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",title:Ge.has(t.id)?"Hide key":"Show key",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:Ge.has(t.id)?"visibility_off":"visibility"})}),e.jsx("button",{onClick:()=>se(t.key,t.id),className:"p-1 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:z===t.id?"check":"content_copy"})})]}),e.jsxs("p",{className:"text-xs text-text-muted mt-1",children:["Created ",new Date(t.createdAt).toLocaleDateString()]}),t.isActive===!1&&e.jsx("p",{className:"text-xs text-orange-500 mt-1",children:"Paused"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{size:"sm",checked:t.isActive??!0,onChange:s=>{t.isActive&&!s?J({title:"Pause API Key",message:`Pause API key "${t.name}"?
5
5
 
6
- This key will stop working immediately but can be resumed later.`,onConfirm:async()=>{J(null),St(t.id,s)}}):St(t.id,s)},title:t.isActive?"Pause key":"Resume key"}),e.jsx("button",{onClick:()=>ks(t.id),className:"p-2 hover:bg-red-500/10 rounded text-red-500 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]},t.id))})]}),e.jsx(B,{isOpen:g,title:"Create API Key",onClose:()=>{C(!1),le("")},children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(G,{label:"Key Name",value:ne,onChange:t=>le(t.target.value),placeholder:"Production Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:Ns,fullWidth:!0,disabled:!ne.trim(),children:"Create"}),e.jsx(c,{onClick:()=>{C(!1),le("")},variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}),e.jsx(B,{isOpen:!!Te,title:"API Key Created",onClose:()=>Se(null),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-4",children:[e.jsx("p",{className:"text-sm text-yellow-800 dark:text-yellow-200 mb-2 font-medium",children:"Save this key now!"}),e.jsx("p",{className:"text-sm text-yellow-700 dark:text-yellow-300",children:"This is the only time you will see this key. Store it securely."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{value:Te||"",readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx(c,{variant:"secondary",icon:z==="created_key"?"check":"content_copy",onClick:()=>se(Te,"created_key"),children:z==="created_key"?"Copied!":"Copy"})]}),e.jsx(c,{onClick:()=>Se(null),fullWidth:!0,children:"Done"})]})}),e.jsx(B,{isOpen:Ft,title:"Enable Tunnel",onClose:()=>Y(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"bg-surface-2 border border-border-subtle rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"cloud_upload"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-text-main font-medium mb-1",children:"Cloudflare Tunnel"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Expose your local FSRouter to the internet. No port forwarding, no static IP needed. Share endpoint URL with your team or use it in Cursor, Cline, and other AI tools from anywhere."})]})]})}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:Os.map(t=>e.jsxs("div",{className:"flex flex-col items-center text-center p-3 rounded-lg bg-sidebar/50",children:[e.jsx("span",{className:"material-symbols-outlined text-xl text-primary mb-1",children:t.icon}),e.jsx("p",{className:"text-xs font-semibold",children:t.title}),e.jsx("p",{className:"text-xs text-text-muted",children:t.desc})]},t.title))}),e.jsx("p",{className:"text-xs text-text-muted",children:"Requires outbound port 7844 (TCP/UDP). Connection may take 10-30s."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:bs,fullWidth:!0,children:"Start Tunnel"}),e.jsx(c,{onClick:()=>Y(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}),e.jsx(B,{isOpen:Kt,title:"Disable Tunnel",onClose:()=>!_&&X(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"The Cloudflare tunnel will be disconnected. Remote access via tunnel URL will stop working."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:gs,fullWidth:!0,disabled:_,variant:"danger",children:_?"Disabling...":"Disable"}),e.jsx(c,{onClick:()=>X(!1),variant:"ghost",fullWidth:!0,disabled:_,children:"Cancel"})]})]})}),e.jsx(B,{isOpen:Bt,title:"Tailscale Funnel",onClose:()=>{fe||($(!1),jt(""),m(null))},children:e.jsxs("div",{className:"flex flex-col gap-4",children:[Fe===null&&e.jsxs("p",{className:"text-sm text-text-muted flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Checking..."]}),Fe===!1&&!fe&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"Tailscale is not installed. Install it to enable Funnel."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:js,fullWidth:!0,children:"Install Tailscale"}),e.jsx(c,{onClick:()=>$(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),fe&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Installing Tailscale..."]}),We.length>0&&e.jsx("div",{ref:be,className:"bg-black/5 dark:bg-white/5 rounded p-2 max-h-40 overflow-y-auto font-mono text-xs text-text-muted",children:We.map((t,s)=>e.jsx("div",{children:t},s))})]}),Fe===!0&&!fe&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"check_circle"}),"Tailscale installed"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:()=>Ye(),fullWidth:!0,children:"Connect"}),e.jsx(c,{onClick:()=>$(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),q&&e.jsx($s,{status:q})]})}),e.jsx(B,{isOpen:Gt,title:"Disable Tailscale",onClose:()=>!U&&Z(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"Tailscale Funnel will be stopped. Remote access via Tailscale URL will stop working."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:ws,fullWidth:!0,disabled:U,variant:"danger",children:U?"Disabling...":"Disable"}),e.jsx(c,{onClick:()=>Z(!1),variant:"ghost",fullWidth:!0,disabled:U,children:"Cancel"})]})]})}),e.jsx(Rs,{isOpen:!!w,onClose:()=>J(null),onConfirm:w==null?void 0:w.onConfirm,title:(w==null?void 0:w.title)||"Confirm",message:w==null?void 0:w.message,variant:"danger"})]})}function qs({label:h,url:d,copyId:x,copied:j,onCopy:R,badge:g,actions:C}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${g==="CF"||g==="TS"?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:h}),e.jsx(G,{value:d,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>R(d,x),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:j===x?"check":"content_copy"})}),C]})}function $s({status:h,className:d=""}){const x=j=>j.split(/(https?:\/\/[^\s]+)/g).map((g,C)=>/^https?:\/\//.test(g)?e.jsx("a",{href:g,target:"_blank",rel:"noreferrer",className:"underline font-medium",children:g},C):g);return e.jsx("div",{className:`p-2 rounded text-sm ${d} ${h.type==="success"?"bg-green-500/10 text-green-600 dark:text-green-400":h.type==="warning"?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":h.type==="info"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-red-500/10 text-red-600 dark:text-red-400"}`,children:x(h.message)})}function zs({text:h}){return e.jsxs("span",{className:"relative group inline-flex items-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-text-muted cursor-help",children:"help"}),e.jsx("span",{className:"pointer-events-none absolute left-5 top-1/2 -translate-y-1/2 z-50 w-64 rounded bg-gray-900 dark:bg-gray-800 text-white text-xs px-2.5 py-1.5 opacity-0 group-hover:opacity-100 transition-opacity shadow-lg",children:h})]})}function Ce({message:h,action:d}){return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 mt-0.5",children:"warning"}),e.jsx("p",{className:"text-xs flex-1",children:h}),d&&e.jsx("a",{href:d.href,className:"text-xs font-medium underline shrink-0 hover:opacity-80",onClick:d.href.startsWith("#")?x=>{var j;x.preventDefault(),(j=document.getElementById(d.href.slice(1)))==null||j.scrollIntoView({behavior:"smooth"})}:void 0,children:d.label})]})}Ws.propTypes={machineId:Is.string.isRequired};export{Ws as A};
6
+ This key will stop working immediately but can be resumed later.`,onConfirm:async()=>{J(null),St(t.id,s)}}):St(t.id,s)},title:t.isActive?"Pause key":"Resume key"}),e.jsx("button",{onClick:()=>vs(t.id),className:"p-2 hover:bg-red-500/10 rounded text-red-500 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-all",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]},t.id))})]}),e.jsx(B,{isOpen:g,title:"Create API Key",onClose:()=>{C(!1),le("")},children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(G,{label:"Key Name",value:ne,onChange:t=>le(t.target.value),placeholder:"Production Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:Ns,fullWidth:!0,disabled:!ne.trim(),children:"Create"}),e.jsx(c,{onClick:()=>{C(!1),le("")},variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}),e.jsx(B,{isOpen:!!Te,title:"API Key Created",onClose:()=>Se(null),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-4",children:[e.jsx("p",{className:"text-sm text-yellow-800 dark:text-yellow-200 mb-2 font-medium",children:"Save this key now!"}),e.jsx("p",{className:"text-sm text-yellow-700 dark:text-yellow-300",children:"This is the only time you will see this key. Store it securely."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{value:Te||"",readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx(c,{variant:"secondary",icon:z==="created_key"?"check":"content_copy",onClick:()=>se(Te,"created_key"),children:z==="created_key"?"Copied!":"Copy"})]}),e.jsx(c,{onClick:()=>Se(null),fullWidth:!0,children:"Done"})]})}),e.jsx(B,{isOpen:Ft,title:"Enable Tunnel",onClose:()=>Y(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"bg-surface-2 border border-border-subtle rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"cloud_upload"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-text-main font-medium mb-1",children:"Cloudflare Tunnel"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Expose your local FSRouter to the internet. No port forwarding, no static IP needed. Share endpoint URL with your team or use it in Cursor, Cline, and other AI tools from anywhere."})]})]})}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:Os.map(t=>e.jsxs("div",{className:"flex flex-col items-center text-center p-3 rounded-lg bg-sidebar/50",children:[e.jsx("span",{className:"material-symbols-outlined text-xl text-primary mb-1",children:t.icon}),e.jsx("p",{className:"text-xs font-semibold",children:t.title}),e.jsx("p",{className:"text-xs text-text-muted",children:t.desc})]},t.title))}),e.jsx("p",{className:"text-xs text-text-muted",children:"Requires outbound port 7844 (TCP/UDP). Connection may take 10-30s."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:bs,fullWidth:!0,children:"Start Tunnel"}),e.jsx(c,{onClick:()=>Y(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}),e.jsx(B,{isOpen:Kt,title:"Disable Tunnel",onClose:()=>!_&&X(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"The Cloudflare tunnel will be disconnected. Remote access via tunnel URL will stop working."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:gs,fullWidth:!0,disabled:_,variant:"danger",children:_?"Disabling...":"Disable"}),e.jsx(c,{onClick:()=>X(!1),variant:"ghost",fullWidth:!0,disabled:_,children:"Cancel"})]})]})}),e.jsx(B,{isOpen:Bt,title:"Tailscale Funnel",onClose:()=>{fe||($(!1),jt(""),m(null))},children:e.jsxs("div",{className:"flex flex-col gap-4",children:[Fe===null&&e.jsxs("p",{className:"text-sm text-text-muted flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Checking..."]}),Fe===!1&&!fe&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"Tailscale is not installed. Install it to enable Funnel."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:js,fullWidth:!0,children:"Install Tailscale"}),e.jsx(c,{onClick:()=>$(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),fe&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-sm",children:"progress_activity"}),"Installing Tailscale..."]}),We.length>0&&e.jsx("div",{ref:be,className:"bg-black/5 dark:bg-white/5 rounded p-2 max-h-40 overflow-y-auto font-mono text-xs text-text-muted",children:We.map((t,s)=>e.jsx("div",{children:t},s))})]}),Fe===!0&&!fe&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"check_circle"}),"Tailscale installed"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:()=>Ye(),fullWidth:!0,children:"Connect"}),e.jsx(c,{onClick:()=>$(!1),variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),q&&e.jsx($s,{status:q})]})}),e.jsx(B,{isOpen:Gt,title:"Disable Tailscale",onClose:()=>!U&&Z(!1),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"Tailscale Funnel will be stopped. Remote access via Tailscale URL will stop working."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:ws,fullWidth:!0,disabled:U,variant:"danger",children:U?"Disabling...":"Disable"}),e.jsx(c,{onClick:()=>Z(!1),variant:"ghost",fullWidth:!0,disabled:U,children:"Cancel"})]})]})}),e.jsx(Rs,{isOpen:!!w,onClose:()=>J(null),onConfirm:w==null?void 0:w.onConfirm,title:(w==null?void 0:w.title)||"Confirm",message:w==null?void 0:w.message,variant:"danger"})]})}function qs({label:h,url:d,copyId:x,copied:j,onCopy:R,badge:g,actions:C}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-mono px-1.5 py-0.5 rounded shrink-0 min-w-[88px] text-center ${g==="CF"||g==="TS"?"bg-primary/10 text-primary":"bg-surface-2 text-text-muted"}`,children:h}),e.jsx(G,{value:d,readOnly:!0,className:"flex-1 font-mono text-sm"}),e.jsx("button",{onClick:()=>R(d,x),className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:j===x?"check":"content_copy"})}),C]})}function $s({status:h,className:d=""}){const x=j=>j.split(/(https?:\/\/[^\s]+)/g).map((g,C)=>/^https?:\/\//.test(g)?e.jsx("a",{href:g,target:"_blank",rel:"noreferrer",className:"underline font-medium",children:g},C):g);return e.jsx("div",{className:`p-2 rounded text-sm ${d} ${h.type==="success"?"bg-green-500/10 text-green-600 dark:text-green-400":h.type==="warning"?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":h.type==="info"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-red-500/10 text-red-600 dark:text-red-400"}`,children:x(h.message)})}function zs({text:h}){return e.jsxs("span",{className:"relative group inline-flex items-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-text-muted cursor-help",children:"help"}),e.jsx("span",{className:"pointer-events-none absolute left-5 top-1/2 -translate-y-1/2 z-50 w-64 rounded bg-gray-900 dark:bg-gray-800 text-white text-xs px-2.5 py-1.5 opacity-0 group-hover:opacity-100 transition-opacity shadow-lg",children:h})]})}function Ce({message:h,action:d}){return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 mt-0.5",children:"warning"}),e.jsx("p",{className:"text-xs flex-1",children:h}),d&&e.jsx("a",{href:d.href,className:"text-xs font-medium underline shrink-0 hover:opacity-80",onClick:d.href.startsWith("#")?x=>{var j;x.preventDefault(),(j=document.getElementById(d.href.slice(1)))==null||j.scrollIntoView({behavior:"smooth"})}:void 0,children:d.label})]})}Ws.propTypes={machineId:Is.string.isRequired};export{Ws as A};
@@ -1 +1 @@
1
- import{j as e,n as t}from"./index.B-zMpSp_.js";function r({size:n="md",className:s}){const i={sm:"size-4",md:"size-6",lg:"size-8",xl:"size-12"};return e.jsx("span",{className:t("material-symbols-outlined animate-spin text-brand-500",i[n],s),children:"progress_activity"})}function c({message:n="Loading..."}){return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col items-center justify-center bg-bg",children:[e.jsx(r,{size:"xl"}),e.jsx("p",{className:"mt-4 text-text-muted",children:n})]})}function a({className:n,...s}){return e.jsx("div",{className:t("animate-pulse rounded-[10px] bg-surface-2",n),...s})}function d(){return e.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface shadow-[var(--shadow-soft)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx(a,{className:"h-4 w-24"}),e.jsx(a,{className:"size-10 rounded-[10px]"})]}),e.jsx(a,{className:"h-8 w-16 mb-2"}),e.jsx(a,{className:"h-3 w-20"})]})}function x({type:n="spinner",...s}){switch(n){case"page":return e.jsx(c,{...s});case"skeleton":return e.jsx(a,{...s});case"card":return e.jsx(d,{...s});default:return e.jsx(r,{...s})}}export{d as C,x as L};
1
+ import{j as e,n as t}from"./index.CShjRV_B.js";function r({size:n="md",className:s}){const i={sm:"size-4",md:"size-6",lg:"size-8",xl:"size-12"};return e.jsx("span",{className:t("material-symbols-outlined animate-spin text-brand-500",i[n],s),children:"progress_activity"})}function c({message:n="Loading..."}){return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col items-center justify-center bg-bg",children:[e.jsx(r,{size:"xl"}),e.jsx("p",{className:"mt-4 text-text-muted",children:n})]})}function a({className:n,...s}){return e.jsx("div",{className:t("animate-pulse rounded-[10px] bg-surface-2",n),...s})}function d(){return e.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface shadow-[var(--shadow-soft)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx(a,{className:"h-4 w-24"}),e.jsx(a,{className:"size-10 rounded-[10px]"})]}),e.jsx(a,{className:"h-8 w-16 mb-2"}),e.jsx(a,{className:"h-3 w-20"})]})}function x({type:n="spinner",...s}){switch(n){case"page":return e.jsx(c,{...s});case"skeleton":return e.jsx(a,{...s});case"card":return e.jsx(d,{...s});default:return e.jsx(r,{...s})}}export{d as C,x as L};
@@ -1,4 +1,4 @@
1
- var KS=Object.defineProperty;var qS=(e,t,r)=>t in e?KS(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ma=(e,t,r)=>qS(e,typeof t!="symbol"?t+"":t,r);import{j as m,n as at,u as Uv,M as hr,B as ue,f as Y,g as Qa,A as Hv,c as Vv,F as Ja,O as Kv,i as Yd,k as qv,l as Yv,h as Xd,P as YS}from"./index.CoYbjSIL.js";import{b as g,r as Vc,g as Xv,W as XS,c as Gv,i as GS}from"./router.Cjj1--8t.js";function xe({label:e,type:t="text",placeholder:r,value:n,onChange:i,error:a,hint:o,icon:s,disabled:l=!1,required:c=!1,className:u,inputClassName:d,...f}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",u),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,c&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[s&&m.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:s})}),m.jsx("input",{type:t,placeholder:r,value:n,onChange:i,disabled:l,className:at("w-full py-2.5 px-3 text-sm text-text-main bg-surface-2 rounded-[10px]","border border-transparent placeholder-text-muted/70","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 ease-out disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",s&&"pl-10",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",d),...f})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function ZS({label:e,options:t=[],value:r,onChange:n,placeholder:i="Select an option",error:a,hint:o,disabled:s=!1,required:l=!1,className:c,selectClassName:u,...d}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",c),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,l&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[m.jsxs("select",{value:r,onChange:n,disabled:s,className:at("w-full py-2.5 px-3 pr-10 text-sm text-text-main","bg-surface-2 border border-transparent rounded-[10px] appearance-none","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",u),...d,children:[m.jsx("option",{value:"",disabled:!0,children:i}),t.map(f=>m.jsx("option",{value:f.value,children:f.label},f.value))]}),m.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"expand_more"})})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function zt({children:e,title:t,subtitle:r,icon:n,action:i,padding:a="md",hover:o=!1,elev:s=!1,className:l,...c}){const u={none:"",xs:"p-3",sm:"p-4",md:"p-6",lg:"p-8"};return m.jsxs("div",{className:at("bg-surface border border-border-subtle",s?"rounded-[14px] shadow-[var(--shadow-elev)]":"rounded-[14px] shadow-[var(--shadow-soft)]",o&&"hover:shadow-[var(--shadow-warm)] hover:border-brand-500/30 transition-all cursor-pointer",u[a],l),...c,children:[(t||i)&&m.jsxs("div",{className:"flex items-center justify-between mb-4",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[n&&m.jsx("div",{className:"p-2 rounded-[10px] bg-bg text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:n})}),m.jsxs("div",{children:[t&&m.jsx("h3",{className:"text-text-main font-semibold",children:t}),r&&m.jsx("p",{className:"text-sm text-text-muted",children:r})]})]}),i]}),e]})}zt.Section=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-4 rounded-[10px]","bg-bg border border-border-subtle",r),...n,children:t})};zt.Row=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-3 -mx-3 px-3 transition-colors","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50",r),...n,children:t})};zt.ListItem=function({children:t,actions:r,className:n,...i}){return m.jsxs("div",{className:at("group flex items-center justify-between p-3 -mx-3 px-3","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50 transition-colors",n),...i,children:[m.jsx("div",{className:"flex-1 min-w-0",children:t}),r&&m.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:r})]})};const QS={default:"bg-surface-2 text-text-muted",primary:"bg-brand-500/10 text-brand-600 dark:text-brand-300",success:"bg-green-500/10 text-green-600 dark:text-green-400",warning:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400",error:"bg-red-500/10 text-red-600 dark:text-red-400",info:"bg-blue-500/10 text-blue-600 dark:text-blue-400"},JS={sm:"px-2 py-0.5 text-[10px]",md:"px-2.5 py-1 text-xs",lg:"px-3 py-1.5 text-sm"};function Ci({children:e,variant:t="default",size:r="md",dot:n=!1,icon:i,className:a}){return m.jsxs("span",{className:at("inline-flex items-center gap-1.5 rounded-full font-semibold",QS[t],JS[r],a),children:[n&&m.jsx("span",{className:at("size-1.5 rounded-full",t==="success"&&"bg-green-500",t==="warning"&&"bg-yellow-500",t==="error"&&"bg-red-500",t==="info"&&"bg-blue-500",t==="primary"&&"bg-brand-500",t==="default"&&"bg-gray-500")}),i&&m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:i}),e]})}function Js({checked:e=!1,onChange:t,label:r,description:n,disabled:i=!1,size:a="md",className:o}){const s={sm:{track:"w-8 h-4",thumb:"size-3",translate:"translate-x-4"},md:{track:"w-11 h-6",thumb:"size-5",translate:"translate-x-5"},lg:{track:"w-14 h-7",thumb:"size-6",translate:"translate-x-7"}},l=()=>{!i&&t&&t(!e)};return m.jsxs("div",{className:at("flex items-center gap-3",i&&"opacity-50 cursor-not-allowed",o),children:[m.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:i,onClick:l,className:at("relative inline-flex shrink-0 cursor-pointer rounded-full","transition-colors duration-200 ease-in-out","focus:outline-none focus:ring-2 focus:ring-brand-500/30",e?"bg-brand-500":"bg-surface-3",s[a].track,i&&"cursor-not-allowed"),children:m.jsx("span",{className:at("pointer-events-none inline-block rounded-full bg-white shadow-sm","transform transition duration-200 ease-in-out",e?s[a].translate:"translate-x-0.5",s[a].thumb,"mt-0.5")})}),(r||n)&&m.jsxs("div",{className:"flex flex-col",children:[r&&m.jsx("span",{className:"text-sm font-medium text-text-main",children:r}),n&&m.jsx("span",{className:"text-xs text-text-muted",children:n})]})]})}function Kc({isOpen:e,provider:t,providerInfo:r,onSuccess:n,onClose:i,oauthMeta:a,idcConfig:o}){const[s,l]=g.useState("waiting"),[c,u]=g.useState(null),[d,f]=g.useState(""),[h,p]=g.useState(null),[y,x]=g.useState(!1),[v,S]=g.useState(null),[b,w]=g.useState(!1),E=g.useRef(null),A=g.useRef(!1),_=g.useRef(!1),{copied:O,copy:j}=Uv(),[M,N]=g.useState(!1),[k,z]=g.useState("/callback?code=..."),P=g.useRef(!1);g.useEffect(()=>{typeof window<"u"&&(N(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),z(`${window.location.origin}/callback?code=...`))},[]);const I=g.useCallback(async(q,X)=>{if(c)try{const F=await fetch(`/api/oauth/${t}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,redirectUri:c.redirectUri,codeVerifier:c.codeVerifier,state:X,...a?{meta:a}:{}})}),B=await F.json();if(!F.ok)throw new Error(B.error);l("success"),n==null||n()}catch(F){p(F.message),l("error")}},[c,t,n,a]),C=g.useCallback(async q=>{if(c!=null&&c.state)try{const X=await fetch("/api/oauth/xai/manual-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,state:c.state})}),F=await X.json();if(!X.ok)throw new Error(F.error);l("success"),n==null||n()}catch(X){p(X.message),l("error")}},[c,n]),T=g.useCallback(async(q,X,F,B,K)=>{A.current=!1,w(!0);const R=Date.now()+(Number.isFinite(K)&&K>0?K:12e4);for(;Date.now()<R;){if(A.current){console.log("[OAuthModal] Polling aborted"),w(!1);return}if(await new Promise(Z=>setTimeout(Z,F*1e3)),A.current){console.log("[OAuthModal] Polling aborted after sleep"),w(!1);return}try{const J=await(await fetch(`/api/oauth/${t}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:q,codeVerifier:X,extraData:B})})).json();if(J.success){A.current=!0,l("success"),w(!1),n==null||n();return}if(J.error==="expired_token"||J.error==="access_denied")throw new Error(J.errorDescription||J.error);J.error==="slow_down"&&(F=Math.min(F+5,30))}catch(Z){p(Z.message),l("error"),w(!1);return}}p("Authorization timeout"),l("error"),w(!1)},[t,n]),$=g.useCallback(async()=>{if(t)try{if(p(null),["github","qwen","kiro","kimi-coding","kilocode","codebuddy-cn","qoder","grok-cli"].includes(t)){x(!0),l("waiting");const re=new URL(`/api/oauth/${t}/device-code`,window.location.origin);t==="kiro"&&(o!=null&&o.startUrl)&&(re.searchParams.set("start_url",o.startUrl),o.region&&re.searchParams.set("region",o.region),re.searchParams.set("auth_method","idc"));const le=await fetch(re.toString()),se=await le.json();if(!le.ok)throw new Error(se.error);S(se);const ce=se.verification_uri_complete||se.verification_uri;ce&&window.open(ce,"_blank","noopener,noreferrer");const ke=t==="kiro"?{_clientId:se._clientId,_clientSecret:se._clientSecret,_region:se._region,_authMethod:se._authMethod,_startUrl:se._startUrl}:t==="qoder"?{_qoderNonce:se._qoderNonce,_qoderMachineId:se._qoderMachineId,_qoderVerifier:se.codeVerifier}:null;T(se.device_code,se.codeVerifier,se.interval||5,ke,Number.isFinite(se.expires_in)&&se.expires_in>0?se.expires_in*1e3:void 0);return}const X=window.location.port||(window.location.protocol==="https:"?"443":"80");let F;t==="codex"?F="http://localhost:1455/auth/callback":t==="xai"?F="http://127.0.0.1:56121/callback":F=`http://localhost:${X}/callback`;const B=new URL(`/api/oauth/${t}/authorize`,window.location.origin);B.searchParams.set("redirect_uri",F),a&&Object.entries(a).forEach(([re,le])=>{le&&B.searchParams.set(re,le)});const K=await fetch(B.toString()),U=await K.json();if(!K.ok)throw new Error(U.error);let R=!1,Z=!1;if(t==="codex")try{const re=new URL("/api/oauth/codex/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();R=se.success,Z=!!se.serverSide}catch{R=!1}let J=!1,ee=!1;if(t==="xai")try{const re=new URL("/api/oauth/xai/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();if(J=se.success,ee=!!se.serverSide,!J&&se.reason==="port_busy")throw new Error("Port 56121 in use; close the conflicting process and retry")}catch(re){if(re!=null&&re.message)throw re;J=!1}if(u({...U,redirectUri:F,codexServerSide:Z,xaiServerSide:ee}),!U.authUrl)throw U.flowType==="device_code"?new Error(`Provider ${t} uses device-code login but is not wired in the OAuth modal device-code list`):new Error("No authorization URL returned from OAuth provider");t==="codex"&&R||t==="xai"&&J?(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input")):!M||t==="codex"||t==="xai"?(l("input"),window.open(U.authUrl,"_blank")):(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input"))}catch(q){p(q.message),l("error")}},[t,M,T,a,o]);g.useEffect(()=>{if(e&&t){if(_.current)return;_.current=!0,u(null),f(""),p(null),x(!1),S(null),w(!1),A.current=!1,$()}else e||(A.current=!0,_.current=!1,t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}))},[e,t,$]),g.useEffect(()=>{const q=c!=null&&c.codexServerSide?"codex":c!=null&&c.xaiServerSide?"xai":null;if(!q||!(c!=null&&c.state)||P.current)return;let X=!1;const F=1500,B=200;let K=0;const U=async()=>{if(!(X||P.current)){K+=1;try{const Z=await(await fetch(`/api/oauth/${q}/poll-status?state=${encodeURIComponent(c.state)}`)).json();if(X||P.current)return;if(Z.status==="done"){P.current=!0,l("success"),n==null||n();return}if(Z.status==="error"){P.current=!0,p(Z.error||"Authentication failed"),l("error");return}}catch{}if(K>=B){P.current=!0,p("Authentication timeout"),l("error");return}setTimeout(U,F)}};return setTimeout(U,F),()=>{X=!0}},[c,n]),g.useEffect(()=>{if(!c)return;P.current=!1;const q=async K=>{if(P.current)return;const{code:U,token:R,state:Z,error:J,errorDescription:ee}=K;if(J){P.current=!0,p(ee||J),l("error");return}(R||U)&&(P.current=!0,await I(R||U,Z))},X=K=>{var Z;const U=K.origin.includes("localhost")||K.origin.includes("127.0.0.1"),R=K.origin===window.location.origin;!U&&!R||((Z=K.data)==null?void 0:Z.type)==="oauth_callback"&&q(K.data.data)};window.addEventListener("message",X);let F;try{F=new BroadcastChannel("oauth_callback"),F.onmessage=K=>q(K.data)}catch{console.log("BroadcastChannel not supported")}const B=K=>{if(K.key==="oauth_callback"&&K.newValue)try{const U=JSON.parse(K.newValue);q(U),localStorage.removeItem("oauth_callback")}catch{console.log("Failed to parse localStorage data")}};window.addEventListener("storage",B);try{const K=localStorage.getItem("oauth_callback");if(K){const U=JSON.parse(K);U.timestamp&&Date.now()-U.timestamp<3e4&&q(U),localStorage.removeItem("oauth_callback")}}catch{}return()=>{window.removeEventListener("message",X),window.removeEventListener("storage",B),F&&F.close()}},[c,I]);const D=async()=>{try{p(null);const q=d.trim();if(q.startsWith("eyJ")&&q.includes(".")){await I(q,null);return}if(t==="xai"&&q&&!q.includes("://")&&!q.includes("?")&&!q.includes("code=")){await C(q);return}if(t==="kimchi"&&q&&!q.includes("://")&&!q.includes("?")){await I(q,null);return}const X=new URL(q),F=X.searchParams.get("code"),B=X.searchParams.get("token"),K=X.searchParams.get("state"),U=X.searchParams.get("error");if(U)throw new Error(X.searchParams.get("error_description")||U);if(!F&&!B)throw new Error(t==="xai"?"Paste the callback URL or copied xAI code":t==="kimchi"?"No Kimchi token found in URL":"No authorization code found in URL");await I(B||F,K)}catch(q){p(q.message),l("error")}},L=g.useCallback(()=>{t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}),i()},[i,t]);if(!t||!r)return null;const V=t==="xai",H=t==="kimchi",Q=(v==null?void 0:v.verification_uri_complete)||(v==null?void 0:v.verification_uri)||"",te=V?"Connect Grok Build OAuth":`Connect ${r.name}`,G=V?"http://127.0.0.1:56121/callback?code=... or copied code":H?`${k.replace("code=...","token=...")} or copied token`:k;return m.jsx(hr,{isOpen:e,title:te,onClose:L,size:"lg",children:m.jsxs("div",{className:"flex flex-col gap-4",children:[(s==="waiting"||s==="input")&&!y&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border border-border rounded-lg bg-sidebar/50",children:[m.jsx("span",{className:"material-symbols-outlined text-base text-primary animate-spin",children:"progress_activity"}),m.jsx("span",{className:"text-sm",children:V?"Waiting for Grok Build OAuth…":"Waiting for popup authorization…"})]}),m.jsxs("div",{className:"flex items-center gap-3 my-1",children:[m.jsx("div",{className:"flex-1 h-px bg-border"}),m.jsx("span",{className:"text-xs text-text-muted uppercase tracking-wider",children:"Or paste callback URL manually"}),m.jsx("div",{className:"flex-1 h-px bg-border"})]}),m.jsxs("div",{className:"space-y-4",children:[m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 1: Open this ",V?"Grok Build OAuth URL":"URL"," in your browser"]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(xe,{value:(c==null?void 0:c.authUrl)||"",readOnly:!0,className:"flex-1 font-mono text-xs"}),m.jsx(ue,{variant:"secondary",icon:O==="auth_url"?"check":"content_copy",onClick:()=>j(c==null?void 0:c.authUrl,"auth_url"),disabled:!(c!=null&&c.authUrl),children:"Copy"})]})]}),m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 2: Paste the ",t==="xai"?"callback URL or copied code":H?"callback URL or copied token":"callback URL"," here"]}),m.jsx("p",{className:"text-xs text-text-muted mb-2",children:t==="xai"?"If xAI shows a code instead of redirecting, paste that code here.":H?"After authorization, copy the full callback URL or token from your browser.":"After authorization, copy the full URL from your browser."}),m.jsx(xe,{value:d,onChange:q=>f(q.target.value),placeholder:G,className:"font-mono text-xs"})]})]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:D,fullWidth:!0,disabled:!d,children:"Connect"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),s==="waiting"&&y&&v&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"text-center py-4",children:[m.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Visit the login URL below and authorize:"}),m.jsxs("div",{className:"bg-sidebar p-4 rounded-lg mb-4",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Login URL"}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("code",{className:"flex-1 text-sm break-all",children:Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="login_url"?"check":"content_copy",onClick:()=>j(Q,"login_url"),disabled:!Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:"open_in_new",onClick:()=>window.open(Q,"_blank","noopener,noreferrer"),disabled:!Q,children:"Open"})]})]}),m.jsxs("div",{className:"bg-primary/10 p-4 rounded-lg",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Your Code"}),m.jsxs("div",{className:"flex items-center justify-center gap-2",children:[m.jsx("p",{className:"text-2xl font-mono font-bold text-primary",children:v.user_code}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="user_code"?"check":"content_copy",onClick:()=>j(v.user_code,"user_code")})]})]})]}),b&&m.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),"Waiting for authorization..."]})]}),s==="success"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-green-600",children:"check_circle"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connected Successfully!"}),m.jsxs("p",{className:"text-sm text-text-muted mb-4",children:["Your ",r.name," account has been connected."]}),m.jsx(ue,{onClick:L,fullWidth:!0,children:"Done"})]}),s==="error"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-red-600",children:"error"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connection Failed"}),m.jsx("p",{className:"text-sm text-red-600 mb-4",children:h}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:$,variant:"secondary",fullWidth:!0,children:"Try Again"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})]})})}Kc.propTypes={isOpen:Y.bool.isRequired,provider:Y.string,providerInfo:Y.shape({name:Y.string}),onSuccess:Y.func,onClose:Y.func.isRequired,oauthMeta:Y.object,idcConfig:Y.shape({startUrl:Y.string,region:Y.string})};const Gd=[...Object.keys(Kv),...Object.keys(Ja),...Object.keys(Vv),...Object.keys(Hv)],Zd=Object.keys(Ja).filter(e=>Ja[e].noAuth);function eA({isOpen:e,onClose:t,onSelect:r,onDeselect:n,selectedModel:i,activeProviders:a=[],title:o="Select Model",modelAliases:s={},kindFilter:l=null,addedModelValues:c=[],closeOnSelect:u=!0}){const d=g.useMemo(()=>l?a.filter(C=>{const T=Qa[C.provider];return((T==null?void 0:T.serviceKinds)||["llm"]).includes(l)}):a,[a,l]),[f,h]=g.useState(""),[p,y]=g.useState([]),[x,v]=g.useState([]),[S,b]=g.useState([]),[w,E]=g.useState({}),A=async()=>{try{const C=await fetch("/api/combos");if(!C.ok)throw new Error(`Failed to fetch combos: ${C.status}`);const T=await C.json();y(T.combos||[])}catch(C){console.error("Error fetching combos:",C),y([])}};g.useEffect(()=>{e&&A()},[e]);const _=async()=>{try{const C=await fetch("/api/provider-nodes");if(!C.ok)throw new Error(`Failed to fetch provider nodes: ${C.status}`);const T=await C.json();v(T.nodes||[])}catch(C){console.error("Error fetching provider nodes:",C),v([])}};g.useEffect(()=>{e&&_()},[e]);const O=async()=>{try{const C=await fetch("/api/models/custom");if(!C.ok)throw new Error(`Failed to fetch custom models: ${C.status}`);const T=await C.json();b(T.models||[])}catch(C){console.error("Error fetching custom models:",C),b([])}};g.useEffect(()=>{e&&O()},[e]);const j=async()=>{try{const C=await fetch("/api/models/disabled");if(!C.ok)throw new Error(`Failed to fetch disabled models: ${C.status}`);const T=await C.json();E(T.disabled||{})}catch(C){console.error("Error fetching disabled models:",C),E({})}};g.useEffect(()=>{e&&j()},[e]);const M=g.useMemo(()=>({...Kv,...Ja,...Vv,...Hv}),[]),N=g.useMemo(()=>{const C={},T=new Set(["webSearch","webFetch"]),$=new Set(["image","tts","stt","embedding","imageToText"]),D=new Set(["tts","image","webFetch"]),L=G=>l?$.has(l)?G.filter(q=>q.isPlaceholder||q.type===l):G:G.filter(q=>q.isPlaceholder||!q.type||q.type==="llm"),V=d.map(G=>G.provider),H=l?Zd.filter(G=>{var q;return(((q=Qa[G])==null?void 0:q.serviceKinds)||["llm"]).includes(l)}):Zd;return[...new Set([...V,...H])].sort((G,q)=>{const X=Gd.indexOf(G),F=Gd.indexOf(q);return(X===-1?999:X)-(F===-1?999:F)}).forEach(G=>{var B;const q=Yd(G),X=M[G]||{name:G,color:"#666"},F=qv(G)||Yv(G);if(l&&T.has(l)){C[G]={name:X.name,alias:q,color:X.color,models:[{id:G,name:X.name,value:G}]};return}if(X.passthroughModels){let U=Object.entries(s).filter(([,R])=>R.startsWith(`${q}/`)).map(([R,Z])=>({id:Z.replace(`${q}/`,""),name:R,value:Z}));if(l&&$.has(l)&&(U=Xd(G).filter(R=>R.type===l).map(R=>({id:R.id,name:R.name,value:`${q}/${R.id}`,type:R.type})),U.length===0&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(U=[{id:G,name:X.name,value:q}])),U.length>0){const R=x.find(J=>J.id===G),Z=(R==null?void 0:R.name)||X.name;C[G]={name:Z,alias:q,color:X.color,models:U}}}else if(F){if(l&&$.has(l))return;const K=a.find(re=>re.provider===G),U=x.find(re=>re.id===G),R=(K==null?void 0:K.name)||(U==null?void 0:U.name)||X.name,Z=((B=K==null?void 0:K.providerSpecificData)==null?void 0:B.prefix)||(U==null?void 0:U.prefix)||G,J=Object.entries(s).filter(([,re])=>re.startsWith(`${G}/`)).map(([re,le])=>({id:le.replace(`${G}/`,""),name:re,value:`${Z}/${le.replace(`${G}/`,"")}`})),ee=J.length>0?J:[{id:`__placeholder__${G}`,name:`${Z}/model-id`,value:`${Z}/model-id`,isPlaceholder:!0}];C[G]={name:R,alias:Z,color:X.color,models:ee,isCustom:!0,hasModels:J.length>0}}else{const K=Xd(G),U=new Set(K.map(ce=>ce.id)),R=K.length>0,Z=Object.entries(s).filter(([ce,ke])=>ke.startsWith(`${q}/`)&&(R?ce===ke.replace(`${q}/`,""):!0)&&!U.has(ke.replace(`${q}/`,""))).map(([ce,ke])=>({id:ke.replace(`${q}/`,""),name:ce,value:ke,isCustom:!0})),J=new Set(Z.map(ce=>ce.id)),ee=S.filter(ce=>ce.providerAlias===q&&!U.has(ce.id)&&!J.has(ce.id)).map(ce=>({id:ce.id,name:ce.name||ce.id,value:`${q}/${ce.id}`,isCustom:!0})),re=[...K.map(ce=>({id:ce.id,name:ce.name,value:`${q}/${ce.id}`,type:ce.type})),...Z,...ee],le=new Set;let se=L(re.filter(ce=>le.has(ce.value)?!1:(le.add(ce.value),!0)));se.length===0&&l&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(se=[{id:G,name:X.name,value:q}]),se.length>0&&(C[G]={name:X.name,alias:q,color:X.color,models:se})}}),Object.entries(C).forEach(([G,q])=>{const X=Yd(G),F=new Set([...w[X]||[],...w[G]||[]]);F.size!==0&&(q.models=q.models.filter(B=>!F.has(B.id)),q.models.length===0&&delete C[G])}),C},[d,s,M,x,S,w,l,a]),k=g.useMemo(()=>{if(l)return[];if(!f.trim())return p;const C=f.toLowerCase();return p.filter(T=>T.name.toLowerCase().includes(C))},[p,f,l]),z=C=>{const T=C.filter(D=>c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name)),$=C.filter(D=>!c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name));return[...T,...$]},P=g.useMemo(()=>{const C=f.trim().toLowerCase(),T={};return Object.entries(N).forEach(([$,D])=>{let L=D.models;if(C){const V=D.name.toLowerCase().includes(C);if(L=L.filter(H=>H.name.toLowerCase().includes(C)||H.id.toLowerCase().includes(C)),L.length===0&&!V)return}T[$]={...D,models:z(L)}}),T},[N,f,c]),I=C=>{const T=(C==null?void 0:C.value)||(C==null?void 0:C.name)||C;c.includes(T)&&n?n(C):r(C),u&&(t(),h(""))};return m.jsxs(hr,{isOpen:e,onClose:()=>{t(),h("")},title:o,size:"md",className:"p-4!",footer:null,children:[m.jsxs("div",{className:"flex items-center gap-2 mb-3 px-2.5 py-2 bg-primary/8 border border-primary/20 rounded-lg text-xs text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined text-primary shrink-0",style:{fontSize:"14px"},children:"info"}),m.jsx("span",{children:"Click to add, click again to remove. Changes are saved automatically."})]}),m.jsx("div",{className:"mb-3",children:m.jsxs("div",{className:"relative",children:[m.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-text-muted text-[16px]",children:"search"}),m.jsx("input",{type:"text",placeholder:"Search...",value:f,onChange:C=>h(C.target.value),className:"w-full pl-8 pr-3 py-1.5 bg-surface border border-border rounded text-xs focus:outline-none focus:ring-1 focus:ring-primary/50"})]})}),m.jsxs("div",{className:"max-h-[400px] overflow-y-auto space-y-3",children:[k.length>0&&m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 sticky top-0 bg-surface py-0.5",children:[m.jsx("span",{className:"material-symbols-outlined text-primary text-[14px]",children:"layers"}),m.jsx("span",{className:"text-xs font-medium text-primary",children:"Combos"}),m.jsxs("span",{className:"text-[10px] text-text-muted",children:["(",k.length,")"]})]}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(C=>{const T=i===C.name;return m.jsxs("button",{onClick:()=>I({id:C.name,name:C.name,value:C.name}),className:`
1
+ var KS=Object.defineProperty;var qS=(e,t,r)=>t in e?KS(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ma=(e,t,r)=>qS(e,typeof t!="symbol"?t+"":t,r);import{j as m,n as at,u as Uv,M as hr,B as ue,f as Y,g as Qa,A as Hv,c as Vv,F as Ja,O as Kv,i as Yd,k as qv,l as Yv,h as Xd,P as YS}from"./index.CShjRV_B.js";import{b as g,r as Vc,g as Xv,W as XS,c as Gv,i as GS}from"./router.Cjj1--8t.js";function xe({label:e,type:t="text",placeholder:r,value:n,onChange:i,error:a,hint:o,icon:s,disabled:l=!1,required:c=!1,className:u,inputClassName:d,...f}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",u),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,c&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[s&&m.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:s})}),m.jsx("input",{type:t,placeholder:r,value:n,onChange:i,disabled:l,className:at("w-full py-2.5 px-3 text-sm text-text-main bg-surface-2 rounded-[10px]","border border-transparent placeholder-text-muted/70","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 ease-out disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",s&&"pl-10",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",d),...f})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function ZS({label:e,options:t=[],value:r,onChange:n,placeholder:i="Select an option",error:a,hint:o,disabled:s=!1,required:l=!1,className:c,selectClassName:u,...d}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",c),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,l&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[m.jsxs("select",{value:r,onChange:n,disabled:s,className:at("w-full py-2.5 px-3 pr-10 text-sm text-text-main","bg-surface-2 border border-transparent rounded-[10px] appearance-none","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",u),...d,children:[m.jsx("option",{value:"",disabled:!0,children:i}),t.map(f=>m.jsx("option",{value:f.value,children:f.label},f.value))]}),m.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"expand_more"})})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function zt({children:e,title:t,subtitle:r,icon:n,action:i,padding:a="md",hover:o=!1,elev:s=!1,className:l,...c}){const u={none:"",xs:"p-3",sm:"p-4",md:"p-6",lg:"p-8"};return m.jsxs("div",{className:at("bg-surface border border-border-subtle",s?"rounded-[14px] shadow-[var(--shadow-elev)]":"rounded-[14px] shadow-[var(--shadow-soft)]",o&&"hover:shadow-[var(--shadow-warm)] hover:border-brand-500/30 transition-all cursor-pointer",u[a],l),...c,children:[(t||i)&&m.jsxs("div",{className:"flex items-center justify-between mb-4",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[n&&m.jsx("div",{className:"p-2 rounded-[10px] bg-bg text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:n})}),m.jsxs("div",{children:[t&&m.jsx("h3",{className:"text-text-main font-semibold",children:t}),r&&m.jsx("p",{className:"text-sm text-text-muted",children:r})]})]}),i]}),e]})}zt.Section=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-4 rounded-[10px]","bg-bg border border-border-subtle",r),...n,children:t})};zt.Row=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-3 -mx-3 px-3 transition-colors","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50",r),...n,children:t})};zt.ListItem=function({children:t,actions:r,className:n,...i}){return m.jsxs("div",{className:at("group flex items-center justify-between p-3 -mx-3 px-3","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50 transition-colors",n),...i,children:[m.jsx("div",{className:"flex-1 min-w-0",children:t}),r&&m.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:r})]})};const QS={default:"bg-surface-2 text-text-muted",primary:"bg-brand-500/10 text-brand-600 dark:text-brand-300",success:"bg-green-500/10 text-green-600 dark:text-green-400",warning:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400",error:"bg-red-500/10 text-red-600 dark:text-red-400",info:"bg-blue-500/10 text-blue-600 dark:text-blue-400"},JS={sm:"px-2 py-0.5 text-[10px]",md:"px-2.5 py-1 text-xs",lg:"px-3 py-1.5 text-sm"};function Ci({children:e,variant:t="default",size:r="md",dot:n=!1,icon:i,className:a}){return m.jsxs("span",{className:at("inline-flex items-center gap-1.5 rounded-full font-semibold",QS[t],JS[r],a),children:[n&&m.jsx("span",{className:at("size-1.5 rounded-full",t==="success"&&"bg-green-500",t==="warning"&&"bg-yellow-500",t==="error"&&"bg-red-500",t==="info"&&"bg-blue-500",t==="primary"&&"bg-brand-500",t==="default"&&"bg-gray-500")}),i&&m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:i}),e]})}function Js({checked:e=!1,onChange:t,label:r,description:n,disabled:i=!1,size:a="md",className:o}){const s={sm:{track:"w-8 h-4",thumb:"size-3",translate:"translate-x-4"},md:{track:"w-11 h-6",thumb:"size-5",translate:"translate-x-5"},lg:{track:"w-14 h-7",thumb:"size-6",translate:"translate-x-7"}},l=()=>{!i&&t&&t(!e)};return m.jsxs("div",{className:at("flex items-center gap-3",i&&"opacity-50 cursor-not-allowed",o),children:[m.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:i,onClick:l,className:at("relative inline-flex shrink-0 cursor-pointer rounded-full","transition-colors duration-200 ease-in-out","focus:outline-none focus:ring-2 focus:ring-brand-500/30",e?"bg-brand-500":"bg-surface-3",s[a].track,i&&"cursor-not-allowed"),children:m.jsx("span",{className:at("pointer-events-none inline-block rounded-full bg-white shadow-sm","transform transition duration-200 ease-in-out",e?s[a].translate:"translate-x-0.5",s[a].thumb,"mt-0.5")})}),(r||n)&&m.jsxs("div",{className:"flex flex-col",children:[r&&m.jsx("span",{className:"text-sm font-medium text-text-main",children:r}),n&&m.jsx("span",{className:"text-xs text-text-muted",children:n})]})]})}function Kc({isOpen:e,provider:t,providerInfo:r,onSuccess:n,onClose:i,oauthMeta:a,idcConfig:o}){const[s,l]=g.useState("waiting"),[c,u]=g.useState(null),[d,f]=g.useState(""),[h,p]=g.useState(null),[y,x]=g.useState(!1),[v,S]=g.useState(null),[b,w]=g.useState(!1),E=g.useRef(null),A=g.useRef(!1),_=g.useRef(!1),{copied:O,copy:j}=Uv(),[M,N]=g.useState(!1),[k,z]=g.useState("/callback?code=..."),P=g.useRef(!1);g.useEffect(()=>{typeof window<"u"&&(N(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),z(`${window.location.origin}/callback?code=...`))},[]);const I=g.useCallback(async(q,X)=>{if(c)try{const F=await fetch(`/api/oauth/${t}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,redirectUri:c.redirectUri,codeVerifier:c.codeVerifier,state:X,...a?{meta:a}:{}})}),B=await F.json();if(!F.ok)throw new Error(B.error);l("success"),n==null||n()}catch(F){p(F.message),l("error")}},[c,t,n,a]),C=g.useCallback(async q=>{if(c!=null&&c.state)try{const X=await fetch("/api/oauth/xai/manual-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,state:c.state})}),F=await X.json();if(!X.ok)throw new Error(F.error);l("success"),n==null||n()}catch(X){p(X.message),l("error")}},[c,n]),T=g.useCallback(async(q,X,F,B,K)=>{A.current=!1,w(!0);const R=Date.now()+(Number.isFinite(K)&&K>0?K:12e4);for(;Date.now()<R;){if(A.current){console.log("[OAuthModal] Polling aborted"),w(!1);return}if(await new Promise(Z=>setTimeout(Z,F*1e3)),A.current){console.log("[OAuthModal] Polling aborted after sleep"),w(!1);return}try{const J=await(await fetch(`/api/oauth/${t}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:q,codeVerifier:X,extraData:B})})).json();if(J.success){A.current=!0,l("success"),w(!1),n==null||n();return}if(J.error==="expired_token"||J.error==="access_denied")throw new Error(J.errorDescription||J.error);J.error==="slow_down"&&(F=Math.min(F+5,30))}catch(Z){p(Z.message),l("error"),w(!1);return}}p("Authorization timeout"),l("error"),w(!1)},[t,n]),$=g.useCallback(async()=>{if(t)try{if(p(null),["github","qwen","kiro","kimi-coding","kilocode","codebuddy-cn","qoder","grok-cli"].includes(t)){x(!0),l("waiting");const re=new URL(`/api/oauth/${t}/device-code`,window.location.origin);t==="kiro"&&(o!=null&&o.startUrl)&&(re.searchParams.set("start_url",o.startUrl),o.region&&re.searchParams.set("region",o.region),re.searchParams.set("auth_method","idc"));const le=await fetch(re.toString()),se=await le.json();if(!le.ok)throw new Error(se.error);S(se);const ce=se.verification_uri_complete||se.verification_uri;ce&&window.open(ce,"_blank","noopener,noreferrer");const ke=t==="kiro"?{_clientId:se._clientId,_clientSecret:se._clientSecret,_region:se._region,_authMethod:se._authMethod,_startUrl:se._startUrl}:t==="qoder"?{_qoderNonce:se._qoderNonce,_qoderMachineId:se._qoderMachineId,_qoderVerifier:se.codeVerifier}:null;T(se.device_code,se.codeVerifier,se.interval||5,ke,Number.isFinite(se.expires_in)&&se.expires_in>0?se.expires_in*1e3:void 0);return}const X=window.location.port||(window.location.protocol==="https:"?"443":"80");let F;t==="codex"?F="http://localhost:1455/auth/callback":t==="xai"?F="http://127.0.0.1:56121/callback":F=`http://localhost:${X}/callback`;const B=new URL(`/api/oauth/${t}/authorize`,window.location.origin);B.searchParams.set("redirect_uri",F),a&&Object.entries(a).forEach(([re,le])=>{le&&B.searchParams.set(re,le)});const K=await fetch(B.toString()),U=await K.json();if(!K.ok)throw new Error(U.error);let R=!1,Z=!1;if(t==="codex")try{const re=new URL("/api/oauth/codex/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();R=se.success,Z=!!se.serverSide}catch{R=!1}let J=!1,ee=!1;if(t==="xai")try{const re=new URL("/api/oauth/xai/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();if(J=se.success,ee=!!se.serverSide,!J&&se.reason==="port_busy")throw new Error("Port 56121 in use; close the conflicting process and retry")}catch(re){if(re!=null&&re.message)throw re;J=!1}if(u({...U,redirectUri:F,codexServerSide:Z,xaiServerSide:ee}),!U.authUrl)throw U.flowType==="device_code"?new Error(`Provider ${t} uses device-code login but is not wired in the OAuth modal device-code list`):new Error("No authorization URL returned from OAuth provider");t==="codex"&&R||t==="xai"&&J?(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input")):!M||t==="codex"||t==="xai"?(l("input"),window.open(U.authUrl,"_blank")):(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input"))}catch(q){p(q.message),l("error")}},[t,M,T,a,o]);g.useEffect(()=>{if(e&&t){if(_.current)return;_.current=!0,u(null),f(""),p(null),x(!1),S(null),w(!1),A.current=!1,$()}else e||(A.current=!0,_.current=!1,t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}))},[e,t,$]),g.useEffect(()=>{const q=c!=null&&c.codexServerSide?"codex":c!=null&&c.xaiServerSide?"xai":null;if(!q||!(c!=null&&c.state)||P.current)return;let X=!1;const F=1500,B=200;let K=0;const U=async()=>{if(!(X||P.current)){K+=1;try{const Z=await(await fetch(`/api/oauth/${q}/poll-status?state=${encodeURIComponent(c.state)}`)).json();if(X||P.current)return;if(Z.status==="done"){P.current=!0,l("success"),n==null||n();return}if(Z.status==="error"){P.current=!0,p(Z.error||"Authentication failed"),l("error");return}}catch{}if(K>=B){P.current=!0,p("Authentication timeout"),l("error");return}setTimeout(U,F)}};return setTimeout(U,F),()=>{X=!0}},[c,n]),g.useEffect(()=>{if(!c)return;P.current=!1;const q=async K=>{if(P.current)return;const{code:U,token:R,state:Z,error:J,errorDescription:ee}=K;if(J){P.current=!0,p(ee||J),l("error");return}(R||U)&&(P.current=!0,await I(R||U,Z))},X=K=>{var Z;const U=K.origin.includes("localhost")||K.origin.includes("127.0.0.1"),R=K.origin===window.location.origin;!U&&!R||((Z=K.data)==null?void 0:Z.type)==="oauth_callback"&&q(K.data.data)};window.addEventListener("message",X);let F;try{F=new BroadcastChannel("oauth_callback"),F.onmessage=K=>q(K.data)}catch{console.log("BroadcastChannel not supported")}const B=K=>{if(K.key==="oauth_callback"&&K.newValue)try{const U=JSON.parse(K.newValue);q(U),localStorage.removeItem("oauth_callback")}catch{console.log("Failed to parse localStorage data")}};window.addEventListener("storage",B);try{const K=localStorage.getItem("oauth_callback");if(K){const U=JSON.parse(K);U.timestamp&&Date.now()-U.timestamp<3e4&&q(U),localStorage.removeItem("oauth_callback")}}catch{}return()=>{window.removeEventListener("message",X),window.removeEventListener("storage",B),F&&F.close()}},[c,I]);const D=async()=>{try{p(null);const q=d.trim();if(q.startsWith("eyJ")&&q.includes(".")){await I(q,null);return}if(t==="xai"&&q&&!q.includes("://")&&!q.includes("?")&&!q.includes("code=")){await C(q);return}if(t==="kimchi"&&q&&!q.includes("://")&&!q.includes("?")){await I(q,null);return}const X=new URL(q),F=X.searchParams.get("code"),B=X.searchParams.get("token"),K=X.searchParams.get("state"),U=X.searchParams.get("error");if(U)throw new Error(X.searchParams.get("error_description")||U);if(!F&&!B)throw new Error(t==="xai"?"Paste the callback URL or copied xAI code":t==="kimchi"?"No Kimchi token found in URL":"No authorization code found in URL");await I(B||F,K)}catch(q){p(q.message),l("error")}},L=g.useCallback(()=>{t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}),i()},[i,t]);if(!t||!r)return null;const V=t==="xai",H=t==="kimchi",Q=(v==null?void 0:v.verification_uri_complete)||(v==null?void 0:v.verification_uri)||"",te=V?"Connect Grok Build OAuth":`Connect ${r.name}`,G=V?"http://127.0.0.1:56121/callback?code=... or copied code":H?`${k.replace("code=...","token=...")} or copied token`:k;return m.jsx(hr,{isOpen:e,title:te,onClose:L,size:"lg",children:m.jsxs("div",{className:"flex flex-col gap-4",children:[(s==="waiting"||s==="input")&&!y&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border border-border rounded-lg bg-sidebar/50",children:[m.jsx("span",{className:"material-symbols-outlined text-base text-primary animate-spin",children:"progress_activity"}),m.jsx("span",{className:"text-sm",children:V?"Waiting for Grok Build OAuth…":"Waiting for popup authorization…"})]}),m.jsxs("div",{className:"flex items-center gap-3 my-1",children:[m.jsx("div",{className:"flex-1 h-px bg-border"}),m.jsx("span",{className:"text-xs text-text-muted uppercase tracking-wider",children:"Or paste callback URL manually"}),m.jsx("div",{className:"flex-1 h-px bg-border"})]}),m.jsxs("div",{className:"space-y-4",children:[m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 1: Open this ",V?"Grok Build OAuth URL":"URL"," in your browser"]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(xe,{value:(c==null?void 0:c.authUrl)||"",readOnly:!0,className:"flex-1 font-mono text-xs"}),m.jsx(ue,{variant:"secondary",icon:O==="auth_url"?"check":"content_copy",onClick:()=>j(c==null?void 0:c.authUrl,"auth_url"),disabled:!(c!=null&&c.authUrl),children:"Copy"})]})]}),m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 2: Paste the ",t==="xai"?"callback URL or copied code":H?"callback URL or copied token":"callback URL"," here"]}),m.jsx("p",{className:"text-xs text-text-muted mb-2",children:t==="xai"?"If xAI shows a code instead of redirecting, paste that code here.":H?"After authorization, copy the full callback URL or token from your browser.":"After authorization, copy the full URL from your browser."}),m.jsx(xe,{value:d,onChange:q=>f(q.target.value),placeholder:G,className:"font-mono text-xs"})]})]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:D,fullWidth:!0,disabled:!d,children:"Connect"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),s==="waiting"&&y&&v&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"text-center py-4",children:[m.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Visit the login URL below and authorize:"}),m.jsxs("div",{className:"bg-sidebar p-4 rounded-lg mb-4",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Login URL"}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("code",{className:"flex-1 text-sm break-all",children:Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="login_url"?"check":"content_copy",onClick:()=>j(Q,"login_url"),disabled:!Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:"open_in_new",onClick:()=>window.open(Q,"_blank","noopener,noreferrer"),disabled:!Q,children:"Open"})]})]}),m.jsxs("div",{className:"bg-primary/10 p-4 rounded-lg",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Your Code"}),m.jsxs("div",{className:"flex items-center justify-center gap-2",children:[m.jsx("p",{className:"text-2xl font-mono font-bold text-primary",children:v.user_code}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="user_code"?"check":"content_copy",onClick:()=>j(v.user_code,"user_code")})]})]})]}),b&&m.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),"Waiting for authorization..."]})]}),s==="success"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-green-600",children:"check_circle"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connected Successfully!"}),m.jsxs("p",{className:"text-sm text-text-muted mb-4",children:["Your ",r.name," account has been connected."]}),m.jsx(ue,{onClick:L,fullWidth:!0,children:"Done"})]}),s==="error"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-red-600",children:"error"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connection Failed"}),m.jsx("p",{className:"text-sm text-red-600 mb-4",children:h}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:$,variant:"secondary",fullWidth:!0,children:"Try Again"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})]})})}Kc.propTypes={isOpen:Y.bool.isRequired,provider:Y.string,providerInfo:Y.shape({name:Y.string}),onSuccess:Y.func,onClose:Y.func.isRequired,oauthMeta:Y.object,idcConfig:Y.shape({startUrl:Y.string,region:Y.string})};const Gd=[...Object.keys(Kv),...Object.keys(Ja),...Object.keys(Vv),...Object.keys(Hv)],Zd=Object.keys(Ja).filter(e=>Ja[e].noAuth);function eA({isOpen:e,onClose:t,onSelect:r,onDeselect:n,selectedModel:i,activeProviders:a=[],title:o="Select Model",modelAliases:s={},kindFilter:l=null,addedModelValues:c=[],closeOnSelect:u=!0}){const d=g.useMemo(()=>l?a.filter(C=>{const T=Qa[C.provider];return((T==null?void 0:T.serviceKinds)||["llm"]).includes(l)}):a,[a,l]),[f,h]=g.useState(""),[p,y]=g.useState([]),[x,v]=g.useState([]),[S,b]=g.useState([]),[w,E]=g.useState({}),A=async()=>{try{const C=await fetch("/api/combos");if(!C.ok)throw new Error(`Failed to fetch combos: ${C.status}`);const T=await C.json();y(T.combos||[])}catch(C){console.error("Error fetching combos:",C),y([])}};g.useEffect(()=>{e&&A()},[e]);const _=async()=>{try{const C=await fetch("/api/provider-nodes");if(!C.ok)throw new Error(`Failed to fetch provider nodes: ${C.status}`);const T=await C.json();v(T.nodes||[])}catch(C){console.error("Error fetching provider nodes:",C),v([])}};g.useEffect(()=>{e&&_()},[e]);const O=async()=>{try{const C=await fetch("/api/models/custom");if(!C.ok)throw new Error(`Failed to fetch custom models: ${C.status}`);const T=await C.json();b(T.models||[])}catch(C){console.error("Error fetching custom models:",C),b([])}};g.useEffect(()=>{e&&O()},[e]);const j=async()=>{try{const C=await fetch("/api/models/disabled");if(!C.ok)throw new Error(`Failed to fetch disabled models: ${C.status}`);const T=await C.json();E(T.disabled||{})}catch(C){console.error("Error fetching disabled models:",C),E({})}};g.useEffect(()=>{e&&j()},[e]);const M=g.useMemo(()=>({...Kv,...Ja,...Vv,...Hv}),[]),N=g.useMemo(()=>{const C={},T=new Set(["webSearch","webFetch"]),$=new Set(["image","tts","stt","embedding","imageToText"]),D=new Set(["tts","image","webFetch"]),L=G=>l?$.has(l)?G.filter(q=>q.isPlaceholder||q.type===l):G:G.filter(q=>q.isPlaceholder||!q.type||q.type==="llm"),V=d.map(G=>G.provider),H=l?Zd.filter(G=>{var q;return(((q=Qa[G])==null?void 0:q.serviceKinds)||["llm"]).includes(l)}):Zd;return[...new Set([...V,...H])].sort((G,q)=>{const X=Gd.indexOf(G),F=Gd.indexOf(q);return(X===-1?999:X)-(F===-1?999:F)}).forEach(G=>{var B;const q=Yd(G),X=M[G]||{name:G,color:"#666"},F=qv(G)||Yv(G);if(l&&T.has(l)){C[G]={name:X.name,alias:q,color:X.color,models:[{id:G,name:X.name,value:G}]};return}if(X.passthroughModels){let U=Object.entries(s).filter(([,R])=>R.startsWith(`${q}/`)).map(([R,Z])=>({id:Z.replace(`${q}/`,""),name:R,value:Z}));if(l&&$.has(l)&&(U=Xd(G).filter(R=>R.type===l).map(R=>({id:R.id,name:R.name,value:`${q}/${R.id}`,type:R.type})),U.length===0&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(U=[{id:G,name:X.name,value:q}])),U.length>0){const R=x.find(J=>J.id===G),Z=(R==null?void 0:R.name)||X.name;C[G]={name:Z,alias:q,color:X.color,models:U}}}else if(F){if(l&&$.has(l))return;const K=a.find(re=>re.provider===G),U=x.find(re=>re.id===G),R=(K==null?void 0:K.name)||(U==null?void 0:U.name)||X.name,Z=((B=K==null?void 0:K.providerSpecificData)==null?void 0:B.prefix)||(U==null?void 0:U.prefix)||G,J=Object.entries(s).filter(([,re])=>re.startsWith(`${G}/`)).map(([re,le])=>({id:le.replace(`${G}/`,""),name:re,value:`${Z}/${le.replace(`${G}/`,"")}`})),ee=J.length>0?J:[{id:`__placeholder__${G}`,name:`${Z}/model-id`,value:`${Z}/model-id`,isPlaceholder:!0}];C[G]={name:R,alias:Z,color:X.color,models:ee,isCustom:!0,hasModels:J.length>0}}else{const K=Xd(G),U=new Set(K.map(ce=>ce.id)),R=K.length>0,Z=Object.entries(s).filter(([ce,ke])=>ke.startsWith(`${q}/`)&&(R?ce===ke.replace(`${q}/`,""):!0)&&!U.has(ke.replace(`${q}/`,""))).map(([ce,ke])=>({id:ke.replace(`${q}/`,""),name:ce,value:ke,isCustom:!0})),J=new Set(Z.map(ce=>ce.id)),ee=S.filter(ce=>ce.providerAlias===q&&!U.has(ce.id)&&!J.has(ce.id)).map(ce=>({id:ce.id,name:ce.name||ce.id,value:`${q}/${ce.id}`,isCustom:!0})),re=[...K.map(ce=>({id:ce.id,name:ce.name,value:`${q}/${ce.id}`,type:ce.type})),...Z,...ee],le=new Set;let se=L(re.filter(ce=>le.has(ce.value)?!1:(le.add(ce.value),!0)));se.length===0&&l&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(se=[{id:G,name:X.name,value:q}]),se.length>0&&(C[G]={name:X.name,alias:q,color:X.color,models:se})}}),Object.entries(C).forEach(([G,q])=>{const X=Yd(G),F=new Set([...w[X]||[],...w[G]||[]]);F.size!==0&&(q.models=q.models.filter(B=>!F.has(B.id)),q.models.length===0&&delete C[G])}),C},[d,s,M,x,S,w,l,a]),k=g.useMemo(()=>{if(l)return[];if(!f.trim())return p;const C=f.toLowerCase();return p.filter(T=>T.name.toLowerCase().includes(C))},[p,f,l]),z=C=>{const T=C.filter(D=>c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name)),$=C.filter(D=>!c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name));return[...T,...$]},P=g.useMemo(()=>{const C=f.trim().toLowerCase(),T={};return Object.entries(N).forEach(([$,D])=>{let L=D.models;if(C){const V=D.name.toLowerCase().includes(C);if(L=L.filter(H=>H.name.toLowerCase().includes(C)||H.id.toLowerCase().includes(C)),L.length===0&&!V)return}T[$]={...D,models:z(L)}}),T},[N,f,c]),I=C=>{const T=(C==null?void 0:C.value)||(C==null?void 0:C.name)||C;c.includes(T)&&n?n(C):r(C),u&&(t(),h(""))};return m.jsxs(hr,{isOpen:e,onClose:()=>{t(),h("")},title:o,size:"md",className:"p-4!",footer:null,children:[m.jsxs("div",{className:"flex items-center gap-2 mb-3 px-2.5 py-2 bg-primary/8 border border-primary/20 rounded-lg text-xs text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined text-primary shrink-0",style:{fontSize:"14px"},children:"info"}),m.jsx("span",{children:"Click to add, click again to remove. Changes are saved automatically."})]}),m.jsx("div",{className:"mb-3",children:m.jsxs("div",{className:"relative",children:[m.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-text-muted text-[16px]",children:"search"}),m.jsx("input",{type:"text",placeholder:"Search...",value:f,onChange:C=>h(C.target.value),className:"w-full pl-8 pr-3 py-1.5 bg-surface border border-border rounded text-xs focus:outline-none focus:ring-1 focus:ring-primary/50"})]})}),m.jsxs("div",{className:"max-h-[400px] overflow-y-auto space-y-3",children:[k.length>0&&m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 sticky top-0 bg-surface py-0.5",children:[m.jsx("span",{className:"material-symbols-outlined text-primary text-[14px]",children:"layers"}),m.jsx("span",{className:"text-xs font-medium text-primary",children:"Combos"}),m.jsxs("span",{className:"text-[10px] text-text-muted",children:["(",k.length,")"]})]}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(C=>{const T=i===C.name;return m.jsxs("button",{onClick:()=>I({id:C.name,name:C.name,value:C.name}),className:`
2
2
  px-2 py-1 rounded-xl text-xs font-medium transition-all border hover:cursor-pointer flex items-center gap-1
3
3
  ${T?"bg-primary text-white border-primary":c.includes(C.name)?"bg-primary border-primary text-white hover:bg-primary-hover":"bg-surface border-border text-text-main hover:border-primary/50 hover:bg-primary/5"}
4
4
  `,children:[c.includes(C.name)&&m.jsx("span",{className:"material-symbols-outlined leading-none",style:{fontSize:"10px"},children:"check"}),C.name]},C.id)})})]}),Object.entries(P).map(([C,T])=>m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 sticky top-0 bg-surface py-0.5",children:[m.jsx(YS,{src:C==="codebuddy"||C==="cb"?"/providers/codebuddy.svg":`/providers/${C}.png`,alt:T.name,size:14,fallbackText:(T.name||C).slice(0,2).toUpperCase(),fallbackColor:T.color}),m.jsx("span",{className:"text-xs font-medium text-primary",children:T.name}),m.jsxs("span",{className:"text-[10px] text-text-muted",children:["(",T.models.length,")"]})]}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:T.models.map($=>{const D=i===$.value,L=$.isPlaceholder;return m.jsx("button",{onClick:()=>I($),title:L?"Select to pre-fill, then edit model ID in the input":void 0,className:`