@kaitranntt/ccs 7.43.0-dev.2 → 7.43.0-dev.20
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/README.md +49 -2
- package/config/base-codex.settings.json +4 -4
- package/dist/api/services/profile-reader.d.ts.map +1 -1
- package/dist/api/services/profile-reader.js +4 -1
- package/dist/api/services/profile-reader.js.map +1 -1
- package/dist/auth/profile-detector.d.ts +14 -3
- package/dist/auth/profile-detector.d.ts.map +1 -1
- package/dist/auth/profile-detector.js +35 -15
- package/dist/auth/profile-detector.js.map +1 -1
- package/dist/ccs.js +34 -4
- package/dist/ccs.js.map +1 -1
- package/dist/cliproxy/auth/auth-types.d.ts +28 -1
- package/dist/cliproxy/auth/auth-types.d.ts.map +1 -1
- package/dist/cliproxy/auth/auth-types.js +70 -4
- package/dist/cliproxy/auth/auth-types.js.map +1 -1
- package/dist/cliproxy/auth/oauth-handler.d.ts.map +1 -1
- package/dist/cliproxy/auth/oauth-handler.js +19 -4
- package/dist/cliproxy/auth/oauth-handler.js.map +1 -1
- package/dist/cliproxy/composite-validator.d.ts +20 -0
- package/dist/cliproxy/composite-validator.d.ts.map +1 -0
- package/dist/cliproxy/composite-validator.js +85 -0
- package/dist/cliproxy/composite-validator.js.map +1 -0
- package/dist/cliproxy/config/env-builder.d.ts +24 -0
- package/dist/cliproxy/config/env-builder.d.ts.map +1 -1
- package/dist/cliproxy/config/env-builder.js +72 -1
- package/dist/cliproxy/config/env-builder.js.map +1 -1
- package/dist/cliproxy/config/thinking-config.d.ts +19 -2
- package/dist/cliproxy/config/thinking-config.d.ts.map +1 -1
- package/dist/cliproxy/config/thinking-config.js +127 -27
- package/dist/cliproxy/config/thinking-config.js.map +1 -1
- package/dist/cliproxy/executor/env-resolver.d.ts +16 -0
- package/dist/cliproxy/executor/env-resolver.d.ts.map +1 -1
- package/dist/cliproxy/executor/env-resolver.js +82 -26
- package/dist/cliproxy/executor/env-resolver.js.map +1 -1
- package/dist/cliproxy/executor/index.d.ts.map +1 -1
- package/dist/cliproxy/executor/index.js +202 -67
- package/dist/cliproxy/executor/index.js.map +1 -1
- package/dist/cliproxy/executor/retry-handler.d.ts +11 -0
- package/dist/cliproxy/executor/retry-handler.d.ts.map +1 -1
- package/dist/cliproxy/executor/retry-handler.js +30 -1
- package/dist/cliproxy/executor/retry-handler.js.map +1 -1
- package/dist/cliproxy/executor/thinking-arg-parser.d.ts +27 -0
- package/dist/cliproxy/executor/thinking-arg-parser.d.ts.map +1 -0
- package/dist/cliproxy/executor/thinking-arg-parser.js +80 -0
- package/dist/cliproxy/executor/thinking-arg-parser.js.map +1 -0
- package/dist/cliproxy/model-catalog.d.ts.map +1 -1
- package/dist/cliproxy/model-catalog.js +14 -3
- package/dist/cliproxy/model-catalog.js.map +1 -1
- package/dist/cliproxy/model-config.d.ts.map +1 -1
- package/dist/cliproxy/model-config.js +27 -7
- package/dist/cliproxy/model-config.js.map +1 -1
- package/dist/cliproxy/provider-capabilities.d.ts +22 -0
- package/dist/cliproxy/provider-capabilities.d.ts.map +1 -0
- package/dist/cliproxy/provider-capabilities.js +95 -0
- package/dist/cliproxy/provider-capabilities.js.map +1 -0
- package/dist/cliproxy/quota-fetcher-codex.d.ts.map +1 -1
- package/dist/cliproxy/quota-fetcher-codex.js +106 -87
- package/dist/cliproxy/quota-fetcher-codex.js.map +1 -1
- package/dist/cliproxy/remote-auth-fetcher.d.ts.map +1 -1
- package/dist/cliproxy/remote-auth-fetcher.js +3 -26
- package/dist/cliproxy/remote-auth-fetcher.js.map +1 -1
- package/dist/cliproxy/service-manager.d.ts.map +1 -1
- package/dist/cliproxy/service-manager.js +3 -6
- package/dist/cliproxy/service-manager.js.map +1 -1
- package/dist/cliproxy/services/index.d.ts +2 -2
- package/dist/cliproxy/services/index.d.ts.map +1 -1
- package/dist/cliproxy/services/index.js +4 -1
- package/dist/cliproxy/services/index.js.map +1 -1
- package/dist/cliproxy/services/proxy-lifecycle-service.d.ts +15 -3
- package/dist/cliproxy/services/proxy-lifecycle-service.d.ts.map +1 -1
- package/dist/cliproxy/services/proxy-lifecycle-service.js +15 -6
- package/dist/cliproxy/services/proxy-lifecycle-service.js.map +1 -1
- package/dist/cliproxy/services/variant-config-adapter.d.ts +15 -0
- package/dist/cliproxy/services/variant-config-adapter.d.ts.map +1 -1
- package/dist/cliproxy/services/variant-config-adapter.js +84 -11
- package/dist/cliproxy/services/variant-config-adapter.js.map +1 -1
- package/dist/cliproxy/services/variant-service.d.ts +26 -0
- package/dist/cliproxy/services/variant-service.d.ts.map +1 -1
- package/dist/cliproxy/services/variant-service.js +164 -9
- package/dist/cliproxy/services/variant-service.js.map +1 -1
- package/dist/cliproxy/services/variant-settings.d.ts +19 -1
- package/dist/cliproxy/services/variant-settings.d.ts.map +1 -1
- package/dist/cliproxy/services/variant-settings.js +150 -12
- package/dist/cliproxy/services/variant-settings.js.map +1 -1
- package/dist/cliproxy/types.d.ts +13 -0
- package/dist/cliproxy/types.d.ts.map +1 -1
- package/dist/cliproxy/types.js.map +1 -1
- package/dist/commands/cliproxy/auth-subcommand.d.ts.map +1 -1
- package/dist/commands/cliproxy/auth-subcommand.js +2 -1
- package/dist/commands/cliproxy/auth-subcommand.js.map +1 -1
- package/dist/commands/cliproxy/help-subcommand.d.ts.map +1 -1
- package/dist/commands/cliproxy/help-subcommand.js +4 -0
- package/dist/commands/cliproxy/help-subcommand.js.map +1 -1
- package/dist/commands/cliproxy/index.d.ts.map +1 -1
- package/dist/commands/cliproxy/index.js +12 -0
- package/dist/commands/cliproxy/index.js.map +1 -1
- package/dist/commands/cliproxy/proxy-lifecycle-subcommand.d.ts +9 -0
- package/dist/commands/cliproxy/proxy-lifecycle-subcommand.d.ts.map +1 -1
- package/dist/commands/cliproxy/proxy-lifecycle-subcommand.js +92 -6
- package/dist/commands/cliproxy/proxy-lifecycle-subcommand.js.map +1 -1
- package/dist/commands/cliproxy/quota-subcommand.d.ts.map +1 -1
- package/dist/commands/cliproxy/quota-subcommand.js +106 -4
- package/dist/commands/cliproxy/quota-subcommand.js.map +1 -1
- package/dist/commands/cliproxy/variant-subcommand.d.ts +1 -0
- package/dist/commands/cliproxy/variant-subcommand.d.ts.map +1 -1
- package/dist/commands/cliproxy/variant-subcommand.js +307 -3
- package/dist/commands/cliproxy/variant-subcommand.js.map +1 -1
- package/dist/commands/command-execution-contract.d.ts +23 -0
- package/dist/commands/command-execution-contract.d.ts.map +1 -0
- package/dist/commands/command-execution-contract.js +21 -0
- package/dist/commands/command-execution-contract.js.map +1 -0
- package/dist/commands/cursor-command-display.d.ts +6 -0
- package/dist/commands/cursor-command-display.d.ts.map +1 -0
- package/dist/commands/cursor-command-display.js +100 -0
- package/dist/commands/cursor-command-display.js.map +1 -0
- package/dist/commands/cursor-command.d.ts +12 -0
- package/dist/commands/cursor-command.d.ts.map +1 -0
- package/dist/commands/cursor-command.js +222 -0
- package/dist/commands/cursor-command.js.map +1 -0
- package/dist/commands/help-command.d.ts.map +1 -1
- package/dist/commands/help-command.js +30 -3
- package/dist/commands/help-command.js.map +1 -1
- package/dist/commands/shell-completion-command.d.ts +20 -0
- package/dist/commands/shell-completion-command.d.ts.map +1 -1
- package/dist/commands/shell-completion-command.js +45 -30
- package/dist/commands/shell-completion-command.js.map +1 -1
- package/dist/config/reserved-names.d.ts +1 -1
- package/dist/config/reserved-names.d.ts.map +1 -1
- package/dist/config/reserved-names.js +2 -0
- package/dist/config/reserved-names.js.map +1 -1
- package/dist/config/unified-config-loader.d.ts +6 -1
- package/dist/config/unified-config-loader.d.ts.map +1 -1
- package/dist/config/unified-config-loader.js +57 -3
- package/dist/config/unified-config-loader.js.map +1 -1
- package/dist/config/unified-config-types.d.ts +71 -2
- package/dist/config/unified-config-types.d.ts.map +1 -1
- package/dist/config/unified-config-types.js +27 -2
- package/dist/config/unified-config-types.js.map +1 -1
- package/dist/cursor/cursor-daemon-entry.d.ts +14 -0
- package/dist/cursor/cursor-daemon-entry.d.ts.map +1 -0
- package/dist/cursor/cursor-daemon-entry.js +236 -0
- package/dist/cursor/cursor-daemon-entry.js.map +1 -0
- package/dist/cursor/cursor-daemon-pid.d.ts +4 -0
- package/dist/cursor/cursor-daemon-pid.d.ts.map +1 -0
- package/dist/cursor/cursor-daemon-pid.js +77 -0
- package/dist/cursor/cursor-daemon-pid.js.map +1 -0
- package/dist/cursor/cursor-daemon.d.ts +36 -0
- package/dist/cursor/cursor-daemon.d.ts.map +1 -0
- package/dist/cursor/cursor-daemon.js +315 -0
- package/dist/cursor/cursor-daemon.js.map +1 -0
- package/dist/cursor/cursor-executor.d.ts +7 -0
- package/dist/cursor/cursor-executor.d.ts.map +1 -1
- package/dist/cursor/cursor-executor.js +244 -44
- package/dist/cursor/cursor-executor.js.map +1 -1
- package/dist/cursor/cursor-models.d.ts +43 -0
- package/dist/cursor/cursor-models.d.ts.map +1 -0
- package/dist/cursor/cursor-models.js +205 -0
- package/dist/cursor/cursor-models.js.map +1 -0
- package/dist/cursor/cursor-protobuf-decoder.js +26 -26
- package/dist/cursor/cursor-protobuf-decoder.js.map +1 -1
- package/dist/cursor/cursor-protobuf-encoder.js +14 -14
- package/dist/cursor/cursor-protobuf-encoder.js.map +1 -1
- package/dist/cursor/cursor-protobuf-schema.d.ts +121 -74
- package/dist/cursor/cursor-protobuf-schema.d.ts.map +1 -1
- package/dist/cursor/cursor-protobuf-schema.js +80 -90
- package/dist/cursor/cursor-protobuf-schema.js.map +1 -1
- package/dist/cursor/cursor-protobuf.js +25 -25
- package/dist/cursor/cursor-protobuf.js.map +1 -1
- package/dist/cursor/cursor-stream-parser.d.ts +52 -0
- package/dist/cursor/cursor-stream-parser.d.ts.map +1 -0
- package/dist/cursor/cursor-stream-parser.js +142 -0
- package/dist/cursor/cursor-stream-parser.js.map +1 -0
- package/dist/cursor/daemon-process-ownership.d.ts +3 -0
- package/dist/cursor/daemon-process-ownership.d.ts.map +1 -0
- package/dist/cursor/daemon-process-ownership.js +96 -0
- package/dist/cursor/daemon-process-ownership.js.map +1 -0
- package/dist/cursor/index.d.ts +11 -0
- package/dist/cursor/index.d.ts.map +1 -0
- package/dist/cursor/index.js +55 -0
- package/dist/cursor/index.js.map +1 -0
- package/dist/cursor/types.d.ts +32 -1
- package/dist/cursor/types.d.ts.map +1 -1
- package/dist/cursor/types.js +1 -1
- package/dist/management/oauth-port-diagnostics.d.ts +4 -7
- package/dist/management/oauth-port-diagnostics.d.ts.map +1 -1
- package/dist/management/oauth-port-diagnostics.js +12 -23
- package/dist/management/oauth-port-diagnostics.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/ui/assets/accounts-D7apG3NM.js +1 -0
- package/dist/ui/assets/{alert-dialog-Dy-8Z_Ud.js → alert-dialog-z6HEaPqe.js} +1 -1
- package/dist/ui/assets/api-C-aJLAbg.js +1 -0
- package/dist/ui/assets/auth-section-DXzTOTWo.js +1 -0
- package/dist/ui/assets/{backups-section-CDuqhiZo.js → backups-section-BWlvR34E.js} +1 -1
- package/dist/ui/assets/cliproxy-BSyjTE6L.js +3 -0
- package/dist/ui/assets/{cliproxy-control-panel-DJd_zNR3.js → cliproxy-control-panel-CKJHMGqD.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-DtYrWaa7.js → confirm-dialog-D8vB20zr.js} +1 -1
- package/dist/ui/assets/{copilot-DHdywZ9L.js → copilot-7sa7MFH_.js} +3 -3
- package/dist/ui/assets/cursor-KwsbcPyA.js +1 -0
- package/dist/ui/assets/globalenv-section-BiyiJmIj.js +1 -0
- package/dist/ui/assets/{health-BsMhSeFz.js → health-Dqa61Bj1.js} +1 -1
- package/dist/ui/assets/{icons-D5eAI-GR.js → icons-G0rMFC4M.js} +1 -1
- package/dist/ui/assets/index-Bqle3SG4.css +1 -0
- package/dist/ui/assets/{index-B2GQ_Joi.js → index-CiJndnpm.js} +1 -1
- package/dist/ui/assets/index-DGFnVfdv.js +47 -0
- package/dist/ui/assets/index-DacpfVrt.js +1 -0
- package/dist/ui/assets/index-akX3q-m-.js +1 -0
- package/dist/ui/assets/{index-CEF_VhSR.js → index-qMp3rvH4.js} +1 -1
- package/dist/ui/assets/{proxy-status-widget-Cb7KfEqq.js → proxy-status-widget-CSq7bxEv.js} +1 -1
- package/dist/ui/assets/shared-DvyiNZGg.js +1 -0
- package/dist/ui/assets/{switch-D6XSRTo_.js → switch-Cr9fAsnM.js} +1 -1
- package/dist/ui/index.html +3 -3
- package/dist/utils/config-manager.d.ts.map +1 -1
- package/dist/utils/config-manager.js +17 -6
- package/dist/utils/config-manager.js.map +1 -1
- package/dist/web-server/jsonl-parser.js +1 -1
- package/dist/web-server/jsonl-parser.js.map +1 -1
- package/dist/web-server/routes/account-routes.d.ts.map +1 -1
- package/dist/web-server/routes/account-routes.js +5 -11
- package/dist/web-server/routes/account-routes.js.map +1 -1
- package/dist/web-server/routes/cliproxy-auth-routes.d.ts +5 -0
- package/dist/web-server/routes/cliproxy-auth-routes.d.ts.map +1 -1
- package/dist/web-server/routes/cliproxy-auth-routes.js +73 -6
- package/dist/web-server/routes/cliproxy-auth-routes.js.map +1 -1
- package/dist/web-server/routes/cliproxy-stats-routes.d.ts.map +1 -1
- package/dist/web-server/routes/cliproxy-stats-routes.js +43 -4
- package/dist/web-server/routes/cliproxy-stats-routes.js.map +1 -1
- package/dist/web-server/routes/cursor-routes.d.ts +16 -0
- package/dist/web-server/routes/cursor-routes.d.ts.map +1 -0
- package/dist/web-server/routes/cursor-routes.js +171 -0
- package/dist/web-server/routes/cursor-routes.js.map +1 -0
- package/dist/web-server/routes/cursor-settings-routes.d.ts +6 -0
- package/dist/web-server/routes/cursor-settings-routes.d.ts.map +1 -0
- package/dist/web-server/routes/cursor-settings-routes.js +209 -0
- package/dist/web-server/routes/cursor-settings-routes.js.map +1 -0
- package/dist/web-server/routes/index.d.ts.map +1 -1
- package/dist/web-server/routes/index.js +3 -0
- package/dist/web-server/routes/index.js.map +1 -1
- package/dist/web-server/routes/variant-routes.d.ts.map +1 -1
- package/dist/web-server/routes/variant-routes.js +107 -6
- package/dist/web-server/routes/variant-routes.js.map +1 -1
- package/package.json +5 -2
- package/scripts/hardening-inventory.js +526 -0
- package/scripts/maintainability-baseline.js +309 -0
- package/dist/ui/assets/accounts-CkN_roEn.js +0 -1
- package/dist/ui/assets/api-2TN7yVwm.js +0 -1
- package/dist/ui/assets/auth-section-CeKCNzzC.js +0 -1
- package/dist/ui/assets/cliproxy-626zUpA_.js +0 -3
- package/dist/ui/assets/globalenv-section-Cn5ufgRh.js +0 -1
- package/dist/ui/assets/index-Bmgylhgn.js +0 -1
- package/dist/ui/assets/index-Cr6iEc8x.js +0 -47
- package/dist/ui/assets/index-DkMR3J96.js +0 -1
- package/dist/ui/assets/index-QvMpU4Lc.css +0 -1
- package/dist/ui/assets/shared-BsWeldW8.js +0 -1
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{j as e,$ as Ps,a0 as Ms}from"./radix-ui-qEZD5MMp.js";import{r as d}from"./react-vendor-CNOkPC89.js";import{a as Ne,u as Je,b as Ts}from"./tanstack-De4wvi8X.js";import{b as S,C as We,a as Xe,c as U,P as ue,L as ae,I as ie,X as Ye,Y as Ze,Z as es,_ as ss,$ as me,a0 as ts,a1 as Os,a2 as Es,a3 as Ds,u as as,a4 as we,a5 as be,a6 as Ce,a7 as ye,a8 as ns,a9 as Fe,aa as Rs,ab as _s,ac as Is,ad as is,ae as de,af as Ls,ag as Ue,ah as qe,B as G,ai as Fs,q as rs,m as ke,l as Us,aj as qs,ak as Hs,al as Ks,am as Z,T as ee,o as se,p as te,an as Gs,ao as $s,ap as zs,aq as He,ar as Bs,as as Vs,at as Qs,au as Js,av as Ws,aw as Xs,ax as Ys,H as Zs,J as et,K as Ke,M as Ge,ay as st,az as tt,aA as at,aB as nt,aC as it,aD as rt,aE as ot,aF as lt,aG as ct,aH as dt,aI as ut,S as mt}from"./index-Cr6iEc8x.js";import{t as L}from"./notifications-B2HqRBj7.js";import{b as os,L as z,m as xe,y as xt,j as B,l as ls,an as Se,R as Ae,n as ne,a0 as oe,ao as pt,ap as pe,Z as le,I as cs,f as ht,a2 as ds,aq as gt,ah as ft,X as Pe,$ as us,s as ms,t as fe,ar as jt,T as vt,p as $e,as as Nt,ag as xs,q as wt,at as bt,k as Ct,a1 as yt,ak as kt,au as ps}from"./icons-D5eAI-GR.js";import{S as Me,C as St}from"./confirm-dialog-DtYrWaa7.js";import{S as hs}from"./switch-D6XSRTo_.js";import{P as At}from"./proxy-status-widget-Cb7KfEqq.js";import"./utils-CzKF5WmX.js";import"./form-utils-C-pVd1--.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-Dy-8Z_Ud.js";const re={agy:{provider:"agy",displayName:"Antigravity",defaultModel:"claude-opus-4-6-thinking",models:[{id:"claude-opus-4-6-thinking",name:"Claude Opus 4.6 Thinking",description:"Latest flagship, extended thinking",extendedContext:!1,presetMapping:{default:"claude-opus-4-6-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5-thinking",haiku:"claude-sonnet-4-5"}},{id:"claude-opus-4-5-thinking",name:"Claude Opus 4.5 Thinking",description:"Previous flagship, extended thinking",presetMapping:{default:"claude-opus-4-5-thinking",opus:"claude-opus-4-5-thinking",sonnet:"claude-sonnet-4-5-thinking",haiku:"claude-sonnet-4-5"}},{id:"claude-sonnet-4-5-thinking",name:"Claude Sonnet 4.5 Thinking",description:"Balanced with extended thinking",presetMapping:{default:"claude-sonnet-4-5-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5-thinking",haiku:"claude-sonnet-4-5"}},{id:"claude-sonnet-4-5",name:"Claude Sonnet 4.5",description:"Fast and capable",presetMapping:{default:"claude-sonnet-4-5",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5",haiku:"claude-sonnet-4-5"}},{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",description:"Google latest model via Antigravity",extendedContext:!0,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",extendedContext:!0,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",extendedContext:!0,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",extendedContext:!0,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",extendedContext:!0,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.2-codex",models:[{id:"gpt-5.2-codex",name:"GPT-5.2 Codex",description:"Full reasoning support (xhigh)",presetMapping:{default:"gpt-5.2-codex",opus:"gpt-5.2-codex",sonnet:"gpt-5.2-codex",haiku:"gpt-5-mini"}},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"Fast, capped at high reasoning (no xhigh)",presetMapping:{default:"gpt-5-mini",opus:"gpt-5.2-codex",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"}},{id:"gpt-5.1-codex-max",name:"Codex Max (5.1)",description:"Legacy 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:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Code-focused model (1M context)",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship model (256K context)",presetMapping:{default:"qwen3-max",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max-preview",name:"Qwen3 Max Preview",description:"Preview with thinking support (256K)",presetMapping:{default:"qwen3-max-preview",opus:"qwen3-max-preview",sonnet:"qwen3-max",haiku:"qwen3-coder-flash"}},{id:"qwen3-235b",name:"Qwen3 235B",description:"Large 235B A22B model",presetMapping:{default:"qwen3-235b",opus:"qwen3-max",sonnet:"qwen3-235b",haiku:"qwen3-coder-flash"}},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language multimodal"},{id:"qwen3-coder-flash",name:"Qwen3 Coder Flash",description:"Fast code generation"},{id:"qwen3-32b",name:"Qwen3 32B",description:"Qwen3 32B 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"}]},claude:{provider:"claude",displayName:"Claude (Anthropic)",defaultModel:"claude-sonnet-4-5-20250929",models:[{id:"claude-opus-4-6",name:"Claude Opus 4.6",description:"Latest flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5",description:"Most capable Claude model",extendedContext:!0,presetMapping:{default:"claude-opus-4-5-20251101",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5",description:"Balanced performance and speed",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-5-20250929",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4",description:"Previous generation Sonnet",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-20250514",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-20250514",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5",description:"Fast and efficient"}]}},je=8317,ge="ccs-internal-managed";async function Pt(){try{const s=await fetch("/api/settings/auth/tokens/raw");return s.ok?(await s.json())?.apiKey?.value??ge:ge}catch{return ge}}async function ve(s,a){const t=re[s];if(!t)return{success:!1};const i=t.models[0],r=i?.presetMapping||{default:t.defaultModel,opus:t.defaultModel,sonnet:t.defaultModel,haiku:t.defaultModel},c=await Pt(),h={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${je}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:c,ANTHROPIC_MODEL:r.default,ANTHROPIC_DEFAULT_OPUS_MODEL:r.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:r.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:r.haiku}};try{return{success:(await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:h})})).ok,presetName:i?.name||t.defaultModel}}catch{return{success:!1}}}function Mt({currentProgress:s,allSteps:a}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:a.map((t,i)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${s>=i?"bg-primary":"bg-muted"}`},t))})}function Tt({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(os,{className:"w-4 h-4 text-muted-foreground"})]},t.id))})}function Ot({selectedProvider:s,providers:a,authCommand:t,isRefreshing:i,isPending:r,onBack:c,onStartAuth:o,onRefresh:h}){const[m,f]=d.useState(!1),j=async x=>{await navigator.clipboard.writeText(x),f(!0),setTimeout(()=>f(!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(x=>x.id===s)?.name," to add an account"]}),e.jsx(S,{onClick:o,disabled:r,className:"w-full gap-2",size:"lg",children:r?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"w-4 h-4"}),"Authenticate in Browser"]})}),r&&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(We,{children:e.jsxs(Xe,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(xt,{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(S,{variant:"outline",size:"icon",onClick:()=>j(t),children:m?e.jsx(B,{className:"w-4 h-4 text-green-500"}):e.jsx(ls,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(S,{variant:"ghost",onClick:c,disabled:r,children:[e.jsx(Se,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(S,{variant:"outline",onClick:h,disabled:i||r,children:[e.jsx(Ae,{className:`w-4 h-4 mr-2 ${i?"animate-spin":""}`}),i?"Checking...":"Refresh Status"]})]})]})}function Et({accounts:s,privacyMode:a,onSelect:t,onAddNew:i,onBack:r}){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 max-h-[320px] overflow-y-auto pr-1",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(ne,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:U("font-medium",a&&ue),children:c.email||c.id}),c.isDefault&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Default account"})]})]}),e.jsx(os,{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:i,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(S,{variant:"ghost",onClick:r,children:[e.jsx(Se,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}const ze="__custom__";function Dt({selectedProvider:s,selectedAccount:a,variantName:t,modelName:i,isPending:r,privacyMode:c,onVariantNameChange:o,onModelChange:h,onBack:m,onSkip:f,onCreate:j}){const x=re[s]?.models||[],n=i&&!x.some(u=>u.id===i),[g,w]=d.useState(n),v=u=>{u===ze?(w(!0),h("")):(w(!1),h(u))};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(ne,{className:"w-4 h-4"}),e.jsxs("span",{children:["Using:"," ",e.jsx("span",{className:U(c&&ue),children:a.email||a.id})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ae,{htmlFor:"variant-name",children:"Variant Name *"}),e.jsx(ie,{id:"variant-name",value:t,onChange:u=>o(u.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(ae,{children:"Model"}),g?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ie,{value:i,onChange:u=>h(u.target.value),placeholder:"e.g., gemini-2.5-pro, claude-opus-4-5"}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>w(!1),children:"Choose from presets instead"})]}):e.jsxs(Ye,{value:x.some(u=>u.id===i)?i:"",onValueChange:v,children:[e.jsx(Ze,{children:e.jsx(es,{placeholder:"Select a model"})}),e.jsxs(ss,{children:[x.map(u=>e.jsx(me,{value:u.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:u.name}),u.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",u.description]})]})},u.id)),e.jsx(me,{value:ze,children:e.jsx("span",{className:"text-primary",children:"Custom model name..."})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:g?"Enter any model name supported by CLIProxy":`Default: ${re[s]?.defaultModel||"provider default"}`})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(S,{variant:"ghost",onClick:m,children:[e.jsx(Se,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"ghost",onClick:f,children:"Skip"}),e.jsx(S,{onClick:j,disabled:!t||r,children:r?"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 Rt({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(B,{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(We,{children:e.jsxs(Xe,{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(S,{onClick:a,className:"w-full",children:"Done"})]})}function _t({open:s,onClose:a}){const[t,i]=d.useState("provider"),[r,c]=d.useState(""),[o,h]=d.useState(null),[m,f]=d.useState(""),[j,x]=d.useState(""),[n,g]=d.useState(!1),[w,v]=d.useState(!1),{data:u,refetch:p}=ts(),M=Os(),I=Es(),D=Ds(),{privacyMode:R}=as(),C=u?.authStatus.find(y=>y.provider===r),O=d.useMemo(()=>C?.accounts||[],[C?.accounts]);d.useEffect(()=>{if(!s){const y=setTimeout(()=>{i("provider"),c(""),h(null),f(""),x(""),v(!1)},0);return()=>clearTimeout(y)}},[s]),d.useEffect(()=>{if(t==="auth"&&O.length>0&&!w){const y=setTimeout(()=>{i("account")},0);return()=>clearTimeout(y)}},[t,O,w]);const T=async()=>{g(!0),await p(),g(!1)},A=()=>{const y=(C?.accounts?.length||0)===0;I.mutate({provider:r},{onSuccess:async P=>{if(y){const F=await ve(r);F.success&&F.presetName?L.success(`Applied "${F.presetName}" preset`):F.success||L.warning("Account added, but failed to apply default preset")}P.account&&(h(P.account),i("variant")),p()}})},N=y=>{c(y),(u?.authStatus.find($=>$.provider===y)?.accounts||[]).length===0?i("auth"):i("account")},k=y=>{h(y),i("variant")},b=async()=>{if(!(!m||!r))try{await M.mutateAsync({name:m,provider:r,model:j||void 0,account:o?.id}),i("success")}catch(y){console.error("Failed to create variant:",y)}},_=`ccs ${r} --auth --add`,q=_s(t),K=y=>{if(!y&&(I.isPending&&r&&D.mutate(r),t==="success"||t==="provider")){a();return}};return e.jsx(we,{open:s,onOpenChange:K,children:e.jsxs(be,{className:"sm:max-w-lg",onPointerDownOutside:y=>{t!=="success"&&t!=="provider"&&y.preventDefault()},onEscapeKeyDown:y=>{(I.isPending||M.isPending)&&y.preventDefault()},children:[e.jsxs(Ce,{children:[e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs(ns,{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(Tt,{providers:Fe,onSelect:N}),t==="auth"&&e.jsx(Ot,{selectedProvider:r,providers:Fe,authCommand:_,isRefreshing:n,isPending:I.isPending,onBack:()=>i("provider"),onStartAuth:A,onRefresh:T}),t==="account"&&e.jsx(Et,{accounts:O,privacyMode:R,onSelect:k,onAddNew:()=>{v(!0),i("auth")},onBack:()=>i("provider")}),t==="variant"&&e.jsx(Dt,{selectedProvider:r,selectedAccount:o,variantName:m,modelName:j,isPending:M.isPending,privacyMode:R,onVariantNameChange:f,onModelChange:x,onBack:()=>O.length>0?i("account"):i("provider"),onSkip:a,onCreate:b}),t==="success"&&e.jsx(Rt,{variantName:m,onClose:a})]}),e.jsx(Mt,{currentProgress:q,allSteps:Rs})]})})}const It=3e3,Lt=300*1e3,X={provider:null,isAuthenticating:!1,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:!1};function Ft(){const[s,a]=d.useState(X),t=d.useRef(null),i=d.useRef(null),r=d.useRef(0),c=Ne(),o=d.useCallback(()=>{i.current&&(clearInterval(i.current),i.current=null)},[]);d.useEffect(()=>()=>{t.current?.abort(),o()},[o]);const h=d.useCallback(async(x,n)=>{if(Date.now()-r.current>Lt){o(),a(g=>({...g,isAuthenticating:!1,error:"Authentication timed out. Please try again."}));return}try{const w=await(await fetch(`/api/cliproxy/auth/${x}/status?state=${encodeURIComponent(n)}`)).json();if(w.status==="ok")o(),c.invalidateQueries({queryKey:["cliproxy-auth"]}),c.invalidateQueries({queryKey:["account-quota"]}),L.success(`${x} authentication successful`),a(X);else if(w.status==="error"){o();const v=w.error||"Authentication failed";L.error(v),a(u=>({...u,isAuthenticating:!1,error:v}))}}catch{}},[c,o]),m=d.useCallback(async(x,n)=>{if(!Is(x)){a({...X,error:`Unknown provider: ${x}`});return}t.current?.abort(),o();const g=new AbortController;t.current=g;const w=is(x);a({provider:x,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:w});try{if(w)fetch(`/api/cliproxy/auth/${x}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nickname:n?.nickname}),signal:g.signal}).then(async v=>{const u=await v.json();if(v.ok&&u.success)c.invalidateQueries({queryKey:["cliproxy-auth"]}),c.invalidateQueries({queryKey:["account-quota"]}),a(X);else{const p=u.error||"Authentication failed";L.error(p),a(M=>({...M,isAuthenticating:!1,error:p}))}}).catch(v=>{if(v instanceof Error&&v.name==="AbortError")return;const u=v instanceof Error?v.message:"Authentication failed";L.error(u),a(p=>({...p,isAuthenticating:!1,error:u}))});else{const v=await fetch(`/api/cliproxy/auth/${x}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nickname:n?.nickname}),signal:g.signal}),u=await v.json();if(!v.ok||!u.success)throw new Error(u.error||"Failed to start OAuth");a(p=>({...p,authUrl:u.authUrl,oauthState:u.state})),u.authUrl&&window.open(u.authUrl,"_blank"),u.state&&(r.current=Date.now(),i.current=setInterval(()=>{h(x,u.state)},It))}}catch(v){if(v instanceof Error&&v.name==="AbortError"){a(X);return}const u=v instanceof Error?v.message:"Authentication failed";L.error(u),a(p=>({...p,isAuthenticating:!1,error:u}))}},[h,o,c]),f=d.useCallback(()=>{const x=s.provider;t.current?.abort(),o(),a(X),x&&de.cliproxy.auth.cancel(x).catch(()=>{})},[s.provider,o]),j=d.useCallback(async x=>{if(s.provider){a(n=>({...n,isSubmittingCallback:!0,error:null}));try{const n=await fetch(`/api/cliproxy/auth/${s.provider}/submit-callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirectUrl:x})}),g=await n.json();if(n.ok&&g.success)o(),c.invalidateQueries({queryKey:["cliproxy-auth"]}),c.invalidateQueries({queryKey:["account-quota"]}),L.success(`${s.provider} authentication successful`),a(X);else throw new Error(g.error||"Callback submission failed")}catch(n){const g=n instanceof Error?n.message:"Failed to submit callback";L.error(g),a(w=>({...w,isSubmittingCallback:!1,error:g}))}}},[s.provider,c,o]);return d.useMemo(()=>({...s,startAuth:m,cancelAuth:f,submitCallback:j}),[s,m,f,j])}function Ut({open:s,onClose:a,provider:t,displayName:i,isFirstAccount:r=!1}){const[c,o]=d.useState(""),[h,m]=d.useState(""),[f,j]=d.useState(!1),x=d.useRef(!1),n=Ft(),g=Ls(),w=t==="kiro",v=is(t),u=n.isAuthenticating||g.isPending,p=()=>{o(""),m(""),j(!1),x.current=!1,a()};d.useEffect(()=>{!n.isAuthenticating&&!n.error&&n.provider===null&&s&&x.current&&(x.current=!1,(async()=>{try{const N=await ve(t);N.success&&N.presetName&&r&&L.success(`Applied "${N.presetName}" preset`)}catch{}p()})())},[n.isAuthenticating,n.error,n.provider]);const M=()=>{n.cancelAuth(),p()},I=async()=>{n.authUrl&&(await navigator.clipboard.writeText(n.authUrl),j(!0),setTimeout(()=>j(!1),2e3))},D=()=>{h.trim()&&n.submitCallback(h.trim())},R=()=>{x.current=!0,n.startAuth(t,{nickname:c.trim()||void 0})},C=()=>{x.current=!0,g.mutate(void 0,{onSuccess:async()=>{const A=await ve("kiro");A.success&&A.presetName&&r&&L.success(`Applied "${A.presetName}" preset`),p()}})},O=A=>{A||M()},T=n.isAuthenticating;return e.jsx(we,{open:s,onOpenChange:O,children:e.jsxs(be,{className:"sm:max-w-md",onInteractOutside:A=>{T&&A.preventDefault()},children:[e.jsxs(Ce,{children:[e.jsxs(ye,{children:["Add ",i," Account"]}),e.jsx(ns,{children:w?"Authenticate via browser or import an existing token from Kiro IDE.":v?"Click Authenticate. A verification code will appear for you to enter on the provider website.":"Click Authenticate to get an OAuth URL. Open it in any browser to sign in."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[!T&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ae,{htmlFor:"nickname",children:"Nickname (optional)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(ie,{id:"nickname",value:c,onChange:A=>o(A.target.value),placeholder:"e.g., work, personal",disabled:u,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."})]}),T&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx(z,{className:"w-4 h-4 inline mr-2 animate-spin"}),"Waiting for authentication..."]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:n.isDeviceCodeFlow?"A verification code dialog will appear shortly. Enter the code on the provider website.":"Complete the authentication in your browser. This dialog closes automatically."})]}),n.error&&!n.authUrl&&e.jsx("p",{className:"text-xs text-center text-destructive",children:n.error}),n.authUrl&&!n.isDeviceCodeFlow&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ae,{className:"text-xs",children:"Open this URL in any browser to sign in:"}),e.jsxs("div",{className:"p-3 bg-muted rounded-md",children:[e.jsx("p",{className:"text-xs text-muted-foreground break-all font-mono line-clamp-3",children:n.authUrl}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:I,children:f?e.jsxs(e.Fragment,{children:[e.jsx(B,{className:"w-3 h-3 mr-1"}),"Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(ls,{className:"w-3 h-3 mr-1"}),"Copy"]})}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>{if(!n.authUrl)return;const A=window.open(n.authUrl,"_blank");(!A||A.closed||typeof A.closed>"u")&&L.warning("Popup blocked. Copy the URL above and open it manually in your browser.",{duration:5e3})},children:[e.jsx(xe,{className:"w-3 h-3 mr-1"}),"Open"]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ae,{htmlFor:"callback-url",className:"text-xs",children:"Redirect didn't work? Paste the callback URL:"}),e.jsx(ie,{id:"callback-url",value:h,onChange:A=>m(A.target.value),placeholder:"Paste the redirect URL here...",className:"font-mono text-xs"}),e.jsx(S,{variant:"secondary",size:"sm",onClick:D,disabled:!h.trim()||n.isSubmittingCallback,children:n.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-3 h-3 mr-1 animate-spin"}),"Submitting..."]}):"Submit Callback"})]})]})]}),g.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(z,{className:"w-4 h-4 inline mr-2 animate-spin"}),"Importing token from Kiro IDE..."]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(S,{variant:"ghost",onClick:M,children:"Cancel"}),w&&!T&&e.jsx(S,{variant:"outline",onClick:C,disabled:u,children:g.isPending?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 mr-2 animate-spin"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(pt,{className:"w-4 h-4 mr-2"}),"Import from IDE"]})}),!T&&e.jsxs(S,{onClick:R,disabled:u,children:[e.jsx(xe,{className:"w-4 h-4 mr-2"}),"Authenticate"]})]})]})]})})}const Te="[1m]";function qt(s){return s.toLowerCase().startsWith("gemini-")}function Oe(s){return s.toLowerCase().endsWith(Te.toLowerCase())}function Ht(s){return!s||Oe(s)?s:`${s}${Te}`}function gs(s){return s&&(Oe(s)?s.slice(0,-Te.length):s)}const Be=["ANTHROPIC_MODEL"],Kt=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function Gt(s){const a=s?.env||{};return Kt.filter(t=>!a[t]?.trim())}function $t(s){const[a,t]=d.useState(null),[i,r]=d.useState(!1),c=Ne(),{data:o,isLoading:h,refetch:m}=Je({queryKey:["settings",s],queryFn:async()=>{const N=await fetch(`/api/settings/${s}/raw`);return N.ok?N.json():{profile:s,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${s}/settings.json`}}}),f=o?.settings,j=d.useMemo(()=>a!==null?a:f?JSON.stringify(f,null,2):`{
|
|
2
|
-
"env": {}
|
|
3
|
-
}`,[a,f]),x=d.useCallback(N=>{t(N)},[]),n=d.useMemo(()=>{try{return JSON.parse(j)}catch{return f||{env:{}}}},[j,f]),g=n?.env?.ANTHROPIC_MODEL,w=n?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,v=n?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,u=n?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,p=d.useMemo(()=>{const N=n?.env||{};return Be.some(k=>{const b=N[k];return b&&Oe(b)})},[n]),M=d.useCallback((N,k)=>{const b={...n?.env||{},[N]:k},_={...n,env:b};t(JSON.stringify(_,null,2))},[n]),I=d.useCallback(N=>{const k=n?.env||{},b={};for(const K of Be){const y=k[K];y&&(b[K]=N?Ht(y):gs(y))}const _={...k,...b};delete _.CCS_EXTENDED_CONTEXT;const q={...n,env:_};t(JSON.stringify(q,null,2))},[n]),D=d.useCallback(N=>{const k={...n?.env||{},...N},b={...n,env:k};t(JSON.stringify(b,null,2))},[n]),R=d.useMemo(()=>{try{return JSON.parse(j),!0}catch{return!1}},[j]),C=d.useMemo(()=>a===null?!1:a!==JSON.stringify(f,null,2),[a,f]),O=d.useMemo(()=>Gt(n),[n]),T=Ts({mutationFn:async()=>{const N=JSON.parse(j),k=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:N,expectedMtime:o?.mtime})});if(k.status===409)throw new Error("CONFLICT");if(!k.ok)throw new Error("Failed to save");return k.json()},onSuccess:N=>{c.invalidateQueries({queryKey:["settings",s]}),t(null),N?.warning?L.success("Settings saved",{description:N.warning}):L.success("Settings saved")},onError:N=>{N.message==="CONFLICT"?r(!0):L.error(N.message)}}),A=async N=>{r(!1),N?(await m(),T.mutate()):t(null)};return{data:o,isLoading:h,refetch:m,rawJsonContent:j,rawJsonEdits:a,isRawJsonValid:R,hasChanges:C,currentSettings:n,currentModel:g,opusModel:w,sonnetModel:v,haikuModel:u,extendedContextEnabled:p,toggleExtendedContext:I,handleRawJsonChange:x,updateEnvValue:M,updateEnvValues:D,saveMutation:{mutate:()=>T.mutate(),isPending:T.isPending},conflictDialog:i,setConflictDialog:r,handleConflictResolve:A,missingRequiredFields:O}}function J({label:s,description:a,value:t,onChange:i,catalog:r,allModels:c,disabled:o}){const h=new Set(r?.models.map(m=>m.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(Ye,{value:t||"",onValueChange:i,disabled:o,children:[e.jsx(Ze,{className:"h-9",children:e.jsx(es,{placeholder:"Select model",children:t&&e.jsx("span",{className:"truncate font-mono text-xs",children:t})})}),e.jsxs(ss,{className:"max-h-[300px]",children:[r&&r.models.length>0&&e.jsxs(Ue,{children:[e.jsx(qe,{className:"text-xs text-primary",children:"Recommended"}),r.models.map(m=>e.jsx(me,{value:m.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:m.id}),m.tier==="paid"&&e.jsx(G,{variant:"outline",className:"text-[9px] h-4 px-1",children:"PAID"}),t===m.id&&e.jsx(B,{className:"w-3 h-3 text-primary ml-auto"})]})},m.id))]}),c.length>0&&e.jsxs(Ue,{children:[e.jsxs(qe,{className:"text-xs text-muted-foreground",children:["All Models (",c.length,")"]}),c.filter(m=>!h.has(m.id)).map(m=>e.jsx(me,{value:m.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:m.id}),t===m.id&&e.jsx(B,{className:"w-3 h-3 text-primary ml-auto"})]})},m.id))]}),(!r||r.models.length===0)&&c.length===0&&e.jsx("div",{className:"py-2 px-3 text-xs text-muted-foreground",children:"No models available"})]})]})]})}function zt({open:s,onClose:a,currentValues:t,onApply:i,onSave:r,isSaving:c,catalog:o,allModels:h}){const[m,f]=d.useState(t),[j,x]=d.useState(""),n=g=>{g?(f(t),x("")):a()};return e.jsx(we,{open:s,onOpenChange:n,children:e.jsxs(be,{className:"sm:max-w-md",children:[e.jsx(Ce,{children:e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(oe,{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(ae,{htmlFor:"preset-name",children:"Preset Name (optional)"}),e.jsx(ie,{id:"preset-name",value:j,onChange:g=>x(g.target.value),placeholder:"e.g., My Custom Config",className:"text-sm"})]}),e.jsx(Me,{}),e.jsx(J,{label:"Default Model",description:"Used when no specific tier is requested",value:m.default,onChange:g=>f({...m,default:g}),catalog:o,allModels:h}),e.jsx(J,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:m.opus,onChange:g=>f({...m,opus:g}),catalog:o,allModels:h}),e.jsx(J,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:m.sonnet,onChange:g=>f({...m,sonnet:g}),catalog:o,allModels:h}),e.jsx(J,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:m.haiku,onChange:g=>f({...m,haiku:g}),catalog:o,allModels:h})]}),e.jsxs(Fs,{className:"gap-2 sm:gap-0",children:[e.jsx(S,{variant:"outline",onClick:a,children:"Cancel"}),r&&e.jsxs(S,{variant:"secondary",onClick:()=>r(m,j||void 0),disabled:c||!j.trim(),children:[c?e.jsx(z,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(pe,{className:"w-4 h-4 mr-1"}),"Save Preset"]}),e.jsxs(S,{onClick:()=>i(m,j||void 0),children:[e.jsx(le,{className:"w-4 h-4 mr-1"}),"Apply Preset"]})]})]})})}function ce({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(rs,{value:a,size:"icon",className:"h-6 w-6"})]})]})}function Bt({provider:s,displayName:a,data:t,authStatus:i}){return e.jsx(ke,{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(cs,{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(rs,{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"}),i.authenticated?e.jsxs(G,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(ht,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(G,{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(ce,{label:"Run with prompt",command:`ccs ${s} "your prompt"`}),e.jsx(ce,{label:"Change model",command:`ccs ${s} --config`}),e.jsx(ce,{label:"Add account",command:`ccs ${s} --add`}),e.jsx(ce,{label:"List accounts",command:`ccs ${s} --accounts`})]})]})]})})}const Vt={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",claude:"/assets/providers/claude.svg"},Qt={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"}},Jt={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 Ee({provider:s,className:a,size:t="md"}){const i=s.toLowerCase(),r=Qt[i]||{text:"text-gray-600",letter:s[0]?.toUpperCase()||"?"},c=Jt[t],o=Vt[i];return e.jsx("div",{className:U("flex items-center justify-center rounded-md",o&&"bg-white p-1",c.container,a),children:o?e.jsx("img",{src:o,alt:`${s} logo`,className:U(c.icon,"object-contain")}):e.jsx("span",{className:U("font-semibold",r.text,c.text),children:r.letter})})}function Wt({displayName:s,logoProvider:a,provider:t,data:i,isLoading:r,hasChanges:c,isRawJsonValid:o,isSaving:h,isRemoteMode:m,port:f,onRefetch:j,onSave:x}){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(Ee,{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}),m&&e.jsxs(G,{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(ds,{className:"w-3 h-3"}),"Remote"]}),f&&e.jsxs(G,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(gt,{className:"w-3 h-3"}),":",f]}),!m&&i?.path&&e.jsx(G,{variant:"outline",className:"text-xs",children:i.path.replace(/^.*[\\/]/,"")})]}),m?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):i&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(i.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"ghost",size:"sm",onClick:j,disabled:r,children:e.jsx(Ae,{className:`w-4 h-4 ${r?"animate-spin":""}`})}),e.jsx(S,{size:"sm",onClick:x,disabled:h||!c||!o,children:h?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ft,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Xt({model:s,provider:a,enabled:t,onToggle:i,disabled:r,className:c}){if(!s?.extendedContext)return null;const o=qt(s.id);return e.jsxs("div",{className:U("rounded-lg border p-3 space-y-2",t?"border-primary/50 bg-primary/5":"border-border bg-muted/30",c),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:U("w-4 h-4",t?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:"text-sm font-medium",children:"Extended Context"}),e.jsx(G,{variant:t?"default":"secondary",className:"text-[10px] h-5 px-1.5",children:"1M tokens"})]}),e.jsx(hs,{checked:t,onCheckedChange:i,disabled:r})]}),e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(cs,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{children:"Enables 1M token context window instead of default 200K."}),e.jsx("p",{className:"text-[10px]",children:o?e.jsxs("span",{className:"text-primary",children:["Auto-enabled for ",a," Gemini models"]}):e.jsxs("span",{children:["Opt-in for ",a," Claude models via --1m flag"]})}),t&&e.jsx("p",{className:"text-amber-600 dark:text-amber-500",children:"Note: 2x input pricing applies for tokens beyond 200K"})]})]})]})}function Yt({catalog:s,savedPresets:a,currentModel:t,opusModel:i,sonnetModel:r,haikuModel:c,providerModels:o,provider:h,extendedContextEnabled:m,onExtendedContextToggle:f,onApplyPreset:j,onUpdateEnvValue:x,onOpenCustomPreset:n,onDeletePreset:g,isDeletePending:w}){const v=s&&s.models.length>0||a.length>0,u=d.useMemo(()=>{if(!s||!t)return;const p=gs(t);return s.models.find(M=>M.id===p)},[s,t]);return e.jsxs(e.Fragment,{children:[v&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(oe,{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(p=>e.jsxs(S,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>{const M=p.presetMapping||{default:p.id,opus:p.id,sonnet:p.id,haiku:p.id};j({ANTHROPIC_MODEL:M.default,ANTHROPIC_DEFAULT_OPUS_MODEL:M.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:M.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:M.haiku})},children:[e.jsx(le,{className:"w-3 h-3"}),p.name]},p.id)),a.map(p=>e.jsxs("div",{className:"group relative",children:[e.jsxs(S,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{j({ANTHROPIC_MODEL:p.default,ANTHROPIC_DEFAULT_OPUS_MODEL:p.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:p.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:p.haiku})},children:[e.jsx(pe,{className:"w-3 h-3 fill-current"}),p.name]}),e.jsx(S,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:M=>{M.stopPropagation(),g(p.name)},disabled:w,children:e.jsx(Pe,{className:"w-3 h-3"})})]},p.name)),e.jsxs(S,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1 border-primary/50 text-primary hover:bg-primary/10 hover:border-primary",onClick:n,children:[e.jsx(us,{className:"w-3 h-3"}),"Custom"]})]})]}),e.jsx(Me,{}),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(J,{label:"Default Model",description:"Used when no specific tier is requested",value:t,onChange:p=>x("ANTHROPIC_MODEL",p),catalog:s,allModels:o}),u?.extendedContext&&f&&e.jsx(Xt,{model:u,provider:h,enabled:m??!1,onToggle:f}),e.jsx(J,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:i,onChange:p=>x("ANTHROPIC_DEFAULT_OPUS_MODEL",p),catalog:s,allModels:o}),e.jsx(J,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:r,onChange:p=>x("ANTHROPIC_DEFAULT_SONNET_MODEL",p),catalog:s,allModels:o}),e.jsx(J,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:c,onChange:p=>x("ANTHROPIC_DEFAULT_HAIKU_MODEL",p),catalog:s,allModels:o})]})]})]})}function Zt({className:s,...a}){return e.jsx(Ps,{"data-slot":"checkbox",className:U("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",s),...a,children:e.jsx(Ms,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:e.jsx(B,{className:"size-3.5"})})})}function ea(s){const a=Math.max(0,Math.min(100,s));return a<=20?"bg-destructive":a<=50?"bg-yellow-500":"bg-green-500"}function Ve(s){if(!s)return"";try{const a=new Date(s),i=new Date().getTime()-a.getTime();if(i<0)return"just now";const r=Math.floor(i/(1e3*60)),c=Math.floor(i/(1e3*60*60)),o=Math.floor(i/(1e3*60*60*24));return o>0?`${o}d ago`:c>0?`${c}h ago`:r>0?`${r}m ago`:"just now"}catch{return""}}function sa(s){if(!s)return!1;try{const a=new Date(s);return new Date().getTime()-a.getTime()<3600*1e3}catch{return!1}}function ta({account:s,onSetDefault:a,onRemove:t,onPauseToggle:i,isRemoving:r,isPausingAccount:c,privacyMode:o,showQuota:h,selectable:m,selected:f,onSelectChange:j}){const{data:x}=Us(h),{data:n,isLoading:g}=qs(s.provider,s.id,h),w=x?.accountStats?.[s.email||s.id]?.lastUsedAt,v=sa(w),u=Hs(s.provider,n),p=Ks(s.provider,n);return e.jsxs("div",{className:U("flex flex-col gap-2 p-3 rounded-lg border transition-colors overflow-hidden",s.isDefault?"border-primary/30 bg-primary/5":"border-border hover:bg-muted/30",s.paused&&"opacity-75",f&&"ring-2 ring-primary/50 bg-primary/5"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[m&&e.jsx("button",{type:"button",onClick:()=>j?.(!f),className:U("flex items-center justify-center w-5 h-5 rounded border-2 transition-colors shrink-0",f?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/30 hover:border-primary/50"),"aria-label":f?"Deselect account":"Select account",children:f&&e.jsx(B,{className:"w-3 h-3"})}),i&&e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>i(!s.paused),disabled:c,children:c?e.jsx(z,{className:"w-4 h-4 animate-spin"}):s.paused?e.jsx(ms,{className:"w-4 h-4 text-emerald-500"}):e.jsx(fe,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(te,{side:"top",children:s.paused?"Resume account":"Pause account"})]})}),e.jsxs("div",{className:"relative shrink-0",children:[e.jsx("div",{className:U("flex items-center justify-center w-8 h-8 rounded-full",s.isDefault?"bg-primary/10":"bg-muted"),children:e.jsx(ne,{className:"w-4 h-4"})}),s.tier&&s.tier!=="unknown"&&s.tier!=="free"&&e.jsx("span",{className:U("absolute -bottom-0.5 -right-0.5 text-[7px] font-bold uppercase px-1 py-px rounded","ring-1 ring-background",s.tier==="ultra"?"bg-violet-500/20 text-violet-600 dark:bg-violet-500/30 dark:text-violet-300":"bg-yellow-500/20 text-yellow-700 dark:bg-yellow-500/25 dark:text-yellow-400"),children:s.tier==="ultra"?"U":"P"})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:U("font-medium text-sm truncate",o&&ue),children:s.email||s.id}),s.isDefault&&e.jsxs(G,{variant:"secondary",className:"text-[10px] h-4 px-1.5 gap-0.5",children:[e.jsx(pe,{className:"w-2.5 h-2.5 fill-current"}),"Default"]}),s.paused&&e.jsxs(G,{variant:"outline",className:"text-[10px] h-4 px-1.5 border-yellow-500 text-yellow-600",children:[e.jsx(fe,{className:"w-2 h-2 mr-0.5"}),"Paused"]})]}),s.provider==="agy"&&e.jsx("div",{className:"flex items-center gap-1.5 mt-1",children:s.projectId?e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(jt,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:U("font-mono max-w-[180px] truncate",o&&ue),title:s.projectId,children:s.projectId})]})}),e.jsx(te,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"GCP Project ID (read-only)"})})]})}):e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(vt,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:"Project ID: N/A"})]})}),e.jsx(te,{side:"bottom",className:"max-w-[250px]",children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium text-amber-600",children:"Missing Project ID"}),e.jsx("p",{children:"This may cause errors. Remove the account and re-add it to fetch the project ID."})]})})]})})}),s.lastUsedAt&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mt-0.5",children:[e.jsx($e,{className:"w-3 h-3"}),"Last used: ",new Date(s.lastUsedAt).toLocaleDateString()]})]})]}),e.jsxs(Gs,{children:[e.jsx($s,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(Nt,{className:"w-4 h-4"})})}),e.jsxs(zs,{align:"end",children:[!s.isDefault&&e.jsxs(He,{onClick:a,children:[e.jsx(pe,{className:"w-4 h-4 mr-2"}),"Set as default"]}),e.jsxs(He,{className:"text-destructive focus:text-destructive",onClick:t,disabled:r,children:[e.jsx(xs,{className:"w-4 h-4 mr-2"}),r?"Removing...":"Remove account"]})]})]})]}),h&&e.jsx("div",{className:"pl-11",children:g?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(z,{className:"w-3 h-3 animate-spin"}),e.jsx("span",{children:"Loading quota..."})]}):u!==null?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:v?e.jsxs(e.Fragment,{children:[e.jsx(wt,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["Active · ",Ve(w)]})]}):w?e.jsxs(e.Fragment,{children:[e.jsx($e,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-muted-foreground",children:["Last used ",Ve(w)]})]}):e.jsxs(e.Fragment,{children:[e.jsx(bt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not used yet"})]})}),e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Bs,{value:Math.max(0,Math.min(100,u)),className:"h-2 flex-1",indicatorClassName:ea(u)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[u,"%"]})]})}),e.jsx(te,{side:"bottom",className:"max-w-xs",children:n&&e.jsx(Vs,{quota:n,resetTime:p})})]})})]}):n?.needsReauth?e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(G,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-amber-500/50 text-amber-600 dark:text-amber-400",children:[e.jsx(Ct,{className:"w-3 h-3"}),"Reauth"]})})}),e.jsx(te,{side:"bottom",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:n.error?.includes("No refresh token")?"No refresh token available. Remove and re-add account to fix.":n.error?.includes("refresh")||n.error?.includes("Invalid")?`Auto-refresh failed: ${n.error}`:`Token issue: ${n.error||"Re-authenticate required"}`})})]})}):n?.error||n&&!n.success?e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(G,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx(yt,{className:"w-3 h-3"}),"N/A"]})})}),e.jsx(te,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:n?.error||"Quota information unavailable"})})]})}):null})]})}function aa({selectedCount:s,onPauseSelected:a,onResumeSelected:t,onClearSelection:i,isPausing:r,isResuming:c}){if(s<1)return null;const o=r||c;return e.jsxs("div",{className:"flex items-center gap-3 p-2 bg-muted/50 rounded-lg border mt-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[s," selected"]}),e.jsx(S,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:i,disabled:o,children:"Clear"}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(S,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:a,disabled:o,children:[r?e.jsx(z,{className:"w-3 h-3 animate-spin"}):e.jsx(fe,{className:"w-3 h-3"}),"Pause Selected"]}),e.jsxs(S,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:t,disabled:o,children:[c?e.jsx(z,{className:"w-3 h-3 animate-spin"}):e.jsx(ms,{className:"w-3 h-3"}),"Resume Selected"]})]})]})}function na({accounts:s,onAddAccount:a,onSetDefault:t,onRemoveAccount:i,onPauseToggle:r,onSoloMode:c,onBulkPause:o,onBulkResume:h,isRemovingAccount:m,isPausingAccount:f,isSoloingAccount:j,isBulkPausing:x,isBulkResuming:n,privacyMode:g,showQuota:w,isKiro:v,kiroNoIncognito:u,onKiroNoIncognitoChange:p,kiroSettingsLoading:M}){const[I,D]=d.useState(new Set),R=d.useMemo(()=>new Set(s.map(P=>P.id)),[s]),C=d.useMemo(()=>new Set([...I].filter(P=>R.has(P))),[I,R]),O=!!(o&&h),T=C.size,A=s.length>0&&C.size===s.length,N=C.size>0&&C.size<s.length,k=d.useCallback(P=>{D(F=>{const $=new Set(F);return $.has(P)?$.delete(P):$.add(P),$})},[]),b=d.useCallback(()=>{D(new Set(s.map(P=>P.id)))},[s]),_=d.useCallback(()=>{D(new Set)},[]),q=d.useCallback(()=>{A?_():b()},[A,b,_]),K=d.useCallback(()=>{o&&C.size>0&&(o(Array.from(C)),D(new Set))},[o,C]),y=d.useCallback(()=>{h&&C.size>0&&(h(Array.from(C)),D(new Set))},[h,C]);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:[O&&s.length>0&&e.jsx(Zt,{checked:A,onCheckedChange:q,"aria-label":"Select all accounts",className:N?"data-[state=checked]:bg-primary/50":"",...N?{"data-state":"indeterminate"}:{}}),e.jsx(ne,{className:"w-4 h-4"}),"Accounts",s.length>0&&e.jsx(G,{variant:"secondary",className:"text-xs",children:s.length})]}),e.jsxs(S,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:a,children:[e.jsx(us,{className:"w-3 h-3"}),"Add"]})]}),O&&T>0&&e.jsx(aa,{selectedCount:T,onPauseSelected:K,onResumeSelected:y,onClearSelection:_,isPausing:!!x,isResuming:!!n}),s.length>0?e.jsx("div",{className:"space-y-2",children:s.map(P=>e.jsx(ta,{account:P,onSetDefault:()=>t(P.id),onRemove:()=>i(P.id),onPauseToggle:r?F=>r(P.id,F):void 0,onSoloMode:c?()=>c(P.id):void 0,isRemoving:m,isPausingAccount:f,isSoloingAccount:j,privacyMode:g,showQuota:w,selectable:O,selected:C.has(P.id),onSelectChange:()=>k(P.id)},P.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(ne,{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"})]}),v&&p&&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(ds,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Use incognito"})]}),e.jsx(hs,{checked:!u,onCheckedChange:P=>p(!P),disabled:M,className:"scale-90"})]})})]})}function ia({provider:s,catalog:a,savedPresets:t,currentModel:i,opusModel:r,sonnetModel:c,haikuModel:o,providerModels:h,extendedContextEnabled:m,onExtendedContextToggle:f,onApplyPreset:j,onUpdateEnvValue:x,onOpenCustomPreset:n,onDeletePreset:g,isDeletePending:w,accounts:v,onAddAccount:u,onSetDefault:p,onRemoveAccount:M,onPauseToggle:I,onSoloMode:D,onBulkPause:R,onBulkResume:C,isRemovingAccount:O,isPausingAccount:T,isSoloingAccount:A,isBulkPausing:N,isBulkResuming:k,privacyMode:b,isRemoteMode:_}){const q=s==="kiro",[K,y]=d.useState(!0),[P,F]=d.useState(!0),[$,Y]=d.useState(!1),l=d.useCallback(async()=>{if(q)try{F(!0);const W=(await de.config.get()).cliproxy;y(W?.kiro_no_incognito??!0)}catch{y(!0)}finally{F(!1)}},[q]),E=d.useCallback(async V=>{y(V),Y(!0);try{const W=await de.config.get(),he=W.cliproxy??{};await de.config.update({...W,cliproxy:{...he,kiro_no_incognito:V}})}catch{y(!V)}finally{Y(!1)}},[]);return d.useEffect(()=>{l()},[l]),e.jsx(ke,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(Yt,{catalog:a,savedPresets:t,currentModel:i,opusModel:r,sonnetModel:c,haikuModel:o,providerModels:h,provider:s,extendedContextEnabled:m,onExtendedContextToggle:f,onApplyPreset:j,onUpdateEnvValue:x,onOpenCustomPreset:n,onDeletePreset:g,isDeletePending:w}),e.jsx(Me,{}),e.jsx(na,{accounts:v,onAddAccount:u,onSetDefault:p,onRemoveAccount:M,onPauseToggle:I,onSoloMode:D,onBulkPause:R,onBulkResume:C,isRemovingAccount:O,isPausingAccount:T,isSoloingAccount:A,isBulkPausing:N,isBulkResuming:k,privacyMode:b,showQuota:Qs.includes(s)&&!_,isKiro:q,kiroNoIncognito:K,onKiroNoIncognitoChange:E,kiroSettingsLoading:P||$})]})})}function Qe({provider:s,displayName:a,authStatus:t,catalog:i,logoProvider:r,baseProvider:c,isRemoteMode:o,port:h,onAddAccount:m,onSetDefault:f,onRemoveAccount:j,onPauseToggle:x,onSoloMode:n,onBulkPause:g,onBulkResume:w,isRemovingAccount:v,isPausingAccount:u,isSoloingAccount:p,isBulkPausing:M,isBulkResuming:I}){const[D,R]=d.useState(!1),{privacyMode:C}=as(),{data:O}=Js(),{data:T}=Ws(s),A=Xs(),N=Ys(),k=T?.presets||[],b=c||s,_=d.useMemo(()=>{if(!O?.models)return[];const Q={gemini:["google"],agy:["antigravity"],codex:["openai"],qwen:["alibaba","qwen"],iflow:["iflow"],kiro:["kiro","aws"],ghcp:["github","copilot"]}[b.toLowerCase()]||[b.toLowerCase()];return O.models.filter(Le=>Q.some(As=>Le.owned_by.toLowerCase().includes(As)))},[O,b]),{data:q,isLoading:K,refetch:y,rawJsonContent:P,rawJsonEdits:F,isRawJsonValid:$,hasChanges:Y,currentModel:l,opusModel:E,sonnetModel:V,haikuModel:W,extendedContextEnabled:he,toggleExtendedContext:fs,handleRawJsonChange:js,updateEnvValue:vs,updateEnvValues:De,saveMutation:Re,conflictDialog:Ns,handleConflictResolve:_e,missingRequiredFields:ws}=$t(s),bs=t.accounts||[],{data:Cs}=Je({queryKey:["auth-tokens-raw"],queryFn:async()=>{const H=await fetch("/api/settings/auth/tokens/raw");return H.ok?H.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),Ie=Cs?.apiKey?.value??"ccs-internal-managed",ys=H=>{De({ANTHROPIC_BASE_URL:`http://127.0.0.1:${h??je}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:Ie,...H}),L.success(`Applied "${H.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},ks=(H,Q)=>{De({ANTHROPIC_BASE_URL:`http://127.0.0.1:${h??je}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:Ie,ANTHROPIC_MODEL:H.default,ANTHROPIC_DEFAULT_OPUS_MODEL:H.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:H.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:H.haiku}),L.success(`Applied ${Q?`"${Q}"`:"custom"} preset`),R(!1)},Ss=(H,Q)=>{if(!Q){L.error("Please enter a preset name to save");return}A.mutate({profile:s,data:{name:Q,...H}}),R(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Wt,{provider:s,displayName:a,logoProvider:r,data:q,isLoading:K,hasChanges:Y,isRawJsonValid:$,isSaving:Re.isPending,isRemoteMode:o,port:h,onRefetch:y,onSave:()=>Re.mutate()}),K?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(z,{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(Zs,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(et,{className:"w-full",children:[e.jsx(Ke,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(Ke,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(Ge,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(ia,{provider:s,catalog:i,savedPresets:k,currentModel:l,opusModel:E,sonnetModel:V,haikuModel:W,providerModels:_,extendedContextEnabled:he,onExtendedContextToggle:fs,onApplyPreset:ys,onUpdateEnvValue:vs,onOpenCustomPreset:()=>R(!0),onDeletePreset:H=>N.mutate({profile:s,name:H}),isDeletePending:N.isPending,accounts:bs,onAddAccount:m,onSetDefault:f,onRemoveAccount:j,onPauseToggle:x,onSoloMode:n,onBulkPause:g,onBulkResume:w,isRemovingAccount:v,isPausingAccount:u,isSoloingAccount:p,isBulkPausing:M,isBulkResuming:I,privacyMode:C,isRemoteMode:o})}),e.jsx(Ge,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(Bt,{provider:s,displayName:a,data:q,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(kt,{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(st,{rawJsonContent:P,isRawJsonValid:$,rawJsonEdits:F,onRawJsonChange:js,profileEnv:q?.settings?.env,missingRequiredFields:ws})]})]}),e.jsx(St,{open:Ns,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>_e(!0),onCancel:()=>_e(!1)}),e.jsx(zt,{open:D,onClose:()=>R(!1),currentValues:{default:l||"",opus:E||"",sonnet:V||"",haiku:W||""},onApply:ks,onSave:Ss,isSaving:A.isPending,catalog:i,allModels:_})]})}function ra({status:s,isSelected:a,onSelect:t}){const i=s.accounts?.length||0;return e.jsxs("button",{className:U("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(Ee,{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}),i>0&&e.jsx(G,{variant:"secondary",className:"text-[10px] h-4 px-1",children:i})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:s.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(B,{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(Pe,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not connected"})]})})]})]})}function oa({variant:s,parentAuth:a,isSelected:t,onSelect:i,onDelete:r,isDeleting:c}){return e.jsxs("button",{className:U("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:i,children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ee,{provider:s.provider,size:"sm"}),e.jsx(ps,{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(G,{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(B,{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(Pe,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Parent not connected"})]})})]}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:o=>{o.stopPropagation(),r()},disabled:c,children:e.jsx(xs,{className:"w-3 h-3"})})]})}function la({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(le,{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(S,{onClick:s,className:"gap-2",children:[e.jsx(oe,{className:"w-4 h-4"}),"Quick Setup"]})]})})}function ba(){const s=Ne(),{data:a,isLoading:t}=ts(),{data:i,isFetching:r}=tt(),{data:c}=at(),o=nt(),h=it(),m=rt(),f=ot(),j=lt(),x=ct(),n=dt(),g=ut(),[w,v]=d.useState(()=>typeof window<"u"?localStorage.getItem("cliproxy-selected-provider"):null),[u,p]=d.useState(null),[M,I]=d.useState(!1),[D,R]=d.useState(null),C=d.useMemo(()=>a?.authStatus||[],[a?.authStatus]),O=a?.source==="remote",T=d.useMemo(()=>i?.variants||[],[i?.variants]),A=l=>{v(l),l&&localStorage.setItem("cliproxy-selected-provider",l)},N=d.useMemo(()=>u?null:w&&C.some(l=>l.provider===w)?w:C.length>0&&(C.find(E=>(E.accounts?.length||0)>0)?.provider||C[0]?.provider)||null,[w,u,C]),k=C.find(l=>l.provider===N),b=T.find(l=>l.name===u),_=b?C.find(l=>l.provider===b.provider):void 0,q=()=>{s.invalidateQueries({queryKey:["cliproxy"]}),s.invalidateQueries({queryKey:["cliproxy-auth"]})},K=(l,E,V)=>{m.isPending||f.isPending||(V?m.mutate({provider:l,accountId:E}):f.mutate({provider:l,accountId:E}))},y=(l,E)=>{j.isPending||j.mutate({provider:l,accountId:E})},P=(l,E)=>{x.isPending||x.mutate({provider:l,accountIds:E})},F=(l,E)=>{n.isPending||n.mutate({provider:l,accountIds:E})},$=l=>{A(l),p(null)},Y=l=>{p(l),A(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(le,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:c?.backendLabel??"CLIProxy"})]}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:q,disabled:r,children:e.jsx(Ae,{className:U("w-4 h-4",r&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"CCS-level account management"}),e.jsxs(S,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>I(!0),children:[e.jsx(oe,{className:"w-4 h-4"}),"Quick Setup"]})]}),e.jsx(ke,{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(l=>e.jsx(mt,{className:"h-14 w-full rounded-lg"},l))}):e.jsx("div",{className:"space-y-1",children:C.map(l=>e.jsx(ra,{status:l,isSelected:N===l.provider,onSelect:()=>$(l.provider)},l.provider))}),T.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(ps,{className:"w-3 h-3"}),"Variants"]}),e.jsx("div",{className:"space-y-1",children:T.map(l=>e.jsx(oa,{variant:l,parentAuth:C.find(E=>E.provider===l.provider),isSelected:u===l.name,onSelect:()=>Y(l.name),onDelete:()=>g.mutate(l.name),isDeleting:g.isPending},l.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(At,{})}),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:[C.length," provider",C.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(B,{className:"w-3 h-3 text-green-600"}),C.filter(l=>l.authenticated).length," connected"]})]})})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:b&&_?e.jsx(Qe,{provider:b.name,displayName:`${b.name} (${b.provider} variant)`,authStatus:_,catalog:re[b.provider],logoProvider:b.provider,baseProvider:b.provider,isRemoteMode:O,port:b.port,onAddAccount:()=>R({provider:b.provider,displayName:_.displayName,isFirstAccount:(_.accounts?.length||0)===0}),onSetDefault:l=>o.mutate({provider:b.provider,accountId:l}),onRemoveAccount:l=>h.mutate({provider:b.provider,accountId:l}),onPauseToggle:(l,E)=>K(b.provider,l,E),onSoloMode:l=>y(b.provider,l),onBulkPause:l=>P(b.provider,l),onBulkResume:l=>F(b.provider,l),isRemovingAccount:h.isPending,isPausingAccount:m.isPending||f.isPending,isSoloingAccount:j.isPending,isBulkPausing:x.isPending,isBulkResuming:n.isPending}):k?e.jsx(Qe,{provider:k.provider,displayName:k.displayName,authStatus:k,catalog:re[k.provider],isRemoteMode:O,onAddAccount:()=>R({provider:k.provider,displayName:k.displayName,isFirstAccount:(k.accounts?.length||0)===0}),onSetDefault:l=>o.mutate({provider:k.provider,accountId:l}),onRemoveAccount:l=>h.mutate({provider:k.provider,accountId:l}),onPauseToggle:(l,E)=>K(k.provider,l,E),onSoloMode:l=>y(k.provider,l),onBulkPause:l=>P(k.provider,l),onBulkResume:l=>F(k.provider,l),isRemovingAccount:h.isPending,isPausingAccount:m.isPending||f.isPending,isSoloingAccount:j.isPending,isBulkPausing:x.isPending,isBulkResuming:n.isPending}):e.jsx(la,{onSetup:()=>I(!0)})}),e.jsx(_t,{open:M,onClose:()=>I(!1)}),e.jsx(Ut,{open:D!==null,onClose:()=>R(null),provider:D?.provider||"",displayName:D?.displayName||"",isFirstAccount:D?.isFirstAccount||!1})]})}export{ba as CliproxyPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-qEZD5MMp.js";import{r as c}from"./react-vendor-CNOkPC89.js";import{aQ as N,aR as C,aS as w,aN as y,aP as G,m as S,b,I as p}from"./index-Cr6iEc8x.js";import{S as k}from"./switch-D6XSRTo_.js";import{R as j,a1 as R,q as A,ag as L,$ as V}from"./icons-D5eAI-GR.js";import"./tanstack-De4wvi8X.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-C-pVd1--.js";import"./code-highlight-BRUf_pqB.js";function _(){const{state:s}=N(),a=C(),[l,d]=c.useState(""),[m,v]=c.useState(""),u=c.useCallback(async()=>{try{a.setGlobalEnvLoading(!0),a.setGlobalEnvError(null);const t=await fetch("/api/global-env");if(!t.ok)throw new Error("Failed to load Global Env config");const o=await t.json();a.setGlobalEnvConfig(o)}catch(t){a.setGlobalEnvError(t.message)}finally{a.setGlobalEnvLoading(!1)}},[a]),i=c.useCallback(async t=>{const o=s.globalEnvConfig;if(!o)return;const x={...o,...t};a.setGlobalEnvConfig(x);try{a.setGlobalEnvSaving(!0),a.setGlobalEnvError(null);const r=await fetch("/api/global-env",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!r.ok){const n=await r.json();throw new Error(n.error||"Failed to save")}const h=await r.json();a.setGlobalEnvConfig(h.config),a.setGlobalEnvSuccess(!0),setTimeout(()=>a.setGlobalEnvSuccess(!1),1500)}catch(r){a.setGlobalEnvConfig(o),a.setGlobalEnvError(r.message)}finally{a.setGlobalEnvSaving(!1)}},[s.globalEnvConfig,a]),f=c.useCallback(()=>{if(!l.trim()||!s.globalEnvConfig)return;const t={...s.globalEnvConfig.env,[l.trim()]:m};i({env:t}),d(""),v("")},[l,m,s.globalEnvConfig,i]),g=c.useCallback(t=>{if(!s.globalEnvConfig)return;const o={...s.globalEnvConfig.env};delete o[t],i({env:o})},[s.globalEnvConfig,i]);return{config:s.globalEnvConfig,loading:s.globalEnvLoading,saving:s.globalEnvSaving,error:s.globalEnvError,success:s.globalEnvSuccess,newEnvKey:l,setNewEnvKey:d,newEnvValue:m,setNewEnvValue:v,fetchConfig:u,saveConfig:i,addEnvVar:f,removeEnvVar:g}}function F(){const{config:s,loading:a,saving:l,error:d,success:m,newEnvKey:v,setNewEnvKey:u,newEnvValue:i,setNewEnvValue:f,fetchConfig:g,saveConfig:t,addEnvVar:o,removeEnvVar:x}=_(),{fetchRawConfig:r}=w();c.useEffect(()=>{g(),r()},[g,r]);const h=()=>{t({enabled:!s?.enabled})};return a?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(j,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${d||m?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[d&&e.jsxs(y,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(R,{className:"h-4 w-4"}),e.jsx(G,{children:d})]}),m&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(A,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(S,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Environment variables injected into all non-Claude subscription profiles (gemini, codex, agy, ghcp, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s?.enabled?"Global Env enabled":"Global Env disabled"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s?.enabled?"Env vars will be injected into third-party profiles":"Env vars will not be injected"})]}),e.jsx(k,{checked:s?.enabled??!0,onCheckedChange:h})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Environment Variables"}),s?.env&&Object.keys(s.env).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(s.env).map(([n,E])=>e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg border bg-background",children:[e.jsx("code",{className:"flex-1 font-mono text-sm truncate",children:n}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("code",{className:"font-mono text-sm px-2 py-1 bg-muted rounded",children:E}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>x(n),disabled:l,className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(L,{className:"w-4 h-4"})})]},n))}):e.jsx("div",{className:"p-4 rounded-lg border border-dashed text-center text-muted-foreground",children:e.jsx("p",{children:"No environment variables configured"})}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Add New Variable"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{value:v,onChange:n=>u(n.target.value.toUpperCase()),placeholder:"KEY_NAME",className:"flex-1 font-mono text-sm h-9",disabled:l}),e.jsx("span",{className:"flex items-center text-muted-foreground",children:"="}),e.jsx(p,{value:i,onChange:n=>f(n.target.value),placeholder:"value",className:"flex-1 font-mono text-sm h-9",disabled:l}),e.jsxs(b,{size:"sm",onClick:o,disabled:l||!v.trim(),className:"h-9",children:[e.jsx(V,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Quick Add Common Variables"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[[{key:"DISABLE_BUG_COMMAND",value:"1"},{key:"DISABLE_ERROR_REPORTING",value:"1"},{key:"DISABLE_TELEMETRY",value:"1"}].map(({key:n,value:E})=>!s?.env?.[n]&&e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>{u(n),f(E)},className:"text-xs font-mono",children:["+ ",n]},n)),s?.env&&["DISABLE_BUG_COMMAND","DISABLE_ERROR_REPORTING","DISABLE_TELEMETRY"].every(n=>s.env[n])&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"All common variables are configured"})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>{g(),r()},disabled:a||l,className:"w-full",children:[e.jsx(j,{className:`w-4 h-4 mr-2 ${a?"animate-spin":""}`}),"Refresh"]})})]})}export{F as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-qEZD5MMp.js";import{r as f,c as fe}from"./react-vendor-CNOkPC89.js";import{u as M,C as p,a as g,S as h,c as d,P as y,B as I,b as H,d as ee,e as pe,f as se,g as ge,h as te,i as N,j as S,k as je,l as Ne,m as ye,n as be}from"./index-Cr6iEc8x.js";import{N as we,a9 as ae,aa as z,ab as re,D as ne,a0 as ve,G as ke,ac as Ce,R as $e,y as Q,U as Se,Z as le,p as De,a4 as G,ad as Le,x as Te,b as Fe,ae as Re,af as Me}from"./icons-D5eAI-GR.js";import{a as Pe,u as P}from"./tanstack-De4wvi8X.js";import{K as L,L as Y,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-BBPXh0Ar.js";import"./notifications-B2HqRBj7.js";import"./form-utils-C-pVd1--.js";import"./code-highlight-BRUf_pqB.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 n=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),r=s?.totalCost?Math.round(n/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:`$${n.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,l)=>{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)})})]})})},l)})})}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:n,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:n}}),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"),n=String(s.getDate()).padStart(2,"0");return`${t}${a}${n}`}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),D(`/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),D(`/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)),D(`/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),D(`/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()),D(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),D(`/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:()=>D("/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),D(`/usage/insights?${t}`)}};async function D(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 n=await a.json();return n.data||n}function Ye(s){return P({queryKey:["usage","summary",s],queryFn:()=>T.summary(s),staleTime:60*1e3})}function Qe(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:L(new Date,30),to:new Date}),[a,n]=f.useState(!1),[r,i]=f.useState(null),[o,l]=f.useState(null),[c,x]=f.useState("daily"),u=Xe(),m=f.useCallback(async()=>{n(!0);try{await u()}finally{n(!1)}},[u]),j=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:b,isLoading:v}=Ye(j),{data:C,isLoading:$}=Qe(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:L(F,1),to:F}),x("hourly")},[]),de=f.useCallback(F=>{t(F),x("daily")},[]),xe=f.useMemo(()=>K?.lastFetch?Y(new Date(K.lastFetch),{addSuffix:!0}):null,[K?.lastFetch]),ue=f.useCallback((F,he)=>{const E=he.currentTarget.getBoundingClientRect();l({x:E.left+E.width/2,y:E.top+E.height/2}),i(F)},[]),me=f.useCallback(()=>{i(null),l(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:L(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:L(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:L(new Date,90),to:new Date}}],className:n}){const[r,i]=fe.useState(!1),o=l=>!s||!s.from||!s.to||!l.from||!l.to?!1:k(s.from,"yyyy-MM-dd")===k(l.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(l.to,"yyyy-MM-dd");return e.jsxs("div",{className:d("flex items-center gap-2",n),children:[a.map(l=>e.jsx(H,{variant:o(l.range)?"default":"outline",size:"sm",onClick:()=>t(l.range),children:l.label},l.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:n,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:L(new Date,7),to:new Date}},{label:"30D",range:{from:L(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:n,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:n}){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",n)});if(!s||s.length===0)return e.jsx("div",{className:d("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const o=({x:l,y:c,payload:x,isRight:u})=>{const m=u?`$${x.value}`:X(Number(x.value));return e.jsx("text",{x:l,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",n),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:l=>e.jsx(o,{...l,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:l=>e.jsx(o,{...l,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(oe,{content:({active:l,payload:c,label:x})=>{if(!l||!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[n,r]=s.split(" ");if(n&&r){const i=new Date(`${n}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:n}=M(),r=f.useMemo(()=>!s||s.length===0?[]:s.map(l=>({name:l.model,value:l.tokens,cost:l.cost,percentage:l.percentage,fill:te(l.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:l,payload:c})=>{if(!l||!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",n&&y),children:[is(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:d("text-muted-foreground",n&&y),children:["$",u.cost.toFixed(4)]})]})},o=l=>l.percentage>5?`${l.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((l,c)=>e.jsx(Ke,{fill:l.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(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return a[a.length-1]||""}function cs({data:s,isLoading:t,className:a}){const{privacyMode:n}=M(),r=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,o=s.total,l=i.reduce((b,v)=>b+(v.inputTokens+v.outputTokens),0),c=Math.round(l/i.length),u=i.reduce((b,v)=>b+v.cost,0)/i.length,m=i[0],j=m?Y(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(Q,{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",n&&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(De,{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:os(i.projectPath)}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Y(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:d("text-right shrink-0 ml-2",n&&y),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[ds(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(Q,{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 ds(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 xs({className:s,isLoading:t}){const{data:a,isLoading:n}=je(),{data:r,isLoading:i,error:o}=Ne(a?.running);if(t||n||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(Le,{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=us(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 us(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 ms(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 hs({models:s,isLoading:t,onModelClick:a,privacyMode:n}){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(fs,{model:r}),e.jsx("span",{className:d("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&y),children:ms(r.tokens)}),e.jsxs("span",{className:d("font-mono font-medium w-16 text-right shrink-0",n&&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(ps,{})]})})]})}function fs({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=n=>s.cost>0?n/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 ps(){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:n})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:d("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function gs({viewMode:s,trends:t,hourlyData:a,models:n,sessions:r,isTrendsLoading:i,isHourlyLoading:o,isModelsLoading:l,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(hs,{models:n,isLoading:l,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:n||[],isLoading:l,className:"h-full w-full"})})]}),e.jsx(cs,{data:r,isLoading:c,className:"lg:col-span-2"}),e.jsx(xs,{isLoading:x,className:"lg:col-span-2"})]})]})}function Ds(){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 Ls(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:n,handleRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:l,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:n,onRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:l}),e.jsx(Ee,{data:c,isLoading:x}),e.jsx(gs,{viewMode:l,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{Ls as AnalyticsPage,Ds as AnalyticsSkeleton};
|