@fudrouter/fsrouter 0.6.77 → 0.6.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/bin/rewriteSseImports.js +13 -15
  2. package/dist/lib/oauth/constants/oauth.js +2 -0
  3. package/dist/lib/oauth/providers.js +72 -0
  4. package/dist/open-sse/handlers/chatCore/nonStreamingHandler.js +1 -1
  5. package/dist/open-sse/handlers/chatCore/requestDetail.js +1 -1
  6. package/dist/open-sse/handlers/chatCore/sseToJsonHandler.js +1 -1
  7. package/dist/open-sse/handlers/chatCore/streamingHandler.js +1 -1
  8. package/dist/open-sse/handlers/imageProviders/leonardo.js +1 -1
  9. package/dist/open-sse/handlers/imageProviders/weavy.js +1 -1
  10. package/dist/open-sse/handlers/videoProviders/weavy.js +1 -1
  11. package/dist/open-sse/mcp-server/tools/advancedTools.js +2 -2
  12. package/dist/open-sse/mcp-server/tools/agentSkillTools.js +1 -1
  13. package/dist/open-sse/mcp-server/tools/compressionTools.js +4 -4
  14. package/dist/open-sse/mcp-server/tools/gamificationTools.js +10 -10
  15. package/dist/open-sse/mcp-server/tools/githubSkillTools.js +1 -1
  16. package/dist/open-sse/mcp-server/tools/memoryTools.js +3 -3
  17. package/dist/open-sse/mcp-server/tools/notionTools.js +2 -2
  18. package/dist/open-sse/mcp-server/tools/obsidianTools.js +2 -2
  19. package/dist/open-sse/mcp-server/tools/pickFastestModel.js +1 -1
  20. package/dist/open-sse/mcp-server/tools/pluginTools.js +4 -4
  21. package/dist/open-sse/mcp-server/tools/skillTools.js +2 -2
  22. package/dist/open-sse/providers/index.js +1 -1
  23. package/dist/open-sse/providers/registry/nous-research.js +10 -2
  24. package/dist/open-sse/services/combo/quotaExhaustionCutoff.js +2 -2
  25. package/dist/open-sse/services/combo/quotaShareStrategy.js +1 -1
  26. package/dist/open-sse/services/combo/resolveAutoStrategy.js +1 -1
  27. package/dist/open-sse/services/combo/sessionStickiness.js +1 -1
  28. package/dist/open-sse/services/combo/targetSorters.js +2 -2
  29. package/dist/open-sse/services/combo/validateQuality.js +1 -1
  30. package/dist/open-sse/services/tokenRefresh/providers.js +3 -3
  31. package/dist/routes/headroom/extras/route.js +2 -2
  32. package/dist/shared/constants/providers.js +1 -1
  33. package/open-sse/handlers/chatCore/nonStreamingHandler.js +1 -1
  34. package/open-sse/handlers/chatCore/requestDetail.js +1 -1
  35. package/open-sse/handlers/chatCore/sseToJsonHandler.js +1 -1
  36. package/open-sse/handlers/chatCore/streamingHandler.js +1 -1
  37. package/open-sse/handlers/imageProviders/leonardo.js +1 -1
  38. package/open-sse/handlers/imageProviders/weavy.js +1 -1
  39. package/open-sse/handlers/videoProviders/weavy.js +1 -1
  40. package/open-sse/mcp-server/tools/advancedTools.js +2 -2
  41. package/open-sse/mcp-server/tools/agentSkillTools.js +1 -1
  42. package/open-sse/mcp-server/tools/compressionTools.js +4 -4
  43. package/open-sse/mcp-server/tools/gamificationTools.js +10 -10
  44. package/open-sse/mcp-server/tools/githubSkillTools.js +1 -1
  45. package/open-sse/mcp-server/tools/memoryTools.js +3 -3
  46. package/open-sse/mcp-server/tools/notionTools.js +2 -2
  47. package/open-sse/mcp-server/tools/obsidianTools.js +2 -2
  48. package/open-sse/mcp-server/tools/pickFastestModel.js +1 -1
  49. package/open-sse/mcp-server/tools/pluginTools.js +4 -4
  50. package/open-sse/mcp-server/tools/skillTools.js +2 -2
  51. package/open-sse/providers/index.js +1 -1
  52. package/open-sse/providers/registry/nous-research.js +10 -2
  53. package/open-sse/services/combo/quotaExhaustionCutoff.js +2 -2
  54. package/open-sse/services/combo/quotaShareStrategy.js +1 -1
  55. package/open-sse/services/combo/resolveAutoStrategy.js +1 -1
  56. package/open-sse/services/combo/sessionStickiness.js +1 -1
  57. package/open-sse/services/combo/targetSorters.js +2 -2
  58. package/open-sse/services/combo/validateQuality.js +1 -1
  59. package/open-sse/services/tokenRefresh/providers.js +3 -3
  60. package/package.json +1 -1
  61. package/public/.vite/manifest.json +197 -85
  62. package/public/assets/EndpointPageClient.BNiu_vhL.js +6 -0
  63. package/public/assets/Loading.CRvAR61e.js +1 -0
  64. package/public/assets/NoAuthProxyCard.BARTPHmg.js +89 -0
  65. package/public/assets/index.BbQSujX0.js +89 -0
  66. package/public/assets/page.2cfQ0soc.js +5 -0
  67. package/public/assets/page.Azr84Ml-.js +1 -0
  68. package/public/assets/page.B57i00nL.js +1 -0
  69. package/public/assets/page.BTTzRlp6.js +1 -0
  70. package/public/assets/page.BY5IysJR.js +2 -0
  71. package/public/assets/page.BYy5vdYY.js +1 -0
  72. package/public/assets/page.Bkhxy2VJ.js +1 -0
  73. package/public/assets/page.BrLVxn10.js +1 -0
  74. package/public/assets/page.C0TLs5yW.js +1 -0
  75. package/public/assets/page.C1MGHZJw.js +1 -0
  76. package/public/assets/page.C5qOhBBX.js +1 -0
  77. package/public/assets/page.CL7pbImn.js +1 -0
  78. package/public/assets/page.CLbi_S1p.js +1 -0
  79. package/public/assets/page.CNUurvtj.js +23 -0
  80. package/public/assets/page.CWyZKaVw.js +31 -0
  81. package/public/assets/page.CXKvW0hn.js +1 -0
  82. package/public/assets/page.CXXS5Pj6.js +4 -0
  83. package/public/assets/page.CavjztiR.js +1 -0
  84. package/public/assets/page.CiURc2ed.js +64 -0
  85. package/public/assets/page.CjbJHAqY.js +1 -0
  86. package/public/assets/page.CqKdcCXs.js +5 -0
  87. package/public/assets/page.CuZp1ItQ.js +1 -0
  88. package/public/assets/page.Cx7iFgCR.js +1 -0
  89. package/public/assets/page.D023izTv.js +6 -0
  90. package/public/assets/page.D5dHsYMc.js +1 -0
  91. package/public/assets/page.DIBe8_S7.js +1 -0
  92. package/public/assets/page.DOS_9ovb.js +1 -0
  93. package/public/assets/page.DTfhMnYX.js +1 -0
  94. package/public/assets/page.D_dG62bf.js +1 -0
  95. package/public/assets/page.DjsFF4p7.js +1 -0
  96. package/public/assets/page.DmjQJ44n.js +6 -0
  97. package/public/assets/page.Dsd5yK6z.js +1 -0
  98. package/public/assets/page.EBdicyw3.js +2 -0
  99. package/public/assets/page.K07l9G5d.js +1 -0
  100. package/public/assets/page.N_CNyJfs.js +1 -0
  101. package/public/assets/page.cIm7s2zC.js +1 -0
  102. package/public/assets/page.u8Bt3ap8.js +1 -0
  103. package/public/index.html +1 -1
@@ -0,0 +1 @@
1
+ import{F as le,j as e,g as Y,n as k,B as q,o as oe}from"./index.BbQSujX0.js";import{d as se,f as re,b as x}from"./router.Cjj1--8t.js";import{B as I,f as D,c as M,d as ie,P as de,U as ce,e as xe,C as V}from"./NoAuthProxyCard.BARTPHmg.js";import{C as ae}from"./Loading.CRvAR61e.js";import"./zustand.akaTi5uX.js";function Q(s){if(s==="leonardo"||s==="weavy")return!0;const t=Y[s];return t!=null&&t.serviceKinds?t.serviceKinds.includes("llm"):!0}function me(s){const t=Math.floor((Date.now()-new Date(s))/1e3);return t<60?`${t}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function ue({timestamp:s}){const[,t]=x.useState(0);return x.useEffect(()=>{const r=setInterval(()=>t(a=>a+1),1e3);return()=>clearInterval(r)},[]),e.jsx(e.Fragment,{children:me(s)})}function pe({requests:s=[]}){return e.jsxs(V,{className:"flex min-w-0 flex-col overflow-hidden",padding:"sm",style:{height:480},children:[e.jsx("div",{className:"px-1 py-2 border-b border-border shrink-0",children:e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide",children:"Recent Requests"})}),s.length?e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("table",{className:"w-full min-w-[300px] border-collapse text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-bg z-10",children:e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("th",{className:"py-1.5 text-left font-semibold text-text-muted w-2"}),e.jsx("th",{className:"py-1.5 text-left font-semibold text-text-muted",children:"Model"}),e.jsx("th",{className:"py-1.5 text-right font-semibold text-text-muted whitespace-nowrap",children:"In / Out"}),e.jsx("th",{className:"py-1.5 text-right font-semibold text-text-muted",children:"When"})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:s.map((t,r)=>{const a=t.status==="streaming",i=!t.status||t.status==="ok"||t.status==="success";return e.jsxs("tr",{className:"hover:bg-bg-subtle transition-colors",children:[e.jsx("td",{className:"py-1.5",children:a?e.jsx("span",{className:"block w-1.5 h-1.5 rounded-full bg-warning animate-pulse",title:"Streaming…"}):e.jsx("span",{className:`block w-1.5 h-1.5 rounded-full ${i?"bg-success":"bg-error"}`})}),e.jsx("td",{className:"py-1.5 font-mono truncate max-w-[120px]",title:t.model,children:t.model}),e.jsx("td",{className:"py-1.5 text-right whitespace-nowrap",children:a?e.jsx("span",{className:"text-warning italic text-[10px]",children:"streaming…"}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-primary",children:[D(t.promptTokens),"↑"]})," ",e.jsxs("span",{className:"text-success",children:[D(t.completionTokens),"↓"]})]})}),e.jsx("td",{className:"py-1.5 text-right text-text-muted whitespace-nowrap",children:e.jsx(ue,{timestamp:t.timestamp})})]},r)})})]})}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-text-muted text-sm",children:"No requests yet."})]})}function _(s,t={},r,a){return Object.entries(s||{}).map(([i,o])=>{const n=(o.promptTokens||0)+(o.completionTokens||0),l=o.cost||0,b=n>0?(o.promptTokens||0)*(l/n):0,p=n>0?(o.completionTokens||0)*(l/n):0;return{...o,key:i,totalTokens:n,totalCost:l,inputCost:b,outputCost:p,pending:t[i]||0}}).sort((i,o)=>{let n=i[r],l=o[r];return typeof n=="string"&&(n=n.toLowerCase()),typeof l=="string"&&(l=l.toLowerCase()),n<l?a==="asc"?-1:1:n>l?a==="asc"?1:-1:0})}function he(s,t){var r;switch(t){case"rawModel":return s.rawModel||"Unknown Model";case"accountName":return s.accountName||`Account ${(r=s.connectionId)==null?void 0:r.slice(0,8)}...`||"Unknown Account";case"keyName":return s.keyName||"Unknown Key";case"endpoint":return s.endpoint||"Unknown Endpoint";default:return s[t]||"Unknown"}}function K(s,t){if(!Array.isArray(s))return[];const r={};return s.forEach(a=>{const i=he(a,t);r[i]||(r[i]={groupKey:i,summary:{requests:0,promptTokens:0,completionTokens:0,totalTokens:0,cost:0,inputCost:0,outputCost:0,lastUsed:null,pending:0},items:[]});const o=r[i].summary;o.requests+=a.requests||0,o.promptTokens+=a.promptTokens||0,o.completionTokens+=a.completionTokens||0,o.totalTokens+=a.totalTokens||0,o.cost+=a.cost||0,o.inputCost+=a.inputCost||0,o.outputCost+=a.outputCost||0,o.pending+=a.pending||0,a.lastUsed&&(!o.lastUsed||new Date(a.lastUsed)>new Date(o.lastUsed))&&(o.lastUsed=a.lastUsed),r[i].items.push(a)}),Object.values(r)}const fe=[{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],be=[{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"accountName",label:"Account"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],ge=[{field:"keyName",label:"API Key Name"},{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],je=[{field:"endpoint",label:"Endpoint"},{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],ve=[{value:"model",label:"Usage by Model"},{value:"account",label:"Usage by Account"},{value:"apiKey",label:"Usage by API Key"},{value:"endpoint",label:"Usage by Endpoint"}],ye=[{value:"today",label:"Today"},{value:"24h",label:"24h"},{value:"7d",label:"7D"},{value:"30d",label:"30D"},{value:"60d",label:"60D"}];function X(s){if(!s)return s;const t={...s};if(t.byProvider&&(t.byProvider={...t.byProvider},t.byProvider.cb)){if(!t.byProvider.codebuddy)t.byProvider.codebuddy=t.byProvider.cb;else{const r=t.byProvider.cb,a=t.byProvider.codebuddy;t.byProvider.codebuddy={requests:(a.requests||0)+(r.requests||0),promptTokens:(a.promptTokens||0)+(r.promptTokens||0),completionTokens:(a.completionTokens||0)+(r.completionTokens||0),cost:(a.cost||0)+(r.cost||0)}}delete t.byProvider.cb}return t.byModel&&(t.byModel=Object.fromEntries(Object.entries(t.byModel).map(([r,a])=>r.endsWith(" (cb)")?[r.slice(0,-5)+" (codebuddy)",{...a,provider:"CodeBuddy"}]:[r,a]))),t.byAccount&&(t.byAccount=Object.fromEntries(Object.entries(t.byAccount).map(([r,a])=>a.provider==="cb"||a.provider==="Codebuddy"||a.provider==="codebuddy"?[r,{...a,provider:"CodeBuddy"}]:[r,a]))),Array.isArray(t.recentRequests)&&(t.recentRequests=t.recentRequests.map(r=>r.provider==="cb"?{...r,provider:"codebuddy"}:r)),t}function Ne({period:s,setPeriod:t,hidePeriodSelector:r=!1}={}){var E,c,w,C;const a=se(),[i]=re(),o=i.get("sortBy")||"rawModel",n=i.get("sortOrder")||"asc",[l,b]=x.useState(null),[p,j]=x.useState(!0),[f,P]=x.useState(!1),[y,h]=x.useState("model"),[N,L]=x.useState("costs"),[O,J]=x.useState([]),[G,W]=x.useState("today"),A=x.useRef(!0),T=s??G,F=t??W;x.useEffect(()=>{fetch("/api/providers").then(m=>m.ok?m.json():null).then(m=>{const v=new Set,d=((m==null?void 0:m.connections)||[]).filter(g=>g.isActive===!1||!Q(g.provider)||v.has(g.provider)?!1:(v.add(g.provider),!0)),u=Object.values(le).filter(g=>g.noAuth&&!v.has(g.id)&&Q(g.id)).map(g=>({provider:g.id,name:g.name}));J([...d,...u])}).catch(()=>{})},[]),x.useEffect(()=>{A.current?(A.current=!1,j(!0)):P(!0),fetch(`/api/usage/stats?period=${T}`).then(m=>m.ok?m.json():null).then(m=>{if(m){const v=X(m);b(d=>({...d,...v}))}}).catch(()=>{}).finally(()=>{j(!1),P(!1)})},[T]),x.useEffect(()=>{const m=new EventSource(`/api/usage/stream?period=${T}`);return m.onmessage=v=>{try{const d=JSON.parse(v.data),u=X(d);b(u),j(!1)}catch(d){console.error("[SSE CLIENT] parse error:",d)}},m.onerror=()=>j(!1),()=>m.close()},[T]);const $=x.useCallback((m,v)=>{const d=new URLSearchParams(i.toString());d.get("sortBy")===v?d.set("sortOrder",d.get("sortOrder")==="asc"?"desc":"asc"):(d.set("sortBy",v),d.set("sortOrder","asc")),a(`?${d.toString()}`,{scroll:!1})},[i,a]),S=x.useMemo(()=>{var m,v;if(!l)return null;switch(y){case"model":{const d=((m=l.pending)==null?void 0:m.byModel)||{};return{columns:fe,groupedData:K(_(l.byModel,d,o,n),"rawModel"),storageKey:"usage-stats:expanded-models",emptyMessage:"No usage recorded yet.",renderSummaryCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.summary.lastUsed)})]}),renderDetailCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:u.pending>0?"primary":"neutral",size:"sm",children:u.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.lastUsed)})]})}}case"account":{const d={};return(v=l==null?void 0:l.pending)!=null&&v.byAccount&&Object.entries(l.byAccount||{}).forEach(([u,g])=>{const H=l.pending.byAccount[g.connectionId];if(H){const ne=g.provider?`${g.rawModel} (${g.provider})`:g.rawModel;d[u]=H[ne]||0}}),{columns:be,groupedData:K(_(l.byAccount,d,o,n),"accountName"),storageKey:"usage-stats:expanded-accounts",emptyMessage:"No account-specific usage recorded yet.",renderSummaryCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.summary.lastUsed)})]}),renderDetailCells:u=>{var g;return e.jsxs(e.Fragment,{children:[e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.accountName||`Account ${(g=u.connectionId)==null?void 0:g.slice(0,8)}...`}),e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:u.pending>0?"primary":"neutral",size:"sm",children:u.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.lastUsed)})]})}}}case"apiKey":return{columns:ge,groupedData:K(_(l.byApiKey,{},o,n),"keyName"),storageKey:"usage-stats:expanded-apikeys",emptyMessage:"No API key usage recorded yet.",renderSummaryCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.summary.lastUsed)})]}),renderDetailCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 font-medium",children:d.keyName}),e.jsx("td",{className:"px-6 py-3",children:d.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:"neutral",size:"sm",children:d.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.lastUsed)})]})};case"endpoint":default:return{columns:je,groupedData:K(_(l.byEndpoint,{},o,n),"endpoint"),storageKey:"usage-stats:expanded-endpoints",emptyMessage:"No endpoint usage recorded yet.",renderSummaryCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.summary.lastUsed)})]}),renderDetailCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 font-medium font-mono text-sm",children:d.endpoint}),e.jsx("td",{className:"px-6 py-3",children:d.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:"neutral",size:"sm",children:d.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.lastUsed)})]})}}},[l,y,o,n]);if(!l&&!p)return e.jsx("div",{className:"text-text-muted",children:"Failed to load usage statistics."});const R=e.jsx("div",{className:"flex items-center justify-center py-12 text-text-muted",children:e.jsx("span",{className:"material-symbols-outlined text-[32px] animate-spin",children:"progress_activity"})});return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6",children:[!r&&e.jsxs("div",{className:"flex w-full items-center gap-2 sm:w-auto sm:self-end",children:[e.jsx("div",{className:"grid flex-1 grid-cols-5 items-center gap-1 rounded-lg border border-border bg-bg-subtle p-1 sm:flex sm:flex-none",children:ye.map(m=>e.jsx("button",{onClick:()=>F(m.value),disabled:f,className:`rounded-md px-3 py-1 text-sm font-medium transition-colors ${T===m.value?"bg-primary text-white shadow-sm":"text-text-muted hover:bg-bg-hover hover:text-text"}`,children:m.label},m.value))}),f&&e.jsx("span",{className:"material-symbols-outlined text-[16px] text-text-muted animate-spin",children:"progress_activity"})]}),p?R:e.jsx(ie,{stats:l}),p?R:e.jsxs("div",{className:"grid min-w-0 grid-cols-1 items-stretch gap-2 lg:grid-cols-[minmax(0,2fr)_minmax(280px,1fr)]",children:[e.jsx(de,{providers:O,activeRequests:l.activeRequests||[],lastProvider:((c=(E=l.recentRequests)==null?void 0:E[0])==null?void 0:c.provider)||"",errorProvider:l.errorProvider||""}),e.jsx(pe,{requests:l.recentRequests||[]})]}),p?R:e.jsx(ce,{period:T,lastRequestTime:(C=(w=l==null?void 0:l.recentRequests)==null?void 0:w[0])==null?void 0:C.timestamp}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("select",{value:y,onChange:m=>h(m.target.value),className:"w-full rounded-lg border border-border bg-surface px-3 py-1.5 text-sm font-medium text-text-main focus:outline-none focus:ring-2 focus:ring-primary/50 sm:w-auto",style:{colorScheme:"auto"},children:ve.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))}),e.jsxs("div",{className:"grid grid-cols-2 items-center gap-1 rounded-lg border border-border bg-bg-subtle p-1 sm:flex",children:[e.jsx("button",{onClick:()=>L("costs"),className:`px-3 py-1 rounded-md text-sm font-medium transition-colors ${N==="costs"?"bg-primary text-white shadow-sm":"text-text-muted hover:text-text hover:bg-bg-hover"}`,children:"Costs"}),e.jsx("button",{onClick:()=>L("tokens"),className:`px-3 py-1 rounded-md text-sm font-medium transition-colors ${N==="tokens"?"bg-primary text-white shadow-sm":"text-text-muted hover:text-text hover:bg-bg-hover"}`,children:"Tokens"})]})]}),p?R:S&&e.jsx(xe,{title:"",columns:S.columns,groupedData:S.groupedData,tableType:y,sortBy:o,sortOrder:n,onToggleSort:$,viewMode:N,storageKey:S.storageKey,renderSummaryCells:S.renderSummaryCells,renderDetailCells:S.renderDetailCells,emptyMessage:S.emptyMessage})]})]})}function we(){const[s,t]=x.useState([]),[r,a]=x.useState(!0),[i,o]=x.useState(!0);x.useEffect(()=>{n()},[]),x.useEffect(()=>{let l;return i&&(l=setInterval(()=>{n(!1)},3e3)),()=>clearInterval(l)},[i]);const n=async(l=!0)=>{l&&a(!0);try{const b=await fetch("/api/usage/request-logs");if(b.ok){const p=await b.json();t(p)}}catch(b){console.error("Failed to fetch logs:",b)}finally{l&&a(!1)}};return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Request Logs"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("label",{className:"text-sm font-medium text-text-muted flex items-center gap-2 cursor-pointer",children:[e.jsx("span",{children:"Auto Refresh (3s)"}),e.jsx("div",{onClick:()=>o(!i),className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus:outline-none ${i?"bg-primary":"bg-bg-subtle border border-border"}`,children:e.jsx("span",{className:`inline-block h-3 w-3 transform rounded-full bg-white transition-transform ${i?"translate-x-5":"translate-x-1"}`})})]})})]}),e.jsx(V,{className:"overflow-hidden bg-black/5 dark:bg-black/20",children:e.jsx("div",{className:"p-0 overflow-x-auto max-h-[600px] overflow-y-auto font-mono text-xs",children:r&&s.length===0?e.jsx("div",{className:"p-8 text-center text-text-muted",children:"Loading logs..."}):s.length===0?e.jsx("div",{className:"p-8 text-center text-text-muted",children:"No logs recorded yet."}):e.jsxs("table",{className:"w-full text-left border-collapse whitespace-nowrap",children:[e.jsx("thead",{className:"sticky top-0 bg-bg-subtle border-b border-border z-10",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"DateTime"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Model"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Provider"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Account"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"In"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Out"}),e.jsx("th",{className:"px-3 py-2",children:"Status"})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:s.map((l,b)=>{const p=l.split(" | ");if(p.length<7)return null;const j=p[6],f=j.includes("PENDING"),P=j.includes("FAILED"),y=j.includes("OK");return e.jsxs("tr",{className:`hover:bg-primary/5 transition-colors ${f?"bg-primary/5":""}`,children:[e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-text-muted",children:p[0]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border font-medium",children:p[1]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-bg-subtle border border-border text-[10px] uppercase font-bold",children:p[2]})}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border truncate max-w-[150px]",title:p[3],children:p[3]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-right text-primary",children:p[4]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-right text-success",children:p[5]}),e.jsx("td",{className:`px-3 py-1.5 font-bold ${y?"text-success":P?"text-error":"text-primary animate-pulse"}`,children:j})]},b)})})]})})}),e.jsx("div",{className:"text-[10px] text-text-muted italic",children:"Logs are loaded from the request history database."})]})}function Z({options:s=[],value:t,onChange:r,size:a="md",className:i}){const o={sm:"h-7 text-xs",md:"h-9 text-sm",lg:"h-11 text-base"};return e.jsx("div",{className:k("inline-flex items-center p-1 rounded-[10px] overflow-x-auto","bg-surface-2",i),children:s.map(n=>e.jsxs("button",{onClick:()=>r(n.value),className:k("shrink-0 px-4 rounded-[8px] font-medium transition-all",o[a],t===n.value?"bg-surface text-text-main shadow-sm":"text-text-muted hover:text-text-main"),children:[n.icon&&e.jsx("span",{className:"material-symbols-outlined text-[16px] mr-1.5",children:n.icon}),n.label]},n.value))})}function ke({isOpen:s,onClose:t,title:r,children:a,width:i="md",className:o}){const n={sm:"w-[400px]",md:"w-[500px]",lg:"w-[600px]",xl:"w-[800px]",full:"w-full"};return x.useEffect(()=>(s?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[s]),x.useEffect(()=>{const l=b=>{b.key==="Escape"&&s&&t()};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[s,t]),s?e.jsxs("div",{className:"fixed inset-0 z-50",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[2px] fade-in cursor-pointer",onClick:t,"aria-hidden":"true"}),e.jsxs("div",{className:k("absolute right-0 top-0 h-full bg-surface flex flex-col","shadow-[var(--shadow-elev)]","slide-in-right","border-l border-border-subtle",n[i]||n.md,o),children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-border-subtle flex-shrink-0",children:[e.jsx("div",{className:"flex items-center gap-3",children:r&&e.jsx("h2",{className:"text-lg font-semibold text-text-main",children:r})}),e.jsx("button",{type:"button",onClick:t,className:"p-1.5 rounded-[10px] text-text-muted hover:bg-surface-2 hover:text-text-main transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 custom-scrollbar",children:a})]})]}):null}function Se({currentPage:s,pageSize:t,totalItems:r,onPageChange:a,onPageSizeChange:i,className:o}){const n=Math.ceil(r/t),l=r>0?(s-1)*t+1:0,b=Math.min(s*t,r),j=(()=>{const f=[];let y=Math.max(1,s-2),h=Math.min(n,y+5-1);h-y+1<5&&(y=Math.max(1,h-5+1));for(let N=y;N<=h;N++)f.push(N);return f})();return e.jsxs("div",{className:k("flex flex-col sm:flex-row items-center justify-between gap-4 py-4 px-2",o),children:[r>0&&e.jsxs("div",{className:"text-sm text-text-muted",children:["Showing ",e.jsx("span",{className:"font-medium text-text-main",children:l})," to"," ",e.jsx("span",{className:"font-medium text-text-main",children:b})," of"," ",e.jsx("span",{className:"font-medium text-text-main",children:r})," results"]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2 sm:gap-4",children:[i&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-text-muted",children:"Rows:"}),e.jsx("select",{value:t,onChange:f=>i(Number(f.target.value)),className:k("h-9 rounded-lg border border-black/10 dark:border-white/10 bg-surface","text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20","cursor-pointer"),style:{colorScheme:"auto"},children:[10,20,50].map(f=>e.jsx("option",{value:f,children:f},f))})]}),n>1&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(q,{variant:"outline",size:"sm",onClick:()=>a(s-1),disabled:s===1,className:"w-9 px-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"chevron_left"})}),j[0]>1&&e.jsxs(e.Fragment,{children:[e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>a(1),className:"w-9 px-0 hidden sm:inline-flex",children:"1"}),j[0]>2&&e.jsx("span",{className:"text-text-muted px-1 hidden sm:inline",children:"..."})]}),j.map(f=>e.jsx(q,{variant:s===f?"primary":"ghost",size:"sm",onClick:()=>a(f),className:k("w-9 px-0",s===f?"inline-flex":"hidden sm:inline-flex"),children:f},f)),j[j.length-1]<n&&e.jsxs(e.Fragment,{children:[j[j.length-1]<n-1&&e.jsx("span",{className:"text-text-muted px-1 hidden sm:inline",children:"..."}),e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>a(n),className:"w-9 px-0 hidden sm:inline-flex",children:n})]}),e.jsx(q,{variant:"outline",size:"sm",onClick:()=>a(s+1),disabled:s===n,className:"w-9 px-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"chevron_right"})})]})]})]})}let z=null,U=null;async function Ce(){if(z&&U)return{providerNameCache:z,providerNodesCache:U};const r=(await(await fetch("/api/provider-nodes")).json()).nodes||[];U={};for(const a of r)U[a.id]=a.name;return z={...Y,...U},{providerNameCache:z,providerNodesCache:U}}function ee(s,t){if(!s||!t)return s;const r=t[s];if(typeof r=="string")return r;if(r!=null&&r.name)return r.name;const a=oe(s)||Y[s];return(a==null?void 0:a.name)||s}function B({title:s,children:t,defaultOpen:r=!1,icon:a=null}){const[i,o]=x.useState(r);return e.jsxs("div",{className:"border border-black/5 dark:border-white/5 rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"w-full flex items-center justify-between p-3 bg-black/[0.02] dark:bg-white/[0.02] hover:bg-black/[0.04] dark:hover:bg-white/[0.04] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[a&&e.jsx("span",{className:"material-symbols-outlined text-[18px] text-text-muted",children:a}),e.jsx("span",{className:"font-semibold text-sm text-text-main",children:s})]}),e.jsx("span",{className:k("material-symbols-outlined text-[20px] text-text-muted transition-transform duration-200",i?"rotate-90":""),children:"chevron_right"})]}),i&&e.jsx("div",{className:"p-4 border-t border-black/5 dark:border-white/5",children:t})]})}function te(s){const t=(s==null?void 0:s.prompt_tokens)||(s==null?void 0:s.input_tokens)||0,r=(s==null?void 0:s.cached_tokens)||(s==null?void 0:s.cache_read_input_tokens)||0;return t<r?r:t}function De(){var T,F,$,S,R,E;const[s,t]=x.useState([]),[r,a]=x.useState({page:1,pageSize:20,totalItems:0,totalPages:0}),[i,o]=x.useState(!1),[n,l]=x.useState(null),[b,p]=x.useState(!1),[j,f]=x.useState([]),[P,y]=x.useState(null),[h,N]=x.useState({provider:"",startDate:"",endDate:""}),L=x.useCallback(async()=>{try{const w=await(await fetch("/api/usage/providers")).json();f(w.providers||[]);const C=await Ce();y(C.providerNameCache)}catch(c){console.error("Failed to fetch providers:",c)}},[]),O=x.useCallback(async()=>{o(!0);try{const c=new URLSearchParams({page:r.page.toString(),pageSize:r.pageSize.toString()});h.provider&&c.append("provider",h.provider),h.startDate&&c.append("startDate",h.startDate),h.endDate&&c.append("endDate",h.endDate);const C=await(await fetch(`/api/usage/request-details?${c}`)).json();t(C.details||[]),a(m=>({...m,...C.pagination}))}catch(c){console.error("Failed to fetch request details:",c)}finally{o(!1)}},[r.page,r.pageSize,h]);x.useEffect(()=>{L()},[L]),x.useEffect(()=>{O()},[O]);const J=c=>{l(c),p(!0)},G=c=>{a(w=>({...w,page:c}))},W=c=>{a(w=>({...w,pageSize:c,page:1}))},A=()=>{N({provider:"",startDate:"",endDate:""})};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6",children:[e.jsx(V,{padding:"md",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"provider-filter",className:"text-sm font-medium text-text-main",children:"Provider"}),e.jsxs("select",{id:"provider-filter",value:h.provider,onChange:c=>N({...h,provider:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20","w-full min-w-0 cursor-pointer"),style:{colorScheme:"auto"},children:[e.jsx("option",{value:"",children:"All Providers"}),j.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"start-date-filter",className:"text-sm font-medium text-text-main",children:"Start Date"}),e.jsx("input",{id:"start-date-filter",type:"datetime-local",value:h.startDate,onChange:c=>N({...h,startDate:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","w-full min-w-0 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"end-date-filter",className:"text-sm font-medium text-text-main",children:"End Date"}),e.jsx("input",{id:"end-date-filter",type:"datetime-local",value:h.endDate,onChange:c=>N({...h,endDate:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","w-full min-w-0 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:col-span-2 lg:col-span-1",children:[e.jsx("span",{className:"hidden text-sm font-medium text-text-main opacity-0 lg:block","aria-hidden":"true",children:"Clear"}),e.jsx(q,{variant:"ghost",onClick:A,disabled:!h.provider&&!h.startDate&&!h.endDate,className:"w-full",children:"Clear Filters"})]})]})}),e.jsxs(V,{padding:"none",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[880px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5",children:[e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Timestamp"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Model"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Provider"}),e.jsx("th",{className:"text-right p-4 text-sm font-semibold text-text-main",children:"Input Tokens"}),e.jsx("th",{className:"text-right p-4 text-sm font-semibold text-text-main",children:"Output Tokens"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Latency"}),e.jsx("th",{className:"text-center p-4 text-sm font-semibold text-text-main",children:"Action"})]})}),e.jsx("tbody",{children:i?e.jsx("tr",{children:e.jsx("td",{colSpan:"7",className:"p-8 text-center text-text-muted",children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[20px]",children:"progress_activity"}),"Loading..."]})})}):s.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:"7",className:"p-8 text-center text-text-muted",children:"No request details found"})}):s.map((c,w)=>{var C,m,v,d;return e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5 last:border-b-0 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"whitespace-nowrap p-4 text-sm text-text-main",children:new Date(c.timestamp).toLocaleString()}),e.jsx("td",{className:"max-w-[260px] truncate p-4 font-mono text-sm text-text-main",children:c.model}),e.jsx("td",{className:"max-w-[180px] truncate p-4 text-sm text-text-main",children:e.jsx("span",{className:"font-medium",children:ee(c.provider,P)})}),e.jsx("td",{className:"p-4 text-sm text-text-main text-right font-mono",children:te(c.tokens).toLocaleString()}),e.jsx("td",{className:"p-4 text-sm text-text-main text-right font-mono",children:((m=(C=c.tokens)==null?void 0:C.completion_tokens)==null?void 0:m.toLocaleString())||0}),e.jsx("td",{className:"p-4 text-sm text-text-muted",children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{children:["TTFT: ",e.jsxs("span",{className:"font-mono",children:[((v=c.latency)==null?void 0:v.ttft)||0,"ms"]})]}),e.jsxs("div",{children:["Total: ",e.jsxs("span",{className:"font-mono",children:[((d=c.latency)==null?void 0:d.total)||0,"ms"]})]})]})}),e.jsx("td",{className:"p-4 text-center",children:e.jsx(q,{variant:"outline",size:"sm",onClick:()=>J(c),children:"Detail"})})]},`${c.id}-${w}`)})})]})}),!i&&s.length>0&&e.jsx("div",{className:"border-t border-black/5 dark:border-white/5",children:e.jsx(Se,{currentPage:r.page,pageSize:r.pageSize,totalItems:r.totalItems,onPageChange:G,onPageSizeChange:W})})]}),e.jsx(ke,{isOpen:b,onClose:()=>p(!1),title:"Request Details",width:"lg",children:n&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-4 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"ID:"})," ",e.jsx("span",{className:"break-all font-mono text-text-main",children:n.id})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Timestamp:"})," ",e.jsx("span",{className:"text-text-main",children:new Date(n.timestamp).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Provider:"})," ",e.jsx("span",{className:"text-text-main font-medium",children:ee(n.provider,P)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Model:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:n.model})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Status:"})," ",e.jsx("span",{className:k("font-medium",n.status==="success"?"text-green-600":"text-red-600"),children:n.status})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Latency:"})," ",e.jsxs("span",{className:"text-text-main font-mono",children:["TTFT ",((T=n.latency)==null?void 0:T.ttft)||0,"ms / Total ",((F=n.latency)==null?void 0:F.total)||0,"ms"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Input Tokens:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:te(n.tokens).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Output Tokens:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:((S=($=n.tokens)==null?void 0:$.completion_tokens)==null?void 0:S.toLocaleString())||0})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(B,{title:"1. Client Request (Input)",defaultOpen:!0,icon:"input",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:JSON.stringify(n.request,null,2)})}),n.providerRequest&&e.jsx(B,{title:"2. Provider Request (Translated)",icon:"translate",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:JSON.stringify(n.providerRequest,null,2)})}),n.providerResponse&&e.jsx(B,{title:"3. Provider Response (Raw)",icon:"data_object",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:typeof n.providerResponse=="object"?JSON.stringify(n.providerResponse,null,2):n.providerResponse})}),e.jsxs(B,{title:"4. Client Response (Final)",defaultOpen:!0,icon:"output",children:[((R=n.response)==null?void 0:R.thinking)&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("h4",{className:"font-semibold text-text-main mb-2 flex items-center gap-2 text-xs uppercase tracking-wide opacity-70",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"psychology"}),"Thinking Process"]}),e.jsx("pre",{className:"max-h-[200px] max-w-full overflow-auto rounded-lg border border-amber-200 bg-amber-50 p-3 font-mono text-xs text-amber-900 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-100 sm:p-4",children:n.response.thinking})]}),e.jsx("h4",{className:"font-semibold text-text-main mb-2 text-xs uppercase tracking-wide opacity-70",children:"Content"}),e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:((E=n.response)==null?void 0:E.content)||"[No content]"})]})]})]})})]})}const Te=[{value:"today",label:"Today"},{value:"24h",label:"24h"},{value:"7d",label:"7D"},{value:"30d",label:"30D"},{value:"60d",label:"60D"}];function Ee(){return e.jsx(x.Suspense,{fallback:e.jsx(ae,{}),children:e.jsx(Pe,{})})}function Pe(){const[s]=re(),t=se(),[r,a]=x.useState("today"),i=s.get("tab"),o=i&&["overview","logs","details"].includes(i)?i:"overview",n=l=>{if(l===o)return;const b=new URLSearchParams(s);b.set("tab",l),t(`/dashboard/usage?${b.toString()}`,{scroll:!1})};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(Z,{options:[{value:"overview",label:"Overview"},{value:"details",label:"Details"}],value:o,onChange:n,className:"w-full sm:w-auto"}),o==="overview"&&e.jsx(Z,{options:Te,value:r,onChange:a,size:"sm",className:"w-full sm:w-auto"})]}),o==="overview"&&e.jsx(x.Suspense,{fallback:e.jsx(ae,{}),children:e.jsx(Ne,{period:r,setPeriod:a,hidePeriodSelector:!0})}),o==="logs"&&e.jsx(we,{}),o==="details"&&e.jsx(De,{})]})}export{Ee as default};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index.1VBQU7rF.js","assets/router.Cjj1--8t.js"])))=>i.map(i=>d[i]);
2
+ import{u as z,j as t,B as c,_ as F}from"./index.BbQSujX0.js";import{b as x}from"./router.Cjj1--8t.js";import{C as $}from"./NoAuthProxyCard.BARTPHmg.js";import"./zustand.akaTi5uX.js";const B=x.lazy(()=>F(()=>import("./index.1VBQU7rF.js"),__vite__mapDeps([0,1]))),v=[{id:1,label:"Client Request",file:"1_req_client.json",lang:"json",desc:"Raw request from client"},{id:2,label:"Source Body",file:"2_req_source.json",lang:"json",desc:"After initial conversion"},{id:3,label:"OpenAI Intermediate",file:"3_req_openai.json",lang:"json",desc:"source → openai"},{id:4,label:"Target Request",file:"4_req_target.json",lang:"json",desc:"openai → target + URL + headers"},{id:5,label:"Provider Response",file:"5_res_provider.txt",lang:"text",desc:"Raw SSE from provider"},{id:6,label:"OpenAI Response",file:"6_res_openai.txt",lang:"text",desc:"target → openai (response)"},{id:7,label:"Client Response",file:"7_res_client.txt",lang:"text",desc:"Final response to client"}],I={minimap:{enabled:!1},fontSize:12,lineNumbers:"on",scrollBeyondLastLine:!1,wordWrap:"on",automaticLayout:!0};function W(){const[i,h]=x.useState({}),[g,u]=x.useState({1:!0}),[p,S]=x.useState({}),[o,w]=x.useState(null),l=(e,s)=>S(a=>({...a,[e]:s})),d=(e,s)=>h(a=>({...a,[e]:s})),O=e=>u(s=>({...s,[e]:!s[e]})),j=e=>u(s=>{const a={};return v.forEach(n=>{a[n.id]=!1}),a[e]=!0,a}),_=async e=>{const s=v.find(a=>a.id===e);l(`load-${e}`,!0);try{const n=await(await fetch(`/api/translator/load?file=${s.file}`)).json();n.success?(d(e,n.content),e===1&&await N(n.content)):alert(n.error||"File not found")}catch(a){alert(a.message)}l(`load-${e}`,!1)},N=async e=>{try{const s=typeof e=="string"?JSON.parse(e):e,n=await(await fetch("/api/translator/translate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({step:1,body:s})})).json();n.success&&w(n.result)}catch{}},f=(e,s)=>fetch("/api/translator/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:e,content:s})}).catch(()=>{}),T=async()=>{l("toOpenAI",!0);try{const e=i[1],s=JSON.parse(e);f("1_req_client.json",e),f("2_req_source.json",JSON.stringify({timestamp:new Date().toISOString(),headers:{},body:s.body||s},null,2));const n=await(await fetch("/api/translator/translate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({step:2,body:s})})).json();if(!n.success){alert(n.error);return}const r=JSON.stringify(n.result.body,null,2);d(3,r),j(3)}catch(e){alert(e.message)}l("toOpenAI",!1)},C=async()=>{l("toTarget",!0);try{const e=i[3],s=JSON.parse(e);f("3_req_openai.json",e);const n=await(await fetch("/api/translator/translate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({step:3,body:{...s,provider:o==null?void 0:o.provider,model:o==null?void 0:o.model}})})).json();if(!n.success){alert(n.error);return}const r={...n.result,provider:o==null?void 0:o.provider,model:o==null?void 0:o.model};d(4,JSON.stringify(r,null,2)),j(4)}catch(e){alert(e.message)}l("toTarget",!1)},J=async()=>{l("send",!0);try{const e=i[4],s=JSON.parse(e);f("4_req_target.json",e);const a=s.provider||(o==null?void 0:o.provider),n=s.model||(o==null?void 0:o.model);if(!a||!n){alert("Missing provider or model. Please run step 1 first to detect them.");return}const r=await fetch("/api/translator/send",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,model:n,body:s.body||s})});if(!r.ok){const b=await r.json().catch(()=>({error:r.statusText}));alert(b.error||"Send failed");return}const E=r.body.getReader(),A=new TextDecoder;let y="";for(;;){const{done:b,value:L}=await E.read();if(b)break;y+=A.decode(L,{stream:!0})}d(5,y),j(5),await fetch("/api/translator/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:"5_res_provider.txt",content:y})})}catch(e){alert(e.message)}finally{l("send",!1)}},{copy:P}=z(),R=async e=>{i[e]&&P(i[e],`translator-step-${e}`)},k=e=>{try{const s=JSON.parse(i[e]);d(e,JSON.stringify(s,null,2))}catch{}},q=e=>e===1?t.jsx(c,{size:"sm",icon:"arrow_forward",loading:p.toOpenAI,onClick:T,children:"→ OpenAI"}):e===3?t.jsx(c,{size:"sm",icon:"arrow_forward",loading:p.toTarget,onClick:C,children:"→ Target"}):e===4?t.jsx(c,{size:"sm",icon:"send",loading:p.send,onClick:J,children:"Send"}):null;return t.jsxs("div",{className:"p-8 space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("div",{children:[t.jsx("h1",{className:"text-2xl font-bold text-text-main",children:"Translator Debug"}),t.jsx("p",{className:"text-sm text-text-muted mt-1",children:"Replay request flow — matches log files"})]}),o&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-end",children:[t.jsx(m,{label:"src",value:o.sourceFormat,color:"blue"}),t.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px]",children:"arrow_forward"}),t.jsx(m,{label:"dst",value:o.targetFormat,color:"orange"}),t.jsx(m,{label:"provider",value:o.provider,color:"green"}),t.jsx(m,{label:"model",value:o.model,color:"purple"})]})]}),v.map(e=>{const s=q(e.id),a=!!g[e.id],n=i[e.id]||"";return t.jsx($,{children:t.jsxs("div",{className:"p-4 space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("button",{onClick:()=>O(e.id),className:"flex items-center gap-2 flex-1 text-left group",children:[t.jsx("span",{className:"material-symbols-outlined text-[20px] text-text-muted group-hover:text-primary transition-colors",children:a?"expand_more":"chevron_right"}),t.jsx("span",{className:"text-xs font-mono text-text-muted/60 w-4",children:e.id}),t.jsx("h3",{className:"text-sm font-semibold text-text-main",children:e.label}),t.jsx("span",{className:"text-xs text-text-muted/60 font-mono",children:e.file}),n&&t.jsxs("span",{className:"text-xs text-green-500",children:["(",n.length," chars)"]})]}),!a&&t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(c,{size:"sm",variant:"ghost",icon:"folder_open",loading:p[`load-${e.id}`],onClick:()=>_(e.id)}),s]})]}),a&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"border border-border rounded-lg overflow-hidden",children:t.jsx(B,{height:"400px",defaultLanguage:e.lang==="text"?"plaintext":"json",value:n,onChange:r=>{d(e.id,r||""),e.id===1&&N(r||"")},theme:"vs-dark",options:I})}),t.jsxs("div",{className:"flex gap-2 flex-wrap",children:[t.jsx(c,{size:"sm",variant:"outline",icon:"folder_open",loading:p[`load-${e.id}`],onClick:()=>_(e.id),children:"Load"}),t.jsx(c,{size:"sm",variant:"outline",icon:"data_object",onClick:()=>k(e.id),children:"Format"}),t.jsx(c,{size:"sm",variant:"outline",icon:"content_copy",onClick:()=>R(e.id),children:"Copy"}),s]})]})]})},e.id)})]})}function m({label:i,value:h,color:g}){const u={blue:"bg-blue-500/10 text-blue-500",orange:"bg-orange-500/10 text-orange-500",green:"bg-green-500/10 text-green-500",purple:"bg-purple-500/10 text-purple-500"};return t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-mono ${u[g]}`,children:[t.jsxs("span",{className:"text-text-muted/70 font-sans text-[10px]",children:[i,":"]}),h]})}export{W as default};
@@ -0,0 +1 @@
1
+ import{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.BbQSujX0.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.BARTPHmg.js";import{C as ee}from"./Loading.CRvAR61e.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 m,j as e,B as p}from"./index.BbQSujX0.js";import{b as l}from"./router.Cjj1--8t.js";import{C as f}from"./NoAuthProxyCard.BARTPHmg.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 @@
1
+ import{j as a}from"./index.BbQSujX0.js";import{b as e}from"./router.Cjj1--8t.js";import{g as m}from"./machine.CagOtseJ.js";import{A as c}from"./EndpointPageClient.BNiu_vhL.js";import"./zustand.akaTi5uX.js";import"./NoAuthProxyCard.BARTPHmg.js";import"./Loading.CRvAR61e.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{j as e}from"./index.BbQSujX0.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};
package/public/index.html CHANGED
@@ -10,7 +10,7 @@
10
10
  <link rel="preconnect" href="https://fonts.googleapis.com" />
11
11
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
12
12
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
13
- <script type="module" crossorigin src="/assets/index.BUwEfcda.js"></script>
13
+ <script type="module" crossorigin src="/assets/index.BbQSujX0.js"></script>
14
14
  <link rel="modulepreload" crossorigin href="/assets/router.Cjj1--8t.js">
15
15
  <link rel="modulepreload" crossorigin href="/assets/zustand.akaTi5uX.js">
16
16
  <link rel="stylesheet" crossorigin href="/assets/index.COMgQZYj.css">