import{j as e,r as p,u as l}from"./query-Bw69rE6b.js";import{P as b}from"./PageHeader-qtVByY5c.js";import{C as c,a as d,b as o}from"./Card-nuKO-lKR.js";import{S as N}from"./StatusPill-DBEWzsQ3.js";import{E as k}from"./EmptyState-CgO0CCgi.js";import{d as h,D as u,R as j,I as x,c as n,a1 as v,a2 as w,f as S,b as m}from"./index-CoUu6FiM.js";import"./react-CQKYBN-P.js";import"./Badge-DwoQNRW3.js";/**
 * @license lucide-react v0.577.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const C=[["path",{d:"M11 2v2",key:"1539x4"}],["path",{d:"M5 2v2",key:"1yf1q8"}],["path",{d:"M5 3H4a2 2 0 0 0-2 2v4a6 6 0 0 0 12 0V5a2 2 0 0 0-2-2h-1",key:"rb5t3r"}],["path",{d:"M8 15a6 6 0 0 0 12 0v-3",key:"x18d4x"}],["circle",{cx:"20",cy:"10",r:"2",key:"ts1r5v"}]],g=h("stethoscope",C);/**
 * @license lucide-react v0.577.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const L=[["path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1",key:"18etb6"}],["path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4",key:"xoc0q4"}]],f=h("wallet",L),_=[{id:"today",label:"Today"},{id:"24h",label:"24h"},{id:"7d",label:"7 days"},{id:"30d",label:"30 days"},{id:"all",label:"All time"}],T=[{id:"doctor",label:"Doctor",icon:g},{id:"usage",label:"Token usage",icon:f},{id:"catalog",label:"Catalog",icon:u}];function O(){return e.jsxs(e.Fragment,{children:[e.jsx(b,{title:"System",breadcrumbs:[{label:"System"}]}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-[10rem_minmax(0,1fr)] [&>*]:min-w-0",children:[e.jsx("nav",{"aria-label":"System sections",className:"hidden md:block",children:e.jsx("ul",{className:"sticky top-4 flex flex-col gap-0.5 text-sm",children:T.map(t=>e.jsx("li",{children:e.jsxs("a",{href:`#sys-${t.id}`,className:"flex items-center gap-2 rounded px-2 py-1 text-ink-muted transition-colors duration-fast hover:bg-surface-subtle hover:text-ink",children:[e.jsx(t.icon,{size:13,className:"text-ink-dim"}),t.label]})},t.id))})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("section",{id:"sys-doctor",className:"scroll-mt-4",children:e.jsx($,{})}),e.jsx("section",{id:"sys-usage",className:"scroll-mt-4",children:e.jsx(R,{})}),e.jsx("section",{id:"sys-catalog",className:"scroll-mt-4",children:e.jsx(I,{})})]})]})]})}function $(){const[t,i]=p.useState(!1),a=l({queryKey:["doctor",t],queryFn:()=>m(`/api/doctor?skip_network=${t}`),retry:!1});return e.jsxs(c,{children:[e.jsx(d,{title:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(g,{size:16,className:"text-accent"}),"Doctor",e.jsx(x,{text:"Installation, config, and connectivity checks — same as `amx doctor` from the CLI. Toggle skip-network to bypass live HTTP/SQL probes."})]}),actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-1.5 text-xs text-ink-muted",children:[e.jsx("input",{type:"checkbox",checked:t,onChange:s=>i(s.target.checked),className:"h-3.5 w-3.5 cursor-pointer"}),"Skip network"]}),e.jsxs("button",{type:"button",onClick:()=>a.refetch(),className:"inline-flex items-center gap-1 rounded-md bg-surface-subtle px-2.5 py-1 text-xs text-ink-muted hover:bg-surface-border",children:[e.jsx(j,{size:12}),"Re-run"]})]})}),e.jsx(o,{className:"p-0",children:a.isLoading?e.jsx("div",{className:"px-5 py-6 text-sm text-ink-dim",children:"Running checks…"}):a.error?e.jsx("div",{className:"px-5 py-6 text-sm text-critical",children:a.error.message}):a.data?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:n("border-b border-surface-border px-5 py-2 text-xs",a.data.ok?"text-positive":"text-critical"),children:a.data.ok?`All ${a.data.total} checks passed.`:`${a.data.failed} of ${a.data.total} checks failed.`}),e.jsx("ul",{className:"divide-y divide-surface-border",children:a.data.checks.map(s=>e.jsx("li",{className:"px-5 py-2.5 text-sm",children:e.jsxs("div",{className:"flex items-start gap-3",children:[s.ok?e.jsx(v,{size:14,className:"mt-0.5 shrink-0 text-positive"}):e.jsx(w,{size:14,className:"mt-0.5 shrink-0 text-critical"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium",children:s.name}),s.detail&&e.jsx("div",{className:"text-xs text-ink-muted",children:s.detail}),s.hint&&e.jsx("div",{className:n("mt-1 text-xs",s.ok?"text-ink-dim":"text-warning"),children:s.hint})]})]})},s.name))})]}):null})]})}function R(){const[t,i]=p.useState("7d"),a=l({queryKey:["usage",t],queryFn:()=>m(`/api/usage?window=${t}`),retry:!1});return e.jsxs(c,{children:[e.jsx(d,{title:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(f,{size:16,className:"text-accent"}),"Token usage + cost",e.jsx(x,{text:"Tokens consumed and approximate cost per (provider, model), aggregated from the local history store. Pricing falls back to $0 for providers without a built-in price table."})]}),actions:e.jsx("div",{className:"flex items-center gap-1",children:_.map(s=>e.jsx("button",{type:"button",onClick:()=>i(s.id),className:n("rounded-md px-2 py-1 text-xs font-medium transition",t===s.id?"bg-accent-soft text-accent-ink":"text-ink-muted hover:bg-surface-subtle"),children:s.label},s.id))})}),e.jsx(o,{className:"p-0 overflow-x-auto",children:a.isLoading?e.jsx("div",{className:"px-5 py-6 text-sm text-ink-dim",children:"Loading…"}):a.error?e.jsx("div",{className:"px-5 py-6 text-sm text-critical",children:a.error.message}):a.data?.message?e.jsx("div",{className:"px-5 py-6 text-sm text-ink-dim",children:a.data.message}):a.data?.rows?.length?e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-surface-subtle/60 text-[11px] uppercase tracking-wider text-ink-dim",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-2 text-left font-semibold",children:"Provider"}),e.jsx("th",{className:"px-5 py-2 text-left font-semibold",children:"Model"}),e.jsx("th",{className:"px-5 py-2 text-right font-semibold",children:"Runs"}),e.jsx("th",{className:"px-5 py-2 text-right font-semibold",children:"Input"}),e.jsx("th",{className:"px-5 py-2 text-right font-semibold",children:"Output"}),e.jsx("th",{className:"px-5 py-2 text-right font-semibold",children:"Total"}),e.jsx("th",{className:"px-5 py-2 text-right font-semibold",children:"Cost"})]})}),e.jsx("tbody",{children:a.data.rows.map(s=>e.jsxs("tr",{className:"border-t border-surface-border",children:[e.jsx("td",{className:"px-5 py-2 text-xs",children:s.provider}),e.jsx("td",{className:"px-5 py-2 font-mono text-xs",children:s.model}),e.jsx("td",{className:"px-5 py-2 text-right font-mono text-xs",children:s.runs}),e.jsx("td",{className:"px-5 py-2 text-right font-mono text-xs tabular-nums",children:s.input_tokens.toLocaleString()}),e.jsx("td",{className:"px-5 py-2 text-right font-mono text-xs tabular-nums",children:s.output_tokens.toLocaleString()}),e.jsx("td",{className:"px-5 py-2 text-right font-mono text-xs tabular-nums",children:s.total_tokens.toLocaleString()}),e.jsx("td",{className:"px-5 py-2 text-right font-mono text-xs",children:s.cost_usd})]},`${s.provider}::${s.model}`))}),e.jsx("tfoot",{className:"border-t-2 border-surface-border bg-surface-subtle/40 text-[11px] uppercase tracking-wider text-ink-dim",children:e.jsxs("tr",{children:[e.jsx("td",{className:"px-5 py-2",colSpan:2,children:"Total"}),e.jsx("td",{className:"px-5 py-2 text-right font-mono",children:a.data.totals.runs}),e.jsx("td",{className:"px-5 py-2 text-right font-mono tabular-nums",children:a.data.totals.input_tokens.toLocaleString()}),e.jsx("td",{className:"px-5 py-2 text-right font-mono tabular-nums",children:a.data.totals.output_tokens.toLocaleString()}),e.jsx("td",{className:"px-5 py-2 text-right font-mono tabular-nums",children:a.data.totals.total_tokens.toLocaleString()}),e.jsx("td",{className:"px-5 py-2"})]})})]}):e.jsx(k,{icon:S,title:`No runs in ${a.data?.window??t}`,description:"Trigger /run from the Runs page; numbers will populate here."})})]})}function I(){const t=l({queryKey:["catalog-status"],queryFn:()=>m("/api/catalog/status"),retry:!1});return e.jsxs(c,{children:[e.jsx(d,{title:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(u,{size:16,className:"text-accent"}),"Search catalog",e.jsx(x,{text:"The vector + lexical index that grounds /ask. Refresh from the CLI with `/search sync` after metadata changes; this card just reads its current state."})]}),actions:e.jsxs("button",{type:"button",onClick:()=>t.refetch(),className:"inline-flex items-center gap-1 rounded-md bg-surface-subtle px-2.5 py-1 text-xs text-ink-muted hover:bg-surface-border",children:[e.jsx(j,{size:12}),"Refresh"]})}),e.jsx(o,{children:t.isLoading?e.jsx("div",{className:"text-sm text-ink-dim",children:"Loading…"}):t.error?e.jsx("div",{className:"text-sm text-critical",children:t.error.message}):t.data?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-3",children:[e.jsx(N,{tone:t.data.ready?"positive":"warning",children:t.data.ready?"Ready":"Empty"}),e.jsxs("span",{className:"text-xs text-ink-muted",children:["LLM ready:"," ",e.jsx("span",{className:"font-mono",children:t.data.llm_ready?"yes":"no"})]})]}),t.data.message&&e.jsx("p",{className:"mb-3 text-xs text-warning",children:t.data.message}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(r,{title:"Entities",data:t.data.entities??{}}),e.jsx(r,{title:"Descriptions",data:t.data.descriptions??{}})]}),t.data.settings&&Object.keys(t.data.settings).length>0&&e.jsx("div",{className:"mt-4",children:e.jsx(r,{title:"Settings",data:t.data.settings})})]}):null})]})}function r({title:t,data:i}){const a=Object.entries(i);return a.length===0?e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 text-[11px] font-semibold uppercase tracking-wider text-ink-dim",children:t}),e.jsx("p",{className:"text-xs text-ink-dim",children:"—"})]}):e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 text-[11px] font-semibold uppercase tracking-wider text-ink-dim",children:t}),e.jsx("ul",{className:"space-y-0.5",children:a.map(([s,y])=>e.jsxs("li",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsx("span",{className:"text-ink-muted",children:s}),e.jsx("span",{className:"font-mono text-ink",children:String(y)})]},s))})]})}export{O as default};
