omnigateway 0.15.4 → 0.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/bin/omni.js +193 -187
- package/gateway.js +324 -318
- package/package.json +1 -1
- package/public/assets/{_app-kgxk7ake.js → _app-hj6zm190.js} +1 -1
- package/public/assets/{_app.accounts-3jabfvcs.js → _app.accounts-p4cfzwak.js} +1 -1
- package/public/assets/{_app.console-y69399jc.js → _app.console-9b5jsgb2.js} +1 -1
- package/public/assets/{_app.database-r5kg3838.js → _app.database-gxm9r50d.js} +1 -1
- package/public/assets/{_app.index-22awhb38.js → _app.index-z62y96gv.js} +1 -1
- package/public/assets/{_app.keys-7vh81n1w.js → _app.keys-9hcrg2sv.js} +1 -1
- package/public/assets/{_app.logs-rssv5a6z.js → _app.logs-wszj7dxd.js} +1 -1
- package/public/assets/_app.models-msggftd4.js +1 -0
- package/public/assets/{_app.plugins.$pluginId-e4xva5tz.js → _app.plugins.$pluginId-c18d9z9g.js} +1 -1
- package/public/assets/{_app.settings-fqzg7wnn.js → _app.settings-1kbbc55c.js} +1 -1
- package/public/assets/{_app.usage-32vje0s7.js → _app.usage-j1q7t12v.js} +1 -1
- package/public/assets/{client-d3mjj5ey.js → client-85yjh3yc.js} +1 -1
- package/public/assets/{index-v31xha7b.js → index-0egbh3rb.js} +1 -1
- package/public/assets/{index-f7t0kve8.js → index-330vgx7r.js} +1 -1
- package/public/assets/{index-dq2f7yk0.js → index-3a10vc18.js} +1 -1
- package/public/assets/{index-nnpqs2w6.js → index-3habqvw2.js} +1 -1
- package/public/assets/{index-938qd7p2.js → index-40vm2qxc.js} +1 -1
- package/public/assets/{index-sbe0ydnc.js → index-6v3e0r4x.js} +1 -1
- package/public/assets/{index-z7c4qz9d.js → index-96zs0ekh.js} +1 -1
- package/public/assets/{index-zkt5p0qd.js → index-9pefp4zb.js} +1 -1
- package/public/assets/{index-85cnhw3e.js → index-9vqvqrvt.js} +1 -1
- package/public/assets/{index-hk28xepa.js → index-dny52xdk.js} +1 -1
- package/public/assets/{index-fcew0gga.js → index-e7nx5832.js} +1 -1
- package/public/assets/{index-8bewp9z1.js → index-h41dkv54.js} +1 -1
- package/public/assets/{index-p9vbm21a.js → index-qkhn11a8.js} +3 -3
- package/public/assets/{index-0j7sghrn.js → index-qtdmekxc.js} +1 -1
- package/public/assets/{index-d09hs7ex.js → index-ywek2f98.js} +1 -1
- package/public/assets/{index-xdyjb1an.js → index-zqfj5xfa.js} +1 -1
- package/public/assets/{login-p97b96t9.js → login-55p1x35d.js} +1 -1
- package/public/index.html +1 -1
- package/public/shared/dashboard-sdk.js +1 -1
- package/public/assets/_app.models-82m2f0kr.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i}from"/assets/index-
|
|
1
|
+
import{i}from"/assets/index-qkhn11a8.js";var e={name:"plus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]};e.node;var Qe=i(e);
|
|
2
2
|
export{Qe};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t}from"/assets/index-
|
|
1
|
+
import{t}from"/assets/index-qkhn11a8.js";import n from"styled-components";import{jsx as e,jsxs as l}from"react/jsx-runtime";var s=n.div.withConfig({displayName:"Readout__Frame"})(["display:flex;flex-direction:column;gap:6px;padding:",";background:",";border:1px solid ",";border-radius:",";min-width:0;"],({theme:o})=>`${o.space(2)} ${o.space(3)}`,({theme:o})=>o.color.panel,({theme:o})=>o.color.rule,({theme:o})=>o.radius.panel),c=n.div.withConfig({displayName:"Readout__Value"})(["display:flex;align-items:baseline;flex-wrap:wrap;gap:4px;font-family:",";font-variant-numeric:tabular-nums;font-size:24px;font-weight:500;letter-spacing:-0.02em;line-height:1.1;color:",";"],({theme:o})=>o.font.mono,({theme:o,$tone:a})=>a==="ok"?o.color.ok:a==="warn"?o.color.warn:a==="down"?o.color.down:o.color.ink),u=n.span.withConfig({displayName:"Readout__Unit"})(["font-size:11px;font-weight:400;color:",";"],({theme:o})=>o.color.inkFaint),f=n.div.withConfig({displayName:"Readout__Trace"})(["margin-top:2px;"]);function D({legend:o,value:a,unit:i,tone:r,trace:d,className:p}){return l(s,{className:p,children:[e(t,{children:o}),l(c,{...r===void 0?{}:{$tone:r},children:[e("span",{children:a}),i===void 0?null:e(u,{children:i})]}),d===void 0?null:e(f,{children:d})]})}
|
|
2
2
|
export{D};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i,dt,a}from"/assets/index-
|
|
1
|
+
import{i,dt,a}from"/assets/index-qkhn11a8.js";var m={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};m.node;var s=i(m);var u={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};u.node;var p=i(u);import c,{keyframes as h}from"styled-components";import{jsx as o,jsxs as t}from"react/jsx-runtime";var n=new Intl.NumberFormat("en-US");function ko(e){return`${n.format(e.inputTokens)} input, ${n.format(e.outputTokens)} output, ${n.format(e.cacheReadTokens)} cache read, ${n.format(e.cacheWriteTokens)} cache write tokens`}var l=c.span.withConfig({displayName:"TokenBreakdown__Breakdown"})(["display:inline-flex;align-items:center;flex-wrap:wrap;gap:6px;white-space:nowrap;"]),r=c.span.withConfig({displayName:"TokenBreakdown__Part"})(["display:inline-flex;align-items:center;line-height:1;gap:2px;svg{width:12px;height:12px;stroke-width:1.75;}"]),k=h(["from{clip-path:inset(0 2ch 0 0);}to{clip-path:inset(0 0 0 0);}"]),w=c.span.withConfig({displayName:"TokenBreakdown__ProcessingDots"})(["display:inline-block;width:3ch;vertical-align:bottom;animation:"," 1.5s steps(2,end) infinite;@media (prefers-reduced-motion:reduce){animation:none;}"],k);function vr(){return t("span",{"aria-hidden":"true",children:["processing",o(w,{children:"..."})]})}function At({tokens:e}){let d=ko(e);return t(l,{role:"img","aria-label":d,title:d,children:[t(r,{"aria-hidden":"true",children:[o(s,{}),a(e.inputTokens)]}),t(r,{"aria-hidden":"true",children:[o(p,{}),a(e.outputTokens)]}),t(r,{"aria-hidden":"true",children:[o(dt,{}),o(s,{}),a(e.cacheReadTokens)]}),t(r,{"aria-hidden":"true",children:[o(dt,{}),o(p,{}),a(e.cacheWriteTokens)]})]})}
|
|
2
2
|
export{ko,vr,At};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ut,n,t,o,r,Er,_t,Zo,Jo,ge,h,Io,Gr}from"/assets/index-
|
|
1
|
+
import{ut,n,t,o,r,Er,_t,Zo,Jo,ge,h,Io,Gr}from"/assets/index-qkhn11a8.js";import{v,m}from"/assets/index-h41dkv54.js";import{ra}from"/assets/index-d0t1fj1y.js";import{useState as w}from"react";import l from"styled-components";import{jsx as a,jsxs as y}from"react/jsx-runtime";var z=l.div.withConfig({displayName:"login__Screen"})(["display:flex;align-items:center;justify-content:center;min-height:100vh;padding:",";"],({theme:e})=>e.space(4)),A=l(Io).withConfig({displayName:"login__Card"})(["width:min(380px,100%);"]),D=l.div.withConfig({displayName:"login__Head"})(["display:flex;align-items:center;gap:8px;padding:",";border-bottom:1px solid ",";background:",";"," font-stretch:74%;font-weight:700;letter-spacing:0.2em;font-size:12px;text-transform:uppercase;"],({theme:e})=>`${e.space(3)} ${e.space(4)}`,({theme:e})=>e.color.rule,({theme:e})=>e.color.panelSunk,Er),H=l.form.withConfig({displayName:"login__Body"})(["display:flex;flex-direction:column;gap:",";padding:",";"],({theme:e})=>e.space(3),({theme:e})=>e.space(4)),M=l.p.withConfig({displayName:"login__Blurb"})(["font-size:12.5px;color:",";"],({theme:e})=>e.color.inkDim),N=l.p.withConfig({displayName:"login__Problem"})(["font-size:12px;color:",";"],({theme:e})=>e.color.down),O=l.p.withConfig({displayName:"login__Ended"})(["font-size:12px;color:",";"],({theme:e})=>e.color.warn),W=l.button.withConfig({displayName:"login__Tab"})(["border:1px solid ",";background:",";color:",";border-radius:",";padding:"," ",";font:inherit;font-size:12px;cursor:pointer;"],({theme:e,$on:s})=>s===!0?e.color.accent:e.color.rule,({theme:e,$on:s})=>s===!0?e.color.accentWash:"transparent",({theme:e,$on:s})=>s===!0?e.color.ink:e.color.inkDim,({theme:e})=>e.radius.control,({theme:e})=>e.space(1),({theme:e})=>e.space(2));function oo(){let e=ut(),{next:s,reason:T}=Gr.useSearch(),c=_t(),C=Zo(),k=Jo(),[p,x]=w(""),[_,B]=w(""),[P,u]=w(null),[g,R]=w("admin"),d=c.data?.configured===!1,S=[{id:"admin",label:"Operator",blurb:"This console is for the operator of this gateway."},...c.data?.viewerConfigured===!0?[{id:"viewer",label:"Read-only",blurb:"Everything the operator can see, and nothing they can change."}]:[],{id:"client",label:"API key",blurb:"Your own usage, limits and requests. Sign in with a gateway API key."}],b=g==="client",E=ra(T),I=C.isPending||k.isPending||c.isLoading,L=()=>{if(b){e({to:"/client"});return}e({to:s?.startsWith("/")===!0?s:"/"})},F=(i)=>{if(i.preventDefault(),u(null),d){if(p!==_){u("The two passwords do not match.");return}k.mutate(p,{onSuccess:L,onError:(f)=>u(h(f))});return}C.mutate({mode:g,secret:p},{onSuccess:L,onError:()=>u(b?"That API key was not accepted. It may have been revoked.":"That password does not match. Try again.")})};return a(z,{children:y(A,{children:[y(D,{children:[a(ge,{state:c.isError?"down":"ok",label:c.isError?"gateway unreachable":"gateway reachable"}),"Omnigateway"]}),y(H,{onSubmit:F,children:[c.isError?a(N,{children:"The gateway is not answering. Check that it is running, then reload."}):null,E===null?null:a(O,{role:"status",children:E}),y(r,{$gap:1,children:[a(t,{children:d?"First run":"Sign in"}),a(M,{children:d?"Set the operator password for this gateway. It is the only account, and it is stored hashed.":S.find((i)=>i.id===g)?.blurb??""})]}),d||S.length<2?null:a(o,{$gap:1,$wrap:!0,role:"tablist","aria-label":"Sign in as",children:S.map((i)=>a(W,{type:"button",role:"tab","aria-selected":i.id===g,$on:i.id===g,onClick:()=>{R(i.id),x(""),u(null)},children:i.label},i.id))}),a(m,{label:b?"API key":"Password",children:(i)=>a(v,{...i,type:"password",autoFocus:!0,autoComplete:d?"new-password":b?"off":"current-password",value:p,onChange:(f)=>x(f.target.value)})}),d?a(m,{label:"Confirm password",children:(i)=>a(v,{...i,type:"password",autoComplete:"new-password",value:_,onChange:(f)=>B(f.target.value)})}):null,P===null?null:a(N,{role:"alert",children:P}),a(o,{children:a(n,{type:"submit",$variant:"primary",disabled:I||p.length===0,children:d?"Set password and sign in":"Sign in"})})]})]})})}export{oo as component};
|
package/public/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e}from"./chunks/react-mv7wrde1.js";import{t}from"./chunks/react-z0w6knjn.js";var T="0.1.
|
|
1
|
+
import{e}from"./chunks/react-mv7wrde1.js";import{t}from"./chunks/react-z0w6knjn.js";var T="0.1.10";class y extends Error{status;code;constructor(i,n,r){super(r);this.name="PluginApiError",this.status=i,this.code=n}get isUnauthenticated(){return this.status===401||this.code==="AUTH"}}var A=/%2e/i;function h(i,n){if(n.length===0)throw TypeError(`plugin api ${i} must not be empty`);if(n.startsWith("/"))throw TypeError(`plugin api ${i} must be relative to the plugin's own prefix, got ${JSON.stringify(n)}`);if(n.includes("..")||A.test(n))throw TypeError(`plugin api ${i} must not escape the plugin's own prefix, got ${JSON.stringify(n)}`)}function w(i,n){if(h("plugin id",i),i.includes("/"))throw TypeError(`plugin api plugin id must be a single path segment, got ${i}`);return h("path",n),`/api/plugins/${i}/${n}`}function P(i){if(typeof i!=="object"||i===null)return!1;let n=i.error;if(typeof n!=="object"||n===null)return!1;return typeof n.message==="string"}async function f(i,n,r,o,p){let g=w(i,r),d={method:n,credentials:"same-origin",headers:o===void 0?{}:{"content-type":"application/json"},...o===void 0?{}:{body:JSON.stringify(o)},...p===void 0?{}:{signal:p}},s=await fetch(g,d),u=null;if(s.status!==204){let l=await s.text();if(l.length>0)try{u=JSON.parse(l)}catch{u=null}}if(!s.ok){let l=P(u)?u.error.code??"INTERNAL":"INTERNAL",S=P(u)?u.error.message:`request failed with status ${s.status}`;throw new y(s.status,String(l),S)}return u}function C(i){return h("plugin id",i),{get:(n,r)=>f(i,"GET",n,void 0,r),post:(n,r)=>f(i,"POST",n,r,void 0),put:(n,r)=>f(i,"PUT",n,r,void 0),del:(n)=>f(i,"DELETE",n,void 0,void 0)}}var x=new Map;function b(i){let n=x.get(i);if(n!==void 0)return n;let r=C(i);return x.set(i,r),r}var c=t(e(),1);var a=t(e(),1),L={status:"poll",pushed:()=>!1},k=a.createContext(null);function E({children:i,connection:n=L,channels:r}){let[o,p]=a.useState(!0),g=a.useCallback(()=>p((s)=>!s),[]),d=a.useMemo(()=>({live:o,toggle:g,connection:n,...r===void 0?{}:{channels:r},cadence:(s,u)=>{if(!o)return!1;if(u===void 0)return s;return n.pushed(u)?!1:s}}),[o,g,n,r]);return a.createElement(k,{value:d},i)}function m(){return a.use(k)??{live:!1,toggle:()=>{},cadence:()=>!1,connection:{status:"offline",pushed:()=>!1}}}function v(i,n,r){let{channels:o}=m(),p=`plugin:${i}:${n}`,[g,d]=c.useState("idle"),s=c.useRef(r);c.useEffect(()=>{s.current=r}),c.useEffect(()=>{if(o===void 0)return;return o.subscribe(p,(l)=>{switch(l.kind){case"frame":s.current(l.payload);return;case"open":d("open");return;case"refused":d("refused");return;case"closed":d("idle");return}})},[o,p]);let u=c.useCallback((l)=>{if(o===void 0||g!=="open")return!1;return o.send(p,l)},[o,g,p]);return{status:g,topic:p,send:u}}var N=["--rack","--panel","--panel-sunk","--panel-raised","--rule","--rule-strong","--ink","--ink-dim","--ink-faint","--accent","--accent-ink","--accent-wash","--ok","--warn","--down","--ok-wash","--warn-wash","--down-wash","--p-anthropic","--p-openai","--p-kimi","--p-kilo","--p-grok","--p-antigravity","--p-muse","--p-qoder","--p-custom","--grid-line","--shadow"];function R(i){return i}export{N as CSS_VARIABLES,E as LiveProvider,y as PluginApiError,T as SDK_VERSION,C as createPluginApi,R as definePluginUI,w as pluginApiPath,m as useLive,b as usePluginApi,v as usePluginChannel};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n,P,t,d,o,r,S,M,fe,z,pe,H,he,mn,hn,gn,i,On,oe,I,h,x,b,ee,k,f}from"/assets/index-p9vbm21a.js";import{R,tt}from"/assets/index-f7t0kve8.js";import{W}from"/assets/index-dq2f7yk0.js";import{C,vt}from"/assets/index-fcew0gga.js";import{re}from"/assets/index-wjqdtafp.js";import{v,m,de}from"/assets/index-8bewp9z1.js";import{br}from"/assets/index-85cnhw3e.js";import{Qe}from"/assets/index-0j7sghrn.js";import{xt}from"/assets/index-nnpqs2w6.js";var Te={name:"play",size:24,node:[["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"}]]};Te.node;var $e=i(Te);import{useEffect as bt,useState as yt}from"react";import le from"styled-components";import{useState as ge}from"react";import X from"styled-components";import{jsx as E,jsxs as B}from"react/jsx-runtime";var Pe=["tier","health","quota","cost","latency","load"],Xe={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"},Ye=X.li.withConfig({displayName:"ExplainPanel__Candidate"})(["padding:"," 0;border-bottom:1px solid ",";&:last-child{border-bottom:0;}"],({theme:e})=>e.space(2),({theme:e})=>e.color.rule),Ze=X(d).withConfig({displayName:"ExplainPanel__Rank"})(["width:22px;color:",";flex:none;"],({theme:e})=>e.color.inkFaint),et=X(C).withConfig({displayName:"ExplainPanel__Winner"})(["border-color:",";color:",";background:",";"],({theme:e})=>e.color.ok,({theme:e})=>e.color.ok,({theme:e})=>e.color.okWash),ot=X.div.withConfig({displayName:"ExplainPanel__Terms"})(["display:grid;grid-template-columns:repeat(auto-fit,minmax(112px,1fr));gap:",";margin-top:",";padding-left:30px;"],({theme:e})=>e.space(2),({theme:e})=>e.space(2)),nt=X.div.withConfig({displayName:"ExplainPanel__TermCell"})(["display:flex;flex-direction:column;gap:3px;min-width:0;"]),rt=X.div.withConfig({displayName:"ExplainPanel__TermHead"})(["display:flex;align-items:baseline;justify-content:space-between;gap:6px;"]),it=X.li.withConfig({displayName:"ExplainPanel__Excluded"})(["display:flex;align-items:center;gap:",";padding:5px 0;"],({theme:e})=>e.space(2)),at=X(o).withConfig({displayName:"ExplainPanel__Probe"})(["gap:",";flex-wrap:wrap;"],({theme:e})=>e.space(3)),be=X.label.withConfig({displayName:"ExplainPanel__Toggled"})(["display:flex;align-items:center;gap:6px;cursor:pointer;font-size:12.5px;"]),lt=X.p.withConfig({displayName:"ExplainPanel__Problem"})(["font-size:12px;color:",";"],({theme:e})=>e.color.down);function Se(e,a,c){return(e[a]??0)*c[a]}function Re({modelId:e}){let[a,c]=ge({tools:!1,images:!1,reasoning:!1}),[l,s]=ge(null),[w,q]=ge(null),N=he(),V=gn(),u=N.data?.weights,Q=()=>{if(e===null)return;q(null),V.mutate({modelId:e,need:a},{onSuccess:(y)=>s(y),onError:(y)=>{s(null),q(h(y))}})},G=new Map(Pe.map((y)=>[y,Math.max(0.0001,...(l?.candidates??[]).map((j)=>u===void 0?0:Math.abs(Se(j.reasons,y,u))))]));return E(f,{legend:"Explain",meta:e??"no model selected",actions:B(n,{type:"button",$size:"sm",$variant:"primary",disabled:e===null||V.isPending,onClick:Q,children:[E($e,{}),V.isPending?"Ranking…":"Rank candidates"]}),children:B(r,{$gap:3,children:[B(r,{$gap:1,children:[E(t,{children:"Pretend the request needs"}),B(at,{children:[B(be,{children:[E(W,{checked:a.tools,label:"Probe request uses tools",onCheckedChange:(y)=>c({...a,tools:y})}),"Tools"]}),B(be,{children:[E(W,{checked:a.images,label:"Probe request includes an image",onCheckedChange:(y)=>c({...a,images:y})}),"Images"]}),B(be,{children:[E(W,{checked:a.reasoning,label:"Probe request asks for reasoning",onCheckedChange:(y)=>c({...a,reasoning:y})}),"Reasoning"]})]})]}),w===null?null:E(lt,{children:w}),l===null?E(I,{legend:"Not ranked yet",message:e===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(o,{$gap:2,$wrap:!0,children:[E(C,{$tone:"accent",children:l.strategy}),l.deterministic?null:E(C,{$tone:"warn",children:"order varies per request"}),E(S,{}),B(t,{children:[l.candidates.length," eligible · ",l.excluded.length," filtered out"]})]}),l.candidates.length===0?E(I,{legend:"Nothing eligible",message:"Every target was filtered out. The reasons below say which rule removed each one."}):E("ul",{children:l.candidates.map((y,j)=>B(Ye,{children:[B(o,{$gap:2,children:[E(Ze,{children:j+1}),E(vt,{provider:y.provider}),E(M,{style:{maxWidth:"22ch"},children:y.credentialLabel}),E(d,{$dim:!0,children:y.model}),B(C,{children:["tier ",y.tier]}),E(S,{}),j===0?E(et,{children:"would be used"}):null,E(d,{children:y.score.toFixed(2)})]}),u===void 0?null:E(ot,{children:Pe.map((L)=>{let D=Se(y.reasons,L,u),U=G.get(L)??1;return B(nt,{title:Xe[L],children:[B(rt,{children:[E(t,{children:L}),E(d,{$dim:!0,$size:"10.5px",children:D.toFixed(2)})]}),E(re,{fraction:Math.abs(D)/U,height:4,tone:"var(--accent)",label:`${L} contributes ${D.toFixed(2)} of ${y.score.toFixed(2)}`})]},L)})})]},`${y.credentialId}:${y.model}`))}),l.excluded.length===0?null:B(r,{$gap:1,children:[E(t,{children:"Filtered out"}),E("ul",{children:l.excluded.map((y)=>B(it,{children:[E(d,{$dim:!0,children:y.model}),E(d,{$dim:!0,children:y.credentialId}),E(S,{}),E(C,{$tone:y.reason.startsWith("capability")?"warn":"down",children:y.reason})]},`${y.credentialId}:${y.model}:${y.reason}`))})]})]})]})})}import{useEffect as mt,useState as ce}from"react";import ue from"styled-components";function Ee(e,a,c){return z(e,a)?.models.find((l)=>l.id===c)}function Ie(e,a,c){let l=z(e,a);if(l===void 0)return null;return l.models.find((s)=>s.id===c)?.auth??l.authTypes}var ye=[{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."}],Me=0;function We(){return Me+=1,`target-${Me}`}function se(e,a,c){let l=Ee(e,a,c)?.pricing;if(l===void 0)return null;return{costInput:String(l.input),costOutput:String(l.output),costCacheRead:String(l.cacheRead),costCacheWrite5m:String(l.cacheWrite5m),costCacheWrite1h:String(l.cacheWrite1h)}}function _e(e,a,c){let l=Ee(e,a,c)?.limits;if(l===void 0)return null;return{contextWindow:String(l.contextWindow),maxOutputTokens:String(l.maxOutputTokens)}}var st={oauth:"OAuth",apiKey:"an API key"};function Ne(e){return e.map((a)=>st[a]).join(" or ")}function De(e){let a=Object.create(null);for(let c of e){let l=a[c.provider]??[];if(!l.includes(c.authType))l.push(c.authType);a[c.provider]=l}return a}function Ae(e,a,c,l){let s=l[a];if(s===void 0||s.length===0)return!0;let w=Ie(e,a,c);if(w===null)return!0;return w.some((q)=>s.includes(q))}function Le(e,a,c){let l=z(e,a);if(l===void 0)return[];return l.models.filter((s)=>Ae(e,a,s.id,c))}function Oe(e,a,c,l){if(c.trim().length===0||Ae(e,a,c,l))return null;let s=l[a]??[],w=Ie(e,a,c)??[];return`${a} serves this model to ${Ne(w)} only, and every ${a} account here is ${Ne(s)}. Requests routed here will fail.`}function Ce(e,a){let c={provider:e.provider,endpointId:e.endpointId};return a.filter((l)=>On(c,l)).map((l)=>({id:l.id,label:l.accountEmail??l.label}))}function Fe(e,a,c){if(e.length===0)return null;if(c.length===0)return null;if(Ce(a,c).some((l)=>l.id===e))return null;return"No connected account has this id. Requests routed here will fail rather than falling back to another account."}function Be(e,a){return{...e,endpointId:a,...a===e.endpointId?{}:{credentialId:""}}}function ze(e,a,c){return{...a,...c,...se(e,c.provider,c.model)??{},...c.provider===a.provider?{}:{credentialId:""},contextWindow:"",maxOutputTokens:""}}function ve(e,a){let c=a??(e[0]?.id??"anthropic"),l=z(e,c)?.defaultModel??"",s=se(e,c,l);return{key:We(),provider:c,endpointId:"",model:l,tier:"1",weight:"1",costInput:s?.costInput??"0",costOutput:s?.costOutput??"0",costCacheRead:s?.costCacheRead??"",costCacheWrite5m:s?.costCacheWrite5m??"",costCacheWrite1h:s?.costCacheWrite1h??"",contextWindow:"",maxOutputTokens:"",credentialId:"",tools:!0,images:!0,reasoning:!0}}function xe(e){return{id:"",strategy:"score",isAlias:!1,targets:[ve(e)]}}function ke(e){return{id:e.id,strategy:e.strategy,isAlias:e.isAlias,targets:e.targets.map((a)=>({key:We(),provider:a.provider,endpointId:a.provider==="custom"?a.endpointId??"":"",model:a.model,tier:String(a.tier),weight:String(a.weight),costInput:String(a.costPerMTok.input),costOutput:String(a.costPerMTok.output),costCacheRead:a.costPerMTok.cacheRead===void 0?"":String(a.costPerMTok.cacheRead),costCacheWrite5m:a.costPerMTok.cacheWrite5m===void 0?"":String(a.costPerMTok.cacheWrite5m),costCacheWrite1h:a.costPerMTok.cacheWrite1h===void 0?"":String(a.costPerMTok.cacheWrite1h),contextWindow:a.contextWindow===void 0?"":String(a.contextWindow),maxOutputTokens:a.maxOutputTokens===void 0?"":String(a.maxOutputTokens),credentialId:a.credentialId??"",tools:a.capabilities.tools,images:a.capabilities.images,reasoning:a.capabilities.reasoning}))}}function qe(e){let a=e.id.trim();if(a.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 c=[];for(let[l,s]of e.targets.entries()){let w=`Target ${l+1}`,q=s.endpointId.trim(),N=s.credentialId.trim();if(s.provider==="custom"&&q.length===0)return{ok:!1,problem:`${w} needs a custom endpoint.`};let V=s.model.trim();if(V.length===0)return{ok:!1,problem:`${w} needs a provider model name.`};let u=Number(s.tier);if(!Number.isInteger(u)||u<1)return{ok:!1,problem:`${w}: tier must be a whole number of 1 or more.`};let Q=Number(s.weight);if(!Number.isFinite(Q)||Q<=0)return{ok:!1,problem:`${w}: weight must be greater than zero.`};let G=Number(s.costInput),y=Number(s.costOutput);if(!Number.isFinite(G)||G<0||!Number.isFinite(y)||y<0)return{ok:!1,problem:`${w}: prices cannot be negative.`};let j=s.costCacheRead.trim().length>0,L=Number(s.costCacheRead);if(j&&(!Number.isFinite(L)||L<0))return{ok:!1,problem:`${w}: the cache-read price cannot be negative.`};let D=s.costCacheWrite5m.trim().length>0,U=Number(s.costCacheWrite5m);if(D&&(!Number.isFinite(U)||U<0))return{ok:!1,problem:`${w}: the 5m cache-write price must be a number of 0 or more.`};let Z=s.costCacheWrite1h.trim().length>0,Y=Number(s.costCacheWrite1h);if(Z&&(!Number.isFinite(Y)||Y<0))return{ok:!1,problem:`${w}: the 1h cache-write price must be a number of 0 or more.`};let p=s.contextWindow.trim().length>0,T=Number(s.contextWindow);if(p&&(!Number.isInteger(T)||T<1))return{ok:!1,problem:`${w}: the context window must be a whole number of tokens.`};let O=s.maxOutputTokens.trim().length>0,J=Number(s.maxOutputTokens);if(O&&(!Number.isInteger(J)||J<1))return{ok:!1,problem:`${w}: the output limit must be a whole number of tokens.`};c.push({provider:s.provider,...s.provider==="custom"?{endpointId:q}:{},model:V,tier:u,weight:Q,costPerMTok:{input:G,output:y,...j?{cacheRead:L}:{},...D?{cacheWrite5m:U}:{},...Z?{cacheWrite1h:Y}:{}},...p?{contextWindow:T}:{},...O?{maxOutputTokens:J}:{},...N.length>0?{credentialId:N}:{},capabilities:{tools:s.tools,images:s.images,reasoning:s.reasoning}})}return{ok:!0,model:{id:a,strategy:e.strategy,isAlias:e.isAlias,targets:c}}}import{useId as dt}from"react";import ie from"styled-components";import{jsx as g,jsxs as _}from"react/jsx-runtime";var ct=ie.fieldset.withConfig({displayName:"TargetEditor__Frame"})(["border:1px solid ",";border-left:3px solid ",";border-radius:",";padding:",";margin:0;background:",";display:flex;flex-direction:column;gap:",";min-width:0;"],({theme:e})=>e.color.rule,({$provider:e})=>oe(e),({theme:e})=>e.radius.control,({theme:e})=>e.space(3),({theme:e})=>e.color.panelSunk,({theme:e})=>e.space(3)),pt=ie.div.withConfig({displayName:"TargetEditor__Cells"})(["display:grid;grid-template-columns:minmax(140px,1.4fr) minmax(160px,2fr) 72px 72px;gap:",";align-items:end;@media (max-width:720px){grid-template-columns:minmax(0,1fr) minmax(0,1fr);}"],({theme:e})=>e.space(2)),He=ie.div.withConfig({displayName:"TargetEditor__Prices"})(["display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:",";align-items:end;"],({theme:e})=>e.space(2)),K=ie.div.withConfig({displayName:"TargetEditor__Cell"})(["display:flex;flex-direction:column;gap:4px;min-width:0;"]),ut=ie(o).withConfig({displayName:"TargetEditor__Caps"})(["gap:",";flex-wrap:wrap;"],({theme:e})=>e.space(3)),Ve=ie.p.withConfig({displayName:"TargetEditor__Unreachable"})(["font-size:11.5px;color:",";margin:0;"],({theme:e})=>e.color.down),we=ie.label.withConfig({displayName:"TargetEditor__Cap"})(["display:flex;align-items:center;gap:6px;cursor:pointer;"]);function Ue({target:e,index:a,onChange:c,onRemove:l,removable:s,catalog:w,endpoints:q,held:N,credentials:V}){let u=dt(),Q=z(w,e.provider),G=Le(w,e.provider,N),y=Oe(w,e.provider,e.model,N),j=Ce(e,V),L=Fe(e.credentialId,e,V),D=(p,T)=>{c({...e,[p]:T})},U=se(w,e.provider,e.model),Z=_e(w,e.provider,e.model),Y=(p)=>{c(ze(w,e,p))};return _(ct,{$provider:e.provider,children:[_(o,{$gap:2,children:[_(t,{as:"legend",children:["Target ",a+1]}),g(S,{}),g(P,{type:"button",$variant:"ghost",$size:"sm",disabled:!s,"aria-label":`Remove target ${a+1}`,title:s?`Remove target ${a+1}`:"A model needs at least one target",onClick:l,children:g(xt,{})})]}),_(pt,{children:[_(K,{children:[g(t,{as:"label",htmlFor:`${u}-provider`,children:"Provider"}),g(R,{id:`${u}-provider`,value:e.provider,options:[...w.map((p)=>({value:p.id,label:p.label})),...Q===void 0?[{value:e.provider,label:`${e.provider} (not in the catalog)`}]:[]],onValueChange:(p)=>{let T=p,O=z(w,T),J=O?.models.some((ae)=>ae.id===e.model)??!1;Y({provider:T,model:J?e.model:O?.defaultModel??""})}})]}),e.provider==="custom"?_(K,{children:[g(t,{as:"label",htmlFor:`${u}-endpoint`,children:"Endpoint"}),g(R,{id:`${u}-endpoint`,value:e.endpointId,options:[{value:"",label:"Choose endpoint"},...q.map((p)=>({value:p.id,label:p.label}))],onValueChange:(p)=>c(Be(e,p))})]}):null,_(K,{children:[g(t,{as:"label",htmlFor:`${u}-model`,children:"Provider model"}),g(tt,{id:`${u}-model`,value:e.model,placeholder:Q?.defaultModel??"",suggestions:G.map((p)=>({value:p.id,label:p.id,detail:p.label===p.id?void 0:p.label})),onValueChange:(p)=>Y({provider:e.provider,model:p})}),y===null?null:g(Ve,{role:"note",children:y})]}),_(K,{children:[g(t,{as:"label",htmlFor:`${u}-tier`,children:"Tier"}),g(de,{id:`${u}-tier`,min:1,step:1,value:e.tier,onChange:(p)=>D("tier",p.target.value)})]}),_(K,{children:[g(t,{as:"label",htmlFor:`${u}-weight`,children:"Weight"}),g(de,{id:`${u}-weight`,min:0,step:0.1,value:e.weight,onChange:(p)=>D("weight",p.target.value)})]})]}),g(r,{$gap:1,children:_(K,{children:[g(t,{as:"label",htmlFor:`${u}-account`,children:"Account"}),g(R,{id:`${u}-account`,value:e.credentialId,options:[{value:"",label:"Any account"},...j.map((p)=>({value:p.id,label:p.label})),...L===null?[]:[{value:e.credentialId,label:`${e.credentialId} (removed)`}]],onValueChange:(p)=>D("credentialId",p)}),L===null?null:g(Ve,{role:"note",children:L})]})}),_(r,{$gap:1,children:[_(o,{$gap:2,children:[g(t,{children:"Price per million tokens"}),g(S,{}),U===null?g(t,{as:"span",children:"not in the catalog — price it yourself"}):_(n,{type:"button",$size:"sm",$variant:"ghost",disabled:e.costInput===U.costInput&&e.costOutput===U.costOutput&&e.costCacheRead===U.costCacheRead&&e.costCacheWrite5m===U.costCacheWrite5m&&e.costCacheWrite1h===U.costCacheWrite1h,onClick:()=>c({...e,...U}),children:[g(br,{}),"Use list price"]})]}),_(He,{children:[_(K,{children:[g(t,{as:"label",htmlFor:`${u}-in`,children:"Input"}),g(de,{id:`${u}-in`,min:0,step:0.01,value:e.costInput,onChange:(p)=>D("costInput",p.target.value)})]}),_(K,{children:[g(t,{as:"label",htmlFor:`${u}-out`,children:"Output"}),g(de,{id:`${u}-out`,min:0,step:0.01,value:e.costOutput,onChange:(p)=>D("costOutput",p.target.value)})]}),_(K,{children:[g(t,{as:"label",htmlFor:`${u}-cache`,children:"Cache read"}),g(de,{id:`${u}-cache`,min:0,step:0.01,placeholder:"same as input",value:e.costCacheRead,onChange:(p)=>D("costCacheRead",p.target.value)})]}),_(K,{children:[g(t,{as:"label",htmlFor:`${u}-write5m`,children:"Cache write 5m"}),g(de,{id:`${u}-write5m`,min:0,step:0.01,placeholder:"1.25x input",value:e.costCacheWrite5m,onChange:(p)=>D("costCacheWrite5m",p.target.value)})]}),_(K,{children:[g(t,{as:"label",htmlFor:`${u}-write1h`,children:"Cache write 1h"}),g(de,{id:`${u}-write1h`,min:0,step:0.01,placeholder:"2x input",value:e.costCacheWrite1h,onChange:(p)=>D("costCacheWrite1h",p.target.value)})]})]})]}),_(r,{$gap:1,children:[_(o,{$gap:2,children:[g(t,{children:"Token limits"}),g(S,{}),Z===null?g(t,{as:"span",children:"not in the catalog — state them yourself"}):g(t,{as:"span",children:"left empty, the published figures are used — and for an OpenAI target, the narrower ones its OAuth backend allows"})]}),_(He,{children:[_(K,{children:[g(t,{as:"label",htmlFor:`${u}-context`,children:"Context window"}),g(de,{id:`${u}-context`,min:1,step:1024,placeholder:Z?.contextWindow??"published",value:e.contextWindow,onChange:(p)=>D("contextWindow",p.target.value)})]}),_(K,{children:[g(t,{as:"label",htmlFor:`${u}-maxout`,children:"Max output"}),g(de,{id:`${u}-maxout`,min:1,step:1024,placeholder:Z?.maxOutputTokens??"published",value:e.maxOutputTokens,onChange:(p)=>D("maxOutputTokens",p.target.value)})]})]})]}),_(r,{$gap:1,children:[g(t,{children:"Capabilities"}),_(ut,{children:[_(we,{children:[g(W,{checked:e.tools,label:`Target ${a+1} supports tools`,onCheckedChange:(p)=>D("tools",p)}),"Tools"]}),_(we,{children:[g(W,{checked:e.images,label:`Target ${a+1} supports images`,onCheckedChange:(p)=>D("images",p)}),"Images"]}),_(we,{children:[g(W,{checked:e.reasoning,label:`Target ${a+1} supports reasoning`,onCheckedChange:(p)=>D("reasoning",p)}),"Reasoning"]})]})]})]})}import{jsx as F,jsxs as te,Fragment as Ge}from"react/jsx-runtime";var Ke=ue.p.withConfig({displayName:"ModelEditor__Blurb"})(["font-size:11.5px;color:",";"],({theme:e})=>e.color.inkDim),gt=ue.p.withConfig({displayName:"ModelEditor__Problem"})(["font-size:12px;color:",";"],({theme:e})=>e.color.down),ht=ue.p.withConfig({displayName:"ModelEditor__Saved"})(["font-size:12px;color:",";"],({theme:e})=>e.color.ok),ft=ue(o).withConfig({displayName:"ModelEditor__AliasRow"})(["gap:8px;"]);function je({model:e,onSaved:a,onDeleted:c}){let l=fe().data??[],[s,w]=ce(()=>e===null?xe(l):ke(e)),[q,N]=ce(null),[V,u]=ce(!1),[Q,G]=ce(!1),y=mn(),j=hn(),L=pe(),D=De(L.data??[]),U=(L.data??[]).filter((T)=>T.provider==="custom").map((T)=>({id:String(T.providerData.endpointId??""),label:String(T.providerData.endpointLabel??T.providerData.endpointId??"")})).filter((T,O,J)=>T.id.length>0&&J.findIndex((ae)=>ae.id===T.id)===O),Z=e?.id??null;mt(()=>{w(e===null?xe(l):ke(e)),N(null),u(!1)},[Z]);let Y=ye.find((T)=>T.id===s.strategy),p=()=>{u(!1);let T=qe(s);if(!T.ok){N(T.problem);return}N(null),y.mutate(T.model,{onSuccess:()=>{u(!0),a(T.model.id)},onError:(O)=>N(h(O))})};return te(Ge,{children:[F(f,{legend:e===null?"New model":"Edit model",meta:e===null?void 0:e.id,actions:te(Ge,{children:[e===null?null:F(n,{type:"button",$variant:"danger",$size:"sm",onClick:()=>G(!0),children:"Delete"}),F(n,{type:"button",$variant:"primary",$size:"sm",disabled:y.isPending,onClick:p,children:y.isPending?"Saving…":e===null?"Create model":"Save changes"})]}),children:te(r,{$gap:3,children:[F(m,{label:"Model name",hint:e===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:(T)=>F(v,{...T,value:s.id,disabled:e!==null,placeholder:"fast",onChange:(O)=>w({...s,id:O.target.value})})}),F(m,{label:"Routing strategy",children:(T)=>F(R,{...T,value:s.strategy,options:ye.map((O)=>({value:O.id,label:O.label})),onValueChange:(O)=>w({...s,strategy:O})})}),Y===void 0?null:F(Ke,{children:Y.blurb}),te(ft,{children:[F(W,{checked:s.isAlias,label:"This model is an alias for a provider model name",onCheckedChange:(T)=>w({...s,isAlias:T})}),te(r,{$gap:0,children:[F(t,{as:"span",children:"Alias"}),F(Ke,{children:"Mark this when the name mirrors a provider's own model name."})]})]}),te(r,{$gap:2,children:[te(o,{children:[F(t,{children:"Targets"}),F(S,{}),te(n,{type:"button",$size:"sm",onClick:()=>w({...s,targets:[...s.targets,ve(l,s.targets.at(-1)?.provider)]}),children:[F(Qe,{}),"Add target"]})]}),s.targets.map((T,O)=>F(Ue,{target:T,index:O,removable:s.targets.length>1,catalog:l,endpoints:U,held:D,credentials:L.data??[],onChange:(J)=>w({...s,targets:s.targets.map((ae)=>ae.key===T.key?J:ae)}),onRemove:()=>w({...s,targets:s.targets.filter((J)=>J.key!==T.key)})},T.key))]}),q===null?null:F(gt,{role:"alert",children:q}),V&&q===null?F(ht,{role:"status",children:"Saved."}):null]})}),F(ee,{open:Q,onOpenChange:G,title:"Delete model",body:e===null?"":`Deleting "${e.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:j.isPending,onConfirm:()=>{if(e===null)return;j.mutate(e.id,{onSuccess:()=>{G(!1),c()},onError:(T)=>{G(!1),N(h(T))}})}})]})}import{jsx as A,jsxs as ne,Fragment as St}from"react/jsx-runtime";var Ct=le.div.withConfig({displayName:"ModelsBoard__Split"})(["display:grid;grid-template-columns:minmax(230px,300px) minmax(0,1fr);gap:",";align-items:start;@media (max-width:980px){grid-template-columns:minmax(0,1fr);}"],({theme:e})=>e.space(4)),kt=le(r).withConfig({displayName:"ModelsBoard__Column"})(["gap:",";min-width:0;"],({theme:e})=>e.space(4)),wt=le.button.withConfig({displayName:"ModelsBoard__Entry"})(["display:flex;flex-direction:column;gap:4px;width:100%;padding:",";text-align:left;background:",";border:0;border-left:2px solid ",";border-bottom:1px solid ",";cursor:pointer;&:hover{background:",";}&:last-child{border-bottom:0;}"],({theme:e})=>`${e.space(2)} ${e.space(3)}`,({theme:e,$selected:a})=>a?e.color.accentWash:"transparent",({theme:e,$selected:a})=>a?e.color.accent:"transparent",({theme:e})=>e.color.rule,({theme:e,$selected:a})=>a?e.color.accentWash:e.color.panelSunk),Tt=le(M).withConfig({displayName:"ModelsBoard__Name"})(["font-family:",";font-size:12.5px;display:block;max-width:100%;"],({theme:e})=>e.font.mono),$t=le.div.withConfig({displayName:"ModelsBoard__Bar"})(["display:flex;gap:2px;"]),Pt=le.span.withConfig({displayName:"ModelsBoard__Pip"})(["width:12px;height:3px;border-radius:1px;background:",";"],({$provider:e})=>oe(e)),me="\x00new";function Je(){let e=H(),[a,c]=yt(null),l=e.data??[],s=a===me?null:l.find((N)=>N.id===a)??null,w=a===me||a===null&&!e.isLoading&&l.length===0;bt(()=>{if(a!==null||l.length===0)return;c(l[0]?.id??null)},[l,a]);let q=e.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((N,V)=>N+V.targets.length,0)} targets.`;return ne(St,{children:[A(k,{legend:"Models",title:"Virtual models",summary:q,actions:ne(n,{type:"button",$variant:"primary",onClick:()=>c(me),children:[A(Qe,{}),"New model"]})}),ne(Ct,{children:[A(f,{legend:"Configured",meta:`${l.length}`,flush:!0,children:e.isError?A(x,{error:e.error,onRetry:()=>void e.refetch()}):e.isLoading?A("div",{style:{padding:12},children:A(b,{rows:4})}):l.length===0?A(I,{legend:"No models",message:"Create a model to give clients something to ask for.",action:A(n,{type:"button",$size:"sm",$variant:"primary",onClick:()=>c(me),children:"New model"})}):A("div",{children:l.map((N)=>{let V=[...new Set(N.targets.map((u)=>u.provider))];return ne(wt,{type:"button",$selected:N.id===a,"aria-pressed":N.id===a,onClick:()=>c(N.id),children:[ne(o,{$gap:2,style:{width:"100%"},children:[A(Tt,{title:N.id,children:N.id}),A(S,{}),N.isAlias?A(C,{children:"alias"}):null]}),ne(o,{$gap:2,style:{width:"100%"},children:[A($t,{children:V.map((u)=>A(Pt,{$provider:u,title:u},u))}),A(t,{children:N.strategy}),A(S,{}),ne(d,{$dim:!0,$size:"11px",children:[N.targets.length," target",N.targets.length===1?"":"s"]})]})]},N.id)})})}),ne(kt,{children:[s===null&&!w?A(f,{legend:"Editor",children:e.isLoading?A(b,{rows:5}):A(I,{legend:"Nothing selected",message:"Pick a model on the left to change its targets, or create a new one."})}):A(je,{model:s,onSaved:(N)=>{c(N),e.refetch()},onDeleted:()=>{c(null),e.refetch()}}),A(Re,{modelId:s?.id??null})]})]})]})}var Oo=Je;export{Oo as component};
|