mapigate 0.5.141 → 0.5.146

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 (47) hide show
  1. package/README.md +8 -8
  2. package/dist/core/capabilities/index.js +5 -4
  3. package/dist/providers/catalog/coarena/index.js +3 -0
  4. package/dist/providers/catalog/coarena/metadata.js +104 -0
  5. package/dist/providers/catalog/coarena/provider.js +91 -0
  6. package/dist/providers/catalog/coarena/quota.js +119 -0
  7. package/dist/providers/generated/chunks/chunk1.js +2 -2
  8. package/dist/providers/generated/chunks/chunk2.js +2 -2
  9. package/dist/providers/generated/chunks/chunk3.js +2 -2
  10. package/dist/providers/generated/chunks/chunk4.js +2 -0
  11. package/dist/providers/generated/runtime/chunk1.js +2 -2
  12. package/dist/providers/generated/runtime/chunk2.js +2 -2
  13. package/dist/providers/generated/runtime/chunk3.js +2 -2
  14. package/dist/providers/generated/runtime/chunk4.js +2 -0
  15. package/dist/providers/runtime/trae/index.js +1 -0
  16. package/dist/providers/runtime/trae/metadata.js +1 -0
  17. package/dist/providers/runtime/trae/provider.js +7 -0
  18. package/dist/providers/runtime/trae/quota.js +99 -0
  19. package/dist/providers/runtime/zed/metadata.js +1 -1
  20. package/dist/providers/runtime/zed/models.js +68 -8
  21. package/dist/providers/runtime/zed/provider.js +60 -15
  22. package/dist/providers/runtime/zed/quota.js +69 -12
  23. package/dist/providers/runtime/zed/routes.js +7 -0
  24. package/dist/shared/constants/quotaOrder.js +5 -0
  25. package/dist/web/assets/{CliToolsTab-rKSWLJC3.js → CliToolsTab-BYO-wJ7y.js} +1 -1
  26. package/dist/web/assets/CombosTab-CujUAbYQ.js +1 -0
  27. package/dist/web/assets/{ConfirmModal-OWeauwYv.js → ConfirmModal-BS3mAUd5.js} +1 -1
  28. package/dist/web/assets/{ConsoleLogTab-rZe8zCb_.js → ConsoleLogTab-CSgZxPGW.js} +1 -1
  29. package/dist/web/assets/{EditAccountModal-CAg-yIOn.js → EditAccountModal-BhPOk3Ya.js} +1 -1
  30. package/dist/web/assets/{EndpointTab-B-Jb4wAG.js → EndpointTab-BRVjAng2.js} +1 -1
  31. package/dist/web/assets/{MitmTab-5dKeNi4T.js → MitmTab-ZOoWyRnb.js} +1 -1
  32. package/dist/web/assets/{ModelAutocompleteInput-CoinzdsW.js → ModelAutocompleteInput-DJkxW2yD.js} +1 -1
  33. package/dist/web/assets/{ProviderDetailPage-D-fodBhz.js → ProviderDetailPage-CnWjM-0J.js} +1 -1
  34. package/dist/web/assets/{ProvidersTab-yzmb4w0D.js → ProvidersTab-BFdg0gXr.js} +1 -1
  35. package/dist/web/assets/QuotaTab-DXg3adeS.js +1 -0
  36. package/dist/web/assets/{SettingsTab-LkByv4Sg.js → SettingsTab-DoYGKtDn.js} +1 -1
  37. package/dist/web/assets/{UsageTab-Hr8XPZD4.js → UsageTab-O6OK0i38.js} +1 -1
  38. package/dist/web/assets/{index-CKuvklEr.js → index-5TzViNxR.js} +2 -2
  39. package/dist/web/assets/metadataRegistry-W75_wn57.js +1 -0
  40. package/dist/web/assets/providers/coarena/icon.png +0 -0
  41. package/dist/web/assets/providers/coarena/icon.svg +3 -0
  42. package/dist/web/assets/{providersData-DS1-ETBi.js → providersData-BI_7MaUL.js} +1 -1
  43. package/dist/web/index.html +1 -1
  44. package/package.json +1 -1
  45. package/dist/web/assets/CombosTab-D1_cfssh.js +0 -1
  46. package/dist/web/assets/QuotaTab-BXevQzen.js +0 -1
  47. package/dist/web/assets/metadataRegistry-NuDSSkP9.js +0 -1
@@ -1 +1 @@
1
- import{j as a,r as x}from"./vendor-BcOI2aZ9.js";import{g as X,a as Z}from"./metadataRegistry-NuDSSkP9.js";const v={vision:!1,pdf:!1,audioInput:!1,videoInput:!1,imageOutput:!1,audioOutput:!1,search:!1,tools:!0,reasoning:!1,thinkingFormat:null,thinkingCanDisable:!0,thinkingRange:null,thinkingEffortSupported:!1,contextWindow:2e5,maxOutput:64e3},C="[-_/:.]",ee=new RegExp([`(^|${C})(image|img)(${C}|$)`,"stable-image","gen[0-9]_image","nanobanana","imagine","t2v","i2v","flux","dall","sdxl","diffusion","embed","rerank","guard","moderation","tts","stt","whisper","voice","speech","audio"].join("|"),"i"),te=new RegExp([`(^|${C})(vision|vl|vlm|multimodal|omni|visual)(${C}|$)`,`[0-9]\\.[0-9]+v(${C}|$)`,`(^|${C})glm-[0-9]+v(${C}|$)`,"(^|[-_/:.])(llava|pixtral|internvl|cogvlm|minicpm-v|moondream|idefics|fuyu)"].join("|"),"i"),V={nvidia:{"minimaxai/minimax-m2.7":{reasoning:!0,thinkingFormat:"openai",thinkingCanDisable:!1,contextWindow:2e5,maxOutput:131072},"minimaxai/minimax-m3":{vision:!0,reasoning:!0,thinkingFormat:"openai",thinkingCanDisable:!1,contextWindow:512e3,maxOutput:131072},"deepseek-ai/deepseek-v4-pro":{reasoning:!0,thinkingFormat:"openai",contextWindow:1e6,maxOutput:65536}},"opencode-go":{"glm-5.3-flash":{vision:!0,videoInput:!0,pdf:!0,reasoning:!0,thinkingFormat:"openai",thinkingCanDisable:!1,contextWindow:1e6,maxOutput:131072}}},S={"claude-fable-5-1":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",thinkingCanDisable:!1,contextWindow:1e6,maxOutput:128e3},"claude-opus-5.5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingCanDisable:!1,forcedToolChoice:!1},"claude-opus-5-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingCanDisable:!1,forcedToolChoice:!1},"claude-opus-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-sonnet-5.5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingOffType:"between_tools",forcedToolChoice:!1},"claude-sonnet-5-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingOffType:"between_tools",forcedToolChoice:!1},"claude-haiku-5.5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-haiku-5-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-sonnet-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-opus-4.8":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-opus-4-8":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-opus-4.6":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-opus-4-6":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-sonnet-4.6":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-sonnet-4-6":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-3-7-sonnet":{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3},"claude-3.7-sonnet":{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3},"claude-3-5-sonnet":{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192},"claude-3.5-sonnet":{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192},"claude-3-5-haiku":{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192},"claude-3.5-haiku":{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192},"claude-3-opus":{vision:!0,contextWindow:2e5,maxOutput:4096},"claude-3-haiku":{vision:!0,contextWindow:2e5,maxOutput:4096},"glm-5.3-flash":{vision:!0,videoInput:!0,pdf:!0,reasoning:!0,thinkingFormat:"zai",thinkingCanDisable:!1,contextWindow:1e6,maxOutput:131072},"glm-4.6v":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"zai",contextWindow:128e3,maxOutput:32768},"glm-4.5v":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"zai",contextWindow:64e3,maxOutput:16384},"glm-5.2":{reasoning:!0,thinkingFormat:"zai",thinkingCanDisable:!1,contextWindow:1e6,maxOutput:131072},"deepseek-chat":{vision:!1,reasoning:!0,thinkingFormat:"deepseek",contextWindow:128e3,maxOutput:64e3},"deepseek-reasoner":{vision:!1,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:128e3,maxOutput:64e3},"deepseek-r1":{vision:!1,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:128e3,maxOutput:64e3},"deepseek-v4.1-flash":{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:1e6,maxOutput:384e3},"deepseek-v4-1-flash":{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:1e6,maxOutput:384e3},"deepseek-v4-flash-vision-exp":{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:1e6,maxOutput:384e3},"deepseek-flash":{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:128e3,maxOutput:64e3},"kimi-k3":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072},"kimi-for-coding":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:262144,maxOutput:65536},"kimi-k2.7-code":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:262144,maxOutput:65536},"gpt-image-1":{imageOutput:!0,tools:!1}};function y(i){if(!i)return!1;const n=String(i).toLowerCase();return ee.test(n)?!1:te.test(n)}function H(i,n){return!i||!n?!1:new RegExp("^"+i.split("*").map(s=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*")+"$","i").test(n)}const ne=[{pattern:"*claude*opus-5.5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingCanDisable:!1,forcedToolChoice:!1}},{pattern:"*claude*opus-5-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingCanDisable:!1,forcedToolChoice:!1}},{pattern:"*claude*sonnet-5.5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingOffType:"between_tools",forcedToolChoice:!1}},{pattern:"*claude*sonnet-5-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingOffType:"between_tools",forcedToolChoice:!1}},{pattern:"*claude*haiku-5.5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*haiku-5-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4.8*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4-8*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4.7*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4-7*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4.6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4-6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-4.7*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-4-7*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-4.6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-4-6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*haiku-6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*haiku-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*haiku-4*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*3.7*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*claude*3-7*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*claude*3.5*sonnet*",caps:{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*3-5*sonnet*",caps:{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*3.5*haiku*",caps:{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*3-5*haiku*",caps:{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*3*opus*",caps:{vision:!0,contextWindow:2e5,maxOutput:4096}},{pattern:"*claude*3*sonnet*",caps:{vision:!0,contextWindow:2e5,maxOutput:4096}},{pattern:"*claude*3*haiku*",caps:{vision:!0,contextWindow:2e5,maxOutput:4096}},{pattern:"*claude-3*",caps:{vision:!0,contextWindow:2e5,maxOutput:4096}},{pattern:"*claude*haiku*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*opus*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*claude*sonnet*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*claude*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*gemini*image*",caps:{vision:!0,imageOutput:!0,contextWindow:1048576}},{pattern:"*gemini-4*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,search:!0,thinkingFormat:"gemini-level",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini-3.8*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,search:!0,thinkingFormat:"gemini-level",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini-3.7*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,search:!0,thinkingFormat:"gemini-level",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini-2.5*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,search:!0,thinkingFormat:"gemini-budget",thinkingRange:{min:0,max:24576},contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini-2*",caps:{vision:!0,audioInput:!0,videoInput:!0,search:!0,contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini*",caps:{vision:!0,search:!0,contextWindow:1048576}},{pattern:"*gemma*",caps:{vision:!0,contextWindow:128e3}},{pattern:"*gpt-6.1-terra*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:5e5,maxOutput:128e3}},{pattern:"*gpt-6.1-sol*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:272e3,maxOutput:128e3}},{pattern:"*gpt-6*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:105e4,maxOutput:128e3}},{pattern:"*gpt-5*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:4e5,maxOutput:128e3}},{pattern:"*gpt-4o*",caps:{vision:!0,search:!0,contextWindow:128e3,maxOutput:16384}},{pattern:"*gpt-4.1*",caps:{vision:!0,contextWindow:1e6,maxOutput:32768}},{pattern:"*gpt-4-turbo*",caps:{vision:!0,contextWindow:128e3}},{pattern:"*gpt-4*",caps:{contextWindow:128e3}},{pattern:"*gpt-3.5*",caps:{contextWindow:16385,maxOutput:4096}},{pattern:"*o1-mini*",caps:{reasoning:!0,thinkingFormat:"openai",contextWindow:128e3}},{pattern:"*o1*",caps:{vision:!0,reasoning:!0,thinkingFormat:"openai",contextWindow:2e5,maxOutput:1e5}},{pattern:"*o3*",caps:{vision:!0,reasoning:!0,thinkingFormat:"openai",contextWindow:2e5,maxOutput:1e5}},{pattern:"*o4*",caps:{vision:!0,reasoning:!0,thinkingFormat:"openai",contextWindow:2e5,maxOutput:1e5}},{pattern:"*grok*image*",caps:{imageOutput:!0}},{pattern:"*grok-code*",caps:{reasoning:!0,thinkingFormat:"openai",contextWindow:256e3}},{pattern:"*grok-4.7*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:5e5,maxOutput:5e5}},{pattern:"*grok-4.6*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:5e5,maxOutput:5e5}},{pattern:"*grok-4.5*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:5e5,maxOutput:64e3}},{pattern:"*grok-4*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:256e3}},{pattern:"*grok*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:128e3}},{pattern:"*deepseek*v4.1*flash*free*",caps:{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:33e4,maxOutput:128e3}},{pattern:"*deepseek-v4.*",caps:{vision:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingEffortSupported:!0,contextWindow:1e6,maxOutput:128e3}},{pattern:"*deepseek-v4*",caps:{reasoning:!0,thinkingFormat:"deepseek",thinkingEffortSupported:!0,contextWindow:1e6,maxOutput:384e3}},{pattern:"*reasoner*",caps:{vision:!1,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:128e3}},{pattern:"*deepseek-r*",caps:{vision:!1,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:128e3}},{pattern:"*deepseek-chat*",caps:{vision:!1,reasoning:!0,thinkingFormat:"deepseek",contextWindow:128e3}},{pattern:"*deepseek*",caps:{reasoning:!0,thinkingFormat:"deepseek",contextWindow:128e3}},{pattern:"*qwen*vl*",caps:{vision:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:262144}},{pattern:"*qwen*omni*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:262144,maxOutput:65536}},{pattern:"*qwen*coder*",caps:{reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6}},{pattern:"*qwen*max*",caps:{vision:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwen3.5*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwen3.6*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwen3.7*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwen*plus*",caps:{vision:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwq*",caps:{reasoning:!0,thinkingFormat:"qwen",thinkingCanDisable:!1,contextWindow:131072}},{pattern:"*qwen*",caps:{reasoning:!0,thinkingFormat:"qwen",contextWindow:262144}},{pattern:"*kimi*k3.1*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*kimi*k3*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*k3.1*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*k3*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*kimi*coding*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:262144,maxOutput:65536}},{pattern:"*kimi*k2*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:262144,maxOutput:65536}},{pattern:"*kimi*",caps:{vision:!0,reasoning:!0,thinkingFormat:"kimi",contextWindow:262144}},{pattern:"*mimo*v2.6*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*mimo*v2.5*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*mimo*omni*",caps:{vision:!0,audioInput:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:262144,maxOutput:131072}},{pattern:"*mimo*",caps:{vision:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:262144,maxOutput:131072}},{pattern:"*llama-4*",caps:{vision:!0,contextWindow:1e6}},{pattern:"*llama*",caps:{contextWindow:128e3}},{pattern:"*mistral-large*",caps:{vision:!0,contextWindow:256e3}},{pattern:"*codestral*",caps:{contextWindow:256e3}},{pattern:"*mistral*",caps:{contextWindow:128e3}}];function K(i){if(i){if(Array.isArray(i)){const n={};for(const u of i)typeof u=="string"&&(n[u]=!0);return n}return i}}function G(i,n){if(!n)return{...v};const u=n.includes("/")?n.split("/").pop():n,s=!i&&n.includes("/")?n.split("/")[0]:i;if(s){const t=X(s);if(t!=null&&t.models){const c=t.models.find(o=>o.id===n||o.id===u||o.upstreamModelId&&(o.upstreamModelId===n||o.upstreamModelId===u));if(c!=null&&c.capabilities){const o=K(c.capabilities);if(o){const m={...v,...o};return!m.vision&&y(n)&&(m.vision=!0),m}}}}else for(const t of Z()){if(!t.models)continue;const c=t.models.find(o=>o.id===n||o.id===u||o.upstreamModelId&&(o.upstreamModelId===n||o.upstreamModelId===u));if(c!=null&&c.capabilities){const o=K(c.capabilities);if(o){const m={...v,...o};return!m.vision&&y(n)&&(m.vision=!0),m}}}if(s&&V[s]){const t=V[s];if(t[n])return{...v,...t[n]};if(t[u])return{...v,...t[u]}}if(S[u]){const t={...v,...S[u]};return!t.vision&&y(n)&&(t.vision=!0),t}if(S[n]){const t={...v,...S[n]};return!t.vision&&y(n)&&(t.vision=!0),t}for(const{pattern:t,caps:c}of ne)if(H(t,u)||H(t,n)){const o={...v,...c};return!o.vision&&y(n)&&(o.vision=!0),o}const g={...v};return!g.vision&&y(n)&&(g.vision=!0),g}function ue(i,n,u=0){if(!i||i.length===0||u>6)return null;const s=i.map(t=>{!t.includes("/")&&(n!=null&&n[t]);const c=t.indexOf("/"),o=c===-1?null:t.slice(0,c),m=c===-1?t:t.slice(c+1);return G(o,m)}),g=s[0];return{vision:s.some(t=>t.vision),pdf:s.some(t=>t.pdf),audioInput:s.some(t=>t.audioInput),videoInput:s.some(t=>t.videoInput),imageOutput:s.some(t=>t.imageOutput),audioOutput:s.some(t=>t.audioOutput),search:s.some(t=>t.search),tools:s.every(t=>t.tools),reasoning:g.reasoning,thinkingFormat:g.thinkingFormat,thinkingCanDisable:g.thinkingCanDisable,thinkingRange:g.thinkingRange,thinkingEffortSupported:g.thinkingEffortSupported,contextWindow:Math.min(...s.map(t=>t.contextWindow)),maxOutput:Math.max(...s.map(t=>t.maxOutput))}}const $={vision:{key:"vision",label:"Vision",icon:"visibility",desc:"Supports image inputs (png, jpg, webp, base64)",colorClass:"text-cyan-400",bgClass:"bg-cyan-500/10",borderClass:"border-cyan-500/20"},pdf:{key:"pdf",label:"PDF",icon:"picture_as_pdf",desc:"Supports PDF and document parsing",colorClass:"text-orange-400",bgClass:"bg-orange-500/10",borderClass:"border-orange-500/20"},audio:{key:"audio",label:"Audio",icon:"graphic_eq",desc:"Supports raw voice and audio speech input",colorClass:"text-purple-400",bgClass:"bg-purple-500/10",borderClass:"border-purple-500/20"},thinking:{key:"thinking",label:"Thinking",icon:"psychology",desc:"Supports reasoning and thinking trace",colorClass:"text-emerald-400",bgClass:"bg-emerald-500/10",borderClass:"border-emerald-500/20"}};function ie(i){if(!i)return null;const n=i.indexOf("/"),u=n===-1?null:i.slice(0,n),s=n===-1?i:i.slice(n+1);return G(u,s)}const ae=({caps:i,model:n,className:u="",showLabels:s=!1,size:g="sm"})=>{const t=i||(n?ie(n):null);if(!t)return null;const c=!!t.vision,o=!!t.pdf,m=!!(t.audioInput||t.audio),N=!!(t.reasoning||t.thinking||t.thinkingFormat&&t.thinkingFormat!==null),h=[];if(c&&h.push($.vision),o&&h.push($.pdf),m&&h.push($.audio),N&&h.push($.thinking),h.length===0)return null;const w={xs:"text-[12px]",sm:"text-[14px]",md:"text-[16px]"},A={xs:"text-[9.5px]",sm:"text-[10.5px]",md:"text-xs"};return a.jsx("div",{className:`inline-flex items-center gap-1.5 flex-wrap ${u}`,children:h.map(d=>a.jsxs("span",{title:`${d.label}: ${d.desc}`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md border font-medium transition-all ${d.colorClass} ${d.bgClass} ${d.borderClass} ${A[g]}`,children:[a.jsx("span",{className:`material-symbols-outlined leading-none ${w[g]}`,children:d.icon}),s&&a.jsx("span",{children:d.label})]},d.key))})};let j=null,E=null;const B=new Set;function oe(i){return B.add(i),()=>{B.delete(i)}}function ce(){j=null,E=null;for(const i of B)try{i()}catch(n){console.error("Error in model cache invalidation listener:",n)}}function U(){return E?Promise.resolve(E):(j||(j=fetch("/api/models/available").then(i=>{if(!i.ok)throw new Error("Failed to load models");return i.json()}).then(i=>(E=i,i)).catch(i=>{throw j=null,i})),j)}const pe=({value:i,onChange:n,onEnter:u,placeholder:s="Search model (e.g. openai/gpt-4o)...",className:g="",autoFocus:t=!1,connectedOnly:c=!0,disabled:o=!1,excludeValues:m,allowCombos:N=!0,fetchCustomModels:h})=>{const[w,A]=x.useState([]),[d,f]=x.useState(!1),[b,k]=x.useState(-1),[W,T]=x.useState(c),[Y,R]=x.useState("bottom"),I=x.useRef(null),q=x.useRef(null);x.useEffect(()=>{if(d&&I.current){const e=I.current.getBoundingClientRect(),p=280,l=window.innerHeight-e.bottom,F=e.top;l<p&&F>l?R("top"):R("bottom")}},[d]),x.useEffect(()=>{let e=!0;const p=()=>{(h?h():U()).then(r=>{e&&A(r)}).catch(()=>{})};p();const l=oe(()=>{e&&p()});return()=>{e=!1,l()}},[h]),x.useEffect(()=>{T(c)},[c]),x.useEffect(()=>{const e=p=>{I.current&&!I.current.contains(p.target)&&f(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]);const L=x.useMemo(()=>w.some(e=>e.hasConnectedAccount),[w]),O=x.useMemo(()=>{const e=(i||"").trim().toLowerCase(),p=new Set((m||[]).map(r=>r.toLowerCase()));let l=w;if(N===!1&&(l=l.filter(r=>!r.isCombo)),p.size>0&&(l=l.filter(r=>!p.has(r.value.toLowerCase())&&!p.has(r.id.toLowerCase()))),W&&L&&(l=l.filter(r=>r.hasConnectedAccount)),!e)return l.slice(0,50);const F=l.filter(r=>!!(r.value.toLowerCase().includes(e)||r.id.toLowerCase().includes(e)||r.name.toLowerCase().includes(e)||r.providerName.toLowerCase().includes(e)||r.providerId.toLowerCase().includes(e)||r.isCombo&&(r.strategy&&r.strategy.toLowerCase().includes(e)||r.models&&r.models.some(M=>M.toLowerCase().includes(e)))));return F.sort((r,D)=>{const M=r.value.toLowerCase(),P=D.value.toLowerCase(),_=r.id.toLowerCase(),z=D.id.toLowerCase();return M===e||_===e?-1:P===e||z===e?1:M.startsWith(e)||_.startsWith(e)?-1:P.startsWith(e)||z.startsWith(e)?1:r.isCombo&&!D.isCombo?-1:!r.isCombo&&D.isCombo?1:0}),F.slice(0,50)},[w,i,W,L,m,N]);x.useEffect(()=>{if(b>=0&&q.current){const e=q.current.children[b];e&&e.scrollIntoView({block:"nearest"})}},[b]);const J=e=>{if(!o)if(e.key==="ArrowDown")e.preventDefault(),d?k(p=>p<O.length-1?p+1:0):f(!0);else if(e.key==="ArrowUp")e.preventDefault(),d?k(p=>p>0?p-1:O.length-1):f(!0);else if(e.key==="Enter")if(d&&b>=0&&O[b]){e.preventDefault();const p=O[b];n(p.value),f(!1),k(-1),u&&u()}else f(!1),u&&(e.preventDefault(),u());else e.key==="Escape"&&(e.preventDefault(),f(!1),k(-1))},Q=e=>{n(e),f(!1),k(-1)};return a.jsxs("div",{ref:I,className:"relative w-full",children:[a.jsx("input",{type:"text",value:i,onChange:e=>{n(e.target.value),d||f(!0),k(-1)},onFocus:()=>{(w.length===0||!E)&&U().then(e=>A(e)).catch(()=>{}),f(!0)},onKeyDown:J,placeholder:s,disabled:o,autoFocus:t,className:g||"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl pl-3 pr-8 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"}),i&&!o&&a.jsx("button",{type:"button",onClick:()=>{n(""),k(-1)},className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white transition-colors cursor-pointer flex items-center justify-center",title:"Clear input",children:a.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})}),d&&a.jsxs("div",{className:`absolute left-0 right-0 ${Y==="top"?"bottom-full mb-1.5":"top-full mt-1.5"} z-50 rounded-xl bg-[#0A0D14] border border-[#1E293B] shadow-2xl overflow-hidden animate-rt-scale-in min-w-[280px]`,children:[a.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#1E293B] bg-[#05070B] text-[11px]",children:[a.jsxs("span",{className:"text-slate-400 font-mono text-[10.5px]",children:[O.length," models ",i.trim()?"found":"available"]}),a.jsxs("button",{type:"button",onMouseDown:e=>{e.preventDefault(),T(!W)},className:`px-2 py-0.5 rounded-md font-sans text-[10.5px] font-medium flex items-center gap-1 transition-all cursor-pointer ${W?"bg-emerald-500/15 border border-emerald-500/30 text-emerald-400":"bg-slate-800 border border-slate-700 text-slate-400 hover:text-slate-200"}`,title:W?"Showing only models from connected accounts. Click to show all catalog models.":"Showing all catalog models. Click to filter by connected accounts.",children:[a.jsx("span",{className:"material-symbols-outlined text-[12px]",children:W?"check":"filter_alt"}),"Connected only"]})]}),a.jsx("div",{ref:q,className:"max-h-56 overflow-y-auto divide-y divide-[#1E293B]/40",children:O.length===0?a.jsxs("div",{className:"p-3 text-center text-xs text-slate-500 space-y-1",children:[a.jsx("p",{children:"No matching models in catalog."}),a.jsx("p",{className:"text-[10.5px] text-slate-400",children:"Custom IDs are supported. Press Enter or click outside to use your custom model ID."}),W&&!L&&a.jsx("button",{type:"button",onMouseDown:e=>{e.preventDefault(),T(!1)},className:"mt-1 text-[11px] text-blue-400 hover:underline",children:"View all registry models"})]}):O.map((e,p)=>{const l=p===b,F=e.value===i;return a.jsxs("div",{onMouseDown:r=>{r.preventDefault(),Q(e.value)},onMouseEnter:()=>k(p),className:`px-3 py-2 cursor-pointer transition-colors flex items-center justify-between gap-2.5 ${l?"bg-blue-600/20 text-white":F?"bg-[#141B2D] text-slate-100":"hover:bg-white/5 text-slate-300"}`,children:[a.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[a.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.isCombo?a.jsx("span",{className:"px-1.5 py-0.2 rounded bg-cyan-500/20 border border-cyan-500/40 font-mono text-[9.5px] text-cyan-300 font-semibold tracking-wide",children:"COMBO"}):a.jsx("span",{className:"px-1.5 py-0.2 rounded bg-slate-800/80 border border-slate-700/60 font-mono text-[9.5px] text-slate-300",children:e.providerName||e.providerId}),a.jsx("span",{className:"font-medium text-xs text-slate-100 truncate",children:e.name}),e.isCombo&&e.strategy&&a.jsx("span",{className:`px-1.5 py-0.2 rounded font-sans text-[9px] font-medium border ${e.strategy==="round-robin"?"bg-cyan-950/40 text-cyan-300 border-cyan-500/30":e.strategy==="fusion"?"bg-purple-950/40 text-purple-300 border-purple-500/30":"bg-amber-950/40 text-amber-300 border-amber-500/30"}`,children:e.strategy==="round-robin"?"Round Robin":e.strategy==="fusion"?"Fusion":"Fallback"}),e.hasConnectedAccount&&a.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400 shrink-0",title:`Connected account active (${e.accountsCount})`})]}),e.isCombo&&e.models&&e.models.length>0?a.jsxs("div",{className:"font-mono text-[10.5px] text-slate-400 truncate",children:[a.jsxs("span",{className:"text-cyan-400 font-semibold",children:[e.models.length," model",e.models.length>1?"s":"",":"]})," ",a.jsxs("span",{className:"text-slate-300",children:[e.models.slice(0,3).join(", "),e.models.length>3?` +${e.models.length-3} more`:""]})]}):a.jsx("div",{className:"font-mono text-[10.5px] text-slate-400 truncate",children:e.value})]}),a.jsx("div",{className:"shrink-0 flex items-center gap-1.5",children:a.jsx(ae,{caps:e.caps,size:"xs",showLabels:!1})})]},e.value)})})]})]})};export{ae as C,pe as M,ue as a,U as b,G as g,ce as i,oe as o};
1
+ import{j as o,r as x}from"./vendor-BcOI2aZ9.js";import{g as X,a as Z}from"./metadataRegistry-W75_wn57.js";const k={vision:!1,pdf:!1,audioInput:!1,videoInput:!1,imageOutput:!1,audioOutput:!1,search:!1,tools:!0,reasoning:!1,thinkingFormat:null,thinkingCanDisable:!0,thinkingRange:null,thinkingEffortSupported:!1,contextWindow:2e5,maxOutput:64e3},I="[-_/:.]",ee=new RegExp([`(^|${I})(image|img)(${I}|$)`,"stable-image","gen[0-9]_image","nanobanana","imagine","t2v","i2v","flux","dall","sdxl","diffusion","embed","rerank","guard","moderation","tts","stt","whisper","voice","speech","audio"].join("|"),"i"),te=new RegExp([`(^|${I})(vision|vl|vlm|multimodal|omni|visual)(${I}|$)`,`[0-9]\\.[0-9]+v(${I}|$)`,`(^|${I})glm-[0-9]+v(${I}|$)`,"(^|[-_/:.])(llava|pixtral|internvl|cogvlm|minicpm-v|moondream|idefics|fuyu)"].join("|"),"i"),V={nvidia:{"minimaxai/minimax-m2.7":{reasoning:!0,thinkingFormat:"openai",thinkingCanDisable:!1,contextWindow:2e5,maxOutput:131072},"minimaxai/minimax-m3":{vision:!0,reasoning:!0,thinkingFormat:"openai",thinkingCanDisable:!1,contextWindow:512e3,maxOutput:131072},"deepseek-ai/deepseek-v4-pro":{reasoning:!0,thinkingFormat:"openai",contextWindow:1e6,maxOutput:65536}},"opencode-go":{"glm-5.3-flash":{vision:!0,videoInput:!0,pdf:!0,reasoning:!0,thinkingFormat:"openai",thinkingCanDisable:!1,contextWindow:1e6,maxOutput:131072}}},A={"claude-fable-5-1":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",thinkingCanDisable:!1,contextWindow:1e6,maxOutput:128e3},"claude-opus-5.5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingCanDisable:!1,forcedToolChoice:!1},"claude-opus-5-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingCanDisable:!1,forcedToolChoice:!1},"claude-opus-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-sonnet-5.5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingOffType:"between_tools",forcedToolChoice:!1},"claude-sonnet-5-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingOffType:"between_tools",forcedToolChoice:!1},"claude-haiku-5.5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-haiku-5-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-sonnet-5":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-opus-4.8":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-opus-4-8":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-opus-4.6":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-opus-4-6":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-sonnet-4.6":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-sonnet-4-6":{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3},"claude-3-7-sonnet":{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3},"claude-3.7-sonnet":{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3},"claude-3-5-sonnet":{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192},"claude-3.5-sonnet":{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192},"claude-3-5-haiku":{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192},"claude-3.5-haiku":{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192},"claude-3-opus":{vision:!0,contextWindow:2e5,maxOutput:4096},"claude-3-haiku":{vision:!0,contextWindow:2e5,maxOutput:4096},"glm-5.3-flash":{vision:!0,videoInput:!0,pdf:!0,reasoning:!0,thinkingFormat:"zai",thinkingCanDisable:!1,contextWindow:1e6,maxOutput:131072},"glm-4.6v":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"zai",contextWindow:128e3,maxOutput:32768},"glm-4.5v":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"zai",contextWindow:64e3,maxOutput:16384},"glm-5.2":{reasoning:!0,thinkingFormat:"zai",thinkingCanDisable:!1,contextWindow:1e6,maxOutput:131072},"deepseek-chat":{vision:!1,reasoning:!0,thinkingFormat:"deepseek",contextWindow:128e3,maxOutput:64e3},"deepseek-reasoner":{vision:!1,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:128e3,maxOutput:64e3},"deepseek-r1":{vision:!1,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:128e3,maxOutput:64e3},"deepseek-v4.1-flash":{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:1e6,maxOutput:384e3},"deepseek-v4-1-flash":{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:1e6,maxOutput:384e3},"deepseek-v4-flash-vision-exp":{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:1e6,maxOutput:384e3},"deepseek-flash":{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:128e3,maxOutput:64e3},"kimi-k3":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072},"kimi-for-coding":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:262144,maxOutput:65536},"kimi-k2.7-code":{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:262144,maxOutput:65536},"gpt-image-1":{imageOutput:!0,tools:!1}};function D(n){if(!n)return!1;const t=String(n).toLowerCase();return ee.test(t)?!1:te.test(t)}function H(n,t){return!n||!t?!1:new RegExp("^"+n.split("*").map(c=>c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*")+"$","i").test(t)}const ne=[{pattern:"*claude*opus-5.5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingCanDisable:!1,forcedToolChoice:!1}},{pattern:"*claude*opus-5-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingCanDisable:!1,forcedToolChoice:!1}},{pattern:"*claude*sonnet-5.5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingOffType:"between_tools",forcedToolChoice:!1}},{pattern:"*claude*sonnet-5-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3,thinkingOffType:"between_tools",forcedToolChoice:!1}},{pattern:"*claude*haiku-5.5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*haiku-5-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4.8*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4-8*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4.7*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4-7*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4.6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*opus-4-6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-4.7*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-4-7*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-4.6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*sonnet-4-6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*haiku-6*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*haiku-5*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*haiku-4*",caps:{vision:!0,pdf:!0,reasoning:!0,search:!0,thinkingFormat:"claude-adaptive",contextWindow:1e6,maxOutput:128e3}},{pattern:"*claude*3.7*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*claude*3-7*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*claude*3.5*sonnet*",caps:{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*3-5*sonnet*",caps:{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*3.5*haiku*",caps:{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*3-5*haiku*",caps:{vision:!0,search:!0,contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*3*opus*",caps:{vision:!0,contextWindow:2e5,maxOutput:4096}},{pattern:"*claude*3*sonnet*",caps:{vision:!0,contextWindow:2e5,maxOutput:4096}},{pattern:"*claude*3*haiku*",caps:{vision:!0,contextWindow:2e5,maxOutput:4096}},{pattern:"*claude-3*",caps:{vision:!0,contextWindow:2e5,maxOutput:4096}},{pattern:"*claude*haiku*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:8192}},{pattern:"*claude*opus*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*claude*sonnet*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*claude*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"claude-budget",contextWindow:2e5,maxOutput:64e3}},{pattern:"*gemini*image*",caps:{vision:!0,imageOutput:!0,contextWindow:1048576}},{pattern:"*gemini-4*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,search:!0,thinkingFormat:"gemini-level",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini-3.8*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,search:!0,thinkingFormat:"gemini-level",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini-3.7*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,search:!0,thinkingFormat:"gemini-level",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini-2.5*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,search:!0,thinkingFormat:"gemini-budget",thinkingRange:{min:0,max:24576},contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini-2*",caps:{vision:!0,audioInput:!0,videoInput:!0,search:!0,contextWindow:1048576,maxOutput:65536}},{pattern:"*gemini*",caps:{vision:!0,search:!0,contextWindow:1048576}},{pattern:"*gemma*",caps:{vision:!0,contextWindow:128e3}},{pattern:"*gpt-6.1-terra*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:5e5,maxOutput:128e3}},{pattern:"*gpt-6.1-sol*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:272e3,maxOutput:128e3}},{pattern:"*gpt-6*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:105e4,maxOutput:128e3}},{pattern:"*gpt-5*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:4e5,maxOutput:128e3}},{pattern:"*gpt-4o*",caps:{vision:!0,search:!0,contextWindow:128e3,maxOutput:16384}},{pattern:"*gpt-4.1*",caps:{vision:!0,contextWindow:1e6,maxOutput:32768}},{pattern:"*gpt-4-turbo*",caps:{vision:!0,contextWindow:128e3}},{pattern:"*gpt-4*",caps:{contextWindow:128e3}},{pattern:"*gpt-3.5*",caps:{contextWindow:16385,maxOutput:4096}},{pattern:"*o1-mini*",caps:{reasoning:!0,thinkingFormat:"openai",contextWindow:128e3}},{pattern:"*o1*",caps:{vision:!0,reasoning:!0,thinkingFormat:"openai",contextWindow:2e5,maxOutput:1e5}},{pattern:"*o3*",caps:{vision:!0,reasoning:!0,thinkingFormat:"openai",contextWindow:2e5,maxOutput:1e5}},{pattern:"*o4*",caps:{vision:!0,reasoning:!0,thinkingFormat:"openai",contextWindow:2e5,maxOutput:1e5}},{pattern:"*grok*image*",caps:{imageOutput:!0}},{pattern:"*grok-code*",caps:{reasoning:!0,thinkingFormat:"openai",contextWindow:256e3}},{pattern:"*grok-4.7*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:5e5,maxOutput:5e5}},{pattern:"*grok-4.6*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:5e5,maxOutput:5e5}},{pattern:"*grok-4.5*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:5e5,maxOutput:64e3}},{pattern:"*grok-4*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:256e3}},{pattern:"*grok*",caps:{vision:!0,reasoning:!0,search:!0,thinkingFormat:"openai",contextWindow:128e3}},{pattern:"*deepseek*v4.1*flash*free*",caps:{vision:!0,reasoning:!0,thinkingFormat:"deepseek",contextWindow:33e4,maxOutput:128e3}},{pattern:"*deepseek-v4.*",caps:{vision:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingEffortSupported:!0,contextWindow:1e6,maxOutput:128e3}},{pattern:"*deepseek-v4*",caps:{reasoning:!0,thinkingFormat:"deepseek",thinkingEffortSupported:!0,contextWindow:1e6,maxOutput:384e3}},{pattern:"*reasoner*",caps:{vision:!1,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:128e3}},{pattern:"*deepseek-r*",caps:{vision:!1,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:128e3}},{pattern:"*deepseek-chat*",caps:{vision:!1,reasoning:!0,thinkingFormat:"deepseek",contextWindow:128e3}},{pattern:"*deepseek*",caps:{reasoning:!0,thinkingFormat:"deepseek",contextWindow:128e3}},{pattern:"*qwen*vl*",caps:{vision:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:262144}},{pattern:"*qwen*omni*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:262144,maxOutput:65536}},{pattern:"*qwen*coder*",caps:{reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6}},{pattern:"*qwen*max*",caps:{vision:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwen3.5*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwen3.6*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwen3.7*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwen*plus*",caps:{vision:!0,reasoning:!0,thinkingFormat:"qwen",contextWindow:1e6,maxOutput:65536}},{pattern:"*qwq*",caps:{reasoning:!0,thinkingFormat:"qwen",thinkingCanDisable:!1,contextWindow:131072}},{pattern:"*qwen*",caps:{reasoning:!0,thinkingFormat:"qwen",contextWindow:262144}},{pattern:"*kimi*k3.1*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*kimi*k3*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*k3.1*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*k3*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*kimi*coding*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:262144,maxOutput:65536}},{pattern:"*kimi*k2*",caps:{vision:!0,videoInput:!0,reasoning:!0,thinkingFormat:"kimi",thinkingCanDisable:!1,contextWindow:262144,maxOutput:65536}},{pattern:"*kimi*",caps:{vision:!0,reasoning:!0,thinkingFormat:"kimi",contextWindow:262144}},{pattern:"*mimo*v2.6*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*mimo*v2.5*",caps:{vision:!0,audioInput:!0,videoInput:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:1048576,maxOutput:131072}},{pattern:"*mimo*omni*",caps:{vision:!0,audioInput:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:262144,maxOutput:131072}},{pattern:"*mimo*",caps:{vision:!0,reasoning:!0,thinkingFormat:"deepseek",thinkingCanDisable:!1,contextWindow:262144,maxOutput:131072}},{pattern:"*llama-4*",caps:{vision:!0,contextWindow:1e6}},{pattern:"*llama*",caps:{contextWindow:128e3}},{pattern:"*mistral-large*",caps:{vision:!0,contextWindow:256e3}},{pattern:"*codestral*",caps:{contextWindow:256e3}},{pattern:"*mistral*",caps:{contextWindow:128e3}}];function K(n){if(n){if(Array.isArray(n)){const t={};for(const u of n)typeof u=="string"&&(t[u]=!0);return t}return n}}function G(n,t){if(!t)return{...k};const u=t.includes("/")?t.split("/").pop():t,c=!n&&t.includes("/")?t.split("/")[0]:n,d=c?c.replace(/\[.*?\]$/,""):null;if(d){const a=X(d);if(a!=null&&a.models){const l=a.models.find(s=>s.id===t||s.id===u||s.upstreamModelId&&(s.upstreamModelId===t||s.upstreamModelId===u));if(l!=null&&l.capabilities){const s=K(l.capabilities);if(s){const h={...k,...s};return!h.vision&&D(t)&&(h.vision=!0),h}}}}else for(const a of Z()){if(!a.models)continue;const l=a.models.find(s=>s.id===t||s.id===u||s.upstreamModelId&&(s.upstreamModelId===t||s.upstreamModelId===u));if(l!=null&&l.capabilities){const s=K(l.capabilities);if(s){const h={...k,...s};return!h.vision&&D(t)&&(h.vision=!0),h}}}if(d&&V[d]){const a=V[d];if(a[t])return{...k,...a[t]};if(a[u])return{...k,...a[u]}}if(A[u]){const a={...k,...A[u]};return!a.vision&&D(t)&&(a.vision=!0),a}if(A[t]){const a={...k,...A[t]};return!a.vision&&D(t)&&(a.vision=!0),a}for(const{pattern:a,caps:l}of ne)if(H(a,u)||H(a,t)){const s={...k,...l};return!s.vision&&D(t)&&(s.vision=!0),s}const i={...k};return!i.vision&&D(t)&&(i.vision=!0),i}function ce(n,t,u=0){if(!n||n.length===0||u>6)return null;const c=n.map(i=>{!i.includes("/")&&(t!=null&&t[i]);const a=i.indexOf("/"),l=a===-1?null:i.slice(0,a),s=a===-1?i:i.slice(a+1);return G(l,s)}),d=c[0];return{vision:c.some(i=>i.vision),pdf:c.some(i=>i.pdf),audioInput:c.some(i=>i.audioInput),videoInput:c.some(i=>i.videoInput),imageOutput:c.some(i=>i.imageOutput),audioOutput:c.some(i=>i.audioOutput),search:c.some(i=>i.search),tools:c.every(i=>i.tools),reasoning:d.reasoning,thinkingFormat:d.thinkingFormat,thinkingCanDisable:d.thinkingCanDisable,thinkingRange:d.thinkingRange,thinkingEffortSupported:d.thinkingEffortSupported,contextWindow:Math.min(...c.map(i=>i.contextWindow)),maxOutput:Math.max(...c.map(i=>i.maxOutput))}}const M={vision:{key:"vision",label:"Vision",icon:"visibility",desc:"Supports image inputs (png, jpg, webp, base64)",colorClass:"text-cyan-400",bgClass:"bg-cyan-500/10",borderClass:"border-cyan-500/20"},pdf:{key:"pdf",label:"PDF",icon:"picture_as_pdf",desc:"Supports PDF and document parsing",colorClass:"text-orange-400",bgClass:"bg-orange-500/10",borderClass:"border-orange-500/20"},audio:{key:"audio",label:"Audio",icon:"graphic_eq",desc:"Supports raw voice and audio speech input",colorClass:"text-purple-400",bgClass:"bg-purple-500/10",borderClass:"border-purple-500/20"},thinking:{key:"thinking",label:"Thinking",icon:"psychology",desc:"Supports reasoning and thinking trace",colorClass:"text-emerald-400",bgClass:"bg-emerald-500/10",borderClass:"border-emerald-500/20"}};function ie(n){if(!n)return null;const t=n.indexOf("/"),u=t===-1?null:n.slice(0,t),c=t===-1?n:n.slice(t+1);return G(u,c)}const ae=({caps:n,model:t,className:u="",showLabels:c=!1,size:d="sm"})=>{const i=n||(t?ie(t):null);if(!i)return null;const a=!!i.vision,l=!!i.pdf,s=!!(i.audioInput||i.audio),h=!!(i.reasoning||i.thinking||i.thinkingFormat&&i.thinkingFormat!==null),f=[];if(a&&f.push(M.vision),l&&f.push(M.pdf),s&&f.push(M.audio),h&&f.push(M.thinking),f.length===0)return null;const W={xs:"text-[12px]",sm:"text-[14px]",md:"text-[16px]"},$={xs:"text-[9.5px]",sm:"text-[10.5px]",md:"text-xs"};return o.jsx("div",{className:`inline-flex items-center gap-1.5 flex-wrap ${u}`,children:f.map(g=>o.jsxs("span",{title:`${g.label}: ${g.desc}`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md border font-medium transition-all ${g.colorClass} ${g.bgClass} ${g.borderClass} ${$[d]}`,children:[o.jsx("span",{className:`material-symbols-outlined leading-none ${W[d]}`,children:g.icon}),c&&o.jsx("span",{children:g.label})]},g.key))})};function oe(n,t){if(!t.trim())return!0;const u=t.toLowerCase().trim(),c=n.toLowerCase();if(c.includes(u))return!0;const d=u.split(/\s+/).filter(Boolean);if(d.length===0)return!0;const i=c.replace(/[-_./]/g," ");return d.every(a=>c.includes(a)||i.includes(a))}let E=null,N=null;const B=new Set;function re(n){return B.add(n),()=>{B.delete(n)}}function pe(){E=null,N=null;for(const n of B)try{n()}catch(t){console.error("Error in model cache invalidation listener:",t)}}function U(){return N?Promise.resolve(N):(E||(E=fetch("/api/models/available").then(n=>{if(!n.ok)throw new Error("Failed to load models");return n.json()}).then(n=>(N=n,n)).catch(n=>{throw E=null,n})),E)}const de=({value:n,onChange:t,onEnter:u,placeholder:c="Search model (e.g. openai/gpt-4o)...",className:d="",autoFocus:i=!1,connectedOnly:a=!0,disabled:l=!1,excludeValues:s,allowCombos:h=!0,fetchCustomModels:f})=>{const[W,$]=x.useState([]),[g,v]=x.useState(!1),[O,w]=x.useState(-1),[F,S]=x.useState(a),[Q,P]=x.useState("bottom"),j=x.useRef(null),T=x.useRef(null);x.useEffect(()=>{if(g&&j.current){const e=j.current.getBoundingClientRect(),p=280,m=window.innerHeight-e.bottom,y=e.top;m<p&&y>m?P("top"):P("bottom")}},[g]),x.useEffect(()=>{let e=!0;const p=()=>{(f?f():U()).then(r=>{e&&$(r)}).catch(()=>{})};p();const m=re(()=>{e&&p()});return()=>{e=!1,m()}},[f]),x.useEffect(()=>{S(a)},[a]),x.useEffect(()=>{const e=p=>{j.current&&!j.current.contains(p.target)&&v(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]);const q=x.useMemo(()=>W.some(e=>e.hasConnectedAccount),[W]),C=x.useMemo(()=>{const e=(n||"").trim().toLowerCase(),p=new Set((s||[]).map(r=>r.toLowerCase()));let m=W;if(h===!1&&(m=m.filter(r=>!r.isCombo)),p.size>0&&(m=m.filter(r=>!p.has(r.value.toLowerCase())&&!(r.isCombo&&p.has(r.id.toLowerCase())))),F&&q&&(m=m.filter(r=>r.hasConnectedAccount)),!e)return m.slice(0,50);const y=m.filter(r=>{let b=`${r.name} ${r.id} ${r.value} ${r.providerName} ${r.providerId}`;return r.isCombo&&(r.strategy&&(b+=` ${r.strategy}`),r.models&&(b+=` ${r.models.join(" ")}`)),oe(b,e)});return y.sort((r,b)=>{const R=r.value.toLowerCase(),_=b.value.toLowerCase(),L=r.id.toLowerCase(),z=b.id.toLowerCase();return R===e||L===e?-1:_===e||z===e?1:R.startsWith(e)||L.startsWith(e)?-1:_.startsWith(e)||z.startsWith(e)?1:r.isCombo&&!b.isCombo?-1:!r.isCombo&&b.isCombo?1:0}),y.slice(0,50)},[W,n,F,q,s,h]);x.useEffect(()=>{if(O>=0&&T.current){const e=T.current.children[O];e&&e.scrollIntoView({block:"nearest"})}},[O]);const Y=e=>{if(!l)if(e.key==="ArrowDown")e.preventDefault(),g?w(p=>p<C.length-1?p+1:0):v(!0);else if(e.key==="ArrowUp")e.preventDefault(),g?w(p=>p>0?p-1:C.length-1):v(!0);else if(e.key==="Enter")if(g&&O>=0&&C[O]){e.preventDefault();const p=C[O];t(p.value),v(!1),w(-1),u&&u(p.value)}else v(!1),u&&(e.preventDefault(),u(n));else e.key==="Escape"&&(e.preventDefault(),v(!1),w(-1))},J=e=>{t(e),v(!1),w(-1)};return o.jsxs("div",{ref:j,className:"relative w-full",children:[o.jsx("input",{type:"text",value:n,onChange:e=>{t(e.target.value),g||v(!0),w(-1)},onFocus:()=>{(W.length===0||!N)&&U().then(e=>$(e)).catch(()=>{}),v(!0)},onKeyDown:Y,placeholder:c,disabled:l,autoFocus:i,className:d||"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl pl-3 pr-8 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"}),n&&!l&&o.jsx("button",{type:"button",onClick:()=>{t(""),w(-1)},className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white transition-colors cursor-pointer flex items-center justify-center",title:"Clear input",children:o.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})}),g&&o.jsxs("div",{className:`absolute left-0 right-0 ${Q==="top"?"bottom-full mb-1.5":"top-full mt-1.5"} z-50 rounded-xl bg-[#0A0D14] border border-[#1E293B] shadow-2xl overflow-hidden animate-rt-scale-in min-w-[280px]`,children:[o.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#1E293B] bg-[#05070B] text-[11px]",children:[o.jsxs("span",{className:"text-slate-400 font-mono text-[10.5px]",children:[C.length," models ",n.trim()?"found":"available"]}),o.jsxs("button",{type:"button",onMouseDown:e=>{e.preventDefault(),S(!F)},className:`px-2 py-0.5 rounded-md font-sans text-[10.5px] font-medium flex items-center gap-1 transition-all cursor-pointer ${F?"bg-emerald-500/15 border border-emerald-500/30 text-emerald-400":"bg-slate-800 border border-slate-700 text-slate-400 hover:text-slate-200"}`,title:F?"Showing only models from connected accounts. Click to show all catalog models.":"Showing all catalog models. Click to filter by connected accounts.",children:[o.jsx("span",{className:"material-symbols-outlined text-[12px]",children:F?"check":"filter_alt"}),"Connected only"]})]}),o.jsx("div",{ref:T,className:"max-h-56 overflow-y-auto divide-y divide-[#1E293B]/40",children:C.length===0?o.jsxs("div",{className:"p-3 text-center text-xs text-slate-500 space-y-1",children:[o.jsx("p",{children:"No matching models in catalog."}),o.jsx("p",{className:"text-[10.5px] text-slate-400",children:"Custom IDs are supported. Press Enter or click outside to use your custom model ID."}),F&&!q&&o.jsx("button",{type:"button",onMouseDown:e=>{e.preventDefault(),S(!1)},className:"mt-1 text-[11px] text-blue-400 hover:underline",children:"View all registry models"})]}):C.map((e,p)=>{const m=p===O,y=e.value===n;return o.jsxs("div",{onMouseDown:r=>{r.preventDefault(),J(e.value)},onMouseEnter:()=>w(p),className:`px-3 py-2 cursor-pointer transition-colors flex items-center justify-between gap-2.5 ${m?"bg-blue-600/20 text-white":y?"bg-[#141B2D] text-slate-100":"hover:bg-white/5 text-slate-300"}`,children:[o.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[o.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.isCombo?o.jsx("span",{className:"px-1.5 py-0.2 rounded bg-cyan-500/20 border border-cyan-500/40 font-mono text-[9.5px] text-cyan-300 font-semibold tracking-wide",children:"COMBO"}):o.jsx("span",{className:"px-1.5 py-0.2 rounded bg-slate-800/80 border border-slate-700/60 font-mono text-[9.5px] text-slate-300",children:e.providerName||e.providerId}),o.jsx("span",{className:"font-medium text-xs text-slate-100 truncate",children:e.name}),e.isCombo&&e.strategy&&o.jsx("span",{className:`px-1.5 py-0.2 rounded font-sans text-[9px] font-medium border ${e.strategy==="round-robin"?"bg-cyan-950/40 text-cyan-300 border-cyan-500/30":e.strategy==="fusion"?"bg-purple-950/40 text-purple-300 border-purple-500/30":"bg-amber-950/40 text-amber-300 border-amber-500/30"}`,children:e.strategy==="round-robin"?"Round Robin":e.strategy==="fusion"?"Fusion":"Fallback"}),e.hasConnectedAccount&&o.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400 shrink-0",title:`Connected account active (${e.accountsCount})`})]}),e.isCombo&&e.models&&e.models.length>0?o.jsxs("div",{className:"font-mono text-[10.5px] text-slate-400 truncate",children:[o.jsxs("span",{className:"text-cyan-400 font-semibold",children:[e.models.length," model",e.models.length>1?"s":"",":"]})," ",o.jsxs("span",{className:"text-slate-300",children:[e.models.slice(0,3).join(", "),e.models.length>3?` +${e.models.length-3} more`:""]})]}):o.jsx("div",{className:"font-mono text-[10.5px] text-slate-400 truncate",children:e.value})]}),o.jsx("div",{className:"shrink-0 flex items-center gap-1.5",children:o.jsx(ae,{caps:e.caps,size:"xs",showLabels:!1})})]},e.value)})})]})]})};export{ae as C,de as M,ce as a,U as b,G as g,pe as i,oe as m,re as o};
@@ -1,4 +1,4 @@
1
- import{r as s,j as e}from"./vendor-BcOI2aZ9.js";import{i as lt}from"./providersData-DS1-ETBi.js";import{g as ot}from"./metadataRegistry-NuDSSkP9.js";import{u as yt,D as vt,P as _e}from"./index-CKuvklEr.js";import{S as ze}from"./Select-BNRH8LIG.js";import{T as Fe}from"./ToolIcon-Cp4gSgFt.js";import{i as Ce}from"./ModelAutocompleteInput-CoinzdsW.js";import{C as nt,E as Nt}from"./EditAccountModal-CAg-yIOn.js";import{C as wt}from"./ConfirmModal-OWeauwYv.js";import"./lucide-Cc35htxl.js";const kt=({isOpen:l,providerId:n,providerName:t,onSuccess:h,onClose:g})=>{const f=s.useRef(h);f.current=h;const c=s.useRef(g);c.current=g;const K=yt(C=>C.info),b=(K==null?void 0:K.port)||vt,I=s.useRef(b);I.current=b;const y=ot(n),k=(y==null?void 0:y.regions)||[],[N,U]=s.useState((y==null?void 0:y.defaultRegion)||(k.length>0?k[0].id:"")),S=s.useRef(N);S.current=N;const[A,H]=s.useState(""),[z,W]=s.useState(`http://localhost:${b}/callback`),[E,M]=s.useState(""),[B,D]=s.useState("loading"),[ee,Y]=s.useState(null),[te,j]=s.useState(!1),[P,Q]=s.useState(!1),[J,L]=s.useState(!1),[ne,ue]=s.useState(!1),[G,oe]=s.useState(null),ge=s.useRef(null),me=s.useRef(!1),be=s.useRef(void 0),V=s.useRef(void 0),X=s.useRef(0),F=s.useRef(null),_=s.useCallback(()=>{F.current&&(clearTimeout(F.current),clearInterval(F.current),F.current=null)},[]),r=s.useCallback(async C=>{if(!me.current){me.current=!0,_(),D("processing"),Y(null);try{const re=await fetch(`/api/oauth/${n}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:C,redirectUri:z,codeVerifier:be.current,state:V.current,region:S.current||void 0})}),$=await re.json().catch(()=>({}));if(!re.ok||$.error)throw new Error($.error||"Token exchange failed");D("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),c.current()},1200)}catch(re){me.current=!1,D("error"),Y(re.message||"Failed to exchange authorization token")}}},[n,z,_]),d=s.useCallback(async C=>{const re=++X.current,$=()=>re!==X.current;me.current=!1,_(),D("loading"),Y(null),M(""),ue(!1),oe(null),L(!1),be.current=void 0,V.current=void 0;const xe=C!==void 0?C:S.current,u=xe?`&region=${encodeURIComponent(xe)}`:"",x=xe?`?region=${encodeURIComponent(xe)}`:"",v=window.location.port==="5173"?`http://localhost:${I.current}/callback`:`${window.location.origin}/callback`;W(v);try{const he=await fetch(`/api/oauth/${n}/authorize?redirect_uri=${encodeURIComponent(v)}${u}`),O=await he.json().catch(()=>({}));if($())return;if(!he.ok||O.error)throw new Error(O.error||`Authorization error (HTTP ${he.status})`);if(O.flowType==="device_code"||!O.authUrl&&O.flowType){ue(!0),D("waiting");const Z=await fetch(`/api/oauth/${n}/device-code${x}`),q=await Z.json().catch(()=>({}));if($())return;if(!Z.ok||!q.device_code)throw new Error(q.error||"Failed to initiate device code flow");oe(q);const Ae=q.verification_uri_complete||q.verification_uri;if(Ae)try{window.open(Ae,"_blank","noopener,noreferrer")}catch{}let fe=Number(q.interval)||5,ie=!0;const Se=we=>{$()||(F.current&&clearTimeout(F.current),F.current=setTimeout(async()=>{if(!(!ie||$()))try{const ce=await(await fetch(`/api/oauth/${n}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:q.device_code,codeVerifier:q.codeVerifier,region:xe||void 0,extraData:{...q||{},_zcodePollToken:q._zcodePollToken,_minimaxPollByUser:q._minimaxPollByUser,codeVerifier:q.codeVerifier,user_code:q.user_code,region:xe||void 0}})})).json();if($())return;if(ce.ok&&ce.success){ie=!1,_(),D("success"),setTimeout(()=>{f.current(),c.current()},1200);return}if(ce.error==="slow_down"){fe=Math.min(fe+5,30),Se(fe);return}if(ce.error==="authorization_pending"){Se(fe);return}if(ce.error){ie=!1,_(),D("error"),Y(ce.error_description||ce.error);return}Se(fe)}catch{ie&&Se(fe)}},we*1e3))};Se(fe);return}if(O.authUrl){H(O.authUrl),O.redirectUri&&W(O.redirectUri),O.codeVerifier&&(be.current=O.codeVerifier),O.state&&(V.current=O.state),D("waiting");try{localStorage.setItem("oauth_pending_flow",JSON.stringify({providerId:n,redirectUri:O.redirectUri||v,state:O.state,codeVerifier:O.codeVerifier,timestamp:Date.now()}))}catch{}try{const Z=window.open(O.authUrl,"oauth_popup","width=600,height=700");Z&&!Z.closed?ge.current=Z:L(!0)}catch{L(!0)}return}throw new Error("No authorization URL returned from provider")}catch(he){if($())return;if(n==="antigravity"&&DEFAULT_ANTIGRAVITY_AUTH_URL){H(DEFAULT_ANTIGRAVITY_AUTH_URL),D("waiting");try{const O=window.open(DEFAULT_ANTIGRAVITY_AUTH_URL,"oauth_popup","width=600,height=700");O?ge.current=O:L(!0)}catch{L(!0)}}else D("error"),Y(he.message||"Failed to initialize authorization endpoint")}},[n,_]);if(s.useEffect(()=>{if(!l){_(),D("loading"),Y(null),ue(!1),oe(null);return}return d(),()=>{X.current++,_()}},[l,n,d,_]),s.useEffect(()=>{if(!l)return;const C=x=>{if(!x)return;if(x.done){me.current=!0,_(),D("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),c.current()},1200);return}if(x.error){D("error"),Y(x.errorDescription||x.error);return}const v=x.code||x.token||(x.userId&&x.token?x.fullUrl||`${window.location.origin}/?user_id=${x.userId}&access_token=${x.token}`:null);v&&r(v)},re=x=>{var v;((v=x.data)==null?void 0:v.type)==="oauth_callback"&&C(x.data.data)};window.addEventListener("message",re);let $=null;try{$=new BroadcastChannel("oauth_callback"),$.onmessage=x=>C(x.data)}catch{}const xe=x=>{if(x.key==="oauth_callback"&&x.newValue)try{const v=JSON.parse(x.newValue);C(v),localStorage.removeItem("oauth_callback")}catch{}};window.addEventListener("storage",xe);const u=setInterval(()=>{try{const x=localStorage.getItem("oauth_callback");if(x){const v=JSON.parse(x);v&&(!v.timestamp||Date.now()-v.timestamp<6e4)&&C(v),localStorage.removeItem("oauth_callback")}}catch{}},500);return()=>{clearInterval(u),window.removeEventListener("message",re),window.removeEventListener("storage",xe),$&&$.close()}},[l,r]),!l)return null;const w=()=>{A&&(navigator.clipboard.writeText(A),j(!0),setTimeout(()=>j(!1),2e3))},pe=C=>{C&&(navigator.clipboard.writeText(C),Q(!0),setTimeout(()=>Q(!1),2e3))},se=()=>{if(A){L(!1);try{const C=window.open(A,"oauth_popup","width=600,height=700");C&&(ge.current=C)}catch{}}},ye=()=>{E.trim()&&r(E.trim())};return e.jsx(_e,{isOpen:l,onClose:g,maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-blue-400",children:"lock"}),e.jsxs("h3",{className:"text-base font-bold text-white tracking-tight",children:["Connect ",t]})]}),e.jsx("button",{type:"button",onClick:g,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/5 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),k.length>0&&e.jsxs("div",{className:"space-y-1.5 p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"block text-xs font-medium text-slate-300",children:"Server / Region:"}),e.jsx("span",{className:"text-[10px] text-slate-500 font-mono",children:N})]}),e.jsx(ze,{value:N,onChange:C=>{U(C),S.current=C,d(C)},options:k.map(C=>({value:C.id,label:C.label}))})]}),B==="loading"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-blue-500/20 rounded-xl bg-blue-500/10 text-xs text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 animate-spin",children:"progress_activity"}),e.jsxs("span",{children:["Initializing authorization for ",t,"..."]})]}),B==="waiting"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-blue-500/20 rounded-xl bg-blue-500/10 text-xs text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{children:ne?"Waiting for device authorization in browser...":J?"Authorization link ready. Click button below to open login window.":"Popup window opened. Complete authorization in browser..."})]}),B==="processing"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-blue-500/20 rounded-xl bg-blue-500/10 text-xs text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 animate-spin",children:"sync"}),e.jsx("span",{children:"Exchanging authorization code and saving credentials..."})]}),B==="success"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-emerald-500/30 rounded-xl bg-emerald-500/10 text-xs text-emerald-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-emerald-400 font-bold",children:"check_circle"}),e.jsx("span",{children:"Connected successfully! Refreshing connections..."})]}),B==="error"&&ee&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 px-3.5 py-2.5 border border-red-500/30 rounded-xl bg-red-500/10 text-xs text-red-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-400 mt-0.5 shrink-0",children:"error"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"Connection Failed"}),e.jsx("p",{className:"text-red-200",children:ee})]})]}),e.jsxs("button",{type:"button",onClick:()=>d(),className:"w-full flex items-center justify-center gap-1.5 py-2 px-3 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-semibold text-slate-200 border border-[#1E293B] cursor-pointer transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"refresh"}),"Retry Authorization"]})]}),ne&&G?e.jsxs("div",{className:"space-y-4 pt-1",children:[e.jsxs("div",{className:"p-3.5 rounded-xl border border-blue-500/20 bg-blue-500/5 space-y-2",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200 block",children:"Your One-Time Device Code:"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-sm font-mono text-white tracking-widest font-bold text-center select-all",children:G.user_code}),e.jsxs("button",{type:"button",onClick:()=>pe(G.user_code),className:"flex items-center gap-1 px-3 py-2 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-xs font-medium text-slate-300 hover:text-white transition-colors cursor-pointer shrink-0",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${P?"text-emerald-400":""}`,children:P?"check":"content_copy"}),P?"Copied":"Copy Code"]})]})]}),e.jsxs("button",{type:"button",onClick:()=>{const C=G.verification_uri_complete||G.verification_uri;C&&window.open(C,"_blank","noopener,noreferrer")},className:"rt-btn rt-btn--primary w-full flex items-center justify-center gap-2 py-2.5 cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"open_in_new"}),"Open Verification Page"]}),e.jsxs("div",{className:"flex items-center gap-3 my-2",children:[e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"}),e.jsx("span",{className:"text-[11px] font-bold text-slate-500 uppercase tracking-wider",children:"OR PASTE TOKEN MANUALLY"}),e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"})]}),e.jsx("div",{className:"space-y-1.5",children:e.jsx("input",{type:"text",value:E,onChange:C=>M(C.target.value),placeholder:"Paste token or authorization response...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-200 focus:outline-none focus:border-blue-500"})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:se,disabled:!A||B==="loading",className:"rt-btn rt-btn--primary w-full flex items-center justify-center gap-2 py-2.5 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"open_in_new"}),e.jsx("span",{children:"Open Authorization Window"})]}),J&&e.jsxs("p",{className:"text-[11px] text-amber-400 text-center flex items-center justify-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"info"}),"Browser blocked popup window. Click above to open the login window directly."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200",children:"Step 1: Authorization Link"}),A&&e.jsx("button",{type:"button",onClick:()=>window.open(A,"_blank"),className:"text-[11px] text-blue-400 hover:text-blue-300 underline cursor-pointer",children:"Open in new tab"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",readOnly:!0,value:A||(B==="loading"?"Initializing link...":"Generating authorization link..."),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-300 focus:outline-none focus:border-blue-500 select-all"}),e.jsxs("button",{type:"button",onClick:w,disabled:!A,className:"flex items-center gap-1 px-3 py-2 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-xs font-medium text-slate-300 hover:text-white transition-colors cursor-pointer shrink-0 disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${te?"text-emerald-400":""}`,children:te?"check":"content_copy"}),te?"Copied":"Copy Link"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 my-2",children:[e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"}),e.jsx("span",{className:"text-[11px] font-bold text-slate-500 uppercase tracking-wider",children:"OR PASTE CALLBACK URL / CODE"}),e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200",children:"Step 2: Paste callback URL or authorization code here"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"After logging in, copy the full URL from your browser address bar and paste it below."}),e.jsx("input",{type:"text",value:E,onChange:C=>M(C.target.value),placeholder:n==="codex"?"http://localhost:1455/auth/callback?code=... or code":`${window.location.origin}/callback?code=... or code`,className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-200 focus:outline-none focus:border-blue-500"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2.5 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:g,className:"px-4 py-2 rounded-xl text-xs font-medium text-slate-400 hover:text-white transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"button",onClick:ye,disabled:!E.trim()||B==="processing",className:"rt-btn rt-btn--primary disabled:opacity-50 disabled:cursor-not-allowed",children:B==="processing"?"Exchanging...":"Connect"})]})]})})};function Ct(l,n={}){const{isCloudflareAi:t=!1}=n,h=l.trim();if(!t&&/^LLM\|/i.test(h))return{baseName:"LLM",apiKey:h};const g=l.split("|");if(t&&g.length>=3){const c=g[0].trim(),K=g.slice(1,-1).join("|").trim(),b=g[g.length-1].trim();return{baseName:c||"Key",apiKey:K,providerSpecificData:{accountId:b}}}if(g.length>=2){const c=g[0].trim(),K=g.slice(1).join("|").trim();return{baseName:c||"Key",apiKey:K}}return{baseName:"Key",apiKey:g[0].trim()}}function At(l,n=[],t={}){const h=Array.isArray(n)?n:[],g=new Set(h.map(c=>typeof c=="string"?c.toLowerCase():"")),f=[];for(const c of l){const K=typeof c=="string"?c.trim():"";if(!K)continue;const b=Ct(K,t);if(!b||!b.apiKey)continue;const I=b.baseName;let y=1,k;for(;k=`${I} ${y}`,!!g.has(k.toLowerCase());)y+=1;g.add(k.toLowerCase());const N={name:k,apiKey:b.apiKey};b.providerSpecificData&&(N.providerSpecificData=b.providerSpecificData),f.push(N)}return f}const St=({isOpen:l,provider:n,existingNames:t=[],onClose:h,onSuccess:g,onOpenOAuth:f})=>{const c=n.id.toLowerCase(),K=c==="opencode"||c==="oc"||!!n.noAuth||n.requiresApiKey===!1||n.authType==="none",b=c==="ollama-local"||c.includes("ollama"),I=!!n.isLocal||c==="lm-studio"||c==="jan",y=K||b||I||n.requiresApiKey===!1,k=c==="azure"||c.includes("azure"),N=c==="cloudflare-ai"||c==="cloudflare",U=c==="bedrock"||c.includes("bedrock"),S=c==="grok-web"||c==="iflow",A=c==="xiaomi-tokenplan",H=c==="alicode"||c==="alibaba",z=s.useMemo(()=>A?[{id:"sgp",label:"Singapore (新加坡)"},{id:"cn",label:"China (中国大陆)"},{id:"ams",label:"Amsterdam (阿姆斯特丹)"}]:n.regions||[],[A,n.regions]),[W,E]=s.useState(n.defaultRegion||(z.length>0?z[0].id:"sgp")),[M,B]=s.useState("single"),[D,ee]=s.useState(""),[Y,te]=s.useState(""),[j,P]=s.useState(""),[Q,J]=s.useState("http://127.0.0.1:11434"),[L,ne]=s.useState(n.defaultBaseUrl||(c==="lm-studio"?"http://localhost:1234/v1":c==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),[ue,G]=s.useState(""),[oe,ge]=s.useState("gpt-4"),[me,be]=s.useState("2024-10-01-preview"),[V,X]=s.useState(""),[F,_]=s.useState(""),[r,d]=s.useState(""),[w,pe]=s.useState("profile"),[se,ye]=s.useState(""),[C,re]=s.useState("us-east-1"),[$,xe]=s.useState(""),[u,x]=s.useState(""),[v,he]=s.useState(""),[O,Z]=s.useState(null),[q,Ae]=s.useState(!1),[fe,ie]=s.useState(null),[Se,we]=s.useState(null),[Be,ce]=s.useState(!1),[Re,Ee]=s.useState(null),[Ue,Me]=s.useState(!1),[ae,ke]=s.useState(null),De=s.useCallback(()=>{B("single"),ee(""),te(""),P(""),J("http://127.0.0.1:11434"),ne(n.defaultBaseUrl||(c==="lm-studio"?"http://localhost:1234/v1":c==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),G(""),ge("gpt-4"),be("2024-10-01-preview"),X(""),_(""),d(""),pe("profile"),ye(""),re("us-east-1"),xe(""),x(""),E(n.defaultRegion||(z.length>0?z[0].id:"sgp")),he(""),Z(null),Ae(!1),ie(null),we(null),ce(!1),Ee(null),Me(!1),ke(null)},[n.defaultBaseUrl,n.defaultRegion,z,c]);s.useEffect(()=>{l&&De()},[l,De]);const He=async()=>{Me(!0),ke(null);try{const le=await(await fetch(`/api/oauth/${encodeURIComponent(n.id)}/auto-import`)).json(),de=le.apiKey||le.accessToken;le.found&&de?(P(de),D.trim()||ee(le.userName||le.keyName||le.email||`${n.name} CLI`),ie(null),we(null)):ke(le.error||`Could not find ${n.name} CLI credentials`)}catch{ke(`Failed to auto-import from ${n.name} CLI`)}finally{Me(!1)}},Oe=()=>{De(),h()},Le=()=>S?c==="grok-web"?"sso=xxxx... or raw cookie":"eyJhbGciOi...":y?"Optional / Not required":A?"tp-...":c.startsWith("deepseek")?"sk-...":c.startsWith("xai")?"xai-...":c.startsWith("groq")?"gsk_...":c.startsWith("anthropic")?"sk-ant-...":c.startsWith("gemini")?"AIzaSy...":"sk-...",ve=()=>{if(b)return{baseUrl:Q.trim()||"http://127.0.0.1:11434"};if(I)return{baseUrl:L.trim()};if(k)return{azureEndpoint:ue.trim(),deployment:oe.trim(),apiVersion:me.trim(),organization:V.trim()||void 0};if(N)return{accountId:F.trim()};if(U)return w==="profile"?{profile:se.trim(),region:C.trim()||"us-east-1"}:{accessKeyId:$.trim(),region:C.trim()||"us-east-1",sessionToken:u.trim()||void 0};if(A||z.length>0){const m={region:W};return H&&r.trim()&&(m.baseUrl=r.trim()),m}},$e=()=>y?!0:U&&w==="profile"?!!se.trim():U&&w==="static"?!!(j.trim()&&$.trim()):k?!!(j.trim()&&ue.trim()&&oe.trim()):N?!!(j.trim()&&F.trim()):A?!!(j.trim()&&W):!!j.trim(),Pe=async()=>{Ae(!0),ie(null),we(null);try{const m=ve(),de=await(await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:n.id,apiKey:j.trim(),providerSpecificData:m})})).json();de.valid?ie("valid"):(ie("invalid"),we(de.error||"Validation check failed"))}catch(m){ie("invalid"),we(m.message||"Connection check error")}finally{Ae(!1)}},Ne=async()=>{if(!$e())return;ce(!0),Ee(null);const m=K?c==="opencode"||c==="oc"?"OpenCode Free":`${n.name} (Public)`:b?"Ollama Local":I?`${n.name} Local`:U&&w==="profile"?`Bedrock (${se})`:A?`Xiaomi MiMo (${W.toUpperCase()})`:`${n.name} Account`,le=D.trim()||m,de=ve()||{};Y.trim()&&(de.tag=Y.trim().toLowerCase());try{const Te=await fetch(`/api/providers/${n.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:le,apiKey:j.trim()||(c==="opencode"||c==="oc"?"public":""),providerSpecificData:Object.keys(de).length>0?de:void 0})});if(!Te.ok){const Ke=await Te.json().catch(()=>({}));throw new Error(Ke.error||`Server returned ${Te.status}`)}Ce(),De(),g(),h()}catch(Te){Ee(Te.message||"Failed to save account")}finally{ce(!1)}},Ie=async()=>{if(!v.trim())return;ce(!0),Z(null),Ee(null);const m=v.split(`
1
+ import{r as s,j as e}from"./vendor-BcOI2aZ9.js";import{i as lt}from"./providersData-BI_7MaUL.js";import{g as ot}from"./metadataRegistry-W75_wn57.js";import{u as yt,D as vt,P as _e}from"./index-5TzViNxR.js";import{S as ze}from"./Select-BNRH8LIG.js";import{T as Fe}from"./ToolIcon-Cp4gSgFt.js";import{i as Ce}from"./ModelAutocompleteInput-DJkxW2yD.js";import{C as nt,E as Nt}from"./EditAccountModal-BhPOk3Ya.js";import{C as wt}from"./ConfirmModal-BS3mAUd5.js";import"./lucide-Cc35htxl.js";const kt=({isOpen:l,providerId:n,providerName:t,onSuccess:h,onClose:g})=>{const f=s.useRef(h);f.current=h;const c=s.useRef(g);c.current=g;const K=yt(C=>C.info),b=(K==null?void 0:K.port)||vt,I=s.useRef(b);I.current=b;const y=ot(n),k=(y==null?void 0:y.regions)||[],[N,U]=s.useState((y==null?void 0:y.defaultRegion)||(k.length>0?k[0].id:"")),S=s.useRef(N);S.current=N;const[A,H]=s.useState(""),[z,W]=s.useState(`http://localhost:${b}/callback`),[E,M]=s.useState(""),[B,D]=s.useState("loading"),[ee,Y]=s.useState(null),[te,j]=s.useState(!1),[P,Q]=s.useState(!1),[J,L]=s.useState(!1),[ne,ue]=s.useState(!1),[G,oe]=s.useState(null),ge=s.useRef(null),me=s.useRef(!1),be=s.useRef(void 0),V=s.useRef(void 0),X=s.useRef(0),F=s.useRef(null),_=s.useCallback(()=>{F.current&&(clearTimeout(F.current),clearInterval(F.current),F.current=null)},[]),r=s.useCallback(async C=>{if(!me.current){me.current=!0,_(),D("processing"),Y(null);try{const re=await fetch(`/api/oauth/${n}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:C,redirectUri:z,codeVerifier:be.current,state:V.current,region:S.current||void 0})}),$=await re.json().catch(()=>({}));if(!re.ok||$.error)throw new Error($.error||"Token exchange failed");D("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),c.current()},1200)}catch(re){me.current=!1,D("error"),Y(re.message||"Failed to exchange authorization token")}}},[n,z,_]),d=s.useCallback(async C=>{const re=++X.current,$=()=>re!==X.current;me.current=!1,_(),D("loading"),Y(null),M(""),ue(!1),oe(null),L(!1),be.current=void 0,V.current=void 0;const xe=C!==void 0?C:S.current,u=xe?`&region=${encodeURIComponent(xe)}`:"",x=xe?`?region=${encodeURIComponent(xe)}`:"",v=window.location.port==="5173"?`http://localhost:${I.current}/callback`:`${window.location.origin}/callback`;W(v);try{const he=await fetch(`/api/oauth/${n}/authorize?redirect_uri=${encodeURIComponent(v)}${u}`),O=await he.json().catch(()=>({}));if($())return;if(!he.ok||O.error)throw new Error(O.error||`Authorization error (HTTP ${he.status})`);if(O.flowType==="device_code"||!O.authUrl&&O.flowType){ue(!0),D("waiting");const Z=await fetch(`/api/oauth/${n}/device-code${x}`),q=await Z.json().catch(()=>({}));if($())return;if(!Z.ok||!q.device_code)throw new Error(q.error||"Failed to initiate device code flow");oe(q);const Ae=q.verification_uri_complete||q.verification_uri;if(Ae)try{window.open(Ae,"_blank","noopener,noreferrer")}catch{}let fe=Number(q.interval)||5,ie=!0;const Se=we=>{$()||(F.current&&clearTimeout(F.current),F.current=setTimeout(async()=>{if(!(!ie||$()))try{const ce=await(await fetch(`/api/oauth/${n}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:q.device_code,codeVerifier:q.codeVerifier,region:xe||void 0,extraData:{...q||{},_zcodePollToken:q._zcodePollToken,_minimaxPollByUser:q._minimaxPollByUser,codeVerifier:q.codeVerifier,user_code:q.user_code,region:xe||void 0}})})).json();if($())return;if(ce.ok&&ce.success){ie=!1,_(),D("success"),setTimeout(()=>{f.current(),c.current()},1200);return}if(ce.error==="slow_down"){fe=Math.min(fe+5,30),Se(fe);return}if(ce.error==="authorization_pending"){Se(fe);return}if(ce.error){ie=!1,_(),D("error"),Y(ce.error_description||ce.error);return}Se(fe)}catch{ie&&Se(fe)}},we*1e3))};Se(fe);return}if(O.authUrl){H(O.authUrl),O.redirectUri&&W(O.redirectUri),O.codeVerifier&&(be.current=O.codeVerifier),O.state&&(V.current=O.state),D("waiting");try{localStorage.setItem("oauth_pending_flow",JSON.stringify({providerId:n,redirectUri:O.redirectUri||v,state:O.state,codeVerifier:O.codeVerifier,timestamp:Date.now()}))}catch{}try{const Z=window.open(O.authUrl,"oauth_popup","width=600,height=700");Z&&!Z.closed?ge.current=Z:L(!0)}catch{L(!0)}return}throw new Error("No authorization URL returned from provider")}catch(he){if($())return;if(n==="antigravity"&&DEFAULT_ANTIGRAVITY_AUTH_URL){H(DEFAULT_ANTIGRAVITY_AUTH_URL),D("waiting");try{const O=window.open(DEFAULT_ANTIGRAVITY_AUTH_URL,"oauth_popup","width=600,height=700");O?ge.current=O:L(!0)}catch{L(!0)}}else D("error"),Y(he.message||"Failed to initialize authorization endpoint")}},[n,_]);if(s.useEffect(()=>{if(!l){_(),D("loading"),Y(null),ue(!1),oe(null);return}return d(),()=>{X.current++,_()}},[l,n,d,_]),s.useEffect(()=>{if(!l)return;const C=x=>{if(!x)return;if(x.done){me.current=!0,_(),D("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),c.current()},1200);return}if(x.error){D("error"),Y(x.errorDescription||x.error);return}const v=x.code||x.token||(x.userId&&x.token?x.fullUrl||`${window.location.origin}/?user_id=${x.userId}&access_token=${x.token}`:null);v&&r(v)},re=x=>{var v;((v=x.data)==null?void 0:v.type)==="oauth_callback"&&C(x.data.data)};window.addEventListener("message",re);let $=null;try{$=new BroadcastChannel("oauth_callback"),$.onmessage=x=>C(x.data)}catch{}const xe=x=>{if(x.key==="oauth_callback"&&x.newValue)try{const v=JSON.parse(x.newValue);C(v),localStorage.removeItem("oauth_callback")}catch{}};window.addEventListener("storage",xe);const u=setInterval(()=>{try{const x=localStorage.getItem("oauth_callback");if(x){const v=JSON.parse(x);v&&(!v.timestamp||Date.now()-v.timestamp<6e4)&&C(v),localStorage.removeItem("oauth_callback")}}catch{}},500);return()=>{clearInterval(u),window.removeEventListener("message",re),window.removeEventListener("storage",xe),$&&$.close()}},[l,r]),!l)return null;const w=()=>{A&&(navigator.clipboard.writeText(A),j(!0),setTimeout(()=>j(!1),2e3))},pe=C=>{C&&(navigator.clipboard.writeText(C),Q(!0),setTimeout(()=>Q(!1),2e3))},se=()=>{if(A){L(!1);try{const C=window.open(A,"oauth_popup","width=600,height=700");C&&(ge.current=C)}catch{}}},ye=()=>{E.trim()&&r(E.trim())};return e.jsx(_e,{isOpen:l,onClose:g,maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-blue-400",children:"lock"}),e.jsxs("h3",{className:"text-base font-bold text-white tracking-tight",children:["Connect ",t]})]}),e.jsx("button",{type:"button",onClick:g,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/5 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),k.length>0&&e.jsxs("div",{className:"space-y-1.5 p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"block text-xs font-medium text-slate-300",children:"Server / Region:"}),e.jsx("span",{className:"text-[10px] text-slate-500 font-mono",children:N})]}),e.jsx(ze,{value:N,onChange:C=>{U(C),S.current=C,d(C)},options:k.map(C=>({value:C.id,label:C.label}))})]}),B==="loading"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-blue-500/20 rounded-xl bg-blue-500/10 text-xs text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 animate-spin",children:"progress_activity"}),e.jsxs("span",{children:["Initializing authorization for ",t,"..."]})]}),B==="waiting"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-blue-500/20 rounded-xl bg-blue-500/10 text-xs text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{children:ne?"Waiting for device authorization in browser...":J?"Authorization link ready. Click button below to open login window.":"Popup window opened. Complete authorization in browser..."})]}),B==="processing"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-blue-500/20 rounded-xl bg-blue-500/10 text-xs text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 animate-spin",children:"sync"}),e.jsx("span",{children:"Exchanging authorization code and saving credentials..."})]}),B==="success"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-emerald-500/30 rounded-xl bg-emerald-500/10 text-xs text-emerald-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-emerald-400 font-bold",children:"check_circle"}),e.jsx("span",{children:"Connected successfully! Refreshing connections..."})]}),B==="error"&&ee&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 px-3.5 py-2.5 border border-red-500/30 rounded-xl bg-red-500/10 text-xs text-red-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-400 mt-0.5 shrink-0",children:"error"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"Connection Failed"}),e.jsx("p",{className:"text-red-200",children:ee})]})]}),e.jsxs("button",{type:"button",onClick:()=>d(),className:"w-full flex items-center justify-center gap-1.5 py-2 px-3 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-semibold text-slate-200 border border-[#1E293B] cursor-pointer transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"refresh"}),"Retry Authorization"]})]}),ne&&G?e.jsxs("div",{className:"space-y-4 pt-1",children:[e.jsxs("div",{className:"p-3.5 rounded-xl border border-blue-500/20 bg-blue-500/5 space-y-2",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200 block",children:"Your One-Time Device Code:"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-sm font-mono text-white tracking-widest font-bold text-center select-all",children:G.user_code}),e.jsxs("button",{type:"button",onClick:()=>pe(G.user_code),className:"flex items-center gap-1 px-3 py-2 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-xs font-medium text-slate-300 hover:text-white transition-colors cursor-pointer shrink-0",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${P?"text-emerald-400":""}`,children:P?"check":"content_copy"}),P?"Copied":"Copy Code"]})]})]}),e.jsxs("button",{type:"button",onClick:()=>{const C=G.verification_uri_complete||G.verification_uri;C&&window.open(C,"_blank","noopener,noreferrer")},className:"rt-btn rt-btn--primary w-full flex items-center justify-center gap-2 py-2.5 cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"open_in_new"}),"Open Verification Page"]}),e.jsxs("div",{className:"flex items-center gap-3 my-2",children:[e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"}),e.jsx("span",{className:"text-[11px] font-bold text-slate-500 uppercase tracking-wider",children:"OR PASTE TOKEN MANUALLY"}),e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"})]}),e.jsx("div",{className:"space-y-1.5",children:e.jsx("input",{type:"text",value:E,onChange:C=>M(C.target.value),placeholder:"Paste token or authorization response...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-200 focus:outline-none focus:border-blue-500"})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:se,disabled:!A||B==="loading",className:"rt-btn rt-btn--primary w-full flex items-center justify-center gap-2 py-2.5 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"open_in_new"}),e.jsx("span",{children:"Open Authorization Window"})]}),J&&e.jsxs("p",{className:"text-[11px] text-amber-400 text-center flex items-center justify-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"info"}),"Browser blocked popup window. Click above to open the login window directly."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200",children:"Step 1: Authorization Link"}),A&&e.jsx("button",{type:"button",onClick:()=>window.open(A,"_blank"),className:"text-[11px] text-blue-400 hover:text-blue-300 underline cursor-pointer",children:"Open in new tab"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",readOnly:!0,value:A||(B==="loading"?"Initializing link...":"Generating authorization link..."),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-300 focus:outline-none focus:border-blue-500 select-all"}),e.jsxs("button",{type:"button",onClick:w,disabled:!A,className:"flex items-center gap-1 px-3 py-2 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-xs font-medium text-slate-300 hover:text-white transition-colors cursor-pointer shrink-0 disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${te?"text-emerald-400":""}`,children:te?"check":"content_copy"}),te?"Copied":"Copy Link"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 my-2",children:[e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"}),e.jsx("span",{className:"text-[11px] font-bold text-slate-500 uppercase tracking-wider",children:"OR PASTE CALLBACK URL / CODE"}),e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200",children:"Step 2: Paste callback URL or authorization code here"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"After logging in, copy the full URL from your browser address bar and paste it below."}),e.jsx("input",{type:"text",value:E,onChange:C=>M(C.target.value),placeholder:n==="codex"?"http://localhost:1455/auth/callback?code=... or code":`${window.location.origin}/callback?code=... or code`,className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-200 focus:outline-none focus:border-blue-500"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2.5 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:g,className:"px-4 py-2 rounded-xl text-xs font-medium text-slate-400 hover:text-white transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"button",onClick:ye,disabled:!E.trim()||B==="processing",className:"rt-btn rt-btn--primary disabled:opacity-50 disabled:cursor-not-allowed",children:B==="processing"?"Exchanging...":"Connect"})]})]})})};function Ct(l,n={}){const{isCloudflareAi:t=!1}=n,h=l.trim();if(!t&&/^LLM\|/i.test(h))return{baseName:"LLM",apiKey:h};const g=l.split("|");if(t&&g.length>=3){const c=g[0].trim(),K=g.slice(1,-1).join("|").trim(),b=g[g.length-1].trim();return{baseName:c||"Key",apiKey:K,providerSpecificData:{accountId:b}}}if(g.length>=2){const c=g[0].trim(),K=g.slice(1).join("|").trim();return{baseName:c||"Key",apiKey:K}}return{baseName:"Key",apiKey:g[0].trim()}}function At(l,n=[],t={}){const h=Array.isArray(n)?n:[],g=new Set(h.map(c=>typeof c=="string"?c.toLowerCase():"")),f=[];for(const c of l){const K=typeof c=="string"?c.trim():"";if(!K)continue;const b=Ct(K,t);if(!b||!b.apiKey)continue;const I=b.baseName;let y=1,k;for(;k=`${I} ${y}`,!!g.has(k.toLowerCase());)y+=1;g.add(k.toLowerCase());const N={name:k,apiKey:b.apiKey};b.providerSpecificData&&(N.providerSpecificData=b.providerSpecificData),f.push(N)}return f}const St=({isOpen:l,provider:n,existingNames:t=[],onClose:h,onSuccess:g,onOpenOAuth:f})=>{const c=n.id.toLowerCase(),K=c==="opencode"||c==="oc"||!!n.noAuth||n.requiresApiKey===!1||n.authType==="none",b=c==="ollama-local"||c.includes("ollama"),I=!!n.isLocal||c==="lm-studio"||c==="jan",y=K||b||I||n.requiresApiKey===!1,k=c==="azure"||c.includes("azure"),N=c==="cloudflare-ai"||c==="cloudflare",U=c==="bedrock"||c.includes("bedrock"),S=c==="grok-web"||c==="iflow",A=c==="xiaomi-tokenplan",H=c==="alicode"||c==="alibaba",z=s.useMemo(()=>A?[{id:"sgp",label:"Singapore (新加坡)"},{id:"cn",label:"China (中国大陆)"},{id:"ams",label:"Amsterdam (阿姆斯特丹)"}]:n.regions||[],[A,n.regions]),[W,E]=s.useState(n.defaultRegion||(z.length>0?z[0].id:"sgp")),[M,B]=s.useState("single"),[D,ee]=s.useState(""),[Y,te]=s.useState(""),[j,P]=s.useState(""),[Q,J]=s.useState("http://127.0.0.1:11434"),[L,ne]=s.useState(n.defaultBaseUrl||(c==="lm-studio"?"http://localhost:1234/v1":c==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),[ue,G]=s.useState(""),[oe,ge]=s.useState("gpt-4"),[me,be]=s.useState("2024-10-01-preview"),[V,X]=s.useState(""),[F,_]=s.useState(""),[r,d]=s.useState(""),[w,pe]=s.useState("profile"),[se,ye]=s.useState(""),[C,re]=s.useState("us-east-1"),[$,xe]=s.useState(""),[u,x]=s.useState(""),[v,he]=s.useState(""),[O,Z]=s.useState(null),[q,Ae]=s.useState(!1),[fe,ie]=s.useState(null),[Se,we]=s.useState(null),[Be,ce]=s.useState(!1),[Re,Ee]=s.useState(null),[Ue,Me]=s.useState(!1),[ae,ke]=s.useState(null),De=s.useCallback(()=>{B("single"),ee(""),te(""),P(""),J("http://127.0.0.1:11434"),ne(n.defaultBaseUrl||(c==="lm-studio"?"http://localhost:1234/v1":c==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),G(""),ge("gpt-4"),be("2024-10-01-preview"),X(""),_(""),d(""),pe("profile"),ye(""),re("us-east-1"),xe(""),x(""),E(n.defaultRegion||(z.length>0?z[0].id:"sgp")),he(""),Z(null),Ae(!1),ie(null),we(null),ce(!1),Ee(null),Me(!1),ke(null)},[n.defaultBaseUrl,n.defaultRegion,z,c]);s.useEffect(()=>{l&&De()},[l,De]);const He=async()=>{Me(!0),ke(null);try{const le=await(await fetch(`/api/oauth/${encodeURIComponent(n.id)}/auto-import`)).json(),de=le.apiKey||le.accessToken;le.found&&de?(P(de),D.trim()||ee(le.userName||le.keyName||le.email||`${n.name} CLI`),ie(null),we(null)):ke(le.error||`Could not find ${n.name} CLI credentials`)}catch{ke(`Failed to auto-import from ${n.name} CLI`)}finally{Me(!1)}},Oe=()=>{De(),h()},Le=()=>S?c==="grok-web"?"sso=xxxx... or raw cookie":"eyJhbGciOi...":y?"Optional / Not required":A?"tp-...":c.startsWith("deepseek")?"sk-...":c.startsWith("xai")?"xai-...":c.startsWith("groq")?"gsk_...":c.startsWith("anthropic")?"sk-ant-...":c.startsWith("gemini")?"AIzaSy...":"sk-...",ve=()=>{if(b)return{baseUrl:Q.trim()||"http://127.0.0.1:11434"};if(I)return{baseUrl:L.trim()};if(k)return{azureEndpoint:ue.trim(),deployment:oe.trim(),apiVersion:me.trim(),organization:V.trim()||void 0};if(N)return{accountId:F.trim()};if(U)return w==="profile"?{profile:se.trim(),region:C.trim()||"us-east-1"}:{accessKeyId:$.trim(),region:C.trim()||"us-east-1",sessionToken:u.trim()||void 0};if(A||z.length>0){const m={region:W};return H&&r.trim()&&(m.baseUrl=r.trim()),m}},$e=()=>y?!0:U&&w==="profile"?!!se.trim():U&&w==="static"?!!(j.trim()&&$.trim()):k?!!(j.trim()&&ue.trim()&&oe.trim()):N?!!(j.trim()&&F.trim()):A?!!(j.trim()&&W):!!j.trim(),Pe=async()=>{Ae(!0),ie(null),we(null);try{const m=ve(),de=await(await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:n.id,apiKey:j.trim(),providerSpecificData:m})})).json();de.valid?ie("valid"):(ie("invalid"),we(de.error||"Validation check failed"))}catch(m){ie("invalid"),we(m.message||"Connection check error")}finally{Ae(!1)}},Ne=async()=>{if(!$e())return;ce(!0),Ee(null);const m=K?c==="opencode"||c==="oc"?"OpenCode Free":`${n.name} (Public)`:b?"Ollama Local":I?`${n.name} Local`:U&&w==="profile"?`Bedrock (${se})`:A?`Xiaomi MiMo (${W.toUpperCase()})`:`${n.name} Account`,le=D.trim()||m,de=ve()||{};Y.trim()&&(de.tag=Y.trim().toLowerCase());try{const Te=await fetch(`/api/providers/${n.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:le,apiKey:j.trim()||(c==="opencode"||c==="oc"?"public":""),providerSpecificData:Object.keys(de).length>0?de:void 0})});if(!Te.ok){const Ke=await Te.json().catch(()=>({}));throw new Error(Ke.error||`Server returned ${Te.status}`)}Ce(),De(),g(),h()}catch(Te){Ee(Te.message||"Failed to save account")}finally{ce(!1)}},Ie=async()=>{if(!v.trim())return;ce(!0),Z(null),Ee(null);const m=v.split(`
2
2
  `),le=At(m,t,{isCloudflareAi:N});if(le.length===0){Ee("No valid keys found in input"),ce(!1);return}try{const de=await fetch(`/api/providers/${n.id}/accounts/bulk`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accounts:le})});if(!de.ok){const Ke=await de.json().catch(()=>({}));throw new Error(Ke.error||`Bulk addition failed (${de.status})`)}const Te=await de.json();Ce(),Z({success:Te.count||le.length,failed:0}),setTimeout(()=>{De(),g(),h()},700)}catch(de){Ee(de.message||"Failed to add bulk keys")}finally{ce(!1)}};return e.jsx(_e,{isOpen:l,onClose:Oe,maxWidthClass:"max-w-xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Fe,{src:n.image,name:n.name,color:n.color,iconBg:n.iconBg,size:"md",fallback:e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"vpn_key"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white",children:["Add ",n.name," Connection"]}),e.jsx("p",{className:"text-xs text-slate-400",children:S?"Paste session cookie credentials":U?"Configure AWS SSO profile or static keys":k?"Configure Azure OpenAI deployment & endpoint":b?"Connect local self-hosted model service":I?`Connect local ${n.name} model server`:y?"No API key required for this provider":A?"Select cluster region & paste Token Plan API key":"API key is hardware-encrypted (AES-256-GCM)"})]})]}),e.jsx("button",{onClick:Oe,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10 cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),f&&e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl border border-blue-500/20 bg-blue-500/10 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-blue-400",children:"lock"}),e.jsx("span",{children:"This provider also supports OAuth authorization."})]}),e.jsx("button",{type:"button",onClick:f,className:"rt-btn rt-btn--primary text-xs py-1 px-3 cursor-pointer shrink-0",children:"Connect with OAuth"})]}),!U&&!b&&!y&&e.jsxs("div",{className:"flex bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-xs",children:[e.jsx("button",{onClick:()=>{B("single"),Z(null)},className:`flex-1 py-1.5 rounded-lg font-medium transition-colors cursor-pointer ${M==="single"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Single Connection"}),e.jsx("button",{onClick:()=>{B("bulk"),Z(null)},className:`flex-1 py-1.5 rounded-lg font-medium transition-colors cursor-pointer ${M==="bulk"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Bulk Add Keys"})]}),M==="bulk"&&!U&&!b&&!y?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-xs text-slate-400 space-y-1",children:[e.jsx("p",{children:"One key per line. Format:"}),e.jsx("code",{className:"block bg-[#0A0D14] p-2 rounded-lg border border-[#1E293B] font-mono text-[11px] text-blue-300",children:N?`name|apiToken|accountId
3
3
  or just apiToken`:`name|apiKey
4
4
  or just apiKey (auto-numbered)`})]}),e.jsx("textarea",{value:v,onChange:m=>he(m.target.value),placeholder:N?`Prod|cf_token_123|acc_xyz456
@@ -1 +1 @@
1
- import{r as l,j as e}from"./vendor-BcOI2aZ9.js";import{P as ae}from"./index-CKuvklEr.js";import{C as ne}from"./ConfirmModal-OWeauwYv.js";import{i as Q}from"./ModelAutocompleteInput-CoinzdsW.js";import{g as X}from"./metadataRegistry-NuDSSkP9.js";import{T as Z}from"./ToolIcon-Cp4gSgFt.js";import{C as ie,O as ee,F as te,A as se}from"./providersData-DS1-ETBi.js";import"./lucide-Cc35htxl.js";const ce=({isOpen:N,existingProviderIds:z,onClose:o,onImportSuccess:g})=>{const[u,w]=l.useState([]),[_,y]=l.useState(!1),[h,j]=l.useState(""),[p,q]=l.useState("all"),[C,b]=l.useState(null),[I,k]=l.useState(""),[d,T]=l.useState(""),[v,P]=l.useState("Default Account"),[D,O]=l.useState(!1),[f,A]=l.useState(null);l.useEffect(()=>{N&&(y(!0),fetch("/api/providers/community-catalog").then(a=>a.json()).then(a=>{a&&Array.isArray(a.catalog)&&w(a.catalog)}).catch(a=>{console.error("Failed to load community catalog:",a)}).finally(()=>{y(!1)}))},[N]);const W=l.useMemo(()=>{const a=new Set;for(const n of u)n.category&&a.add(n.category);return["all",...Array.from(a).sort()]},[u]),B=l.useMemo(()=>{const a=h.toLowerCase().trim();return u.filter(n=>{var S;return p!=="all"&&n.category!==p?!1:a?n.name.toLowerCase().includes(a)||n.id.toLowerCase().includes(a)||n.baseUrl.toLowerCase().includes(a)||((S=n.models)==null?void 0:S.some(U=>U.id.toLowerCase().includes(a))):!0})},[u,h,p]),L=a=>{b(a),k(a.baseUrl||"https://api.openai.com"),T(""),P("Default Account"),A(null)},$=async()=>{if(C){O(!0),A(null);try{const a=await fetch("/api/providers/community-catalog/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.id,customBaseUrl:I.trim(),apiKey:d.trim()||void 0,accountName:v.trim()||"Default Account"})}),n=await a.json();if(!a.ok||!n.success)throw new Error(n.error||"Failed to import provider");g(C.id),b(null)}catch(a){A(a.message||"Import failed")}finally{O(!1)}}};return N?e.jsx(ae,{isOpen:N,onClose:o,maxWidthClass:"w-full max-w-4xl",children:e.jsxs("div",{className:"relative w-full max-w-4xl bg-[#0B0F19] border border-[#1E293B] rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[88vh]",children:[e.jsxs("div",{className:"p-6 border-b border-[#1E293B] bg-[#0F1420]/70 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-500/10 border border-blue-500/20 flex items-center justify-center text-blue-400",children:e.jsx("span",{className:"material-symbols-outlined text-[22px]",children:"explore"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-white",children:"Community Providers Catalog"}),e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-blue-500/10 border border-blue-500/20 text-blue-400 text-[11px] font-mono",children:[u.length," Available"]})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"Browse on-demand multi-gateways, token resellers, and community inference proxies. Import directly into active providers."})]})]}),e.jsx("button",{onClick:o,className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-white/5 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsxs("div",{className:"p-4 border-b border-[#1E293B] bg-[#0A0D14]/80 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[240px]",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-2.5 text-slate-500 text-[18px]",children:"search"}),e.jsx("input",{type:"text",value:h,onChange:a=>j(a.target.value),placeholder:"Search community provider by name, ID, endpoint...",className:"w-full pl-9 pr-3 py-2 text-xs bg-[#0F1420] border border-[#1E293B] rounded-xl text-white placeholder-slate-500 focus:outline-none focus:border-blue-500/60 transition-colors"}),h&&e.jsx("button",{onClick:()=>j(""),className:"absolute right-3 top-2.5 text-slate-500 hover:text-white text-xs",children:"✕"})]}),e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1 max-w-full",children:W.map(a=>e.jsx("button",{onClick:()=>q(a),className:`px-2.5 py-1 rounded-lg text-[11px] font-medium capitalize transition-colors cursor-pointer ${p===a?"bg-blue-600 text-white shadow-xs":"bg-[#0F1420] text-slate-400 border border-[#1E293B] hover:text-white"}`,children:a},a))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-2.5 min-h-[300px]",children:_?e.jsxs("div",{className:"py-20 flex flex-col items-center justify-center text-slate-500 text-xs gap-3",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[28px] text-blue-400",children:"sync"}),e.jsx("span",{children:"Loading community catalog..."})]}):B.length===0?e.jsxs("div",{className:"py-16 text-center text-slate-500 text-xs flex flex-col items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[32px] text-slate-600",children:"search_off"}),e.jsx("span",{children:"No community providers match your filter query."})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:B.map(a=>{const n=z.includes(a.id);return e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0F1420]/80 border border-[#1E293B] hover:border-slate-700 transition-all flex flex-col justify-between gap-3 group",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-semibold text-xs text-white",children:a.name}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-[#1E293B] text-slate-400 font-mono",children:a.id})]}),e.jsx("div",{className:"text-[11px] text-slate-500 font-mono truncate max-w-[280px] mt-1",title:a.baseUrl||"Custom Base URL required",children:a.baseUrl||e.jsx("span",{className:"italic text-amber-500/80",children:"Requires custom URL"})})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-mono uppercase font-semibold ${a.format==="claude"?"bg-amber-500/10 text-amber-400 border border-amber-500/20":"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20"}`,children:a.format})})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-3 text-[11px] text-slate-400",children:[a.models&&a.models.length>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-500",children:"memory"}),a.models.length," preset models"]}),a.website&&e.jsxs("a",{href:a.website,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-blue-400/80 hover:text-blue-300 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"open_in_new"}),"Docs"]})]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B]/60 flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-slate-500 capitalize",children:a.category}),n?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-emerald-400 font-medium px-2 py-0.5 rounded bg-emerald-500/10 border border-emerald-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"check_circle"}),"Active"]}):e.jsxs("button",{onClick:()=>L(a),className:"flex items-center gap-1 px-3 py-1 rounded-lg bg-blue-600 hover:bg-blue-500 text-white text-[11px] font-semibold transition-colors cursor-pointer shadow-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"download"}),"Import"]})]})]},a.id)})})}),e.jsxs("div",{className:"p-3 border-t border-[#1E293B] bg-[#0A0D14] flex items-center justify-between text-xs text-slate-500",children:[e.jsxs("span",{children:["Showing ",B.length," of ",u.length," community providers"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-blue-400",children:"info"}),"Imported providers are saved locally in SQLite and support load balancing."]})]}),C&&e.jsx("div",{className:"absolute inset-0 bg-black/75 backdrop-blur-xs flex items-center justify-center p-4 z-50 animate-rt-fade-in",children:e.jsxs("div",{className:"w-full max-w-md bg-[#0F1420] border border-[#1E293B] rounded-2xl p-5 shadow-2xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-[#1E293B] pb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"add_task"}),e.jsxs("h3",{className:"text-sm font-bold text-white",children:["Import ",C.name]})]}),e.jsx("button",{onClick:()=>b(null),className:"text-slate-400 hover:text-white text-xs cursor-pointer",children:"✕"})]}),f&&e.jsxs("div",{className:"p-2.5 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-xs flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"error"}),e.jsx("span",{children:f})]}),e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"Base URL"}),e.jsx("input",{type:"text",value:I,onChange:a=>k(a.target.value),placeholder:"https://api.example.com/v1",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"API endpoint prefix where request completions will be routed."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"Account Name"}),e.jsx("input",{type:"text",value:v,onChange:a=>P(a.target.value),placeholder:"Default Account",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"API Key (Optional)"}),e.jsx("input",{type:"password",value:d,onChange:a=>T(a.target.value),placeholder:"sk-...",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Encrypted with AES-256-GCM hardware vault. You can also configure it later."})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>b(null),disabled:D,className:"px-3.5 py-1.5 rounded-xl border border-[#1E293B] text-slate-400 hover:text-white text-xs font-semibold cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:$,disabled:D||!I.trim(),className:"px-4 py-1.5 rounded-xl bg-blue-600 hover:bg-blue-500 disabled:opacity-50 text-white text-xs font-semibold flex items-center gap-1.5 cursor-pointer shadow-xs",children:D?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[14px]",children:"sync"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"check"}),"Save & Activate"]})})]})]})})]})}):null},ge=({searchQuery:N,onSelectProvider:z})=>{const[o,g]=l.useState(null),[u,w]=l.useState(""),[_,y]=l.useState("Default Account"),[h,j]=l.useState(""),[p,q]=l.useState([]),[C,b]=l.useState(new Set),[I,k]=l.useState({}),[d,T]=l.useState(null),[v,P]=l.useState("all"),[D,O]=l.useState(!1),[f,A]=l.useState(null),[W,B]=l.useState(!1),[L,$]=l.useState(!1),[a,n]=l.useState(null),S=async()=>{try{const t=await fetch("/api/providers");if(t.ok){const s=await t.json(),r=Array.isArray(s)?s.filter(x=>x.id!=="combo"&&x.category!=="composite"):[];q(r)}}catch{}};l.useEffect(()=>{S()},[]);const U=t=>{const s=t.baseUrl||t.defaultBaseUrl||"";return s.startsWith("devin://")||s.startsWith("auggie://")||s.startsWith("zcode://")||s.includes("://")&&s.endsWith("/stdio")},F=t=>U(t)?!1:!!t.noAuth||t.requiresApiKey===!1||t.authType==="none"||t.id==="opencode"||t.id==="oc"||t.id==="ollama-local"||t.id==="lm-studio"||t.id==="jan",G=t=>{const s=p.find(x=>x.id===t),r=X(t);return r&&U(r)?(s==null?void 0:s.accountsCount)??0:t==="opencode"||t==="oc"||s!=null&&s.noAuth||r!=null&&r.noAuth||(r==null?void 0:r.requiresApiKey)===!1||(r==null?void 0:r.authType)==="none"?Math.max(1,(s==null?void 0:s.accountsCount)??0):(s==null?void 0:s.accountsCount)??0},M=t=>{const s=!N||t.name.toLowerCase().includes(N.toLowerCase()),r=G(t.id);return v==="connected"?s&&(r>0||F(t)):v==="not_connected"?s&&r===0&&!F(t):s},re=async()=>{if(o){$(!0),n(null);try{const t=p.find(s=>s.id===o.id);if(!t||h.trim()&&h.trim()!==t.baseUrl){const s={id:o.id,name:(t==null?void 0:t.name)||o.name,baseUrl:h.trim()||o.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:(t==null?void 0:t.format)||o.format||"openai"};t&&(s.models=t.models,s.customHeaders=t.customHeaders,s.proxyUrl=t.proxyUrl,s.thinkingMode=t.thinkingMode,s.strategy=t.strategy,s.stickyLimit=t.stickyLimit);const r=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||`Failed to save provider (${r.status})`)}}if(u.trim()||F(o)){const s=await fetch(`/api/providers/${o.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:_||`${o.name} Connection`,apiKey:u.trim()||(o.id==="opencode"||o.id==="oc"?"public":"")})});if(!s.ok){const r=await s.json().catch(()=>({}));throw new Error(r.error||`Failed to add account (${s.status})`)}}await S(),Q(),w(""),y("Default Account"),j(""),n(null),g(null)}catch(t){console.error(t),n(t.message||"Failed to save connection.")}finally{$(!1)}}},H=async t=>{b(s=>new Set(s).add(t));try{const r=await(await fetch(`/api/providers/${t}/test`,{method:"POST"})).json();k(x=>({...x,[t]:{success:!!r.success,msg:r.message||(r.success?"Connected successfully":"Connection failed"),latencyMs:r.latencyMs}}))}catch(s){k(r=>({...r,[t]:{success:!1,msg:s.message||"Failed to reach gateway"}}))}finally{b(s=>{const r=new Set(s);return r.delete(t),r})}},J=async(t,s)=>{const r=t.filter(c=>G(c.id)>0||F(c));if(r.length===0){alert(`No configured or ready accounts found in ${s}.`);return}T(s);const x=r.map(c=>c.id);b(c=>{const m=new Set(c);return x.forEach(i=>m.add(i)),m});try{const c=await fetch("/api/providers/test-bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerIds:x})});if(c.ok){const m=await c.json();m.results&&k(i=>{const E={...i};for(const[oe,K]of Object.entries(m.results))E[oe]={success:!!K.success,msg:K.message||(K.success?"Connected successfully":"Connection failed"),latencyMs:K.latencyMs};return E})}else for(const m of r)await H(m.id)}catch{for(const c of r)await H(c.id)}finally{b(c=>{const m=new Set(c);return x.forEach(i=>m.delete(i)),m}),T(null)}},le=async()=>{if(f){B(!0);try{(await fetch(`/api/providers/${f.id}`,{method:"DELETE"})).ok&&(await S(),Q())}catch{}finally{B(!1),A(null)}}},Y=new Set(ie.map(t=>t.id)),V=p.filter(t=>!Y.has(t.id)).map(t=>{const s=X(t.id);return{id:t.id,name:t.name,image:(s==null?void 0:s.image)||(t.format==="anthropic"?"/assets/providers/anthropic/icon.png":"/assets/providers/openai/icon.png"),color:(s==null?void 0:s.color)||(t.format==="anthropic"?"#D97706":"#10A37F"),iconBg:(s==null?void 0:s.iconBg)||"#ffffff",category:"custom",format:t.format||"openai",baseUrl:t.baseUrl,models:t.models,thinkingMode:t.thinkingMode}}),R=(t,s=!1)=>{const r=t.category==="custom"||!Y.has(t.id),x=!!s&&r,c=G(t.id),m=C.has(t.id),i=I[t.id];return e.jsxs("div",{onClick:()=>z(t),className:"rt-card stagger-item group flex flex-col justify-between cursor-pointer relative overflow-hidden min-w-[300px] hover:border-blue-500/30 transition-all",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(Z,{src:t.image,name:t.name,color:t.color,iconBg:t.iconBg,size:"md",className:"group-hover:border-blue-500/40 transition-colors shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"text-xs font-bold text-slate-100 truncate group-hover:text-blue-400 transition-colors",children:t.name}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5 flex-wrap",children:[U(t)?e.jsx("span",{className:"rt-badge rt-badge--muted text-[10px]",children:"CLI Bridge"}):F(t)?e.jsxs("span",{className:"rt-badge rt-badge--success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"}),t.isLocal?"Ready (Local)":"Ready (Free)"]}):c>0?e.jsxs("span",{className:"rt-badge rt-badge--success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400 animate-pulse"}),c," Connected"]}):e.jsx("span",{className:"rt-badge rt-badge--muted",children:"No connections"}),i&&e.jsx("span",{className:`rt-badge text-[10px] ${i.success?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,title:i.msg,children:i.success?`● ${i.latencyMs?`${i.latencyMs}ms`:"Active"}`:"● Error"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:E=>{E.stopPropagation(),H(t.id)},disabled:m,title:"Test Connection",className:"p-2 rounded-lg bg-white/5 hover:bg-blue-500/20 text-slate-400 hover:text-blue-400 transition-colors cursor-pointer",children:e.jsx("span",{className:`material-symbols-outlined text-[16px] ${m?"animate-spin text-blue-400":""}`,children:m?"sync":"speed"})}),x&&e.jsx("button",{onClick:E=>{E.stopPropagation(),A(t)},title:"Delete Provider",className:"p-2 rounded-lg bg-white/5 hover:bg-red-500/20 text-slate-400 hover:text-red-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})]})]}),i&&e.jsx("div",{className:`w-full py-1 px-3 text-[10px] font-mono border-t truncate ${i.success?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-red-500/10 text-red-400 border-red-500/20"}`,title:i.msg,children:i.success?`✓ ${i.msg}`:`✗ ${i.msg}`})]},t.id)};return e.jsxs("div",{className:"space-y-8 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4 rounded-2xl bg-[#0F1420]/70 border border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("span",{className:"font-semibold text-slate-300",children:"Filter Status:"}),e.jsxs("div",{className:"flex items-center bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B]",children:[e.jsx("button",{onClick:()=>P("all"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="all"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"All Providers"}),e.jsx("button",{onClick:()=>P("connected"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="connected"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Connected Only"}),e.jsx("button",{onClick:()=>P("not_connected"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="not_connected"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Unconfigured"})]})]}),e.jsxs("div",{className:"text-xs text-slate-400 font-mono flex items-center gap-2",children:[e.jsx("span",{children:"Active Accounts:"}),e.jsx("span",{className:"px-2 py-0.5 rounded-md bg-blue-500/10 text-blue-400 border border-blue-500/20 font-bold",children:p.reduce((t,s)=>t+(s.accountsCount||0),0)})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"add_circle"}),"Custom Providers (OpenAI & Anthropic Compatible)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>{w(""),y("Default Account"),j("https://api.anthropic.com"),g({id:`custom-anthropic-${Date.now().toString().slice(-4)}`,name:"Custom Anthropic",image:"/assets/providers/anthropic/icon.png",category:"custom",format:"anthropic",baseUrl:"https://api.anthropic.com"})},className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add Anthropic Compatible"]}),e.jsxs("button",{onClick:()=>{w(""),y("Default Account"),j("https://api.openai.com"),g({id:`custom-openai-${Date.now().toString().slice(-4)}`,name:"Custom OpenAI",image:"/assets/providers/openai/icon.png",category:"custom",format:"openai",baseUrl:"https://api.openai.com"})},className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add OpenAI Compatible"]}),e.jsxs("button",{onClick:()=>O(!0),className:"rt-btn rt-btn--secondary hover:border-blue-500/50",title:"Browse 124 community-curated routers & gateways",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[16px]",children:"explore"}),"Community Catalog"]})]})]}),V.filter(M).length>0?e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:V.filter(M).map(t=>R(t,!0))}):e.jsxs("div",{className:"border border-dashed border-[#1E293B] bg-[#0E1320]/60 rounded-2xl p-5 text-center text-xs text-slate-400 flex items-center justify-center gap-2 hover:border-blue-500/30 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"cloud_sync"}),e.jsx("span",{children:V.length>0?"No custom providers match the current filter.":"Use the buttons above to register self-hosted vLLM, Ollama, LM Studio, or local API proxies."})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"verified"}),"OAuth & Managed IDE Providers"]}),e.jsxs("button",{onClick:()=>J(ee,"OAuth Providers"),disabled:d==="OAuth Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="OAuth Providers"?"animate-spin text-blue-400":""}`,children:d==="OAuth Providers"?"sync":"play_arrow"}),d==="OAuth Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:ee.filter(M).map(t=>R(t,!1))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[18px]",children:"redeem"}),"Free Tier & Community Gateways"]}),e.jsxs("button",{onClick:()=>J(te,"Free Tier Providers"),disabled:d==="Free Tier Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="Free Tier Providers"?"animate-spin text-emerald-400":""}`,children:d==="Free Tier Providers"?"sync":"play_arrow"}),d==="Free Tier Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:te.filter(M).map(t=>R(t,!1))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"key"}),"Direct API Key Providers"]}),e.jsxs("button",{onClick:()=>J(se,"API Key Providers"),disabled:d==="API Key Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="API Key Providers"?"animate-spin text-blue-400":""}`,children:d==="API Key Providers"?"sync":"play_arrow"}),d==="API Key Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:se.filter(M).map(t=>R(t,!1))})]}),e.jsx(ae,{isOpen:!!o,onClose:()=>{g(null),w(""),y("Default Account"),j(""),n(null)},maxWidthClass:"max-w-md",children:o&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Z,{src:o.image,name:o.name,color:o.color,iconBg:o.iconBg,size:"sm"}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:o.name}),e.jsxs("span",{className:"text-[11px] text-blue-400 font-mono",children:[o.format||"openai"," protocol"]})]})]}),e.jsx("button",{onClick:()=>g(null),className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),a&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-500/10 border border-red-500/20 text-xs text-red-400 flex items-start gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-400 shrink-0 mt-0.5",children:"error"}),e.jsx("span",{children:a})]}),e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Account Label / Nickname"}),e.jsx("input",{type:"text",value:_,onChange:t=>y(t.target.value),placeholder:"e.g. Work Pro Key 1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Base URL Override"}),e.jsx("input",{type:"text",value:h,onChange:t=>j(t.target.value),placeholder:o.format==="anthropic"?"https://api.anthropic.com":o.baseUrl||"https://api.openai.com",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"API Key / Secret Token (AES-256-GCM Hardware Encrypted)"}),e.jsx("input",{type:"password",value:u,onChange:t=>w(t.target.value),placeholder:"sk-...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-[11px] text-slate-400 flex items-start gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-emerald-400 shrink-0 mt-0.5",children:"enhanced_encryption"}),e.jsx("span",{className:"leading-relaxed",children:"Keys are securely locked with your PC's machine ID salt. No cloud upload, no telemetry."})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>g(null),disabled:L,className:"px-4 py-2 text-xs text-slate-400 hover:text-white transition-colors cursor-pointer disabled:opacity-50",children:"Cancel"}),e.jsx("button",{onClick:re,disabled:L,className:"rt-btn rt-btn--primary disabled:opacity-50",children:L?"Saving...":"Save & Connect"})]})]})}),e.jsx(ce,{isOpen:D,existingProviderIds:p.map(t=>t.id),onClose:()=>O(!1),onImportSuccess:async()=>{await S(),Q()}}),e.jsx(ne,{isOpen:!!f,title:"Delete Provider",message:`Are you sure you want to delete "${f==null?void 0:f.name}"? This will permanently remove the provider configuration and all associated accounts/credentials.`,confirmText:W?"Deleting...":"Delete",variant:"danger",onConfirm:le,onCancel:()=>A(null)})]})};export{ge as ProvidersTab};
1
+ import{r as l,j as e}from"./vendor-BcOI2aZ9.js";import{P as ae}from"./index-5TzViNxR.js";import{C as ne}from"./ConfirmModal-BS3mAUd5.js";import{i as Q}from"./ModelAutocompleteInput-DJkxW2yD.js";import{g as X}from"./metadataRegistry-W75_wn57.js";import{T as Z}from"./ToolIcon-Cp4gSgFt.js";import{C as ie,O as ee,F as te,A as se}from"./providersData-BI_7MaUL.js";import"./lucide-Cc35htxl.js";const ce=({isOpen:N,existingProviderIds:z,onClose:o,onImportSuccess:g})=>{const[u,w]=l.useState([]),[_,y]=l.useState(!1),[h,j]=l.useState(""),[p,q]=l.useState("all"),[C,b]=l.useState(null),[I,k]=l.useState(""),[d,T]=l.useState(""),[v,P]=l.useState("Default Account"),[D,O]=l.useState(!1),[f,A]=l.useState(null);l.useEffect(()=>{N&&(y(!0),fetch("/api/providers/community-catalog").then(a=>a.json()).then(a=>{a&&Array.isArray(a.catalog)&&w(a.catalog)}).catch(a=>{console.error("Failed to load community catalog:",a)}).finally(()=>{y(!1)}))},[N]);const W=l.useMemo(()=>{const a=new Set;for(const n of u)n.category&&a.add(n.category);return["all",...Array.from(a).sort()]},[u]),B=l.useMemo(()=>{const a=h.toLowerCase().trim();return u.filter(n=>{var S;return p!=="all"&&n.category!==p?!1:a?n.name.toLowerCase().includes(a)||n.id.toLowerCase().includes(a)||n.baseUrl.toLowerCase().includes(a)||((S=n.models)==null?void 0:S.some(U=>U.id.toLowerCase().includes(a))):!0})},[u,h,p]),L=a=>{b(a),k(a.baseUrl||"https://api.openai.com"),T(""),P("Default Account"),A(null)},$=async()=>{if(C){O(!0),A(null);try{const a=await fetch("/api/providers/community-catalog/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.id,customBaseUrl:I.trim(),apiKey:d.trim()||void 0,accountName:v.trim()||"Default Account"})}),n=await a.json();if(!a.ok||!n.success)throw new Error(n.error||"Failed to import provider");g(C.id),b(null)}catch(a){A(a.message||"Import failed")}finally{O(!1)}}};return N?e.jsx(ae,{isOpen:N,onClose:o,maxWidthClass:"w-full max-w-4xl",children:e.jsxs("div",{className:"relative w-full max-w-4xl bg-[#0B0F19] border border-[#1E293B] rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[88vh]",children:[e.jsxs("div",{className:"p-6 border-b border-[#1E293B] bg-[#0F1420]/70 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-500/10 border border-blue-500/20 flex items-center justify-center text-blue-400",children:e.jsx("span",{className:"material-symbols-outlined text-[22px]",children:"explore"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-white",children:"Community Providers Catalog"}),e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-blue-500/10 border border-blue-500/20 text-blue-400 text-[11px] font-mono",children:[u.length," Available"]})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"Browse on-demand multi-gateways, token resellers, and community inference proxies. Import directly into active providers."})]})]}),e.jsx("button",{onClick:o,className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-white/5 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsxs("div",{className:"p-4 border-b border-[#1E293B] bg-[#0A0D14]/80 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[240px]",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-2.5 text-slate-500 text-[18px]",children:"search"}),e.jsx("input",{type:"text",value:h,onChange:a=>j(a.target.value),placeholder:"Search community provider by name, ID, endpoint...",className:"w-full pl-9 pr-3 py-2 text-xs bg-[#0F1420] border border-[#1E293B] rounded-xl text-white placeholder-slate-500 focus:outline-none focus:border-blue-500/60 transition-colors"}),h&&e.jsx("button",{onClick:()=>j(""),className:"absolute right-3 top-2.5 text-slate-500 hover:text-white text-xs",children:"✕"})]}),e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1 max-w-full",children:W.map(a=>e.jsx("button",{onClick:()=>q(a),className:`px-2.5 py-1 rounded-lg text-[11px] font-medium capitalize transition-colors cursor-pointer ${p===a?"bg-blue-600 text-white shadow-xs":"bg-[#0F1420] text-slate-400 border border-[#1E293B] hover:text-white"}`,children:a},a))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-2.5 min-h-[300px]",children:_?e.jsxs("div",{className:"py-20 flex flex-col items-center justify-center text-slate-500 text-xs gap-3",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[28px] text-blue-400",children:"sync"}),e.jsx("span",{children:"Loading community catalog..."})]}):B.length===0?e.jsxs("div",{className:"py-16 text-center text-slate-500 text-xs flex flex-col items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[32px] text-slate-600",children:"search_off"}),e.jsx("span",{children:"No community providers match your filter query."})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:B.map(a=>{const n=z.includes(a.id);return e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0F1420]/80 border border-[#1E293B] hover:border-slate-700 transition-all flex flex-col justify-between gap-3 group",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-semibold text-xs text-white",children:a.name}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-[#1E293B] text-slate-400 font-mono",children:a.id})]}),e.jsx("div",{className:"text-[11px] text-slate-500 font-mono truncate max-w-[280px] mt-1",title:a.baseUrl||"Custom Base URL required",children:a.baseUrl||e.jsx("span",{className:"italic text-amber-500/80",children:"Requires custom URL"})})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-mono uppercase font-semibold ${a.format==="claude"?"bg-amber-500/10 text-amber-400 border border-amber-500/20":"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20"}`,children:a.format})})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-3 text-[11px] text-slate-400",children:[a.models&&a.models.length>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-500",children:"memory"}),a.models.length," preset models"]}),a.website&&e.jsxs("a",{href:a.website,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-blue-400/80 hover:text-blue-300 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"open_in_new"}),"Docs"]})]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B]/60 flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-slate-500 capitalize",children:a.category}),n?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-emerald-400 font-medium px-2 py-0.5 rounded bg-emerald-500/10 border border-emerald-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"check_circle"}),"Active"]}):e.jsxs("button",{onClick:()=>L(a),className:"flex items-center gap-1 px-3 py-1 rounded-lg bg-blue-600 hover:bg-blue-500 text-white text-[11px] font-semibold transition-colors cursor-pointer shadow-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"download"}),"Import"]})]})]},a.id)})})}),e.jsxs("div",{className:"p-3 border-t border-[#1E293B] bg-[#0A0D14] flex items-center justify-between text-xs text-slate-500",children:[e.jsxs("span",{children:["Showing ",B.length," of ",u.length," community providers"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-blue-400",children:"info"}),"Imported providers are saved locally in SQLite and support load balancing."]})]}),C&&e.jsx("div",{className:"absolute inset-0 bg-black/75 backdrop-blur-xs flex items-center justify-center p-4 z-50 animate-rt-fade-in",children:e.jsxs("div",{className:"w-full max-w-md bg-[#0F1420] border border-[#1E293B] rounded-2xl p-5 shadow-2xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-[#1E293B] pb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"add_task"}),e.jsxs("h3",{className:"text-sm font-bold text-white",children:["Import ",C.name]})]}),e.jsx("button",{onClick:()=>b(null),className:"text-slate-400 hover:text-white text-xs cursor-pointer",children:"✕"})]}),f&&e.jsxs("div",{className:"p-2.5 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-xs flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"error"}),e.jsx("span",{children:f})]}),e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"Base URL"}),e.jsx("input",{type:"text",value:I,onChange:a=>k(a.target.value),placeholder:"https://api.example.com/v1",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"API endpoint prefix where request completions will be routed."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"Account Name"}),e.jsx("input",{type:"text",value:v,onChange:a=>P(a.target.value),placeholder:"Default Account",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"API Key (Optional)"}),e.jsx("input",{type:"password",value:d,onChange:a=>T(a.target.value),placeholder:"sk-...",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Encrypted with AES-256-GCM hardware vault. You can also configure it later."})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>b(null),disabled:D,className:"px-3.5 py-1.5 rounded-xl border border-[#1E293B] text-slate-400 hover:text-white text-xs font-semibold cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:$,disabled:D||!I.trim(),className:"px-4 py-1.5 rounded-xl bg-blue-600 hover:bg-blue-500 disabled:opacity-50 text-white text-xs font-semibold flex items-center gap-1.5 cursor-pointer shadow-xs",children:D?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[14px]",children:"sync"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"check"}),"Save & Activate"]})})]})]})})]})}):null},ge=({searchQuery:N,onSelectProvider:z})=>{const[o,g]=l.useState(null),[u,w]=l.useState(""),[_,y]=l.useState("Default Account"),[h,j]=l.useState(""),[p,q]=l.useState([]),[C,b]=l.useState(new Set),[I,k]=l.useState({}),[d,T]=l.useState(null),[v,P]=l.useState("all"),[D,O]=l.useState(!1),[f,A]=l.useState(null),[W,B]=l.useState(!1),[L,$]=l.useState(!1),[a,n]=l.useState(null),S=async()=>{try{const t=await fetch("/api/providers");if(t.ok){const s=await t.json(),r=Array.isArray(s)?s.filter(x=>x.id!=="combo"&&x.category!=="composite"):[];q(r)}}catch{}};l.useEffect(()=>{S()},[]);const U=t=>{const s=t.baseUrl||t.defaultBaseUrl||"";return s.startsWith("devin://")||s.startsWith("auggie://")||s.startsWith("zcode://")||s.includes("://")&&s.endsWith("/stdio")},F=t=>U(t)?!1:!!t.noAuth||t.requiresApiKey===!1||t.authType==="none"||t.id==="opencode"||t.id==="oc"||t.id==="ollama-local"||t.id==="lm-studio"||t.id==="jan",G=t=>{const s=p.find(x=>x.id===t),r=X(t);return r&&U(r)?(s==null?void 0:s.accountsCount)??0:t==="opencode"||t==="oc"||s!=null&&s.noAuth||r!=null&&r.noAuth||(r==null?void 0:r.requiresApiKey)===!1||(r==null?void 0:r.authType)==="none"?Math.max(1,(s==null?void 0:s.accountsCount)??0):(s==null?void 0:s.accountsCount)??0},M=t=>{const s=!N||t.name.toLowerCase().includes(N.toLowerCase()),r=G(t.id);return v==="connected"?s&&(r>0||F(t)):v==="not_connected"?s&&r===0&&!F(t):s},re=async()=>{if(o){$(!0),n(null);try{const t=p.find(s=>s.id===o.id);if(!t||h.trim()&&h.trim()!==t.baseUrl){const s={id:o.id,name:(t==null?void 0:t.name)||o.name,baseUrl:h.trim()||o.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:(t==null?void 0:t.format)||o.format||"openai"};t&&(s.models=t.models,s.customHeaders=t.customHeaders,s.proxyUrl=t.proxyUrl,s.thinkingMode=t.thinkingMode,s.strategy=t.strategy,s.stickyLimit=t.stickyLimit);const r=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||`Failed to save provider (${r.status})`)}}if(u.trim()||F(o)){const s=await fetch(`/api/providers/${o.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:_||`${o.name} Connection`,apiKey:u.trim()||(o.id==="opencode"||o.id==="oc"?"public":"")})});if(!s.ok){const r=await s.json().catch(()=>({}));throw new Error(r.error||`Failed to add account (${s.status})`)}}await S(),Q(),w(""),y("Default Account"),j(""),n(null),g(null)}catch(t){console.error(t),n(t.message||"Failed to save connection.")}finally{$(!1)}}},H=async t=>{b(s=>new Set(s).add(t));try{const r=await(await fetch(`/api/providers/${t}/test`,{method:"POST"})).json();k(x=>({...x,[t]:{success:!!r.success,msg:r.message||(r.success?"Connected successfully":"Connection failed"),latencyMs:r.latencyMs}}))}catch(s){k(r=>({...r,[t]:{success:!1,msg:s.message||"Failed to reach gateway"}}))}finally{b(s=>{const r=new Set(s);return r.delete(t),r})}},J=async(t,s)=>{const r=t.filter(c=>G(c.id)>0||F(c));if(r.length===0){alert(`No configured or ready accounts found in ${s}.`);return}T(s);const x=r.map(c=>c.id);b(c=>{const m=new Set(c);return x.forEach(i=>m.add(i)),m});try{const c=await fetch("/api/providers/test-bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerIds:x})});if(c.ok){const m=await c.json();m.results&&k(i=>{const E={...i};for(const[oe,K]of Object.entries(m.results))E[oe]={success:!!K.success,msg:K.message||(K.success?"Connected successfully":"Connection failed"),latencyMs:K.latencyMs};return E})}else for(const m of r)await H(m.id)}catch{for(const c of r)await H(c.id)}finally{b(c=>{const m=new Set(c);return x.forEach(i=>m.delete(i)),m}),T(null)}},le=async()=>{if(f){B(!0);try{(await fetch(`/api/providers/${f.id}`,{method:"DELETE"})).ok&&(await S(),Q())}catch{}finally{B(!1),A(null)}}},Y=new Set(ie.map(t=>t.id)),V=p.filter(t=>!Y.has(t.id)).map(t=>{const s=X(t.id);return{id:t.id,name:t.name,image:(s==null?void 0:s.image)||(t.format==="anthropic"?"/assets/providers/anthropic/icon.png":"/assets/providers/openai/icon.png"),color:(s==null?void 0:s.color)||(t.format==="anthropic"?"#D97706":"#10A37F"),iconBg:(s==null?void 0:s.iconBg)||"#ffffff",category:"custom",format:t.format||"openai",baseUrl:t.baseUrl,models:t.models,thinkingMode:t.thinkingMode}}),R=(t,s=!1)=>{const r=t.category==="custom"||!Y.has(t.id),x=!!s&&r,c=G(t.id),m=C.has(t.id),i=I[t.id];return e.jsxs("div",{onClick:()=>z(t),className:"rt-card stagger-item group flex flex-col justify-between cursor-pointer relative overflow-hidden min-w-[300px] hover:border-blue-500/30 transition-all",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(Z,{src:t.image,name:t.name,color:t.color,iconBg:t.iconBg,size:"md",className:"group-hover:border-blue-500/40 transition-colors shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"text-xs font-bold text-slate-100 truncate group-hover:text-blue-400 transition-colors",children:t.name}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5 flex-wrap",children:[U(t)?e.jsx("span",{className:"rt-badge rt-badge--muted text-[10px]",children:"CLI Bridge"}):F(t)?e.jsxs("span",{className:"rt-badge rt-badge--success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"}),t.isLocal?"Ready (Local)":"Ready (Free)"]}):c>0?e.jsxs("span",{className:"rt-badge rt-badge--success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400 animate-pulse"}),c," Connected"]}):e.jsx("span",{className:"rt-badge rt-badge--muted",children:"No connections"}),i&&e.jsx("span",{className:`rt-badge text-[10px] ${i.success?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,title:i.msg,children:i.success?`● ${i.latencyMs?`${i.latencyMs}ms`:"Active"}`:"● Error"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:E=>{E.stopPropagation(),H(t.id)},disabled:m,title:"Test Connection",className:"p-2 rounded-lg bg-white/5 hover:bg-blue-500/20 text-slate-400 hover:text-blue-400 transition-colors cursor-pointer",children:e.jsx("span",{className:`material-symbols-outlined text-[16px] ${m?"animate-spin text-blue-400":""}`,children:m?"sync":"speed"})}),x&&e.jsx("button",{onClick:E=>{E.stopPropagation(),A(t)},title:"Delete Provider",className:"p-2 rounded-lg bg-white/5 hover:bg-red-500/20 text-slate-400 hover:text-red-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})]})]}),i&&e.jsx("div",{className:`w-full py-1 px-3 text-[10px] font-mono border-t truncate ${i.success?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-red-500/10 text-red-400 border-red-500/20"}`,title:i.msg,children:i.success?`✓ ${i.msg}`:`✗ ${i.msg}`})]},t.id)};return e.jsxs("div",{className:"space-y-8 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4 rounded-2xl bg-[#0F1420]/70 border border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("span",{className:"font-semibold text-slate-300",children:"Filter Status:"}),e.jsxs("div",{className:"flex items-center bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B]",children:[e.jsx("button",{onClick:()=>P("all"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="all"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"All Providers"}),e.jsx("button",{onClick:()=>P("connected"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="connected"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Connected Only"}),e.jsx("button",{onClick:()=>P("not_connected"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="not_connected"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Unconfigured"})]})]}),e.jsxs("div",{className:"text-xs text-slate-400 font-mono flex items-center gap-2",children:[e.jsx("span",{children:"Active Accounts:"}),e.jsx("span",{className:"px-2 py-0.5 rounded-md bg-blue-500/10 text-blue-400 border border-blue-500/20 font-bold",children:p.reduce((t,s)=>t+(s.accountsCount||0),0)})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"add_circle"}),"Custom Providers (OpenAI & Anthropic Compatible)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>{w(""),y("Default Account"),j("https://api.anthropic.com"),g({id:`custom-anthropic-${Date.now().toString().slice(-4)}`,name:"Custom Anthropic",image:"/assets/providers/anthropic/icon.png",category:"custom",format:"anthropic",baseUrl:"https://api.anthropic.com"})},className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add Anthropic Compatible"]}),e.jsxs("button",{onClick:()=>{w(""),y("Default Account"),j("https://api.openai.com"),g({id:`custom-openai-${Date.now().toString().slice(-4)}`,name:"Custom OpenAI",image:"/assets/providers/openai/icon.png",category:"custom",format:"openai",baseUrl:"https://api.openai.com"})},className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add OpenAI Compatible"]}),e.jsxs("button",{onClick:()=>O(!0),className:"rt-btn rt-btn--secondary hover:border-blue-500/50",title:"Browse 124 community-curated routers & gateways",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[16px]",children:"explore"}),"Community Catalog"]})]})]}),V.filter(M).length>0?e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:V.filter(M).map(t=>R(t,!0))}):e.jsxs("div",{className:"border border-dashed border-[#1E293B] bg-[#0E1320]/60 rounded-2xl p-5 text-center text-xs text-slate-400 flex items-center justify-center gap-2 hover:border-blue-500/30 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"cloud_sync"}),e.jsx("span",{children:V.length>0?"No custom providers match the current filter.":"Use the buttons above to register self-hosted vLLM, Ollama, LM Studio, or local API proxies."})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"verified"}),"OAuth & Managed IDE Providers"]}),e.jsxs("button",{onClick:()=>J(ee,"OAuth Providers"),disabled:d==="OAuth Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="OAuth Providers"?"animate-spin text-blue-400":""}`,children:d==="OAuth Providers"?"sync":"play_arrow"}),d==="OAuth Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:ee.filter(M).map(t=>R(t,!1))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[18px]",children:"redeem"}),"Free Tier & Community Gateways"]}),e.jsxs("button",{onClick:()=>J(te,"Free Tier Providers"),disabled:d==="Free Tier Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="Free Tier Providers"?"animate-spin text-emerald-400":""}`,children:d==="Free Tier Providers"?"sync":"play_arrow"}),d==="Free Tier Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:te.filter(M).map(t=>R(t,!1))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"key"}),"Direct API Key Providers"]}),e.jsxs("button",{onClick:()=>J(se,"API Key Providers"),disabled:d==="API Key Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="API Key Providers"?"animate-spin text-blue-400":""}`,children:d==="API Key Providers"?"sync":"play_arrow"}),d==="API Key Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:se.filter(M).map(t=>R(t,!1))})]}),e.jsx(ae,{isOpen:!!o,onClose:()=>{g(null),w(""),y("Default Account"),j(""),n(null)},maxWidthClass:"max-w-md",children:o&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Z,{src:o.image,name:o.name,color:o.color,iconBg:o.iconBg,size:"sm"}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:o.name}),e.jsxs("span",{className:"text-[11px] text-blue-400 font-mono",children:[o.format||"openai"," protocol"]})]})]}),e.jsx("button",{onClick:()=>g(null),className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),a&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-500/10 border border-red-500/20 text-xs text-red-400 flex items-start gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-400 shrink-0 mt-0.5",children:"error"}),e.jsx("span",{children:a})]}),e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Account Label / Nickname"}),e.jsx("input",{type:"text",value:_,onChange:t=>y(t.target.value),placeholder:"e.g. Work Pro Key 1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Base URL Override"}),e.jsx("input",{type:"text",value:h,onChange:t=>j(t.target.value),placeholder:o.format==="anthropic"?"https://api.anthropic.com":o.baseUrl||"https://api.openai.com",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"API Key / Secret Token (AES-256-GCM Hardware Encrypted)"}),e.jsx("input",{type:"password",value:u,onChange:t=>w(t.target.value),placeholder:"sk-...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-[11px] text-slate-400 flex items-start gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-emerald-400 shrink-0 mt-0.5",children:"enhanced_encryption"}),e.jsx("span",{className:"leading-relaxed",children:"Keys are securely locked with your PC's machine ID salt. No cloud upload, no telemetry."})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>g(null),disabled:L,className:"px-4 py-2 text-xs text-slate-400 hover:text-white transition-colors cursor-pointer disabled:opacity-50",children:"Cancel"}),e.jsx("button",{onClick:re,disabled:L,className:"rt-btn rt-btn--primary disabled:opacity-50",children:L?"Saving...":"Save & Connect"})]})]})}),e.jsx(ce,{isOpen:D,existingProviderIds:p.map(t=>t.id),onClose:()=>O(!1),onImportSuccess:async()=>{await S(),Q()}}),e.jsx(ne,{isOpen:!!f,title:"Delete Provider",message:`Are you sure you want to delete "${f==null?void 0:f.name}"? This will permanently remove the provider configuration and all associated accounts/credentials.`,confirmText:W?"Deleting...":"Delete",variant:"danger",onConfirm:le,onCancel:()=>A(null)})]})};export{ge as ProvidersTab};
@@ -0,0 +1 @@
1
+ import{j as e,r as h}from"./vendor-BcOI2aZ9.js";import{g as D}from"./metadataRegistry-W75_wn57.js";import{T as V}from"./ToolIcon-Cp4gSgFt.js";import{S as F}from"./Select-BNRH8LIG.js";import{C as Y,E as K}from"./EditAccountModal-BhPOk3Ya.js";import{C as X}from"./ConfirmModal-BS3mAUd5.js";import"./index-5TzViNxR.js";import"./lucide-Cc35htxl.js";const Z={antigravity:["Gemini (5h)","Gemini (Weekly)","Claude & GPT (5h)","Claude & GPT (Weekly)","Gemini 4 Argon (Weekly)"],github:["Chat","Completions","Premium Interactions"],copilot:["Chat","Completions","Premium Interactions"],claude:["5-Hour Window","5h Session","Session","7-Day Window","Weekly"],codex:["Session","Weekly","Credits","Balance"],openai:["Session","Weekly","Credits","Balance"],gemini:["Requests (RPM)","Requests (Daily)","Tokens (TPM)","Tokens (Daily)"],"gemini-cli":["Gemini (5h)","Gemini (Weekly)","Requests (RPM)","Requests (Daily)","Tokens (TPM)","Tokens (Daily)"],grok:["Session","Weekly","Requests","Tokens","Balance"],"grok-cli":["Session","Weekly","Requests","Tokens","Balance"],kiro:["Session","Weekly","Monthly","Credits"],deepseek:["Balance","Total Grants","Topped-up Balance"],minimax:["Coding Tokens","Standard Tokens","Balance"],"minimax-cn":["Coding Tokens","Standard Tokens","Balance"],glm:["Session","Weekly","Balance"],"glm-cn":["Session","Weekly","Balance"],qoder:["Daily","Weekly","Monthly","Balance"],"qoder-cn":["Daily","Weekly","Monthly","Balance"],xkiro:["Session (5h)","Weekly (7d)","Free Tokens (Daily)","Wallet Balance"],"xiaomi-tokenplan":["Monthly Tokens","Weekly Quota"],xmtp:["Monthly Tokens","Weekly Quota"],"xiaomi-mimo":["Monthly Tokens","Weekly Quota"],mimo:["Monthly Tokens","Weekly Quota"],trae:["Dollar Usage","Autocomplete","Fast Requests"]},ee=new Proxy(Z,{get(s,o){if(typeof o!="string")return;const m=o.toLowerCase(),u=D(m);return u!=null&&u.quotaOrder?u.quotaOrder:s[m]},has(s,o){if(typeof o!="string")return!1;const m=o.toLowerCase(),u=D(m);return!!(u!=null&&u.quotaOrder)||m in s}});function te(s,o){if(!o||o.length<=1)return o?[...o]:[];const m=(s||"").toLowerCase(),u=D(m),l=(u==null?void 0:u.quotaOrder)||ee[m]||[];return[...o].sort((g,v)=>{const f=b=>{const i=(b||"").trim().toLowerCase(),d=l.findIndex(y=>{const x=y.toLowerCase();return i===x||i.startsWith(x)||x.startsWith(i)||i.includes(x)});return d===-1?9999:d},j=f(g.label),p=f(v.label);return j!==p?j-p:(g.label||"").localeCompare(v.label||"")})}function re(s,o,m,u){const l=m.toLowerCase(),g=(u==null?void 0:u.toLowerCase())==="kiro",v=l.includes("token"),f=l.includes("credit")||g&&!l.includes("request"),j=l.includes("$")||l.includes("dollar")||l.includes("usd"),p=l.includes("cny")||l.includes("rmb")||l.includes("¥");if(j){const i=d=>`$${d.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return o>0?`${i(s)} / ${i(o)}`:i(s)}if(p){const i=d=>`¥${d.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return o>0?`${i(s)} / ${i(o)}`:i(s)}if(v){if(o>=1e9){const i=`${(o/1e9).toFixed(1)}B`;return`${s>=1e9?`${(s/1e9).toFixed(2)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s.toLocaleString()} / ${i} tokens`}if(o>=1e6){const i=`${(o/1e6).toFixed(0)}M`;return`${s>=1e6?`${(s/1e6).toFixed(2)}M`:s.toLocaleString()} / ${i} tokens`}return o>0?`${s.toLocaleString()} / ${o.toLocaleString()} tokens`:`${s.toLocaleString()} tokens`}if(f){const i=o===1?"credit":"credits";return o>0?`${s.toLocaleString()} / ${o.toLocaleString()} ${i}`:`${s.toLocaleString()} ${i}`}if(l.includes("point")||l.includes("pts")){const i=o===1?"pt":"pts";return o>0?`${s.toLocaleString()} / ${o.toLocaleString()} ${i}`:`${s.toLocaleString()} ${i}`}return l.includes("autocomplete")||l.includes("completion")?o>0?`${s.toLocaleString()} / ${o.toLocaleString()}`:`${s.toLocaleString()}`:o===100&&!l.includes("req")?`${s}% used`:l.includes("req")||l.includes("call")||l.includes("interaction")||l.includes("turn")||l.includes("prompt")||l.includes("session")||l.includes("window")||l.includes("chat")?o>0?`${s.toLocaleString()} / ${o.toLocaleString()} reqs`:`${s.toLocaleString()} reqs`:o>0?`${s.toLocaleString()} / ${o.toLocaleString()}`:`${s.toLocaleString()}`}const se=({label:s,used:o,total:m,percentage:u,resetInText:l="-",unlimited:g=!1,recurring:v=!0,providerId:f})=>{const p=(i=>i>=50?{text:"text-emerald-400",bg:"bg-emerald-500",bgTrack:"bg-emerald-500/15",emoji:"🟢"}:i>0?{text:"text-amber-400",bg:"bg-amber-500",bgTrack:"bg-amber-500/15",emoji:"🟡"}:{text:"text-red-400",bg:"bg-red-500",bgTrack:"bg-red-500/15",emoji:"🔴"})(u),b=v?"Reset":"Expires";return e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-slate-200 truncate pr-2",title:s,children:s}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("span",{className:"text-[10px]",children:p.emoji}),e.jsx("span",{className:`font-semibold ${p.text}`,children:g?"100%":`${u}%`})]})]}),!g&&e.jsx("div",{className:`h-2 rounded-full overflow-hidden ${p.bgTrack} w-full`,children:e.jsx("div",{className:`h-full transition-all duration-300 rounded-full ${p.bg}`,style:{width:`${Math.min(100,Math.max(0,u))}%`}})}),e.jsxs("div",{className:"flex items-center justify-between text-[11px] text-slate-400",children:[e.jsx("span",{children:g?"Unlimited":re(o,m,s,f)}),l&&l!=="-"&&e.jsxs("div",{className:"flex items-center gap-1 font-mono text-[10px] text-slate-400",children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:[b," in ",l]})]})]})]})},ae={antigravity:"#4285F4",gemini:"#1A73E8","gemini-cli":"#1A73E8",claude:"#D97757",codex:"#10A37F",openai:"#10A37F",github:"#24292F",copilot:"#24292F",kiro:"#FF9900",deepseek:"#4D6BFE",grok:"#E11D48","grok-cli":"#E11D48",minimax:"#7C3AED","minimax-cn":"#7C3AED",qoder:"#EC4899","qoder-cn":"#EC4899",glm:"#0055FF","glm-cn":"#0055FF"},P=({account:s,loading:o=!1,onRefresh:m,onEdit:u,onToggle:l})=>{const[g,v]=h.useState(!1),f=D(s.providerId),j=(f==null?void 0:f.color)||ae[s.providerId.toLowerCase()]||"#3B82F6",p=async()=>{if(!(g||o)){v(!0);try{await m(s.accountId)}finally{v(!1)}}},b=o||g,i=h.useMemo(()=>{var x;let d=s.quotas||[];const y=(x=s.providerId)==null?void 0:x.toLowerCase();if(y==="antigravity"||y==="gemini-cli"){const L=["gemini (5h)","gemini (weekly)","claude & gpt (5h)","claude & gpt (weekly)","gemini 4 argon (weekly)"],k=d.filter(C=>L.some(I=>(C.label||"").toLowerCase().trim()===I));k.length>0&&(d=k)}return te(s.providerId,d)},[s.providerId,s.quotas]);return e.jsxs("div",{className:`flex flex-col justify-between bg-[#0F1420]/80 border border-[#1E293B] hover:border-slate-700/80 rounded-2xl p-4 sm:p-5 transition-all duration-200 shadow-lg min-w-[400px] ${s.isActive?"":"opacity-60 bg-[#0B0E17]/60"}`,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 pb-3 border-b border-[#1E293B]/70",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(V,{src:(f==null?void 0:f.image)||`/assets/providers/${s.providerId}/icon.png`,name:s.providerId,color:j,iconBg:f==null?void 0:f.iconBg,size:"md"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-slate-100 text-xs sm:text-sm capitalize truncate",children:s.providerId}),s.plan&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md font-medium bg-blue-500/10 text-blue-400 border border-blue-500/20",children:s.plan})]}),e.jsx("div",{className:"text-[11px] text-slate-400 truncate max-w-[170px]",title:s.accountName,children:s.accountName})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:p,disabled:b,title:"Refresh Quota",className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-[#1E293B]/70 transition-colors disabled:opacity-50 cursor-pointer",children:e.jsx("span",{className:`material-symbols-outlined text-[18px] ${b?"animate-spin text-blue-400":""}`,children:"refresh"})}),e.jsx("button",{onClick:()=>u(s),title:"Edit Account",className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-[#1E293B]/70 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer ml-1",title:"Toggle active status",children:[e.jsx("input",{type:"checkbox",checked:s.isActive,onChange:d=>l(s.accountId,d.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-8 h-4.5 bg-slate-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-all peer-checked:bg-blue-600"})]})]})]}),b&&i.length===0?e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx("div",{className:"h-4 bg-slate-800/60 rounded animate-pulse w-3/4"}),e.jsx("div",{className:"h-2 bg-slate-800/60 rounded-full animate-pulse w-full"}),e.jsx("div",{className:"h-4 bg-slate-800/60 rounded animate-pulse w-2/3"}),e.jsx("div",{className:"h-2 bg-slate-800/60 rounded-full animate-pulse w-full"})]}):i.length>0?e.jsx("div",{className:"space-y-2.5",children:i.map((d,y)=>e.jsx(se,{label:d.label,used:d.used,total:d.total,percentage:d.remainingPercentage,resetInText:d.resetInText,unlimited:d.unlimited,recurring:d.recurring,providerId:s.providerId},`${d.label}-${y}`))}):e.jsx("div",{className:"py-4 text-center text-xs text-slate-400 bg-[#0A0D14]/50 rounded-xl border border-[#1E293B]/50 px-3",children:s.error?e.jsx("span",{className:"text-red-400/90",children:s.error}):s.message||"No quota data available."})]}),e.jsxs("div",{className:"pt-3 mt-2 border-t border-[#1E293B]/50 flex items-center justify-between text-[10px] text-slate-500 font-mono",children:[e.jsx("span",{children:s.isActive?e.jsx("span",{className:"text-emerald-400 font-medium",children:"Active"}):e.jsx("span",{className:"text-slate-400",children:"Inactive"})}),s.lastFetchedAt&&e.jsxs("span",{children:["Updated ",new Date(s.lastFetchedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})},ne=({providers:s,selectedProvider:o,onSelectProvider:m,statusFilter:u,onSelectStatusFilter:l,sortMode:g,onSelectSortMode:v,autoRefresh:f,onToggleAutoRefresh:j,countdownSeconds:p,isRefreshingAll:b,onRefreshAll:i,onTurnOffEmpty:d,onTurnOnAvailable:y})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 text-xs p-4 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] shadow-lg w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx(F,{value:o,onChange:m,options:[{value:"all",label:"All providers"},...s.map(x=>({value:x,label:x.toUpperCase()}))],className:"min-w-[140px]"}),e.jsx(F,{value:u,onChange:x=>l(x),options:[{value:"all",label:"All accounts"},{value:"active",label:"Active only"},{value:"inactive",label:"Turned off"}],className:"min-w-[130px]"}),e.jsx(F,{value:g,onChange:x=>v(x),options:[{value:"fixed",label:"Fixed order (Providers)"},{value:"expiring-first",label:"Expiring first"},{value:"quota-asc",label:"% Quota: low to high"},{value:"quota-desc",label:"% Quota: high to low"}],className:"min-w-[175px]"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsxs("button",{onClick:d,title:"Turn off all accounts with depleted (0%) quota",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl border border-red-500/20 bg-red-500/10 text-red-400 hover:bg-red-500/20 transition-colors cursor-pointer font-medium active:scale-95",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"block"}),"Turn off Empty"]}),e.jsxs("button",{onClick:y,title:"Turn on accounts with available (>0%) quota",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl border border-emerald-500/20 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20 transition-colors cursor-pointer font-medium active:scale-95",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check_circle"}),"Turn on Available"]}),e.jsxs("div",{className:"flex items-center gap-2 bg-[#0A0D14] border border-[#1E293B] px-3 py-1.5 rounded-xl select-none",children:[e.jsx(Y,{size:"sm",checked:f,onChange:x=>j(x),label:"Autorefresh"}),f&&e.jsxs("span",{className:"font-mono text-[10px] text-blue-400 font-semibold bg-blue-500/10 px-1.5 py-0.5 rounded border border-blue-500/20",children:[p,"s"]})]}),e.jsx("button",{onClick:i,disabled:b,title:"Refresh all quotas",className:"p-1.5 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-slate-400 hover:text-white hover:border-slate-600 transition-colors cursor-pointer disabled:opacity-50",children:e.jsx("span",{className:`material-symbols-outlined text-[17px] ${b?"animate-spin text-blue-400":""}`,children:"refresh"})})]})]}),R=60,W="mapigate_cached_quota_accounts",_="mapigate_quota_sort_mode",pe=({searchQuery:s=""})=>{const[o,m]=h.useState(()=>{try{const a=localStorage.getItem(W);if(a){const r=JSON.parse(a);if(Array.isArray(r)&&r.length>0)return r}}catch{}return[]}),[u,l]=h.useState(()=>o.length===0),[g,v]=h.useState(!1),[f,j]=h.useState("all"),[p,b]=h.useState("all"),[i,d]=h.useState(()=>{try{const a=localStorage.getItem(_);if(a==="fixed"||a==="expiring-first"||a==="quota-asc"||a==="quota-desc")return a}catch{}return"fixed"}),[y,x]=h.useState(!0),[L,k]=h.useState(R),[C,I]=h.useState(null),[S,$]=h.useState(null),T=h.useCallback(async(a=!1)=>{try{a&&v(!0);const t=await fetch(a?"/api/quota?force=true":"/api/quota");if(!t.ok)throw new Error(`HTTP error ${t.status}`);const n=await t.json();m(n);try{localStorage.setItem(W,JSON.stringify(n))}catch{}}catch(r){console.error("[QuotaTab] Failed to fetch quotas:",r)}finally{l(!1),v(!1)}},[]);h.useEffect(()=>{T(!1).then(()=>{T(!0)})},[T]),h.useEffect(()=>{if(!y)return;const a=setInterval(()=>{document.hidden||k(r=>r<=1?(T(!1),R):r-1)},1e3);return()=>clearInterval(a)},[y,T]);const Q=async()=>{v(!0),k(R),await T(!0)},B=async a=>{try{const r=await fetch(`/api/quota/${a}`);if(!r.ok)throw new Error(`HTTP error ${r.status}`);const t=await r.json();m(n=>n.map(c=>c.accountId===a?{...c,...t,sortOrder:c.sortOrder??t.sortOrder,createdAt:c.createdAt??t.createdAt}:c))}catch(r){console.error(`[QuotaTab] Failed to refresh account ${a}:`,r)}},M=async(a,r)=>{m(t=>t.map(n=>n.accountId===a?{...n,isActive:r}:n));try{(await fetch(`/api/quota/accounts/${a}/toggle`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:r})})).ok||m(n=>n.map(c=>c.accountId===a?{...c,isActive:!r}:c))}catch{m(t=>t.map(n=>n.accountId===a?{...n,isActive:!r}:n))}},G=async a=>{if(!C)return;const r=await fetch(`/api/quota/accounts/${C.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||"Failed to update account.")}const{account:t}=await r.json();t?m(n=>n.map(c=>c.accountId===C.id?t:c)):await T(!0)},U=()=>{const a=o.filter(r=>r.isActive&&r.quotas.length>0&&r.quotas.some(t=>!t.unlimited&&t.remainingPercentage===0));if(a.length===0){alert("No active accounts with depleted (0%) quota found.");return}$({isOpen:!0,title:"Turn off Depleted Accounts",message:`Are you sure you want to turn off ${a.length} account(s) with 0% quota? This will prevent upstream 429 rate limit errors.`,variant:"danger",confirmText:`Turn off (${a.length})`,onConfirm:async()=>{const r=a.map(t=>t.accountId);m(t=>t.map(n=>r.includes(n.accountId)?{...n,isActive:!1}:n)),$(null);try{await fetch("/api/quota/toggle-batch",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:r,isActive:!1})})}catch(t){console.error("[QuotaTab] Failed to turn off depleted accounts:",t)}}})},z=()=>{const a=o.filter(r=>!r.isActive&&r.quotas.length>0&&r.quotas.every(t=>t.unlimited||t.remainingPercentage>0));if(a.length===0){alert("No inactive accounts with available (>0%) quota found.");return}$({isOpen:!0,title:"Turn on Available Accounts",message:`Activate ${a.length} account(s) that have recovered capacity?`,variant:"emerald",confirmText:`Turn on (${a.length})`,onConfirm:async()=>{const r=a.map(t=>t.accountId);m(t=>t.map(n=>r.includes(n.accountId)?{...n,isActive:!0}:n)),$(null);try{await fetch("/api/quota/toggle-batch",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:r,isActive:!0})})}catch(t){console.error("[QuotaTab] Failed to turn on available accounts:",t)}}})},H=h.useMemo(()=>{const a=new Set;return o.forEach(r=>{r.providerId&&a.add(r.providerId.toLowerCase())}),Array.from(a).sort()},[o]),O=h.useMemo(()=>{let a=[...o];if(f!=="all"&&(a=a.filter(r=>r.providerId.toLowerCase()===f.toLowerCase())),p==="active"?a=a.filter(r=>r.isActive):p==="inactive"&&(a=a.filter(r=>!r.isActive)),s.trim()){const r=s.toLowerCase().trim();a=a.filter(t=>t.accountName.toLowerCase().includes(r)||t.providerId.toLowerCase().includes(r)||t.accountId.toLowerCase().includes(r))}if(i==="fixed")a.sort((r,t)=>{const n=r.providerId.localeCompare(t.providerId);if(n!==0)return n;const c=(r.sortOrder??0)-(t.sortOrder??0);if(c!==0)return c;if(r.createdAt&&t.createdAt&&r.createdAt!==t.createdAt)return r.createdAt-t.createdAt;const N=r.accountName.localeCompare(t.accountName);return N!==0?N:r.accountId.localeCompare(t.accountId)});else if(i==="expiring-first"){const r=t=>{const n=t.quotas.map(c=>c.resetAt).filter(c=>typeof c=="number"&&c>0);return n.length>0?Math.min(...n):Number.POSITIVE_INFINITY};a.sort((t,n)=>{const c=r(t)-r(n);if(c!==0)return c;const N=t.providerId.localeCompare(n.providerId);if(N!==0)return N;const w=(t.sortOrder??0)-(n.sortOrder??0);if(w!==0)return w;if(t.createdAt&&n.createdAt&&t.createdAt!==n.createdAt)return t.createdAt-n.createdAt;const A=t.accountName.localeCompare(n.accountName);return A!==0?A:t.accountId.localeCompare(n.accountId)})}else if(i==="quota-asc"){const r=t=>t.quotas.length===0?Number.POSITIVE_INFINITY:Math.min(...t.quotas.map(n=>n.remainingPercentage));a.sort((t,n)=>{const c=r(t)-r(n);if(c!==0)return c;const N=t.providerId.localeCompare(n.providerId);if(N!==0)return N;const w=(t.sortOrder??0)-(n.sortOrder??0);if(w!==0)return w;if(t.createdAt&&n.createdAt&&t.createdAt!==n.createdAt)return t.createdAt-n.createdAt;const A=t.accountName.localeCompare(n.accountName);return A!==0?A:t.accountId.localeCompare(n.accountId)})}else if(i==="quota-desc"){const r=t=>t.quotas.length===0?Number.NEGATIVE_INFINITY:Math.max(...t.quotas.map(n=>n.remainingPercentage));a.sort((t,n)=>{const c=r(n)-r(t);if(c!==0)return c;const N=t.providerId.localeCompare(n.providerId);if(N!==0)return N;const w=(t.sortOrder??0)-(n.sortOrder??0);if(w!==0)return w;if(t.createdAt&&n.createdAt&&t.createdAt!==n.createdAt)return t.createdAt-n.createdAt;const A=t.accountName.localeCompare(n.accountName);return A!==0?A:t.accountId.localeCompare(n.accountId)})}return a},[o,f,p,i,s]),{accountsWithData:E,accountsWithoutData:q}=h.useMemo(()=>{const a=[],r=[];for(const t of O)Array.isArray(t.quotas)&&t.quotas.length>0||t.error?a.push(t):r.push(t);return{accountsWithData:a,accountsWithoutData:r}},[O]),J=a=>{d(a);try{localStorage.setItem(_,a)}catch{}};return e.jsxs("div",{className:"space-y-6 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsx(ne,{providers:H,selectedProvider:f,onSelectProvider:j,statusFilter:p,onSelectStatusFilter:b,sortMode:i,onSelectSortMode:J,autoRefresh:y,onToggleAutoRefresh:x,countdownSeconds:L,isRefreshingAll:g,onRefreshAll:Q,onTurnOffEmpty:U,onTurnOnAvailable:z}),u?e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(400px,1fr))] gap-4 w-full",children:[...Array(6)].map((a,r)=>e.jsxs("div",{className:"bg-[#0F1420]/80 border border-[#1E293B] rounded-2xl p-5 space-y-4 animate-pulse shadow-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 bg-slate-800 rounded-xl"}),e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx("div",{className:"h-4 bg-slate-800 rounded w-1/2"}),e.jsx("div",{className:"h-3 bg-slate-800 rounded w-3/4"})]})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx("div",{className:"h-3 bg-slate-800 rounded w-full"}),e.jsx("div",{className:"h-2 bg-slate-800 rounded-full w-full"}),e.jsx("div",{className:"h-3 bg-slate-800 rounded w-5/6"}),e.jsx("div",{className:"h-2 bg-slate-800 rounded-full w-full"})]})]},r))}):O.length===0?e.jsxs("div",{className:"p-12 text-center rounded-2xl bg-[#0F1420]/50 border border-[#1E293B] text-slate-400 space-y-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[36px] text-slate-500",children:"account_balance_wallet"}),e.jsx("div",{className:"text-sm font-medium text-slate-300",children:"No matching accounts found"}),e.jsx("p",{className:"text-xs text-slate-500 max-w-sm mx-auto",children:o.length===0?"Connect provider accounts in the Providers tab to track real-time quota.":"Try adjusting your provider, status, or search filters above."})]}):e.jsxs("div",{className:"space-y-8 w-full",children:[E.length>0&&e.jsxs("div",{className:"space-y-3",children:[q.length>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-slate-300",children:[e.jsx("span",{className:"size-2 rounded-full bg-emerald-400"}),e.jsxs("span",{children:["Accounts With Quota (",E.length,")"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(400px,1fr))] gap-4 w-full",children:E.map(a=>e.jsx(P,{account:a,onRefresh:B,onEdit:r=>I({id:r.accountId,providerId:r.providerId,name:r.accountName,isActive:r.isActive,providerSpecificData:r.providerSpecificData}),onToggle:M},a.accountId))})]}),q.length>0&&e.jsxs("div",{className:`space-y-3 ${E.length>0?"pt-6 border-t border-[#1E293B]/70":""}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 pb-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-slate-400",children:[e.jsx("span",{className:"size-2 rounded-full bg-slate-500"}),e.jsxs("span",{children:["Accounts Without Quota Data (",q.length,")"]})]}),e.jsx("span",{className:"text-[11px] text-slate-500 font-mono",children:"No active quota or unsupported metrics"})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(400px,1fr))] gap-4 w-full",children:q.map(a=>e.jsx(P,{account:a,onRefresh:B,onEdit:r=>I({id:r.accountId,providerId:r.providerId,name:r.accountName,isActive:r.isActive,providerSpecificData:r.providerSpecificData}),onToggle:M},a.accountId))})]})]}),e.jsx(K,{isOpen:!!C,account:C,onClose:()=>I(null),onSave:G}),S&&e.jsx(X,{isOpen:S.isOpen,title:S.title,message:S.message,variant:S.variant,confirmText:S.confirmText,onConfirm:S.onConfirm,onCancel:()=>$(null)})]})};export{pe as QuotaTab};