@kaitranntt/ccs 6.7.1-dev.2 → 6.7.1-dev.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.
@@ -5,7 +5,7 @@
5
5
  * Uses native fetch API with aggressive timeout for CLI responsiveness.
6
6
  */
7
7
  /** Error codes for remote proxy status */
8
- export type RemoteProxyErrorCode = 'CONNECTION_REFUSED' | 'TIMEOUT' | 'AUTH_FAILED' | 'UNKNOWN';
8
+ export type RemoteProxyErrorCode = 'CONNECTION_REFUSED' | 'TIMEOUT' | 'AUTH_FAILED' | 'DNS_FAILED' | 'NETWORK_UNREACHABLE' | 'UNKNOWN';
9
9
  /** Status returned from remote proxy health check */
10
10
  export interface RemoteProxyStatus {
11
11
  /** Whether the remote proxy is reachable */
@@ -1 +1 @@
1
- {"version":3,"file":"remote-proxy-client.d.ts","sourceRoot":"","sources":["../../src/cliproxy/remote-proxy-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,0CAA0C;AAC1C,MAAM,MAAM,oBAAoB,GAAG,oBAAoB,GAAG,SAAS,GAAG,aAAa,GAAG,SAAS,CAAC;AAEhG,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC,4CAA4C;IAC5C,SAAS,EAAE,OAAO,CAAC;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,SAAS,CAAC,EAAE,oBAAoB,CAAC;CAClC;AAED,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACtC,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,OA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AAC,CA6H5B;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAEhG"}
@@ -56,8 +56,8 @@ function buildProxyUrl(host, port, protocol, path) {
56
56
  * Map error to RemoteProxyErrorCode
57
57
  *
58
58
  * Handles various error types including:
59
- * - NodeJS.ErrnoException (ECONNREFUSED, ETIMEDOUT)
60
- * - Fetch errors (AbortError, TypeError)
59
+ * - NodeJS.ErrnoException (ECONNREFUSED, ETIMEDOUT, ENOTFOUND, ENETUNREACH)
60
+ * - Fetch errors (AbortError, TypeError, "fetch failed")
61
61
  * - HTTP status codes (401, 403)
62
62
  */
63
63
  function mapErrorToCode(error, statusCode) {
@@ -65,6 +65,21 @@ function mapErrorToCode(error, statusCode) {
65
65
  // Handle error.code safely - it may be string, number, or undefined
66
66
  const rawCode = error.code;
67
67
  const code = typeof rawCode === 'string' ? rawCode.toLowerCase() : undefined;
68
+ // DNS resolution failed
69
+ if (code === 'enotfound' ||
70
+ code === 'eai_again' ||
71
+ message.includes('getaddrinfo') ||
72
+ message.includes('dns')) {
73
+ return 'DNS_FAILED';
74
+ }
75
+ // Network unreachable / host unreachable
76
+ if (code === 'enetunreach' ||
77
+ code === 'ehostunreach' ||
78
+ code === 'enetdown' ||
79
+ message.includes('network') ||
80
+ message.includes('unreachable')) {
81
+ return 'NETWORK_UNREACHABLE';
82
+ }
68
83
  // Connection refused
69
84
  if (code === 'econnrefused' || message.includes('connection refused')) {
70
85
  return 'CONNECTION_REFUSED';
@@ -80,6 +95,16 @@ function mapErrorToCode(error, statusCode) {
80
95
  if (statusCode === 401 || statusCode === 403) {
81
96
  return 'AUTH_FAILED';
82
97
  }
98
+ // Generic "fetch failed" - try to extract cause
99
+ if (message.includes('fetch failed') || message.includes('failed to fetch')) {
100
+ // Check if there's a cause property (Node.js 18+)
101
+ const cause = error.cause;
102
+ if (cause) {
103
+ return mapErrorToCode(cause);
104
+ }
105
+ // Likely network/DNS issue if no specific cause
106
+ return 'NETWORK_UNREACHABLE';
107
+ }
83
108
  return 'UNKNOWN';
84
109
  }
85
110
  /**
@@ -90,11 +115,15 @@ function getErrorMessage(errorCode, rawError) {
90
115
  case 'CONNECTION_REFUSED':
91
116
  return 'Connection refused - is the proxy running?';
92
117
  case 'TIMEOUT':
93
- return 'Connection timed out';
118
+ return 'Connection timed out - server may be slow or unreachable';
94
119
  case 'AUTH_FAILED':
95
120
  return 'Authentication failed - check auth token';
121
+ case 'DNS_FAILED':
122
+ return 'DNS lookup failed - check hostname';
123
+ case 'NETWORK_UNREACHABLE':
124
+ return 'Network unreachable - check if host is on same network';
96
125
  default:
97
- return rawError || 'Unknown error';
126
+ return rawError || 'Connection failed';
98
127
  }
99
128
  }
100
129
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"remote-proxy-client.js","sourceRoot":"","sources":["../../src/cliproxy/remote-proxy-client.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAsC/B,wEAAwE;AACxE,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC;;;GAGG;AACH,SAAS,cAAc,CAAC,QAA0B;IAChD,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CACpB,IAAY,EACZ,IAAwB,EACxB,QAA0B,EAC1B,IAAY;IAEZ,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,aAAa,GAAG,IAAI,IAAI,WAAW,CAAC;IAE1C,gEAAgE;IAChE,IAAI,aAAa,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,GAAG,QAAQ,MAAM,IAAI,GAAG,IAAI,EAAE,CAAC;IACxC,CAAC;IACD,OAAO,GAAG,QAAQ,MAAM,IAAI,IAAI,aAAa,GAAG,IAAI,EA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,MAAM,GAAG,GAAG,KAAc,CAAC;QAC3B,MAAM,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QAEtC,OAAO;YACL,SAAS,EAAE,KAAK;YAChB,KAAK,EAAE,eAAe,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC;YAC9C,SAAS;SACV,CAAC;IACJ,CAAC;AACH,CAAC;AA/HD,4CA+HC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,cAAc,CAAC,MAA+B;IAClE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAFD,wCAEC"}
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-CV3R9pD6.js";import{a as x,u as p,b as h,d as f,f as l,g as b}from"./tanstack-Df9bCj5R.js";import"./react-vendor-FspHSO0w.js";import{c as r,a4 as u,B as g}from"./index-C1W0iP_Z.js";import{t as d}from"./notifications-B2Pz7lik.js";import{j}from"./icons-ZmwVoUeR.js";import"./utils-CzKF5WmX.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function y({className:s,...t}){return e.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:e.jsx("table",{"data-slot":"table",className:r("w-full caption-bottom text-sm",s),...t})})}function N({className:s,...t}){return e.jsx("thead",{"data-slot":"table-header",className:r("[&_tr]:border-b",s),...t})}function w({className:s,...t}){return e.jsx("tbody",{"data-slot":"table-body",className:r("[&_tr:last-child]:border-0",s),...t})}function i({className:s,...t}){return e.jsx("tr",{"data-slot":"table-row",className:r("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",s),...t})}function v({className:s,...t}){return e.jsx("th",{"data-slot":"table-head",className:r("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}function C({className:s,...t}){return e.jsx("td",{"data-slot":"table-cell",className:r("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}function D(){return x({queryKey:["accounts"],queryFn:()=>u.accounts.list()})}function T(){const s=p();return h({mutationFn:t=>u.accounts.setDefault(t),onSuccess:(t,o)=>{s.invalidateQueries({queryKey:["accounts"]}),d.success(`Default account set to "${o}"`)},onError:t=>{d.error(t.message)}})}function A({data:s,defaultAccount:t}){const o=T(),c=f({data:s,columns:[{accessorKey:"name",header:"Name",size:200,cell:({row:a})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:a.original.name}),a.original.name===t&&e.jsx("span",{className:"text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded border border-primary/20",children:"default"})]})},{accessorKey:"type",header:"Type",size:100,cell:({row:a})=>e.jsx("span",{className:"capitalize text-muted-foreground",children:a.original.type||"oauth"})},{accessorKey:"created",header:"Created",size:150,cell:({row:a})=>{const n=new Date(a.original.created);return e.jsx("span",{className:"text-muted-foreground",children:n.toLocaleDateString()})}},{accessorKey:"last_used",header:"Last Used",size:150,cell:({row:a})=>{if(!a.original.last_used)return e.jsx("span",{className:"text-muted-foreground/50",children:"-"});const n=new Date(a.original.last_used);return e.jsx("span",{className:"text-muted-foreground",children:n.toLocaleDateString()})}},{id:"actions",header:"Actions",size:100,cell:({row:a})=>{const n=a.original.name===t;return e.jsxs(g,{variant:n?"secondary":"default",size:"sm",className:"h-8 px-2 w-full",disabled:n||o.isPending,onClick:()=>o.mutate(a.original.name),children:[e.jsx(j,{className:`w-3 h-3 mr-1.5 ${n?"opacity-50":""}`}),n?"Active":"Set Default"]})}}],getCoreRowModel:b()});return s.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:["No accounts found. Use ",e.jsx("code",{className:"text-sm bg-muted px-1 rounded",children:"ccs login"})," to add accounts."]}):e.jsx("div",{className:"border rounded-md",children:e.jsxs(y,{children:[e.jsx(N,{children:c.getHeaderGroups().map(a=>e.jsx(i,{children:a.headers.map(n=>{const m={name:"w-[200px]",type:"w-[100px]",created:"w-[150px]",last_used:"w-[150px]",actions:"w-[100px]"}[n.id]||"w-auto";return e.jsx(v,{className:m,children:n.isPlaceholder?null:l(n.column.columnDef.header,n.getContext())},n.id)})},a.id))}),e.jsx(w,{children:c.getRowModel().rows.map(a=>e.jsx(i,{children:a.getVisibleCells().map(n=>e.jsx(C,{children:l(n.column.columnDef.cell,n.getContext())},n.id))},a.id))})]})})}function H(){const{data:s,isLoading:t}=D();return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-8",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Accounts"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage multi-account Claude sessions (profiles.json)"})]})}),t?e.jsx("div",{className:"text-muted-foreground",children:"Loading accounts..."}):e.jsx(A,{data:s?.accounts||[],defaultAccount:s?.default??null}),e.jsx("div",{className:"text-sm text-muted-foreground border-t pt-4 mt-4",children:e.jsxs("p",{children:["Accounts are isolated Claude instances with separate sessions.",e.jsx("br",{}),"Use ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs auth create <name>"})," to add new accounts via CLI."]})})]})}export{H as AccountsPage};
1
+ import{j as e}from"./radix-ui-CV3R9pD6.js";import{a as x,u as p,b as h,d as f,f as l,g as b}from"./tanstack-Df9bCj5R.js";import"./react-vendor-FspHSO0w.js";import{c as r,a4 as u,B as g}from"./index-BJVyJi5-.js";import{t as d}from"./notifications-B2Pz7lik.js";import{j}from"./icons-ZmwVoUeR.js";import"./utils-CzKF5WmX.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function y({className:s,...t}){return e.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:e.jsx("table",{"data-slot":"table",className:r("w-full caption-bottom text-sm",s),...t})})}function N({className:s,...t}){return e.jsx("thead",{"data-slot":"table-header",className:r("[&_tr]:border-b",s),...t})}function w({className:s,...t}){return e.jsx("tbody",{"data-slot":"table-body",className:r("[&_tr:last-child]:border-0",s),...t})}function i({className:s,...t}){return e.jsx("tr",{"data-slot":"table-row",className:r("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",s),...t})}function v({className:s,...t}){return e.jsx("th",{"data-slot":"table-head",className:r("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}function C({className:s,...t}){return e.jsx("td",{"data-slot":"table-cell",className:r("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}function D(){return x({queryKey:["accounts"],queryFn:()=>u.accounts.list()})}function T(){const s=p();return h({mutationFn:t=>u.accounts.setDefault(t),onSuccess:(t,o)=>{s.invalidateQueries({queryKey:["accounts"]}),d.success(`Default account set to "${o}"`)},onError:t=>{d.error(t.message)}})}function A({data:s,defaultAccount:t}){const o=T(),c=f({data:s,columns:[{accessorKey:"name",header:"Name",size:200,cell:({row:a})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:a.original.name}),a.original.name===t&&e.jsx("span",{className:"text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded border border-primary/20",children:"default"})]})},{accessorKey:"type",header:"Type",size:100,cell:({row:a})=>e.jsx("span",{className:"capitalize text-muted-foreground",children:a.original.type||"oauth"})},{accessorKey:"created",header:"Created",size:150,cell:({row:a})=>{const n=new Date(a.original.created);return e.jsx("span",{className:"text-muted-foreground",children:n.toLocaleDateString()})}},{accessorKey:"last_used",header:"Last Used",size:150,cell:({row:a})=>{if(!a.original.last_used)return e.jsx("span",{className:"text-muted-foreground/50",children:"-"});const n=new Date(a.original.last_used);return e.jsx("span",{className:"text-muted-foreground",children:n.toLocaleDateString()})}},{id:"actions",header:"Actions",size:100,cell:({row:a})=>{const n=a.original.name===t;return e.jsxs(g,{variant:n?"secondary":"default",size:"sm",className:"h-8 px-2 w-full",disabled:n||o.isPending,onClick:()=>o.mutate(a.original.name),children:[e.jsx(j,{className:`w-3 h-3 mr-1.5 ${n?"opacity-50":""}`}),n?"Active":"Set Default"]})}}],getCoreRowModel:b()});return s.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:["No accounts found. Use ",e.jsx("code",{className:"text-sm bg-muted px-1 rounded",children:"ccs login"})," to add accounts."]}):e.jsx("div",{className:"border rounded-md",children:e.jsxs(y,{children:[e.jsx(N,{children:c.getHeaderGroups().map(a=>e.jsx(i,{children:a.headers.map(n=>{const m={name:"w-[200px]",type:"w-[100px]",created:"w-[150px]",last_used:"w-[150px]",actions:"w-[100px]"}[n.id]||"w-auto";return e.jsx(v,{className:m,children:n.isPlaceholder?null:l(n.column.columnDef.header,n.getContext())},n.id)})},a.id))}),e.jsx(w,{children:c.getRowModel().rows.map(a=>e.jsx(i,{children:a.getVisibleCells().map(n=>e.jsx(C,{children:l(n.column.columnDef.cell,n.getContext())},n.id))},a.id))})]})})}function H(){const{data:s,isLoading:t}=D();return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-8",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Accounts"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage multi-account Claude sessions (profiles.json)"})]})}),t?e.jsx("div",{className:"text-muted-foreground",children:"Loading accounts..."}):e.jsx(A,{data:s?.accounts||[],defaultAccount:s?.default??null}),e.jsx("div",{className:"text-sm text-muted-foreground border-t pt-4 mt-4",children:e.jsxs("p",{children:["Accounts are isolated Claude instances with separate sessions.",e.jsx("br",{}),"Use ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"ccs auth create <name>"})," to add new accounts via CLI."]})})]})}export{H as AccountsPage};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-CV3R9pD6.js";import{c as ge,r as p}from"./react-vendor-FspHSO0w.js";import{C as g,a as j,b as N,c as C}from"./card-B-DPlvgo.js";import{c as i,B as I,P as ee,a as je,b as se,C as Ne,u as R,S as m,d as y,g as te,e as B,f as ye,h as be,i as we,j as ve}from"./index-C1W0iP_Z.js";import{K as F,f as k,L as H,H as ke}from"./utils-CzKF5WmX.js";import{O as Ce,p as $e,Q as ae,V as W,Y as re,s as ne,_ as Se,G as De,T as Q,U as Le,Z as le,o as Fe,$ as q,a0 as Te,a1 as Me,a2 as Re,a3 as Pe,b as Ae,a4 as Be}from"./icons-ZmwVoUeR.js";import{R as ie,A as Ue,C as qe,X as Oe,Y as V,T as oe,a as Z,P as Ie,b as Ke,c as Ee}from"./charts-B9Jh-s-X.js";import{u as Ge,a as P}from"./tanstack-Df9bCj5R.js";import"./notifications-B2Pz7lik.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function He({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:F(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:F(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:F(new Date,90),to:new Date}}],className:d}){const[o,c]=ge.useState(!1),n=r=>!s||!s.from||!s.to||!r.from||!r.to?!1:k(s.from,"yyyy-MM-dd")===k(r.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(r.to,"yyyy-MM-dd");return e.jsxs("div",{className:i("flex items-center gap-2",d),children:[a.map(r=>e.jsx(I,{variant:n(r.range)?"default":"outline",size:"sm",onClick:()=>t(r.range),children:r.label},r.label)),e.jsxs(ee,{open:o,onOpenChange:c,children:[e.jsx(je,{asChild:!0,children:e.jsxs(I,{id:"date",variant:"outline",className:i("w-auto min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[k(s.from,"LLL dd, y")," - ",k(s.to,"LLL dd, y")]}):k(s.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(se,{className:"w-auto p-0",align:"end",children:e.jsx(Ne,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function We({data:s,isLoading:t}){const{privacyMode:a}=R();if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 xl:grid-cols-5 gap-4",children:[1,2,3,4,5].map(n=>e.jsx(g,{children:e.jsx(j,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{className:"h-4 w-[100px]"}),e.jsx(m,{className:"h-8 w-[80px]"})]}),e.jsx(m,{className:"h-8 w-8 rounded-lg"})]})})},n))});const d=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),o=s?.totalCost?Math.round(d/s.totalCost*100):0,c=[{title:"Total Tokens",value:s?.totalTokens??0,icon:$e,format:n=>M(n),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:`${M(s?.totalInputTokens??0)} in / ${M(s?.totalOutputTokens??0)} out`},{title:"Total Cost",value:s?.totalCost??0,icon:ae,format:n=>`$${n.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:`$${s?.averageCostPerDay?.toFixed(2)??"0.00"}/day avg`},{title:"Cache Tokens",value:s?.totalCacheTokens??0,icon:W,format:n=>M(n),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:`$${d.toFixed(2)} (${o}% of cost)`},{title:"Input Cost",value:s?.tokenBreakdown?.input?.cost??0,icon:re,format:n=>`$${n.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:`${M(s?.tokenBreakdown?.input?.tokens??0)} tokens`},{title:"Output Cost",value:s?.tokenBreakdown?.output?.cost??0,icon:ne,format:n=>`$${n.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:`${M(s?.tokenBreakdown?.output?.tokens??0)} tokens`}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 xl:grid-cols-5 gap-4",children:c.map((n,r)=>{const x=n.icon;return e.jsx(g,{className:"hover:shadow-md transition-shadow",children:e.jsx(j,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:n.title}),e.jsx("p",{className:i("text-xl font-bold truncate",a&&y),children:n.format(n.value)}),n.subtitle&&e.jsx("p",{className:i("text-[10px] text-muted-foreground truncate",a&&y),children:n.subtitle})]}),e.jsx("div",{className:i("p-2 rounded-lg shrink-0",n.bgColor),children:e.jsx(x,{className:i("h-4 w-4",n.color)})})]})})},r)})})}function M(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function _e({data:s,isLoading:t,granularity:a="daily",className:d}){const{privacyMode:o}=R(),c=p.useMemo(()=>!s||s.length===0?[]:(a==="hourly"?s:[...s].reverse()).map(x=>{const u="hour"in x?x.hour:x.date;return{...x,dateFormatted:ze(u,a),costRounded:Number(x.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(m,{className:i("h-full w-full",d)});if(!s||s.length===0)return e.jsx("div",{className:i("h-full flex items-center justify-center",d),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const n=({x:r,y:x,payload:u,isRight:f})=>{const h=f?`$${u.value}`:X(Number(u.value));return e.jsx("text",{x:r,y:x,dy:4,textAnchor:f?"start":"end",fontSize:12,fill:"currentColor",className:i("fill-muted-foreground",o&&"blur-[4px]"),children:h})};return e.jsx("div",{className:i("w-full h-full",d),children:e.jsx(ie,{width:"100%",height:"100%",children:e.jsxs(Ue,{data:c,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(qe,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Oe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"left",orientation:"left",tick:r=>e.jsx(n,{...r,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:r=>e.jsx(n,{...r,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(oe,{content:({active:r,payload:x,label:u})=>{if(!r||!x||!x.length)return null;const f=x[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:u}),x.map((h,S)=>e.jsxs("p",{className:i("text-sm",o&&y),style:{color:h.color},children:[h.name,":"," ",h.name==="Tokens"?X(Number(h.value)||0):`$${h.value}`]},S)),"requests"in f&&e.jsxs("p",{className:i("text-sm text-muted-foreground mt-1",o&&y),children:["Requests: ",f.requests]})]})}}),e.jsx(Z,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(Z,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function ze(s,t){if(t==="hourly"){const[d,o]=s.split(" ");if(d&&o){const c=new Date(`${d}T${o}:00Z`);return k(c,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?k(a,"MMM yyyy"):k(a,"MMM dd")}function X(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ye({data:s,isLoading:t,className:a}){const{privacyMode:d}=R(),o=p.useMemo(()=>!s||s.length===0?[]:s.map(r=>({name:r.model,value:r.tokens,cost:r.cost,percentage:r.percentage,fill:te(r.model)})),[s]);if(t)return e.jsx(m,{className:i("h-[300px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:i("h-[300px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:"No model data available"})});const c=({active:r,payload:x})=>{if(!r||!x)return null;const u=x;if(!u.length)return null;const f=u[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:f.name}),e.jsxs("p",{className:i("text-muted-foreground",d&&y),children:[Qe(f.value)," (",f.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:i("text-muted-foreground",d&&y),children:["$",f.cost.toFixed(4)]})]})},n=r=>r.percentage>5?`${r.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:i("w-full",a),children:e.jsx(ie,{width:"100%",height:250,children:e.jsxs(Ie,{children:[e.jsx(Ke,{data:o,cx:"50%",cy:"50%",labelLine:!1,label:n,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:o.map((r,x)=>e.jsx(Ee,{fill:r.fill,strokeWidth:1},`cell-${x}`))}),e.jsx(oe,{content:c})]})})})}function Qe(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ve({model:s}){const{privacyMode:t}=R(),a=Ze(s.ioRatio);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(B,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(B,{variant:a.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:i("text-lg font-bold",t&&y),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Cost"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:i("text-lg font-bold",t&&y),children:Je(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Tokens"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:i("space-y-1",t&&y),children:[e.jsx(O,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:re}),e.jsx(O,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:ne}),e.jsx(O,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:W}),e.jsx(O,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:W})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:"Input/Output Ratio"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:a.description})]})]})}function O({label:s,tokens:t,cost:a,color:d,icon:o}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:d}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",a.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(o,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:Xe(t)})]})]})]})}function Ze(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function Xe(s){return s.toLocaleString()}function Je(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function es({data:s,isLoading:t,className:a}){const{privacyMode:d}=R(),o=p.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const c=s.sessions,n=s.total,r=c.reduce((v,b)=>v+(b.inputTokens+b.outputTokens),0),x=Math.round(r/c.length),f=c.reduce((v,b)=>v+b.cost,0)/c.length,h=c[0],S=h?H(new Date(h.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:n,avgTokens:x,avgCost:f,lastActive:S,recentSessions:c.slice(0,3)}},[s]);return t?e.jsxs(g,{className:i("flex flex-col h-full",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsx(m,{className:"h-5 w-32"})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(m,{className:"h-full w-full"})})]}):o?e.jsxs(g,{className:i("flex flex-col h-full shadow-sm",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(j,{className:"px-3 pb-3 pt-0 flex-1 flex flex-col gap-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx(Le,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:o.totalSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Total Sessions"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(le,{className:"w-4 h-4"}),e.jsxs("span",{className:i("text-xl font-bold",d&&y),children:["$",o.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx(Fe,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5",children:o.recentSessions.map(c=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium truncate",title:c.projectPath,children:c.projectPath.split("/").pop()}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:H(new Date(c.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:i("text-right shrink-0 ml-2",d&&y),children:[e.jsxs("div",{className:"font-mono",children:["$",c.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[ss(c.inputTokens+c.outputTokens)," toks"]})]})]},c.sessionId))})]})]})]}):e.jsxs(g,{className:i("flex flex-col h-full",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"No session data available"})})]})}function ss(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function ts({className:s,isLoading:t}){const{data:a,isLoading:d}=ye(),{data:o,isLoading:c,error:n}=be(a?.running);if(t||d||a?.running&&c)return e.jsxs(g,{className:i("flex flex-col h-full",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(m,{className:"h-4 w-[100px]"}),e.jsx(m,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(g,{className:i("flex flex-col h-full border-dashed",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(B,{variant:"secondary",className:"text-[10px] h-5",children:"Offline"})]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Start a CLIProxy session (gemini, codex, agy) to collect stats."})})]});if(n)return e.jsxs(g,{className:i("flex flex-col h-full border-destructive/50",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(B,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:n.message})})]});const x=o?.totalRequests??0,u=o?.quotaExceededCount??0,f=x-u,h=x>0?Math.round(f/x*100):100,S=o?.tokens?.total??0,v=Object.entries(o?.requestsByModel??{}).sort((D,L)=>L[1]-D[1]).slice(0,4),b=v.length>0?v[0][1]:1;return e.jsxs(g,{className:i("flex flex-col h-full overflow-hidden",s),children:[e.jsx(N,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(B,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(le,{className:"h-3 w-3 mr-0.5"}),"Running"]})]})}),e.jsx(j,{className:"p-0 flex-1 min-h-0",children:e.jsx(we,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${h*.88} 88`,strokeLinecap:"round",className:h>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[h,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(x)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:u>0?`${u} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Te,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(S)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:"Total tokens"})]})]})]}),v.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Me,{className:"h-3 w-3"}),"Models Used"]}),e.jsx("div",{className:"space-y-1",children:v.map(([D,L])=>{const K=Math.round(L/b*100),E=as(D);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:D,children:E}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:L})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${K}%`}})})]},D)})})]})]})})})]})}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function as(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}const rs="/api";function w(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),d=String(s.getDate()).padStart(2,"0");return`${t}${a}${d}`}const T={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),$(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),$(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),$(`/usage/monthly?${a}`)},refresh:async()=>{if(!(await fetch(`${rs}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>$("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/insights?${t}`)}};async function $(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const o=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(o.error||a.statusText)}const d=await a.json();return d.data||d}function ns(s){return P({queryKey:["usage","summary",s],queryFn:()=>T.summary(s),staleTime:60*1e3})}function ls(s){return P({queryKey:["usage","trends",s],queryFn:()=>T.trends(s),staleTime:60*1e3})}function is(s){return P({queryKey:["usage","hourly",s],queryFn:()=>T.hourly(s),staleTime:60*1e3})}function os(s){return P({queryKey:["usage","models",s],queryFn:()=>T.models(s),staleTime:60*1e3})}function cs(){const s=Ge();return p.useCallback(async()=>{await T.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function ds(){return P({queryKey:["usage","status"],queryFn:()=>T.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function xs(s){return P({queryKey:["usage","sessions",s],queryFn:()=>T.sessions(s),staleTime:60*1e3})}function us(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function ks(){const{privacyMode:s}=R(),[t,a]=p.useState({from:F(new Date,30),to:new Date}),[d,o]=p.useState(!1),[c,n]=p.useState(null),[r,x]=p.useState(null),[u,f]=p.useState("daily"),h=p.useRef(null),S=cs(),v=async()=>{o(!0);try{await S()}finally{o(!1)}},b={startDate:t?.from,endDate:t?.to},{data:D,isLoading:L}=ns(b),{data:K,isLoading:E}=ls(b),{data:ce,isLoading:de}=is(b),{data:_,isLoading:z}=os(b),{data:xe,isLoading:ue}=xs({...b,limit:3}),{data:G}=ds(),me=p.useCallback(()=>{const l=new Date;a({from:F(l,1),to:l}),f("hourly")},[]),fe=p.useCallback(l=>{a(l),f("daily")},[]),Y=p.useMemo(()=>G?.lastFetch?H(new Date(G.lastFetch),{addSuffix:!0}):null,[G?.lastFetch]),he=p.useCallback((l,A)=>{const U=A.currentTarget.getBoundingClientRect();x({x:U.left+U.width/2,y:U.top+U.height/2}),n(l)},[]),pe=p.useCallback(()=>{n(null),x(null)},[]);return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden px-4 pt-4 pb-50 gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Track usage & insights"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{variant:u==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:me,children:"24H"}),e.jsx(He,{value:t,onChange:fe,presets:[{label:"7D",range:{from:F(new Date,7),to:new Date}},{label:"30D",range:{from:F(new Date,30),to:new Date}},{label:"Month",range:{from:ke(new Date),to:new Date}},{label:"All Time",range:{from:void 0,to:new Date}}]}),Y&&e.jsxs("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:["Updated ",Y]}),e.jsx(I,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:v,disabled:d,children:e.jsx(Re,{className:`w-3.5 h-3.5 ${d?"animate-spin":""}`})})]})]}),e.jsx(We,{data:D,isLoading:L}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 gap-4",children:[e.jsxs(g,{className:"flex flex-col flex-1 min-h-0 max-h-[500px] overflow-hidden shadow-sm",children:[e.jsx(N,{className:"px-3 py-2 shrink-0",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),u==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(_e,{data:u==="hourly"?ce||[]:K||[],isLoading:u==="hourly"?de:E,granularity:u==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto lg:h-[180px] shrink-0",children:[e.jsxs(g,{className:"flex flex-col h-full min-h-0 shadow-sm lg:col-span-4",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ae,{className:"w-4 h-4"}),"Cost by Model"]})}),e.jsx(j,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:z?e.jsx(m,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[..._||[]].sort((l,A)=>A.cost-l.cost).map(l=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:A=>he(l,A),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:te(l.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:l.model})]}),e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:"#335c67",width:`${l.cost>0?l.costBreakdown.input.cost/l.cost*100:0}%`},title:`Input: $${l.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:"#fff3b0",width:`${l.cost>0?l.costBreakdown.output.cost/l.cost*100:0}%`},title:`Output: $${l.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:"#e09f3e",width:`${l.cost>0?l.costBreakdown.cacheCreation.cost/l.cost*100:0}%`},title:`Cache Write: $${l.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:"#9e2a2b",width:`${l.cost>0?l.costBreakdown.cacheRead.cost/l.cost*100:0}%`},title:`Cache Read: $${l.costBreakdown.cacheRead.cost.toFixed(2)}`})]})}),e.jsx("span",{className:i("text-[10px] text-muted-foreground w-14 text-right shrink-0",s&&y),children:us(l.tokens)}),e.jsxs("span",{className:i("font-mono font-medium w-16 text-right shrink-0",s&&y),children:["$",l.cost.toFixed(2)]}),e.jsx(Ae,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},l.model)),e.jsxs("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"#335c67"}}),"Input"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full border border-muted-foreground/30",style:{backgroundColor:"#fff3b0"}}),"Output"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"#e09f3e"}}),"Cache Write"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"#9e2a2b"}}),"Cache Read"]})]})]})})]}),e.jsxs(g,{className:"flex flex-col h-full min-h-0 shadow-sm lg:col-span-2",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Be,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(j,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(Ye,{data:_||[],isLoading:z,className:"h-full w-full"})})]}),e.jsx(es,{data:xe,isLoading:ue,className:"lg:col-span-2"}),e.jsx(ts,{isLoading:L,className:"lg:col-span-2"})]}),e.jsxs(ee,{open:!!c,onOpenChange:l=>!l&&pe(),children:[e.jsx(ve,{asChild:!0,children:e.jsx("div",{ref:h,className:"fixed pointer-events-none",style:{left:r?.x??0,top:r?.y??0,width:1,height:1}})}),e.jsx(se,{className:"w-80 p-3",side:"top",align:"center",children:c&&e.jsx(Ve,{model:c})})]})]})]})}function Cs(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(g,{className:"flex flex-col min-h-[300px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(m,{className:"h-4 w-32"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsx(m,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(g,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(m,{className:"h-4 w-28"})}),e.jsx(j,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(m,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(m,{className:"h-3 w-24"})]}),e.jsx(m,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(g,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(m,{className:"h-4 w-28"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(m,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(m,{className:"w-2 h-2 rounded-full"}),e.jsx(m,{className:"h-3 w-20"})]},s))})]})})]})]})]})}export{ks as AnalyticsPage,Cs as AnalyticsSkeleton};
1
+ import{j as e}from"./radix-ui-CV3R9pD6.js";import{c as ge,r as p}from"./react-vendor-FspHSO0w.js";import{C as g,a as j,b as N,c as C}from"./card-Dh2Mk43l.js";import{c as i,B as I,P as ee,a as je,b as se,C as Ne,u as R,S as m,d as y,g as te,e as B,f as ye,h as be,i as we,j as ve}from"./index-BJVyJi5-.js";import{K as F,f as k,L as H,H as ke}from"./utils-CzKF5WmX.js";import{O as Ce,p as $e,Q as ae,V as W,Y as re,s as ne,_ as Se,G as De,T as Q,U as Le,Z as le,o as Fe,$ as q,a0 as Te,a1 as Me,a2 as Re,a3 as Pe,b as Ae,a4 as Be}from"./icons-ZmwVoUeR.js";import{R as ie,A as Ue,C as qe,X as Oe,Y as V,T as oe,a as Z,P as Ie,b as Ke,c as Ee}from"./charts-B9Jh-s-X.js";import{u as Ge,a as P}from"./tanstack-Df9bCj5R.js";import"./notifications-B2Pz7lik.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function He({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:F(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:F(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:F(new Date,90),to:new Date}}],className:d}){const[o,c]=ge.useState(!1),n=r=>!s||!s.from||!s.to||!r.from||!r.to?!1:k(s.from,"yyyy-MM-dd")===k(r.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(r.to,"yyyy-MM-dd");return e.jsxs("div",{className:i("flex items-center gap-2",d),children:[a.map(r=>e.jsx(I,{variant:n(r.range)?"default":"outline",size:"sm",onClick:()=>t(r.range),children:r.label},r.label)),e.jsxs(ee,{open:o,onOpenChange:c,children:[e.jsx(je,{asChild:!0,children:e.jsxs(I,{id:"date",variant:"outline",className:i("w-auto min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[k(s.from,"LLL dd, y")," - ",k(s.to,"LLL dd, y")]}):k(s.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(se,{className:"w-auto p-0",align:"end",children:e.jsx(Ne,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function We({data:s,isLoading:t}){const{privacyMode:a}=R();if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 xl:grid-cols-5 gap-4",children:[1,2,3,4,5].map(n=>e.jsx(g,{children:e.jsx(j,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{className:"h-4 w-[100px]"}),e.jsx(m,{className:"h-8 w-[80px]"})]}),e.jsx(m,{className:"h-8 w-8 rounded-lg"})]})})},n))});const d=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),o=s?.totalCost?Math.round(d/s.totalCost*100):0,c=[{title:"Total Tokens",value:s?.totalTokens??0,icon:$e,format:n=>M(n),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:`${M(s?.totalInputTokens??0)} in / ${M(s?.totalOutputTokens??0)} out`},{title:"Total Cost",value:s?.totalCost??0,icon:ae,format:n=>`$${n.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:`$${s?.averageCostPerDay?.toFixed(2)??"0.00"}/day avg`},{title:"Cache Tokens",value:s?.totalCacheTokens??0,icon:W,format:n=>M(n),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:`$${d.toFixed(2)} (${o}% of cost)`},{title:"Input Cost",value:s?.tokenBreakdown?.input?.cost??0,icon:re,format:n=>`$${n.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:`${M(s?.tokenBreakdown?.input?.tokens??0)} tokens`},{title:"Output Cost",value:s?.tokenBreakdown?.output?.cost??0,icon:ne,format:n=>`$${n.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:`${M(s?.tokenBreakdown?.output?.tokens??0)} tokens`}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 xl:grid-cols-5 gap-4",children:c.map((n,r)=>{const x=n.icon;return e.jsx(g,{className:"hover:shadow-md transition-shadow",children:e.jsx(j,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:n.title}),e.jsx("p",{className:i("text-xl font-bold truncate",a&&y),children:n.format(n.value)}),n.subtitle&&e.jsx("p",{className:i("text-[10px] text-muted-foreground truncate",a&&y),children:n.subtitle})]}),e.jsx("div",{className:i("p-2 rounded-lg shrink-0",n.bgColor),children:e.jsx(x,{className:i("h-4 w-4",n.color)})})]})})},r)})})}function M(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function _e({data:s,isLoading:t,granularity:a="daily",className:d}){const{privacyMode:o}=R(),c=p.useMemo(()=>!s||s.length===0?[]:(a==="hourly"?s:[...s].reverse()).map(x=>{const u="hour"in x?x.hour:x.date;return{...x,dateFormatted:ze(u,a),costRounded:Number(x.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(m,{className:i("h-full w-full",d)});if(!s||s.length===0)return e.jsx("div",{className:i("h-full flex items-center justify-center",d),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const n=({x:r,y:x,payload:u,isRight:f})=>{const h=f?`$${u.value}`:X(Number(u.value));return e.jsx("text",{x:r,y:x,dy:4,textAnchor:f?"start":"end",fontSize:12,fill:"currentColor",className:i("fill-muted-foreground",o&&"blur-[4px]"),children:h})};return e.jsx("div",{className:i("w-full h-full",d),children:e.jsx(ie,{width:"100%",height:"100%",children:e.jsxs(Ue,{data:c,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(qe,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Oe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"left",orientation:"left",tick:r=>e.jsx(n,{...r,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:r=>e.jsx(n,{...r,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(oe,{content:({active:r,payload:x,label:u})=>{if(!r||!x||!x.length)return null;const f=x[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:u}),x.map((h,S)=>e.jsxs("p",{className:i("text-sm",o&&y),style:{color:h.color},children:[h.name,":"," ",h.name==="Tokens"?X(Number(h.value)||0):`$${h.value}`]},S)),"requests"in f&&e.jsxs("p",{className:i("text-sm text-muted-foreground mt-1",o&&y),children:["Requests: ",f.requests]})]})}}),e.jsx(Z,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(Z,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function ze(s,t){if(t==="hourly"){const[d,o]=s.split(" ");if(d&&o){const c=new Date(`${d}T${o}:00Z`);return k(c,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?k(a,"MMM yyyy"):k(a,"MMM dd")}function X(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ye({data:s,isLoading:t,className:a}){const{privacyMode:d}=R(),o=p.useMemo(()=>!s||s.length===0?[]:s.map(r=>({name:r.model,value:r.tokens,cost:r.cost,percentage:r.percentage,fill:te(r.model)})),[s]);if(t)return e.jsx(m,{className:i("h-[300px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:i("h-[300px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:"No model data available"})});const c=({active:r,payload:x})=>{if(!r||!x)return null;const u=x;if(!u.length)return null;const f=u[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:f.name}),e.jsxs("p",{className:i("text-muted-foreground",d&&y),children:[Qe(f.value)," (",f.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:i("text-muted-foreground",d&&y),children:["$",f.cost.toFixed(4)]})]})},n=r=>r.percentage>5?`${r.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:i("w-full",a),children:e.jsx(ie,{width:"100%",height:250,children:e.jsxs(Ie,{children:[e.jsx(Ke,{data:o,cx:"50%",cy:"50%",labelLine:!1,label:n,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:o.map((r,x)=>e.jsx(Ee,{fill:r.fill,strokeWidth:1},`cell-${x}`))}),e.jsx(oe,{content:c})]})})})}function Qe(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ve({model:s}){const{privacyMode:t}=R(),a=Ze(s.ioRatio);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(B,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(B,{variant:a.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:i("text-lg font-bold",t&&y),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Cost"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:i("text-lg font-bold",t&&y),children:Je(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Tokens"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:i("space-y-1",t&&y),children:[e.jsx(O,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:re}),e.jsx(O,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:ne}),e.jsx(O,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:W}),e.jsx(O,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:W})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:"Input/Output Ratio"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:a.description})]})]})}function O({label:s,tokens:t,cost:a,color:d,icon:o}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:d}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",a.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(o,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:Xe(t)})]})]})]})}function Ze(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function Xe(s){return s.toLocaleString()}function Je(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function es({data:s,isLoading:t,className:a}){const{privacyMode:d}=R(),o=p.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const c=s.sessions,n=s.total,r=c.reduce((v,b)=>v+(b.inputTokens+b.outputTokens),0),x=Math.round(r/c.length),f=c.reduce((v,b)=>v+b.cost,0)/c.length,h=c[0],S=h?H(new Date(h.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:n,avgTokens:x,avgCost:f,lastActive:S,recentSessions:c.slice(0,3)}},[s]);return t?e.jsxs(g,{className:i("flex flex-col h-full",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsx(m,{className:"h-5 w-32"})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(m,{className:"h-full w-full"})})]}):o?e.jsxs(g,{className:i("flex flex-col h-full shadow-sm",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(j,{className:"px-3 pb-3 pt-0 flex-1 flex flex-col gap-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx(Le,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:o.totalSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Total Sessions"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(le,{className:"w-4 h-4"}),e.jsxs("span",{className:i("text-xl font-bold",d&&y),children:["$",o.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx(Fe,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5",children:o.recentSessions.map(c=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium truncate",title:c.projectPath,children:c.projectPath.split("/").pop()}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:H(new Date(c.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:i("text-right shrink-0 ml-2",d&&y),children:[e.jsxs("div",{className:"font-mono",children:["$",c.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[ss(c.inputTokens+c.outputTokens)," toks"]})]})]},c.sessionId))})]})]})]}):e.jsxs(g,{className:i("flex flex-col h-full",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"No session data available"})})]})}function ss(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function ts({className:s,isLoading:t}){const{data:a,isLoading:d}=ye(),{data:o,isLoading:c,error:n}=be(a?.running);if(t||d||a?.running&&c)return e.jsxs(g,{className:i("flex flex-col h-full",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(m,{className:"h-4 w-[100px]"}),e.jsx(m,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(g,{className:i("flex flex-col h-full border-dashed",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(B,{variant:"secondary",className:"text-[10px] h-5",children:"Offline"})]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Start a CLIProxy session (gemini, codex, agy) to collect stats."})})]});if(n)return e.jsxs(g,{className:i("flex flex-col h-full border-destructive/50",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(B,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:n.message})})]});const x=o?.totalRequests??0,u=o?.quotaExceededCount??0,f=x-u,h=x>0?Math.round(f/x*100):100,S=o?.tokens?.total??0,v=Object.entries(o?.requestsByModel??{}).sort((D,L)=>L[1]-D[1]).slice(0,4),b=v.length>0?v[0][1]:1;return e.jsxs(g,{className:i("flex flex-col h-full overflow-hidden",s),children:[e.jsx(N,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(B,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(le,{className:"h-3 w-3 mr-0.5"}),"Running"]})]})}),e.jsx(j,{className:"p-0 flex-1 min-h-0",children:e.jsx(we,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${h*.88} 88`,strokeLinecap:"round",className:h>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[h,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(x)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:u>0?`${u} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Te,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(S)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:"Total tokens"})]})]})]}),v.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Me,{className:"h-3 w-3"}),"Models Used"]}),e.jsx("div",{className:"space-y-1",children:v.map(([D,L])=>{const K=Math.round(L/b*100),E=as(D);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:D,children:E}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:L})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${K}%`}})})]},D)})})]})]})})})]})}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function as(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}const rs="/api";function w(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),d=String(s.getDate()).padStart(2,"0");return`${t}${a}${d}`}const T={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),$(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),$(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),$(`/usage/monthly?${a}`)},refresh:async()=>{if(!(await fetch(`${rs}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>$("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),$(`/usage/insights?${t}`)}};async function $(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const o=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(o.error||a.statusText)}const d=await a.json();return d.data||d}function ns(s){return P({queryKey:["usage","summary",s],queryFn:()=>T.summary(s),staleTime:60*1e3})}function ls(s){return P({queryKey:["usage","trends",s],queryFn:()=>T.trends(s),staleTime:60*1e3})}function is(s){return P({queryKey:["usage","hourly",s],queryFn:()=>T.hourly(s),staleTime:60*1e3})}function os(s){return P({queryKey:["usage","models",s],queryFn:()=>T.models(s),staleTime:60*1e3})}function cs(){const s=Ge();return p.useCallback(async()=>{await T.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function ds(){return P({queryKey:["usage","status"],queryFn:()=>T.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function xs(s){return P({queryKey:["usage","sessions",s],queryFn:()=>T.sessions(s),staleTime:60*1e3})}function us(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function ks(){const{privacyMode:s}=R(),[t,a]=p.useState({from:F(new Date,30),to:new Date}),[d,o]=p.useState(!1),[c,n]=p.useState(null),[r,x]=p.useState(null),[u,f]=p.useState("daily"),h=p.useRef(null),S=cs(),v=async()=>{o(!0);try{await S()}finally{o(!1)}},b={startDate:t?.from,endDate:t?.to},{data:D,isLoading:L}=ns(b),{data:K,isLoading:E}=ls(b),{data:ce,isLoading:de}=is(b),{data:_,isLoading:z}=os(b),{data:xe,isLoading:ue}=xs({...b,limit:3}),{data:G}=ds(),me=p.useCallback(()=>{const l=new Date;a({from:F(l,1),to:l}),f("hourly")},[]),fe=p.useCallback(l=>{a(l),f("daily")},[]),Y=p.useMemo(()=>G?.lastFetch?H(new Date(G.lastFetch),{addSuffix:!0}):null,[G?.lastFetch]),he=p.useCallback((l,A)=>{const U=A.currentTarget.getBoundingClientRect();x({x:U.left+U.width/2,y:U.top+U.height/2}),n(l)},[]),pe=p.useCallback(()=>{n(null),x(null)},[]);return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden px-4 pt-4 pb-50 gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Track usage & insights"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{variant:u==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:me,children:"24H"}),e.jsx(He,{value:t,onChange:fe,presets:[{label:"7D",range:{from:F(new Date,7),to:new Date}},{label:"30D",range:{from:F(new Date,30),to:new Date}},{label:"Month",range:{from:ke(new Date),to:new Date}},{label:"All Time",range:{from:void 0,to:new Date}}]}),Y&&e.jsxs("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:["Updated ",Y]}),e.jsx(I,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:v,disabled:d,children:e.jsx(Re,{className:`w-3.5 h-3.5 ${d?"animate-spin":""}`})})]})]}),e.jsx(We,{data:D,isLoading:L}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 gap-4",children:[e.jsxs(g,{className:"flex flex-col flex-1 min-h-0 max-h-[500px] overflow-hidden shadow-sm",children:[e.jsx(N,{className:"px-3 py-2 shrink-0",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),u==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(j,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(_e,{data:u==="hourly"?ce||[]:K||[],isLoading:u==="hourly"?de:E,granularity:u==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto lg:h-[180px] shrink-0",children:[e.jsxs(g,{className:"flex flex-col h-full min-h-0 shadow-sm lg:col-span-4",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ae,{className:"w-4 h-4"}),"Cost by Model"]})}),e.jsx(j,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:z?e.jsx(m,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[..._||[]].sort((l,A)=>A.cost-l.cost).map(l=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:A=>he(l,A),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:te(l.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:l.model})]}),e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:"#335c67",width:`${l.cost>0?l.costBreakdown.input.cost/l.cost*100:0}%`},title:`Input: $${l.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:"#fff3b0",width:`${l.cost>0?l.costBreakdown.output.cost/l.cost*100:0}%`},title:`Output: $${l.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:"#e09f3e",width:`${l.cost>0?l.costBreakdown.cacheCreation.cost/l.cost*100:0}%`},title:`Cache Write: $${l.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:"#9e2a2b",width:`${l.cost>0?l.costBreakdown.cacheRead.cost/l.cost*100:0}%`},title:`Cache Read: $${l.costBreakdown.cacheRead.cost.toFixed(2)}`})]})}),e.jsx("span",{className:i("text-[10px] text-muted-foreground w-14 text-right shrink-0",s&&y),children:us(l.tokens)}),e.jsxs("span",{className:i("font-mono font-medium w-16 text-right shrink-0",s&&y),children:["$",l.cost.toFixed(2)]}),e.jsx(Ae,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},l.model)),e.jsxs("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"#335c67"}}),"Input"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full border border-muted-foreground/30",style:{backgroundColor:"#fff3b0"}}),"Output"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"#e09f3e"}}),"Cache Write"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"#9e2a2b"}}),"Cache Read"]})]})]})})]}),e.jsxs(g,{className:"flex flex-col h-full min-h-0 shadow-sm lg:col-span-2",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(C,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Be,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(j,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(Ye,{data:_||[],isLoading:z,className:"h-full w-full"})})]}),e.jsx(es,{data:xe,isLoading:ue,className:"lg:col-span-2"}),e.jsx(ts,{isLoading:L,className:"lg:col-span-2"})]}),e.jsxs(ee,{open:!!c,onOpenChange:l=>!l&&pe(),children:[e.jsx(ve,{asChild:!0,children:e.jsx("div",{ref:h,className:"fixed pointer-events-none",style:{left:r?.x??0,top:r?.y??0,width:1,height:1}})}),e.jsx(se,{className:"w-80 p-3",side:"top",align:"center",children:c&&e.jsx(Ve,{model:c})})]})]})]})}function Cs(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(g,{className:"flex flex-col min-h-[300px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(m,{className:"h-4 w-32"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsx(m,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(g,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(m,{className:"h-4 w-28"})}),e.jsx(j,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(m,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(m,{className:"h-3 w-24"})]}),e.jsx(m,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(g,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(m,{className:"h-4 w-28"})}),e.jsx(j,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(m,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(m,{className:"w-2 h-2 rounded-full"}),e.jsx(m,{className:"h-3 w-20"})]},s))})]})})]})]})]})}export{ks as AnalyticsPage,Cs as AnalyticsSkeleton};
@@ -1 +1 @@
1
- import{j as e}from"./radix-ui-CV3R9pD6.js";import{r as d}from"./react-vendor-FspHSO0w.js";import{e as C,B as f,I as E,i as L,L as P,k,T as B,l as Y,m as F,n as M,R as W,o as X,p as G,q as Z,c as ee}from"./index-C1W0iP_Z.js";import{C as _,S as se}from"./confirm-dialog-DZkzZLrs.js";import{u as te,a as ae,b as ne}from"./tanstack-Df9bCj5R.js";import{t as D}from"./notifications-B2Pz7lik.js";import{a2 as T,a5 as $,L as K,a6 as re,E as ie,d as le,J as I,I as ce,a7 as oe,$ as de,a8 as me,a9 as U,aa as xe,k as V,z as ue,D as he}from"./icons-ZmwVoUeR.js";import"./utils-CzKF5WmX.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function fe({profileName:s,data:t,isLoading:n,isSaving:c,hasChanges:u,isRawJsonValid:a,onRefresh:i,onDelete:o,onSave:g}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),t?.path&&e.jsx(C,{variant:"outline",className:"text-xs",children:t.path.replace(/^.*\//,"")})]}),t&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(t.mtime).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:"ghost",size:"sm",onClick:i,disabled:n,children:e.jsx(T,{className:`w-4 h-4 ${n?"animate-spin":""}`})}),o&&e.jsx(f,{variant:"ghost",size:"sm",onClick:o,children:e.jsx($,{className:"w-4 h-4 text-destructive"})}),e.jsx(f,{size:"sm",onClick:g,disabled:c||!u||!a,children:c?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function pe({label:s,...t}){const[n,c]=d.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[s&&e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"relative",children:[e.jsx(E,{type:n?"text":"password",className:"pr-10 font-mono",...t}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>c(!n),tabIndex:-1,children:n?e.jsx(ie,{className:"w-4 h-4"}):e.jsx(le,{className:"w-4 h-4"})})]})]})}function z(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(n=>n.test(s))}function je({currentSettings:s,newEnvKey:t,onNewEnvKeyChange:n,onEnvValueChange:c,onAddEnvVar:u}){return e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-4",children:s?.env&&Object.keys(s.env).length>0?e.jsx(e.Fragment,{children:Object.entries(s.env).map(([a,i])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(P,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[a,z(a)&&e.jsx(C,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:"sensitive"})]}),z(a)?e.jsx(pe,{value:i,onChange:o=>c(a,o.target.value),className:"font-mono text-sm h-8"}):e.jsx(E,{value:i,onChange:o=>c(a,o.target.value),className:"font-mono text-sm h-8"})]},a))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed text-sm",children:[e.jsx("p",{children:"No environment variables configured."}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:"Add variables using the input below or edit the JSON directly."})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(P,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(E,{placeholder:"VARIABLE_NAME",value:t,onChange:a=>n(a.target.value.toUpperCase()),className:"font-mono text-sm h-8",onKeyDown:a=>a.key==="Enter"&&u()}),e.jsx(f,{variant:"outline",size:"sm",className:"h-8",onClick:u,disabled:!t.trim(),children:e.jsx(I,{className:"w-4 h-4"})})]})]})]})}function ge({profileName:s,data:t}){return e.jsx(L,{className:"h-full",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(ce,{className:"w-4 h-4"}),"Profile Information"]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Profile Name"}),e.jsx("span",{className:"font-mono",children:t.profile})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:t.path}),e.jsx(k,{value:t.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Last Modified"}),e.jsx("span",{className:"text-xs",children:new Date(t.mtime).toLocaleString()})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{children:[e.jsx(P,{className:"text-xs text-muted-foreground",children:"Run with profile"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs ",s,' "prompt"']}),e.jsx(k,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(P,{className:"text-xs text-muted-foreground",children:"Set as default"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs default ",s]}),e.jsx(k,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function Ne({profileName:s,data:t,currentSettings:n,newEnvKey:c,onNewEnvKeyChange:u,onEnvValueChange:a,onAddEnvVar:i}){return e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs(B,{defaultValue:"env",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Y,{className:"w-full",children:[e.jsx(F,{value:"env",className:"flex-1",children:"Environment Variables"}),e.jsx(F,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(M,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(je,{currentSettings:n,newEnvKey:c,onNewEnvKeyChange:u,onEnvValueChange:a,onAddEnvVar:i})}),e.jsx(M,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(ge,{profileName:s,data:t})})]})]})})}function ve({profileName:s,onDelete:t}){const[n,c]=d.useState({}),[u,a]=d.useState(!1),[i,o]=d.useState(null),[g,S]=d.useState(""),p=te(),{data:h,isLoading:N,isError:m,refetch:w}=ae({queryKey:["settings",s],queryFn:async()=>{const l=await fetch(`/api/settings/${s}/raw`);if(!l.ok)throw new Error(`Failed to load settings: ${l.status}`);return l.json()}}),x=h?.settings,v=d.useMemo(()=>{if(i!==null)try{return JSON.parse(i)}catch{}if(x)return{...x,env:{...x.env,...n}}},[x,n,i]),y=d.useMemo(()=>i!==null?i:x?JSON.stringify(x,null,2):"",[i,x]),b=d.useCallback(l=>{o(l)},[]),r=(l,j)=>{const A={...v?.env||{},[l]:j};c(q=>({...q,[l]:j})),o(JSON.stringify({...v,env:A},null,2))},H=()=>{if(!g.trim())return;const l=g.trim(),j={...v?.env||{},[l]:""};c(A=>({...A,[l]:""})),o(JSON.stringify({...v,env:j},null,2)),S("")},R=d.useMemo(()=>{try{return JSON.parse(y),!0}catch{return!1}},[y]),Q=d.useMemo(()=>i!==null?i!==JSON.stringify(x,null,2):Object.keys(n).length>0,[i,n,x]),O=ne({mutationFn:async()=>{let l;try{l=JSON.parse(y)}catch{l={...h?.settings,env:{...h?.settings?.env,...n}}}const j=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:l,expectedMtime:h?.mtime})});if(j.status===409)throw new Error("CONFLICT");if(!j.ok)throw new Error("Failed to save");return j.json()},onSuccess:()=>{p.invalidateQueries({queryKey:["settings",s]}),p.invalidateQueries({queryKey:["profiles"]}),c({}),o(null),D.success("Settings saved")},onError:l=>{l.message==="CONFLICT"?a(!0):D.error(l.message)}}),J=async l=>{a(!1),l?(await w(),O.mutate()):(c({}),o(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(fe,{profileName:s,data:h,isLoading:N,isSaving:O.isPending,hasChanges:Q,isRawJsonValid:R,onRefresh:()=>w(),onDelete:t,onSave:()=>O.mutate()}),N?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(K,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):m?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load settings."}),e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>w(),children:[e.jsx(T,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5",children:e.jsx(Ne,{profileName:s,data:h,currentSettings:v,newEnvKey:g,onNewEnvKeyChange:S,onEnvValueChange:r,onAddEnvVar:H})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(oe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(W,{rawJsonContent:y,isRawJsonValid:R,rawJsonEdits:i,settings:x,onChange:b})]})]}),e.jsx(_,{open:u,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>J(!0),onCancel:()=>J(!1)})]},s)}function Te(){const{data:s,isLoading:t,isError:n,refetch:c}=X(),u=G(),[a,i]=d.useState(null),[o,g]=d.useState(""),[S,p]=d.useState(!1),[h,N]=d.useState(null),m=d.useMemo(()=>s?.profiles||[],[s?.profiles]),w=d.useMemo(()=>m.filter(r=>r.name.toLowerCase().includes(o.toLowerCase())),[m,o]),x=d.useMemo(()=>a&&m.some(r=>r.name===a)?a:m.length>0?m[0].name:null,[a,m]),v=r=>{u.mutate(r,{onSuccess:()=>{a===r&&i(null),N(null)}})},y=r=>{p(!1),i(r)},b=m.find(r=>r.name===x);return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"API Profiles"})]}),e.jsxs(f,{size:"sm",onClick:()=>{p(!0)},children:[e.jsx(I,{className:"w-4 h-4 mr-1"}),"New"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(me,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search profiles...",className:"pl-8 h-9",value:o,onChange:r=>g(r.target.value)})]})]}),e.jsx(L,{className:"flex-1",children:t?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading profiles..."}):n?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(U,{className:"w-12 h-12 mx-auto text-destructive/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Failed to load profiles"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Unable to fetch API profiles. Please try again."})]}),e.jsxs(f,{size:"sm",variant:"outline",onClick:()=>c(),children:[e.jsx(T,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):w.length===0?e.jsx("div",{className:"p-4 text-center",children:m.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(xe,{className:"w-12 h-12 mx-auto text-muted-foreground/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"No API profiles yet"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Create your first profile to connect to custom API endpoints"})]}),e.jsxs(f,{size:"sm",variant:"outline",onClick:()=>{p(!0)},children:[e.jsx(I,{className:"w-4 h-4 mr-1"}),"Create Profile"]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground py-4",children:['No profiles match "',o,'"']})}):e.jsx("div",{className:"p-2 space-y-1",children:w.map(r=>e.jsx(we,{profile:r,isSelected:x===r.name,onSelect:()=>{i(r.name)},onDelete:()=>N(r.name)},r.name))})}),m.length>0&&e.jsx("div",{className:"p-3 border-t bg-background text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[m.length," profile",m.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(V,{className:"w-3 h-3 text-green-600"}),m.filter(r=>r.configured).length," configured"]})]})})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:b?e.jsx(ve,{profileName:b.name,onDelete:()=>N(b.name)}):e.jsx(ye,{onCreateClick:()=>{p(!0)}})}),e.jsx(Z,{open:S,onOpenChange:p,onSuccess:y}),e.jsx(_,{open:!!h,title:"Delete Profile",description:`Are you sure you want to delete "${h}"? This will remove the settings file and cannot be undone.`,confirmText:"Delete",variant:"destructive",onConfirm:()=>h&&v(h),onCancel:()=>N(null)})]})}function we({profile:s,isSelected:t,onSelect:n,onDelete:c}){return e.jsxs("div",{className:ee("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:n,children:[s.configured?e.jsx(V,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(U,{className:"w-4 h-4 text-yellow-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground truncate flex-1",children:s.settingsPath}),e.jsx(k,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(f,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:u=>{u.stopPropagation(),c()},children:e.jsx($,{className:"w-3.5 h-3.5 text-destructive"})})]})}function ye({onCreateClick:s}){return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx(ue,{className:"w-16 h-16 mx-auto text-muted-foreground/30 mb-6"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"API Profile Manager"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Configure custom API endpoints for Claude CLI. Connect to proxy services like copilot-api, OpenRouter, or your own API backend."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(f,{onClick:s,className:"w-full",children:[e.jsx(I,{className:"w-4 h-4 mr-2"}),"Create Your First Profile"]}),e.jsx(se,{className:"my-4"}),e.jsxs("div",{className:"text-left space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"What you can configure:"}),e.jsxs("ul",{className:"text-sm text-muted-foreground space-y-1.5",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(C,{variant:"outline",className:"text-xs shrink-0 mt-0.5",children:"URL"}),e.jsx("span",{children:"Custom API base URL endpoint"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(C,{variant:"outline",className:"text-xs shrink-0 mt-0.5",children:"Auth"}),e.jsx("span",{children:"API key or authentication token"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(C,{variant:"outline",className:"text-xs shrink-0 mt-0.5",children:"Models"}),e.jsx("span",{children:"Model mapping for Opus/Sonnet/Haiku"})]})]})]}),e.jsx("div",{className:"pt-4",children:e.jsxs("a",{href:"https://github.com/kaitranntt/ccs#api-profiles",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-xs text-primary hover:underline",children:["Learn more about API profiles",e.jsx(he,{className:"w-3 h-3 ml-1"})]})})]})]})})}export{Te as ApiPage};
1
+ import{j as e}from"./radix-ui-CV3R9pD6.js";import{r as d}from"./react-vendor-FspHSO0w.js";import{e as C,B as f,I as E,i as L,L as P,k,T as B,l as Y,m as F,n as M,R as W,o as X,p as G,q as Z,c as ee}from"./index-BJVyJi5-.js";import{C as _,S as se}from"./confirm-dialog-BCZXbxwW.js";import{u as te,a as ae,b as ne}from"./tanstack-Df9bCj5R.js";import{t as D}from"./notifications-B2Pz7lik.js";import{a2 as T,a5 as $,L as K,a6 as re,E as ie,d as le,J as I,I as ce,a7 as oe,$ as de,a8 as me,a9 as U,aa as xe,k as V,z as ue,D as he}from"./icons-ZmwVoUeR.js";import"./utils-CzKF5WmX.js";import"./form-utils-DP6ILe7Z.js";import"./code-highlight-BoHWVYut.js";function fe({profileName:s,data:t,isLoading:n,isSaving:c,hasChanges:u,isRawJsonValid:a,onRefresh:i,onDelete:o,onSave:g}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),t?.path&&e.jsx(C,{variant:"outline",className:"text-xs",children:t.path.replace(/^.*\//,"")})]}),t&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(t.mtime).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:"ghost",size:"sm",onClick:i,disabled:n,children:e.jsx(T,{className:`w-4 h-4 ${n?"animate-spin":""}`})}),o&&e.jsx(f,{variant:"ghost",size:"sm",onClick:o,children:e.jsx($,{className:"w-4 h-4 text-destructive"})}),e.jsx(f,{size:"sm",onClick:g,disabled:c||!u||!a,children:c?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function pe({label:s,...t}){const[n,c]=d.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[s&&e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"relative",children:[e.jsx(E,{type:n?"text":"password",className:"pr-10 font-mono",...t}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>c(!n),tabIndex:-1,children:n?e.jsx(ie,{className:"w-4 h-4"}):e.jsx(le,{className:"w-4 h-4"})})]})]})}function z(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(n=>n.test(s))}function je({currentSettings:s,newEnvKey:t,onNewEnvKeyChange:n,onEnvValueChange:c,onAddEnvVar:u}){return e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-4",children:s?.env&&Object.keys(s.env).length>0?e.jsx(e.Fragment,{children:Object.entries(s.env).map(([a,i])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(P,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[a,z(a)&&e.jsx(C,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:"sensitive"})]}),z(a)?e.jsx(pe,{value:i,onChange:o=>c(a,o.target.value),className:"font-mono text-sm h-8"}):e.jsx(E,{value:i,onChange:o=>c(a,o.target.value),className:"font-mono text-sm h-8"})]},a))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed text-sm",children:[e.jsx("p",{children:"No environment variables configured."}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:"Add variables using the input below or edit the JSON directly."})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(P,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(E,{placeholder:"VARIABLE_NAME",value:t,onChange:a=>n(a.target.value.toUpperCase()),className:"font-mono text-sm h-8",onKeyDown:a=>a.key==="Enter"&&u()}),e.jsx(f,{variant:"outline",size:"sm",className:"h-8",onClick:u,disabled:!t.trim(),children:e.jsx(I,{className:"w-4 h-4"})})]})]})]})}function ge({profileName:s,data:t}){return e.jsx(L,{className:"h-full",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(ce,{className:"w-4 h-4"}),"Profile Information"]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Profile Name"}),e.jsx("span",{className:"font-mono",children:t.profile})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:t.path}),e.jsx(k,{value:t.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Last Modified"}),e.jsx("span",{className:"text-xs",children:new Date(t.mtime).toLocaleString()})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{children:[e.jsx(P,{className:"text-xs text-muted-foreground",children:"Run with profile"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs ",s,' "prompt"']}),e.jsx(k,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(P,{className:"text-xs text-muted-foreground",children:"Set as default"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs default ",s]}),e.jsx(k,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function Ne({profileName:s,data:t,currentSettings:n,newEnvKey:c,onNewEnvKeyChange:u,onEnvValueChange:a,onAddEnvVar:i}){return e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs(B,{defaultValue:"env",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Y,{className:"w-full",children:[e.jsx(F,{value:"env",className:"flex-1",children:"Environment Variables"}),e.jsx(F,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(M,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(je,{currentSettings:n,newEnvKey:c,onNewEnvKeyChange:u,onEnvValueChange:a,onAddEnvVar:i})}),e.jsx(M,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(ge,{profileName:s,data:t})})]})]})})}function ve({profileName:s,onDelete:t}){const[n,c]=d.useState({}),[u,a]=d.useState(!1),[i,o]=d.useState(null),[g,S]=d.useState(""),p=te(),{data:h,isLoading:N,isError:m,refetch:w}=ae({queryKey:["settings",s],queryFn:async()=>{const l=await fetch(`/api/settings/${s}/raw`);if(!l.ok)throw new Error(`Failed to load settings: ${l.status}`);return l.json()}}),x=h?.settings,v=d.useMemo(()=>{if(i!==null)try{return JSON.parse(i)}catch{}if(x)return{...x,env:{...x.env,...n}}},[x,n,i]),y=d.useMemo(()=>i!==null?i:x?JSON.stringify(x,null,2):"",[i,x]),b=d.useCallback(l=>{o(l)},[]),r=(l,j)=>{const A={...v?.env||{},[l]:j};c(q=>({...q,[l]:j})),o(JSON.stringify({...v,env:A},null,2))},H=()=>{if(!g.trim())return;const l=g.trim(),j={...v?.env||{},[l]:""};c(A=>({...A,[l]:""})),o(JSON.stringify({...v,env:j},null,2)),S("")},R=d.useMemo(()=>{try{return JSON.parse(y),!0}catch{return!1}},[y]),Q=d.useMemo(()=>i!==null?i!==JSON.stringify(x,null,2):Object.keys(n).length>0,[i,n,x]),O=ne({mutationFn:async()=>{let l;try{l=JSON.parse(y)}catch{l={...h?.settings,env:{...h?.settings?.env,...n}}}const j=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:l,expectedMtime:h?.mtime})});if(j.status===409)throw new Error("CONFLICT");if(!j.ok)throw new Error("Failed to save");return j.json()},onSuccess:()=>{p.invalidateQueries({queryKey:["settings",s]}),p.invalidateQueries({queryKey:["profiles"]}),c({}),o(null),D.success("Settings saved")},onError:l=>{l.message==="CONFLICT"?a(!0):D.error(l.message)}}),J=async l=>{a(!1),l?(await w(),O.mutate()):(c({}),o(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(fe,{profileName:s,data:h,isLoading:N,isSaving:O.isPending,hasChanges:Q,isRawJsonValid:R,onRefresh:()=>w(),onDelete:t,onSave:()=>O.mutate()}),N?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(K,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):m?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load settings."}),e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>w(),children:[e.jsx(T,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5",children:e.jsx(Ne,{profileName:s,data:h,currentSettings:v,newEnvKey:g,onNewEnvKeyChange:S,onEnvValueChange:r,onAddEnvVar:H})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(oe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(W,{rawJsonContent:y,isRawJsonValid:R,rawJsonEdits:i,settings:x,onChange:b})]})]}),e.jsx(_,{open:u,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>J(!0),onCancel:()=>J(!1)})]},s)}function Te(){const{data:s,isLoading:t,isError:n,refetch:c}=X(),u=G(),[a,i]=d.useState(null),[o,g]=d.useState(""),[S,p]=d.useState(!1),[h,N]=d.useState(null),m=d.useMemo(()=>s?.profiles||[],[s?.profiles]),w=d.useMemo(()=>m.filter(r=>r.name.toLowerCase().includes(o.toLowerCase())),[m,o]),x=d.useMemo(()=>a&&m.some(r=>r.name===a)?a:m.length>0?m[0].name:null,[a,m]),v=r=>{u.mutate(r,{onSuccess:()=>{a===r&&i(null),N(null)}})},y=r=>{p(!1),i(r)},b=m.find(r=>r.name===x);return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"API Profiles"})]}),e.jsxs(f,{size:"sm",onClick:()=>{p(!0)},children:[e.jsx(I,{className:"w-4 h-4 mr-1"}),"New"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(me,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search profiles...",className:"pl-8 h-9",value:o,onChange:r=>g(r.target.value)})]})]}),e.jsx(L,{className:"flex-1",children:t?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading profiles..."}):n?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(U,{className:"w-12 h-12 mx-auto text-destructive/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Failed to load profiles"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Unable to fetch API profiles. Please try again."})]}),e.jsxs(f,{size:"sm",variant:"outline",onClick:()=>c(),children:[e.jsx(T,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):w.length===0?e.jsx("div",{className:"p-4 text-center",children:m.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(xe,{className:"w-12 h-12 mx-auto text-muted-foreground/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"No API profiles yet"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Create your first profile to connect to custom API endpoints"})]}),e.jsxs(f,{size:"sm",variant:"outline",onClick:()=>{p(!0)},children:[e.jsx(I,{className:"w-4 h-4 mr-1"}),"Create Profile"]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground py-4",children:['No profiles match "',o,'"']})}):e.jsx("div",{className:"p-2 space-y-1",children:w.map(r=>e.jsx(we,{profile:r,isSelected:x===r.name,onSelect:()=>{i(r.name)},onDelete:()=>N(r.name)},r.name))})}),m.length>0&&e.jsx("div",{className:"p-3 border-t bg-background text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[m.length," profile",m.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(V,{className:"w-3 h-3 text-green-600"}),m.filter(r=>r.configured).length," configured"]})]})})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:b?e.jsx(ve,{profileName:b.name,onDelete:()=>N(b.name)}):e.jsx(ye,{onCreateClick:()=>{p(!0)}})}),e.jsx(Z,{open:S,onOpenChange:p,onSuccess:y}),e.jsx(_,{open:!!h,title:"Delete Profile",description:`Are you sure you want to delete "${h}"? This will remove the settings file and cannot be undone.`,confirmText:"Delete",variant:"destructive",onConfirm:()=>h&&v(h),onCancel:()=>N(null)})]})}function we({profile:s,isSelected:t,onSelect:n,onDelete:c}){return e.jsxs("div",{className:ee("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:n,children:[s.configured?e.jsx(V,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(U,{className:"w-4 h-4 text-yellow-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground truncate flex-1",children:s.settingsPath}),e.jsx(k,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(f,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:u=>{u.stopPropagation(),c()},children:e.jsx($,{className:"w-3.5 h-3.5 text-destructive"})})]})}function ye({onCreateClick:s}){return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx(ue,{className:"w-16 h-16 mx-auto text-muted-foreground/30 mb-6"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"API Profile Manager"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Configure custom API endpoints for Claude CLI. Connect to proxy services like copilot-api, OpenRouter, or your own API backend."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(f,{onClick:s,className:"w-full",children:[e.jsx(I,{className:"w-4 h-4 mr-2"}),"Create Your First Profile"]}),e.jsx(se,{className:"my-4"}),e.jsxs("div",{className:"text-left space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"What you can configure:"}),e.jsxs("ul",{className:"text-sm text-muted-foreground space-y-1.5",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(C,{variant:"outline",className:"text-xs shrink-0 mt-0.5",children:"URL"}),e.jsx("span",{children:"Custom API base URL endpoint"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(C,{variant:"outline",className:"text-xs shrink-0 mt-0.5",children:"Auth"}),e.jsx("span",{children:"API key or authentication token"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(C,{variant:"outline",className:"text-xs shrink-0 mt-0.5",children:"Models"}),e.jsx("span",{children:"Model mapping for Opus/Sonnet/Haiku"})]})]})]}),e.jsx("div",{className:"pt-4",children:e.jsxs("a",{href:"https://github.com/kaitranntt/ccs#api-profiles",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-xs text-primary hover:underline",children:["Learn more about API profiles",e.jsx(he,{className:"w-3 h-3 ml-1"})]})})]})]})})}export{Te as ApiPage};
@@ -1 +1 @@
1
- import{j as t}from"./radix-ui-CV3R9pD6.js";import"./react-vendor-FspHSO0w.js";import{c as o}from"./index-C1W0iP_Z.js";function n({className:a,...r}){return t.jsx("div",{"data-slot":"card",className:o("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",a),...r})}function c({className:a,...r}){return t.jsx("div",{"data-slot":"card-header",className:o("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",a),...r})}function i({className:a,...r}){return t.jsx("div",{"data-slot":"card-title",className:o("leading-none font-semibold",a),...r})}function l({className:a,...r}){return t.jsx("div",{"data-slot":"card-content",className:o("px-6",a),...r})}export{n as C,l as a,c as b,i as c};
1
+ import{j as t}from"./radix-ui-CV3R9pD6.js";import"./react-vendor-FspHSO0w.js";import{c as o}from"./index-BJVyJi5-.js";function n({className:a,...r}){return t.jsx("div",{"data-slot":"card",className:o("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",a),...r})}function c({className:a,...r}){return t.jsx("div",{"data-slot":"card-header",className:o("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",a),...r})}function i({className:a,...r}){return t.jsx("div",{"data-slot":"card-title",className:o("leading-none font-semibold",a),...r})}function l({className:a,...r}){return t.jsx("div",{"data-slot":"card-content",className:o("px-6",a),...r})}export{n as C,l as a,c as b,i as c};