@kaitranntt/ccs 7.13.0 → 7.13.1
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/api/services/validation-service.d.ts.map +1 -1
- package/dist/api/services/validation-service.js +3 -0
- package/dist/api/services/validation-service.js.map +1 -1
- package/dist/cliproxy/account-manager.d.ts +9 -0
- package/dist/cliproxy/account-manager.d.ts.map +1 -1
- package/dist/cliproxy/account-manager.js +25 -5
- package/dist/cliproxy/account-manager.js.map +1 -1
- package/dist/cliproxy/auth/gemini-token-refresh.d.ts +33 -0
- package/dist/cliproxy/auth/gemini-token-refresh.d.ts.map +1 -0
- package/dist/cliproxy/auth/gemini-token-refresh.js +191 -0
- package/dist/cliproxy/auth/gemini-token-refresh.js.map +1 -0
- package/dist/cliproxy/auth/token-manager.d.ts +13 -0
- package/dist/cliproxy/auth/token-manager.d.ts.map +1 -1
- package/dist/cliproxy/auth/token-manager.js +21 -1
- package/dist/cliproxy/auth/token-manager.js.map +1 -1
- package/dist/cliproxy/cliproxy-executor.d.ts.map +1 -1
- package/dist/cliproxy/cliproxy-executor.js +16 -0
- package/dist/cliproxy/cliproxy-executor.js.map +1 -1
- package/dist/cliproxy/proxy-target-resolver.d.ts +11 -1
- package/dist/cliproxy/proxy-target-resolver.d.ts.map +1 -1
- package/dist/cliproxy/proxy-target-resolver.js +22 -1
- 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 +9 -1
- package/dist/cliproxy/remote-auth-fetcher.js.map +1 -1
- package/dist/cliproxy/services/binary-service.d.ts +1 -1
- package/dist/cliproxy/services/binary-service.js +2 -2
- package/dist/cliproxy/services/binary-service.js.map +1 -1
- package/dist/cliproxy/services/variant-service.d.ts.map +1 -1
- package/dist/cliproxy/services/variant-service.js +3 -0
- package/dist/cliproxy/services/variant-service.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/commands/cliproxy-command.d.ts.map +1 -1
- package/dist/commands/cliproxy-command.js +4 -2
- package/dist/commands/cliproxy-command.js.map +1 -1
- package/dist/config/reserved-names.d.ts +12 -0
- package/dist/config/reserved-names.d.ts.map +1 -1
- package/dist/config/reserved-names.js +39 -1
- package/dist/config/reserved-names.js.map +1 -1
- package/dist/config/unified-config-loader.d.ts.map +1 -1
- package/dist/config/unified-config-loader.js +2 -0
- package/dist/config/unified-config-loader.js.map +1 -1
- package/dist/config/unified-config-types.d.ts +8 -1
- 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-CYPk9fa-.js → accounts-DKm_BUkJ.js} +1 -1
- package/dist/ui/assets/{alert-dialog-BrIFqgMZ.js → alert-dialog-BBbNIyvF.js} +1 -1
- package/dist/ui/assets/{api-Bi24p47r.js → api-p6k8BwWO.js} +1 -1
- package/dist/ui/assets/{auth-section-3fqp84IR.js → auth-section-B4wvcy8z.js} +1 -1
- package/dist/ui/assets/{card-ClMztcJ3.js → card-D6fGkasO.js} +1 -1
- package/dist/ui/assets/cliproxy-DuWY_mzK.js +3 -0
- package/dist/ui/assets/{cliproxy-control-panel-Cahd6g6e.js → cliproxy-control-panel-D7gdCCO7.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-ByvRv_aE.js → confirm-dialog-D55Qga4b.js} +1 -1
- package/dist/ui/assets/{copilot-B4AE6FGx.js → copilot-fwj1xk6l.js} +2 -2
- package/dist/ui/assets/{globalenv-section-CGdnlj1K.js → globalenv-section-DMSdqrn_.js} +1 -1
- package/dist/ui/assets/{health-BINs7JKH.js → health-65nETbIF.js} +1 -1
- package/dist/ui/assets/{index-DXF1Z58h.js → index-8HAJX3-Y.js} +2 -2
- package/dist/ui/assets/{index-Cf72mW4U.js → index-BrijlHVl.js} +1 -1
- package/dist/ui/assets/{index-CV_o8KZD.js → index-CwDi6WPm.js} +1 -1
- package/dist/ui/assets/index-Dc8X9bLV.js +1 -0
- package/dist/ui/assets/{shared-bCN7WjG_.js → shared-CMWj9K3T.js} +1 -1
- package/dist/ui/assets/{switch-Big41pQ7.js → switch-D_o-N1Sa.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/cliproxy-CsE7HKWc.js +0 -3
- package/dist/ui/assets/index-4FYBhG16.js +0 -1
|
@@ -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-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
|
+
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as h}from"./react-vendor-B_CU-WTZ.js";import{aB as Z,aC as ee,af as L,I as w,O as te,Q as se,U as ae,V as oe,W as F,a as $,aD as re,ay as ne,aA as le,i as ce}from"./index-8HAJX3-Y.js";import{S as M}from"./switch-D_o-N1Sa.js";import{aw as B,a0 as R,e as de,n as D,W as ie,V as me,ax as xe}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 ue(){const{state:s}=Z(),t=ee(),[l,c]=h.useState(null),[u,g]=h.useState(null),[p,i]=h.useState(null),[f,y]=h.useState(null),[j,b]=h.useState(null),v=h.useCallback(async()=>{try{t.setProxyLoading(!0),t.setProxyError(null);const n=await L.cliproxyServer.get();t.setProxyConfig(n)}catch(n){t.setProxyError(n.message)}finally{t.setProxyLoading(!1)}},[t]),N=h.useCallback(async n=>{const d=s.proxyConfig;if(!d)return;const m={remote:{...d.remote,...n.remote},fallback:{...d.fallback,...n.fallback},local:{...d.local,...n.local}};t.setProxyConfig(m),t.setProxyTestResult(null);try{t.setProxySaving(!0),t.setProxyError(null);const a=await L.cliproxyServer.update(n);t.setProxyConfig(a),t.setProxySuccess(!0),setTimeout(()=>t.setProxySuccess(!1),1500)}catch(a){t.setProxyConfig(d),t.setProxyError(a.message)}finally{t.setProxySaving(!1)}},[s.proxyConfig,t]),C=h.useCallback(async n=>{const{host:d,port:m,protocol:a,authToken:P}=n;if(!d){t.setProxyError("Host is required");return}try{t.setProxyTesting(!0),t.setProxyError(null),t.setProxyTestResult(null);const o=m?parseInt(m,10):void 0,x=await L.cliproxyServer.test({host:d,port:o||void 0,protocol:a,authToken:P||void 0});t.setProxyTestResult(x)}catch(o){t.setProxyError(o.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:l,setEditedHost:c,editedPort:u,setEditedPort:g,editedAuthToken:p,setEditedAuthToken:i,editedManagementKey:f,setEditedManagementKey:y,editedLocalPort:j,setEditedLocalPort:b,fetchConfig:v,saveConfig:N,testConnection:C}}function he({config:s,saving:t,displayLocalPort:l,setEditedLocalPort:c,onSaveLocalPort:u,onSaveConfig:g}){const p=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(w,{type:"number",value:l,onChange:i=>c(i.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(M,{checked:p.auto_start??!0,onCheckedChange:i=>g({local:{...p,auto_start:i}}),disabled:t})]})]})]})}function pe({config:s,saving:t,testing:l,testResult:c,displayHost:u,displayPort:g,displayAuthToken:p,displayManagementKey:i,setEditedHost:f,setEditedPort:y,setEditedAuthToken:j,setEditedManagementKey:b,onSaveHost:v,onSavePort:N,onSaveAuthToken:C,onSaveManagementKey:n,onSaveConfig:d,onTestConnection:m}){const a=s.remote,P=o=>o==="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(B,{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(w,{value:u,onChange:o=>f(o.target.value),onBlur:v,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: ",P(s.remote.protocol||"http"),")"]})]}),e.jsx(w,{type:"text",inputMode:"numeric",value:g,onChange:o=>y(o.target.value.replace(/\D/g,"")),onBlur:N,placeholder:`Leave empty for ${P(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(te,{value:s.remote.protocol||"http",onValueChange:o=>d({remote:{...a,protocol:o}}),disabled:t,children:[e.jsx(se,{children:e.jsx(ae,{})}),e.jsxs(oe,{children:[e.jsx(F,{value:"http",children:"HTTP"}),e.jsx(F,{value:"https",children:"HTTPS"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"API Key (optional)"}),e.jsx(w,{type:"password",value:p,onChange:o=>j(o.target.value),onBlur:C,placeholder:"For /v1/* API endpoints",className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used for API requests to /v1/chat/completions"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Management Key (optional)"}),e.jsx(w,{type:"password",value:i,onChange:o=>b(o.target.value),onBlur:n,placeholder:"For /v0/management/* endpoints",className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used for dashboard management APIs. Falls back to API Key if not set."})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx($,{onClick:m,disabled:l||!u,variant:"outline",className:"w-full",children:l?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"w-4 h-4 mr-2 animate-spin"}),"Testing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"w-4 h-4 mr-2"}),"Test Connection"]})}),c&&e.jsx("div",{className:`p-3 rounded-md ${c.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:c.reachable?e.jsxs(e.Fragment,{children:[e.jsx(D,{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 (",c.latencyMs,"ms)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ie,{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:c.error||"Connection failed"})]})})})]})]})}function Se(){const{config:s,loading:t,saving:l,error:c,success:u,testResult:g,testing:p,editedHost:i,setEditedHost:f,editedPort:y,setEditedPort:j,editedAuthToken:b,setEditedAuthToken:v,editedManagementKey:N,setEditedManagementKey:C,editedLocalPort:n,setEditedLocalPort:d,fetchConfig:m,saveConfig:a,testConnection:P}=ue(),{fetchRawConfig:o}=re();if(h.useEffect(()=>{m(),o()},[m,o]),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(R,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const x=s.remote.enabled??!1,k=s.remote,S=s.fallback,U=s.remote.host??"",V=s.remote.port!==void 0?s.remote.port.toString():"",W=s.remote.auth_token??"",q=s.remote.management_key??"",z=(s.local.port??8317).toString(),E=i??U,A=y??V,I=b??W,K=N??q,H=n??z,O=()=>{const r=i??E;r!==s.remote.host&&a({remote:{...k,host:r}}),f(null)},Q=()=>{const r=y??A,T=r===""?void 0:parseInt(r,10),_=T&&!isNaN(T)&&T>0?T:void 0;_!==s.remote.port&&a({remote:{...k,port:_}}),j(null)},G=()=>{const r=b??I;r!==s.remote.auth_token&&a({remote:{...k,auth_token:r}}),v(null)},J=()=>{const r=N??K;r!==s.remote.management_key&&a({remote:{...k,management_key:r||void 0}}),C(null)},X=()=>{const r=parseInt(n??H,10);!isNaN(r)&&r!==s.local.port&&a({local:{...s.local,port:r}}),d(null)},Y=()=>{P({host:E,port:A,protocol:s.remote.protocol||"http",authToken:I})};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 ${c||u?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[c&&e.jsxs(ne,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(me,{className:"h-4 w-4"}),e.jsx(le,{children:c})]}),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(D,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(ce,{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:()=>a({remote:{...k,enabled:!1}}),disabled:l,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(xe,{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:()=>a({remote:{...k,enabled:!0}}),disabled:l,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(B,{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(pe,{config:s,saving:l,testing:p,testResult:g,displayHost:E,displayPort:A,displayAuthToken:I,displayManagementKey:K,setEditedHost:f,setEditedPort:j,setEditedAuthToken:v,setEditedManagementKey:C,onSaveHost:O,onSavePort:Q,onSaveAuthToken:G,onSaveManagementKey:J,onSaveConfig:a,onTestConnection:Y}),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(M,{checked:S.enabled??!0,onCheckedChange:r=>a({fallback:{...S,enabled:r}}),disabled:l||!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(M,{checked:S.auto_start??!1,onCheckedChange:r=>a({fallback:{...S,auto_start:r}}),disabled:l||!x||!S.enabled})]})]})]}),!x&&e.jsx(he,{config:s,saving:l,displayLocalPort:H,setEditedLocalPort:d,onSaveLocalPort:X,onSaveConfig:a})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs($,{variant:"outline",size:"sm",onClick:()=>{m(),o()},disabled:t||l,className:"w-full",children:[e.jsx(R,{className:`w-4 h-4 mr-2 ${t?"animate-spin":""}`}),"Refresh"]})})]})}export{Se as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s}from"./radix-ui-uXQB-q0u.js";import{r as d}from"./react-vendor-B_CU-WTZ.js";import{C as l,a as m}from"./card-
|
|
1
|
+
import{j as s}from"./radix-ui-uXQB-q0u.js";import{r as d}from"./react-vendor-B_CU-WTZ.js";import{C as l,a as m}from"./card-D6fGkasO.js";import{aw as c,ax as x,ay as u,az as h,aA as p,a as g}from"./index-8HAJX3-Y.js";import{x as j,Q as f,av as N,T 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 B(){const[t,r]=d.useState("commands"),{data:e}=c(),{data:n,isLoading:i}=x(t),o=[{id:"commands",label:"Commands",icon:j,count:e?.commands??0},{id:"skills",label:"Skills",icon:f,count:e?.skills??0},{id:"agents",label:"Agents",icon:N,count:e?.agents??0}];return s.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-8",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold",children:"Shared Data"}),s.jsx("p",{className:"text-muted-foreground",children:"Commands, skills, and agents shared across Claude instances"})]}),e&&!e.symlinkStatus.valid&&s.jsxs(u,{variant:"warning",children:[s.jsx(v,{className:"h-4 w-4"}),s.jsx(h,{children:"Configuration Required"}),s.jsxs(p,{children:[e.symlinkStatus.message,". Run `ccs sync` to configure."]})]}),s.jsx("div",{className:"flex gap-2 border-b pb-2",children:o.map(a=>s.jsxs(g,{variant:t===a.id?"default":"ghost",size:"sm",onClick:()=>r(a.id),className:"flex items-center gap-2",children:[s.jsx(a.icon,{className:"w-4 h-4"}),a.label," (",a.count,")"]},a.id))}),s.jsx("div",{className:"mt-4",children:i?s.jsx("div",{className:"text-muted-foreground",children:"Loading..."}):n?.items.length===0?s.jsxs("div",{className:"text-muted-foreground",children:["No ",t," found"]}):s.jsx("div",{className:"grid gap-3",children:n?.items.map(a=>s.jsx(l,{children:s.jsxs(m,{children:[s.jsx("div",{className:"font-medium",children:a.name}),s.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:a.description}),s.jsx("p",{className:"text-xs text-muted-foreground mt-2 font-mono truncate",children:a.path})]})},a.name))})})]})}export{B as SharedPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as a,a8 as s,a9 as n}from"./radix-ui-uXQB-q0u.js";import"./react-vendor-B_CU-WTZ.js";import{c as e}from"./index-
|
|
1
|
+
import{j as a,a8 as s,a9 as n}from"./radix-ui-uXQB-q0u.js";import"./react-vendor-B_CU-WTZ.js";import{c as e}from"./index-8HAJX3-Y.js";function c({className:t,...r}){return a.jsx(s,{"data-slot":"switch",className:e("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",t),...r,children:a.jsx(n,{"data-slot":"switch-thumb",className:e("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}export{c as S};
|
package/dist/ui/index.html
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap"
|
|
25
25
|
rel="stylesheet"
|
|
26
26
|
/>
|
|
27
|
-
<script type="module" crossorigin src="/assets/index-
|
|
27
|
+
<script type="module" crossorigin src="/assets/index-8HAJX3-Y.js"></script>
|
|
28
28
|
<link rel="modulepreload" crossorigin href="/assets/react-vendor-B_CU-WTZ.js">
|
|
29
29
|
<link rel="modulepreload" crossorigin href="/assets/radix-ui-uXQB-q0u.js">
|
|
30
30
|
<link rel="modulepreload" crossorigin href="/assets/tanstack-Coed0rqz.js">
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{j as e,W as is,X as rs,Y as os,Z as ls,_ as cs}from"./radix-ui-uXQB-q0u.js";import{r as h}from"./react-vendor-B_CU-WTZ.js";import{u as _e,a as Ee,b as ds}from"./tanstack-Coed0rqz.js";import{a as j,c as A,P as re,L as ee,I as oe,O as Le,Q as Re,U as Ie,V as Fe,W as ae,X as Ue,Y as ms,Z as He,_ as Ge,u as $e,$ as le,a0 as ce,a1 as de,a2 as me,a3 as Ke,a4 as us,a5 as be,a6 as ye,B as _,a7 as xs,m as Ve,i as ue,h as ps,a8 as hs,a9 as gs,aa as fs,ab as js,T as vs,k as Ns,ac as ws,l as bs,ad as ys,ae as Cs,af as X,ag as ks,ah as As,ai as Ss,aj as Ps,D as Ms,E as Os,F as Ce,G as ke,ak as Ts,al as Ds,am as _s,an as Es,ao as Ls,ap as Rs,aq as Is,ar as Fs,as as Us,S as Hs}from"./index-DXF1Z58h.js";import{t as E}from"./notifications-dJQY2-U6.js";import{b as qe,L as $,m as xe,t as Gs,j as K,l as $s,ag as pe,a0 as G,ah as q,Q as B,ai as Ks,aj as se,Z as te,I as Vs,f as qs,Y as he,ak as zs,aa as Qs,X as ge,O as ze,q as Z,al as Bs,a9 as Qe,n as Js,am as Ws,ad as Ys,A as Ae,an as Se,ao as Pe,U as Xs,ap as Zs,aq as et,ar as Be}from"./icons-CwFZAiDB.js";import{C as Je,a as We}from"./card-ClMztcJ3.js";import{S as fe,C as st}from"./confirm-dialog-ByvRv_aE.js";import{S as tt}from"./switch-Big41pQ7.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";import"./alert-dialog-BrIFqgMZ.js";const Q={agy:{provider:"agy",displayName:"Antigravity",defaultModel:"gemini-claude-opus-4-5-thinking",models:[{id:"gemini-claude-opus-4-5-thinking",name:"Claude Opus 4.5 Thinking",description:"Most capable, extended thinking",presetMapping:{default:"gemini-claude-opus-4-5-thinking",opus:"gemini-claude-opus-4-5-thinking",sonnet:"gemini-claude-sonnet-4-5-thinking",haiku:"gemini-claude-sonnet-4-5"}},{id:"gemini-claude-sonnet-4-5-thinking",name:"Claude Sonnet 4.5 Thinking",description:"Balanced with extended thinking",presetMapping:{default:"gemini-claude-sonnet-4-5-thinking",opus:"gemini-claude-opus-4-5-thinking",sonnet:"gemini-claude-sonnet-4-5-thinking",haiku:"gemini-claude-sonnet-4-5"}},{id:"gemini-claude-sonnet-4-5",name:"Claude Sonnet 4.5",description:"Fast and capable",presetMapping:{default:"gemini-claude-sonnet-4-5",opus:"gemini-claude-opus-4-5-thinking",sonnet:"gemini-claude-sonnet-4-5",haiku:"gemini-claude-sonnet-4-5"}},{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",description:"Google latest model via Antigravity",presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",description:"Fast Gemini model via Antigravity",presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}}]},gemini:{provider:"gemini",displayName:"Gemini",defaultModel:"gemini-2.5-pro",models:[{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",tier:"paid",description:"Latest model, requires paid Google account",presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",tier:"paid",description:"Fast Gemini 3 model, requires paid Google account",presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro",description:"Stable, works with free Google account",presetMapping:{default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-2.5-flash"}}]},codex:{provider:"codex",displayName:"Codex",defaultModel:"gpt-5.1-codex-max",models:[{id:"gpt-5.1-codex-max",name:"Codex Max (5.1)",description:"Most capable Codex model",presetMapping:{default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max-high",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini-high"}},{id:"gpt-5.2",name:"GPT 5.2",description:"Latest GPT model",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.2",haiku:"gpt-5.2"}},{id:"gpt-5.1-codex-mini",name:"Codex Mini",description:"Fast and efficient Codex model"}]},qwen:{provider:"qwen",displayName:"Qwen",defaultModel:"qwen-coder-plus",models:[{id:"qwen-coder-plus",name:"Qwen Coder Plus",description:"Alibaba code-focused model"},{id:"qwen-max",name:"Qwen Max",description:"Most capable Qwen model"}]},iflow:{provider:"iflow",displayName:"iFlow",defaultModel:"iflow-default",models:[{id:"iflow-default",name:"iFlow Default",description:"Default iFlow model"}]},kiro:{provider:"kiro",displayName:"Kiro (AWS)",defaultModel:"kiro-claude-sonnet-4-5",models:[{id:"kiro-claude-opus-4-5",name:"Kiro Claude Opus 4.5",description:"Claude Opus 4.5 via Kiro (2.2x credit)",presetMapping:{default:"kiro-claude-opus-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4-5",name:"Kiro Claude Sonnet 4.5",description:"Claude Sonnet 4.5 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4",name:"Kiro Claude Sonnet 4",description:"Claude Sonnet 4 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-haiku-4-5",name:"Kiro Claude Haiku 4.5",description:"Claude Haiku 4.5 via Kiro (0.4x credit)"}]},ghcp:{provider:"ghcp",displayName:"GitHub Copilot (OAuth)",defaultModel:"claude-sonnet-4.5",models:[{id:"claude-opus-4.5",name:"Claude Opus 4.5",description:"Anthropic Claude Opus 4.5 via GitHub Copilot",presetMapping:{default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4.5",name:"Claude Sonnet 4.5",description:"Anthropic Claude Sonnet 4.5 via GitHub Copilot",presetMapping:{default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4",name:"Claude Sonnet 4",description:"Anthropic Claude Sonnet 4 via GitHub Copilot"},{id:"claude-haiku-4.5",name:"Claude Haiku 4.5",description:"Anthropic Claude Haiku 4.5 via GitHub Copilot"},{id:"gpt-5.2",name:"GPT-5.2",description:"OpenAI GPT-5.2 via GitHub Copilot",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"}},{id:"gpt-5.1",name:"GPT-5.1",description:"OpenAI GPT-5.1 via GitHub Copilot"},{id:"gpt-5",name:"GPT-5",description:"OpenAI GPT-5 via GitHub Copilot"},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"OpenAI GPT-5 Mini via GitHub Copilot"},{id:"gemini-3-pro",name:"Gemini 3 Pro",description:"Google Gemini 3 Pro via GitHub Copilot"}]}},ne=8317;async function ie(s,a){const t=Q[s];if(!t)return{success:!1};const n=t.models[0],i=n?.presetMapping||{default:t.defaultModel,opus:t.defaultModel,sonnet:t.defaultModel,haiku:t.defaultModel},l={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${ne}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:"ccs-internal-managed",ANTHROPIC_MODEL:i.default,ANTHROPIC_DEFAULT_OPUS_MODEL:i.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:i.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:i.haiku}};try{return{success:(await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:l})})).ok,presetName:n?.name||t.defaultModel}}catch{return{success:!1}}}const Me=[{id:"gemini",name:"Google Gemini",description:"Gemini Pro/Flash models"},{id:"codex",name:"OpenAI Codex",description:"GPT-4 and codex models"},{id:"agy",name:"Antigravity",description:"Antigravity AI models"},{id:"qwen",name:"Alibaba Qwen",description:"Qwen Code models"},{id:"iflow",name:"iFlow",description:"iFlow AI models"},{id:"kiro",name:"Kiro (AWS)",description:"AWS CodeWhisperer models"},{id:"ghcp",name:"GitHub Copilot (OAuth)",description:"GitHub Copilot via OAuth"}],Ye=["provider","auth","variant","success"];function at(s){return s==="account"?1:Ye.indexOf(s)}function nt({currentProgress:s,allSteps:a}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:a.map((t,n)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${s>=n?"bg-primary":"bg-muted"}`},t))})}function it({providers:s,onSelect:a}){return e.jsx("div",{className:"grid gap-2",children:s.map(t=>e.jsxs("button",{onClick:()=>a(t.id),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t.description})]}),e.jsx(qe,{className:"w-4 h-4 text-muted-foreground"})]},t.id))})}function rt({selectedProvider:s,providers:a,authCommand:t,isRefreshing:n,isPending:i,onBack:c,onStartAuth:l,onRefresh:d}){const[r,u]=h.useState(!1),p=async m=>{await navigator.clipboard.writeText(m),u(!0),setTimeout(()=>u(!1),2e3)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Authenticate with ",a.find(m=>m.id===s)?.name," to add an account"]}),e.jsx(j,{onClick:l,disabled:i,className:"w-full gap-2",size:"lg",children:i?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"w-4 h-4"}),"Authenticate in Browser"]})}),i&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Complete the OAuth flow in your browser..."})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or use terminal"})})]}),e.jsx(Je,{children:e.jsxs(We,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Gs,{className:"w-4 h-4"}),"Run this command in your terminal:"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-3 py-2 bg-muted rounded-md font-mono text-sm",children:t}),e.jsx(j,{variant:"outline",size:"icon",onClick:()=>p(t),children:r?e.jsx(K,{className:"w-4 h-4 text-green-500"}):e.jsx($s,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(j,{variant:"ghost",onClick:c,disabled:i,children:[e.jsx(pe,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(j,{variant:"outline",onClick:d,disabled:n||i,children:[e.jsx(G,{className:`w-4 h-4 mr-2 ${n?"animate-spin":""}`}),n?"Checking...":"Refresh Status"]})]})]})}function ot({accounts:s,privacyMode:a,onSelect:t,onAddNew:n,onBack:i}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Select an account (",s.length,")"]}),e.jsx("div",{className:"grid gap-2",children:s.map(c=>e.jsxs("button",{type:"button",onClick:()=>t(c),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(q,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:A("font-medium",a&&re),children:c.email||c.id}),c.isDefault&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Default account"})]})]}),e.jsx(qe,{className:"w-4 h-4 text-muted-foreground"})]},c.id))}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or"})})]}),e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 p-3 border-2 border-dashed border-primary/50 rounded-lg hover:border-primary hover:bg-primary/5 transition-colors text-left",onClick:n,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(xe,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary",children:"Add new account"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Authenticate with a different account"})]})]}),e.jsx("div",{className:"flex items-center justify-between pt-2",children:e.jsxs(j,{variant:"ghost",onClick:i,children:[e.jsx(pe,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}function lt({selectedProvider:s,selectedAccount:a,variantName:t,modelName:n,isPending:i,privacyMode:c,onVariantNameChange:l,onModelChange:d,onBack:r,onSkip:u,onCreate:p}){return e.jsxs("div",{className:"space-y-4",children:[a&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx(q,{className:"w-4 h-4"}),e.jsxs("span",{children:["Using:"," ",e.jsx("span",{className:A(c&&re),children:a.email||a.id})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"variant-name",children:"Variant Name *"}),e.jsx(oe,{id:"variant-name",value:t,onChange:m=>l(m.target.value),placeholder:"e.g., my-gemini, g3, flash"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Use this name to invoke: ccs ",t||"<name>",' "prompt"']})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{children:"Model"}),e.jsxs(Le,{value:n,onValueChange:d,children:[e.jsx(Re,{children:e.jsx(Ie,{placeholder:"Select a model"})}),e.jsx(Fe,{children:Q[s]?.models.map(m=>e.jsx(ae,{value:m.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:m.name}),m.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",m.description]})]})},m.id))})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Default: ",Q[s]?.defaultModel||"provider default"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(j,{variant:"ghost",onClick:r,children:[e.jsx(pe,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{variant:"ghost",onClick:u,children:"Skip"}),e.jsx(j,{onClick:p,disabled:!t||i,children:i?"Creating...":"Create Variant"})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:"Skip if you just wanted to add an account without creating a variant"})]})}function ct({variantName:s,onClose:a}){return e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center",children:e.jsx(K,{className:"w-8 h-8 text-green-600 dark:text-green-400"})})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-lg",children:"Variant Created!"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Your custom variant is ready to use"})]}),e.jsx(Je,{children:e.jsxs(We,{className:"p-4 space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Usage:"}),e.jsxs("code",{className:"block px-3 py-2 bg-muted rounded-md font-mono text-sm",children:["ccs ",s,' "your prompt here"']})]})}),e.jsx(j,{onClick:a,className:"w-full",children:"Done"})]})}function dt({open:s,onClose:a}){const[t,n]=h.useState("provider"),[i,c]=h.useState(""),[l,d]=h.useState(null),[r,u]=h.useState(""),[p,m]=h.useState(""),[g,o]=h.useState(!1),[v,k]=h.useState(!1),{data:f,refetch:T}=Ue(),M=ms(),P=He(),y=Ge(),{privacyMode:N}=$e(),C=f?.authStatus.find(b=>b.provider===i),O=h.useMemo(()=>C?.accounts||[],[C?.accounts]);h.useEffect(()=>{if(!s){const b=setTimeout(()=>{n("provider"),c(""),d(null),u(""),m(""),k(!1)},0);return()=>clearTimeout(b)}},[s]),h.useEffect(()=>{if(t==="auth"&&O.length>0&&!v){const b=setTimeout(()=>{n("account")},0);return()=>clearTimeout(b)}},[t,O,v]);const w=async()=>{o(!0),await T(),o(!1)},S=()=>{const b=(C?.accounts?.length||0)===0;P.mutate({provider:i},{onSuccess:async z=>{if(b){const H=await ie(i);H.success&&H.presetName?E.success(`Applied "${H.presetName}" preset`):H.success||E.warning("Account added, but failed to apply default preset")}z.account&&(d(z.account),n("variant")),T()}})},x=b=>{c(b),(f?.authStatus.find(W=>W.provider===b)?.accounts||[]).length===0?n("auth"):n("account")},L=b=>{d(b),n("variant")},I=async()=>{if(!(!r||!i))try{await M.mutateAsync({name:r,provider:i,model:p||void 0,account:l?.id}),n("success")}catch(b){console.error("Failed to create variant:",b)}},R=`ccs ${i} --auth --add`,V=at(t),J=b=>{if(!b&&(P.isPending&&i&&y.mutate(i),t==="success"||t==="provider")){a();return}};return e.jsx(le,{open:s,onOpenChange:J,children:e.jsxs(ce,{className:"sm:max-w-lg",onPointerDownOutside:b=>{t!=="success"&&t!=="provider"&&b.preventDefault()},onEscapeKeyDown:b=>{(P.isPending||M.isPending)&&b.preventDefault()},children:[e.jsxs(de,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(B,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs(Ke,{children:[t==="provider"&&"Select a provider to get started",t==="auth"&&"Authenticate with your provider",t==="account"&&"Select which account to use",t==="variant"&&"Create your custom variant",t==="success"&&"Setup complete!"]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[t==="provider"&&e.jsx(it,{providers:Me,onSelect:x}),t==="auth"&&e.jsx(rt,{selectedProvider:i,providers:Me,authCommand:R,isRefreshing:g,isPending:P.isPending,onBack:()=>n("provider"),onStartAuth:S,onRefresh:w}),t==="account"&&e.jsx(ot,{accounts:O,privacyMode:N,onSelect:L,onAddNew:()=>{k(!0),n("auth")},onBack:()=>n("provider")}),t==="variant"&&e.jsx(lt,{selectedProvider:i,selectedAccount:l,variantName:r,modelName:p,isPending:M.isPending,privacyMode:N,onVariantNameChange:u,onModelChange:m,onBack:()=>O.length>0?n("account"):n("provider"),onSkip:a,onCreate:I}),t==="success"&&e.jsx(ct,{variantName:r,onClose:a})]}),e.jsx(nt,{currentProgress:V,allSteps:Ye})]})})}function mt({open:s,onClose:a,provider:t,displayName:n,isFirstAccount:i=!1}){const[c,l]=h.useState(""),d=He(),r=us(),u=Ge(),p=t==="kiro",m=d.isPending||r.isPending,g=()=>{m&&u.mutate(t),l(""),a()},o=()=>{d.mutate({provider:t,nickname:c.trim()||void 0},{onSuccess:async()=>{const f=await ie(t);f.success&&f.presetName?i&&E.success(`Applied "${f.presetName}" preset`):f.success||E.warning("Account added, but failed to apply default preset. You may need to configure settings manually."),l(""),a()}})},v=()=>{r.mutate(void 0,{onSuccess:async()=>{const f=await ie("kiro");f.success&&f.presetName&&i&&E.success(`Applied "${f.presetName}" preset`),l(""),a()}})},k=f=>{f||g()};return e.jsx(le,{open:s,onOpenChange:k,children:e.jsxs(ce,{className:"sm:max-w-md",children:[e.jsxs(de,{children:[e.jsxs(me,{children:["Add ",n," Account"]}),e.jsx(Ke,{children:p?"Authenticate via browser or import an existing token from Kiro IDE.":"Click the button below to authenticate a new account. A browser window will open for OAuth."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"nickname",children:"Nickname (optional)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(oe,{id:"nickname",value:c,onChange:f=>l(f.target.value),placeholder:"e.g., work, personal",disabled:m,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"A friendly name to identify this account. Auto-generated from email if left empty."})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(j,{variant:"ghost",onClick:g,children:"Cancel"}),p&&e.jsx(j,{variant:"outline",onClick:v,disabled:m,children:r.isPending?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"w-4 h-4 mr-2 animate-spin"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ks,{className:"w-4 h-4 mr-2"}),"Import from IDE"]})}),e.jsx(j,{onClick:o,disabled:m,children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"w-4 h-4 mr-2 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"w-4 h-4 mr-2"}),"Authenticate"]})})]}),d.isPending&&e.jsx("p",{className:"text-sm text-center text-muted-foreground",children:"Complete the OAuth flow in your browser..."}),r.isPending&&e.jsx("p",{className:"text-sm text-center text-muted-foreground",children:"Importing token from Kiro IDE..."})]})]})})}const ut=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function xt(s){const a=s?.env||{};return ut.filter(t=>!a[t]?.trim())}function pt(s){const[a,t]=h.useState(null),[n,i]=h.useState(!1),c=_e(),{data:l,isLoading:d,refetch:r}=Ee({queryKey:["settings",s],queryFn:async()=>{const w=await fetch(`/api/settings/${s}/raw`);return w.ok?w.json():{profile:s,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${s}/settings.json`}}}),u=l?.settings,p=h.useMemo(()=>a!==null?a:u?JSON.stringify(u,null,2):`{
|
|
2
|
-
"env": {}
|
|
3
|
-
}`,[a,u]),m=h.useCallback(w=>{t(w)},[]),g=h.useMemo(()=>{try{return JSON.parse(p)}catch{return u||{env:{}}}},[p,u]),o=g?.env?.ANTHROPIC_MODEL,v=g?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,k=g?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,f=g?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,T=h.useCallback((w,S)=>{const x={...g?.env||{},[w]:S},L={...g,env:x};t(JSON.stringify(L,null,2))},[g]),M=h.useCallback(w=>{const S={...g?.env||{},...w},x={...g,env:S};t(JSON.stringify(x,null,2))},[g]),P=h.useMemo(()=>{try{return JSON.parse(p),!0}catch{return!1}},[p]),y=h.useMemo(()=>a===null?!1:a!==JSON.stringify(u,null,2),[a,u]),N=h.useMemo(()=>xt(g),[g]),C=ds({mutationFn:async()=>{const w=JSON.parse(p),S=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:w,expectedMtime:l?.mtime})});if(S.status===409)throw new Error("CONFLICT");if(!S.ok)throw new Error("Failed to save");return S.json()},onSuccess:w=>{c.invalidateQueries({queryKey:["settings",s]}),t(null),w?.warning?E.success("Settings saved",{description:w.warning}):E.success("Settings saved")},onError:w=>{w.message==="CONFLICT"?i(!0):E.error(w.message)}}),O=async w=>{i(!1),w?(await r(),C.mutate()):t(null)};return{data:l,isLoading:d,refetch:r,rawJsonContent:p,rawJsonEdits:a,isRawJsonValid:P,hasChanges:y,currentSettings:g,currentModel:o,opusModel:v,sonnetModel:k,haikuModel:f,handleRawJsonChange:m,updateEnvValue:T,updateEnvValues:M,saveMutation:{mutate:()=>C.mutate(),isPending:C.isPending},conflictDialog:n,setConflictDialog:i,handleConflictResolve:O,missingRequiredFields:N}}function U({label:s,description:a,value:t,onChange:n,catalog:i,allModels:c,disabled:l}){const d=new Set(i?.models.map(r=>r.id)||[]);return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:s}),a&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:a})]}),e.jsxs(Le,{value:t||"",onValueChange:n,disabled:l,children:[e.jsx(Re,{className:"h-9",children:e.jsx(Ie,{placeholder:"Select model",children:t&&e.jsx("span",{className:"truncate font-mono text-xs",children:t})})}),e.jsxs(Fe,{className:"max-h-[300px]",children:[i&&i.models.length>0&&e.jsxs(be,{children:[e.jsx(ye,{className:"text-xs text-primary",children:"Recommended"}),i.models.map(r=>e.jsx(ae,{value:r.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.id}),r.tier==="paid"&&e.jsx(_,{variant:"outline",className:"text-[9px] h-4 px-1",children:"PAID"}),t===r.id&&e.jsx(K,{className:"w-3 h-3 text-primary ml-auto"})]})},r.id))]}),c.length>0&&e.jsxs(be,{children:[e.jsxs(ye,{className:"text-xs text-muted-foreground",children:["All Models (",c.length,")"]}),c.filter(r=>!d.has(r.id)).map(r=>e.jsx(ae,{value:r.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.id}),t===r.id&&e.jsx(K,{className:"w-3 h-3 text-primary ml-auto"})]})},r.id))]}),(!i||i.models.length===0)&&c.length===0&&e.jsx("div",{className:"py-2 px-3 text-xs text-muted-foreground",children:"No models available"})]})]})]})}function ht({open:s,onClose:a,currentValues:t,onApply:n,onSave:i,isSaving:c,catalog:l,allModels:d}){const[r,u]=h.useState(t),[p,m]=h.useState(""),g=o=>{o?(u(t),m("")):a()};return e.jsx(le,{open:s,onOpenChange:g,children:e.jsxs(ce,{className:"sm:max-w-md",children:[e.jsx(de,{children:e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(B,{className:"w-4 h-4"}),"Custom Preset"]})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"preset-name",children:"Preset Name (optional)"}),e.jsx(oe,{id:"preset-name",value:p,onChange:o=>m(o.target.value),placeholder:"e.g., My Custom Config",className:"text-sm"})]}),e.jsx(fe,{}),e.jsx(U,{label:"Default Model",description:"Used when no specific tier is requested",value:r.default,onChange:o=>u({...r,default:o}),catalog:l,allModels:d}),e.jsx(U,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:r.opus,onChange:o=>u({...r,opus:o}),catalog:l,allModels:d}),e.jsx(U,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:r.sonnet,onChange:o=>u({...r,sonnet:o}),catalog:l,allModels:d}),e.jsx(U,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:r.haiku,onChange:o=>u({...r,haiku:o}),catalog:l,allModels:d})]}),e.jsxs(xs,{className:"gap-2 sm:gap-0",children:[e.jsx(j,{variant:"outline",onClick:a,children:"Cancel"}),i&&e.jsxs(j,{variant:"secondary",onClick:()=>i(r,p||void 0),disabled:c||!p.trim(),children:[c?e.jsx($,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(se,{className:"w-4 h-4 mr-1"}),"Save Preset"]}),e.jsxs(j,{onClick:()=>n(r,p||void 0),children:[e.jsx(te,{className:"w-4 h-4 mr-1"}),"Apply Preset"]})]})]})})}function Y({label:s,command:a}){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:a}),e.jsx(Ve,{value:a,size:"icon",className:"h-6 w-6"})]})]})}function gt({provider:s,displayName:a,data:t,authStatus:n}){return e.jsx(ue,{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(Vs,{className:"w-4 h-4"}),"Provider Information"]}),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:a})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:t.path}),e.jsx(Ve,{value:t.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Last Modified"}),e.jsx("span",{className:"text-xs",children:new Date(t.mtime).toLocaleString()})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Status"}),n.authenticated?e.jsxs(_,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(qs,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(_,{variant:"outline",className:"w-fit text-muted-foreground",children:"Not connected"})]})]})]}),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(Y,{label:"Run with prompt",command:`ccs ${s} "your prompt"`}),e.jsx(Y,{label:"Change model",command:`ccs ${s} --config`}),e.jsx(Y,{label:"Add account",command:`ccs ${s} --add`}),e.jsx(Y,{label:"List accounts",command:`ccs ${s} --accounts`})]})]})]})})}const ft={gemini:"/assets/providers/gemini-color.svg",codex:"/assets/providers/openai.svg",agy:"/assets/providers/agy.png",qwen:"/assets/providers/qwen-color.svg",iflow:"/assets/providers/iflow.png",kiro:"/assets/providers/kiro.png",ghcp:"/assets/providers/copilot.svg"},jt={gemini:{text:"text-blue-600",letter:"G"},claude:{text:"text-orange-600",letter:"C"},codex:{text:"text-emerald-600",letter:"X"},agy:{text:"text-violet-600",letter:"A"},qwen:{text:"text-cyan-600",letter:"Q"},iflow:{text:"text-indigo-600",letter:"i"},kiro:{text:"text-teal-600",letter:"K"},ghcp:{text:"text-green-600",letter:"C"}},vt={sm:{container:"w-6 h-6",icon:"w-4 h-4",text:"text-xs"},md:{container:"w-8 h-8",icon:"w-5 h-5",text:"text-sm"},lg:{container:"w-12 h-12",icon:"w-8 h-8",text:"text-lg"}};function je({provider:s,className:a,size:t="md"}){const n=s.toLowerCase(),i=jt[n]||{text:"text-gray-600",letter:s[0]?.toUpperCase()||"?"},c=vt[t],l=ft[n];return e.jsx("div",{className:A("flex items-center justify-center rounded-md",l&&"bg-white p-1",c.container,a),children:l?e.jsx("img",{src:l,alt:`${s} logo`,className:A(c.icon,"object-contain")}):e.jsx("span",{className:A("font-semibold",i.text,c.text),children:i.letter})})}function Nt({displayName:s,logoProvider:a,provider:t,data:n,isLoading:i,hasChanges:c,isRawJsonValid:l,isSaving:d,isRemoteMode:r,port:u,onRefetch:p,onSave:m}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(je,{provider:a||t,size:"lg"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),r&&e.jsxs(_,{variant:"secondary",className:"text-xs gap-1 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:[e.jsx(he,{className:"w-3 h-3"}),"Remote"]}),u&&e.jsxs(_,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(zs,{className:"w-3 h-3"}),":",u]}),!r&&n?.path&&e.jsx(_,{variant:"outline",className:"text-xs",children:n.path.replace(/^.*[\\/]/,"")})]}),r?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):n&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(n.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{variant:"ghost",size:"sm",onClick:p,disabled:i,children:e.jsx(G,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsx(j,{size:"sm",onClick:m,disabled:d||!c||!l,children:d?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Qs,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function wt({catalog:s,savedPresets:a,currentModel:t,opusModel:n,sonnetModel:i,haikuModel:c,providerModels:l,onApplyPreset:d,onUpdateEnvValue:r,onOpenCustomPreset:u,onDeletePreset:p,isDeletePending:m}){const g=s&&s.models.length>0||a.length>0;return e.jsxs(e.Fragment,{children:[g&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(B,{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:"flex flex-wrap gap-2",children:[s?.models.slice(0,4).map(o=>e.jsxs(j,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>{const v=o.presetMapping||{default:o.id,opus:o.id,sonnet:o.id,haiku:o.id};d({ANTHROPIC_MODEL:v.default,ANTHROPIC_DEFAULT_OPUS_MODEL:v.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:v.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:v.haiku})},children:[e.jsx(te,{className:"w-3 h-3"}),o.name]},o.id)),a.map(o=>e.jsxs("div",{className:"group relative",children:[e.jsxs(j,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{d({ANTHROPIC_MODEL:o.default,ANTHROPIC_DEFAULT_OPUS_MODEL:o.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:o.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:o.haiku})},children:[e.jsx(se,{className:"w-3 h-3 fill-current"}),o.name]}),e.jsx(j,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:v=>{v.stopPropagation(),p(o.name)},disabled:m,children:e.jsx(ge,{className:"w-3 h-3"})})]},o.name)),e.jsxs(j,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1 border-primary/50 text-primary hover:bg-primary/10 hover:border-primary",onClick:u,children:[e.jsx(ze,{className:"w-3 h-3"}),"Custom"]})]})]}),e.jsx(fe,{}),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(U,{label:"Default Model",description:"Used when no specific tier is requested",value:t,onChange:o=>r("ANTHROPIC_MODEL",o),catalog:s,allModels:l}),e.jsx(U,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:n,onChange:o=>r("ANTHROPIC_DEFAULT_OPUS_MODEL",o),catalog:s,allModels:l}),e.jsx(U,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:i,onChange:o=>r("ANTHROPIC_DEFAULT_SONNET_MODEL",o),catalog:s,allModels:l}),e.jsx(U,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:c,onChange:o=>r("ANTHROPIC_DEFAULT_HAIKU_MODEL",o),catalog:s,allModels:l})]})]})]})}function bt({...s}){return e.jsx(is,{"data-slot":"dropdown-menu",...s})}function yt({...s}){return e.jsx(rs,{"data-slot":"dropdown-menu-trigger",...s})}function Ct({className:s,sideOffset:a=4,...t}){return e.jsx(os,{children:e.jsx(ls,{"data-slot":"dropdown-menu-content",sideOffset:a,className:A("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md bg-white dark:bg-zinc-950",s),...t})})}function Oe({className:s,inset:a,variant:t="default",...n}){return e.jsx(cs,{"data-slot":"dropdown-menu-item","data-inset":a,"data-variant":t,className:A("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground focus:[&_svg:not([class*='text-'])]:text-current relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",s),...n})}function kt(s){return s<=20?"bg-destructive":s<=50?"bg-yellow-500":"bg-green-500"}function Te(s){if(!s)return"";try{const a=new Date(s),n=new Date().getTime()-a.getTime();if(n<0)return"just now";const i=Math.floor(n/(1e3*60)),c=Math.floor(n/(1e3*60*60)),l=Math.floor(n/(1e3*60*60*24));return l>0?`${l}d ago`:c>0?`${c}h ago`:i>0?`${i}m ago`:"just now"}catch{return""}}function At(s){if(!s)return!1;try{const a=new Date(s);return new Date().getTime()-a.getTime()<3600*1e3}catch{return!1}}function St({account:s,onSetDefault:a,onRemove:t,isRemoving:n,privacyMode:i,showQuota:c}){const{data:l}=ps(c&&s.provider==="agy"),{data:d,isLoading:r}=hs(s.provider,s.id,c&&s.provider==="agy"),u=l?.accountStats?.[s.email||s.id]?.lastUsedAt,p=At(u),m=d?.success?gs(d.models):null,g=d?.success&&d.models.length>0?fs(d.models):null;return e.jsxs("div",{className:A("flex flex-col gap-2 p-3 rounded-lg border transition-colors",s.isDefault?"border-primary/30 bg-primary/5":"border-border hover:bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:A("flex items-center justify-center w-8 h-8 rounded-full",s.isDefault?"bg-primary/10":"bg-muted"),children:e.jsx(q,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:A("font-medium text-sm",i&&re),children:s.email||s.id}),s.isDefault&&e.jsxs(_,{variant:"secondary",className:"text-[10px] h-4 px-1.5 gap-0.5",children:[e.jsx(se,{className:"w-2.5 h-2.5 fill-current"}),"Default"]})]}),s.lastUsedAt&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mt-0.5",children:[e.jsx(Z,{className:"w-3 h-3"}),"Last used: ",new Date(s.lastUsedAt).toLocaleDateString()]})]})]}),e.jsxs(bt,{children:[e.jsx(yt,{asChild:!0,children:e.jsx(j,{variant:"ghost",size:"icon",className:"h-7 w-7",children:e.jsx(Bs,{className:"w-4 h-4"})})}),e.jsxs(Ct,{align:"end",children:[!s.isDefault&&e.jsxs(Oe,{onClick:a,children:[e.jsx(se,{className:"w-4 h-4 mr-2"}),"Set as default"]}),e.jsxs(Oe,{className:"text-destructive focus:text-destructive",onClick:t,disabled:n,children:[e.jsx(Qe,{className:"w-4 h-4 mr-2"}),n?"Removing...":"Remove account"]})]})]})]}),c&&s.provider==="agy"&&e.jsx("div",{className:"pl-11",children:r?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx($,{className:"w-3 h-3 animate-spin"}),e.jsx("span",{children:"Loading quota..."})]}):m!==null?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:p?e.jsxs(e.Fragment,{children:[e.jsx(Js,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["Active · ",Te(u)]})]}):u?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-muted-foreground",children:["Last used ",Te(u)]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ws,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not used yet"})]})}),e.jsx(js,{children:e.jsxs(vs,{children:[e.jsx(Ns,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ws,{value:m,className:"h-2 flex-1",indicatorClassName:kt(m)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[m,"%"]})]})}),e.jsx(bs,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium",children:"Model Quotas:"}),ys(d?.models||[]).map(o=>e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{className:"truncate",children:o.displayName||o.name}),e.jsxs("span",{className:"font-mono",children:[o.percentage,"%"]})]},o.name)),g&&e.jsxs("div",{className:"flex items-center gap-1.5 mt-2 pt-2 border-t border-border/50",children:[e.jsx(Z,{className:"w-3 h-3 text-blue-400"}),e.jsxs("span",{className:"text-blue-400 font-medium",children:["Resets ",Cs(g)]})]})]})})]})})]}):d?.error?e.jsx("div",{className:"text-xs text-muted-foreground",children:d.error}):null})]})}function Pt({accounts:s,onAddAccount:a,onSetDefault:t,onRemoveAccount:n,isRemovingAccount:i,privacyMode:c,showQuota:l,isKiro:d,kiroNoIncognito:r,onKiroNoIncognitoChange:u,kiroSettingsLoading:p}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(q,{className:"w-4 h-4"}),"Accounts",s.length>0&&e.jsx(_,{variant:"secondary",className:"text-xs",children:s.length})]}),e.jsxs(j,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:a,children:[e.jsx(ze,{className:"w-3 h-3"}),"Add"]})]}),s.length>0?e.jsx("div",{className:"space-y-2",children:s.map(m=>e.jsx(St,{account:m,onSetDefault:()=>t(m.id),onRemove:()=>n(m.id),isRemoving:i,privacyMode:c,showQuota:l},m.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(q,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No accounts connected"}),e.jsx("p",{className:"text-xs opacity-70",children:"Add an account to get started"})]}),d&&u&&e.jsx("div",{className:"mt-3 pt-3 border-t border-dashed",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(he,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Use incognito"})]}),e.jsx(tt,{checked:!r,onCheckedChange:m=>u(!m),disabled:p,className:"scale-90"})]})})]})}function Mt({provider:s,catalog:a,savedPresets:t,currentModel:n,opusModel:i,sonnetModel:c,haikuModel:l,providerModels:d,onApplyPreset:r,onUpdateEnvValue:u,onOpenCustomPreset:p,onDeletePreset:m,isDeletePending:g,accounts:o,onAddAccount:v,onSetDefault:k,onRemoveAccount:f,isRemovingAccount:T,privacyMode:M}){const P=s==="kiro",[y,N]=h.useState(!0),[C,O]=h.useState(!0),[w,S]=h.useState(!1),x=h.useCallback(async()=>{if(P)try{O(!0);const R=(await X.config.get()).cliproxy;N(R?.kiro_no_incognito??!0)}catch{N(!0)}finally{O(!1)}},[P]),L=h.useCallback(async I=>{N(I),S(!0);try{const R=await X.config.get(),V=R.cliproxy??{};await X.config.update({...R,cliproxy:{...V,kiro_no_incognito:I}})}catch{N(!I)}finally{S(!1)}},[]);return h.useEffect(()=>{x()},[x]),e.jsx(ue,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(wt,{catalog:a,savedPresets:t,currentModel:n,opusModel:i,sonnetModel:c,haikuModel:l,providerModels:d,onApplyPreset:r,onUpdateEnvValue:u,onOpenCustomPreset:p,onDeletePreset:m,isDeletePending:g}),e.jsx(fe,{}),e.jsx(Pt,{accounts:o,onAddAccount:v,onSetDefault:k,onRemoveAccount:f,isRemovingAccount:T,privacyMode:M,showQuota:s==="agy",isKiro:P,kiroNoIncognito:y,onKiroNoIncognitoChange:L,kiroSettingsLoading:C||w})]})})}function De({provider:s,displayName:a,authStatus:t,catalog:n,logoProvider:i,baseProvider:c,isRemoteMode:l,port:d,onAddAccount:r,onSetDefault:u,onRemoveAccount:p,isRemovingAccount:m}){const[g,o]=h.useState(!1),{privacyMode:v}=$e(),{data:k}=ks(),{data:f}=As(s),T=Ss(),M=Ps(),P=f?.presets||[],y=c||s,N=h.useMemo(()=>{if(!k?.models)return[];const F={gemini:["google"],agy:["antigravity"],codex:["openai"],qwen:["alibaba","qwen"],iflow:["iflow"],kiro:["kiro","aws"],ghcp:["github","copilot"]}[y.toLowerCase()]||[y.toLowerCase()];return k.models.filter(we=>F.some(ns=>we.owned_by.toLowerCase().includes(ns)))},[k,y]),{data:C,isLoading:O,refetch:w,rawJsonContent:S,rawJsonEdits:x,isRawJsonValid:L,hasChanges:I,currentModel:R,opusModel:V,sonnetModel:J,haikuModel:b,handleRawJsonChange:z,updateEnvValue:H,updateEnvValues:W,saveMutation:ve,conflictDialog:Xe,handleConflictResolve:Ne,missingRequiredFields:Ze}=pt(s),es=t.accounts||[],ss=D=>{W({ANTHROPIC_BASE_URL:`http://127.0.0.1:${d??ne}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:"ccs-internal-managed",...D}),E.success(`Applied "${D.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},ts=(D,F)=>{W({ANTHROPIC_BASE_URL:`http://127.0.0.1:${d??ne}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:"ccs-internal-managed",ANTHROPIC_MODEL:D.default,ANTHROPIC_DEFAULT_OPUS_MODEL:D.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:D.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:D.haiku}),E.success(`Applied ${F?`"${F}"`:"custom"} preset`),o(!1)},as=(D,F)=>{if(!F){E.error("Please enter a preset name to save");return}T.mutate({profile:s,data:{name:F,...D}}),o(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Nt,{provider:s,displayName:a,logoProvider:i,data:C,isLoading:O,hasChanges:I,isRawJsonValid:L,isSaving:ve.isPending,isRemoteMode:l,port:d,onRefetch:w,onSave:()=>ve.mutate()}),O?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx($,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5",children:e.jsxs(Ms,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Os,{className:"w-full",children:[e.jsx(Ce,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(Ce,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(ke,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(Mt,{provider:s,catalog:n,savedPresets:P,currentModel:R,opusModel:V,sonnetModel:J,haikuModel:b,providerModels:N,onApplyPreset:ss,onUpdateEnvValue:H,onOpenCustomPreset:()=>o(!0),onDeletePreset:D=>M.mutate({profile:s,name:D}),isDeletePending:M.isPending,accounts:es,onAddAccount:r,onSetDefault:u,onRemoveAccount:p,isRemovingAccount:m,privacyMode:v})}),e.jsx(ke,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(gt,{provider:s,displayName:a,data:C,authStatus:t})})]})]})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(Ys,{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(Ts,{rawJsonContent:S,isRawJsonValid:L,rawJsonEdits:x,onRawJsonChange:z,profileEnv:C?.settings?.env,missingRequiredFields:Ze})]})]}),e.jsx(st,{open:Xe,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>Ne(!0),onCancel:()=>Ne(!1)}),e.jsx(ht,{open:g,onClose:()=>o(!1),currentValues:{default:R||"",opus:V||"",sonnet:J||"",haiku:b||""},onApply:ts,onSave:as,isSaving:T.isPending,catalog:n,allModels:N})]})}function Ot(s){if(!s)return"";const a=new Date(s).getTime(),n=Date.now()-a,i=Math.floor(n/(1e3*60*60)),c=Math.floor(n%(1e3*60*60)/(1e3*60));return i>0?`${i}h ${c}m`:`${c}m`}function Tt(s){if(!s)return"";const a=Date.now()-s,t=Math.floor(a/(1e3*60)),n=Math.floor(a/(1e3*60*60));return t<1?"just now":t<60?`${t}m ago`:`${n}h ago`}function Dt(){const{data:s,isLoading:a}=Ds(),{data:t}=_s(),n=Es(),i=Ls(),{data:c}=Ee({queryKey:["cliproxy-server-config"],queryFn:()=>X.cliproxyServer.get(),staleTime:3e4}),l=c?.remote,d=l?.enabled&&l?.host,r=s?.running??!1,u=n.isPending||i.isPending,p=t?.hasUpdate??!1,m=d?(()=>{const o=l.protocol||"http",v=l.port||(o==="https"?443:80);return o==="https"&&v===443||o==="http"&&v===80?l.host:`${l.host}:${v}`})():null,g=async()=>{await i.mutateAsync(),await new Promise(o=>setTimeout(o,500)),n.mutate()};return d?e.jsxs("div",{className:A("rounded-lg border p-3 transition-colors","border-blue-500/30 bg-blue-500/5"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium",children:"Remote Proxy"}),e.jsx(_,{variant:"secondary",className:"text-[10px] h-4 px-1.5 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:"Active"})]}),e.jsx(Ae,{className:"w-3 h-3 text-blue-600"})]}),e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[e.jsx("div",{className:"flex items-center gap-1 mb-1",children:e.jsx("span",{className:"font-mono",children:m})}),e.jsx("p",{className:"text-[10px] text-muted-foreground/70 leading-tight",children:"Traffic auto-routed to remote server"})]})]}):e.jsxs("div",{className:A("rounded-lg border p-3 transition-colors",r?"border-green-500/30 bg-green-500/5":"border-muted bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:A("w-2 h-2 rounded-full",r?"bg-green-500 animate-pulse":"bg-muted-foreground/30")}),e.jsx("span",{className:"text-sm font-medium",children:"CLIProxy Plus"}),p&&e.jsxs(_,{variant:"secondary",className:"text-[10px] h-4 px-1.5 gap-0.5 bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",title:`Update: v${t?.currentVersion} -> v${t?.latestVersion}`,children:[e.jsx(Se,{className:"w-2.5 h-2.5"}),"Update"]})]}),e.jsx("div",{className:"flex items-center gap-1",children:a?e.jsx(G,{className:"w-3 h-3 animate-spin text-muted-foreground"}):r?e.jsx(Ae,{className:"w-3 h-3 text-green-600"}):e.jsx(Pe,{className:"w-3 h-3 text-muted-foreground"})})]}),r&&s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-2 flex items-center gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:["Port ",s.port]}),s.sessionCount!==void 0&&s.sessionCount>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Xs,{className:"w-3 h-3"}),s.sessionCount," session",s.sessionCount!==1?"s":""]}),s.startedAt&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Z,{className:"w-3 h-3"}),Ot(s.startedAt)]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsxs(j,{variant:p?"default":"outline",size:"sm",className:A("h-7 text-xs gap-1 flex-1",p&&"bg-sidebar-accent hover:bg-sidebar-accent/90 text-sidebar-accent-foreground"),onClick:g,disabled:u,title:p?`Restart to update: v${t?.currentVersion} -> v${t?.latestVersion}`:"Restart CLIProxy service",children:[u?e.jsx(G,{className:"w-3 h-3 animate-spin"}):p?e.jsx(Se,{className:"w-3 h-3"}):e.jsx(Zs,{className:"w-3 h-3"}),p?"Update":"Restart"]}),e.jsxs(j,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1 hover:bg-destructive/10 hover:text-destructive hover:border-destructive/30",onClick:()=>i.mutate(),disabled:u,title:"Stop CLIProxy service",children:[i.isPending?e.jsx(G,{className:"w-3 h-3 animate-spin"}):e.jsx(et,{className:"w-3 h-3"}),"Stop"]})]})]}):e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not running"}),e.jsxs(j,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",onClick:()=>n.mutate(),disabled:n.isPending,children:[n.isPending?e.jsx(G,{className:"w-3 h-3 animate-spin"}):e.jsx(Pe,{className:"w-3 h-3"}),"Start"]})]}),t?.currentVersion&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-muted flex items-center justify-between text-[10px] text-muted-foreground/70",children:[e.jsxs("span",{children:["v",t.currentVersion]}),t.checkedAt&&e.jsxs("span",{title:new Date(t.checkedAt).toLocaleString(),children:["Synced ",Tt(t.checkedAt)]})]})]})}function _t({status:s,isSelected:a,onSelect:t}){const n=s.accounts?.length||0;return e.jsxs("button",{className:A("w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors cursor-pointer text-left",a?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:t,children:[e.jsx(je,{provider:s.provider,size:"md"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:s.displayName}),n>0&&e.jsx(_,{variant:"secondary",className:"text-[10px] h-4 px-1",children:n})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:s.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-green-600",children:"Connected"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not connected"})]})})]})]})}function Et({variant:s,parentAuth:a,isSelected:t,onSelect:n,onDelete:i,isDeleting:c}){return e.jsxs("button",{className:A("group w-full flex items-center gap-3 px-3 py-2 rounded-lg transition-colors cursor-pointer text-left pl-6",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:n,children:[e.jsxs("div",{className:"relative",children:[e.jsx(je,{provider:s.provider,size:"sm"}),e.jsx(Be,{className:"w-2.5 h-2.5 absolute -bottom-0.5 -right-0.5 text-muted-foreground"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:s.name}),e.jsx(_,{variant:"outline",className:"text-[9px] h-4 px-1",children:"variant"})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:a?.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-3 h-3 text-green-600"}),e.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["via ",s.provider]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Parent not connected"})]})})]}),e.jsx(j,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:l=>{l.stopPropagation(),i()},disabled:c,children:e.jsx(Qe,{className:"w-3 h-3"})})]})}function Lt({onSetup:s}){return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-muted flex items-center justify-center mx-auto mb-6",children:e.jsx(te,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"CCS Profile Manager"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Manage OAuth authentication, account preferences, and model selection for CLIProxy providers. Configure how CCS routes requests to different AI backends."}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-6",children:["For live usage stats and real-time monitoring, visit the"," ",e.jsx("a",{href:"/cliproxy/control-panel",className:"text-primary hover:underline",children:"Control Panel"}),"."]}),e.jsxs(j,{onClick:s,className:"gap-2",children:[e.jsx(B,{className:"w-4 h-4"}),"Quick Setup"]})]})})}function Jt(){const s=_e(),{data:a,isLoading:t}=Ue(),{data:n,isFetching:i}=Rs(),c=Is(),l=Fs(),d=Us(),[r,u]=h.useState(null),[p,m]=h.useState(null),[g,o]=h.useState(!1),[v,k]=h.useState(null),f=h.useMemo(()=>a?.authStatus||[],[a?.authStatus]),T=a?.source==="remote",M=h.useMemo(()=>n?.variants||[],[n?.variants]),P=h.useMemo(()=>p?null:r&&f.some(x=>x.provider===r)?r:f.length>0?f[0].provider:null,[r,p,f]),y=f.find(x=>x.provider===P),N=M.find(x=>x.name===p),C=N?f.find(x=>x.provider===N.provider):void 0,O=()=>{s.invalidateQueries({queryKey:["cliproxy"]}),s.invalidateQueries({queryKey:["cliproxy-auth"]})},w=x=>{u(x),m(null)},S=x=>{m(x),u(null)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"CLIProxy Plus"})]}),e.jsx(j,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:O,disabled:i,children:e.jsx(G,{className:A("w-4 h-4",i&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"CCS-level account management"}),e.jsxs(j,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>o(!0),children:[e.jsx(B,{className:"w-4 h-4"}),"Quick Setup"]})]}),e.jsx(ue,{className:"flex-1",children:e.jsxs("div",{className:"p-2",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3 py-2",children:"Providers"}),t?e.jsx("div",{className:"space-y-2 px-2",children:[1,2,3,4].map(x=>e.jsx(Hs,{className:"h-14 w-full rounded-lg"},x))}):e.jsx("div",{className:"space-y-1",children:f.map(x=>e.jsx(_t,{status:x,isSelected:P===x.provider,onSelect:()=>w(x.provider)},x.provider))}),M.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3 py-2 mt-4 flex items-center gap-1.5",children:[e.jsx(Be,{className:"w-3 h-3"}),"Variants"]}),e.jsx("div",{className:"space-y-1",children:M.map(x=>e.jsx(Et,{variant:x,parentAuth:f.find(L=>L.provider===x.provider),isSelected:p===x.name,onSelect:()=>S(x.name),onDelete:()=>d.mutate(x.name),isDeleting:d.isPending},x.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(Dt,{})}),e.jsx("div",{className:"p-3 border-t bg-background text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[f.length," provider",f.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(K,{className:"w-3 h-3 text-green-600"}),f.filter(x=>x.authenticated).length," connected"]})]})})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:N&&C?e.jsx(De,{provider:N.name,displayName:`${N.name} (${N.provider} variant)`,authStatus:C,catalog:Q[N.provider],logoProvider:N.provider,baseProvider:N.provider,isRemoteMode:T,port:N.port,onAddAccount:()=>k({provider:N.provider,displayName:C.displayName,isFirstAccount:(C.accounts?.length||0)===0}),onSetDefault:x=>c.mutate({provider:N.provider,accountId:x}),onRemoveAccount:x=>l.mutate({provider:N.provider,accountId:x}),isRemovingAccount:l.isPending}):y?e.jsx(De,{provider:y.provider,displayName:y.displayName,authStatus:y,catalog:Q[y.provider],isRemoteMode:T,onAddAccount:()=>k({provider:y.provider,displayName:y.displayName,isFirstAccount:(y.accounts?.length||0)===0}),onSetDefault:x=>c.mutate({provider:y.provider,accountId:x}),onRemoveAccount:x=>l.mutate({provider:y.provider,accountId:x}),isRemovingAccount:l.isPending}):e.jsx(Lt,{onSetup:()=>o(!0)})}),e.jsx(dt,{open:g,onClose:()=>o(!1)}),e.jsx(mt,{open:v!==null,onClose:()=>k(null),provider:v?.provider||"",displayName:v?.displayName||"",isFirstAccount:v?.isFirstAccount||!1})]})}export{Jt as CliproxyPage};
|
|
@@ -1 +0,0 @@
|
|
|
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};
|