@yina-npm/openrouterx 0.4.18 → 0.4.19

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 (121) hide show
  1. package/app/.next/BUILD_ID +1 -1
  2. package/app/.next/app-path-routes-manifest.json +1 -1
  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/page_client-reference-manifest.js +1 -1
  8. package/app/.next/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
  9. package/app/.next/server/app/(dashboard)/dashboard/console-log/page_client-reference-manifest.js +1 -1
  10. package/app/.next/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
  11. package/app/.next/server/app/(dashboard)/dashboard/media-providers/[kind]/[id]/page.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/cli-tools/antigravity-mitm/route.js +1 -1
  48. package/app/.next/server/app/api/models/route.js +1 -1
  49. package/app/.next/server/app/api/providers/route.js +1 -1
  50. package/app/.next/server/app/api/providers/validate/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/update/route.js +1 -1
  55. package/app/.next/server/app/callback/page_client-reference-manifest.js +1 -1
  56. package/app/.next/server/app/callback.html +1 -1
  57. package/app/.next/server/app/callback.rsc +3 -3
  58. package/app/.next/server/app/callback.segments/_full.segment.rsc +3 -3
  59. package/app/.next/server/app/callback.segments/_head.segment.rsc +1 -1
  60. package/app/.next/server/app/callback.segments/_index.segment.rsc +3 -3
  61. package/app/.next/server/app/callback.segments/_tree.segment.rsc +1 -1
  62. package/app/.next/server/app/callback.segments/callback/__PAGE__.segment.rsc +1 -1
  63. package/app/.next/server/app/callback.segments/callback.segment.rsc +1 -1
  64. package/app/.next/server/app/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
  65. package/app/.next/server/app/dashboard/settings/pricing.html +1 -1
  66. package/app/.next/server/app/dashboard/settings/pricing.rsc +3 -3
  67. package/app/.next/server/app/dashboard/settings/pricing.segments/_full.segment.rsc +3 -3
  68. package/app/.next/server/app/dashboard/settings/pricing.segments/_head.segment.rsc +1 -1
  69. package/app/.next/server/app/dashboard/settings/pricing.segments/_index.segment.rsc +3 -3
  70. package/app/.next/server/app/dashboard/settings/pricing.segments/_tree.segment.rsc +1 -1
  71. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing/__PAGE__.segment.rsc +1 -1
  72. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing.segment.rsc +1 -1
  73. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings.segment.rsc +1 -1
  74. package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard.segment.rsc +1 -1
  75. package/app/.next/server/app/index.html +1 -1
  76. package/app/.next/server/app/index.rsc +3 -3
  77. package/app/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  78. package/app/.next/server/app/index.segments/_full.segment.rsc +3 -3
  79. package/app/.next/server/app/index.segments/_head.segment.rsc +1 -1
  80. package/app/.next/server/app/index.segments/_index.segment.rsc +3 -3
  81. package/app/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  82. package/app/.next/server/app/landing/page_client-reference-manifest.js +1 -1
  83. package/app/.next/server/app/landing.html +1 -1
  84. package/app/.next/server/app/landing.rsc +3 -3
  85. package/app/.next/server/app/landing.segments/_full.segment.rsc +3 -3
  86. package/app/.next/server/app/landing.segments/_head.segment.rsc +1 -1
  87. package/app/.next/server/app/landing.segments/_index.segment.rsc +3 -3
  88. package/app/.next/server/app/landing.segments/_tree.segment.rsc +1 -1
  89. package/app/.next/server/app/landing.segments/landing/__PAGE__.segment.rsc +1 -1
  90. package/app/.next/server/app/landing.segments/landing.segment.rsc +1 -1
  91. package/app/.next/server/app/login/page_client-reference-manifest.js +1 -1
  92. package/app/.next/server/app/login.html +1 -1
  93. package/app/.next/server/app/login.rsc +4 -4
  94. package/app/.next/server/app/login.segments/_full.segment.rsc +4 -4
  95. package/app/.next/server/app/login.segments/_head.segment.rsc +1 -1
  96. package/app/.next/server/app/login.segments/_index.segment.rsc +3 -3
  97. package/app/.next/server/app/login.segments/_tree.segment.rsc +1 -1
  98. package/app/.next/server/app/login.segments/login/__PAGE__.segment.rsc +2 -2
  99. package/app/.next/server/app/login.segments/login.segment.rsc +1 -1
  100. package/app/.next/server/app/page_client-reference-manifest.js +1 -1
  101. package/app/.next/server/app-paths-manifest.json +1 -1
  102. package/app/.next/server/chunks/2238.js +1 -1
  103. package/app/.next/server/chunks/412.js +1 -1
  104. package/app/.next/server/chunks/4122.js +1 -1
  105. package/app/.next/server/chunks/5627.js +1 -1
  106. package/app/.next/server/chunks/7595.js +1 -1
  107. package/app/.next/server/chunks/7937.js +1 -1
  108. package/app/.next/server/middleware-build-manifest.js +1 -1
  109. package/app/.next/server/pages/404.html +1 -1
  110. package/app/.next/server/pages/500.html +1 -1
  111. package/app/.next/static/chunks/{1321-e38d25b213a61af7.js → 1321-7e9aeddc67afb663.js} +1 -1
  112. package/app/.next/static/chunks/{4295-a6fa5532d32ad57b.js → 4295-fbaece639df900b6.js} +1 -1
  113. package/app/.next/static/chunks/{5497-ca14fd2ec8ec4965.js → 5497-54ae9c6ec04c2fb1.js} +1 -1
  114. package/app/.next/static/chunks/app/(dashboard)/dashboard/media-providers/[kind]/[id]/{page-fe66b224c0368b52.js → page-e8660483a85aed9d.js} +1 -1
  115. package/app/.next/static/chunks/app/(dashboard)/dashboard/providers/[id]/page-08a8f17b396ac1f4.js +1 -0
  116. package/app/package.json +1 -1
  117. package/app/src/shared/constants/mitmToolHosts.js +1 -0
  118. package/package.json +1 -1
  119. package/app/.next/static/chunks/app/(dashboard)/dashboard/providers/[id]/page-ffb5f2c63ae94906.js +0 -1
  120. /package/app/.next/static/{qn5ddCosq_qTH6CJRFJIB → NtU3O4mCJYjlmlBWGF7gX}/_buildManifest.js +0 -0
  121. /package/app/.next/static/{qn5ddCosq_qTH6CJRFJIB → NtU3O4mCJYjlmlBWGF7gX}/_ssgManifest.js +0 -0
@@ -1,4 +1,4 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[182],{42661:(e,t,s)=>{Promise.resolve().then(s.bind(s,94588))},94588:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>I});var a=s(95155),r=s(73321),l=s(98500),o=s.n(l),n=s(12115),i=s(35497),d=s(57250),c=s(52679),m=s(28777),p=s(11059),u=s(14051),x=s.n(u);function h({until:e}){let[t,s]=(0,n.useState)("");return((0,n.useEffect)(()=>{let t=()=>{let t=new Date(e).getTime()-Date.now();if(t<=0)return void s("");let a=Math.floor(t/1e3);a<60?s(`${a}s`):a<3600?s(`${Math.floor(a/60)}m ${a%60}s`):s(`${Math.floor(a/3600)}h ${Math.floor(a%3600/60)}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 b({connection:e,proxyPools:t,isOAuth:s,isFirst:r,isLast:l,onMoveUp:o,onMoveDown:d,onToggleActive:c,onUpdateProxy:m,onEdit:p,onDelete:u}){let[x,f]=(0,n.useState)(!1),[g,y]=(0,n.useState)(!1),[j,v]=(0,n.useState)(!1),w=(0,n.useRef)(null),N=new Map((t||[]).map(e=>[e.id,e])),k=e.providerSpecificData?.proxyPoolId||null,S=k?N.get(k):null,C=e.providerSpecificData?.connectionProxyEnabled===!0&&!!e.providerSpecificData?.connectionProxyUrl,$=!!k||C,A=S?`Pool: ${S.name}`:k?`Pool: ${k} (inactive/missing)`:C?`Legacy: ${e.providerSpecificData?.connectionProxyUrl}`:"",P="",_=S?.proxyUrl||e.providerSpecificData?.connectionProxyUrl;if(_)try{let e=new URL(_);P=`${e.protocol}//${e.hostname}${e.port?`:${e.port}`:""}`}catch{P=_}let T=S?.noProxy||e.providerSpecificData?.connectionNoProxy||"",R=S?.isActive===!0?"success":k||C?"error":"default",E=Object.entries(e).filter(([e])=>e.startsWith("modelLock_")).map(([,e])=>e).filter(Boolean).sort()[0]||null;(0,n.useEffect)(()=>{let t=()=>{v(!!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=E?setInterval(t,1e3):null;return()=>{s&&clearInterval(s)}},[E]),(0,n.useEffect)(()=>{if(!x)return;let e=e=>{w.current&&!w.current.contains(e.target)&&f(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[x]);let I="unavailable"!==e.testStatus||j?e.testStatus:"active",O=s?e.name||e.email||e.displayName||"OAuth Account":e.name,M=async e=>{y(!0);try{await m("__none__"===e?null:e)}finally{y(!1),f(!1)}};return(0,a.jsxs)("div",{className:`group flex flex-col gap-3 p-2 rounded-lg sm:flex-row sm:items-center sm:justify-between hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors ${!1===e.isActive?"opacity-60":""}`,children:[(0,a.jsxs)("div",{className:"flex w-full min-w-0 flex-1 items-start gap-3 sm:items-center",children:[(0,a.jsxs)("div",{className:"flex flex-col",children:[(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_up"})}),(0,a.jsx)("button",{onClick:d,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_down"})})]}),(0,a.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:s?"lock":"key"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-medium truncate",children:O}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mt-1",children:[(0,a.jsx)(i.Ex,{variant:!1===e.isActive?"default":"active"===I||"success"===I?"success":"error"===I||"expired"===I||"unavailable"===I?"error":"default",size:"sm",dot:!0,children:!1===e.isActive?"disabled":I||"Unknown"}),$&&(0,a.jsx)(i.Ex,{variant:R,size:"sm",children:"Proxy"}),j&&!1!==e.isActive&&(0,a.jsx)(h,{until:E}),e.lastError&&!1!==e.isActive&&(0,a.jsx)("span",{className:"text-xs text-red-500 truncate max-w-[300px]",title:e.lastError,children:e.lastError}),(0,a.jsxs)("span",{className:"text-xs text-text-muted",children:["#",e.priority]})]}),$&&(0,a.jsxs)("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"text-[11px] text-text-muted truncate max-w-[420px]",title:A,children:A}),P&&(0,a.jsx)("code",{className:"text-[10px] font-mono bg-black/5 dark:bg-white/5 px-1 py-0.5 rounded text-text-muted",children:P}),T&&(0,a.jsxs)("span",{className:"text-[11px] text-text-muted truncate max-w-[320px]",title:T,children:["no_proxy: ",T]})]})]})]}),(0,a.jsxs)("div",{className:"flex w-full flex-wrap items-center justify-between gap-2 sm:w-auto sm:justify-end",children:[(0,a.jsxs)("div",{className:"flex flex-wrap gap-1",children:[(t||[]).length>0&&(0,a.jsxs)("div",{className:"relative",ref:w,children:[(0,a.jsxs)("button",{onClick:()=>f(e=>!e),className:`flex flex-col items-center px-2 py-1 rounded hover:bg-black/5 dark:hover:bg-white/5 transition-colors ${$?"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"})]}),x&&(0,a.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-50 bg-bg border border-border rounded-lg shadow-lg py-1 min-w-[160px]",children:[(0,a.jsx)("button",{onClick:()=>M("__none__"),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${!k?"text-primary font-medium":"text-text-main"}`,children:"None"}),(t||[]).map(e=>(0,a.jsx)("button",{onClick:()=>M(e.id),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${k===e.id?"text-primary font-medium":"text-text-main"}`,children:e.name},e.id))]})]}),(0,a.jsxs)("button",{onClick:p,className:"flex flex-col items-center px-2 py-1 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-primary",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:u,className:"flex flex-col items-center px-2 py-1 rounded hover:bg-red-500/10 text-red-500",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)(i.lM,{size:"sm",checked:e.isActive??!0,onChange:c,title:e.isActive??!0?"Disable":"Enable"})]})]})}function f({isOpen:e,provider:t,providerName:s,proxyPools:r,onSave:l,onClose:o}){let d="__none__",[c,m]=(0,n.useState)({name:"",apiKey:"",priority:1,proxyPoolId:d}),[p,u]=(0,n.useState)(!1),[x,h]=(0,n.useState)(null),[b,g]=(0,n.useState)(!1),y=async()=>{u(!0);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:c.apiKey})}),s=await e.json();h(s.valid?"success":"failed")}catch{h("failed")}finally{u(!1)}},j=async()=>{if(t&&c.apiKey){g(!0);try{let e=!1;try{u(!0),h(null);let s=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:c.apiKey})});e=!!(await s.json()).valid,h(e?"success":"failed")}catch{h("failed")}finally{u(!1)}await l({name:c.name,apiKey:c.apiKey,priority:c.priority,proxyPoolId:c.proxyPoolId===d?null:c.proxyPoolId,testStatus:e?"active":"unknown"})}finally{g(!1)}}};return t?(0,a.jsx)(i.aF,{isOpen:e,title:`Add ${s||t} API Key`,onClose:o,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Name"}),(0,a.jsx)("input",{className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",value:c.name,onChange:e=>m({...c,name:e.target.value}),placeholder:"Production Key"})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"API Key"}),(0,a.jsx)("input",{type:"password",className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",value:c.apiKey,onChange:e=>m({...c,apiKey:e.target.value})})]}),(0,a.jsx)("div",{className:"pt-6",children:(0,a.jsx)(i.$n,{onClick:y,disabled:!c.apiKey||p||b,variant:"secondary",children:p?"Checking...":"Check"})})]}),x&&(0,a.jsx)(i.Ex,{variant:"success"===x?"success":"error",children:"success"===x?"Valid":"Invalid"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Priority"}),(0,a.jsx)("input",{type:"number",className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",value:c.priority,onChange:e=>m({...c,priority:Number.parseInt(e.target.value)||1})})]}),(0,a.jsx)(i.l6,{label:"Proxy Pool",value:c.proxyPoolId,onChange:e=>m({...c,proxyPoolId:e.target.value}),options:[{value:d,label:"None"},...(r||[]).map(e=>({value:e.id,label:e.name}))]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(i.$n,{onClick:j,fullWidth:!0,disabled:!c.name||!c.apiKey||b,children:b?"Saving...":"Save"}),(0,a.jsx)(i.$n,{onClick:o,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}function g({providerId:e,isOAuth:t}){let[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)([]),[d,c]=(0,n.useState)(!0),[m,p]=(0,n.useState)(!1),[u,x]=(0,n.useState)(!1),[h,y]=(0,n.useState)(null),[j,v]=(0,n.useState)(null),[w,N]=(0,n.useState)("1"),k=(0,n.useCallback)(async()=>{try{let[t,s,a]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/proxy-pools?isActive=true",{cache:"no-store"}),fetch("/api/settings",{cache:"no-store"})]),l=await t.json(),n=await s.json(),i=a.ok?await a.json():{};t.ok&&r((l.connections||[]).filter(t=>t.provider===e)),s.ok&&o(n.proxyPools||[]);let d=(i.providerStrategies||{})[e]||{};v(d.fallbackStrategy||null),N(null!=d.stickyRoundRobinLimit?String(d.stickyRoundRobinLimit):"1")}catch(e){console.log("ConnectionsCard fetch error:",e)}finally{c(!1)}},[e]);(0,n.useEffect)(()=>{k()},[k]);let S=async(t,s)=>{try{let a=await fetch("/api/settings",{cache:"no-store"}),r=(a.ok?await a.json():{}).providerStrategies||{},l={};t&&(l.fallbackStrategy=t),"round-robin"===t&&""!==s&&(l.stickyRoundRobinLimit=Number(s)||3);let o={...r};0===Object.keys(l).length?delete o[e]:o[e]=l,await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerStrategies:o})})}catch(e){console.log("saveStrategy error:",e)}},C=async(e,t)=>{let a=[...s];[a[e],a[t]]=[a[t],a[e]],r(a);try{await Promise.all([fetch(`/api/providers/${a[e].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:e})}),fetch(`/api/providers/${a[t].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:t})})])}catch{await k()}},$=async e=>{if(confirm("Delete this connection?"))try{(await fetch(`/api/providers/${e}`,{method:"DELETE"})).ok&&r(t=>t.filter(t=>t.id!==e))}catch(e){console.log("delete error:",e)}},A=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&r(s=>s.map(s=>s.id===e?{...s,isActive:t}:s))}catch(e){console.log("toggle error:",e)}},P=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyPoolId:t||null})})).ok&&r(s=>s.map(s=>s.id===e?{...s,providerSpecificData:{...s.providerSpecificData,proxyPoolId:t||null}}:s))}catch(e){console.log("proxy error:",e)}},_=async t=>{try{(await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,...t})})).ok&&(await k(),p(!1))}catch(e){console.log("save apikey error:",e)}},T=async e=>{try{(await fetch(`/api/providers/${h.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(await k(),x(!1))}catch(e){console.log("update connection error:",e)}};return d?(0,a.jsx)(i.Zp,{children:(0,a.jsx)("div",{className:"h-20 animate-pulse bg-black/5 rounded-lg"})}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(i.Zp,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between mb-4",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:"Connections"}),(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)(i.lM,{checked:"round-robin"===j,onChange:e=>{let t=e?"round-robin":null;v(t),e&&!w&&N("1"),S(t,e?w||"1":w)}}),"round-robin"===j&&(0,a.jsxs)("div",{className:"flex flex-wrap 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:w,onChange:e=>{N(e.target.value),S("round-robin",e.target.value)},className:"w-16 px-2 py-1 text-xs border border-border rounded-md bg-background focus:outline-none focus:border-primary"})]})]})]}),0===s.length?(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"No connections yet"}),(0,a.jsx)(i.$n,{size:"sm",icon:"add",onClick:()=>p(!0),children:"Add Connection"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"flex flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:s.map((e,r)=>(0,a.jsx)(b,{connection:e,proxyPools:l,isOAuth:t,isFirst:0===r,isLast:r===s.length-1,onMoveUp:()=>C(r,r-1),onMoveDown:()=>C(r,r+1),onToggleActive:t=>A(e.id,t),onUpdateProxy:t=>P(e.id,t),onEdit:()=>{y(e),x(!0)},onDelete:()=>$(e.id)},e.id))}),(0,a.jsx)("div",{className:"mt-4 flex justify-stretch sm:justify-start",children:(0,a.jsx)(i.$n,{size:"sm",icon:"add",onClick:()=>p(!0),children:"Add"})})]})]}),(0,a.jsx)(f,{isOpen:m,provider:e,proxyPools:l,onSave:_,onClose:()=>p(!1)}),(0,a.jsx)(i.wI,{isOpen:u,connection:h,proxyPools:l,onSave:T,onClose:()=>x(!1)})]})}function y({model:e,fullModel:t,copied:s,onCopy:r,testStatus:l,isCustom:o,isFree:n,onDeleteAlias:i,onTest:d,isTesting:c}){let m="ok"===l?"#22c55e":"error"===l?"#ef4444":void 0;return(0,a.jsx)("div",{className:`group px-3 py-2 rounded-lg border ${"ok"===l?"border-green-500/40":"error"===l?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-base",style:m?{color:m}:void 0,children:"ok"===l?"check_circle":"error"===l?"cancel":"smart_toy"}),(0,a.jsxs)("div",{className:"flex flex-col gap-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}),e.name&&(0,a.jsx)("span",{className:"text-[9px] text-text-muted/70 italic pl-1",children:e.name})]}),d&&(0,a.jsxs)("div",{className:"relative group/btn",children:[(0,a.jsx)("button",{onClick:d,disabled:c,className:`p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary transition-opacity ${c?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",style:c?{animation:"spin 1s linear infinite"}:void 0,children:c?"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:c?"Testing...":"Test"})]}),(0,a.jsxs)("div",{className:"relative group/btn",children:[(0,a.jsx)("button",{onClick:()=>r(t,`model-${e.id}`),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.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:s===`model-${e.id}`?"Copied!":"Copy"})]}),n&&(0,a.jsx)("span",{className:"text-[10px] font-bold text-green-500 bg-green-500/10 px-1.5 py-0.5 rounded",children:"FREE"}),o&&(0,a.jsx)("button",{onClick:i,className:"p-0.5 hover:bg-red-500/10 rounded text-text-muted hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity ml-auto",title:"Remove custom model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})})]})})}function j({isOpen:e,onSave:t,onClose:s}){let[r,l]=(0,n.useState)(""),o=()=>{r.trim()&&(t(r.trim()),l(""))};return(0,a.jsx)(i.aF,{isOpen:e,title:"Add Custom Model",onClose:s,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Model ID"}),(0,a.jsx)("input",{className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",value:r,onChange:e=>l(e.target.value),onKeyDown:e=>"Enter"===e.key&&o(),placeholder:"e.g. tts-1-hd",autoFocus:!0})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(i.$n,{onClick:o,fullWidth:!0,disabled:!r.trim(),children:"Add"}),(0,a.jsx)(i.$n,{onClick:s,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}function v({providerId:e,kindFilter:t,providerAliasOverride:s}){let{copied:r,copy:l}=(0,p.C)(),[o,d]=(0,n.useState)({}),[u,x]=(0,n.useState)([]),[h,b]=(0,n.useState)({}),[f,g]=(0,n.useState)(null),[w,N]=(0,n.useState)(""),[k,S]=(0,n.useState)(!1),[C,$]=(0,n.useState)([]),A=s||(0,c.wG)(e),P=t||"llm",_=(0,n.useCallback)(async()=>{try{let[t,s,a]=await Promise.all([fetch("/api/models/alias"),fetch("/api/providers",{cache:"no-store"}),fetch("/api/models/custom",{cache:"no-store"})]),r=await t.json(),l=await s.json(),o=await a.json();t.ok&&d(r.aliases||{}),s.ok&&$((l.connections||[]).filter(t=>t.provider===e)),a.ok&&x(o.models||[])}catch(e){console.log("ModelsCard fetch error:",e)}},[e]);(0,n.useEffect)(()=>{_()},[_]);let T=async(e,t)=>{let s=`${A}/${e}`;try{(await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:s,alias:t})})).ok&&await _()}catch(e){console.log("set alias error:",e)}},R=async e=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await _()}catch(e){console.log("delete alias error:",e)}},E=async e=>{try{(await fetch("/api/models/custom",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:A,id:e,type:P})})).ok&&(await _(),window.dispatchEvent(new CustomEvent("customModelChanged")))}catch(e){console.log("add custom model error:",e)}},I=async e=>{try{let t=new URLSearchParams({providerAlias:A,id:e,type:P});(await fetch(`/api/models/custom?${t}`,{method:"DELETE"})).ok&&(await _(),window.dispatchEvent(new CustomEvent("customModelChanged")))}catch(e){console.log("delete custom model error:",e)}},O=async e=>{if(!f){g(e);try{let s=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${A}/${e}`,kind:t})}),a=await s.json();b(t=>({...t,[e]:a.ok?"ok":"error"})),N(a.ok?"":a.error||"Model not reachable")}catch{b(t=>({...t,[e]:"error"})),N("Network error")}finally{g(null)}}},M=(0,m.KC)(e),U=t?M.filter(e=>e.kinds?e.kinds.includes(t):(e.type||"llm")===t):M,K=u.filter(e=>e.providerAlias===A&&(e.type||"llm")===P&&!U.some(t=>t.id===e.id));return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(i.Zp,{children:[(0,a.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,a.jsxs)("h2",{className:"text-lg font-semibold",children:["Models",t?` — ${t.toUpperCase()}`:""]})}),w&&(0,a.jsx)("p",{className:"text-xs text-red-500 mb-3 break-words",children:w}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-3",children:[U.map(e=>{let t=`${A}/${e.id}`,s=Object.entries(o).find(([,e])=>e===t)?.[0];return(0,a.jsx)(y,{model:e,fullModel:`${A}/${e.id}`,alias:s,copied:r,onCopy:l,onSetAlias:t=>T(e.id,t),onDeleteAlias:()=>R(s),testStatus:h[e.id],onTest:C.length>0?()=>O(e.id):void 0,isTesting:f===e.id,isFree:e.isFree},e.id)}),K.map(e=>(0,a.jsx)(y,{model:{id:e.id,name:e.name},fullModel:`${A}/${e.id}`,copied:r,onCopy:l,onSetAlias:()=>{},onDeleteAlias:()=>I(e.id),testStatus:h[e.id],onTest:C.length>0?()=>O(e.id):void 0,isTesting:f===e.id,isCustom:!0},`${e.id}-${e.type}`)),(0,a.jsxs)("button",{onClick:()=>S(!0),className:"flex items-center gap-1.5 px-3 py-2 rounded-lg border border-dashed border-black/15 dark:border-white/15 text-xs text-text-muted hover:text-primary hover:border-primary/40 transition-colors",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"add"}),"Add Model"]})]})]}),(0,a.jsx)(j,{isOpen:k,onSave:async e=>{await E(e),S(!1)},onClose:()=>S(!1)})]})}h.propTypes={until:x().string.isRequired},b.propTypes={connection:x().shape({id:x().string,name:x().string,email:x().string,displayName:x().string,testStatus:x().string,isActive:x().bool,lastError:x().string,priority:x().number}).isRequired,proxyPools:x().array,isOAuth:x().bool.isRequired,isFirst:x().bool.isRequired,isLast:x().bool.isRequired,onMoveUp:x().func.isRequired,onMoveDown:x().func.isRequired,onToggleActive:x().func.isRequired,onUpdateProxy:x().func,onEdit:x().func.isRequired,onDelete:x().func.isRequired},f.propTypes={isOpen:x().bool.isRequired,provider:x().string,providerName:x().string,proxyPools:x().array,onSave:x().func.isRequired,onClose:x().func.isRequired},g.propTypes={providerId:x().string.isRequired,isOAuth:x().bool},y.propTypes={model:x().shape({id:x().string.isRequired}).isRequired,fullModel:x().string.isRequired,copied:x().string,onCopy:x().func.isRequired,testStatus:x().oneOf(["ok","error"]),isCustom:x().bool,isFree:x().bool,onDeleteAlias:x().func,onTest:x().func,isTesting:x().bool},j.propTypes={isOpen:x().bool.isRequired,onSave:x().func.isRequired,onClose:x().func.isRequired},v.propTypes={providerId:x().string.isRequired,kindFilter:x().string,providerAliasOverride:x().string};let w={"google-tts":{hasLanguageDropdown:!1,hasModelSelector:!1,hasBrowseButton:!0,voiceSource:"hardcoded"},openai:{hasLanguageDropdown:!1,hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"hardcoded",modelKey:"openai-tts-models",voiceKey:"openai-tts-voices",voicesPerModel:!0},openrouter:{hasLanguageDropdown:!1,hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"hardcoded",modelKey:"openrouter-tts-models",voiceKey:"openrouter-tts-voices",voicesPerModel:!0},elevenlabs:{hasLanguageDropdown:!1,hasModelSelector:!0,hasBrowseButton:!0,hasVoiceIdInput:!0,voiceSource:"api-language",modelKey:"elevenlabs-tts-models",apiEndpoint:"/api/media-providers/tts/elevenlabs/voices"},"edge-tts":{hasLanguageDropdown:!1,hasModelSelector:!1,hasBrowseButton:!0,voiceSource:"api-language"},"local-device":{hasLanguageDropdown:!1,hasModelSelector:!1,hasBrowseButton:!0,voiceSource:"api-language"},nvidia:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},hyperbolic:{hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"config"},deepgram:{hasModelSelector:!1,hasBrowseButton:!0,voiceSource:"api-language",apiEndpoint:"/api/media-providers/tts/deepgram/voices"},huggingface:{hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"config"},cartesia:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},playht:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},coqui:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},tortoise:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},inworld:{hasModelSelector:!0,hasBrowseButton:!0,hasVoiceIdInput:!0,voiceSource:"api-language",modelKey:"inworld-tts-models",apiEndpoint:"/api/media-providers/tts/inworld/voices"},qwen:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},gemini:{hasLanguageDropdown:!1,hasLanguageHint:!0,hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"hardcoded",modelKey:"gemini-tts-models",voiceKey:"gemini-tts-voices",voicesPerModel:!0}};var N=s(717),k=s(91781);function S({label:e,children:t,align:s="center"}){return(0,a.jsxs)("div",{className:"flex min-w-0 flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-3",children:[(0,a.jsx)("span",{className:"w-full text-xs font-medium text-text-muted sm:w-20 sm:shrink-0",children:e}),(0,a.jsx)("div",{className:"w-full min-w-0 flex-1",children:t})]})}function C(){return"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,11)}`}let $=`// Audio will appear here after running.
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[182],{42661:(e,t,s)=>{Promise.resolve().then(s.bind(s,94588))},94588:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>I});var a=s(95155),r=s(73321),l=s(98500),o=s.n(l),n=s(12115),i=s(35497),d=s(57250),c=s(52679),m=s(28777),p=s(11059),u=s(14051),x=s.n(u);function h({until:e}){let[t,s]=(0,n.useState)("");return((0,n.useEffect)(()=>{let t=()=>{let t=new Date(e).getTime()-Date.now();if(t<=0)return void s("");let a=Math.floor(t/1e3);a<60?s(`${a}s`):a<3600?s(`${Math.floor(a/60)}m ${a%60}s`):s(`${Math.floor(a/3600)}h ${Math.floor(a%3600/60)}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 b({connection:e,proxyPools:t,isOAuth:s,isFirst:r,isLast:l,onMoveUp:o,onMoveDown:d,onToggleActive:c,onUpdateProxy:m,onEdit:p,onDelete:u}){let[x,f]=(0,n.useState)(!1),[g,y]=(0,n.useState)(!1),[j,v]=(0,n.useState)(!1),w=(0,n.useRef)(null),N=new Map((t||[]).map(e=>[e.id,e])),k=e.providerSpecificData?.proxyPoolId||null,S=k?N.get(k):null,C=e.providerSpecificData?.connectionProxyEnabled===!0&&!!e.providerSpecificData?.connectionProxyUrl,$=!!k||C,A=S?`Pool: ${S.name}`:k?`Pool: ${k} (inactive/missing)`:C?`Legacy: ${e.providerSpecificData?.connectionProxyUrl}`:"",P="",_=S?.proxyUrl||e.providerSpecificData?.connectionProxyUrl;if(_)try{let e=new URL(_);P=`${e.protocol}//${e.hostname}${e.port?`:${e.port}`:""}`}catch{P=_}let T=S?.noProxy||e.providerSpecificData?.connectionNoProxy||"",R=S?.isActive===!0?"success":k||C?"error":"default",E=Object.entries(e).filter(([e])=>e.startsWith("modelLock_")).map(([,e])=>e).filter(Boolean).sort()[0]||null;(0,n.useEffect)(()=>{let t=()=>{v(!!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=E?setInterval(t,1e3):null;return()=>{s&&clearInterval(s)}},[E]),(0,n.useEffect)(()=>{if(!x)return;let e=e=>{w.current&&!w.current.contains(e.target)&&f(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[x]);let I="unavailable"!==e.testStatus||j?e.testStatus:"active",O=s?e.name||e.email||e.displayName||"OAuth Account":e.name,M=async e=>{y(!0);try{await m("__none__"===e?null:e)}finally{y(!1),f(!1)}};return(0,a.jsxs)("div",{className:`group flex flex-col gap-3 p-2 rounded-lg sm:flex-row sm:items-center sm:justify-between hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors ${!1===e.isActive?"opacity-60":""}`,children:[(0,a.jsxs)("div",{className:"flex w-full min-w-0 flex-1 items-start gap-3 sm:items-center",children:[(0,a.jsxs)("div",{className:"flex flex-col",children:[(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_up"})}),(0,a.jsx)("button",{onClick:d,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_down"})})]}),(0,a.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:s?"lock":"key"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-medium truncate",children:O}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mt-1",children:[(0,a.jsx)(i.Ex,{variant:!1===e.isActive?"default":"active"===I||"success"===I?"success":"error"===I||"expired"===I||"unavailable"===I?"error":"default",size:"sm",dot:!0,children:!1===e.isActive?"disabled":I||"Unknown"}),$&&(0,a.jsx)(i.Ex,{variant:R,size:"sm",children:"Proxy"}),j&&!1!==e.isActive&&(0,a.jsx)(h,{until:E}),e.lastError&&!1!==e.isActive&&(0,a.jsx)("span",{className:"text-xs text-red-500 truncate max-w-[300px]",title:e.lastError,children:e.lastError}),(0,a.jsxs)("span",{className:"text-xs text-text-muted",children:["#",e.priority]})]}),$&&(0,a.jsxs)("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"text-[11px] text-text-muted truncate max-w-[420px]",title:A,children:A}),P&&(0,a.jsx)("code",{className:"text-[10px] font-mono bg-black/5 dark:bg-white/5 px-1 py-0.5 rounded text-text-muted",children:P}),T&&(0,a.jsxs)("span",{className:"text-[11px] text-text-muted truncate max-w-[320px]",title:T,children:["no_proxy: ",T]})]})]})]}),(0,a.jsxs)("div",{className:"flex w-full flex-wrap items-center justify-between gap-2 sm:w-auto sm:justify-end",children:[(0,a.jsxs)("div",{className:"flex flex-wrap gap-1",children:[(t||[]).length>0&&(0,a.jsxs)("div",{className:"relative",ref:w,children:[(0,a.jsxs)("button",{onClick:()=>f(e=>!e),className:`flex flex-col items-center px-2 py-1 rounded hover:bg-black/5 dark:hover:bg-white/5 transition-colors ${$?"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"})]}),x&&(0,a.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-50 bg-bg border border-border rounded-lg shadow-lg py-1 min-w-[160px]",children:[(0,a.jsx)("button",{onClick:()=>M("__none__"),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${!k?"text-primary font-medium":"text-text-main"}`,children:"None"}),(t||[]).map(e=>(0,a.jsx)("button",{onClick:()=>M(e.id),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${k===e.id?"text-primary font-medium":"text-text-main"}`,children:e.name},e.id))]})]}),(0,a.jsxs)("button",{onClick:p,className:"flex flex-col items-center px-2 py-1 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-primary",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:u,className:"flex flex-col items-center px-2 py-1 rounded hover:bg-red-500/10 text-red-500",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)(i.lM,{size:"sm",checked:e.isActive??!0,onChange:c,title:e.isActive??!0?"Disable":"Enable"})]})]})}function f({isOpen:e,provider:t,providerName:s,proxyPools:r,onSave:l,onClose:o}){let d="__none__",[c,m]=(0,n.useState)({name:"",apiKey:"",priority:1,proxyPoolId:d}),[p,u]=(0,n.useState)(!1),[x,h]=(0,n.useState)(null),[b,g]=(0,n.useState)(!1),y=async()=>{u(!0);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:c.apiKey})}),s=await e.json();h(s.valid?"success":"failed")}catch{h("failed")}finally{u(!1)}},j=async()=>{if(t&&c.apiKey){g(!0);try{let e=!1;try{u(!0),h(null);let s=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:c.apiKey})});e=!!(await s.json()).valid,h(e?"success":"failed")}catch{h("failed")}finally{u(!1)}await l({name:c.name,apiKey:c.apiKey,priority:c.priority,proxyPoolId:c.proxyPoolId===d?null:c.proxyPoolId,testStatus:e?"active":"unknown"})}finally{g(!1)}}};return t?(0,a.jsx)(i.aF,{isOpen:e,title:`Add ${s||t} API Key`,onClose:o,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Name"}),(0,a.jsx)("input",{className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",value:c.name,onChange:e=>m({...c,name:e.target.value}),placeholder:"Production Key"})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"API Key"}),(0,a.jsx)("input",{type:"password",className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",value:c.apiKey,onChange:e=>m({...c,apiKey:e.target.value})})]}),(0,a.jsx)("div",{className:"pt-6",children:(0,a.jsx)(i.$n,{onClick:y,disabled:!c.apiKey||p||b,variant:"secondary",children:p?"Checking...":"Check"})})]}),x&&(0,a.jsx)(i.Ex,{variant:"success"===x?"success":"error",children:"success"===x?"Valid":"Invalid"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Priority"}),(0,a.jsx)("input",{type:"number",className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",value:c.priority,onChange:e=>m({...c,priority:Number.parseInt(e.target.value)||1})})]}),(0,a.jsx)(i.l6,{label:"Proxy Pool",value:c.proxyPoolId,onChange:e=>m({...c,proxyPoolId:e.target.value}),options:[{value:d,label:"None"},...(r||[]).map(e=>({value:e.id,label:e.name}))]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(i.$n,{onClick:j,fullWidth:!0,disabled:!c.name||!c.apiKey||b,children:b?"Saving...":"Save"}),(0,a.jsx)(i.$n,{onClick:o,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}function g({providerId:e,isOAuth:t}){let[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)([]),[d,c]=(0,n.useState)(!0),[m,p]=(0,n.useState)(!1),[u,x]=(0,n.useState)(!1),[h,y]=(0,n.useState)(null),[j,v]=(0,n.useState)(null),[w,N]=(0,n.useState)("1"),k=(0,n.useCallback)(async()=>{try{let[t,s,a]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/proxy-pools?isActive=true",{cache:"no-store"}),fetch("/api/settings",{cache:"no-store"})]),l=await t.json(),n=await s.json(),i=a.ok?await a.json():{};t.ok&&r((l.connections||[]).filter(t=>t.provider===e)),s.ok&&o(n.proxyPools||[]);let d=(i.providerStrategies||{})[e]||{};v(d.fallbackStrategy||null),N(null!=d.stickyRoundRobinLimit?String(d.stickyRoundRobinLimit):"1")}catch(e){console.log("ConnectionsCard fetch error:",e)}finally{c(!1)}},[e]);(0,n.useEffect)(()=>{k()},[k]);let S=async(t,s)=>{try{let a=await fetch("/api/settings",{cache:"no-store"}),r=(a.ok?await a.json():{}).providerStrategies||{},l={};t&&(l.fallbackStrategy=t),"round-robin"===t&&""!==s&&(l.stickyRoundRobinLimit=Number(s)||3);let o={...r};0===Object.keys(l).length?delete o[e]:o[e]=l,await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerStrategies:o})})}catch(e){console.log("saveStrategy error:",e)}},C=async(e,t)=>{let a=[...s];[a[e],a[t]]=[a[t],a[e]],r(a);try{await Promise.all([fetch(`/api/providers/${a[e].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:e})}),fetch(`/api/providers/${a[t].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:t})})])}catch{await k()}},$=async e=>{if(confirm("Delete this connection?"))try{(await fetch(`/api/providers/${e}`,{method:"DELETE"})).ok&&r(t=>t.filter(t=>t.id!==e))}catch(e){console.log("delete error:",e)}},A=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&r(s=>s.map(s=>s.id===e?{...s,isActive:t}:s))}catch(e){console.log("toggle error:",e)}},P=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyPoolId:t||null})})).ok&&r(s=>s.map(s=>s.id===e?{...s,providerSpecificData:{...s.providerSpecificData,proxyPoolId:t||null}}:s))}catch(e){console.log("proxy error:",e)}},_=async t=>{try{(await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,...t})})).ok&&(await k(),p(!1))}catch(e){console.log("save apikey error:",e)}},T=async e=>{try{(await fetch(`/api/providers/${h.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(await k(),x(!1))}catch(e){console.log("update connection error:",e)}};return d?(0,a.jsx)(i.Zp,{children:(0,a.jsx)("div",{className:"h-20 animate-pulse bg-black/5 rounded-lg"})}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(i.Zp,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between mb-4",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold",children:"Connections"}),(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)(i.lM,{checked:"round-robin"===j,onChange:e=>{let t=e?"round-robin":null;v(t),e&&!w&&N("1"),S(t,e?w||"1":w)}}),"round-robin"===j&&(0,a.jsxs)("div",{className:"flex flex-wrap 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:w,onChange:e=>{N(e.target.value),S("round-robin",e.target.value)},className:"w-16 px-2 py-1 text-xs border border-border rounded-md bg-background focus:outline-none focus:border-primary"})]})]})]}),0===s.length?(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"No connections yet"}),(0,a.jsx)(i.$n,{size:"sm",icon:"add",onClick:()=>p(!0),children:"Add Connection"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"flex flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:s.map((e,r)=>(0,a.jsx)(b,{connection:e,proxyPools:l,isOAuth:t,isFirst:0===r,isLast:r===s.length-1,onMoveUp:()=>C(r,r-1),onMoveDown:()=>C(r,r+1),onToggleActive:t=>A(e.id,t),onUpdateProxy:t=>P(e.id,t),onEdit:()=>{y(e),x(!0)},onDelete:()=>$(e.id)},e.id))}),(0,a.jsx)("div",{className:"mt-4 flex justify-stretch sm:justify-start",children:(0,a.jsx)(i.$n,{size:"sm",icon:"add",onClick:()=>p(!0),children:"Add"})})]})]}),(0,a.jsx)(f,{isOpen:m,provider:e,proxyPools:l,onSave:_,onClose:()=>p(!1)}),(0,a.jsx)(i.wI,{isOpen:u,connection:h,proxyPools:l,onSave:T,onClose:()=>x(!1)})]})}function y({model:e,fullModel:t,copied:s,onCopy:r,testStatus:l,isCustom:o,isFree:n,onDeleteAlias:i,onTest:d,isTesting:c}){let m="ok"===l?"#22c55e":"error"===l?"#ef4444":void 0;return(0,a.jsx)("div",{className:`group px-3 py-2 rounded-lg border ${"ok"===l?"border-green-500/40":"error"===l?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-base",style:m?{color:m}:void 0,children:"ok"===l?"check_circle":"error"===l?"cancel":"smart_toy"}),(0,a.jsxs)("div",{className:"flex flex-col gap-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}),e.name&&(0,a.jsx)("span",{className:"text-[9px] text-text-muted/70 italic pl-1",children:e.name})]}),d&&(0,a.jsxs)("div",{className:"relative group/btn",children:[(0,a.jsx)("button",{onClick:d,disabled:c,className:`p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary transition-opacity ${c?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",style:c?{animation:"spin 1s linear infinite"}:void 0,children:c?"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:c?"Testing...":"Test"})]}),(0,a.jsxs)("div",{className:"relative group/btn",children:[(0,a.jsx)("button",{onClick:()=>r(t,`model-${e.id}`),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.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:s===`model-${e.id}`?"Copied!":"Copy"})]}),n&&(0,a.jsx)("span",{className:"text-[10px] font-bold text-green-500 bg-green-500/10 px-1.5 py-0.5 rounded",children:"FREE"}),o&&(0,a.jsx)("button",{onClick:i,className:"p-0.5 hover:bg-red-500/10 rounded text-text-muted hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity ml-auto",title:"Remove custom model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})})]})})}function j({isOpen:e,onSave:t,onClose:s}){let[r,l]=(0,n.useState)(""),o=()=>{r.trim()&&(t(r.trim()),l(""))};return(0,a.jsx)(i.aF,{isOpen:e,title:"Add Custom Model",onClose:s,children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Model ID"}),(0,a.jsx)("input",{className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",value:r,onChange:e=>l(e.target.value),onKeyDown:e=>"Enter"===e.key&&o(),placeholder:"e.g. tts-1-hd",autoFocus:!0})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(i.$n,{type:"button",onClick:o,fullWidth:!0,disabled:!r.trim(),children:"Add"}),(0,a.jsx)(i.$n,{type:"button",onClick:s,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}function v({providerId:e,kindFilter:t,providerAliasOverride:s}){let{copied:r,copy:l}=(0,p.C)(),[o,d]=(0,n.useState)({}),[u,x]=(0,n.useState)([]),[h,b]=(0,n.useState)({}),[f,g]=(0,n.useState)(null),[w,N]=(0,n.useState)(""),[k,S]=(0,n.useState)(!1),[C,$]=(0,n.useState)([]),A=s||(0,c.wG)(e),P=t||"llm",_=(0,n.useCallback)(async()=>{try{let[t,s,a]=await Promise.all([fetch("/api/models/alias"),fetch("/api/providers",{cache:"no-store"}),fetch("/api/models/custom",{cache:"no-store"})]),r=await t.json(),l=await s.json(),o=await a.json();t.ok&&d(r.aliases||{}),s.ok&&$((l.connections||[]).filter(t=>t.provider===e)),a.ok&&x(o.models||[])}catch(e){console.log("ModelsCard fetch error:",e)}},[e]);(0,n.useEffect)(()=>{_()},[_]);let T=async(e,t)=>{let s=`${A}/${e}`;try{(await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:s,alias:t})})).ok&&await _()}catch(e){console.log("set alias error:",e)}},R=async e=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await _()}catch(e){console.log("delete alias error:",e)}},E=async e=>{try{(await fetch("/api/models/custom",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:A,id:e,type:P})})).ok&&(await _(),window.dispatchEvent(new CustomEvent("customModelChanged")))}catch(e){console.log("add custom model error:",e)}},I=async e=>{try{let t=new URLSearchParams({providerAlias:A,id:e,type:P});(await fetch(`/api/models/custom?${t}`,{method:"DELETE"})).ok&&(await _(),window.dispatchEvent(new CustomEvent("customModelChanged")))}catch(e){console.log("delete custom model error:",e)}},O=async e=>{if(!f){g(e);try{let s=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${A}/${e}`,kind:t})}),a=await s.json();b(t=>({...t,[e]:a.ok?"ok":"error"})),N(a.ok?"":a.error||"Model not reachable")}catch{b(t=>({...t,[e]:"error"})),N("Network error")}finally{g(null)}}},M=(0,m.KC)(e),U=t?M.filter(e=>e.kinds?e.kinds.includes(t):(e.type||"llm")===t):M,K=u.filter(e=>e.providerAlias===A&&(e.type||"llm")===P&&!U.some(t=>t.id===e.id));return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(i.Zp,{children:[(0,a.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,a.jsxs)("h2",{className:"text-lg font-semibold",children:["Models",t?` — ${t.toUpperCase()}`:""]})}),w&&(0,a.jsx)("p",{className:"text-xs text-red-500 mb-3 break-words",children:w}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-3",children:[U.map(e=>{let t=`${A}/${e.id}`,s=Object.entries(o).find(([,e])=>e===t)?.[0];return(0,a.jsx)(y,{model:e,fullModel:`${A}/${e.id}`,alias:s,copied:r,onCopy:l,onSetAlias:t=>T(e.id,t),onDeleteAlias:()=>R(s),testStatus:h[e.id],onTest:C.length>0?()=>O(e.id):void 0,isTesting:f===e.id,isFree:e.isFree},e.id)}),K.map(e=>(0,a.jsx)(y,{model:{id:e.id,name:e.name},fullModel:`${A}/${e.id}`,copied:r,onCopy:l,onSetAlias:()=>{},onDeleteAlias:()=>I(e.id),testStatus:h[e.id],onTest:C.length>0?()=>O(e.id):void 0,isTesting:f===e.id,isCustom:!0},`${e.id}-${e.type}`)),(0,a.jsxs)("button",{onClick:()=>S(!0),className:"flex items-center gap-1.5 px-3 py-2 rounded-lg border border-dashed border-black/15 dark:border-white/15 text-xs text-text-muted hover:text-primary hover:border-primary/40 transition-colors",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"add"}),"Add Model"]})]})]}),(0,a.jsx)(j,{isOpen:k,onSave:async e=>{await E(e),S(!1)},onClose:()=>S(!1)})]})}h.propTypes={until:x().string.isRequired},b.propTypes={connection:x().shape({id:x().string,name:x().string,email:x().string,displayName:x().string,testStatus:x().string,isActive:x().bool,lastError:x().string,priority:x().number}).isRequired,proxyPools:x().array,isOAuth:x().bool.isRequired,isFirst:x().bool.isRequired,isLast:x().bool.isRequired,onMoveUp:x().func.isRequired,onMoveDown:x().func.isRequired,onToggleActive:x().func.isRequired,onUpdateProxy:x().func,onEdit:x().func.isRequired,onDelete:x().func.isRequired},f.propTypes={isOpen:x().bool.isRequired,provider:x().string,providerName:x().string,proxyPools:x().array,onSave:x().func.isRequired,onClose:x().func.isRequired},g.propTypes={providerId:x().string.isRequired,isOAuth:x().bool},y.propTypes={model:x().shape({id:x().string.isRequired}).isRequired,fullModel:x().string.isRequired,copied:x().string,onCopy:x().func.isRequired,testStatus:x().oneOf(["ok","error"]),isCustom:x().bool,isFree:x().bool,onDeleteAlias:x().func,onTest:x().func,isTesting:x().bool},j.propTypes={isOpen:x().bool.isRequired,onSave:x().func.isRequired,onClose:x().func.isRequired},v.propTypes={providerId:x().string.isRequired,kindFilter:x().string,providerAliasOverride:x().string};let w={"google-tts":{hasLanguageDropdown:!1,hasModelSelector:!1,hasBrowseButton:!0,voiceSource:"hardcoded"},openai:{hasLanguageDropdown:!1,hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"hardcoded",modelKey:"openai-tts-models",voiceKey:"openai-tts-voices",voicesPerModel:!0},openrouter:{hasLanguageDropdown:!1,hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"hardcoded",modelKey:"openrouter-tts-models",voiceKey:"openrouter-tts-voices",voicesPerModel:!0},elevenlabs:{hasLanguageDropdown:!1,hasModelSelector:!0,hasBrowseButton:!0,hasVoiceIdInput:!0,voiceSource:"api-language",modelKey:"elevenlabs-tts-models",apiEndpoint:"/api/media-providers/tts/elevenlabs/voices"},"edge-tts":{hasLanguageDropdown:!1,hasModelSelector:!1,hasBrowseButton:!0,voiceSource:"api-language"},"local-device":{hasLanguageDropdown:!1,hasModelSelector:!1,hasBrowseButton:!0,voiceSource:"api-language"},nvidia:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},hyperbolic:{hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"config"},deepgram:{hasModelSelector:!1,hasBrowseButton:!0,voiceSource:"api-language",apiEndpoint:"/api/media-providers/tts/deepgram/voices"},huggingface:{hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"config"},cartesia:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},playht:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},coqui:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},tortoise:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},inworld:{hasModelSelector:!0,hasBrowseButton:!0,hasVoiceIdInput:!0,voiceSource:"api-language",modelKey:"inworld-tts-models",apiEndpoint:"/api/media-providers/tts/inworld/voices"},qwen:{hasModelSelector:!0,hasBrowseButton:!1,hasVoiceIdInput:!0,voiceSource:"config"},gemini:{hasLanguageDropdown:!1,hasLanguageHint:!0,hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"hardcoded",modelKey:"gemini-tts-models",voiceKey:"gemini-tts-voices",voicesPerModel:!0}};var N=s(717),k=s(91781);function S({label:e,children:t,align:s="center"}){return(0,a.jsxs)("div",{className:"flex min-w-0 flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-3",children:[(0,a.jsx)("span",{className:"w-full text-xs font-medium text-text-muted sm:w-20 sm:shrink-0",children:e}),(0,a.jsx)("div",{className:"w-full min-w-0 flex-1",children:t})]})}function C(){return"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,11)}`}let $=`// Audio will appear here after running.
2
2
  // Example JSON response (response_format=json):
3
3
  {
4
4
  "format": "mp3",
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2134],{17721:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>C});var i=s(95155),a=s(12115),l=s(73321),r=s(98500),o=s.n(r),n=s(5772),d=s(35497),c=s(52679),p=s(28777),m=s(11059);let x=new Map;async function u(e){if(!e?.url||!e?.type)return[];let t=x.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 i=(await s.json()).data??[];return x.set(e.url,{data:i,expiresAt:Date.now()+6e5}),i}catch{return[]}}var h=s(14051),f=s.n(h);function y({model:e,fullModel:t,alias:s,copied:a,onCopy:l,testStatus:r,isCustom:o,isFree:n,onDeleteAlias:d,onTest:c,isTesting:p,onDisable:m}){let x="ok"===r?"#22c55e":"error"===r?"#ef4444":void 0;return(0,i.jsx)("div",{className:`group min-w-0 max-w-full rounded-lg border px-3 py-2 ${"ok"===r?"border-green-500/40":"error"===r?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:(0,i.jsxs)("div",{className:"flex min-w-0 items-start gap-2 sm:items-center",children:[(0,i.jsx)("span",{className:"material-symbols-outlined shrink-0 text-base",style:x?{color:x}:void 0,children:"ok"===r?"check_circle":"error"===r?"cancel":"smart_toy"}),(0,i.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[(0,i.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:t}),e.name&&(0,i.jsx)("span",{className:"truncate pl-1 text-[9px] italic text-text-muted/70",children:e.name})]}),c&&(0,i.jsxs)("div",{className:"relative shrink-0 group/btn",children:[(0,i.jsx)("button",{onClick:c,disabled:p,className:`rounded p-0.5 text-text-muted transition-opacity hover:bg-sidebar hover:text-primary ${p?"opacity-100":"opacity-100 sm:opacity-0 sm:group-hover:opacity-100"}`,children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",style:p?{animation:"spin 1s linear infinite"}:void 0,children:p?"progress_activity":"science"})}),(0,i.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:p?"Testing...":"Test"})]}),(0,i.jsxs)("div",{className:"relative shrink-0 group/btn",children:[(0,i.jsx)("button",{onClick:()=>l(t,`model-${e.id}`),className:"rounded p-0.5 text-text-muted hover:bg-sidebar hover:text-primary",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:a===`model-${e.id}`?"check":"content_copy"})}),(0,i.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:a===`model-${e.id}`?"Copied!":"Copy"})]}),o?(0,i.jsx)("button",{onClick:d,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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})}):m?(0,i.jsx)("button",{onClick:m,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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})}):null]})})}function g({modelId:e,fullModel:t,copied:s,onCopy:a,onDeleteAlias:l,onTest:r,testStatus:o,isTesting:n}){let d="ok"===o?"#22c55e":"error"===o?"#ef4444":void 0;return(0,i.jsxs)("div",{className:`flex items-center gap-3 p-3 rounded-lg border ${"ok"===o?"border-green-500/40":"error"===o?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",style:d?{color:d}:void 0,children:"ok"===o?"check_circle":"error"===o?"cancel":"smart_toy"}),(0,i.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,i.jsx)("p",{className:"text-sm font-medium truncate",children:e}),(0,i.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,i.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:t}),(0,i.jsxs)("div",{className:"relative group/btn",children:[(0,i.jsx)("button",{onClick:()=>a(t,`model-${e}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:s===`model-${e}`?"check":"content_copy"})}),(0,i.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,i.jsxs)("div",{className:"relative group/btn",children:[(0,i.jsx)("button",{onClick:r,disabled:n,className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary transition-colors",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",style:n?{animation:"spin 1s linear infinite"}:void 0,children:n?"progress_activity":"science"})}),(0,i.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:n?"Testing...":"Test"})]})]})]}),(0,i.jsx)("button",{onClick:l,className:"p-1 hover:bg-red-50 rounded text-red-500",title:"Remove model",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})}function b({providerStorageAlias:e,providerDisplayAlias:t,modelAliases:s,copied:l,onCopy:r,onSetAlias:o,onDeleteAlias:n,connections:c,isAnthropic:p}){let[m,x]=(0,a.useState)(""),[u,h]=(0,a.useState)(!1),[f,y]=(0,a.useState)(!1),[v,j]=(0,a.useState)(null),[w,N]=(0,a.useState)({}),k=async t=>{if(!v){j(t);try{let s=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${e}/${t}`})}),i=await s.json();N(e=>({...e,[t]:i.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=i=>{let a,l=`${e}/${i}`;if(Object.values(s).includes(l))return null;let r=(a=i.split("/"))[a.length-1];if(!s[r])return r;let o=`${t}-${r}`;return s[o]?null:o},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 o(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){y(!0);try{let s=await fetch(`/api/providers/${t.id}/models`),i=await s.json();if(!s.ok)return void alert(i.error||"Failed to import models");let a=i.models||[];if(0===a.length)return void alert("No models returned from /models.");let l=0;for(let t of a){let s=t.id||t.name||t.model;if(!s)continue;let i=S(s);i&&(await o(s,i,e),l+=1)}0===l&&alert("No new models were added.")}catch(e){console.log("Error importing models:",e)}finally{y(!1)}}},P=c.some(e=>!1!==e.isActive);return(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsxs)("p",{className:"text-sm text-text-muted",children:["Add ",p?"Anthropic":"OpenAI","-compatible models manually or import them from the /models endpoint."]}),(0,i.jsxs)("div",{className:"flex items-end gap-2 flex-wrap",children:[(0,i.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,i.jsx)("label",{htmlFor:"new-compatible-model-input",className:"text-xs text-text-muted mb-1 block",children:"Model ID"}),(0,i.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,i.jsx)(d.$n,{size:"sm",icon:"add",onClick:A,disabled:!m.trim()||u,children:u?"Adding...":"Add"}),(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"download",onClick:$,disabled:!P||f,children:f?"Importing...":"Import from /models"})]}),!P&&(0,i.jsx)("p",{className:"text-xs text-text-muted",children:"Add a connection to enable importing models."}),C.length>0&&(0,i.jsx)("div",{className:"flex flex-col gap-3",children:C.map(({modelId:e,fullModel:s,alias:a})=>(0,i.jsx)(g,{modelId:e,fullModel:`${t}/${e}`,copied:l,onCopy:r,onDeleteAlias:()=>n(a),onTest:c.length>0?()=>k(e):void 0,testStatus:w[e],isTesting:v===e},s))})]})}function v({until:e}){let[t,s]=(0,a.useState)("");return((0,a.useEffect)(()=>{let t=()=>{let t=new Date(e).getTime()-Date.now();if(t<=0)return void s("");let i=Math.floor(t/1e3);if(i<60)s(`${i}s`);else if(i<3600)s(`${Math.floor(i/60)}m ${i%60}s`);else{let e=Math.floor(i/3600),t=Math.floor(i%3600/60);s(`${e}h ${t}m`)}};t();let i=setInterval(t,1e3);return()=>clearInterval(i)},[e]),t)?(0,i.jsxs)("span",{className:"text-xs text-orange-500 font-mono",children:["⏱ ",t]}):null}function j({connection:e,proxyPools:t,isOAuth:s,isFirst:l,isLast:r,onMoveUp:o,onMoveDown:n,onToggleActive:c,onUpdateProxy:p,onEdit:m,onDelete:x}){let[u,h]=(0,a.useState)(!1),[f,y]=(0,a.useState)(!1),g=(0,a.useRef)(null),b=new Map((t||[]).map(e=>[e.id,e])),w=e.providerSpecificData?.proxyPoolId||null,N=w?b.get(w):null,k=e.providerSpecificData?.connectionProxyEnabled===!0&&!!e.providerSpecificData?.connectionProxyUrl,C=!!w||k,S=N?`Pool: ${N.name}`:w?`Pool: ${w} (inactive/missing)`:k?`Legacy: ${e.providerSpecificData?.connectionProxyUrl}`:"",A="";if(N?.proxyUrl||e.providerSpecificData?.connectionProxyUrl){let t=N?.proxyUrl||e.providerSpecificData?.connectionProxyUrl;try{let e=new URL(t);A=`${e.protocol}//${e.hostname}${e.port?`:${e.port}`:""}`}catch{A=t}}let $=N?.noProxy||e.providerSpecificData?.connectionNoProxy||"",P="default";N?.isActive===!0?P="success":(w||k)&&(P="error"),(0,a.useEffect)(()=>{if(!u)return;let e=e=>{g.current&&!g.current.contains(e.target)&&h(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[u]);let T=async e=>{y(!0);try{await p("__none__"===e?null:e)}finally{y(!1),h(!1)}},O=e=>"string"==typeof e&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),E=s?O(e.email)?e.email:O(e.name)?e.name:e.name||e.email||e.displayName||"OAuth Account":e.name,[I,R]=(0,a.useState)(!1),U=Object.entries(e).filter(([e])=>e.startsWith("modelLock_")).map(([,e])=>e).filter(e=>!!e).sort()[0]||null;(0,a.useEffect)(()=>{let t=()=>{R(!!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=U?setInterval(t,1e3):null;return()=>{s&&clearInterval(s)}},[U]);let _="unavailable"!==e.testStatus||I?e.testStatus:"active";return(0,i.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,i.jsxs)("div",{className:"flex min-w-0 flex-1 items-start gap-2 sm:items-center sm:gap-3",children:[(0,i.jsxs)("div",{className:"flex shrink-0 flex-col",children:[(0,i.jsx)("button",{onClick:o,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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_up"})}),(0,i.jsx)("button",{onClick:n,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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_down"})})]}),(0,i.jsx)("span",{className:"material-symbols-outlined shrink-0 text-base text-text-muted",children:s?"lock":"key"}),(0,i.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,i.jsx)("p",{className:"text-sm font-medium truncate",children:E}),(0,i.jsxs)("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1.5 sm:gap-2",children:[(0,i.jsx)(d.Ex,{variant:!1===e.isActive?"default":"active"===_||"success"===_?"success":"error"===_||"expired"===_||"unavailable"===_?"error":"default",size:"sm",dot:!0,children:!1===e.isActive?"disabled":_||"Unknown"}),C&&(0,i.jsx)(d.Ex,{variant:P,size:"sm",children:"Proxy"}),I&&!1!==e.isActive&&(0,i.jsx)(v,{until:U}),e.lastError&&!1!==e.isActive&&(0,i.jsx)("span",{className:"max-w-full truncate text-xs text-red-500 sm:max-w-[300px]",title:e.lastError,children:e.lastError}),(0,i.jsxs)("span",{className:"text-xs text-text-muted",children:["#",e.priority]}),e.globalPriority&&(0,i.jsxs)("span",{className:"text-xs text-text-muted",children:["Auto: ",e.globalPriority]})]}),C&&(0,i.jsxs)("div",{className:"mt-1 flex items-center gap-2 flex-wrap",children:[(0,i.jsx)("span",{className:"max-w-full truncate text-[11px] text-text-muted sm:max-w-[420px]",title:S,children:S}),A&&(0,i.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}),$&&(0,i.jsxs)("span",{className:"max-w-full truncate text-[11px] text-text-muted sm:max-w-[320px]",title:$,children:["no_proxy: ",$]})]})]})]}),(0,i.jsxs)("div",{className:"flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-end",children:[(0,i.jsxs)("div",{className:"grid flex-1 grid-cols-3 gap-1 sm:flex sm:flex-none",children:[(t||[]).length>0&&(0,i.jsxs)("div",{className:"relative",ref:g,children:[(0,i.jsxs)("button",{onClick:()=>h(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 ${C?"text-primary":"text-text-muted hover:text-primary"}`,disabled:f,children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:f?"progress_activity":"lan"}),(0,i.jsx)("span",{className:"text-[10px] leading-tight",children:"Proxy"})]}),u&&(0,i.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,i.jsx)("button",{onClick:()=>T("__none__"),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${!w?"text-primary font-medium":"text-text-main"}`,children:"None"}),(t||[]).map(e=>(0,i.jsx)("button",{onClick:()=>T(e.id),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${w===e.id?"text-primary font-medium":"text-text-main"}`,children:e.name},e.id))]})]}),(0,i.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,i.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"edit"}),(0,i.jsx)("span",{className:"text-[10px] leading-tight",children:"Edit"})]}),(0,i.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,i.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"delete"}),(0,i.jsx)("span",{className:"text-[10px] leading-tight",children:"Delete"})]})]}),(0,i.jsx)(d.lM,{size:"sm",checked:e.isActive??!0,onChange:c,title:e.isActive??!0?"Disable connection":"Enable connection"})]})]})}function w({isOpen:e,provider:t,providerName:s,isCompatible:l,isAnthropic:r,authType:o,authHint:n,website:c,proxyPools:p,onSave:m,onClose:x}){let u="__none__",h="ollama-local"===t,f="cookie"===o,y=f?"Cookie Value":"API Key",g=f?"grok-web"===t?"sso=xxxxx... or just the raw value":"eyJhbGciOi...":"",b="azure"===t,v="cloudflare-ai"===t,[j,N]=(0,a.useState)({name:"",apiKey:"",priority:1,proxyPoolId:u,ollamaHostUrl:""}),[k,C]=(0,a.useState)({azureEndpoint:"",apiVersion:"2024-10-01-preview",deployment:"",organization:""}),[S,A]=(0,a.useState)({accountId:""}),[$,P]=(0,a.useState)(!1),[T,O]=(0,a.useState)(null),[E,I]=(0,a.useState)(!1),R=h?"Ollama Local":f?`${s||t} Cookie`:"Production Key";(0,a.useEffect)(()=>{e&&(N({name:l?R:"",apiKey:"",priority:1,proxyPoolId:u,ollamaHostUrl:""}),C({azureEndpoint:"",apiVersion:"2024-10-01-preview",deployment:"",organization:""}),A({accountId:""}),P(!1),O(null),I(!1))},[R,l,e]);let U=()=>h&&j.ollamaHostUrl.trim()?{baseUrl:j.ollamaHostUrl.trim()}:b?{azureEndpoint:k.azureEndpoint,apiVersion:k.apiVersion,deployment:k.deployment,organization:k.organization}:v?{accountId:S.accountId}:void 0,_=async()=>{P(!0);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:j.apiKey,providerSpecificData:U()})}),s=await e.json();O(s.valid?"success":"failed")}catch{O("failed")}finally{P(!1)}},D=async()=>{if(!t||!h&&!j.apiKey)return;let e=j.name.trim()||R;I(!0);try{let s=!1;try{P(!0),O(null);let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:j.apiKey,providerSpecificData:U()})});s=!!(await e.json()).valid,O(s?"success":"failed")}catch{O("failed")}finally{P(!1)}await m({name:e,apiKey:j.apiKey,priority:j.priority,proxyPoolId:j.proxyPoolId===u?null:j.proxyPoolId,testStatus:s?"active":"unknown",providerSpecificData:U()})}finally{I(!1)}};return t?(0,i.jsx)(d.aF,{isOpen:e,title:`Add ${s||t} ${y}`,onClose:x,children:(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsx)(d.pd,{label:"Name",value:j.name,onChange:e=>N({...j,name:e.target.value}),placeholder:R}),h&&(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.pd,{label:"Ollama Host URL",value:j.ollamaHostUrl,onChange:e=>N({...j,ollamaHostUrl:e.target.value}),placeholder:"http://localhost:11434",className:"flex-1"}),(0,i.jsx)("div",{className:"pt-6",children:(0,i.jsx)(d.$n,{onClick:_,disabled:$||E,variant:"secondary",children:$?"Checking...":"Check"})})]}),!h&&(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.pd,{label:y,type:f?"text":"password",value:j.apiKey,onChange:e=>N({...j,apiKey:e.target.value}),placeholder:g,className:"flex-1"}),(0,i.jsx)("div",{className:"pt-6",children:(0,i.jsx)(d.$n,{onClick:_,disabled:!j.apiKey||$||E,variant:"secondary",children:$?"Checking...":"Check"})})]}),f&&n&&(0,i.jsxs)("p",{className:"text-xs text-text-muted",children:[n,c&&(0,i.jsxs)(i.Fragment,{children:[" ",(0,i.jsxs)("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:["Open ",c.replace(/^https?:\/\//,"")]})]})]}),h&&(0,i.jsxs)("p",{className:"text-xs text-text-muted",children:["Leave blank to use ",(0,i.jsx)("code",{children:"http://localhost:11434"}),". For remote Ollama, enter the full host URL (e.g. ",(0,i.jsx)("code",{children:"http://192.168.1.10:11434"}),")."]}),T&&(0,i.jsx)(d.Ex,{variant:"success"===T?"success":"error",children:"success"===T?"Valid":"Invalid"}),l&&(0,i.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.`}),v&&(0,i.jsxs)("div",{className:"bg-sidebar/50 p-4 rounded-lg border border-accent/20",children:[(0,i.jsx)("h3",{className:"font-semibold mb-3 text-sm",children:"Cloudflare Workers AI"}),(0,i.jsx)(d.pd,{label:"Account ID",value:S.accountId,onChange:e=>A({...S,accountId:e.target.value}),placeholder:"abc123def456..."}),(0,i.jsxs)("p",{className:"text-xs text-text-muted mt-2",children:["Find your Account ID in the right sidebar of ",(0,i.jsx)("a",{href:"https://dash.cloudflare.com",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"dash.cloudflare.com"})]})]}),b&&(0,i.jsxs)("div",{className:"bg-sidebar/50 p-4 rounded-lg border border-accent/20",children:[(0,i.jsx)("h3",{className:"font-semibold mb-3 text-sm",children:"Azure OpenAI Configuration"}),(0,i.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,i.jsx)(d.pd,{label:"Azure Endpoint",value:k.azureEndpoint,onChange:e=>C({...k,azureEndpoint:e.target.value}),placeholder:"https://your-resource.openai.azure.com"}),(0,i.jsx)(d.pd,{label:"Deployment Name",value:k.deployment,onChange:e=>C({...k,deployment:e.target.value}),placeholder:"gpt-4"}),(0,i.jsx)(d.pd,{label:"API Version",value:k.apiVersion,onChange:e=>C({...k,apiVersion:e.target.value}),placeholder:"2024-10-01-preview"}),(0,i.jsx)(d.pd,{label:"Organization",value:k.organization,onChange:e=>C({...k,organization:e.target.value}),placeholder:"Organization ID"})]})]}),(0,i.jsx)(d.pd,{label:"Priority",type:"number",value:j.priority,onChange:e=>N({...j,priority:Number.parseInt(e.target.value)||1})}),(0,i.jsx)(d.l6,{label:"Proxy Pool",value:j.proxyPoolId,onChange:e=>N({...j,proxyPoolId:e.target.value}),options:[{value:u,label:"None"},...(p||[]).map(e=>({value:e.id,label:e.name}))],placeholder:"None"}),0===(p||[]).length&&(0,i.jsx)("p",{className:"text-xs text-text-muted",children:"No active proxy pools available. Create one in Proxy Pools page first."}),(0,i.jsx)("p",{className:"text-xs text-text-muted",children:"Legacy manual proxy fields are still accepted by API for backward compatibility."}),(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.$n,{onClick:D,fullWidth:!0,disabled:E||!h&&!j.apiKey||b&&(!k.azureEndpoint||!k.deployment||!k.organization)||v&&!S.accountId,children:E?"Saving...":"Save"}),(0,i.jsx)(d.$n,{onClick:x,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}function N({isOpen:e,node:t,onSave:s,onClose:l,isAnthropic:r}){let[o,n]=(0,a.useState)({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[c,p]=(0,a.useState)(!1),[m,x]=(0,a.useState)(""),[u,h]=(0,a.useState)(""),[f,y]=(0,a.useState)(!1),[g,b]=(0,a.useState)(null);(0,a.useEffect)(()=>{t&&n({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(o.name.trim()&&o.prefix.trim()&&o.baseUrl.trim()){p(!0);try{let e={name:o.name,prefix:o.prefix,baseUrl:o.baseUrl};r||(e.apiType=o.apiType),await s(e)}finally{p(!1)}}},j=async()=>{y(!0);try{let e=await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:o.baseUrl,apiKey:m,type:r?"anthropic-compatible":"openai-compatible",modelId:u.trim()||void 0})}),t=await e.json();b(t.valid?"success":"failed")}catch{b("failed")}finally{y(!1)}};return t?(0,i.jsx)(d.aF,{isOpen:e,title:`Edit ${r?"Anthropic":"OpenAI"} Compatible`,onClose:l,children:(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsx)(d.pd,{label:"Name",value:o.name,onChange:e=>n({...o,name:e.target.value}),placeholder:`${r?"Anthropic":"OpenAI"} Compatible (Prod)`,hint:"Required. A friendly label for this node."}),(0,i.jsx)(d.pd,{label:"Prefix",value:o.prefix,onChange:e=>n({...o,prefix:e.target.value}),placeholder:r?"ac-prod":"oc-prod",hint:"Required. Used as the provider prefix for model IDs."}),!r&&(0,i.jsx)(d.l6,{label:"API Type",options:[{value:"chat",label:"Chat Completions"},{value:"responses",label:"Responses API"}],value:o.apiType,onChange:e=>n({...o,apiType:e.target.value})}),(0,i.jsx)(d.pd,{label:"Base URL",value:o.baseUrl,onChange:e=>n({...o,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,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.pd,{label:"API Key (for Check)",type:"password",value:m,onChange:e=>x(e.target.value),className:"flex-1"}),(0,i.jsx)("div",{className:"pt-6",children:(0,i.jsx)(d.$n,{onClick:j,disabled:!m||f||!o.baseUrl.trim(),variant:"secondary",children:f?"Checking...":"Check"})})]}),(0,i.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."}),g&&(0,i.jsx)(d.Ex,{variant:"success"===g?"success":"error",children:"success"===g?"Valid":"Invalid"}),(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.$n,{onClick:v,fullWidth:!0,disabled:!o.name.trim()||!o.prefix.trim()||!o.baseUrl.trim()||c,children:c?"Saving...":"Save"}),(0,i.jsx)(d.$n,{onClick:l,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}function k({isOpen:e,providerAlias:t,providerDisplayAlias:s,onSave:l,onClose:r}){var o;let n,[c,p]=(0,a.useState)(""),[m,x]=(0,a.useState)(null),[u,h]=(0,a.useState)(""),[f,y]=(0,a.useState)(!1);(0,a.useEffect)(()=>{e&&(p(""),x(null),h(""),y(!1))},[e]);let g=(o=c.trim(),n=`${t}/`,o.startsWith(n)?o.slice(n.length):o),b=async()=>{if(g){x("testing"),h("");try{let e=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${t}/${g}`})}),s=await e.json();x(s.ok?"ok":"error"),h(s.error||"")}catch(e){x("error"),h(e.message)}}},v=async()=>{if(g&&!f){y(!0);try{await l(g)}finally{y(!1)}}};return(0,i.jsx)(d.aF,{isOpen:e,onClose:r,title:"Add Custom Model",children:(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{className:"text-sm font-medium mb-1.5 block",children:"Model ID"}),(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.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,i.jsx)(d.$n,{type:"button",variant:"secondary",icon:"science",loading:"testing"===m,onClick:b,disabled:!g||"testing"===m,children:"testing"===m?"Testing...":"Test"})]}),(0,i.jsxs)("p",{className:"text-xs text-text-muted mt-1",children:["Sent to provider as: ",(0,i.jsx)("code",{className:"font-mono bg-sidebar px-1 rounded",children:g||"model-id"})]})]}),"ok"===m&&(0,i.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600",children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-base",children:"check_circle"}),"Model is reachable"]}),"error"===m&&(0,i.jsxs)("div",{className:"flex items-start gap-2 text-sm text-red-500",children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-base shrink-0",children:"cancel"}),(0,i.jsx)("span",{children:u||"Model not reachable"})]}),(0,i.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,i.jsx)(d.$n,{type:"button",onClick:r,variant:"ghost",fullWidth:!0,size:"sm",children:"Cancel"}),(0,i.jsx)(d.$n,{type:"button",onClick:v,fullWidth:!0,size:"sm",disabled:!g||f,children:f?"Adding...":"Add Model"})]})]})})}function C(){let e,t=(0,l.useParams)(),s=(0,l.useRouter)(),r=t.id,[x,h]=(0,a.useState)([]),[f,g]=(0,a.useState)(!0),[v,C]=(0,a.useState)(null),[S,A]=(0,a.useState)([]),[$,P]=(0,a.useState)(!1),[T,O]=(0,a.useState)(!1),[E,I]=(0,a.useState)(!1),[R,U]=(0,a.useState)(!1),[_,D]=(0,a.useState)(!1),[q,z]=(0,a.useState)(!1),[M,L]=(0,a.useState)(null),[K,F]=(0,a.useState)({}),[J,W]=(0,a.useState)(!1),[V,H]=(0,a.useState)({}),[G,B]=(0,a.useState)(""),[Q,Z]=(0,a.useState)(null),[X,Y]=(0,a.useState)(!1),[ee,et]=(0,a.useState)([]),[es,ei]=(0,a.useState)("__none__"),[ea,el]=(0,a.useState)(!1),[er,eo]=(0,a.useState)(null),[en,ed]=(0,a.useState)(""),[ec,ep]=(0,a.useState)("auto"),[em,ex]=(0,a.useState)([]),[eu,eh]=(0,a.useState)([]),[ef,ey]=(0,a.useState)([]),{copied:eg,copy:eb}=(0,m.C)(),ev=v?{id:v.id,name:v.name||("anthropic-compatible"===v.type?"Anthropic Compatible":"OpenAI Compatible"),color:"anthropic-compatible"===v.type?"#D97757":"#10A37F",textIcon:"anthropic-compatible"===v.type?"AC":"OC",apiType:v.apiType,baseUrl:v.baseUrl,type:v.type}:c.zN[r]||c.fg[r]||c.IS[r]||c.nJ[r]||c.br[r],ej=!!c.zN[r]||!!c.IS[r],ew=!!c.IS[r]?.noAuth,eN=(0,p.KC)(r),ek=(0,c.wG)(r),eC=(0,c.mq)(r),eS=(0,c.gb)(r),eA=eC||eS;c.Q2[r]?.thinkingConfig||c.s9.extended;let e$=eA?r:ek,eP=eA?v?.prefix||r:ek,eT=(0,a.useCallback)(async()=>{try{let e=await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(e$)}`,{cache:"no-store"}),t=await e.json();e.ok&&ey(t.ids||[])}catch(e){console.log("Error fetching disabled models:",e)}},[e$]),eO=async e=>{try{(await fetch("/api/models/disabled",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:e$,ids:[e]})})).ok&&await eT()}catch(e){console.log("Error disabling model:",e)}},eE=async e=>{try{(await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(e$)}&id=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await eT()}catch(e){console.log("Error enabling model:",e)}},eI=async e=>{if(e.length&&confirm(`Disable all ${e.length} model(s)?`))try{(await fetch("/api/models/disabled",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:e$,ids:e})})).ok&&await eT()}catch(e){console.log("Error disabling all models:",e)}},eR=async()=>{try{(await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(e$)}`,{method:"DELETE"})).ok&&await eT()}catch(e){console.log("Error enabling all models:",e)}},eU=(0,a.useCallback)(async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&F(t.aliases||{})}catch(e){console.log("Error fetching aliases:",e)}},[]);(0,a.useEffect)(()=>{"kilocode"===r&&fetch("/api/providers/kilo/free-models").then(e=>e.json()).then(e=>{e.models?.length&&eh(e.models)}).catch(()=>{})},[r]);let e_=(0,a.useCallback)(async()=>{try{let[e,t,s,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"})]),a=await e.json(),l=await t.json(),o=await s.json(),n=i.ok?await i.json():{};if(e.ok){let e=(a.connections||[]).filter(e=>e.provider===r);h(e)}s.ok&&A(o.proxyPools||[]);let d=(n.providerStrategies||{})[r]||{};eo(d.fallbackStrategy||null),ed(null!=d.stickyRoundRobinLimit?String(d.stickyRoundRobinLimit):"1");let c=(n.providerThinking||{})[r]||{};if(ep(c.mode||"auto"),t.ok){let e=(l.nodes||[]).find(e=>e.id===r)||null;if(!e&&eA)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}C(e)}}catch(e){console.log("Error fetching connections:",e)}finally{g(!1)}},[r,eA]),eD=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&&(C(s.node),await e_(),D(!1))}catch(e){console.log("Error updating provider node:",e)}},eq=async(e,t)=>{try{let s=await fetch("/api/settings",{cache:"no-store"}),i=(s.ok?await s.json():{}).providerStrategies||{},a={};e&&(a.fallbackStrategy=e),"round-robin"===e&&""!==t&&(a.stickyRoundRobinLimit=Number(t)||3);let l={...i};0===Object.keys(a).length?delete l[r]:l[r]=a,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)}};(0,a.useEffect)(()=>{e_(),eU(),eT()},[e_,eU,eT]),(0,a.useEffect)(()=>{let e=(c.zN[r]||c.fg[r]||c.IS[r]||c.nJ[r])?.modelsFetcher;e&&u(e).then(ex)},[r]);let ez=async(e,t,s=ek)=>{let i=`${s}/${e}`;try{let e=await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:i,alias:t})});if(e.ok)await eU();else{let t=await e.json();alert(t.error||"Failed to set alias")}}catch(e){console.log("Error setting alias:",e)}},eM=async e=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await eU()}catch(e){console.log("Error deleting alias:",e)}},eL=async e=>{if(confirm("Delete this connection?"))try{(await fetch(`/api/providers/${e}`,{method:"DELETE"})).ok&&h(x.filter(t=>t.id!==e))}catch(e){console.log("Error deleting connection:",e)}},eK=()=>{e_(),P(!1)},eF=async e=>{try{(await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,...e})})).ok&&(await e_(),I(!1))}catch(e){console.log("Error saving connection:",e)}},eJ=async e=>{try{(await fetch(`/api/providers/${M.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(await e_(),U(!1))}catch(e){console.log("Error updating connection:",e)}},eW=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&h(s=>s.map(s=>s.id===e?{...s,isActive:t}:s))}catch(e){console.log("Error updating connection status:",e)}},eV=async(e,t)=>{let s=[...x];[s[e],s[t]]=[s[t],s[e]],h(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 e_()}},eH=x.filter(e=>ee.includes(e.id));x.length>0&&(ee.length,x.length),(0,a.useEffect)(()=>{et(e=>e.filter(e=>x.some(t=>t.id===e)))},[x]);let eG=(()=>{if(0===eH.length)return"";let e=new Set(eH.map(e=>e.providerSpecificData?.proxyPoolId||"__none__"));if(1===e.size){let t=[...e][0];if("__none__"===t)return"All selected currently unbound";let s=S.find(e=>e.id===t);return`All selected currently bound to ${s?.name||t}`}return"Selected connections have mixed proxy bindings"})(),eB=()=>{ea||z(!1)},eQ=async()=>{if(0===ee.length)return;let e="__none__"===es?null:es;el(!0);try{let t=[];for(let s of ee)try{let i=await fetch(`/api/providers/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyPoolId:e})});t.push(i.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 e_(),et([]),ei("__none__"),z(!1)}catch(e){console.log("Error applying bulk proxy pool:",e)}finally{el(!1)}},eZ=(0,i.jsx)("div",{className:"flex min-w-0 flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:x.map((e,t)=>(0,i.jsx)("div",{className:"flex min-w-0 items-stretch",children:(0,i.jsx)("div",{className:"flex-1 min-w-0",children:(0,i.jsx)(j,{connection:e,proxyPools:S,isOAuth:ej,isFirst:0===t,isLast:t===x.length-1,onMoveUp:()=>eV(t,t-1),onMoveDown:()=>eV(t,t+1),onToggleActive:t=>eW(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&&h(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:()=>{L(e),U(!0)},onDelete:()=>eL(e.id)})})},e.id))}),eX=[{value:"__none__",label:"None"},...S.map(e=>({value:e.id,label:e.name}))],eY=0===ee.length?"Select one or more connections, then click Proxy Action.":eG,e0=ee.length>0&&!ea,e1=(0,i.jsx)(d.aF,{isOpen:q,onClose:eB,title:`Proxy Action (${ee.length} selected)`,children:(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsx)(d.l6,{label:"Proxy Pool",value:es,onChange:e=>ei(e.target.value),options:eX,placeholder:"None"}),(0,i.jsx)("p",{className:"text-xs text-text-muted",children:eY}),(0,i.jsx)("p",{className:"text-xs text-text-muted",children:"Selecting None will unbind selected connections from proxy pool."}),(0,i.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,i.jsx)(d.$n,{onClick:eQ,fullWidth:!0,disabled:!e0,children:ea?"Applying...":"Apply"}),(0,i.jsx)(d.$n,{onClick:eB,variant:"ghost",fullWidth:!0,disabled:ea,children:"Cancel"})]})]})}),e2=async e=>{if(!Q){Z(e);try{let t=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${e$}/${e}`})}),s=await t.json();H(t=>({...t,[e]:s.ok?"ok":"error"})),B(s.ok?"":s.error||"Model not reachable")}catch{H(t=>({...t,[e]:"error"})),B("Network error")}finally{Z(null)}}};return f?(0,i.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,i.jsx)(d.Qv,{}),(0,i.jsx)(d.Qv,{})]}):ev?(0,i.jsxs)("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:gap-8 sm:px-0",children:[(0,i.jsxs)("div",{className:"min-w-0",children:[(0,i.jsxs)(o(),{href:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),"Back to Providers"]}),(0,i.jsxs)("div",{className:"flex min-w-0 items-center gap-3 sm:gap-4",children:[(0,i.jsx)("div",{className:"flex size-12 shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${ev.color}15`},children:J?(0,i.jsx)("span",{className:"text-sm font-bold",style:{color:ev.color},children:ev.textIcon||ev.id.slice(0,2).toUpperCase()}):(0,i.jsx)(n.default,{src:eC&&ev.apiType?"responses"===ev.apiType?"/providers/oai-r.png":"/providers/oai-cc.png":eS?"/providers/anthropic-m.png":`/providers/${ev.id}.png`,alt:ev.name,width:48,height:48,className:"max-h-12 max-w-12 rounded-lg object-contain",sizes:"48px",onError:()=>W(!0)})}),(0,i.jsxs)("div",{className:"min-w-0",children:[(0,i.jsxs)("div",{className:"flex items-center gap-3 flex-wrap",children:[(0,i.jsx)("h1",{className:"truncate text-2xl font-semibold tracking-tight sm:text-3xl",children:ev.name}),(ev.notice?.apiKeyUrl||ev.notice?.signupUrl||ev.website)&&(0,i.jsxs)("a",{href:ev.notice?.apiKeyUrl||ev.notice?.signupUrl||ev.website,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline inline-flex items-center gap-1",children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"open_in_new"}),ev.notice?.apiKeyUrl?"Get API Key":"Sign up / Learn more"]})]}),(0,i.jsxs)("p",{className:"text-text-muted",children:[x.length," connection",1===x.length?"":"s"]})]})]})]}),ev.deprecated&&(0,i.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,i.jsx)("span",{className:"material-symbols-outlined text-[16px] text-yellow-500 mt-0.5 shrink-0",children:"warning"}),(0,i.jsx)("p",{className:"text-xs text-red-600 dark:text-yellow-400 leading-relaxed",children:ev.deprecationNotice})]}),ev.notice?.text&&!ev.deprecated&&(0,i.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,i.jsx)("span",{className:"material-symbols-outlined text-[16px] text-blue-500 shrink-0",children:"info"}),(0,i.jsx)("p",{className:"min-w-0 flex-1 text-xs leading-relaxed text-blue-600 dark:text-blue-400",children:ev.notice.text}),ev.notice.apiKeyUrl&&(0,i.jsx)("a",{href:ev.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 →"})]}),eA&&v&&(0,i.jsxs)(d.Zp,{children:[(0,i.jsxs)("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,i.jsxs)("div",{className:"min-w-0",children:[(0,i.jsx)("h2",{className:"text-lg font-semibold",children:eS?"Anthropic Compatible Details":"OpenAI Compatible Details"}),(0,i.jsxs)("p",{className:"break-all text-sm text-text-muted",children:[eS?"Messages API":"responses"===v.apiType?"Responses API":"Chat Completions"," \xb7 ",(v.baseUrl||"").replace(/\/$/,""),"/",eS?"messages":"responses"===v.apiType?"responses":"chat/completions"]})]}),(0,i.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,i.jsx)(d.$n,{size:"sm",icon:"add",onClick:()=>I(!0),disabled:x.length>0,className:"w-full sm:w-auto",children:"Add"}),(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>D(!0),className:"w-full sm:w-auto",children:"Edit"}),(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"delete",onClick:async()=>{if(confirm(`Delete this ${eS?"Anthropic":"OpenAI"} Compatible node?`))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"})]})]}),x.length>0&&(0,i.jsx)("p",{className:"text-sm text-text-muted",children:"Only one connection is allowed per compatible node. Add another node if you need more connections."})]}),ew?(0,i.jsx)(d.gw,{providerId:r}):(0,i.jsxs)(d.Zp,{children:[(0,i.jsxs)("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,i.jsx)("h2",{className:"text-lg font-semibold",children:"Connections"}),(0,i.jsx)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",children:(0,i.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,i.jsx)("span",{className:"text-xs text-text-muted font-medium",children:"Round Robin"}),(0,i.jsx)(d.lM,{checked:"round-robin"===er,onChange:e=>{let t=e?"round-robin":null,s=e?en||"1":en;e&&!en&&ed("1"),eo(t),eq(t,s)}}),"round-robin"===er&&(0,i.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,i.jsx)("span",{className:"text-xs text-text-muted",children:"Sticky:"}),(0,i.jsx)("input",{type:"number",min:1,value:en,onChange:e=>{var t;ed(t=e.target.value),eq("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===x.length?(0,i.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,i.jsxs)("div",{className:"flex items-center gap-3",children:[(0,i.jsx)("div",{className:"inline-flex items-center justify-center w-9 h-9 rounded-full bg-primary/10 text-primary shrink-0",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:ej?"lock":"key"})}),(0,i.jsx)("p",{className:"text-sm text-text-muted",children:"No connections yet"})]}),!eA&&(0,i.jsxs)("div",{className:"flex gap-2",children:["iflow"===r&&(0,i.jsx)(d.$n,{size:"sm",icon:"cookie",variant:"secondary",onClick:()=>O(!0),children:"Cookie"}),(0,i.jsx)(d.$n,{size:"sm",icon:"add",onClick:()=>ej?P(!0):I(!0),children:"iflow"===r?"OAuth":"Add Connection"})]})]}):(0,i.jsxs)(i.Fragment,{children:[eZ,!eA&&(0,i.jsxs)("div",{className:"mt-4 grid grid-cols-1 gap-2 sm:flex",children:["iflow"===r&&(0,i.jsx)(d.$n,{size:"sm",icon:"cookie",variant:"secondary",onClick:()=>O(!0),title:"Add connection using browser cookie",className:"w-full sm:w-auto",children:"Cookie"}),(0,i.jsx)(d.$n,{size:"sm",icon:"add",onClick:()=>ej?P(!0):I(!0),className:"w-full sm:w-auto",children:"Add"})]})]})]}),(0,i.jsxs)(d.Zp,{children:[(0,i.jsxs)("div",{className:"mb-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,i.jsx)("h2",{className:"text-lg font-semibold",children:"Available Models"}),!eA&&(e=[...eN,...eu.filter(e=>!eN.some(t=>t.id===e.id))].filter(e=>!e.type||"llm"===e.type).map(e=>e.id).filter(e=>!ef.includes(e)),(0,i.jsxs)("div",{className:"flex gap-2",children:[ef.length>0&&(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"restart_alt",onClick:eR,children:"Active All"}),e.length>0&&(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"block",onClick:()=>eI(e),children:"Disable All"})]}))]}),!!G&&(0,i.jsx)("p",{className:"text-xs text-red-500 mb-3 break-words",children:G}),(()=>{let e,t,s;if(eA)return(0,i.jsx)(b,{providerStorageAlias:e$,providerDisplayAlias:eP,modelAliases:K,copied:eg,onCopy:eb,onSetAlias:ez,onDeleteAlias:eM,connections:x,isAnthropic:eS});let a=[...eN,...eu.filter(e=>!eN.some(t=>t.id===e.id))].filter(e=>!e.type||"llm"===e.type),l=new Set(ef),o=a.filter(e=>!l.has(e.id)),n=a.filter(e=>l.has(e.id)),d=Object.entries(K).filter(([e,t])=>{let s=`${e$}/`;if(!t.startsWith(s))return!1;let i=t.slice(s.length);return ev.passthroughModels?!eN.some(e=>e.id===i):!eN.some(e=>e.id===i)&&e===i}).map(([e,t])=>({id:t.slice(`${e$}/`.length),alias:e,fullModel:t}));return(0,i.jsxs)("div",{className:"flex flex-wrap gap-3",children:[d.map(e=>(0,i.jsx)(y,{model:{id:e.id},fullModel:`${eP}/${e.id}`,alias:e.alias,copied:eg,onCopy:eb,onSetAlias:()=>{},onDeleteAlias:()=>eM(e.alias),testStatus:V[e.id],onTest:x.length>0||ew?()=>e2(e.id):void 0,isTesting:Q===e.id,isCustom:!0,isFree:!1},e.id)),o.map(e=>{let t=`${e$}/${e.id}`,s=`${r}/${e.id}`,a=Object.entries(K).find(([,e])=>e===t||e===s)?.[0];return(0,i.jsx)(y,{model:e,fullModel:`${eP}/${e.id}`,alias:a,copied:eg,onCopy:eb,onSetAlias:t=>ez(e.id,t,e$),onDeleteAlias:()=>eM(a),testStatus:V[e.id],onTest:x.length>0||ew?()=>e2(e.id):void 0,isTesting:Q===e.id,isFree:e.isFree,onDisable:()=>eO(e.id)},e.id)}),(0,i.jsxs)("button",{onClick:()=>Y(!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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"add"}),"Add Model"]}),em.length>0&&(e=new Set(Object.values(K)),t=new Set(eN.map(e=>e.id)),0===(s=em.filter(s=>!e.has(`${e$}/${s.id}`)&&!t.has(s.id))).length?null:(0,i.jsxs)("div",{className:"w-full mt-2",children:[(0,i.jsx)("p",{className:"text-xs text-text-muted mb-2",children:"Suggested free models (≥200k context):"}),(0,i.jsx)("div",{className:"flex flex-wrap gap-2",children:s.map(e=>(0,i.jsxs)("button",{onClick:async()=>{let t=e.id.split("/").pop();await ez(e.id,t,e$)},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,i.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),e.id.split("/").pop()]},e.id))})]})),n.length>0&&(0,i.jsxs)("div",{className:"w-full mt-2",children:[(0,i.jsxs)("p",{className:"text-xs text-text-muted mb-2",children:["Disabled models (",n.length,"):"]}),(0,i.jsx)("div",{className:"flex flex-wrap gap-2",children:n.map(e=>(0,i.jsxs)("button",{onClick:()=>eE(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,i.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),e.id]},e.id))})]})]})})()]}),e1,"kiro"===r?(0,i.jsx)(d.Mh,{isOpen:$,providerInfo:ev,onSuccess:eK,onClose:()=>P(!1)}):"cursor"===r?(0,i.jsx)(d.G9,{isOpen:$,onSuccess:eK,onClose:()=>P(!1)}):"gitlab"===r?(0,i.jsx)(d.vj,{isOpen:$,providerInfo:ev,onSuccess:eK,onClose:()=>P(!1)}):(0,i.jsx)(d.LF,{isOpen:$,provider:r,providerInfo:ev,onSuccess:eK,onClose:()=>P(!1)}),"iflow"===r&&(0,i.jsx)(d.vE,{isOpen:T,onSuccess:()=>{e_(),O(!1)},onClose:()=>O(!1)}),(0,i.jsx)(w,{isOpen:E,provider:r,providerName:ev.name,isCompatible:eA,isAnthropic:eS,authType:ev?.authType,authHint:ev?.authHint,website:ev?.website,proxyPools:S,onSave:eF,onClose:()=>I(!1)}),(0,i.jsx)(d.wI,{isOpen:R,connection:M,proxyPools:S,onSave:eJ,onClose:()=>U(!1)}),eA&&(0,i.jsx)(N,{isOpen:_,node:v,onSave:eD,onClose:()=>D(!1),isAnthropic:eS}),!eA&&(0,i.jsx)(k,{isOpen:X,providerAlias:e$,providerDisplayAlias:eP,onSave:async e=>{let t=ev?.passthroughModels?e.split("/").pop():e;await ez(e,t,e$),Y(!1)},onClose:()=>Y(!1)})]}):(0,i.jsxs)("div",{className:"text-center py-20",children:[(0,i.jsx)("p",{className:"text-text-muted",children:"Provider not found"}),(0,i.jsx)(o(),{href:"/dashboard/providers",className:"text-primary mt-4 inline-block",children:"Back to Providers"})]})}y.propTypes={model:f().shape({id:f().string.isRequired}).isRequired,fullModel:f().string.isRequired,alias:f().string,copied:f().string,onCopy:f().func.isRequired,testStatus:f().oneOf(["ok","error"]),isCustom:f().bool,isFree:f().bool,onDeleteAlias:f().func,onTest:f().func,isTesting:f().bool,onDisable:f().func},f().string.isRequired,f().string.isRequired,f().string,f().func.isRequired,f().func.isRequired,f().func,f().oneOf(["ok","error"]),f().bool,f().string.isRequired,f().object.isRequired,f().string,f().func.isRequired,f().func.isRequired,f().func.isRequired,b.propTypes={providerStorageAlias:f().string.isRequired,providerDisplayAlias:f().string.isRequired,modelAliases:f().object.isRequired,copied:f().string,onCopy:f().func.isRequired,onSetAlias:f().func.isRequired,onDeleteAlias:f().func.isRequired,connections:f().arrayOf(f().shape({id:f().string,isActive:f().bool})).isRequired,isAnthropic:f().bool},v.propTypes={until:f().string.isRequired},j.propTypes={connection:f().shape({id:f().string,name:f().string,email:f().string,displayName:f().string,modelLockUntil:f().string,testStatus:f().string,isActive:f().bool,lastError:f().string,priority:f().number,globalPriority:f().number}).isRequired,proxyPools:f().arrayOf(f().shape({id:f().string,name:f().string,proxyUrl:f().string,noProxy:f().string,isActive:f().bool})),isOAuth:f().bool.isRequired,isFirst:f().bool.isRequired,isLast:f().bool.isRequired,onMoveUp:f().func.isRequired,onMoveDown:f().func.isRequired,onToggleActive:f().func.isRequired,onUpdateProxy:f().func,onEdit:f().func.isRequired,onDelete:f().func.isRequired},w.propTypes={isOpen:f().bool.isRequired,provider:f().string,providerName:f().string,isCompatible:f().bool,isAnthropic:f().bool,authType:f().string,authHint:f().string,website:f().string,proxyPools:f().arrayOf(f().shape({id:f().string,name:f().string})),onSave:f().func.isRequired,onClose:f().func.isRequired},N.propTypes={isOpen:f().bool.isRequired,node:f().shape({id:f().string,name:f().string,prefix:f().string,apiType:f().string,baseUrl:f().string}),onSave:f().func.isRequired,onClose:f().func.isRequired,isAnthropic:f().bool},k.propTypes={isOpen:f().bool.isRequired,providerAlias:f().string.isRequired,providerDisplayAlias:f().string.isRequired,onSave:f().func.isRequired,onClose:f().func.isRequired}},53655:(e,t,s)=>{Promise.resolve().then(s.bind(s,17721))}},e=>{e.O(0,[2574,3862,1051,5772,1321,5497,8441,3794,7358],()=>e(e.s=53655)),_N_E=e.O()}]);
package/app/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "9router-app",
3
- "version": "0.4.18",
3
+ "version": "0.4.19",
4
4
  "description": "9Router web dashboard",
5
5
  "private": true,
6
6
  "scripts": {
@@ -7,6 +7,7 @@ const TOOL_HOSTS = {
7
7
  copilot: ["api.individual.githubcopilot.com"],
8
8
  kiro: ["q.us-east-1.amazonaws.com", "codewhisperer.us-east-1.amazonaws.com"],
9
9
  cursor: ["api2.cursor.sh"],
10
+ openrouter: ["openrouter.ai", "api.openrouter.ai"],
10
11
  };
11
12
 
12
13
  module.exports = { TOOL_HOSTS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yina-npm/openrouterx",
3
- "version": "0.4.18",
3
+ "version": "0.4.19",
4
4
  "description": "openrouterX CLI - Start and manage 9Router server",
5
5
  "bin": {
6
6
  "openrouterX": "./cli.js"
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2134],{17721:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>C});var i=s(95155),a=s(12115),l=s(73321),r=s(98500),o=s.n(r),n=s(5772),d=s(35497),c=s(52679),p=s(28777),m=s(11059);let x=new Map;async function u(e){if(!e?.url||!e?.type)return[];let t=x.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 i=(await s.json()).data??[];return x.set(e.url,{data:i,expiresAt:Date.now()+6e5}),i}catch{return[]}}var h=s(14051),f=s.n(h);function y({model:e,fullModel:t,alias:s,copied:a,onCopy:l,testStatus:r,isCustom:o,isFree:n,onDeleteAlias:d,onTest:c,isTesting:p,onDisable:m}){let x="ok"===r?"#22c55e":"error"===r?"#ef4444":void 0;return(0,i.jsx)("div",{className:`group min-w-0 max-w-full rounded-lg border px-3 py-2 ${"ok"===r?"border-green-500/40":"error"===r?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:(0,i.jsxs)("div",{className:"flex min-w-0 items-start gap-2 sm:items-center",children:[(0,i.jsx)("span",{className:"material-symbols-outlined shrink-0 text-base",style:x?{color:x}:void 0,children:"ok"===r?"check_circle":"error"===r?"cancel":"smart_toy"}),(0,i.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[(0,i.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:t}),e.name&&(0,i.jsx)("span",{className:"truncate pl-1 text-[9px] italic text-text-muted/70",children:e.name})]}),c&&(0,i.jsxs)("div",{className:"relative shrink-0 group/btn",children:[(0,i.jsx)("button",{onClick:c,disabled:p,className:`rounded p-0.5 text-text-muted transition-opacity hover:bg-sidebar hover:text-primary ${p?"opacity-100":"opacity-100 sm:opacity-0 sm:group-hover:opacity-100"}`,children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",style:p?{animation:"spin 1s linear infinite"}:void 0,children:p?"progress_activity":"science"})}),(0,i.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:p?"Testing...":"Test"})]}),(0,i.jsxs)("div",{className:"relative shrink-0 group/btn",children:[(0,i.jsx)("button",{onClick:()=>l(t,`model-${e.id}`),className:"rounded p-0.5 text-text-muted hover:bg-sidebar hover:text-primary",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:a===`model-${e.id}`?"check":"content_copy"})}),(0,i.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:a===`model-${e.id}`?"Copied!":"Copy"})]}),o?(0,i.jsx)("button",{onClick:d,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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})}):m?(0,i.jsx)("button",{onClick:m,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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"})}):null]})})}function g({modelId:e,fullModel:t,copied:s,onCopy:a,onDeleteAlias:l,onTest:r,testStatus:o,isTesting:n}){let d="ok"===o?"#22c55e":"error"===o?"#ef4444":void 0;return(0,i.jsxs)("div",{className:`flex items-center gap-3 p-3 rounded-lg border ${"ok"===o?"border-green-500/40":"error"===o?"border-red-500/40":"border-border"} hover:bg-sidebar/50`,children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",style:d?{color:d}:void 0,children:"ok"===o?"check_circle":"error"===o?"cancel":"smart_toy"}),(0,i.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,i.jsx)("p",{className:"text-sm font-medium truncate",children:e}),(0,i.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,i.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:t}),(0,i.jsxs)("div",{className:"relative group/btn",children:[(0,i.jsx)("button",{onClick:()=>a(t,`model-${e}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:s===`model-${e}`?"check":"content_copy"})}),(0,i.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,i.jsxs)("div",{className:"relative group/btn",children:[(0,i.jsx)("button",{onClick:r,disabled:n,className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary transition-colors",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",style:n?{animation:"spin 1s linear infinite"}:void 0,children:n?"progress_activity":"science"})}),(0,i.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:n?"Testing...":"Test"})]})]})]}),(0,i.jsx)("button",{onClick:l,className:"p-1 hover:bg-red-50 rounded text-red-500",title:"Remove model",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})}function b({providerStorageAlias:e,providerDisplayAlias:t,modelAliases:s,copied:l,onCopy:r,onSetAlias:o,onDeleteAlias:n,connections:c,isAnthropic:p}){let[m,x]=(0,a.useState)(""),[u,h]=(0,a.useState)(!1),[f,y]=(0,a.useState)(!1),[v,j]=(0,a.useState)(null),[N,w]=(0,a.useState)({}),k=async t=>{if(!v){j(t);try{let s=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${e}/${t}`})}),i=await s.json();w(e=>({...e,[t]:i.ok?"ok":"error"}))}catch{w(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=i=>{let a,l=`${e}/${i}`;if(Object.values(s).includes(l))return null;let r=(a=i.split("/"))[a.length-1];if(!s[r])return r;let o=`${t}-${r}`;return s[o]?null:o},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 o(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){y(!0);try{let s=await fetch(`/api/providers/${t.id}/models`),i=await s.json();if(!s.ok)return void alert(i.error||"Failed to import models");let a=i.models||[];if(0===a.length)return void alert("No models returned from /models.");let l=0;for(let t of a){let s=t.id||t.name||t.model;if(!s)continue;let i=S(s);i&&(await o(s,i,e),l+=1)}0===l&&alert("No new models were added.")}catch(e){console.log("Error importing models:",e)}finally{y(!1)}}},T=c.some(e=>!1!==e.isActive);return(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsxs)("p",{className:"text-sm text-text-muted",children:["Add ",p?"Anthropic":"OpenAI","-compatible models manually or import them from the /models endpoint."]}),(0,i.jsxs)("div",{className:"flex items-end gap-2 flex-wrap",children:[(0,i.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,i.jsx)("label",{htmlFor:"new-compatible-model-input",className:"text-xs text-text-muted mb-1 block",children:"Model ID"}),(0,i.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,i.jsx)(d.$n,{size:"sm",icon:"add",onClick:A,disabled:!m.trim()||u,children:u?"Adding...":"Add"}),(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"download",onClick:$,disabled:!T||f,children:f?"Importing...":"Import from /models"})]}),!T&&(0,i.jsx)("p",{className:"text-xs text-text-muted",children:"Add a connection to enable importing models."}),C.length>0&&(0,i.jsx)("div",{className:"flex flex-col gap-3",children:C.map(({modelId:e,fullModel:s,alias:a})=>(0,i.jsx)(g,{modelId:e,fullModel:`${t}/${e}`,copied:l,onCopy:r,onDeleteAlias:()=>n(a),onTest:c.length>0?()=>k(e):void 0,testStatus:N[e],isTesting:v===e},s))})]})}function v({until:e}){let[t,s]=(0,a.useState)("");return((0,a.useEffect)(()=>{let t=()=>{let t=new Date(e).getTime()-Date.now();if(t<=0)return void s("");let i=Math.floor(t/1e3);if(i<60)s(`${i}s`);else if(i<3600)s(`${Math.floor(i/60)}m ${i%60}s`);else{let e=Math.floor(i/3600),t=Math.floor(i%3600/60);s(`${e}h ${t}m`)}};t();let i=setInterval(t,1e3);return()=>clearInterval(i)},[e]),t)?(0,i.jsxs)("span",{className:"text-xs text-orange-500 font-mono",children:["⏱ ",t]}):null}function j({connection:e,proxyPools:t,isOAuth:s,isFirst:l,isLast:r,onMoveUp:o,onMoveDown:n,onToggleActive:c,onUpdateProxy:p,onEdit:m,onDelete:x}){let[u,h]=(0,a.useState)(!1),[f,y]=(0,a.useState)(!1),g=(0,a.useRef)(null),b=new Map((t||[]).map(e=>[e.id,e])),N=e.providerSpecificData?.proxyPoolId||null,w=N?b.get(N):null,k=e.providerSpecificData?.connectionProxyEnabled===!0&&!!e.providerSpecificData?.connectionProxyUrl,C=!!N||k,S=w?`Pool: ${w.name}`:N?`Pool: ${N} (inactive/missing)`:k?`Legacy: ${e.providerSpecificData?.connectionProxyUrl}`:"",A="";if(w?.proxyUrl||e.providerSpecificData?.connectionProxyUrl){let t=w?.proxyUrl||e.providerSpecificData?.connectionProxyUrl;try{let e=new URL(t);A=`${e.protocol}//${e.hostname}${e.port?`:${e.port}`:""}`}catch{A=t}}let $=w?.noProxy||e.providerSpecificData?.connectionNoProxy||"",T="default";w?.isActive===!0?T="success":(N||k)&&(T="error"),(0,a.useEffect)(()=>{if(!u)return;let e=e=>{g.current&&!g.current.contains(e.target)&&h(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[u]);let P=async e=>{y(!0);try{await p("__none__"===e?null:e)}finally{y(!1),h(!1)}},O=e=>"string"==typeof e&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),E=s?O(e.email)?e.email:O(e.name)?e.name:e.name||e.email||e.displayName||"OAuth Account":e.name,[I,R]=(0,a.useState)(!1),_=Object.entries(e).filter(([e])=>e.startsWith("modelLock_")).map(([,e])=>e).filter(e=>!!e).sort()[0]||null;(0,a.useEffect)(()=>{let t=()=>{R(!!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=_?setInterval(t,1e3):null;return()=>{s&&clearInterval(s)}},[_]);let U="unavailable"!==e.testStatus||I?e.testStatus:"active";return(0,i.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,i.jsxs)("div",{className:"flex min-w-0 flex-1 items-start gap-2 sm:items-center sm:gap-3",children:[(0,i.jsxs)("div",{className:"flex shrink-0 flex-col",children:[(0,i.jsx)("button",{onClick:o,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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_up"})}),(0,i.jsx)("button",{onClick:n,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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_down"})})]}),(0,i.jsx)("span",{className:"material-symbols-outlined shrink-0 text-base text-text-muted",children:s?"lock":"key"}),(0,i.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,i.jsx)("p",{className:"text-sm font-medium truncate",children:E}),(0,i.jsxs)("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1.5 sm:gap-2",children:[(0,i.jsx)(d.Ex,{variant:!1===e.isActive?"default":"active"===U||"success"===U?"success":"error"===U||"expired"===U||"unavailable"===U?"error":"default",size:"sm",dot:!0,children:!1===e.isActive?"disabled":U||"Unknown"}),C&&(0,i.jsx)(d.Ex,{variant:T,size:"sm",children:"Proxy"}),I&&!1!==e.isActive&&(0,i.jsx)(v,{until:_}),e.lastError&&!1!==e.isActive&&(0,i.jsx)("span",{className:"max-w-full truncate text-xs text-red-500 sm:max-w-[300px]",title:e.lastError,children:e.lastError}),(0,i.jsxs)("span",{className:"text-xs text-text-muted",children:["#",e.priority]}),e.globalPriority&&(0,i.jsxs)("span",{className:"text-xs text-text-muted",children:["Auto: ",e.globalPriority]})]}),C&&(0,i.jsxs)("div",{className:"mt-1 flex items-center gap-2 flex-wrap",children:[(0,i.jsx)("span",{className:"max-w-full truncate text-[11px] text-text-muted sm:max-w-[420px]",title:S,children:S}),A&&(0,i.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}),$&&(0,i.jsxs)("span",{className:"max-w-full truncate text-[11px] text-text-muted sm:max-w-[320px]",title:$,children:["no_proxy: ",$]})]})]})]}),(0,i.jsxs)("div",{className:"flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-end",children:[(0,i.jsxs)("div",{className:"grid flex-1 grid-cols-3 gap-1 sm:flex sm:flex-none",children:[(t||[]).length>0&&(0,i.jsxs)("div",{className:"relative",ref:g,children:[(0,i.jsxs)("button",{onClick:()=>h(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 ${C?"text-primary":"text-text-muted hover:text-primary"}`,disabled:f,children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:f?"progress_activity":"lan"}),(0,i.jsx)("span",{className:"text-[10px] leading-tight",children:"Proxy"})]}),u&&(0,i.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,i.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,i.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,i.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,i.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"edit"}),(0,i.jsx)("span",{className:"text-[10px] leading-tight",children:"Edit"})]}),(0,i.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,i.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"delete"}),(0,i.jsx)("span",{className:"text-[10px] leading-tight",children:"Delete"})]})]}),(0,i.jsx)(d.lM,{size:"sm",checked:e.isActive??!0,onChange:c,title:e.isActive??!0?"Disable connection":"Enable connection"})]})]})}function N({isOpen:e,provider:t,providerName:s,isCompatible:l,isAnthropic:r,authType:o,authHint:n,website:c,proxyPools:p,onSave:m,onClose:x}){let u="__none__",h="ollama-local"===t,f="cookie"===o,y=f?"Cookie Value":"API Key",g="azure"===t,b="cloudflare-ai"===t,[v,j]=(0,a.useState)({name:"",apiKey:"",priority:1,proxyPoolId:u,ollamaHostUrl:""}),[w,k]=(0,a.useState)({azureEndpoint:"",apiVersion:"2024-10-01-preview",deployment:"",organization:""}),[C,S]=(0,a.useState)({accountId:""}),[A,$]=(0,a.useState)(!1),[T,P]=(0,a.useState)(null),[O,E]=(0,a.useState)(!1),I=()=>h&&v.ollamaHostUrl.trim()?{baseUrl:v.ollamaHostUrl.trim()}:g?{azureEndpoint:w.azureEndpoint,apiVersion:w.apiVersion,deployment:w.deployment,organization:w.organization}:b?{accountId:C.accountId}:void 0,R=async()=>{$(!0);try{let e=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:v.apiKey,providerSpecificData:I()})}),s=await e.json();P(s.valid?"success":"failed")}catch{P("failed")}finally{$(!1)}},_=async()=>{if(t&&(h||v.apiKey)&&(h||v.name)){E(!0);try{let e=!1;try{$(!0),P(null);let s=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,apiKey:v.apiKey,providerSpecificData:I()})});e=!!(await s.json()).valid,P(e?"success":"failed")}catch{P("failed")}finally{$(!1)}await m({name:v.name||(h?"Ollama Local":""),apiKey:v.apiKey,priority:v.priority,proxyPoolId:v.proxyPoolId===u?null:v.proxyPoolId,testStatus:e?"active":"unknown",providerSpecificData:I()})}finally{E(!1)}}};return t?(0,i.jsx)(d.aF,{isOpen:e,title:`Add ${s||t} ${y}`,onClose:x,children:(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsx)(d.pd,{label:"Name",value:v.name,onChange:e=>j({...v,name:e.target.value}),placeholder:h?"Ollama Local":"Production Key"}),h&&(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.pd,{label:"Ollama Host URL",value:v.ollamaHostUrl,onChange:e=>j({...v,ollamaHostUrl:e.target.value}),placeholder:"http://localhost:11434",className:"flex-1"}),(0,i.jsx)("div",{className:"pt-6",children:(0,i.jsx)(d.$n,{onClick:R,disabled:A||O,variant:"secondary",children:A?"Checking...":"Check"})})]}),!h&&(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.pd,{label:y,type:f?"text":"password",value:v.apiKey,onChange:e=>j({...v,apiKey:e.target.value}),placeholder:f?"grok-web"===t?"sso=xxxxx... or just the raw value":"eyJhbGciOi...":"",className:"flex-1"}),(0,i.jsx)("div",{className:"pt-6",children:(0,i.jsx)(d.$n,{onClick:R,disabled:!v.apiKey||A||O,variant:"secondary",children:A?"Checking...":"Check"})})]}),f&&n&&(0,i.jsxs)("p",{className:"text-xs text-text-muted",children:[n,c&&(0,i.jsxs)(i.Fragment,{children:[" ",(0,i.jsxs)("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:["Open ",c.replace(/^https?:\/\//,"")]})]})]}),h&&(0,i.jsxs)("p",{className:"text-xs text-text-muted",children:["Leave blank to use ",(0,i.jsx)("code",{children:"http://localhost:11434"}),". For remote Ollama, enter the full host URL (e.g. ",(0,i.jsx)("code",{children:"http://192.168.1.10:11434"}),")."]}),T&&(0,i.jsx)(d.Ex,{variant:"success"===T?"success":"error",children:"success"===T?"Valid":"Invalid"}),l&&(0,i.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.`}),b&&(0,i.jsxs)("div",{className:"bg-sidebar/50 p-4 rounded-lg border border-accent/20",children:[(0,i.jsx)("h3",{className:"font-semibold mb-3 text-sm",children:"Cloudflare Workers AI"}),(0,i.jsx)(d.pd,{label:"Account ID",value:C.accountId,onChange:e=>S({...C,accountId:e.target.value}),placeholder:"abc123def456..."}),(0,i.jsxs)("p",{className:"text-xs text-text-muted mt-2",children:["Find your Account ID in the right sidebar of ",(0,i.jsx)("a",{href:"https://dash.cloudflare.com",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"dash.cloudflare.com"})]})]}),g&&(0,i.jsxs)("div",{className:"bg-sidebar/50 p-4 rounded-lg border border-accent/20",children:[(0,i.jsx)("h3",{className:"font-semibold mb-3 text-sm",children:"Azure OpenAI Configuration"}),(0,i.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,i.jsx)(d.pd,{label:"Azure Endpoint",value:w.azureEndpoint,onChange:e=>k({...w,azureEndpoint:e.target.value}),placeholder:"https://your-resource.openai.azure.com"}),(0,i.jsx)(d.pd,{label:"Deployment Name",value:w.deployment,onChange:e=>k({...w,deployment:e.target.value}),placeholder:"gpt-4"}),(0,i.jsx)(d.pd,{label:"API Version",value:w.apiVersion,onChange:e=>k({...w,apiVersion:e.target.value}),placeholder:"2024-10-01-preview"}),(0,i.jsx)(d.pd,{label:"Organization",value:w.organization,onChange:e=>k({...w,organization:e.target.value}),placeholder:"Organization ID"})]})]}),(0,i.jsx)(d.pd,{label:"Priority",type:"number",value:v.priority,onChange:e=>j({...v,priority:Number.parseInt(e.target.value)||1})}),(0,i.jsx)(d.l6,{label:"Proxy Pool",value:v.proxyPoolId,onChange:e=>j({...v,proxyPoolId:e.target.value}),options:[{value:u,label:"None"},...(p||[]).map(e=>({value:e.id,label:e.name}))],placeholder:"None"}),0===(p||[]).length&&(0,i.jsx)("p",{className:"text-xs text-text-muted",children:"No active proxy pools available. Create one in Proxy Pools page first."}),(0,i.jsx)("p",{className:"text-xs text-text-muted",children:"Legacy manual proxy fields are still accepted by API for backward compatibility."}),(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.$n,{onClick:_,fullWidth:!0,disabled:O||!h&&(!v.name||!v.apiKey)||g&&(!w.azureEndpoint||!w.deployment||!w.organization)||b&&!C.accountId,children:O?"Saving...":"Save"}),(0,i.jsx)(d.$n,{onClick:x,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}function w({isOpen:e,node:t,onSave:s,onClose:l,isAnthropic:r}){let[o,n]=(0,a.useState)({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[c,p]=(0,a.useState)(!1),[m,x]=(0,a.useState)(""),[u,h]=(0,a.useState)(""),[f,y]=(0,a.useState)(!1),[g,b]=(0,a.useState)(null);(0,a.useEffect)(()=>{t&&n({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(o.name.trim()&&o.prefix.trim()&&o.baseUrl.trim()){p(!0);try{let e={name:o.name,prefix:o.prefix,baseUrl:o.baseUrl};r||(e.apiType=o.apiType),await s(e)}finally{p(!1)}}},j=async()=>{y(!0);try{let e=await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:o.baseUrl,apiKey:m,type:r?"anthropic-compatible":"openai-compatible",modelId:u.trim()||void 0})}),t=await e.json();b(t.valid?"success":"failed")}catch{b("failed")}finally{y(!1)}};return t?(0,i.jsx)(d.aF,{isOpen:e,title:`Edit ${r?"Anthropic":"OpenAI"} Compatible`,onClose:l,children:(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsx)(d.pd,{label:"Name",value:o.name,onChange:e=>n({...o,name:e.target.value}),placeholder:`${r?"Anthropic":"OpenAI"} Compatible (Prod)`,hint:"Required. A friendly label for this node."}),(0,i.jsx)(d.pd,{label:"Prefix",value:o.prefix,onChange:e=>n({...o,prefix:e.target.value}),placeholder:r?"ac-prod":"oc-prod",hint:"Required. Used as the provider prefix for model IDs."}),!r&&(0,i.jsx)(d.l6,{label:"API Type",options:[{value:"chat",label:"Chat Completions"},{value:"responses",label:"Responses API"}],value:o.apiType,onChange:e=>n({...o,apiType:e.target.value})}),(0,i.jsx)(d.pd,{label:"Base URL",value:o.baseUrl,onChange:e=>n({...o,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,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.pd,{label:"API Key (for Check)",type:"password",value:m,onChange:e=>x(e.target.value),className:"flex-1"}),(0,i.jsx)("div",{className:"pt-6",children:(0,i.jsx)(d.$n,{onClick:j,disabled:!m||f||!o.baseUrl.trim(),variant:"secondary",children:f?"Checking...":"Check"})})]}),(0,i.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."}),g&&(0,i.jsx)(d.Ex,{variant:"success"===g?"success":"error",children:"success"===g?"Valid":"Invalid"}),(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)(d.$n,{onClick:v,fullWidth:!0,disabled:!o.name.trim()||!o.prefix.trim()||!o.baseUrl.trim()||c,children:c?"Saving...":"Save"}),(0,i.jsx)(d.$n,{onClick:l,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}function k({isOpen:e,providerAlias:t,providerDisplayAlias:s,onSave:l,onClose:r}){let[o,n]=(0,a.useState)(""),[c,p]=(0,a.useState)(null),[m,x]=(0,a.useState)(""),[u,h]=(0,a.useState)(!1);(0,a.useEffect)(()=>{e&&(n(""),p(null),x(""))},[e]);let f=e=>{let s=`${t}/`;return e.startsWith(s)?e.slice(s.length):e},y=async()=>{let e=f(o.trim());if(e){p("testing"),x("");try{let s=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${t}/${e}`})}),i=await s.json();p(i.ok?"ok":"error"),x(i.error||"")}catch(e){p("error"),x(e.message)}}},g=async()=>{let e=f(o.trim());if(e&&!u){h(!0);try{await l(e)}finally{h(!1)}}};return(0,i.jsx)(d.aF,{isOpen:e,onClose:r,title:"Add Custom Model",children:(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{className:"text-sm font-medium mb-1.5 block",children:"Model ID"}),(0,i.jsxs)("div",{className:"flex gap-2",children:[(0,i.jsx)("input",{type:"text",value:o,onChange:e=>{n(e.target.value),p(null),x("")},onKeyDown:e=>{"Enter"===e.key&&y()},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,i.jsx)(d.$n,{variant:"secondary",icon:"science",loading:"testing"===c,onClick:y,disabled:!o.trim()||"testing"===c,children:"testing"===c?"Testing...":"Test"})]}),(0,i.jsxs)("p",{className:"text-xs text-text-muted mt-1",children:["Sent to provider as: ",(0,i.jsx)("code",{className:"font-mono bg-sidebar px-1 rounded",children:f(o.trim())||"model-id"})]})]}),"ok"===c&&(0,i.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600",children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-base",children:"check_circle"}),"Model is reachable"]}),"error"===c&&(0,i.jsxs)("div",{className:"flex items-start gap-2 text-sm text-red-500",children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-base shrink-0",children:"cancel"}),(0,i.jsx)("span",{children:m||"Model not reachable"})]}),(0,i.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,i.jsx)(d.$n,{onClick:r,variant:"ghost",fullWidth:!0,size:"sm",children:"Cancel"}),(0,i.jsx)(d.$n,{onClick:g,fullWidth:!0,size:"sm",disabled:!o.trim()||u,children:u?"Adding...":"Add Model"})]})]})})}function C(){let e,t=(0,l.useParams)(),s=(0,l.useRouter)(),r=t.id,[x,h]=(0,a.useState)([]),[f,g]=(0,a.useState)(!0),[v,C]=(0,a.useState)(null),[S,A]=(0,a.useState)([]),[$,T]=(0,a.useState)(!1),[P,O]=(0,a.useState)(!1),[E,I]=(0,a.useState)(!1),[R,_]=(0,a.useState)(!1),[U,D]=(0,a.useState)(!1),[q,z]=(0,a.useState)(!1),[L,M]=(0,a.useState)(null),[K,F]=(0,a.useState)({}),[J,W]=(0,a.useState)(!1),[V,H]=(0,a.useState)({}),[G,B]=(0,a.useState)(""),[Q,Z]=(0,a.useState)(null),[X,Y]=(0,a.useState)(!1),[ee,et]=(0,a.useState)([]),[es,ei]=(0,a.useState)("__none__"),[ea,el]=(0,a.useState)(!1),[er,eo]=(0,a.useState)(null),[en,ed]=(0,a.useState)(""),[ec,ep]=(0,a.useState)("auto"),[em,ex]=(0,a.useState)([]),[eu,eh]=(0,a.useState)([]),[ef,ey]=(0,a.useState)([]),{copied:eg,copy:eb}=(0,m.C)(),ev=v?{id:v.id,name:v.name||("anthropic-compatible"===v.type?"Anthropic Compatible":"OpenAI Compatible"),color:"anthropic-compatible"===v.type?"#D97757":"#10A37F",textIcon:"anthropic-compatible"===v.type?"AC":"OC",apiType:v.apiType,baseUrl:v.baseUrl,type:v.type}:c.zN[r]||c.fg[r]||c.IS[r]||c.nJ[r]||c.br[r],ej=!!c.zN[r]||!!c.IS[r],eN=!!c.IS[r]?.noAuth,ew=(0,p.KC)(r),ek=(0,c.wG)(r),eC=(0,c.mq)(r),eS=(0,c.gb)(r),eA=eC||eS;c.Q2[r]?.thinkingConfig||c.s9.extended;let e$=eA?r:ek,eT=eA?v?.prefix||r:ek,eP=(0,a.useCallback)(async()=>{try{let e=await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(e$)}`,{cache:"no-store"}),t=await e.json();e.ok&&ey(t.ids||[])}catch(e){console.log("Error fetching disabled models:",e)}},[e$]),eO=async e=>{try{(await fetch("/api/models/disabled",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:e$,ids:[e]})})).ok&&await eP()}catch(e){console.log("Error disabling model:",e)}},eE=async e=>{try{(await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(e$)}&id=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await eP()}catch(e){console.log("Error enabling model:",e)}},eI=async e=>{if(e.length&&confirm(`Disable all ${e.length} model(s)?`))try{(await fetch("/api/models/disabled",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:e$,ids:e})})).ok&&await eP()}catch(e){console.log("Error disabling all models:",e)}},eR=async()=>{try{(await fetch(`/api/models/disabled?providerAlias=${encodeURIComponent(e$)}`,{method:"DELETE"})).ok&&await eP()}catch(e){console.log("Error enabling all models:",e)}},e_=(0,a.useCallback)(async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&F(t.aliases||{})}catch(e){console.log("Error fetching aliases:",e)}},[]);(0,a.useEffect)(()=>{"kilocode"===r&&fetch("/api/providers/kilo/free-models").then(e=>e.json()).then(e=>{e.models?.length&&eh(e.models)}).catch(()=>{})},[r]);let eU=(0,a.useCallback)(async()=>{try{let[e,t,s,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"})]),a=await e.json(),l=await t.json(),o=await s.json(),n=i.ok?await i.json():{};if(e.ok){let e=(a.connections||[]).filter(e=>e.provider===r);h(e)}s.ok&&A(o.proxyPools||[]);let d=(n.providerStrategies||{})[r]||{};eo(d.fallbackStrategy||null),ed(null!=d.stickyRoundRobinLimit?String(d.stickyRoundRobinLimit):"1");let c=(n.providerThinking||{})[r]||{};if(ep(c.mode||"auto"),t.ok){let e=(l.nodes||[]).find(e=>e.id===r)||null;if(!e&&eA)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}C(e)}}catch(e){console.log("Error fetching connections:",e)}finally{g(!1)}},[r,eA]),eD=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&&(C(s.node),await eU(),D(!1))}catch(e){console.log("Error updating provider node:",e)}},eq=async(e,t)=>{try{let s=await fetch("/api/settings",{cache:"no-store"}),i=(s.ok?await s.json():{}).providerStrategies||{},a={};e&&(a.fallbackStrategy=e),"round-robin"===e&&""!==t&&(a.stickyRoundRobinLimit=Number(t)||3);let l={...i};0===Object.keys(a).length?delete l[r]:l[r]=a,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)}};(0,a.useEffect)(()=>{eU(),e_(),eP()},[eU,e_,eP]),(0,a.useEffect)(()=>{let e=(c.zN[r]||c.fg[r]||c.IS[r]||c.nJ[r])?.modelsFetcher;e&&u(e).then(ex)},[r]);let ez=async(e,t,s=ek)=>{let i=`${s}/${e}`;try{let e=await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:i,alias:t})});if(e.ok)await e_();else{let t=await e.json();alert(t.error||"Failed to set alias")}}catch(e){console.log("Error setting alias:",e)}},eL=async e=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&await e_()}catch(e){console.log("Error deleting alias:",e)}},eM=async e=>{if(confirm("Delete this connection?"))try{(await fetch(`/api/providers/${e}`,{method:"DELETE"})).ok&&h(x.filter(t=>t.id!==e))}catch(e){console.log("Error deleting connection:",e)}},eK=()=>{eU(),T(!1)},eF=async e=>{try{(await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,...e})})).ok&&(await eU(),I(!1))}catch(e){console.log("Error saving connection:",e)}},eJ=async e=>{try{(await fetch(`/api/providers/${L.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(await eU(),_(!1))}catch(e){console.log("Error updating connection:",e)}},eW=async(e,t)=>{try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&h(s=>s.map(s=>s.id===e?{...s,isActive:t}:s))}catch(e){console.log("Error updating connection status:",e)}},eV=async(e,t)=>{let s=[...x];[s[e],s[t]]=[s[t],s[e]],h(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 eU()}},eH=x.filter(e=>ee.includes(e.id));x.length>0&&(ee.length,x.length),(0,a.useEffect)(()=>{et(e=>e.filter(e=>x.some(t=>t.id===e)))},[x]);let eG=(()=>{if(0===eH.length)return"";let e=new Set(eH.map(e=>e.providerSpecificData?.proxyPoolId||"__none__"));if(1===e.size){let t=[...e][0];if("__none__"===t)return"All selected currently unbound";let s=S.find(e=>e.id===t);return`All selected currently bound to ${s?.name||t}`}return"Selected connections have mixed proxy bindings"})(),eB=()=>{ea||z(!1)},eQ=async()=>{if(0===ee.length)return;let e="__none__"===es?null:es;el(!0);try{let t=[];for(let s of ee)try{let i=await fetch(`/api/providers/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyPoolId:e})});t.push(i.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 eU(),et([]),ei("__none__"),z(!1)}catch(e){console.log("Error applying bulk proxy pool:",e)}finally{el(!1)}},eZ=(0,i.jsx)("div",{className:"flex min-w-0 flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:x.map((e,t)=>(0,i.jsx)("div",{className:"flex min-w-0 items-stretch",children:(0,i.jsx)("div",{className:"flex-1 min-w-0",children:(0,i.jsx)(j,{connection:e,proxyPools:S,isOAuth:ej,isFirst:0===t,isLast:t===x.length-1,onMoveUp:()=>eV(t,t-1),onMoveDown:()=>eV(t,t+1),onToggleActive:t=>eW(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&&h(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:()=>{M(e),_(!0)},onDelete:()=>eM(e.id)})})},e.id))}),eX=[{value:"__none__",label:"None"},...S.map(e=>({value:e.id,label:e.name}))],eY=0===ee.length?"Select one or more connections, then click Proxy Action.":eG,e0=ee.length>0&&!ea,e1=(0,i.jsx)(d.aF,{isOpen:q,onClose:eB,title:`Proxy Action (${ee.length} selected)`,children:(0,i.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,i.jsx)(d.l6,{label:"Proxy Pool",value:es,onChange:e=>ei(e.target.value),options:eX,placeholder:"None"}),(0,i.jsx)("p",{className:"text-xs text-text-muted",children:eY}),(0,i.jsx)("p",{className:"text-xs text-text-muted",children:"Selecting None will unbind selected connections from proxy pool."}),(0,i.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,i.jsx)(d.$n,{onClick:eQ,fullWidth:!0,disabled:!e0,children:ea?"Applying...":"Apply"}),(0,i.jsx)(d.$n,{onClick:eB,variant:"ghost",fullWidth:!0,disabled:ea,children:"Cancel"})]})]})}),e5=async e=>{if(!Q){Z(e);try{let t=await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${e$}/${e}`})}),s=await t.json();H(t=>({...t,[e]:s.ok?"ok":"error"})),B(s.ok?"":s.error||"Model not reachable")}catch{H(t=>({...t,[e]:"error"})),B("Network error")}finally{Z(null)}}};return f?(0,i.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,i.jsx)(d.Qv,{}),(0,i.jsx)(d.Qv,{})]}):ev?(0,i.jsxs)("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:gap-8 sm:px-0",children:[(0,i.jsxs)("div",{className:"min-w-0",children:[(0,i.jsxs)(o(),{href:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),"Back to Providers"]}),(0,i.jsxs)("div",{className:"flex min-w-0 items-center gap-3 sm:gap-4",children:[(0,i.jsx)("div",{className:"flex size-12 shrink-0 items-center justify-center rounded-lg",style:{backgroundColor:`${ev.color}15`},children:J?(0,i.jsx)("span",{className:"text-sm font-bold",style:{color:ev.color},children:ev.textIcon||ev.id.slice(0,2).toUpperCase()}):(0,i.jsx)(n.default,{src:eC&&ev.apiType?"responses"===ev.apiType?"/providers/oai-r.png":"/providers/oai-cc.png":eS?"/providers/anthropic-m.png":`/providers/${ev.id}.png`,alt:ev.name,width:48,height:48,className:"max-h-12 max-w-12 rounded-lg object-contain",sizes:"48px",onError:()=>W(!0)})}),(0,i.jsxs)("div",{className:"min-w-0",children:[(0,i.jsxs)("div",{className:"flex items-center gap-3 flex-wrap",children:[(0,i.jsx)("h1",{className:"truncate text-2xl font-semibold tracking-tight sm:text-3xl",children:ev.name}),(ev.notice?.apiKeyUrl||ev.notice?.signupUrl||ev.website)&&(0,i.jsxs)("a",{href:ev.notice?.apiKeyUrl||ev.notice?.signupUrl||ev.website,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline inline-flex items-center gap-1",children:[(0,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"open_in_new"}),ev.notice?.apiKeyUrl?"Get API Key":"Sign up / Learn more"]})]}),(0,i.jsxs)("p",{className:"text-text-muted",children:[x.length," connection",1===x.length?"":"s"]})]})]})]}),ev.deprecated&&(0,i.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,i.jsx)("span",{className:"material-symbols-outlined text-[16px] text-yellow-500 mt-0.5 shrink-0",children:"warning"}),(0,i.jsx)("p",{className:"text-xs text-red-600 dark:text-yellow-400 leading-relaxed",children:ev.deprecationNotice})]}),ev.notice?.text&&!ev.deprecated&&(0,i.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,i.jsx)("span",{className:"material-symbols-outlined text-[16px] text-blue-500 shrink-0",children:"info"}),(0,i.jsx)("p",{className:"min-w-0 flex-1 text-xs leading-relaxed text-blue-600 dark:text-blue-400",children:ev.notice.text}),ev.notice.apiKeyUrl&&(0,i.jsx)("a",{href:ev.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 →"})]}),eA&&v&&(0,i.jsxs)(d.Zp,{children:[(0,i.jsxs)("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,i.jsxs)("div",{className:"min-w-0",children:[(0,i.jsx)("h2",{className:"text-lg font-semibold",children:eS?"Anthropic Compatible Details":"OpenAI Compatible Details"}),(0,i.jsxs)("p",{className:"break-all text-sm text-text-muted",children:[eS?"Messages API":"responses"===v.apiType?"Responses API":"Chat Completions"," \xb7 ",(v.baseUrl||"").replace(/\/$/,""),"/",eS?"messages":"responses"===v.apiType?"responses":"chat/completions"]})]}),(0,i.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,i.jsx)(d.$n,{size:"sm",icon:"add",onClick:()=>I(!0),disabled:x.length>0,className:"w-full sm:w-auto",children:"Add"}),(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>D(!0),className:"w-full sm:w-auto",children:"Edit"}),(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"delete",onClick:async()=>{if(confirm(`Delete this ${eS?"Anthropic":"OpenAI"} Compatible node?`))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"})]})]}),x.length>0&&(0,i.jsx)("p",{className:"text-sm text-text-muted",children:"Only one connection is allowed per compatible node. Add another node if you need more connections."})]}),eN?(0,i.jsx)(d.gw,{providerId:r}):(0,i.jsxs)(d.Zp,{children:[(0,i.jsxs)("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,i.jsx)("h2",{className:"text-lg font-semibold",children:"Connections"}),(0,i.jsx)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",children:(0,i.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,i.jsx)("span",{className:"text-xs text-text-muted font-medium",children:"Round Robin"}),(0,i.jsx)(d.lM,{checked:"round-robin"===er,onChange:e=>{let t=e?"round-robin":null,s=e?en||"1":en;e&&!en&&ed("1"),eo(t),eq(t,s)}}),"round-robin"===er&&(0,i.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,i.jsx)("span",{className:"text-xs text-text-muted",children:"Sticky:"}),(0,i.jsx)("input",{type:"number",min:1,value:en,onChange:e=>{var t;ed(t=e.target.value),eq("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===x.length?(0,i.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,i.jsxs)("div",{className:"flex items-center gap-3",children:[(0,i.jsx)("div",{className:"inline-flex items-center justify-center w-9 h-9 rounded-full bg-primary/10 text-primary shrink-0",children:(0,i.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:ej?"lock":"key"})}),(0,i.jsx)("p",{className:"text-sm text-text-muted",children:"No connections yet"})]}),!eA&&(0,i.jsxs)("div",{className:"flex gap-2",children:["iflow"===r&&(0,i.jsx)(d.$n,{size:"sm",icon:"cookie",variant:"secondary",onClick:()=>O(!0),children:"Cookie"}),(0,i.jsx)(d.$n,{size:"sm",icon:"add",onClick:()=>ej?T(!0):I(!0),children:"iflow"===r?"OAuth":"Add Connection"})]})]}):(0,i.jsxs)(i.Fragment,{children:[eZ,!eA&&(0,i.jsxs)("div",{className:"mt-4 grid grid-cols-1 gap-2 sm:flex",children:["iflow"===r&&(0,i.jsx)(d.$n,{size:"sm",icon:"cookie",variant:"secondary",onClick:()=>O(!0),title:"Add connection using browser cookie",className:"w-full sm:w-auto",children:"Cookie"}),(0,i.jsx)(d.$n,{size:"sm",icon:"add",onClick:()=>ej?T(!0):I(!0),className:"w-full sm:w-auto",children:"Add"})]})]})]}),(0,i.jsxs)(d.Zp,{children:[(0,i.jsxs)("div",{className:"mb-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,i.jsx)("h2",{className:"text-lg font-semibold",children:"Available Models"}),!eA&&(e=[...ew,...eu.filter(e=>!ew.some(t=>t.id===e.id))].filter(e=>!e.type||"llm"===e.type).map(e=>e.id).filter(e=>!ef.includes(e)),(0,i.jsxs)("div",{className:"flex gap-2",children:[ef.length>0&&(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"restart_alt",onClick:eR,children:"Active All"}),e.length>0&&(0,i.jsx)(d.$n,{size:"sm",variant:"secondary",icon:"block",onClick:()=>eI(e),children:"Disable All"})]}))]}),!!G&&(0,i.jsx)("p",{className:"text-xs text-red-500 mb-3 break-words",children:G}),(()=>{let e,t,s;if(eA)return(0,i.jsx)(b,{providerStorageAlias:e$,providerDisplayAlias:eT,modelAliases:K,copied:eg,onCopy:eb,onSetAlias:ez,onDeleteAlias:eL,connections:x,isAnthropic:eS});let a=[...ew,...eu.filter(e=>!ew.some(t=>t.id===e.id))].filter(e=>!e.type||"llm"===e.type),l=new Set(ef),o=a.filter(e=>!l.has(e.id)),n=a.filter(e=>l.has(e.id)),d=Object.entries(K).filter(([e,t])=>{let s=`${e$}/`;if(!t.startsWith(s))return!1;let i=t.slice(s.length);return ev.passthroughModels?!ew.some(e=>e.id===i):!ew.some(e=>e.id===i)&&e===i}).map(([e,t])=>({id:t.slice(`${e$}/`.length),alias:e,fullModel:t}));return(0,i.jsxs)("div",{className:"flex flex-wrap gap-3",children:[d.map(e=>(0,i.jsx)(y,{model:{id:e.id},fullModel:`${eT}/${e.id}`,alias:e.alias,copied:eg,onCopy:eb,onSetAlias:()=>{},onDeleteAlias:()=>eL(e.alias),testStatus:V[e.id],onTest:x.length>0||eN?()=>e5(e.id):void 0,isTesting:Q===e.id,isCustom:!0,isFree:!1},e.id)),o.map(e=>{let t=`${e$}/${e.id}`,s=`${r}/${e.id}`,a=Object.entries(K).find(([,e])=>e===t||e===s)?.[0];return(0,i.jsx)(y,{model:e,fullModel:`${eT}/${e.id}`,alias:a,copied:eg,onCopy:eb,onSetAlias:t=>ez(e.id,t,e$),onDeleteAlias:()=>eL(a),testStatus:V[e.id],onTest:x.length>0||eN?()=>e5(e.id):void 0,isTesting:Q===e.id,isFree:e.isFree,onDisable:()=>eO(e.id)},e.id)}),(0,i.jsxs)("button",{onClick:()=>Y(!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,i.jsx)("span",{className:"material-symbols-outlined text-sm",children:"add"}),"Add Model"]}),em.length>0&&(e=new Set(Object.values(K)),t=new Set(ew.map(e=>e.id)),0===(s=em.filter(s=>!e.has(`${e$}/${s.id}`)&&!t.has(s.id))).length?null:(0,i.jsxs)("div",{className:"w-full mt-2",children:[(0,i.jsx)("p",{className:"text-xs text-text-muted mb-2",children:"Suggested free models (≥200k context):"}),(0,i.jsx)("div",{className:"flex flex-wrap gap-2",children:s.map(e=>(0,i.jsxs)("button",{onClick:async()=>{let t=e.id.split("/").pop();await ez(e.id,t,e$)},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,i.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),e.id.split("/").pop()]},e.id))})]})),n.length>0&&(0,i.jsxs)("div",{className:"w-full mt-2",children:[(0,i.jsxs)("p",{className:"text-xs text-text-muted mb-2",children:["Disabled models (",n.length,"):"]}),(0,i.jsx)("div",{className:"flex flex-wrap gap-2",children:n.map(e=>(0,i.jsxs)("button",{onClick:()=>eE(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,i.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),e.id]},e.id))})]})]})})()]}),e1,"kiro"===r?(0,i.jsx)(d.Mh,{isOpen:$,providerInfo:ev,onSuccess:eK,onClose:()=>T(!1)}):"cursor"===r?(0,i.jsx)(d.G9,{isOpen:$,onSuccess:eK,onClose:()=>T(!1)}):"gitlab"===r?(0,i.jsx)(d.vj,{isOpen:$,providerInfo:ev,onSuccess:eK,onClose:()=>T(!1)}):(0,i.jsx)(d.LF,{isOpen:$,provider:r,providerInfo:ev,onSuccess:eK,onClose:()=>T(!1)}),"iflow"===r&&(0,i.jsx)(d.vE,{isOpen:P,onSuccess:()=>{eU(),O(!1)},onClose:()=>O(!1)}),(0,i.jsx)(N,{isOpen:E,provider:r,providerName:ev.name,isCompatible:eA,isAnthropic:eS,authType:ev?.authType,authHint:ev?.authHint,website:ev?.website,proxyPools:S,onSave:eF,onClose:()=>I(!1)}),(0,i.jsx)(d.wI,{isOpen:R,connection:L,proxyPools:S,onSave:eJ,onClose:()=>_(!1)}),eA&&(0,i.jsx)(w,{isOpen:U,node:v,onSave:eD,onClose:()=>D(!1),isAnthropic:eS}),!eA&&(0,i.jsx)(k,{isOpen:X,providerAlias:e$,providerDisplayAlias:eT,onSave:async e=>{let t=ev?.passthroughModels?e.split("/").pop():e;await ez(e,t,e$),Y(!1)},onClose:()=>Y(!1)})]}):(0,i.jsxs)("div",{className:"text-center py-20",children:[(0,i.jsx)("p",{className:"text-text-muted",children:"Provider not found"}),(0,i.jsx)(o(),{href:"/dashboard/providers",className:"text-primary mt-4 inline-block",children:"Back to Providers"})]})}y.propTypes={model:f().shape({id:f().string.isRequired}).isRequired,fullModel:f().string.isRequired,alias:f().string,copied:f().string,onCopy:f().func.isRequired,testStatus:f().oneOf(["ok","error"]),isCustom:f().bool,isFree:f().bool,onDeleteAlias:f().func,onTest:f().func,isTesting:f().bool,onDisable:f().func},f().string.isRequired,f().string.isRequired,f().string,f().func.isRequired,f().func.isRequired,f().func,f().oneOf(["ok","error"]),f().bool,f().string.isRequired,f().object.isRequired,f().string,f().func.isRequired,f().func.isRequired,f().func.isRequired,b.propTypes={providerStorageAlias:f().string.isRequired,providerDisplayAlias:f().string.isRequired,modelAliases:f().object.isRequired,copied:f().string,onCopy:f().func.isRequired,onSetAlias:f().func.isRequired,onDeleteAlias:f().func.isRequired,connections:f().arrayOf(f().shape({id:f().string,isActive:f().bool})).isRequired,isAnthropic:f().bool},v.propTypes={until:f().string.isRequired},j.propTypes={connection:f().shape({id:f().string,name:f().string,email:f().string,displayName:f().string,modelLockUntil:f().string,testStatus:f().string,isActive:f().bool,lastError:f().string,priority:f().number,globalPriority:f().number}).isRequired,proxyPools:f().arrayOf(f().shape({id:f().string,name:f().string,proxyUrl:f().string,noProxy:f().string,isActive:f().bool})),isOAuth:f().bool.isRequired,isFirst:f().bool.isRequired,isLast:f().bool.isRequired,onMoveUp:f().func.isRequired,onMoveDown:f().func.isRequired,onToggleActive:f().func.isRequired,onUpdateProxy:f().func,onEdit:f().func.isRequired,onDelete:f().func.isRequired},N.propTypes={isOpen:f().bool.isRequired,provider:f().string,providerName:f().string,isCompatible:f().bool,isAnthropic:f().bool,authType:f().string,authHint:f().string,website:f().string,proxyPools:f().arrayOf(f().shape({id:f().string,name:f().string})),onSave:f().func.isRequired,onClose:f().func.isRequired},w.propTypes={isOpen:f().bool.isRequired,node:f().shape({id:f().string,name:f().string,prefix:f().string,apiType:f().string,baseUrl:f().string}),onSave:f().func.isRequired,onClose:f().func.isRequired,isAnthropic:f().bool},k.propTypes={isOpen:f().bool.isRequired,providerAlias:f().string.isRequired,providerDisplayAlias:f().string.isRequired,onSave:f().func.isRequired,onClose:f().func.isRequired}},53655:(e,t,s)=>{Promise.resolve().then(s.bind(s,17721))}},e=>{e.O(0,[2574,3862,1051,5772,1321,5497,8441,3794,7358],()=>e(e.s=53655)),_N_E=e.O()}]);