@tokenbuddy/tokenbuddy 1.0.23 → 1.0.25
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.
|
@@ -232,5 +232,5 @@ Please change the parent <Route path="${U}"> to <Route path="${U==="/"?"*":`${U}
|
|
|
232
232
|
*
|
|
233
233
|
* This source code is licensed under the ISC license.
|
|
234
234
|
* See the LICENSE file in the root directory of this source tree.
|
|
235
|
-
*/const rj=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Zr=qe("x",rj);class Jx extends Error{constructor(r,u,d){super(r);pd(this,"status");pd(this,"code");this.status=u,this.code=d}}async function yl(a){var r,u;const i=await fetch(a);if(!i.ok){const d=await i.json().catch(()=>({}));throw new Jx(((r=d.error)==null?void 0:r.message)??`${a} returned ${i.status}`,i.status,(u=d.error)==null?void 0:u.code)}return i.json()}async function Xa(a,i,r){var d,m;const u=await fetch(i,{method:a,headers:r?{"content-type":"application/json"}:void 0,body:r?JSON.stringify(r):void 0});if(!u.ok){const h=await u.json().catch(()=>({}));throw new Jx(((d=h.error)==null?void 0:d.message)??`${a} ${i} returned ${u.status}`,u.status,(m=h.error)==null?void 0:m.code)}return u.json()}function Wo(){return xl({queryKey:["ledger","inferences"],queryFn:()=>yl("/ledger/inferences"),refetchInterval:1e4})}function sj(){return xl({queryKey:["ledger","purchases"],queryFn:()=>yl("/ledger/purchases"),refetchInterval:1e4})}function Fx(){return xl({queryKey:["payments"],queryFn:()=>yl("/payments"),refetchInterval:1e4})}function Wx(){const a=is();return Qi({mutationFn:()=>Xa("POST","/payments/clawtip/activate"),onSuccess:()=>{a.invalidateQueries({queryKey:["payments"]})}})}function Px(){return Qi({mutationFn:()=>Xa("POST","/payments/clawtip/recharge")})}function Ix(){return xl({queryKey:["routing","strategy"],queryFn:()=>yl("/routing/strategy")})}function e0(){const a=is();return Qi({mutationFn:i=>Xa("PUT","/routing/strategy",i),onSuccess:()=>{a.invalidateQueries({queryKey:["routing","strategy"]})}})}function oj(a){const i=new URLSearchParams;for(const[r,u]of Object.entries(a))u!=null&&u!==""&&i.set(r,uj(u));return xl({queryKey:["routing","preview",i.toString()],queryFn:()=>yl(`/routing/preview?${i.toString()}`),enabled:!1})}function uj(a){return Array.isArray(a)?a.join(","):typeof a=="object"&&a!==null?Object.entries(a).map(([i,r])=>`${i}:${r}`).join(","):String(a)}function t0(){return xl({queryKey:["sellers"],queryFn:()=>yl("/sellers"),refetchInterval:3e4})}function xf(){return xl({queryKey:["models"],queryFn:()=>yl("/models"),refetchInterval:3e4})}function cj(){return xl({queryKey:["prewarm","focus-set"],queryFn:()=>yl("/v1.2/prewarm").then(a=>({ok:!0,focusSet:a.focusSet??[],source:"historical"}))})}async function Lo(a){const i=Array.isArray(a)?{models:a}:a;return Xa("PUT","/prewarm/focus-set",i)}function l0(){return xl({queryKey:["status"],queryFn:()=>yl("/status"),refetchInterval:5e3})}function jt({children:a,className:i=""}){return o.jsx("div",{className:["rounded-[var(--radius-xl)] border border-[var(--color-line-2)] bg-white shadow-[var(--shadow-panel)]",i].join(" "),children:a})}function rs({tone:a="lavender",children:i}){const r={lavender:"bg-[var(--color-lavender)] text-[var(--color-primary)]",green:"bg-[var(--color-success-soft)] text-[var(--color-success)]",amber:"bg-[var(--color-warning-soft)] text-[var(--color-warning)]",red:"bg-[var(--color-danger-soft)] text-[var(--color-danger)]",blue:"bg-[var(--color-tokens-soft)] text-[var(--color-tokens)]",gray:"bg-slate-100 text-slate-600"};return o.jsxs("span",{className:["inline-flex items-center gap-1.5 text-[0.78rem] font-medium px-2.5 py-0.5 rounded-[var(--radius-pill)]",r[a]??r.lavender].join(" "),children:[o.jsx("span",{className:"size-1.5 rounded-full bg-current"}),i]})}const Te="—",Ht=a=>a<10?`0${a}`:`${a}`;function pl(a,i={}){if(!Number.isFinite(a))return Te;const r=a;return i.compact===!1||r<1e4?Math.round(r).toLocaleString("en-US"):r<1e6?`${(r/1e3).toFixed(1)}K`:r<1e9?`${(r/1e6).toFixed(1)}M`:`${(r/1e9).toFixed(2)}B`}function $r(a,i,r={}){const u=r.separator??" / ";return`In ${pl(a,r)}${u}Out ${pl(i,r)}`}function dj(a,i){return!Number.isFinite(a)&&!Number.isFinite(i)?Te:`Input ${Ke(a)} / Output ${Ke(i)}`}function Ke(a){return Number.isFinite(a)?Math.round(a).toLocaleString("en-US"):Te}function st(a,i={}){if(!Number.isFinite(a))return Te;const r=Math.abs(a/1e6),u=i.digits??(i.ledger&&r<.01?6:4),d=`$${(a/1e6).toFixed(u)}`;return i.signed&&a>=0?`+${d}`:d}function fj(a,i,r={}){return!Number.isFinite(a)&&!Number.isFinite(i)?Te:`${st(a,r)} / ${st(i,r)}`}function xt(a){if(!Number.isFinite(a))return Te;const i=Math.max(0,Math.round(a));return i<1e3?`${i}ms`:`${(i/1e3).toFixed(2)}s`}function yf(a){return Number.isFinite(a)?`${Math.round(a*100)}%`:Te}function a0(a){if(!Number.isFinite(a))return Te;const i=Math.max(0,1-a);return yf(i)}function n0(a,i){return fj(a,i,{digits:4})}function Rl(a){return a?a.trim().toLowerCase().replaceAll("_"," "):Te}function Ka(a){const i=Rl(a);return i==="ok"||i==="online"||i==="configured"||i==="settled"||i==="completed"||i==="success"||i==="active"||i==="healthy"?"green":i==="fallback"||i==="pending"||i==="degraded"||i==="preview"?"amber":i==="failed"||i==="error"||i==="canceled"||i==="unhealthy"||i==="offline"?"red":i==="running"?"blue":"gray"}function Jr(a,i=32){return a?a.length>i?`${a.slice(0,i)}...`:a:Te}function mj(a){return a?a.startsWith("tbs-")&&a.length>10?a.slice(0,10):a.length<=12?a:a.slice(0,12):Te}function i0(a){if(!a)return Te;const i=new Date(a);if(Number.isNaN(i.getTime()))return Te;const r=new Date,u=i.getFullYear()===r.getFullYear()&&i.getMonth()===r.getMonth()&&i.getDate()===r.getDate(),d=`${Ht(i.getHours())}:${Ht(i.getMinutes())}`;return u?d:`${Ht(i.getMonth()+1)}/${Ht(i.getDate())} ${d}`}function vl(a){if(!a)return Te;const i=new Date(a);return Number.isNaN(i.getTime())?Te:`${i.getFullYear()}-${Ht(i.getMonth()+1)}-${Ht(i.getDate())} ${Ht(i.getHours())}:${Ht(i.getMinutes())}:${Ht(i.getSeconds())}`}function r0(a){if(!a)return Te;const i=new Date(a);return Number.isNaN(i.getTime())?Te:`${i.getFullYear()}/${Ht(i.getMonth()+1)}/${Ht(i.getDate())} ${Ht(i.getHours())}:${Ht(i.getMinutes())}:${Ht(i.getSeconds())}`}function hj(a){return i0(a)}function s0({inferences:a,modelsResponse:i,sellersResponse:r,previewPlan:u,activeModelId:d}){const m=xj(i,r),h=[...a].sort(jj),x=new Map,p=new Map;let v=0,g=0,b=0;for(const C of h){const A=C.modelId||Te,z=C.sellerKey||Te,B=fl(C.promptTokens)??0,U=fl(C.completionTokens)??0,G=B+U,K=fl(C.billedMicros)??0;v+=1,g+=G,b+=K;const L=x.get(A)??yj(A);L.entries.push(C),L.requestCount+=1,L.inputTokens+=B,L.outputTokens+=U,L.totalSpendMicros+=K,L.touchedSellers.add(z),L.sellerCounts.set(z,(L.sellerCounts.get(z)??0)+1),L.fallbackCount+=fl(C.fallbackCount)??0;const V=fl(C.ttftMs);V!==void 0&&(L.ttftTotal+=V,L.ttftCount+=1);const P=fl(C.durationMs);P!==void 0&&(L.durationTotal+=P,L.durationCount+=1),x.set(A,L);const J=p.get(z)??{requestCount:0,totalTokens:0};J.requestCount+=1,J.totalTokens+=G,p.set(z,J)}const E=Array.from(x.values()).map(C=>pj(C,p,m)).sort(Sj);if(E.length===0){const C=vj(d,u,m);C&&E.push(C)}return{rows:E,totalRequests:v,totalTokens:g,totalSpendMicros:b}}function pj(a,i,r){const u=a.entries[a.entries.length-1],d=(u==null?void 0:u.sellerKey)||Te,m=o0(d,r),h=a.sellerCounts.get(d)??0,x=i.get(d),p=r.modelsBySellerAndModel.get(`${d}\0${a.modelId}`);return{source:"ledger",modelId:a.modelId,currentSellerId:d,currentSellerName:m.name,currentSellerUrl:m.url,currentSellerStatus:m.status,currentSellerPaymentMethods:m.paymentMethods,sellerDiscount:m.discount,sellerServiceFee:m.serviceFee,sellerModelCount:m.modelCount,requestCount:a.requestCount,currentSellerModelRequests:h,currentSellerRequests:(x==null?void 0:x.requestCount)??h,inputTokens:a.inputTokens,outputTokens:a.outputTokens,totalTokens:a.inputTokens+a.outputTokens,currentSellerTokens:(x==null?void 0:x.totalTokens)??0,totalSpendMicros:a.totalSpendMicros,avgTtftMs:Qv(a.ttftTotal,a.ttftCount),avgDurationMs:Qv(a.durationTotal,a.durationCount),lastTtftMs:fl(u==null?void 0:u.ttftMs),lastDurationMs:fl(u==null?void 0:u.durationMs),selectedAt:bj(a.entries,d),lastSellerSwitchAt:gj(a.entries),lastAccessAt:u==null?void 0:u.createdAt,lastRequestId:u==null?void 0:u.requestId,lastStatus:u==null?void 0:u.status,routeReason:u==null?void 0:u.routeReason,upstreamStatus:u==null?void 0:u.upstreamStatus,fallbackCount:a.fallbackCount,falloverChain:(u==null?void 0:u.falloverChain)??[],touchedSellerCount:a.touchedSellers.size,inputPriceMicrosPer1m:p==null?void 0:p.inputPriceMicrosPer1m,outputPriceMicrosPer1m:p==null?void 0:p.outputPriceMicrosPer1m}}function vj(a,i,r){var p,v,g;const u=(p=i==null?void 0:i.routes)==null?void 0:p[0];if(!u||!a)return;const d=o0(u.seller.id,r,u),m=fl(u.metrics.ttftMs)??fl(u.metrics.avgLatencyMs),h=fl(u.metrics.avgInferenceMs),x=r.modelsBySellerAndModel.get(`${u.seller.id}\0${a}`);return{source:"preview",modelId:a,currentSellerId:u.seller.id,currentSellerName:d.name,currentSellerUrl:d.url,currentSellerStatus:d.status,currentSellerPaymentMethods:d.paymentMethods,sellerDiscount:d.discount,sellerServiceFee:d.serviceFee,sellerModelCount:d.modelCount,requestCount:0,currentSellerModelRequests:0,currentSellerRequests:0,inputTokens:0,outputTokens:0,totalTokens:0,currentSellerTokens:0,totalSpendMicros:0,avgTtftMs:m,avgDurationMs:h,lastTtftMs:m,lastDurationMs:h,routeReason:i.reason??i.sourceReason??"Preview route",fallbackCount:0,falloverChain:((v=i.routes)==null?void 0:v.map(b=>b.seller.id))??[],touchedSellerCount:((g=i.routes)==null?void 0:g.length)??1,inputPriceMicrosPer1m:x==null?void 0:x.inputPriceMicrosPer1m,outputPriceMicrosPer1m:x==null?void 0:x.outputPriceMicrosPer1m}}function xj(a,i){const r=new Map;for(const u of(a==null?void 0:a.data)??[]){const d=r.get(u.sellerId)??new Set;d.add(u.id),r.set(u.sellerId,d)}return{registryById:new Map(((i==null?void 0:i.sellers)??[]).map(u=>[u.id,u])),catalogById:new Map(((a==null?void 0:a.sellers)??[]).map(u=>[u.id,u])),modelsBySellerAndModel:new Map(((a==null?void 0:a.data)??[]).map(u=>[`${u.sellerId}\0${u.id}`,u])),modelCountsBySellerId:new Map(Array.from(r.entries()).map(([u,d])=>[u,d.size]))}}function yj(a){return{modelId:a,entries:[],sellerCounts:new Map,touchedSellers:new Set,requestCount:0,inputTokens:0,outputTokens:0,totalSpendMicros:0,ttftTotal:0,ttftCount:0,durationTotal:0,durationCount:0,fallbackCount:0}}function bj(a,i){var r;for(let u=a.length-1;u>=0;u-=1){const d=a[u];if(d.sellerKey!==i)return(r=a[u+1])==null?void 0:r.createdAt;if(u===0)return d.createdAt}}function gj(a){let i;for(let r=1;r<a.length;r+=1)a[r].sellerKey!==a[r-1].sellerKey&&(i=a[r].createdAt);return i}function o0(a,i,r){const u=i.catalogById.get(a),d=i.registryById.get(a),m=(r==null?void 0:r.metrics.discountRatio)??(u==null?void 0:u.discountRatio);return{name:Nj((r==null?void 0:r.seller.name)??(u==null?void 0:u.name)??(d==null?void 0:d.name)??a),url:(r==null?void 0:r.seller.url)??(u==null?void 0:u.url)??(d==null?void 0:d.url),status:(u==null?void 0:u.status)??(d==null?void 0:d.status)??Te,paymentMethods:(u==null?void 0:u.paymentMethods)??(d==null?void 0:d.paymentMethods)??(r==null?void 0:r.seller.paymentMethods)??[],discount:a0(m),serviceFee:yf(u==null?void 0:u.serviceFeeRatio),modelCount:(u==null?void 0:u.modelCount)??i.modelCountsBySellerId.get(a)}}function jj(a,i){return Ko(a.createdAt)-Ko(i.createdAt)}function Sj(a,i){return Ko(i.lastAccessAt)-Ko(a.lastAccessAt)}function Ko(a){if(!a)return 0;const i=new Date(a).getTime();return Number.isNaN(i)?0:i}function Qv(a,i){return i>0?a/i:void 0}function fl(a){return Number.isFinite(a)?a:void 0}function Nj(a){var i;return((i=a.split("(")[0])==null?void 0:i.trim())||a}function Yv(){var oe,F,fe,ye,Ee,me,D,$,re,be,ge,M,_,Z,I,X,ae;const[a,i]=j.useState(null),r=l0(),u=Ix(),d=Fx(),m=Wx(),h=Px(),x=d.refetch,p=m.reset,v=Wo(),g=t0(),b=xf(),E=((oe=v.data)==null?void 0:oe.inferences)??[],C=((F=d.data)==null?void 0:F.payments)??[],A=new Set((((fe=b.data)==null?void 0:fe.data)??[]).map(W=>W.id)).size,z=((ye=g.data)==null?void 0:ye.sellers.length)??((me=(Ee=b.data)==null?void 0:Ee.sellers)==null?void 0:me.length)??0,B=j.useMemo(()=>kj(E),[E]),U=j.useMemo(()=>Uj(C,E),[E,C]),G=j.useMemo(()=>s0({inferences:E,modelsResponse:b.data,sellersResponse:g.data}),[E,b.data,g.data]),L=C.some(W=>hl(W.method)==="clawtip"&&(W.enabled||d0(W.config,"walletConfigPresent")))||((D=m.data)==null?void 0:D.walletConfigPresent)===!0,V=(($=r.data)==null?void 0:$.status)==="running"&&!r.isError,P=new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),J=((re=u.data)==null?void 0:re.strategy.mode)??((be=r.data)==null?void 0:be.sellerRoutingMode)??Te,ee=((ge=u.data)==null?void 0:ge.strategy.scorer)??((M=r.data)==null?void 0:M.sellerRoutingScorer)??Te,le=()=>{i(null),m.reset(),h.reset()};return j.useEffect(()=>{if((a==null?void 0:a.kind)!=="activate"||hl(a.method)!=="clawtip"||L)return;const W=window.setInterval(()=>{x()},1500);return()=>window.clearInterval(W)},[L,a==null?void 0:a.kind,a==null?void 0:a.method,x]),j.useEffect(()=>{(a==null?void 0:a.kind)==="activate"&&hl(a.method)==="clawtip"&&L&&(i(null),p())},[L,a==null?void 0:a.kind,a==null?void 0:a.method,p]),o.jsxs("div",{className:"min-w-0 overflow-x-hidden space-y-3",children:[o.jsxs("section",{className:"grid grid-cols-2 gap-2.5 md:grid-cols-3 xl:grid-cols-6",children:[o.jsx(bi,{to:"/routing",icon:o.jsx(Vx,{className:"size-4"}),label:"Router",value:J,note:`${ee} scorer`,tone:"router"}),o.jsx(bi,{to:"/ledger",icon:o.jsx(Lv,{className:"size-4"}),label:"Today requests",value:Ke(B.todayRequestCount),note:`${Ke(B.totalRequestCount)} total`,tone:"requests"}),o.jsx(bi,{to:"/ledger",icon:o.jsx(Bi,{className:"size-4"}),label:"Spend today",value:st(B.todaySpendMicros,{digits:4}),note:`${st(B.totalSpendMicros,{digits:4})} total`,tone:"spend"}),o.jsx(bi,{to:"/ledger",icon:o.jsx(qv,{className:"size-4"}),label:"Today tokens",value:pl(B.todayInputTokens+B.todayOutputTokens),note:$r(B.todayInputTokens,B.todayOutputTokens),tone:"tokens"}),o.jsx(bi,{to:"/ledger",icon:o.jsx(Lv,{className:"size-4"}),label:"Total tokens",value:pl(B.inputTokens+B.outputTokens),note:$r(B.inputTokens,B.outputTokens),tone:"tokens"}),o.jsx(bi,{to:"/routing",icon:o.jsx(qv,{className:"size-4"}),label:"Models / Sellers",value:`${A}`,note:`${z} sellers`,tone:"inventory"})]}),o.jsx("section",{className:"grid min-w-0 gap-3",children:o.jsxs("div",{className:"min-w-0 space-y-3",children:[o.jsx(Mj,{rows:G.rows,totalRequests:G.totalRequests,totalTokens:G.totalTokens}),o.jsxs(jt,{className:"p-3.5",children:[o.jsx("div",{className:"flex items-start justify-between gap-4",children:o.jsx("div",{children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("h2",{className:"text-[1rem] font-semibold text-[var(--color-ink)]",children:"Payment management"}),o.jsx(rs,{tone:C.some(W=>W.enabled)?"green":"amber",children:C.some(W=>W.enabled)?"configured":"not configured"})]})})}),o.jsx("div",{className:"mt-2 min-w-0 overflow-hidden rounded-[10px] border border-[var(--color-line-2)] bg-white",children:U.map(W=>o.jsx(Cj,{...W,onActivate:()=>{i({kind:"activate",method:W.method}),W.method==="clawtip"&&m.mutate()},onRecharge:()=>{i({kind:"recharge",method:W.method}),W.method==="clawtip"&&h.mutate()}},W.method))})]}),o.jsxs(jt,{className:"p-3",children:[o.jsxs("div",{className:"mb-2 flex min-w-0 flex-col gap-2",children:[o.jsx("div",{className:"flex min-w-0 flex-wrap items-center justify-between gap-2",children:o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx(nj,{className:"size-4 shrink-0 text-[var(--color-purple)]"}),o.jsx("h2",{className:"truncate text-[1rem] font-semibold text-[var(--color-ink)]",children:"TokenUsage"})]})}),o.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2.5 gap-y-1 text-[0.7rem] text-[var(--color-muted)]",children:[B.modelUsage.map(W=>o.jsx(Oj,{model:W.model,color:W.color},W.model)),o.jsx(Gv,{label:"in"}),o.jsx(Gv,{label:"out",dashed:!0})]})]}),o.jsxs("div",{className:"grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_190px]",children:[o.jsx(Aj,{days:B.days,series:B.modelUsage}),o.jsxs("div",{className:"grid gap-3",children:[o.jsx(zj,{days:B.days,values:B.cost,total:st(B.weeklySpendMicros)}),o.jsx(Rj,{values:B.thirtyDaySpend,total:st(B.totalSpendMicros)})]})]})]})]})}),o.jsx(_j,{checkedAt:P,healthy:V,pid:(_=r.data)==null?void 0:_.pid,status:(Z=r.data)==null?void 0:Z.status,proxyPort:(I=r.data)==null?void 0:I.proxyPort,controlPort:(X=r.data)==null?void 0:X.controlPort,registryUrl:(ae=r.data)==null?void 0:ae.sellerRegistryUrl}),a?o.jsx(Ej,{modal:a,methods:U,qr:a.kind==="activate"?m.data:h.data,loading:a.kind==="activate"?m.isPending:h.isPending,error:a.kind==="activate"?m.error:h.error,onClose:le}):null]})}function Mj({rows:a,totalRequests:i,totalTokens:r}){var d;const u=a.slice(0,3);return o.jsxs(jt,{className:"overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--color-line-2)] px-3.5 py-3",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx(Vx,{className:"size-4 shrink-0 text-[var(--color-purple)]"}),o.jsx("h2",{className:"truncate text-[1rem] font-semibold text-[var(--color-ink)]",children:"Recent model routes"})]}),o.jsx(ns,{to:"/routing",className:"shrink-0 rounded-[8px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-2.5 py-1.5 text-[0.72rem] font-semibold text-[var(--color-purple)] transition hover:bg-white",children:"Details"})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-2 border-b border-[var(--color-line-2)] bg-[var(--color-page)]/55 px-3.5 py-2 sm:grid-cols-4",children:[o.jsx(Oo,{label:"Req",value:Ke(i)}),o.jsx(Oo,{label:"Token",value:pl(r)}),o.jsx(Oo,{label:"Models",value:Ke(a.length)}),o.jsx(Oo,{label:"Latest",value:i0((d=a[0])==null?void 0:d.lastAccessAt)})]}),u.length>0?o.jsx("div",{className:"divide-y divide-[var(--color-line-2)]",children:u.map(m=>o.jsx(wj,{row:m},`${m.modelId}-${m.currentSellerId}`))}):o.jsx("div",{className:"px-3.5 py-7 text-center text-[0.82rem] text-[var(--color-muted)]",children:"No model traffic yet."})]})}function Oo({label:a,value:i}){return o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[0.65rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:a}),o.jsx("div",{className:"mt-0.5 truncate font-mono text-[0.88rem] font-semibold text-[var(--color-ink)]",children:i})]})}function wj({row:a}){const i=a.lastSellerSwitchAt??a.selectedAt;return o.jsxs("div",{className:"grid min-w-0 gap-3 px-3.5 py-3 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,2fr)] lg:items-center",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",title:a.modelId,children:a.modelId}),o.jsxs("div",{className:"mt-0.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-[0.72rem] text-[var(--color-muted)]",children:[o.jsx("span",{className:"truncate",children:a.currentSellerName}),o.jsx("span",{className:"font-mono",children:a.currentSellerStatus})]})]}),o.jsxs("div",{className:"grid min-w-0 grid-cols-2 gap-1.5 sm:grid-cols-3 lg:grid-cols-6",children:[o.jsx(yi,{label:"In",value:pl(a.inputTokens),tone:"tokens",title:`Input tokens: ${Ke(a.inputTokens)}`}),o.jsx(yi,{label:"Out",value:pl(a.outputTokens),tone:"success",title:`Output tokens: ${Ke(a.outputTokens)}`}),o.jsx(yi,{label:"TTFT",value:xt(a.lastTtftMs??a.avgTtftMs),tone:"router",title:`Time to first token: ${xt(a.lastTtftMs??a.avgTtftMs)}`}),o.jsx(yi,{label:"Total",value:xt(a.lastDurationMs??a.avgDurationMs),tone:"slate",title:`Total inference duration: ${xt(a.lastDurationMs??a.avgDurationMs)}`}),o.jsx(yi,{label:"Disc",value:a.sellerDiscount,tone:"success",title:`Seller discount: ${a.sellerDiscount}`}),o.jsx(yi,{label:"Switch",value:hj(i),tone:"slate",title:`Last seller switch: ${vl(i)}`})]})]})}function yi({label:a,value:i,tone:r,title:u}){const d={router:"bg-[var(--color-lavender)] text-[var(--color-router)]",success:"bg-[var(--color-success-soft)] text-[var(--color-success)]",warning:"bg-[var(--color-warning-soft)] text-[var(--color-warning)]",tokens:"bg-[var(--color-tokens-soft)] text-[var(--color-tokens)]",slate:"bg-slate-50 text-slate-700"}[r];return o.jsxs("div",{className:["min-w-0 rounded-[var(--radius-md)] px-2 py-1",d].join(" "),title:u??`${a}: ${i}`,children:[o.jsx("div",{className:"text-[0.58rem] font-semibold uppercase tracking-wider opacity-70",children:a}),o.jsx("div",{className:"truncate font-mono text-[0.76rem] font-semibold",children:i})]})}function bi({to:a,icon:i,label:r,value:u,note:d,tone:m}){const h={router:{card:"border border-[var(--color-hairline-strong)] bg-white shadow-[var(--shadow-panel-strong)] hover:border-[var(--color-primary)] before:bg-[var(--color-router)]",icon:"bg-[var(--color-lavender)] text-[var(--color-router)]",label:"text-[var(--color-router)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-muted)]"},requests:{card:"border border-[var(--color-hairline)] bg-white shadow-[var(--shadow-panel)] hover:border-[var(--color-success)] before:bg-[var(--color-success)]",icon:"bg-[var(--color-success-soft)] text-[var(--color-success)]",label:"text-[var(--color-success)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-muted)]"},spend:{card:"border border-[var(--color-spend-border)] bg-[var(--color-spend-soft)] shadow-[var(--shadow-panel)] hover:border-[var(--color-spend)] before:bg-[var(--color-spend)]",icon:"bg-white text-[var(--color-spend)]",label:"text-[var(--color-spend)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-spend)]"},tokens:{card:"border border-[var(--color-tokens-border)] bg-[var(--color-tokens-soft)] shadow-[var(--shadow-panel)] hover:border-[var(--color-tokens)] before:bg-[var(--color-tokens)]",icon:"bg-white text-[var(--color-tokens)]",label:"text-[var(--color-tokens)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-tokens)]"},inventory:{card:"border border-[var(--color-inventory-border)] bg-[var(--color-inventory-soft)] shadow-[var(--shadow-panel)] hover:border-[var(--color-inventory)] before:bg-[var(--color-inventory)]",icon:"bg-white text-[var(--color-inventory)]",label:"text-[var(--color-inventory)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-inventory)]"}}[m];return o.jsxs(ns,{to:a,"aria-label":`Open ${r}`,className:["relative block min-h-[94px] overflow-hidden rounded-[var(--radius-xl)] p-3 transition before:absolute before:inset-y-0 before:left-0 before:w-1 hover:-translate-y-0.5 focus:outline-none focus:ring-2 focus:ring-[var(--color-primary)]",h.card].join(" "),children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("div",{className:`grid size-7 place-items-center rounded-[var(--radius-md)] ${h.icon}`,children:i}),o.jsx("span",{className:["text-right text-[0.66rem] font-semibold uppercase leading-3 tracking-[0.08em]",h.label].join(" "),children:r})]}),o.jsx("div",{className:["mt-2 text-[1.25rem] font-semibold leading-none tracking-tight",h.value].join(" "),children:u}),o.jsx("div",{className:["mt-1.5 truncate text-[0.72rem] font-medium",h.note].join(" "),children:d})]})}function Cj({name:a,method:i,balance:r,status:u,note:d,action:m,icon:h,balanceHidden:x,onActivate:p,onRecharge:v}){const g=u==="Bound",b=g&&x&&hl(i)==="clawtip";return o.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_74px_82px] items-center gap-2 border-b border-[var(--color-line-2)] px-2 py-2.5 last:border-b-0 sm:grid-cols-[minmax(0,1fr)_96px_92px] sm:gap-3 sm:px-3",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[o.jsx(Tj,{method:i,icon:h,bound:g}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-semibold text-[var(--color-ink)]",children:a}),d?o.jsx("div",{className:"mt-0.5 truncate text-[0.74rem] text-[var(--color-muted)]",children:d}):null]})})]}),b?o.jsxs("button",{type:"button",className:"inline-flex w-fit items-center gap-1 rounded-[7px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-2 py-1 font-mono text-[0.82rem] font-semibold text-[var(--color-purple)] transition hover:border-[var(--color-purple)] hover:bg-white active:translate-y-px",onClick:v,"aria-label":"Scan with JD app to view ClawTip wallet balance",title:"Scan with JD app to view wallet balance",children:[o.jsx(q2,{className:"size-3.5"}),"••••"]}):o.jsx("div",{className:"font-mono text-[0.9rem] font-semibold text-[var(--color-ink)]",children:r}),o.jsx("button",{className:"rounded-[8px] bg-[var(--color-purple)] px-2.5 py-1.5 text-[0.76rem] font-semibold text-white shadow-[0_8px_18px_rgba(124,61,240,0.16)] transition hover:bg-[#6e32dc] active:translate-y-px",onClick:g?v:p,"aria-label":m,title:`${m} ${a}`,children:m})]})}function Tj({method:a,icon:i,bound:r}){return hl(a)==="clawtip"?o.jsx("div",{className:"grid size-8 shrink-0 place-items-center rounded-[8px] border border-red-100 bg-[#e1251b] font-mono text-[0.72rem] font-black uppercase tracking-tight text-white shadow-[0_8px_18px_rgba(225,37,27,0.16)]","aria-label":"JD wallet",title:"JD wallet",children:"JD"}):o.jsx("div",{className:["grid size-8 shrink-0 place-items-center rounded-[8px] text-[0.8rem] font-bold",r?"bg-[var(--color-lavender)] text-[var(--color-purple)]":"bg-[var(--color-page)] text-[var(--color-muted)]"].join(" "),children:i})}function Ej({modal:a,methods:i,qr:r,loading:u,error:d,onClose:m}){const h=a.kind==="recharge",x=i.find(z=>z.method===a.method),p=h&&hl(a.method)==="clawtip",v=Td(x==null?void 0:x.config,"resourceUrl"),g=Td(x==null?void 0:x.config,"walletConfigPath"),b=Td(x==null?void 0:x.config,"orderNo"),E=(r==null?void 0:r.walletConfigPresent)===!0||d0(x==null?void 0:x.config,"walletConfigPresent"),C=!h&&!!(r!=null&&r.qrImageUrl)&&!E&&!d,A=(x==null?void 0:x.name)??u0(a.method);return o.jsx("div",{className:"fixed inset-0 z-30 grid place-items-center overflow-y-auto bg-[rgba(32,26,56,0.28)] px-4 py-6",children:o.jsxs("div",{className:"w-full max-w-[820px] rounded-[14px] bg-white p-5 shadow-[0_20px_56px_rgba(32,26,56,0.20)] sm:p-6",children:[o.jsxs("div",{className:"flex items-start justify-between gap-4",children:[o.jsxs("div",{children:[o.jsx("h3",{className:"text-[1.05rem] font-semibold text-[var(--color-ink)]",children:p?"ClawTip wallet QR":h?`Recharge ${A}`:`Activate ${A}`}),o.jsx("p",{className:"mt-1 text-[0.82rem] leading-5 text-[var(--color-muted)]",children:p?"Scan with JD app to view wallet balance or recharge.":h?"Load the fixed ClawTip recharge QR from static assets.":"Reuse the tb init ClawTip flow and wait for wallet binding."})]}),o.jsx("button",{className:"rounded-[7px] p-1.5 text-[var(--color-muted)] transition hover:bg-[var(--color-page)]",onClick:m,"aria-label":"Close payment modal",children:o.jsx(Zr,{className:"size-4"})})]}),o.jsxs("div",{className:"mt-5 flex flex-col gap-4",children:[o.jsx("div",{className:"mx-auto grid min-h-[320px] w-full max-w-[720px] place-items-center overflow-hidden rounded-[12px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-3 sm:min-h-[560px] sm:p-4",children:r!=null&&r.qrImageUrl?o.jsx("img",{className:"max-h-[72vh] w-full object-contain",src:r.qrImageUrl,alt:`${A} ${h?"recharge":"activation"} QR code`}):o.jsxs("div",{className:"flex flex-col items-center gap-2 px-3 text-center text-[0.78rem] leading-5 text-[var(--color-muted)]",children:[u?o.jsx(Et,{className:"size-5 animate-spin text-[var(--color-purple)]"}):null,o.jsx("span",{children:u?"Generating ClawTip QR...":"QR image unavailable"})]})}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[o.jsx(Lr,{label:"Method",value:A}),o.jsx(Lr,{label:"Wallet",value:E?"bound":"waiting",warn:!E}),r!=null&&r.orderNo||b?o.jsx(Lr,{label:"Order",value:(r==null?void 0:r.orderNo)??b??""}):null,r!=null&&r.walletConfigPath||g?o.jsx(Lr,{label:"Config",value:Hj((r==null?void 0:r.walletConfigPath)??g??"")}):null,r!=null&&r.clawtipId?o.jsx(Lr,{label:"Device",value:r.clawtipId}):null]}),d?o.jsx("div",{className:"rounded-[8px] border border-rose-100 bg-rose-50 px-3 py-2 text-[0.78rem] leading-5 text-rose-700",children:d instanceof Error?d.message:String(d)}):null,r!=null&&r.qrImageUrl?o.jsx("div",{className:"rounded-[8px] border border-emerald-100 bg-emerald-50 px-3 py-2 text-[0.78rem] leading-5 text-emerald-800",children:h?"Scan with JD app to view wallet balance or recharge.":o.jsxs("span",{className:"flex items-start gap-2",children:[C?o.jsx(Et,{className:"mt-0.5 size-4 shrink-0 animate-spin"}):null,o.jsx("span",{children:E?"Wallet bound. Closing...":"Scan with JD app. TokenBuddy is waiting for the local wallet config."})]})}):null,r!=null&&r.resourceUrl||v?o.jsx("a",{className:"block rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 py-2 font-mono text-[0.75rem] text-[var(--color-purple)] transition hover:bg-[var(--color-lavender)]",href:(r==null?void 0:r.resourceUrl)??v,target:"_blank",rel:"noreferrer",children:c0((r==null?void 0:r.resourceUrl)??v??"")}):!(r!=null&&r.qrImageUrl)&&!u&&!d?o.jsxs("div",{className:"rounded-[8px] border border-amber-100 bg-amber-50 px-3 py-2 text-[0.78rem] leading-5 text-amber-800",children:["No recharge link is available from the daemon. Run ",o.jsx("span",{className:"font-mono",children:"tb init"})," to bind this payment method."]}):null]})]})]})})}function Aj({days:a,series:i}){const d={top:14,right:18,bottom:26,left:26},m=i.flatMap(v=>[...v.input,...v.output]),h=Math.max(1,...m),x=v=>d.left+v*(680-d.left-d.right)/Math.max(1,a.length-1),p=v=>d.top+(1-v/h)*(150-d.top-d.bottom);return o.jsx("div",{className:"rounded-[var(--radius-lg)] border border-[var(--color-line-2)] bg-white px-3 py-1.5",children:o.jsxs("svg",{className:"h-[160px] w-full",viewBox:"0 0 680 150",role:"img","aria-label":"Daily model input and output usage lines",children:[[.25,.5,.75,1].map(v=>o.jsx("line",{x1:d.left,x2:680-d.right,y1:d.top+(1-v)*(150-d.top-d.bottom),y2:d.top+(1-v)*(150-d.top-d.bottom),stroke:"var(--color-chart-grid)",strokeWidth:"1"},v)),a.map((v,g)=>o.jsx("text",{x:x(g),y:143,textAnchor:"middle",className:"fill-[var(--color-muted)] text-[10px]",children:v},v)),i.map(v=>o.jsxs("g",{children:[o.jsx("path",{d:Fd(v.input.map((g,b)=>[x(b),p(g)])),fill:"none",stroke:v.color,strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"}),o.jsx("path",{d:Fd(v.output.map((g,b)=>[x(b),p(g)])),fill:"none",stroke:v.color,strokeWidth:"2.4",strokeDasharray:"5 5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.75"}),v.input.map((g,b)=>o.jsx("circle",{cx:x(b),cy:p(g),r:"2.7",fill:v.color},`${v.model}-input-${b}`)),v.output.map((g,b)=>o.jsx("circle",{cx:x(b),cy:p(g),r:"2.2",fill:"#fff",stroke:v.color,strokeWidth:"1.8"},`${v.model}-output-${b}`))]},v.model)),i.length===0?o.jsx("text",{x:680/2,y:150/2,textAnchor:"middle",className:"fill-[var(--color-muted)] text-[12px]",children:"No token usage yet"}):null]})})}function zj({days:a,values:i,total:r}){const m={top:10,right:8,bottom:16,left:8},h=Math.max(1,...i),x=v=>m.left+v*(190-m.left-m.right)/Math.max(1,i.length-1),p=v=>m.top+(1-v/h)*(72-m.top-m.bottom);return o.jsxs("div",{className:"rounded-[var(--radius-lg)] border border-[var(--color-line-2)] bg-white px-3 py-1.5",children:[o.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[o.jsx("span",{className:"text-[0.74rem] font-semibold text-[var(--color-ink)]",children:"Cost curve"}),o.jsx("span",{className:"font-mono text-[0.74rem] text-[var(--color-muted)]",children:r})]}),o.jsxs("svg",{className:"h-[66px] w-full",viewBox:"0 0 190 72",role:"img","aria-label":"Daily cost curve",children:[o.jsx("path",{d:Fd(i.map((v,g)=>[x(g),p(v)])),fill:"none",stroke:"var(--color-chart-cost)",strokeWidth:"3",strokeLinecap:"round"}),i.map((v,g)=>o.jsx("circle",{cx:x(g),cy:p(v),r:"2.4",fill:"var(--color-chart-cost)"},a[g]))]})]})}function Rj({values:a,total:i}){const r=Math.max(1,...a);return o.jsxs("div",{className:"rounded-[var(--radius-lg)] border border-[var(--color-line-2)] bg-white px-3 py-1.5",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[o.jsx("span",{className:"text-[0.74rem] font-semibold text-[var(--color-ink)]",children:"30 day spend"}),o.jsx("span",{className:"font-mono text-[0.74rem] text-[var(--color-muted)]",children:i})]}),o.jsx("div",{className:"flex h-[60px] items-end gap-1",children:a.map((u,d)=>o.jsx("span",{className:"flex-1 rounded-t-[3px] bg-[var(--color-tokens)]/75",style:{height:`${Math.max(8,u/r*100)}%`}},d))})]})}function Fd(a){return a.length===0?"":a.length===1?`M ${a[0][0]} ${a[0][1]}`:a.reduce((i,r,u)=>{if(u===0)return`M ${r[0]} ${r[1]}`;const d=a[u-1],m=(d[0]+r[0])/2;return`${i} C ${m} ${d[1]}, ${m} ${r[1]}, ${r[0]} ${r[1]}`},"")}function Oj({model:a,color:i}){return o.jsxs("span",{className:"inline-flex min-w-0 max-w-[9rem] items-center gap-1.5 rounded-[7px] border border-[var(--color-line-2)] bg-white px-1.5 py-0.5",title:a,children:[o.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{backgroundColor:i}}),o.jsx("span",{className:"truncate font-mono text-[0.68rem]",children:a})]})}function Gv({label:a,dashed:i=!1}){return o.jsxs("span",{className:"inline-flex items-center gap-1 rounded-[7px] border border-[var(--color-line-2)] bg-white px-1.5 py-0.5",children:[o.jsx("span",{className:["h-px w-4 border-t border-[var(--color-ink)]",i?"border-dashed":""].join(" ")}),o.jsx("span",{className:"font-mono text-[0.68rem]",children:a})]})}function Lr({label:a,value:i,warn:r=!1}){return o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[o.jsx("div",{className:"text-[0.78rem] text-[var(--color-muted)]",children:a}),o.jsx("div",{className:["font-mono text-[0.94rem] font-semibold",r?"text-amber-700":"text-[var(--color-ink)]"].join(" "),children:i})]})}function _j({checkedAt:a,healthy:i,pid:r,status:u,proxyPort:d,controlPort:m,registryUrl:h}){const x=[{icon:o.jsx(A2,{className:"size-3"}),label:"Daemon",value:r?`pid ${r}`:u??Te,tone:i?"green":"amber"},{icon:o.jsx(Y2,{className:"size-3"}),label:"Proxy",value:d?`:${d}`:Te,tone:"blue"},{icon:o.jsx(F2,{className:"size-3"}),label:"Control",value:m?`:${m}`:Te,tone:"router"},{icon:o.jsx(k2,{className:"size-3"}),label:"Registry",value:h?c0(h):Te,tone:"spend"}];return o.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 rounded-[var(--radius-xl)] border border-[var(--color-line-2)] bg-white px-3 py-2 shadow-[var(--shadow-chip)]",children:[o.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-[var(--radius-md)] border border-[var(--color-line-2)] bg-white px-2.5 py-1 text-[0.72rem] font-medium text-[var(--color-muted)]",children:[o.jsx(Z2,{className:"size-3.5"}),a]}),x.map(p=>o.jsx(Dj,{...p},p.label))]})}function Dj({icon:a,label:i,value:r,tone:u}){const d={green:"bg-[var(--color-success-soft)] text-[var(--color-success)]",blue:"bg-[var(--color-tokens-soft)] text-[var(--color-tokens)]",router:"bg-[var(--color-lavender)] text-[var(--color-router)]",spend:"bg-[var(--color-spend-soft)] text-[var(--color-spend)]",amber:"bg-[var(--color-warning-soft)] text-[var(--color-warning)]"}[u];return o.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-2 rounded-[var(--radius-md)] border border-[var(--color-line-2)] bg-white px-2.5 py-1",children:[o.jsx("span",{className:["grid size-5 shrink-0 place-items-center rounded-[var(--radius-sm)]",d].join(" "),children:a}),o.jsx("span",{className:"text-[0.72rem] font-semibold text-[var(--color-ink)]",children:i}),o.jsx("span",{className:"min-w-0 truncate font-mono text-[0.72rem] text-[var(--color-muted)]",children:r})]})}function kj(a){const i=Kv(7),r=Kv(30),u=Wd(new Date),d=new Set(i.map(L=>L.key)),m=new Map(r.map((L,V)=>[L.key,V])),h=["var(--color-chart-input)","var(--color-spend)","var(--color-chart-cost)","var(--color-inventory)"],x=new Map,p=i.map(()=>0),v=r.map(()=>0);let g=0,b=0,E=0,C=0,A=0,z=0,B=0,U=0,G=0;for(const L of a){const V=Wd(new Date(L.createdAt)),P=L.billedMicros??0,J=L.promptTokens??0,ee=L.completionTokens??0;G+=1,b+=P,C+=J,A+=ee,V===u&&(U+=1,g+=P,z+=J,B+=ee);const le=i.findIndex(F=>F.key===V);if(le>=0){E+=P,p[le]+=P/1e6;const F=x.get(L.modelId)??{input:i.map(()=>0),output:i.map(()=>0),total:0};F.input[le]+=J,F.output[le]+=ee,F.total+=J+ee,x.set(L.modelId,F)}else d.has(V)&&(E+=P);const oe=m.get(V);oe!==void 0&&(v[oe]+=P/1e6)}const K=Array.from(x.entries()).sort((L,V)=>V[1].total-L[1].total).slice(0,4).map(([L,V],P)=>({model:L,color:h[P%h.length],input:V.input,output:V.output}));return{days:i.map(L=>L.label),modelUsage:K,cost:p,thirtyDaySpend:v,todaySpendMicros:g,totalSpendMicros:b,weeklySpendMicros:E,inputTokens:C,outputTokens:A,todayInputTokens:z,todayOutputTokens:B,todayRequestCount:U,totalRequestCount:G}}function Uj(a,i){const r=new Map;for(const u of[...i].sort((d,m)=>d.createdAt.localeCompare(m.createdAt)))!u.paymentMethod||u.balanceSnapshotMicros===void 0||r.set(hl(u.paymentMethod),u.balanceSnapshotMicros);return[...a].filter(u=>hl(u.method)!=="mock").sort((u,d)=>Number(d.isDefault)-Number(u.isDefault)||u.method.localeCompare(d.method)).map(u=>{const d=hl(u.method),m=u.enabled||!!(u.config&&Object.keys(u.config).length>0),h=r.get(d),x=d==="clawtip";return{name:u0(u.method),method:u.method,balance:x?"••••":st(h),status:u.enabled?"Bound":"Available",note:m?u.isDefault?"Default wallet":"Configured":"Not bound",action:u.enabled?"Recharge":"Activate",icon:Bj(u.method),balanceHidden:x,config:u.config}})}function Kv(a){const i=[],r=new Intl.DateTimeFormat("en",{weekday:"short"});for(let u=a-1;u>=0;u-=1){const d=new Date;d.setHours(0,0,0,0),d.setDate(d.getDate()-u),i.push({key:Wd(d),label:r.format(d)})}return i}function Wd(a){if(Number.isNaN(a.getTime()))return"";const i=a.getFullYear(),r=String(a.getMonth()+1).padStart(2,"0"),u=String(a.getDate()).padStart(2,"0");return`${i}-${r}-${u}`}function u0(a){const i=hl(a);return i==="clawtip"?"ClawTip":i==="alipay-agent"?"Alipay Agent Payment":i==="wechat-pay"?"WeChat Pay":i==="coinbase-smart-wallet"?"Coinbase Smart Wallet":a.split(/[-_\s]+/).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function Bj(a){const i=hl(a);return i==="clawtip"?"C":i==="wechat-pay"?"W":i==="alipay-agent"?"A":i.charAt(0).toUpperCase()||"P"}function hl(a){return a.trim().toLowerCase()}function c0(a){try{const i=new URL(a),r=i.pathname==="/"?"":i.pathname;return`${i.host}${r}`.slice(0,34)}catch{return a.length>34?`${a.slice(0,31)}...`:a}}function Hj(a){const i=a.split("/");return i.length<=3?a:`.../${i.slice(-2).join("/")}`}function Td(a,i){const r=a==null?void 0:a[i];return typeof r=="string"&&r.length>0?r:void 0}function d0(a,i){return(a==null?void 0:a[i])===!0}const Lj=[{value:"fullAuto",label:"Full auto",help:"Choose from all compatible sellers for each model."},{value:"fixedSet",label:"Fixed set",help:"Choose automatically within your selected seller set."},{value:"fixed",label:"Fixed",help:"Pin one fixed seller for each model."}],qj=[{value:"balanced",label:"Balanced",help:"Balance reliability, speed, and cost."},{value:"speed",label:"Speed first",help:"Prioritize low TTFT and high throughput."},{value:"discount",label:"Cost first",help:"Prioritize discount and available balance."}];function Qj(){var ge,M,_,Z,I;const a=Ix(),i=e0(),r=t0(),u=xf(),d=cj(),m=Wo(),[h,x]=j.useState({mode:"fullAuto",scorer:"balanced"}),[p,v]=j.useState([]),[g,b]=j.useState(""),[E,C]=j.useState(null),[A,z]=j.useState(null),B=oj({...h,modelId:g}),U=u.data,G=((ge=r.data)==null?void 0:ge.sellers)??[],K=((M=d.data)==null?void 0:M.focusSet)??[],L=j.useMemo(()=>Ij((U==null?void 0:U.data)??[],K),[K,U==null?void 0:U.data]),V=tS(B.data),P=j.useMemo(()=>eS(G,U,(V==null?void 0:V.routes)??[]),[U,V==null?void 0:V.routes,G]),J=j.useMemo(()=>p.map(X=>L.find(ae=>ae.id===X)).filter(p0),[L,p]),ee=h.sellerIds??[],le=h.fixedByModel??{},oe=J.length,F=J.filter(X=>h.mode==="fixed"?!!le[X.id]:h.mode==="fixedSet"?ee.length>0:!0).length,fe=j.useMemo(()=>{var X;return s0({inferences:((X=m.data)==null?void 0:X.inferences)??[],modelsResponse:U,sellersResponse:r.data,previewPlan:V,activeModelId:g})},[g,(_=m.data)==null?void 0:_.inferences,U,V,r.data]);j.useEffect(()=>{var X;(X=a.data)!=null&&X.strategy&&x(a.data.strategy)},[(Z=a.data)==null?void 0:Z.strategy]),j.useEffect(()=>{if(p.length>0||L.length===0)return;const X=K.filter(W=>L.some(Ae=>Ae.id===W)),ae=X.length>0?X:L.slice(0,2).map(W=>W.id);v(ae),b(ae[0]??"")},[K,L,p.length]),j.useEffect(()=>{!g||p.includes(g)||b(p[0]??"")},[g,p]),j.useEffect(()=>{g&&B.refetch()},[g,h.mode,h.scorer,h.sellerId,(I=h.sellerIds)==null?void 0:I.join(","),rS(h.fixedByModel)]);async function ye(X){x(X),C(null);try{await i.mutateAsync(X)}catch(ae){C(ae instanceof Error?ae.message:String(ae))}}function Ee(X){v(ae=>{if(ae.includes(X)){const Ae=ae.filter(Oe=>Oe!==X);return g===X&&b(Ae[0]??""),Lo(Ae).catch(()=>{}),Ae}b(X);const W=[...ae,X];return Lo(W).catch(()=>{}),W})}function me(X){v(ae=>{const W=ae.filter(Ae=>Ae!==X);return g===X&&b(W[0]??""),Lo(W).catch(()=>{}),W})}function D(X){const ae=lS({...h,mode:X},P,g);ye(ae)}function $(X){ye({...h,scorer:X})}function re(X,ae){const W=h.sellerIds??[],Ae=W.includes(ae)?W.filter(Oe=>Oe!==ae):[...W,ae];ye({...h,mode:"fixedSet",sellerIds:Ae,sellerId:void 0})}function be(X,ae){const W={...h.fixedByModel??{},[X]:ae};ye({...h,mode:"fixed",fixedByModel:W,sellerId:void 0,sellerIds:void 0}),b(X),z(null)}return o.jsxs("div",{className:"space-y-5",children:[o.jsx("section",{children:o.jsxs(jt,{className:"p-4",children:[o.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--color-line-2)] px-4 py-3",children:[o.jsx("div",{className:"min-w-0 flex-1",children:o.jsx("div",{className:"text-[0.78rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Models"})}),o.jsxs("button",{type:"button",onClick:()=>z({kind:"models"}),className:"inline-flex items-center gap-1.5 rounded-[8px] bg-[var(--color-purple)] px-3 py-1.5 text-[0.78rem] font-semibold text-white hover:bg-[var(--color-purple-2)]","aria-label":"Add",title:"Add models","data-testid":"routing-add-models",children:[o.jsx(Jd,{size:14}),"Add"]})]}),o.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[J.map(X=>{const ae=g===X.id,W=X.sellerCount>0;return o.jsxs("div",{className:["inline-flex min-h-9 items-center gap-2 rounded-[9px] border px-3 py-1.5 transition-colors",W?"border-[var(--color-lavender-2)] bg-[var(--color-lavender)] text-[var(--color-purple)] hover:border-[var(--color-purple)] hover:bg-white":"border-rose-200 bg-rose-50 text-rose-700 hover:bg-white",ae?"ring-2 ring-[var(--color-lavender-2)] ring-offset-1 ring-offset-white":""].join(" "),children:[o.jsx("button",{type:"button",onClick:()=>b(X.id),className:"flex items-center text-left",children:o.jsx("span",{className:["font-mono text-[0.82rem] font-semibold",W?"text-[var(--color-purple)]":"text-rose-700"].join(" "),children:X.id})}),o.jsx("button",{type:"button",onClick:()=>me(X.id),className:["inline-flex size-5 items-center justify-center rounded-[6px]",W?"text-[var(--color-purple)]/70 hover:bg-white hover:text-[var(--color-purple)]":"text-rose-700/70 hover:bg-white hover:text-rose-700"].join(" "),"aria-label":`Remove ${X.id}`,children:o.jsx($x,{size:12})})]},X.id)}),J.length===0?o.jsx("div",{className:"px-4 py-8 text-center text-[0.88rem] text-[var(--color-muted)]",children:"No models yet. Click Add to add common models."}):null,d.isError?o.jsx("div",{className:"px-3 py-2 text-[0.82rem] text-amber-700",children:"Focus models could not be saved."}):null]})]})}),o.jsx("section",{children:o.jsx(jt,{className:"overflow-hidden",children:o.jsxs("div",{className:"p-5",children:[o.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[o.jsx("div",{className:"text-[0.78rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Strategy"}),o.jsxs("div",{className:"text-[0.78rem] text-[var(--color-muted)]",children:[F,"/",Math.max(oe,1)," configured"]})]}),a.isLoading||r.isLoading||u.isLoading?o.jsx("div",{className:"mb-3 rounded-[10px] border border-[var(--color-line-2)] bg-white px-3 py-2 text-[0.82rem] text-[var(--color-muted)]",children:"Loading routing data..."}):null,a.isError||r.isError||u.isError?o.jsx("div",{className:"mb-3 rounded-[10px] border border-rose-100 bg-rose-50 px-3 py-2 text-[0.82rem] text-rose-700",children:"Some routing data could not be loaded. Check that tb-proxyd is running."}):null,E?o.jsx("div",{className:"mb-3 rounded-[10px] border border-rose-100 bg-rose-50 px-3 py-2 text-[0.82rem] text-rose-700",children:E}):null,o.jsx("div",{className:"mb-5 grid grid-cols-1 gap-2 md:grid-cols-3",children:Lj.map(X=>o.jsx(Fj,{active:h.mode===X.value,title:X.label,description:X.help,onClick:()=>D(X.value)},X.value))}),o.jsx("div",{className:"rounded-[14px] border border-[var(--color-line-2)] bg-white p-4",children:o.jsx(Yj,{mode:h.mode,scorer:h.scorer,selectedModels:J,fixedSetSellers:ee,fixedByModel:le,sellers:P,activeModelId:g,onScorerChange:$,onOpenSellerPicker:z,onToggleFixedSetSeller:re})})]})})}),o.jsx(Gj,{summary:fe}),(A==null?void 0:A.kind)==="models"?o.jsx($j,{models:L,selectedModelIds:p,onClose:()=>z(null),onToggle:Ee}):null,(A==null?void 0:A.kind)==="sellers"?o.jsx(Jj,{modelId:A.modelId,selection:A.selection,selectedSellerIds:A.selection==="single"?le[A.modelId]?[le[A.modelId]]:[]:ee,scorer:h.scorer,sellers:P,onClose:()=>z(null),onToggle:X=>{A.selection==="single"?be(A.modelId,X):re(A.modelId,X)}}):null]})}function Yj({mode:a,scorer:i,selectedModels:r,fixedSetSellers:u,fixedByModel:d,sellers:m,activeModelId:h,onScorerChange:x,onOpenSellerPicker:p,onToggleFixedSetSeller:v}){var E;const g=oS(r,h),b=(E=g[0])==null?void 0:E.id;return a==="fullAuto"?o.jsx("div",{children:o.jsx(Xv,{scorer:i,onChange:x})}):a==="fixedSet"?o.jsxs("div",{className:"space-y-3",children:[o.jsx(Xv,{scorer:i,onChange:x}),o.jsx(Vj,{modelId:b,sellers:m,sellerIds:u,onChoose:C=>p({kind:"sellers",modelId:C,selection:"multi"}),onRemove:C=>{b&&v(b,C)}})]}):o.jsx("div",{className:"space-y-3",children:o.jsx(Zj,{selectedModels:g,activeModelId:h,resolveValue:C=>iS(d[C],m),onChoose:C=>p({kind:"sellers",modelId:C,selection:"single"})})})}function Gj({summary:a}){return o.jsx("section",{children:o.jsxs(jt,{className:"overflow-hidden",children:[o.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-[var(--color-line-2)] px-4 py-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[0.78rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Model route activity"}),o.jsxs("div",{className:"mt-0.5 font-mono text-[0.74rem] text-[var(--color-muted)]",children:[Ke(a.totalRequests)," requests · ",pl(a.totalTokens)," tokens · ",st(a.totalSpendMicros,{digits:4})]})]}),o.jsxs("div",{className:"rounded-[8px] border border-[var(--color-line-2)] bg-white px-2.5 py-1.5 font-mono text-[0.74rem] text-[var(--color-muted)]",children:[Ke(a.rows.length)," models"]})]}),o.jsxs("div",{className:"divide-y divide-[var(--color-line-2)] bg-white xl:hidden",children:[a.rows.map(i=>o.jsx(Kj,{row:i},`${i.source}-${i.modelId}-${i.currentSellerId}`)),a.rows.length===0?o.jsx("div",{className:"px-4 py-8 text-center text-[var(--color-muted)]",children:"No model traffic yet."}):null]}),o.jsx("div",{className:"hidden min-w-0 max-w-full overflow-x-auto xl:block",children:o.jsxs("table",{className:"w-full min-w-[1180px] border-collapse text-left text-[0.82rem]",children:[o.jsx("thead",{className:"bg-white/70 text-[0.68rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"px-4 py-2.5 font-semibold",children:"MODEL"}),o.jsx("th",{className:"px-4 py-2.5 font-semibold",children:"NODE"}),o.jsx("th",{className:"px-4 py-2.5 text-right font-semibold",children:"REQ"}),o.jsx("th",{className:"px-4 py-2.5 text-right font-semibold",children:"DISC"}),o.jsx("th",{className:"px-4 py-2.5 text-right font-semibold",children:"TTFT"}),o.jsx("th",{className:"px-4 py-2.5 text-right font-semibold",children:"TOKEN"}),o.jsx("th",{className:"px-4 py-2.5 font-semibold",children:"SWITCH"}),o.jsx("th",{className:"px-4 py-2.5 font-semibold",children:"TIME"})]})}),o.jsxs("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:[a.rows.map(i=>o.jsx(Xj,{row:i},`${i.source}-${i.modelId}-${i.currentSellerId}`)),a.rows.length===0?o.jsx("tr",{children:o.jsx("td",{colSpan:8,className:"px-4 py-8 text-center text-[var(--color-muted)]",children:"No model traffic yet."})}):null]})]})})]})})}function Kj({row:a}){return o.jsxs("article",{className:"px-4 py-3",children:[o.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-mono text-[0.92rem] font-semibold text-[var(--color-ink)]",title:a.modelId,children:a.modelId}),o.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[o.jsx(Ni,{tone:a.source==="ledger"?"green":"amber",children:a.source}),a.lastStatus?o.jsx(Ni,{tone:Ka(a.lastStatus),children:Rl(a.lastStatus)}):null,a.upstreamStatus?o.jsx(Ni,{tone:Ka(a.upstreamStatus),children:Rl(a.upstreamStatus)}):null]}),a.routeReason?o.jsx("div",{className:"mt-1 truncate text-[0.72rem] text-[var(--color-muted)]",title:a.routeReason,children:a.routeReason}):null]}),o.jsxs("div",{className:"min-w-0 text-right",children:[o.jsx("div",{className:"truncate font-semibold text-[var(--color-purple)]",title:a.currentSellerId,children:a.currentSellerName}),o.jsx("div",{className:"mt-0.5 truncate font-mono text-[0.72rem] text-[var(--color-muted)]",title:a.currentSellerId,children:a.currentSellerId}),o.jsx("div",{className:"mt-1 text-[0.72rem] text-[var(--color-muted)]",children:a.currentSellerPaymentMethods.length>0?a.currentSellerPaymentMethods.join(", "):Te})]})]}),o.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-3",children:[o.jsx(gi,{label:"Node stats",value:Ke(a.currentSellerRequests),detail:`${Ke(a.sellerModelCount)} models · ${Ke(a.touchedSellerCount)} nodes`}),o.jsx(gi,{label:"Discount",value:a.sellerDiscount,detail:`fee ${a.sellerServiceFee} · ${n0(a.inputPriceMicrosPer1m,a.outputPriceMicrosPer1m)}`,tone:"green"}),o.jsx(gi,{label:"Speed",value:xt(a.lastTtftMs??a.avgTtftMs),detail:`${xt(a.lastDurationMs??a.avgDurationMs)} total`}),o.jsx(gi,{label:"Tokens",value:pl(a.totalTokens),detail:`${$r(a.inputTokens,a.outputTokens)} · ${st(a.totalSpendMicros,{digits:4})}`}),o.jsx(gi,{label:"Switch",value:vl(a.selectedAt),compact:!0}),o.jsx(gi,{label:"Last access",value:vl(a.lastAccessAt),detail:a.lastRequestId??void 0,compact:!0})]})]})}function gi({label:a,value:i,detail:r,tone:u="default",compact:d=!1}){return o.jsxs("div",{className:"min-w-0 rounded-[9px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-2.5 py-2",children:[o.jsx("div",{className:"text-[0.62rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:a}),o.jsx("div",{className:["mt-1 min-w-0 truncate font-mono font-semibold",d?"text-[0.72rem]":"text-[0.88rem]",u==="green"?"text-emerald-700":"text-[var(--color-ink)]"].join(" "),title:i,children:i}),r?o.jsx("div",{className:"mt-0.5 truncate text-[0.68rem] text-[var(--color-muted)]",title:r,children:r}):null]})}function Xj({row:a}){return o.jsxs("tr",{className:"align-top transition hover:bg-[var(--color-lavender)]/25",children:[o.jsxs("td",{className:"px-4 py-3",children:[o.jsx("div",{className:"max-w-[230px] truncate font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",title:a.modelId,children:a.modelId}),o.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[o.jsx(Ni,{tone:a.source==="ledger"?"green":"amber",children:a.source}),a.lastStatus?o.jsx(Ni,{tone:Ka(a.lastStatus),children:Rl(a.lastStatus)}):null,a.upstreamStatus?o.jsx(Ni,{tone:Ka(a.upstreamStatus),children:Rl(a.upstreamStatus)}):null]}),a.routeReason?o.jsx("div",{className:"mt-1 max-w-[240px] truncate text-[0.72rem] text-[var(--color-muted)]",title:a.routeReason,children:a.routeReason}):null]}),o.jsxs("td",{className:"px-4 py-3",children:[o.jsx("div",{className:"max-w-[210px] truncate font-semibold text-[var(--color-purple)]",title:a.currentSellerId,children:a.currentSellerName}),o.jsx("div",{className:"mt-0.5 max-w-[210px] truncate font-mono text-[0.72rem] text-[var(--color-muted)]",title:a.currentSellerId,children:mj(a.currentSellerId)}),o.jsx("div",{className:"mt-1 text-[0.72rem] text-[var(--color-muted)]",children:a.currentSellerPaymentMethods.length>0?a.currentSellerPaymentMethods.join(", "):Te})]}),o.jsxs("td",{className:"px-4 py-3 text-right",children:[o.jsx("div",{className:"font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",children:Ke(a.currentSellerRequests)}),o.jsx("div",{className:"mt-0.5 text-[0.72rem] text-[var(--color-muted)]",children:"node requests"}),o.jsxs("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:[Ke(a.sellerModelCount)," models · ",Ke(a.touchedSellerCount)," nodes"]})]}),o.jsxs("td",{className:"px-4 py-3 text-right",children:[o.jsx("div",{className:"font-mono text-[0.84rem] font-semibold text-emerald-700",children:a.sellerDiscount}),o.jsxs("div",{className:"mt-0.5 text-[0.72rem] text-[var(--color-muted)]",children:["fee ",a.sellerServiceFee]}),o.jsx("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:n0(a.inputPriceMicrosPer1m,a.outputPriceMicrosPer1m)})]}),o.jsxs("td",{className:"px-4 py-3 text-right",children:[o.jsx("div",{className:"font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",children:xt(a.lastTtftMs??a.avgTtftMs)}),o.jsx("div",{className:"mt-0.5 text-[0.72rem] text-[var(--color-muted)]",children:"TTFT"}),o.jsxs("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:[xt(a.lastDurationMs??a.avgDurationMs)," total"]})]}),o.jsxs("td",{className:"px-4 py-3 text-right",children:[o.jsx("div",{className:"font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",children:pl(a.totalTokens)}),o.jsx("div",{className:"mt-0.5 text-[0.72rem] text-[var(--color-muted)]",children:$r(a.inputTokens,a.outputTokens)}),o.jsx("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:st(a.totalSpendMicros,{digits:4})})]}),o.jsx("td",{className:"whitespace-nowrap px-4 py-3 font-mono text-[0.74rem] text-[var(--color-muted)]",children:vl(a.selectedAt)}),o.jsxs("td",{className:"whitespace-nowrap px-4 py-3",children:[o.jsx("div",{className:"font-mono text-[0.74rem] text-[var(--color-muted)]",children:vl(a.lastAccessAt)}),a.lastRequestId?o.jsx("div",{className:"mt-1 max-w-[160px] truncate font-mono text-[0.68rem] text-[var(--color-faint)]",title:a.lastRequestId,children:a.lastRequestId}):null]})]})}function Ni({tone:a,children:i}){const r={green:"bg-emerald-50 text-emerald-700",amber:"bg-amber-50 text-amber-700",red:"bg-rose-50 text-rose-700",blue:"bg-blue-50 text-blue-700",gray:"bg-slate-100 text-slate-600"}[a];return o.jsx("span",{className:["rounded-full px-2 py-0.5 text-[0.66rem] font-semibold uppercase",r].join(" "),children:i})}function Xv({scorer:a,onChange:i}){return o.jsx("div",{className:"rounded-[12px] border border-[var(--color-line-2)] bg-white p-1.5",children:o.jsx("div",{className:"grid grid-cols-1 gap-1.5 md:grid-cols-3",children:qj.map(r=>o.jsxs("button",{type:"button",onClick:()=>i(r.value),"aria-label":`Routing scorer: ${r.label}`,className:["flex min-h-14 items-center gap-2 rounded-[9px] px-3 py-2 text-left transition-colors",a===r.value?"bg-[var(--color-lavender)] text-[var(--color-ink)]":"text-[var(--color-muted)] hover:bg-[var(--color-lavender)]/40"].join(" "),children:[o.jsx(Po,{active:a===r.value,fixed:!0}),o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block text-[0.86rem] font-semibold",children:r.label}),o.jsx("span",{className:"block truncate text-[0.72rem] text-[var(--color-muted)]",children:r.help})]})]},r.value))})})}function Vj({modelId:a,sellers:i,sellerIds:r,onChoose:u,onRemove:d}){if(!a)return o.jsx("div",{className:"rounded-[12px] border border-[var(--color-line-2)] bg-white px-3 py-4 text-[0.86rem] text-[var(--color-muted)]",children:"Add models before configuring a seller set."});const m=r.map(h=>i.find(x=>x.id===h)).filter(p0);return o.jsxs("div",{className:"overflow-hidden rounded-[12px] border border-[var(--color-line-2)] bg-white",children:[o.jsxs("div",{className:"flex flex-wrap items-center gap-3 border-b border-[var(--color-line-2)] bg-white/70 px-3 py-2.5",children:[o.jsx("div",{className:"min-w-0 flex-1",children:o.jsx("div",{className:"text-[0.78rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Sellers"})}),o.jsx("button",{type:"button",onClick:()=>u(a),className:"rounded-[8px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-3 py-1.5 text-[0.78rem] font-semibold text-[var(--color-purple)] hover:bg-white","aria-label":`Add sellers to fixed set for ${a}`,children:"Add sellers"})]}),m.length>0?o.jsx("div",{className:"min-w-0 max-w-full overflow-x-auto",children:o.jsxs("table",{className:"w-full border-collapse text-left text-[0.82rem]",children:[o.jsx("thead",{className:"bg-white/70 text-[0.68rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Seller"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Discount"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Markup fee"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Payment"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"TTFT"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Tok/s"}),o.jsx("th",{className:"w-10 px-3 py-2 font-semibold"})]})}),o.jsx("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:m.map(h=>o.jsxs("tr",{children:[o.jsx("td",{className:"px-3 py-2.5 font-semibold text-[var(--color-ink)]",children:h.name}),o.jsxs("td",{className:"whitespace-nowrap px-3 py-2.5 text-right",children:[o.jsx("div",{className:"font-mono font-semibold text-[var(--color-purple)]",children:h.discount}),o.jsx("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:h.price})]}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:h.markupFee}),o.jsx("td",{className:"px-3 py-2.5 text-[var(--color-muted)]",children:h.paymentMethods.join(", ")}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:xt(h.latencyMs)}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:Ke(h.tokensPerSecond)}),o.jsx("td",{className:"px-3 py-2.5 text-right",children:o.jsx("button",{type:"button",onClick:()=>d(h.id),className:"inline-flex size-7 items-center justify-center rounded-[7px] text-[var(--color-muted)] hover:bg-rose-50 hover:text-rose-700","aria-label":`Remove ${h.name}`,children:o.jsx($x,{size:14})})})]},h.id))})]})}):o.jsx("div",{className:"px-3 py-8 text-center text-[0.86rem] text-[var(--color-muted)]",children:"No sellers yet. Click Add sellers to build the fixed set."})]})}function Zj({selectedModels:a,activeModelId:i,resolveValue:r,onChoose:u}){return a.length===0?o.jsx("div",{className:"rounded-[12px] border border-[var(--color-line-2)] bg-white px-3 py-4 text-[0.86rem] text-[var(--color-muted)]",children:"Add models before configuring sellers."}):o.jsx("div",{className:"divide-y divide-[var(--color-line-2)] rounded-[12px] border border-[var(--color-line-2)] bg-white",children:a.map(d=>o.jsxs("div",{className:["flex flex-wrap items-center gap-3 px-3 py-3",i===d.id?"bg-[var(--color-lavender)]/55":""].join(" "),children:[o.jsx("div",{className:"min-w-0 flex-1",children:o.jsx("div",{className:"truncate font-mono text-[0.88rem] font-semibold text-[var(--color-ink)]",children:d.id})}),o.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[o.jsx("button",{type:"button",onClick:()=>u(d.id),className:"max-w-[240px] truncate rounded-[8px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-3 py-1.5 text-[0.78rem] font-semibold text-[var(--color-purple)] hover:bg-white","aria-label":`Choose seller for ${d.id}`,children:r(d.id)}),o.jsx("button",{type:"button",onClick:()=>u(d.id),className:"rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 py-1.5 text-[0.78rem] font-semibold text-[var(--color-muted)] hover:border-[var(--color-lavender-2)] hover:text-[var(--color-purple)]","aria-label":`Reselect seller for ${d.id}`,children:"Reselect"})]})]},d.id))})}function $j({models:a,selectedModelIds:i,onClose:r,onToggle:u}){const[d,m]=j.useState(""),h=a.filter(x=>h0(d,[x.id,x.paymentMethod,x.enabled?"enabled":"not enabled"]));return o.jsxs(f0,{title:"Add models",onClose:r,children:[o.jsx(m0,{value:d,onChange:m,placeholder:"Search models or payment"}),o.jsx("div",{className:"mt-3 overflow-hidden rounded-[12px] border border-[var(--color-line-2)]",children:o.jsxs("table",{className:"w-full border-collapse text-left text-[0.84rem]",children:[o.jsx("thead",{className:"bg-white/70 text-[0.7rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"w-10 px-3 py-2 font-semibold"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Model"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Payment"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Sellers"})]})}),o.jsxs("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:[h.map(x=>{const p=i.includes(x.id);return o.jsxs("tr",{onClick:()=>u(x.id),className:["cursor-pointer",p?"bg-[var(--color-lavender)]/70":"hover:bg-[var(--color-lavender)]/35",x.enabled?"":"opacity-60"].join(" "),children:[o.jsx("td",{className:"px-3 py-2.5",children:o.jsx(Po,{active:p,fixed:!1})}),o.jsx("td",{className:"px-3 py-2.5 font-mono font-semibold text-[var(--color-ink)]",children:x.id}),o.jsx("td",{className:"px-3 py-2.5",children:o.jsx(Wj,{enabled:x.enabled,paymentMethod:x.paymentMethod})}),o.jsx("td",{className:"px-3 py-2.5 text-right text-[var(--color-muted)]",children:x.sellerCount})]},x.id)}),h.length===0?o.jsx("tr",{children:o.jsx("td",{colSpan:4,className:"px-3 py-8 text-center text-[var(--color-muted)]",children:"No models found."})}):null]})]})}),o.jsx("div",{className:"mt-3 flex items-center justify-end border-t border-[var(--color-line-2)] pt-3",children:o.jsx("button",{type:"button",onClick:r,"aria-label":"Done","data-testid":"routing-model-picker-done",className:"inline-flex h-9 items-center justify-center rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)]",children:"Done"})})]})}function Jj({modelId:a,selection:i,selectedSellerIds:r,scorer:u,sellers:d,onClose:m,onToggle:h}){const[x,p]=j.useState(""),g=Pj(d.filter(b=>b.coverageModelIds.includes(a)),[a],u).filter(b=>h0(x,[b.name,b.id,b.paymentMethods.join(" "),b.health,b.notes.join(" ")]));return o.jsxs(f0,{title:`Choose seller · ${a}`,onClose:m,children:[o.jsx(m0,{value:x,onChange:p,placeholder:"Search sellers, payment, notes"}),o.jsx("div",{className:"mt-3 overflow-hidden rounded-[12px] border border-[var(--color-line-2)]",children:o.jsxs("table",{className:"w-full border-collapse text-left text-[0.82rem]",children:[o.jsx("thead",{className:"bg-white/70 text-[0.7rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"w-10 px-3 py-2 font-semibold"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Seller"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Discount"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Markup fee"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Payment"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"TTFT"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Tok/s"})]})}),o.jsxs("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:[g.map(b=>{const E=r.includes(b.id);return o.jsxs("tr",{onClick:()=>h(b.id),className:["cursor-pointer",E?"bg-[var(--color-lavender)]/70":"hover:bg-[var(--color-lavender)]/35"].join(" "),children:[o.jsx("td",{className:"px-3 py-2.5",children:o.jsx(Po,{active:E,fixed:i==="single"})}),o.jsx("td",{className:"px-3 py-2.5 font-semibold text-[var(--color-ink)]",children:b.name}),o.jsxs("td",{className:"whitespace-nowrap px-3 py-2.5 text-right",children:[o.jsx("div",{className:"font-mono font-semibold text-[var(--color-purple)]",children:b.discount}),o.jsx("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:b.price})]}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:b.markupFee}),o.jsx("td",{className:"px-3 py-2.5 text-[var(--color-muted)]",children:b.paymentMethods.join(", ")}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:xt(b.latencyMs)}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:Ke(b.tokensPerSecond)})]},b.id)}),g.length===0?o.jsx("tr",{children:o.jsx("td",{colSpan:7,className:"px-3 py-8 text-center text-[var(--color-muted)]",children:"No sellers found."})}):null]})]})})]})}function f0({title:a,children:i,onClose:r}){return o.jsx("div",{className:"fixed inset-0 z-30 flex items-center justify-center bg-[#201a38]/35 px-4 py-6 backdrop-blur-sm",children:o.jsxs("div",{className:"max-h-[86dvh] w-full max-w-[820px] overflow-hidden rounded-[14px] border border-[var(--color-line-2)] bg-white shadow-[0_24px_70px_rgba(32,26,56,0.22)]",children:[o.jsxs("div",{className:"flex items-center gap-3 border-b border-[var(--color-line-2)] px-5 py-4",children:[o.jsx("div",{className:"min-w-0 flex-1 truncate text-[1rem] font-semibold text-[var(--color-ink)]",children:a}),o.jsx("button",{type:"button",onClick:r,className:"inline-flex size-8 items-center justify-center rounded-[8px] text-[var(--color-muted)] hover:bg-[var(--color-lavender)] hover:text-[var(--color-purple)]","aria-label":"Close",children:o.jsx(Zr,{size:16})})]}),o.jsx("div",{className:"max-h-[calc(86dvh-65px)] overflow-auto p-4",children:i})]})})}function Fj({active:a,title:i,description:r,onClick:u}){return o.jsxs("button",{type:"button",onClick:u,"aria-label":`Set ${i} routing mode`,className:["min-h-[86px] rounded-[12px] border px-3 py-2.5 text-left transition-all",a?"border-[var(--color-lavender-2)] bg-[var(--color-lavender)] text-[var(--color-ink)]":"border-[var(--color-line-2)] bg-white text-[var(--color-muted)] hover:border-[var(--color-line)]"].join(" "),children:[o.jsxs("span",{className:"flex items-center gap-2 font-mono text-[0.86rem] font-semibold",children:[o.jsx(Po,{active:a,fixed:!0}),i]}),o.jsx("span",{className:"mt-1.5 block text-[0.74rem] leading-snug text-[var(--color-muted)]",children:r})]})}function Wj({enabled:a,paymentMethod:i}){return o.jsxs("span",{className:["inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[0.72rem] ring-1",a?"bg-emerald-50 text-emerald-700 ring-emerald-100":"bg-slate-100 text-slate-500 ring-slate-200"].join(" "),children:[a?o.jsx(P2,{size:12}):o.jsx($d,{size:12}),i," ",a?"enabled":"not enabled"]})}function Po({active:a,fixed:i}){return o.jsx("span",{className:["inline-flex size-5 shrink-0 items-center justify-center border",i?"rounded-full":"rounded-[6px]",a?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line)] bg-white text-transparent"].join(" "),children:o.jsx(Jt,{size:13,strokeWidth:2.4})})}function Pj(a,i,r){return[...a].sort((u,d)=>{const m=Vv(u,i),h=Vv(d,i);return m!==h?h-m:r==="speed"?nS(u.latencyMs,d.latencyMs):r==="discount"?Number.parseInt(d.discount,10)-Number.parseInt(u.discount,10):d.healthScore-u.healthScore})}function Ij(a,i){const r=new Map;for(const d of a){const m=r.get(d.id)??{sellerIds:new Set,paymentMethods:new Set};m.sellerIds.add(d.sellerId);for(const h of d.paymentMethods)m.paymentMethods.add(h);r.set(d.id,m)}const u=new Map(i.map((d,m)=>[d,m]));return Array.from(r.entries()).map(([d,m])=>({id:d,paymentMethod:Array.from(m.paymentMethods)[0]??Te,enabled:m.sellerIds.size>0,sellerCount:m.sellerIds.size})).sort((d,m)=>{const h=u.get(d.id),x=u.get(m.id);return h!==void 0||x!==void 0?(h??9999)-(x??9999):d.id.localeCompare(m.id)})}function eS(a,i,r){const u=(i==null?void 0:i.data)??[],d=new Map(((i==null?void 0:i.sellers)??[]).map(h=>[h.id,h])),m=new Map(r.map(h=>[h.seller.id,h]));return a.map((h,x)=>{var A;const p=m.get(h.id),v=d.get(h.id),g=Array.from(new Set(u.filter(z=>z.sellerId===h.id).map(z=>z.id))),b=(p==null?void 0:p.metrics.ttftMs)??(p==null?void 0:p.metrics.avgLatencyMs),E=p==null?void 0:p.metrics.healthScore,C=(p==null?void 0:p.metrics.discountRatio)??(v==null?void 0:v.discountRatio);return{id:h.id,name:sS(h.name??(v==null?void 0:v.name)??h.id),endpoint:h.url,health:(v==null?void 0:v.status)==="error"||(v==null?void 0:v.status)==="manifest_unavailable"||h.status==="failed"?"offline":h.status==="degraded"?"degraded":"online",healthScore:Number.isFinite(E)?Math.round(E):0,coverageModelIds:g,paymentMethods:(v==null?void 0:v.paymentMethods)??h.paymentMethods??[],discount:a0(C),markupFee:yf(v==null?void 0:v.serviceFeeRatio),price:p?"preview":"registry",latencyMs:Number.isFinite(b)?Math.round(b):void 0,tokensPerSecond:void 0,notes:[((A=h.supportedProtocols)==null?void 0:A.join(", "))||"no protocols",`registry #${x+1}`]}})}function tS(a){if(a)return a.plan??{routes:a.routes,mode:a.mode,scorer:a.scorer,reason:a.reason}}function lS(a,i,r){var u,d;if(a.mode==="fixed"){const m={...a.fixedByModel??{}},h=((u=aS(i,r))==null?void 0:u.id)||((d=i[0])==null?void 0:d.id);return r&&!m[r]&&h&&(m[r]=h),{mode:"fixed",scorer:a.scorer,fixedByModel:m}}if(a.mode==="fixedSet"){const m=a.sellerIds&&a.sellerIds.length>0?a.sellerIds:i.filter(h=>!r||h.coverageModelIds.includes(r)).slice(0,2).map(h=>h.id);return{mode:"fixedSet",scorer:a.scorer,sellerIds:m}}return{mode:"fullAuto",scorer:a.scorer}}function aS(a,i){return a.find(r=>!i||r.coverageModelIds.includes(i))}function Vv(a,i){return i.length===0?a.coverageModelIds.length:i.filter(r=>a.coverageModelIds.includes(r)).length}function nS(a,i){const r=Number.isFinite(a),u=Number.isFinite(i);return r&&u?a-i:r?-1:u?1:0}function iS(a,i){var r;return a?((r=i.find(u=>u.id===a))==null?void 0:r.name)??a:"Not selected"}function rS(a){return Object.entries(a??{}).sort(([i],[r])=>i.localeCompare(r)).map(([i,r])=>`${i}:${r}`).join(",")}function sS(a){var i;return((i=a.split("(")[0])==null?void 0:i.trim())||a}function m0({value:a,onChange:i,placeholder:r}){return o.jsxs("label",{className:"flex items-center gap-2 rounded-[12px] border border-[var(--color-line-2)] bg-white px-3 py-2 text-[0.84rem] text-[var(--color-muted)]",children:[o.jsx(Fo,{size:15}),o.jsx("input",{name:"routing-search",value:a,onChange:u=>i(u.target.value),placeholder:r,className:"min-w-0 flex-1 bg-transparent font-mono text-[0.84rem] text-[var(--color-ink)] outline-none placeholder:text-[var(--color-faint)]"})]})}function h0(a,i){const r=a.trim().toLowerCase();return r?i.some(u=>u.toLowerCase().includes(r)):!0}function oS(a,i){return i?[...a].sort((r,u)=>r.id===i?-1:u.id===i?1:0):a}function p0(a){return a!==void 0}function v0({totalItems:a,pageSize:i,page:r,onPageChange:u,onPageSizeChange:d,pageSizeOptions:m=[25,50,100]}){const h=Math.max(1,Math.ceil(a/i)),x=j.useMemo(()=>uS(r,h),[r,h]);if(a===0)return null;const p=(r-1)*i+1,v=Math.min(r*i,a);return o.jsxs("div",{className:"flex flex-col gap-3 border-t border-[var(--color-line-2)] bg-[var(--color-page)]/60 px-4 py-3 text-[0.85rem] lg:flex-row lg:items-center lg:justify-between",children:[o.jsxs("div",{className:"text-[var(--color-muted)]",children:["Showing ",o.jsx("span",{className:"font-mono font-semibold text-[var(--color-ink)]",children:p}),"-",o.jsx("span",{className:"font-mono font-semibold text-[var(--color-ink)]",children:v})," of"," ",o.jsx("span",{className:"font-mono font-semibold text-[var(--color-ink)]",children:a})]}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("label",{className:"text-[0.78rem] text-[var(--color-muted)]",children:"Rows"}),o.jsx("select",{className:"bg-[var(--color-card)] border border-[var(--color-line-2)] rounded px-1.5 py-0.5 text-[0.85rem] text-[var(--color-ink)] focus:outline-none focus:border-[var(--color-purple)]",value:i,onChange:g=>{const b=Math.max(1,Number(g.target.value)||25);d==null||d(b),u(1)},children:m.map(g=>o.jsx("option",{value:g,children:g},g))}),o.jsxs("div",{className:"ml-2 flex items-center gap-1",children:[o.jsx("button",{type:"button",disabled:r<=1,onClick:()=>u(1),className:"px-2 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] disabled:opacity-40 disabled:cursor-not-allowed hover:bg-[var(--color-lavender)]/40",title:"First page","aria-label":"First page",children:"«"}),o.jsx("button",{type:"button",disabled:r<=1,onClick:()=>u(r-1),className:"px-2 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] disabled:opacity-40 disabled:cursor-not-allowed hover:bg-[var(--color-lavender)]/40",title:"Previous page","aria-label":"Previous page",children:"‹"}),x.map((g,b)=>g==="…"?o.jsx("span",{className:"px-1.5 text-[var(--color-muted)]",children:"…"},`gap-${b}`):o.jsx("button",{type:"button",onClick:()=>u(g),"aria-label":`Page ${g}`,"aria-current":g===r?"page":void 0,className:g===r?"px-2.5 py-0.5 rounded bg-[var(--color-purple)] text-white font-medium":"px-2.5 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] hover:bg-[var(--color-lavender)]/40",children:g},g)),o.jsx("button",{type:"button",disabled:r>=h,onClick:()=>u(r+1),className:"px-2 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] disabled:opacity-40 disabled:cursor-not-allowed hover:bg-[var(--color-lavender)]/40",title:"Next page","aria-label":"Next page",children:"›"}),o.jsx("button",{type:"button",disabled:r>=h,onClick:()=>u(h),className:"px-2 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] disabled:opacity-40 disabled:cursor-not-allowed hover:bg-[var(--color-lavender)]/40",title:"Last page","aria-label":"Last page",children:"»"}),o.jsx("span",{className:"ml-2 text-[0.78rem] text-[var(--color-muted)]",children:"Go to"}),o.jsx("input",{type:"number",min:1,max:h,defaultValue:r,"aria-label":"Go to page",onKeyDown:g=>{if(g.key==="Enter"){const b=Math.max(1,Math.min(h,Number(g.target.value)||1));u(b)}},className:"w-14 bg-[var(--color-card)] border border-[var(--color-line-2)] rounded px-1.5 py-0.5 text-[0.85rem] text-[var(--color-ink)] text-center focus:outline-none focus:border-[var(--color-purple)]"}),o.jsx("span",{className:"text-[0.78rem] text-[var(--color-muted)]",children:"page"})]})]})]})}function uS(a,i){if(i<=7)return Array.from({length:i},(d,m)=>m+1);const r=[],u=d=>{r[r.length-1]!==d&&r.push(d)};u(1),a>4&&u("…");for(let d=Math.max(2,a-1);d<=Math.min(i-1,a+1);d++)u(d);return a<i-3&&u("…"),u(i),r}function cS(){var ge,M;const a=Wo(),i=sj(),[r,u]=j.useState("inferences"),[d,m]=j.useState(""),[h,x]=j.useState("all"),[p,v]=j.useState("all"),[g,b]=j.useState("all"),[E,C]=j.useState("all"),[A,z]=j.useState(1),[B,U]=j.useState(1),[G,K]=j.useState(25),[L,V]=j.useState(null),[P,J]=j.useState(null),ee=a.isLoading||i.isLoading,le=((ge=a.data)==null?void 0:ge.inferences)??[],oe=((M=i.data)==null?void 0:M.purchases)??[],F=d.trim().toLowerCase(),fe=j.useMemo(()=>vS(le,oe),[le,oe]),ye=j.useMemo(()=>xS(le),[le]),Ee=j.useMemo(()=>yS(oe),[oe]),me=j.useMemo(()=>le.filter(_=>h!=="all"&&_.status!==h||p!=="all"&&_.modelId!==p?!1:bS(_,F)).sort((_,Z)=>Z.createdAt.localeCompare(_.createdAt)),[le,p,h,F]),D=j.useMemo(()=>oe.filter(_=>g!=="all"&&_.status!==g||E!=="all"&&_.paymentMethod!==E?!1:gS(_,F)).sort((_,Z)=>Z.createdAt.localeCompare(_.createdAt)),[oe,E,g,F]),$=j.useMemo(()=>$v(me,A,G),[me,A,G]),re=j.useMemo(()=>$v(D,B,G),[D,B,G]),be=a.isError||i.isError;return j.useEffect(()=>{const _=Math.max(1,Math.ceil(me.length/G));A>_&&z(_)},[me.length,A,G]),j.useEffect(()=>{const _=Math.max(1,Math.ceil(D.length/G));B>_&&U(_)},[D.length,G,B]),o.jsxs("div",{className:"space-y-4",children:[o.jsxs("section",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[o.jsx(_o,{icon:o.jsx(X2,{className:"size-5"}),label:"Inference spend",value:st(fe.inferenceSpendMicros,{digits:4}),detail:`${Ke(fe.inferenceCount)} requests`,tone:"spend"}),o.jsx(_o,{icon:o.jsx(O2,{className:"size-5"}),label:"Token usage",value:pl(fe.inputTokens+fe.outputTokens),detail:$r(fe.inputTokens,fe.outputTokens),tone:"tokens"}),o.jsx(_o,{icon:o.jsx(Gr,{className:"size-5"}),label:"Purchase credit",value:st(fe.purchaseCreditMicros,{digits:4}),detail:`${Ke(fe.settledPurchases)} settled`,tone:"credit"}),o.jsx(_o,{icon:o.jsx(w2,{className:"size-5"}),label:"Average response",value:xt(fe.averageDurationMs),detail:"Completed inference time",tone:"latency"})]}),o.jsxs(jt,{className:"overflow-hidden p-0",children:[o.jsxs("div",{className:"border-b border-[var(--color-line-2)] bg-white px-4 py-3",children:[o.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[o.jsx("div",{children:o.jsx("h1",{className:"text-[1.05rem] font-semibold text-[var(--color-ink)]",children:"Usage details"})}),o.jsxs("div",{className:"grid grid-cols-2 overflow-hidden rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-1",children:[o.jsx(Zv,{label:"Inferences",active:r==="inferences",count:me.length,onClick:()=>u("inferences"),children:"Inferences"}),o.jsx(Zv,{label:"Purchases",active:r==="purchases",count:D.length,onClick:()=>u("purchases"),children:"Purchases"})]})]}),o.jsxs("div",{className:"mt-3 grid gap-2 lg:grid-cols-[minmax(220px,1fr)_160px_200px]",children:[o.jsxs("label",{className:"relative block",children:[o.jsx(Fo,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-[var(--color-muted)]"}),o.jsx("input",{className:"h-9 w-full rounded-[8px] border border-[var(--color-line-2)] bg-white pl-9 pr-3 text-[0.86rem] text-[var(--color-ink)] outline-none transition placeholder:text-[var(--color-muted)] focus:border-[var(--color-purple)]",value:d,placeholder:r==="inferences"?"Search request, model, seller...":"Search purchase, method, seller...",onChange:_=>{m(_.target.value),z(1),U(1)}})]}),r==="inferences"?o.jsxs(o.Fragment,{children:[o.jsx(Do,{label:"Status",value:h,options:ye.statuses,onChange:_=>{x(_),z(1)}}),o.jsx(Do,{label:"Model",value:p,options:ye.models,onChange:_=>{v(_),z(1)}})]}):o.jsxs(o.Fragment,{children:[o.jsx(Do,{label:"Status",value:g,options:Ee.statuses,onChange:_=>{b(_),U(1)}}),o.jsx(Do,{label:"Method",value:E,options:Ee.methods,onChange:_=>{C(_),U(1)}})]})]})]}),be?o.jsx("div",{className:"border-b border-rose-100 bg-rose-50 px-4 py-3 text-[0.86rem] text-rose-700",children:"Ledger data could not be loaded. The local daemon may be offline or missing ledger endpoints."}):null,ee?o.jsx(pS,{}):r==="inferences"?o.jsx(dS,{entries:$,total:me.length,page:A,pageSize:G,openId:L,onToggle:_=>V(L===_?null:_),onPageChange:z,onPageSizeChange:_=>{K(_),z(1),U(1)}}):o.jsx(fS,{entries:re,total:D.length,page:B,pageSize:G,openId:P,onToggle:_=>J(P===_?null:_),onPageChange:U,onPageSizeChange:_=>{K(_),z(1),U(1)}})]})]})}function _o({icon:a,label:i,value:r,detail:u,tone:d}){const m={spend:{card:"border-[#cceee6] bg-[#e8fbf7]",icon:"bg-white text-[#0f766e]",label:"text-[#0f766e]",value:"text-[#201a38]",accent:"bg-[#0f766e]"},tokens:{card:"border-[#d9e7ff] bg-[#eaf2ff]",icon:"bg-white text-[#2563eb]",label:"text-[#2563eb]",value:"text-[#201a38]",accent:"bg-[#2563eb]"},credit:{card:"border-[#dff8ec] bg-[#e8fff6]",icon:"bg-white text-emerald-700",label:"text-emerald-700",value:"text-[#201a38]",accent:"bg-emerald-500"},latency:{card:"border-[#f8d5de] bg-[#fff0f3]",icon:"bg-white text-[#ef5b78]",label:"text-[#ef5b78]",value:"text-[#201a38]",accent:"bg-[#ef5b78]"}}[d];return o.jsxs(jt,{className:["relative flex min-h-[7rem] items-center gap-4 overflow-hidden px-4 py-4",m.card].join(" "),children:[o.jsx("div",{className:["absolute inset-y-0 left-0 w-1",m.accent].join(" ")}),o.jsx("div",{className:["grid size-11 shrink-0 place-items-center rounded-[10px] shadow-sm",m.icon].join(" "),children:a}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:["text-[0.72rem] font-bold uppercase tracking-[0.08em]",m.label].join(" "),children:i}),o.jsx("div",{className:["mt-1 truncate font-mono text-[1.55rem] font-bold leading-none tracking-normal",m.value].join(" "),children:r}),o.jsx("div",{className:"mt-2 truncate text-[0.76rem] font-medium text-[var(--color-muted)]",children:u})]})]})}function Zv({label:a,active:i,count:r,onClick:u,children:d}){return o.jsxs("button",{type:"button",onClick:u,"aria-label":`${a} ledger records, ${Ke(r)} records`,className:["inline-flex h-8 items-center justify-center gap-2 rounded-[8px] px-3 text-[0.82rem] font-semibold transition",i?"bg-white text-[var(--color-ink)] shadow-sm":"text-[var(--color-muted)] hover:text-[var(--color-ink)]"].join(" "),children:[o.jsx("span",{children:d}),o.jsx("span",{className:"font-mono text-[0.76rem]",children:Ke(r)})]})}function Do({label:a,value:i,options:r,onChange:u}){return o.jsxs("label",{className:"grid gap-1",children:[o.jsx("span",{className:"sr-only",children:a}),o.jsxs("select",{"aria-label":a,className:"h-9 rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.86rem] text-[var(--color-ink)] outline-none transition focus:border-[var(--color-purple)]",value:i,onChange:d=>u(d.target.value),children:[o.jsxs("option",{value:"all",children:["All ",a.toLowerCase()]}),r.map(d=>o.jsx("option",{value:d,children:d},d))]})]})}function dS({entries:a,total:i,page:r,pageSize:u,openId:d,onToggle:m,onPageChange:h,onPageSizeChange:x}){return i===0?o.jsx(g0,{label:"inference records"}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"divide-y divide-[var(--color-line-2)] bg-white xl:hidden",children:a.map(p=>o.jsx(mS,{entry:p,open:d===p.requestId,onToggle:()=>m(p.requestId)},p.requestId))}),o.jsx("div",{className:"hidden min-w-0 max-w-full overflow-x-auto xl:block",children:o.jsxs("table",{className:"w-full min-w-[1080px] text-[0.86rem]",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"bg-[var(--color-page)]/70 text-left text-[0.7rem] font-semibold uppercase tracking-[0.08em] text-[var(--color-muted)]",children:[o.jsx("th",{className:"px-4 py-2.5",children:"TIME"}),o.jsx("th",{className:"px-4 py-2.5",children:"REQ"}),o.jsx("th",{className:"px-4 py-2.5",children:"MODEL"}),o.jsx("th",{className:"px-4 py-2.5",children:"SELLER"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"TOKEN"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"COST"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"TTFT"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"TOTAL"}),o.jsx("th",{className:"px-4 py-2.5",children:"STATUS"})]})}),a.map(p=>o.jsxs("tbody",{children:[o.jsxs("tr",{onClick:()=>m(p.requestId),className:"cursor-pointer border-t border-[var(--color-line-2)] transition hover:bg-[var(--color-lavender)]/25",children:[o.jsx("td",{className:"whitespace-nowrap px-4 py-3 font-mono text-[0.76rem] text-[var(--color-muted)]",children:r0(p.createdAt)}),o.jsx("td",{className:"px-4 py-3",children:o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(Io,{tone:"purple",children:o.jsx(Zx,{className:"size-4"})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"max-w-[180px] truncate font-mono text-[0.78rem] font-semibold text-[var(--color-ink)]",children:p.requestId}),o.jsx("div",{className:"mt-0.5 max-w-[180px] truncate text-[0.72rem] text-[var(--color-muted)]",children:p.endpoint})]})]})}),o.jsx("td",{className:"max-w-[190px] truncate px-4 py-3 text-[var(--color-ink)]",children:p.modelId}),o.jsx("td",{className:"px-4 py-3 font-mono text-[0.78rem] text-[var(--color-text)]",children:p.sellerKey}),o.jsxs("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem]",children:[o.jsx("div",{children:Ke(p.promptTokens)}),o.jsx("div",{className:"text-[0.72rem] text-[var(--color-muted)]",children:Ke(p.completionTokens)})]}),o.jsx("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem] font-semibold text-[var(--color-ink)]",children:st(p.billedMicros,{ledger:!0})}),o.jsx("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem] text-[var(--color-muted)]",children:xt(p.ttftMs)}),o.jsx("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem] text-[var(--color-muted)]",children:xt(p.durationMs)}),o.jsx("td",{className:"px-4 py-3",children:o.jsx(rs,{tone:Ka(p.status),children:Rl(p.status)})})]}),d===p.requestId?o.jsx("tr",{children:o.jsx("td",{colSpan:9,className:"border-t border-[var(--color-line-2)] bg-[var(--color-page)]/70 px-5 py-4",children:o.jsx(x0,{entry:p})})}):null]},p.requestId))]})}),o.jsx(v0,{totalItems:i,pageSize:u,page:r,onPageChange:h,onPageSizeChange:x})]})}function fS({entries:a,total:i,page:r,pageSize:u,openId:d,onToggle:m,onPageChange:h,onPageSizeChange:x}){return i===0?o.jsx(g0,{label:"purchase records"}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"divide-y divide-[var(--color-line-2)] bg-white xl:hidden",children:a.map(p=>o.jsx(hS,{entry:p,open:d===p.purchaseId,onToggle:()=>m(p.purchaseId)},p.purchaseId))}),o.jsx("div",{className:"hidden min-w-0 max-w-full overflow-x-auto xl:block",children:o.jsxs("table",{className:"w-full min-w-[980px] text-[0.86rem]",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"bg-[var(--color-page)]/70 text-left text-[0.7rem] font-semibold uppercase tracking-[0.08em] text-[var(--color-muted)]",children:[o.jsx("th",{className:"px-4 py-2.5",children:"When"}),o.jsx("th",{className:"px-4 py-2.5",children:"Purchase"}),o.jsx("th",{className:"px-4 py-2.5",children:"Payment method"}),o.jsx("th",{className:"px-4 py-2.5",children:"Model"}),o.jsx("th",{className:"px-4 py-2.5",children:"Seller"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"Credit"}),o.jsx("th",{className:"px-4 py-2.5",children:"Status"})]})}),a.map(p=>o.jsxs("tbody",{children:[o.jsxs("tr",{onClick:()=>m(p.purchaseId),className:"cursor-pointer border-t border-[var(--color-line-2)] transition hover:bg-[var(--color-lavender)]/25",children:[o.jsx("td",{className:"whitespace-nowrap px-4 py-3 font-mono text-[0.76rem] text-[var(--color-muted)]",children:r0(p.createdAt)}),o.jsx("td",{className:"px-4 py-3",children:o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(Io,{tone:"green",children:o.jsx(Bi,{className:"size-4"})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"max-w-[210px] truncate font-mono text-[0.78rem] font-semibold text-[var(--color-ink)]",children:p.purchaseId}),o.jsx("div",{className:"mt-0.5 max-w-[210px] truncate text-[0.72rem] text-[var(--color-muted)]",children:Jr(p.paymentReferenceHash)})]})]})}),o.jsx("td",{className:"px-4 py-3 text-[var(--color-ink)]",children:p.paymentMethod}),o.jsx("td",{className:"max-w-[180px] truncate px-4 py-3 text-[var(--color-ink)]",children:p.modelId}),o.jsx("td",{className:"px-4 py-3 font-mono text-[0.78rem] text-[var(--color-text)]",children:p.sellerKey}),o.jsx("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem] font-semibold text-emerald-700",children:st(p.creditMicros,{digits:4,signed:!0})}),o.jsx("td",{className:"px-4 py-3",children:o.jsx(rs,{tone:Ka(p.status),children:Rl(p.status)})})]}),d===p.purchaseId?o.jsx("tr",{children:o.jsx("td",{colSpan:7,className:"border-t border-[var(--color-line-2)] bg-[var(--color-page)]/70 px-5 py-4",children:o.jsx(y0,{entry:p})})}):null]},p.purchaseId))]})}),o.jsx(v0,{totalItems:i,pageSize:u,page:r,onPageChange:h,onPageSizeChange:x})]})}function mS({entry:a,open:i,onToggle:r}){return o.jsxs("article",{className:"px-4 py-3",children:[o.jsx("button",{type:"button",onClick:r,"aria-expanded":i,"aria-label":`Inference ${a.requestId}`,className:"block w-full text-left",children:o.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[o.jsx(Io,{tone:"purple",children:o.jsx(Zx,{className:"size-4"})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",title:a.requestId,children:a.requestId}),o.jsx("div",{className:"mt-0.5 truncate text-[0.72rem] text-[var(--color-muted)]",title:a.endpoint,children:a.endpoint})]}),o.jsx(rs,{tone:Ka(a.status),children:Rl(a.status)})]}),o.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4",children:[o.jsx(gt,{label:"Time",value:vl(a.createdAt),compact:!0}),o.jsx(gt,{label:"Model",value:a.modelId}),o.jsx(gt,{label:"Seller",value:a.sellerKey}),o.jsx(gt,{label:"Cost",value:st(a.billedMicros,{ledger:!0}),tone:"strong"}),o.jsx(gt,{label:"In",value:Ke(a.promptTokens)}),o.jsx(gt,{label:"Out",value:Ke(a.completionTokens)}),o.jsx(gt,{label:"TTFT",value:xt(a.ttftMs)}),o.jsx(gt,{label:"Total",value:xt(a.durationMs)}),o.jsx(gt,{label:"Route",value:a.routeReason??Te})]})]})]})}),i?o.jsx("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3",children:o.jsx(x0,{entry:a})}):null]})}function hS({entry:a,open:i,onToggle:r}){return o.jsxs("article",{className:"px-4 py-3",children:[o.jsx("button",{type:"button",onClick:r,"aria-expanded":i,"aria-label":`Purchase ${a.purchaseId}`,className:"block w-full text-left",children:o.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[o.jsx(Io,{tone:"green",children:o.jsx(Bi,{className:"size-4"})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",title:a.purchaseId,children:a.purchaseId}),o.jsx("div",{className:"mt-0.5 truncate text-[0.72rem] text-[var(--color-muted)]",title:a.paymentReferenceHash??void 0,children:Jr(a.paymentReferenceHash)})]}),o.jsx(rs,{tone:Ka(a.status),children:Rl(a.status)})]}),o.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4",children:[o.jsx(gt,{label:"Time",value:vl(a.createdAt),compact:!0}),o.jsx(gt,{label:"Method",value:a.paymentMethod}),o.jsx(gt,{label:"Model",value:a.modelId}),o.jsx(gt,{label:"Seller",value:a.sellerKey}),o.jsx(gt,{label:"Credit",value:st(a.creditMicros,{digits:4,signed:!0}),tone:"green"}),o.jsx(gt,{label:"Currency",value:a.currency}),o.jsx(gt,{label:"Completed",value:vl(a.completedAt),compact:!0})]})]})]})}),i?o.jsx("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3",children:o.jsx(y0,{entry:a})}):null]})}function gt({label:a,value:i,tone:r="default",compact:u=!1}){return o.jsxs("div",{className:"min-w-0 rounded-[9px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-2.5 py-2",children:[o.jsx("div",{className:"text-[0.62rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:a}),o.jsx("div",{className:["mt-1 truncate font-mono font-semibold",u?"text-[0.7rem]":"text-[0.84rem]",r==="green"?"text-emerald-700":r==="strong"?"text-[var(--color-ink)]":"text-[var(--color-text)]"].join(" "),title:i,children:i})]})}function Io({tone:a,children:i}){return o.jsx("div",{className:["grid size-9 shrink-0 place-items-center rounded-lg border",a==="purple"?"border-[var(--color-lavender-2)] bg-[var(--color-lavender)] text-[var(--color-purple)]":"border-emerald-100 bg-emerald-50 text-emerald-700"].join(" "),children:i})}function x0({entry:a}){return o.jsx(b0,{rows:[["Request ID",a.requestId],["Created",vl(a.createdAt)],["Endpoint",a.endpoint],["Payment method",a.paymentMethod??Te],["Route",`${a.routeReason??Te} -> ${a.sellerKey}`],["Fallback chain",a.falloverChain&&a.falloverChain.length>0?a.falloverChain.join(" -> "):Te],["Upstream status",Rl(a.upstreamStatus)],["TTFT / total",`${xt(a.ttftMs)} / ${xt(a.durationMs)}`],["Input / output tokens",dj(a.promptTokens,a.completionTokens)],["Billed",st(a.billedMicros,{ledger:!0})],["Balance after",st(a.balanceSnapshotMicros,{digits:4})],["Prompt hash",Jr(a.promptHash)],["Response hash",Jr(a.responseHash)],["Price version",a.priceVersion??Te]]})}function y0({entry:a}){return o.jsx(b0,{rows:[["Purchase ID",a.purchaseId],["Created",vl(a.createdAt)],["Completed",vl(a.completedAt)],["Payment method",a.paymentMethod],["Payment reference",Jr(a.paymentReferenceHash)],["Credit",st(a.creditMicros,{digits:4})],["Credit micros",Ke(a.creditMicros)],["Currency",a.currency],["Seller",a.sellerKey],["Model",a.modelId]]})}function b0({rows:a}){return o.jsx("div",{className:"grid gap-x-4 gap-y-2 text-[0.84rem] sm:grid-cols-[150px_minmax(0,1fr)]",children:a.map(([i,r])=>o.jsxs("div",{className:"contents",children:[o.jsx("div",{className:"text-[var(--color-muted)]",children:i}),o.jsx("div",{className:"min-w-0 break-all font-mono text-[0.8rem] text-[var(--color-ink)]",children:r})]},i))})}function pS(){return o.jsx("div",{className:"space-y-2 px-4 py-4",children:Array.from({length:7},(a,i)=>o.jsx("div",{className:"h-12 rounded-lg bg-[var(--color-lavender)]/35"},i))})}function g0({label:a}){return o.jsxs("div",{className:"flex min-h-[220px] flex-col items-center justify-center px-6 py-10 text-center",children:[o.jsx("div",{className:"grid size-12 place-items-center rounded-xl border border-[var(--color-line-2)] bg-[var(--color-page)] text-[var(--color-purple)]",children:o.jsx(Fo,{className:"size-5"})}),o.jsxs("div",{className:"mt-4 font-semibold text-[var(--color-ink)]",children:["No matching ",a]}),o.jsx("div",{className:"mt-1 max-w-[360px] text-[0.86rem] text-[var(--color-muted)]",children:"Adjust the query or filters to inspect another slice of the local ledger."})]})}function vS(a,i){const r=a.reduce((p,v)=>p+(v.billedMicros??0),0),u=i.reduce((p,v)=>p+v.creditMicros,0),d=a.reduce((p,v)=>p+(v.promptTokens??0),0),m=a.reduce((p,v)=>p+(v.completionTokens??0),0),h=a.map(p=>p.durationMs).filter(p=>p!==void 0),x=h.length===0?void 0:h.reduce((p,v)=>p+v,0)/h.length;return{inferenceCount:a.length,inferenceSpendMicros:r,purchaseCreditMicros:u,inputTokens:d,outputTokens:m,settledPurchases:i.filter(p=>jS(p.status)).length,averageDurationMs:x}}function xS(a){return{statuses:Xo(a.map(i=>i.status)),models:Xo(a.map(i=>i.modelId))}}function yS(a){return{statuses:Xo(a.map(i=>i.status)),methods:Xo(a.map(i=>i.paymentMethod))}}function Xo(a){return Array.from(new Set(a.filter(Boolean))).sort((i,r)=>i.localeCompare(r))}function bS(a,i){return i?[a.requestId,a.sellerKey,a.modelId,a.endpoint,a.status,a.paymentMethod,a.routeReason,a.upstreamStatus].some(r=>r==null?void 0:r.toLowerCase().includes(i)):!0}function gS(a,i){return i?[a.purchaseId,a.sellerKey,a.modelId,a.paymentMethod,a.status,a.currency,a.paymentReferenceHash].some(r=>r==null?void 0:r.toLowerCase().includes(i)):!0}function $v(a,i,r){const u=(i-1)*r;return a.slice(u,u+r)}function jS(a){return a==="settled"||a==="active"||a==="completed"||a==="success"}function SS(){return xl({queryKey:["init","state"],queryFn:()=>yl("/init/state"),refetchInterval:1e4})}async function NS(a){return Xa("POST","/init/complete",void 0)}function MS(){return Qi({mutationFn:()=>Xa("POST","/init/doctor/run")})}function wS(){return xl({queryKey:["providers","status"],queryFn:()=>yl("/providers/status"),refetchInterval:1e4})}function CS(){return Qi({mutationFn:a=>Xa("POST","/providers/install/preview",a)})}function TS(){const a=is();return Qi({mutationFn:i=>Xa("POST","/providers/install/apply",i),onSuccess:()=>{a.invalidateQueries({queryKey:["providers","status"]}),a.invalidateQueries({queryKey:["init","state"]})}})}const ES=[{value:"fullAuto",title:"全自动",body:"自动选择可用供应商。"},{value:"fixedSet",title:"固定供应商组",body:"在指定供应商组内切换。"},{value:"fixed",title:"固定供应商",body:"始终使用指定供应商。"}],AS=[{value:"balanced",title:"平衡模式",body:"综合速度、价格、健康度、余额。"},{value:"speed",title:"速度优先",body:"优先选择更快、吞吐量更高供应商。"},{value:"discount",title:"成本优先",body:"优先选择更低成本供应商。"}],Jv=[{index:1,label:"选择模型",value:"默认模型"},{index:2,label:"绑定钱包",value:"支付方式"},{index:3,label:"配置策略",value:"路由规则"},{index:4,label:"配置工具",value:"终端接入"}],zS=[{method:"wechat-pay",name:"WeChat Pay",detail:"微信支付入口预留"},{method:"alipay-agent",name:"Alipay Agent Payment",detail:"代理支付入口预留"},{method:"coinbase-smart-wallet",name:"Coinbase Smart Wallet",detail:"USDC 钱包入口预留"}],RS=["GPT","Claude","Gemini","DeepSeek","Kimi","Qwen","MiniMax","GLM","Doubao","Grok"];function OS(a){const i=new URLSearchParams(a);return i.has("verifyPaymentMethods")?2:(i.has("verifyPickerDom")||i.has("verifyNoIntro")||i.has("verifyCompact"),1)}function _S(){var fs,ms,hs,$a,Ja,Fa,Sl,Wa,oa,ps,Gi,Rn;const[a,i]=j.useState(()=>OS(typeof window>"u"?"":window.location.search)),[r,u]=j.useState([]),[d,m]=j.useState(!1),[h,x]=j.useState(),[p,v]=j.useState(!1),[g,b]=j.useState(!1),[E,C]=j.useState("fullAuto"),[A,z]=j.useState("balanced"),[B,U]=j.useState(""),[G,K]=j.useState([]),[L,V]=j.useState(),[P,J]=j.useState(""),[ee,le]=j.useState([]),[oe,F]=j.useState({}),[fe,ye]=j.useState(),[Ee,me]=j.useState(),[D,$]=j.useState(!1),[re,be]=j.useState(null),[ge,M]=j.useState(!1),[_,Z]=j.useState(),I=SS(),X=l0(),ae=e0(),W=Fx(),Ae=wS(),Oe=Wx(),bl=Px(),ia=CS(),Tn=TS(),At=MS(),ft=xf(),En=Wo(),ra=j.useMemo(()=>{var ie;return BS(((ie=ft.data)==null?void 0:ie.data)??[])},[(fs=ft.data)==null?void 0:fs.data]),tu=j.useMemo(()=>{var ie,Qe,Lt;return IS(((ie=ft.data)==null?void 0:ie.sellers)??[],((Qe=ft.data)==null?void 0:Qe.data)??[],((Lt=En.data)==null?void 0:Lt.inferences)??[])},[(ms=En.data)==null?void 0:ms.inferences,(hs=ft.data)==null?void 0:hs.data,($a=ft.data)==null?void 0:$a.sellers]),An=j.useMemo(()=>{var ie;return HS(ra,r,((ie=I.data)==null?void 0:ie.recommendedModels)??[])},[(Ja=I.data)==null?void 0:Ja.recommendedModels,ra,r]),gl=j.useMemo(()=>r.length>0?r:An.map(ie=>ie.id),[An,r]),Va=`http://127.0.0.1:${((Fa=X.data)==null?void 0:Fa.proxyPort)??((Sl=I.data)==null?void 0:Sl.runtime.proxyPort)??17821}`,sa=j.useMemo(()=>{var ie;return(((ie=Ae.data)==null?void 0:ie.clients)??[]).filter(Qe=>Qe.id!=="custom"&&Qe.detected)},[(Wa=Ae.data)==null?void 0:Wa.clients]),ss=((oa=W.data)==null?void 0:oa.payments.filter(ie=>ie.enabled&&eu(ie.method)!=="mock"))??[],os=j.useMemo(()=>iN(E,A,B,G),[B,G,E,A]),St=rN({serviceReady:((ps=X.data)==null?void 0:ps.status)==="running",modelCount:ra.length,routingMode:E,paymentReady:ss.length>0,configuredTools:((Gi=Ae.data)==null?void 0:Gi.summary.configuredCount)??0}),lu=((Rn=At.data)==null?void 0:Rn.checks.map(sN))??St;j.useEffect(()=>{p||!I.data||(u(I.data.focusSet),v(!0))},[I.data,p]),j.useEffect(()=>{P||r.length===0||J(r[0])},[P,r]),j.useEffect(()=>{g||sa.length===0||(le(sa.filter(ie=>!ie.configured).map(ie=>ie.id)),b(!0))},[g,sa]),j.useEffect(()=>{a!==5||At.data||At.error||At.isPending||At.mutate()},[a,At]),j.useEffect(()=>{var Lt;const ie=ua=>{ua.preventDefault(),be(ua),Z("浏览器已经允许直接安装 TokenBuddy。")},Qe=()=>{M(!0),be(null),Z("TokenBuddy 桌面应用已安装。")};return window.addEventListener("beforeinstallprompt",ie),window.addEventListener("appinstalled",Qe),(Lt=window.matchMedia)!=null&&Lt.call(window,"(display-mode: standalone)").matches&&M(!0),()=>{window.removeEventListener("beforeinstallprompt",ie),window.removeEventListener("appinstalled",Qe)}},[]);const us=ie=>{x(void 0),u(Qe=>Qe.includes(ie)?Qe.filter(Lt=>Lt!==ie):[...Qe,ie])},cs=async()=>{m(!0),x(void 0);try{await Lo(r),x("关注模型已保存。后续工具配置会优先参考这些模型。")}catch(ie){x(`保存失败:${ie instanceof Error?ie.message:String(ie)}`)}finally{m(!1)}},zn=async()=>{if(V(void 0),!os){V(E==="fixed"?"请选择一个固定供应商。":"请至少选择一个供应商。");return}try{await ae.mutateAsync(os),V("供应商路由策略已保存。"),i(4)}catch(ie){V(`保存失败:${ie instanceof Error?ie.message:String(ie)}`)}},au=async()=>{try{await Oe.mutateAsync()}catch{}},ds=async()=>{try{await bl.mutateAsync()}catch{}},nu=async()=>{ye(void 0);const ie=P||gl[0];if(!ie){ye("请先选择一个默认模型。");return}if(ee.length===0){ye("请选择至少一个要安装的终端工具。");return}try{await ia.mutateAsync({providers:ee,proxyUrl:Va,model:ie,providerSelections:tx(ee,oe,gl,ie)}),ye("已生成安装预览。确认无误后可以写入配置。")}catch(Qe){ye(`预览失败:${Qe instanceof Error?Qe.message:String(Qe)}`)}},iu=async()=>{ye(void 0);const ie=P||gl[0];if(!ie){ye("请先选择一个默认模型。");return}if(ee.length===0){ye("请选择至少一个要安装的终端工具。");return}try{const Qe=await Tn.mutateAsync({providers:ee,proxyUrl:Va,model:ie,providerSelections:tx(ee,oe,gl,ie)});ye(`已写入 ${Qe.applied.length} 个配置文件。`),i(5)}catch(Qe){ye(`安装失败:${Qe instanceof Error?Qe.message:String(Qe)}`)}},Za=()=>{X.refetch(),I.refetch(),W.refetch(),Ae.refetch(),ft.refetch(),At.mutate()},Nt=async()=>{me(void 0),$(!0);try{await NS(),me("初始化已标记完成。你可以把 TokenBuddy 安装成桌面应用,之后从系统应用入口打开。"),I.refetch()}catch(ie){me(`完成失败:${ie instanceof Error?ie.message:String(ie)}`)}finally{$(!1)}},jl=async()=>{if(!re){Z("请在浏览器地址栏右侧或菜单里选择“安装应用”。");return}try{Z(void 0),await re.prompt();const ie=await re.userChoice;if(be(null),ie.outcome==="accepted"){M(!0),Z("TokenBuddy 桌面应用已安装。");return}Z("你可以稍后继续使用浏览器安装入口。")}catch(ie){Z(`安装未完成:${ie instanceof Error?ie.message:String(ie)}`)}},Mt=(()=>{var ie,Qe,Lt,ua,Ki,On,_n,Xi,Vi;return a<=1?o.jsx(kS,{commonModels:An,allModels:ra,loading:ft.isLoading,error:ft.error,selectedModels:r,saving:d,saveMessage:h,onToggleModel:us,onSave:cs,onContinue:()=>i(2)}):a===2?o.jsx(ZS,{payments:((ie=W.data)==null?void 0:ie.payments)??[],enabledPaymentCount:ss.length,loading:W.isLoading,qrUrl:(Qe=Oe.data)==null?void 0:Qe.qrImageUrl,rechargeQrUrl:(Lt=bl.data)==null?void 0:Lt.qrImageUrl,walletConfigPresent:(ua=Oe.data)==null?void 0:ua.walletConfigPresent,error:Oe.error,rechargeError:bl.error,binding:Oe.isPending,rechargeLoading:bl.isPending,onBind:au,onLoadRecharge:ds,onRefreshPayments:()=>{W.refetch()},onBack:()=>i(1),onContinue:()=>i(3)}):a===3?o.jsx(XS,{mode:E,scorer:A,sellers:tu,fixedSellerId:B,fixedSetSellerIds:G,saving:ae.isPending,message:L,onModeChange:C,onScorerChange:z,onFixedSellerChange:U,onToggleFixedSetSeller:ot=>{K(Ye=>Ye.includes(ot)?Ye.filter(et=>et!==ot):[...Ye,ot])},onSave:zn,onBack:()=>i(2)}):a===4?o.jsx(JS,{clients:((Ki=Ae.data)==null?void 0:Ki.clients)??[],candidates:sa,loading:Ae.isLoading,selectedProviders:ee,selectedModel:P||gl[0]||"",modelOptions:gl,providerSelections:oe,proxyUrl:Va,previewChanges:(On=ia.data)==null?void 0:On.changes,applying:Tn.isPending,previewing:ia.isPending,message:fe,onToggleProvider:ot=>{le(Ye=>Ye.includes(ot)?Ye.filter(et=>et!==ot):[...Ye,ot])},onModelChange:J,onProviderSelectionChange:(ot,Ye)=>{F(et=>({...et,[ot]:Ye}))},onPreview:nu,onInstall:iu,onBack:()=>i(3)}):a===5?o.jsx(WS,{items:lu,status:(_n=At.data)==null?void 0:_n.status,generatedAt:(Xi=At.data)==null?void 0:Xi.generatedAt,running:At.isPending,error:At.error,onRefresh:Za,onBack:()=>i(4),onContinue:()=>i(6)}):o.jsx(PS,{complete:((Vi=I.data)==null?void 0:Vi.setup.status)==="completed",message:Ee,installMessage:_,canInstall:!!re,installed:ge,saving:D,onBack:()=>i(5),onComplete:Nt,onInstall:jl})})();return o.jsxs("div",{className:"min-w-0 space-y-3",children:[o.jsx(DS,{activeStep:a,onSelect:i}),o.jsx("div",{className:"min-w-0",children:Mt})]})}function DS({activeStep:a,onSelect:i}){return o.jsx("nav",{"aria-label":"初始化步骤",className:"rounded-[12px] border border-[var(--color-line-2)] bg-white p-2.5 shadow-[0_8px_22px_rgba(60,41,112,0.045)]",children:o.jsx("div",{className:"flex items-stretch gap-2 overflow-x-auto",children:Jv.map(r=>{const u=a===r.index,d=a>r.index;return o.jsxs(j.Fragment,{children:[o.jsxs("button",{type:"button",onClick:()=>i(r.index),"aria-current":u?"step":void 0,className:["relative flex min-w-[190px] flex-1 items-center gap-2 rounded-[8px] px-3 py-2 text-left transition",u?"bg-[var(--color-lavender)] ring-1 ring-[var(--color-lavender-2)]":"hover:bg-[var(--color-page)]"].join(" "),children:[o.jsx("span",{className:["grid size-6 shrink-0 place-items-center rounded-full border bg-white",u?"border-[var(--color-purple)] text-[var(--color-purple)] shadow-[0_0_0_3px_rgba(124,61,240,0.1)]":"",d?"border-emerald-200 bg-emerald-50 text-emerald-700":"",!u&&!d?"border-[var(--color-line-2)] text-[var(--color-muted)]":""].join(" "),children:d?o.jsx(Jt,{className:"size-3.5"}):o.jsx("span",{className:"size-1.5 rounded-full bg-current"})}),o.jsxs("span",{className:"min-w-0",children:[o.jsxs("span",{className:["block font-mono text-[0.62rem] font-black uppercase tracking-[0.08em]",u?"text-[var(--color-purple)]":"text-[var(--color-muted)]"].join(" "),children:["STEP ",r.index,":"]}),o.jsx("span",{className:["mt-0.5 block text-[0.82rem] font-semibold",u?"text-[var(--color-purple)]":"text-[var(--color-ink)]"].join(" "),children:r.label}),o.jsx("span",{className:"block truncate text-[0.7rem] text-[var(--color-muted)]",children:r.value})]})]}),r.index<Jv.length?o.jsx("div",{className:"hidden min-w-8 items-center justify-center text-[var(--color-purple)]/70 sm:flex",children:o.jsx(Jo,{className:"size-5",strokeWidth:2.6})}):null]},r.index)})})})}function Yi({index:a,title:i,detail:r,meta:u,action:d}){return o.jsxs("div",{className:"flex flex-col gap-2.5 border-b border-[var(--color-line-2)] pb-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"min-w-0",children:o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("span",{className:"rounded-[7px] bg-[var(--color-lavender)] px-2 py-0.5 font-mono text-[0.68rem] font-semibold text-[var(--color-purple)]",children:String(a).padStart(2,"0")}),o.jsx("div",{className:"text-[0.92rem] font-semibold text-[var(--color-ink)]",children:i}),r?o.jsx("span",{className:"text-[0.74rem] text-[var(--color-muted)]",children:r}):null,u?o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5 font-mono text-[0.68rem] text-[var(--color-muted)]",children:u}):null]})}),d?o.jsx("div",{className:"shrink-0",children:d}):null]})}function kS({commonModels:a,allModels:i,loading:r,error:u,selectedModels:d,saving:m,saveMessage:h,onToggleModel:x,onSave:p,onContinue:v}){const[g,b]=j.useState(!1),E=d.map(C=>i.find(A=>A.id===C)??{id:C,sellerCount:0,protocols:[],paymentMethods:[]});return o.jsxs("div",{className:"space-y-3",children:[o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:1,title:"模型访问",detail:"默认和高频模型",meta:`${d.length} selected`,action:o.jsxs("button",{type:"button",disabled:r||!!u,onClick:()=>b(!0),className:"inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-purple)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple-2)] disabled:cursor-not-allowed disabled:opacity-45",children:[o.jsx(Jd,{className:"size-3.5"}),"添加模型"]})}),u?o.jsxs("div",{className:"mt-3 rounded-[10px] bg-rose-50 px-3 py-2 text-[0.84rem] leading-6 text-rose-700",children:["模型目录加载失败:",u instanceof Error?u.message:String(u)]}):null,E.length===0?o.jsxs("button",{type:"button",disabled:r||!!u,onClick:()=>b(!0),className:"mt-3 flex min-h-[72px] w-full items-center gap-3 rounded-[10px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3 text-left transition hover:border-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[o.jsx("span",{className:"grid size-8 shrink-0 place-items-center rounded-[8px] bg-white text-[var(--color-purple)]",children:o.jsx(Jd,{className:"size-4"})}),o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block text-[0.86rem] font-semibold text-[var(--color-ink)]",children:"添加可能使用到的模型"}),o.jsx("span",{className:"mt-0.5 block text-[0.76rem] text-[var(--color-muted)]",children:"至少选择一个模型后才能保存并继续。"})]})]}):o.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:E.map(C=>o.jsxs("div",{className:"inline-flex min-h-9 max-w-full items-center gap-2 rounded-[9px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-3 py-1.5",children:[o.jsx("span",{className:"truncate font-mono text-[0.82rem] font-semibold text-[var(--color-purple)]",children:C.id}),o.jsx("span",{className:"rounded-full bg-white/70 px-2 py-0.5 text-[0.68rem] font-semibold text-emerald-700",children:"可用"}),o.jsx("button",{type:"button",onClick:()=>x(C.id),className:"inline-flex size-5 items-center justify-center rounded-[6px] text-[var(--color-purple)]/70 hover:bg-white hover:text-[var(--color-purple)]","aria-label":`Remove ${C.id}`,children:o.jsx(Zr,{className:"size-3"})})]},C.id))}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2.5 border-t border-[var(--color-line-2)] pt-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsxs("div",{className:"min-h-5 text-[0.8rem] leading-5 text-[var(--color-muted)]",children:[r?o.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[o.jsx(Et,{className:"size-3.5 animate-spin text-[var(--color-purple)]"})," loading catalog"]}):null,!r&&!u&&d.length===0?o.jsx("span",{children:"请选择至少一个可能使用的模型。"}):null,h?o.jsx("div",{className:"mt-1 font-medium text-[var(--color-ink)]",children:h}):null]}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsxs("button",{type:"button",disabled:m||d.length===0,onClick:p,className:"inline-flex h-9 shrink-0 items-center justify-center gap-2 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[m?o.jsx(Et,{className:"size-3.5 animate-spin"}):null,"保存"]}),o.jsxs("button",{type:"button",disabled:d.length===0,onClick:v,className:"inline-flex h-9 shrink-0 items-center justify-center gap-1.5 rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:["下一步",o.jsx(Jo,{className:"size-3.5"})]})]})]})]}),g?o.jsx(US,{models:a,allModels:i,selectedModelIds:d,onToggle:x,onClose:()=>b(!1)}):null]})}function US({models:a,allModels:i,selectedModelIds:r,onToggle:u,onClose:d}){const[m,h]=j.useState("common"),[x,p]=j.useState(""),v=x.trim(),g=m==="common"?a:v?QS(i,v):[],b=m==="common"?"没有可用的推荐模型。":"输入关键词搜索全部可用模型。",E=[{id:"common",label:"推荐模型",hint:"直接勾选"},{id:"all",label:"搜索添加",hint:"全部模型"}];return o.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[rgba(32,26,56,0.22)] px-3 py-6 backdrop-blur-sm",children:o.jsxs("div",{className:"flex max-h-full w-full max-w-[720px] flex-col overflow-hidden rounded-[14px] border border-[var(--color-line-2)] bg-white shadow-[0_24px_80px_rgba(32,26,56,0.22)]",children:[o.jsxs("div",{className:"flex items-start gap-3 border-b border-[var(--color-line-2)] px-4 py-3",children:[o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"text-[0.72rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Select models"}),o.jsx("h2",{className:"mt-0.5 text-[1rem] font-semibold text-[var(--color-ink)]",children:"选择可能使用到的模型"}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:"推荐模型直接勾选;搜索添加用于查找平台全部模型。"})]}),o.jsxs("div",{className:"mt-0.5 rounded-full bg-[var(--color-lavender)] px-2.5 py-1 font-mono text-[0.72rem] font-semibold text-[var(--color-purple)]",children:[r.length," selected"]}),o.jsx("button",{type:"button",onClick:d,className:"inline-flex size-8 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] text-[var(--color-muted)] hover:text-[var(--color-ink)]","aria-label":"Close model picker",children:o.jsx(Zr,{className:"size-4"})})]}),o.jsxs("div",{className:"border-b border-[var(--color-line-2)] px-4 py-2.5",children:[o.jsx("div",{className:"mb-2 text-[0.72rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"已选模型"}),r.length===0?o.jsx("div",{className:"rounded-[9px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 text-[0.78rem] text-[var(--color-muted)]",children:"还没有选择模型。"}):o.jsx("div",{className:"flex max-h-[92px] flex-wrap gap-1.5 overflow-y-auto pr-1",children:r.map(C=>o.jsxs("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-[8px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-2 py-1",children:[o.jsx("span",{className:"max-w-[220px] truncate font-mono text-[0.72rem] font-semibold text-[var(--color-purple)]",children:C}),o.jsx("button",{type:"button",onClick:()=>u(C),className:"inline-flex size-4 items-center justify-center rounded-[5px] text-[var(--color-purple)]/70 hover:bg-white hover:text-[var(--color-purple)]","aria-label":`Remove ${C}`,children:o.jsx(Zr,{className:"size-3"})})]},C))})]}),o.jsxs("div",{className:"border-b border-[var(--color-line-2)] p-3",children:[o.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:E.map(C=>{const A=m===C.id;return o.jsxs("button",{type:"button",onClick:()=>h(C.id),className:["rounded-[9px] border px-3 py-2 text-left transition",A?"border-[var(--color-purple)] bg-[var(--color-lavender)]":"border-[var(--color-line-2)] bg-white hover:border-[var(--color-lavender-2)]"].join(" "),children:[o.jsx("span",{className:["block text-[0.84rem] font-semibold",A?"text-[var(--color-purple)]":"text-[var(--color-ink)]"].join(" "),children:C.label}),o.jsx("span",{className:"mt-0.5 block text-[0.72rem] text-[var(--color-muted)]",children:C.hint})]},C.id)})}),m==="all"?o.jsxs("label",{className:"relative mt-3 block",children:[o.jsx(Fo,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-[var(--color-muted)]"}),o.jsx("input",{value:x,onChange:C=>p(C.target.value),placeholder:"搜索平台全部模型...",className:"h-10 w-full rounded-[9px] border border-[var(--color-line-2)] bg-white pl-9 pr-3 text-[0.88rem] text-[var(--color-ink)] outline-none transition placeholder:text-[var(--color-muted)] focus:border-[var(--color-purple)]"})]}):null]}),o.jsx("div",{className:"min-h-0 max-h-[320px] overflow-y-auto p-3",children:g.length===0?o.jsx("div",{className:"rounded-[12px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-4 py-8 text-center text-[0.86rem] text-[var(--color-muted)]",children:b}):o.jsx("div",{className:"grid gap-2",children:g.map(C=>{const A=r.includes(C.id);return o.jsxs("button",{type:"button",onClick:()=>u(C.id),"aria-pressed":A,className:["flex items-center gap-3 rounded-[10px] border px-3 py-2 text-left transition",A?"border-[var(--color-purple)] bg-[var(--color-lavender)]":"border-[var(--color-line-2)] bg-white hover:border-[var(--color-lavender-2)]"].join(" "),children:[o.jsx("span",{className:["grid size-6 shrink-0 place-items-center rounded-[7px] border",A?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] bg-white text-transparent"].join(" "),children:o.jsx(Jt,{className:"size-3.5"})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block truncate font-mono text-[0.88rem] font-semibold text-[var(--color-ink)]",children:C.id}),o.jsxs("span",{className:"mt-1 flex flex-wrap gap-1.5 text-[0.72rem] text-[var(--color-muted)]",children:[o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:bf(C.id)}),o.jsx("span",{className:"rounded-full bg-emerald-50 px-2 py-0.5 font-semibold text-emerald-700",children:"可用"}),Pd(C.paymentMethods)?o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:Pd(C.paymentMethods)}):null]})]}),o.jsx("span",{className:["rounded-[7px] px-2 py-1 text-[0.72rem] font-semibold",A?"bg-[var(--color-purple)] text-white":"bg-[var(--color-page)] text-[var(--color-muted)]"].join(" "),children:A?"已选择":"选择"})]},C.id)})})}),o.jsxs("div",{className:"flex flex-col gap-2 border-t border-[var(--color-line-2)] bg-white px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsxs("div",{className:"text-[0.8rem] leading-5 text-[var(--color-muted)]",children:["已选择 ",o.jsx("span",{className:"font-mono font-semibold text-[var(--color-ink)]",children:r.length})," 个模型"]}),o.jsxs("button",{type:"button",onClick:d,"aria-label":"Done",title:"Done selecting models",className:"inline-flex h-9 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)]",children:["完成选择",o.jsx(Jt,{className:"size-3.5"})]})]})]})})}function BS(a){const i=new Map;for(const r of a){const u=i.get(r.id)??{sellers:new Set,protocols:new Set,paymentMethods:new Set};u.sellers.add(r.sellerId);for(const d of r.supportedProtocols)u.protocols.add(d);for(const d of r.paymentMethods)u.paymentMethods.add(d);i.set(r.id,u)}return Array.from(i.entries()).map(([r,u])=>({id:r,sellerCount:u.sellers.size,protocols:Array.from(u.protocols).sort(),paymentMethods:Array.from(u.paymentMethods).sort()})).sort((r,u)=>u.sellerCount!==r.sellerCount?u.sellerCount-r.sellerCount:r.id.localeCompare(u.id))}function HS(a,i,r){const u=LS(a,r);if(u.length>0)return u.slice(0,14);const d=new Set(i),m=new Map;for(const p of i){const v=a.find(g=>g.id===p);v&&m.set(v.id,v)}const h=a.map(p=>({model:p,rank:YS(p.id)})).filter(p=>p.rank<100).sort((p,v)=>p.rank!==v.rank?p.rank-v.rank:v.model.sellerCount!==p.model.sellerCount?v.model.sellerCount-p.model.sellerCount:p.model.id.localeCompare(v.model.id)),x=new Map;for(const p of h){const v=bf(p.model.id),g=x.get(v)??[];g.push(p),x.set(v,g)}for(const p of RS){const v=p==="GPT"?3:p==="Claude"||p==="Gemini"?2:1;for(const g of(x.get(p)??[]).slice(0,v))m.set(g.model.id,g.model)}for(const p of h){if(m.size>=14)break;d.has(p.model.id)||m.set(p.model.id,p.model)}return Array.from(m.values()).slice(0,14)}function LS(a,i){const r=new Map;for(const u of i){const d=qS(a,u,r);d&&r.set(d.id,d)}return Array.from(r.values())}function qS(a,i,r){const u=Ed(i);if(!u)return;const d=a.find(m=>Ed(m.id)===u&&!r.has(m.id));return d||a.find(m=>{if(r.has(m.id))return!1;const h=Ed(m.id);return h.includes(u)||u.includes(h)})}function Ed(a){return a.trim().toLowerCase().replace(/_/g,"-")}function QS(a,i){const r=i.trim().toLowerCase();return r?a.filter(u=>[u.id,bf(u.id),...u.paymentMethods].some(d=>d.toLowerCase().includes(r))):a}function YS(a){const i=a.toLowerCase();return i.includes("gpt-5.5")||i.includes("gpt-5-5")||i.includes("gpt-5_5")?0:i.includes("gpt-5.4")||i.includes("gpt-5-4")||i.includes("gpt-5_4")?1:i.includes("gpt-5")||i.includes("gpt-latest")||i.includes("openai/gpt")?2:i.includes("claude")&&(i.includes("4.8")||i.includes("4-8"))?3:i.includes("claude")&&i.includes("opus")?4:i.includes("claude")&&i.includes("sonnet")?5:i.includes("claude")?6:i.includes("gemini")&&(i.includes("3.1")||i.includes("3-1"))?7:i.includes("gemini")&&i.includes("pro")?8:i.includes("gemini")?9:i.includes("deepseek")?10:i.includes("kimi")||i.includes("moonshot")?11:i.includes("qwen")||i.includes("tongyi")?12:i.includes("minimax")?13:i.includes("glm")||i.includes("zhipu")?14:i.includes("doubao")||i.includes("bytedance")?15:i.includes("grok")?16:100}function bf(a){const i=a.toLowerCase();return i.includes("gpt")||i.includes("openai")?"GPT":i.includes("claude")||i.includes("anthropic")?"Claude":i.includes("gemini")||i.includes("google")?"Gemini":i.includes("deepseek")?"DeepSeek":i.includes("kimi")||i.includes("moonshot")?"Kimi":i.includes("qwen")||i.includes("tongyi")?"Qwen":i.includes("minimax")?"MiniMax":i.includes("glm")||i.includes("zhipu")?"GLM":i.includes("doubao")||i.includes("bytedance")?"Doubao":i.includes("grok")?"Grok":"Common"}function Pd(a){return a.length===0?"":`${GS(a.map(KS)).join("、")}`}function GS(a){return Array.from(new Set(a))}function KS(a){const i=eu(a);return i.includes("x402")?"X402":i.includes("clawtip")?"ClawTip":i.includes("wallet")?"钱包":i.includes("mock")||i.includes("test")?"测试":"其它"}function eu(a){return a.trim().toLowerCase()}function XS({mode:a,scorer:i,sellers:r,fixedSellerId:u,fixedSetSellerIds:d,saving:m,message:h,onModeChange:x,onScorerChange:p,onFixedSellerChange:v,onToggleFixedSetSeller:g,onSave:b,onBack:E}){const C=a!=="fullAuto";return o.jsxs("div",{className:"space-y-3",children:[o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:3,title:"配置策略",detail:"路由规则",meta:`${T0(a)} / ${fN(i)}`}),o.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-2",children:[o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-2.5",children:[o.jsx("div",{className:"mb-2 text-[0.78rem] font-semibold text-[var(--color-ink)]",children:"路由模式"}),o.jsx("div",{className:"grid gap-2",children:ES.map(A=>o.jsxs("button",{type:"button",onClick:()=>x(A.value),className:["rounded-[9px] border bg-white p-2.5 text-left transition",a===A.value?"border-[var(--color-purple)] bg-[var(--color-lavender)]":"border-[var(--color-line-2)] bg-white hover:border-[var(--color-lavender-2)]"].join(" "),children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:["grid size-5 place-items-center rounded-full border",a===A.value?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] text-transparent"].join(" "),children:o.jsx(Jt,{className:"size-3"})}),o.jsx("span",{className:"text-[0.84rem] font-semibold text-[var(--color-ink)]",children:A.title})]}),o.jsx("p",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:A.body})]},A.value))})]}),o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-2.5",children:[o.jsx("div",{className:"mb-2 text-[0.78rem] font-semibold text-[var(--color-ink)]",children:"优化目标"}),o.jsx("div",{className:"grid gap-2",children:AS.map(A=>o.jsxs("button",{type:"button",onClick:()=>p(A.value),className:["rounded-[9px] border bg-white p-2.5 text-left transition",i===A.value?"border-[var(--color-purple)] bg-[var(--color-lavender)]":"border-[var(--color-line-2)] bg-white hover:border-[var(--color-lavender-2)]"].join(" "),children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:["grid size-5 place-items-center rounded-full border",i===A.value?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] text-transparent"].join(" "),children:o.jsx(Jt,{className:"size-3"})}),o.jsx("span",{className:"text-[0.84rem] font-semibold text-[var(--color-ink)]",children:A.title})]}),o.jsx("p",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:A.body})]},A.value))})]})]}),C?o.jsxs("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-white p-3",children:[o.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"text-[0.8rem] font-semibold text-[var(--color-ink)]",children:"选择供应商"}),o.jsx("div",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5 text-[0.72rem] text-[var(--color-muted)]",children:a==="fixed"?u?"已选择 1 个":"尚未选择":`已选择 ${d.length} 个`})]}),r.length===0?o.jsx("div",{className:"mt-2 rounded-[9px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3 text-[0.8rem] leading-5 text-[var(--color-muted)]",children:"正在等待供应商目录。你也可以先返回上一步确认模型目录是否已经加载完成。"}):o.jsx(VS,{mode:a,sellers:r,fixedSellerId:u,fixedSetSellerIds:d,onFixedSellerChange:v,onToggleFixedSetSeller:g})]}):o.jsx("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 text-[0.8rem] leading-5 text-[var(--color-muted)]",children:"当前是全自动模式,TokenBuddy 会根据模型、供应商健康度、速度、价格和余额状态自动规划调用路径。"})]}),o.jsx(j0,{backLabel:"上一步:绑定钱包",nextLabel:"下一步:配置工具",saving:m,message:h,onBack:E,onNext:b})]})}function VS({mode:a,sellers:i,fixedSellerId:r,fixedSetSellerIds:u,onFixedSellerChange:d,onToggleFixedSetSeller:m}){const[h,x]=j.useState({key:"status",direction:"asc"}),p=j.useMemo(()=>S0(i,h),[i,h]),v=b=>{x(E=>({key:b,direction:E.key===b&&E.direction==="asc"?"desc":"asc"}))},g=b=>{if(a==="fixed"){d(b);return}m(b)};return o.jsx("div",{className:"mt-2 overflow-hidden rounded-[9px] border border-[var(--color-line-2)]",children:o.jsx("div",{className:"max-h-[300px] overflow-auto",children:o.jsxs("table",{className:"min-w-[760px] w-full border-collapse text-left text-[0.78rem]",children:[o.jsx("thead",{className:"sticky top-0 z-10 border-b border-[var(--color-line-2)] bg-[var(--color-page)] text-[0.68rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"w-12 px-2 py-2 font-semibold",children:"选"}),o.jsx(ji,{label:"供应商",sortKey:"name",sort:h,onSort:v}),o.jsx(ji,{label:"状态",sortKey:"status",sort:h,onSort:v}),o.jsx(ji,{label:"模型",sortKey:"models",sort:h,onSort:v,align:"right"}),o.jsx(ji,{label:"价格",sortKey:"price",sort:h,onSort:v}),o.jsx(ji,{label:"折扣",sortKey:"discount",sort:h,onSort:v,align:"right"}),o.jsx(ji,{label:"响应",sortKey:"speed",sort:h,onSort:v,align:"right"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"支付"})]})}),o.jsx("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:p.map(b=>{const E=a==="fixed"?r===b.id:u.includes(b.id);return o.jsxs("tr",{onClick:()=>g(b.id),className:["cursor-pointer transition hover:bg-[var(--color-lavender)]/45",E?"bg-[var(--color-lavender)]/70":"bg-white"].join(" "),children:[o.jsx("td",{className:"px-2 py-2.5",children:o.jsx("span",{className:["grid size-5 place-items-center rounded-full border",E?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] text-transparent"].join(" "),children:o.jsx(Jt,{className:"size-3"})})}),o.jsxs("td",{className:"max-w-[210px] px-3 py-2.5",children:[o.jsx("div",{className:"truncate font-semibold text-[var(--color-ink)]",children:b.name}),o.jsx("div",{className:"mt-0.5 truncate font-mono text-[0.68rem] text-[var(--color-muted)]",children:b.id})]}),o.jsx("td",{className:"px-3 py-2.5",children:o.jsx("span",{className:["inline-flex whitespace-nowrap rounded-full px-2 py-0.5 text-[0.7rem] font-semibold",hN(b.status)].join(" "),children:mN(b.status)})}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono font-semibold text-[var(--color-ink)]",children:b.modelCount}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 font-mono text-[0.72rem] text-[var(--color-ink)]",children:tN(b.minInputPriceMicrosPer1m,b.minOutputPriceMicrosPer1m)}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono font-semibold text-[var(--color-purple)]",children:lN(b.discountRatio)}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:aN(b.avgResponseMs,b.avgTtftMs)}),o.jsx("td",{className:"max-w-[150px] px-3 py-2.5",children:o.jsx("div",{className:"truncate text-[0.72rem] text-[var(--color-muted)]",children:Pd(b.paymentMethods)||"—"})})]},b.id)})})]})})})}function ji({label:a,sortKey:i,sort:r,align:u="left",onSort:d}){const m=r.key===i,h=m?r.direction==="asc"?"↑":"↓":"↕";return o.jsx("th",{className:["px-3 py-2 font-semibold",u==="right"?"text-right":"text-left"].join(" "),children:o.jsxs("button",{type:"button",onClick:()=>d(i),className:["inline-flex items-center gap-1 rounded-[6px] px-1.5 py-1 transition hover:bg-white",u==="right"?"justify-end":"justify-start",m?"text-[var(--color-purple)]":"text-[var(--color-muted)]"].join(" "),children:[o.jsx("span",{children:a}),o.jsx("span",{className:"font-mono text-[0.66rem]",children:h})]})})}function ZS({payments:a,enabledPaymentCount:i,loading:r,qrUrl:u,rechargeQrUrl:d,walletConfigPresent:m,error:h,rechargeError:x,binding:p,rechargeLoading:v,onBind:g,onLoadRecharge:b,onRefreshPayments:E,onBack:C,onContinue:A}){const[z,B]=j.useState("clawtip"),[U,G]=j.useState(!1),[K,L]=j.useState(!1),V=a.find(D=>eu(D.method)==="clawtip"),P=!!(V!=null&&V.enabled||m||$S(V==null?void 0:V.config,"walletConfigPresent")),J=U&&P,ee=[{method:"clawtip",name:"ClawTip",detail:"JD App 扫码 / 微支付",status:P?"已绑定":"可绑定",available:!0},...zS.map(D=>({...D,status:"Coming soon",available:!1}))],le=ee.find(D=>D.method===z)??ee[0],oe=le.method==="clawtip",F=oe&&P&&!J,fe=J||F||U,ye=oe?fe:!0,Ee=()=>{G(!0),g()},me=()=>{L(!0),b()};return j.useEffect(()=>{if(!oe||!U||P)return;const D=window.setInterval(E,1500);return()=>window.clearInterval(D)},[U,P,E,oe]),j.useEffect(()=>{!F||d||v||K||(L(!0),b())},[b,v,d,K,F]),o.jsxs("div",{className:"space-y-3",children:[o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:2,title:"选择支付方式",detail:"钱包和充值通道",meta:r?"checking":`${i} active`,action:oe&&F?o.jsxs("button",{type:"button",disabled:v,onClick:me,className:"inline-flex h-8 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[v?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx(Bi,{className:"size-3.5"}),"刷新充值码"]}):oe&&U&&!P?o.jsxs("button",{type:"button",disabled:p,onClick:Ee,className:"inline-flex h-8 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[p?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx(Gr,{className:"size-3.5"}),"重新生成"]}):oe&&!U&&!P?o.jsxs("button",{type:"button",disabled:p,onClick:Ee,className:"inline-flex h-8 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[p?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx(Gr,{className:"size-3.5"}),"开始绑定"]}):oe?null:o.jsx("span",{className:"inline-flex h-8 items-center rounded-[8px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-2.5 font-mono text-[0.72rem] font-semibold text-[var(--color-muted)]",children:"Coming soon"})}),o.jsxs("div",{className:["mt-3 grid gap-3",ye?"lg:grid-cols-[minmax(0,300px)_minmax(0,1fr)]":"lg:max-w-[360px]"].join(" "),children:[o.jsx("div",{className:"grid content-start gap-2",children:ee.map(D=>{const $=D.method===le.method;return o.jsxs("button",{type:"button",onClick:()=>B(D.method),"aria-pressed":$,className:["grid min-h-[64px] grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-[10px] border px-3 py-2 text-left transition",$?"border-[var(--color-purple)] bg-[var(--color-lavender)] shadow-[0_8px_22px_rgba(124,61,240,0.08)]":"border-[var(--color-line-2)] bg-white hover:bg-[var(--color-page)]"].join(" "),children:[o.jsx("span",{className:["grid size-9 shrink-0 place-items-center rounded-[9px] border",$?"border-[var(--color-lavender-2)] bg-white text-[var(--color-purple)]":"border-[var(--color-line-2)] bg-[var(--color-page)] text-[var(--color-muted)]"].join(" "),children:Fv(D.method)}),o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block truncate text-[0.86rem] font-semibold text-[var(--color-ink)]",children:D.name}),o.jsx("span",{className:"mt-0.5 block truncate text-[0.73rem] text-[var(--color-muted)]",children:D.detail})]}),o.jsx("span",{className:["rounded-full px-2 py-0.5 text-[0.68rem] font-semibold",D.available?"bg-emerald-50 text-emerald-700":"bg-[var(--color-page)] text-[var(--color-muted)]"].join(" "),children:D.status})]},D.method)})}),oe?fe?o.jsx("div",{className:"flex min-h-[360px] items-center justify-center rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-4",children:J?o.jsx("div",{className:"grid size-full min-h-[320px] place-items-center rounded-[10px] border border-emerald-100 bg-emerald-50 px-4 py-5 text-center",children:o.jsxs("div",{children:[o.jsx(Jt,{className:"mx-auto size-8 text-emerald-700"}),o.jsx("div",{className:"mt-3 text-[0.92rem] font-semibold text-emerald-900",children:"绑定成功"}),o.jsx("div",{className:"mt-1 text-[0.78rem] leading-5 text-emerald-800",children:"ClawTip 钱包已经写入本机配置,可以继续配置路由策略。"})]})}):F?d?o.jsx("img",{src:d,alt:"ClawTip 充值二维码",className:"max-h-[340px] w-full max-w-[340px] rounded-[10px] border border-[var(--color-line-2)] bg-white p-3 object-contain shadow-[0_12px_28px_rgba(15,23,42,0.1)]"}):o.jsx("div",{className:"grid size-full min-h-[320px] place-items-center rounded-[10px] border border-dashed border-[var(--color-line-2)] bg-white px-3 py-4 text-center",children:o.jsxs("div",{children:[v?o.jsx(Et,{className:"mx-auto size-6 animate-spin text-[var(--color-purple)]"}):o.jsx(Bi,{className:"mx-auto size-6 text-[var(--color-purple)]"}),o.jsx("div",{className:"mt-2 text-[0.84rem] font-semibold text-[var(--color-ink)]",children:v?"正在加载充值码":"充值码未加载"}),o.jsx("button",{type:"button",disabled:v,onClick:me,className:"mt-3 inline-flex h-8 items-center justify-center rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:"重新加载"})]})}):U&&u?o.jsx("img",{src:u,alt:"ClawTip 钱包绑定二维码",className:"max-h-[340px] w-full max-w-[340px] rounded-[10px] border border-[var(--color-line-2)] bg-white p-3 object-contain shadow-[0_12px_28px_rgba(15,23,42,0.1)]"}):U?o.jsx("div",{className:"grid size-full min-h-[320px] place-items-center rounded-[10px] border border-dashed border-[var(--color-line-2)] bg-white px-3 py-4 text-center",children:o.jsxs("div",{children:[p?o.jsx(Et,{className:"mx-auto size-6 animate-spin text-[var(--color-purple)]"}):o.jsx(Gr,{className:"mx-auto size-6 text-[var(--color-purple)]"}),o.jsx("div",{className:"mt-2 text-[0.84rem] font-semibold text-[var(--color-ink)]",children:p?"正在生成绑定码":"等待绑定码"}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:"生成后使用京东 App 扫码绑定。"})]})}):null}):null:o.jsx("div",{className:"grid min-h-[220px] place-items-center rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-4 text-center",children:o.jsxs("div",{className:"max-w-[360px]",children:[o.jsx("span",{className:"mx-auto grid size-11 place-items-center rounded-[12px] border border-[var(--color-line-2)] bg-white text-[var(--color-purple)]",children:Fv(le.method)}),o.jsx("div",{className:"mt-3 text-[0.92rem] font-semibold text-[var(--color-ink)]",children:le.name}),o.jsxs("div",{className:"mt-1 text-[0.78rem] leading-5 text-[var(--color-muted)]",children:[le.detail,"。当前版本先通过 ClawTip 完成钱包绑定,后续会在这里接入更多支付流程。"]}),o.jsx("div",{className:"mt-3 inline-flex rounded-full bg-white px-3 py-1 font-mono text-[0.7rem] font-semibold text-[var(--color-muted)]",children:"Coming soon"})]})})]}),oe&&!P&&U&&h?o.jsxs("div",{className:"mt-3 rounded-[10px] bg-rose-50 px-3 py-2 text-[0.84rem] leading-6 text-rose-700",children:["生成二维码失败:",h instanceof Error?h.message:String(h)]}):null,oe&&F&&x?o.jsxs("div",{className:"mt-3 rounded-[10px] bg-rose-50 px-3 py-2 text-[0.84rem] leading-6 text-rose-700",children:["加载充值二维码失败:",x instanceof Error?x.message:String(x)]}):null]}),o.jsx(j0,{backLabel:"上一步:模型访问",nextLabel:"下一步:配置策略",message:i>0?"支付方式已可用,可以继续配置路由策略。":"如果你暂时跳过绑定,后续首次购买模型额度时仍需要完成支付配置。",onBack:C,onNext:A})]})}function Fv(a){const i=eu(a);return i==="wechat-pay"?o.jsx(ej,{className:"size-4"}):i==="alipay-agent"?o.jsx(B2,{className:"size-4"}):i==="coinbase-smart-wallet"?o.jsx(Bi,{className:"size-4"}):o.jsx(Gr,{className:"size-4"})}function $S(a,i){const r=a==null?void 0:a[i];return r===!0||r==="true"||r===1||r==="1"}function JS({clients:a,candidates:i,loading:r,selectedProviders:u,selectedModel:d,modelOptions:m,providerSelections:h,proxyUrl:x,previewChanges:p,applying:v,previewing:g,message:b,onToggleProvider:E,onModelChange:C,onProviderSelectionChange:A,onPreview:z,onInstall:B,onBack:U}){var oe;const G=new Set(i.map(F=>F.id)),K=i.length,L=a.find(F=>F.id==="custom")??w0(x),V=[...a.filter(F=>F.id!=="custom"),{...L,name:"其他工具"}],P=((oe=V[0])==null?void 0:oe.id)??"custom",[J,ee]=j.useState(P),le=V.find(F=>F.id===J)??V[0]??L;return j.useEffect(()=>{var F;V.some(fe=>fe.id===J)||ee(((F=V[0])==null?void 0:F.id)??"custom")},[J,V]),o.jsxs("div",{className:"space-y-3",children:[o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:4,title:"配置工具",detail:"终端接入",meta:`${u.length} selected / ${K} detected`,action:r?o.jsx(Et,{className:"size-4 animate-spin text-[var(--color-purple)]"}):null}),o.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,320px)_minmax(0,1fr)]",children:[o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-2.5",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("div",{className:"text-[0.8rem] font-semibold text-[var(--color-ink)]",children:"工具"}),o.jsxs("div",{className:"rounded-full bg-white px-2 py-0.5 text-[0.72rem] text-[var(--color-muted)]",children:[a.length," tools"]})]}),o.jsx("div",{className:"mt-2 grid max-h-[380px] gap-2 overflow-y-auto pr-1",children:V.map(F=>{const fe=F.id!=="custom"&&G.has(F.id),ye=u.includes(F.id),Ee=le.id===F.id;return o.jsx("button",{type:"button",onClick:()=>ee(F.id),className:["rounded-[10px] border p-2.5 text-left transition",Ee?"border-[var(--color-purple)] bg-white shadow-[0_10px_24px_rgba(60,41,112,0.08)]":"border-[var(--color-line-2)] bg-white/70 hover:border-[var(--color-lavender-2)]"].join(" "),children:o.jsxs("div",{className:"flex items-start gap-2.5",children:[o.jsx("span",{className:["mt-0.5 grid size-6 shrink-0 place-items-center rounded-[8px] border text-[0.72rem] font-semibold",Ee?"border-[var(--color-purple)] bg-[var(--color-lavender)] text-[var(--color-purple)]":"border-[var(--color-line-2)] bg-white text-[var(--color-muted)]"].join(" "),children:nN(F.name)}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("div",{className:"truncate text-[0.84rem] font-semibold text-[var(--color-ink)]",children:F.name}),ye?o.jsx("span",{className:"rounded-full bg-emerald-50 px-1.5 py-0.5 text-[0.66rem] font-semibold text-emerald-700",children:"安装"}):null]}),o.jsxs("div",{className:"mt-1 flex flex-wrap gap-1.5 text-[0.68rem] text-[var(--color-muted)]",children:[o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:E0(F)}),F.commandName?o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:F.commandName}):null,F.id==="custom"?o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:"复制配置"}):null]})]}),F.id!=="custom"?o.jsx("span",{"aria-hidden":"true",className:["mt-0.5 grid size-5 shrink-0 place-items-center rounded-full border",ye?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] text-transparent",fe?"":"opacity-45"].join(" "),children:o.jsx(Jt,{className:"size-3"})}):null]})},F.id)})})]}),o.jsx("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-white p-3",children:o.jsx(FS,{client:le,selected:u.includes(le.id),installable:le.id!=="custom"&&G.has(le.id),selectedModel:d,modelOptions:m,providerSelections:h,proxyUrl:x,onToggleInstall:()=>E(le.id),onModelChange:C,onProviderSelectionChange:A})})]}),p?o.jsxs("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-white p-3",children:[o.jsx("div",{className:"text-[0.8rem] font-semibold text-[var(--color-ink)]",children:"配置文件变更"}),p.length===0?o.jsx("div",{className:"mt-2 rounded-[9px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3 text-[0.8rem] text-[var(--color-muted)]",children:"没有需要写入的配置变更。"}):o.jsx("div",{className:"mt-2 grid max-h-[180px] gap-2 overflow-y-auto pr-1",children:p.map(F=>o.jsxs("div",{className:"rounded-[9px] border border-[var(--color-line-2)] bg-white p-2.5",children:[o.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[0.78rem] font-semibold text-[var(--color-ink)]",children:[o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:pN(F.action)}),o.jsx("span",{children:F.providerId})]}),o.jsx("div",{className:"mt-1 truncate font-mono text-[0.72rem] text-[var(--color-muted)]",children:F.path}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:F.summary})]},`${F.providerId}:${F.path}:${F.summary}`))})]}):null]}),o.jsxs(jt,{className:"flex flex-col gap-3 p-3 lg:flex-row lg:items-center lg:justify-between",children:[o.jsx("div",{className:"text-[0.84rem] leading-6 text-[var(--color-muted)]",children:b?o.jsx("div",{className:"mt-1 font-medium text-[var(--color-ink)]",children:b}):null}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",onClick:U,className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-muted)] transition hover:text-[var(--color-ink)]",children:"上一步:配置策略"}),o.jsxs("button",{type:"button",disabled:g||u.length===0,onClick:z,className:"inline-flex h-9 items-center justify-center gap-2 rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[g?o.jsx(Et,{className:"size-4 animate-spin"}):null,"预览安装"]}),o.jsxs("button",{type:"button",disabled:v||u.length===0,onClick:B,className:"inline-flex h-9 items-center justify-center gap-2 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[v?o.jsx(Et,{className:"size-4 animate-spin"}):null,"写入配置"]})]})]})]})}function FS({client:a,selected:i,installable:r,selectedModel:u,modelOptions:d,providerSelections:m,proxyUrl:h,onToggleInstall:x,onModelChange:p,onProviderSelectionChange:v}){var E,C,A;if(a.id==="custom"){const z=a.manualConfig??w0(h).manualConfig;return o.jsxs("div",{className:"space-y-3",children:[o.jsx(Ad,{client:a,selected:!1,installable:!1}),o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Qr,{label:"OpenAI base URL",value:(z==null?void 0:z.openaiBaseUrl)??C0(h)}),o.jsx(Qr,{label:"Anthropic base URL",value:(z==null?void 0:z.anthropicBaseUrl)??h}),o.jsx(Qr,{label:"API key",value:(z==null?void 0:z.apiKey)??"TOKENBUDDY_PROXY"})]}),o.jsx("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:"其他工具只需要填入本地推理服务接口和 key,不会写入本机配置文件。"})]})}if(a.id==="claude-code"){const z=M0(m[a.id],d,u),B=(G,K)=>{v(a.id,{...z,fallbackModel:z.fallbackModel||K||u,roles:{...z.roles,[G]:K?{upstreamModel:K,displayName:K}:void 0}})},U=G=>{v(a.id,{...z,fallbackModel:G}),p(G)};return o.jsxs("div",{className:"space-y-3",children:[o.jsx(Ad,{client:a,selected:i,installable:r,onToggleInstall:x}),o.jsxs("div",{className:"grid gap-2 lg:grid-cols-2",children:[o.jsx(qr,{label:"Fallback",value:z.fallbackModel??u,modelOptions:d,onChange:U}),o.jsx(qr,{label:"Haiku",value:((E=z.roles.haiku)==null?void 0:E.upstreamModel)??"",modelOptions:d,onChange:G=>B("haiku",G)}),o.jsx(qr,{label:"Sonnet",value:((C=z.roles.sonnet)==null?void 0:C.upstreamModel)??"",modelOptions:d,onChange:G=>B("sonnet",G)}),o.jsx(qr,{label:"Opus",value:((A=z.roles.opus)==null?void 0:A.upstreamModel)??"",modelOptions:d,onChange:G=>B("opus",G)})]}),o.jsx("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:"Claude Code 会把 Haiku、Sonnet、Opus 三种客户端模型映射到你选择的上游模型。"})]})}const g=N0(a.id,m[a.id],u),b=z=>{p(z),v(a.id,{selectionKind:"single-model",protocolPreference:Id(a.id),defaultModel:z})};return o.jsxs("div",{className:"space-y-3",children:[o.jsx(Ad,{client:a,selected:i,installable:r,onToggleInstall:x}),o.jsx(qr,{label:"模型",value:g.defaultModel,modelOptions:d,onChange:b}),o.jsxs("div",{className:"grid gap-2 lg:grid-cols-2",children:[o.jsx(Qr,{label:"Proxy URL",value:h,compact:!0}),o.jsx(Qr,{label:"API key",value:"TOKENBUDDY_PROXY",compact:!0})]}),a.configPath?o.jsx("div",{className:"truncate rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 font-mono text-[0.72rem] text-[var(--color-muted)]",children:a.configPath}):null]})}function Ad({client:a,selected:i,installable:r,onToggleInstall:u}){return o.jsxs("div",{className:"flex flex-col gap-2 border-b border-[var(--color-line-2)] pb-3 sm:flex-row sm:items-start sm:justify-between",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("div",{className:"text-[0.9rem] font-semibold text-[var(--color-ink)]",children:a.name}),o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5 text-[0.7rem] text-[var(--color-muted)]",children:E0(a)})]}),o.jsx("div",{className:"mt-1 text-[0.74rem] leading-5 text-[var(--color-muted)]",children:a.reason})]}),a.id!=="custom"?o.jsxs("button",{type:"button",disabled:!r,onClick:u,className:["inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-[8px] px-2.5 text-[0.78rem] font-semibold transition disabled:cursor-not-allowed disabled:opacity-45",i?"bg-[var(--color-purple)] text-white hover:bg-[var(--color-purple-2)]":"border border-[var(--color-line-2)] bg-white text-[var(--color-ink)] hover:border-[var(--color-purple)]"].join(" "),children:[o.jsx(Jt,{className:"size-3.5"}),i?"已加入安装":"加入安装"]}):null]})}function qr({label:a,value:i,modelOptions:r,onChange:u}){return o.jsxs("label",{className:"block",children:[o.jsx("span",{className:"text-[0.74rem] font-semibold text-[var(--color-muted)]",children:a}),o.jsxs("select",{value:i,onChange:d=>u(d.target.value),className:"mt-1 h-9 w-full rounded-[8px] border border-[var(--color-line-2)] bg-white px-2.5 text-[0.82rem] text-[var(--color-ink)] outline-none focus:border-[var(--color-purple)]",children:[o.jsx("option",{value:"",children:"请选择模型"}),r.map(d=>o.jsx("option",{value:d,children:d},d))]})]})}function Qr({label:a,value:i,compact:r=!1}){const[u,d]=j.useState(!1),m=async()=>{try{await navigator.clipboard.writeText(i),d(!0),window.setTimeout(()=>d(!1),1200)}catch{d(!1)}};return o.jsxs("div",{className:["rounded-[10px] border border-[var(--color-line-2)] bg-white px-3 py-2",r?"min-w-0":""].join(" "),children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("div",{className:"text-[0.72rem] font-semibold text-[var(--color-muted)]",children:a}),o.jsxs("button",{type:"button",onClick:m,className:"inline-flex h-7 items-center justify-center gap-1 rounded-[7px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-2 text-[0.7rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)]",children:[o.jsx(T2,{className:"size-3"}),u?"已复制":"复制"]})]}),o.jsx("div",{className:"mt-1 truncate font-mono text-[0.76rem] text-[var(--color-ink)]",children:i})]})}function WS({items:a,status:i,generatedAt:r,running:u,error:d,onRefresh:m,onBack:h,onContinue:x}){return o.jsx("div",{className:"space-y-3",children:o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:5,title:"验证网关",detail:"本机状态",meta:u?"checking":lx(i),action:o.jsxs("button",{type:"button",disabled:u,onClick:m,className:"inline-flex h-8 items-center justify-center gap-1.5 rounded-[8px] border border-[var(--color-line-2)] bg-white px-2.5 text-[0.78rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[u?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx($d,{className:"size-3.5"}),"刷新"]})}),o.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[0.76rem] text-[var(--color-muted)]",children:[o.jsx("span",{className:["rounded-full px-2 py-0.5 font-semibold",oN(i)].join(" "),children:u?"正在检查":lx(i)}),r?o.jsxs("span",{children:["检查时间:",new Date(r).toLocaleString()]}):o.jsx("span",{children:"等待后端检查。"})]}),d?o.jsxs("div",{className:"mt-3 rounded-[10px] bg-rose-50 px-3 py-2 text-[0.82rem] leading-6 text-rose-700",children:["检查失败:",d instanceof Error?d.message:String(d)]}):null,o.jsx("div",{className:"mt-3 grid gap-2 xl:grid-cols-2",children:a.map(p=>o.jsxs("div",{className:"flex gap-2.5 rounded-[10px] border border-[var(--color-line-2)] bg-white p-2.5",children:[o.jsx("span",{className:["mt-0.5 grid size-6 shrink-0 place-items-center rounded-full",cN(p.status)].join(" "),children:p.ok?o.jsx(Jt,{className:"size-3.5"}):o.jsx($d,{className:"size-3.5"})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-[0.82rem] font-semibold text-[var(--color-ink)]",children:[p.title,o.jsx("span",{className:["rounded-full px-1.5 py-0.5 text-[0.68rem]",dN(p.status)].join(" "),children:uN(p.status)})]}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:p.body})]})]},p.title))}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2 border-t border-[var(--color-line-2)] pt-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"text-[0.78rem] leading-5 text-[var(--color-muted)]",children:"发现异常时返回对应步骤补齐配置。"}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-muted)] transition hover:text-[var(--color-ink)]",children:"上一步"}),o.jsxs("button",{type:"button",onClick:x,className:"inline-flex h-9 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)]",children:["下一步",o.jsx(Jo,{className:"size-3.5"})]})]})]})]})})}function PS({complete:a,message:i,installMessage:r,canInstall:u,installed:d,saving:m,onBack:h,onComplete:x,onInstall:p}){return o.jsx("div",{className:"space-y-3",children:o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:6,title:a?"初始化完成":"桌面应用",detail:d?"已安装":"可选安装",meta:a?"complete":d?"installed":"optional",action:o.jsxs("button",{type:"button",disabled:d,onClick:p,className:"inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[o.jsx(Jt,{className:"size-3.5"}),d?"已安装":"安装应用"]})}),o.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,290px)_minmax(0,1fr)]",children:[o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-3",children:[o.jsx("div",{className:"text-[0.84rem] font-semibold text-[var(--color-ink)]",children:d?"TokenBuddy 桌面应用已安装":u?"浏览器支持直接安装":"可从浏览器菜单安装"}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:d?"你可以从系统应用入口打开 TokenBuddy。":u?"点击右上角安装按钮并确认浏览器弹窗。":"在地址栏右侧或浏览器菜单中找到安装应用入口。"}),r?o.jsx("div",{className:"mt-2 text-[0.78rem] font-medium text-[var(--color-ink)]",children:r}):null]}),o.jsx("div",{className:"grid gap-2 lg:grid-cols-3",children:[{title:"安装入口",body:"地址栏或浏览器菜单。"},{title:"应用名称",body:"TokenBuddy。"},{title:"本地服务",body:"继续由 tb-proxyd 提供。"}].map((v,g)=>o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-white p-2.5",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"grid size-5 place-items-center rounded-full bg-[var(--color-lavender)] font-mono text-[0.68rem] font-semibold text-[var(--color-purple)]",children:g+1}),o.jsx("span",{className:"text-[0.8rem] font-semibold text-[var(--color-ink)]",children:v.title})]}),o.jsx("div",{className:"mt-1 text-[0.74rem] leading-5 text-[var(--color-muted)]",children:v.body})]},v.title))})]}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2 border-t border-[var(--color-line-2)] pt-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"text-[0.78rem] leading-5 text-[var(--color-muted)]",children:i?o.jsx("span",{className:"font-medium text-[var(--color-ink)]",children:i}):"完成后可以进入控制台。"}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-muted)] transition hover:text-[var(--color-ink)]",children:"上一步"}),o.jsxs("button",{type:"button",disabled:m||a,onClick:x,className:"inline-flex h-9 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[m?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx(Jt,{className:"size-3.5"}),a?"已完成":"完成初始化"]}),o.jsx(ns,{to:"/overview",className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)]",children:"进入控制台"})]})]})]})})}function j0({backLabel:a,nextLabel:i,saving:r=!1,message:u,onBack:d,onNext:m}){return o.jsxs(jt,{className:"flex flex-col gap-2.5 p-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"text-[0.78rem] leading-5 text-[var(--color-muted)]",children:u??"配置完成后继续下一步。"}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",onClick:d,className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-muted)] transition hover:text-[var(--color-ink)]",children:a}),o.jsxs("button",{type:"button",disabled:r,onClick:m,className:"inline-flex h-9 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[r?o.jsx(Et,{className:"size-3.5 animate-spin"}):null,i,r?null:o.jsx(Jo,{className:"size-3.5"})]})]})]})}function IS(a,i,r){const u=new Map;for(const h of i){const x=u.get(h.sellerId)??{modelIds:new Set,protocols:new Set,paymentMethods:new Set,responseMsSamples:[],ttftMsSamples:[]};x.modelIds.add(h.id);for(const p of h.supportedProtocols)x.protocols.add(p);for(const p of h.paymentMethods)x.paymentMethods.add(p);x.minInputPriceMicrosPer1m=Pv(x.minInputPriceMicrosPer1m,h.inputPriceMicrosPer1m),x.minOutputPriceMicrosPer1m=Pv(x.minOutputPriceMicrosPer1m,h.outputPriceMicrosPer1m),u.set(h.sellerId,x)}for(const h of r){const x=h.sellerKey;if(!x)continue;const p=u.get(x)??{modelIds:new Set,protocols:new Set,paymentMethods:new Set,responseMsSamples:[],ttftMsSamples:[]};Number.isFinite(h.durationMs)&&p.responseMsSamples.push(h.durationMs),Number.isFinite(h.ttftMs)&&p.ttftMsSamples.push(h.ttftMs),u.set(x,p)}const d=a.map(h=>{const x=u.get(h.id);return{id:h.id,name:Iv(h.name??h.manifestSellerId??h.id),status:h.status,modelCount:h.modelCount??(x==null?void 0:x.modelIds.size)??0,protocols:h.supportedProtocols??Array.from((x==null?void 0:x.protocols)??[]),paymentMethods:h.paymentMethods??Array.from((x==null?void 0:x.paymentMethods)??[]),discountRatio:h.discountRatio,serviceFeeRatio:h.serviceFeeRatio,minInputPriceMicrosPer1m:x==null?void 0:x.minInputPriceMicrosPer1m,minOutputPriceMicrosPer1m:x==null?void 0:x.minOutputPriceMicrosPer1m,avgResponseMs:ko((x==null?void 0:x.responseMsSamples)??[]),avgTtftMs:ko((x==null?void 0:x.ttftMsSamples)??[])}}),m=new Set(d.map(h=>h.id));for(const[h,x]of u.entries()){if(m.has(h))continue;const p=i.find(v=>v.sellerId===h);d.push({id:h,name:Iv((p==null?void 0:p.sellerName)??h),status:"unknown",modelCount:x.modelIds.size,protocols:Array.from(x.protocols).sort(),paymentMethods:Array.from(x.paymentMethods).sort(),minInputPriceMicrosPer1m:x.minInputPriceMicrosPer1m,minOutputPriceMicrosPer1m:x.minOutputPriceMicrosPer1m,avgResponseMs:ko(x.responseMsSamples),avgTtftMs:ko(x.ttftMsSamples)})}return S0(d,{key:"status",direction:"asc"})}function S0(a,i){const r=i.direction==="asc"?1:-1;return[...a].sort((u,d)=>{const m=eN(u,d,i.key);if(m!==0)return m*r;const h=Vo(u.status)-Vo(d.status);return h!==0?h:d.modelCount!==u.modelCount?d.modelCount-u.modelCount:u.name.localeCompare(d.name)})}function eN(a,i,r){return r==="status"?Vo(a.status)-Vo(i.status):r==="name"?a.name.localeCompare(i.name):r==="models"?a.modelCount-i.modelCount:r==="price"?zd(Wv(a),Wv(i)):r==="discount"?zd(a.discountRatio,i.discountRatio):zd(a.avgResponseMs??a.avgTtftMs,i.avgResponseMs??i.avgTtftMs)}function Wv(a){if(!(!Number.isFinite(a.minInputPriceMicrosPer1m)&&!Number.isFinite(a.minOutputPriceMicrosPer1m)))return(a.minInputPriceMicrosPer1m??0)+(a.minOutputPriceMicrosPer1m??0)}function Pv(a,i){const r=Number.isFinite(a),u=Number.isFinite(i);if(r&&u)return Math.min(a,i);if(r)return a;if(u)return i}function ko(a){const i=a.filter(r=>Number.isFinite(r));if(i.length!==0)return i.reduce((r,u)=>r+u,0)/i.length}function zd(a,i){const r=Number.isFinite(a),u=Number.isFinite(i);return r&&u?a-i:r?-1:u?1:0}function Iv(a){var i;return((i=a.split("(")[0])==null?void 0:i.trim())||a}function tN(a,i){return!Number.isFinite(a)&&!Number.isFinite(i)?"-":`I ${ex(a)} / O ${ex(i)}`}function ex(a){if(!Number.isFinite(a))return"-";const i=a/1e6;return`$${i>=1?i.toFixed(2):i.toFixed(4)}`}function lN(a){if(!Number.isFinite(a))return"-";const i=a;if(i<=0)return"free";const r=Math.max(0,1-i);return r>=.01?`${Math.round(r*100)}% off`:`x${i.toFixed(2)}`}function aN(a,i){return!Number.isFinite(a)&&!Number.isFinite(i)?"-":Number.isFinite(a)&&Number.isFinite(i)?`${Math.round(a)}ms / T ${Math.round(i)}ms`:Number.isFinite(a)?`${Math.round(a)}ms`:`T ${Math.round(i)}ms`}function tx(a,i,r,u){const d=u||r[0]||"",m={};for(const h of a)h!=="custom"&&(m[h]=h==="claude-code"?M0(i[h],r,d):N0(h,i[h],d));return m}function N0(a,i,r){return(i==null?void 0:i.selectionKind)==="single-model"?{...i,protocolPreference:i.protocolPreference??Id(a),defaultModel:i.defaultModel||r}:{selectionKind:"single-model",protocolPreference:Id(a),defaultModel:r}}function M0(a,i,r){var m;const u=(a==null?void 0:a.selectionKind)==="claude-role-mapping"?(m=a.roles.sonnet)==null?void 0:m.upstreamModel:void 0,d=r||u||i[0]||"";return(a==null?void 0:a.selectionKind)==="claude-role-mapping"?{...a,protocolPreference:"messages",fallbackModel:a.fallbackModel||d,roles:{...a.roles,sonnet:a.roles.sonnet??(d?{upstreamModel:d,displayName:d}:void 0)}}:{selectionKind:"claude-role-mapping",protocolPreference:"messages",fallbackModel:d,roles:{sonnet:d?{upstreamModel:d,displayName:d}:void 0}}}function Id(a){if(a==="codex")return"responses";if(a==="claude-code"||a==="claude-desktop")return"messages";if(["openclaw","opencode","hermes"].includes(a))return"chat_completions"}function w0(a){return{id:"custom",name:"其他工具",status:"manual",detected:!0,configured:!1,reason:"复制本地推理服务接口到任意 OpenAI 或 Anthropic 兼容客户端。",manualConfig:{openaiBaseUrl:C0(a),anthropicBaseUrl:a,apiKey:"TOKENBUDDY_PROXY"}}}function C0(a){const i=a.replace(/\/+$/,"");return i.endsWith("/v1")?i:`${i}/v1`}function nN(a){const i=a.trim();return i?i.slice(0,1).toUpperCase():"?"}function iN(a,i,r,u){if(a==="fixed"){const d=r.trim();return d?{mode:a,scorer:i,sellerId:d}:void 0}if(a==="fixedSet"){const d=Array.from(new Set(u.map(m=>m.trim()).filter(Boolean)));return d.length===0?void 0:{mode:a,scorer:i,sellerIds:d}}return{mode:a,scorer:i}}function rN({serviceReady:a,modelCount:i,routingMode:r,paymentReady:u,configuredTools:d}){return[{title:a?"本地网关正在运行":"本地网关尚未就绪",body:a?"控制台服务和本地代理已经响应。":"请确认 tb-proxyd 已启动,并等待控制台刷新状态。",ok:a,status:a?"passed":"failed",details:[]},{title:i>0?"模型目录已加载":"模型目录尚未加载",body:i>0?`已发现 ${i} 个可用模型。`:"请检查供应商注册表或网络连接。",ok:i>0,status:i>0?"passed":"failed",details:[]},{title:"路由策略已选择",body:`当前策略为${T0(r)},TokenBuddy 会按这个策略规划供应商。`,ok:!!r,status:r?"passed":"failed",details:[]},{title:u?"支付方式可用":"支付方式尚未可用",body:u?"已经检测到至少一个可用支付方式。":"请完成 ClawTip 绑定,或稍后在支付页面补充配置。",ok:u,status:u?"passed":"warning",details:[]},{title:d>0?"终端工具已接入":"终端工具尚未接入",body:d>0?`已经写入 ${d} 个终端工具配置。`:"如果你还没有安装终端工具,可以稍后再执行接入。",ok:d>0,status:d>0?"passed":"warning",details:[]}]}function sN(a){return{title:a.label,body:a.message,ok:a.status==="passed"||a.status==="skipped",status:a.status,details:a.details}}function lx(a){return a==="passed"?"全部通过":a==="warning"?"存在警告":a==="failed"?"需要修复":"等待检查"}function oN(a){return a==="passed"?"bg-emerald-50 text-emerald-700":a==="warning"?"bg-amber-50 text-amber-700":a==="failed"?"bg-rose-50 text-rose-700":"bg-[var(--color-page)] text-[var(--color-muted)]"}function uN(a){return a==="passed"?"通过":a==="warning"?"警告":a==="failed"?"失败":"已跳过"}function cN(a){return a==="passed"?"bg-emerald-50 text-emerald-700":a==="failed"?"bg-rose-50 text-rose-700":a==="skipped"?"bg-slate-100 text-slate-600":"bg-amber-50 text-amber-700"}function dN(a){return a==="passed"?"bg-emerald-50 text-emerald-700":a==="failed"?"bg-rose-50 text-rose-700":a==="skipped"?"bg-slate-100 text-slate-600":"bg-amber-50 text-amber-700"}function T0(a){return a==="fixed"?"固定供应商":a==="fixedSet"?"固定供应商组":"全自动"}function fN(a){return a==="speed"?"速度优先":a==="discount"?"成本优先":"平衡模式"}function mN(a){const i=a.toLowerCase();return["ok","healthy","active","available"].includes(i)?"状态正常":["error","failed","unavailable"].includes(i)?"状态异常":["unknown","pending"].includes(i)?"等待检测":`状态:${a}`}function hN(a){const i=a.toLowerCase();return["ok","healthy","active","available"].includes(i)?"bg-emerald-50 text-emerald-700":["error","failed","unavailable"].includes(i)?"bg-rose-50 text-rose-700":"bg-amber-50 text-amber-700"}function Vo(a){const i=a.toLowerCase();return["ok","healthy","active","available"].includes(i)?0:["unknown","pending"].includes(i)?1:2}function E0(a){return a.configured?"已配置":a.status==="installed"?"已安装":a.status==="manual"?"需要手动配置":a.detected?"已检测到":"未检测到"}function pN(a){return a==="create"?"创建":"更新"}function vN(){return o.jsxs("div",{className:"min-h-full",children:[o.jsxs("nav",{"aria-label":"Primary",className:"sticky top-0 z-10 flex h-12 items-center gap-2 border-b border-[var(--color-line-2)] bg-[var(--color-page)]/95 px-3 backdrop-blur sm:gap-5 sm:px-6",children:[o.jsxs(df,{to:"/overview","aria-label":"TokenBuddy home",className:"group inline-flex shrink-0 items-center rounded-[var(--radius-md)] px-1 py-1.5 focus:outline-none focus:ring-2 focus:ring-[var(--color-primary)]",children:[o.jsx("span",{className:"font-mono text-[0.86rem] font-bold uppercase tracking-[0.14em] text-[var(--color-ink)]",children:"tokenbuddy"}),o.jsx("span",{className:"ml-1.5 inline-block size-1.5 rounded-full bg-[var(--color-primary)] shadow-[0_0_0_3px_rgba(124,61,240,0.18)]","aria-hidden":!0})]}),o.jsxs("div",{className:"ml-auto flex min-w-0 gap-0.5 sm:gap-1",children:[o.jsx(Rd,{to:"/overview",children:"Overview"}),o.jsx(Rd,{to:"/routing",children:"Routing"}),o.jsx(Rd,{to:"/ledger",children:"Ledger"})]})]}),o.jsx("main",{className:"mx-auto max-w-[1180px] px-3 py-5 sm:px-6 sm:py-7",children:o.jsxs(Fg,{children:[o.jsx(Si,{path:"/",element:o.jsx(Yv,{})}),o.jsx(Si,{path:"/overview",element:o.jsx(Yv,{})}),o.jsx(Si,{path:"/init",element:o.jsx(_S,{})}),o.jsx(Si,{path:"/routing",element:o.jsx(Qj,{})}),o.jsx(Si,{path:"/ledger",element:o.jsx(cS,{})})]})})]})}function Rd({to:a,children:i}){return o.jsx(df,{to:a,className:({isActive:r})=>["rounded-[var(--radius-md)] px-2 py-1.5 text-[0.82rem] font-medium transition-colors sm:px-3.5 sm:text-[0.92rem]",r?"font-semibold text-[var(--color-ink)] underline decoration-[var(--color-primary)] decoration-2 underline-offset-[10px]":"text-[var(--color-muted)] hover:text-[var(--color-ink)]"].join(" "),children:i})}function xN(){!("serviceWorker"in navigator)||window.location.port==="5173"||window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js").catch(()=>{})})}const yN=new e2({defaultOptions:{queries:{staleTime:5e3,refetchOnWindowFocus:!1,retry:1}}});Wb.createRoot(document.getElementById("root")).render(o.jsx(j.StrictMode,{children:o.jsx(t2,{client:yN,children:o.jsx(g1,{children:o.jsx(vN,{})})})}));xN();
|
|
236
|
-
//# sourceMappingURL=index-
|
|
235
|
+
*/const rj=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Zr=qe("x",rj);class Jx extends Error{constructor(r,u,d){super(r);pd(this,"status");pd(this,"code");this.status=u,this.code=d}}async function yl(a){var r,u;const i=await fetch(a);if(!i.ok){const d=await i.json().catch(()=>({}));throw new Jx(((r=d.error)==null?void 0:r.message)??`${a} returned ${i.status}`,i.status,(u=d.error)==null?void 0:u.code)}return i.json()}async function Xa(a,i,r){var d,m;const u=await fetch(i,{method:a,headers:r?{"content-type":"application/json"}:void 0,body:r?JSON.stringify(r):void 0});if(!u.ok){const h=await u.json().catch(()=>({}));throw new Jx(((d=h.error)==null?void 0:d.message)??`${a} ${i} returned ${u.status}`,u.status,(m=h.error)==null?void 0:m.code)}return u.json()}function Wo(){return xl({queryKey:["ledger","inferences"],queryFn:()=>yl("/ledger/inferences"),refetchInterval:1e4})}function sj(){return xl({queryKey:["ledger","purchases"],queryFn:()=>yl("/ledger/purchases"),refetchInterval:1e4})}function Fx(){return xl({queryKey:["payments"],queryFn:()=>yl("/payments"),refetchInterval:1e4})}function Wx(){const a=is();return Qi({mutationFn:()=>Xa("POST","/payments/clawtip/activate"),onSuccess:()=>{a.invalidateQueries({queryKey:["payments"]})}})}function Px(){return Qi({mutationFn:()=>Xa("POST","/payments/clawtip/recharge")})}function Ix(){return xl({queryKey:["routing","strategy"],queryFn:()=>yl("/routing/strategy")})}function e0(){const a=is();return Qi({mutationFn:i=>Xa("PUT","/routing/strategy",i),onSuccess:()=>{a.invalidateQueries({queryKey:["routing","strategy"]})}})}function oj(a){const i=new URLSearchParams;for(const[r,u]of Object.entries(a))u!=null&&u!==""&&i.set(r,uj(u));return xl({queryKey:["routing","preview",i.toString()],queryFn:()=>yl(`/routing/preview?${i.toString()}`),enabled:!1})}function uj(a){return Array.isArray(a)?a.join(","):typeof a=="object"&&a!==null?Object.entries(a).map(([i,r])=>`${i}:${r}`).join(","):String(a)}function t0(){return xl({queryKey:["sellers"],queryFn:()=>yl("/sellers"),refetchInterval:3e4})}function xf(){return xl({queryKey:["models"],queryFn:()=>yl("/models"),refetchInterval:3e4})}function cj(){return xl({queryKey:["prewarm","focus-set"],queryFn:()=>yl("/v1.2/prewarm").then(a=>({ok:!0,focusSet:a.focusSet??[],source:"historical"}))})}async function Lo(a){const i=Array.isArray(a)?{models:a}:a;return Xa("PUT","/prewarm/focus-set",i)}function l0(){return xl({queryKey:["status"],queryFn:()=>yl("/status"),refetchInterval:5e3})}function jt({children:a,className:i=""}){return o.jsx("div",{className:["rounded-[var(--radius-xl)] border border-[var(--color-line-2)] bg-white shadow-[var(--shadow-panel)]",i].join(" "),children:a})}function rs({tone:a="lavender",children:i}){const r={lavender:"bg-[var(--color-lavender)] text-[var(--color-primary)]",green:"bg-[var(--color-success-soft)] text-[var(--color-success)]",amber:"bg-[var(--color-warning-soft)] text-[var(--color-warning)]",red:"bg-[var(--color-danger-soft)] text-[var(--color-danger)]",blue:"bg-[var(--color-tokens-soft)] text-[var(--color-tokens)]",gray:"bg-slate-100 text-slate-600"};return o.jsxs("span",{className:["inline-flex items-center gap-1.5 text-[0.78rem] font-medium px-2.5 py-0.5 rounded-[var(--radius-pill)]",r[a]??r.lavender].join(" "),children:[o.jsx("span",{className:"size-1.5 rounded-full bg-current"}),i]})}const Te="—",Ht=a=>a<10?`0${a}`:`${a}`;function pl(a,i={}){if(!Number.isFinite(a))return Te;const r=a;return i.compact===!1||r<1e4?Math.round(r).toLocaleString("en-US"):r<1e6?`${(r/1e3).toFixed(1)}K`:r<1e9?`${(r/1e6).toFixed(1)}M`:`${(r/1e9).toFixed(2)}B`}function $r(a,i,r={}){const u=r.separator??" / ";return`In ${pl(a,r)}${u}Out ${pl(i,r)}`}function dj(a,i){return!Number.isFinite(a)&&!Number.isFinite(i)?Te:`Input ${Ke(a)} / Output ${Ke(i)}`}function Ke(a){return Number.isFinite(a)?Math.round(a).toLocaleString("en-US"):Te}function st(a,i={}){if(!Number.isFinite(a))return Te;const r=Math.abs(a/1e6),u=i.digits??(i.ledger&&r<.01?6:4),d=`$${(a/1e6).toFixed(u)}`;return i.signed&&a>=0?`+${d}`:d}function fj(a,i,r={}){return!Number.isFinite(a)&&!Number.isFinite(i)?Te:`${st(a,r)} / ${st(i,r)}`}function xt(a){if(!Number.isFinite(a))return Te;const i=Math.max(0,Math.round(a));return i<1e3?`${i}ms`:`${(i/1e3).toFixed(2)}s`}function yf(a){return Number.isFinite(a)?`${Math.round(a*100)}%`:Te}function a0(a){if(!Number.isFinite(a))return Te;const i=Math.max(0,1-a);return yf(i)}function n0(a,i){return fj(a,i,{digits:4})}function Rl(a){return a?a.trim().toLowerCase().replaceAll("_"," "):Te}function Ka(a){const i=Rl(a);return i==="ok"||i==="online"||i==="configured"||i==="settled"||i==="completed"||i==="success"||i==="active"||i==="healthy"?"green":i==="fallback"||i==="pending"||i==="degraded"||i==="preview"?"amber":i==="failed"||i==="error"||i==="canceled"||i==="unhealthy"||i==="offline"?"red":i==="running"?"blue":"gray"}function Jr(a,i=32){return a?a.length>i?`${a.slice(0,i)}...`:a:Te}function mj(a){return a?a.startsWith("tbs-")&&a.length>10?a.slice(0,10):a.length<=12?a:a.slice(0,12):Te}function i0(a){if(!a)return Te;const i=new Date(a);if(Number.isNaN(i.getTime()))return Te;const r=new Date,u=i.getFullYear()===r.getFullYear()&&i.getMonth()===r.getMonth()&&i.getDate()===r.getDate(),d=`${Ht(i.getHours())}:${Ht(i.getMinutes())}`;return u?d:`${Ht(i.getMonth()+1)}/${Ht(i.getDate())} ${d}`}function vl(a){if(!a)return Te;const i=new Date(a);return Number.isNaN(i.getTime())?Te:`${i.getFullYear()}-${Ht(i.getMonth()+1)}-${Ht(i.getDate())} ${Ht(i.getHours())}:${Ht(i.getMinutes())}:${Ht(i.getSeconds())}`}function r0(a){if(!a)return Te;const i=new Date(a);return Number.isNaN(i.getTime())?Te:`${i.getFullYear()}/${Ht(i.getMonth()+1)}/${Ht(i.getDate())} ${Ht(i.getHours())}:${Ht(i.getMinutes())}:${Ht(i.getSeconds())}`}function hj(a){return i0(a)}function s0({inferences:a,modelsResponse:i,sellersResponse:r,previewPlan:u,activeModelId:d}){const m=xj(i,r),h=[...a].sort(jj),x=new Map,p=new Map;let v=0,g=0,b=0;for(const C of h){const A=C.modelId||Te,z=C.sellerKey||Te,B=fl(C.promptTokens)??0,U=fl(C.completionTokens)??0,G=B+U,K=fl(C.billedMicros)??0;v+=1,g+=G,b+=K;const L=x.get(A)??yj(A);L.entries.push(C),L.requestCount+=1,L.inputTokens+=B,L.outputTokens+=U,L.totalSpendMicros+=K,L.touchedSellers.add(z),L.sellerCounts.set(z,(L.sellerCounts.get(z)??0)+1),L.fallbackCount+=fl(C.fallbackCount)??0;const V=fl(C.ttftMs);V!==void 0&&(L.ttftTotal+=V,L.ttftCount+=1);const P=fl(C.durationMs);P!==void 0&&(L.durationTotal+=P,L.durationCount+=1),x.set(A,L);const J=p.get(z)??{requestCount:0,totalTokens:0};J.requestCount+=1,J.totalTokens+=G,p.set(z,J)}const E=Array.from(x.values()).map(C=>pj(C,p,m)).sort(Sj);if(E.length===0){const C=vj(d,u,m);C&&E.push(C)}return{rows:E,totalRequests:v,totalTokens:g,totalSpendMicros:b}}function pj(a,i,r){const u=a.entries[a.entries.length-1],d=(u==null?void 0:u.sellerKey)||Te,m=o0(d,r),h=a.sellerCounts.get(d)??0,x=i.get(d),p=r.modelsBySellerAndModel.get(`${d}\0${a.modelId}`);return{source:"ledger",modelId:a.modelId,currentSellerId:d,currentSellerName:m.name,currentSellerUrl:m.url,currentSellerStatus:m.status,currentSellerPaymentMethods:m.paymentMethods,sellerDiscount:m.discount,sellerServiceFee:m.serviceFee,sellerModelCount:m.modelCount,requestCount:a.requestCount,currentSellerModelRequests:h,currentSellerRequests:(x==null?void 0:x.requestCount)??h,inputTokens:a.inputTokens,outputTokens:a.outputTokens,totalTokens:a.inputTokens+a.outputTokens,currentSellerTokens:(x==null?void 0:x.totalTokens)??0,totalSpendMicros:a.totalSpendMicros,avgTtftMs:Qv(a.ttftTotal,a.ttftCount),avgDurationMs:Qv(a.durationTotal,a.durationCount),lastTtftMs:fl(u==null?void 0:u.ttftMs),lastDurationMs:fl(u==null?void 0:u.durationMs),selectedAt:bj(a.entries,d),lastSellerSwitchAt:gj(a.entries),lastAccessAt:u==null?void 0:u.createdAt,lastRequestId:u==null?void 0:u.requestId,lastStatus:u==null?void 0:u.status,routeReason:u==null?void 0:u.routeReason,upstreamStatus:u==null?void 0:u.upstreamStatus,fallbackCount:a.fallbackCount,falloverChain:(u==null?void 0:u.falloverChain)??[],touchedSellerCount:a.touchedSellers.size,inputPriceMicrosPer1m:p==null?void 0:p.inputPriceMicrosPer1m,outputPriceMicrosPer1m:p==null?void 0:p.outputPriceMicrosPer1m}}function vj(a,i,r){var p,v,g;const u=(p=i==null?void 0:i.routes)==null?void 0:p[0];if(!u||!a)return;const d=o0(u.seller.id,r,u),m=fl(u.metrics.ttftMs)??fl(u.metrics.avgLatencyMs),h=fl(u.metrics.avgInferenceMs),x=r.modelsBySellerAndModel.get(`${u.seller.id}\0${a}`);return{source:"preview",modelId:a,currentSellerId:u.seller.id,currentSellerName:d.name,currentSellerUrl:d.url,currentSellerStatus:d.status,currentSellerPaymentMethods:d.paymentMethods,sellerDiscount:d.discount,sellerServiceFee:d.serviceFee,sellerModelCount:d.modelCount,requestCount:0,currentSellerModelRequests:0,currentSellerRequests:0,inputTokens:0,outputTokens:0,totalTokens:0,currentSellerTokens:0,totalSpendMicros:0,avgTtftMs:m,avgDurationMs:h,lastTtftMs:m,lastDurationMs:h,routeReason:i.reason??i.sourceReason??"Preview route",fallbackCount:0,falloverChain:((v=i.routes)==null?void 0:v.map(b=>b.seller.id))??[],touchedSellerCount:((g=i.routes)==null?void 0:g.length)??1,inputPriceMicrosPer1m:x==null?void 0:x.inputPriceMicrosPer1m,outputPriceMicrosPer1m:x==null?void 0:x.outputPriceMicrosPer1m}}function xj(a,i){const r=new Map;for(const u of(a==null?void 0:a.data)??[]){const d=r.get(u.sellerId)??new Set;d.add(u.id),r.set(u.sellerId,d)}return{registryById:new Map(((i==null?void 0:i.sellers)??[]).map(u=>[u.id,u])),catalogById:new Map(((a==null?void 0:a.sellers)??[]).map(u=>[u.id,u])),modelsBySellerAndModel:new Map(((a==null?void 0:a.data)??[]).map(u=>[`${u.sellerId}\0${u.id}`,u])),modelCountsBySellerId:new Map(Array.from(r.entries()).map(([u,d])=>[u,d.size]))}}function yj(a){return{modelId:a,entries:[],sellerCounts:new Map,touchedSellers:new Set,requestCount:0,inputTokens:0,outputTokens:0,totalSpendMicros:0,ttftTotal:0,ttftCount:0,durationTotal:0,durationCount:0,fallbackCount:0}}function bj(a,i){var r;for(let u=a.length-1;u>=0;u-=1){const d=a[u];if(d.sellerKey!==i)return(r=a[u+1])==null?void 0:r.createdAt;if(u===0)return d.createdAt}}function gj(a){let i;for(let r=1;r<a.length;r+=1)a[r].sellerKey!==a[r-1].sellerKey&&(i=a[r].createdAt);return i}function o0(a,i,r){const u=i.catalogById.get(a),d=i.registryById.get(a),m=(r==null?void 0:r.metrics.discountRatio)??(u==null?void 0:u.discountRatio);return{name:Nj((r==null?void 0:r.seller.name)??(u==null?void 0:u.name)??(d==null?void 0:d.name)??a),url:(r==null?void 0:r.seller.url)??(u==null?void 0:u.url)??(d==null?void 0:d.url),status:(u==null?void 0:u.status)??(d==null?void 0:d.status)??Te,paymentMethods:(u==null?void 0:u.paymentMethods)??(d==null?void 0:d.paymentMethods)??(r==null?void 0:r.seller.paymentMethods)??[],discount:a0(m),serviceFee:yf(u==null?void 0:u.serviceFeeRatio),modelCount:(u==null?void 0:u.modelCount)??i.modelCountsBySellerId.get(a)}}function jj(a,i){return Ko(a.createdAt)-Ko(i.createdAt)}function Sj(a,i){return Ko(i.lastAccessAt)-Ko(a.lastAccessAt)}function Ko(a){if(!a)return 0;const i=new Date(a).getTime();return Number.isNaN(i)?0:i}function Qv(a,i){return i>0?a/i:void 0}function fl(a){return Number.isFinite(a)?a:void 0}function Nj(a){var i;return((i=a.split("(")[0])==null?void 0:i.trim())||a}function Yv(){var oe,F,fe,ye,Ee,me,D,$,re,be,ge,M,_,Z,I,X,ae;const[a,i]=j.useState(null),r=l0(),u=Ix(),d=Fx(),m=Wx(),h=Px(),x=d.refetch,p=m.reset,v=Wo(),g=t0(),b=xf(),E=((oe=v.data)==null?void 0:oe.inferences)??[],C=((F=d.data)==null?void 0:F.payments)??[],A=new Set((((fe=b.data)==null?void 0:fe.data)??[]).map(W=>W.id)).size,z=((ye=g.data)==null?void 0:ye.sellers.length)??((me=(Ee=b.data)==null?void 0:Ee.sellers)==null?void 0:me.length)??0,B=j.useMemo(()=>kj(E),[E]),U=j.useMemo(()=>Uj(C,E),[E,C]),G=j.useMemo(()=>s0({inferences:E,modelsResponse:b.data,sellersResponse:g.data}),[E,b.data,g.data]),L=C.some(W=>hl(W.method)==="clawtip"&&(W.enabled||d0(W.config,"walletConfigPresent")))||((D=m.data)==null?void 0:D.walletConfigPresent)===!0,V=(($=r.data)==null?void 0:$.status)==="running"&&!r.isError,P=new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),J=((re=u.data)==null?void 0:re.strategy.mode)??((be=r.data)==null?void 0:be.sellerRoutingMode)??Te,ee=((ge=u.data)==null?void 0:ge.strategy.scorer)??((M=r.data)==null?void 0:M.sellerRoutingScorer)??Te,le=()=>{i(null),m.reset(),h.reset()};return j.useEffect(()=>{if((a==null?void 0:a.kind)!=="activate"||hl(a.method)!=="clawtip"||L)return;const W=window.setInterval(()=>{x()},1500);return()=>window.clearInterval(W)},[L,a==null?void 0:a.kind,a==null?void 0:a.method,x]),j.useEffect(()=>{(a==null?void 0:a.kind)==="activate"&&hl(a.method)==="clawtip"&&L&&(i(null),p())},[L,a==null?void 0:a.kind,a==null?void 0:a.method,p]),o.jsxs("div",{className:"min-w-0 overflow-x-hidden space-y-3",children:[o.jsxs("section",{className:"grid grid-cols-2 gap-2.5 md:grid-cols-3 xl:grid-cols-6",children:[o.jsx(bi,{to:"/routing",icon:o.jsx(Vx,{className:"size-4"}),label:"Router",value:J,note:`${ee} scorer`,tone:"router"}),o.jsx(bi,{to:"/ledger",icon:o.jsx(Lv,{className:"size-4"}),label:"Today requests",value:Ke(B.todayRequestCount),note:`${Ke(B.totalRequestCount)} total`,tone:"requests"}),o.jsx(bi,{to:"/ledger",icon:o.jsx(Bi,{className:"size-4"}),label:"Spend today",value:st(B.todaySpendMicros,{digits:4}),note:`${st(B.totalSpendMicros,{digits:4})} total`,tone:"spend"}),o.jsx(bi,{to:"/ledger",icon:o.jsx(qv,{className:"size-4"}),label:"Today tokens",value:pl(B.todayInputTokens+B.todayOutputTokens),note:$r(B.todayInputTokens,B.todayOutputTokens),tone:"tokens"}),o.jsx(bi,{to:"/ledger",icon:o.jsx(Lv,{className:"size-4"}),label:"Total tokens",value:pl(B.inputTokens+B.outputTokens),note:$r(B.inputTokens,B.outputTokens),tone:"tokens"}),o.jsx(bi,{to:"/routing",icon:o.jsx(qv,{className:"size-4"}),label:"Models / Sellers",value:`${A}`,note:`${z} sellers`,tone:"inventory"})]}),o.jsx("section",{className:"grid min-w-0 gap-3",children:o.jsxs("div",{className:"min-w-0 space-y-3",children:[o.jsx(Mj,{rows:G.rows,totalRequests:G.totalRequests,totalTokens:G.totalTokens}),o.jsxs(jt,{className:"p-3.5",children:[o.jsx("div",{className:"flex items-start justify-between gap-4",children:o.jsx("div",{children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("h2",{className:"text-[1rem] font-semibold text-[var(--color-ink)]",children:"Payment management"}),o.jsx(rs,{tone:C.some(W=>W.enabled)?"green":"amber",children:C.some(W=>W.enabled)?"configured":"not configured"})]})})}),o.jsx("div",{className:"mt-2 min-w-0 overflow-hidden rounded-[10px] border border-[var(--color-line-2)] bg-white",children:U.map(W=>o.jsx(Cj,{...W,onActivate:()=>{i({kind:"activate",method:W.method}),W.method==="clawtip"&&m.mutate()},onRecharge:()=>{i({kind:"recharge",method:W.method}),W.method==="clawtip"&&h.mutate()}},W.method))})]}),o.jsxs(jt,{className:"p-3",children:[o.jsxs("div",{className:"mb-2 flex min-w-0 flex-col gap-2",children:[o.jsx("div",{className:"flex min-w-0 flex-wrap items-center justify-between gap-2",children:o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx(nj,{className:"size-4 shrink-0 text-[var(--color-purple)]"}),o.jsx("h2",{className:"truncate text-[1rem] font-semibold text-[var(--color-ink)]",children:"TokenUsage"})]})}),o.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2.5 gap-y-1 text-[0.7rem] text-[var(--color-muted)]",children:[B.modelUsage.map(W=>o.jsx(Oj,{model:W.model,color:W.color},W.model)),o.jsx(Gv,{label:"in"}),o.jsx(Gv,{label:"out",dashed:!0})]})]}),o.jsxs("div",{className:"grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_190px]",children:[o.jsx(Aj,{days:B.days,series:B.modelUsage}),o.jsxs("div",{className:"grid gap-3",children:[o.jsx(zj,{days:B.days,values:B.cost,total:st(B.weeklySpendMicros)}),o.jsx(Rj,{values:B.thirtyDaySpend,total:st(B.totalSpendMicros)})]})]})]})]})}),o.jsx(_j,{checkedAt:P,healthy:V,pid:(_=r.data)==null?void 0:_.pid,status:(Z=r.data)==null?void 0:Z.status,proxyPort:(I=r.data)==null?void 0:I.proxyPort,controlPort:(X=r.data)==null?void 0:X.controlPort,registryUrl:(ae=r.data)==null?void 0:ae.sellerRegistryUrl}),a?o.jsx(Ej,{modal:a,methods:U,qr:a.kind==="activate"?m.data:h.data,loading:a.kind==="activate"?m.isPending:h.isPending,error:a.kind==="activate"?m.error:h.error,onClose:le}):null]})}function Mj({rows:a,totalRequests:i,totalTokens:r}){var d;const u=a.slice(0,3);return o.jsxs(jt,{className:"overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--color-line-2)] px-3.5 py-3",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx(Vx,{className:"size-4 shrink-0 text-[var(--color-purple)]"}),o.jsx("h2",{className:"truncate text-[1rem] font-semibold text-[var(--color-ink)]",children:"Recent model routes"})]}),o.jsx(ns,{to:"/routing",className:"shrink-0 rounded-[8px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-2.5 py-1.5 text-[0.72rem] font-semibold text-[var(--color-purple)] transition hover:bg-white",children:"Details"})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-2 border-b border-[var(--color-line-2)] bg-[var(--color-page)]/55 px-3.5 py-2 sm:grid-cols-4",children:[o.jsx(Oo,{label:"Req",value:Ke(i)}),o.jsx(Oo,{label:"Token",value:pl(r)}),o.jsx(Oo,{label:"Models",value:Ke(a.length)}),o.jsx(Oo,{label:"Latest",value:i0((d=a[0])==null?void 0:d.lastAccessAt)})]}),u.length>0?o.jsx("div",{className:"divide-y divide-[var(--color-line-2)]",children:u.map(m=>o.jsx(wj,{row:m},`${m.modelId}-${m.currentSellerId}`))}):o.jsx("div",{className:"px-3.5 py-7 text-center text-[0.82rem] text-[var(--color-muted)]",children:"No model traffic yet."})]})}function Oo({label:a,value:i}){return o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[0.65rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:a}),o.jsx("div",{className:"mt-0.5 truncate font-mono text-[0.88rem] font-semibold text-[var(--color-ink)]",children:i})]})}function wj({row:a}){const i=a.lastSellerSwitchAt??a.selectedAt;return o.jsxs("div",{className:"grid min-w-0 gap-3 px-3.5 py-3 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,2fr)] lg:items-center",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",title:a.modelId,children:a.modelId}),o.jsxs("div",{className:"mt-0.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-[0.72rem] text-[var(--color-muted)]",children:[o.jsx("span",{className:"truncate",children:a.currentSellerName}),o.jsx("span",{className:"font-mono",children:a.currentSellerStatus})]})]}),o.jsxs("div",{className:"grid min-w-0 grid-cols-2 gap-1.5 sm:grid-cols-3 lg:grid-cols-6",children:[o.jsx(yi,{label:"In",value:pl(a.inputTokens),tone:"tokens",title:`Input tokens: ${Ke(a.inputTokens)}`}),o.jsx(yi,{label:"Out",value:pl(a.outputTokens),tone:"success",title:`Output tokens: ${Ke(a.outputTokens)}`}),o.jsx(yi,{label:"TTFT",value:xt(a.lastTtftMs??a.avgTtftMs),tone:"router",title:`Time to first token: ${xt(a.lastTtftMs??a.avgTtftMs)}`}),o.jsx(yi,{label:"Total",value:xt(a.lastDurationMs??a.avgDurationMs),tone:"slate",title:`Total inference duration: ${xt(a.lastDurationMs??a.avgDurationMs)}`}),o.jsx(yi,{label:"Disc",value:a.sellerDiscount,tone:"success",title:`Seller discount: ${a.sellerDiscount}`}),o.jsx(yi,{label:"Switch",value:hj(i),tone:"slate",title:`Last seller switch: ${vl(i)}`})]})]})}function yi({label:a,value:i,tone:r,title:u}){const d={router:"bg-[var(--color-lavender)] text-[var(--color-router)]",success:"bg-[var(--color-success-soft)] text-[var(--color-success)]",warning:"bg-[var(--color-warning-soft)] text-[var(--color-warning)]",tokens:"bg-[var(--color-tokens-soft)] text-[var(--color-tokens)]",slate:"bg-slate-50 text-slate-700"}[r];return o.jsxs("div",{className:["min-w-0 rounded-[var(--radius-md)] px-2 py-1",d].join(" "),title:u??`${a}: ${i}`,children:[o.jsx("div",{className:"text-[0.58rem] font-semibold uppercase tracking-wider opacity-70",children:a}),o.jsx("div",{className:"truncate font-mono text-[0.76rem] font-semibold",children:i})]})}function bi({to:a,icon:i,label:r,value:u,note:d,tone:m}){const h={router:{card:"border border-[var(--color-hairline-strong)] bg-white shadow-[var(--shadow-panel-strong)] hover:border-[var(--color-primary)] before:bg-[var(--color-router)]",icon:"bg-[var(--color-lavender)] text-[var(--color-router)]",label:"text-[var(--color-router)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-muted)]"},requests:{card:"border border-[var(--color-hairline)] bg-white shadow-[var(--shadow-panel)] hover:border-[var(--color-success)] before:bg-[var(--color-success)]",icon:"bg-[var(--color-success-soft)] text-[var(--color-success)]",label:"text-[var(--color-success)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-muted)]"},spend:{card:"border border-[var(--color-spend-border)] bg-[var(--color-spend-soft)] shadow-[var(--shadow-panel)] hover:border-[var(--color-spend)] before:bg-[var(--color-spend)]",icon:"bg-white text-[var(--color-spend)]",label:"text-[var(--color-spend)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-spend)]"},tokens:{card:"border border-[var(--color-tokens-border)] bg-[var(--color-tokens-soft)] shadow-[var(--shadow-panel)] hover:border-[var(--color-tokens)] before:bg-[var(--color-tokens)]",icon:"bg-white text-[var(--color-tokens)]",label:"text-[var(--color-tokens)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-tokens)]"},inventory:{card:"border border-[var(--color-inventory-border)] bg-[var(--color-inventory-soft)] shadow-[var(--shadow-panel)] hover:border-[var(--color-inventory)] before:bg-[var(--color-inventory)]",icon:"bg-white text-[var(--color-inventory)]",label:"text-[var(--color-inventory)]",value:"text-[var(--color-ink)]",note:"text-[var(--color-inventory)]"}}[m];return o.jsxs(ns,{to:a,"aria-label":`Open ${r}`,className:["relative block min-h-[94px] overflow-hidden rounded-[var(--radius-xl)] p-3 transition before:absolute before:inset-y-0 before:left-0 before:w-1 hover:-translate-y-0.5 focus:outline-none focus:ring-2 focus:ring-[var(--color-primary)]",h.card].join(" "),children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("div",{className:`grid size-7 place-items-center rounded-[var(--radius-md)] ${h.icon}`,children:i}),o.jsx("span",{className:["text-right text-[0.66rem] font-semibold uppercase leading-3 tracking-[0.08em]",h.label].join(" "),children:r})]}),o.jsx("div",{className:["mt-2 text-[1.25rem] font-semibold leading-none tracking-tight",h.value].join(" "),children:u}),o.jsx("div",{className:["mt-1.5 truncate text-[0.72rem] font-medium",h.note].join(" "),children:d})]})}function Cj({name:a,method:i,balance:r,status:u,note:d,action:m,icon:h,balanceHidden:x,onActivate:p,onRecharge:v}){const g=u==="Bound",b=g&&x&&hl(i)==="clawtip";return o.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_74px_82px] items-center gap-2 border-b border-[var(--color-line-2)] px-2 py-2.5 last:border-b-0 sm:grid-cols-[minmax(0,1fr)_96px_92px] sm:gap-3 sm:px-3",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[o.jsx(Tj,{method:i,icon:h,bound:g}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-semibold text-[var(--color-ink)]",children:a}),d?o.jsx("div",{className:"mt-0.5 truncate text-[0.74rem] text-[var(--color-muted)]",children:d}):null]})})]}),b?o.jsxs("button",{type:"button",className:"inline-flex w-fit items-center gap-1 rounded-[7px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-2 py-1 font-mono text-[0.82rem] font-semibold text-[var(--color-purple)] transition hover:border-[var(--color-purple)] hover:bg-white active:translate-y-px",onClick:v,"aria-label":"Scan with JD app to view ClawTip wallet balance",title:"Scan with JD app to view wallet balance",children:[o.jsx(q2,{className:"size-3.5"}),"••••"]}):o.jsx("div",{className:"font-mono text-[0.9rem] font-semibold text-[var(--color-ink)]",children:r}),o.jsx("button",{className:"rounded-[8px] bg-[var(--color-purple)] px-2.5 py-1.5 text-[0.76rem] font-semibold text-white shadow-[0_8px_18px_rgba(124,61,240,0.16)] transition hover:bg-[#6e32dc] active:translate-y-px",onClick:g?v:p,"aria-label":m,title:`${m} ${a}`,children:m})]})}function Tj({method:a,icon:i,bound:r}){return hl(a)==="clawtip"?o.jsx("div",{className:"grid size-8 shrink-0 place-items-center rounded-[8px] border border-red-100 bg-[#e1251b] font-mono text-[0.72rem] font-black uppercase tracking-tight text-white shadow-[0_8px_18px_rgba(225,37,27,0.16)]","aria-label":"JD wallet",title:"JD wallet",children:"JD"}):o.jsx("div",{className:["grid size-8 shrink-0 place-items-center rounded-[8px] text-[0.8rem] font-bold",r?"bg-[var(--color-lavender)] text-[var(--color-purple)]":"bg-[var(--color-page)] text-[var(--color-muted)]"].join(" "),children:i})}function Ej({modal:a,methods:i,qr:r,loading:u,error:d,onClose:m}){const h=a.kind==="recharge",x=i.find(z=>z.method===a.method),p=h&&hl(a.method)==="clawtip",v=Td(x==null?void 0:x.config,"resourceUrl"),g=Td(x==null?void 0:x.config,"walletConfigPath"),b=Td(x==null?void 0:x.config,"orderNo"),E=(r==null?void 0:r.walletConfigPresent)===!0||d0(x==null?void 0:x.config,"walletConfigPresent"),C=!h&&!!(r!=null&&r.qrImageUrl)&&!E&&!d,A=(x==null?void 0:x.name)??u0(a.method);return o.jsx("div",{className:"fixed inset-0 z-30 grid place-items-center overflow-y-auto bg-[rgba(32,26,56,0.28)] px-4 py-6",children:o.jsxs("div",{className:"w-full max-w-[820px] rounded-[14px] bg-white p-5 shadow-[0_20px_56px_rgba(32,26,56,0.20)] sm:p-6",children:[o.jsxs("div",{className:"flex items-start justify-between gap-4",children:[o.jsxs("div",{children:[o.jsx("h3",{className:"text-[1.05rem] font-semibold text-[var(--color-ink)]",children:p?"ClawTip wallet QR":h?`Recharge ${A}`:`Activate ${A}`}),o.jsx("p",{className:"mt-1 text-[0.82rem] leading-5 text-[var(--color-muted)]",children:p?"Scan with JD app to view wallet balance or recharge.":h?"Load the fixed ClawTip recharge QR from static assets.":"Reuse the tb init ClawTip flow and wait for wallet binding."})]}),o.jsx("button",{className:"rounded-[7px] p-1.5 text-[var(--color-muted)] transition hover:bg-[var(--color-page)]",onClick:m,"aria-label":"Close payment modal",children:o.jsx(Zr,{className:"size-4"})})]}),o.jsxs("div",{className:"mt-5 flex flex-col gap-4",children:[o.jsx("div",{className:"mx-auto grid min-h-[320px] w-full max-w-[720px] place-items-center overflow-hidden rounded-[12px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-3 sm:min-h-[560px] sm:p-4",children:r!=null&&r.qrImageUrl?o.jsx("img",{className:"max-h-[72vh] w-full object-contain",src:r.qrImageUrl,alt:`${A} ${h?"recharge":"activation"} QR code`}):o.jsxs("div",{className:"flex flex-col items-center gap-2 px-3 text-center text-[0.78rem] leading-5 text-[var(--color-muted)]",children:[u?o.jsx(Et,{className:"size-5 animate-spin text-[var(--color-purple)]"}):null,o.jsx("span",{children:u?"Generating ClawTip QR...":"QR image unavailable"})]})}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[o.jsx(Lr,{label:"Method",value:A}),o.jsx(Lr,{label:"Wallet",value:E?"bound":"waiting",warn:!E}),r!=null&&r.orderNo||b?o.jsx(Lr,{label:"Order",value:(r==null?void 0:r.orderNo)??b??""}):null,r!=null&&r.walletConfigPath||g?o.jsx(Lr,{label:"Config",value:Hj((r==null?void 0:r.walletConfigPath)??g??"")}):null,r!=null&&r.clawtipId?o.jsx(Lr,{label:"Device",value:r.clawtipId}):null]}),d?o.jsx("div",{className:"rounded-[8px] border border-rose-100 bg-rose-50 px-3 py-2 text-[0.78rem] leading-5 text-rose-700",children:d instanceof Error?d.message:String(d)}):null,r!=null&&r.qrImageUrl?o.jsx("div",{className:"rounded-[8px] border border-emerald-100 bg-emerald-50 px-3 py-2 text-[0.78rem] leading-5 text-emerald-800",children:h?"Scan with JD app to view wallet balance or recharge.":o.jsxs("span",{className:"flex items-start gap-2",children:[C?o.jsx(Et,{className:"mt-0.5 size-4 shrink-0 animate-spin"}):null,o.jsx("span",{children:E?"Wallet bound. Closing...":"Scan with JD app. TokenBuddy is waiting for the local wallet config."})]})}):null,r!=null&&r.resourceUrl||v?o.jsx("a",{className:"block rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 py-2 font-mono text-[0.75rem] text-[var(--color-purple)] transition hover:bg-[var(--color-lavender)]",href:(r==null?void 0:r.resourceUrl)??v,target:"_blank",rel:"noreferrer",children:c0((r==null?void 0:r.resourceUrl)??v??"")}):!(r!=null&&r.qrImageUrl)&&!u&&!d?o.jsxs("div",{className:"rounded-[8px] border border-amber-100 bg-amber-50 px-3 py-2 text-[0.78rem] leading-5 text-amber-800",children:["No recharge link is available from the daemon. Run ",o.jsx("span",{className:"font-mono",children:"tb init"})," to bind this payment method."]}):null]})]})]})})}function Aj({days:a,series:i}){const d={top:14,right:18,bottom:26,left:26},m=i.flatMap(v=>[...v.input,...v.output]),h=Math.max(1,...m),x=v=>d.left+v*(680-d.left-d.right)/Math.max(1,a.length-1),p=v=>d.top+(1-v/h)*(150-d.top-d.bottom);return o.jsx("div",{className:"rounded-[var(--radius-lg)] border border-[var(--color-line-2)] bg-white px-3 py-1.5",children:o.jsxs("svg",{className:"h-[160px] w-full",viewBox:"0 0 680 150",role:"img","aria-label":"Daily model input and output usage lines",children:[[.25,.5,.75,1].map(v=>o.jsx("line",{x1:d.left,x2:680-d.right,y1:d.top+(1-v)*(150-d.top-d.bottom),y2:d.top+(1-v)*(150-d.top-d.bottom),stroke:"var(--color-chart-grid)",strokeWidth:"1"},v)),a.map((v,g)=>o.jsx("text",{x:x(g),y:143,textAnchor:"middle",className:"fill-[var(--color-muted)] text-[10px]",children:v},v)),i.map(v=>o.jsxs("g",{children:[o.jsx("path",{d:Fd(v.input.map((g,b)=>[x(b),p(g)])),fill:"none",stroke:v.color,strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"}),o.jsx("path",{d:Fd(v.output.map((g,b)=>[x(b),p(g)])),fill:"none",stroke:v.color,strokeWidth:"2.4",strokeDasharray:"5 5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.75"}),v.input.map((g,b)=>o.jsx("circle",{cx:x(b),cy:p(g),r:"2.7",fill:v.color},`${v.model}-input-${b}`)),v.output.map((g,b)=>o.jsx("circle",{cx:x(b),cy:p(g),r:"2.2",fill:"#fff",stroke:v.color,strokeWidth:"1.8"},`${v.model}-output-${b}`))]},v.model)),i.length===0?o.jsx("text",{x:680/2,y:150/2,textAnchor:"middle",className:"fill-[var(--color-muted)] text-[12px]",children:"No token usage yet"}):null]})})}function zj({days:a,values:i,total:r}){const m={top:10,right:8,bottom:16,left:8},h=Math.max(1,...i),x=v=>m.left+v*(190-m.left-m.right)/Math.max(1,i.length-1),p=v=>m.top+(1-v/h)*(72-m.top-m.bottom);return o.jsxs("div",{className:"rounded-[var(--radius-lg)] border border-[var(--color-line-2)] bg-white px-3 py-1.5",children:[o.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[o.jsx("span",{className:"text-[0.74rem] font-semibold text-[var(--color-ink)]",children:"Cost curve"}),o.jsx("span",{className:"font-mono text-[0.74rem] text-[var(--color-muted)]",children:r})]}),o.jsxs("svg",{className:"h-[66px] w-full",viewBox:"0 0 190 72",role:"img","aria-label":"Daily cost curve",children:[o.jsx("path",{d:Fd(i.map((v,g)=>[x(g),p(v)])),fill:"none",stroke:"var(--color-chart-cost)",strokeWidth:"3",strokeLinecap:"round"}),i.map((v,g)=>o.jsx("circle",{cx:x(g),cy:p(v),r:"2.4",fill:"var(--color-chart-cost)"},a[g]))]})]})}function Rj({values:a,total:i}){const r=Math.max(1,...a);return o.jsxs("div",{className:"rounded-[var(--radius-lg)] border border-[var(--color-line-2)] bg-white px-3 py-1.5",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[o.jsx("span",{className:"text-[0.74rem] font-semibold text-[var(--color-ink)]",children:"30 day spend"}),o.jsx("span",{className:"font-mono text-[0.74rem] text-[var(--color-muted)]",children:i})]}),o.jsx("div",{className:"flex h-[60px] items-end gap-1",children:a.map((u,d)=>o.jsx("span",{className:"flex-1 rounded-t-[3px] bg-[var(--color-tokens)]/75",style:{height:`${Math.max(8,u/r*100)}%`}},d))})]})}function Fd(a){return a.length===0?"":a.length===1?`M ${a[0][0]} ${a[0][1]}`:a.reduce((i,r,u)=>{if(u===0)return`M ${r[0]} ${r[1]}`;const d=a[u-1],m=(d[0]+r[0])/2;return`${i} C ${m} ${d[1]}, ${m} ${r[1]}, ${r[0]} ${r[1]}`},"")}function Oj({model:a,color:i}){return o.jsxs("span",{className:"inline-flex min-w-0 max-w-[9rem] items-center gap-1.5 rounded-[7px] border border-[var(--color-line-2)] bg-white px-1.5 py-0.5",title:a,children:[o.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{backgroundColor:i}}),o.jsx("span",{className:"truncate font-mono text-[0.68rem]",children:a})]})}function Gv({label:a,dashed:i=!1}){return o.jsxs("span",{className:"inline-flex items-center gap-1 rounded-[7px] border border-[var(--color-line-2)] bg-white px-1.5 py-0.5",children:[o.jsx("span",{className:["h-px w-4 border-t border-[var(--color-ink)]",i?"border-dashed":""].join(" ")}),o.jsx("span",{className:"font-mono text-[0.68rem]",children:a})]})}function Lr({label:a,value:i,warn:r=!1}){return o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[o.jsx("div",{className:"text-[0.78rem] text-[var(--color-muted)]",children:a}),o.jsx("div",{className:["font-mono text-[0.94rem] font-semibold",r?"text-amber-700":"text-[var(--color-ink)]"].join(" "),children:i})]})}function _j({checkedAt:a,healthy:i,pid:r,status:u,proxyPort:d,controlPort:m,registryUrl:h}){const x=[{icon:o.jsx(A2,{className:"size-3"}),label:"Daemon",value:r?`pid ${r}`:u??Te,tone:i?"green":"amber"},{icon:o.jsx(Y2,{className:"size-3"}),label:"Proxy",value:d?`:${d}`:Te,tone:"blue"},{icon:o.jsx(F2,{className:"size-3"}),label:"Control",value:m?`:${m}`:Te,tone:"router"},{icon:o.jsx(k2,{className:"size-3"}),label:"Registry",value:h?c0(h):Te,tone:"spend"}];return o.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 rounded-[var(--radius-xl)] border border-[var(--color-line-2)] bg-white px-3 py-2 shadow-[var(--shadow-chip)]",children:[o.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-[var(--radius-md)] border border-[var(--color-line-2)] bg-white px-2.5 py-1 text-[0.72rem] font-medium text-[var(--color-muted)]",children:[o.jsx(Z2,{className:"size-3.5"}),a]}),x.map(p=>o.jsx(Dj,{...p},p.label))]})}function Dj({icon:a,label:i,value:r,tone:u}){const d={green:"bg-[var(--color-success-soft)] text-[var(--color-success)]",blue:"bg-[var(--color-tokens-soft)] text-[var(--color-tokens)]",router:"bg-[var(--color-lavender)] text-[var(--color-router)]",spend:"bg-[var(--color-spend-soft)] text-[var(--color-spend)]",amber:"bg-[var(--color-warning-soft)] text-[var(--color-warning)]"}[u];return o.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-2 rounded-[var(--radius-md)] border border-[var(--color-line-2)] bg-white px-2.5 py-1",children:[o.jsx("span",{className:["grid size-5 shrink-0 place-items-center rounded-[var(--radius-sm)]",d].join(" "),children:a}),o.jsx("span",{className:"text-[0.72rem] font-semibold text-[var(--color-ink)]",children:i}),o.jsx("span",{className:"min-w-0 truncate font-mono text-[0.72rem] text-[var(--color-muted)]",children:r})]})}function kj(a){const i=Kv(7),r=Kv(30),u=Wd(new Date),d=new Set(i.map(L=>L.key)),m=new Map(r.map((L,V)=>[L.key,V])),h=["var(--color-chart-input)","var(--color-spend)","var(--color-chart-cost)","var(--color-inventory)"],x=new Map,p=i.map(()=>0),v=r.map(()=>0);let g=0,b=0,E=0,C=0,A=0,z=0,B=0,U=0,G=0;for(const L of a){const V=Wd(new Date(L.createdAt)),P=L.billedMicros??0,J=L.promptTokens??0,ee=L.completionTokens??0;G+=1,b+=P,C+=J,A+=ee,V===u&&(U+=1,g+=P,z+=J,B+=ee);const le=i.findIndex(F=>F.key===V);if(le>=0){E+=P,p[le]+=P/1e6;const F=x.get(L.modelId)??{input:i.map(()=>0),output:i.map(()=>0),total:0};F.input[le]+=J,F.output[le]+=ee,F.total+=J+ee,x.set(L.modelId,F)}else d.has(V)&&(E+=P);const oe=m.get(V);oe!==void 0&&(v[oe]+=P/1e6)}const K=Array.from(x.entries()).sort((L,V)=>V[1].total-L[1].total).slice(0,4).map(([L,V],P)=>({model:L,color:h[P%h.length],input:V.input,output:V.output}));return{days:i.map(L=>L.label),modelUsage:K,cost:p,thirtyDaySpend:v,todaySpendMicros:g,totalSpendMicros:b,weeklySpendMicros:E,inputTokens:C,outputTokens:A,todayInputTokens:z,todayOutputTokens:B,todayRequestCount:U,totalRequestCount:G}}function Uj(a,i){const r=new Map;for(const u of[...i].sort((d,m)=>d.createdAt.localeCompare(m.createdAt)))!u.paymentMethod||u.balanceSnapshotMicros===void 0||r.set(hl(u.paymentMethod),u.balanceSnapshotMicros);return[...a].filter(u=>hl(u.method)!=="mock").sort((u,d)=>Number(d.isDefault)-Number(u.isDefault)||u.method.localeCompare(d.method)).map(u=>{const d=hl(u.method),m=u.enabled||!!(u.config&&Object.keys(u.config).length>0),h=r.get(d),x=d==="clawtip";return{name:u0(u.method),method:u.method,balance:x?"••••":st(h),status:u.enabled?"Bound":"Available",note:m?u.isDefault?"Default wallet":"Configured":"Not bound",action:u.enabled?"Recharge":"Activate",icon:Bj(u.method),balanceHidden:x,config:u.config}})}function Kv(a){const i=[],r=new Intl.DateTimeFormat("en",{weekday:"short"});for(let u=a-1;u>=0;u-=1){const d=new Date;d.setHours(0,0,0,0),d.setDate(d.getDate()-u),i.push({key:Wd(d),label:r.format(d)})}return i}function Wd(a){if(Number.isNaN(a.getTime()))return"";const i=a.getFullYear(),r=String(a.getMonth()+1).padStart(2,"0"),u=String(a.getDate()).padStart(2,"0");return`${i}-${r}-${u}`}function u0(a){const i=hl(a);return i==="clawtip"?"ClawTip":i==="alipay-agent"?"Alipay Agent Payment":i==="wechat-pay"?"WeChat Pay":i==="coinbase-smart-wallet"?"Coinbase Smart Wallet":a.split(/[-_\s]+/).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function Bj(a){const i=hl(a);return i==="clawtip"?"C":i==="wechat-pay"?"W":i==="alipay-agent"?"A":i.charAt(0).toUpperCase()||"P"}function hl(a){return a.trim().toLowerCase()}function c0(a){try{const i=new URL(a),r=i.pathname==="/"?"":i.pathname;return`${i.host}${r}`.slice(0,34)}catch{return a.length>34?`${a.slice(0,31)}...`:a}}function Hj(a){const i=a.split("/");return i.length<=3?a:`.../${i.slice(-2).join("/")}`}function Td(a,i){const r=a==null?void 0:a[i];return typeof r=="string"&&r.length>0?r:void 0}function d0(a,i){return(a==null?void 0:a[i])===!0}const Lj=[{value:"fullAuto",label:"Full auto",help:"Choose from all compatible sellers for each model."},{value:"fixedSet",label:"Fixed set",help:"Choose automatically within your selected seller set."},{value:"fixed",label:"Fixed",help:"Pin one fixed seller for each model."}],qj=[{value:"balanced",label:"Balanced",help:"Balance reliability, speed, and cost."},{value:"speed",label:"Speed first",help:"Prioritize low TTFT and high throughput."},{value:"discount",label:"Cost first",help:"Prioritize discount and available balance."}];function Qj(){var ge,M,_,Z,I;const a=Ix(),i=e0(),r=t0(),u=xf(),d=cj(),m=Wo(),[h,x]=j.useState({mode:"fullAuto",scorer:"balanced"}),[p,v]=j.useState([]),[g,b]=j.useState(""),[E,C]=j.useState(null),[A,z]=j.useState(null),B=oj({...h,modelId:g}),U=u.data,G=((ge=r.data)==null?void 0:ge.sellers)??[],K=((M=d.data)==null?void 0:M.focusSet)??[],L=j.useMemo(()=>Ij((U==null?void 0:U.data)??[],K),[K,U==null?void 0:U.data]),V=tS(B.data),P=j.useMemo(()=>eS(G,U,(V==null?void 0:V.routes)??[]),[U,V==null?void 0:V.routes,G]),J=j.useMemo(()=>p.map(X=>L.find(ae=>ae.id===X)).filter(p0),[L,p]),ee=h.sellerIds??[],le=h.fixedByModel??{},oe=J.length,F=J.filter(X=>h.mode==="fixed"?!!le[X.id]:h.mode==="fixedSet"?ee.length>0:!0).length,fe=j.useMemo(()=>{var X;return s0({inferences:((X=m.data)==null?void 0:X.inferences)??[],modelsResponse:U,sellersResponse:r.data,previewPlan:V,activeModelId:g})},[g,(_=m.data)==null?void 0:_.inferences,U,V,r.data]);j.useEffect(()=>{var X;(X=a.data)!=null&&X.strategy&&x(a.data.strategy)},[(Z=a.data)==null?void 0:Z.strategy]),j.useEffect(()=>{if(p.length>0||L.length===0)return;const X=K.filter(W=>L.some(Ae=>Ae.id===W)),ae=X.length>0?X:L.slice(0,2).map(W=>W.id);v(ae),b(ae[0]??"")},[K,L,p.length]),j.useEffect(()=>{!g||p.includes(g)||b(p[0]??"")},[g,p]),j.useEffect(()=>{g&&B.refetch()},[g,h.mode,h.scorer,h.sellerId,(I=h.sellerIds)==null?void 0:I.join(","),rS(h.fixedByModel)]);async function ye(X){x(X),C(null);try{await i.mutateAsync(X)}catch(ae){C(ae instanceof Error?ae.message:String(ae))}}function Ee(X){v(ae=>{if(ae.includes(X)){const Ae=ae.filter(Oe=>Oe!==X);return g===X&&b(Ae[0]??""),Lo(Ae).catch(()=>{}),Ae}b(X);const W=[...ae,X];return Lo(W).catch(()=>{}),W})}function me(X){v(ae=>{const W=ae.filter(Ae=>Ae!==X);return g===X&&b(W[0]??""),Lo(W).catch(()=>{}),W})}function D(X){const ae=lS({...h,mode:X},P,g);ye(ae)}function $(X){ye({...h,scorer:X})}function re(X,ae){const W=h.sellerIds??[],Ae=W.includes(ae)?W.filter(Oe=>Oe!==ae):[...W,ae];ye({...h,mode:"fixedSet",sellerIds:Ae,sellerId:void 0})}function be(X,ae){const W={...h.fixedByModel??{},[X]:ae};ye({...h,mode:"fixed",fixedByModel:W,sellerId:void 0,sellerIds:void 0}),b(X),z(null)}return o.jsxs("div",{className:"space-y-5",children:[o.jsx("section",{children:o.jsxs(jt,{className:"p-4",children:[o.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--color-line-2)] px-4 py-3",children:[o.jsx("div",{className:"min-w-0 flex-1",children:o.jsx("div",{className:"text-[0.78rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Models"})}),o.jsxs("button",{type:"button",onClick:()=>z({kind:"models"}),className:"inline-flex items-center gap-1.5 rounded-[8px] bg-[var(--color-purple)] px-3 py-1.5 text-[0.78rem] font-semibold text-white hover:bg-[var(--color-purple-2)]","aria-label":"Add",title:"Add models","data-testid":"routing-add-models",children:[o.jsx(Jd,{size:14}),"Add"]})]}),o.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[J.map(X=>{const ae=g===X.id,W=X.sellerCount>0;return o.jsxs("div",{className:["inline-flex min-h-9 items-center gap-2 rounded-[9px] border px-3 py-1.5 transition-colors",W?"border-[var(--color-lavender-2)] bg-[var(--color-lavender)] text-[var(--color-purple)] hover:border-[var(--color-purple)] hover:bg-white":"border-rose-200 bg-rose-50 text-rose-700 hover:bg-white",ae?"ring-2 ring-[var(--color-lavender-2)] ring-offset-1 ring-offset-white":""].join(" "),children:[o.jsx("button",{type:"button",onClick:()=>b(X.id),className:"flex items-center text-left",children:o.jsx("span",{className:["font-mono text-[0.82rem] font-semibold",W?"text-[var(--color-purple)]":"text-rose-700"].join(" "),children:X.id})}),o.jsx("button",{type:"button",onClick:()=>me(X.id),className:["inline-flex size-5 items-center justify-center rounded-[6px]",W?"text-[var(--color-purple)]/70 hover:bg-white hover:text-[var(--color-purple)]":"text-rose-700/70 hover:bg-white hover:text-rose-700"].join(" "),"aria-label":`Remove ${X.id}`,children:o.jsx($x,{size:12})})]},X.id)}),J.length===0?o.jsx("div",{className:"px-4 py-8 text-center text-[0.88rem] text-[var(--color-muted)]",children:"No models yet. Click Add to add common models."}):null,d.isError?o.jsx("div",{className:"px-3 py-2 text-[0.82rem] text-amber-700",children:"Focus models could not be saved."}):null]})]})}),o.jsx("section",{children:o.jsx(jt,{className:"overflow-hidden",children:o.jsxs("div",{className:"p-5",children:[o.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[o.jsx("div",{className:"text-[0.78rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Strategy"}),o.jsxs("div",{className:"text-[0.78rem] text-[var(--color-muted)]",children:[F,"/",Math.max(oe,1)," configured"]})]}),a.isLoading||r.isLoading||u.isLoading?o.jsx("div",{className:"mb-3 rounded-[10px] border border-[var(--color-line-2)] bg-white px-3 py-2 text-[0.82rem] text-[var(--color-muted)]",children:"Loading routing data..."}):null,a.isError||r.isError||u.isError?o.jsx("div",{className:"mb-3 rounded-[10px] border border-rose-100 bg-rose-50 px-3 py-2 text-[0.82rem] text-rose-700",children:"Some routing data could not be loaded. Check that tb-proxyd is running."}):null,E?o.jsx("div",{className:"mb-3 rounded-[10px] border border-rose-100 bg-rose-50 px-3 py-2 text-[0.82rem] text-rose-700",children:E}):null,o.jsx("div",{className:"mb-5 grid grid-cols-1 gap-2 md:grid-cols-3",children:Lj.map(X=>o.jsx(Fj,{active:h.mode===X.value,title:X.label,description:X.help,onClick:()=>D(X.value)},X.value))}),o.jsx("div",{className:"rounded-[14px] border border-[var(--color-line-2)] bg-white p-4",children:o.jsx(Yj,{mode:h.mode,scorer:h.scorer,selectedModels:J,fixedSetSellers:ee,fixedByModel:le,sellers:P,activeModelId:g,onScorerChange:$,onOpenSellerPicker:z,onToggleFixedSetSeller:re})})]})})}),o.jsx(Gj,{summary:fe}),(A==null?void 0:A.kind)==="models"?o.jsx($j,{models:L,selectedModelIds:p,onClose:()=>z(null),onToggle:Ee}):null,(A==null?void 0:A.kind)==="sellers"?o.jsx(Jj,{modelId:A.modelId,selection:A.selection,selectedSellerIds:A.selection==="single"?le[A.modelId]?[le[A.modelId]]:[]:ee,scorer:h.scorer,sellers:P,onClose:()=>z(null),onToggle:X=>{A.selection==="single"?be(A.modelId,X):re(A.modelId,X)}}):null]})}function Yj({mode:a,scorer:i,selectedModels:r,fixedSetSellers:u,fixedByModel:d,sellers:m,activeModelId:h,onScorerChange:x,onOpenSellerPicker:p,onToggleFixedSetSeller:v}){var E;const g=oS(r,h),b=(E=g[0])==null?void 0:E.id;return a==="fullAuto"?o.jsx("div",{children:o.jsx(Xv,{scorer:i,onChange:x})}):a==="fixedSet"?o.jsxs("div",{className:"space-y-3",children:[o.jsx(Xv,{scorer:i,onChange:x}),o.jsx(Vj,{modelId:b,sellers:m,sellerIds:u,onChoose:C=>p({kind:"sellers",modelId:C,selection:"multi"}),onRemove:C=>{b&&v(b,C)}})]}):o.jsx("div",{className:"space-y-3",children:o.jsx(Zj,{selectedModels:g,activeModelId:h,resolveValue:C=>iS(d[C],m),onChoose:C=>p({kind:"sellers",modelId:C,selection:"single"})})})}function Gj({summary:a}){return o.jsx("section",{children:o.jsxs(jt,{className:"overflow-hidden",children:[o.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-[var(--color-line-2)] px-4 py-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[0.78rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Model route activity"}),o.jsxs("div",{className:"mt-0.5 font-mono text-[0.74rem] text-[var(--color-muted)]",children:[Ke(a.totalRequests)," requests · ",pl(a.totalTokens)," tokens · ",st(a.totalSpendMicros,{digits:4})]})]}),o.jsxs("div",{className:"rounded-[8px] border border-[var(--color-line-2)] bg-white px-2.5 py-1.5 font-mono text-[0.74rem] text-[var(--color-muted)]",children:[Ke(a.rows.length)," models"]})]}),o.jsxs("div",{className:"divide-y divide-[var(--color-line-2)] bg-white xl:hidden",children:[a.rows.map(i=>o.jsx(Kj,{row:i},`${i.source}-${i.modelId}-${i.currentSellerId}`)),a.rows.length===0?o.jsx("div",{className:"px-4 py-8 text-center text-[var(--color-muted)]",children:"No model traffic yet."}):null]}),o.jsx("div",{className:"hidden min-w-0 max-w-full overflow-x-auto xl:block",children:o.jsxs("table",{className:"w-full min-w-[1180px] border-collapse text-left text-[0.82rem]",children:[o.jsx("thead",{className:"bg-white/70 text-[0.68rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"px-4 py-2.5 font-semibold",children:"MODEL"}),o.jsx("th",{className:"px-4 py-2.5 font-semibold",children:"NODE"}),o.jsx("th",{className:"px-4 py-2.5 text-right font-semibold",children:"REQ"}),o.jsx("th",{className:"px-4 py-2.5 text-right font-semibold",children:"DISC"}),o.jsx("th",{className:"px-4 py-2.5 text-right font-semibold",children:"TTFT"}),o.jsx("th",{className:"px-4 py-2.5 text-right font-semibold",children:"TOKEN"}),o.jsx("th",{className:"px-4 py-2.5 font-semibold",children:"SWITCH"}),o.jsx("th",{className:"px-4 py-2.5 font-semibold",children:"TIME"})]})}),o.jsxs("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:[a.rows.map(i=>o.jsx(Xj,{row:i},`${i.source}-${i.modelId}-${i.currentSellerId}`)),a.rows.length===0?o.jsx("tr",{children:o.jsx("td",{colSpan:8,className:"px-4 py-8 text-center text-[var(--color-muted)]",children:"No model traffic yet."})}):null]})]})})]})})}function Kj({row:a}){return o.jsxs("article",{className:"px-4 py-3",children:[o.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-mono text-[0.92rem] font-semibold text-[var(--color-ink)]",title:a.modelId,children:a.modelId}),o.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[o.jsx(Ni,{tone:a.source==="ledger"?"green":"amber",children:a.source}),a.lastStatus?o.jsx(Ni,{tone:Ka(a.lastStatus),children:Rl(a.lastStatus)}):null,a.upstreamStatus?o.jsx(Ni,{tone:Ka(a.upstreamStatus),children:Rl(a.upstreamStatus)}):null]}),a.routeReason?o.jsx("div",{className:"mt-1 truncate text-[0.72rem] text-[var(--color-muted)]",title:a.routeReason,children:a.routeReason}):null]}),o.jsxs("div",{className:"min-w-0 text-right",children:[o.jsx("div",{className:"truncate font-semibold text-[var(--color-purple)]",title:a.currentSellerId,children:a.currentSellerName}),o.jsx("div",{className:"mt-0.5 truncate font-mono text-[0.72rem] text-[var(--color-muted)]",title:a.currentSellerId,children:a.currentSellerId}),o.jsx("div",{className:"mt-1 text-[0.72rem] text-[var(--color-muted)]",children:a.currentSellerPaymentMethods.length>0?a.currentSellerPaymentMethods.join(", "):Te})]})]}),o.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-3",children:[o.jsx(gi,{label:"Node stats",value:Ke(a.currentSellerRequests),detail:`${Ke(a.sellerModelCount)} models · ${Ke(a.touchedSellerCount)} nodes`}),o.jsx(gi,{label:"Discount",value:a.sellerDiscount,detail:`fee ${a.sellerServiceFee} · ${n0(a.inputPriceMicrosPer1m,a.outputPriceMicrosPer1m)}`,tone:"green"}),o.jsx(gi,{label:"Speed",value:xt(a.lastTtftMs??a.avgTtftMs),detail:`${xt(a.lastDurationMs??a.avgDurationMs)} total`}),o.jsx(gi,{label:"Tokens",value:pl(a.totalTokens),detail:`${$r(a.inputTokens,a.outputTokens)} · ${st(a.totalSpendMicros,{digits:4})}`}),o.jsx(gi,{label:"Switch",value:vl(a.selectedAt),compact:!0}),o.jsx(gi,{label:"Last access",value:vl(a.lastAccessAt),detail:a.lastRequestId??void 0,compact:!0})]})]})}function gi({label:a,value:i,detail:r,tone:u="default",compact:d=!1}){return o.jsxs("div",{className:"min-w-0 rounded-[9px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-2.5 py-2",children:[o.jsx("div",{className:"text-[0.62rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:a}),o.jsx("div",{className:["mt-1 min-w-0 truncate font-mono font-semibold",d?"text-[0.72rem]":"text-[0.88rem]",u==="green"?"text-emerald-700":"text-[var(--color-ink)]"].join(" "),title:i,children:i}),r?o.jsx("div",{className:"mt-0.5 truncate text-[0.68rem] text-[var(--color-muted)]",title:r,children:r}):null]})}function Xj({row:a}){return o.jsxs("tr",{className:"align-top transition hover:bg-[var(--color-lavender)]/25",children:[o.jsxs("td",{className:"px-4 py-3",children:[o.jsx("div",{className:"max-w-[230px] truncate font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",title:a.modelId,children:a.modelId}),o.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[o.jsx(Ni,{tone:a.source==="ledger"?"green":"amber",children:a.source}),a.lastStatus?o.jsx(Ni,{tone:Ka(a.lastStatus),children:Rl(a.lastStatus)}):null,a.upstreamStatus?o.jsx(Ni,{tone:Ka(a.upstreamStatus),children:Rl(a.upstreamStatus)}):null]}),a.routeReason?o.jsx("div",{className:"mt-1 max-w-[240px] truncate text-[0.72rem] text-[var(--color-muted)]",title:a.routeReason,children:a.routeReason}):null]}),o.jsxs("td",{className:"px-4 py-3",children:[o.jsx("div",{className:"max-w-[210px] truncate font-semibold text-[var(--color-purple)]",title:a.currentSellerId,children:a.currentSellerName}),o.jsx("div",{className:"mt-0.5 max-w-[210px] truncate font-mono text-[0.72rem] text-[var(--color-muted)]",title:a.currentSellerId,children:mj(a.currentSellerId)}),o.jsx("div",{className:"mt-1 text-[0.72rem] text-[var(--color-muted)]",children:a.currentSellerPaymentMethods.length>0?a.currentSellerPaymentMethods.join(", "):Te})]}),o.jsxs("td",{className:"px-4 py-3 text-right",children:[o.jsx("div",{className:"font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",children:Ke(a.currentSellerRequests)}),o.jsx("div",{className:"mt-0.5 text-[0.72rem] text-[var(--color-muted)]",children:"node requests"}),o.jsxs("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:[Ke(a.sellerModelCount)," models · ",Ke(a.touchedSellerCount)," nodes"]})]}),o.jsxs("td",{className:"px-4 py-3 text-right",children:[o.jsx("div",{className:"font-mono text-[0.84rem] font-semibold text-emerald-700",children:a.sellerDiscount}),o.jsxs("div",{className:"mt-0.5 text-[0.72rem] text-[var(--color-muted)]",children:["fee ",a.sellerServiceFee]}),o.jsx("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:n0(a.inputPriceMicrosPer1m,a.outputPriceMicrosPer1m)})]}),o.jsxs("td",{className:"px-4 py-3 text-right",children:[o.jsx("div",{className:"font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",children:xt(a.lastTtftMs??a.avgTtftMs)}),o.jsx("div",{className:"mt-0.5 text-[0.72rem] text-[var(--color-muted)]",children:"TTFT"}),o.jsxs("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:[xt(a.lastDurationMs??a.avgDurationMs)," total"]})]}),o.jsxs("td",{className:"px-4 py-3 text-right",children:[o.jsx("div",{className:"font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",children:pl(a.totalTokens)}),o.jsx("div",{className:"mt-0.5 text-[0.72rem] text-[var(--color-muted)]",children:$r(a.inputTokens,a.outputTokens)}),o.jsx("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:st(a.totalSpendMicros,{digits:4})})]}),o.jsx("td",{className:"whitespace-nowrap px-4 py-3 font-mono text-[0.74rem] text-[var(--color-muted)]",children:vl(a.selectedAt)}),o.jsxs("td",{className:"whitespace-nowrap px-4 py-3",children:[o.jsx("div",{className:"font-mono text-[0.74rem] text-[var(--color-muted)]",children:vl(a.lastAccessAt)}),a.lastRequestId?o.jsx("div",{className:"mt-1 max-w-[160px] truncate font-mono text-[0.68rem] text-[var(--color-faint)]",title:a.lastRequestId,children:a.lastRequestId}):null]})]})}function Ni({tone:a,children:i}){const r={green:"bg-emerald-50 text-emerald-700",amber:"bg-amber-50 text-amber-700",red:"bg-rose-50 text-rose-700",blue:"bg-blue-50 text-blue-700",gray:"bg-slate-100 text-slate-600"}[a];return o.jsx("span",{className:["rounded-full px-2 py-0.5 text-[0.66rem] font-semibold uppercase",r].join(" "),children:i})}function Xv({scorer:a,onChange:i}){return o.jsx("div",{className:"rounded-[12px] border border-[var(--color-line-2)] bg-white p-1.5",children:o.jsx("div",{className:"grid grid-cols-1 gap-1.5 md:grid-cols-3",children:qj.map(r=>o.jsxs("button",{type:"button",onClick:()=>i(r.value),"aria-label":`Routing scorer: ${r.label}`,className:["flex min-h-14 items-center gap-2 rounded-[9px] px-3 py-2 text-left transition-colors",a===r.value?"bg-[var(--color-lavender)] text-[var(--color-ink)]":"text-[var(--color-muted)] hover:bg-[var(--color-lavender)]/40"].join(" "),children:[o.jsx(Po,{active:a===r.value,fixed:!0}),o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block text-[0.86rem] font-semibold",children:r.label}),o.jsx("span",{className:"block truncate text-[0.72rem] text-[var(--color-muted)]",children:r.help})]})]},r.value))})})}function Vj({modelId:a,sellers:i,sellerIds:r,onChoose:u,onRemove:d}){if(!a)return o.jsx("div",{className:"rounded-[12px] border border-[var(--color-line-2)] bg-white px-3 py-4 text-[0.86rem] text-[var(--color-muted)]",children:"Add models before configuring a seller set."});const m=r.map(h=>i.find(x=>x.id===h)).filter(p0);return o.jsxs("div",{className:"overflow-hidden rounded-[12px] border border-[var(--color-line-2)] bg-white",children:[o.jsxs("div",{className:"flex flex-wrap items-center gap-3 border-b border-[var(--color-line-2)] bg-white/70 px-3 py-2.5",children:[o.jsx("div",{className:"min-w-0 flex-1",children:o.jsx("div",{className:"text-[0.78rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Sellers"})}),o.jsx("button",{type:"button",onClick:()=>u(a),className:"rounded-[8px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-3 py-1.5 text-[0.78rem] font-semibold text-[var(--color-purple)] hover:bg-white","aria-label":`Add sellers to fixed set for ${a}`,children:"Add sellers"})]}),m.length>0?o.jsx("div",{className:"min-w-0 max-w-full overflow-x-auto",children:o.jsxs("table",{className:"w-full border-collapse text-left text-[0.82rem]",children:[o.jsx("thead",{className:"bg-white/70 text-[0.68rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Seller"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Discount"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Markup fee"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Payment"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"TTFT"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Tok/s"}),o.jsx("th",{className:"w-10 px-3 py-2 font-semibold"})]})}),o.jsx("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:m.map(h=>o.jsxs("tr",{children:[o.jsx("td",{className:"px-3 py-2.5 font-semibold text-[var(--color-ink)]",children:h.name}),o.jsxs("td",{className:"whitespace-nowrap px-3 py-2.5 text-right",children:[o.jsx("div",{className:"font-mono font-semibold text-[var(--color-purple)]",children:h.discount}),o.jsx("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:h.price})]}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:h.markupFee}),o.jsx("td",{className:"px-3 py-2.5 text-[var(--color-muted)]",children:h.paymentMethods.join(", ")}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:xt(h.latencyMs)}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:Ke(h.tokensPerSecond)}),o.jsx("td",{className:"px-3 py-2.5 text-right",children:o.jsx("button",{type:"button",onClick:()=>d(h.id),className:"inline-flex size-7 items-center justify-center rounded-[7px] text-[var(--color-muted)] hover:bg-rose-50 hover:text-rose-700","aria-label":`Remove ${h.name}`,children:o.jsx($x,{size:14})})})]},h.id))})]})}):o.jsx("div",{className:"px-3 py-8 text-center text-[0.86rem] text-[var(--color-muted)]",children:"No sellers yet. Click Add sellers to build the fixed set."})]})}function Zj({selectedModels:a,activeModelId:i,resolveValue:r,onChoose:u}){return a.length===0?o.jsx("div",{className:"rounded-[12px] border border-[var(--color-line-2)] bg-white px-3 py-4 text-[0.86rem] text-[var(--color-muted)]",children:"Add models before configuring sellers."}):o.jsx("div",{className:"divide-y divide-[var(--color-line-2)] rounded-[12px] border border-[var(--color-line-2)] bg-white",children:a.map(d=>o.jsxs("div",{className:["flex flex-wrap items-center gap-3 px-3 py-3",i===d.id?"bg-[var(--color-lavender)]/55":""].join(" "),children:[o.jsx("div",{className:"min-w-0 flex-1",children:o.jsx("div",{className:"truncate font-mono text-[0.88rem] font-semibold text-[var(--color-ink)]",children:d.id})}),o.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[o.jsx("button",{type:"button",onClick:()=>u(d.id),className:"max-w-[240px] truncate rounded-[8px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-3 py-1.5 text-[0.78rem] font-semibold text-[var(--color-purple)] hover:bg-white","aria-label":`Choose seller for ${d.id}`,children:r(d.id)}),o.jsx("button",{type:"button",onClick:()=>u(d.id),className:"rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 py-1.5 text-[0.78rem] font-semibold text-[var(--color-muted)] hover:border-[var(--color-lavender-2)] hover:text-[var(--color-purple)]","aria-label":`Reselect seller for ${d.id}`,children:"Reselect"})]})]},d.id))})}function $j({models:a,selectedModelIds:i,onClose:r,onToggle:u}){const[d,m]=j.useState(""),h=a.filter(x=>h0(d,[x.id,x.paymentMethod,x.enabled?"enabled":"not enabled"]));return o.jsxs(f0,{title:"Add models",onClose:r,children:[o.jsx(m0,{value:d,onChange:m,placeholder:"Search models or payment"}),o.jsx("div",{className:"mt-3 overflow-hidden rounded-[12px] border border-[var(--color-line-2)]",children:o.jsxs("table",{className:"w-full border-collapse text-left text-[0.84rem]",children:[o.jsx("thead",{className:"bg-white/70 text-[0.7rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"w-10 px-3 py-2 font-semibold"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Model"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Payment"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Sellers"})]})}),o.jsxs("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:[h.map(x=>{const p=i.includes(x.id);return o.jsxs("tr",{onClick:()=>u(x.id),className:["cursor-pointer",p?"bg-[var(--color-lavender)]/70":"hover:bg-[var(--color-lavender)]/35",x.enabled?"":"opacity-60"].join(" "),children:[o.jsx("td",{className:"px-3 py-2.5",children:o.jsx(Po,{active:p,fixed:!1})}),o.jsx("td",{className:"px-3 py-2.5 font-mono font-semibold text-[var(--color-ink)]",children:x.id}),o.jsx("td",{className:"px-3 py-2.5",children:o.jsx(Wj,{enabled:x.enabled,paymentMethod:x.paymentMethod})}),o.jsx("td",{className:"px-3 py-2.5 text-right text-[var(--color-muted)]",children:x.sellerCount})]},x.id)}),h.length===0?o.jsx("tr",{children:o.jsx("td",{colSpan:4,className:"px-3 py-8 text-center text-[var(--color-muted)]",children:"No models found."})}):null]})]})}),o.jsx("div",{className:"mt-3 flex items-center justify-end border-t border-[var(--color-line-2)] pt-3",children:o.jsx("button",{type:"button",onClick:r,"aria-label":"Done","data-testid":"routing-model-picker-done",className:"inline-flex h-9 items-center justify-center rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)]",children:"Done"})})]})}function Jj({modelId:a,selection:i,selectedSellerIds:r,scorer:u,sellers:d,onClose:m,onToggle:h}){const[x,p]=j.useState(""),g=Pj(d.filter(b=>b.coverageModelIds.includes(a)),[a],u).filter(b=>h0(x,[b.name,b.id,b.paymentMethods.join(" "),b.health,b.notes.join(" ")]));return o.jsxs(f0,{title:`Choose seller · ${a}`,onClose:m,children:[o.jsx(m0,{value:x,onChange:p,placeholder:"Search sellers, payment, notes"}),o.jsx("div",{className:"mt-3 overflow-hidden rounded-[12px] border border-[var(--color-line-2)]",children:o.jsxs("table",{className:"w-full border-collapse text-left text-[0.82rem]",children:[o.jsx("thead",{className:"bg-white/70 text-[0.7rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"w-10 px-3 py-2 font-semibold"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Seller"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Discount"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Markup fee"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"Payment"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"TTFT"}),o.jsx("th",{className:"px-3 py-2 text-right font-semibold",children:"Tok/s"})]})}),o.jsxs("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:[g.map(b=>{const E=r.includes(b.id);return o.jsxs("tr",{onClick:()=>h(b.id),className:["cursor-pointer",E?"bg-[var(--color-lavender)]/70":"hover:bg-[var(--color-lavender)]/35"].join(" "),children:[o.jsx("td",{className:"px-3 py-2.5",children:o.jsx(Po,{active:E,fixed:i==="single"})}),o.jsx("td",{className:"px-3 py-2.5 font-semibold text-[var(--color-ink)]",children:b.name}),o.jsxs("td",{className:"whitespace-nowrap px-3 py-2.5 text-right",children:[o.jsx("div",{className:"font-mono font-semibold text-[var(--color-purple)]",children:b.discount}),o.jsx("div",{className:"mt-0.5 font-mono text-[0.72rem] text-[var(--color-muted)]",children:b.price})]}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:b.markupFee}),o.jsx("td",{className:"px-3 py-2.5 text-[var(--color-muted)]",children:b.paymentMethods.join(", ")}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:xt(b.latencyMs)}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:Ke(b.tokensPerSecond)})]},b.id)}),g.length===0?o.jsx("tr",{children:o.jsx("td",{colSpan:7,className:"px-3 py-8 text-center text-[var(--color-muted)]",children:"No sellers found."})}):null]})]})})]})}function f0({title:a,children:i,onClose:r}){return o.jsx("div",{className:"fixed inset-0 z-30 flex items-center justify-center bg-[#201a38]/35 px-4 py-6 backdrop-blur-sm",children:o.jsxs("div",{className:"max-h-[86dvh] w-full max-w-[820px] overflow-hidden rounded-[14px] border border-[var(--color-line-2)] bg-white shadow-[0_24px_70px_rgba(32,26,56,0.22)]",children:[o.jsxs("div",{className:"flex items-center gap-3 border-b border-[var(--color-line-2)] px-5 py-4",children:[o.jsx("div",{className:"min-w-0 flex-1 truncate text-[1rem] font-semibold text-[var(--color-ink)]",children:a}),o.jsx("button",{type:"button",onClick:r,className:"inline-flex size-8 items-center justify-center rounded-[8px] text-[var(--color-muted)] hover:bg-[var(--color-lavender)] hover:text-[var(--color-purple)]","aria-label":"Close",children:o.jsx(Zr,{size:16})})]}),o.jsx("div",{className:"max-h-[calc(86dvh-65px)] overflow-auto p-4",children:i})]})})}function Fj({active:a,title:i,description:r,onClick:u}){return o.jsxs("button",{type:"button",onClick:u,"aria-label":`Set ${i} routing mode`,className:["min-h-[86px] rounded-[12px] border px-3 py-2.5 text-left transition-all",a?"border-[var(--color-lavender-2)] bg-[var(--color-lavender)] text-[var(--color-ink)]":"border-[var(--color-line-2)] bg-white text-[var(--color-muted)] hover:border-[var(--color-line)]"].join(" "),children:[o.jsxs("span",{className:"flex items-center gap-2 font-mono text-[0.86rem] font-semibold",children:[o.jsx(Po,{active:a,fixed:!0}),i]}),o.jsx("span",{className:"mt-1.5 block text-[0.74rem] leading-snug text-[var(--color-muted)]",children:r})]})}function Wj({enabled:a,paymentMethod:i}){return o.jsxs("span",{className:["inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[0.72rem] ring-1",a?"bg-emerald-50 text-emerald-700 ring-emerald-100":"bg-slate-100 text-slate-500 ring-slate-200"].join(" "),children:[a?o.jsx(P2,{size:12}):o.jsx($d,{size:12}),i," ",a?"enabled":"not enabled"]})}function Po({active:a,fixed:i}){return o.jsx("span",{className:["inline-flex size-5 shrink-0 items-center justify-center border",i?"rounded-full":"rounded-[6px]",a?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line)] bg-white text-transparent"].join(" "),children:o.jsx(Jt,{size:13,strokeWidth:2.4})})}function Pj(a,i,r){return[...a].sort((u,d)=>{const m=Vv(u,i),h=Vv(d,i);return m!==h?h-m:r==="speed"?nS(u.latencyMs,d.latencyMs):r==="discount"?Number.parseInt(d.discount,10)-Number.parseInt(u.discount,10):d.healthScore-u.healthScore})}function Ij(a,i){const r=new Map;for(const d of a){const m=r.get(d.id)??{sellerIds:new Set,paymentMethods:new Set};m.sellerIds.add(d.sellerId);for(const h of d.paymentMethods)m.paymentMethods.add(h);r.set(d.id,m)}const u=new Map(i.map((d,m)=>[d,m]));return Array.from(r.entries()).map(([d,m])=>({id:d,paymentMethod:Array.from(m.paymentMethods)[0]??Te,enabled:m.sellerIds.size>0,sellerCount:m.sellerIds.size})).sort((d,m)=>{const h=u.get(d.id),x=u.get(m.id);return h!==void 0||x!==void 0?(h??9999)-(x??9999):d.id.localeCompare(m.id)})}function eS(a,i,r){const u=(i==null?void 0:i.data)??[],d=new Map(((i==null?void 0:i.sellers)??[]).map(h=>[h.id,h])),m=new Map(r.map(h=>[h.seller.id,h]));return a.map((h,x)=>{var A;const p=m.get(h.id),v=d.get(h.id),g=Array.from(new Set(u.filter(z=>z.sellerId===h.id).map(z=>z.id))),b=(p==null?void 0:p.metrics.ttftMs)??(p==null?void 0:p.metrics.avgLatencyMs),E=p==null?void 0:p.metrics.healthScore,C=(p==null?void 0:p.metrics.discountRatio)??(v==null?void 0:v.discountRatio);return{id:h.id,name:sS(h.name??(v==null?void 0:v.name)??h.id),endpoint:h.url,health:(v==null?void 0:v.status)==="error"||(v==null?void 0:v.status)==="manifest_unavailable"||h.status==="failed"?"offline":h.status==="degraded"?"degraded":"online",healthScore:Number.isFinite(E)?Math.round(E):0,coverageModelIds:g,paymentMethods:(v==null?void 0:v.paymentMethods)??h.paymentMethods??[],discount:a0(C),markupFee:yf(v==null?void 0:v.serviceFeeRatio),price:p?"preview":"registry",latencyMs:Number.isFinite(b)?Math.round(b):void 0,tokensPerSecond:void 0,notes:[((A=h.supportedProtocols)==null?void 0:A.join(", "))||"no protocols",`registry #${x+1}`]}})}function tS(a){if(a)return a.plan??{routes:a.routes,mode:a.mode,scorer:a.scorer,reason:a.reason}}function lS(a,i,r){var u,d;if(a.mode==="fixed"){const m={...a.fixedByModel??{}},h=((u=aS(i,r))==null?void 0:u.id)||((d=i[0])==null?void 0:d.id);return r&&!m[r]&&h&&(m[r]=h),{mode:"fixed",scorer:a.scorer,fixedByModel:m}}if(a.mode==="fixedSet"){const m=a.sellerIds&&a.sellerIds.length>0?a.sellerIds:i.filter(h=>!r||h.coverageModelIds.includes(r)).slice(0,2).map(h=>h.id);return{mode:"fixedSet",scorer:a.scorer,sellerIds:m}}return{mode:"fullAuto",scorer:a.scorer}}function aS(a,i){return a.find(r=>!i||r.coverageModelIds.includes(i))}function Vv(a,i){return i.length===0?a.coverageModelIds.length:i.filter(r=>a.coverageModelIds.includes(r)).length}function nS(a,i){const r=Number.isFinite(a),u=Number.isFinite(i);return r&&u?a-i:r?-1:u?1:0}function iS(a,i){var r;return a?((r=i.find(u=>u.id===a))==null?void 0:r.name)??a:"Not selected"}function rS(a){return Object.entries(a??{}).sort(([i],[r])=>i.localeCompare(r)).map(([i,r])=>`${i}:${r}`).join(",")}function sS(a){var i;return((i=a.split("(")[0])==null?void 0:i.trim())||a}function m0({value:a,onChange:i,placeholder:r}){return o.jsxs("label",{className:"flex items-center gap-2 rounded-[12px] border border-[var(--color-line-2)] bg-white px-3 py-2 text-[0.84rem] text-[var(--color-muted)]",children:[o.jsx(Fo,{size:15}),o.jsx("input",{name:"routing-search",value:a,onChange:u=>i(u.target.value),placeholder:r,className:"min-w-0 flex-1 bg-transparent font-mono text-[0.84rem] text-[var(--color-ink)] outline-none placeholder:text-[var(--color-faint)]"})]})}function h0(a,i){const r=a.trim().toLowerCase();return r?i.some(u=>u.toLowerCase().includes(r)):!0}function oS(a,i){return i?[...a].sort((r,u)=>r.id===i?-1:u.id===i?1:0):a}function p0(a){return a!==void 0}function v0({totalItems:a,pageSize:i,page:r,onPageChange:u,onPageSizeChange:d,pageSizeOptions:m=[25,50,100]}){const h=Math.max(1,Math.ceil(a/i)),x=j.useMemo(()=>uS(r,h),[r,h]);if(a===0)return null;const p=(r-1)*i+1,v=Math.min(r*i,a);return o.jsxs("div",{className:"flex flex-col gap-3 border-t border-[var(--color-line-2)] bg-[var(--color-page)]/60 px-4 py-3 text-[0.85rem] lg:flex-row lg:items-center lg:justify-between",children:[o.jsxs("div",{className:"text-[var(--color-muted)]",children:["Showing ",o.jsx("span",{className:"font-mono font-semibold text-[var(--color-ink)]",children:p}),"-",o.jsx("span",{className:"font-mono font-semibold text-[var(--color-ink)]",children:v})," of"," ",o.jsx("span",{className:"font-mono font-semibold text-[var(--color-ink)]",children:a})]}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("label",{className:"text-[0.78rem] text-[var(--color-muted)]",children:"Rows"}),o.jsx("select",{className:"bg-[var(--color-card)] border border-[var(--color-line-2)] rounded px-1.5 py-0.5 text-[0.85rem] text-[var(--color-ink)] focus:outline-none focus:border-[var(--color-purple)]",value:i,onChange:g=>{const b=Math.max(1,Number(g.target.value)||25);d==null||d(b),u(1)},children:m.map(g=>o.jsx("option",{value:g,children:g},g))}),o.jsxs("div",{className:"ml-2 flex items-center gap-1",children:[o.jsx("button",{type:"button",disabled:r<=1,onClick:()=>u(1),className:"px-2 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] disabled:opacity-40 disabled:cursor-not-allowed hover:bg-[var(--color-lavender)]/40",title:"First page","aria-label":"First page",children:"«"}),o.jsx("button",{type:"button",disabled:r<=1,onClick:()=>u(r-1),className:"px-2 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] disabled:opacity-40 disabled:cursor-not-allowed hover:bg-[var(--color-lavender)]/40",title:"Previous page","aria-label":"Previous page",children:"‹"}),x.map((g,b)=>g==="…"?o.jsx("span",{className:"px-1.5 text-[var(--color-muted)]",children:"…"},`gap-${b}`):o.jsx("button",{type:"button",onClick:()=>u(g),"aria-label":`Page ${g}`,"aria-current":g===r?"page":void 0,className:g===r?"px-2.5 py-0.5 rounded bg-[var(--color-purple)] text-white font-medium":"px-2.5 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] hover:bg-[var(--color-lavender)]/40",children:g},g)),o.jsx("button",{type:"button",disabled:r>=h,onClick:()=>u(r+1),className:"px-2 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] disabled:opacity-40 disabled:cursor-not-allowed hover:bg-[var(--color-lavender)]/40",title:"Next page","aria-label":"Next page",children:"›"}),o.jsx("button",{type:"button",disabled:r>=h,onClick:()=>u(h),className:"px-2 py-0.5 rounded border border-[var(--color-line-2)] text-[var(--color-ink)] disabled:opacity-40 disabled:cursor-not-allowed hover:bg-[var(--color-lavender)]/40",title:"Last page","aria-label":"Last page",children:"»"}),o.jsx("span",{className:"ml-2 text-[0.78rem] text-[var(--color-muted)]",children:"Go to"}),o.jsx("input",{type:"number",min:1,max:h,defaultValue:r,"aria-label":"Go to page",onKeyDown:g=>{if(g.key==="Enter"){const b=Math.max(1,Math.min(h,Number(g.target.value)||1));u(b)}},className:"w-14 bg-[var(--color-card)] border border-[var(--color-line-2)] rounded px-1.5 py-0.5 text-[0.85rem] text-[var(--color-ink)] text-center focus:outline-none focus:border-[var(--color-purple)]"}),o.jsx("span",{className:"text-[0.78rem] text-[var(--color-muted)]",children:"page"})]})]})]})}function uS(a,i){if(i<=7)return Array.from({length:i},(d,m)=>m+1);const r=[],u=d=>{r[r.length-1]!==d&&r.push(d)};u(1),a>4&&u("…");for(let d=Math.max(2,a-1);d<=Math.min(i-1,a+1);d++)u(d);return a<i-3&&u("…"),u(i),r}function cS(){var ge,M;const a=Wo(),i=sj(),[r,u]=j.useState("inferences"),[d,m]=j.useState(""),[h,x]=j.useState("all"),[p,v]=j.useState("all"),[g,b]=j.useState("all"),[E,C]=j.useState("all"),[A,z]=j.useState(1),[B,U]=j.useState(1),[G,K]=j.useState(25),[L,V]=j.useState(null),[P,J]=j.useState(null),ee=a.isLoading||i.isLoading,le=((ge=a.data)==null?void 0:ge.inferences)??[],oe=((M=i.data)==null?void 0:M.purchases)??[],F=d.trim().toLowerCase(),fe=j.useMemo(()=>vS(le,oe),[le,oe]),ye=j.useMemo(()=>xS(le),[le]),Ee=j.useMemo(()=>yS(oe),[oe]),me=j.useMemo(()=>le.filter(_=>h!=="all"&&_.status!==h||p!=="all"&&_.modelId!==p?!1:bS(_,F)).sort((_,Z)=>Z.createdAt.localeCompare(_.createdAt)),[le,p,h,F]),D=j.useMemo(()=>oe.filter(_=>g!=="all"&&_.status!==g||E!=="all"&&_.paymentMethod!==E?!1:gS(_,F)).sort((_,Z)=>Z.createdAt.localeCompare(_.createdAt)),[oe,E,g,F]),$=j.useMemo(()=>$v(me,A,G),[me,A,G]),re=j.useMemo(()=>$v(D,B,G),[D,B,G]),be=a.isError||i.isError;return j.useEffect(()=>{const _=Math.max(1,Math.ceil(me.length/G));A>_&&z(_)},[me.length,A,G]),j.useEffect(()=>{const _=Math.max(1,Math.ceil(D.length/G));B>_&&U(_)},[D.length,G,B]),o.jsxs("div",{className:"space-y-4",children:[o.jsxs("section",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[o.jsx(_o,{icon:o.jsx(X2,{className:"size-5"}),label:"Inference spend",value:st(fe.inferenceSpendMicros,{digits:4}),detail:`${Ke(fe.inferenceCount)} requests`,tone:"spend"}),o.jsx(_o,{icon:o.jsx(O2,{className:"size-5"}),label:"Token usage",value:pl(fe.inputTokens+fe.outputTokens),detail:$r(fe.inputTokens,fe.outputTokens),tone:"tokens"}),o.jsx(_o,{icon:o.jsx(Gr,{className:"size-5"}),label:"Purchase credit",value:st(fe.purchaseCreditMicros,{digits:4}),detail:`${Ke(fe.settledPurchases)} settled`,tone:"credit"}),o.jsx(_o,{icon:o.jsx(w2,{className:"size-5"}),label:"Average response",value:xt(fe.averageDurationMs),detail:"Completed inference time",tone:"latency"})]}),o.jsxs(jt,{className:"overflow-hidden p-0",children:[o.jsxs("div",{className:"border-b border-[var(--color-line-2)] bg-white px-4 py-3",children:[o.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[o.jsx("div",{children:o.jsx("h1",{className:"text-[1.05rem] font-semibold text-[var(--color-ink)]",children:"Usage details"})}),o.jsxs("div",{className:"grid grid-cols-2 overflow-hidden rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-1",children:[o.jsx(Zv,{label:"Inferences",active:r==="inferences",count:me.length,onClick:()=>u("inferences"),children:"Inferences"}),o.jsx(Zv,{label:"Purchases",active:r==="purchases",count:D.length,onClick:()=>u("purchases"),children:"Purchases"})]})]}),o.jsxs("div",{className:"mt-3 grid gap-2 lg:grid-cols-[minmax(220px,1fr)_160px_200px]",children:[o.jsxs("label",{className:"relative block",children:[o.jsx(Fo,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-[var(--color-muted)]"}),o.jsx("input",{className:"h-9 w-full rounded-[8px] border border-[var(--color-line-2)] bg-white pl-9 pr-3 text-[0.86rem] text-[var(--color-ink)] outline-none transition placeholder:text-[var(--color-muted)] focus:border-[var(--color-purple)]",value:d,placeholder:r==="inferences"?"Search request, model, seller...":"Search purchase, method, seller...",onChange:_=>{m(_.target.value),z(1),U(1)}})]}),r==="inferences"?o.jsxs(o.Fragment,{children:[o.jsx(Do,{label:"Status",value:h,options:ye.statuses,onChange:_=>{x(_),z(1)}}),o.jsx(Do,{label:"Model",value:p,options:ye.models,onChange:_=>{v(_),z(1)}})]}):o.jsxs(o.Fragment,{children:[o.jsx(Do,{label:"Status",value:g,options:Ee.statuses,onChange:_=>{b(_),U(1)}}),o.jsx(Do,{label:"Method",value:E,options:Ee.methods,onChange:_=>{C(_),U(1)}})]})]})]}),be?o.jsx("div",{className:"border-b border-rose-100 bg-rose-50 px-4 py-3 text-[0.86rem] text-rose-700",children:"Ledger data could not be loaded. The local daemon may be offline or missing ledger endpoints."}):null,ee?o.jsx(pS,{}):r==="inferences"?o.jsx(dS,{entries:$,total:me.length,page:A,pageSize:G,openId:L,onToggle:_=>V(L===_?null:_),onPageChange:z,onPageSizeChange:_=>{K(_),z(1),U(1)}}):o.jsx(fS,{entries:re,total:D.length,page:B,pageSize:G,openId:P,onToggle:_=>J(P===_?null:_),onPageChange:U,onPageSizeChange:_=>{K(_),z(1),U(1)}})]})]})}function _o({icon:a,label:i,value:r,detail:u,tone:d}){const m={spend:{card:"border-[#cceee6] bg-[#e8fbf7]",icon:"bg-white text-[#0f766e]",label:"text-[#0f766e]",value:"text-[#201a38]",accent:"bg-[#0f766e]"},tokens:{card:"border-[#d9e7ff] bg-[#eaf2ff]",icon:"bg-white text-[#2563eb]",label:"text-[#2563eb]",value:"text-[#201a38]",accent:"bg-[#2563eb]"},credit:{card:"border-[#dff8ec] bg-[#e8fff6]",icon:"bg-white text-emerald-700",label:"text-emerald-700",value:"text-[#201a38]",accent:"bg-emerald-500"},latency:{card:"border-[#f8d5de] bg-[#fff0f3]",icon:"bg-white text-[#ef5b78]",label:"text-[#ef5b78]",value:"text-[#201a38]",accent:"bg-[#ef5b78]"}}[d];return o.jsxs(jt,{className:["relative flex min-h-[7rem] items-center gap-4 overflow-hidden px-4 py-4",m.card].join(" "),children:[o.jsx("div",{className:["absolute inset-y-0 left-0 w-1",m.accent].join(" ")}),o.jsx("div",{className:["grid size-11 shrink-0 place-items-center rounded-[10px] shadow-sm",m.icon].join(" "),children:a}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:["text-[0.72rem] font-bold uppercase tracking-[0.08em]",m.label].join(" "),children:i}),o.jsx("div",{className:["mt-1 truncate font-mono text-[1.55rem] font-bold leading-none tracking-normal",m.value].join(" "),children:r}),o.jsx("div",{className:"mt-2 truncate text-[0.76rem] font-medium text-[var(--color-muted)]",children:u})]})]})}function Zv({label:a,active:i,count:r,onClick:u,children:d}){return o.jsxs("button",{type:"button",onClick:u,"aria-label":`${a} ledger records, ${Ke(r)} records`,className:["inline-flex h-8 items-center justify-center gap-2 rounded-[8px] px-3 text-[0.82rem] font-semibold transition",i?"bg-white text-[var(--color-ink)] shadow-sm":"text-[var(--color-muted)] hover:text-[var(--color-ink)]"].join(" "),children:[o.jsx("span",{children:d}),o.jsx("span",{className:"font-mono text-[0.76rem]",children:Ke(r)})]})}function Do({label:a,value:i,options:r,onChange:u}){return o.jsxs("label",{className:"grid gap-1",children:[o.jsx("span",{className:"sr-only",children:a}),o.jsxs("select",{"aria-label":a,className:"h-9 rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.86rem] text-[var(--color-ink)] outline-none transition focus:border-[var(--color-purple)]",value:i,onChange:d=>u(d.target.value),children:[o.jsxs("option",{value:"all",children:["All ",a.toLowerCase()]}),r.map(d=>o.jsx("option",{value:d,children:d},d))]})]})}function dS({entries:a,total:i,page:r,pageSize:u,openId:d,onToggle:m,onPageChange:h,onPageSizeChange:x}){return i===0?o.jsx(g0,{label:"inference records"}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"divide-y divide-[var(--color-line-2)] bg-white xl:hidden",children:a.map(p=>o.jsx(mS,{entry:p,open:d===p.requestId,onToggle:()=>m(p.requestId)},p.requestId))}),o.jsx("div",{className:"hidden min-w-0 max-w-full overflow-x-auto xl:block",children:o.jsxs("table",{className:"w-full min-w-[1080px] text-[0.86rem]",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"bg-[var(--color-page)]/70 text-left text-[0.7rem] font-semibold uppercase tracking-[0.08em] text-[var(--color-muted)]",children:[o.jsx("th",{className:"px-4 py-2.5",children:"TIME"}),o.jsx("th",{className:"px-4 py-2.5",children:"REQ"}),o.jsx("th",{className:"px-4 py-2.5",children:"MODEL"}),o.jsx("th",{className:"px-4 py-2.5",children:"SELLER"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"TOKEN"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"COST"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"TTFT"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"TOTAL"}),o.jsx("th",{className:"px-4 py-2.5",children:"STATUS"})]})}),a.map(p=>o.jsxs("tbody",{children:[o.jsxs("tr",{onClick:()=>m(p.requestId),className:"cursor-pointer border-t border-[var(--color-line-2)] transition hover:bg-[var(--color-lavender)]/25",children:[o.jsx("td",{className:"whitespace-nowrap px-4 py-3 font-mono text-[0.76rem] text-[var(--color-muted)]",children:r0(p.createdAt)}),o.jsx("td",{className:"px-4 py-3",children:o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(Io,{tone:"purple",children:o.jsx(Zx,{className:"size-4"})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"max-w-[180px] truncate font-mono text-[0.78rem] font-semibold text-[var(--color-ink)]",children:p.requestId}),o.jsx("div",{className:"mt-0.5 max-w-[180px] truncate text-[0.72rem] text-[var(--color-muted)]",children:p.endpoint})]})]})}),o.jsx("td",{className:"max-w-[190px] truncate px-4 py-3 text-[var(--color-ink)]",children:p.modelId}),o.jsx("td",{className:"px-4 py-3 font-mono text-[0.78rem] text-[var(--color-text)]",children:p.sellerKey}),o.jsxs("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem]",children:[o.jsx("div",{children:Ke(p.promptTokens)}),o.jsx("div",{className:"text-[0.72rem] text-[var(--color-muted)]",children:Ke(p.completionTokens)})]}),o.jsx("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem] font-semibold text-[var(--color-ink)]",children:st(p.billedMicros,{ledger:!0})}),o.jsx("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem] text-[var(--color-muted)]",children:xt(p.ttftMs)}),o.jsx("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem] text-[var(--color-muted)]",children:xt(p.durationMs)}),o.jsx("td",{className:"px-4 py-3",children:o.jsx(rs,{tone:Ka(p.status),children:Rl(p.status)})})]}),d===p.requestId?o.jsx("tr",{children:o.jsx("td",{colSpan:9,className:"border-t border-[var(--color-line-2)] bg-[var(--color-page)]/70 px-5 py-4",children:o.jsx(x0,{entry:p})})}):null]},p.requestId))]})}),o.jsx(v0,{totalItems:i,pageSize:u,page:r,onPageChange:h,onPageSizeChange:x})]})}function fS({entries:a,total:i,page:r,pageSize:u,openId:d,onToggle:m,onPageChange:h,onPageSizeChange:x}){return i===0?o.jsx(g0,{label:"purchase records"}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"divide-y divide-[var(--color-line-2)] bg-white xl:hidden",children:a.map(p=>o.jsx(hS,{entry:p,open:d===p.purchaseId,onToggle:()=>m(p.purchaseId)},p.purchaseId))}),o.jsx("div",{className:"hidden min-w-0 max-w-full overflow-x-auto xl:block",children:o.jsxs("table",{className:"w-full min-w-[980px] text-[0.86rem]",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"bg-[var(--color-page)]/70 text-left text-[0.7rem] font-semibold uppercase tracking-[0.08em] text-[var(--color-muted)]",children:[o.jsx("th",{className:"px-4 py-2.5",children:"When"}),o.jsx("th",{className:"px-4 py-2.5",children:"Purchase"}),o.jsx("th",{className:"px-4 py-2.5",children:"Payment method"}),o.jsx("th",{className:"px-4 py-2.5",children:"Model"}),o.jsx("th",{className:"px-4 py-2.5",children:"Seller"}),o.jsx("th",{className:"px-4 py-2.5 text-right",children:"Credit"}),o.jsx("th",{className:"px-4 py-2.5",children:"Status"})]})}),a.map(p=>o.jsxs("tbody",{children:[o.jsxs("tr",{onClick:()=>m(p.purchaseId),className:"cursor-pointer border-t border-[var(--color-line-2)] transition hover:bg-[var(--color-lavender)]/25",children:[o.jsx("td",{className:"whitespace-nowrap px-4 py-3 font-mono text-[0.76rem] text-[var(--color-muted)]",children:r0(p.createdAt)}),o.jsx("td",{className:"px-4 py-3",children:o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(Io,{tone:"green",children:o.jsx(Bi,{className:"size-4"})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"max-w-[210px] truncate font-mono text-[0.78rem] font-semibold text-[var(--color-ink)]",children:p.purchaseId}),o.jsx("div",{className:"mt-0.5 max-w-[210px] truncate text-[0.72rem] text-[var(--color-muted)]",children:Jr(p.paymentReferenceHash)})]})]})}),o.jsx("td",{className:"px-4 py-3 text-[var(--color-ink)]",children:p.paymentMethod}),o.jsx("td",{className:"max-w-[180px] truncate px-4 py-3 text-[var(--color-ink)]",children:p.modelId}),o.jsx("td",{className:"px-4 py-3 font-mono text-[0.78rem] text-[var(--color-text)]",children:p.sellerKey}),o.jsx("td",{className:"px-4 py-3 text-right font-mono text-[0.82rem] font-semibold text-emerald-700",children:st(p.creditMicros,{digits:4,signed:!0})}),o.jsx("td",{className:"px-4 py-3",children:o.jsx(rs,{tone:Ka(p.status),children:Rl(p.status)})})]}),d===p.purchaseId?o.jsx("tr",{children:o.jsx("td",{colSpan:7,className:"border-t border-[var(--color-line-2)] bg-[var(--color-page)]/70 px-5 py-4",children:o.jsx(y0,{entry:p})})}):null]},p.purchaseId))]})}),o.jsx(v0,{totalItems:i,pageSize:u,page:r,onPageChange:h,onPageSizeChange:x})]})}function mS({entry:a,open:i,onToggle:r}){return o.jsxs("article",{className:"px-4 py-3",children:[o.jsx("button",{type:"button",onClick:r,"aria-expanded":i,"aria-label":`Inference ${a.requestId}`,className:"block w-full text-left",children:o.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[o.jsx(Io,{tone:"purple",children:o.jsx(Zx,{className:"size-4"})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",title:a.requestId,children:a.requestId}),o.jsx("div",{className:"mt-0.5 truncate text-[0.72rem] text-[var(--color-muted)]",title:a.endpoint,children:a.endpoint})]}),o.jsx(rs,{tone:Ka(a.status),children:Rl(a.status)})]}),o.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4",children:[o.jsx(gt,{label:"Time",value:vl(a.createdAt),compact:!0}),o.jsx(gt,{label:"Model",value:a.modelId}),o.jsx(gt,{label:"Seller",value:a.sellerKey}),o.jsx(gt,{label:"Cost",value:st(a.billedMicros,{ledger:!0}),tone:"strong"}),o.jsx(gt,{label:"In",value:Ke(a.promptTokens)}),o.jsx(gt,{label:"Out",value:Ke(a.completionTokens)}),o.jsx(gt,{label:"TTFT",value:xt(a.ttftMs)}),o.jsx(gt,{label:"Total",value:xt(a.durationMs)}),o.jsx(gt,{label:"Route",value:a.routeReason??Te})]})]})]})}),i?o.jsx("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3",children:o.jsx(x0,{entry:a})}):null]})}function hS({entry:a,open:i,onToggle:r}){return o.jsxs("article",{className:"px-4 py-3",children:[o.jsx("button",{type:"button",onClick:r,"aria-expanded":i,"aria-label":`Purchase ${a.purchaseId}`,className:"block w-full text-left",children:o.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[o.jsx(Io,{tone:"green",children:o.jsx(Bi,{className:"size-4"})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate font-mono text-[0.84rem] font-semibold text-[var(--color-ink)]",title:a.purchaseId,children:a.purchaseId}),o.jsx("div",{className:"mt-0.5 truncate text-[0.72rem] text-[var(--color-muted)]",title:a.paymentReferenceHash??void 0,children:Jr(a.paymentReferenceHash)})]}),o.jsx(rs,{tone:Ka(a.status),children:Rl(a.status)})]}),o.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4",children:[o.jsx(gt,{label:"Time",value:vl(a.createdAt),compact:!0}),o.jsx(gt,{label:"Method",value:a.paymentMethod}),o.jsx(gt,{label:"Model",value:a.modelId}),o.jsx(gt,{label:"Seller",value:a.sellerKey}),o.jsx(gt,{label:"Credit",value:st(a.creditMicros,{digits:4,signed:!0}),tone:"green"}),o.jsx(gt,{label:"Currency",value:a.currency}),o.jsx(gt,{label:"Completed",value:vl(a.completedAt),compact:!0})]})]})]})}),i?o.jsx("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3",children:o.jsx(y0,{entry:a})}):null]})}function gt({label:a,value:i,tone:r="default",compact:u=!1}){return o.jsxs("div",{className:"min-w-0 rounded-[9px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-2.5 py-2",children:[o.jsx("div",{className:"text-[0.62rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:a}),o.jsx("div",{className:["mt-1 truncate font-mono font-semibold",u?"text-[0.7rem]":"text-[0.84rem]",r==="green"?"text-emerald-700":r==="strong"?"text-[var(--color-ink)]":"text-[var(--color-text)]"].join(" "),title:i,children:i})]})}function Io({tone:a,children:i}){return o.jsx("div",{className:["grid size-9 shrink-0 place-items-center rounded-lg border",a==="purple"?"border-[var(--color-lavender-2)] bg-[var(--color-lavender)] text-[var(--color-purple)]":"border-emerald-100 bg-emerald-50 text-emerald-700"].join(" "),children:i})}function x0({entry:a}){return o.jsx(b0,{rows:[["Request ID",a.requestId],["Created",vl(a.createdAt)],["Endpoint",a.endpoint],["Payment method",a.paymentMethod??Te],["Route",`${a.routeReason??Te} -> ${a.sellerKey}`],["Fallback chain",a.falloverChain&&a.falloverChain.length>0?a.falloverChain.join(" -> "):Te],["Upstream status",Rl(a.upstreamStatus)],["TTFT / total",`${xt(a.ttftMs)} / ${xt(a.durationMs)}`],["Input / output tokens",dj(a.promptTokens,a.completionTokens)],["Billed",st(a.billedMicros,{ledger:!0})],["Balance after",st(a.balanceSnapshotMicros,{digits:4})],["Prompt hash",Jr(a.promptHash)],["Response hash",Jr(a.responseHash)],["Price version",a.priceVersion??Te]]})}function y0({entry:a}){return o.jsx(b0,{rows:[["Purchase ID",a.purchaseId],["Created",vl(a.createdAt)],["Completed",vl(a.completedAt)],["Payment method",a.paymentMethod],["Payment reference",Jr(a.paymentReferenceHash)],["Credit",st(a.creditMicros,{digits:4})],["Credit micros",Ke(a.creditMicros)],["Currency",a.currency],["Seller",a.sellerKey],["Model",a.modelId]]})}function b0({rows:a}){return o.jsx("div",{className:"grid gap-x-4 gap-y-2 text-[0.84rem] sm:grid-cols-[150px_minmax(0,1fr)]",children:a.map(([i,r])=>o.jsxs("div",{className:"contents",children:[o.jsx("div",{className:"text-[var(--color-muted)]",children:i}),o.jsx("div",{className:"min-w-0 break-all font-mono text-[0.8rem] text-[var(--color-ink)]",children:r})]},i))})}function pS(){return o.jsx("div",{className:"space-y-2 px-4 py-4",children:Array.from({length:7},(a,i)=>o.jsx("div",{className:"h-12 rounded-lg bg-[var(--color-lavender)]/35"},i))})}function g0({label:a}){return o.jsxs("div",{className:"flex min-h-[220px] flex-col items-center justify-center px-6 py-10 text-center",children:[o.jsx("div",{className:"grid size-12 place-items-center rounded-xl border border-[var(--color-line-2)] bg-[var(--color-page)] text-[var(--color-purple)]",children:o.jsx(Fo,{className:"size-5"})}),o.jsxs("div",{className:"mt-4 font-semibold text-[var(--color-ink)]",children:["No matching ",a]}),o.jsx("div",{className:"mt-1 max-w-[360px] text-[0.86rem] text-[var(--color-muted)]",children:"Adjust the query or filters to inspect another slice of the local ledger."})]})}function vS(a,i){const r=a.reduce((p,v)=>p+(v.billedMicros??0),0),u=i.reduce((p,v)=>p+v.creditMicros,0),d=a.reduce((p,v)=>p+(v.promptTokens??0),0),m=a.reduce((p,v)=>p+(v.completionTokens??0),0),h=a.map(p=>p.durationMs).filter(p=>p!==void 0),x=h.length===0?void 0:h.reduce((p,v)=>p+v,0)/h.length;return{inferenceCount:a.length,inferenceSpendMicros:r,purchaseCreditMicros:u,inputTokens:d,outputTokens:m,settledPurchases:i.filter(p=>jS(p.status)).length,averageDurationMs:x}}function xS(a){return{statuses:Xo(a.map(i=>i.status)),models:Xo(a.map(i=>i.modelId))}}function yS(a){return{statuses:Xo(a.map(i=>i.status)),methods:Xo(a.map(i=>i.paymentMethod))}}function Xo(a){return Array.from(new Set(a.filter(Boolean))).sort((i,r)=>i.localeCompare(r))}function bS(a,i){return i?[a.requestId,a.sellerKey,a.modelId,a.endpoint,a.status,a.paymentMethod,a.routeReason,a.upstreamStatus].some(r=>r==null?void 0:r.toLowerCase().includes(i)):!0}function gS(a,i){return i?[a.purchaseId,a.sellerKey,a.modelId,a.paymentMethod,a.status,a.currency,a.paymentReferenceHash].some(r=>r==null?void 0:r.toLowerCase().includes(i)):!0}function $v(a,i,r){const u=(i-1)*r;return a.slice(u,u+r)}function jS(a){return a==="settled"||a==="active"||a==="completed"||a==="success"}function SS(){return xl({queryKey:["init","state"],queryFn:()=>yl("/init/state"),refetchInterval:1e4})}async function NS(a){return Xa("POST","/init/complete",void 0)}function MS(){return Qi({mutationFn:()=>Xa("POST","/init/doctor/run")})}function wS(){return xl({queryKey:["providers","status"],queryFn:()=>yl("/providers/status"),refetchInterval:1e4})}function CS(){return Qi({mutationFn:a=>Xa("POST","/providers/install/preview",a)})}function TS(){const a=is();return Qi({mutationFn:i=>Xa("POST","/providers/install/apply",i),onSuccess:()=>{a.invalidateQueries({queryKey:["providers","status"]}),a.invalidateQueries({queryKey:["init","state"]})}})}const ES=[{value:"fullAuto",title:"全自动",body:"自动选择可用供应商。"},{value:"fixedSet",title:"固定供应商组",body:"在指定供应商组内切换。"},{value:"fixed",title:"固定供应商",body:"始终使用指定供应商。"}],AS=[{value:"balanced",title:"平衡模式",body:"综合速度、价格、健康度、余额。"},{value:"speed",title:"速度优先",body:"优先选择更快、吞吐量更高供应商。"},{value:"discount",title:"成本优先",body:"优先选择更低成本供应商。"}],Jv=[{index:1,label:"选择模型",value:"默认模型"},{index:2,label:"绑定钱包",value:"支付方式"},{index:3,label:"配置策略",value:"路由规则"},{index:4,label:"配置工具",value:"终端接入"}],zS=[{method:"wechat-pay",name:"WeChat Pay",detail:"微信支付入口预留"},{method:"alipay-agent",name:"Alipay Agent Payment",detail:"代理支付入口预留"},{method:"coinbase-smart-wallet",name:"Coinbase Smart Wallet",detail:"USDC 钱包入口预留"}],RS=["GPT","Claude","Gemini","DeepSeek","Kimi","Qwen","MiniMax","GLM","Doubao","Grok"];function OS(a){const i=new URLSearchParams(a);return i.has("verifyPaymentMethods")?2:(i.has("verifyPickerDom")||i.has("verifyNoIntro")||i.has("verifyCompact"),1)}function _S(){var fs,ms,hs,$a,Ja,Fa,Sl,Wa,oa,ps,Gi,Rn;const[a,i]=j.useState(()=>OS(typeof window>"u"?"":window.location.search)),[r,u]=j.useState([]),[d,m]=j.useState(!1),[h,x]=j.useState(),[p,v]=j.useState(!1),[g,b]=j.useState(!1),[E,C]=j.useState("fullAuto"),[A,z]=j.useState("balanced"),[B,U]=j.useState(""),[G,K]=j.useState([]),[L,V]=j.useState(),[P,J]=j.useState(""),[ee,le]=j.useState([]),[oe,F]=j.useState({}),[fe,ye]=j.useState(),[Ee,me]=j.useState(),[D,$]=j.useState(!1),[re,be]=j.useState(null),[ge,M]=j.useState(!1),[_,Z]=j.useState(),I=SS(),X=l0(),ae=e0(),W=Fx(),Ae=wS(),Oe=Wx(),bl=Px(),ia=CS(),Tn=TS(),At=MS(),ft=xf(),En=Wo(),ra=j.useMemo(()=>{var ie;return BS(((ie=ft.data)==null?void 0:ie.data)??[])},[(fs=ft.data)==null?void 0:fs.data]),tu=j.useMemo(()=>{var ie,Qe,Lt;return IS(((ie=ft.data)==null?void 0:ie.sellers)??[],((Qe=ft.data)==null?void 0:Qe.data)??[],((Lt=En.data)==null?void 0:Lt.inferences)??[])},[(ms=En.data)==null?void 0:ms.inferences,(hs=ft.data)==null?void 0:hs.data,($a=ft.data)==null?void 0:$a.sellers]),An=j.useMemo(()=>{var ie;return HS(ra,r,((ie=I.data)==null?void 0:ie.recommendedModels)??[])},[(Ja=I.data)==null?void 0:Ja.recommendedModels,ra,r]),gl=j.useMemo(()=>r.length>0?r:An.map(ie=>ie.id),[An,r]),Va=`http://127.0.0.1:${((Fa=X.data)==null?void 0:Fa.proxyPort)??((Sl=I.data)==null?void 0:Sl.runtime.proxyPort)??17821}`,sa=j.useMemo(()=>{var ie;return(((ie=Ae.data)==null?void 0:ie.clients)??[]).filter(Qe=>Qe.id!=="custom"&&Qe.detected)},[(Wa=Ae.data)==null?void 0:Wa.clients]),ss=((oa=W.data)==null?void 0:oa.payments.filter(ie=>ie.enabled&&eu(ie.method)!=="mock"))??[],os=j.useMemo(()=>iN(E,A,B,G),[B,G,E,A]),St=rN({serviceReady:((ps=X.data)==null?void 0:ps.status)==="running",modelCount:ra.length,routingMode:E,paymentReady:ss.length>0,configuredTools:((Gi=Ae.data)==null?void 0:Gi.summary.configuredCount)??0}),lu=((Rn=At.data)==null?void 0:Rn.checks.map(sN))??St;j.useEffect(()=>{p||!I.data||(u(I.data.focusSet),v(!0))},[I.data,p]),j.useEffect(()=>{P||r.length===0||J(r[0])},[P,r]),j.useEffect(()=>{g||sa.length===0||(le(sa.filter(ie=>!ie.configured).map(ie=>ie.id)),b(!0))},[g,sa]),j.useEffect(()=>{a!==5||At.data||At.error||At.isPending||At.mutate()},[a,At]),j.useEffect(()=>{var Lt;const ie=ua=>{ua.preventDefault(),be(ua),Z("浏览器已经允许直接安装 TokenBuddy。")},Qe=()=>{M(!0),be(null),Z("TokenBuddy 桌面应用已安装。")};return window.addEventListener("beforeinstallprompt",ie),window.addEventListener("appinstalled",Qe),(Lt=window.matchMedia)!=null&&Lt.call(window,"(display-mode: standalone)").matches&&M(!0),()=>{window.removeEventListener("beforeinstallprompt",ie),window.removeEventListener("appinstalled",Qe)}},[]);const us=ie=>{x(void 0),u(Qe=>Qe.includes(ie)?Qe.filter(Lt=>Lt!==ie):[...Qe,ie])},cs=async()=>{m(!0),x(void 0);try{await Lo(r),x("关注模型已保存。后续工具配置会优先参考这些模型。")}catch(ie){x(`保存失败:${ie instanceof Error?ie.message:String(ie)}`)}finally{m(!1)}},zn=async()=>{if(V(void 0),!os){V(E==="fixed"?"请选择一个固定供应商。":"请至少选择一个供应商。");return}try{await ae.mutateAsync(os),V("供应商路由策略已保存。"),i(4)}catch(ie){V(`保存失败:${ie instanceof Error?ie.message:String(ie)}`)}},au=async()=>{try{await Oe.mutateAsync()}catch{}},ds=async()=>{try{await bl.mutateAsync()}catch{}},nu=async()=>{ye(void 0);const ie=P||gl[0];if(!ie){ye("请先选择一个默认模型。");return}if(ee.length===0){ye("请选择至少一个要安装的终端工具。");return}try{await ia.mutateAsync({providers:ee,proxyUrl:Va,model:ie,providerSelections:tx(ee,oe,gl,ie)}),ye("已生成安装预览。确认无误后可以写入配置。")}catch(Qe){ye(`预览失败:${Qe instanceof Error?Qe.message:String(Qe)}`)}},iu=async()=>{ye(void 0);const ie=P||gl[0];if(!ie){ye("请先选择一个默认模型。");return}if(ee.length===0){ye("请选择至少一个要安装的终端工具。");return}try{const Qe=await Tn.mutateAsync({providers:ee,proxyUrl:Va,model:ie,providerSelections:tx(ee,oe,gl,ie)});ye(`已写入 ${Qe.applied.length} 个配置文件。`),i(5)}catch(Qe){ye(`安装失败:${Qe instanceof Error?Qe.message:String(Qe)}`)}},Za=()=>{X.refetch(),I.refetch(),W.refetch(),Ae.refetch(),ft.refetch(),At.mutate()},Nt=async()=>{me(void 0),$(!0);try{await NS(),me("初始化已标记完成。你可以把 TokenBuddy 安装成桌面应用,之后从系统应用入口打开。"),I.refetch()}catch(ie){me(`完成失败:${ie instanceof Error?ie.message:String(ie)}`)}finally{$(!1)}},jl=async()=>{if(!re){Z("请在浏览器地址栏右侧或菜单里选择“安装应用”。");return}try{Z(void 0),await re.prompt();const ie=await re.userChoice;if(be(null),ie.outcome==="accepted"){M(!0),Z("TokenBuddy 桌面应用已安装。");return}Z("你可以稍后继续使用浏览器安装入口。")}catch(ie){Z(`安装未完成:${ie instanceof Error?ie.message:String(ie)}`)}},Mt=(()=>{var ie,Qe,Lt,ua,Ki,On,_n,Xi,Vi;return a<=1?o.jsx(kS,{commonModels:An,allModels:ra,loading:ft.isLoading,error:ft.error,selectedModels:r,saving:d,saveMessage:h,onToggleModel:us,onSave:cs,onContinue:()=>i(2)}):a===2?o.jsx(ZS,{payments:((ie=W.data)==null?void 0:ie.payments)??[],enabledPaymentCount:ss.length,loading:W.isLoading,qrUrl:(Qe=Oe.data)==null?void 0:Qe.qrImageUrl,rechargeQrUrl:(Lt=bl.data)==null?void 0:Lt.qrImageUrl,walletConfigPresent:(ua=Oe.data)==null?void 0:ua.walletConfigPresent,error:Oe.error,rechargeError:bl.error,binding:Oe.isPending,rechargeLoading:bl.isPending,onBind:au,onLoadRecharge:ds,onRefreshPayments:()=>{W.refetch()},onBack:()=>i(1),onContinue:()=>i(3)}):a===3?o.jsx(XS,{mode:E,scorer:A,sellers:tu,fixedSellerId:B,fixedSetSellerIds:G,saving:ae.isPending,message:L,onModeChange:C,onScorerChange:z,onFixedSellerChange:U,onToggleFixedSetSeller:ot=>{K(Ye=>Ye.includes(ot)?Ye.filter(et=>et!==ot):[...Ye,ot])},onSave:zn,onBack:()=>i(2)}):a===4?o.jsx(JS,{clients:((Ki=Ae.data)==null?void 0:Ki.clients)??[],candidates:sa,loading:Ae.isLoading,selectedProviders:ee,selectedModel:P||gl[0]||"",modelOptions:gl,providerSelections:oe,proxyUrl:Va,previewChanges:(On=ia.data)==null?void 0:On.changes,applying:Tn.isPending,previewing:ia.isPending,message:fe,onToggleProvider:ot=>{le(Ye=>Ye.includes(ot)?Ye.filter(et=>et!==ot):[...Ye,ot])},onModelChange:J,onProviderSelectionChange:(ot,Ye)=>{F(et=>({...et,[ot]:Ye}))},onPreview:nu,onInstall:iu,onBack:()=>i(3)}):a===5?o.jsx(WS,{items:lu,status:(_n=At.data)==null?void 0:_n.status,generatedAt:(Xi=At.data)==null?void 0:Xi.generatedAt,running:At.isPending,error:At.error,onRefresh:Za,onBack:()=>i(4),onContinue:()=>i(6)}):o.jsx(PS,{complete:((Vi=I.data)==null?void 0:Vi.setup.status)==="completed",message:Ee,installMessage:_,canInstall:!!re,installed:ge,saving:D,onBack:()=>i(5),onComplete:Nt,onInstall:jl})})();return o.jsxs("div",{className:"min-w-0 space-y-3",children:[o.jsx(DS,{activeStep:a,onSelect:i}),o.jsx("div",{className:"min-w-0",children:Mt})]})}function DS({activeStep:a,onSelect:i}){return o.jsx("nav",{"aria-label":"初始化步骤",className:"rounded-[12px] border border-[var(--color-line-2)] bg-white p-2.5 shadow-[0_8px_22px_rgba(60,41,112,0.045)]",children:o.jsx("div",{className:"flex items-stretch gap-2 overflow-x-auto",children:Jv.map(r=>{const u=a===r.index,d=a>r.index;return o.jsxs(j.Fragment,{children:[o.jsxs("button",{type:"button",onClick:()=>i(r.index),"aria-current":u?"step":void 0,className:["relative flex min-w-[190px] flex-1 items-center gap-2 rounded-[8px] px-3 py-2 text-left transition",u?"bg-[var(--color-lavender)] ring-1 ring-[var(--color-lavender-2)]":"hover:bg-[var(--color-page)]"].join(" "),children:[o.jsx("span",{className:["grid size-6 shrink-0 place-items-center rounded-full border bg-white",u?"border-[var(--color-purple)] text-[var(--color-purple)] shadow-[0_0_0_3px_rgba(124,61,240,0.1)]":"",d?"border-emerald-200 bg-emerald-50 text-emerald-700":"",!u&&!d?"border-[var(--color-line-2)] text-[var(--color-muted)]":""].join(" "),children:d?o.jsx(Jt,{className:"size-3.5"}):o.jsx("span",{className:"size-1.5 rounded-full bg-current"})}),o.jsxs("span",{className:"min-w-0",children:[o.jsxs("span",{className:["block font-mono text-[0.62rem] font-black uppercase tracking-[0.08em]",u?"text-[var(--color-purple)]":"text-[var(--color-muted)]"].join(" "),children:["STEP ",r.index,":"]}),o.jsx("span",{className:["mt-0.5 block text-[0.82rem] font-semibold",u?"text-[var(--color-purple)]":"text-[var(--color-ink)]"].join(" "),children:r.label}),o.jsx("span",{className:"block truncate text-[0.7rem] text-[var(--color-muted)]",children:r.value})]})]}),r.index<Jv.length?o.jsx("div",{className:"hidden min-w-8 items-center justify-center text-[var(--color-purple)]/70 sm:flex",children:o.jsx(Jo,{className:"size-5",strokeWidth:2.6})}):null]},r.index)})})})}function Yi({index:a,title:i,detail:r,meta:u,action:d}){return o.jsxs("div",{className:"flex flex-col gap-2.5 border-b border-[var(--color-line-2)] pb-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"min-w-0",children:o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("span",{className:"rounded-[7px] bg-[var(--color-lavender)] px-2 py-0.5 font-mono text-[0.68rem] font-semibold text-[var(--color-purple)]",children:String(a).padStart(2,"0")}),o.jsx("div",{className:"text-[0.92rem] font-semibold text-[var(--color-ink)]",children:i}),r?o.jsx("span",{className:"text-[0.74rem] text-[var(--color-muted)]",children:r}):null,u?o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5 font-mono text-[0.68rem] text-[var(--color-muted)]",children:u}):null]})}),d?o.jsx("div",{className:"shrink-0",children:d}):null]})}function kS({commonModels:a,allModels:i,loading:r,error:u,selectedModels:d,saving:m,saveMessage:h,onToggleModel:x,onSave:p,onContinue:v}){const[g,b]=j.useState(!1),E=d.map(C=>i.find(A=>A.id===C)??{id:C,sellerCount:0,protocols:[],paymentMethods:[]});return o.jsxs("div",{className:"space-y-3",children:[o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:1,title:"模型访问",detail:"默认和高频模型",meta:`${d.length} selected`,action:o.jsxs("button",{type:"button",disabled:r||!!u,onClick:()=>b(!0),className:"inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-purple)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple-2)] disabled:cursor-not-allowed disabled:opacity-45",children:[o.jsx(Jd,{className:"size-3.5"}),"添加模型"]})}),u?o.jsxs("div",{className:"mt-3 rounded-[10px] bg-rose-50 px-3 py-2 text-[0.84rem] leading-6 text-rose-700",children:["模型目录加载失败:",u instanceof Error?u.message:String(u)]}):null,E.length===0?o.jsxs("button",{type:"button",disabled:r||!!u,onClick:()=>b(!0),className:"mt-3 flex min-h-[72px] w-full items-center gap-3 rounded-[10px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3 text-left transition hover:border-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[o.jsx("span",{className:"grid size-8 shrink-0 place-items-center rounded-[8px] bg-white text-[var(--color-purple)]",children:o.jsx(Jd,{className:"size-4"})}),o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block text-[0.86rem] font-semibold text-[var(--color-ink)]",children:"添加可能使用到的模型"}),o.jsx("span",{className:"mt-0.5 block text-[0.76rem] text-[var(--color-muted)]",children:"至少选择一个模型后才能保存并继续。"})]})]}):o.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:E.map(C=>o.jsxs("div",{className:"inline-flex min-h-9 max-w-full items-center gap-2 rounded-[9px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-3 py-1.5",children:[o.jsx("span",{className:"truncate font-mono text-[0.82rem] font-semibold text-[var(--color-purple)]",children:C.id}),o.jsx("span",{className:"rounded-full bg-white/70 px-2 py-0.5 text-[0.68rem] font-semibold text-emerald-700",children:"可用"}),o.jsx("button",{type:"button",onClick:()=>x(C.id),className:"inline-flex size-5 items-center justify-center rounded-[6px] text-[var(--color-purple)]/70 hover:bg-white hover:text-[var(--color-purple)]","aria-label":`Remove ${C.id}`,children:o.jsx(Zr,{className:"size-3"})})]},C.id))}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2.5 border-t border-[var(--color-line-2)] pt-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsxs("div",{className:"min-h-5 text-[0.8rem] leading-5 text-[var(--color-muted)]",children:[r?o.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[o.jsx(Et,{className:"size-3.5 animate-spin text-[var(--color-purple)]"})," loading catalog"]}):null,!r&&!u&&d.length===0?o.jsx("span",{children:"请选择至少一个可能使用的模型。"}):null,h?o.jsx("div",{className:"mt-1 font-medium text-[var(--color-ink)]",children:h}):null]}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsxs("button",{type:"button",disabled:m||d.length===0,onClick:p,className:"inline-flex h-9 shrink-0 items-center justify-center gap-2 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[m?o.jsx(Et,{className:"size-3.5 animate-spin"}):null,"保存"]}),o.jsxs("button",{type:"button",disabled:d.length===0,onClick:v,className:"inline-flex h-9 shrink-0 items-center justify-center gap-1.5 rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:["下一步",o.jsx(Jo,{className:"size-3.5"})]})]})]})]}),g?o.jsx(US,{models:a,allModels:i,selectedModelIds:d,onToggle:x,onClose:()=>b(!1)}):null]})}function US({models:a,allModels:i,selectedModelIds:r,onToggle:u,onClose:d}){const[m,h]=j.useState("common"),[x,p]=j.useState(""),v=x.trim(),g=m==="common"?a:v?QS(i,v):[],b=m==="common"?"没有可用的推荐模型。":"输入关键词搜索全部可用模型。",E=[{id:"common",label:"推荐模型",hint:"直接勾选"},{id:"all",label:"搜索添加",hint:"全部模型"}];return o.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[rgba(32,26,56,0.22)] px-3 py-6 backdrop-blur-sm",children:o.jsxs("div",{className:"flex max-h-full w-full max-w-[720px] flex-col overflow-hidden rounded-[14px] border border-[var(--color-line-2)] bg-white shadow-[0_24px_80px_rgba(32,26,56,0.22)]",children:[o.jsxs("div",{className:"flex items-start gap-3 border-b border-[var(--color-line-2)] px-4 py-3",children:[o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"text-[0.72rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"Select models"}),o.jsx("h2",{className:"mt-0.5 text-[1rem] font-semibold text-[var(--color-ink)]",children:"选择可能使用到的模型"}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:"推荐模型直接勾选;搜索添加用于查找平台全部模型。"})]}),o.jsxs("div",{className:"mt-0.5 rounded-full bg-[var(--color-lavender)] px-2.5 py-1 font-mono text-[0.72rem] font-semibold text-[var(--color-purple)]",children:[r.length," selected"]}),o.jsx("button",{type:"button",onClick:d,className:"inline-flex size-8 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] text-[var(--color-muted)] hover:text-[var(--color-ink)]","aria-label":"Close model picker",children:o.jsx(Zr,{className:"size-4"})})]}),o.jsxs("div",{className:"border-b border-[var(--color-line-2)] px-4 py-2.5",children:[o.jsx("div",{className:"mb-2 text-[0.72rem] font-semibold uppercase tracking-wider text-[var(--color-muted)]",children:"已选模型"}),r.length===0?o.jsx("div",{className:"rounded-[9px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 text-[0.78rem] text-[var(--color-muted)]",children:"还没有选择模型。"}):o.jsx("div",{className:"flex max-h-[92px] flex-wrap gap-1.5 overflow-y-auto pr-1",children:r.map(C=>o.jsxs("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-[8px] border border-[var(--color-lavender-2)] bg-[var(--color-lavender)] px-2 py-1",children:[o.jsx("span",{className:"max-w-[220px] truncate font-mono text-[0.72rem] font-semibold text-[var(--color-purple)]",children:C}),o.jsx("button",{type:"button",onClick:()=>u(C),className:"inline-flex size-4 items-center justify-center rounded-[5px] text-[var(--color-purple)]/70 hover:bg-white hover:text-[var(--color-purple)]","aria-label":`Remove ${C}`,children:o.jsx(Zr,{className:"size-3"})})]},C))})]}),o.jsxs("div",{className:"border-b border-[var(--color-line-2)] p-3",children:[o.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:E.map(C=>{const A=m===C.id;return o.jsxs("button",{type:"button",onClick:()=>h(C.id),className:["rounded-[9px] border px-3 py-2 text-left transition",A?"border-[var(--color-purple)] bg-[var(--color-lavender)]":"border-[var(--color-line-2)] bg-white hover:border-[var(--color-lavender-2)]"].join(" "),children:[o.jsx("span",{className:["block text-[0.84rem] font-semibold",A?"text-[var(--color-purple)]":"text-[var(--color-ink)]"].join(" "),children:C.label}),o.jsx("span",{className:"mt-0.5 block text-[0.72rem] text-[var(--color-muted)]",children:C.hint})]},C.id)})}),m==="all"?o.jsxs("label",{className:"relative mt-3 block",children:[o.jsx(Fo,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-[var(--color-muted)]"}),o.jsx("input",{value:x,onChange:C=>p(C.target.value),placeholder:"搜索平台全部模型...",className:"h-10 w-full rounded-[9px] border border-[var(--color-line-2)] bg-white pl-9 pr-3 text-[0.88rem] text-[var(--color-ink)] outline-none transition placeholder:text-[var(--color-muted)] focus:border-[var(--color-purple)]"})]}):null]}),o.jsx("div",{className:"min-h-0 max-h-[320px] overflow-y-auto p-3",children:g.length===0?o.jsx("div",{className:"rounded-[12px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-4 py-8 text-center text-[0.86rem] text-[var(--color-muted)]",children:b}):o.jsx("div",{className:"grid gap-2",children:g.map(C=>{const A=r.includes(C.id);return o.jsxs("button",{type:"button",onClick:()=>u(C.id),"aria-pressed":A,className:["flex items-center gap-3 rounded-[10px] border px-3 py-2 text-left transition",A?"border-[var(--color-purple)] bg-[var(--color-lavender)]":"border-[var(--color-line-2)] bg-white hover:border-[var(--color-lavender-2)]"].join(" "),children:[o.jsx("span",{className:["grid size-6 shrink-0 place-items-center rounded-[7px] border",A?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] bg-white text-transparent"].join(" "),children:o.jsx(Jt,{className:"size-3.5"})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block truncate font-mono text-[0.88rem] font-semibold text-[var(--color-ink)]",children:C.id}),o.jsxs("span",{className:"mt-1 flex flex-wrap gap-1.5 text-[0.72rem] text-[var(--color-muted)]",children:[o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:bf(C.id)}),o.jsx("span",{className:"rounded-full bg-emerald-50 px-2 py-0.5 font-semibold text-emerald-700",children:"可用"}),Pd(C.paymentMethods)?o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:Pd(C.paymentMethods)}):null]})]}),o.jsx("span",{className:["rounded-[7px] px-2 py-1 text-[0.72rem] font-semibold",A?"bg-[var(--color-purple)] text-white":"bg-[var(--color-page)] text-[var(--color-muted)]"].join(" "),children:A?"已选择":"选择"})]},C.id)})})}),o.jsxs("div",{className:"flex flex-col gap-2 border-t border-[var(--color-line-2)] bg-white px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsxs("div",{className:"text-[0.8rem] leading-5 text-[var(--color-muted)]",children:["已选择 ",o.jsx("span",{className:"font-mono font-semibold text-[var(--color-ink)]",children:r.length})," 个模型"]}),o.jsxs("button",{type:"button",onClick:d,"aria-label":"Done",title:"Done selecting models",className:"inline-flex h-9 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)]",children:["完成选择",o.jsx(Jt,{className:"size-3.5"})]})]})]})})}function BS(a){const i=new Map;for(const r of a){const u=i.get(r.id)??{sellers:new Set,protocols:new Set,paymentMethods:new Set};u.sellers.add(r.sellerId);for(const d of r.supportedProtocols)u.protocols.add(d);for(const d of r.paymentMethods)u.paymentMethods.add(d);i.set(r.id,u)}return Array.from(i.entries()).map(([r,u])=>({id:r,sellerCount:u.sellers.size,protocols:Array.from(u.protocols).sort(),paymentMethods:Array.from(u.paymentMethods).sort()})).sort((r,u)=>u.sellerCount!==r.sellerCount?u.sellerCount-r.sellerCount:r.id.localeCompare(u.id))}function HS(a,i,r){const u=LS(a,r);if(u.length>0)return u.slice(0,14);const d=new Set(i),m=new Map;for(const p of i){const v=a.find(g=>g.id===p);v&&m.set(v.id,v)}const h=a.map(p=>({model:p,rank:YS(p.id)})).filter(p=>p.rank<100).sort((p,v)=>p.rank!==v.rank?p.rank-v.rank:v.model.sellerCount!==p.model.sellerCount?v.model.sellerCount-p.model.sellerCount:p.model.id.localeCompare(v.model.id)),x=new Map;for(const p of h){const v=bf(p.model.id),g=x.get(v)??[];g.push(p),x.set(v,g)}for(const p of RS){const v=p==="GPT"?3:p==="Claude"||p==="Gemini"?2:1;for(const g of(x.get(p)??[]).slice(0,v))m.set(g.model.id,g.model)}for(const p of h){if(m.size>=14)break;d.has(p.model.id)||m.set(p.model.id,p.model)}return Array.from(m.values()).slice(0,14)}function LS(a,i){const r=new Map;for(const u of i){const d=qS(a,u,r);d&&r.set(d.id,d)}return Array.from(r.values())}function qS(a,i,r){const u=Ed(i);if(!u)return;const d=a.find(m=>Ed(m.id)===u&&!r.has(m.id));return d||a.find(m=>{if(r.has(m.id))return!1;const h=Ed(m.id);return h.includes(u)||u.includes(h)})}function Ed(a){return a.trim().toLowerCase().replace(/_/g,"-")}function QS(a,i){const r=i.trim().toLowerCase();return r?a.filter(u=>[u.id,bf(u.id),...u.paymentMethods].some(d=>d.toLowerCase().includes(r))):a}function YS(a){const i=a.toLowerCase();return i.includes("gpt-5.5")||i.includes("gpt-5-5")||i.includes("gpt-5_5")?0:i.includes("gpt-5.4")||i.includes("gpt-5-4")||i.includes("gpt-5_4")?1:i.includes("gpt-5")||i.includes("gpt-latest")||i.includes("openai/gpt")?2:i.includes("claude")&&(i.includes("4.8")||i.includes("4-8"))?3:i.includes("claude")&&i.includes("opus")?4:i.includes("claude")&&i.includes("sonnet")?5:i.includes("claude")?6:i.includes("gemini")&&(i.includes("3.1")||i.includes("3-1"))?7:i.includes("gemini")&&i.includes("pro")?8:i.includes("gemini")?9:i.includes("deepseek")?10:i.includes("kimi")||i.includes("moonshot")?11:i.includes("qwen")||i.includes("tongyi")?12:i.includes("minimax")?13:i.includes("glm")||i.includes("zhipu")?14:i.includes("doubao")||i.includes("bytedance")?15:i.includes("grok")?16:100}function bf(a){const i=a.toLowerCase();return i.includes("gpt")||i.includes("openai")?"GPT":i.includes("claude")||i.includes("anthropic")?"Claude":i.includes("gemini")||i.includes("google")?"Gemini":i.includes("deepseek")?"DeepSeek":i.includes("kimi")||i.includes("moonshot")?"Kimi":i.includes("qwen")||i.includes("tongyi")?"Qwen":i.includes("minimax")?"MiniMax":i.includes("glm")||i.includes("zhipu")?"GLM":i.includes("doubao")||i.includes("bytedance")?"Doubao":i.includes("grok")?"Grok":"Common"}function Pd(a){return a.length===0?"":`${GS(a.map(KS)).join("、")}`}function GS(a){return Array.from(new Set(a))}function KS(a){const i=eu(a);return i.includes("x402")?"X402":i.includes("clawtip")?"ClawTip":i.includes("wallet")?"钱包":i.includes("mock")||i.includes("test")?"测试":"其它"}function eu(a){return a.trim().toLowerCase()}function XS({mode:a,scorer:i,sellers:r,fixedSellerId:u,fixedSetSellerIds:d,saving:m,message:h,onModeChange:x,onScorerChange:p,onFixedSellerChange:v,onToggleFixedSetSeller:g,onSave:b,onBack:E}){const C=a!=="fullAuto";return o.jsxs("div",{className:"space-y-3",children:[o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:3,title:"配置策略",detail:"路由规则",meta:`${T0(a)} / ${fN(i)}`}),o.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-2",children:[o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-2.5",children:[o.jsx("div",{className:"mb-2 text-[0.78rem] font-semibold text-[var(--color-ink)]",children:"路由模式"}),o.jsx("div",{className:"grid gap-2",children:ES.map(A=>o.jsxs("button",{type:"button",onClick:()=>x(A.value),className:["rounded-[9px] border bg-white p-2.5 text-left transition",a===A.value?"border-[var(--color-purple)] bg-[var(--color-lavender)]":"border-[var(--color-line-2)] bg-white hover:border-[var(--color-lavender-2)]"].join(" "),children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:["grid size-5 place-items-center rounded-full border",a===A.value?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] text-transparent"].join(" "),children:o.jsx(Jt,{className:"size-3"})}),o.jsx("span",{className:"text-[0.84rem] font-semibold text-[var(--color-ink)]",children:A.title})]}),o.jsx("p",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:A.body})]},A.value))})]}),o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-2.5",children:[o.jsx("div",{className:"mb-2 text-[0.78rem] font-semibold text-[var(--color-ink)]",children:"优化目标"}),o.jsx("div",{className:"grid gap-2",children:AS.map(A=>o.jsxs("button",{type:"button",onClick:()=>p(A.value),className:["rounded-[9px] border bg-white p-2.5 text-left transition",i===A.value?"border-[var(--color-purple)] bg-[var(--color-lavender)]":"border-[var(--color-line-2)] bg-white hover:border-[var(--color-lavender-2)]"].join(" "),children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:["grid size-5 place-items-center rounded-full border",i===A.value?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] text-transparent"].join(" "),children:o.jsx(Jt,{className:"size-3"})}),o.jsx("span",{className:"text-[0.84rem] font-semibold text-[var(--color-ink)]",children:A.title})]}),o.jsx("p",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:A.body})]},A.value))})]})]}),C?o.jsxs("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-white p-3",children:[o.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"text-[0.8rem] font-semibold text-[var(--color-ink)]",children:"选择供应商"}),o.jsx("div",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5 text-[0.72rem] text-[var(--color-muted)]",children:a==="fixed"?u?"已选择 1 个":"尚未选择":`已选择 ${d.length} 个`})]}),r.length===0?o.jsx("div",{className:"mt-2 rounded-[9px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3 text-[0.8rem] leading-5 text-[var(--color-muted)]",children:"正在等待供应商目录。你也可以先返回上一步确认模型目录是否已经加载完成。"}):o.jsx(VS,{mode:a,sellers:r,fixedSellerId:u,fixedSetSellerIds:d,onFixedSellerChange:v,onToggleFixedSetSeller:g})]}):o.jsx("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 text-[0.8rem] leading-5 text-[var(--color-muted)]",children:"当前是全自动模式,TokenBuddy 会根据模型、供应商健康度、速度、价格和余额状态自动规划调用路径。"})]}),o.jsx(j0,{backLabel:"上一步:绑定钱包",nextLabel:"下一步:配置工具",saving:m,message:h,onBack:E,onNext:b})]})}function VS({mode:a,sellers:i,fixedSellerId:r,fixedSetSellerIds:u,onFixedSellerChange:d,onToggleFixedSetSeller:m}){const[h,x]=j.useState({key:"status",direction:"asc"}),p=j.useMemo(()=>S0(i,h),[i,h]),v=b=>{x(E=>({key:b,direction:E.key===b&&E.direction==="asc"?"desc":"asc"}))},g=b=>{if(a==="fixed"){d(b);return}m(b)};return o.jsx("div",{className:"mt-2 overflow-hidden rounded-[9px] border border-[var(--color-line-2)]",children:o.jsx("div",{className:"max-h-[300px] overflow-auto",children:o.jsxs("table",{className:"min-w-[760px] w-full border-collapse text-left text-[0.78rem]",children:[o.jsx("thead",{className:"sticky top-0 z-10 border-b border-[var(--color-line-2)] bg-[var(--color-page)] text-[0.68rem] uppercase tracking-wider text-[var(--color-muted)]",children:o.jsxs("tr",{children:[o.jsx("th",{className:"w-12 px-2 py-2 font-semibold",children:"选"}),o.jsx(ji,{label:"供应商",sortKey:"name",sort:h,onSort:v}),o.jsx(ji,{label:"状态",sortKey:"status",sort:h,onSort:v}),o.jsx(ji,{label:"模型",sortKey:"models",sort:h,onSort:v,align:"right"}),o.jsx(ji,{label:"价格",sortKey:"price",sort:h,onSort:v}),o.jsx(ji,{label:"折扣",sortKey:"discount",sort:h,onSort:v,align:"right"}),o.jsx(ji,{label:"响应",sortKey:"speed",sort:h,onSort:v,align:"right"}),o.jsx("th",{className:"px-3 py-2 font-semibold",children:"支付"})]})}),o.jsx("tbody",{className:"divide-y divide-[var(--color-line-2)] bg-white",children:p.map(b=>{const E=a==="fixed"?r===b.id:u.includes(b.id);return o.jsxs("tr",{onClick:()=>g(b.id),className:["cursor-pointer transition hover:bg-[var(--color-lavender)]/45",E?"bg-[var(--color-lavender)]/70":"bg-white"].join(" "),children:[o.jsx("td",{className:"px-2 py-2.5",children:o.jsx("span",{className:["grid size-5 place-items-center rounded-full border",E?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] text-transparent"].join(" "),children:o.jsx(Jt,{className:"size-3"})})}),o.jsxs("td",{className:"max-w-[210px] px-3 py-2.5",children:[o.jsx("div",{className:"truncate font-semibold text-[var(--color-ink)]",children:b.name}),o.jsx("div",{className:"mt-0.5 truncate font-mono text-[0.68rem] text-[var(--color-muted)]",children:b.id})]}),o.jsx("td",{className:"px-3 py-2.5",children:o.jsx("span",{className:["inline-flex whitespace-nowrap rounded-full px-2 py-0.5 text-[0.7rem] font-semibold",hN(b.status)].join(" "),children:mN(b.status)})}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono font-semibold text-[var(--color-ink)]",children:b.modelCount}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 font-mono text-[0.72rem] text-[var(--color-ink)]",children:tN(b.minInputPriceMicrosPer1m,b.minOutputPriceMicrosPer1m)}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono font-semibold text-[var(--color-purple)]",children:lN(b.discountRatio)}),o.jsx("td",{className:"whitespace-nowrap px-3 py-2.5 text-right font-mono text-[var(--color-ink)]",children:aN(b.avgResponseMs,b.avgTtftMs)}),o.jsx("td",{className:"max-w-[150px] px-3 py-2.5",children:o.jsx("div",{className:"truncate text-[0.72rem] text-[var(--color-muted)]",children:Pd(b.paymentMethods)||"—"})})]},b.id)})})]})})})}function ji({label:a,sortKey:i,sort:r,align:u="left",onSort:d}){const m=r.key===i,h=m?r.direction==="asc"?"↑":"↓":"↕";return o.jsx("th",{className:["px-3 py-2 font-semibold",u==="right"?"text-right":"text-left"].join(" "),children:o.jsxs("button",{type:"button",onClick:()=>d(i),className:["inline-flex items-center gap-1 rounded-[6px] px-1.5 py-1 transition hover:bg-white",u==="right"?"justify-end":"justify-start",m?"text-[var(--color-purple)]":"text-[var(--color-muted)]"].join(" "),children:[o.jsx("span",{children:a}),o.jsx("span",{className:"font-mono text-[0.66rem]",children:h})]})})}function ZS({payments:a,enabledPaymentCount:i,loading:r,qrUrl:u,rechargeQrUrl:d,walletConfigPresent:m,error:h,rechargeError:x,binding:p,rechargeLoading:v,onBind:g,onLoadRecharge:b,onRefreshPayments:E,onBack:C,onContinue:A}){const[z,B]=j.useState("clawtip"),[U,G]=j.useState(!1),[K,L]=j.useState(!1),V=a.find(D=>eu(D.method)==="clawtip"),P=!!(V!=null&&V.enabled||m||$S(V==null?void 0:V.config,"walletConfigPresent")),J=U&&P,ee=[{method:"clawtip",name:"ClawTip",detail:"JD App 扫码 / 微支付",status:P?"已绑定":"可绑定",available:!0},...zS.map(D=>({...D,status:"Coming soon",available:!1}))],le=ee.find(D=>D.method===z)??ee[0],oe=le.method==="clawtip",F=oe&&P&&!J,fe=J||F||U,ye=oe?fe:!0,Ee=()=>{G(!0),g()},me=()=>{L(!0),b()};return j.useEffect(()=>{if(!oe||!U||P)return;const D=window.setInterval(E,1500);return()=>window.clearInterval(D)},[U,P,E,oe]),j.useEffect(()=>{!F||d||v||K||(L(!0),b())},[b,v,d,K,F]),o.jsxs("div",{className:"space-y-3",children:[o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:2,title:"选择支付方式",detail:"钱包和充值通道",meta:r?"checking":`${i} active`,action:oe&&F?o.jsxs("button",{type:"button",disabled:v,onClick:me,className:"inline-flex h-8 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[v?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx(Bi,{className:"size-3.5"}),"刷新充值码"]}):oe&&U&&!P?o.jsxs("button",{type:"button",disabled:p,onClick:Ee,className:"inline-flex h-8 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[p?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx(Gr,{className:"size-3.5"}),"重新生成"]}):oe&&!U&&!P?o.jsxs("button",{type:"button",disabled:p,onClick:Ee,className:"inline-flex h-8 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[p?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx(Gr,{className:"size-3.5"}),"开始绑定"]}):oe?null:o.jsx("span",{className:"inline-flex h-8 items-center rounded-[8px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-2.5 font-mono text-[0.72rem] font-semibold text-[var(--color-muted)]",children:"Coming soon"})}),o.jsxs("div",{className:["mt-3 grid gap-3",ye?"lg:grid-cols-[minmax(0,300px)_minmax(0,1fr)]":"lg:max-w-[360px]"].join(" "),children:[o.jsx("div",{className:"grid content-start gap-2",children:ee.map(D=>{const $=D.method===le.method;return o.jsxs("button",{type:"button",onClick:()=>B(D.method),"aria-pressed":$,className:["grid min-h-[64px] grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-[10px] border px-3 py-2 text-left transition",$?"border-[var(--color-purple)] bg-[var(--color-lavender)] shadow-[0_8px_22px_rgba(124,61,240,0.08)]":"border-[var(--color-line-2)] bg-white hover:bg-[var(--color-page)]"].join(" "),children:[o.jsx("span",{className:["grid size-9 shrink-0 place-items-center rounded-[9px] border",$?"border-[var(--color-lavender-2)] bg-white text-[var(--color-purple)]":"border-[var(--color-line-2)] bg-[var(--color-page)] text-[var(--color-muted)]"].join(" "),children:Fv(D.method)}),o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block truncate text-[0.86rem] font-semibold text-[var(--color-ink)]",children:D.name}),o.jsx("span",{className:"mt-0.5 block truncate text-[0.73rem] text-[var(--color-muted)]",children:D.detail})]}),o.jsx("span",{className:["rounded-full px-2 py-0.5 text-[0.68rem] font-semibold",D.available?"bg-emerald-50 text-emerald-700":"bg-[var(--color-page)] text-[var(--color-muted)]"].join(" "),children:D.status})]},D.method)})}),oe?fe?o.jsx("div",{className:"flex min-h-[360px] items-center justify-center rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-4",children:J?o.jsx("div",{className:"grid size-full min-h-[320px] place-items-center rounded-[10px] border border-emerald-100 bg-emerald-50 px-4 py-5 text-center",children:o.jsxs("div",{children:[o.jsx(Jt,{className:"mx-auto size-8 text-emerald-700"}),o.jsx("div",{className:"mt-3 text-[0.92rem] font-semibold text-emerald-900",children:"绑定成功"}),o.jsx("div",{className:"mt-1 text-[0.78rem] leading-5 text-emerald-800",children:"ClawTip 钱包已经写入本机配置,可以继续配置路由策略。"})]})}):F?d?o.jsx("img",{src:d,alt:"ClawTip 充值二维码",className:"max-h-[340px] w-full max-w-[340px] rounded-[10px] border border-[var(--color-line-2)] bg-white p-3 object-contain shadow-[0_12px_28px_rgba(15,23,42,0.1)]"}):o.jsx("div",{className:"grid size-full min-h-[320px] place-items-center rounded-[10px] border border-dashed border-[var(--color-line-2)] bg-white px-3 py-4 text-center",children:o.jsxs("div",{children:[v?o.jsx(Et,{className:"mx-auto size-6 animate-spin text-[var(--color-purple)]"}):o.jsx(Bi,{className:"mx-auto size-6 text-[var(--color-purple)]"}),o.jsx("div",{className:"mt-2 text-[0.84rem] font-semibold text-[var(--color-ink)]",children:v?"正在加载充值码":"充值码未加载"}),o.jsx("button",{type:"button",disabled:v,onClick:me,className:"mt-3 inline-flex h-8 items-center justify-center rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:"重新加载"})]})}):U&&u?o.jsx("img",{src:u,alt:"ClawTip 钱包绑定二维码",className:"max-h-[340px] w-full max-w-[340px] rounded-[10px] border border-[var(--color-line-2)] bg-white p-3 object-contain shadow-[0_12px_28px_rgba(15,23,42,0.1)]"}):U?o.jsx("div",{className:"grid size-full min-h-[320px] place-items-center rounded-[10px] border border-dashed border-[var(--color-line-2)] bg-white px-3 py-4 text-center",children:o.jsxs("div",{children:[p?o.jsx(Et,{className:"mx-auto size-6 animate-spin text-[var(--color-purple)]"}):o.jsx(Gr,{className:"mx-auto size-6 text-[var(--color-purple)]"}),o.jsx("div",{className:"mt-2 text-[0.84rem] font-semibold text-[var(--color-ink)]",children:p?"正在生成二维码":"等待二维码"}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:"生成后使用京东 App 扫码绑定。"})]})}):null}):null:o.jsx("div",{className:"grid min-h-[220px] place-items-center rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-4 text-center",children:o.jsxs("div",{className:"max-w-[360px]",children:[o.jsx("span",{className:"mx-auto grid size-11 place-items-center rounded-[12px] border border-[var(--color-line-2)] bg-white text-[var(--color-purple)]",children:Fv(le.method)}),o.jsx("div",{className:"mt-3 text-[0.92rem] font-semibold text-[var(--color-ink)]",children:le.name}),o.jsxs("div",{className:"mt-1 text-[0.78rem] leading-5 text-[var(--color-muted)]",children:[le.detail,"。当前版本先通过 ClawTip 完成钱包绑定,后续会在这里接入更多支付流程。"]}),o.jsx("div",{className:"mt-3 inline-flex rounded-full bg-white px-3 py-1 font-mono text-[0.7rem] font-semibold text-[var(--color-muted)]",children:"Coming soon"})]})})]}),oe&&!P&&U&&h?o.jsxs("div",{className:"mt-3 rounded-[10px] bg-rose-50 px-3 py-2 text-[0.84rem] leading-6 text-rose-700",children:["生成二维码失败:",h instanceof Error?h.message:String(h)]}):null,oe&&F&&x?o.jsxs("div",{className:"mt-3 rounded-[10px] bg-rose-50 px-3 py-2 text-[0.84rem] leading-6 text-rose-700",children:["加载充值二维码失败:",x instanceof Error?x.message:String(x)]}):null]}),o.jsx(j0,{backLabel:"上一步:模型访问",nextLabel:"下一步:配置策略",message:i>0?"支付方式已可用,可以继续配置路由策略。":"如果你暂时跳过绑定,后续首次购买模型额度时仍需要完成支付配置。",onBack:C,onNext:A})]})}function Fv(a){const i=eu(a);return i==="wechat-pay"?o.jsx(ej,{className:"size-4"}):i==="alipay-agent"?o.jsx(B2,{className:"size-4"}):i==="coinbase-smart-wallet"?o.jsx(Bi,{className:"size-4"}):o.jsx(Gr,{className:"size-4"})}function $S(a,i){const r=a==null?void 0:a[i];return r===!0||r==="true"||r===1||r==="1"}function JS({clients:a,candidates:i,loading:r,selectedProviders:u,selectedModel:d,modelOptions:m,providerSelections:h,proxyUrl:x,previewChanges:p,applying:v,previewing:g,message:b,onToggleProvider:E,onModelChange:C,onProviderSelectionChange:A,onPreview:z,onInstall:B,onBack:U}){var oe;const G=new Set(i.map(F=>F.id)),K=i.length,L=a.find(F=>F.id==="custom")??w0(x),V=[...a.filter(F=>F.id!=="custom"),{...L,name:"其他工具"}],P=((oe=V[0])==null?void 0:oe.id)??"custom",[J,ee]=j.useState(P),le=V.find(F=>F.id===J)??V[0]??L;return j.useEffect(()=>{var F;V.some(fe=>fe.id===J)||ee(((F=V[0])==null?void 0:F.id)??"custom")},[J,V]),o.jsxs("div",{className:"space-y-3",children:[o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:4,title:"配置工具",detail:"终端接入",meta:`${u.length} selected / ${K} detected`,action:r?o.jsx(Et,{className:"size-4 animate-spin text-[var(--color-purple)]"}):null}),o.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,320px)_minmax(0,1fr)]",children:[o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-2.5",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("div",{className:"text-[0.8rem] font-semibold text-[var(--color-ink)]",children:"工具"}),o.jsxs("div",{className:"rounded-full bg-white px-2 py-0.5 text-[0.72rem] text-[var(--color-muted)]",children:[a.length," tools"]})]}),o.jsx("div",{className:"mt-2 grid max-h-[380px] gap-2 overflow-y-auto pr-1",children:V.map(F=>{const fe=F.id!=="custom"&&G.has(F.id),ye=u.includes(F.id),Ee=le.id===F.id;return o.jsx("button",{type:"button",onClick:()=>ee(F.id),className:["rounded-[10px] border p-2.5 text-left transition",Ee?"border-[var(--color-purple)] bg-white shadow-[0_10px_24px_rgba(60,41,112,0.08)]":"border-[var(--color-line-2)] bg-white/70 hover:border-[var(--color-lavender-2)]"].join(" "),children:o.jsxs("div",{className:"flex items-start gap-2.5",children:[o.jsx("span",{className:["mt-0.5 grid size-6 shrink-0 place-items-center rounded-[8px] border text-[0.72rem] font-semibold",Ee?"border-[var(--color-purple)] bg-[var(--color-lavender)] text-[var(--color-purple)]":"border-[var(--color-line-2)] bg-white text-[var(--color-muted)]"].join(" "),children:nN(F.name)}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("div",{className:"truncate text-[0.84rem] font-semibold text-[var(--color-ink)]",children:F.name}),ye?o.jsx("span",{className:"rounded-full bg-emerald-50 px-1.5 py-0.5 text-[0.66rem] font-semibold text-emerald-700",children:"安装"}):null]}),o.jsxs("div",{className:"mt-1 flex flex-wrap gap-1.5 text-[0.68rem] text-[var(--color-muted)]",children:[o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:E0(F)}),F.commandName?o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:F.commandName}):null,F.id==="custom"?o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:"复制配置"}):null]})]}),F.id!=="custom"?o.jsx("span",{"aria-hidden":"true",className:["mt-0.5 grid size-5 shrink-0 place-items-center rounded-full border",ye?"border-[var(--color-purple)] bg-[var(--color-purple)] text-white":"border-[var(--color-line-2)] text-transparent",fe?"":"opacity-45"].join(" "),children:o.jsx(Jt,{className:"size-3"})}):null]})},F.id)})})]}),o.jsx("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-white p-3",children:o.jsx(FS,{client:le,selected:u.includes(le.id),installable:le.id!=="custom"&&G.has(le.id),selectedModel:d,modelOptions:m,providerSelections:h,proxyUrl:x,onToggleInstall:()=>E(le.id),onModelChange:C,onProviderSelectionChange:A})})]}),p?o.jsxs("div",{className:"mt-3 rounded-[10px] border border-[var(--color-line-2)] bg-white p-3",children:[o.jsx("div",{className:"text-[0.8rem] font-semibold text-[var(--color-ink)]",children:"配置文件变更"}),p.length===0?o.jsx("div",{className:"mt-2 rounded-[9px] border border-dashed border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-3 text-[0.8rem] text-[var(--color-muted)]",children:"没有需要写入的配置变更。"}):o.jsx("div",{className:"mt-2 grid max-h-[180px] gap-2 overflow-y-auto pr-1",children:p.map(F=>o.jsxs("div",{className:"rounded-[9px] border border-[var(--color-line-2)] bg-white p-2.5",children:[o.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[0.78rem] font-semibold text-[var(--color-ink)]",children:[o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5",children:pN(F.action)}),o.jsx("span",{children:F.providerId})]}),o.jsx("div",{className:"mt-1 truncate font-mono text-[0.72rem] text-[var(--color-muted)]",children:F.path}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:F.summary})]},`${F.providerId}:${F.path}:${F.summary}`))})]}):null]}),o.jsxs(jt,{className:"flex flex-col gap-3 p-3 lg:flex-row lg:items-center lg:justify-between",children:[o.jsx("div",{className:"text-[0.84rem] leading-6 text-[var(--color-muted)]",children:b?o.jsx("div",{className:"mt-1 font-medium text-[var(--color-ink)]",children:b}):null}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",onClick:U,className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-muted)] transition hover:text-[var(--color-ink)]",children:"上一步:配置策略"}),o.jsxs("button",{type:"button",disabled:g||u.length===0,onClick:z,className:"inline-flex h-9 items-center justify-center gap-2 rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[g?o.jsx(Et,{className:"size-4 animate-spin"}):null,"预览安装"]}),o.jsxs("button",{type:"button",disabled:v||u.length===0,onClick:B,className:"inline-flex h-9 items-center justify-center gap-2 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[v?o.jsx(Et,{className:"size-4 animate-spin"}):null,"写入配置"]})]})]})]})}function FS({client:a,selected:i,installable:r,selectedModel:u,modelOptions:d,providerSelections:m,proxyUrl:h,onToggleInstall:x,onModelChange:p,onProviderSelectionChange:v}){var E,C,A;if(a.id==="custom"){const z=a.manualConfig??w0(h).manualConfig;return o.jsxs("div",{className:"space-y-3",children:[o.jsx(Ad,{client:a,selected:!1,installable:!1}),o.jsxs("div",{className:"grid gap-2",children:[o.jsx(Qr,{label:"OpenAI base URL",value:(z==null?void 0:z.openaiBaseUrl)??C0(h)}),o.jsx(Qr,{label:"Anthropic base URL",value:(z==null?void 0:z.anthropicBaseUrl)??h}),o.jsx(Qr,{label:"API key",value:(z==null?void 0:z.apiKey)??"TOKENBUDDY_PROXY"})]}),o.jsx("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:"其他工具只需要填入本地推理服务接口和 key,不会写入本机配置文件。"})]})}if(a.id==="claude-code"){const z=M0(m[a.id],d,u),B=(G,K)=>{v(a.id,{...z,fallbackModel:z.fallbackModel||K||u,roles:{...z.roles,[G]:K?{upstreamModel:K,displayName:K}:void 0}})},U=G=>{v(a.id,{...z,fallbackModel:G}),p(G)};return o.jsxs("div",{className:"space-y-3",children:[o.jsx(Ad,{client:a,selected:i,installable:r,onToggleInstall:x}),o.jsxs("div",{className:"grid gap-2 lg:grid-cols-2",children:[o.jsx(qr,{label:"Fallback",value:z.fallbackModel??u,modelOptions:d,onChange:U}),o.jsx(qr,{label:"Haiku",value:((E=z.roles.haiku)==null?void 0:E.upstreamModel)??"",modelOptions:d,onChange:G=>B("haiku",G)}),o.jsx(qr,{label:"Sonnet",value:((C=z.roles.sonnet)==null?void 0:C.upstreamModel)??"",modelOptions:d,onChange:G=>B("sonnet",G)}),o.jsx(qr,{label:"Opus",value:((A=z.roles.opus)==null?void 0:A.upstreamModel)??"",modelOptions:d,onChange:G=>B("opus",G)})]}),o.jsx("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:"Claude Code 会把 Haiku、Sonnet、Opus 三种客户端模型映射到你选择的上游模型。"})]})}const g=N0(a.id,m[a.id],u),b=z=>{p(z),v(a.id,{selectionKind:"single-model",protocolPreference:Id(a.id),defaultModel:z})};return o.jsxs("div",{className:"space-y-3",children:[o.jsx(Ad,{client:a,selected:i,installable:r,onToggleInstall:x}),o.jsx(qr,{label:"模型",value:g.defaultModel,modelOptions:d,onChange:b}),o.jsxs("div",{className:"grid gap-2 lg:grid-cols-2",children:[o.jsx(Qr,{label:"Proxy URL",value:h,compact:!0}),o.jsx(Qr,{label:"API key",value:"TOKENBUDDY_PROXY",compact:!0})]}),a.configPath?o.jsx("div",{className:"truncate rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-3 py-2 font-mono text-[0.72rem] text-[var(--color-muted)]",children:a.configPath}):null]})}function Ad({client:a,selected:i,installable:r,onToggleInstall:u}){return o.jsxs("div",{className:"flex flex-col gap-2 border-b border-[var(--color-line-2)] pb-3 sm:flex-row sm:items-start sm:justify-between",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("div",{className:"text-[0.9rem] font-semibold text-[var(--color-ink)]",children:a.name}),o.jsx("span",{className:"rounded-full bg-[var(--color-page)] px-2 py-0.5 text-[0.7rem] text-[var(--color-muted)]",children:E0(a)})]}),o.jsx("div",{className:"mt-1 text-[0.74rem] leading-5 text-[var(--color-muted)]",children:a.reason})]}),a.id!=="custom"?o.jsxs("button",{type:"button",disabled:!r,onClick:u,className:["inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-[8px] px-2.5 text-[0.78rem] font-semibold transition disabled:cursor-not-allowed disabled:opacity-45",i?"bg-[var(--color-purple)] text-white hover:bg-[var(--color-purple-2)]":"border border-[var(--color-line-2)] bg-white text-[var(--color-ink)] hover:border-[var(--color-purple)]"].join(" "),children:[o.jsx(Jt,{className:"size-3.5"}),i?"已加入安装":"加入安装"]}):null]})}function qr({label:a,value:i,modelOptions:r,onChange:u}){return o.jsxs("label",{className:"block",children:[o.jsx("span",{className:"text-[0.74rem] font-semibold text-[var(--color-muted)]",children:a}),o.jsxs("select",{value:i,onChange:d=>u(d.target.value),className:"mt-1 h-9 w-full rounded-[8px] border border-[var(--color-line-2)] bg-white px-2.5 text-[0.82rem] text-[var(--color-ink)] outline-none focus:border-[var(--color-purple)]",children:[o.jsx("option",{value:"",children:"请选择模型"}),r.map(d=>o.jsx("option",{value:d,children:d},d))]})]})}function Qr({label:a,value:i,compact:r=!1}){const[u,d]=j.useState(!1),m=async()=>{try{await navigator.clipboard.writeText(i),d(!0),window.setTimeout(()=>d(!1),1200)}catch{d(!1)}};return o.jsxs("div",{className:["rounded-[10px] border border-[var(--color-line-2)] bg-white px-3 py-2",r?"min-w-0":""].join(" "),children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("div",{className:"text-[0.72rem] font-semibold text-[var(--color-muted)]",children:a}),o.jsxs("button",{type:"button",onClick:m,className:"inline-flex h-7 items-center justify-center gap-1 rounded-[7px] border border-[var(--color-line-2)] bg-[var(--color-page)] px-2 text-[0.7rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)]",children:[o.jsx(T2,{className:"size-3"}),u?"已复制":"复制"]})]}),o.jsx("div",{className:"mt-1 truncate font-mono text-[0.76rem] text-[var(--color-ink)]",children:i})]})}function WS({items:a,status:i,generatedAt:r,running:u,error:d,onRefresh:m,onBack:h,onContinue:x}){return o.jsx("div",{className:"space-y-3",children:o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:5,title:"验证网关",detail:"本机状态",meta:u?"checking":lx(i),action:o.jsxs("button",{type:"button",disabled:u,onClick:m,className:"inline-flex h-8 items-center justify-center gap-1.5 rounded-[8px] border border-[var(--color-line-2)] bg-white px-2.5 text-[0.78rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[u?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx($d,{className:"size-3.5"}),"刷新"]})}),o.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[0.76rem] text-[var(--color-muted)]",children:[o.jsx("span",{className:["rounded-full px-2 py-0.5 font-semibold",oN(i)].join(" "),children:u?"正在检查":lx(i)}),r?o.jsxs("span",{children:["检查时间:",new Date(r).toLocaleString()]}):o.jsx("span",{children:"等待后端检查。"})]}),d?o.jsxs("div",{className:"mt-3 rounded-[10px] bg-rose-50 px-3 py-2 text-[0.82rem] leading-6 text-rose-700",children:["检查失败:",d instanceof Error?d.message:String(d)]}):null,o.jsx("div",{className:"mt-3 grid gap-2 xl:grid-cols-2",children:a.map(p=>o.jsxs("div",{className:"flex gap-2.5 rounded-[10px] border border-[var(--color-line-2)] bg-white p-2.5",children:[o.jsx("span",{className:["mt-0.5 grid size-6 shrink-0 place-items-center rounded-full",cN(p.status)].join(" "),children:p.ok?o.jsx(Jt,{className:"size-3.5"}):o.jsx($d,{className:"size-3.5"})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-[0.82rem] font-semibold text-[var(--color-ink)]",children:[p.title,o.jsx("span",{className:["rounded-full px-1.5 py-0.5 text-[0.68rem]",dN(p.status)].join(" "),children:uN(p.status)})]}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:p.body})]})]},p.title))}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2 border-t border-[var(--color-line-2)] pt-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"text-[0.78rem] leading-5 text-[var(--color-muted)]",children:"发现异常时返回对应步骤补齐配置。"}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-muted)] transition hover:text-[var(--color-ink)]",children:"上一步"}),o.jsxs("button",{type:"button",onClick:x,className:"inline-flex h-9 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)]",children:["下一步",o.jsx(Jo,{className:"size-3.5"})]})]})]})]})})}function PS({complete:a,message:i,installMessage:r,canInstall:u,installed:d,saving:m,onBack:h,onComplete:x,onInstall:p}){return o.jsx("div",{className:"space-y-3",children:o.jsxs(jt,{className:"p-3",children:[o.jsx(Yi,{index:6,title:a?"初始化完成":"桌面应用",detail:d?"已安装":"可选安装",meta:a?"complete":d?"installed":"optional",action:o.jsxs("button",{type:"button",disabled:d,onClick:p,className:"inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-2.5 text-[0.78rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[o.jsx(Jt,{className:"size-3.5"}),d?"已安装":"安装应用"]})}),o.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,290px)_minmax(0,1fr)]",children:[o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-[var(--color-page)] p-3",children:[o.jsx("div",{className:"text-[0.84rem] font-semibold text-[var(--color-ink)]",children:d?"TokenBuddy 桌面应用已安装":u?"浏览器支持直接安装":"可从浏览器菜单安装"}),o.jsx("div",{className:"mt-1 text-[0.76rem] leading-5 text-[var(--color-muted)]",children:d?"你可以从系统应用入口打开 TokenBuddy。":u?"点击右上角安装按钮并确认浏览器弹窗。":"在地址栏右侧或浏览器菜单中找到安装应用入口。"}),r?o.jsx("div",{className:"mt-2 text-[0.78rem] font-medium text-[var(--color-ink)]",children:r}):null]}),o.jsx("div",{className:"grid gap-2 lg:grid-cols-3",children:[{title:"安装入口",body:"地址栏或浏览器菜单。"},{title:"应用名称",body:"TokenBuddy。"},{title:"本地服务",body:"继续由 tb-proxyd 提供。"}].map((v,g)=>o.jsxs("div",{className:"rounded-[10px] border border-[var(--color-line-2)] bg-white p-2.5",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"grid size-5 place-items-center rounded-full bg-[var(--color-lavender)] font-mono text-[0.68rem] font-semibold text-[var(--color-purple)]",children:g+1}),o.jsx("span",{className:"text-[0.8rem] font-semibold text-[var(--color-ink)]",children:v.title})]}),o.jsx("div",{className:"mt-1 text-[0.74rem] leading-5 text-[var(--color-muted)]",children:v.body})]},v.title))})]}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2 border-t border-[var(--color-line-2)] pt-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"text-[0.78rem] leading-5 text-[var(--color-muted)]",children:i?o.jsx("span",{className:"font-medium text-[var(--color-ink)]",children:i}):"完成后可以进入控制台。"}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-muted)] transition hover:text-[var(--color-ink)]",children:"上一步"}),o.jsxs("button",{type:"button",disabled:m||a,onClick:x,className:"inline-flex h-9 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[m?o.jsx(Et,{className:"size-3.5 animate-spin"}):o.jsx(Jt,{className:"size-3.5"}),a?"已完成":"完成初始化"]}),o.jsx(ns,{to:"/overview",className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-ink)] transition hover:border-[var(--color-purple)]",children:"进入控制台"})]})]})]})})}function j0({backLabel:a,nextLabel:i,saving:r=!1,message:u,onBack:d,onNext:m}){return o.jsxs(jt,{className:"flex flex-col gap-2.5 p-3 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("div",{className:"text-[0.78rem] leading-5 text-[var(--color-muted)]",children:u??"配置完成后继续下一步。"}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",onClick:d,className:"inline-flex h-9 items-center justify-center rounded-[8px] border border-[var(--color-line-2)] bg-white px-3 text-[0.82rem] font-semibold text-[var(--color-muted)] transition hover:text-[var(--color-ink)]",children:a}),o.jsxs("button",{type:"button",disabled:r,onClick:m,className:"inline-flex h-9 items-center justify-center gap-1.5 rounded-[8px] bg-[var(--color-ink)] px-3 text-[0.82rem] font-semibold text-white transition hover:bg-[var(--color-purple)] disabled:cursor-not-allowed disabled:opacity-45",children:[r?o.jsx(Et,{className:"size-3.5 animate-spin"}):null,i,r?null:o.jsx(Jo,{className:"size-3.5"})]})]})]})}function IS(a,i,r){const u=new Map;for(const h of i){const x=u.get(h.sellerId)??{modelIds:new Set,protocols:new Set,paymentMethods:new Set,responseMsSamples:[],ttftMsSamples:[]};x.modelIds.add(h.id);for(const p of h.supportedProtocols)x.protocols.add(p);for(const p of h.paymentMethods)x.paymentMethods.add(p);x.minInputPriceMicrosPer1m=Pv(x.minInputPriceMicrosPer1m,h.inputPriceMicrosPer1m),x.minOutputPriceMicrosPer1m=Pv(x.minOutputPriceMicrosPer1m,h.outputPriceMicrosPer1m),u.set(h.sellerId,x)}for(const h of r){const x=h.sellerKey;if(!x)continue;const p=u.get(x)??{modelIds:new Set,protocols:new Set,paymentMethods:new Set,responseMsSamples:[],ttftMsSamples:[]};Number.isFinite(h.durationMs)&&p.responseMsSamples.push(h.durationMs),Number.isFinite(h.ttftMs)&&p.ttftMsSamples.push(h.ttftMs),u.set(x,p)}const d=a.map(h=>{const x=u.get(h.id);return{id:h.id,name:Iv(h.name??h.manifestSellerId??h.id),status:h.status,modelCount:h.modelCount??(x==null?void 0:x.modelIds.size)??0,protocols:h.supportedProtocols??Array.from((x==null?void 0:x.protocols)??[]),paymentMethods:h.paymentMethods??Array.from((x==null?void 0:x.paymentMethods)??[]),discountRatio:h.discountRatio,serviceFeeRatio:h.serviceFeeRatio,minInputPriceMicrosPer1m:x==null?void 0:x.minInputPriceMicrosPer1m,minOutputPriceMicrosPer1m:x==null?void 0:x.minOutputPriceMicrosPer1m,avgResponseMs:ko((x==null?void 0:x.responseMsSamples)??[]),avgTtftMs:ko((x==null?void 0:x.ttftMsSamples)??[])}}),m=new Set(d.map(h=>h.id));for(const[h,x]of u.entries()){if(m.has(h))continue;const p=i.find(v=>v.sellerId===h);d.push({id:h,name:Iv((p==null?void 0:p.sellerName)??h),status:"unknown",modelCount:x.modelIds.size,protocols:Array.from(x.protocols).sort(),paymentMethods:Array.from(x.paymentMethods).sort(),minInputPriceMicrosPer1m:x.minInputPriceMicrosPer1m,minOutputPriceMicrosPer1m:x.minOutputPriceMicrosPer1m,avgResponseMs:ko(x.responseMsSamples),avgTtftMs:ko(x.ttftMsSamples)})}return S0(d,{key:"status",direction:"asc"})}function S0(a,i){const r=i.direction==="asc"?1:-1;return[...a].sort((u,d)=>{const m=eN(u,d,i.key);if(m!==0)return m*r;const h=Vo(u.status)-Vo(d.status);return h!==0?h:d.modelCount!==u.modelCount?d.modelCount-u.modelCount:u.name.localeCompare(d.name)})}function eN(a,i,r){return r==="status"?Vo(a.status)-Vo(i.status):r==="name"?a.name.localeCompare(i.name):r==="models"?a.modelCount-i.modelCount:r==="price"?zd(Wv(a),Wv(i)):r==="discount"?zd(a.discountRatio,i.discountRatio):zd(a.avgResponseMs??a.avgTtftMs,i.avgResponseMs??i.avgTtftMs)}function Wv(a){if(!(!Number.isFinite(a.minInputPriceMicrosPer1m)&&!Number.isFinite(a.minOutputPriceMicrosPer1m)))return(a.minInputPriceMicrosPer1m??0)+(a.minOutputPriceMicrosPer1m??0)}function Pv(a,i){const r=Number.isFinite(a),u=Number.isFinite(i);if(r&&u)return Math.min(a,i);if(r)return a;if(u)return i}function ko(a){const i=a.filter(r=>Number.isFinite(r));if(i.length!==0)return i.reduce((r,u)=>r+u,0)/i.length}function zd(a,i){const r=Number.isFinite(a),u=Number.isFinite(i);return r&&u?a-i:r?-1:u?1:0}function Iv(a){var i;return((i=a.split("(")[0])==null?void 0:i.trim())||a}function tN(a,i){return!Number.isFinite(a)&&!Number.isFinite(i)?"-":`I ${ex(a)} / O ${ex(i)}`}function ex(a){if(!Number.isFinite(a))return"-";const i=a/1e6;return`$${i>=1?i.toFixed(2):i.toFixed(4)}`}function lN(a){if(!Number.isFinite(a))return"-";const i=a;if(i<=0)return"free";const r=Math.max(0,1-i);return r>=.01?`${Math.round(r*100)}% off`:`x${i.toFixed(2)}`}function aN(a,i){return!Number.isFinite(a)&&!Number.isFinite(i)?"-":Number.isFinite(a)&&Number.isFinite(i)?`${Math.round(a)}ms / T ${Math.round(i)}ms`:Number.isFinite(a)?`${Math.round(a)}ms`:`T ${Math.round(i)}ms`}function tx(a,i,r,u){const d=u||r[0]||"",m={};for(const h of a)h!=="custom"&&(m[h]=h==="claude-code"?M0(i[h],r,d):N0(h,i[h],d));return m}function N0(a,i,r){return(i==null?void 0:i.selectionKind)==="single-model"?{...i,protocolPreference:i.protocolPreference??Id(a),defaultModel:i.defaultModel||r}:{selectionKind:"single-model",protocolPreference:Id(a),defaultModel:r}}function M0(a,i,r){var m;const u=(a==null?void 0:a.selectionKind)==="claude-role-mapping"?(m=a.roles.sonnet)==null?void 0:m.upstreamModel:void 0,d=r||u||i[0]||"";return(a==null?void 0:a.selectionKind)==="claude-role-mapping"?{...a,protocolPreference:"messages",fallbackModel:a.fallbackModel||d,roles:{...a.roles,sonnet:a.roles.sonnet??(d?{upstreamModel:d,displayName:d}:void 0)}}:{selectionKind:"claude-role-mapping",protocolPreference:"messages",fallbackModel:d,roles:{sonnet:d?{upstreamModel:d,displayName:d}:void 0}}}function Id(a){if(a==="codex")return"responses";if(a==="claude-code"||a==="claude-desktop")return"messages";if(["openclaw","opencode","hermes"].includes(a))return"chat_completions"}function w0(a){return{id:"custom",name:"其他工具",status:"manual",detected:!0,configured:!1,reason:"复制本地推理服务接口到任意 OpenAI 或 Anthropic 兼容客户端。",manualConfig:{openaiBaseUrl:C0(a),anthropicBaseUrl:a,apiKey:"TOKENBUDDY_PROXY"}}}function C0(a){const i=a.replace(/\/+$/,"");return i.endsWith("/v1")?i:`${i}/v1`}function nN(a){const i=a.trim();return i?i.slice(0,1).toUpperCase():"?"}function iN(a,i,r,u){if(a==="fixed"){const d=r.trim();return d?{mode:a,scorer:i,sellerId:d}:void 0}if(a==="fixedSet"){const d=Array.from(new Set(u.map(m=>m.trim()).filter(Boolean)));return d.length===0?void 0:{mode:a,scorer:i,sellerIds:d}}return{mode:a,scorer:i}}function rN({serviceReady:a,modelCount:i,routingMode:r,paymentReady:u,configuredTools:d}){return[{title:a?"本地网关正在运行":"本地网关尚未就绪",body:a?"控制台服务和本地代理已经响应。":"请确认 tb-proxyd 已启动,并等待控制台刷新状态。",ok:a,status:a?"passed":"failed",details:[]},{title:i>0?"模型目录已加载":"模型目录尚未加载",body:i>0?`已发现 ${i} 个可用模型。`:"请检查供应商注册表或网络连接。",ok:i>0,status:i>0?"passed":"failed",details:[]},{title:"路由策略已选择",body:`当前策略为${T0(r)},TokenBuddy 会按这个策略规划供应商。`,ok:!!r,status:r?"passed":"failed",details:[]},{title:u?"支付方式可用":"支付方式尚未可用",body:u?"已经检测到至少一个可用支付方式。":"请完成 ClawTip 绑定,或稍后在支付页面补充配置。",ok:u,status:u?"passed":"warning",details:[]},{title:d>0?"终端工具已接入":"终端工具尚未接入",body:d>0?`已经写入 ${d} 个终端工具配置。`:"如果你还没有安装终端工具,可以稍后再执行接入。",ok:d>0,status:d>0?"passed":"warning",details:[]}]}function sN(a){return{title:a.label,body:a.message,ok:a.status==="passed"||a.status==="skipped",status:a.status,details:a.details}}function lx(a){return a==="passed"?"全部通过":a==="warning"?"存在警告":a==="failed"?"需要修复":"等待检查"}function oN(a){return a==="passed"?"bg-emerald-50 text-emerald-700":a==="warning"?"bg-amber-50 text-amber-700":a==="failed"?"bg-rose-50 text-rose-700":"bg-[var(--color-page)] text-[var(--color-muted)]"}function uN(a){return a==="passed"?"通过":a==="warning"?"警告":a==="failed"?"失败":"已跳过"}function cN(a){return a==="passed"?"bg-emerald-50 text-emerald-700":a==="failed"?"bg-rose-50 text-rose-700":a==="skipped"?"bg-slate-100 text-slate-600":"bg-amber-50 text-amber-700"}function dN(a){return a==="passed"?"bg-emerald-50 text-emerald-700":a==="failed"?"bg-rose-50 text-rose-700":a==="skipped"?"bg-slate-100 text-slate-600":"bg-amber-50 text-amber-700"}function T0(a){return a==="fixed"?"固定供应商":a==="fixedSet"?"固定供应商组":"全自动"}function fN(a){return a==="speed"?"速度优先":a==="discount"?"成本优先":"平衡模式"}function mN(a){const i=a.toLowerCase();return["ok","healthy","active","available"].includes(i)?"状态正常":["error","failed","unavailable"].includes(i)?"状态异常":["unknown","pending"].includes(i)?"等待检测":`状态:${a}`}function hN(a){const i=a.toLowerCase();return["ok","healthy","active","available"].includes(i)?"bg-emerald-50 text-emerald-700":["error","failed","unavailable"].includes(i)?"bg-rose-50 text-rose-700":"bg-amber-50 text-amber-700"}function Vo(a){const i=a.toLowerCase();return["ok","healthy","active","available"].includes(i)?0:["unknown","pending"].includes(i)?1:2}function E0(a){return a.configured?"已配置":a.status==="installed"?"已安装":a.status==="manual"?"需要手动配置":a.detected?"已检测到":"未检测到"}function pN(a){return a==="create"?"创建":"更新"}function vN(){return o.jsxs("div",{className:"min-h-full",children:[o.jsxs("nav",{"aria-label":"Primary",className:"sticky top-0 z-10 flex h-12 items-center gap-2 border-b border-[var(--color-line-2)] bg-[var(--color-page)]/95 px-3 backdrop-blur sm:gap-5 sm:px-6",children:[o.jsxs(df,{to:"/overview","aria-label":"TokenBuddy home",className:"group inline-flex shrink-0 items-center rounded-[var(--radius-md)] px-1 py-1.5 focus:outline-none focus:ring-2 focus:ring-[var(--color-primary)]",children:[o.jsx("span",{className:"font-mono text-[0.86rem] font-bold uppercase tracking-[0.14em] text-[var(--color-ink)]",children:"tokenbuddy"}),o.jsx("span",{className:"ml-1.5 inline-block size-1.5 rounded-full bg-[var(--color-primary)] shadow-[0_0_0_3px_rgba(124,61,240,0.18)]","aria-hidden":!0})]}),o.jsxs("div",{className:"ml-auto flex min-w-0 gap-0.5 sm:gap-1",children:[o.jsx(Rd,{to:"/overview",children:"Overview"}),o.jsx(Rd,{to:"/routing",children:"Routing"}),o.jsx(Rd,{to:"/ledger",children:"Ledger"})]})]}),o.jsx("main",{className:"mx-auto max-w-[1180px] px-3 py-5 sm:px-6 sm:py-7",children:o.jsxs(Fg,{children:[o.jsx(Si,{path:"/",element:o.jsx(Yv,{})}),o.jsx(Si,{path:"/overview",element:o.jsx(Yv,{})}),o.jsx(Si,{path:"/init",element:o.jsx(_S,{})}),o.jsx(Si,{path:"/routing",element:o.jsx(Qj,{})}),o.jsx(Si,{path:"/ledger",element:o.jsx(cS,{})})]})})]})}function Rd({to:a,children:i}){return o.jsx(df,{to:a,className:({isActive:r})=>["rounded-[var(--radius-md)] px-2 py-1.5 text-[0.82rem] font-medium transition-colors sm:px-3.5 sm:text-[0.92rem]",r?"font-semibold text-[var(--color-ink)] underline decoration-[var(--color-primary)] decoration-2 underline-offset-[10px]":"text-[var(--color-muted)] hover:text-[var(--color-ink)]"].join(" "),children:i})}function xN(){!("serviceWorker"in navigator)||window.location.port==="5173"||window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js").catch(()=>{})})}const yN=new e2({defaultOptions:{queries:{staleTime:5e3,refetchOnWindowFocus:!1,retry:1}}});Wb.createRoot(document.getElementById("root")).render(o.jsx(j.StrictMode,{children:o.jsx(t2,{client:yN,children:o.jsx(g1,{children:o.jsx(vN,{})})})}));xN();
|
|
236
|
+
//# sourceMappingURL=index-BJSOFJIU.js.map
|