omniroute 1.4.9 → 1.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/app/.next/BUILD_ID +1 -1
  2. package/app/.next/app-path-routes-manifest.json +34 -34
  3. package/app/.next/build-manifest.json +2 -2
  4. package/app/.next/prerender-manifest.json +3 -3
  5. package/app/.next/server/app/(dashboard)/dashboard/analytics/page_client-reference-manifest.js +1 -1
  6. package/app/.next/server/app/(dashboard)/dashboard/api-manager/page_client-reference-manifest.js +1 -1
  7. package/app/.next/server/app/(dashboard)/dashboard/audit-log/page_client-reference-manifest.js +1 -1
  8. package/app/.next/server/app/(dashboard)/dashboard/cli-tools/page_client-reference-manifest.js +1 -1
  9. package/app/.next/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
  10. package/app/.next/server/app/(dashboard)/dashboard/costs/page_client-reference-manifest.js +1 -1
  11. package/app/.next/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
  12. package/app/.next/server/app/(dashboard)/dashboard/health/page_client-reference-manifest.js +1 -1
  13. package/app/.next/server/app/(dashboard)/dashboard/limits/page_client-reference-manifest.js +1 -1
  14. package/app/.next/server/app/(dashboard)/dashboard/logs/page_client-reference-manifest.js +1 -1
  15. package/app/.next/server/app/(dashboard)/dashboard/onboarding/page_client-reference-manifest.js +1 -1
  16. package/app/.next/server/app/(dashboard)/dashboard/page_client-reference-manifest.js +1 -1
  17. package/app/.next/server/app/(dashboard)/dashboard/profile/page_client-reference-manifest.js +1 -1
  18. package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page.js +1 -1
  19. package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
  20. package/app/.next/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
  21. package/app/.next/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
  22. package/app/.next/server/app/(dashboard)/dashboard/settings/page_client-reference-manifest.js +1 -1
  23. package/app/.next/server/app/(dashboard)/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
  24. package/app/.next/server/app/(dashboard)/dashboard/translator/page_client-reference-manifest.js +1 -1
  25. package/app/.next/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
  26. package/app/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  27. package/app/.next/server/app/_global-error.html +2 -2
  28. package/app/.next/server/app/_global-error.rsc +1 -1
  29. package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  30. package/app/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  31. package/app/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  32. package/app/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  33. package/app/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  34. package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  35. package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  36. package/app/.next/server/app/api/auth/login/route_client-reference-manifest.js +1 -1
  37. package/app/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -1
  38. package/app/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
  39. package/app/.next/server/app/api/cache/route_client-reference-manifest.js +1 -1
  40. package/app/.next/server/app/api/cache/stats/route_client-reference-manifest.js +1 -1
  41. package/app/.next/server/app/api/cli-tools/antigravity-mitm/alias/route.js +2 -2
  42. package/app/.next/server/app/api/cli-tools/antigravity-mitm/alias/route_client-reference-manifest.js +1 -1
  43. package/app/.next/server/app/api/cli-tools/antigravity-mitm/route.js +2 -2
  44. package/app/.next/server/app/api/cli-tools/antigravity-mitm/route_client-reference-manifest.js +1 -1
  45. package/app/.next/server/app/api/cli-tools/backups/route.js +2 -2
  46. package/app/.next/server/app/api/cli-tools/backups/route_client-reference-manifest.js +1 -1
  47. package/app/.next/server/app/api/cli-tools/claude-settings/route.js +1 -1
  48. package/app/.next/server/app/api/cli-tools/claude-settings/route_client-reference-manifest.js +1 -1
  49. package/app/.next/server/app/api/cli-tools/cline-settings/route.js +1 -1
  50. package/app/.next/server/app/api/cli-tools/cline-settings/route_client-reference-manifest.js +1 -1
  51. package/app/.next/server/app/api/cli-tools/codex-profiles/route.js +1 -1
  52. package/app/.next/server/app/api/cli-tools/codex-profiles/route_client-reference-manifest.js +1 -1
  53. package/app/.next/server/app/api/cli-tools/codex-settings/route.js +1 -1
  54. package/app/.next/server/app/api/cli-tools/codex-settings/route_client-reference-manifest.js +1 -1
  55. package/app/.next/server/app/api/cli-tools/droid-settings/route.js +2 -2
  56. package/app/.next/server/app/api/cli-tools/droid-settings/route_client-reference-manifest.js +1 -1
  57. package/app/.next/server/app/api/cli-tools/guide-settings/[toolId]/route_client-reference-manifest.js +1 -1
  58. package/app/.next/server/app/api/cli-tools/kilo-settings/route.js +1 -1
  59. package/app/.next/server/app/api/cli-tools/kilo-settings/route_client-reference-manifest.js +1 -1
  60. package/app/.next/server/app/api/cli-tools/openclaw-settings/route.js +2 -2
  61. package/app/.next/server/app/api/cli-tools/openclaw-settings/route_client-reference-manifest.js +1 -1
  62. package/app/.next/server/app/api/cli-tools/runtime/[toolId]/route.js +2 -2
  63. package/app/.next/server/app/api/cli-tools/runtime/[toolId]/route_client-reference-manifest.js +1 -1
  64. package/app/.next/server/app/api/cli-tools/status/route.js +1 -1
  65. package/app/.next/server/app/api/cli-tools/status/route_client-reference-manifest.js +1 -1
  66. package/app/.next/server/app/api/cloud/auth/route_client-reference-manifest.js +1 -1
  67. package/app/.next/server/app/api/cloud/credentials/update/route_client-reference-manifest.js +1 -1
  68. package/app/.next/server/app/api/cloud/model/resolve/route_client-reference-manifest.js +1 -1
  69. package/app/.next/server/app/api/cloud/models/alias/route_client-reference-manifest.js +1 -1
  70. package/app/.next/server/app/api/combos/[id]/route_client-reference-manifest.js +1 -1
  71. package/app/.next/server/app/api/combos/metrics/route_client-reference-manifest.js +1 -1
  72. package/app/.next/server/app/api/combos/route_client-reference-manifest.js +1 -1
  73. package/app/.next/server/app/api/combos/test/route_client-reference-manifest.js +1 -1
  74. package/app/.next/server/app/api/compliance/audit-log/route_client-reference-manifest.js +1 -1
  75. package/app/.next/server/app/api/db-backups/export/route_client-reference-manifest.js +1 -1
  76. package/app/.next/server/app/api/db-backups/exportAll/route_client-reference-manifest.js +1 -1
  77. package/app/.next/server/app/api/db-backups/import/route_client-reference-manifest.js +1 -1
  78. package/app/.next/server/app/api/db-backups/route_client-reference-manifest.js +1 -1
  79. package/app/.next/server/app/api/evals/[suiteId]/route_client-reference-manifest.js +1 -1
  80. package/app/.next/server/app/api/evals/route_client-reference-manifest.js +1 -1
  81. package/app/.next/server/app/api/fallback/chains/route_client-reference-manifest.js +1 -1
  82. package/app/.next/server/app/api/init/route_client-reference-manifest.js +1 -1
  83. package/app/.next/server/app/api/keys/[id]/route_client-reference-manifest.js +1 -1
  84. package/app/.next/server/app/api/keys/route_client-reference-manifest.js +1 -1
  85. package/app/.next/server/app/api/logs/console/route_client-reference-manifest.js +1 -1
  86. package/app/.next/server/app/api/models/alias/route_client-reference-manifest.js +1 -1
  87. package/app/.next/server/app/api/models/availability/route_client-reference-manifest.js +1 -1
  88. package/app/.next/server/app/api/models/catalog/route_client-reference-manifest.js +1 -1
  89. package/app/.next/server/app/api/models/route.js +1 -1
  90. package/app/.next/server/app/api/models/route_client-reference-manifest.js +1 -1
  91. package/app/.next/server/app/api/monitoring/health/route.js +1 -1
  92. package/app/.next/server/app/api/monitoring/health/route_client-reference-manifest.js +1 -1
  93. package/app/.next/server/app/api/oauth/[provider]/[action]/route_client-reference-manifest.js +1 -1
  94. package/app/.next/server/app/api/oauth/cursor/auto-import/route_client-reference-manifest.js +1 -1
  95. package/app/.next/server/app/api/oauth/cursor/import/route_client-reference-manifest.js +1 -1
  96. package/app/.next/server/app/api/oauth/kiro/auto-import/route_client-reference-manifest.js +1 -1
  97. package/app/.next/server/app/api/oauth/kiro/import/route_client-reference-manifest.js +1 -1
  98. package/app/.next/server/app/api/oauth/kiro/social-authorize/route_client-reference-manifest.js +1 -1
  99. package/app/.next/server/app/api/oauth/kiro/social-exchange/route_client-reference-manifest.js +1 -1
  100. package/app/.next/server/app/api/policies/route_client-reference-manifest.js +1 -1
  101. package/app/.next/server/app/api/pricing/defaults/route_client-reference-manifest.js +1 -1
  102. package/app/.next/server/app/api/pricing/models/route_client-reference-manifest.js +1 -1
  103. package/app/.next/server/app/api/pricing/route_client-reference-manifest.js +1 -1
  104. package/app/.next/server/app/api/provider-metrics/route_client-reference-manifest.js +1 -1
  105. package/app/.next/server/app/api/provider-models/route_client-reference-manifest.js +1 -1
  106. package/app/.next/server/app/api/provider-nodes/[id]/route_client-reference-manifest.js +1 -1
  107. package/app/.next/server/app/api/provider-nodes/route_client-reference-manifest.js +1 -1
  108. package/app/.next/server/app/api/provider-nodes/validate/route_client-reference-manifest.js +1 -1
  109. package/app/.next/server/app/api/providers/[id]/models/route_client-reference-manifest.js +1 -1
  110. package/app/.next/server/app/api/providers/[id]/route_client-reference-manifest.js +1 -1
  111. package/app/.next/server/app/api/providers/[id]/test/route_client-reference-manifest.js +1 -1
  112. package/app/.next/server/app/api/providers/client/route_client-reference-manifest.js +1 -1
  113. package/app/.next/server/app/api/providers/route.js +1 -1
  114. package/app/.next/server/app/api/providers/route_client-reference-manifest.js +1 -1
  115. package/app/.next/server/app/api/providers/test-batch/route_client-reference-manifest.js +1 -1
  116. package/app/.next/server/app/api/providers/validate/route_client-reference-manifest.js +1 -1
  117. package/app/.next/server/app/api/rate-limit/route_client-reference-manifest.js +1 -1
  118. package/app/.next/server/app/api/rate-limits/route_client-reference-manifest.js +1 -1
  119. package/app/.next/server/app/api/resilience/reset/route_client-reference-manifest.js +1 -1
  120. package/app/.next/server/app/api/resilience/route_client-reference-manifest.js +1 -1
  121. package/app/.next/server/app/api/restart/route_client-reference-manifest.js +1 -1
  122. package/app/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -1
  123. package/app/.next/server/app/api/settings/combo-defaults/route_client-reference-manifest.js +1 -1
  124. package/app/.next/server/app/api/settings/ip-filter/route_client-reference-manifest.js +1 -1
  125. package/app/.next/server/app/api/settings/proxy/route_client-reference-manifest.js +1 -1
  126. package/app/.next/server/app/api/settings/proxy/test/route_client-reference-manifest.js +1 -1
  127. package/app/.next/server/app/api/settings/require-login/route_client-reference-manifest.js +1 -1
  128. package/app/.next/server/app/api/settings/route_client-reference-manifest.js +1 -1
  129. package/app/.next/server/app/api/settings/system-prompt/route_client-reference-manifest.js +1 -1
  130. package/app/.next/server/app/api/settings/thinking-budget/route_client-reference-manifest.js +1 -1
  131. package/app/.next/server/app/api/shutdown/route_client-reference-manifest.js +1 -1
  132. package/app/.next/server/app/api/storage/health/route_client-reference-manifest.js +1 -1
  133. package/app/.next/server/app/api/sync/cloud/route_client-reference-manifest.js +1 -1
  134. package/app/.next/server/app/api/sync/initialize/route_client-reference-manifest.js +1 -1
  135. package/app/.next/server/app/api/tags/route_client-reference-manifest.js +1 -1
  136. package/app/.next/server/app/api/telemetry/summary/route_client-reference-manifest.js +1 -1
  137. package/app/.next/server/app/api/token-health/route_client-reference-manifest.js +1 -1
  138. package/app/.next/server/app/api/translator/detect/route_client-reference-manifest.js +1 -1
  139. package/app/.next/server/app/api/translator/history/route_client-reference-manifest.js +1 -1
  140. package/app/.next/server/app/api/translator/load/route_client-reference-manifest.js +1 -1
  141. package/app/.next/server/app/api/translator/save/route_client-reference-manifest.js +1 -1
  142. package/app/.next/server/app/api/translator/send/route_client-reference-manifest.js +1 -1
  143. package/app/.next/server/app/api/translator/translate/route_client-reference-manifest.js +1 -1
  144. package/app/.next/server/app/api/usage/[connectionId]/route_client-reference-manifest.js +1 -1
  145. package/app/.next/server/app/api/usage/analytics/route_client-reference-manifest.js +1 -1
  146. package/app/.next/server/app/api/usage/budget/route_client-reference-manifest.js +1 -1
  147. package/app/.next/server/app/api/usage/call-logs/[id]/route_client-reference-manifest.js +1 -1
  148. package/app/.next/server/app/api/usage/call-logs/route_client-reference-manifest.js +1 -1
  149. package/app/.next/server/app/api/usage/history/route_client-reference-manifest.js +1 -1
  150. package/app/.next/server/app/api/usage/logs/route_client-reference-manifest.js +1 -1
  151. package/app/.next/server/app/api/usage/proxy-logs/route_client-reference-manifest.js +1 -1
  152. package/app/.next/server/app/api/usage/request-logs/route_client-reference-manifest.js +1 -1
  153. package/app/.next/server/app/api/v1/api/chat/route_client-reference-manifest.js +1 -1
  154. package/app/.next/server/app/api/v1/audio/speech/route_client-reference-manifest.js +1 -1
  155. package/app/.next/server/app/api/v1/audio/transcriptions/route_client-reference-manifest.js +1 -1
  156. package/app/.next/server/app/api/v1/chat/completions/route_client-reference-manifest.js +1 -1
  157. package/app/.next/server/app/api/v1/embeddings/route_client-reference-manifest.js +1 -1
  158. package/app/.next/server/app/api/v1/images/generations/route_client-reference-manifest.js +1 -1
  159. package/app/.next/server/app/api/v1/messages/count_tokens/route_client-reference-manifest.js +1 -1
  160. package/app/.next/server/app/api/v1/messages/route_client-reference-manifest.js +1 -1
  161. package/app/.next/server/app/api/v1/models/route_client-reference-manifest.js +1 -1
  162. package/app/.next/server/app/api/v1/moderations/route_client-reference-manifest.js +1 -1
  163. package/app/.next/server/app/api/v1/providers/[provider]/chat/completions/route_client-reference-manifest.js +1 -1
  164. package/app/.next/server/app/api/v1/providers/[provider]/embeddings/route_client-reference-manifest.js +1 -1
  165. package/app/.next/server/app/api/v1/providers/[provider]/images/generations/route_client-reference-manifest.js +1 -1
  166. package/app/.next/server/app/api/v1/rerank/route_client-reference-manifest.js +1 -1
  167. package/app/.next/server/app/api/v1/responses/route_client-reference-manifest.js +1 -1
  168. package/app/.next/server/app/api/v1/route_client-reference-manifest.js +1 -1
  169. package/app/.next/server/app/api/v1beta/models/[...path]/route_client-reference-manifest.js +1 -1
  170. package/app/.next/server/app/api/v1beta/models/route_client-reference-manifest.js +1 -1
  171. package/app/.next/server/app/callback/page_client-reference-manifest.js +1 -1
  172. package/app/.next/server/app/docs/page.js +1 -1
  173. package/app/.next/server/app/docs/page_client-reference-manifest.js +1 -1
  174. package/app/.next/server/app/forbidden/page_client-reference-manifest.js +1 -1
  175. package/app/.next/server/app/forgot-password/page_client-reference-manifest.js +1 -1
  176. package/app/.next/server/app/landing/page_client-reference-manifest.js +1 -1
  177. package/app/.next/server/app/login/page_client-reference-manifest.js +1 -1
  178. package/app/.next/server/app/page_client-reference-manifest.js +1 -1
  179. package/app/.next/server/app/privacy/page_client-reference-manifest.js +1 -1
  180. package/app/.next/server/app/terms/page_client-reference-manifest.js +1 -1
  181. package/app/.next/server/app-paths-manifest.json +34 -34
  182. package/app/.next/server/chunks/1259.js +1 -1
  183. package/app/.next/server/chunks/2180.js +3 -1
  184. package/app/.next/server/chunks/2910.js +3 -1
  185. package/app/.next/server/chunks/4488.js +3 -1
  186. package/app/.next/server/middleware.js +3 -1
  187. package/app/.next/server/pages/500.html +2 -2
  188. package/app/.next/server/server-reference-manifest.js +1 -1
  189. package/app/.next/server/server-reference-manifest.json +1 -1
  190. package/app/.next/static/chunks/{5846-756d72eb0e01a60c.js → 5846-bac355f56b136439.js} +1 -1
  191. package/app/.next/static/chunks/app/(dashboard)/dashboard/cli-tools/{page-012be9f38cda4c4a.js → page-ad885fdf9806e9a6.js} +1 -1
  192. package/app/.next/static/chunks/app/(dashboard)/dashboard/providers/[id]/page-6b6d62c5872aee46.js +1 -0
  193. package/app/.next/static/css/{a0c29bb208bb9dfe.css → e90887a86e63903f.css} +1 -1
  194. package/app/node_modules/better-sqlite3/build/Release/better_sqlite3.node +0 -0
  195. package/app/package.json +1 -1
  196. package/package.json +1 -1
  197. package/app/.next/static/chunks/app/(dashboard)/dashboard/providers/[id]/page-62c6fceede3a5549.js +0 -1
  198. /package/app/.next/static/{oaQaCPrOo77oe3OAEMAe- → 8UAle4UTGR7gIVofXmh_1}/_buildManifest.js +0 -0
  199. /package/app/.next/static/{oaQaCPrOo77oe3OAEMAe- → 8UAle4UTGR7gIVofXmh_1}/_ssgManifest.js +0 -0
package/app/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omniroute",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
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": "1.4.9",
3
+ "version": "1.4.10",
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": {
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2134],{56411:(e,t,r)=>{Promise.resolve().then(r.bind(r,88618))},88618:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>y});var s=r(95155),a=r(12115),i=r(67671),l=r(14051),o=r.n(l),n=r(73321),d=r(98500),c=r.n(d),m=r(5772),p=r(50910),u=r(40993),h=r(20909),x=r(81135),f=r(30949);function y(){let e=(0,n.useParams)(),t=(0,n.useRouter)(),r=e.id,[i,l]=(0,a.useState)([]),[o,d]=(0,a.useState)(!0),[y,b]=(0,a.useState)(null),[w,C]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[R,I]=(0,a.useState)(!1),[O,P]=(0,a.useState)(!1),[_,q]=(0,a.useState)(null),[U,D]=(0,a.useState)(null),[F,K]=(0,a.useState)({}),[L,M]=(0,a.useState)(!1),{copied:z,copy:J}=(0,f.C)(),V=(0,p.c)("providers"),W=(0,a.useRef)(!1),B=(0,a.useRef)(!1),[Z,G]=(0,a.useState)(null),[Q,H]=(0,a.useState)(null),[X,Y]=(0,a.useState)(!1),[ee,et]=(0,a.useState)(!1),[er,es]=(0,a.useState)({current:0,total:0,phase:"idle",status:"",logs:[],error:"",importedCount:0}),ea=y?{id:y.id,name:y.name||("anthropic-compatible"===y.type?"Anthropic Compatible":"OpenAI Compatible"),color:"anthropic-compatible"===y.type?"#D97757":"#10A37F",textIcon:"anthropic-compatible"===y.type?"AC":"OC",apiType:y.apiType,baseUrl:y.baseUrl,type:y.type}:h.IS[r]||h.zN[r]||h.fg[r],ei=!!h.IS[r]||!!h.zN[r],el=(0,x.KC)(r),eo=(0,h.wG)(r),en=(0,h.mq)(r),ed=(0,h.gb)(r),ec=en||ed,em=ec?r:eo,ep=ec?y?.prefix||r:eo,eu=(0,a.useCallback)(async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&K(t.aliases||{})}catch(e){console.log("Error fetching aliases:",e)}},[]),eh=(0,a.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(),a=await t.json();if(e.ok){let e=(s.connections||[]).filter(e=>e.provider===r);l(e)}if(t.ok){let e=(a.nodes||[]).find(e=>e.id===r)||null;if(!e&&ec)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}b(e)}}catch(e){console.log("Error fetching connections:",e)}finally{d(!1)}},[r,ec]),ex=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&&(b(s.node),await eh(),P(!1))}catch(e){console.log("Error updating provider node:",e)}};(0,a.useEffect)(()=>{eh(),eu(),fetch("/api/settings/proxy").then(e=>e.ok?e.json():null).then(e=>H(e)).catch(()=>{})},[eh,eu]),(0,a.useEffect)(()=>{o||0!==i.length||!ea||ec||W.current||B.current||(W.current=!0,ei?C(!0):E(!0))},[o]);let ef=async(e,t,r=eo)=>{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 eu();else{let t=await e.json();alert(t.error||V("failedSetAlias"))}}catch(e){console.log("Error setting alias:",e)}},ey=async e=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await eu()}catch(e){console.log("Error deleting alias:",e)}},eg=async e=>{if(confirm(V("deleteConnectionConfirm")))try{(await fetch(`/api/providers/${e}`,{method:"DELETE"})).ok&&l(i.filter(t=>t.id!==e))}catch(e){console.log("Error deleting connection:",e)}},ev=(0,a.useCallback)(()=>{eh(),C(!1)},[eh]),eb=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 eh(),E(!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")}},ej=async e=>{try{(await fetch(`/api/providers/${_.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(await eh(),I(!1))}catch(e){console.log("Error updating connection:",e)}},eN=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&l(r=>r.map(r=>r.id===e?{...r,isActive:t}:r))}catch(e){console.log("Error updating connection status:",e)}},ew=async(e,t)=>{try{(await fetch("/api/rate-limits",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({connectionId:e,enabled:t})})).ok&&l(r=>r.map(r=>r.id===e?{...r,rateLimitProtection:t}:r))}catch(e){console.error("Error toggling rate limit:",e)}},eC=async e=>{if(e&&!U){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 eh()}catch(e){console.error("Error retesting connection:",e)}finally{D(null)}}},ek=async(e,t)=>{if(e&&t)try{let r=t.priority,s=e.priority;r===s&&(r=i.indexOf(e)>i.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 eh()}catch(e){console.log("Error swapping priority:",e)}},eS=async()=>{if(X)return;let e=i.find(e=>!1!==e.isActive);if(e){Y(!0),et(!0),es({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 es(e=>({...e,phase:"error",status:V("failedFetchModels"),error:s.error||"Failed to import models"}));let a=s.models||[];if(0===a.length)return void es(e=>({...e,phase:"done",status:V("noModelsFound"),logs:["No models returned from /models endpoint."]}));es(e=>({...e,phase:"importing",total:a.length,status:`Importing 0 of ${a.length} models...`,logs:[`Found ${a.length} models. Starting import...`]}));let i=0;for(let e=0;e<a.length;e++){let t=a[e],s=t.id||t.name||t.model;if(!s)continue;let l=s.split("/"),o=l[l.length-1];es(t=>({...t,current:e+1,status:`Importing ${e+1} of ${a.length} models...`,logs:[...t.logs,`Importing ${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"})}),F[o]||await ef(s,o,em),i+=1}await eu(),es(e=>({...e,phase:"done",current:a.length,status:i>0?`Successfully imported ${i} model${1===i?"":"s"}!`:"No new models were added (all already exist).",logs:[...e.logs,i>0?`✓ Done! ${i} model${1===i?"":"s"} imported.`:"No new models were added."],importedCount:i})),i>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(e){console.log("Error importing models:",e),es(t=>({...t,phase:"error",status:V("importFailed"),error:e instanceof Error?e.message:"An unexpected error occurred"}))}finally{Y(!1)}}},eA=async(e,t)=>{et(!0),es({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 es(e=>({...e,phase:"done",status:V("noModelsFound"),logs:["No models returned from /models endpoint."]}));es(e=>({...e,phase:"importing",total:r.length,status:`Importing 0 of ${r.length} models...`,logs:[`Found ${r.length} models. Starting import...`]}));let s=0;for(let e=0;e<r.length;e++){let a=r[e],i=a.id||a.name||a.model;i&&(es(t=>({...t,current:e+1,status:`Importing ${e+1} of ${r.length} models...`,logs:[...t.logs,`Importing ${i}...`]})),await t(a)&&(s+=1))}es(e=>({...e,phase:"done",current:r.length,status:s>0?`Successfully imported ${s} model${1===s?"":"s"}!`:"No new models were added.",logs:[...e.logs,s>0?`✓ Done! ${s} model${1===s?"":"s"} imported.`:"No new models were added."],importedCount:s})),s>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(e){console.log("Error importing models:",e),es(t=>({...t,phase:"error",status:V("importFailed"),error:e instanceof Error?e.message:"An unexpected error occurred"}))}},e$=i.some(e=>!1!==e.isActive);return o?(0,s.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,s.jsx)(u.Qv,{}),(0,s.jsx)(u.Qv,{})]}):ea?(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:`${ea.color}15`},children:L?(0,s.jsx)("span",{className:"text-sm font-bold",style:{color:ea.color},children:ea.textIcon||ea.id.slice(0,2).toUpperCase()}):(0,s.jsx)(m.default,{src:en&&ea.apiType?"responses"===ea.apiType?"/providers/oai-r.png":"/providers/oai-cc.png":ed?"/providers/anthropic-m.png":`/providers/${ea.id}.png`,alt:ea.name,width:48,height:48,className:"object-contain rounded-lg max-w-[48px] max-h-[48px]",sizes:"48px",onError:()=>M(!0)})}),(0,s.jsxs)("div",{children:[ea.website?(0,s.jsxs)("a",{href:ea.website,target:"_blank",rel:"noopener noreferrer",className:"text-3xl font-semibold tracking-tight hover:underline inline-flex items-center gap-2",style:{color:ea.color},children:[ea.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:ea.name}),(0,s.jsxs)("p",{className:"text-text-muted",children:[i.length," connection",1===i.length?"":"s"]})]})]})]}),ec&&y&&(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:ed?V("anthropicCompatibleDetails"):V("openaiCompatibleDetails")}),(0,s.jsxs)("p",{className:"text-sm text-text-muted",children:[ed?V("messagesApi"):"responses"===y.apiType?V("responsesApi"):V("chatCompletions")," ","\xb7 ",(y.baseUrl||"").replace(/\/$/,""),"/",ed?"messages":"responses"===y.apiType?"responses":"chat/completions"]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:()=>E(!0),disabled:i.length>0,children:"Add"}),(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>P(!0),children:"Edit"}),(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"delete",onClick:async()=>{if(confirm(`Delete this ${ed?"Anthropic":"OpenAI"} Compatible node?`))try{(await fetch(`/api/provider-nodes/${r}`,{method:"DELETE"})).ok&&t.push("/dashboard/providers")}catch(e){console.log("Error deleting provider node:",e)}},children:"Delete"})]})]}),i.length>0&&(0,s.jsx)("p",{className:"text-sm text-text-muted",children:"Only one connection is allowed per compatible node. Add another node if you need more connections."})]}),(0,s.jsxs)(u.Zp,{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold",children:"Connections"}),!ec&&(0,s.jsx)(u.$n,{size:"sm",icon:"add",onClick:()=>ei?C(!0):E(!0),children:"Add"})]}),0===i.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:ei?"lock":"key"})}),(0,s.jsx)("p",{className:"text-text-main font-medium mb-1",children:"No connections yet"}),(0,s.jsx)("p",{className:"text-sm text-text-muted mb-4",children:"Add your first connection to get started"}),!ec&&(0,s.jsx)(u.$n,{icon:"add",onClick:()=>ei?C(!0):E(!0),children:"Add Connection"})]}):(0,s.jsx)("div",{className:"flex flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:i.sort((e,t)=>(e.priority||0)-(t.priority||0)).map((e,t)=>(0,s.jsx)(k,{connection:e,isOAuth:ei,isFirst:0===t,isLast:t===i.length-1,onMoveUp:()=>ek(e,i[t-1]),onMoveDown:()=>ek(e,i[t+1]),onToggleActive:t=>eN(e.id,t),onToggleRateLimit:t=>ew(e.id,t),onRetest:()=>eC(e.id),isRetesting:U===e.id,onEdit:()=>{q(e),I(!0)},onDelete:()=>eg(e.id),onReauth:ei?()=>C(!0):void 0,onProxy:()=>G({level:"key",id:e.id,label:e.name||e.email||e.id}),hasProxy:!!Q?.keys?.[e.id]},e.id))})]}),(0,s.jsxs)(u.Zp,{children:[(0,s.jsx)("h2",{className:"text-lg font-semibold mb-4",children:"Available Models"}),(()=>{if(ec)return(0,s.jsx)(N,{providerStorageAlias:em,providerDisplayAlias:ep,modelAliases:F,copied:z,onCopy:J,onSetAlias:ef,onDeleteAlias:ey,connections:i,isAnthropic:ed,onImportWithProgress:eA});if(ea.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:eS,disabled:!e$||X,children:X?V("importingModels"):V("importFromModels")}),!e$&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:V("addConnectionToImport")})]}),(0,s.jsx)(v,{providerAlias:eo,modelAliases:F,copied:z,onCopy:J,onSetAlias:ef,onDeleteAlias:ey})]});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:eS,disabled:!e$||X,children:X?V("importingModels"):V("importFromModels")}),!e$&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:V("addConnectionToImport")})]});return 0===el.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:el.map(e=>{let t=`${em}/${e.id}`,a=`${r}/${e.id}`,i=Object.entries(F).find(([,e])=>e===t||e===a)?.[0];return(0,s.jsx)(g,{model:e,fullModel:`${ep}/${e.id}`,alias:i,copied:z,onCopy:J,onSetAlias:t=>ef(e.id,t,em),onDeleteAlias:()=>ey(i)},e.id)})})]})})(),!ec&&(0,s.jsx)(j,{providerId:r,providerAlias:ep,copied:z,onCopy:J})]}),"kiro"===r?(0,s.jsx)(u.Mh,{isOpen:w,providerInfo:ea,onSuccess:ev,onClose:()=>{B.current=!0,C(!1)}}):"cursor"===r?(0,s.jsx)(u.G9,{isOpen:w,onSuccess:ev,onClose:()=>{B.current=!0,C(!1)}}):(0,s.jsx)(u.LF,{isOpen:w,provider:r,providerInfo:ea,onSuccess:ev,onClose:()=>{B.current=!0,C(!1)}}),(0,s.jsx)(S,{isOpen:T,provider:r,providerName:ea.name,isCompatible:ec,isAnthropic:ed,onSave:eb,onClose:()=>E(!1)}),(0,s.jsx)(A,{isOpen:R,connection:_,onSave:ej,onClose:()=>I(!1)}),ec&&(0,s.jsx)($,{isOpen:O,node:y,onSave:ex,onClose:()=>P(!1),isAnthropic:ed}),Z&&(0,s.jsx)(u.KN,{isOpen:!!Z,onClose:()=>G(null),level:Z.level,levelId:Z.id,levelLabel:Z.label}),(0,s.jsx)(u.aF,{isOpen:ee,onClose:()=>{("done"===er.phase||"error"===er.phase)&&et(!1)},title:"Importing Models",size:"md",closeOnOverlay:!1,showCloseButton:"done"===er.phase||"error"===er.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"===er.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"importing"===er.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"done"===er.phase&&(0,s.jsx)("span",{className:"material-symbols-outlined text-green-500",children:"check_circle"}),"error"===er.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:er.status})]}),("importing"===er.phase||"done"===er.phase)&&er.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:[er.current," / ",er.total]}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:[Math.round(er.current/er.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:`${er.current/er.total*100}%`,background:"done"===er.phase?"linear-gradient(90deg, #22c55e, #16a34a)":"linear-gradient(90deg, var(--color-primary), var(--color-primary-hover, var(--color-primary)))"}})})]}),"fetching"===er.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"===er.phase&&er.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:er.error})}),er.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:er.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"===er.phase&&er.importedCount>0&&(0,s.jsx)("p",{className:"text-xs text-text-muted text-center animate-pulse",children:"Page will refresh automatically..."})]})})]}):(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 g({model:e,fullModel:t,alias:r,copied:a,onCopy:i,onSetAlias:l,onDeleteAlias:o}){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:()=>i(t,`model-${e.id}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:"Copy model",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:a===`model-${e.id}`?"check":"content_copy"})})]})}function v({providerAlias:e,modelAliases:t,copied:r,onCopy:i,onSetAlias:l,onDeleteAlias:o}){let[n,d]=(0,a.useState)(""),[c,m]=(0,a.useState)(!1),p=Object.entries(t).filter(([,t])=>t.startsWith(`${e}/`)).map(([t,r])=>({modelId:r.replace(`${e}/`,""),fullModel:r,alias:t})),h=async()=>{let e;if(!n.trim()||c)return;let r=n.trim(),s=(e=r.split("/"))[e.length-1];if(t[s])return void alert(`Alias "${s}" already exists. Please use a different model or edit existing alias.`);m(!0);try{await l(r,s),d("")}catch(e){console.log("Error adding model:",e)}finally{m(!1)}};return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)("p",{className:"text-sm text-text-muted",children:"OpenRouter supports any model. Add models and create aliases for quick access."}),(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:"Model ID (from OpenRouter)"}),(0,s.jsx)("input",{id:"new-model-input",type:"text",value:n,onChange:e=>d(e.target.value),onKeyDown:e=>"Enter"===e.key&&h(),placeholder:"anthropic/claude-3-opus",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:h,disabled:!n.trim()||c,children:c?"Adding...":"Add"})]}),p.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-3",children:p.map(({modelId:e,fullModel:t,alias:a})=>(0,s.jsx)(b,{modelId:e,fullModel:t,copied:r,onCopy:i,onDeleteAlias:()=>o(a)},t))})]})}function b({modelId:e,fullModel:t,copied:r,onCopy:a,onDeleteAlias:i}){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:()=>a(t,`model-${e}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:"Copy model",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:r===`model-${e}`?"check":"content_copy"})})]})]}),(0,s.jsx)("button",{onClick:i,className:"p-1 hover:bg-red-50 rounded text-red-500",title:"Remove model",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})}function j({providerId:e,providerAlias:t,copied:r,onCopy:i}){let[l,o]=(0,a.useState)([]),[n,d]=(0,a.useState)(""),[c,m]=(0,a.useState)(""),[p,h]=(0,a.useState)(!1),[x,f]=(0,a.useState)(!0),y=(0,a.useCallback)(async()=>{try{let t=await fetch(`/api/provider-models?provider=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json();o(e.models||[])}}catch(e){console.error("Failed to fetch custom models:",e)}finally{f(!1)}},[e]);(0,a.useEffect)(()=>{y()},[y]);let g=async()=>{if(n.trim()&&!p){h(!0);try{(await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,modelId:n.trim(),modelName:c.trim()||void 0})})).ok&&(d(""),m(""),await y())}catch(e){console.error("Failed to add custom model:",e)}finally{h(!1)}}},v=async t=>{try{await fetch(`/api/provider-models?provider=${encodeURIComponent(e)}&model=${encodeURIComponent(t)}`,{method:"DELETE"}),await y()}catch(e){console.error("Failed to remove custom model:",e)}};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"}),"Custom Models"]}),(0,s.jsx)("p",{className:"text-xs text-text-muted mb-3",children:"Add model IDs not in the default list. These will be available for routing."}),(0,s.jsxs)("div",{className:"flex items-end gap-2 mb-3",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:"Model ID"}),(0,s.jsx)("input",{id:"custom-model-id",type:"text",value:n,onChange:e=>d(e.target.value),onKeyDown:e=>"Enter"===e.key&&g(),placeholder:"e.g. gpt-4.5-turbo",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:"Display Name"}),(0,s.jsx)("input",{id:"custom-model-name",type:"text",value:c,onChange:e=>m(e.target.value),onKeyDown:e=>"Enter"===e.key&&g(),placeholder:"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:g,disabled:!n.trim()||p,children:p?"Adding...":"Add"})]}),x?(0,s.jsx)("p",{className:"text-xs text-text-muted",children:"Loading..."}):l.length>0?(0,s.jsx)("div",{className:"flex flex-col gap-2",children:l.map(e=>{let a=`${t}/${e.id}`,l=`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",children:[(0,s.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:a}),(0,s.jsx)("button",{onClick:()=>i(a,l),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:"Copy model",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-sm",children:r===l?"check":"content_copy"})})]})]}),(0,s.jsx)("button",{onClick:()=>v(e.id),className:"p-1 hover:bg-red-50 rounded text-red-500",title:"Remove custom model",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:"No custom models added yet."})]})}function N({providerStorageAlias:e,providerDisplayAlias:t,modelAliases:r,copied:l,onCopy:o,onSetAlias:n,onDeleteAlias:d,connections:c,isAnthropic:m,onImportWithProgress:p}){let[h,x]=(0,a.useState)(""),[f,y]=(0,a.useState)(!1),[g,v]=(0,a.useState)(!1),j=(0,i.i)(),N=Object.entries(r).filter(([,t])=>t.startsWith(`${e}/`)).map(([t,r])=>({modelId:r.replace(`${e}/`,""),fullModel:r,alias:t})),w=e=>{let s,a=(s=e.split("/"))[s.length-1];if(!r[a])return a;let i=`${t}-${a}`;return r[i]?null:i},C=async()=>{if(!h.trim()||f)return;let t=h.trim(),r=w(t);if(!r)return void j.error("All suggested aliases already exist. Please choose a different model or remove conflicting aliases.");y(!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||"Failed to save custom model")}await n(t,r,e),x(""),j.success(`Model ${t} added successfully`)}catch(e){console.error("Error adding model:",e),j.error(e instanceof Error?e.message:"Failed to add model. Please try again.")}finally{y(!1)}},k=async()=>{if(g)return;let t=c.find(e=>!1!==e.isActive);if(t){v(!0);try{await p(async()=>{let e=await fetch(`/api/providers/${t.id}/models`),r=await e.json();if(!e.ok)throw Error(r.error||"Failed to import models");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):(j.error("Failed to save imported model to custom database"),!1))})}catch(e){console.error("Error importing models:",e),j.error("Failed to import models. Please try again.")}finally{v(!1)}}},S=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("Failed to remove model from database");await d(r),j.success("Model removed successfully")}catch(e){console.error("Error deleting model:",e),j.error(e instanceof Error?e.message:"Failed to delete model. Please try again.")}};return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsxs)("p",{className:"text-sm text-text-muted",children:["Add ",m?"Anthropic":"OpenAI","-compatible models manually or import them from the /models endpoint."]}),(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:"Model ID"}),(0,s.jsx)("input",{id:"new-compatible-model-input",type:"text",value:h,onChange:e=>x(e.target.value),onKeyDown:e=>"Enter"===e.key&&C(),placeholder:m?"claude-3-opus-20240229":"gpt-4o",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:C,disabled:!h.trim()||f,children:f?"Adding...":"Add"}),(0,s.jsx)(u.$n,{size:"sm",variant:"secondary",icon:"download",onClick:k,disabled:!S||g,children:g?"Importing...":"Import from /models"})]}),!S&&(0,s.jsx)("p",{className:"text-xs text-text-muted",children:"Add a connection to enable importing models."}),N.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-3",children:N.map(({modelId:e,fullModel:r,alias:a})=>(0,s.jsx)(b,{modelId:e,fullModel:`${t}/${e}`,copied:l,onCopy:o,onDeleteAlias:()=>A(e,a)},r))})]})}function w({until:e}){let[t,r]=(0,a.useState)("");return((0,a.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}g.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},b.propTypes={modelId:o().string.isRequired,fullModel:o().string.isRequired,copied:o().string,onCopy:o().func.isRequired,onDeleteAlias:o().func.isRequired},j.propTypes={providerId:o().string.isRequired,providerAlias:o().string.isRequired,copied:o().string,onCopy:o().func.isRequired},N.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},w.propTypes={until:o().string.isRequired};let C={runtime_error:{label:"Local runtime",variant:"warning"},upstream_auth_error:{label:"Upstream auth",variant:"error"},auth_missing:{label:"Missing credential",variant:"warning"},token_refresh_failed:{label:"Refresh failed",variant:"warning"},token_expired:{label:"Token expired",variant:"warning"},upstream_rate_limited:{label:"Rate limited",variant:"warning"},upstream_unavailable:{label:"Upstream unavailable",variant:"error"},network_error:{label:"Network error",variant:"warning"},unsupported:{label:"Test unsupported",variant:"default"},upstream_error:{label:"Upstream error",variant:"error"}};function k({connection:e,isOAuth:t,isFirst:r,isLast:i,onMoveUp:l,onMoveDown:o,onToggleActive:n,onToggleRateLimit:d,onRetest:c,isRetesting:m,onEdit:p,onDelete:h,onReauth:x,onProxy:f,hasProxy:y}){let g=t?e.name||e.email||e.displayName||"OAuth Account":e.name,[v,b]=(0,a.useState)(!1);(0,a.useEffect)(()=>{let t=()=>{b(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 j="unavailable"!==e.testStatus||v?e.testStatus:"active",N=function(e,t,r){if(!1===e.isActive)return{statusVariant:"default",statusLabel:"disabled",errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};if("active"===t||"success"===t)return{statusVariant:"success",statusLabel:"connected",errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};let s=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=s&&C[s]||null;return"runtime_error"===s?{statusVariant:"warning",statusLabel:"runtime issue",errorType:s,errorBadge:a,errorTextClass:"text-yellow-600 dark:text-yellow-400"}:"upstream_auth_error"===s||"auth_missing"===s||"token_refresh_failed"===s||"token_expired"===s?{statusVariant:"error",statusLabel:"auth failed",errorType:s,errorBadge:a,errorTextClass:"text-red-500"}:"upstream_rate_limited"===s?{statusVariant:"warning",statusLabel:"rate limited",errorType:s,errorBadge:a,errorTextClass:"text-yellow-600 dark:text-yellow-400"}:"network_error"===s?{statusVariant:"warning",statusLabel:"network issue",errorType:s,errorBadge:a,errorTextClass:"text-yellow-600 dark:text-yellow-400"}:"unsupported"===s?{statusVariant:"default",statusLabel:"test unsupported",errorType:s,errorBadge:a,errorTextClass:"text-text-muted"}:{statusVariant:"error",statusLabel:t||"error",errorType:s,errorBadge:a,errorTextClass:"text-red-500"}}(e,j,v),k=!!e.rateLimitProtection;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:l,disabled:r,className:`p-0.5 rounded ${r?"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:o,disabled:i,className:`p-0.5 rounded ${i?"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:g}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[(0,s.jsx)(u.Ex,{variant:N.statusVariant,size:"sm",dot:!0,children:N.statusLabel}),v&&!1!==e.isActive&&(0,s.jsx)(w,{until:e.rateLimitedUntil}),N.errorBadge&&!1!==e.isActive&&(0,s.jsx)(u.Ex,{variant:N.errorBadge.variant,size:"sm",children:N.errorBadge.label}),e.lastError&&!1!==e.isActive&&(0,s.jsx)("span",{className:`text-xs truncate max-w-[300px] ${N.errorTextClass}`,title:e.lastError,children:e.lastError}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:["#",e.priority]}),e.globalPriority&&(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:["Auto: ",e.globalPriority]}),(0,s.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,s.jsxs)("button",{onClick:()=>d(!k),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${k?"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:k?"Click to disable rate limit protection":"Click to enable rate limit protection",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"shield"}),k?"Protected":"Unprotected"]}),y&&(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 bg-primary/15 text-primary",title:"Proxy configured",children:[(0,s.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"vpn_lock"}),"Proxy"]})]})]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(u.$n,{size:"sm",variant:"ghost",icon:"refresh",loading:m,disabled:!1===e.isActive,onClick:c,className:"!h-7 !px-2 text-xs",title:"Retest authentication",children:"Retest"}),(0,s.jsx)(u.lM,{size:"sm",checked:e.isActive??!0,onChange:n,title:e.isActive??!0?"Disable connection":"Enable connection"}),(0,s.jsxs)("div",{className:"flex gap-1 ml-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[x&&(0,s.jsx)("button",{onClick:x,className:"p-2 hover:bg-amber-500/10 rounded text-amber-600 hover:text-amber-500",title:"Re-authenticate this connection",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"passkey"})}),(0,s.jsx)("button",{onClick:p,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),(0,s.jsx)("button",{onClick:f,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",title:"Proxy config",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"vpn_lock"})}),(0,s.jsx)("button",{onClick:h,className:"p-2 hover:bg-red-500/10 rounded text-red-500",children:(0,s.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]})]})}function S({isOpen:e,provider:t,providerName:r,isCompatible:i,isAnthropic:l,onSave:o,onClose:n}){let[d,c]=(0,a.useState)({name:"",apiKey:"",priority:1}),[m,p]=(0,a.useState)(!1),[h,x]=(0,a.useState)(null),[f,y]=(0,a.useState)(!1),[g,v]=(0,a.useState)(null),b=async()=>{p(!0),v(null);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:d.apiKey})}),r=await e.json();x(r.valid?"success":"failed")}catch{x("failed")}finally{p(!1)}},j=async()=>{if(t&&d.apiKey){y(!0),v(null);try{let e=!1;try{p(!0),x(null);let r=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:d.apiKey})});e=!!(await r.json()).valid,x(e?"success":"failed")}catch{x("failed")}finally{p(!1)}if(!e)return void v("API key validation failed. Please check your key and try again.");let r=await o({name:d.name,apiKey:d.apiKey,priority:d.priority,testStatus:"active"});r&&v("string"==typeof r?r:"Failed to save connection")}finally{y(!1)}}};return t?(0,s.jsx)(u.aF,{isOpen:e,title:`Add ${r||t} API Key`,onClose:n,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(u.pd,{label:"Name",value:d.name,onChange:e=>c({...d,name:e.target.value}),placeholder:"Production Key"}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.pd,{label:"API Key",type:"password",value:d.apiKey,onChange:e=>c({...d,apiKey:e.target.value}),className:"flex-1"}),(0,s.jsx)("div",{className:"pt-6",children:(0,s.jsx)(u.$n,{onClick:b,disabled:!d.apiKey||m||f,variant:"secondary",children:m?"Checking...":"Check"})})]}),h&&(0,s.jsx)(u.Ex,{variant:"success"===h?"success":"error",children:"success"===h?"Valid":"Invalid"}),g&&(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:g}),i&&(0,s.jsx)("p",{className:"text-xs text-text-muted",children:l?`Validation checks ${r||"Anthropic Compatible"} by verifying the API key.`:`Validation checks ${r||"OpenAI Compatible"} via /models on your base URL.`}),(0,s.jsx)(u.pd,{label:"Priority",type:"number",value:d.priority,onChange:e=>c({...d,priority:Number.parseInt(e.target.value)||1})}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.$n,{onClick:j,fullWidth:!0,disabled:!d.name||!d.apiKey||f,children:f?"Saving...":"Save"}),(0,s.jsx)(u.$n,{onClick:n,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}function A({isOpen:e,connection:t,onSave:r,onClose:i}){let[l,o]=(0,a.useState)({name:"",priority:1,apiKey:"",healthCheckInterval:60}),[n,d]=(0,a.useState)(!1),[c,m]=(0,a.useState)(null),[p,x]=(0,a.useState)(!1),[f,y]=(0,a.useState)(null),[g,v]=(0,a.useState)(!1);(0,a.useEffect)(()=>{t&&(o({name:t.name||"",priority:t.priority||1,apiKey:"",healthCheckInterval:t.healthCheckInterval??60}),m(null),y(null))},[t]);let b=async()=>{if(t?.provider){d(!0),m(null);try{let e=await fetch(`/api/providers/${t.id}/test`,{method:"POST"}),r=await e.json();m({valid:!!r.valid,diagnosis:r.diagnosis||null,message:r.error||null})}catch{m({valid:!1,diagnosis:{type:"network_error"},message:"Failed to test connection"})}finally{d(!1)}}},j=async()=>{if(t?.provider&&l.apiKey){x(!0),y(null);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t.provider,apiKey:l.apiKey})}),r=await e.json();y(r.valid?"success":"failed")}catch{y("failed")}finally{x(!1)}}},N=async()=>{v(!0);try{let e={name:l.name,priority:l.priority,healthCheckInterval:l.healthCheckInterval};if(!w&&l.apiKey){e.apiKey=l.apiKey;let r="success"===f;if(!r)try{x(!0),y(null);let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t.provider,apiKey:l.apiKey})});r=!!(await e.json()).valid,y(r?"success":"failed")}catch{y("failed")}finally{x(!1)}r&&(e.testStatus="active",e.lastError=null,e.lastErrorAt=null,e.lastErrorType=null,e.lastErrorSource=null,e.errorCode=null,e.rateLimitedUntil=null)}await r(e)}finally{v(!1)}};if(!t)return null;let w="oauth"===t.authType,k=(0,h.mq)(t.provider)||(0,h.gb)(t.provider),S=!c?.valid&&c?.diagnosis?.type&&C[c.diagnosis.type]||null;return(0,s.jsx)(u.aF,{isOpen:e,title:"Edit Connection",onClose:i,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(u.pd,{label:"Name",value:l.name,onChange:e=>o({...l,name:e.target.value}),placeholder:w?"Account name":"Production Key"}),w&&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:"Email"}),(0,s.jsx)("p",{className:"font-medium",children:t.email})]}),w&&(0,s.jsx)(u.pd,{label:"Health Check (min)",type:"number",value:l.healthCheckInterval,onChange:e=>o({...l,healthCheckInterval:Math.max(0,Number.parseInt(e.target.value)||0)}),hint:"Proactive token refresh interval. 0 = disabled."}),(0,s.jsx)(u.pd,{label:"Priority",type:"number",value:l.priority,onChange:e=>o({...l,priority:Number.parseInt(e.target.value)||1})}),!w&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.pd,{label:"API Key",type:"password",value:l.apiKey,onChange:e=>o({...l,apiKey:e.target.value}),placeholder:"Enter new API key",hint:"Leave blank to keep the current API key.",className:"flex-1"}),(0,s.jsx)("div",{className:"pt-6",children:(0,s.jsx)(u.$n,{onClick:j,disabled:!l.apiKey||p||g,variant:"secondary",children:p?"Checking...":"Check"})})]}),f&&(0,s.jsx)(u.Ex,{variant:"success"===f?"success":"error",children:"success"===f?"Valid":"Invalid"})]}),!k&&(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(u.$n,{onClick:b,variant:"secondary",disabled:n,children:n?"Testing...":"Test Connection"}),c&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.Ex,{variant:c.valid?"success":"error",children:c.valid?"Valid":"Failed"}),S&&(0,s.jsx)(u.Ex,{variant:S.variant,children:S.label})]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.$n,{onClick:N,fullWidth:!0,disabled:g,children:g?"Saving...":"Save"}),(0,s.jsx)(u.$n,{onClick:i,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}function $({isOpen:e,node:t,onSave:r,onClose:i,isAnthropic:l}){let[o,n]=(0,a.useState)({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[d,c]=(0,a.useState)(!1),[m,p]=(0,a.useState)(""),[h,x]=(0,a.useState)(!1),[f,y]=(0,a.useState)(null);(0,a.useEffect)(()=>{t&&n({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 g=async()=>{if(o.name.trim()&&o.prefix.trim()&&o.baseUrl.trim()){c(!0);try{let e={name:o.name,prefix:o.prefix,baseUrl:o.baseUrl};l||(e.apiType=o.apiType),await r(e)}finally{c(!1)}}},v=async()=>{x(!0);try{let e=await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:o.baseUrl,apiKey:m,type:l?"anthropic-compatible":"openai-compatible"})}),t=await e.json();y(t.valid?"success":"failed")}catch{y("failed")}finally{x(!1)}};return t?(0,s.jsx)(u.aF,{isOpen:e,title:`Edit ${l?"Anthropic":"OpenAI"} Compatible`,onClose:i,children:(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)(u.pd,{label:"Name",value:o.name,onChange:e=>n({...o,name:e.target.value}),placeholder:`${l?"Anthropic":"OpenAI"} Compatible (Prod)`,hint:"Required. A friendly label for this node."}),(0,s.jsx)(u.pd,{label:"Prefix",value:o.prefix,onChange:e=>n({...o,prefix:e.target.value}),placeholder:l?"ac-prod":"oc-prod",hint:"Required. Used as the provider prefix for model IDs."}),!l&&(0,s.jsx)(u.l6,{label:"API Type",options:[{value:"chat",label:"Chat Completions"},{value:"responses",label:"Responses API"}],value:o.apiType,onChange:e=>n({...o,apiType:e.target.value})}),(0,s.jsx)(u.pd,{label:"Base URL",value:o.baseUrl,onChange:e=>n({...o,baseUrl:e.target.value}),placeholder:l?"https://api.anthropic.com/v1":"https://api.openai.com/v1",hint:`Use the base URL (ending in /v1) for your ${l?"Anthropic":"OpenAI"}-compatible API.`}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.pd,{label:"API Key (for Check)",type:"password",value:m,onChange:e=>p(e.target.value),className:"flex-1"}),(0,s.jsx)("div",{className:"pt-6",children:(0,s.jsx)(u.$n,{onClick:v,disabled:!m||h||!o.baseUrl.trim(),variant:"secondary",children:h?"Checking...":"Check"})})]}),f&&(0,s.jsx)(u.Ex,{variant:"success"===f?"success":"error",children:"success"===f?"Valid":"Invalid"}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(u.$n,{onClick:g,fullWidth:!0,disabled:!o.name.trim()||!o.prefix.trim()||!o.baseUrl.trim()||d,children:d?"Saving...":"Save"}),(0,s.jsx)(u.$n,{onClick:i,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}k.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}).isRequired,isOAuth:o().bool.isRequired,isFirst:o().bool.isRequired,isLast:o().bool.isRequired,onMoveUp:o().func.isRequired,onMoveDown:o().func.isRequired,onToggleActive:o().func.isRequired,onToggleRateLimit:o().func.isRequired,onRetest:o().func.isRequired,isRetesting:o().bool,onEdit:o().func.isRequired,onDelete:o().func.isRequired,onReauth:o().func},S.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},A.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},$.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,[3418,8500,9751,782,6458,5846,993,8441,3794,7358],()=>e(e.s=56411)),_N_E=e.O()}]);