omnigateway 0.4.13 → 0.5.0

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 (47) hide show
  1. package/README.md +52 -1
  2. package/bin/omni.js +176 -72
  3. package/gateway.js +1145 -126
  4. package/package.json +1 -1
  5. package/public/assets/{CopyValue-C2DkO9Yz.js → CopyValue-dQWAaTxf.js} +3 -3
  6. package/public/assets/{Field-B79Yxdit.js → Field-DTQ2LPzA.js} +1 -1
  7. package/public/assets/{Match-BWa6L0L1.js → Match-C85GObiU.js} +1 -1
  8. package/public/assets/{Panel-CoulMx6R.js → Panel-CQVz9yeR.js} +2 -2
  9. package/public/assets/Rack-V32CHmN6.js +316 -0
  10. package/public/assets/{Readout-D1XEfywe.js → Readout-DJR1qKja.js} +1 -1
  11. package/public/assets/States-CauIsA0N.js +54 -0
  12. package/public/assets/{Toggle-CRrH9nDt.js → Toggle-BQI8jz09.js} +1 -1
  13. package/public/assets/{TokenBreakdown-C2NsJnqO.js → TokenBreakdown-B2_gfuqt.js} +1 -1
  14. package/public/assets/_app-DzzXdoyU.js +1 -0
  15. package/public/assets/_app.accounts-owsnxlbn.js +64 -0
  16. package/public/assets/_app.console-bzKNP_8Y.js +44 -0
  17. package/public/assets/_app.database-CsJbkedE.js +24 -0
  18. package/public/assets/_app.index-D4ydl2mY.js +62 -0
  19. package/public/assets/_app.keys-DKX0smty.js +82 -0
  20. package/public/assets/_app.logs-CFFsj2zR.js +68 -0
  21. package/public/assets/_app.models-B0ZxWGHV.js +148 -0
  22. package/public/assets/{_app.plugins._pluginId-BOXRBToU.js → _app.plugins._pluginId-C5X4B1cE.js} +3 -3
  23. package/public/assets/{_app.settings-DoaOUmc1.js → _app.settings-Yg_6az-L.js} +4 -4
  24. package/public/assets/_app.usage-BRIz_GCn.js +83 -0
  25. package/public/assets/index-DiCU8bLB.js +178 -0
  26. package/public/assets/{login-B9CJqU--.js → login-B4LoiALI.js} +3 -3
  27. package/public/assets/plus-xu9reaJp.js +1 -0
  28. package/public/assets/queries-DuSqKybM.js +145 -0
  29. package/public/assets/{shared-Cct_4xwp.js → shared-DYkFSPbd.js} +4 -4
  30. package/public/assets/stream-Dz5HjHBh.js +1 -0
  31. package/public/assets/{trash-2-DwMK-JrZ.js → trash-2-DbutVvFY.js} +1 -1
  32. package/public/index.html +3 -3
  33. package/public/shared/dashboard-sdk.js +1 -1
  34. package/public/assets/Rack-HM36SprU.js +0 -314
  35. package/public/assets/States-DtkkMzEu.js +0 -54
  36. package/public/assets/_app-DVpIsUid.js +0 -1
  37. package/public/assets/_app.accounts-64d_cxir.js +0 -64
  38. package/public/assets/_app.console-BBuBmLRI.js +0 -44
  39. package/public/assets/_app.database-J9Ujio8l.js +0 -24
  40. package/public/assets/_app.index-BX4yKEXO.js +0 -62
  41. package/public/assets/_app.keys-2sKwhZJc.js +0 -76
  42. package/public/assets/_app.logs-DuHXYrZU.js +0 -68
  43. package/public/assets/_app.models-B0kTfPtn.js +0 -148
  44. package/public/assets/_app.usage-B5sxB40E.js +0 -83
  45. package/public/assets/index-iCfSaRSG.js +0 -178
  46. package/public/assets/plus-DKapAGoR.js +0 -1
  47. package/public/assets/queries-CX9mStps.js +0 -145
@@ -1,24 +0,0 @@
1
- import{$ as e,H as t,I as n,K as r,N as i,Q as a,S as o,_ as s,a as c,at as l,b as u,lt as d,m as f,nt as p,ot as m,rt as h}from"./queries-CX9mStps.js";import{g,o as _,t as v}from"./Rack-HM36SprU.js";import{A as y,O as b,i as x,j as S,n as C,r as w,t as T,w as E}from"./States-DtkkMzEu.js";import{r as D,t as O}from"./Field-B79Yxdit.js";import{t as k}from"./Meter-stpt3vQu.js";import{t as A}from"./Panel-CoulMx6R.js";import{i as j,n as M,r as N,t as P}from"./Table-CVDZ69Zx.js";import{t as F}from"./Readout-D1XEfywe.js";import{n as I}from"./reasons-Cb8yF4Oy.js";import{useQueryClient as L}from"@tanstack/react-query";import{useCallback as R,useState as z}from"react";import{Fragment as B,jsx as V,jsxs as H}from"react/jsx-runtime";import U from"styled-components";var W=g(`camera`,[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]),G=g(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),K=[{id:`keepLatest`,label:`Snapshots kept`,hint:`How many survive regardless of age. The newest is always kept, whatever both numbers say.`,unit:`files`,max:100},{id:`maxAgeDays`,label:`Maximum age`,hint:`Older snapshots are pruned after every new one and on the hourly maintenance sweep.`,unit:`days`,max:3650}],q=U.p`
2
- font-size: 12px;
3
- color: ${({theme:e})=>e.color.down};
4
- `,J=U.p`
5
- font-size: 12px;
6
- color: ${({theme:e})=>e.color.ok};
7
- `,Y=U.div`
8
- display: grid;
9
- grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
10
- gap: ${({theme:e})=>e.space(3)};
11
- `;function X(e){let t={};for(let n of K){let r=e[n.id].trim(),i=Number(r);if(r.length===0||!Number.isInteger(i)||i<1)return{ok:!1,problem:`${n.label} must be a whole number of 1 or more.`};if(i>n.max)return{ok:!1,problem:`${n.label} cannot exceed ${n.max}.`};t[n.id]=i}return{ok:!0,policy:t}}function Z({retention:t}){let r=n(),[i,a]=z({}),[o,s]=z(null),[c,u]=z(!1),f={keepLatest:i.keepLatest??(t===void 0?``:String(t.keepLatest)),maxAgeDays:i.maxAgeDays??(t===void 0?``:String(t.maxAgeDays))};return V(A,{legend:`Retention`,actions:V(d,{type:`button`,$size:`sm`,disabled:r.isPending||t===void 0,onClick:()=>{u(!1);let e=X(f);if(!e.ok){s(e.problem);return}s(null),r.mutate(e.policy,{onSuccess:()=>{u(!0),a({})},onError:e=>s(x(e))})},children:r.isPending?`Saving…`:`Save retention`}),children:H(l,{$gap:3,children:[V(Y,{children:K.map(t=>V(O,{label:t.label,hint:t.hint,children:n=>H(p,{$gap:2,children:[V(D,{...n,min:1,max:t.max,step:1,value:f[t.id],onChange:e=>a({...i,[t.id]:e.target.value})}),V(e,{children:t.unit})]})},t.id))}),o===null?null:V(q,{role:`alert`,children:o}),c&&o===null?V(J,{role:`status`,children:`Retention saved.`}):null]})})}function Q(){let e=L();return R(t=>{if(t.adminPasswordChanged){I(`admin-password-changed`);return}e.invalidateQueries()},[e])}var $=U.p`
12
- font-size: 12px;
13
- color: ${({theme:e})=>e.color.down};
14
- `,ee=U.input`
15
- font-size: 12px;
16
- color: ${({theme:e})=>e.color.inkDim};
17
- max-width: 40ch;
18
- `;function te(){let e=t(),n=f(),r=i(),a=Q(),s=u(),g=o(),[v,y]=z(null),[S,D]=z(null),[k,F]=z(null),[I,L]=z(!1),R=e.data??[],B=H(d,{type:`button`,$variant:`primary`,$size:`sm`,disabled:n.isPending,onClick:()=>n.mutate(),children:[V(W,{}),n.isPending?`Copying…`:`Take a snapshot`]}),U=H(l,{$gap:2,children:[H(p,{$gap:2,$wrap:!0,children:[V(O,{label:`Database file to import`,hint:`A snapshot taken from this or another OmniGateway. It is checked for integrity and rejected if it is not one of ours.`,children:e=>V(ee,{...e,type:`file`,accept:`.sqlite,.db,application/octet-stream`,onChange:e=>F(e.target.files?.[0]??null)})}),V(d,{type:`button`,$variant:`danger`,$size:`sm`,disabled:k===null||g.isPending,onClick:()=>L(!0),children:g.isPending?`Replacing…`:`Import`})]}),g.isError?V($,{role:`alert`,children:x(g.error)}):null,r.isError?V($,{role:`alert`,children:x(r.error)}):null,n.isError?V($,{role:`alert`,children:x(n.error)}):null]});return H(A,{legend:`Snapshots`,meta:`${R.length}`,actions:B,footer:U,flush:!0,children:[e.isError?V(C,{error:e.error,onRetry:()=>void e.refetch()}):e.isLoading?V(`div`,{style:{padding:12},children:V(w,{rows:3})}):R.length===0?V(T,{legend:`No snapshots`,message:`Nothing has been copied yet, so there is nothing to go back to. Take one before a migration or a settings change you are unsure of.`,action:V(d,{type:`button`,$variant:`primary`,$size:`sm`,disabled:n.isPending,onClick:()=>n.mutate(),children:`Take the first snapshot`})}):V(h,{children:H(P,{children:[V(`thead`,{children:H(`tr`,{children:[V(N,{children:`File`}),V(N,{children:`Reason`}),V(N,{$align:`right`,children:`Size`}),V(N,{$align:`right`,children:`Taken`}),V(N,{})]})}),V(`tbody`,{children:R.map(e=>H(j,{children:[V(M,{$mono:!0,children:V(m,{style:{maxWidth:`38ch`,display:`block`},children:e.filename})}),V(M,{children:e.reason}),V(M,{$align:`right`,$mono:!0,children:E(e.sizeBytes)}),V(M,{$align:`right`,$mono:!0,children:b(e.createdAt)}),V(M,{$align:`right`,children:H(p,{$gap:1,$justify:`flex-end`,children:[V(d,{as:`a`,$size:`sm`,href:c(e.id),download:e.filename,children:`Download`}),V(d,{type:`button`,$variant:`danger`,$size:`sm`,onClick:()=>y(e),children:`Restore`}),V(d,{type:`button`,$variant:`danger`,$size:`sm`,onClick:()=>D(e),children:`Delete`})]})})]},e.id))})]})}),V(_,{open:v!==null,onOpenChange:e=>{e||y(null)},title:`Restore database`,body:v===null?``:`Replacing the live database with ${v.filename}. Client requests are refused while the file is swapped, and a copy of the current database is taken first so this can be undone. Captured request bodies are not part of a snapshot and are left where they are.`,confirmLabel:`Restore database`,busy:r.isPending,onConfirm:()=>{v!==null&&r.mutate(v.id,{onSuccess:a,onSettled:()=>y(null)})}}),V(_,{open:S!==null,onOpenChange:e=>{e||D(null)},title:`Delete snapshot`,body:S===null?``:`Deleting ${S.filename} from disk. Download it first if it is the copy you would go back to; there is no other one of it.`,confirmLabel:`Delete snapshot`,busy:s.isPending,onConfirm:()=>{S!==null&&s.mutate(S.id,{onSettled:()=>D(null)})}}),V(_,{open:I,onOpenChange:L,title:`Import database`,body:k===null?``:`Replacing the live database with ${k.name}. It is validated before anything is touched, and a copy of the current database is taken first. If the file carries a different admin password, every session ends and you will be asked to sign in again.`,confirmLabel:`Replace database`,busy:g.isPending,onConfirm:()=>{k!==null&&g.mutate(k,{onSuccess:a,onSettled:()=>L(!1)})}})]})}var ne=U.p`
19
- font-size: 12px;
20
- color: ${({theme:e})=>e.color.ok};
21
- `,re=U.p`
22
- font-size: 12px;
23
- color: ${({theme:e})=>e.color.down};
24
- `;function ie(){let e=s(),t=r(),[n,i]=z(!1),o=e.data,c=o===void 0||o.logicalBytes===0?0:o.freePageBytes/o.logicalBytes;return H(B,{children:[V(v,{legend:`Database`,title:`Storage, snapshots, and retention`,summary:e.isLoading?`Measuring the database…`:`The one SQLite file this gateway runs from, the copies taken of it, and how long they are kept.`}),V(A,{legend:`Size`,meta:o===void 0?void 0:`schema v${o.stats.schemaVersion}`,actions:H(d,{type:`button`,$size:`sm`,disabled:t.isPending||o===void 0,onClick:()=>i(!0),children:[V(G,{}),t.isPending?`Compacting…`:`Compact`]}),footer:t.isError?V(re,{role:`alert`,children:x(t.error)}):t.data===void 0?void 0:V(ne,{role:`status`,children:`Compacted, reclaiming ${E(t.data.reclaimedBytes)} in ${y(t.data.durationMs)}.`}),children:e.isError?V(C,{error:e.error,onRetry:()=>void e.refetch()}):o===void 0?V(w,{rows:3}):H(a,{$min:`180px`,$stretch:!0,children:[V(F,{legend:`Database file`,value:E(o.fileBytes),unit:`${o.stats.pageCount} pages of ${E(o.stats.pageSize)}`,trace:V(k,{fraction:c,label:`${S(c,0)} of the file is reclaimable`})}),V(F,{legend:`Reclaimable`,value:E(o.freePageBytes),unit:`${o.stats.freelistCount} free pages`}),V(F,{legend:`Write-ahead log`,value:E(o.walBytes),unit:`folded into every snapshot`}),V(F,{legend:`Captured bodies`,value:E(o.bodiesBytes),unit:`never in a snapshot`}),V(F,{legend:`Snapshots`,value:E(o.snapshots.totalBytes),unit:`${o.snapshots.count} kept`}),V(F,{legend:`Free disk`,value:E(o.freeDiskBytes),unit:o.freeDiskBytes===null?`not readable here`:`on this filesystem`})]})}),V(te,{}),V(Z,{retention:o?.retention}),V(_,{open:n,onOpenChange:i,title:`Compact database`,body:`Running VACUUM rewrites the database to give back its free pages. It holds the write lock for as long as it takes, so requests in flight will wait, and it needs room on disk for a second copy while it runs.`,confirmLabel:`Compact database`,busy:t.isPending,onConfirm:()=>t.mutate(void 0,{onSettled:()=>i(!1)})})]})}var ae=ie;export{ae as component};
@@ -1,62 +0,0 @@
1
- import{$ as e,D as t,G as n,O as r,Q as i,at as a,dt as o,et as s,g as c,h as l,it as u,lt as d,nt as f,ot as p,rt as m,z as h}from"./queries-CX9mStps.js";import{a as g,r as _,t as ee}from"./Rack-HM36SprU.js";import{n as v,t as y}from"./TokenBreakdown-C2NsJnqO.js";import{A as b,D as x,E as S,M as C,N as w,a as T,b as te,d as E,g as D,h as O,j as k,l as A,n as j,o as M,p as N,s as P,t as F,u as I,v as ne,x as re}from"./States-DtkkMzEu.js";import{n as L,t as R}from"./Chip-BltJSw8A.js";import{t as z}from"./Meter-stpt3vQu.js";import{t as B}from"./Panel-CoulMx6R.js";import{i as V,n as H,r as U,t as W}from"./Table-CVDZ69Zx.js";import{t as G}from"./Readout-D1XEfywe.js";import{Fragment as K,jsx as q,jsxs as J}from"react/jsx-runtime";import Y from"styled-components";var X=Y(p)`
2
- font-weight: 500;
3
- display: block;
4
- max-width: 24ch;
5
- `,Z=Y.span`
6
- font-size: 11px;
7
- color: ${({theme:e})=>e.color.inkDim};
8
- `,ie=Y.div`
9
- display: grid;
10
- grid-template-columns: 72px 1fr;
11
- align-items: center;
12
- gap: 6px;
13
- min-width: 172px;
14
- `,ae=Y.div`
15
- display: flex;
16
- flex-direction: column;
17
- gap: 4px;
18
- `;function oe(e){let t=null;for(let n of e)n.stale||n.survives!==!1||n.exhaustsAt===null||(t===null||n.exhaustsAt<t)&&(t=n.exhaustsAt);return t}function se(e,t){return e===null?t===null?0:1:t===null?-1:e-t}function ce({credentials:t,health:n,quota:r,burn:i,usage:a,quotaPollIntervalMs:s,now:c}){let l=E(n,e=>e.credentialId),u=E(r,e=>e.credentialId),p=E(i,e=>e.credentialId),h=new Map(a.map(e=>[e.key,e])),g={down:0,warn:1,ok:2,idle:3,live:3},_=t.map(e=>{let t=p.get(e.id)??[];return{credential:e,status:I(l.get(e.id)??[],c,e.enabled,e.disabledReason),quota:te(u.get(e.id)??[]),burn:t,exhaustsAt:oe(t),usage:h.get(e.id)}}).sort((e,t)=>g[e.status.state]-g[t.status.state]||se(e.exhaustsAt,t.exhaustsAt)||e.credential.tier-t.credential.tier);return q(B,{legend:`Accounts`,meta:`${t.length} connected`,flush:!0,actions:q(d,{as:o,to:`/accounts`,$size:`sm`,children:`Manage accounts`}),children:t.length===0?q(F,{legend:`No accounts`,message:`The gateway has no provider credentials, so every request will fail. Connect one to start routing.`,action:q(d,{as:o,to:`/accounts`,$variant:`primary`,$size:`sm`,children:`Connect an account`})}):q(m,{children:J(W,{children:[q(`thead`,{children:J(`tr`,{children:[q(U,{children:`Account`}),q(U,{children:`Provider`}),q(U,{$align:`right`,children:`Tier`}),q(U,{children:`Quota`}),q(U,{$align:`right`,children:`TTFT`}),q(U,{$align:`right`,children:`Requests`}),q(U,{$align:`right`,children:`Last used`})]})}),q(`tbody`,{children:_.map(({credential:t,status:n,quota:r,burn:i,usage:a})=>J(V,{children:[q(H,{children:J(f,{$gap:2,children:[q(T,{state:n.state,label:n.note===``?`healthy`:n.note}),J(`div`,{children:[q(X,{children:t.label}),n.note===``?null:q(Z,{children:n.note})]})]})}),q(H,{children:q(L,{provider:t.provider})}),q(H,{$align:`right`,$mono:!0,children:t.tier}),q(H,{children:r.length===0?q(Z,{children:`unknown`}):q(ae,{children:r.map(({window:t,fraction:n})=>J(ie,{children:[q(z,{fraction:n,label:`${M[t.windowType]} window, ${Math.round(n*100)}% used`}),q(e,{children:ne(t,c,s,C,A(i,t.windowType))})]},t.windowType))})}),q(H,{$align:`right`,$mono:!0,children:b(n.ttftMs)}),q(H,{$align:`right`,$mono:!0,children:a===void 0?`—`:x(a.requests)}),q(H,{$align:`right`,$mono:!0,children:C(n.lastUsedAt,c)})]},t.id))})]})})})}var le=Y.ul`
19
- display: flex;
20
- flex-direction: column;
21
- `,ue=Y.li`
22
- display: flex;
23
- align-items: center;
24
- gap: ${({theme:e})=>e.space(2)};
25
- padding: 6px ${({theme:e})=>e.space(3)};
26
- border-bottom: 1px solid ${({theme:e})=>e.color.rule};
27
-
28
- &:last-child {
29
- border-bottom: 0;
30
- }
31
- `,de=Y(p)`
32
- font-family: ${({theme:e})=>e.font.mono};
33
- font-size: 12px;
34
- max-width: 30ch;
35
- `,fe=Y(s)`
36
- color: ${({theme:e})=>e.color.down};
37
- font-size: 11px;
38
- `;function pe({logs:e}){let t=e.slice(0,12);return q(B,{legend:`Activity`,meta:`most recent first`,flush:!0,actions:q(d,{as:o,to:`/logs`,$size:`sm`,children:`Open logs`}),children:t.length===0?q(F,{legend:`No traffic yet`,message:`Point a client at this gateway with an API key and the requests will appear here.`}):q(le,{children:t.map(e=>J(ue,{children:[q(T,{state:D(e),label:O(e)}),q(s,{$dim:!0,children:S(e.at)}),q(de,{title:e.requestedModel,children:e.requestedModel||`—`}),e.resolvedProvider===null?null:q(s,{$dim:!0,style:{color:`var(--p-${e.resolvedProvider})`},children:e.resolvedProvider}),q(u,{}),N(e)?q(s,{$dim:!0,"aria-label":`processing`,children:q(y,{})}):J(K,{children:[e.errorCode===null?null:q(fe,{children:e.errorCode}),e.attempts>1?J(s,{$dim:!0,children:[e.attempts,`×`]}):null,q(s,{$dim:!0,children:q(v,{tokens:e})}),q(s,{$dim:!0,children:b(e.durationMs)}),q(s,{$dim:!0,children:w(e.costUsd)})]})]},e.id))})})}var me=Y.ul`
39
- display: flex;
40
- flex-direction: column;
41
- gap: ${({theme:e})=>e.space(3)};
42
- `,Q=Y(p)`
43
- font-family: ${({theme:e})=>e.font.mono};
44
- font-size: 12.5px;
45
- `,he=Y.div`
46
- display: flex;
47
- height: 5px;
48
- border-radius: 2px;
49
- overflow: hidden;
50
- background: ${({theme:e})=>e.color.panelSunk};
51
- border: 1px solid ${({theme:e})=>e.color.rule};
52
- `,ge=Y.div`
53
- flex: ${({$grow:e})=>e} 0 0;
54
- background: ${({$color:e})=>e};
55
- opacity: 0.8;
56
- `,_e=Y.div`
57
- flex: ${({$grow:e})=>e} 0 0;
58
- `;function ve({models:t,logs:n}){let r=new Map;for(let e of n){let t=r.get(e.requestedModel)??{requests:0,costUsd:0};t.requests+=1,t.costUsd+=e.costUsd,r.set(e.requestedModel,t)}let i=Math.max(1,...[...r.values()].map(e=>e.requests)),a=[...t].map(e=>({model:e,used:r.get(e.id)})).sort((e,t)=>(t.used?.requests??0)-(e.used?.requests??0)).slice(0,8);return q(B,{legend:`Models`,meta:`${t.length} configured`,actions:q(d,{as:o,to:`/models`,$size:`sm`,children:`Edit routing`}),children:t.length===0?q(F,{legend:`No models`,message:`Nothing is routable yet. Create a virtual model and point it at one or more provider targets.`,action:q(d,{as:o,to:`/models`,$variant:`primary`,$size:`sm`,children:`Create a model`})}):q(me,{children:a.map(({model:t,used:n})=>{let r=(n?.requests??0)/i,a=[...new Set(t.targets.map(e=>e.provider))];return J(`li`,{children:[J(f,{$gap:2,children:[q(Q,{title:t.id,children:t.id}),t.isAlias?q(R,{children:`alias`}):null,q(R,{$tone:`accent`,children:t.strategy}),q(u,{}),q(s,{$dim:!0,children:x(n?.requests??0)}),q(e,{children:`req`}),q(s,{$dim:!0,children:w(n?.costUsd??0)})]}),J(he,{style:{marginTop:6},title:`${Math.round(r*100)}% of the busiest model`,children:[a.map(e=>q(ge,{$color:`var(--p-${e})`,$grow:r/a.length},e)),q(_e,{$grow:Math.max(0,1-r)})]})]},t.id)})})})}var ye=Y.div`
59
- display: grid;
60
- grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
61
- gap: ${({theme:e})=>e.space(3)};
62
- `;function be({logs:e,windowMs:t,now:n}){let r=e.filter(e=>n-e.at<=t),i=re(r,t),a=P(r,{now:n,spanMs:t,count:32}),o=i.errorRate>=.25?`down`:i.errorRate>=.05?`warn`:`ok`,s=i.inputTokens+i.outputTokens+i.cacheReadTokens+i.cacheWriteTokens;return J(ye,{children:[q(G,{legend:`Requests`,value:x(i.requests),unit:`${i.ratePerMin.toFixed(1)}/min`,trace:q(_,{values:a.map(e=>e.total),overlay:a.map(e=>e.errors),label:`${i.requests} requests, ${i.errors} of them failed`})}),q(G,{legend:`Error rate`,value:k(i.errorRate),unit:`${x(i.errors)} failed`,tone:i.requests===0?`ink`:o,trace:q(_,{values:a.map(e=>e.errors),scaleTo:Math.max(...a.map(e=>e.total)),color:`var(--down)`,label:`${i.errors} failed requests against ${i.requests} total`})}),q(G,{legend:`Total tokens`,value:x(s),unit:q(v,{tokens:i}),trace:q(_,{values:a.map(e=>e.tokens),label:`token volume over the window, ${s.toLocaleString(`en-US`)} total`})}),q(G,{legend:`Time to first token`,value:b(i.ttftP50),unit:`p95 ${b(i.ttftP95)}`,trace:q(_,{values:a.map(e=>e.ttftMs??0),color:`var(--ok)`,label:`median first-token latency, currently ${b(i.ttftP50)}`})}),q(G,{legend:`Spend`,value:w(i.costUsd),unit:`${x(i.inputTokens+i.outputTokens)} tokens`,trace:q(_,{values:a.map(e=>e.costUsd),color:`var(--warn)`,label:`spend over the window, ${w(i.costUsd)} total`})})]})}var $=36e5;function xe(){let{cadence:e}=g(),o=c(),s=l(e(1e4)),u=r(),d=t(500,e(1e4)),f=h(),p=Date.now(),m=Math.floor((p-$)/6e4)*6e4,_=n({groupBy:`credential`,since:m},e(6e4)),v=o.data??[],y=E(s.data?.health??[],e=>e.credentialId),b=v.filter(e=>I(y.get(e.id)??[],p,e.enabled,e.disabledReason).state===`down`),x=o.isLoading||d.isLoading?`Reading the gateway…`:v.length===0?`No accounts are connected, so every request fails at the router.`:b.length>0?`${b.length} account${b.length===1?` is`:`s are`} out of rotation.`:`All ${v.length} accounts are answering. Nothing needs attention.`;return J(K,{children:[q(ee,{legend:`Rack`,title:`Gateway`,summary:x}),d.isError?q(B,{legend:`Traffic`,children:q(j,{legend:`The gateway did not answer`,error:d.error,onRetry:()=>void d.refetch()})}):J(a,{$gap:4,children:[q(be,{logs:d.data??[],windowMs:$,now:p}),q(ce,{credentials:v,health:s.data?.health??[],quota:s.data?.quota??[],burn:s.data?.burn??[],usage:_.data??[],quotaPollIntervalMs:f.data?.quotaPollIntervalMs??3e5,now:p}),J(i,{$min:`340px`,$gap:4,children:[q(ve,{models:u.data??[],logs:d.data??[]}),q(pe,{logs:d.data??[]})]})]})]})}var Se=xe;export{Se as component};
@@ -1,76 +0,0 @@
1
- import{$ as e,C as t,O as n,P as r,R as i,at as a,et as o,lt as s,nt as c,ot as l,p as u,rt as d,ut as f}from"./queries-CX9mStps.js";import{m as p,o as m,s as h,t as g}from"./Rack-HM36SprU.js";import{n as _,r as v,t as y}from"./CopyValue-C2DkO9Yz.js";import{t as b}from"./plus-DKapAGoR.js";import{t as x}from"./Toggle-CRrH9nDt.js";import{O as S,i as C,n as w,r as T,t as E}from"./States-DtkkMzEu.js";import{t as D}from"./Chip-BltJSw8A.js";import{n as O,r as k,t as A}from"./Field-B79Yxdit.js";import{t as j}from"./Meter-stpt3vQu.js";import{t as M}from"./Panel-CoulMx6R.js";import{i as N,n as P,r as F,t as I}from"./Table-CVDZ69Zx.js";import{Fragment as L,useState as R}from"react";import{Fragment as z,jsx as B,jsxs as V}from"react/jsx-runtime";import H from"styled-components";var U=[{dimension:`requests`,window:`1m`},{dimension:`requests`,window:`5h`},{dimension:`requests`,window:`1w`},{dimension:`tokens`,window:`1m`},{dimension:`tokens`,window:`5h`},{dimension:`tokens`,window:`1w`},{dimension:`spend`,window:`5h`},{dimension:`spend`,window:`1w`},{dimension:`concurrency`,window:null}];function W(e){return e.window===null?e.dimension:`${e.dimension}:${e.window}`}var G={requests:`Requests`,tokens:`Tokens`,spend:`Spend`,concurrency:`Concurrent`},ee={"1m":`per minute`,"5h":`per 5 hours`,"1w":`per week`};function K(e){let t=G[e.dimension];return e.window===null?t:`${t} ${ee[e.window]}`}function q(e,t){return e===`spend`?`$${t<1?t.toFixed(4):t.toFixed(2)}`:t.toLocaleString(`en-US`)}function J(e){return e.used===null||e.limit<=0?null:Math.max(0,e.used/e.limit)}function te(e){let t=null,n=-1;for(let r of e){let e=J(r);e!==null&&e>n&&(t=r,n=e)}return t}function Y(e){let t={};for(let e of U)t[W(e)]=``;if(e===null)return t;for(let n of U){let r=n.window===null?e.concurrency:n.dimension===`requests`?e.requests?.[n.window]:n.dimension===`tokens`?e.tokens?.[n.window]:n.window===`1m`?void 0:e.spend?.[n.window];r!=null&&(t[W(n)]=String(r))}return t}function X(e){let t={},n={},r={},i;for(let a of U){let o=(e[W(a)]??``).trim();if(o.length===0)continue;let s=Number(o),c=a.dimension===`spend`;if(!Number.isFinite(s)||s<=0||!c&&!Number.isInteger(s))return{problem:c?`${K(a)} must be an amount above zero, or blank for no limit.`:`${K(a)} must be a whole number above zero, or blank for no limit.`};a.window===null?i=s:a.dimension===`requests`?t[a.window]=s:a.dimension===`tokens`?n[a.window]=s:a.window!==`1m`&&(r[a.window]=s)}return{limits:{...Object.keys(t).length>0?{requests:t}:{},...Object.keys(n).length>0?{tokens:n}:{},...Object.keys(r).length>0?{spend:r}:{},...i===void 0?{}:{concurrency:i}}}}var Z=H.div`
2
- display: grid;
3
- grid-template-columns: repeat(3, minmax(0, 1fr));
4
- gap: ${({theme:e})=>e.space(2)};
5
- `,ne=H.p`
6
- font-size: 11px;
7
- color: ${({theme:e})=>e.color.inkDim};
8
- `;function Q({draft:e,onChange:t,disabled:n=!1}){return V(a,{$gap:2,children:[B(Z,{children:U.map(r=>{let i=W(r);return B(A,{label:K(r),children:a=>B(k,{...a,min:r.dimension===`spend`?void 0:1,step:r.dimension===`spend`?`any`:1,disabled:n,value:e[i]??``,placeholder:`none`,onChange:n=>t({...e,[i]:n.target.value})})},i)})}),B(ne,{children:`Blank means no limit. Token and spend ceilings are debited after a response completes, so a key at its ceiling is refused on its next request rather than its current one. Concurrency counts requests in flight right now and resets when the gateway restarts.`})]})}var re=H.p`
9
- font-size: 12px;
10
- color: ${({theme:e})=>e.color.down};
11
- `,ie=H.p`
12
- font-size: 12px;
13
- color: ${({theme:e})=>e.color.warn};
14
- `;function ae({apiKey:e,onOpenChange:t}){let n=i(),[r,o]=R(()=>Y(e?.limits??{})),[c,l]=R(null);return B(h,{open:e!==null,onOpenChange:t,title:`Edit limits`,description:e===null?void 0:`What "${e.label}" may do per minute, per five hours, and per week. Every field is a ceiling; blank is no limit.`,width:`640px`,footer:V(z,{children:[B(s,{type:`button`,onClick:()=>t(!1),children:`Cancel`}),B(s,{type:`button`,$variant:`primary`,disabled:n.isPending,onClick:()=>{if(e===null)return;let i=X(r);if(`problem`in i){l(i.problem);return}l(null),n.mutate({id:e.id,limits:i.limits},{onSuccess:()=>t(!1),onError:e=>l(C(e))})},children:n.isPending?`Saving…`:`Save limits`})]}),children:V(a,{$gap:3,children:[e?.limits===null?B(ie,{role:`status`,children:`The stored limits for this key cannot be read, so the gateway refuses it. Saving here replaces them.`}):null,B(Q,{draft:r,onChange:o,disabled:n.isPending}),c===null?null:B(re,{role:`alert`,children:c})]})})}var oe=H.div`
15
- display: grid;
16
- grid-template-columns: minmax(0, 11rem) minmax(0, 12rem) minmax(0, 1fr) minmax(0, 3.5rem);
17
- align-items: center;
18
- gap: ${({theme:e})=>e.space(2)} ${({theme:e})=>e.space(4)};
19
- `,se=H.span`
20
- font-size: 11.5px;
21
- color: ${({theme:e})=>e.color.inkDim};
22
- `,ce=H.p`
23
- font-size: 11px;
24
- color: ${({theme:e})=>e.color.inkDim};
25
- `;function le({label:t,readings:n}){return V(a,{$gap:3,children:[B(oe,{children:n.map(n=>{let r=K({dimension:n.dimension,window:n.window}),i=J(n),a=q(n.dimension,n.limit);return V(L,{children:[B(e,{as:`span`,children:r}),B(o,{children:n.used===null?a:`${q(n.dimension,n.used)} of ${a}`}),i===null?B(se,{children:`in flight now, counted in the gateway process`}):B(j,{fraction:Math.min(1,i),label:`${t}, ${r}, ${Math.round(i*100)}% used`}),B(o,{children:i===null?`—`:`${Math.round(i*100)}%`})]},r)})}),B(ce,{children:`Usage counts completed requests still inside each window. Requests in flight are added by the gateway itself and are not shown here.`})]})}var ue=H.div`
26
- display: flex;
27
- flex-direction: column;
28
- gap: 2px;
29
- max-height: 190px;
30
- overflow-y: auto;
31
- padding: ${({theme:e})=>e.space(1)};
32
- border: 1px solid ${({theme:e})=>e.color.ruleStrong};
33
- border-radius: ${({theme:e})=>e.radius.control};
34
- background: ${({theme:e})=>e.color.panelSunk};
35
- `,de=H.label`
36
- display: flex;
37
- align-items: center;
38
- gap: ${({theme:e})=>e.space(2)};
39
- padding: 4px 6px;
40
- border-radius: 2px;
41
- cursor: pointer;
42
- font-family: ${({theme:e})=>e.font.mono};
43
- font-size: 12px;
44
-
45
- &:hover {
46
- background: ${({theme:e})=>e.color.panelRaised};
47
- }
48
- `,fe=H.p`
49
- font-size: 12px;
50
- color: ${({theme:e})=>e.color.warn};
51
- `,pe=H.p`
52
- font-size: 12px;
53
- color: ${({theme:e})=>e.color.down};
54
- `,me=H.p`
55
- font-size: 12px;
56
- color: ${({theme:e})=>e.color.inkDim};
57
- `,he=H(s)`
58
- gap: 4px;
59
- `,ge=H.p`
60
- font-size: 11px;
61
- color: ${({theme:e})=>e.color.inkDim};
62
- `;function _e({open:t,onOpenChange:r}){let i=n(),l=u(),[d,f]=R(``),[p,m]=R(!0),[g,b]=R([]),[S,w]=R(()=>Y({})),[T,E]=R(!1),[D,k]=R(!1),[j,M]=R(null),[N,P]=R(null),F=()=>{f(``),m(!0),b([]),w(Y({})),E(!1),k(!1),M(null),P(null),l.reset()},I=e=>{e||F(),r(e)},L=Object.values(S).filter(e=>e.trim().length>0).length;return B(h,{open:t,onOpenChange:I,title:j===null?`Create an API key`:`Key created`,description:j===null?`Clients send this key as a bearer token or as x-api-key on every /v1 request.`:void 0,footer:j===null?V(z,{children:[B(s,{type:`button`,onClick:()=>I(!1),children:`Cancel`}),B(s,{type:`button`,$variant:`primary`,disabled:l.isPending,onClick:()=>{let e=X(S);if(`problem`in e){E(!0),P(e.problem);return}P(null),l.mutate({label:d.trim().length===0?`api key`:d.trim(),modelAllowlist:p?null:g,limits:e.limits,bodyLoggingOptOut:D},{onSuccess:e=>M(e),onError:e=>P(C(e))})},children:l.isPending?`Creating…`:`Create key`})]}):B(s,{type:`button`,$variant:`primary`,onClick:()=>I(!1),children:`I have copied the key`}),children:j===null?V(a,{$gap:3,children:[B(A,{label:`Label`,hint:`Names the client this key belongs to, e.g. laptop or CI.`,children:e=>B(O,{...e,value:d,placeholder:`api key`,onChange:e=>f(e.target.value)})}),V(a,{$gap:2,children:[V(c,{$gap:2,children:[B(x,{checked:p,label:`Allow every model`,onCheckedChange:m}),B(e,{as:`span`,children:`Allow every model`})]}),p?null:V(z,{children:[B(ue,{children:(i.data??[]).map(e=>V(de,{children:[B(`input`,{type:`checkbox`,checked:g.includes(e.id),onChange:t=>b(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),e.id]},e.id))}),g.length===0?B(fe,{children:`With no model selected this key is allowed nothing and every request it makes will be refused.`}):null]})]}),V(a,{$gap:2,children:[V(c,{$gap:2,children:[V(he,{type:`button`,$size:`sm`,"aria-expanded":T,onClick:()=>E(e=>!e),children:[B(T?v:_,{}),`Limits`]}),B(e,{as:`span`,children:L===0?`no limits; this key is unbounded`:`${L} limit${L===1?``:`s`} set`})]}),T?B(Q,{draft:S,onChange:w}):null]}),V(a,{$gap:2,children:[V(c,{$gap:2,children:[B(x,{checked:D,label:`Never record this key's bodies`,onCheckedChange:k}),B(e,{as:`span`,children:`Never record this key's bodies`})]}),B(ge,{children:`Suppresses body capture for this key whatever the gateway setting says. Choose it for a client whose payloads must not be retained. It cannot be changed after the key is created — issue a new key instead.`})]}),N===null?null:B(pe,{role:`alert`,children:N})]}):V(a,{$gap:3,children:[B(me,{children:`This is the only time the key is shown. The gateway keeps a hash, so a lost key has to be replaced rather than recovered.`}),B(y,{value:j.key,label:`Copy API key`}),V(c,{$gap:2,children:[B(e,{children:`Label`}),B(o,{children:j.label}),B(e,{children:`Prefix`}),B(o,{children:j.prefix})]})]})})}var ve=H(c)`
63
- gap: 4px;
64
- flex-wrap: wrap;
65
- max-width: 34ch;
66
- `,ye=H.span`
67
- color: ${({theme:e})=>e.color.inkFaint};
68
- `,$=H.span`
69
- font-size: 11px;
70
- color: ${({theme:e})=>e.color.inkDim};
71
- `,be=H.div`
72
- display: flex;
73
- flex-direction: column;
74
- align-items: flex-end;
75
- gap: 2px;
76
- `;function xe(e){if(e===null)return`usage not counted here`;let t=J(e);return`${K({dimension:e.dimension,window:e.window})} ${q(e.dimension,e.limit)}, ${t===null?`—`:Math.round(t*100)}% used`}function Se(){let n=t(),i=r(),[a,o]=R(!1),[u,h]=R(null),[y,x]=R(null),[C,O]=R(null),k=n.data??[],A=k.filter(e=>e.revokedAt===null),j=n.isLoading?`Reading issued keys…`:k.length===0?`No keys exist, so nothing can call this gateway yet.`:`${A.length} active key${A.length===1?``:`s`} of ${k.length} ever issued.`;return V(z,{children:[B(g,{legend:`Keys`,title:`Gateway API keys`,summary:j,actions:V(s,{type:`button`,$variant:`primary`,onClick:()=>o(!0),children:[B(b,{}),`Create a key`]})}),B(M,{legend:`Issued keys`,meta:`${k.length}`,flush:!0,children:n.isError?B(w,{error:n.error,onRetry:()=>void n.refetch()}):n.isLoading?B(`div`,{style:{padding:12},children:B(T,{rows:4})}):k.length===0?B(E,{legend:`No keys`,message:`Create a key and give it to a client. The key is shown once, at creation.`,action:B(s,{type:`button`,$variant:`primary`,$size:`sm`,onClick:()=>o(!0),children:`Create a key`})}):B(d,{children:V(I,{children:[B(`thead`,{children:V(`tr`,{children:[B(F,{children:`Label`}),B(F,{children:`Prefix`}),B(F,{children:`Allowed models`}),B(F,{$align:`right`,children:`Limits`}),B(F,{$align:`right`,children:`Created`}),B(F,{children:`Body capture`}),B(F,{children:`Status`}),B(F,{})]})}),B(`tbody`,{children:k.map(t=>{let n=y===t.id,r=te(t.limitUsage);return V(L,{children:[V(N,{children:[B(P,{children:B(l,{style:{maxWidth:`24ch`,display:`block`},children:t.label})}),V(P,{$mono:!0,children:[t.prefix,`…`]}),B(P,{children:t.modelAllowlist===null?B(e,{children:`every model`}):t.modelAllowlist.length===0?B(D,{$tone:`down`,children:`no models`}):B(ve,{children:t.modelAllowlist.map(e=>B(D,{children:e},e))})}),B(P,{$align:`right`,children:t.limits===null?B(D,{$tone:`down`,children:`unreadable`}):t.limitUsage.length===0?B(e,{children:`no limits`}):V(be,{children:[V(`span`,{children:[t.limitUsage.length,` limit`,t.limitUsage.length===1?``:`s`]}),B($,{children:xe(r)})]})}),B(P,{$align:`right`,$mono:!0,children:S(t.createdAt)}),B(P,{children:t.bodyLoggingOptOut?B(D,{children:`no bodies`}):B(e,{children:`—`})}),B(P,{children:t.revokedAt===null?B(D,{$tone:`ok`,children:`active`}):B(ye,{title:S(t.revokedAt),children:B(D,{children:`revoked`})})}),B(P,{$align:`right`,children:V(c,{$gap:1,$justify:`flex-end`,children:[t.limitUsage.length===0?null:B(f,{type:`button`,$variant:`ghost`,$size:`sm`,"aria-expanded":n,"aria-label":`${n?`Hide`:`Show`} limits for ${t.label}`,title:`${n?`Hide`:`Show`} limits for ${t.label}`,onClick:()=>x(n?null:t.id),children:B(n?v:_,{})}),t.revokedAt===null?V(z,{children:[B(f,{type:`button`,$variant:`ghost`,$size:`sm`,"aria-label":`Edit limits for ${t.label}`,title:`Edit limits for ${t.label}`,onClick:()=>h(t),children:B(p,{})}),B(s,{type:`button`,$variant:`danger`,$size:`sm`,onClick:()=>O(t),children:`Revoke`})]}):null]})})]}),n?B(N,{children:B(P,{colSpan:8,children:B(le,{label:t.label,readings:t.limitUsage})})}):null]},t.id)})})]})})}),B(_e,{open:a,onOpenChange:o}),B(ae,{apiKey:u,onOpenChange:e=>{e||h(null)}},u?.id??`none`),B(m,{open:C!==null,onOpenChange:e=>{e||O(null)},title:`Revoke key`,body:C===null?``:`Revoking "${C.label}" refuses its next request. The key stays listed so past usage keeps its attribution, and it cannot be un-revoked.`,confirmLabel:`Revoke key`,busy:i.isPending,onConfirm:()=>{C!==null&&i.mutate(C.id,{onSettled:()=>O(null)})}})]})}var Ce=Se;export{Ce as component};
@@ -1,68 +0,0 @@
1
- import{$ as e,C as t,D as n,at as r,et as i,g as ee,j as a,lt as o,n as te,nt as s,ot as c,rt as l,s as u}from"./queries-CX9mStps.js";import{a as ne,s as re,t as ie}from"./Rack-HM36SprU.js";import{n as d,r as f,t as p}from"./TokenBreakdown-C2NsJnqO.js";import{A as m,D as h,E as g,F as _,N as v,O as y,a as ae,f as b,g as oe,h as se,k as ce,n as x,p as S,r as C,t as w}from"./States-DtkkMzEu.js";import{n as T,t as E}from"./Chip-BltJSw8A.js";import{i as D,n as O}from"./Field-B79Yxdit.js";import{t as k}from"./Panel-CoulMx6R.js";import{i as le,n as A,r as j,t as ue}from"./Table-CVDZ69Zx.js";import{useEffect as M,useMemo as N,useState as P}from"react";import{Fragment as F,jsx as I,jsxs as L}from"react/jsx-runtime";import R from"styled-components";var z={none:{legend:`Not captured`,message:`Body capture was not running for this request. It needs OMNI_BODY_LOGGING_ALLOWED in the environment and the body logging setting turned on, and the calling key must not have opted out.`},missing:{legend:`Captured, then lost`,message:`This request was captured, but its artifact is no longer on disk. Retention or the row cap has since pruned it, or something removed the file underneath the gateway.`},corrupt:{legend:`Captured, but unreadable`,message:`This request was captured and the artifact is still on disk, but it failed its checksum or would not decrypt. Changing OMNI_ENCRYPTION_KEY invalidates every artifact written under the old one.`}},B=new Intl.NumberFormat(`en-US`),V=R.p`
2
- font-size: 12px;
3
- color: ${({theme:e})=>e.color.inkDim};
4
- max-width: 62ch;
5
- `,H=R(V)`
6
- border-left: 2px solid ${({theme:e})=>e.color.ruleStrong};
7
- padding-left: ${({theme:e})=>e.space(2)};
8
- `,U=R.h4`
9
- font-size: 11px;
10
- font-weight: 600;
11
- letter-spacing: 0.12em;
12
- text-transform: uppercase;
13
- color: ${({theme:e})=>e.color.inkDim};
14
- margin: 0;
15
- `,W=R.figcaption`
16
- display: flex;
17
- align-items: center;
18
- gap: ${({theme:e})=>e.space(2)};
19
- flex-wrap: wrap;
20
- margin-bottom: 4px;
21
- `,G=R.figure`
22
- margin: 0;
23
- min-width: 0;
24
- `,K=R.pre`
25
- margin: 0;
26
- padding: ${({theme:e})=>e.space(2)};
27
- max-height: 260px;
28
- overflow: auto;
29
- border: 1px solid ${({theme:e})=>e.color.rule};
30
- border-radius: ${({theme:e})=>e.radius.control};
31
- background: ${({theme:e})=>e.color.panelSunk};
32
- font-family: ${({theme:e})=>e.font.mono};
33
- font-size: 11.5px;
34
- line-height: 1.5;
35
- white-space: pre-wrap;
36
- word-break: break-word;
37
- `;function q(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=e;if(t.omitted!==!0||typeof t.reason!=`string`)return null;let n=t.serializedBytes;return{omitted:!0,reason:t.reason,serializedBytes:typeof n==`number`?n:0}}function J({title:e,stage:t,value:n}){let r=q(n);return L(G,{children:[L(W,{children:[I(U,{children:e}),t===void 0?null:I(E,{children:t})]}),r===null?n==null?I(V,{children:`Nothing was recorded for this half — it never happened, or never completed.`}):I(K,{children:JSON.stringify(n,null,2)}):L(V,{children:[`Too large to keep: `,r.reason,`. The payload was`,` `,B.format(r.serializedBytes),` bytes after structural bounding, so it was replaced by this marker rather than written oversized or dropped without a trace.`]})]})}function Y({attempt:t}){return L(r,{$gap:2,children:[L(s,{$gap:2,$wrap:!0,children:[L(e,{as:`h3`,children:[`Attempt `,t.attempt,` · `,t.provider]}),t.truncated?I(E,{$tone:`warn`,children:`truncated`}):null]}),I(J,{title:`Request sent to the provider`,stage:`post-RTK`,value:t.request}),I(J,{title:`Response from the provider`,value:t.response}),t.streamChunks===null?null:I(J,{title:`Raw stream frames (${h(t.streamChunks.length)})`,value:t.streamChunks})]})}function X({body:t}){let n=t.artifact;if(n===null){let n=z[t.detailState===`ready`?`corrupt`:t.detailState];return L(r,{$gap:1,children:[I(e,{children:n.legend}),I(V,{children:n.message})]})}return L(r,{$gap:3,children:[n.attempts.length===0?null:I(H,{children:`The client request below is what arrived at the gateway. Each attempt request is what went upstream after RTK filters ran, so the two are not the same payload — compare them to see what compression actually removed.`}),L(r,{$gap:2,children:[L(s,{$gap:2,$wrap:!0,children:[I(e,{as:`h3`,children:`Client`}),n.client.truncated?I(E,{$tone:`warn`,children:`truncated`}):null]}),I(J,{title:`Request from the client`,stage:`pre-RTK`,value:n.client.request}),I(J,{title:`Response returned to the client`,value:n.client.response})]}),n.attempts.map(e=>I(Y,{attempt:e},`${e.attempt}-${e.provider}`)),n.error===null||n.error===void 0?null:I(J,{title:`Error`,value:n.error})]})}function de({requestId:e}){let t=a(e),n=t.data===void 0||t.data.detailState!==`ready`?void 0:`${B.format(t.data.sizeBytes)} bytes on disk`;return I(k,{legend:`Captured bodies`,...n===void 0?{}:{meta:n},...t.data?.truncated===!0?{actions:I(E,{$tone:`warn`,children:`truncated`})}:{},children:t.isError?I(x,{error:t.error,onRetry:()=>void t.refetch()}):t.isPending?I(C,{rows:3}):I(X,{body:t.data})})}var fe=[50,100,250,500],pe=R(s)`
38
- gap: ${({theme:e})=>e.space(2)};
39
- flex-wrap: wrap;
40
- `,me=R(O)`
41
- width: 220px;
42
- `,Z=R(D)`
43
- width: auto;
44
- `,Q=R(k)`
45
- flex: 1;
46
- min-height: 0;
47
-
48
- > div {
49
- display: flex;
50
- flex: 1;
51
- flex-direction: column;
52
- min-height: 0;
53
- }
54
- `,he=R(l)`
55
- flex: 1;
56
- min-height: 0;
57
- overflow-y: auto;
58
- `;function ge(e){let[t,n]=P(Date.now);return M(()=>{if(!e)return;n(Date.now());let t=window.setInterval(()=>n(Date.now()),1e3);return()=>window.clearInterval(t)},[e]),t}function _e({log:e}){return I(A,{$align:`right`,$mono:!0,...S(e)?{"aria-label":`processing`}:{title:f(e)},children:S(e)?I(p,{}):I(d,{tokens:e})})}var ve=R.dl`
59
- display: grid;
60
- grid-template-columns: minmax(120px, auto) minmax(0, 1fr);
61
- gap: 6px ${({theme:e})=>e.space(3)};
62
- margin: 0;
63
- font-size: 12.5px;
64
- `,$=R.dd`
65
- margin: 0;
66
- font-family: ${({theme:e})=>e.font.mono};
67
- word-break: break-all;
68
- `;function ye(){let{cadence:a,live:l}=ne(),[d,f]=P(100),[p,D]=P(`all`),[O,k]=P(``),[M,R]=P(null),z=n(d,a(te)),B=ee(),V=t(),H=u(),U=(z.data??[]).some(S),W=ge(l&&U),G=N(()=>{let e=new Map;for(let t of B.data??[])e.set(t.id,t.label);return e},[B.data]),K=N(()=>{let e=new Map;for(let t of V.data??[])e.set(t.id,t.label);return e},[V.data]),q=O.trim().toLowerCase(),J=(z.data??[]).filter(e=>p===`failed`&&!b(e)?!1:q.length===0||e.requestedModel.toLowerCase().includes(q)||(e.resolvedModel??``).toLowerCase().includes(q)||(e.errorCode??``).toLowerCase().includes(q)||(e.credentialId===null?``:G.get(e.credentialId)??``).toLowerCase().includes(q)||(e.apiKeyId===null?``:K.get(e.apiKeyId)??e.apiKeyId).toLowerCase().includes(q)),Y=(z.data??[]).filter(b).length,X=(z.data??[]).filter(S).length;return L(F,{children:[I(ie,{legend:`Logs`,title:`Recent requests`,summary:z.isLoading?`Reading the request log…`:`${h(z.data?.length??0)} recent requests, ${h(Y)} of them failed${X===0?``:`, ${h(X)} still running`}. ${H.data===!0?`Body capture is on: open a request to read what it sent and received.`:`Prompt and response bodies are not being recorded.`}`,actions:L(pe,{children:[I(me,{value:O,placeholder:`Filter by model, account, key, or error`,"aria-label":`Filter requests`,onChange:e=>k(e.target.value)}),L(Z,{value:p,"aria-label":`Show which requests`,onChange:e=>D(e.target.value),children:[I(`option`,{value:`all`,children:`All requests`}),I(`option`,{value:`failed`,children:`Failed only`})]}),I(Z,{value:d,"aria-label":`How many requests to fetch`,onChange:e=>f(Number(e.target.value)),children:fe.map(e=>L(`option`,{value:e,children:[`last `,e]},e))})]})}),I(Q,{legend:`Request log`,meta:`${J.length} shown`,flush:!0,children:z.isError?I(x,{error:z.error,onRetry:()=>void z.refetch()}):z.isLoading?I(`div`,{style:{padding:12},children:I(C,{rows:8})}):J.length===0?I(w,{legend:`Nothing to show`,message:(z.data?.length??0)===0?`No requests have reached the gateway yet.`:`No request in this window matches the filter. Clear it to see everything.`}):I(he,{"data-testid":`request-log-scroller`,children:L(ue,{children:[I(`thead`,{children:L(`tr`,{children:[I(j,{}),I(j,{$align:`right`,children:`Time`}),I(j,{children:`Requested`}),I(j,{children:`Routed to`}),I(j,{children:`Account`}),I(j,{children:`Key`}),I(j,{$align:`right`,children:`Try`}),I(j,{$align:`right`,children:`TTFT`}),I(j,{$align:`right`,children:`Total`}),I(j,{$align:`right`,children:`Tokens`}),I(j,{$align:`right`,children:`Cost`}),I(j,{children:`Outcome`})]})}),I(`tbody`,{children:J.map(t=>L(le,{$selectable:!0,onClick:()=>R(t),children:[I(A,{children:I(ae,{state:oe(t),label:se(t)})}),I(A,{$align:`right`,$mono:!0,title:y(t.at),children:g(t.at)}),I(A,{$mono:!0,children:I(c,{style:{display:`block`,maxWidth:`20ch`},children:t.requestedModel||`—`})}),I(A,{children:t.resolvedProvider===null?I(e,{children:S(t)?`routing…`:`not routed`}):L(s,{$gap:1,children:[I(T,{provider:t.resolvedProvider}),I(i,{$dim:!0,children:t.resolvedModel??`—`})]})}),I(A,{children:I(c,{style:{display:`block`,maxWidth:`18ch`},children:t.credentialId===null?`—`:G.get(t.credentialId)??_(t.credentialId)})}),I(A,{children:I(c,{style:{display:`block`,maxWidth:`16ch`},title:t.apiKeyId??void 0,children:t.apiKeyId===null?`—`:K.get(t.apiKeyId)??_(t.apiKeyId)})}),I(A,{$align:`right`,$mono:!0,children:S(t)?`—`:t.attempts}),I(A,{$align:`right`,$mono:!0,children:S(t)?`—`:m(t.ttftMs)}),I(A,{$align:`right`,$mono:!0,children:S(t)?ce(Math.max(0,W-t.at)):m(t.durationMs)}),I(_e,{log:t}),I(A,{$align:`right`,$mono:!0,children:S(t)?`—`:v(t.costUsd)}),I(A,{children:S(t)?I(E,{$tone:`accent`,children:`live`}):t.errorCode===null?I(E,{$tone:`ok`,children:t.status}):I(E,{$tone:`down`,children:t.errorCode})})]},t.id))})]})})}),I(re,{open:M!==null,onOpenChange:e=>{e||R(null)},title:`Request detail`,width:`760px`,footer:I(o,{type:`button`,onClick:()=>R(null),children:`Close`}),children:M===null?null:L(r,{$gap:3,children:[L(ve,{children:[I(e,{as:`dt`,children:`Request id`}),I($,{children:M.id}),I(e,{as:`dt`,children:`At`}),I($,{children:y(M.at)}),I(e,{as:`dt`,children:`Requested model`}),I($,{children:M.requestedModel||`—`}),I(e,{as:`dt`,children:`Routed to`}),I($,{children:S(M)?`—`:M.resolvedProvider===null?`not routed`:`${M.resolvedProvider} · ${M.resolvedModel??`—`}`}),I(e,{as:`dt`,children:`Account`}),I($,{children:M.credentialId===null?`—`:G.get(M.credentialId)??M.credentialId}),I(e,{as:`dt`,children:`Key`}),I($,{children:M.apiKeyId===null?`—`:K.get(M.apiKeyId)??M.apiKeyId}),I(e,{as:`dt`,children:`Attempts`}),I($,{children:S(M)?`—`:M.attempts}),I(e,{as:`dt`,children:`Status`}),I($,{children:S(M)?`in flight`:M.errorCode===null?M.status:`${M.status} ${M.errorCode}`}),I(e,{as:`dt`,children:`Timing`}),I($,{children:S(M)?`—`:`first token ${m(M.ttftMs)} · total ${m(M.durationMs)}`}),I(e,{as:`dt`,children:`Tokens`}),I($,{children:S(M)?`—`:L(F,{children:[h(M.inputTokens),` in · `,h(M.outputTokens),` out ·`,` `,h(M.cacheReadTokens),` cache read ·`,` `,h(M.cacheWriteTokens),` cache write`]})}),I(e,{as:`dt`,children:`Cost`}),I($,{children:S(M)?`—`:v(M.costUsd)}),I(e,{as:`dt`,children:`RTK compression`}),I($,{children:S(M)?`—`:M.rtkApplied?`${h(M.rtkFilterHits)} hits · ${h(M.rtkOriginalCodeUnits)} → ${h(M.rtkCompressedCodeUnits)} code units · ~${h(M.rtkEstimatedTokensSaved)} tokens saved`:`not applied`}),I(e,{as:`dt`,children:`RTK filters`}),I($,{children:M.rtkFilters.length===0?`—`:M.rtkFilters.join(`, `)})]}),M.degradations.length===0?null:L(r,{$gap:1,children:[I(e,{children:`Capabilities dropped to fit the target`}),I(s,{$gap:1,$wrap:!0,children:M.degradations.map(e=>I(E,{$tone:`warn`,children:e},e))})]}),I(de,{requestId:M.id})]})})]})}var be=ye;export{be as component};
@@ -1,148 +0,0 @@
1
- import{$ as e,F as t,O as n,at as r,et as i,g as a,it as o,lt as s,nt as c,ot as l,ut as u,x as d,y as f,z as p}from"./queries-CX9mStps.js";import{r as m}from"./index-iCfSaRSG.js";import{g as h,o as g,t as _}from"./Rack-HM36SprU.js";import{t as v}from"./plus-DKapAGoR.js";import{t as y}from"./trash-2-DwMK-JrZ.js";import{t as b}from"./Toggle-CRrH9nDt.js";import{i as x,n as S,r as C,t as w}from"./States-DtkkMzEu.js";import{n as T,t as E}from"./Chip-BltJSw8A.js";import{i as D,n as O,r as k,t as A}from"./Field-B79Yxdit.js";import{t as j}from"./Meter-stpt3vQu.js";import{t as M}from"./Panel-CoulMx6R.js";import{i as N,n as ee,r as P,t as F}from"./catalog-BBKm8Ih8.js";import{useEffect as I,useId as te,useState as L}from"react";import{Fragment as R,jsx as z,jsxs as B}from"react/jsx-runtime";import V from"styled-components";var ne=h(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]),re=h(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),H=[`tier`,`health`,`quota`,`cost`,`latency`,`load`],ie={tier:`How preferred this tier is`,health:`Consecutive failures and breaker state`,quota:`Headroom in the tightest window, against how much of it is left`,cost:`Price of this request against the other candidates`,latency:`Observed time to first token`,load:`Requests in flight on this pair right now`},ae=V.li`
2
- padding: ${({theme:e})=>e.space(2)} 0;
3
- border-bottom: 1px solid ${({theme:e})=>e.color.rule};
4
-
5
- &:last-child {
6
- border-bottom: 0;
7
- }
8
- `,oe=V(i)`
9
- width: 22px;
10
- color: ${({theme:e})=>e.color.inkFaint};
11
- flex: none;
12
- `,se=V(E)`
13
- border-color: ${({theme:e})=>e.color.ok};
14
- color: ${({theme:e})=>e.color.ok};
15
- background: ${({theme:e})=>e.color.okWash};
16
- `,ce=V.div`
17
- display: grid;
18
- grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
19
- gap: ${({theme:e})=>e.space(2)};
20
- margin-top: ${({theme:e})=>e.space(2)};
21
- padding-left: 30px;
22
- `,le=V.div`
23
- display: flex;
24
- flex-direction: column;
25
- gap: 3px;
26
- min-width: 0;
27
- `,ue=V.div`
28
- display: flex;
29
- align-items: baseline;
30
- justify-content: space-between;
31
- gap: 6px;
32
- `,de=V.li`
33
- display: flex;
34
- align-items: center;
35
- gap: ${({theme:e})=>e.space(2)};
36
- padding: 5px 0;
37
- `,fe=V(c)`
38
- gap: ${({theme:e})=>e.space(3)};
39
- flex-wrap: wrap;
40
- `,U=V.label`
41
- display: flex;
42
- align-items: center;
43
- gap: 6px;
44
- cursor: pointer;
45
- font-size: 12.5px;
46
- `,pe=V.p`
47
- font-size: 12px;
48
- color: ${({theme:e})=>e.color.down};
49
- `;function W(e,t,n){return(e[t]??0)*n[t]}function me({modelId:t}){let[n,a]=L({tools:!1,images:!1,reasoning:!1}),[u,f]=L(null),[m,h]=L(null),g=p(),_=d(),v=g.data?.weights,y=()=>{t!==null&&(h(null),_.mutate({modelId:t,need:n},{onSuccess:e=>f(e),onError:e=>{f(null),h(x(e))}}))},S=new Map(H.map(e=>[e,Math.max(1e-4,...(u?.candidates??[]).map(t=>v===void 0?0:Math.abs(W(t.reasons,e,v))))]));return z(M,{legend:`Explain`,meta:t??`no model selected`,actions:B(s,{type:`button`,$size:`sm`,$variant:`primary`,disabled:t===null||_.isPending,onClick:y,children:[z(ne,{}),_.isPending?`Ranking…`:`Rank candidates`]}),children:B(r,{$gap:3,children:[B(r,{$gap:1,children:[z(e,{children:`Pretend the request needs`}),B(fe,{children:[B(U,{children:[z(b,{checked:n.tools,label:`Probe request uses tools`,onCheckedChange:e=>a({...n,tools:e})}),`Tools`]}),B(U,{children:[z(b,{checked:n.images,label:`Probe request includes an image`,onCheckedChange:e=>a({...n,images:e})}),`Images`]}),B(U,{children:[z(b,{checked:n.reasoning,label:`Probe request asks for reasoning`,onCheckedChange:e=>a({...n,reasoning:e})}),`Reasoning`]})]})]}),m===null?null:z(pe,{children:m}),u===null?z(w,{legend:`Not ranked yet`,message:t===null?`Select a model to see which account the router would pick for it.`:`Run the ranking to see which account wins, by how much, and what was filtered out.`}):B(r,{$gap:3,children:[B(c,{$gap:2,$wrap:!0,children:[z(E,{$tone:`accent`,children:u.strategy}),u.deterministic?null:z(E,{$tone:`warn`,children:`order varies per request`}),z(o,{}),B(e,{children:[u.candidates.length,` eligible · `,u.excluded.length,` filtered out`]})]}),u.candidates.length===0?z(w,{legend:`Nothing eligible`,message:`Every target was filtered out. The reasons below say which rule removed each one.`}):z(`ul`,{children:u.candidates.map((t,n)=>B(ae,{children:[B(c,{$gap:2,children:[z(oe,{children:n+1}),z(T,{provider:t.provider}),z(l,{style:{maxWidth:`22ch`},children:t.credentialLabel}),z(i,{$dim:!0,children:t.model}),B(E,{children:[`tier `,t.tier]}),z(o,{}),n===0?z(se,{children:`would be used`}):null,z(i,{children:t.score.toFixed(2)})]}),v===void 0?null:z(ce,{children:H.map(n=>{let r=W(t.reasons,n,v),a=S.get(n)??1;return B(le,{title:ie[n],children:[B(ue,{children:[z(e,{children:n}),z(i,{$dim:!0,$size:`10.5px`,children:r.toFixed(2)})]}),z(j,{fraction:Math.abs(r)/a,height:4,tone:`var(--accent)`,label:`${n} contributes ${r.toFixed(2)} of ${t.score.toFixed(2)}`})]},n)})})]},`${t.credentialId}:${t.model}`))}),u.excluded.length===0?null:B(r,{$gap:1,children:[z(e,{children:`Filtered out`}),z(`ul`,{children:u.excluded.map(e=>B(de,{children:[z(i,{$dim:!0,children:e.model}),z(o,{}),z(E,{$tone:e.reason.startsWith(`capability`)?`warn`:`down`,children:e.reason})]},`${e.credentialId}:${e.model}:${e.reason}`))})]})]})]})})}var G=[{id:`score`,label:`Best score`,blurb:`Rank every eligible target by the routing weights and take the best one.`},{id:`priority`,label:`Lowest tier`,blurb:`Always prefer the lowest tier. Score only breaks ties inside a tier.`},{id:`roundRobin`,label:`Round robin`,blurb:`Take whichever eligible target has been idle longest, to spread load evenly.`},{id:`weighted`,label:`Weighted draw`,blurb:`Pick at random, biased by weight. The order differs from request to request.`}],K=0;function q(){return K+=1,`target-${K}`}function J(e,t){let n=N(e,t);return n===null?null:{costInput:String(n.input),costOutput:String(n.output),costCacheRead:String(n.cacheRead),costCacheWrite5m:String(n.cacheWrite5m),costCacheWrite1h:String(n.cacheWrite1h)}}function he(e,t){let n=ee(e,t);return n===null?null:{contextWindow:String(n.contextWindow),maxOutputTokens:String(n.maxOutputTokens)}}var ge={oauth:`OAuth`,apiKey:`an API key`};function Y(e){return e.map(e=>ge[e]).join(` or `)}function _e(e){let t={};for(let n of e){let e=t[n.provider]??[];e.includes(n.authType)||e.push(n.authType),t[n.provider]=e}return t}function X(e,t,n){let r=n[e];return r===void 0||r.length===0||P(e,t).some(e=>r.includes(e))}function ve(e,t){return F[e].models.filter(n=>X(e,n.id,t))}function ye(e,t,n){if(t.trim().length===0||X(e,t,n))return null;let r=n[e]??[];return`${e} serves this model to ${Y(P(e,t))} only, and every ${e} account here is ${Y(r)}. Requests routed here will fail.`}function be(e,t){return{...e,...t,...J(t.provider,t.model)??{},contextWindow:``,maxOutputTokens:``}}function xe(e=`anthropic`){let t=F[e].defaultModel,n=J(e,t);return{key:q(),provider:e,endpointId:``,model:t,tier:`1`,weight:`1`,costInput:n?.costInput??`0`,costOutput:n?.costOutput??`0`,costCacheRead:n?.costCacheRead??``,costCacheWrite5m:n?.costCacheWrite5m??``,costCacheWrite1h:n?.costCacheWrite1h??``,contextWindow:``,maxOutputTokens:``,tools:!0,images:!0,reasoning:!0}}function Se(){return{id:``,strategy:`score`,isAlias:!1,targets:[xe()]}}function Ce(e){return{id:e.id,strategy:e.strategy,isAlias:e.isAlias,targets:e.targets.map(e=>({key:q(),provider:e.provider,endpointId:e.provider===`custom`?e.endpointId??``:``,model:e.model,tier:String(e.tier),weight:String(e.weight),costInput:String(e.costPerMTok.input),costOutput:String(e.costPerMTok.output),costCacheRead:e.costPerMTok.cacheRead===void 0?``:String(e.costPerMTok.cacheRead),costCacheWrite5m:e.costPerMTok.cacheWrite5m===void 0?``:String(e.costPerMTok.cacheWrite5m),costCacheWrite1h:e.costPerMTok.cacheWrite1h===void 0?``:String(e.costPerMTok.cacheWrite1h),contextWindow:e.contextWindow===void 0?``:String(e.contextWindow),maxOutputTokens:e.maxOutputTokens===void 0?``:String(e.maxOutputTokens),tools:e.capabilities.tools,images:e.capabilities.images,reasoning:e.capabilities.reasoning}))}}function we(e){let t=e.id.trim();if(t.length===0)return{ok:!1,problem:`Give the model a name clients will ask for.`};if(e.targets.length===0)return{ok:!1,problem:`A model needs at least one target to route to.`};let n=[];for(let[t,r]of e.targets.entries()){let e=`Target ${t+1}`,i=r.endpointId.trim();if(r.provider===`custom`&&i.length===0)return{ok:!1,problem:`${e} needs a custom endpoint.`};let a=r.model.trim();if(a.length===0)return{ok:!1,problem:`${e} needs a provider model name.`};let o=Number(r.tier);if(!Number.isInteger(o)||o<1)return{ok:!1,problem:`${e}: tier must be a whole number of 1 or more.`};let s=Number(r.weight);if(!Number.isFinite(s)||s<=0)return{ok:!1,problem:`${e}: weight must be greater than zero.`};let c=Number(r.costInput),l=Number(r.costOutput);if(!Number.isFinite(c)||c<0||!Number.isFinite(l)||l<0)return{ok:!1,problem:`${e}: prices cannot be negative.`};let u=r.costCacheRead.trim().length>0,d=Number(r.costCacheRead);if(u&&(!Number.isFinite(d)||d<0))return{ok:!1,problem:`${e}: the cache-read price cannot be negative.`};let f=r.costCacheWrite5m.trim().length>0,p=Number(r.costCacheWrite5m);if(f&&(!Number.isFinite(p)||p<0))return{ok:!1,problem:`${e}: the 5m cache-write price must be a number of 0 or more.`};let m=r.costCacheWrite1h.trim().length>0,h=Number(r.costCacheWrite1h);if(m&&(!Number.isFinite(h)||h<0))return{ok:!1,problem:`${e}: the 1h cache-write price must be a number of 0 or more.`};let g=r.contextWindow.trim().length>0,_=Number(r.contextWindow);if(g&&(!Number.isInteger(_)||_<1))return{ok:!1,problem:`${e}: the context window must be a whole number of tokens.`};let v=r.maxOutputTokens.trim().length>0,y=Number(r.maxOutputTokens);if(v&&(!Number.isInteger(y)||y<1))return{ok:!1,problem:`${e}: the output limit must be a whole number of tokens.`};n.push({provider:r.provider,...r.provider===`custom`?{endpointId:i}:{},model:a,tier:o,weight:s,costPerMTok:{input:c,output:l,...u?{cacheRead:d}:{},...f?{cacheWrite5m:p}:{},...m?{cacheWrite1h:h}:{}},...g?{contextWindow:_}:{},...v?{maxOutputTokens:y}:{},capabilities:{tools:r.tools,images:r.images,reasoning:r.reasoning}})}return{ok:!0,model:{id:t,strategy:e.strategy,isAlias:e.isAlias,targets:n}}}var Te=Object.keys(F),Ee=V.fieldset`
50
- border: 1px solid ${({theme:e})=>e.color.rule};
51
- border-left: 3px solid ${({theme:e,$provider:t})=>e.provider[t]};
52
- border-radius: ${({theme:e})=>e.radius.control};
53
- padding: ${({theme:e})=>e.space(3)};
54
- margin: 0;
55
- background: ${({theme:e})=>e.color.panelSunk};
56
- display: flex;
57
- flex-direction: column;
58
- gap: ${({theme:e})=>e.space(3)};
59
- min-width: 0;
60
- `,De=V.div`
61
- display: grid;
62
- grid-template-columns: minmax(140px, 1.4fr) minmax(160px, 2fr) 72px 72px;
63
- gap: ${({theme:e})=>e.space(2)};
64
- align-items: end;
65
-
66
- @media (max-width: 720px) {
67
- grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
68
- }
69
- `,Oe=V.div`
70
- display: grid;
71
- grid-template-columns: repeat(3, minmax(0, 1fr));
72
- gap: ${({theme:e})=>e.space(2)};
73
- align-items: end;
74
- `,Z=V.div`
75
- display: flex;
76
- flex-direction: column;
77
- gap: 4px;
78
- min-width: 0;
79
- `,ke=V(c)`
80
- gap: ${({theme:e})=>e.space(3)};
81
- flex-wrap: wrap;
82
- `,Ae=V.p`
83
- font-size: 11.5px;
84
- color: ${({theme:e})=>e.color.down};
85
- margin: 0;
86
- `,Q=V.label`
87
- display: flex;
88
- align-items: center;
89
- gap: 6px;
90
- cursor: pointer;
91
- `;function je({target:t,index:n,onChange:i,onRemove:a,removable:l,endpoints:d,held:f}){let p=te(),h=F[t.provider],g=ve(t.provider,f),_=ye(t.provider,t.model,f),v=(e,n)=>{i({...t,[e]:n})},x=J(t.provider,t.model),S=he(t.provider,t.model),C=e=>{i(be(t,e))};return B(Ee,{$provider:t.provider,children:[B(c,{$gap:2,children:[B(e,{as:`legend`,children:[`Target `,n+1]}),z(o,{}),z(u,{type:`button`,$variant:`ghost`,$size:`sm`,disabled:!l,"aria-label":`Remove target ${n+1}`,title:l?`Remove target ${n+1}`:`A model needs at least one target`,onClick:a,children:z(y,{})})]}),B(De,{children:[B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-provider`,children:`Provider`}),z(D,{id:`${p}-provider`,value:t.provider,onChange:e=>{let n=e.target.value,r=F[n].models.some(e=>e.id===t.model);C({provider:n,model:r?t.model:F[n].defaultModel})},children:Te.map(e=>z(`option`,{value:e,children:m[e]},e))})]}),t.provider===`custom`?B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-endpoint`,children:`Endpoint`}),B(D,{id:`${p}-endpoint`,value:t.endpointId,onChange:e=>v(`endpointId`,e.target.value),children:[z(`option`,{value:``,children:`Choose endpoint`}),d.map(e=>z(`option`,{value:e.id,children:e.label},e.id))]})]}):null,B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-model`,children:`Provider model`}),z(O,{id:`${p}-model`,list:`${p}-catalog`,value:t.model,placeholder:h.defaultModel,onChange:e=>C({provider:t.provider,model:e.target.value})}),z(`datalist`,{id:`${p}-catalog`,children:g.map(e=>z(`option`,{value:e.id,children:e.label},e.id))}),_===null?null:z(Ae,{role:`note`,children:_})]}),B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-tier`,children:`Tier`}),z(k,{id:`${p}-tier`,min:1,step:1,value:t.tier,onChange:e=>v(`tier`,e.target.value)})]}),B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-weight`,children:`Weight`}),z(k,{id:`${p}-weight`,min:0,step:.1,value:t.weight,onChange:e=>v(`weight`,e.target.value)})]})]}),B(r,{$gap:1,children:[B(c,{$gap:2,children:[z(e,{children:`Price per million tokens`}),z(o,{}),x===null?z(e,{as:`span`,children:`not in the catalog — price it yourself`}):B(s,{type:`button`,$size:`sm`,$variant:`ghost`,disabled:t.costInput===x.costInput&&t.costOutput===x.costOutput&&t.costCacheRead===x.costCacheRead&&t.costCacheWrite5m===x.costCacheWrite5m&&t.costCacheWrite1h===x.costCacheWrite1h,onClick:()=>i({...t,...x}),children:[z(re,{}),`Use list price`]})]}),B(Oe,{children:[B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-in`,children:`Input`}),z(k,{id:`${p}-in`,min:0,step:.01,value:t.costInput,onChange:e=>v(`costInput`,e.target.value)})]}),B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-out`,children:`Output`}),z(k,{id:`${p}-out`,min:0,step:.01,value:t.costOutput,onChange:e=>v(`costOutput`,e.target.value)})]}),B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-cache`,children:`Cache read`}),z(k,{id:`${p}-cache`,min:0,step:.01,placeholder:`same as input`,value:t.costCacheRead,onChange:e=>v(`costCacheRead`,e.target.value)})]}),B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-write5m`,children:`Cache write 5m`}),z(k,{id:`${p}-write5m`,min:0,step:.01,placeholder:`1.25x input`,value:t.costCacheWrite5m,onChange:e=>v(`costCacheWrite5m`,e.target.value)})]}),B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-write1h`,children:`Cache write 1h`}),z(k,{id:`${p}-write1h`,min:0,step:.01,placeholder:`2x input`,value:t.costCacheWrite1h,onChange:e=>v(`costCacheWrite1h`,e.target.value)})]})]})]}),B(r,{$gap:1,children:[B(c,{$gap:2,children:[z(e,{children:`Token limits`}),z(o,{}),S===null?z(e,{as:`span`,children:`not in the catalog — state them yourself`}):z(e,{as:`span`,children:`left empty, the published figures are used — and for an OpenAI target, the narrower ones its OAuth backend allows`})]}),B(Oe,{children:[B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-context`,children:`Context window`}),z(k,{id:`${p}-context`,min:1,step:1024,placeholder:S?.contextWindow??`published`,value:t.contextWindow,onChange:e=>v(`contextWindow`,e.target.value)})]}),B(Z,{children:[z(e,{as:`label`,htmlFor:`${p}-maxout`,children:`Max output`}),z(k,{id:`${p}-maxout`,min:1,step:1024,placeholder:S?.maxOutputTokens??`published`,value:t.maxOutputTokens,onChange:e=>v(`maxOutputTokens`,e.target.value)})]})]})]}),B(r,{$gap:1,children:[z(e,{children:`Capabilities`}),B(ke,{children:[B(Q,{children:[z(b,{checked:t.tools,label:`Target ${n+1} supports tools`,onCheckedChange:e=>v(`tools`,e)}),`Tools`]}),B(Q,{children:[z(b,{checked:t.images,label:`Target ${n+1} supports images`,onCheckedChange:e=>v(`images`,e)}),`Images`]}),B(Q,{children:[z(b,{checked:t.reasoning,label:`Target ${n+1} supports reasoning`,onCheckedChange:e=>v(`reasoning`,e)}),`Reasoning`]})]})]})]})}var Me=V.p`
92
- font-size: 11.5px;
93
- color: ${({theme:e})=>e.color.inkDim};
94
- `,Ne=V.p`
95
- font-size: 12px;
96
- color: ${({theme:e})=>e.color.down};
97
- `,Pe=V.p`
98
- font-size: 12px;
99
- color: ${({theme:e})=>e.color.ok};
100
- `,Fe=V(c)`
101
- gap: 8px;
102
- `;function Ie({model:n,onSaved:i,onDeleted:l}){let[u,d]=L(()=>n===null?Se():Ce(n)),[p,m]=L(null),[h,_]=L(!1),[y,S]=L(!1),C=t(),w=f(),T=a(),E=_e(T.data??[]),k=(T.data??[]).filter(e=>e.provider===`custom`).map(e=>({id:String(e.providerData.endpointId??``),label:String(e.providerData.endpointLabel??e.providerData.endpointId??``)})).filter((e,t,n)=>e.id.length>0&&n.findIndex(t=>t.id===e.id)===t),j=n?.id??null;I(()=>{d(n===null?Se():Ce(n)),m(null),_(!1)},[j]);let N=G.find(e=>e.id===u.strategy);return B(R,{children:[z(M,{legend:n===null?`New model`:`Edit model`,meta:n===null?void 0:n.id,actions:B(R,{children:[n===null?null:z(s,{type:`button`,$variant:`danger`,$size:`sm`,onClick:()=>S(!0),children:`Delete`}),z(s,{type:`button`,$variant:`primary`,$size:`sm`,disabled:C.isPending,onClick:()=>{_(!1);let e=we(u);if(!e.ok){m(e.problem);return}m(null),C.mutate(e.model,{onSuccess:()=>{_(!0),i(e.model.id)},onError:e=>m(x(e))})},children:C.isPending?`Saving…`:n===null?`Create model`:`Save changes`})]}),children:B(r,{$gap:3,children:[z(A,{label:`Model name`,hint:n===null?`What clients send as the model. Anything not listed here is rejected.`:`Fixed once created. To rename, create a model under the new name and delete this one.`,children:e=>z(O,{...e,value:u.id,disabled:n!==null,placeholder:`fast`,onChange:e=>d({...u,id:e.target.value})})}),z(A,{label:`Routing strategy`,children:e=>z(D,{...e,value:u.strategy,onChange:e=>d({...u,strategy:e.target.value}),children:G.map(e=>z(`option`,{value:e.id,children:e.label},e.id))})}),N===void 0?null:z(Me,{children:N.blurb}),B(Fe,{children:[z(b,{checked:u.isAlias,label:`This model is an alias for a provider model name`,onCheckedChange:e=>d({...u,isAlias:e})}),B(r,{$gap:0,children:[z(e,{as:`span`,children:`Alias`}),z(Me,{children:`Mark this when the name mirrors a provider's own model name.`})]})]}),B(r,{$gap:2,children:[B(c,{children:[z(e,{children:`Targets`}),z(o,{}),B(s,{type:`button`,$size:`sm`,onClick:()=>d({...u,targets:[...u.targets,xe(u.targets.at(-1)?.provider??`anthropic`)]}),children:[z(v,{}),`Add target`]})]}),u.targets.map((e,t)=>z(je,{target:e,index:t,removable:u.targets.length>1,endpoints:k,held:E,onChange:t=>d({...u,targets:u.targets.map(n=>n.key===e.key?t:n)}),onRemove:()=>d({...u,targets:u.targets.filter(t=>t.key!==e.key)})},e.key))]}),p===null?null:z(Ne,{role:`alert`,children:p}),h&&p===null?z(Pe,{role:`status`,children:`Saved.`}):null]})}),z(g,{open:y,onOpenChange:S,title:`Delete model`,body:n===null?``:`Deleting "${n.id}" makes it unroutable. Clients asking for it will get a model-unavailable error, and any key allowlisting it keeps a name that no longer resolves.`,confirmLabel:`Delete model`,busy:w.isPending,onConfirm:()=>{n!==null&&w.mutate(n.id,{onSuccess:()=>{S(!1),l()},onError:e=>{S(!1),m(x(e))}})}})]})}var Le=V.div`
103
- display: grid;
104
- grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
105
- gap: ${({theme:e})=>e.space(4)};
106
- align-items: start;
107
-
108
- @media (max-width: 980px) {
109
- grid-template-columns: minmax(0, 1fr);
110
- }
111
- `,Re=V(r)`
112
- gap: ${({theme:e})=>e.space(4)};
113
- min-width: 0;
114
- `,ze=V.button`
115
- display: flex;
116
- flex-direction: column;
117
- gap: 4px;
118
- width: 100%;
119
- padding: ${({theme:e})=>`${e.space(2)} ${e.space(3)}`};
120
- text-align: left;
121
- background: ${({theme:e,$selected:t})=>t?e.color.accentWash:`transparent`};
122
- border: 0;
123
- border-left: 2px solid
124
- ${({theme:e,$selected:t})=>t?e.color.accent:`transparent`};
125
- border-bottom: 1px solid ${({theme:e})=>e.color.rule};
126
- cursor: pointer;
127
-
128
- &:hover {
129
- background: ${({theme:e,$selected:t})=>t?e.color.accentWash:e.color.panelSunk};
130
- }
131
-
132
- &:last-child {
133
- border-bottom: 0;
134
- }
135
- `,Be=V(l)`
136
- font-family: ${({theme:e})=>e.font.mono};
137
- font-size: 12.5px;
138
- display: block;
139
- max-width: 100%;
140
- `,Ve=V.div`
141
- display: flex;
142
- gap: 2px;
143
- `,He=V.span`
144
- width: 12px;
145
- height: 3px;
146
- border-radius: 1px;
147
- background: ${({$provider:e})=>`var(--p-${e})`};
148
- `,$=`\0new`;function Ue(){let t=n(),[r,a]=L(null),l=t.data??[],u=r===$?null:l.find(e=>e.id===r)??null,d=r===$||r===null&&!t.isLoading&&l.length===0;I(()=>{r===null&&l.length!==0&&a(l[0]?.id??null)},[l,r]);let f=t.isLoading?`Reading configured models…`:l.length===0?`No virtual models exist yet, so no client request can resolve to an upstream.`:`${l.length} model${l.length===1?``:`s`} routing to ${l.reduce((e,t)=>e+t.targets.length,0)} targets.`;return B(R,{children:[z(_,{legend:`Models`,title:`Virtual models`,summary:f,actions:B(s,{type:`button`,$variant:`primary`,onClick:()=>a($),children:[z(v,{}),`New model`]})}),B(Le,{children:[z(M,{legend:`Configured`,meta:`${l.length}`,flush:!0,children:t.isError?z(S,{error:t.error,onRetry:()=>void t.refetch()}):t.isLoading?z(`div`,{style:{padding:12},children:z(C,{rows:4})}):l.length===0?z(w,{legend:`No models`,message:`Create a model to give clients something to ask for.`,action:z(s,{type:`button`,$size:`sm`,$variant:`primary`,onClick:()=>a($),children:`New model`})}):z(`div`,{children:l.map(t=>{let n=[...new Set(t.targets.map(e=>e.provider))];return B(ze,{type:`button`,$selected:t.id===r,"aria-pressed":t.id===r,onClick:()=>a(t.id),children:[B(c,{$gap:2,style:{width:`100%`},children:[z(Be,{title:t.id,children:t.id}),z(o,{}),t.isAlias?z(E,{children:`alias`}):null]}),B(c,{$gap:2,style:{width:`100%`},children:[z(Ve,{children:n.map(e=>z(He,{$provider:e,title:e},e))}),z(e,{children:t.strategy}),z(o,{}),B(i,{$dim:!0,$size:`11px`,children:[t.targets.length,` target`,t.targets.length===1?``:`s`]})]})]},t.id)})})}),B(Re,{children:[u===null&&!d?z(M,{legend:`Editor`,children:t.isLoading?z(C,{rows:5}):z(w,{legend:`Nothing selected`,message:`Pick a model on the left to change its targets, or create a new one.`})}):z(Ie,{model:u,onSaved:e=>{a(e),t.refetch()},onDeleted:()=>{a(null),t.refetch()}}),z(me,{modelId:u?.id??null})]})]})]})}var We=Ue;export{We as component};
@@ -1,83 +0,0 @@
1
- import{$ as e,A as t,At as n,B as r,C as i,Ct as a,D as o,Dt as s,E as c,Et as l,F as u,G as d,H as f,I as p,J as m,K as h,L as g,M as _,Mt as v,N as y,O as b,Ot as x,P as S,Q as C,R as ee,S as w,St as te,T,Tt as E,U as D,V as ne,W as re,X as ie,Y as ae,Z as oe,_ as se,_t as ce,a as le,at as O,b as k,bt as A,c as j,ct as M,d as ue,dt as de,et as fe,f as N,ft as pe,g as me,gt as he,h as ge,ht as _e,i as ve,it as ye,j as be,jt as xe,k as Se,kt as Ce,l as we,lt as Te,m as Ee,mt as De,n as Oe,nt as ke,o as Ae,ot as je,p as Me,pt as Ne,q as Pe,r as Fe,rt as Ie,s as P,st as Le,t as Re,tt as ze,u as Be,ut as Ve,v as He,vt as Ue,w as We,wt as Ge,x as F,xt as Ke,y as qe,yt as Je,z as Ye}from"./shared-Cct_4xwp.js";import{$ as Xe,C as Ze,G as I,O as Qe,Q as $e,at as L,et as R,g as et,nt as tt,ot as nt,rt}from"./queries-CX9mStps.js";import{i as it,n as at,r as ot}from"./index-iCfSaRSG.js";import{a as st,r as z,t as ct}from"./Rack-HM36SprU.js";import{A as lt,D as B,N as V,j as H,n as ut,r as dt,t as ft}from"./States-DtkkMzEu.js";import{t as pt}from"./Panel-CoulMx6R.js";import{i as mt,n as U,r as W,t as ht}from"./Table-CVDZ69Zx.js";import{t as gt}from"./catalog-BBKm8Ih8.js";import{t as G}from"./Readout-D1XEfywe.js";import*as K from"react";import{PureComponent as _t,forwardRef as vt,useMemo as q,useRef as yt,useState as bt}from"react";import{jsx as J,jsxs as Y}from"react/jsx-runtime";import X from"styled-components";function xt(e,t){return e.graphicalItems.cartesianItems.find(e=>e.id===t)?.xAxisId??0}function St(e,t){return e.graphicalItems.cartesianItems.find(e=>e.id===t)?.yAxisId??0}var Ct=(e,t,n)=>C(e,`xAxis`,xt(e,t),n),wt=(e,t,n)=>fe(e,`xAxis`,xt(e,t),n),Tt=(e,t,n)=>C(e,`yAxis`,St(e,t),n),Et=(e,t,n)=>fe(e,`yAxis`,St(e,t),n),Dt=A([M,Ct,Tt,wt,Et],(e,t,n,r,i)=>Ue(e,`xAxis`)?Ne(t,r,!1):Ne(n,i,!1)),Ot=A([ze,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`area`).find(e=>e.id===t)),kt=e=>{var t=M(e);return Ue(t,`xAxis`)?`yAxis`:`xAxis`},At=(e,t)=>kt(e)===`yAxis`?St(e,t):xt(e,t),jt=(t,n,r)=>e(t,kt(t),At(t,n),r),Mt=A([Ot,jt],(e,t)=>{if(e!=null&&t!=null){var n=e.stackId,r=ke(e);if(n!=null&&r!=null){var i=(t[n]?.stackedData)?.find(e=>e.key===r);if(i!=null)return i.map(e=>[e[0],e[1]])}}}),Nt=A([Ot,jt],(e,t)=>{if(e!=null&&e.stackId!=null&&t!=null){var n=t[e.stackId];if(n!=null)return n.graphicalItems.map(e=>e.dataKey).filter(E)}}),Pt=A([M,Ct,Tt,wt,Et,Mt,O,Dt,Ot,ye,Nt],(e,t,n,r,i,a,o,s,c,l,u)=>{var d=o.chartData,f=o.dataStartIndex,p=o.dataEndIndex;if(!(c==null||e!==`horizontal`&&e!==`vertical`||t==null||n==null||r==null||i==null||r.length===0||i.length===0||s==null)){var m=c.data,h=m&&m.length>0?m:d?.slice(f,p+1);if(h!=null)return pn({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataStartIndex:f,areaSettings:c,stackedData:a,displayedData:h,chartBaseValue:l,bandSize:s,stackDataKeys:u})}}),Ft=[`animationElapsedTime`,`isAnimating`,`isEntrance`,`layout`,`isRange`,`stroke`,`connectNulls`],It=[`id`,`baseLine`];function Lt(){return Lt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Lt.apply(null,arguments)}function Rt(e,t){if(e==null)return{};var n,r,i=zt(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function zt(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Bt(e){var t=e.alpha,n=e.baseLine,r=e.points,i=e.strokeWidth,a=r[0]?.x,o=r[r.length-1]?.x;if(!Je(a)||!Je(o))return null;var c=t*Math.abs(a-o),l=Math.max(...r.map(e=>e.y||0));return s(n)?l=Math.max(n,l):n&&Array.isArray(n)&&n.length&&(l=Math.max(...n.map(e=>e.y||0),l)),s(l)?K.createElement(`rect`,{x:a<o?a:a-c,y:0,width:c,height:Math.floor(l+(i?parseInt(`${i}`,10):1))}):null}function Vt(e){var t=e.alpha,n=e.baseLine,r=e.points,i=e.strokeWidth,a=r[0]?.y,o=r[r.length-1]?.y;if(!Je(a)||!Je(o))return null;var c=t*Math.abs(a-o),l=Math.max(...r.map(e=>e.x||0));return s(n)?l=Math.max(n,l):n&&Array.isArray(n)&&n.length&&(l=Math.max(...n.map(e=>e.x||0),l)),s(l)?K.createElement(`rect`,{x:0,y:a<o?a:a-c,width:l+(i?parseInt(`${i}`,10):1),height:Math.floor(c)}):null}function Ht(e){var t=e.alpha,n=e.layout,r=e.points,i=e.baseLine,a=e.strokeWidth;return n===`vertical`?K.createElement(Vt,{alpha:t,points:r,baseLine:i,strokeWidth:a}):K.createElement(Bt,{alpha:t,points:r,baseLine:i,strokeWidth:a})}function Ut(e){var t=e.animationElapsedTime,n=t===void 0?1:t,r=e.isAnimating,i=r!==void 0&&r,a=e.isEntrance,o=a!==void 0&&a,s=e.layout,c=e.isRange,l=e.stroke,u=e.connectNulls,d=Rt(e,Ft),f=s===`vertical`?`vertical`:`horizontal`,m=u??!1,h=p(),g=d.id,_=d.baseLine,v=Rt(d,It),y=xe(v),b=K.createElement(je,Lt({},d,{id:g,baseLine:_,connectNulls:m,stroke:`none`,className:`recharts-area-area`,layout:f})),x=l!==`none`&&K.createElement(je,Lt({},y,{className:`recharts-area-curve`,layout:f,type:d.type,connectNulls:m,fill:`none`,stroke:l,points:d.points})),S=l!==`none`&&c&&Array.isArray(_)&&K.createElement(je,Lt({},y,{className:`recharts-area-curve`,layout:f,type:d.type,connectNulls:m,fill:`none`,stroke:l,points:_}));return o&&(i||n<1)?K.createElement(Ce,null,K.createElement(`defs`,null,K.createElement(`clipPath`,{id:h},K.createElement(Ht,{alpha:n,points:d.points??[],baseLine:_,layout:f,strokeWidth:d.strokeWidth}))),K.createElement(Ce,{clipPath:`url(#${h})`},b,x,S)):K.createElement(K.Fragment,null,b,x,S)}var Wt=[`id`],Gt=[`activeDot`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`fill`,`fillOpacity`,`hide`,`isAnimationActive`,`legendType`,`stroke`,`xAxisId`,`yAxisId`];function Kt(){return Kt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Kt.apply(null,arguments)}function qt(e,t){if(e==null)return{};var n,r,i=Jt(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Jt(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Yt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Z(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Yt(Object(n),!0).forEach(function(t){Xt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Yt(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Xt(e,t,n){return(t=Zt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Zt(e){var t=Qt(e,`string`);return typeof t==`symbol`?t:t+``}function Qt(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var $t={activeDot:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,animationMatchBy:ne,animationInterpolateFn:(e,t)=>e==null?[]:t===1?e.flatMap(e=>e.status===`removed`?[]:[e.next]):e.flatMap(e=>e.status===`matched`?[Z(Z({},e.next),{},{x:a(e.prev.x,e.next.x,t),y:a(e.prev.y,e.next.y,t)})]:e.status===`added`?[e.next]:[]),connectNulls:!1,dot:!1,fill:`#3182bd`,fillOpacity:.6,hide:!1,isAnimationActive:`auto`,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,type:`linear`,label:!1,shape:Ut,xAxisId:0,yAxisId:0,zIndex:Ie.area};function en(e,t){return e&&e!==`none`?e:t}var tn=e=>{var t=e.dataKey,n=e.name,r=e.stroke,i=e.fill,a=e.legendType;return[{inactive:e.hide,dataKey:t,type:a,color:en(r,i),value:he(n,t),payload:e}]},nn=K.memo(e=>{var t=e.dataKey,n=e.data,r=e.stroke,i=e.strokeWidth,a=e.fill,o=e.name,s=e.hide,c=e.unit,l=e.formatter,u=e.tooltipType,d=e.id,f={dataDefinedOnItem:n,getPosition:x,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:he(o,t),hide:s,type:u,color:en(r,a),unit:c,formatter:l,graphicalItemId:d}};return K.createElement(D,{tooltipEntrySettings:f})});function rn(e){var t=e.clipPathId,n=e.points,r=e.props,i=r.needClip,a=r.dot,o=r.dataKey,s=xe(r);return K.createElement(y,{points:n,dot:a,className:`recharts-area-dots`,dotClassName:`recharts-area-dot`,dataKey:o,baseProps:s,needClip:i,clipPathId:t})}function an(e){var t=e.showLabels,n=e.children,r=e.points.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return Z(Z({},t),{},{value:e.value,payload:e.payload,parentViewBox:void 0,viewBox:t,fill:void 0})});return K.createElement(h,{value:t?r:void 0},n)}function on(e){var t=e.points,r=e.baseLine,i=e.needClip,a=e.clipPathId,o=e.props,s=e.animationElapsedTime,c=e.isAnimating,l=e.isEntrance,u=o.layout,d=o.type,f=o.stroke,p=o.connectNulls,m=o.isRange,h=o.shape,g=o.id,_=qt(o,Wt),v=Z(Z({},n(_)),{},{id:g,points:t,connectNulls:p,type:d,baseLine:r,layout:u,stroke:f,isRange:m,animationElapsedTime:s,isAnimating:c,isEntrance:l});return K.createElement(K.Fragment,null,t?.length>1&&K.createElement(Ce,{clipPath:i?`url(#clipPath-${a})`:void 0},K.createElement(re,{option:h,DefaultShape:$t.shape,shapeProps:v})),K.createElement(rn,{points:t,props:_,clipPathId:a}))}function sn(e,t,n){if(s(e)){var r=s(t)?t:void 0;return a(r,e,n)}if(l(e)||Ge(e)){var i=s(t)?t:void 0;return a(i,0,n)}return e}function cn(e){var t=e.needClip,n=e.clipPathId,i=e.props,a=e.previousPointsRef,o=e.previousBaselineRef,s=i.points,c=i.baseLine,l=i.isAnimationActive,u=i.animationBegin,d=i.animationDuration,f=i.animationEasing,p=i.animationMatchBy,m=i.animationInterpolateFn,h=q(()=>({points:s,baseLine:c}),[s,c]),_=Ye(h,o),v=Te(),y=ee(i.onAnimationStart,i.onAnimationEnd),b=y.isAnimating,x=y.handleAnimationStart,S=y.handleAnimationEnd,C=_.startValue;if(v==null)return null;var w=Array.isArray(c)&&Array.isArray(C)?r(C,c,p):Array.isArray(c)?r(null,c,p):null;return K.createElement(g,{animationInput:h,animationIdPrefix:`recharts-area-`,items:s,previousItemsRef:a,isAnimationActive:l,animationBegin:u,animationDuration:d,animationEasing:f,onAnimationStart:x,onAnimationEnd:S,animationInterpolateFn:m,animationMatchBy:p,layout:v},(e,r,a)=>{var o=r===1?c:Array.isArray(c)?m(w,r,v):a?c:sn(c,C,r);return _.syncStepValue(o,r),K.createElement(an,{showLabels:!b,points:s},i.children,K.createElement(on,{points:e,baseLine:o,needClip:t,clipPathId:n,props:i,animationElapsedTime:r,isAnimating:b||r<1,isEntrance:a}),K.createElement(Pe,{label:i.label}))})}function ln(e){var t=e.needClip,n=e.clipPathId,r=e.props,i=yt(null),a=yt();return K.createElement(cn,{needClip:t,clipPathId:n,props:r,previousPointsRef:i,previousBaselineRef:a})}var un=class extends _t{render(){var e=this.props,t=e.hide,n=e.dot,r=e.points,i=e.className,a=e.top,s=e.left,c=e.needClip,l=e.xAxisId,u=e.yAxisId,f=e.width,p=e.height,m=e.id,h=e.baseLine,g=e.zIndex;if(t)return null;var _=v(`recharts-area`,i),y=m,x=o(n),S=x.r,C=x.strokeWidth,ee=d(n),w=S*2+C,te=c?`url(#clipPath-${ee?``:`dots-`}${y})`:void 0;return K.createElement(ie,{zIndex:g},K.createElement(Ce,{className:_},c&&K.createElement(`defs`,null,K.createElement(b,{clipPathId:y,xAxisId:l,yAxisId:u}),!ee&&K.createElement(`clipPath`,{id:`clipPath-dots-${y}`},K.createElement(`rect`,{x:s-w/2,y:a-w/2,width:f+w,height:p+w}))),K.createElement(ln,{needClip:c,clipPathId:y,props:this.props})),K.createElement(be,{points:r,mainColor:en(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:te}),this.props.isRange&&Array.isArray(h)&&K.createElement(be,{points:h,mainColor:en(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:te}))}};function dn(e){var t=e.activeDot,n=e.animationBegin,r=e.animationDuration,i=e.animationEasing,a=e.connectNulls,o=e.dot,s=e.fill,c=e.fillOpacity,l=e.hide,u=e.isAnimationActive,d=e.legendType,f=e.stroke,p=e.xAxisId,m=e.yAxisId,h=qt(e,Gt),g=Ve(),v=oe(),y=Se(p,m).needClip,b=pe(),x=Ke(t=>Pt(t,e.id,b))??{},S=x.points,C=x.isRange,ee=x.baseLine,w=_();if(g!==`horizontal`&&g!==`vertical`||w==null||v!==`AreaChart`&&v!==`ComposedChart`)return null;var te=w.height,T=w.width,E=w.x,D=w.y;return!S||!S.length?null:K.createElement(un,Kt({},h,{activeDot:t,animationBegin:n,animationDuration:r,animationEasing:i,baseLine:ee,connectNulls:a,dot:o,fill:s,fillOpacity:c,height:te,hide:l,layout:g,isAnimationActive:u,isRange:C,legendType:d,needClip:y,points:S,stroke:f,width:T,left:E,top:D,xAxisId:p,yAxisId:m}))}var fn=(e,t,n,r,i)=>{var a=n??t;if(s(a))return a;var o=e===`horizontal`?i:r,c=o.scale.domain();if(o.type===`number`){var l=Math.max(c[0],c[1]),u=Math.min(c[0],c[1]);return a===`dataMin`?u:a===`dataMax`||l<0?l:Math.max(Math.min(c[0],c[1]),0)}return a===`dataMin`?c[0]:a===`dataMax`?c[1]:c[0]};function pn(e){var t=e.areaSettings,n=t.connectNulls,r=t.baseValue,i=t.dataKey,a=e.stackedData,o=e.layout,s=e.chartBaseValue,c=e.xAxis,l=e.yAxis,u=e.displayedData,d=e.dataStartIndex,f=e.xAxisTicks,p=e.yAxisTicks,m=e.bandSize,h=e.stackDataKeys,g=a&&a.length,_=fn(o,s,r,c,l),v=o===`horizontal`,y=!1,b=u.map((e,t)=>{var r;if(g)r=a[d+t];else{var o=ce(e,i);Array.isArray(o)?(r=o,y=!0):r=[_,o]}var s=r?.[1]??null,u=ce(e,i),b=g&&u==null&&h!=null&&h.length>0&&h.every(t=>ce(e,t)==null),x=s==null||g&&!n&&u==null||b;return v?{x:De({axis:c,ticks:f,bandSize:m,entry:e,index:t}),y:x?null:l.scale.map(s)??null,value:r,payload:e}:{x:x?null:c.scale.map(s)??null,y:De({axis:l,ticks:p,bandSize:m,entry:e,index:t}),value:r,payload:e}});return{points:b,baseLine:(g||y?b.map(e=>{var t=Array.isArray(e.value)?e.value[0]:null;return v?{x:e.x,y:t!=null&&e.y!=null?l.scale.map(t)??null:null,payload:e.payload}:{x:t==null?null:c.scale.map(t)??null,y:e.y,payload:e.payload}}):v?l.scale.map(_):c.scale.map(_))??0,isRange:y}}function mn(e){var t=te(e,$t),n=pe();return K.createElement(u,{id:t.id,type:`area`},e=>K.createElement(K.Fragment,null,K.createElement(f,{legendPayload:tn(t)}),K.createElement(nn,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,formatter:t.formatter,tooltipType:t.tooltipType,id:e}),K.createElement(S,{type:`area`,id:e,data:t.data,dataKey:t.dataKey,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,stackId:_e(t.stackId),hide:t.hide,barSize:void 0,baseValue:t.baseValue,isPanorama:n,connectNulls:t.connectNulls}),K.createElement(dn,Kt({},t,{id:e}))))}var hn=K.memo(mn,Le);hn.displayName=`Area`;var gn=[`axis`],_n=vt((e,t)=>K.createElement(i,{chartName:`AreaChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:gn,tooltipPayloadSearcher:ae,categoricalChartProps:e,ref:t})),vn=[`axis`],yn=vt((e,t)=>K.createElement(i,{chartName:`ComposedChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:vn,tooltipPayloadSearcher:ae,categoricalChartProps:e,ref:t})),bn=53,Q=9,xn=2,Sn=X.div`
2
- display: flex;
3
- gap: ${xn}px;
4
- `,Cn=X.div`
5
- display: grid;
6
- grid-template-rows: repeat(7, ${Q}px);
7
- gap: ${xn}px;
8
- padding-top: ${11}px;
9
- font-size: 9px;
10
- color: ${({theme:e})=>e.color.inkFaint};
11
- `,wn=X.div`
12
- line-height: ${Q}px;
13
- padding-right: 2px;
14
- text-align: right;
15
- `,Tn=X.div`
16
- display: grid;
17
- grid-template-columns: repeat(${bn}, ${Q}px);
18
- gap: ${xn}px;
19
- height: ${Q}px;
20
- font-size: 9px;
21
- color: ${({theme:e})=>e.color.inkFaint};
22
- `,En=X.div`
23
- white-space: nowrap;
24
- line-height: ${Q}px;
25
- `,Dn=X.div`
26
- display: grid;
27
- grid-template-columns: repeat(${bn}, ${Q}px);
28
- gap: ${xn}px;
29
- `,On=X.div`
30
- display: grid;
31
- grid-template-rows: repeat(7, ${Q}px);
32
- gap: ${xn}px;
33
- `,kn=X.div`
34
- width: ${Q}px;
35
- height: ${Q}px;
36
- border-radius: 2px;
37
- background: ${({$level:e})=>e===0?`var(--panel-sunk)`:`color-mix(in oklch, var(--accent) ${[0,24,46,70,100][e]??100}%, var(--panel-sunk))`};
38
- border: 1px solid var(--rule);
39
- visibility: ${({$future:e})=>e?`hidden`:`visible`};
40
-
41
- &:hover,
42
- &:focus-visible {
43
- outline: 1px solid var(--ink-dim);
44
- outline-offset: 1px;
45
- }
46
- `,An=X(tt)`
47
- gap: ${xn}px;
48
- `,jn=X(R)`
49
- color: ${({theme:e})=>e.color.inkDim};
50
- font-size: 11px;
51
- `;function Mn(e){let t=e.filter(e=>e>0).sort((e,t)=>e-t);if(t.length===0)return[0,0,0];let n=e=>t[Math.min(t.length-1,Math.floor(t.length*e))]??0;return[n(.25),n(.5),n(.75)]}function Nn(e,[t,n,r]){return e<=0?0:e<=t?1:e<=n?2:e<=r?3:4}function Pn({days:e,now:t}){let[n,r]=bt(`tokens`),[i,a]=bt(null),o=me(n),s=q(()=>{let n=new Map;for(let t of e){let e=Number(t.key);Number.isFinite(e)&&n.set(qe(e),{requests:t.requests,errors:t.errors,costUsd:t.costUsd,inputTokens:t.inputTokens,outputTokens:t.outputTokens,cacheReadTokens:t.cacheReadTokens,cacheWriteTokens:t.cacheWriteTokens,rtkSavedTokens:t.rtkSavedTokens,rtkAppliedRequests:t.rtkAppliedRequests,durationMsSum:t.durationMsSum})}let r=new Date(qe(t));r.setDate(r.getDate()+(6-r.getDay())-370);let i=qe(t);return Array.from({length:bn},()=>Array.from({length:7},()=>{let e=r.getTime();return r.setDate(r.getDate()+1),{at:e,totals:n.get(e)??we,future:e>i}}))},[e,t]),c=s.flat(),l=Mn(c.map(e=>o.of({key:``,...e.totals}))),u=c.reduce((e,t)=>Be(e,N(t.totals)),we),d=c.reduce((e,t)=>e+ +(t.totals.requests>0),0),f=(e,t)=>`${e}: ${B(t.requests)} requests, ${B(ue(t))} tokens, ${V(t.costUsd)}`;return J(pt,{legend:`Activity`,meta:i===null?`${B(d)} active days`:void 0,actions:J(Oe,{children:ve.map(e=>J(Ae,{type:`button`,$size:`sm`,$on:e.id===n,"aria-pressed":e.id===n,onClick:()=>r(e.id),children:e.label},e.id))}),children:Y(L,{$gap:2,children:[J(rt,{children:J(L,{$gap:1,style:{width:611},children:Y(Sn,{children:[J(Cn,{"aria-hidden":`true`,children:[``,`Mon`,``,`Wed`,``,`Fri`,``].map((e,t)=>J(wn,{children:e},t))}),Y(L,{$gap:1,children:[J(Tn,{"aria-hidden":`true`,children:s.map((e,t)=>{let n=e[0],r=s[t-1]?.[0],i=n!==void 0&&(r===void 0||new Date(r.at).getMonth()!==new Date(n.at).getMonth());return J(En,{children:i&&n!==void 0?new Date(n.at).toLocaleDateString(`en-GB`,{month:`short`}):``},n?.at??t)})}),J(Dn,{role:`grid`,"aria-label":`${o.label} per day over the last year`,children:s.map(e=>J(On,{role:`row`,children:e.map(e=>J(kn,{role:`gridcell`,tabIndex:-1,"aria-label":f(Ee(e.at),e.totals),title:f(Ee(e.at),e.totals),$future:e.future,$level:e.future?0:Nn(o.of({key:``,...e.totals}),l),onMouseEnter:()=>a(e),onMouseLeave:()=>a(null)},e.at))},e[0]?.at))})]})]})})}),Y(tt,{$justify:`space-between`,$wrap:!0,children:[J(jn,{children:i===null?f(`Last 12 months`,u):f(Ee(i.at),i.totals)}),Y(tt,{$gap:1,children:[J(Xe,{children:`Less`}),J(An,{"aria-hidden":`true`,children:[0,1,2,3,4].map(e=>J(kn,{$level:e,$future:!1},e))}),J(Xe,{children:`More`})]})]})]})})}function Fn({buckets:e,by:t,since:n,until:r,metric:i,names:a}){let o=F(n,r,t),s=new Map,c=new Map;for(let n of e){let e=n.split??`unknown`;s.set(e,Be(s.get(e)??we,n));let r=c.get(e)??new Map,a=ge(n.key,t);r.set(a,(r.get(a)??0)+i.of(n)),c.set(e,r)}let l=[...s.entries()].sort((e,t)=>i.of(N(t[1]))-i.of(N(e[1])));return J(rt,{children:Y(ht,{children:[J(`thead`,{children:Y(`tr`,{children:[J(W,{children:`Key`}),J(W,{children:`Trend`}),J(W,{$align:`right`,children:`Requests`}),J(W,{$align:`right`,children:`Failed`}),J(W,{$align:`right`,children:`Tokens`}),J(W,{$align:`right`,children:`Mean`}),J(W,{$align:`right`,children:`Cost`})]})}),J(`tbody`,{children:l.map(([e,t])=>{let n=c.get(e)??new Map,r=e===`unknown`?`Unattributed`:a.get(e)??e;return Y(mt,{children:[J(U,{children:J(nt,{style:{display:`block`,maxWidth:`28ch`},children:r})}),J(U,{style:{width:120},children:J(z,{values:o.map(e=>n.get(e)??0),height:20,label:`${r}: ${i.format(i.of(N(t)))} over the window`})}),J(U,{$align:`right`,$mono:!0,children:B(t.requests)}),J(U,{$align:`right`,$mono:!0,style:t.errors>0?{color:`var(--down)`}:void 0,children:H(t.requests===0?0:t.errors/t.requests,0)}),J(U,{$align:`right`,$mono:!0,children:B(ue(t))}),J(U,{$align:`right`,$mono:!0,children:lt(t.requests===0?null:t.durationMsSum/t.requests)}),J(U,{$align:`right`,$mono:!0,children:V(t.costUsd)})]},e)})})]})})}var In=6,Ln=`__other__`,Rn=`unknown`;function zn(e,t){let n=t.get(e);return n===void 0?at.find(t=>gt[t].models.some(t=>t.id===e))??null:n}function Bn(e,t){return e===null?`var(--ink-faint)`:`color-mix(in oklch, ${it(e)} ${Math.max(30,100-t*22)}%, var(--panel))`}function Vn({buckets:e,by:n,since:r,until:i,metric:a,providers:o}){let s=[...Me(e,a).entries()],c=s.slice(0,In),l=s.slice(In),u=[];for(let e of[...at,null])c.filter(([t])=>zn(t,o)===e).forEach(([t,n],r)=>{u.push({name:t,label:t===Rn?`Unresolved`:t,color:Bn(e,r),totals:n})});l.length>0&&u.push({name:Ln,label:`${l.length} more`,color:`var(--ink-faint)`,totals:l.reduce((e,[,t])=>Be(e,N(t)),we)});let d=new Set(c.map(([e])=>e)),f=new Map;for(let t of e){let e=t.split??Rn,r=`${ge(t.key,n)} ${d.has(e)?e:Ln}`;f.set(r,(f.get(r)??0)+a.of(t))}let p=F(r,i,n).map(e=>{let t={at:e};for(let n of u)t[n.name]=f.get(`${e} ${n.name}`)??0;return t}),h=new Map(u.map(e=>[e.name,e.label]));return Y(L,{$gap:2,children:[J(Re,{$height:220,children:J(de,{width:`100%`,height:`100%`,children:Y(_n,{data:p,margin:{top:4,right:4,bottom:4,left:4},children:[J(t,{stroke:`var(--rule)`,vertical:!1}),J(T,{dataKey:`at`,tickFormatter:e=>k(e,n),tick:{fill:`var(--ink-faint)`,fontSize:10},stroke:`var(--rule-strong)`,interval:`preserveStartEnd`,minTickGap:28}),J(We,{tickFormatter:e=>a.format(e),tick:{fill:`var(--ink-faint)`,fontSize:10},stroke:`var(--rule-strong)`,width:40}),J(m,{cursor:{stroke:`var(--rule-strong)`},content:({active:e,payload:t,label:r})=>{if(e!==!0||t===void 0||t.length===0)return null;let i=t.filter(e=>Number(e.value??0)>0);return Y(j,{children:[J(`div`,{children:k(Number(r),n)}),i.length===0?J(`div`,{children:`No ${a.label.toLowerCase()}`}):i.map(e=>Y(`div`,{children:[h.get(String(e.dataKey))??String(e.dataKey),` `,a.format(Number(e.value??0))]},String(e.dataKey)))]})}}),u.map(e=>J(hn,{type:`monotone`,dataKey:e.name,stackId:`models`,stroke:e.color,strokeWidth:2,fill:e.color,fillOpacity:.22,isAnimationActive:!1},e.name))]})})}),J(Fe,{children:u.map(e=>Y(`span`,{children:[J(P,{$color:e.color}),` `,J(nt,{title:`${e.label}: ${a.format(a.of(N(e.totals)))} ${a.label.toLowerCase()}`,style:{display:`inline-block`,maxWidth:`24ch`,verticalAlign:`bottom`},children:e.label})]},e.name))})]})}var Hn=`unknown`;function Un(e){let t=at.find(t=>t===e);return t===void 0?`var(--ink-faint)`:it(t)}function Wn(e){let t=at.find(t=>t===e);return t===void 0?`Unresolved`:ot[t]}function Gn({buckets:e,by:n,since:r,until:i,metric:a}){let o=Me(e,a),s=[...at,Hn].map(e=>({name:e,totals:o.get(e)})).filter(e=>e.totals!==void 0),c=s.map(e=>e.name),l=F(r,i,n),u=He(e,l,n,a),d=[...o.values()].reduce((e,t)=>e+t.requests,0);return Y(L,{$gap:3,children:[J(Re,{$height:200,children:J(de,{width:`100%`,height:`100%`,children:Y(_n,{data:u,margin:{top:4,right:4,bottom:4,left:4},children:[J(t,{stroke:`var(--rule)`,vertical:!1}),J(T,{dataKey:`at`,tickFormatter:e=>k(e,n),tick:{fill:`var(--ink-faint)`,fontSize:10},stroke:`var(--rule-strong)`,interval:`preserveStartEnd`,minTickGap:28}),J(We,{tickFormatter:e=>a.format(e),tick:{fill:`var(--ink-faint)`,fontSize:10},stroke:`var(--rule-strong)`,width:48}),J(m,{cursor:{stroke:`var(--rule-strong)`},content:({active:e,payload:t,label:r})=>e!==!0||t===void 0||t.length===0?null:Y(j,{children:[J(`div`,{children:k(Number(r),n)}),t.map(e=>Y(`div`,{children:[Wn(String(e.dataKey)),` `,a.format(Number(e.value??0))]},String(e.dataKey)))]})}),c.map(e=>J(hn,{type:`monotone`,dataKey:e,stackId:`providers`,stroke:Un(e),strokeWidth:2,fill:Un(e),fillOpacity:.22,isAnimationActive:!1},e))]})})}),J(Fe,{children:c.map(e=>Y(`span`,{children:[J(P,{$color:Un(e)}),` `,Wn(e)]},e))}),Y(ht,{children:[J(`thead`,{children:Y(`tr`,{children:[J(W,{children:`Provider`}),J(W,{$align:`right`,children:`Share`}),J(W,{$align:`right`,children:`Requests`}),J(W,{$align:`right`,children:`Failed`}),J(W,{$align:`right`,children:`Tokens`}),J(W,{$align:`right`,children:`Cost`})]})}),J(`tbody`,{children:s.map(({name:e,totals:t})=>Y(mt,{children:[Y(U,{children:[J(P,{$color:Un(e)}),` `,Wn(e)]}),J(U,{$align:`right`,$mono:!0,children:H(d===0?0:t.requests/d,0)}),J(U,{$align:`right`,$mono:!0,children:B(t.requests)}),J(U,{$align:`right`,$mono:!0,style:t.errors>0?{color:`var(--down)`}:void 0,children:B(t.errors)}),J(U,{$align:`right`,$mono:!0,children:B(ue(t))}),J(U,{$align:`right`,$mono:!0,children:V(t.costUsd)})]},e))})]})]})}var Kn=X.li`
52
- display: grid;
53
- grid-template-columns: minmax(0, 20ch) 1fr auto;
54
- align-items: center;
55
- gap: ${({theme:e})=>e.space(2)};
56
- `,qn=X.ol`
57
- display: flex;
58
- flex-direction: column;
59
- gap: ${({theme:e})=>e.space(2)};
60
- `,Jn=X.div`
61
- height: 8px;
62
- border-radius: 2px;
63
- background: ${({theme:e})=>e.color.panelSunk};
64
- border: 1px solid ${({theme:e})=>e.color.rule};
65
- overflow: hidden;
66
- `,Yn=X.div`
67
- width: ${({$share:e})=>`${Math.max(1.5,e*100)}%`};
68
- height: 100%;
69
- border-radius: 0 2px 2px 0;
70
- background: ${({theme:e,$fault:t})=>t?e.color.down:e.color.accent};
71
- opacity: 0.85;
72
- `,Xn=X(nt)`
73
- display: block;
74
- font-family: ${({theme:e})=>e.font.mono};
75
- font-size: 12px;
76
- `,Zn=12;function Qn({buckets:e,metric:t,names:n,unknownLabel:r}){let i=new Map;for(let t of e)i.set(t.key,Be(i.get(t.key)??we,t));let a=e=>e===`unknown`?r??`Unattributed`:n?.get(e)??e,o=[...i.entries()].map(([e,n])=>({name:a(e),entry:n,value:t.of(N(n))})).sort((e,t)=>t.value-e.value),s=o.slice(0,Zn),c=o.slice(Zn),l=s[0]?.value??0;return Y(L,{$gap:3,children:[J(qn,{children:s.map(({name:e,entry:n,value:r})=>Y(Kn,{children:[J(Xn,{title:e,children:e}),J(Jn,{children:J(Yn,{$share:l===0?0:r/l,$fault:n.requests>0&&n.errors===n.requests})}),Y(tt,{$gap:2,children:[J(R,{$size:`12px`,children:t.format(r)}),J(R,{$size:`11px`,$dim:!0,children:V(n.costUsd)})]})]},e))}),c.length===0?null:J(R,{$size:`11px`,$dim:!0,children:`+ ${c.length} more, ${B(c.reduce((e,t)=>e+t.entry.requests,0))} requests`})]})}function $({legend:e,meta:t,actions:n,query:r,empty:i,isEmpty:a,children:o}){return J(pt,{legend:e,meta:t,actions:n,children:r.isError?J(ut,{error:r.error,onRetry:r.refetch}):r.isLoading?J(dt,{rows:4}):a?J(ft,{legend:i.legend,message:i.message}):o})}var $n=[{id:`inputTokens`,label:`Uncached input`,opacity:.95},{id:`outputTokens`,label:`Output`,opacity:.7},{id:`cacheReadTokens`,label:`Cache read`,opacity:.45},{id:`cacheWriteTokens`,label:`Cache write`,opacity:.22}];function er({buckets:e,by:n,since:r,until:i}){let a=new Map;for(let t of e)a.set(ge(t.key,n),t);let o=F(r,i,n).map(e=>{let t=a.get(e);return{at:e,inputTokens:t?.inputTokens??0,outputTokens:t?.outputTokens??0,cacheReadTokens:t?.cacheReadTokens??0,cacheWriteTokens:t?.cacheWriteTokens??0}}),s=$n.map(e=>({...e,value:o.reduce((t,n)=>t+n[e.id],0)})),c=s.reduce((e,t)=>e+t.value,0);return Y(L,{$gap:3,children:[J(Re,{$height:200,children:J(de,{width:`100%`,height:`100%`,children:Y(_n,{data:o,margin:{top:4,right:4,bottom:4,left:4},children:[J(t,{stroke:`var(--rule)`,vertical:!1}),J(T,{dataKey:`at`,tickFormatter:e=>k(e,n),tick:{fill:`var(--ink-faint)`,fontSize:10},stroke:`var(--rule-strong)`,interval:`preserveStartEnd`,minTickGap:28}),J(We,{tick:{fill:`var(--ink-faint)`,fontSize:10},stroke:`var(--rule-strong)`,width:44,tickFormatter:e=>B(e)}),J(m,{cursor:{stroke:`var(--rule-strong)`},content:({active:e,payload:t,label:r})=>e!==!0||t===void 0||t.length===0?null:Y(j,{children:[J(`div`,{children:k(Number(r),n)}),$n.map(e=>Y(`div`,{children:[e.label,` `,B(Number(t.find(t=>t.dataKey===e.id)?.value??0))]},e.id))]})}),$n.map(e=>J(hn,{type:`monotone`,dataKey:e.id,stackId:`tokens`,stroke:`var(--accent)`,strokeOpacity:e.opacity,strokeWidth:1.5,fill:`var(--accent)`,fillOpacity:e.opacity*.5,isAnimationActive:!1},e.id))]})})}),J(Fe,{children:s.map(e=>Y(tt,{$gap:1,children:[J(P,{$color:`var(--accent)`,style:{opacity:e.opacity}}),J(`span`,{children:e.label}),J(R,{$size:`11px`,children:B(e.value)}),J(R,{$size:`11px`,$dim:!0,children:H(c===0?0:e.value/c,0)})]},e.id))})]})}function tr({buckets:e,by:n,since:r,until:i}){let a=new Map;for(let t of e)a.set(ge(t.key,n),t);let o=F(r,i,n).map(e=>{let t=a.get(e);return{at:e,label:k(e,n),requests:t?.requests??0,errors:t?.errors??0,costUsd:t?.costUsd??0,tokens:t===void 0?0:ue(t)}});return Y(L,{$gap:2,children:[J(Re,{$height:220,children:J(de,{width:`100%`,height:`100%`,children:Y(yn,{data:o,margin:{top:4,right:4,bottom:4,left:4},children:[J(t,{stroke:`var(--rule)`,vertical:!1}),J(T,{dataKey:`label`,tick:{fill:`var(--ink-faint)`,fontSize:10},stroke:`var(--rule-strong)`,interval:`preserveStartEnd`,minTickGap:28}),J(We,{tick:{fill:`var(--ink-faint)`,fontSize:10},stroke:`var(--rule-strong)`,width:40}),J(m,{cursor:{stroke:`var(--rule-strong)`},content:({active:e,payload:t})=>{if(e!==!0||t===void 0||t.length===0)return null;let n=t[0]?.payload;return n===void 0?null:Y(j,{children:[J(`div`,{children:n.label}),Y(`div`,{children:[B(n.requests),` requests`]}),Y(`div`,{children:[B(n.errors),` failed`]}),Y(`div`,{children:[B(n.tokens),` tokens`]}),J(`div`,{children:V(n.costUsd)})]})}}),J(hn,{type:`monotone`,dataKey:`requests`,stroke:`none`,fill:`var(--accent)`,fillOpacity:.12,isAnimationActive:!1}),J(c,{type:`monotone`,dataKey:`requests`,stroke:`var(--accent)`,strokeWidth:2,dot:!1,activeDot:{r:4,stroke:`var(--panel)`,strokeWidth:2},isAnimationActive:!1}),J(c,{type:`monotone`,dataKey:`errors`,stroke:`var(--down)`,strokeWidth:2,dot:!1,activeDot:{r:4,stroke:`var(--panel)`,strokeWidth:2},isAnimationActive:!1})]})})}),Y(Fe,{children:[Y(`span`,{children:[J(P,{$color:`var(--accent)`}),` Requests`]}),Y(`span`,{children:[J(P,{$color:`var(--down)`}),` Failed`]})]})]})}var nr=X.div`
77
- display: grid;
78
- grid-template-columns: repeat(
79
- auto-fit,
80
- minmax(max(180px, calc((100% - 4 * ${({theme:e})=>e.space(3)}) / 5)), 1fr)
81
- );
82
- gap: ${({theme:e})=>e.space(3)};
83
- `,rr=864e5,ir=[{id:`requestedModel`,label:`As requested`,column:`Virtual model`},{id:`model`,label:`As served`,column:`Upstream model`}];function ar(){let{cadence:e}=st(),[t,n]=bt(`24h`),[r,i]=bt(`tokens`),[a,o]=bt(`model`),s=se(t),c=me(r),l=q(()=>s.grain===`daily`?qe(Date.now()-s.ms):Math.floor((Date.now()-s.ms)/6e4)*6e4,[s]),u=q(()=>l+s.ms,[l,s]),d=q(()=>qe(Date.now()-371*rr),[]),f={since:l,grain:s.grain},p=I({...f,groupBy:s.by},e(6e4)),m=I({...f,groupBy:s.by,splitBy:`provider`},e(6e4)),h=I({...f,groupBy:s.by,splitBy:`model`},e(6e4)),g=I({...f,groupBy:s.by,splitBy:`apiKey`},e(6e4)),_=I({...f,groupBy:a},e(6e4)),v=I({...f,groupBy:`credential`},e(6e4)),y=I({since:d,grain:`daily`,groupBy:`day`},e(3e5)),b=Ze(),x=et(),S=Qe(),C=q(()=>{let e=new Map;for(let t of S.data??[])for(let n of t.targets)e.set(n.model,n.provider);return e},[S.data]),ee=q(()=>{let e=new Map;for(let t of b.data??[])e.set(t.id,t.label);return e},[b.data]),te=q(()=>{let e=new Map;for(let t of x.data??[])e.set(t.id,t.label);return e},[x.data]),T=p.data??[],E=w(T),D=E.inputTokens+E.cacheReadTokens+E.cacheWriteTokens,ne=ue(E),re=E.requests===0?0:E.outputTokens/E.requests,ie=D===0?0:E.cacheReadTokens/D,ae=D===0?0:E.cacheWriteTokens/D,oe=E.requests===0?0:E.costUsd/E.requests,ce=F(l,u,s.by),O=new Map(T.map(e=>[ge(e.key,s.by),e])),k=e=>ce.map(e),A=e=>e>=.25?`down`:e>=.05?`warn`:`ok`,j=E.requests===0?0:E.errors/E.requests,M={legend:`Nothing recorded`,message:`No requests landed in this window. Widen the range, or send traffic through the gateway.`};return Y(L,{$gap:4,children:[J(ct,{legend:`Usage`,title:`Requests, tokens, and spend`,summary:p.isLoading?`Reading usage…`:`${B(E.requests)} requests and ${V(E.costUsd)} over the last ${s.label}.`,actions:J(Oe,{children:le.map(e=>J(Ae,{type:`button`,$size:`sm`,$on:e.id===t,"aria-pressed":e.id===t,onClick:()=>n(e.id),children:e.id},e.id))})}),Y(nr,{"data-testid":`usage-summary-deck`,children:[J(G,{legend:`Requests`,value:B(E.requests),unit:s.label,trace:J(z,{values:k(e=>O.get(e)?.requests??0),overlay:k(e=>O.get(e)?.errors??0),label:`${E.requests} requests, ${E.errors} of them failed`})}),J(G,{legend:`Error rate`,value:H(j),unit:`${B(E.errors)} failed`,tone:E.requests===0?`ink`:A(j),trace:J(z,{values:k(e=>{let t=O.get(e);return t===void 0||t.requests===0?0:t.errors/t.requests}),color:`var(--down)`,label:`${E.errors} failed requests against ${E.requests} total`})}),J(G,{legend:`Prompt input`,value:B(D),unit:`${B(E.inputTokens)} uncached`,trace:J(z,{values:k(e=>{let t=O.get(e);return(t?.inputTokens??0)+(t?.cacheReadTokens??0)+(t?.cacheWriteTokens??0)}),label:`${D} prompt input tokens over the window`})}),J(G,{legend:`Output`,value:B(E.outputTokens),unit:`mean ${B(re)}/request`,trace:J(z,{values:k(e=>O.get(e)?.outputTokens??0),label:`${E.outputTokens} output tokens over the window`})}),J(G,{legend:`Cache reads`,value:B(E.cacheReadTokens),unit:`${H(ie,0)} of prompt`,trace:J(z,{values:k(e=>O.get(e)?.cacheReadTokens??0),label:`${E.cacheReadTokens} cache-read tokens over the window`})}),J(G,{legend:`Cache writes`,value:B(E.cacheWriteTokens),unit:`${H(ae,0)} of prompt`,trace:J(z,{values:k(e=>O.get(e)?.cacheWriteTokens??0),label:`${E.cacheWriteTokens} cache-write tokens over the window`})}),J(G,{legend:`RTK saved`,value:B(E.rtkSavedTokens),unit:`${B(E.rtkAppliedRequests)} requests`,trace:J(z,{values:k(e=>O.get(e)?.rtkSavedTokens??0),label:`${E.rtkSavedTokens} estimated tokens saved by RTK over the window`})}),J(G,{legend:`Mean duration`,value:lt(E.requests===0?null:E.durationMsSum/E.requests),unit:`per request`,trace:J(z,{values:k(e=>{let t=O.get(e);return t===void 0||t.requests===0?0:t.durationMsSum/t.requests}),color:`var(--ok)`,label:`mean request duration over the window`})}),J(G,{legend:`Spend`,value:V(E.costUsd),unit:s.label,trace:J(z,{values:k(e=>O.get(e)?.costUsd??0),color:`var(--warn)`,label:`spend over the window, ${V(E.costUsd)} total`})}),J(G,{legend:`Cost / request`,value:V(oe),unit:`mean`,trace:J(z,{values:k(e=>{let t=O.get(e);return t===void 0||t.requests===0?0:t.costUsd/t.requests}),color:`var(--warn)`,label:`${V(oe)} mean cost per request over the window`})})]}),J($,{legend:`Traffic`,meta:s.by===`hour`?`By hour`:`By day`,query:p,isEmpty:T.length===0,empty:M,children:J(tr,{buckets:T,by:s.by,since:l,until:u})}),J(Oe,{children:ve.map(e=>J(Ae,{type:`button`,$size:`sm`,$on:e.id===r,"aria-pressed":e.id===r,onClick:()=>i(e.id),children:`Rank by ${e.label.toLowerCase()}`},e.id))}),J($,{legend:`Traffic by upstream model`,meta:`${c.label}, ${s.by===`hour`?`by hour`:`by day`}`,query:h,isEmpty:(h.data??[]).length===0,empty:M,children:J(Vn,{buckets:h.data??[],by:s.by,since:l,until:u,metric:c,providers:C})}),Y($e,{$min:`480px`,$gap:4,children:[Y(L,{$gap:4,children:[J($,{legend:`Providers`,meta:c.label,query:m,isEmpty:(m.data??[]).length===0,empty:M,children:J(Gn,{buckets:m.data??[],by:s.by,since:l,until:u,metric:c})}),J(Pn,{days:y.data??[],now:Date.now()})]}),Y(L,{$gap:4,children:[J($,{legend:`Token mix`,meta:B(ne),query:p,isEmpty:T.length===0,empty:M,children:J(er,{buckets:T,by:s.by,since:l,until:u})}),J($,{legend:`Models`,meta:ir.find(e=>e.id===a)?.column,query:_,isEmpty:(_.data??[]).length===0,empty:M,actions:J(Oe,{children:ir.map(e=>J(Ae,{type:`button`,$size:`sm`,$on:e.id===a,"aria-pressed":e.id===a,onClick:()=>o(e.id),children:e.label},e.id))}),children:J(Qn,{buckets:_.data??[],metric:c})}),J($,{legend:`Accounts`,meta:c.label,query:v,isEmpty:(v.data??[]).length===0,empty:M,children:J(Qn,{buckets:v.data??[],metric:c,names:te,unknownLabel:`No account`})})]})]}),J($,{legend:`API keys`,meta:c.label,query:g,isEmpty:(g.data??[]).length===0,empty:M,children:J(Fn,{buckets:g.data??[],by:s.by,since:l,until:u,metric:c,names:ee})})]})}var or=ar;export{or as component};