@aidotnet/server-linux-arm64 0.15.1 → 0.15.3

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 (51) hide show
  1. package/bin/astra-server +2 -2
  2. package/bin/wwwroot/assets/ClientsPage-DJ8OiYcX.js +11 -0
  3. package/bin/wwwroot/assets/KeyPage-5UvBWycd.js +1 -0
  4. package/bin/wwwroot/assets/{LibraryPage-zWB1AmNM.js → LibraryPage-JQxAvawG.js} +2 -2
  5. package/bin/wwwroot/assets/McpPage-oozJ21zq.js +9 -0
  6. package/bin/wwwroot/assets/{ModelDetailPage-DX2Tmcg8.js → ModelDetailPage-Cfz2zi0U.js} +1 -1
  7. package/bin/wwwroot/assets/{ModelsPage-DQ723Bep.js → ModelsPage-DAvS9uxX.js} +1 -1
  8. package/bin/wwwroot/assets/PluginsPage-DfBHZfb2.js +2 -0
  9. package/bin/wwwroot/assets/PrivacyPage-BgA0yvY0.js +1 -0
  10. package/bin/wwwroot/assets/ProviderDetailPage-bIxbjCzP.js +3 -0
  11. package/bin/wwwroot/assets/ProvidersPage-Uiuwx_Cd.js +3 -0
  12. package/bin/wwwroot/assets/{RoutingGroupsPage-BTUW7SzD.js → RoutingGroupsPage-DUdcBWYq.js} +3 -3
  13. package/bin/wwwroot/assets/SettingsPage-B0IMSAPT.js +2 -0
  14. package/bin/wwwroot/assets/SkillsPage-Ctyb7F5q.js +1 -0
  15. package/bin/wwwroot/assets/SmartRoutingPage-CPcCOOTH.js +2 -0
  16. package/bin/wwwroot/assets/TokenDetailPage-PLOYTNPK.js +1 -0
  17. package/bin/wwwroot/assets/{TokenPoolEditor-IFC01xaC.js → TokenPoolEditor-DzEkYZ9z.js} +1 -1
  18. package/bin/wwwroot/assets/TokensPage-DwZEaXdO.js +1 -0
  19. package/bin/wwwroot/assets/ToolsPage-DQwpPzFX.js +1 -0
  20. package/bin/wwwroot/assets/{TracesPage-BZrA-1-1.js → TracesPage-DbNt1DV8.js} +2 -2
  21. package/bin/wwwroot/assets/{TrayPanelPage-BZ5qX7RL.js → TrayPanelPage-D3T3wyqR.js} +1 -1
  22. package/bin/wwwroot/assets/{TrayPanelView-BCnCVX3H.js → TrayPanelView-wy6Co_3P.js} +1 -1
  23. package/bin/wwwroot/assets/TrayTitleSource-DleIYaE6.js +41 -0
  24. package/bin/wwwroot/assets/{checkbox-CgKXs5Sq.js → checkbox-DKNuVOmF.js} +1 -1
  25. package/bin/wwwroot/assets/confirm-morph-CpavTPxZ.js +1 -0
  26. package/bin/wwwroot/assets/{format-DFMHYFFs.js → format-BmuJU1J1.js} +4 -4
  27. package/bin/wwwroot/assets/index-CZ4Wdbud.js +124 -0
  28. package/bin/wwwroot/assets/{radio-cards-BvbUpDsv.js → radio-cards-BvgAI3-W.js} +1 -1
  29. package/bin/wwwroot/assets/{sortable.esm-DTOfU4E0.js → sortable.esm-CJQ90KMg.js} +1 -1
  30. package/bin/wwwroot/assets/square-check-big-qw-46oRI.js +1 -0
  31. package/bin/wwwroot/assets/use-transform-btbU40wQ.js +1 -0
  32. package/bin/wwwroot/index.html +4 -4
  33. package/package.json +1 -1
  34. package/bin/wwwroot/assets/ClientsPage-BTh-MAoi.js +0 -11
  35. package/bin/wwwroot/assets/KeyPage-DE781Xxu.js +0 -1
  36. package/bin/wwwroot/assets/McpPage-B9XqS9Bw.js +0 -9
  37. package/bin/wwwroot/assets/PluginsPage-DL2OpHwt.js +0 -2
  38. package/bin/wwwroot/assets/PrivacyPage-CLuKXL5L.js +0 -1
  39. package/bin/wwwroot/assets/ProviderDetailPage-k8pFYdq_.js +0 -3
  40. package/bin/wwwroot/assets/ProvidersPage-DPZUeWOI.js +0 -3
  41. package/bin/wwwroot/assets/SettingsPage-CZ14Qoi7.js +0 -2
  42. package/bin/wwwroot/assets/SkillsPage-D02hvfyt.js +0 -1
  43. package/bin/wwwroot/assets/SmartRoutingPage-C_WvZBQn.js +0 -2
  44. package/bin/wwwroot/assets/TokenDetailPage-Dx1dSnTW.js +0 -1
  45. package/bin/wwwroot/assets/TokensPage-ChYVyi0B.js +0 -1
  46. package/bin/wwwroot/assets/ToolsPage-eggyG1x7.js +0 -1
  47. package/bin/wwwroot/assets/TrayTitleSource-DPgZ1gwk.js +0 -41
  48. package/bin/wwwroot/assets/confirm-morph-DiY_OTKx.js +0 -1
  49. package/bin/wwwroot/assets/index-Dd8H-gQl.js +0 -124
  50. package/bin/wwwroot/assets/square-check-big-Bs2Ld6rG.js +0 -1
  51. package/bin/wwwroot/assets/use-transform-DAvHgos2.js +0 -1
@@ -1,3 +1,3 @@
1
- import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{C as n,D as r,F as i,G as a,Ko as o,L as s,Ln as c,O as l,P as u,So as d,T as f,W as p,Xi as m,Yi as h,Zi as g,bn as _,ec as v,ft as y,k as b,r as x,z as S}from"./format-DFMHYFFs.js";import{H as C,U as w,V as T,W as E}from"./TrayTitleSource-DPgZ1gwk.js";import{t as D}from"./grip-vertical-DFI2_ajd.js";import{t as O}from"./layers-lBgMUT4n.js";import{t as k}from"./pencil-CpF9MxGZ.js";import{t as A}from"./plus-c3HzV6VX.js";import{t as j}from"./trash-BHBJn5GS.js";import{a as M,c as ee,d as te,f as N,i as P,l as ne,n as F,o as I,r as L,s as R,t as z,u as B}from"./sortable.esm-DTOfU4E0.js";import{v as V}from"./index-Dd8H-gQl.js";var H=e(t(),1),U=v(),W=[`smart`,`order`,`rotate`,`usage`,`pace`,`weight`],re=[`auto`,`session`,`turn`,`off`,`strict`],G=e=>e.group?`group/${e.group}`:`${e.provider}/${e.model}`;function ie(e){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t.length>48?t.slice(0,48).replace(/-+$/,``):t}var K=()=>({name:``,slug:``,mode:`smart`,stays:`auto`,enabled:!0,listed:!0,members:[]}),q=e=>({name:e.name,slug:e.slug,mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({provider:e.provider??null,model:e.model??null,group:e.group??null,weight:e.weight}))});function ae(e){return e.name.trim()!==``&&/^[a-z0-9][a-z0-9-]{0,47}$/.test(e.slug)&&e.members.length>0}function oe(e,t){return{name:e.name.trim(),...t?{slug:e.slug}:{},mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({...e,weight:Math.min(1e3,Math.max(1,Math.floor(e.weight||1)))}))}}function J(e,t){if(e instanceof o){let n=e.details?.problems;if(n?.length)return n.map(e=>{let n=`routingGroups.problem.${e.code}`;return n in r?t(n):e.message})}return[w(e)]}var Y={healthy:`green`,cooling:`orange`,open:`orange`,half_open:`orange`,no_account:`red`,off:`red`,missing:`red`,group:`neutral`};function X(e,t){if(!e)return`—`;let n=`routingGroups.reason.${e}`;return n in r?t(n):e}function Z(){let{t:e,locale:t}=f();return n=>n.health===`cooling`||n.health===`open`?e(`routingGroups.health.${n.health}`,{time:n.coolingUntil?x(n.coolingUntil,t):`—`}):e(`routingGroups.health.${n.health}`)}function Q(){let{t:e}=f(),{toast:t,confirm:n}=E(),r=m(),i=h(),a=d(),o=c(),[s,l]=(0,H.useState)(null),g=e=>i.data?.find(t=>t.id===e),_=async r=>{await n({title:e(`routingGroups.deleteTitle`,{name:r.name}),detail:e(`routingGroups.deleteDetail`,{model:r.modelId}),confirmLabel:e(`common.delete`),destructive:!0})&&o.mutate(r.id,{onError:n=>t(J(n,e).join(`
2
- `),`error`)})};return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,U.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:e(`routingGroups.intro`)}),(0,U.jsx)(b,{variant:`primary`,icon:(0,U.jsx)(A,{className:`size-3.5`}),onClick:()=>l(K()),children:e(`routingGroups.add`)})]}),r.isLoading&&(0,U.jsx)(p,{lines:3}),r.data?.length===0&&(0,U.jsx)(`div`,{className:`card`,children:(0,U.jsx)(u,{icon:(0,U.jsx)(O,{className:`size-6`}),title:e(`routingGroups.empty`),detail:e(`routingGroups.emptyDetail`)})}),(0,U.jsx)(`div`,{className:`grid gap-3`,children:r.data?.map(n=>(0,U.jsx)($,{group:n,status:g(n.id),onEdit:()=>l({id:n.id,draft:q(n)}),onDelete:()=>void _(n),onToggle:r=>a.mutate({id:n.id,body:{enabled:r}},{onError:n=>t(J(n,e).join(`
3
- `),`error`)})},n.id))}),(0,U.jsx)(ce,{target:s,groups:r.data??[],status:s&&`id`in s?g(s.id):void 0,onClose:()=>l(null)})]})}function $({group:e,status:t,onEdit:n,onDelete:r,onToggle:i}){let{t:o,locale:s}=f(),c=Z(),u=new Map(t?.members.map(e=>[e.key,e])??[]);return(0,U.jsxs)(`div`,{className:y(`card p-4`,!e.enabled&&`opacity-70`),children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-[14px] font-medium`,children:e.name}),(0,U.jsx)(l,{tone:`accent`,children:o(`routingGroups.mode.${e.mode}`)}),!e.enabled&&(0,U.jsx)(l,{tone:`neutral`,children:o(`routingGroups.disabled`)}),!e.listed&&(0,U.jsx)(l,{tone:`neutral`,children:o(`routingGroups.unlisted`)})]}),(0,U.jsx)(`code`,{className:`selectable text-[12px] text-[var(--text-secondary)]`,children:e.modelId})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(a,{label:o(`routingGroups.enabled`),checked:e.enabled,onChange:i}),(0,U.jsx)(b,{size:`sm`,variant:`plain`,icon:(0,U.jsx)(k,{className:`size-3.5`}),"aria-label":o(`common.edit`),title:o(`common.edit`),onClick:n}),(0,U.jsx)(b,{size:`sm`,variant:`plain`,icon:(0,U.jsx)(j,{className:`size-3.5`}),"aria-label":o(`common.delete`),title:o(`common.delete`),onClick:r})]})]}),(0,U.jsx)(`div`,{className:`mt-3 divide-y divide-[var(--border-subtle)] overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:e.members.map((t,n)=>(0,U.jsx)(se,{member:t,index:n,group:e,live:u.get(G(t)),healthText:c},G(t)))}),t?.lastReason&&t.lastDecisionAt&&(0,U.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:o(`routingGroups.lastDecision`,{reason:X(t.lastReason,o),time:x(t.lastDecisionAt,s)})})]})}function se({member:e,index:t,group:n,live:r,healthText:i}){let{t:a,locale:o}=f(),s=e.group?`group/${e.group}`:`${r?.providerName??e.provider} · ${e.model}`,c=r?.usedPercent==null?null:a(`routingGroups.quotaUsed`,{percent:Math.round(r.usedPercent)})+(r.resetsAt?` · `+a(`routingGroups.resets`,{time:x(r.resetsAt,o)}):``);return(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-3 py-2 text-[12px]`,children:[(0,U.jsx)(`span`,{className:`w-5 shrink-0 text-center tabular-nums text-[var(--text-muted)]`,children:t+1}),(0,U.jsx)(`span`,{className:`min-w-0 flex-1 basis-44 truncate text-[13px]`,children:s}),n.mode===`weight`&&(0,U.jsx)(l,{tone:`neutral`,children:a(`routingGroups.weightN`,{n:e.weight})}),r&&(0,U.jsx)(l,{tone:Y[r.health]??`neutral`,children:i(r)}),r?.problem&&(0,U.jsx)(l,{tone:`red`,children:a(`routingGroups.memberProblem.${r.problem}`)}),c&&(0,U.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:c}),r&&!c&&r.health!==`group`&&(0,U.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:a(`routingGroups.quotaUnknown`)}),r?.lastUsed&&(0,U.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:a(`routingGroups.lastUsed`,{time:x(r.lastUsed,o)})})]})}function ce({target:e,groups:t,status:r,onClose:o}){let{t:c}=f(),l=Z(),u=_(),p=d(),m=g(),h=e&&`id`in e?e.id:null,[v,y]=(0,H.useState)(K()),[x,S]=(0,H.useState)(!1),[w,E]=(0,H.useState)([]);(0,H.useEffect)(()=>{e&&(y(`id`in e?e.draft:e),S(`id`in e),E([]))},[e]);let D=h?t.find(e=>e.id===h):void 0,O=u.isPending||p.isPending,k=te(B(ee,{activationConstraint:{distance:4}}),B(R,{coordinateGetter:L})),A=e=>y(t=>({...t,...e})),j=e=>A({members:e}),N=new Set(v.members.map(G)),P=(0,H.useMemo)(()=>(m.data??[]).filter(e=>!N.has(`${e.providerId}/${e.id}`)).map(e=>({value:`${e.providerId}/${e.id}`,label:`${e.providerName} · ${e.id}`,m:e})),[m.data,v.members]),V=t.filter(e=>e.id!==h&&!N.has(`group/${e.slug}`)).map(e=>({value:e.slug,label:`group/${e.slug} · ${e.name}`})),q=({active:e,over:t})=>{if(!t||e.id===t.id)return;let n=v.members.findIndex(t=>G(t)===e.id),r=v.members.findIndex(e=>G(e)===t.id);n>=0&&r>=0&&j(F(v.members,n,r))},Y=()=>{let e=oe(v,h===null),t={onSuccess:()=>o(),onError:e=>E(J(e,c))};h?p.mutate({id:h,body:e},t):u.mutate(e,t)},X=new Map(r?.members.map(e=>[e.key,e])??[]),Q=(e,t)=>e.group?`group/${e.group}`:`${t?.providerName??X.get(G(e))?.providerName??e.provider} · ${e.model}`,$=new Map((m.data??[]).map(e=>[`${e.providerId}/${e.id}`,e]));return(0,U.jsx)(C,{open:e!==null,onOpenChange:e=>!e&&o(),width:600,title:D?c(`routingGroups.editTitle`,{name:D.name}):c(`routingGroups.addTitle`),footer:(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(b,{onClick:o,children:c(`common.cancel`)}),(0,U.jsx)(b,{variant:`primary`,disabled:!ae(v),loading:O,onClick:Y,children:c(`common.save`)})]}),children:(0,U.jsxs)(`div`,{className:`grid gap-4`,children:[(0,U.jsx)(i,{label:c(`routingGroups.name`),children:(0,U.jsx)(s,{value:v.name,maxLength:80,placeholder:`Opus anywhere`,onChange:e=>A({name:e.target.value,...!x&&h===null?{slug:ie(e.target.value)}:{}})})}),(0,U.jsx)(i,{label:c(`routingGroups.slug`),hint:h?c(`routingGroups.slugLocked`):c(`routingGroups.slugHint`,{model:`group/${v.slug||`…`}`}),children:(0,U.jsx)(s,{mono:!0,value:v.slug,maxLength:48,disabled:h!==null,placeholder:`opus-anywhere`,onChange:e=>{S(!0),A({slug:e.target.value})}})}),(0,U.jsx)(i,{label:c(`routingGroups.modeLabel`),hint:c(`routingGroups.mode.${v.mode}.hint`),children:(0,U.jsx)(T,{value:v.mode,onChange:e=>A({mode:e}),options:W.map(e=>({value:e,label:c(`routingGroups.mode.${e}`)}))})}),(0,U.jsx)(i,{label:c(`routingGroups.staysLabel`),hint:c(`routingGroups.stays.${v.stays}.hint`),children:(0,U.jsx)(T,{value:v.stays,onChange:e=>A({stays:e}),options:re.map(e=>({value:e,label:c(`routingGroups.stays.${e}`)}))})}),(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsx)(`div`,{className:`text-[12px] font-medium text-[var(--text-secondary)]`,children:c(`routingGroups.membersTitle`)}),(0,U.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:c(`routingGroups.membersHint`)}),v.members.length===0?(0,U.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:c(`routingGroups.noMembers`)}):(0,U.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,U.jsx)(I,{sensors:k,collisionDetection:ne,onDragEnd:q,children:(0,U.jsx)(z,{items:v.members.map(G),strategy:M,children:v.members.map((e,t)=>(0,U.jsx)(le,{member:e,name:Q(e,$.get(G(e))),weighted:v.mode===`weight`,live:X.get(G(e)),healthText:l,onWeight:e=>j(v.members.map((n,r)=>r===t?{...n,weight:e}:n)),onRemove:()=>j(v.members.filter((e,n)=>n!==t))},G(e)))})})}),(0,U.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,U.jsx)(T,{ariaLabel:c(`routingGroups.addModel`),placeholder:c(`routingGroups.addModel`),value:null,disabled:P.length===0,onChange:e=>{let t=P.find(t=>t.value===e)?.m;t&&j([...v.members,{provider:t.providerId,model:t.id,group:null,weight:1}])},options:P.map(({value:e,label:t})=>({value:e,label:t}))}),(0,U.jsx)(T,{ariaLabel:c(`routingGroups.addGroup`),placeholder:c(`routingGroups.addGroup`),value:null,disabled:V.length===0,onChange:e=>j([...v.members,{provider:null,model:null,group:e,weight:1}]),options:V})]})]}),(0,U.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,U.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,U.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,U.jsx)(`span`,{children:c(`routingGroups.listed`)}),(0,U.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:c(`routingGroups.listedHint`)})]}),(0,U.jsx)(a,{label:c(`routingGroups.listed`),checked:v.listed,onChange:e=>A({listed:e})})]}),(0,U.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsx)(`span`,{children:c(`routingGroups.enabled`)}),(0,U.jsx)(a,{label:c(`routingGroups.enabled`),checked:v.enabled,onChange:e=>A({enabled:e})})]})]}),w.length>0&&(0,U.jsx)(n,{tone:`danger`,title:c(`routingGroups.refused`),children:(0,U.jsx)(`ul`,{className:`list-disc pl-4`,children:w.map(e=>(0,U.jsx)(`li`,{children:e},e))})})]})})}function le({member:e,name:t,weighted:n,live:r,healthText:i,onWeight:a,onRemove:o}){let{t:s}=f(),{attributes:c,listeners:u,setNodeRef:d,setActivatorNodeRef:p,transform:m,transition:h,isDragging:g}=P({id:G(e)});return(0,U.jsxs)(`div`,{ref:d,style:{transform:N.Transform.toString(m),transition:h},className:y(`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`,g&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,U.jsx)(`button`,{ref:p,type:`button`,"aria-label":s(`clients.dragToReorder`,{provider:t}),title:s(`clients.dragToReorder`,{provider:t}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...c,...u,children:(0,U.jsx)(D,{className:`size-4`})}),(0,U.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:t}),r&&(0,U.jsx)(l,{tone:Y[r.health]??`neutral`,children:i(r)}),r?.problem&&(0,U.jsx)(l,{tone:`red`,children:s(`routingGroups.memberProblem.${r.problem}`)})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,U.jsx)(`div`,{className:`w-20`,children:(0,U.jsx)(S,{label:s(`routingGroups.weight`),placeholder:s(`routingGroups.weight`),value:e.weight,min:1,step:1,onChange:e=>a(e??1)})}),(0,U.jsx)(b,{size:`sm`,variant:`plain`,icon:(0,U.jsx)(j,{className:`size-3.5`}),"aria-label":s(`routingGroups.remove`,{name:t}),title:s(`routingGroups.remove`,{name:t}),onClick:o})]})]})}function ue(){let{t:e}=f();return(0,U.jsx)(V,{title:e(`nav.routingGroups`),subtitle:e(`routingGroups.subtitle`),children:(0,U.jsx)(Q,{})})}export{ue as RoutingGroupsPage};
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{$i as n,C as r,D as i,F as a,G as o,Jo as s,L as c,O as l,P as u,Qi as d,Sn as f,T as p,W as m,Zi as h,ft as g,k as _,nc as v,r as y,wo as b,z as x,zn as S}from"./format-BmuJU1J1.js";import{H as C,U as w,V as T,W as E}from"./TrayTitleSource-DleIYaE6.js";import{t as D}from"./grip-vertical-DFI2_ajd.js";import{t as O}from"./layers-lBgMUT4n.js";import{t as k}from"./pencil-CpF9MxGZ.js";import{t as A}from"./plus-c3HzV6VX.js";import{t as j}from"./trash-BHBJn5GS.js";import{a as ee,c as te,d as ne,f as M,i as N,l as P,n as F,o as I,r as L,s as R,t as z,u as B}from"./sortable.esm-CJQ90KMg.js";import{v as V}from"./index-CZ4Wdbud.js";var H=e(t(),1),U=v(),W=[`smart`,`order`,`rotate`,`usage`,`pace`,`weight`],re=[`auto`,`session`,`turn`,`off`,`strict`],G=e=>e.group?`group/${e.group}`:`${e.provider}/${e.model}`;function ie(e){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t.length>48?t.slice(0,48).replace(/-+$/,``):t}var K=()=>({name:``,slug:``,mode:`smart`,stays:`auto`,enabled:!0,listed:!0,members:[]}),q=e=>({name:e.name,slug:e.slug,mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({provider:e.provider??null,model:e.model??null,group:e.group??null,weight:e.weight}))});function ae(e){return e.name.trim()!==``&&/^[a-z0-9][a-z0-9-]{0,47}$/.test(e.slug)&&e.members.length>0}function oe(e,t){return{name:e.name.trim(),...t?{slug:e.slug}:{},mode:e.mode,stays:e.stays,enabled:e.enabled,listed:e.listed,members:e.members.map(e=>({...e,weight:Math.min(1e3,Math.max(1,Math.floor(e.weight||1)))}))}}function J(e,t){if(e instanceof s){let n=e.details?.problems;if(n?.length)return n.map(e=>{let n=`routingGroups.problem.${e.code}`;return n in i?t(n):e.message})}return[w(e)]}var Y={healthy:`green`,cooling:`orange`,open:`orange`,half_open:`orange`,no_account:`red`,off:`red`,missing:`red`,group:`neutral`};function X(e,t){if(!e)return`—`;let n=`routingGroups.reason.${e}`;return n in i?t(n):e}function Z(){let{t:e,locale:t}=p();return n=>n.health===`cooling`||n.health===`open`?e(`routingGroups.health.${n.health}`,{time:n.coolingUntil?y(n.coolingUntil,t):`—`}):e(`routingGroups.health.${n.health}`)}function Q(){let{t:e}=p(),{toast:t,confirm:n}=E(),r=d(),i=h(),a=b(),o=S(),[s,c]=(0,H.useState)(null),l=e=>i.data?.find(t=>t.id===e),f=async r=>{await n({title:e(`routingGroups.deleteTitle`,{name:r.name}),detail:e(`routingGroups.deleteDetail`,{model:r.modelId}),confirmLabel:e(`common.delete`),destructive:!0})&&o.mutate(r.id,{onError:n=>t(J(n,e).join(`
2
+ `),`error`)})};return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,U.jsx)(`p`,{className:`min-w-0 flex-1 text-[12px] text-[var(--text-secondary)]`,children:e(`routingGroups.intro`)}),(0,U.jsx)(_,{variant:`primary`,icon:(0,U.jsx)(A,{className:`size-3.5`}),onClick:()=>c(K()),children:e(`routingGroups.add`)})]}),r.isLoading&&(0,U.jsx)(m,{lines:3}),r.data?.length===0&&(0,U.jsx)(`div`,{className:`card`,children:(0,U.jsx)(u,{icon:(0,U.jsx)(O,{className:`size-6`}),title:e(`routingGroups.empty`),detail:e(`routingGroups.emptyDetail`)})}),(0,U.jsx)(`div`,{className:`grid gap-3`,children:r.data?.map(n=>(0,U.jsx)($,{group:n,status:l(n.id),onEdit:()=>c({id:n.id,draft:q(n)}),onDelete:()=>void f(n),onToggle:r=>a.mutate({id:n.id,body:{enabled:r}},{onError:n=>t(J(n,e).join(`
3
+ `),`error`)})},n.id))}),(0,U.jsx)(ce,{target:s,groups:r.data??[],status:s&&`id`in s?l(s.id):void 0,onClose:()=>c(null)})]})}function $({group:e,status:t,onEdit:n,onDelete:r,onToggle:i}){let{t:a,locale:s}=p(),c=Z(),u=new Map(t?.members.map(e=>[e.key,e])??[]);return(0,U.jsxs)(`div`,{className:g(`card p-4`,!e.enabled&&`opacity-70`),children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-[14px] font-medium`,children:e.name}),(0,U.jsx)(l,{tone:`accent`,children:a(`routingGroups.mode.${e.mode}`)}),!e.enabled&&(0,U.jsx)(l,{tone:`neutral`,children:a(`routingGroups.disabled`)}),!e.listed&&(0,U.jsx)(l,{tone:`neutral`,children:a(`routingGroups.unlisted`)})]}),(0,U.jsx)(`code`,{className:`selectable text-[12px] text-[var(--text-secondary)]`,children:e.modelId})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(o,{label:a(`routingGroups.enabled`),checked:e.enabled,onChange:i}),(0,U.jsx)(_,{size:`sm`,variant:`plain`,icon:(0,U.jsx)(k,{className:`size-3.5`}),"aria-label":a(`common.edit`),title:a(`common.edit`),onClick:n}),(0,U.jsx)(_,{size:`sm`,variant:`plain`,icon:(0,U.jsx)(j,{className:`size-3.5`}),"aria-label":a(`common.delete`),title:a(`common.delete`),onClick:r})]})]}),(0,U.jsx)(`div`,{className:`mt-3 divide-y divide-[var(--border-subtle)] overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:e.members.map((t,n)=>(0,U.jsx)(se,{member:t,index:n,group:e,live:u.get(G(t)),healthText:c},G(t)))}),t?.lastReason&&t.lastDecisionAt&&(0,U.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--text-muted)]`,children:a(`routingGroups.lastDecision`,{reason:X(t.lastReason,a),time:y(t.lastDecisionAt,s)})})]})}function se({member:e,index:t,group:n,live:r,healthText:i}){let{t:a,locale:o}=p(),s=e.group?`group/${e.group}`:`${r?.providerName??e.provider} · ${e.model}`,c=r?.usedPercent==null?null:a(`routingGroups.quotaUsed`,{percent:Math.round(r.usedPercent)})+(r.resetsAt?` · `+a(`routingGroups.resets`,{time:y(r.resetsAt,o)}):``);return(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-3 py-2 text-[12px]`,children:[(0,U.jsx)(`span`,{className:`w-5 shrink-0 text-center tabular-nums text-[var(--text-muted)]`,children:t+1}),(0,U.jsx)(`span`,{className:`min-w-0 flex-1 basis-44 truncate text-[13px]`,children:s}),n.mode===`weight`&&(0,U.jsx)(l,{tone:`neutral`,children:a(`routingGroups.weightN`,{n:e.weight})}),r&&(0,U.jsx)(l,{tone:Y[r.health]??`neutral`,children:i(r)}),r?.problem&&(0,U.jsx)(l,{tone:`red`,children:a(`routingGroups.memberProblem.${r.problem}`)}),c&&(0,U.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:c}),r&&!c&&r.health!==`group`&&(0,U.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:a(`routingGroups.quotaUnknown`)}),r?.lastUsed&&(0,U.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:a(`routingGroups.lastUsed`,{time:y(r.lastUsed,o)})})]})}function ce({target:e,groups:t,status:i,onClose:s}){let{t:l}=p(),u=Z(),d=f(),m=b(),h=n(),g=e&&`id`in e?e.id:null,[v,y]=(0,H.useState)(K()),[x,S]=(0,H.useState)(!1),[w,E]=(0,H.useState)([]);(0,H.useEffect)(()=>{e&&(y(`id`in e?e.draft:e),S(`id`in e),E([]))},[e]);let D=g?t.find(e=>e.id===g):void 0,O=d.isPending||m.isPending,k=ne(B(te,{activationConstraint:{distance:4}}),B(R,{coordinateGetter:L})),A=e=>y(t=>({...t,...e})),j=e=>A({members:e}),M=new Set(v.members.map(G)),N=(0,H.useMemo)(()=>(h.data??[]).filter(e=>!M.has(`${e.providerId}/${e.id}`)).map(e=>({value:`${e.providerId}/${e.id}`,label:`${e.providerName} · ${e.id}`,m:e})),[h.data,v.members]),V=t.filter(e=>e.id!==g&&!M.has(`group/${e.slug}`)).map(e=>({value:e.slug,label:`group/${e.slug} · ${e.name}`})),q=({active:e,over:t})=>{if(!t||e.id===t.id)return;let n=v.members.findIndex(t=>G(t)===e.id),r=v.members.findIndex(e=>G(e)===t.id);n>=0&&r>=0&&j(F(v.members,n,r))},Y=()=>{let e=oe(v,g===null),t={onSuccess:()=>s(),onError:e=>E(J(e,l))};g?m.mutate({id:g,body:e},t):d.mutate(e,t)},X=new Map(i?.members.map(e=>[e.key,e])??[]),Q=(e,t)=>e.group?`group/${e.group}`:`${t?.providerName??X.get(G(e))?.providerName??e.provider} · ${e.model}`,$=new Map((h.data??[]).map(e=>[`${e.providerId}/${e.id}`,e]));return(0,U.jsx)(C,{open:e!==null,onOpenChange:e=>!e&&s(),width:600,title:D?l(`routingGroups.editTitle`,{name:D.name}):l(`routingGroups.addTitle`),footer:(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(_,{onClick:s,children:l(`common.cancel`)}),(0,U.jsx)(_,{variant:`primary`,disabled:!ae(v),loading:O,onClick:Y,children:l(`common.save`)})]}),children:(0,U.jsxs)(`div`,{className:`grid gap-4`,children:[(0,U.jsx)(a,{label:l(`routingGroups.name`),children:(0,U.jsx)(c,{value:v.name,maxLength:80,placeholder:`Opus anywhere`,onChange:e=>A({name:e.target.value,...!x&&g===null?{slug:ie(e.target.value)}:{}})})}),(0,U.jsx)(a,{label:l(`routingGroups.slug`),hint:g?l(`routingGroups.slugLocked`):l(`routingGroups.slugHint`,{model:`group/${v.slug||`…`}`}),children:(0,U.jsx)(c,{mono:!0,value:v.slug,maxLength:48,disabled:g!==null,placeholder:`opus-anywhere`,onChange:e=>{S(!0),A({slug:e.target.value})}})}),(0,U.jsx)(a,{label:l(`routingGroups.modeLabel`),hint:l(`routingGroups.mode.${v.mode}.hint`),children:(0,U.jsx)(T,{value:v.mode,onChange:e=>A({mode:e}),options:W.map(e=>({value:e,label:l(`routingGroups.mode.${e}`)}))})}),(0,U.jsx)(a,{label:l(`routingGroups.staysLabel`),hint:l(`routingGroups.stays.${v.stays}.hint`),children:(0,U.jsx)(T,{value:v.stays,onChange:e=>A({stays:e}),options:re.map(e=>({value:e,label:l(`routingGroups.stays.${e}`)}))})}),(0,U.jsxs)(`div`,{className:`grid gap-2`,children:[(0,U.jsx)(`div`,{className:`text-[12px] font-medium text-[var(--text-secondary)]`,children:l(`routingGroups.membersTitle`)}),(0,U.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:l(`routingGroups.membersHint`)}),v.members.length===0?(0,U.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:l(`routingGroups.noMembers`)}):(0,U.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,U.jsx)(I,{sensors:k,collisionDetection:P,onDragEnd:q,children:(0,U.jsx)(z,{items:v.members.map(G),strategy:ee,children:v.members.map((e,t)=>(0,U.jsx)(le,{member:e,name:Q(e,$.get(G(e))),weighted:v.mode===`weight`,live:X.get(G(e)),healthText:u,onWeight:e=>j(v.members.map((n,r)=>r===t?{...n,weight:e}:n)),onRemove:()=>j(v.members.filter((e,n)=>n!==t))},G(e)))})})}),(0,U.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,U.jsx)(T,{ariaLabel:l(`routingGroups.addModel`),placeholder:l(`routingGroups.addModel`),value:null,disabled:N.length===0,onChange:e=>{let t=N.find(t=>t.value===e)?.m;t&&j([...v.members,{provider:t.providerId,model:t.id,group:null,weight:1}])},options:N.map(({value:e,label:t})=>({value:e,label:t}))}),(0,U.jsx)(T,{ariaLabel:l(`routingGroups.addGroup`),placeholder:l(`routingGroups.addGroup`),value:null,disabled:V.length===0,onChange:e=>j([...v.members,{provider:null,model:null,group:e,weight:1}]),options:V})]})]}),(0,U.jsxs)(`div`,{className:`grid gap-2 text-[13px]`,children:[(0,U.jsxs)(`label`,{className:`flex items-start justify-between gap-3`,children:[(0,U.jsxs)(`span`,{className:`grid gap-0.5`,children:[(0,U.jsx)(`span`,{children:l(`routingGroups.listed`)}),(0,U.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:l(`routingGroups.listedHint`)})]}),(0,U.jsx)(o,{label:l(`routingGroups.listed`),checked:v.listed,onChange:e=>A({listed:e})})]}),(0,U.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsx)(`span`,{children:l(`routingGroups.enabled`)}),(0,U.jsx)(o,{label:l(`routingGroups.enabled`),checked:v.enabled,onChange:e=>A({enabled:e})})]})]}),w.length>0&&(0,U.jsx)(r,{tone:`danger`,title:l(`routingGroups.refused`),children:(0,U.jsx)(`ul`,{className:`list-disc pl-4`,children:w.map(e=>(0,U.jsx)(`li`,{children:e},e))})})]})})}function le({member:e,name:t,weighted:n,live:r,healthText:i,onWeight:a,onRemove:o}){let{t:s}=p(),{attributes:c,listeners:u,setNodeRef:d,setActivatorNodeRef:f,transform:m,transition:h,isDragging:v}=N({id:G(e)});return(0,U.jsxs)(`div`,{ref:d,style:{transform:M.Transform.toString(m),transition:h},className:g(`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`,v&&`relative z-10 bg-[var(--surface-solid)] shadow-lg`),children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-48 items-center gap-2`,children:[(0,U.jsx)(`button`,{ref:f,type:`button`,"aria-label":s(`clients.dragToReorder`,{provider:t}),title:s(`clients.dragToReorder`,{provider:t}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...c,...u,children:(0,U.jsx)(D,{className:`size-4`})}),(0,U.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:t}),r&&(0,U.jsx)(l,{tone:Y[r.health]??`neutral`,children:i(r)}),r?.problem&&(0,U.jsx)(l,{tone:`red`,children:s(`routingGroups.memberProblem.${r.problem}`)})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,U.jsx)(`div`,{className:`w-20`,children:(0,U.jsx)(x,{label:s(`routingGroups.weight`),placeholder:s(`routingGroups.weight`),value:e.weight,min:1,step:1,onChange:e=>a(e??1)})}),(0,U.jsx)(_,{size:`sm`,variant:`plain`,icon:(0,U.jsx)(j,{className:`size-3.5`}),"aria-label":s(`routingGroups.remove`,{name:t}),title:s(`routingGroups.remove`,{name:t}),onClick:o})]})]})}function ue(){let{t:e}=p();return(0,U.jsx)(V,{title:e(`nav.routingGroups`),subtitle:e(`routingGroups.subtitle`),children:(0,U.jsx)(Q,{})})}export{ue as RoutingGroupsPage};
@@ -0,0 +1,2 @@
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{A as n,Ao as r,B as i,Bt as a,C as o,Dn as s,Do as c,Er as l,F as u,Fo as d,G as f,Gi as p,Gn as m,Hi as h,Ho as g,I as _,Io as v,Ja as y,Ko as b,L as x,Lr as S,M as C,N as w,O as T,On as E,Po as D,Q as O,Qa as k,Qo as A,Ro as ee,Si as te,T as j,Tn as ne,U as M,Uo as N,Va as re,Vo as ie,Vt as P,W as F,Wn as ae,Wo as oe,Wt as se,Xa as ce,Xt as le,Yo as ue,Yt as I,Zn as de,Zt as L,_n as R,a as fe,ar as z,br as pe,da as B,do as me,ds as he,ea as ge,es as _e,fs as ve,ht as ye,is as be,k as V,ls as H,ms as xe,nc as Se,ns as Ce,oa as we,po as Te,pt as Ee,qo as De,r as U,ri as Oe,rn as ke,rr as Ae,rs as je,ta as Me,tc as Ne,to as Pe,ua as W,un as Fe,uo as Ie,us as Le,va as Re,wt as ze,yi as Be,z as Ve,za as He,zt as Ue}from"./format-BmuJU1J1.js";import{B as We,H as Ge,R as G,U as K,V as q,W as J,a as Ke,c as qe,dt as Je,i as Ye,o as Xe,r as Ze,s as Qe}from"./TrayTitleSource-DleIYaE6.js";import{t as $e}from"./use-transform-btbU40wQ.js";import{t as et}from"./archive-CiVf7slo.js";import{t as tt}from"./bell-ring-kS9kGwcv.js";import{t as nt}from"./bell-i0ZTNxjY.js";import{t as rt}from"./book-open-W5VGeEf_.js";import{t as it}from"./copy-48gwhhDO.js";import{t as at}from"./ellipsis-CidyZaW2.js";import{t as ot}from"./external-link-D6jQM2CZ.js";import{t as st}from"./flame-BPbKoD7V.js";import{t as ct}from"./flask-conical-P-TiuT25.js";import{t as lt}from"./folder-open-z1RXMZa1.js";import{t as ut}from"./globe-CFH0vwgV.js";import{t as dt}from"./key-round-m9ps8ZDi.js";import{t as ft}from"./list-checks-CStYtbur.js";import{t as pt}from"./log-out-CgcpH2Q7.js";import{t as mt}from"./minus-BxRsdlKm.js";import{t as ht}from"./panel-top-dXjBAa0g.js";import{t as gt}from"./pencil-CpF9MxGZ.js";import{t as _t}from"./plus-c3HzV6VX.js";import{t as vt}from"./refresh-cw-CoLAai2c.js";import{t as yt}from"./rotate-ccw-fsXoCwyv.js";import{t as bt}from"./sliders-horizontal-B2K_lfHz.js";import{t as xt}from"./trash-BHBJn5GS.js";import{t as St}from"./upload-yXA41tlC.js";import{t as Ct}from"./webhook-BiqcD9Uv.js";import{t as wt}from"./x-AFrW8zH7.js";import{B as Tt,D as Et,E as Dt,G as Ot,O as kt,P as At,W as jt,k as Mt,n as Nt,o as Pt,t as Ft,u as It,v as Lt}from"./index-CZ4Wdbud.js";import{t as Rt}from"./checkbox-DKNuVOmF.js";import{t as zt}from"./radio-cards-BvgAI3-W.js";import{t as Bt}from"./TrayPanelView-wy6Co_3P.js";var Y=e(t(),1),X=Se(),Vt=[`settings`,`prices`,`providers`,`signins`,`tokens`,`routing`,`privacy`,`tools`,`profiles`,`mcp`,`alerts`,`plugins`,`library`,`clients`,`usage`],Ht=(e,t)=>{let n=`backup.all.section.${t}`,r=e(n);return r===n?t:r};function Ut(e,t){let n=URL.createObjectURL(new Blob([t],{type:`application/json`})),r=document.createElement(`a`);r.href=n,r.download=e,r.click(),URL.revokeObjectURL(n)}function Wt(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Gt(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Kt({ids:e,picked:t,onChange:n,counts:r,disabled:i}){let{t:a}=j();return(0,X.jsx)(`div`,{className:`grid gap-x-4 gap-y-1.5 sm:grid-cols-2 md:grid-cols-3`,role:`group`,"aria-label":a(`backup.all.sections`),children:e.map(e=>(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(Rt,{checked:t.has(e),disabled:i,"aria-label":Ht(a,e),onCheckedChange:r=>{let i=new Set(t);r===!0?i.add(e):i.delete(e),n(i)}}),(0,X.jsx)(`span`,{children:Ht(a,e)}),r&&e in r&&(0,X.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:r[e]})]},e))})}var qt={added:`green`,changed:`orange`,removed:`red`,unchanged:`neutral`};function Jt({items:e,truncated:t}){let{t:n}=j();return(0,X.jsxs)(`ul`,{className:`max-h-[220px] divide-y divide-[var(--border)] overflow-auto text-[12px]`,children:[e.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 px-3 py-1.5`,children:[(0,X.jsx)(T,{tone:qt[e.status]??`neutral`,children:n(`backup.all.status.${e.status}`)}),(0,X.jsx)(`span`,{className:`min-w-0 truncate`,title:e.id,children:e.label||e.id})]},`${e.id}-${e.status}`)),t&&(0,X.jsx)(`li`,{className:`px-3 py-1.5 text-[11px] text-[var(--text-muted)]`,children:n(`backup.all.truncated`)})]})}function Yt({plan:e}){let{t}=j();return(0,X.jsxs)(`div`,{className:`grid gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:Ht(t,e.section)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,"data-testid":`plan-${e.section}`,children:t(`backup.all.counts`,{added:e.added,changed:e.changed,removed:e.removed,unchanged:e.unchanged})})]}),e.items.length>0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(Jt,{items:e.items,truncated:e.truncated})})]})}function Xt({localOnly:e,onRestore:t}){let{t:n}=j(),{toast:r,confirm:a}=J(),o=le(),s=Me(),c=ge(),l=E(),u=o.data,[d,p]=(0,Y.useState)(`24`),[m,h]=(0,Y.useState)(`7`),[g,v]=(0,Y.useState)(``);(0,Y.useEffect)(()=>{u&&(p(String(u.hours)),h(String(u.keep)))},[u?.hours,u?.keep]);let y=(e,t)=>s.mutate(e,{onSuccess:t,onError:e=>r(K(e),`error`)});if(!u)return null;let b=Number(d),S=Number(m),C=Number.isInteger(b)&&b>=1&&Number.isInteger(S)&&S>=1;return(0,X.jsxs)(_,{title:n(`backup.all.auto.title`),footer:e?n(`backup.all.localOnly`):n(`backup.all.auto.hint`,{dir:u.dir}),children:[(0,X.jsx)(i,{label:n(`backup.all.auto.enabled`),children:(0,X.jsx)(f,{checked:u.enabled,disabled:e||s.isPending,label:n(`backup.all.auto.enabled`),onChange:e=>y({enabled:e})})}),(0,X.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[12.5px]`,children:[(0,X.jsxs)(`label`,{className:`flex items-center gap-2`,children:[n(`backup.all.auto.every`),(0,X.jsx)(x,{className:`w-20`,type:`number`,min:1,"aria-label":n(`backup.all.auto.every`),value:d,onChange:e=>p(e.target.value)}),n(`backup.all.auto.hours`)]}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2`,children:[n(`backup.all.auto.keep`),(0,X.jsx)(x,{className:`w-20`,type:`number`,min:1,"aria-label":n(`backup.all.auto.keep`),value:m,onChange:e=>h(e.target.value)})]}),(0,X.jsx)(V,{size:`sm`,disabled:e||!C||s.isPending||b===u.hours&&S===u.keep,onClick:()=>y({hours:b,keep:S}),children:n(`common.save`)})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(x,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":n(`backup.all.auto.passphrase`),placeholder:u.hasPassphrase?n(`backup.all.auto.passphraseSet`):n(`backup.all.auto.passphrase`),value:g,disabled:e,onChange:e=>v(e.target.value)}),(0,X.jsx)(V,{size:`sm`,disabled:e||g.length<8||s.isPending,onClick:()=>y({passphrase:g},()=>v(``)),children:n(`backup.all.auto.setPassphrase`)}),u.hasPassphrase&&(0,X.jsx)(V,{size:`sm`,disabled:e||s.isPending,onClick:()=>y({clearPassphrase:!0}),children:n(`backup.all.auto.clearPassphrase`)})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(`backup.all.auto.passphraseHint`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(V,{variant:`primary`,disabled:e||c.isPending,onClick:()=>c.mutate(void 0,{onSuccess:()=>r(n(`backup.all.auto.ran`)),onError:e=>r(K(e),`error`)}),children:n(`backup.all.auto.run`)})})]}),u.files.length===0?(0,X.jsx)(`p`,{className:`px-4 py-3 text-[12px] text-[var(--text-muted)]`,children:n(`backup.all.auto.empty`)}):u.files.map(i=>(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-4 py-2.5 text-[12.5px]`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,title:i.name,children:i.name}),(0,X.jsx)(T,{tone:i.kind===`auto`?`neutral`:`accent`,children:n(`backup.all.auto.kind.${i.kind}`)}),i.encrypted&&(0,X.jsx)(T,{tone:`orange`,children:n(`backup.all.auto.encrypted`)}),(0,X.jsxs)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:[Gt(i.at),` · `,Wt(i.size)]}),(0,X.jsx)(V,{size:`sm`,disabled:e,onClick:()=>t(i.name),children:n(`backup.all.auto.restoreFrom`)}),(0,X.jsx)(V,{size:`sm`,icon:(0,X.jsx)(xt,{className:`size-3.5`}),"aria-label":n(`common.delete`),disabled:e||l.isPending,onClick:async()=>{await a({title:n(`backup.all.auto.deleteConfirm`,{name:i.name}),destructive:!0,confirmLabel:n(`common.delete`)})&&l.mutate(i.name,{onError:e=>r(K(e),`error`)})}})]},i.name))]})}function Zt({localOnly:e}){let{t}=j(),{toast:n}=J(),r=z(),i=de(),[a,s]=(0,Y.useState)(()=>new Set(Vt.filter(e=>e!==`usage`))),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(null),m=c&&!e,h=i.isPending||a.size===0||m&&u.length<8;return(0,X.jsx)(_,{title:t(`backup.all.export.title`),footer:t(`backup.all.export.hint`),children:(0,X.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,X.jsx)(Kt,{ids:Vt,picked:a,onChange:s,counts:r.data?.sections}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(Rt,{checked:m,disabled:e,"aria-label":t(`backup.all.export.keys`),onCheckedChange:e=>l(e===!0)}),(0,X.jsx)(`span`,{children:t(`backup.all.export.keys`)})]}),e&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`backup.all.localOnly.keys`)}),m&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(x,{type:`password`,autoComplete:`new-password`,"aria-label":t(`backup.all.passphrase`),placeholder:t(`backup.all.passphrase`),value:u,onChange:e=>d(e.target.value)}),(0,X.jsx)(o,{tone:`warning`,title:t(`backup.all.passphrase.warn`)}),u.length>0&&u.length<8&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--danger)]`,children:t(`backup.all.passphrase.short`,{min:8})})]}),!m&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`backup.all.export.noKeys`)}),f&&(0,X.jsx)(o,{tone:`danger`,title:t(`common.error`),children:f}),(0,X.jsx)(`div`,{children:(0,X.jsx)(V,{variant:`primary`,icon:(0,X.jsx)(Tt,{className:`size-3.5`}),disabled:h,onClick:()=>{p(null),i.mutate({sections:Vt.filter(e=>a.has(e)&&e!==`usage`),includeUsage:a.has(`usage`),includeKeys:m,passphrase:m?u:void 0},{onSuccess:e=>{Ut(e.name,e.content),n(t(`backup.all.export.done`,{count:e.documents})),d(``)},onError:e=>p(K(e))})},children:t(`backup.all.export.run`)})})]})})}function Qt({localOnly:e,autoName:t}){let{t:n}=j(),{toast:r,confirm:i}=J(),a=le(!e),s=Oe(),c=p(),l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(`file`),[f,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(``),[v,y]=(0,Y.useState)(``),[b,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)(`merge`),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(new Set),[A,ee]=(0,Y.useState)(null),[te,ne]=(0,Y.useState)(null),N=()=>{D(null),ee(null),ne(null)};(0,Y.useEffect)(()=>{t&&(d(`auto`),y(t),N())},[t]);let re=e=>({source:u,content:u===`file`?f??void 0:void 0,name:u===`auto`?v:void 0,passphrase:b||void 0,sections:e,mode:C}),ie=u===`file`?f!==null:u!==`auto`||v!==``,P=()=>{N(),s.mutate(re(),{onSuccess:e=>{D(e),k(new Set(e.available))},onError:e=>ne(K(e))})},F=async()=>{E&&(C!==`replace`||await i({title:n(`backup.all.restore.replaceConfirm`),detail:n(`backup.all.restore.replaceDetail`),confirmLabel:n(`backup.all.restore.run`),destructive:!0}))&&(ne(null),c.mutate(re(E.legacy?void 0:[...O]),{onSuccess:e=>{ee(e),D(null),S(``),r(n(`backup.all.restore.done`,{written:e.written,removed:e.removed}))},onError:e=>ne(K(e))}))},ae=async e=>{N(),m(null),g(``),e&&(m(await e.text()),g(e.name))},oe=a.data?.files??[];return(0,X.jsx)(_,{title:n(`backup.all.restore.title`),footer:e?n(`backup.all.localOnly`):void 0,children:(0,X.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,X.jsx)(M,{value:u,onChange:e=>{d(e),N()},items:[{value:`file`,label:n(`backup.all.restore.source.file`)},{value:`auto`,label:n(`backup.all.restore.source.auto`)},{value:`remote`,label:n(`backup.all.restore.source.remote`)}]}),u===`file`&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`input`,{ref:l,type:`file`,className:`hidden`,"aria-label":n(`backup.all.restore.choose`),onChange:e=>{ae(e.target.files?.[0]),e.target.value=``}}),(0,X.jsx)(V,{icon:(0,X.jsx)(St,{className:`size-3.5`}),disabled:e,onClick:()=>l.current?.click(),children:n(`backup.all.restore.choose`)}),h&&(0,X.jsx)(`span`,{className:`truncate font-mono text-[12px]`,children:h})]}),u===`auto`&&(0,X.jsx)(q,{className:`w-full`,ariaLabel:n(`backup.all.restore.source.auto`),placeholder:n(`backup.all.restore.pickAuto`),value:v||null,onChange:e=>{y(e),N()},options:oe.map(e=>({value:e.name,label:`${e.name} · ${Gt(e.at)}`}))}),u===`remote`&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`backup.all.restore.remoteHint`)}),(0,X.jsx)(x,{type:`password`,autoComplete:`off`,"aria-label":n(`backup.all.restore.passphrase`),placeholder:n(`backup.all.restore.passphrase`),value:b,onChange:e=>S(e.target.value)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[12.5px] text-[var(--text-muted)]`,children:n(`backup.all.restore.mode`)}),(0,X.jsx)(M,{value:C,onChange:e=>{w(e),N()},items:[{value:`merge`,label:n(`backup.all.restore.mode.merge`)},{value:`replace`,label:n(`backup.all.restore.mode.replace`)}]})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:n(C===`merge`?`backup.all.restore.mode.mergeHint`:`backup.all.restore.mode.replaceHint`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(V,{disabled:e||!ie||s.isPending,onClick:P,children:n(`backup.all.restore.preview`)})}),te&&(0,X.jsx)(o,{tone:`danger`,title:n(`common.error`),children:te}),E&&(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[12px] text-[var(--text-muted)]`,children:[(0,X.jsx)(`span`,{children:n(`backup.all.restore.created`,{time:Gt(E.createdAt),version:E.astraVersion})}),(0,X.jsx)(T,{tone:E.hasKeys?`orange`:`neutral`,children:E.hasKeys?n(`backup.all.restore.hasKeys`):n(`backup.all.restore.noKeys`)})]}),E.notes.map(e=>(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:e},e)),E.legacy?(0,X.jsx)(o,{tone:`info`,title:n(`backup.all.restore.legacy`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Kt,{ids:E.available,picked:O,onChange:k}),(0,X.jsx)(`div`,{className:`grid gap-3`,children:E.sections.filter(e=>O.has(e.section)).map(e=>(0,X.jsx)(Yt,{plan:e},e.section))})]}),(0,X.jsx)(`div`,{children:(0,X.jsx)(V,{variant:`primary`,disabled:c.isPending||!E.legacy&&O.size===0,onClick:()=>void F(),children:n(`backup.all.restore.run`)})})]}),A&&(0,X.jsxs)(`div`,{className:`grid gap-2`,"data-testid":`restore-result`,children:[(0,X.jsx)(o,{tone:A.errors.length>0?`warning`:`success`,title:n(`backup.all.restore.done`,{written:A.written,removed:A.removed})}),A.safetyBackup&&(0,X.jsx)(`p`,{className:`text-[12px]`,children:n(`backup.all.restore.safety`,{name:A.safetyBackup})}),A.skipped.length>0&&(0,X.jsxs)(`div`,{className:`text-[12px]`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:n(`backup.all.restore.skipped`,{count:A.skipped.length})}),(0,X.jsx)(`ul`,{className:`list-disc pl-5 text-[var(--text-muted)]`,children:A.skipped.map(e=>(0,X.jsx)(`li`,{children:e},e))})]}),A.errors.length>0&&(0,X.jsxs)(`div`,{className:`text-[12px]`,children:[(0,X.jsx)(`div`,{className:`font-medium text-[var(--danger)]`,children:n(`backup.all.restore.errors`,{count:A.errors.length})}),(0,X.jsx)(`ul`,{className:`list-disc pl-5 text-[var(--danger)]`,children:A.errors.map(e=>(0,X.jsx)(`li`,{children:e},e))})]})]})]})})}var $t=Vt.filter(e=>e!==`usage`),en=[`folder`,`webdav`,`s3`,`github`];function tn({localOnly:e}){let{t}=j(),{toast:n,confirm:r}=J(),a=re().data,s=we(),c=y(),l=He(),u=Ae(),d=Fe(),p=ee(),[m,h]=(0,Y.useState)(`folder`),[g,v]=(0,Y.useState)(``),[b,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)(``),[E,D]=(0,Y.useState)(``),[O,k]=(0,Y.useState)(``),[A,te]=(0,Y.useState)(``),[ne,M]=(0,Y.useState)(!1),[N,ie]=(0,Y.useState)(``),[P,F]=(0,Y.useState)(``),[ae,oe]=(0,Y.useState)(`15`),[se,ce]=(0,Y.useState)(new Set($t)),[le,ue]=(0,Y.useState)(!1),[I,de]=(0,Y.useState)(!1),[L,R]=(0,Y.useState)(null),[fe,z]=(0,Y.useState)(null),pe=a?.configured;if((0,Y.useEffect)(()=>{if(!a)return;let e=a.target;h(e.kind||`folder`),v(e.url),S(e.username),D(e.folder),k(e.bucket),te(e.region),M(e.pathStyle),ie(e.branch),oe(String(a.intervalMinutes||15)),ce(new Set(a.sections.length>0?a.sections:$t)),ue(a.includeKeys),de(a.includeSignins),w(``),F(``)},[a===void 0,pe]),!a)return null;let B=e=>z(K(e)),me=()=>({kind:m,url:m===`webdav`||m===`s3`||m===`github`?g.trim():void 0,username:m===`webdav`||m===`s3`?b.trim():void 0,secret:C||void 0,folder:E.trim(),bucket:m===`s3`?O.trim():void 0,region:m===`s3`?A.trim():void 0,pathStyle:m===`s3`?ne:void 0,branch:m===`github`?N.trim():void 0}),he=()=>({target:me(),passphrase:P||void 0,intervalMinutes:Math.max(1,Number(ae)||15),sections:[...$t.filter(e=>se.has(e))],includeKeys:le,includeSignins:I}),ge=e=>{z(null),s.mutate(he(),{onSuccess:()=>{w(``),F(``),e?.()},onError:B})},_e=()=>ge(()=>c.mutate(void 0,{onSuccess:()=>n(t(`sync.test.ok`)),onError:B})),ve=e=>{z(null),R(null),l.mutate(e,{onSuccess:r=>{R(r),e||n(t(`sync.run.done`,{pushed:r.pushed,pulled:r.pulled}))},onError:B})},ye=async()=>{await r({title:t(`sync.forget.confirm`),detail:t(`sync.forget.detail`),destructive:!0,confirmLabel:t(`sync.forget`)})&&u.mutate(void 0,{onSuccess:()=>R(null),onError:B})},be=()=>{z(null),p.mutate({sections:[...$t.filter(e=>se.has(e))],includeKeys:le,passphrase:P||void 0},{onSuccess:e=>n(t(`sync.upload.done`,{name:e.name})),onError:B})},H=s.isPending||c.isPending||l.isPending||a.running,xe=a.target.hasSecret&&a.target.kind===m?t(`sync.secret.saved`):t(`sync.secret.${m}`),Se=P.length===0?a.hasPassphrase:P.length>=8;return(0,X.jsxs)(_,{title:t(`sync.title`),footer:t(e?`backup.all.localOnly`:`sync.hint`),children:[(0,X.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[12.5px] text-[var(--text-muted)]`,children:t(`sync.kind`)}),(0,X.jsx)(q,{className:`w-56`,ariaLabel:t(`sync.kind`),value:m,disabled:e,onChange:e=>h(e),options:en.map(e=>({value:e,label:t(`sync.kind.${e}`)}))})]}),(m===`webdav`||m===`s3`||m===`github`)&&(0,X.jsx)(x,{"aria-label":t(`sync.url.${m}`),placeholder:t(`sync.url.${m}`),value:g,disabled:e,onChange:e=>v(e.target.value)}),m===`s3`&&(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsx)(x,{"aria-label":t(`sync.bucket`),placeholder:t(`sync.bucket`),value:O,disabled:e,onChange:e=>k(e.target.value)}),(0,X.jsx)(x,{"aria-label":t(`sync.region`),placeholder:t(`sync.region`),value:A,disabled:e,onChange:e=>te(e.target.value)})]}),(m===`webdav`||m===`s3`)&&(0,X.jsx)(x,{"aria-label":t(m===`s3`?`sync.accessKey`:`sync.username`),placeholder:t(m===`s3`?`sync.accessKey`:`sync.username`),value:b,disabled:e,onChange:e=>S(e.target.value)}),m!==`folder`&&(0,X.jsx)(x,{type:`password`,autoComplete:`new-password`,"aria-label":t(`sync.secret`),placeholder:xe,value:C,disabled:e,onChange:e=>w(e.target.value)}),m===`github`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(x,{"aria-label":t(`sync.branch`),placeholder:t(`sync.branch`),value:N,disabled:e,onChange:e=>ie(e.target.value)}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`sync.github.private`)})]}),m===`s3`&&(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(Rt,{checked:ne,disabled:e,"aria-label":t(`sync.pathStyle`),onCheckedChange:e=>M(e===!0)}),(0,X.jsx)(`span`,{children:t(`sync.pathStyle`)})]}),(0,X.jsx)(x,{"aria-label":t(`sync.folder`),placeholder:t(`sync.folder.${m}`),value:E,disabled:e,onChange:e=>D(e.target.value)}),(0,X.jsx)(x,{type:`password`,autoComplete:`new-password`,"aria-label":t(`sync.passphrase`),placeholder:a.hasPassphrase?t(`sync.passphrase.saved`):t(`sync.passphrase`),value:P,disabled:e,onChange:e=>F(e.target.value)}),(0,X.jsx)(o,{tone:`warning`,title:t(`sync.passphrase.warn`)}),P.length>0&&P.length<8&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--danger)]`,children:t(`backup.all.passphrase.short`,{min:8})}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[t(`sync.interval`),(0,X.jsx)(x,{className:`w-20`,type:`number`,min:1,"aria-label":t(`sync.interval`),value:ae,disabled:e,onChange:e=>oe(e.target.value)}),t(`sync.minutes`)]}),(0,X.jsx)(Kt,{ids:$t,picked:se,onChange:ce,disabled:e}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(Rt,{checked:I,disabled:e,"aria-label":t(`sync.includeSignins`),onCheckedChange:e=>de(e===!0)}),(0,X.jsx)(`span`,{children:t(`sync.includeSignins`)})]}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,X.jsx)(Rt,{checked:le,disabled:e,"aria-label":t(`sync.includeKeys`),onCheckedChange:e=>ue(e===!0)}),(0,X.jsx)(`span`,{children:t(`sync.includeKeys`)})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`sync.includeKeys.hint`)}),fe&&(0,X.jsx)(o,{tone:`danger`,title:t(`common.error`),children:fe}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(V,{disabled:e||H,onClick:_e,children:t(`sync.test`)}),(0,X.jsx)(V,{variant:`primary`,disabled:e||H||!Se,onClick:()=>ge(()=>n(t(`sync.saved`))),children:t(`common.save`)}),(0,X.jsx)(V,{disabled:e||H||!a.configured,onClick:()=>ve(!1),children:t(`sync.now`)}),(0,X.jsx)(V,{disabled:e||H||!a.configured,onClick:()=>ve(!0),children:t(`sync.preview`)}),(0,X.jsx)(V,{disabled:e||H||!a.configured,onClick:be,children:t(`sync.upload`)}),(0,X.jsx)(V,{disabled:e||u.isPending||!a.configured,onClick:()=>void ye(),children:t(`sync.forget`)})]})]}),(0,X.jsx)(i,{label:t(`sync.enabled`),detail:a.configured?void 0:t(`sync.notConfigured`),children:(0,X.jsx)(f,{checked:a.enabled,disabled:e||!a.configured||s.isPending,label:t(`sync.enabled`),onChange:e=>s.mutate({enabled:e},{onError:B})})}),(0,X.jsx)(nn,{s:a}),L&&(0,X.jsxs)(`div`,{className:`grid gap-2 p-4`,"data-testid":`sync-run`,children:[(0,X.jsx)(`div`,{className:`text-[12.5px] font-medium`,children:L.dryRun?t(`sync.run.preview`,{pushed:L.pushed,pulled:L.pulled}):t(`sync.run.done`,{pushed:L.pushed,pulled:L.pulled})}),L.firstSync&&(0,X.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`sync.run.first`)}),L.items.length>0&&(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(Jt,{items:L.items})}),L.errors.map(e=>(0,X.jsx)(o,{tone:`danger`,title:e},e))]}),a.conflicts.length>0&&(0,X.jsxs)(`div`,{className:`grid gap-2 p-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-[12.5px] font-medium`,children:t(`sync.conflicts`,{count:a.conflicts.length})}),(0,X.jsx)(V,{size:`sm`,disabled:e||d.isPending,onClick:()=>d.mutate(void 0,{onError:B}),children:t(`sync.conflicts.clear`)})]}),(0,X.jsx)(`ul`,{className:`card divide-y divide-[var(--border)] text-[12px]`,children:a.conflicts.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2 px-3 py-1.5`,children:[(0,X.jsx)(T,{children:t(`backup.all.section.${e.section}`)}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label||e.id}),(0,X.jsx)(T,{tone:e.winner===`local`?`green`:`orange`,children:e.winner===`local`?t(`sync.winner.local`):t(`sync.winner.remote`)}),(0,X.jsxs)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:[Gt(e.at),` · `,e.device]})]},`${e.section}/${e.id}/${e.at}`))})]})]})}function nn({s:e}){let{t}=j();return(0,X.jsxs)(`div`,{className:`grid gap-1 p-4 text-[12px]`,"data-testid":`sync-status`,children:[(0,X.jsxs)(`div`,{children:[t(`sync.status.last`),`: `,e.lastSyncAt?Gt(e.lastSyncAt):t(`sync.status.never`),e.running&&` · ${t(`sync.status.running`)}`]}),(0,X.jsx)(`div`,{children:t(`sync.status.counts`,{pushed:e.lastPushed,pulled:e.lastPulled,tracked:e.tracked})}),(0,X.jsxs)(`div`,{className:`text-[var(--text-muted)]`,children:[t(`sync.status.device`),`: `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.deviceId})]}),e.lastError&&(0,X.jsx)(o,{tone:`danger`,title:t(`sync.status.error`),children:e.lastError})]})}function rn(){let{t:e}=j(),t=I().data?.required===!0,[n,r]=(0,Y.useState)(null);return(0,X.jsxs)(`div`,{className:`grid gap-1`,children:[t&&(0,X.jsx)(o,{tone:`info`,title:e(`backup.all.localOnly`)}),(0,X.jsx)(Zt,{localOnly:t}),(0,X.jsx)(Qt,{localOnly:t,autoName:n}),(0,X.jsx)(Xt,{localOnly:t,onRestore:r}),(0,X.jsx)(tn,{localOnly:t})]})}var an=`https://astra-gate.si/docs/guide/remote-access`,on=`astra.remote.acknowledged`;function sn(e,t){return e.mode===`named`&&!e.hasToken?t(`settings.remote.block.token`):e.mode===`named`&&!e.hostname?t(`settings.remote.block.hostname`):e.allowAdmin&&!e.checks.passwordSet?t(`settings.remote.block.password`):e.checks.blocker??null}function cn(e,t,n){return/can no longer be read/i.test(e)?n(`settings.remote.err.tokenLost`):/downloading cloudflared|checksum/i.test(e)?n(`settings.remote.err.download`):/unauthorized|invalid tunnel secret|token.*(invalid|not valid|malformed)/i.test(e)?n(`settings.remote.err.token`):/origin service|origin server/i.test(e)?n(`settings.remote.err.origin`,{origin:t.originUrl}):/429|too many requests|rate.?limit/i.test(e)?n(`settings.remote.err.rate`):/dial|timeout|timed out|no such host|unreachable|quic|edge/i.test(e)?n(`settings.remote.err.network`):n(`settings.remote.err.generic`)}function ln(){try{return localStorage.getItem(on)===`1`}catch{return!1}}function un(){try{localStorage.setItem(on,`1`)}catch{}}function dn(){let{t:e}=j(),t=Ie(),n=t.data;return n?n.supported?(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsx)(fn,{s:n}),(0,X.jsx)(pn,{s:n}),(0,X.jsx)(mn,{s:n}),(0,X.jsx)(_n,{s:n}),(0,X.jsx)(C,{title:n.cloudflared.path&&n.cloudflared.version?e(`settings.remote.logWithVersion`,{version:n.cloudflared.version}):e(`settings.remote.log`),children:n.log.length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:e(`settings.remote.logEmpty`)}):(0,X.jsx)(`pre`,{className:`max-h-72 overflow-auto font-mono text-[10.5px] leading-relaxed whitespace-pre-wrap text-[var(--text-secondary)] selectable`,children:n.log.join(`
2
+ `)})})]}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:(0,X.jsx)(o,{tone:`info`,title:e(`settings.remote.unsupported`),children:e(`settings.remote.unsupportedDetail`)})}):(0,X.jsx)(`div`,{className:`mx-auto max-w-[680px]`,children:t.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:K(t.error)}):(0,X.jsx)(F,{className:`mx-auto my-8`})})}function fn({s:e}){let{t,locale:n}=j(),{toast:r,confirm:a}=J(),s=k(),c=I(),l=sn(e,t),u=async e=>{await G.copy(e)&&r(t(`common.copied`))},d=async e=>{if(e&&!ln()){if(!await a({title:t(`settings.remote.enableConfirm`),detail:t(`settings.remote.enableDetail`),confirmLabel:t(`settings.remote.enableAction`)}))return;un()}(e||!c.data?.remote||await a({title:t(`settings.remote.disableSelfConfirm`),detail:t(`settings.remote.disableSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&s.mutate(e,{onError:e=>r(K(e),`error`)})},p=e.state===`connected`?`green`:e.state===`off`?`neutral`:`orange`,m=e.connectedAt?Date.now()-new Date(e.connectedAt).getTime():null,h=e.state===`connected`&&m!==null?m<6e4?t(`settings.remote.connectedJustNow`):t(`settings.remote.connectedFor`,{duration:fe(m,n)}):e.state===`downloading`&&e.cloudflared.source?t(`settings.remote.state.downloadingFrom`,{source:e.cloudflared.source}):t(`settings.remote.state.${e.state}`),g=e.cloudflared,v=g.downloading||g.path?null:g.asset?t(`settings.remote.cloudflaredMissing`,{version:g.version??``}):t(`settings.remote.cloudflaredUnsupported`),y=e.enabled?e.error??g.error??null:null,b=y!==null&&(e.state!==`connected`||/origin service|origin server/i.test(y)),x=e.publicUrl;return(0,X.jsxs)(_,{title:t(`settings.remote.status`),footer:t(`settings.remote.statusFooter`),children:[(0,X.jsx)(i,{label:t(`settings.remote.enable`),detail:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.connectedAt?U(e.connectedAt,n):void 0,children:[(0,X.jsx)(w,{tone:p}),h,g.downloading&&g.progress!=null&&(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[Math.round(g.progress*100),`%`]})]}),children:(0,X.jsx)(f,{checked:e.enabled,label:t(`settings.remote.enable`),disabled:s.isPending||!e.enabled&&l!==null,onChange:e=>void d(e)})}),!e.enabled&&l&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:l}),!e.enabled&&!l&&v&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--text-muted)]`,children:v}),e.enabled&&x&&(0,X.jsxs)(i,{label:t(`settings.remote.publicUrl`),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:`${x}/v1`}),children:[(0,X.jsx)(We,{label:t(`settings.remote.copyMenu`),icon:(0,X.jsx)(it,{className:`size-3.5`}),iconOnly:!0,items:[{id:`openai`,label:t(`settings.remote.copy.openai`),onSelect:()=>void u(`${x}/v1`)},{id:`anthropic`,label:t(`settings.remote.copy.anthropic`),onSelect:()=>void u(x)},{id:`key`,label:t(`settings.remote.copy.key`),onSelect:()=>void u(`${x}/key`),separatorBefore:!0}]}),(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(ot,{className:`size-3.5`}),"aria-label":t(`settings.remote.openPage`),title:t(`settings.remote.openPage`),onClick:()=>window.open(x,`_blank`,`noopener`)})]}),e.enabled&&x&&(0,X.jsx)(`p`,{className:`px-4 py-2 text-[11px] text-[var(--text-muted)]`,children:t(`settings.remote.publicUrlHint`)}),b&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(o,{tone:e.state===`connected`?`warning`:`danger`,title:cn(y,e,t),children:y})})]})}function pn({s:e}){let{t}=j(),{toast:n,confirm:r}=J(),a=D(),[s,c]=(0,Y.useState)({token:``,hostname:e.hostname??``});(0,Y.useEffect)(()=>c(t=>({...t,hostname:e.hostname??``})),[e.hostname]);let l=async e=>{await G.copy(e)&&n(t(`common.copied`))},u=async i=>{if(e.enabled){let n=i===`named`&&(!e.hasToken||!e.hostname);if(!await r({title:t(`settings.remote.modeSwitchConfirm`),detail:t(n?`settings.remote.modeSwitchStopDetail`:`settings.remote.modeSwitchDetail`),confirmLabel:t(`settings.remote.modeSwitchAction`),destructive:n}))return}a.mutate({mode:i},{onError:e=>n(K(e),`error`)})},d=()=>a.mutate({hostname:s.hostname.trim()||null,...s.token.trim()?{token:s.token.trim()}:{}},{onSuccess:e=>{n(e.enabled?t(`settings.remote.savedRestart`):t(`settings.remote.saved`)),c(e=>({...e,token:``}))},onError:e=>n(K(e),`error`)}),f=s.token.trim()!==``||s.hostname.trim()!==(e.hostname??``);return(0,X.jsxs)(_,{title:t(`settings.remote.mode`),footer:e.mode===`named`?t(`settings.remote.namedFooter`):void 0,children:[(0,X.jsx)(i,{label:t(`settings.remote.modeLabel`),detail:t(`settings.remote.mode.${e.mode}.hint`),children:(0,X.jsx)(M,{ariaLabel:t(`settings.remote.modeLabel`),value:e.mode,onChange:e=>void u(e),items:[{value:`quick`,label:t(`settings.remote.mode.quick`)},{value:`named`,label:t(`settings.remote.mode.named`)}]})}),e.mode===`quick`?(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(o,{tone:`warning`,title:t(`settings.remote.quickWarning`)})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(i,{label:t(`settings.remote.token`),detail:e.hasToken?t(`settings.remote.tokenSaved`):t(`settings.remote.tokenHint`),children:(0,X.jsx)(x,{className:`w-64`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":t(`settings.remote.token`),placeholder:e.hasToken?`••••••••`:`eyJhIjoi…`,value:s.token,onChange:e=>c({...s,token:e.target.value})})}),(0,X.jsx)(i,{label:t(`settings.remote.hostname`),detail:t(`settings.remote.hostnameHint`),children:(0,X.jsx)(x,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.hostname`),placeholder:`astra.example.com`,value:s.hostname,onChange:e=>c({...s,hostname:e.target.value})})}),(0,X.jsxs)(i,{label:t(`settings.remote.origin`),detail:t(`settings.remote.originHint`),children:[(0,X.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.originUrl}),(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),"aria-label":t(`common.copy`),onClick:()=>void l(e.originUrl)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2`,children:[(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(rt,{className:`size-3.5`}),onClick:()=>window.open(an,`_blank`,`noopener`),children:t(`settings.remote.guide`)}),(0,X.jsx)(V,{size:`sm`,disabled:!f||a.isPending,onClick:d,children:t(`common.save`)})]})]})]})}function mn({s:e}){let{t}=j(),{toast:n,confirm:r}=J(),a=D(),o=I(),s=async e=>{(!e||await r({title:t(`settings.remote.adminConfirm`),detail:t(`settings.remote.adminDetail`),confirmLabel:t(`settings.remote.adminAction`),destructive:!0}))&&(e||!o.data?.remote||await r({title:t(`settings.remote.adminOffSelfConfirm`),detail:t(`settings.remote.adminOffSelfDetail`),confirmLabel:t(`settings.remote.disableAction`),destructive:!0}))&&a.mutate({allowAdmin:e},{onError:e=>n(K(e),`error`)})};return(0,X.jsxs)(_,{title:t(`settings.remote.scope`),footer:t(`settings.remote.scopeFooter`),children:[(0,X.jsx)(i,{label:t(`settings.remote.scope.gateway`),detail:t(`settings.remote.scope.gatewayHint`),children:(0,X.jsx)(T,{tone:`green`,children:t(`settings.remote.scope.gatewayBadge`)})}),(0,X.jsx)(i,{label:t(`settings.remote.scope.admin`),detail:e.checks.passwordSet?t(`settings.remote.scope.adminHint`):t(`settings.remote.block.password`),children:(0,X.jsx)(f,{checked:e.allowAdmin,label:t(`settings.remote.scope.admin`),disabled:a.isPending||!e.allowAdmin&&!e.checks.passwordSet,onChange:e=>void s(e)})}),(0,X.jsx)(hn,{passwordSet:e.checks.passwordSet})]})}function hn({passwordSet:e}){let{t}=j(),{toast:n}=J(),r=I(),a=W(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(``);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(i,{label:t(`settings.remote.password`),detail:t(e?`settings.remote.passwordSet`:`settings.remote.passwordMissing`),children:!o&&!r.data?.required&&(0,X.jsx)(V,{size:`sm`,onClick:()=>s(!0),children:t(e?`settings.remote.passwordChange`:`settings.remote.passwordSetAction`)})}),o&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(x,{className:`w-64`,type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":t(`settings.remote.passwordNew`),placeholder:t(`settings.remote.passwordNew`),value:c,onChange:e=>l(e.target.value)}),(0,X.jsx)(V,{size:`sm`,variant:`plain`,onClick:()=>s(!1),children:t(`common.cancel`)}),(0,X.jsx)(V,{size:`sm`,variant:`primary`,disabled:c.length<8,loading:a.isPending,onClick:()=>a.mutate(c,{onSuccess:()=>{n(t(`settings.remote.passwordSaved`)),s(!1),l(``)},onError:e=>n(K(e),`error`)}),children:t(`common.save`)})]})]})}var gn=[`auto`,`github`,`astra`,`custom`];function _n({s:e}){let{t}=j(),{toast:n}=J(),r=D(),a=m(),o=I(),s=e.cloudflared,[c,l]=(0,Y.useState)(e.download.downloadBaseUrl??``),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(``);(0,Y.useEffect)(()=>l(e.download.downloadBaseUrl??``),[e.download.downloadBaseUrl]);let[h,g]=(0,Y.useState)(e.download.downloadSource);(0,Y.useEffect)(()=>g(e.download.downloadSource),[e.download.downloadSource]);let v=(e,i)=>r.mutate(e,{onSuccess:()=>{n(t(`settings.remote.cf.saved`)),i?.()},onError:e=>n(K(e),`error`)}),y=t=>{g(t),(t!==`custom`||e.download.downloadBaseUrl)&&v({downloadSource:t})},b=()=>a.mutate(void 0,{onSuccess:e=>e.path?p(e.path):n(t(`settings.remote.cf.detectNone`)),onError:e=>n(K(e),`error`)}),S=s.fromEnvironment?t(`settings.remote.cf.fromEnv`):s.installed?s.version?t(`settings.remote.cf.installedProgram`,{version:s.version}):t(`settings.remote.cf.installedUnknown`):s.path?t(`settings.remote.cf.downloaded`,{version:s.version??``}):s.asset?t(`settings.remote.cf.notDownloaded`,{version:s.version??``}):t(`settings.remote.cloudflaredUnsupported`);return(0,X.jsxs)(_,{title:`cloudflared`,footer:t(`settings.remote.cf.footer`),children:[(0,X.jsx)(i,{label:t(`settings.remote.cf.program`),detail:(0,X.jsx)(`span`,{title:s.path??void 0,children:S}),children:(0,X.jsx)(w,{tone:s.path?`green`:s.asset?`neutral`:`red`})}),!e.download.cloudflaredPath&&!s.fromEnvironment&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(i,{label:t(`settings.remote.cf.source`),detail:t(`settings.remote.cf.source.${h}.hint`),children:(0,X.jsx)(q,{className:`w-44`,ariaLabel:t(`settings.remote.cf.source`),value:h,onChange:y,options:gn.map(e=>({value:e,label:t(`settings.remote.cf.source.${e}`)}))})}),h===`custom`&&(0,X.jsxs)(i,{label:t(`settings.remote.cf.baseUrl`),detail:t(`settings.remote.cf.baseUrlHint`),children:[(0,X.jsx)(x,{className:`w-64`,mono:!0,"aria-label":t(`settings.remote.cf.baseUrl`),placeholder:`https://…/cloudflare/cloudflared/releases/download`,value:c,onChange:e=>l(e.target.value)}),(0,X.jsx)(V,{size:`sm`,disabled:!c.trim()||r.isPending||c.trim()===(e.download.downloadBaseUrl??``)&&e.download.downloadSource===`custom`,onClick:()=>v({downloadSource:`custom`,downloadBaseUrl:c.trim()}),children:t(`common.save`)})]})]}),!o.data?.remote&&!s.fromEnvironment&&(0,X.jsx)(i,{label:t(`settings.remote.cf.installed`),detail:e.download.cloudflaredPath?(0,X.jsx)(`span`,{className:`font-mono selectable`,children:e.download.cloudflaredPath}):t(`settings.remote.cf.installedHint`),children:e.download.cloudflaredPath?(0,X.jsx)(V,{size:`sm`,disabled:r.isPending,onClick:()=>v({cloudflaredPath:``}),children:t(`settings.remote.cf.useDownloaded`)}):!u&&(0,X.jsx)(V,{size:`sm`,onClick:()=>{d(!0),b()},children:t(`settings.remote.cf.choose`)})}),u&&!e.download.cloudflaredPath&&(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-2`,children:[(0,X.jsx)(x,{className:`w-72`,mono:!0,autoFocus:!0,"aria-label":t(`settings.remote.cf.installedPath`),placeholder:t(`settings.remote.cf.installedPath`),value:f,onChange:e=>p(e.target.value)}),(0,X.jsx)(V,{size:`sm`,variant:`plain`,loading:a.isPending,onClick:b,children:t(`settings.remote.cf.detect`)}),(0,X.jsx)(V,{size:`sm`,variant:`plain`,onClick:()=>d(!1),children:t(`common.cancel`)}),(0,X.jsx)(V,{size:`sm`,variant:`primary`,disabled:!f.trim(),loading:r.isPending,onClick:()=>v({cloudflaredPath:f.trim()},()=>d(!1)),children:t(`settings.remote.cf.use`)})]})]})}var vn=[`127.0.0.1`,`localhost`,`::1`,`[::1]`],yn={local:`127.0.0.1`,lan:`0.0.0.0`},bn=e=>vn.includes(e)?`local`:`lan`;function xn(){let{t:e}=j(),{toast:t,confirm:n}=J(),r=Ne(),a=pe(),o=I(),s=Te(),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=a.data;if(!f)return(0,X.jsx)(i,{label:e(`settings.listen`),detail:a.isError?K(a.error):void 0,children:a.isPending&&(0,X.jsx)(F,{className:`size-3.5`})});let p=`${f.host}:${f.port}`,m=bn(f.configuredHost),h=f.configuredHost!==f.host,g=!!o.data?.required,_=async n=>{await G.copy(n)&&t(e(`common.copied`))},v=n=>s.mutate(yn[n],{onSuccess:n=>n.configuredHost!==n.host&&t(e(`settings.listen.saved`)),onError:e=>t(K(e),`error`)}),y=async t=>{if(t!==m){if(t===`lan`){if(!f.passwordSet){l(!0);return}if(!await n({title:e(`settings.listen.lanConfirm`),detail:e(`settings.listen.lanDetail`),confirmLabel:e(`settings.listen.lanAction`)}))return}v(t)}},b=async()=>{d(!0);let n=await G.restartService();if(d(!1),n){if(!n.ok){t(n.error??e(`common.error`),`error`);return}t(e(`settings.listen.restarted`)),r.invalidateQueries()}},x=f.hostFromEnvironment?e(`settings.listen.env`,{address:p}):g?e(`settings.listen.localOnly`,{address:p}):h?`${e(`settings.listen.pending`,{host:f.configuredHost})}${je?``:` · ${e(`settings.listen.restartHint`)}`}`:p;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(i,{label:e(`settings.listen`),detail:x,children:!f.hostFromEnvironment&&!g&&(0,X.jsxs)(X.Fragment,{children:[h&&je&&(0,X.jsx)(V,{size:`sm`,loading:u,onClick:()=>void b(),children:e(`settings.listen.restart`)}),(0,X.jsx)(M,{ariaLabel:e(`settings.listen`),value:m,onChange:e=>void y(e),items:[{value:`local`,label:e(`settings.listen.local`)},{value:`lan`,label:e(`settings.listen.lan`)}]})]})}),f.networkUrls.map(t=>(0,X.jsx)(i,{label:e(`settings.listen.networkUrl`),detail:`${t}/v1`,children:(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void _(`${t}/v1`)})},t)),(m===`lan`||f.networkUrls.length>0)&&(0,X.jsx)(hn,{passwordSet:f.passwordSet}),(0,X.jsx)(Sn,{open:c,onOpenChange:l,onSaved:()=>v(`lan`)})]})}function Sn({open:e,onOpenChange:t,onSaved:n}){let{t:r}=j(),{toast:i}=J(),a=W(),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),u=c!==``&&c!==o,d=o.length>=8&&o===c,f=e=>{e||(s(``),l(``)),t(e)},p=()=>{d&&!a.isPending&&a.mutate(o,{onSuccess:()=>{i(r(`settings.remote.passwordSaved`)),f(!1),n()},onError:e=>i(K(e),`error`)})};return(0,X.jsx)(Ge,{open:e,onOpenChange:f,title:r(`settings.listen.passwordTitle`),description:r(`settings.listen.passwordDetail`),width:420,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{onClick:()=>f(!1),children:r(`common.cancel`)}),(0,X.jsx)(V,{variant:`primary`,disabled:!d,loading:a.isPending,onClick:p,children:r(`settings.listen.passwordAction`)})]}),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,X.jsx)(x,{type:`password`,autoComplete:`new-password`,autoFocus:!0,"aria-label":r(`settings.remote.passwordNew`),placeholder:r(`settings.remote.passwordNew`),value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(x,{type:`password`,autoComplete:`new-password`,"aria-label":r(`settings.listen.passwordRepeat`),placeholder:r(`settings.listen.passwordRepeat`),invalid:u,value:c,onChange:e=>l(e.target.value)}),u&&(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:r(`settings.listen.passwordMismatch`)}),(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`settings.listen.lanDetail`)}),(0,X.jsx)(`button`,{type:`submit`,hidden:!0})]})})}var Cn=[`generic`,`feishu`,`dingtalk`,`wecom`,`slack`,`discord`],wn={generic:`https://`,feishu:`https://open.feishu.cn/open-apis/bot/v2/hook/…`,dingtalk:`https://oapi.dingtalk.com/robot/send?access_token=…`,wecom:`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=…`,slack:`https://hooks.slack.com/services/…`,discord:`https://discord.com/api/webhooks/…`},Tn=e=>e===`feishu`||e===`dingtalk`,En=(e,t)=>e(`alerts.event.${t}`),Dn=(e,t)=>e(`alerts.event.${t}.hint`);function On(){return(0,X.jsxs)(`div`,{className:`flex flex-col`,children:[(0,X.jsx)(kn,{}),(0,X.jsx)(An,{}),(0,X.jsx)(Fn,{})]})}function kn(){let{t:e,locale:t}=j(),n=P(!0);return(0,X.jsxs)(_,{title:e(`alerts.firing`),children:[n.isLoading&&(0,X.jsx)(F,{}),n.data?.length===0&&(0,X.jsx)(i,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.firing.empty`)})}),n.data?.map(n=>(0,X.jsx)(i,{icon:(0,X.jsx)(tt,{className:`size-4 text-[var(--danger)]`}),label:`${En(e,n.event)} · ${n.subjectName}`,detail:`${n.ruleName} · ${U(n.changedAt,t)}`},`${n.ruleId}:${n.subjectId}`))]})}function An(){let{t:e}=j(),{toast:t,confirm:n}=J(),r=De(),a=ae(),o=ce(),s=h(),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(null),m=n=>o.mutate(n.id,{onSuccess:n=>n.status===`success`?t(e(`alerts.webhooks.testOk`,{status:n.httpStatus??``}),`success`):t(e(`alerts.webhooks.testFailed`,{error:n.error??n.status}),`error`),onError:e=>t(K(e),`error`)}),g=async r=>{await n({title:e(`alerts.webhooks.resetSecretConfirm`,{name:r.name}),detail:e(`alerts.webhooks.resetSecretDetail`),confirmLabel:e(`alerts.webhooks.resetSecret`),destructive:!0})&&s.mutate(r.id,{onSuccess:e=>p(e.secret??null),onError:e=>t(K(e),`error`)})},v=async r=>{await n({title:e(`alerts.webhooks.deleteConfirm`,{name:r.name}),detail:e(`alerts.webhooks.deleteDetail`),confirmLabel:e(`common.delete`),destructive:!0})&&a.mutate(r.id,{onSuccess:()=>t(e(`alerts.webhooks.deleted`,{name:r.name})),onError:e=>t(K(e),`error`)})};return(0,X.jsxs)(_,{title:e(`alerts.webhooks`),footer:e(`alerts.webhooks.hint`),children:[r.isLoading&&(0,X.jsx)(F,{}),r.data?.length===0&&(0,X.jsx)(i,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.webhooks.empty`)})}),r.data?.map(t=>(0,X.jsxs)(i,{icon:(0,X.jsx)(Ct,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[t.name,!t.enabled&&(0,X.jsx)(T,{tone:`orange`,children:e(`alerts.webhooks.disabledBadge`)}),t.format!==`generic`&&(0,X.jsx)(T,{tone:`accent`,children:e(`alerts.webhooks.format.${t.format}`)}),!t.hasSecret&&(t.format===`generic`||Tn(t.format))&&(0,X.jsx)(T,{children:e(`alerts.webhooks.unsigned`)})]}),detail:(0,X.jsx)(`span`,{className:`font-mono selectable`,children:t.url}),children:[(0,X.jsx)(V,{size:`sm`,icon:(0,X.jsx)(ct,{className:`size-3.5`}),loading:o.isPending&&o.variables===t.id,onClick:()=>m(t),children:e(`alerts.webhooks.test`)}),(0,X.jsx)(We,{label:e(`common.more`),icon:(0,X.jsx)(at,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.webhooks.edit`),icon:(0,X.jsx)(gt,{className:`size-3.5`}),onSelect:()=>l(t)},{id:`deliveries`,label:e(`alerts.webhooks.deliveries`),icon:(0,X.jsx)(ft,{className:`size-3.5`}),onSelect:()=>d(t)},{id:`secret`,label:e(`alerts.webhooks.resetSecret`),icon:(0,X.jsx)(dt,{className:`size-3.5`}),onSelect:()=>void g(t)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(xt,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void v(t)}]})]},t.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(V,{size:`sm`,icon:(0,X.jsx)(_t,{className:`size-3.5`}),onClick:()=>l(`new`),children:e(`alerts.webhooks.add`)})}),(0,X.jsx)(jn,{hook:c,onClose:()=>l(null),onSecret:p}),(0,X.jsx)(Nn,{hook:u,onClose:()=>d(null)}),(0,X.jsx)(Mn,{secret:f,onClose:()=>p(null)})]})}function jn({hook:e,onClose:t,onSecret:n}){let{t:r}=j(),{toast:a}=J(),o=ne(),s=v(),[c,l]=(0,Y.useState)(``),[d,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)(10),[g,_]=(0,Y.useState)(!0),[y,b]=(0,Y.useState)(!0),[S,C]=(0,Y.useState)(!0),[w,T]=(0,Y.useState)(`generic`),[E,D]=(0,Y.useState)(``),[O,k]=(0,Y.useState)([]),A=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e;l(t?.name??``),p(t?.url??``),h(t?.timeoutSec??10),_(t?.useProxy??!0),b(t?.enabled??!0),C(!t||t.hasSecret),T(t?.format??`generic`),D(``),k((t?.headerNames??[]).map(e=>({name:e,value:``,stored:!0})))},[e]),(0,X.jsx)(Ge,{open:e!==null,onOpenChange:e=>!e&&t(),title:r(A?`alerts.webhooks.add`:`alerts.webhooks.edit`),width:540,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{onClick:t,children:r(`common.cancel`)}),(0,X.jsx)(V,{variant:`primary`,disabled:!c.trim()||!d.trim(),loading:o.isPending||s.isPending,onClick:()=>{let i=Object.fromEntries(O.filter(e=>e.name.trim()).map(e=>[e.name.trim(),e.value])),l={name:c.trim(),url:d.trim(),timeoutSec:m??10,useProxy:g,enabled:y,headers:Object.keys(i).length>0?i:null},u={onError:e=>a(K(e),`error`)},f=!A&&e!==null&&e.format!==w,p=Tn(w)?S?E.trim()||void 0:``:void 0;A?o.mutate({...l,format:w,...w===`generic`?{signed:S}:p?{secret:p}:{}},{...u,onSuccess:e=>{t(),e.secret&&n(e.secret)}}):e&&s.mutate({id:e.id,...l,...f?{format:w}:{},...w===`generic`?S||!e.hasSecret||f?{}:{signed:!1}:p===void 0?{}:{secret:p}},{...u,onSuccess:()=>{t(),a(r(`common.saved`),`success`)}})},children:r(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(u,{label:r(`alerts.webhooks.name`),children:(0,X.jsx)(x,{value:c,maxLength:64,onChange:e=>l(e.target.value)})}),(0,X.jsx)(u,{label:r(`alerts.webhooks.format`),hint:r(`alerts.webhooks.format.${w}.hint`),children:(0,X.jsx)(q,{ariaLabel:r(`alerts.webhooks.format`),value:w,onChange:t=>{T(t),C(t===`generic`||e!==`new`&&e!==null&&e.format===t&&e.hasSecret||Tn(t))},options:Cn.map(e=>({value:e,label:r(`alerts.webhooks.format.${e}`)}))})}),(0,X.jsx)(u,{label:r(`alerts.webhooks.url`),children:(0,X.jsx)(x,{mono:!0,value:d,placeholder:wn[w],onChange:e=>p(e.target.value)})}),Tn(w)&&S&&(0,X.jsx)(u,{label:r(`alerts.webhooks.botSecret`),hint:r(`alerts.webhooks.botSecretHint`),children:(0,X.jsx)(x,{mono:!0,type:`password`,autoComplete:`off`,value:E,placeholder:e!==`new`&&e!==null&&e.format===w&&e.hasSecret?r(`alerts.webhooks.headerKept`):`SEC…`,onChange:e=>D(e.target.value)})}),(0,X.jsx)(u,{label:r(`alerts.webhooks.timeout`),children:(0,X.jsx)(Ve,{value:m,min:1,step:1,label:r(`alerts.webhooks.timeout`),onChange:h})}),(0,X.jsx)(u,{label:r(`alerts.webhooks.headers`),hint:r(`alerts.webhooks.headersHint`),children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[O.map((e,t)=>(0,X.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto] items-center gap-2`,children:[(0,X.jsx)(x,{mono:!0,"aria-label":r(`alerts.webhooks.headerName`),placeholder:r(`alerts.webhooks.headerName`),value:e.name,onChange:e=>k(O.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,X.jsx)(x,{mono:!0,"aria-label":r(`alerts.webhooks.headerValue`),placeholder:e.stored?r(`alerts.webhooks.headerKept`):r(`alerts.webhooks.headerValue`),value:e.value,onChange:e=>k(O.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(xt,{className:`size-3.5`}),"aria-label":r(`common.delete`),onClick:()=>k(O.filter((e,n)=>n!==t))})]},t)),(0,X.jsx)(`div`,{children:(0,X.jsx)(V,{size:`sm`,icon:(0,X.jsx)(_t,{className:`size-3.5`}),onClick:()=>k([...O,{name:``,value:``,stored:!1}]),children:r(`alerts.webhooks.addHeader`)})})]})}),(0,X.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[(0,X.jsx)(i,{label:r(`alerts.webhooks.enabled`),children:(0,X.jsx)(f,{checked:y,label:r(`alerts.webhooks.enabled`),onChange:b})}),(0,X.jsx)(i,{label:r(`alerts.webhooks.useProxy`),detail:r(`alerts.webhooks.useProxyHint`),children:(0,X.jsx)(f,{checked:g,label:r(`alerts.webhooks.useProxy`),onChange:_})}),(w===`generic`?A||e!==null&&e.format===`generic`&&e.hasSecret:Tn(w))&&(0,X.jsx)(i,{label:r(`alerts.webhooks.signed`),detail:r(w===`generic`?`alerts.webhooks.signedHint`:`alerts.webhooks.botSignedHint`),children:(0,X.jsx)(f,{checked:S,label:r(`alerts.webhooks.signed`),onChange:C})})]})]})})}function Mn({secret:e,onClose:t}){let{t:n}=j(),{toast:r}=J();return(0,X.jsx)(Ge,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`alerts.webhooks.secretTitle`),description:n(`alerts.webhooks.secretShown`),footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{onClick:async()=>e&&await G.copy(e)&&r(n(`common.copied`)),children:n(`common.copy`)}),(0,X.jsx)(V,{variant:`primary`,onClick:t,children:n(`common.done`)})]}),children:(0,X.jsx)(`code`,{className:`block rounded-[var(--radius-control)] bg-[var(--surface-muted)] p-3 font-mono text-[12px] break-all selectable`,children:e})})}function Nn({hook:e,onClose:t}){let{t:r,locale:i}=j(),{toast:a}=J(),o=b(e?.id),s=te(),c={success:`green`,pending:`orange`,failed:`red`};return(0,X.jsxs)(Ge,{open:e!==null,onOpenChange:e=>!e&&t(),title:`${r(`alerts.webhooks.deliveries`)} · ${e?.name??``}`,width:640,children:[o.isLoading&&(0,X.jsx)(F,{lines:4}),o.data?.length===0&&(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`alerts.delivery.empty`)}),(0,X.jsx)(`div`,{className:`grid max-h-[60vh] gap-2 overflow-y-auto`,children:o.data?.map(e=>(0,X.jsxs)(`details`,{className:`rounded-[var(--radius-control)] bg-[var(--surface-muted)] px-3 py-2 text-[12px]`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-default flex-wrap items-center gap-2`,children:[(0,X.jsx)(T,{tone:c[e.status],children:r(`alerts.delivery.status.${e.status}`)}),(0,X.jsx)(`span`,{children:e.event===`test`?r(`alerts.webhooks.test`):En(r,e.event)}),(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:U(e.createdAt,i)}),(0,X.jsxs)(`span`,{className:`text-[var(--text-muted)]`,children:[e.httpStatus?`HTTP ${e.httpStatus}`:``,` `,e.error&&e.status!==`success`?e.error:``]}),(0,X.jsx)(`span`,{className:`ml-auto text-[var(--text-muted)]`,children:e.status===`pending`&&e.nextAttemptAt?r(`alerts.delivery.next`,{time:U(e.nextAttemptAt,i)}):r(`alerts.delivery.attempts`,{count:e.attempts})})]}),(0,X.jsxs)(`div`,{className:`mt-2 grid gap-2`,children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:r(`alerts.delivery.payload`)}),(0,X.jsx)(n,{children:JSON.stringify(e.payload,null,2)}),e.responseSnippet&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:r(`alerts.delivery.response`)}),(0,X.jsx)(n,{language:`text`,children:e.responseSnippet})]}),e.status!==`pending`&&(0,X.jsx)(`div`,{children:(0,X.jsx)(V,{size:`sm`,loading:s.isPending&&s.variables===e.id,onClick:()=>s.mutate(e.id,{onSuccess:()=>a(r(`alerts.delivery.redelivered`)),onError:e=>a(K(e),`error`)}),children:r(`alerts.delivery.redeliver`)})})]})]},e.id))})]})}function Pn(e){let t=Be(),n=Pe(),r=(0,Y.useMemo)(()=>(t.data??[]).filter(e=>e.authScheme===`oauth-subscription`),[t.data]),i=Je({queries:r.map(t=>({queryKey:ze.providerAccounts(t.id),queryFn:()=>ue(`GET`,`/api/providers/${A(t.id)}/accounts`),enabled:e===`account`}))});return e===`provider`?(t.data??[]).filter(e=>e.authScheme!==`oauth-subscription`&&e.authScheme!==`plugin`).map(e=>({value:e.id,label:e.name})):e===`token`?(n.data??[]).map(e=>({value:e.id,label:e.name})):e===`account`?r.flatMap((e,t)=>(i[t]?.data??[]).map(t=>({value:t.id,label:`${e.name} / ${t.displayName||t.id}`}))):[]}function Fn(){let{t:e}=j(),{toast:t,confirm:n}=J(),r=a(),o=De(),c=me(),l=s(),[u,d]=(0,Y.useState)(null),p=e=>o.data?.find(t=>t.id===e)?.name??e,m=async r=>{await n({title:e(`alerts.rules.deleteConfirm`,{name:r.name}),confirmLabel:e(`common.delete`),destructive:!0})&&l.mutate(r.id,{onSuccess:()=>t(e(`alerts.rules.deleted`,{name:r.name})),onError:e=>t(K(e),`error`)})};return(0,X.jsxs)(_,{title:e(`alerts.rules`),footer:e(`alerts.rules.hint`),children:[r.isLoading&&(0,X.jsx)(F,{}),r.data?.length===0&&(0,X.jsx)(i,{label:(0,X.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:e(`alerts.rules.empty`)})}),r.data?.map(n=>(0,X.jsxs)(i,{icon:(0,X.jsx)(tt,{className:`size-4 text-[var(--text-muted)]`}),label:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[n.name,n.firing>0&&(0,X.jsx)(T,{tone:`red`,children:e(`alerts.rules.firing`,{count:n.firing})}),!n.enabled&&(0,X.jsx)(T,{tone:`orange`,children:e(`alerts.rules.disabledBadge`)})]}),detail:`${En(e,n.event)} → ${n.webhookIds.map(p).join(`, `)||`—`}`,children:[(0,X.jsx)(f,{checked:n.enabled,label:e(`alerts.rules.enabled`),onChange:e=>c.mutate({id:n.id,enabled:e},{onError:e=>t(K(e),`error`)})}),(0,X.jsx)(We,{label:e(`common.more`),icon:(0,X.jsx)(at,{className:`size-4`}),items:[{id:`edit`,label:e(`alerts.rules.edit`),icon:(0,X.jsx)(gt,{className:`size-3.5`}),onSelect:()=>d(n)},{id:`delete`,label:e(`common.delete`),icon:(0,X.jsx)(xt,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void m(n)}]})]},n.id)),(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(V,{size:`sm`,icon:(0,X.jsx)(_t,{className:`size-3.5`}),onClick:()=>d(`new`),children:e(`alerts.rules.add`)})}),(0,X.jsx)(Ln,{rule:u,onClose:()=>d(null)})]})}function In(e){let t={};for(let n of e?.params??[])t[n.name]=n.kind===`choice`?n.choices?.[0]??``:n.kind===`number`?n.default??null:``;return t}function Ln({rule:e,onClose:t}){let{t:n}=j(),{toast:r}=J(),a=Ue(),o=De(),s=R(),c=me(),[l,d]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)({}),[_,v]=(0,Y.useState)(`all`),[y,b]=(0,Y.useState)([]),[S,C]=(0,Y.useState)([]),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(60),A=a.data?.find(e=>e.id===p),ee=Pn(A?.subjectType),te=e===`new`;return(0,Y.useEffect)(()=>{if(e===null)return;let t=e===`new`?null:e,n=a.data?.[0];d(t?.name??``),m(t?.event??n?.id??``),g(t?{...In(a.data?.find(e=>e.id===t.event)),...t.condition}:In(n)),v(t?.subjects?`only`:`all`),b(t?.subjects??[]),C(t?.webhookIds??(o.data??[]).map(e=>e.id)),T(t?.notifyResolved??!1),D(t?.repeatMinutes??null),k(t?.cooldownMinutes??60)},[e]),(0,X.jsx)(Ge,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(te?`alerts.rules.add`:`alerts.rules.edit`),width:560,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{onClick:t,children:n(`common.cancel`)}),(0,X.jsx)(V,{variant:`primary`,disabled:!l.trim()||!p,loading:s.isPending||c.isPending,onClick:()=>{let i=Object.fromEntries(Object.entries(h).filter(([,e])=>e!==null&&e!==``)),a={name:l.trim(),event:p,condition:i,subjects:_===`all`?null:y,webhookIds:S,notifyResolved:w,repeatMinutes:E&&E>0?Math.floor(E):null,cooldownMinutes:Math.max(0,Math.floor(O??0))},o={onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(K(e),`error`)};te?s.mutate(a,o):e&&c.mutate({id:e.id,...a},o)},children:n(`common.save`)})]}),children:(0,X.jsxs)(`div`,{className:`grid gap-4`,children:[(0,X.jsx)(u,{label:n(`alerts.rules.name`),children:(0,X.jsx)(x,{value:l,maxLength:64,onChange:e=>d(e.target.value)})}),(0,X.jsx)(u,{label:n(`alerts.rules.event`),hint:p?Dn(n,p):void 0,children:(0,X.jsx)(q,{ariaLabel:n(`alerts.rules.event`),value:p,onChange:e=>{m(e),g(In(a.data?.find(t=>t.id===e))),b([])},options:(a.data??[]).map(e=>({value:e.id,label:En(n,e.id)}))})}),A?.params.map(e=>(0,X.jsx)(u,{label:n(`alerts.param.${e.name}`),children:e.kind===`number`?(0,X.jsx)(Ve,{value:typeof h[e.name]==`number`?h[e.name]:null,min:0,label:n(`alerts.param.${e.name}`),onChange:t=>g({...h,[e.name]:t})}):e.kind===`choice`?(0,X.jsx)(q,{ariaLabel:n(`alerts.param.${e.name}`),value:String(h[e.name]??``),onChange:t=>g({...h,[e.name]:t}),options:(e.choices??[]).map(t=>({value:t,label:n(`alerts.choice.${e.name}.${t}`)}))}):(0,X.jsx)(x,{mono:!0,value:String(h[e.name]??``),"aria-label":n(`alerts.param.${e.name}`),placeholder:n(`alerts.param.${e.name}.placeholder`),onChange:t=>g({...h,[e.name]:t.target.value})})},e.name)),A&&(0,X.jsx)(u,{label:`${n(`alerts.rules.subjects`)} · ${n(`alerts.subject.${A.subjectType}`)}`,children:(0,X.jsxs)(`div`,{className:`grid gap-2`,children:[(0,X.jsx)(M,{ariaLabel:n(`alerts.rules.subjects`),value:_,onChange:v,items:[{value:`all`,label:n(`alerts.rules.subjectsAll`)},{value:`only`,label:n(`alerts.rules.subjectsOnly`)}]}),_===`only`&&(0,X.jsx)(It,{label:n(`alerts.rules.subjects`),value:y,onValueChange:b,options:[...ee,...y.filter(e=>!ee.some(t=>t.value===e)).map(e=>({value:e,label:e}))]})]})}),(0,X.jsx)(u,{label:n(`alerts.rules.webhooks`),children:(o.data??[]).length===0?(0,X.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`alerts.rules.noWebhooks`)}):(0,X.jsx)(It,{label:n(`alerts.rules.webhooks`),value:S,onValueChange:C,options:(o.data??[]).map(e=>({value:e.id,label:e.name}))})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,X.jsx)(u,{label:n(`alerts.rules.repeat`),hint:n(`alerts.rules.repeatHint`),children:(0,X.jsx)(Ve,{value:E,min:1,step:1,label:n(`alerts.rules.repeat`),onChange:D})}),(0,X.jsx)(u,{label:n(`alerts.rules.cooldown`),hint:n(`alerts.rules.cooldownHint`),children:(0,X.jsx)(Ve,{value:O,min:0,step:1,label:n(`alerts.rules.cooldown`),onChange:k})})]}),(0,X.jsx)(`div`,{className:`card`,children:(0,X.jsx)(i,{label:n(`alerts.rules.notifyResolved`),children:(0,X.jsx)(f,{checked:w,label:n(`alerts.rules.notifyResolved`),onChange:T})})})]})})}function Rn(){let{t:e}=j(),t=L(),n=Ce()?.loginItem,r=t.data?.mechanism===`launchd`||!!n&&be;return(0,X.jsxs)(_,{title:e(`settings.startup`),footer:r?e(`settings.startup.macFooter`):void 0,children:[n&&(0,X.jsx)(zn,{loginItem:n}),(0,X.jsx)(Bn,{})]})}function zn({loginItem:e}){let{t}=j(),{toast:n}=J(),[r,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let t=!0;e.get().then(e=>{t&&a(e)});let n=e.onChanged(a);return()=>{t=!1,n()}},[e]),(0,X.jsx)(i,{label:t(`settings.startup.app`),detail:r&&!r.supported?t(`settings.startup.appUnsupported`):t(`settings.startup.appHint`),children:r?(0,X.jsx)(f,{checked:r.enabled,disabled:!r.supported||o,label:t(`settings.startup.app`),onChange:r=>{s(!0),e.set(r).then(e=>{a(e),e.enabled!==r&&n(t(`settings.startup.failed`),`error`)}).catch(e=>n(K(e),`error`)).finally(()=>s(!1))}}):(0,X.jsx)(F,{className:`size-3.5`})})}function Bn(){let{t:e}=j(),{toast:t}=J(),n=L(),r=B(),a=n.data;if(!a)return(0,X.jsx)(i,{label:e(`settings.startup.service`),detail:n.isError?K(n.error):void 0,children:n.isPending&&(0,X.jsx)(F,{className:`size-3.5`})});let o=!a.supported||a.mechanism===`none`?e(`settings.startup.unsupported.${a.unsupported??`platform`}`):a.canChange?a.enabled&&a.location?e(`settings.startup.entry`,{location:a.location}):e(`settings.startup.service.${a.mechanism}`):e(`settings.startup.localOnly`);return(0,X.jsx)(i,{label:e(`settings.startup.service`),detail:o,children:a.supported&&(0,X.jsx)(f,{checked:a.enabled,disabled:!a.canChange||r.isPending,label:e(`settings.startup.service`),onChange:n=>r.mutate(n,{onSuccess:n=>n.enabled&&t(e(`settings.startup.saved`)),onError:e=>t(K(e),`error`)})})})}function Vn(){let{t:e}=j(),{toast:t}=J(),n=Ne(),a=c(),o=Re(),s=r(),l=ke(),u=s.data,d=o.data?.updateChannel??u?.channel,p=Ce()?.updates??null,[m,h]=(0,Y.useState)(!1),g=se(),_=!p&&u?.containerUpdater===!0,v=()=>g.mutate(void 0,{onSuccess:n=>n.applyError?t(e(`settings.updateContainerFailed`,{error:n.applyError}),`error`):t(e(`settings.updateContainerRequested`)),onError:e=>t(K(e),`error`)}),y=()=>l.mutate(void 0,{onSuccess:n=>n.error?t(e(`settings.updateCheckFailed`,{error:n.error}),`error`):t(n.available?e(`settings.updateAvailable`,{version:n.available}):e(`settings.upToDate`)),onError:e=>t(K(e),`error`)}),b=()=>{p&&!m&&(h(!0),p.apply().then(r=>{r===`server`?(t(e(`settings.updateApplied`)),n.invalidateQueries({queryKey:ze.version}),n.invalidateQueries({queryKey:ze.update})):t(e(r===`desktop`?`settings.updateDesktopRelaunch`:r===`download`?`settings.updateDownloadOpened`:r===`downloading`?`settings.updateDownloading`:`settings.upToDate`))}).catch(e=>t(K(e),`error`)).finally(()=>h(!1)))},x=u?.lastCheckAt?new Date(u.lastCheckAt).toLocaleString():void 0,S=_&&u?.available&&u.applyVersion===u.available&&u.applyRequestedAt?u.applyError?e(`settings.updateContainerFailed`,{error:u.applyError}):e(`settings.updateContainerPending`,{version:u.available,time:new Date(u.applyRequestedAt).toLocaleString()}):void 0,C=u?.available?S??(p?e(`settings.updateAvailable`,{version:u.available}):`${e(`settings.updateAvailable`,{version:u.available})} ${e(_?`settings.updateContainerHint`:`settings.updateApplyHint`)}`):void 0;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(i,{label:e(`settings.autoCheck`),detail:u&&!u.feedConfigured?e(`settings.updateCheckFailed`,{error:`feed-not-configured`}):void 0,children:(0,X.jsx)(f,{checked:u?.autoCheck??!0,label:e(`settings.autoCheck`),onChange:e=>a.mutate({updateAutoCheck:e},{onError:e=>t(K(e),`error`)})})}),_&&(0,X.jsx)(i,{label:e(`settings.autoApply`),detail:e(`settings.autoApplyHint`),children:(0,X.jsx)(f,{checked:u?.autoApply??!0,label:e(`settings.autoApply`),disabled:a.isPending,onChange:e=>a.mutate({updateAutoApply:e},{onSuccess:()=>void n.invalidateQueries({queryKey:ze.update}),onError:e=>t(K(e),`error`)})})}),(0,X.jsx)(i,{label:e(`settings.previewUpdates`),detail:e(`settings.previewUpdatesHint`),children:(0,X.jsx)(f,{checked:d===`preview`,label:e(`settings.previewUpdates`),disabled:!d||a.isPending,onChange:e=>a.mutate({updateChannel:e?`preview`:`stable`},{onSuccess:y,onError:e=>t(K(e),`error`)})})}),(0,X.jsxs)(i,{label:e(`settings.checkUpdates`),detail:l.isError?e(`settings.updateCheckFailed`,{error:K(l.error)}):u?.available?C:x?e(`settings.lastChecked`,{time:x}):void 0,children:[(0,X.jsx)(V,{size:`sm`,variant:`plain`,disabled:l.isPending,onClick:y,children:l.isPending?(0,X.jsx)(F,{className:`size-3.5`}):(0,X.jsx)(vt,{className:`size-3.5`})}),p&&u?.available&&(0,X.jsx)(V,{size:`sm`,variant:`plain`,disabled:m,"aria-label":e(`settings.updateApply`),onClick:b,children:m?(0,X.jsx)(F,{className:`size-3.5`}):(0,X.jsx)(Tt,{className:`size-3.5`})}),_&&u?.available&&(0,X.jsx)(V,{size:`sm`,variant:`plain`,disabled:g.isPending,"aria-label":e(`settings.updateApply`),onClick:v,children:g.isPending?(0,X.jsx)(F,{className:`size-3.5`}):(0,X.jsx)(Tt,{className:`size-3.5`})})]})]})}var Hn=[1,2,3,4,5,6,0],Un=/^([01]\d|2[0-3]):[0-5]\d$/;function Wn(){let{t:e}=j(),{toast:t}=J(),n=oe(),r=d(),[a,o]=(0,Y.useState)(``),s=n.data;if(!s)return n.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:K(n.error)}):(0,X.jsx)(F,{className:`mx-auto my-8`});let c=n=>r.mutate(n,{onSuccess:()=>t(e(`warmup.saved`),`success`),onError:e=>t(K(e),`error`)}),l=()=>{Un.test(a)&&!s.times.includes(a)&&(c({times:[...s.times,a].sort()}),o(``))},u=e=>c({weekdays:s.weekdays.includes(e)?s.weekdays.filter(t=>t!==e):[...s.weekdays,e].sort()});return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(_,{title:e(`warmup.title`),footer:e(`warmup.hint`),children:[(0,X.jsx)(i,{label:e(`warmup.enabled`),icon:(0,X.jsx)(st,{className:`size-4`}),children:(0,X.jsx)(f,{checked:s.enabled,disabled:r.isPending,label:e(`warmup.enabled`),onChange:e=>c({enabled:e})})}),(0,X.jsx)(i,{label:e(`warmup.mode`),children:(0,X.jsx)(M,{ariaLabel:e(`warmup.mode`),value:s.mode,onChange:e=>c({mode:e}),items:[{value:`daily`,label:e(`warmup.mode.daily`)},{value:`auto`,label:e(`warmup.mode.auto`)}]})}),s.mode===`daily`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(i,{label:e(`warmup.times`),detail:e(`warmup.zone`,{zone:s.timeZone}),children:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[s.times.map(t=>(0,X.jsx)(T,{tone:`neutral`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-mono`,children:[t,(0,X.jsx)(`button`,{type:`button`,"aria-label":e(`warmup.removeTime`,{time:t}),onClick:()=>c({times:s.times.filter(e=>e!==t)}),children:(0,X.jsx)(wt,{className:`size-3`})})]})},t)),(0,X.jsx)(x,{mono:!0,className:`w-20`,placeholder:`06:00`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&l()}),(0,X.jsx)(V,{size:`sm`,icon:(0,X.jsx)(_t,{className:`size-3.5`}),disabled:!Un.test(a),onClick:l,children:e(`warmup.addTime`)})]})}),(0,X.jsx)(i,{label:e(`warmup.weekdays`),detail:s.weekdays.length===0?e(`warmup.everyDay`):void 0,children:(0,X.jsx)(`div`,{role:`group`,"aria-label":e(`warmup.weekdays`),className:`flex gap-1`,children:Hn.map(t=>(0,X.jsx)(`button`,{type:`button`,"aria-pressed":s.weekdays.length===0||s.weekdays.includes(t),onClick:()=>u(t),className:`rounded-full px-2.5 py-0.5 text-[11.5px] ${s.weekdays.length===0||s.weekdays.includes(t)?`bg-[var(--fill)] text-[var(--text)]`:`text-[var(--text-muted)]`}`,children:e(`warmup.day.${t}`)},t))})})]}),(0,X.jsx)(i,{label:e(`warmup.claude`),children:(0,X.jsx)(f,{checked:s.claude,disabled:r.isPending,label:e(`warmup.claude`),onChange:e=>c({claude:e})})}),(0,X.jsx)(i,{label:e(`warmup.codex`),children:(0,X.jsx)(f,{checked:s.codex,disabled:r.isPending,label:e(`warmup.codex`),onChange:e=>c({codex:e})})})]}),(0,X.jsx)(Gn,{})]})}function Gn(){let{t:e,locale:t}=j(),{toast:n}=J(),r=N(),a=S(),o=g(),s=r.data??[],c=(e,t)=>a.mutate({id:e.accountId,...t},{onError:e=>n(K(e),`error`)}),l=t=>o.mutate(t.accountId,{onSuccess:r=>n(e(`warmup.ran`,{name:t.accountName,result:e(`warmup.result.${r.result}`)})+(r.message?` — ${r.message}`:``),r.result===`ok`?`success`:`error`),onError:e=>n(K(e),`error`)});return(0,X.jsxs)(_,{title:e(`warmup.accounts`),children:[s.length===0&&(0,X.jsx)(`div`,{className:`px-4 py-3 text-[12px] text-[var(--text-muted)]`,children:e(`warmup.accounts.empty`)}),s.map(n=>(0,X.jsxs)(i,{label:`${n.providerName} · ${n.accountName}`,detail:(0,X.jsxs)(`span`,{className:`block whitespace-normal`,children:[n.lastAt&&n.lastResult?e(`warmup.last`,{result:e(`warmup.result.${n.lastResult}`),when:U(n.lastAt,t)}):null,n.lastMessage?` — ${n.lastMessage}`:``,n.nextAt?` ${e(`warmup.next`,{when:U(n.nextAt,t)})}`:``,n.warmed?``:` ${e(`warmup.notWarmed`)}`]}),children:[(0,X.jsx)(M,{ariaLabel:e(`warmup.mode`),value:n.mode,onChange:e=>c(n,{mode:e}),items:[{value:`inherit`,label:e(`warmup.mode.inherit`)},{value:`daily`,label:e(`warmup.mode.daily`)},{value:`auto`,label:e(`warmup.mode.auto`)},{value:`off`,label:e(`warmup.mode.off`)}]}),(0,X.jsx)(V,{size:`sm`,icon:(0,X.jsx)(st,{className:`size-3.5`}),disabled:o.isPending,onClick:()=>l(n),children:e(`warmup.runNow`)})]},n.accountId))]})}var Z={field:`_field_bhhp1_1`,head:`_head_bhhp1_6`,label:`_label_bhhp1_7`,limit:`_limit_bhhp1_9`,control:`_control_bhhp1_14`,step:`_step_bhhp1_22`,icon:`_icon_bhhp1_23`,valueWrap:`_valueWrap_bhhp1_34`,value:`_value_bhhp1_34`,affix:`_affix_bhhp1_38`,char:`_char_bhhp1_39`,number:`_number_bhhp1_42`,display:`_display_bhhp1_43`,mirror:`_mirror_bhhp1_45`,input:`_input_bhhp1_46`,column:`_column_bhhp1_52`,sizer:`_sizer_bhhp1_53`,glyph:`_glyph_bhhp1_54`,symbol:`_symbol_bhhp1_55`,messageSlot:`_messageSlot_bhhp1_57`,hint:`_hint_bhhp1_58`,words:`_words_bhhp1_60`,wordSlot:`_wordSlot_bhhp1_61`,wordSizer:`_wordSizer_bhhp1_62`,word:`_word_bhhp1_60`,srOnly:`_srOnly_bhhp1_64`},{spring:Q,duration:$,blur:Kn}=O,qn=[...O.ease.enter],Jn=[...O.ease.standard],Yn=[0,1,2,3,4,5,6,7,8,9],Xn=6,Zn=400,Qn=40,$n=240,er=1500,tr=700,nr=700,rr=.22,ir=4,ar=130,or=(()=>{let e=2*Math.PI/(Q.morph.visualDuration*1.2);return{type:`spring`,stiffness:e*e,damping:2*(1-Q.morph.bounce)*e}})(),sr=e=>(String(e).split(`.`)[1]??``).length,cr=e=>e.replace(/[.*+?^${}()|[\]\\-]/g,`\\$&`),lr=(e,t)=>typeof e==`function`?e(t):e??``,ur=(e,t=10)=>Math.sign(e)*(1-1/(Math.abs(e)*.55/t+1))*t;function dr(e,t){let n=t.formatToParts(e),r=n.reduce((e,t)=>e+(t.type===`integer`?t.value.length:0),0),i=0;return n.flatMap((e,t)=>e.type===`integer`?[...e.value].map(e=>({key:`i${--r}`,digit:Number(e)})):e.type===`fraction`?[...e.value].map(e=>({key:`f${i++}`,digit:Number(e)})):[{key:e.type===`group`?`g${r}`:e.type===`decimal`?`d`:e.type===`minusSign`?`m`:`${e.type}${t}`,text:e.value}])}var fr={enter:e=>({width:0,scale:.6,opacity:0,y:`${e*.3}em`,filter:`blur(${Kn.soft}px)`}),center:{width:`auto`,scale:1,opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{width:Q.morph,scale:Q.morph,opacity:Q.morph,y:Q.snappy,filter:{duration:.3,ease:Jn}}},exit:e=>({width:0,scale:.6,opacity:0,y:`${e*-.3}em`,filter:`blur(${Kn.subtle}px)`,transition:{width:Q.smooth,scale:Q.smooth,y:{duration:$.fast,ease:Jn},opacity:{duration:$.instant},filter:{duration:$.instant}}})},pr=e=>({width:`auto`,scale:1,opacity:e,y:0,filter:`none`}),mr={enter:pr(0),center:{...pr(1),transition:{duration:$.instant}},exit:{width:0,opacity:0,transition:{duration:0}}},hr={enter:pr(1),center:{...pr(1),transition:{duration:0}},exit:{width:0,opacity:0,transition:{duration:0}}};function gr({position:e,digit:t}){let n=e=>((t-e)%10+15)%10-5,r=$e(e,e=>`${n(e)*1.05}em`),i=$e(e,e=>Math.max(0,1-Math.abs(n(e))**1.5*1.1)),a=$e(e,e=>Math.abs(n(e))>=1?`hidden`:`visible`),o=$e(e,e=>{let t=Math.abs(n(e));return t<.02||t>=1?`none`:`blur(${(t*Kn.soft*.75).toFixed(2)}px)`});return(0,X.jsx)(H.span,{className:Z.glyph,style:{y:r,opacity:i,filter:o,visibility:a},children:t})}function _r({digit:e,direction:t,instant:n}){let r=he(),i=ve(e),a=(0,Y.useRef)({digit:e,target:e});return(0,Y.useLayoutEffect)(()=>{let o=a.current;if(o.digit===e)return;let s=t>0?(e-o.digit+10)%10:-((o.digit-e+10)%10);Math.abs(s)>5&&(s-=Math.sign(s)*10),o.target+=s,o.digit=e,n||r?i.jump(o.target):Le(i,o.target,Q.snappy)},[e,t,n,i,r]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.sizer,children:`0`}),Yn.map(e=>(0,X.jsx)(gr,{position:i,digit:e},e))]})}function vr({value:e,format:t,direction:n,instant:r}){let i=he(),a=r?hr:i?mr:fr;return(0,X.jsx)(xe,{initial:!1,custom:n,children:dr(e,t).map(e=>(0,X.jsx)(H.span,{className:`digit`in e?Z.column:Z.symbol,custom:n,variants:a,initial:`enter`,animate:`center`,exit:`exit`,children:`digit`in e?(0,X.jsx)(_r,{digit:e.digit,direction:n,instant:r}):e.text},e.key))})}function yr({text:e,direction:t,className:n}){let r=he();return(0,X.jsx)(`span`,{className:n,children:(0,X.jsx)(xe,{initial:!1,custom:t,children:[...e].map((e,n)=>(0,X.jsx)(H.span,{className:Z.char,custom:t,variants:r?mr:fr,initial:`enter`,animate:`center`,exit:`exit`,children:e},`${n}:${e}`))})})}var br=e=>{let t=e?.replace(/[^\d.-]/g,``);return t&&/\d/.test(t)&&Number.isFinite(Number(t))?Number(t):null},xr=(e,t)=>{let n=e.split(` `);return t.split(` `).map((e,t)=>{let r=br(n[t]),i=br(e);return r!==null&&i!==null&&i<r?-1:1})},Sr={enter:e=>({opacity:0,y:`${e*.3}em`,filter:`blur(${Kn.soft}px)`}),center:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`},transition:{duration:.22,ease:qn,opacity:Q.morph}},exit:e=>({opacity:0,y:`${e*-.3}em`,filter:`blur(${Kn.subtle}px)`,transition:{duration:.14,ease:Jn}})},Cr={enter:{opacity:0,y:0,filter:`none`},center:{opacity:1,y:0,filter:`none`,transition:{duration:$.instant}},exit:{opacity:0,transition:{duration:0}}};function wr({word:e,direction:t}){let n=he(),r=(0,Y.useRef)(null),i=ve(`auto`),a=(0,Y.useRef)(!1);return(0,Y.useLayoutEffect)(()=>{let e=r.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{!a.current||n?i.jump(e.offsetWidth):Le(i,e.offsetWidth,Q.morph),a.current=!0});return t.observe(e),()=>t.disconnect()},[n,i]),(0,X.jsxs)(H.span,{className:Z.wordSlot,style:{width:i},children:[(0,X.jsx)(`span`,{ref:r,className:Z.wordSizer,children:e}),(0,X.jsx)(xe,{initial:!1,mode:`popLayout`,custom:t,children:(0,X.jsx)(H.span,{className:Z.word,custom:t,variants:n?Cr:Sr,initial:`enter`,animate:`center`,exit:`exit`,children:e},e)})]})}function Tr({text:e}){let[t,n]=(0,Y.useState)({text:e,directions:[]});t.text!==e&&n({text:e,directions:xr(t.text,e)});let r=t.text===e?t.directions:xr(t.text,e),i=e.split(` `);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:Z.srOnly,children:e}),(0,X.jsx)(`span`,{className:Z.words,"aria-hidden":`true`,children:i.map((e,t)=>(0,X.jsxs)(Y.Fragment,{children:[t>0&&` `,(0,X.jsx)(wr,{word:e,direction:r[t]??1})]},t))})]})}function Er({id:e,text:t,className:n}){return(0,X.jsx)(xe,{initial:!1,children:t?(0,X.jsx)(Dr,{id:e,text:t,className:n},`message`):null})}function Dr({id:e,text:t,className:n}){let r=he(),i=(0,Y.useRef)(null),[a,o]=(0,Y.useState)(`auto`);return(0,Y.useLayoutEffect)(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([t])=>o(t.borderBoxSize?.[0]?.blockSize??e.offsetHeight));return t.observe(e),()=>t.disconnect()},[]),(0,X.jsx)(H.span,{className:Z.messageSlot,initial:{height:0,opacity:0},animate:{height:a,opacity:1},exit:{height:0,opacity:0,transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.instant}}},transition:r?{duration:0}:{height:Q.smooth,opacity:{duration:$.fast}},children:(0,X.jsx)(H.span,{ref:i,id:e,className:n,initial:!r&&{y:`0.35em`,filter:`blur(${Kn.soft}px)`},animate:{y:0,filter:`blur(0px)`},transition:{duration:r?0:$.standard,ease:qn},children:(0,X.jsx)(Tr,{text:t})})})}function Or({id:e,edge:t,text:n}){let r=he();return(0,X.jsx)(xe,{initial:!1,children:t!==0&&(0,X.jsx)(H.span,{id:e,className:Z.limit,initial:r?{opacity:0}:{opacity:0,y:`${t*.45}em`,filter:`blur(${Kn.subtle}px)`},animate:{opacity:1,y:0,filter:`blur(0px)`,transitionEnd:{filter:`none`}},exit:{opacity:0,transition:{duration:r?$.instant:$.standard,ease:Jn}},transition:r?{duration:$.instant}:{y:Q.snappy,opacity:{duration:$.fast},filter:{duration:$.fast}},children:n},`limit`)})}function kr({toward:e,label:t,disabled:n,controls:r,limit:i,pressed:a,iconRef:o,onPress:s,onRelease:c,onActivate:l}){let u=e>0?_t:mt;return(0,X.jsx)(`button`,{type:`button`,className:Z.step,disabled:n,"aria-controls":r,"aria-label":`${e>0?`Increase`:`Decrease`} ${t}`,"aria-disabled":i||void 0,"data-pressed":a||void 0,onPointerDown:e=>{e.button===0&&s()},onPointerUp:c,onPointerLeave:c,onPointerCancel:c,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.detail===0&&l()},onContextMenu:e=>e.preventDefault(),children:(0,X.jsx)(`span`,{ref:o,className:Z.icon,children:(0,X.jsx)(u,{size:16,strokeWidth:1.75,"aria-hidden":`true`})})})}function Ar({label:e,value:t,defaultValue:n=0,onValueChange:r,min:i=0,max:a=2**53-1,step:o=1,largeStep:s,description:c,disabled:l,id:u,prefix:d,suffix:f,scrub:p=!1,locale:m=`en-US`,formatOptions:h,size:g=`md`,limitHint:_=!0}){let v=he(),y=(0,Y.useId)(),b=u??y,x=c?`${b}-description`:void 0,S=`${b}-limit`,C=o>0?o:1,[w,T]=(0,Y.useState)(n),E=t??w,[D,O]=(0,Y.useState)(``),[k,A]=(0,Y.useState)(!1),[ee,te]=(0,Y.useState)(0),[j,ne]=(0,Y.useState)(!1),[M,N]=(0,Y.useState)(``),[re,ie]=(0,Y.useState)(0),[P,F]=(0,Y.useState)(!1),ae=(0,Y.useRef)(null),oe=(0,Y.useRef)(null),se=(0,Y.useRef)(null),ce=(0,Y.useRef)(void 0),le=(0,Y.useRef)(void 0),ue=(0,Y.useRef)(void 0),I=(0,Y.useRef)({edge:0,count:0,at:0}),de=(0,Y.useRef)(null),L=(0,Y.useRef)(null),R=(0,Y.useRef)(E),fe=(0,Y.useRef)(E),z=(0,Y.useRef)(void 0),pe=(0,Y.useRef)(null),B=(0,Y.useRef)(!1),me=(0,Y.useRef)(null),ge=(0,Y.useRef)(!1),_e=(0,Y.useRef)(()=>!1),ye=ve(0),be=ve(0),V=ve(0),xe=$e(()=>be.get()+V.get()),Se=Number.isFinite(i)?i:0,Ce=Math.max(sr(C),sr(Se)),we=h?.minimumFractionDigits??Ce,Te=Math.max(we,h?.maximumFractionDigits??Ce),Ee=h?.useGrouping??!0,De=(0,Y.useMemo)(()=>new Intl.NumberFormat(m,{minimumFractionDigits:we,maximumFractionDigits:Te,useGrouping:Ee,numberingSystem:`latn`}),[m,we,Te,Ee]),U=(0,Y.useMemo)(()=>{let e=new Intl.NumberFormat(m).formatToParts(-1234.5);return{group:e.find(e=>e.type===`group`)?.value??`,`,decimal:e.find(e=>e.type===`decimal`)?.value??`.`}},[m]),Oe=e=>Number(e.toFixed(Ce))||0,ke=e=>Math.min(a,Math.max(i,e)),Ae=e=>Oe(Se+Math.round((e-Se)/C)*C),je=(e,t)=>{let n=(e-Se)/C;return Oe(Se+((t>0?Math.floor(n+1e-7):Math.ceil(n-1e-7))+t)*C)},Me=e=>`${lr(d,e)}${De.format(e)}${lr(f,e)}`.trim();function Ne(e){let t=e.split(U.group).join(``).replace(U.decimal,`.`).replace(/[^\d.-]/g,``);if(!/\d/.test(t))return null;let n=Number(t);return Number.isFinite(n)?n:null}let Pe=k?Ne(D):null,W=Pe??E,[Fe,Ie]=(0,Y.useState)({value:W,direction:1});Fe.value!==W&&Ie({value:W,direction:W>Fe.value?1:-1});let Re=Fe.value===W?Fe.direction:W>Fe.value?1:-1;(0,Y.useEffect)(()=>()=>{window.clearTimeout(z.current),window.clearTimeout(ce.current),window.clearTimeout(le.current),window.clearTimeout(ue.current)},[]);function ze(e,t){let n=performance.now(),r=I.current;r.count=r.edge===e&&n-r.at<nr?r.count+1:1,r.edge=e,r.at=n;let i=ae.current;if(i&&(i.dataset.strain=e>0?`max`:`min`,window.clearTimeout(ue.current),ue.current=window.setTimeout(()=>{delete i.dataset.strain},420)),!v){Le(ye,0,{...or,velocity:-e*ar*(1+Math.min(r.count-1,ir)*rr)});let n=(e>0?se:oe).current;n&&(t===`button`||t===`key`)&&Le(n,{x:[0,-2.5,2.5,-1.5,1,0]},{duration:.32,ease:`easeOut`})}_&&(ie(e),window.clearTimeout(ce.current),ce.current=window.setTimeout(()=>ie(0),er))}function Be(e,n){if(!Number.isFinite(e))return!1;let i=ke(e),a=Math.sign(e-i);return a&&n!==`scrub`?(ze(a>0?1:-1,n),N(`${Me(i)}, ${a>0?`maximum`:`minimum`}`)):n===`button`&&i!==R.current&&N(Me(i)),i!==R.current&&(R.current=i,t===void 0&&T(i),r?.(i),!0)}let Ve=(e,t,n)=>Be(je(R.current,e*t),n);(0,Y.useLayoutEffect)(()=>{R.current=E,_e.current=Ve});function He(){let e=L.current;e&&me.current===null&&(me.current=e.getBoundingClientRect().left-be.get()-V.get())}(0,Y.useLayoutEffect)(()=>{let e=me.current,t=L.current;if(me.current=null,ge.current){ge.current=!1;let e=de.current;if(e&&document.activeElement===e){let t=e.value.length;e.setSelectionRange(t,t)}}if(e===null||!t)return;let n=e-(t.getBoundingClientRect().left-be.get()-V.get());Math.abs(n)<.5||(V.set(V.get()+n),v?V.jump(0):Le(V,0,Q.morph))});function Ue(){window.clearTimeout(le.current),F(!1)}function We(){if(!k)return;He(),A(!1),Ue();let e=Ne(D);e!==null&&Be(Ae(e),`type`)}function Ge(){window.clearTimeout(z.current),z.current=void 0,te(0)}function G(e,t,n){Ge(),We();let r=Math.max(1,Math.round(t/C));n===`button`&&te(e);let i=0,a=()=>{let t=_e.current(e,r,n);z.current=window.setTimeout(a,t?Math.max(Qn,150*.86**++i):$n)};z.current=window.setTimeout(a,Ve(e,r,n)?Zn:360)}function K(e){let t=s??C*10,n={ArrowUp:[1,e.shiftKey?t:C],ArrowDown:[-1,e.shiftKey?t:C],PageUp:[1,t],PageDown:[-1,t]}[e.key];if(n){e.preventDefault(),e.repeat||G(n[0],n[1],`key`);return}if(!k&&(e.key===`Home`&&Number.isFinite(i)||e.key===`End`&&a<2**53-1)){e.preventDefault(),Be(e.key===`Home`?i:a,`key`);return}e.key===`Enter`&&(e.preventDefault(),k?(ge.current=!0,We()):e.currentTarget.select()),e.key===`Escape`&&k&&(e.preventDefault(),He(),A(!1),Ue(),ge.current=!0,Be(fe.current,`type`))}function q(e){let t=RegExp(`[^0-9${cr(U.group)}${Ce||Te?cr(U.decimal):``}${i<0?`\\-`:``}]`,`g`),n=e.replace(t,``);k||(fe.current=E),He(),O(n),A(!0);let r=Ne(n);r!==null&&r>=i&&r<=a&&Ae(r)===r&&Be(r,`type`),Ue(),r!==null&&r<i&&(le.current=window.setTimeout(()=>F(!0),tr))}function J(e){B.current=!1,p&&!l&&e.button===0&&(We(),pe.current={pointer:e.pointerId,x:e.clientX,from:R.current,active:!1},e.currentTarget.setPointerCapture(e.pointerId))}function Ke(e){let t=pe.current;if(!t||t.pointer!==e.pointerId)return;let n=e.clientX-t.x;if(!t.active){if(Math.abs(n)<3)return;t.active=!0,ne(!0)}let r=n/Xn,o=Math.trunc(r);Be(o?je(t.from,o):t.from,`scrub`);let s=t.from+r*C,c=s>a?(s-a)/C*Xn:s<i?(s-i)/C*Xn:0;be.set(v?0:ur(c))}function qe(e){let t=pe.current;t&&t.pointer===e.pointerId&&(pe.current=null,t.active&&(B.current=!0,ne(!1),Le(be,0,v?{duration:0}:Q.snappy),N(Me(R.current))))}let Je=t=>({toward:t,label:e,disabled:l,controls:b,limit:t>0?W>=a:W<=i,pressed:ee===t}),Ye=Pe===null?0:Pe>a?1:Pe<i&&P?-1:0,Xe=_?Ye||re:0,Ze=Xe>0?a:i,Qe=Xe?typeof _==`function`?_(Xe>0?`max`:`min`,Ze):`${Xe>0?`Max`:`Min`} ${Me(Ze)}`:``,et=[x,Ye&&_?S:void 0].filter(Boolean).join(` `)||void 0;return(0,X.jsxs)(`div`,{className:Z.field,"data-size":g,children:[(0,X.jsxs)(`div`,{className:Z.head,children:[(0,X.jsx)(`label`,{htmlFor:b,className:Z.label,"data-scrub":p&&!l||void 0,onPointerDown:J,onPointerMove:Ke,onPointerUp:qe,onPointerCancel:qe,onClick:e=>{B.current&&=(e.preventDefault(),!1)},children:e}),(0,X.jsx)(Or,{id:S,edge:Xe,text:Qe})]}),(0,X.jsxs)(`div`,{ref:ae,className:Z.control,"data-scrubbing":j||void 0,"data-disabled":l||void 0,"data-warn":Ye?Ye>0?`max`:`min`:void 0,children:[(0,X.jsx)(kr,{...Je(-1),iconRef:oe,onPress:()=>G(-1,C,`button`),onRelease:Ge,onActivate:()=>{We(),Ve(-1,1,`button`)}}),(0,X.jsx)(`div`,{className:Z.valueWrap,onMouseDown:e=>{e.target!==de.current&&e.preventDefault()},onClick:e=>{!l&&e.target!==de.current&&(de.current?.focus(),de.current?.select())},children:(0,X.jsxs)(H.span,{ref:L,className:Z.value,style:{x:xe,y:ye},children:[(0,X.jsx)(yr,{text:lr(d,W),direction:Re,className:Z.affix}),(0,X.jsxs)(`span`,{className:Z.number,children:[(0,X.jsx)(`span`,{className:Z.display,"data-hidden":k||void 0,"aria-hidden":`true`,children:(0,X.jsx)(vr,{value:W,format:De,direction:Re,instant:k})}),k&&(0,X.jsx)(`span`,{className:Z.mirror,"aria-hidden":`true`,children:D}),(0,X.jsx)(`input`,{ref:de,id:b,className:Z.input,type:`text`,role:`spinbutton`,inputMode:i<0?`text`:Ce||Te?`decimal`:`numeric`,autoComplete:`off`,spellCheck:!1,value:k?D:De.format(E),disabled:l,"aria-describedby":et,"aria-invalid":Ye?!0:void 0,"aria-valuenow":E,"aria-valuetext":Me(E),"aria-valuemin":Number.isFinite(i)?i:void 0,"aria-valuemax":a<2**53-1?a:void 0,onChange:e=>q(e.currentTarget.value),onKeyDown:K,onKeyUp:e=>{/^(Arrow(Up|Down)|Page(Up|Down))$/.test(e.key)&&Ge()},onBlur:()=>{Ge(),We()}})]}),(0,X.jsx)(yr,{text:lr(f,W),direction:Re,className:Z.affix})]})}),(0,X.jsx)(kr,{...Je(1),iconRef:se,onPress:()=>G(1,C,`button`),onRelease:Ge,onActivate:()=>{We(),Ve(1,1,`button`)}})]}),(0,X.jsx)(Er,{id:x,text:c,className:Z.hint}),(0,X.jsx)(`span`,{className:Z.srOnly,"aria-live":`polite`,"aria-atomic":`true`,children:M})]})}var jr=[`overview`,`cost`,`chart`,`topModel`,`compareYesterday`,`cacheHitRate`,`quota`];function Mr(){let{t:e}=j(),t=Ne(),[n,r]=Xe(),a=Qe(),o=Ze(n,{enabled:a.running,background:!1,live:!0}),s=t=>(0,X.jsx)(i,{label:e(`settings.tray.section.${t}`),detail:e(`settings.tray.section.${t}.hint`),children:(0,X.jsx)(f,{checked:n.sections[t],label:e(`settings.tray.section.${t}`),onChange:e=>r(qe(n,t,e))})},t);return(0,X.jsxs)(`div`,{className:`mx-auto grid max-w-[1120px] items-start gap-4 lg:grid-cols-[minmax(0,1fr)_392px]`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsx)(Nr,{title:e(`settings.tray.titleHeading`),hint:e(`settings.tray.titleHint`),children:(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(zt,{"aria-label":e(`settings.tray.titleHeading`),minColumnWidth:150,value:n.title,onValueChange:e=>r({...n,title:e}),options:_e.map(t=>({value:t,label:e(`settings.tray.title.${t}`),description:e(`settings.tray.title.${t}.hint`)}))})})}),(0,X.jsx)(Nr,{title:e(`settings.tray.usageHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:jr.map(s)})}),(0,X.jsx)(Nr,{title:e(`settings.tray.clientsHeading`),children:(0,X.jsx)(`div`,{className:`divide-y divide-[var(--border)]`,children:s(`clients`)})}),(0,X.jsx)(`div`,{children:(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(yt,{className:`size-3.5`}),onClick:()=>r(Ye),children:e(`settings.tray.reset`)})})]}),(0,X.jsx)(`div`,{className:`lg:sticky lg:top-0`,children:(0,X.jsxs)(Nr,{title:e(`settings.tray.previewHeading`),hint:e(`settings.tray.previewHint`),children:[(0,X.jsx)(`div`,{className:`flex justify-center bg-[var(--surface-muted)] px-4 py-5`,children:(0,X.jsx)(Bt,{preview:!0,className:`w-[360px] max-w-full shadow-[0_12px_40px_rgb(0_0_0/0.25)]`,prefs:n,state:a,data:o,onRefresh:()=>void t.invalidateQueries({queryKey:[`stats`]})})}),(0,X.jsx)(`p`,{className:`border-t border-[var(--border)] px-4 py-2.5 text-[11px] text-[var(--text-muted)]`,children:e(`settings.tray.previewFooter`)})]})})]})}function Nr({title:e,hint:t,children:n}){let{t:r}=j();return(0,X.jsxs)(`section`,{className:`card`,children:[(0,X.jsxs)(`header`,{className:`border-b border-[var(--border)] px-4 py-3`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-[var(--text-muted)]`,children:r(`settings.tab.tray`)}),(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold`,children:e}),t&&(0,X.jsx)(`p`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t})]}),n]})}var Pr=[`general`,`notifications`,`remote`,`backup`,`tray`],Fr=[`UTC`,`Asia/Shanghai`,`Asia/Hong_Kong`,`Asia/Taipei`,`Asia/Tokyo`,`Asia/Singapore`,`Europe/London`,`Europe/Berlin`,`America/New_York`,`America/Los_Angeles`];function Ir(){let{t:e}=j(),{tab:t}=Ot(),n=jt(),r=Ke(),i=Pr.includes(t)&&(t!==`tray`||r)?t:`general`;return(0,X.jsxs)(Lt,{title:e(`nav.settings`),children:[(0,X.jsxs)(Dt,{value:i,onValueChange:e=>n(e===`general`?`/settings`:`/settings/${e}`,{replace:!0}),children:[(0,X.jsxs)(kt,{"aria-label":e(`nav.settings`),children:[(0,X.jsx)(Mt,{value:`general`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(bt,{className:`size-3.5`}),e(`settings.tab.general`)]})}),(0,X.jsx)(Mt,{value:`notifications`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(nt,{className:`size-3.5`}),e(`settings.tab.notifications`)]})}),(0,X.jsx)(Mt,{value:`remote`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ut,{className:`size-3.5`}),e(`settings.tab.remote`)]})}),(0,X.jsx)(Mt,{value:`backup`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(et,{className:`size-3.5`}),e(`settings.tab.backup`)]})}),r&&(0,X.jsx)(Mt,{value:`tray`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(ht,{className:`size-3.5`}),e(`settings.tab.tray`)]})})]}),(0,X.jsx)(Et,{value:`general`,className:`pt-5`,children:(0,X.jsx)(Lr,{})}),(0,X.jsx)(Et,{value:`notifications`,className:`pt-5`,children:(0,X.jsx)(On,{})}),(0,X.jsx)(Et,{value:`remote`,className:`pt-5`,children:(0,X.jsx)(dn,{})}),(0,X.jsx)(Et,{value:`backup`,className:`pt-5`,children:(0,X.jsx)(rn,{})}),r&&(0,X.jsx)(Et,{value:`tray`,className:`pt-5`,children:(0,X.jsx)(Mr,{})})]}),(0,X.jsx)(`div`,{className:`mt-6`,children:(0,X.jsx)(Pt,{name:`settings.sections`})})]})}function Lr(){let{t:e,locale:t,setLocale:n}=j(),r=Nt(),a=Re(),o=c(),s=Ne(),u=ie(),d=I(),p=l(),m=Ie(),{toast:h,confirm:g}=J(),v=a.data,y=m.data?.state===`connected`&&m.data.publicUrl?`${m.data.publicUrl}/v1`:null,b=e=>o.mutate(e,{onError:e=>h(K(e),`error`)}),x=e=>{n(e),b({locale:e})},S=async t=>{await G.copy(t)&&h(e(`common.copied`))};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-[680px]`,children:[(0,X.jsxs)(_,{title:e(`settings.appearance`),children:[(0,X.jsx)(i,{label:e(`settings.theme`),children:(0,X.jsx)(M,{ariaLabel:e(`settings.theme`),value:r.theme,onChange:r.setTheme,items:[{value:`system`,label:e(`settings.theme.system`)},{value:`light`,label:e(`settings.theme.light`)},{value:`dark`,label:e(`settings.theme.dark`)}]})}),(0,X.jsx)(i,{label:e(`settings.accent`),detail:r.accentChoice===`system`?r.systemAccent?e(`settings.accent.followingSystem`):e(`settings.accent.systemUnavailable`):void 0,children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.accent`),value:r.accentChoice,onChange:r.setAccentChoice,options:[{value:`system`,label:e(`settings.accent.system`)},...Ft.map(t=>({value:t.color,label:e(`settings.accent.${t.id}`)}))]})}),(0,X.jsx)(i,{label:e(`settings.language`),detail:e(`settings.languageHint`),children:(0,X.jsx)(M,{ariaLabel:e(`settings.language`),value:t,onChange:x,items:[{value:`zh`,label:`中文`},{value:`en`,label:`English`}]})})]}),(0,X.jsx)(Rn,{}),(0,X.jsx)(Wn,{}),v?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(_,{title:e(`settings.gateway`),footer:e(`settings.gatewayFooter`),children:[(0,X.jsx)(i,{label:e(`settings.gatewayUrl`),detail:`${v.gatewayBaseUrl}/v1`,children:(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void S(`${v.gatewayBaseUrl}/v1`)})}),y&&(0,X.jsx)(i,{label:e(`settings.remote.publicUrl`),detail:y,children:(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void S(y)})}),(0,X.jsx)(xn,{}),(0,X.jsx)(i,{label:e(`settings.dataDir`),detail:v.dataDir,children:G.canOpenPaths?(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(lt,{className:`size-3.5`}),"aria-label":e(`settings.openFolder`),onClick:()=>void G.openPath(v.dataDir)}):(0,X.jsx)(V,{size:`sm`,variant:`plain`,icon:(0,X.jsx)(it,{className:`size-3.5`}),"aria-label":e(`common.copy`),onClick:()=>void S(v.dataDir)})}),(0,X.jsx)(i,{label:e(`settings.requireKey`),detail:e(`settings.requireKeyHint`),children:(0,X.jsx)(f,{checked:v.requireGatewayKey,label:e(`settings.requireKey`),onChange:async t=>{(t||await g({title:e(`settings.requireKeyOffConfirm`),detail:e(`settings.requireKeyOffDetail`),confirmLabel:e(`settings.requireKeyOff`),destructive:!0}))&&b({requireGatewayKey:t})}})}),(0,X.jsx)(i,{label:e(`settings.streamIdle`),detail:e(`settings.streamIdleHint`),children:(0,X.jsx)(Ur,{label:e(`settings.streamIdle`),value:v.streamIdleTimeoutSec,onCommit:e=>b({streamIdleTimeoutSec:e??300}),suffix:` s`})}),(0,X.jsx)(i,{label:e(`settings.maxBody`),detail:e(`settings.maxBodyHint`),children:(0,X.jsx)(Ur,{label:e(`settings.maxBody`),value:v.maxRequestBodyMb??64,onCommit:e=>b({maxRequestBodyMb:e??64}),suffix:` MiB`})}),(0,X.jsx)(i,{label:e(`settings.requestCompression`),detail:e(`settings.requestCompressionHint`),children:(0,X.jsx)(q,{className:`w-40`,ariaLabel:e(`settings.requestCompression`),value:v.requestCompression,onChange:e=>b({requestCompression:e}),options:[{value:`default`,label:e(`settings.requestCompression.default`)},{value:`zstd`,label:`zstd`},{value:`gzip`,label:`gzip`},{value:`br`,label:`Brotli (br)`},{value:`deflate`,label:`deflate`},{value:`none`,label:e(`settings.requestCompression.none`)}]})})]}),(0,X.jsx)(_,{footer:e(`settings.preventSleepHint`),children:(0,X.jsx)(i,{label:e(`settings.preventSleep`),children:(0,X.jsx)(f,{checked:v.preventSleep??!1,label:e(`settings.preventSleep`),onChange:e=>b({preventSleep:e})})})}),(0,X.jsx)(_,{footer:e(`settings.clientFailoverHint`),children:(0,X.jsx)(i,{label:e(`settings.clientFailover`),children:(0,X.jsx)(f,{checked:v.clientProviderFailover??!0,label:e(`settings.clientFailover`),onChange:e=>b({clientProviderFailover:e})})})}),(0,X.jsx)(_,{footer:e(`settings.stripStaleReasoningHint`),children:(0,X.jsx)(i,{label:e(`settings.stripStaleReasoning`),children:(0,X.jsx)(f,{checked:v.stripStaleReasoning??!0,label:e(`settings.stripStaleReasoning`),onChange:e=>b({stripStaleReasoning:e})})})}),(0,X.jsx)(zr,{settings:v}),(0,X.jsx)(Br,{settings:v}),(0,X.jsx)(Vr,{settings:v}),(0,X.jsx)(Rr,{settings:v}),(0,X.jsx)(Hr,{settings:v}),(0,X.jsxs)(_,{title:e(`settings.quota`),footer:e(`settings.quota.autoIntervalHint`),children:[(0,X.jsx)(i,{label:e(`settings.quota.autoInterval`),children:(0,X.jsx)(Ur,{label:e(`settings.quota.autoInterval`),value:v.quotaAutoIntervalMinutes,onCommit:e=>o.mutate({quotaAutoIntervalMinutes:e??30},{onSuccess:()=>void s.invalidateQueries({queryKey:ze.providers}),onError:e=>h(K(e),`error`)}),suffix:` ${e(`settings.minutes`)}`})}),(0,X.jsx)(i,{label:e(`settings.quota.subscriptionInterval`),detail:e(`settings.quota.subscriptionIntervalHint`),children:(0,X.jsx)(Ur,{label:e(`settings.quota.subscriptionInterval`),value:v.subscriptionQuotaIntervalMinutes,onCommit:e=>b({subscriptionQuotaIntervalMinutes:e??30}),suffix:` ${e(`settings.minutes`)}`})})]}),(0,X.jsx)(_,{footer:e(`settings.usageTimeZone.hint`),children:(0,X.jsx)(i,{label:e(`settings.usageTimeZone`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:e(`settings.usageTimeZone`),value:v.usageTimeZone??``,onChange:e=>b({usageTimeZone:e||null}),options:[{value:``,label:e(`settings.usageTimeZone.system`,{zone:v.effectiveUsageTimeZone})},...[...new Set([...Fr,...v.usageTimeZone?[v.usageTimeZone]:[]])].map(e=>({value:e,label:e}))]})})}),(0,X.jsxs)(_,{title:e(`settings.logging`),footer:e(`settings.debugBodiesHint`),children:[(0,X.jsx)(i,{label:e(`settings.debugBodies`),children:(0,X.jsx)(f,{checked:v.debugBodies,label:e(`settings.debugBodies`),onChange:e=>b({debugBodies:e})})}),(0,X.jsx)(i,{label:e(`settings.bodyRetention`),children:(0,X.jsx)(Ur,{label:e(`settings.bodyRetention`),value:v.bodyRetentionDays,onCommit:e=>b({bodyRetentionDays:e??7}),suffix:` ${e(`settings.days`)}`})}),(0,X.jsxs)(i,{label:e(`settings.requestRetention`),detail:v.requestRetentionDays==null?e(`settings.keepForever`):void 0,children:[(0,X.jsx)(f,{checked:v.requestRetentionDays!=null,label:e(`settings.requestRetention`),onChange:e=>b({requestRetentionDays:e?90:null})}),v.requestRetentionDays!=null&&(0,X.jsx)(Ur,{label:e(`settings.requestRetention`),value:v.requestRetentionDays,onCommit:e=>b({requestRetentionDays:e??90}),suffix:` ${e(`settings.days`)}`})]})]}),(0,X.jsx)(_,{footer:e(`settings.traceContentHint`),children:(0,X.jsx)(i,{label:e(`settings.traceContent`),children:(0,X.jsx)(f,{checked:v.traceContent??!1,label:e(`settings.traceContent`),onChange:e=>b({traceContent:e})})})}),(0,X.jsx)(_,{title:e(`settings.effort`),footer:e(`settings.effortHint`),children:[`low`,`medium`,`high`].map(t=>(0,X.jsx)(i,{label:e(`settings.effort.${t}`),children:(0,X.jsx)(Ur,{label:e(`settings.effort.${t}`),value:v.effortBudgets[t],onCommit:e=>b({effortBudgets:{...v.effortBudgets,[t]:e??v.effortBudgets[t]}}),suffix:` tokens`,step:1024})},t))})]}):a.isError?(0,X.jsx)(`div`,{className:`text-[12px] text-[var(--danger)]`,children:K(a.error)}):(0,X.jsx)(F,{className:`mx-auto my-8`}),(0,X.jsxs)(_,{title:e(`settings.about`),children:[(0,X.jsx)(i,{label:e(`settings.serverVersion`),detail:u.data?`${u.data.version} · API ${u.data.apiVersion}`:`—`}),je&&(0,X.jsx)(i,{label:e(`settings.desktopVersion`),detail:Ce()?.version||`—`}),(0,X.jsx)(Vn,{}),je&&(0,X.jsx)(i,{label:e(`settings.logs`),onClick:()=>void G.revealLogs(),children:(0,X.jsx)(lt,{className:`size-4 text-[var(--text-secondary)]`})}),d.data?.required&&(0,X.jsx)(i,{label:e(`settings.logout`),onClick:()=>p.mutate(),children:(0,X.jsx)(pt,{className:`size-4 text-[var(--text-secondary)]`})})]})]})}function Rr({settings:e}){let{t}=j(),{toast:n}=J(),r=c(),[a,o]=(0,Y.useState)(e.proxyMode),[s,l]=(0,Y.useState)({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``});(0,Y.useEffect)(()=>o(e.proxyMode),[e.proxyMode]),(0,Y.useEffect)(()=>l({url:e.proxyUrl??``,username:e.proxyUsername??``,password:``,bypass:e.proxyBypass??``}),[e.proxyUrl,e.proxyUsername,e.proxyBypass,e.hasProxyPassword]);let u=t=>{o(t),(t!==`custom`||e.proxyUrl)&&r.mutate({proxyMode:t},{onError:e=>n(K(e),`error`)})},d=()=>r.mutate({proxyMode:`custom`,proxyUrl:s.url.trim()||null,proxyUsername:s.username.trim()||null,proxyBypass:s.bypass.trim()||null,...s.password?{proxyPassword:s.password}:{}},{onSuccess:()=>n(t(`settings.proxy.saved`)),onError:e=>n(K(e),`error`)}),f=a!==e.proxyMode||s.url!==(e.proxyUrl??``)||s.username!==(e.proxyUsername??``)||s.password!==``||s.bypass!==(e.proxyBypass??``);return(0,X.jsxs)(_,{title:t(`settings.proxy`),footer:t(`settings.proxy.footer`),children:[(0,X.jsx)(i,{label:t(`settings.proxy.mode`),detail:t(`settings.proxy.mode.${a}.hint`),children:(0,X.jsx)(M,{ariaLabel:t(`settings.proxy.mode`),value:a,onChange:u,items:[{value:`system`,label:t(`settings.proxy.mode.system`)},{value:`custom`,label:t(`settings.proxy.mode.custom`)},{value:`direct`,label:t(`settings.proxy.mode.direct`)}]})}),a===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(i,{label:t(`settings.proxy.url`),detail:t(`settings.proxy.urlHint`),children:(0,X.jsx)(x,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.url`),placeholder:`http://127.0.0.1:7890`,value:s.url,onChange:e=>l({...s,url:e.target.value})})}),(0,X.jsx)(i,{label:t(`settings.proxy.username`),detail:t(`settings.proxy.optional`),children:(0,X.jsx)(x,{className:`w-64`,autoComplete:`off`,"aria-label":t(`settings.proxy.username`),value:s.username,onChange:e=>l({...s,username:e.target.value})})}),(0,X.jsx)(i,{label:t(`settings.proxy.password`),detail:e.hasProxyPassword?t(`settings.proxy.passwordSaved`):t(`settings.proxy.optional`),children:(0,X.jsx)(x,{className:`w-64`,type:`password`,autoComplete:`new-password`,"aria-label":t(`settings.proxy.password`),placeholder:e.hasProxyPassword?`••••••••`:void 0,value:s.password,onChange:e=>l({...s,password:e.target.value})})}),(0,X.jsx)(i,{label:t(`settings.proxy.bypass`),detail:t(`settings.proxy.bypassHint`),children:(0,X.jsx)(x,{className:`w-64`,mono:!0,"aria-label":t(`settings.proxy.bypass`),placeholder:`example.com, *.lan`,value:s.bypass,onChange:e=>l({...s,bypass:e.target.value})})}),(0,X.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,X.jsx)(V,{size:`sm`,disabled:!f||!s.url.trim()||r.isPending,onClick:d,children:t(`common.save`)})})]})]})}function zr({settings:e}){let{t}=j(),{toast:n}=J(),r=c(),a=e.providerQualifiedModels??!1,o=a?e.modelQualifyScope??`shared`:`off`,s=e.modelProviderSeparator??`@`,[l,u]=(0,Y.useState)(s);(0,Y.useEffect)(()=>u(s),[s]);let d=e=>r.mutate(e,{onError:e=>{u(s),n(K(e),`error`)}});return(0,X.jsxs)(_,{title:t(`settings.qualifiedModels`),footer:t(`settings.qualifiedModels.footer`),children:[(0,X.jsx)(i,{label:t(`settings.qualifiedModels.mode`),detail:t(`settings.qualifiedModels.modeHint`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:t(`settings.qualifiedModels.mode`),value:o,onChange:e=>d(e===`off`?{providerQualifiedModels:!1}:{providerQualifiedModels:!0,modelQualifyScope:e}),options:[{value:`off`,label:t(`settings.qualifiedModels.mode.off`)},{value:`shared`,label:t(`settings.qualifiedModels.mode.shared`)},{value:`all`,label:t(`settings.qualifiedModels.mode.all`)}]})}),a&&(0,X.jsx)(i,{label:t(`settings.qualifiedModels.separator`),detail:t(`settings.qualifiedModels.separatorHint`),children:(0,X.jsx)(x,{className:`w-24`,mono:!0,maxLength:8,"aria-label":t(`settings.qualifiedModels.separator`),value:l,onChange:e=>u(e.target.value),onBlur:()=>l!==s&&d({modelProviderSeparator:l})})})]})}function Br({settings:e}){let{t}=j(),{toast:n}=J(),r=c(),a=e.currencyRates??{},o=e.displayCurrency??`USD`,[s,l]=(0,Y.useState)({}),u=e=>r.mutate(e,{onError:e=>n(K(e),`error`)}),d=Ee.filter(e=>e.code!==`USD`&&(a[e.code]!=null||s[e.code]!=null)),f=Ee.filter(e=>e.code!==`USD`&&!d.includes(e)),p=e=>l(({[e]:t,...n})=>n),m=e=>{let r=(s[e]??a[e]??``).trim();if(r===a[e])return p(e);if(ye(r)==null)return n(t(`settings.currency.badRate`),`error`);p(e),u({currencyRates:{...a,[e]:r}})},h=e=>{if(p(e),a[e]==null)return;let{[e]:t,...n}=a;u(o===e?{displayCurrency:`USD`,currencyRates:n}:{currencyRates:n})};return(0,X.jsxs)(_,{title:t(`settings.currency`),footer:t(`settings.currency.footer`),children:[(0,X.jsx)(i,{label:t(`settings.currency.display`),detail:t(`settings.currency.displayHint`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:t(`settings.currency.display`),value:o,onChange:e=>u({displayCurrency:e}),options:[{value:`USD`,label:`USD · $`},...Ee.filter(e=>e.code!==`USD`&&ye(a[e.code])!=null).map(e=>({value:e.code,label:`${e.code} · ${e.symbol.trim()}`}))]})}),d.map(e=>(0,X.jsx)(i,{label:t(`settings.currency.rateRow`,{code:e.code}),children:(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`num text-[12px] text-[var(--text-secondary)]`,children:`1 USD =`}),(0,X.jsx)(x,{className:`w-28`,mono:!0,inputMode:`decimal`,"aria-label":t(`settings.currency.rateOf`,{code:e.code}),value:s[e.code]??a[e.code]??``,onChange:t=>l(n=>({...n,[e.code]:t.target.value})),onBlur:()=>m(e.code)}),(0,X.jsx)(`span`,{className:`num text-[12px] text-[var(--text-secondary)]`,children:e.code}),(0,X.jsx)(V,{size:`sm`,variant:`plain`,onClick:()=>h(e.code),children:t(`settings.currency.remove`)})]})},e.code)),f.length>0&&(0,X.jsx)(i,{label:t(`settings.currency.add`),detail:t(`settings.currency.addHint`),children:(0,X.jsx)(q,{className:`w-56`,ariaLabel:t(`settings.currency.add`),value:null,placeholder:t(`settings.currency.addPlaceholder`),onChange:e=>l(t=>({...t,[e]:``})),options:f.map(e=>({value:e.code,label:`${e.code} · ${e.symbol.trim()}`}))})})]})}function Vr({settings:e}){let{t}=j(),{toast:n}=J(),r=c(),a=e.hiddenNav??[],o=At.flatMap(e=>e.items).filter(e=>e.id!==`settings`),s=(e,t)=>r.mutate({hiddenNav:t?a.filter(t=>t!==e):[...a,e]},{onError:e=>n(K(e),`error`)});return(0,X.jsx)(_,{title:t(`settings.sidebar`),footer:t(`settings.sidebar.footer`),children:o.map(e=>(0,X.jsx)(i,{label:t(e.label),children:(0,X.jsx)(f,{checked:!a.includes(e.id),label:t(e.label),onChange:t=>s(e.id,t)})},e.id))})}function Hr({settings:e}){let{t}=j(),{toast:n}=J(),r=c(),a=e.pluginMarketUrl===``,[o,s]=(0,Y.useState)(e.pluginMarketUrl??``);(0,Y.useEffect)(()=>s(e.pluginMarketUrl??``),[e.pluginMarketUrl]);let l=(e,i=!1)=>r.mutate({pluginMarketUrl:e},{onSuccess:()=>i&&n(t(`settings.pluginMarket.saved`)),onError:e=>n(K(e),`error`)});return(0,X.jsxs)(_,{title:t(`settings.pluginMarket`),footer:t(`settings.pluginMarket.footer`),children:[(0,X.jsx)(i,{label:t(`settings.pluginMarket.offline`),detail:t(`settings.pluginMarket.offlineHint`),children:(0,X.jsx)(f,{checked:a,label:t(`settings.pluginMarket.offline`),onChange:e=>l(e?``:null)})}),!a&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(i,{label:t(`settings.pluginMarket.url`),detail:t(`settings.pluginMarket.urlHint`),children:(0,X.jsx)(x,{className:`w-80`,mono:!0,"aria-label":t(`settings.pluginMarket.url`),placeholder:e.pluginMarketDefaultUrl,value:o,onChange:e=>s(e.target.value)})}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-2`,children:[e.pluginMarketUrl!==null&&(0,X.jsx)(V,{size:`sm`,disabled:r.isPending,onClick:()=>l(null,!0),children:t(`settings.pluginMarket.reset`)}),(0,X.jsx)(V,{size:`sm`,disabled:r.isPending||o.trim()===(e.pluginMarketUrl??``),onClick:()=>l(o.trim()||null,!0),children:t(`common.save`)})]})]})]})}function Ur({label:e,value:t,onCommit:n,suffix:r,step:i=1}){let[a,o]=(0,Y.useState)(t);(0,Y.useEffect)(()=>o(t),[t]);let s=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{s.current=n}),(0,Y.useEffect)(()=>{if(a===t)return;let e=setTimeout(()=>s.current(a),600);return()=>clearTimeout(e)},[a,t]),(0,X.jsx)(`div`,{className:`astra-label-hidden w-36`,children:(0,X.jsx)(Ar,{label:e,size:`sm`,value:a,onValueChange:o,min:0,step:i,suffix:r})})}export{Ir as SettingsPage};
@@ -0,0 +1 @@
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{B as n,C as r,Ca as i,F as a,Fa as o,G as s,Hn as c,Ia as l,L as u,Mr as d,O as f,Oo as p,P as m,Sa as h,T as g,Ta as _,U as v,V as y,W as b,_a as x,_r as S,ba as C,ft as w,ga as T,jr as E,k as D,nc as O,qi as k,r as A,ui as j,vr as M,wa as N,xa as P,yr as F}from"./format-BmuJU1J1.js";import{B as I,H as L,U as R,W as z}from"./TrayTitleSource-DleIYaE6.js";import{t as ee}from"./ellipsis-CidyZaW2.js";import{t as B}from"./plus-c3HzV6VX.js";import{t as V}from"./refresh-cw-CoLAai2c.js";import{t as H}from"./sparkles-ibXDb_LG.js";import{B as U,v as W}from"./index-CZ4Wdbud.js";import{t as G}from"./checkbox-DKNuVOmF.js";import{t as K}from"./clientNames-Bskc9G1M.js";var q=e(t(),1),J=O();function Y({library:e}){let{t}=g(),{toast:o}=z(),[s,c]=(0,q.useState)(``),[l,d]=(0,q.useState)(new Set),p=h(s),_=S(),v=i(),x=T(),[C,w]=(0,q.useState)(null),E=(0,q.useMemo)(()=>{let e=new Map;for(let t of p.data?.skills??[])e.set(t.source,[...e.get(t.source)??[],t]);return[...e.entries()]},[p.data]),O=e.targets.filter(e=>e.supported&&e.detected),k=e=>_.mutate({source:e.source,skillId:e.skillId,clients:[...l]},{onSuccess:e=>{let n=e.filter(e=>!e.ok);n.length===0?o(t(`skills.toast.installed`,{n:e.length}),`success`):o(t(`skills.toast.partial`,{ok:e.length-n.length,failed:n.length,reason:n[0]?.reason??``}),`error`)},onError:e=>o(R(e),`error`)}),A=e=>x.mutate(e,{onSuccess:()=>w(null),onError:e=>o(R(e),`error`)});return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(r,{tone:`info`,title:t(`skills.market.thirdParty`,{url:v.data?.url??``})}),(0,J.jsxs)(`div`,{className:`my-3 flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(y,{className:`w-72`,value:s,onChange:c,placeholder:t(`skills.market.search`)}),(0,J.jsx)(D,{size:`sm`,onClick:()=>w(v.data?.url??``),disabled:!e.canCreate,children:t(`skills.market.registry`)})]}),C!==null&&(0,J.jsxs)(`div`,{className:`card mb-3 grid gap-3 p-4`,children:[(0,J.jsx)(a,{label:t(`skills.market.registry`),hint:t(`skills.market.registryHint`,{url:v.data?.default??``}),children:(0,J.jsx)(u,{mono:!0,value:C,onChange:e=>w(e.target.value)})}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(D,{variant:`primary`,loading:x.isPending,onClick:()=>A(C.trim()),children:t(`common.save`)}),(0,J.jsx)(D,{onClick:()=>A(``),children:t(`skills.market.registryReset`)}),(0,J.jsx)(D,{onClick:()=>w(null),children:t(`common.cancel`)})]})]}),O.length>0&&(0,J.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-x-4 gap-y-2 px-1`,children:[(0,J.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:t(`skills.install.apply`)}),O.map(e=>(0,J.jsx)(G,{label:K(e.kind),checked:l.has(e.kind),onCheckedChange:t=>d(n=>{let r=new Set(n);return t===!0?r.add(e.kind):r.delete(e.kind),r})},e.kind))]}),s.trim().length<2&&(0,J.jsx)(m,{title:t(`skills.market.hint`)}),p.isFetching&&(0,J.jsx)(b,{lines:2}),p.data?.error&&(0,J.jsx)(r,{tone:`warning`,title:`${t(`skills.market.error`)}: ${p.data.error}`}),p.data&&!p.data.error&&E.length===0&&!p.isFetching&&(0,J.jsx)(m,{title:t(`skills.market.none`)}),E.map(([r,i])=>(0,J.jsxs)(`div`,{className:`mb-3`,children:[(0,J.jsx)(`div`,{className:`mb-1 px-1 font-mono text-[12px] text-[var(--text-secondary)]`,children:r}),(0,J.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:i.map(r=>(0,J.jsx)(n,{label:(0,J.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:r.name}),r.installed&&(0,J.jsx)(f,{tone:`green`,children:t(`skills.market.installed`)})]}),detail:r.installs>0?t(`skills.market.installs`,{n:r.installs}):void 0,children:(0,J.jsx)(D,{size:`sm`,icon:(0,J.jsx)(U,{className:`size-3.5`}),disabled:r.installed||!e.canCreate||_.isPending,onClick:()=>k(r),children:t(`skills.market.install`)})},r.skillId))})]},r))]})}function X({skill:e,library:t,onClose:r}){let{t:i}=g(),{toast:o}=z(),s=F(),c=l(),[u,d]=(0,q.useState)(null),p=t.projectDirs??[],h=(t,n)=>e?.placements.some(r=>r.target===`project`&&r.project===t&&r.path.endsWith(`${n}${n.includes(`\\`)?`\\`:`/`}${e.name}`))??!1,_=(t,n,r)=>{e&&(d(t+n),c.mutate({name:e.name,project:t,dir:n,on:r},{onError:e=>o(R(e),`error`),onSettled:()=>d(null)}))};return(0,J.jsx)(L,{open:e!==null,onOpenChange:e=>!e&&r(),width:560,title:i(`skills.project.title`,{skill:e?.name??``}),description:i(`skills.project.hint`),footer:(0,J.jsx)(D,{onClick:r,children:i(`common.close`)}),children:(s.data??[]).length===0?(0,J.jsx)(m,{title:i(`skills.project.none`)}):(0,J.jsx)(`div`,{className:`grid gap-3`,children:(s.data??[]).map(e=>(0,J.jsxs)(a,{label:e.name,hint:e.path,children:[!e.exists&&(0,J.jsx)(f,{tone:`orange`,children:i(`library.state.project-missing`)}),(0,J.jsx)(`div`,{className:`grid gap-1`,children:p.map(t=>(0,J.jsx)(n,{label:(0,J.jsx)(`span`,{className:`font-mono text-[12px]`,children:t.dir}),detail:t.clients.map(K).join(`, `),children:(0,J.jsx)(G,{"aria-label":`${e.name} ${t.dir}`,checked:h(e.path,t.dir),disabled:u===e.path+t.dir||!e.exists&&!h(e.path,t.dir),onCheckedChange:n=>_(e.path,t.dir,n===!0)})},t.dir))})]},e.path))})})}function Z({canChange:e}){let{t}=g(),{toast:r}=z(),i=N(),a=x(),o=(i.data??[]).filter(e=>e.supported||e.enabled);return o.length===0?null:(0,J.jsxs)(`div`,{className:`mt-4`,children:[(0,J.jsx)(`div`,{className:`mb-1 px-1 text-[12px] font-medium`,children:t(`skills.router.title`)}),(0,J.jsx)(`p`,{className:`mb-2 px-1 text-[11px] text-[var(--text-muted)]`,children:t(`skills.router.hint`)}),(0,J.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[o.map(i=>(0,J.jsx)(n,{label:(0,J.jsxs)(`span`,{className:`flex items-center gap-2`,children:[K(i.kind),i.enabled&&(0,J.jsx)(f,{tone:`green`,children:t(`skills.router.listed`,{n:i.listed})})]}),detail:i.entry?(0,J.jsx)(`span`,{className:`font-mono text-[11px]`,children:i.entry}):void 0,children:(0,J.jsx)(s,{checked:i.enabled,label:K(i.kind),disabled:!e||a.isPending,onChange:e=>a.mutate({client:i.kind,on:e},{onError:e=>r(R(e),`error`)})})},i.kind)),(i.data??[]).filter(e=>!e.supported&&!e.enabled).map(e=>(0,J.jsx)(n,{className:`opacity-60`,label:K(e.kind),detail:e.why?t(`skills.router.why.${e.why}`):void 0},e.kind))]})]})}function Q({open:e,onOpenChange:t,names:n,libraryDir:r}){let{t:i,locale:o}=g(),{toast:s}=z(),c=d(),l=E(),[u,p]=(0,q.useState)([]),[m,h]=(0,q.useState)({}),[_,v]=(0,q.useState)(null);(0,q.useEffect)(()=>{e&&(v(null),h({}),c.mutate(n,{onSuccess:e=>p(e),onError:e=>v(R(e))}))},[e,n]);let y=u.filter(e=>e.conflict&&!m[e.name]),x=u.filter(e=>!e.conflict||m[e.name]),S=async()=>{try{let e=await l.mutateAsync(x.map(e=>({name:e.name,keep:e.inLibrary?`library`:m[e.name]??null}))),n=e.filter(e=>!e.ok);n.length===0?s(i(`skills.toast.migrated`,{n:e.length}),`success`):s(i(`skills.toast.partial`,{ok:e.length-n.length,failed:n.length,reason:n[0]?.reason??``}),`error`),t(!1)}catch(e){v(R(e))}};return(0,J.jsxs)(L,{open:e,onOpenChange:t,title:i(`skills.migrate.title`),description:i(`skills.migrate.lead`),width:560,footer:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(D,{onClick:()=>t(!1),children:i(`common.cancel`)}),(0,J.jsx)(D,{variant:`primary`,disabled:x.length===0||y.length>0||l.isPending,onClick:()=>void S(),children:i(`skills.migrate.submit`,{n:x.length})})]}),children:[c.isPending&&(0,J.jsx)(b,{lines:3}),_&&(0,J.jsx)(`p`,{className:`mb-3 text-[12px] text-[var(--danger)]`,children:_}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[u.map(e=>(0,J.jsx)(a,{label:e.name,children:(0,J.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[e.conflict?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`px-3 py-2 text-[12px] text-[var(--text-secondary)]`,children:i(`skills.migrate.keep`)}),e.locations.map(t=>(0,J.jsxs)(`label`,{className:`flex cursor-default items-start gap-3 px-3 py-2`,children:[(0,J.jsx)(`input`,{type:`radio`,name:`keep-${e.name}`,checked:m[e.name]===t.path,onChange:()=>h(n=>({...n,[e.name]:t.path}))}),(0,J.jsxs)(`span`,{className:`min-w-0`,children:[(0,J.jsx)(`span`,{className:`block truncate font-mono text-[12px]`,children:t.path}),(0,J.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:i(`skills.migrate.modified`,{time:A(t.modified,o)})})]})]},t.path)),(0,J.jsx)(`div`,{className:`px-3 py-2 text-[11px] text-[var(--text-muted)]`,children:i(`skills.migrate.keepHint`)})]}):e.locations.map(t=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[12px]`,children:t.path}),(0,J.jsx)(f,{tone:`green`,children:e.inLibrary?i(`skills.found.inLibrary`):i(`skills.migrate.noConflict`)})]},t.path)),e.inLibrary&&(0,J.jsx)(`div`,{className:`px-3 py-2 text-[11px] text-[var(--text-muted)]`,children:i(`skills.migrate.inLibrary`)})]})},e.name)),u.length>0&&(0,J.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:i(`skills.migrate.backup`,{dir:r.replace(/library[\\/]skills$/,`backups/library`)})})]})]})}function te({open:e,onOpenChange:t,library:n}){let{t:r}=g(),{toast:i}=z(),o=j(),s=M(),[c,l]=(0,q.useState)(`git`),[d,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(``),[_,y]=(0,q.useState)(null),[b,x]=(0,q.useState)(new Set),[S,C]=(0,q.useState)(new Set),[T,E]=(0,q.useState)(null);(0,q.useEffect)(()=>{e||(y(null),x(new Set),C(new Set),E(null))},[e]);let O=e=>e.status===`new`||e.status===`exists`,k=n.targets.filter(e=>e.supported&&e.detected),A=async()=>{E(null),y(null);try{let e=await o.mutateAsync({kind:c,source:d.trim(),ref:c===`git`&&m.trim()?m.trim():void 0});y(e),x(new Set(e.skills.filter(e=>e.status===`new`).map(e=>e.name)))}catch(e){E(R(e))}},N=async()=>{if(_)try{let e=await s.mutateAsync({probeId:_.probeId,names:[...b],clients:[...S]}),n=e.filter(e=>!e.ok);n.length===0?i(r(`skills.toast.installed`,{n:e.length}),`success`):i(r(`skills.toast.partial`,{ok:e.length-n.length,failed:n.length,reason:n[0]?.reason??``}),`error`),t(!1)}catch(e){E(R(e))}},P=(e,t,n)=>{let r=new Set(e);return n?r.add(t):r.delete(t),r};return(0,J.jsx)(L,{open:e,onOpenChange:t,title:r(`skills.install.title`),description:r(`skills.install.localOnly`),width:520,footer:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(D,{onClick:()=>t(!1),children:r(`common.cancel`)}),(0,J.jsx)(D,{variant:`primary`,disabled:!_||b.size===0||s.isPending,onClick:()=>void N(),children:r(`skills.install.submit`,{n:b.size})})]}),children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(v,{value:c,onChange:e=>{l(e),y(null)},items:[{value:`git`,label:r(`skills.install.kind.git`)},{value:`local`,label:r(`skills.install.kind.local`)}]}),(0,J.jsx)(a,{label:r(c===`git`?`skills.install.repo`:`skills.install.dir`),hint:c===`git`?r(`skills.install.repoHint`):void 0,error:T??void 0,children:(0,J.jsx)(u,{mono:!0,value:d,onChange:e=>p(e.target.value),placeholder:c===`git`?`https://github.com/owner/skills`:`/Users/me/skills`})}),c===`git`&&(0,J.jsx)(a,{label:r(`skills.install.ref`),children:(0,J.jsx)(u,{value:m,onChange:e=>h(e.target.value),placeholder:r(`skills.install.refPlaceholder`)})}),(0,J.jsx)(`div`,{children:(0,J.jsx)(D,{onClick:()=>void A(),disabled:d.trim()===``||o.isPending,children:r(`skills.install.probe`)})}),_&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(a,{label:r(`skills.install.found`,{n:_.skills.length}),children:(0,J.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:_.skills.map(e=>(0,J.jsxs)(`div`,{className:w(`flex items-start gap-3 px-3 py-2`,!O(e)&&`opacity-60`),children:[(0,J.jsx)(G,{checked:b.has(e.name),disabled:!O(e),onCheckedChange:t=>x(n=>P(n,e.name,t===!0)),"aria-label":e.name}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] font-medium`,children:[e.name,e.status!==`new`&&(0,J.jsxs)(f,{tone:e.status===`exists`?`green`:`orange`,children:[r(`skills.status.${e.status}`),e.reason?` · ${r(`skills.reason.${e.reason===`size`?`size`:`name`}`)}`:``]})]}),(0,J.jsx)(`div`,{className:`text-[11px] text-[var(--text-secondary)]`,children:e.description})]})]},e.name))})}),(0,J.jsx)(a,{label:r(`skills.install.apply`),children:(0,J.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-2`,children:k.map(e=>(0,J.jsx)(G,{label:K(e.kind)+(e.readsShared?` · ${r(`skills.badge.shared`)}`:``),checked:S.has(e.kind),onCheckedChange:t=>C(n=>P(n,e.kind,t===!0))},e.kind))})})]})]})})}function ne(e,t){return(!t?.supported||!t.detected)&&e.state===`off`?`disabled`:re(e)}function re(e){return e.state===`off`?`off`:e.how===`copy`?`copy`:e.state===`own`?`on`:e.state===`via-shared`?`shared`:`locked`}var ie={on:`border-[var(--accent)] bg-[var(--accent-subtle)] text-[var(--accent)]`,shared:`border-[var(--accent)] bg-[var(--accent-subtle)] text-[var(--accent)]`,locked:`cursor-help border-dashed border-[var(--accent)] bg-transparent text-[var(--accent)]`,copy:`border-[var(--warning)] bg-transparent text-[var(--warning)]`,off:`border-[var(--border)] text-[var(--text-muted)] hover:border-[var(--text-muted)] hover:text-[var(--text-secondary)]`,disabled:`cursor-not-allowed border-[var(--border)] text-[var(--text-muted)] line-through opacity-40`};function ae({skill:e,targets:t,actions:n}){let{t:r}=g();return(0,J.jsx)(`div`,{className:`flex max-w-[380px] flex-wrap justify-end gap-1.5`,children:e.clients.map(i=>{let a=t.find(e=>e.kind===i.kind),o=ne(i,a),s=K(i.kind),c=i.state.startsWith(`via-`)&&i.state!==`via-shared`?K(i.state.slice(4)):``,l=o===`shared`?r(`skills.badge.sharedHint`):o===`locked`?r(`skills.badge.viaHint`,{client:c}):o===`copy`?r(`skills.badge.copyHint`):o===`disabled`?r(a?.supported?`skills.badge.notDetected`:`skills.badge.unsupported`):void 0,u=o===`on`||o===`shared`||o===`copy`||o===`off`;return(0,J.jsxs)(`button`,{type:`button`,title:l,disabled:o===`disabled`,"aria-pressed":o!==`off`&&o!==`disabled`,className:w(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11.5px] transition-colors`,ie[o]),onClick:u?()=>void n.toggle(e.name,i.kind,o===`off`):void 0,children:[s,o===`shared`&&(0,J.jsx)(`i`,{className:`text-[10px] not-italic opacity-80`,children:r(`skills.badge.shared`)}),o===`copy`&&(0,J.jsx)(`i`,{className:`text-[10px] not-italic opacity-80`,children:i.modified?`${r(`skills.badge.copy`)}·${r(`skills.badge.modified`)}`:r(`skills.badge.copy`)})]},i.kind)})})}function oe(){let{t:e}=g(),{toast:t,confirm:n}=z(),r=o(),i=k(),a=c(),s=C(),l=p(),u=(n,r=`skills.toast.returned`)=>{let i=n.filter(e=>!e.ok);i.length===0?t(e(r),`success`):t(e(`skills.toast.partial`,{ok:n.length-i.length,failed:i.length,reason:i[0]?.reason??``}),`error`)},d=async e=>{try{await e()}catch(e){t(R(e),`error`)}};return{async toggle(t,i,a){await d(async()=>{let o=await r.mutateAsync({name:t,client:i,on:a});if(o.needsConfirm){if(!await n({title:e(`skills.confirm.sharedOff.title`,{client:K(i)}),detail:e(`skills.confirm.sharedOff.detail`,{client:K(i),skill:t,others:o.affected.map(K).join(`、`)}),confirmLabel:e(`skills.confirm.sharedOff.confirm`),destructive:!0}))return;o=await r.mutateAsync({name:t,client:i,on:a,confirm:!0})}})},async update(r,i){(!i||await n({title:e(`skills.confirm.update.title`,{skill:r}),detail:e(`skills.confirm.update.detail`),confirmLabel:e(`skills.updates.update`),destructive:!0}))&&await d(async()=>{await l.mutateAsync({name:r,force:i}),t(e(`skills.toast.updated`,{skill:r}),`success`)})},async giveBack(t){await n({title:e(`skills.confirm.return.title`,{skill:t}),detail:e(`skills.confirm.return.detail`),confirmLabel:e(`skills.menu.return`)})&&await d(async()=>u(await i.mutateAsync(t)))},async returnAll(){await n({title:e(`skills.confirm.returnAll.title`),detail:e(`skills.confirm.returnAll.detail`),confirmLabel:e(`skills.returnAll`)})&&await d(async()=>u(await i.mutateAsync(null)))},async remove(r){await n({title:e(`skills.confirm.delete.title`,{skill:r}),detail:e(`skills.confirm.delete.detail`),confirmLabel:e(`common.delete`),destructive:!0})&&await d(async()=>{await a.mutateAsync(r),t(e(`skills.toast.deleted`),`success`)})},async takeEdits(r){await n({title:e(`skills.confirm.take.title`),detail:e(`skills.confirm.take.detail`),confirmLabel:e(`skills.menu.take`)})&&await d(async()=>{await s.mutateAsync({name:r,action:`take-edits`}),t(e(`skills.toast.done`),`success`)})},async overwriteCopy(r){await n({title:e(`skills.confirm.overwrite.title`),detail:e(`skills.confirm.overwrite.detail`),confirmLabel:e(`skills.menu.overwrite`)})&&await d(async()=>{await s.mutateAsync({name:r,action:`overwrite-copy`}),t(e(`skills.toast.done`),`success`)})}}}function $(){let{t:e}=g(),t=P(),[n,i]=(0,q.useState)(`managed`),[a,o]=(0,q.useState)(``),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(void 0),p=oe(),h=_(),{toast:x}=z(),[S,C]=(0,q.useState)(null),w=(0,q.useMemo)(()=>new Map((h.data??[]).map(e=>[e.name,e])),[h.data]),T=t.data,E=(T?.found??[]).filter(e=>e.kind===`unmanaged`),O=(T?.found??[]).filter(e=>e.kind===`external`),k=(0,q.useMemo)(()=>{let e=a.trim().toLowerCase();return(T?.skills??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e))},[T,a]);return(0,J.jsxs)(W,{title:e(`nav.skills`),subtitle:e(`skills.subtitle`),actions:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(D,{variant:`glass`,icon:(0,J.jsx)(V,{className:`size-4`}),loading:h.isPending,disabled:!T||T.canCreate===!1||!T.skills.some(e=>e.sourceKind===`git`),onClick:()=>h.mutate(void 0,{onSuccess:t=>x(t.some(e=>e.behind)?e(`skills.updates.found`,{n:t.filter(e=>e.behind).length}):e(`skills.updates.none`),`success`),onError:e=>x(R(e),`error`)}),children:e(`skills.updates.check`)}),(0,J.jsx)(D,{variant:`glass`,onClick:()=>void p.returnAll(),disabled:!T||T.skills.length===0,children:e(`skills.returnAll`)}),(0,J.jsx)(D,{variant:`primary`,icon:(0,J.jsx)(B,{className:`size-4`}),onClick:()=>c(!0),disabled:T?.canCreate===!1,children:e(`skills.install`)})]}),children:[t.isError&&(0,J.jsx)(r,{tone:`danger`,title:`${e(`skills.error.load`)}: ${R(t.error)}`}),t.isLoading&&(0,J.jsx)(b,{lines:4}),T&&T.canCreate===!1&&(0,J.jsx)(r,{tone:`info`,title:e(`skills.install.disabled`)}),T&&E.length>0&&n===`managed`&&(0,J.jsxs)(`div`,{className:`card mb-3 flex items-center gap-3 border-[var(--warning)] px-4 py-2 text-[12px]`,children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1`,children:e(`skills.foundBanner`,{n:E.length})}),(0,J.jsx)(D,{size:`sm`,onClick:()=>i(`found`),children:e(`skills.foundBannerAction`)})]}),T&&(0,J.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(v,{value:n,onChange:i,items:[{value:`managed`,label:`${e(`skills.tab.managed`)} · ${T.skills.length}`},{value:`market`,label:e(`skills.tab.market`)},{value:`found`,label:`${e(`skills.tab.found`)} · ${T.found.length}`}]}),n===`managed`&&(0,J.jsx)(y,{className:`ml-auto w-56`,value:a,onChange:o,placeholder:e(`skills.search`)})]}),T&&n===`managed`&&(0,J.jsxs)(J.Fragment,{children:[T.skills.length===0?(0,J.jsx)(m,{icon:(0,J.jsx)(H,{className:`size-6`}),title:e(`skills.empty.title`),detail:e(`skills.empty.detail`),action:T.canCreate?(0,J.jsx)(D,{variant:`primary`,onClick:()=>c(!0),children:e(`skills.install`)}):void 0}):(0,J.jsx)(`div`,{className:`card divide-y divide-[var(--border)]`,children:k.map(e=>(0,J.jsx)(se,{skill:e,targets:T.targets,actions:p,update:w.get(e.name),canPlace:T.canCreate&&(T.projectDirs??[]).length>0,onPlace:()=>C(e)},e.name))}),(0,J.jsx)(le,{}),(0,J.jsx)(Z,{canChange:T.canCreate})]}),T&&n===`market`&&(0,J.jsx)(Y,{library:T}),T&&n===`found`&&(0,J.jsx)(ue,{unmanaged:E,external:O,onMigrate:e=>{f(e),u(!0)}}),T&&(0,J.jsx)(te,{open:s,onOpenChange:c,library:T}),T&&(0,J.jsx)(X,{skill:S,library:T,onClose:()=>C(null)}),T&&(0,J.jsx)(Q,{open:l,onOpenChange:u,names:d,libraryDir:T.libraryDir})]})}function se({skill:e,targets:t,actions:r,update:i,canPlace:a,onPlace:o}){let{t:s}=g(),c=e.placements.some(e=>e.modified),l=e.sourceKind===`git`?`green`:`neutral`,u=e.sourceJson?ce(e.sourceJson):``,d=e.placements.filter(e=>e.target===`project`);return(0,J.jsxs)(n,{label:(0,J.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,J.jsx)(f,{tone:l,children:s(`skills.source.${e.sourceKind}`)}),c&&(0,J.jsx)(f,{tone:`orange`,children:s(`skills.copyModified`)}),i?.behind&&(0,J.jsx)(f,{tone:`orange`,children:s(`skills.updates.behind`)}),i&&!i.behind&&!i.error&&(0,J.jsx)(f,{tone:`green`,children:s(`skills.updates.current`)}),i?.error&&(0,J.jsx)(f,{tone:`red`,title:i.error,children:s(`skills.updates.error`)})]}),detail:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{children:e.description||`—`}),u&&(0,J.jsx)(`span`,{className:`ml-2 text-[var(--text-muted)]`,children:u}),e.placements.length===0&&(0,J.jsxs)(`span`,{className:`ml-2 text-[var(--text-muted)]`,children:[`· `,s(`skills.noPlacements`)]}),d.map(e=>(0,J.jsxs)(`span`,{className:`ml-2 text-[var(--text-muted)]`,title:e.path,children:[`· `,s(`skills.badge.project`,{name:(e.project??``).split(/[\\/]/).filter(Boolean).pop()??``}),e.projectMissing?` (${s(`library.state.project-missing`)})`:``]},e.path))]}),className:`items-start py-3`,children:[(0,J.jsx)(ae,{skill:e,targets:t,actions:r}),(0,J.jsx)(I,{label:``,iconOnly:!0,icon:(0,J.jsx)(ee,{className:`size-4`}),items:[...i?.behind?[{id:`update`,label:s(`skills.updates.update`),onSelect:()=>void r.update(e.name,i.edited)}]:[],...a?[{id:`project`,label:s(`skills.project.menu`),onSelect:o}]:[],...c?[{id:`take`,label:s(`skills.menu.take`),onSelect:()=>void r.takeEdits(e.name)},{id:`over`,label:s(`skills.menu.overwrite`),onSelect:()=>void r.overwriteCopy(e.name)}]:[],{id:`return`,label:s(`skills.menu.return`),disabled:e.placements.length===0,separatorBefore:c,onSelect:()=>void r.giveBack(e.name)},{id:`delete`,label:s(`skills.menu.delete`),destructive:!0,onSelect:()=>void r.remove(e.name)}]})]})}function ce(e){try{let t=JSON.parse(e);return t.url?`${t.url.replace(/^https?:\/\//,``).replace(/\.git$/,``)}${t.commit?` · ${t.commit.slice(0,7)}`:``}`:t.path??t.from??``}catch{return``}}function le(){let{t:e}=g();return(0,J.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-4 gap-y-1 px-1 text-[11px] text-[var(--text-muted)]`,children:[(0,J.jsx)(`span`,{children:e(`skills.legend.on`)}),(0,J.jsx)(`span`,{children:e(`skills.legend.shared`)}),(0,J.jsx)(`span`,{children:e(`skills.legend.copy`)}),(0,J.jsx)(`span`,{children:e(`skills.legend.off`)})]})}function ue({unmanaged:e,external:t,onMigrate:r}){let{t:i}=g(),[a,o]=(0,q.useState)(()=>new Set(e.filter(e=>!e.skillsCli).map(e=>e.name))),s=(e,t)=>o(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r});return e.length===0&&t.length===0?(0,J.jsx)(m,{title:i(`skills.found.empty`)}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-1`,children:[(0,J.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:i(`skills.found.selected`,{n:a.size,total:e.length})}),(0,J.jsx)(D,{className:`ml-auto`,variant:`primary`,disabled:a.size===0,onClick:()=>r([...a]),children:i(`skills.found.migrate`)})]}),(0,J.jsxs)(`div`,{className:`card divide-y divide-[var(--border)]`,children:[e.map(e=>(0,J.jsx)(n,{icon:(0,J.jsx)(G,{checked:a.has(e.name),onCheckedChange:t=>s(e.name,t===!0),"aria-label":e.name}),label:(0,J.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,J.jsx)(f,{children:i(`skills.found.kind.unmanaged`)}),e.conflict&&(0,J.jsx)(f,{tone:`orange`,children:i(`skills.found.differs`)}),e.inLibrary&&(0,J.jsx)(f,{tone:`green`,children:i(`skills.found.inLibrary`)}),e.skillsCli&&(0,J.jsx)(f,{tone:`orange`,title:i(`skills.found.skillsCliHint`),children:i(`skills.found.skillsCli`)})]}),detail:(0,J.jsx)(`span`,{className:`font-mono`,children:e.locations.map(e=>e.path).join(` · `)}),children:(0,J.jsx)(`span`,{className:`text-[11px] text-[var(--text-muted)]`,children:i(`skills.found.places`,{n:e.locations.length})})},e.name)),t.map(e=>(0,J.jsx)(n,{className:`opacity-70`,label:(0,J.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,J.jsx)(f,{children:i(`skills.found.kind.external`)})]}),detail:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`span`,{className:`font-mono`,children:[e.locations[0]?.path,` → `,e.linkTarget]}),(0,J.jsx)(`span`,{className:`ml-2`,children:i(`skills.found.externalHint`)})]})},e.name+e.locations[0]?.path))]})]})}export{$ as SkillsPage};
@@ -0,0 +1,2 @@
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{$i as n,B as r,C as i,D as a,Ea as o,G as s,I as c,Jo as l,K as u,L as d,M as f,N as p,O as m,Qi as h,T as g,U as _,W as v,d as y,k as b,ko as x,nc as S,qa as C,z as w}from"./format-BmuJU1J1.js";import{R as T,U as E,V as D,W as O}from"./TrayTitleSource-DleIYaE6.js";import{t as k}from"./arrow-down-Def8Fl70.js";import{t as A}from"./arrow-up-DE65OgjV.js";import{t as j}from"./copy-48gwhhDO.js";import{t as M}from"./plus-c3HzV6VX.js";import{t as N}from"./trash-BHBJn5GS.js";import{T as P,v as F}from"./index-CZ4Wdbud.js";var I=e(t(),1),L=S(),R=2,z=6;function B({detail:e,...t}){return(0,L.jsx)(r,{...t,detail:e==null?void 0:(0,L.jsx)(`span`,{className:`block whitespace-normal`,children:e})})}var V={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:``}]},H=(e,t)=>`${e??``}\n${t}`;function U(e,t){let n=t.trim().replace(/\/+$/,``);return V[e].find(e=>e.baseUrl===n)?.id??`custom`}function W(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 G(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 K=e=>[e.timeoutMs,e.sessionTtlMinutes,e.minConfidence,e.contextTurns,e.maxChars].every(e=>e!==null);function q(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 J(e){return{virtualModel:e.virtualModel,judge:q(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 Y(e,t,n){let r=`smartRouting.problem.${e.code}`;if(!(r in a))return e.message;let i=/^grades\[(\d+)\]/.exec(e.field??``),o=i?t.grades[Number(i[1])]:void 0;return n(r,{grade:o?o.name||o.id:``,field:e.field??``})}function X(e,t,n){if(e instanceof l){let r=e.details?.problems;if(Array.isArray(r)&&r.length>0)return r.map(e=>Y(e,t,n))}return[E(e)]}function Z(e){let t=`smartRouting.unusable.${e}`;return e&&t in a?t:null}function Q(e,t){let n=`smartRouting.failure.${e}`;return n in a?t(n):e??``}function $(){let{t:e}=g(),t=o();return t.data?(0,L.jsx)(ee,{saved:t.data}):(0,L.jsx)(`div`,{className:`mx-auto max-w-[760px]`,children:t.isError?(0,L.jsx)(i,{tone:`danger`,title:e(`smartRouting.loadFailed`),children:E(t.error)}):(0,L.jsx)(v,{className:`mx-auto my-8`})})}function ee({saved:e}){let{t}=g(),{toast:n}=O(),r=x(),[i,a]=(0,I.useState)(()=>G(e)),[o,s]=(0,I.useState)([]),c=e=>a(t=>({...t,...e})),l=JSON.stringify(i)!==JSON.stringify(G(e)),u=K(i),d=e=>r.mutate({...J(i),...e!==void 0&&{enabled:e}},{onSuccess:r=>{s([]),a(G(r)),n(t(e===void 0?`common.saved`:e?`smartRouting.toast.on`:`smartRouting.toast.off`))},onError:e=>s(X(e,i,t))});return(0,L.jsxs)(`div`,{className:`mx-auto max-w-[760px]`,children:[(0,L.jsx)(te,{saved:e,busy:r.isPending,canSave:u,onToggle:e=>d(e),problems:o}),(0,L.jsx)(re,{saved:e,draft:i,patch:c}),(0,L.jsx)(ae,{draft:i,patch:c}),(0,L.jsx)(oe,{draft:i,patch:c}),!u&&(0,L.jsx)(`p`,{className:`mb-3 px-1 text-[12px] text-[var(--warning)]`,children:t(`smartRouting.numberMissing`)}),(0,L.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[l&&(0,L.jsx)(b,{variant:`plain`,onClick:()=>a(G(e)),children:t(`smartRouting.discard`)}),(0,L.jsx)(b,{variant:`primary`,disabled:!l||!u,loading:r.isPending,onClick:()=>d(),children:t(`common.save`)})]})]})}function te({saved:e,busy:t,canSave:n,onToggle:r,problems:a}){let{t:o}=g(),{toast:l}=O(),{status:u}=e,d=async e=>{await T.copy(e)&&l(o(`common.copied`))},f=(0,I.useRef)(null);return(0,I.useEffect)(()=>{a.length>0&&f.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[a]),(0,L.jsxs)(c,{title:o(`smartRouting.status`),footer:o(`smartRouting.statusFooter`),children:[(0,L.jsx)(B,{label:o(`smartRouting.enable`),detail:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,L.jsx)(p,{tone:e.enabled?u.breakerOpen?`orange`:`green`:`neutral`}),e.enabled?u.breakerOpen?o(`smartRouting.state.breaker`):`${o(`smartRouting.state.on`)}${u.pins>0?` · ${o(`smartRouting.state.pins`,{count:u.pins})}`:``}`:o(`smartRouting.state.off`)]}),children:(0,L.jsx)(s,{checked:e.enabled,label:o(`smartRouting.enable`),disabled:t||!n,onChange:r})}),e.enabled&&(0,L.jsxs)(B,{label:o(`smartRouting.use`),detail:o(`smartRouting.useHint`),children:[(0,L.jsx)(`span`,{className:`font-mono text-[12px] selectable`,children:e.virtualModel}),(0,L.jsx)(b,{size:`sm`,variant:`plain`,icon:(0,L.jsx)(j,{className:`size-3.5`}),"aria-label":o(`common.copy`),onClick:()=>void d(e.virtualModel)})]}),e.enabled&&(0,L.jsx)(ne,{saved:e}),a.length>0&&(0,L.jsx)(`div`,{ref:f,className:`px-3 py-2`,children:(0,L.jsx)(i,{tone:`danger`,title:o(`smartRouting.problems`),children:(0,L.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:a.map((e,t)=>(0,L.jsx)(`li`,{children:e},`${t}-${e}`))})})})]})}function ne({saved:e}){let{t,locale:n}=g(),r=e.status.recent??{total:0,outcomes:{}},o=e.status.unreachable??[],s=t=>{let n=e.grades.find(e=>e.id===t);return n?n.name||n.id:t},c=r.outcomes.judge??0,l=Object.entries(r.outcomes).filter(([e])=>e!==`judge`).sort((e,t)=>t[1]-e[1]),u=r.total-c,d=[t(`smartRouting.recent.judged`,{count:c,total:r.total}),...l.map(([e,n])=>t(`smartRouting.recent.fallback`,{reason:Q(e,t),count:n})),...r.medianJudgeMs==null?[]:[t(`smartRouting.recent.median`,{ms:r.medianJudgeMs})]].join(` · `),f=`smartRouting.recent.hint.${l[0]?.[0]}`;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{label:t(`smartRouting.recent`),detail:r.total===0?t(`smartRouting.recent.none`):d}),u>=2&&u*2>r.total&&(0,L.jsx)(`div`,{className:`px-3 py-2`,children:(0,L.jsxs)(i,{tone:`warning`,title:t(`smartRouting.recent.failing`,{grade:s(e.rules.fallbackGrade)}),children:[(0,L.jsx)(`p`,{children:t(f in a?f:`smartRouting.recent.hint.other`)}),r.lastFallbackAt&&(0,L.jsx)(`p`,{className:`mt-1 text-[var(--text-muted)]`,children:t(`smartRouting.recent.last`,{reason:Q(r.lastFallback,t),time:y(r.lastFallbackAt,n)})})]})}),o.length>0&&(0,L.jsx)(`div`,{className:`px-3 py-2`,children:(0,L.jsxs)(i,{tone:`warning`,title:t(`smartRouting.unreachable.title`),children:[(0,L.jsx)(`ul`,{className:`list-disc space-y-1.5 pl-4`,children:o.map(e=>{let r=Z(e.reason),i={count:e.count,time:y(e.lastAt,n)};return(0,L.jsxs)(`li`,{children:[(0,L.jsxs)(`div`,{children:[t(`smartRouting.unreachable.item`,{caller:P(e.caller),grade:s(e.grade),where:e.providerName?t(`smartRouting.unreachable.where`,{provider:e.providerName,model:e.model}):e.model,reason:t(r??`smartRouting.unusable.unknown`)}),` `,e.usedGrade?t(`smartRouting.unreachable.used`,{...i,used:s(e.usedGrade)}):t(`smartRouting.unreachable.none`,i)]}),r&&(0,L.jsx)(`div`,{className:`text-[var(--text-muted)]`,children:t(`${r}.fix`)})]},`${e.caller}\n${e.grade}`)})}),o.some(e=>!Z(e.reason))&&(0,L.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.unreachable.hint`)})]})})]})}function re({saved:e,draft:t,patch:n}){let{t:r}=g(),a=U(t.protocol,t.baseUrl),o=e.judge.hasApiKey&&t.apiKey===``&&W(t.baseUrl,t.protocol,e.protocols)!==W(e.judge.baseUrl??``,e.judge.protocol,e.protocols);return(0,L.jsxs)(c,{title:r(`smartRouting.judge.title`),footer:r(`smartRouting.judge.footer`),children:[(0,L.jsx)(B,{label:r(`smartRouting.judge.protocol`),detail:r(`smartRouting.judge.protocol.${t.protocol}.hint`),children:(0,L.jsx)(_,{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,L.jsx)(`div`,{className:`px-3 py-2`,children:(0,L.jsx)(i,{tone:`warning`,title:r(`smartRouting.judge.openaiDraft`)})}),(0,L.jsx)(B,{label:r(`smartRouting.judge.service`),children:(0,L.jsx)(D,{className:`w-52`,ariaLabel:r(`smartRouting.judge.service`),value:a,onChange:e=>{if(e===`custom`)return n({baseUrl:t.baseUrl||`https://`});let r=V[t.protocol].find(t=>t.id===e);r&&n({baseUrl:r.baseUrl,...r.model!==void 0&&{model:r.model}})},options:[...V[t.protocol].map(e=>({value:e.id,label:r(`smartRouting.preset.${e.id}`)})),{value:`custom`,label:r(`smartRouting.preset.custom`)}]})}),a===`custom`&&(0,L.jsx)(B,{label:r(`smartRouting.judge.baseUrl`),detail:r(`smartRouting.judge.baseUrlHint`),children:(0,L.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,L.jsx)(B,{label:r(`smartRouting.judge.apiKey`),detail:o?r(`smartRouting.judge.keyReplace`):e.judge.hasApiKey?r(`smartRouting.judge.keySaved`,{mask:e.judge.apiKeyMasked??``}):r(`smartRouting.judge.keyMissing`),children:(0,L.jsx)(d,{className:`w-72`,type:`password`,autoComplete:`off`,mono:!0,"aria-label":r(`smartRouting.judge.apiKey`),placeholder:e.judge.hasApiKey&&!o?`••••••••`:`sk-…`,value:t.apiKey,onChange:e=>n({apiKey:e.target.value})})}),o&&(0,L.jsx)(`div`,{className:`px-3 py-2`,children:(0,L.jsx)(i,{tone:`warning`,title:r(`smartRouting.judge.keyDropped`)})}),(0,L.jsx)(B,{label:r(`smartRouting.judge.model`),detail:r(`smartRouting.judge.modelHint`),children:(0,L.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,L.jsx)(B,{label:r(`smartRouting.judge.timeout`),detail:r(`smartRouting.judge.timeoutHint`),children:(0,L.jsx)(w,{className:`w-28`,label:r(`smartRouting.judge.timeout`),step:100,min:200,value:t.timeoutMs,onChange:e=>n({timeoutMs:e})})}),(0,L.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,L.jsx)(i,{tone:`info`,title:r(`smartRouting.privacy.title`),children:r(`smartRouting.privacy.body`,{turns:t.contextTurns??0,chars:t.maxChars??0})}),t.protocol===`typesafe`&&(0,L.jsx)(i,{tone:`warning`,title:r(`smartRouting.judge.nonEnglish`)}),(0,L.jsxs)(f,{title:r(`smartRouting.judge.instructions`),children:[(0,L.jsx)(`p`,{className:`mb-2 text-[11px] text-[var(--text-muted)]`,children:r(`smartRouting.judge.instructionsHint`)}),(0,L.jsx)(u,{rows:4,"aria-label":r(`smartRouting.judge.instructions`),placeholder:e.defaultInstructions,value:t.instructions,onChange:e=>n({instructions:e.target.value})})]})]}),(0,L.jsx)(ie,{draft:t})]})}function ie({draft:e}){let{t}=g(),n=C(),[r,a]=(0,I.useState)(``),[o,s]=(0,I.useState)(null),[c,l]=(0,I.useState)([]),d=()=>{s(null),l([]),n.mutate({text:r,judge:q(e),grades:e.grades},{onSuccess:s,onError:n=>l(X(n,e,t))})},f=o!==null&&o.latencyMs>o.limitMs;return(0,L.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,L.jsx)(`div`,{className:`text-[13px]`,children:t(`smartRouting.test.title`)}),(0,L.jsx)(`p`,{className:`text-[11px] text-[var(--text-muted)]`,children:t(`smartRouting.test.hint`)}),(0,L.jsx)(u,{rows:3,"aria-label":t(`smartRouting.test.title`),placeholder:t(`smartRouting.test.placeholder`),value:r,onChange:e=>a(e.target.value)}),(0,L.jsx)(`div`,{className:`flex justify-end`,children:(0,L.jsx)(b,{size:`sm`,disabled:r.trim()===``,loading:n.isPending,onClick:d,children:t(`smartRouting.test.run`)})}),c.length>0&&(0,L.jsx)(i,{tone:`danger`,title:t(`smartRouting.problems`),children:(0,L.jsx)(`ul`,{className:`list-disc space-y-0.5 pl-4`,children:c.map((e,t)=>(0,L.jsx)(`li`,{children:e},`${t}-${e}`))})}),o&&(o.ok?(0,L.jsx)(i,{tone:o.confident&&!f?`success`:`warning`,title:t(`smartRouting.test.result`,{grade:o.gradeName??o.grade??``}),children:(0,L.jsxs)(`div`,{className:`space-y-0.5 text-[12px]`,children:[(0,L.jsx)(`div`,{children:o.model?t(`smartRouting.test.model`,{model:o.model}):t(`smartRouting.test.noModel`)}),(0,L.jsxs)(`div`,{children:[t(`smartRouting.test.confidence`,{percent:Math.round((o.confidence??0)*100)}),` ·`,` `,o.confident?t(`smartRouting.test.confident`):t(`smartRouting.test.notConfident`)]}),f&&(0,L.jsxs)(`div`,{className:`text-[var(--warning)]`,children:[t(`smartRouting.test.slow`,{ms:o.latencyMs,limit:o.limitMs}),o.newConnection&&` ${t(`smartRouting.test.connecting`)}`]}),(0,L.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,L.jsxs)(i,{tone:`danger`,title:t(`smartRouting.test.failed`,{reason:Q(o.failure,t)}),children:[o.message,o.failure===`timeout`&&o.newConnection&&(0,L.jsx)(`p`,{className:`mt-1`,children:t(`smartRouting.test.connecting`)})]}))]})}function ae({draft:e,patch:t}){let{t:r}=g(),i=n(),a=h(),o=e.grades,s=(n,r=e.fallbackGrade)=>t({grades:n,fallbackGrade:n.some(e=>e.id===r)?r:n[Math.floor(n.length/2)]?.id??``}),l=(e,t)=>s(o.map((n,r)=>r===e?{...n,...t}:n)),f=(e,t)=>{let n=[...o];[n[e],n[e+t]]=[n[e+t],n[e]],s(n)},p=()=>{let e=o.length+1;for(;o.some(t=>t.id===`grade-${e}`);)e++;s([...o,{id:`grade-${e}`,name:``,description:``,model:``}])},_=i.data??[],v=new Set(_.filter((e,t)=>_.findIndex(t=>t.id===e.id)!==t).map(e=>e.id)),y=_.map(e=>({value:H(e.providerId,e.id),label:v.has(e.id)?`${e.id} · ${e.providerName}`:e.id,detail:v.has(e.id)?void 0:e.providerName})),x=(a.data??[]).filter(e=>e.enabled).map(e=>({value:H(null,e.modelId),label:r(`smartRouting.grade.groupOption`,{name:e.name||e.slug}),detail:e.modelId})),S=[...y,...x],C=e=>{let t=H(e.providerId,e.model);return e.model&&!S.some(e=>e.value===t)?[{value:t,label:r(`smartRouting.grade.unavailable`,{model:e.model})},...S]:S},w=(e,t)=>{let n=t.indexOf(`
2
+ `);l(e,{providerId:t.slice(0,n)||null,model:t.slice(n+1)})};return(0,L.jsxs)(c,{title:r(`smartRouting.grades.title`),footer:r(`smartRouting.grades.footer`),children:[o.map((t,n)=>(0,L.jsxs)(`div`,{className:`space-y-2 px-4 py-3`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`w-4 text-center font-mono text-[11px] text-[var(--text-muted)]`,children:n+1}),(0,L.jsx)(d,{className:`flex-1`,"aria-label":r(`smartRouting.grade.name`),placeholder:t.id,value:t.name,onChange:e=>l(n,{name:e.target.value})}),e.fallbackGrade===t.id&&(0,L.jsx)(m,{tone:`accent`,children:r(`smartRouting.grade.fallbackBadge`)}),(0,L.jsx)(b,{size:`sm`,variant:`plain`,icon:(0,L.jsx)(A,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.up`),disabled:n===0,onClick:()=>f(n,-1)}),(0,L.jsx)(b,{size:`sm`,variant:`plain`,icon:(0,L.jsx)(k,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.down`),disabled:n===o.length-1,onClick:()=>f(n,1)}),(0,L.jsx)(b,{size:`sm`,variant:`plain`,icon:(0,L.jsx)(N,{className:`size-3.5`}),"aria-label":r(`smartRouting.grade.remove`),disabled:o.length<=R,onClick:()=>s(o.filter((e,t)=>t!==n))})]}),(0,L.jsx)(u,{rows:2,"aria-label":r(`smartRouting.grade.description`),placeholder:r(`smartRouting.grade.descriptionPlaceholder`),value:t.description,onChange:e=>l(n,{description:e.target.value})}),(0,L.jsx)(D,{ariaLabel:r(`smartRouting.grade.model`),placeholder:r(`smartRouting.grade.pickModel`),value:t.model?H(t.providerId,t.model):``,options:C(t),onChange:e=>w(n,e)})]},t.id)),i.data?.length===0&&(0,L.jsx)(`p`,{className:`px-4 py-2 text-[12px] text-[var(--warning)]`,children:r(`smartRouting.grade.noModels`)}),(0,L.jsx)(`div`,{className:`flex justify-end px-4 py-2`,children:(0,L.jsx)(b,{size:`sm`,icon:(0,L.jsx)(M,{className:`size-3.5`}),disabled:o.length>=z,onClick:p,children:r(`smartRouting.grade.add`)})})]})}function oe({draft:e,patch:t}){let{t:n}=g();return(0,L.jsxs)(c,{title:n(`smartRouting.rules.title`),footer:n(`smartRouting.rules.footer`),children:[(0,L.jsx)(B,{label:n(`smartRouting.rules.mode`),detail:n(`smartRouting.rules.mode.${e.mode}.hint`),children:(0,L.jsx)(_,{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,L.jsx)(B,{label:n(`smartRouting.rules.ttl`),detail:n(`smartRouting.rules.ttlHint`),children:(0,L.jsx)(w,{className:`w-28`,label:n(`smartRouting.rules.ttl`),step:1,min:1,value:e.sessionTtlMinutes,onChange:e=>t({sessionTtlMinutes:e})})}),(0,L.jsx)(B,{label:n(`smartRouting.rules.fallback`),detail:n(`smartRouting.rules.fallbackHint`),children:(0,L.jsx)(D,{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,L.jsx)(B,{label:n(`smartRouting.rules.minConfidence`),detail:n(`smartRouting.rules.minConfidenceHint`),children:(0,L.jsx)(w,{className:`w-28`,label:n(`smartRouting.rules.minConfidence`),step:.05,min:0,value:e.minConfidence,onChange:e=>t({minConfidence:e})})}),(0,L.jsx)(B,{label:n(`smartRouting.rules.contextTurns`),detail:n(`smartRouting.rules.contextTurnsHint`),children:(0,L.jsx)(w,{className:`w-28`,label:n(`smartRouting.rules.contextTurns`),step:1,min:0,value:e.contextTurns,onChange:e=>t({contextTurns:e})})}),(0,L.jsx)(B,{label:n(`smartRouting.rules.maxChars`),detail:n(`smartRouting.rules.maxCharsHint`),children:(0,L.jsx)(w,{className:`w-28`,label:n(`smartRouting.rules.maxChars`),step:500,min:500,value:e.maxChars,onChange:e=>t({maxChars:e})})}),(0,L.jsx)(`div`,{className:`px-3 py-2`,children:(0,L.jsx)(f,{title:n(`smartRouting.rules.advanced`),children:(0,L.jsx)(B,{label:n(`smartRouting.rules.virtualModel`),detail:n(`smartRouting.rules.virtualModelHint`),children:(0,L.jsx)(d,{className:`w-56`,mono:!0,"aria-label":n(`smartRouting.rules.virtualModel`),value:e.virtualModel,onChange:e=>t({virtualModel:e.target.value})})})})})]})}function se(){let{t:e}=g();return(0,L.jsx)(F,{title:e(`nav.smartRouting`),subtitle:e(`smartRouting.subtitle`),children:(0,L.jsx)($,{})})}export{se as SmartRoutingPage};
@@ -0,0 +1 @@
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{$a as n,C as r,Ma as i,N as a,O as o,P as s,Ri as c,T as l,U as u,W as d,Za as f,_i as p,c as m,d as h,f as g,h as _,io as v,k as y,nc as b,o as x,yi as ee}from"./format-BmuJU1J1.js";import{D as te,E as ne,O as re,T as ie,U as ae,w as S}from"./TrayTitleSource-DleIYaE6.js";import{t as C}from"./arrow-left-DhPqlXf4.js";import{t as w}from"./scroll-text-DjXe21uH.js";import{A as T,G as E,H as D,W as O,_ as k,j as A,o as j,v as M}from"./index-CZ4Wdbud.js";import{a as N,n as P}from"./TokenPoolEditor-DzEkYZ9z.js";var F=e(t(),1),I=b();function L(){let{id:e=``}=E(),{t,locale:b}=l(),L=O(),[z,B]=(0,F.useState)(`7d`),V=n(e),oe=ee(),H=i(z,void 0,e),U=f(z,z===`today`?`hour`:`day`,`token`,void 0,e),W=v(z,void 0,20,e),G=p(z,e),K=c({token:e,page:1,pageSize:10},!1),q=N(),J=(0,I.jsx)(y,{variant:`glass`,icon:(0,I.jsx)(C,{className:`size-4`}),"aria-label":t(`common.back`),onClick:()=>L(`/tokens`)}),Y=t(`range.${z}`),se=(0,F.useMemo)(()=>te(ne(U.data??[],`requests`),re(z)).map(e=>({key:e.bucket,label:ie(e.bucket),axisLabel:S(e.bucket),value:Math.round(e.value)})),[U.data,z]),X=new Map((oe.data??[]).map(e=>[e.id,e.name])),Z=(G.data??[]).reduce((e,t)=>e+t.requests,0),ce=(G.data??[]).map(e=>({id:e.providerId,name:X.get(e.providerId)??e.name??e.providerId,requests:e.requests,share:Z?e.requests/Z:0,success:e.successRate,ttft:e.avgTtftMs??null,cost:e.costUsd,out:e.failoversOut,in:e.failoversIn})),le=[{key:`name`,label:t(`tokens.detail.provider`),sortable:!0},{key:`requests`,label:t(`overview.requests`),sortable:!0,numeric:!0,render:e=>g(e)},{key:`share`,label:t(`tokens.detail.share`),sortable:!0,numeric:!0,render:e=>m(e)},{key:`success`,label:t(`overview.successRate`),sortable:!0,numeric:!0,render:(e,t)=>t.requests?m(e):`—`},{key:`ttft`,label:t(`overview.avgTtft`),sortable:!0,numeric:!0,render:e=>x(e)},{key:`cost`,label:t(`overview.cost`),sortable:!0,numeric:!0,render:e=>_(e)},{key:`out`,label:t(`tokens.detail.failoversOut`),sortable:!0,numeric:!0},{key:`in`,label:t(`tokens.detail.failoversIn`),sortable:!0,numeric:!0}],ue=(W.data??[]).map(e=>({model:e.model,requests:e.requests,tokens:e.tokens,cost:e.costUsd})),de=[{key:`model`,label:t(`tokens.detail.model`),sortable:!0},{key:`requests`,label:t(`overview.requests`),sortable:!0,numeric:!0,render:e=>g(e)},{key:`tokens`,label:t(`overview.tokens`),sortable:!0,numeric:!0,render:e=>g(e,!0)},{key:`cost`,label:t(`overview.cost`),sortable:!0,numeric:!0,render:e=>_(e)}],fe=(K.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})),pe=[{key:`time`,label:t(`tokens.detail.time`),render:(e,t)=>h(t.r.startedAtUtc,b)},{key:`model`,label:t(`tokens.detail.model`)},{key:`provider`,label:t(`tokens.detail.provider`)},{key:`status`,label:t(`tokens.detail.status`),render:e=>(0,I.jsx)(o,{tone:e===`success`?`green`:`red`,children:t(`status.${e}`)})},{key:`cost`,label:t(`overview.cost`),numeric:!0,render:e=>_(e)}];if(V.isError)return(0,I.jsx)(M,{title:t(`nav.tokens`),leading:J,children:(0,I.jsx)(r,{tone:`danger`,title:t(`common.error`),children:ae(V.error)})});let Q=V.data,$=H.data;return(0,I.jsx)(M,{title:Q?.name??``,subtitle:Q?(0,I.jsx)(`code`,{className:`font-mono`,children:Q.keyMasked}):void 0,leading:J,actions:(0,I.jsx)(D,{to:`/requests?token=${encodeURIComponent(e)}`,children:(0,I.jsx)(y,{icon:(0,I.jsx)(w,{className:`size-3.5`}),children:t(`tokens.detail.viewLogs`)})}),children:(0,I.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(u,{ariaLabel:t(`overview.range`),value:z,onChange:B,items:[`today`,`7d`,`30d`,`90d`].map(e=>({value:e,label:t(`range.${e}`)}))})}),$?(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-3 xl:grid-cols-5`,children:[(0,I.jsx)(R,{label:t(`overview.totalCost`),value:_($.costUsd),context:Y}),(0,I.jsx)(R,{label:t(`overview.totalRequests`),value:g($.requests),context:Y}),(0,I.jsx)(R,{label:t(`overview.tokens`),value:g($.inputTokens+$.outputTokens,!0),context:t(`overview.tokensContext`,{input:g($.inputTokens,!0),output:g($.outputTokens,!0)})}),(0,I.jsx)(R,{label:t(`usage.hitRate`),value:m(k($.cacheReadTokens,$.inputTokens)??0),context:Y}),(0,I.jsx)(R,{label:t(`overview.successRate`),value:$.requests?m($.successRate):`—`,context:x($.avgTtftMs)})]}):(0,I.jsx)(d,{lines:3}),Q?.pool&&(0,I.jsxs)(`section`,{className:`card p-5`,children:[(0,I.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[t(`tokens.pool.title`),` · `,t(`tokens.strategy.${Q.pool.strategy}`)]}),(0,I.jsx)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2 text-[13px]`,children:Q.pool.members.map(e=>(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,I.jsx)(a,{tone:P(e.health.state)}),X.get(e.providerId)??e.providerId,(0,I.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:q(e.health)})]},e.providerId))})]}),$&&$.requests===0?(0,I.jsx)(`div`,{className:`card`,children:(0,I.jsx)(s,{title:t(`overview.tokenEmpty.title`,{token:Q?.name??``}),detail:t(`overview.tokenEmpty.detail`,{range:Y})})}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`section`,{className:`card p-5`,children:[(0,I.jsxs)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:[t(`overview.usageTrend`),` · `,Y]}),U.isLoading?(0,I.jsx)(d,{lines:4}):(0,I.jsx)(A,{data:se,label:t(`overview.requests`),period:Y,height:160,formatValue:e=>g(e),averageLabel:t(z===`today`?`overview.hourlyAverage`:`overview.dailyAverage`),valueLabel:t(`overview.total`),categoryLabel:t(z===`today`?`overview.hour`:`overview.day`)})]}),(0,I.jsxs)(`section`,{className:`card p-5`,children:[(0,I.jsx)(`h2`,{className:`mb-1 text-[13px] font-medium`,children:t(`tokens.detail.byProvider`)}),(0,I.jsx)(`p`,{className:`mb-3 text-[12px] text-[var(--text-muted)]`,children:t(`tokens.detail.byProviderHint`)}),(0,I.jsx)(T,{caption:t(`tokens.detail.byProvider`),rows:ce,columns:le,rowKey:`id`,emptyMessage:t(`common.noData`)})]}),(0,I.jsxs)(`section`,{className:`card p-5`,children:[(0,I.jsx)(`h2`,{className:`mb-3 text-[13px] font-medium`,children:t(`tokens.detail.byModel`)}),(0,I.jsx)(T,{caption:t(`tokens.detail.byModel`),rows:ue,columns:de,rowKey:`model`,emptyMessage:t(`common.noData`)})]})]}),(0,I.jsxs)(`section`,{className:`card p-5`,children:[(0,I.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,I.jsx)(`h2`,{className:`text-[13px] font-medium`,children:t(`tokens.detail.recent`)}),(0,I.jsx)(D,{className:`text-[12px] text-[var(--accent)]`,to:`/requests?token=${encodeURIComponent(e)}`,children:t(`tokens.detail.viewLogs`)})]}),(0,I.jsx)(T,{caption:t(`tokens.detail.recent`),rows:fe,columns:pe,rowKey:`id`,emptyMessage:t(`common.noData`)})]}),(0,I.jsx)(j,{name:`token.detail.sections`,params:{tokenId:e}})]})})}function R({label:e,value:t,context:n}){return(0,I.jsxs)(`article`,{className:`card min-w-0 px-4 py-3`,children:[(0,I.jsx)(`div`,{className:`truncate text-[12px] text-[var(--text-secondary)]`,children:e}),(0,I.jsx)(`div`,{className:`num mt-1 truncate text-[22px] leading-tight font-semibold selectable`,title:t,children:t}),(0,I.jsx)(`div`,{className:`mt-1 truncate text-[11px] text-[var(--text-muted)]`,title:n,children:n})]})}export{L as TokenDetailPage};
@@ -1 +1 @@
1
- import{G as e,O as t,T as n,U as r,d as i,ec as a,fi as o,ft as s,k as c,z as l}from"./format-DFMHYFFs.js";import{V as u}from"./TrayTitleSource-DPgZ1gwk.js";import{t as d}from"./grip-vertical-DFI2_ajd.js";import{t as f}from"./trash-BHBJn5GS.js";import{a as p,c as m,d as h,f as g,i as _,l as v,n as y,o as b,r as x,s as S,t as C,u as w}from"./sortable.esm-DTOfU4E0.js";import{w as T}from"./index-Dd8H-gQl.js";var E=a(),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:e,locale:t}=n();return n=>n.state===`cooling`||n.state===`open`?e(`tokens.health.${n.state}`,{time:n.until?i(n.until,t):`—`}):e(`tokens.health.${n.state}`)}function F({draft:t,onChange:i,providers:a,health:o}){let{t:s}=n(),c=new Map(a.map(e=>[e.id,e])),d=t.members.length>1,f=h(w(m,{activationConstraint:{distance:4}}),w(S,{coordinateGetter:x})),g=e=>i({...t,members:e}),_=(e,n)=>g(t.members.map((t,r)=>r===e?{...t,...n}:t)),T=({active:e,over:n})=>{if(!n||e.id===n.id)return;let r=t.members.findIndex(t=>t.providerId===e.id),i=t.members.findIndex(e=>e.providerId===n.id);r>=0&&i>=0&&g(y(t.members,r,i))},O=a.filter(e=>e.enabled&&!t.members.some(t=>t.providerId===e.id)),k=A(t),M=t.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:[d&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsx)(r,{ariaLabel:s(`tokens.pool.strategy`),value:t.strategy,onChange:e=>i({...t,strategy:e}),items:D.map(e=>({value:e,label:s(`tokens.strategy.${e}`)}))}),(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:s(`tokens.strategy.${t.strategy}.hint`)})]}),t.members.length===0?(0,E.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:s(`tokens.pool.empty`)}):(0,E.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,E.jsx)(b,{sensors:f,collisionDetection:v,onDragEnd:T,children:(0,E.jsx)(C,{items:t.members.map(e=>e.providerId),strategy:p,children:t.members.map((e,n)=>(0,E.jsx)(I,{member:e,index:n,draft:t,provider:c.get(e.providerId),health:o?.get(e.providerId),onChange:e=>_(n,e),onRemove:()=>g(t.members.filter((e,t)=>t!==n))},e.providerId))})})}),O.length>0&&(0,E.jsx)(u,{ariaLabel:s(`tokens.pool.add`),placeholder:s(`tokens.pool.add`),value:null,onChange:e=>g([...t.members,{providerId:e,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:s(`tokens.pool.noModels`,{providers:M.join(`, `)})}),d&&(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:s(`tokens.pool.share`)}),(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:s(`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:t.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:t.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:s(`tokens.pool.standby`)})]},e.providerId))})]}),d&&(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:s(`tokens.pool.sticky`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:s(`tokens.pool.stickyHint`)})]}),(0,E.jsx)(e,{label:s(`tokens.pool.sticky`),checked:t.sticky===`session`,onChange:e=>i({...t,sticky:e?`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:s(`tokens.pool.failover`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:s(`tokens.pool.failoverHint`)})]}),(0,E.jsx)(e,{label:s(`tokens.pool.failover`),checked:t.failover,onChange:e=>i({...t,failover:e})})]}),t.failover&&(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{children:s(`tokens.pool.maxAttempts`)}),(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(l,{label:s(`tokens.pool.maxAttempts`),value:t.maxAttempts,min:1,step:1,onChange:e=>i({...t,maxAttempts:e??1})})})]})]})]})}function I({member:e,index:r,draft:i,provider:a,health:p,onChange:m,onRemove:h}){let{t:v}=n(),y=P(),{attributes:b,listeners:x,setNodeRef:S,setActivatorNodeRef:C,transform:w,transition:D,isDragging:O}=_({id:e.providerId}),k=!!a&&M.has(a.authScheme),A=o(a?.id,k),j=a?.name??e.providerId,F=i.members.length>1,I=a?a.enabled?p:{state:`disabled`}:{state:`missing`};return(0,E.jsxs)(`div`,{ref:S,style:{transform:g.Transform.toString(w),transition:D},className:s(`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:C,type:`button`,"aria-label":v(`clients.dragToReorder`,{provider:j}),title:v(`clients.dragToReorder`,{provider:j}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...b,...x,children:(0,E.jsx)(d,{className:`size-4`})}),a&&(0,E.jsx)(T,{name:a.name,icon:a.icon,colorKey:a.templateId,size:20}),(0,E.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:j}),F&&i.strategy===`failover`&&(0,E.jsx)(t,{tone:r===0?`accent`:`neutral`,children:r===0?v(`tokens.pool.primary`):v(`tokens.pool.backup`,{n:r})}),I&&(0,E.jsx)(t,{tone:N(I.state),children:y(I)})]}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[F&&(i.strategy===`weighted`||i.strategy===`tiered`)&&(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(l,{label:v(`tokens.pool.weight`),placeholder:v(`tokens.pool.weight`),value:e.weight,min:1,step:1,onChange:e=>m({weight:e??1})})}),F&&i.strategy===`tiered`&&(0,E.jsx)(u,{ariaLabel:v(`tokens.pool.tier`),value:String(e.tier),onChange:e=>m({tier:Number(e)}),options:[`1`,`2`,`3`].map(e=>({value:e,label:v(`tokens.pool.tierN`,{n:e})}))}),k&&(0,E.jsx)(u,{ariaLabel:v(`tokens.directAccount`),value:e.accountId??``,onChange:e=>m({accountId:e||null}),options:[{value:``,label:v(`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)(f,{className:`size-3.5`}),"aria-label":v(`tokens.pool.remove`,{provider:j}),title:v(`tokens.pool.remove`,{provider:j}),onClick:h})]})]})}export{P as a,k as i,N as n,O as r,F as t};
1
+ import{G as e,O as t,T as n,U as r,d as i,ft as a,k as o,mi as s,nc as c,z as l}from"./format-BmuJU1J1.js";import{V as u}from"./TrayTitleSource-DleIYaE6.js";import{t as d}from"./grip-vertical-DFI2_ajd.js";import{t as f}from"./trash-BHBJn5GS.js";import{a as p,c as m,d as h,f as g,i as _,l as v,n as y,o as b,r as x,s as S,t as C,u as w}from"./sortable.esm-CJQ90KMg.js";import{w as T}from"./index-CZ4Wdbud.js";var E=c(),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:e,locale:t}=n();return n=>n.state===`cooling`||n.state===`open`?e(`tokens.health.${n.state}`,{time:n.until?i(n.until,t):`—`}):e(`tokens.health.${n.state}`)}function F({draft:t,onChange:i,providers:a,health:o}){let{t:s}=n(),c=new Map(a.map(e=>[e.id,e])),d=t.members.length>1,f=h(w(m,{activationConstraint:{distance:4}}),w(S,{coordinateGetter:x})),g=e=>i({...t,members:e}),_=(e,n)=>g(t.members.map((t,r)=>r===e?{...t,...n}:t)),T=({active:e,over:n})=>{if(!n||e.id===n.id)return;let r=t.members.findIndex(t=>t.providerId===e.id),i=t.members.findIndex(e=>e.providerId===n.id);r>=0&&i>=0&&g(y(t.members,r,i))},O=a.filter(e=>e.enabled&&!t.members.some(t=>t.providerId===e.id)),k=A(t),M=t.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:[d&&(0,E.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,E.jsx)(r,{ariaLabel:s(`tokens.pool.strategy`),value:t.strategy,onChange:e=>i({...t,strategy:e}),items:D.map(e=>({value:e,label:s(`tokens.strategy.${e}`)}))}),(0,E.jsx)(`p`,{className:`text-[12px] text-[var(--text-secondary)]`,children:s(`tokens.strategy.${t.strategy}.hint`)})]}),t.members.length===0?(0,E.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:s(`tokens.pool.empty`)}):(0,E.jsx)(`div`,{className:`overflow-hidden rounded-[var(--radius-control)] border border-[var(--border-subtle)]`,children:(0,E.jsx)(b,{sensors:f,collisionDetection:v,onDragEnd:T,children:(0,E.jsx)(C,{items:t.members.map(e=>e.providerId),strategy:p,children:t.members.map((e,n)=>(0,E.jsx)(I,{member:e,index:n,draft:t,provider:c.get(e.providerId),health:o?.get(e.providerId),onChange:e=>_(n,e),onRemove:()=>g(t.members.filter((e,t)=>t!==n))},e.providerId))})})}),O.length>0&&(0,E.jsx)(u,{ariaLabel:s(`tokens.pool.add`),placeholder:s(`tokens.pool.add`),value:null,onChange:e=>g([...t.members,{providerId:e,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:s(`tokens.pool.noModels`,{providers:M.join(`, `)})}),d&&(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:s(`tokens.pool.share`)}),(0,E.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:s(`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:t.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:t.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:s(`tokens.pool.standby`)})]},e.providerId))})]}),d&&(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:s(`tokens.pool.sticky`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:s(`tokens.pool.stickyHint`)})]}),(0,E.jsx)(e,{label:s(`tokens.pool.sticky`),checked:t.sticky===`session`,onChange:e=>i({...t,sticky:e?`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:s(`tokens.pool.failover`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:s(`tokens.pool.failoverHint`)})]}),(0,E.jsx)(e,{label:s(`tokens.pool.failover`),checked:t.failover,onChange:e=>i({...t,failover:e})})]}),t.failover&&(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{children:s(`tokens.pool.maxAttempts`)}),(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(l,{label:s(`tokens.pool.maxAttempts`),value:t.maxAttempts,min:1,step:1,onChange:e=>i({...t,maxAttempts:e??1})})})]})]})]})}function I({member:e,index:r,draft:i,provider:c,health:p,onChange:m,onRemove:h}){let{t:v}=n(),y=P(),{attributes:b,listeners:x,setNodeRef:S,setActivatorNodeRef:C,transform:w,transition:D,isDragging:O}=_({id:e.providerId}),k=!!c&&M.has(c.authScheme),A=s(c?.id,k),j=c?.name??e.providerId,F=i.members.length>1,I=c?c.enabled?p:{state:`disabled`}:{state:`missing`};return(0,E.jsxs)(`div`,{ref:S,style:{transform:g.Transform.toString(w),transition:D},className:a(`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:C,type:`button`,"aria-label":v(`clients.dragToReorder`,{provider:j}),title:v(`clients.dragToReorder`,{provider:j}),className:`inline-flex cursor-grab touch-none text-[var(--text-muted)] hover:text-[var(--text-secondary)] active:cursor-grabbing`,...b,...x,children:(0,E.jsx)(d,{className:`size-4`})}),c&&(0,E.jsx)(T,{name:c.name,icon:c.icon,colorKey:c.templateId,size:20}),(0,E.jsx)(`span`,{className:`truncate text-[13px] font-medium`,children:j}),F&&i.strategy===`failover`&&(0,E.jsx)(t,{tone:r===0?`accent`:`neutral`,children:r===0?v(`tokens.pool.primary`):v(`tokens.pool.backup`,{n:r})}),I&&(0,E.jsx)(t,{tone:N(I.state),children:y(I)})]}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[F&&(i.strategy===`weighted`||i.strategy===`tiered`)&&(0,E.jsx)(`div`,{className:`w-20`,children:(0,E.jsx)(l,{label:v(`tokens.pool.weight`),placeholder:v(`tokens.pool.weight`),value:e.weight,min:1,step:1,onChange:e=>m({weight:e??1})})}),F&&i.strategy===`tiered`&&(0,E.jsx)(u,{ariaLabel:v(`tokens.pool.tier`),value:String(e.tier),onChange:e=>m({tier:Number(e)}),options:[`1`,`2`,`3`].map(e=>({value:e,label:v(`tokens.pool.tierN`,{n:e})}))}),k&&(0,E.jsx)(u,{ariaLabel:v(`tokens.directAccount`),value:e.accountId??``,onChange:e=>m({accountId:e||null}),options:[{value:``,label:v(`clients.accountDefault`)},...(A.data??[]).map(e=>({value:e.id,label:e.displayName||e.id}))]}),(0,E.jsx)(o,{size:`sm`,variant:`plain`,icon:(0,E.jsx)(f,{className:`size-3.5`}),"aria-label":v(`tokens.pool.remove`,{provider:j}),title:v(`tokens.pool.remove`,{provider:j}),onClick:h})]})]})}export{P as a,k as i,N as n,O as r,F as t};
@@ -0,0 +1 @@
1
+ import{o as e,r as t}from"./createLucideIcon-7fjTeqBK.js";import{C as n,Cn as r,F as i,Ji as a,L as o,Mo as s,N as c,O as l,P as u,T as d,U as f,Un as p,Vi as m,W as h,Yi as g,c as _,d as v,eo as y,f as b,h as x,k as S,kr as ee,l as C,mt as w,nc as T,p as E,r as D,to as O,uo as k,va as A,vt as j,wn as M,yi as N,yt as P,z as F}from"./format-BmuJU1J1.js";import{B as te,H as I,R as L,U as R,V as z,W as B}from"./TrayTitleSource-DleIYaE6.js";import{t as ne}from"./chart-column-TQVFilUc.js";import{t as re}from"./chevron-right-Bgtn3ze-.js";import{t as ie}from"./copy-48gwhhDO.js";import{t as ae}from"./ellipsis-CidyZaW2.js";import{t as V}from"./key-round-m9ps8ZDi.js";import{t as H}from"./link-2-BtBtZbXv.js";import{t as oe}from"./pencil-CpF9MxGZ.js";import{t as U}from"./plus-c3HzV6VX.js";import{t as se}from"./power-BZC18Gj2.js";import{t as ce}from"./rotate-ccw-fsXoCwyv.js";import{t as le}from"./scroll-text-DjXe21uH.js";import{t as ue}from"./square-terminal-pyhtjn4S.js";import{t as W}from"./trash-BHBJn5GS.js";import{t as de}from"./user-plus-Bsk_v4UF.js";import{H as G,S as K,a as fe,b as q,u as J,v as Y}from"./index-CZ4Wdbud.js";import{a as pe,i as me,n as X,r as he,t as ge}from"./TokenPoolEditor-DzEkYZ9z.js";var Z=e(t(),1),Q=T(),_e=[15,60,1440];function ve({token:e,open:t,onOpenChange:n}){let{t:r,locale:i}=d(),{toast:a}=B(),[o,s]=(0,Z.useState)(15),[c,u]=(0,Z.useState)(null),p=y(e.id,t),m=M(e.id),h=g(e.id),_=e=>e<60?r(`tokens.invite.minutes`,{n:e}):r(`tokens.invite.hours`,{n:e/60}),v=()=>m.mutate(o,{onSuccess:async e=>{u(e.link),a(await L.copy(e.link)?r(`tokens.invite.copied`):r(`tokens.copyFailed`),`success`)},onError:e=>a(R(e),`error`)}),b=e=>e===`pending`?`accent`:e===`used`?`green`:`neutral`;return(0,Q.jsx)(I,{open:t,onOpenChange:e=>{e||u(null),n(e)},title:r(`tokens.invite.title`,{name:e.name}),description:r(`tokens.invite.description`),footer:(0,Q.jsx)(S,{variant:`primary`,icon:(0,Q.jsx)(H,{className:`size-3.5`}),loading:m.isPending,onClick:v,children:r(`tokens.invite.generate`)}),children:(0,Q.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`tokens.invite.lifetime`)}),(0,Q.jsx)(f,{items:_e.map(e=>({value:String(e),label:_(e)})),value:String(o),onChange:e=>s(Number(e)),ariaLabel:r(`tokens.invite.lifetime`)})]}),c&&(0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`tokens.invite.linkOnce`)}),(0,Q.jsx)(`code`,{className:`selectable break-all rounded-lg bg-[var(--surface-muted)] px-3 py-2 font-mono text-[11.5px]`,children:c})]}),(0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-secondary)]`,children:r(`tokens.invite.recent`)}),(p.data??[]).length===0?(0,Q.jsx)(`p`,{className:`text-[12px] text-[var(--text-muted)]`,children:r(`tokens.invite.none`)}):(0,Q.jsx)(`ul`,{className:`grid gap-1.5`,children:(p.data??[]).map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2 rounded-lg border border-[var(--border)] px-3 py-2 text-[12px]`,children:[(0,Q.jsx)(l,{tone:b(e.status),children:r(`tokens.invite.status.${e.status}`)}),(0,Q.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:e.status===`used`?r(`tokens.invite.usedAt`,{time:D(e.usedAt,i),ip:e.usedIp??`—`}):r(`tokens.invite.expires`,{time:D(e.expiresAt,i)})}),e.status===`pending`&&(0,Q.jsx)(S,{size:`sm`,variant:`plain`,className:`ml-auto`,loading:h.isPending&&h.variables===e.id,onClick:()=>h.mutate(e.id,{onError:e=>a(R(e),`error`)}),children:r(`tokens.invite.revoke`)})]},e.id))})]})]})})}function ye(){let{t:e}=d(),t=O(),r=A(),i=k(),a=i.data?.state===`connected`?i.data.publicUrl:null,[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null);return(0,Q.jsxs)(Y,{title:e(`nav.tokens`),subtitle:e(`tokens.subtitle`),actions:(0,Q.jsx)(S,{variant:`primary`,icon:(0,Q.jsx)(U,{className:`size-3.5`}),onClick:()=>s(!0),children:e(`tokens.add`)}),children:[(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-[1100px] flex-col gap-4`,children:[r.data&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 px-1 text-[12px] text-[var(--text-secondary)]`,children:[(0,Q.jsx)(`p`,{children:e(`tokens.directHint`,{url:`${r.data.gatewayBaseUrl}/v1`})}),(0,Q.jsx)(`p`,{className:`selectable`,children:e(`tokens.selfServiceHint`,{url:r.data.gatewayBaseUrl})}),a&&(0,Q.jsx)(`p`,{className:`selectable text-[var(--accent)]`,children:e(`tokens.remoteHint`,{url:`${a}/v1`,key:`${a}/key`})})]}),t.isLoading&&(0,Q.jsx)(h,{lines:4}),t.isError&&(0,Q.jsx)(n,{tone:`danger`,title:e(`common.error`),children:R(t.error)}),t.data?.length===0&&(0,Q.jsx)(`div`,{className:`card`,children:(0,Q.jsx)(u,{icon:(0,Q.jsx)(V,{className:`size-6`}),title:e(`tokens.empty`)})}),t.data&&t.data.length>0&&(0,Q.jsx)(`div`,{className:`card divide-y divide-[var(--border-subtle)] overflow-hidden p-0`,children:t.data.map(e=>(0,Q.jsx)(be,{token:e,defaultOpen:t.data.length===1,onEdit:()=>l(e)},e.id))})]}),(0,Q.jsx)(Te,{open:o,onOpenChange:s}),(0,Q.jsx)(Ee,{token:c,onClose:()=>l(null)})]})}function be({token:e,defaultOpen:t,onEdit:n}){let{t:r,locale:i}=d(),{toast:o,confirm:u}=B(),f=N(),h=A(),g=a(),_=s(),y=m(),ee=p(),[C,w]=(0,Z.useState)(t),T=fe(`token.row`,{tokenId:e.id}),E=(f.data??[]).find(t=>t.id===e.providerId),O=pe(),k=`token-detail-${e.id}`,j=(e,t)=>{o(t,`success`),e.skipped.length>0&&o(r(`tokens.skipped`,{clients:e.skipped.map(e=>q[e]?.name??e).join(`, `)}),`error`)},M=()=>g.mutate(e.id,{onSuccess:async({token:e})=>{await L.copy(e)?o(r(`tokens.copied`)):o(r(`tokens.copyFailed`),`error`)},onError:e=>o(R(e),`error`)}),[P,F]=(0,Z.useState)(!1),I=async()=>{let e=h.data?.gatewayBaseUrl;e&&(await L.copy(`${e}/v1`)?o(r(`tokens.urlCopied`)):o(r(`tokens.copyFailed`),`error`))},z=async()=>{let e=h.data?.gatewayBaseUrl;e&&(await L.copy(`npx @aidotnet/astra-connect join ${e}`)?o(r(`tokens.joinCopied`)):o(r(`tokens.copyFailed`),`error`))},V=async()=>{(!e.enabled||await u({title:r(`tokens.disableConfirm`,{name:e.name}),detail:r(`tokens.disableDetail`),confirmLabel:r(`tokens.disable`),destructive:!0}))&&_.mutate({id:e.id,enabled:!e.enabled},{onError:e=>o(R(e),`error`)})},U=async()=>{await u({title:r(`tokens.resetConfirm`,{name:e.name}),detail:r(`tokens.resetDetail`),confirmLabel:r(`tokens.reset`),destructive:!0})&&y.mutate(e.id,{onSuccess:e=>j(e,r(`tokens.resetDone`,{count:e.rewritten.length})),onError:e=>o(R(e),`error`)})},J=async()=>{await u({title:r(`tokens.deleteConfirm`,{name:e.name}),detail:r(`tokens.deleteDetail`),confirmLabel:r(`common.delete`),destructive:!0})&&ee.mutate(e.id,{onSuccess:t=>j(t,r(`tokens.deleted`,{name:e.name})),onError:e=>o(R(e),`error`)})},Y=e.lastUsedAt?D(e.lastUsedAt,i):r(`tokens.neverUsed`);return(0,Q.jsxs)(`article`,{children:[(0,Q.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:()=>w(e=>!e),children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-start gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`mt-0.5 rounded text-[var(--text-muted)]`,"aria-expanded":C,"aria-controls":k,"aria-label":r(`tokens.details`),onClick:e=>{e.stopPropagation(),w(e=>!e)},children:(0,Q.jsx)(re,{className:`size-4 transition-transform ${C?`rotate-90`:``}`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`h2`,{className:`truncate text-[14px] font-medium ${e.enabled?``:`text-[var(--text-muted)]`}`,children:e.name}),e.isDefault&&(0,Q.jsx)(l,{tone:`accent`,children:r(`tokens.default`)}),!e.enabled&&(0,Q.jsx)(l,{tone:`orange`,children:r(`tokens.disabledBadge`)}),e.limitUsage.some(e=>e.exhausted)&&(0,Q.jsx)(l,{tone:`orange`,children:r(`tokens.limitExhausted`)}),e.pool&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:e.pool.members.map(e=>e.providerId).join(`, `),children:[(0,Q.jsx)(l,{children:r(`tokens.pool.summary`,{count:e.pool.members.length,strategy:r(`tokens.strategy.${e.pool.strategy}`)})}),e.pool.members.map(e=>(0,Q.jsx)(c,{tone:X(e.health.state)},e.providerId))]})]}),(0,Q.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--text-secondary)] selectable`,children:e.keyMasked}),(0,Q.jsx)(S,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(ie,{className:`size-3.5`}),"aria-label":r(`tokens.copy`),title:r(`tokens.copy`),loading:g.isPending,onClick:M}),(0,Q.jsx)(S,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(H,{className:`size-3.5`}),"aria-label":r(`tokens.copyUrl`),title:r(`tokens.copyUrl`),disabled:!h.data,onClick:()=>void I()}),(0,Q.jsx)(S,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(ue,{className:`size-3.5`}),"aria-label":r(`tokens.copyJoin`),title:r(`tokens.copyJoin`),disabled:!h.data,onClick:()=>void z()}),(0,Q.jsx)(S,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(de,{className:`size-3.5`}),"aria-label":r(`tokens.invite.open`),title:r(`tokens.invite.open`),disabled:!e.enabled,onClick:()=>F(!0)}),(0,Q.jsx)(ve,{token:e,open:P,onOpenChange:F})]})]})]}),(0,Q.jsx)(`div`,{className:`hidden w-16 items-center gap-1.5 md:flex`,title:e.clients.map(e=>q[e]?.name??e).join(`, `)||r(`tokens.noClients`),children:e.clients.length===0?(0,Q.jsx)(`span`,{className:`text-[12px] text-[var(--text-muted)]`,children:`—`}):e.clients.map(e=>(0,Q.jsx)(K,{kind:e,size:16},e))}),(0,Q.jsx)($,{label:r(`tokens.today`),value:x(e.today.costUsd),context:r(`tokens.requestsContext`,{count:b(e.today.requests)})}),(0,Q.jsx)($,{label:r(`tokens.total`),value:x(e.total.costUsd),context:`${b(e.total.totalTokens,!0)} Token`}),(0,Q.jsx)($,{label:r(`tokens.lastUsedTitle`),value:e.lastUsedAt?v(e.lastUsedAt,i):`—`,context:e.lastUsedAt?``:r(`tokens.neverUsed`),title:Y}),(0,Q.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(te,{label:r(`common.more`),icon:(0,Q.jsx)(ae,{className:`size-4`}),items:[{id:`settings`,label:r(`tokens.settings`),icon:(0,Q.jsx)(oe,{className:`size-3.5`}),onSelect:n},{id:`toggle`,label:e.enabled?r(`tokens.disable`):r(`tokens.enable`),icon:(0,Q.jsx)(se,{className:`size-3.5`}),onSelect:()=>void V()},{id:`reset`,label:r(`tokens.reset`),icon:(0,Q.jsx)(ce,{className:`size-3.5`}),onSelect:()=>void U()},...T,...e.isDefault?[]:[{id:`delete`,label:r(`tokens.delete`),icon:(0,Q.jsx)(W,{className:`size-3.5`}),destructive:!0,separatorBefore:!0,onSelect:()=>void J()}]]})})]}),C&&(0,Q.jsxs)(`div`,{id:k,className:`border-t border-[var(--border-subtle)] bg-[var(--surface-muted)] px-4 py-3 md:pl-10`,children:[(0,Q.jsxs)(`dl`,{className:`flex flex-wrap gap-x-8 gap-y-2 text-[12px]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:r(`tokens.clients`)}),(0,Q.jsx)(`dd`,{className:`mt-0.5 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.clients.length===0?r(`tokens.noClients`):e.clients.map(e=>(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Q.jsx)(K,{kind:e,size:14}),q[e]?.name??e]},e))})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:e.pool?r(`tokens.pool.title`):r(`tokens.directProvider`)}),e.pool?(0,Q.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[var(--text-secondary)]`,children:e.pool.members.map(e=>(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,title:O(e.health),children:[(0,Q.jsx)(c,{tone:X(e.health.state)}),(f.data??[]).find(t=>t.id===e.providerId)?.name??e.providerId]},e.providerId))}):(0,Q.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:E?.name??(e.providerId?e.providerId:r(`tokens.directNone`))})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:r(`tokens.allowedClients`)}),(0,Q.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:e.allowedClients==null?r(`tokens.allowedClientsAny`):e.allowedClients.length===0?r(`tokens.directOnly`):e.allowedClients.map(e=>q[e]?.name??e).join(`, `)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[var(--text-muted)]`,children:r(`tokens.lastUsedTitle`)}),(0,Q.jsx)(`dd`,{className:`mt-0.5 truncate text-[var(--text-secondary)]`,children:Y})]})]}),(0,Q.jsx)(xe,{token:e}),(0,Q.jsx)(Ce,{today:e.today,total:e.total}),(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,Q.jsx)(G,{to:`/tokens/${encodeURIComponent(e.id)}`,children:(0,Q.jsx)(S,{size:`sm`,icon:(0,Q.jsx)(ne,{className:`size-3.5`}),children:r(`tokens.detail.open`)})}),(0,Q.jsx)(G,{to:`/requests?token=${encodeURIComponent(e.id)}`,children:(0,Q.jsx)(S,{size:`sm`,icon:(0,Q.jsx)(le,{className:`size-3.5`}),children:r(`tokens.detail.viewLogs`)})})]})]})]})}function xe({token:e}){let{t}=d(),n=e.limits?.rpm;return(0,Q.jsxs)(`div`,{className:`mt-3`,children:[(0,Q.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:t(`tokens.limits`)}),e.limitUsage.length===0&&n==null?(0,Q.jsx)(`div`,{className:`mt-0.5 text-[12px] text-[var(--text-secondary)]`,children:t(`tokens.unlimited`)}):(0,Q.jsxs)(`div`,{className:`mt-1.5 grid gap-3 sm:grid-cols-2`,children:[e.limitUsage.map(e=>(0,Q.jsx)(Se,{usage:e},`${e.metric}:${e.period}`)),n!=null&&(0,Q.jsxs)(`div`,{className:`text-[11.5px] text-[var(--text-secondary)]`,children:[t(`tokens.rpm`),` · `,(0,Q.jsx)(`span`,{className:`num`,children:t(`tokens.rpmUsage`,{used:e.recentRequests,limit:n})})]})]})]})}function Se({usage:e}){let{t,locale:n}=d(),r=`${t(`tokens.period.${e.period}`)} · ${t(`tokens.metric.${e.metric}`)}`,i=t=>e.metric===`cost`?x(t):b(t,!0),a=Math.max(0,Math.min(100,Math.round(e.usedPercent))),o=a>=90?`var(--danger)`:a>=70?`var(--warning)`:`var(--accent)`;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2 text-[11.5px]`,children:[(0,Q.jsx)(`span`,{className:`text-[var(--text-secondary)]`,children:r}),(0,Q.jsx)(`span`,{className:`num`,children:t(`tokens.limitUsed`,{used:i(e.used),limit:i(e.limit)})})]}),(0,Q.jsx)(`div`,{role:`progressbar`,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":r,className:`h-1.5 w-full overflow-hidden rounded-full bg-[var(--surface)]`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full`,style:{width:`${a}%`,background:o}})}),e.resetsAt&&(0,Q.jsx)(`div`,{className:`mt-1 text-[10.5px] text-[var(--text-muted)]`,children:t(`tokens.limitResets`,{time:D(e.resetsAt,n)})})]})}function $({label:e,value:t,context:n,title:r}){return(0,Q.jsxs)(`div`,{className:`w-24 min-w-0`,title:r,children:[(0,Q.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:e}),(0,Q.jsx)(`div`,{className:`num truncate text-[14px] leading-tight font-semibold`,children:t}),(0,Q.jsx)(`div`,{className:`truncate text-[11px] text-[var(--text-muted)]`,children:n||`\xA0`})]})}function Ce({today:e,total:t}){let{t:n}=d(),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,Q.jsx)(`div`,{className:`mt-3 overflow-x-auto rounded-[var(--radius-control)] bg-[var(--surface)]`,children:(0,Q.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`border-b border-[var(--border-subtle)]`,children:[(0,Q.jsx)(`th`,{className:`${i} text-left`}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.cost`)}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.requests`)}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.tokens`)}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.inOut`)}),(0,Q.jsx)(`th`,{className:i,children:n(`tokens.cacheHit`)}),(0,Q.jsx)(`th`,{className:i,title:n(`tokens.tpsContext`),children:n(`tokens.tps`)})]})}),(0,Q.jsx)(`tbody`,{children:r.map(([e,t])=>(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-medium whitespace-nowrap text-[var(--text-secondary)]`,children:e}),(0,Q.jsx)(`td`,{className:`${a} font-semibold selectable`,children:x(t.costUsd)}),(0,Q.jsx)(`td`,{className:a,children:b(t.requests)}),(0,Q.jsx)(`td`,{className:a,children:b(t.totalTokens,!0)}),(0,Q.jsxs)(`td`,{className:`${a} text-[var(--text-secondary)]`,children:[b(t.inputTokens,!0),` / `,b(t.outputTokens,!0)]}),(0,Q.jsx)(`td`,{className:a,title:n(`usage.cacheAmounts`,{read:b(t.cacheReadTokens,!0),write:b(t.cacheWriteTokens,!0)}),children:t.cacheHitRate==null?`—`:_(t.cacheHitRate)}),(0,Q.jsx)(`td`,{className:a,children:t.tps==null?`—`:E(t.tps)})]},e))})]})})}function we(){let{t:e}=d(),t=(N().data??[]).filter(e=>e.enabled);return{providers:t,options:[{value:``,label:e(`tokens.directNone`)},...t.map(e=>({value:e.id,label:e.name}))]}}function Te({open:e,onOpenChange:t}){let{t:n}=d(),{toast:a}=B(),s=r(),{options:c}=we(),[l,u]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``);return(0,Z.useEffect)(()=>{e&&(u(``),p(``))},[e]),(0,Q.jsx)(I,{open:e,onOpenChange:t,title:n(`tokens.createTitle`),footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(S,{onClick:()=>t(!1),children:n(`common.cancel`)}),(0,Q.jsx)(S,{variant:`primary`,disabled:!l.trim(),loading:s.isPending,onClick:()=>s.mutate({name:l.trim(),providerId:f||null},{onSuccess:e=>{t(!1),a(n(`tokens.created`,{name:e.name}),`success`)},onError:e=>a(R(e),`error`)}),children:n(`common.create`)})]}),children:(0,Q.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Q.jsx)(i,{label:n(`tokens.name`),children:(0,Q.jsx)(o,{value:l,maxLength:64,placeholder:n(`tokens.namePlaceholder`),onChange:e=>u(e.target.value)})}),(0,Q.jsx)(i,{label:n(`tokens.directProvider`),children:(0,Q.jsx)(z,{value:f,onChange:p,options:c})})]})})}function Ee({token:e,onClose:t}){let{t:n}=d(),{toast:r}=B(),a=s(),c=N(),l=ee(),[u,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)([]),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)([]),[b,x]=(0,Z.useState)(null),[C,w]=(0,Z.useState)(`any`),[T,E]=(0,Z.useState)([]),D=new Set(v.map(e=>`${e.metric}:${e.period}`)).size<v.length,O=new Map((e?.pool?.members??[]).map(e=>[e.providerId,e.health]));return(0,Z.useEffect)(()=>{e&&(p(e.name),_(he(e)),y(e.limits?.budgets.map(e=>e.metric===`cost`?{...e,limit:P(e.limit),usd:e.limit,shown:P(e.limit)}:{...e})??[]),x(e.limits?.rpm??null),w(e.allowedClients==null?`any`:`only`),E(e.allowedClients??[]),h(e.mcpServers??[]))},[e]),(0,Q.jsx)(I,{open:e!==null,onOpenChange:e=>!e&&t(),title:n(`tokens.settingsTitle`,{name:e?.name??``}),footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(S,{onClick:t,children:n(`common.cancel`)}),(0,Q.jsx)(S,{variant:`primary`,disabled:!u.trim()||D,loading:a.isPending,onClick:()=>{if(!e)return;let i=v.flatMap(e=>{if(e.limit==null||e.limit<=0)return[];let{usd:t,shown:n,...r}=e,i=e.metric===`cost`?t!=null&&e.limit===n?t:Math.round(j(e.limit)*1e9)/1e9:e.limit;return[{...r,limit:i}]}),o=i.length>0||b!=null&&b>0?{budgets:i,rpm:b!=null&&b>0?Math.floor(b):null}:null;a.mutate({id:e.id,name:u.trim(),...g?{pool:me(g,c.data??[])}:{},limits:o,allowedClients:C===`any`?null:T,...l.data?{mcpServers:m.filter(e=>l.data.some(t=>t.id===e))}:{}},{onSuccess:()=>{t(),r(n(`common.saved`),`success`)},onError:e=>r(R(e),`error`)})},children:n(`common.save`)})]}),children:(0,Q.jsxs)(`div`,{className:`grid gap-4`,children:[(0,Q.jsx)(i,{label:n(`tokens.name`),children:(0,Q.jsx)(o,{value:u,maxLength:64,onChange:e=>p(e.target.value)})}),(0,Q.jsx)(i,{label:n(`tokens.pool.title`),hint:n(`tokens.pool.hint`),children:g&&(0,Q.jsx)(ge,{draft:g,onChange:_,providers:c.data??[],health:O})}),(0,Q.jsx)(i,{label:n(`tokens.limits`),hint:n(`tokens.limitsHint`),error:D?n(`tokens.limitDuplicate`):void 0,children:(0,Q.jsx)(ke,{budgets:v,onChange:y})}),(0,Q.jsx)(i,{label:n(`tokens.rpm`),hint:n(`tokens.rpmHint`),children:(0,Q.jsx)(F,{value:b,min:1,step:1,label:n(`tokens.rpm`),placeholder:n(`tokens.unlimited`),onChange:x})}),(0,Q.jsx)(i,{label:n(`tokens.mcp`),hint:l.data&&l.data.length===0?n(`tokens.mcpNone`):n(`tokens.mcpHint`),children:l.data&&l.data.length>0&&(0,Q.jsx)(J,{label:n(`tokens.mcp`),options:l.data.map(e=>({value:e.id,label:e.name})),value:m.filter(e=>l.data.some(t=>t.id===e)),onValueChange:e=>h(e)})}),(0,Q.jsx)(i,{label:n(`tokens.allowedClients`),hint:n(`tokens.allowedClientsHint`),children:(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(f,{ariaLabel:n(`tokens.allowedClients`),value:C,onChange:w,items:[{value:`any`,label:n(`tokens.allowedClientsAny`)},{value:`only`,label:n(`tokens.allowedClientsOnly`)}]}),C===`only`&&(0,Q.jsx)(J,{label:n(`tokens.allowedClients`),options:[...new Set([...Object.keys(q),...T])].map(e=>({value:e,label:q[e]?.name??e})),value:T,onValueChange:e=>E(e)})]})})]})})}var De=[`cost`,`requests`,`tokens`],Oe=[`day`,`week`,`month`,`total`];function ke({budgets:e,onChange:t}){let{t:n}=d(),r=w(),i=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),a=De.flatMap(e=>Oe.map(t=>({metric:e,period:t}))).find(t=>!e.some(e=>e.metric===t.metric&&e.period===t.period));return(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[e.length===0&&(0,Q.jsx)(`div`,{className:`text-[12px] text-[var(--text-muted)]`,children:n(`tokens.unlimited`)}),e.map((a,o)=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,Q.jsx)(z,{ariaLabel:n(`tokens.limitMetric`),value:a.metric,onChange:e=>i(o,{metric:e}),options:De.map(e=>({value:e,label:n(`tokens.metric.${e}`)}))}),(0,Q.jsx)(z,{ariaLabel:n(`tokens.limitPeriod`),value:a.period,onChange:e=>i(o,{period:e}),options:Oe.map(e=>({value:e,label:n(`tokens.period.${e}`)}))}),(0,Q.jsx)(F,{label:n(`tokens.limitValue`),value:a.limit,min:0,step:a.metric===`cost`?`any`:1,placeholder:a.metric===`cost`?`${n(`tokens.limitValue`)} (${r.code})`:n(`tokens.limitValue`),onChange:e=>i(o,{limit:e})}),(0,Q.jsx)(S,{size:`sm`,variant:`plain`,icon:(0,Q.jsx)(W,{className:`size-3.5`}),"aria-label":n(`tokens.removeLimit`),title:n(`tokens.removeLimit`),onClick:()=>t(e.filter((e,t)=>t!==o))})]}),a.metric===`cost`&&r.code!==`USD`&&a.limit!=null&&a.limit>0&&(0,Q.jsx)(`div`,{className:`num mt-1 text-[11px] text-[var(--text-muted)]`,children:n(`tokens.limitUsdEquivalent`,{usd:C(j(a.limit))})})]},o)),a&&(0,Q.jsx)(`div`,{children:(0,Q.jsx)(S,{size:`sm`,icon:(0,Q.jsx)(U,{className:`size-3.5`}),onClick:()=>t([...e,{...a,limit:null}]),children:n(`tokens.addLimit`)})})]})}export{ye as TokensPage};