omniroute 2.5.2 → 2.5.3
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.
- package/app/.next/BUILD_ID +1 -1
- package/app/.next/app-path-routes-manifest.json +50 -50
- package/app/.next/build-manifest.json +2 -2
- package/app/.next/server/app/(dashboard)/dashboard/a2a/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/agents/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/analytics/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/api-manager/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/audit-log/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/auto-combo/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/cli-tools/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/costs/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/health/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/limits/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/logs/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/mcp/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/media/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/onboarding/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/playground/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/profile/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/settings/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/translator/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/.well-known/agent.json/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/400/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/401/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/403/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/408/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/429/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/500/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/502/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/503/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/_global-error.html +2 -2
- package/app/.next/server/app/_global-error.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/a2a/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/a2a/status/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/a2a/tasks/[id]/cancel/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/a2a/tasks/[id]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/a2a/tasks/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/acp/agents/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/auth/login/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cache/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cache/stats/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/antigravity-mitm/alias/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/antigravity-mitm/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/backups/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/claude-settings/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/cline-settings/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/codex-profiles/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/codex-settings/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/droid-settings/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/guide-settings/[toolId]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/kilo-settings/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/openclaw/auto-order/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/openclaw-settings/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/runtime/[toolId]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cli-tools/status/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cloud/auth/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cloud/credentials/update/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cloud/model/resolve/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/cloud/models/alias/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/combos/[id]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/combos/auto/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/combos/metrics/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/combos/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/combos/test/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/compliance/audit-log/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/db-backups/export/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/db-backups/exportAll/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/db-backups/import/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/db-backups/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/evals/[suiteId]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/evals/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/fallback/chains/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/init/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/keys/[id]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/keys/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/logs/console/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/mcp/audit/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/mcp/audit/stats/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/mcp/sse/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/mcp/status/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/mcp/stream/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/mcp/tools/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/models/alias/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/models/availability/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/models/catalog/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/models/openrouter-catalog/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/models/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/monitoring/health/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/oauth/[provider]/[action]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/oauth/cursor/auto-import/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/oauth/cursor/import/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/oauth/kiro/auto-import/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/oauth/kiro/import/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/oauth/kiro/social-authorize/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/oauth/kiro/social-exchange/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/policies/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/pricing/defaults/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/pricing/models/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/pricing/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/pricing/sync/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/provider-metrics/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/provider-models/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/provider-nodes/[id]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/provider-nodes/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/provider-nodes/validate/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/providers/[id]/models/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/providers/[id]/refresh/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/providers/[id]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/providers/[id]/test/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/providers/client/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/providers/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/providers/test-batch/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/providers/validate/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/rate-limit/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/rate-limits/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/resilience/reset/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/resilience/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/restart/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/background-degradation/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/codex-service-tier/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/combo-defaults/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/ip-filter/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/model-aliases/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/proxy/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/proxy/test/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/require-login/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/system-prompt/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/task-routing/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/settings/thinking-budget/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/shutdown/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/storage/health/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/sync/cloud/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/sync/initialize/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/tags/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/telemetry/summary/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/token-health/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/translator/detect/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/translator/history/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/translator/load/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/translator/save/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/translator/send/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/translator/translate/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/[connectionId]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/analytics/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/budget/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/call-logs/[id]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/call-logs/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/history/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/logs/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/proxy-logs/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/quota/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/usage/request-logs/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/api/chat/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/audio/speech/route.js +1 -1
- package/app/.next/server/app/api/v1/audio/speech/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/audio/transcriptions/route.js +1 -1
- package/app/.next/server/app/api/v1/audio/transcriptions/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/chat/completions/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/completions/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/embeddings/route.js +1 -1
- package/app/.next/server/app/api/v1/embeddings/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/images/generations/route.js +1 -1
- package/app/.next/server/app/api/v1/images/generations/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/messages/count_tokens/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/messages/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/models/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/moderations/route.js +1 -1
- package/app/.next/server/app/api/v1/moderations/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/music/generations/route.js +1 -1
- package/app/.next/server/app/api/v1/music/generations/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/providers/[provider]/chat/completions/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/providers/[provider]/embeddings/route.js +1 -1
- package/app/.next/server/app/api/v1/providers/[provider]/embeddings/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/providers/[provider]/images/generations/route.js +1 -1
- package/app/.next/server/app/api/v1/providers/[provider]/images/generations/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/rerank/route.js +1 -1
- package/app/.next/server/app/api/v1/rerank/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/responses/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1/videos/generations/route.js +1 -1
- package/app/.next/server/app/api/v1/videos/generations/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1beta/models/[...path]/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/v1beta/models/route_client-reference-manifest.js +1 -1
- package/app/.next/server/app/callback/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/docs/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/forbidden/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/forgot-password/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/landing/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/maintenance/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/offline/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/privacy/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/status/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/terms/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app-paths-manifest.json +50 -50
- package/app/.next/server/chunks/1909.js +1 -1
- package/app/.next/server/chunks/2910.js +2 -1
- package/app/.next/server/chunks/4488.js +2 -1
- package/app/.next/server/chunks/5979.js +1 -1
- package/app/.next/server/chunks/7327.js +1 -1
- package/app/.next/server/middleware.js +2 -1
- package/app/.next/server/pages/500.html +2 -2
- package/app/.next/server/server-reference-manifest.js +1 -1
- package/app/.next/server/server-reference-manifest.json +1 -1
- package/app/.next/static/chunks/{5846-5e09930da5f637df.js → 5846-63e1f1f0bd63a6ad.js} +1 -1
- package/app/.next/static/chunks/app/(dashboard)/dashboard/providers/[id]/{page-c311c2074730a9d4.js → page-389538ee27f0e405.js} +1 -1
- package/app/package.json +1 -1
- package/package.json +1 -1
- /package/app/.next/static/{3s5SDPHTqXdRuXH0NTawz → O9lSHUzWYvY1bYZSFuKAJ}/_buildManifest.js +0 -0
- /package/app/.next/static/{3s5SDPHTqXdRuXH0NTawz → O9lSHUzWYvY1bYZSFuKAJ}/_ssgManifest.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2134],{3751:(e,t,r)=>{Promise.resolve().then(r.bind(r,88618))},40993:(e,t,r)=>{"use strict";r.d(t,{Ex:()=>d.default,$n:()=>s.default,Zp:()=>l.default,Qv:()=>n.CardSkeleton,G9:()=>b.default,bQ:()=>C.default,pp:()=>j.default,Qn:()=>N.default,pd:()=>i.default,Mh:()=>y.default,uR:()=>u.default,aF:()=>o.default,rq:()=>m.default,LF:()=>p.default,KN:()=>f.default,Lo:()=>g.default,y7:()=>h.default,Iz:()=>v.default,l6:()=>a.default,lM:()=>c.default,cn:()=>x.default});var s=r(35806),i=r(34422),a=r(42994),l=r(81060),o=r(71361),n=r(92542);r(17705);var d=r(80927),c=r(19790);r(6261),r(55846),r(34243),r(89938),r(99023);var p=r(80178),m=r(85444),u=r(91961);r(25112);var x=r(45624),h=r(37415),f=r(48643),g=r(8287);r(1652);var y=r(92701);r(18150);var b=r(71689),v=r(33709);r(76332);var j=r(66200);r(61580);var N=r(51503);r(54128);var C=r(44638);r(21720),r(97050)},88618:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>y});var s=r(95155),i=r(12115),a=r(67671),l=r(14051),o=r.n(l),n=r(73321),d=r(98500),c=r.n(d),p=r(5772),m=r(50910),u=r(40993),x=r(20909),h=r(81135),f=r(30949);function g(e){let t=e&&"object"==typeof e&&!Array.isArray(e)?e:{};return{use5h:"boolean"!=typeof t.use5h||t.use5h,useWeekly:"boolean"!=typeof t.useWeekly||t.useWeekly}}function y(){let e=(0,n.useParams)(),t=(0,n.useRouter)(),r=e.id,[l,o]=(0,i.useState)([]),[d,y]=(0,i.useState)(!0),[j,k]=(0,i.useState)(null),[w,$]=(0,i.useState)(!1),[R,P]=(0,i.useState)(!1),[M,O]=(0,i.useState)(!1),[I,_]=(0,i.useState)(!1),[K,F]=(0,i.useState)(null),[L,D]=(0,i.useState)(null),[q,U]=(0,i.useState)({}),[z,J]=(0,i.useState)(!1),{copied:W,copy:B}=(0,f.C)(),V=(0,m.c)("providers"),H=(0,a.i)(),Q=(0,i.useRef)(!1),G=(0,i.useRef)(!1),[Z,Y]=(0,i.useState)(null),[X,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(!1),[es,ei]=(0,i.useState)(!1),[ea,el]=(0,i.useState)({current:0,total:0,phase:"idle",status:"",logs:[],error:"",importedCount:0}),eo=j?{id:j.id,name:j.name||("anthropic-compatible"===j.type?V("anthropicCompatibleName"):V("openaiCompatibleName")),color:"anthropic-compatible"===j.type?"#D97757":"#10A37F",textIcon:"anthropic-compatible"===j.type?"AC":"OC",apiType:j.apiType,baseUrl:j.baseUrl,type:j.type}:x.IS[r]||x.zN[r]||x.fg[r],en=!!x.IS[r]||!!x.zN[r],ed=(0,h.KC)(r),ec=(0,x.wG)(r),ep=(0,x.mq)(r),em=(0,x.gb)(r),eu=ep||em,ex=eu?r:ec,eh=eu?j?.prefix||r:ec,ef=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&U(t.aliases||{})}catch(e){console.log("Error fetching aliases:",e)}},[]),eg=(0,i.useCallback)(async()=>{try{let[e,t]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/provider-nodes",{cache:"no-store"})]),s=await e.json(),i=await t.json();if(e.ok){let e=(s.connections||[]).filter(e=>e.provider===r);o(e)}if(t.ok){let e=(i.nodes||[]).find(e=>e.id===r)||null;if(!e&&eu)for(let t=0;t<3;t+=1){await new Promise(e=>setTimeout(e,150));let t=await fetch("/api/provider-nodes",{cache:"no-store"});if(t.ok&&(e=((await t.json()).nodes||[]).find(e=>e.id===r)||null))break}k(e)}}catch(e){console.log("Error fetching connections:",e)}finally{y(!1)}},[r,eu]),ey=async e=>{try{let t=await fetch(`/api/provider-nodes/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),s=await t.json();t.ok&&(k(s.node),await eg(),_(!1))}catch(e){console.log("Error updating provider node:",e)}};(0,i.useEffect)(()=>{eg(),ef(),fetch("/api/settings/proxy").then(e=>e.ok?e.json():null).then(e=>ee(e)).catch(()=>{})},[eg,ef]),(0,i.useEffect)(()=>{d||0!==l.length||!eo||eu||Q.current||G.current||(Q.current=!0,en?$(!0):P(!0))},[d]);let eb=async(e,t,r=ec)=>{let s=`${r}/${e}`;try{let e=await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:s,alias:t})});if(e.ok)await ef();else{let t=await e.json();alert(t.error||V("failedSetAlias"))}}catch(e){console.log("Error setting alias:",e)}},ev=async e=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await ef()}catch(e){console.log("Error deleting alias:",e)}},ej=async e=>{if(confirm(V("deleteConnectionConfirm")))try{(await fetch(`/api/providers/${e}`,{method:"DELETE"})).ok&&o(l.filter(t=>t.id!==e))}catch(e){console.log("Error deleting connection:",e)}},eN=(0,i.useCallback)(()=>{eg(),$(!1)},[eg]),eC=async e=>{try{let t=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,...e})});if(t.ok)return await eg(),P(!1),null;let s=await t.json().catch(()=>({}));return s.error?.message||s.error||V("failedSaveConnection")}catch(e){return console.log("Error saving connection:",e),V("failedSaveConnectionRetry")}},ek=async e=>{try{(await fetch(`/api/providers/${K.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(await eg(),O(!1))}catch(e){console.log("Error updating connection:",e)}},ew=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&o(r=>r.map(r=>r.id===e?{...r,isActive:t}:r))}catch(e){console.log("Error updating connection status:",e)}},eS=async(e,t)=>{try{(await fetch("/api/rate-limits",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({connectionId:e,enabled:t})})).ok&&o(r=>r.map(r=>r.id===e?{...r,rateLimitProtection:t}:r))}catch(e){console.error("Error toggling rate limit:",e)}},eT=async(e,t,r)=>{try{let s=l.find(t=>t.id===e);if(!s)return;let i=s.providerSpecificData&&"object"==typeof s.providerSpecificData?s.providerSpecificData:{},a=i.codexLimitPolicy&&"object"==typeof i.codexLimitPolicy?i.codexLimitPolicy:{},n={...g(a),[t]:r},d=await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerSpecificData:{...i,codexLimitPolicy:n}})});if(!d.ok){let e=await d.json().catch(()=>({}));H.error(e.error||"Failed to update Codex limit policy");return}o(t=>t.map(t=>t.id===e?{...t,providerSpecificData:{...t.providerSpecificData||{},codexLimitPolicy:n}}:t)),H.success("Codex limit policy updated")}catch(e){console.error("Error toggling Codex quota policy:",e),H.error("Failed to update Codex limit policy")}},eE=async e=>{if(e&&!L){D(e);try{let t=await fetch(`/api/providers/${e}/test`,{method:"POST"});if(!t.ok){let e=await t.json().catch(()=>({}));alert(e.error||V("failedRetestConnection"));return}await eg()}catch(e){console.error("Error retesting connection:",e)}finally{D(null)}}},[eA,e$]=(0,i.useState)(null),eR=async e=>{if(!eA){e$(e);try{let t=await fetch(`/api/providers/${e}/refresh`,{method:"POST"}),r=await t.json().catch(()=>({}));t.ok&&r.success?(H.success(V("tokenRefreshed")),await eg()):H.error(r.error||V("tokenRefreshFailed"))}catch(e){console.error("Error refreshing token:",e),H.error(V("tokenRefreshFailed"))}finally{e$(null)}}},eP=async(e,t)=>{if(e&&t)try{let r=t.priority,s=e.priority;r===s&&(r=l.indexOf(e)>l.indexOf(t)?t.priority-.5:t.priority+.5),await Promise.all([fetch(`/api/providers/${e.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:r})}),fetch(`/api/providers/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:s})})]),await eg()}catch(e){console.log("Error swapping priority:",e)}},eM=async()=>{if(et)return;let e=l.find(e=>!1!==e.isActive);if(e){er(!0),ei(!0),el({current:0,total:0,phase:"fetching",status:V("fetchingModels"),logs:[],error:"",importedCount:0});try{let t=await fetch(`/api/providers/${e.id}/models`),s=await t.json();if(!t.ok)return void el(e=>({...e,phase:"error",status:V("failedFetchModels"),error:s.error||V("failedImportModels")}));let i=s.models||[];if(0===i.length)return void el(e=>({...e,phase:"done",status:V("noModelsFound"),logs:[V("noModelsReturnedFromEndpoint")]}));el(e=>({...e,phase:"importing",total:i.length,status:V("importingModelsProgress",{current:0,total:i.length}),logs:[V("foundModelsStartingImport",{count:i.length})]}));let a=0;for(let e=0;e<i.length;e++){let t=i[e],s=t.id||t.name||t.model;if(!s)continue;let l=s.split("/"),o=l[l.length-1];el(t=>({...t,current:e+1,status:V("importingModelsProgress",{current:e+1,total:i.length}),logs:[...t.logs,V("importingModelById",{modelId:s})]})),await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,modelId:s,modelName:t.name||s,source:"imported"})}),q[o]||await eb(s,o,ex),a+=1}await ef(),el(e=>({...e,phase:"done",current:i.length,status:a>0?V("importSuccessCount",{count:a}):V("noNewModelsAddedExisting"),logs:[...e.logs,a>0?V("importDoneCount",{count:a}):V("noNewModelsAdded")],importedCount:a})),a>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(e){console.log("Error importing models:",e),el(t=>({...t,phase:"error",status:V("importFailed"),error:e instanceof Error?e.message:V("unexpectedErrorOccurred")}))}finally{er(!1)}}},eO=async(e,t)=>{ei(!0),el({current:0,total:0,phase:"fetching",status:V("fetchingModels"),logs:[],error:"",importedCount:0});try{let r=(await e()).models||[];if(0===r.length)return void el(e=>({...e,phase:"done",status:V("noModelsFound"),logs:[V("noModelsReturnedFromEndpoint")]}));el(e=>({...e,phase:"importing",total:r.length,status:V("importingModelsProgress",{current:0,total:r.length}),logs:[V("foundModelsStartingImport",{count:r.length})]}));let s=0;for(let e=0;e<r.length;e++){let i=r[e],a=i.id||i.name||i.model;a&&(el(t=>({...t,current:e+1,status:V("importingModelsProgress",{current:e+1,total:r.length}),logs:[...t.logs,V("importingModelById",{modelId:a})]})),await t(i)&&(s+=1))}el(e=>({...e,phase:"done",current:r.length,status:s>0?V("importSuccessCount",{count:s}):V("noNewModelsAdded"),logs:[...e.logs,s>0?V("importDoneCount",{count:s}):V("noNewModelsAdded")],importedCount:s})),s>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(e){console.log("Error importing models:",e),el(t=>({...t,phase:"error",status:V("importFailed"),error:e instanceof Error?e.message:V("unexpectedErrorOccurred")}))}},eI=l.some(e=>!1!==e.isActive);return d?(0,s.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,s.jsx)(u.Qv,{}),(0,s.jsx)(u.Qv,{})]}):eo?(0,s.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)(c(),{href:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),V("backToProviders")]}),(0,s.jsxs)("div",{className:"flex items-center gap-4",children:[(0,s.jsx)("div",{className:"rounded-lg flex items-center justify-center",style:{backgroundColor:`${eo.color}15`},children:z?(0,s.jsx)("span",{className:"text-sm font-bold",style:{color:eo.color},children:eo.textIcon||eo.id.slice(0,2).toUpperCase()}):(0,s.jsx)(p.default,{src:ep&&eo.apiType?"responses"===eo.apiType?"/providers/oai-r.png":"/providers/oai-cc.png":em?"/providers/anthropic-m.png":`/providers/${eo.id}.png`,alt:eo.name,width:48,height:48,className:"object-contain rounded-lg max-w-[48px] max-h-[48px]",sizes:"48px",onError:()=>J(!0)})}),(0,s.jsxs)("div",{children:[eo.website?(0,s.jsxs)("a",{href:eo.website,target:"_blank",rel:"noopener noreferrer",className:"text-3xl font-semibold tracking-tight hover:underline inline-flex items-center gap-2",style:{color:eo.color},children:[eo.name,(0,s.jsx)("span",{className:"material-symbols-outlined text-lg opacity-60",children:"open_in_new"})]}):(0,s.jsx)("h1",{className:"text-3xl font-semibold tracking-tight",children:eo.name}),(0,s.jsx)("p",{className:"text-text-muted",children:V("connectionCountLabel",{count:l.length})})]})]})]}),eu&&j&&(0,s.jsxs)(u.Zp,{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-lg font-semibold",children:em?V("anthropicCompatibleDetails"):V("openaiCompatibleDetails")}),(0,s.jsxs)("p",{className:"text-sm text-text-muted",children:[em?V("messagesApi"):"responses"===j.apiType?V("responsesApi"):V("chatCompletions")," ","\xb7 ",(j.baseUrl||"").replace(/\/$/,""),"/",em?V("messagesPath"):"responses"===j.apiType?V("responsesPath"):V("chatCompletionsPath")]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:()=>P(!0),disabled:l.length>0,children:V("add")}),(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>_(!0),children:V("edit")}),(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"delete",onClick:async()=>{if(confirm(V("deleteCompatibleNodeConfirm",{type:em?V("anthropic"):V("openai")})))try{(await fetch(`/api/provider-nodes/${r}`,{method:"DELETE"})).ok&&t.push("/dashboard/providers")}catch(e){console.log("Error deleting provider node:",e)}},children:V("delete")})]})]}),l.length>0&&(0,s.jsx)("p",{className:"text-sm text-text-muted",children:V("singleConnectionPerCompatible")})]}),(0,s.jsxs)(u.Zp,{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold",children:V("connections")}),(0,s.jsxs)("button",{onClick:()=>Y({level:"provider",id:r,label:eo?.name||r}),className:`inline-flex items-center gap-1 px-2 py-1 rounded text-xs font-medium transition-all ${X?.providers?.[r]?"bg-amber-500/15 text-amber-500 hover:bg-amber-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:X?.providers?.[r]?V("providerProxyTitleConfigured",{host:X.providers[r].host||V("configured")}):V("providerProxyConfigureHint"),children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"vpn_lock"}),X?.providers?.[r]&&X.providers[r].host||V("providerProxy")]})]}),eu?0===l.length&&(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:()=>P(!0),children:V("add")}):(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:()=>en?$(!0):P(!0),children:V("add")})]}),0===l.length?(0,s.jsxs)("div",{className:"text-center py-12",children:[(0,s.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[32px]",children:en?"lock":"key"})}),(0,s.jsx)("p",{className:"text-text-main font-medium mb-1",children:V("noConnectionsYet")}),(0,s.jsx)("p",{className:"text-sm text-text-muted mb-4",children:V("addFirstConnectionHint")}),!eu&&(0,s.jsx)(u.$n,{icon:"add",onClick:()=>en?$(!0):P(!0),children:V("addConnection")})]}):(0,s.jsx)("div",{className:"flex flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:l.sort((e,t)=>(e.priority||0)-(t.priority||0)).map((e,t)=>(0,s.jsx)(S,{connection:e,isOAuth:en,isFirst:0===t,isLast:t===l.length-1,onMoveUp:()=>eP(e,l[t-1]),onMoveDown:()=>eP(e,l[t+1]),onToggleActive:t=>ew(e.id,t),onToggleRateLimit:t=>eS(e.id,t),isCodex:"codex"===r,onToggleCodex5h:t=>eT(e.id,"use5h",t),onToggleCodexWeekly:t=>eT(e.id,"useWeekly",t),onRetest:()=>eE(e.id),isRetesting:L===e.id,onEdit:()=>{F(e),O(!0)},onDelete:()=>ej(e.id),onReauth:en?()=>$(!0):void 0,onRefreshToken:en?()=>eR(e.id):void 0,isRefreshing:eA===e.id,onProxy:()=>Y({level:"key",id:e.id,label:e.name||e.email||e.id}),hasProxy:!!(X?.keys?.[e.id]||X?.providers?.[r]||X?.global),proxySource:X?.keys?.[e.id]?"key":X?.providers?.[r]?"provider":X?.global?"global":null,proxyHost:(X?.keys?.[e.id]||X?.providers?.[r]||X?.global)?.host||null},e.id))})]}),(0,s.jsxs)(u.Zp,{children:[(0,s.jsx)("h2",{className:"text-lg font-semibold mb-4",children:V("availableModels")}),(()=>{if(eu)return(0,s.jsx)(C,{providerStorageAlias:ex,providerDisplayAlias:eh,modelAliases:q,copied:W,onCopy:B,onSetAlias:eb,onDeleteAlias:ev,connections:l,isAnthropic:em,onImportWithProgress:eO});if(eo.passthroughModels)return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"download",onClick:eM,disabled:!eI||et,children:et?V("importingModels"):V("importFromModels")}),!eI&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:V("addConnectionToImport")})]}),(0,s.jsx)(v,{providerAlias:ec,modelAliases:q,copied:W,onCopy:B,onSetAlias:eb,onDeleteAlias:ev})]});let e=(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"download",onClick:eM,disabled:!eI||et,children:et?V("importingModels"):V("importFromModels")}),!eI&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:V("addConnectionToImport")})]});return 0===ed.length?(0,s.jsxs)("div",{children:[e,(0,s.jsx)("p",{className:"text-sm text-text-muted",children:V("noModelsConfigured")})]}):(0,s.jsxs)("div",{children:[e,(0,s.jsx)("div",{className:"flex flex-wrap gap-3",children:ed.map(e=>{let t=`${ex}/${e.id}`,i=`${r}/${e.id}`,a=Object.entries(q).find(([,e])=>e===t||e===i)?.[0];return(0,s.jsx)(b,{model:e,fullModel:`${eh}/${e.id}`,alias:a,copied:W,onCopy:B,onSetAlias:t=>eb(e.id,t,ex),onDeleteAlias:()=>ev(a)},e.id)})})]})})(),!eu&&(0,s.jsx)(N,{providerId:r,providerAlias:eh,copied:W,onCopy:B})]}),"kiro"===r?(0,s.jsx)(u.Mh,{isOpen:w,providerInfo:eo,onSuccess:eN,onClose:()=>{G.current=!0,$(!1)}}):"cursor"===r?(0,s.jsx)(u.G9,{isOpen:w,onSuccess:eN,onClose:()=>{G.current=!0,$(!1)}}):(0,s.jsx)(u.LF,{isOpen:w,provider:r,providerInfo:eo,onSuccess:eN,onClose:()=>{G.current=!0,$(!1)}}),(0,s.jsx)(T,{isOpen:R,provider:r,providerName:eo.name,isCompatible:eu,isAnthropic:em,onSave:eC,onClose:()=>P(!1)}),(0,s.jsx)(E,{isOpen:M,connection:K,onSave:ek,onClose:()=>O(!1)}),eu&&(0,s.jsx)(A,{isOpen:I,node:j,onSave:ey,onClose:()=>_(!1),isAnthropic:em}),Z&&(0,s.jsx)(u.KN,{isOpen:!!Z,onClose:()=>Y(null),level:Z.level,levelId:Z.id,levelLabel:Z.label}),(0,s.jsx)(u.aF,{isOpen:es,onClose:()=>{("done"===ea.phase||"error"===ea.phase)&&ei(!1)},title:V("importingModelsTitle"),size:"md",closeOnOverlay:!1,showCloseButton:"done"===ea.phase||"error"===ea.phase,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:["fetching"===ea.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"importing"===ea.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"done"===ea.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-green-500",children:"check_circle"}),"error"===ea.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-red-500",children:"error"}),(0,s.jsx)("span",{className:"text-sm font-medium text-text-main",children:ea.status})]}),("importing"===ea.phase||"done"===ea.phase)&&ea.total>0&&(0,s.jsxs)("div",{className:"w-full",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:[ea.current," / ",ea.total]}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:[Math.round(ea.current/ea.total*100),"%"]})]}),(0,s.jsx)("div",{className:"w-full h-2.5 bg-black/10 dark:bg-white/10 rounded-full overflow-hidden",children:(0,s.jsx)("div",{className:"h-full rounded-full transition-all duration-300 ease-out",style:{width:`${ea.current/ea.total*100}%`,background:"done"===ea.phase?"linear-gradient(90deg, #22c55e, #16a34a)":"linear-gradient(90deg, var(--color-primary), var(--color-primary-hover, var(--color-primary)))"}})})]}),"fetching"===ea.phase&&(0,s.jsx)("div",{className:"w-full h-2.5 bg-black/10 dark:bg-white/10 rounded-full overflow-hidden",children:(0,s.jsx)("div",{className:"h-full rounded-full animate-pulse",style:{width:"60%",background:"linear-gradient(90deg, var(--color-primary), var(--color-primary-hover, var(--color-primary)))"}})}),"error"===ea.phase&&ea.error&&(0,s.jsx)("div",{className:"p-3 rounded-lg bg-red-500/10 border border-red-500/20",children:(0,s.jsx)("p",{className:"text-sm text-red-400",children:ea.error})}),ea.logs.length>0&&(0,s.jsx)("div",{className:"max-h-48 overflow-y-auto rounded-lg bg-black/5 dark:bg-white/5 p-3 border border-black/5 dark:border-white/5",children:(0,s.jsx)("div",{className:"flex flex-col gap-1",children:ea.logs.map((e,t)=>(0,s.jsx)("p",{className:`text-xs font-mono ${e.startsWith("✓")?"text-green-500 font-semibold":"text-text-muted"}`,children:e},t))})}),"done"===ea.phase&&ea.importedCount>0&&(0,s.jsx)("p",{className:"text-xs text-text-muted text-center animate-pulse",children:V("pageAutoRefresh")})]})})]}):(0,s.jsxs)("div",{className:"text-center py-20",children:[(0,s.jsx)("p",{className:"text-text-muted",children:V("providerNotFound")}),(0,s.jsx)(c(),{href:"/dashboard/providers",className:"text-primary mt-4 inline-block",children:V("backToProviders")})]})}function b({model:e,fullModel:t,alias:r,copied:i,onCopy:a,onSetAlias:l,onDeleteAlias:o}){let n=(0,m.c)("providers");return(0,s.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:"smart_toy"}),(0,s.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:t}),(0,s.jsx)("button",{onClick:()=>a(t,`model-${e.id}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:n("copyModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:i===`model-${e.id}`?"check":"content_copy"})})]})}function v({providerAlias:e,modelAliases:t,copied:r,onCopy:a,onSetAlias:l,onDeleteAlias:o}){let n=(0,m.c)("providers"),[d,c]=(0,i.useState)(""),[p,x]=(0,i.useState)(!1),h=Object.entries(t).filter(([,t])=>t.startsWith(`${e}/`)).map(([t,r])=>({modelId:r.replace(`${e}/`,""),fullModel:r,alias:t})),f=async()=>{let e;if(!d.trim()||p)return;let r=d.trim(),s=(e=r.split("/"))[e.length-1];if(t[s])return void alert(n("aliasExistsAlert",{alias:s}));x(!0);try{await l(r,s),c("")}catch(e){console.log("Error adding model:",e)}finally{x(!1)}};return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)("p",{className:"text-sm text-text-muted",children:n("openRouterAnyModelHint")}),(0,s.jsxs)("div",{className:"flex items-end gap-2",children:[(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("label",{htmlFor:"new-model-input",className:"text-xs text-text-muted mb-1 block",children:n("modelIdFromOpenRouter")}),(0,s.jsx)("input",{id:"new-model-input",type:"text",value:d,onChange:e=>c(e.target.value),onKeyDown:e=>"Enter"===e.key&&f(),placeholder:n("openRouterModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:f,disabled:!d.trim()||p,children:p?n("adding"):n("add")})]}),h.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-3",children:h.map(({modelId:e,fullModel:t,alias:i})=>(0,s.jsx)(j,{modelId:e,fullModel:t,copied:r,onCopy:a,onDeleteAlias:()=>o(i)},t))})]})}function j({modelId:e,fullModel:t,copied:r,onCopy:i,onDeleteAlias:a}){let l=(0,m.c)("providers");return(0,s.jsxs)("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:"smart_toy"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium truncate",children:e}),(0,s.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,s.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:t}),(0,s.jsx)("button",{onClick:()=>i(t,`model-${e}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:l("copyModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:r===`model-${e}`?"check":"content_copy"})})]})]}),(0,s.jsx)("button",{onClick:a,className:"p-1 hover:bg-red-50 rounded text-red-500",title:l("removeModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})}function N({providerId:e,providerAlias:t,copied:r,onCopy:l}){let o=(0,m.c)("providers"),n=(0,a.i)(),[d,c]=(0,i.useState)([]),[p,x]=(0,i.useState)(""),[h,f]=(0,i.useState)(""),[g,y]=(0,i.useState)("chat-completions"),[b,v]=(0,i.useState)(["chat"]),[j,N]=(0,i.useState)(!1),[C,k]=(0,i.useState)(!0),[w,S]=(0,i.useState)(null),[T,E]=(0,i.useState)("chat-completions"),[A,$]=(0,i.useState)(["chat"]),[R,P]=(0,i.useState)(null),M=(0,i.useCallback)(async()=>{try{let t=await fetch(`/api/provider-models?provider=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json();c(e.models||[])}}catch(e){console.error("Failed to fetch custom models:",e)}finally{k(!1)}},[e]);(0,i.useEffect)(()=>{M()},[M]);let O=async()=>{if(p.trim()&&!j){N(!0);try{(await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,modelId:p.trim(),modelName:h.trim()||void 0,apiFormat:g,supportedEndpoints:b})})).ok&&(x(""),f(""),y("chat-completions"),v(["chat"]),await M())}catch(e){console.error("Failed to add custom model:",e)}finally{N(!1)}}},I=async t=>{try{await fetch(`/api/provider-models?provider=${encodeURIComponent(e)}&model=${encodeURIComponent(t)}`,{method:"DELETE"}),await M()}catch(e){console.error("Failed to remove custom model:",e)}},_=()=>{S(null),E("chat-completions"),$(["chat"]),P(null)},K=async t=>{if(w&&w===t){if(!A.length)return void n.error("Select at least one supported endpoint");P(t);try{let r=d.find(e=>e.id===t);if(!(await fetch("/api/provider-models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,modelId:t,modelName:r?.name||t,source:r?.source||"manual",apiFormat:T,supportedEndpoints:A})})).ok)throw Error("Failed to save model endpoint settings");await M(),n.success("Saved model endpoint settings"),_()}catch(e){console.error("Failed to save custom model:",e),n.error("Failed to save model endpoint settings")}finally{P(null)}}};return(0,s.jsxs)("div",{className:"mt-6 pt-6 border-t border-border",children:[(0,s.jsxs)("h3",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-primary",children:"tune"}),o("customModels")]}),(0,s.jsx)("p",{className:"text-xs text-text-muted mb-3",children:o("customModelsHint")}),(0,s.jsxs)("div",{className:"flex flex-col gap-3 mb-3",children:[(0,s.jsxs)("div",{className:"flex items-end gap-2",children:[(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("label",{htmlFor:"custom-model-id",className:"text-xs text-text-muted mb-1 block",children:o("modelId")}),(0,s.jsx)("input",{id:"custom-model-id",type:"text",value:p,onChange:e=>x(e.target.value),onKeyDown:e=>"Enter"===e.key&&O(),placeholder:o("customModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,s.jsxs)("div",{className:"w-40",children:[(0,s.jsx)("label",{htmlFor:"custom-model-name",className:"text-xs text-text-muted mb-1 block",children:o("displayName")}),(0,s.jsx)("input",{id:"custom-model-name",type:"text",value:h,onChange:e=>f(e.target.value),onKeyDown:e=>"Enter"===e.key&&O(),placeholder:o("optional"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:O,disabled:!p.trim()||j,children:j?o("adding"):o("add")})]}),(0,s.jsxs)("div",{className:"flex items-end gap-4 flex-wrap",children:[(0,s.jsxs)("div",{className:"w-48",children:[(0,s.jsx)("label",{htmlFor:"custom-api-format",className:"text-xs text-text-muted mb-1 block",children:"API Format"}),(0,s.jsxs)("select",{id:"custom-api-format",value:g,onChange:e=>y(e.target.value),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[(0,s.jsx)("option",{value:"chat-completions",children:"Chat Completions"}),(0,s.jsx)("option",{value:"responses",children:"Responses API"})]})]}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted mb-1 block",children:"Supported Endpoints"}),(0,s.jsx)("div",{className:"flex items-center gap-3",children:["chat","embeddings","images","audio"].map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-text-main cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:b.includes(e),onChange:t=>{t.target.checked?v(t=>[...t,e]):v(t=>t.filter(t=>t!==e))},className:"rounded border-border"}),"chat"===e?"\uD83D\uDCAC Chat":"embeddings"===e?"\uD83D\uDCD0 Embeddings":"images"===e?"\uD83D\uDDBC️ Images":"\uD83D\uDD0A Audio"]},e))})]})]})]}),C?(0,s.jsx)("p",{className:"text-xs text-text-muted",children:o("loading")}):d.length>0?(0,s.jsx)("div",{className:"flex flex-col gap-2",children:d.map(e=>{let i=`${t}/${e.id}`,a=`custom-${e.id}`;return(0,s.jsxs)("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-primary",children:"tune"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium truncate",children:e.name||e.id}),(0,s.jsxs)("div",{className:"flex items-center gap-1 mt-1 flex-wrap",children:[(0,s.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:i}),(0,s.jsx)("button",{onClick:()=>l(i,a),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:o("copyModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:r===a?"check":"content_copy"})}),"responses"===e.apiFormat&&(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-blue-500/15 text-blue-400 font-medium",children:"Responses"}),e.supportedEndpoints?.includes("embeddings")&&(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-purple-500/15 text-purple-400 font-medium",children:"\uD83D\uDCD0 Embed"}),e.supportedEndpoints?.includes("images")&&(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/15 text-amber-400 font-medium",children:"\uD83D\uDDBC️ Images"}),e.supportedEndpoints?.includes("audio")&&(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-green-500/15 text-green-400 font-medium",children:"\uD83D\uDD0A Audio"})]}),w===e.id&&(0,s.jsxs)("div",{className:"mt-3 p-3 rounded-lg border border-border bg-sidebar/40",children:[(0,s.jsxs)("div",{className:"flex items-end gap-3 flex-wrap",children:[(0,s.jsxs)("div",{className:"w-44",children:[(0,s.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"API Format"}),(0,s.jsxs)("select",{value:T,onChange:e=>E(e.target.value),className:"w-full px-2.5 py-2 text-xs border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[(0,s.jsx)("option",{value:"chat-completions",children:"Chat Completions"}),(0,s.jsx)("option",{value:"responses",children:"Responses API"})]})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted mb-1 block",children:"Supported Endpoints"}),(0,s.jsx)("div",{className:"flex items-center gap-3 flex-wrap",children:["chat","embeddings","images","audio"].map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-text-main cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:A.includes(e),onChange:t=>{t.target.checked?$(t=>t.includes(e)?t:[...t,e]):$(t=>t.filter(t=>t!==e))},className:"rounded border-border"}),"chat"===e?"\uD83D\uDCAC Chat":"embeddings"===e?"\uD83D\uDCD0 Embeddings":"images"===e?"\uD83D\uDDBC️ Images":"\uD83D\uDD0A Audio"]},e))})]})]}),(0,s.jsxs)("div",{className:"mt-3 flex items-center gap-2",children:[(0,s.jsx)(u.$n,{size:"sm",onClick:()=>K(e.id),disabled:R===e.id,children:R===e.id?o("saving"):o("save")}),(0,s.jsx)(u.$n,{size:"sm",variant:"ghost",onClick:_,children:o("cancel")})]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{onClick:()=>{S(e.id),E(e.apiFormat||"chat-completions"),$(Array.isArray(e.supportedEndpoints)&&e.supportedEndpoints.length?e.supportedEndpoints:["chat"])},className:"p-1 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:o("edit"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"edit"})}),(0,s.jsx)("button",{onClick:()=>I(e.id),className:"p-1 hover:bg-red-50 rounded text-red-500",title:o("removeCustomModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})]},e.id)})}):(0,s.jsx)("p",{className:"text-xs text-text-muted",children:o("noCustomModels")})]})}function C({providerStorageAlias:e,providerDisplayAlias:t,modelAliases:r,copied:l,onCopy:o,onSetAlias:n,onDeleteAlias:d,connections:c,isAnthropic:p,onImportWithProgress:x}){let h=(0,m.c)("providers"),[f,g]=(0,i.useState)(""),[y,b]=(0,i.useState)(!1),[v,N]=(0,i.useState)(!1),C=(0,a.i)(),k=Object.entries(r).filter(([,t])=>t.startsWith(`${e}/`)).map(([t,r])=>({modelId:r.replace(`${e}/`,""),fullModel:r,alias:t})),w=e=>{let s,i=(s=e.split("/"))[s.length-1];if(!r[i])return i;let a=`${t}-${i}`;return r[a]?null:a},S=async()=>{if(!f.trim()||y)return;let t=f.trim(),r=w(t);if(!r)return void C.error(h("allSuggestedAliasesExist"));b(!0);try{let s=await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,modelId:t,modelName:t,source:"manual"})});if(!s.ok){let e={};try{e=await s.json()}catch(e){console.error("Failed to parse error response from custom model API:",e)}throw Error(e.error?.message||h("failedSaveCustomModel"))}await n(t,r,e),g(""),C.success(h("modelAddedSuccess",{modelId:t}))}catch(e){console.error("Error adding model:",e),C.error(e instanceof Error?e.message:h("failedAddModelTryAgain"))}finally{b(!1)}},T=async()=>{if(v)return;let t=c.find(e=>!1!==e.isActive);if(t){N(!0);try{await x(async()=>{let e=await fetch(`/api/providers/${t.id}/models`),r=await e.json();if(!e.ok)throw Error(r.error||h("failedImportModels"));return r},async t=>{let r=t.id||t.name||t.model;if(!r)return!1;let s=w(r);return!!s&&((await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,modelId:r,modelName:t.name||r,source:"imported"})})).ok?(await n(r,s,e),!0):(C.error(h("failedSaveImportedModel")),!1))})}catch(e){console.error("Error importing models:",e),C.error(h("failedImportModelsTryAgain"))}finally{N(!1)}}},E=c.some(e=>!1!==e.isActive),A=async(t,r)=>{try{if(!(await fetch(`/api/provider-models?provider=${encodeURIComponent(e)}&model=${encodeURIComponent(t)}`,{method:"DELETE"})).ok)throw Error(h("failedRemoveModelFromDatabase"));await d(r),C.success(h("modelRemovedSuccess"))}catch(e){console.error("Error deleting model:",e),C.error(e instanceof Error?e.message:h("failedDeleteModelTryAgain"))}};return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)("p",{className:"text-sm text-text-muted",children:h("compatibleModelsDescription",{type:p?h("anthropic"):h("openai")})}),(0,s.jsxs)("div",{className:"flex items-end gap-2 flex-wrap",children:[(0,s.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,s.jsx)("label",{htmlFor:"new-compatible-model-input",className:"text-xs text-text-muted mb-1 block",children:h("modelId")}),(0,s.jsx)("input",{id:"new-compatible-model-input",type:"text",value:f,onChange:e=>g(e.target.value),onKeyDown:e=>"Enter"===e.key&&S(),placeholder:p?h("anthropicCompatibleModelPlaceholder"):h("openaiCompatibleModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:S,disabled:!f.trim()||y,children:y?h("adding"):h("add")}),(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"download",onClick:T,disabled:!E||v,children:v?h("importingModels"):h("importFromModels")})]}),!E&&(0,s.jsx)("p",{className:"text-xs text-text-muted",children:h("addConnectionToImport")}),k.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-3",children:k.map(({modelId:e,fullModel:r,alias:i})=>(0,s.jsx)(j,{modelId:e,fullModel:`${t}/${e}`,copied:l,onCopy:o,onDeleteAlias:()=>A(e,i)},r))})]})}function k({until:e}){let[t,r]=(0,i.useState)("");return((0,i.useEffect)(()=>{let t=()=>{let t=new Date(e).getTime()-Date.now();if(t<=0)return void r("");let s=Math.floor(t/1e3);if(s<60)r(`${s}s`);else if(s<3600)r(`${Math.floor(s/60)}m ${s%60}s`);else{let e=Math.floor(s/3600),t=Math.floor(s%3600/60);r(`${e}h ${t}m`)}};t();let s=setInterval(t,1e3);return()=>clearInterval(s)},[e]),t)?(0,s.jsxs)("span",{className:"text-xs text-orange-500 font-mono",children:["⏱ ",t]}):null}b.propTypes={model:o().shape({id:o().string.isRequired}).isRequired,fullModel:o().string.isRequired,alias:o().string,copied:o().string,onCopy:o().func.isRequired},v.propTypes={providerAlias:o().string.isRequired,modelAliases:o().object.isRequired,copied:o().string,onCopy:o().func.isRequired,onSetAlias:o().func.isRequired,onDeleteAlias:o().func.isRequired},j.propTypes={modelId:o().string.isRequired,fullModel:o().string.isRequired,copied:o().string,onCopy:o().func.isRequired,onDeleteAlias:o().func.isRequired},N.propTypes={providerId:o().string.isRequired,providerAlias:o().string.isRequired,copied:o().string,onCopy:o().func.isRequired},C.propTypes={providerStorageAlias:o().string.isRequired,providerDisplayAlias:o().string.isRequired,modelAliases:o().object.isRequired,copied:o().string,onCopy:o().func.isRequired,onSetAlias:o().func.isRequired,onDeleteAlias:o().func.isRequired,connections:o().arrayOf(o().shape({id:o().string,isActive:o().bool})).isRequired,isAnthropic:o().bool,onImportWithProgress:o().func.isRequired},k.propTypes={until:o().string.isRequired};let w={runtime_error:{labelKey:"errorTypeRuntime",variant:"warning"},upstream_auth_error:{labelKey:"errorTypeUpstreamAuth",variant:"error"},auth_missing:{labelKey:"errorTypeMissingCredential",variant:"warning"},token_refresh_failed:{labelKey:"errorTypeRefreshFailed",variant:"warning"},token_expired:{labelKey:"errorTypeTokenExpired",variant:"warning"},upstream_rate_limited:{labelKey:"errorTypeRateLimited",variant:"warning"},upstream_unavailable:{labelKey:"errorTypeUpstreamUnavailable",variant:"error"},network_error:{labelKey:"errorTypeNetworkError",variant:"warning"},unsupported:{labelKey:"errorTypeTestUnsupported",variant:"default"},upstream_error:{labelKey:"errorTypeUpstreamError",variant:"error"}};function S({connection:e,isOAuth:t,isCodex:r,isFirst:a,isLast:l,onMoveUp:o,onMoveDown:n,onToggleActive:d,onToggleRateLimit:c,onToggleCodex5h:p,onToggleCodexWeekly:x,onRetest:h,isRetesting:f,onEdit:y,onDelete:b,onReauth:v,onProxy:j,hasProxy:N,proxySource:C,proxyHost:S,onRefreshToken:T,isRefreshing:E}){let A,$=(0,m.c)("providers"),R=t?e.name||e.email||e.displayName||$("oauthAccount"):e.name,[P,M]=(0,i.useState)(!1),[O,I]=(0,i.useState)(()=>t&&e.expiresAt?Math.floor((new Date(e.expiresAt).getTime()-Date.now())/6e4):null);(0,i.useEffect)(()=>{if(!t||!e.expiresAt)return;let r=setInterval(()=>{I(Math.floor((new Date(e.expiresAt).getTime()-Date.now())/6e4))},3e4);return()=>clearInterval(r)},[t,e.expiresAt]),(0,i.useEffect)(()=>{let t=()=>{M(e.rateLimitedUntil&&new Date(e.rateLimitedUntil).getTime()>Date.now())};t();let r=e.rateLimitedUntil?setInterval(t,1e3):null;return()=>{r&&clearInterval(r)}},[e.rateLimitedUntil]);let _="unavailable"!==e.testStatus||P?e.testStatus:"active",K=function(e,t,r,s){if(!1===e.isActive)return{statusVariant:"default",statusLabel:s("statusDisabled"),errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};if("active"===t||"success"===t)return{statusVariant:"success",statusLabel:s("statusConnected"),errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};let i=function(e,t){if(t)return"upstream_rate_limited";if(e.lastErrorType)return e.lastErrorType;let r=Number(e.errorCode);if(401===r||403===r)return"upstream_auth_error";if(429===r)return"upstream_rate_limited";if(r>=500)return"upstream_unavailable";let s=(e.lastError||"").toLowerCase();return s?s.includes("runtime")||s.includes("not runnable")||s.includes("not installed")||s.includes("healthcheck")?"runtime_error":s.includes("refresh failed")?"token_refresh_failed":s.includes("token expired")||s.includes("expired")?"token_expired":s.includes("invalid api key")||s.includes("token invalid")||s.includes("revoked")||s.includes("access denied")||s.includes("unauthorized")?"upstream_auth_error":s.includes("rate limit")||s.includes("quota")||s.includes("too many requests")||s.includes("429")?"upstream_rate_limited":s.includes("fetch failed")||s.includes("network")||s.includes("timeout")||s.includes("econn")||s.includes("enotfound")?"network_error":s.includes("not supported")?"unsupported":"upstream_error":null}(e,r),a=i&&w[i]||null;return"runtime_error"===i?{statusVariant:"warning",statusLabel:s("statusRuntimeIssue"),errorType:i,errorBadge:a,errorTextClass:"text-yellow-600 dark:text-yellow-400"}:"upstream_auth_error"===i||"auth_missing"===i||"token_refresh_failed"===i||"token_expired"===i?{statusVariant:"error",statusLabel:s("statusAuthFailed"),errorType:i,errorBadge:a,errorTextClass:"text-red-500"}:"upstream_rate_limited"===i?{statusVariant:"warning",statusLabel:s("statusRateLimited"),errorType:i,errorBadge:a,errorTextClass:"text-yellow-600 dark:text-yellow-400"}:"network_error"===i?{statusVariant:"warning",statusLabel:s("statusNetworkIssue"),errorType:i,errorBadge:a,errorTextClass:"text-yellow-600 dark:text-yellow-400"}:"unsupported"===i?{statusVariant:"default",statusLabel:s("statusTestUnsupported"),errorType:i,errorBadge:a,errorTextClass:"text-text-muted"}:{statusVariant:"error",statusLabel:({unavailable:s("statusUnavailable"),failed:s("statusFailed"),error:s("statusError")})[t]||t||s("statusError"),errorType:i,errorBadge:a,errorTextClass:"text-red-500"}}(e,_,P,$),F=!!e.rateLimitProtection,L=g(e.providerSpecificData&&"object"==typeof e.providerSpecificData&&e.providerSpecificData.codexLimitPolicy&&"object"==typeof e.providerSpecificData.codexLimitPolicy?e.providerSpecificData.codexLimitPolicy:{}),D=L.use5h,q=L.useWeekly;return(0,s.jsxs)("div",{className:`group flex items-center justify-between p-3 rounded-lg hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors ${!1===e.isActive?"opacity-60":""}`,children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("button",{onClick:o,disabled:a,className:`p-0.5 rounded ${a?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_up"})}),(0,s.jsx)("button",{onClick:n,disabled:l,className:`p-0.5 rounded ${l?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_down"})})]}),(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:t?"lock":"key"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium truncate",children:R}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[(0,s.jsx)(u.Ex,{variant:K.statusVariant,size:"sm",dot:!0,children:K.statusLabel}),null!==O&&(O<0?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium bg-red-500/15 text-red-500",title:`Token expired: ${e.expiresAt}`,children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"error"}),"expired"]}):O<30?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/15 text-amber-500",title:`Token expires in ${O}m`,children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"warning"}),`~${O}m`]}):null),P&&!1!==e.isActive&&(0,s.jsx)(k,{until:e.rateLimitedUntil}),K.errorBadge&&!1!==e.isActive&&(0,s.jsx)(u.Ex,{variant:K.errorBadge.variant,size:"sm",children:$(K.errorBadge.labelKey)}),e.lastError&&!1!==e.isActive&&(0,s.jsx)("span",{className:`text-xs truncate max-w-[300px] ${K.errorTextClass}`,title:e.lastError,children:e.lastError}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:["#",e.priority]}),e.globalPriority&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:$("autoPriority",{priority:e.globalPriority})}),(0,s.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,s.jsxs)("button",{onClick:()=>c(!F),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${F?"bg-emerald-500/15 text-emerald-500 hover:bg-emerald-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:$(F?"disableRateLimitProtection":"enableRateLimitProtection"),children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"shield"}),$(F?"rateLimitProtected":"rateLimitUnprotected")]}),r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,s.jsxs)("button",{onClick:()=>p?.(!D),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${D?"bg-blue-500/15 text-blue-500 hover:bg-blue-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:"Toggle Codex 5h limit policy",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"timer"}),"5h ",D?"ON":"OFF"]}),(0,s.jsxs)("button",{onClick:()=>x?.(!q),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${q?"bg-violet-500/15 text-violet-500 hover:bg-violet-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:"Toggle Codex weekly limit policy",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"date_range"}),"Weekly ",q?"ON":"OFF"]})]}),N&&(A=$("global"===C?"proxySourceGlobal":"provider"===C?"proxySourceProvider":"proxySourceKey"),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,s.jsxs)("span",{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium ${"global"===C?"bg-emerald-500/15 text-emerald-500":"provider"===C?"bg-amber-500/15 text-amber-500":"bg-blue-500/15 text-blue-500"}`,title:$("proxyConfiguredBySource",{source:A,host:S||$("configured")}),children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"vpn_lock"}),S||$("proxy")]})]}))]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(u.$n,{size:"sm",variant:"ghost",icon:"refresh",loading:f,disabled:!1===e.isActive,onClick:h,className:"!h-7 !px-2 text-xs",title:$("retestAuthentication"),children:$("retest")}),T&&(0,s.jsx)(u.$n,{size:"sm",variant:"ghost",icon:"token",loading:E,disabled:!1===e.isActive||E,onClick:T,className:"!h-7 !px-2 text-xs text-amber-500 hover:text-amber-400",title:"Refresh OAuth token manually",children:"Token"}),(0,s.jsx)(u.lM,{size:"sm",checked:e.isActive??!0,onChange:d,title:$(e.isActive??!0?"disableConnection":"enableConnection")}),(0,s.jsxs)("div",{className:"flex gap-1 ml-1 transition-opacity",children:[v&&(0,s.jsx)("button",{onClick:v,className:"p-2 hover:bg-amber-500/10 rounded text-amber-600 hover:text-amber-500",title:$("reauthenticateConnection"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"passkey"})}),(0,s.jsx)("button",{onClick:y,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",title:$("edit"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),(0,s.jsx)("button",{onClick:j,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",title:$("proxyConfig"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"vpn_lock"})}),(0,s.jsx)("button",{onClick:b,className:"p-2 hover:bg-red-500/10 rounded text-red-500",title:$("deleteConnection"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]})]})}function T({isOpen:e,provider:t,providerName:r,isCompatible:a,isAnthropic:l,onSave:o,onClose:n}){let d=(0,m.c)("providers"),[c,p]=(0,i.useState)({name:"",apiKey:"",priority:1}),[x,h]=(0,i.useState)(!1),[f,g]=(0,i.useState)(null),[y,b]=(0,i.useState)(!1),[v,j]=(0,i.useState)(null),N=async()=>{h(!0),j(null);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:c.apiKey})}),r=await e.json();g(r.valid?"success":"failed")}catch{g("failed")}finally{h(!1)}},C=async()=>{if(t&&c.apiKey){b(!0),j(null);try{let e=!1;try{h(!0),g(null);let r=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:c.apiKey})});e=!!(await r.json()).valid,g(e?"success":"failed")}catch{g("failed")}finally{h(!1)}if(!e)return void j(d("apiKeyValidationFailed"));let r=await o({name:c.name,apiKey:c.apiKey,priority:c.priority,testStatus:"active"});r&&j("string"==typeof r?r:d("failedSaveConnection"))}finally{b(!1)}}};return t?(0,s.jsx)(u.aF,{isOpen:e,title:d("addProviderApiKeyTitle",{provider:r||t}),onClose:n,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(u.pd,{label:d("nameLabel"),value:c.name,onChange:e=>p({...c,name:e.target.value}),placeholder:d("productionKey")}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.pd,{label:d("apiKeyLabel"),type:"password",value:c.apiKey,onChange:e=>p({...c,apiKey:e.target.value}),className:"flex-1"}),(0,s.jsx)("div",{className:"pt-6",children:(0,s.jsx)(u.$n,{onClick:N,disabled:!c.apiKey||x||y,variant:"secondary",children:x?d("checking"):d("check")})})]}),f&&(0,s.jsx)(u.Ex,{variant:"success"===f?"success":"error",children:"success"===f?d("valid"):d("invalid")}),v&&(0,s.jsx)("div",{className:"text-sm text-red-500 bg-red-500/10 border border-red-500/20 rounded-lg px-3 py-2",children:v}),a&&(0,s.jsx)("p",{className:"text-xs text-text-muted",children:l?d("validationChecksAnthropicCompatible",{provider:r||d("anthropicCompatibleName")}):d("validationChecksOpenAiCompatible",{provider:r||d("openaiCompatibleName")})}),(0,s.jsx)(u.pd,{label:d("priorityLabel"),type:"number",value:c.priority,onChange:e=>p({...c,priority:Number.parseInt(e.target.value)||1})}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.$n,{onClick:C,fullWidth:!0,disabled:!c.name||!c.apiKey||y,children:y?d("saving"):d("save")}),(0,s.jsx)(u.$n,{onClick:n,variant:"ghost",fullWidth:!0,children:d("cancel")})]})]})}):null}function E({isOpen:e,connection:t,onSave:r,onClose:a}){let l=(0,m.c)("providers"),[o,n]=(0,i.useState)({name:"",priority:1,apiKey:"",healthCheckInterval:60}),[d,c]=(0,i.useState)(!1),[p,h]=(0,i.useState)(null),[f,g]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null),[v,j]=(0,i.useState)(!1),[N,C]=(0,i.useState)([]),[k,S]=(0,i.useState)("");(0,i.useEffect)(()=>{if(t){n({name:t.name||"",priority:t.priority||1,apiKey:"",healthCheckInterval:t.healthCheckInterval??60});let e=t.providerSpecificData?.extraApiKeys;C(Array.isArray(e)?e:[]),S(""),h(null),b(null)}},[t]);let T=async()=>{if(t?.provider){c(!0),h(null);try{let e=await fetch(`/api/providers/${t.id}/test`,{method:"POST"}),r=await e.json();h({valid:!!r.valid,diagnosis:r.diagnosis||null,message:r.error||null})}catch{h({valid:!1,diagnosis:{type:"network_error"},message:l("failedTestConnection")})}finally{c(!1)}}},E=async()=>{if(t?.provider&&o.apiKey){g(!0),b(null);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t.provider,apiKey:o.apiKey})}),r=await e.json();b(r.valid?"success":"failed")}catch{b("failed")}finally{g(!1)}}},A=async()=>{j(!0);try{let e={name:o.name,priority:o.priority,healthCheckInterval:o.healthCheckInterval};if(!$&&o.apiKey){e.apiKey=o.apiKey;let r="success"===y;if(!r)try{g(!0),b(null);let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t.provider,apiKey:o.apiKey})});r=!!(await e.json()).valid,b(r?"success":"failed")}catch{b("failed")}finally{g(!1)}r&&(e.testStatus="active",e.lastError=null,e.lastErrorAt=null,e.lastErrorType=null,e.lastErrorSource=null,e.errorCode=null,e.rateLimitedUntil=null)}$||(e.providerSpecificData={...t.providerSpecificData||{},extraApiKeys:N.filter(e=>e.trim().length>0)}),await r(e)}finally{j(!1)}};if(!t)return null;let $="oauth"===t.authType,R=(0,x.mq)(t.provider)||(0,x.gb)(t.provider),P=!p?.valid&&p?.diagnosis?.type&&w[p.diagnosis.type]||null;return(0,s.jsx)(u.aF,{isOpen:e,title:l("editConnection"),onClose:a,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(u.pd,{label:l("nameLabel"),value:o.name,onChange:e=>n({...o,name:e.target.value}),placeholder:$?l("accountName"):l("productionKey")}),$&&t.email&&(0,s.jsxs)("div",{className:"bg-sidebar/50 p-3 rounded-lg",children:[(0,s.jsx)("p",{className:"text-sm text-text-muted mb-1",children:l("email")}),(0,s.jsx)("p",{className:"font-medium",children:t.email})]}),$&&(0,s.jsx)(u.pd,{label:l("healthCheckMinutes"),type:"number",value:o.healthCheckInterval,onChange:e=>n({...o,healthCheckInterval:Math.max(0,Number.parseInt(e.target.value)||0)}),hint:l("healthCheckHint")}),(0,s.jsx)(u.pd,{label:l("priorityLabel"),type:"number",value:o.priority,onChange:e=>n({...o,priority:Number.parseInt(e.target.value)||1})}),!$&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.pd,{label:l("apiKeyLabel"),type:"password",value:o.apiKey,onChange:e=>n({...o,apiKey:e.target.value}),placeholder:l("enterNewApiKey"),hint:l("leaveBlankKeepCurrentApiKey"),className:"flex-1"}),(0,s.jsx)("div",{className:"pt-6",children:(0,s.jsx)(u.$n,{onClick:E,disabled:!o.apiKey||f||v,variant:"secondary",children:f?l("checking"):l("check")})})]}),y&&(0,s.jsx)(u.Ex,{variant:"success"===y?"success":"error",children:"success"===y?l("valid"):l("invalid")})]}),!$&&(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)("label",{className:"text-sm font-medium text-text-main",children:["Extra API Keys",(0,s.jsx)("span",{className:"ml-2 text-[11px] font-normal text-text-muted",children:"(round-robin rotation — optional)"})]}),N.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-1.5",children:N.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"flex-1 font-mono text-xs bg-sidebar/50 px-3 py-2 rounded border border-border text-text-muted truncate",children:`Key #${t+2}: ${e.slice(0,6)}...${e.slice(-4)}`}),(0,s.jsx)("button",{onClick:()=>C(N.filter((e,r)=>r!==t)),className:"p-1.5 rounded hover:bg-red-500/10 text-red-400 hover:text-red-500",title:"Remove this key",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]},t))}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("input",{type:"password",value:k,onChange:e=>S(e.target.value),placeholder:"Add another API key...",className:"flex-1 text-sm bg-sidebar/50 border border-border rounded px-3 py-2 text-text-main placeholder:text-text-muted focus:ring-1 focus:ring-primary outline-none",onKeyDown:e=>{"Enter"===e.key&&k.trim()&&(C([...N,k.trim()]),S(""))}}),(0,s.jsx)("button",{onClick:()=>{k.trim()&&(C([...N,k.trim()]),S(""))},disabled:!k.trim(),className:"px-3 py-2 rounded bg-primary/10 text-primary hover:bg-primary/20 disabled:opacity-40 text-sm font-medium",children:"Add"})]}),N.length>0&&(0,s.jsxs)("p",{className:"text-[11px] text-text-muted",children:[N.length+1," keys total — rotating round-robin on each request."]})]}),!R&&(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(u.$n,{onClick:T,variant:"secondary",disabled:d,children:d?l("testing"):l("testConnection")}),p&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.Ex,{variant:p.valid?"success":"error",children:p.valid?l("valid"):l("failed")}),P&&(0,s.jsx)(u.Ex,{variant:P.variant,children:l(P.labelKey)})]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.$n,{onClick:A,fullWidth:!0,disabled:v,children:v?l("saving"):l("save")}),(0,s.jsx)(u.$n,{onClick:a,variant:"ghost",fullWidth:!0,children:l("cancel")})]})]})})}function A({isOpen:e,node:t,onSave:r,onClose:a,isAnthropic:l}){let o=(0,m.c)("providers"),[n,d]=(0,i.useState)({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[c,p]=(0,i.useState)(!1),[x,h]=(0,i.useState)(""),[f,g]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null);(0,i.useEffect)(()=>{t&&d({name:t.name||"",prefix:t.prefix||"",apiType:t.apiType||"chat",baseUrl:t.baseUrl||(l?"https://api.anthropic.com/v1":"https://api.openai.com/v1")})},[t,l]);let v=[{value:"chat",label:o("chatCompletions")},{value:"responses",label:o("responsesApi")}],j=async()=>{if(n.name.trim()&&n.prefix.trim()&&n.baseUrl.trim()){p(!0);try{let e={name:n.name,prefix:n.prefix,baseUrl:n.baseUrl};l||(e.apiType=n.apiType),await r(e)}finally{p(!1)}}},N=async()=>{g(!0);try{let e=await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:n.baseUrl,apiKey:x,type:l?"anthropic-compatible":"openai-compatible"})}),t=await e.json();b(t.valid?"success":"failed")}catch{b("failed")}finally{g(!1)}};return t?(0,s.jsx)(u.aF,{isOpen:e,title:o("editCompatibleTitle",{type:o(l?"anthropic":"openai")}),onClose:a,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(u.pd,{label:o("nameLabel"),value:n.name,onChange:e=>d({...n,name:e.target.value}),placeholder:o("compatibleProdPlaceholder",{type:o(l?"anthropic":"openai")}),hint:o("nameHint")}),(0,s.jsx)(u.pd,{label:o("prefixLabel"),value:n.prefix,onChange:e=>d({...n,prefix:e.target.value}),placeholder:o(l?"anthropicPrefixPlaceholder":"openaiPrefixPlaceholder"),hint:o("prefixHint")}),!l&&(0,s.jsx)(u.l6,{label:o("apiTypeLabel"),options:v,value:n.apiType,onChange:e=>d({...n,apiType:e.target.value})}),(0,s.jsx)(u.pd,{label:o("baseUrlLabel"),value:n.baseUrl,onChange:e=>d({...n,baseUrl:e.target.value}),placeholder:o(l?"anthropicBaseUrlPlaceholder":"openaiBaseUrlPlaceholder"),hint:o("compatibleBaseUrlHint",{type:o(l?"anthropic":"openai")})}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.pd,{label:o("apiKeyForCheck"),type:"password",value:x,onChange:e=>h(e.target.value),className:"flex-1"}),(0,s.jsx)("div",{className:"pt-6",children:(0,s.jsx)(u.$n,{onClick:N,disabled:!x||f||!n.baseUrl.trim(),variant:"secondary",children:o(f?"checking":"check")})})]}),y&&(0,s.jsx)(u.Ex,{variant:"success"===y?"success":"error",children:o("success"===y?"valid":"invalid")}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.$n,{onClick:j,fullWidth:!0,disabled:!n.name.trim()||!n.prefix.trim()||!n.baseUrl.trim()||c,children:o(c?"saving":"save")}),(0,s.jsx)(u.$n,{onClick:a,variant:"ghost",fullWidth:!0,children:o("cancel")})]})]})}):null}S.propTypes={connection:o().shape({id:o().string,name:o().string,email:o().string,displayName:o().string,rateLimitedUntil:o().string,rateLimitProtection:o().bool,testStatus:o().string,isActive:o().bool,priority:o().number,lastError:o().string,lastErrorType:o().string,lastErrorSource:o().string,errorCode:o().oneOfType([o().string,o().number]),globalPriority:o().number,providerSpecificData:o().object}).isRequired,isOAuth:o().bool.isRequired,isCodex:o().bool,isFirst:o().bool.isRequired,isLast:o().bool.isRequired,onMoveUp:o().func.isRequired,onMoveDown:o().func.isRequired,onToggleActive:o().func.isRequired,onToggleRateLimit:o().func.isRequired,onToggleCodex5h:o().func,onToggleCodexWeekly:o().func,onRetest:o().func.isRequired,isRetesting:o().bool,onEdit:o().func.isRequired,onDelete:o().func.isRequired,onReauth:o().func},T.propTypes={isOpen:o().bool.isRequired,provider:o().string,providerName:o().string,isCompatible:o().bool,isAnthropic:o().bool,onSave:o().func.isRequired,onClose:o().func.isRequired},E.propTypes={isOpen:o().bool.isRequired,connection:o().shape({id:o().string,name:o().string,email:o().string,priority:o().number,authType:o().string,provider:o().string}),onSave:o().func.isRequired,onClose:o().func.isRequired},A.propTypes={isOpen:o().bool.isRequired,node:o().shape({id:o().string,name:o().string,prefix:o().string,apiType:o().string,baseUrl:o().string}),onSave:o().func.isRequired,onClose:o().func.isRequired,isAnthropic:o().bool}}},e=>{e.O(0,[8500,3418,9751,8055,1149,5846,647,8441,3794,7358],()=>e(e.s=3751)),_N_E=e.O()}]);
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2134],{3751:(e,t,r)=>{Promise.resolve().then(r.bind(r,88618))},40993:(e,t,r)=>{"use strict";r.d(t,{Ex:()=>d.default,$n:()=>s.default,Zp:()=>l.default,Qv:()=>n.CardSkeleton,G9:()=>b.default,bQ:()=>C.default,pp:()=>j.default,Qn:()=>N.default,pd:()=>i.default,Mh:()=>y.default,uR:()=>u.default,aF:()=>o.default,rq:()=>m.default,LF:()=>p.default,KN:()=>f.default,Lo:()=>g.default,y7:()=>h.default,Iz:()=>v.default,l6:()=>a.default,lM:()=>c.default,cn:()=>x.default});var s=r(35806),i=r(34422),a=r(42994),l=r(81060),o=r(71361),n=r(92542);r(17705);var d=r(80927),c=r(19790);r(6261),r(55846),r(34243),r(89938),r(99023);var p=r(80178),m=r(85444),u=r(91961);r(25112);var x=r(45624),h=r(37415),f=r(48643),g=r(8287);r(1652);var y=r(92701);r(18150);var b=r(71689),v=r(33709);r(76332);var j=r(66200);r(61580);var N=r(51503);r(54128);var C=r(44638);r(21720),r(97050)},88618:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>y});var s=r(95155),i=r(12115),a=r(67671),l=r(14051),o=r.n(l),n=r(73321),d=r(98500),c=r.n(d),p=r(5772),m=r(50910),u=r(40993),x=r(20909),h=r(81135),f=r(30949);function g(e){let t=e&&"object"==typeof e&&!Array.isArray(e)?e:{};return{use5h:"boolean"!=typeof t.use5h||t.use5h,useWeekly:"boolean"!=typeof t.useWeekly||t.useWeekly}}function y(){let e=(0,n.useParams)(),t=(0,n.useRouter)(),r=e.id,[l,o]=(0,i.useState)([]),[d,y]=(0,i.useState)(!0),[j,k]=(0,i.useState)(null),[w,$]=(0,i.useState)(!1),[R,P]=(0,i.useState)(!1),[M,O]=(0,i.useState)(!1),[I,_]=(0,i.useState)(!1),[K,F]=(0,i.useState)(null),[L,D]=(0,i.useState)(null),[q,U]=(0,i.useState)({}),[z,J]=(0,i.useState)(!1),{copied:W,copy:B}=(0,f.C)(),V=(0,m.c)("providers"),H=(0,a.i)(),Q=(0,i.useRef)(!1),G=(0,i.useRef)(!1),[Z,Y]=(0,i.useState)(null),[X,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(!1),[es,ei]=(0,i.useState)(!1),[ea,el]=(0,i.useState)({current:0,total:0,phase:"idle",status:"",logs:[],error:"",importedCount:0}),eo=j?{id:j.id,name:j.name||("anthropic-compatible"===j.type?V("anthropicCompatibleName"):V("openaiCompatibleName")),color:"anthropic-compatible"===j.type?"#D97757":"#10A37F",textIcon:"anthropic-compatible"===j.type?"AC":"OC",apiType:j.apiType,baseUrl:j.baseUrl,type:j.type}:x.IS[r]||x.zN[r]||x.fg[r],en=!!x.IS[r]||!!x.zN[r],ed=(0,h.KC)(r),ec=(0,x.wG)(r),ep=(0,x.mq)(r),em=(0,x.gb)(r),eu=ep||em,ex=eu?r:ec,eh=eu?j?.prefix||r:ec,ef=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&U(t.aliases||{})}catch(e){console.log("Error fetching aliases:",e)}},[]),eg=(0,i.useCallback)(async()=>{try{let[e,t]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/provider-nodes",{cache:"no-store"})]),s=await e.json(),i=await t.json();if(e.ok){let e=(s.connections||[]).filter(e=>e.provider===r);o(e)}if(t.ok){let e=(i.nodes||[]).find(e=>e.id===r)||null;if(!e&&eu)for(let t=0;t<3;t+=1){await new Promise(e=>setTimeout(e,150));let t=await fetch("/api/provider-nodes",{cache:"no-store"});if(t.ok&&(e=((await t.json()).nodes||[]).find(e=>e.id===r)||null))break}k(e)}}catch(e){console.log("Error fetching connections:",e)}finally{y(!1)}},[r,eu]),ey=async e=>{try{let t=await fetch(`/api/provider-nodes/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),s=await t.json();t.ok&&(k(s.node),await eg(),_(!1))}catch(e){console.log("Error updating provider node:",e)}};(0,i.useEffect)(()=>{eg(),ef(),fetch("/api/settings/proxy").then(e=>e.ok?e.json():null).then(e=>ee(e)).catch(()=>{})},[eg,ef]),(0,i.useEffect)(()=>{d||0!==l.length||!eo||eu||Q.current||G.current||(Q.current=!0,en?$(!0):P(!0))},[d]);let eb=async(e,t,r=ec)=>{let s=`${r}/${e}`;try{let e=await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:s,alias:t})});if(e.ok)await ef();else{let t=await e.json();alert(t.error||V("failedSetAlias"))}}catch(e){console.log("Error setting alias:",e)}},ev=async e=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await ef()}catch(e){console.log("Error deleting alias:",e)}},ej=async e=>{if(confirm(V("deleteConnectionConfirm")))try{(await fetch(`/api/providers/${e}`,{method:"DELETE"})).ok&&o(l.filter(t=>t.id!==e))}catch(e){console.log("Error deleting connection:",e)}},eN=(0,i.useCallback)(()=>{eg(),$(!1)},[eg]),eC=async e=>{try{let t=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,...e})});if(t.ok)return await eg(),P(!1),null;let s=await t.json().catch(()=>({}));return s.error?.message||s.error||V("failedSaveConnection")}catch(e){return console.log("Error saving connection:",e),V("failedSaveConnectionRetry")}},ek=async e=>{try{(await fetch(`/api/providers/${K.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(await eg(),O(!1))}catch(e){console.log("Error updating connection:",e)}},ew=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&o(r=>r.map(r=>r.id===e?{...r,isActive:t}:r))}catch(e){console.log("Error updating connection status:",e)}},eS=async(e,t)=>{try{(await fetch("/api/rate-limits",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({connectionId:e,enabled:t})})).ok&&o(r=>r.map(r=>r.id===e?{...r,rateLimitProtection:t}:r))}catch(e){console.error("Error toggling rate limit:",e)}},eT=async(e,t,r)=>{try{let s=l.find(t=>t.id===e);if(!s)return;let i=s.providerSpecificData&&"object"==typeof s.providerSpecificData?s.providerSpecificData:{},a=i.codexLimitPolicy&&"object"==typeof i.codexLimitPolicy?i.codexLimitPolicy:{},n={...g(a),[t]:r},d=await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerSpecificData:{...i,codexLimitPolicy:n}})});if(!d.ok){let e=await d.json().catch(()=>({}));H.error(e.error||"Failed to update Codex limit policy");return}o(t=>t.map(t=>t.id===e?{...t,providerSpecificData:{...t.providerSpecificData||{},codexLimitPolicy:n}}:t)),H.success("Codex limit policy updated")}catch(e){console.error("Error toggling Codex quota policy:",e),H.error("Failed to update Codex limit policy")}},eE=async e=>{if(e&&!L){D(e);try{let t=await fetch(`/api/providers/${e}/test`,{method:"POST"});if(!t.ok){let e=await t.json().catch(()=>({}));alert(e.error||V("failedRetestConnection"));return}await eg()}catch(e){console.error("Error retesting connection:",e)}finally{D(null)}}},[eA,e$]=(0,i.useState)(null),eR=async e=>{if(!eA){e$(e);try{let t=await fetch(`/api/providers/${e}/refresh`,{method:"POST"}),r=await t.json().catch(()=>({}));t.ok&&r.success?(H.success(V("tokenRefreshed")),await eg()):H.error(r.error||V("tokenRefreshFailed"))}catch(e){console.error("Error refreshing token:",e),H.error(V("tokenRefreshFailed"))}finally{e$(null)}}},eP=async(e,t)=>{if(e&&t)try{let r=t.priority,s=e.priority;r===s&&(r=l.indexOf(e)>l.indexOf(t)?t.priority-.5:t.priority+.5),await Promise.all([fetch(`/api/providers/${e.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:r})}),fetch(`/api/providers/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:s})})]),await eg()}catch(e){console.log("Error swapping priority:",e)}},eM=async()=>{if(et)return;let e=l.find(e=>!1!==e.isActive);if(e){er(!0),ei(!0),el({current:0,total:0,phase:"fetching",status:V("fetchingModels"),logs:[],error:"",importedCount:0});try{let t=await fetch(`/api/providers/${e.id}/models`),s=await t.json();if(!t.ok)return void el(e=>({...e,phase:"error",status:V("failedFetchModels"),error:s.error||V("failedImportModels")}));let i=s.models||[];if(0===i.length)return void el(e=>({...e,phase:"done",status:V("noModelsFound"),logs:[V("noModelsReturnedFromEndpoint")]}));el(e=>({...e,phase:"importing",total:i.length,status:V("importingModelsProgress",{current:0,total:i.length}),logs:[V("foundModelsStartingImport",{count:i.length})]}));let a=0;for(let e=0;e<i.length;e++){let t=i[e],s=t.id||t.name||t.model;if(!s)continue;let l=s.split("/"),o=l[l.length-1];el(t=>({...t,current:e+1,status:V("importingModelsProgress",{current:e+1,total:i.length}),logs:[...t.logs,V("importingModelById",{modelId:s})]})),await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,modelId:s,modelName:t.name||s,source:"imported"})}),q[o]||await eb(s,o,ex),a+=1}await ef(),el(e=>({...e,phase:"done",current:i.length,status:a>0?V("importSuccessCount",{count:a}):V("noNewModelsAddedExisting"),logs:[...e.logs,a>0?V("importDoneCount",{count:a}):V("noNewModelsAdded")],importedCount:a})),a>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(e){console.log("Error importing models:",e),el(t=>({...t,phase:"error",status:V("importFailed"),error:e instanceof Error?e.message:V("unexpectedErrorOccurred")}))}finally{er(!1)}}},eO=async(e,t)=>{ei(!0),el({current:0,total:0,phase:"fetching",status:V("fetchingModels"),logs:[],error:"",importedCount:0});try{let r=(await e()).models||[];if(0===r.length)return void el(e=>({...e,phase:"done",status:V("noModelsFound"),logs:[V("noModelsReturnedFromEndpoint")]}));el(e=>({...e,phase:"importing",total:r.length,status:V("importingModelsProgress",{current:0,total:r.length}),logs:[V("foundModelsStartingImport",{count:r.length})]}));let s=0;for(let e=0;e<r.length;e++){let i=r[e],a=i.id||i.name||i.model;a&&(el(t=>({...t,current:e+1,status:V("importingModelsProgress",{current:e+1,total:r.length}),logs:[...t.logs,V("importingModelById",{modelId:a})]})),await t(i)&&(s+=1))}el(e=>({...e,phase:"done",current:r.length,status:s>0?V("importSuccessCount",{count:s}):V("noNewModelsAdded"),logs:[...e.logs,s>0?V("importDoneCount",{count:s}):V("noNewModelsAdded")],importedCount:s})),s>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(e){console.log("Error importing models:",e),el(t=>({...t,phase:"error",status:V("importFailed"),error:e instanceof Error?e.message:V("unexpectedErrorOccurred")}))}},eI=l.some(e=>!1!==e.isActive);return d?(0,s.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,s.jsx)(u.Qv,{}),(0,s.jsx)(u.Qv,{})]}):eo?(0,s.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)(c(),{href:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),V("backToProviders")]}),(0,s.jsxs)("div",{className:"flex items-center gap-4",children:[(0,s.jsx)("div",{className:"rounded-lg flex items-center justify-center",style:{backgroundColor:`${eo.color}15`},children:z?(0,s.jsx)("span",{className:"text-sm font-bold",style:{color:eo.color},children:eo.textIcon||eo.id.slice(0,2).toUpperCase()}):(0,s.jsx)(p.default,{src:ep&&eo.apiType?"responses"===eo.apiType?"/providers/oai-r.png":"/providers/oai-cc.png":em?"/providers/anthropic-m.png":`/providers/${eo.id}.png`,alt:eo.name,width:48,height:48,className:"object-contain rounded-lg max-w-[48px] max-h-[48px]",sizes:"48px",onError:()=>J(!0)})}),(0,s.jsxs)("div",{children:[eo.website?(0,s.jsxs)("a",{href:eo.website,target:"_blank",rel:"noopener noreferrer",className:"text-3xl font-semibold tracking-tight hover:underline inline-flex items-center gap-2",style:{color:eo.color},children:[eo.name,(0,s.jsx)("span",{className:"material-symbols-outlined text-lg opacity-60",children:"open_in_new"})]}):(0,s.jsx)("h1",{className:"text-3xl font-semibold tracking-tight",children:eo.name}),(0,s.jsx)("p",{className:"text-text-muted",children:V("connectionCountLabel",{count:l.length})})]})]})]}),eu&&j&&(0,s.jsxs)(u.Zp,{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-lg font-semibold",children:em?V("anthropicCompatibleDetails"):V("openaiCompatibleDetails")}),(0,s.jsxs)("p",{className:"text-sm text-text-muted",children:[em?V("messagesApi"):"responses"===j.apiType?V("responsesApi"):V("chatCompletions")," ","\xb7 ",(j.baseUrl||"").replace(/\/$/,""),"/",em?V("messagesPath"):"responses"===j.apiType?V("responsesPath"):V("chatCompletionsPath")]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:()=>P(!0),disabled:l.length>0,children:V("add")}),(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>_(!0),children:V("edit")}),(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"delete",onClick:async()=>{if(confirm(V("deleteCompatibleNodeConfirm",{type:em?V("anthropic"):V("openai")})))try{(await fetch(`/api/provider-nodes/${r}`,{method:"DELETE"})).ok&&t.push("/dashboard/providers")}catch(e){console.log("Error deleting provider node:",e)}},children:V("delete")})]})]}),l.length>0&&(0,s.jsx)("p",{className:"text-sm text-text-muted",children:V("singleConnectionPerCompatible")})]}),(0,s.jsxs)(u.Zp,{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold",children:V("connections")}),(0,s.jsxs)("button",{onClick:()=>Y({level:"provider",id:r,label:eo?.name||r}),className:`inline-flex items-center gap-1 px-2 py-1 rounded text-xs font-medium transition-all ${X?.providers?.[r]?"bg-amber-500/15 text-amber-500 hover:bg-amber-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:X?.providers?.[r]?V("providerProxyTitleConfigured",{host:X.providers[r].host||V("configured")}):V("providerProxyConfigureHint"),children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"vpn_lock"}),X?.providers?.[r]&&X.providers[r].host||V("providerProxy")]})]}),eu?0===l.length&&(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:()=>P(!0),children:V("add")}):(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:()=>en?$(!0):P(!0),children:V("add")})]}),0===l.length?(0,s.jsxs)("div",{className:"text-center py-12",children:[(0,s.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[32px]",children:en?"lock":"key"})}),(0,s.jsx)("p",{className:"text-text-main font-medium mb-1",children:V("noConnectionsYet")}),(0,s.jsx)("p",{className:"text-sm text-text-muted mb-4",children:V("addFirstConnectionHint")}),!eu&&(0,s.jsx)(u.$n,{icon:"add",onClick:()=>en?$(!0):P(!0),children:V("addConnection")})]}):(0,s.jsx)("div",{className:"flex flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:l.sort((e,t)=>(e.priority||0)-(t.priority||0)).map((e,t)=>(0,s.jsx)(S,{connection:e,isOAuth:en,isFirst:0===t,isLast:t===l.length-1,onMoveUp:()=>eP(e,l[t-1]),onMoveDown:()=>eP(e,l[t+1]),onToggleActive:t=>ew(e.id,t),onToggleRateLimit:t=>eS(e.id,t),isCodex:"codex"===r,onToggleCodex5h:t=>eT(e.id,"use5h",t),onToggleCodexWeekly:t=>eT(e.id,"useWeekly",t),onRetest:()=>eE(e.id),isRetesting:L===e.id,onEdit:()=>{F(e),O(!0)},onDelete:()=>ej(e.id),onReauth:en?()=>$(!0):void 0,onRefreshToken:en?()=>eR(e.id):void 0,isRefreshing:eA===e.id,onProxy:()=>Y({level:"key",id:e.id,label:e.name||e.email||e.id}),hasProxy:!!(X?.keys?.[e.id]||X?.providers?.[r]||X?.global),proxySource:X?.keys?.[e.id]?"key":X?.providers?.[r]?"provider":X?.global?"global":null,proxyHost:(X?.keys?.[e.id]||X?.providers?.[r]||X?.global)?.host||null},e.id))})]}),(0,s.jsxs)(u.Zp,{children:[(0,s.jsx)("h2",{className:"text-lg font-semibold mb-4",children:V("availableModels")}),(()=>{if(eu)return(0,s.jsx)(C,{providerStorageAlias:ex,providerDisplayAlias:eh,modelAliases:q,copied:W,onCopy:B,onSetAlias:eb,onDeleteAlias:ev,connections:l,isAnthropic:em,onImportWithProgress:eO});if(eo.passthroughModels)return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"download",onClick:eM,disabled:!eI||et,children:et?V("importingModels"):V("importFromModels")}),!eI&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:V("addConnectionToImport")})]}),(0,s.jsx)(v,{providerAlias:ec,modelAliases:q,copied:W,onCopy:B,onSetAlias:eb,onDeleteAlias:ev})]});let e=(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"download",onClick:eM,disabled:!eI||et,children:et?V("importingModels"):V("importFromModels")}),!eI&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:V("addConnectionToImport")})]});return 0===ed.length?(0,s.jsxs)("div",{children:[e,(0,s.jsx)("p",{className:"text-sm text-text-muted",children:V("noModelsConfigured")})]}):(0,s.jsxs)("div",{children:[e,(0,s.jsx)("div",{className:"flex flex-wrap gap-3",children:ed.map(e=>{let t=`${ex}/${e.id}`,i=`${r}/${e.id}`,a=Object.entries(q).find(([,e])=>e===t||e===i)?.[0];return(0,s.jsx)(b,{model:e,fullModel:`${eh}/${e.id}`,alias:a,copied:W,onCopy:B,onSetAlias:t=>eb(e.id,t,ex),onDeleteAlias:()=>ev(a)},e.id)})})]})})(),!eu&&(0,s.jsx)(N,{providerId:r,providerAlias:eh,copied:W,onCopy:B})]}),"kiro"===r?(0,s.jsx)(u.Mh,{isOpen:w,providerInfo:eo,onSuccess:eN,onClose:()=>{G.current=!0,$(!1)}}):"cursor"===r?(0,s.jsx)(u.G9,{isOpen:w,onSuccess:eN,onClose:()=>{G.current=!0,$(!1)}}):(0,s.jsx)(u.LF,{isOpen:w,provider:r,providerInfo:eo,onSuccess:eN,onClose:()=>{G.current=!0,$(!1)}}),(0,s.jsx)(T,{isOpen:R,provider:r,providerName:eo.name,isCompatible:eu,isAnthropic:em,onSave:eC,onClose:()=>P(!1)}),(0,s.jsx)(E,{isOpen:M,connection:K,onSave:ek,onClose:()=>O(!1)}),eu&&(0,s.jsx)(A,{isOpen:I,node:j,onSave:ey,onClose:()=>_(!1),isAnthropic:em}),Z&&(0,s.jsx)(u.KN,{isOpen:!!Z,onClose:()=>Y(null),level:Z.level,levelId:Z.id,levelLabel:Z.label}),(0,s.jsx)(u.aF,{isOpen:es,onClose:()=>{("done"===ea.phase||"error"===ea.phase)&&ei(!1)},title:V("importingModelsTitle"),size:"md",closeOnOverlay:!1,showCloseButton:"done"===ea.phase||"error"===ea.phase,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:["fetching"===ea.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"importing"===ea.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"done"===ea.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-green-500",children:"check_circle"}),"error"===ea.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-red-500",children:"error"}),(0,s.jsx)("span",{className:"text-sm font-medium text-text-main",children:ea.status})]}),("importing"===ea.phase||"done"===ea.phase)&&ea.total>0&&(0,s.jsxs)("div",{className:"w-full",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:[ea.current," / ",ea.total]}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:[Math.round(ea.current/ea.total*100),"%"]})]}),(0,s.jsx)("div",{className:"w-full h-2.5 bg-black/10 dark:bg-white/10 rounded-full overflow-hidden",children:(0,s.jsx)("div",{className:"h-full rounded-full transition-all duration-300 ease-out",style:{width:`${ea.current/ea.total*100}%`,background:"done"===ea.phase?"linear-gradient(90deg, #22c55e, #16a34a)":"linear-gradient(90deg, var(--color-primary), var(--color-primary-hover, var(--color-primary)))"}})})]}),"fetching"===ea.phase&&(0,s.jsx)("div",{className:"w-full h-2.5 bg-black/10 dark:bg-white/10 rounded-full overflow-hidden",children:(0,s.jsx)("div",{className:"h-full rounded-full animate-pulse",style:{width:"60%",background:"linear-gradient(90deg, var(--color-primary), var(--color-primary-hover, var(--color-primary)))"}})}),"error"===ea.phase&&ea.error&&(0,s.jsx)("div",{className:"p-3 rounded-lg bg-red-500/10 border border-red-500/20",children:(0,s.jsx)("p",{className:"text-sm text-red-400",children:ea.error})}),ea.logs.length>0&&(0,s.jsx)("div",{className:"max-h-48 overflow-y-auto rounded-lg bg-black/5 dark:bg-white/5 p-3 border border-black/5 dark:border-white/5",children:(0,s.jsx)("div",{className:"flex flex-col gap-1",children:ea.logs.map((e,t)=>(0,s.jsx)("p",{className:`text-xs font-mono ${e.startsWith("✓")?"text-green-500 font-semibold":"text-text-muted"}`,children:e},t))})}),"done"===ea.phase&&ea.importedCount>0&&(0,s.jsx)("p",{className:"text-xs text-text-muted text-center animate-pulse",children:V("pageAutoRefresh")})]})})]}):(0,s.jsxs)("div",{className:"text-center py-20",children:[(0,s.jsx)("p",{className:"text-text-muted",children:V("providerNotFound")}),(0,s.jsx)(c(),{href:"/dashboard/providers",className:"text-primary mt-4 inline-block",children:V("backToProviders")})]})}function b({model:e,fullModel:t,alias:r,copied:i,onCopy:a,onSetAlias:l,onDeleteAlias:o}){let n=(0,m.c)("providers");return(0,s.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:"smart_toy"}),(0,s.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:t}),(0,s.jsx)("button",{onClick:()=>a(t,`model-${e.id}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:n("copyModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:i===`model-${e.id}`?"check":"content_copy"})})]})}function v({providerAlias:e,modelAliases:t,copied:r,onCopy:a,onSetAlias:l,onDeleteAlias:o}){let n=(0,m.c)("providers"),[d,c]=(0,i.useState)(""),[p,x]=(0,i.useState)(!1),h=Object.entries(t).filter(([,t])=>t.startsWith(`${e}/`)).map(([t,r])=>({modelId:r.replace(`${e}/`,""),fullModel:r,alias:t})),f=async()=>{let e;if(!d.trim()||p)return;let r=d.trim(),s=(e=r.split("/"))[e.length-1];if(t[s])return void alert(n("aliasExistsAlert",{alias:s}));x(!0);try{await l(r,s),c("")}catch(e){console.log("Error adding model:",e)}finally{x(!1)}};return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)("p",{className:"text-sm text-text-muted",children:n("openRouterAnyModelHint")}),(0,s.jsxs)("div",{className:"flex items-end gap-2",children:[(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("label",{htmlFor:"new-model-input",className:"text-xs text-text-muted mb-1 block",children:n("modelIdFromOpenRouter")}),(0,s.jsx)("input",{id:"new-model-input",type:"text",value:d,onChange:e=>c(e.target.value),onKeyDown:e=>"Enter"===e.key&&f(),placeholder:n("openRouterModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:f,disabled:!d.trim()||p,children:p?n("adding"):n("add")})]}),h.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-3",children:h.map(({modelId:e,fullModel:t,alias:i})=>(0,s.jsx)(j,{modelId:e,fullModel:t,copied:r,onCopy:a,onDeleteAlias:()=>o(i)},t))})]})}function j({modelId:e,fullModel:t,copied:r,onCopy:i,onDeleteAlias:a}){let l=(0,m.c)("providers");return(0,s.jsxs)("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:"smart_toy"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium truncate",children:e}),(0,s.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,s.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:t}),(0,s.jsx)("button",{onClick:()=>i(t,`model-${e}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:l("copyModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:r===`model-${e}`?"check":"content_copy"})})]})]}),(0,s.jsx)("button",{onClick:a,className:"p-1 hover:bg-red-50 rounded text-red-500",title:l("removeModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})}function N({providerId:e,providerAlias:t,copied:r,onCopy:l}){let o=(0,m.c)("providers"),n=(0,a.i)(),[d,c]=(0,i.useState)([]),[p,x]=(0,i.useState)(""),[h,f]=(0,i.useState)(""),[g,y]=(0,i.useState)("chat-completions"),[b,v]=(0,i.useState)(["chat"]),[j,N]=(0,i.useState)(!1),[C,k]=(0,i.useState)(!0),[w,S]=(0,i.useState)(null),[T,E]=(0,i.useState)("chat-completions"),[A,$]=(0,i.useState)(["chat"]),[R,P]=(0,i.useState)(null),M=(0,i.useCallback)(async()=>{try{let t=await fetch(`/api/provider-models?provider=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json();c(e.models||[])}}catch(e){console.error("Failed to fetch custom models:",e)}finally{k(!1)}},[e]);(0,i.useEffect)(()=>{M()},[M]);let O=async()=>{if(p.trim()&&!j){N(!0);try{(await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,modelId:p.trim(),modelName:h.trim()||void 0,apiFormat:g,supportedEndpoints:b})})).ok&&(x(""),f(""),y("chat-completions"),v(["chat"]),await M())}catch(e){console.error("Failed to add custom model:",e)}finally{N(!1)}}},I=async t=>{try{await fetch(`/api/provider-models?provider=${encodeURIComponent(e)}&model=${encodeURIComponent(t)}`,{method:"DELETE"}),await M()}catch(e){console.error("Failed to remove custom model:",e)}},_=()=>{S(null),E("chat-completions"),$(["chat"]),P(null)},K=async t=>{if(w&&w===t){if(!A.length)return void n.error("Select at least one supported endpoint");P(t);try{let r=d.find(e=>e.id===t);if(!(await fetch("/api/provider-models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,modelId:t,modelName:r?.name||t,source:r?.source||"manual",apiFormat:T,supportedEndpoints:A})})).ok)throw Error("Failed to save model endpoint settings");await M(),n.success("Saved model endpoint settings"),_()}catch(e){console.error("Failed to save custom model:",e),n.error("Failed to save model endpoint settings")}finally{P(null)}}};return(0,s.jsxs)("div",{className:"mt-6 pt-6 border-t border-border",children:[(0,s.jsxs)("h3",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-primary",children:"tune"}),o("customModels")]}),(0,s.jsx)("p",{className:"text-xs text-text-muted mb-3",children:o("customModelsHint")}),(0,s.jsxs)("div",{className:"flex flex-col gap-3 mb-3",children:[(0,s.jsxs)("div",{className:"flex items-end gap-2",children:[(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("label",{htmlFor:"custom-model-id",className:"text-xs text-text-muted mb-1 block",children:o("modelId")}),(0,s.jsx)("input",{id:"custom-model-id",type:"text",value:p,onChange:e=>x(e.target.value),onKeyDown:e=>"Enter"===e.key&&O(),placeholder:o("customModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,s.jsxs)("div",{className:"w-40",children:[(0,s.jsx)("label",{htmlFor:"custom-model-name",className:"text-xs text-text-muted mb-1 block",children:o("displayName")}),(0,s.jsx)("input",{id:"custom-model-name",type:"text",value:h,onChange:e=>f(e.target.value),onKeyDown:e=>"Enter"===e.key&&O(),placeholder:o("optional"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:O,disabled:!p.trim()||j,children:j?o("adding"):o("add")})]}),(0,s.jsxs)("div",{className:"flex items-end gap-4 flex-wrap",children:[(0,s.jsxs)("div",{className:"w-48",children:[(0,s.jsx)("label",{htmlFor:"custom-api-format",className:"text-xs text-text-muted mb-1 block",children:"API Format"}),(0,s.jsxs)("select",{id:"custom-api-format",value:g,onChange:e=>y(e.target.value),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[(0,s.jsx)("option",{value:"chat-completions",children:"Chat Completions"}),(0,s.jsx)("option",{value:"responses",children:"Responses API"})]})]}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted mb-1 block",children:"Supported Endpoints"}),(0,s.jsx)("div",{className:"flex items-center gap-3",children:["chat","embeddings","images","audio"].map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-text-main cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:b.includes(e),onChange:t=>{t.target.checked?v(t=>[...t,e]):v(t=>t.filter(t=>t!==e))},className:"rounded border-border"}),"chat"===e?"\uD83D\uDCAC Chat":"embeddings"===e?"\uD83D\uDCD0 Embeddings":"images"===e?"\uD83D\uDDBC️ Images":"\uD83D\uDD0A Audio"]},e))})]})]})]}),C?(0,s.jsx)("p",{className:"text-xs text-text-muted",children:o("loading")}):d.length>0?(0,s.jsx)("div",{className:"flex flex-col gap-2",children:d.map(e=>{let i=`${t}/${e.id}`,a=`custom-${e.id}`;return(0,s.jsxs)("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-primary",children:"tune"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium truncate",children:e.name||e.id}),(0,s.jsxs)("div",{className:"flex items-center gap-1 mt-1 flex-wrap",children:[(0,s.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:i}),(0,s.jsx)("button",{onClick:()=>l(i,a),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:o("copyModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:r===a?"check":"content_copy"})}),"responses"===e.apiFormat&&(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-blue-500/15 text-blue-400 font-medium",children:"Responses"}),e.supportedEndpoints?.includes("embeddings")&&(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-purple-500/15 text-purple-400 font-medium",children:"\uD83D\uDCD0 Embed"}),e.supportedEndpoints?.includes("images")&&(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/15 text-amber-400 font-medium",children:"\uD83D\uDDBC️ Images"}),e.supportedEndpoints?.includes("audio")&&(0,s.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-green-500/15 text-green-400 font-medium",children:"\uD83D\uDD0A Audio"})]}),w===e.id&&(0,s.jsxs)("div",{className:"mt-3 p-3 rounded-lg border border-border bg-sidebar/40",children:[(0,s.jsxs)("div",{className:"flex items-end gap-3 flex-wrap",children:[(0,s.jsxs)("div",{className:"w-44",children:[(0,s.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"API Format"}),(0,s.jsxs)("select",{value:T,onChange:e=>E(e.target.value),className:"w-full px-2.5 py-2 text-xs border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[(0,s.jsx)("option",{value:"chat-completions",children:"Chat Completions"}),(0,s.jsx)("option",{value:"responses",children:"Responses API"})]})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted mb-1 block",children:"Supported Endpoints"}),(0,s.jsx)("div",{className:"flex items-center gap-3 flex-wrap",children:["chat","embeddings","images","audio"].map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-text-main cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:A.includes(e),onChange:t=>{t.target.checked?$(t=>t.includes(e)?t:[...t,e]):$(t=>t.filter(t=>t!==e))},className:"rounded border-border"}),"chat"===e?"\uD83D\uDCAC Chat":"embeddings"===e?"\uD83D\uDCD0 Embeddings":"images"===e?"\uD83D\uDDBC️ Images":"\uD83D\uDD0A Audio"]},e))})]})]}),(0,s.jsxs)("div",{className:"mt-3 flex items-center gap-2",children:[(0,s.jsx)(u.$n,{size:"sm",onClick:()=>K(e.id),disabled:R===e.id,children:R===e.id?o("saving"):o("save")}),(0,s.jsx)(u.$n,{size:"sm",variant:"ghost",onClick:_,children:o("cancel")})]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{onClick:()=>{S(e.id),E(e.apiFormat||"chat-completions"),$(Array.isArray(e.supportedEndpoints)&&e.supportedEndpoints.length?e.supportedEndpoints:["chat"])},className:"p-1 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:o("edit"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"edit"})}),(0,s.jsx)("button",{onClick:()=>I(e.id),className:"p-1 hover:bg-red-50 rounded text-red-500",title:o("removeCustomModel"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})]},e.id)})}):(0,s.jsx)("p",{className:"text-xs text-text-muted",children:o("noCustomModels")})]})}function C({providerStorageAlias:e,providerDisplayAlias:t,modelAliases:r,copied:l,onCopy:o,onSetAlias:n,onDeleteAlias:d,connections:c,isAnthropic:p,onImportWithProgress:x}){let h=(0,m.c)("providers"),[f,g]=(0,i.useState)(""),[y,b]=(0,i.useState)(!1),[v,N]=(0,i.useState)(!1),C=(0,a.i)(),k=Object.entries(r).filter(([,t])=>t.startsWith(`${e}/`)).map(([t,r])=>({modelId:r.replace(`${e}/`,""),fullModel:r,alias:t})),w=e=>{let s,i=(s=e.split("/"))[s.length-1];if(!r[i])return i;let a=`${t}-${i}`;return r[a]?null:a},S=async()=>{if(!f.trim()||y)return;let t=f.trim(),r=w(t);if(!r)return void C.error(h("allSuggestedAliasesExist"));b(!0);try{let s=await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,modelId:t,modelName:t,source:"manual"})});if(!s.ok){let e={};try{e=await s.json()}catch(e){console.error("Failed to parse error response from custom model API:",e)}throw Error(e.error?.message||h("failedSaveCustomModel"))}await n(t,r,e),g(""),C.success(h("modelAddedSuccess",{modelId:t}))}catch(e){console.error("Error adding model:",e),C.error(e instanceof Error?e.message:h("failedAddModelTryAgain"))}finally{b(!1)}},T=async()=>{if(v)return;let t=c.find(e=>!1!==e.isActive);if(t){N(!0);try{await x(async()=>{let e=await fetch(`/api/providers/${t.id}/models`),r=await e.json();if(!e.ok)throw Error(r.error||h("failedImportModels"));return r},async t=>{let r=t.id||t.name||t.model;if(!r)return!1;let s=w(r);return!!s&&((await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,modelId:r,modelName:t.name||r,source:"imported"})})).ok?(await n(r,s,e),!0):(C.error(h("failedSaveImportedModel")),!1))})}catch(e){console.error("Error importing models:",e),C.error(h("failedImportModelsTryAgain"))}finally{N(!1)}}},E=c.some(e=>!1!==e.isActive),A=async(t,r)=>{try{if(!(await fetch(`/api/provider-models?provider=${encodeURIComponent(e)}&model=${encodeURIComponent(t)}`,{method:"DELETE"})).ok)throw Error(h("failedRemoveModelFromDatabase"));await d(r),C.success(h("modelRemovedSuccess"))}catch(e){console.error("Error deleting model:",e),C.error(e instanceof Error?e.message:h("failedDeleteModelTryAgain"))}};return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)("p",{className:"text-sm text-text-muted",children:h("compatibleModelsDescription",{type:p?h("anthropic"):h("openai")})}),(0,s.jsxs)("div",{className:"flex items-end gap-2 flex-wrap",children:[(0,s.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,s.jsx)("label",{htmlFor:"new-compatible-model-input",className:"text-xs text-text-muted mb-1 block",children:h("modelId")}),(0,s.jsx)("input",{id:"new-compatible-model-input",type:"text",value:f,onChange:e=>g(e.target.value),onKeyDown:e=>"Enter"===e.key&&S(),placeholder:p?h("anthropicCompatibleModelPlaceholder"):h("openaiCompatibleModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:S,disabled:!f.trim()||y,children:y?h("adding"):h("add")}),(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"download",onClick:T,disabled:!E||v,children:v?h("importingModels"):h("importFromModels")})]}),!E&&(0,s.jsx)("p",{className:"text-xs text-text-muted",children:h("addConnectionToImport")}),k.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-3",children:k.map(({modelId:e,fullModel:r,alias:i})=>(0,s.jsx)(j,{modelId:e,fullModel:`${t}/${e}`,copied:l,onCopy:o,onDeleteAlias:()=>A(e,i)},r))})]})}function k({until:e}){let[t,r]=(0,i.useState)("");return((0,i.useEffect)(()=>{let t=()=>{let t=new Date(e).getTime()-Date.now();if(t<=0)return void r("");let s=Math.floor(t/1e3);if(s<60)r(`${s}s`);else if(s<3600)r(`${Math.floor(s/60)}m ${s%60}s`);else{let e=Math.floor(s/3600),t=Math.floor(s%3600/60);r(`${e}h ${t}m`)}};t();let s=setInterval(t,1e3);return()=>clearInterval(s)},[e]),t)?(0,s.jsxs)("span",{className:"text-xs text-orange-500 font-mono",children:["⏱ ",t]}):null}b.propTypes={model:o().shape({id:o().string.isRequired}).isRequired,fullModel:o().string.isRequired,alias:o().string,copied:o().string,onCopy:o().func.isRequired},v.propTypes={providerAlias:o().string.isRequired,modelAliases:o().object.isRequired,copied:o().string,onCopy:o().func.isRequired,onSetAlias:o().func.isRequired,onDeleteAlias:o().func.isRequired},j.propTypes={modelId:o().string.isRequired,fullModel:o().string.isRequired,copied:o().string,onCopy:o().func.isRequired,onDeleteAlias:o().func.isRequired},N.propTypes={providerId:o().string.isRequired,providerAlias:o().string.isRequired,copied:o().string,onCopy:o().func.isRequired},C.propTypes={providerStorageAlias:o().string.isRequired,providerDisplayAlias:o().string.isRequired,modelAliases:o().object.isRequired,copied:o().string,onCopy:o().func.isRequired,onSetAlias:o().func.isRequired,onDeleteAlias:o().func.isRequired,connections:o().arrayOf(o().shape({id:o().string,isActive:o().bool})).isRequired,isAnthropic:o().bool,onImportWithProgress:o().func.isRequired},k.propTypes={until:o().string.isRequired};let w={runtime_error:{labelKey:"errorTypeRuntime",variant:"warning"},upstream_auth_error:{labelKey:"errorTypeUpstreamAuth",variant:"error"},auth_missing:{labelKey:"errorTypeMissingCredential",variant:"warning"},token_refresh_failed:{labelKey:"errorTypeRefreshFailed",variant:"warning"},token_expired:{labelKey:"errorTypeTokenExpired",variant:"warning"},upstream_rate_limited:{labelKey:"errorTypeRateLimited",variant:"warning"},upstream_unavailable:{labelKey:"errorTypeUpstreamUnavailable",variant:"error"},network_error:{labelKey:"errorTypeNetworkError",variant:"warning"},unsupported:{labelKey:"errorTypeTestUnsupported",variant:"default"},upstream_error:{labelKey:"errorTypeUpstreamError",variant:"error"}};function S({connection:e,isOAuth:t,isCodex:r,isFirst:a,isLast:l,onMoveUp:o,onMoveDown:n,onToggleActive:d,onToggleRateLimit:c,onToggleCodex5h:p,onToggleCodexWeekly:x,onRetest:h,isRetesting:f,onEdit:y,onDelete:b,onReauth:v,onProxy:j,hasProxy:N,proxySource:C,proxyHost:S,onRefreshToken:T,isRefreshing:E}){let A,$=(0,m.c)("providers"),R=t?e.name||e.email||e.displayName||$("oauthAccount"):e.name,[P,M]=(0,i.useState)(!1),[O,I]=(0,i.useState)(()=>t&&e.expiresAt?Math.floor((new Date(e.expiresAt).getTime()-Date.now())/6e4):null);(0,i.useEffect)(()=>{if(!t||!e.expiresAt)return;let r=setInterval(()=>{I(Math.floor((new Date(e.expiresAt).getTime()-Date.now())/6e4))},3e4);return()=>clearInterval(r)},[t,e.expiresAt]),(0,i.useEffect)(()=>{let t=()=>{M(e.rateLimitedUntil&&new Date(e.rateLimitedUntil).getTime()>Date.now())};t();let r=e.rateLimitedUntil?setInterval(t,1e3):null;return()=>{r&&clearInterval(r)}},[e.rateLimitedUntil]);let _="unavailable"!==e.testStatus||P?e.testStatus:"active",K=function(e,t,r,s){if(!1===e.isActive)return{statusVariant:"default",statusLabel:s("statusDisabled"),errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};if("active"===t||"success"===t)return{statusVariant:"success",statusLabel:s("statusConnected"),errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};let i=function(e,t){if(t)return"upstream_rate_limited";if(e.lastErrorType)return e.lastErrorType;let r=Number(e.errorCode);if(401===r||403===r)return"upstream_auth_error";if(429===r)return"upstream_rate_limited";if(r>=500)return"upstream_unavailable";let s=(e.lastError||"").toLowerCase();return s?s.includes("runtime")||s.includes("not runnable")||s.includes("not installed")||s.includes("healthcheck")?"runtime_error":s.includes("refresh failed")?"token_refresh_failed":s.includes("token expired")||s.includes("expired")?"token_expired":s.includes("invalid api key")||s.includes("token invalid")||s.includes("revoked")||s.includes("access denied")||s.includes("unauthorized")?"upstream_auth_error":s.includes("rate limit")||s.includes("quota")||s.includes("too many requests")||s.includes("429")?"upstream_rate_limited":s.includes("fetch failed")||s.includes("network")||s.includes("timeout")||s.includes("econn")||s.includes("enotfound")?"network_error":s.includes("not supported")?"unsupported":"upstream_error":null}(e,r),a=i&&w[i]||null;return"runtime_error"===i?{statusVariant:"warning",statusLabel:s("statusRuntimeIssue"),errorType:i,errorBadge:a,errorTextClass:"text-yellow-600 dark:text-yellow-400"}:"upstream_auth_error"===i||"auth_missing"===i||"token_refresh_failed"===i||"token_expired"===i?{statusVariant:"error",statusLabel:s("statusAuthFailed"),errorType:i,errorBadge:a,errorTextClass:"text-red-500"}:"upstream_rate_limited"===i?{statusVariant:"warning",statusLabel:s("statusRateLimited"),errorType:i,errorBadge:a,errorTextClass:"text-yellow-600 dark:text-yellow-400"}:"network_error"===i?{statusVariant:"warning",statusLabel:s("statusNetworkIssue"),errorType:i,errorBadge:a,errorTextClass:"text-yellow-600 dark:text-yellow-400"}:"unsupported"===i?{statusVariant:"default",statusLabel:s("statusTestUnsupported"),errorType:i,errorBadge:a,errorTextClass:"text-text-muted"}:{statusVariant:"error",statusLabel:({unavailable:s("statusUnavailable"),failed:s("statusFailed"),error:s("statusError")})[t]||t||s("statusError"),errorType:i,errorBadge:a,errorTextClass:"text-red-500"}}(e,_,P,$),F=!!e.rateLimitProtection,L=g(e.providerSpecificData&&"object"==typeof e.providerSpecificData&&e.providerSpecificData.codexLimitPolicy&&"object"==typeof e.providerSpecificData.codexLimitPolicy?e.providerSpecificData.codexLimitPolicy:{}),D=L.use5h,q=L.useWeekly;return(0,s.jsxs)("div",{className:`group flex items-center justify-between p-3 rounded-lg hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors ${!1===e.isActive?"opacity-60":""}`,children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("button",{onClick:o,disabled:a,className:`p-0.5 rounded ${a?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_up"})}),(0,s.jsx)("button",{onClick:n,disabled:l,className:`p-0.5 rounded ${l?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_down"})})]}),(0,s.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:t?"lock":"key"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium truncate",children:R}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[(0,s.jsx)(u.Ex,{variant:K.statusVariant,size:"sm",dot:!0,children:K.statusLabel}),null!==O&&(O<0?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium bg-red-500/15 text-red-500",title:`Token expired: ${e.expiresAt}`,children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"error"}),"expired"]}):O<30?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/15 text-amber-500",title:`Token expires in ${O}m`,children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"warning"}),`~${O}m`]}):null),P&&!1!==e.isActive&&(0,s.jsx)(k,{until:e.rateLimitedUntil}),K.errorBadge&&!1!==e.isActive&&(0,s.jsx)(u.Ex,{variant:K.errorBadge.variant,size:"sm",children:$(K.errorBadge.labelKey)}),e.lastError&&!1!==e.isActive&&(0,s.jsx)("span",{className:`text-xs truncate max-w-[300px] ${K.errorTextClass}`,title:e.lastError,children:e.lastError}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:["#",e.priority]}),e.globalPriority&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:$("autoPriority",{priority:e.globalPriority})}),(0,s.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,s.jsxs)("button",{onClick:()=>c(!F),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${F?"bg-emerald-500/15 text-emerald-500 hover:bg-emerald-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:$(F?"disableRateLimitProtection":"enableRateLimitProtection"),children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"shield"}),$(F?"rateLimitProtected":"rateLimitUnprotected")]}),r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,s.jsxs)("button",{onClick:()=>p?.(!D),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${D?"bg-blue-500/15 text-blue-500 hover:bg-blue-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:"Toggle Codex 5h limit policy",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"timer"}),"5h ",D?"ON":"OFF"]}),(0,s.jsxs)("button",{onClick:()=>x?.(!q),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${q?"bg-violet-500/15 text-violet-500 hover:bg-violet-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:"Toggle Codex weekly limit policy",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"date_range"}),"Weekly ",q?"ON":"OFF"]})]}),N&&(A=$("global"===C?"proxySourceGlobal":"provider"===C?"proxySourceProvider":"proxySourceKey"),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,s.jsxs)("span",{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium ${"global"===C?"bg-emerald-500/15 text-emerald-500":"provider"===C?"bg-amber-500/15 text-amber-500":"bg-blue-500/15 text-blue-500"}`,title:$("proxyConfiguredBySource",{source:A,host:S||$("configured")}),children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"vpn_lock"}),S||$("proxy")]})]}))]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(u.$n,{size:"sm",variant:"ghost",icon:"refresh",loading:f,disabled:!1===e.isActive,onClick:h,className:"!h-7 !px-2 text-xs",title:$("retestAuthentication"),children:$("retest")}),T&&(0,s.jsx)(u.$n,{size:"sm",variant:"ghost",icon:"token",loading:E,disabled:!1===e.isActive||E,onClick:T,className:"!h-7 !px-2 text-xs text-amber-500 hover:text-amber-400",title:"Refresh OAuth token manually",children:"Token"}),(0,s.jsx)(u.lM,{size:"sm",checked:e.isActive??!0,onChange:d,title:$(e.isActive??!0?"disableConnection":"enableConnection")}),(0,s.jsxs)("div",{className:"flex gap-1 ml-1 transition-opacity",children:[v&&(0,s.jsx)("button",{onClick:v,className:"p-2 hover:bg-amber-500/10 rounded text-amber-600 hover:text-amber-500",title:$("reauthenticateConnection"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"passkey"})}),(0,s.jsx)("button",{onClick:y,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",title:$("edit"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),(0,s.jsx)("button",{onClick:j,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",title:$("proxyConfig"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"vpn_lock"})}),(0,s.jsx)("button",{onClick:b,className:"p-2 hover:bg-red-500/10 rounded text-red-500",title:$("delete"),children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]})]})}function T({isOpen:e,provider:t,providerName:r,isCompatible:a,isAnthropic:l,onSave:o,onClose:n}){let d=(0,m.c)("providers"),[c,p]=(0,i.useState)({name:"",apiKey:"",priority:1}),[x,h]=(0,i.useState)(!1),[f,g]=(0,i.useState)(null),[y,b]=(0,i.useState)(!1),[v,j]=(0,i.useState)(null),N=async()=>{h(!0),j(null);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:c.apiKey})}),r=await e.json();g(r.valid?"success":"failed")}catch{g("failed")}finally{h(!1)}},C=async()=>{if(t&&c.apiKey){b(!0),j(null);try{let e=!1;try{h(!0),g(null);let r=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:c.apiKey})});e=!!(await r.json()).valid,g(e?"success":"failed")}catch{g("failed")}finally{h(!1)}if(!e)return void j(d("apiKeyValidationFailed"));let r=await o({name:c.name,apiKey:c.apiKey,priority:c.priority,testStatus:"active"});r&&j("string"==typeof r?r:d("failedSaveConnection"))}finally{b(!1)}}};return t?(0,s.jsx)(u.aF,{isOpen:e,title:d("addProviderApiKeyTitle",{provider:r||t}),onClose:n,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(u.pd,{label:d("nameLabel"),value:c.name,onChange:e=>p({...c,name:e.target.value}),placeholder:d("productionKey")}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.pd,{label:d("apiKeyLabel"),type:"password",value:c.apiKey,onChange:e=>p({...c,apiKey:e.target.value}),className:"flex-1"}),(0,s.jsx)("div",{className:"pt-6",children:(0,s.jsx)(u.$n,{onClick:N,disabled:!c.apiKey||x||y,variant:"secondary",children:x?d("checking"):d("check")})})]}),f&&(0,s.jsx)(u.Ex,{variant:"success"===f?"success":"error",children:"success"===f?d("valid"):d("invalid")}),v&&(0,s.jsx)("div",{className:"text-sm text-red-500 bg-red-500/10 border border-red-500/20 rounded-lg px-3 py-2",children:v}),a&&(0,s.jsx)("p",{className:"text-xs text-text-muted",children:l?d("validationChecksAnthropicCompatible",{provider:r||d("anthropicCompatibleName")}):d("validationChecksOpenAiCompatible",{provider:r||d("openaiCompatibleName")})}),(0,s.jsx)(u.pd,{label:d("priorityLabel"),type:"number",value:c.priority,onChange:e=>p({...c,priority:Number.parseInt(e.target.value)||1})}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.$n,{onClick:C,fullWidth:!0,disabled:!c.name||!c.apiKey||y,children:y?d("saving"):d("save")}),(0,s.jsx)(u.$n,{onClick:n,variant:"ghost",fullWidth:!0,children:d("cancel")})]})]})}):null}function E({isOpen:e,connection:t,onSave:r,onClose:a}){let l=(0,m.c)("providers"),[o,n]=(0,i.useState)({name:"",priority:1,apiKey:"",healthCheckInterval:60}),[d,c]=(0,i.useState)(!1),[p,h]=(0,i.useState)(null),[f,g]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null),[v,j]=(0,i.useState)(!1),[N,C]=(0,i.useState)([]),[k,S]=(0,i.useState)("");(0,i.useEffect)(()=>{if(t){n({name:t.name||"",priority:t.priority||1,apiKey:"",healthCheckInterval:t.healthCheckInterval??60});let e=t.providerSpecificData?.extraApiKeys;C(Array.isArray(e)?e:[]),S(""),h(null),b(null)}},[t]);let T=async()=>{if(t?.provider){c(!0),h(null);try{let e=await fetch(`/api/providers/${t.id}/test`,{method:"POST"}),r=await e.json();h({valid:!!r.valid,diagnosis:r.diagnosis||null,message:r.error||null})}catch{h({valid:!1,diagnosis:{type:"network_error"},message:l("failedTestConnection")})}finally{c(!1)}}},E=async()=>{if(t?.provider&&o.apiKey){g(!0),b(null);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t.provider,apiKey:o.apiKey})}),r=await e.json();b(r.valid?"success":"failed")}catch{b("failed")}finally{g(!1)}}},A=async()=>{j(!0);try{let e={name:o.name,priority:o.priority,healthCheckInterval:o.healthCheckInterval};if(!$&&o.apiKey){e.apiKey=o.apiKey;let r="success"===y;if(!r)try{g(!0),b(null);let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t.provider,apiKey:o.apiKey})});r=!!(await e.json()).valid,b(r?"success":"failed")}catch{b("failed")}finally{g(!1)}r&&(e.testStatus="active",e.lastError=null,e.lastErrorAt=null,e.lastErrorType=null,e.lastErrorSource=null,e.errorCode=null,e.rateLimitedUntil=null)}$||(e.providerSpecificData={...t.providerSpecificData||{},extraApiKeys:N.filter(e=>e.trim().length>0)}),await r(e)}finally{j(!1)}};if(!t)return null;let $="oauth"===t.authType,R=(0,x.mq)(t.provider)||(0,x.gb)(t.provider),P=!p?.valid&&p?.diagnosis?.type&&w[p.diagnosis.type]||null;return(0,s.jsx)(u.aF,{isOpen:e,title:l("editConnection"),onClose:a,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(u.pd,{label:l("nameLabel"),value:o.name,onChange:e=>n({...o,name:e.target.value}),placeholder:$?l("accountName"):l("productionKey")}),$&&t.email&&(0,s.jsxs)("div",{className:"bg-sidebar/50 p-3 rounded-lg",children:[(0,s.jsx)("p",{className:"text-sm text-text-muted mb-1",children:l("email")}),(0,s.jsx)("p",{className:"font-medium",children:t.email})]}),$&&(0,s.jsx)(u.pd,{label:l("healthCheckMinutes"),type:"number",value:o.healthCheckInterval,onChange:e=>n({...o,healthCheckInterval:Math.max(0,Number.parseInt(e.target.value)||0)}),hint:l("healthCheckHint")}),(0,s.jsx)(u.pd,{label:l("priorityLabel"),type:"number",value:o.priority,onChange:e=>n({...o,priority:Number.parseInt(e.target.value)||1})}),!$&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.pd,{label:l("apiKeyLabel"),type:"password",value:o.apiKey,onChange:e=>n({...o,apiKey:e.target.value}),placeholder:l("enterNewApiKey"),hint:l("leaveBlankKeepCurrentApiKey"),className:"flex-1"}),(0,s.jsx)("div",{className:"pt-6",children:(0,s.jsx)(u.$n,{onClick:E,disabled:!o.apiKey||f||v,variant:"secondary",children:f?l("checking"):l("check")})})]}),y&&(0,s.jsx)(u.Ex,{variant:"success"===y?"success":"error",children:"success"===y?l("valid"):l("invalid")})]}),!$&&(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)("label",{className:"text-sm font-medium text-text-main",children:["Extra API Keys",(0,s.jsx)("span",{className:"ml-2 text-[11px] font-normal text-text-muted",children:"(round-robin rotation — optional)"})]}),N.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-1.5",children:N.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"flex-1 font-mono text-xs bg-sidebar/50 px-3 py-2 rounded border border-border text-text-muted truncate",children:`Key #${t+2}: ${e.slice(0,6)}...${e.slice(-4)}`}),(0,s.jsx)("button",{onClick:()=>C(N.filter((e,r)=>r!==t)),className:"p-1.5 rounded hover:bg-red-500/10 text-red-400 hover:text-red-500",title:"Remove this key",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]},t))}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("input",{type:"password",value:k,onChange:e=>S(e.target.value),placeholder:"Add another API key...",className:"flex-1 text-sm bg-sidebar/50 border border-border rounded px-3 py-2 text-text-main placeholder:text-text-muted focus:ring-1 focus:ring-primary outline-none",onKeyDown:e=>{"Enter"===e.key&&k.trim()&&(C([...N,k.trim()]),S(""))}}),(0,s.jsx)("button",{onClick:()=>{k.trim()&&(C([...N,k.trim()]),S(""))},disabled:!k.trim(),className:"px-3 py-2 rounded bg-primary/10 text-primary hover:bg-primary/20 disabled:opacity-40 text-sm font-medium",children:"Add"})]}),N.length>0&&(0,s.jsxs)("p",{className:"text-[11px] text-text-muted",children:[N.length+1," keys total — rotating round-robin on each request."]})]}),!R&&(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(u.$n,{onClick:T,variant:"secondary",disabled:d,children:d?l("testing"):l("testConnection")}),p&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.Ex,{variant:p.valid?"success":"error",children:p.valid?l("valid"):l("failed")}),P&&(0,s.jsx)(u.Ex,{variant:P.variant,children:l(P.labelKey)})]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.$n,{onClick:A,fullWidth:!0,disabled:v,children:v?l("saving"):l("save")}),(0,s.jsx)(u.$n,{onClick:a,variant:"ghost",fullWidth:!0,children:l("cancel")})]})]})})}function A({isOpen:e,node:t,onSave:r,onClose:a,isAnthropic:l}){let o=(0,m.c)("providers"),[n,d]=(0,i.useState)({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[c,p]=(0,i.useState)(!1),[x,h]=(0,i.useState)(""),[f,g]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null);(0,i.useEffect)(()=>{t&&d({name:t.name||"",prefix:t.prefix||"",apiType:t.apiType||"chat",baseUrl:t.baseUrl||(l?"https://api.anthropic.com/v1":"https://api.openai.com/v1")})},[t,l]);let v=[{value:"chat",label:o("chatCompletions")},{value:"responses",label:o("responsesApi")}],j=async()=>{if(n.name.trim()&&n.prefix.trim()&&n.baseUrl.trim()){p(!0);try{let e={name:n.name,prefix:n.prefix,baseUrl:n.baseUrl};l||(e.apiType=n.apiType),await r(e)}finally{p(!1)}}},N=async()=>{g(!0);try{let e=await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:n.baseUrl,apiKey:x,type:l?"anthropic-compatible":"openai-compatible"})}),t=await e.json();b(t.valid?"success":"failed")}catch{b("failed")}finally{g(!1)}};return t?(0,s.jsx)(u.aF,{isOpen:e,title:o("editCompatibleTitle",{type:o(l?"anthropic":"openai")}),onClose:a,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(u.pd,{label:o("nameLabel"),value:n.name,onChange:e=>d({...n,name:e.target.value}),placeholder:o("compatibleProdPlaceholder",{type:o(l?"anthropic":"openai")}),hint:o("nameHint")}),(0,s.jsx)(u.pd,{label:o("prefixLabel"),value:n.prefix,onChange:e=>d({...n,prefix:e.target.value}),placeholder:o(l?"anthropicPrefixPlaceholder":"openaiPrefixPlaceholder"),hint:o("prefixHint")}),!l&&(0,s.jsx)(u.l6,{label:o("apiTypeLabel"),options:v,value:n.apiType,onChange:e=>d({...n,apiType:e.target.value})}),(0,s.jsx)(u.pd,{label:o("baseUrlLabel"),value:n.baseUrl,onChange:e=>d({...n,baseUrl:e.target.value}),placeholder:o(l?"anthropicBaseUrlPlaceholder":"openaiBaseUrlPlaceholder"),hint:o("compatibleBaseUrlHint",{type:o(l?"anthropic":"openai")})}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.pd,{label:o("apiKeyForCheck"),type:"password",value:x,onChange:e=>h(e.target.value),className:"flex-1"}),(0,s.jsx)("div",{className:"pt-6",children:(0,s.jsx)(u.$n,{onClick:N,disabled:!x||f||!n.baseUrl.trim(),variant:"secondary",children:o(f?"checking":"check")})})]}),y&&(0,s.jsx)(u.Ex,{variant:"success"===y?"success":"error",children:o("success"===y?"valid":"invalid")}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.$n,{onClick:j,fullWidth:!0,disabled:!n.name.trim()||!n.prefix.trim()||!n.baseUrl.trim()||c,children:o(c?"saving":"save")}),(0,s.jsx)(u.$n,{onClick:a,variant:"ghost",fullWidth:!0,children:o("cancel")})]})]})}):null}S.propTypes={connection:o().shape({id:o().string,name:o().string,email:o().string,displayName:o().string,rateLimitedUntil:o().string,rateLimitProtection:o().bool,testStatus:o().string,isActive:o().bool,priority:o().number,lastError:o().string,lastErrorType:o().string,lastErrorSource:o().string,errorCode:o().oneOfType([o().string,o().number]),globalPriority:o().number,providerSpecificData:o().object}).isRequired,isOAuth:o().bool.isRequired,isCodex:o().bool,isFirst:o().bool.isRequired,isLast:o().bool.isRequired,onMoveUp:o().func.isRequired,onMoveDown:o().func.isRequired,onToggleActive:o().func.isRequired,onToggleRateLimit:o().func.isRequired,onToggleCodex5h:o().func,onToggleCodexWeekly:o().func,onRetest:o().func.isRequired,isRetesting:o().bool,onEdit:o().func.isRequired,onDelete:o().func.isRequired,onReauth:o().func},T.propTypes={isOpen:o().bool.isRequired,provider:o().string,providerName:o().string,isCompatible:o().bool,isAnthropic:o().bool,onSave:o().func.isRequired,onClose:o().func.isRequired},E.propTypes={isOpen:o().bool.isRequired,connection:o().shape({id:o().string,name:o().string,email:o().string,priority:o().number,authType:o().string,provider:o().string}),onSave:o().func.isRequired,onClose:o().func.isRequired},A.propTypes={isOpen:o().bool.isRequired,node:o().shape({id:o().string,name:o().string,prefix:o().string,apiType:o().string,baseUrl:o().string}),onSave:o().func.isRequired,onClose:o().func.isRequired,isAnthropic:o().bool}}},e=>{e.O(0,[8500,3418,9751,8055,1149,5846,647,8441,3794,7358],()=>e(e.s=3751)),_N_E=e.O()}]);
|
package/app/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omniroute",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "Smart AI Router with auto fallback — route to FREE & cheap models, zero downtime. Works with Cursor, Cline, Claude Desktop, Codex, and any OpenAI-compatible tool.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omniroute",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "Smart AI Router with auto fallback — route to FREE & cheap models, zero downtime. Works with Cursor, Cline, Claude Desktop, Codex, and any OpenAI-compatible tool.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
File without changes
|
|
File without changes
|