@fudrouter/fsrouter 0.6.107 → 0.6.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/routes/db/info/route.js +22 -0
- package/package.json +1 -1
- package/public/.vite/manifest.json +85 -85
- package/public/assets/EndpointPageClient.BN-D__UM.js +6 -0
- package/public/assets/Loading.BoU3gy5K.js +1 -0
- package/public/assets/NoAuthProxyCard.CLW2-XwE.js +89 -0
- package/public/assets/index.BO_pNnMt.js +89 -0
- package/public/assets/page.-P08pALK.js +6 -0
- package/public/assets/page.-PU2bgJe.js +1 -0
- package/public/assets/page.2bfZgPuP.js +1 -0
- package/public/assets/page.Asf9tesx.js +1 -0
- package/public/assets/page.B11lN3QC.js +1 -0
- package/public/assets/page.B1ZhgC-Y.js +1 -0
- package/public/assets/page.B28QUiM4.js +1 -0
- package/public/assets/page.BBnpNaQh.js +6 -0
- package/public/assets/page.BOy_Vt2f.js +1 -0
- package/public/assets/page.BRDONwuI.js +1 -0
- package/public/assets/page.BWFxAlAj.js +1 -0
- package/public/assets/page.BebFlAF6.js +1 -0
- package/public/assets/page.BqxsFxH_.js +2 -0
- package/public/assets/page.C1Z5-h5h.js +1 -0
- package/public/assets/page.CIxYSsJm.js +1 -0
- package/public/assets/page.CQLGTJxs.js +1 -0
- package/public/assets/page.CTO5ojlP.js +1 -0
- package/public/assets/page.CTx0rdSY.js +1 -0
- package/public/assets/page.CXAgJ2hd.js +1 -0
- package/public/assets/page.CdVrDM5I.js +1 -0
- package/public/assets/page.CgidHjOu.js +1 -0
- package/public/assets/page.CqPzqV4I.js +7 -0
- package/public/assets/page.Cr-bxDIh.js +4 -0
- package/public/assets/page.CsL3JXbA.js +1 -0
- package/public/assets/page.D6eEvzRr.js +5 -0
- package/public/assets/page.DHyqPTHy.js +1 -0
- package/public/assets/page.DS5iFEwr.js +31 -0
- package/public/assets/page.Dre9jdlU.js +1 -0
- package/public/assets/page.IyBPROCc.js +1 -0
- package/public/assets/page.KoOCODPg.js +5 -0
- package/public/assets/page.MP_9jcAE.js +1 -0
- package/public/assets/page.WAG7HQOU.js +2 -0
- package/public/assets/page.XKedaymF.js +1 -0
- package/public/assets/page.ZZHz9al1.js +64 -0
- package/public/assets/page.alTMqTdj.js +1 -0
- package/public/assets/page.tpebkgG7.js +1 -0
- package/public/assets/page.xIh7b02j.js +23 -0
- package/public/index.html +4 -4
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as ot,j as e,B as i,M as I,C as lt}from"./index.BO_pNnMt.js";import{b as l}from"./router.Cjj1--8t.js";import{C as Pe,B as k,T as ie,I as y}from"./NoAuthProxyCard.CLW2-XwE.js";import{C as Se}from"./Loading.BoU3gy5K.js";import"./zustand.akaTi5uX.js";function at(x){return x==="active"?"success":x==="error"?"error":"default"}function nt(x){if(!x)return"Never";const W=new Date(x);return Number.isNaN(W.getTime())?"Never":W.toLocaleString()}function ce(x={}){return{name:x.name||"",proxyUrl:x.proxyUrl||"",noProxy:x.noProxy||"",isActive:x.isActive!==!1,strictProxy:x.strictProxy===!0}}function ht(){const[x,W]=l.useState([]),[De,A]=l.useState(!1),[$,B]=l.useState(""),[b,L]=l.useState([]),[E,Y]=l.useState(null),[c,U]=l.useState([]),[Te,Ie]=l.useState(!0),[Ae,K]=l.useState(!1),[$e,Q]=l.useState(!1),[Ee,de]=l.useState(!1),[Ue,xe]=l.useState(!1),[Oe,me]=l.useState(!1),[O,M]=l.useState(!1),[V,he]=l.useState(null),[u,C]=l.useState(ce()),[X,ue]=l.useState(""),[F,Z]=l.useState({vercelToken:"",projectName:"vercel-relay"}),[j,_]=l.useState({accountId:"",apiToken:"",projectName:"cloudflare-relay"}),[N,q]=l.useState({denoToken:"",orgDomain:"",projectName:""}),[R,pe]=l.useState(!1),[J,fe]=l.useState(!1),[p,S]=l.useState(!1),[ee,ye]=l.useState(null),[h,H]=l.useState([]),[v,ge]=l.useState(!1),[be,te]=l.useState({current:0,total:0}),[z,D]=l.useState(!1),[g,w]=l.useState(null),se=l.useRef(null),n=ot();l.useEffect(()=>{const t=s=>{se.current&&!se.current.contains(s.target)&&M(!1)};return O&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[O]);const f=l.useCallback(async()=>{try{const t=await fetch("/api/proxy-pools?includeUsage=true",{cache:"no-store"}),s=await t.json();t.ok&&U(s.proxyPools||[])}catch(t){console.log("Error fetching proxy pools:",t)}finally{Ie(!1)}},[]),G=l.useCallback(async()=>{try{const t=await fetch("/api/proxy-combos",{cache:"no-store"}),s=await t.json();t.ok&&W(s.combos||[])}catch{}},[]);l.useEffect(()=>{f(),G()},[f,G]);const je=()=>{he(null),C(ce())},ve=()=>{je(),K(!0)},Me=t=>{he(t),C(ce(t)),K(!0)},re=()=>{K(!1),je()},Fe=async()=>{const t={name:u.name.trim(),proxyUrl:u.proxyUrl.trim(),noProxy:u.noProxy.trim(),isActive:u.isActive===!0,strictProxy:u.strictProxy===!0};if(!(!t.name||!t.proxyUrl)){pe(!0);try{const s=!!V,r=await fetch(s?`/api/proxy-pools/${V.id}`:"/api/proxy-pools",{method:s?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(r.ok)await f(),re(),n.success(V?"Proxy pool updated":"Proxy pool created");else{const o=await r.json();n.error(o.error||"Failed to save proxy pool")}}catch(s){console.log("Error saving proxy pool:",s)}finally{pe(!1)}}},Re=async t=>{w({title:"Delete Proxy Pool",message:`Delete proxy pool "${t.name}"?`,onConfirm:async()=>{w(null);try{const s=await fetch(`/api/proxy-pools/${t.id}`,{method:"DELETE"});if(s.ok){U(o=>o.filter(a=>a.id!==t.id)),n.success("Proxy pool deleted");return}const r=await s.json();s.status===409?n.warning(`Cannot delete: ${r.boundConnectionCount||0} connection(s) are still using this pool.`):n.error(r.error||"Failed to delete proxy pool")}catch(s){console.log("Error deleting proxy pool:",s),n.error("Failed to delete proxy pool")}}})},ze=async t=>{ye(t);try{const s=await fetch(`/api/proxy-pools/${t}/test`,{method:"POST"}),r=await s.json();if(!s.ok){n.error(r.error||"Failed to test proxy");return}await f(),n.success(r.ok?"Proxy test passed":"Proxy test failed")}catch(s){console.log("Error testing proxy pool:",s),n.error("Failed to test proxy")}finally{ye(null)}},We=async t=>{const s=!t.isActive;U(r=>r.map(o=>o.id===t.id?{...o,isActive:s}:o));try{(await fetch(`/api/proxy-pools/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:s})})).ok||(U(o=>o.map(a=>a.id===t.id?{...a,isActive:t.isActive}:a)),n.error("Failed to update active state"))}catch(r){console.log("Error toggling active:",r),U(o=>o.map(a=>a.id===t.id?{...a,isActive:t.isActive}:a))}},oe=c.length>0&&h.length===c.length,Be=t=>H(s=>s.includes(t)?s.filter(r=>r!==t):[...s,t]),Le=()=>H(oe?[]:c.map(t=>t.id)),ke=()=>H([]),Ce=async t=>{const s=h.length>0?h:c.map(r=>r.id);if(s.length!==0){D(!0);try{let r=0,o=0;for(const a of s)try{(await fetch(`/api/proxy-pools/${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok?r+=1:o+=1}catch{o+=1}await f(),n.success(`${t?"Activated":"Deactivated"} ${r}${o?`, failed ${o}`:""}`)}finally{D(!1)}}},Ve=async()=>{h.length!==0&&w({title:"Delete Proxy Pools",message:`Delete ${h.length} proxy pool(s)?`,onConfirm:async()=>{w(null),D(!0);try{let t=0,s=0,r=0;for(const o of h)try{const a=await fetch(`/api/proxy-pools/${o}`,{method:"DELETE"});a.ok?t+=1:a.status===409?s+=1:r+=1}catch{r+=1}await f(),ke(),n.success(`Deleted ${t}${s?`, ${s} bound`:""}${r?`, ${r} failed`:""}`)}finally{D(!1)}}})},_e=async()=>{const t=h.length>0?c.filter(d=>h.includes(d.id)):c;if(t.length===0)return;ge(!0),te({current:0,total:t.length});let s=0;const r=[];let o=0;const a=10,m=[...t],P=async()=>{for(;m.length>0;){const d=m.shift();if(!d)break;try{const T=await fetch(`/api/proxy-pools/${d.id}/test`,{method:"POST"}),we=await T.json();T.ok&&we.ok?s+=1:r.push(d.id)}catch{r.push(d.id)}finally{o+=1,te({current:o,total:t.length})}}};await Promise.all(Array.from({length:Math.min(a,t.length)},P)),await f(),ge(!1),te({current:0,total:0}),r.length>0?w({title:"Disable Dead Proxies",message:`Alive: ${s}, Dead: ${r.length}.
|
|
2
|
+
|
|
3
|
+
Disable ${r.length} dead proxies?`,onConfirm:async()=>{w(null),D(!0);try{for(const d of r)try{await fetch(`/api/proxy-pools/${d}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:!1})})}catch{}await f(),n.success(`Disabled ${r.length} dead proxies`)}finally{D(!1)}}}):n.success(`Health check done. Alive: ${s}, Dead: ${r.length}`)};l.useEffect(()=>{H(t=>t.filter(s=>c.some(r=>r.id===s)))},[c]);const qe=()=>{ue(""),Q(!0)},Ne=()=>{J||Q(!1)},Je=()=>{Z({vercelToken:"",projectName:"vercel-relay"}),de(!0)},le=()=>{p||de(!1)},He=()=>{_({accountId:"",apiToken:"",projectName:"cloudflare-relay"}),xe(!0)},ae=()=>{p||xe(!1)},Ge=()=>{q({denoToken:"",orgDomain:"",projectName:""}),me(!0)},ne=()=>{p||me(!1)},Ye=async()=>{if(F.vercelToken.trim()){S(!0);try{const t=await fetch("/api/proxy-pools/vercel-deploy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)}),s=await t.json();t.ok?(await f(),le(),n.success(`Deployed: ${s.deployUrl}`)):n.error(s.error||"Deploy failed")}catch(t){console.log("Error deploying Vercel relay:",t),n.error("Deploy failed")}finally{S(!1)}}},Ke=async()=>{if(!(!j.accountId.trim()||!j.apiToken.trim())){S(!0);try{const t=await fetch("/api/proxy-pools/cloudflare-deploy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(j)}),s=await t.json();t.ok?(await f(),ae(),n.success(`Deployed: ${s.deployUrl}`)):n.error(s.error||"Deploy failed")}catch(t){console.log("Error deploying Cloudflare relay:",t),n.error("Deploy failed")}finally{S(!1)}}},Qe=async()=>{if(N.denoToken.trim()){S(!0);try{const t=await fetch("/api/proxy-pools/deno-deploy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)}),s=await t.json();t.ok?(await f(),ne(),n.success(`Deployed: ${s.deployUrl}`)):n.error(s.error||"Deploy failed")}catch(t){console.log("Error deploying Deno relay:",t),n.error("Deploy failed")}finally{S(!1)}}},Xe=t=>{const s=t.trim();if(!s)return null;if(s.includes("://")){const o=new URL(s),a=o.port?`${o.hostname}:${o.port}`:o.hostname;return{proxyUrl:o.toString(),name:`Imported ${a}`}}const r=s.split(":");if(r.length===4){const[o,a,m,P]=r;if(!o||!a||!m||!P)throw new Error("Invalid host:port:user:pass format");const d=`http://${encodeURIComponent(m)}:${encodeURIComponent(P)}@${o}:${a}`;return{proxyUrl:new URL(d).toString(),name:`Imported ${o}:${a}`}}throw new Error("Unsupported format")},Ze=async()=>{const t=X.split(/\r?\n/).map(o=>o.trim()).filter(Boolean);if(t.length===0){n.warning("Please paste at least one proxy line.");return}const s=[],r=[];if(t.forEach((o,a)=>{try{const m=Xe(o);m&&s.push({...m,lineNumber:a+1})}catch(m){r.push(`Line ${a+1}: ${m.message}`)}}),r.length>0){n.error(`Invalid proxy format:
|
|
4
|
+
${r.join(`
|
|
5
|
+
`)}`);return}fe(!0);try{const o=new Set(c.map(d=>`${(d.proxyUrl||"").trim()}|||${(d.noProxy||"").trim()}`));let a=0,m=0,P=0;for(const d of s){const T=`${d.proxyUrl}|||`;if(o.has(T)){m+=1;continue}(await fetch("/api/proxy-pools",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:d.name,proxyUrl:d.proxyUrl,noProxy:"",isActive:!0})})).ok?(a+=1,o.add(T)):P+=1}await f(),Q(!1),n.success(`Batch import completed: Created ${a}, Skipped ${m}, Failed ${P}`)}catch(o){console.log("Error batch importing proxies:",o),n.error("Batch import failed")}finally{fe(!1)}},et=l.useMemo(()=>c.filter(t=>t.isActive===!0).length,[c]);if(Te)return e.jsxs("div",{className:"mx-auto flex w-full max-w-5xl flex-col gap-4 px-1 sm:gap-6 sm:px-0",children:[e.jsx(Se,{}),e.jsx(Se,{})]});const tt=async()=>{if(!$.trim()||b.length===0)return;const t=E?"PUT":"POST",s=E?{id:E.id,name:$,poolIds:b}:{name:$,poolIds:b};await fetch("/api/proxy-combos",{method:t,headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),A(!1),B(""),L([]),Y(null),G()},st=async t=>{await fetch("/api/proxy-combos",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t})}),G()},rt=t=>{var s;return((s=c.find(r=>r.id===t))==null?void 0:s.name)||t.slice(0,8)};return e.jsxs("div",{className:"mx-auto flex w-full max-w-5xl flex-col gap-4 px-1 sm:gap-6 sm:px-0",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("h1",{className:"text-xl font-semibold sm:text-2xl",children:"Proxy Pools"})}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs("div",{className:"relative",ref:se,children:[e.jsxs(i,{size:"sm",variant:"secondary",icon:"rocket_launch",onClick:()=>M(!O),children:["Deploy Relay",e.jsx("span",{className:"material-symbols-outlined ml-1 text-[18px]",children:O?"expand_less":"expand_more"})]}),O&&e.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-48 rounded-xl border border-black/10 bg-white p-1 shadow-xl dark:border-white/10 dark:bg-zinc-900 sm:left-auto sm:right-0",children:[e.jsxs("button",{onClick:()=>{He(),M(!1)},className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-text-main transition-colors hover:bg-black/5 dark:hover:bg-white/5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-orange-500",children:"cloud"}),"Cloudflare Relay"]}),e.jsxs("button",{onClick:()=>{Je(),M(!1)},className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-text-main transition-colors hover:bg-black/5 dark:hover:bg-white/5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-blue-500",children:"cloud_upload"}),"Vercel Relay"]}),e.jsxs("button",{onClick:()=>{Ge(),M(!1)},className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-text-main transition-colors hover:bg-black/5 dark:hover:bg-white/5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-green-500",children:"terminal"}),"Deno Relay"]})]})]}),e.jsx(i,{size:"sm",variant:"secondary",icon:"upload",onClick:qe,children:"Batch Import"}),e.jsx(i,{size:"sm",icon:"add",onClick:ve,children:"Add Proxy Pool"})]})]}),e.jsxs(Pe,{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[c.length>0&&e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-text-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:oe,onChange:Le,className:"size-4 rounded border-black/20 dark:border-white/20"}),oe?"Unselect all":"Select all"]}),e.jsxs(k,{variant:"default",children:["Total: ",c.length]}),e.jsxs(k,{variant:"success",children:["Active: ",et]})]}),(h.length>0||v)&&e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2 rounded-lg border border-primary/30 bg-primary/5 px-3 py-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-primary",children:"checklist"}),e.jsx("span",{className:"text-xs font-medium text-primary",children:h.length>0?`${h.length} selected`:"All pools"}),e.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:[e.jsx(i,{size:"sm",icon:v?"progress_activity":"health_and_safety",onClick:_e,disabled:v||z||c.length===0,children:v?`Checking ${be.current}/${be.total}`:"Health Check"}),h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(i,{size:"sm",variant:"secondary",icon:"toggle_on",onClick:()=>Ce(!0),disabled:z||v,children:"Activate"}),e.jsx(i,{size:"sm",variant:"secondary",icon:"toggle_off",onClick:()=>Ce(!1),disabled:z||v,children:"Deactivate"}),e.jsx(i,{size:"sm",variant:"secondary",icon:"delete",onClick:Ve,disabled:z||v,children:"Delete"}),e.jsx(i,{size:"sm",variant:"ghost",onClick:ke,disabled:z||v,children:"Clear"})]})]})]}),c.length===0?e.jsxs("div",{className:"text-center py-10",children:[e.jsx("p",{className:"text-text-main font-medium mb-1",children:"No proxy pool entries yet"}),e.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Create a proxy pool entry, then assign it to connections."}),e.jsx(i,{icon:"add",onClick:ve,children:"Add Proxy Pool"})]}):e.jsx("div",{className:"flex flex-col divide-y divide-black/[0.04] dark:divide-white/[0.05]",children:c.map(t=>e.jsxs("div",{className:"flex flex-col gap-3 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0 flex-1",children:[e.jsx("input",{type:"checkbox",checked:h.includes(t.id),onChange:()=>Be(t.id),className:"mt-1 size-4 shrink-0 rounded border-black/20 dark:border-white/20"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"min-w-0 max-w-full truncate text-sm font-medium sm:max-w-[18rem]",children:t.name}),e.jsx(k,{variant:at(t.testStatus),size:"sm",dot:!0,children:t.testStatus||"unknown"}),e.jsx(k,{variant:t.isActive?"success":"default",size:"sm",children:t.isActive?"active":"inactive"}),t.type==="vercel"&&e.jsx(k,{variant:"default",size:"sm",children:"vercel relay"}),t.type==="cloudflare"&&e.jsx(k,{variant:"default",size:"sm",children:"cloudflare relay"}),e.jsxs(k,{variant:"default",size:"sm",children:[t.boundConnectionCount||0," bound"]})]}),e.jsx("p",{className:"text-xs text-text-muted truncate mt-1",children:t.proxyUrl}),t.noProxy?e.jsxs("p",{className:"text-xs text-text-muted truncate",children:["No proxy: ",t.noProxy]}):null,e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:["Last tested: ",nt(t.lastTestedAt),t.lastError?` · ${t.lastError}`:""]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(ie,{size:"sm",checked:t.isActive===!0,onChange:()=>We(t),title:t.isActive?"Disable":"Enable"}),e.jsx("button",{onClick:()=>ze(t.id),className:"p-2 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-primary",title:"Test proxy",disabled:ee===t.id,children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",style:ee===t.id?{animation:"spin 1s linear infinite"}:void 0,children:ee===t.id?"progress_activity":"science"})}),e.jsx("button",{onClick:()=>Me(t),className:"p-2 rounded hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-primary",title:"Edit",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),e.jsx("button",{onClick:()=>Re(t),className:"p-2 rounded hover:bg-red-500/10 text-red-500",title:"Delete",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]},t.id))})]}),e.jsx(I,{isOpen:$e,title:"Batch Import Proxies",onClose:Ne,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-text-main mb-1 block",children:"Paste Proxy List (One per line)"}),e.jsx("textarea",{value:X,onChange:t=>ue(t.target.value),placeholder:`http://user:pass@127.0.0.1:7897
|
|
6
|
+
127.0.0.1:7897:user:pass`,className:"w-full min-h-[180px] py-2 px-3 text-sm text-text-main bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-md focus:ring-1 focus:ring-primary/30 focus:border-primary/50 focus:outline-none transition-all"}),e.jsx("p",{className:"text-xs text-text-muted mt-1",children:"Supported formats: protocol://user:pass@host:port, host:port:user:pass"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Ze,disabled:!X.trim()||J,children:J?"Importing...":"Import"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:Ne,disabled:J,children:"Cancel"})]})]})}),e.jsx(I,{isOpen:Ee,title:"Deploy Vercel Relay",onClose:le,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg bg-blue-500/5 border border-blue-500/10 p-3 flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-sm text-text-main font-medium",children:"What is Vercel Relay?"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Deploys an edge relay function to Vercel. All AI provider requests will be forwarded through Vercel's edge network, masking your real IP from providers."}),e.jsxs("ul",{className:"text-xs text-text-muted list-disc pl-4 space-y-0.5",children:[e.jsx("li",{children:"Your IP is replaced by Vercel's dynamic edge IPs (hundreds of IPs across 20+ global regions)"}),e.jsx("li",{children:"Vercel serves millions of apps — providers can't block Vercel IPs without affecting legitimate traffic"}),e.jsx("li",{children:"Free tier: 100GB bandwidth/month, 500K edge invocations"}),e.jsx("li",{children:"Deploy multiple relays on different accounts for more IP diversity"})]})]}),e.jsx(y,{label:"Vercel API Token",value:F.vercelToken,onChange:t=>Z(s=>({...s,vercelToken:t.target.value})),placeholder:"your-vercel-api-token",hint:e.jsxs(e.Fragment,{children:["Token is used once for deployment and not stored. ",e.jsx("a",{href:"https://vercel.com/account/tokens",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Get token →"})]}),type:"password"}),e.jsx(y,{label:"Project Name",value:F.projectName,onChange:t=>Z(s=>({...s,projectName:t.target.value})),placeholder:"my-relay",hint:"Unique name for your Vercel project. Leave empty for auto-generated name."}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Ye,disabled:!F.vercelToken.trim()||p,children:p?"Deploying... (may take ~1 min)":"Deploy"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:le,disabled:p,children:"Cancel"})]})]})}),e.jsx(I,{isOpen:Ue,title:"Deploy Cloudflare Relay",onClose:ae,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg bg-orange-500/5 border border-orange-500/10 p-3 flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-sm text-text-main font-medium",children:"What is Cloudflare Relay?"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Deploys a Cloudflare Worker as a proxy relay. All AI provider requests will be forwarded through Cloudflare's global edge network."}),e.jsxs("ul",{className:"text-xs text-text-muted list-disc pl-4 space-y-0.5",children:[e.jsx("li",{children:"High performance global routing and IP masking via Cloudflare Workers"}),e.jsx("li",{children:"Free tier: 100,000 requests per day"}),e.jsx("li",{children:"Requires Cloudflare Account ID and a Workers API Token (Edit Workers permission)"})]}),e.jsxs("div",{className:"mt-2 pt-2 border-t border-orange-500/10 text-xs text-text-muted",children:[e.jsx("p",{className:"font-medium text-text-main mb-1",children:"How to generate your API Token:"}),e.jsxs("ol",{className:"list-decimal pl-4 space-y-0.5",children:[e.jsxs("li",{children:["Go to ",e.jsx("b",{children:"My Profile"})," → ",e.jsx("b",{children:"API Tokens"})," → ",e.jsx("b",{children:"Create Token"})]}),e.jsxs("li",{children:["Scroll down to ",e.jsx("b",{children:"Custom Token"})," and click ",e.jsx("b",{children:"Get started"})]}),e.jsxs("li",{children:["Under ",e.jsx("b",{children:"Permissions"}),": Account | Workers Scripts | Edit"]}),e.jsxs("li",{children:["Under ",e.jsx("b",{children:"Account Resources"}),": Include | Account | ",e.jsx("i",{children:"Your Account Name"})]}),e.jsxs("li",{children:["Click ",e.jsx("b",{children:"Continue to summary"})," → ",e.jsx("b",{children:"Create Token"})]})]})]})]}),e.jsx(y,{label:"Account ID",value:j.accountId,onChange:t=>_(s=>({...s,accountId:t.target.value})),placeholder:"your-cloudflare-account-id",hint:e.jsx(e.Fragment,{children:"Found on the right side of the Cloudflare dashboard overview page."})}),e.jsx(y,{label:"API Token",value:j.apiToken,onChange:t=>_(s=>({...s,apiToken:t.target.value})),placeholder:"your-cloudflare-api-token",hint:e.jsxs(e.Fragment,{children:['Requires "Workers Scripts: Edit" permission. ',e.jsx("a",{href:"https://dash.cloudflare.com/profile/api-tokens",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Get token →"})]}),type:"password"}),e.jsx(y,{label:"Worker Name",value:j.projectName,onChange:t=>_(s=>({...s,projectName:t.target.value})),placeholder:"my-relay",hint:"Unique name for your Cloudflare Worker. Leave empty for auto-generated name."}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Ke,disabled:!j.accountId.trim()||!j.apiToken.trim()||p,children:p?"Deploying...":"Deploy Worker"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:ae,disabled:p,children:"Cancel"})]})]})}),e.jsx(I,{isOpen:Oe,title:"Deploy Deno Relay",onClose:ne,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 p-3 flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-sm text-text-main font-medium",children:"What is Deno Relay?"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Deploys a relay worker to Deno Deploy's global edge network. All AI provider requests are forwarded through Deno's edge, masking your real IP."}),e.jsxs("ul",{className:"text-xs text-text-muted list-disc pl-4 space-y-0.5",children:[e.jsx("li",{children:"Deno Deploy v2 runs on a high-performance global edge network"}),e.jsx("li",{children:"Free tier: 1M requests & 100GiB outbound traffic per month"}),e.jsx("li",{children:"No per-request CPU time limits (unlike Vercel/Cloudflare)"}),e.jsx("li",{children:"Support up to 20 active apps & 50 custom domains"}),e.jsx("li",{children:"Deploy multiple relays for maximum IP diversity"})]}),e.jsxs("div",{className:"mt-2 pt-2 border-t border-black/10 dark:border-white/10 text-xs text-text-muted",children:[e.jsx("p",{className:"font-medium text-text-main mb-1",children:"How to generate API token:"}),e.jsxs("ol",{className:"list-decimal pl-4 space-y-0.5",children:[e.jsxs("li",{children:["Go to ",e.jsx("b",{children:"console.deno.com"})]}),e.jsxs("li",{children:["Select your ",e.jsx("b",{children:"Organization"})," → ",e.jsx("b",{children:"Settings"})," → ",e.jsx("b",{children:"Organization Tokens"})]}),e.jsxs("li",{children:["Create a ",e.jsx("b",{children:"Organization Token"})," (prefix ",e.jsx("b",{children:"ddo_"}),")"]})]})]})]}),e.jsx(y,{label:"Deno Deploy API Token",value:N.denoToken,onChange:t=>q(s=>({...s,denoToken:t.target.value})),placeholder:"ddo_xxxxxxxxxxxxxxxx",hint:e.jsx(e.Fragment,{children:"Token is used once for deployment, not stored. Found in Organization Settings."}),type:"password"}),e.jsx(y,{label:"Organization Domain",value:N.orgDomain,onChange:t=>q(s=>({...s,orgDomain:t.target.value})),placeholder:"your-org.deno.net",hint:"Organization's default domain. Your relay URL will be in the format: https://my-relay.your-org.deno.net"}),e.jsx(y,{label:"App Name",value:N.projectName,onChange:t=>q(s=>({...s,projectName:t.target.value})),placeholder:"deno-relay",hint:"Unique app name. Leave empty for auto-generated name."}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Qe,disabled:!N.denoToken.trim()||!N.orgDomain.trim()||p,children:p?"Deploying...":"Deploy Relay"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:ne,disabled:p,children:"Cancel"})]})]})}),e.jsx(I,{isOpen:Ae,title:V?"Edit Proxy Pool":"Add Proxy Pool",onClose:re,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(y,{label:"Name",value:u.name,onChange:t=>C(s=>({...s,name:t.target.value})),placeholder:"Office Proxy"}),e.jsx(y,{label:"Proxy URL",value:u.proxyUrl,onChange:t=>C(s=>({...s,proxyUrl:t.target.value})),placeholder:"http://127.0.0.1:7897"}),e.jsx(y,{label:"No Proxy",value:u.noProxy,onChange:t=>C(s=>({...s,noProxy:t.target.value})),placeholder:"localhost,127.0.0.1,.internal",hint:"Comma-separated hosts/domains to bypass proxy"}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border/50 p-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Active"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Inactive pools are ignored by runtime resolution."})]}),e.jsx(ie,{checked:u.isActive===!0,onChange:()=>C(t=>({...t,isActive:!t.isActive})),disabled:R})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border/50 p-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Strict Proxy"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Fail request if proxy is unreachable instead of falling back to direct."})]}),e.jsx(ie,{checked:u.strictProxy===!0,onChange:()=>C(t=>({...t,strictProxy:!t.strictProxy})),disabled:R})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(i,{fullWidth:!0,onClick:Fe,disabled:!u.name.trim()||!u.proxyUrl.trim()||R,children:R?"Saving...":"Save"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:re,disabled:R,children:"Cancel"})]})]})}),e.jsxs(Pe,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Proxy Combos"}),e.jsx("p",{className:"text-xs text-text-muted",children:"Round-robin rotation across multiple pools"})]}),e.jsx(i,{size:"sm",icon:"add",onClick:()=>{Y(null),B(""),L([]),A(!0)},children:"Add Combo"})]}),x.length===0?e.jsx("p",{className:"text-sm text-text-muted py-4 text-center",children:"No combos yet. Create one to rotate proxies automatically."}):e.jsx("div",{className:"space-y-2",children:x.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border border-border-subtle bg-surface hover:bg-surface/50",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium text-sm text-text-main",children:t.name}),e.jsx("p",{className:"text-xs text-text-muted mt-0.5",children:(t.poolIds||[]).map((s,r)=>e.jsxs("span",{children:[r>0?" → ":"",rt(s)]},s))})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-3",children:[e.jsxs(k,{variant:"success",size:"sm",children:[(t.poolIds||[]).length," pools"]}),e.jsx("button",{onClick:()=>{Y(t),B(t.name),L(t.poolIds||[]),A(!0)},className:"text-xs text-brand-400 hover:text-brand-300 cursor-pointer",children:"Edit"}),e.jsx("button",{onClick:()=>st(t.id),className:"text-xs text-red-400 hover:text-red-300 cursor-pointer",children:"Delete"})]})]},t.id))})]}),e.jsx(I,{isOpen:De,onClose:()=>A(!1),title:E?"Edit Combo":"Create Proxy Combo",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-text-muted block mb-1",children:"Combo Name"}),e.jsx(y,{value:$,onChange:t=>B(t.target.value),placeholder:"e.g. Free Proxy Round Robin"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-text-muted block mb-2",children:"Select Pools (click to toggle)"}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1 rounded-lg border border-border-subtle p-2",children:c.map(t=>e.jsxs("label",{className:`flex items-center gap-2 p-2 rounded cursor-pointer text-sm transition-colors ${b.includes(t.id)?"bg-primary/10 text-primary":"hover:bg-surface-2 text-text-main"}`,children:[e.jsx("input",{type:"checkbox",checked:b.includes(t.id),onChange:s=>{L(s.target.checked?[...b,t.id]:b.filter(r=>r!==t.id))},className:"rounded"}),t.name]},t.id))})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(i,{fullWidth:!0,onClick:tt,disabled:!$.trim()||b.length===0,children:E?"Save Changes":"Create Combo"}),e.jsx(i,{fullWidth:!0,variant:"ghost",onClick:()=>A(!1),children:"Cancel"})]})]})}),e.jsx(lt,{isOpen:!!g,onClose:()=>w(null),onConfirm:g==null?void 0:g.onConfirm,title:(g==null?void 0:g.title)||"Confirm",message:g==null?void 0:g.message,variant:"danger"})]})}export{ht as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as a}from"./index.BO_pNnMt.js";import{b as e}from"./router.Cjj1--8t.js";import{g as m}from"./machine.CagOtseJ.js";import{A as c}from"./EndpointPageClient.BN-D__UM.js";import"./zustand.akaTi5uX.js";import"./NoAuthProxyCard.CLW2-XwE.js";import"./Loading.BoU3gy5K.js";function h(){const[i,s]=e.useState(null),[n,r]=e.useState(!0);return e.useEffect(()=>{let t=!0;return m().then(o=>{t&&(s(o),r(!1))}).catch(()=>{t&&r(!1)}),()=>{t=!1}},[]),n?a.jsx("div",{className:"text-text-muted text-sm py-12 text-center",children:"Loading..."}):a.jsx(c,{machineId:i})}export{h as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as v,j as e,B as c,m as j}from"./index.BO_pNnMt.js";import{d as N,b as u,L as h}from"./router.Cjj1--8t.js";import{C as p,S as k,I as x,T as A}from"./NoAuthProxyCard.CLW2-XwE.js";import"./zustand.akaTi5uX.js";const P=Object.values(v).map(a=>({value:a.id,label:a.name})),S=Object.values(j).map(a=>({value:a.id,label:a.name}));function E(){const a=N(),[b,m]=u.useState(!1),[t,y]=u.useState({provider:"",authMethod:"api_key",apiKey:"",displayName:"",isActive:!0}),[s,n]=u.useState({}),i=(r,o)=>{y(l=>({...l,[r]:o})),s[r]&&n(l=>({...l,[r]:null}))},f=()=>{const r={};return t.provider||(r.provider="Please select a provider"),t.authMethod==="api_key"&&!t.apiKey&&(r.apiKey="API Key is required"),n(r),Object.keys(r).length===0},g=async r=>{if(r.preventDefault(),!!f()){m(!0);try{const o=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(o.ok)a("/dashboard/providers");else{const l=await o.json();n({submit:l.error||"Failed to create provider"})}}catch{n({submit:"An error occurred. Please try again."})}finally{m(!1)}}},d=v[t.provider];return e.jsxs("div",{className:"max-w-2xl mx-auto",children:[e.jsxs("div",{className:"mb-8",children:[e.jsxs(h,{to:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[e.jsx("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),"Back to Providers"]}),e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:"Add New Provider"}),e.jsx("p",{className:"text-text-muted mt-2",children:"Configure a new AI provider to use with your applications."})]}),e.jsx(p,{children:e.jsxs("form",{onSubmit:g,className:"flex flex-col gap-6",children:[e.jsx(k,{label:"Provider",options:P,value:t.provider,onChange:r=>i("provider",r.target.value),placeholder:"Select a provider",error:s.provider,required:!0}),d&&e.jsxs(p.Section,{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-lg flex items-center justify-center bg-bg border border-border",children:e.jsx("span",{className:"material-symbols-outlined text-xl",style:{color:d.color},children:d.icon})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:d.name}),e.jsx("p",{className:"text-sm text-text-muted",children:"Selected provider"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("label",{className:"text-sm font-medium",children:["Authentication Method ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("div",{className:"flex gap-3",children:S.map(r=>e.jsxs("button",{type:"button",onClick:()=>i("authMethod",r.value),className:`flex-1 flex items-center justify-center gap-2 p-4 rounded-lg border transition-all ${t.authMethod===r.value?"border-primary bg-primary/5 text-primary":"border-border hover:border-primary/50"}`,children:[e.jsx("span",{className:"material-symbols-outlined",children:r.value==="api_key"?"key":"lock"}),e.jsx("span",{className:"font-medium",children:r.label})]},r.value))})]}),t.authMethod==="api_key"&&e.jsx(x,{label:"API Key",type:"password",placeholder:"Enter your API key",value:t.apiKey,onChange:r=>i("apiKey",r.target.value),error:s.apiKey,hint:"Your API key will be encrypted and stored securely.",required:!0}),t.authMethod==="oauth2"&&e.jsxs(p.Section,{children:[e.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Connect your account using OAuth2 authentication."}),e.jsx(c,{type:"button",variant:"secondary",icon:"link",children:"Connect with OAuth2"})]}),e.jsx(x,{label:"Display Name",placeholder:"e.g., Production API, Dev Environment",value:t.displayName,onChange:r=>i("displayName",r.target.value),hint:"Optional. A friendly name to identify this configuration."}),e.jsx(A,{checked:t.isActive,onChange:r=>i("isActive",r),label:"Active",description:"Enable this provider for use in your applications"}),s.submit&&e.jsx("div",{className:"p-4 rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-red-600 dark:text-red-400 text-sm",children:s.submit}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t border-border",children:[e.jsx(h,{to:"/dashboard/providers",className:"flex-1",children:e.jsx(c,{type:"button",variant:"ghost",fullWidth:!0,children:"Cancel"})}),e.jsx(c,{type:"submit",loading:b,fullWidth:!0,className:"flex-1",children:"Create Provider"})]})]})})]})}export{E as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./index.BO_pNnMt.js";import{L as m,b as i}from"./router.Cjj1--8t.js";import{g as u}from"./machine.CagOtseJ.js";import{C as d}from"./NoAuthProxyCard.CLW2-XwE.js";import{C as r}from"./Loading.BoU3gy5K.js";import{C as p,M as h}from"./cliTools.CsdwAybi.js";import"./zustand.akaTi5uX.js";function f({tool:s}){return e.jsx(m,{to:"/dashboard/mitm",className:"block",children:e.jsx(d,{padding:"sm",className:"overflow-hidden hover:border-primary/50 transition-colors cursor-pointer",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:s.image,alt:s.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 items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:s.name}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-purple-500/10 text-purple-600 dark:text-purple-400 rounded-full",children:"MITM"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:s.description})]})]}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[20px]",children:"chevron_right"})]})})})}function j(s){return s?s.installed?s.hasFSRouter?{label:"Connected",cls:"bg-green-500/10 text-green-600 dark:text-green-400"}:{label:"Not configured",cls:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400"}:{label:"Not installed",cls:"bg-gray-500/10 text-gray-500"}:{label:"Unknown",cls:"bg-gray-500/10 text-gray-500"}}function N({toolId:s,tool:t,status:c}){const n=j(c);return e.jsx(m,{to:`/dashboard/cli-tools/${s}`,className:"block",children:e.jsx(d,{padding:"sm",className:"h-full overflow-hidden hover:border-primary/50 transition-colors cursor-pointer",children:e.jsx("div",{className:"flex h-full flex-col gap-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:t.image?e.jsx("img",{src:t.image,alt:t.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:o=>{o.target.style.display="none"}}):t.icon?e.jsx("span",{className:"material-symbols-outlined text-[28px]",style:{color:t.color},children:t.icon}):null}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"font-medium text-sm truncate",children:t.name}),e.jsx("span",{className:`inline-block mt-1 px-1.5 py-0.5 text-[10px] font-medium rounded-full ${n.cls}`,children:n.label})]}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[18px] shrink-0",children:"chevron_right"})]})})})})}const b="/api/cli-tools/all-statuses";function y({machineId:s}){const[t,c]=i.useState(!0),[n,o]=i.useState({});if(i.useEffect(()=>{let a=!0;return(async()=>{try{const l=await fetch(b);l.ok&&a&&o(await l.json())}catch(l){console.log("Error fetching tool statuses:",l)}finally{a&&c(!1)}})(),()=>{a=!1}},[]),t)return e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-4",children:[e.jsx(r,{}),e.jsx(r,{}),e.jsx(r,{}),e.jsx(r,{}),e.jsx(r,{}),e.jsx(r,{})]});const x=Object.entries(p),g=Object.entries(h);return e.jsxs("div",{className:"mx-auto flex w-full max-w-5xl flex-col gap-6 px-1 sm:px-0",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-4",children:x.map(([a,l])=>e.jsx(N,{toolId:a,tool:l,status:n[a]},a))}),e.jsxs("div",{className:"flex flex-col gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2 px-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-primary",children:"security"}),e.jsx("h2",{className:"text-sm font-semibold text-text-main",children:"MITM Tools"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-4",children:g.map(([a,l])=>e.jsx(f,{tool:l},a))})]})]})}function M(){const[s,t]=i.useState("");return i.useEffect(()=>{u().then(t)},[]),s?e.jsx(y,{machineId:s}):null}export{M as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as ae,j as e,B as _,b as Y,O as ve,F as ye,c as je,A as Ne,W as Ce,d as we,e as Te,P as re,M as ie,f as i}from"./index.BO_pNnMt.js";import{b as c,L as le}from"./router.Cjj1--8t.js";import{C as ne,B as P,T as oe,I as O,S as ke}from"./NoAuthProxyCard.CLW2-XwE.js";import{C as ee}from"./Loading.BoU3gy5K.js";import"./zustand.akaTi5uX.js";function Ae(r){if(!r)return null;const a=r.match(/\b([45]\d{2})\b/);return a?a[1]:"ERR"}function Ie(r){if(!r)return"";const a=Date.now()-new Date(r).getTime(),m=Math.floor(a/6e4);if(m<1)return"just now";if(m<60)return`${m}m ago`;const s=Math.floor(m/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}const te={available:{icon:"check_circle",color:"#22c55e",label:"Available"},cooldown:{icon:"schedule",color:"#f59e0b",label:"Cooldown"},unavailable:{icon:"error",color:"#ef4444",label:"Unavailable"},unknown:{icon:"help",color:"#6b7280",label:"Unknown"}};function Se(){const[r,a]=c.useState(null),[m,s]=c.useState(!0),[l,h]=c.useState(!1),[w,v]=c.useState(null),y=c.useRef(null),u=ae(),N=c.useCallback(async()=>{try{const x=await fetch("/api/models/availability");if(x.ok){const g=await x.json();a(g)}}catch{}finally{s(!1)}},[]);c.useEffect(()=>{N();const x=setInterval(N,3e4);return()=>clearInterval(x)},[N]),c.useEffect(()=>{const x=g=>{y.current&&!y.current.contains(g.target)&&h(!1)};return l&&document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[l]);const C=async(x,g)=>{v(`${x}:${g}`);try{(await fetch("/api/models/availability",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"clearCooldown",provider:x,model:g})})).ok?(u.success(`Cooldown cleared for ${g}`),await N()):u.error("Failed to clear cooldown")}catch{u.error("Failed to clear cooldown")}finally{v(null)}};if(m)return null;const p=(r==null?void 0:r.models)||[],j=((r==null?void 0:r.unavailableCount)||p.filter(x=>x.status!=="available").length)===0,k={};return p.forEach(x=>{if(x.status==="available")return;const g=x.provider||"unknown";k[g]||(k[g]=[]),k[g].push(x)}),e.jsx("div",{className:"relative",ref:y,children:l&&e.jsxs("div",{className:"absolute top-full right-0 mt-2 w-80 bg-surface border border-border rounded-xl shadow-2xl z-50 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-bg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",style:{color:j?"#22c55e":"#f59e0b"},children:j?"verified":"warning"}),e.jsx("span",{className:"text-sm font-semibold text-text-main",children:"Model Status"})]}),e.jsx("button",{onClick:N,className:"p-1 rounded-lg hover:bg-surface text-text-muted hover:text-text-main transition-colors",title:"Refresh",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"refresh"})})]}),e.jsx("div",{className:"px-4 py-3 max-h-60 overflow-y-auto",children:j?e.jsx("p",{className:"text-sm text-text-muted text-center py-2",children:"All models are responding normally."}):e.jsx("div",{className:"flex flex-col gap-2.5",children:Object.entries(k).map(([x,g])=>e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-text-main mb-1.5 capitalize",children:x}),e.jsx("div",{className:"flex flex-col gap-1",children:g.map(o=>{const n=te[o.status]||te.unknown,b=w===`${o.provider}:${o.model}`;return e.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5 rounded-lg bg-surface/30",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] shrink-0",style:{color:n.color},children:n.icon}),e.jsx("span",{className:"font-mono text-xs text-text-main truncate",children:o.model})]}),o.status==="cooldown"&&e.jsx(_,{size:"sm",variant:"ghost",onClick:()=>C(o.provider,o.model),disabled:b,className:"text-[10px] px-1.5! py-0.5! ml-2",children:b?"...":"Clear"})]},`${o.provider}-${o.model}`)})})]},x))})})]})})}function ce(r,a,m){const s=[];if(r>0&&s.push(e.jsxs(P,{variant:"success",size:"sm",dot:!0,children:[r," Connected"]},"connected")),a>0){const l=m?`${a} Error (${m})`:`${a} Error`;s.push(e.jsx(P,{variant:"error",size:"sm",dot:!0,children:l},"error"))}return s.length===0?e.jsx("span",{className:"text-text-muted",children:"No connections"}):s}function Re(r){if(!r)return null;const a=r.lastErrorType;if(a==="runtime_error")return"RUNTIME";if(a==="upstream_auth_error"||a==="auth_missing"||a==="token_refresh_failed"||a==="token_expired")return"AUTH";if(a==="upstream_rate_limited")return"429";if(a==="upstream_unavailable")return"5XX";if(a==="network_error")return"NET";const m=Number(r.errorCode);if(Number.isFinite(m)&&m>=400)return String(m);const s=Ae(r.lastError);if(s==="401"||s==="403")return"AUTH";if(s&&s!=="ERR")return s;const l=(r.lastError||"").toLowerCase();return l.includes("runtime")||l.includes("not runnable")||l.includes("not installed")?"RUNTIME":l.includes("invalid api key")||l.includes("token invalid")||l.includes("revoked")||l.includes("unauthorized")?"AUTH":"ERR"}const se=20;function De(){const[r,a]=c.useState([]),[m,s]=c.useState([]),[l,h]=c.useState(!0),[w,v]=c.useState(!1),[y,u]=c.useState(!1),[N,C]=c.useState(!1),[p,I]=c.useState(null),[j,k]=c.useState(null),x=ae(),g=Y(t=>t.query),o=Y(t=>t.register),n=Y(t=>t.unregister);c.useEffect(()=>(o("Search providers..."),()=>n()),[o,n]);const b=t=>!g.trim()||t.toLowerCase().includes(g.trim().toLowerCase()),K=(t,d)=>[...t].sort(([f,S],[A,R])=>{const q=D(f,d),F=D(A,d),L=q.connected>0?1:0,U=F.connected>0?1:0;return L!==U?U-L:(S.name||"").localeCompare(R.name||"")});c.useEffect(()=>{(async()=>{try{const[d,f]=await Promise.all([fetch("/api/providers"),fetch("/api/provider-nodes")]),S=await d.json(),A=await f.json();d.ok&&a(S.connections||[]),f.ok&&s(A.nodes||[])}catch(d){console.log("Error fetching data:",d)}finally{h(!1)}})()},[]);const D=(t,d)=>{const f=r.filter(T=>T.provider===t&&(T.authType===d||(t==="codebuddy"||t==="kimchi")&&T.authType==="apikey")),S=T=>{const E=Object.entries(T).some(([be,Z])=>be.startsWith("modelLock_")&&Z&&new Date(Z).getTime()>Date.now());return T.testStatus==="unavailable"&&!E?"active":T.testStatus},A=f.filter(T=>{const E=S(T);return E==="active"||E==="success"}).length,R=f.filter(T=>{const E=S(T);return E==="error"||E==="expired"||E==="unavailable"}),q=R.length,F=f.length,L=F>0&&f.every(T=>T.isActive===!1),U=R.sort((T,E)=>new Date(E.lastErrorAt||0)-new Date(T.lastErrorAt||0))[0],fe=U?Re(U):null,ge=U!=null&&U.lastErrorAt?Ie(U.lastErrorAt):null;return{connected:A,error:q,total:F,errorCode:fe,errorTime:ge,allDisabled:L}},$=async(t,d,f)=>{const S=r.filter(A=>A.provider===t&&A.authType===d);a(A=>A.map(R=>R.provider===t&&R.authType===d?{...R,isActive:f}:R)),await Promise.allSettled(S.map(A=>fetch(`/api/providers/${A.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:f})})))},V=async(t,d=null)=>{if(!p){I(t==="provider"?d:t),k(null);try{const S=await(await fetch("/api/providers/test-batch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:t,providerId:d})})).json();if(k(S),S.summary){const{passed:A,failed:R,total:q}=S.summary;R===0?x.success(`All ${q} tests passed`):x.warning(`${A}/${q} passed, ${R} failed`)}}catch{k({error:"Test request failed"}),x.error("Provider test failed")}finally{I(null)}}},B=m.filter(t=>t.type==="openai-compatible").map(t=>({id:t.id,name:t.name||"OpenAI Compatible",color:"#10A37F",textIcon:"OC",apiType:t.apiType})).filter(t=>b(t.name)),W=m.filter(t=>t.type==="anthropic-compatible").map(t=>({id:t.id,name:t.name||"Anthropic Compatible",color:"#D97757",textIcon:"AC"})).filter(t=>b(t.name)),H=Object.entries(ve).filter(([,t])=>!t.hidden&&b(t.name)),J=Object.entries(ye).filter(([,t])=>!t.hidden&&b(t.name)),X=Object.entries(je).filter(([,t])=>!t.hidden&&b(t.name)),M=K(Object.entries(Ne).filter(([,t])=>!t.hidden&&(t.serviceKinds??["llm"]).includes("llm")&&b(t.name)),"apikey"),Q=!!g.trim(),xe=Q||w?M:M.slice(0,se),ue=M.length-se;if(l)return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(ee,{}),e.jsx(ee,{})]});const he=H.length>0||J.length>0||X.length>0||M.length>0||B.length>0||W.length>0;return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[!he&&e.jsxs("div",{className:"text-center py-8 border border-dashed border-border rounded-xl",children:[e.jsx("span",{className:"material-symbols-outlined text-[32px] text-text-muted mb-2",children:"search_off"}),e.jsx("p",{className:"text-text-muted text-sm",children:"No providers match your search"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:["Custom Providers (OpenAI/Anthropic Compatible)"," "]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:w-auto",children:[e.jsx(_,{size:"sm",icon:"add",onClick:()=>C(!0),className:"w-full sm:w-auto",children:"Add Anthropic Compatible"}),e.jsx(_,{size:"sm",variant:"secondary",icon:"add",onClick:()=>u(!0),className:"w-full !bg-white !text-black hover:!bg-gray-100 sm:w-auto",children:"Add OpenAI Compatible"})]})]}),B.length===0&&W.length===0?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-2 border border-dashed border-border rounded-xl text-text-muted text-sm",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"extension"}),e.jsx("span",{children:"No custom providers — use buttons above to add OpenAI/Anthropic compatible endpoints"})]}):e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:[...B,...W].map(t=>e.jsx(z,{providerId:t.id,provider:t,stats:D(t.id,"apikey"),authType:"compatible",onToggle:d=>$(t.id,"apikey",d)},t.id))})]}),H.length>0&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:"OAuth Providers"}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsx(Se,{}),e.jsxs("button",{onClick:()=>V("oauth"),disabled:!!p,className:`flex w-full items-center justify-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors sm:w-auto sm:py-1.5 ${p==="oauth"?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"}`,title:"Test all OAuth connections","aria-label":"Test all OAuth connections",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px]${p==="oauth"?" animate-spin":""}`,children:"play_arrow"}),p==="oauth"?"Testing...":"Test All"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:H.map(([t,d])=>e.jsx(G,{providerId:t,provider:d,stats:D(t,"oauth"),authType:"oauth",onToggle:f=>$(t,"oauth",f)},t))})]}),(J.length>0||X.length>0)&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:"Free Tier Providers"}),e.jsxs("button",{onClick:()=>V("free"),disabled:!!p,className:`flex w-full items-center justify-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors sm:w-auto sm:py-1.5 ${p==="free"?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"}`,title:"Test all Free connections","aria-label":"Test all Free provider connections",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px]${p==="free"?" animate-spin":""}`,children:"play_arrow"}),p==="free"?"Testing...":"Test All"]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:[J.map(([t,d])=>e.jsx(G,{providerId:t,provider:d,stats:D(t,"oauth"),authType:"free",onToggle:f=>$(t,"oauth",f)},t)),X.map(([t,d])=>e.jsx(z,{providerId:t,provider:d,stats:D(t,"apikey"),authType:"apikey",onToggle:f=>$(t,"apikey",f)},t))]})]}),M.length>0&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:["API Key Providers"," "]}),e.jsxs("button",{onClick:()=>V("apikey"),disabled:!!p,className:`flex w-full items-center justify-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors sm:w-auto sm:py-1.5 ${p==="apikey"?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"}`,title:"Test all API Key connections","aria-label":"Test all API Key connections",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px]${p==="apikey"?" animate-spin":""}`,children:"play_arrow"}),p==="apikey"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:xe.map(([t,d])=>e.jsx(z,{providerId:t,provider:d,stats:D(t,"apikey"),authType:"apikey",onToggle:f=>$(t,"apikey",f)},t))}),!Q&&!w&&ue>0&&e.jsxs("button",{onClick:()=>v(!0),className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-primary/40 px-3 py-2.5 text-sm font-medium text-primary transition-colors hover:border-primary hover:bg-primary/5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"expand_more"}),"Show all ",M.length," providers"]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("h2",{className:"text-xl font-semibold flex items-center gap-2",children:["Web Cookie Providers"," "]})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:Object.entries(Ce).map(([t,d])=>e.jsx(z,{providerId:t,provider:d,stats:D(t,"apikey"),authType:"apikey",onToggle:f=>$(t,"apikey",f)},t))})]}),e.jsx(de,{isOpen:y,onClose:()=>u(!1),onCreated:t=>{s(d=>[...d,t]),u(!1)}}),e.jsx(me,{isOpen:N,onClose:()=>C(!1),onCreated:t=>{s(d=>[...d,t]),C(!1)}}),j&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-start justify-center px-3 pt-[6vh] sm:pt-[10vh]",onClick:()=>k(null),children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-surface border border-border rounded-xl w-full max-w-[600px] max-h-[86vh] sm:max-h-[80vh] overflow-y-auto shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-5 py-3 border-b border-border bg-surface/95 backdrop-blur-sm rounded-t-xl",children:[e.jsx("h3",{className:"font-semibold",children:"Test Results"}),e.jsx("button",{onClick:()=>k(null),className:"p-1 rounded-lg hover:bg-bg text-text-muted hover:text-text-main transition-colors","aria-label":"Close test results",children:e.jsx("span",{className:"material-symbols-outlined text-lg",children:"close"})})]}),e.jsx("div",{className:"p-5",children:e.jsx(pe,{results:j})})]})]})]})}function G({providerId:r,provider:a,stats:m,authType:s,onToggle:l}){var C;const{connected:h,error:w,errorCode:v,errorTime:y,allDisabled:u}=m,N=!!a.noAuth;return e.jsx(le,{to:`/dashboard/providers/${r}`,className:"group min-w-0",children:e.jsx(ne,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${u?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 shrink-0 rounded-lg flex items-center justify-center",style:{backgroundColor:`${((C=a.color)==null?void 0:C.length)>7?a.color:a.color+"15"}`},children:e.jsx(re,{src:a.id==="codebuddy"||a.id==="cb"?"/providers/codebuddy.svg":`/providers/${a.id}.png`,alt:a.name,size:30,className:"object-contain rounded-lg max-w-[32px] max-h-[32px]",fallbackText:a.textIcon||a.id.slice(0,2).toUpperCase(),fallbackColor:a.color})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate font-semibold",children:a.name}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5 text-xs flex-wrap",children:u?e.jsx(P,{variant:"default",size:"sm",children:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"pause_circle"}),"Disabled"]})}):N?e.jsx(P,{variant:"success",size:"sm",dot:!0,children:"Ready"}):e.jsxs(e.Fragment,{children:[ce(h,w,v),y&&e.jsx("span",{className:"text-text-muted",children:y})]})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:m.total>0&&e.jsx("div",{className:"opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100",onClick:p=>{p.preventDefault(),p.stopPropagation(),l(!!u)},children:e.jsx(oe,{size:"sm",checked:!u,onChange:()=>{},title:u?"Enable provider":"Disable provider"})})})]})})})}G.propTypes={providerId:i.string.isRequired,provider:i.shape({id:i.string.isRequired,name:i.string.isRequired,color:i.string,textIcon:i.string}).isRequired,stats:i.shape({connected:i.number,error:i.number,errorCode:i.string,errorTime:i.string}).isRequired,authType:i.string,onToggle:i.func};function z({providerId:r,provider:a,stats:m,authType:s,onToggle:l}){var I;const{connected:h,error:w,errorCode:v,errorTime:y,allDisabled:u}=m,N=r.startsWith(we),C=r.startsWith(Te),p=()=>a.id==="codebuddy"||a.id==="cb"?"/providers/codebuddy.svg":N?a.apiType==="responses"?"/providers/oai-r.png":"/providers/oai-cc.png":C?"/providers/anthropic-m.png":`/providers/${a.id}.png`;return e.jsx(le,{to:`/dashboard/providers/${r}`,className:"group min-w-0",children:e.jsx(ne,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${u?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 shrink-0 rounded-lg flex items-center justify-center",style:{backgroundColor:`${((I=a.color)==null?void 0:I.length)>7?a.color:a.color+"15"}`},children:e.jsx(re,{src:p(),alt:a.name,size:30,className:"object-contain rounded-lg max-w-[30px] max-h-[30px]",fallbackText:a.textIcon||a.id.slice(0,2).toUpperCase(),fallbackColor:a.color})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate font-semibold",children:a.name}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5 text-xs flex-wrap",children:u?e.jsx(P,{variant:"default",size:"sm",children:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"pause_circle"}),"Disabled"]})}):e.jsxs(e.Fragment,{children:[ce(h,w,v),N&&e.jsx(P,{variant:"default",size:"sm",children:a.apiType==="responses"?"Responses":"Chat"}),C&&e.jsx(P,{variant:"default",size:"sm",children:"Messages"}),y&&e.jsx("span",{className:"text-text-muted",children:y})]})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:m.total>0&&e.jsx("div",{className:"opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100",onClick:j=>{j.preventDefault(),j.stopPropagation(),l(!!u)},children:e.jsx(oe,{size:"sm",checked:!u,onChange:()=>{},title:u?"Enable provider":"Disable provider"})})})]})})})}z.propTypes={providerId:i.string.isRequired,provider:i.shape({id:i.string.isRequired,name:i.string.isRequired,color:i.string,textIcon:i.string,apiType:i.string}).isRequired,stats:i.shape({connected:i.number,error:i.number,errorCode:i.string,errorTime:i.string}).isRequired,authType:i.string,onToggle:i.func};function de({isOpen:r,onClose:a,onCreated:m}){const[s,l]=c.useState({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[h,w]=c.useState(!1),[v,y]=c.useState(""),[u,N]=c.useState(""),[C,p]=c.useState(!1),[I,j]=c.useState(null),k=[{value:"chat",label:"Chat Completions"},{value:"responses",label:"Responses API"}];c.useEffect(()=>{const n="https://api.openai.com/v1";l(b=>({...b,baseUrl:n}))},[s.apiType]);const x=async()=>{if(!(!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim())){w(!0);try{const n=await fetch("/api/provider-nodes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.name,prefix:s.prefix,apiType:s.apiType,baseUrl:s.baseUrl,type:"openai-compatible"})}),b=await n.json();n.ok&&(m(b.node),l({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),y(""),j(null))}catch(n){console.log("Error creating OpenAI Compatible node:",n)}finally{w(!1)}}},g=async()=>{p(!0);try{const b=await(await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:s.baseUrl,apiKey:v,type:"openai-compatible",modelId:u.trim()||void 0})})).json();j(b)}catch{j({valid:!1,error:"Network error"})}finally{p(!1)}},o=()=>{if(!I)return null;const{valid:n,error:b,method:K}=I;return n?e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"success",children:"Valid"}),K==="chat"&&e.jsx("span",{className:"text-sm text-text-muted",children:"(via inference test)"})]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(P,{variant:"error",children:"Invalid"}),b&&e.jsx("span",{className:"text-sm text-red-500",children:b})]})};return e.jsx(ie,{isOpen:r,title:"Add OpenAI Compatible",onClose:a,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(O,{label:"Name",value:s.name,onChange:n=>l({...s,name:n.target.value}),placeholder:"OpenAI Compatible (Prod)",hint:"Required. A friendly label for this node."}),e.jsx(O,{label:"Prefix",value:s.prefix,onChange:n=>l({...s,prefix:n.target.value}),placeholder:"oc-prod",hint:"Required. Used as the provider prefix for model IDs."}),e.jsx(ke,{label:"API Type",options:k,value:s.apiType,onChange:n=>l({...s,apiType:n.target.value})}),e.jsx(O,{label:"Base URL",value:s.baseUrl,onChange:n=>l({...s,baseUrl:n.target.value}),placeholder:"https://api.openai.com/v1",hint:"Use the base URL (ending in /v1) for your OpenAI-compatible API."}),e.jsx(O,{label:"API Key (for Check)",type:"password",value:v,onChange:n=>y(n.target.value)}),e.jsx(O,{label:"Model ID (optional)",value:u,onChange:n=>N(n.target.value),placeholder:"e.g. gpt-4, claude-3-opus",hint:"If provider lacks /models endpoint, enter a model ID to validate via chat/completions instead."}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsx(_,{onClick:g,disabled:!v||C||!s.baseUrl.trim(),variant:"secondary",className:"w-full sm:w-auto",children:C?"Checking...":"Check"}),o()]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(_,{onClick:x,fullWidth:!0,disabled:!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim()||h,children:h?"Creating...":"Create"}),e.jsx(_,{onClick:a,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}de.propTypes={isOpen:i.bool.isRequired,onClose:i.func.isRequired,onCreated:i.func.isRequired};function me({isOpen:r,onClose:a,onCreated:m}){const[s,l]=c.useState({name:"",prefix:"",baseUrl:"https://api.anthropic.com/v1"}),[h,w]=c.useState(!1),[v,y]=c.useState(""),[u,N]=c.useState(""),[C,p]=c.useState(!1),[I,j]=c.useState(null);c.useEffect(()=>{r&&(j(null),y(""),N(""))},[r]);const k=async()=>{if(!(!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim())){w(!0);try{const o=await fetch("/api/provider-nodes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.name,prefix:s.prefix,baseUrl:s.baseUrl,type:"anthropic-compatible"})}),n=await o.json();o.ok&&(m(n.node),l({name:"",prefix:"",baseUrl:"https://api.anthropic.com/v1"}),y(""),j(null))}catch(o){console.log("Error creating Anthropic Compatible node:",o)}finally{w(!1)}}},x=async()=>{p(!0);try{const n=await(await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:s.baseUrl,apiKey:v,type:"anthropic-compatible",modelId:u.trim()||void 0})})).json();j(n)}catch{j({valid:!1,error:"Network error"})}finally{p(!1)}},g=()=>{if(!I)return null;const{valid:o,error:n,method:b}=I;return o?e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"success",children:"Valid"}),b==="chat"&&e.jsx("span",{className:"text-sm text-text-muted",children:"(via inference test)"})]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(P,{variant:"error",children:"Invalid"}),n&&e.jsx("span",{className:"text-sm text-red-500",children:n})]})};return e.jsx(ie,{isOpen:r,title:"Add Anthropic Compatible",onClose:a,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(O,{label:"Name",value:s.name,onChange:o=>l({...s,name:o.target.value}),placeholder:"Anthropic Compatible (Prod)",hint:"Required. A friendly label for this node."}),e.jsx(O,{label:"Prefix",value:s.prefix,onChange:o=>l({...s,prefix:o.target.value}),placeholder:"ac-prod",hint:"Required. Used as the provider prefix for model IDs."}),e.jsx(O,{label:"Base URL",value:s.baseUrl,onChange:o=>l({...s,baseUrl:o.target.value}),placeholder:"https://api.anthropic.com/v1",hint:"Use the base URL (ending in /v1) for your Anthropic-compatible API. The system will append /messages."}),e.jsx(O,{label:"API Key (for Check)",type:"password",value:v,onChange:o=>y(o.target.value)}),e.jsx(O,{label:"Model ID (optional)",value:u,onChange:o=>N(o.target.value),placeholder:"e.g. claude-3-opus",hint:"If provider lacks /models endpoint, enter a model ID to validate via chat/completions instead."}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsx(_,{onClick:x,disabled:!v||C||!s.baseUrl.trim(),variant:"secondary",className:"w-full sm:w-auto",children:C?"Checking...":"Check"}),g()]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(_,{onClick:k,fullWidth:!0,disabled:!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim()||h,children:h?"Creating...":"Create"}),e.jsx(_,{onClick:a,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}me.propTypes={isOpen:i.bool.isRequired,onClose:i.func.isRequired,onCreated:i.func.isRequired};function pe({results:r}){if(r.error&&!r.results)return e.jsxs("div",{className:"text-center py-6",children:[e.jsx("span",{className:"material-symbols-outlined text-red-500 text-[32px] mb-2 block",children:"error"}),e.jsx("p",{className:"text-sm text-red-400",children:r.error})]});const{summary:a,mode:m}=r,s=r.results||[],l={oauth:"OAuth",free:"Free",apikey:"API Key",provider:"Provider",all:"All"}[m]||m;return e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[a&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs mb-1 sm:gap-3",children:[e.jsxs("span",{className:"text-text-muted",children:[l," Test"]}),e.jsxs("span",{className:"px-2 py-0.5 rounded bg-emerald-500/15 text-emerald-400 font-medium",children:[a.passed," passed"]}),a.failed>0&&e.jsxs("span",{className:"px-2 py-0.5 rounded bg-red-500/15 text-red-400 font-medium",children:[a.failed," failed"]}),e.jsxs("span",{className:"text-text-muted sm:ml-auto",children:[a.total," tested"]})]}),s.map((h,w)=>{var v;return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 rounded-lg bg-black/[0.03] px-3 py-2 text-xs dark:bg-white/[0.03] sm:flex-nowrap",children:[e.jsx("span",{className:`material-symbols-outlined text-[16px] ${h.valid?"text-emerald-500":"text-red-500"}`,children:h.valid?"check_circle":"error"}),e.jsxs("div",{className:"min-w-0 flex-[1_1_160px]",children:[e.jsx("span",{className:"block truncate font-medium sm:inline",children:h.connectionName}),e.jsxs("span",{className:"block truncate text-text-muted sm:ml-1.5 sm:inline",children:["(",h.provider,")"]})]}),h.latencyMs!==void 0&&e.jsxs("span",{className:"shrink-0 text-text-muted font-mono tabular-nums",children:[h.latencyMs,"ms"]}),e.jsx("span",{className:`shrink-0 text-[10px] uppercase font-bold px-1.5 py-0.5 rounded ${h.valid?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:h.valid?"OK":((v=h.diagnosis)==null?void 0:v.type)||"ERROR"})]},h.connectionId||w)}),s.length===0&&e.jsx("div",{className:"text-center py-4 text-text-muted text-sm",children:"No active connections found for this group."})]})}pe.propTypes={results:i.shape({mode:i.string,results:i.array,summary:i.shape({total:i.number,passed:i.number,failed:i.number}),error:i.string}).isRequired};export{De as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./index.BO_pNnMt.js";import{b as o}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function u(){const[i,n]=o.useState({}),l=t=>{navigator.clipboard.writeText(t),n(r=>({...r,[t]:!0})),setTimeout(()=>{n(r=>({...r,[t]:!1}))},1500)},a=({value:t,text:r="Copy",className:d=""})=>{const s=i[t];return e.jsxs("button",{type:"button",onClick:()=>l(t),className:`text-xs px-3 py-1 rounded cursor-pointer transition-all duration-150 flex items-center gap-1 border font-semibold shrink-0 ${s?"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"} ${d}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:s?"check":"content_copy"}),s?"Copied":r]})};return e.jsxs("div",{className:"max-w-3xl mx-auto py-8 px-4 text-white space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-white/10 pb-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[28px]",children:"auto_stories"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",children:"Panduan Lengkap Deploy Temp Mail"}),e.jsx("p",{className:"text-xs text-white/50 mt-0.5",children:"Panduan integrasi Cloudflare Worker & D1 Database untuk fsrouter"})]})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx("a",{href:"/dashboard/automation",className:"px-3.5 py-1.5 rounded-lg bg-white/5 border border-white/10 text-xs font-semibold hover:bg-white/10 transition-colors cursor-pointer",children:"Kembali ke Dashboard"})})]}),e.jsxs("div",{className:"space-y-6 text-sm leading-relaxed text-white/80",children:[e.jsxs("div",{className:"bg-primary/5 border border-primary/20 rounded-xl p-4 text-xs text-primary/95 flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined shrink-0 mt-0.5",children:"lightbulb"}),e.jsxs("p",{children:[e.jsx("strong",{children:"Info Penting:"})," Panduan ini ditujukan jika Anda ingin melakukan deployment secara manual ke Cloudflare menggunakan CLI. Jika Anda ingin setup otomatis, silakan kembali ke Dashboard dan gunakan form ",e.jsx("strong",{children:"⚡ Auto Deploy (Cloudflare)"})," untuk setup 1-klik."]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"1"}),"Prasyarat & Login Cloudflare"]}),e.jsx("p",{children:"Pastikan Node.js telah terinstal di komputer Anda. Buka terminal lalu autentikasikan akun Cloudflare Anda menggunakan Wrangler CLI:"}),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 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler login"}),e.jsx(a,{value:"npx wrangler login"})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"2"}),"Masuk Folder & Install Dependencies"]}),e.jsx("p",{children:"Buka terminal pada direktori worker lokal Anda (`tempmail`) lalu install package dependencies:"}),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 gap-4",children:[e.jsx("span",{className:"break-all",children:"cd /home/data/Project/fsrouter/tempmail && npm install"}),e.jsx(a,{value:"cd /home/data/Project/fsrouter/tempmail && npm install"})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"3"}),"Buat Database Cloudflare D1"]}),e.jsxs("p",{children:["Buat database baru bernama ",e.jsx("code",{children:"tempmail"})," pada Cloudflare D1 untuk menyimpan data kotak surat dan isi pesan:"]}),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 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler d1 create tempmail"}),e.jsx(a,{value:"npx wrangler d1 create tempmail"})]}),e.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/20 rounded-lg p-3.5 text-xs text-amber-300 flex items-start gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined shrink-0 mt-0.5",children:"warning"}),e.jsxs("span",{children:["Perintah di atas akan menghasilkan **database_id** (UUID). Salin ID tersebut, kemudian buka berkas ",e.jsx("code",{className:"bg-white/10 px-1 py-0.5 rounded font-mono text-white",children:"wrangler.jsonc"})," di folder proyek tempmail Anda, ganti nilai ",e.jsx("code",{children:"database_id"})," di baris terbawah dengan ID baru Anda."]})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"4"}),"Jalankan Migrasi Database D1"]}),e.jsx("p",{children:"Buat struktur tabel database yang diperlukan dengan menerapkan migrasi database baik secara lokal maupun langsung di 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 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler d1 migrations apply tempmail --remote"}),e.jsx(a,{value:"npx wrangler d1 migrations apply tempmail --remote"})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"5"}),"Buat API Access Key untuk fsrouter"]}),e.jsx("p",{children:"fsrouter berkomunikasi dengan Worker menggunakan API Key yang aman. Jalankan perintah SQL berikut untuk mendaftarkan fsrouter admin ke database D1 Anda:"}),e.jsxs("div",{className:"space-y-3",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 gap-4",children:[e.jsx("span",{className:"break-all overflow-hidden text-ellipsis",children:`npx wrangler d1 execute tempmail --remote --command="INSERT OR IGNORE INTO chats (chat_id, username, first_name, last_name, created_at, updated_at) VALUES ('fsrouter', 'fsrouter_admin', 'FSRouter', 'Admin', datetime('now'), datetime('now')); INSERT OR REPLACE INTO api_access (user_id, api_key, quota_daily, quota_used, quota_date, granted_by, granted_at, expires_at) VALUES ('fsrouter', 'tm_YOUR_SECURE_API_KEY', 0, 0, strftime('%Y-%m-%d', 'now'), 'admin', datetime('now'), '2099-12-31T23:59:59Z');"`}),e.jsx(a,{value:`npx wrangler d1 execute tempmail --remote --command="INSERT OR IGNORE INTO chats (chat_id, username, first_name, last_name, created_at, updated_at) VALUES ('fsrouter', 'fsrouter_admin', 'FSRouter', 'Admin', datetime('now'), datetime('now')); INSERT OR REPLACE INTO api_access (user_id, api_key, quota_daily, quota_used, quota_date, granted_by, granted_at, expires_at) VALUES ('fsrouter', 'tm_YOUR_SECURE_API_KEY', 0, 0, strftime('%Y-%m-%d', 'now'), 'admin', datetime('now'), '2099-12-31T23:59:59Z');"`})]}),e.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/20 rounded-lg p-3.5 text-xs text-amber-300 flex items-start gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined shrink-0 mt-0.5",children:"info"}),e.jsxs("span",{children:["Ganti ",e.jsx("code",{children:"tm_YOUR_SECURE_API_KEY"})," dengan API Key acak pilihan Anda (misalnya menggunakan format ",e.jsx("code",{children:"tm_"})," diikuti oleh karakter hex acak). Salin API Key ini ke pengaturan fsrouter Anda."]})]})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"6"}),"Atur Secret Tokens (Telegram & Webhook)"]}),e.jsx("p",{children:"Simpan token bot Telegram dan webhook secret ke dalam Cloudflare secret variables secara aman:"}),e.jsxs("div",{className:"space-y-3",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 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler secret put TELEGRAM_BOT_TOKEN"}),e.jsx(a,{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 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler secret put TELEGRAM_WEBHOOK_SECRET"}),e.jsx(a,{value:"npx wrangler secret put TELEGRAM_WEBHOOK_SECRET"})]})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"7"}),"Deploy ke Cloudflare Workers"]}),e.jsxs("p",{children:["Buka file ",e.jsx("code",{className:"bg-white/10 px-1 py-0.5 rounded font-mono text-white",children:"wrangler.jsonc"}),", sesuaikan parameter ",e.jsx("code",{children:"vars"})," (domain, base URL) agar sesuai dengan domain milik Anda. Setelah itu, deploy ke 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 gap-4",children:[e.jsx("span",{className:"break-all",children:"npx wrangler deploy"}),e.jsx(a,{value:"npx wrangler deploy"})]})]}),e.jsxs("div",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"8"}),"Daftarkan Webhook Telegram Bot (Opsional)"]}),e.jsx("p",{children:"Daftarkan URL domain worker Anda ke API Telegram agar bot Anda dapat menerima chat command secara instan:"}),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 gap-4",children:[e.jsx("span",{className:"break-all",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(a,{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",{className:"bg-neutral-900 border border-white/5 rounded-xl p-6 space-y-4",children:[e.jsxs("h4",{className:"text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"bg-primary/20 text-primary w-6 h-6 rounded-full flex items-center justify-center text-xs",children:"9"}),"Konfigurasi Cloudflare Email Routing & DNS (Paling Penting!)"]}),e.jsx("p",{children:"Ini adalah langkah krusial agar email dapat diterima dan diproses oleh Worker yang telah dideploy. Masuk ke panel Cloudflare Anda, lalu ikuti panduan berikut:"}),e.jsxs("div",{className:"space-y-4 border-l-2 border-primary/30 pl-4 mt-2",children:[e.jsxs("div",{children:[e.jsxs("h5",{className:"font-bold text-white text-xs flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary"}),"Bagian A: Sinkronkan dan Kunci Rekaman DNS"]}),e.jsxs("p",{className:"text-xs text-white/70 mt-1",children:["Jika status DNS Anda tertulis ",e.jsx("code",{className:"bg-white/10 text-white px-1 rounded",children:"Not configured"})," atau ada rekaman dengan status ",e.jsx("code",{className:"bg-amber-500/10 text-amber-300 px-1 rounded border border-amber-500/20",children:"Unlocked"})," (misalnya TXT SPF):"]}),e.jsxs("ul",{className:"list-disc list-inside text-xs text-white/70 mt-1.5 space-y-1 ml-2",children:[e.jsxs("li",{children:["Buka menu ",e.jsx("strong",{children:"Email Routing"})," di panel domain Cloudflare Anda."]}),e.jsx("li",{children:"Pilih tab **`Settings`** di sebelah atas."}),e.jsx("li",{children:"Di sebelah kanan judul **`DNS records`**, klik tombol **`Lock`** (ikon gembok). Cloudflare akan otomatis mengunci dan menerapkan semua MX dan TXT records yang dibutuhkan untuk rute email."})]})]}),e.jsxs("div",{children:[e.jsxs("h5",{className:"font-bold text-white text-xs flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary"}),"Bagian B: Buat Aturan Rute Catch-All"]}),e.jsx("p",{className:"text-xs text-white/70 mt-1",children:"Agar semua email masuk diteruskan ke database Worker Anda:"}),e.jsxs("ul",{className:"list-disc list-inside text-xs text-white/70 mt-1.5 space-y-1 ml-2",children:[e.jsx("li",{children:"Klik tab **`Routing rules`** (tab ketiga dari kiri)."}),e.jsx("li",{children:"Scroll ke bawah ke bagian **Catch-all address**."}),e.jsx("li",{children:"Klik **Edit** / **Configure**."}),e.jsx("li",{children:"Pada kolom **Action** (Aksi), pilih opsi **`Send to a Worker`** (Kirim ke Worker)."}),e.jsx("li",{children:"Pada kolom **Destination** (Worker tujuan), pilih nama Worker yang baru saja dideploy (contohnya: **`tempmail-pixelnest`**)."}),e.jsx("li",{children:"Klik **Save** untuk menyimpan aturan perutean."})]})]})]})]})]})]})}export{u as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{J as m,j as e,B as p}from"./index.BO_pNnMt.js";import{b as l}from"./router.Cjj1--8t.js";import{C as f}from"./NoAuthProxyCard.CLW2-XwE.js";import"./zustand.akaTi5uX.js";const g={LOG:"text-green-400",INFO:"text-blue-400",WARN:"text-yellow-400",ERROR:"text-red-400",DEBUG:"text-purple-400"};function h(n){var s;const o=n.match(/\[(\w+)\]/g),u=o?(s=o[1])==null?void 0:s.replace(/\[|\]/g,""):null,c=g[u]||"text-green-400";return e.jsx("span",{className:c,children:n})}function j(){const[n,o]=l.useState([]),[u,c]=l.useState(!1),s=l.useRef(null),d=async()=>{try{await fetch("/api/translator/console-logs",{method:"DELETE"})}catch(t){console.error("Failed to clear console logs:",t)}};return l.useEffect(()=>{const t=new EventSource("/api/translator/console-logs/stream");return t.onopen=()=>c(!0),t.onmessage=a=>{const r=JSON.parse(a.data);r.type==="init"?o(r.logs.slice(-200)):r.type==="line"?o(x=>{const i=[...x,r.line];return i.length>m.maxLines?i.slice(-200):i}):r.type==="clear"&&o([])},t.onerror=()=>c(!1),()=>t.close()},[]),l.useEffect(()=>{s.current&&(s.current.scrollTop=s.current.scrollHeight)},[n]),e.jsx("div",{className:"",children:e.jsxs(f,{children:[e.jsx("div",{className:"flex items-center justify-end px-4 pt-3 pb-2",children:e.jsx(p,{size:"sm",variant:"outline",icon:"delete",onClick:d,children:"Clear"})}),e.jsx("div",{ref:s,className:"bg-black rounded-b-lg p-4 text-xs font-mono h-[calc(100vh-220px)] overflow-y-auto",children:n.length===0?e.jsx("span",{className:"text-text-muted",children:"No console logs yet."}):e.jsx("div",{className:"space-y-0.5",children:n.map((t,a)=>e.jsx("div",{children:h(t)},a))})})]})})}const N="force-dynamic";function O(){return e.jsx(j,{})}export{O as default,N as dynamic};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{j as e}from"./index.BO_pNnMt.js";import{b as l}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function b({value:r,label:d="Copy"}){const[t,i]=l.useState(!1),a=async()=>{if(r)try{await navigator.clipboard.writeText(r),i(!0),setTimeout(()=>i(!1),1500)}catch{const n=document.createElement("textarea");n.value=r,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),i(!0),setTimeout(()=>i(!1),1500)}};return e.jsx("button",{onClick:a,disabled:!r,title:r?r.slice(0,60)+(r.length>60?"…":""):"Tidak tersedia",style:{padding:"2px 10px",fontSize:11,borderRadius:4,border:"1px solid",cursor:r?"pointer":"not-allowed",borderColor:t?"#22c55e":r?"#6366f1":"#374151",background:t?"#166534":r?"#1e1b4b":"#111827",color:t?"#86efac":r?"#a5b4fc":"#4b5563",transition:"all 0.15s",whiteSpace:"nowrap",minWidth:60},children:t?"✓ Copied!":d})}function y({value:r,maxLen:d=22}){const[t,i]=l.useState(!1);if(!r)return e.jsx("span",{style:{color:"#6b7280",fontSize:12},children:"—"});const a=t?r:r.slice(0,d)+"…";return e.jsxs("span",{style:{fontFamily:"monospace",fontSize:11,color:"#d1d5db"},children:[a,e.jsx("button",{onClick:()=>i(n=>!n),style:{marginLeft:4,fontSize:10,color:"#6366f1",background:"none",border:"none",cursor:"pointer"},children:t?"hide":"show"})]})}function w(r){const d=r.map(s=>({email:s.email,firebase_refresh_token:s.firebaseRefreshToken,firebase_api_key:s.firebaseApiKey,jwt:s.jwt,jwt_expires_at:s.jwtExpiresAt,balance:s.balance})),t=JSON.stringify(d,null,2),i=new Blob([t],{type:"application/json"}),a=URL.createObjectURL(i),n=document.createElement("a");n.href=a,n.download=`weavy-tokens-${Date.now()}.json`,n.click(),URL.revokeObjectURL(a)}function S(r){const t=`email,firebase_refresh_token,firebase_api_key
|
|
2
|
+
`+r.filter(s=>s.firebaseRefreshToken&&s.firebaseApiKey).map(s=>`${s.email},${s.firebaseRefreshToken},${s.firebaseApiKey}`).join(`
|
|
3
|
+
`),i=new Blob([t],{type:"text/csv"}),a=URL.createObjectURL(i),n=document.createElement("a");n.href=a,n.download=`weavy-refresh-tokens-${Date.now()}.csv`,n.click(),URL.revokeObjectURL(a)}function C(){const[r,d]=l.useState([]),[t,i]=l.useState(null),[a,n]=l.useState(!0),[s,g]=l.useState(""),[x,m]=l.useState(""),[p,j]=l.useState("all"),h=l.useCallback(async()=>{n(!0),g("");try{const c=await(await fetch("/api/providers/weavy/pool")).json();if(!c.ok)throw new Error(c.error||"Failed");d(c.pool||[]),i(c.stats||null)}catch(o){g(o.message)}finally{n(!1)}},[]);l.useEffect(()=>{h()},[h]);const u=r.filter(o=>{const c=!x||o.email.toLowerCase().includes(x.toLowerCase()),k=p==="all"?!0:p==="hasToken"?!!o.firebaseRefreshToken:p==="noToken"?!o.firebaseRefreshToken:p==="validJwt"?o.jwtValid:!0;return c&&k}),v={background:"#111827",border:"1px solid #1f2937",borderRadius:8,padding:"10px 14px",marginBottom:8},f=(o,c,k="#6366f1")=>e.jsxs("div",{style:{background:"#0f172a",borderRadius:8,padding:"12px 20px",border:"1px solid #1f2937",textAlign:"center",minWidth:100},children:[e.jsx("div",{style:{fontSize:28,fontWeight:700,color:k},children:c}),e.jsx("div",{style:{fontSize:11,color:"#9ca3af",marginTop:2},children:o})]});return e.jsxs("div",{style:{minHeight:"100vh",background:"#030712",color:"#e5e7eb",padding:"24px 32px",fontFamily:"Inter, sans-serif"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h1",{style:{margin:0,fontSize:22,fontWeight:700,color:"#f9fafb"},children:"🪄 Weavy Token Pool"}),e.jsx("p",{style:{margin:"4px 0 0",fontSize:13,color:"#6b7280"},children:"Copy firebase_refresh_token + firebase_api_key ke kliperspro atau sistem lain"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:h,style:{padding:"6px 14px",borderRadius:6,background:"#1f2937",border:"1px solid #374151",color:"#d1d5db",cursor:"pointer",fontSize:13},children:"↻ Refresh"}),e.jsx("button",{onClick:()=>S(r),style:{padding:"6px 14px",borderRadius:6,background:"#1e1b4b",border:"1px solid #4338ca",color:"#a5b4fc",cursor:"pointer",fontSize:13},children:"⬇ Export CSV"}),e.jsx("button",{onClick:()=>w(r),style:{padding:"6px 14px",borderRadius:6,background:"#14532d",border:"1px solid #166534",color:"#86efac",cursor:"pointer",fontSize:13},children:"⬇ Export JSON"})]})]}),t&&e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:24,flexWrap:"wrap"},children:[f("Total Akun",t.total,"#e5e7eb"),f("Aktif",t.active,"#22c55e"),f("JWT Valid",t.jwtValid,"#6366f1"),f("Punya Refresh Token",t.hasRefreshToken,"#f59e0b")]}),t&&t.hasRefreshToken===0&&e.jsxs("div",{style:{background:"#431407",border:"1px solid #7c2d12",borderRadius:8,padding:"12px 16px",marginBottom:20,fontSize:13,color:"#fed7aa"},children:["⚠️ ",e.jsx("strong",{children:"firebase_refresh_token masih kosong"})," untuk semua akun. Jalankan ulang signup untuk akun-akun ini agar refresh token tertangkap dari IndexedDB."]}),e.jsxs("div",{style:{background:"#0c1a2e",border:"1px solid #1e3a5f",borderRadius:8,padding:"12px 16px",marginBottom:20,fontSize:12},children:[e.jsx("strong",{style:{color:"#60a5fa"},children:"📋 Cara pakai di kliperspro (production):"}),e.jsx("pre",{style:{margin:"8px 0 0",color:"#93c5fd",fontSize:11,overflow:"auto"},children:`POST https://securetoken.googleapis.com/v1/token?key=<firebase_api_key>
|
|
4
|
+
Body: grant_type=refresh_token&refresh_token=<firebase_refresh_token>
|
|
5
|
+
→ Response: { id_token: "<JWT baru>", refresh_token: "<update ini>" }
|
|
6
|
+
→ Gunakan id_token sebagai: Authorization: Bearer <JWT>`})]}),e.jsxs("div",{style:{display:"flex",gap:10,marginBottom:16,flexWrap:"wrap"},children:[e.jsx("input",{value:x,onChange:o=>m(o.target.value),placeholder:"Cari email…",style:{flex:1,minWidth:200,background:"#111827",border:"1px solid #374151",borderRadius:6,padding:"6px 12px",color:"#e5e7eb",fontSize:13}}),["all","hasToken","noToken","validJwt"].map(o=>e.jsx("button",{onClick:()=>j(o),style:{padding:"6px 12px",borderRadius:6,fontSize:12,cursor:"pointer",border:"1px solid",borderColor:p===o?"#6366f1":"#374151",background:p===o?"#1e1b4b":"#111827",color:p===o?"#a5b4fc":"#9ca3af"},children:{all:"Semua",hasToken:"✅ Punya Token",noToken:"❌ Tanpa Token",validJwt:"🔑 JWT Valid"}[o]},o))]}),a?e.jsx("div",{style:{textAlign:"center",color:"#6b7280",padding:40},children:"Memuat…"}):s?e.jsxs("div",{style:{color:"#f87171",padding:20},children:["Error: ",s]}):e.jsxs("div",{children:[e.jsxs("div",{style:{color:"#6b7280",fontSize:12,marginBottom:8},children:["Menampilkan ",u.length," dari ",r.length," akun"]}),u.map(o=>e.jsxs("div",{style:{...v,opacity:o.isActive?1:.5},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontWeight:600,fontSize:13,minWidth:220,color:o.isActive?"#f9fafb":"#6b7280"},children:o.email}),e.jsx("span",{style:{fontSize:10,padding:"2px 7px",borderRadius:4,fontWeight:600,background:o.jwtValid?"#14532d":"#7f1d1d",color:o.jwtValid?"#86efac":"#fca5a5"},children:o.jwtValid?`JWT valid ${Math.ceil(o.jwtSecondsLeft/60)}m`:"JWT expired"}),e.jsx("span",{style:{fontSize:10,padding:"2px 7px",borderRadius:4,fontWeight:600,background:o.firebaseRefreshToken?"#1c1917":"#1f2937",color:o.firebaseRefreshToken?"#fbbf24":"#4b5563"},children:o.firebaseRefreshToken?"🔑 refresh_token ✓":"❌ no refresh_token"}),e.jsxs("span",{style:{fontSize:11,color:"#6b7280"},children:["💰 ",o.balance," credits"]}),e.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx(b,{value:o.firebaseRefreshToken,label:"Copy refresh_token"}),e.jsx(b,{value:o.firebaseApiKey,label:"Copy api_key"}),e.jsx(b,{value:o.jwt,label:"Copy JWT"}),e.jsx(b,{value:o.firebaseRefreshToken&&o.firebaseApiKey?JSON.stringify({email:o.email,firebase_refresh_token:o.firebaseRefreshToken,firebase_api_key:o.firebaseApiKey},null,2):"",label:"Copy All"})]})]}),e.jsxs("div",{style:{marginTop:6,display:"flex",gap:16,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("span",{style:{fontSize:10,color:"#9ca3af"},children:"refresh_token: "}),e.jsx(y,{value:o.firebaseRefreshToken})]}),e.jsxs("div",{children:[e.jsx("span",{style:{fontSize:10,color:"#9ca3af"},children:"api_key: "}),e.jsx(y,{value:o.firebaseApiKey,maxLen:16})]}),e.jsxs("div",{children:[e.jsx("span",{style:{fontSize:10,color:"#9ca3af"},children:"JWT: "}),e.jsx(y,{value:o.jwt})]})]})]},o.id)),u.length===0&&e.jsx("div",{style:{textAlign:"center",color:"#6b7280",padding:40},children:"Tidak ada akun ditemukan"})]})]})}export{C as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./index.BO_pNnMt.js";import{b as t,d as H}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function z(){const[x,N]=t.useState(""),[m,c]=t.useState(""),[W,b]=t.useState(""),[r,f]=t.useState(0),[g,w]=t.useState(!1),[y,u]=t.useState(null),[n,k]=t.useState("password"),[i,L]=t.useState(!1),[S,C]=t.useState("Sign in with OIDC"),[h,M]=t.useState(!1),l=H();t.useEffect(()=>{if(r<=0)return;const a=setInterval(()=>f(s=>s>0?s-1:0),1e3);return()=>clearInterval(a)},[r]),t.useEffect(()=>{async function a(){const s=new AbortController,o=setTimeout(()=>s.abort(),5e3),R=typeof window<"u"?window.location.origin:"";try{const v=await fetch(`${R}/api/auth/status`,{signal:s.signal});if(clearTimeout(o),v.ok){const d=await v.json(),j=new URLSearchParams(window.location.search),E=j.get("force")==="true"||j.get("force")==="1";if(d.requireLogin===!1&&!E){localStorage.setItem("9r_authed","1"),l("/dashboard"),l(0);return}u(!!d.hasPassword),k(d.authMode||"password"),L(d.oidcConfigured===!0),C(d.oidcLoginLabel||"Sign in with OIDC")}else u(!0)}catch{clearTimeout(o),u(!0)}}a()},[l]);const P=async a=>{a.preventDefault(),w(!0),c(""),b("");try{const s=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:x})});if(s.ok)localStorage.setItem("9r_authed","1"),l("/dashboard"),l(0);else{const o=await s.json();c(o.error||"Invalid password"),o.resetHint&&b(o.resetHint),o.retryAfter&&f(Number(o.retryAfter))}}catch{c("An error occurred. Please try again.")}finally{w(!1)}},I=()=>{window.location.href="/api/auth/oidc/start"},A=i&&["oidc","both"].includes(n),p=n!=="oidc"||!i,O=n==="oidc"&&!i||n==="both"&&!i,D=n==="both"&&i;return y===null?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-400"})}):e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 via-white to-slate-100 p-4",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute -top-40 -right-40 w-80 h-80 bg-violet-200/30 rounded-full blur-3xl"}),e.jsx("div",{className:"absolute -bottom-40 -left-40 w-80 h-80 bg-blue-200/30 rounded-full blur-3xl"})]}),e.jsxs("div",{className:"relative w-full max-w-sm",children:[e.jsxs("div",{className:"bg-white rounded-2xl shadow-lg shadow-slate-200/50 border border-slate-200/60 p-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-gradient-to-br from-violet-500 to-blue-500 mb-4 shadow-lg shadow-violet-500/25",children:e.jsx("svg",{className:"w-6 h-6 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),e.jsx("h1",{className:"text-2xl font-bold text-slate-900 tracking-tight",children:"FSRouter"}),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:n==="oidc"&&i?"Sign in with your OIDC provider":"Enter your password to continue"})]}),O&&e.jsx("div",{className:"mb-4 p-3 rounded-lg bg-amber-50 border border-amber-200 text-xs text-amber-700",children:"OIDC not configured yet. Password login is available."}),D&&e.jsx("div",{className:"mb-4 p-3 rounded-lg bg-violet-50 border border-violet-200 text-xs text-violet-700 text-center",children:"Password and OIDC login are both enabled."}),p&&e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 block mb-1.5",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{name:"password",type:h?"text":"password",placeholder:"••••••••",value:x,onChange:a=>N(a.target.value),required:!0,autoFocus:!0,className:"w-full bg-slate-50 border border-slate-200 text-slate-900 text-sm p-3 pr-10 rounded-xl focus:outline-none focus:border-violet-400 focus:ring-2 focus:ring-violet-100 placeholder-slate-400 transition-all"}),e.jsx("button",{type:"button",onClick:()=>M(!h),className:"absolute inset-y-0 right-3 flex items-center text-slate-400 hover:text-slate-600",children:h?e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.878 9.878L3 3m6.878 6.878l4.242 4.242M21 21l-3.122-3.122"})}):e.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]}),m&&e.jsx("p",{className:"text-xs text-red-500 mt-1.5",children:m}),r>0&&e.jsxs("p",{className:"text-xs text-amber-600 mt-1.5",children:["Locked. Retry in ",r,"s."]})]}),e.jsx("button",{type:"submit",disabled:g||r>0,className:"w-full bg-gradient-to-r from-violet-500 to-blue-500 hover:from-violet-600 hover:to-blue-600 text-white font-medium text-sm py-3 rounded-xl transition-all shadow-lg shadow-violet-500/25 disabled:opacity-50 cursor-pointer",children:g?"Logging in...":r>0?`Wait ${r}s`:"Login"}),e.jsxs("p",{className:"text-center text-xs text-slate-400",children:["Default password is ",e.jsx("code",{className:"bg-slate-100 px-1.5 py-0.5 rounded text-slate-500 font-mono",children:"123456"})]})]}),A&&e.jsxs(e.Fragment,{children:[p&&e.jsxs("div",{className:"relative flex items-center justify-center py-4",children:[e.jsx("span",{className:"w-full border-t border-slate-200"}),e.jsx("span",{className:"px-3 text-xs text-slate-400 bg-white absolute",children:"or"})]}),e.jsxs("button",{onClick:I,type:"button",className:"w-full flex items-center justify-center gap-2 border border-slate-200 rounded-xl py-3 hover:bg-slate-50 transition-colors text-slate-600 text-sm cursor-pointer",children:[e.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M15 3h4a2 2 0 012 2v14a2 2 0 01-2 2h-4M10 17l5-5-5-5M15 12H3"})}),S]})]})]}),e.jsx("p",{className:"text-center text-xs text-slate-400 mt-6",children:"Powered by FSRouter"})]})]})}export{z as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as Re,r as ce,v as Ue,j as t,M as Ie,B as b,C as Oe}from"./index.BO_pNnMt.js";import{b as s}from"./router.Cjj1--8t.js";import{C as Be,T as y,I as Me}from"./NoAuthProxyCard.CLW2-XwE.js";import"./zustand.akaTi5uX.js";const $e=["zh-CN","zh-TW"],S=[{id:"lite",label:"Lite",desc:"Drop filler, keep grammar"},{id:"full",label:"Full",desc:"Drop articles, fragments OK"},{id:"ultra",label:"Ultra",desc:"Telegraphic, max compression"},{id:"wenyan-lite",label:"文 Lite",desc:"Classical Chinese, light compression",wenyan:!0},{id:"wenyan",label:"文 Full",desc:"Maximum 文言文, 80-90% reduction",wenyan:!0},{id:"wenyan-ultra",label:"文 Ultra",desc:"Extreme classical compression",wenyan:!0}],de=[{id:"lite",label:"Lite",desc:"Build asked, name lazier option"},{id:"full",label:"Full",desc:"Ladder enforced: stdlib/native first"},{id:"ultra",label:"Ultra",desc:"YAGNI extremist, deletion first"}];function Ke(){var le,ie;const[M,$]=s.useState(!0),[D,J]=s.useState(!1),[L,j]=s.useState("http://localhost:8787"),[l,T]=s.useState({installed:!1,running:!1,python:null,loading:!0}),[me,A]=s.useState(!1),[v,w]=s.useState(!1),[_,G]=s.useState(""),[N,h]=s.useState({version:null,extras:{code:!1,ml:!1},available:["code","ml"],loading:!1}),[c,x]=s.useState([]),[P,K]=s.useState(!1),[W,p]=s.useState(""),[H,z]=s.useState(null),[F,Y]=s.useState(""),[n,C]=s.useState(null),[he,V]=s.useState(!1),[xe,q]=s.useState(!0),[Q,X]=s.useState(!1),u=s.useRef(null),[R,Z]=s.useState(!1),[k,U]=s.useState("full"),[I,ee]=s.useState(!1),[te,ae]=s.useState("full"),[pe,se]=s.useState("en"),{copied:ue,copy:fe}=Re();s.useEffect(()=>(se(ce()),Ue(()=>se(ce()))),[]);const O=$e.includes(pe),ge=O?S:S.filter(e=>!e.wenyan);s.useEffect(()=>{const e=S.find(a=>a.id===k);e!=null&&e.wenyan&&!O&&(U("ultra"),m({cavemanLevel:"ultra"}))},[O,k]);const m=async e=>{try{await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}catch(a){console.log("Error updating setting:",a)}},be=async e=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({rtkEnabled:e})})).ok&&$(e)}catch(a){console.log("Error updating rtkEnabled:",a)}},ye=e=>{Z(e),m({cavemanEnabled:e})},je=e=>{U(e),m({cavemanLevel:e})},ve=e=>{const a=L.trim()||"http://localhost:8787";j(a),J(e),m({headroomEnabled:e,headroomUrl:a})},we=async()=>{const e=L.trim()||"http://localhost:8787";j(e),await m({headroomUrl:e}),i()},i=s.useCallback(async()=>{T(e=>({...e,loading:!0}));try{const a=await(await fetch("/api/headroom/status",{headers:{"Cache-Control":"no-store"}})).json();if(T({...a,loading:!1}),!(a!=null&&a.installed)){h({version:null,extras:{code:!1,ml:!1},available:["code","ml"],loading:!1}),x([]);return}try{const r=await fetch("/api/headroom/extras",{headers:{"Cache-Control":"no-store"}});if(!r.ok)throw new Error("extras status failed");const o=await r.json();h(g=>({...g,version:o.version??null,extras:o.extras||{code:!1,ml:!1},available:o.available||["code","ml"],loading:!1})),x([])}catch{h({version:null,extras:{code:!1,ml:!1},available:["code","ml"],loading:!1}),x([])}}catch{T({installed:!1,running:!1,python:null,loading:!1}),h({version:null,extras:{code:!1,ml:!1},available:["code","ml"],loading:!1}),x([])}},[]),Ne=s.useCallback(async()=>{G(""),w(!0);try{const e=await fetch("/api/headroom/start",{method:"POST"}),a=await e.json().catch(()=>({}));if(!e.ok)throw new Error(a.error||"Failed to start proxy");await i()}catch(e){G(e.message)}finally{w(!1)}},[i]),Ce=s.useCallback(async()=>{w(!0);try{await fetch("/api/headroom/stop",{method:"POST"}),await i()}finally{w(!1)}},[i]),ke=e=>{x(a=>a.includes(e)?a.filter(r=>r!==e):[...a,e])},E=s.useCallback(()=>{Y(""),u.current&&clearInterval(u.current);const e=async()=>{try{const r=await(await fetch("/api/headroom/extras?log=1",{headers:{"Cache-Control":"no-store"}})).json().catch(()=>({}));typeof r.log=="string"&&Y(r.log)}catch{}};e(),u.current=setInterval(e,1500)},[]),f=s.useCallback(()=>{u.current&&(clearInterval(u.current),u.current=null)},[]);s.useEffect(()=>()=>f(),[f]);const B=s.useCallback(async()=>{if(c.length!==0){K(!0),p(""),E();try{const e=await fetch("/api/headroom/extras",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({extras:c})}),a=await e.json().catch(()=>({}));if(!e.ok)throw new Error(a.error||"Install failed");h(r=>({...r,version:a.version??r.version,extras:a.extras||r.extras})),x([])}catch(e){p(e.message)}finally{f(),K(!1)}}},[c,E,f]),re=s.useCallback(async e=>{z(e),p(""),E();try{const a=await fetch("/api/headroom/extras",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({extras:[e]})}),r=await a.json().catch(()=>({}));if(!a.ok)throw new Error(r.error||"Remove failed");h(o=>({...o,version:r.version??o.version,extras:r.extras||o.extras}))}catch(a){p(a.message)}finally{f(),z(null)}},[E,f]),Ee=s.useCallback(()=>{if(c.length!==0){if(c.includes("ml")){C({title:"Install [ml]",message:"[ml] downloads ~1 GB (torch + huggingface-hub). Continue?",confirmText:"Install",variant:"primary",onConfirm:B});return}B()}},[c,B]),Se=s.useCallback(e=>{C({title:`Remove [${e}]`,message:`Remove [${e}] and its packages?`,confirmText:"Remove",variant:"danger",onConfirm:()=>re(e)})},[re]),Le=s.useCallback(async(e,a)=>{if(p(""),e==="code"&&V(a),e==="ml"&&q(a),await m({[e==="code"?"headroomCodeAware":"headroomKompress"]:a}),!!l.running){X(!0);try{const o=await fetch("/api/headroom/restart",{method:"POST"}),g=await o.json().catch(()=>({}));if(!o.ok)throw new Error(g.error||"Restart failed");await i()}catch(o){p(o.message)}finally{X(!1)}}},[l.running,i]),Te=e=>{ee(e),m({ponytailEnabled:e})},Ae=e=>{ae(e),m({ponytailLevel:e})};s.useEffect(()=>{(async()=>{try{const a=await fetch("/api/settings");if(!a.ok)return;const r=await a.json();$(r.rtkEnabled!==!1),J(!!r.headroomEnabled),j(r.headroomUrl||"http://localhost:8787"),V(r.headroomCodeAware===!0),q(r.headroomKompress!==!1),Z(!!r.cavemanEnabled),U(r.cavemanLevel||"full"),ee(!!r.ponytailEnabled),ae(r.ponytailLevel||"full"),i()}catch{}})()},[i]);const d=!!l.running,ne=l.loading?"Checking…":d?"Running":l.localUrl!==!1&&!l.installed?"Not installed":l.localUrl!==!1?"Stopped":"External",oe=l.localUrl!==!1,Pe=!!l.canStart,He=oe&&!!l.managedPid;return t.jsxs("div",{className:"space-y-6 p-6",children:[t.jsxs(Be,{id:"rtk",children:[t.jsx("div",{className:"flex items-center justify-between mb-2",children:t.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[t.jsx("span",{className:"material-symbols-outlined text-primary",children:"bolt"}),"Token Saver"]})}),t.jsxs("div",{className:"flex items-center justify-between pt-2 pb-4 border-b border-border gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("p",{className:"font-medium",children:["Compress tool output"," ",t.jsx("a",{href:"https://github.com/rtk-ai/rtk",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(RTK)"})]}),t.jsx("p",{className:"text-sm text-text-muted",children:"git/grep/ls/tree/logs → 60-90% fewer input tokens"})]}),t.jsx(y,{checked:M,onChange:()=>be(!M)})]}),t.jsxs("div",{className:"flex items-center justify-between py-4 gap-4 flex-wrap",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[t.jsxs("p",{className:"font-medium",children:["Compress context"," ",t.jsx("a",{href:"https://github.com/chopratejas/headroom",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Headroom)"})]}),t.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${d?"bg-success/15 text-success":"bg-warning/15 text-warning"}`,children:ne}),t.jsx("button",{type:"button",onClick:()=>A(!0),className:"text-xs text-primary underline hover:opacity-80",children:d?"Manage":"Setup"})]}),t.jsx("p",{className:"text-sm text-text-muted mt-1",children:"Compress prompts via /v1/compress before routing to the model"})]}),t.jsx(y,{checked:D&&d,disabled:!d,onChange:()=>ve(!D)})]}),l.installed&&t.jsxs("div",{className:"mb-3 ml-1 pl-3 pb-4 border-l-2 border-border",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsxs("span",{className:"text-xs text-text-muted",children:["Compression extras",N.version?` · v${N.version}`:"",":"]}),N.available.map(e=>{const a=!!N.extras[e],r=c.includes(e),o=e==="code"?"tree-sitter AST compression for code responses":"Kompress-v2 HF model for prose/agentic traces (~+1GB)";if(a){const g=e==="code"?he:xe;return t.jsxs("div",{className:"flex items-center gap-1.5 text-xs px-2 py-1 rounded border border-success/40 bg-success/5 text-text",title:o,children:[t.jsx(y,{size:"sm",checked:g,disabled:Q,onChange:()=>Le(e,!g)}),t.jsxs("span",{className:"font-medium",children:["[",e,"]"]}),t.jsx("button",{type:"button",onClick:()=>Se(e),disabled:H===e,className:"ml-1 text-error underline hover:opacity-80 disabled:opacity-50",title:`Uninstall [${e}]`,children:H===e?"Uninstalling…":"Uninstall"})]},e)}return t.jsxs("label",{className:`flex items-center gap-1.5 text-xs px-2 py-1 rounded border cursor-pointer transition-colors ${r?"border-primary bg-primary/10 text-primary":"border-border text-text-muted hover:bg-surface-2"}`,title:o,children:[t.jsx("input",{type:"checkbox",className:"w-3 h-3",checked:r,onChange:()=>ke(e)}),t.jsxs("span",{className:"font-medium",children:["[",e,"]"]}),t.jsx("span",{className:"opacity-70",children:"not installed"})]},e)}),c.length>0&&t.jsx("button",{onClick:Ee,disabled:P,className:"text-xs px-2.5 py-1 rounded bg-primary text-white hover:opacity-90 disabled:opacity-50",children:P?"Installing…":`Install [proxy,${c.join(",")}]`})]}),W&&t.jsx("p",{className:"text-xs text-error mt-1",children:W}),Q&&t.jsx("p",{className:"text-xs text-text-muted mt-1",children:"Restarting proxy…"}),(P||H)&&F&&t.jsx("pre",{className:"mt-2 max-h-32 overflow-auto rounded bg-surface-2 p-2 text-[10px] leading-tight text-text-muted whitespace-pre-wrap",children:F}),t.jsxs("p",{className:"text-xs text-text-muted mt-1",children:["Installing adds the package; use ",t.jsx("code",{children:"on"}),"/",t.jsx("code",{children:"off"})," ","to activate it (restarts the proxy). Default install is"," ",t.jsx("code",{children:"[proxy]"})," only (SmartCrusher for JSON). Adding"," ",t.jsx("code",{children:"[code]"})," enables AST compression (Python/JS/TS/Go/Rust/Java/C/C++/Perl). Adding ",t.jsx("code",{children:"[ml]"})," ","enables the Kompress-v2 HF model for prose/agentic traces but adds ~1 GB (torch + huggingface-hub)."]})]}),t.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-border gap-4 flex-wrap",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("p",{className:"font-medium",children:["Compress LLM output"," ",t.jsx("a",{href:"https://github.com/JuliusBrussee/caveman",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Caveman)"})]}),t.jsx("p",{className:"text-sm text-text-muted",children:"Terse-style system prompt → ~65% fewer output tokens (up to 87%)"})]}),t.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[R&&t.jsxs("div",{className:"flex flex-col items-end gap-1",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:ge.map(e=>t.jsx("button",{onClick:()=>je(e.id),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${k===e.id?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:e.desc,children:e.label},e.id))}),t.jsx("p",{className:"text-xs text-primary",children:(le=S.find(e=>e.id===k))==null?void 0:le.desc})]}),t.jsx(y,{checked:R,onChange:()=>ye(!R)})]})]}),t.jsxs("div",{className:"flex items-center justify-between pt-4 mt-4 border-t border-border gap-4 flex-wrap",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("p",{className:"font-medium",children:["Lazy senior dev"," ",t.jsx("a",{href:"https://github.com/DietrichGebert/ponytail",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Ponytail)"})]}),t.jsx("p",{className:"text-sm text-text-muted",children:"Bias the model toward minimal code: YAGNI, reuse stdlib, deletion over addition"})]}),t.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[I&&t.jsxs("div",{className:"flex flex-col items-end gap-1",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:de.map(e=>t.jsx("button",{onClick:()=>Ae(e.id),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${te===e.id?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:e.desc,children:e.label},e.id))}),t.jsx("p",{className:"text-xs text-primary",children:(ie=de.find(e=>e.id===te))==null?void 0:ie.desc})]}),t.jsx(y,{checked:I,onChange:()=>Te(!I)})]})]})]}),t.jsx(Ie,{isOpen:me,title:d?"Headroom":"Setup Headroom",onClose:()=>A(!1),children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{children:"Status"}),t.jsx("span",{className:d?"text-success":"text-warning",children:ne})]}),d&&t.jsx("a",{href:"/api/headroom/proxy/dashboard",target:"_blank",rel:"noreferrer",className:"w-full rounded border border-border px-4 py-2 text-center text-sm hover:bg-surface-2",children:"Open Headroom Dashboard"}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("p",{className:"text-sm font-medium",children:"Proxy URL"}),t.jsx(Me,{value:L,onChange:e=>j(e.target.value),onBlur:we,placeholder:"http://localhost:8787",className:"font-mono text-sm"}),t.jsx("p",{className:"text-xs text-text-muted",children:"Use a local proxy for Start/Stop, or an external Docker sidecar like http://headroom:8787."})]}),He?t.jsx(b,{onClick:Ce,variant:"ghost",fullWidth:!0,disabled:v,children:v?"Stopping…":"Stop Headroom"}):d?t.jsx("p",{className:"text-sm text-success",children:"Headroom proxy is reachable. You can enable the token saver."}):Pe?t.jsx(b,{onClick:Ne,fullWidth:!0,disabled:v,children:v?"Starting…":"Start Headroom"}):oe?l.python?t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("p",{className:"text-sm font-medium",children:"Install then click Start:"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("pre",{className:"flex-1 rounded bg-black/5 dark:bg-white/5 p-2 text-xs font-mono overflow-x-auto",children:'pip install "headroom-ai[proxy]"'}),t.jsx(b,{size:"sm",variant:"ghost",onClick:()=>fe('pip install "headroom-ai[proxy]"'),children:ue?"Copied":"Copy"})]})]}):t.jsx("p",{className:"text-sm text-warning",children:"Python ≥ 3.10 required for local managed mode. Install Python first, or use an external proxy URL."}):t.jsx("p",{className:"text-sm text-warning",children:"Start Headroom separately at the configured URL, then recheck."}),_&&t.jsx("p",{className:"text-sm text-warning",children:_}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(b,{onClick:()=>i(),variant:"ghost",fullWidth:!0,children:"Recheck"}),t.jsx(b,{onClick:()=>A(!1),fullWidth:!0,children:"Done"})]})]})}),t.jsx(Oe,{isOpen:!!n,onClose:()=>C(null),onConfirm:()=>{const e=n==null?void 0:n.onConfirm;C(null),e==null||e()},title:n==null?void 0:n.title,message:n==null?void 0:n.message,confirmText:n==null?void 0:n.confirmText,variant:n==null?void 0:n.variant})]})}export{Ke as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{N as B,K as I,j as e,B as E,g as A,P as z}from"./index.BO_pNnMt.js";import{h as _,d as M,b,L as T}from"./router.Cjj1--8t.js";import{A as R,C as D,B as j,T as K}from"./NoAuthProxyCard.CLW2-XwE.js";import"./zustand.akaTi5uX.js";const F=new Set([]),L={image:"image-combo",tts:"tts-combo"};function P(s){const o=Object.entries(s).some(([i,d])=>i.startsWith("modelLock_")&&d&&new Date(d).getTime()>Date.now());return s.testStatus==="unavailable"&&!o?"active":s.testStatus}function $({provider:s,kind:o,connections:i,isCustom:d,onToggle:l}){var C;const n=A[s.id],y=!!(n!=null&&n.noAuth),p=i.filter(a=>a.provider===s.id),v=p.filter(a=>{const x=P(a);return x==="active"||x==="success"}).length,h=p.filter(a=>{const x=P(a);return x==="error"||x==="expired"||x==="unavailable"}).length,m=p.length,r=m>0&&p.every(a=>a.isActive===!1),u=a=>{a.preventDefault(),a.stopPropagation(),l&&l(s.id,r)},k=()=>y?e.jsx(j,{variant:"success",size:"sm",children:"Ready"}):r?e.jsx(j,{variant:"default",size:"sm",children:"Disabled"}):m===0?e.jsx("span",{className:"text-xs text-text-muted",children:"No connections"}):e.jsxs(e.Fragment,{children:[v>0&&e.jsxs(j,{variant:"success",size:"sm",dot:!0,children:[v," Connected"]}),h>0&&e.jsxs(j,{variant:"error",size:"sm",dot:!0,children:[h," Error"]}),v===0&&h===0&&e.jsxs(j,{variant:"default",size:"sm",children:[m," Added"]})]});return e.jsx(T,{to:`/dashboard/media-providers/${o}/${s.id}`,className:"group",children:e.jsx(D,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${r?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 rounded-lg flex items-center justify-center shrink-0",style:{backgroundColor:`${((C=s.color)==null?void 0:C.length)>7?s.color:(s.color??"#888")+"15"}`},children:e.jsx(z,{src:`/providers/${s.id}.png`,alt:s.name,size:30,className:"object-contain rounded-lg max-w-[30px] max-h-[30px]",fallbackText:s.textIcon||s.id.slice(0,2).toUpperCase(),fallbackColor:s.color})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm",children:s.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[d&&e.jsx(j,{variant:"default",size:"sm",children:"Custom"}),k()]})]})]}),m>0&&e.jsx("div",{className:"shrink-0 opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100",onClick:u,children:e.jsx(K,{size:"sm",checked:!r,onChange:()=>{},title:r?"Enable provider":"Disable provider"})})]})})})}function U({combos:s}){return s.length===0?null:e.jsx("div",{className:"flex flex-col gap-2",children:s.map(o=>e.jsx(T,{to:`/dashboard/media-providers/combo/${o.id}`,children:e.jsx(D,{padding:"xs",className:"hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors cursor-pointer",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"layers"}),e.jsx("code",{className:"text-sm font-mono font-medium flex-1 truncate",children:o.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 sm:shrink-0",children:[o.models.slice(0,6).map((i,d)=>{const l=typeof i=="string"?i.split("/")[0]:"",n=A[l];return e.jsx("div",{title:(n==null?void 0:n.name)||i,className:"size-5 rounded flex items-center justify-center",style:{backgroundColor:`${(n==null?void 0:n.color)??"#888"}15`},children:e.jsx(z,{src:`/providers/${l}.png`,alt:(n==null?void 0:n.name)||l,size:18,className:"object-contain rounded max-w-[18px] max-h-[18px]",fallbackText:(n==null?void 0:n.textIcon)||l.slice(0,2).toUpperCase(),fallbackColor:n==null?void 0:n.color})},`${i}-${d}`)}),o.models.length>6&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1",children:["+",o.models.length-6]})]}),e.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:o.models.length}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[16px]",children:"chevron_right"})]})})},o.id))})}function G(){const{kind:s}=_(),o=M(),[i,d]=b.useState([]),[l,n]=b.useState([]),[y,p]=b.useState([]),[v,h]=b.useState(!1);b.useEffect(()=>{(s==="webSearch"||s==="webFetch")&&o("/dashboard/media-providers/web")},[s,o]);const m=B.find(t=>t.id===s),r=s==="embedding",u=F.has(s);if(b.useEffect(()=>{m&&(fetch("/api/providers",{cache:"no-store"}).then(t=>t.json()).then(t=>d(t.connections||[])).catch(()=>{}),r&&fetch("/api/provider-nodes",{cache:"no-store"}).then(t=>t.json()).then(t=>n((t.nodes||[]).filter(c=>c.type==="custom-embedding"))).catch(()=>{}),u&&fetch("/api/combos",{cache:"no-store"}).then(t=>t.json()).then(t=>p(t.combos||[])).catch(()=>{}))},[r,u,m]),!m)return null;const k=I(s),C=y.filter(t=>t.kind===s),a=l.map(t=>({id:t.id,name:t.name||"Custom Embedding",color:"#6366F1",textIcon:"CE"})),x=[...k,...a],S=async(t,c)=>{const w=i.filter(f=>f.provider===t);d(f=>f.map(g=>g.provider===t?{...g,isActive:c}:g)),await Promise.allSettled(w.map(f=>fetch(`/api/providers/${f.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:c})})))},O=async()=>{const t=L[s]||`${s}-combo`;let c=t,w=1;const f=new Set(y.map(N=>N.name));for(;f.has(c);)c=`${t}-${w++}`;const g=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:c,models:[],kind:s})});if(g.ok){const N=await g.json();o(`/dashboard/media-providers/combo/${N.id}`)}else{const N=await g.json();alert(N.error||"Failed to create combo")}};return e.jsxs("div",{className:"flex flex-col gap-6",children:[(r||u)&&e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[u&&e.jsx(E,{size:"sm",icon:"add",onClick:O,children:"Create Combo"}),r&&e.jsx(E,{size:"sm",icon:"add",onClick:()=>h(!0),children:"Add Custom Embedding"})]}),u&&C.length>0&&e.jsx(U,{combos:C}),x.length===0?e.jsxs("div",{className:"text-center py-12 border border-dashed border-border rounded-xl text-text-muted text-sm",children:["No providers support ",e.jsx("strong",{children:m.label})," yet."]}):e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:[k.map(t=>e.jsx($,{provider:t,kind:s,connections:i,onToggle:S},t.id)),a.map(t=>e.jsx($,{provider:t,kind:s,connections:i,isCustom:!0,onToggle:S},t.id))]}),r&&e.jsx(R,{isOpen:v,onClose:()=>h(!1),onCreated:t=>{n(c=>[...c,t]),h(!1)}})]})}export{G as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./index.BO_pNnMt.js";import{b as r}from"./router.Cjj1--8t.js";import{C as j}from"./Loading.BoU3gy5K.js";import"./zustand.akaTi5uX.js";function P(){return e.jsx(r.Suspense,{fallback:e.jsx(j,{}),children:e.jsx(v,{})})}function v(){const[o,u]=r.useState([]),[p,b]=r.useState(!0),[s,f]=r.useState(""),[a,n]=r.useState(null),[i,d]=r.useState(!1),[l,x]=r.useState(""),[c,m]=r.useState(null);r.useEffect(()=>{fetch("/api/media-providers/moderation").then(t=>t.json()).then(t=>{u(Array.isArray(t)?t:[]),t.length>0&&x(t[0].id)}).catch(()=>{}).finally(()=>b(!1))},[]);const h=async()=>{if(s.trim()){d(!0),m(null),n(null);try{const t=await fetch("/api/media/moderation",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:s,providerId:l||void 0})});if(!t.ok)throw new Error(`HTTP ${t.status}`);const g=await t.json();n(g)}catch(t){m(t.message)}finally{d(!1)}}};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[28px] text-primary",children:"shield"}),e.jsx("h1",{className:"text-xl font-semibold text-text-main",children:"Moderations"})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Moderation Providers"}),p?e.jsx("p",{className:"text-xs text-text-muted",children:"Loading providers..."}):o.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:"No moderation providers configured. Add one in Media Providers."}):e.jsx("div",{className:"flex flex-wrap gap-2",children:o.map(t=>e.jsx("button",{onClick:()=>x(t.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-colors cursor-pointer ${l===t.id?"bg-primary/10 text-primary border border-primary/30":"bg-surface-2 text-text-muted hover:text-text-main border border-transparent"}`,children:t.name||t.id},t.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Test Moderation"}),e.jsx("textarea",{value:s,onChange:t=>f(t.target.value),placeholder:"Enter text to moderate...",rows:4,className:"w-full rounded-lg border border-border-subtle bg-surface-2 px-3 py-2 text-sm text-text-main placeholder:text-text-muted/50 focus:outline-none focus:ring-1 focus:ring-primary/50 resize-none mb-3"}),e.jsx("button",{onClick:h,disabled:i||!s.trim(),className:"px-4 py-2 rounded-lg bg-primary text-white text-sm font-medium hover:bg-primary/90 disabled:opacity-50 transition-colors cursor-pointer",children:i?"Testing...":"Run Moderation"})]}),c&&e.jsx("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-4",children:e.jsx("p",{className:"text-sm text-red-400",children:c})}),a&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Result"}),e.jsx("pre",{className:"text-xs text-text-muted overflow-auto max-h-96 bg-surface-2 rounded-lg p-3 font-mono whitespace-pre-wrap",children:JSON.stringify(a,null,2)})]})]})}export{P as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{j as t}from"./index.BO_pNnMt.js";import{b as a}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function g(){const[s,u]=a.useState(""),[n,i]=a.useState(""),[r,l]=a.useState(null),[o,c]=a.useState(!1),d=async()=>{c(!0);try{const e=await fetch("/api/rerank",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:s,documents:n.split(`
|
|
2
|
+
`).filter(Boolean)})});l(await e.json())}catch(e){l({error:e.message})}c(!1)};return t.jsxs("div",{className:"space-y-6 p-6",children:[t.jsx("h1",{className:"text-2xl font-bold",children:"Rerank"}),t.jsx("p",{className:"text-text-muted",children:"Rerank documents by relevance using Cohere-compatible API"}),t.jsx("input",{className:"w-full p-3 rounded-lg border",placeholder:"Query",value:s,onChange:e=>u(e.target.value)}),t.jsx("textarea",{className:"w-full p-3 rounded-lg border h-40",placeholder:"Documents (one per line)",value:n,onChange:e=>i(e.target.value)}),t.jsx("button",{onClick:d,disabled:o,className:"px-4 py-2 bg-primary text-white rounded-lg",children:o?"Reranking...":"Rerank"}),r&&t.jsx("pre",{className:"p-4 bg-black/5 rounded-lg text-sm overflow-auto",children:JSON.stringify(r,null,2)})]})}export{g as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h as et,j as e,U as tt,P as Ae}from"./index.BO_pNnMt.js";import{b as c}from"./router.Cjj1--8t.js";import{C as rt}from"./Loading.BoU3gy5K.js";import{C as ce,T as st,E as nt}from"./NoAuthProxyCard.CLW2-XwE.js";import"./zustand.akaTi5uX.js";function at(s){if(!s)return"-";try{const u=(typeof s=="string"?new Date(s):s)-new Date;if(u<=0)return"-";const l=Math.ceil(u/(1e3*60));if(l<60)return`${l}m`;const a=Math.floor(l/60),x=l%60;if(a<24)return`${a}h ${x}m`;const h=Math.floor(a/24),p=a%24;return`${h}d ${p}h ${x}m`}catch{return"-"}}function $e(s,n){return!n||n===0?0:!s||s<0?100:s>=n?0:Math.round((n-s)/n*100)}function it(s){return(s==null?void 0:s.remaining)!==void 0?Math.max(0,Math.round(s.remaining)):(s==null?void 0:s.remainingPercentage)!==void 0?Math.round(s.remainingPercentage):$e(s==null?void 0:s.used,s==null?void 0:s.total)}function ot(s,n){if(!n||typeof n!="object")return[];const o=[];try{switch(s.toLowerCase()){case"github":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null})});break;case"antigravity":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:a.displayName||l,modelKey:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,remainingPercentage:a.remainingPercentage})});break;case"codex":if(n.quotas){const l={session:"Session (5h)",weekly:"Weekly (7d)",code_review:"Code Review",code_review_weekly:"Code Review Weekly",spark:"Spark",spark_weekly:"Spark Weekly"};Object.entries(n.quotas).forEach(([a,x])=>{o.push({name:x.displayName||l[a]||a,used:x.used||0,total:x.total||0,remaining:x.remaining,resetAt:x.resetAt||null})})}n.bankedResetCredits!==void 0&&n.bankedResetCredits>0&&o.push({name:"Banked Reset Credits",used:0,total:n.bankedResetCredits,remaining:n.bankedResetCredits,resetAt:null});break;case"kiro":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null})});break;case"qoder":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{l==="organization"&&(!a||(Number(a.total)||0)===0)||o.push({name:l==="user"?"Personal":l==="organization"?"Organization":l,used:a.used||0,total:a.total||0,unit:a.unit,resetAt:a.resetAt||null})});break;case"claude":n.message?o.push({name:"error",used:0,total:0,resetAt:null,message:n.message}):n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null})});break;case"leonardo":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l==="tokens"?"Tokens":l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,unit:a.unit||null,remaining:a.remaining!==void 0?a.remaining:null})});break;case"weavy":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l==="tokens"?"tokens":l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,unit:a.unit||null,remaining:a.remaining!==void 0?a.remaining:null})});break;case"cloudflare-ai":n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,unit:a.unit||"neurons"})});break;default:n.quotas&&Object.entries(n.quotas).forEach(([l,a])=>{o.push({name:l,used:a.used||0,total:a.total||0,resetAt:a.resetAt||null,unit:a.unit||null,remaining:a.remaining!==void 0?a.remaining:null})})}}catch(l){return console.error(`Error parsing quota data for ${s}:`,l),[]}const u=et(s);if(u.length>0){const l=new Map(u.map((a,x)=>[a.id,x]));o.sort((a,x)=>{const h=a.modelKey||a.name,p=x.modelKey||x.name,U=l.get(h)??999,G=l.get(p)??999;return U-G})}return o}const W=10;function lt(s){if(!s)return null;try{const n=new Date(s),o=new Date,u=new Date(o.getFullYear(),o.getMonth(),o.getDate()),l=new Date(u);l.setDate(l.getDate()+1);let a="";n>=u&&n<l?a="Today":n>=l&&n<new Date(l.getTime()+1440*60*1e3)?a="Tomorrow":a=n.toLocaleDateString("en-US",{month:"short",day:"numeric"});const x=n.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});return`${a}, ${x}`}catch{return null}}function ct(s){return s>70?{text:"text-green-600 dark:text-green-400",bg:"bg-green-500",bgLight:"bg-green-500/10",emoji:"🟢"}:s>=30?{text:"text-yellow-600 dark:text-yellow-400",bg:"bg-yellow-500",bgLight:"bg-yellow-500/10",emoji:"🟡"}:{text:"text-red-600 dark:text-red-400",bg:"bg-red-500",bgLight:"bg-red-500/10",emoji:"🔴"}}function dt(s,n){return n==="remaining-asc"?[...s].sort((o,u)=>o.remaining-u.remaining||o.name.localeCompare(u.name)):n==="remaining-desc"?[...s].sort((o,u)=>u.remaining-o.remaining||o.name.localeCompare(u.name)):s}function ut({quotas:s=[],compact:n=!1,sortMode:o="default",showSortLabel:u=!1}){const[l,a]=c.useState(1),x=c.useMemo(()=>s.map((m,f)=>({...m,index:f,remaining:it(m)})),[s]),h=c.useMemo(()=>dt(x,o),[x,o]),p=Math.max(1,Math.ceil(h.length/W));if(c.useEffect(()=>{a(1)},[o,s]),c.useEffect(()=>{a(m=>Math.min(m,p))},[p]),!s||s.length===0)return null;const U=h.slice((l-1)*W,l*W),G=h.length===0?0:(l-1)*W+1,V=Math.min(l*W,h.length),b=n?"py-1 px-1.5":"py-2 px-3",q=n?"text-[11px]":"text-sm",v=n?"text-[11px]":"text-sm",J=n?"text-[10px] leading-tight":"text-xs";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[h.length," quota",h.length>1?"s":""]}),u&&e.jsx("div",{className:"rounded-md border border-black/10 bg-black/[0.02] px-2 py-1 text-[10px] text-text-muted dark:border-white/10 dark:bg-white/[0.03]",children:"Sorted by account remaining"})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"w-full table-fixed text-left",children:e.jsx("tbody",{children:U.map(m=>{var B;const f=ct(m.remaining),I=at(m.resetAt),D=lt(m.resetAt),te=((B=m.name)==null?void 0:B.toLowerCase())==="tokens"?Math.max(0,m.total-m.used):m.used;return e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:`${b} w-[30%]`,children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-[10px] shrink-0",children:f.emoji}),e.jsx("span",{className:`${q} font-medium text-text-primary truncate`,children:m.name})]})}),e.jsx("td",{className:`${b} w-[45%]`,children:e.jsxs("div",{className:n?"space-y-1":"space-y-1.5",children:[e.jsx("div",{className:`${n?"h-1":"h-1.5"} rounded-full overflow-hidden border ${f.bgLight} ${m.remaining===0?"border-black/10 dark:border-white/10":"border-transparent"}`,children:e.jsx("div",{className:`h-full transition-all duration-300 ${f.bg}`,style:{width:`${Math.min(m.remaining,100)}%`}})}),e.jsxs("div",{className:`flex items-center justify-between ${n?"text-[10px]":"text-xs"}`,children:[e.jsxs("span",{className:"text-text-muted",children:[te.toLocaleString()," / ",m.total>0?m.total.toLocaleString():"∞"]}),e.jsxs("span",{className:`font-medium ${f.text}`,children:[m.remaining,"%"]})]})]})}),e.jsx("td",{className:`${b} w-[25%]`,children:I!=="-"||D?n?e.jsx("div",{className:`${v} text-text-primary font-medium truncate`,title:D||"",children:I!=="-"?`in ${I}`:D}):e.jsxs("div",{className:"space-y-0.5",children:[I!=="-"&&e.jsxs("div",{className:`${v} text-text-primary font-medium`,children:["in ",I]}),D&&e.jsx("div",{className:`${J} text-text-muted`,children:D})]}):e.jsx("div",{className:`${v} text-text-muted italic`,children:"N/A"})})]},`${m.name}-${m.index}`)})})})}),p>1&&e.jsxs("div",{className:"rounded-md border border-black/10 bg-black/[0.02] px-2 py-1.5 dark:border-white/10 dark:bg-white/[0.03]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-[10px] text-text-muted",children:[e.jsxs("span",{children:["Showing ",G,"-",V," of ",h.length]}),e.jsxs("span",{children:["Page ",l," / ",p]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>a(m=>Math.max(1,m-1)),disabled:l===1,className:"flex h-6 items-center rounded-md border border-black/10 px-2 text-[10px] text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5",children:"Prev"}),e.jsx("button",{type:"button",onClick:()=>a(m=>Math.min(p,m+1)),disabled:l===p,className:"flex h-6 items-center rounded-md border border-black/10 px-2 text-[10px] text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5",children:"Next"})]})]})]})}function X(s){const n=o=>typeof o=="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o);return n(s.email)?s.email:(n(s.name),s.name)}function mt(s,n,o){if(!o)return s;const u=l=>{var x;const a=(((x=n[l.id])==null?void 0:x.quotas)||[]).map(h=>h.resetAt?new Date(h.resetAt).getTime():Number.POSITIVE_INFINITY).filter(h=>Number.isFinite(h));return a.length>0?Math.min(...a):Number.POSITIVE_INFINITY};return[...s].sort((l,a)=>{const x=u(l)-u(a);return x!==0?x:(l.provider||"").localeCompare(a.provider||"")||(X(l)||"").localeCompare(X(a)||"")})}function Pe(s){const n={};return s.forEach(o=>{n[o.id]=!0}),n}function Z(s,n){const o=new Set(n.map(u=>u.id));return Object.fromEntries(Object.entries(s).filter(([u])=>o.has(u)))}function xt(s){if(!s.total)return{start:0,end:0};const n=(s.page-1)*s.pageSize+1,o=Math.min(s.page*s.pageSize,s.total);return{start:n,end:o}}function ht(s,n,o){return s.eligibleConnections?s.providerFilteredConnections?{icon:"filter_alt_off",title:"No Accounts On This Page",description:"Try moving to another page or refreshing the current filters."}:{icon:"filter_alt_off",title:"No Accounts Match Current Filters",description:n==="all"?"Try changing the account status filter to see more quota trackers.":`No ${o==="inactive"?"turned off":o==="active"?"active":"matching"} accounts found for ${n}.`}:{icon:"cloud_off",title:"No Providers Connected",description:"Connect to providers with OAuth to track your API quota limits and usage."}}function pt(s){const{start:n,end:o}=xt(s);return`Showing ${n}-${o} of ${s.total}`}function bt(s,n){return s||{page:1,pageSize:n,total:0,totalPages:1}}function gt(s,n=0){return s||{eligibleConnections:n,providerFilteredConnections:n}}function de(s,n){return s!==n}function ft(s,n){return(s==null?void 0:s.page)||n}function yt(s){return s||[]}async function ue(s,n){return await s(n)}const he="quotaCacheData";function Me(){if(typeof window>"u")return{};try{const s=window.localStorage.getItem(he);return s?JSON.parse(s):{}}catch(s){return console.error("Error reading quota cache:",s),{}}}function Te(s,n){if(!(typeof window>"u"))try{const o=Me();o[s]={...n,cachedAt:new Date().toISOString()},window.localStorage.setItem(he,JSON.stringify(o))}catch(o){console.error("Error writing quota cache:",o)}}const Oe=6e4,vt=5,Ie="quotaAutoRefresh",wt=[{value:"all",label:"All accounts"},{value:"active",label:"Active"},{value:"inactive",label:"Turned off"}],kt=[{value:"default",label:"Default order"},{value:"remaining-asc",label:"Least credits first"},{value:"remaining-desc",label:"Most credits first"},{value:"balance-asc",label:"Saldo Terendah (Lowest Balance)"},{value:"balance-desc",label:"Saldo Tertinggi (Highest Balance)"}],me=20,De=[10,20,50,100],xe=500;function jt(){const[s,n]=c.useState([]),[o,u]=c.useState({}),[l,a]=c.useState({}),[x,h]=c.useState({}),[p,U]=c.useState(!0),[G,V]=c.useState(null),[b,q]=c.useState(!1),[v,J]=c.useState(!1),[pe,m]=c.useState(60),[f,I]=c.useState(!0),[D,ee]=c.useState(null),[te,B]=c.useState(null),[_e,re]=c.useState(!1),[R,se]=c.useState(null),[Re,Le]=c.useState([]),[A,ne]=c.useState("all"),[Fe,be]=c.useState([]),[L,ge]=c.useState("all"),[P,fe]=c.useState("default"),[F,ze]=c.useState(!1),[Nt,St]=c.useState(!1),[Y,ye]=c.useState(!1),[w,C]=c.useState(1),[$,ae]=c.useState(me),[ie,Q]=c.useState(String(me)),[E,ve]=c.useState({page:1,pageSize:me,total:0,totalPages:1}),[k,we]=c.useState({eligibleConnections:0,providerFilteredConnections:0}),T=c.useRef(null),O=c.useRef(null),j=c.useCallback(async(t=w)=>{try{let r="priority";F?r="expiring":P==="remaining-asc"?r="usage-asc":P==="remaining-desc"?r="usage-desc":P==="balance-asc"?r="balance-asc":P==="balance-desc"&&(r="balance-desc");const i=new URLSearchParams({page:String(t),pageSize:String($),accountStatus:L,sort:r});A!=="all"&&i.set("provider",A);const d=await fetch(`/api/providers/client?${i.toString()}`);if(!d.ok)throw new Error("Failed to fetch connections");const N=await d.json(),g=N.connections||[],y=bt(N.pagination,$),S=gt(N.totals,g.length);return n(g),be(yt(N.providerOptions)),ve(y),we(S),C(ft(N.pagination,t)),g}catch(r){return console.error("Error fetching connections:",r),n([]),be([]),ve({page:1,pageSize:$,total:0,totalPages:1}),we({eligibleConnections:0,providerFilteredConnections:0}),[]}},[L,F,w,$,A,P]),M=c.useCallback(async(t,r)=>{a(i=>({...i,[t]:!0})),h(i=>({...i,[t]:null}));try{const i=await fetch(`/api/usage/${t}`);if(!i.ok){const S=(await i.json().catch(()=>({}))).error||i.statusText;if(i.status===404)return;if(i.status===401){const _={quotas:[],message:S};u(H=>({...H,[t]:_})),Te(t,_);return}throw new Error(`HTTP ${i.status}: ${S}`)}const d=await i.json(),g={quotas:ot(r,d),plan:d.plan||null,message:d.message||null,raw:d};u(y=>({...y,[t]:g})),Te(t,g)}catch(i){h(d=>({...d,[t]:i.message||"Failed to fetch quota"}))}finally{a(i=>({...i,[t]:!1}))}},[]),Ue=c.useCallback(async(t,r)=>{await M(t,r),V(new Date)},[M]),Qe=c.useCallback(async t=>{if(confirm("Delete this connection?")){ee(t);try{if((await fetch(`/api/providers/${t}`,{method:"DELETE"})).ok){if(u(i=>{const d={...i};return delete d[t],d}),a(i=>{const d={...i};return delete d[t],d}),h(i=>{const d={...i};return delete d[t],d}),typeof window<"u")try{const i=Me();i[t]&&(delete i[t],window.localStorage.setItem(he,JSON.stringify(i)))}catch(i){console.error("Error deleting cache entry:",i)}await ue(j,w)}}catch(r){console.error("Error deleting connection:",r)}finally{ee(null)}}},[j,w]),He=c.useCallback(async(t,r)=>{B(t);try{(await fetch(`/api/providers/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:r})})).ok&&(u(d=>({...d})),await ue(j,w))}catch(i){console.error("Error updating connection status:",i)}finally{B(null)}},[j,w]),Ve=c.useCallback(async t=>{if(!(R!=null&&R.id))return;const r=R.id,i=R.provider;try{(await fetch(`/api/providers/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok&&(await j(),re(!1),se(null),tt.includes(i)&&await M(r,i))}catch(d){console.error("Error saving connection:",d)}},[R,j,M]);c.useEffect(()=>{let t=!1;return fetch("/api/proxy-pools?isActive=true",{cache:"no-store"}).then(r=>r.json()).then(r=>{!t&&(r!=null&&r.proxyPools)&&Le(r.proxyPools)}).catch(()=>{}),()=>{t=!0}},[]);const K=c.useCallback(async()=>{if(!v){J(!0),m(60);try{const t=await j(w);a(Pe(t)),h(r=>Z(r,t)),u(r=>Z(r,t)),await Promise.all(t.map(r=>M(r.id,r.provider))),V(new Date)}catch(t){console.error("Error refreshing all providers:",t)}finally{J(!1)}}},[v,j,M,w]);c.useEffect(()=>{if(!b)return;(async()=>{I(!0);const r=await j(w);I(!1),a(Pe(r)),h(i=>Z(i,r)),u(i=>Z(i,r)),await Promise.all(r.map(i=>M(i.id,i.provider))),V(new Date)})()},[j,M,w,b]);const ke="quotaProviderFilter",je="quotaAccountFilter",Ne="quotaSortMode";c.useEffect(()=>{if(typeof window>"u")return;const t=window.localStorage.getItem(Ie);U(t===null?!0:t==="true");const r=window.localStorage.getItem(ke);r&&ne(r);const i=window.localStorage.getItem(je);i&&ge(i);const d=window.localStorage.getItem(Ne);d&&fe(d),q(!0)},[]),c.useEffect(()=>{typeof window>"u"||!b||window.localStorage.setItem(Ie,String(p))},[p,b]),c.useEffect(()=>{typeof window>"u"||!b||window.localStorage.setItem(ke,A)},[A,b]),c.useEffect(()=>{typeof window>"u"||!b||window.localStorage.setItem(je,L)},[L,b]),c.useEffect(()=>{typeof window>"u"||!b||window.localStorage.setItem(Ne,P)},[P,b]),c.useEffect(()=>{if(!b||!p){T.current&&(clearInterval(T.current),T.current=null),O.current&&(clearInterval(O.current),O.current=null);return}return T.current=setInterval(()=>{K()},Oe),O.current=setInterval(()=>{m(t=>t<=1?60:t-1)},1e3),()=>{T.current&&clearInterval(T.current),O.current&&clearInterval(O.current)}},[p,K,b]),c.useEffect(()=>{const t=()=>{document.hidden?(T.current&&(clearInterval(T.current),T.current=null),O.current&&(clearInterval(O.current),O.current=null)):p&&b&&(T.current=setInterval(K,Oe),O.current=setInterval(()=>{m(r=>r<=1?60:r-1)},1e3))};return document.addEventListener("visibilitychange",t),()=>{document.removeEventListener("visibilitychange",t)}},[p,K,b]);const z=c.useMemo(()=>mt(s,o,F),[s,o,F]),Se=t=>{var i;const r=(i=o[t.id])==null?void 0:i.quotas;return r!=null&&r.length?r.some(d=>!d.total||d.total<=0?!1:$e(d.used,d.total)<=vt):!1},Ce=t=>{const r=o[t.id];return r&&r.message==="Account disabled (Credits exhausted)"},oe=c.useCallback(async(t,r)=>{if(!(!t.length||Y)){ye(!0);try{await Promise.all(t.map(i=>fetch(`/api/providers/${i}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:r})}))),await ue(j,w)}catch(i){console.error("Error bulk toggling connections:",i)}finally{ye(!1)}}},[Y,j,w]),Be=()=>{const t=z.filter(r=>(r.isActive??!0)&&Se(r)).map(r=>r.id);oe(t,!1)},Ye=()=>{const t=z.filter(r=>(r.isActive??!0)&&Ce(r)).map(r=>r.id);oe(t,!1)},Ke=()=>{const t=z.filter(r=>!(r.isActive??!0)&&!Se(r)&&!Ce(r)).map(r=>r.id);oe(t,!0)},{totalCredits:We,providerStats:Ge,exhaustedCount:Ee}=c.useMemo(()=>{var N;let t=0;const r={};let i=0;z.forEach(g=>{const y=o[g.id];if(y&&y.message==="Account disabled (Credits exhausted)"&&(i+=1),!y)return;const S=g.provider;r[S]||(r[S]={accounts:0,credits:0}),r[S].accounts+=1,y.quotas&&y.quotas.forEach(_=>{let H=typeof _.remaining=="number"&&Number.isFinite(_.remaining)?_.remaining:Math.max(0,(_.total||0)-(_.used||0));Number.isFinite(H)&&H>0&&S!=="cloudflare-ai"&&(t+=H,r[S].credits+=H)})});const d=((N=k==null?void 0:k.providerCounts)==null?void 0:N["cloudflare-ai"])||0;if(d>0){const g=(k==null?void 0:k.cloudflareAi)!==void 0?Math.max(0,k.cloudflareAi.total-k.cloudflareAi.used):d*1e4;r["cloudflare-ai"]||(r["cloudflare-ai"]={accounts:d,credits:0}),r["cloudflare-ai"].accounts=d,r["cloudflare-ai"].credits=g,t+=g}return{totalCredits:t,providerStats:r,exhaustedCount:i}},[o,z,k]),Je=k.eligibleConnections>0,Ze=z.length>0,le=ht(k,A,L),Xe=pt(E),qe=!De.includes($);return!f&&!Je?e.jsx(ce,{padding:"lg",children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx("span",{className:"material-symbols-outlined text-[64px] text-text-muted opacity-20",children:"cloud_off"}),e.jsx("h3",{className:"mt-4 text-lg font-semibold text-text-primary",children:"No Providers Connected"}),e.jsx("p",{className:"mt-2 text-sm text-text-muted max-w-md mx-auto",children:"Connect to providers with OAuth to track your API quota limits and usage."})]})}):e.jsxs("div",{className:"space-y-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 flex-wrap items-center gap-2 text-sm font-medium text-text-primary px-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 bg-black/5 dark:bg-white/10 px-2.5 py-1 rounded-md",title:"Total active accounts on this page",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-text-muted",children:"group"}),e.jsxs("span",{children:[k.providerFilteredConnections," Accounts"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 bg-primary/10 px-2.5 py-1 rounded-md",title:"Total credits across these accounts",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-primary",children:"database"}),e.jsxs("span",{className:"text-primary",children:[Math.floor(We)," Credits"]})]}),Ee>0&&e.jsxs("div",{className:"flex items-center gap-1.5 bg-red-500/10 px-2.5 py-1 rounded-md",title:"Total exhausted accounts",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-500",children:"warning"}),e.jsxs("span",{className:"text-red-500",children:[Ee," Exhausted"]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1 ml-2",children:Object.entries(Ge).map(([t,r])=>e.jsxs("div",{className:"flex items-center gap-1 bg-black/5 dark:bg-white/5 px-2 py-0.5 rounded text-xs text-text-muted border border-black/10 dark:border-white/10",title:`${r.accounts} accounts`,children:[e.jsx("span",{className:"capitalize",children:t}),": ",e.jsx("span",{className:"font-semibold text-text-primary",children:Math.floor(r.credits)})]},t))})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 justify-end",children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs("button",{type:"button",onClick:()=>{de(A,"all")&&C(1),ne("all")},className:`flex h-8 items-center gap-1.5 rounded-lg px-2.5 text-xs font-medium transition-colors ${A==="all"?"bg-primary/15 text-primary border border-primary/30":"bg-black/5 text-text-muted border border-transparent hover:bg-black/10 dark:bg-white/5 dark:hover:bg-white/10"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"apps"}),e.jsx("span",{children:"All"})]}),Fe.map(t=>e.jsxs("button",{type:"button",onClick:()=>{de(A,t)&&C(1),ne(t)},className:`flex h-8 items-center gap-1.5 rounded-lg px-2.5 text-xs font-medium transition-colors ${A===t?"bg-primary/15 text-primary border border-primary/30":"bg-black/5 text-text-muted border border-transparent hover:bg-black/10 dark:bg-white/5 dark:hover:bg-white/10"}`,children:[e.jsx(Ae,{src:t==="codebuddy"||t==="cb"?"/providers/codebuddy.svg":`/providers/${t}.png`,alt:t,size:16,className:"size-4 rounded object-contain",fallbackText:t.slice(0,2).toUpperCase()}),e.jsx("span",{className:"capitalize",children:t})]},t))]}),e.jsx("select",{value:L,onChange:t=>{const r=t.target.value;de(L,r)&&C(1),ge(r)},className:"h-8 rounded-lg border border-black/10 bg-black/[0.02] px-2 text-xs text-text-primary outline-none transition-colors hover:bg-black/5 dark:border-white/10 dark:bg-white/[0.03] dark:hover:bg-white/10","aria-label":"Filter accounts by status",children:wt.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("select",{value:P,onChange:t=>fe(t.target.value),className:"h-8 rounded-lg border border-black/10 bg-black/[0.02] px-2 text-xs text-text-primary outline-none transition-colors hover:bg-black/5 dark:border-white/10 dark:bg-white/[0.03] dark:hover:bg-white/10","aria-label":"Sort quotas by remaining",children:kt.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsxs("button",{type:"button",onClick:()=>ze(t=>!t),"aria-pressed":F,className:`flex h-8 shrink-0 items-center gap-1 rounded-lg border px-2 text-xs transition-colors ${F?"border-amber-500/40 bg-amber-500/10 text-amber-500":"border-black/10 text-text-primary hover:bg-black/5 dark:border-white/10 dark:hover:bg-white/5"}`,title:"Sort accounts by earliest quota reset time",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"hourglass_top"}),e.jsx("span",{className:"hidden sm:inline",children:"Expiring first"})]}),e.jsxs("button",{type:"button",onClick:Be,disabled:Y,className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-red-500/30 px-2 text-xs text-red-500 transition-colors hover:bg-red-500/10 disabled:opacity-50",title:"Disable connections with depleted quota on the current page",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"block"}),e.jsx("span",{className:"hidden sm:inline",children:"Turn off Empty"})]}),e.jsxs("button",{type:"button",onClick:Ye,disabled:Y,className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-red-500/30 px-2 text-xs text-red-500 transition-colors hover:bg-red-500/10 disabled:opacity-50",title:"Disable connections that are exhausted",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"block"}),e.jsx("span",{className:"hidden sm:inline",children:"Disable Exhausted"})]}),e.jsxs("button",{type:"button",onClick:Ke,disabled:Y,className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-emerald-500/30 px-2 text-xs text-emerald-500 transition-colors hover:bg-emerald-500/10 disabled:opacity-50",title:"Enable connections that still have quota on the current page",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"check_circle"}),e.jsx("span",{className:"hidden sm:inline",children:"Turn on Available"})]}),e.jsxs("button",{onClick:()=>U(t=>!t),className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-black/10 px-2 text-xs transition-colors hover:bg-black/5 dark:border-white/10 dark:hover:bg-white/5",title:p?"Disable auto-refresh":"Enable auto-refresh",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px] ${p?"text-primary":"text-text-muted"}`,children:p?"toggle_on":"toggle_off"}),e.jsx("span",{className:"hidden text-text-primary sm:inline",children:"Auto-refresh"}),p&&e.jsxs("span",{className:"text-[10px] text-text-muted tabular-nums",children:["(",pe,"s)"]})]}),e.jsx("button",{type:"button",onClick:K,disabled:v,className:"flex h-8 shrink-0 items-center gap-1 rounded-lg border border-black/10 px-2 text-xs text-text-primary transition-colors hover:bg-black/5 dark:border-white/10 dark:hover:bg-white/5 disabled:opacity-50",title:"Refresh all",children:e.jsx("span",{className:`material-symbols-outlined text-[14px] ${v?"animate-spin":""}`,children:"refresh"})})]})]}),(F||P!=="default")&&e.jsx("div",{className:"rounded-xl border border-amber-500/20 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300 mb-3",children:"Sorting currently reorders accounts inside the current page. Cross-page ordering still follows backend pagination. Try increasing the page size to sort across more accounts."}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:!f&&!Ze?e.jsx("div",{className:"col-span-1 md:col-span-2",children:e.jsx(ce,{padding:"lg",children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx("span",{className:"material-symbols-outlined text-[64px] text-text-muted opacity-20",children:le.icon}),e.jsx("h3",{className:"mt-4 text-lg font-semibold text-text-primary",children:le.title}),e.jsx("p",{className:"mt-2 text-sm text-text-muted max-w-md mx-auto",children:le.description})]})})}):z.map(t=>{var y;const r=o[t.id],i=l[t.id],d=x[t.id],N=t.isActive===!1,g=D===t.id||te===t.id;return e.jsxs(ce,{padding:"none",className:`min-w-0 ${N?"opacity-60":""}`,children:[e.jsx("div",{className:"px-3 py-2 border-b border-black/10 dark:border-white/10",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 shrink-0 rounded-md flex items-center justify-center overflow-hidden",children:e.jsx(Ae,{src:t.provider==="codebuddy"||t.provider==="cb"?"/providers/codebuddy.svg":`/providers/${t.provider}.png`,alt:t.provider,size:32,className:"object-contain",fallbackText:((y=t.provider)==null?void 0:y.slice(0,2).toUpperCase())||"PR"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-primary capitalize truncate",children:t.provider}),X(t)?e.jsx("p",{className:"text-xs text-text-muted truncate",children:X(t)}):null]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Ue(t.id,t.provider),disabled:i||g,"aria-label":"Refresh quota",className:"p-1.5 rounded-lg hover:bg-black/5 dark:hover:bg-white/5 transition-colors disabled:opacity-50",title:"Refresh quota",children:e.jsx("span",{className:`material-symbols-outlined text-[18px] text-text-muted ${i?"animate-spin":""}`,children:"refresh"})}),e.jsx("button",{type:"button",onClick:()=>{se(t),re(!0)},disabled:g,"aria-label":"Edit connection",className:"p-1.5 rounded-lg hover:bg-black/5 dark:hover:bg-white/5 text-text-muted hover:text-primary transition-colors disabled:opacity-50",title:"Edit connection",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),e.jsx("button",{type:"button",onClick:()=>Qe(t.id),disabled:g,"aria-label":"Delete connection",className:"p-1.5 rounded-lg hover:bg-red-500/10 text-red-500 transition-colors disabled:opacity-50",title:"Delete connection",children:e.jsx("span",{className:`material-symbols-outlined text-[18px] ${D===t.id?"animate-pulse":""}`,children:"delete"})}),e.jsx("div",{className:"inline-flex items-center pl-0.5",title:t.isActive??!0?"Disable connection":"Enable connection",children:e.jsx(st,{size:"sm",checked:t.isActive??!0,disabled:g,onChange:S=>He(t.id,S)})})]})]})}),e.jsx("div",{className:"px-2 py-1.5",children:i?e.jsx("div",{className:"text-center py-5 text-text-muted",children:e.jsx("span",{className:"material-symbols-outlined text-[28px] animate-spin",children:"progress_activity"})}):d?e.jsxs("div",{className:"text-center py-5",children:[e.jsx("span",{className:"material-symbols-outlined text-[28px] text-red-500",children:"error"}),e.jsx("p",{className:"mt-1.5 text-xs text-text-muted",children:d})]}):r!=null&&r.message?e.jsx("div",{className:"text-center py-5",children:e.jsx("p",{className:"text-xs text-text-muted",children:r.message})}):e.jsx(ut,{quotas:r==null?void 0:r.quotas,compact:!0,sortMode:"default",showSortLabel:t.provider==="codex"&&P!=="default"})})]},t.id)})}),e.jsx("div",{className:"rounded-xl border border-black/10 bg-black/[0.02] px-3 py-2 dark:border-white/10 dark:bg-white/[0.03]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-text-muted",children:Xe}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("select",{value:qe?"custom":String($),onChange:t=>{const r=t.target.value;if(r==="custom")return;const i=Number.parseInt(r,10);Number.isFinite(i)&&(C(1),ae(i),Q(String(i)))},className:"h-8 rounded-lg border border-black/10 bg-black/[0.02] px-2 text-xs text-text-primary outline-none transition-colors hover:bg-black/5 dark:border-white/10 dark:bg-white/[0.03] dark:hover:bg-white/10","aria-label":"Accounts per page",children:[De.map(t=>e.jsxs("option",{value:String(t),children:[t," / page"]},t)),e.jsx("option",{value:"500",children:"500 / page"}),e.jsx("option",{value:"1000",children:"1000 / page"}),e.jsx("option",{value:"custom",children:"Custom"})]}),e.jsx("input",{type:"number",min:"1",max:String(xe),inputMode:"numeric",value:ie,onChange:t=>Q(t.target.value),onBlur:()=>{const t=Number.parseInt(ie,10);if(!Number.isFinite(t)){Q(String($));return}const r=Math.min(xe,Math.max(1,t));C(1),ae(r),Q(String(r))},onKeyDown:t=>{if(t.key!=="Enter")return;const r=Number.parseInt(ie,10);if(!Number.isFinite(r)){Q(String($));return}const i=Math.min(xe,Math.max(1,r));C(1),ae(i),Q(String(i))},className:"h-8 w-20 rounded-lg border border-black/10 bg-black/[0.02] px-2 text-xs text-text-primary outline-none transition-colors hover:bg-black/5 dark:border-white/10 dark:bg-white/[0.03] dark:hover:bg-white/10","aria-label":"Custom accounts per page",placeholder:"Custom"}),e.jsxs("span",{className:"text-xs text-text-muted",children:["Page ",E.page," / ",E.totalPages]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{suppressHydrationWarning:!0,type:"button",onClick:()=>C(1),disabled:E.page<=1||f||v,className:"flex h-8 items-center rounded-lg border border-black/10 px-3 text-xs text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5",children:"First Page"}),e.jsx("button",{suppressHydrationWarning:!0,type:"button",onClick:()=>C(t=>Math.max(1,t-1)),disabled:E.page<=1||f||v,className:"flex h-8 w-8 items-center justify-center rounded-lg border border-black/10 text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5","aria-label":"Previous accounts page",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"chevron_left"})}),e.jsx("button",{suppressHydrationWarning:!0,type:"button",onClick:()=>C(t=>Math.min(E.totalPages,t+1)),disabled:E.page>=E.totalPages||f||v,className:"flex h-8 w-8 items-center justify-center rounded-lg border border-black/10 text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5","aria-label":"Next accounts page",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"chevron_right"})}),e.jsx("button",{suppressHydrationWarning:!0,type:"button",onClick:()=>C(E.totalPages),disabled:E.page>=E.totalPages||f||v,className:"flex h-8 items-center rounded-lg border border-black/10 px-3 text-xs text-text-primary transition-colors hover:bg-black/5 disabled:cursor-not-allowed disabled:opacity-40 dark:border-white/10 dark:hover:bg-white/5",children:"Last Page"})]})]})}),e.jsx(nt,{isOpen:_e,connection:R,proxyPools:Re,onSave:Ve,onClose:()=>{re(!1),se(null)}})]})}function Ot(){return e.jsx(c.Suspense,{fallback:e.jsx(rt,{}),children:e.jsx(jt,{})})}export{Ot as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./index.BO_pNnMt.js";import{b as n,f as h}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function u(){const[s]=h(),[a,l]=n.useState("processing");return n.useEffect(()=>{const r=s.get("code"),i=s.get("state"),o=s.get("error"),d=s.get("error_description"),c={code:r,state:i,error:o,errorDescription:d,fullUrl:window.location.href},m=[window.location.origin,"http://localhost:1455","http://localhost:51121"];if(window.opener)for(const t of m)try{window.opener.postMessage({type:"oauth_callback",data:c},t)}catch(x){console.log("postMessage failed:",x)}try{const t=new BroadcastChannel("oauth_callback");t.postMessage(c),t.close()}catch(t){console.log("BroadcastChannel failed:",t)}try{localStorage.setItem("oauth_callback",JSON.stringify({...c,timestamp:Date.now()}))}catch(t){console.log("localStorage failed:",t)}if(!(r||o)){setTimeout(()=>l("manual"),0);return}l("success"),setTimeout(()=>{window.close(),setTimeout(()=>l("done"),500)},1500)},[s]),e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-bg",children:e.jsxs("div",{className:"text-center p-8 max-w-md",children:[a==="processing"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-primary animate-spin",children:"progress_activity"})}),e.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Processing..."}),e.jsx("p",{className:"text-text-muted",children:"Please wait while we complete the authorization."})]}),(a==="success"||a==="done")&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-green-600",children:"check_circle"})}),e.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Authorization Successful!"}),e.jsx("p",{className:"text-text-muted",children:a==="success"?"This window will close automatically...":"You can close this tab now."})]}),a==="manual"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-yellow-100 dark:bg-yellow-900/30 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-yellow-600",children:"info"})}),e.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Copy This URL"}),e.jsx("p",{className:"text-text-muted mb-4",children:"Please copy the URL from the address bar and paste it in the application."}),e.jsx("div",{className:"bg-surface border border-border rounded-lg p-3 text-left",children:e.jsx("code",{className:"text-xs break-all",children:typeof window<"u"?window.location.href:""})})]})]})})}function b(){return e.jsx(n.Suspense,{fallback:e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-bg",children:e.jsxs("div",{className:"text-center p-8",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-primary animate-spin",children:"progress_activity"})}),e.jsx("p",{className:"text-text-muted",children:"Loading..."})]})}),children:e.jsx(u,{})})}export{b as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./index.BO_pNnMt.js";import{b as s}from"./router.Cjj1--8t.js";import"./zustand.akaTi5uX.js";function u(){const[a,o]=s.useState(""),[l,r]=s.useState(null),[n,c]=s.useState(!1),i=async()=>{c(!0);try{const t=await fetch("/api/web/fetch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:a})});r(await t.json())}catch(t){r({error:t.message})}c(!1)};return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Web Fetch"}),e.jsx("p",{className:"text-text-muted",children:"Fetch web content via Firecrawl, Jina, Tavily, or TinyFish"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:"flex-1 p-3 rounded-lg border",placeholder:"https://example.com",value:a,onChange:t=>o(t.target.value)}),e.jsx("button",{onClick:i,disabled:n,className:"px-4 py-2 bg-primary text-white rounded-lg",children:n?"Fetching...":"Fetch"})]}),l&&e.jsx("pre",{className:"p-4 bg-black/5 rounded-lg text-sm overflow-auto max-h-96",children:JSON.stringify(l,null,2)})]})}export{u as default};
|