@aidotnet/server-linux-x64 0.11.6 → 0.11.7

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 (52) hide show
  1. package/bin/astra-server +2 -2
  2. package/bin/wwwroot/assets/ClientsPage-BkryyG2f.js +9 -0
  3. package/bin/wwwroot/assets/{KeyPage-CNp0pPiQ.js → KeyPage-Dvq7y7mN.js} +1 -1
  4. package/bin/wwwroot/assets/ModelDetailPage-C7_EPeUV.js +1 -0
  5. package/bin/wwwroot/assets/{ModelsPage-KeUV0kEe.js → ModelsPage-CecKPzmY.js} +1 -1
  6. package/bin/wwwroot/assets/{PluginsPage-D-Idp7rX.js → PluginsPage-D1aMay74.js} +2 -2
  7. package/bin/wwwroot/assets/PrivacyPage-0MkKjVWn.js +1 -0
  8. package/bin/wwwroot/assets/ProviderDetailPage-VBGL5ZrY.js +3 -0
  9. package/bin/wwwroot/assets/ProvidersPage-D5JY75MS.js +2 -0
  10. package/bin/wwwroot/assets/SettingsPage-DNie2n8k.js +2 -0
  11. package/bin/wwwroot/assets/{SmartRoutingPage-d7VpOJbs.js → SmartRoutingPage-B-aCfkfa.js} +2 -2
  12. package/bin/wwwroot/assets/TokenDetailPage-DGTEwfS_.js +1 -0
  13. package/bin/wwwroot/assets/{TokenPoolEditor-D1m8Jjy3.js → TokenPoolEditor-B9uZPbeG.js} +1 -1
  14. package/bin/wwwroot/assets/TokensPage-m2mErUTL.js +1 -0
  15. package/bin/wwwroot/assets/{TracesPage-D8KIKCul.js → TracesPage-CJZ-nJlq.js} +2 -2
  16. package/bin/wwwroot/assets/{TrayPanelPage-DaxLSbIE.js → TrayPanelPage-DGyB4UQp.js} +1 -1
  17. package/bin/wwwroot/assets/{TrayPanelView-D6QJsy-r.js → TrayPanelView-hLE52k5W.js} +1 -1
  18. package/bin/wwwroot/assets/{alert-BadMvy1R.js → alert-DNq6XGjw.js} +6 -6
  19. package/bin/wwwroot/assets/{arrow-down-Cv-6a_e3.js → arrow-down-BeKBqI8J.js} +1 -1
  20. package/bin/wwwroot/assets/{arrow-left-dS7bcLEo.js → arrow-left-raXRLTWx.js} +1 -1
  21. package/bin/wwwroot/assets/checkbox-B4QCx8vR.js +1 -0
  22. package/bin/wwwroot/assets/{cloud-download-CpuzW7lP.js → cloud-download-DCdlPad8.js} +1 -1
  23. package/bin/wwwroot/assets/confirm-morph-wPnl8JgZ.js +1 -0
  24. package/bin/wwwroot/assets/{download-DhWYUpCm.js → download-C7rkArJ1.js} +1 -1
  25. package/bin/wwwroot/assets/{ellipsis-DhDdch5j.js → ellipsis-fH6Z7dKK.js} +1 -1
  26. package/bin/wwwroot/assets/{external-link-D3yhOoFs.js → external-link-RRwePVkf.js} +1 -1
  27. package/bin/wwwroot/assets/{folder-open-Bggy7qkR.js → folder-open-D2dhOmB_.js} +1 -1
  28. package/bin/wwwroot/assets/{index-BUzE8kPN.css → index-Bw0Y3RgL.css} +1 -1
  29. package/bin/wwwroot/assets/{index-BUGU_FDT.js → index-XrDQKNHp.js} +10 -10
  30. package/bin/wwwroot/assets/{log-out-DV1PNbkn.js → log-out-DzqOZbat.js} +1 -1
  31. package/bin/wwwroot/assets/minus-jJwwqp0i.js +1 -0
  32. package/bin/wwwroot/assets/overlays-DvhyCmfZ.js +41 -0
  33. package/bin/wwwroot/assets/{pencil-TH_5IGXD.js → pencil-DQhF_n_3.js} +1 -1
  34. package/bin/wwwroot/assets/{power-DF2viDB7.js → power-CCGgTfLt.js} +1 -1
  35. package/bin/wwwroot/assets/radio-cards-C1r9wSvL.js +1 -0
  36. package/bin/wwwroot/assets/{rotate-ccw-BxvPRjim.js → rotate-ccw-DHnulJrY.js} +1 -1
  37. package/bin/wwwroot/assets/{sortable.esm-DYxWT0KU.js → sortable.esm-Bi_ISyN_.js} +1 -1
  38. package/bin/wwwroot/index.html +4 -4
  39. package/package.json +1 -1
  40. package/bin/wwwroot/assets/ClientsPage-TqHAFA25.js +0 -9
  41. package/bin/wwwroot/assets/ModelDetailPage-B61Xlxp4.js +0 -1
  42. package/bin/wwwroot/assets/PrivacyPage-C3YpZHD5.js +0 -1
  43. package/bin/wwwroot/assets/ProviderDetailPage-CeXebQjO.js +0 -3
  44. package/bin/wwwroot/assets/ProvidersPage-Ca7aGIQg.js +0 -2
  45. package/bin/wwwroot/assets/SettingsPage-CpD7hQB4.js +0 -2
  46. package/bin/wwwroot/assets/TokenDetailPage-TJa2J-N_.js +0 -1
  47. package/bin/wwwroot/assets/TokensPage-CnAympZG.js +0 -1
  48. package/bin/wwwroot/assets/checkbox-CaaP8Tue.js +0 -1
  49. package/bin/wwwroot/assets/confirm-morph-XE52Kxj6.js +0 -1
  50. package/bin/wwwroot/assets/minus-DxRH0N_9.js +0 -1
  51. package/bin/wwwroot/assets/overlays-D-LaJu2w.js +0 -41
  52. package/bin/wwwroot/assets/radio-cards-Geph_wiF.js +0 -1
@@ -1,2 +1,2 @@
1
- import{Er as e,Ia as t,Ir as n,J as r,Jr as i,Ma as a,Na as o,Ti as s,_ as c,b as l,ct as u,d,gt as f,hi as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x,ut as S,v as C,y as w}from"./alert-BadMvy1R.js";import{a as T,gt as E,o as D,r as O}from"./overlays-D-LaJu2w.js";import{t as k}from"./arrow-down-Cv-6a_e3.js";import{K as A,N as j,S as M,h as N,z as P}from"./index-BUGU_FDT.js";var F=t(o(),1),I=a(),L=2,R=6;function z({detail:e,...t}){return(0,I.jsx)(m,{...t,detail:e==null?void 0:(0,I.jsx)(`span`,{className:`block whitespace-normal`,children:e})})}var B={typesafe:[{id:`typesafe`,baseUrl:``,model:`jev-latest`},{id:`openrouter`,baseUrl:`https://openrouter.ai/api`,model:`~typesafe/jev-latest`},{id:`vercel`,baseUrl:`https://ai-gateway.vercel.sh/typesafe`,model:`typesafe-ai/jev`}],openai:[{id:`openai`,baseUrl:``}]},V=(e,t)=>`${e??``}\n${t}`;function H(e,t){let n=t.trim().replace(/\/+$/,``);return B[e].find(e=>e.baseUrl===n)?.id??`custom`}function U(e,t,n){let r=e.trim()||(n.find(e=>e.id===t)?.defaultBaseUrl??``);try{return new URL(r).origin.toLowerCase()}catch{return r}}function W(e){return{virtualModel:e.virtualModel,protocol:e.judge.protocol,baseUrl:e.judge.baseUrl??``,apiKey:``,model:e.judge.model,instructions:e.judge.instructions??``,timeoutMs:e.judge.timeoutMs,grades:e.grades.map(e=>({...e})),mode:e.rules.mode,sessionTtlMinutes:e.rules.sessionTtlMinutes,fallbackGrade:e.rules.fallbackGrade,minConfidence:e.rules.minConfidence,contextTurns:e.rules.contextTurns,maxChars:e.rules.maxChars}}var G=e=>[e.timeoutMs,e.sessionTtlMinutes,e.minConfidence,e.contextTurns,e.maxChars].every(e=>e!==null);function K(e){return{protocol:e.protocol,baseUrl:e.baseUrl,model:e.model,instructions:e.instructions,...e.timeoutMs!==null&&{timeoutMs:e.timeoutMs},...e.apiKey!==``&&{apiKey:e.apiKey}}}function q(e){return{virtualModel:e.virtualModel,judge:K(e),grades:e.grades,rules:{mode:e.mode,fallbackGrade:e.fallbackGrade,...e.sessionTtlMinutes!==null&&{sessionTtlMinutes:e.sessionTtlMinutes},...e.minConfidence!==null&&{minConfidence:e.minConfidence},...e.contextTurns!==null&&{contextTurns:e.contextTurns},...e.maxChars!==null&&{maxChars:e.maxChars}}}}function J(e,t,n){let r=`smartRouting.problem.${e.code}`;if(!(r in S))return e.message;let i=/^grades\[(\d+)\]/.exec(e.field??``),a=i?t.grades[Number(i[1])]:void 0;return n(r,{grade:a?a.name||a.id:``,field:e.field??``})}function Y(e,t,n){if(e instanceof s){let r=e.details?.problems;if(Array.isArray(r)&&r.length>0)return r.map(e=>J(e,t,n))}return[T(e)]}function X(e){let t=`smartRouting.unusable.${e}`;return e&&t in S?t:null}function Z(e,t){let n=`smartRouting.failure.${e}`;return n in S?t(n):e??``}function Q(){let{t:e}=u(),t=n();return t.data?(0,I.jsx)($,{saved:t.data}):(0,I.jsx)(`div`,{className:`mx-auto max-w-[760px]`,children:t.isError?(0,I.jsx)(b,{tone:`danger`,title:e(`smartRouting.loadFailed`),children:T(t.error)}):(0,I.jsx)(C,{className:`mx-auto my-8`})})}function $({saved:e}){let{t}=u(),{toast:n}=D(),r=p(),[i,a]=(0,F.useState)(()=>W(e)),[o,s]=(0,F.useState)([]),c=e=>a(t=>({...t,...e})),l=JSON.stringify(i)!==JSON.stringify(W(e)),d=G(i),f=e=>r.mutate({...q(i),...e!==void 0&&{enabled:e}},{onSuccess:r=>{s([]),a(W(r)),n(t(e===void 0?`common.saved`:e?`smartRouting.toast.on`:`smartRouting.toast.off`))},onError:e=>s(Y(e,i,t))});return(0,I.jsxs)(`div`,{className:`mx-auto max-w-[760px]`,children:[(0,I.jsx)(ee,{saved:e,busy:r.isPending,canSave:d,onToggle:e=>f(e),problems:o}),(0,I.jsx)(ne,{saved:e,draft:i,patch:c}),(0,I.jsx)(ie,{draft:i,patch:c}),(0,I.jsx)(ae,{draft:i,patch:c}),!d&&(0,I.jsx)(`p`,{className:`mb-3 px-1 text-[12px] text-[var(--warning)]`,children:t(`smartRouting.numberMissing`)}),(0,I.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[l&&(0,I.jsx)(v,{variant:`plain`,onClick:()=>a(W(e)),children:t(`smartRouting.discard`)}),(0,I.jsx)(v,{variant:`primary`,disabled:!l||!d,loading:r.isPending,onClick:()=>f(),children:t(`common.save`)})]})]})}function ee({saved:e,busy:t,canSave:n,onToggle:r,problems:i}){let{t:a}=u(),{toast:o}=D(),{status:s}=e,c=async e=>{await E.copy(e)&&o(a(`common.copied`))},l=(0,F.useRef)(null);return(0,F.useEffect)(()=>{i.length>0&&l.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[i]),(0,I.jsxs)(x,{title:a(`smartRouting.status`),footer:a(`smartRouting.statusFooter`),children:[(0,I.jsx)(z,{label:a(`smartRouting.enable`),detail:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(y,{tone:e.enabled?s.breakerOpen?`orange`:`green`:`neutral`}),e.enabled?s.breakerOpen?a(`smartRouting.state.breaker`):`${a(`smartRouting.state.on`)}${s.pins>0?` · ${a(`smartRouting.state.pins`,{count:s.pins})}`:``}`:a(`smartRouting.state.off`)]}),children:(0,I.jsx)(w,{checked:e.enabled,label:a(`smartRouting.enable`),disabled:t||!n,onChange:r})}),e.enabled&&(0,I.jsxs)(z,{label:a(`smartRouting.use`),detail:a(`smartRouting.useHint`),children:[(0,I.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.virtualModel}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(f,{className:`size-3.5`}),"aria-label":a(`common.copy`),onClick:()=>void c(e.virtualModel)})]}),e.enabled&&(0,I.jsx)(te,{saved:e}),i.length>0&&(0,I.jsx)(`div`,{ref:l,className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`danger`,title:a(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:i.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})})})]})}function te({saved:e}){let{t,locale:n}=u(),i=e.status.recent??{total:0,outcomes:{}},a=e.status.unreachable??[],o=t=>{let n=e.grades.find(e=>e.id===t);return n?n.name||n.id:t},s=i.outcomes.judge??0,c=Object.entries(i.outcomes).filter(([e])=>e!==`judge`).sort((e,t)=>t[1]-e[1]),l=i.total-s,d=[t(`smartRouting.recent.judged`,{count:s,total:i.total}),...c.map(([e,n])=>t(`smartRouting.recent.fallback`,{reason:Z(e,t),count:n})),...i.medianJudgeMs==null?[]:[t(`smartRouting.recent.median`,{ms:i.medianJudgeMs})]].join(` · `),f=`smartRouting.recent.hint.${c[0]?.[0]}`;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{label:t(`smartRouting.recent`),detail:i.total===0?t(`smartRouting.recent.none`):d}),l>=2&&l*2>i.total&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.recent.failing`,{grade:o(e.rules.fallbackGrade)}),children:[(0,I.jsx)(`p`,{children:t(f in S?f:`smartRouting.recent.hint.other`)}),i.lastFallbackAt&&(0,I.jsx)(`p`,{className:`mt-1 text-[var(--text-muted)]`,children:t(`smartRouting.recent.last`,{reason:Z(i.lastFallback,t),time:r(i.lastFallbackAt,n)})})]})}),a.length>0&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.unreachable.title`),children:[(0,I.jsx)(`ul`,{className:`list-disc space-y-1.5 pl-4`,children:a.map(e=>{let i=X(e.reason),a={count:e.count,time:r(e.lastAt,n)};return(0,I.jsxs)(`li`,{children:[(0,I.jsxs)(`div`,{children:[t(`smartRouting.unreachable.item`,{caller:M(e.caller),grade:o(e.grade),where:e.providerName?t(`smartRouting.unreachable.where`,{provider:e.providerName,model:e.model}):e.model,reason:t(i??`smartRouting.unusable.unknown`)}),` `,e.usedGrade?t(`smartRouting.unreachable.used`,{...a,used:o(e.usedGrade)}):t(`smartRouting.unreachable.none`,a)]}),i&&(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`${i}.fix`)})]},`${e.caller}\n${e.grade}`)})}),a.some(e=>!X(e.reason))&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.unreachable.hint`)})]})})]})}function ne({saved:e,draft:t,patch:n}){let{t:r}=u(),i=H(t.protocol,t.baseUrl),a=e.judge.hasApiKey&&t.apiKey===``&&U(t.baseUrl,t.protocol,e.protocols)!==U(e.judge.baseUrl??``,e.judge.protocol,e.protocols);return(0,I.jsxs)(x,{title:r(`smartRouting.judge.title`),footer:r(`smartRouting.judge.footer`),children:[(0,I.jsx)(z,{label:r(`smartRouting.judge.protocol`),detail:r(`smartRouting.judge.protocol.${t.protocol}.hint`),children:(0,I.jsx)(c,{ariaLabel:r(`smartRouting.judge.protocol`),value:t.protocol,onChange:t=>n({protocol:t,baseUrl:``,apiKey:``,model:e.protocols.find(e=>e.id===t)?.defaultModel??``}),items:[{value:`typesafe`,label:r(`smartRouting.judge.protocol.typesafe`)},{value:`openai`,label:r(`smartRouting.judge.protocol.openai`)}]})}),t.protocol===`openai`&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.openaiDraft`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.service`),children:(0,I.jsx)(O,{className:`w-52`,ariaLabel:r(`smartRouting.judge.service`),value:i,onChange:e=>{if(e===`custom`)return n({baseUrl:t.baseUrl||`https://`});let r=B[t.protocol].find(t=>t.id===e);r&&n({baseUrl:r.baseUrl,...r.model!==void 0&&{model:r.model}})},options:[...B[t.protocol].map(e=>({value:e.id,label:r(`smartRouting.preset.${e.id}`)})),{value:`custom`,label:r(`smartRouting.preset.custom`)}]})}),i===`custom`&&(0,I.jsx)(z,{label:r(`smartRouting.judge.baseUrl`),detail:r(`smartRouting.judge.baseUrlHint`),children:(0,I.jsx)(d,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.baseUrl`),placeholder:`https://…`,value:t.baseUrl,onChange:e=>n({baseUrl:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.apiKey`),detail:a?r(`smartRouting.judge.keyReplace`):e.judge.hasApiKey?r(`smartRouting.judge.keySaved`,{mask:e.judge.apiKeyMasked??``}):r(`smartRouting.judge.keyMissing`),children:(0,I.jsx)(d,{className:`w-72`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":r(`smartRouting.judge.apiKey`),placeholder:e.judge.hasApiKey&&!a?`••••••••`:`sk-…`,value:t.apiKey,onChange:e=>n({apiKey:e.target.value})})}),a&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.keyDropped`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.model`),detail:r(`smartRouting.judge.modelHint`),children:(0,I.jsx)(d,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.model`),placeholder:e.protocols.find(e=>e.id===t.protocol)?.defaultModel||`model`,value:t.model,onChange:e=>n({model:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.timeout`),detail:r(`smartRouting.judge.timeoutHint`),children:(0,I.jsx)(_,{className:`w-28`,label:r(`smartRouting.judge.timeout`),step:100,min:200,value:t.timeoutMs,onChange:e=>n({timeoutMs:e})})}),(0,I.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,I.jsx)(b,{tone:`info`,title:r(`smartRouting.privacy.title`),children:r(`smartRouting.privacy.body`,{turns:t.contextTurns??0,chars:t.maxChars??0})}),t.protocol===`typesafe`&&(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.nonEnglish`)}),(0,I.jsxs)(g,{title:r(`smartRouting.judge.instructions`),children:[(0,I.jsx)(`p`,{className:`mb-2 text-[11px] text-[var(--text-muted)]`,children:r(`smartRouting.judge.instructionsHint`)}),(0,I.jsx)(l,{rows:4,"aria-label":r(`smartRouting.judge.instructions`),placeholder:e.defaultInstructions,value:t.instructions,onChange:e=>n({instructions:e.target.value})})]})]}),(0,I.jsx)(re,{draft:t})]})}function re({draft:e}){let{t}=u(),n=i(),[r,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(null),[c,d]=(0,F.useState)([]),f=()=>{s(null),d([]),n.mutate({text:r,judge:K(e),grades:e.grades},{onSuccess:s,onError:n=>d(Y(n,e,t))})},p=o!==null&&o.latencyMs>o.limitMs;return(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsx)(`div`,{className:`text-[13px]`,children:t(`smartRouting.test.title`)}),(0,I.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`smartRouting.test.hint`)}),(0,I.jsx)(l,{rows:3,"aria-label":t(`smartRouting.test.title`),placeholder:t(`smartRouting.test.placeholder`),value:r,onChange:e=>a(e.target.value)}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(v,{size:`sm`,disabled:r.trim()===``,loading:n.isPending,onClick:f,children:t(`smartRouting.test.run`)})}),c.length>0&&(0,I.jsx)(b,{tone:`danger`,title:t(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:c.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})}),o&&(o.ok?(0,I.jsx)(b,{tone:o.confident&&!p?`success`:`warning`,title:t(`smartRouting.test.result`,{grade:o.gradeName??o.grade??``}),children:(0,I.jsxs)(`div`,{className:`space-y-0.5 text-[12px]`,children:[(0,I.jsx)(`div`,{children:o.model?t(`smartRouting.test.model`,{model:o.model}):t(`smartRouting.test.noModel`)}),(0,I.jsxs)(`div`,{children:[t(`smartRouting.test.confidence`,{percent:Math.round((o.confidence??0)*100)}),` ·`,` `,o.confident?t(`smartRouting.test.confident`):t(`smartRouting.test.notConfident`)]}),p&&(0,I.jsxs)(`div`,{className:`text-[var(--warning)]`,children:[t(`smartRouting.test.slow`,{ms:o.latencyMs,limit:o.limitMs}),o.newConnection&&` ${t(`smartRouting.test.connecting`)}`]}),(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`smartRouting.test.meta`,{ms:o.latencyMs,input:o.inputTokens,output:o.outputTokens,model:o.judgeModel??``})})]})}):(0,I.jsxs)(b,{tone:`danger`,title:t(`smartRouting.test.failed`,{reason:Z(o.failure,t)}),children:[o.message,o.failure===`timeout`&&o.newConnection&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.test.connecting`)})]}))]})}function ie({draft:t,patch:n}){let{t:r}=u(),i=e(),a=t.grades,o=(e,r=t.fallbackGrade)=>n({grades:e,fallbackGrade:e.some(e=>e.id===r)?r:e[Math.floor(e.length/2)]?.id??``}),s=(e,t)=>o(a.map((n,r)=>r===e?{...n,...t}:n)),c=(e,t)=>{let n=[...a];[n[e],n[e+t]]=[n[e+t],n[e]],o(n)},f=()=>{let e=a.length+1;for(;a.some(t=>t.id===`grade-${e}`);)e++;o([...a,{id:`grade-${e}`,name:``,description:``,model:``}])},p=i.data??[],m=new Set(p.filter((e,t)=>p.findIndex(t=>t.id===e.id)!==t).map(e=>e.id)),g=p.map(e=>({value:V(e.providerId,e.id),label:m.has(e.id)?`${e.id} · ${e.providerName}`:e.id,detail:m.has(e.id)?void 0:e.providerName})),_=e=>{let t=V(e.providerId,e.model);return e.model&&!g.some(e=>e.value===t)?[{value:t,label:r(`smartRouting.grade.unavailable`,{model:e.model})},...g]:g},y=(e,t)=>{let n=t.indexOf(`
2
- `);s(e,{providerId:t.slice(0,n)||null,model:t.slice(n+1)})};return(0,I.jsxs)(x,{title:r(`smartRouting.grades.title`),footer:r(`smartRouting.grades.footer`),children:[a.map((e,n)=>(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`w-4 text-center font-mono text-[11px] text-[var(--text-muted)]`,children:n+1}),(0,I.jsx)(d,{className:`flex-1`,"aria-label":r(`smartRouting.grade.name`),placeholder:e.id,value:e.name,onChange:e=>s(n,{name:e.target.value})}),t.fallbackGrade===e.id&&(0,I.jsx)(h,{tone:`accent`,children:r(`smartRouting.grade.fallbackBadge`)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(A,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.up`),disabled:n===0,onClick:()=>c(n,-1)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(k,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.down`),disabled:n===a.length-1,onClick:()=>c(n,1)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(j,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.remove`),disabled:a.length<=L,onClick:()=>o(a.filter((e,t)=>t!==n))})]}),(0,I.jsx)(l,{rows:2,"aria-label":r(`smartRouting.grade.description`),placeholder:r(`smartRouting.grade.descriptionPlaceholder`),value:e.description,onChange:e=>s(n,{description:e.target.value})}),(0,I.jsx)(O,{ariaLabel:r(`smartRouting.grade.model`),placeholder:r(`smartRouting.grade.pickModel`),value:e.model?V(e.providerId,e.model):``,options:_(e),onChange:e=>y(n,e)})]},e.id)),i.data?.length===0&&(0,I.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:r(`smartRouting.grade.noModels`)}),(0,I.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,I.jsx)(v,{size:`sm`,icon:(0,I.jsx)(P,{className:`size-3.5`}),disabled:a.length>=R,onClick:f,children:r(`smartRouting.grade.add`)})})]})}function ae({draft:e,patch:t}){let{t:n}=u();return(0,I.jsxs)(x,{title:n(`smartRouting.rules.title`),footer:n(`smartRouting.rules.footer`),children:[(0,I.jsx)(z,{label:n(`smartRouting.rules.mode`),detail:n(`smartRouting.rules.mode.${e.mode}.hint`),children:(0,I.jsx)(c,{ariaLabel:n(`smartRouting.rules.mode`),value:e.mode,onChange:e=>t({mode:e}),items:[{value:`session`,label:n(`smartRouting.rules.mode.session`)},{value:`turn`,label:n(`smartRouting.rules.mode.turn`)}]})}),e.mode===`session`&&(0,I.jsx)(z,{label:n(`smartRouting.rules.ttl`),detail:n(`smartRouting.rules.ttlHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.ttl`),step:1,min:1,value:e.sessionTtlMinutes,onChange:e=>t({sessionTtlMinutes:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.fallback`),detail:n(`smartRouting.rules.fallbackHint`),children:(0,I.jsx)(O,{className:`w-44`,ariaLabel:n(`smartRouting.rules.fallback`),value:e.fallbackGrade,onChange:e=>t({fallbackGrade:e}),options:e.grades.map(e=>({value:e.id,label:e.name||e.id}))})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.minConfidence`),detail:n(`smartRouting.rules.minConfidenceHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.minConfidence`),step:.05,min:0,value:e.minConfidence,onChange:e=>t({minConfidence:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.contextTurns`),detail:n(`smartRouting.rules.contextTurnsHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.contextTurns`),step:1,min:0,value:e.contextTurns,onChange:e=>t({contextTurns:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.maxChars`),detail:n(`smartRouting.rules.maxCharsHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.maxChars`),step:500,min:500,value:e.maxChars,onChange:e=>t({maxChars:e})})}),(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(g,{title:n(`smartRouting.rules.advanced`),children:(0,I.jsx)(z,{label:n(`smartRouting.rules.virtualModel`),detail:n(`smartRouting.rules.virtualModelHint`),children:(0,I.jsx)(d,{className:`w-56`,mono:!0,"aria-label":n(`smartRouting.rules.virtualModel`),value:e.virtualModel,onChange:e=>t({virtualModel:e.target.value})})})})})]})}function oe(){let{t:e}=u();return(0,I.jsx)(N,{title:e(`nav.smartRouting`),subtitle:e(`smartRouting.subtitle`),children:(0,I.jsx)(Q,{})})}export{oe as SmartRoutingPage};
1
+ import{Ei as e,Er as t,Ir as n,J as r,La as i,Na as a,Pa as o,Yr as s,_ as c,b as l,ct as u,d,gi as f,gt as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x,ut as S,v as C,y as w}from"./alert-DNq6XGjw.js";import{a as T,gt as E,o as D,r as O}from"./overlays-DvhyCmfZ.js";import{t as k}from"./arrow-down-BeKBqI8J.js";import{K as A,N as j,S as M,h as N,z as P}from"./index-XrDQKNHp.js";var F=i(o(),1),I=a(),L=2,R=6;function z({detail:e,...t}){return(0,I.jsx)(m,{...t,detail:e==null?void 0:(0,I.jsx)(`span`,{className:`block whitespace-normal`,children:e})})}var B={typesafe:[{id:`typesafe`,baseUrl:``,model:`jev-latest`},{id:`openrouter`,baseUrl:`https://openrouter.ai/api`,model:`~typesafe/jev-latest`},{id:`vercel`,baseUrl:`https://ai-gateway.vercel.sh/typesafe`,model:`typesafe-ai/jev`}],openai:[{id:`openai`,baseUrl:``}]},V=(e,t)=>`${e??``}\n${t}`;function H(e,t){let n=t.trim().replace(/\/+$/,``);return B[e].find(e=>e.baseUrl===n)?.id??`custom`}function U(e,t,n){let r=e.trim()||(n.find(e=>e.id===t)?.defaultBaseUrl??``);try{return new URL(r).origin.toLowerCase()}catch{return r}}function W(e){return{virtualModel:e.virtualModel,protocol:e.judge.protocol,baseUrl:e.judge.baseUrl??``,apiKey:``,model:e.judge.model,instructions:e.judge.instructions??``,timeoutMs:e.judge.timeoutMs,grades:e.grades.map(e=>({...e})),mode:e.rules.mode,sessionTtlMinutes:e.rules.sessionTtlMinutes,fallbackGrade:e.rules.fallbackGrade,minConfidence:e.rules.minConfidence,contextTurns:e.rules.contextTurns,maxChars:e.rules.maxChars}}var G=e=>[e.timeoutMs,e.sessionTtlMinutes,e.minConfidence,e.contextTurns,e.maxChars].every(e=>e!==null);function K(e){return{protocol:e.protocol,baseUrl:e.baseUrl,model:e.model,instructions:e.instructions,...e.timeoutMs!==null&&{timeoutMs:e.timeoutMs},...e.apiKey!==``&&{apiKey:e.apiKey}}}function q(e){return{virtualModel:e.virtualModel,judge:K(e),grades:e.grades,rules:{mode:e.mode,fallbackGrade:e.fallbackGrade,...e.sessionTtlMinutes!==null&&{sessionTtlMinutes:e.sessionTtlMinutes},...e.minConfidence!==null&&{minConfidence:e.minConfidence},...e.contextTurns!==null&&{contextTurns:e.contextTurns},...e.maxChars!==null&&{maxChars:e.maxChars}}}}function J(e,t,n){let r=`smartRouting.problem.${e.code}`;if(!(r in S))return e.message;let i=/^grades\[(\d+)\]/.exec(e.field??``),a=i?t.grades[Number(i[1])]:void 0;return n(r,{grade:a?a.name||a.id:``,field:e.field??``})}function Y(t,n,r){if(t instanceof e){let e=t.details?.problems;if(Array.isArray(e)&&e.length>0)return e.map(e=>J(e,n,r))}return[T(t)]}function X(e){let t=`smartRouting.unusable.${e}`;return e&&t in S?t:null}function Z(e,t){let n=`smartRouting.failure.${e}`;return n in S?t(n):e??``}function Q(){let{t:e}=u(),t=n();return t.data?(0,I.jsx)($,{saved:t.data}):(0,I.jsx)(`div`,{className:`mx-auto max-w-[760px]`,children:t.isError?(0,I.jsx)(b,{tone:`danger`,title:e(`smartRouting.loadFailed`),children:T(t.error)}):(0,I.jsx)(C,{className:`mx-auto my-8`})})}function $({saved:e}){let{t}=u(),{toast:n}=D(),r=f(),[i,a]=(0,F.useState)(()=>W(e)),[o,s]=(0,F.useState)([]),c=e=>a(t=>({...t,...e})),l=JSON.stringify(i)!==JSON.stringify(W(e)),d=G(i),p=e=>r.mutate({...q(i),...e!==void 0&&{enabled:e}},{onSuccess:r=>{s([]),a(W(r)),n(t(e===void 0?`common.saved`:e?`smartRouting.toast.on`:`smartRouting.toast.off`))},onError:e=>s(Y(e,i,t))});return(0,I.jsxs)(`div`,{className:`mx-auto max-w-[760px]`,children:[(0,I.jsx)(ee,{saved:e,busy:r.isPending,canSave:d,onToggle:e=>p(e),problems:o}),(0,I.jsx)(ne,{saved:e,draft:i,patch:c}),(0,I.jsx)(ie,{draft:i,patch:c}),(0,I.jsx)(ae,{draft:i,patch:c}),!d&&(0,I.jsx)(`p`,{className:`mb-3 px-1 text-[12px] text-[var(--warning)]`,children:t(`smartRouting.numberMissing`)}),(0,I.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[l&&(0,I.jsx)(v,{variant:`plain`,onClick:()=>a(W(e)),children:t(`smartRouting.discard`)}),(0,I.jsx)(v,{variant:`primary`,disabled:!l||!d,loading:r.isPending,onClick:()=>p(),children:t(`common.save`)})]})]})}function ee({saved:e,busy:t,canSave:n,onToggle:r,problems:i}){let{t:a}=u(),{toast:o}=D(),{status:s}=e,c=async e=>{await E.copy(e)&&o(a(`common.copied`))},l=(0,F.useRef)(null);return(0,F.useEffect)(()=>{i.length>0&&l.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[i]),(0,I.jsxs)(x,{title:a(`smartRouting.status`),footer:a(`smartRouting.statusFooter`),children:[(0,I.jsx)(z,{label:a(`smartRouting.enable`),detail:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(y,{tone:e.enabled?s.breakerOpen?`orange`:`green`:`neutral`}),e.enabled?s.breakerOpen?a(`smartRouting.state.breaker`):`${a(`smartRouting.state.on`)}${s.pins>0?` · ${a(`smartRouting.state.pins`,{count:s.pins})}`:``}`:a(`smartRouting.state.off`)]}),children:(0,I.jsx)(w,{checked:e.enabled,label:a(`smartRouting.enable`),disabled:t||!n,onChange:r})}),e.enabled&&(0,I.jsxs)(z,{label:a(`smartRouting.use`),detail:a(`smartRouting.useHint`),children:[(0,I.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.virtualModel}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(p,{className:`size-3.5`}),"aria-label":a(`common.copy`),onClick:()=>void c(e.virtualModel)})]}),e.enabled&&(0,I.jsx)(te,{saved:e}),i.length>0&&(0,I.jsx)(`div`,{ref:l,className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`danger`,title:a(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:i.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})})})]})}function te({saved:e}){let{t,locale:n}=u(),i=e.status.recent??{total:0,outcomes:{}},a=e.status.unreachable??[],o=t=>{let n=e.grades.find(e=>e.id===t);return n?n.name||n.id:t},s=i.outcomes.judge??0,c=Object.entries(i.outcomes).filter(([e])=>e!==`judge`).sort((e,t)=>t[1]-e[1]),l=i.total-s,d=[t(`smartRouting.recent.judged`,{count:s,total:i.total}),...c.map(([e,n])=>t(`smartRouting.recent.fallback`,{reason:Z(e,t),count:n})),...i.medianJudgeMs==null?[]:[t(`smartRouting.recent.median`,{ms:i.medianJudgeMs})]].join(` · `),f=`smartRouting.recent.hint.${c[0]?.[0]}`;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(z,{label:t(`smartRouting.recent`),detail:i.total===0?t(`smartRouting.recent.none`):d}),l>=2&&l*2>i.total&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.recent.failing`,{grade:o(e.rules.fallbackGrade)}),children:[(0,I.jsx)(`p`,{children:t(f in S?f:`smartRouting.recent.hint.other`)}),i.lastFallbackAt&&(0,I.jsx)(`p`,{className:`mt-1 text-[var(--text-muted)]`,children:t(`smartRouting.recent.last`,{reason:Z(i.lastFallback,t),time:r(i.lastFallbackAt,n)})})]})}),a.length>0&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsxs)(b,{tone:`warning`,title:t(`smartRouting.unreachable.title`),children:[(0,I.jsx)(`ul`,{className:`list-disc space-y-1.5 pl-4`,children:a.map(e=>{let i=X(e.reason),a={count:e.count,time:r(e.lastAt,n)};return(0,I.jsxs)(`li`,{children:[(0,I.jsxs)(`div`,{children:[t(`smartRouting.unreachable.item`,{caller:M(e.caller),grade:o(e.grade),where:e.providerName?t(`smartRouting.unreachable.where`,{provider:e.providerName,model:e.model}):e.model,reason:t(i??`smartRouting.unusable.unknown`)}),` `,e.usedGrade?t(`smartRouting.unreachable.used`,{...a,used:o(e.usedGrade)}):t(`smartRouting.unreachable.none`,a)]}),i&&(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`${i}.fix`)})]},`${e.caller}\n${e.grade}`)})}),a.some(e=>!X(e.reason))&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.unreachable.hint`)})]})})]})}function ne({saved:e,draft:t,patch:n}){let{t:r}=u(),i=H(t.protocol,t.baseUrl),a=e.judge.hasApiKey&&t.apiKey===``&&U(t.baseUrl,t.protocol,e.protocols)!==U(e.judge.baseUrl??``,e.judge.protocol,e.protocols);return(0,I.jsxs)(x,{title:r(`smartRouting.judge.title`),footer:r(`smartRouting.judge.footer`),children:[(0,I.jsx)(z,{label:r(`smartRouting.judge.protocol`),detail:r(`smartRouting.judge.protocol.${t.protocol}.hint`),children:(0,I.jsx)(c,{ariaLabel:r(`smartRouting.judge.protocol`),value:t.protocol,onChange:t=>n({protocol:t,baseUrl:``,apiKey:``,model:e.protocols.find(e=>e.id===t)?.defaultModel??``}),items:[{value:`typesafe`,label:r(`smartRouting.judge.protocol.typesafe`)},{value:`openai`,label:r(`smartRouting.judge.protocol.openai`)}]})}),t.protocol===`openai`&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.openaiDraft`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.service`),children:(0,I.jsx)(O,{className:`w-52`,ariaLabel:r(`smartRouting.judge.service`),value:i,onChange:e=>{if(e===`custom`)return n({baseUrl:t.baseUrl||`https://`});let r=B[t.protocol].find(t=>t.id===e);r&&n({baseUrl:r.baseUrl,...r.model!==void 0&&{model:r.model}})},options:[...B[t.protocol].map(e=>({value:e.id,label:r(`smartRouting.preset.${e.id}`)})),{value:`custom`,label:r(`smartRouting.preset.custom`)}]})}),i===`custom`&&(0,I.jsx)(z,{label:r(`smartRouting.judge.baseUrl`),detail:r(`smartRouting.judge.baseUrlHint`),children:(0,I.jsx)(d,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.baseUrl`),placeholder:`https://…`,value:t.baseUrl,onChange:e=>n({baseUrl:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.apiKey`),detail:a?r(`smartRouting.judge.keyReplace`):e.judge.hasApiKey?r(`smartRouting.judge.keySaved`,{mask:e.judge.apiKeyMasked??``}):r(`smartRouting.judge.keyMissing`),children:(0,I.jsx)(d,{className:`w-72`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":r(`smartRouting.judge.apiKey`),placeholder:e.judge.hasApiKey&&!a?`••••••••`:`sk-…`,value:t.apiKey,onChange:e=>n({apiKey:e.target.value})})}),a&&(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.keyDropped`)})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.model`),detail:r(`smartRouting.judge.modelHint`),children:(0,I.jsx)(d,{className:`w-72`,mono:!0,"aria-label":r(`smartRouting.judge.model`),placeholder:e.protocols.find(e=>e.id===t.protocol)?.defaultModel||`model`,value:t.model,onChange:e=>n({model:e.target.value})})}),(0,I.jsx)(z,{label:r(`smartRouting.judge.timeout`),detail:r(`smartRouting.judge.timeoutHint`),children:(0,I.jsx)(_,{className:`w-28`,label:r(`smartRouting.judge.timeout`),step:100,min:200,value:t.timeoutMs,onChange:e=>n({timeoutMs:e})})}),(0,I.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,I.jsx)(b,{tone:`info`,title:r(`smartRouting.privacy.title`),children:r(`smartRouting.privacy.body`,{turns:t.contextTurns??0,chars:t.maxChars??0})}),t.protocol===`typesafe`&&(0,I.jsx)(b,{tone:`warning`,title:r(`smartRouting.judge.nonEnglish`)}),(0,I.jsxs)(g,{title:r(`smartRouting.judge.instructions`),children:[(0,I.jsx)(`p`,{className:`mb-2 text-[11px] text-[var(--text-muted)]`,children:r(`smartRouting.judge.instructionsHint`)}),(0,I.jsx)(l,{rows:4,"aria-label":r(`smartRouting.judge.instructions`),placeholder:e.defaultInstructions,value:t.instructions,onChange:e=>n({instructions:e.target.value})})]})]}),(0,I.jsx)(re,{draft:t})]})}function re({draft:e}){let{t}=u(),n=s(),[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(null),[c,d]=(0,F.useState)([]),f=()=>{o(null),d([]),n.mutate({text:r,judge:K(e),grades:e.grades},{onSuccess:o,onError:n=>d(Y(n,e,t))})},p=a!==null&&a.latencyMs>a.limitMs;return(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsx)(`div`,{className:`text-[13px]`,children:t(`smartRouting.test.title`)}),(0,I.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`smartRouting.test.hint`)}),(0,I.jsx)(l,{rows:3,"aria-label":t(`smartRouting.test.title`),placeholder:t(`smartRouting.test.placeholder`),value:r,onChange:e=>i(e.target.value)}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(v,{size:`sm`,disabled:r.trim()===``,loading:n.isPending,onClick:f,children:t(`smartRouting.test.run`)})}),c.length>0&&(0,I.jsx)(b,{tone:`danger`,title:t(`smartRouting.problems`),children:(0,I.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:c.map((e,t)=>(0,I.jsx)(`li`,{children:e},`${t}-${e}`))})}),a&&(a.ok?(0,I.jsx)(b,{tone:a.confident&&!p?`success`:`warning`,title:t(`smartRouting.test.result`,{grade:a.gradeName??a.grade??``}),children:(0,I.jsxs)(`div`,{className:`space-y-0.5 text-[12px]`,children:[(0,I.jsx)(`div`,{children:a.model?t(`smartRouting.test.model`,{model:a.model}):t(`smartRouting.test.noModel`)}),(0,I.jsxs)(`div`,{children:[t(`smartRouting.test.confidence`,{percent:Math.round((a.confidence??0)*100)}),` ·`,` `,a.confident?t(`smartRouting.test.confident`):t(`smartRouting.test.notConfident`)]}),p&&(0,I.jsxs)(`div`,{className:`text-[var(--warning)]`,children:[t(`smartRouting.test.slow`,{ms:a.latencyMs,limit:a.limitMs}),a.newConnection&&` ${t(`smartRouting.test.connecting`)}`]}),(0,I.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`smartRouting.test.meta`,{ms:a.latencyMs,input:a.inputTokens,output:a.outputTokens,model:a.judgeModel??``})})]})}):(0,I.jsxs)(b,{tone:`danger`,title:t(`smartRouting.test.failed`,{reason:Z(a.failure,t)}),children:[a.message,a.failure===`timeout`&&a.newConnection&&(0,I.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.test.connecting`)})]}))]})}function ie({draft:e,patch:n}){let{t:r}=u(),i=t(),a=e.grades,o=(t,r=e.fallbackGrade)=>n({grades:t,fallbackGrade:t.some(e=>e.id===r)?r:t[Math.floor(t.length/2)]?.id??``}),s=(e,t)=>o(a.map((n,r)=>r===e?{...n,...t}:n)),c=(e,t)=>{let n=[...a];[n[e],n[e+t]]=[n[e+t],n[e]],o(n)},f=()=>{let e=a.length+1;for(;a.some(t=>t.id===`grade-${e}`);)e++;o([...a,{id:`grade-${e}`,name:``,description:``,model:``}])},p=i.data??[],m=new Set(p.filter((e,t)=>p.findIndex(t=>t.id===e.id)!==t).map(e=>e.id)),g=p.map(e=>({value:V(e.providerId,e.id),label:m.has(e.id)?`${e.id} · ${e.providerName}`:e.id,detail:m.has(e.id)?void 0:e.providerName})),_=e=>{let t=V(e.providerId,e.model);return e.model&&!g.some(e=>e.value===t)?[{value:t,label:r(`smartRouting.grade.unavailable`,{model:e.model})},...g]:g},y=(e,t)=>{let n=t.indexOf(`
2
+ `);s(e,{providerId:t.slice(0,n)||null,model:t.slice(n+1)})};return(0,I.jsxs)(x,{title:r(`smartRouting.grades.title`),footer:r(`smartRouting.grades.footer`),children:[a.map((t,n)=>(0,I.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`w-4 text-center font-mono text-[11px] text-[var(--text-muted)]`,children:n+1}),(0,I.jsx)(d,{className:`flex-1`,"aria-label":r(`smartRouting.grade.name`),placeholder:t.id,value:t.name,onChange:e=>s(n,{name:e.target.value})}),e.fallbackGrade===t.id&&(0,I.jsx)(h,{tone:`accent`,children:r(`smartRouting.grade.fallbackBadge`)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(A,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.up`),disabled:n===0,onClick:()=>c(n,-1)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(k,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.down`),disabled:n===a.length-1,onClick:()=>c(n,1)}),(0,I.jsx)(v,{size:`sm`,variant:`plain`,icon:(0,I.jsx)(j,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.remove`),disabled:a.length<=L,onClick:()=>o(a.filter((e,t)=>t!==n))})]}),(0,I.jsx)(l,{rows:2,"aria-label":r(`smartRouting.grade.description`),placeholder:r(`smartRouting.grade.descriptionPlaceholder`),value:t.description,onChange:e=>s(n,{description:e.target.value})}),(0,I.jsx)(O,{ariaLabel:r(`smartRouting.grade.model`),placeholder:r(`smartRouting.grade.pickModel`),value:t.model?V(t.providerId,t.model):``,options:_(t),onChange:e=>y(n,e)})]},t.id)),i.data?.length===0&&(0,I.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:r(`smartRouting.grade.noModels`)}),(0,I.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,I.jsx)(v,{size:`sm`,icon:(0,I.jsx)(P,{className:`size-3.5`}),disabled:a.length>=R,onClick:f,children:r(`smartRouting.grade.add`)})})]})}function ae({draft:e,patch:t}){let{t:n}=u();return(0,I.jsxs)(x,{title:n(`smartRouting.rules.title`),footer:n(`smartRouting.rules.footer`),children:[(0,I.jsx)(z,{label:n(`smartRouting.rules.mode`),detail:n(`smartRouting.rules.mode.${e.mode}.hint`),children:(0,I.jsx)(c,{ariaLabel:n(`smartRouting.rules.mode`),value:e.mode,onChange:e=>t({mode:e}),items:[{value:`session`,label:n(`smartRouting.rules.mode.session`)},{value:`turn`,label:n(`smartRouting.rules.mode.turn`)}]})}),e.mode===`session`&&(0,I.jsx)(z,{label:n(`smartRouting.rules.ttl`),detail:n(`smartRouting.rules.ttlHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.ttl`),step:1,min:1,value:e.sessionTtlMinutes,onChange:e=>t({sessionTtlMinutes:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.fallback`),detail:n(`smartRouting.rules.fallbackHint`),children:(0,I.jsx)(O,{className:`w-44`,ariaLabel:n(`smartRouting.rules.fallback`),value:e.fallbackGrade,onChange:e=>t({fallbackGrade:e}),options:e.grades.map(e=>({value:e.id,label:e.name||e.id}))})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.minConfidence`),detail:n(`smartRouting.rules.minConfidenceHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.minConfidence`),step:.05,min:0,value:e.minConfidence,onChange:e=>t({minConfidence:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.contextTurns`),detail:n(`smartRouting.rules.contextTurnsHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.contextTurns`),step:1,min:0,value:e.contextTurns,onChange:e=>t({contextTurns:e})})}),(0,I.jsx)(z,{label:n(`smartRouting.rules.maxChars`),detail:n(`smartRouting.rules.maxCharsHint`),children:(0,I.jsx)(_,{className:`w-28`,label:n(`smartRouting.rules.maxChars`),step:500,min:500,value:e.maxChars,onChange:e=>t({maxChars:e})})}),(0,I.jsx)(`div`,{className:`px-3 py-2`,children:(0,I.jsx)(g,{title:n(`smartRouting.rules.advanced`),children:(0,I.jsx)(z,{label:n(`smartRouting.rules.virtualModel`),detail:n(`smartRouting.rules.virtualModelHint`),children:(0,I.jsx)(d,{className:`w-56`,mono:!0,"aria-label":n(`smartRouting.rules.virtualModel`),value:e.virtualModel,onChange:e=>t({virtualModel:e.target.value})})})})})]})}function oe(){let{t:e}=u();return(0,I.jsx)(N,{title:e(`nav.smartRouting`),subtitle:e(`smartRouting.subtitle`),children:(0,I.jsx)(Q,{})})}export{oe as SmartRoutingPage};
@@ -0,0 +1 @@
1
+ import{$r as e,Br as t,G as n,J as r,La as i,Na as a,Pa as o,Q as s,Y as c,Zr as l,_ as u,c as d,ct as f,ir as p,n as m,or as h,q as g,r as _,s as v,t as y,ti as b,v as x,yr as S}from"./alert-DNq6XGjw.js";import{a as ee,at as te,it as ne,nt as re,ot as ie,rt as ae}from"./overlays-DvhyCmfZ.js";import{t as C}from"./arrow-left-raXRLTWx.js";import{$ as w,D as T,L as E,O as D,Q as O,X as k,h as A,m as j}from"./index-XrDQKNHp.js";import{a as M,n as N}from"./TokenPoolEditor-B9uZPbeG.js";var P=i(o(),1),F=a();function I(){let{id:i=``}=w(),{t:a,locale:o}=f(),I=O(),[R,oe]=(0,P.useState)(`7d`),z=e(i),B=h(),V=t(R,void 0,i),H=l(R,R===`today`?`hour`:`day`,`token`,void 0,i),U=b(R,void 0,20,i),W=p(R,i),G=S({token:i,page:1,pageSize:10},!1),K=M(),q=(0,F.jsx)(_,{variant:`glass`,icon:(0,F.jsx)(C,{className:`size-4`}),"aria-label":a(`common.back`),onClick:()=>I(`/tokens`)}),J=a(`range.${R}`),se=(0,P.useMemo)(()=>te(ne(H.data??[],`requests`),ie(R)).map(e=>({key:e.bucket,label:ae(e.bucket),axisLabel:re(e.bucket),value:Math.round(e.value)})),[H.data,R]),Y=new Map((B.data??[]).map(e=>[e.id,e.name])),X=(W.data??[]).reduce((e,t)=>e+t.requests,0),ce=(W.data??[]).map(e=>({id:e.providerId,name:Y.get(e.providerId)??e.name??e.providerId,requests:e.requests,share:X?e.requests/X:0,success:e.successRate,ttft:e.avgTtftMs??null,cost:e.costUsd,out:e.failoversOut,in:e.failoversIn})),Z=[{key:`name`,label:a(`tokens.detail.provider`),sortable:!0},{key:`requests`,label:a(`overview.requests`),sortable:!0,numeric:!0,render:e=>c(e)},{key:`share`,label:a(`tokens.detail.share`),sortable:!0,numeric:!0,render:e=>g(e)},{key:`success`,label:a(`overview.successRate`),sortable:!0,numeric:!0,render:(e,t)=>t.requests?g(e):`—`},{key:`ttft`,label:a(`overview.avgTtft`),sortable:!0,numeric:!0,render:e=>n(e)},{key:`cost`,label:a(`overview.cost`),sortable:!0,numeric:!0,render:e=>s(e)},{key:`out`,label:a(`tokens.detail.failoversOut`),sortable:!0,numeric:!0},{key:`in`,label:a(`tokens.detail.failoversIn`),sortable:!0,numeric:!0}],le=(U.data??[]).map(e=>({model:e.model,requests:e.requests,tokens:e.tokens,cost:e.costUsd})),ue=[{key:`model`,label:a(`tokens.detail.model`),sortable:!0},{key:`requests`,label:a(`overview.requests`),sortable:!0,numeric:!0,render:e=>c(e)},{key:`tokens`,label:a(`overview.tokens`),sortable:!0,numeric:!0,render:e=>c(e,!0)},{key:`cost`,label:a(`overview.cost`),sortable:!0,numeric:!0,render:e=>s(e)}],de=(G.data?.items??[]).map(e=>({id:e.id,time:new Date(e.startedAtUtc).getTime(),model:e.requestedModel??`—`,provider:e.providerName??e.providerId??`—`,status:e.status,cost:e.costNanoUsd/1e9,r:e})),fe=[{key:`time`,label:a(`tokens.detail.time`),render:(e,t)=>r(t.r.startedAtUtc,o)},{key:`model`,label:a(`tokens.detail.model`)},{key:`provider`,label:a(`tokens.detail.provider`)},{key:`status`,label:a(`tokens.detail.status`),render:e=>(0,F.jsx)(m,{tone:e===`success`?`green`:`red`,children:a(`status.${e}`)})},{key:`cost`,label:a(`overview.cost`),numeric:!0,render:e=>s(e)}];if(z.isError)return(0,F.jsx)(A,{title:a(`nav.tokens`),leading:q,children:(0,F.jsx)(y,{tone:`danger`,title:a(`common.error`),children:ee(z.error)})});let Q=z.data,$=V.data;return(0,F.jsx)(A,{title:Q?.name??``,subtitle:Q?(0,F.jsx)(`code`,{className:`font-mono`,children:Q.keyMasked}):void 0,leading:q,actions:(0,F.jsx)(k,{to:`/requests?token=${encodeURIComponent(i)}`,children:(0,F.jsx)(_,{icon:(0,F.jsx)(E,{className:`size-3.5`}),children:a(`tokens.detail.viewLogs`)})}),children:(0,F.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[(0,F.jsx)(`div`,{className:`flex justify-end`,children:(0,F.jsx)(u,{ariaLabel:a(`overview.range`),value:R,onChange:oe,items:[`today`,`7d`,`30d`,`90d`].map(e=>({value:e,label:a(`range.${e}`)}))})}),$?(0,F.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-3 xl:grid-cols-5`,children:[(0,F.jsx)(L,{label:a(`overview.totalCost`),value:s($.costUsd),context:J}),(0,F.jsx)(L,{label:a(`overview.totalRequests`),value:c($.requests),context:J}),(0,F.jsx)(L,{label:a(`overview.tokens`),value:c($.inputTokens+$.outputTokens,!0),context:a(`overview.tokensContext`,{input:c($.inputTokens,!0),output:c($.outputTokens,!0)})}),(0,F.jsx)(L,{label:a(`usage.hitRate`),value:g(j($.cacheReadTokens,$.inputTokens)??0),context:J}),(0,F.jsx)(L,{label:a(`overview.successRate`),value:$.requests?g($.successRate):`—`,context:n($.avgTtftMs)})]}):(0,F.jsx)(x,{lines:3}),Q?.pool&&(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[a(`tokens.pool.title`),` · `,a(`tokens.strategy.${Q.pool.strategy}`)]}),(0,F.jsx)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2 text-[13px]`,children:Q.pool.members.map(e=>(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,F.jsx)(v,{tone:N(e.health.state)}),Y.get(e.providerId)??e.providerId,(0,F.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:K(e.health)})]},e.providerId))})]}),$&&$.requests===0?(0,F.jsx)(`div`,{className:`card`,children:(0,F.jsx)(d,{title:a(`overview.tokenEmpty.title`,{token:Q?.name??``}),detail:a(`overview.tokenEmpty.detail`,{range:J})})}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[a(`overview.usageTrend`),` · `,J]}),H.isLoading?(0,F.jsx)(x,{lines:4}):(0,F.jsx)(D,{data:se,label:a(`overview.requests`),period:J,height:160,formatValue:e=>c(e),averageLabel:a(R===`today`?`overview.hourlyAverage`:`overview.dailyAverage`),valueLabel:a(`overview.total`),categoryLabel:a(R===`today`?`overview.hour`:`overview.day`)})]}),(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsx)(`h2`,{className:`mb-1 text-[13px] font-medium`,children:a(`tokens.detail.byProvider`)}),(0,F.jsx)(`p`,{className:`mb-3 text-[12px] text-[var(--text-muted)]`,children:a(`tokens.detail.byProviderHint`)}),(0,F.jsx)(T,{caption:a(`tokens.detail.byProvider`),rows:ce,columns:Z,rowKey:`id`,emptyMessage:a(`common.noData`)})]}),(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsx)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:a(`tokens.detail.byModel`)}),(0,F.jsx)(T,{caption:a(`tokens.detail.byModel`),rows:le,columns:ue,rowKey:`model`,emptyMessage:a(`common.noData`)})]})]}),(0,F.jsxs)(`section`,{className:`card p-5`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,F.jsx)(`h2`,{className:`text-[13px] font-medium`,children:a(`tokens.detail.recent`)}),(0,F.jsx)(k,{className:`text-[12px] text-[var(--accent)]`,to:`/requests?token=${encodeURIComponent(i)}`,children:a(`tokens.detail.viewLogs`)})]}),(0,F.jsx)(T,{caption:a(`tokens.detail.recent`),rows:de,columns:fe,rowKey:`id`,emptyMessage:a(`common.noData`)})]})]})})}function L({label:e,value:t,context:n}){return(0,F.jsxs)(`article`,{className:`card min-w-0 px-4 py-3`,children:[(0,F.jsx)(`div`,{className:`truncate text-[12px] text-[var(--text-secondary)]`,children:e}),(0,F.jsx)(`div`,{className:`num mt-1 truncate text-[22px] leading-tight font-semibold selectable`,title:t,children:t}),(0,F.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-[var(--text-muted)]`,title:n,children:n})]})}export{I as TokenDetailPage};
@@ -1 +1 @@
1
- import{J as e,Ma as t,_ as n,ct as r,n as i,nr as a,ot as o,p as s,r as c,y as l}from"./alert-BadMvy1R.js";import{r as u}from"./overlays-D-LaJu2w.js";import{a as d,c as f,d as p,f as m,i as h,l as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C}from"./sortable.esm-DYxWT0KU.js";import{N as w,x as T}from"./index-BUGU_FDT.js";var E=t(),D=[`failover`,`round_robin`,`weighted`,`tiered`,`least_busy`];function O(e){return e.pool?{strategy:e.pool.strategy,sticky:e.pool.sticky,failover:e.pool.failover,maxAttempts:e.pool.maxAttempts,members:e.pool.members.map(e=>({providerId:e.providerId,accountId:e.accountId??null,weight:e.weight,tier:e.tier}))}:{strategy:`failover`,sticky:`session`,failover:!0,maxAttempts:3,members:e.providerId?[{providerId:e.providerId,accountId:e.accountId??null,weight:1,tier:1}]:[]}}function k(e,t){let n=new Set(t.map(e=>e.id));return{strategy:e.strategy,sticky:e.sticky,failover:e.failover,maxAttempts:Math.min(5,Math.max(1,Math.floor(e.maxAttempts||1))),members:e.members.filter(e=>n.has(e.providerId)).map(e=>({...e,weight:Math.max(1,Math.floor(e.weight||1))}))}}function A(e){let{members:t,strategy:n}=e;if(t.length===0)return[];let r=e=>e.reduce((e,t)=>e+Math.max(1,t.weight),0);switch(n){case`failover`:return t.map((e,t)=>+(t===0));case`weighted`:{let e=r(t);return t.map(t=>Math.max(1,t.weight)/e)}case`tiered`:{let e=Math.min(...t.map(e=>e.tier)),n=r(t.filter(t=>t.tier===e));return t.map(t=>t.tier===e?Math.max(1,t.weight)/n:0)}default:return t.map(()=>1/t.length)}}var j=[`var(--accent)`,`var(--success)`,`var(--warning)`,`#af52de`,`#5ac8fa`,`#ff2d55`],M=new Set([`oauth-subscription`,`plugin`]);function N(e){return e===`healthy`?`green`:e===`cooling`||e===`open`||e===`half_open`?`orange`:`red`}function P(){let{t,locale:n}=r();return r=>r.state===`cooling`||r.state===`open`?t(`tokens.health.${r.state}`,{time:r.until?e(r.until,n):`—`}):t(`tokens.health.${r.state}`)}function F({draft:e,onChange:t,providers:i,health:a}){let{t:o}=r(),c=new Map(i.map(e=>[e.id,e])),m=e.members.length>1,h=p(C(f,{activationConstraint:{distance:4}}),C(x,{coordinateGetter:b})),y=n=>t({...e,members:n}),w=(t,n)=>y(e.members.map((e,r)=>r===t?{...e,...n}:e)),T=({active:t,over:n})=>{if(!n||t.id===n.id)return;let r=e.members.findIndex(e=>e.providerId===t.id),i=e.members.findIndex(e=>e.providerId===n.id);r>=0&&i>=0&&y(_(e.members,r,i))},O=i.filter(t=>t.enabled&&!e.members.some(e=>e.providerId===t.id)),k=A(e),M=e.members.flatMap(e=>{let t=c.get(e.providerId);return t&&t.modelCount===0?[t.name]:[]});return(0,E.jsxs)(`div`,{className:`grid gap-3`,children:[m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsx)(n,{ariaLabel:o(`tokens.pool.strategy`),value:e.strategy,onChange:n=>t({...e,strategy:n}),items:D.map(e=>({value:e,label:o(`tokens.strategy.${e}`)}))}),(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:o(`tokens.strategy.${e.strategy}.hint`)})]}),e.members.length===0?(0,E.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.empty`)}):(0,E.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,E.jsx)(v,{sensors:h,collisionDetection:g,onDragEnd:T,children:(0,E.jsx)(S,{items:e.members.map(e=>e.providerId),strategy:d,children:e.members.map((t,n)=>(0,E.jsx)(I,{member:t,index:n,draft:e,provider:c.get(t.providerId),health:a?.get(t.providerId),onChange:e=>w(n,e),onRemove:()=>y(e.members.filter((e,t)=>t!==n))},t.providerId))})})}),O.length>0&&(0,E.jsx)(u,{ariaLabel:o(`tokens.pool.add`),placeholder:o(`tokens.pool.add`),value:null,onChange:t=>y([...e.members,{providerId:t,accountId:null,weight:1,tier:1}]),options:O.map(e=>({value:e.id,label:e.name}))}),M.length>0&&(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--warning)]`,children:o(`tokens.pool.noModels`,{providers:M.join(`, `)})}),m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2 text-[12px]`,children:[(0,E.jsx)(`span`,{className:`font-medium text-[var(--text-secondary)]`,children:o(`tokens.pool.share`)}),(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`tokens.pool.shareHint`)})]}),(0,E.jsx)(`div`,{className:`flex h-2 gap-0.5 overflow-hidden rounded-full bg-[var(--fill-2)]`,"aria-hidden":`true`,children:e.members.map((e,t)=>k[t]>0?(0,E.jsx)(`span`,{style:{flex:k[t],background:j[t%j.length]}},e.providerId):null)}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-[12px] text-[var(--text-secondary)]`,children:e.members.map((e,t)=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:`inline-block size-2 rounded-sm`,style:{background:j[t%j.length]}}),c.get(e.providerId)?.name??e.providerId,(0,E.jsxs)(`b`,{className:`tabular-nums text-[var(--text-primary)]`,children:[Math.round(k[t]*100),`%`]}),k[t]===0&&(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`tokens.pool.standby`)})]},e.providerId))})]}),m&&(0,E.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.sticky`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.stickyHint`)})]}),(0,E.jsx)(l,{label:o(`tokens.pool.sticky`),checked:e.sticky===`session`,onChange:n=>t({...e,sticky:n?`session`:`off`})})]}),(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.failover`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.failoverHint`)})]}),(0,E.jsx)(l,{label:o(`tokens.pool.failover`),checked:e.failover,onChange:n=>t({...e,failover:n})})]}),e.failover&&(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.maxAttempts`)}),(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(s,{label:o(`tokens.pool.maxAttempts`),value:e.maxAttempts,min:1,step:1,onChange:n=>t({...e,maxAttempts:n??1})})})]})]})]})}function I({member:e,index:t,draft:n,provider:l,health:d,onChange:f,onRemove:p}){let{t:g}=r(),_=P(),{attributes:v,listeners:b,setNodeRef:x,setActivatorNodeRef:S,transform:C,transition:D,isDragging:O}=h({id:e.providerId}),k=!!l&&M.has(l.authScheme),A=a(l?.id,k),j=l?.name??e.providerId,F=n.members.length>1,I=l?l.enabled?d:{state:`disabled`}:{state:`missing`};return(0,E.jsxs)(`div`,{ref:x,style:{transform:m.Transform.toString(C),transition:D},className:o(`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-[var(--border-subtle)] px-2.5 py-2 last:border-b-0`,O&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,E.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,E.jsx)(`button`,{ref:S,type:`button`,"aria-label":g(`clients.dragToReorder`,{provider:j}),title:g(`clients.dragToReorder`,{provider:j}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...v,...b,children:(0,E.jsx)(y,{className:`size-4`})}),l&&(0,E.jsx)(T,{name:l.name,icon:l.icon,colorKey:l.templateId,size:20}),(0,E.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:j}),F&&n.strategy===`failover`&&(0,E.jsx)(i,{tone:t===0?`accent`:`neutral`,children:t===0?g(`tokens.pool.primary`):g(`tokens.pool.backup`,{n:t})}),I&&(0,E.jsx)(i,{tone:N(I.state),children:_(I)})]}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[F&&(n.strategy===`weighted`||n.strategy===`tiered`)&&(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(s,{label:g(`tokens.pool.weight`),placeholder:g(`tokens.pool.weight`),value:e.weight,min:1,step:1,onChange:e=>f({weight:e??1})})}),F&&n.strategy===`tiered`&&(0,E.jsx)(u,{ariaLabel:g(`tokens.pool.tier`),value:String(e.tier),onChange:e=>f({tier:Number(e)}),options:[`1`,`2`,`3`].map(e=>({value:e,label:g(`tokens.pool.tierN`,{n:e})}))}),k&&(0,E.jsx)(u,{ariaLabel:g(`tokens.directAccount`),value:e.accountId??``,onChange:e=>f({accountId:e||null}),options:[{value:``,label:g(`clients.accountDefault`)},...(A.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]}),(0,E.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,E.jsx)(w,{className:`size-3.5`}),"aria-label":g(`tokens.pool.remove`,{provider:j}),title:g(`tokens.pool.remove`,{provider:j}),onClick:p})]})]})}export{P as a,k as i,N as n,O as r,F as t};
1
+ import{J as e,Na as t,_ as n,ct as r,n as i,nr as a,ot as o,p as s,r as c,y as l}from"./alert-DNq6XGjw.js";import{r as u}from"./overlays-DvhyCmfZ.js";import{a as d,c as f,d as p,f as m,i as h,l as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C}from"./sortable.esm-Bi_ISyN_.js";import{N as w,x as T}from"./index-XrDQKNHp.js";var E=t(),D=[`failover`,`round_robin`,`weighted`,`tiered`,`least_busy`];function O(e){return e.pool?{strategy:e.pool.strategy,sticky:e.pool.sticky,failover:e.pool.failover,maxAttempts:e.pool.maxAttempts,members:e.pool.members.map(e=>({providerId:e.providerId,accountId:e.accountId??null,weight:e.weight,tier:e.tier}))}:{strategy:`failover`,sticky:`session`,failover:!0,maxAttempts:3,members:e.providerId?[{providerId:e.providerId,accountId:e.accountId??null,weight:1,tier:1}]:[]}}function k(e,t){let n=new Set(t.map(e=>e.id));return{strategy:e.strategy,sticky:e.sticky,failover:e.failover,maxAttempts:Math.min(5,Math.max(1,Math.floor(e.maxAttempts||1))),members:e.members.filter(e=>n.has(e.providerId)).map(e=>({...e,weight:Math.max(1,Math.floor(e.weight||1))}))}}function A(e){let{members:t,strategy:n}=e;if(t.length===0)return[];let r=e=>e.reduce((e,t)=>e+Math.max(1,t.weight),0);switch(n){case`failover`:return t.map((e,t)=>+(t===0));case`weighted`:{let e=r(t);return t.map(t=>Math.max(1,t.weight)/e)}case`tiered`:{let e=Math.min(...t.map(e=>e.tier)),n=r(t.filter(t=>t.tier===e));return t.map(t=>t.tier===e?Math.max(1,t.weight)/n:0)}default:return t.map(()=>1/t.length)}}var j=[`var(--accent)`,`var(--success)`,`var(--warning)`,`#af52de`,`#5ac8fa`,`#ff2d55`],M=new Set([`oauth-subscription`,`plugin`]);function N(e){return e===`healthy`?`green`:e===`cooling`||e===`open`||e===`half_open`?`orange`:`red`}function P(){let{t,locale:n}=r();return r=>r.state===`cooling`||r.state===`open`?t(`tokens.health.${r.state}`,{time:r.until?e(r.until,n):`—`}):t(`tokens.health.${r.state}`)}function F({draft:e,onChange:t,providers:i,health:a}){let{t:o}=r(),c=new Map(i.map(e=>[e.id,e])),m=e.members.length>1,h=p(C(f,{activationConstraint:{distance:4}}),C(x,{coordinateGetter:b})),y=n=>t({...e,members:n}),w=(t,n)=>y(e.members.map((e,r)=>r===t?{...e,...n}:e)),T=({active:t,over:n})=>{if(!n||t.id===n.id)return;let r=e.members.findIndex(e=>e.providerId===t.id),i=e.members.findIndex(e=>e.providerId===n.id);r>=0&&i>=0&&y(_(e.members,r,i))},O=i.filter(t=>t.enabled&&!e.members.some(e=>e.providerId===t.id)),k=A(e),M=e.members.flatMap(e=>{let t=c.get(e.providerId);return t&&t.modelCount===0?[t.name]:[]});return(0,E.jsxs)(`div`,{className:`grid gap-3`,children:[m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsx)(n,{ariaLabel:o(`tokens.pool.strategy`),value:e.strategy,onChange:n=>t({...e,strategy:n}),items:D.map(e=>({value:e,label:o(`tokens.strategy.${e}`)}))}),(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:o(`tokens.strategy.${e.strategy}.hint`)})]}),e.members.length===0?(0,E.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.empty`)}):(0,E.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,E.jsx)(v,{sensors:h,collisionDetection:g,onDragEnd:T,children:(0,E.jsx)(S,{items:e.members.map(e=>e.providerId),strategy:d,children:e.members.map((t,n)=>(0,E.jsx)(I,{member:t,index:n,draft:e,provider:c.get(t.providerId),health:a?.get(t.providerId),onChange:e=>w(n,e),onRemove:()=>y(e.members.filter((e,t)=>t!==n))},t.providerId))})})}),O.length>0&&(0,E.jsx)(u,{ariaLabel:o(`tokens.pool.add`),placeholder:o(`tokens.pool.add`),value:null,onChange:t=>y([...e.members,{providerId:t,accountId:null,weight:1,tier:1}]),options:O.map(e=>({value:e.id,label:e.name}))}),M.length>0&&(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--warning)]`,children:o(`tokens.pool.noModels`,{providers:M.join(`, `)})}),m&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2 text-[12px]`,children:[(0,E.jsx)(`span`,{className:`font-medium text-[var(--text-secondary)]`,children:o(`tokens.pool.share`)}),(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`tokens.pool.shareHint`)})]}),(0,E.jsx)(`div`,{className:`flex h-2 gap-0.5 overflow-hidden rounded-full bg-[var(--fill-2)]`,"aria-hidden":`true`,children:e.members.map((e,t)=>k[t]>0?(0,E.jsx)(`span`,{style:{flex:k[t],background:j[t%j.length]}},e.providerId):null)}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-[12px] text-[var(--text-secondary)]`,children:e.members.map((e,t)=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:`inline-block size-2 rounded-sm`,style:{background:j[t%j.length]}}),c.get(e.providerId)?.name??e.providerId,(0,E.jsxs)(`b`,{className:`tabular-nums text-[var(--text-primary)]`,children:[Math.round(k[t]*100),`%`]}),k[t]===0&&(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:o(`tokens.pool.standby`)})]},e.providerId))})]}),m&&(0,E.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.sticky`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.stickyHint`)})]}),(0,E.jsx)(l,{label:o(`tokens.pool.sticky`),checked:e.sticky===`session`,onChange:n=>t({...e,sticky:n?`session`:`off`})})]}),(0,E.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.failover`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:o(`tokens.pool.failoverHint`)})]}),(0,E.jsx)(l,{label:o(`tokens.pool.failover`),checked:e.failover,onChange:n=>t({...e,failover:n})})]}),e.failover&&(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{children:o(`tokens.pool.maxAttempts`)}),(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(s,{label:o(`tokens.pool.maxAttempts`),value:e.maxAttempts,min:1,step:1,onChange:n=>t({...e,maxAttempts:n??1})})})]})]})]})}function I({member:e,index:t,draft:n,provider:l,health:d,onChange:f,onRemove:p}){let{t:g}=r(),_=P(),{attributes:v,listeners:b,setNodeRef:x,setActivatorNodeRef:S,transform:C,transition:D,isDragging:O}=h({id:e.providerId}),k=!!l&&M.has(l.authScheme),A=a(l?.id,k),j=l?.name??e.providerId,F=n.members.length>1,I=l?l.enabled?d:{state:`disabled`}:{state:`missing`};return(0,E.jsxs)(`div`,{ref:x,style:{transform:m.Transform.toString(C),transition:D},className:o(`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-[var(--border-subtle)] px-2.5 py-2 last:border-b-0`,O&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,E.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,E.jsx)(`button`,{ref:S,type:`button`,"aria-label":g(`clients.dragToReorder`,{provider:j}),title:g(`clients.dragToReorder`,{provider:j}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...v,...b,children:(0,E.jsx)(y,{className:`size-4`})}),l&&(0,E.jsx)(T,{name:l.name,icon:l.icon,colorKey:l.templateId,size:20}),(0,E.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:j}),F&&n.strategy===`failover`&&(0,E.jsx)(i,{tone:t===0?`accent`:`neutral`,children:t===0?g(`tokens.pool.primary`):g(`tokens.pool.backup`,{n:t})}),I&&(0,E.jsx)(i,{tone:N(I.state),children:_(I)})]}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[F&&(n.strategy===`weighted`||n.strategy===`tiered`)&&(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(s,{label:g(`tokens.pool.weight`),placeholder:g(`tokens.pool.weight`),value:e.weight,min:1,step:1,onChange:e=>f({weight:e??1})})}),F&&n.strategy===`tiered`&&(0,E.jsx)(u,{ariaLabel:g(`tokens.pool.tier`),value:String(e.tier),onChange:e=>f({tier:Number(e)}),options:[`1`,`2`,`3`].map(e=>({value:e,label:g(`tokens.pool.tierN`,{n:e})}))}),k&&(0,E.jsx)(u,{ariaLabel:g(`tokens.directAccount`),value:e.accountId??``,onChange:e=>f({accountId:e||null}),options:[{value:``,label:g(`clients.accountDefault`)},...(A.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]}),(0,E.jsx)(c,{size:`sm`,variant:`plain`,icon:(0,E.jsx)(w,{className:`size-3.5`}),"aria-label":g(`tokens.pool.remove`,{provider:j}),title:g(`tokens.pool.remove`,{provider:j}),onClick:p})]})]})}export{P as a,k as i,N as n,O as r,F as t};
@@ -0,0 +1 @@
1
+ import{H as e,J as t,La as n,Na as r,Pa as i,Pr as a,Q as o,Sr as s,Tr as c,X as l,Y as u,_ as d,c as f,ct as p,d as m,ei as h,gt as g,l as _,ln as v,n as y,oi as b,or as x,p as S,q as C,r as w,s as T,t as E,tn as D,v as O,xt as k,yi as A}from"./alert-DNq6XGjw.js";import{a as j,gt as M,i as N,n as ee,o as P,r as F}from"./overlays-DvhyCmfZ.js";import{t as te}from"./ellipsis-fH6Z7dKK.js";import{t as ne}from"./pencil-DQhF_n_3.js";import{t as re}from"./power-CCGgTfLt.js";import{t as ie}from"./rotate-ccw-DHnulJrY.js";import{H as ae,L as oe,N as I,P as se,V as L,X as R,_ as z,h as B,s as V,y as H,z as U}from"./index-XrDQKNHp.js";import{a as ce,i as W,n as G,r as K,t as q}from"./TokenPoolEditor-B9uZPbeG.js";var J={name:`chart-column`,size:24,node:[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]],aliases:[`bar-chart-3`]};J.node;var le=k(J),Y={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};Y.node;var ue=k(Y),X=n(i(),1),Z=r();function de(){let{t:e}=p(),t=h(),n=a(),r=b(),i=r.data?.state===`connected`?r.data.publicUrl:null,[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null);return(0,Z.jsxs)(B,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,Z.jsx)(w,{variant:`primary`,icon:(0,Z.jsx)(U,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`tokens.add`)}),children:[(0,Z.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[n.data&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,Z.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${n.data.gatewayBaseUrl}/v1`})}),(0,Z.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:n.data.gatewayBaseUrl})}),i&&(0,Z.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${i}/v1`,key:`${i}/key`})})]}),t.isLoading&&(0,Z.jsx)(O,{lines:4}),t.isError&&(0,Z.jsx)(E,{tone:`danger`,title:e(`common.error`),children:j(t.error)}),t.data?.length===0&&(0,Z.jsx)(`div`,{className:`card`,children:(0,Z.jsx)(f,{icon:(0,Z.jsx)(L,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,Z.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,Z.jsx)(fe,{token:e,defaultOpen:t.data.length===1,onEdit:()=>l(e)},e.id))})]}),(0,Z.jsx)(_e,{open:o,onOpenChange:s}),(0,Z.jsx)(ve,{token:c,onClose:()=>l(null)})]})}function fe({token:n,defaultOpen:r,onEdit:i}){let{t:l,locale:d}=p(),{toast:f,confirm:m}=P(),h=x(),_=a(),b=c(),S=A(),C=s(),E=v(),[D,O]=(0,X.useState)(r),k=(h.data??[]).find(e=>e.id===n.providerId),N=ce(),F=`token-detail-${n.id}`,L=(e,t)=>{f(t,`success`),e.skipped.length>0&&f(l(`tokens.skipped`,{clients:e.skipped.map(e=>z[e]?.name??e).join(`, `)}),`error`)},B=()=>b.mutate(n.id,{onSuccess:async({token:e})=>{await M.copy(e)?f(l(`tokens.copied`)):f(l(`tokens.copyFailed`),`error`)},onError:e=>f(j(e),`error`)}),V=async()=>{let e=_.data?.gatewayBaseUrl;e&&(await M.copy(`${e}/v1`)?f(l(`tokens.urlCopied`)):f(l(`tokens.copyFailed`),`error`))},U=async()=>{let e=_.data?.gatewayBaseUrl;e&&(await M.copy(`npx @aidotnet/astra-connect join ${e}`)?f(l(`tokens.joinCopied`)):f(l(`tokens.copyFailed`),`error`))},W=async()=>{(!n.enabled||await m({title:l(`tokens.disableConfirm`,{name:n.name}),detail:l(`tokens.disableDetail`),confirmLabel:l(`tokens.disable`),destructive:!0}))&&S.mutate({id:n.id,enabled:!n.enabled},{onError:e=>f(j(e),`error`)})},K=async()=>{await m({title:l(`tokens.resetConfirm`,{name:n.name}),detail:l(`tokens.resetDetail`),confirmLabel:l(`tokens.reset`),destructive:!0})&&C.mutate(n.id,{onSuccess:e=>L(e,l(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>f(j(e),`error`)})},q=async()=>{await m({title:l(`tokens.deleteConfirm`,{name:n.name}),detail:l(`tokens.deleteDetail`),confirmLabel:l(`common.delete`),destructive:!0})&&E.mutate(n.id,{onSuccess:e=>L(e,l(`tokens.deleted`,{name:n.name})),onError:e=>f(j(e),`error`)})},J=n.lastUsedAt?e(n.lastUsedAt,d):l(`tokens.neverUsed`);return(0,Z.jsxs)(`article`,{children:[(0,Z.jsxs)(`div`,{className:`flex cursor-pointer flex-wrap items-center gap-x-5 gap-y-2 px-4 py-3 hover:bg-[var(--surface-muted)]`,onClick:()=>O(e=>!e),children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":D,"aria-controls":F,"aria-label":l(`tokens.details`),onClick:e=>{e.stopPropagation(),O(e=>!e)},children:(0,Z.jsx)(ae,{className:`size-4 transition-transform ${D?`rotate-90`:``}`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${n.enabled?``:`text-[var(--text-muted)]`}`,children:n.name}),n.isDefault&&(0,Z.jsx)(y,{tone:`accent`,children:l(`tokens.default`)}),!n.enabled&&(0,Z.jsx)(y,{tone:`orange`,children:l(`tokens.disabledBadge`)}),n.limitUsage.some(e=>e.exhausted)&&(0,Z.jsx)(y,{tone:`orange`,children:l(`tokens.limitExhausted`)}),n.pool&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:n.pool.members.map(e=>e.providerId).join(`, `),children:[(0,Z.jsx)(y,{children:l(`tokens.pool.summary`,{count:n.pool.members.length,strategy:l(`tokens.strategy.${n.pool.strategy}`)})}),n.pool.members.map(e=>(0,Z.jsx)(T,{tone:G(e.health.state)},e.providerId))]})]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:n.keyMasked}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(g,{className:`size-3.5`}),"aria-label":l(`tokens.copy`),title:l(`tokens.copy`),loading:b.isPending,onClick:B}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(ue,{className:`size-3.5`}),"aria-label":l(`tokens.copyUrl`),title:l(`tokens.copyUrl`),disabled:!_.data,onClick:()=>void V()}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(se,{className:`size-3.5`}),"aria-label":l(`tokens.copyJoin`),title:l(`tokens.copyJoin`),disabled:!_.data,onClick:()=>void U()})]})]})]}),(0,Z.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:n.clients.map(e=>z[e]?.name??e).join(`, `)||l(`tokens.noClients`),children:n.clients.length===0?(0,Z.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):n.clients.map(e=>(0,Z.jsx)(H,{kind:e,size:16},e))}),(0,Z.jsx)(Q,{label:l(`tokens.today`),value:o(n.today.costUsd),context:l(`tokens.requestsContext`,{count:u(n.today.requests)})}),(0,Z.jsx)(Q,{label:l(`tokens.total`),value:o(n.total.costUsd),context:`${u(n.total.totalTokens,!0)} Token`}),(0,Z.jsx)(Q,{label:l(`tokens.lastUsedTitle`),value:n.lastUsedAt?t(n.lastUsedAt,d):`—`,context:n.lastUsedAt?``:l(`tokens.neverUsed`),title:J}),(0,Z.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(ee,{label:l(`common.more`),icon:(0,Z.jsx)(te,{className:`size-4`}),items:[{id:`settings`,label:l(`tokens.settings`),icon:(0,Z.jsx)(ne,{className:`size-3.5`}),onSelect:i},{id:`toggle`,label:n.enabled?l(`tokens.disable`):l(`tokens.enable`),icon:(0,Z.jsx)(re,{className:`size-3.5`}),onSelect:()=>void W()},{id:`reset`,label:l(`tokens.reset`),icon:(0,Z.jsx)(ie,{className:`size-3.5`}),onSelect:()=>void K()},...n.isDefault?[]:[{id:`delete`,label:l(`tokens.delete`),icon:(0,Z.jsx)(I,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void q()}]]})})]}),D&&(0,Z.jsxs)(`div`,{id:F,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,Z.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:l(`tokens.clients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:n.clients.length===0?l(`tokens.noClients`):n.clients.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(H,{kind:e,size:14}),z[e]?.name??e]},e))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:n.pool?l(`tokens.pool.title`):l(`tokens.directProvider`)}),n.pool?(0,Z.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:n.pool.members.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:N(e.health),children:[(0,Z.jsx)(T,{tone:G(e.health.state)}),(h.data??[]).find(t=>t.id===e.providerId)?.name??e.providerId]},e.providerId))}):(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:k?.name??(n.providerId?n.providerId:l(`tokens.directNone`))})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:l(`tokens.allowedClients`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:n.allowedClients==null?l(`tokens.allowedClientsAny`):n.allowedClients.length===0?l(`tokens.directOnly`):n.allowedClients.map(e=>z[e]?.name??e).join(`, `)})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:l(`tokens.lastUsedTitle`)}),(0,Z.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:J})]})]}),(0,Z.jsx)(pe,{token:n}),(0,Z.jsx)(he,{today:n.today,total:n.total}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,Z.jsx)(R,{to:`/tokens/${encodeURIComponent(n.id)}`,children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(le,{className:`size-3.5`}),children:l(`tokens.detail.open`)})}),(0,Z.jsx)(R,{to:`/requests?token=${encodeURIComponent(n.id)}`,children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(oe,{className:`size-3.5`}),children:l(`tokens.detail.viewLogs`)})})]})]})]})}function pe({token:e}){let{t}=p(),n=e.limits?.rpm;return(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,Z.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,Z.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,Z.jsx)(me,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,Z.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,Z.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function me({usage:t}){let{t:n,locale:r}=p(),i=`${n(`tokens.period.${t.period}`)} · ${n(`tokens.metric.${t.metric}`)}`,a=e=>t.metric===`cost`?o(e):u(e,!0),s=Math.max(0,Math.min(100,Math.round(t.usedPercent))),c=s>=90?`var(--danger)`:s>=70?`var(--warning)`:`var(--accent)`;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,Z.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:i}),(0,Z.jsx)(`span`,{className:`num`,children:n(`tokens.limitUsed`,{used:a(t.used),limit:a(t.limit)})})]}),(0,Z.jsx)(`div`,{role:`progressbar`,"aria-valuenow":s,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${s}%`,background:c}})}),t.resetsAt&&(0,Z.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:n(`tokens.limitResets`,{time:e(t.resetsAt,r)})})]})}function Q({label:e,value:t,context:n,title:r}){return(0,Z.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Z.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,Z.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function he({today:e,total:t}){let{t:n}=p(),r=[[n(`tokens.today`),e],[n(`tokens.total`),t]],i=`px-3 py-1.5 text-right font-normal whitespace-nowrap text-[var(--text-muted)]`,a=`num px-3 py-1.5 text-right whitespace-nowrap`;return(0,Z.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,Z.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,Z.jsx)(`th`,{className:`${i} text-left`}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.cost`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.requests`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.tokens`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.inOut`)}),(0,Z.jsx)(`th`,{className:i,children:n(`tokens.cacheHit`)}),(0,Z.jsx)(`th`,{className:i,title:n(`tokens.tpsContext`),children:n(`tokens.tps`)})]})}),(0,Z.jsx)(`tbody`,{children:r.map(([e,t])=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,Z.jsx)(`td`,{className:`${a} font-semibold selectable`,children:o(t.costUsd)}),(0,Z.jsx)(`td`,{className:a,children:u(t.requests)}),(0,Z.jsx)(`td`,{className:a,children:u(t.totalTokens,!0)}),(0,Z.jsxs)(`td`,{className:`${a} text-[var(--text-secondary)]`,children:[u(t.inputTokens,!0),` / `,u(t.outputTokens,!0)]}),(0,Z.jsx)(`td`,{className:a,title:n(`usage.cacheAmounts`,{read:u(t.cacheReadTokens,!0),write:u(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:C(t.cacheHitRate)}),(0,Z.jsx)(`td`,{className:a,children:t.tps==null?`—`:l(t.tps)})]},e))})]})})}function ge(){let{t:e}=p(),t=(x().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function _e({open:e,onOpenChange:t}){let{t:n}=p(),{toast:r}=P(),i=D(),{options:a}=ge(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(``);return(0,X.useEffect)(()=>{e&&(s(``),l(``))},[e]),(0,Z.jsx)(N,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(w,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,Z.jsx)(w,{variant:`primary`,disabled:!o.trim(),loading:i.isPending,onClick:()=>i.mutate({name:o.trim(),providerId:c||null},{onSuccess:e=>{t(!1),r(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>r(j(e),`error`)}),children:n(`common.create`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(_,{label:n(`tokens.name`),children:(0,Z.jsx)(m,{value:o,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>s(e.target.value)})}),(0,Z.jsx)(_,{label:n(`tokens.directProvider`),children:(0,Z.jsx)(F,{value:c,onChange:l,options:a})})]})})}function ve({token:e,onClose:t}){let{t:n}=p(),{toast:r}=P(),i=A(),a=x(),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)([]),[h,g]=(0,X.useState)(null),[v,y]=(0,X.useState)(`any`),[b,C]=(0,X.useState)([]),T=new Set(u.map(e=>`${e.metric}:${e.period}`)).size<u.length,E=new Map((e?.pool?.members??[]).map(e=>[e.providerId,e.health]));return(0,X.useEffect)(()=>{e&&(s(e.name),l(K(e)),f(e.limits?.budgets.map(e=>({...e}))??[]),g(e.limits?.rpm??null),y(e.allowedClients==null?`any`:`only`),C(e.allowedClients??[]))},[e]),(0,Z.jsx)(N,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(w,{onClick:t,children:n(`common.cancel`)}),(0,Z.jsx)(w,{variant:`primary`,disabled:!o.trim()||T,loading:i.isPending,onClick:()=>{if(!e)return;let s=u.flatMap(e=>e.limit!=null&&e.limit>0?[{...e,limit:e.limit}]:[]),l=s.length>0||h!=null&&h>0?{budgets:s,rpm:h!=null&&h>0?Math.floor(h):null}:null;i.mutate({id:e.id,name:o.trim(),...c?{pool:W(c,a.data??[])}:{},limits:l,allowedClients:v===`any`?null:b},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(j(e),`error`)})},children:n(`common.save`)})]}),children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Z.jsx)(_,{label:n(`tokens.name`),children:(0,Z.jsx)(m,{value:o,maxLength:64,onChange:e=>s(e.target.value)})}),(0,Z.jsx)(_,{label:n(`tokens.pool.title`),hint:n(`tokens.pool.hint`),children:c&&(0,Z.jsx)(q,{draft:c,onChange:l,providers:a.data??[],health:E})}),(0,Z.jsx)(_,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:T?n(`tokens.limitDuplicate`):void 0,children:(0,Z.jsx)(be,{budgets:u,onChange:f})}),(0,Z.jsx)(_,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,Z.jsx)(S,{value:h,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:g})}),(0,Z.jsx)(_,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(d,{ariaLabel:n(`tokens.allowedClients`),value:v,onChange:y,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),v===`only`&&(0,Z.jsx)(V,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(z),...b])].map(e=>({value:e,label:z[e]?.name??e})),value:b,onValueChange:e=>C(e)})]})})]})})}var $=[`cost`,`requests`,`tokens`],ye=[`day`,`week`,`month`,`total`];function be({budgets:e,onChange:t}){let{t:n}=p(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),i=$.flatMap(e=>ye.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,Z.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((i,a)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitMetric`),value:i.metric,onChange:e=>r(a,{metric:e}),options:$.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,Z.jsx)(F,{ariaLabel:n(`tokens.limitPeriod`),value:i.period,onChange:e=>r(a,{period:e}),options:ye.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,Z.jsx)(S,{label:n(`tokens.limitValue`),value:i.limit,min:0,step:i.metric===`cost`?`any`:1,placeholder:n(`tokens.limitValue`),onChange:e=>r(a,{limit:e})}),(0,Z.jsx)(w,{size:`sm`,variant:`plain`,icon:(0,Z.jsx)(I,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==a))})]},a)),i&&(0,Z.jsx)(`div`,{children:(0,Z.jsx)(w,{size:`sm`,icon:(0,Z.jsx)(U,{className:`size-3.5`}),onClick:()=>t([...e,{...i,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{de as TokensPage};