@aidotnet/server-linux-x64 0.13.3 → 0.13.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/bin/astra-server +2 -2
  2. package/bin/wwwroot/assets/{ClientsPage-CnHLR9_Q.js → ClientsPage-gRSh7_CV.js} +2 -2
  3. package/bin/wwwroot/assets/{KeyPage-zIb63Of5.js → KeyPage-D77qfw6X.js} +1 -1
  4. package/bin/wwwroot/assets/{ModelDetailPage-BcXehC4E.js → ModelDetailPage-9WGV08Ir.js} +1 -1
  5. package/bin/wwwroot/assets/{ModelsPage-BWIb4L9N.js → ModelsPage-ONDK3J08.js} +1 -1
  6. package/bin/wwwroot/assets/{PluginsPage-BaoJMLzq.js → PluginsPage-nSzZ0q9J.js} +1 -1
  7. package/bin/wwwroot/assets/{PrivacyPage-BmqVk2pi.js → PrivacyPage-L2K6y0cS.js} +1 -1
  8. package/bin/wwwroot/assets/{ProviderDetailPage-BLCMpahq.js → ProviderDetailPage-Cb_AXwQV.js} +1 -1
  9. package/bin/wwwroot/assets/{ProvidersPage-CnBPj_Jb.js → ProvidersPage-D4CaD0A4.js} +1 -1
  10. package/bin/wwwroot/assets/{SettingsPage-CcEs-Ivi.js → SettingsPage-DxaHksJO.js} +2 -2
  11. package/bin/wwwroot/assets/{SmartRoutingPage-BEf8F6eE.js → SmartRoutingPage-CAcrEtoz.js} +1 -1
  12. package/bin/wwwroot/assets/{TokenDetailPage-CnwCepbj.js → TokenDetailPage-DQjS2Rfd.js} +1 -1
  13. package/bin/wwwroot/assets/{TokenPoolEditor-B5YYbTBI.js → TokenPoolEditor-B_Z5aPHq.js} +1 -1
  14. package/bin/wwwroot/assets/{TokensPage-IYF5mfUz.js → TokensPage-DI5GW9jT.js} +1 -1
  15. package/bin/wwwroot/assets/{TracesPage-RdQ1uzTo.js → TracesPage-BLhnQx6x.js} +1 -1
  16. package/bin/wwwroot/assets/{TrayPanelPage-DF3TZ-Mi.js → TrayPanelPage-BVygPKsx.js} +1 -1
  17. package/bin/wwwroot/assets/{TrayPanelView-ctysAPlQ.js → TrayPanelView-CxRkRjNA.js} +1 -1
  18. package/bin/wwwroot/assets/{alert-CMMOyMsp.js → alert-BF0mCqUl.js} +3 -3
  19. package/bin/wwwroot/assets/{arrow-down-rd1gJD55.js → arrow-down-DZLYQSjE.js} +1 -1
  20. package/bin/wwwroot/assets/{arrow-left-BYi8J86q.js → arrow-left-D_GXSlab.js} +1 -1
  21. package/bin/wwwroot/assets/{arrow-up-right-DNaPmTcJ.js → arrow-up-right-6yJy6Xdl.js} +1 -1
  22. package/bin/wwwroot/assets/{checkbox--x0D0yfB.js → checkbox-j5bCl2a6.js} +1 -1
  23. package/bin/wwwroot/assets/{cloud-download-BkOTPIzF.js → cloud-download-D02pcV_l.js} +1 -1
  24. package/bin/wwwroot/assets/{confirm-morph-BLco2mdX.js → confirm-morph-DanmNnVF.js} +1 -1
  25. package/bin/wwwroot/assets/{download-CSRdoXEJ.js → download-DDp7Ezie.js} +1 -1
  26. package/bin/wwwroot/assets/{ellipsis-BI50R2Bc.js → ellipsis-D10W7mYw.js} +1 -1
  27. package/bin/wwwroot/assets/{external-link-Bzx5-ExU.js → external-link-DTLyxO14.js} +1 -1
  28. package/bin/wwwroot/assets/{folder-open-BxXgq-F4.js → folder-open-VpvxiCWo.js} +1 -1
  29. package/bin/wwwroot/assets/{index-Ck4Qlg9B.js → index-CN0EAD0q.js} +3 -3
  30. package/bin/wwwroot/assets/{log-out-DzOM9UKH.js → log-out-DOsFUSwe.js} +1 -1
  31. package/bin/wwwroot/assets/minus-CFFJg-m8.js +1 -0
  32. package/bin/wwwroot/assets/{overlays-BFrvqpMl.js → overlays-OPtjc9Yr.js} +1 -1
  33. package/bin/wwwroot/assets/{pencil-BMnmsFVj.js → pencil-Zf5QNEUX.js} +1 -1
  34. package/bin/wwwroot/assets/{power-CznSHqkx.js → power-B2lC52A0.js} +1 -1
  35. package/bin/wwwroot/assets/{radio-cards-DNOgi4px.js → radio-cards-DAFCv1Xc.js} +1 -1
  36. package/bin/wwwroot/assets/{rotate-ccw-Bhx85LK2.js → rotate-ccw-DwTwYkU2.js} +1 -1
  37. package/bin/wwwroot/assets/{sortable.esm-BY9yO4Eq.js → sortable.esm-Btakc5-n.js} +1 -1
  38. package/bin/wwwroot/index.html +3 -3
  39. package/package.json +1 -1
  40. package/bin/wwwroot/assets/minus-CYKTpU0K.js +0 -1
@@ -1 +1 @@
1
- import{Fa as e,H as t,J as n,Pa as r,Pr as i,Q as a,Ra as o,Sr as s,Tr as c,X as l,Y as u,_ as d,bi as f,c as p,ct as m,d as h,ei as g,gt as _,l as v,ln as y,n as b,or as x,p as S,q as C,r as w,s as T,si as E,t as D,tn as O,v as k,xt as A}from"./alert-CMMOyMsp.js";import{a as j,gt as M,i as N,n as ee,o as P,r as F}from"./overlays-BFrvqpMl.js";import{t as te}from"./ellipsis-BI50R2Bc.js";import{t as ne}from"./pencil-BMnmsFVj.js";import{t as re}from"./power-CznSHqkx.js";import{t as ie}from"./rotate-ccw-Bhx85LK2.js";import{H as ae,L as oe,N as I,P as se,V as L,X as R,_ as z,h as B,s as V,y as H,z as U}from"./index-Ck4Qlg9B.js";import{a as ce,i as W,n as G,r as K,t as q}from"./TokenPoolEditor-B5YYbTBI.js";var J={name:`chart-column`,size:24,node:[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]],aliases:[`bar-chart-3`]};J.node;var le=A(J),Y={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};Y.node;var ue=A(Y),X=o(e(),1),Z=r();function de(){let{t:e}=m(),t=g(),n=i(),r=E(),a=r.data?.state===`connected`?r.data.publicUrl:null,[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null);return(0,Z.jsxs)(B,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,Z.jsx)(w,{variant:`primary`,icon:(0,Z.jsx)(U,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`tokens.add`)}),children:[(0,Z.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[n.data&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${n.data.gatewayBaseUrl}/v1`})}),(0,Z.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:n.data.gatewayBaseUrl})}),a&&(0,Z.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${a}/v1`,key:`${a}/key`})})]}),t.isLoading&&(0,Z.jsx)(k,{lines:4}),t.isError&&(0,Z.jsx)(D,{tone:`danger`,title:e(`common.error`),children:j(t.error)}),t.data?.length===0&&(0,Z.jsx)(`div`,{className:`card`,children:(0,Z.jsx)(p,{icon:(0,Z.jsx)(L,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,Z.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,Z.jsx)(fe,{token:e,defaultOpen:t.data.length===1,onEdit:()=>l(e)},e.id))})]}),(0,Z.jsx)(_e,{open:o,onOpenChange:s}),(0,Z.jsx)(ve,{token:c,onClose:()=>l(null)})]})}function fe({token:e,defaultOpen:r,onEdit:o}){let{t:l,locale:d}=m(),{toast:p,confirm:h}=P(),g=x(),v=i(),S=c(),C=f(),E=s(),D=y(),[O,k]=(0,X.useState)(r),A=(g.data??[]).find(t=>t.id===e.providerId),N=ce(),F=`token-detail-${e.id}`,L=(e,t)=>{p(t,`success`),e.skipped.length>0&&p(l(`tokens.skipped`,{clients:e.skipped.map(e=>z[e]?.name??e).join(`, `)}),`error`)},B=()=>S.mutate(e.id,{onSuccess:async({token:e})=>{await M.copy(e)?p(l(`tokens.copied`)):p(l(`tokens.copyFailed`),`error`)},onError:e=>p(j(e),`error`)}),V=async()=>{let e=v.data?.gatewayBaseUrl;e&&(await M.copy(`${e}/v1`)?p(l(`tokens.urlCopied`)):p(l(`tokens.copyFailed`),`error`))},U=async()=>{let e=v.data?.gatewayBaseUrl;e&&(await M.copy(`npx @aidotnet/astra-connect join ${e}`)?p(l(`tokens.joinCopied`)):p(l(`tokens.copyFailed`),`error`))},W=async()=>{(!e.enabled||await h({title:l(`tokens.disableConfirm`,{name:e.name}),detail:l(`tokens.disableDetail`),confirmLabel:l(`tokens.disable`),destructive:!0}))&&C.mutate({id:e.id,enabled:!e.enabled},{onError:e=>p(j(e),`error`)})},K=async()=>{await h({title:l(`tokens.resetConfirm`,{name:e.name}),detail:l(`tokens.resetDetail`),confirmLabel:l(`tokens.reset`),destructive:!0})&&E.mutate(e.id,{onSuccess:e=>L(e,l(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>p(j(e),`error`)})},q=async()=>{await h({title:l(`tokens.deleteConfirm`,{name:e.name}),detail:l(`tokens.deleteDetail`),confirmLabel:l(`common.delete`),destructive:!0})&&D.mutate(e.id,{onSuccess:t=>L(t,l(`tokens.deleted`,{name:e.name})),onError:e=>p(j(e),`error`)})},J=e.lastUsedAt?t(e.lastUsedAt,d):l(`tokens.neverUsed`);return(0,Z.jsxs)(`article`,{children:[(0,Z.jsxs)(`div`,{className:`flex cursor-pointer flex-wrap items-center gap-x-5 gap-y-2 px-4 py-3 hover:bg-[var(--surface-muted)]`,onClick:()=>k(e=>!e),children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":O,"aria-controls":F,"aria-label":l(`tokens.details`),onClick:e=>{e.stopPropagation(),k(e=>!e)},children:(0,Z.jsx)(ae,{className:`size-4 transition-transform ${O?`rotate-90`:``}`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${e.enabled?``:`text-[var(--text-muted)]`}`,children:e.name}),e.isDefault&&(0,Z.jsx)(b,{tone:`accent`,children:l(`tokens.default`)}),!e.enabled&&(0,Z.jsx)(b,{tone:`orange`,children:l(`tokens.disabledBadge`)}),e.limitUsage.some(e=>e.exhausted)&&(0,Z.jsx)(b,{tone:`orange`,children:l(`tokens.limitExhausted`)}),e.pool&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.pool.members.map(e=>e.providerId).join(`, `),children:[(0,Z.jsx)(b,{children:l(`tokens.pool.summary`,{count:e.pool.members.length,strategy:l(`tokens.strategy.${e.pool.strategy}`)})}),e.pool.members.map(e=>(0,Z.jsx)(T,{tone:G(e.health.state)},e.providerId))]})]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:e.keyMasked}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(_,{className:`size-3.5`}),"aria-label":l(`tokens.copy`),title:l(`tokens.copy`),loading:S.isPending,onClick:B}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(ue,{className:`size-3.5`}),"aria-label":l(`tokens.copyUrl`),title:l(`tokens.copyUrl`),disabled:!v.data,onClick:()=>void V()}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(se,{className:`size-3.5`}),"aria-label":l(`tokens.copyJoin`),title:l(`tokens.copyJoin`),disabled:!v.data,onClick:()=>void U()})]})]})]}),(0,Z.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:e.clients.map(e=>z[e]?.name??e).join(`, `)||l(`tokens.noClients`),children:e.clients.length===0?(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):e.clients.map(e=>(0,Z.jsx)(H,{kind:e,size:16},e))}),(0,Z.jsx)(Q,{label:l(`tokens.today`),value:a(e.today.costUsd),context:l(`tokens.requestsContext`,{count:u(e.today.requests)})}),(0,Z.jsx)(Q,{label:l(`tokens.total`),value:a(e.total.costUsd),context:`${u(e.total.totalTokens,!0)} Token`}),(0,Z.jsx)(Q,{label:l(`tokens.lastUsedTitle`),value:e.lastUsedAt?n(e.lastUsedAt,d):`—`,context:e.lastUsedAt?``:l(`tokens.neverUsed`),title:J}),(0,Z.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(ee,{label:l(`common.more`),icon:(0,Z.jsx)(te,{className:`size-4`}),items:[{id:`settings`,label:l(`tokens.settings`),icon:(0,Z.jsx)(ne,{className:`size-3.5`}),onSelect:o},{id:`toggle`,label:e.enabled?l(`tokens.disable`):l(`tokens.enable`),icon:(0,Z.jsx)(re,{className:`size-3.5`}),onSelect:()=>void W()},{id:`reset`,label:l(`tokens.reset`),icon:(0,Z.jsx)(ie,{className:`size-3.5`}),onSelect:()=>void K()},...e.isDefault?[]:[{id:`delete`,label:l(`tokens.delete`),icon:(0,Z.jsx)(I,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void q()}]]})})]}),O&&(0,Z.jsxs)(`div`,{id:F,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,Z.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:l(`tokens.clients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.clients.length===0?l(`tokens.noClients`):e.clients.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(H,{kind:e,size:14}),z[e]?.name??e]},e))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:e.pool?l(`tokens.pool.title`):l(`tokens.directProvider`)}),e.pool?(0,Z.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.pool.members.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:N(e.health),children:[(0,Z.jsx)(T,{tone:G(e.health.state)}),(g.data??[]).find(t=>t.id===e.providerId)?.name??e.providerId]},e.providerId))}):(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:A?.name??(e.providerId?e.providerId:l(`tokens.directNone`))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:l(`tokens.allowedClients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:e.allowedClients==null?l(`tokens.allowedClientsAny`):e.allowedClients.length===0?l(`tokens.directOnly`):e.allowedClients.map(e=>z[e]?.name??e).join(`, `)})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:l(`tokens.lastUsedTitle`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:J})]})]}),(0,Z.jsx)(pe,{token:e}),(0,Z.jsx)(he,{today:e.today,total:e.total}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,Z.jsx)(R,{to:`/tokens/${encodeURIComponent(e.id)}`,children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(le,{className:`size-3.5`}),children:l(`tokens.detail.open`)})}),(0,Z.jsx)(R,{to:`/requests?token=${encodeURIComponent(e.id)}`,children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(oe,{className:`size-3.5`}),children:l(`tokens.detail.viewLogs`)})})]})]})]})}function pe({token:e}){let{t}=m(),n=e.limits?.rpm;return(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,Z.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,Z.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,Z.jsx)(me,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,Z.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,Z.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function me({usage:e}){let{t:n,locale:r}=m(),i=`${n(`tokens.period.${e.period}`)} · ${n(`tokens.metric.${e.metric}`)}`,o=t=>e.metric===`cost`?a(t):u(t,!0),s=Math.max(0,Math.min(100,Math.round(e.usedPercent))),c=s>=90?`var(--danger)`:s>=70?`var(--warning)`:`var(--accent)`;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,Z.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:i}),(0,Z.jsx)(`span`,{className:`num`,children:n(`tokens.limitUsed`,{used:o(e.used),limit:o(e.limit)})})]}),(0,Z.jsx)(`div`,{role:`progressbar`,"aria-valuenow":s,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${s}%`,background:c}})}),e.resetsAt&&(0,Z.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n(`tokens.limitResets`,{time:t(e.resetsAt,r)})})]})}function Q({label:e,value:t,context:n,title:r}){return(0,Z.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Z.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function he({today:e,total:t}){let{t:n}=m(),r=[[n(`tokens.today`),e],[n(`tokens.total`),t]],i=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,o=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,Z.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,Z.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,Z.jsx)(`th`,{className:`${i} text-left`}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.cost`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.requests`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.tokens`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.inOut`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.cacheHit`)}),(0,Z.jsx)(`th`,{className:i,title:n(`tokens.tpsContext`),children:n(`tokens.tps`)})]})}),(0,Z.jsx)(`tbody`,{children:r.map(([e,t])=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,Z.jsx)(`td`,{className:`${o} font-semibold selectable`,children:a(t.costUsd)}),(0,Z.jsx)(`td`,{className:o,children:u(t.requests)}),(0,Z.jsx)(`td`,{className:o,children:u(t.totalTokens,!0)}),(0,Z.jsxs)(`td`,{className:`${o} text-[var(--text-secondary)]`,children:[u(t.inputTokens,!0),` / `,u(t.outputTokens,!0)]}),(0,Z.jsx)(`td`,{className:o,title:n(`usage.cacheAmounts`,{read:u(t.cacheReadTokens,!0),write:u(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:C(t.cacheHitRate)}),(0,Z.jsx)(`td`,{className:o,children:t.tps==null?`—`:l(t.tps)})]},e))})]})})}function ge(){let{t:e}=m(),t=(x().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function _e({open:e,onOpenChange:t}){let{t:n}=m(),{toast:r}=P(),i=O(),{options:a}=ge(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(``);return(0,X.useEffect)(()=>{e&&(s(``),l(``))},[e]),(0,Z.jsx)(N,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(w,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,Z.jsx)(w,{variant:`primary`,disabled:!o.trim(),loading:i.isPending,onClick:()=>i.mutate({name:o.trim(),providerId:c||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(j(e),`error`)}),children:n(`common.create`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(v,{label:n(`tokens.name`),children:(0,Z.jsx)(h,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>s(e.target.value)})}),(0,Z.jsx)(v,{label:n(`tokens.directProvider`),children:(0,Z.jsx)(F,{value:c,onChange:l,options:a})})]})})}function ve({token:e,onClose:t}){let{t:n}=m(),{toast:r}=P(),i=f(),a=x(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(null),[u,p]=(0,X.useState)([]),[g,_]=(0,X.useState)(null),[y,b]=(0,X.useState)(`any`),[C,T]=(0,X.useState)([]),E=new Set(u.map(e=>`${e.metric}:${e.period}`)).size<u.length,D=new Map((e?.pool?.members??[]).map(e=>[e.providerId,e.health]));return(0,X.useEffect)(()=>{e&&(s(e.name),l(K(e)),p(e.limits?.budgets.map(e=>({...e}))??[]),_(e.limits?.rpm??null),b(e.allowedClients==null?`any`:`only`),T(e.allowedClients??[]))},[e]),(0,Z.jsx)(N,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(w,{onClick:t,children:n(`common.cancel`)}),(0,Z.jsx)(w,{variant:`primary`,disabled:!o.trim()||E,loading:i.isPending,onClick:()=>{if(!e)return;let s=u.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),l=s.length>0||g!=null&&g>0?{budgets:s,rpm:g!=null&&g>0?Math.floor(g):null}:null;i.mutate({id:e.id,name:o.trim(),...c?{pool:W(c,a.data??[])}:{},limits:l,allowedClients:y===`any`?null:C},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(j(e),`error`)})},children:n(`common.save`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(v,{label:n(`tokens.name`),children:(0,Z.jsx)(h,{value:o,maxLength:64,onChange:e=>s(e.target.value)})}),(0,Z.jsx)(v,{label:n(`tokens.pool.title`),hint:n(`tokens.pool.hint`),children:c&&(0,Z.jsx)(q,{draft:c,onChange:l,providers:a.data??[],health:D})}),(0,Z.jsx)(v,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:E?n(`tokens.limitDuplicate`):void 0,children:(0,Z.jsx)(be,{budgets:u,onChange:p})}),(0,Z.jsx)(v,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,Z.jsx)(S,{value:g,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:_})}),(0,Z.jsx)(v,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(d,{ariaLabel:n(`tokens.allowedClients`),value:y,onChange:b,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),y===`only`&&(0,Z.jsx)(V,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(z),...C])].map(e=>({value:e,label:z[e]?.name??e})),value:C,onValueChange:e=>T(e)})]})})]})})}var $=[`cost`,`requests`,`tokens`],ye=[`day`,`week`,`month`,`total`];function be({budgets:e,onChange:t}){let{t:n}=m(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=$.flatMap(e=>ye.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:$.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:ye.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,Z.jsx)(S,{label:n(`tokens.limitValue`),value:i.limit,min:0,step:i.metric===`cost`?`any`:1,placeholder:n(`tokens.limitValue`),onChange:e=>r(a,{limit:e})}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(I,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==a))})]},a)),i&&(0,Z.jsx)(`div`,{children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(U,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{de as TokensPage};
1
+ import{Fa as e,H as t,J as n,Pa as r,Pr as i,Q as a,Ra as o,Sr as s,Tr as c,X as l,Y as u,_ as d,bi as f,c as p,ct as m,d as h,ei as g,gt as _,l as v,ln as y,n as b,or as x,p as S,q as C,r as w,s as T,si as E,t as D,tn as O,v as k,xt as A}from"./alert-BF0mCqUl.js";import{a as j,gt as M,i as N,n as ee,o as P,r as F}from"./overlays-OPtjc9Yr.js";import{t as te}from"./ellipsis-D10W7mYw.js";import{t as ne}from"./pencil-Zf5QNEUX.js";import{t as re}from"./power-B2lC52A0.js";import{t as ie}from"./rotate-ccw-DwTwYkU2.js";import{H as ae,L as oe,N as I,P as se,V as L,X as R,_ as z,h as B,s as V,y as H,z as U}from"./index-CN0EAD0q.js";import{a as ce,i as W,n as G,r as K,t as q}from"./TokenPoolEditor-B_Z5aPHq.js";var J={name:`chart-column`,size:24,node:[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]],aliases:[`bar-chart-3`]};J.node;var le=A(J),Y={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};Y.node;var ue=A(Y),X=o(e(),1),Z=r();function de(){let{t:e}=m(),t=g(),n=i(),r=E(),a=r.data?.state===`connected`?r.data.publicUrl:null,[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null);return(0,Z.jsxs)(B,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,Z.jsx)(w,{variant:`primary`,icon:(0,Z.jsx)(U,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`tokens.add`)}),children:[(0,Z.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[n.data&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${n.data.gatewayBaseUrl}/v1`})}),(0,Z.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:n.data.gatewayBaseUrl})}),a&&(0,Z.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${a}/v1`,key:`${a}/key`})})]}),t.isLoading&&(0,Z.jsx)(k,{lines:4}),t.isError&&(0,Z.jsx)(D,{tone:`danger`,title:e(`common.error`),children:j(t.error)}),t.data?.length===0&&(0,Z.jsx)(`div`,{className:`card`,children:(0,Z.jsx)(p,{icon:(0,Z.jsx)(L,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,Z.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,Z.jsx)(fe,{token:e,defaultOpen:t.data.length===1,onEdit:()=>l(e)},e.id))})]}),(0,Z.jsx)(_e,{open:o,onOpenChange:s}),(0,Z.jsx)(ve,{token:c,onClose:()=>l(null)})]})}function fe({token:e,defaultOpen:r,onEdit:o}){let{t:l,locale:d}=m(),{toast:p,confirm:h}=P(),g=x(),v=i(),S=c(),C=f(),E=s(),D=y(),[O,k]=(0,X.useState)(r),A=(g.data??[]).find(t=>t.id===e.providerId),N=ce(),F=`token-detail-${e.id}`,L=(e,t)=>{p(t,`success`),e.skipped.length>0&&p(l(`tokens.skipped`,{clients:e.skipped.map(e=>z[e]?.name??e).join(`, `)}),`error`)},B=()=>S.mutate(e.id,{onSuccess:async({token:e})=>{await M.copy(e)?p(l(`tokens.copied`)):p(l(`tokens.copyFailed`),`error`)},onError:e=>p(j(e),`error`)}),V=async()=>{let e=v.data?.gatewayBaseUrl;e&&(await M.copy(`${e}/v1`)?p(l(`tokens.urlCopied`)):p(l(`tokens.copyFailed`),`error`))},U=async()=>{let e=v.data?.gatewayBaseUrl;e&&(await M.copy(`npx @aidotnet/astra-connect join ${e}`)?p(l(`tokens.joinCopied`)):p(l(`tokens.copyFailed`),`error`))},W=async()=>{(!e.enabled||await h({title:l(`tokens.disableConfirm`,{name:e.name}),detail:l(`tokens.disableDetail`),confirmLabel:l(`tokens.disable`),destructive:!0}))&&C.mutate({id:e.id,enabled:!e.enabled},{onError:e=>p(j(e),`error`)})},K=async()=>{await h({title:l(`tokens.resetConfirm`,{name:e.name}),detail:l(`tokens.resetDetail`),confirmLabel:l(`tokens.reset`),destructive:!0})&&E.mutate(e.id,{onSuccess:e=>L(e,l(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>p(j(e),`error`)})},q=async()=>{await h({title:l(`tokens.deleteConfirm`,{name:e.name}),detail:l(`tokens.deleteDetail`),confirmLabel:l(`common.delete`),destructive:!0})&&D.mutate(e.id,{onSuccess:t=>L(t,l(`tokens.deleted`,{name:e.name})),onError:e=>p(j(e),`error`)})},J=e.lastUsedAt?t(e.lastUsedAt,d):l(`tokens.neverUsed`);return(0,Z.jsxs)(`article`,{children:[(0,Z.jsxs)(`div`,{className:`flex cursor-pointer flex-wrap items-center gap-x-5 gap-y-2 px-4 py-3 hover:bg-[var(--surface-muted)]`,onClick:()=>k(e=>!e),children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":O,"aria-controls":F,"aria-label":l(`tokens.details`),onClick:e=>{e.stopPropagation(),k(e=>!e)},children:(0,Z.jsx)(ae,{className:`size-4 transition-transform ${O?`rotate-90`:``}`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${e.enabled?``:`text-[var(--text-muted)]`}`,children:e.name}),e.isDefault&&(0,Z.jsx)(b,{tone:`accent`,children:l(`tokens.default`)}),!e.enabled&&(0,Z.jsx)(b,{tone:`orange`,children:l(`tokens.disabledBadge`)}),e.limitUsage.some(e=>e.exhausted)&&(0,Z.jsx)(b,{tone:`orange`,children:l(`tokens.limitExhausted`)}),e.pool&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.pool.members.map(e=>e.providerId).join(`, `),children:[(0,Z.jsx)(b,{children:l(`tokens.pool.summary`,{count:e.pool.members.length,strategy:l(`tokens.strategy.${e.pool.strategy}`)})}),e.pool.members.map(e=>(0,Z.jsx)(T,{tone:G(e.health.state)},e.providerId))]})]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:e.keyMasked}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(_,{className:`size-3.5`}),"aria-label":l(`tokens.copy`),title:l(`tokens.copy`),loading:S.isPending,onClick:B}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(ue,{className:`size-3.5`}),"aria-label":l(`tokens.copyUrl`),title:l(`tokens.copyUrl`),disabled:!v.data,onClick:()=>void V()}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(se,{className:`size-3.5`}),"aria-label":l(`tokens.copyJoin`),title:l(`tokens.copyJoin`),disabled:!v.data,onClick:()=>void U()})]})]})]}),(0,Z.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:e.clients.map(e=>z[e]?.name??e).join(`, `)||l(`tokens.noClients`),children:e.clients.length===0?(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):e.clients.map(e=>(0,Z.jsx)(H,{kind:e,size:16},e))}),(0,Z.jsx)(Q,{label:l(`tokens.today`),value:a(e.today.costUsd),context:l(`tokens.requestsContext`,{count:u(e.today.requests)})}),(0,Z.jsx)(Q,{label:l(`tokens.total`),value:a(e.total.costUsd),context:`${u(e.total.totalTokens,!0)} Token`}),(0,Z.jsx)(Q,{label:l(`tokens.lastUsedTitle`),value:e.lastUsedAt?n(e.lastUsedAt,d):`—`,context:e.lastUsedAt?``:l(`tokens.neverUsed`),title:J}),(0,Z.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(ee,{label:l(`common.more`),icon:(0,Z.jsx)(te,{className:`size-4`}),items:[{id:`settings`,label:l(`tokens.settings`),icon:(0,Z.jsx)(ne,{className:`size-3.5`}),onSelect:o},{id:`toggle`,label:e.enabled?l(`tokens.disable`):l(`tokens.enable`),icon:(0,Z.jsx)(re,{className:`size-3.5`}),onSelect:()=>void W()},{id:`reset`,label:l(`tokens.reset`),icon:(0,Z.jsx)(ie,{className:`size-3.5`}),onSelect:()=>void K()},...e.isDefault?[]:[{id:`delete`,label:l(`tokens.delete`),icon:(0,Z.jsx)(I,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void q()}]]})})]}),O&&(0,Z.jsxs)(`div`,{id:F,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,Z.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:l(`tokens.clients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.clients.length===0?l(`tokens.noClients`):e.clients.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(H,{kind:e,size:14}),z[e]?.name??e]},e))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:e.pool?l(`tokens.pool.title`):l(`tokens.directProvider`)}),e.pool?(0,Z.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.pool.members.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:N(e.health),children:[(0,Z.jsx)(T,{tone:G(e.health.state)}),(g.data??[]).find(t=>t.id===e.providerId)?.name??e.providerId]},e.providerId))}):(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:A?.name??(e.providerId?e.providerId:l(`tokens.directNone`))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:l(`tokens.allowedClients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:e.allowedClients==null?l(`tokens.allowedClientsAny`):e.allowedClients.length===0?l(`tokens.directOnly`):e.allowedClients.map(e=>z[e]?.name??e).join(`, `)})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:l(`tokens.lastUsedTitle`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:J})]})]}),(0,Z.jsx)(pe,{token:e}),(0,Z.jsx)(he,{today:e.today,total:e.total}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,Z.jsx)(R,{to:`/tokens/${encodeURIComponent(e.id)}`,children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(le,{className:`size-3.5`}),children:l(`tokens.detail.open`)})}),(0,Z.jsx)(R,{to:`/requests?token=${encodeURIComponent(e.id)}`,children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(oe,{className:`size-3.5`}),children:l(`tokens.detail.viewLogs`)})})]})]})]})}function pe({token:e}){let{t}=m(),n=e.limits?.rpm;return(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,Z.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,Z.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,Z.jsx)(me,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,Z.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,Z.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function me({usage:e}){let{t:n,locale:r}=m(),i=`${n(`tokens.period.${e.period}`)} · ${n(`tokens.metric.${e.metric}`)}`,o=t=>e.metric===`cost`?a(t):u(t,!0),s=Math.max(0,Math.min(100,Math.round(e.usedPercent))),c=s>=90?`var(--danger)`:s>=70?`var(--warning)`:`var(--accent)`;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,Z.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:i}),(0,Z.jsx)(`span`,{className:`num`,children:n(`tokens.limitUsed`,{used:o(e.used),limit:o(e.limit)})})]}),(0,Z.jsx)(`div`,{role:`progressbar`,"aria-valuenow":s,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${s}%`,background:c}})}),e.resetsAt&&(0,Z.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n(`tokens.limitResets`,{time:t(e.resetsAt,r)})})]})}function Q({label:e,value:t,context:n,title:r}){return(0,Z.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Z.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function he({today:e,total:t}){let{t:n}=m(),r=[[n(`tokens.today`),e],[n(`tokens.total`),t]],i=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,o=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,Z.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,Z.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,Z.jsx)(`th`,{className:`${i} text-left`}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.cost`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.requests`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.tokens`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.inOut`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.cacheHit`)}),(0,Z.jsx)(`th`,{className:i,title:n(`tokens.tpsContext`),children:n(`tokens.tps`)})]})}),(0,Z.jsx)(`tbody`,{children:r.map(([e,t])=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,Z.jsx)(`td`,{className:`${o} font-semibold selectable`,children:a(t.costUsd)}),(0,Z.jsx)(`td`,{className:o,children:u(t.requests)}),(0,Z.jsx)(`td`,{className:o,children:u(t.totalTokens,!0)}),(0,Z.jsxs)(`td`,{className:`${o} text-[var(--text-secondary)]`,children:[u(t.inputTokens,!0),` / `,u(t.outputTokens,!0)]}),(0,Z.jsx)(`td`,{className:o,title:n(`usage.cacheAmounts`,{read:u(t.cacheReadTokens,!0),write:u(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:C(t.cacheHitRate)}),(0,Z.jsx)(`td`,{className:o,children:t.tps==null?`—`:l(t.tps)})]},e))})]})})}function ge(){let{t:e}=m(),t=(x().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function _e({open:e,onOpenChange:t}){let{t:n}=m(),{toast:r}=P(),i=O(),{options:a}=ge(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(``);return(0,X.useEffect)(()=>{e&&(s(``),l(``))},[e]),(0,Z.jsx)(N,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(w,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,Z.jsx)(w,{variant:`primary`,disabled:!o.trim(),loading:i.isPending,onClick:()=>i.mutate({name:o.trim(),providerId:c||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(j(e),`error`)}),children:n(`common.create`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(v,{label:n(`tokens.name`),children:(0,Z.jsx)(h,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>s(e.target.value)})}),(0,Z.jsx)(v,{label:n(`tokens.directProvider`),children:(0,Z.jsx)(F,{value:c,onChange:l,options:a})})]})})}function ve({token:e,onClose:t}){let{t:n}=m(),{toast:r}=P(),i=f(),a=x(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(null),[u,p]=(0,X.useState)([]),[g,_]=(0,X.useState)(null),[y,b]=(0,X.useState)(`any`),[C,T]=(0,X.useState)([]),E=new Set(u.map(e=>`${e.metric}:${e.period}`)).size<u.length,D=new Map((e?.pool?.members??[]).map(e=>[e.providerId,e.health]));return(0,X.useEffect)(()=>{e&&(s(e.name),l(K(e)),p(e.limits?.budgets.map(e=>({...e}))??[]),_(e.limits?.rpm??null),b(e.allowedClients==null?`any`:`only`),T(e.allowedClients??[]))},[e]),(0,Z.jsx)(N,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(w,{onClick:t,children:n(`common.cancel`)}),(0,Z.jsx)(w,{variant:`primary`,disabled:!o.trim()||E,loading:i.isPending,onClick:()=>{if(!e)return;let s=u.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),l=s.length>0||g!=null&&g>0?{budgets:s,rpm:g!=null&&g>0?Math.floor(g):null}:null;i.mutate({id:e.id,name:o.trim(),...c?{pool:W(c,a.data??[])}:{},limits:l,allowedClients:y===`any`?null:C},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(j(e),`error`)})},children:n(`common.save`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(v,{label:n(`tokens.name`),children:(0,Z.jsx)(h,{value:o,maxLength:64,onChange:e=>s(e.target.value)})}),(0,Z.jsx)(v,{label:n(`tokens.pool.title`),hint:n(`tokens.pool.hint`),children:c&&(0,Z.jsx)(q,{draft:c,onChange:l,providers:a.data??[],health:D})}),(0,Z.jsx)(v,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:E?n(`tokens.limitDuplicate`):void 0,children:(0,Z.jsx)(be,{budgets:u,onChange:p})}),(0,Z.jsx)(v,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,Z.jsx)(S,{value:g,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:_})}),(0,Z.jsx)(v,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(d,{ariaLabel:n(`tokens.allowedClients`),value:y,onChange:b,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),y===`only`&&(0,Z.jsx)(V,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(z),...C])].map(e=>({value:e,label:z[e]?.name??e})),value:C,onValueChange:e=>T(e)})]})})]})})}var $=[`cost`,`requests`,`tokens`],ye=[`day`,`week`,`month`,`total`];function be({budgets:e,onChange:t}){let{t:n}=m(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=$.flatMap(e=>ye.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:$.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:ye.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,Z.jsx)(S,{label:n(`tokens.limitValue`),value:i.limit,min:0,step:i.metric===`cost`?`any`:1,placeholder:n(`tokens.limitValue`),onChange:e=>r(a,{limit:e})}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(I,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==a))})]},a)),i&&(0,Z.jsx)(`div`,{children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(U,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{de as TokensPage};