@fudrouter/fsrouter 0.6.118 → 0.6.119

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/package.json +1 -1
  2. package/public/assets/EndpointPageClient.Di2YqgPf.js +6 -0
  3. package/public/assets/Loading.D9qCFX3R.js +1 -0
  4. package/public/assets/NoAuthProxyCard.DMCykSRG.js +89 -0
  5. package/public/assets/index.C5VWu_q7.js +89 -0
  6. package/public/assets/page.BFEjgGXd.js +2 -0
  7. package/public/assets/page.BIksOupz.js +1 -0
  8. package/public/assets/page.BN35ziqx.js +6 -0
  9. package/public/assets/page.BY-Z5lJc.js +1 -0
  10. package/public/assets/page.BYuvYI81.js +1 -0
  11. package/public/assets/page.BZn6EjgR.js +1 -0
  12. package/public/assets/page.BqDkuLBL.js +1 -0
  13. package/public/assets/page.Brx8iIwy.js +31 -0
  14. package/public/assets/page.ByoxqtTd.js +1 -0
  15. package/public/assets/page.C-2PY_Ek.js +6 -0
  16. package/public/assets/page.CBJ3PIz6.js +1 -0
  17. package/public/assets/page.CC2igP7g.js +5 -0
  18. package/public/assets/page.CJV7n_Cb.js +1 -0
  19. package/public/assets/page.CadeLR3B.js +2 -0
  20. package/public/assets/page.Cn9VXlxl.js +1 -0
  21. package/public/assets/page.Cnk5NKtT.js +1 -0
  22. package/public/assets/page.Ctr5GGfe.js +23 -0
  23. package/public/assets/page.CvY1-VAN.js +5 -0
  24. package/public/assets/page.DD2_vWM3.js +1 -0
  25. package/public/assets/page.DFOtpzzq.js +7 -0
  26. package/public/assets/page.DGqaAFu_.js +1 -0
  27. package/public/assets/page.DSCWOtet.js +1 -0
  28. package/public/assets/page.DUXPs518.js +1 -0
  29. package/public/assets/page.DV-sp6Ji.js +1 -0
  30. package/public/assets/page.DarYN1Wo.js +1 -0
  31. package/public/assets/page.DsnVF9ld.js +1 -0
  32. package/public/assets/page.DuJrvy6q.js +1 -0
  33. package/public/assets/page.DvVWtaJ8.js +1 -0
  34. package/public/assets/page.Dvoll2rR.js +64 -0
  35. package/public/assets/page.K41VgPhA.js +1 -0
  36. package/public/assets/page.LA8kHbDi.js +4 -0
  37. package/public/assets/page.UGWWqB47.js +1 -0
  38. package/public/assets/page.eObJ7Eqq.js +1 -0
  39. package/public/assets/page.hGYtnZEk.js +1 -0
  40. package/public/assets/page.hr04hSjp.js +1 -0
  41. package/public/assets/page.imKuq2A5.js +1 -0
  42. package/public/assets/page.zF9qqJjX.js +1 -0
  43. package/public/index.html +4 -4
@@ -0,0 +1,23 @@
1
+ import{j as e,B as m}from"./index.C5VWu_q7.js";import{b as r}from"./router.Cjj1--8t.js";import{C as Ye,T as Ge,B as qe}from"./NoAuthProxyCard.DMCykSRG.js";import{L as Xe}from"./Loading.D9qCFX3R.js";import"./zustand.akaTi5uX.js";function it(){const[u,h]=r.useState("codebuddy"),X=(x,ee,f)=>e.jsxs("button",{onClick:()=>h(x),className:`flex items-center gap-2 pb-3 text-sm font-semibold transition-all border-b-2 cursor-pointer ${u===x?"border-primary text-primary":"border-transparent text-text-muted hover:text-text-main"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:ee}),f]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex border-b border-border-subtle pb-px gap-6 flex-wrap",children:[X("codebuddy","smart_toy","Automation"),X("fsmail","mail","FSMail Temp Mail")]}),u==="codebuddy"&&e.jsx(et,{}),u==="fsmail"&&e.jsx(st,{})]})}function et(){const u={codebuddy:"CodeBuddy",kiro:"Kiro AI",qoder:"Qoder",leonardo:"Leonardo AI",weavy:"Weavy AI","kimi-coding":"Kimi Coding",cloudflare:"Cloudflare Workers AI",openvecta:"OpenVecta",flashloop:"Flashloop"},[h,X]=r.useState([]),[x,ee]=r.useState(""),[f,te]=r.useState(null),[N,I]=r.useState([]);r.useRef(null);const $=r.useRef(new Set),[se,ue]=r.useState(1),ae=r.useRef(-1),pe=10,Se=r.useRef(!1),[g,Ue]=r.useState(!1),[K,Ce]=r.useState(3),[$e,re]=r.useState(!1),[ne,he]=r.useState(!1),[A,Re]=r.useState(""),[_e,j]=r.useState(""),[i,R]=r.useState("cloudflare"),[G,be]=r.useState(!0),[O,U]=r.useState(!1),[Te,We]=r.useState(!1),[oe,fe]=r.useState(!1),[k,V]=r.useState([]),[ze,W]=r.useState(!1),[ge,le]=r.useState(""),[Be,Ae]=r.useState(""),[Fe,S]=r.useState(""),[Le,Q]=r.useState(!1),[z,L]=r.useState({general:!0,proxy:!1}),C=t=>{L(a=>({...a,[t]:!a[t]}))},Pe=(t,a,n,l)=>e.jsxs("button",{onClick:l,type:"button",className:"flex items-center gap-1.5 hover:text-primary text-text-main font-semibold text-xs transition-all cursor-pointer select-none py-1",children:[e.jsx("span",{className:`material-symbols-outlined text-[16px] text-text-muted transition-transform duration-200 ${n?"":"-rotate-90"}`,children:"expand_more"}),e.jsx("span",{children:t})]}),[_,Z]=r.useState(!1),[D,B]=r.useState(0),[F,je]=r.useState({}),[d,ie]=r.useState(!1),[T,J]=r.useState(new Set),[M,Je]=r.useState(!1),[ye,Oe]=r.useState(5),[we,He]=r.useState([]),[ce,de]=r.useState("");r.useEffect(()=>{if(typeof window<"u"){const t=localStorage.getItem("automation_target_provider");R(t||"cloudflare");const a=localStorage.getItem("automation_concurrency");a&&Ce(parseInt(a)||3);const n=localStorage.getItem("automation_auto_email");n&&Je(n==="1");const l=localStorage.getItem("automation_generate_count");l&&Oe(parseInt(l)||5);const b=localStorage.getItem("automation_open_settings");if(b)try{L(c=>({...c,...JSON.parse(b)}))}catch(c){console.error("Failed to parse saved automation open settings",c)}Ue(!0)}},[]),r.useEffect(()=>{g&&localStorage.setItem("automation_target_provider",i)},[i,g]),r.useEffect(()=>{g&&localStorage.setItem("automation_concurrency",String(K))},[K,g]),r.useEffect(()=>{g&&localStorage.setItem("automation_auto_email",M?"1":"0")},[M,g]),r.useEffect(()=>{g&&localStorage.setItem("automation_generate_count",String(ye))},[ye,g]),r.useEffect(()=>{g&&localStorage.setItem("automation_open_settings",JSON.stringify(z))},[z,g]);const[y,Ve]=r.useState(""),[xe,De]=r.useState(1),Me=8;r.useEffect(()=>{fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"list-domains"})}).then(t=>t.json()).then(t=>{var a;(a=t.domains)!=null&&a.length&&(He(t.domains),de(n=>n||t.default_domain||t.domains[0]))}).catch(()=>{})},[]);const w=async(t=!1)=>{var a,n;try{const l=await fetch("/api/automation/codebuddy"),b=await l.json();if(l.ok){if(X(b.accounts||[]),ee(b.active_job_id||""),b.active_job_id&&Se.current&&(Se.current=!1,$.current.clear()),!Se.current)if(te(b.active_job||null),(n=(a=b.active_job)==null?void 0:a.results)!=null&&n.length){const c=b.active_job.results.filter(p=>p).map((p,ke)=>({idx:ke,email:p.email||`Account #${ke+1}`,status:p.status||"pending",step:p.status==="failed"?p.error||p.step||"-":p.step||"-",ok:p.ok})).filter(p=>!$.current.has(p.email.toLowerCase()));I(c)}else b.active_job_id;if(t){const c=b.settings||{};re(c.auto_fsrouter==="1"||c.auto_fsrouter===!0),be(!!c.browser_headless),U(!!c.debug_mode),We(c.leave_canva_team==="1"||c.leave_canva_team===!0),fe(!!c.proxy_enabled);try{const p=JSON.parse(c.proxy_pool||"[]");V(Array.isArray(p)?p:[])}catch{V([])}Ae(c.leonardo_invite_link||""),S(c.codebuddy_2captcha_api_key||"")}}}catch(l){console.error(l)}};r.useEffect(()=>{g&&w(!0)},[g]),r.useEffect(()=>{if(!g)return;const a=setInterval(()=>w(!1),x?3e3:15e3);return()=>clearInterval(a)},[g,x]),r.useEffect(()=>{if(N.length===0){ue(1),ae.current=-1;return}const t=N.findIndex(a=>a.status==="running");if(t!==-1&&t!==ae.current){ae.current=t;const a=Math.floor(t/pe)+1;ue(a)}},[N]),r.useEffect(()=>{if(O&&x){const t=setInterval(()=>{fetch("/api/automation/codebuddy/debug-vnc?action=status").then(a=>a.json()).then(a=>{a.available&&(Z(!0),B(Date.now()),clearInterval(t))}).catch(()=>{})},2e3);return()=>clearInterval(t)}else if(!x&&_){const t=setTimeout(()=>{Z(!1),B(0)},1e4);return()=>clearTimeout(t)}},[O,x]);const Qe=async()=>{Q(!0);try{(await fetch("/api/automation/codebuddy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"settings",auto_fsrouter:$e,browser_headless:G,debug_mode:O,leave_canva_team:Te,proxy_enabled:oe,proxy_pool:JSON.stringify(k),leonardo_invite_link:Be,codebuddy_2captcha_api_key:Fe})})).ok&&(j("Settings saved successfully."),setTimeout(()=>j(""),3e3),await w(!0))}catch(t){console.error(t)}finally{Q(!1)}},Ze=async()=>{var t,a;if(!A.trim()){j("Please enter at least one email:password line.");return}j("Adding accounts...");try{const n=await fetch("/api/automation/codebuddy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add-google",accounts_text:A,run_now:ne,concurrency:K,provider:i})}),l=await n.json();n.ok?(Re(""),j(`Created: ${((t=l.created)==null?void 0:t.length)||0}, Skipped: ${((a=l.skipped)==null?void 0:a.length)||0}${l.job_id?" (Job started)":""}`),w()):j(`Error: ${l.error}`)}catch(n){j(`Failed: ${n.message}`)}},Ee=async()=>{var t;j("Generating emails...");try{const a=await fetch("/api/automation/codebuddy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"auto-generate-email",count:ye,provider:i,run_now:!0,concurrency:K,domain:ce||void 0})}),n=await a.json();a.ok?(j(`✓ Generated ${((t=n.created)==null?void 0:t.length)||0} temp mail accounts and started signup job.`),w()):j(`Error: ${n.error||"Failed to generate emails"}`)}catch(a){console.error(a),j("Failed to contact server.")}},Ie=async()=>{try{const t=await fetch("/api/automation/codebuddy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"run-all",concurrency:K,provider:i})}),a=await t.json();t.ok?($.current.clear(),ee(a.job_id),w()):j(`Failed: ${a.error}`)}catch(t){j(`Failed: ${t.message}`)}},E=async()=>{try{const t=await fetch("/api/automation/codebuddy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop"})}),a=await t.json();t.ok?w():alert(a.error)}catch(t){console.error(t)}},ve=async t=>{try{const a=await fetch(`/api/automation/codebuddy/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"run"})}),n=await a.json();a.ok?($.current.clear(),ee(n.job_id),w()):alert(n.error)}catch(a){console.error(a)}},Ne=async t=>{try{const a=await fetch(`/api/automation/codebuddy/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add-to-fsrouter"})}),n=await a.json();a.ok?(alert(`✓ ${n.message||"Added successfully!"}`),w()):alert(`Failed: ${n.error}`)}catch(a){console.error(a)}},s=async()=>{const t=u[i]||"CodeBuddy";if(confirm(`Inject all Ready ${t} accounts into fsrouter?`))try{const a=await fetch("/api/automation/codebuddy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"bulk-add-to-fsrouter",provider:i})}),n=await a.json();a.ok?(alert(n.message),w()):alert(`Failed: ${n.error}`)}catch(a){console.error(a)}},o=async t=>{if(!confirm("Hapus akun ini?"))return;const a=confirm("Apakah ingin menghapus juga koneksi akun ini di fsrouter?"),n=h.find(l=>l.id===t);try{await fetch(`/api/automation/codebuddy/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"delete",deleteFromfsrouter:a})}),n&&($.current.add(n.email.toLowerCase()),I(l=>l.filter(b=>b.email.toLowerCase()!==n.email.toLowerCase()))),w()}catch(l){console.error(l)}},v=async(t,a=null)=>{const n=a?`${a.length} selected accounts`:`all accounts with status: ${t.join(", ")}`;if(!confirm(`Delete ${n}?`))return;const l=confirm("Apakah ingin menghapus juga koneksi akun-akun tersebut di fsrouter?"),b=h.filter(c=>a?a.includes(c.id):c.provider===i&&t.includes(c.api_key_status)).map(c=>c.email.toLowerCase());try{(await fetch("/api/automation/codebuddy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a?{action:"bulk-delete-ids",ids:a,provider:i,deleteFromfsrouter:l}:{action:"bulk-delete",statuses:t,provider:i,deleteFromfsrouter:l})})).ok&&(b.forEach(p=>$.current.add(p)),I(p=>p.filter(ke=>!b.includes(ke.email.toLowerCase()))),J(new Set),w())}catch(c){console.error(c)}},P=h.filter(t=>t.provider===i&&(t.email.toLowerCase().includes(y.toLowerCase())||t.api_key&&t.api_key.toLowerCase().includes(y.toLowerCase()))),me=Math.ceil(P.length/Me),H=P.slice((xe-1)*Me,xe*Me),Y=Math.ceil(N.length/pe)||1,q=Math.min(se,Y),Ke=N.slice((q-1)*pe,q*pe);return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-1 space-y-6",children:[e.jsxs(Ye,{padding:"md",className:"space-y-4",children:[e.jsxs("h2",{className:"text-sm font-bold text-text-main flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"person_add"}),(i==="leonardo"||i==="weavy"||i==="cloudflare")&&M?"Generate Temp Accounts":"Add Accounts"]}),e.jsxs("div",{className:"flex flex-col gap-1.5 pb-1",children:[e.jsx("label",{className:"text-xs font-semibold text-text-main",children:"Target Provider Connection"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:i==="weavy"?"/providers/weavy.jpeg":i==="kimi-coding"?"/providers/kimi.png":`/providers/${i}.png`,alt:i,className:"size-5 rounded object-contain",onError:t=>{t.target.style.display="none"}}),e.jsxs("select",{value:i,onChange:t=>{const a=t.target.value;R(a),De(1)},className:"flex-1 text-xs p-2 rounded-lg border border-border-subtle bg-surface text-text-main focus:outline-none focus:border-primary cursor-pointer",children:[e.jsx("option",{value:"cloudflare",children:"☁️ Cloudflare Workers AI"}),e.jsx("option",{value:"openvecta",children:"🟣 OpenVecta"}),e.jsx("option",{value:"flashloop",children:"⚡ Flashloop"})]})]})]}),(i==="leonardo"||i==="weavy"||i==="cloudflare"||i==="openvecta"||i==="flashloop")&&e.jsx("div",{className:"pt-1 border-t border-border-subtle",children:e.jsxs("label",{className:"flex items-center gap-2 text-xs text-text-main cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:M,onChange:t=>Je(t.target.checked),className:"rounded border-border-subtle accent-primary size-4"}),"Auto Generate Email (FSMail)"]})}),(i==="leonardo"||i==="weavy"||i==="cloudflare"||i==="openvecta"||i==="flashloop")&&M?e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-text-muted",children:"Count to generate:"}),e.jsx("input",{type:"number",min:1,max:50,value:ye,onChange:t=>Oe(parseInt(t.target.value)||1),className:"w-16 text-xs p-1.5 rounded-lg border border-border-subtle bg-surface text-center text-text-main"})]}),we.length>=1&&e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-text-muted",children:"Email domain:"}),e.jsx("select",{value:ce,onChange:t=>de(t.target.value),className:"flex-1 text-xs p-1.5 rounded-lg border border-border-subtle bg-surface text-text-main ml-2 max-w-[180px]",children:we.map(t=>e.jsxs("option",{value:t,children:["@",t]},t))})]}),e.jsx(m,{variant:"primary",size:"sm",fullWidth:!0,onClick:Ee,children:"Generate & Run"})]}):e.jsxs("div",{className:"space-y-4 pt-1",children:[e.jsxs("p",{className:"text-xs text-text-muted",children:["Format: ",e.jsx("code",{className:"bg-surface-2 px-1 rounded",children:"email:password"})," (one per line)."]}),e.jsx("textarea",{value:A,onChange:t=>Re(t.target.value),rows:4,placeholder:`user1@gmail.com:Passw0rd1
2
+ user2@gmail.com:Passw0rd2`,className:"w-full text-xs font-mono p-3 rounded-lg border border-border-subtle bg-surface focus:outline-none focus:border-primary resize-y text-text-main"}),e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-text-main cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:ne,onChange:t=>he(t.target.checked),className:"rounded border-border-subtle accent-primary size-4"}),"Run immediately"]}),e.jsx(m,{variant:"primary",size:"sm",onClick:Ze,children:"Add Accounts"})]})]}),_e&&e.jsx("p",{className:"text-[11px] text-primary italic",children:_e})]}),e.jsxs(Ye,{padding:"md",className:"space-y-4",children:[e.jsxs("h2",{className:"text-sm font-bold text-text-main flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"settings"}),"Automation Settings"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[Pe("General Settings","dns",z.general,()=>C("general")),z.general&&e.jsxs("div",{className:"pl-6 pr-2 py-2 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-medium text-text-main",children:"Headless Browser"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"Jalankan di latar belakang tanpa membuka jendela baru"})]}),e.jsx(Ge,{checked:G,onChange:be})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-medium text-text-main",children:"Tampilkan Preview Panel"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"Aktifkan live stream visual di bawah"})]}),e.jsx(Ge,{checked:O,onChange:U})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-xs font-medium text-text-main",children:"Auto Inject to fsrouter"}),e.jsx(Ge,{checked:$e,onChange:re})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[Pe("Outbound Proxy Settings","vpn_lock",z.proxy,()=>C("proxy")),z.proxy&&e.jsxs("div",{className:"pl-6 pr-2 py-2 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-xs font-medium text-text-main",children:"Enable Outbound Proxy"}),e.jsx(Ge,{checked:oe,onChange:fe})]}),oe&&e.jsxs("div",{className:"space-y-2 pt-1 border-t border-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-[11px] text-text-muted",children:[k.length," ",k.length===1?"proxy":"proxies"," configured"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[k.length>0&&e.jsx("button",{onClick:async()=>{if(d)return;ie(!0);const t={};for(const a of k){t[a]={testing:!0},je({...t});try{const l=await(await fetch("/api/automation/codebuddy/test-proxy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxy:a})})).json();t[a]=l}catch{t[a]={ok:!1,error:"Request failed"}}je({...t})}ie(!1)},disabled:d,className:`text-[11px] px-3 py-1 rounded-lg border font-medium transition-colors ${d?"bg-surface-2 border-border-subtle text-text-muted cursor-wait":"bg-surface-2 border-border-subtle hover:border-green-500 text-green-400 hover:text-green-300"}`,children:d?"⏳ Testing...":"🧪 Test"}),e.jsx("button",{onClick:()=>{le(k.join(`
3
+ `)),W(!0)},className:"text-[11px] px-3 py-1 rounded-lg bg-surface-2 border border-border-subtle hover:border-primary text-primary font-medium transition-colors",children:"✏️ Edit"})]})]}),k.length>0&&e.jsx("div",{className:"text-[10px] bg-surface-2 rounded-lg p-2 max-h-[120px] overflow-y-auto font-mono space-y-1",children:k.map((t,a)=>{const n=F[t],l=t.replace(/:[^:@]*@/,":***@");return e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate text-text-muted flex-1",title:l,children:l}),n&&e.jsx("span",{className:`shrink-0 whitespace-nowrap ${n.testing?"text-yellow-400":n.ok?"text-green-400":"text-red-400"}`,children:n.testing?"⏳":n.ok?`✅ ${n.ip} · ${n.latency}ms`:`❌ ${n.error}`})]},a)})})]})]})]}),e.jsx(m,{variant:"secondary",size:"sm",fullWidth:!0,onClick:Qe,disabled:Le,children:Le?"Saving...":"Save Settings"})]})]})]}),e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[(x||N.length>0)&&e.jsxs("div",{className:"border border-border-subtle bg-surface-2 rounded-xl p-4 space-y-3 relative overflow-hidden",children:[f&&e.jsx("div",{className:"absolute top-0 left-0 h-1 bg-gradient-to-r from-primary to-green-500 transition-all duration-500",style:{width:`${f.progress||0}%`}}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[x?e.jsx("span",{className:"material-symbols-outlined text-[18px] text-primary animate-spin",children:"autorenew"}):(f==null?void 0:f.status)==="stopped"?e.jsx("span",{className:"material-symbols-outlined text-[18px] text-red-400",children:"cancel"}):e.jsx("span",{className:"material-symbols-outlined text-[18px] text-green-400",children:"check_circle"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-text-main",children:x?"Job Running":(f==null?void 0:f.status)==="stopped"?"Job Stopped":"Job Completed"}),f&&e.jsxs("p",{className:"text-[11px] text-text-muted mt-0.5",children:["Progress: ",f.completed,"/",f.count," ·",e.jsxs("span",{className:"text-green-400 ml-1",children:["✓ ",f.success]}),e.jsxs("span",{className:"text-red-400 ml-1",children:["✗ ",f.failed]})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[!x&&N.length>0&&e.jsx(m,{variant:"ghost",size:"sm",onClick:async()=>{Se.current=!0,N.forEach(t=>$.current.add(t.email.toLowerCase())),I([]),te(null);try{await fetch("/api/automation/codebuddy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"clear-logs"})})}catch{}},children:"Clear"}),x&&e.jsx(m,{variant:"danger",size:"sm",onClick:E,children:"■ Stop"})]})]}),e.jsx("div",{className:"max-h-96 overflow-y-auto overflow-x-auto rounded-lg bg-black/40 border border-border/40 text-[11px] font-mono",children:e.jsxs("table",{className:"w-full min-w-[540px]",children:[e.jsx("thead",{className:"sticky top-0 bg-black/80 backdrop-blur-sm",children:e.jsxs("tr",{className:"text-text-muted text-left",children:[e.jsx("th",{className:"px-2 py-1 w-6",children:"#"}),e.jsx("th",{className:"px-2 py-1",children:"Email"}),e.jsx("th",{className:"px-2 py-1 w-16",children:"Status"}),e.jsx("th",{className:"px-2 py-1",children:"Step"}),e.jsx("th",{className:"px-2 py-1 w-14 text-right",children:"Time"}),e.jsx("th",{className:"px-2 py-1 w-12 text-right",children:"Actions"})]})}),e.jsx("tbody",{children:N.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-2 py-2 text-center text-text-muted",children:"Waiting for log entries..."})}):Ke.map((t,a)=>{var c;const n=(c=t.step)==null?void 0:c.match(/\[([^\]]+s)\]$/),l=n?t.step.replace(n[0],"").trim():t.step,b=n?n[1]:"--";return e.jsxs("tr",{className:`border-t border-border/20 ${t.status==="failed"?"bg-red-500/5":t.status==="done"?"bg-green-500/5":""}`,children:[e.jsx("td",{className:"px-2 py-1 text-text-muted",children:t.idx+1}),e.jsx("td",{className:"px-2 py-1 text-text-main truncate max-w-[160px]",title:t.email,children:t.email}),e.jsxs("td",{className:"px-2 py-1 whitespace-nowrap",children:[t.status==="running"&&e.jsx("span",{className:"text-blue-400",children:"● run"}),t.status==="done"&&e.jsx("span",{className:"text-green-400",children:"✓ ok"}),t.status==="failed"&&e.jsx("span",{className:"text-red-400",children:"✗ fail"}),t.status==="pending"&&e.jsx("span",{className:"text-text-muted",children:"◌"})]}),e.jsx("td",{className:"px-2 py-1 text-text-muted truncate max-w-[280px]",title:t.status==="done"?t.balance!==void 0?`Success · ${t.balance} tokens${t.left_team===!0?" · Left team ✓":t.left_team===!1?" · Left team ✗":""}`:"Success":l,children:t.status==="done"?e.jsxs("span",{className:"text-green-400 font-medium",children:[t.balance!==void 0?`Success · ${t.balance} tokens`:"Success",t.left_team===!0&&e.jsx("span",{className:"text-purple-400 ml-1",children:"· Left team ✓"}),t.left_team===!1&&e.jsx("span",{className:"text-yellow-400 ml-1",children:"· Left team ✗"})]}):l}),e.jsx("td",{className:"px-2 py-1 text-right text-[10px] text-text-muted font-mono",children:b}),e.jsx("td",{className:"px-2 py-1 text-right whitespace-nowrap",children:t.status==="failed"&&e.jsx("button",{onClick:()=>{const p=h.find(ke=>ke.email.toLowerCase()===t.email.toLowerCase());p?ve(p.id):alert("Account tidak ditemukan.")},disabled:!!x,className:`text-[9px] font-bold px-1.5 py-0.5 rounded cursor-pointer transition-colors ${x?"text-text-muted bg-surface-3 cursor-not-allowed opacity-50":"text-brand-400 hover:text-brand-300 hover:bg-brand-500/15 bg-brand-500/5"}`,children:"Retry"})})]},a)})})]})}),Y>1&&e.jsxs("div",{className:"flex items-center justify-between gap-4 pt-2",children:[e.jsx(m,{variant:"secondary",size:"sm",onClick:()=>ue(t=>Math.max(1,t-1)),disabled:q===1,children:"Previous"}),e.jsxs("span",{className:"text-xs text-text-muted",children:["Page ",q," of ",Y," · (",N.length," items)"]}),e.jsx(m,{variant:"secondary",size:"sm",onClick:()=>ue(t=>Math.min(Y,t+1)),disabled:q===Y,children:"Next"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("h2",{className:"text-sm font-bold text-text-main flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"group"}),"Accounts"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-text-muted",children:[h.filter(t=>t.provider===i).length," total"]}),e.jsxs(qe,{variant:"success",size:"sm",children:[h.filter(t=>t.provider===i&&t.api_key_status==="ready").length," ready"]})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("input",{type:"text",placeholder:"Search email...",value:y,onChange:t=>Ve(t.target.value),className:"text-xs p-2 rounded-lg border border-border-subtle bg-surface focus:outline-none focus:border-primary w-48"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("label",{className:"text-xs text-text-main flex items-center gap-1",children:["Limit:",e.jsx("input",{type:"number",min:1,max:20,value:K,onChange:t=>Ce(parseInt(t.target.value)||3),className:"w-12 text-center p-1 rounded border border-border-subtle bg-surface"})]}),e.jsx(m,{variant:"primary",size:"sm",onClick:Ie,disabled:!!x,children:"Run All Pending"}),e.jsx(m,{variant:"secondary",size:"sm",onClick:s,children:"⚡ Add All Ready → fsrouter"}),e.jsx(m,{variant:"danger",size:"sm",onClick:()=>v(["pending","failed"]),children:"🗑 Delete Pending/Failed"})]})]}),T.size>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-xs",children:[e.jsxs("span",{className:"text-primary font-semibold",children:[T.size," selected"]}),e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsx("button",{onClick:async()=>{const t=[...T];J(new Set),await Promise.all(t.map(a=>ve(a)))},disabled:!!x,className:"text-brand-400 hover:text-brand-300 font-semibold disabled:opacity-40 disabled:cursor-not-allowed",children:"▶ Run Selected"}),e.jsx("span",{className:"text-text-muted",children:"·"}),e.jsx("button",{onClick:()=>v(null,[...T]),className:"text-red-400 hover:text-red-300 font-semibold",children:"🗑 Delete Selected"}),e.jsx("button",{onClick:()=>J(new Set),className:"ml-auto text-text-muted hover:text-text-main",children:"✕ Clear"})]}),e.jsx("div",{className:"rounded-xl border border-border-subtle bg-surface-2 overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs text-left border-collapse min-w-[640px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-surface text-text-muted border-b border-border-subtle font-semibold",children:[e.jsx("th",{className:"p-2.5 w-8",children:e.jsx("input",{type:"checkbox",className:"rounded cursor-pointer accent-primary",checked:H.length>0&&H.every(t=>T.has(t.id)),onChange:t=>{t.target.checked?J(a=>new Set([...a,...H.map(n=>n.id)])):J(a=>{const n=new Set(a);return H.forEach(l=>n.delete(l.id)),n})}})}),e.jsx("th",{className:"p-2.5 w-10",children:"#"}),e.jsx("th",{className:"p-2.5",children:"Email"}),e.jsx("th",{className:"p-2.5 w-24",children:"Status"}),e.jsx("th",{className:"p-2.5",children:"API Key"}),e.jsx("th",{className:"p-2.5 text-right",children:"Actions"})]})}),e.jsxs("tbody",{children:[H.map(t=>e.jsxs("tr",{className:`border-b border-border-subtle transition-colors ${T.has(t.id)?"bg-primary/5":"hover:bg-surface/50"}`,children:[e.jsx("td",{className:"p-2.5",children:e.jsx("input",{type:"checkbox",className:"rounded cursor-pointer accent-primary",checked:T.has(t.id),onChange:a=>{J(n=>{const l=new Set(n);return a.target.checked?l.add(t.id):l.delete(t.id),l})}})}),e.jsxs("td",{className:"p-2.5 font-mono text-text-muted",children:["#",t.id]}),e.jsx("td",{className:"p-2.5 font-semibold text-text-main truncate max-w-[100px] sm:max-w-[140px] sm:max-w-[200px]",title:t.email,children:t.email}),e.jsxs("td",{className:"p-2.5",children:[e.jsx(qe,{variant:t.api_key_status==="ready"?"success":t.api_key_status==="failed"?"danger":t.api_key_status==="running"?"primary":"default",size:"sm",children:t.api_key_status}),t.last_error&&e.jsxs("p",{className:"text-[10px] text-red-500 mt-0.5 truncate max-w-[150px]",title:t.last_error,children:["⚠ ",t.last_error]})]}),e.jsx("td",{className:"p-2.5",children:t.api_key?e.jsx("code",{className:"bg-surface px-1.5 py-0.5 rounded font-mono text-[10px] text-text-main max-w-[100px] sm:max-w-[140px] block truncate",title:t.api_key,children:t.api_key}):e.jsx("span",{className:"text-text-muted",children:"—"})}),e.jsx("td",{className:"p-2.5 text-right whitespace-nowrap",children:e.jsxs("div",{className:"inline-flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>ve(t.id),disabled:!!x||t.api_key_status==="running",className:`inline-flex items-center gap-0.5 text-[11px] font-bold transition-all cursor-pointer ${x||t.api_key_status==="running"?"text-text-muted cursor-not-allowed opacity-40":"text-brand-400 hover:text-brand-300 hover:underline"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"play_arrow"}),"Process"]}),t.api_key_status==="ready"&&t.api_key&&e.jsxs("button",{onClick:()=>Ne(t.id),className:"inline-flex items-center gap-0.5 text-[11px] font-bold text-green-400 hover:text-green-300 hover:underline transition-all cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"add_link"}),"+fsrouter"]}),e.jsxs("button",{onClick:()=>o(t.id),className:"inline-flex items-center gap-0.5 text-[11px] font-bold text-red-400 hover:text-red-300 hover:underline transition-all cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"delete"}),"Delete"]})]})})]},t.id)),H.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"p-6 text-center text-text-muted",children:"No accounts found. Add manual accounts to get started."})})]})]})}),me>1&&e.jsxs("div",{className:"flex items-center justify-between gap-4 pt-2",children:[e.jsx(m,{variant:"secondary",size:"sm",onClick:()=>De(t=>Math.max(1,t-1)),disabled:xe===1,children:"Previous"}),e.jsxs("span",{className:"text-xs text-text-muted",children:["Page ",xe," of ",me]}),e.jsx(m,{variant:"secondary",size:"sm",onClick:()=>De(t=>Math.min(me,t+1)),disabled:xe===me,children:"Next"})]})]})]})]}),O&&e.jsxs(Ye,{padding:"md",className:"space-y-3 border border-brand-500/20 bg-brand-500/5 mt-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h2",{className:"text-xs font-bold text-brand-400 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"bug_report"}),"🖥️ Live Browser Preview"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!_&&e.jsx("span",{className:"text-[10px] text-text-muted",children:x?"Starting...":"Run a job to see the browser"}),_&&e.jsxs("span",{className:"text-[10px] text-green-400 flex items-center gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-400 animate-pulse"}),"Live · ~2fps"]})]})]}),e.jsx("div",{className:"relative rounded-lg overflow-hidden border border-border-subtle bg-black",style:{aspectRatio:"16/10"},children:_?e.jsx("img",{src:`/api/automation/codebuddy/debug-vnc?action=screenshot&t=${D}`,alt:"Browser preview",className:"w-full h-full object-contain",style:{minHeight:"400px",imageRendering:"auto"},onLoad:()=>{O&&x&&setTimeout(()=>B(Date.now()),400)},onError:()=>{setTimeout(()=>B(Date.now()),2e3)}},"debug-screenshot"):e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[32px] text-text-muted",children:"desktop_windows"}),e.jsx("p",{className:"text-xs text-text-muted",children:x?"Starting browser preview...":"Run a job with Debug Mode to see live browser"})]})})})]}),ze&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>W(!1),children:e.jsxs("div",{className:"bg-surface border border-border-subtle rounded-2xl shadow-2xl w-full max-w-lg mx-4 max-h-[90vh] overflow-hidden",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"p-5 border-b border-border-subtle",children:[e.jsxs("h3",{className:"text-base font-bold text-text-main flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:"dns"}),"Edit Proxy Pool"]}),e.jsx("p",{className:"text-xs text-text-muted mt-1",children:"Enter one proxy per line. A random proxy will be selected for each automation run."})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsx("textarea",{value:ge,onChange:t=>le(t.target.value),placeholder:`socks5://user:pass@host:port
4
+ http://host:port
5
+ host:port:user:pass
6
+ host:port`,rows:10,className:"w-full text-xs p-3 rounded-xl border border-border-subtle bg-surface-2 focus:outline-none focus:border-primary text-text-main font-mono resize-none",spellCheck:!1}),e.jsxs("div",{className:"text-[10px] text-text-muted bg-surface-2 rounded-lg p-3 space-y-1",children:[e.jsx("div",{className:"font-semibold text-text-main mb-1",children:"Supported formats:"}),e.jsx("div",{children:e.jsx("code",{className:"text-primary",children:"socks5://user:pass@host:port"})}),e.jsx("div",{children:e.jsx("code",{className:"text-primary",children:"http://user:pass@host:port"})}),e.jsx("div",{children:e.jsx("code",{className:"text-primary",children:"socks5://host:port"})}),e.jsx("div",{children:e.jsx("code",{className:"text-primary",children:"http://host:port"})}),e.jsx("div",{children:e.jsx("code",{className:"text-primary",children:"host:port:user:pass"})}),e.jsx("div",{children:e.jsx("code",{className:"text-primary",children:"host:port"})})]})]}),e.jsxs("div",{className:"p-5 border-t border-border-subtle flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-xs text-text-muted",children:[ge.split(`
7
+ `).filter(t=>t.trim()).length," proxies"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>W(!1),className:"px-4 py-2 text-xs rounded-lg border border-border-subtle text-text-muted hover:text-text-main transition-colors",children:"Cancel"}),e.jsx("button",{onClick:async()=>{const t=ge.split(`
8
+ `).map(a=>a.trim()).filter(Boolean);V(t),W(!1);try{await fetch("/api/automation/codebuddy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"settings",proxy_enabled:!0,proxy_pool:JSON.stringify(t)})})}catch{}},className:"px-4 py-2 text-xs rounded-lg bg-primary text-white font-medium hover:opacity-90 transition-opacity",children:"Save Proxies"})]})]})]})})]})}function tt(u){if(!u)return"";const h=`
9
+ <style id="router-injected-styles">
10
+ html, body {
11
+ overflow-x: auto !important;
12
+ overflow-y: auto !important;
13
+ margin: 0 !important;
14
+ padding: 12px !important;
15
+ background-color: #ffffff !important;
16
+ color: #000000 !important;
17
+ }
18
+ img {
19
+ max-width: 100% !important;
20
+ height: auto !important;
21
+ }
22
+ </style>
23
+ `;return u.includes("<head>")?u.replace("<head>",`<head>${h}`):u.includes("<HEAD>")?u.replace("<HEAD>",`<HEAD>${h}`):u.includes("<body>")?u.replace("<body>",`<body>${h}`):u.includes("<BODY>")?u.replace("<BODY>",`<BODY>${h}`):h+u}function st(){const[u,h]=r.useState(!1),[X,x]=r.useState(!1),[ee,f]=r.useState(!0),[te,N]=r.useState(!1),[I,$]=r.useState(""),[se,ue]=r.useState([]),[ae,pe]=r.useState([]),[Se,g]=r.useState(null),[Ue,K]=r.useState(""),[Ce,$e]=r.useState([]),[re,ne]=r.useState(1),[he,A]=r.useState(!1),[Re,_e]=r.useState(!1),[j,i]=r.useState(!1),[R,G]=r.useState(""),[be,O]=r.useState(""),[U,Te]=r.useState(""),[We,oe]=r.useState(""),[fe,k]=r.useState("manual"),[V,ze]=r.useState(""),[W,ge]=r.useState(""),[le,Be]=r.useState(""),[Ae,Fe]=r.useState(""),[S,Le]=r.useState(""),[Q,z]=r.useState({}),[L,C]=r.useState(null),Pe=r.useRef(!1);r.useEffect(()=>{Pe.current=he,he||C(null)},[he]);const[_,Z]=r.useState("all"),[D,B]=r.useState(""),[F,je]=r.useState(null),[d,ie]=r.useState(null),[T,J]=r.useState("html"),[M,Je]=r.useState(""),[ye,Oe]=r.useState(!1),[we,He]=r.useState(""),[ce,de]=r.useState(""),y=async()=>{var s,o,v,P,me,H,Y,q,Ke;try{const t=await fetch("/api/automation/fsmail"),a=await t.json();if(t.ok){x(a.configured),N(a.connection_ok),$(a.connection_error),ue(a.domains||[]);const n=a.inboxes||[];pe(n),B(l=>l&&n.some(c=>c.address.toLowerCase()===l.toLowerCase())?l:n.length>0?n[0].address:""),g(a.webhook),K(a.webhook_url),$e(a.otps||[]),Pe.current||(G(((s=a.settings)==null?void 0:s.base_url)||""),O(((o=a.settings)==null?void 0:o.api_key)||""),Te(((v=a.settings)==null?void 0:v.default_domain)||""),oe(((P=a.settings)==null?void 0:P.webhook_secret)||""),ze(((me=a.settings)==null?void 0:me.cf_account_id)||""),ge(((H=a.settings)==null?void 0:H.cf_api_token)||""),Be(((Y=a.settings)==null?void 0:Y.cf_domain)||""),Fe(((q=a.settings)==null?void 0:q.cf_telegram_bot_token)||""),Le(((Ke=a.settings)==null?void 0:Ke.cf_workers_dev_url)||""))}}catch(t){console.error(t)}finally{f(!1)}};r.useEffect(()=>{y();const s=setInterval(y,5e3);return()=>clearInterval(s)},[]);const Ve=async()=>{try{(await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"settings",base_url:R,api_key:be,default_domain:U,webhook_secret:We,cf_account_id:V,cf_api_token:W,cf_domain:le,cf_telegram_bot_token:Ae,cf_workers_dev_url:S})})).ok&&(A(!1),y())}catch(s){alert(`Save failed: ${s.message}`)}},xe=async()=>{h(!0),C(null);try{const s=await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"test-connection",base_url:R,api_key:be})}),o=await s.json();s.ok?(C({ok:!0,message:"Koneksi ke worker berhasil!"}),y()):C({ok:!1,message:`Koneksi gagal: ${o.error}`})}catch(s){C({ok:!1,message:`Error: ${s.message}`})}finally{h(!1)}},De=async()=>{if(!V||!W||!le){alert("Account ID, API Token, dan Domain wajib diisi!");return}h(!0),C(null);try{const s=await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"auto-deploy",cf_account_id:V,cf_api_token:W,cf_domain:le,telegram_bot_token:Ae})}),o=await s.json();s.ok?(C({ok:!0,message:"Sukses! Worker telah di-deploy ke Cloudflare dan siap digunakan."}),G(o.base_url||""),O(o.api_key||""),Te(o.default_domain||""),oe(o.webhook_secret||""),Le(o.cf_workers_dev_url||""),y()):C({ok:!1,message:`Deploy gagal: ${o.error}`})}catch(s){C({ok:!1,message:`Error: ${s.message}`})}finally{h(!1)}},Me=async()=>{try{const s=await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"webhook-register"})}),o=await s.json();s.ok?(alert("Webhook registered successfully!"),y()):alert(`Failed: ${o.error}`)}catch(s){alert(`Error: ${s.message}`)}},w=async s=>{s.preventDefault();try{const o=await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"inbox-create",alias:we,domain:ce})}),v=await o.json();if(o.ok){i(!1);const P=`${we}@${ce}`.toLowerCase();B(P),He(""),de(""),y()}else alert(v.error)}catch(o){alert(o.message)}},Qe=async s=>{if(confirm(`Hapus inbox ${s}?`))try{(await fetch("/api/automation/fsmail",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"inbox-delete",alias:s})})).ok&&(D&&D.split("@")[0]===s&&B(""),d&&d.alias===s&&(je(null),ie(null)),y())}catch(o){console.error(o)}},Ze=async s=>{je(s),ie(null),ne(1);try{const o=await fetch(`/api/automation/fsmail/otps/${s}`),v=await o.json();o.ok&&(ie(v.otp),y())}catch(o){console.error(o)}},Ee=async(s,o)=>{if(s.stopPropagation(),!!confirm("Delete this email?"))try{await fetch(`/api/automation/fsmail/otps/${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"delete"})}),F===o&&(je(null),ie(null)),y()}catch(v){console.error(v)}},Ie=s=>{navigator.clipboard.writeText(s),z(o=>({...o,[s]:!0})),setTimeout(()=>{z(o=>({...o,[s]:!1}))},1500)},E=({value:s,text:o="Copy",className:v=""})=>{const P=Q[s];return e.jsxs("button",{type:"button",onClick:()=>Ie(s),className:`text-[10px] px-2 py-1 rounded cursor-pointer transition-all duration-150 flex items-center gap-1 border font-semibold ${P?"text-green-400 bg-green-500/10 border-green-500/20":"text-white/50 hover:text-white bg-white/5 hover:bg-white/10 border-transparent"} ${v}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:P?"check":"content_copy"}),P?"Copied":o]})},ve=Ce.filter(s=>{if(!D||s.address.toLowerCase()!==D.toLowerCase()||_==="unread"&&s.used_at||_==="read"&&!s.used_at||_==="otp"&&!s.otp_code)return!1;if(M){const o=M.toLowerCase();return s.sender.toLowerCase().includes(o)||s.subject.toLowerCase().includes(o)||s.otp_code&&s.otp_code.includes(o)}return!0}),Ne=s=>Ce.filter(o=>!(!D||o.address.toLowerCase()!==D.toLowerCase()||s==="unread"&&o.used_at||s==="read"&&!o.used_at||s==="otp"&&!o.otp_code)).length;return e.jsxs("div",{className:"border border-border-subtle rounded-2xl overflow-hidden bg-vibrancy backdrop-blur-xl flex flex-col h-[calc(100vh-210px)] min-h-[500px] shadow-[var(--shadow-warm)]",children:[ee?e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-8 text-center space-y-3",children:e.jsx(Xe,{size:"lg",label:"Memuat setelan Temp Mail..."})}):X?e.jsxs("div",{className:"flex-1 flex divide-x divide-border-subtle min-h-0",children:[e.jsxs("aside",{className:"w-60 shrink-0 bg-surface/40 flex flex-col min-h-0",children:[e.jsxs("div",{className:"p-4 border-b border-border-subtle flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-xs font-bold text-text-main flex items-center gap-1.5",title:!te&&I?I:void 0,children:[e.jsx("span",{className:`inline-block size-2 rounded-full ${te?"bg-green-500":"bg-red-500 animate-ping"}`}),te?"Connected":"Disconnected"]}),e.jsx("button",{onClick:()=>A(!0),className:"text-text-muted hover:text-text-main cursor-pointer",title:"Settings",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"settings"})})]}),!te&&I&&e.jsxs("div",{className:"px-4 py-2.5 bg-red-500/10 border-b border-red-500/20 text-[10px] text-red-400 break-all space-y-1",children:[e.jsxs("div",{className:"font-semibold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"error"}),"Koneksi Gagal:"]}),e.jsx("div",{className:"opacity-80",children:I}),S&&R!==S&&e.jsx("button",{onClick:()=>{G(S),A(!0),k("manual")},className:"text-primary hover:underline text-[9px] font-semibold block mt-1 text-left",children:"💡 Gunakan domain workers.dev fallback"})]}),e.jsx("div",{className:"p-4",children:e.jsx(m,{variant:"primary",size:"sm",fullWidth:!0,onClick:()=>{de(U||(se.length>0?se[0]:"")),i(!0)},children:"+ New Inbox"})}),e.jsxs("nav",{className:"flex flex-col px-2 space-y-0.5",children:[e.jsxs("button",{onClick:()=>{Z("all")},className:`flex items-center justify-between px-3 py-1.5 rounded-lg text-xs font-semibold cursor-pointer ${_==="all"?"bg-primary/10 text-primary":"text-text-muted hover:bg-surface"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"size-4 opacity-80",children:[e.jsx("polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12"}),e.jsx("path",{d:"M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"})]}),"Inbox"]}),e.jsx("span",{className:"bg-surface-3 px-1.5 py-0.5 rounded-full text-[10px] text-text-muted",children:Ne("all")})]}),e.jsxs("button",{onClick:()=>Z("unread"),className:`flex items-center justify-between px-3 py-1.5 rounded-lg text-xs font-semibold cursor-pointer ${_==="unread"?"bg-primary/10 text-primary":"text-text-muted hover:bg-surface"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"size-4 opacity-80",children:[e.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),e.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),"Unread"]}),e.jsx("span",{className:"bg-surface-3 px-1.5 py-0.5 rounded-full text-[10px] text-text-muted",children:Ne("unread")})]}),e.jsxs("button",{onClick:()=>Z("read"),className:`flex items-center justify-between px-3 py-1.5 rounded-lg text-xs font-semibold cursor-pointer ${_==="read"?"bg-primary/10 text-primary":"text-text-muted hover:bg-surface"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"size-4 opacity-80",children:[e.jsx("path",{d:"M2 17V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2Z"}),e.jsx("path",{d:"M2 7l10 7 10-7"})]}),"Read"]}),e.jsx("span",{className:"bg-surface-3 px-1.5 py-0.5 rounded-full text-[10px] text-text-muted",children:Ne("read")})]}),e.jsxs("button",{onClick:()=>Z("otp"),className:`flex items-center justify-between px-3 py-1.5 rounded-lg text-xs font-semibold cursor-pointer ${_==="otp"?"bg-primary/10 text-primary":"text-text-muted hover:bg-surface"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"size-4 opacity-80",children:e.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})}),"With OTP"]}),e.jsx("span",{className:"bg-surface-3 px-1.5 py-0.5 rounded-full text-[10px] text-text-muted",children:Ne("otp")})]})]}),e.jsx("div",{className:"px-4 py-3 border-t border-b border-border-subtle/45 mt-4 bg-surface/10",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",placeholder:"Search inboxes...",value:M,onChange:s=>Je(s.target.value),className:"w-full text-xs pl-8 pr-3 py-1.5 rounded-lg border border-border-subtle bg-surface focus:outline-none focus:border-primary text-text-main"}),e.jsx("span",{className:"absolute left-2.5 top-2.5 text-text-muted/60",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"size-3.5",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto custom-scrollbar px-2 pt-4",children:e.jsxs("div",{children:[e.jsxs("p",{className:"px-3 text-[10px] font-semibold text-text-muted uppercase tracking-wider mb-2",children:["Active Inboxes (",ae.length,")"]}),e.jsxs("div",{className:"space-y-0.5",children:[ae.filter(s=>s.address.toLowerCase().includes(M.toLowerCase())).map(s=>e.jsxs("div",{onClick:()=>{B(s.address),Z("all")},className:`group/inbox flex items-center justify-between px-3 py-2 rounded-lg text-xs font-medium cursor-pointer transition-colors ${D.toLowerCase()===s.address.toLowerCase()?"bg-primary/10 text-primary":"text-text-muted hover:bg-surface"}`,children:[e.jsx("span",{className:"truncate w-32",title:s.address,children:s.address}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-1",children:[e.jsx("button",{onClick:o=>{o.stopPropagation(),Ie(s.address)},className:`size-6 flex items-center justify-center rounded-md transition-all duration-150 ${Q[s.address]?"text-green-400 bg-green-500/15":"text-text-muted hover:text-primary hover:bg-primary/15"}`,title:"Copy address",children:Q[s.address]?e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"size-3.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"size-3.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),e.jsx("button",{onClick:o=>{o.stopPropagation(),Qe(s.alias)},className:"size-6 flex items-center justify-center rounded-md text-text-muted hover:text-red-400 hover:bg-red-500/15 transition-all duration-150",title:"Delete inbox",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"size-3.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},s.address)),ae.length===0&&e.jsx("p",{className:"px-3 text-[11px] text-text-muted italic",children:"No inboxes. Click New Inbox above."})]})]})})]}),e.jsxs("section",{className:"w-80 shrink-0 flex flex-col min-h-0 bg-surface/10",children:[e.jsxs("div",{className:"p-3 border-b border-border-subtle flex items-center justify-between gap-2 bg-surface/10",children:[e.jsx("span",{className:"text-xs font-bold text-text-muted uppercase tracking-wider pl-1",children:"Messages"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>{Oe(!0),y().finally(()=>Oe(!1))},className:`p-1.5 hover:bg-surface rounded-lg cursor-pointer text-text-muted transition-colors duration-150 ${ye?"animate-spin":""}`,title:"Refresh",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"size-4",children:[e.jsx("path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),e.jsx("path",{d:"M3 3v5h5"}),e.jsx("path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"}),e.jsx("path",{d:"M16 16h5v5"})]})}),e.jsx("button",{onClick:s=>{F&&Ee(s,F)},disabled:!F,className:`p-1.5 rounded-lg cursor-pointer transition-colors duration-150 ${F?"text-red-500 hover:bg-red-500/10":"text-text-muted/30 cursor-not-allowed"}`,title:"Delete selected email",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"size-4",children:[e.jsx("path",{d:"M3 6h18"}),e.jsx("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),e.jsx("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"}),e.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),e.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto custom-scrollbar p-2 space-y-1.5",children:D?ve.length===0?e.jsx("div",{className:"text-center p-8 text-text-muted text-xs italic",children:"No messages found."}):ve.map(s=>e.jsxs("div",{onClick:()=>Ze(s.id),className:`group p-3 rounded-xl border border-border-subtle cursor-pointer transition-colors relative flex flex-col gap-1 ${F===s.id?"bg-primary/10 border-primary":s.used_at?"bg-surface/40 hover:bg-surface":"bg-surface font-semibold shadow-[var(--shadow-soft)] hover:bg-surface/80"}`,children:[e.jsxs("div",{className:"flex justify-between items-baseline gap-2",children:[e.jsx("span",{className:"text-xs text-text-main truncate w-36",children:s.sender}),e.jsx("span",{className:"text-[9px] text-text-muted shrink-0",children:new Date(s.received_at*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]}),e.jsx("h4",{className:"text-xs text-text-main truncate",children:s.subject}),s.otp_code&&e.jsx("div",{className:"mt-1",children:e.jsxs("span",{className:"bg-amber-500/10 text-amber-500 border border-amber-500/20 px-1.5 py-0.5 rounded font-mono text-[10px] font-bold tracking-wider",children:["🔑 ",s.otp_code]})}),e.jsx("button",{onClick:o=>Ee(o,s.id),className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 text-text-muted hover:text-red-500 transition-all p-1 hover:bg-red-500/10 rounded cursor-pointer",title:"Delete email",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"size-3.5",children:[e.jsx("path",{d:"M3 6h18"}),e.jsx("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),e.jsx("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})})]},s.id)):e.jsx("div",{className:"text-center p-8 text-text-muted text-xs italic",children:"Select an inbox to view messages."})})]}),e.jsx("article",{className:"flex-1 flex flex-col min-h-0 bg-surface/5",children:F===null?e.jsx("div",{className:"flex-1 flex items-center justify-center text-text-muted text-xs italic",children:"Select an email to read its contents."}):d===null?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-text-muted text-xs",children:[e.jsx("span",{className:"animate-spin mr-2",children:"⏳"})," Loading email details..."]}):e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:"p-6 border-b border-border-subtle space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-start gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-text-main",children:d.subject}),e.jsxs("p",{className:"text-xs text-text-muted mt-1",children:["From: ",e.jsx("span",{className:"font-semibold text-text-main",children:d.sender})]}),e.jsxs("p",{className:"text-xs text-text-muted",children:["To: ",e.jsx("span",{className:"font-semibold text-text-main",children:d.address})]})]}),e.jsxs("div",{className:"text-right flex flex-col items-end gap-2 shrink-0",children:[e.jsx("span",{className:"text-[11px] text-text-muted",children:new Date(d.received_at*1e3).toLocaleString()}),e.jsxs("button",{onClick:s=>Ee(s,d.id),className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-[11px] font-bold rounded-lg border bg-red-500/10 text-red-400 hover:bg-red-500/20 border-red-500/20 transition-all active:scale-95 cursor-pointer mt-1",title:"Delete this email",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"size-3",children:[e.jsx("path",{d:"M3 6h18"}),e.jsx("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),e.jsx("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete Email"]})]})]}),d.otp_code&&e.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/25 rounded-xl p-4 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-amber-500 uppercase tracking-widest font-bold",children:"Verification OTP"}),e.jsx("p",{className:"text-2xl font-black font-mono tracking-widest text-text-main mt-1",children:d.otp_code})]}),e.jsx(m,{variant:Q[d.otp_code]?"success":"secondary",size:"sm",onClick:()=>Ie(d.otp_code),children:Q[d.otp_code]?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"check"}),"Copied!"]}):"Copy Code"})]}),d.verify_url&&e.jsxs("div",{className:"bg-primary/10 border border-primary/20 rounded-xl p-3 flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{className:"truncate flex-1 text-text-main",title:d.verify_url,children:["🔗 ",d.verify_url]}),e.jsx("a",{href:d.verify_url,target:"_blank",rel:"noreferrer",className:"bg-primary hover:bg-primary/95 text-white px-3 py-1.5 rounded-lg font-semibold shrink-0",children:"Open Link"})]})]}),e.jsxs("div",{className:"flex justify-between items-center border-b border-border-subtle bg-surface/20 px-6 shrink-0",children:[e.jsxs("div",{className:"flex",children:[d.body_html&&e.jsx("button",{onClick:()=>J("html"),className:`px-4 py-2.5 text-xs font-semibold border-b-2 cursor-pointer ${T==="html"?"border-primary text-primary":"border-transparent text-text-muted"}`,children:"HTML View"}),e.jsx("button",{onClick:()=>J("text"),className:`px-4 py-2.5 text-xs font-semibold border-b-2 cursor-pointer ${T==="text"||!d.body_html?"border-primary text-primary":"border-transparent text-text-muted"}`,children:"Plain Text"})]}),T==="html"&&d.body_html&&e.jsxs("div",{className:"flex items-center gap-2 py-1.5 text-xs text-text-muted select-none",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-white/40",children:"zoom_in"}),e.jsx("button",{onClick:()=>ne(s=>Math.max(.4,s-.1)),className:"px-2 py-0.5 rounded bg-white/5 hover:bg-white/10 border border-white/10 active:bg-white/20 transition-colors text-[10px] font-bold cursor-pointer text-white",title:"Zoom Out",children:"A-"}),e.jsxs("span",{className:"font-mono text-[10px] w-10 text-center text-white/80",children:[Math.round(re*100),"%"]}),e.jsx("button",{onClick:()=>ne(s=>Math.min(1.5,s+.1)),className:"px-2 py-0.5 rounded bg-white/5 hover:bg-white/10 border border-white/10 active:bg-white/20 transition-colors text-[10px] font-bold cursor-pointer text-white",title:"Zoom In",children:"A+"}),e.jsx("button",{onClick:()=>ne(1),className:"px-2 py-0.5 rounded bg-white/5 hover:bg-white/10 border border-white/10 active:bg-white/20 transition-colors text-[10px] font-semibold cursor-pointer text-white ml-1",children:"Reset"})]})]}),e.jsx("div",{className:"flex-1 overflow-auto custom-scrollbar p-6 relative min-h-[450px]",children:T==="html"&&d.body_html?e.jsx("div",{className:"w-full h-full relative overflow-auto custom-scrollbar",children:e.jsx("iframe",{srcDoc:tt(d.body_html),title:"Email Preview",sandbox:"allow-popups allow-popups-to-escape-sandbox",style:{transform:`scale(${re})`,transformOrigin:"top left",width:`${100/re}%`,height:`${100/re}%`},className:"border border-border-subtle rounded-xl bg-white absolute inset-0"})}):e.jsx("pre",{className:"text-xs font-sans whitespace-pre-wrap leading-relaxed text-text-main",children:d.body_text})})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 text-center space-y-4",children:[e.jsx("div",{className:"size-16 rounded-full bg-primary/10 text-primary flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"mail_lock"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-text-main",children:"FSMail Client Not Configured"}),e.jsx("p",{className:"text-xs text-text-muted mt-1 max-w-sm",children:"Please enter your FSMail Cloudflare worker credentials and endpoint in settings to enable temp emails."})]}),e.jsx(m,{variant:"primary",onClick:()=>A(!0),children:"⚙ Configure Settings"})]}),he&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/60 backdrop-blur-sm p-4 pt-[6vh] overflow-y-auto",children:e.jsxs("div",{className:"bg-neutral-900 border border-white/10 rounded-2xl w-full max-w-md text-white max-h-[80vh] flex flex-col overflow-hidden shadow-2xl",children:[e.jsxs("div",{className:"flex justify-between items-center p-5 border-b border-white/5 shrink-0",children:[e.jsx("h3",{className:"text-base font-bold",children:"FSMail Settings"}),e.jsx("button",{onClick:()=>A(!1),className:"text-white/60 hover:text-white cursor-pointer flex items-center",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsxs("div",{className:"p-5 overflow-y-auto custom-scrollbar flex-1 space-y-4",children:[e.jsxs("div",{className:"flex border border-white/10 rounded-lg p-0.5 bg-white/5 text-xs shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>k("manual"),className:`flex-1 py-1.5 rounded-md font-semibold cursor-pointer text-center transition-all ${fe==="manual"?"bg-primary text-white":"text-white/60 hover:text-white"}`,children:"Manual Input"}),e.jsx("button",{type:"button",onClick:()=>k("auto"),className:`flex-1 py-1.5 rounded-md font-semibold cursor-pointer text-center transition-all ${fe==="auto"?"bg-primary text-white":"text-white/60 hover:text-white"}`,children:"⚡ Auto Deploy (Cloudflare)"})]}),fe==="manual"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-white/60 block mb-1",children:"Base URL Worker"}),e.jsx("input",{type:"text",placeholder:"https://mail.yourdomain.com",value:R,onChange:s=>G(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"}),S&&R!==S&&e.jsxs("div",{className:"mt-1.5 p-2 bg-primary/10 border border-primary/20 rounded-lg text-[10px] text-primary space-y-1 text-left",children:[e.jsx("div",{children:"💡 Coba gunakan URL workers.dev fallback:"}),e.jsx("div",{className:"font-mono text-[9px] break-all bg-black/40 p-1 rounded select-all",children:S}),e.jsx("button",{type:"button",onClick:()=>G(S),className:"underline hover:no-underline font-semibold block",children:"Klik untuk gunakan URL ini"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-white/60 block mb-1",children:"API Key (X-API-Key)"}),e.jsx("input",{type:"password",placeholder:"tm_...",value:be,onChange:s=>O(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-white/60 block mb-1",children:"Default Domain"}),e.jsx("input",{type:"text",placeholder:"yourdomain.com",value:U,onChange:s=>Te(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-white/60 block mb-1",children:"Webhook Secret"}),e.jsx("input",{type:"password",placeholder:"Leave empty to auto-generate",value:We,onChange:s=>oe(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(m,{variant:"secondary",size:"sm",fullWidth:!0,onClick:xe,disabled:u,children:u?"Testing...":"⚡ Test Connection"}),L&&e.jsxs("div",{className:`p-2.5 rounded-lg text-xs font-medium flex items-start gap-2 ${L.ok?"bg-green-500/10 border border-green-500/20 text-green-400":"bg-red-500/10 border border-red-500/20 text-red-400"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 mt-0.5",children:L.ok?"check_circle":"error"}),e.jsx("span",{className:"break-all text-left",children:L.message})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(m,{variant:"secondary",size:"sm",fullWidth:!0,onClick:()=>A(!1),children:"Cancel"}),e.jsx(m,{variant:"primary",size:"sm",fullWidth:!0,onClick:Ve,children:"Save Settings"})]})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("label",{className:"text-[11px] text-white/60 block",children:"Cloudflare Account ID"}),e.jsxs("a",{href:"https://dash.cloudflare.com",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-primary hover:underline cursor-pointer flex items-center gap-0.5",children:["Temukan disini ",e.jsx("span",{className:"material-symbols-outlined text-[10px]",children:"open_in_new"})]})]}),e.jsx("input",{type:"text",placeholder:"Paste Account ID Anda",value:V,onChange:s=>ze(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("label",{className:"text-[11px] text-white/60 block",children:"Cloudflare API Token (Workers & D1)"}),e.jsxs("a",{href:"https://dash.cloudflare.com/profile/api-tokens",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-primary hover:underline cursor-pointer flex items-center gap-0.5",children:["Buat disini ",e.jsx("span",{className:"material-symbols-outlined text-[10px]",children:"open_in_new"})]})]}),e.jsx("input",{type:"password",placeholder:"Paste API Token Anda",value:W,onChange:s=>ge(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-white/60 block mb-1",children:"Domain Worker (misal: mail.domainanda.com)"}),e.jsx("input",{type:"text",placeholder:"mail.domainanda.com",value:le,onChange:s=>Be(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("label",{className:"text-[11px] text-white/60 block",children:"Telegram Bot Token (Opsional)"}),e.jsxs("a",{href:"https://t.me/BotFather",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-primary hover:underline cursor-pointer flex items-center gap-0.5",children:["Dapatkan di @BotFather ",e.jsx("span",{className:"material-symbols-outlined text-[10px]",children:"open_in_new"})]})]}),e.jsx("input",{type:"password",placeholder:"Token Bot dari @BotFather",value:Ae,onChange:s=>Fe(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"})]})]}),e.jsxs("div",{className:"space-y-3",children:[L&&e.jsxs("div",{className:`p-2.5 rounded-lg text-xs font-medium flex items-start gap-2 ${L.ok?"bg-green-500/10 border border-green-500/20 text-green-400":"bg-red-500/10 border border-red-500/20 text-red-400"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 mt-0.5",children:L.ok?"check_circle":"error"}),e.jsx("span",{className:"break-all text-left",children:L.message})]}),S&&e.jsxs("div",{className:"p-2.5 bg-white/5 border border-white/10 rounded-lg text-[10px] text-white/70 space-y-1 text-left",children:[e.jsx("span",{className:"font-semibold text-primary block",children:"Workers.dev fallback URL:"}),e.jsx("span",{className:"font-mono text-[9px] break-all block bg-black/40 p-1 rounded select-all",children:S}),e.jsx("span",{className:"block leading-relaxed",children:"Jika custom domain Anda terputus (misal karena DNS belum merambat), Anda dapat menggunakan URL fallback ini di tab Manual Input."})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(m,{variant:"secondary",size:"sm",fullWidth:!0,onClick:()=>A(!1),children:"Cancel"}),e.jsx(m,{variant:"primary",size:"sm",fullWidth:!0,onClick:De,disabled:u,children:u?"Deploying...":"⚡ Auto Deploy & Setup"})]})]})]}),e.jsxs("div",{className:"space-y-3 pt-2 border-t border-white/5 shrink-0",children:[e.jsx("a",{href:"/dashboard/automation/fsmail-tutorial",target:"_blank",rel:"noopener noreferrer",className:"w-full py-2 rounded-lg bg-neutral-900 border border-primary/20 hover:border-primary/50 text-primary text-xs font-semibold flex items-center justify-center gap-1.5 transition-colors cursor-pointer",children:"📖 Buka Panduan Lengkap Deploy"}),e.jsxs("details",{className:"group bg-white/5 border border-white/10 rounded-xl overflow-hidden",children:[e.jsxs("summary",{className:"list-none flex items-center justify-between p-3 cursor-pointer select-none text-[11px] font-semibold text-white/80 hover:text-white transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-primary",children:"help"}),"Cara Setup Temp Mail (FSMail)"]}),e.jsx("span",{className:"material-symbols-outlined text-[16px] transition-transform group-open:rotate-180",children:"expand_more"})]}),e.jsxs("div",{className:"p-3 pt-0 border-t border-white/5 text-[11px] text-white/70 space-y-2 leading-relaxed max-h-40 overflow-y-auto custom-scrollbar",children:[e.jsxs("p",{className:"mt-2",children:["FSMail adalah sistem email sementara berbasis ",e.jsx("strong",{children:"Cloudflare Worker"}),". Ikuti langkah berikut untuk mengaturnya:"]}),e.jsxs("ol",{className:"list-decimal list-inside space-y-1.5 text-white/60",children:[e.jsxs("li",{children:[e.jsx("strong",{className:"text-white/80",children:"Deploy Worker:"})," Deploy kode worker FSMail di akun Cloudflare Anda."]}),e.jsxs("li",{children:[e.jsx("strong",{className:"text-white/80",children:"Set API Key:"})," Pada dashboard Worker Anda, tambahkan Environment Variable ",e.jsx("code",{className:"bg-white/10 px-1 py-0.5 rounded font-mono text-amber-300",children:"API_KEY"})," dengan nilai token rahasia Anda."]}),e.jsxs("li",{children:[e.jsx("strong",{className:"text-white/80",children:"Email Routing:"})," Aktifkan Cloudflare Email Routing pada domain Anda, lalu arahkan semua email masuk ke worker tersebut."]}),e.jsxs("li",{children:[e.jsx("strong",{className:"text-white/80",children:"Hubungkan:"})," Masukkan ",e.jsx("strong",{className:"text-white",children:"Base URL Worker"})," (misal: ",e.jsx("code",{className:"text-amber-200",children:"https://mail.domain.com"}),") dan ",e.jsx("strong",{className:"text-white",children:"API Key"})," ke form di atas, lalu tekan ",e.jsx("strong",{className:"text-white",children:"Test Connection"}),"."]}),e.jsxs("li",{children:[e.jsx("strong",{className:"text-white/80",children:"Aktifkan Webhook:"})," Setelah koneksi berhasil dan pengaturan disimpan, klik tombol ",e.jsx("strong",{className:"text-white",children:"Register Webhook"})," di bawah untuk mengaktifkan sinkronisasi email secara real-time."]})]})]})]}),X&&e.jsxs("div",{className:"border-t border-white/10 pt-3 mt-2 space-y-2",children:[e.jsx("p",{className:"text-[10px] text-white/40 uppercase font-bold tracking-wider",children:"Worker Integration"}),e.jsx("pre",{className:"text-[10px] bg-white/5 p-2 rounded overflow-x-auto text-amber-300 font-mono",children:Ue}),e.jsx(m,{variant:"primary",size:"sm",fullWidth:!0,onClick:Me,children:"Register Webhook"})]})]})]})]})}),Re&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-neutral-950 border border-white/10 rounded-2xl w-full max-w-2xl text-white max-h-[85vh] flex flex-col overflow-hidden shadow-2xl",children:[e.jsxs("div",{className:"flex justify-between items-center p-5 border-b border-white/5 shrink-0 bg-neutral-900",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[22px]",children:"auto_stories"}),e.jsx("h3",{className:"text-base font-bold",children:"Panduan Lengkap Deploy Temp Mail"})]}),e.jsx("button",{onClick:()=>_e(!1),className:"text-white/60 hover:text-white cursor-pointer flex items-center",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsxs("div",{className:"p-6 overflow-y-auto custom-scrollbar flex-1 space-y-6 text-sm leading-relaxed text-white/80",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary px-2 py-0.5 rounded text-xs",children:"1"}),"Prasyarat & Login Cloudflare"]}),e.jsx("p",{className:"mb-2",children:"Pastikan Node.js sudah terinstal. Login ke akun Cloudflare Anda melalui terminal dengan menjalankan perintah berikut:"}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300",children:[e.jsx("span",{children:"npx wrangler login"}),e.jsx(E,{value:"npx wrangler login"})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary px-2 py-0.5 rounded text-xs",children:"2"}),"Install Dependencies"]}),e.jsx("p",{className:"mb-2",children:"Masuk ke direktori tempmail lokal di sistem Anda dan install dependensi NPM:"}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300",children:[e.jsx("span",{children:"cd /home/data/Project/fsrouter/tempmail && npm install"}),e.jsx(E,{value:"cd /home/data/Project/fsrouter/tempmail && npm install"})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary px-2 py-0.5 rounded text-xs",children:"3"}),"Buat Database D1"]}),e.jsx("p",{className:"mb-2",children:"Buat database SQL D1 baru untuk menyimpan inbox dan pesan email masuk:"}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300 mb-3",children:[e.jsx("span",{children:"npx wrangler d1 create tempmail"}),e.jsx(E,{value:"npx wrangler d1 create tempmail"})]}),e.jsxs("div",{className:"bg-blue-500/10 border border-blue-500/20 rounded-lg p-3 text-xs text-blue-300 flex items-start gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 mt-0.5",children:"info"}),e.jsxs("span",{children:["Salin ",e.jsx("strong",{children:"database_id"})," hasil output perintah di atas, lalu buka file ",e.jsx("a",{href:"file:///home/data/Project/fsrouter/tempmail/wrangler.jsonc",className:"underline font-semibold hover:text-blue-200",children:"wrangler.jsonc"})," dan ganti nilai ",e.jsx("code",{children:"database_id"})," di dalamnya."]})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary px-2 py-0.5 rounded text-xs",children:"4"}),"Jalankan Migrasi Database"]}),e.jsx("p",{className:"mb-2",children:"Inisialisasi tabel database temp mail di lokal dan jarak jauh (remote Cloudflare):"}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300",children:[e.jsx("span",{children:"npm run db:migrate:local && npm run db:migrate:remote"}),e.jsx(E,{value:"npm run db:migrate:local && npm run db:migrate:remote"})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary px-2 py-0.5 rounded text-xs",children:"5"}),"Simpan Secret Bot Telegram"]}),e.jsx("p",{className:"mb-2",children:"Set token Telegram bot Anda dan webhook secret token ke Cloudflare Workers:"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300",children:[e.jsx("span",{children:"npx wrangler secret put TELEGRAM_BOT_TOKEN"}),e.jsx(E,{value:"npx wrangler secret put TELEGRAM_BOT_TOKEN"})]}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300",children:[e.jsx("span",{children:"npx wrangler secret put TELEGRAM_WEBHOOK_SECRET"}),e.jsx(E,{value:"npx wrangler secret put TELEGRAM_WEBHOOK_SECRET"})]})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary px-2 py-0.5 rounded text-xs",children:"6"}),"Konfigurasi `wrangler.jsonc` & Deploy"]}),e.jsxs("p",{className:"mb-2",children:["Sesuaikan nilai di bagian ",e.jsx("code",{children:"vars"})," (domain dan base URL) pada file ",e.jsx("a",{href:"file:///home/data/Project/fsrouter/tempmail/wrangler.jsonc",className:"underline font-semibold hover:text-white",children:"wrangler.jsonc"}),", lalu deploy worker:"]}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300",children:[e.jsx("span",{children:"npm run deploy"}),e.jsx(E,{value:"npm run deploy"})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary px-2 py-0.5 rounded text-xs",children:"7"}),"Set Webhook Telegram Bot"]}),e.jsx("p",{className:"mb-2",children:"Daftarkan URL Worker Anda agar bot Telegram dapat memproses command masuk:"}),e.jsxs("div",{className:"flex items-center justify-between bg-white/5 p-3 rounded-lg border border-white/10 font-mono text-xs text-amber-300",children:[e.jsx("span",{className:"truncate mr-2",children:`curl -X POST "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook" -H "Content-Type: application/json" -d '{"url":"https://<worker-host>/telegram/webhook","secret_token":"<WEBHOOK_SECRET>"}'`}),e.jsx(E,{value:`curl -X POST "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook" -H "Content-Type: application/json" -d '{"url":"https://<worker-host>/telegram/webhook","secret_token":"<WEBHOOK_SECRET>"}'`})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary px-2 py-0.5 rounded text-xs",children:"8"}),"Cloudflare Email Routing"]}),e.jsxs("p",{children:["Masuk ke Cloudflare Dashboard domain Anda, klik menu ",e.jsx("strong",{children:"Email Routing"}),", aktifkan fitur tersebut, lalu buat rule ",e.jsx("strong",{children:"Catch-all"})," dengan aksi ",e.jsx("strong",{children:"Send to a Worker"})," mengarah ke nama Worker Anda."]})]})]}),e.jsx("div",{className:"p-5 border-t border-white/5 shrink-0 bg-neutral-900 flex justify-end",children:e.jsx(m,{variant:"primary",size:"sm",onClick:()=>_e(!1),children:"Selesai Membaca"})})]})}),j&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",children:e.jsxs("form",{onSubmit:w,className:"bg-neutral-900 border border-white/10 rounded-2xl w-full max-w-sm p-6 space-y-4 text-white",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-base font-bold",children:"New Inbox"}),e.jsx("button",{type:"button",onClick:()=>i(!1),className:"text-white/60 hover:text-white cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-white/60 block mb-1",children:"Alias (optional, empty = random)"}),e.jsx("input",{type:"text",placeholder:"e.g. business-inbox",value:we,onChange:s=>He(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-white/60 block mb-1",children:"Domain"}),se.length>0?e.jsxs("select",{value:ce,onChange:s=>de(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-neutral-900 focus:outline-none focus:border-primary text-white",children:[e.jsxs("option",{value:"",children:["— Default (",U||se[0],") —"]}),se.map(s=>e.jsx("option",{value:s,children:s},s))]}):e.jsx("input",{type:"text",placeholder:U||"yourdomain.com",value:ce,onChange:s=>de(s.target.value),className:"w-full text-xs p-2.5 rounded-lg border border-white/10 bg-white/5 focus:outline-none focus:border-primary text-white"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(m,{type:"button",variant:"secondary",size:"sm",fullWidth:!0,onClick:()=>i(!1),children:"Cancel"}),e.jsx(m,{type:"submit",variant:"primary",size:"sm",fullWidth:!0,children:"Create Inbox"})]})]})]})})]})}export{it 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.C5VWu_q7.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.DMCykSRG.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,P as i,u as d}from"./index.C5VWu_q7.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,7 @@
1
+ import{j as t,B as C}from"./index.C5VWu_q7.js";import{b as r}from"./router.Cjj1--8t.js";import"./NoAuthProxyCard.DMCykSRG.js";import"./zustand.akaTi5uX.js";function Z(){const[E,j]=r.useState(!1),[y,N]=r.useState(!1),[D,n]=r.useState(""),[L,w]=r.useState(""),[R,g]=r.useState(0),[F,S]=r.useState(""),[M,A]=r.useState([]),[T,J]=r.useState(""),[O,U]=r.useState(""),[k,q]=r.useState(null),[I,B]=r.useState(!1),$=r.useRef(null);r.useEffect(()=>{fetch("/api/db/info").then(e=>e.ok?e.json():null).then(e=>{e&&(q(e),U(e.examplePath||""))}).catch(()=>{})},[]);const s=r.useCallback((e,a="info")=>{A(u=>[...u.slice(-300),{msg:e,level:a,ts:new Date().toLocaleTimeString()}])},[]),_=r.useCallback(async()=>{N(!0),n(""),s("Memulai backup data (logical)...");try{const e=await fetch("/api/db");if(!e.ok)throw new Error(`HTTP ${e.status}`);const a=Number(e.headers.get("Content-Length"))||0,u=e.body.getReader(),o=new TextDecoder;let l=0,d="";for(;;){const{done:b,value:p}=await u.read();if(b)break;l+=p.length,a&&g(Math.min(99,Math.round(l/a*100))),d+=o.decode(p,{stream:!0})}const m=JSON.parse(d),x=new Blob([JSON.stringify(m,null,2)],{type:"application/json"}),h=URL.createObjectURL(x),f=document.createElement("a");f.href=h,f.download="fsrouter-backup.fud",f.click(),URL.revokeObjectURL(h),g(100),s("✓ Backup selesai: fsrouter-backup.fud","info")}catch(e){s("ERROR: "+e.message,"error"),n("Gagal backup: "+e.message)}finally{N(!1)}},[s]),G=r.useCallback(async()=>{N(!0),n(""),s("Memulai backup database mentah (.sqlite)...");try{const e=await fetch("/api/db/raw");if(!e.ok)throw new Error(`HTTP ${e.status}`);const a=Number(e.headers.get("Content-Length"))||0,u=e.body.getReader(),o=[];let l=0;for(;;){const{done:h,value:f}=await u.read();if(h)break;l+=f.length,a&&g(Math.min(99,Math.round(l/a*100))),o.push(f)}const d=new Blob(o,{type:"application/octet-stream"}),m=URL.createObjectURL(d),x=document.createElement("a");x.href=m,x.download=`fsrouter-db-raw-${Date.now()}.sqlite`,x.click(),URL.revokeObjectURL(m),g(100),s("✓ Backup mentah selesai","info")}catch(e){s("ERROR: "+e.message,"error"),n("Gagal backup mentah: "+e.message)}finally{N(!1)}},[s]),v=r.useCallback(async e=>{n(""),w(""),A([]),g(0),S("Memulai restore..."),j(!0);try{const a=await fetch("/api/db",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!a.ok||!a.body){const m=await a.json().catch(()=>({}));throw new Error(m.error||`HTTP ${a.status}`)}const u=a.body.getReader(),o=new TextDecoder;let l="",d=!1;for(;!d;){const{done:m,value:x}=await u.read();if(m)break;l+=o.decode(x,{stream:!0});const h=l.split(`
2
+
3
+ `);l=h.pop()||"";for(const f of h){const b=f.split(`
4
+ `);let p="message",c="";for(const P of b)P.startsWith("event:")?p=P.slice(6).trim():P.startsWith("data:")&&(c=P.slice(5).trim());if(!c)continue;let i;try{i=JSON.parse(c)}catch{continue}p==="progress"?(g(i.percent||0),S(i.label||""),s(`[${i.percent}%] ${i.label}`,"info")):p==="log"?s(i.message,i.level||"info"):p==="error"?(s(`ERROR: ${i.message}`,"error"),n(i.message)):p==="done"&&(s("✓ "+(i.message||"Selesai"),"info"),w("Restore berhasil! Server sedang merestart, harap tunggu beberapa saat..."),d=!0,setTimeout(()=>window.location.reload(),5e3))}}d||(w("Restore selesai. Server sedang merestart..."),setTimeout(()=>window.location.reload(),5e3))}catch(a){s("ERROR: "+(a.message||a),"error"),n(a.message||"File backup corrupt atau tidak valid."),j(!1)}},[s]),W=r.useCallback(async e=>{if(!e)return;if(!e.name.endsWith(".fud")&&!e.name.endsWith(".json")&&!e.name.endsWith(".sqlite")){n("Format tidak didukung (.fud / .json / .sqlite)");return}if(!window.confirm("PERINGATAN: Restore akan MENIMPA semua data saat ini! Lanjutkan?"))return;if(e.name.endsWith(".sqlite")){const u=await new Promise(o=>{const l=new FileReader;l.onload=()=>o(btoa(new Uint8Array(l.result).reduce((d,m)=>d+String.fromCharCode(m),""))),l.readAsArrayBuffer(e)});return v({signature:"FUDROUTER_BACKUP",version:1,files:{"db/data.sqlite":u}})}const a=new FileReader;a.onload=async u=>{try{const o=JSON.parse(u.target.result);await v(o)}catch{n("File backup corrupt atau tidak valid."),j(!1)}},a.readAsText(e)},[v]),H=e=>W(e.target.files[0]),z=r.useCallback(async()=>{if(!T.trim()){n("Textarea kosong.");return}if(window.confirm("PERINGATAN: Restore akan MENIMPA semua data saat ini! Lanjutkan?"))try{const e=JSON.parse(T);await v(e)}catch{n("JSON tidak valid."),j(!1)}},[T,v]),K=r.useCallback(async()=>{if(!O.trim()){n("Path kosong.");return}if(window.confirm("PERINGATAN: Restore akan MENIMPA semua data saat ini! Lanjutkan?"))try{const e=await fetch("/api/db/restore-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:O.trim()})});if(!e.ok||!e.body){const d=await e.json().catch(()=>({}));throw new Error(d.error||`HTTP ${e.status}`)}const a=e.body.getReader(),u=new TextDecoder;let o="",l=!1;for(n(""),w(""),A([]),g(0),S("Memulai restore dari path..."),j(!0);!l;){const{done:d,value:m}=await a.read();if(d)break;o+=u.decode(m,{stream:!0});const x=o.split(`
5
+
6
+ `);o=x.pop()||"";for(const h of x){const f=h.split(`
7
+ `);let b="message",p="";for(const i of f)i.startsWith("event:")?b=i.slice(6).trim():i.startsWith("data:")&&(p=i.slice(5).trim());if(!p)continue;let c;try{c=JSON.parse(p)}catch{continue}b==="progress"?(g(c.percent||0),S(c.label||""),s(`[${c.percent}%] ${c.label}`)):b==="log"?s(c.message,c.level||"info"):b==="error"?(s("ERROR: "+c.message,"error"),n(c.message)):b==="done"&&(s("✓ "+(c.message||"Selesai")),w("Restore berhasil! Server merestart..."),l=!0,setTimeout(()=>window.location.reload(),5e3))}}}catch(e){s("ERROR: "+(e.message||e),"error"),n(e.message||"Gagal restore dari path."),j(!1)}},[O,s]);return t.jsxs("div",{className:"max-w-4xl mx-auto p-4 space-y-6",children:[t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs("h1",{className:"text-2xl font-bold text-text-main flex items-center gap-2",children:[t.jsx("span",{className:"material-symbols-outlined text-[28px] text-primary",children:"backup"}),"Backup & Restore"]}),t.jsx("p",{className:"text-xs text-text-muted",children:"Amankan seluruh data FSRouter (provider, connections, akun automation, proxy, api keys) ke satu file, atau pulihkan dari file/teks/path."})]}),D&&t.jsxs("div",{className:"p-4 bg-red-500/10 border border-red-500/20 text-red-500 text-sm rounded-lg flex items-center gap-2",children:[t.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),D]}),L&&t.jsxs("div",{className:"p-4 bg-green-500/10 border border-green-500/20 text-green-500 text-sm rounded-lg flex items-center gap-2",children:[t.jsx("span",{className:"material-symbols-outlined text-sm",children:"check_circle"}),L]}),t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[t.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface flex flex-col gap-4",children:[t.jsxs("div",{className:"flex items-center gap-3 text-text-main",children:[t.jsx("div",{className:"size-10 rounded-full bg-blue-500/10 text-blue-500 flex items-center justify-center",children:t.jsx("span",{className:"material-symbols-outlined text-xl",children:"cloud_download"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-semibold",children:"Buat Backup"}),t.jsx("p",{className:"text-[11px] text-text-muted",children:"Simpan data ke perangkat"})]})]}),t.jsx("div",{className:"text-xs text-text-muted leading-relaxed flex-1",children:t.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-1",children:[t.jsxs("li",{children:[t.jsx("b",{children:"Portabel (.fud)"}),": semua data sebagai JSON — bisa dipulihkan di OS berbeda."]}),t.jsxs("li",{children:[t.jsx("b",{children:"Mentah (.sqlite)"}),": copy langsung file database — paling akurat, sama OS."]})]})}),t.jsx(C,{variant:"primary",fullWidth:!0,onClick:_,disabled:y,icon:"download",children:y?`Membackup... ${R}%`:"Download Backup (.fud)"}),t.jsx(C,{variant:"secondary",fullWidth:!0,onClick:G,disabled:y,icon:"storage",children:"Download Database Mentah (.sqlite)"}),y&&t.jsx("div",{className:"w-full h-2.5 rounded-full bg-sidebar overflow-hidden",children:t.jsx("div",{className:"h-full bg-gradient-to-r from-primary to-emerald-400 transition-all",style:{width:`${R}%`}})})]}),t.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface flex flex-col gap-4",children:[t.jsxs("div",{className:"flex items-center gap-3 text-text-main",children:[t.jsx("div",{className:"size-10 rounded-full bg-amber-500/10 text-amber-500 flex items-center justify-center",children:t.jsx("span",{className:"material-symbols-outlined text-xl",children:"restore"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-semibold",children:"Pulihkan Backup"}),t.jsx("p",{className:"text-[11px] text-text-muted",children:"Timpa data dari file/teks/path"})]})]}),t.jsxs("div",{onDragOver:e=>{e.preventDefault(),B(!0)},onDragLeave:()=>B(!1),onDrop:e=>{e.preventDefault(),B(!1),W(e.dataTransfer.files[0])},onClick:()=>{var e;return(e=$.current)==null?void 0:e.click()},className:`border-2 border-dashed rounded-lg p-5 text-center cursor-pointer transition-colors ${I?"border-primary bg-primary/5":"border-border-subtle hover:border-primary/50"}`,children:[t.jsx("span",{className:"material-symbols-outlined text-3xl text-text-muted",children:"upload_file"}),t.jsx("p",{className:"text-xs text-text-muted mt-1",children:"Klik atau seret file .fud / .json / .sqlite ke sini"})]}),t.jsx("input",{type:"file",accept:".fud,.json,.sqlite",ref:$,onChange:H,className:"hidden"}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-[11px] text-text-muted",children:"Atau tempel (paste) isi file backup JSON:"}),t.jsx("textarea",{value:T,onChange:e=>J(e.target.value),placeholder:'{ "signature": "FUDROUTER_BACKUP", ... }',className:"w-full h-20 text-[11px] font-mono bg-black/40 border border-border-subtle rounded p-2 text-text-main resize-none"}),t.jsx(C,{variant:"secondary",fullWidth:!0,onClick:z,disabled:E,icon:"content_paste",children:"Restore dari Teks"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("label",{className:"text-[11px] text-text-muted",children:["Atau path file di server",k?` (${k.isWindows?"Windows":k.platform}):`:":"]}),t.jsx("input",{value:O,onChange:e=>U(e.target.value),placeholder:(k==null?void 0:k.examplePath)||"C:\\Users\\fud\\AppData\\Roaming\\fsrouter\\backups\\fsrouter-backup.fud",className:"w-full text-[11px] bg-black/40 border border-border-subtle rounded p-2 text-text-main"}),k&&t.jsxs("p",{className:"text-[10px] text-text-muted",children:["Folder backup default: ",t.jsx("code",{className:"text-primary",children:k.defaultBackupDir})]}),t.jsx(C,{variant:"secondary",fullWidth:!0,onClick:K,disabled:E,icon:"folder_open",children:"Restore dari Path"})]}),E&&t.jsxs("div",{className:"mt-2 space-y-3",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex justify-between text-[11px] text-text-muted mb-1",children:[t.jsx("span",{children:F||"Memproses..."}),t.jsxs("span",{children:[R,"%"]})]}),t.jsx("div",{className:"w-full h-2.5 rounded-full bg-sidebar overflow-hidden",children:t.jsx("div",{className:"h-full bg-gradient-to-r from-primary to-emerald-400 transition-all duration-300",style:{width:`${R}%`}})})]}),t.jsx("div",{className:"bg-black/80 rounded-lg p-3 h-48 overflow-y-auto font-mono text-[10px] leading-relaxed",children:M.length===0?t.jsx("div",{className:"text-text-muted",children:"Menunggu output restore..."}):M.map((e,a)=>t.jsxs("div",{className:e.level==="error"?"text-red-400":e.level==="warn"?"text-amber-400":"text-green-300",children:[t.jsxs("span",{className:"text-text-muted",children:["[",e.ts,"]"]})," ",e.msg]},a))})]})]})]})]})}export{Z as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.C5VWu_q7.js";import{b as n}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function x(){const[s,a]=n.useState(null),[c,r]=n.useState(!1),i=async m=>{const o=m.target.files[0];if(!o)return;r(!0);const l=new FormData;l.append("file",o);try{const t=await fetch("/api/ocr",{method:"POST",body:l});a(await t.json())}catch(t){a({error:t.message})}r(!1)};return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"OCR"}),e.jsx("p",{className:"text-text-muted",children:"Extract text from images using Mistral OCR API"}),e.jsx("input",{type:"file",accept:"image/*,.pdf",onChange:i,className:"block"}),c&&e.jsx("p",{children:"Processing..."}),s&&e.jsx("pre",{className:"p-4 bg-black/5 rounded-lg text-sm overflow-auto max-h-96",children:JSON.stringify(s,null,2)})]})}export{x as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.C5VWu_q7.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};
@@ -0,0 +1 @@
1
+ import{j as e,B as I,y as te,h as ae,k as re,l as le}from"./index.C5VWu_q7.js";import{b as r}from"./router.Cjj1--8t.js";import{M as ie}from"./cliTools.CsdwAybi.js";import{C as Z,B,I as K,M as ne}from"./NoAuthProxyCard.DMCykSRG.js";import"./zustand.akaTi5uX.js";const $=te();function oe({apiKeys:l,cloudEnabled:b,onStatusChange:y}){const[s,c]=r.useState(null),[x,v]=r.useState(!1),[D,N]=r.useState(!1),[T,p]=r.useState(""),[j,U]=r.useState(()=>{var a;return((a=l==null?void 0:l[0])==null?void 0:a.key)||""}),[E,h]=r.useState(null),[A,w]=r.useState(null),[_,S]=r.useState(null),[i,n]=r.useState($),[m,R]=r.useState(null),u=(s==null?void 0:s.isWin)===!0,q=u||(s==null?void 0:s.hasCachedPassword)||(s==null?void 0:s.needsSudoPassword)===!1,k=(s==null?void 0:s.isAdmin)!==!1;!k&&(u||!(s!=null&&s.hasCachedPassword)&&(s==null||s.needsSudoPassword));const g=r.useCallback(async()=>{try{const a=await fetch("/api/cli-tools/antigravity-mitm");if(a.ok){const d=await a.json();c(d),d.mitmRouterBaseUrl&&n(d.mitmRouterBaseUrl),y==null||y(d)}}catch{c({running:!1,certExists:!1,dnsStatus:{}})}},[y]);r.useEffect(()=>{queueMicrotask(()=>{g()})},[g]);const O=a=>{S(null),s&&(q?z(a,""):(h(a),N(!0),w(null)))},z=async(a,d,L=!1)=>{v(!0),S(null);try{let f;if(a==="trust-cert")f=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"trust-cert",sudoPassword:d})});else if(a==="start"){const P=(j==null?void 0:j.trim())||((l==null?void 0:l.length)>0?l[0].key:null)||(b?null:"sk_fsrouter");f=await fetch("/api/cli-tools/antigravity-mitm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:P,sudoPassword:d,mitmRouterBaseUrl:i.trim()||$,forceKillPort443:L})})}else f=await fetch("/api/cli-tools/antigravity-mitm",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({sudoPassword:d})});if(!f.ok){const P=await f.json().catch(()=>({}));if(P.code==="PORT_443_BUSY"&&P.portOwner){N(!1),R({owner:P.portOwner,password:d});return}S(P.error||`Failed to ${a} MITM server`);return}N(!1),p(""),R(null),await g()}catch(f){S(f.message||"Network error")}finally{v(!1),h(null)}},F=()=>{const a=(m==null?void 0:m.password)||"";z("start",a,!0)},M=()=>{if(!T.trim()){w("Sudo password is required");return}z(E,T)},C=s==null?void 0:s.running;return e.jsxs(e.Fragment,{children:[e.jsx(Z,{padding:"sm",className:"border-primary/20 bg-primary/5",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[20px]",children:"security"}),e.jsx("span",{className:"font-semibold text-sm text-text-main",children:"MITM Server"}),C?e.jsx(B,{variant:"success",size:"sm",children:"Running"}):e.jsx(B,{variant:"default",size:"sm",children:"Stopped"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1 text-xs text-text-muted","data-i18n-skip":"true",children:[{label:"Cert",ok:s==null?void 0:s.certExists},{label:"Trusted",ok:s==null?void 0:s.certTrusted},{label:"Server",ok:C}].map(({label:a,ok:d})=>e.jsxs("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded ${d?"text-green-600":"text-text-muted"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:d?"check_circle":"cancel"}),a]},a))})]}),e.jsxs("div",{className:"px-2 py-2 rounded-lg bg-surface/50 border border-border/50 flex flex-col gap-2",children:[e.jsxs("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[e.jsx("span",{className:"font-medium text-text-main",children:"Purpose:"})," Use Antigravity IDE & GitHub Copilot → with ANY provider/model from FSRouter"]}),e.jsxs("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[e.jsx("span",{className:"font-medium text-text-main",children:"How it works:"})," Antigravity/Copilot IDE request → DNS redirect to localhost:443 → MITM proxy intercepts → FSRouter → response to Antigravity/Copilot"]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"FSRouter Base URL"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("input",{type:"text",value:i,onChange:a=>n(a.target.value),placeholder:$,disabled:C,className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50 disabled:opacity-50"})]}),!C&&e.jsxs("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("input",{type:"text",list:"mitm-api-keys",value:j,onChange:a=>U(a.target.value),placeholder:b?"Enter or pick API key":"sk_fsrouter (default)",className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50"}),(l==null?void 0:l.length)>0&&e.jsx("datalist",{id:"mitm-api-keys",children:l.map(a=>e.jsx("option",{value:a.key,children:a.name||a.key},a.id))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center","data-i18n-skip":"true",children:[(s==null?void 0:s.certExists)&&!(s!=null&&s.certTrusted)&&e.jsxs("button",{onClick:()=>O("trust-cert"),disabled:x,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-yellow-500/30 bg-yellow-500/10 px-4 py-2 text-xs font-medium text-yellow-600 transition-colors hover:bg-yellow-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"verified_user"}),"Trust Cert"]}),C?e.jsxs("button",{onClick:()=>O("stop"),disabled:x,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2 text-xs font-medium text-red-500 transition-colors hover:bg-red-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"stop_circle"}),"Stop Server"]}):e.jsxs("button",{onClick:()=>O("start"),disabled:x||!s||u&&!k,title:u&&!k?"Administrator required":void 0,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-primary/30 bg-primary/10 px-4 py-2 text-xs font-medium text-primary transition-colors hover:bg-primary/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"play_circle"}),"Start Server"]}),C&&e.jsx("p",{className:"text-xs text-text-muted",children:"Enable DNS per tool below to activate interception"})]}),_&&e.jsxs("div",{className:"flex items-start gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 dark:text-red-400 border border-red-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mt-0.5 shrink-0",children:"error"}),e.jsx("span",{children:_})]}),u&&!k&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 border border-red-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"shield_lock"}),e.jsx("span",{children:"Administrator required — restart FSRouter as Administrator to use MITM"})]})]})}),D&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[e.jsx("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Required for SSL certificate and server startup"})]}),e.jsx(K,{type:"password",placeholder:"Enter sudo password",value:T,onChange:a=>p(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!x&&M()}}),A&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),e.jsx("span",{children:A})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{N(!1),p(""),w(null)},disabled:x,children:"Cancel"}),e.jsx(I,{variant:"primary",size:"sm",onClick:M,loading:x,children:"Confirm"})]})]})}),m&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[e.jsx("h3",{className:"font-semibold text-text-main",children:"Port 443 Already In Use"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),e.jsxs("div",{className:"flex flex-col gap-1 text-xs text-text-muted",children:[e.jsx("p",{children:"Port 443 is currently used by another process:"}),e.jsxs("p",{className:"font-mono text-text-main","data-i18n-skip":"true",children:[m.owner.name," (PID ",m.owner.pid,")"]}),e.jsx("p",{children:"Kill this process to start MITM Server?"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{R(null),v(!1)},disabled:x,children:"Cancel"}),e.jsx(I,{variant:"primary",size:"sm",onClick:F,loading:x,children:"Kill & Start"})]})]})})]})}const de={antigravity:["daily-cloudcode-pa.googleapis.com","cloudcode-pa.googleapis.com"],copilot:["api.individual.githubcopilot.com"],kiro:["q.us-east-1.amazonaws.com","codewhisperer.us-east-1.amazonaws.com"],cursor:["api2.cursor.sh"]};function ce({tool:l,isExpanded:b,onToggle:y,serverRunning:s,dnsActive:c,hasCachedPassword:x,needsSudoPassword:v,isWin:D,apiKeys:N,activeProviders:T,hasActiveProviders:p,modelAliases:j={},cloudEnabled:U,onDnsChange:E}){var Q,V;const[h,A]=r.useState(!1),[w,_]=r.useState(null),[S,i]=r.useState(!1),[n,m]=r.useState(""),[R,u]=r.useState(null),[q,k]=r.useState(null),[g,O]=r.useState({}),[z,F]=r.useState(!1),[M,C]=r.useState(null),a=de[l.id]??[],d=D||x||v===!1;r.useEffect(()=>{b&&L()},[b]);const L=async()=>{try{const t=await fetch(`/api/cli-tools/antigravity-mitm/alias?tool=${l.id}`);if(t.ok){const o=await t.json();Object.keys(o.aliases||{}).length>0&&O(o.aliases)}}catch{}},f=r.useCallback(async t=>{try{await fetch("/api/cli-tools/antigravity-mitm/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:l.id,mappings:t})})}catch{}},[l.id]),P=(t,o)=>{f({...g,[t]:o})},W=(t,o)=>{O(H=>({...H,[t]:o}))},ee=t=>{C(t),F(!0)},se=t=>{if(!M||t.isPlaceholder)return;const o={...g,[M]:t.value};O(o),f(o)},J=()=>{if(!s)return;const t=c?"disable":"enable";d?G(t,""):(u(t),i(!0),k(null))},G=async(t,o)=>{A(!0),_(null);try{const H=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:l.id,action:t,sudoPassword:o})}),X=await H.json();if(!H.ok)throw new Error(X.error||"Failed to toggle DNS");t==="enable"&&_(`Restart ${l.name} to apply changes`),i(!1),m(""),E==null||E(X)}catch{}finally{A(!1),u(null)}},Y=()=>{if(!n.trim()){k("Sudo password is required");return}G(R,n)};return e.jsxs(e.Fragment,{children:[e.jsxs(Z,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:y,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("img",{src:l.image,alt:l.name,width:32,height:32,className:"size-8 object-contain rounded-lg",onError:t=>{t.target.style.display="none"}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:l.name}),s?c?e.jsx(B,{variant:"success",size:"sm",children:"Active"}):e.jsx(B,{variant:"warning",size:"sm",children:"DNS off"}):e.jsx(B,{variant:"default",size:"sm",children:"Server off"})]}),e.jsxs("p",{className:"text-xs text-text-muted sm:truncate",children:["Intercept ",l.name," requests via MITM proxy"]})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${b?"rotate-180":""}`,children:"expand_more"})]}),b&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[a.length>0&&e.jsxs("div",{className:"mt-2 rounded-md border border-border bg-surface/50 px-2 py-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium tracking-wide text-text-main/80 mb-1",children:"Edit hosts file manually to add the following entries:"}),e.jsx("ul",{className:"list-none space-y-0.5 font-mono text-[10px] text-text-muted break-all",children:a.map(t=>e.jsxs("li",{children:["127.0.0.1 ",t]},t))})]}),e.jsxs("div",{className:"flex flex-col gap-0.5 text-[11px] text-text-muted px-1",children:[e.jsxs("p",{children:["Toggle DNS to redirect ",l.name," traffic through FSRouter via MITM."]}),!c&&e.jsx("p",{className:"text-amber-600 text-[10px] mt-1",children:"⚠️ Enable DNS to edit model mappings"})]}),((Q=l.defaultModels)==null?void 0:Q.length)>0&&e.jsx("div",{className:"flex flex-col gap-2",children:l.defaultModels.map(t=>e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[9rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right",children:t.name}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:g[t.alias]||"",onChange:o=>W(t.alias,o.target.value),onBlur:o=>P(t.alias,o.target.value),placeholder:"provider/model-id",disabled:!c,className:`w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5 ${c?"":"opacity-50 cursor-not-allowed"}`}),g[t.alias]&&e.jsx("button",{onClick:()=>{W(t.alias,""),f({...g,[t.alias]:""})},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>ee(t.alias),disabled:!p||!c,className:`rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 ${p&&c?"bg-surface border-border hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]},t.alias))}),((V=l.defaultModels)==null?void 0:V.length)===0&&e.jsx("p",{className:"text-xs text-text-muted px-1",children:"Model mappings will be available soon."}),e.jsxs("div",{className:"flex flex-col gap-2 sm:items-start",children:[c?e.jsxs("button",{onClick:J,disabled:!s||h,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2 text-xs font-medium text-red-500 transition-colors hover:bg-red-500/20 disabled:cursor-not-allowed disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"stop_circle"}),"Stop DNS"]}):e.jsxs("button",{onClick:J,disabled:!s||h,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-primary/30 bg-primary/10 px-4 py-2 text-xs font-medium text-primary transition-colors hover:bg-primary/20 disabled:cursor-not-allowed disabled:opacity-50 sm:w-auto sm:py-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"play_circle"}),"Start DNS"]}),w&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs text-amber-500",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"warning"}),e.jsx("span",{children:w})]})]})]})]}),S&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[e.jsx("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Required to modify /etc/hosts and flush DNS cache"})]}),e.jsx(K,{type:"password",placeholder:"Enter sudo password",value:n,onChange:t=>m(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!h&&Y()}}),q&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),e.jsx("span",{children:q})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{i(!1),m(""),k(null)},disabled:h,children:"Cancel"}),e.jsx(I,{variant:"primary",size:"sm",onClick:Y,loading:h,children:"Confirm"})]})]})}),e.jsx(ne,{isOpen:z,onClose:()=>F(!1),onSelect:se,selectedModel:M?g[M]:null,activeProviders:T,modelAliases:j,title:`Select model for ${M}`})]})}function me(){const[l,b]=r.useState([]),[y,s]=r.useState([]),[c,x]=r.useState({}),[v,D]=r.useState(!1),[N,T]=r.useState(null),[p,j]=r.useState({running:!1,certExists:!1,dnsStatus:{},hasCachedPassword:!1});r.useEffect(()=>{U(),E(),h(),A()},[]);const U=async()=>{try{const i=await fetch("/api/providers");if(i.ok){const n=await i.json();b(n.connections||[])}}catch{}},E=async()=>{try{const i=await fetch("/api/keys");if(i.ok){const n=await i.json();s(n.keys||[])}}catch{}},h=async()=>{try{const i=await fetch("/api/models/alias");if(i.ok){const n=await i.json();x(n.aliases||{})}}catch{}},A=async()=>{try{const i=await fetch("/api/settings");if(i.ok){const n=await i.json();D(n.cloudEnabled||!1)}}catch{}},w=()=>l.filter(i=>i.isActive!==!1),_=()=>w().some(n=>ae(n.provider).length>0||re(n.provider)||le(n.provider)),S=Object.entries(ie);return e.jsxs("div",{className:"flex w-full flex-col gap-6",children:[e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-yellow-500 mt-0.5 shrink-0",children:"warning"}),e.jsx("p",{className:"text-xs text-red-600 dark:text-yellow-400 leading-relaxed",children:"⚠️ MITM intercepts HTTPS traffic of IDE tools (Antigravity, GitHub Copilot, Kiro) via local CA to redirect requests to your providers. May violate ToS → account ban. Use at your own risk."})]}),e.jsx(oe,{apiKeys:y,cloudEnabled:v,onStatusChange:j}),e.jsx("div",{className:"grid gap-3 sm:gap-4",children:S.map(([i,n])=>{var m;return e.jsx(ce,{tool:n,isExpanded:N===i,onToggle:()=>T(N===i?null:i),serverRunning:p.running,dnsActive:((m=p.dnsStatus)==null?void 0:m[i])||!1,hasCachedPassword:p.hasCachedPassword||!1,needsSudoPassword:p.needsSudoPassword!==!1,isWin:p.isWin===!0,apiKeys:y,activeProviders:w(),hasActiveProviders:_(),modelAliases:c,cloudEnabled:v,onDnsChange:R=>j(u=>({...u,dnsStatus:R.dnsStatus??u.dnsStatus}))},i)})})]})}function ge(){return e.jsx(me,{})}export{ge as default};
@@ -0,0 +1 @@
1
+ import{F as le,j as e,g as Y,n as k,B as q,o as oe}from"./index.C5VWu_q7.js";import{d as se,f as re,b as x}from"./router.Cjj1--8t.js";import{B as I,f as D,c as M,d as ie,P as de,U as ce,e as xe,C as V}from"./NoAuthProxyCard.DMCykSRG.js";import{C as ae}from"./Loading.D9qCFX3R.js";import"./zustand.akaTi5uX.js";function Q(s){if(s==="leonardo"||s==="weavy")return!0;const t=Y[s];return t!=null&&t.serviceKinds?t.serviceKinds.includes("llm"):!0}function me(s){const t=Math.floor((Date.now()-new Date(s))/1e3);return t<60?`${t}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function ue({timestamp:s}){const[,t]=x.useState(0);return x.useEffect(()=>{const r=setInterval(()=>t(a=>a+1),1e3);return()=>clearInterval(r)},[]),e.jsx(e.Fragment,{children:me(s)})}function pe({requests:s=[]}){return e.jsxs(V,{className:"flex min-w-0 flex-col overflow-hidden",padding:"sm",style:{height:480},children:[e.jsx("div",{className:"px-1 py-2 border-b border-border shrink-0",children:e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide",children:"Recent Requests"})}),s.length?e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("table",{className:"w-full min-w-[300px] border-collapse text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-bg z-10",children:e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("th",{className:"py-1.5 text-left font-semibold text-text-muted w-2"}),e.jsx("th",{className:"py-1.5 text-left font-semibold text-text-muted",children:"Model"}),e.jsx("th",{className:"py-1.5 text-right font-semibold text-text-muted whitespace-nowrap",children:"In / Out"}),e.jsx("th",{className:"py-1.5 text-right font-semibold text-text-muted",children:"When"})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:s.map((t,r)=>{const a=t.status==="streaming",i=!t.status||t.status==="ok"||t.status==="success";return e.jsxs("tr",{className:"hover:bg-bg-subtle transition-colors",children:[e.jsx("td",{className:"py-1.5",children:a?e.jsx("span",{className:"block w-1.5 h-1.5 rounded-full bg-warning animate-pulse",title:"Streaming…"}):e.jsx("span",{className:`block w-1.5 h-1.5 rounded-full ${i?"bg-success":"bg-error"}`})}),e.jsx("td",{className:"py-1.5 font-mono truncate max-w-[120px]",title:t.model,children:t.model}),e.jsx("td",{className:"py-1.5 text-right whitespace-nowrap",children:a?e.jsx("span",{className:"text-warning italic text-[10px]",children:"streaming…"}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-primary",children:[D(t.promptTokens),"↑"]})," ",e.jsxs("span",{className:"text-success",children:[D(t.completionTokens),"↓"]})]})}),e.jsx("td",{className:"py-1.5 text-right text-text-muted whitespace-nowrap",children:e.jsx(ue,{timestamp:t.timestamp})})]},r)})})]})}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-text-muted text-sm",children:"No requests yet."})]})}function _(s,t={},r,a){return Object.entries(s||{}).map(([i,o])=>{const n=(o.promptTokens||0)+(o.completionTokens||0),l=o.cost||0,b=n>0?(o.promptTokens||0)*(l/n):0,p=n>0?(o.completionTokens||0)*(l/n):0;return{...o,key:i,totalTokens:n,totalCost:l,inputCost:b,outputCost:p,pending:t[i]||0}}).sort((i,o)=>{let n=i[r],l=o[r];return typeof n=="string"&&(n=n.toLowerCase()),typeof l=="string"&&(l=l.toLowerCase()),n<l?a==="asc"?-1:1:n>l?a==="asc"?1:-1:0})}function he(s,t){var r;switch(t){case"rawModel":return s.rawModel||"Unknown Model";case"accountName":return s.accountName||`Account ${(r=s.connectionId)==null?void 0:r.slice(0,8)}...`||"Unknown Account";case"keyName":return s.keyName||"Unknown Key";case"endpoint":return s.endpoint||"Unknown Endpoint";default:return s[t]||"Unknown"}}function K(s,t){if(!Array.isArray(s))return[];const r={};return s.forEach(a=>{const i=he(a,t);r[i]||(r[i]={groupKey:i,summary:{requests:0,promptTokens:0,completionTokens:0,totalTokens:0,cost:0,inputCost:0,outputCost:0,lastUsed:null,pending:0},items:[]});const o=r[i].summary;o.requests+=a.requests||0,o.promptTokens+=a.promptTokens||0,o.completionTokens+=a.completionTokens||0,o.totalTokens+=a.totalTokens||0,o.cost+=a.cost||0,o.inputCost+=a.inputCost||0,o.outputCost+=a.outputCost||0,o.pending+=a.pending||0,a.lastUsed&&(!o.lastUsed||new Date(a.lastUsed)>new Date(o.lastUsed))&&(o.lastUsed=a.lastUsed),r[i].items.push(a)}),Object.values(r)}const fe=[{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],be=[{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"accountName",label:"Account"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],ge=[{field:"keyName",label:"API Key Name"},{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],je=[{field:"endpoint",label:"Endpoint"},{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],ve=[{value:"model",label:"Usage by Model"},{value:"account",label:"Usage by Account"},{value:"apiKey",label:"Usage by API Key"},{value:"endpoint",label:"Usage by Endpoint"}],ye=[{value:"today",label:"Today"},{value:"24h",label:"24h"},{value:"7d",label:"7D"},{value:"30d",label:"30D"},{value:"60d",label:"60D"}];function X(s){if(!s)return s;const t={...s};if(t.byProvider&&(t.byProvider={...t.byProvider},t.byProvider.cb)){if(!t.byProvider.codebuddy)t.byProvider.codebuddy=t.byProvider.cb;else{const r=t.byProvider.cb,a=t.byProvider.codebuddy;t.byProvider.codebuddy={requests:(a.requests||0)+(r.requests||0),promptTokens:(a.promptTokens||0)+(r.promptTokens||0),completionTokens:(a.completionTokens||0)+(r.completionTokens||0),cost:(a.cost||0)+(r.cost||0)}}delete t.byProvider.cb}return t.byModel&&(t.byModel=Object.fromEntries(Object.entries(t.byModel).map(([r,a])=>r.endsWith(" (cb)")?[r.slice(0,-5)+" (codebuddy)",{...a,provider:"CodeBuddy"}]:[r,a]))),t.byAccount&&(t.byAccount=Object.fromEntries(Object.entries(t.byAccount).map(([r,a])=>a.provider==="cb"||a.provider==="Codebuddy"||a.provider==="codebuddy"?[r,{...a,provider:"CodeBuddy"}]:[r,a]))),Array.isArray(t.recentRequests)&&(t.recentRequests=t.recentRequests.map(r=>r.provider==="cb"?{...r,provider:"codebuddy"}:r)),t}function Ne({period:s,setPeriod:t,hidePeriodSelector:r=!1}={}){var E,c,w,C;const a=se(),[i]=re(),o=i.get("sortBy")||"rawModel",n=i.get("sortOrder")||"asc",[l,b]=x.useState(null),[p,j]=x.useState(!0),[f,P]=x.useState(!1),[y,h]=x.useState("model"),[N,L]=x.useState("costs"),[O,J]=x.useState([]),[G,W]=x.useState("today"),A=x.useRef(!0),T=s??G,F=t??W;x.useEffect(()=>{fetch("/api/providers").then(m=>m.ok?m.json():null).then(m=>{const v=new Set,d=((m==null?void 0:m.connections)||[]).filter(g=>g.isActive===!1||!Q(g.provider)||v.has(g.provider)?!1:(v.add(g.provider),!0)),u=Object.values(le).filter(g=>g.noAuth&&!v.has(g.id)&&Q(g.id)).map(g=>({provider:g.id,name:g.name}));J([...d,...u])}).catch(()=>{})},[]),x.useEffect(()=>{A.current?(A.current=!1,j(!0)):P(!0),fetch(`/api/usage/stats?period=${T}`).then(m=>m.ok?m.json():null).then(m=>{if(m){const v=X(m);b(d=>({...d,...v}))}}).catch(()=>{}).finally(()=>{j(!1),P(!1)})},[T]),x.useEffect(()=>{const m=new EventSource(`/api/usage/stream?period=${T}`);return m.onmessage=v=>{try{const d=JSON.parse(v.data),u=X(d);b(u),j(!1)}catch(d){console.error("[SSE CLIENT] parse error:",d)}},m.onerror=()=>j(!1),()=>m.close()},[T]);const $=x.useCallback((m,v)=>{const d=new URLSearchParams(i.toString());d.get("sortBy")===v?d.set("sortOrder",d.get("sortOrder")==="asc"?"desc":"asc"):(d.set("sortBy",v),d.set("sortOrder","asc")),a(`?${d.toString()}`,{scroll:!1})},[i,a]),S=x.useMemo(()=>{var m,v;if(!l)return null;switch(y){case"model":{const d=((m=l.pending)==null?void 0:m.byModel)||{};return{columns:fe,groupedData:K(_(l.byModel,d,o,n),"rawModel"),storageKey:"usage-stats:expanded-models",emptyMessage:"No usage recorded yet.",renderSummaryCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.summary.lastUsed)})]}),renderDetailCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:u.pending>0?"primary":"neutral",size:"sm",children:u.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.lastUsed)})]})}}case"account":{const d={};return(v=l==null?void 0:l.pending)!=null&&v.byAccount&&Object.entries(l.byAccount||{}).forEach(([u,g])=>{const H=l.pending.byAccount[g.connectionId];if(H){const ne=g.provider?`${g.rawModel} (${g.provider})`:g.rawModel;d[u]=H[ne]||0}}),{columns:be,groupedData:K(_(l.byAccount,d,o,n),"accountName"),storageKey:"usage-stats:expanded-accounts",emptyMessage:"No account-specific usage recorded yet.",renderSummaryCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.summary.lastUsed)})]}),renderDetailCells:u=>{var g;return e.jsxs(e.Fragment,{children:[e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.accountName||`Account ${(g=u.connectionId)==null?void 0:g.slice(0,8)}...`}),e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:u.pending>0?"primary":"neutral",size:"sm",children:u.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.lastUsed)})]})}}}case"apiKey":return{columns:ge,groupedData:K(_(l.byApiKey,{},o,n),"keyName"),storageKey:"usage-stats:expanded-apikeys",emptyMessage:"No API key usage recorded yet.",renderSummaryCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.summary.lastUsed)})]}),renderDetailCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 font-medium",children:d.keyName}),e.jsx("td",{className:"px-6 py-3",children:d.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:"neutral",size:"sm",children:d.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.lastUsed)})]})};case"endpoint":default:return{columns:je,groupedData:K(_(l.byEndpoint,{},o,n),"endpoint"),storageKey:"usage-stats:expanded-endpoints",emptyMessage:"No endpoint usage recorded yet.",renderSummaryCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.summary.lastUsed)})]}),renderDetailCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 font-medium font-mono text-sm",children:d.endpoint}),e.jsx("td",{className:"px-6 py-3",children:d.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:"neutral",size:"sm",children:d.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.lastUsed)})]})}}},[l,y,o,n]);if(!l&&!p)return e.jsx("div",{className:"text-text-muted",children:"Failed to load usage statistics."});const R=e.jsx("div",{className:"flex items-center justify-center py-12 text-text-muted",children:e.jsx("span",{className:"material-symbols-outlined text-[32px] animate-spin",children:"progress_activity"})});return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6",children:[!r&&e.jsxs("div",{className:"flex w-full items-center gap-2 sm:w-auto sm:self-end",children:[e.jsx("div",{className:"grid flex-1 grid-cols-5 items-center gap-1 rounded-lg border border-border bg-bg-subtle p-1 sm:flex sm:flex-none",children:ye.map(m=>e.jsx("button",{onClick:()=>F(m.value),disabled:f,className:`rounded-md px-3 py-1 text-sm font-medium transition-colors ${T===m.value?"bg-primary text-white shadow-sm":"text-text-muted hover:bg-bg-hover hover:text-text"}`,children:m.label},m.value))}),f&&e.jsx("span",{className:"material-symbols-outlined text-[16px] text-text-muted animate-spin",children:"progress_activity"})]}),p?R:e.jsx(ie,{stats:l}),p?R:e.jsxs("div",{className:"grid min-w-0 grid-cols-1 items-stretch gap-2 lg:grid-cols-[minmax(0,2fr)_minmax(280px,1fr)]",children:[e.jsx(de,{providers:O,activeRequests:l.activeRequests||[],lastProvider:((c=(E=l.recentRequests)==null?void 0:E[0])==null?void 0:c.provider)||"",errorProvider:l.errorProvider||""}),e.jsx(pe,{requests:l.recentRequests||[]})]}),p?R:e.jsx(ce,{period:T,lastRequestTime:(C=(w=l==null?void 0:l.recentRequests)==null?void 0:w[0])==null?void 0:C.timestamp}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("select",{value:y,onChange:m=>h(m.target.value),className:"w-full rounded-lg border border-border bg-surface px-3 py-1.5 text-sm font-medium text-text-main focus:outline-none focus:ring-2 focus:ring-primary/50 sm:w-auto",style:{colorScheme:"auto"},children:ve.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))}),e.jsxs("div",{className:"grid grid-cols-2 items-center gap-1 rounded-lg border border-border bg-bg-subtle p-1 sm:flex",children:[e.jsx("button",{onClick:()=>L("costs"),className:`px-3 py-1 rounded-md text-sm font-medium transition-colors ${N==="costs"?"bg-primary text-white shadow-sm":"text-text-muted hover:text-text hover:bg-bg-hover"}`,children:"Costs"}),e.jsx("button",{onClick:()=>L("tokens"),className:`px-3 py-1 rounded-md text-sm font-medium transition-colors ${N==="tokens"?"bg-primary text-white shadow-sm":"text-text-muted hover:text-text hover:bg-bg-hover"}`,children:"Tokens"})]})]}),p?R:S&&e.jsx(xe,{title:"",columns:S.columns,groupedData:S.groupedData,tableType:y,sortBy:o,sortOrder:n,onToggleSort:$,viewMode:N,storageKey:S.storageKey,renderSummaryCells:S.renderSummaryCells,renderDetailCells:S.renderDetailCells,emptyMessage:S.emptyMessage})]})]})}function we(){const[s,t]=x.useState([]),[r,a]=x.useState(!0),[i,o]=x.useState(!0);x.useEffect(()=>{n()},[]),x.useEffect(()=>{let l;return i&&(l=setInterval(()=>{n(!1)},3e3)),()=>clearInterval(l)},[i]);const n=async(l=!0)=>{l&&a(!0);try{const b=await fetch("/api/usage/request-logs");if(b.ok){const p=await b.json();t(p)}}catch(b){console.error("Failed to fetch logs:",b)}finally{l&&a(!1)}};return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Request Logs"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("label",{className:"text-sm font-medium text-text-muted flex items-center gap-2 cursor-pointer",children:[e.jsx("span",{children:"Auto Refresh (3s)"}),e.jsx("div",{onClick:()=>o(!i),className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus:outline-none ${i?"bg-primary":"bg-bg-subtle border border-border"}`,children:e.jsx("span",{className:`inline-block h-3 w-3 transform rounded-full bg-white transition-transform ${i?"translate-x-5":"translate-x-1"}`})})]})})]}),e.jsx(V,{className:"overflow-hidden bg-black/5 dark:bg-black/20",children:e.jsx("div",{className:"p-0 overflow-x-auto max-h-[600px] overflow-y-auto font-mono text-xs",children:r&&s.length===0?e.jsx("div",{className:"p-8 text-center text-text-muted",children:"Loading logs..."}):s.length===0?e.jsx("div",{className:"p-8 text-center text-text-muted",children:"No logs recorded yet."}):e.jsxs("table",{className:"w-full text-left border-collapse whitespace-nowrap",children:[e.jsx("thead",{className:"sticky top-0 bg-bg-subtle border-b border-border z-10",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"DateTime"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Model"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Provider"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Account"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"In"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Out"}),e.jsx("th",{className:"px-3 py-2",children:"Status"})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:s.map((l,b)=>{const p=l.split(" | ");if(p.length<7)return null;const j=p[6],f=j.includes("PENDING"),P=j.includes("FAILED"),y=j.includes("OK");return e.jsxs("tr",{className:`hover:bg-primary/5 transition-colors ${f?"bg-primary/5":""}`,children:[e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-text-muted",children:p[0]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border font-medium",children:p[1]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-bg-subtle border border-border text-[10px] uppercase font-bold",children:p[2]})}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border truncate max-w-[150px]",title:p[3],children:p[3]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-right text-primary",children:p[4]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-right text-success",children:p[5]}),e.jsx("td",{className:`px-3 py-1.5 font-bold ${y?"text-success":P?"text-error":"text-primary animate-pulse"}`,children:j})]},b)})})]})})}),e.jsx("div",{className:"text-[10px] text-text-muted italic",children:"Logs are loaded from the request history database."})]})}function Z({options:s=[],value:t,onChange:r,size:a="md",className:i}){const o={sm:"h-7 text-xs",md:"h-9 text-sm",lg:"h-11 text-base"};return e.jsx("div",{className:k("inline-flex items-center p-1 rounded-[10px] overflow-x-auto","bg-surface-2",i),children:s.map(n=>e.jsxs("button",{onClick:()=>r(n.value),className:k("shrink-0 px-4 rounded-[8px] font-medium transition-all",o[a],t===n.value?"bg-surface text-text-main shadow-sm":"text-text-muted hover:text-text-main"),children:[n.icon&&e.jsx("span",{className:"material-symbols-outlined text-[16px] mr-1.5",children:n.icon}),n.label]},n.value))})}function ke({isOpen:s,onClose:t,title:r,children:a,width:i="md",className:o}){const n={sm:"w-[400px]",md:"w-[500px]",lg:"w-[600px]",xl:"w-[800px]",full:"w-full"};return x.useEffect(()=>(s?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[s]),x.useEffect(()=>{const l=b=>{b.key==="Escape"&&s&&t()};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[s,t]),s?e.jsxs("div",{className:"fixed inset-0 z-50",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[2px] fade-in cursor-pointer",onClick:t,"aria-hidden":"true"}),e.jsxs("div",{className:k("absolute right-0 top-0 h-full bg-surface flex flex-col","shadow-[var(--shadow-elev)]","slide-in-right","border-l border-border-subtle",n[i]||n.md,o),children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-border-subtle flex-shrink-0",children:[e.jsx("div",{className:"flex items-center gap-3",children:r&&e.jsx("h2",{className:"text-lg font-semibold text-text-main",children:r})}),e.jsx("button",{type:"button",onClick:t,className:"p-1.5 rounded-[10px] text-text-muted hover:bg-surface-2 hover:text-text-main transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 custom-scrollbar",children:a})]})]}):null}function Se({currentPage:s,pageSize:t,totalItems:r,onPageChange:a,onPageSizeChange:i,className:o}){const n=Math.ceil(r/t),l=r>0?(s-1)*t+1:0,b=Math.min(s*t,r),j=(()=>{const f=[];let y=Math.max(1,s-2),h=Math.min(n,y+5-1);h-y+1<5&&(y=Math.max(1,h-5+1));for(let N=y;N<=h;N++)f.push(N);return f})();return e.jsxs("div",{className:k("flex flex-col sm:flex-row items-center justify-between gap-4 py-4 px-2",o),children:[r>0&&e.jsxs("div",{className:"text-sm text-text-muted",children:["Showing ",e.jsx("span",{className:"font-medium text-text-main",children:l})," to"," ",e.jsx("span",{className:"font-medium text-text-main",children:b})," of"," ",e.jsx("span",{className:"font-medium text-text-main",children:r})," results"]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2 sm:gap-4",children:[i&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-text-muted",children:"Rows:"}),e.jsx("select",{value:t,onChange:f=>i(Number(f.target.value)),className:k("h-9 rounded-lg border border-black/10 dark:border-white/10 bg-surface","text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20","cursor-pointer"),style:{colorScheme:"auto"},children:[10,20,50].map(f=>e.jsx("option",{value:f,children:f},f))})]}),n>1&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(q,{variant:"outline",size:"sm",onClick:()=>a(s-1),disabled:s===1,className:"w-9 px-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"chevron_left"})}),j[0]>1&&e.jsxs(e.Fragment,{children:[e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>a(1),className:"w-9 px-0 hidden sm:inline-flex",children:"1"}),j[0]>2&&e.jsx("span",{className:"text-text-muted px-1 hidden sm:inline",children:"..."})]}),j.map(f=>e.jsx(q,{variant:s===f?"primary":"ghost",size:"sm",onClick:()=>a(f),className:k("w-9 px-0",s===f?"inline-flex":"hidden sm:inline-flex"),children:f},f)),j[j.length-1]<n&&e.jsxs(e.Fragment,{children:[j[j.length-1]<n-1&&e.jsx("span",{className:"text-text-muted px-1 hidden sm:inline",children:"..."}),e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>a(n),className:"w-9 px-0 hidden sm:inline-flex",children:n})]}),e.jsx(q,{variant:"outline",size:"sm",onClick:()=>a(s+1),disabled:s===n,className:"w-9 px-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"chevron_right"})})]})]})]})}let z=null,U=null;async function Ce(){if(z&&U)return{providerNameCache:z,providerNodesCache:U};const r=(await(await fetch("/api/provider-nodes")).json()).nodes||[];U={};for(const a of r)U[a.id]=a.name;return z={...Y,...U},{providerNameCache:z,providerNodesCache:U}}function ee(s,t){if(!s||!t)return s;const r=t[s];if(typeof r=="string")return r;if(r!=null&&r.name)return r.name;const a=oe(s)||Y[s];return(a==null?void 0:a.name)||s}function B({title:s,children:t,defaultOpen:r=!1,icon:a=null}){const[i,o]=x.useState(r);return e.jsxs("div",{className:"border border-black/5 dark:border-white/5 rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"w-full flex items-center justify-between p-3 bg-black/[0.02] dark:bg-white/[0.02] hover:bg-black/[0.04] dark:hover:bg-white/[0.04] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[a&&e.jsx("span",{className:"material-symbols-outlined text-[18px] text-text-muted",children:a}),e.jsx("span",{className:"font-semibold text-sm text-text-main",children:s})]}),e.jsx("span",{className:k("material-symbols-outlined text-[20px] text-text-muted transition-transform duration-200",i?"rotate-90":""),children:"chevron_right"})]}),i&&e.jsx("div",{className:"p-4 border-t border-black/5 dark:border-white/5",children:t})]})}function te(s){const t=(s==null?void 0:s.prompt_tokens)||(s==null?void 0:s.input_tokens)||0,r=(s==null?void 0:s.cached_tokens)||(s==null?void 0:s.cache_read_input_tokens)||0;return t<r?r:t}function De(){var T,F,$,S,R,E;const[s,t]=x.useState([]),[r,a]=x.useState({page:1,pageSize:20,totalItems:0,totalPages:0}),[i,o]=x.useState(!1),[n,l]=x.useState(null),[b,p]=x.useState(!1),[j,f]=x.useState([]),[P,y]=x.useState(null),[h,N]=x.useState({provider:"",startDate:"",endDate:""}),L=x.useCallback(async()=>{try{const w=await(await fetch("/api/usage/providers")).json();f(w.providers||[]);const C=await Ce();y(C.providerNameCache)}catch(c){console.error("Failed to fetch providers:",c)}},[]),O=x.useCallback(async()=>{o(!0);try{const c=new URLSearchParams({page:r.page.toString(),pageSize:r.pageSize.toString()});h.provider&&c.append("provider",h.provider),h.startDate&&c.append("startDate",h.startDate),h.endDate&&c.append("endDate",h.endDate);const C=await(await fetch(`/api/usage/request-details?${c}`)).json();t(C.details||[]),a(m=>({...m,...C.pagination}))}catch(c){console.error("Failed to fetch request details:",c)}finally{o(!1)}},[r.page,r.pageSize,h]);x.useEffect(()=>{L()},[L]),x.useEffect(()=>{O()},[O]);const J=c=>{l(c),p(!0)},G=c=>{a(w=>({...w,page:c}))},W=c=>{a(w=>({...w,pageSize:c,page:1}))},A=()=>{N({provider:"",startDate:"",endDate:""})};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6",children:[e.jsx(V,{padding:"md",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"provider-filter",className:"text-sm font-medium text-text-main",children:"Provider"}),e.jsxs("select",{id:"provider-filter",value:h.provider,onChange:c=>N({...h,provider:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20","w-full min-w-0 cursor-pointer"),style:{colorScheme:"auto"},children:[e.jsx("option",{value:"",children:"All Providers"}),j.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"start-date-filter",className:"text-sm font-medium text-text-main",children:"Start Date"}),e.jsx("input",{id:"start-date-filter",type:"datetime-local",value:h.startDate,onChange:c=>N({...h,startDate:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","w-full min-w-0 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"end-date-filter",className:"text-sm font-medium text-text-main",children:"End Date"}),e.jsx("input",{id:"end-date-filter",type:"datetime-local",value:h.endDate,onChange:c=>N({...h,endDate:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","w-full min-w-0 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:col-span-2 lg:col-span-1",children:[e.jsx("span",{className:"hidden text-sm font-medium text-text-main opacity-0 lg:block","aria-hidden":"true",children:"Clear"}),e.jsx(q,{variant:"ghost",onClick:A,disabled:!h.provider&&!h.startDate&&!h.endDate,className:"w-full",children:"Clear Filters"})]})]})}),e.jsxs(V,{padding:"none",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[880px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5",children:[e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Timestamp"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Model"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Provider"}),e.jsx("th",{className:"text-right p-4 text-sm font-semibold text-text-main",children:"Input Tokens"}),e.jsx("th",{className:"text-right p-4 text-sm font-semibold text-text-main",children:"Output Tokens"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Latency"}),e.jsx("th",{className:"text-center p-4 text-sm font-semibold text-text-main",children:"Action"})]})}),e.jsx("tbody",{children:i?e.jsx("tr",{children:e.jsx("td",{colSpan:"7",className:"p-8 text-center text-text-muted",children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[20px]",children:"progress_activity"}),"Loading..."]})})}):s.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:"7",className:"p-8 text-center text-text-muted",children:"No request details found"})}):s.map((c,w)=>{var C,m,v,d;return e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5 last:border-b-0 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"whitespace-nowrap p-4 text-sm text-text-main",children:new Date(c.timestamp).toLocaleString()}),e.jsx("td",{className:"max-w-[260px] truncate p-4 font-mono text-sm text-text-main",children:c.model}),e.jsx("td",{className:"max-w-[180px] truncate p-4 text-sm text-text-main",children:e.jsx("span",{className:"font-medium",children:ee(c.provider,P)})}),e.jsx("td",{className:"p-4 text-sm text-text-main text-right font-mono",children:te(c.tokens).toLocaleString()}),e.jsx("td",{className:"p-4 text-sm text-text-main text-right font-mono",children:((m=(C=c.tokens)==null?void 0:C.completion_tokens)==null?void 0:m.toLocaleString())||0}),e.jsx("td",{className:"p-4 text-sm text-text-muted",children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{children:["TTFT: ",e.jsxs("span",{className:"font-mono",children:[((v=c.latency)==null?void 0:v.ttft)||0,"ms"]})]}),e.jsxs("div",{children:["Total: ",e.jsxs("span",{className:"font-mono",children:[((d=c.latency)==null?void 0:d.total)||0,"ms"]})]})]})}),e.jsx("td",{className:"p-4 text-center",children:e.jsx(q,{variant:"outline",size:"sm",onClick:()=>J(c),children:"Detail"})})]},`${c.id}-${w}`)})})]})}),!i&&s.length>0&&e.jsx("div",{className:"border-t border-black/5 dark:border-white/5",children:e.jsx(Se,{currentPage:r.page,pageSize:r.pageSize,totalItems:r.totalItems,onPageChange:G,onPageSizeChange:W})})]}),e.jsx(ke,{isOpen:b,onClose:()=>p(!1),title:"Request Details",width:"lg",children:n&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-4 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"ID:"})," ",e.jsx("span",{className:"break-all font-mono text-text-main",children:n.id})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Timestamp:"})," ",e.jsx("span",{className:"text-text-main",children:new Date(n.timestamp).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Provider:"})," ",e.jsx("span",{className:"text-text-main font-medium",children:ee(n.provider,P)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Model:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:n.model})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Status:"})," ",e.jsx("span",{className:k("font-medium",n.status==="success"?"text-green-600":"text-red-600"),children:n.status})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Latency:"})," ",e.jsxs("span",{className:"text-text-main font-mono",children:["TTFT ",((T=n.latency)==null?void 0:T.ttft)||0,"ms / Total ",((F=n.latency)==null?void 0:F.total)||0,"ms"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Input Tokens:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:te(n.tokens).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Output Tokens:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:((S=($=n.tokens)==null?void 0:$.completion_tokens)==null?void 0:S.toLocaleString())||0})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(B,{title:"1. Client Request (Input)",defaultOpen:!0,icon:"input",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:JSON.stringify(n.request,null,2)})}),n.providerRequest&&e.jsx(B,{title:"2. Provider Request (Translated)",icon:"translate",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:JSON.stringify(n.providerRequest,null,2)})}),n.providerResponse&&e.jsx(B,{title:"3. Provider Response (Raw)",icon:"data_object",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:typeof n.providerResponse=="object"?JSON.stringify(n.providerResponse,null,2):n.providerResponse})}),e.jsxs(B,{title:"4. Client Response (Final)",defaultOpen:!0,icon:"output",children:[((R=n.response)==null?void 0:R.thinking)&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("h4",{className:"font-semibold text-text-main mb-2 flex items-center gap-2 text-xs uppercase tracking-wide opacity-70",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"psychology"}),"Thinking Process"]}),e.jsx("pre",{className:"max-h-[200px] max-w-full overflow-auto rounded-lg border border-amber-200 bg-amber-50 p-3 font-mono text-xs text-amber-900 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-100 sm:p-4",children:n.response.thinking})]}),e.jsx("h4",{className:"font-semibold text-text-main mb-2 text-xs uppercase tracking-wide opacity-70",children:"Content"}),e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:((E=n.response)==null?void 0:E.content)||"[No content]"})]})]})]})})]})}const Te=[{value:"today",label:"Today"},{value:"24h",label:"24h"},{value:"7d",label:"7D"},{value:"30d",label:"30D"},{value:"60d",label:"60D"}];function Ee(){return e.jsx(x.Suspense,{fallback:e.jsx(ae,{}),children:e.jsx(Pe,{})})}function Pe(){const[s]=re(),t=se(),[r,a]=x.useState("today"),i=s.get("tab"),o=i&&["overview","logs","details"].includes(i)?i:"overview",n=l=>{if(l===o)return;const b=new URLSearchParams(s);b.set("tab",l),t(`/dashboard/usage?${b.toString()}`,{scroll:!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 flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(Z,{options:[{value:"overview",label:"Overview"},{value:"details",label:"Details"}],value:o,onChange:n,className:"w-full sm:w-auto"}),o==="overview"&&e.jsx(Z,{options:Te,value:r,onChange:a,size:"sm",className:"w-full sm:w-auto"})]}),o==="overview"&&e.jsx(x.Suspense,{fallback:e.jsx(ae,{}),children:e.jsx(Ne,{period:r,setPeriod:a,hidePeriodSelector:!0})}),o==="logs"&&e.jsx(we,{}),o==="details"&&e.jsx(De,{})]})}export{Ee as default};