@yina-npm/openrouterx 0.4.71 → 0.4.72

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 (115) hide show
  1. package/app/.next/BUILD_ID +1 -1
  2. package/app/.next/app-path-routes-manifest.json +2 -2
  3. package/app/.next/build-manifest.json +2 -2
  4. package/app/.next/server/app/(dashboard)/dashboard/admin/keys/page_client-reference-manifest.js +1 -1
  5. package/app/.next/server/app/(dashboard)/dashboard/admin/users/page_client-reference-manifest.js +1 -1
  6. package/app/.next/server/app/(dashboard)/dashboard/basic-chat/page_client-reference-manifest.js +1 -1
  7. package/app/.next/server/app/(dashboard)/dashboard/cli-tools/[toolId]/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/console-log/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/media-providers/[kind]/[id]/page_client-reference-manifest.js +1 -1
  13. package/app/.next/server/app/(dashboard)/dashboard/media-providers/[kind]/page_client-reference-manifest.js +1 -1
  14. package/app/.next/server/app/(dashboard)/dashboard/media-providers/combo/[id]/page_client-reference-manifest.js +1 -1
  15. package/app/.next/server/app/(dashboard)/dashboard/media-providers/web/page_client-reference-manifest.js +1 -1
  16. package/app/.next/server/app/(dashboard)/dashboard/mitm/page_client-reference-manifest.js +1 -1
  17. package/app/.next/server/app/(dashboard)/dashboard/page_client-reference-manifest.js +1 -1
  18. package/app/.next/server/app/(dashboard)/dashboard/profile/page_client-reference-manifest.js +1 -1
  19. package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page.js +1 -1
  20. package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
  21. package/app/.next/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
  22. package/app/.next/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
  23. package/app/.next/server/app/(dashboard)/dashboard/proxy-pools/page_client-reference-manifest.js +1 -1
  24. package/app/.next/server/app/(dashboard)/dashboard/quota/page_client-reference-manifest.js +1 -1
  25. package/app/.next/server/app/(dashboard)/dashboard/skills/page_client-reference-manifest.js +1 -1
  26. package/app/.next/server/app/(dashboard)/dashboard/translator/page_client-reference-manifest.js +1 -1
  27. package/app/.next/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
  28. package/app/.next/server/app/(dashboard)/dashboard/user/page_client-reference-manifest.js +1 -1
  29. package/app/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  30. package/app/.next/server/app/_global-error.html +1 -1
  31. package/app/.next/server/app/_global-error.rsc +1 -1
  32. package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  33. package/app/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  34. package/app/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  35. package/app/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  36. package/app/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  37. package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  38. package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  39. package/app/.next/server/app/_not-found.html +1 -1
  40. package/app/.next/server/app/_not-found.rsc +3 -3
  41. package/app/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  42. package/app/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  43. package/app/.next/server/app/_not-found.segments/_index.segment.rsc +3 -3
  44. package/app/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  45. package/app/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  46. package/app/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  47. package/app/.next/server/app/api/models/route.js +1 -1
  48. package/app/.next/server/app/api/models/test/route.js +1 -1
  49. package/app/.next/server/app/api/providers/[id]/test-models/route.js +1 -1
  50. package/app/.next/server/app/api/providers/route.js +1 -1
  51. package/app/.next/server/app/api/translator/console-logs/route.js +1 -1
  52. package/app/.next/server/app/api/translator/console-logs/stream/route.js +1 -1
  53. package/app/.next/server/app/api/version/route.js +1 -1
  54. package/app/.next/server/app/api/version/shutdown/route.js +1 -1
  55. package/app/.next/server/app/api/version/update/route.js +1 -1
  56. package/app/.next/server/app/callback/page_client-reference-manifest.js +1 -1
  57. package/app/.next/server/app/callback.html +1 -1
  58. package/app/.next/server/app/callback.rsc +3 -3
  59. package/app/.next/server/app/callback.segments/_full.segment.rsc +3 -3
  60. package/app/.next/server/app/callback.segments/_head.segment.rsc +1 -1
  61. package/app/.next/server/app/callback.segments/_index.segment.rsc +3 -3
  62. package/app/.next/server/app/callback.segments/_tree.segment.rsc +1 -1
  63. package/app/.next/server/app/callback.segments/callback/__PAGE__.segment.rsc +1 -1
  64. package/app/.next/server/app/callback.segments/callback.segment.rsc +1 -1
  65. package/app/.next/server/app/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
  66. package/app/.next/server/app/dashboard/settings/pricing.html +1 -1
  67. package/app/.next/server/app/dashboard/settings/pricing.rsc +3 -3
  68. package/app/.next/server/app/dashboard/settings/pricing.segments/_full.segment.rsc +3 -3
  69. package/app/.next/server/app/dashboard/settings/pricing.segments/_head.segment.rsc +1 -1
  70. package/app/.next/server/app/dashboard/settings/pricing.segments/_index.segment.rsc +3 -3
  71. package/app/.next/server/app/dashboard/settings/pricing.segments/_tree.segment.rsc +1 -1
  72. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing/__PAGE__.segment.rsc +1 -1
  73. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing.segment.rsc +1 -1
  74. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings.segment.rsc +1 -1
  75. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard.segment.rsc +1 -1
  76. package/app/.next/server/app/index.html +1 -1
  77. package/app/.next/server/app/index.rsc +3 -3
  78. package/app/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  79. package/app/.next/server/app/index.segments/_full.segment.rsc +3 -3
  80. package/app/.next/server/app/index.segments/_head.segment.rsc +1 -1
  81. package/app/.next/server/app/index.segments/_index.segment.rsc +3 -3
  82. package/app/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  83. package/app/.next/server/app/landing/page_client-reference-manifest.js +1 -1
  84. package/app/.next/server/app/landing.html +1 -1
  85. package/app/.next/server/app/landing.rsc +3 -3
  86. package/app/.next/server/app/landing.segments/_full.segment.rsc +3 -3
  87. package/app/.next/server/app/landing.segments/_head.segment.rsc +1 -1
  88. package/app/.next/server/app/landing.segments/_index.segment.rsc +3 -3
  89. package/app/.next/server/app/landing.segments/_tree.segment.rsc +1 -1
  90. package/app/.next/server/app/landing.segments/landing/__PAGE__.segment.rsc +1 -1
  91. package/app/.next/server/app/landing.segments/landing.segment.rsc +1 -1
  92. package/app/.next/server/app/login/page_client-reference-manifest.js +1 -1
  93. package/app/.next/server/app/login.html +1 -1
  94. package/app/.next/server/app/login.rsc +4 -4
  95. package/app/.next/server/app/login.segments/_full.segment.rsc +4 -4
  96. package/app/.next/server/app/login.segments/_head.segment.rsc +1 -1
  97. package/app/.next/server/app/login.segments/_index.segment.rsc +3 -3
  98. package/app/.next/server/app/login.segments/_tree.segment.rsc +1 -1
  99. package/app/.next/server/app/login.segments/login/__PAGE__.segment.rsc +2 -2
  100. package/app/.next/server/app/login.segments/login.segment.rsc +1 -1
  101. package/app/.next/server/app/page_client-reference-manifest.js +1 -1
  102. package/app/.next/server/app-paths-manifest.json +2 -2
  103. package/app/.next/server/chunks/1350.js +1 -1
  104. package/app/.next/server/chunks/3110.js +1 -1
  105. package/app/.next/server/chunks/8220.js +1 -1
  106. package/app/.next/server/chunks/9203.js +1 -1
  107. package/app/.next/server/middleware-build-manifest.js +1 -1
  108. package/app/.next/server/pages/404.html +1 -1
  109. package/app/.next/server/pages/500.html +1 -1
  110. package/app/.next/static/chunks/{1321-9d7d6181b08dfcf4.js → 1321-58e5381616484736.js} +1 -1
  111. package/app/.next/static/chunks/app/(dashboard)/dashboard/providers/[id]/{page-7cd7e81cc32bcf4d.js → page-1690d87838647d4e.js} +2 -2
  112. package/app/package.json +1 -1
  113. package/package.json +1 -1
  114. /package/app/.next/static/{jssxgK5Jb3snQyFlT_oQ6 → rGKKdynzip7FM3GQ6xztk}/_buildManifest.js +0 -0
  115. /package/app/.next/static/{jssxgK5Jb3snQyFlT_oQ6 → rGKKdynzip7FM3GQ6xztk}/_ssgManifest.js +0 -0
@@ -1,3 +1,3 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2134],{7570:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>$});var a=s(95155),i=s(12115),l=s(73321),r=s(98500),n=s.n(r),o=s(5772),d=s(35497),c=s(52679),p=s(28777),m=s(11059),x=s(73006);let u=new Map;async function h(e){if(!e?.url||!e?.type)return[];let t=u.get(e.url);if(t&&Date.now()<t.expiresAt)return t.data;try{let t=new URLSearchParams({url:e.url,type:e.type}),s=await fetch(`/api/providers/suggested-models?${t}`);if(!s.ok)return[];let a=(await s.json()).data??[];return u.set(e.url,{data:a,expiresAt:Date.now()+6e5}),a}catch{return[]}}var f=s(14051),g=s.n(f);function y({model:e,fullModel:t,displayModel:s,alias:i,copied:l,onCopy:r,testStatus:n,isCustom:o,isFree:d,onDeleteAlias:c,onTest:p,isTesting:m,onDisable:x}){let u="ok"===n?"#22c55e":"error"===n?"#ef4444":void 0;return(0,a.jsx)("div",{className:`group min-w-0 max-w-full rounded-lg border px-3 py-2 ${"ok"===n?"border-green-500/40":"error"===n?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:(0,a.jsxs)("div",{className:"flex min-w-0 items-start gap-2 sm:items-center",children:[(0,a.jsx)("span",{className:"material-symbols-outlined shrink-0 text-base",style:u?{color:u}:void 0,children:"ok"===n?"check_circle":"error"===n?"cancel":"smart_toy"}),(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[(0,a.jsx)("code",{className:"max-w-[72vw] truncate rounded bg-sidebar px-1.5 py-0.5 font-mono text-xs text-text-muted sm:max-w-[360px]",children:s||t}),e.name&&(0,a.jsx)("span",{className:"truncate pl-1 text-[9px] italic text-text-muted/70",children:e.name})]}),p&&(0,a.jsxs)("div",{className:"relative shrink-0 group/btn",children:[(0,a.jsx)("button",{onClick:p,disabled:m,className:`rounded p-0.5 text-text-muted transition-opacity hover:bg-sidebar hover:text-primary ${m?"opacity-100":"opacity-100 sm:opacity-0 sm:group-hover:opacity-100"}`,children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",style:m?{animation:"spin 1s linear infinite"}:void 0,children:m?"progress_activity":"science"})}),(0,a.jsx)("span",{className:"pointer-events-none absolute mt-1 top-5 left-1/2 -translate-x-1/2 text-[10px] text-text-muted whitespace-nowrap opacity-0 group-hover/btn:opacity-100 transition-opacity",children:m?"Testing...":"Test"})]}),(0,a.jsxs)("div",{className:"relative shrink-0 group/btn",children:[(0,a.jsx)("button",{onClick:()=>r(t,`model-${e.id}`),className:"rounded p-0.5 text-text-muted hover:bg-sidebar hover:text-primary",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:l===`model-${e.id}`?"check":"content_copy"})}),(0,a.jsx)("span",{className:"pointer-events-none absolute mt-1 top-5 left-1/2 -translate-x-1/2 text-[10px] text-text-muted whitespace-nowrap opacity-0 group-hover/btn:opacity-100 transition-opacity",children:l===`model-${e.id}`?"Copied!":"Copy"})]}),o?(0,a.jsx)("button",{onClick:c,className:"ml-auto rounded p-0.5 text-text-muted opacity-100 transition-opacity hover:bg-red-500/10 hover:text-red-500 sm:opacity-0 sm:group-hover:opacity-100",title:"Remove custom model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})}):x?(0,a.jsx)("button",{onClick:x,className:"ml-auto rounded p-0.5 text-text-muted opacity-100 transition-opacity hover:bg-red-500/10 hover:text-red-500 sm:opacity-0 sm:group-hover:opacity-100",title:"Disable this model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})}):null]})})}function b({modelId:e,fullModel:t,copied:s,onCopy:i,onDeleteAlias:l,onTest:r,testStatus:n,isTesting:o}){let d="ok"===n?"#22c55e":"error"===n?"#ef4444":void 0;return(0,a.jsxs)("div",{className:`flex items-center gap-3 p-3 rounded-lg border ${"ok"===n?"border-green-500/40":"error"===n?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",style:d?{color:d}:void 0,children:"ok"===n?"check_circle":"error"===n?"cancel":"smart_toy"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-medium truncate",children:e}),(0,a.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,a.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:t}),(0,a.jsxs)("div",{className:"relative group/btn",children:[(0,a.jsx)("button",{onClick:()=>i(t,`model-${e}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:s===`model-${e}`?"check":"content_copy"})}),(0,a.jsx)("span",{className:"pointer-events-none absolute top-5 left-1/2 -translate-x-1/2 text-[10px] text-text-muted whitespace-nowrap opacity-0 group-hover/btn:opacity-100 transition-opacity",children:s===`model-${e}`?"Copied!":"Copy"})]}),r&&(0,a.jsxs)("div",{className:"relative group/btn",children:[(0,a.jsx)("button",{onClick:r,disabled:o,className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary transition-colors",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",style:o?{animation:"spin 1s linear infinite"}:void 0,children:o?"progress_activity":"science"})}),(0,a.jsx)("span",{className:"pointer-events-none absolute top-5 left-1/2 -translate-x-1/2 text-[10px] text-text-muted whitespace-nowrap opacity-0 group-hover/btn:opacity-100 transition-opacity",children:o?"Testing...":"Test"})]})]})]}),(0,a.jsx)("button",{onClick:l,className:"p-1 hover:bg-red-50 rounded text-red-500",title:"Remove model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})}function v({providerStorageAlias:e,providerDisplayAlias:t,modelAliases:s,copied:l,onCopy:r,onSetAlias:n,onDeleteAlias:o,connections:c,isAnthropic:p}){let[m,x]=(0,i.useState)(""),[u,h]=(0,i.useState)(!1),[f,g]=(0,i.useState)(!1),[y,j]=(0,i.useState)(null),[w,N]=(0,i.useState)({}),k=async t=>{if(!y){j(t);try{let s=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${e}/${t}`})}),a=await s.json();N(e=>({...e,[t]:a.ok?"ok":"error"}))}catch{N(e=>({...e,[t]:"error"}))}finally{j(null)}}},C=Object.entries(s).filter(([,t])=>t.startsWith(`${e}/`)).map(([t,s])=>({modelId:s.replace(`${e}/`,""),fullModel:s,alias:t})),S=a=>{let i,l=`${e}/${a}`;if(Object.values(s).includes(l))return null;let r=(i=a.split("/"))[i.length-1];if(!s[r])return r;let n=`${t}-${r}`;return s[n]?null:n},A=async()=>{if(!m.trim()||u)return;let t=m.trim(),s=S(t);if(!s)return void alert("All suggested aliases already exist. Please choose a different model or remove conflicting aliases.");h(!0);try{await n(t,s,e),x("")}catch(e){console.log("Error adding model:",e)}finally{h(!1)}},$=async()=>{if(f)return;let t=c.find(e=>!1!==e.isActive);if(t){g(!0);try{let s=await fetch(`/api/providers/${t.id}/models`),a=await s.json();if(!s.ok)return void alert(a.error||"Failed to import models");let i=a.models||[];if(0===i.length)return void alert("No models returned from /models.");let l=0;for(let t of i){let s=t.id||t.name||t.model;if(!s)continue;let a=S(s);a&&(await n(s,a,e),l+=1)}0===l&&alert("No new models were added.")}catch(e){console.log("Error importing models:",e)}finally{g(!1)}}},T=c.some(e=>!1!==e.isActive);return(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("p",{className:"text-sm text-text-muted",children:["Add ",p?"Anthropic":"OpenAI","-compatible models manually or import them from the /models endpoint."]}),(0,a.jsxs)("div",{className:"flex items-end gap-2 flex-wrap",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,a.jsx)("label",{htmlFor:"new-compatible-model-input",className:"text-xs text-text-muted mb-1 block",children:"Model ID"}),(0,a.jsx)("input",{id:"new-compatible-model-input",type:"text",value:m,onChange:e=>x(e.target.value),onKeyDown:e=>"Enter"===e.key&&A(),placeholder:p?"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,a.jsx)(d.$n,{size:"sm",icon:"add",onClick:A,disabled:!m.trim()||u,children:u?"Adding...":"Add"}),(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"download",onClick:$,disabled:!T||f,children:f?"Importing...":"Import from /models"})]}),!T&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Add a connection to enable importing models."}),C.length>0&&(0,a.jsx)("div",{className:"flex flex-col gap-3",children:C.map(({modelId:e,fullModel:s,alias:i})=>(0,a.jsx)(b,{modelId:e,fullModel:`${t}/${e}`,copied:l,onCopy:r,onDeleteAlias:()=>o(i),onTest:c.length>0?()=>k(e):void 0,testStatus:w[e],isTesting:y===e},s))})]})}function j({until:e}){let[t,s]=(0,i.useState)("");return((0,i.useEffect)(()=>{let t=()=>{let t=new Date(e).getTime()-Date.now();if(t<=0)return void s("");let a=Math.floor(t/1e3);if(a<60)s(`${a}s`);else if(a<3600)s(`${Math.floor(a/60)}m ${a%60}s`);else{let e=Math.floor(a/3600),t=Math.floor(a%3600/60);s(`${e}h ${t}m`)}};t();let a=setInterval(t,1e3);return()=>clearInterval(a)},[e]),t)?(0,a.jsxs)("span",{className:"text-xs text-orange-500 font-mono",children:["⏱ ",t]}):null}function w({connection:e,proxyPools:t,isOAuth:s,isFirst:l,isLast:r,onMoveUp:n,onMoveDown:o,onToggleActive:c,onUpdateProxy:p,onEdit:m,onDelete:x,oneByOneStatus:u=null}){let[h,f]=(0,i.useState)(!1),[g,y]=(0,i.useState)(!1),b=(0,i.useRef)(null),v=new Map((t||[]).map(e=>[e.id,e])),N=e.providerSpecificData?.proxyPoolId||null,k=N?v.get(N):null,C=e.providerSpecificData?.connectionProxyEnabled===!0&&!!e.providerSpecificData?.connectionProxyUrl,S=!!N||C,A=k?`Pool: ${k.name}`:N?`Pool: ${N} (inactive/missing)`:C?`Legacy: ${e.providerSpecificData?.connectionProxyUrl}`:"",$="";if(k?.proxyUrl||e.providerSpecificData?.connectionProxyUrl){let t=k?.proxyUrl||e.providerSpecificData?.connectionProxyUrl;try{let e=new URL(t);$=`${e.protocol}//${e.hostname}${e.port?`:${e.port}`:""}`}catch{$=t}}let T=k?.noProxy||e.providerSpecificData?.connectionNoProxy||"",O="default";k?.isActive===!0?O="success":(N||C)&&(O="error"),(0,i.useEffect)(()=>{if(!h)return;let e=e=>{b.current&&!b.current.contains(e.target)&&f(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[h]);let P=async e=>{y(!0);try{await p("__none__"===e?null:e)}finally{y(!1),f(!1)}},I=e.authType||(s?"oauth":"apikey"),E="oauth"===I,R="cookie"===I,_=e=>"string"==typeof e&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),U=E?_(e.email)?e.email:_(e.name)?e.name:e.name||e.email||e.displayName||"OAuth Account":e.name||e.email||e.displayName||"API Key",[D,z]=(0,i.useState)(!1),q=Object.entries(e).filter(([e])=>e.startsWith("modelLock_")).map(([,e])=>e).filter(e=>!!e).sort()[0]||null;(0,i.useEffect)(()=>{let t=()=>{z(!!Object.entries(e).filter(([e])=>e.startsWith("modelLock_")).map(([,e])=>e).filter(e=>e&&new Date(e).getTime()>Date.now()).sort()[0])};t();let s=q?setInterval(t,1e3):null;return()=>{s&&clearInterval(s)}},[q]);let M="unavailable"!==e.testStatus||D?e.testStatus:"active",F=()=>u?"queued"===u.state?"queued":"testing"===u.state?"testing":"success"===u.state?"success":"failed"===u.state?u.error?`failed: ${u.error}`:"failed":null:null;return(0,a.jsxs)("div",{className:`group flex min-w-0 flex-col gap-3 rounded-lg p-2 transition-colors hover:bg-black/[0.02] dark:hover:bg-white/[0.02] sm:flex-row sm:items-center sm:justify-between ${!1===e.isActive?"opacity-60":""}`,children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 items-start gap-2 sm:items-center sm:gap-3",children:[(0,a.jsxs)("div",{className:"flex shrink-0 flex-col",children:[(0,a.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,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_up"})}),(0,a.jsx)("button",{onClick:o,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,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_down"})})]}),(0,a.jsx)("span",{className:"material-symbols-outlined shrink-0 text-base text-text-muted",children:R?"cookie":E?"lock":"key"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-medium truncate",children:U}),(0,a.jsxs)("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1.5 sm:gap-2",children:[(0,a.jsx)(d.Ex,{variant:!1===e.isActive?"default":"active"===M||"success"===M?"success":"error"===M||"expired"===M||"unavailable"===M?"error":"default",size:"sm",dot:!0,children:!1===e.isActive?"disabled":M||"Unknown"}),(0,a.jsx)(d.Ex,{variant:"default",size:"sm",children:E?"OAuth":R?"Cookie":"API Key"}),S&&(0,a.jsx)(d.Ex,{variant:O,size:"sm",children:"Proxy"}),D&&!1!==e.isActive&&(0,a.jsx)(j,{until:q}),e.lastError&&!1!==e.isActive&&(0,a.jsx)("span",{className:"max-w-full truncate text-xs text-red-500 sm:max-w-[300px]",title:e.lastError,children:e.lastError}),(0,a.jsxs)("span",{className:"text-xs text-text-muted",children:["#",e.priority]}),e.globalPriority&&(0,a.jsxs)("span",{className:"text-xs text-text-muted",children:["Auto: ",e.globalPriority]}),F()&&(0,a.jsx)(d.Ex,{variant:u?"success"===u.state?"success":"failed"===u.state?"error":"testing"===u.state?"primary":"default":"default",size:"sm",children:F()})]}),S&&(0,a.jsxs)("div",{className:"mt-1 flex items-center gap-2 flex-wrap",children:[(0,a.jsx)("span",{className:"max-w-full truncate text-[11px] text-text-muted sm:max-w-[420px]",title:A,children:A}),$&&(0,a.jsx)("code",{className:"max-w-full truncate rounded bg-black/5 px-1 py-0.5 font-mono text-[10px] text-text-muted dark:bg-white/5 sm:max-w-[260px]",children:$}),T&&(0,a.jsxs)("span",{className:"max-w-full truncate text-[11px] text-text-muted sm:max-w-[320px]",title:T,children:["no_proxy: ",T]})]})]})]}),(0,a.jsxs)("div",{className:"flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-end",children:[(0,a.jsxs)("div",{className:"grid flex-1 grid-cols-3 gap-1 sm:flex sm:flex-none",children:[(t||[]).length>0&&(0,a.jsxs)("div",{className:"relative",ref:b,children:[(0,a.jsxs)("button",{onClick:()=>f(e=>!e),className:`flex w-full flex-col items-center rounded px-2 py-1 transition-colors hover:bg-black/5 dark:hover:bg-white/5 ${S?"text-primary":"text-text-muted hover:text-primary"}`,disabled:g,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:g?"progress_activity":"lan"}),(0,a.jsx)("span",{className:"text-[10px] leading-tight",children:"Proxy"})]}),h&&(0,a.jsxs)("div",{className:"absolute right-0 top-full z-50 mt-1 max-w-[78vw] min-w-[160px] rounded-lg border border-border bg-bg py-1 shadow-lg",children:[(0,a.jsx)("button",{onClick:()=>P("__none__"),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${!N?"text-primary font-medium":"text-text-main"}`,children:"None"}),(t||[]).map(e=>(0,a.jsx)("button",{onClick:()=>P(e.id),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${N===e.id?"text-primary font-medium":"text-text-main"}`,children:e.name},e.id))]})]}),(0,a.jsxs)("button",{onClick:m,className:"flex flex-col items-center rounded px-2 py-1 text-text-muted hover:bg-black/5 hover:text-primary dark:hover:bg-white/5",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"edit"}),(0,a.jsx)("span",{className:"text-[10px] leading-tight",children:"Edit"})]}),(0,a.jsxs)("button",{onClick:x,className:"flex flex-col items-center rounded px-2 py-1 text-red-500 hover:bg-red-500/10",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"delete"}),(0,a.jsx)("span",{className:"text-[10px] leading-tight",children:"Delete"})]})]}),(0,a.jsx)(d.lM,{size:"sm",checked:e.isActive??!0,onChange:c,title:e.isActive??!0?"Disable connection":"Enable connection"})]})]})}y.propTypes={model:g().shape({id:g().string.isRequired}).isRequired,fullModel:g().string.isRequired,displayModel:g().string,alias:g().string,copied:g().string,onCopy:g().func.isRequired,testStatus:g().oneOf(["ok","error"]),isCustom:g().bool,isFree:g().bool,onDeleteAlias:g().func,onTest:g().func,isTesting:g().bool,onDisable:g().func},g().string.isRequired,g().string.isRequired,g().string,g().func.isRequired,g().func.isRequired,g().func,g().oneOf(["ok","error"]),g().bool,g().string.isRequired,g().object.isRequired,g().string,g().func.isRequired,g().func.isRequired,g().func.isRequired,v.propTypes={providerStorageAlias:g().string.isRequired,providerDisplayAlias:g().string.isRequired,modelAliases:g().object.isRequired,copied:g().string,onCopy:g().func.isRequired,onSetAlias:g().func.isRequired,onDeleteAlias:g().func.isRequired,connections:g().arrayOf(g().shape({id:g().string,isActive:g().bool})).isRequired,isAnthropic:g().bool},j.propTypes={until:g().string.isRequired},w.propTypes={connection:g().shape({id:g().string,name:g().string,email:g().string,displayName:g().string,modelLockUntil:g().string,testStatus:g().string,isActive:g().bool,lastError:g().string,priority:g().number,globalPriority:g().number}).isRequired,proxyPools:g().arrayOf(g().shape({id:g().string,name:g().string,proxyUrl:g().string,noProxy:g().string,isActive:g().bool})),isOAuth:g().bool.isRequired,isFirst:g().bool.isRequired,isLast:g().bool.isRequired,onMoveUp:g().func.isRequired,onMoveDown:g().func.isRequired,onToggleActive:g().func.isRequired,onUpdateProxy:g().func,onEdit:g().func.isRequired,onDelete:g().func.isRequired,oneByOneStatus:g().shape({state:g().string,error:g().string})};let N=`Production|sk-...
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2134],{7570:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>A});var a=s(95155),i=s(12115),l=s(73321),r=s(98500),n=s.n(r),o=s(5772),d=s(35497),c=s(52679),p=s(28777),m=s(11059),x=s(73006);let u=new Map;async function h(e){if(!e?.url||!e?.type)return[];let t=u.get(e.url);if(t&&Date.now()<t.expiresAt)return t.data;try{let t=new URLSearchParams({url:e.url,type:e.type}),s=await fetch(`/api/providers/suggested-models?${t}`);if(!s.ok)return[];let a=(await s.json()).data??[];return u.set(e.url,{data:a,expiresAt:Date.now()+6e5}),a}catch{return[]}}var f=s(14051),g=s.n(f);function y({model:e,fullModel:t,displayModel:s,alias:i,copied:l,onCopy:r,testStatus:n,isCustom:o,isFree:d,onDeleteAlias:c,onTest:p,isTesting:m,onDisable:x}){let u="ok"===n?"#22c55e":"error"===n?"#ef4444":void 0;return(0,a.jsx)("div",{className:`group min-w-0 max-w-full rounded-lg border px-3 py-2 ${"ok"===n?"border-green-500/40":"error"===n?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:(0,a.jsxs)("div",{className:"flex min-w-0 items-start gap-2 sm:items-center",children:[(0,a.jsx)("span",{className:"material-symbols-outlined shrink-0 text-base",style:u?{color:u}:void 0,children:"ok"===n?"check_circle":"error"===n?"cancel":"smart_toy"}),(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[(0,a.jsx)("code",{className:"max-w-[72vw] truncate rounded bg-sidebar px-1.5 py-0.5 font-mono text-xs text-text-muted sm:max-w-[360px]",children:s||t}),e.name&&(0,a.jsx)("span",{className:"truncate pl-1 text-[9px] italic text-text-muted/70",children:e.name})]}),p&&(0,a.jsxs)("div",{className:"relative shrink-0 group/btn",children:[(0,a.jsx)("button",{onClick:p,disabled:m,className:`rounded p-0.5 text-text-muted transition-opacity hover:bg-sidebar hover:text-primary ${m?"opacity-100":"opacity-100 sm:opacity-0 sm:group-hover:opacity-100"}`,children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",style:m?{animation:"spin 1s linear infinite"}:void 0,children:m?"progress_activity":"science"})}),(0,a.jsx)("span",{className:"pointer-events-none absolute mt-1 top-5 left-1/2 -translate-x-1/2 text-[10px] text-text-muted whitespace-nowrap opacity-0 group-hover/btn:opacity-100 transition-opacity",children:m?"Testing...":"Test"})]}),(0,a.jsxs)("div",{className:"relative shrink-0 group/btn",children:[(0,a.jsx)("button",{onClick:()=>r(t,`model-${e.id}`),className:"rounded p-0.5 text-text-muted hover:bg-sidebar hover:text-primary",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:l===`model-${e.id}`?"check":"content_copy"})}),(0,a.jsx)("span",{className:"pointer-events-none absolute mt-1 top-5 left-1/2 -translate-x-1/2 text-[10px] text-text-muted whitespace-nowrap opacity-0 group-hover/btn:opacity-100 transition-opacity",children:l===`model-${e.id}`?"Copied!":"Copy"})]}),o?(0,a.jsx)("button",{onClick:c,className:"ml-auto rounded p-0.5 text-text-muted opacity-100 transition-opacity hover:bg-red-500/10 hover:text-red-500 sm:opacity-0 sm:group-hover:opacity-100",title:"Remove custom model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})}):x?(0,a.jsx)("button",{onClick:x,className:"ml-auto rounded p-0.5 text-text-muted opacity-100 transition-opacity hover:bg-red-500/10 hover:text-red-500 sm:opacity-0 sm:group-hover:opacity-100",title:"Disable this model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})}):null]})})}function b({modelId:e,fullModel:t,copied:s,onCopy:i,onDeleteAlias:l,onTest:r,testStatus:n,isTesting:o}){let d="ok"===n?"#22c55e":"error"===n?"#ef4444":void 0;return(0,a.jsxs)("div",{className:`flex items-center gap-3 p-3 rounded-lg border ${"ok"===n?"border-green-500/40":"error"===n?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",style:d?{color:d}:void 0,children:"ok"===n?"check_circle":"error"===n?"cancel":"smart_toy"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-medium truncate",children:e}),(0,a.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,a.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:t}),(0,a.jsxs)("div",{className:"relative group/btn",children:[(0,a.jsx)("button",{onClick:()=>i(t,`model-${e}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:s===`model-${e}`?"check":"content_copy"})}),(0,a.jsx)("span",{className:"pointer-events-none absolute top-5 left-1/2 -translate-x-1/2 text-[10px] text-text-muted whitespace-nowrap opacity-0 group-hover/btn:opacity-100 transition-opacity",children:s===`model-${e}`?"Copied!":"Copy"})]}),r&&(0,a.jsxs)("div",{className:"relative group/btn",children:[(0,a.jsx)("button",{onClick:r,disabled:o,className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary transition-colors",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",style:o?{animation:"spin 1s linear infinite"}:void 0,children:o?"progress_activity":"science"})}),(0,a.jsx)("span",{className:"pointer-events-none absolute top-5 left-1/2 -translate-x-1/2 text-[10px] text-text-muted whitespace-nowrap opacity-0 group-hover/btn:opacity-100 transition-opacity",children:o?"Testing...":"Test"})]})]})]}),(0,a.jsx)("button",{onClick:l,className:"p-1 hover:bg-red-50 rounded text-red-500",title:"Remove model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})}function v({providerStorageAlias:e,providerDisplayAlias:t,modelAliases:s,copied:l,onCopy:r,onSetAlias:n,onDeleteAlias:o,connections:c,isAnthropic:p}){let[m,x]=(0,i.useState)(""),[u,h]=(0,i.useState)(!1),[f,g]=(0,i.useState)(!1),[y,j]=(0,i.useState)(null),[w,N]=(0,i.useState)({}),k=async t=>{if(!y){j(t);try{let s=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${e}/${t}`})}),a=await s.json();N(e=>({...e,[t]:a.ok?"ok":"error"}))}catch{N(e=>({...e,[t]:"error"}))}finally{j(null)}}},C=Object.entries(s).filter(([,t])=>t.startsWith(`${e}/`)).map(([t,s])=>({modelId:s.replace(`${e}/`,""),fullModel:s,alias:t})),S=a=>{let i,l=`${e}/${a}`;if(Object.values(s).includes(l))return null;let r=(i=a.split("/"))[i.length-1];if(!s[r])return r;let n=`${t}-${r}`;return s[n]?null:n},$=async()=>{if(!m.trim()||u)return;let t=m.trim(),s=S(t);if(!s)return void alert("All suggested aliases already exist. Please choose a different model or remove conflicting aliases.");h(!0);try{await n(t,s,e),x("")}catch(e){console.log("Error adding model:",e)}finally{h(!1)}},A=async()=>{if(f)return;let t=c.find(e=>!1!==e.isActive);if(t){g(!0);try{let s=await fetch(`/api/providers/${t.id}/models`),a=await s.json();if(!s.ok)return void alert(a.error||"Failed to import models");let i=a.models||[];if(0===i.length)return void alert("No models returned from /models.");let l=0;for(let t of i){let s=t.id||t.name||t.model;if(!s)continue;let a=S(s);a&&(await n(s,a,e),l+=1)}0===l&&alert("No new models were added.")}catch(e){console.log("Error importing models:",e)}finally{g(!1)}}},T=c.some(e=>!1!==e.isActive);return(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("p",{className:"text-sm text-text-muted",children:["Add ",p?"Anthropic":"OpenAI","-compatible models manually or import them from the /models endpoint."]}),(0,a.jsxs)("div",{className:"flex items-end gap-2 flex-wrap",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,a.jsx)("label",{htmlFor:"new-compatible-model-input",className:"text-xs text-text-muted mb-1 block",children:"Model ID"}),(0,a.jsx)("input",{id:"new-compatible-model-input",type:"text",value:m,onChange:e=>x(e.target.value),onKeyDown:e=>"Enter"===e.key&&$(),placeholder:p?"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,a.jsx)(d.$n,{size:"sm",icon:"add",onClick:$,disabled:!m.trim()||u,children:u?"Adding...":"Add"}),(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"download",onClick:A,disabled:!T||f,children:f?"Importing...":"Import from /models"})]}),!T&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Add a connection to enable importing models."}),C.length>0&&(0,a.jsx)("div",{className:"flex flex-col gap-3",children:C.map(({modelId:e,fullModel:s,alias:i})=>(0,a.jsx)(b,{modelId:e,fullModel:`${t}/${e}`,copied:l,onCopy:r,onDeleteAlias:()=>o(i),onTest:c.length>0?()=>k(e):void 0,testStatus:w[e],isTesting:y===e},s))})]})}function j({until:e}){let[t,s]=(0,i.useState)("");return((0,i.useEffect)(()=>{let t=()=>{let t=new Date(e).getTime()-Date.now();if(t<=0)return void s("");let a=Math.floor(t/1e3);if(a<60)s(`${a}s`);else if(a<3600)s(`${Math.floor(a/60)}m ${a%60}s`);else{let e=Math.floor(a/3600),t=Math.floor(a%3600/60);s(`${e}h ${t}m`)}};t();let a=setInterval(t,1e3);return()=>clearInterval(a)},[e]),t)?(0,a.jsxs)("span",{className:"text-xs text-orange-500 font-mono",children:["⏱ ",t]}):null}function w({connection:e,proxyPools:t,isOAuth:s,isFirst:l,isLast:r,onMoveUp:n,onMoveDown:o,onToggleActive:c,onUpdateProxy:p,onEdit:m,onDelete:x,oneByOneStatus:u=null}){let[h,f]=(0,i.useState)(!1),[g,y]=(0,i.useState)(!1),b=(0,i.useRef)(null),v=new Map((t||[]).map(e=>[e.id,e])),N=e.providerSpecificData?.proxyPoolId||null,k=N?v.get(N):null,C=e.providerSpecificData?.connectionProxyEnabled===!0&&!!e.providerSpecificData?.connectionProxyUrl,S=!!N||C,$=k?`Pool: ${k.name}`:N?`Pool: ${N} (inactive/missing)`:C?`Legacy: ${e.providerSpecificData?.connectionProxyUrl}`:"",A="";if(k?.proxyUrl||e.providerSpecificData?.connectionProxyUrl){let t=k?.proxyUrl||e.providerSpecificData?.connectionProxyUrl;try{let e=new URL(t);A=`${e.protocol}//${e.hostname}${e.port?`:${e.port}`:""}`}catch{A=t}}let T=k?.noProxy||e.providerSpecificData?.connectionNoProxy||"",O="default";k?.isActive===!0?O="success":(N||C)&&(O="error"),(0,i.useEffect)(()=>{if(!h)return;let e=e=>{b.current&&!b.current.contains(e.target)&&f(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[h]);let P=async e=>{y(!0);try{await p("__none__"===e?null:e)}finally{y(!1),f(!1)}},I=e.authType||(s?"oauth":"apikey"),E="oauth"===I,R="cookie"===I,_=e=>"string"==typeof e&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),U=E?_(e.email)?e.email:_(e.name)?e.name:e.name||e.email||e.displayName||"OAuth Account":e.name||e.email||e.displayName||"API Key",[D,z]=(0,i.useState)(!1),q=Object.entries(e).filter(([e])=>e.startsWith("modelLock_")).map(([,e])=>e).filter(e=>!!e).sort()[0]||null;(0,i.useEffect)(()=>{let t=()=>{z(!!Object.entries(e).filter(([e])=>e.startsWith("modelLock_")).map(([,e])=>e).filter(e=>e&&new Date(e).getTime()>Date.now()).sort()[0])};t();let s=q?setInterval(t,1e3):null;return()=>{s&&clearInterval(s)}},[q]);let M="unavailable"!==e.testStatus||D?e.testStatus:"active",F=()=>u?"queued"===u.state?"queued":"testing"===u.state?"testing":"success"===u.state?"success":"failed"===u.state?u.error?`failed: ${u.error}`:"failed":null:null;return(0,a.jsxs)("div",{className:`group flex min-w-0 flex-col gap-3 rounded-lg p-2 transition-colors hover:bg-black/[0.02] dark:hover:bg-white/[0.02] sm:flex-row sm:items-center sm:justify-between ${!1===e.isActive?"opacity-60":""}`,children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 items-start gap-2 sm:items-center sm:gap-3",children:[(0,a.jsxs)("div",{className:"flex shrink-0 flex-col",children:[(0,a.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,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_up"})}),(0,a.jsx)("button",{onClick:o,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,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_down"})})]}),(0,a.jsx)("span",{className:"material-symbols-outlined shrink-0 text-base text-text-muted",children:R?"cookie":E?"lock":"key"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-medium truncate",children:U}),(0,a.jsxs)("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1.5 sm:gap-2",children:[(0,a.jsx)(d.Ex,{variant:!1===e.isActive?"default":"active"===M||"success"===M?"success":"error"===M||"expired"===M||"unavailable"===M?"error":"default",size:"sm",dot:!0,children:!1===e.isActive?"disabled":M||"Unknown"}),(0,a.jsx)(d.Ex,{variant:"default",size:"sm",children:E?"OAuth":R?"Cookie":"API Key"}),S&&(0,a.jsx)(d.Ex,{variant:O,size:"sm",children:"Proxy"}),D&&!1!==e.isActive&&(0,a.jsx)(j,{until:q}),e.lastError&&!1!==e.isActive&&(0,a.jsx)("span",{className:"max-w-full truncate text-xs text-red-500 sm:max-w-[300px]",title:e.lastError,children:e.lastError}),(0,a.jsxs)("span",{className:"text-xs text-text-muted",children:["#",e.priority]}),e.globalPriority&&(0,a.jsxs)("span",{className:"text-xs text-text-muted",children:["Auto: ",e.globalPriority]}),F()&&(0,a.jsx)(d.Ex,{variant:u?"success"===u.state?"success":"failed"===u.state?"error":"testing"===u.state?"primary":"default":"default",size:"sm",children:F()})]}),S&&(0,a.jsxs)("div",{className:"mt-1 flex items-center gap-2 flex-wrap",children:[(0,a.jsx)("span",{className:"max-w-full truncate text-[11px] text-text-muted sm:max-w-[420px]",title:$,children:$}),A&&(0,a.jsx)("code",{className:"max-w-full truncate rounded bg-black/5 px-1 py-0.5 font-mono text-[10px] text-text-muted dark:bg-white/5 sm:max-w-[260px]",children:A}),T&&(0,a.jsxs)("span",{className:"max-w-full truncate text-[11px] text-text-muted sm:max-w-[320px]",title:T,children:["no_proxy: ",T]})]})]})]}),(0,a.jsxs)("div",{className:"flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-end",children:[(0,a.jsxs)("div",{className:"grid flex-1 grid-cols-3 gap-1 sm:flex sm:flex-none",children:[(t||[]).length>0&&(0,a.jsxs)("div",{className:"relative",ref:b,children:[(0,a.jsxs)("button",{onClick:()=>f(e=>!e),className:`flex w-full flex-col items-center rounded px-2 py-1 transition-colors hover:bg-black/5 dark:hover:bg-white/5 ${S?"text-primary":"text-text-muted hover:text-primary"}`,disabled:g,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:g?"progress_activity":"lan"}),(0,a.jsx)("span",{className:"text-[10px] leading-tight",children:"Proxy"})]}),h&&(0,a.jsxs)("div",{className:"absolute right-0 top-full z-50 mt-1 max-w-[78vw] min-w-[160px] rounded-lg border border-border bg-bg py-1 shadow-lg",children:[(0,a.jsx)("button",{onClick:()=>P("__none__"),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${!N?"text-primary font-medium":"text-text-main"}`,children:"None"}),(t||[]).map(e=>(0,a.jsx)("button",{onClick:()=>P(e.id),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${N===e.id?"text-primary font-medium":"text-text-main"}`,children:e.name},e.id))]})]}),(0,a.jsxs)("button",{onClick:m,className:"flex flex-col items-center rounded px-2 py-1 text-text-muted hover:bg-black/5 hover:text-primary dark:hover:bg-white/5",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"edit"}),(0,a.jsx)("span",{className:"text-[10px] leading-tight",children:"Edit"})]}),(0,a.jsxs)("button",{onClick:x,className:"flex flex-col items-center rounded px-2 py-1 text-red-500 hover:bg-red-500/10",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"delete"}),(0,a.jsx)("span",{className:"text-[10px] leading-tight",children:"Delete"})]})]}),(0,a.jsx)(d.lM,{size:"sm",checked:e.isActive??!0,onChange:c,title:e.isActive??!0?"Disable connection":"Enable connection"})]})]})}y.propTypes={model:g().shape({id:g().string.isRequired}).isRequired,fullModel:g().string.isRequired,displayModel:g().string,alias:g().string,copied:g().string,onCopy:g().func.isRequired,testStatus:g().oneOf(["ok","error"]),isCustom:g().bool,isFree:g().bool,onDeleteAlias:g().func,onTest:g().func,isTesting:g().bool,onDisable:g().func},g().string.isRequired,g().string.isRequired,g().string,g().func.isRequired,g().func.isRequired,g().func,g().oneOf(["ok","error"]),g().bool,g().string.isRequired,g().object.isRequired,g().string,g().func.isRequired,g().func.isRequired,g().func.isRequired,v.propTypes={providerStorageAlias:g().string.isRequired,providerDisplayAlias:g().string.isRequired,modelAliases:g().object.isRequired,copied:g().string,onCopy:g().func.isRequired,onSetAlias:g().func.isRequired,onDeleteAlias:g().func.isRequired,connections:g().arrayOf(g().shape({id:g().string,isActive:g().bool})).isRequired,isAnthropic:g().bool},j.propTypes={until:g().string.isRequired},w.propTypes={connection:g().shape({id:g().string,name:g().string,email:g().string,displayName:g().string,modelLockUntil:g().string,testStatus:g().string,isActive:g().bool,lastError:g().string,priority:g().number,globalPriority:g().number}).isRequired,proxyPools:g().arrayOf(g().shape({id:g().string,name:g().string,proxyUrl:g().string,noProxy:g().string,isActive:g().bool})),isOAuth:g().bool.isRequired,isFirst:g().bool.isRequired,isLast:g().bool.isRequired,onMoveUp:g().func.isRequired,onMoveDown:g().func.isRequired,onToggleActive:g().func.isRequired,onUpdateProxy:g().func,onEdit:g().func.isRequired,onDelete:g().func.isRequired,oneByOneStatus:g().shape({state:g().string,error:g().string})};let N=`Production|sk-...
2
2
  Backup|sk-...
3
- sk-...`;function k({isOpen:e,provider:t,providerName:s,isCompatible:l,isAnthropic:r,authType:n,authHint:o,website:p,proxyPools:m,onSave:x,onBulkDone:u,onClose:h}){let f="__none__",g="ollama-local"===t,y="cookie"===n,b="xai"===t&&!y,v=y?"Cookie Value":"API Key",j=y?"grok-web"===t?"sso=xxxxx... or just the raw value":"eyJhbGciOi...":b?"xai-...":"",w="azure"===t,C="cloudflare-ai"===t,S=c.Q2?.[t]?.regions||null,A=c.Q2?.[t]?.defaultRegion||S?.[0]?.id||"",[$,T]=(0,i.useState)({name:"",apiKey:"",priority:1,proxyPoolId:f,ollamaHostUrl:""}),[O,P]=(0,i.useState)({azureEndpoint:"",apiVersion:"2024-10-01-preview",deployment:"",organization:""}),[I,E]=(0,i.useState)({accountId:""}),[R,_]=(0,i.useState)(A),[U,D]=(0,i.useState)(!1),[z,q]=(0,i.useState)(null),[M,F]=(0,i.useState)(!1),[K,J]=(0,i.useState)("single"),[L,W]=(0,i.useState)(""),[H,B]=(0,i.useState)(null),V=g?"Ollama Local":y?`${s||t} Cookie`:"Production Key";(0,i.useEffect)(()=>{e&&(T({name:l?V:"",apiKey:"",priority:1,proxyPoolId:f,ollamaHostUrl:""}),P({azureEndpoint:"",apiVersion:"2024-10-01-preview",deployment:"",organization:""}),E({accountId:""}),D(!1),q(null),F(!1),J("single"),W(""),B(null))},[V,l,e]);let G=()=>g&&$.ollamaHostUrl.trim()?{baseUrl:$.ollamaHostUrl.trim()}:w?{azureEndpoint:O.azureEndpoint,apiVersion:O.apiVersion,deployment:O.deployment,organization:O.organization}:C?{accountId:I.accountId}:S&&R?{region:R}:void 0,Q=async()=>{D(!0);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:$.apiKey,providerSpecificData:G()})}),s=await e.json();q(s.valid?"success":"failed")}catch{q("failed")}finally{D(!1)}},Z=async()=>{if(!t||!g&&!$.apiKey)return;let e=$.name.trim()||V;F(!0);try{let s=!1;try{D(!0),q(null);let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:$.apiKey,providerSpecificData:G()})});s=!!(await e.json()).valid,q(s?"success":"failed")}catch{q("failed")}finally{D(!1)}await x({name:e,apiKey:$.apiKey,priority:$.priority,proxyPoolId:$.proxyPoolId===f?null:$.proxyPoolId,testStatus:s?"active":"unknown",providerSpecificData:G()})}finally{F(!1)}},X=async()=>{let e=L.split("\n").map(e=>e.trim()).filter(Boolean);if(!e.length)return;F(!0),B(null);let s=0,a=0;for(let i=0;i<e.length;i++){let l=e[i].split("|"),r=l.length>=2?l.slice(1).join("|").trim():l[0].trim(),n=l.length>=2?l[0].trim():"Key",o=`${n} ${i+1}`;try{(await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:r,name:o,priority:1,testStatus:"unknown"})})).ok?s++:a++}catch{a++}}F(!1),B({success:s,failed:a}),s>0&&u&&u()};return t?(0,a.jsx)(d.aF,{isOpen:e,title:`Add ${s||t} ${v}`,onClose:h,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{size:"sm",variant:"single"===K?"primary":"ghost",onClick:()=>{J("single"),B(null)},children:"Single"}),(0,a.jsx)(d.$n,{size:"sm",variant:"bulk"===K?"primary":"ghost",onClick:()=>{J("bulk"),B(null)},children:"Bulk Add"})]}),"bulk"===K&&(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:["One key per line. Format: ",(0,a.jsx)("code",{children:"name|apiKey"})," or just ",(0,a.jsx)("code",{children:"apiKey"})," (auto-named by index)."]}),(0,a.jsx)("textarea",{className:"w-full rounded border border-accent/30 bg-sidebar p-2 text-sm font-mono resize-y min-h-[140px] focus:outline-none focus:ring-1 focus:ring-primary",placeholder:N,value:L,onChange:e=>W(e.target.value)}),H&&(0,a.jsxs)("div",{className:`text-sm font-medium ${H.failed>0?"text-yellow-400":"text-green-400"}`,children:["✓ ",H.success," added",H.failed>0?`, ✗ ${H.failed} failed`:""]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{onClick:X,fullWidth:!0,disabled:M||!L.trim(),children:M?"Adding...":"Add All Keys"}),(0,a.jsx)(d.$n,{onClick:h,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),"single"===K&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.pd,{label:"Name",value:$.name,onChange:e=>T({...$,name:e.target.value}),placeholder:V}),g&&(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.pd,{label:"Ollama Host URL",value:$.ollamaHostUrl,onChange:e=>T({...$,ollamaHostUrl:e.target.value}),placeholder:"http://localhost:11434",className:"flex-1"}),(0,a.jsx)("div",{className:"pt-6",children:(0,a.jsx)(d.$n,{onClick:Q,disabled:U||M,variant:"secondary",children:U?"Checking...":"Check"})})]}),!g&&(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.pd,{label:v,type:y?"text":"password",value:$.apiKey,onChange:e=>T({...$,apiKey:e.target.value}),placeholder:j,className:"flex-1"}),(0,a.jsx)("div",{className:"pt-6",children:(0,a.jsx)(d.$n,{onClick:Q,disabled:!$.apiKey||U||M,variant:"secondary",children:U?"Checking...":"Check"})})]}),b&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Use a direct xAI API key from console.x.ai. This is separate from Grok Build OAuth."}),y&&o&&(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:[o,p&&(0,a.jsxs)(a.Fragment,{children:[" ",(0,a.jsxs)("a",{href:p,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:["Open ",p.replace(/^https?:\/\//,"")]})]})]}),S&&(0,a.jsx)(d.l6,{label:"Region",value:R,onChange:e=>_(e.target.value),options:S.map(e=>({value:e.id,label:e.label}))}),l&&(0,a.jsx)(d.pd,{label:"Default Model",value:$.defaultModel,onChange:e=>T({...$,defaultModel:e.target.value}),placeholder:r?"claude-3-5-sonnet-latest":"gpt-4o-mini"}),g&&(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:["Leave blank to use ",(0,a.jsx)("code",{children:"http://localhost:11434"}),". For remote Ollama, enter the full host URL (e.g. ",(0,a.jsx)("code",{children:"http://192.168.1.10:11434"}),")."]}),z&&(0,a.jsx)(d.Ex,{variant:"success"===z?"success":"error",children:"success"===z?"Valid":"Invalid"}),l&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:r?`Validation checks ${s||"Anthropic Compatible"} by verifying the API key.`:`Validation checks ${s||"OpenAI Compatible"} via /models on your base URL.`}),C&&(0,a.jsxs)("div",{className:"bg-sidebar/50 p-4 rounded-lg border border-accent/20",children:[(0,a.jsx)("h3",{className:"font-semibold mb-3 text-sm",children:"Cloudflare Workers AI"}),(0,a.jsx)(d.pd,{label:"Account ID",value:I.accountId,onChange:e=>E({...I,accountId:e.target.value}),placeholder:"abc123def456..."}),(0,a.jsxs)("p",{className:"text-xs text-text-muted mt-2",children:["Find your Account ID in the right sidebar of ",(0,a.jsx)("a",{href:"https://dash.cloudflare.com",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"dash.cloudflare.com"})]})]}),w&&(0,a.jsxs)("div",{className:"bg-sidebar/50 p-4 rounded-lg border border-accent/20",children:[(0,a.jsx)("h3",{className:"font-semibold mb-3 text-sm",children:"Azure OpenAI Configuration"}),(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsx)(d.pd,{label:"Azure Endpoint",value:O.azureEndpoint,onChange:e=>P({...O,azureEndpoint:e.target.value}),placeholder:"https://your-resource.openai.azure.com"}),(0,a.jsx)(d.pd,{label:"Deployment Name",value:O.deployment,onChange:e=>P({...O,deployment:e.target.value}),placeholder:"gpt-4"}),(0,a.jsx)(d.pd,{label:"API Version",value:O.apiVersion,onChange:e=>P({...O,apiVersion:e.target.value}),placeholder:"2024-10-01-preview"}),(0,a.jsx)(d.pd,{label:"Organization",value:O.organization,onChange:e=>P({...O,organization:e.target.value}),placeholder:"Organization ID"})]})]}),(0,a.jsx)(d.pd,{label:"Priority",type:"number",value:$.priority,onChange:e=>T({...$,priority:Number.parseInt(e.target.value)||1})}),(0,a.jsx)(d.l6,{label:"Proxy Pool",value:$.proxyPoolId,onChange:e=>T({...$,proxyPoolId:e.target.value}),options:[{value:f,label:"None"},...(m||[]).map(e=>({value:e.id,label:e.name}))],placeholder:"None"}),0===(m||[]).length&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"No active proxy pools available. Create one in Proxy Pools page first."}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Legacy manual proxy fields are still accepted by API for backward compatibility."}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{onClick:Z,fullWidth:!0,disabled:M||!g&&!$.apiKey||w&&(!O.azureEndpoint||!O.deployment||!O.organization)||C&&!I.accountId,children:M?"Saving...":"Save"}),(0,a.jsx)(d.$n,{onClick:h,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})]})}):null}function C({isOpen:e,node:t,onSave:s,onClose:l,isAnthropic:r}){let[n,o]=(0,i.useState)({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[c,p]=(0,i.useState)(!1),[m,x]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[f,g]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null);(0,i.useEffect)(()=>{t&&o({name:t.name||"",prefix:t.prefix||"",apiType:t.apiType||"chat",baseUrl:t.baseUrl||(r?"https://api.anthropic.com/v1":"https://api.openai.com/v1")})},[t,r]);let v=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};r||(e.apiType=n.apiType),await s(e)}finally{p(!1)}}},j=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:m,type:r?"anthropic-compatible":"openai-compatible",modelId:u.trim()||void 0})}),t=await e.json();b(t.valid?"success":"failed")}catch{b("failed")}finally{g(!1)}};return t?(0,a.jsx)(d.aF,{isOpen:e,title:`Edit ${r?"Anthropic":"OpenAI"} Compatible`,onClose:l,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsx)(d.pd,{label:"Name",value:n.name,onChange:e=>o({...n,name:e.target.value}),placeholder:`${r?"Anthropic":"OpenAI"} Compatible (Prod)`,hint:"Required. A friendly label for this node."}),(0,a.jsx)(d.pd,{label:"Prefix",value:n.prefix,onChange:e=>o({...n,prefix:e.target.value}),placeholder:r?"ac-prod":"oc-prod",hint:"Required. Used as the provider prefix for model IDs."}),!r&&(0,a.jsx)(d.l6,{label:"API Type",options:[{value:"chat",label:"Chat Completions"},{value:"responses",label:"Responses API"}],value:n.apiType,onChange:e=>o({...n,apiType:e.target.value})}),(0,a.jsx)(d.pd,{label:"Base URL",value:n.baseUrl,onChange:e=>o({...n,baseUrl:e.target.value}),placeholder:r?"https://api.anthropic.com/v1":"https://api.openai.com/v1",hint:`Use the base URL (ending in /v1) for your ${r?"Anthropic":"OpenAI"}-compatible API.`}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.pd,{label:"API Key (for Check)",type:"password",value:m,onChange:e=>x(e.target.value),className:"flex-1"}),(0,a.jsx)("div",{className:"pt-6",children:(0,a.jsx)(d.$n,{onClick:j,disabled:!m||f||!n.baseUrl.trim(),variant:"secondary",children:f?"Checking...":"Check"})})]}),(0,a.jsx)(d.pd,{label:"Model ID (optional)",value:u,onChange:e=>h(e.target.value),placeholder:"e.g. my-model-id",hint:"If provider lacks /models endpoint, enter a model ID to validate via chat/completions instead."}),y&&(0,a.jsx)(d.Ex,{variant:"success"===y?"success":"error",children:"success"===y?"Valid":"Invalid"}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{onClick:v,fullWidth:!0,disabled:!n.name.trim()||!n.prefix.trim()||!n.baseUrl.trim()||c,children:c?"Saving...":"Save"}),(0,a.jsx)(d.$n,{onClick:l,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}function S({isOpen:e,providerAlias:t,providerDisplayAlias:s,onSave:l,onClose:r}){var n;let o,[c,p]=(0,i.useState)(""),[m,x]=(0,i.useState)(null),[u,h]=(0,i.useState)(""),[f,g]=(0,i.useState)(!1);(0,i.useEffect)(()=>{e&&(p(""),x(null),h(""),g(!1))},[e]);let y=(n=c.trim(),o=`${t}/`,n.startsWith(o)?n.slice(o.length):n),b=async()=>{if(y){x("testing"),h("");try{let e=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${t}/${y}`})}),s=await e.json();x(s.ok?"ok":"error"),h(s.error||"")}catch(e){x("error"),h(e.message)}}},v=async()=>{if(y&&!f){g(!0);try{await l(y)}finally{g(!1)}}};return(0,a.jsx)(d.aF,{isOpen:e,onClose:r,title:"Add Custom Model",children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-sm font-medium mb-1.5 block",children:"Model ID"}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("input",{type:"text",value:c,onChange:e=>{p(e.target.value),x(null),h("")},onKeyDown:e=>{"Enter"===e.key&&b()},placeholder:"e.g. claude-opus-4-5",className:"flex-1 px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",autoFocus:!0}),(0,a.jsx)(d.$n,{type:"button",variant:"secondary",icon:"science",loading:"testing"===m,onClick:b,disabled:!y||"testing"===m,children:"testing"===m?"Testing...":"Test"})]}),(0,a.jsxs)("p",{className:"text-xs text-text-muted mt-1",children:["Sent to provider as: ",(0,a.jsx)("code",{className:"font-mono bg-sidebar px-1 rounded",children:y||"model-id"})]})]}),"ok"===m&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-base",children:"check_circle"}),"Model is reachable"]}),"error"===m&&(0,a.jsxs)("div",{className:"flex items-start gap-2 text-sm text-red-500",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-base shrink-0",children:"cancel"}),(0,a.jsx)("span",{children:u||"Model not reachable"})]}),(0,a.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,a.jsx)(d.$n,{type:"button",onClick:r,variant:"ghost",fullWidth:!0,size:"sm",children:"Cancel"}),(0,a.jsx)(d.$n,{type:"button",onClick:v,fullWidth:!0,size:"sm",disabled:!y||f,children:f?"Adding...":"Add Model"})]})]})})}function A({isOpen:e,onClose:t,onSuccess:s}){let[l,r]=(0,i.useState)([]),[n,o]=(0,i.useState)(""),[c,p]=(0,i.useState)(!1),[m,x]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),f=()=>{r([]),o(""),x(null),h(null),t()},g=async()=>{p(!0),x(null),h(null);try{let e=await Promise.all(l.map(async e=>({filename:e.name,jsonText:await e.text()}))),t=n.trim()?[{filename:"pasted JSON",jsonText:n.trim()}]:[],a=[...e,...t];if(0===a.length)throw Error("Select JSON files or paste JSON first");let i=await fetch("/api/oauth/codex/import-batch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:a})}),r=await i.json();if(!i.ok)throw Error(r.error||"Failed to import accounts");x(r),r.imported?.length>0&&s?.()}catch(e){h(e.message||"Failed to import accounts")}finally{p(!1)}},y=m?.imported?.length||0,b=m?.skipped?.length||0;return(0,a.jsx)(d.aF,{isOpen:e,title:"Import Codex Accounts",onClose:f,size:"lg",children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"rounded-lg border border-border bg-surface/50 p-3",children:[(0,a.jsx)("label",{className:"mb-2 block text-sm font-medium",children:"JSON files"}),(0,a.jsx)("input",{type:"file",accept:".json,application/json",multiple:!0,onChange:e=>r(Array.from(e.target.files||[])),className:"block w-full text-sm text-text-muted file:mr-3 file:rounded-md file:border-0 file:bg-primary file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-white hover:file:bg-primary/90"}),l.length>0&&(0,a.jsx)("div",{className:"mt-2 flex flex-wrap gap-1.5",children:l.map(e=>(0,a.jsx)("span",{className:"rounded bg-primary/10 px-2 py-0.5 text-xs text-primary",children:e.name},`${e.name}-${e.size}`))})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"mb-2 block text-sm font-medium",children:"Paste JSON"}),(0,a.jsx)("textarea",{value:n,onChange:e=>o(e.target.value),placeholder:'[{ "type": "codex", "access_token": "...", "refresh_token": "..." }]',className:"h-36 w-full resize-none rounded-md border border-black/10 bg-white px-3 py-2 font-mono text-xs text-text-main shadow-inner transition-all placeholder-text-muted/60 focus:border-primary/50 focus:outline-none focus:ring-1 focus:ring-primary/30 dark:border-white/10 dark:bg-white/5"})]}),(0,a.jsx)("div",{className:"rounded-lg border border-border bg-background/60 px-3 py-2 text-xs text-text-muted",children:"Auto-detects Codex Session JSON, CLI Proxy API Auth JSON, and Sub2API JSON."}),u&&(0,a.jsx)("div",{className:"rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-600",children:u}),m&&(0,a.jsxs)("div",{className:"rounded-lg border border-border bg-surface/40 p-3",children:[(0,a.jsxs)("div",{className:"mb-2 flex flex-wrap items-center gap-2 text-sm",children:[(0,a.jsxs)("span",{className:"font-medium text-green-600",children:[y," imported"]}),b>0&&(0,a.jsxs)("span",{className:"text-text-muted",children:[b," skipped"]})]}),m.imported?.length>0&&(0,a.jsx)("div",{className:"max-h-32 overflow-auto rounded border border-border/70",children:m.imported.map(e=>(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-border/70 px-2 py-1.5 last:border-b-0",children:[(0,a.jsx)("span",{className:"min-w-0 truncate text-xs",children:e.email||e.displayName||e.name||e.id}),(0,a.jsx)("span",{className:"shrink-0 text-xs text-text-muted",children:e.sourceFormat})]},e.id))}),m.skipped?.length>0&&(0,a.jsx)("div",{className:"mt-2 max-h-28 overflow-auto rounded border border-border/70",children:m.skipped.map((e,t)=>(0,a.jsxs)("div",{className:"border-b border-border/70 px-2 py-1.5 text-xs last:border-b-0",children:[(0,a.jsx)("span",{className:"font-medium",children:e.filename}),(0,a.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",e.reason]})]},`${e.filename}-${t}`))})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{onClick:g,loading:c,disabled:c||!l.length&&!n.trim(),fullWidth:!0,children:"Import"}),(0,a.jsx)(d.$n,{onClick:f,variant:"ghost",fullWidth:!0,children:"Close"})]})]})})}function $(){let e,t=(0,l.useParams)(),s=(0,l.useRouter)(),r=t.id,[u,f]=(0,i.useState)([]),[g,b]=(0,i.useState)(!0),[j,N]=(0,i.useState)(null),[$,T]=(0,i.useState)([]),[O,P]=(0,i.useState)(!1),[I,E]=(0,i.useState)(!1),[R,_]=(0,i.useState)(!1),[U,D]=(0,i.useState)(!1),[z,q]=(0,i.useState)(null),[M,F]=(0,i.useState)(!1),[K,J]=(0,i.useState)(!1),[L,W]=(0,i.useState)(!1),[H,B]=(0,i.useState)(!1),[V,G]=(0,i.useState)(null),[Q,Z]=(0,i.useState)({}),[X,Y]=(0,i.useState)(!1),[ee,et]=(0,i.useState)({}),[es,ea]=(0,i.useState)(""),[ei,el]=(0,i.useState)(null),[er,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)([]),[ec,ep]=(0,i.useState)("__none__"),[em,ex]=(0,i.useState)(!1),[eu,eh]=(0,i.useState)(null),[ef,eg]=(0,i.useState)(""),[ey,eb]=(0,i.useState)("auto"),[ev,ej]=(0,i.useState)(!1),[ew,eN]=(0,i.useState)(!1),[ek,eC]=(0,i.useState)("super_admin"),[eS,eA]=(0,i.useState)([]),[e$,eT]=(0,i.useState)([]),[eO,eP]=(0,i.useState)([]),[eI,eE]=(0,i.useState)(null),[eR,e_]=(0,i.useState)(!1),[eU,eD]=(0,i.useState)(!1),[ez,eq]=(0,i.useState)(!1),[eM,eF]=(0,i.useState)(null),[eK,eJ]=(0,i.useState)({}),[eL,eW]=(0,i.useState)(null),eH=(0,i.useRef)(!1),[eB,eV]=(0,i.useState)(!1),{copied:eG,copy:eQ}=(0,m.C)(),eZ="ag_risk_confirmed",eX=()=>{P(!0)},eY=()=>{"antigravity"===r&&"true"!==window.localStorage.getItem(eZ)?e_(!0):e3?eX():(setAddConnectionError(""),F(!0))},e0=()=>{setAddConnectionError(""),F(!0)},e1=()=>{e3?eY():e0()},e2=j?{id:j.id,name:j.name||("anthropic-compatible"===j.type?"Anthropic Compatible":"OpenAI Compatible"),color:"anthropic-compatible"===j.type?"#D97757":"#10A37F",textIcon:"anthropic-compatible"===j.type?"AC":"OC",apiType:j.apiType,baseUrl:j.baseUrl,type:j.type}:c.zN[r]||c.fg[r]||c.IS[r]||c.nJ[r]||c.br[r],e5=e2?.authModes||[],e3=!!c.zN[r]||!!c.IS[r]||e5.includes("oauth"),e4=!!c.fg[r]||e5.includes("apikey"),e6=!!c.IS[r]?.noAuth,e7=(0,p.KC)(r),e8=(0,c.wG)(r),e9=(0,c.mq)(r),te=(0,c.gb)(r),tt=e9||te,ts=!tt&&e3&&e4,ta="xai"===r?"Grok Build OAuth":"OAuth",ti="xai"===r?"xAI API Key":"API Key",tl=c.Q2[r]?.thinkingConfig||c.s9.extended,tr=tt?r:e8,tn=tt?j?.prefix||r:e8,to="codex"===r,td=(tl?.options||[]).map(e=>({value:e,label:"auto"===e?"codex"===r?"Auto (Medium)":"Auto":"xhigh"===e?"XHigh":e.charAt(0).toUpperCase()+e.slice(1)})),tc=(0,i.useCallback)(async()=>{try{let e=await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(tr)}`,{cache:"no-store"}),t=await e.json();e.ok&&eP(t.ids||[])}catch(e){console.log("Error fetching disabled models:",e)}},[tr]),tp=async e=>{try{(await fetch("/api/models/disabled",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:tr,ids:[e]})})).ok&&await tc()}catch(e){console.log("Error disabling model:",e)}},tm=async e=>{try{(await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(tr)}&id=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await tc()}catch(e){console.log("Error enabling model:",e)}},tx=async e=>{e.length&&eE({title:"Disable All Models",message:`Disable all ${e.length} model(s)?`,onConfirm:async()=>{eE(null);try{(await fetch("/api/models/disabled",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:tr,ids:e})})).ok&&await tc()}catch(e){console.log("Error disabling all models:",e)}}})},tu=async()=>{try{(await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(tr)}`,{method:"DELETE"})).ok&&await tc()}catch(e){console.log("Error enabling all models:",e)}},th=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&Z(t.aliases||{})}catch(e){console.log("Error fetching aliases:",e)}},[]);(0,i.useEffect)(()=>{"kilocode"===r&&fetch("/api/providers/kilo/free-models").then(e=>e.json()).then(e=>{e.models?.length&&eT(e.models)}).catch(()=>{})},[r]);let tf=(0,i.useCallback)(async()=>{try{let[e,t,s,a,i]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/provider-nodes",{cache:"no-store"}),fetch("/api/proxy-pools?isActive=true",{cache:"no-store"}),fetch("/api/settings",{cache:"no-store"}),fetch("/api/auth/me",{cache:"no-store"})]),l=await e.json(),n=await t.json(),o=await s.json(),d=a.ok?await a.json():{},c=i.ok?await i.json():{};if(e.ok){let e=(l.connections||[]).filter(e=>e.provider===r);f(e)}s.ok&&T(o.proxyPools||[]);let p=(d.providerStrategies||{})[r]||{};eh(p.fallbackStrategy||null),eg(null!=p.stickyRoundRobinLimit?String(p.stickyRoundRobinLimit):"1");let m=(d.providerThinking||{})[r]||{},x=c.providerThinkingScopeKey||c.userId||"super_admin",u="sub_user"===c.role?(c.providerThinking||{})[r]||{}:(d.userProviderThinking||{})[x]?.[r]||{};if(eb(m.mode||"auto"),ej(!0===m.fastMode),eC(x),eN(Object.prototype.hasOwnProperty.call(u,"fastMode")?!0===u.fastMode:!0===m.fastMode),t.ok){let e=(n.nodes||[]).find(e=>e.id===r)||null;if(!e&&tt)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}N(e)}}catch(e){console.log("Error fetching connections:",e)}finally{b(!1)}},[r,tt]),tg=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&&(N(s.node),await tf(),W(!1))}catch(e){console.log("Error updating provider node:",e)}},ty=async(e,t)=>{try{let s=await fetch("/api/settings",{cache:"no-store"}),a=(s.ok?await s.json():{}).providerStrategies||{},i={};e&&(i.fallbackStrategy=e),"round-robin"===e&&""!==t&&(i.stickyRoundRobinLimit=Number(t)||3);let l={...a};0===Object.keys(i).length?delete l[r]:l[r]=i,await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerStrategies:l})})}catch(e){console.log("Error saving provider strategy:",e)}},tb=async(e,t=ev)=>{try{let s=await fetch("/api/settings",{cache:"no-store"}),a={...(s.ok?await s.json():{}).providerThinking||{}},i={};e&&"auto"!==e&&(i.mode=e),"codex"===r&&!0===t&&(i.fastMode=!0),0===Object.keys(i).length?delete a[r]:a[r]=i,await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerThinking:a})})}catch(e){console.log("Error saving thinking config:",e)}},tv=async e=>{try{let t=await fetch("/api/settings",{cache:"no-store"}),s=(t.ok?await t.json():{}).userProviderThinking||{},a=ek||"super_admin",i=s[a]||{},l=i[r]||{},n={...s,[a]:{...i,[r]:{...l,fastMode:e}}};await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({userProviderThinking:n})})}catch(e){console.log("Error saving account fast mode:",e)}};(0,i.useEffect)(()=>{(async()=>{await Promise.all([tf(),th(),tc()])})()},[tf,th,tc]),(0,i.useEffect)(()=>{let e=(c.zN[r]||c.fg[r]||c.IS[r]||c.nJ[r])?.modelsFetcher;e&&h(e).then(eA)},[r]);let tj=async(e,t,s=e8)=>{let a=`${s}/${e}`;try{let e=await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:a,alias:t})});if(e.ok)await th();else{let t=await e.json();alert(t.error||"Failed to set alias")}}catch(e){console.log("Error setting alias:",e)}},tw=async e=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await th()}catch(e){console.log("Error deleting alias:",e)}},tN=async()=>{if(eB)return;let e=u.find(e=>!1!==e.isActive);if(!e)return void alert((0,x.Tl)("Please add an active Qoder connection first"));eV(!0);try{let t=await fetch(`/api/providers/${e.id}/models`),s=await t.json();if(!t.ok)return void alert(s.error||(0,x.Tl)("Failed to fetch models"));let a=s.models||[];if(0===a.length)return void alert((0,x.Tl)("No models returned"));let i=0;for(let e of a){let t=e.id||e.name;if(!t)continue;let s=t.replace(/^qoder\//,""),a=`${tr}/${s}`;!Object.values(Q).includes(a)&&(Q[s]||(await tj(s,s,tr),i+=1))}0===i?alert((0,x.Tl)("All models already exist, no new models added")):alert((0,x.Tl)("Successfully added")+` ${i} `+(0,x.Tl)("models"))}catch(e){console.log("Error importing Qoder models:",e),alert((0,x.Tl)("Error fetching models")+": "+e.message)}finally{eV(!1)}},tk=async()=>{if(eU||0===u.length)return;let e=Object.fromEntries(u.map(e=>[e.id,{state:"queued",error:null}]));eH.current=!1,eD(!0),eq(!1),eF(null),eJ(e),eW({total:u.length,completed:0,passed:0,failed:0,stopped:!1});let t=0,s=0;try{for(let e=0;e<u.length;e+=1){if(eH.current){eW({total:u.length,completed:e,passed:t,failed:s,stopped:!0});break}let a=u[e];eF(a.id),eJ(e=>({...e,[a.id]:{state:"testing",error:null}}));try{let e=await fetch(`/api/providers/${a.id}/test`,{method:"POST"}),i=await e.json(),l=!!i.valid;l?t+=1:s+=1,eJ(e=>({...e,[a.id]:{state:l?"success":"failed",error:l?null:i.error||null}}))}catch(e){s+=1,eJ(t=>({...t,[a.id]:{state:"failed",error:e.message||"Test failed"}}))}eW({total:u.length,completed:e+1,passed:t,failed:s,stopped:!1}),e<u.length-1&&await new Promise(e=>setTimeout(e,1e3))}}finally{eF(null),eD(!1),eq(!1),eH.current=!1}},tC=async e=>{eE({title:"Delete Connection",message:"Delete this connection?",onConfirm:async()=>{eE(null);try{(await fetch(`/api/providers/${e}`,{method:"DELETE"})).ok&&f(u.filter(t=>t.id!==e))}catch(e){console.log("Error deleting connection:",e)}}})},tS=()=>{tf(),P(!1)},tA=async()=>{if(!U){D(!0),q(null);try{let e=await fetch("/api/oauth/codex/refresh-all",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}),t=await e.json();if(!e.ok&&!t?.refreshed?.length)throw Error(t.error||"Failed to refresh Codex tokens");q(t),await tf()}catch(e){q({error:e.message,refreshed:[],failed:[],skipped:[]})}finally{D(!1)}}},t$=async e=>{try{(await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,...e})})).ok&&(await tf(),F(!1))}catch(e){console.log("Error saving connection:",e)}},tT=async e=>{try{(await fetch(`/api/providers/${V.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(await tf(),J(!1))}catch(e){console.log("Error updating connection:",e)}},tO=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&f(s=>s.map(s=>s.id===e?{...s,isActive:t}:s))}catch(e){console.log("Error updating connection status:",e)}},tP=async(e,t)=>{let s=[...u];[s[e],s[t]]=[s[t],s[e]],f(s);try{await Promise.all([fetch(`/api/providers/${s[e].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:e})}),fetch(`/api/providers/${s[t].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:t})})])}catch(e){console.log("Error swapping priority:",e),await tf()}},tI=(0,i.useMemo)(()=>new Set(u.map(e=>e.id)),[u]),tE=(0,i.useMemo)(()=>eo.filter(e=>tI.has(e)),[eo,tI]),tR=u.filter(e=>tE.includes(e.id));u.length>0&&(tE.length,u.length);let t_=(()=>{if(0===tR.length)return"";let e=new Set(tR.map(e=>e.providerSpecificData?.proxyPoolId||"__none__"));if(1===e.size){let t=[...e][0];if("__none__"===t)return"All selected currently unbound";let s=$.find(e=>e.id===t);return`All selected currently bound to ${s?.name||t}`}return"Selected connections have mixed proxy bindings"})(),tU=()=>{em||B(!1)},tD=async()=>{if(0===tE.length)return;let e="__none__"===ec?null:ec;ex(!0);try{let t=[];for(let s of tE)try{let a=await fetch(`/api/providers/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyPoolId:e})});t.push(a.ok)}catch(e){console.log("Error applying bulk proxy pool for",s,e),t.push(!1)}let s=t.filter(e=>!e).length;s>0&&alert(`Updated with ${s} failed request(s).`),await tf(),ed([]),ep("__none__"),B(!1)}catch(e){console.log("Error applying bulk proxy pool:",e)}finally{ex(!1)}},tz=(0,a.jsx)("div",{className:"flex min-w-0 flex-col divide-y divide-black/3 dark:divide-white/3",children:u.map((e,t)=>(0,a.jsx)("div",{className:"flex min-w-0 items-stretch",children:(0,a.jsx)("div",{className:"flex-1 min-w-0",children:(0,a.jsx)(w,{connection:e,proxyPools:$,isOAuth:e3,isFirst:0===t,isLast:t===u.length-1,onMoveUp:()=>tP(t,t-1),onMoveDown:()=>tP(t,t+1),onToggleActive:t=>tO(e.id,t),onUpdateProxy:async t=>{try{(await fetch(`/api/providers/${e.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyPoolId:t||null})})).ok&&f(s=>s.map(s=>s.id===e.id?{...s,providerSpecificData:{...s.providerSpecificData,proxyPoolId:t||null}}:s))}catch(e){console.log("Error updating proxy:",e)}},onEdit:()=>{G(e),J(!0)},onDelete:()=>tC(e.id),oneByOneStatus:eK[e.id]||null})})},e.id))}),tq=[{value:"__none__",label:"None"},...$.map(e=>({value:e.id,label:e.name}))],tM=0===tE.length?"Select one or more connections, then click Proxy Action.":t_,tF=tE.length>0&&!em,tK=(0,a.jsx)(d.aF,{isOpen:H,onClose:tU,title:`Proxy Action (${tE.length} selected)`,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsx)(d.l6,{label:"Proxy Pool",value:ec,onChange:e=>ep(e.target.value),options:tq,placeholder:"None"}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:tM}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Selecting None will unbind selected connections from proxy pool."}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,a.jsx)(d.$n,{onClick:tD,fullWidth:!0,disabled:!tF,children:em?"Applying...":"Apply"}),(0,a.jsx)(d.$n,{onClick:tU,variant:"ghost",fullWidth:!0,disabled:em,children:"Cancel"})]})]})}),tJ=async e=>{if(!ei){el(e);try{let t=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${tr}/${e}`})}),s=await t.json();et(t=>({...t,[e]:s.ok?"ok":"error"})),ea(s.ok?"":s.error||"Model not reachable")}catch{et(t=>({...t,[e]:"error"})),ea("Network error")}finally{el(null)}}};return g?(0,a.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,a.jsx)(d.Qv,{}),(0,a.jsx)(d.Qv,{})]}):e2?(0,a.jsxs)("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:gap-8 sm:px-0",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)(n(),{href:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),"Back to Providers"]}),(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3 sm:gap-4",children:[(0,a.jsx)("div",{className:"flex size-12 shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${e2.color}15`},children:X?(0,a.jsx)("span",{className:"text-sm font-bold",style:{color:e2.color},children:e2.textIcon||e2.id.slice(0,2).toUpperCase()}):(0,a.jsx)(o.default,{src:e9&&e2.apiType?"responses"===e2.apiType?"/providers/oai-r.png":"/providers/oai-cc.png":te?"/providers/anthropic-m.png":`/providers/${e2.id}.png`,alt:e2.name,width:48,height:48,className:"max-h-12 max-w-12 rounded-lg object-contain",sizes:"48px",onError:()=>Y(!0)})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3 flex-wrap",children:[(0,a.jsx)("h1",{className:"truncate text-2xl font-semibold tracking-tight sm:text-3xl",children:e2.name}),(e2.notice?.apiKeyUrl||e2.notice?.signupUrl||e2.website)&&(0,a.jsxs)("a",{href:e2.notice?.apiKeyUrl||e2.notice?.signupUrl||e2.website,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline inline-flex items-center gap-1",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"open_in_new"}),e2.notice?.apiKeyUrl?"Get API Key":"Sign up / Learn more"]})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:[u.length," connection",1===u.length?"":"s"]})]})]})]}),e2.deprecated&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px] text-yellow-500 mt-0.5 shrink-0",children:"warning"}),(0,a.jsx)("p",{className:"text-xs text-red-600 dark:text-yellow-400 leading-relaxed",children:e2.deprecationNotice})]}),e2.notice?.text&&!e2.deprecated&&(0,a.jsxs)("div",{className:"flex flex-col gap-2 rounded-lg border border-blue-500/30 bg-blue-500/10 px-3 py-2 sm:flex-row sm:items-center",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px] text-blue-500 shrink-0",children:"info"}),(0,a.jsx)("p",{className:"min-w-0 flex-1 text-xs leading-relaxed text-blue-600 dark:text-blue-400",children:e2.notice.text}),e2.notice.apiKeyUrl&&(0,a.jsx)("a",{href:e2.notice.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex justify-center rounded bg-blue-500 px-2 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-600 sm:py-0.5",children:"Get API Key →"})]}),tt&&j&&(0,a.jsx)(d.Zp,{children:(0,a.jsxs)("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:te?"Anthropic Compatible Details":"OpenAI Compatible Details"}),(0,a.jsxs)("p",{className:"break-all text-sm text-text-muted",children:[te?"Messages API":"responses"===j.apiType?"Responses API":"Chat Completions"," \xb7 ",(j.baseUrl||"").replace(/\/$/,""),"/",te?"messages":"responses"===j.apiType?"responses":"chat/completions"]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsx)(d.$n,{size:"sm",icon:"add",onClick:()=>F(!0),disabled:u.length>0,className:"w-full sm:w-auto",children:"Add"}),(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>W(!0),className:"w-full sm:w-auto",children:"Edit"}),(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"delete",onClick:async()=>{eE({title:"Delete Compatible Node",message:`Delete this ${te?"Anthropic":"OpenAI"} Compatible node?`,onConfirm:async()=>{eE(null);try{(await fetch(`/api/provider-nodes/${r}`,{method:"DELETE"})).ok&&s.push("/dashboard/providers")}catch(e){console.log("Error deleting provider node:",e)}}})},className:"w-full sm:w-auto",children:"Delete"})]})]})}),e6?(0,a.jsx)(d.gw,{providerId:r}):(0,a.jsxs)(d.Zp,{children:[(0,a.jsxs)("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:"Connections"}),(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",children:[u.length>0&&$.length>0&&(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"lan",onClick:()=>B(!0),children:"Apply Proxy"}),u.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"sync",onClick:tk,disabled:eU,children:eU?"Testing Connection One-by-One...":"Test Connection One-by-One"}),eU&&(0,a.jsx)(d.$n,{size:"sm",variant:"ghost",icon:"stop",onClick:()=>{eU&&(eH.current=!0,eq(!0))},disabled:ez,children:ez?"Stopping...":"Stop"})]}),"codex"===r&&(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,a.jsxs)("label",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-text-muted whitespace-nowrap",children:"Global Fast"}),(0,a.jsx)(d.lM,{checked:ev,onChange:e=>{ej(e),tb(ey,e)}})]}),(0,a.jsxs)("label",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-text-muted whitespace-nowrap",children:"My Fast"}),(0,a.jsx)(d.lM,{checked:ew,onChange:e=>{eN(e),tv(e)}})]})]}),tl&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("label",{htmlFor:"provider-default-reasoning",className:"text-xs font-medium text-text-muted whitespace-nowrap",children:"Default Reasoning"}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("select",{id:"provider-default-reasoning",value:ey,onChange:e=>{var t;eb(t=e.target.value),tb(t)},disabled:g,className:"h-6 w-28 appearance-none rounded-full border border-border/60 bg-surface-2 pl-3 pr-7 text-xs font-medium text-text-main transition-colors focus:border-primary/50 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-50",children:td.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))}),(0,a.jsx)("span",{className:"material-symbols-outlined pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[16px] text-text-muted",children:"expand_more"})]})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"text-xs text-text-muted font-medium",children:"Round Robin"}),(0,a.jsx)(d.lM,{checked:"round-robin"===eu,onChange:e=>{let t=e?"round-robin":null,s=e?ef||"1":ef;e&&!ef&&eg("1"),eh(t),ty(t,s)}}),"round-robin"===eu&&(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"Sticky:"}),(0,a.jsx)("input",{type:"number",min:1,value:ef,onChange:e=>{var t;eg(t=e.target.value),ty("round-robin",t)},placeholder:"1",className:"w-14 px-2 py-1 text-xs border border-border rounded-md bg-background focus:outline-none focus:border-primary"})]})]})]})]}),0===u.length?(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"inline-flex items-center justify-center w-9 h-9 rounded-full bg-primary/10 text-primary shrink-0",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:e3?"lock":"key"})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"No connections yet"}),ts&&(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:["Choose ",ta," or ",ti,"."]})]})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[ts?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",icon:"lock",variant:"secondary",onClick:eY,children:ta}),(0,a.jsx)(d.$n,{size:"sm",icon:"key",onClick:e0,children:ti})]}):(0,a.jsxs)(a.Fragment,{children:[!tt&&"iflow"===r&&(0,a.jsx)(d.$n,{size:"sm",icon:"cookie",variant:"secondary",onClick:()=>E(!0),children:"Cookie"}),(0,a.jsx)(d.$n,{size:"sm",icon:"add",onClick:e1,children:tt?"Add API Key":"iflow"===r?"OAuth":"Add Connection"})]}),"codex"===r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",icon:"upload_file",variant:"secondary",onClick:()=>_(!0),children:"Batch Import"}),(0,a.jsx)(d.$n,{size:"sm",icon:"sync",variant:"secondary",onClick:tA,loading:U,children:"Refresh Tokens"})]})]})]}):(0,a.jsxs)(a.Fragment,{children:[eL&&(0,a.jsx)("div",{className:"mb-4 rounded-lg border border-black/10 bg-black/[0.02] px-3 py-2 text-xs text-text-muted dark:border-white/10 dark:bg-white/[0.03]",children:(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,a.jsxs)("span",{children:["Total: ",eL.total]}),(0,a.jsxs)("span",{children:["Completed: ",eL.completed]}),(0,a.jsxs)("span",{children:["Passed: ",eL.passed]}),(0,a.jsxs)("span",{children:["Failed: ",eL.failed]}),eL.stopped&&(0,a.jsx)("span",{className:"text-amber-600 dark:text-amber-400",children:"Stopped"}),eU&&eM&&(0,a.jsxs)("span",{children:["Running: ",u.find(e=>e.id===eM)?.name||eM]})]})}),tz,!tt&&(0,a.jsxs)("div",{className:"mt-4 grid grid-cols-1 gap-2 sm:flex",children:["iflow"===r&&(0,a.jsx)(d.$n,{size:"sm",icon:"cookie",variant:"secondary",onClick:()=>E(!0),title:"Add connection using browser cookie",className:"w-full sm:w-auto",children:"Cookie"}),ts?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",icon:"lock",variant:"secondary",onClick:eY,className:"w-full sm:w-auto",children:ta}),(0,a.jsx)(d.$n,{size:"sm",icon:"key",onClick:e0,className:"w-full sm:w-auto",children:ti})]}):(0,a.jsx)(d.$n,{size:"sm",icon:"add",onClick:e1,className:"w-full sm:w-auto",children:"Add"}),"codex"===r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",icon:"upload_file",variant:"secondary",onClick:()=>_(!0),className:"w-full sm:w-auto",children:"Batch Import"}),(0,a.jsx)(d.$n,{size:"sm",icon:"sync",variant:"secondary",onClick:tA,loading:U,className:"w-full sm:w-auto",children:"Refresh Tokens"})]})]})]}),"codex"===r&&z&&(0,a.jsx)("div",{className:`mt-4 rounded-lg border px-3 py-2 text-sm ${z.error?"border-red-500/30 bg-red-500/10 text-red-600":"border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300"}`,children:z.error?z.error:`Token refresh complete: ${z.refreshed?.length||0} refreshed, ${z.failed?.length||0} failed, ${z.skipped?.length||0} skipped.`})]}),(0,a.jsxs)(d.Zp,{children:[(0,a.jsxs)("div",{className:"mb-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:"Available Models"}),!tt&&(e=[...e7,...e$.filter(e=>!e7.some(t=>t.id===e.id))].filter(e=>!e.type||"llm"===e.type).map(e=>e.id).filter(e=>!eO.includes(e)),(0,a.jsxs)("div",{className:"flex gap-2",children:[eO.length>0&&(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"restart_alt",onClick:tu,children:"Active All"}),e.length>0&&(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"block",onClick:()=>tx(e),children:"Disable All"})]}))]}),!!es&&(0,a.jsx)("p",{className:"text-xs text-red-500 mb-3 wrap-break-word",children:es}),(()=>{let e,t,s;if(tt)return(0,a.jsx)(v,{providerStorageAlias:tr,providerDisplayAlias:tn,modelAliases:Q,copied:eG,onCopy:eQ,onSetAlias:tj,onDeleteAlias:tw,connections:u,isAnthropic:te});let i=[...e7,...e$.filter(e=>!e7.some(t=>t.id===e.id))].filter(e=>!e.type||"llm"===e.type),l=new Set(eO),n=i.filter(e=>!l.has(e.id)),o=i.filter(e=>l.has(e.id)),d=Object.entries(Q).filter(([e,t])=>{let s=`${tr}/`;if(!t.startsWith(s))return!1;let a=t.slice(s.length);return e2.passthroughModels?!e7.some(e=>e.id===a):!e7.some(e=>e.id===a)&&e===a}).map(([e,t])=>({id:t.slice(`${tr}/`.length),alias:e,fullModel:t}));return(0,a.jsxs)("div",{className:"flex flex-wrap gap-3",children:[d.map(e=>(0,a.jsx)(y,{model:{id:e.id},fullModel:`${tn}/${e.id}`,displayModel:to?e.id:`${tn}/${e.id}`,alias:e.alias,copied:eG,onCopy:eQ,onSetAlias:()=>{},onDeleteAlias:()=>tw(e.alias),testStatus:ee[e.id],onTest:u.length>0||e6?()=>tJ(e.id):void 0,isTesting:ei===e.id,isCustom:!0,isFree:!1},e.id)),n.map(e=>{let t=`${tr}/${e.id}`,s=`${r}/${e.id}`,i=Object.entries(Q).find(([,e])=>e===t||e===s)?.[0];return(0,a.jsx)(y,{model:e,fullModel:`${tn}/${e.id}`,displayModel:to?e.id:`${tn}/${e.id}`,alias:i,copied:eG,onCopy:eQ,onSetAlias:t=>tj(e.id,t,tr),onDeleteAlias:()=>tw(i),testStatus:ee[e.id],onTest:u.length>0||e6?()=>tJ(e.id):void 0,isTesting:ei===e.id,isFree:e.isFree,onDisable:()=>tp(e.id)},e.id)}),(0,a.jsxs)("button",{onClick:()=>en(!0),className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-primary/40 px-3 py-2 text-xs text-primary transition-colors hover:border-primary hover:bg-primary/5 sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"add"}),"Add Model"]}),"qoder"===r&&u.some(e=>!1!==e.isActive)&&(0,a.jsxs)("button",{onClick:tN,disabled:eB,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-blue-500/40 px-3 py-2 text-xs text-blue-600 dark:text-blue-400 transition-colors hover:border-blue-500 hover:bg-blue-500/5 sm:w-auto disabled:opacity-50 disabled:cursor-not-allowed",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",style:eB?{animation:"spin 1s linear infinite"}:void 0,children:eB?"progress_activity":"download"}),eB?(0,x.Tl)("Fetching..."):(0,x.Tl)("Fetch Qoder Models")]}),eS.length>0&&(e=new Set(Object.values(Q)),t=new Set(e7.map(e=>e.id)),0===(s=eS.filter(s=>!e.has(`${tr}/${s.id}`)&&!t.has(s.id))).length?null:(0,a.jsxs)("div",{className:"w-full mt-2",children:[(0,a.jsx)("p",{className:"text-xs text-text-muted mb-2",children:"Suggested free models (≥200k context):"}),(0,a.jsx)("div",{className:"flex flex-wrap gap-2",children:s.map(e=>(0,a.jsxs)("button",{onClick:async()=>{let t=e.id.split("/").pop();await tj(e.id,t,tr)},className:"flex items-center gap-1 px-2.5 py-1.5 rounded-lg border border-black/10 dark:border-white/10 text-xs text-text-muted hover:text-primary hover:border-primary/40 hover:bg-primary/5 transition-colors",title:`${e.name} \xb7 ${(e.contextLength/1e3).toFixed(0)}k ctx`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),e.id.split("/").pop()]},e.id))})]})),o.length>0&&(0,a.jsxs)("div",{className:"w-full mt-2",children:[(0,a.jsxs)("p",{className:"text-xs text-text-muted mb-2",children:["Disabled models (",o.length,"):"]}),(0,a.jsx)("div",{className:"flex flex-wrap gap-2",children:o.map(e=>(0,a.jsxs)("button",{onClick:()=>tm(e.id),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-lg border border-dashed border-black/10 dark:border-white/10 text-xs text-text-muted hover:text-primary hover:border-primary/40 hover:bg-primary/5 transition-colors",title:"Restore model",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),e.id]},e.id))})]})]})})()]}),tK,"kiro"===r?(0,a.jsx)(d.Mh,{isOpen:O,providerInfo:e2,onSuccess:tS,onClose:()=>P(!1)}):"cursor"===r?(0,a.jsx)(d.G9,{isOpen:O,onSuccess:tS,onClose:()=>P(!1)}):"gitlab"===r?(0,a.jsx)(d.vj,{isOpen:O,providerInfo:e2,onSuccess:tS,onClose:()=>P(!1)}):(0,a.jsx)(d.LF,{isOpen:O,provider:r,providerInfo:e2,onSuccess:tS,onClose:()=>P(!1)}),"iflow"===r&&(0,a.jsx)(d.vE,{isOpen:I,onSuccess:()=>{tf(),E(!1)},onClose:()=>E(!1)}),"codex"===r&&(0,a.jsx)(A,{isOpen:R,onSuccess:tf,onClose:()=>_(!1)}),(0,a.jsx)(k,{isOpen:M,provider:r,providerName:e2.name,isCompatible:tt,isAnthropic:te,authType:e2?.authType,authHint:e2?.authHint,website:e2?.website,proxyPools:$,onSave:t$,onClose:()=>F(!1)}),(0,a.jsx)(d.wI,{isOpen:K,connection:V,proxyPools:$,onSave:tT,onClose:()=>J(!1)}),tt&&(0,a.jsx)(C,{isOpen:L,node:j,onSave:tg,onClose:()=>W(!1),isAnthropic:te}),!tt&&(0,a.jsx)(S,{isOpen:er,providerAlias:tr,providerDisplayAlias:tn,onSave:async e=>{let t=e2?.passthroughModels?e.split("/").pop():e;await tj(e,t,tr),en(!1)},onClose:()=>en(!1)}),(0,a.jsx)(d.uo,{isOpen:eR,onClose:()=>e_(!1),onConfirm:()=>{(window.localStorage.setItem(eZ,"true"),e_(!1),e3)?eX():e0()},title:"Risk Notice",message:e2?.deprecationNotice,confirmText:"I Understand, Continue",cancelText:"Cancel",variant:"danger"}),(0,a.jsx)(d.uo,{isOpen:!!eI,onClose:()=>eE(null),onConfirm:eI?.onConfirm,title:eI?.title||"Confirm",message:eI?.message,variant:"danger"})]}):(0,a.jsxs)("div",{className:"text-center py-20",children:[(0,a.jsx)("p",{className:"text-text-muted",children:"Provider not found"}),(0,a.jsx)(n(),{href:"/dashboard/providers",className:"text-primary mt-4 inline-block",children:"Back to Providers"})]})}k.propTypes={isOpen:g().bool.isRequired,provider:g().string,providerName:g().string,isCompatible:g().bool,isAnthropic:g().bool,authType:g().string,authHint:g().string,website:g().string,proxyPools:g().arrayOf(g().shape({id:g().string,name:g().string})),onSave:g().func.isRequired,onBulkDone:g().func,onClose:g().func.isRequired},C.propTypes={isOpen:g().bool.isRequired,node:g().shape({id:g().string,name:g().string,prefix:g().string,apiType:g().string,baseUrl:g().string}),onSave:g().func.isRequired,onClose:g().func.isRequired,isAnthropic:g().bool},S.propTypes={isOpen:g().bool.isRequired,providerAlias:g().string.isRequired,providerDisplayAlias:g().string.isRequired,onSave:g().func.isRequired,onClose:g().func.isRequired},A.propTypes={isOpen:g().bool.isRequired,onClose:g().func.isRequired,onSuccess:g().func}},29610:(e,t,s)=>{Promise.resolve().then(s.bind(s,7570))}},e=>{e.O(0,[2574,3862,1051,5772,1321,5497,8441,3794,7358],()=>e(e.s=29610)),_N_E=e.O()}]);
3
+ sk-...`;function k({isOpen:e,provider:t,providerName:s,isCompatible:l,isAnthropic:r,authType:n,authHint:o,website:p,proxyPools:m,onSave:x,onBulkDone:u,onClose:h}){let f="__none__",g="ollama-local"===t,y="cookie"===n,b="xai"===t&&!y,v=y?"Cookie Value":"API Key",j=y?"grok-web"===t?"sso=xxxxx... or just the raw value":"eyJhbGciOi...":b?"xai-...":"",w="azure"===t,C="cloudflare-ai"===t,S=c.Q2?.[t]?.regions||null,$=c.Q2?.[t]?.defaultRegion||S?.[0]?.id||"",[A,T]=(0,i.useState)({name:"",apiKey:"",priority:1,proxyPoolId:f,ollamaHostUrl:""}),[O,P]=(0,i.useState)({azureEndpoint:"",apiVersion:"2024-10-01-preview",deployment:"",organization:""}),[I,E]=(0,i.useState)({accountId:""}),[R,_]=(0,i.useState)($),[U,D]=(0,i.useState)(!1),[z,q]=(0,i.useState)(null),[M,F]=(0,i.useState)(!1),[K,J]=(0,i.useState)("single"),[L,W]=(0,i.useState)(""),[H,B]=(0,i.useState)(null),V=g?"Ollama Local":y?`${s||t} Cookie`:"Production Key";(0,i.useEffect)(()=>{e&&(T({name:l?V:"",apiKey:"",priority:1,proxyPoolId:f,ollamaHostUrl:""}),P({azureEndpoint:"",apiVersion:"2024-10-01-preview",deployment:"",organization:""}),E({accountId:""}),D(!1),q(null),F(!1),J("single"),W(""),B(null))},[V,l,e]);let G=()=>g&&A.ollamaHostUrl.trim()?{baseUrl:A.ollamaHostUrl.trim()}:w?{azureEndpoint:O.azureEndpoint,apiVersion:O.apiVersion,deployment:O.deployment,organization:O.organization}:C?{accountId:I.accountId}:S&&R?{region:R}:void 0,Q=async()=>{D(!0);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:A.apiKey,providerSpecificData:G()})}),s=await e.json();q(s.valid?"success":"failed")}catch{q("failed")}finally{D(!1)}},Z=async()=>{if(!t||!g&&!A.apiKey)return;let e=A.name.trim()||V;F(!0);try{let s=!1;try{D(!0),q(null);let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:A.apiKey,providerSpecificData:G()})});s=!!(await e.json()).valid,q(s?"success":"failed")}catch{q("failed")}finally{D(!1)}await x({name:e,apiKey:A.apiKey,priority:A.priority,proxyPoolId:A.proxyPoolId===f?null:A.proxyPoolId,testStatus:s?"active":"unknown",providerSpecificData:G()})}finally{F(!1)}},X=async()=>{let e=L.split("\n").map(e=>e.trim()).filter(Boolean);if(!e.length)return;F(!0),B(null);let s=0,a=0;for(let i=0;i<e.length;i++){let l=e[i].split("|"),r=l.length>=2?l.slice(1).join("|").trim():l[0].trim(),n=l.length>=2?l[0].trim():"Key",o=`${n} ${i+1}`;try{(await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:r,name:o,priority:1,testStatus:"unknown"})})).ok?s++:a++}catch{a++}}F(!1),B({success:s,failed:a}),s>0&&u&&u()};return t?(0,a.jsx)(d.aF,{isOpen:e,title:`Add ${s||t} ${v}`,onClose:h,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{size:"sm",variant:"single"===K?"primary":"ghost",onClick:()=>{J("single"),B(null)},children:"Single"}),(0,a.jsx)(d.$n,{size:"sm",variant:"bulk"===K?"primary":"ghost",onClick:()=>{J("bulk"),B(null)},children:"Bulk Add"})]}),"bulk"===K&&(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:["One key per line. Format: ",(0,a.jsx)("code",{children:"name|apiKey"})," or just ",(0,a.jsx)("code",{children:"apiKey"})," (auto-named by index)."]}),(0,a.jsx)("textarea",{className:"w-full rounded border border-accent/30 bg-sidebar p-2 text-sm font-mono resize-y min-h-[140px] focus:outline-none focus:ring-1 focus:ring-primary",placeholder:N,value:L,onChange:e=>W(e.target.value)}),H&&(0,a.jsxs)("div",{className:`text-sm font-medium ${H.failed>0?"text-yellow-400":"text-green-400"}`,children:["✓ ",H.success," added",H.failed>0?`, ✗ ${H.failed} failed`:""]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{onClick:X,fullWidth:!0,disabled:M||!L.trim(),children:M?"Adding...":"Add All Keys"}),(0,a.jsx)(d.$n,{onClick:h,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),"single"===K&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.pd,{label:"Name",value:A.name,onChange:e=>T({...A,name:e.target.value}),placeholder:V}),g&&(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.pd,{label:"Ollama Host URL",value:A.ollamaHostUrl,onChange:e=>T({...A,ollamaHostUrl:e.target.value}),placeholder:"http://localhost:11434",className:"flex-1"}),(0,a.jsx)("div",{className:"pt-6",children:(0,a.jsx)(d.$n,{onClick:Q,disabled:U||M,variant:"secondary",children:U?"Checking...":"Check"})})]}),!g&&(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.pd,{label:v,type:y?"text":"password",value:A.apiKey,onChange:e=>T({...A,apiKey:e.target.value}),placeholder:j,className:"flex-1"}),(0,a.jsx)("div",{className:"pt-6",children:(0,a.jsx)(d.$n,{onClick:Q,disabled:!A.apiKey||U||M,variant:"secondary",children:U?"Checking...":"Check"})})]}),b&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Use a direct xAI API key from console.x.ai. This is separate from Grok Build OAuth."}),y&&o&&(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:[o,p&&(0,a.jsxs)(a.Fragment,{children:[" ",(0,a.jsxs)("a",{href:p,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:["Open ",p.replace(/^https?:\/\//,"")]})]})]}),S&&(0,a.jsx)(d.l6,{label:"Region",value:R,onChange:e=>_(e.target.value),options:S.map(e=>({value:e.id,label:e.label}))}),l&&(0,a.jsx)(d.pd,{label:"Default Model",value:A.defaultModel,onChange:e=>T({...A,defaultModel:e.target.value}),placeholder:r?"claude-3-5-sonnet-latest":"gpt-4o-mini"}),g&&(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:["Leave blank to use ",(0,a.jsx)("code",{children:"http://localhost:11434"}),". For remote Ollama, enter the full host URL (e.g. ",(0,a.jsx)("code",{children:"http://192.168.1.10:11434"}),")."]}),z&&(0,a.jsx)(d.Ex,{variant:"success"===z?"success":"error",children:"success"===z?"Valid":"Invalid"}),l&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:r?`Validation checks ${s||"Anthropic Compatible"} by verifying the API key.`:`Validation checks ${s||"OpenAI Compatible"} via /models on your base URL.`}),C&&(0,a.jsxs)("div",{className:"bg-sidebar/50 p-4 rounded-lg border border-accent/20",children:[(0,a.jsx)("h3",{className:"font-semibold mb-3 text-sm",children:"Cloudflare Workers AI"}),(0,a.jsx)(d.pd,{label:"Account ID",value:I.accountId,onChange:e=>E({...I,accountId:e.target.value}),placeholder:"abc123def456..."}),(0,a.jsxs)("p",{className:"text-xs text-text-muted mt-2",children:["Find your Account ID in the right sidebar of ",(0,a.jsx)("a",{href:"https://dash.cloudflare.com",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"dash.cloudflare.com"})]})]}),w&&(0,a.jsxs)("div",{className:"bg-sidebar/50 p-4 rounded-lg border border-accent/20",children:[(0,a.jsx)("h3",{className:"font-semibold mb-3 text-sm",children:"Azure OpenAI Configuration"}),(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsx)(d.pd,{label:"Azure Endpoint",value:O.azureEndpoint,onChange:e=>P({...O,azureEndpoint:e.target.value}),placeholder:"https://your-resource.openai.azure.com"}),(0,a.jsx)(d.pd,{label:"Deployment Name",value:O.deployment,onChange:e=>P({...O,deployment:e.target.value}),placeholder:"gpt-4"}),(0,a.jsx)(d.pd,{label:"API Version",value:O.apiVersion,onChange:e=>P({...O,apiVersion:e.target.value}),placeholder:"2024-10-01-preview"}),(0,a.jsx)(d.pd,{label:"Organization",value:O.organization,onChange:e=>P({...O,organization:e.target.value}),placeholder:"Organization ID"})]})]}),(0,a.jsx)(d.pd,{label:"Priority",type:"number",value:A.priority,onChange:e=>T({...A,priority:Number.parseInt(e.target.value)||1})}),(0,a.jsx)(d.l6,{label:"Proxy Pool",value:A.proxyPoolId,onChange:e=>T({...A,proxyPoolId:e.target.value}),options:[{value:f,label:"None"},...(m||[]).map(e=>({value:e.id,label:e.name}))],placeholder:"None"}),0===(m||[]).length&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"No active proxy pools available. Create one in Proxy Pools page first."}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Legacy manual proxy fields are still accepted by API for backward compatibility."}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{onClick:Z,fullWidth:!0,disabled:M||!g&&!A.apiKey||w&&(!O.azureEndpoint||!O.deployment||!O.organization)||C&&!I.accountId,children:M?"Saving...":"Save"}),(0,a.jsx)(d.$n,{onClick:h,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})]})}):null}function C({isOpen:e,node:t,onSave:s,onClose:l,isAnthropic:r}){let[n,o]=(0,i.useState)({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[c,p]=(0,i.useState)(!1),[m,x]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[f,g]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null);(0,i.useEffect)(()=>{t&&o({name:t.name||"",prefix:t.prefix||"",apiType:t.apiType||"chat",baseUrl:t.baseUrl||(r?"https://api.anthropic.com/v1":"https://api.openai.com/v1")})},[t,r]);let v=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};r||(e.apiType=n.apiType),await s(e)}finally{p(!1)}}},j=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:m,type:r?"anthropic-compatible":"openai-compatible",modelId:u.trim()||void 0})}),t=await e.json();b(t.valid?"success":"failed")}catch{b("failed")}finally{g(!1)}};return t?(0,a.jsx)(d.aF,{isOpen:e,title:`Edit ${r?"Anthropic":"OpenAI"} Compatible`,onClose:l,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsx)(d.pd,{label:"Name",value:n.name,onChange:e=>o({...n,name:e.target.value}),placeholder:`${r?"Anthropic":"OpenAI"} Compatible (Prod)`,hint:"Required. A friendly label for this node."}),(0,a.jsx)(d.pd,{label:"Prefix",value:n.prefix,onChange:e=>o({...n,prefix:e.target.value}),placeholder:r?"ac-prod":"oc-prod",hint:"Required. Used as the provider prefix for model IDs."}),!r&&(0,a.jsx)(d.l6,{label:"API Type",options:[{value:"chat",label:"Chat Completions"},{value:"responses",label:"Responses API"}],value:n.apiType,onChange:e=>o({...n,apiType:e.target.value})}),(0,a.jsx)(d.pd,{label:"Base URL",value:n.baseUrl,onChange:e=>o({...n,baseUrl:e.target.value}),placeholder:r?"https://api.anthropic.com/v1":"https://api.openai.com/v1",hint:`Use the base URL (ending in /v1) for your ${r?"Anthropic":"OpenAI"}-compatible API.`}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.pd,{label:"API Key (for Check)",type:"password",value:m,onChange:e=>x(e.target.value),className:"flex-1"}),(0,a.jsx)("div",{className:"pt-6",children:(0,a.jsx)(d.$n,{onClick:j,disabled:!m||f||!n.baseUrl.trim(),variant:"secondary",children:f?"Checking...":"Check"})})]}),(0,a.jsx)(d.pd,{label:"Model ID (optional)",value:u,onChange:e=>h(e.target.value),placeholder:"e.g. my-model-id",hint:"If provider lacks /models endpoint, enter a model ID to validate via chat/completions instead."}),y&&(0,a.jsx)(d.Ex,{variant:"success"===y?"success":"error",children:"success"===y?"Valid":"Invalid"}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{onClick:v,fullWidth:!0,disabled:!n.name.trim()||!n.prefix.trim()||!n.baseUrl.trim()||c,children:c?"Saving...":"Save"}),(0,a.jsx)(d.$n,{onClick:l,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}function S({isOpen:e,providerAlias:t,providerDisplayAlias:s,onSave:l,onClose:r}){var n;let o,[c,p]=(0,i.useState)(""),[m,x]=(0,i.useState)(null),[u,h]=(0,i.useState)(""),[f,g]=(0,i.useState)(!1);(0,i.useEffect)(()=>{e&&(p(""),x(null),h(""),g(!1))},[e]);let y=(n=c.trim(),o=`${t}/`,n.startsWith(o)?n.slice(o.length):n),b=async()=>{if(y){x("testing"),h("");try{let e=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${t}/${y}`})}),s=await e.json();x(s.ok?"ok":"error"),h(s.error||"")}catch(e){x("error"),h(e.message)}}},v=async()=>{if(y&&!f){g(!0);try{await l(y)}finally{g(!1)}}};return(0,a.jsx)(d.aF,{isOpen:e,onClose:r,title:"Add Custom Model",children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-sm font-medium mb-1.5 block",children:"Model ID"}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("input",{type:"text",value:c,onChange:e=>{p(e.target.value),x(null),h("")},onKeyDown:e=>{"Enter"===e.key&&b()},placeholder:"e.g. claude-opus-4-5",className:"flex-1 px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",autoFocus:!0}),(0,a.jsx)(d.$n,{type:"button",variant:"secondary",icon:"science",loading:"testing"===m,onClick:b,disabled:!y||"testing"===m,children:"testing"===m?"Testing...":"Test"})]}),(0,a.jsxs)("p",{className:"text-xs text-text-muted mt-1",children:["Sent to provider as: ",(0,a.jsx)("code",{className:"font-mono bg-sidebar px-1 rounded",children:y||"model-id"})]})]}),"ok"===m&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-base",children:"check_circle"}),"Model is reachable"]}),"error"===m&&(0,a.jsxs)("div",{className:"flex items-start gap-2 text-sm text-red-500",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-base shrink-0",children:"cancel"}),(0,a.jsx)("span",{children:u||"Model not reachable"})]}),(0,a.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,a.jsx)(d.$n,{type:"button",onClick:r,variant:"ghost",fullWidth:!0,size:"sm",children:"Cancel"}),(0,a.jsx)(d.$n,{type:"button",onClick:v,fullWidth:!0,size:"sm",disabled:!y||f,children:f?"Adding...":"Add Model"})]})]})})}function $({isOpen:e,onClose:t,onSuccess:s}){let[l,r]=(0,i.useState)([]),[n,o]=(0,i.useState)(""),[c,p]=(0,i.useState)(!1),[m,x]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),f=()=>{r([]),o(""),x(null),h(null),t()},g=async()=>{p(!0),x(null),h(null);try{let e=await Promise.all(l.map(async e=>({filename:e.name,jsonText:await e.text()}))),t=n.trim()?[{filename:"pasted JSON",jsonText:n.trim()}]:[],a=[...e,...t];if(0===a.length)throw Error("Select JSON files or paste JSON first");let i=await fetch("/api/oauth/codex/import-batch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:a})}),r=await i.json();if(!i.ok)throw Error(r.error||"Failed to import accounts");x(r),r.imported?.length>0&&s?.()}catch(e){h(e.message||"Failed to import accounts")}finally{p(!1)}},y=m?.imported?.length||0,b=m?.skipped?.length||0;return(0,a.jsx)(d.aF,{isOpen:e,title:"Import Codex Accounts",onClose:f,size:"lg",children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"rounded-lg border border-border bg-surface/50 p-3",children:[(0,a.jsx)("label",{className:"mb-2 block text-sm font-medium",children:"JSON files"}),(0,a.jsx)("input",{type:"file",accept:".json,application/json",multiple:!0,onChange:e=>r(Array.from(e.target.files||[])),className:"block w-full text-sm text-text-muted file:mr-3 file:rounded-md file:border-0 file:bg-primary file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-white hover:file:bg-primary/90"}),l.length>0&&(0,a.jsx)("div",{className:"mt-2 flex flex-wrap gap-1.5",children:l.map(e=>(0,a.jsx)("span",{className:"rounded bg-primary/10 px-2 py-0.5 text-xs text-primary",children:e.name},`${e.name}-${e.size}`))})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"mb-2 block text-sm font-medium",children:"Paste JSON"}),(0,a.jsx)("textarea",{value:n,onChange:e=>o(e.target.value),placeholder:'[{ "type": "codex", "access_token": "...", "refresh_token": "..." }]',className:"h-36 w-full resize-none rounded-md border border-black/10 bg-white px-3 py-2 font-mono text-xs text-text-main shadow-inner transition-all placeholder-text-muted/60 focus:border-primary/50 focus:outline-none focus:ring-1 focus:ring-primary/30 dark:border-white/10 dark:bg-white/5"})]}),(0,a.jsx)("div",{className:"rounded-lg border border-border bg-background/60 px-3 py-2 text-xs text-text-muted",children:"Auto-detects Codex Session JSON, CLI Proxy API Auth JSON, and Sub2API JSON."}),u&&(0,a.jsx)("div",{className:"rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-600",children:u}),m&&(0,a.jsxs)("div",{className:"rounded-lg border border-border bg-surface/40 p-3",children:[(0,a.jsxs)("div",{className:"mb-2 flex flex-wrap items-center gap-2 text-sm",children:[(0,a.jsxs)("span",{className:"font-medium text-green-600",children:[y," imported"]}),b>0&&(0,a.jsxs)("span",{className:"text-text-muted",children:[b," skipped"]})]}),m.imported?.length>0&&(0,a.jsx)("div",{className:"max-h-32 overflow-auto rounded border border-border/70",children:m.imported.map(e=>(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-border/70 px-2 py-1.5 last:border-b-0",children:[(0,a.jsx)("span",{className:"min-w-0 truncate text-xs",children:e.email||e.displayName||e.name||e.id}),(0,a.jsx)("span",{className:"shrink-0 text-xs text-text-muted",children:e.sourceFormat})]},e.id))}),m.skipped?.length>0&&(0,a.jsx)("div",{className:"mt-2 max-h-28 overflow-auto rounded border border-border/70",children:m.skipped.map((e,t)=>(0,a.jsxs)("div",{className:"border-b border-border/70 px-2 py-1.5 text-xs last:border-b-0",children:[(0,a.jsx)("span",{className:"font-medium",children:e.filename}),(0,a.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",e.reason]})]},`${e.filename}-${t}`))})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(d.$n,{onClick:g,loading:c,disabled:c||!l.length&&!n.trim(),fullWidth:!0,children:"Import"}),(0,a.jsx)(d.$n,{onClick:f,variant:"ghost",fullWidth:!0,children:"Close"})]})]})})}function A(){let e,t=(0,l.useParams)(),s=(0,l.useRouter)(),r=t.id,[u,f]=(0,i.useState)([]),[g,b]=(0,i.useState)(!0),[j,N]=(0,i.useState)(null),[A,T]=(0,i.useState)([]),[O,P]=(0,i.useState)(!1),[I,E]=(0,i.useState)(!1),[R,_]=(0,i.useState)(!1),[U,D]=(0,i.useState)(!1),[z,q]=(0,i.useState)(null),[M,F]=(0,i.useState)(!1),[K,J]=(0,i.useState)(!1),[L,W]=(0,i.useState)(!1),[H,B]=(0,i.useState)(!1),[V,G]=(0,i.useState)(null),[Q,Z]=(0,i.useState)({}),[X,Y]=(0,i.useState)(!1),[ee,et]=(0,i.useState)({}),[es,ea]=(0,i.useState)(""),[ei,el]=(0,i.useState)(null),[er,en]=(0,i.useState)(!1),[eo,ed]=(0,i.useState)([]),[ec,ep]=(0,i.useState)("__none__"),[em,ex]=(0,i.useState)(!1),[eu,eh]=(0,i.useState)(null),[ef,eg]=(0,i.useState)(""),[ey,eb]=(0,i.useState)("auto"),[ev,ej]=(0,i.useState)(!1),[ew,eN]=(0,i.useState)(!1),[ek,eC]=(0,i.useState)("super_admin"),[eS,e$]=(0,i.useState)([]),[eA,eT]=(0,i.useState)([]),[eO,eP]=(0,i.useState)([]),[eI,eE]=(0,i.useState)(null),[eR,e_]=(0,i.useState)(!1),[eU,eD]=(0,i.useState)(!1),[ez,eq]=(0,i.useState)(!1),[eM,eF]=(0,i.useState)(null),[eK,eJ]=(0,i.useState)({}),[eL,eW]=(0,i.useState)(null),eH=(0,i.useRef)(!1),[eB,eV]=(0,i.useState)(!1),{copied:eG,copy:eQ}=(0,m.C)(),eZ="ag_risk_confirmed",eX=()=>{P(!0)},eY=()=>{"antigravity"===r&&"true"!==window.localStorage.getItem(eZ)?e_(!0):e3?eX():F(!0)},e0=()=>{F(!0)},e1=()=>{e3?eY():e0()},e2=j?{id:j.id,name:j.name||("anthropic-compatible"===j.type?"Anthropic Compatible":"OpenAI Compatible"),color:"anthropic-compatible"===j.type?"#D97757":"#10A37F",textIcon:"anthropic-compatible"===j.type?"AC":"OC",apiType:j.apiType,baseUrl:j.baseUrl,type:j.type}:c.zN[r]||c.fg[r]||c.IS[r]||c.nJ[r]||c.br[r],e5=e2?.authModes||[],e3=!!c.zN[r]||!!c.IS[r]||e5.includes("oauth"),e4=!!c.fg[r]||e5.includes("apikey"),e6=!!c.IS[r]?.noAuth,e7=(0,p.KC)(r),e8=(0,c.wG)(r),e9=(0,c.mq)(r),te=(0,c.gb)(r),tt=e9||te,ts=!tt&&e3&&e4,ta="xai"===r?"Grok Build OAuth":"OAuth",ti="xai"===r?"xAI API Key":"API Key",tl=c.Q2[r]?.thinkingConfig||c.s9.extended,tr=tt?r:e8,tn=tt?j?.prefix||r:e8,to="codex"===r,td=(tl?.options||[]).map(e=>({value:e,label:"auto"===e?"codex"===r?"Auto (Medium)":"Auto":"xhigh"===e?"XHigh":e.charAt(0).toUpperCase()+e.slice(1)})),tc=(0,i.useCallback)(async()=>{try{let e=await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(tr)}`,{cache:"no-store"}),t=await e.json();e.ok&&eP(t.ids||[])}catch(e){console.log("Error fetching disabled models:",e)}},[tr]),tp=async e=>{try{(await fetch("/api/models/disabled",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:tr,ids:[e]})})).ok&&await tc()}catch(e){console.log("Error disabling model:",e)}},tm=async e=>{try{(await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(tr)}&id=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await tc()}catch(e){console.log("Error enabling model:",e)}},tx=async e=>{e.length&&eE({title:"Disable All Models",message:`Disable all ${e.length} model(s)?`,onConfirm:async()=>{eE(null);try{(await fetch("/api/models/disabled",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:tr,ids:e})})).ok&&await tc()}catch(e){console.log("Error disabling all models:",e)}}})},tu=async()=>{try{(await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(tr)}`,{method:"DELETE"})).ok&&await tc()}catch(e){console.log("Error enabling all models:",e)}},th=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&Z(t.aliases||{})}catch(e){console.log("Error fetching aliases:",e)}},[]);(0,i.useEffect)(()=>{"kilocode"===r&&fetch("/api/providers/kilo/free-models").then(e=>e.json()).then(e=>{e.models?.length&&eT(e.models)}).catch(()=>{})},[r]);let tf=(0,i.useCallback)(async()=>{try{let[e,t,s,a,i]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/provider-nodes",{cache:"no-store"}),fetch("/api/proxy-pools?isActive=true",{cache:"no-store"}),fetch("/api/settings",{cache:"no-store"}),fetch("/api/auth/me",{cache:"no-store"})]),l=await e.json(),n=await t.json(),o=await s.json(),d=a.ok?await a.json():{},c=i.ok?await i.json():{};if(e.ok){let e=(l.connections||[]).filter(e=>e.provider===r);f(e)}s.ok&&T(o.proxyPools||[]);let p=(d.providerStrategies||{})[r]||{};eh(p.fallbackStrategy||null),eg(null!=p.stickyRoundRobinLimit?String(p.stickyRoundRobinLimit):"1");let m=(d.providerThinking||{})[r]||{},x=c.providerThinkingScopeKey||c.userId||"super_admin",u="sub_user"===c.role?(c.providerThinking||{})[r]||{}:(d.userProviderThinking||{})[x]?.[r]||{};if(eb(m.mode||"auto"),ej(!0===m.fastMode),eC(x),eN(Object.prototype.hasOwnProperty.call(u,"fastMode")?!0===u.fastMode:!0===m.fastMode),t.ok){let e=(n.nodes||[]).find(e=>e.id===r)||null;if(!e&&tt)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}N(e)}}catch(e){console.log("Error fetching connections:",e)}finally{b(!1)}},[r,tt]),tg=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&&(N(s.node),await tf(),W(!1))}catch(e){console.log("Error updating provider node:",e)}},ty=async(e,t)=>{try{let s=await fetch("/api/settings",{cache:"no-store"}),a=(s.ok?await s.json():{}).providerStrategies||{},i={};e&&(i.fallbackStrategy=e),"round-robin"===e&&""!==t&&(i.stickyRoundRobinLimit=Number(t)||3);let l={...a};0===Object.keys(i).length?delete l[r]:l[r]=i,await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerStrategies:l})})}catch(e){console.log("Error saving provider strategy:",e)}},tb=async(e,t=ev)=>{try{let s=await fetch("/api/settings",{cache:"no-store"}),a={...(s.ok?await s.json():{}).providerThinking||{}},i={};e&&"auto"!==e&&(i.mode=e),"codex"===r&&!0===t&&(i.fastMode=!0),0===Object.keys(i).length?delete a[r]:a[r]=i,await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerThinking:a})})}catch(e){console.log("Error saving thinking config:",e)}},tv=async e=>{try{let t=await fetch("/api/settings",{cache:"no-store"}),s=(t.ok?await t.json():{}).userProviderThinking||{},a=ek||"super_admin",i=s[a]||{},l=i[r]||{},n={...s,[a]:{...i,[r]:{...l,fastMode:e}}};await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({userProviderThinking:n})})}catch(e){console.log("Error saving account fast mode:",e)}};(0,i.useEffect)(()=>{(async()=>{await Promise.all([tf(),th(),tc()])})()},[tf,th,tc]),(0,i.useEffect)(()=>{let e=(c.zN[r]||c.fg[r]||c.IS[r]||c.nJ[r])?.modelsFetcher;e&&h(e).then(e$)},[r]);let tj=async(e,t,s=e8)=>{let a=`${s}/${e}`;try{let e=await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:a,alias:t})});if(e.ok)await th();else{let t=await e.json();alert(t.error||"Failed to set alias")}}catch(e){console.log("Error setting alias:",e)}},tw=async e=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await th()}catch(e){console.log("Error deleting alias:",e)}},tN=async()=>{if(eB)return;let e=u.find(e=>!1!==e.isActive);if(!e)return void alert((0,x.Tl)("Please add an active Qoder connection first"));eV(!0);try{let t=await fetch(`/api/providers/${e.id}/models`),s=await t.json();if(!t.ok)return void alert(s.error||(0,x.Tl)("Failed to fetch models"));let a=s.models||[];if(0===a.length)return void alert((0,x.Tl)("No models returned"));let i=0;for(let e of a){let t=e.id||e.name;if(!t)continue;let s=t.replace(/^qoder\//,""),a=`${tr}/${s}`;!Object.values(Q).includes(a)&&(Q[s]||(await tj(s,s,tr),i+=1))}0===i?alert((0,x.Tl)("All models already exist, no new models added")):alert((0,x.Tl)("Successfully added")+` ${i} `+(0,x.Tl)("models"))}catch(e){console.log("Error importing Qoder models:",e),alert((0,x.Tl)("Error fetching models")+": "+e.message)}finally{eV(!1)}},tk=async()=>{if(eU||0===u.length)return;let e=Object.fromEntries(u.map(e=>[e.id,{state:"queued",error:null}]));eH.current=!1,eD(!0),eq(!1),eF(null),eJ(e),eW({total:u.length,completed:0,passed:0,failed:0,stopped:!1});let t=0,s=0;try{for(let e=0;e<u.length;e+=1){if(eH.current){eW({total:u.length,completed:e,passed:t,failed:s,stopped:!0});break}let a=u[e];eF(a.id),eJ(e=>({...e,[a.id]:{state:"testing",error:null}}));try{let e=await fetch(`/api/providers/${a.id}/test`,{method:"POST"}),i=await e.json(),l=!!i.valid;l?t+=1:s+=1,eJ(e=>({...e,[a.id]:{state:l?"success":"failed",error:l?null:i.error||null}}))}catch(e){s+=1,eJ(t=>({...t,[a.id]:{state:"failed",error:e.message||"Test failed"}}))}eW({total:u.length,completed:e+1,passed:t,failed:s,stopped:!1}),e<u.length-1&&await new Promise(e=>setTimeout(e,1e3))}}finally{eF(null),eD(!1),eq(!1),eH.current=!1}},tC=async e=>{eE({title:"Delete Connection",message:"Delete this connection?",onConfirm:async()=>{eE(null);try{(await fetch(`/api/providers/${e}`,{method:"DELETE"})).ok&&f(u.filter(t=>t.id!==e))}catch(e){console.log("Error deleting connection:",e)}}})},tS=()=>{tf(),P(!1)},t$=async()=>{if(!U){D(!0),q(null);try{let e=await fetch("/api/oauth/codex/refresh-all",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}),t=await e.json();if(!e.ok&&!t?.refreshed?.length)throw Error(t.error||"Failed to refresh Codex tokens");q(t),await tf()}catch(e){q({error:e.message,refreshed:[],failed:[],skipped:[]})}finally{D(!1)}}},tA=async e=>{try{(await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,...e})})).ok&&(await tf(),F(!1))}catch(e){console.log("Error saving connection:",e)}},tT=async e=>{try{(await fetch(`/api/providers/${V.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(await tf(),J(!1))}catch(e){console.log("Error updating connection:",e)}},tO=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&f(s=>s.map(s=>s.id===e?{...s,isActive:t}:s))}catch(e){console.log("Error updating connection status:",e)}},tP=async(e,t)=>{let s=[...u];[s[e],s[t]]=[s[t],s[e]],f(s);try{await Promise.all([fetch(`/api/providers/${s[e].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:e})}),fetch(`/api/providers/${s[t].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:t})})])}catch(e){console.log("Error swapping priority:",e),await tf()}},tI=(0,i.useMemo)(()=>new Set(u.map(e=>e.id)),[u]),tE=(0,i.useMemo)(()=>eo.filter(e=>tI.has(e)),[eo,tI]),tR=u.filter(e=>tE.includes(e.id));u.length>0&&(tE.length,u.length);let t_=(()=>{if(0===tR.length)return"";let e=new Set(tR.map(e=>e.providerSpecificData?.proxyPoolId||"__none__"));if(1===e.size){let t=[...e][0];if("__none__"===t)return"All selected currently unbound";let s=A.find(e=>e.id===t);return`All selected currently bound to ${s?.name||t}`}return"Selected connections have mixed proxy bindings"})(),tU=()=>{em||B(!1)},tD=async()=>{if(0===tE.length)return;let e="__none__"===ec?null:ec;ex(!0);try{let t=[];for(let s of tE)try{let a=await fetch(`/api/providers/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyPoolId:e})});t.push(a.ok)}catch(e){console.log("Error applying bulk proxy pool for",s,e),t.push(!1)}let s=t.filter(e=>!e).length;s>0&&alert(`Updated with ${s} failed request(s).`),await tf(),ed([]),ep("__none__"),B(!1)}catch(e){console.log("Error applying bulk proxy pool:",e)}finally{ex(!1)}},tz=(0,a.jsx)("div",{className:"flex min-w-0 flex-col divide-y divide-black/3 dark:divide-white/3",children:u.map((e,t)=>(0,a.jsx)("div",{className:"flex min-w-0 items-stretch",children:(0,a.jsx)("div",{className:"flex-1 min-w-0",children:(0,a.jsx)(w,{connection:e,proxyPools:A,isOAuth:e3,isFirst:0===t,isLast:t===u.length-1,onMoveUp:()=>tP(t,t-1),onMoveDown:()=>tP(t,t+1),onToggleActive:t=>tO(e.id,t),onUpdateProxy:async t=>{try{(await fetch(`/api/providers/${e.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyPoolId:t||null})})).ok&&f(s=>s.map(s=>s.id===e.id?{...s,providerSpecificData:{...s.providerSpecificData,proxyPoolId:t||null}}:s))}catch(e){console.log("Error updating proxy:",e)}},onEdit:()=>{G(e),J(!0)},onDelete:()=>tC(e.id),oneByOneStatus:eK[e.id]||null})})},e.id))}),tq=[{value:"__none__",label:"None"},...A.map(e=>({value:e.id,label:e.name}))],tM=0===tE.length?"Select one or more connections, then click Proxy Action.":t_,tF=tE.length>0&&!em,tK=(0,a.jsx)(d.aF,{isOpen:H,onClose:tU,title:`Proxy Action (${tE.length} selected)`,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsx)(d.l6,{label:"Proxy Pool",value:ec,onChange:e=>ep(e.target.value),options:tq,placeholder:"None"}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:tM}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Selecting None will unbind selected connections from proxy pool."}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,a.jsx)(d.$n,{onClick:tD,fullWidth:!0,disabled:!tF,children:em?"Applying...":"Apply"}),(0,a.jsx)(d.$n,{onClick:tU,variant:"ghost",fullWidth:!0,disabled:em,children:"Cancel"})]})]})}),tJ=async e=>{if(!ei){el(e);try{let t=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${tr}/${e}`})}),s=await t.json();et(t=>({...t,[e]:s.ok?"ok":"error"})),ea(s.ok?"":s.error||"Model not reachable")}catch{et(t=>({...t,[e]:"error"})),ea("Network error")}finally{el(null)}}};return g?(0,a.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,a.jsx)(d.Qv,{}),(0,a.jsx)(d.Qv,{})]}):e2?(0,a.jsxs)("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:gap-8 sm:px-0",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)(n(),{href:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),"Back to Providers"]}),(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3 sm:gap-4",children:[(0,a.jsx)("div",{className:"flex size-12 shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${e2.color}15`},children:X?(0,a.jsx)("span",{className:"text-sm font-bold",style:{color:e2.color},children:e2.textIcon||e2.id.slice(0,2).toUpperCase()}):(0,a.jsx)(o.default,{src:e9&&e2.apiType?"responses"===e2.apiType?"/providers/oai-r.png":"/providers/oai-cc.png":te?"/providers/anthropic-m.png":`/providers/${e2.id}.png`,alt:e2.name,width:48,height:48,className:"max-h-12 max-w-12 rounded-lg object-contain",sizes:"48px",onError:()=>Y(!0)})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3 flex-wrap",children:[(0,a.jsx)("h1",{className:"truncate text-2xl font-semibold tracking-tight sm:text-3xl",children:e2.name}),(e2.notice?.apiKeyUrl||e2.notice?.signupUrl||e2.website)&&(0,a.jsxs)("a",{href:e2.notice?.apiKeyUrl||e2.notice?.signupUrl||e2.website,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline inline-flex items-center gap-1",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"open_in_new"}),e2.notice?.apiKeyUrl?"Get API Key":"Sign up / Learn more"]})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:[u.length," connection",1===u.length?"":"s"]})]})]})]}),e2.deprecated&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px] text-yellow-500 mt-0.5 shrink-0",children:"warning"}),(0,a.jsx)("p",{className:"text-xs text-red-600 dark:text-yellow-400 leading-relaxed",children:e2.deprecationNotice})]}),e2.notice?.text&&!e2.deprecated&&(0,a.jsxs)("div",{className:"flex flex-col gap-2 rounded-lg border border-blue-500/30 bg-blue-500/10 px-3 py-2 sm:flex-row sm:items-center",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px] text-blue-500 shrink-0",children:"info"}),(0,a.jsx)("p",{className:"min-w-0 flex-1 text-xs leading-relaxed text-blue-600 dark:text-blue-400",children:e2.notice.text}),e2.notice.apiKeyUrl&&(0,a.jsx)("a",{href:e2.notice.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex justify-center rounded bg-blue-500 px-2 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-600 sm:py-0.5",children:"Get API Key →"})]}),tt&&j&&(0,a.jsx)(d.Zp,{children:(0,a.jsxs)("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:te?"Anthropic Compatible Details":"OpenAI Compatible Details"}),(0,a.jsxs)("p",{className:"break-all text-sm text-text-muted",children:[te?"Messages API":"responses"===j.apiType?"Responses API":"Chat Completions"," \xb7 ",(j.baseUrl||"").replace(/\/$/,""),"/",te?"messages":"responses"===j.apiType?"responses":"chat/completions"]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsx)(d.$n,{size:"sm",icon:"add",onClick:()=>F(!0),disabled:u.length>0,className:"w-full sm:w-auto",children:"Add"}),(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>W(!0),className:"w-full sm:w-auto",children:"Edit"}),(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"delete",onClick:async()=>{eE({title:"Delete Compatible Node",message:`Delete this ${te?"Anthropic":"OpenAI"} Compatible node?`,onConfirm:async()=>{eE(null);try{(await fetch(`/api/provider-nodes/${r}`,{method:"DELETE"})).ok&&s.push("/dashboard/providers")}catch(e){console.log("Error deleting provider node:",e)}}})},className:"w-full sm:w-auto",children:"Delete"})]})]})}),e6?(0,a.jsx)(d.gw,{providerId:r}):(0,a.jsxs)(d.Zp,{children:[(0,a.jsxs)("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:"Connections"}),(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",children:[u.length>0&&A.length>0&&(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"lan",onClick:()=>B(!0),children:"Apply Proxy"}),u.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"sync",onClick:tk,disabled:eU,children:eU?"Testing Connection One-by-One...":"Test Connection One-by-One"}),eU&&(0,a.jsx)(d.$n,{size:"sm",variant:"ghost",icon:"stop",onClick:()=>{eU&&(eH.current=!0,eq(!0))},disabled:ez,children:ez?"Stopping...":"Stop"})]}),"codex"===r&&(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,a.jsxs)("label",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-text-muted whitespace-nowrap",children:"Global Fast"}),(0,a.jsx)(d.lM,{checked:ev,onChange:e=>{ej(e),tb(ey,e)}})]}),(0,a.jsxs)("label",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-text-muted whitespace-nowrap",children:"My Fast"}),(0,a.jsx)(d.lM,{checked:ew,onChange:e=>{eN(e),tv(e)}})]})]}),tl&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("label",{htmlFor:"provider-default-reasoning",className:"text-xs font-medium text-text-muted whitespace-nowrap",children:"Default Reasoning"}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("select",{id:"provider-default-reasoning",value:ey,onChange:e=>{var t;eb(t=e.target.value),tb(t)},disabled:g,className:"h-6 w-28 appearance-none rounded-full border border-border/60 bg-surface-2 pl-3 pr-7 text-xs font-medium text-text-main transition-colors focus:border-primary/50 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-50",children:td.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))}),(0,a.jsx)("span",{className:"material-symbols-outlined pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[16px] text-text-muted",children:"expand_more"})]})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"text-xs text-text-muted font-medium",children:"Round Robin"}),(0,a.jsx)(d.lM,{checked:"round-robin"===eu,onChange:e=>{let t=e?"round-robin":null,s=e?ef||"1":ef;e&&!ef&&eg("1"),eh(t),ty(t,s)}}),"round-robin"===eu&&(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"Sticky:"}),(0,a.jsx)("input",{type:"number",min:1,value:ef,onChange:e=>{var t;eg(t=e.target.value),ty("round-robin",t)},placeholder:"1",className:"w-14 px-2 py-1 text-xs border border-border rounded-md bg-background focus:outline-none focus:border-primary"})]})]})]})]}),0===u.length?(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"inline-flex items-center justify-center w-9 h-9 rounded-full bg-primary/10 text-primary shrink-0",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:e3?"lock":"key"})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"No connections yet"}),ts&&(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:["Choose ",ta," or ",ti,"."]})]})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[ts?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",icon:"lock",variant:"secondary",onClick:eY,children:ta}),(0,a.jsx)(d.$n,{size:"sm",icon:"key",onClick:e0,children:ti})]}):(0,a.jsxs)(a.Fragment,{children:[!tt&&"iflow"===r&&(0,a.jsx)(d.$n,{size:"sm",icon:"cookie",variant:"secondary",onClick:()=>E(!0),children:"Cookie"}),(0,a.jsx)(d.$n,{size:"sm",icon:"add",onClick:e1,children:tt?"Add API Key":"iflow"===r?"OAuth":"Add Connection"})]}),"codex"===r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",icon:"upload_file",variant:"secondary",onClick:()=>_(!0),children:"Batch Import"}),(0,a.jsx)(d.$n,{size:"sm",icon:"sync",variant:"secondary",onClick:t$,loading:U,children:"Refresh Tokens"})]})]})]}):(0,a.jsxs)(a.Fragment,{children:[eL&&(0,a.jsx)("div",{className:"mb-4 rounded-lg border border-black/10 bg-black/[0.02] px-3 py-2 text-xs text-text-muted dark:border-white/10 dark:bg-white/[0.03]",children:(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,a.jsxs)("span",{children:["Total: ",eL.total]}),(0,a.jsxs)("span",{children:["Completed: ",eL.completed]}),(0,a.jsxs)("span",{children:["Passed: ",eL.passed]}),(0,a.jsxs)("span",{children:["Failed: ",eL.failed]}),eL.stopped&&(0,a.jsx)("span",{className:"text-amber-600 dark:text-amber-400",children:"Stopped"}),eU&&eM&&(0,a.jsxs)("span",{children:["Running: ",u.find(e=>e.id===eM)?.name||eM]})]})}),tz,!tt&&(0,a.jsxs)("div",{className:"mt-4 grid grid-cols-1 gap-2 sm:flex",children:["iflow"===r&&(0,a.jsx)(d.$n,{size:"sm",icon:"cookie",variant:"secondary",onClick:()=>E(!0),title:"Add connection using browser cookie",className:"w-full sm:w-auto",children:"Cookie"}),ts?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",icon:"lock",variant:"secondary",onClick:eY,className:"w-full sm:w-auto",children:ta}),(0,a.jsx)(d.$n,{size:"sm",icon:"key",onClick:e0,className:"w-full sm:w-auto",children:ti})]}):(0,a.jsx)(d.$n,{size:"sm",icon:"add",onClick:e1,className:"w-full sm:w-auto",children:"Add"}),"codex"===r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.$n,{size:"sm",icon:"upload_file",variant:"secondary",onClick:()=>_(!0),className:"w-full sm:w-auto",children:"Batch Import"}),(0,a.jsx)(d.$n,{size:"sm",icon:"sync",variant:"secondary",onClick:t$,loading:U,className:"w-full sm:w-auto",children:"Refresh Tokens"})]})]})]}),"codex"===r&&z&&(0,a.jsx)("div",{className:`mt-4 rounded-lg border px-3 py-2 text-sm ${z.error?"border-red-500/30 bg-red-500/10 text-red-600":"border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300"}`,children:z.error?z.error:`Token refresh complete: ${z.refreshed?.length||0} refreshed, ${z.failed?.length||0} failed, ${z.skipped?.length||0} skipped.`})]}),(0,a.jsxs)(d.Zp,{children:[(0,a.jsxs)("div",{className:"mb-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:"Available Models"}),!tt&&(e=[...e7,...eA.filter(e=>!e7.some(t=>t.id===e.id))].filter(e=>!e.type||"llm"===e.type).map(e=>e.id).filter(e=>!eO.includes(e)),(0,a.jsxs)("div",{className:"flex gap-2",children:[eO.length>0&&(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"restart_alt",onClick:tu,children:"Active All"}),e.length>0&&(0,a.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"block",onClick:()=>tx(e),children:"Disable All"})]}))]}),!!es&&(0,a.jsx)("p",{className:"text-xs text-red-500 mb-3 wrap-break-word",children:es}),(()=>{let e,t,s;if(tt)return(0,a.jsx)(v,{providerStorageAlias:tr,providerDisplayAlias:tn,modelAliases:Q,copied:eG,onCopy:eQ,onSetAlias:tj,onDeleteAlias:tw,connections:u,isAnthropic:te});let i=[...e7,...eA.filter(e=>!e7.some(t=>t.id===e.id))].filter(e=>!e.type||"llm"===e.type),l=new Set(eO),n=i.filter(e=>!l.has(e.id)),o=i.filter(e=>l.has(e.id)),d=Object.entries(Q).filter(([e,t])=>{let s=`${tr}/`;if(!t.startsWith(s))return!1;let a=t.slice(s.length);return e2.passthroughModels?!e7.some(e=>e.id===a):!e7.some(e=>e.id===a)&&e===a}).map(([e,t])=>({id:t.slice(`${tr}/`.length),alias:e,fullModel:t}));return(0,a.jsxs)("div",{className:"flex flex-wrap gap-3",children:[d.map(e=>(0,a.jsx)(y,{model:{id:e.id},fullModel:`${tn}/${e.id}`,displayModel:to?e.id:`${tn}/${e.id}`,alias:e.alias,copied:eG,onCopy:eQ,onSetAlias:()=>{},onDeleteAlias:()=>tw(e.alias),testStatus:ee[e.id],onTest:u.length>0||e6?()=>tJ(e.id):void 0,isTesting:ei===e.id,isCustom:!0,isFree:!1},e.id)),n.map(e=>{let t=`${tr}/${e.id}`,s=`${r}/${e.id}`,i=Object.entries(Q).find(([,e])=>e===t||e===s)?.[0];return(0,a.jsx)(y,{model:e,fullModel:`${tn}/${e.id}`,displayModel:to?e.id:`${tn}/${e.id}`,alias:i,copied:eG,onCopy:eQ,onSetAlias:t=>tj(e.id,t,tr),onDeleteAlias:()=>tw(i),testStatus:ee[e.id],onTest:u.length>0||e6?()=>tJ(e.id):void 0,isTesting:ei===e.id,isFree:e.isFree,onDisable:()=>tp(e.id)},e.id)}),(0,a.jsxs)("button",{onClick:()=>en(!0),className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-primary/40 px-3 py-2 text-xs text-primary transition-colors hover:border-primary hover:bg-primary/5 sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"add"}),"Add Model"]}),"qoder"===r&&u.some(e=>!1!==e.isActive)&&(0,a.jsxs)("button",{onClick:tN,disabled:eB,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-blue-500/40 px-3 py-2 text-xs text-blue-600 dark:text-blue-400 transition-colors hover:border-blue-500 hover:bg-blue-500/5 sm:w-auto disabled:opacity-50 disabled:cursor-not-allowed",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",style:eB?{animation:"spin 1s linear infinite"}:void 0,children:eB?"progress_activity":"download"}),eB?(0,x.Tl)("Fetching..."):(0,x.Tl)("Fetch Qoder Models")]}),eS.length>0&&(e=new Set(Object.values(Q)),t=new Set(e7.map(e=>e.id)),0===(s=eS.filter(s=>!e.has(`${tr}/${s.id}`)&&!t.has(s.id))).length?null:(0,a.jsxs)("div",{className:"w-full mt-2",children:[(0,a.jsx)("p",{className:"text-xs text-text-muted mb-2",children:"Suggested free models (≥200k context):"}),(0,a.jsx)("div",{className:"flex flex-wrap gap-2",children:s.map(e=>(0,a.jsxs)("button",{onClick:async()=>{let t=e.id.split("/").pop();await tj(e.id,t,tr)},className:"flex items-center gap-1 px-2.5 py-1.5 rounded-lg border border-black/10 dark:border-white/10 text-xs text-text-muted hover:text-primary hover:border-primary/40 hover:bg-primary/5 transition-colors",title:`${e.name} \xb7 ${(e.contextLength/1e3).toFixed(0)}k ctx`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),e.id.split("/").pop()]},e.id))})]})),o.length>0&&(0,a.jsxs)("div",{className:"w-full mt-2",children:[(0,a.jsxs)("p",{className:"text-xs text-text-muted mb-2",children:["Disabled models (",o.length,"):"]}),(0,a.jsx)("div",{className:"flex flex-wrap gap-2",children:o.map(e=>(0,a.jsxs)("button",{onClick:()=>tm(e.id),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-lg border border-dashed border-black/10 dark:border-white/10 text-xs text-text-muted hover:text-primary hover:border-primary/40 hover:bg-primary/5 transition-colors",title:"Restore model",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),e.id]},e.id))})]})]})})()]}),tK,"kiro"===r?(0,a.jsx)(d.Mh,{isOpen:O,providerInfo:e2,onSuccess:tS,onClose:()=>P(!1)}):"cursor"===r?(0,a.jsx)(d.G9,{isOpen:O,onSuccess:tS,onClose:()=>P(!1)}):"gitlab"===r?(0,a.jsx)(d.vj,{isOpen:O,providerInfo:e2,onSuccess:tS,onClose:()=>P(!1)}):(0,a.jsx)(d.LF,{isOpen:O,provider:r,providerInfo:e2,onSuccess:tS,onClose:()=>P(!1)}),"iflow"===r&&(0,a.jsx)(d.vE,{isOpen:I,onSuccess:()=>{tf(),E(!1)},onClose:()=>E(!1)}),"codex"===r&&(0,a.jsx)($,{isOpen:R,onSuccess:tf,onClose:()=>_(!1)}),(0,a.jsx)(k,{isOpen:M,provider:r,providerName:e2.name,isCompatible:tt,isAnthropic:te,authType:e2?.authType,authHint:e2?.authHint,website:e2?.website,proxyPools:A,onSave:tA,onClose:()=>F(!1)}),(0,a.jsx)(d.wI,{isOpen:K,connection:V,proxyPools:A,onSave:tT,onClose:()=>J(!1)}),tt&&(0,a.jsx)(C,{isOpen:L,node:j,onSave:tg,onClose:()=>W(!1),isAnthropic:te}),!tt&&(0,a.jsx)(S,{isOpen:er,providerAlias:tr,providerDisplayAlias:tn,onSave:async e=>{let t=e2?.passthroughModels?e.split("/").pop():e;await tj(e,t,tr),en(!1)},onClose:()=>en(!1)}),(0,a.jsx)(d.uo,{isOpen:eR,onClose:()=>e_(!1),onConfirm:()=>{(window.localStorage.setItem(eZ,"true"),e_(!1),e3)?eX():e0()},title:"Risk Notice",message:e2?.deprecationNotice,confirmText:"I Understand, Continue",cancelText:"Cancel",variant:"danger"}),(0,a.jsx)(d.uo,{isOpen:!!eI,onClose:()=>eE(null),onConfirm:eI?.onConfirm,title:eI?.title||"Confirm",message:eI?.message,variant:"danger"})]}):(0,a.jsxs)("div",{className:"text-center py-20",children:[(0,a.jsx)("p",{className:"text-text-muted",children:"Provider not found"}),(0,a.jsx)(n(),{href:"/dashboard/providers",className:"text-primary mt-4 inline-block",children:"Back to Providers"})]})}k.propTypes={isOpen:g().bool.isRequired,provider:g().string,providerName:g().string,isCompatible:g().bool,isAnthropic:g().bool,authType:g().string,authHint:g().string,website:g().string,proxyPools:g().arrayOf(g().shape({id:g().string,name:g().string})),onSave:g().func.isRequired,onBulkDone:g().func,onClose:g().func.isRequired},C.propTypes={isOpen:g().bool.isRequired,node:g().shape({id:g().string,name:g().string,prefix:g().string,apiType:g().string,baseUrl:g().string}),onSave:g().func.isRequired,onClose:g().func.isRequired,isAnthropic:g().bool},S.propTypes={isOpen:g().bool.isRequired,providerAlias:g().string.isRequired,providerDisplayAlias:g().string.isRequired,onSave:g().func.isRequired,onClose:g().func.isRequired},$.propTypes={isOpen:g().bool.isRequired,onClose:g().func.isRequired,onSuccess:g().func}},29610:(e,t,s)=>{Promise.resolve().then(s.bind(s,7570))}},e=>{e.O(0,[2574,3862,1051,5772,1321,5497,8441,3794,7358],()=>e(e.s=29610)),_N_E=e.O()}]);
package/app/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "9router-app",
3
- "version": "0.4.71",
3
+ "version": "0.4.72",
4
4
  "description": "9Router web dashboard",
5
5
  "private": true,
6
6
  "scripts": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yina-npm/openrouterx",
3
- "version": "0.4.71",
3
+ "version": "0.4.72",
4
4
  "description": "openrouterX CLI - Start and manage 9Router server",
5
5
  "bin": {
6
6
  "openrouterX": "./cli.js"