@fudrouter/fsrouter 0.6.107 → 0.6.108

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 (45) hide show
  1. package/dist/routes/db/info/route.js +22 -0
  2. package/package.json +1 -1
  3. package/public/.vite/manifest.json +85 -85
  4. package/public/assets/EndpointPageClient.BN-D__UM.js +6 -0
  5. package/public/assets/Loading.BoU3gy5K.js +1 -0
  6. package/public/assets/NoAuthProxyCard.CLW2-XwE.js +89 -0
  7. package/public/assets/index.BO_pNnMt.js +89 -0
  8. package/public/assets/page.-P08pALK.js +6 -0
  9. package/public/assets/page.-PU2bgJe.js +1 -0
  10. package/public/assets/page.2bfZgPuP.js +1 -0
  11. package/public/assets/page.Asf9tesx.js +1 -0
  12. package/public/assets/page.B11lN3QC.js +1 -0
  13. package/public/assets/page.B1ZhgC-Y.js +1 -0
  14. package/public/assets/page.B28QUiM4.js +1 -0
  15. package/public/assets/page.BBnpNaQh.js +6 -0
  16. package/public/assets/page.BOy_Vt2f.js +1 -0
  17. package/public/assets/page.BRDONwuI.js +1 -0
  18. package/public/assets/page.BWFxAlAj.js +1 -0
  19. package/public/assets/page.BebFlAF6.js +1 -0
  20. package/public/assets/page.BqxsFxH_.js +2 -0
  21. package/public/assets/page.C1Z5-h5h.js +1 -0
  22. package/public/assets/page.CIxYSsJm.js +1 -0
  23. package/public/assets/page.CQLGTJxs.js +1 -0
  24. package/public/assets/page.CTO5ojlP.js +1 -0
  25. package/public/assets/page.CTx0rdSY.js +1 -0
  26. package/public/assets/page.CXAgJ2hd.js +1 -0
  27. package/public/assets/page.CdVrDM5I.js +1 -0
  28. package/public/assets/page.CgidHjOu.js +1 -0
  29. package/public/assets/page.CqPzqV4I.js +7 -0
  30. package/public/assets/page.Cr-bxDIh.js +4 -0
  31. package/public/assets/page.CsL3JXbA.js +1 -0
  32. package/public/assets/page.D6eEvzRr.js +5 -0
  33. package/public/assets/page.DHyqPTHy.js +1 -0
  34. package/public/assets/page.DS5iFEwr.js +31 -0
  35. package/public/assets/page.Dre9jdlU.js +1 -0
  36. package/public/assets/page.IyBPROCc.js +1 -0
  37. package/public/assets/page.KoOCODPg.js +5 -0
  38. package/public/assets/page.MP_9jcAE.js +1 -0
  39. package/public/assets/page.WAG7HQOU.js +2 -0
  40. package/public/assets/page.XKedaymF.js +1 -0
  41. package/public/assets/page.ZZHz9al1.js +64 -0
  42. package/public/assets/page.alTMqTdj.js +1 -0
  43. package/public/assets/page.tpebkgG7.js +1 -0
  44. package/public/assets/page.xIh7b02j.js +23 -0
  45. package/public/index.html +4 -4
@@ -0,0 +1 @@
1
+ import{j as e,L as Qe,D as Xe,E as ye,G as je,H as Ze,n as he,B as v,I as ge,C as es}from"./index.BO_pNnMt.js";import{b as o,c as ss,d as ts}from"./router.Cjj1--8t.js";import{C as T,T as C,I as m}from"./NoAuthProxyCard.CLW2-XwE.js";import"./zustand.akaTi5uX.js";function as(){if(typeof document>"u")return"en";const g=document.cookie.split(";").find(S=>S.trim().startsWith(`${ye}=`)),k=g?decodeURIComponent(g.split("=")[1]):"en";return je(k)}const oe=g=>({en:{name:"English",flag:"🇺🇸"},vi:{name:"Tiếng Việt",flag:"🇻🇳"},"zh-CN":{name:"简体中文",flag:"🇨🇳"},"zh-TW":{name:"繁體中文",flag:"🇹🇼"},ja:{name:"日本語",flag:"🇯🇵"},"pt-BR":{name:"Português (Brasil)",flag:"🇧🇷"},"pt-PT":{name:"Português (Portugal)",flag:"🇵🇹"},ko:{name:"한국어",flag:"🇰🇷"},es:{name:"Español",flag:"🇪🇸"},de:{name:"Deutsch",flag:"🇩🇪"},fr:{name:"Français",flag:"🇫🇷"},he:{name:"עברית",flag:"🇮🇱"},ar:{name:"العربية",flag:"🇸🇦"},ru:{name:"Русский",flag:"🇷🇺"},pl:{name:"Polski",flag:"🇵🇱"},cs:{name:"Čeština",flag:"🇨🇿"},nl:{name:"Nederlands",flag:"🇳🇱"},tr:{name:"Türkçe",flag:"🇹🇷"},uk:{name:"Українська",flag:"🇺🇦"},tl:{name:"Tagalog",flag:"🇵🇭"},id:{name:"Indonesia",flag:"🇮🇩"},th:{name:"ไทย",flag:"🇹🇭"},hi:{name:"हिन्दी",flag:"🇮🇳"},bn:{name:"বাংলা",flag:"🇧🇩"},ur:{name:"اردو",flag:"🇵🇰"},ro:{name:"Română",flag:"🇷🇴"},sv:{name:"Svenska",flag:"🇸🇪"},it:{name:"Italiano",flag:"🇮🇹"},el:{name:"Ελληνικά",flag:"🇬🇷"},hu:{name:"Magyar",flag:"🇭🇺"},fi:{name:"Suomi",flag:"🇫🇮"},da:{name:"Dansk",flag:"🇩🇰"},no:{name:"Norsk",flag:"🇳🇴"}})[g]||{name:g,flag:"🌐"};function os({className:g="",isOpen:k,onClose:S,hideTrigger:re=!1}){const[P,U]=o.useState("en"),[R,H]=o.useState(!1),[E,V]=o.useState(!1),F=o.useRef(null),r=typeof k=="boolean",x=r?k:E,i=c=>{r?!c&&S&&S(P):V(c)};o.useEffect(()=>{U(as())},[]),o.useEffect(()=>{function c(N){F.current&&!F.current.contains(N.target)&&i(!1)}if(x)return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[x]);const B=async c=>{if(!(c===P||R)){H(!0),i(!1);try{await fetch("/api/locale",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({locale:c})}),await Xe(),U(c)}catch(N){console.error("Failed to set locale:",N)}finally{H(!1)}}};return e.jsxs("div",{className:g,children:[!re&&e.jsxs("button",{onClick:()=>i(!x),disabled:R,className:"flex items-center gap-2 px-3 py-2 rounded-lg text-text-muted hover:text-text-main hover:bg-surface/60 transition-colors",title:"Language","data-i18n-skip":"true",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"language"}),e.jsx("span",{className:"text-sm font-medium",children:oe(P).name}),e.jsx("span",{className:"text-lg",children:oe(P).flag})]}),x&&ss.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4","data-i18n-skip":"true",children:[e.jsx("div",{className:"absolute inset-0 bg-black/30 backdrop-blur-sm",onClick:()=>i(!1)}),e.jsxs("div",{ref:F,className:"relative w-full bg-surface border border-black/10 dark:border-white/10 rounded-xl shadow-2xl animate-in fade-in zoom-in-95 duration-200 max-w-2xl flex flex-col max-h-[80vh]",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-black/5 dark:border-white/5",children:[e.jsx("h2",{className:"text-lg font-semibold text-text-main",children:"Select Language"}),e.jsx("button",{onClick:()=>i(!1),className:"p-1.5 rounded-lg text-text-muted hover:bg-black/5 dark:hover:bg-white/5 transition-colors","aria-label":"Close",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsx("div",{className:"p-6 overflow-y-auto flex-1",children:e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(100px,1fr))] gap-2",children:Qe.map(c=>{const N=P===c,O=oe(c);return e.jsxs("button",{onClick:()=>B(c),disabled:R,className:`flex flex-col items-center justify-start gap-1 px-2 py-3 rounded-lg text-xs font-medium transition-colors w-full ${N?"bg-primary/15 text-primary ring-2 ring-primary":"text-text-main hover:bg-black/5 dark:hover:bg-white/5"} ${R?"opacity-70 cursor-wait":""}`,title:O.name,children:[e.jsx("span",{className:"text-2xl",children:O.flag}),e.jsx("span",{className:"text-center leading-tight line-clamp-2 h-8 flex items-center",children:O.name}),N&&e.jsx("span",{className:"material-symbols-outlined text-sm",children:"check"})]},c)})})})]})]}),document.body)]})}function rs(){if(typeof document>"u")return"en";const g=document.cookie.split(";").find(S=>S.trim().startsWith(`${ye}=`)),k=g?decodeURIComponent(g.split("=")[1]):"en";return je(k)}function ds(){const g=ts(),{theme:k,setTheme:S}=Ze(),[re,P]=o.useState("en"),[U,R]=o.useState(!1),[H,E]=o.useState(!1),[V,F]=o.useState(!1),[r,x]=o.useState({fallbackStrategy:"fill-first"}),[i,B]=o.useState(!0),[c,N]=o.useState({current:"",new:"",confirm:""}),[O,M]=o.useState({type:"",message:""}),[we,ie]=o.useState(!1),[le,W]=o.useState(!1),[Y,D]=o.useState({type:"",message:""}),[p,Q]=o.useState({authMode:"password",oidcIssuerUrl:"",oidcClientId:"",oidcScopes:"openid profile email",oidcLoginLabel:"Sign in with OIDC"}),[X,Z]=o.useState(""),[ee,A]=o.useState({type:"",message:""}),[L,ne]=o.useState(!1),[ve,ce]=o.useState(!1),[se,I]=o.useState({type:"",message:""}),[Ne,_e]=o.useState("/api/auth/oidc/callback"),[de,me]=o.useState(!1),K=o.useRef(null),[J,z]=o.useState({outboundProxyEnabled:!1,outboundProxyUrl:"",outboundNoProxy:""}),[te,y]=o.useState({type:"",message:""}),[$,G]=o.useState(!1),[ke,xe]=o.useState(!1),[l,j]=o.useState({codebuddy_auto_fsrouter:!1,codebuddy_leave_canva_team:!1,codebuddy_browser_headless:!0,codebuddy_proxy_enabled:!1,codebuddy_proxy_server:"",codebuddy_proxy_username:"",codebuddy_proxy_password:"",fsmail_base_url:"",fsmail_api_key:"",fsmail_default_domain:"",fsmail_webhook_secret:""}),[ae,f]=o.useState({type:"",message:""}),[w,ue]=o.useState(!1),[Ce,pe]=o.useState(!1),[Se,be]=o.useState(!1),[fe,Pe]=o.useState(!1);o.useEffect(()=>{P(rs())},[U]),o.useEffect(()=>{fetch("/api/settings").then(s=>s.json()).then(s=>{x(s),Q({authMode:(s==null?void 0:s.authMode)||"password",oidcIssuerUrl:(s==null?void 0:s.oidcIssuerUrl)||"",oidcClientId:(s==null?void 0:s.oidcClientId)||"",oidcScopes:(s==null?void 0:s.oidcScopes)||"openid profile email",oidcLoginLabel:(s==null?void 0:s.oidcLoginLabel)||"Sign in with OIDC"}),Z(""),((s==null?void 0:s.authMode)==="oidc"||(s==null?void 0:s.authMode)==="both")&&me(!0),z({outboundProxyEnabled:(s==null?void 0:s.outboundProxyEnabled)===!0,outboundProxyUrl:(s==null?void 0:s.outboundProxyUrl)||"",outboundNoProxy:(s==null?void 0:s.outboundNoProxy)||""}),j({codebuddy_auto_fsrouter:(s==null?void 0:s.codebuddy_auto_fsrouter)==="1",codebuddy_leave_canva_team:(s==null?void 0:s.codebuddy_leave_canva_team)==="1",codebuddy_browser_headless:(s==null?void 0:s.codebuddy_browser_headless)!=="0",codebuddy_proxy_enabled:(s==null?void 0:s.codebuddy_proxy_enabled)==="1",codebuddy_proxy_server:(s==null?void 0:s.codebuddy_proxy_server)||"",codebuddy_proxy_username:(s==null?void 0:s.codebuddy_proxy_username)||"",codebuddy_proxy_password:(s==null?void 0:s.codebuddy_proxy_password)||"",fsmail_base_url:(s==null?void 0:s.fsmail_base_url)||"",fsmail_api_key:(s==null?void 0:s.fsmail_api_key)||"",fsmail_default_domain:(s==null?void 0:s.fsmail_default_domain)||"",fsmail_webhook_secret:(s==null?void 0:s.fsmail_webhook_secret)||""}),B(!1)}).catch(s=>{console.error("Failed to fetch settings:",s),B(!1)})},[]),o.useEffect(()=>{typeof window<"u"&&_e(`${window.location.origin}/api/auth/oidc/callback`)},[]);const Oe=async s=>{ue(!0),f({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({codebuddy_auto_fsrouter:l.codebuddy_auto_fsrouter?"1":"0",codebuddy_leave_canva_team:l.codebuddy_leave_canva_team?"1":"0",codebuddy_browser_headless:l.codebuddy_browser_headless?"1":"0",codebuddy_proxy_enabled:l.codebuddy_proxy_enabled?"1":"0",codebuddy_proxy_server:l.codebuddy_proxy_server,codebuddy_proxy_username:l.codebuddy_proxy_username,codebuddy_proxy_password:l.codebuddy_proxy_password,fsmail_base_url:l.fsmail_base_url,fsmail_api_key:l.fsmail_api_key,fsmail_default_domain:l.fsmail_default_domain,fsmail_webhook_secret:l.fsmail_webhook_secret})}),a=await t.json();t.ok?(x(n=>({...n,...a})),f({type:"success",message:"Automation settings saved successfully."})):f({type:"error",message:a.error||"Failed to update automation settings"})}catch{f({type:"error",message:"An error occurred"})}finally{ue(!1)}},Le=async()=>{pe(!0),f({type:"",message:""});try{const s=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fsmail_base_url:l.fsmail_base_url,fsmail_api_key:l.fsmail_api_key,fsmail_default_domain:l.fsmail_default_domain,fsmail_webhook_secret:l.fsmail_webhook_secret})});if(!s.ok){const n=await s.json().catch(()=>({}));f({type:"error",message:n.error||"Failed to save settings before testing connection"});return}const t=await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"test-connection"})}),a=await t.json().catch(()=>({}));t.ok?f({type:"success",message:"FSMail Connection Successful!"}):f({type:"error",message:a.error||"FSMail Connection Failed."})}catch(s){f({type:"error",message:s.message||"An error occurred"})}finally{pe(!1)}},Ie=async()=>{var s;be(!0),f({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fsmail_base_url:l.fsmail_base_url,fsmail_api_key:l.fsmail_api_key,fsmail_default_domain:l.fsmail_default_domain,fsmail_webhook_secret:l.fsmail_webhook_secret})});if(!t.ok){const b=await t.json().catch(()=>({}));f({type:"error",message:b.error||"Failed to save settings before registering webhook"});return}const a=await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"webhook-register"})}),n=await a.json().catch(()=>({}));a.ok?(f({type:"success",message:"FSMail Webhook Registered Successfully!"}),(s=n.webhook)!=null&&s.secret&&j(b=>({...b,fsmail_webhook_secret:n.webhook.secret}))):f({type:"error",message:n.error||"FSMail Webhook Registration Failed."})}catch(t){f({type:"error",message:t.message||"An error occurred"})}finally{be(!1)}},Te=async s=>{if(s.preventDefault(),r.outboundProxyEnabled===!0){G(!0),y({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({outboundProxyUrl:J.outboundProxyUrl,outboundNoProxy:J.outboundNoProxy})}),a=await t.json();t.ok?(x(n=>({...n,...a})),y({type:"success",message:"Proxy settings applied"})):y({type:"error",message:a.error||"Failed to update proxy settings"})}catch{y({type:"error",message:"An error occurred"})}finally{G(!1)}}},Re=async()=>{if(r.outboundProxyEnabled!==!0)return;const s=(J.outboundProxyUrl||"").trim();if(!s){y({type:"error",message:"Please enter a Proxy URL to test"});return}xe(!0),y({type:"",message:""});try{const t=await fetch("/api/settings/proxy-test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxyUrl:s})}),a=await t.json();t.ok&&(a!=null&&a.ok)?y({type:"success",message:`Proxy test OK (${a.status}) in ${a.elapsedMs}ms`}):y({type:"error",message:(a==null?void 0:a.error)||"Proxy test failed"})}catch{y({type:"error",message:"An error occurred"})}finally{xe(!1)}},Fe=async s=>{G(!0),y({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({outboundProxyEnabled:s})}),a=await t.json();t.ok?(x(n=>({...n,...a})),z(n=>({...n,outboundProxyEnabled:(a==null?void 0:a.outboundProxyEnabled)===!0})),y({type:"success",message:s?"Proxy enabled":"Proxy disabled"})):y({type:"error",message:a.error||"Failed to update proxy settings"})}catch{y({type:"error",message:"An error occurred"})}finally{G(!1)}},De=async s=>{if(s.preventDefault(),c.new!==c.confirm){M({type:"error",message:"Passwords do not match"});return}ie(!0),M({type:"",message:""});try{const t=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentPassword:c.current,newPassword:c.new})}),a=await t.json();t.ok?(M({type:"success",message:"Password updated successfully"}),N({current:"",new:"",confirm:""})):M({type:"error",message:a.error||"Failed to update password"})}catch{M({type:"error",message:"An error occurred"})}finally{ie(!1)}},Ae=async s=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fallbackStrategy:s})})).ok&&x(a=>({...a,fallbackStrategy:s}))}catch(t){console.error("Failed to update settings:",t)}},Ue=async s=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({comboStrategy:s})})).ok&&x(a=>({...a,comboStrategy:s}))}catch(t){console.error("Failed to update combo strategy:",t)}},Ee=async s=>{const t=parseInt(s);if(!(isNaN(t)||t<1))try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({stickyRoundRobinLimit:t})})).ok&&x(n=>({...n,stickyRoundRobinLimit:t}))}catch(a){console.error("Failed to update sticky limit:",a)}},Me=async s=>{const t=parseInt(s);if(!(isNaN(t)||t<1))try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({comboStickyRoundRobinLimit:t})})).ok&&x(n=>({...n,comboStickyRoundRobinLimit:t}))}catch(a){console.error("Failed to update combo sticky limit:",a)}},Je=async s=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({requireLogin:s})})).ok&&x(a=>({...a,requireLogin:s}))}catch(t){console.error("Failed to update require login:",t)}},q=(s,t)=>{Q(a=>({...a,[s]:t}))},$e=async(s=p.authMode||"password")=>{const t=p.oidcIssuerUrl.trim(),a=p.oidcClientId.trim(),n=p.oidcScopes.trim(),b=p.oidcLoginLabel.trim(),u=X.trim();if(s!=="password"&&(!t||!a||!u)&&!r.oidcConfigured){A({type:"error",message:"Issuer URL, client ID, and client secret are required to enable OIDC."});return}ne(!0),A({type:"",message:""}),I({type:"",message:""});try{const _={authMode:s,oidcIssuerUrl:t,oidcClientId:a,oidcScopes:n||"openid profile email",oidcLoginLabel:b||"Sign in with OIDC"};u&&(_.oidcClientSecret=u);const h=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)}),d=await h.json();h.ok?(x(Ye=>({...Ye,...d})),Q({authMode:(d==null?void 0:d.authMode)||s,oidcIssuerUrl:(d==null?void 0:d.oidcIssuerUrl)||t,oidcClientId:(d==null?void 0:d.oidcClientId)||a,oidcScopes:(d==null?void 0:d.oidcScopes)||n||"openid profile email",oidcLoginLabel:(d==null?void 0:d.oidcLoginLabel)||b||"Sign in with OIDC"}),Z(""),A({type:"success",message:s==="oidc"?"OIDC login enabled":s==="both"?"Password and OIDC login enabled":"OIDC settings saved"})):A({type:"error",message:d.error||"Failed to save OIDC settings"})}catch{A({type:"error",message:"An error occurred"})}finally{ne(!1)}},qe=async()=>{const s=p.oidcIssuerUrl.trim(),t=p.oidcClientId.trim(),a=p.oidcScopes.trim(),n=X.trim();if(!s||!t){I({type:"error",message:"Issuer URL and client ID are required to test the connection."});return}ce(!0),A({type:"",message:""}),I({type:"",message:""});try{const b=await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({authMode:p.authMode||r.authMode||"password",oidcIssuerUrl:s,oidcClientId:t,oidcScopes:a||"openid profile email",oidcLoginLabel:p.oidcLoginLabel.trim()||"Sign in with OIDC",...n?{oidcClientSecret:n}:{}})}),u=await b.json().catch(()=>({}));if(!b.ok){I({type:"error",message:u.error||"Failed to save OIDC settings before testing"});return}const _=await fetch("/api/auth/oidc/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({issuerUrl:u.oidcIssuerUrl||s,clientId:u.oidcClientId||t,scopes:u.oidcScopes||a||"openid profile email"})}),h=await _.json().catch(()=>({}));if(_.ok&&(h!=null&&h.ok)){const d=h.clientSecretTested?h.clientSecretValid===!0?`Connection OK. Discovery loaded from ${h.issuerUrl}. Client secret validated too.`:`Connection OK. Discovery loaded from ${h.issuerUrl}. Client secret was not checked.`:`Connection OK. Discovery loaded from ${h.issuerUrl}.`;I({type:"success",message:d})}else I({type:"error",message:h.error||"OIDC connection test failed"})}catch{I({type:"error",message:"An error occurred"})}finally{ce(!1)}},He=async s=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enableObservability:s})})).ok&&x(a=>({...a,enableObservability:s}))}catch(t){console.error("Failed to update enableObservability:",t)}},Be=async()=>{try{const s=await fetch("/api/settings");if(!s.ok)return;const t=await s.json();x(t)}catch(s){console.error("Failed to reload settings:",s)}},We=async()=>{W(!0),D({type:"",message:""});try{const s=await fetch("/api/settings/database");if(!s.ok){const h=await s.json().catch(()=>({}));throw new Error(h.error||"Failed to export database")}const t=await s.json(),a=JSON.stringify(t,null,2),n=new Blob([a],{type:"application/json"}),b=URL.createObjectURL(n),u=document.createElement("a"),_=new Date().toISOString().replace(/[.:]/g,"-");u.href=b,u.download=`fsrouter-backup-${_}.json`,document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(b),D({type:"success",message:"Database backup downloaded"})}catch(s){D({type:"error",message:s.message||"Failed to export database"})}finally{W(!1)}},Ke=async s=>{var a;const t=(a=s.target.files)==null?void 0:a[0];if(t){W(!0),D({type:"",message:""});try{const n=await t.text(),b=JSON.parse(n),u=await fetch("/api/settings/database",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)}),_=await u.json().catch(()=>({}));if(!u.ok)throw new Error(_.error||"Failed to import database");await Be(),D({type:"success",message:"Database imported successfully"})}catch(n){D({type:"error",message:n.message||"Invalid backup file"})}finally{K.current&&(K.current.value=""),W(!1)}}},ze=r.enableObservability===!0,Ge=async()=>{F(!0);try{await fetch("/api/version/shutdown",{method:"POST"})}catch{}F(!1),E(!1)},Ve=async()=>{try{(await fetch("/api/auth/logout",{method:"POST"})).ok&&(localStorage.removeItem("9r_authed"),g("/login"),g(0))}catch(s){console.error("Failed to logout:",s)}};return e.jsxs("div",{className:"max-w-2xl mx-auto px-4 sm:px-0",children:[e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs(T,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3 sm:gap-4",children:[e.jsx("div",{className:"size-10 sm:size-12 rounded-lg bg-green-500/10 text-green-500 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-xl sm:text-2xl",children:"computer"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg sm:text-xl font-semibold",children:"Local Mode"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Running on your machine"})]})]}),e.jsx("div",{className:"inline-flex p-1 rounded-lg bg-black/5 dark:bg-white/5 w-full sm:w-auto",children:["light","dark","system"].map(s=>e.jsxs("button",{type:"button",onClick:()=>S(s),className:he("flex items-center justify-center gap-1 sm:gap-1.5 px-2 sm:px-3 py-1.5 rounded-md font-medium transition-all flex-1 sm:flex-initial",k===s?"bg-white dark:bg-white/10 text-text-main shadow-sm":"text-text-muted hover:text-text-main"),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:s==="light"?"light_mode":s==="dark"?"dark_mode":"contrast"}),e.jsx("span",{className:"capitalize text-xs sm:text-sm",children:s})]},s))})]}),e.jsxs("div",{className:"flex flex-col gap-3 pt-4 border-t border-border",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between p-3 rounded-lg bg-bg border border-border gap-2",children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Database Location"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted font-mono break-all",children:"~/.fsrouter/db/data.sqlite"})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(v,{variant:"secondary",icon:"download",onClick:We,loading:le,className:"w-full sm:w-auto",children:"Download Backup"}),e.jsx(v,{variant:"outline",icon:"upload",onClick:()=>{var s;return(s=K.current)==null?void 0:s.click()},disabled:le,className:"w-full sm:w-auto",children:"Import Backup"}),e.jsx("input",{ref:K,type:"file",accept:"application/json,.json",className:"hidden",onChange:Ke})]}),Y.message&&e.jsx("p",{className:`text-sm ${Y.type==="error"?"text-red-500":"text-green-600 dark:text-green-400"}`,children:Y.message})]})]}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10 text-primary shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"shield"})}),e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Security"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Require login"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"When ON, dashboard requires password. When OFF, access without login."})]}),e.jsx(C,{checked:r.requireLogin===!0,onChange:()=>Je(!r.requireLogin),disabled:i})]}),r.requireLogin===!0&&e.jsxs("form",{onSubmit:De,className:"flex flex-col gap-4 pt-4 border-t border-border/50",children:[r.hasPassword&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs sm:text-sm font-medium",children:"Current Password"}),e.jsx(m,{type:"password",placeholder:"Enter current password",value:c.current,onChange:s=>N({...c,current:s.target.value}),required:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs sm:text-sm font-medium",children:"New Password"}),e.jsx(m,{type:"password",placeholder:"Enter new password",value:c.new,onChange:s=>N({...c,new:s.target.value}),required:!0})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs sm:text-sm font-medium",children:"Confirm New Password"}),e.jsx(m,{type:"password",placeholder:"Confirm new password",value:c.confirm,onChange:s=>N({...c,confirm:s.target.value}),required:!0})]})]}),O.message&&e.jsx("p",{className:`text-xs sm:text-sm ${O.type==="error"?"text-red-500":"text-green-500"}`,children:O.message}),e.jsx("div",{className:"pt-2",children:e.jsx(v,{type:"submit",variant:"primary",loading:we,className:"w-full sm:w-auto",children:r.hasPassword?"Update Password":"Set Password"})})]})]})]}),e.jsxs(T,{children:[e.jsxs("button",{type:"button",onClick:()=>me(s=>!s),className:"w-full flex items-center gap-3 text-left",children:[e.jsx("div",{className:"p-2 rounded-lg bg-indigo-500/10 text-indigo-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"lock_open"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"OIDC Dashboard Login"}),e.jsx("p",{className:"text-xs text-text-muted",children:r.authMode==="oidc"?"OIDC active":r.authMode==="both"?"Password + OIDC active":"Optional SSO via Authentik/Keycloak/Google"})]}),e.jsx("span",{className:"material-symbols-outlined text-text-muted shrink-0",children:de?"expand_less":"expand_more"})]}),de&&e.jsxs("div",{className:"flex flex-col gap-4 mt-4",children:[e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Use Authentik or any OIDC provider to sign in to the dashboard. You can enable password-only, OIDC-only, or both for the dashboard; model API access still uses API keys."}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Auth Mode"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:[{value:"password",title:"Password only",desc:"Keep the legacy password login."},{value:"oidc",title:"OIDC only",desc:"Require OIDC for dashboard access."},{value:"both",title:"Both",desc:"Allow either password or OIDC."}].map(s=>{const t=p.authMode===s.value;return e.jsxs("button",{type:"button",onClick:()=>q("authMode",s.value),className:he("text-left rounded-lg border p-3 transition-colors",t?"border-primary bg-primary/5":"border-border bg-bg hover:bg-black/5 dark:hover:bg-white/5"),disabled:i||L,children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:s.title}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted mt-1",children:s.desc})]},s.value)})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Issuer URL"}),e.jsx(m,{placeholder:"https://auth.example.com/application/o/fsrouter/",value:p.oidcIssuerUrl,onChange:s=>q("oidcIssuerUrl",s.target.value),disabled:i||L})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Client ID"}),e.jsx(m,{placeholder:"fsrouter-dashboard",value:p.oidcClientId,onChange:s=>q("oidcClientId",s.target.value),disabled:i||L})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Client Secret"}),e.jsx(m,{type:"password",placeholder:"Leave blank to keep existing secret",value:X,onChange:s=>Z(s.target.value),disabled:i||L}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"This value is write-only after saving."})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Scopes"}),e.jsx(m,{placeholder:"openid profile email",value:p.oidcScopes,onChange:s=>q("oidcScopes",s.target.value),disabled:i||L})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Login Button Label"}),e.jsx(m,{placeholder:"Sign in with OIDC",value:p.oidcLoginLabel,onChange:s=>q("oidcLoginLabel",s.target.value),disabled:i||L})]})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-bg p-3 text-xs sm:text-sm text-text-muted",children:[e.jsx("p",{className:"font-medium text-text-main mb-1",children:"Redirect URI"}),e.jsx("code",{className:"block break-all font-mono",children:Ne})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-2 border-t border-border/50",children:[e.jsx(v,{type:"button",variant:"primary",loading:L,onClick:()=>$e(),className:"w-full sm:w-auto",children:"Save auth mode"}),e.jsx(v,{type:"button",variant:"outline",loading:ve,onClick:qe,className:"w-full sm:w-auto",children:"Test connection"})]}),se.message&&e.jsx("p",{className:`text-xs sm:text-sm ${se.type==="error"?"text-red-500":"text-green-500"}`,children:se.message}),ee.message&&e.jsx("p",{className:`text-xs sm:text-sm ${ee.type==="error"?"text-red-500":"text-green-500"}`,children:ee.message}),r.authMode==="oidc"&&e.jsx("p",{className:"text-xs sm:text-sm text-amber-600 dark:text-amber-400",children:"OIDC login is currently active. Password login is disabled until you switch back."}),r.authMode==="both"&&e.jsx("p",{className:"text-xs sm:text-sm text-amber-600 dark:text-amber-400",children:"Password and OIDC login are both active."})]})]}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-blue-500/10 text-blue-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"route"})}),e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Routing Strategy"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Round Robin"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Cycle through accounts to distribute load"})]}),e.jsx(C,{checked:r.fallbackStrategy==="round-robin",onChange:()=>Ae(r.fallbackStrategy==="round-robin"?"fill-first":"round-robin"),disabled:i})]}),r.fallbackStrategy==="round-robin"&&e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Sticky Limit"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Calls per account before switching"})]}),e.jsx(m,{type:"number",min:"1",max:"10",value:r.stickyRoundRobinLimit||3,onChange:s=>Ee(s.target.value),disabled:i,className:"w-16 sm:w-20 text-center shrink-0"})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-4 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Combo Round Robin"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Cycle through providers in combos instead of always starting with first"})]}),e.jsx(C,{checked:r.comboStrategy==="round-robin",onChange:()=>Ue(r.comboStrategy==="round-robin"?"fallback":"round-robin"),disabled:i})]}),r.comboStrategy==="round-robin"&&e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-border/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Combo Sticky Limit"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Calls per combo model before switching"})]}),e.jsx(m,{type:"number",min:"1",max:"100",value:r.comboStickyRoundRobinLimit||1,onChange:s=>Me(s.target.value),disabled:i,className:"w-20 text-center"})]}),e.jsxs("p",{className:"text-xs text-text-muted italic pt-2 border-t border-border/50",children:[r.fallbackStrategy==="round-robin"?`Currently distributing requests across all available accounts with ${r.stickyRoundRobinLimit||3} calls per account.`:"Currently using accounts in priority order (Fill First).",r.comboStrategy==="round-robin"?` Combos rotate after ${r.comboStickyRoundRobinLimit||1} call${(r.comboStickyRoundRobinLimit||1)===1?"":"s"} per model.`:" Combos always start with their first model."]})]})]}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-purple-500/10 text-purple-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"wifi"})}),e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Network"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Outbound Proxy"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Enable proxy for OAuth + provider outbound requests."})]}),e.jsx(C,{checked:r.outboundProxyEnabled===!0,onChange:()=>Fe(r.outboundProxyEnabled!==!0),disabled:i||$})]}),r.outboundProxyEnabled===!0&&e.jsxs("form",{onSubmit:Te,className:"flex flex-col gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Proxy URL"}),e.jsx(m,{placeholder:"http://127.0.0.1:7897",value:J.outboundProxyUrl,onChange:s=>z(t=>({...t,outboundProxyUrl:s.target.value})),disabled:i||$}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Leave empty to inherit existing env proxy (if any)."})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-2 border-t border-border/50",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"No Proxy"}),e.jsx(m,{placeholder:"localhost,127.0.0.1",value:J.outboundNoProxy,onChange:s=>z(t=>({...t,outboundNoProxy:s.target.value})),disabled:i||$}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Comma-separated hostnames/domains to bypass the proxy."})]}),e.jsxs("div",{className:"pt-2 border-t border-border/50 flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsx(v,{type:"button",variant:"secondary",loading:ke,disabled:i||$,onClick:Re,className:"w-full sm:w-auto",children:"Test proxy URL"}),e.jsx(v,{type:"submit",variant:"primary",loading:$,className:"w-full sm:w-auto",children:"Apply"})]})]}),te.message&&e.jsx("p",{className:`text-xs sm:text-sm ${te.type==="error"?"text-red-500":"text-green-500"} pt-2 border-t border-border/50`,children:te.message})]})]}),e.jsxs(T,{children:[e.jsxs("button",{type:"button",onClick:()=>Pe(s=>!s),className:"w-full flex items-center gap-3 text-left focus:outline-none",children:[e.jsx("div",{className:"p-2 rounded-lg bg-emerald-500/10 text-emerald-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"smart_toy"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Automation Settings"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Manage CodeBuddy browser signup & FSMail temporary email configurations."})]}),e.jsx("span",{className:"material-symbols-outlined text-text-muted shrink-0",children:fe?"expand_less":"expand_more"})]}),fe&&e.jsxs("div",{className:"flex flex-col gap-4 mt-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h4",{className:"font-semibold text-sm text-text-main flex items-center gap-1.5 border-b border-border/55 pb-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"smart_toy"}),"CodeBuddy API Gen Settings"]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Headless Browser"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Run the automated signup browser in headless mode (no visual window)."})]}),e.jsx(C,{checked:l.codebuddy_browser_headless,onChange:s=>j(t=>({...t,codebuddy_browser_headless:s})),disabled:i||w})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Auto Inject to fsrouter"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Automatically add newly generated CodeBuddy API keys to fsrouter connections."})]}),e.jsx(C,{checked:l.codebuddy_auto_fsrouter,onChange:s=>j(t=>({...t,codebuddy_auto_fsrouter:s})),disabled:i||w})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Leave Canva Team after Leonardo Registration"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Automatically leave the Canva team after completing Leonardo registration to free up team invite slots."})]}),e.jsx(C,{checked:l.codebuddy_leave_canva_team,onChange:s=>j(t=>({...t,codebuddy_leave_canva_team:s})),disabled:i||w})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Use Outbound Proxy"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Route the automation browser traffic through a proxy server."})]}),e.jsx(C,{checked:l.codebuddy_proxy_enabled,onChange:s=>j(t=>({...t,codebuddy_proxy_enabled:s})),disabled:i||w})]}),l.codebuddy_proxy_enabled&&e.jsxs("div",{className:"flex flex-col gap-3 pl-4 border-l-2 border-primary/20 pt-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-main",children:"Proxy Server"}),e.jsx(m,{placeholder:"host:port (e.g. 127.0.0.1:8080)",value:l.codebuddy_proxy_server,onChange:s=>j(t=>({...t,codebuddy_proxy_server:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-main",children:"Proxy Username (Optional)"}),e.jsx(m,{placeholder:"username",value:l.codebuddy_proxy_username,onChange:s=>j(t=>({...t,codebuddy_proxy_username:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-main",children:"Proxy Password (Optional)"}),e.jsx(m,{type:"password",placeholder:"password",value:l.codebuddy_proxy_password,onChange:s=>j(t=>({...t,codebuddy_proxy_password:s.target.value})),disabled:i||w})]})]})]})]}),e.jsxs("div",{className:"space-y-4 pt-4 border-t border-border/55",children:[e.jsxs("h4",{className:"font-semibold text-sm text-text-main flex items-center gap-1.5 border-b border-border/55 pb-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"mail"}),"FSMail Temp Mail Settings"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Base URL"}),e.jsx(m,{placeholder:"https://fsmail.example.com",value:l.fsmail_base_url,onChange:s=>j(t=>({...t,fsmail_base_url:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"API Key"}),e.jsx(m,{type:"password",placeholder:"FSMail API Key",value:l.fsmail_api_key,onChange:s=>j(t=>({...t,fsmail_api_key:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Default Domain"}),e.jsx(m,{placeholder:"example.com",value:l.fsmail_default_domain,onChange:s=>j(t=>({...t,fsmail_default_domain:s.target.value})),disabled:i||w})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"font-medium text-sm sm:text-base",children:"Webhook Secret"}),e.jsx(m,{type:"password",placeholder:"Leave empty to auto-generate",value:l.fsmail_webhook_secret,onChange:s=>j(t=>({...t,fsmail_webhook_secret:s.target.value})),disabled:i||w})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-4 border-t border-border/50",children:[e.jsx(v,{type:"button",variant:"primary",loading:w,onClick:()=>Oe(),className:"w-full sm:w-auto",children:"Save Settings"}),e.jsx(v,{type:"button",variant:"secondary",loading:Ce,onClick:Le,className:"w-full sm:w-auto",children:"Test FSMail Connection"}),e.jsx(v,{type:"button",variant:"outline",loading:Se,onClick:Ie,className:"w-full sm:w-auto",children:"Register Webhook"})]}),ae.message&&e.jsx("p",{className:`text-xs sm:text-sm ${ae.type==="error"?"text-red-500":"text-green-500"} pt-2 border-t border-border/50`,children:ae.message})]})]}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-orange-500/10 text-orange-500 shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"monitoring"})}),e.jsx("h3",{className:"text-base sm:text-lg font-semibold",children:"Observability"})]}),e.jsxs("div",{className:"flex items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm sm:text-base",children:"Enable Observability"}),e.jsx("p",{className:"text-xs sm:text-sm text-text-muted",children:"Record request details for inspection in the logs view"})]}),e.jsx(C,{checked:ze,onChange:He,disabled:i})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(v,{variant:"outline",fullWidth:!0,icon:"power_settings_new",onClick:()=>E(!0),className:"text-red-500 border-red-200 hover:bg-red-50 hover:border-red-300",children:"Shutdown"}),e.jsx(v,{variant:"outline",fullWidth:!0,icon:"logout",onClick:Ve,children:"Logout"})]}),e.jsxs("div",{className:"text-center text-xs sm:text-sm text-text-muted py-4",children:[e.jsxs("p",{children:[ge.name," v",ge.version]}),e.jsx("p",{className:"mt-1",children:"Local Mode - All data stored on your machine"})]})]}),e.jsx(os,{hideTrigger:!0,isOpen:U,onClose:s=>{R(!1),P(s)}}),e.jsx(es,{isOpen:H,onClose:()=>E(!1),onConfirm:Ge,title:"Close Proxy",message:"Are you sure you want to close the proxy server?",confirmText:"Close",cancelText:"Cancel",variant:"danger",loading:V})]})}export{ds as default};
@@ -0,0 +1,5 @@
1
+ import{j as e,N as pe,y as fe,B as A,P as be,g as ge}from"./index.BO_pNnMt.js";import{h as je,d as we,b as c,L as ve}from"./router.Cjj1--8t.js";import{C as S,I as ye,T as Ne,M as ke}from"./NoAuthProxyCard.CLW2-XwE.js";import"./zustand.akaTi5uX.js";function Se(o){if(typeof o!="string")return{providerId:"",model:""};const g=o.indexOf("/");return g<0?{providerId:o,model:""}:{providerId:o.slice(0,g),model:o.slice(g+1)}}const Re=/^[a-zA-Z0-9_.\-]+$/,Ee={webSearch:"Web Search",webFetch:"Web Fetch",image:"Text to Image",tts:"Text To Speech"},V={webSearch:"/v1/search",webFetch:"/v1/web/fetch",image:"/v1/images/generations",tts:"/v1/audio/speech"},L={webSearch:o=>({model:o,query:"What is the latest news about AI?",search_type:"web",max_results:5}),webFetch:o=>({model:o,url:"https://example.com",format:"markdown"}),image:o=>({model:o,prompt:"A cute cat playing piano",n:1,size:"1024x1024"}),tts:o=>({model:o,input:"Hello, this is a test.",voice:"alloy"})};function X(o){return o==="webSearch"||o==="webFetch"?"/dashboard/media-providers/web":`/dashboard/media-providers/${o}`}function Le(){var K;const{id:o}=je(),g=we(),[r,P]=c.useState(null),[q,O]=c.useState(!0),[N,_]=c.useState(""),[G,R]=c.useState(""),[m,j]=c.useState([]),[Y,$]=c.useState(!1),[Z,M]=c.useState(!1),[D,Q]=c.useState([]),[I,B]=c.useState(!1),[l,w]=c.useState(null),[z,E]=c.useState(""),[U,ee]=c.useState(""),[te,se]=c.useState([]),[ae,ne]=c.useState({}),H=async()=>{var t,s,a;try{const[n,i,k,y,x,p]=await Promise.all([fetch(`/api/combos/${o}`,{cache:"no-store"}),fetch("/api/settings",{cache:"no-store"}),fetch("/api/usage/logs",{cache:"no-store"}),fetch("/api/keys",{cache:"no-store"}),fetch("/api/providers",{cache:"no-store"}),fetch("/api/models/alias",{cache:"no-store"})]);if(p.ok&&ne((await p.json()).aliases||{}),y.ok){const b=await y.json();ee(((t=(b.keys||[]).find(d=>d.isActive!==!1))==null?void 0:t.key)||"")}if(x.ok&&se((await x.json()).connections||[]),!n.ok){P(null),O(!1);return}const h=await n.json();P(h),_(h.name),j(h.models||[]);const f=i.ok?await i.json():{};$(((a=(s=f.comboStrategies)==null?void 0:s[h.name])==null?void 0:a.fallbackStrategy)==="round-robin");const u=k.ok?await k.json():[];Q(u.filter(b=>typeof b=="string"&&b.includes(h.name)).slice(0,50))}catch{}O(!1)};c.useEffect(()=>{H()},[o]);const F=t=>t.trim()?Re.test(t)?(R(""),!0):(R("Only letters, numbers, -, _ and ."),!1):(R("Name is required"),!1),v=async t=>{const s=await fetch(`/api/combos/${o}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!s.ok){const a=await s.json();return alert(a.error||"Failed to save"),!1}return!0},oe=async()=>{if(!F(N)||N===r.name)return;await v({name:N})&&await H()},re=async t=>{const s=(t==null?void 0:t.value)||t;if(!s||m.includes(s))return;const a=[...m,s];j(a),await v({models:a})},le=async t=>{const s=(t==null?void 0:t.value)||t;if(!s||!m.includes(s))return;const a=m.filter(n=>n!==s);j(a),await v({models:a})},ie=async t=>{const s=m.filter((a,n)=>n!==t);j(s),await v({models:s})},J=async(t,s)=>{const a=[...m],n=t+s;n<0||n>=a.length||([a[t],a[n]]=[a[n],a[t]],j(a),await v({models:a}))},ce=async t=>{$(t);const s=await fetch("/api/settings",{cache:"no-store"}),n={...(s.ok?await s.json():{}).comboStrategies||{}};t?n[r.name]={fallbackStrategy:"round-robin"}:delete n[r.name],await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({comboStrategies:n})})},de=async()=>{if(!confirm(`Delete combo "${r.name}"?`))return;(await fetch(`/api/combos/${o}`,{method:"DELETE"})).ok&&g(X(r.kind))},me=async()=>{var s,a,n;if(B(!0),w(null),E(""),l!=null&&l.audioUrl)try{URL.revokeObjectURL(l.audioUrl)}catch{}if((s=l==null?void 0:l.imageUrl)!=null&&s.startsWith("blob:"))try{URL.revokeObjectURL(l.imageUrl)}catch{}const t=Date.now();try{const i=V[r.kind],k=L[r.kind](r.name),y={"Content-Type":"application/json"};U&&(y.Authorization=`Bearer ${U}`);const x=await fetch(`/api${i}`,{method:"POST",headers:y,body:JSON.stringify(k)}),p=Date.now()-t;if(!x.ok){const d=await x.json().catch(()=>({}));E(((a=d==null?void 0:d.error)==null?void 0:a.message)||(d==null?void 0:d.error)||`HTTP ${x.status}`),w({json:JSON.stringify(d,null,2),latencyMs:p});return}const h=x.headers.get("content-type")||"";if(h.startsWith("image/")){const d=await x.blob();w({imageUrl:URL.createObjectURL(d),latencyMs:p});return}if(h.startsWith("audio/")||h==="application/octet-stream"){const d=await x.blob();w({audioUrl:URL.createObjectURL(d),latencyMs:p});return}const f=await x.json(),u=(n=f==null?void 0:f.data)==null?void 0:n[0],b=u!=null&&u.b64_json?`data:image/png;base64,${u.b64_json}`:(u==null?void 0:u.url)||"";w({json:JSON.stringify(C(f),null,2),imageUrl:b,latencyMs:p})}catch(i){E(i.message||"Network error")}B(!1)};function C(t){if(!t||typeof t!="object")return t;if(Array.isArray(t))return t.map(C);const s={};for(const[a,n]of Object.entries(t))s[a]=a==="b64_json"&&typeof n=="string"&&n.length>100?`<${n.length} chars base64>`:C(n);return s}if(q)return e.jsx("div",{className:"text-text-muted text-sm",children:"Loading..."});if(!r)return null;const W=Ee[r.kind]||((K=pe.find(t=>t.id===r.kind))==null?void 0:K.label)||"Combo",T=V[r.kind],xe=r.kind&&L[r.kind]?L[r.kind](r.name):null,he=T?`curl -X POST ${fe()}${T} \\
2
+ -H "Content-Type: application/json" \\
3
+ -H "Authorization: Bearer ${U||"YOUR_KEY"}" \\
4
+ -d '${JSON.stringify(xe)}'`:"",ue=X(r.kind);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(ve,{to:ue,className:"text-text-muted hover:text-primary",children:e.jsx("span",{className:"material-symbols-outlined",children:"arrow_back"})}),e.jsx("div",{className:"size-10 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-primary",children:"layers"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-xs text-text-muted",children:[W," Combo"]}),e.jsx("code",{className:"text-lg font-semibold font-mono",children:r.name})]})]}),e.jsx(A,{variant:"outline",icon:"delete",onClick:de,className:"text-red-500 border-red-200 hover:bg-red-50",children:"Delete"})]}),e.jsxs(S,{children:[e.jsx("h2",{className:"text-lg font-semibold mb-3",children:"Settings"}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx(ye,{label:"Combo Name",value:N,onChange:t=>{_(t.target.value),F(t.target.value)},onBlur:oe,error:G}),e.jsx("p",{className:"text-[10px] text-text-muted mt-0.5",children:"Only letters, numbers, -, _ and ."})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Round Robin"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Rotate providers across requests instead of strict fallback order."})]}),e.jsx(Ne,{checked:Y,onChange:ce})]})]})]}),e.jsxs(S,{children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between mb-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Providers"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Tried in order (top-down) or rotated when round-robin is on."})]}),e.jsx(A,{size:"sm",icon:"add",onClick:()=>M(!0),children:"Add Provider"})]}),m.length===0?e.jsx("div",{className:"text-center py-6 border border-dashed border-border rounded-lg text-text-muted text-sm",children:"No providers yet."}):e.jsx("div",{className:"flex flex-col gap-2",children:m.map((t,s)=>{const{providerId:a,model:n}=Se(t),i=ge[a];return e.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-lg bg-black/[0.02] dark:bg-white/[0.02]",children:[e.jsx("span",{className:"text-xs text-text-muted w-5 text-center",children:s+1}),e.jsx(be,{src:`/providers/${a}.png`,alt:(i==null?void 0:i.name)||a,size:24,className:"object-contain rounded shrink-0",fallbackText:(i==null?void 0:i.textIcon)||a.slice(0,2).toUpperCase(),fallbackColor:i==null?void 0:i.color}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:(i==null?void 0:i.name)||a}),n&&e.jsx("code",{className:"text-[10px] text-text-muted font-mono truncate block",children:n})]}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("button",{onClick:()=>J(s,-1),disabled:s===0,className:`p-1 rounded ${s===0?"text-text-muted/20":"text-text-muted hover:text-primary hover:bg-black/5"}`,title:"Move up",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_upward"})}),e.jsx("button",{onClick:()=>J(s,1),disabled:s===m.length-1,className:`p-1 rounded ${s===m.length-1?"text-text-muted/20":"text-text-muted hover:text-primary hover:bg-black/5"}`,title:"Move down",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_downward"})}),e.jsx("button",{onClick:()=>ie(s),className:"p-1 rounded text-text-muted hover:text-red-500 hover:bg-red-500/10",title:"Remove",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]})]},`${t}-${s}`)})})]}),r.kind&&T&&e.jsxs(S,{children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between mb-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Test Example"}),e.jsx(A,{size:"sm",icon:"play_arrow",onClick:me,disabled:I||m.length===0,children:I?"Running...":"Run"})]}),e.jsx("pre",{className:"text-xs font-mono bg-black/[0.03] dark:bg-white/[0.03] p-3 rounded-lg overflow-x-auto whitespace-pre-wrap break-all",children:he}),z&&e.jsx("p",{className:"mt-3 text-xs text-red-500 break-words",children:z}),l&&e.jsxs("div",{className:"mt-3 flex flex-col gap-3",children:[l.latencyMs!=null&&e.jsxs("span",{className:"text-[11px] text-text-muted",children:["⚡ ",l.latencyMs,"ms"]}),l.imageUrl&&e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-end mb-1.5",children:e.jsxs("a",{href:l.imageUrl,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:l.imageUrl,alt:"Generated",className:"max-w-full rounded-lg border border-border"})]}),l.audioUrl&&e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-end mb-1.5",children:e.jsxs("a",{href:l.audioUrl,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:l.audioUrl,className:"w-full"})]}),l.json&&e.jsx("pre",{className:"text-xs font-mono bg-black/[0.03] dark:bg-white/[0.03] p-3 rounded-lg overflow-auto max-h-[300px] whitespace-pre-wrap break-all",children:l.json})]})]}),e.jsxs(S,{children:[e.jsx("h2",{className:"text-lg font-semibold mb-3",children:"Usage Logs"}),D.length===0?e.jsx("p",{className:"text-xs text-text-muted italic",children:"No usage yet."}):e.jsx("pre",{className:"text-[11px] font-mono bg-black/[0.03] dark:bg-white/[0.03] p-3 rounded-lg overflow-auto max-h-[400px] whitespace-pre-wrap",children:D.join(`
5
+ `)})]}),e.jsx(ke,{isOpen:Z,onClose:()=>M(!1),onSelect:re,onDeselect:le,activeProviders:te,modelAliases:ae,title:`Add ${W} Model`,kindFilter:r.kind,addedModelValues:m,closeOnSelect:!1})]})}export{Le as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.BO_pNnMt.js";import{b as r}from"./router.Cjj1--8t.js";import{C as j}from"./Loading.BoU3gy5K.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};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index.1VBQU7rF.js","assets/router.Cjj1--8t.js"])))=>i.map(i=>d[i]);
2
+ import{u as z,j as t,B as c,_ as F}from"./index.BO_pNnMt.js";import{b as x}from"./router.Cjj1--8t.js";import{C as $}from"./NoAuthProxyCard.CLW2-XwE.js";import"./zustand.akaTi5uX.js";const B=x.lazy(()=>F(()=>import("./index.1VBQU7rF.js"),__vite__mapDeps([0,1]))),v=[{id:1,label:"Client Request",file:"1_req_client.json",lang:"json",desc:"Raw request from client"},{id:2,label:"Source Body",file:"2_req_source.json",lang:"json",desc:"After initial conversion"},{id:3,label:"OpenAI Intermediate",file:"3_req_openai.json",lang:"json",desc:"source → openai"},{id:4,label:"Target Request",file:"4_req_target.json",lang:"json",desc:"openai → target + URL + headers"},{id:5,label:"Provider Response",file:"5_res_provider.txt",lang:"text",desc:"Raw SSE from provider"},{id:6,label:"OpenAI Response",file:"6_res_openai.txt",lang:"text",desc:"target → openai (response)"},{id:7,label:"Client Response",file:"7_res_client.txt",lang:"text",desc:"Final response to client"}],I={minimap:{enabled:!1},fontSize:12,lineNumbers:"on",scrollBeyondLastLine:!1,wordWrap:"on",automaticLayout:!0};function W(){const[i,h]=x.useState({}),[g,u]=x.useState({1:!0}),[p,S]=x.useState({}),[o,w]=x.useState(null),l=(e,s)=>S(a=>({...a,[e]:s})),d=(e,s)=>h(a=>({...a,[e]:s})),O=e=>u(s=>({...s,[e]:!s[e]})),j=e=>u(s=>{const a={};return v.forEach(n=>{a[n.id]=!1}),a[e]=!0,a}),_=async e=>{const s=v.find(a=>a.id===e);l(`load-${e}`,!0);try{const n=await(await fetch(`/api/translator/load?file=${s.file}`)).json();n.success?(d(e,n.content),e===1&&await N(n.content)):alert(n.error||"File not found")}catch(a){alert(a.message)}l(`load-${e}`,!1)},N=async e=>{try{const s=typeof e=="string"?JSON.parse(e):e,n=await(await fetch("/api/translator/translate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({step:1,body:s})})).json();n.success&&w(n.result)}catch{}},f=(e,s)=>fetch("/api/translator/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:e,content:s})}).catch(()=>{}),T=async()=>{l("toOpenAI",!0);try{const e=i[1],s=JSON.parse(e);f("1_req_client.json",e),f("2_req_source.json",JSON.stringify({timestamp:new Date().toISOString(),headers:{},body:s.body||s},null,2));const n=await(await fetch("/api/translator/translate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({step:2,body:s})})).json();if(!n.success){alert(n.error);return}const r=JSON.stringify(n.result.body,null,2);d(3,r),j(3)}catch(e){alert(e.message)}l("toOpenAI",!1)},C=async()=>{l("toTarget",!0);try{const e=i[3],s=JSON.parse(e);f("3_req_openai.json",e);const n=await(await fetch("/api/translator/translate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({step:3,body:{...s,provider:o==null?void 0:o.provider,model:o==null?void 0:o.model}})})).json();if(!n.success){alert(n.error);return}const r={...n.result,provider:o==null?void 0:o.provider,model:o==null?void 0:o.model};d(4,JSON.stringify(r,null,2)),j(4)}catch(e){alert(e.message)}l("toTarget",!1)},J=async()=>{l("send",!0);try{const e=i[4],s=JSON.parse(e);f("4_req_target.json",e);const a=s.provider||(o==null?void 0:o.provider),n=s.model||(o==null?void 0:o.model);if(!a||!n){alert("Missing provider or model. Please run step 1 first to detect them.");return}const r=await fetch("/api/translator/send",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,model:n,body:s.body||s})});if(!r.ok){const b=await r.json().catch(()=>({error:r.statusText}));alert(b.error||"Send failed");return}const E=r.body.getReader(),A=new TextDecoder;let y="";for(;;){const{done:b,value:L}=await E.read();if(b)break;y+=A.decode(L,{stream:!0})}d(5,y),j(5),await fetch("/api/translator/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:"5_res_provider.txt",content:y})})}catch(e){alert(e.message)}finally{l("send",!1)}},{copy:P}=z(),R=async e=>{i[e]&&P(i[e],`translator-step-${e}`)},k=e=>{try{const s=JSON.parse(i[e]);d(e,JSON.stringify(s,null,2))}catch{}},q=e=>e===1?t.jsx(c,{size:"sm",icon:"arrow_forward",loading:p.toOpenAI,onClick:T,children:"→ OpenAI"}):e===3?t.jsx(c,{size:"sm",icon:"arrow_forward",loading:p.toTarget,onClick:C,children:"→ Target"}):e===4?t.jsx(c,{size:"sm",icon:"send",loading:p.send,onClick:J,children:"Send"}):null;return t.jsxs("div",{className:"p-8 space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("div",{children:[t.jsx("h1",{className:"text-2xl font-bold text-text-main",children:"Translator Debug"}),t.jsx("p",{className:"text-sm text-text-muted mt-1",children:"Replay request flow — matches log files"})]}),o&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-end",children:[t.jsx(m,{label:"src",value:o.sourceFormat,color:"blue"}),t.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px]",children:"arrow_forward"}),t.jsx(m,{label:"dst",value:o.targetFormat,color:"orange"}),t.jsx(m,{label:"provider",value:o.provider,color:"green"}),t.jsx(m,{label:"model",value:o.model,color:"purple"})]})]}),v.map(e=>{const s=q(e.id),a=!!g[e.id],n=i[e.id]||"";return t.jsx($,{children:t.jsxs("div",{className:"p-4 space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("button",{onClick:()=>O(e.id),className:"flex items-center gap-2 flex-1 text-left group",children:[t.jsx("span",{className:"material-symbols-outlined text-[20px] text-text-muted group-hover:text-primary transition-colors",children:a?"expand_more":"chevron_right"}),t.jsx("span",{className:"text-xs font-mono text-text-muted/60 w-4",children:e.id}),t.jsx("h3",{className:"text-sm font-semibold text-text-main",children:e.label}),t.jsx("span",{className:"text-xs text-text-muted/60 font-mono",children:e.file}),n&&t.jsxs("span",{className:"text-xs text-green-500",children:["(",n.length," chars)"]})]}),!a&&t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(c,{size:"sm",variant:"ghost",icon:"folder_open",loading:p[`load-${e.id}`],onClick:()=>_(e.id)}),s]})]}),a&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"border border-border rounded-lg overflow-hidden",children:t.jsx(B,{height:"400px",defaultLanguage:e.lang==="text"?"plaintext":"json",value:n,onChange:r=>{d(e.id,r||""),e.id===1&&N(r||"")},theme:"vs-dark",options:I})}),t.jsxs("div",{className:"flex gap-2 flex-wrap",children:[t.jsx(c,{size:"sm",variant:"outline",icon:"folder_open",loading:p[`load-${e.id}`],onClick:()=>_(e.id),children:"Load"}),t.jsx(c,{size:"sm",variant:"outline",icon:"data_object",onClick:()=>k(e.id),children:"Format"}),t.jsx(c,{size:"sm",variant:"outline",icon:"content_copy",onClick:()=>R(e.id),children:"Copy"}),s]})]})]})},e.id)})]})}function m({label:i,value:h,color:g}){const u={blue:"bg-blue-500/10 text-blue-500",orange:"bg-orange-500/10 text-orange-500",green:"bg-green-500/10 text-green-500",purple:"bg-purple-500/10 text-purple-500"};return t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-mono ${u[g]}`,children:[t.jsxs("span",{className:"text-text-muted/70 font-sans text-[10px]",children:[i,":"]}),h]})}export{W as default};
@@ -0,0 +1 @@
1
+ import{j as e,P as i,u as d}from"./index.BO_pNnMt.js";import{b as l,d as n}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function c(){const[t,r]=l.useState(!1),s=n();return e.jsxs("nav",{className:"fixed top-0 z-50 w-full bg-[#181411]/80 backdrop-blur-md border-b border-[#3a2f27]",children:[e.jsxs("div",{className:"max-w-7xl mx-auto px-6 h-16 flex items-center justify-between",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-3 cursor-pointer bg-transparent border-none p-0",onClick:()=>s("/"),"aria-label":"Navigate to home",children:[e.jsx("img",{src:"/logo_fsrouter.png",alt:"FSRouter v2",className:"size-8 rounded object-cover"}),e.jsx("h2",{className:"text-white text-xl font-bold tracking-tight",children:"FSRouter"})]}),e.jsxs("div",{className:"hidden md:flex items-center gap-8",children:[e.jsx("a",{className:"text-gray-300 hover:text-white text-sm font-medium transition-colors",href:"#features",children:"Features"}),e.jsx("a",{className:"text-gray-300 hover:text-white text-sm font-medium transition-colors",href:"#how-it-works",children:"How it Works"}),e.jsx("a",{className:"text-gray-300 hover:text-white text-sm font-medium transition-colors",href:"https://github.com/nexusrouters/fsrouter#readme",target:"_blank",rel:"noopener noreferrer",children:"Docs"}),e.jsxs("a",{className:"text-gray-300 hover:text-white text-sm font-medium transition-colors flex items-center gap-1",href:"https://github.com/nexusrouters/fsrouter",target:"_blank",rel:"noopener noreferrer",children:["GitHub ",e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"open_in_new"})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>s("/dashboard"),className:"hidden sm:flex h-9 items-center justify-center rounded-lg px-4 bg-[#f97815] hover:bg-[#e0650a] transition-all text-[#181411] text-sm font-bold shadow-[0_0_15px_rgba(249,120,21,0.4)] hover:shadow-[0_0_20px_rgba(249,120,21,0.6)]",children:"Get Started"}),e.jsx("button",{className:"md:hidden text-white",onClick:()=>r(!t),children:e.jsx("span",{className:"material-symbols-outlined",children:t?"close":"menu"})})]})]}),t&&e.jsx("div",{className:"md:hidden border-t border-[#3a2f27] bg-[#181411]/95 backdrop-blur-md",children:e.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[e.jsx("a",{className:"text-gray-300 hover:text-white text-sm font-medium transition-colors",href:"#features",onClick:()=>r(!1),children:"Features"}),e.jsx("a",{className:"text-gray-300 hover:text-white text-sm font-medium transition-colors",href:"#how-it-works",onClick:()=>r(!1),children:"How it Works"}),e.jsx("a",{className:"text-gray-300 hover:text-white text-sm font-medium transition-colors",href:"https://github.com/nexusrouters/fsrouter#readme",target:"_blank",rel:"noopener noreferrer",children:"Docs"}),e.jsx("a",{className:"text-gray-300 hover:text-white text-sm font-medium transition-colors",href:"https://github.com/nexusrouters/fsrouter",target:"_blank",rel:"noopener noreferrer",children:"GitHub"}),e.jsx("button",{onClick:()=>s("/dashboard"),className:"h-9 rounded-lg bg-[#f97815] hover:bg-[#e0650a] text-[#181411] text-sm font-bold",children:"Get Started"})]})})]})}function x(){return e.jsxs("section",{className:"relative pt-32 pb-20 px-6 min-h-[90vh] flex flex-col items-center justify-center overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 w-[1000px] h-[500px] bg-[#f97815]/10 rounded-full blur-[120px] pointer-events-none"}),e.jsxs("div",{className:"relative z-10 max-w-4xl w-full text-center flex flex-col items-center gap-8",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-[#3a2f27] bg-[#23180f]/50 px-3 py-1 text-xs font-medium text-[#f97815]",children:[e.jsx("span",{className:"flex h-2 w-2 rounded-full bg-[#f97815] animate-pulse"}),"v1.0 is now live"]}),e.jsxs("h1",{className:"text-5xl md:text-7xl font-black leading-[1.1] tracking-tight",children:["One Endpoint for ",e.jsx("br",{}),e.jsx("span",{className:"text-[#f97815]",children:"All AI Providers"})]}),e.jsx("p",{className:"text-lg md:text-xl text-gray-400 max-w-2xl mx-auto font-light",children:"AI endpoint proxy with web dashboard - A JavaScript port of CLIProxyAPI. Works seamlessly with Claude Code, OpenAI Codex, Cline, RooCode, and other CLI tools."}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-4 w-full",children:[e.jsxs("button",{className:"h-12 px-8 rounded-lg bg-[#f97815] hover:bg-[#e0650a] text-[#181411] text-base font-bold transition-all shadow-[0_0_15px_rgba(249,120,21,0.4)] flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined",children:"rocket_launch"}),"Get Started"]}),e.jsxs("a",{href:"https://github.com/nexusrouters/fsrouter",target:"_blank",rel:"noopener noreferrer",className:"h-12 px-8 rounded-lg border border-[#3a2f27] bg-[#23180f] hover:bg-[#3a2f27] text-white text-base font-bold transition-all flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined",children:"code"}),"View on GitHub"]})]})]})]})}const m=[{id:"claude",name:"Claude Code",image:"/providers/claude.png"},{id:"codex",name:"OpenAI Codex",image:"/providers/codex.png"},{id:"cline",name:"Cline",image:"/providers/cline.png"},{id:"cursor",name:"Cursor",image:"/providers/cursor.png"}],o=[{id:"openai",name:"OpenAI",color:"bg-emerald-500",textColor:"text-white"},{id:"anthropic",name:"Anthropic",color:"bg-orange-400",textColor:"text-white"},{id:"gemini",name:"Gemini",color:"bg-blue-500",textColor:"text-white"},{id:"github",name:"GitHub Copilot",color:"bg-gray-700",textColor:"text-white"}];function h(){const[t,r]=l.useState(0);return l.useEffect(()=>{const s=setInterval(()=>{r(a=>(a+1)%o.length)},2e3);return()=>clearInterval(s)},[]),e.jsxs("div",{className:"mt-16 w-full max-w-4xl relative h-[360px] hidden md:flex items-center justify-center animate-[float_6s_ease-in-out_infinite]",children:[e.jsxs("div",{className:"relative z-20 w-32 h-32 rounded-full bg-[#23180f] border-2 border-[#f97815] shadow-[0_0_40px_rgba(249,120,21,0.3)] flex flex-col items-center justify-center gap-1 group cursor-pointer hover:scale-105 transition-transform duration-500",children:[e.jsx("span",{className:"material-symbols-outlined text-4xl text-[#f97815]",children:"hub"}),e.jsx("span",{className:"text-xs font-bold text-white tracking-widest uppercase",children:"FSRouter"}),e.jsx("div",{className:"absolute inset-0 rounded-full border border-[#f97815]/30 animate-ping opacity-20"})]}),e.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 flex flex-col gap-7",children:m.map(s=>e.jsx("div",{className:"flex items-center gap-3 opacity-70 hover:opacity-100 transition-opacity group",children:e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[#23180f] border border-[#3a2f27] flex items-center justify-center overflow-hidden p-2 hover:border-[#f97815]/50 transition-all hover:scale-105",children:e.jsx(i,{src:s.image,alt:s.name,size:48,className:"object-contain rounded-xl max-w-[48px] max-h-[48px]",fallbackText:s.name.slice(0,2).toUpperCase()})})},s.id))}),e.jsxs("svg",{className:"absolute inset-0 w-full h-full z-10 pointer-events-none stroke-yellow-700",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{className:"animate-[dash_2s_linear_infinite]",d:"M 60 50 C 250 70, 250 180, 360 180",fill:"none",strokeDasharray:"5,5",strokeWidth:"2"}),e.jsx("path",{className:"animate-[dash_2s_linear_infinite]",d:"M 60 140 C 250 140, 250 180, 360 180",fill:"none",strokeDasharray:"5,5",strokeWidth:"2"}),e.jsx("path",{className:"animate-[dash_2s_linear_infinite]",d:"M 60 210 C 250 210, 250 180, 360 180",fill:"none",strokeDasharray:"5,5",strokeWidth:"2"}),e.jsx("path",{className:"animate-[dash_2s_linear_infinite]",d:"M 60 300 C 250 280, 250 180, 360 180",fill:"none",strokeDasharray:"5,5",strokeWidth:"2"})]}),e.jsxs("svg",{className:"absolute inset-0 w-full h-full z-10 pointer-events-none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M 440 180 C 550 180, 550 50, 740 50",fill:"none",stroke:t===0?"#f97815":"rgb(75, 85, 99)",strokeWidth:t===0?"3":"2",className:t===0?"animate-pulse":""}),e.jsx("path",{d:"M 440 180 C 550 180, 550 130, 740 130",fill:"none",stroke:t===1?"#f97815":"rgb(75, 85, 99)",strokeWidth:t===1?"3":"2",className:t===1?"animate-pulse":""}),e.jsx("path",{d:"M 440 180 C 550 180, 550 230, 740 230",fill:"none",stroke:t===2?"#f97815":"rgb(75, 85, 99)",strokeWidth:t===2?"3":"2",className:t===2?"animate-pulse":""}),e.jsx("path",{d:"M 440 180 C 550 180, 550 310, 740 310",fill:"none",stroke:t===3?"#f97815":"rgb(75, 85, 99)",strokeWidth:t===3?"3":"2",className:t===3?"animate-pulse":""})]}),e.jsx("div",{className:"absolute right-0 top-0 bottom-0 flex flex-col justify-between py-6",children:o.map((s,a)=>e.jsx("div",{className:`px-4 py-2 rounded-lg ${s.color} ${s.textColor} flex items-center justify-center font-bold text-xs shadow-lg hover:scale-110 transition-all cursor-help min-w-[140px] ${t===a?"ring-4 ring-[#f97815]/50 scale-110":""}`,title:s.name,children:s.name},s.id))}),e.jsx("div",{className:"md:hidden mt-8 w-full p-4 rounded-lg bg-[#23180f] border border-[#3a2f27]",children:e.jsx("p",{className:"text-sm text-center text-gray-400",children:"Interactive diagram visible on desktop"})})]})}function u(){return e.jsx("section",{className:"py-24 border-y border-[#3a2f27] bg-[#23180f]/30",id:"how-it-works",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-6",children:[e.jsxs("div",{className:"mb-16",children:[e.jsx("h2",{className:"text-3xl md:text-4xl font-bold mb-4",children:"How FSRouter Works"}),e.jsx("p",{className:"text-gray-400 max-w-xl text-lg",children:"Data flows seamlessly from your application through our intelligent routing layer to the best provider for the job."})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-8 relative",children:[e.jsx("div",{className:"hidden md:block absolute top-12 left-[16%] right-[16%] h-[2px] bg-linear-to-r from-gray-700 via-[#f97815] to-gray-700 -z-10"}),e.jsxs("div",{className:"flex flex-col gap-6 relative group",children:[e.jsx("div",{className:"w-24 h-24 rounded-2xl bg-[#181411] border border-[#3a2f27] flex items-center justify-center shadow-xl group-hover:border-gray-500 transition-colors z-10 mx-auto md:mx-0",children:e.jsx("span",{className:"material-symbols-outlined text-4xl text-gray-300",children:"terminal"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold mb-2",children:"1. CLI & SDKs"}),e.jsx("p",{className:"text-sm text-gray-400",children:"Your requests start from your favorite tools or our unified SDK. Just change the base URL."})]})]}),e.jsxs("div",{className:"flex flex-col gap-6 relative group md:items-center md:text-center",children:[e.jsx("div",{className:"w-24 h-24 rounded-2xl bg-[#181411] border-2 border-[#f97815] flex items-center justify-center shadow-[0_0_30px_rgba(249,120,21,0.2)] z-10 mx-auto",children:e.jsx("span",{className:"material-symbols-outlined text-4xl text-[#f97815] animate-pulse",children:"hub"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold mb-2 text-[#f97815]",children:"2. FSRouter Hub"}),e.jsx("p",{className:"text-sm text-gray-400",children:"Our engine analyzes the prompt, checks provider health, and routes for lowest latency or cost."})]})]}),e.jsxs("div",{className:"flex flex-col gap-6 relative group md:items-end md:text-right",children:[e.jsx("div",{className:"w-24 h-24 rounded-2xl bg-[#181411] border border-[#3a2f27] flex items-center justify-center shadow-xl group-hover:border-gray-500 transition-colors z-10 mx-auto md:mx-0",children:e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-white/10"}),e.jsx("div",{className:"w-6 h-6 rounded bg-white/10"}),e.jsx("div",{className:"w-6 h-6 rounded bg-white/10"}),e.jsx("div",{className:"w-6 h-6 rounded bg-white/10"})]})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold mb-2",children:"3. AI Providers"}),e.jsx("p",{className:"text-sm text-gray-400",children:"The request is fulfilled by OpenAI, Anthropic, Gemini, or others instantly."})]})]})]})]})})}const f=[{icon:"link",title:"Unified Endpoint",desc:"Access all providers via a single standard API URL.",colors:{border:"hover:border-blue-500/50",bg:"hover:bg-blue-500/5",iconBg:"bg-blue-500/10",iconText:"text-blue-500",titleHover:"group-hover:text-blue-400"}},{icon:"bolt",title:"Easy Setup",desc:"Get up and running in minutes with npx command.",colors:{border:"hover:border-orange-500/50",bg:"hover:bg-orange-500/5",iconBg:"bg-orange-500/10",iconText:"text-orange-500",titleHover:"group-hover:text-orange-400"}},{icon:"shield_with_heart",title:"Model Fallback",desc:"Automatically switch providers on failure or high latency.",colors:{border:"hover:border-rose-500/50",bg:"hover:bg-rose-500/5",iconBg:"bg-rose-500/10",iconText:"text-rose-500",titleHover:"group-hover:text-rose-400"}},{icon:"monitoring",title:"Usage Tracking",desc:"Detailed analytics and cost monitoring across all models.",colors:{border:"hover:border-purple-500/50",bg:"hover:bg-purple-500/5",iconBg:"bg-purple-500/10",iconText:"text-purple-500",titleHover:"group-hover:text-purple-400"}},{icon:"key",title:"OAuth & API Keys",desc:"Securely manage credentials in one vault.",colors:{border:"hover:border-amber-500/50",bg:"hover:bg-amber-500/5",iconBg:"bg-amber-500/10",iconText:"text-amber-500",titleHover:"group-hover:text-amber-400"}},{icon:"cloud_sync",title:"Cloud Sync",desc:"Sync your configurations across devices instantly.",colors:{border:"hover:border-sky-500/50",bg:"hover:bg-sky-500/5",iconBg:"bg-sky-500/10",iconText:"text-sky-500",titleHover:"group-hover:text-sky-400"}},{icon:"terminal",title:"CLI Support",desc:"Works with Claude Code, Codex, Cline, Cursor, and more.",colors:{border:"hover:border-emerald-500/50",bg:"hover:bg-emerald-500/5",iconBg:"bg-emerald-500/10",iconText:"text-emerald-500",titleHover:"group-hover:text-emerald-400"}},{icon:"dashboard",title:"Dashboard",desc:"Visual dashboard for real-time traffic analysis.",colors:{border:"hover:border-fuchsia-500/50",bg:"hover:bg-fuchsia-500/5",iconBg:"bg-fuchsia-500/10",iconText:"text-fuchsia-500",titleHover:"group-hover:text-fuchsia-400"}}];function g(){return e.jsx("section",{className:"py-24 px-6",id:"features",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-16",children:[e.jsx("h2",{className:"text-3xl md:text-4xl font-bold mb-4",children:"Powerful Features"}),e.jsx("p",{className:"text-gray-400 max-w-xl text-lg",children:"Everything you need to manage your AI infrastructure in one place, built for scale."})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:f.map(t=>e.jsxs("div",{className:`p-6 rounded-xl bg-[#23180f] border border-[#3a2f27] ${t.colors.border} ${t.colors.bg} transition-all duration-300 group`,children:[e.jsx("div",{className:`w-10 h-10 rounded-lg ${t.colors.iconBg} flex items-center justify-center mb-4 ${t.colors.iconText} group-hover:scale-110 transition-transform duration-300`,children:e.jsx("span",{className:"material-symbols-outlined",children:t.icon})}),e.jsx("h3",{className:`text-lg font-bold mb-2 ${t.colors.titleHover} transition-colors`,children:t.title}),e.jsx("p",{className:"text-sm text-gray-400 leading-relaxed",children:t.desc})]},t.title))})]})})}function b(){const{copied:t,copy:r}=d(),s=a=>{r(a,"landing")};return e.jsx("section",{className:"py-24 px-6 bg-[#120f0d]",children:e.jsx("div",{className:"max-w-7xl mx-auto",children:e.jsxs("div",{className:"flex flex-col lg:flex-row gap-16 items-start",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-3xl md:text-4xl font-bold mb-6",children:"Get Started in 30 Seconds"}),e.jsx("p",{className:"text-gray-400 text-lg mb-8",children:"Install FSRouter, configure your providers via web dashboard, and start routing AI requests."}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("div",{className:"flex gap-4",children:[e.jsx("div",{className:"flex-none w-8 h-8 rounded-full bg-[#f97815]/20 text-[#f97815] flex items-center justify-center font-bold",children:"1"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-lg",children:"Install FSRouter"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Run npx command to start the server instantly"})]})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx("div",{className:"flex-none w-8 h-8 rounded-full bg-[#f97815]/20 text-[#f97815] flex items-center justify-center font-bold",children:"2"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-lg",children:"Open Dashboard"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Configure providers and API keys via web interface"})]})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx("div",{className:"flex-none w-8 h-8 rounded-full bg-[#f97815]/20 text-[#f97815] flex items-center justify-center font-bold",children:"3"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-lg",children:"Route Requests"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Point your CLI tools to http://localhost:20128"})]})]})]})]}),e.jsx("div",{className:"flex-1 w-full",children:e.jsxs("div",{className:"rounded-xl overflow-hidden bg-[#1e1e1e] border border-[#3a2f27] shadow-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 bg-[#252526] border-b border-gray-700",children:[e.jsx("div",{className:"w-3 h-3 rounded-full bg-red-500"}),e.jsx("div",{className:"w-3 h-3 rounded-full bg-yellow-500"}),e.jsx("div",{className:"w-3 h-3 rounded-full bg-green-500"}),e.jsx("div",{className:"ml-2 text-xs text-gray-500 font-mono",children:"terminal"})]}),e.jsxs("div",{className:"p-6 font-mono text-sm leading-relaxed overflow-x-auto",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4 group cursor-pointer",onClick:()=>s("npx fsrouter"),children:[e.jsx("span",{className:"text-green-400",children:"$"}),e.jsx("span",{className:"text-white",children:"npx fsrouter"}),e.jsx("span",{className:"ml-auto text-gray-500 text-xs opacity-0 group-hover:opacity-100",children:t==="landing"?"✓ Copied":"Copy"})]}),e.jsxs("div",{className:"text-gray-400 mb-6",children:[e.jsx("span",{className:"text-[#f97815]",children:">"})," Starting FSRouter...",e.jsx("br",{}),e.jsx("span",{className:"text-[#f97815]",children:">"})," Server running on ",e.jsx("span",{className:"text-blue-400",children:"http://localhost:20128"}),e.jsx("br",{}),e.jsx("span",{className:"text-[#f97815]",children:">"})," Dashboard: ",e.jsx("span",{className:"text-blue-400",children:"http://localhost:20128/dashboard"}),e.jsx("br",{}),e.jsx("span",{className:"text-green-400",children:">"})," Ready to route! ✓"]}),e.jsx("div",{className:"text-xs text-gray-500 mb-2 border-t border-gray-700 pt-4",children:"📝 Configure providers in dashboard or use environment variables"}),e.jsxs("div",{className:"text-gray-400 text-xs",children:[e.jsx("span",{className:"text-purple-400",children:"Data Location:"}),e.jsx("br",{}),e.jsx("span",{className:"text-gray-500",children:" macOS/Linux:"})," ~/.fsrouter/db/data.sqlite",e.jsx("br",{}),e.jsx("span",{className:"text-gray-500",children:" Windows:"})," %APPDATA%/fsrouter/db/data.sqlite"]})]})]})})]})})})}function p(){return e.jsx("footer",{className:"border-t border-[#3a2f27] bg-[#120f0d] pt-16 pb-8 px-6",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 gap-8 mb-16",children:[e.jsxs("div",{className:"col-span-2 lg:col-span-2",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"size-6 rounded bg-[#f97815] flex items-center justify-center text-white",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"hub"})}),e.jsx("h3",{className:"text-white text-lg font-bold",children:"FSRouter"})]}),e.jsx("p",{className:"text-gray-500 text-sm max-w-xs mb-6",children:"The unified endpoint for AI generation. Connect, route, and manage your AI providers with ease."}),e.jsx("div",{className:"flex gap-4",children:e.jsx("a",{className:"text-gray-400 hover:text-white transition-colors",href:"https://github.com/nexusrouters/fsrouter",target:"_blank",rel:"noopener noreferrer",children:e.jsx("span",{className:"material-symbols-outlined",children:"code"})})})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("h4",{className:"font-bold text-white",children:"Product"}),e.jsx("a",{className:"text-gray-400 hover:text-[#f97815] text-sm transition-colors",href:"#features",children:"Features"}),e.jsx("a",{className:"text-gray-400 hover:text-[#f97815] text-sm transition-colors",href:"/dashboard",children:"Dashboard"}),e.jsx("a",{className:"text-gray-400 hover:text-[#f97815] text-sm transition-colors",href:"https://github.com/nexusrouters/fsrouter",target:"_blank",rel:"noopener noreferrer",children:"Changelog"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("h4",{className:"font-bold text-white",children:"Resources"}),e.jsx("a",{className:"text-gray-400 hover:text-[#f97815] text-sm transition-colors",href:"https://github.com/nexusrouters/fsrouter#readme",target:"_blank",rel:"noopener noreferrer",children:"Documentation"}),e.jsx("a",{className:"text-gray-400 hover:text-[#f97815] text-sm transition-colors",href:"https://github.com/nexusrouters/fsrouter",target:"_blank",rel:"noopener noreferrer",children:"GitHub"}),e.jsx("a",{className:"text-gray-400 hover:text-[#f97815] text-sm transition-colors",href:"https://www.npmjs.com/package/fsrouter",target:"_blank",rel:"noopener noreferrer",children:"NPM"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("h4",{className:"font-bold text-white",children:"Legal"}),e.jsx("a",{className:"text-gray-400 hover:text-[#f97815] text-sm transition-colors",href:"https://github.com/nexusrouters/fsrouter/blob/main/LICENSE",target:"_blank",rel:"noopener noreferrer",children:"MIT License"})]})]}),e.jsxs("div",{className:"border-t border-[#3a2f27] pt-8 flex flex-col md:flex-row justify-between items-center gap-4",children:[e.jsx("p",{className:"text-gray-600 text-sm",children:"© 2025 FSRouter. All rights reserved."}),e.jsxs("div",{className:"flex gap-6",children:[e.jsx("a",{className:"text-gray-600 hover:text-white text-sm transition-colors",href:"https://github.com/nexusrouters/fsrouter",target:"_blank",rel:"noopener noreferrer",children:"GitHub"}),e.jsx("a",{className:"text-gray-600 hover:text-white text-sm transition-colors",href:"https://www.npmjs.com/package/fsrouter",target:"_blank",rel:"noopener noreferrer",children:"NPM"})]})]})]})})}function w(){const t=n();return e.jsxs("div",{className:"relative text-white font-sans overflow-x-hidden antialiased selection:bg-[#f97815] selection:text-white",children:[e.jsxs("div",{className:"fixed inset-0 z-0 overflow-hidden pointer-events-none bg-[#181411]",children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.06]",style:{backgroundImage:"linear-gradient(to right, #f97815 1px, transparent 1px), linear-gradient(to bottom, #f97815 1px, transparent 1px)",backgroundSize:"50px 50px"}}),e.jsx("div",{className:"absolute top-0 left-1/4 w-[700px] h-[700px] bg-[#f97815]/12 rounded-full blur-[130px] animate-blob"}),e.jsx("div",{className:"absolute top-1/3 right-1/4 w-[600px] h-[600px] bg-purple-500/10 rounded-full blur-[130px] animate-blob",style:{animationDelay:"2s",animationDuration:"22s"}}),e.jsx("div",{className:"absolute bottom-0 left-1/2 w-[650px] h-[650px] bg-blue-500/8 rounded-full blur-[130px] animate-blob",style:{animationDelay:"4s",animationDuration:"25s"}}),e.jsx("div",{className:"absolute inset-0",style:{background:"radial-gradient(circle at center, transparent 0%, rgba(24, 20, 17, 0.4) 100%)"}})]}),e.jsxs("div",{className:"relative z-10",children:[e.jsx(c,{}),e.jsxs("main",{children:[e.jsxs("div",{className:"relative",children:[e.jsx(x,{}),e.jsx("div",{className:"flex justify-center pb-20",children:e.jsx(h,{})})]}),e.jsx(b,{}),e.jsx(u,{}),e.jsx(g,{}),e.jsxs("section",{className:"py-32 px-6 relative overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 bg-linear-to-t from-[#f97815]/5 to-transparent pointer-events-none"}),e.jsxs("div",{className:"max-w-4xl mx-auto text-center relative z-10",children:[e.jsx("h2",{className:"text-4xl md:text-5xl font-black mb-6",children:"Ready to Simplify Your AI Infrastructure?"}),e.jsx("p",{className:"text-xl text-gray-400 mb-10 max-w-2xl mx-auto",children:"Join developers who are streamlining their AI integrations with FSRouter. Open source and free to start."}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-center gap-4",children:[e.jsx("button",{onClick:()=>t("/dashboard"),className:"w-full sm:w-auto h-14 px-10 rounded-lg bg-[#f97815] hover:bg-[#e0650a] text-[#181411] text-lg font-bold transition-all shadow-[0_0_20px_rgba(249,120,21,0.5)]",children:"Start Free"}),e.jsx("button",{onClick:()=>window.open("https://github.com/nexusrouters/fsrouter#readme","_blank"),className:"w-full sm:w-auto h-14 px-10 rounded-lg border border-[#3a2f27] hover:bg-[#23180f] text-white text-lg font-bold transition-all",children:"Read Documentation"})]})]})]})]}),e.jsx(p,{})]})]})}export{w 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.BO_pNnMt.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.CLW2-XwE.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 o}from"./index.BO_pNnMt.js";import{b as r}from"./router.Cjj1--8t.js";import{g as a}from"./machine.CagOtseJ.js";import{A as i}from"./EndpointPageClient.BN-D__UM.js";import"./zustand.akaTi5uX.js";import"./NoAuthProxyCard.CLW2-XwE.js";import"./Loading.BoU3gy5K.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{j as e}from"./index.BO_pNnMt.js";import{b as n}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function j(){const[o,p]=n.useState("tts"),[x,h]=n.useState(""),[t,s]=n.useState(null),[i,r]=n.useState(!1),u=async()=>{r(!0);try{const a=await fetch("/api/audio/speech",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:x,model:"tts-1",voice:"alloy"})});if(a.ok){const c=await a.blob();s({audio:URL.createObjectURL(c)})}else s({error:await a.text()})}catch(a){s({error:a.message})}r(!1)},m=async a=>{const c=a.target.files[0];if(!c)return;r(!0);const l=new FormData;l.append("file",c),l.append("model","whisper-1");try{const d=await fetch("/api/audio/transcriptions",{method:"POST",body:l});s(await d.json())}catch(d){s({error:d.message})}r(!1)};return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Audio"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>p("tts"),className:`px-4 py-2 rounded-lg ${o==="tts"?"bg-primary text-white":"bg-black/5"}`,children:"Text to Speech"}),e.jsx("button",{onClick:()=>p("stt"),className:`px-4 py-2 rounded-lg ${o==="stt"?"bg-primary text-white":"bg-black/5"}`,children:"Speech to Text"})]}),o==="tts"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("textarea",{className:"w-full p-3 rounded-lg border h-40",placeholder:"Enter text to convert to speech...",value:x,onChange:a=>h(a.target.value)}),e.jsx("button",{onClick:u,disabled:i,className:"px-4 py-2 bg-primary text-white rounded-lg",children:i?"Generating...":"Generate Speech"}),(t==null?void 0:t.audio)&&e.jsx("audio",{controls:!0,src:t.audio,className:"w-full"})]}),o==="stt"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("input",{type:"file",accept:"audio/*",onChange:m,className:"block"}),i&&e.jsx("p",{children:"Transcribing..."})]}),(t==null?void 0:t.error)&&e.jsx("p",{className:"text-red-500",children:t.error}),(t==null?void 0:t.text)&&e.jsx("pre",{className:"p-4 bg-black/5 rounded-lg text-sm",children:t.text})]})}export{j as default};