@fudrouter/fsrouter 0.6.117 → 0.6.119

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 (44) hide show
  1. package/dist/routes/v1/models/route.js +12 -4
  2. package/package.json +1 -1
  3. package/public/assets/EndpointPageClient.Di2YqgPf.js +6 -0
  4. package/public/assets/Loading.D9qCFX3R.js +1 -0
  5. package/public/assets/NoAuthProxyCard.DMCykSRG.js +89 -0
  6. package/public/assets/index.C5VWu_q7.js +89 -0
  7. package/public/assets/page.BFEjgGXd.js +2 -0
  8. package/public/assets/page.BIksOupz.js +1 -0
  9. package/public/assets/page.BN35ziqx.js +6 -0
  10. package/public/assets/page.BY-Z5lJc.js +1 -0
  11. package/public/assets/page.BYuvYI81.js +1 -0
  12. package/public/assets/page.BZn6EjgR.js +1 -0
  13. package/public/assets/page.BqDkuLBL.js +1 -0
  14. package/public/assets/page.Brx8iIwy.js +31 -0
  15. package/public/assets/page.ByoxqtTd.js +1 -0
  16. package/public/assets/page.C-2PY_Ek.js +6 -0
  17. package/public/assets/page.CBJ3PIz6.js +1 -0
  18. package/public/assets/page.CC2igP7g.js +5 -0
  19. package/public/assets/page.CJV7n_Cb.js +1 -0
  20. package/public/assets/page.CadeLR3B.js +2 -0
  21. package/public/assets/page.Cn9VXlxl.js +1 -0
  22. package/public/assets/page.Cnk5NKtT.js +1 -0
  23. package/public/assets/page.Ctr5GGfe.js +23 -0
  24. package/public/assets/page.CvY1-VAN.js +5 -0
  25. package/public/assets/page.DD2_vWM3.js +1 -0
  26. package/public/assets/page.DFOtpzzq.js +7 -0
  27. package/public/assets/page.DGqaAFu_.js +1 -0
  28. package/public/assets/page.DSCWOtet.js +1 -0
  29. package/public/assets/page.DUXPs518.js +1 -0
  30. package/public/assets/page.DV-sp6Ji.js +1 -0
  31. package/public/assets/page.DarYN1Wo.js +1 -0
  32. package/public/assets/page.DsnVF9ld.js +1 -0
  33. package/public/assets/page.DuJrvy6q.js +1 -0
  34. package/public/assets/page.DvVWtaJ8.js +1 -0
  35. package/public/assets/page.Dvoll2rR.js +64 -0
  36. package/public/assets/page.K41VgPhA.js +1 -0
  37. package/public/assets/page.LA8kHbDi.js +4 -0
  38. package/public/assets/page.UGWWqB47.js +1 -0
  39. package/public/assets/page.eObJ7Eqq.js +1 -0
  40. package/public/assets/page.hGYtnZEk.js +1 -0
  41. package/public/assets/page.hr04hSjp.js +1 -0
  42. package/public/assets/page.imKuq2A5.js +1 -0
  43. package/public/assets/page.zF9qqJjX.js +1 -0
  44. package/public/index.html +4 -4
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.C5VWu_q7.js";import"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function i(){return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex items-center justify-center size-8 rounded-lg bg-primary/10",children:e.jsx("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"menu_book"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-sm font-semibold text-text-main",children:"API Reference"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Image & Video Generation — all providers, models, and parameters"})]})]}),e.jsxs("a",{href:"/image-video-docs.html",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-text-muted hover:text-text-main hover:bg-surface-2 transition-all",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"open_in_new"}),"Open in new tab"]})]}),e.jsx("iframe",{src:"/image-video-docs.html",className:"flex-1 w-full border-0 min-h-0",title:"Image & Video API Reference"})]})}export{i as default};
@@ -0,0 +1 @@
1
+ import{j as o}from"./index.C5VWu_q7.js";import{b as r}from"./router.Cjj1--8t.js";import{g as a}from"./machine.CagOtseJ.js";import{A as i}from"./EndpointPageClient.Di2YqgPf.js";import"./zustand.akaTi5uX.js";import"./NoAuthProxyCard.DMCykSRG.js";import"./Loading.D9qCFX3R.js";function d(){const[t,e]=r.useState("");return r.useEffect(()=>{a().then(e)},[]),t?o.jsx(i,{machineId:t}):null}export{d as default};
@@ -0,0 +1 @@
1
+ import{N as B,K as I,j as e,B as E,g as A,P as z}from"./index.C5VWu_q7.js";import{h as _,d as M,b,L as T}from"./router.Cjj1--8t.js";import{A as R,C as D,B as j,T as K}from"./NoAuthProxyCard.DMCykSRG.js";import"./zustand.akaTi5uX.js";const F=new Set([]),L={image:"image-combo",tts:"tts-combo"};function P(s){const o=Object.entries(s).some(([i,d])=>i.startsWith("modelLock_")&&d&&new Date(d).getTime()>Date.now());return s.testStatus==="unavailable"&&!o?"active":s.testStatus}function $({provider:s,kind:o,connections:i,isCustom:d,onToggle:l}){var C;const n=A[s.id],y=!!(n!=null&&n.noAuth),p=i.filter(a=>a.provider===s.id),v=p.filter(a=>{const x=P(a);return x==="active"||x==="success"}).length,h=p.filter(a=>{const x=P(a);return x==="error"||x==="expired"||x==="unavailable"}).length,m=p.length,r=m>0&&p.every(a=>a.isActive===!1),u=a=>{a.preventDefault(),a.stopPropagation(),l&&l(s.id,r)},k=()=>y?e.jsx(j,{variant:"success",size:"sm",children:"Ready"}):r?e.jsx(j,{variant:"default",size:"sm",children:"Disabled"}):m===0?e.jsx("span",{className:"text-xs text-text-muted",children:"No connections"}):e.jsxs(e.Fragment,{children:[v>0&&e.jsxs(j,{variant:"success",size:"sm",dot:!0,children:[v," Connected"]}),h>0&&e.jsxs(j,{variant:"error",size:"sm",dot:!0,children:[h," Error"]}),v===0&&h===0&&e.jsxs(j,{variant:"default",size:"sm",children:[m," Added"]})]});return e.jsx(T,{to:`/dashboard/media-providers/${o}/${s.id}`,className:"group",children:e.jsx(D,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${r?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 rounded-lg flex items-center justify-center shrink-0",style:{backgroundColor:`${((C=s.color)==null?void 0:C.length)>7?s.color:(s.color??"#888")+"15"}`},children:e.jsx(z,{src:`/providers/${s.id}.png`,alt:s.name,size:30,className:"object-contain rounded-lg max-w-[30px] max-h-[30px]",fallbackText:s.textIcon||s.id.slice(0,2).toUpperCase(),fallbackColor:s.color})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm",children:s.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[d&&e.jsx(j,{variant:"default",size:"sm",children:"Custom"}),k()]})]})]}),m>0&&e.jsx("div",{className:"shrink-0 opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100",onClick:u,children:e.jsx(K,{size:"sm",checked:!r,onChange:()=>{},title:r?"Enable provider":"Disable provider"})})]})})})}function U({combos:s}){return s.length===0?null:e.jsx("div",{className:"flex flex-col gap-2",children:s.map(o=>e.jsx(T,{to:`/dashboard/media-providers/combo/${o.id}`,children:e.jsx(D,{padding:"xs",className:"hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors cursor-pointer",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"layers"}),e.jsx("code",{className:"text-sm font-mono font-medium flex-1 truncate",children:o.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 sm:shrink-0",children:[o.models.slice(0,6).map((i,d)=>{const l=typeof i=="string"?i.split("/")[0]:"",n=A[l];return e.jsx("div",{title:(n==null?void 0:n.name)||i,className:"size-5 rounded flex items-center justify-center",style:{backgroundColor:`${(n==null?void 0:n.color)??"#888"}15`},children:e.jsx(z,{src:`/providers/${l}.png`,alt:(n==null?void 0:n.name)||l,size:18,className:"object-contain rounded max-w-[18px] max-h-[18px]",fallbackText:(n==null?void 0:n.textIcon)||l.slice(0,2).toUpperCase(),fallbackColor:n==null?void 0:n.color})},`${i}-${d}`)}),o.models.length>6&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1",children:["+",o.models.length-6]})]}),e.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:o.models.length}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[16px]",children:"chevron_right"})]})})},o.id))})}function G(){const{kind:s}=_(),o=M(),[i,d]=b.useState([]),[l,n]=b.useState([]),[y,p]=b.useState([]),[v,h]=b.useState(!1);b.useEffect(()=>{(s==="webSearch"||s==="webFetch")&&o("/dashboard/media-providers/web")},[s,o]);const m=B.find(t=>t.id===s),r=s==="embedding",u=F.has(s);if(b.useEffect(()=>{m&&(fetch("/api/providers",{cache:"no-store"}).then(t=>t.json()).then(t=>d(t.connections||[])).catch(()=>{}),r&&fetch("/api/provider-nodes",{cache:"no-store"}).then(t=>t.json()).then(t=>n((t.nodes||[]).filter(c=>c.type==="custom-embedding"))).catch(()=>{}),u&&fetch("/api/combos",{cache:"no-store"}).then(t=>t.json()).then(t=>p(t.combos||[])).catch(()=>{}))},[r,u,m]),!m)return null;const k=I(s),C=y.filter(t=>t.kind===s),a=l.map(t=>({id:t.id,name:t.name||"Custom Embedding",color:"#6366F1",textIcon:"CE"})),x=[...k,...a],S=async(t,c)=>{const w=i.filter(f=>f.provider===t);d(f=>f.map(g=>g.provider===t?{...g,isActive:c}:g)),await Promise.allSettled(w.map(f=>fetch(`/api/providers/${f.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:c})})))},O=async()=>{const t=L[s]||`${s}-combo`;let c=t,w=1;const f=new Set(y.map(N=>N.name));for(;f.has(c);)c=`${t}-${w++}`;const g=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:c,models:[],kind:s})});if(g.ok){const N=await g.json();o(`/dashboard/media-providers/combo/${N.id}`)}else{const N=await g.json();alert(N.error||"Failed to create combo")}};return e.jsxs("div",{className:"flex flex-col gap-6",children:[(r||u)&&e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[u&&e.jsx(E,{size:"sm",icon:"add",onClick:O,children:"Create Combo"}),r&&e.jsx(E,{size:"sm",icon:"add",onClick:()=>h(!0),children:"Add Custom Embedding"})]}),u&&C.length>0&&e.jsx(U,{combos:C}),x.length===0?e.jsxs("div",{className:"text-center py-12 border border-dashed border-border rounded-xl text-text-muted text-sm",children:["No providers support ",e.jsx("strong",{children:m.label})," yet."]}):e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:[k.map(t=>e.jsx($,{provider:t,kind:s,connections:i,onToggle:S},t.id)),a.map(t=>e.jsx($,{provider:t,kind:s,connections:i,isCustom:!0,onToggle:S},t.id))]}),r&&e.jsx(R,{isOpen:v,onClose:()=>h(!1),onCreated:t=>{n(c=>[...c,t]),h(!1)}})]})}export{G as default};
@@ -0,0 +1 @@
1
+ import{a as ae,j as e,B as _,b as Y,O as ve,F as ye,c as je,A as Ne,W as Ce,d as we,e as Te,P as re,M as ie,f as i}from"./index.C5VWu_q7.js";import{b as c,L as le}from"./router.Cjj1--8t.js";import{C as ne,B as P,T as oe,I as O,S as ke}from"./NoAuthProxyCard.DMCykSRG.js";import{C as ee}from"./Loading.D9qCFX3R.js";import"./zustand.akaTi5uX.js";function Ae(r){if(!r)return null;const a=r.match(/\b([45]\d{2})\b/);return a?a[1]:"ERR"}function Ie(r){if(!r)return"";const a=Date.now()-new Date(r).getTime(),m=Math.floor(a/6e4);if(m<1)return"just now";if(m<60)return`${m}m ago`;const s=Math.floor(m/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}const te={available:{icon:"check_circle",color:"#22c55e",label:"Available"},cooldown:{icon:"schedule",color:"#f59e0b",label:"Cooldown"},unavailable:{icon:"error",color:"#ef4444",label:"Unavailable"},unknown:{icon:"help",color:"#6b7280",label:"Unknown"}};function Se(){const[r,a]=c.useState(null),[m,s]=c.useState(!0),[l,h]=c.useState(!1),[w,v]=c.useState(null),y=c.useRef(null),u=ae(),N=c.useCallback(async()=>{try{const x=await fetch("/api/models/availability");if(x.ok){const g=await x.json();a(g)}}catch{}finally{s(!1)}},[]);c.useEffect(()=>{N();const x=setInterval(N,3e4);return()=>clearInterval(x)},[N]),c.useEffect(()=>{const x=g=>{y.current&&!y.current.contains(g.target)&&h(!1)};return l&&document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[l]);const C=async(x,g)=>{v(`${x}:${g}`);try{(await fetch("/api/models/availability",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"clearCooldown",provider:x,model:g})})).ok?(u.success(`Cooldown cleared for ${g}`),await N()):u.error("Failed to clear cooldown")}catch{u.error("Failed to clear cooldown")}finally{v(null)}};if(m)return null;const p=(r==null?void 0:r.models)||[],j=((r==null?void 0:r.unavailableCount)||p.filter(x=>x.status!=="available").length)===0,k={};return p.forEach(x=>{if(x.status==="available")return;const g=x.provider||"unknown";k[g]||(k[g]=[]),k[g].push(x)}),e.jsx("div",{className:"relative",ref:y,children:l&&e.jsxs("div",{className:"absolute top-full right-0 mt-2 w-80 bg-surface border border-border rounded-xl shadow-2xl z-50 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-bg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",style:{color:j?"#22c55e":"#f59e0b"},children:j?"verified":"warning"}),e.jsx("span",{className:"text-sm font-semibold text-text-main",children:"Model Status"})]}),e.jsx("button",{onClick:N,className:"p-1 rounded-lg hover:bg-surface text-text-muted hover:text-text-main transition-colors",title:"Refresh",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"refresh"})})]}),e.jsx("div",{className:"px-4 py-3 max-h-60 overflow-y-auto",children:j?e.jsx("p",{className:"text-sm text-text-muted text-center py-2",children:"All models are responding normally."}):e.jsx("div",{className:"flex flex-col gap-2.5",children:Object.entries(k).map(([x,g])=>e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-text-main mb-1.5 capitalize",children:x}),e.jsx("div",{className:"flex flex-col gap-1",children:g.map(o=>{const n=te[o.status]||te.unknown,b=w===`${o.provider}:${o.model}`;return e.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5 rounded-lg bg-surface/30",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] shrink-0",style:{color:n.color},children:n.icon}),e.jsx("span",{className:"font-mono text-xs text-text-main truncate",children:o.model})]}),o.status==="cooldown"&&e.jsx(_,{size:"sm",variant:"ghost",onClick:()=>C(o.provider,o.model),disabled:b,className:"text-[10px] px-1.5! py-0.5! ml-2",children:b?"...":"Clear"})]},`${o.provider}-${o.model}`)})})]},x))})})]})})}function ce(r,a,m){const s=[];if(r>0&&s.push(e.jsxs(P,{variant:"success",size:"sm",dot:!0,children:[r," Connected"]},"connected")),a>0){const l=m?`${a} Error (${m})`:`${a} Error`;s.push(e.jsx(P,{variant:"error",size:"sm",dot:!0,children:l},"error"))}return s.length===0?e.jsx("span",{className:"text-text-muted",children:"No connections"}):s}function Re(r){if(!r)return null;const a=r.lastErrorType;if(a==="runtime_error")return"RUNTIME";if(a==="upstream_auth_error"||a==="auth_missing"||a==="token_refresh_failed"||a==="token_expired")return"AUTH";if(a==="upstream_rate_limited")return"429";if(a==="upstream_unavailable")return"5XX";if(a==="network_error")return"NET";const m=Number(r.errorCode);if(Number.isFinite(m)&&m>=400)return String(m);const s=Ae(r.lastError);if(s==="401"||s==="403")return"AUTH";if(s&&s!=="ERR")return s;const l=(r.lastError||"").toLowerCase();return l.includes("runtime")||l.includes("not runnable")||l.includes("not installed")?"RUNTIME":l.includes("invalid api key")||l.includes("token invalid")||l.includes("revoked")||l.includes("unauthorized")?"AUTH":"ERR"}const se=20;function De(){const[r,a]=c.useState([]),[m,s]=c.useState([]),[l,h]=c.useState(!0),[w,v]=c.useState(!1),[y,u]=c.useState(!1),[N,C]=c.useState(!1),[p,I]=c.useState(null),[j,k]=c.useState(null),x=ae(),g=Y(t=>t.query),o=Y(t=>t.register),n=Y(t=>t.unregister);c.useEffect(()=>(o("Search providers..."),()=>n()),[o,n]);const b=t=>!g.trim()||t.toLowerCase().includes(g.trim().toLowerCase()),K=(t,d)=>[...t].sort(([f,S],[A,R])=>{const q=D(f,d),F=D(A,d),L=q.connected>0?1:0,U=F.connected>0?1:0;return L!==U?U-L:(S.name||"").localeCompare(R.name||"")});c.useEffect(()=>{(async()=>{try{const[d,f]=await Promise.all([fetch("/api/providers"),fetch("/api/provider-nodes")]),S=await d.json(),A=await f.json();d.ok&&a(S.connections||[]),f.ok&&s(A.nodes||[])}catch(d){console.log("Error fetching data:",d)}finally{h(!1)}})()},[]);const D=(t,d)=>{const f=r.filter(T=>T.provider===t&&(T.authType===d||(t==="codebuddy"||t==="kimchi")&&T.authType==="apikey")),S=T=>{const E=Object.entries(T).some(([be,Z])=>be.startsWith("modelLock_")&&Z&&new Date(Z).getTime()>Date.now());return T.testStatus==="unavailable"&&!E?"active":T.testStatus},A=f.filter(T=>{const E=S(T);return E==="active"||E==="success"}).length,R=f.filter(T=>{const E=S(T);return E==="error"||E==="expired"||E==="unavailable"}),q=R.length,F=f.length,L=F>0&&f.every(T=>T.isActive===!1),U=R.sort((T,E)=>new Date(E.lastErrorAt||0)-new Date(T.lastErrorAt||0))[0],fe=U?Re(U):null,ge=U!=null&&U.lastErrorAt?Ie(U.lastErrorAt):null;return{connected:A,error:q,total:F,errorCode:fe,errorTime:ge,allDisabled:L}},$=async(t,d,f)=>{const S=r.filter(A=>A.provider===t&&A.authType===d);a(A=>A.map(R=>R.provider===t&&R.authType===d?{...R,isActive:f}:R)),await Promise.allSettled(S.map(A=>fetch(`/api/providers/${A.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:f})})))},V=async(t,d=null)=>{if(!p){I(t==="provider"?d:t),k(null);try{const S=await(await fetch("/api/providers/test-batch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:t,providerId:d})})).json();if(k(S),S.summary){const{passed:A,failed:R,total:q}=S.summary;R===0?x.success(`All ${q} tests passed`):x.warning(`${A}/${q} passed, ${R} failed`)}}catch{k({error:"Test request failed"}),x.error("Provider test failed")}finally{I(null)}}},B=m.filter(t=>t.type==="openai-compatible").map(t=>({id:t.id,name:t.name||"OpenAI Compatible",color:"#10A37F",textIcon:"OC",apiType:t.apiType})).filter(t=>b(t.name)),W=m.filter(t=>t.type==="anthropic-compatible").map(t=>({id:t.id,name:t.name||"Anthropic Compatible",color:"#D97757",textIcon:"AC"})).filter(t=>b(t.name)),H=Object.entries(ve).filter(([,t])=>!t.hidden&&b(t.name)),J=Object.entries(ye).filter(([,t])=>!t.hidden&&b(t.name)),X=Object.entries(je).filter(([,t])=>!t.hidden&&b(t.name)),M=K(Object.entries(Ne).filter(([,t])=>!t.hidden&&(t.serviceKinds??["llm"]).includes("llm")&&b(t.name)),"apikey"),Q=!!g.trim(),xe=Q||w?M:M.slice(0,se),ue=M.length-se;if(l)return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(ee,{}),e.jsx(ee,{})]});const he=H.length>0||J.length>0||X.length>0||M.length>0||B.length>0||W.length>0;return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[!he&&e.jsxs("div",{className:"text-center py-8 border border-dashed border-border rounded-xl",children:[e.jsx("span",{className:"material-symbols-outlined text-[32px] text-text-muted mb-2",children:"search_off"}),e.jsx("p",{className:"text-text-muted text-sm",children:"No providers match your search"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:["Custom Providers (OpenAI/Anthropic Compatible)"," "]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:w-auto",children:[e.jsx(_,{size:"sm",icon:"add",onClick:()=>C(!0),className:"w-full sm:w-auto",children:"Add Anthropic Compatible"}),e.jsx(_,{size:"sm",variant:"secondary",icon:"add",onClick:()=>u(!0),className:"w-full !bg-white !text-black hover:!bg-gray-100 sm:w-auto",children:"Add OpenAI Compatible"})]})]}),B.length===0&&W.length===0?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-2 border border-dashed border-border rounded-xl text-text-muted text-sm",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"extension"}),e.jsx("span",{children:"No custom providers — use buttons above to add OpenAI/Anthropic compatible endpoints"})]}):e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:[...B,...W].map(t=>e.jsx(z,{providerId:t.id,provider:t,stats:D(t.id,"apikey"),authType:"compatible",onToggle:d=>$(t.id,"apikey",d)},t.id))})]}),H.length>0&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:"OAuth Providers"}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsx(Se,{}),e.jsxs("button",{onClick:()=>V("oauth"),disabled:!!p,className:`flex w-full items-center justify-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors sm:w-auto sm:py-1.5 ${p==="oauth"?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"}`,title:"Test all OAuth connections","aria-label":"Test all OAuth connections",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px]${p==="oauth"?" animate-spin":""}`,children:"play_arrow"}),p==="oauth"?"Testing...":"Test All"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:H.map(([t,d])=>e.jsx(G,{providerId:t,provider:d,stats:D(t,"oauth"),authType:"oauth",onToggle:f=>$(t,"oauth",f)},t))})]}),(J.length>0||X.length>0)&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:"Free Tier Providers"}),e.jsxs("button",{onClick:()=>V("free"),disabled:!!p,className:`flex w-full items-center justify-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors sm:w-auto sm:py-1.5 ${p==="free"?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"}`,title:"Test all Free connections","aria-label":"Test all Free provider connections",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px]${p==="free"?" animate-spin":""}`,children:"play_arrow"}),p==="free"?"Testing...":"Test All"]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:[J.map(([t,d])=>e.jsx(G,{providerId:t,provider:d,stats:D(t,"oauth"),authType:"free",onToggle:f=>$(t,"oauth",f)},t)),X.map(([t,d])=>e.jsx(z,{providerId:t,provider:d,stats:D(t,"apikey"),authType:"apikey",onToggle:f=>$(t,"apikey",f)},t))]})]}),M.length>0&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:["API Key Providers"," "]}),e.jsxs("button",{onClick:()=>V("apikey"),disabled:!!p,className:`flex w-full items-center justify-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors sm:w-auto sm:py-1.5 ${p==="apikey"?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"}`,title:"Test all API Key connections","aria-label":"Test all API Key connections",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px]${p==="apikey"?" animate-spin":""}`,children:"play_arrow"}),p==="apikey"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:xe.map(([t,d])=>e.jsx(z,{providerId:t,provider:d,stats:D(t,"apikey"),authType:"apikey",onToggle:f=>$(t,"apikey",f)},t))}),!Q&&!w&&ue>0&&e.jsxs("button",{onClick:()=>v(!0),className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-primary/40 px-3 py-2.5 text-sm font-medium text-primary transition-colors hover:border-primary hover:bg-primary/5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"expand_more"}),"Show all ",M.length," providers"]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("h2",{className:"text-xl font-semibold flex items-center gap-2",children:["Web Cookie Providers"," "]})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:Object.entries(Ce).map(([t,d])=>e.jsx(z,{providerId:t,provider:d,stats:D(t,"apikey"),authType:"apikey",onToggle:f=>$(t,"apikey",f)},t))})]}),e.jsx(de,{isOpen:y,onClose:()=>u(!1),onCreated:t=>{s(d=>[...d,t]),u(!1)}}),e.jsx(me,{isOpen:N,onClose:()=>C(!1),onCreated:t=>{s(d=>[...d,t]),C(!1)}}),j&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-start justify-center px-3 pt-[6vh] sm:pt-[10vh]",onClick:()=>k(null),children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-surface border border-border rounded-xl w-full max-w-[600px] max-h-[86vh] sm:max-h-[80vh] overflow-y-auto shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-5 py-3 border-b border-border bg-surface/95 backdrop-blur-sm rounded-t-xl",children:[e.jsx("h3",{className:"font-semibold",children:"Test Results"}),e.jsx("button",{onClick:()=>k(null),className:"p-1 rounded-lg hover:bg-bg text-text-muted hover:text-text-main transition-colors","aria-label":"Close test results",children:e.jsx("span",{className:"material-symbols-outlined text-lg",children:"close"})})]}),e.jsx("div",{className:"p-5",children:e.jsx(pe,{results:j})})]})]})]})}function G({providerId:r,provider:a,stats:m,authType:s,onToggle:l}){var C;const{connected:h,error:w,errorCode:v,errorTime:y,allDisabled:u}=m,N=!!a.noAuth;return e.jsx(le,{to:`/dashboard/providers/${r}`,className:"group min-w-0",children:e.jsx(ne,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${u?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 shrink-0 rounded-lg flex items-center justify-center",style:{backgroundColor:`${((C=a.color)==null?void 0:C.length)>7?a.color:a.color+"15"}`},children:e.jsx(re,{src:a.id==="codebuddy"||a.id==="cb"?"/providers/codebuddy.svg":`/providers/${a.id}.png`,alt:a.name,size:30,className:"object-contain rounded-lg max-w-[32px] max-h-[32px]",fallbackText:a.textIcon||a.id.slice(0,2).toUpperCase(),fallbackColor:a.color})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate font-semibold",children:a.name}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5 text-xs flex-wrap",children:u?e.jsx(P,{variant:"default",size:"sm",children:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"pause_circle"}),"Disabled"]})}):N?e.jsx(P,{variant:"success",size:"sm",dot:!0,children:"Ready"}):e.jsxs(e.Fragment,{children:[ce(h,w,v),y&&e.jsx("span",{className:"text-text-muted",children:y})]})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:m.total>0&&e.jsx("div",{className:"opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100",onClick:p=>{p.preventDefault(),p.stopPropagation(),l(!!u)},children:e.jsx(oe,{size:"sm",checked:!u,onChange:()=>{},title:u?"Enable provider":"Disable provider"})})})]})})})}G.propTypes={providerId:i.string.isRequired,provider:i.shape({id:i.string.isRequired,name:i.string.isRequired,color:i.string,textIcon:i.string}).isRequired,stats:i.shape({connected:i.number,error:i.number,errorCode:i.string,errorTime:i.string}).isRequired,authType:i.string,onToggle:i.func};function z({providerId:r,provider:a,stats:m,authType:s,onToggle:l}){var I;const{connected:h,error:w,errorCode:v,errorTime:y,allDisabled:u}=m,N=r.startsWith(we),C=r.startsWith(Te),p=()=>a.id==="codebuddy"||a.id==="cb"?"/providers/codebuddy.svg":N?a.apiType==="responses"?"/providers/oai-r.png":"/providers/oai-cc.png":C?"/providers/anthropic-m.png":`/providers/${a.id}.png`;return e.jsx(le,{to:`/dashboard/providers/${r}`,className:"group min-w-0",children:e.jsx(ne,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${u?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 shrink-0 rounded-lg flex items-center justify-center",style:{backgroundColor:`${((I=a.color)==null?void 0:I.length)>7?a.color:a.color+"15"}`},children:e.jsx(re,{src:p(),alt:a.name,size:30,className:"object-contain rounded-lg max-w-[30px] max-h-[30px]",fallbackText:a.textIcon||a.id.slice(0,2).toUpperCase(),fallbackColor:a.color})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate font-semibold",children:a.name}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5 text-xs flex-wrap",children:u?e.jsx(P,{variant:"default",size:"sm",children:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"pause_circle"}),"Disabled"]})}):e.jsxs(e.Fragment,{children:[ce(h,w,v),N&&e.jsx(P,{variant:"default",size:"sm",children:a.apiType==="responses"?"Responses":"Chat"}),C&&e.jsx(P,{variant:"default",size:"sm",children:"Messages"}),y&&e.jsx("span",{className:"text-text-muted",children:y})]})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:m.total>0&&e.jsx("div",{className:"opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100",onClick:j=>{j.preventDefault(),j.stopPropagation(),l(!!u)},children:e.jsx(oe,{size:"sm",checked:!u,onChange:()=>{},title:u?"Enable provider":"Disable provider"})})})]})})})}z.propTypes={providerId:i.string.isRequired,provider:i.shape({id:i.string.isRequired,name:i.string.isRequired,color:i.string,textIcon:i.string,apiType:i.string}).isRequired,stats:i.shape({connected:i.number,error:i.number,errorCode:i.string,errorTime:i.string}).isRequired,authType:i.string,onToggle:i.func};function de({isOpen:r,onClose:a,onCreated:m}){const[s,l]=c.useState({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[h,w]=c.useState(!1),[v,y]=c.useState(""),[u,N]=c.useState(""),[C,p]=c.useState(!1),[I,j]=c.useState(null),k=[{value:"chat",label:"Chat Completions"},{value:"responses",label:"Responses API"}];c.useEffect(()=>{const n="https://api.openai.com/v1";l(b=>({...b,baseUrl:n}))},[s.apiType]);const x=async()=>{if(!(!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim())){w(!0);try{const n=await fetch("/api/provider-nodes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.name,prefix:s.prefix,apiType:s.apiType,baseUrl:s.baseUrl,type:"openai-compatible"})}),b=await n.json();n.ok&&(m(b.node),l({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),y(""),j(null))}catch(n){console.log("Error creating OpenAI Compatible node:",n)}finally{w(!1)}}},g=async()=>{p(!0);try{const b=await(await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:s.baseUrl,apiKey:v,type:"openai-compatible",modelId:u.trim()||void 0})})).json();j(b)}catch{j({valid:!1,error:"Network error"})}finally{p(!1)}},o=()=>{if(!I)return null;const{valid:n,error:b,method:K}=I;return n?e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"success",children:"Valid"}),K==="chat"&&e.jsx("span",{className:"text-sm text-text-muted",children:"(via inference test)"})]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(P,{variant:"error",children:"Invalid"}),b&&e.jsx("span",{className:"text-sm text-red-500",children:b})]})};return e.jsx(ie,{isOpen:r,title:"Add OpenAI Compatible",onClose:a,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(O,{label:"Name",value:s.name,onChange:n=>l({...s,name:n.target.value}),placeholder:"OpenAI Compatible (Prod)",hint:"Required. A friendly label for this node."}),e.jsx(O,{label:"Prefix",value:s.prefix,onChange:n=>l({...s,prefix:n.target.value}),placeholder:"oc-prod",hint:"Required. Used as the provider prefix for model IDs."}),e.jsx(ke,{label:"API Type",options:k,value:s.apiType,onChange:n=>l({...s,apiType:n.target.value})}),e.jsx(O,{label:"Base URL",value:s.baseUrl,onChange:n=>l({...s,baseUrl:n.target.value}),placeholder:"https://api.openai.com/v1",hint:"Use the base URL (ending in /v1) for your OpenAI-compatible API."}),e.jsx(O,{label:"API Key (for Check)",type:"password",value:v,onChange:n=>y(n.target.value)}),e.jsx(O,{label:"Model ID (optional)",value:u,onChange:n=>N(n.target.value),placeholder:"e.g. gpt-4, claude-3-opus",hint:"If provider lacks /models endpoint, enter a model ID to validate via chat/completions instead."}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsx(_,{onClick:g,disabled:!v||C||!s.baseUrl.trim(),variant:"secondary",className:"w-full sm:w-auto",children:C?"Checking...":"Check"}),o()]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(_,{onClick:x,fullWidth:!0,disabled:!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim()||h,children:h?"Creating...":"Create"}),e.jsx(_,{onClick:a,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}de.propTypes={isOpen:i.bool.isRequired,onClose:i.func.isRequired,onCreated:i.func.isRequired};function me({isOpen:r,onClose:a,onCreated:m}){const[s,l]=c.useState({name:"",prefix:"",baseUrl:"https://api.anthropic.com/v1"}),[h,w]=c.useState(!1),[v,y]=c.useState(""),[u,N]=c.useState(""),[C,p]=c.useState(!1),[I,j]=c.useState(null);c.useEffect(()=>{r&&(j(null),y(""),N(""))},[r]);const k=async()=>{if(!(!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim())){w(!0);try{const o=await fetch("/api/provider-nodes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.name,prefix:s.prefix,baseUrl:s.baseUrl,type:"anthropic-compatible"})}),n=await o.json();o.ok&&(m(n.node),l({name:"",prefix:"",baseUrl:"https://api.anthropic.com/v1"}),y(""),j(null))}catch(o){console.log("Error creating Anthropic Compatible node:",o)}finally{w(!1)}}},x=async()=>{p(!0);try{const n=await(await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:s.baseUrl,apiKey:v,type:"anthropic-compatible",modelId:u.trim()||void 0})})).json();j(n)}catch{j({valid:!1,error:"Network error"})}finally{p(!1)}},g=()=>{if(!I)return null;const{valid:o,error:n,method:b}=I;return o?e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"success",children:"Valid"}),b==="chat"&&e.jsx("span",{className:"text-sm text-text-muted",children:"(via inference test)"})]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(P,{variant:"error",children:"Invalid"}),n&&e.jsx("span",{className:"text-sm text-red-500",children:n})]})};return e.jsx(ie,{isOpen:r,title:"Add Anthropic Compatible",onClose:a,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(O,{label:"Name",value:s.name,onChange:o=>l({...s,name:o.target.value}),placeholder:"Anthropic Compatible (Prod)",hint:"Required. A friendly label for this node."}),e.jsx(O,{label:"Prefix",value:s.prefix,onChange:o=>l({...s,prefix:o.target.value}),placeholder:"ac-prod",hint:"Required. Used as the provider prefix for model IDs."}),e.jsx(O,{label:"Base URL",value:s.baseUrl,onChange:o=>l({...s,baseUrl:o.target.value}),placeholder:"https://api.anthropic.com/v1",hint:"Use the base URL (ending in /v1) for your Anthropic-compatible API. The system will append /messages."}),e.jsx(O,{label:"API Key (for Check)",type:"password",value:v,onChange:o=>y(o.target.value)}),e.jsx(O,{label:"Model ID (optional)",value:u,onChange:o=>N(o.target.value),placeholder:"e.g. claude-3-opus",hint:"If provider lacks /models endpoint, enter a model ID to validate via chat/completions instead."}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsx(_,{onClick:x,disabled:!v||C||!s.baseUrl.trim(),variant:"secondary",className:"w-full sm:w-auto",children:C?"Checking...":"Check"}),g()]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(_,{onClick:k,fullWidth:!0,disabled:!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim()||h,children:h?"Creating...":"Create"}),e.jsx(_,{onClick:a,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}me.propTypes={isOpen:i.bool.isRequired,onClose:i.func.isRequired,onCreated:i.func.isRequired};function pe({results:r}){if(r.error&&!r.results)return e.jsxs("div",{className:"text-center py-6",children:[e.jsx("span",{className:"material-symbols-outlined text-red-500 text-[32px] mb-2 block",children:"error"}),e.jsx("p",{className:"text-sm text-red-400",children:r.error})]});const{summary:a,mode:m}=r,s=r.results||[],l={oauth:"OAuth",free:"Free",apikey:"API Key",provider:"Provider",all:"All"}[m]||m;return e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[a&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs mb-1 sm:gap-3",children:[e.jsxs("span",{className:"text-text-muted",children:[l," Test"]}),e.jsxs("span",{className:"px-2 py-0.5 rounded bg-emerald-500/15 text-emerald-400 font-medium",children:[a.passed," passed"]}),a.failed>0&&e.jsxs("span",{className:"px-2 py-0.5 rounded bg-red-500/15 text-red-400 font-medium",children:[a.failed," failed"]}),e.jsxs("span",{className:"text-text-muted sm:ml-auto",children:[a.total," tested"]})]}),s.map((h,w)=>{var v;return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 rounded-lg bg-black/[0.03] px-3 py-2 text-xs dark:bg-white/[0.03] sm:flex-nowrap",children:[e.jsx("span",{className:`material-symbols-outlined text-[16px] ${h.valid?"text-emerald-500":"text-red-500"}`,children:h.valid?"check_circle":"error"}),e.jsxs("div",{className:"min-w-0 flex-[1_1_160px]",children:[e.jsx("span",{className:"block truncate font-medium sm:inline",children:h.connectionName}),e.jsxs("span",{className:"block truncate text-text-muted sm:ml-1.5 sm:inline",children:["(",h.provider,")"]})]}),h.latencyMs!==void 0&&e.jsxs("span",{className:"shrink-0 text-text-muted font-mono tabular-nums",children:[h.latencyMs,"ms"]}),e.jsx("span",{className:`shrink-0 text-[10px] uppercase font-bold px-1.5 py-0.5 rounded ${h.valid?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:h.valid?"OK":((v=h.diagnosis)==null?void 0:v.type)||"ERROR"})]},h.connectionId||w)}),s.length===0&&e.jsx("div",{className:"text-center py-4 text-text-muted text-sm",children:"No active connections found for this group."})]})}pe.propTypes={results:i.shape({mode:i.string,results:i.array,summary:i.shape({total:i.number,passed:i.number,failed:i.number}),error:i.string}).isRequired};export{De as default};
@@ -0,0 +1,64 @@
1
+ import{j as e,B as be,C as $t,g as Ae,M as gt,f as w,u as ve,i as Be,h as pe,N as bt,Q as yt,P as Pt,R as pt,S as Tt,V as _t}from"./index.C5VWu_q7.js";import{b as s,h as Lt,d as It,L as Dt}from"./router.Cjj1--8t.js";import{C as we,T as Ue,E as Ut,B as Oe,S as Ot,N as Bt,A as Kt}from"./NoAuthProxyCard.DMCykSRG.js";import"./zustand.akaTi5uX.js";const Ft={mode:{label:"Mode",format:t=>t},defaultModel:{label:"Model",format:t=>t,mono:!0},baseUrl:{label:"Endpoint",format:t=>t,isLink:!0,mono:!0},costPerQuery:{label:"Cost / call",format:t=>t===0?"Free":`$${t.toFixed(4)}`},pricingUrl:{label:"Pricing",format:()=>"View pricing",isLink:!0},freeTier:{label:"Free tier",format:t=>t},freeMonthlyQuota:{label:"Free quota",format:t=>t===0?"—":t>=999999?"Unlimited":`${t.toLocaleString()} / mo`},searchTypes:{label:"Types",format:t=>t.join(", ")},formats:{label:"Formats",format:t=>t.join(", ")},maxMaxResults:{label:"Max results",format:t=>t},maxCharacters:{label:"Max chars",format:t=>t.toLocaleString()}};function Vt({config:t,provider:r,title:i="Provider Info"}){var d,p;if(!t)return null;const S=Object.entries(Ft).filter(([h])=>t[h]!==void 0&&t[h]!==null&&t[h]!=="").map(([h,y])=>({key:h,label:y.label,value:y.format(t[h]),isLink:y.isLink,mono:y.mono,raw:t[h]})),c=((d=r==null?void 0:r.notice)==null?void 0:d.apiKeyUrl)||(r==null?void 0:r.website),M=(p=r==null?void 0:r.notice)==null?void 0:p.text;return e.jsxs(we,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:i}),c&&e.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"open_in_new"}),"Get API Key"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-2",children:[S.map(h=>e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:"text-xs text-text-muted w-28 shrink-0",children:h.label}),h.isLink?e.jsx("a",{href:h.raw,target:"_blank",rel:"noopener noreferrer",className:`text-sm text-primary hover:underline truncate ${h.mono?"font-mono":""}`,children:h.value}):e.jsx("span",{className:`text-sm text-text-main truncate ${h.mono?"font-mono":""}`,children:h.value})]},h.key)),M&&e.jsxs("div",{className:"flex items-start gap-3 min-w-0 sm:col-span-2",children:[e.jsx("span",{className:"text-xs text-text-muted w-28 shrink-0 mt-0.5",children:"Notice"}),e.jsx("span",{className:"text-sm text-text-main leading-relaxed",children:M})]})]})]})}function jt({until:t}){const[r,i]=s.useState("");return s.useEffect(()=>{const S=()=>{const M=new Date(t).getTime()-Date.now();if(M<=0){i("");return}const d=Math.floor(M/1e3);d<60?i(`${d}s`):d<3600?i(`${Math.floor(d/60)}m ${d%60}s`):i(`${Math.floor(d/3600)}h ${Math.floor(d%3600/60)}m`)};S();const c=setInterval(S,1e3);return()=>clearInterval(c)},[t]),r?e.jsxs("span",{className:"text-xs text-orange-500 font-mono",children:["⏱ ",r]}):null}jt.propTypes={until:w.string.isRequired};function vt({connection:t,proxyPools:r,isOAuth:i,isFirst:S,isLast:c,onMoveUp:M,onMoveDown:d,onToggleActive:p,onUpdateProxy:h,onEdit:y,onDelete:$}){var a,g,P,K,f,D;const[R,A]=s.useState(!1),[u,v]=s.useState(!1),[U,O]=s.useState(!1),L=s.useRef(null),I=new Map((r||[]).map(b=>[b.id,b])),j=((a=t.providerSpecificData)==null?void 0:a.proxyPoolId)||null,x=j?I.get(j):null,N=((g=t.providerSpecificData)==null?void 0:g.connectionProxyEnabled)===!0&&!!((P=t.providerSpecificData)!=null&&P.connectionProxyUrl),B=!!j||N,X=x?`Pool: ${x.name}`:j?`Pool: ${j} (inactive/missing)`:N?`Legacy: ${(K=t.providerSpecificData)==null?void 0:K.connectionProxyUrl}`:"";let Q="";const V=(x==null?void 0:x.proxyUrl)||((f=t.providerSpecificData)==null?void 0:f.connectionProxyUrl);if(V)try{const b=new URL(V);Q=`${b.protocol}//${b.hostname}${b.port?`:${b.port}`:""}`}catch{Q=V}const re=(x==null?void 0:x.noProxy)||((D=t.providerSpecificData)==null?void 0:D.connectionNoProxy)||"",ae=(x==null?void 0:x.isActive)===!0?"success":j||N?"error":"default",H=Object.entries(t).filter(([b])=>b.startsWith("modelLock_")).map(([,b])=>b).filter(Boolean).sort()[0]||null;s.useEffect(()=>{const b=()=>{const ne=Object.entries(t).filter(([G])=>G.startsWith("modelLock_")).map(([,G])=>G).filter(G=>G&&new Date(G).getTime()>Date.now()).sort()[0]||null;O(!!ne)};b();const Z=H?setInterval(b,1e3):null;return()=>{Z&&clearInterval(Z)}},[H]),s.useEffect(()=>{if(!R)return;const b=Z=>{L.current&&!L.current.contains(Z.target)&&A(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[R]);const W=t.testStatus==="unavailable"&&!U?"active":t.testStatus,le=()=>t.isActive===!1?"default":W==="active"||W==="success"?"success":W==="error"||W==="expired"||W==="unavailable"?"error":"default",m=i?t.name||t.email||t.displayName||"OAuth Account":t.name,o=async b=>{v(!0);try{await h(b==="__none__"?null:b)}finally{v(!1),A(!1)}};return e.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 ${t.isActive===!1?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex w-full min-w-0 flex-1 items-start gap-3 sm:items-center",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("button",{onClick:M,disabled:S,className:`p-0.5 rounded ${S?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:e.jsx("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_up"})}),e.jsx("button",{onClick:d,disabled:c,className:`p-0.5 rounded ${c?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:e.jsx("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_down"})})]}),e.jsx("span",{className:"material-symbols-outlined text-base text-text-muted",children:i?"lock":"key"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:m}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1",children:[e.jsx(Oe,{variant:le(),size:"sm",dot:!0,children:t.isActive===!1?"disabled":W||"Unknown"}),B&&e.jsx(Oe,{variant:ae,size:"sm",children:"Proxy"}),U&&t.isActive!==!1&&e.jsx(jt,{until:H}),t.lastError&&t.isActive!==!1&&e.jsx("span",{className:"text-xs text-red-500 truncate max-w-[300px]",title:t.lastError,children:t.lastError}),e.jsxs("span",{className:"text-xs text-text-muted",children:["#",t.priority]})]}),B&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-text-muted truncate max-w-[420px]",title:X,children:X}),Q&&e.jsx("code",{className:"text-[10px] font-mono bg-black/5 dark:bg-white/5 px-1 py-0.5 rounded text-text-muted",children:Q}),re&&e.jsxs("span",{className:"text-[11px] text-text-muted truncate max-w-[320px]",title:re,children:["no_proxy: ",re]})]})]})]}),e.jsxs("div",{className:"flex w-full flex-wrap items-center justify-between gap-2 sm:w-auto sm:justify-end",children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[(r||[]).length>0&&e.jsxs("div",{className:"relative",ref:L,children:[e.jsxs("button",{onClick:()=>A(b=>!b),className:`flex flex-col items-center px-2 py-1 rounded hover:bg-black/5 dark:hover:bg-white/5 transition-colors ${B?"text-primary":"text-text-muted hover:text-primary"}`,disabled:u,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:u?"progress_activity":"lan"}),e.jsx("span",{className:"text-[10px] leading-tight",children:"Proxy"})]}),R&&e.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:[e.jsx("button",{onClick:()=>o("__none__"),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${j?"text-text-main":"text-primary font-medium"}`,children:"None"}),(r||[]).map(b=>e.jsx("button",{onClick:()=>o(b.id),className:`w-full text-left px-3 py-1.5 text-sm hover:bg-black/5 dark:hover:bg-white/5 ${j===b.id?"text-primary font-medium":"text-text-main"}`,children:b.name},b.id))]})]}),e.jsxs("button",{onClick:y,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:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"edit"}),e.jsx("span",{className:"text-[10px] leading-tight",children:"Edit"})]}),e.jsxs("button",{onClick:$,className:"flex flex-col items-center px-2 py-1 rounded hover:bg-red-500/10 text-red-500",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"delete"}),e.jsx("span",{className:"text-[10px] leading-tight",children:"Delete"})]})]}),e.jsx(Ue,{size:"sm",checked:t.isActive??!0,onChange:p,title:t.isActive??!0?"Disable":"Enable"})]})]})}vt.propTypes={connection:w.shape({id:w.string,name:w.string,email:w.string,displayName:w.string,testStatus:w.string,isActive:w.bool,lastError:w.string,priority:w.number}).isRequired,proxyPools:w.array,isOAuth:w.bool.isRequired,isFirst:w.bool.isRequired,isLast:w.bool.isRequired,onMoveUp:w.func.isRequired,onMoveDown:w.func.isRequired,onToggleActive:w.func.isRequired,onUpdateProxy:w.func,onEdit:w.func.isRequired,onDelete:w.func.isRequired};function wt({isOpen:t,provider:r,providerName:i,proxyPools:S,onSave:c,onClose:M}){var j;const d="__none__",[p,h]=s.useState({name:"",apiKey:"",priority:1,proxyPoolId:d,supportsImageRef:!0,supportsVideoRef:!0,supportsStartEndFrame:!0}),[y,$]=s.useState(!1),[R,A]=s.useState(null),[u,v]=s.useState(!1),U=Ae[r],O=((j=U==null?void 0:U.serviceKinds)==null?void 0:j.includes("video"))||r==="leonardo"||r==="runwayml",L=async()=>{$(!0);try{const N=await(await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,apiKey:p.apiKey})})).json();A(N.valid?"success":"failed")}catch{A("failed")}finally{$(!1)}},I=async()=>{if(!(!r||!p.apiKey)){v(!0);try{let x=!1;try{$(!0),A(null),x=!!(await(await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:r,apiKey:p.apiKey})})).json()).valid,A(x?"success":"failed")}catch{A("failed")}finally{$(!1)}await c({name:p.name,apiKey:p.apiKey,priority:p.priority,proxyPoolId:p.proxyPoolId===d?null:p.proxyPoolId,testStatus:x?"active":"unknown",providerSpecificData:{supportsImageRef:p.supportsImageRef,supportsVideoRef:p.supportsVideoRef,supportsStartEndFrame:p.supportsStartEndFrame}})}finally{v(!1)}}};return r?e.jsx(gt,{isOpen:t,title:`Add ${i||r} API Key`,onClose:M,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-text-muted mb-1 block",children:"Name"}),e.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:p.name,onChange:x=>h({...p,name:x.target.value}),placeholder:"Production Key"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-xs text-text-muted mb-1 block",children:"API Key"}),e.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:p.apiKey,onChange:x=>h({...p,apiKey:x.target.value})})]}),e.jsx("div",{className:"pt-6",children:e.jsx(be,{onClick:L,disabled:!p.apiKey||y||u,variant:"secondary",children:y?"Checking...":"Check"})})]}),R&&e.jsx(Oe,{variant:R==="success"?"success":"error",children:R==="success"?"Valid":"Invalid"}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-text-muted mb-1 block",children:"Priority"}),e.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:p.priority,onChange:x=>h({...p,priority:Number.parseInt(x.target.value)||1})})]}),e.jsx(Ot,{label:"Proxy Pool",value:p.proxyPoolId,onChange:x=>h({...p,proxyPoolId:x.target.value}),options:[{value:d,label:"None"},...(S||[]).map(x=>({value:x.id,label:x.name}))]}),O&&e.jsxs("div",{className:"bg-sidebar/30 p-4 rounded-lg border border-accent/10 flex flex-col gap-3 my-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Capabilities"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Image Reference"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Supports image URL inputs as prompts"})]}),e.jsx(Ue,{checked:p.supportsImageRef??!0,onChange:x=>h({...p,supportsImageRef:x})})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-accent/5 pt-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Video Reference"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Supports video URL inputs as prompts"})]}),e.jsx(Ue,{checked:p.supportsVideoRef??!0,onChange:x=>h({...p,supportsVideoRef:x})})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-accent/5 pt-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Start/End Frame"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Supports specifying start/end frames"})]}),e.jsx(Ue,{checked:p.supportsStartEndFrame??!0,onChange:x=>h({...p,supportsStartEndFrame:x})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(be,{onClick:I,fullWidth:!0,disabled:!p.name||!p.apiKey||u,children:u?"Saving...":"Save"}),e.jsx(be,{onClick:M,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})}):null}wt.propTypes={isOpen:w.bool.isRequired,provider:w.string,providerName:w.string,proxyPools:w.array,onSave:w.func.isRequired,onClose:w.func.isRequired};function Nt({providerId:t,isOAuth:r}){const[i,S]=s.useState([]),[c,M]=s.useState([]),[d,p]=s.useState(!0),[h,y]=s.useState(!1),[$,R]=s.useState(!1),[A,u]=s.useState(null),[v,U]=s.useState(null),[O,L]=s.useState("1"),[I,j]=s.useState(null),[x,N]=s.useState(!1),B=s.useCallback(async()=>{try{const[o,a,g]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/proxy-pools?isActive=true",{cache:"no-store"}),fetch("/api/settings",{cache:"no-store"})]),P=await o.json(),K=await a.json(),f=g.ok?await g.json():{};o.ok&&S((P.connections||[]).filter(b=>b.provider===t)),a.ok&&M(K.proxyPools||[]);const D=(f.providerStrategies||{})[t]||{};U(D.fallbackStrategy||null),L(D.stickyRoundRobinLimit!=null?String(D.stickyRoundRobinLimit):"1")}catch(o){console.log("ConnectionsCard fetch error:",o)}finally{p(!1)}},[t]);s.useEffect(()=>{B()},[B]);const X=async(o,a)=>{try{const g=await fetch("/api/settings",{cache:"no-store"}),K=(g.ok?await g.json():{}).providerStrategies||{},f={};o&&(f.fallbackStrategy=o),o==="round-robin"&&a!==""&&(f.stickyRoundRobinLimit=Number(a)||3);const D={...K};Object.keys(f).length===0?delete D[t]:D[t]=f,await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerStrategies:D})})}catch(g){console.log("saveStrategy error:",g)}},Q=async(o,a)=>{const g=[...i];[g[o],g[a]]=[g[a],g[o]],S(g);try{await Promise.all([fetch(`/api/providers/${g[o].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:o})}),fetch(`/api/providers/${g[a].id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:a})})])}catch{await B()}},V=async o=>{j({title:"Delete Connection",message:"Delete this connection?",onConfirm:async()=>{j(null);try{(await fetch(`/api/providers/${o}`,{method:"DELETE"})).ok&&S(g=>g.filter(P=>P.id!==o))}catch(a){console.log("delete error:",a)}}})},re=async(o,a)=>{try{(await fetch(`/api/providers/${o}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:a})})).ok&&S(P=>P.map(K=>K.id===o?{...K,isActive:a}:K))}catch(g){console.log("toggle error:",g)}},ae=async(o,a)=>{try{(await fetch(`/api/providers/${o}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyPoolId:a||null})})).ok&&S(P=>P.map(K=>K.id===o?{...K,providerSpecificData:{...K.providerSpecificData,proxyPoolId:a||null}}:K))}catch(g){console.log("proxy error:",g)}},H=async()=>{if(i.length!==0){N(!0);try{await Promise.all(i.map(o=>fetch(`/api/providers/${o.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({testStatus:"active",lastError:"",lastErrorAt:null})}))),S(o=>o.map(a=>({...a,testStatus:"active",lastError:"",lastErrorAt:null})))}catch(o){console.log("reset all status error:",o)}finally{N(!1)}}},W=async o=>{try{(await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t,...o})})).ok&&(await B(),y(!1))}catch(a){console.log("save apikey error:",a)}},le=async o=>{try{(await fetch(`/api/providers/${A.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)})).ok&&(await B(),R(!1))}catch(a){console.log("update connection error:",a)}};if(d)return e.jsx(we,{children:e.jsx("div",{className:"h-20 animate-pulse bg-black/5 rounded-lg"})});const m=i.some(o=>o.lastError||o.testStatus==="error");return e.jsxs(e.Fragment,{children:[e.jsxs(we,{children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Connections"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.length>0&&e.jsxs("button",{onClick:H,disabled:x,title:"Reset testStatus and lastError for all connections",className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg border border-border text-xs text-text-muted hover:text-amber-500 hover:border-amber-500/40 hover:bg-amber-500/5 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:x?"progress_activity":"restart_alt"}),x?"Resetting...":"Reset All Status",m&&!x&&e.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-red-500/15 text-red-500 text-[10px] font-bold",children:"!"})]}),e.jsx("span",{className:"text-xs text-text-muted font-medium",children:"Round Robin"}),e.jsx(Ue,{checked:v==="round-robin",onChange:o=>{const a=o?"round-robin":null;U(a),o&&!O&&L("1"),X(a,o?O||"1":O)}}),v==="round-robin"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-text-muted",children:"Sticky:"}),e.jsx("input",{type:"number",min:1,value:O,onChange:o=>{L(o.target.value),X("round-robin",o.target.value)},className:"w-16 px-2 py-1 text-xs border border-border rounded-md bg-background focus:outline-none focus:border-primary"})]})]})]}),i.length===0?e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("p",{className:"text-sm text-text-muted",children:"No connections yet"}),e.jsx(be,{size:"sm",icon:"add",onClick:()=>y(!0),children:"Add Connection"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:i.map((o,a)=>e.jsx(vt,{connection:o,proxyPools:c,isOAuth:r,isFirst:a===0,isLast:a===i.length-1,onMoveUp:()=>Q(a,a-1),onMoveDown:()=>Q(a,a+1),onToggleActive:g=>re(o.id,g),onUpdateProxy:g=>ae(o.id,g),onEdit:()=>{u(o),R(!0)},onDelete:()=>V(o.id)},o.id))}),e.jsx("div",{className:"mt-4 flex justify-stretch sm:justify-start",children:e.jsx(be,{size:"sm",icon:"add",onClick:()=>y(!0),children:"Add"})})]})]}),e.jsx(wt,{isOpen:h,provider:t,proxyPools:c,onSave:W,onClose:()=>y(!1)}),e.jsx(Ut,{isOpen:$,connection:A,proxyPools:c,onSave:le,onClose:()=>R(!1)}),e.jsx($t,{isOpen:!!I,onClose:()=>j(null),onConfirm:I==null?void 0:I.onConfirm,title:(I==null?void 0:I.title)||"Confirm",message:I==null?void 0:I.message,variant:"danger"})]})}Nt.propTypes={providerId:w.string.isRequired,isOAuth:w.bool};function Xe({model:t,fullModel:r,copied:i,onCopy:S,testStatus:c,isCustom:M,isFree:d,onDeleteAlias:p,onTest:h,isTesting:y}){const $=c==="ok"?"border-green-500/40":c==="error"?"border-red-500/40":"border-border",R=c==="ok"?"#22c55e":c==="error"?"#ef4444":void 0;return e.jsx("div",{className:`group px-3 py-2 rounded-lg border ${$} hover:bg-sidebar/50`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-base",style:R?{color:R}:void 0,children:c==="ok"?"check_circle":c==="error"?"cancel":"smart_toy"}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:r}),t.name&&e.jsx("span",{className:"text-[9px] text-text-muted/70 italic pl-1",children:t.name})]}),h&&e.jsxs("div",{className:"relative group/btn",children:[e.jsx("button",{onClick:h,disabled:y,className:`p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary transition-opacity ${y?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:e.jsx("span",{className:"material-symbols-outlined text-sm",style:y?{animation:"spin 1s linear infinite"}:void 0,children:y?"progress_activity":"science"})}),e.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:y?"Testing...":"Test"})]}),e.jsxs("div",{className:"relative group/btn",children:[e.jsx("button",{onClick:()=>S(r,`model-${t.id}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",children:e.jsx("span",{className:"material-symbols-outlined text-sm",children:i===`model-${t.id}`?"check":"content_copy"})}),e.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:i===`model-${t.id}`?"Copied!":"Copy"})]}),d&&e.jsx("span",{className:"text-[10px] font-bold text-green-500 bg-green-500/10 px-1.5 py-0.5 rounded",children:"FREE"}),M&&e.jsx("button",{onClick:p,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:e.jsx("span",{className:"material-symbols-outlined text-sm",children:"close"})})]})})}Xe.propTypes={model:w.shape({id:w.string.isRequired}).isRequired,fullModel:w.string.isRequired,copied:w.string,onCopy:w.func.isRequired,testStatus:w.oneOf(["ok","error"]),isCustom:w.bool,isFree:w.bool,onDeleteAlias:w.func,onTest:w.func,isTesting:w.bool};function kt({isOpen:t,onSave:r,onClose:i}){const[S,c]=s.useState(""),M=()=>{S.trim()&&(r(S.trim()),c(""))};return e.jsx(gt,{isOpen:t,title:"Add Custom Model",onClose:i,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-text-muted mb-1 block",children:"Model ID"}),e.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:S,onChange:d=>c(d.target.value),onKeyDown:d=>d.key==="Enter"&&M(),placeholder:"e.g. tts-1-hd",autoFocus:!0})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(be,{onClick:M,fullWidth:!0,disabled:!S.trim(),children:"Add"}),e.jsx(be,{onClick:i,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}kt.propTypes={isOpen:w.bool.isRequired,onSave:w.func.isRequired,onClose:w.func.isRequired};function St({providerId:t,kindFilter:r,providerAliasOverride:i}){const{copied:S,copy:c}=ve(),[M,d]=s.useState({}),[p,h]=s.useState([]),[y,$]=s.useState({}),[R,A]=s.useState(null),[u,v]=s.useState(""),[U,O]=s.useState(!1),[L,I]=s.useState([]),j=i||Be(t),x=r||"llm",N=s.useCallback(async()=>{try{const[m,o,a]=await Promise.all([fetch("/api/models/alias"),fetch("/api/providers",{cache:"no-store"}),fetch("/api/models/custom",{cache:"no-store"})]),g=await m.json(),P=await o.json(),K=await a.json();m.ok&&d(g.aliases||{}),o.ok&&I((P.connections||[]).filter(f=>f.provider===t)),a.ok&&h(K.models||[])}catch(m){console.log("ModelsCard fetch error:",m)}},[t]);s.useEffect(()=>{N()},[N]);const B=async(m,o)=>{const a=`${j}/${m}`;try{(await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:a,alias:o})})).ok&&await N()}catch(g){console.log("set alias error:",g)}},X=async m=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(m)}`,{method:"DELETE"})).ok&&await N()}catch(o){console.log("delete alias error:",o)}},Q=async m=>{try{(await fetch("/api/models/custom",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerAlias:j,id:m,type:x})})).ok&&(await N(),window.dispatchEvent(new CustomEvent("customModelChanged")))}catch(o){console.log("add custom model error:",o)}},V=async m=>{try{const o=new URLSearchParams({providerAlias:j,id:m,type:x});(await fetch(`/api/models/custom?${o}`,{method:"DELETE"})).ok&&(await N(),window.dispatchEvent(new CustomEvent("customModelChanged")))}catch(o){console.log("delete custom model error:",o)}},re=async m=>{if(!R){A(m);try{const a=await(await fetch("/api/models/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:`${j}/${m}`,kind:r})})).json();$(g=>({...g,[m]:a.ok?"ok":"error"})),v(a.ok?"":a.error||"Model not reachable")}catch{$(o=>({...o,[m]:"error"})),v("Network error")}finally{A(null)}}},ae=pe(t),H=r?ae.filter(m=>m.kinds?m.kinds.includes(r):(m.type||"llm")===r):ae,W=p.filter(m=>m.providerAlias===j&&(m.type||"llm")===x&&!H.some(o=>o.id===m.id)),le=H;return e.jsxs(e.Fragment,{children:[e.jsxs(we,{children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("h2",{className:"text-lg font-semibold",children:["Models",r?` — ${r.toUpperCase()}`:""]})}),u&&e.jsx("p",{className:"text-xs text-red-500 mb-3 break-words",children:u}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[le.map(m=>{var g;const o=`${j}/${m.id}`,a=(g=Object.entries(M).find(([,P])=>P===o))==null?void 0:g[0];return e.jsx(Xe,{model:m,fullModel:`${j}/${m.id}`,alias:a,copied:S,onCopy:c,onSetAlias:P=>B(m.id,P),onDeleteAlias:()=>X(a),testStatus:y[m.id],onTest:L.length>0?()=>re(m.id):void 0,isTesting:R===m.id,isFree:m.isFree},m.id)}),W.map(m=>e.jsx(Xe,{model:{id:m.id,name:m.name},fullModel:`${j}/${m.id}`,copied:S,onCopy:c,onSetAlias:()=>{},onDeleteAlias:()=>V(m.id),testStatus:y[m.id],onTest:L.length>0?()=>re(m.id):void 0,isTesting:R===m.id,isCustom:!0},`${m.id}-${m.type}`)),e.jsxs("button",{onClick:()=>O(!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:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"add"}),"Add Model"]})]})]}),e.jsx(kt,{isOpen:U,onSave:async m=>{await Q(m),O(!1)},onClose:()=>O(!1)})]})}St.propTypes={providerId:w.string.isRequired,kindFilter:w.string,providerAliasOverride:w.string};const xt={"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"},minimax:{hasModelSelector:!0,hasBrowseButton:!0,hasVoiceIdInput:!0,voiceSource:"api-language",apiEndpoint:"/api/media-providers/tts/minimax/voices",defaultVoiceId:"English_expressive_narrator"},"minimax-cn":{hasModelSelector:!0,hasBrowseButton:!0,hasVoiceIdInput:!0,voiceSource:"api-language",apiEndpoint:"/api/media-providers/tts/minimax/voices?provider=minimax-cn",defaultVoiceId:"English_expressive_narrator"},gemini:{hasLanguageDropdown:!1,hasLanguageHint:!0,hasModelSelector:!0,hasBrowseButton:!1,voiceSource:"hardcoded",modelKey:"gemini-tts-models",voiceKey:"gemini-tts-voices",voicesPerModel:!0}};function _({label:t,children:r}){return e.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-3",children:[e.jsx("span",{className:"w-full text-xs font-medium text-text-muted sm:w-20 sm:shrink-0",children:t}),e.jsx("div",{className:"w-full min-w-0 flex-1",children:r})]})}const qt=`// Audio will appear here after running.
2
+ // Example JSON response (response_format=json):
3
+ {
4
+ "format": "mp3",
5
+ "audio": "//NExAANaAIIAUAAANNNNNNNN..." // base64 encoded MP3
6
+ }`,Jt=`{
7
+ "object": "list",
8
+ "data": [{
9
+ "object": "embedding",
10
+ "index": 0,
11
+ "embedding": [0.002301, -0.019212, 0.004815, -0.031249, ...]
12
+ }],
13
+ "model": "...",
14
+ "usage": { "prompt_tokens": 9, "total_tokens": 9 }
15
+ }`,ft="https://pub-1fb693cb11cc46b2b2f656f51e015a2c.r2.dev/dog.png",zt="https://pub-1fb693cb11cc46b2b2f656f51e015a2c.r2.dev/dog-mask.png";function Ht(t,r){return t!=="cloudflare-ai"?{}:r==="@cf/runwayml/stable-diffusion-v1-5-img2img"?{image:ft}:r==="@cf/runwayml/stable-diffusion-v1-5-inpainting"?{image:ft,mask_image:zt}:{}}function ht(t){const r=typeof t=="string"?t.trim():"";return r?/^(data:image\/|https?:\/\/)/i.test(r)?r:`data:image/png;base64,${r}`:""}const Ct={webSearch:{inputLabel:"Query",inputPlaceholder:"What is the latest news about AI?",defaultInput:"What is the latest news about AI?",bodyKey:"query",defaultResponse:`{
16
+ "results": [
17
+ { "title": "...", "url": "...", "snippet": "..." }
18
+ ]
19
+ }`,extraFields:[{key:"search_type",label:"Type",type:"select",default:"web",options:["web","news"]},{key:"max_results",label:"Max results",type:"number",default:5,min:1,max:100},{key:"country",label:"Country",type:"text",default:""},{key:"language",label:"Language",type:"text",default:""}]},webFetch:{inputLabel:"URL",inputPlaceholder:"https://example.com",defaultInput:"https://example.com",bodyKey:"url",defaultResponse:`{
20
+ "content": "...",
21
+ "title": "...",
22
+ "url": "..."
23
+ }`,extraFields:[{key:"format",label:"Format",type:"select",default:"markdown",options:["markdown","text","html"]},{key:"max_characters",label:"Max chars",type:"number",default:0,min:0}]},image:{inputLabel:"Prompt",inputPlaceholder:"A cute cat wearing a hat",defaultInput:"A cute cat wearing a hat",bodyKey:"prompt",defaultResponse:`{
24
+ "data": [
25
+ { "url": "...", "b64_json": "..." }
26
+ ]
27
+ }`,extraFields:[{key:"n",label:"n",type:"number",default:1,min:1,max:4},{key:"size",label:"Size",type:"select",default:"auto",options:["auto","1024x1024","1024x1536","1536x1024","1024x1792","1792x1024"]},{key:"quality",label:"Quality",type:"select",default:"auto",options:["auto","low","medium","high","standard","hd"]},{key:"background",label:"Background",type:"select",default:"auto",options:["auto","transparent","opaque"]},{key:"style",label:"Style",type:"select",default:"",options:["","vivid","natural"]},{key:"response_format",label:"Format",type:"select",default:"",options:["","url","b64_json"]},{key:"image_detail",label:"Image Detail",type:"select",default:"high",options:["auto","low","high","original"]},{key:"output_format",label:"Codec",type:"select",default:"png",options:["png","jpeg","webp"]}]},imageToText:{inputLabel:"Image URL",inputPlaceholder:"https://example.com/image.png",defaultInput:"https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg",bodyKey:"url",extraBody:{prompt:"Describe this image in detail"},defaultResponse:`{
28
+ "text": "A cat sitting on a windowsill...",
29
+ "model": "..."
30
+ }`},video:{inputLabel:"Prompt",inputPlaceholder:"A serene lake at sunset",defaultInput:"A serene lake at sunset",bodyKey:"prompt",defaultResponse:`{
31
+ "data": [
32
+ { "url": "..." }
33
+ ]
34
+ }`,extraFields:[{key:"duration",label:"Duration (seconds)",type:"number",default:5,min:1,max:10},{key:"resolution",label:"Resolution",type:"select",default:"720",options:["480","720","1080"]},{key:"aspect_ratio",label:"Aspect Ratio",type:"select",default:"16:9",options:["16:9","9:16","1:1"]},{key:"image_url",label:"Image Reference (URL)",type:"text",default:"",placeholder:"https://example.com/image.png"},{key:"video_url",label:"Video Reference (URL)",type:"text",default:"",placeholder:"https://example.com/video.mp4"},{key:"motion_strength",label:"Motion Strength",type:"number",default:5,min:1,max:10}]},music:{inputLabel:"Prompt",inputPlaceholder:"A calm piano melody",defaultInput:"A calm piano melody",bodyKey:"prompt",defaultResponse:`{
35
+ "data": [
36
+ { "url": "...", "format": "mp3" }
37
+ ]
38
+ }`}};function Wt({providerId:t,customAlias:r}){var K;const i=yt(t),S=i?r||t:Be(t),c=i?[]:pe(t).filter(f=>f.type==="embedding"),[M,d]=s.useState(((K=c[0])==null?void 0:K.id)??""),[p,h]=s.useState("The quick brown fox jumps over the lazy dog"),[y,$]=s.useState(""),[R,A]=s.useState(""),[u,v]=s.useState(!1),[U,O]=s.useState(""),[L,I]=s.useState(""),[j,x]=s.useState(null),[N,B]=s.useState(!1),[X,Q]=s.useState(""),{copied:V,copy:re}=ve(),{copied:ae,copy:H}=ve();s.useEffect(()=>{O(window.location.origin),fetch("/api/keys").then(f=>f.json()).then(f=>{var D;A(((D=(f.keys||[]).find(b=>b.isActive!==!1))==null?void 0:D.key)||"")}).catch(()=>{}),fetch("/api/tunnel/status").then(f=>f.json()).then(f=>{f.publicUrl&&I(f.publicUrl)}).catch(()=>{})},[]);const W=u?L:U,le=M?`${S}/${M}`:"",m=()=>{const f={model:le,input:p.trim()},D=Number(y);return y&&Number.isFinite(D)&&D>0&&(f.dimensions=D),f},o=`curl -X POST ${W}/v1/embeddings \\
39
+ -H "Content-Type: application/json" \\
40
+ -H "Authorization: Bearer ${R||"YOUR_KEY"}" \\
41
+ -d '${JSON.stringify(m())}'`,a=async()=>{var D;if(!p.trim()||!le)return;B(!0),Q(""),x(null);const f=Date.now();try{const b={"Content-Type":"application/json"};R&&(b.Authorization=`Bearer ${R}`);const Z=await fetch("/api/v1/embeddings",{method:"POST",headers:b,body:JSON.stringify(m())}),ne=Date.now()-f,G=await Z.json();if(!Z.ok){Q(((D=G==null?void 0:G.error)==null?void 0:D.message)||(G==null?void 0:G.error)||`HTTP ${Z.status}`);return}x({data:G,latencyMs:ne})}catch(b){Q(b.message||"Network error")}finally{B(!1)}},g=f=>{if(!f)return Jt;const D=JSON.parse(JSON.stringify(f));return(D.data||[]).forEach(b=>{Array.isArray(b.embedding)&&b.embedding.length>4&&(b.embedding=[...b.embedding.slice(0,4).map(Z=>parseFloat(Z.toFixed(6))),`... (${b.embedding.length} dims)`])}),JSON.stringify(D,null,2)},P=j?JSON.stringify(j.data,null,2):"";return e.jsxs(we,{children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Example"}),e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(_,{label:"Model",children:i?e.jsx("input",{value:M,onChange:f=>d(f.target.value),placeholder:"e.g. voyage-3, embed-english-v3.0, text-embedding-3-small",className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary font-mono"}):e.jsx("select",{value:M,onChange:f=>d(f.target.value),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:c.map(f=>e.jsx("option",{value:f.id,children:f.name||f.id},f.id))})}),e.jsx(_,{label:"Endpoint",children:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsx("input",{value:W,onChange:f=>u?I(f.target.value):O(f.target.value),className:"w-full min-w-0 flex-1 px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary font-mono",placeholder:"http://localhost:3000"}),L&&e.jsxs("button",{onClick:()=>v(f=>!f),title:u?"Using tunnel":"Using local",className:`flex items-center gap-1 text-xs px-2 py-1.5 rounded-lg border shrink-0 transition-colors ${u?"border-primary/40 bg-primary/10 text-primary":"border-border text-text-muted hover:text-primary"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"wifi_tethering"}),"Tunnel"]})]})}),e.jsx(_,{label:"API Key",children:e.jsx("input",{type:"password",value:R,onChange:f=>A(f.target.value),placeholder:"sk-...",className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary font-mono"})}),e.jsx(_,{label:"Input",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:p,onChange:f=>h(f.target.value),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"}),p&&e.jsx("button",{type:"button",onClick:()=>h(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-muted hover:text-primary transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]})}),e.jsx(_,{label:"Dimensions",children:e.jsx("input",{type:"number",min:"1",value:y,onChange:f=>$(f.target.value),placeholder:"optional, e.g. 512, 1024 (leave empty for default)",className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})}),e.jsxs("div",{className:"mt-1",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Request"}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsxs("button",{onClick:()=>re(o),className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:V?"check":"content_copy"}),V?"Copied":"Copy"]}),e.jsxs("button",{onClick:a,disabled:N||!p.trim()||!le,className:"flex w-full sm:w-auto items-center justify-center gap-1.5 px-3 py-1 rounded-lg bg-primary text-white text-xs font-medium hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",style:N?{animation:"spin 1s linear infinite"}:void 0,children:"play_arrow"}),N?"Running...":"Run"]})]})]}),e.jsx("pre",{className:"bg-sidebar rounded-lg px-3 py-2.5 text-xs font-mono text-text-main overflow-x-auto whitespace-pre-wrap break-all",children:o})]}),X&&e.jsx("p",{className:"text-xs text-red-500 break-words",children:X}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-1.5",children:[e.jsxs("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:["Response ",j&&e.jsxs("span",{className:"font-normal normal-case",children:["⚡ ",j.latencyMs,"ms"]})]}),j&&e.jsxs("button",{onClick:()=>H(P),className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:ae?"check":"content_copy"}),ae?"Copied":"Copy"]})]}),e.jsx("pre",{className:"bg-sidebar rounded-lg px-3 py-2.5 text-xs font-mono text-text-main overflow-x-auto whitespace-pre-wrap break-all opacity-70",children:g(j==null?void 0:j.data)})]})]})]})}function Gt({providerId:t}){var Te,Fe,_e,Ce,Ee,Le,Ve;const r=Be(t),i=xt[t]||xt["edge-tts"],[S,c]=s.useState(i.defaultVoiceId||""),[M,d]=s.useState(""),[p,h]=s.useState(i.defaultVoiceId||""),[y,$]=s.useState([]),[R,A]=s.useState(""),[u,v]=s.useState(()=>{var Y,E,F;const n=(E=(Y=Ae[t])==null?void 0:Y.ttsConfig)==null?void 0:E.models;if(n!=null&&n.length)return n[0].id;if(i.hasModelSelector&&i.modelKey){const z=pe(i.modelKey);return((F=z==null?void 0:z[0])==null?void 0:F.id)||""}return""}),[U,O]=s.useState("Hello, this is a text to speech test."),[L,I]=s.useState(""),[j,x]=s.useState(!1),[N,B]=s.useState(""),[X,Q]=s.useState(""),[V,re]=s.useState("mp3"),[ae,H]=s.useState(""),[W,le]=s.useState(null),[m,o]=s.useState(!1),[a,g]=s.useState(""),[P,K]=s.useState(null),{copied:f,copy:D}=ve(),[b,Z]=s.useState(!1),[ne,G]=s.useState([]),[ue,ye]=s.useState(!1),[xe,C]=s.useState(""),[J,ee]=s.useState(""),[ce,fe]=s.useState({}),[Ne,de]=s.useState("");s.useEffect(()=>{var n,Y;if(B(window.location.origin),fetch("/api/keys").then(E=>E.json()).then(E=>{var F;I(((F=(E.keys||[]).find(z=>z.isActive!==!1))==null?void 0:F.key)||"")}).catch(()=>{}),fetch("/api/tunnel/status").then(E=>E.json()).then(E=>{E.publicUrl&&Q(E.publicUrl)}).catch(()=>{}),i.voiceSource==="hardcoded"){const E=i.hasModelSelector&&i.modelKey&&((Y=(n=pe(i.modelKey))==null?void 0:n[0])==null?void 0:Y.id)||"",F=i.voicesPerModel&&E?pt(t,E)||[]:pe(i.voiceKey||t).filter(z=>z.type==="tts");if(F.length)if(i.hasBrowseButton){const z=F.find(ie=>ie.id==="en")||F[0];A(z.id),c(z.id),d(z.name),$([{id:z.id,name:z.name}])}else $(F),c(F[0].id),d(F[0].name||F[0].id)}},[t]),s.useEffect(()=>{if(!i.voicesPerModel||!u)return;const n=pt(t,u)||[];$(n),n.length&&(c(n[0].id),d(n[0].name||n[0].id))},[u]);const Me=async()=>{if(Z(!0),C(""),ee(""),!ne.length){ye(!0);try{if(i.voiceSource==="hardcoded"){const n=i.voiceKey||t,Y=pe(n).filter(F=>F.type==="tts"),E={};for(const F of Y)E[F.id]||(E[F.id]={code:F.id,name:F.name,voices:[{id:F.id,name:F.name}]});fe(E),G(Object.values(E).sort((F,z)=>F.name.localeCompare(z.name)))}else{const n=i.apiEndpoint?i.apiEndpoint:`/api/media-providers/tts/voices?provider=${t==="local-device"?"local-device":"edge-tts"}`,E=await(await fetch(n)).json();if(E.error){ee(E.error);return}G(E.languages||[]),fe(E.byLang||{})}}catch(n){ee(n.message)}finally{ye(!1)}}},ze=n=>{var E;Z(!1),A(n.code);const Y=((E=ce[n.code])==null?void 0:E.voices)||[];$(Y),Y.length&&(c(Y[0].id),d(Y[0].name),i.hasVoiceIdInput&&h(Y[0].id))},$e=xe?ne.filter(n=>n.name.toLowerCase().includes(xe.toLowerCase())||n.code.toLowerCase().includes(xe.toLowerCase())):ne,Pe=j?X:N,ge=i.hasVoiceIdInput&&p||S,je=i.hasModelSelector&&u&&ge?`${r}/${u}/${ge}`:i.hasModelSelector&&u?`${r}/${u}`:ge?`${r}/${ge}`:"",ke=(()=>{const n={model:je,input:U};return i.hasLanguageHint&&Ne&&(n.language=Ne),n})(),Se=`curl -X POST ${Pe}/v1/audio/speech${V==="json"?"?response_format=json":""} \\
42
+ -H "Content-Type: application/json" \\
43
+ -H "Authorization: Bearer ${L||"YOUR_KEY"}" \\
44
+ -d '${JSON.stringify(ke)}' \\
45
+ ${V==="json"?"":"--output speech.mp3"}`,Ke=async()=>{var Y;if(!U.trim()||!je)return;o(!0),g(""),H(""),le(null);const n=Date.now();try{const E={"Content-Type":"application/json"};L&&(E.Authorization=`Bearer ${L}`);const z=await fetch(`/api/v1/audio/speech${V==="json"?"?response_format=json":""}`,{method:"POST",headers:E,body:JSON.stringify({...ke,input:U.trim()})});if(K(Date.now()-n),!z.ok){const ie=await z.json().catch(()=>({}));g(((Y=ie==null?void 0:ie.error)==null?void 0:Y.message)||(ie==null?void 0:ie.error)||`HTTP ${z.status}`);return}if(V==="json"){const ie=await z.json();le(ie);const qe=await fetch(`data:audio/mp3;base64,${ie.audio}`).then(Je=>Je.blob());H(URL.createObjectURL(qe))}else{const ie=await z.blob();H(URL.createObjectURL(ie))}}catch(E){g(E.message||"Network error")}finally{o(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs(we,{children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Example"}),e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(_,{label:"Endpoint",children:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsxs("span",{className:"w-full min-w-0 flex-1 px-3 py-1.5 text-sm font-mono text-text-main bg-sidebar rounded-lg truncate",children:[Pe,"/v1/audio/speech"]}),X&&e.jsxs("button",{onClick:()=>x(n=>!n),title:j?"Using tunnel":"Using local",className:`flex items-center gap-1 text-xs px-2 py-1.5 rounded-lg border shrink-0 transition-colors ${j?"border-primary/40 bg-primary/10 text-primary":"border-border text-text-muted hover:text-primary"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"wifi_tethering"}),"Tunnel"]})]})}),e.jsx(_,{label:"API Key",children:e.jsx("span",{className:"px-3 py-1.5 text-sm font-mono text-text-main bg-sidebar rounded-lg truncate block",children:L?`${L.slice(0,8)}${"•".repeat(Math.min(20,L.length-8))}`:e.jsx("span",{className:"text-text-muted italic",children:"No key configured"})})}),i.hasModelSelector&&(i.modelKey||((_e=(Fe=(Te=Ae[t])==null?void 0:Te.ttsConfig)==null?void 0:Fe.models)==null?void 0:_e.length))&&e.jsx(_,{label:"Model",children:e.jsx("select",{value:u,onChange:n=>v(n.target.value),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:(((Le=(Ee=(Ce=Ae[t])==null?void 0:Ce.ttsConfig)==null?void 0:Ee.models)!=null&&Le.length?Ae[t].ttsConfig.models:pe(i.modelKey))||[]).map(n=>e.jsx("option",{value:n.id,children:n.name||n.id},n.id))})}),i.hasLanguageHint&&e.jsx(_,{label:"Language",children:e.jsxs("select",{value:Ne,onChange:n=>de(n.target.value),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[e.jsx("option",{value:"",children:"Auto-detect"}),Tt.map(n=>e.jsx("option",{value:n.name,children:n.name},n.id))]})}),i.hasBrowseButton&&e.jsx(_,{label:"Language",children:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsx("button",{onClick:Me,className:"w-full min-w-0 flex-1 px-3 py-1.5 text-sm border border-border rounded-lg bg-background font-mono truncate text-left hover:border-primary/40 transition-colors",children:R?e.jsx("span",{className:"text-text-main",children:((Ve=ne.find(n=>n.code===R))==null?void 0:Ve.name)||R}):e.jsx("span",{className:"text-text-muted",children:"No language selected"})}),e.jsxs("button",{onClick:Me,className:"flex w-full items-center justify-center gap-1 text-xs px-2.5 py-1.5 rounded-lg border border-border text-text-muted hover:text-primary hover:border-primary/40 transition-colors sm:w-auto sm:shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"language"}),"Select language"]})]})}),y.length>0&&e.jsx(_,{label:"Voice",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:y.map(n=>e.jsxs("button",{onClick:()=>{c(n.id),d(n.name),i.hasVoiceIdInput&&h(n.id)},className:`px-2.5 py-1 rounded-full text-xs border transition-colors ${S===n.id?"bg-primary/15 border-primary/40 text-primary font-medium":"border-border text-text-muted hover:text-primary hover:border-primary/40"}`,children:[n.name,n.gender?` · ${n.gender[0].toUpperCase()}`:"",n.free_users_allowed===!0&&e.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-semibold rounded bg-green-500/15 text-green-600 border border-green-500/20",children:"Free"}),n.free_users_allowed===!1&&e.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-semibold rounded bg-amber-500/15 text-amber-600 border border-amber-500/20",children:"Paid"})]},n.id))})}),i.hasVoiceIdInput&&e.jsx(_,{label:"Voice ID",children:e.jsx("div",{className:"flex flex-col gap-1",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:p,onChange:n=>{h(n.target.value),c(n.target.value)},placeholder:"e.g. CwhRBWXzGAHq8TQ4Fs17",className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary font-mono"}),p&&e.jsx("button",{type:"button",onClick:()=>{h(""),c("")},className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-muted hover:text-primary transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]})})}),i.hasLanguageDropdown&&e.jsx(_,{label:"Language",children:e.jsx("select",{value:S,onChange:n=>{const Y=pe(t).filter(E=>E.type==="tts").find(E=>E.id===n.target.value);c(n.target.value),d((Y==null?void 0:Y.name)||n.target.value)},className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:pe(t).filter(n=>n.type==="tts").map(n=>e.jsx("option",{value:n.id,children:n.name||n.id},n.id))})}),e.jsx(_,{label:"Input",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:U,onChange:n=>O(n.target.value),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"}),U&&e.jsx("button",{type:"button",onClick:()=>O(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-muted hover:text-primary transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]})}),e.jsx(_,{label:"Output Format",children:e.jsxs("select",{value:V,onChange:n=>re(n.target.value),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[e.jsx("option",{value:"mp3",children:"MP3 (Binary)"}),e.jsx("option",{value:"json",children:"JSON (Base64)"})]})}),e.jsxs("div",{className:"mt-1",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Request"}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsxs("button",{onClick:()=>D(Se),className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:f?"check":"content_copy"}),f?"Copied":"Copy"]}),e.jsxs("button",{onClick:Ke,disabled:m||!U.trim()||!je,className:"flex w-full sm:w-auto items-center justify-center gap-1.5 px-3 py-1 rounded-lg bg-primary text-white text-xs font-medium hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",style:m?{animation:"spin 1s linear infinite"}:void 0,children:"play_arrow"}),m?"Generating...":"Run"]})]})]}),e.jsx("pre",{className:"bg-sidebar rounded-lg px-3 py-2.5 text-xs font-mono text-text-main overflow-x-auto whitespace-pre-wrap break-all",children:Se})]}),a&&e.jsx("p",{className:"text-xs text-red-500 break-words",children:a}),ae?e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-1.5",children:[e.jsxs("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:["Response ",P&&e.jsxs("span",{className:"font-normal normal-case",children:["⚡ ",P,"ms"]})]}),e.jsxs("a",{href:ae,download:"speech.mp3",className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"download"}),"Download"]})]}),e.jsx("audio",{controls:!0,src:ae,className:"w-full"}),W&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-1.5",children:e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"JSON Response"})}),e.jsx("pre",{className:"bg-sidebar rounded-lg px-3 py-2.5 text-xs font-mono text-text-main overflow-x-auto whitespace-pre-wrap break-all",children:JSON.stringify({format:W.format,audio:W.audio?`${W.audio.substring(0,100)}...`:""},null,2)})]})]}):e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Response"}),e.jsx("pre",{className:"mt-1.5 bg-sidebar rounded-lg px-3 py-2.5 text-xs font-mono text-text-main overflow-x-auto whitespace-pre-wrap break-all opacity-50",children:qt})]})]})]}),b&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-end justify-center sm:items-center",style:{backgroundColor:"rgba(0,0,0,0.6)",backdropFilter:"blur(2px)"},onClick:()=>Z(!1),children:e.jsxs("div",{className:"border border-border rounded-xl shadow-2xl w-full max-w-md mx-4 flex flex-col max-h-[80vh]",style:{backgroundColor:"var(--color-bg)",isolation:"isolate"},onClick:n=>n.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0 rounded-t-xl",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Select Language"}),e.jsx("button",{onClick:()=>Z(!1),className:"text-text-muted hover:text-primary transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsx("div",{className:"px-4 py-2.5 border-b border-border shrink-0",children:e.jsx("input",{autoFocus:!0,value:xe,onChange:n=>C(n.target.value),placeholder:"Search language...",className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})}),e.jsxs("div",{className:"overflow-y-auto flex-1 p-2",children:[J&&e.jsx("p",{className:"text-xs text-red-500 px-2 py-1",children:J}),ue?e.jsx("p",{className:"text-xs text-text-muted px-2 py-3",children:"Loading..."}):e.jsxs("div",{className:"flex flex-col gap-0.5",children:[$e.map(n=>e.jsxs("button",{onClick:()=>ze(n),className:`flex items-center justify-between w-full px-3 py-2 rounded-lg text-left hover:bg-sidebar transition-colors ${R===n.code?"bg-primary/10 text-primary":""}`,children:[e.jsx("span",{className:"text-sm",children:n.name}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("span",{className:"text-xs text-text-muted",children:[n.voices.length," voices"]}),R===n.code&&e.jsx("span",{className:"material-symbols-outlined text-[16px] text-primary",children:"check"})]})]},n.code)),$e.length===0&&e.jsx("p",{className:"text-xs text-text-muted px-2 py-3",children:"No languages found."})]})]})]})})]})}function Yt({providerId:t,kind:r}){var z,ie,qe,Je,Qe,Ze,et,tt,st,at,nt,ot,rt,lt,it,ct,dt,ut,mt;const i=Be(t),c=_t(i)===t?i:t,M=bt.find(l=>l.id===r),d=Ct[r],p=d||{},h=pe(t).filter(l=>l.type===r),$=new Set(["image","video","music","imageToText"]).has(r),R=$&&h.length===0,[A,u]=s.useState(((z=h[0])==null?void 0:z.id)??""),v=h.find(l=>l.id===A),U=!!((ie=v==null?void 0:v.capabilities)!=null&&ie.includes("edit")),O=!!((qe=v==null?void 0:v.capabilities)!=null&&qe.includes("mask")),[L,I]=s.useState(p.defaultInput||""),[j,x]=s.useState(""),[N,B]=s.useState(""),[X,Q]=s.useState(()=>(p.extraFields||[]).reduce((l,k)=>(l[k.key]=k.default??"",l),{})),[V,re]=s.useState(""),[ae,H]=s.useState(!1),[W,le]=s.useState(""),[m,o]=s.useState(""),[a,g]=s.useState(null),[P,K]=s.useState(null),[f,D]=s.useState(null),[b,Z]=s.useState("json"),[ne,G]=s.useState(""),[ue,ye]=s.useState(!1),[xe,C]=s.useState(""),[J,ee]=s.useState([]),[ce,fe]=s.useState(""),{copied:Ne,copy:de}=ve(),{copied:Me,copy:ze}=ve();if(s.useEffect(()=>{le(window.location.origin),fetch("/api/keys").then(l=>l.json()).then(l=>{var k;re(((k=(l.keys||[]).find(T=>T.isActive!==!1))==null?void 0:k.key)||"")}).catch(()=>{}),fetch("/api/tunnel/status").then(l=>l.json()).then(l=>{l.publicUrl&&o(l.publicUrl)}).catch(()=>{}),fetch("/api/providers/client").then(l=>l.json()).then(l=>{const k=(l.connections||[]).filter(T=>T.provider===t&&T.isActive!==!1);ee(k)}).catch(()=>{})},[t]),s.useEffect(()=>{v&&Q(l=>{const k={...l};let T=!1;return(p.extraFields||[]).forEach(te=>{const se=Array.isArray(v==null?void 0:v.paramDefs)?v.paramDefs.find(oe=>oe.name===te.key):null,q=(se==null?void 0:se.validValues)||te.options||[],he=l[te.key];if(he&&q.length>0&&!q.includes(he)){const oe=(se==null?void 0:se.default)??q[0]??"";oe!==he&&(k[te.key]=oe,T=!0)}}),T?k:l})},[A,v,p.extraFields]),!M||!d)return null;const $e=ae?m:W,Pe=M.endpoint.path,ge=$?A?`${c}/${A}`:R?"":c:c,je=Ht(t,A),ke=j.trim()||je.image||"",Se=N.trim()||je.mask_image||"",Ke=ht(ke),Te=ht(Se),Fe=Object.entries(X).reduce((l,[k,T])=>(T===""||T===null||T===void 0||typeof T=="number"&&Number.isNaN(T)||(l[k]=T),l),{}),_e={model:ge,[d.bodyKey]:L,...d.extraBody,...Fe,...U&&ke?{image:ke}:{},...O&&Se?{mask_image:Se}:{}},Ce=r==="image"&&b==="binary",Ee=r==="image"&&t==="codex"&&!Ce,Le=`${Pe}${Ce?"?response_format=binary":""}`,Ve=`-H "Content-Type: application/json" \\
46
+ -H "Authorization: Bearer ${V||"YOUR_KEY"}"${ce?` \\
47
+ -H "x-connection-id: ${ce}"`:""}${Ee?` \\
48
+ -H "Accept: text/event-stream"`:""}`,n=`curl -X ${M.endpoint.method} ${$e}${Le} \\
49
+ ${Ve.replace(/\\\n /g,`\\
50
+ `)} \\
51
+ -d '${JSON.stringify(_e)}'${Ce?` \\
52
+ --output image.png`:""}`,Y=async()=>{var k;if(!L.trim()||!ge)return;if(ye(!0),C(""),g(null),K(null),D(null),ne){try{URL.revokeObjectURL(ne)}catch{}G("")}const l=Date.now();try{const T={"Content-Type":"application/json"};V&&(T.Authorization=`Bearer ${V}`),ce&&(T["x-connection-id"]=ce),Ee&&(T.Accept="text/event-stream");const te={..._e,model:ge},se=await fetch(`/api${Le}`,{method:M.endpoint.method,headers:T,body:JSON.stringify(te)});if(!se.ok){const oe=await se.json().catch(()=>({}));C(((k=oe==null?void 0:oe.error)==null?void 0:k.message)||(oe==null?void 0:oe.error)||`HTTP ${se.status}`);return}const q=se.headers.get("content-type")||"";if(q.startsWith("image/")){const oe=await se.blob(),Ie=URL.createObjectURL(oe);G(Ie),g({data:{binary:!0,mime:q,size:oe.size},latencyMs:Date.now()-l});return}if(q.includes("text/event-stream")&&se.body){const oe=se.body.getReader(),Ie=new TextDecoder;let De="",He=null,We=null;for(;;){const{done:Rt,value:At}=await oe.read();if(Rt)break;De+=Ie.decode(At,{stream:!0});let Ge;for(;(Ge=De.indexOf(`
53
+
54
+ `))!==-1;){const Mt=De.slice(0,Ge);De=De.slice(Ge+2);let Re=null,Ye="";for(const me of Mt.split(`
55
+ `))me.startsWith("event:")?Re=me.slice(6).trim():me.startsWith("data:")&&(Ye+=me.slice(5).trim());if(Re)try{const me=Ye?JSON.parse(Ye):{};Re==="progress"?K(me):Re==="partial_image"?D(me):Re==="done"?He=me:Re==="error"&&(We=(me==null?void 0:me.message)||"Stream error")}catch{}}}const Et=Date.now()-l;if(We){C(We);return}He&&g({data:He,latencyMs:Et})}else{const oe=await se.json(),Ie=Date.now()-l;g({data:oe,latencyMs:Ie})}}catch(T){C(T.message||"Network error")}finally{ye(!1)}},E=l=>{if(!l||typeof l!="object")return l;if(Array.isArray(l))return l.map(E);const k={};for(const[T,te]of Object.entries(l))k[T]=T==="b64_json"&&typeof te=="string"&&te.length>100?`<${te.length} chars base64>`:E(te);return k},F=a?JSON.stringify(E(a.data),null,2):"";return e.jsxs(we,{children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Example"}),e.jsxs("div",{className:"flex flex-col gap-2.5",children:[h.length>0?e.jsx(_,{label:"Model",children:e.jsx("select",{value:A,onChange:l=>u(l.target.value),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:h.map(l=>e.jsx("option",{value:l.id,children:l.name||l.id},l.id))})}):R?e.jsx(_,{label:"Model",children:e.jsx("input",{value:A,onChange:l=>u(l.target.value),placeholder:"Enter model id (provider-specific)",className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary font-mono"})}):null,e.jsx(_,{label:"Endpoint",children:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsxs("span",{className:"w-full min-w-0 flex-1 px-3 py-1.5 text-sm font-mono text-text-main bg-sidebar rounded-lg truncate",children:[$e,Pe]}),m&&e.jsxs("button",{onClick:()=>H(l=>!l),title:ae?"Using tunnel":"Using local",className:`flex items-center gap-1 text-xs px-2 py-1.5 rounded-lg border shrink-0 transition-colors ${ae?"border-primary/40 bg-primary/10 text-primary":"border-border text-text-muted hover:text-primary"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"wifi_tethering"}),"Tunnel"]})]})}),e.jsx(_,{label:"API Key",children:e.jsx("span",{className:"px-3 py-1.5 text-sm font-mono text-text-main bg-sidebar rounded-lg truncate block",children:V?`${V.slice(0,8)}${"•".repeat(Math.min(20,V.length-8))}`:e.jsx("span",{className:"text-text-muted italic",children:"No key configured"})})}),J.length>0&&e.jsx(_,{label:"Connection",children:e.jsxs("select",{value:ce,onChange:l=>fe(l.target.value),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[e.jsx("option",{value:"",children:"Auto (by priority)"}),J.map(l=>{var te;const k=(te=l.providerSpecificData)==null?void 0:te.chatgptPlanType,T=l.email||l.name||l.id.slice(0,8);return e.jsxs("option",{value:l.id,children:[T,k?` [${k}]`:""]},l.id)})]})}),e.jsx(_,{label:d.inputLabel,children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:L,onChange:l=>I(l.target.value),placeholder:d.inputPlaceholder,className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"}),L&&e.jsx("button",{type:"button",onClick:()=>I(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-muted hover:text-primary transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]})}),U&&e.jsx(_,{label:"Ref Image (URL)",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:j,onChange:l=>x(l.target.value),placeholder:je.image||"https://example.com/source.png",className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"}),j&&e.jsx("button",{type:"button",onClick:()=>x(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-muted hover:text-primary transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),Ke&&e.jsx("img",{src:Ke,alt:"Reference",className:"max-h-40 rounded-lg border border-border object-contain bg-sidebar",onError:l=>{l.currentTarget.style.display="none"},onLoad:l=>{l.currentTarget.style.display="block"}})]})}),O&&e.jsx(_,{label:"Mask (URL)",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:N,onChange:l=>B(l.target.value),placeholder:je.mask_image||"https://example.com/mask.png",className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"}),N&&e.jsx("button",{type:"button",onClick:()=>B(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-muted hover:text-primary transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),Te&&e.jsx("img",{src:Te,alt:"Mask",className:"max-h-40 rounded-lg border border-border object-contain bg-sidebar",onError:l=>{l.currentTarget.style.display="none"},onLoad:l=>{l.currentTarget.style.display="block"}})]})}),(()=>{const l={"1:1":"1:1 Square","9:16":"9:16 Portrait","3:4":"3:4 Portrait","16:9":"16:9 Landscape","4:3":"4:3 Landscape"};return(d.extraFields||[]).filter(k=>h.length===0||Array.isArray(v==null?void 0:v.params)&&v.params.includes(k.key)).map(k=>{const T=Array.isArray(v==null?void 0:v.paramDefs)?v.paramDefs.find(q=>q.name===k.key):null,te=(T==null?void 0:T.validValues)||k.options||[],se=te.length>0&&te.every(q=>q in l);return e.jsx(_,{label:k.label,children:k.type==="select"?e.jsx("select",{value:X[k.key]??"",onChange:q=>Q(he=>({...he,[k.key]:q.target.value})),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:(te||[]).map(q=>e.jsx("option",{value:q,children:q===""?"(default)":se&&l[q]||q},q))}):k.type==="text"?e.jsx("input",{type:"text",value:X[k.key]??"",placeholder:k.placeholder,onChange:q=>Q(he=>({...he,[k.key]:q.target.value})),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"}):e.jsx("input",{type:"number",value:X[k.key]??"",min:k.min,max:k.max,onChange:q=>Q(he=>({...he,[k.key]:q.target.value===""?"":Number(q.target.value)})),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})},k.key)})})(),r==="image"&&e.jsx(_,{label:"Output Format",children:e.jsxs("select",{value:b,onChange:l=>Z(l.target.value),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[e.jsx("option",{value:"json",children:"JSON (Base64)"}),e.jsx("option",{value:"binary",children:"Binary File"})]})}),e.jsxs("div",{className:"mt-1",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Request"}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsxs("button",{onClick:()=>de(n),className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:Ne?"check":"content_copy"}),Ne?"Copied":"Copy"]}),e.jsxs("button",{onClick:Y,disabled:ue||!L.trim()||!ge,className:"flex w-full sm:w-auto items-center justify-center gap-1.5 px-3 py-1 rounded-lg bg-primary text-white text-xs font-medium hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",style:ue?{animation:"spin 1s linear infinite"}:void 0,children:"play_arrow"}),ue?"Running...":"Run"]})]})]}),e.jsx("pre",{className:"bg-sidebar rounded-lg px-3 py-2.5 text-xs font-mono text-text-main overflow-x-auto whitespace-pre-wrap break-all",children:n})]}),(ue||P)&&Ee&&e.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2 rounded-lg bg-sidebar border border-border sm:flex-row sm:items-center sm:gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-primary",style:ue?{animation:"spin 1s linear infinite"}:void 0,children:ue?"progress_activity":"check_circle"}),e.jsxs("span",{className:"text-xs text-text-muted",children:[(P==null?void 0:P.stage)||"starting",!ue&&(P!=null&&P.bytesReceived)?` · ${(P.bytesReceived/1024).toFixed(1)} KB`:""]})]}),(f==null?void 0:f.b64_json)&&!a&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Partial preview"}),e.jsx("img",{src:`data:image/png;base64,${f.b64_json}`,alt:"Partial",className:"max-w-full rounded-lg border border-border mt-1.5 opacity-80"})]}),xe&&e.jsx("p",{className:"text-xs text-red-500 break-words",children:xe}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-1.5",children:[e.jsxs("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:["Response ",a&&e.jsxs("span",{className:"font-normal normal-case",children:["⚡ ",a.latencyMs,"ms"]})]}),a&&e.jsxs("button",{onClick:()=>ze(F),className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:Me?"check":"content_copy"}),Me?"Copied":"Copy"]})]}),e.jsx("pre",{className:"bg-sidebar rounded-lg px-3 py-2.5 text-xs font-mono text-text-main overflow-x-auto whitespace-pre-wrap break-all opacity-70",children:a?F:d.defaultResponse}),r==="image"&&(ne||((Qe=(Je=a==null?void 0:a.data)==null?void 0:Je.data)==null?void 0:Qe[0]))&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center justify-end mb-1.5",children:e.jsxs("a",{href:ne||((tt=(et=(Ze=a==null?void 0:a.data)==null?void 0:Ze.data)==null?void 0:et[0])!=null&&tt.b64_json?`data:image/png;base64,${a.data.data[0].b64_json}`:((nt=(at=(st=a==null?void 0:a.data)==null?void 0:st.data)==null?void 0:at[0])==null?void 0:nt.url)||""),download:"image.png",className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"download"}),"Download"]})}),e.jsx("img",{src:ne||((lt=(rt=(ot=a==null?void 0:a.data)==null?void 0:ot.data)==null?void 0:rt[0])!=null&&lt.b64_json?`data:image/png;base64,${a.data.data[0].b64_json}`:(dt=(ct=(it=a==null?void 0:a.data)==null?void 0:it.data)==null?void 0:ct[0])==null?void 0:dt.url),alt:"Generated",className:"max-w-full rounded-lg border border-border"})]}),r==="video"&&((mt=(ut=a==null?void 0:a.data)==null?void 0:ut.data)==null?void 0:mt.length)>0&&(()=>{const l=a.data.data,k=l.find(se=>/\.mp4(\?|$)/i.test(se.url||"")||/\/video\//i.test(se.url||""))||l[l.length-1],T=k==null?void 0:k.url;if(!T)return null;const te=`/api/media-proxy?url=${encodeURIComponent(T)}`;return e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center justify-end mb-1.5",children:e.jsxs("a",{href:T,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"download"}),"Download"]})}),e.jsx("video",{src:te,controls:!0,preload:"metadata",className:"max-w-full rounded-lg border border-border"})]})})()]})]})]})}function Xt({providerId:t}){var xe;const r=Be(t),i=pe(t).filter(C=>C.type==="stt"),[S,c]=s.useState([]),M=[...i,...S],[d,p]=s.useState(((xe=i[0])==null?void 0:xe.id)??""),h=M.find(C=>C.id===d),y=Array.isArray(h==null?void 0:h.params)?h.params:[],[$,R]=s.useState(null),[A,u]=s.useState(""),[v,U]=s.useState(""),[O,L]=s.useState("json"),[I,j]=s.useState(""),[x,N]=s.useState(""),[B,X]=s.useState(!1),[Q,V]=s.useState(""),[re,ae]=s.useState(""),[H,W]=s.useState(null),[le,m]=s.useState(null),[o,a]=s.useState(!1),[g,P]=s.useState(""),{copied:K,copy:f}=ve(),{copied:D,copy:b}=ve();s.useEffect(()=>{V(window.location.origin),fetch("/api/keys").then(J=>J.json()).then(J=>{var ee;N(((ee=(J.keys||[]).find(ce=>ce.isActive!==!1))==null?void 0:ee.key)||"")}).catch(()=>{}),fetch("/api/tunnel/status").then(J=>J.json()).then(J=>{J.publicUrl&&ae(J.publicUrl)}).catch(()=>{});const C=()=>{fetch("/api/models/custom",{cache:"no-store"}).then(J=>J.json()).then(J=>{const ee=(J.models||[]).filter(ce=>ce.type==="stt"&&ce.providerAlias===r);c(ee)}).catch(()=>{})};return C(),window.addEventListener("focus",C),window.addEventListener("customModelChanged",C),()=>{window.removeEventListener("focus",C),window.removeEventListener("customModelChanged",C)}},[r]);const Z=B?re:Q,ne=d?`${r}/${d}`:"",G=`curl -X POST ${Z}/v1/audio/transcriptions \\
56
+ -H "Authorization: Bearer ${x||"YOUR_KEY"}" \\
57
+ -F "file=@${($==null?void 0:$.name)||"audio.mp3"}" \\
58
+ -F "model=${ne}"${y.includes("language")&&A?` \\
59
+ -F "language=${A}"`:""}${y.includes("response_format")?` \\
60
+ -F "response_format=${O}"`:""}${y.includes("temperature")&&I?` \\
61
+ -F "temperature=${I}"`:""}${y.includes("prompt")&&v?` \\
62
+ -F "prompt=${v}"`:""}`,ue=async()=>{var J;if(!$||!ne)return;a(!0),P(""),W(null);const C=Date.now();try{const ee=new FormData;ee.append("file",$),ee.append("model",ne),y.includes("language")&&A&&ee.append("language",A),y.includes("response_format")&&ee.append("response_format",O),y.includes("temperature")&&I&&ee.append("temperature",I),y.includes("prompt")&&v&&ee.append("prompt",v);const ce={};x&&(ce.Authorization=`Bearer ${x}`);const fe=await fetch("/api/v1/audio/transcriptions",{method:"POST",headers:ce,body:ee});m(Date.now()-C);const de=(fe.headers.get("content-type")||"").includes("application/json")?await fe.json():await fe.text();if(!fe.ok){P(((J=de==null?void 0:de.error)==null?void 0:J.message)||(de==null?void 0:de.error)||de||`HTTP ${fe.status}`);return}W(de)}catch(ee){P(ee.message||"Network error")}finally{a(!1)}},ye=typeof H=="string"?H:H?JSON.stringify(H,null,2):`{
63
+ "text": "Hello world..."
64
+ }`;return e.jsxs(we,{children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Example"}),e.jsxs("div",{className:"flex flex-col gap-2.5",children:[M.length>0?e.jsx(_,{label:"Model",children:e.jsx("select",{value:d,onChange:C=>p(C.target.value),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:M.map(C=>e.jsx("option",{value:C.id,children:C.name||C.id},C.id))})}):e.jsx(_,{label:"Model",children:e.jsx("input",{value:d,onChange:C=>p(C.target.value),placeholder:"Enter model id",className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary font-mono"})}),e.jsx(_,{label:"Endpoint",children:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsxs("span",{className:"w-full min-w-0 flex-1 px-3 py-1.5 text-sm font-mono text-text-main bg-sidebar rounded-lg truncate",children:[Z,"/v1/audio/transcriptions"]}),re&&e.jsxs("button",{onClick:()=>X(C=>!C),title:B?"Using tunnel":"Using local",className:`flex items-center gap-1 text-xs px-2 py-1.5 rounded-lg border shrink-0 transition-colors ${B?"border-primary/40 bg-primary/10 text-primary":"border-border text-text-muted hover:text-primary"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"wifi_tethering"}),"Tunnel"]})]})}),e.jsx(_,{label:"API Key",children:e.jsx("span",{className:"px-3 py-1.5 text-sm font-mono text-text-main bg-sidebar rounded-lg truncate block",children:x?`${x.slice(0,8)}${"•".repeat(Math.min(20,x.length-8))}`:e.jsx("span",{className:"text-text-muted italic",children:"No key configured"})})}),e.jsx(_,{label:"Audio File",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("input",{type:"file",accept:"audio/*,video/mp4,.m4a,.mp3,.wav,.ogg,.flac,.webm,.opus",onChange:C=>{var J;return R(((J=C.target.files)==null?void 0:J[0])||null)},className:"w-full text-xs text-text-muted file:mr-2 file:py-1 file:px-2.5 file:rounded-lg file:border file:border-border file:bg-background file:text-text-main hover:file:bg-sidebar file:cursor-pointer"}),$&&e.jsxs("span",{className:"text-xs text-text-muted font-mono",children:[$.name," · ",($.size/1024).toFixed(1)," KB"]})]})}),y.includes("language")&&e.jsx(_,{label:"Language",children:e.jsx("input",{value:A,onChange:C=>u(C.target.value),placeholder:"e.g. en, vi, ja (auto-detect if empty)",className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary font-mono"})}),y.includes("prompt")&&e.jsx(_,{label:"Prompt",children:e.jsx("input",{value:v,onChange:C=>U(C.target.value),placeholder:"optional context to improve accuracy",className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})}),y.includes("temperature")&&e.jsx(_,{label:"Temperature",children:e.jsx("input",{type:"number",step:"0.1",min:"0",max:"1",value:I,onChange:C=>j(C.target.value),placeholder:"0 - 1 (default 0)",className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})}),y.includes("response_format")&&e.jsx(_,{label:"Response Format",children:e.jsxs("select",{value:O,onChange:C=>L(C.target.value),className:"w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[e.jsx("option",{value:"json",children:"json"}),e.jsx("option",{value:"text",children:"text"}),e.jsx("option",{value:"srt",children:"srt"}),e.jsx("option",{value:"verbose_json",children:"verbose_json"}),e.jsx("option",{value:"vtt",children:"vtt"})]})}),e.jsxs("div",{className:"mt-1",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Request"}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsxs("button",{onClick:()=>f(G),className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:K?"check":"content_copy"}),K?"Copied":"Copy"]}),e.jsxs("button",{onClick:ue,disabled:o||!$||!ne,className:"flex w-full sm:w-auto items-center justify-center gap-1.5 px-3 py-1 rounded-lg bg-primary text-white text-xs font-medium hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",style:o?{animation:"spin 1s linear infinite"}:void 0,children:"play_arrow"}),o?"Transcribing...":"Run"]})]})]}),e.jsx("pre",{className:"bg-sidebar rounded-lg px-3 py-2.5 text-xs font-mono text-text-main overflow-x-auto whitespace-pre-wrap break-all",children:G})]}),g&&e.jsx("p",{className:"text-xs text-red-500 break-words",children:g}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-1.5",children:[e.jsxs("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:["Response ",H&&le&&e.jsxs("span",{className:"font-normal normal-case",children:["⚡ ",le,"ms"]})]}),H&&e.jsxs("button",{onClick:()=>b(ye),className:"inline-flex items-center gap-1 text-xs text-text-muted hover:text-primary transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:D?"check":"content_copy"}),D?"Copied":"Copy"]})]}),e.jsx("pre",{className:"bg-sidebar rounded-lg px-3 py-2.5 text-xs font-mono text-text-main overflow-x-auto whitespace-pre-wrap break-all opacity-70",children:ye})]})]})]})}function ss(){var U,O,L,I,j,x;const{kind:t,id:r}=Lt(),i=It(),S=bt.find(N=>N.id===t),c=yt(r)&&t==="embedding",M=async()=>{if(confirm("Delete this Custom Embedding node?"))try{(await fetch(`/api/provider-nodes/${r}`,{method:"DELETE"})).ok&&i(`/dashboard/media-providers/${t}`)}catch(N){console.log("Error deleting custom embedding node:",N)}},[d,p]=s.useState(null),[h,y]=s.useState(c),[$,R]=s.useState(!1);if(s.useEffect(()=>{if(!c)return;let N=!1;return fetch("/api/provider-nodes",{cache:"no-store"}).then(B=>B.json()).then(B=>{N||(p((B.nodes||[]).find(X=>X.id===r)||null),y(!1))}).catch(()=>{N||y(!1)}),()=>{N=!0}},[r,c]),!S)return null;const A=Ae[r],u=c?d?{id:r,name:d.name||"Custom Embedding",color:"#6366F1",textIcon:"CE"}:null:A;if(!c&&!A||c&&!h&&!d)return null;if(c&&h)return e.jsx("div",{className:"text-text-muted text-sm py-12 text-center",children:"Loading..."});const v=c?["embedding"]:u.serviceKinds??["llm"];return!c&&!v.includes(t)?null:e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsxs("div",{children:[e.jsxs(Dt,{to:`/dashboard/media-providers/${t}`,className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[e.jsx("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),S.label]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",children:[e.jsx("div",{className:"size-12 rounded-lg flex items-center justify-center shrink-0",style:{backgroundColor:`${u.color}15`},children:e.jsx(Pt,{src:`/providers/${u.id}.png`,alt:u.name,size:48,className:"object-contain rounded-lg max-w-[48px] max-h-[48px]",fallbackText:u.textIcon||u.id.slice(0,2).toUpperCase(),fallbackColor:u.color})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:u.name}),!c&&((U=u.notice)==null?void 0:U.apiKeyUrl)&&e.jsxs("a",{href:u.notice.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"open_in_new"}),"Get API Key"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 flex-wrap",children:[c&&e.jsxs(Oe,{variant:"default",size:"sm",children:["Custom · ",d==null?void 0:d.prefix]}),v.map(N=>e.jsx(Oe,{variant:N===t?"primary":"default",size:"sm",children:N.toUpperCase()},N))]})]}),c&&e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsx(be,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>R(!0),children:"Edit"}),e.jsx(be,{size:"sm",variant:"secondary",icon:"delete",onClick:M,children:"Delete"})]})]})]}),!c&&((O=u.kindNotice)==null?void 0:O[t])&&e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/30 text-amber-700 dark:text-amber-400",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] mt-0.5",children:"warning"}),e.jsx("p",{className:"text-sm",children:u.kindNotice[t]})]}),!c&&((L=u.notice)==null?void 0:L.text)&&!u.deprecated&&e.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:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-500 shrink-0",children:"info"}),e.jsx("p",{className:"min-w-0 flex-1 text-xs leading-relaxed text-blue-600 dark:text-blue-400",children:u.notice.text}),u.notice.apiKeyUrl&&e.jsx("a",{href:u.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 →"})]}),!c&&u.noAuth?e.jsx(Bt,{providerId:r}):e.jsx(Nt,{providerId:r,isOAuth:!1}),t!=="tts"&&t!=="webSearch"&&t!=="webFetch"&&e.jsx(St,{providerId:r,kindFilter:t,providerAliasOverride:c?d==null?void 0:d.prefix:void 0}),!c&&(u.searchConfig||u.fetchConfig||u.ttsConfig||u.sttConfig||u.embeddingConfig||u.searchViaChat)&&e.jsx(Vt,{config:t==="webFetch"?u.fetchConfig:t==="tts"?u.ttsConfig:t==="stt"?u.sttConfig:t==="embedding"?u.embeddingConfig:u.searchConfig||{mode:"chat-completions",defaultModel:(I=u.searchViaChat)==null?void 0:I.defaultModel,pricingUrl:(j=u.searchViaChat)==null?void 0:j.pricingUrl,freeTier:(x=u.searchViaChat)==null?void 0:x.freeTier},provider:u,title:`${S.label} Config`}),t==="embedding"&&e.jsx(Wt,{providerId:r,customAlias:d==null?void 0:d.prefix}),t==="tts"&&e.jsx(Gt,{providerId:r}),t==="stt"&&!c&&e.jsx(Xt,{providerId:r}),!c&&Ct[t]&&e.jsx(Yt,{providerId:r,kind:t}),c&&e.jsx(Kt,{isOpen:$,node:d,onClose:()=>R(!1),onSaved:N=>{p(N),R(!1)}})]})}export{ss as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.C5VWu_q7.js";import{b as r}from"./router.Cjj1--8t.js";import{C as j}from"./Loading.D9qCFX3R.js";import"./zustand.akaTi5uX.js";function P(){return e.jsx(r.Suspense,{fallback:e.jsx(j,{}),children:e.jsx(y,{})})}function y(){const[a,h]=r.useState([]),[p,b]=r.useState(!0),[s,f]=r.useState(""),[o,n]=r.useState(null),[i,d]=r.useState(!1),[l,c]=r.useState(""),[x,m]=r.useState(null);r.useEffect(()=>{fetch("/api/media-providers/webSearch").then(t=>t.json()).then(t=>{h(Array.isArray(t)?t:[]),t.length>0&&c(t[0].id)}).catch(()=>{}).finally(()=>b(!1))},[]);const u=async()=>{if(s.trim()){d(!0),m(null),n(null);try{const t=await fetch("/api/media/webSearch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:s,providerId:l||void 0})});if(!t.ok)throw new Error(`HTTP ${t.status}`);const g=await t.json();n(g)}catch(t){m(t.message)}finally{d(!1)}}};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[28px] text-primary",children:"search"}),e.jsx("h1",{className:"text-xl font-semibold text-text-main",children:"Search"})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Search Providers"}),p?e.jsx("p",{className:"text-xs text-text-muted",children:"Loading providers..."}):a.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:"No search providers configured. Add one in Media Providers."}):e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(t=>e.jsx("button",{onClick:()=>c(t.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-colors cursor-pointer ${l===t.id?"bg-primary/10 text-primary border border-primary/30":"bg-surface-2 text-text-muted hover:text-text-main border border-transparent"}`,children:t.name||t.id},t.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Test Search"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:t=>f(t.target.value),onKeyDown:t=>t.key==="Enter"&&u(),placeholder:"Enter search query...",className:"flex-1 rounded-lg border border-border-subtle bg-surface-2 px-3 py-2 text-sm text-text-main placeholder:text-text-muted/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),e.jsx("button",{onClick:u,disabled:i||!s.trim(),className:"px-4 py-2 rounded-lg bg-primary text-white text-sm font-medium hover:bg-primary/90 disabled:opacity-50 transition-colors cursor-pointer",children:i?"Searching...":"Search"})]})]}),x&&e.jsx("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-4",children:e.jsx("p",{className:"text-sm text-red-400",children:x})}),o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Results"}),e.jsx("pre",{className:"text-xs text-text-muted overflow-auto max-h-96 bg-surface-2 rounded-lg p-3 font-mono whitespace-pre-wrap",children:JSON.stringify(o,null,2)})]})]})}export{P as default};