@kaitranntt/ccs 7.13.0-dev.1 → 7.13.0
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.
- package/dist/cliproxy/proxy-target-resolver.d.ts +1 -11
- package/dist/cliproxy/proxy-target-resolver.d.ts.map +1 -1
- package/dist/cliproxy/proxy-target-resolver.js +1 -22
- package/dist/cliproxy/proxy-target-resolver.js.map +1 -1
- package/dist/cliproxy/remote-auth-fetcher.d.ts.map +1 -1
- package/dist/cliproxy/remote-auth-fetcher.js +1 -9
- package/dist/cliproxy/remote-auth-fetcher.js.map +1 -1
- package/dist/cliproxy/stats-fetcher.d.ts.map +1 -1
- package/dist/cliproxy/stats-fetcher.js +6 -6
- package/dist/cliproxy/stats-fetcher.js.map +1 -1
- package/dist/config/unified-config-loader.d.ts.map +1 -1
- package/dist/config/unified-config-loader.js +0 -2
- package/dist/config/unified-config-loader.js.map +1 -1
- package/dist/config/unified-config-types.d.ts +1 -8
- package/dist/config/unified-config-types.d.ts.map +1 -1
- package/dist/config/unified-config-types.js.map +1 -1
- package/dist/ui/assets/{accounts-DKm_BUkJ.js → accounts-CYPk9fa-.js} +1 -1
- package/dist/ui/assets/{alert-dialog-BBbNIyvF.js → alert-dialog-BrIFqgMZ.js} +1 -1
- package/dist/ui/assets/{api-p6k8BwWO.js → api-Bi24p47r.js} +1 -1
- package/dist/ui/assets/{auth-section-B4wvcy8z.js → auth-section-3fqp84IR.js} +1 -1
- package/dist/ui/assets/{card-D6fGkasO.js → card-ClMztcJ3.js} +1 -1
- package/dist/ui/assets/cliproxy-CsE7HKWc.js +3 -0
- package/dist/ui/assets/{cliproxy-control-panel-D7gdCCO7.js → cliproxy-control-panel-Cahd6g6e.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-D55Qga4b.js → confirm-dialog-ByvRv_aE.js} +1 -1
- package/dist/ui/assets/{copilot-fwj1xk6l.js → copilot-B4AE6FGx.js} +2 -2
- package/dist/ui/assets/{globalenv-section-DMSdqrn_.js → globalenv-section-CGdnlj1K.js} +1 -1
- package/dist/ui/assets/{health-65nETbIF.js → health-BINs7JKH.js} +1 -1
- package/dist/ui/assets/index-4FYBhG16.js +1 -0
- package/dist/ui/assets/{index-CwDi6WPm.js → index-CV_o8KZD.js} +1 -1
- package/dist/ui/assets/{index-BrijlHVl.js → index-Cf72mW4U.js} +1 -1
- package/dist/ui/assets/{index-8HAJX3-Y.js → index-DXF1Z58h.js} +2 -2
- package/dist/ui/assets/{shared-CMWj9K3T.js → shared-bCN7WjG_.js} +1 -1
- package/dist/ui/assets/{switch-D_o-N1Sa.js → switch-Big41pQ7.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/cliproxy-DuWY_mzK.js +0 -3
- package/dist/ui/assets/index-Dc8X9bLV.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-
|
|
2
|
-
import{j as e}from"./radix-ui-uXQB-q0u.js";import{B as b,a as v,O as re,Q as ce,U as de,V as me,a5 as ye,a6 as be,W as K,G as Y,i as J,L as C,I as ae,m as ue,at as Ce,au as Se,S as y,D as ke,E as Fe,F as z,c as W}from"./index-8HAJX3-Y.js";import{r as g}from"./react-vendor-B_CU-WTZ.js";import{u as Pe,a as M,b as S}from"./tanstack-Coed0rqz.js";import{S as X,C as Me}from"./confirm-dialog-D55Qga4b.js";import{a0 as xe,L as Z,aa as Ae,j as Le,Q as Ee,Z as ne,I as Te,X as Re,T as he,ad as _e,a as Oe,_ as Ie,ai as qe,ao as ie,K as De,s as Ue,as as Qe,n as pe,o as fe}from"./icons-CwFZAiDB.js";import{S as H}from"./switch-D_o-N1Sa.js";import{t as A}from"./notifications-dJQY2-U6.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";import"./alert-dialog-BBbNIyvF.js";const j="/api";async function Ke(){const s=await fetch(`${j}/copilot/status`);if(!s.ok)throw new Error("Failed to fetch copilot status");return s.json()}async function Je(){const s=await fetch(`${j}/copilot/config`);if(!s.ok)throw new Error("Failed to fetch copilot config");return s.json()}async function $e(){const s=await fetch(`${j}/copilot/models`);if(!s.ok)throw new Error("Failed to fetch copilot models");return s.json()}async function Ge(){const s=await fetch(`${j}/copilot/settings/raw`);if(!s.ok)throw new Error("Failed to fetch copilot raw settings");return s.json()}async function Be(s){const t=await fetch(`${j}/copilot/config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!t.ok)throw new Error("Failed to update copilot config");return t.json()}async function ze(s){const t=await fetch(`${j}/copilot/settings/raw`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(t.status===409)throw new Error("CONFLICT");if(!t.ok)throw new Error("Failed to save copilot raw settings");return t.json()}async function He(){const s=await fetch(`${j}/copilot/auth/start`,{method:"POST"});if(!s.ok)throw new Error("Failed to start auth");return s.json()}async function Ve(){const s=await fetch(`${j}/copilot/daemon/start`,{method:"POST"});if(!s.ok)throw new Error("Failed to start daemon");return s.json()}async function We(){const s=await fetch(`${j}/copilot/daemon/stop`,{method:"POST"});if(!s.ok)throw new Error("Failed to stop daemon");return s.json()}async function Xe(){const s=await fetch(`${j}/copilot/info`);if(!s.ok)throw new Error("Failed to fetch copilot info");return s.json()}async function Ye(s){const t=await fetch(`${j}/copilot/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s?{version:s}:{})});if(!t.ok)throw new Error("Failed to install copilot-api");return t.json()}function ge(){const s=Pe(),t=M({queryKey:["copilot-status"],queryFn:Ke,refetchInterval:5e3}),l=M({queryKey:["copilot-config"],queryFn:Je}),c=M({queryKey:["copilot-models"],queryFn:$e}),a=M({queryKey:["copilot-raw-settings"],queryFn:Ge}),r=M({queryKey:["copilot-info"],queryFn:Xe}),o=S({mutationFn:Be,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]}),s.invalidateQueries({queryKey:["copilot-config"]}),s.invalidateQueries({queryKey:["copilot-raw-settings"]})}}),i=S({mutationFn:ze,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]}),s.invalidateQueries({queryKey:["copilot-config"]}),s.invalidateQueries({queryKey:["copilot-raw-settings"]})}}),m=S({mutationFn:He,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]})}}),h=S({mutationFn:Ve,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]})}}),x=S({mutationFn:We,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]})}}),n=S({mutationFn:Ye,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]}),s.invalidateQueries({queryKey:["copilot-info"]})}});return g.useMemo(()=>({status:t.data,statusLoading:t.isLoading,statusError:t.error,refetchStatus:t.refetch,config:l.data,configLoading:l.isLoading,models:c.data?.models??[],currentModel:c.data?.current,modelsLoading:c.isLoading,rawSettings:a.data,rawSettingsLoading:a.isLoading,refetchRawSettings:a.refetch,updateConfig:o.mutate,updateConfigAsync:o.mutateAsync,isUpdating:o.isPending,saveRawSettings:i.mutate,saveRawSettingsAsync:i.mutateAsync,isSavingRawSettings:i.isPending,startAuth:m.mutate,startAuthAsync:m.mutateAsync,isAuthenticating:m.isPending,authResult:m.data,startDaemon:h.mutate,isStartingDaemon:h.isPending,stopDaemon:x.mutate,isStoppingDaemon:x.isPending,info:r.data,infoLoading:r.isLoading,refetchInfo:r.refetch,install:n.mutate,installAsync:n.mutateAsync,isInstalling:n.isPending}),[t.data,t.isLoading,t.error,t.refetch,l.data,l.isLoading,c.data,c.isLoading,a.data,a.isLoading,a.refetch,o.mutate,o.mutateAsync,o.isPending,i.mutate,i.mutateAsync,i.isPending,m.mutate,m.mutateAsync,m.isPending,m.data,h.mutate,h.isPending,x.mutate,x.isPending,r.data,r.isLoading,r.refetch,n.mutate,n.mutateAsync,n.isPending])}function Ze({rawSettings:s,rawSettingsLoading:t,isUpdating:l,isSavingRawSettings:c,hasChanges:a,isRawJsonValid:r,onRefresh:o,onSave:i}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Copilot Configuration"}),s&&e.jsx(b,{variant:"outline",className:"text-xs",children:"copilot.settings.json"})]}),s&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified:"," ",s.exists?new Date(s.mtime).toLocaleString():"Never saved"]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{variant:"ghost",size:"sm",onClick:o,disabled:t,children:e.jsx(xe,{className:`w-4 h-4 ${t?"animate-spin":""}`})}),e.jsx(v,{size:"sm",onClick:i,disabled:l||c||!a||!r,children:l||c?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}const es=[{name:"GPT-4.1 (Free)",description:"Free tier - no premium usage",default:"gpt-4.1",opus:"gpt-4.1",sonnet:"gpt-4.1",haiku:"gpt-4.1"},{name:"GPT-5 Mini (Free)",description:"Free tier - lightweight model",default:"gpt-5-mini",opus:"gpt-5-mini",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"},{name:"Raptor Mini (Free)",description:"Free tier - fine-tuned for coding",default:"raptor-mini",opus:"raptor-mini",sonnet:"raptor-mini",haiku:"raptor-mini"}],ss=[{name:"Claude Opus 4.5",description:"Pro+ (3x) - Most capable reasoning",default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"},{name:"Claude Sonnet 4.5",description:"Pro+ (1x) - Balanced performance",default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"},{name:"GPT-5.2",description:"Pro+ (1x) - Latest OpenAI (Preview)",default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"},{name:"GPT-5.1 Codex Max",description:"Pro+ (1x) - Best for coding",default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex",haiku:"gpt-5.1-codex-mini"},{name:"Gemini 2.5 Pro",description:"Pro+ (1x) - Google latest",default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-3-flash"}];function le(s){switch(s){case"free":return"bg-green-100 text-green-700 border-green-200";case"pro":return"bg-blue-100 text-blue-700 border-blue-200";case"pro+":return"bg-purple-100 text-purple-700 border-purple-200";case"business":return"bg-orange-100 text-orange-700 border-orange-200";case"enterprise":return"bg-red-100 text-red-700 border-red-200";default:return"bg-muted text-muted-foreground"}}function ts(s){return s==null?null:s===0?"Free":s<1?`${s}x`:s===1?"1x":`${s}x`}function D({label:s,description:t,value:l,onChange:c,models:a,disabled:r}){const o=a.find(i=>i.id===l);return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:s}),t&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:t})]}),e.jsxs(re,{value:l||"",onValueChange:c,disabled:r,children:[e.jsx(ce,{className:"h-9",children:e.jsx(de,{placeholder:"Select model",children:l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:l}),o?.minPlan&&e.jsx(b,{variant:"outline",className:`text-[9px] px-1 py-0 h-4 ${le(o.minPlan)}`,children:o.minPlan})]})})}),e.jsx(me,{className:"max-h-[300px]",children:e.jsxs(ye,{children:[e.jsxs(be,{className:"text-xs text-muted-foreground",children:["Available Models (",a.length,")"]}),a.map(i=>e.jsx(K,{value:i.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:i.name||i.id}),i.minPlan&&e.jsx(b,{variant:"outline",className:`text-[9px] px-1 py-0 h-4 ${le(i.minPlan)}`,children:i.minPlan}),i.multiplier!==void 0&&e.jsx("span",{className:"text-[9px] text-muted-foreground",children:ts(i.multiplier)}),i.preview&&e.jsx(b,{variant:"secondary",className:"text-[9px] px-1 py-0 h-4",children:"Preview"}),l===i.id&&e.jsx(Le,{className:"w-3 h-3 text-primary ml-auto"})]})},i.id))]})})]})]})}function as({currentModel:s,opusModel:t,sonnetModel:l,haikuModel:c,models:a,modelsLoading:r,onApplyPreset:o,onUpdateModel:i,onUpdateOpusModel:m,onUpdateSonnetModel:h,onUpdateHaikuModel:x}){return e.jsx(Y,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(J,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Ee,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Apply pre-configured model mappings"}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(b,{variant:"outline",className:"text-[10px] bg-green-100 text-green-700 border-green-200",children:"Free Tier"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"No premium usage count"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:es.map(n=>e.jsxs(v,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>o(n),title:n.description,children:[e.jsx(ne,{className:"w-3 h-3 text-green-600"}),n.name]},n.name))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(b,{variant:"outline",className:"text-[10px] bg-blue-100 text-blue-700 border-blue-200",children:"Pro+ Required"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Uses premium request quota"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ss.map(n=>e.jsxs(v,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>o(n),title:n.description,children:[e.jsx(ne,{className:"w-3 h-3"}),n.name]},n.name))})]})]}),e.jsx(X,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Model Mapping"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Configure which models to use for each tier"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{label:"Default Model",description:"Used when no specific tier is requested",value:s,onChange:i,models:a,disabled:r}),e.jsx(D,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:t||s,onChange:m,models:a,disabled:r}),e.jsx(D,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:l||s,onChange:h,models:a,disabled:r}),e.jsx(D,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:c||s,onChange:x,models:a,disabled:r})]})]})]})})})}function ns({enabled:s,autoStart:t,port:l,accountType:c,rateLimit:a,waitOnLimit:r,onUpdateEnabled:o,onUpdateAutoStart:i,onUpdatePort:m,onUpdateAccountType:h,onUpdateRateLimit:x,onUpdateWaitOnLimit:n}){return e.jsx(Y,{value:"settings",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(J,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{htmlFor:"enabled",className:"text-sm font-medium",children:"Enable Copilot"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Allow using GitHub Copilot subscription"})]}),e.jsx(H,{id:"enabled",checked:s,onCheckedChange:o})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Basic Settings"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"port",className:"text-xs",children:"Port"}),e.jsx(ae,{id:"port",type:"number",value:l,onChange:N=>m(parseInt(N.target.value,10)),min:1024,max:65535,className:"max-w-[150px] h-8"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"account-type",className:"text-xs",children:"Account Type"}),e.jsxs(re,{value:c,onValueChange:h,children:[e.jsx(ce,{id:"account-type",className:"max-w-[150px] h-8",children:e.jsx(de,{})}),e.jsxs(me,{children:[e.jsx(K,{value:"individual",children:"Individual"}),e.jsx(K,{value:"business",children:"Business"}),e.jsx(K,{value:"enterprise",children:"Enterprise"})]})]})]})]}),e.jsx(X,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Rate Limiting"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"rate-limit",className:"text-xs",children:"Rate Limit (seconds)"}),e.jsx(ae,{id:"rate-limit",type:"number",value:a,onChange:N=>x(N.target.value),placeholder:"No limit",min:0,className:"max-w-[150px] h-8"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{htmlFor:"wait-on-limit",className:"text-xs",children:"Wait on Rate Limit"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Wait instead of error when limit hit"})]}),e.jsx(H,{id:"wait-on-limit",checked:r,onCheckedChange:n})]})]}),e.jsx(X,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Daemon Settings"}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{htmlFor:"auto-start",className:"text-xs",children:"Auto-start Daemon"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Start copilot-api when using profile"})]}),e.jsx(H,{id:"auto-start",checked:t,onCheckedChange:i})]})]})]})})})}function U({label:s,command:t}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:s}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:t}),e.jsx(ue,{value:t,size:"icon",className:"h-6 w-6"})]})]})}function is({rawSettings:s}){return e.jsx(Y,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(J,{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(Te,{className:"w-4 h-4"}),"Configuration Info"]}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",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:"Provider"}),e.jsx("span",{className:"font-mono",children:"GitHub Copilot"})]}),s&&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:"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:s.path}),e.jsx(ue,{value:s.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:"Status"}),e.jsx(b,{variant:"outline",className:s.exists?"w-fit text-green-600 border-green-200 bg-green-50":"w-fit text-muted-foreground",children:s.exists?"File exists":"Using defaults"})]})]})]})]}),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.jsx(U,{label:"Run with Copilot",command:"ccs copilot"}),e.jsx(U,{label:"Authenticate",command:"ccs copilot auth"}),e.jsx(U,{label:"Start daemon",command:"ccs copilot --start"}),e.jsx(U,{label:"Stop daemon",command:"ccs copilot --stop"})]})]})]})})})}const ls=g.lazy(()=>Se(()=>import("./index-8HAJX3-Y.js").then(s=>s.aE),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(s=>({default:s.CodeEditor})));function os({rawJsonContent:s,isRawJsonValid:t,rawJsonEdits:l,rawSettingsEnv:c,onChange:a,missingRequiredFields:r=[]}){const o=r.length>0;return e.jsx(g.Suspense,{fallback:e.jsxs("div",{className:"flex items-center justify-center h-full",children:[e.jsx(Z,{className:"w-6 h-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Loading editor..."})]}),children:e.jsxs("div",{className:"h-full flex flex-col",children:[!t&&l!==null&&e.jsxs("div",{className:"mb-2 px-3 py-2 bg-destructive/10 text-destructive text-sm rounded-md flex items-center gap-2 mx-6 mt-4 shrink-0",children:[e.jsx(Re,{className:"w-4 h-4"}),"Invalid JSON syntax"]}),t&&o&&e.jsxs("div",{className:"mb-2 px-3 py-2 bg-warning/10 text-warning-foreground text-sm rounded-md flex items-start gap-2 mx-6 mt-4 shrink-0 border border-warning/20",children:[e.jsx(he,{className:"w-4 h-4 mt-0.5 text-amber-500 shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-amber-600 dark:text-amber-400",children:"Missing required fields:"})," ",e.jsx("code",{className:"text-xs bg-muted px-1 py-0.5 rounded",children:r.join(", ")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"These fields will use default values at runtime."})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden px-6 pb-4 pt-4",children:e.jsx("div",{className:"h-full border rounded-md overflow-hidden bg-background",children:e.jsx(ls,{value:s,onChange:a,language:"json",minHeight:"100%"})})}),e.jsx("div",{className:"mx-6 mb-4",children:e.jsx("div",{className:"border rounded-md overflow-hidden",children:e.jsx(Ce,{profileEnv:c})})})]})})}const rs=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function oe(s){const t=s?.env||{};return rs.filter(l=>!t[l]?.trim())}function cs(){const{config:s,configLoading:t,models:l,modelsLoading:c,rawSettings:a,rawSettingsLoading:r,updateConfigAsync:o,isUpdating:i,saveRawSettingsAsync:m,isSavingRawSettings:h,refetchRawSettings:x}=ge(),[n,N]=g.useState({}),[f,k]=g.useState(null),[$,L]=g.useState(!1),E=n.enabled??s?.enabled??!1,T=n.autoStart??s?.auto_start??!1,F=n.port??s?.port??4141,R=n.accountType??s?.account_type??"individual",_=n.model??s?.model??"claude-opus-4-5-20250514",p=n.rateLimit??s?.rate_limit?.toString()??"",O=n.waitOnLimit??s?.wait_on_limit??!0,I=n.opusModel??s?.opus_model??"",q=n.sonnetModel??s?.sonnet_model??"",P=n.haikuModel??s?.haiku_model??"",G=(u,w)=>{N(we=>({...we,[u]:w}))},B=u=>{N(w=>({...w,model:u.default,opusModel:u.opus,sonnetModel:u.sonnet,haikuModel:u.haiku})),A.success(`Applied "${u.name}" preset`)},d=g.useMemo(()=>f!==null?f:a?.settings?JSON.stringify(a.settings,null,2):`{
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DXF1Z58h.js","assets/radix-ui-uXQB-q0u.js","assets/react-vendor-B_CU-WTZ.js","assets/tanstack-Coed0rqz.js","assets/notifications-dJQY2-U6.js","assets/utils-CzKF5WmX.js","assets/icons-CwFZAiDB.js","assets/form-utils-kUVlZZAO.js","assets/code-highlight-DKN39ySy.js","assets/index-oS2cgEFl.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as e}from"./radix-ui-uXQB-q0u.js";import{B as b,a as v,O as re,Q as ce,U as de,V as me,a5 as ye,a6 as be,W as K,G as Y,i as J,L as C,I as ae,m as ue,at as Ce,au as Se,S as y,D as ke,E as Fe,F as z,c as W}from"./index-DXF1Z58h.js";import{r as g}from"./react-vendor-B_CU-WTZ.js";import{u as Pe,a as M,b as S}from"./tanstack-Coed0rqz.js";import{S as X,C as Me}from"./confirm-dialog-ByvRv_aE.js";import{a0 as xe,L as Z,aa as Ae,j as Le,Q as Ee,Z as ne,I as Te,X as Re,T as he,ad as _e,a as Oe,_ as Ie,ai as qe,ao as ie,K as De,s as Ue,as as Qe,n as pe,o as fe}from"./icons-CwFZAiDB.js";import{S as H}from"./switch-Big41pQ7.js";import{t as A}from"./notifications-dJQY2-U6.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";import"./alert-dialog-BrIFqgMZ.js";const j="/api";async function Ke(){const s=await fetch(`${j}/copilot/status`);if(!s.ok)throw new Error("Failed to fetch copilot status");return s.json()}async function Je(){const s=await fetch(`${j}/copilot/config`);if(!s.ok)throw new Error("Failed to fetch copilot config");return s.json()}async function $e(){const s=await fetch(`${j}/copilot/models`);if(!s.ok)throw new Error("Failed to fetch copilot models");return s.json()}async function Ge(){const s=await fetch(`${j}/copilot/settings/raw`);if(!s.ok)throw new Error("Failed to fetch copilot raw settings");return s.json()}async function Be(s){const t=await fetch(`${j}/copilot/config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!t.ok)throw new Error("Failed to update copilot config");return t.json()}async function ze(s){const t=await fetch(`${j}/copilot/settings/raw`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(t.status===409)throw new Error("CONFLICT");if(!t.ok)throw new Error("Failed to save copilot raw settings");return t.json()}async function He(){const s=await fetch(`${j}/copilot/auth/start`,{method:"POST"});if(!s.ok)throw new Error("Failed to start auth");return s.json()}async function Ve(){const s=await fetch(`${j}/copilot/daemon/start`,{method:"POST"});if(!s.ok)throw new Error("Failed to start daemon");return s.json()}async function We(){const s=await fetch(`${j}/copilot/daemon/stop`,{method:"POST"});if(!s.ok)throw new Error("Failed to stop daemon");return s.json()}async function Xe(){const s=await fetch(`${j}/copilot/info`);if(!s.ok)throw new Error("Failed to fetch copilot info");return s.json()}async function Ye(s){const t=await fetch(`${j}/copilot/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s?{version:s}:{})});if(!t.ok)throw new Error("Failed to install copilot-api");return t.json()}function ge(){const s=Pe(),t=M({queryKey:["copilot-status"],queryFn:Ke,refetchInterval:5e3}),l=M({queryKey:["copilot-config"],queryFn:Je}),c=M({queryKey:["copilot-models"],queryFn:$e}),a=M({queryKey:["copilot-raw-settings"],queryFn:Ge}),r=M({queryKey:["copilot-info"],queryFn:Xe}),o=S({mutationFn:Be,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]}),s.invalidateQueries({queryKey:["copilot-config"]}),s.invalidateQueries({queryKey:["copilot-raw-settings"]})}}),i=S({mutationFn:ze,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]}),s.invalidateQueries({queryKey:["copilot-config"]}),s.invalidateQueries({queryKey:["copilot-raw-settings"]})}}),m=S({mutationFn:He,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]})}}),h=S({mutationFn:Ve,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]})}}),x=S({mutationFn:We,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]})}}),n=S({mutationFn:Ye,onSuccess:()=>{s.invalidateQueries({queryKey:["copilot-status"]}),s.invalidateQueries({queryKey:["copilot-info"]})}});return g.useMemo(()=>({status:t.data,statusLoading:t.isLoading,statusError:t.error,refetchStatus:t.refetch,config:l.data,configLoading:l.isLoading,models:c.data?.models??[],currentModel:c.data?.current,modelsLoading:c.isLoading,rawSettings:a.data,rawSettingsLoading:a.isLoading,refetchRawSettings:a.refetch,updateConfig:o.mutate,updateConfigAsync:o.mutateAsync,isUpdating:o.isPending,saveRawSettings:i.mutate,saveRawSettingsAsync:i.mutateAsync,isSavingRawSettings:i.isPending,startAuth:m.mutate,startAuthAsync:m.mutateAsync,isAuthenticating:m.isPending,authResult:m.data,startDaemon:h.mutate,isStartingDaemon:h.isPending,stopDaemon:x.mutate,isStoppingDaemon:x.isPending,info:r.data,infoLoading:r.isLoading,refetchInfo:r.refetch,install:n.mutate,installAsync:n.mutateAsync,isInstalling:n.isPending}),[t.data,t.isLoading,t.error,t.refetch,l.data,l.isLoading,c.data,c.isLoading,a.data,a.isLoading,a.refetch,o.mutate,o.mutateAsync,o.isPending,i.mutate,i.mutateAsync,i.isPending,m.mutate,m.mutateAsync,m.isPending,m.data,h.mutate,h.isPending,x.mutate,x.isPending,r.data,r.isLoading,r.refetch,n.mutate,n.mutateAsync,n.isPending])}function Ze({rawSettings:s,rawSettingsLoading:t,isUpdating:l,isSavingRawSettings:c,hasChanges:a,isRawJsonValid:r,onRefresh:o,onSave:i}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Copilot Configuration"}),s&&e.jsx(b,{variant:"outline",className:"text-xs",children:"copilot.settings.json"})]}),s&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified:"," ",s.exists?new Date(s.mtime).toLocaleString():"Never saved"]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{variant:"ghost",size:"sm",onClick:o,disabled:t,children:e.jsx(xe,{className:`w-4 h-4 ${t?"animate-spin":""}`})}),e.jsx(v,{size:"sm",onClick:i,disabled:l||c||!a||!r,children:l||c?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}const es=[{name:"GPT-4.1 (Free)",description:"Free tier - no premium usage",default:"gpt-4.1",opus:"gpt-4.1",sonnet:"gpt-4.1",haiku:"gpt-4.1"},{name:"GPT-5 Mini (Free)",description:"Free tier - lightweight model",default:"gpt-5-mini",opus:"gpt-5-mini",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"},{name:"Raptor Mini (Free)",description:"Free tier - fine-tuned for coding",default:"raptor-mini",opus:"raptor-mini",sonnet:"raptor-mini",haiku:"raptor-mini"}],ss=[{name:"Claude Opus 4.5",description:"Pro+ (3x) - Most capable reasoning",default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"},{name:"Claude Sonnet 4.5",description:"Pro+ (1x) - Balanced performance",default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"},{name:"GPT-5.2",description:"Pro+ (1x) - Latest OpenAI (Preview)",default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"},{name:"GPT-5.1 Codex Max",description:"Pro+ (1x) - Best for coding",default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex",haiku:"gpt-5.1-codex-mini"},{name:"Gemini 2.5 Pro",description:"Pro+ (1x) - Google latest",default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-3-flash"}];function le(s){switch(s){case"free":return"bg-green-100 text-green-700 border-green-200";case"pro":return"bg-blue-100 text-blue-700 border-blue-200";case"pro+":return"bg-purple-100 text-purple-700 border-purple-200";case"business":return"bg-orange-100 text-orange-700 border-orange-200";case"enterprise":return"bg-red-100 text-red-700 border-red-200";default:return"bg-muted text-muted-foreground"}}function ts(s){return s==null?null:s===0?"Free":s<1?`${s}x`:s===1?"1x":`${s}x`}function D({label:s,description:t,value:l,onChange:c,models:a,disabled:r}){const o=a.find(i=>i.id===l);return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:s}),t&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:t})]}),e.jsxs(re,{value:l||"",onValueChange:c,disabled:r,children:[e.jsx(ce,{className:"h-9",children:e.jsx(de,{placeholder:"Select model",children:l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:l}),o?.minPlan&&e.jsx(b,{variant:"outline",className:`text-[9px] px-1 py-0 h-4 ${le(o.minPlan)}`,children:o.minPlan})]})})}),e.jsx(me,{className:"max-h-[300px]",children:e.jsxs(ye,{children:[e.jsxs(be,{className:"text-xs text-muted-foreground",children:["Available Models (",a.length,")"]}),a.map(i=>e.jsx(K,{value:i.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:i.name||i.id}),i.minPlan&&e.jsx(b,{variant:"outline",className:`text-[9px] px-1 py-0 h-4 ${le(i.minPlan)}`,children:i.minPlan}),i.multiplier!==void 0&&e.jsx("span",{className:"text-[9px] text-muted-foreground",children:ts(i.multiplier)}),i.preview&&e.jsx(b,{variant:"secondary",className:"text-[9px] px-1 py-0 h-4",children:"Preview"}),l===i.id&&e.jsx(Le,{className:"w-3 h-3 text-primary ml-auto"})]})},i.id))]})})]})]})}function as({currentModel:s,opusModel:t,sonnetModel:l,haikuModel:c,models:a,modelsLoading:r,onApplyPreset:o,onUpdateModel:i,onUpdateOpusModel:m,onUpdateSonnetModel:h,onUpdateHaikuModel:x}){return e.jsx(Y,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(J,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Ee,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Apply pre-configured model mappings"}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(b,{variant:"outline",className:"text-[10px] bg-green-100 text-green-700 border-green-200",children:"Free Tier"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"No premium usage count"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:es.map(n=>e.jsxs(v,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>o(n),title:n.description,children:[e.jsx(ne,{className:"w-3 h-3 text-green-600"}),n.name]},n.name))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(b,{variant:"outline",className:"text-[10px] bg-blue-100 text-blue-700 border-blue-200",children:"Pro+ Required"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Uses premium request quota"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ss.map(n=>e.jsxs(v,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>o(n),title:n.description,children:[e.jsx(ne,{className:"w-3 h-3"}),n.name]},n.name))})]})]}),e.jsx(X,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Model Mapping"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Configure which models to use for each tier"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(D,{label:"Default Model",description:"Used when no specific tier is requested",value:s,onChange:i,models:a,disabled:r}),e.jsx(D,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:t||s,onChange:m,models:a,disabled:r}),e.jsx(D,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:l||s,onChange:h,models:a,disabled:r}),e.jsx(D,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:c||s,onChange:x,models:a,disabled:r})]})]})]})})})}function ns({enabled:s,autoStart:t,port:l,accountType:c,rateLimit:a,waitOnLimit:r,onUpdateEnabled:o,onUpdateAutoStart:i,onUpdatePort:m,onUpdateAccountType:h,onUpdateRateLimit:x,onUpdateWaitOnLimit:n}){return e.jsx(Y,{value:"settings",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(J,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{htmlFor:"enabled",className:"text-sm font-medium",children:"Enable Copilot"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Allow using GitHub Copilot subscription"})]}),e.jsx(H,{id:"enabled",checked:s,onCheckedChange:o})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Basic Settings"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"port",className:"text-xs",children:"Port"}),e.jsx(ae,{id:"port",type:"number",value:l,onChange:N=>m(parseInt(N.target.value,10)),min:1024,max:65535,className:"max-w-[150px] h-8"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"account-type",className:"text-xs",children:"Account Type"}),e.jsxs(re,{value:c,onValueChange:h,children:[e.jsx(ce,{id:"account-type",className:"max-w-[150px] h-8",children:e.jsx(de,{})}),e.jsxs(me,{children:[e.jsx(K,{value:"individual",children:"Individual"}),e.jsx(K,{value:"business",children:"Business"}),e.jsx(K,{value:"enterprise",children:"Enterprise"})]})]})]})]}),e.jsx(X,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Rate Limiting"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"rate-limit",className:"text-xs",children:"Rate Limit (seconds)"}),e.jsx(ae,{id:"rate-limit",type:"number",value:a,onChange:N=>x(N.target.value),placeholder:"No limit",min:0,className:"max-w-[150px] h-8"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{htmlFor:"wait-on-limit",className:"text-xs",children:"Wait on Rate Limit"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Wait instead of error when limit hit"})]}),e.jsx(H,{id:"wait-on-limit",checked:r,onCheckedChange:n})]})]}),e.jsx(X,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Daemon Settings"}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{htmlFor:"auto-start",className:"text-xs",children:"Auto-start Daemon"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Start copilot-api when using profile"})]}),e.jsx(H,{id:"auto-start",checked:t,onCheckedChange:i})]})]})]})})})}function U({label:s,command:t}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:s}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:t}),e.jsx(ue,{value:t,size:"icon",className:"h-6 w-6"})]})]})}function is({rawSettings:s}){return e.jsx(Y,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(J,{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(Te,{className:"w-4 h-4"}),"Configuration Info"]}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",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:"Provider"}),e.jsx("span",{className:"font-mono",children:"GitHub Copilot"})]}),s&&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:"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:s.path}),e.jsx(ue,{value:s.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:"Status"}),e.jsx(b,{variant:"outline",className:s.exists?"w-fit text-green-600 border-green-200 bg-green-50":"w-fit text-muted-foreground",children:s.exists?"File exists":"Using defaults"})]})]})]})]}),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.jsx(U,{label:"Run with Copilot",command:"ccs copilot"}),e.jsx(U,{label:"Authenticate",command:"ccs copilot auth"}),e.jsx(U,{label:"Start daemon",command:"ccs copilot --start"}),e.jsx(U,{label:"Stop daemon",command:"ccs copilot --stop"})]})]})]})})})}const ls=g.lazy(()=>Se(()=>import("./index-DXF1Z58h.js").then(s=>s.aE),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(s=>({default:s.CodeEditor})));function os({rawJsonContent:s,isRawJsonValid:t,rawJsonEdits:l,rawSettingsEnv:c,onChange:a,missingRequiredFields:r=[]}){const o=r.length>0;return e.jsx(g.Suspense,{fallback:e.jsxs("div",{className:"flex items-center justify-center h-full",children:[e.jsx(Z,{className:"w-6 h-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Loading editor..."})]}),children:e.jsxs("div",{className:"h-full flex flex-col",children:[!t&&l!==null&&e.jsxs("div",{className:"mb-2 px-3 py-2 bg-destructive/10 text-destructive text-sm rounded-md flex items-center gap-2 mx-6 mt-4 shrink-0",children:[e.jsx(Re,{className:"w-4 h-4"}),"Invalid JSON syntax"]}),t&&o&&e.jsxs("div",{className:"mb-2 px-3 py-2 bg-warning/10 text-warning-foreground text-sm rounded-md flex items-start gap-2 mx-6 mt-4 shrink-0 border border-warning/20",children:[e.jsx(he,{className:"w-4 h-4 mt-0.5 text-amber-500 shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-amber-600 dark:text-amber-400",children:"Missing required fields:"})," ",e.jsx("code",{className:"text-xs bg-muted px-1 py-0.5 rounded",children:r.join(", ")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"These fields will use default values at runtime."})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden px-6 pb-4 pt-4",children:e.jsx("div",{className:"h-full border rounded-md overflow-hidden bg-background",children:e.jsx(ls,{value:s,onChange:a,language:"json",minHeight:"100%"})})}),e.jsx("div",{className:"mx-6 mb-4",children:e.jsx("div",{className:"border rounded-md overflow-hidden",children:e.jsx(Ce,{profileEnv:c})})})]})})}const rs=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function oe(s){const t=s?.env||{};return rs.filter(l=>!t[l]?.trim())}function cs(){const{config:s,configLoading:t,models:l,modelsLoading:c,rawSettings:a,rawSettingsLoading:r,updateConfigAsync:o,isUpdating:i,saveRawSettingsAsync:m,isSavingRawSettings:h,refetchRawSettings:x}=ge(),[n,N]=g.useState({}),[f,k]=g.useState(null),[$,L]=g.useState(!1),E=n.enabled??s?.enabled??!1,T=n.autoStart??s?.auto_start??!1,F=n.port??s?.port??4141,R=n.accountType??s?.account_type??"individual",_=n.model??s?.model??"claude-opus-4-5-20250514",p=n.rateLimit??s?.rate_limit?.toString()??"",O=n.waitOnLimit??s?.wait_on_limit??!0,I=n.opusModel??s?.opus_model??"",q=n.sonnetModel??s?.sonnet_model??"",P=n.haikuModel??s?.haiku_model??"",G=(u,w)=>{N(we=>({...we,[u]:w}))},B=u=>{N(w=>({...w,model:u.default,opusModel:u.opus,sonnetModel:u.sonnet,haikuModel:u.haiku})),A.success(`Applied "${u.name}" preset`)},d=g.useMemo(()=>f!==null?f:a?.settings?JSON.stringify(a.settings,null,2):`{
|
|
3
3
|
"env": {}
|
|
4
4
|
}`,[f,a]),je=g.useCallback(u=>{k(u)},[]),ee=g.useMemo(()=>{try{return JSON.parse(d),!0}catch{return!1}},[d]),Ne=g.useMemo(()=>{const u=Object.keys(n).length>0,w=f!==null&&f!==JSON.stringify(a?.settings,null,2);return u||w},[n,f,a]),se=g.useMemo(()=>{if(f!==null)try{return JSON.parse(f)}catch{return a?.settings}return a?.settings},[f,a?.settings]),ve=g.useMemo(()=>oe(se),[se]),te=async()=>{try{if(Object.keys(n).length>0&&await o({enabled:E,auto_start:T,port:F,account_type:R,model:_,rate_limit:p?parseInt(p,10):null,wait_on_limit:O,opus_model:I||void 0,sonnet_model:q||void 0,haiku_model:P||void 0}),f!==null&&ee){const u=JSON.parse(d),w=oe(u);await m({settings:u,expectedMtime:a?.mtime}),w.length>0?A.success("Copilot configuration saved",{description:`Missing fields will use defaults: ${w.join(", ")}`}):A.success("Copilot configuration saved")}else A.success("Copilot configuration saved");N({}),k(null)}catch(u){u.message==="CONFLICT"?L(!0):A.error("Failed to save settings")}};return{configLoading:t,rawSettingsLoading:r,modelsLoading:c,isUpdating:i,isSavingRawSettings:h,models:l,rawSettings:a,rawJsonContent:d,rawJsonEdits:f,enabled:E,autoStart:T,port:F,accountType:R,currentModel:_,rateLimit:p,waitOnLimit:O,opusModel:I,sonnetModel:q,haikuModel:P,isRawJsonValid:ee,hasChanges:Ne,conflictDialog:$,updateField:G,applyPreset:B,handleRawJsonChange:je,handleSave:te,handleConflictResolve:async u=>{L(!1),u?(await x(),te()):k(null)},refetchRawSettings:x,missingRequiredFields:ve}}function ds(){const{configLoading:s,rawSettingsLoading:t,modelsLoading:l,isUpdating:c,isSavingRawSettings:a,models:r,rawSettings:o,rawJsonContent:i,rawJsonEdits:m,enabled:h,autoStart:x,port:n,accountType:N,currentModel:f,rateLimit:k,waitOnLimit:$,opusModel:L,sonnetModel:E,haikuModel:T,isRawJsonValid:F,hasChanges:R,conflictDialog:_,updateField:p,applyPreset:O,handleRawJsonChange:I,handleSave:q,handleConflictResolve:P,refetchRawSettings:G,missingRequiredFields:B}=cs();return s||t?e.jsxs("div",{className:"space-y-6",children:[e.jsx(y,{className:"h-10 w-full"}),e.jsx(y,{className:"h-10 w-full"}),e.jsx(y,{className:"h-10 w-full"}),e.jsx(y,{className:"h-10 w-full"})]}):e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Ze,{rawSettings:o,rawSettingsLoading:t,isUpdating:c,isSavingRawSettings:a,hasChanges:R,isRawJsonValid:F,onRefresh:()=>G(),onSave:q}),e.jsxs("div",{className:"flex-1 flex divide-x overflow-hidden",children:[e.jsx("div",{className:"w-[540px] shrink-0 flex flex-col overflow-hidden bg-muted/5",children:e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs(ke,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Fe,{className:"w-full",children:[e.jsx(z,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(z,{value:"settings",className:"flex-1",children:"Settings"}),e.jsx(z,{value:"info",className:"flex-1",children:"Info"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(as,{currentModel:f,opusModel:L,sonnetModel:E,haikuModel:T,models:r,modelsLoading:l,onApplyPreset:O,onUpdateModel:d=>p("model",d),onUpdateOpusModel:d=>p("opusModel",d),onUpdateSonnetModel:d=>p("sonnetModel",d),onUpdateHaikuModel:d=>p("haikuModel",d)}),e.jsx(ns,{enabled:h,autoStart:x,port:n,accountType:N,rateLimit:k,waitOnLimit:$,onUpdateEnabled:d=>p("enabled",d),onUpdateAutoStart:d=>p("autoStart",d),onUpdatePort:d=>p("port",d),onUpdateAccountType:d=>p("accountType",d),onUpdateRateLimit:d=>p("rateLimit",d),onUpdateWaitOnLimit:d=>p("waitOnLimit",d)}),e.jsx(is,{rawSettings:o})]})]})})}),e.jsxs("div",{className:"flex-1 min-w-0 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(_e,{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(os,{rawJsonContent:i,isRawJsonValid:F,rawJsonEdits:m,rawSettingsEnv:o?.settings?.env,onChange:I,missingRequiredFields:B})]})]}),e.jsx(Me,{open:_,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>P(!0),onCancel:()=>P(!1)})]})}function V({title:s,children:t}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3",children:s}),e.jsx("div",{className:"space-y-1",children:t})]})}function Q({icon:s,label:t,status:l,statusText:c,variant:a="default"}){return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/50",children:[e.jsx(s,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("span",{className:"text-sm",children:t})}),e.jsx("div",{className:"flex items-center gap-1.5",children:l?e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:W("w-4 h-4",a==="warning"?"text-yellow-500":"text-green-500")}),e.jsx("span",{className:W("text-xs",a==="warning"?"text-yellow-500":"text-green-500"),children:c||"Yes"})]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:c||"No"})]})})]})}function ms(){return e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx(y,{className:"h-8 w-full"}),e.jsx(y,{className:"h-12 w-full"}),e.jsx(y,{className:"h-12 w-full"}),e.jsx(y,{className:"h-12 w-full"})]})}function Ss(){const{status:s,statusLoading:t,refetchStatus:l,startAuth:c,isAuthenticating:a,startDaemon:r,isStartingDaemon:o,stopDaemon:i,isStoppingDaemon:m,install:h,isInstalling:x}=ge();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 shrink-0",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Oe,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"Copilot"})]}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>l(),disabled:t,children:e.jsx(xe,{className:W("w-4 h-4",t&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"GitHub Copilot proxy"})]}),e.jsx(J,{className:"flex-1",children:t?e.jsx(ms,{}):e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsxs("div",{className:"rounded-md border border-yellow-500/50 bg-yellow-500/15 p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-400 shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-yellow-800 dark:text-yellow-200",children:"Unofficial API - Use at Your Own Risk"})]}),e.jsxs("ul",{className:"text-[11px] text-yellow-700 dark:text-yellow-300 space-y-0.5 pl-6 list-disc",children:[e.jsx("li",{children:"Reverse-engineered API - may break anytime"}),e.jsx("li",{children:"Excessive use may trigger account restrictions"}),e.jsx("li",{children:"No warranty, no responsibility from CCS"})]})]}),e.jsxs(V,{title:"Setup",children:[e.jsx(Q,{icon:Ie,label:"copilot-api",status:s?.installed??!1,statusText:s?.installed?s.version?`v${s.version}`:"Installed":"Missing"}),!s?.installed&&e.jsx(v,{size:"sm",className:"w-full mt-2",onClick:()=>h(void 0),disabled:x,children:x?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}),"Installing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(qe,{className:"w-3.5 h-3.5 mr-1.5"}),"Install copilot-api"]})}),s?.installed&&e.jsx(Q,{icon:ie,label:"Integration",status:s?.enabled??!1,statusText:s?.enabled?"Enabled":"Disabled"})]}),s?.installed&&e.jsxs(V,{title:"Auth",children:[e.jsx(Q,{icon:De,label:"GitHub",status:s?.authenticated??!1,statusText:s?.authenticated?"Connected":"Not Connected"}),!s?.authenticated&&e.jsx(v,{size:"sm",className:"w-full mt-2",onClick:()=>c(),disabled:a,children:a?"Authenticating...":"Authenticate"})]}),s?.authenticated&&e.jsxs(V,{title:"Daemon",children:[e.jsx(Q,{icon:Ue,label:"Status",status:s?.daemon_running??!1,statusText:s?.daemon_running?"Running":"Stopped"}),e.jsxs("div",{className:"px-3 py-1 text-xs text-muted-foreground",children:["Port: ",s?.port??4141]}),e.jsx("div",{className:"px-1",children:s?.daemon_running?e.jsxs(v,{size:"sm",variant:"outline",className:"w-full",onClick:()=>i(),disabled:m,children:[e.jsx(Qe,{className:"w-3.5 h-3.5 mr-1.5"}),m?"Stopping...":"Stop"]}):e.jsxs(v,{size:"sm",variant:"outline",className:"w-full",onClick:()=>r(),disabled:o,children:[e.jsx(ie,{className:"w-3.5 h-3.5 mr-1.5"}),o?"Starting...":"Start"]})})]})]})}),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.jsx("span",{children:"Proxy"}),s?.daemon_running?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(pe,{className:"w-3 h-3 text-green-500"}),"Active"]}):e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(fe,{className:"w-3 h-3 text-muted-foreground"}),"Inactive"]})]})})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-background overflow-hidden",children:e.jsx(ds,{})})]})}export{Ss as CopilotPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as c}from"./react-vendor-B_CU-WTZ.js";import{aB as N,aC as C,aD as w,ay as y,aA as G,i as S,a as b,I as p}from"./index-
|
|
1
|
+
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as c}from"./react-vendor-B_CU-WTZ.js";import{aB as N,aC as C,aD as w,ay as y,aA as G,i as S,a as b,I as p}from"./index-DXF1Z58h.js";import{S as k}from"./switch-Big41pQ7.js";import{a0 as j,V as A,n as R,a9 as L,O as V}from"./icons-CwFZAiDB.js";import"./tanstack-Coed0rqz.js";import"./notifications-dJQY2-U6.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function _(){const{state:s}=N(),a=C(),[l,d]=c.useState(""),[m,v]=c.useState(""),u=c.useCallback(async()=>{try{a.setGlobalEnvLoading(!0),a.setGlobalEnvError(null);const t=await fetch("/api/global-env");if(!t.ok)throw new Error("Failed to load Global Env config");const o=await t.json();a.setGlobalEnvConfig(o)}catch(t){a.setGlobalEnvError(t.message)}finally{a.setGlobalEnvLoading(!1)}},[a]),i=c.useCallback(async t=>{const o=s.globalEnvConfig;if(!o)return;const x={...o,...t};a.setGlobalEnvConfig(x);try{a.setGlobalEnvSaving(!0),a.setGlobalEnvError(null);const r=await fetch("/api/global-env",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!r.ok){const n=await r.json();throw new Error(n.error||"Failed to save")}const h=await r.json();a.setGlobalEnvConfig(h.config),a.setGlobalEnvSuccess(!0),setTimeout(()=>a.setGlobalEnvSuccess(!1),1500)}catch(r){a.setGlobalEnvConfig(o),a.setGlobalEnvError(r.message)}finally{a.setGlobalEnvSaving(!1)}},[s.globalEnvConfig,a]),f=c.useCallback(()=>{if(!l.trim()||!s.globalEnvConfig)return;const t={...s.globalEnvConfig.env,[l.trim()]:m};i({env:t}),d(""),v("")},[l,m,s.globalEnvConfig,i]),g=c.useCallback(t=>{if(!s.globalEnvConfig)return;const o={...s.globalEnvConfig.env};delete o[t],i({env:o})},[s.globalEnvConfig,i]);return{config:s.globalEnvConfig,loading:s.globalEnvLoading,saving:s.globalEnvSaving,error:s.globalEnvError,success:s.globalEnvSuccess,newEnvKey:l,setNewEnvKey:d,newEnvValue:m,setNewEnvValue:v,fetchConfig:u,saveConfig:i,addEnvVar:f,removeEnvVar:g}}function F(){const{config:s,loading:a,saving:l,error:d,success:m,newEnvKey:v,setNewEnvKey:u,newEnvValue:i,setNewEnvValue:f,fetchConfig:g,saveConfig:t,addEnvVar:o,removeEnvVar:x}=_(),{fetchRawConfig:r}=w();c.useEffect(()=>{g(),r()},[g,r]);const h=()=>{t({enabled:!s?.enabled})};return a?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(j,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${d||m?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[d&&e.jsxs(y,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(A,{className:"h-4 w-4"}),e.jsx(G,{children:d})]}),m&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(R,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(S,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Environment variables injected into all non-Claude subscription profiles (gemini, codex, agy, ghcp, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s?.enabled?"Global Env enabled":"Global Env disabled"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s?.enabled?"Env vars will be injected into third-party profiles":"Env vars will not be injected"})]}),e.jsx(k,{checked:s?.enabled??!0,onCheckedChange:h})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Environment Variables"}),s?.env&&Object.keys(s.env).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(s.env).map(([n,E])=>e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg border bg-background",children:[e.jsx("code",{className:"flex-1 font-mono text-sm truncate",children:n}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("code",{className:"font-mono text-sm px-2 py-1 bg-muted rounded",children:E}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>x(n),disabled:l,className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(L,{className:"w-4 h-4"})})]},n))}):e.jsx("div",{className:"p-4 rounded-lg border border-dashed text-center text-muted-foreground",children:e.jsx("p",{children:"No environment variables configured"})}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Add New Variable"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{value:v,onChange:n=>u(n.target.value.toUpperCase()),placeholder:"KEY_NAME",className:"flex-1 font-mono text-sm h-9",disabled:l}),e.jsx("span",{className:"flex items-center text-muted-foreground",children:"="}),e.jsx(p,{value:i,onChange:n=>f(n.target.value),placeholder:"value",className:"flex-1 font-mono text-sm h-9",disabled:l}),e.jsxs(b,{size:"sm",onClick:o,disabled:l||!v.trim(),className:"h-9",children:[e.jsx(V,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Quick Add Common Variables"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[[{key:"DISABLE_BUG_COMMAND",value:"1"},{key:"DISABLE_ERROR_REPORTING",value:"1"},{key:"DISABLE_TELEMETRY",value:"1"}].map(({key:n,value:E})=>!s?.env?.[n]&&e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>{u(n),f(E)},className:"text-xs font-mono",children:["+ ",n]},n)),s?.env&&["DISABLE_BUG_COMMAND","DISABLE_ERROR_REPORTING","DISABLE_TELEMETRY"].every(n=>s.env[n])&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"All common variables are configured"})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>{g(),r()},disabled:a||l,className:"w-full",children:[e.jsx(j,{className:`w-4 h-4 mr-2 ${a?"animate-spin":""}`}),"Refresh"]})})]})}export{F as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-uXQB-q0u.js";import{c as l,a as p,y as w,z as y,A as k,B as z,S as h}from"./index-8HAJX3-Y.js";import{a as M,u as R,b as W}from"./tanstack-Coed0rqz.js";import{t as g}from"./notifications-dJQY2-U6.js";import{r as j}from"./react-vendor-B_CU-WTZ.js";import{at as v,b as E,t as C,l as S,Z as P,f as O,U as $,S as H,au as I,J as T,s as F,a0 as A}from"./icons-CwFZAiDB.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";const B={sm:{dimension:80,strokeWidth:6,fontSize:"text-lg",labelSize:"text-[10px]"},md:{dimension:120,strokeWidth:8,fontSize:"text-3xl",labelSize:"text-xs"},lg:{dimension:160,strokeWidth:10,fontSize:"text-4xl",labelSize:"text-sm"}},D={ok:{stroke:"#22C55E",glow:"rgba(34, 197, 94, 0.4)"},warning:{stroke:"#EAB308",glow:"rgba(234, 179, 8, 0.4)"},error:{stroke:"#EF4444",glow:"rgba(239, 68, 68, 0.4)"}};function L({passed:s,total:t,status:r,size:o="md"}){const n=B[o],d=D[r],i=t>0?Math.round(s/t*100):0,a=(n.dimension-n.strokeWidth)/2,c=2*Math.PI*a,f=c-i/100*c,x=n.dimension/2;return e.jsxs("div",{className:"relative inline-flex items-center justify-center",children:[e.jsxs("svg",{width:n.dimension,height:n.dimension,className:"transform -rotate-90",style:{filter:`drop-shadow(0 0 8px ${d.glow})`},children:[e.jsx("circle",{cx:x,cy:x,r:a,fill:"none",stroke:"currentColor",strokeWidth:n.strokeWidth,className:"text-muted/30"}),e.jsx("circle",{cx:x,cy:x,r:a,fill:"none",stroke:d.stroke,strokeWidth:n.strokeWidth,strokeLinecap:"round",strokeDasharray:c,strokeDashoffset:f,className:"transition-all duration-1000 ease-out"}),i>0&&e.jsx("circle",{cx:x+a*Math.cos(i/100*2*Math.PI-Math.PI/2),cy:x+a*Math.sin(i/100*2*Math.PI-Math.PI/2),r:n.strokeWidth/2,fill:d.stroke,className:"animate-pulse",style:{filter:`drop-shadow(0 0 4px ${d.glow})`}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:l("font-mono font-bold tracking-tight",n.fontSize),children:i}),e.jsx("span",{className:l("font-mono uppercase tracking-widest text-muted-foreground",n.labelSize),children:"health"})]})]})}function b({label:s,value:t,color:r,bgColor:o}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full animate-pulse",o)}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:s}),e.jsx("span",{className:l("font-mono font-bold text-sm",r),children:t})]})}function q({total:s,passed:t,warnings:r,errors:o,info:n}){const d=t/s*100,i=r/s*100,a=o/s*100,c=n/s*100;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"h-2 rounded-full overflow-hidden bg-muted/50 flex",children:[a>0&&e.jsx("div",{className:"h-full bg-red-500 transition-all duration-500",style:{width:`${a}%`}}),i>0&&e.jsx("div",{className:"h-full bg-yellow-500 transition-all duration-500",style:{width:`${i}%`}}),c>0&&e.jsx("div",{className:"h-full bg-blue-500 transition-all duration-500",style:{width:`${c}%`}}),d>0&&e.jsx("div",{className:"h-full bg-green-500 transition-all duration-500",style:{width:`${d}%`}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Checks"}),e.jsx("span",{className:"font-mono font-bold text-lg",children:s})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx(b,{label:"OK",value:t,color:"text-green-500",bgColor:"bg-green-500"}),e.jsx(b,{label:"WARN",value:r,color:"text-yellow-500",bgColor:"bg-yellow-500"}),e.jsx(b,{label:"ERR",value:o,color:"text-red-500",bgColor:"bg-red-500"}),e.jsx(b,{label:"INFO",value:n,color:"text-blue-500",bgColor:"bg-blue-500"})]})]})]})}function G(){return M({queryKey:["health"],queryFn:async()=>(await fetch("/api/health")).json(),refetchInterval:3e4})}function K(){const s=R();return W({mutationFn:async t=>{const r=await fetch(`/api/health/fix/${t}`,{method:"POST"}),o=await r.json();if(!r.ok)throw new Error(o.message);return o},onSuccess:t=>{s.invalidateQueries({queryKey:["health"]}),g.success(t.message)},onError:t=>{g.error(t.message)}})}const Q={ok:{dot:"bg-green-500",label:"OK",labelColor:"text-green-500"},warning:{dot:"bg-yellow-500",label:"WARN",labelColor:"text-yellow-500"},error:{dot:"bg-red-500",label:"ERR",labelColor:"text-red-500"},info:{dot:"bg-blue-500",label:"INFO",labelColor:"text-blue-500"}};function U({check:s}){const t=K(),r=Q[s.status],[o,n]=j.useState(!1),d=s.details||s.fix,i=a=>{navigator.clipboard.writeText(a),g.success("Copied to clipboard")};return d?e.jsx(w,{open:o,onOpenChange:n,children:e.jsxs("div",{className:l("group rounded-lg border transition-all duration-150",o?"border-border bg-muted/30":"border-transparent hover:border-border/50 hover:bg-muted/50"),children:[e.jsx(y,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),e.jsx(E,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",o&&"rotate-90")})]})}),e.jsx(k,{children:e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-2 ml-7",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.message}),s.details&&e.jsx("pre",{className:"text-xs font-mono text-muted-foreground bg-background/50 rounded p-2 overflow-x-auto border border-border/50",children:s.details}),s.fix&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 bg-background/50 rounded px-2 py-1.5 border border-border/50",children:[e.jsx(C,{className:"w-3 h-3 text-muted-foreground shrink-0"}),e.jsx("code",{className:"text-xs font-mono flex-1 truncate",children:s.fix}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>s.fix&&i(s.fix),className:"h-5 w-5 p-0",children:e.jsx(S,{className:"w-3 h-3"})})]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",onClick:()=>t.mutate(s.id),disabled:t.isPending,className:"h-7 px-3 text-xs",children:[e.jsx(v,{className:"w-3 h-3 mr-1"}),"Apply Fix"]})]})]})})]})}):e.jsxs("div",{className:l("group flex items-center gap-3 px-3 py-2 rounded-lg","hover:bg-muted/50 transition-colors duration-150","border border-transparent hover:border-border/50"),children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",variant:"ghost",onClick:()=>t.mutate(s.id),disabled:t.isPending,className:"h-6 px-2 text-xs opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(v,{className:"w-3 h-3 mr-1"}),"Fix"]})]})}const Z={Monitor:I,Settings:H,Users:$,Shield:O,Zap:P};function J({group:s,defaultOpen:t=!0}){const[r,o]=j.useState(t),n=Z[s.icon]||I,d=s.checks.filter(m=>m.status==="ok").length,i=s.checks.length,a=s.checks.some(m=>m.status==="error"),c=s.checks.some(m=>m.status==="warning"),f=Math.round(d/i*100),x=a?"text-red-500":c?"text-yellow-500":"text-green-500",u=a?"bg-red-500":c?"bg-yellow-500":"bg-green-500";return e.jsx(w,{open:r,onOpenChange:o,children:e.jsxs("div",{className:l("rounded-lg border transition-all duration-200",a?"border-red-500/30":c?"border-yellow-500/30":"border-border"),children:[e.jsx(y,{asChild:!0,children:e.jsxs("button",{className:l("w-full flex items-center gap-3 p-3 text-left rounded-lg","hover:bg-muted/50 transition-colors duration-150",r&&"rounded-b-none border-b border-border/50"),children:[e.jsx("div",{className:l("p-1.5 rounded-md",a?"bg-red-500/10 text-red-500":c?"bg-yellow-500/10 text-yellow-500":"bg-muted text-muted-foreground"),children:e.jsx(n,{className:"w-4 h-4"})}),e.jsx("span",{className:"flex-1 text-sm font-semibold",children:s.name}),!r&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"w-16 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:l("h-full transition-all duration-500",u),style:{width:`${f}%`}})})}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",x),children:[d,"/",i]}),e.jsx(T,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",r&&"rotate-180")})]})}),e.jsx(k,{children:e.jsx("div",{className:"p-2 space-y-0.5",children:s.checks.map(m=>e.jsx(U,{check:m},m.id))})})]})})}function V(s){return s.errors>0?"error":s.warnings>0?"warning":"ok"}function X(s){const t=Math.floor((Date.now()-s)/1e3);if(t<5)return"just now";if(t<60)return`${t}s ago`;const r=Math.floor(t/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function Y(s){return[...s].sort((t,r)=>{const o=t.checks.filter(a=>a.status==="error").length,n=r.checks.filter(a=>a.status==="error").length,d=t.checks.filter(a=>a.status==="warning").length,i=r.checks.filter(a=>a.status==="warning").length;return o!==n?n-o:i-d})}function _(){return e.jsxs("div",{className:"font-mono text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500",children:"$"}),e.jsx("span",{children:"ccs doctor"})]})}function ee(){return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsx("div",{className:"rounded-xl border bg-gradient-to-br from-background to-muted/20 p-6",children:e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx(h,{className:"w-[120px] h-[120px] rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(h,{className:"h-5 w-48"}),e.jsx(h,{className:"h-8 w-64"}),e.jsx(h,{className:"h-4 w-32"})]})]})}),e.jsx(h,{className:"h-16 w-full rounded-lg"}),e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(s=>e.jsx(h,{className:"h-20 rounded-lg"},s))})]})}function ce(){const{data:s,isLoading:t,refetch:r,dataUpdatedAt:o}=G(),n=o,[d,i]=j.useState(0);j.useEffect(()=>{const u=setInterval(()=>i(m=>m+1),1e3);return()=>clearInterval(u)},[]);const a=()=>{navigator.clipboard.writeText("ccs doctor"),g.success("Copied to clipboard")},c=()=>{r(),g.info("Refreshing health checks...")};if(t&&!s)return e.jsx(ee,{});const f=s?V(s.summary):"ok",x=s?.groups?Y(s.groups):[];return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:l("relative overflow-hidden rounded-xl border p-6","bg-gradient-to-br from-background via-background to-muted/30"),children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.02] pointer-events-none",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsx("div",{className:"absolute inset-0 opacity-[0.03] pointer-events-none",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)",backgroundSize:"24px 24px"}})}),e.jsxs("div",{className:"relative flex flex-col md:flex-row items-start md:items-center gap-6",children:[s&&e.jsx("div",{className:"shrink-0",children:e.jsx(L,{passed:s.summary.passed,total:s.summary.total-s.summary.info,status:f,size:"md"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(_,{}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h1",{className:"text-2xl font-bold font-mono tracking-tight",children:"System Health"}),s?.version&&e.jsxs(z,{variant:"outline",className:"font-mono text-xs bg-muted/50",children:["build ",s.version]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(F,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Last scan:"}),e.jsx("span",{className:"font-mono",children:n?X(n):"--"}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsx("span",{className:"text-muted-foreground",children:"Auto-refresh:"}),e.jsx("span",{className:"font-mono text-green-500",children:"30s"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:a,className:"gap-2 font-mono text-xs",children:[e.jsx(C,{className:"w-3 h-3"}),"ccs doctor",e.jsx(S,{className:"w-3 h-3 opacity-50"})]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:c,disabled:t,className:"gap-2",children:[e.jsx(A,{className:l("w-4 h-4",t&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"}),e.jsx("kbd",{className:"hidden md:inline-flex h-5 items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground",children:"R"})]})]})]})]}),s&&e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsx(q,{total:s.summary.total,passed:s.summary.passed,warnings:s.summary.warnings,errors:s.summary.errors,info:s.summary.info})}),x.length>0&&e.jsx("div",{className:"space-y-3",children:x.map((u,m)=>e.jsx(J,{group:u,defaultOpen:m<2||u.checks.some(N=>N.status==="error"||N.status==="warning")},u.id))}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{children:["Version ",e.jsx("span",{className:"font-mono",children:s?.version??"--"})]}),e.jsxs("span",{children:["Platform"," ",e.jsx("span",{className:"font-mono",children:typeof navigator<"u"?navigator.platform:"linux"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),e.jsx("span",{children:"Live monitoring active"})]})]})]})}export{ce as HealthPage};
|
|
1
|
+
import{j as e}from"./radix-ui-uXQB-q0u.js";import{c as l,a as p,y as w,z as y,A as k,B as z,S as h}from"./index-DXF1Z58h.js";import{a as M,u as R,b as W}from"./tanstack-Coed0rqz.js";import{t as g}from"./notifications-dJQY2-U6.js";import{r as j}from"./react-vendor-B_CU-WTZ.js";import{at as v,b as E,t as C,l as S,Z as P,f as O,U as $,S as H,au as I,J as T,s as F,a0 as A}from"./icons-CwFZAiDB.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";const B={sm:{dimension:80,strokeWidth:6,fontSize:"text-lg",labelSize:"text-[10px]"},md:{dimension:120,strokeWidth:8,fontSize:"text-3xl",labelSize:"text-xs"},lg:{dimension:160,strokeWidth:10,fontSize:"text-4xl",labelSize:"text-sm"}},D={ok:{stroke:"#22C55E",glow:"rgba(34, 197, 94, 0.4)"},warning:{stroke:"#EAB308",glow:"rgba(234, 179, 8, 0.4)"},error:{stroke:"#EF4444",glow:"rgba(239, 68, 68, 0.4)"}};function L({passed:s,total:t,status:r,size:o="md"}){const n=B[o],d=D[r],i=t>0?Math.round(s/t*100):0,a=(n.dimension-n.strokeWidth)/2,c=2*Math.PI*a,f=c-i/100*c,x=n.dimension/2;return e.jsxs("div",{className:"relative inline-flex items-center justify-center",children:[e.jsxs("svg",{width:n.dimension,height:n.dimension,className:"transform -rotate-90",style:{filter:`drop-shadow(0 0 8px ${d.glow})`},children:[e.jsx("circle",{cx:x,cy:x,r:a,fill:"none",stroke:"currentColor",strokeWidth:n.strokeWidth,className:"text-muted/30"}),e.jsx("circle",{cx:x,cy:x,r:a,fill:"none",stroke:d.stroke,strokeWidth:n.strokeWidth,strokeLinecap:"round",strokeDasharray:c,strokeDashoffset:f,className:"transition-all duration-1000 ease-out"}),i>0&&e.jsx("circle",{cx:x+a*Math.cos(i/100*2*Math.PI-Math.PI/2),cy:x+a*Math.sin(i/100*2*Math.PI-Math.PI/2),r:n.strokeWidth/2,fill:d.stroke,className:"animate-pulse",style:{filter:`drop-shadow(0 0 4px ${d.glow})`}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:l("font-mono font-bold tracking-tight",n.fontSize),children:i}),e.jsx("span",{className:l("font-mono uppercase tracking-widest text-muted-foreground",n.labelSize),children:"health"})]})]})}function b({label:s,value:t,color:r,bgColor:o}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full animate-pulse",o)}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:s}),e.jsx("span",{className:l("font-mono font-bold text-sm",r),children:t})]})}function q({total:s,passed:t,warnings:r,errors:o,info:n}){const d=t/s*100,i=r/s*100,a=o/s*100,c=n/s*100;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"h-2 rounded-full overflow-hidden bg-muted/50 flex",children:[a>0&&e.jsx("div",{className:"h-full bg-red-500 transition-all duration-500",style:{width:`${a}%`}}),i>0&&e.jsx("div",{className:"h-full bg-yellow-500 transition-all duration-500",style:{width:`${i}%`}}),c>0&&e.jsx("div",{className:"h-full bg-blue-500 transition-all duration-500",style:{width:`${c}%`}}),d>0&&e.jsx("div",{className:"h-full bg-green-500 transition-all duration-500",style:{width:`${d}%`}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Checks"}),e.jsx("span",{className:"font-mono font-bold text-lg",children:s})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx(b,{label:"OK",value:t,color:"text-green-500",bgColor:"bg-green-500"}),e.jsx(b,{label:"WARN",value:r,color:"text-yellow-500",bgColor:"bg-yellow-500"}),e.jsx(b,{label:"ERR",value:o,color:"text-red-500",bgColor:"bg-red-500"}),e.jsx(b,{label:"INFO",value:n,color:"text-blue-500",bgColor:"bg-blue-500"})]})]})]})}function G(){return M({queryKey:["health"],queryFn:async()=>(await fetch("/api/health")).json(),refetchInterval:3e4})}function K(){const s=R();return W({mutationFn:async t=>{const r=await fetch(`/api/health/fix/${t}`,{method:"POST"}),o=await r.json();if(!r.ok)throw new Error(o.message);return o},onSuccess:t=>{s.invalidateQueries({queryKey:["health"]}),g.success(t.message)},onError:t=>{g.error(t.message)}})}const Q={ok:{dot:"bg-green-500",label:"OK",labelColor:"text-green-500"},warning:{dot:"bg-yellow-500",label:"WARN",labelColor:"text-yellow-500"},error:{dot:"bg-red-500",label:"ERR",labelColor:"text-red-500"},info:{dot:"bg-blue-500",label:"INFO",labelColor:"text-blue-500"}};function U({check:s}){const t=K(),r=Q[s.status],[o,n]=j.useState(!1),d=s.details||s.fix,i=a=>{navigator.clipboard.writeText(a),g.success("Copied to clipboard")};return d?e.jsx(w,{open:o,onOpenChange:n,children:e.jsxs("div",{className:l("group rounded-lg border transition-all duration-150",o?"border-border bg-muted/30":"border-transparent hover:border-border/50 hover:bg-muted/50"),children:[e.jsx(y,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),e.jsx(E,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",o&&"rotate-90")})]})}),e.jsx(k,{children:e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-2 ml-7",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.message}),s.details&&e.jsx("pre",{className:"text-xs font-mono text-muted-foreground bg-background/50 rounded p-2 overflow-x-auto border border-border/50",children:s.details}),s.fix&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 bg-background/50 rounded px-2 py-1.5 border border-border/50",children:[e.jsx(C,{className:"w-3 h-3 text-muted-foreground shrink-0"}),e.jsx("code",{className:"text-xs font-mono flex-1 truncate",children:s.fix}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>s.fix&&i(s.fix),className:"h-5 w-5 p-0",children:e.jsx(S,{className:"w-3 h-3"})})]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",onClick:()=>t.mutate(s.id),disabled:t.isPending,className:"h-7 px-3 text-xs",children:[e.jsx(v,{className:"w-3 h-3 mr-1"}),"Apply Fix"]})]})]})})]})}):e.jsxs("div",{className:l("group flex items-center gap-3 px-3 py-2 rounded-lg","hover:bg-muted/50 transition-colors duration-150","border border-transparent hover:border-border/50"),children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",variant:"ghost",onClick:()=>t.mutate(s.id),disabled:t.isPending,className:"h-6 px-2 text-xs opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(v,{className:"w-3 h-3 mr-1"}),"Fix"]})]})}const Z={Monitor:I,Settings:H,Users:$,Shield:O,Zap:P};function J({group:s,defaultOpen:t=!0}){const[r,o]=j.useState(t),n=Z[s.icon]||I,d=s.checks.filter(m=>m.status==="ok").length,i=s.checks.length,a=s.checks.some(m=>m.status==="error"),c=s.checks.some(m=>m.status==="warning"),f=Math.round(d/i*100),x=a?"text-red-500":c?"text-yellow-500":"text-green-500",u=a?"bg-red-500":c?"bg-yellow-500":"bg-green-500";return e.jsx(w,{open:r,onOpenChange:o,children:e.jsxs("div",{className:l("rounded-lg border transition-all duration-200",a?"border-red-500/30":c?"border-yellow-500/30":"border-border"),children:[e.jsx(y,{asChild:!0,children:e.jsxs("button",{className:l("w-full flex items-center gap-3 p-3 text-left rounded-lg","hover:bg-muted/50 transition-colors duration-150",r&&"rounded-b-none border-b border-border/50"),children:[e.jsx("div",{className:l("p-1.5 rounded-md",a?"bg-red-500/10 text-red-500":c?"bg-yellow-500/10 text-yellow-500":"bg-muted text-muted-foreground"),children:e.jsx(n,{className:"w-4 h-4"})}),e.jsx("span",{className:"flex-1 text-sm font-semibold",children:s.name}),!r&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"w-16 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:l("h-full transition-all duration-500",u),style:{width:`${f}%`}})})}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",x),children:[d,"/",i]}),e.jsx(T,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",r&&"rotate-180")})]})}),e.jsx(k,{children:e.jsx("div",{className:"p-2 space-y-0.5",children:s.checks.map(m=>e.jsx(U,{check:m},m.id))})})]})})}function V(s){return s.errors>0?"error":s.warnings>0?"warning":"ok"}function X(s){const t=Math.floor((Date.now()-s)/1e3);if(t<5)return"just now";if(t<60)return`${t}s ago`;const r=Math.floor(t/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function Y(s){return[...s].sort((t,r)=>{const o=t.checks.filter(a=>a.status==="error").length,n=r.checks.filter(a=>a.status==="error").length,d=t.checks.filter(a=>a.status==="warning").length,i=r.checks.filter(a=>a.status==="warning").length;return o!==n?n-o:i-d})}function _(){return e.jsxs("div",{className:"font-mono text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500",children:"$"}),e.jsx("span",{children:"ccs doctor"})]})}function ee(){return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsx("div",{className:"rounded-xl border bg-gradient-to-br from-background to-muted/20 p-6",children:e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx(h,{className:"w-[120px] h-[120px] rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(h,{className:"h-5 w-48"}),e.jsx(h,{className:"h-8 w-64"}),e.jsx(h,{className:"h-4 w-32"})]})]})}),e.jsx(h,{className:"h-16 w-full rounded-lg"}),e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(s=>e.jsx(h,{className:"h-20 rounded-lg"},s))})]})}function ce(){const{data:s,isLoading:t,refetch:r,dataUpdatedAt:o}=G(),n=o,[d,i]=j.useState(0);j.useEffect(()=>{const u=setInterval(()=>i(m=>m+1),1e3);return()=>clearInterval(u)},[]);const a=()=>{navigator.clipboard.writeText("ccs doctor"),g.success("Copied to clipboard")},c=()=>{r(),g.info("Refreshing health checks...")};if(t&&!s)return e.jsx(ee,{});const f=s?V(s.summary):"ok",x=s?.groups?Y(s.groups):[];return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:l("relative overflow-hidden rounded-xl border p-6","bg-gradient-to-br from-background via-background to-muted/30"),children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.02] pointer-events-none",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsx("div",{className:"absolute inset-0 opacity-[0.03] pointer-events-none",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)",backgroundSize:"24px 24px"}})}),e.jsxs("div",{className:"relative flex flex-col md:flex-row items-start md:items-center gap-6",children:[s&&e.jsx("div",{className:"shrink-0",children:e.jsx(L,{passed:s.summary.passed,total:s.summary.total-s.summary.info,status:f,size:"md"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(_,{}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h1",{className:"text-2xl font-bold font-mono tracking-tight",children:"System Health"}),s?.version&&e.jsxs(z,{variant:"outline",className:"font-mono text-xs bg-muted/50",children:["build ",s.version]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(F,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Last scan:"}),e.jsx("span",{className:"font-mono",children:n?X(n):"--"}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsx("span",{className:"text-muted-foreground",children:"Auto-refresh:"}),e.jsx("span",{className:"font-mono text-green-500",children:"30s"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:a,className:"gap-2 font-mono text-xs",children:[e.jsx(C,{className:"w-3 h-3"}),"ccs doctor",e.jsx(S,{className:"w-3 h-3 opacity-50"})]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:c,disabled:t,className:"gap-2",children:[e.jsx(A,{className:l("w-4 h-4",t&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"}),e.jsx("kbd",{className:"hidden md:inline-flex h-5 items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground",children:"R"})]})]})]})]}),s&&e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsx(q,{total:s.summary.total,passed:s.summary.passed,warnings:s.summary.warnings,errors:s.summary.errors,info:s.summary.info})}),x.length>0&&e.jsx("div",{className:"space-y-3",children:x.map((u,m)=>e.jsx(J,{group:u,defaultOpen:m<2||u.checks.some(N=>N.status==="error"||N.status==="warning")},u.id))}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{children:["Version ",e.jsx("span",{className:"font-mono",children:s?.version??"--"})]}),e.jsxs("span",{children:["Platform"," ",e.jsx("span",{className:"font-mono",children:typeof navigator<"u"?navigator.platform:"linux"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),e.jsx("span",{children:"Live monitoring active"})]})]})]})}export{ce as HealthPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as p}from"./react-vendor-B_CU-WTZ.js";import{aB as G,aC as J,af as L,I as S,O as K,Q as X,U as Y,V as Z,W as $,a as B,aD as ee,ay as te,aA as se,i as re}from"./index-DXF1Z58h.js";import{S as A}from"./switch-Big41pQ7.js";import{aw as _,a0 as I,e as oe,n as F,W as ae,V as ne,ax as le}from"./icons-CwFZAiDB.js";import"./tanstack-Coed0rqz.js";import"./notifications-dJQY2-U6.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function ce(){const{state:s}=G(),t=J(),[n,l]=p.useState(null),[u,f]=p.useState(null),[h,d]=p.useState(null),[j,y]=p.useState(null),b=p.useCallback(async()=>{try{t.setProxyLoading(!0),t.setProxyError(null);const a=await L.cliproxyServer.get();t.setProxyConfig(a)}catch(a){t.setProxyError(a.message)}finally{t.setProxyLoading(!1)}},[t]),v=p.useCallback(async a=>{const c=s.proxyConfig;if(!c)return;const m={remote:{...c.remote,...a.remote},fallback:{...c.fallback,...a.fallback},local:{...c.local,...a.local}};t.setProxyConfig(m),t.setProxyTestResult(null);try{t.setProxySaving(!0),t.setProxyError(null);const r=await L.cliproxyServer.update(a);t.setProxyConfig(r),t.setProxySuccess(!0),setTimeout(()=>t.setProxySuccess(!1),1500)}catch(r){t.setProxyConfig(c),t.setProxyError(r.message)}finally{t.setProxySaving(!1)}},[s.proxyConfig,t]),N=p.useCallback(async a=>{const{host:c,port:m,protocol:r,authToken:i}=a;if(!c){t.setProxyError("Host is required");return}try{t.setProxyTesting(!0),t.setProxyError(null),t.setProxyTestResult(null);const g=m?parseInt(m,10):void 0,x=await L.cliproxyServer.test({host:c,port:g||void 0,protocol:r,authToken:i||void 0});t.setProxyTestResult(x)}catch(g){t.setProxyError(g.message)}finally{t.setProxyTesting(!1)}},[t]);return{config:s.proxyConfig,loading:s.proxyLoading,saving:s.proxySaving,error:s.proxyError,success:s.proxySuccess,testResult:s.proxyTestResult,testing:s.proxyTesting,editedHost:n,setEditedHost:l,editedPort:u,setEditedPort:f,editedAuthToken:h,setEditedAuthToken:d,editedLocalPort:j,setEditedLocalPort:y,fetchConfig:b,saveConfig:v,testConnection:N}}function ie({config:s,saving:t,displayLocalPort:n,setEditedLocalPort:l,onSaveLocalPort:u,onSaveConfig:f}){const h=s.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Local Proxy"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Port"}),e.jsx(S,{type:"number",value:n,onChange:d=>l(d.target.value),onBlur:u,placeholder:"8317",className:"font-mono max-w-32",disabled:t})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Start local proxy automatically when needed"})]}),e.jsx(A,{checked:h.auto_start??!0,onCheckedChange:d=>f({local:{...h,auto_start:d}}),disabled:t})]})]})]})}function de({config:s,saving:t,testing:n,testResult:l,displayHost:u,displayPort:f,displayAuthToken:h,setEditedHost:d,setEditedPort:j,setEditedAuthToken:y,onSaveHost:b,onSavePort:v,onSaveAuthToken:N,onSaveConfig:a,onTestConnection:c}){const m=s.remote,r=i=>i==="https"?443:8317;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(_,{className:"w-4 h-4"}),"Remote Server Configuration"]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Host"}),e.jsx(S,{value:u,onChange:i=>d(i.target.value),onBlur:b,placeholder:"192.168.1.100 or proxy.example.com",className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:["Port"," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(default: ",r(s.remote.protocol||"http"),")"]})]}),e.jsx(S,{type:"text",inputMode:"numeric",value:f,onChange:i=>j(i.target.value.replace(/\D/g,"")),onBlur:v,placeholder:`Leave empty for ${r(s.remote.protocol||"http")}`,className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Protocol"}),e.jsxs(K,{value:s.remote.protocol||"http",onValueChange:i=>a({remote:{...m,protocol:i}}),disabled:t,children:[e.jsx(X,{children:e.jsx(Y,{})}),e.jsxs(Z,{children:[e.jsx($,{value:"http",children:"HTTP"}),e.jsx($,{value:"https",children:"HTTPS"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Auth Token (optional)"}),e.jsx(S,{type:"password",value:h,onChange:i=>y(i.target.value),onBlur:N,placeholder:"Bearer token for authentication",className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(B,{onClick:c,disabled:n||!u,variant:"outline",className:"w-full",children:n?e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"w-4 h-4 mr-2 animate-spin"}),"Testing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-4 h-4 mr-2"}),"Test Connection"]})}),l&&e.jsx("div",{className:`p-3 rounded-md ${l.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:l.reachable?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsxs("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:["Connected (",l.latencyMs,"ms)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:l.error||"Connection failed"})]})})})]})]})}function ve(){const{config:s,loading:t,saving:n,error:l,success:u,testResult:f,testing:h,editedHost:d,setEditedHost:j,editedPort:y,setEditedPort:b,editedAuthToken:v,setEditedAuthToken:N,editedLocalPort:a,setEditedLocalPort:c,fetchConfig:m,saveConfig:r,testConnection:i}=ce(),{fetchRawConfig:g}=ee();if(p.useEffect(()=>{m(),g()},[m,g]),t||!s)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(I,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const x=s.remote.enabled??!1,C=s.remote,P=s.fallback,D=s.remote.host??"",M=s.remote.port!==void 0?s.remote.port.toString():"",V=s.remote.auth_token??"",W=(s.local.port??8317).toString(),w=d??D,T=y??M,E=v??V,R=a??W,z=()=>{const o=d??w;o!==s.remote.host&&r({remote:{...C,host:o}}),j(null)},O=()=>{const o=y??T,k=o===""?void 0:parseInt(o,10),H=k&&!isNaN(k)&&k>0?k:void 0;H!==s.remote.port&&r({remote:{...C,port:H}}),b(null)},U=()=>{const o=v??E;o!==s.remote.auth_token&&r({remote:{...C,auth_token:o}}),N(null)},q=()=>{const o=parseInt(a??R,10);!isNaN(o)&&o!==s.local.port&&r({local:{...s.local,port:o}}),c(null)},Q=()=>{i({host:w,port:T,protocol:s.remote.protocol||"http",authToken:E})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${l||u?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[l&&e.jsxs(te,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ne,{className:"h-4 w-4"}),e.jsx(se,{children:l})]}),u&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(F,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(re,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure local or remote CLIProxy Plus connection for proxy-based profiles"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Connection Mode"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>r({remote:{...C,enabled:!1}}),disabled:n,className:`p-4 rounded-lg border-2 text-left transition-all ${x?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(le,{className:`w-5 h-5 ${x?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:"Local"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Run CLIProxy Plus binary on this machine"})]}),e.jsxs("button",{onClick:()=>r({remote:{...C,enabled:!0}}),disabled:n,className:`p-4 rounded-lg border-2 text-left transition-all ${x?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(_,{className:`w-5 h-5 ${x?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:"Remote"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect to a remote CLIProxy Plus server"})]})]})]}),x&&e.jsx(de,{config:s,saving:n,testing:h,testResult:f,displayHost:w,displayPort:T,displayAuthToken:E,setEditedHost:j,setEditedPort:b,setEditedAuthToken:N,onSaveHost:z,onSavePort:O,onSaveAuthToken:U,onSaveConfig:r,onTestConnection:Q}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Fallback Settings"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Enable fallback to local"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use local proxy if remote is unreachable"})]}),e.jsx(A,{checked:P.enabled??!0,onCheckedChange:o=>r({fallback:{...P,enabled:o}}),disabled:n||!x})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start local proxy"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Automatically start local proxy on fallback"})]}),e.jsx(A,{checked:P.auto_start??!1,onCheckedChange:o=>r({fallback:{...P,auto_start:o}}),disabled:n||!x||!P.enabled})]})]})]}),!x&&e.jsx(ie,{config:s,saving:n,displayLocalPort:R,setEditedLocalPort:c,onSaveLocalPort:q,onSaveConfig:r})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>{m(),g()},disabled:t||n,className:"w-full",children:[e.jsx(I,{className:`w-4 h-4 mr-2 ${t?"animate-spin":""}`}),"Refresh"]})})]})}export{ve as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as f,c as fe}from"./react-vendor-B_CU-WTZ.js";import{u as M,S as h,c as d,P as y,B as I,a as H,b as ee,d as pe,e as se,C as ge,g as te,f as je,h as Ne,i as ye,j as be}from"./index-8HAJX3-Y.js";import{C as p,a as g,b as N,c as S}from"./card-D6fGkasO.js";import{x as we,a2 as ae,a3 as z,a4 as re,v as ne,Q as ve,G as ke,a5 as Ce,a0 as $e,t as Y,U as Se,Z as le,q as Le,_ as G,a6 as De,s as Te,b as Fe,a7 as Re,a8 as Me}from"./icons-CwFZAiDB.js";import{u as Pe,a as P}from"./tanstack-Coed0rqz.js";import{K as D,L as Q,f as k,H as Ae}from"./utils-CzKF5WmX.js";import{R as ie,A as Be,C as Ue,X as qe,Y as V,T as oe,a as Z,P as Ie,b as Oe,c as Ke}from"./charts-CJC4bH8P.js";import"./notifications-dJQY2-U6.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function Ee({data:s,isLoading:t}){const{privacyMode:a}=M();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(o=>e.jsx(p,{children:e.jsx(g,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-8 w-[80px]"})]}),e.jsx(h,{className:"h-8 w-8 rounded-lg"})]})})},o))});const l=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),r=s?.totalCost?Math.round(l/s.totalCost*100):0,i=[{title:"Total Tokens",value:s?.totalTokens??0,icon:we,format:o=>R(o),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:`${R(s?.totalInputTokens??0)} in / ${R(s?.totalOutputTokens??0)} out`},{title:"Total Cost",value:s?.totalCost??0,icon:ae,format:o=>`$${o.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:z,format:o=>R(o),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:`$${l.toFixed(2)} (${r}% of cost)`},{title:"Input Cost",value:s?.tokenBreakdown?.input?.cost??0,icon:re,format:o=>`$${o.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:`${R(s?.tokenBreakdown?.input?.tokens??0)} tokens`},{title:"Output Cost",value:s?.tokenBreakdown?.output?.cost??0,icon:ne,format:o=>`$${o.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:`${R(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:i.map((o,n)=>{const c=o.icon;return e.jsx(p,{className:"hover:shadow-md transition-shadow",children:e.jsx(g,{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:o.title}),e.jsx("p",{className:d("text-xl font-bold truncate",a&&y),children:o.format(o.value)}),o.subtitle&&e.jsx("p",{className:d("text-[10px] text-muted-foreground truncate",a&&y),children:o.subtitle})]}),e.jsx("div",{className:d("p-2 rounded-lg shrink-0",o.bgColor),children:e.jsx(c,{className:d("h-4 w-4",o.color)})})]})})},n)})})}function R(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ge({model:s}){const{privacyMode:t}=M(),a=We(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(ve,{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(I,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(I,{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:d("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:d("text-lg font-bold",t&&y),children:_e(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:d("space-y-1",t&&y),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:re}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:ne}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:z}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:z})]})]}),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(ke,{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 W({label:s,tokens:t,cost:a,color:l,icon:r}){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:l}}),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(r,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:He(t)})]})]})]})}function We(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 He(s){return s.toLocaleString()}function _e(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()}const ze="/api";function w(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0");return`${t}${a}${l}`}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),L(`/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),L(`/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)),L(`/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),L(`/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()),L(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),L(`/usage/monthly?${a}`)},refresh:async()=>{if(!(await fetch(`${ze}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>L("/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),L(`/usage/insights?${t}`)}};async function L(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const r=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(r.error||a.statusText)}const l=await a.json();return l.data||l}function Qe(s){return P({queryKey:["usage","summary",s],queryFn:()=>T.summary(s),staleTime:60*1e3})}function Ye(s){return P({queryKey:["usage","trends",s],queryFn:()=>T.trends(s),staleTime:60*1e3})}function Ve(s){return P({queryKey:["usage","hourly",s],queryFn:()=>T.hourly(s),staleTime:60*1e3})}function Ze(s){return P({queryKey:["usage","models",s],queryFn:()=>T.models(s),staleTime:60*1e3})}function Xe(){const s=Pe();return f.useCallback(async()=>{await T.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function Je(){return P({queryKey:["usage","status"],queryFn:()=>T.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function es(s){return P({queryKey:["usage","sessions",s],queryFn:()=>T.sessions(s),staleTime:60*1e3})}function ss(){const[s,t]=f.useState({from:D(new Date,30),to:new Date}),[a,l]=f.useState(!1),[r,i]=f.useState(null),[o,n]=f.useState(null),[c,x]=f.useState("daily"),u=Xe(),m=f.useCallback(async()=>{l(!0);try{await u()}finally{l(!1)}},[u]),j=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:b,isLoading:v}=Qe(j),{data:C,isLoading:$}=Ye(j),{data:A,isLoading:B}=Ve(j),{data:U,isLoading:q}=Ze(j),{data:_,isLoading:O}=es({...j,limit:3}),{data:K}=Je(),ce=f.useCallback(()=>{const F=new Date;t({from:D(F,1),to:F}),x("hourly")},[]),de=f.useCallback(F=>{t(F),x("daily")},[]),xe=f.useMemo(()=>K?.lastFetch?Q(new Date(K.lastFetch),{addSuffix:!0}):null,[K?.lastFetch]),ue=f.useCallback((F,he)=>{const E=he.currentTarget.getBoundingClientRect();n({x:E.left+E.width/2,y:E.top+E.height/2}),i(F)},[]),me=f.useCallback(()=>{i(null),n(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:c,selectedModel:r,popoverPosition:o,summary:b,trends:C,hourlyData:A,models:U,sessions:_,status:K,isSummaryLoading:v,isTrendsLoading:$,isHourlyLoading:B,isModelsLoading:q,isSessionsLoading:O,isLoading:v||$||q||O,handleRefresh:m,handleTodayClick:ce,handleDateRangeChange:de,handleModelClick:ue,handlePopoverClose:me,lastUpdatedText:xe}}function ts({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:D(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:D(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:D(new Date,90),to:new Date}}],className:l}){const[r,i]=fe.useState(!1),o=n=>!s||!s.from||!s.to||!n.from||!n.to?!1:k(s.from,"yyyy-MM-dd")===k(n.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(n.to,"yyyy-MM-dd");return e.jsxs("div",{className:d("flex items-center gap-2",l),children:[a.map(n=>e.jsx(H,{variant:o(n.range)?"default":"outline",size:"sm",onClick:()=>t(n.range),children:n.label},n.label)),e.jsxs(ee,{open:r,onOpenChange:i,children:[e.jsx(pe,{asChild:!0,children:e.jsxs(H,{id:"date",variant:"outline",className:d("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(ge,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function as({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:l,isRefreshing:r,lastUpdatedText:i,viewMode:o}){return 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(H,{variant:o==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(ts,{value:s,onChange:t,presets:[{label:"7D",range:{from:D(new Date,7),to:new Date}},{label:"30D",range:{from:D(new Date,30),to:new Date}},{label:"Month",range:{from:Ae(new Date),to:new Date}},{label:"All Time",range:{from:void 0,to:new Date}}]}),i&&e.jsxs("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:["Updated ",i]}),e.jsx(H,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:l,disabled:r,children:e.jsx($e,{className:`w-3.5 h-3.5 ${r?"animate-spin":""}`})})]})]})}function rs({data:s,isLoading:t,granularity:a="daily",className:l}){const{privacyMode:r}=M(),i=f.useMemo(()=>!s||s.length===0?[]:(a==="hourly"?s:[...s].reverse()).map(c=>{const x="hour"in c?c.hour:c.date;return{...c,dateFormatted:ns(x,a),costRounded:Number(c.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(h,{className:d("h-full w-full",l)});if(!s||s.length===0)return e.jsx("div",{className:d("h-full flex items-center justify-center",l),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const o=({x:n,y:c,payload:x,isRight:u})=>{const m=u?`$${x.value}`:X(Number(x.value));return e.jsx("text",{x:n,y:c,dy:4,textAnchor:u?"start":"end",fontSize:12,fill:"currentColor",className:d("fill-muted-foreground",r&&"blur-[4px]"),children:m})};return e.jsx("div",{className:d("w-full h-full",l),children:e.jsx(ie,{width:"100%",height:"100%",children:e.jsxs(Be,{data:i,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(Ue,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(qe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"left",orientation:"left",tick:n=>e.jsx(o,{...n,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:n=>e.jsx(o,{...n,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(oe,{content:({active:n,payload:c,label:x})=>{if(!n||!c||!c.length)return null;const u=c[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:x}),c.map((m,j)=>e.jsxs("p",{className:d("text-sm",r&&y),style:{color:m.color},children:[m.name,":"," ",m.name==="Tokens"?X(Number(m.value)||0):`$${m.value}`]},j)),"requests"in u&&e.jsxs("p",{className:d("text-sm text-muted-foreground mt-1",r&&y),children:["Requests: ",u.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 ns(s,t){if(t==="hourly"){const[l,r]=s.split(" ");if(l&&r){const i=new Date(`${l}T${r}:00Z`);return k(i,"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 ls({data:s,isLoading:t,className:a}){const{privacyMode:l}=M(),r=f.useMemo(()=>!s||s.length===0?[]:s.map(n=>({name:n.model,value:n.tokens,cost:n.cost,percentage:n.percentage,fill:te(n.model)})),[s]);if(t)return e.jsx(h,{className:d("h-[300px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:d("h-[300px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:"No model data available"})});const i=({active:n,payload:c})=>{if(!n||!c)return null;const x=c;if(!x.length)return null;const u=x[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:u.name}),e.jsxs("p",{className:d("text-muted-foreground",l&&y),children:[is(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:d("text-muted-foreground",l&&y),children:["$",u.cost.toFixed(4)]})]})},o=n=>n.percentage>5?`${n.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:d("w-full",a),children:e.jsx(ie,{width:"100%",height:250,children:e.jsxs(Ie,{children:[e.jsx(Oe,{data:r,cx:"50%",cy:"50%",labelLine:!1,label:o,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:r.map((n,c)=>e.jsx(Ke,{fill:n.fill,strokeWidth:1},`cell-${c}`))}),e.jsx(oe,{content:i})]})})})}function is(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function os({data:s,isLoading:t,className:a}){const{privacyMode:l}=M(),r=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,o=s.total,n=i.reduce((b,v)=>b+(v.inputTokens+v.outputTokens),0),c=Math.round(n/i.length),u=i.reduce((b,v)=>b+v.cost,0)/i.length,m=i[0],j=m?Q(new Date(m.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:o,avgTokens:c,avgCost:u,lastActive:j,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(p,{className:d("flex flex-col h-full",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsx(h,{className:"h-5 w-32"})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}):r?e.jsxs(p,{className:d("flex flex-col h-full shadow-sm",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(g,{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(Se,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:r.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:d("text-xl font-bold",l&&y),children:["$",r.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(Le,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5",children:r.recentSessions.map(i=>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:i.projectPath,children:i.projectPath.split("/").pop()}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Q(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:d("text-right shrink-0 ml-2",l&&y),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[cs(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(p,{className:d("flex flex-col h-full",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(g,{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 cs(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 ds({className:s,isLoading:t}){const{data:a,isLoading:l}=je(),{data:r,isLoading:i,error:o}=Ne(a?.running);if(t||l||a?.running&&i)return e.jsxs(p,{className:d("flex flex-col h-full",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(p,{className:d("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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"secondary",className:"text-[10px] h-5",children:"Offline"})]})}),e.jsx(g,{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(o)return e.jsxs(p,{className:d("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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:o.message})})]});const c=r?.totalRequests??0,x=r?.quotaExceededCount??0,u=c-x,m=c>0?Math.round(u/c*100):100,j=r?.tokens?.total??0,b=Object.entries(r?.requestsByModel??{}).sort((C,$)=>$[1]-C[1]).slice(0,4),v=b.length>0?b[0][1]:1;return e.jsxs(p,{className:d("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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(I,{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(g,{className:"p-0 flex-1 min-h-0",children:e.jsx(ye,{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:`${m*.88} 88`,strokeLinecap:"round",className:m>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[m,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(c)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:x>0?`${x} 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(De,{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(j)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:"Total tokens"})]})]})]}),b.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(Te,{className:"h-3 w-3"}),"Models Used"]}),e.jsx("div",{className:"space-y-1",children:b.map(([C,$])=>{const A=Math.round($/v*100),B=xs(C);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:C,children:B}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:$})]}),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:`${A}%`}})})]},C)})})]})]})})})]})}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function xs(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}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 ms({models:s,isLoading:t,onModelClick:a,privacyMode:l}){return e.jsxs(p,{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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ae,{className:"w-4 h-4"}),"Cost by Model"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(h,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((r,i)=>i.cost-r.cost).map(r=>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:i=>a(r,i),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(r.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:r.model})]}),e.jsx(hs,{model:r}),e.jsx("span",{className:d("text-[10px] text-muted-foreground w-14 text-right shrink-0",l&&y),children:us(r.tokens)}),e.jsxs("span",{className:d("font-mono font-medium w-16 text-right shrink-0",l&&y),children:["$",r.cost.toFixed(2)]}),e.jsx(Fe,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},r.model)),e.jsx(fs,{})]})})]})}function hs({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=l=>s.cost>0?l/s.cost*100:0;return 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:t.input,width:`${a(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${a(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${a(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${a(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function fs(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:a,hasBorder:l})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:d("w-2 h-2 rounded-full",l&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function ps({viewMode:s,trends:t,hourlyData:a,models:l,sessions:r,isTrendsLoading:i,isHourlyLoading:o,isModelsLoading:n,isSessionsLoading:c,isSummaryLoading:x,onModelClick:u}){const{privacyMode:m}=M();return e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 gap-4",children:[e.jsxs(p,{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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Re,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(rs,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?o:i,granularity:s==="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.jsx(ms,{models:l,isLoading:n,onModelClick:u,privacyMode:m}),e.jsxs(p,{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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(ls,{data:l||[],isLoading:n,className:"h-full w-full"})})]}),e.jsx(os,{data:r,isLoading:c,className:"lg:col-span-2"}),e.jsx(ds,{isLoading:x,className:"lg:col-span-2"})]})]})}function Ls(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(p,{className:"flex flex-col min-h-[300px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-32"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{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(h,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(h,{className:"h-3 w-24"})]}),e.jsx(h,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{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(h,{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(h,{className:"w-2 h-2 rounded-full"}),e.jsx(h,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Ds(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:l,handleRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:n,summary:c,isSummaryLoading:x,trends:u,hourlyData:m,models:j,sessions:b,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:$,isSessionsLoading:A,handleModelClick:B,selectedModel:U,popoverPosition:q,handlePopoverClose:_}=ss();return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden px-4 pt-4 pb-50 gap-4",children:[e.jsx(as,{dateRange:t,onDateRangeChange:a,onTodayClick:l,onRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:n}),e.jsx(Ee,{data:c,isLoading:x}),e.jsx(ps,{viewMode:n,trends:u,hourlyData:m,models:j,sessions:b,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:$,isSessionsLoading:A,isSummaryLoading:x,onModelClick:B}),e.jsxs(ee,{open:!!U,onOpenChange:O=>!O&&_(),children:[e.jsx(be,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:q?.x??0,top:q?.y??0,width:1,height:1}})}),e.jsx(se,{className:"w-80 p-3",side:"top",align:"center",children:U&&e.jsx(Ge,{model:U})})]})]})}export{Ds as AnalyticsPage,Ls as AnalyticsSkeleton};
|
|
1
|
+
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as f,c as fe}from"./react-vendor-B_CU-WTZ.js";import{u as M,S as h,c as d,P as y,B as I,a as H,b as ee,d as pe,e as se,C as ge,g as te,f as je,h as Ne,i as ye,j as be}from"./index-DXF1Z58h.js";import{C as p,a as g,b as N,c as S}from"./card-ClMztcJ3.js";import{x as we,a2 as ae,a3 as z,a4 as re,v as ne,Q as ve,G as ke,a5 as Ce,a0 as $e,t as Y,U as Se,Z as le,q as Le,_ as G,a6 as De,s as Te,b as Fe,a7 as Re,a8 as Me}from"./icons-CwFZAiDB.js";import{u as Pe,a as P}from"./tanstack-Coed0rqz.js";import{K as D,L as Q,f as k,H as Ae}from"./utils-CzKF5WmX.js";import{R as ie,A as Be,C as Ue,X as qe,Y as V,T as oe,a as Z,P as Ie,b as Oe,c as Ke}from"./charts-CJC4bH8P.js";import"./notifications-dJQY2-U6.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function Ee({data:s,isLoading:t}){const{privacyMode:a}=M();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(o=>e.jsx(p,{children:e.jsx(g,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-8 w-[80px]"})]}),e.jsx(h,{className:"h-8 w-8 rounded-lg"})]})})},o))});const l=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),r=s?.totalCost?Math.round(l/s.totalCost*100):0,i=[{title:"Total Tokens",value:s?.totalTokens??0,icon:we,format:o=>R(o),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:`${R(s?.totalInputTokens??0)} in / ${R(s?.totalOutputTokens??0)} out`},{title:"Total Cost",value:s?.totalCost??0,icon:ae,format:o=>`$${o.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:z,format:o=>R(o),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:`$${l.toFixed(2)} (${r}% of cost)`},{title:"Input Cost",value:s?.tokenBreakdown?.input?.cost??0,icon:re,format:o=>`$${o.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:`${R(s?.tokenBreakdown?.input?.tokens??0)} tokens`},{title:"Output Cost",value:s?.tokenBreakdown?.output?.cost??0,icon:ne,format:o=>`$${o.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:`${R(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:i.map((o,n)=>{const c=o.icon;return e.jsx(p,{className:"hover:shadow-md transition-shadow",children:e.jsx(g,{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:o.title}),e.jsx("p",{className:d("text-xl font-bold truncate",a&&y),children:o.format(o.value)}),o.subtitle&&e.jsx("p",{className:d("text-[10px] text-muted-foreground truncate",a&&y),children:o.subtitle})]}),e.jsx("div",{className:d("p-2 rounded-lg shrink-0",o.bgColor),children:e.jsx(c,{className:d("h-4 w-4",o.color)})})]})})},n)})})}function R(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ge({model:s}){const{privacyMode:t}=M(),a=We(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(ve,{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(I,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(I,{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:d("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:d("text-lg font-bold",t&&y),children:_e(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:d("space-y-1",t&&y),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:re}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:ne}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:z}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:z})]})]}),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(ke,{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 W({label:s,tokens:t,cost:a,color:l,icon:r}){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:l}}),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(r,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:He(t)})]})]})]})}function We(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 He(s){return s.toLocaleString()}function _e(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()}const ze="/api";function w(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0");return`${t}${a}${l}`}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),L(`/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),L(`/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)),L(`/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),L(`/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()),L(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),L(`/usage/monthly?${a}`)},refresh:async()=>{if(!(await fetch(`${ze}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>L("/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),L(`/usage/insights?${t}`)}};async function L(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const r=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(r.error||a.statusText)}const l=await a.json();return l.data||l}function Qe(s){return P({queryKey:["usage","summary",s],queryFn:()=>T.summary(s),staleTime:60*1e3})}function Ye(s){return P({queryKey:["usage","trends",s],queryFn:()=>T.trends(s),staleTime:60*1e3})}function Ve(s){return P({queryKey:["usage","hourly",s],queryFn:()=>T.hourly(s),staleTime:60*1e3})}function Ze(s){return P({queryKey:["usage","models",s],queryFn:()=>T.models(s),staleTime:60*1e3})}function Xe(){const s=Pe();return f.useCallback(async()=>{await T.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function Je(){return P({queryKey:["usage","status"],queryFn:()=>T.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function es(s){return P({queryKey:["usage","sessions",s],queryFn:()=>T.sessions(s),staleTime:60*1e3})}function ss(){const[s,t]=f.useState({from:D(new Date,30),to:new Date}),[a,l]=f.useState(!1),[r,i]=f.useState(null),[o,n]=f.useState(null),[c,x]=f.useState("daily"),u=Xe(),m=f.useCallback(async()=>{l(!0);try{await u()}finally{l(!1)}},[u]),j=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:b,isLoading:v}=Qe(j),{data:C,isLoading:$}=Ye(j),{data:A,isLoading:B}=Ve(j),{data:U,isLoading:q}=Ze(j),{data:_,isLoading:O}=es({...j,limit:3}),{data:K}=Je(),ce=f.useCallback(()=>{const F=new Date;t({from:D(F,1),to:F}),x("hourly")},[]),de=f.useCallback(F=>{t(F),x("daily")},[]),xe=f.useMemo(()=>K?.lastFetch?Q(new Date(K.lastFetch),{addSuffix:!0}):null,[K?.lastFetch]),ue=f.useCallback((F,he)=>{const E=he.currentTarget.getBoundingClientRect();n({x:E.left+E.width/2,y:E.top+E.height/2}),i(F)},[]),me=f.useCallback(()=>{i(null),n(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:c,selectedModel:r,popoverPosition:o,summary:b,trends:C,hourlyData:A,models:U,sessions:_,status:K,isSummaryLoading:v,isTrendsLoading:$,isHourlyLoading:B,isModelsLoading:q,isSessionsLoading:O,isLoading:v||$||q||O,handleRefresh:m,handleTodayClick:ce,handleDateRangeChange:de,handleModelClick:ue,handlePopoverClose:me,lastUpdatedText:xe}}function ts({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:D(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:D(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:D(new Date,90),to:new Date}}],className:l}){const[r,i]=fe.useState(!1),o=n=>!s||!s.from||!s.to||!n.from||!n.to?!1:k(s.from,"yyyy-MM-dd")===k(n.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(n.to,"yyyy-MM-dd");return e.jsxs("div",{className:d("flex items-center gap-2",l),children:[a.map(n=>e.jsx(H,{variant:o(n.range)?"default":"outline",size:"sm",onClick:()=>t(n.range),children:n.label},n.label)),e.jsxs(ee,{open:r,onOpenChange:i,children:[e.jsx(pe,{asChild:!0,children:e.jsxs(H,{id:"date",variant:"outline",className:d("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(ge,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function as({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:l,isRefreshing:r,lastUpdatedText:i,viewMode:o}){return 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(H,{variant:o==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(ts,{value:s,onChange:t,presets:[{label:"7D",range:{from:D(new Date,7),to:new Date}},{label:"30D",range:{from:D(new Date,30),to:new Date}},{label:"Month",range:{from:Ae(new Date),to:new Date}},{label:"All Time",range:{from:void 0,to:new Date}}]}),i&&e.jsxs("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:["Updated ",i]}),e.jsx(H,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:l,disabled:r,children:e.jsx($e,{className:`w-3.5 h-3.5 ${r?"animate-spin":""}`})})]})]})}function rs({data:s,isLoading:t,granularity:a="daily",className:l}){const{privacyMode:r}=M(),i=f.useMemo(()=>!s||s.length===0?[]:(a==="hourly"?s:[...s].reverse()).map(c=>{const x="hour"in c?c.hour:c.date;return{...c,dateFormatted:ns(x,a),costRounded:Number(c.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(h,{className:d("h-full w-full",l)});if(!s||s.length===0)return e.jsx("div",{className:d("h-full flex items-center justify-center",l),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const o=({x:n,y:c,payload:x,isRight:u})=>{const m=u?`$${x.value}`:X(Number(x.value));return e.jsx("text",{x:n,y:c,dy:4,textAnchor:u?"start":"end",fontSize:12,fill:"currentColor",className:d("fill-muted-foreground",r&&"blur-[4px]"),children:m})};return e.jsx("div",{className:d("w-full h-full",l),children:e.jsx(ie,{width:"100%",height:"100%",children:e.jsxs(Be,{data:i,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(Ue,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(qe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"left",orientation:"left",tick:n=>e.jsx(o,{...n,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:n=>e.jsx(o,{...n,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(oe,{content:({active:n,payload:c,label:x})=>{if(!n||!c||!c.length)return null;const u=c[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:x}),c.map((m,j)=>e.jsxs("p",{className:d("text-sm",r&&y),style:{color:m.color},children:[m.name,":"," ",m.name==="Tokens"?X(Number(m.value)||0):`$${m.value}`]},j)),"requests"in u&&e.jsxs("p",{className:d("text-sm text-muted-foreground mt-1",r&&y),children:["Requests: ",u.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 ns(s,t){if(t==="hourly"){const[l,r]=s.split(" ");if(l&&r){const i=new Date(`${l}T${r}:00Z`);return k(i,"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 ls({data:s,isLoading:t,className:a}){const{privacyMode:l}=M(),r=f.useMemo(()=>!s||s.length===0?[]:s.map(n=>({name:n.model,value:n.tokens,cost:n.cost,percentage:n.percentage,fill:te(n.model)})),[s]);if(t)return e.jsx(h,{className:d("h-[300px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:d("h-[300px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:"No model data available"})});const i=({active:n,payload:c})=>{if(!n||!c)return null;const x=c;if(!x.length)return null;const u=x[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:u.name}),e.jsxs("p",{className:d("text-muted-foreground",l&&y),children:[is(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:d("text-muted-foreground",l&&y),children:["$",u.cost.toFixed(4)]})]})},o=n=>n.percentage>5?`${n.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:d("w-full",a),children:e.jsx(ie,{width:"100%",height:250,children:e.jsxs(Ie,{children:[e.jsx(Oe,{data:r,cx:"50%",cy:"50%",labelLine:!1,label:o,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:r.map((n,c)=>e.jsx(Ke,{fill:n.fill,strokeWidth:1},`cell-${c}`))}),e.jsx(oe,{content:i})]})})})}function is(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function os({data:s,isLoading:t,className:a}){const{privacyMode:l}=M(),r=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,o=s.total,n=i.reduce((b,v)=>b+(v.inputTokens+v.outputTokens),0),c=Math.round(n/i.length),u=i.reduce((b,v)=>b+v.cost,0)/i.length,m=i[0],j=m?Q(new Date(m.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:o,avgTokens:c,avgCost:u,lastActive:j,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(p,{className:d("flex flex-col h-full",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsx(h,{className:"h-5 w-32"})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}):r?e.jsxs(p,{className:d("flex flex-col h-full shadow-sm",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(g,{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(Se,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:r.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:d("text-xl font-bold",l&&y),children:["$",r.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(Le,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5",children:r.recentSessions.map(i=>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:i.projectPath,children:i.projectPath.split("/").pop()}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Q(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:d("text-right shrink-0 ml-2",l&&y),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[cs(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(p,{className:d("flex flex-col h-full",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(g,{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 cs(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 ds({className:s,isLoading:t}){const{data:a,isLoading:l}=je(),{data:r,isLoading:i,error:o}=Ne(a?.running);if(t||l||a?.running&&i)return e.jsxs(p,{className:d("flex flex-col h-full",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(p,{className:d("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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"secondary",className:"text-[10px] h-5",children:"Offline"})]})}),e.jsx(g,{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(o)return e.jsxs(p,{className:d("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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:o.message})})]});const c=r?.totalRequests??0,x=r?.quotaExceededCount??0,u=c-x,m=c>0?Math.round(u/c*100):100,j=r?.tokens?.total??0,b=Object.entries(r?.requestsByModel??{}).sort((C,$)=>$[1]-C[1]).slice(0,4),v=b.length>0?b[0][1]:1;return e.jsxs(p,{className:d("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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(I,{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(g,{className:"p-0 flex-1 min-h-0",children:e.jsx(ye,{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:`${m*.88} 88`,strokeLinecap:"round",className:m>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[m,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(c)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:x>0?`${x} 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(De,{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(j)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:"Total tokens"})]})]})]}),b.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(Te,{className:"h-3 w-3"}),"Models Used"]}),e.jsx("div",{className:"space-y-1",children:b.map(([C,$])=>{const A=Math.round($/v*100),B=xs(C);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:C,children:B}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:$})]}),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:`${A}%`}})})]},C)})})]})]})})})]})}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function xs(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}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 ms({models:s,isLoading:t,onModelClick:a,privacyMode:l}){return e.jsxs(p,{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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ae,{className:"w-4 h-4"}),"Cost by Model"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(h,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((r,i)=>i.cost-r.cost).map(r=>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:i=>a(r,i),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(r.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:r.model})]}),e.jsx(hs,{model:r}),e.jsx("span",{className:d("text-[10px] text-muted-foreground w-14 text-right shrink-0",l&&y),children:us(r.tokens)}),e.jsxs("span",{className:d("font-mono font-medium w-16 text-right shrink-0",l&&y),children:["$",r.cost.toFixed(2)]}),e.jsx(Fe,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},r.model)),e.jsx(fs,{})]})})]})}function hs({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=l=>s.cost>0?l/s.cost*100:0;return 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:t.input,width:`${a(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${a(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${a(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${a(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function fs(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:a,hasBorder:l})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:d("w-2 h-2 rounded-full",l&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function ps({viewMode:s,trends:t,hourlyData:a,models:l,sessions:r,isTrendsLoading:i,isHourlyLoading:o,isModelsLoading:n,isSessionsLoading:c,isSummaryLoading:x,onModelClick:u}){const{privacyMode:m}=M();return e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 gap-4",children:[e.jsxs(p,{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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Re,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(rs,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?o:i,granularity:s==="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.jsx(ms,{models:l,isLoading:n,onModelClick:u,privacyMode:m}),e.jsxs(p,{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(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(ls,{data:l||[],isLoading:n,className:"h-full w-full"})})]}),e.jsx(os,{data:r,isLoading:c,className:"lg:col-span-2"}),e.jsx(ds,{isLoading:x,className:"lg:col-span-2"})]})]})}function Ls(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(p,{className:"flex flex-col min-h-[300px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-32"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{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(h,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(h,{className:"h-3 w-24"})]}),e.jsx(h,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{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(h,{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(h,{className:"w-2 h-2 rounded-full"}),e.jsx(h,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Ds(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:l,handleRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:n,summary:c,isSummaryLoading:x,trends:u,hourlyData:m,models:j,sessions:b,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:$,isSessionsLoading:A,handleModelClick:B,selectedModel:U,popoverPosition:q,handlePopoverClose:_}=ss();return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden px-4 pt-4 pb-50 gap-4",children:[e.jsx(as,{dateRange:t,onDateRangeChange:a,onTodayClick:l,onRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:n}),e.jsx(Ee,{data:c,isLoading:x}),e.jsx(ps,{viewMode:n,trends:u,hourlyData:m,models:j,sessions:b,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:$,isSessionsLoading:A,isSummaryLoading:x,onModelClick:B}),e.jsxs(ee,{open:!!U,onOpenChange:O=>!O&&_(),children:[e.jsx(be,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:q?.x??0,top:q?.y??0,width:1,height:1}})}),e.jsx(se,{className:"w-80 p-3",side:"top",align:"center",children:U&&e.jsx(Ge,{model:U})})]})]})}export{Ds as AnalyticsPage,Ls as AnalyticsSkeleton};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as i}from"./react-vendor-B_CU-WTZ.js";import{aB as $,aC as P,I as F,aD as U,ay as B,aA as _,i as D,a as A}from"./index-8HAJX3-Y.js";import{S as K}from"./switch-D_o-N1Sa.js";import{t as z,j as q,D as J,J as V,m as Y,a0 as L,V as X,n as Z}from"./icons-CwFZAiDB.js";import"./tanstack-Coed0rqz.js";import"./notifications-dJQY2-U6.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function Q(){const{state:s}=$(),a=P(),[d,l]=i.useState(""),[o,m]=i.useState(""),[f,h]=i.useState(!1),[j,u]=i.useState(!1),S=i.useCallback(async()=>{try{a.setWebSearchLoading(!0),a.setWebSearchError(null);const t=await fetch("/api/websearch");if(!t.ok)throw new Error("Failed to load WebSearch config");const r=await t.json();a.setWebSearchConfig(r)}catch(t){a.setWebSearchError(t.message)}finally{a.setWebSearchLoading(!1)}},[a]),v=i.useCallback(async()=>{try{a.setWebSearchStatusLoading(!0);const t=await fetch("/api/websearch/status");if(!t.ok)throw new Error("Failed to load status");const r=await t.json();a.setWebSearchStatus(r)}catch{}finally{a.setWebSearchStatusLoading(!1)}},[a]),p=i.useCallback(async t=>{const r=s.webSearchConfig;if(!r)return;const w={...r,...t};a.setWebSearchConfig(w);try{a.setWebSearchSaving(!0),a.setWebSearchError(null);const n=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)});if(!n.ok){const k=await n.json();throw new Error(k.error||"Failed to save")}const C=await n.json();a.setWebSearchConfig(C.websearch),a.setWebSearchSuccess(!0),setTimeout(()=>a.setWebSearchSuccess(!1),1500)}catch(n){a.setWebSearchConfig(r),a.setWebSearchError(n.message)}finally{a.setWebSearchSaving(!1)}},[s.webSearchConfig,a]);i.useEffect(()=>{s.webSearchConfig&&(l(s.webSearchConfig.providers?.gemini?.model??"gemini-2.5-flash"),m(s.webSearchConfig.providers?.opencode?.model??"opencode/grok-code"))},[s.webSearchConfig]);const x=i.useCallback(async()=>{const t=s.webSearchConfig?.providers?.gemini?.model??"gemini-2.5-flash";if(d!==t){const r=s.webSearchConfig?.providers||{};await p({providers:{...r,gemini:{...r.gemini,model:d}}}),h(!0),setTimeout(()=>h(!1),2e3)}},[d,s.webSearchConfig,p]),g=i.useCallback(async()=>{const t=s.webSearchConfig?.providers?.opencode?.model??"opencode/grok-code";if(o!==t){const r=s.webSearchConfig?.providers||{};await p({providers:{...r,opencode:{...r.opencode,model:o}}}),u(!0),setTimeout(()=>u(!1),2e3)}},[o,s.webSearchConfig,p]);return{config:s.webSearchConfig,status:s.webSearchStatus,loading:s.webSearchLoading,statusLoading:s.webSearchStatusLoading,saving:s.webSearchSaving,error:s.webSearchError,success:s.webSearchSuccess,geminiModelInput:d,setGeminiModelInput:l,opencodeModelInput:o,setOpencodeModelInput:m,geminiModelSaved:f,opencodeModelSaved:j,fetchConfig:S,fetchStatus:v,saveConfig:p,saveGeminiModel:x,saveOpencodeModel:g}}function O({name:s,label:a,badge:d,badgeColor:l,enabled:o,installed:m,statusLoading:f,saving:h,onToggle:j,modelInput:u,setModelInput:S,onModelBlur:v,modelSaved:p,modelPlaceholder:x,showHint:g,setShowHint:t,installCmd:r,docsUrl:w,hintColor:n}){const C=l==="green"?"bg-green-500/10 text-green-600":l==="blue"?"bg-blue-500/10 text-blue-600":"bg-purple-500/10 text-purple-600",k=n==="amber"?"bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300":n==="blue"?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",y=n==="amber"?"bg-amber-100 dark:bg-amber-900/40":n==="blue"?"bg-blue-100 dark:bg-blue-900/40":"bg-purple-100 dark:bg-purple-900/40",E=n==="amber"?"text-amber-600 dark:text-amber-400":n==="blue"?"text-blue-600 dark:text-blue-400":"text-purple-600 dark:text-purple-400",M=s==="opencode"?"OpenCode":s.charAt(0).toUpperCase()+s.slice(1);return e.jsxs("div",{className:`rounded-lg border transition-colors ${o?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(z,{className:`w-5 h-5 ${o?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:s}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${C}`,children:d}),m?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"installed"}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:"not installed"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a})]})]}),e.jsx(K,{checked:o,onCheckedChange:j,disabled:h||!m})]}),o&&u!==void 0&&S&&v&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:"Model:"}),e.jsx(F,{value:u,onChange:I=>S(I.target.value),onBlur:v,placeholder:x,className:"h-8 text-sm font-mono",disabled:h}),p&&e.jsxs("span",{className:"flex items-center gap-1 text-green-600 dark:text-green-400 text-xs animate-in fade-in duration-200",children:[e.jsx(q,{className:"w-3.5 h-3.5"}),"Saved"]})]})}),!m&&!f&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>t(!g),className:`flex items-center gap-2 text-sm hover:underline w-full py-2 ${E}`,children:[g?e.jsx(J,{className:"w-4 h-4"}):e.jsx(V,{className:"w-4 h-4"}),"How to install ",M," CLI"]}),g&&e.jsxs("div",{className:`mt-2 p-3 rounded-md text-sm ${k}`,children:[e.jsxs("p",{className:"mb-2",children:["Install globally"," ",d==="GROK_API_KEY"?"(requires xAI API key)":"(FREE tier available)",":"]}),e.jsx("code",{className:`text-sm px-2 py-1 rounded font-mono block mb-2 ${y}`,children:r}),e.jsxs("a",{href:w,target:"_blank",rel:"noopener noreferrer",className:"hover:underline inline-flex items-center gap-1",children:[e.jsx(Y,{className:"w-3 h-3"}),"View documentation"]})]})]})]})}function ce(){const{config:s,status:a,loading:d,statusLoading:l,saving:o,error:m,success:f,geminiModelInput:h,setGeminiModelInput:j,opencodeModelInput:u,setOpencodeModelInput:S,geminiModelSaved:v,opencodeModelSaved:p,fetchConfig:x,fetchStatus:g,saveConfig:t,saveGeminiModel:r,saveOpencodeModel:w}=Q(),{fetchRawConfig:n}=U(),[C,k]=i.useState(!1),[y,E]=i.useState(!1),[M,I]=i.useState(!1);i.useEffect(()=>{x(),g(),n()},[x,g,n]);const N=s?.providers?.gemini?.enabled??!1,W=s?.providers?.grok?.enabled??!1,G=s?.providers?.opencode?.enabled??!1,H=()=>{const c=s?.providers||{},b=c.gemini?.enabled??!1;t({enabled:!b||W||G,providers:{...c,gemini:{...c.gemini,enabled:!b}}})},R=()=>{const c=s?.providers||{},b=c.grok?.enabled??!1;t({enabled:N||!b||G,providers:{...c,grok:{...c.grok,enabled:!b}}})},T=()=>{const c=s?.providers||{},b=c.opencode?.enabled??!1;t({enabled:N||W||!b,providers:{...c,opencode:{...c.opencode,enabled:!b}}})};return d?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(L,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${m||f?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[m&&e.jsxs(B,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(X,{className:"h-4 w-4"}),e.jsx(_,{children:m})]}),f&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(Z,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(D,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"CLI-based web search for third-party profiles (gemini, codex, agy, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:N?"WebSearch enabled":"WebSearch disabled"}),l?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking status..."}):a?.readiness?e.jsx("p",{className:"text-sm text-muted-foreground",children:a.readiness.message}):null]}),e.jsx(A,{variant:"ghost",size:"sm",onClick:g,disabled:l,children:e.jsx(L,{className:`w-4 h-4 ${l?"animate-spin":""}`})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Providers"}),e.jsx(O,{name:"gemini",label:"Google Gemini CLI (1000 req/day free)",badge:"FREE",badgeColor:"green",enabled:N,installed:a?.geminiCli?.installed??!1,statusLoading:l,saving:o,onToggle:H,modelInput:h,setModelInput:j,onModelBlur:r,modelSaved:v,modelPlaceholder:"gemini-2.5-flash",showHint:C,setShowHint:k,installCmd:"npm install -g @google/gemini-cli",docsUrl:"https://github.com/google-gemini/gemini-cli",hintColor:"amber"}),e.jsx(O,{name:"opencode",label:"OpenCode (web search via Zen)",badge:"FREE",badgeColor:"green",enabled:G,installed:a?.opencodeCli?.installed??!1,statusLoading:l,saving:o,onToggle:T,modelInput:u,setModelInput:S,onModelBlur:w,modelSaved:p,modelPlaceholder:"opencode/grok-code",showHint:y,setShowHint:E,installCmd:"curl -fsSL https://opencode.ai/install | bash",docsUrl:"https://github.com/sst/opencode",hintColor:"purple"}),e.jsx(O,{name:"grok",label:"xAI Grok CLI (web + X search)",badge:"GROK_API_KEY",badgeColor:"blue",enabled:W,installed:a?.grokCli?.installed??!1,statusLoading:l,saving:o,onToggle:R,showHint:M,setShowHint:I,installCmd:"npm install -g @vibe-kit/grok-cli",docsUrl:"https://github.com/superagent-ai/grok-cli",hintColor:"blue"})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>{x(),n()},disabled:d||o,className:"w-full",children:[e.jsx(L,{className:`w-4 h-4 mr-2 ${d?"animate-spin":""}`}),"Refresh"]})})]})}export{ce as default};
|
|
1
|
+
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as i}from"./react-vendor-B_CU-WTZ.js";import{aB as $,aC as P,I as F,aD as U,ay as B,aA as _,i as D,a as A}from"./index-DXF1Z58h.js";import{S as K}from"./switch-Big41pQ7.js";import{t as z,j as q,D as J,J as V,m as Y,a0 as L,V as X,n as Z}from"./icons-CwFZAiDB.js";import"./tanstack-Coed0rqz.js";import"./notifications-dJQY2-U6.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function Q(){const{state:s}=$(),a=P(),[d,l]=i.useState(""),[o,m]=i.useState(""),[f,h]=i.useState(!1),[j,u]=i.useState(!1),S=i.useCallback(async()=>{try{a.setWebSearchLoading(!0),a.setWebSearchError(null);const t=await fetch("/api/websearch");if(!t.ok)throw new Error("Failed to load WebSearch config");const r=await t.json();a.setWebSearchConfig(r)}catch(t){a.setWebSearchError(t.message)}finally{a.setWebSearchLoading(!1)}},[a]),v=i.useCallback(async()=>{try{a.setWebSearchStatusLoading(!0);const t=await fetch("/api/websearch/status");if(!t.ok)throw new Error("Failed to load status");const r=await t.json();a.setWebSearchStatus(r)}catch{}finally{a.setWebSearchStatusLoading(!1)}},[a]),p=i.useCallback(async t=>{const r=s.webSearchConfig;if(!r)return;const w={...r,...t};a.setWebSearchConfig(w);try{a.setWebSearchSaving(!0),a.setWebSearchError(null);const n=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)});if(!n.ok){const k=await n.json();throw new Error(k.error||"Failed to save")}const C=await n.json();a.setWebSearchConfig(C.websearch),a.setWebSearchSuccess(!0),setTimeout(()=>a.setWebSearchSuccess(!1),1500)}catch(n){a.setWebSearchConfig(r),a.setWebSearchError(n.message)}finally{a.setWebSearchSaving(!1)}},[s.webSearchConfig,a]);i.useEffect(()=>{s.webSearchConfig&&(l(s.webSearchConfig.providers?.gemini?.model??"gemini-2.5-flash"),m(s.webSearchConfig.providers?.opencode?.model??"opencode/grok-code"))},[s.webSearchConfig]);const x=i.useCallback(async()=>{const t=s.webSearchConfig?.providers?.gemini?.model??"gemini-2.5-flash";if(d!==t){const r=s.webSearchConfig?.providers||{};await p({providers:{...r,gemini:{...r.gemini,model:d}}}),h(!0),setTimeout(()=>h(!1),2e3)}},[d,s.webSearchConfig,p]),g=i.useCallback(async()=>{const t=s.webSearchConfig?.providers?.opencode?.model??"opencode/grok-code";if(o!==t){const r=s.webSearchConfig?.providers||{};await p({providers:{...r,opencode:{...r.opencode,model:o}}}),u(!0),setTimeout(()=>u(!1),2e3)}},[o,s.webSearchConfig,p]);return{config:s.webSearchConfig,status:s.webSearchStatus,loading:s.webSearchLoading,statusLoading:s.webSearchStatusLoading,saving:s.webSearchSaving,error:s.webSearchError,success:s.webSearchSuccess,geminiModelInput:d,setGeminiModelInput:l,opencodeModelInput:o,setOpencodeModelInput:m,geminiModelSaved:f,opencodeModelSaved:j,fetchConfig:S,fetchStatus:v,saveConfig:p,saveGeminiModel:x,saveOpencodeModel:g}}function O({name:s,label:a,badge:d,badgeColor:l,enabled:o,installed:m,statusLoading:f,saving:h,onToggle:j,modelInput:u,setModelInput:S,onModelBlur:v,modelSaved:p,modelPlaceholder:x,showHint:g,setShowHint:t,installCmd:r,docsUrl:w,hintColor:n}){const C=l==="green"?"bg-green-500/10 text-green-600":l==="blue"?"bg-blue-500/10 text-blue-600":"bg-purple-500/10 text-purple-600",k=n==="amber"?"bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300":n==="blue"?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",y=n==="amber"?"bg-amber-100 dark:bg-amber-900/40":n==="blue"?"bg-blue-100 dark:bg-blue-900/40":"bg-purple-100 dark:bg-purple-900/40",E=n==="amber"?"text-amber-600 dark:text-amber-400":n==="blue"?"text-blue-600 dark:text-blue-400":"text-purple-600 dark:text-purple-400",M=s==="opencode"?"OpenCode":s.charAt(0).toUpperCase()+s.slice(1);return e.jsxs("div",{className:`rounded-lg border transition-colors ${o?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(z,{className:`w-5 h-5 ${o?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:s}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${C}`,children:d}),m?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"installed"}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:"not installed"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a})]})]}),e.jsx(K,{checked:o,onCheckedChange:j,disabled:h||!m})]}),o&&u!==void 0&&S&&v&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:"Model:"}),e.jsx(F,{value:u,onChange:I=>S(I.target.value),onBlur:v,placeholder:x,className:"h-8 text-sm font-mono",disabled:h}),p&&e.jsxs("span",{className:"flex items-center gap-1 text-green-600 dark:text-green-400 text-xs animate-in fade-in duration-200",children:[e.jsx(q,{className:"w-3.5 h-3.5"}),"Saved"]})]})}),!m&&!f&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>t(!g),className:`flex items-center gap-2 text-sm hover:underline w-full py-2 ${E}`,children:[g?e.jsx(J,{className:"w-4 h-4"}):e.jsx(V,{className:"w-4 h-4"}),"How to install ",M," CLI"]}),g&&e.jsxs("div",{className:`mt-2 p-3 rounded-md text-sm ${k}`,children:[e.jsxs("p",{className:"mb-2",children:["Install globally"," ",d==="GROK_API_KEY"?"(requires xAI API key)":"(FREE tier available)",":"]}),e.jsx("code",{className:`text-sm px-2 py-1 rounded font-mono block mb-2 ${y}`,children:r}),e.jsxs("a",{href:w,target:"_blank",rel:"noopener noreferrer",className:"hover:underline inline-flex items-center gap-1",children:[e.jsx(Y,{className:"w-3 h-3"}),"View documentation"]})]})]})]})}function ce(){const{config:s,status:a,loading:d,statusLoading:l,saving:o,error:m,success:f,geminiModelInput:h,setGeminiModelInput:j,opencodeModelInput:u,setOpencodeModelInput:S,geminiModelSaved:v,opencodeModelSaved:p,fetchConfig:x,fetchStatus:g,saveConfig:t,saveGeminiModel:r,saveOpencodeModel:w}=Q(),{fetchRawConfig:n}=U(),[C,k]=i.useState(!1),[y,E]=i.useState(!1),[M,I]=i.useState(!1);i.useEffect(()=>{x(),g(),n()},[x,g,n]);const N=s?.providers?.gemini?.enabled??!1,W=s?.providers?.grok?.enabled??!1,G=s?.providers?.opencode?.enabled??!1,H=()=>{const c=s?.providers||{},b=c.gemini?.enabled??!1;t({enabled:!b||W||G,providers:{...c,gemini:{...c.gemini,enabled:!b}}})},R=()=>{const c=s?.providers||{},b=c.grok?.enabled??!1;t({enabled:N||!b||G,providers:{...c,grok:{...c.grok,enabled:!b}}})},T=()=>{const c=s?.providers||{},b=c.opencode?.enabled??!1;t({enabled:N||W||!b,providers:{...c,opencode:{...c.opencode,enabled:!b}}})};return d?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(L,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${m||f?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[m&&e.jsxs(B,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(X,{className:"h-4 w-4"}),e.jsx(_,{children:m})]}),f&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(Z,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(D,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"CLI-based web search for third-party profiles (gemini, codex, agy, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:N?"WebSearch enabled":"WebSearch disabled"}),l?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking status..."}):a?.readiness?e.jsx("p",{className:"text-sm text-muted-foreground",children:a.readiness.message}):null]}),e.jsx(A,{variant:"ghost",size:"sm",onClick:g,disabled:l,children:e.jsx(L,{className:`w-4 h-4 ${l?"animate-spin":""}`})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Providers"}),e.jsx(O,{name:"gemini",label:"Google Gemini CLI (1000 req/day free)",badge:"FREE",badgeColor:"green",enabled:N,installed:a?.geminiCli?.installed??!1,statusLoading:l,saving:o,onToggle:H,modelInput:h,setModelInput:j,onModelBlur:r,modelSaved:v,modelPlaceholder:"gemini-2.5-flash",showHint:C,setShowHint:k,installCmd:"npm install -g @google/gemini-cli",docsUrl:"https://github.com/google-gemini/gemini-cli",hintColor:"amber"}),e.jsx(O,{name:"opencode",label:"OpenCode (web search via Zen)",badge:"FREE",badgeColor:"green",enabled:G,installed:a?.opencodeCli?.installed??!1,statusLoading:l,saving:o,onToggle:T,modelInput:u,setModelInput:S,onModelBlur:w,modelSaved:p,modelPlaceholder:"opencode/grok-code",showHint:y,setShowHint:E,installCmd:"curl -fsSL https://opencode.ai/install | bash",docsUrl:"https://github.com/sst/opencode",hintColor:"purple"}),e.jsx(O,{name:"grok",label:"xAI Grok CLI (web + X search)",badge:"GROK_API_KEY",badgeColor:"blue",enabled:W,installed:a?.grokCli?.installed??!1,statusLoading:l,saving:o,onToggle:R,showHint:M,setShowHint:I,installCmd:"npm install -g @vibe-kit/grok-cli",docsUrl:"https://github.com/superagent-ai/grok-cli",hintColor:"blue"})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>{x(),n()},disabled:d||o,className:"w-full",children:[e.jsx(L,{className:`w-4 h-4 mr-2 ${d?"animate-spin":""}`}),"Refresh"]})})]})}export{ce as default};
|