import{u as c,j as e}from"./query-Bw69rE6b.js";import{L as u}from"./react-CQKYBN-P.js";import{d as x,B as y,S as g,e as d,f as h,I as N,a as p,b as k}from"./index-CoUu6FiM.js";import{P as _}from"./PageHeader-qtVByY5c.js";import{C as v,a as F,b as S}from"./Card-nuKO-lKR.js";import{E as C}from"./EmptyState-CgO0CCgi.js";import{S as $}from"./StatusPill-DBEWzsQ3.js";import{h as L,s as A,r as q,b as M,c as T,a as z}from"./runDisplay-BnzArzDk.js";import{C as b}from"./circle-play-BX3na9-o.js";import{A as P}from"./arrow-down-to-line-CCt3pyba.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 R=[["path",{d:"m18 9-6-6-6 6",key:"kcunyi"}],["path",{d:"M12 3v14",key:"7cf3v8"}],["path",{d:"M5 21h14",key:"11awu3"}]],D=x("arrow-up-from-line",R);/**
 * @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 H=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],I=x("dollar-sign",H);/**
 * @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 B=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],K=x("trending-up",B);function ae(){const{data:t}=c({queryKey:["context"],queryFn:()=>p.context()}),r=c({queryKey:["stats"],queryFn:()=>p.stats(),retry:!1}),n=c({queryKey:["recent-runs"],queryFn:()=>p.recentRuns(8),retry:!1}),i=c({queryKey:["usage","all"],queryFn:()=>k("/api/usage?window=all"),retry:!1});return e.jsxs(e.Fragment,{children:[e.jsx(_,{title:"Overview",actions:e.jsx(u,{to:"/runs/new",children:e.jsx(y,{variant:"primary",size:"md",leadingIcon:e.jsx(b,{size:14}),children:"New run"})})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(l,{icon:g,label:"LLM model",value:t?.llm_model??"—",tone:"neutral",to:"/settings",hint:"The model that generates descriptions. Configured under Settings → LLM."}),e.jsx(l,{icon:b,label:"Total runs",value:U(r.data),tone:"accent",to:"/runs",hint:"All-time count of /run, /apply, and /ask invocations recorded in the local history store."}),e.jsx(l,{icon:K,label:"Success rate",value:w(r.data),tone:"positive",to:"/runs",hint:"Percentage of runs whose worker exited cleanly. Cancelled and failed runs both count against the total."})]}),e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-3",children:[e.jsx(l,{icon:D,label:"Input tokens",value:j(i.data?.totals.input_tokens),tone:"neutral",to:"/system",hint:"All-time prompt tokens billed at the input rate, summed across every recorded run. Click to drill into the System page's per-(provider, model) breakdown."}),e.jsx(l,{icon:P,label:"Output tokens",value:j(i.data?.totals.output_tokens),tone:"neutral",to:"/system",hint:"All-time completion tokens billed at the output rate. Output is usually the dominant cost contributor on modern models."}),e.jsx(l,{icon:I,label:"Total cost (USD)",value:O(i.data?.totals.cost_usd),tone:"accent",to:"/system",hint:"All-time USD cost frozen at run time. Older runs without a recorded price contribute zero — refresh prices via the TopBar ↻ button or run /usage --live for a recompute against current rates."})]}),e.jsx("div",{className:"mt-6",children:e.jsxs(v,{children:[e.jsx(F,{title:"Recent runs",actions:e.jsx(u,{to:"/runs",className:"text-xs font-medium text-accent hover:text-accent-ink",children:"View all →"})}),e.jsx(S,{className:"p-0",children:n.isLoading?e.jsx("ul",{className:"divide-y divide-border",children:Array.from({length:5}).map((s,a)=>e.jsxs("li",{className:"flex items-center gap-3 px-5 py-2.5",children:[e.jsx(d,{className:"h-3 w-10"}),e.jsx(d,{className:"h-3 w-24"}),e.jsx(d,{className:"h-3 w-32"}),e.jsx(d,{className:"ml-auto h-4 w-16"})]},a))}):n.error?e.jsx("div",{className:"px-5 py-6 text-sm text-critical",children:n.error.message}):n.data?.runs?.length?e.jsx("ul",{className:"divide-y divide-border",children:n.data.runs.map(s=>{const a=Q(s.metrics),o=V(s.metrics);return e.jsx("li",{children:e.jsxs(u,{to:`/runs/${s.id}`,className:"flex items-start gap-3 px-5 py-2.5 text-sm transition-colors duration-fast hover:bg-surface-subtle/60 focus-visible:bg-surface-subtle/60 focus-visible:outline-none",children:[e.jsx(h,{size:13,className:"mt-1 text-ink-dim shrink-0"}),e.jsxs("span",{className:"mt-0.5 font-mono text-xs text-ink-dim",children:["#",s.id]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"font-medium text-ink truncate",title:s.command,children:L(s.command,s.scope_json??s.scope)}),e.jsxs("span",{className:"truncate text-ink-muted text-xs",children:["· ",E(s.scope_json??s.scope,s.db_profile),a!=null&&e.jsxs("span",{className:"ml-2 text-ink-dim",children:[a,o!=null&&o!==a?`/${o}`:""," ","processed"]})]})]}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 text-[11px] text-ink-dim",children:[s.db_profile&&e.jsx("span",{className:"font-mono",title:`DB profile: ${s.db_profile}`,children:s.db_profile}),s.llm_model&&e.jsxs(e.Fragment,{children:[s.db_profile&&e.jsx("span",{children:"·"}),e.jsx("span",{className:"truncate font-mono",title:s.llm_model,children:A(s.llm_model)})]}),s.duration_sec!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[s.duration_sec.toFixed(1),"s"]})]}),s.started_at!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{children:q(s.started_at)})]})]})]}),e.jsx("span",{className:"mt-0.5 ml-auto shrink-0",children:e.jsx($,{tone:T(s.status),children:M(s.status)})})]})},s.id)})}):e.jsx("div",{className:"px-5 py-5",children:e.jsx(C,{icon:h,title:"No runs yet",description:"Trigger a /run from the CLI or use the New run button above to get started.",compact:!0})})})]})})]})}function l({icon:t,label:r,value:n,tone:i,hint:s,to:a}){const o=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10.5px] font-semibold uppercase tracking-[0.06em] text-ink-dim",children:[r,s&&e.jsx("span",{onClick:m=>m.stopPropagation(),onMouseDown:m=>m.stopPropagation(),children:e.jsx(N,{text:s})})]}),e.jsx(t,{size:14,className:i==="accent"?"text-accent":i==="positive"?"text-positive":"text-ink-dim"})]}),e.jsx("div",{className:"mt-1.5 truncate font-mono text-[14px] leading-tight tabular-nums text-ink",children:n})]}),f="flex min-h-[68px] flex-col rounded-xl border border-border bg-surface-raised px-4 py-3 shadow-xs";return a?e.jsx(u,{to:a,title:n,className:`${f} transition-colors duration-fast hover:border-accent/40 hover:bg-surface-subtle/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:o}):e.jsx("div",{title:n,className:f,children:o})}function w(t){if(!t||typeof t!="object")return"—";const r=t,n=r.total_runs??r.total,i=r.success_runs??r.success,s=typeof n=="number"?n:Number(n),a=typeof i=="number"?i:Number(i);return Number.isFinite(s)&&Number.isFinite(a)&&s>0?`${Math.round(a/s*100)}%`:"—"}function j(t){return t==null||!Number.isFinite(t)||t<=0?"—":t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e4?`${(t/1e3).toFixed(1)}K`:t.toLocaleString()}function O(t){return t==null||!Number.isFinite(t)||t<=0?"—":t<.01?"<$0.01":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function U(t){if(!t||typeof t!="object")return"—";const r=t,n=r.total_runs??r.total;return typeof n=="number"?String(n):"—"}function E(t,r){const n=z(t);return n==="All schemas"&&r?`All schemas in ${r}`:n}function Q(t){if(!t)return null;for(const r of["processed_count","tables_processed","columns_processed","applied_count"]){const n=t[r];if(typeof n=="number"&&Number.isFinite(n))return n}return null}function V(t){if(!t)return null;for(const r of["selected_count","planned_count","tables_selected"]){const n=t[r];if(typeof n=="number"&&Number.isFinite(n))return n}return null}export{ae as default};
