mapigate 0.5.168 → 0.5.174

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 (73) hide show
  1. package/README.md +1 -1
  2. package/dist/core/adapters/responsesAdapter.js +2 -2
  3. package/dist/mitm/handlers/base.js +2 -2
  4. package/dist/providers/catalog/perplexity/index.js +1 -1
  5. package/dist/providers/catalog/perplexity/provider.js +1 -1
  6. package/dist/providers/core/base/customExecutionHelper.js +21 -1
  7. package/dist/providers/core/base/responsesExecution.js +37 -0
  8. package/dist/providers/core/base/responsesPayloadBuilder.js +5 -0
  9. package/dist/providers/runtime/antigravity/executor.js +8 -8
  10. package/dist/providers/runtime/antigravity/metadata.js +1 -1
  11. package/dist/providers/runtime/antigravity/provider.js +1 -1
  12. package/dist/providers/runtime/antigravity/quota.js +1 -1
  13. package/dist/providers/runtime/antigravity/routes.js +1 -1
  14. package/dist/providers/runtime/antigravity/types.js +1 -1
  15. package/dist/providers/runtime/antigravity/weekly.js +1 -1
  16. package/dist/providers/runtime/codex/index.js +1 -1
  17. package/dist/providers/runtime/codex/provider.js +1 -1
  18. package/dist/providers/runtime/codex/responses.js +1 -0
  19. package/dist/providers/runtime/codex/responsesPayload.js +1 -0
  20. package/dist/providers/runtime/gemini-cli/provider.js +1 -1
  21. package/dist/providers/runtime/gemini-cli/quota.js +1 -1
  22. package/dist/providers/runtime/gemini-cli/routes.js +1 -1
  23. package/dist/providers/runtime/grok-cli/grokWeb.js +5 -0
  24. package/dist/providers/runtime/grok-cli/provider.js +1 -1
  25. package/dist/providers/runtime/kiro/constants.js +1 -0
  26. package/dist/providers/runtime/kiro/executor.js +6 -6
  27. package/dist/providers/runtime/kiro/index.js +1 -1
  28. package/dist/providers/runtime/kiro/metadata.js +1 -1
  29. package/dist/providers/runtime/kiro/provider.js +1 -1
  30. package/dist/providers/runtime/kiro/quota.js +1 -1
  31. package/dist/providers/runtime/ollama/nativeChat.js +3 -0
  32. package/dist/providers/runtime/ollama/provider.js +1 -1
  33. package/dist/providers/runtime/opencode/provider.js +1 -1
  34. package/dist/web/assets/CallbackPage-B-htyyMG.js +1 -0
  35. package/dist/web/assets/{CliToolsTab-D4DtbZ7V.js → CliToolsTab-Q0vXiulu.js} +24 -24
  36. package/dist/web/assets/ComboDetailPage-hWEuQaOZ.js +1 -0
  37. package/dist/web/assets/CombosTab-nBWliTLU.js +1 -0
  38. package/dist/web/assets/{ConfirmModal-DCYNsbhd.js → ConfirmModal-CsfteGXH.js} +1 -1
  39. package/dist/web/assets/ConsoleLogTab-CW8OK2qW.js +6 -0
  40. package/dist/web/assets/EditAccountModal-CAxJfsFe.js +1 -0
  41. package/dist/web/assets/EndpointTab-BSOhVZQl.js +1 -0
  42. package/dist/web/assets/MitmTab-BjTPAKno.js +6 -0
  43. package/dist/web/assets/{ModelAutocompleteInput-Cdnm0qff.js → ModelAutocompleteInput-BH4gr6Dr.js} +1 -1
  44. package/dist/web/assets/ModelSelectModal-BP5Ha7Az.js +1 -0
  45. package/dist/web/assets/PortalDrawer-Bv31mboq.js +1 -0
  46. package/dist/web/assets/ProviderDetailPage-CeYToos_.js +6 -0
  47. package/dist/web/assets/{ProvidersTab-KfP8Lt0p.js → ProvidersTab-C4ZpyulK.js} +1 -1
  48. package/dist/web/assets/QuotaTab-Dh1eTSJx.js +1 -0
  49. package/dist/web/assets/SettingsTab-D0Bo21nq.js +1 -0
  50. package/dist/web/assets/{TokenSaverTab-B3Fbu_yc.js → TokenSaverTab-BYqUuEE1.js} +1 -1
  51. package/dist/web/assets/UsageTab-C5qvXO61.js +1 -0
  52. package/dist/web/assets/clipboard-CLQF8jeK.js +1 -0
  53. package/dist/web/assets/index-_goGZDSK.css +1 -0
  54. package/dist/web/assets/index-vFoRSZw0.js +10 -0
  55. package/dist/web/assets/metadataRegistry-4BIaQVmV.js +1 -0
  56. package/dist/web/assets/{providersData-BevGw_jX.js → providersData-C-7jZmPi.js} +1 -1
  57. package/dist/web/index.html +2 -2
  58. package/package.json +2 -2
  59. package/dist/web/assets/CallbackPage-sTRnWJ-d.js +0 -1
  60. package/dist/web/assets/ComboDetailPage-RbsO_iJo.js +0 -1
  61. package/dist/web/assets/CombosTab-DpKJ-Tdm.js +0 -1
  62. package/dist/web/assets/ConsoleLogTab-DfNJ54Az.js +0 -6
  63. package/dist/web/assets/EditAccountModal-DdreWxg7.js +0 -1
  64. package/dist/web/assets/EndpointTab-BYSh-fMY.js +0 -1
  65. package/dist/web/assets/MitmTab-DDSeULv5.js +0 -14
  66. package/dist/web/assets/ModelSelectModal-BsleTaNw.js +0 -1
  67. package/dist/web/assets/ProviderDetailPage-k1kl7EIO.js +0 -6
  68. package/dist/web/assets/QuotaTab-BA1BaQbz.js +0 -1
  69. package/dist/web/assets/SettingsTab-FET_sXur.js +0 -1
  70. package/dist/web/assets/UsageTab-C-Cs4o-K.js +0 -1
  71. package/dist/web/assets/index-Di7mCTbW.js +0 -2
  72. package/dist/web/assets/index-h7Meu4Tn.css +0 -1
  73. package/dist/web/assets/metadataRegistry-EMxpq0lK.js +0 -1
@@ -0,0 +1 @@
1
+ import{r as d,j as e,R as ae}from"./vendor-BcOI2aZ9.js";import{u as Re,a as ue,D as Pe,c as Ve,S as _e,v as qe,b as he,s as ze,K as Ge,P as Oe,d as Ke,C as Qe}from"./dnd-kit-DecqzwfZ.js";import{P as fe}from"./index-vFoRSZw0.js";import{M as ge,i as te,C as re,g as ne,m as Ue,a as We}from"./ModelAutocompleteInput-BH4gr6Dr.js";import{M as ye,f as He,V as Ze,S as Je}from"./ModelSelectModal-BP5Ha7Az.js";import{S as se}from"./Select-BNRH8LIG.js";import{T as oe}from"./ToolIcon-BZE0Fv7L.js";import{P as Xe}from"./metadataRegistry-4BIaQVmV.js";import{C as Ye}from"./ConfirmModal-CsfteGXH.js";import{c as et}from"./clipboard-CLQF8jeK.js";import"./lucide-Cc35htxl.js";const tt=/^[a-zA-Z0-9_.-]+$/,je=ae.memo(({id:a,model:s,index:n,onEdit:m,onRemove:x,onMoveUp:i,onMoveDown:o,isFirst:r,isLast:h,excludeValues:l})=>{const[c,p]=d.useState(!1),[T,C]=d.useState(s);d.useEffect(()=>{C(s)},[s]);const k=b=>{const E=(typeof b=="string"?b:T).trim();E&&E!==s?m(n,E):C(s),p(!1)},{attributes:v,listeners:$,setNodeRef:S,transform:L,transition:B,isDragging:A}=Ke({id:a}),y={transform:Qe.Transform.toString(L),transition:B,zIndex:A?50:void 0,opacity:A?.6:1};return e.jsxs("div",{ref:S,style:y,className:`group flex items-center justify-between gap-2.5 px-3 py-2 rounded-xl border bg-[#0A0D14] transition-all ${A?"border-blue-500 shadow-lg shadow-blue-500/10 bg-blue-950/40":"border-[#1E293B] hover:border-slate-700"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{type:"button",...v,...$,className:"cursor-grab active:cursor-grabbing text-slate-500 hover:text-slate-300 p-0.5 rounded touch-none shrink-0",title:"Drag to reorder priority",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"drag_indicator"})}),e.jsx("span",{className:"size-5 rounded-md bg-[#141B2D] border border-[#1E293B] text-[10px] font-mono text-blue-400 font-bold flex items-center justify-center shrink-0",children:n+1}),c?e.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-1.5",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(ge,{autoFocus:!0,value:T,onChange:b=>C(b),onEnter:b=>k(b),placeholder:"e.g. anthropic/claude-3-7-sonnet",excludeValues:l,allowCombos:!1,className:"w-full rounded border border-blue-500/60 bg-[#141B2D] px-2 py-0.5 font-mono text-xs text-white outline-none focus:border-blue-400"})}),e.jsx("button",{type:"button",onClick:()=>k(),className:"p-1 text-emerald-400 hover:text-emerald-300 cursor-pointer",title:"Save changes",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check"})}),e.jsx("button",{type:"button",onClick:()=>{C(s),p(!1)},className:"p-1 text-slate-400 hover:text-white cursor-pointer",title:"Cancel",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})})]}):e.jsxs("div",{className:"min-w-0 flex-1 cursor-text truncate rounded px-1.5 py-0.5 font-mono text-xs text-white hover:bg-white/5 flex items-center gap-2",onClick:()=>p(!0),title:"Click to edit model ID inline",children:[e.jsx("span",{className:"truncate",title:s,children:s}),e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-500 opacity-0 group-hover:opacity-100 transition-opacity",children:"edit"})]}),!c&&e.jsx(re,{model:s,size:"xs"})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>i(n),disabled:r,className:"p-1 text-slate-400 hover:text-white disabled:opacity-20 disabled:hover:text-slate-400 cursor-pointer transition-colors",title:"Move up",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"arrow_upward"})}),e.jsx("button",{type:"button",onClick:()=>o(n),disabled:h,className:"p-1 text-slate-400 hover:text-white disabled:opacity-20 disabled:hover:text-slate-400 cursor-pointer transition-colors",title:"Move down",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"arrow_downward"})}),e.jsx("button",{type:"button",onClick:()=>x(n),className:"p-1 text-slate-400 hover:text-rose-400 cursor-pointer transition-colors",title:"Remove model",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})})]})]})});je.displayName="SortableComboModelRow";const st=({isOpen:a,onClose:s,combo:n,title:m,onSave:x})=>{const[i,o]=d.useState(""),[r,h]=d.useState("round-robin"),[l,c]=d.useState([]),[p,T]=d.useState(""),[C,k]=d.useState(""),[v,$]=d.useState(""),[S,L]=d.useState(!1),[B,A]=d.useState(!1),y=!!n,b=Re(ue(Oe,{activationConstraint:{distance:4}}),ue(Ge,{coordinateGetter:ze}));d.useEffect(()=>{a&&(n?(o(n.name),h(n.strategy||"round-robin"),c(Array.isArray(n.models)?[...n.models]:[])):(o(""),h("round-robin"),c([])),T(""),k(""),$(""),A(!1))},[a,n]);const I=N=>{const f=N.trim();return f?tt.test(f)?(T(""),!0):(T("Name can only contain letters, numbers, -, _ and ."),!1):(T("Combo name is required."),!1)},E=N=>{const f=N.target.value;o(f),f.trim()?I(f):T("")},R=d.useMemo(()=>{const N=[];n!=null&&n.id&&N.push(n.id),n!=null&&n.name&&(N.push(n.name),N.push(`combo/${n.name}`));const f=i.trim();return f&&(N.push(f),N.push(`combo/${f}`)),N},[n,i]),D=d.useCallback(N=>{const f=N.trim().toLowerCase(),t=f.startsWith("combo/")?f.slice(6):f;return R.some(u=>{const j=u.toLowerCase(),F=j.startsWith("combo/")?j.slice(6):j;return f===j||t===F})},[R]),_=d.useCallback((N,f)=>{const t=f.trim();if(D(t)){k("A combo cannot bundle itself (circular reference).");return}c(u=>{const j=[...u];return j[N]=t,j}),k("")},[D]),Q=d.useCallback(N=>{c(f=>f.filter((t,u)=>u!==N))},[]),W=d.useCallback(N=>{N!==0&&c(f=>{const t=[...f],u=t[N-1];return t[N-1]=t[N],t[N]=u,t})},[]),U=d.useCallback(N=>{c(f=>{if(N>=f.length-1)return f;const t=[...f],u=t[N+1];return t[N+1]=t[N],t[N]=u,t})},[]),H=N=>{const{active:f,over:t}=N;t&&f.id!==t.id&&c(u=>{const j=u.map((G,Y)=>`${G}-${Y}`),F=j.indexOf(String(f.id)),q=j.indexOf(String(t.id));return F!==-1&&q!==-1?he(u,F,q):u})},Z=(N,f)=>{const t=(typeof f=="string"?f:v).trim();if(t){if(D(t)){k("A combo cannot bundle itself (circular reference).");return}l.includes(t)||(c([...l,t]),k("")),$("")}},X=async N=>{if(N.preventDefault(),!!I(i)){if(l.length===0){k("At least one model must be added to the combo.");return}if(l.some(D)){k("A combo cannot bundle itself (circular reference).");return}try{A(!0),await x({id:n==null?void 0:n.id,name:i.trim(),models:l,strategy:r,isActive:n?n.isActive:!0}),te(),s()}catch(f){T((f==null?void 0:f.message)||"Failed to save combo.")}finally{A(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx(fe,{isOpen:a,onClose:s,maxWidthClass:"w-full max-w-3xl",children:e.jsxs("form",{onSubmit:X,className:"space-y-5 -m-2 sm:-m-4 p-5 sm:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between pb-4 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-9 rounded-xl bg-blue-500/10 border border-blue-500/20 text-blue-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:y?"edit_note":"add_circle"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-white",children:m||(y?`Edit Combo: ${n==null?void 0:n.name}`:"Create Smart Model Combo")}),e.jsx("p",{className:"text-xs text-slate-400",children:"Configure an alias to rotate or fallback across multiple upstream models"})]})]}),e.jsx("button",{type:"button",onClick:s,className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-white/10 cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:["Combo Name / Alias ",e.jsx("span",{className:"text-rose-400",children:"*"})]}),e.jsx("input",{type:"text",placeholder:"e.g. combo-fast-coding, claude-3-7-sonnet",value:i,onChange:E,className:`w-full bg-[#0A0D14] border rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors ${p?"border-rose-500/80 focus:border-rose-500":"border-[#1E293B] focus:border-blue-500"}`}),p?e.jsxs("p",{className:"text-[11px] text-rose-400 mt-1 flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"error"}),p]}):e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Can contain letters, numbers, dashes, underscores, and dots."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:"Routing Strategy"}),e.jsx(se,{value:r,onChange:N=>h(N),options:[{value:"round-robin",label:"Round Robin — Rotate across accounts"},{value:"fallback",label:"Fallback — Sequential priority order"},{value:"fusion",label:"Fusion — Parallel query panel + judge synthesis"},{value:"lkgp",label:"LKGP — Last Known Good (maximize prompt cache warmth)"},{value:"p2c",label:"P2C — Power of Two Choices (dynamic EMA load balancing)"}],className:"w-full"}),e.jsxs("div",{className:"mt-2 p-2.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-[11px] text-slate-400",children:[r==="round-robin"&&e.jsxs("span",{className:"text-cyan-300",children:[e.jsx("strong",{children:"Round Robin:"})," Spreads requests across member models in alternating turns to balance rate limits."]}),r==="fallback"&&e.jsxs("span",{className:"text-blue-300",children:[e.jsx("strong",{children:"Fallback:"})," Tries models sequentially; moves to backup on HTTP 429, 503, or quota errors."]}),r==="fusion"&&e.jsxs("span",{className:"text-indigo-300",children:[e.jsx("strong",{children:"Fusion:"})," Queries member models concurrently in parallel, then synthesizes the best answer with a judge."]}),r==="lkgp"&&e.jsxs("span",{className:"text-emerald-300",children:[e.jsx("strong",{children:"LKGP (Last Known Good):"})," Retains the model that succeeded on the last request to keep prompt caches warm; fails over on error."]}),r==="p2c"&&e.jsxs("span",{className:"text-amber-300",children:[e.jsx("strong",{children:"P2C (Power of Two Choices):"})," Samples 2 candidates at random and routes to the one with superior latency and error score via EMA."]})]})]}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("label",{className:"block text-xs font-semibold text-slate-200",children:["Member Models (",l.length,") ",e.jsx("span",{className:"text-rose-400",children:"*"})]}),e.jsxs("button",{type:"button",onClick:()=>L(!0),className:"px-3 py-1 rounded-lg bg-blue-600/10 border border-blue-500/30 text-blue-400 hover:bg-blue-600/20 text-xs font-medium flex items-center gap-1.5 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"Add Model"]})]}),e.jsx("div",{className:"border border-[#1E293B] rounded-2xl bg-[#0A0D14]/50 p-2.5 space-y-2 min-h-[140px] max-h-[260px] overflow-y-auto",children:l.length===0?e.jsx("div",{className:"py-8 text-center text-slate-500 text-xs",children:"No models in this combo yet. Click “Add Model” to pick from catalog or enter a model ID below."}):e.jsx(Pe,{sensors:b,collisionDetection:Ve,onDragEnd:H,children:e.jsx(_e,{items:l.map((N,f)=>`${N}-${f}`),strategy:qe,children:e.jsx("div",{className:"space-y-1.5",children:l.map((N,f)=>e.jsx(je,{id:`${N}-${f}`,model:N,index:f,onEdit:_,onRemove:Q,onMoveUp:W,onMoveDown:U,isFirst:f===0,isLast:f===l.length-1,excludeValues:R},`${N}-${f}`))})})})}),C&&e.jsxs("p",{className:"text-[11px] text-rose-400 flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"error"}),C]}),e.jsxs("div",{className:"flex gap-2 pt-1 items-start",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(ge,{placeholder:"Or search/type model ID (e.g. anthropic/claude-3-7-sonnet)...",value:v,onChange:$,onEnter:N=>Z(void 0,N),excludeValues:R,allowCombos:!1,className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-1.5 text-xs text-white font-mono placeholder-slate-500 focus:outline-none focus:border-blue-500"})}),e.jsx("button",{type:"button",onClick:()=>Z(),disabled:!v.trim(),className:"px-3 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] hover:border-blue-500/50 hover:bg-blue-600/10 text-xs text-slate-300 hover:text-white disabled:opacity-40 cursor-pointer whitespace-nowrap shrink-0",children:"Add"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-4 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:s,disabled:B,className:"px-4 py-2 rounded-xl text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] hover:border-slate-700 transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:B,className:"px-5 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer",children:B?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving..."]}):e.jsx("span",{children:y?"Update Combo":"Save Combo"})})]})]})}),S&&e.jsx(ye,{isOpen:S,onClose:()=>L(!1),addedModelValues:l,initialSelectedModels:l,excludeModelIds:R,allowCombos:!1,onConfirm:N=>{c(N),N.length>0&&k("")},title:"Add Model to Combo",multiSelect:!0,closeOnSelect:!1})]})},at=({searchInputRef:a,searchQuery:s,onSearchChange:n,onlyConnected:m,onToggleOnlyConnected:x,groupMode:i,onGroupModeChange:o,onlyMultiProvider:r,onToggleOnlyMultiProvider:h,modalityFilter:l,onModalityFilterChange:c,onSelectConnectedOnly:p,onDeselectAll:T,onTestAll:C,isTestingAll:k,mobileTab:v,onMobileTabChange:$,totalMatchingCount:S,selectedCount:L,isMultiMode:B,activeGroupsCount:A})=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 sm:px-5 py-2.5 border-b border-[#1E293B] bg-[#0A0D14]/40 flex flex-wrap items-center gap-2 shrink-0",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-[16px] text-slate-500",children:"search"}),e.jsx("input",{ref:a,type:"text",value:s,onChange:y=>n(y.target.value),placeholder:"Search free providers or models...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl pl-9 pr-7 py-1.5 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-emerald-500 font-mono"}),s&&e.jsx("button",{type:"button",onClick:()=>n(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("div",{className:"flex items-center p-0.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] shrink-0",children:[{id:"provider",label:"Provider"},{id:"model",label:"Model"},{id:"family",label:"Family"},{id:"role",label:"Role"}].map(y=>e.jsx("button",{type:"button",onClick:()=>o(y.id),className:`px-2.5 py-1 rounded-lg text-[11px] font-medium transition-colors cursor-pointer ${i===y.id?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:y.label},y.id))}),e.jsxs("button",{type:"button",onClick:x,className:`px-2.5 py-1.5 rounded-xl text-[11px] font-medium border flex items-center gap-1 transition-colors cursor-pointer shrink-0 ${m?"bg-emerald-500/15 text-emerald-300 border-emerald-500/35":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-white"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:m?"check_circle":"filter_alt"}),e.jsx("span",{children:"Connected Only"})]}),i==="model"&&e.jsxs("button",{type:"button",onClick:h,className:`px-2.5 py-1.5 rounded-xl text-[11px] font-medium border flex items-center gap-1 transition-colors cursor-pointer shrink-0 ${r?"bg-purple-500/15 text-purple-300 border-purple-500/35":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-white"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"hub"}),e.jsx("span",{children:"2+ Providers"})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>c("all"),className:`px-2 py-1.5 rounded-xl text-[11px] font-medium border transition-colors cursor-pointer ${l==="all"?"bg-blue-600 text-white border-blue-500":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-white"}`,children:"All"}),e.jsxs("button",{type:"button",onClick:()=>c(l==="vision"?"all":"vision"),className:`px-2 py-1.5 rounded-xl text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${l==="vision"?"bg-cyan-500/20 text-cyan-300 border-cyan-500/40":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-cyan-300"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"visibility"}),"Vision"]}),e.jsxs("button",{type:"button",onClick:()=>c(l==="reasoning"?"all":"reasoning"),className:`px-2 py-1.5 rounded-xl text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${l==="reasoning"?"bg-emerald-500/20 text-emerald-300 border-emerald-500/40":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-emerald-300"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"psychology"}),"Reasoning"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[e.jsx("button",{type:"button",onClick:p,className:"px-2 py-1.5 rounded-xl bg-emerald-500/10 hover:bg-emerald-500/20 text-emerald-400 text-[11px] font-medium border border-emerald-500/25 cursor-pointer",title:"Select all models from connected providers",children:"+ Connected"}),e.jsx("button",{type:"button",onClick:T,className:"px-2 py-1.5 rounded-xl bg-[#0A0D14] hover:bg-slate-800 text-slate-400 hover:text-white text-[11px] font-medium border border-[#1E293B] cursor-pointer",children:"Clear"}),e.jsxs("button",{type:"button",onClick:C,disabled:k,className:"px-2.5 py-1.5 rounded-xl bg-blue-600/15 hover:bg-blue-600/25 text-blue-400 text-[11px] font-semibold border border-blue-500/30 flex items-center gap-1 cursor-pointer disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[13px] ${k?"animate-spin":""}`,children:k?"refresh":"network_check"}),e.jsx("span",{children:k?"Testing...":"Test All"})]})]})]}),e.jsxs("div",{className:"lg:hidden grid grid-cols-2 border-b border-[#1E293B] bg-[#080B12] shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>$("catalog"),className:`py-2 text-xs font-semibold border-b-2 transition-colors cursor-pointer ${v==="catalog"?"border-emerald-500 text-emerald-400 bg-emerald-500/5":"border-transparent text-slate-400"}`,children:["Browse (",S,")"]}),e.jsx("button",{type:"button",onClick:()=>$("selected"),className:`py-2 text-xs font-semibold border-b-2 transition-colors cursor-pointer ${v==="selected"?"border-emerald-500 text-emerald-400 bg-emerald-500/5":"border-transparent text-slate-400"}`,children:B?`Combos (${A})`:`Selected (${L})`})]})]}),lt=({isMultiMode:a,onToggleMultiMode:s,canMultiMode:n,comboName:m,onComboNameChange:x,namePrefix:i,onNamePrefixChange:o,strategy:r,onStrategyChange:h,activeGroupsCount:l})=>e.jsxs("div",{className:"px-4 sm:px-5 py-2.5 border-b border-[#1E293B] bg-[#0A0D14]/60 flex flex-wrap items-center gap-2.5 shrink-0",children:[n&&e.jsxs("div",{className:"flex items-center p-0.5 rounded-xl bg-[#0F1420] border border-[#1E293B] shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>s(!1),className:`px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-colors cursor-pointer ${a?"text-slate-400 hover:text-white":"bg-emerald-600 text-white"}`,children:"Single Combo"}),e.jsxs("button",{type:"button",onClick:()=>s(!0),className:`px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-colors cursor-pointer flex items-center gap-1 ${a?"bg-emerald-600 text-white":"text-slate-400 hover:text-white"}`,children:[e.jsx("span",{children:"Batch"}),l>0&&e.jsx("span",{className:"px-1 rounded bg-black/25 text-[10px] font-mono",children:l})]})]}),a?e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-[200px]",children:[e.jsx("span",{className:"text-[11px] font-semibold text-slate-400 shrink-0",children:"Prefix:"}),e.jsx("input",{type:"text",value:i,onChange:c=>o(c.target.value),placeholder:"free-",className:"flex-1 bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-xs font-mono text-white placeholder-slate-500 focus:outline-none focus:border-emerald-500"})]}):e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-[220px]",children:[e.jsx("span",{className:"text-[11px] font-semibold text-slate-400 shrink-0",children:"Combo Name:"}),e.jsx("input",{type:"text",value:m,onChange:c=>x(c.target.value),placeholder:"e.g. free-fallback",className:"flex-1 bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-xs font-mono text-white placeholder-slate-500 focus:outline-none focus:border-emerald-500"})]}),e.jsxs("div",{className:"flex items-center gap-2 min-w-[210px]",children:[e.jsx("span",{className:"text-[11px] font-semibold text-slate-400 shrink-0",children:"Strategy:"}),e.jsx(se,{value:r,onChange:c=>h(c),options:[{value:"fallback",label:"Fallback (priority order)"},{value:"round-robin",label:"Round Robin (rotate)"},{value:"fusion",label:"Fusion (parallel judge)"},{value:"lkgp",label:"LKGP (cache warmth)"},{value:"p2c",label:"P2C (adaptive latency)"}],className:"flex-1"})]})]}),ve=ae.memo(({groupMode:a,railItems:s,activeScopeId:n,onSelectScope:m,totalMatchingCount:x})=>{const i=n==="all",o=a==="provider"?`Free Providers (${s.length})`:a==="model"?`Model Groups (${s.length})`:a==="family"?`Model Families (${s.length})`:`Model Roles (${s.length})`;return e.jsxs("div",{className:"hidden lg:flex lg:flex-col lg:col-span-3 min-h-0 bg-[#080B12]/70 overflow-hidden",children:[e.jsx("div",{className:"px-3.5 py-2.5 border-b border-[#1E293B] flex items-center justify-between shrink-0",children:e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider text-slate-400",children:o})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto p-2 space-y-1",children:[e.jsxs("button",{type:"button",onClick:()=>m("all"),className:`w-full flex items-center justify-between gap-2 px-2.5 py-2 rounded-xl text-left transition-colors duration-75 cursor-pointer ${i?"bg-emerald-600/15 border border-emerald-500/40 text-white":"border border-transparent text-slate-300 hover:bg-white/[0.04] hover:text-white"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"size-6 rounded-lg bg-[#141B2D] border border-[#1E293B] flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[15px] text-emerald-400",children:"savings"})}),e.jsx("span",{className:"text-xs font-semibold truncate",children:a==="provider"?"All Free Models":"All Groups"})]}),e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-slate-800/90 text-slate-400 shrink-0",children:x})]}),s.length>0&&e.jsx("div",{className:"my-1.5 border-t border-[#1E293B]/70"}),s.map(r=>{const h=n===r.id,l=r.connectionStatus==="connected"?"bg-emerald-400":r.connectionStatus==="not_connected"?"bg-amber-400":r.connectionStatus?"bg-rose-400":null;return e.jsxs("button",{type:"button",onClick:()=>m(r.id),className:`w-full flex items-center justify-between gap-2 px-2.5 py-1.5 rounded-xl text-left transition-colors duration-75 cursor-pointer ${h?"bg-emerald-600/15 border border-emerald-500/40 text-white":"border border-transparent text-slate-300 hover:bg-white/[0.04] hover:text-white"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[a==="provider"?e.jsx(oe,{src:r.image,name:r.name,color:r.color,iconBg:r.iconBg,size:"sm",className:"!size-6 !rounded-lg !p-0.5"}):e.jsxs("div",{className:"size-6 rounded-lg bg-[#141B2D] border border-[#1E293B] flex items-center justify-center shrink-0 text-[10px] font-mono font-bold text-purple-300",children:[r.uniqueProvidersCount??1,"P"]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-xs font-medium truncate",children:r.name}),l&&e.jsx("span",{className:`size-1.5 rounded-full shrink-0 ${l}`,title:r.subLabel})]}),a!=="provider"&&(r.connectedProvidersCount??0)>0&&e.jsxs("span",{className:"text-[9.5px] text-emerald-400 block leading-tight",children:[r.connectedProvidersCount," connected"]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.selectedCount>0&&e.jsx("span",{className:"text-[10px] font-mono px-1.5 py-0.2 rounded bg-emerald-500/25 text-emerald-300 border border-emerald-500/35 font-semibold",title:`${r.selectedCount} selected`,children:r.selectedCount}),e.jsx("span",{className:"text-[10px] font-mono text-slate-500 min-w-[20px] text-right",children:r.totalCount})]})]},r.id)})]})]})});ve.displayName="FreeTierSidebar";const Ne=ae.memo(({groupMode:a,railItems:s,activeScopeId:n,onSelectScope:m,totalMatchingCount:x})=>{const i=[{value:"all",label:a==="provider"?`All Free Models (${x})`:`All Groups (${x})`},...s.map(o=>({value:o.id,label:`${o.name} (${o.totalCount})${o.selectedCount>0?` • ${o.selectedCount}✓`:""}`}))];return e.jsx("div",{className:"lg:hidden shrink-0",children:e.jsx(se,{value:n,onChange:m,options:i,className:"w-full"})})});Ne.displayName="MobileFreeTierScopeSelect";const we=ae.memo(({item:a,isSelected:s,showProviderInfo:n,isTesting:m,onToggle:x,onTestConnection:i})=>{const o=He(a.contextLength),r=a.connectionStatus==="connected"?"bg-emerald-400":a.connectionStatus==="not_connected"?"bg-amber-400":"bg-rose-400";return e.jsxs("div",{onClick:()=>x(a.comboModelValue),className:`h-full flex items-center justify-between gap-2.5 px-3 py-2 rounded-xl border transition-colors duration-75 cursor-pointer select-none ${s?"bg-emerald-600/12 border-emerald-500/45 text-white":"bg-[#0A0D14] border-[#1E293B] hover:border-slate-700 hover:bg-[#0F1420] text-slate-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[n&&e.jsx(oe,{src:a.providerImage,name:a.providerName,color:a.providerColor,iconBg:a.providerIconBg,size:"sm",className:"!size-6 !rounded-lg !p-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[n&&e.jsx("span",{className:"px-1.5 py-0.2 rounded bg-slate-800/90 border border-slate-700/70 text-[9.5px] font-medium text-slate-300 shrink-0 max-w-[96px] truncate",children:a.providerName}),e.jsx("span",{className:"text-xs font-semibold text-white truncate",children:a.modelName}),o&&e.jsx("span",{className:"text-[9.5px] font-mono px-1 py-0.2 rounded bg-slate-800 text-slate-400 border border-slate-700/60 leading-tight shrink-0",children:o})]}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0 mt-0.5",children:[e.jsx("span",{className:"font-mono text-[10.5px] text-slate-400 truncate",children:a.comboModelValue}),a.limit&&e.jsxs("span",{className:"text-[10px] text-cyan-400/90 truncate shrink-0 max-w-[150px]",children:["• ",a.limit]}),a.latencyMs!=null&&e.jsxs("span",{className:"text-[10px] text-emerald-400 font-mono shrink-0",children:[a.latencyMs,"ms"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(re,{caps:a.caps,size:"xs"}),n&&e.jsxs("button",{type:"button",onClick:h=>{h.stopPropagation(),i(a.providerId)},disabled:m,title:a.statusDetail?`${a.statusLabel} (${a.statusDetail})`:a.statusLabel,className:"p-1 rounded-lg bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-slate-400 hover:text-white flex items-center gap-1 cursor-pointer disabled:opacity-50",children:[e.jsx("span",{className:`size-1.5 rounded-full ${r}`}),e.jsx("span",{className:`material-symbols-outlined text-[13px] ${m?"animate-spin text-blue-400":""}`,children:m?"refresh":"network_check"})]}),e.jsx("button",{type:"button",onClick:h=>{h.stopPropagation(),x(a.comboModelValue)},"aria-label":s?`Deselect ${a.comboModelValue}`:`Select ${a.comboModelValue}`,className:`size-7 rounded-lg flex items-center justify-center shrink-0 border transition-colors duration-75 cursor-pointer ${s?"bg-emerald-600 border-emerald-500 text-white":"bg-[#141B2D] border-[#1E293B] text-slate-400 hover:text-white hover:border-slate-600"}`,children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:s?"check":"add"})})]})]})});we.displayName="FreeTierModelRow";const nt=66,xe={local:{label:"Local Engine",cls:"bg-purple-500/10 text-purple-400 border-purple-500/20"},credits:{label:"Free Credits",cls:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20"},"per-model":{label:"Per-Model Limits",cls:"bg-blue-500/10 text-blue-400 border-blue-500/20"},requests:{label:"Free Requests",cls:"bg-cyan-500/10 text-cyan-400 border-cyan-500/20"}},rt=({groupMode:a,railItems:s,activeScopeId:n,onSelectScope:m,visibleCandidates:x,totalMatchingCount:i,activeProvider:o,activeGroup:r,selectedSet:h,selectedInViewCount:l,testingIds:c,isMultiMode:p,groupComboName:T,onGroupComboNameChange:C,onToggleModel:k,onAddAllVisible:v,onDeselectVisible:$,onTestConnection:S,onlyConnected:L,onShowAllProviders:B,scrollKey:A,className:y=""})=>{const b=n==="all"||a!=="provider",I=d.useCallback(D=>e.jsx(we,{item:D,isSelected:h.has(D.comboModelValue),showProviderInfo:b,isTesting:c.has(D.providerId),onToggle:k,onTestConnection:S}),[h,b,c,k,S]),E=d.useCallback(D=>D.comboModelValue,[]),R=o?xe[o.freeTier.limitType||"requests"]||xe.requests:null;return e.jsxs("div",{className:`lg:col-span-5 flex-col min-h-0 p-3.5 space-y-2.5 overflow-hidden ${y}`,children:[e.jsx(Ne,{groupMode:a,railItems:s,activeScopeId:n,onSelectScope:m,totalMatchingCount:i}),o?e.jsxs("div",{className:"p-2.5 rounded-xl border border-[#1E293B] bg-[#0A0D14]/80 space-y-1.5 shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(oe,{src:o.provider.image,name:o.provider.name,color:o.provider.color,iconBg:o.provider.iconBg,size:"sm",className:"!size-6 !rounded-lg !p-0.5 shrink-0"}),e.jsx("span",{className:"text-xs font-bold text-white truncate",children:o.provider.name}),R&&e.jsx("span",{className:`px-1.5 py-0.2 rounded text-[10px] font-medium border shrink-0 ${R.cls}`,children:R.label})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10.5px] font-medium border ${o.connectionStatus==="connected"?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":o.connectionStatus==="not_connected"?"bg-amber-500/10 text-amber-400 border-amber-500/20":"bg-rose-500/10 text-rose-400 border-rose-500/20"}`,title:o.statusDetail||o.statusLabel,children:[e.jsx("span",{className:"size-1.5 rounded-full bg-current"}),e.jsx("span",{children:o.statusLabel})]}),e.jsxs("button",{type:"button",onClick:()=>S(o.provider.id),disabled:c.has(o.provider.id),className:"px-2 py-0.5 rounded-md bg-slate-800 hover:bg-slate-700 text-slate-300 text-[10.5px] font-medium flex items-center gap-1 cursor-pointer disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[12px] ${c.has(o.provider.id)?"animate-spin text-blue-400":""}`,children:c.has(o.provider.id)?"refresh":"network_check"}),e.jsx("span",{children:"Test"})]})]})]}),o.freeTier.note&&e.jsx("p",{className:"text-[11px] text-slate-400 leading-snug",children:o.freeTier.note})]}):r?e.jsxs("div",{className:"p-2.5 rounded-xl border border-[#1E293B] bg-[#0A0D14]/80 flex flex-wrap items-center justify-between gap-2 shrink-0",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-xs font-bold text-white truncate block",children:r.name}),r.description&&e.jsx("span",{className:"text-[11px] text-slate-400 truncate block",children:r.description})]}),p&&a!=="provider"&&e.jsxs("div",{className:"flex items-center gap-1.5 bg-[#0F1420] px-2 py-1 rounded-lg border border-[#1E293B]",children:[e.jsx("span",{className:"text-[10px] font-mono text-slate-400",children:"Combo:"}),e.jsx("input",{type:"text",value:T??r.defaultComboName,onChange:D=>C(r.id,D.target.value),placeholder:r.defaultComboName,className:"w-36 bg-transparent text-[11px] font-mono text-emerald-400 focus:outline-none"})]})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-2 px-0.5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-xs font-bold text-white truncate",children:o?"Models":r?"Providers for Group":a==="provider"?"All Free Models":"All Matching Candidates"}),e.jsxs("span",{className:"text-[11px] font-mono text-slate-400 shrink-0",children:[x.length," model",x.length!==1?"s":""]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[l>0&&e.jsxs("button",{type:"button",onClick:$,className:"text-[11px] text-slate-400 hover:text-rose-400 cursor-pointer transition-colors",children:["Deselect (",l,")"]}),x.length>0&&x.length<=50&&l<x.length&&e.jsxs("button",{type:"button",onClick:v,className:"text-[11px] text-emerald-400 hover:text-emerald-300 font-medium cursor-pointer transition-colors",children:["+ Select all (",x.length,")"]})]})]}),x.length===0?e.jsx("div",{className:"flex-1 min-h-0 flex items-center justify-center",children:e.jsxs("div",{className:"py-10 text-center text-slate-500 text-xs space-y-2.5 px-4",children:[e.jsx("span",{className:"material-symbols-outlined text-[28px] text-slate-600 block mx-auto",children:"search_off"}),e.jsx("p",{className:"max-w-xs mx-auto leading-relaxed",children:L?"No connected free tier models match your current filter.":"No matching free tier models found."}),e.jsxs("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:[n!=="all"&&i>0&&e.jsxs("button",{type:"button",onClick:()=>m("all"),className:"px-3 py-1 rounded-lg bg-emerald-600/15 border border-emerald-500/35 text-emerald-300 hover:bg-emerald-600/25 text-xs font-medium cursor-pointer",children:["Search All (",i,")"]}),L&&e.jsx("button",{type:"button",onClick:B,className:"px-3 py-1 rounded-lg bg-blue-600/10 border border-blue-500/30 text-blue-300 hover:bg-blue-600/20 text-xs font-medium cursor-pointer",children:"Show All Free Providers"})]})]})}):e.jsx(Ze,{items:x,itemHeight:nt,scrollKey:A,getKey:E,renderItem:I,className:"flex-1 min-h-0 pr-1"})]})},Ce=ae.memo(({activeGroups:a,selectedSet:s,groupComboNames:n,onGroupComboNameChange:m,onRemoveModel:x,onClearAll:i,className:o=""})=>e.jsxs("div",{className:`flex flex-col min-h-0 p-3.5 space-y-2.5 bg-[#0A0D14]/45 overflow-hidden ${o}`,children:[e.jsxs("div",{className:"flex items-center justify-between pb-2 border-b border-[#1E293B] shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[18px]",children:"dynamic_feed"}),e.jsxs("span",{className:"text-xs font-bold text-white",children:["Batch Combos (",a.length,")"]})]}),s.size>0&&e.jsx("button",{type:"button",onClick:i,className:"text-[11px] text-slate-500 hover:text-rose-400 transition-colors cursor-pointer",children:"Clear all"})]}),e.jsx("p",{className:"text-[11px] text-slate-400 leading-snug shrink-0",children:"Each active group generates a separate combo. Edit combo names inline before creating."}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto pr-1 space-y-2",children:a.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-xs border border-dashed border-[#1E293B] rounded-2xl p-4",children:"Select models from any group on the left to preview batch combos here."}):a.map(r=>{const h=r.candidates.map(l=>l.model.comboModelValue).filter(l=>s.has(l));return e.jsxs("div",{className:"p-2.5 rounded-xl border border-[#1E293B] bg-[#0A0D14] space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("input",{type:"text",value:n[r.id]??r.defaultComboName,onChange:l=>m(r.id,l.target.value),placeholder:r.defaultComboName,className:"flex-1 min-w-0 bg-[#141B2D] border border-[#1E293B] focus:border-emerald-500 rounded-lg px-2 py-1 text-xs font-mono text-emerald-300 focus:outline-none"}),e.jsxs("span",{className:"text-[10px] font-mono text-slate-400 shrink-0",children:[h.length," model",h.length>1?"s":""]})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:h.map(l=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md bg-[#141B2D] border border-[#1E293B] text-[10.5px] font-mono text-slate-300 max-w-full",children:[e.jsx("span",{className:"truncate",children:l}),e.jsx("button",{type:"button",onClick:()=>x(l),className:"text-slate-500 hover:text-rose-400 cursor-pointer shrink-0",title:"Remove",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},l))})]},r.id)})})]}));Ce.displayName="BatchCombosPreviewPanel";function ot(a,s){if(!a||!s)return!1;if(a===s)return!0;const n=a.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${n}$`,"i").test(s)}function it(a){return a?a.freeTier!=null||a.category==="freeTier"||a.category==="free"||a.isLocal===!0||a.requiresApiKey===!1||a.authType==="none"||a.noAuth===!0:!1}function ct(a,s){const n=a.freeTier,m=a.models||[],x=(s==null?void 0:s.models)||[],i=new Map;for(const l of m)!l||!l.id||l.kind&&l.kind!=="chat"||i.set(l.id,{id:l.id,name:l.name||l.id,contextLength:l.contextLength,kind:l.kind,capabilities:Array.isArray(l.capabilities)?l.capabilities:void 0});for(const l of x){const c=typeof l=="string"?l:l==null?void 0:l.id;if(!c)continue;const p=typeof l=="object"?l.kind:void 0;p&&p!=="chat"||i.has(c)||i.set(c,{id:c,name:typeof l=="string"?l:l.name||c,contextLength:typeof l=="object"?l.contextLength:void 0,kind:p,capabilities:typeof l=="object"?l.capabilities:void 0})}const o=[],r=new Set,h=l=>l.startsWith(`${a.id}/`)?l:`${a.id}/${l}`;if(!n){for(const[l,c]of i.entries())r.has(l)||(r.add(l),o.push({id:l,comboModelValue:h(l),name:c.name,limit:a.isLocal?"Local inference":void 0,contextLength:c.contextLength,kind:c.kind,capabilities:c.capabilities,providerId:a.id}));return o}if(Array.isArray(n.models))for(const l of n.models){if(!l||!l.id)continue;const c=l.id,p=i.get(c);p!=null&&p.kind&&p.kind!=="chat"||r.has(c)||(r.add(c),o.push({id:c,comboModelValue:h(c),name:(p==null?void 0:p.name)||c,limit:l.limit||n.note,contextLength:p==null?void 0:p.contextLength,kind:p==null?void 0:p.kind,capabilities:p==null?void 0:p.capabilities,providerId:a.id}))}if(Array.isArray(n.match)&&n.match.length>0)for(const[l,c]of i.entries()){if(r.has(l)||c.kind&&c.kind!=="chat")continue;n.match.some(T=>ot(T,l))&&(r.add(l),o.push({id:l,comboModelValue:h(l),name:c.name,limit:n.note||"Free tier",contextLength:c.contextLength,kind:c.kind,capabilities:c.capabilities,providerId:a.id}))}if(n.scope==="all"){for(const[l,c]of i.entries())if(!r.has(l)){if(c.kind&&c.kind!=="chat")continue;r.add(l),o.push({id:l,comboModelValue:h(l),name:c.name,limit:n.note,contextLength:c.contextLength,kind:c.kind,capabilities:c.capabilities,providerId:a.id})}}return o}function dt(a,s,n){if(n){if(n.success)return{status:"connected",label:"Connected",detail:n.latencyMs!=null?`${n.latencyMs}ms`:void 0};const o=n.error||n.message||"Connection failed",r=/quota|rate limit|exhausted|429/i.test(o);return{status:r?"exhausted":"error",label:r?"Quota Exhausted":"Connection Error",detail:o}}if(a.isLocal)return{status:"connected",label:"Local Engine",detail:"Runs on localhost"};if(a.noAuth||a.requiresApiKey===!1||a.authType==="none")return{status:"connected",label:"Ready (Zero Config)"};const x=((s==null?void 0:s.accounts)||[]).filter(o=>o.isActive!==!1),i=(s==null?void 0:s.accountsCount)??x.length;return i>0||x.length>0?x.length>0&&x.every(r=>(r.rateLimitHits??0)>=3)?{status:"exhausted",label:"Rate Limited",detail:"Cooldown active"}:{status:"connected",label:"Connected",detail:`${i} account${i>1?"s":""}`}:{status:"not_connected",label:"Not Connected",detail:"API key required"}}function mt(a){const[s,n]=d.useState([]),[m,x]=d.useState(new Set),[i,o]=d.useState({}),[r,h]=d.useState(!1),l=d.useCallback(async()=>{try{const C=await fetch("/api/providers");if(C.ok){const k=await C.json();Array.isArray(k)&&n(k)}}catch(C){console.error("Failed to load providers:",C)}},[]);d.useEffect(()=>{a&&l()},[a,l]);const c=d.useMemo(()=>{const C=Object.values(Xe).filter(v=>v.id==="combo"||v.category==="composite"?!1:it(v)),k=new Map(s.map(v=>[v.id,v]));return C.map(v=>{var b;const $=k.get(v.id),S=v.freeTier||{scope:"all",limitType:v.isLocal?"local":"requests",note:(b=v.notice)==null?void 0:b.text},L=ct(v,$),B=i[v.id],A=dt(v,$,B),y=($==null?void 0:$.accountsCount)??(Array.isArray($==null?void 0:$.accounts)?$.accounts.length:0);return{provider:v,freeTier:S,freeModels:L,accountsCount:y,connectionStatus:A.status,statusLabel:A.label,statusDetail:A.detail,testResult:B}})},[s,i]),p=async C=>{x(k=>new Set(k).add(C));try{const v=await(await fetch(`/api/providers/${encodeURIComponent(C)}/test`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timeoutMs:7e3})})).json();o($=>({...$,[C]:{success:!!v.success,message:v.message,latencyMs:v.latencyMs,error:v.error}}))}catch(k){o(v=>({...v,[C]:{success:!1,error:k.message||"Test failed"}}))}finally{x(k=>{const v=new Set(k);return v.delete(C),v})}};return{freeProvidersList:c,testingIds:m,isTestingAll:r,testConnection:p,testAll:async C=>{h(!0),await Promise.allSettled(C.map(k=>p(k))),h(!1)}}}function ut(a){if(!a)return"";let s=a.trim().toLowerCase();return s.includes("/")&&(s=s.split("/").pop()),s=s.replace(/:free$/,"").replace(/-free$/,"").replace(/\/free$/,"").replace(/-contributor-free(-exp)?$/,"").replace(/-vision-exp$/,"").replace(/-(versatile|instant|instruct|preview|latest|it)$/,"").replace(/-(2501|2507|1017)$/,""),s=s.replace(/\./g,"-").replace(/[\s_]+/g,"-").replace(/-+/g,"-"),s=s.replace(/^meta-llama-/,"llama-").replace(/^qwen3/,"qwen-3").replace(/^qwen2-5/,"qwen-2-5").replace(/^llama3-3/,"llama-3-3").replace(/^llama4/,"llama-4").replace(/^zai-glm-/,"glm-"),s.replace(/^-+|-+$/g,"")}function xt(a){if(!a)return"Unknown Model";const s={"llama-3-3-70b":"Llama 3.3 70B","llama-3-1-8b":"Llama 3.1 8B","llama-4-maverick-17b-128e":"Llama 4 Maverick","llama-4-scout-17b-16e":"Llama 4 Scout","qwen-3-32b":"Qwen 3 32B","qwen-2-5-coder-32b":"Qwen 2.5 Coder 32B","gpt-oss-120b":"GPT OSS 120B","gemini-3-8-flash":"Gemini 3.8 Flash","gemini-2-5-flash":"Gemini 2.5 Flash","gemini-2-5-pro":"Gemini 2.5 Pro","deepseek-r1-distill-llama-70b":"DeepSeek R1 (Llama 70B)","deepseek-r1":"DeepSeek R1","deepseek-v4-flash":"DeepSeek V4 Flash","deepseek-v4-1-flash":"DeepSeek V4.1 Flash","minimax-m2-7":"MiniMax M2.7","minimax-m3":"MiniMax M3",codestral:"Codestral","mistral-small":"Mistral Small"};return s[a]?s[a]:a.split("-").map(n=>n.length<=3?n.toUpperCase():n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function pt(a){const s=a.toLowerCase();return s.includes("llama")?{id:"llama",name:"Meta Llama"}:s.includes("qwen")||s.includes("qwq")?{id:"qwen",name:"Qwen"}:s.includes("deepseek")?{id:"deepseek",name:"DeepSeek"}:s.includes("gemini")||s.includes("gemma")?{id:"gemini",name:"Google Gemini"}:s.includes("mistral")||s.includes("codestral")||s.includes("ministral")?{id:"mistral",name:"Mistral AI"}:s.includes("glm")||s.includes("zcode")?{id:"glm",name:"Zhipu GLM"}:s.includes("minimax")?{id:"minimax",name:"MiniMax"}:s.includes("gpt")||s.includes("openai")?{id:"gpt",name:"OpenAI / GPT-OSS"}:s.includes("kilo")?{id:"kilo",name:"Kilo Gateway"}:{id:"community",name:"Community / Other"}}function bt(a,s){let n="";Array.isArray(s.capabilities)?n=s.capabilities.join(" "):s.capabilities&&typeof s.capabilities=="object"?n=Object.entries(s.capabilities).filter(([x,i])=>!!i).map(([x])=>x).join(" "):typeof s.capabilities=="string"&&(n=s.capabilities);const m=`${a} ${s.name||""} ${n}`.toLowerCase();return m.includes("coder")||m.includes("codestral")||m.includes("code")?{id:"coding",name:"Coding Specialists",description:"Models tuned specifically for programming and code completion"}:m.includes("r1")||m.includes("qwq")||m.includes("reasoning")||m.includes("thinking")?{id:"reasoning",name:"Deep Reasoning",description:"Chain-of-thought and deep reasoning models for complex problem solving"}:m.includes("flash-lite")||m.includes("instant")||m.includes("nano")||m.includes("mini")||m.includes("-8b")||m.includes("-3b")||m.includes("-1b")?{id:"fast",name:"Fast & Lightweight",description:"Ultra-fast low-latency models for autocomplete and quick tasks"}:{id:"general",name:"General & Balanced",description:"High-capacity balanced models for versatile assistant workflows"}}function ht(a){return[...a].sort((s,n)=>{const m=o=>o==="connected"?0:o==="not_connected"?1:2,x=m(s.connectionStatus),i=m(n.connectionStatus);return x!==i?x-i:s.latencyMs!=null&&n.latencyMs!=null?s.latencyMs-n.latencyMs:s.latencyMs!=null?-1:n.latencyMs!=null?1:s.provider.name.localeCompare(n.provider.name)})}function ft(a,s,n=new Set){const m=s instanceof Set?s:new Set(s);let x=a.trim().toLowerCase().replace(/[^a-zA-Z0-9_.-]/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"");x||(x="free-combo");let i=x,o=2;for(;m.has(i)||n.has(i);)i=`${x}-${o++}`;return n.add(i),i}function gt(a,s,n="free-"){var i;const m=new Map;for(const o of a)for(const r of o.freeModels){const h=ut(r.id);let l="",c="",p;if(s==="model")l=h||r.id,c=xt(h);else if(s==="family"){const C=pt(h);l=C.id,c=C.name,p=`Models from the ${C.name} architecture`}else{const C=bt(h,r);l=C.id,c=C.name,p=C.description}if(!m.has(l)){const k=`${n.replace(/[^a-zA-Z0-9_.-]/g,"")}${l}`.replace(/-+/g,"-");m.set(l,{id:l,name:c,description:p,defaultComboName:k,candidates:[]})}m.get(l).candidates.push({model:r,provider:o.provider,connectionStatus:o.connectionStatus,statusLabel:o.statusLabel,statusDetail:o.statusDetail,latencyMs:(i=o.testResult)==null?void 0:i.latencyMs})}const x=[];for(const o of m.values()){o.candidates=ht(o.candidates);const r=new Set(o.candidates.map(h=>h.provider.id)).size;o.badge=`${r} Provider${r>1?"s":""}`,x.push(o)}return s==="model"?x.sort((o,r)=>{const h=new Set(o.candidates.map(c=>c.provider.id)).size,l=new Set(r.candidates.map(c=>c.provider.id)).size;return h!==l?l-h:o.name.localeCompare(r.name)}):x.sort((o,r)=>r.candidates.length-o.candidates.length),x}const ke=/^[a-zA-Z0-9_.-]+$/;function yt(a,s,n,m,x){const i=[],o=new Set(m);for(const r of a){const h=(n[r.id]||r.defaultComboName).trim();if(!h)return{error:`Combo name for "${r.name}" cannot be empty.`};if(!ke.test(h))return{error:`Invalid name "${h}". Use only letters, numbers, -, _ and .`};if(o.has(h))return{error:`Combo name "${h}" already exists. Please choose another.`};o.add(h);const l=r.candidates.filter(c=>s.has(c.model.comboModelValue)).map(c=>c.model.comboModelValue);l.length>0&&i.push({name:h,models:l,strategy:x})}return i.length===0?{error:"No valid combos to create."}:{combos:i}}const jt=new Intl.Collator(void 0,{sensitivity:"base"});function vt(a){const s=new Map;for(const n of a)for(const m of n.freeModels)s.set(m.comboModelValue,ne(n.provider.id,m.id));return s}function pe(a,s){return s==="vision"?!!a.vision:s==="reasoning"?!!(a.reasoning||a.thinking||a.thinkingFormat):!0}function be(a,s,n,m,x,i,o){if(!a.trim())return!0;const r=`${s} ${n} ${m} ${x} ${i} ${o||""}`;return Ue(r,a)}function Nt(a){var $;const{freeProvidersList:s,groups:n,groupMode:m,searchQuery:x,onlyConnected:i,onlyMultiProvider:o,modalityFilter:r,activeScopeId:h,selectedSet:l,capsMap:c}=a,p=x.trim().toLowerCase();if(m==="provider"){const S=[],L=[];let B=0,A=null;for(const y of s){if(i&&y.connectionStatus!=="connected")continue;const b=[];let I=0;for(const E of y.freeModels){const R=c.get(E.comboModelValue)||ne(y.provider.id,E.id);pe(R,r)&&be(p,E.name,E.id,E.comboModelValue,y.provider.name,y.provider.id)&&(l.has(E.comboModelValue)&&I++,b.push({comboModelValue:E.comboModelValue,modelId:E.id,modelName:E.name,contextLength:E.contextLength,limit:E.limit,caps:R,providerId:y.provider.id,providerName:y.provider.name,providerColor:y.provider.color,providerIconBg:y.provider.iconBg,providerImage:y.provider.image,connectionStatus:y.connectionStatus,statusLabel:y.statusLabel,statusDetail:y.statusDetail,latencyMs:($=y.testResult)==null?void 0:$.latencyMs}))}b.length!==0&&(B+=b.length,h===y.provider.id&&(A=y),S.push({id:y.provider.id,name:y.provider.name,subLabel:y.statusLabel,image:y.provider.image,color:y.provider.color,iconBg:y.provider.iconBg,connectionStatus:y.connectionStatus,totalCount:b.length,selectedCount:I,limitType:y.freeTier.limitType}),(h==="all"||h===y.provider.id)&&L.push(...b))}return h==="all"&&L.sort((y,b)=>jt.compare(y.modelName,b.modelName)),{railItems:S,visibleCandidates:L,totalMatchingCount:B,activeProvider:A,activeGroup:null}}const T=[],C=[];let k=0,v=null;for(const S of n){if(m==="model"&&o&&new Set(S.candidates.map(I=>I.provider.id)).size<2)continue;const L=[];let B=0;const A=new Set,y=new Set;for(const b of S.candidates){if(i&&b.connectionStatus!=="connected")continue;const I=c.get(b.model.comboModelValue)||ne(b.provider.id,b.model.id);pe(I,r)&&be(p,b.model.name,b.model.id,b.model.comboModelValue,b.provider.name,b.provider.id,S.name)&&(A.add(b.provider.id),b.connectionStatus==="connected"&&y.add(b.provider.id),l.has(b.model.comboModelValue)&&B++,L.push({comboModelValue:b.model.comboModelValue,modelId:b.model.id,modelName:b.model.name,contextLength:b.model.contextLength,limit:b.model.limit,caps:I,providerId:b.provider.id,providerName:b.provider.name,providerColor:b.provider.color,providerIconBg:b.provider.iconBg,providerImage:b.provider.image,connectionStatus:b.connectionStatus,statusLabel:b.statusLabel,statusDetail:b.statusDetail,latencyMs:b.latencyMs,groupId:S.id,groupName:S.name}))}L.length!==0&&(k+=L.length,h===S.id&&(v=S),T.push({id:S.id,name:S.name,totalCount:L.length,selectedCount:B,uniqueProvidersCount:A.size,connectedProvidersCount:y.size}),(h==="all"||h===S.id)&&C.push(...L))}return{railItems:T,visibleCandidates:C,totalMatchingCount:k,activeProvider:null,activeGroup:v}}const wt=({isOpen:a,onClose:s,onSave:n,onSaveBatch:m,existingComboNames:x=[]})=>{const[i,o]=d.useState("free-fallback"),[r,h]=d.useState("free-"),[l,c]=d.useState("fallback"),[p,T]=d.useState("provider"),[C,k]=d.useState(!1),[v,$]=d.useState(!1),[S,L]=d.useState(!1),[B,A]=d.useState("all"),[y,b]=d.useState(""),I=d.useDeferredValue(y),[E,R]=d.useState("all"),[D,_]=d.useState([]),[Q,W]=d.useState({}),[U,H]=d.useState("catalog"),[Z,X]=d.useState(!1),[N,f]=d.useState(null),t=d.useRef(!1),u=d.useRef(null),{freeProvidersList:j,testingIds:F,isTestingAll:q,testConnection:G,testAll:Y}=mt(a);d.useEffect(()=>{if(a){t.current=!1,o(ft("free-fallback",x)),_([]),W({}),b(""),R("all"),A("all"),H("catalog"),f(null);const g=setTimeout(()=>{var w;return(w=u.current)==null?void 0:w.focus()},50);return()=>clearTimeout(g)}},[a]),d.useEffect(()=>{if(a&&!t.current&&j.length>0){t.current=!0;const g=[];for(const w of j)if(w.connectionStatus==="connected"&&w.freeModels.length>0)for(const M of w.freeModels.slice(0,3))g.includes(M.comboModelValue)||g.push(M.comboModelValue);g.length>0&&_(g)}},[a,j]);const O=d.useMemo(()=>new Set(D),[D]),ee=d.useMemo(()=>vt(j),[j]),K=d.useMemo(()=>p==="provider"?[]:gt(j,p,r),[j,p,r]),P=d.useMemo(()=>Nt({freeProvidersList:j,groups:K,groupMode:p,searchQuery:I,onlyConnected:S,onlyMultiProvider:v,modalityFilter:B,activeScopeId:E,selectedSet:O,capsMap:ee}),[j,K,p,I,S,v,B,E,O,ee]);d.useEffect(()=>{E!=="all"&&!I.trim()&&!P.railItems.some(g=>g.id===E)&&R("all")},[E,I,P.railItems]);const z=d.useMemo(()=>K.filter(g=>g.candidates.some(w=>O.has(w.model.comboModelValue))),[K,O]),Me=d.useMemo(()=>{let g=0;for(const w of P.visibleCandidates)O.has(w.comboModelValue)&&g++;return g},[P.visibleCandidates,O]),Se=d.useCallback(g=>{T(g),R("all"),g==="provider"&&k(!1)},[]),Ae=d.useCallback(g=>{_(w=>w.includes(g)?w.filter(M=>M!==g):[...w,g])},[]),Ee=d.useCallback(()=>{_(g=>{const w=new Set(g),M=[...g];for(const V of P.visibleCandidates)w.has(V.comboModelValue)||(w.add(V.comboModelValue),M.push(V.comboModelValue));return M})},[P.visibleCandidates]),Be=d.useCallback(()=>{const g=new Set(P.visibleCandidates.map(w=>w.comboModelValue));_(w=>w.filter(M=>!g.has(M)))},[P.visibleCandidates]),$e=d.useCallback(()=>{const g=[],w=new Set;for(const M of j)if(M.connectionStatus==="connected")for(const V of M.freeModels)w.has(V.comboModelValue)||(w.add(V.comboModelValue),g.push(V.comboModelValue));_(g)},[j]),le=d.useCallback(()=>_([]),[]),ie=d.useCallback(g=>{_(w=>w.filter(M=>M!==g))},[]),De=d.useCallback(g=>{g<=0||_(w=>{const M=[...w],V=M[g-1];return M[g-1]=M[g],M[g]=V,M})},[]),Te=d.useCallback(g=>{_(w=>{if(g>=w.length-1)return w;const M=[...w],V=M[g+1];return M[g+1]=M[g],M[g]=V,M})},[]),Le=d.useCallback(g=>{const{active:w,over:M}=g;M&&w.id!==M.id&&_(V=>{const de=V.indexOf(String(w.id)),me=V.indexOf(String(M.id));return de!==-1&&me!==-1?he(V,de,me):V})},[]),ce=d.useCallback((g,w)=>{W(M=>({...M,[g]:w}))},[]),Fe=async g=>{if(g.preventDefault(),D.length===0)return f("Please select at least one free model for this combo.");try{if(X(!0),f(null),!C||p==="provider"){const w=i.trim();if(!w)return f("Combo name is required.");if(!ke.test(w))return f("Name can only contain letters, numbers, -, _ and .");await n({name:w,models:D,strategy:l})}else{if(z.length===0)return f("Please select at least one model from any group.");const{error:w,combos:M}=yt(z,O,Q,x,l);if(w)return f(w);if(!M||M.length===0)return f("No valid combos to create.");if(m)await m(M);else for(const V of M)await n(V)}s()}catch(w){f(w instanceof Error?w.message:"Failed to create free tier combo.")}finally{X(!1)}},J=C&&p!=="provider",Ie=`${a?"1":"0"}|${p}|${E}|${I}|${S?"1":"0"}|${v?"1":"0"}|${B}`;return e.jsx(fe,{isOpen:a,onClose:s,maxWidthClass:"w-full max-w-[78rem]",overflowHidden:!0,children:e.jsxs("form",{onSubmit:Fe,className:"flex flex-col h-[88vh] max-h-[820px] -m-2 sm:-m-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-5 py-3.5 border-b border-[#1E293B] shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"size-9 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"savings"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2 truncate",children:[e.jsx("span",{children:"Create Free Tier Combo"}),e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-semibold bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 shrink-0",children:"Zero-Cost Gateway"})]}),e.jsx("p",{className:"text-xs text-slate-400 truncate",children:"Bundle verified free models across providers and set priority order on the right"})]})]}),e.jsx("button",{type:"button",onClick:s,className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-white/10 cursor-pointer shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsx(lt,{isMultiMode:J,onToggleMultiMode:k,canMultiMode:p!=="provider",comboName:i,onComboNameChange:g=>{o(g),N&&f(null)},namePrefix:r,onNamePrefixChange:h,strategy:l,onStrategyChange:c,activeGroupsCount:z.length}),e.jsx(at,{searchInputRef:u,searchQuery:y,onSearchChange:b,onlyConnected:S,onToggleOnlyConnected:()=>L(g=>!g),groupMode:p,onGroupModeChange:Se,onlyMultiProvider:v,onToggleOnlyMultiProvider:()=>$(g=>!g),modalityFilter:B,onModalityFilterChange:A,onSelectConnectedOnly:$e,onDeselectAll:le,onTestAll:()=>Y(j.map(g=>g.provider.id)),isTestingAll:q,mobileTab:U,onMobileTabChange:H,totalMatchingCount:P.totalMatchingCount,selectedCount:D.length,isMultiMode:J,activeGroupsCount:z.length}),e.jsxs("div",{className:"flex-1 min-h-0 grid grid-cols-1 lg:grid-cols-12 overflow-hidden lg:divide-x divide-[#1E293B]",children:[e.jsx(ve,{groupMode:p,railItems:P.railItems,activeScopeId:E,onSelectScope:R,totalMatchingCount:P.totalMatchingCount}),e.jsx(rt,{groupMode:p,railItems:P.railItems,activeScopeId:E,onSelectScope:R,visibleCandidates:P.visibleCandidates,totalMatchingCount:P.totalMatchingCount,activeProvider:P.activeProvider,activeGroup:P.activeGroup,selectedSet:O,selectedInViewCount:Me,testingIds:F,isMultiMode:J,groupComboName:P.activeGroup?Q[P.activeGroup.id]:void 0,onGroupComboNameChange:ce,onToggleModel:Ae,onAddAllVisible:Ee,onDeselectVisible:Be,onTestConnection:G,onlyConnected:S,onShowAllProviders:()=>L(!1),scrollKey:Ie,className:U==="catalog"?"flex":"hidden lg:flex"}),J?e.jsx(Ce,{activeGroups:z,selectedSet:O,groupComboNames:Q,onGroupComboNameChange:ce,onRemoveModel:ie,onClearAll:le,className:`lg:col-span-4 ${U==="selected"?"flex":"hidden lg:flex"}`}):e.jsx(Je,{selectedModels:D,capsMap:ee,onClearAll:le,onRemoveModel:ie,onMoveUp:De,onMoveDown:Te,onDragEnd:Le,className:`lg:col-span-4 ${U==="selected"?"flex":"hidden lg:flex"}`})]}),N&&e.jsxs("div",{className:"px-4 sm:px-5 py-2 bg-rose-500/10 border-t border-rose-500/20 text-rose-400 text-xs flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"error"}),e.jsx("span",{children:N})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 sm:px-5 py-3.5 border-t border-[#1E293B] bg-[#0A0D14]/60 shrink-0",children:[e.jsxs("div",{className:"text-xs text-slate-400",children:["Selected:"," ",e.jsx("strong",{className:"text-emerald-400 font-mono",children:D.length})," free model",D.length!==1?"s":"",J&&z.length>0&&e.jsxs("span",{className:"ml-2 text-slate-500",children:["(",z.length," combo",z.length!==1?"s":"",")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 rounded-xl bg-[#141B2D] border border-[#1E293B] hover:border-slate-700 text-xs font-medium text-slate-300 hover:text-white transition-colors cursor-pointer",children:"Cancel"}),e.jsxs("button",{type:"submit",disabled:Z||D.length===0,className:"px-5 py-2 rounded-xl bg-emerald-600 hover:bg-emerald-500 disabled:opacity-50 text-xs font-semibold text-white shadow-md shadow-emerald-600/20 flex items-center gap-1.5 transition-all cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:Z?"hourglass_empty":J&&z.length>1?"dynamic_feed":"check_circle"}),e.jsx("span",{children:J&&z.length>1?`Create ${z.length} Free Combos`:"Create Free Tier Combo"})]})]})]})]})})},Ct={vision:{enabled:!1,roundRobin:!1,models:[]},audioInput:{enabled:!1,roundRobin:!1,models:[]}},It=({onSelectCombo:a})=>{const[s,n]=d.useState([]),[m,x]=d.useState(!0),[i,o]=d.useState(Ct),[r,h]=d.useState(!1),[l,c]=d.useState(null),[p,T]=d.useState(""),C=d.useMemo(()=>{const t=p.trim().toLowerCase(),u=[...s].sort((j,F)=>j.name.localeCompare(F.name,void 0,{sensitivity:"base"}));return t?u.filter(j=>!!(j.name.toLowerCase().includes(t)||j.strategy.toLowerCase().includes(t)||j.models&&j.models.some(F=>F.toLowerCase().includes(t)))):u},[s,p]),[k,v]=d.useState(!1),[$,S]=d.useState(!1),[L,B]=d.useState(null),[A,y]=d.useState(null),[b,I]=d.useState(null),E=d.useCallback(async()=>{try{x(!0);const t=await fetch("/api/combos");if(t.ok){const u=await t.json();Array.isArray(u)&&n(u)}}catch(t){console.error("Failed to load combos:",t)}finally{x(!1)}},[]),R=d.useCallback(async()=>{try{const t=await fetch("/api/settings/capacity-adapter");if(t.ok){const u=await t.json();u&&typeof u=="object"&&o({vision:u.vision||{enabled:!1,roundRobin:!1,models:[]},audioInput:u.audioInput||{enabled:!1,roundRobin:!1,models:[]},pdf:u.pdf,videoInput:u.videoInput})}}catch(t){console.error("Failed to load capacity adapter settings:",t)}},[]);d.useEffect(()=>{E(),R()},[E,R]);const D=async t=>{o(t);try{h(!0),await fetch("/api/settings/capacity-adapter",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(u){console.error("Failed to save capacity adapter settings:",u)}finally{h(!1)}},_=t=>{const u=i[t];D({...i,[t]:{...u,enabled:!u.enabled}})},Q=(t,u)=>{const j=i[t];D({...i,[t]:{...j,roundRobin:u}})},W=(t,u)=>{const j=i[t];D({...i,[t]:{...j,models:j.models.filter(F=>F!==u)}})},U=t=>{if(!A)return;const u=i[A];D({...i,[A]:{...u,models:t}}),y(null)},H=async t=>{if(t.id){const u=await fetch(`/api/combos/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,models:t.models,strategy:t.strategy,isActive:t.isActive})});if(!u.ok){const j=await u.json();throw new Error(j.error||"Failed to update combo")}}else{const u=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,models:t.models,strategy:t.strategy})});if(!u.ok){const j=await u.json();throw new Error(j.error||"Failed to create combo")}}await E(),te(),v(!1),B(null)},Z=async t=>{try{const u=await fetch(`/api/combos/${t.id}/toggle`,{method:"POST"});if(u.ok){const j=await u.json();n(F=>F.map(q=>q.id===t.id?j:q)),te()}}catch(u){console.error("Error toggling combo status:",u)}},X=async(t,u)=>{try{const j=await fetch(`/api/combos/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({strategy:u})});if(j.ok){const F=await j.json();n(q=>q.map(G=>G.id===t.id?F:G)),te()}}catch(j){console.error("Error updating strategy:",j)}},N=t=>{I({title:"Delete Combo",message:`Are you sure you want to delete combo "${t.name}"? This action cannot be undone.`,confirmText:"Delete Combo",variant:"danger",onConfirm:async()=>{try{(await fetch(`/api/combos/${t.id}`,{method:"DELETE"})).ok&&(n(j=>j.filter(F=>F.id!==t.id)),te())}catch(u){console.error("Error deleting combo:",u)}finally{I(null)}}})},f=(t,u)=>{et(t),c(u),setTimeout(()=>c(null),2e3)};return e.jsxs("div",{className:"space-y-8 w-full pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"w-full p-5 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"hub"}),e.jsx("span",{className:"font-bold text-sm text-slate-100",children:"Smart Model Combos & Routing Strategies"})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>S(!0),className:"px-4 py-2 rounded-xl bg-emerald-600 hover:bg-emerald-500 shadow-lg shadow-emerald-600/20 text-xs font-semibold text-white flex items-center gap-1.5 transition-all cursor-pointer shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"savings"}),"Create Free Tier Combo"]}),e.jsxs("button",{type:"button",onClick:()=>{B(null),v(!0)},className:"px-4 py-2 rounded-xl bg-blue-600 hover:bg-blue-500 shadow-lg shadow-blue-600/20 text-xs font-semibold text-white flex items-center gap-1.5 transition-all cursor-pointer shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add_circle"}),"Create Combo"]})]})]}),e.jsx("p",{className:"text-xs text-slate-300 leading-relaxed",children:"Group multiple models and provider accounts under a single unified alias. Mapigate automatically manages fallbacks, load balances requests, or fuses multiple outputs together."}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 xl:grid-cols-5 gap-2.5 pt-1 text-[11px]",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-blue-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"low_priority"}),"Fallback Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Tries models in order; moves to backup on 429, 503, or quota limits."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-cyan-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"sync"}),"Round Robin Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Spreads requests sequentially across accounts to maximize throughput."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-indigo-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"call_split"}),"Fusion Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Queries models in parallel and synthesizes the best answer with a judge."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-emerald-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"verified"}),"LKGP Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Sticks to last known good model for prompt cache warmth; fails over on error."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-amber-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"balance"}),"P2C Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Samples 2 random models and picks the higher-scoring via EMA latency/error rate."})]})]})]}),e.jsxs("div",{className:"w-full space-y-3.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 px-1 text-xs text-slate-400",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"layers"}),e.jsxs("span",{className:"font-bold text-white text-sm",children:["Configured Combos (",p?`${C.length} of ${s.length}`:s.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-slate-500 text-[16px]",children:"search"}),e.jsx("input",{type:"text",value:p,onChange:t=>T(t.target.value),placeholder:"Filter combos by name or model...",className:"pl-8 pr-7 py-1 text-xs bg-[#0F1420] border border-[#1E293B] rounded-xl text-white placeholder-slate-500 focus:outline-none focus:border-blue-500/50 w-52 sm:w-64 transition-all"}),p&&e.jsx("button",{type:"button",onClick:()=>T(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white text-xs",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("span",{className:"text-[11px] text-slate-500 hidden sm:inline",children:"Backed by SQLite"})]})]}),m?e.jsxs("div",{className:"w-full py-16 text-center text-slate-400 flex flex-col items-center justify-center gap-3 bg-[#0F1420]/40 rounded-2xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{className:"text-xs",children:"Loading combos from database..."})]}):s.length===0?e.jsxs("div",{className:"w-full py-16 text-center text-slate-400 flex flex-col items-center justify-center gap-3 bg-[#0F1420]/40 rounded-2xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-slate-600",children:"layers_clear"}),e.jsx("p",{className:"text-sm font-semibold text-slate-300",children:"No combos configured in SQLite database yet"}),e.jsx("p",{className:"text-xs text-slate-500 max-w-md",children:"Click “Create Combo” to build your first multi-model cluster (e.g. combo/smart-coding). Tool-specific model aliases (sonnet, default...) are configured in the CLI Tools tab."})]}):C.length===0?e.jsxs("div",{className:"w-full py-12 text-center text-slate-400 flex flex-col items-center justify-center gap-2 bg-[#0F1420]/40 rounded-2xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-slate-600",children:"search_off"}),e.jsxs("p",{className:"text-xs font-semibold text-slate-300",children:["No combos match “",p,"”"]}),e.jsx("button",{onClick:()=>T(""),className:"text-xs text-blue-400 hover:underline cursor-pointer",children:"Clear filter"})]}):e.jsx("div",{className:"w-full space-y-2.5",children:C.map((t,u)=>{const j=We(t.models),F=t.isActive!==!1;return e.jsxs("div",{className:`w-full flex flex-wrap items-center justify-between gap-4 py-3.5 px-5 rounded-2xl border transition-all ${F?"bg-[#0F1420]/80 border-[#1E293B] hover:border-slate-700":"bg-[#0A0D14]/50 border-[#1E293B]/50 opacity-60"}`,style:{animationDelay:`${u*30}ms`},children:[e.jsxs("div",{className:"flex items-start sm:items-center gap-3.5 min-w-0 flex-1",children:[e.jsx("div",{className:`size-9 rounded-xl flex items-center justify-center shrink-0 border ${t.strategy==="fallback"?"bg-blue-500/10 text-blue-400 border-blue-500/20":t.strategy==="round-robin"?"bg-cyan-500/10 text-cyan-400 border-cyan-500/20":t.strategy==="fusion"?"bg-indigo-500/10 text-indigo-400 border-indigo-500/20":t.strategy==="lkgp"?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-amber-500/10 text-amber-400 border-amber-500/20"}`,children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:t.strategy==="fallback"?"low_priority":t.strategy==="round-robin"?"sync":t.strategy==="fusion"?"call_split":t.strategy==="lkgp"?"verified":"balance"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>a?a(t):(B(t),v(!0)),className:"text-xs font-bold text-white font-mono hover:text-blue-400 cursor-pointer transition-colors text-left",title:"Open combo details & manage models",children:t.name}),j&&e.jsx(re,{caps:j,size:"xs"}),(()=>{const q=new Set(t.models.map(G=>G.split("/")[0].replace(/\(.*?\)/,"").trim())).size;return e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[#161F30] border border-[#26354D] text-[10px] text-slate-400 font-medium",children:[t.models.length," ",t.models.length===1?"model":"models",q>0&&` · ${q} ${q===1?"provider":"providers"}`]})})(),!F&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-slate-800 text-slate-400 text-[10px] uppercase font-bold",children:"Disabled"})]}),(()=>{const G=p.trim().toLowerCase(),Y=G?t.models.filter(K=>K.toLowerCase().includes(G)):[],O=G&&Y.length>0?Y.slice(0,4):t.models.slice(0,4),ee=t.models.length-O.length;return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-1.5",children:[O.map((K,P)=>{const z=t.models.indexOf(K);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-lg bg-[#0A0D14] border border-[#1E293B] text-[11px] text-slate-300 font-mono",children:[e.jsx("span",{className:"text-[10px] text-blue-400 font-bold",children:z+1}),e.jsx("span",{className:"truncate max-w-[220px] sm:max-w-none",children:K})]},P)}),ee>0&&e.jsxs("button",{type:"button",onClick:K=>{K.stopPropagation(),a?a(t):(B(t),v(!0))},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-lg bg-blue-500/10 hover:bg-blue-500/20 text-[11px] text-blue-400 font-semibold border border-blue-500/25 transition-colors cursor-pointer",title:`Click to view and manage all ${t.models.length} models`,children:[e.jsxs("span",{children:["+",ee," more"]}),e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"arrow_forward"})]})]})})()]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsx(se,{value:t.strategy,onChange:q=>X(t,q),options:[{value:"round-robin",label:"Round Robin (rotate)"},{value:"fallback",label:"Fallback (try in order)"},{value:"fusion",label:"Fusion (parallel panel)"},{value:"lkgp",label:"LKGP (Last Known Good)"},{value:"p2c",label:"P2C (Power of Two Choices)"}],className:"min-w-[180px]"}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",title:F?"Disable combo":"Enable combo",children:[e.jsx("input",{type:"checkbox",checked:F,onChange:()=>Z(t),className:"sr-only peer"}),e.jsx("div",{className:"w-9 h-5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-blue-600"})]}),e.jsxs("div",{className:"flex items-center gap-1 text-slate-400 border-l border-[#1E293B] pl-2",children:[e.jsx("button",{type:"button",title:"Manage models & details",onClick:()=>{a?a(t):(B(t),v(!0))},className:"p-1.5 rounded-lg hover:bg-blue-500/10 hover:text-blue-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"tune"})}),e.jsx("button",{type:"button",title:l===t.id?"Copied to clipboard!":"Copy combo identifier",onClick:()=>f(t.name,t.id),className:`p-1.5 rounded-lg transition-colors cursor-pointer ${l===t.id?"bg-emerald-500/20 text-emerald-400":"hover:bg-white/10 hover:text-white"}`,children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:l===t.id?"check":"content_copy"})}),e.jsx("button",{type:"button",title:"Edit combo",onClick:()=>{B(t),v(!0)},className:"p-1.5 rounded-lg hover:bg-white/10 hover:text-white transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"edit"})}),e.jsx("button",{type:"button",title:"Delete combo",onClick:()=>N(t),className:"p-1.5 rounded-lg hover:bg-rose-500/10 hover:text-rose-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})]})]})]},t.id)})})]}),e.jsxs("div",{className:"w-full space-y-4 pt-6 border-t border-[#1E293B]",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-cyan-400 text-[20px]",children:"visibility"}),"Multimodal Capacity Adapter"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"When client coding tools send image or audio prompts to models lacking those modalities, Mapigate seamlessly elevates designated adapter models to priority #1."})]}),r&&e.jsxs("span",{className:"text-[11px] text-blue-400 flex items-center gap-1 font-mono",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin",children:"progress_activity"}),"Syncing settings..."]})]}),e.jsxs("div",{className:"w-full grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"w-full p-5 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] flex flex-col justify-between gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-9 rounded-xl bg-cyan-500/10 border border-cyan-500/20 text-cyan-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"image"})}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-bold text-white flex items-center gap-2",children:["Vision Input Adapter",e.jsx("span",{className:"px-1.5 py-0.2 rounded text-[10px] bg-cyan-500/10 text-cyan-400 border border-cyan-500/20",children:"Images & Screenshots"})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Auto-reroutes image payloads (png, jpg, webp, base64)"})]})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:i.vision.enabled,onChange:()=>_("vision"),className:"sr-only peer"}),e.jsx("div",{className:"w-10 h-5.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4.5 after:w-4.5 after:transition-all peer-checked:bg-cyan-600"})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs pt-1",children:[e.jsx("span",{className:"text-slate-400",children:"Adapter Pool Strategy:"}),e.jsx(se,{value:i.vision.roundRobin?"round-robin":"fallback",onChange:t=>Q("vision",t==="round-robin"),options:[{value:"fallback",label:"Fallback (try in order)"},{value:"round-robin",label:"Round Robin (rotate)"}],className:"min-w-[170px]"})]})]}),e.jsxs("div",{className:"space-y-2 pt-2 border-t border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsxs("span",{className:"text-slate-400 font-semibold",children:["Vision Model Pool (",i.vision.models.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>y("vision"),className:"px-2.5 py-1 rounded-lg bg-cyan-600/10 border border-cyan-500/30 text-cyan-400 hover:bg-cyan-600/20 font-medium flex items-center gap-1 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),"Manage Models"]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 min-h-[38px] p-2 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:i.vision.models.length===0?e.jsx("span",{className:"text-[11px] text-slate-500 italic",children:"No models in vision pool. Click Manage Models to add."}):i.vision.models.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-lg bg-[#141B2D] border border-cyan-500/20 text-[11px] text-cyan-300 font-mono",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-cyan-400"}),e.jsx("span",{children:t}),e.jsx("button",{type:"button",onClick:()=>W("vision",t),className:"text-slate-500 hover:text-rose-400 cursor-pointer ml-0.5",title:"Remove model from pool",children:e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"close"})})]},t))})]})]}),e.jsxs("div",{className:"w-full p-5 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] flex flex-col justify-between gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-9 rounded-xl bg-purple-500/10 border border-purple-500/20 text-purple-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"graphic_eq"})}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-bold text-white flex items-center gap-2",children:["Audio Input Adapter",e.jsx("span",{className:"px-1.5 py-0.2 rounded text-[10px] bg-purple-500/10 text-purple-400 border border-purple-500/20",children:"Speech & Voice"})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Auto-reroutes speech and audio inputs to audio-capable models"})]})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:i.audioInput.enabled,onChange:()=>_("audioInput"),className:"sr-only peer"}),e.jsx("div",{className:"w-10 h-5.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4.5 after:w-4.5 after:transition-all peer-checked:bg-purple-600"})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs pt-1",children:[e.jsx("span",{className:"text-slate-400",children:"Adapter Pool Strategy:"}),e.jsx(se,{value:i.audioInput.roundRobin?"round-robin":"fallback",onChange:t=>Q("audioInput",t==="round-robin"),options:[{value:"fallback",label:"Fallback (try in order)"},{value:"round-robin",label:"Round Robin (rotate)"}],className:"min-w-[170px]"})]})]}),e.jsxs("div",{className:"space-y-2 pt-2 border-t border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsxs("span",{className:"text-slate-400 font-semibold",children:["Audio Model Pool (",i.audioInput.models.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>y("audioInput"),className:"px-2.5 py-1 rounded-lg bg-purple-600/10 border border-purple-500/30 text-purple-400 hover:bg-purple-600/20 font-medium flex items-center gap-1 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),"Manage Models"]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 min-h-[38px] p-2 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:i.audioInput.models.length===0?e.jsx("span",{className:"text-[11px] text-slate-500 italic",children:"No models in audio pool. Click Manage Models to add."}):i.audioInput.models.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-lg bg-[#141B2D] border border-purple-500/20 text-[11px] text-purple-300 font-mono",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-purple-400"}),e.jsx("span",{children:t}),e.jsx("button",{type:"button",onClick:()=>W("audioInput",t),className:"text-slate-500 hover:text-rose-400 cursor-pointer ml-0.5",title:"Remove model from pool",children:e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"close"})})]},t))})]})]})]})]}),e.jsx(st,{isOpen:k,onClose:()=>{v(!1),B(null)},combo:L,onSave:H}),e.jsx(wt,{isOpen:$,onClose:()=>S(!1),onSave:async t=>{await H({...t,isActive:!0})},onSaveBatch:async t=>{for(const u of t){const j=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:u.name,models:u.models,strategy:u.strategy})});if(!j.ok){const F=await j.json();throw new Error(F.error||`Failed to create combo ${u.name}`)}}await E(),te()},existingComboNames:s.map(t=>t.name)}),A&&e.jsx(ye,{isOpen:A!==null,onClose:()=>y(null),title:`Configure ${A==="vision"?"Vision":"Audio"} Adapter Model Pool`,initialSelectedModels:i[A].models,onConfirm:U,filterModality:A==="vision"?"vision":"audio",multiSelect:!0}),b&&e.jsx(Ye,{isOpen:b!==null,title:b.title,message:b.message,confirmText:b.confirmText||"Confirm",variant:b.variant||"primary",onConfirm:b.onConfirm,onCancel:()=>I(null)})]})};export{It as CombosTab};
@@ -1 +1 @@
1
- import{j as e}from"./vendor-BcOI2aZ9.js";import{P as m}from"./index-Di7mCTbW.js";const h=({isOpen:r,title:s,message:o,confirmText:a="Confirm",cancelText:n="Cancel",confirmVariant:l="primary",variant:i,onConfirm:d,onCancel:t})=>{const x=i||l,c=()=>{switch(x){case"danger":return"bg-red-600 hover:bg-red-500 text-white";case"emerald":return"bg-emerald-600 hover:bg-emerald-500 text-white";default:return"bg-blue-600 hover:bg-blue-500 text-white"}};return e.jsx(m,{isOpen:r,onClose:t,maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold text-slate-100",children:s}),e.jsx("p",{className:"text-sm text-slate-300 leading-relaxed",children:o}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:n}),e.jsx("button",{type:"button",onClick:d,className:`px-4 py-2 text-xs font-medium rounded-xl transition-colors cursor-pointer ${c()}`,children:a})]})]})})};export{h as C};
1
+ import{j as e}from"./vendor-BcOI2aZ9.js";import{P as m}from"./index-vFoRSZw0.js";const h=({isOpen:r,title:s,message:o,confirmText:a="Confirm",cancelText:n="Cancel",confirmVariant:l="primary",variant:i,onConfirm:d,onCancel:t})=>{const x=i||l,c=()=>{switch(x){case"danger":return"bg-red-600 hover:bg-red-500 text-white";case"emerald":return"bg-emerald-600 hover:bg-emerald-500 text-white";default:return"bg-blue-600 hover:bg-blue-500 text-white"}};return e.jsx(m,{isOpen:r,onClose:t,maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold text-slate-100",children:s}),e.jsx("p",{className:"text-sm text-slate-300 leading-relaxed",children:o}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:n}),e.jsx("button",{type:"button",onClick:d,className:`px-4 py-2 text-xs font-medium rounded-xl transition-colors cursor-pointer ${c()}`,children:a})]})]})})};export{h as C};
@@ -0,0 +1,6 @@
1
+ import{r as c,j as e}from"./vendor-BcOI2aZ9.js";import{S as V}from"./Select-BNRH8LIG.js";import{L as Q,i as ee,t as ge,P as je,f as X,g as le,u as Ne,R as ve,l as ye,X as ce,h as de,Z as ie,k as we,W as te,C as xe,D as Ce,A as Ee,a as Te,v as Se,S as ke,e as Ae,w as ze,x as Le}from"./lucide-Cc35htxl.js";import{T as pe}from"./ToolIcon-BZE0Fv7L.js";import{u as me,D as ue,c as be,b as Be,A as Re}from"./index-vFoRSZw0.js";import{P as Oe}from"./PortalDrawer-Bv31mboq.js";import{c as he}from"./clipboard-CLQF8jeK.js";const Me=[{value:"trace",label:"TRACE (Max)",icon:e.jsx("span",{className:"size-2 rounded-full bg-purple-400 shadow-[0_0_6px_#c084fc]"})},{value:"debug",label:"DEBUG",icon:e.jsx("span",{className:"size-2 rounded-full bg-sky-400 shadow-[0_0_6px_#38bdf8]"})},{value:"info",label:"INFO (Default)",icon:e.jsx("span",{className:"size-2 rounded-full bg-emerald-400 shadow-[0_0_6px_#34d399]"})},{value:"warn",label:"WARN",icon:e.jsx("span",{className:"size-2 rounded-full bg-amber-400 shadow-[0_0_6px_#facc15]"})},{value:"error",label:"ERROR",icon:e.jsx("span",{className:"size-2 rounded-full bg-red-400 shadow-[0_0_6px_#f87171]"})}],$e=[{value:"errors_only",label:"Trace: Errors Only",icon:e.jsx("span",{className:"size-2 rounded-full bg-amber-400 shadow-[0_0_6px_#facc15]"})},{value:"all",label:"Trace: All Requests",icon:e.jsx("span",{className:"size-2 rounded-full bg-emerald-400 shadow-[0_0_6px_#34d399]"})},{value:"off",label:"Trace: Disabled (Off)",icon:e.jsx("span",{className:"size-2 rounded-full bg-slate-500"})}],Ie=({connected:l,totalCount:o,filteredCount:n,viewMode:s,onViewModeChange:N,categoryTab:f,onCategoryTabChange:u,searchQuery:b,onSearchQueryChange:p,clientToolFilter:v,onClientToolFilterChange:i,providerFilter:g,onProviderFilterChange:a,statusFilter:y,onStatusFilterChange:j,levelFilter:w,onLevelFilterChange:t,gatewayLogLevel:T,onGatewayLogLevelChange:C,observabilityMode:B,onObservabilityModeChange:S,autoScroll:k,onAutoScrollToggle:P,onCopy:R,copied:E,onClear:D,availableTools:q,availableProviders:F})=>{const A=c.useMemo(()=>[{value:"all",label:"Tool: All"},...q.map(m=>({value:m,label:`Tool: ${m}`}))],[q]),U=c.useMemo(()=>[{value:"all",label:"Provider: All"},...F.map(m=>({value:m,label:`Provider: ${m}`}))],[F]),G=c.useMemo(()=>[{value:"all",label:"Status: All"},{value:"200",label:"200 OK",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"})},{value:"429",label:"429 Rate Limit",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-amber-400"})},{value:"error",label:"5xx / Errors",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-red-400"})}],[]),J=c.useMemo(()=>[{value:"all",label:"Level: All"},{value:"trace",label:"Trace only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-purple-400"})},{value:"debug",label:"Debug only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-sky-400"})},{value:"info",label:"Info only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"})},{value:"warn",label:"Warn only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-amber-400"})},{value:"error",label:"Error only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-red-400"})}],[]),O=v!=="all"||g!=="all"||y!=="all"||w!=="all"||b.trim()!=="",H=()=>{i("all"),a("all"),j("all"),t("all"),p("")};return e.jsxs("div",{className:"space-y-2.5 shrink-0",children:[e.jsxs("div",{className:"rt-card px-4 py-2.5 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1 rounded-lg bg-[#0A0D14] border border-[#1E293B]",children:[e.jsx("span",{className:`size-2 rounded-full ${l?"bg-emerald-400 shadow-[0_0_8px_#34d399]":"bg-red-500 animate-pulse"}`}),e.jsx("span",{className:"text-xs font-semibold text-slate-300",children:l?"Live Stream":"Disconnected"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-[#0A0D14] border border-[#1E293B] text-xs font-mono text-slate-400",children:[e.jsx("span",{className:"text-slate-200 font-semibold",children:n}),n!==o&&e.jsxs("span",{className:"text-slate-500",children:["/ ",o]}),e.jsx("span",{children:"logs"})]}),e.jsxs("div",{className:"flex items-center bg-[#0A0D14] p-0.5 rounded-lg border border-[#1E293B]",children:[e.jsxs("button",{type:"button",onClick:()=>N("structured"),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-semibold transition-colors cursor-pointer ${s==="structured"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(Q,{className:"size-3.5"}),e.jsx("span",{children:"AI Transactions"})]}),e.jsxs("button",{type:"button",onClick:()=>N("raw"),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-semibold transition-colors cursor-pointer ${s==="raw"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(ee,{className:"size-3.5"}),e.jsx("span",{children:"Raw Terminal"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-slate-400 shrink-0",children:"Log Level:"}),e.jsx(V,{value:T,onChange:C,options:Me,size:"sm",className:"min-w-[140px]",triggerClassName:"h-8 !py-1 !px-2.5 text-xs font-semibold rounded-lg bg-[#0A0D14] border-[#1E293B] hover:border-slate-700",menuClassName:"min-w-[145px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx(V,{value:B,onChange:m=>S(m),options:$e,size:"sm",className:"min-w-[170px]",triggerClassName:"h-8 !py-1 !px-2.5 text-xs font-semibold rounded-lg bg-[#0A0D14] border-[#1E293B] hover:border-slate-700",menuClassName:"min-w-[180px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{type:"button",onClick:P,className:`px-2.5 py-1 rounded-lg text-xs font-semibold border flex items-center gap-1.5 transition-colors cursor-pointer ${k?"bg-blue-500/10 text-blue-400 border-blue-500/30 hover:bg-blue-500/20":"bg-slate-800/40 text-slate-400 border-slate-700/60 hover:text-slate-200"}`,title:k?"Pause auto-scrolling":"Enable auto-scrolling",children:[k?e.jsx(ge,{className:"size-3.5"}):e.jsx(je,{className:"size-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:k?"Auto-scroll ON":"Paused"})]}),e.jsxs("button",{type:"button",onClick:R,disabled:n===0,className:"px-2.5 py-1 rounded-lg text-xs font-semibold bg-[#0A0D14] border border-[#1E293B] text-slate-300 hover:text-white hover:border-slate-600 disabled:opacity-40 disabled:cursor-not-allowed flex items-center gap-1.5 transition-colors cursor-pointer",title:"Copy logs",children:[E?e.jsx(X,{className:"size-3.5 text-emerald-400"}):e.jsx(le,{className:"size-3.5"}),e.jsx("span",{children:E?"Copied!":"Copy"})]}),e.jsxs("button",{type:"button",onClick:D,disabled:o===0,className:"px-2.5 py-1 rounded-lg text-xs font-semibold bg-red-500/10 border border-red-500/20 text-red-400 hover:bg-red-500/20 hover:border-red-500/40 disabled:opacity-40 disabled:cursor-not-allowed flex items-center gap-1.5 transition-colors cursor-pointer",title:"Clear all logs",children:[e.jsx(Ne,{className:"size-3.5"}),e.jsx("span",{children:"Clear"})]})]})]}),e.jsxs("div",{className:"rt-card px-4 py-2.5 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex items-center gap-1 overflow-x-auto pb-1 sm:pb-0",children:[{id:"all",label:"All Logs"},{id:"proxy",label:"AI Requests"},{id:"stream",label:"Stream & Tools"},{id:"errors",label:"Errors & Warns"},{id:"system",label:"System & MITM"}].map(m=>e.jsx("button",{type:"button",onClick:()=>u(m.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-all cursor-pointer whitespace-nowrap ${f===m.id?"bg-blue-600/15 text-blue-400 font-semibold border border-blue-500/30 shadow-xs":"text-slate-400 hover:text-slate-200 hover:bg-white/[0.04] border border-transparent"}`,children:m.label},m.id))}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap flex-1 justify-end min-w-[280px]",children:[e.jsx(V,{value:v,onChange:i,options:A,size:"sm",className:"min-w-[115px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${v!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"min-w-[130px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),e.jsx(V,{value:g,onChange:a,options:U,size:"sm",className:"min-w-[125px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${g!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"min-w-[140px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),e.jsx(V,{value:y,onChange:j,options:G,size:"sm",className:"min-w-[115px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${y!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"min-w-[130px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),e.jsx(V,{value:w,onChange:t,options:J,size:"sm",className:"min-w-[115px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${w!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"right-0 left-auto min-w-[130px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),O&&e.jsxs("button",{type:"button",onClick:H,className:"h-8 px-2 py-1 rounded-lg text-xs font-semibold text-slate-400 hover:text-white hover:bg-slate-800/50 border border-transparent hover:border-slate-700 flex items-center gap-1 transition-colors cursor-pointer",title:"Reset all filters to default",children:[e.jsx(ve,{className:"size-3"}),e.jsx("span",{className:"hidden xl:inline",children:"Reset"})]}),e.jsxs("div",{className:"relative w-44 sm:w-52",children:[e.jsx(ye,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 size-3.5 text-slate-500"}),e.jsx("input",{type:"text",placeholder:"Search in logs...",value:b,onChange:m=>p(m.target.value),className:"h-8 w-full bg-[#0A0D14] border border-[#1E293B] rounded-lg pl-8 pr-7 text-xs text-white placeholder-slate-500 font-mono focus:outline-hidden focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-all"}),b&&e.jsx("button",{type:"button",onClick:()=>p(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 hover:text-white cursor-pointer",children:e.jsx(ce,{className:"size-3"})})]})]})]})]})};function _e(l){const o=new Date(l),n=s=>String(s).padStart(2,"0");return`${n(o.getHours())}:${n(o.getMinutes())}:${n(o.getSeconds())}`}const Pe=({entry:l,onClick:o,isSelected:n=!1})=>{const{gateway:s,level:N,category:f,message:u,reqTag:b,timestamp:p,error:v}=l,i=(s==null?void 0:s.statusCode)||(v==null?void 0:v.status),g=i&&i>=200&&i<300,a=i===429,y=N==="error"||i&&i>=400&&!a,j=()=>a?e.jsx("span",{className:"px-2 py-0.5 rounded text-[11px] font-bold bg-amber-500/15 text-amber-400 border border-amber-500/30",children:"429"}):y?e.jsx("span",{className:"px-2 py-0.5 rounded text-[11px] font-bold bg-red-500/15 text-red-400 border border-red-500/30",children:i||"ERR"}):g?e.jsxs("span",{className:"px-2 py-0.5 rounded text-[11px] font-bold bg-emerald-500/15 text-emerald-400 border border-emerald-500/30",children:[i," OK"]}):null,w=()=>{switch(f){case"proxy":return"bg-blue-500/10 text-blue-400 border-blue-500/30";case"router":return"bg-purple-500/10 text-purple-400 border-purple-500/30";case"rtk":return"bg-emerald-500/10 text-emerald-400 border-emerald-500/30";case"mitm":return"bg-cyan-500/10 text-cyan-400 border-cyan-500/30";case"scheduler":return"bg-slate-700/30 text-slate-400 border-slate-700/50";default:return"bg-slate-800/40 text-slate-400 border-slate-700/60"}};return e.jsxs("div",{onClick:o,className:`group px-3.5 py-2.5 rounded-xl border transition-all cursor-pointer select-text ${n?"bg-[#131B2E] border-blue-500 shadow-md ring-1 ring-blue-500/20":"bg-[#0A0E18] hover:bg-[#0E1524] border-[#1E293B] hover:border-slate-700"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[e.jsx("span",{className:"text-[11px] font-mono text-slate-500 shrink-0",children:_e(p)}),b&&e.jsx("span",{className:"text-xs shrink-0 select-none",children:b}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-semibold uppercase tracking-wider border shrink-0 ${w()}`,children:f}),N==="trace"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono font-bold bg-purple-500/15 text-purple-400 border border-purple-500/30",children:"TRACE"}),N==="debug"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono font-bold bg-sky-500/15 text-sky-400 border border-sky-500/30",children:"DEBUG"}),j(),(s==null?void 0:s.clientTool)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-[#05070B] border border-[#1E293B]",children:[e.jsx(pe,{name:s.clientTool,size:"sm",className:"size-4"}),e.jsx("span",{className:"text-xs font-semibold text-slate-300",children:s.clientTool})]}),((s==null?void 0:s.actualModel)||(s==null?void 0:s.requestedModel))&&e.jsxs("div",{className:"flex items-center gap-1 text-xs font-mono text-slate-300 truncate",children:[s.providerId&&e.jsxs("span",{className:"text-slate-500",children:[s.providerId,"/"]}),e.jsx("span",{className:"font-medium text-blue-300",children:s.actualModel||s.requestedModel})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 ml-auto",children:[(s==null?void 0:s.durationMs)!==void 0&&e.jsxs("div",{className:"flex items-center gap-1 px-2 py-0.5 rounded-md bg-slate-900 border border-slate-800 text-[11px] font-mono text-slate-400",children:[e.jsx(de,{className:"size-3 text-slate-500"}),e.jsxs("span",{children:[s.durationMs,"ms"]}),s.ttftMs!==void 0&&s.ttftMs>0&&e.jsxs("span",{className:"text-slate-500",children:["· TTFT ",s.ttftMs,"ms"]})]}),(s==null?void 0:s.tokens)&&e.jsxs("div",{className:"hidden sm:flex items-center gap-1 text-[11px] font-mono",children:[e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:["IN ",s.tokens.prompt.toLocaleString(),s.tokens.cached?` (↻${s.tokens.cached.toLocaleString()})`:""]}),e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:["OUT ",s.tokens.completion.toLocaleString()]}),s.tokens.savedByRtk?e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20 flex items-center gap-0.5",children:[e.jsx(ie,{className:"size-2.5"}),e.jsxs("span",{children:["-",s.tokens.savedByRtk.toLocaleString()]})]}):null]}),(s==null?void 0:s.cost)!==void 0&&s.cost>0&&e.jsxs("span",{className:"hidden md:inline px-1.5 py-0.5 rounded bg-slate-800 border border-slate-700 text-[11px] font-mono text-slate-300 font-semibold",children:["$",s.cost<.01?s.cost.toFixed(4):s.cost.toFixed(3)]}),e.jsx(we,{className:"size-4 text-slate-600 group-hover:text-slate-400 transition-colors"})]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-mono text-slate-400 truncate flex-1",children:u}),(s==null?void 0:s.tools)&&s.tools.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0 overflow-hidden",children:[s.tools.slice(0,3).map((t,T)=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-mono bg-purple-500/15 text-purple-300 border border-purple-500/30",children:[e.jsx(te,{className:"size-2.5"}),e.jsx("span",{className:"truncate max-w-[120px]",children:t.name})]},T)),s.tools.length>3&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["+",s.tools.length-3]})]})]})]})};function De(l){const o=l.toUpperCase();return o.includes("[ERROR]")||o.includes("ERROR:")||o.includes("EXCEPTION")||l.includes("Error:")||l.includes("ERR!")||l.toLowerCase().includes("failed")||l.includes("💥")||l.includes("❌")?"text-red-400":o.includes("[WARN]")||o.includes("WARN:")||o.includes("WARNING:")||l.includes("⚠️")?"text-amber-400":o.includes("[INFO]")||o.includes("INFO:")||l.includes("ℹ️")?"text-blue-400":o.includes("[LOG]")||l.includes("🚀")||l.includes("📡")||l.includes("▶")||l.includes("✔")||l.includes("Gateway running")||l.includes("📊")?"text-emerald-400":o.includes("[DEBUG]")||l.includes("🔍")?"text-purple-400":"text-slate-300"}const Fe=({logs:l,filterText:o,scrollRef:n})=>{const s=me(u=>u.info),N=(s==null?void 0:s.port)||ue,f=(s==null?void 0:s.host)||be;return e.jsxs("div",{className:"flex-1 flex flex-col rounded-xl border border-[#1E293B] bg-[#05070B] overflow-hidden shadow-2xl min-h-0",children:[e.jsxs("div",{className:"bg-[#0A0D14] px-4 py-2 border-b border-[#1E293B] flex items-center justify-between shrink-0 select-none",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"size-3 rounded-full bg-[#EF4444]/80 inline-block"}),e.jsx("span",{className:"size-3 rounded-full bg-[#F59E0B]/80 inline-block"}),e.jsx("span",{className:"size-3 rounded-full bg-[#10B981]/80 inline-block"}),e.jsx("span",{className:"ml-2 text-[11px] font-mono text-slate-400",children:"mapigate-gateway > stdout / stderr"})]}),e.jsx("div",{className:"text-[10px] font-mono text-slate-500",children:"UTF-8 · Local Gateway"})]}),e.jsx("div",{ref:n,className:"flex-1 p-4 font-mono text-xs overflow-y-auto space-y-0.5 select-text",children:l.length===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-slate-500 py-16 space-y-2 select-none",children:[e.jsx(ee,{className:"size-8 text-slate-600"}),e.jsx("p",{className:"text-xs",children:o.trim()?`No logs match "${o}"`:"No console logs yet. Gateway logs will stream here in real time."}),e.jsxs("span",{className:"text-[10px] text-slate-600 font-mono",children:["Listening on http://",f,":",N,"/api/console-logs/stream"]})]}):l.map((u,b)=>{const p=De(u);return e.jsxs("div",{className:`py-0.5 px-1.5 rounded flex items-start gap-2.5 hover:bg-white/[0.03] transition-colors leading-relaxed ${p}`,children:[e.jsx("span",{className:"text-slate-600 select-none text-[10px] w-9 text-right shrink-0 pt-0.5 font-mono",children:b+1}),e.jsx("span",{className:"break-all whitespace-pre-wrap flex-1",children:u})]},b)})})]})},Ue=({tokens:l})=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(xe,{className:"size-3.5 text-blue-400"})," Token Economics"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Prompt Tokens"}),e.jsx("p",{className:"text-sm font-bold font-mono text-blue-400",children:l.prompt.toLocaleString()})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Cached Tokens (↻)"}),e.jsx("p",{className:"text-sm font-bold font-mono text-cyan-400",children:(l.cached||0).toLocaleString()})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Output Tokens"}),e.jsx("p",{className:"text-sm font-bold font-mono text-emerald-400",children:l.completion.toLocaleString()})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Tokens Saved"}),e.jsxs("p",{className:"text-sm font-bold font-mono text-amber-400 flex items-center gap-1",children:[e.jsx(ie,{className:"size-3"}),(l.savedByRtk||0).toLocaleString()]})]})]})]}),Je=({tools:l})=>!l||l.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(te,{className:"size-3.5 text-purple-400"})," Tool Calls (",l.length,")"]}),e.jsx("div",{className:"space-y-2",children:l.map((o,n)=>e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B] flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"p-1 rounded bg-purple-500/20 text-purple-300",children:e.jsx(te,{className:"size-3.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold text-white font-mono truncate",children:o.name}),e.jsx("p",{className:"text-[11px] text-slate-400 font-mono truncate",children:o.summary})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-semibold bg-slate-800 text-slate-300 uppercase",children:o.type})]},n))})]}),qe=({detail:l,loading:o=!1})=>{var y,j,w,t,T,C,B,S,k;const[n,s]=c.useState("client"),[N,f]=c.useState(null),u=(P,R)=>{navigator.clipboard.writeText(P),f(R),setTimeout(()=>f(null),2e3)};if(o)return e.jsxs("div",{className:"p-6 rounded-xl bg-[#0A0E18] border border-[#1E293B] flex items-center justify-center gap-3 text-slate-400",children:[e.jsx("span",{className:"size-4 border-2 border-blue-400 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"text-xs font-mono",children:"Loading full payload observability trace..."})]});if(!l)return e.jsxs("div",{className:"p-5 rounded-xl bg-[#0A0E18] border border-[#1E293B] space-y-2 text-center select-none",children:[e.jsx(Ce,{className:"size-6 text-slate-500 mx-auto"}),e.jsx("p",{className:"text-xs font-semibold text-slate-300",children:"No payload trace snapshot found for this request"}),e.jsxs("p",{className:"text-[11px] text-slate-500 max-w-md mx-auto",children:["Observability trace is either set to ",e.jsx("strong",{className:"text-amber-400 font-mono",children:"Errors Only"})," (which bypasses successful 200 OK payloads) or ",e.jsx("strong",{className:"text-slate-400 font-mono",children:"Off"}),". Switch to ",e.jsx("strong",{className:"text-emerald-400 font-mono",children:"Trace: All"})," in the top toolbar to record all full payloads."]})]});const b=((y=l.request)==null?void 0:y.body)||{},p=((j=l.providerRequest)==null?void 0:j.body)||{},v=((w=l.response)==null?void 0:w.body)||((t=l.providerResponse)==null?void 0:t.body)||l.errorMessage||{},i=n==="client"?b:n==="providerReq"?p:v,g=n==="client"?(T=l.request)==null?void 0:T.headers:n==="providerReq"?(C=l.providerRequest)==null?void 0:C.headers:((B=l.response)==null?void 0:B.headers)||((S=l.providerResponse)==null?void 0:S.headers),a=JSON.stringify(i,null,2);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-[#05070B] p-1 rounded-lg border border-[#1E293B]",children:[e.jsxs("button",{type:"button",onClick:()=>s("client"),className:`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-semibold transition-all cursor-pointer ${n==="client"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(Ee,{className:"size-3.5"}),e.jsx("span",{children:"Client Inbound"})]}),e.jsxs("button",{type:"button",onClick:()=>s("providerReq"),className:`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-semibold transition-all cursor-pointer ${n==="providerReq"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(Te,{className:"size-3.5"}),e.jsx("span",{children:"Provider Transformed"})]}),e.jsxs("button",{type:"button",onClick:()=>s("response"),className:`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-semibold transition-all cursor-pointer ${n==="response"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(Se,{className:"size-3.5"}),e.jsx("span",{children:"Response & Output"})]})]}),e.jsx("button",{type:"button",onClick:()=>u(a,n),className:"px-2.5 py-1 rounded-md bg-[#0A0E18] border border-[#1E293B] text-slate-300 hover:text-white flex items-center gap-1.5 transition-colors text-xs cursor-pointer",children:N===n?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"size-3.5 text-emerald-400"}),e.jsx("span",{children:"Copied JSON"})]}):e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"size-3.5"}),e.jsx("span",{children:"Copy JSON"})]})})]}),n==="providerReq"&&((k=l.providerRequest)==null?void 0:k.url)&&e.jsxs("div",{className:"px-3 py-1.5 rounded-lg bg-[#05070B] border border-[#1E293B] text-[11px] font-mono text-slate-400 flex items-center gap-2",children:[e.jsx("span",{className:"text-slate-500 uppercase font-bold text-[10px]",children:"URL:"}),e.jsx("span",{className:"text-blue-300 truncate",children:l.providerRequest.url})]}),g&&Object.keys(g).length>0&&e.jsxs("details",{className:"rounded-lg bg-[#05070B] border border-[#1E293B] text-[11px] font-mono text-slate-400 overflow-hidden",children:[e.jsx("summary",{className:"px-3 py-1.5 cursor-pointer hover:text-slate-200 select-none flex items-center justify-between",children:e.jsxs("span",{className:"font-semibold text-slate-300",children:["Headers (",Object.keys(g).length,")"]})}),e.jsx("div",{className:"p-3 border-t border-[#1E293B] bg-black/40 max-h-36 overflow-y-auto",children:e.jsx("pre",{className:"text-[10px] text-slate-300 whitespace-pre-wrap",children:JSON.stringify(g,null,2)})})]}),e.jsx("div",{className:"rounded-xl bg-[#05070B] border border-[#1E293B] p-3 max-h-96 overflow-y-auto font-mono text-[11px] text-slate-200 leading-relaxed",children:a&&a!=="{}"?e.jsx("pre",{className:"whitespace-pre-wrap break-all select-text",children:a}):e.jsx("span",{className:"text-slate-500 italic",children:"No JSON payload body captured for this section."})})]})},Ge=({entry:l,isOpen:o,onClose:n})=>{var J,O,H,m,_;const s=me(M=>M.info),N=(s==null?void 0:s.port)||ue,f=(s==null?void 0:s.host)||be,[u,b]=c.useState(!1),[p,v]=c.useState(!1),[i,g]=c.useState(!1),[a,y]=c.useState(null),[j,w]=c.useState(!1);if(c.useEffect(()=>{if(!o||!l){y(null);return}const M=l.requestId||l.id;if(!M){y(null);return}let z=!0;return w(!0),fetch(`/api/usage/request-details/${encodeURIComponent(M)}`).then($=>$.ok?$.json():null).then($=>{z&&(y($),w(!1))}).catch(()=>{z&&w(!1)}),()=>{z=!1}},[o,l]),!o||!l)return null;const{gateway:t,error:T,level:C,category:B,rawText:S,reqTag:k,id:P,requestId:R}=l,E=(t==null?void 0:t.statusCode)||(T==null?void 0:T.status)||(a==null?void 0:a.status),D=E===429,q=C==="error"||typeof E=="number"&&E>=400&&!D,F=typeof E=="number"&&E>=200&&E<300,A=B==="proxy"||!!t||!!a||!!l.requestId,U=(M,z)=>{he(M),z==="id"?(b(!0),setTimeout(()=>b(!1),2e3)):z==="json"?(v(!0),setTimeout(()=>v(!1),2e3)):z==="curl"&&(g(!0),setTimeout(()=>g(!1),2e3))},G=()=>{var Y;const M=(t==null?void 0:t.route)||"/v1/messages",z=(t==null?void 0:t.actualModel)||(t==null?void 0:t.requestedModel)||(a==null?void 0:a.model)||"claude-3-7-sonnet",$=((Y=a==null?void 0:a.request)==null?void 0:Y.body)||{model:z,messages:[{role:"user",content:"Hello"}]},se=JSON.stringify($,null,2).replace(/'/g,"'\\''");return`curl -X POST http://${f}:${N}${M} \\
2
+ -H "Content-Type: application/json" \\
3
+ -H "Authorization: Bearer [REDACTED]" \\
4
+ -d '${se}'`};return e.jsxs(Oe,{isOpen:o,onClose:n,children:[e.jsxs("div",{className:"p-4 sm:p-5 border-b border-[#1E293B] flex items-center justify-between bg-[#0A0E18]",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[t!=null&&t.clientTool?e.jsx(pe,{name:t.clientTool,size:"md"}):e.jsx("div",{className:"p-1.5 rounded-lg bg-blue-500/10 border border-blue-500/20 text-blue-400",children:e.jsx(Q,{className:"size-4"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-bold text-sm text-white",children:A?"AI Transaction Inspector":"System Event Diagnostics"}),k&&e.jsx("span",{children:k}),e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-semibold uppercase bg-blue-500/10 text-blue-400 border border-blue-500/20",children:B})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:"text-xs text-slate-400 font-mono",children:P||R||"N/A"}),e.jsx("button",{type:"button",onClick:()=>U(P||R||"","id"),className:"text-slate-500 hover:text-slate-300 transition-colors cursor-pointer",title:"Copy ID",children:u?e.jsx(X,{className:"size-3 text-emerald-400"}):e.jsx(le,{className:"size-3"})})]})]})]})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("button",{type:"button",onClick:n,"aria-label":"Close",className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-slate-800 transition-colors cursor-pointer",children:e.jsx(ce,{className:"size-5"})})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-6",children:[A?e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0E18] border border-[#1E293B]",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(ke,{className:"size-3.5 text-blue-400"})," Status"]}),e.jsx("p",{className:"mt-1 text-sm font-bold",children:D?e.jsx("span",{className:"text-amber-400",children:"429 Rate Limit"}):q?e.jsx("span",{className:"text-red-400",children:E||"Error"}):F?e.jsxs("span",{className:"text-emerald-400",children:[E," OK"]}):e.jsx("span",{className:"text-slate-300",children:C.toUpperCase()})})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0E18] border border-[#1E293B]",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(de,{className:"size-3.5 text-amber-400"})," Duration"]}),e.jsx("p",{className:"mt-1 text-sm font-bold text-slate-200 font-mono",children:(t==null?void 0:t.durationMs)!==void 0?`${t.durationMs}ms`:((J=a==null?void 0:a.latency)==null?void 0:J.totalMs)!==void 0?`${a.latency.totalMs}ms`:"-"}),(t==null?void 0:t.ttftMs)!==void 0&&t.ttftMs>0&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["TTFT: ",t.ttftMs,"ms"]})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0E18] border border-[#1E293B]",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(xe,{className:"size-3.5 text-purple-400"})," Model"]}),e.jsx("p",{className:"mt-1 text-xs font-bold text-slate-200 font-mono truncate",title:(t==null?void 0:t.actualModel)||(t==null?void 0:t.requestedModel)||(a==null?void 0:a.model)||void 0,children:(t==null?void 0:t.actualModel)||(t==null?void 0:t.requestedModel)||(a==null?void 0:a.model)||"-"}),((t==null?void 0:t.providerId)||(a==null?void 0:a.provider))&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["via ",(t==null?void 0:t.providerId)||(a==null?void 0:a.provider)]})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0E18] border border-[#1E293B]",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(Ae,{className:"size-3.5 text-emerald-400"})," Cost"]}),e.jsx("p",{className:"mt-1 text-sm font-bold text-emerald-400 font-mono",children:(t==null?void 0:t.cost)!==void 0?`$${t.cost<.01?t.cost.toFixed(4):t.cost.toFixed(3)}`:(a==null?void 0:a.cost)!==void 0?`$${a.cost.toFixed(4)}`:"$0.00"})]})]}):e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0E18] border border-[#1E293B] flex items-center justify-between text-xs font-mono",children:[e.jsxs("span",{className:"text-slate-400",children:["Level: ",e.jsx("strong",{className:"text-white uppercase",children:C})]}),e.jsxs("span",{className:"text-slate-400",children:["Category: ",e.jsx("strong",{className:"text-blue-400 uppercase",children:B})]})]}),(t==null?void 0:t.tokens)&&e.jsx(Ue,{tokens:t.tokens}),(t==null?void 0:t.tools)&&t.tools.length>0&&e.jsx(Je,{tools:t.tools}),(l.error||(a==null?void 0:a.errorMessage))&&e.jsxs("div",{className:"p-4 rounded-xl bg-red-950/20 border border-red-500/30 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-bold text-red-400 flex items-center gap-1.5",children:[e.jsx(ze,{className:"size-4 text-red-400"})," Error Diagnostics"]}),(((O=l.error)==null?void 0:O.code)||((H=l.error)==null?void 0:H.status))&&e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono font-bold bg-red-500/20 text-red-300 border border-red-500/40",children:l.error.code||`HTTP ${l.error.status}`})]}),e.jsx("div",{className:"text-xs font-mono text-red-200 bg-black/40 p-3 rounded-lg border border-red-500/20 whitespace-pre-wrap break-all leading-relaxed",children:((m=l.error)==null?void 0:m.message)||(a==null?void 0:a.errorMessage)||"Unknown error occurred"}),((_=l.error)==null?void 0:_.stack)&&e.jsxs("details",{className:"text-[11px] font-mono text-slate-400",children:[e.jsx("summary",{className:"cursor-pointer hover:text-slate-200 select-none",children:"View Stack Trace"}),e.jsx("pre",{className:"mt-2 p-2.5 rounded bg-black/60 text-[10px] text-slate-400 overflow-x-auto whitespace-pre-wrap leading-relaxed border border-slate-800",children:l.error.stack})]})]}),A&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(Q,{className:"size-3.5 text-blue-400"})," Observability Payload Trace"]}),e.jsx(qe,{detail:a,loading:j})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(ee,{className:"size-3.5 text-slate-400"})," Log Output"]}),e.jsx("div",{className:"p-3 rounded-lg bg-[#05070B] border border-[#1E293B] font-mono text-xs text-slate-300 whitespace-pre-wrap break-all leading-relaxed",children:S})]})]}),e.jsxs("div",{className:"p-4 border-t border-[#1E293B] bg-[#0A0E18] flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[A&&e.jsxs("button",{type:"button",onClick:()=>U(G(),"curl"),className:"px-3 py-1.5 rounded-lg text-xs font-semibold bg-[#131B2E] border border-blue-500/30 text-blue-400 hover:bg-blue-500/20 flex items-center gap-1.5 transition-colors cursor-pointer",children:[i?e.jsx(X,{className:"size-3.5 text-emerald-400"}):e.jsx(ee,{className:"size-3.5"}),e.jsx("span",{children:i?"Copied cURL!":"Copy cURL"})]}),e.jsxs("button",{type:"button",onClick:()=>U(JSON.stringify(a||l,null,2),"json"),className:"px-3 py-1.5 rounded-lg text-xs font-semibold bg-[#1E293B] text-slate-300 hover:text-white flex items-center gap-1.5 transition-colors cursor-pointer",children:[p?e.jsx(X,{className:"size-3.5 text-emerald-400"}):e.jsx(Le,{className:"size-3.5"}),e.jsx("span",{children:p?"Copied JSON!":"Copy JSON"})]})]}),e.jsx("button",{type:"button",onClick:n,className:"px-4 py-1.5 rounded-lg text-xs font-semibold bg-slate-800 text-slate-300 hover:text-white transition-colors cursor-pointer",children:"Close"})]})]})},es=()=>{const[l,o]=c.useState([]),[n,s]=c.useState([]),[N,f]=c.useState(!1),[u,b]=c.useState(!0),[p,v]=c.useState("structured"),[i,g]=c.useState("all"),[a,y]=c.useState(""),[j,w]=c.useState("all"),[t,T]=c.useState("all"),[C,B]=c.useState("all"),[S,k]=c.useState("all"),[P,R]=c.useState("info"),[E,D]=c.useState("errors_only"),[q,F]=c.useState(!1),[A,U]=c.useState(null),[G,J]=c.useState(!1),O=c.useRef(null);c.useEffect(()=>{let r=null,x=!0;return(()=>{try{const d=Re.getToken(),I=d?`/api/console-logs/stream?token=${encodeURIComponent(d)}`:"/api/console-logs/stream";r=new EventSource(I),r.onopen=()=>{x&&f(!0)},r.onmessage=Z=>{if(x)try{const h=JSON.parse(Z.data);h.type==="init"?(Array.isArray(h.logs||h.lines)&&o(h.logs||h.lines),Array.isArray(h.structured)&&s(h.structured)):h.type==="lines"?(Array.isArray(h.lines)&&o(W=>[...W,...h.lines].slice(-500)),Array.isArray(h.structured)&&s(W=>[...W,...h.structured].slice(-500))):h.type==="clear"&&(o([]),s([]))}catch{}},r.onerror=()=>{x&&f(!1)}}catch{x&&f(!1)}})(),fetch("/api/console-logs").then(d=>d.json()).then(d=>{x&&d.success&&(Array.isArray(d.logs)&&d.logs.length>0&&o(I=>I.length===0?d.logs:I),Array.isArray(d.structuredLogs)&&d.structuredLogs.length>0&&s(I=>I.length===0?d.structuredLogs:I),d.level&&R(d.level))}).catch(()=>{}),fetch("/api/console-logs/level").then(d=>d.json()).then(d=>{x&&d.success&&d.level&&R(d.level)}).catch(()=>{}),fetch("/api/console-logs/observability").then(d=>d.json()).then(d=>{x&&d.success&&d.mode&&D(d.mode)}).catch(()=>{}),()=>{x=!1,r==null||r.close()}},[]),c.useEffect(()=>{u&&O.current&&(O.current.scrollTop=O.current.scrollHeight)},[l,n,u,p]);const H=c.useMemo(()=>{var x;const r=new Set;for(const L of n)(x=L.gateway)!=null&&x.clientTool&&r.add(L.gateway.clientTool);return Array.from(r).sort()},[n]),m=c.useMemo(()=>{var x;const r=new Set;for(const L of n)(x=L.gateway)!=null&&x.providerId&&r.add(L.gateway.providerId);return Array.from(r).sort()},[n]),_=c.useMemo(()=>n.filter(r=>{var x,L,d,I,Z,h,W,re,ae,oe,ne;if(i==="proxy"&&r.category!=="proxy"||i==="stream"&&!(r.rawText.includes("Tool invoked:")||r.rawText.includes("streaming chunks")||(x=r.gateway)!=null&&x.tools&&r.gateway.tools.length>0)||i==="errors"&&!(r.level==="error"||r.level==="warn"||(L=r.gateway)!=null&&L.statusCode&&r.gateway.statusCode>=400)||i==="system"&&r.category==="proxy"||j!=="all"&&((d=r.gateway)==null?void 0:d.clientTool)!==j||t!=="all"&&((I=r.gateway)==null?void 0:I.providerId)!==t||C==="200"&&((Z=r.gateway)==null?void 0:Z.statusCode)!==200||C==="429"&&((h=r.gateway)==null?void 0:h.statusCode)!==429||C==="error"&&!(r.level==="error"||(W=r.gateway)!=null&&W.statusCode&&r.gateway.statusCode>=400&&r.gateway.statusCode!==429)||S!=="all"&&r.level!==S||S==="all"&&(r.level==="trace"||r.level==="debug")&&!((re=r.gateway)!=null&&re.statusCode)&&!((ae=r.gateway)!=null&&ae.actualModel)&&!r.error)return!1;if(a.trim()){const K=a.toLowerCase();if(!(r.rawText.toLowerCase().includes(K)||r.message.toLowerCase().includes(K)||r.requestId&&r.requestId.toLowerCase().includes(K)||((oe=r.gateway)==null?void 0:oe.actualModel)&&r.gateway.actualModel.toLowerCase().includes(K)||((ne=r.gateway)==null?void 0:ne.requestedModel)&&r.gateway.requestedModel.toLowerCase().includes(K)))return!1}return!0}),[n,i,j,t,C,S,a]),M=async r=>{R(r);try{await fetch("/api/console-logs/level",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({level:r})})}catch{}},z=async r=>{D(r);try{await fetch("/api/console-logs/observability",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:r})})}catch{}},$=c.useMemo(()=>{if(n.length>0)return _.map(x=>x.rawText);if(!a.trim())return l;const r=a.toLowerCase();return l.filter(x=>x.toLowerCase().includes(r))},[n.length,_,l,a]),se=async()=>{try{o([]),s([]),await fetch("/api/console-logs",{method:"DELETE"})}catch{}},Y=async()=>{const r=p==="raw"?$.join(`
5
+ `):_.map(L=>L.rawText).join(`
6
+ `);if(!r)return;await he(r)&&(F(!0),setTimeout(()=>F(!1),2e3))},fe=r=>{U(r),J(!0)};return e.jsxs("div",{className:"w-full space-y-3 animate-rt-fade-in flex flex-col h-[calc(100vh-140px)] min-h-[500px]",children:[e.jsx(Ie,{connected:N,totalCount:p==="raw"?l.length:n.length,filteredCount:p==="raw"?$.length:_.length,viewMode:p,onViewModeChange:v,categoryTab:i,onCategoryTabChange:g,searchQuery:a,onSearchQueryChange:y,clientToolFilter:j,onClientToolFilterChange:w,providerFilter:t,onProviderFilterChange:T,statusFilter:C,onStatusFilterChange:B,levelFilter:S,onLevelFilterChange:k,gatewayLogLevel:P,onGatewayLogLevelChange:M,observabilityMode:E,onObservabilityModeChange:z,autoScroll:u,onAutoScrollToggle:()=>b(r=>!r),onCopy:Y,copied:q,onClear:se,availableTools:H,availableProviders:m}),p==="raw"?e.jsx(Fe,{logs:$,filterText:a,scrollRef:O}):e.jsx("div",{ref:O,className:"flex-1 overflow-y-auto space-y-2 pr-1 select-text min-h-0",children:_.length===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-slate-500 py-16 space-y-2 select-none border border-[#1E293B] rounded-xl bg-[#05070B]",children:[e.jsx(Q,{className:"size-8 text-slate-600"}),e.jsx("p",{className:"text-xs",children:a.trim()||j!=="all"||t!=="all"?"No structured logs match the current filters.":"No structured logs yet. Proxy and system events will appear here."}),e.jsxs("span",{className:"text-[10px] text-slate-600 font-mono",children:["Listening on ",Be,"/api/console-logs/stream"]})]}):_.map(r=>e.jsx(Pe,{entry:r,onClick:()=>fe(r),isSelected:(A==null?void 0:A.id)===r.id&&G},r.id))}),e.jsx(Ge,{entry:A,isOpen:G,onClose:()=>J(!1)})]})};export{es as ConsoleLogTab};
@@ -0,0 +1 @@
1
+ import{R as ne,r as o,j as e}from"./vendor-BcOI2aZ9.js";import{P as xe}from"./index-vFoRSZw0.js";import{T as pe}from"./ToolIcon-BZE0Fv7L.js";import{S as me}from"./Select-BNRH8LIG.js";import{g as be}from"./metadataRegistry-4BIaQVmV.js";const ae={sm:{box:"size-4 rounded-[4px]",icon:"size-2.5",label:"text-xs",description:"text-[11px]",gap:"gap-2"},md:{box:"size-5 rounded-[5px]",icon:"size-3.5",label:"text-sm",description:"text-xs",gap:"gap-2.5"},lg:{box:"size-6 rounded-[6px]",icon:"size-4",label:"text-base",description:"text-sm",gap:"gap-3"}},re={primary:{active:"bg-blue-600 border-blue-500 text-white shadow-sm shadow-blue-500/25",focusRing:"peer-focus-visible:ring-blue-500/50",hoverBorder:"group-hover:border-blue-500/50 hover:border-blue-500/50"},emerald:{active:"bg-emerald-600 border-emerald-500 text-white shadow-sm shadow-emerald-500/25",focusRing:"peer-focus-visible:ring-emerald-500/50",hoverBorder:"group-hover:border-emerald-500/50 hover:border-emerald-500/50"},cyan:{active:"bg-cyan-600 border-cyan-500 text-white shadow-sm shadow-cyan-500/25",focusRing:"peer-focus-visible:ring-cyan-500/50",hoverBorder:"group-hover:border-cyan-500/50 hover:border-cyan-500/50"}},he=ne.forwardRef(({checked:B,defaultChecked:a,indeterminate:n=!1,onChange:y,size:j="md",variant:C="primary",label:u,description:x,disabled:i=!1,className:S="",checkboxClassName:b="",wrapperClassName:E="",onClick:I,...D},p)=>{const h=o.useRef(null),N=B!==void 0,[f,k]=o.useState(!!a),m=N?!!B:f;o.useEffect(()=>{h.current&&(h.current.indeterminate=!!n)},[n]);const z=c=>{h.current=c,typeof p=="function"?p(c):p&&(p.current=c)},$=c=>{i||(N||k(c.target.checked),y==null||y(c.target.checked,c))},d=ae[j]||ae.md,w=re[C]||re.primary,R=m||n,A=!!x;return e.jsxs("label",{className:`group inline-flex select-none transition-opacity ${A?"items-start":"items-center"} ${i?"cursor-not-allowed opacity-50":"cursor-pointer"} ${d.gap} ${E||S}`,onClick:I,children:[e.jsxs("div",{className:`relative inline-flex items-center justify-center shrink-0 ${A?"mt-0.5":""}`,children:[e.jsx("input",{ref:z,type:"checkbox",checked:m,disabled:i,onChange:$,"aria-checked":n?"mixed":m,className:"sr-only peer",...D}),e.jsxs("div",{className:`flex items-center justify-center border transition-all duration-150 ease-out peer-focus-visible:ring-2 peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-[#0A0D14] ${d.box} ${R?w.active:`bg-[#0B0F17] border-[#1E293B] text-transparent ${i?"":"group-hover:border-slate-500 hover:border-slate-500"}`} ${w.focusRing} ${i?"":"active:scale-95"} ${b}`,children:[e.jsx("svg",{className:`transition-all duration-150 ease-out ${d.icon} ${m&&!n?"scale-100 opacity-100":"scale-50 opacity-0"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),e.jsx("svg",{className:`transition-all duration-150 ease-out absolute ${d.icon} ${n?"scale-100 opacity-100":"scale-50 opacity-0"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3.5,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})]})]}),(u||x)&&e.jsxs("div",{className:"flex flex-col leading-tight min-w-0 justify-center",children:[u&&e.jsx("span",{className:`font-medium text-slate-200 transition-colors ${i?"":"group-hover:text-white"} ${d.label}`,children:u}),x&&e.jsx("span",{className:`text-slate-400 mt-0.5 ${d.description}`,children:x})]})]})});he.displayName="Checkbox";const Ne=({isOpen:B,account:a,onClose:n,onSave:y})=>{const[j,C]=o.useState(""),[u,x]=o.useState(""),[i,S]=o.useState(""),[b,E]=o.useState(!1),[I,D]=o.useState(!0),[p,h]=o.useState(!1),[N,f]=o.useState(null),[k,m]=o.useState(""),[z,$]=o.useState(""),[d,w]=o.useState(""),[R,A]=o.useState("2024-10-01-preview"),[c,F]=o.useState(""),[M,_]=o.useState(""),[q,H]=o.useState("sgp"),[O,L]=o.useState("profile"),[V,G]=o.useState(""),[T,X]=o.useState("us-east-1"),[Y,Z]=o.useState(""),[J,Q]=o.useState(""),[U,P]=o.useState(""),r=((a==null?void 0:a.providerId)||"").toLowerCase(),s=be((a==null?void 0:a.providerId)||""),ie=r==="opencode"||r==="oc"||!!(s!=null&&s.noAuth)||(s==null?void 0:s.requiresApiKey)===!1||(s==null?void 0:s.authType)==="none",g=r==="ollama-local"||r.includes("ollama"),W=!!(s!=null&&s.isLocal)||r==="lm-studio"||r==="jan"||r==="local-device",ee=ie||g||W||(s==null?void 0:s.requiresApiKey)===!1,te=r==="azure"||r.includes("azure"),se=r==="cloudflare-ai"||r==="cloudflare",le=r==="bedrock"||r.includes("bedrock"),K=r==="xiaomi-tokenplan",oe=r==="alicode"||r==="alibaba",v=ne.useMemo(()=>K?[{id:"sgp",label:"Singapore (新加坡)"},{id:"cn",label:"China (中国大陆)"},{id:"ams",label:"Amsterdam (阿姆斯特丹)"}]:(s==null?void 0:s.regions)||[],[K,s==null?void 0:s.regions]);if(o.useEffect(()=>{var t;if(a){C(a.name||""),x(a.tag||((t=a.providerSpecificData)==null?void 0:t.tag)||""),S(""),E(!1),D(!!a.isActive),f(null);const l=a.providerSpecificData||{};m(l.baseUrl||(g?"http://127.0.0.1:11434":r==="lm-studio"?"http://localhost:1234/v1":r==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),$(l.azureEndpoint||""),w(l.deployment||"gpt-4"),A(l.apiVersion||"2024-10-01-preview"),F(l.organization||""),_(l.accountId||""),H(l.region||(v.length>0?v[0].id:"sgp")),P(l.baseUrl||"");const ue=!!l.accessKeyId;L(ue?"static":"profile"),G(l.profile||""),X(l.region||"us-east-1"),Z(l.accessKeyId||""),Q(l.sessionToken||"")}},[a,v,g,r]),!a)return null;const ce=()=>{const t=a.providerSpecificData||{};let l={};return g?l.baseUrl=k.trim()||"http://127.0.0.1:11434":W?l.baseUrl=k.trim():te?l={azureEndpoint:z.trim(),deployment:d.trim(),apiVersion:R.trim(),organization:c.trim()||void 0}:se?l={accountId:M.trim()}:le?O==="profile"?l={profile:V.trim(),region:T.trim()||"us-east-1"}:l={accessKeyId:Y.trim(),region:T.trim()||"us-east-1",sessionToken:J.trim()||void 0}:(K||v.length>0)&&(l.region=q,oe&&(U.trim()?l.baseUrl=U.trim():t.baseUrl&&delete t.baseUrl)),Object.keys(l).length>0?{...t,...l}:Object.keys(t).length>0?t:void 0},de=async t=>{if(t.preventDefault(),!j.trim()){f("Account name is required.");return}h(!0),f(null);try{const l=ce()||{};u.trim()?l.tag=u.trim().toLowerCase():delete l.tag,await y({name:j.trim(),apiKey:i.trim()?i.trim():void 0,isActive:I,providerSpecificData:Object.keys(l).length>0?l:void 0}),n()}catch(l){f(l.message||"Failed to save account changes.")}finally{h(!1)}};return e.jsx(xe,{isOpen:B,onClose:n,maxWidthClass:"max-w-xl",children:e.jsxs("form",{onSubmit:de,className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(pe,{src:(s==null?void 0:s.image)||`/assets/providers/${a.providerId}/icon.png`,name:(s==null?void 0:s.name)||a.providerId,color:(s==null?void 0:s.color)||"#3B82F6",iconBg:s==null?void 0:s.iconBg,size:"sm"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-100 flex items-center gap-1.5",children:"Edit Account"}),e.jsxs("div",{className:"text-[11px] text-slate-400 font-mono",children:[(s==null?void 0:s.name)||a.providerId.toUpperCase()," • ",a.id]})]})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Close",className:"text-slate-400 hover:text-white transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),N&&e.jsxs("div",{className:"p-3 bg-red-500/10 border border-red-500/20 text-red-400 text-xs rounded-xl flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"error"}),e.jsx("span",{children:N})]}),e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-slate-300 font-medium mb-1",children:["Account Name / Label ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx("input",{type:"text",value:j,onChange:t=>C(t.target.value),placeholder:"e.g. Work Account or user@example.com",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("label",{className:"text-slate-300 font-medium flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] text-blue-400",children:"label"}),"Group Tag"]}),e.jsx("span",{className:"text-slate-500 text-[11px]",children:"Optional • For grouping in Combos"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",value:u,onChange:t=>x(t.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"")),placeholder:"e.g. pro, plus, free, team",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 pl-3 pr-20 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"}),e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1 pointer-events-none",children:["pro","plus","free"].map(t=>e.jsx("button",{type:"button",tabIndex:-1,onClick:l=>{l.preventDefault(),x(t)},className:`pointer-events-auto text-[10px] px-1.5 py-0.5 rounded font-mono transition-colors ${u===t?"bg-blue-600 text-white font-semibold":"bg-[#1E293B] text-slate-400 hover:text-slate-200"}`,children:t},t))})]})]})]}),ee&&e.jsxs("div",{className:"p-2.5 bg-emerald-500/10 border border-emerald-500/20 rounded-xl text-emerald-300 text-[11px] flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[16px]",children:"verified"}),e.jsxs("span",{children:[(s==null?void 0:s.name)||a.providerId," does not require an API key by default. You can leave the key blank."]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-slate-300 font-medium",children:ee?"API Key / Auth Token (Optional)":"Update API Key / Secret Token"}),e.jsx("span",{className:"text-slate-500 text-[11px]",children:"Leave blank to keep existing key"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:b?"text":"password",value:i,onChange:t=>S(t.target.value),placeholder:"Enter new API key or token to overwrite...",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 pl-3 pr-9 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"}),e.jsx("button",{type:"button",onClick:()=>E(!b),tabIndex:-1,className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors cursor-pointer",title:b?"Hide token":"Show token",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:b?"visibility_off":"visibility"})})]})]}),(g||W)&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Local Host / Base URL"}),e.jsx("input",{type:"text",value:k,onChange:t=>m(t.target.value),placeholder:g?"http://127.0.0.1:11434":"http://localhost:1234/v1",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"})]}),te&&e.jsxs("div",{className:"space-y-2.5 p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{className:"text-[11px] font-semibold text-slate-300 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[14px]",children:"cloud"}),"Azure OpenAI Deployment Parameters"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Endpoint URL"}),e.jsx("input",{type:"text",value:z,onChange:t=>$(t.target.value),placeholder:"https://my-resource.openai.azure.com",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Deployment Name"}),e.jsx("input",{type:"text",value:d,onChange:t=>w(t.target.value),placeholder:"gpt-4",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"API Version"}),e.jsx("input",{type:"text",value:R,onChange:t=>A(t.target.value),placeholder:"2024-10-01-preview",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Organization (Optional)"}),e.jsx("input",{type:"text",value:c,onChange:t=>F(t.target.value),placeholder:"org-...",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]})]}),se&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Cloudflare Account ID"}),e.jsx("input",{type:"text",value:M,onChange:t=>_(t.target.value),placeholder:"Cloudflare account ID (32 chars)",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"})]}),le&&e.jsxs("div",{className:"space-y-2.5 p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{className:"flex bg-[#141B2D] p-1 rounded-lg border border-[#1E293B] text-xs",children:[e.jsx("button",{type:"button",onClick:()=>L("profile"),className:`flex-1 py-1 rounded-md font-medium transition-colors cursor-pointer ${O==="profile"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"AWS Profile"}),e.jsx("button",{type:"button",onClick:()=>L("static"),className:`flex-1 py-1 rounded-md font-medium transition-colors cursor-pointer ${O==="static"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Static IAM Keys"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Region"}),e.jsx("input",{type:"text",value:T,onChange:t=>X(t.target.value),placeholder:"us-east-1",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),O==="profile"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Profile Name"}),e.jsx("input",{type:"text",value:V,onChange:t=>G(t.target.value),placeholder:"default",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Access Key ID"}),e.jsx("input",{type:"text",value:Y,onChange:t=>Z(t.target.value),placeholder:"AKIA...",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Session Token (Optional)"}),e.jsx("input",{type:"password",value:J,onChange:t=>Q(t.target.value),placeholder:"Optional STS token...",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]})]})]}),(K||v.length>0)&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Cluster Region"}),e.jsx(me,{value:q,onChange:t=>H(t),options:v.map(t=>({value:t.id,label:t.label.includes(t.id)?t.label:`${t.label} (${t.id})`})),className:"w-full",triggerClassName:"bg-[#0A0D14] font-mono text-xs py-2"})]}),oe&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"block text-slate-400 text-xs",children:["Dedicated Workspace Endpoint URL ",e.jsx("span",{className:"text-slate-500",children:"(Optional)"})]}),e.jsx("input",{type:"text",value:U,onChange:t=>P(t.target.value),placeholder:"e.g. https://ws-xxx.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono text-xs"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Required if your API key was created inside an Alibaba Model Studio custom workspace."})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-[#141B2D] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-slate-200",children:"Active Status"}),e.jsx("div",{className:"text-[11px] text-slate-400",children:"Inactive accounts are excluded from routing and quota polling."})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:t=>D(t.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-9 h-5 bg-slate-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-blue-600"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-4 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:n,disabled:p,className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:p,className:"px-4 py-2 text-xs font-medium text-white bg-blue-600 hover:bg-blue-500 rounded-xl transition-colors cursor-pointer flex items-center gap-1.5 disabled:opacity-50",children:p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving..."]}):"Save Changes"})]})]})})};export{he as C,Ne as E};
@@ -0,0 +1 @@
1
+ import{r as l,j as e}from"./vendor-BcOI2aZ9.js";import{S as we}from"./Select-BNRH8LIG.js";import{C as ve}from"./ConfirmModal-CsfteGXH.js";import{u as ee,D as m,c as se,P as Ce}from"./index-vFoRSZw0.js";import{c as te}from"./clipboard-CLQF8jeK.js";import"./lucide-Cc35htxl.js";const u="10.*, 172.16-31.*, 192.168.*, 169.254.*, *.local",ke={host:se,port:m,requireApiKey:!1,proxyUrl:"",customHeaders:{},allowedHosts:u},Pe=({onRestartClick:K})=>{const o=ee(t=>t.info),w=ee(t=>t.fetchSystemInfo),ae=!!(o!=null&&o.isRestartRequired),[r,c]=l.useState(ke),[le,P]=l.useState(!0),[T,H]=l.useState(!1),[L,f]=l.useState(null),[R,I]=l.useState(null),[y,g]=l.useState([]),[v,j]=l.useState([]),[re,_]=l.useState(!0),[ne,oe]=l.useState(new Set),[p,U]=l.useState(null),[ie,F]=l.useState(null),[q,h]=l.useState(!1),[G,O]=l.useState(""),[$,M]=l.useState(!1),[N,b]=l.useState(null),[x,C]=l.useState(null),[J,k]=l.useState(null),[A,V]=l.useState(!1),W=l.useCallback(async()=>{try{P(!0);const[t]=await Promise.all([fetch("/api/settings/endpoint"),w()]);if(t.ok){const s=await t.json();c({host:s.host||se,port:s.port||m,requireApiKey:!!s.requireApiKey,proxyUrl:s.proxyUrl||"",customHeaders:s.customHeaders||{},allowedHosts:s.allowedHosts||u});const a=Object.entries(s.customHeaders||{}).map(([i,n],d)=>({id:`header-${d}-${Date.now()}`,key:i,value:String(n)}));g(a)}}catch(t){console.error("Failed to load endpoint settings:",t)}finally{P(!1)}},[w]),z=l.useCallback(async()=>{try{_(!0);const t=await fetch("/api/settings/endpoint/keys");if(t.ok){const s=await t.json();Array.isArray(s)&&j(s)}}catch(t){console.error("Failed to load gateway API keys:",t)}finally{_(!1)}},[]);l.useEffect(()=>{W(),z()},[W,z]);const ce=async t=>{var a,i;t&&t.preventDefault(),H(!0),f(null),I(null);const s={};for(const n of y){const d=n.key.trim();d&&(s[d]=n.value.trim())}try{const n={host:r.host,port:Number(r.port)||m,requireApiKey:r.requireApiKey,proxyUrl:((a=r.proxyUrl)==null?void 0:a.trim())||"",customHeaders:s,allowedHosts:((i=r.allowedHosts)==null?void 0:i.trim())||u},d=await fetch("/api/settings/endpoint",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!d.ok){const Ne=await d.json();throw new Error(Ne.error||"Failed to update endpoint settings")}const ge=await d.json();c(ge);const D=await w(),je=!!(D!=null&&D.isRestartRequired);f(je?"Configuration saved! Server restart is required to rebind the network interface.":"Settings saved successfully!"),setTimeout(()=>f(null),5e3)}catch(n){I((n==null?void 0:n.message)||"Failed to save settings")}finally{H(!1)}},de=async t=>{t.preventDefault();try{M(!0);const s=await fetch("/api/settings/endpoint/keys",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:G.trim()||void 0})});if(s.ok){const a=await s.json();j(i=>[a,...i]),b(a),O("")}else{const a=await s.json();alert(a.error||"Failed to create API key")}}catch(s){console.error("Error creating key:",s)}finally{M(!1)}},xe=async t=>{try{const s=await fetch(`/api/settings/endpoint/keys/${t.id}/toggle`,{method:"PATCH"});if(s.ok){const a=await s.json();j(i=>i.map(n=>n.id===t.id?a:n))}}catch(s){console.error("Error toggling API key:",s)}},pe=async()=>{if(x)try{(await fetch(`/api/settings/endpoint/keys/${x.id}`,{method:"DELETE"})).ok&&j(s=>s.filter(a=>a.id!==x.id))}catch(t){console.error("Error deleting API key:",t)}finally{C(null)}},me=t=>{oe(s=>{const a=new Set(s);return a.has(t)?a.delete(t):a.add(t),a})},S=(t,s)=>{te(t),U(s),setTimeout(()=>U(null),2e3)},ue=(t,s)=>{te(t),F(s),setTimeout(()=>F(null),2e3)},he=()=>{g([...y,{id:`header-${Date.now()}`,key:"",value:""}])},X=(t,s,a)=>{g(i=>i.map(n=>n.id===t?{...n,[s]:a}:n))},be=t=>{g(s=>s.filter(a=>a.id!==t))},Y=r.host==="0.0.0.0"?"127.0.0.1":r.host||"127.0.0.1",fe=(o==null?void 0:o.port)||(typeof window<"u"&&window.location.port&&window.location.port!=="5173"?Number(window.location.port):m),E=r.port||fe,Q=`http://${Y}:${E}/v1`,B=`http://${Y}:${E}`,ye=async()=>{V(!0),k(null);try{const s=await(await fetch("/health")).json();k(JSON.stringify(s,null,2))}catch{k(JSON.stringify({error:"Failed to connect to gateway"},null,2))}finally{V(!1)}},Z=t=>{if(t.length<=10)return"••••••••";const s=t.slice(0,6),a=t.slice(-4);return`${s}••••••••${a}`};return e.jsxs("div",{className:"space-y-8 w-full pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"w-full p-6 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-blue-400",children:"api"}),"Local Gateway Endpoints"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Universal endpoints accepting OpenAI Chat Completions and Anthropic Messages protocols"})]}),e.jsxs("div",{className:"space-y-3.5 text-xs font-mono",children:[e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 block text-[10px] uppercase font-sans font-semibold",children:"OpenAI-Compatible Base URL (Cursor, Cline, OpenCode, Codex)"}),e.jsx("span",{className:"text-blue-400 font-bold text-sm",children:Q})]}),e.jsxs("button",{type:"button",onClick:()=>S(Q,"openai"),className:"px-3.5 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-xs font-semibold text-slate-300 hover:text-white flex items-center gap-1.5 transition-all cursor-pointer self-start sm:self-center font-sans",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:p==="openai"?"check":"content_copy"}),p==="openai"?"Copied":"Copy"]})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 block text-[10px] uppercase font-sans font-semibold",children:"Anthropic Base URL (Claude Code CLI: ANTHROPIC_BASE_URL)"}),e.jsx("span",{className:"text-cyan-400 font-bold text-sm",children:B})]}),e.jsxs("button",{type:"button",onClick:()=>S(B,"anthropic"),className:"px-3.5 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-xs font-semibold text-slate-300 hover:text-white flex items-center gap-1.5 transition-all cursor-pointer self-start sm:self-center font-sans",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:p==="anthropic"?"check":"content_copy"}),p==="anthropic"?"Copied":"Copy"]})]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B] space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-bold text-slate-200 block font-sans",children:"Test Gateway Connectivity:"}),e.jsxs("button",{type:"button",onClick:ye,disabled:A,className:"px-4 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer font-sans",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${A?"animate-spin":""}`,children:A?"sync":"play_arrow"}),"Execute Test Ping"]})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-xs font-mono text-slate-300 overflow-x-auto",children:["curl ",B,"/health"]}),J&&e.jsx("pre",{className:"bg-[#080B10] p-4 rounded-xl border border-blue-500/30 text-emerald-400 text-xs font-mono overflow-x-auto animate-rt-scale-in",children:J})]})]}),e.jsxs("div",{className:"w-full p-6 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-cyan-400",children:"tune"}),"Gateway & Connection Configuration"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Configure server listening network interface, listening port, security enforcement, and global upstream proxy."})]}),L&&e.jsxs("span",{className:"px-3 py-1 rounded-lg bg-emerald-500/10 border border-emerald-500/30 text-emerald-400 text-xs font-medium flex items-center gap-1.5 animate-rt-fade-in self-start sm:self-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check_circle"}),L]}),R&&e.jsxs("span",{className:"px-3 py-1 rounded-lg bg-rose-500/10 border border-rose-500/30 text-rose-400 text-xs font-medium flex items-center gap-1.5 self-start sm:self-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"error"}),R]})]}),ae&&e.jsxs("div",{className:"p-4 rounded-xl bg-amber-500/10 border border-amber-500/30 flex flex-col sm:flex-row sm:items-center justify-between gap-3 animate-rt-fade-in",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-amber-400 shrink-0",children:"restart_alt"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold text-amber-300",children:"Restart Required to Apply Network Configuration"}),e.jsxs("p",{className:"text-[11px] text-amber-200/70 mt-0.5",children:["Listening host is configured as ",e.jsx("span",{className:"font-mono font-semibold text-white",children:o==null?void 0:o.configuredHost}),", but the gateway socket is still bound to ",e.jsx("span",{className:"font-mono font-semibold text-white",children:o==null?void 0:o.host}),"."]})]})]}),K&&e.jsxs("button",{type:"button",onClick:K,className:"px-3.5 py-1.5 rounded-lg bg-amber-500 hover:bg-amber-400 text-slate-950 font-semibold text-xs transition-colors flex items-center gap-1.5 shrink-0 self-start sm:self-center cursor-pointer shadow-sm",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"restart_alt"}),"Restart Gateway Now"]})]}),le?e.jsxs("div",{className:"py-12 text-center text-slate-400 flex flex-col items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-2xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{className:"text-xs",children:"Loading configuration..."})]}):e.jsxs("form",{onSubmit:ce,className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:"Listening Host Interface"}),e.jsx(we,{value:r.host,onChange:t=>c({...r,host:t}),options:[{value:"127.0.0.1",label:"127.0.0.1 — Localhost only (Recommended, Private)"},{value:"0.0.0.0",label:"0.0.0.0 — All Interfaces (LAN / Network Access)"},{value:"localhost",label:"localhost — Standard local loopback"}],className:"w-full"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Bind to 127.0.0.1 to isolate Mapigate to this machine, or 0.0.0.0 to expose on your local network."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:"Gateway Port"}),e.jsx("input",{type:"number",min:1024,max:65535,value:r.port,onChange:t=>c({...r,port:parseInt(t.target.value,10)||m}),className:"w-full bg-[#0A0D14] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors"}),e.jsxs("p",{className:"text-[11px] text-slate-500 mt-1",children:["Active server listening on port ",e.jsx("span",{className:"text-blue-400 font-mono font-semibold",children:E}),". Default port is ",m,". Change requires restarting Mapigate server."]})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-2.5",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("label",{className:"text-xs font-semibold text-slate-200 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-cyan-400",children:"lan"}),"Trusted LAN Host Patterns / IP Ranges"]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Host header patterns allowed when accessing Mapigate over LAN (comma-separated)."})]}),e.jsxs("button",{type:"button",onClick:()=>c({...r,allowedHosts:u}),className:"px-2.5 py-1 rounded-lg bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-[11px] font-medium text-slate-300 hover:text-white flex items-center gap-1 transition-all cursor-pointer self-start sm:self-center shrink-0",title:"Reset to default private network ranges",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-400",children:"restart_alt"}),"Reset to Default"]})]}),e.jsx("input",{type:"text",placeholder:u,value:r.allowedHosts||"",onChange:t=>c({...r,allowedHosts:t.target.value}),className:"w-full bg-[#080B10] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-1 text-[10.5px] text-slate-500",children:[e.jsxs("span",{children:["Default: ",e.jsx("code",{className:"text-slate-400 font-mono",children:u})]}),e.jsx("span",{children:"Supports wildcards (e.g. 192.168.*, 10.*, *.local)"})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-[#0A0D14] border border-[#1E293B] flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("span",{className:"text-xs font-bold text-white flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-amber-400",children:"key"}),"Require API Key Authentication"]}),e.jsxs("p",{className:"text-[11px] text-slate-400",children:["When enabled, all incoming proxy requests to ",e.jsx("code",{className:"font-mono text-slate-300",children:"/v1/*"})," must supply an Authorization header matching an active Gateway Key below."]})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer shrink-0",children:[e.jsx("input",{type:"checkbox",checked:r.requireApiKey,onChange:t=>c({...r,requireApiKey:t.target.checked}),className:"sr-only peer"}),e.jsx("div",{className:"w-10 h-5.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4.5 after:w-4.5 after:transition-all peer-checked:bg-blue-600"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-purple-400",children:"router"}),"Global Upstream Proxy URL (Optional)"]}),e.jsx("input",{type:"text",placeholder:"e.g. http://127.0.0.1:7890 or socks5://127.0.0.1:1080",value:r.proxyUrl||"",onChange:t=>c({...r,proxyUrl:t.target.value}),className:"w-full bg-[#0A0D14] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Egress proxy used for routing outgoing requests to upstream AI model providers. Leave blank for direct connection."})]}),e.jsxs("div",{className:"space-y-2.5 pt-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200",children:"Custom Outbound Headers"}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Appended to all outgoing requests to upstream providers"})]}),e.jsxs("button",{type:"button",onClick:he,className:"px-3 py-1 rounded-lg bg-blue-600/10 border border-blue-500/30 text-blue-400 hover:bg-blue-600/20 text-xs font-medium flex items-center gap-1 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"add"}),"Add Header"]})]}),y.length===0?e.jsx("div",{className:"p-3 text-center rounded-xl bg-[#0A0D14] border border-[#1E293B] text-slate-500 text-xs",children:"No custom headers configured. Click “Add Header” to add custom headers."}):e.jsx("div",{className:"space-y-2",children:y.map(t=>e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsx("input",{type:"text",placeholder:"Header Name (e.g. X-Org-ID)",value:t.key,onChange:s=>X(t.id,"key",s.target.value),className:"flex-1 bg-transparent border-0 px-2 py-1 text-xs font-mono text-white placeholder-slate-600 focus:outline-none"}),e.jsx("span",{className:"text-slate-600 font-mono text-xs",children:":"}),e.jsx("input",{type:"text",placeholder:"Header Value",value:t.value,onChange:s=>X(t.id,"value",s.target.value),className:"flex-1 bg-transparent border-0 px-2 py-1 text-xs font-mono text-white placeholder-slate-600 focus:outline-none"}),e.jsx("button",{type:"button",onClick:()=>be(t.id),className:"p-1 text-slate-500 hover:text-rose-400 cursor-pointer transition-colors",title:"Remove header",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]},t.id))})]}),e.jsx("div",{className:"flex items-center justify-end pt-3 border-t border-[#1E293B]",children:e.jsx("button",{type:"submit",disabled:T,className:"px-5 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer",children:T?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving Configuration..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"save"}),"Save Configuration"]})})})]})]}),e.jsxs("div",{className:"w-full p-6 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-amber-400",children:"vpn_key"}),"Client Gateway API Keys (",v.length,")"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Authentication tokens used by Claude Code CLI, Cursor, and Cline to access Mapigate gateway securely."})]}),e.jsxs("button",{type:"button",onClick:()=>{b(null),h(!0)},className:"px-4 py-2 rounded-xl bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 text-xs font-semibold text-white flex items-center gap-1.5 transition-all cursor-pointer self-start sm:self-center shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Generate New Key"]})]}),re?e.jsxs("div",{className:"py-12 text-center text-slate-400 flex flex-col items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-2xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{className:"text-xs",children:"Loading API keys..."})]}):v.length===0?e.jsxs("div",{className:"py-12 text-center text-slate-400 flex flex-col items-center justify-center gap-2.5 bg-[#0A0D14] rounded-xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-slate-600",children:"key_off"}),e.jsx("p",{className:"text-xs font-semibold text-slate-300",children:"No Gateway API Keys Generated"}),e.jsx("p",{className:"text-[11px] text-slate-500 max-w-sm",children:"Generate a client API key to authenticate requests from external developer tools when “Require API Key” is enabled."})]}):e.jsx("div",{className:"w-full overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-xs text-slate-300 border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[#1E293B] text-[11px] text-slate-400 uppercase font-semibold",children:[e.jsx("th",{className:"py-3 px-3",children:"Name / Label"}),e.jsx("th",{className:"py-3 px-3",children:"API Token"}),e.jsx("th",{className:"py-3 px-3",children:"Created"}),e.jsx("th",{className:"py-3 px-3",children:"Last Used"}),e.jsx("th",{className:"py-3 px-3 text-center",children:"Status"}),e.jsx("th",{className:"py-3 px-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-[#1E293B]/60",children:v.map(t=>{const s=ne.has(t.id),a=ie===t.id;return e.jsxs("tr",{className:"hover:bg-[#141B2D]/40 transition-colors",children:[e.jsx("td",{className:"py-3.5 px-3 font-semibold text-white",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:t.name}),t.isSystem&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-500/15 text-blue-400 border border-blue-500/30 font-medium",children:"System"})]})}),e.jsx("td",{className:"py-3.5 px-3",children:e.jsxs("div",{className:"flex items-center gap-2 font-mono text-xs",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-lg border ${s?"bg-[#0A0D14] border-blue-500/30 text-blue-300 select-all":"bg-[#0A0D14] border-[#1E293B] text-slate-400 select-none"}`,children:s?t.key:Z(t.key)}),e.jsx("button",{type:"button",onClick:()=>me(t.id),className:"p-1 text-slate-400 hover:text-white transition-colors cursor-pointer",title:s?"Hide token":"Reveal token",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:s?"visibility_off":"visibility"})}),e.jsx("button",{type:"button",onClick:()=>ue(t.key,t.id),className:"p-1 text-slate-400 hover:text-white transition-colors cursor-pointer",title:"Copy API key",children:e.jsx("span",{className:`material-symbols-outlined text-[15px] ${a?"text-emerald-400":""}`,children:a?"check":"content_copy"})})]})}),e.jsx("td",{className:"py-3.5 px-3 text-slate-400 text-[11px]",children:new Date(t.createdAt).toLocaleDateString()}),e.jsx("td",{className:"py-3.5 px-3 text-slate-400 text-[11px] font-mono",children:t.lastUsedAt?new Date(t.lastUsedAt).toLocaleString():"Never"}),e.jsx("td",{className:"py-3.5 px-3 text-center",children:e.jsxs("label",{className:`relative inline-flex items-center ${t.isSystem?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[e.jsx("input",{type:"checkbox",checked:t.isActive,disabled:t.isSystem,onChange:()=>xe(t),className:"sr-only peer"}),e.jsx("div",{className:"w-8 h-4.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-all peer-checked:bg-emerald-500"})]})}),e.jsx("td",{className:"py-3.5 px-3 text-right",children:t.isSystem?e.jsx("span",{className:"text-[11px] text-slate-500 italic pr-2",children:"Protected"}):e.jsx("button",{type:"button",onClick:()=>C(t),className:"p-1.5 text-slate-400 hover:text-rose-400 hover:bg-rose-500/10 rounded-lg transition-colors cursor-pointer",title:"Delete API key",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})})]},t.id)})})]})})]}),q&&e.jsx(Ce,{isOpen:q,onClose:()=>{h(!1),b(null)},maxWidthClass:"max-w-xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-amber-400",children:"vpn_key"}),"Generate Gateway API Key"]}),e.jsx("button",{type:"button",onClick:()=>{h(!1),b(null)},className:"p-1 rounded text-slate-400 hover:text-white cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),N?e.jsxs("div",{className:"space-y-4 py-2 animate-rt-scale-in",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-emerald-500/10 border border-emerald-500/30 text-emerald-400 text-xs flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"check_circle"}),e.jsxs("span",{children:["API Key “",N.name,"” generated successfully!"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-slate-400 block",children:"Your Gateway Secret Token:"}),e.jsxs("div",{className:"flex items-center gap-2 p-2.5 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsx("span",{className:"font-mono text-xs text-white break-all flex-1 select-all",children:N.key}),e.jsxs("button",{type:"button",onClick:()=>S(N.key,"newlyCreated"),className:"px-2.5 py-1 rounded-lg bg-blue-600 hover:bg-blue-500 text-white text-xs font-semibold flex items-center gap-1 transition-all cursor-pointer shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:p==="newlyCreated"?"check":"content_copy"}),p==="newlyCreated"?"Copied":"Copy"]})]})]}),e.jsx("div",{className:"flex justify-end pt-2",children:e.jsx("button",{type:"button",onClick:()=>{h(!1),b(null)},className:"px-4 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] text-xs font-semibold text-white hover:border-slate-600 cursor-pointer",children:"Done"})})]}):e.jsxs("form",{onSubmit:de,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1",children:"Key Label / Client Name"}),e.jsx("input",{type:"text",placeholder:"e.g. Claude Code CLI, Cursor MacBook, Cline",value:G,onChange:t=>O(t.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3 py-2 text-xs text-white placeholder-slate-500 focus:outline-none",autoFocus:!0}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"A friendly label to identify which coding tool is using this key."})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:()=>h(!1),className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:$,className:"px-4 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer",children:$?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin",children:"progress_activity"}),"Generating..."]}):"Generate Key"})]})]})]})}),x&&e.jsx(ve,{isOpen:x!==null,title:"Delete Gateway API Key",message:`Are you sure you want to permanently delete API key "${x.name}" (${Z(x.key)})? Any client tool configured with this key will no longer be authorized.`,confirmText:"Delete Key",variant:"danger",onConfirm:pe,onCancel:()=>C(null)})]})};export{Pe as EndpointTab};