@kaitranntt/ccs 7.26.0 → 7.26.1-dev.2

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.
Files changed (104) hide show
  1. package/config/base-glm.settings.json +4 -4
  2. package/config/base-glmt.settings.json +4 -4
  3. package/dist/ccs.js +3 -1
  4. package/dist/ccs.js.map +1 -1
  5. package/dist/cliproxy/auth/oauth-process.js +1 -1
  6. package/dist/cliproxy/auth/oauth-process.js.map +1 -1
  7. package/dist/cliproxy/binary/extractor.d.ts +2 -2
  8. package/dist/cliproxy/binary/extractor.d.ts.map +1 -1
  9. package/dist/cliproxy/binary/extractor.js +4 -3
  10. package/dist/cliproxy/binary/extractor.js.map +1 -1
  11. package/dist/cliproxy/binary/index.d.ts +1 -1
  12. package/dist/cliproxy/binary/index.d.ts.map +1 -1
  13. package/dist/cliproxy/binary/index.js +2 -1
  14. package/dist/cliproxy/binary/index.js.map +1 -1
  15. package/dist/cliproxy/binary/installer.d.ts +5 -4
  16. package/dist/cliproxy/binary/installer.d.ts.map +1 -1
  17. package/dist/cliproxy/binary/installer.js +29 -17
  18. package/dist/cliproxy/binary/installer.js.map +1 -1
  19. package/dist/cliproxy/binary/lifecycle.d.ts.map +1 -1
  20. package/dist/cliproxy/binary/lifecycle.js +11 -8
  21. package/dist/cliproxy/binary/lifecycle.js.map +1 -1
  22. package/dist/cliproxy/binary/tar-extractor.d.ts +2 -1
  23. package/dist/cliproxy/binary/tar-extractor.d.ts.map +1 -1
  24. package/dist/cliproxy/binary/tar-extractor.js +3 -3
  25. package/dist/cliproxy/binary/tar-extractor.js.map +1 -1
  26. package/dist/cliproxy/binary/types.d.ts +14 -2
  27. package/dist/cliproxy/binary/types.d.ts.map +1 -1
  28. package/dist/cliproxy/binary/types.js +19 -3
  29. package/dist/cliproxy/binary/types.js.map +1 -1
  30. package/dist/cliproxy/binary/version-cache.d.ts +28 -22
  31. package/dist/cliproxy/binary/version-cache.d.ts.map +1 -1
  32. package/dist/cliproxy/binary/version-cache.js +57 -34
  33. package/dist/cliproxy/binary/version-cache.js.map +1 -1
  34. package/dist/cliproxy/binary/version-checker.d.ts +9 -3
  35. package/dist/cliproxy/binary/version-checker.d.ts.map +1 -1
  36. package/dist/cliproxy/binary/version-checker.js +21 -14
  37. package/dist/cliproxy/binary/version-checker.js.map +1 -1
  38. package/dist/cliproxy/binary/zip-extractor.d.ts +2 -1
  39. package/dist/cliproxy/binary/zip-extractor.d.ts.map +1 -1
  40. package/dist/cliproxy/binary/zip-extractor.js +3 -3
  41. package/dist/cliproxy/binary/zip-extractor.js.map +1 -1
  42. package/dist/cliproxy/binary-manager.d.ts +9 -7
  43. package/dist/cliproxy/binary-manager.d.ts.map +1 -1
  44. package/dist/cliproxy/binary-manager.js +28 -20
  45. package/dist/cliproxy/binary-manager.js.map +1 -1
  46. package/dist/cliproxy/cliproxy-executor.d.ts.map +1 -1
  47. package/dist/cliproxy/cliproxy-executor.js +5 -4
  48. package/dist/cliproxy/cliproxy-executor.js.map +1 -1
  49. package/dist/cliproxy/service-manager.d.ts.map +1 -1
  50. package/dist/cliproxy/service-manager.js +6 -1
  51. package/dist/cliproxy/service-manager.js.map +1 -1
  52. package/dist/cliproxy/services/binary-service.d.ts +6 -6
  53. package/dist/cliproxy/services/binary-service.d.ts.map +1 -1
  54. package/dist/cliproxy/services/binary-service.js +54 -22
  55. package/dist/cliproxy/services/binary-service.js.map +1 -1
  56. package/dist/cliproxy/session-tracker.d.ts +4 -1
  57. package/dist/cliproxy/session-tracker.d.ts.map +1 -1
  58. package/dist/cliproxy/session-tracker.js +3 -1
  59. package/dist/cliproxy/session-tracker.js.map +1 -1
  60. package/dist/cliproxy/types.d.ts +2 -0
  61. package/dist/cliproxy/types.d.ts.map +1 -1
  62. package/dist/cliproxy/types.js.map +1 -1
  63. package/dist/commands/cliproxy-command.d.ts.map +1 -1
  64. package/dist/commands/cliproxy-command.js +25 -15
  65. package/dist/commands/cliproxy-command.js.map +1 -1
  66. package/dist/config/unified-config-loader.d.ts.map +1 -1
  67. package/dist/config/unified-config-loader.js +4 -0
  68. package/dist/config/unified-config-loader.js.map +1 -1
  69. package/dist/glmt/glmt-transformer.js +2 -2
  70. package/dist/glmt/pipeline/response-builder.js +1 -1
  71. package/dist/ui/assets/{accounts-DmDtOjgI.js → accounts-ClRO9xRe.js} +1 -1
  72. package/dist/ui/assets/{alert-dialog-BRQuLTE0.js → alert-dialog-DFi20Kyu.js} +1 -1
  73. package/dist/ui/assets/{api-D8s9_3Vf.js → api-BpnXG9Bg.js} +1 -1
  74. package/dist/ui/assets/auth-section-Dvxm2fKF.js +1 -0
  75. package/dist/ui/assets/{backups-section-CD8WE3jo.js → backups-section-DRZ3sdMb.js} +1 -1
  76. package/dist/ui/assets/cliproxy-DfCPAvnX.js +3 -0
  77. package/dist/ui/assets/{cliproxy-control-panel-CL1taFji.js → cliproxy-control-panel-TVrFXe7F.js} +1 -1
  78. package/dist/ui/assets/{confirm-dialog-BrDkVCMB.js → confirm-dialog-DRaXid8b.js} +1 -1
  79. package/dist/ui/assets/{copilot-CeZzCZ47.js → copilot-CxS7F-wF.js} +3 -3
  80. package/dist/ui/assets/{globalenv-section-CU9L9qj2.js → globalenv-section-BAdk876f.js} +1 -1
  81. package/dist/ui/assets/{health-CxRN4wo5.js → health-DtEewGXR.js} +1 -1
  82. package/dist/ui/assets/{icons-TP-W6wBb.js → icons-MT_USDDP.js} +1 -1
  83. package/dist/ui/assets/index-9iuiv2P7.js +1 -0
  84. package/dist/ui/assets/{index-5ld5FlA0.js → index-Bqpm7XFW.js} +14 -14
  85. package/dist/ui/assets/{index-B8SMrsmS.js → index-BxW8t4Z6.js} +1 -1
  86. package/dist/ui/assets/{index-BjlrUl8j.css → index-CRayOc33.css} +1 -1
  87. package/dist/ui/assets/index-CWHCl8iV.js +1 -0
  88. package/dist/ui/assets/{index-DoymmWw8.js → index-CtbouR3A.js} +1 -1
  89. package/dist/ui/assets/proxy-status-widget-DNGPVCQ7.js +1 -0
  90. package/dist/ui/assets/{shared-XYu0X19W.js → shared-Axa1XCh5.js} +1 -1
  91. package/dist/ui/assets/{switch-BUYlYaJx.js → switch-D7uSKm8B.js} +1 -1
  92. package/dist/ui/assets/{tanstack-C1q4365B.js → tanstack-ChZysrI1.js} +2 -2
  93. package/dist/ui/index.html +4 -4
  94. package/dist/web-server/routes/cliproxy-stats-routes.d.ts.map +1 -1
  95. package/dist/web-server/routes/cliproxy-stats-routes.js +14 -2
  96. package/dist/web-server/routes/cliproxy-stats-routes.js.map +1 -1
  97. package/dist/web-server/routes/proxy-routes.d.ts.map +1 -1
  98. package/dist/web-server/routes/proxy-routes.js +3 -2
  99. package/dist/web-server/routes/proxy-routes.js.map +1 -1
  100. package/package.json +1 -1
  101. package/dist/ui/assets/auth-section-6c47NtRw.js +0 -1
  102. package/dist/ui/assets/cliproxy-B8mhLLOW.js +0 -3
  103. package/dist/ui/assets/index-5SlpA5l0.js +0 -1
  104. package/dist/ui/assets/index-74OuxlYT.js +0 -1
@@ -12,6 +12,7 @@ const express_1 = require("express");
12
12
  const unified_config_loader_1 = require("../../config/unified-config-loader");
13
13
  const remote_proxy_client_1 = require("../../cliproxy/remote-proxy-client");
14
14
  const proxy_lifecycle_service_1 = require("../../cliproxy/services/proxy-lifecycle-service");
15
+ const platform_detector_1 = require("../../cliproxy/platform-detector");
15
16
  const unified_config_types_1 = require("../../config/unified-config-types");
16
17
  const router = (0, express_1.Router)();
17
18
  /**
@@ -67,7 +68,7 @@ router.put('/', async (req, res) => {
67
68
  router.get('/backend', async (_req, res) => {
68
69
  try {
69
70
  const config = await (0, unified_config_loader_1.loadOrCreateUnifiedConfig)();
70
- res.json({ backend: config.cliproxy?.backend ?? 'plus' });
71
+ res.json({ backend: config.cliproxy?.backend ?? platform_detector_1.DEFAULT_BACKEND });
71
72
  }
72
73
  catch (error) {
73
74
  console.error('[cliproxy-server-routes] Failed to load backend config:', error);
@@ -92,7 +93,7 @@ router.put('/backend', async (req, res) => {
92
93
  }
93
94
  // Check if proxy is running - warn about restart requirement
94
95
  const config = await (0, unified_config_loader_1.loadOrCreateUnifiedConfig)();
95
- const currentBackend = config.cliproxy?.backend ?? 'plus';
96
+ const currentBackend = config.cliproxy?.backend ?? platform_detector_1.DEFAULT_BACKEND;
96
97
  if (currentBackend !== backend && (0, proxy_lifecycle_service_1.isProxyRunning)() && !force) {
97
98
  res.status(409).json({
98
99
  error: 'Proxy is running. Stop proxy first or use force=true to change backend.',
@@ -1 +1 @@
1
- {"version":3,"file":"proxy-routes.js","sourceRoot":"","sources":["../../../src/web-server/routes/proxy-routes.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"proxy-routes.js","sourceRoot":"","sources":["../../../src/web-server/routes/proxy-routes.ts"],"names":[],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaitranntt/ccs",
3
- "version": "7.26.0",
3
+ "version": "7.26.1-dev.2",
4
4
  "description": "Claude Code Switch - Instant profile switching between Claude Sonnet 4.5 and GLM 4.6",
5
5
  "keywords": [
6
6
  "cli",
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-DP8--cuX.js";import{r as t}from"./react-vendor-CNOkPC89.js";import{aQ as Q,aL as _,aN as H,m as V,I as b,b as i}from"./index-5ld5FlA0.js";import{a5 as E,$ as W,p as X,k as Y,E as K,d as A,j as T,l as I,aI as Z,_ as ee,R as se,ag as ae}from"./icons-TP-W6wBb.js";import"./tanstack-C1q4365B.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-C-pVd1--.js";import"./code-highlight-BRUf_pqB.js";function ue(){const{fetchRawConfig:o}=Q(),[a,P]=t.useState(null),[g,v]=t.useState(!0),[n,c]=t.useState(!1),[x,r]=t.useState(null),[p,f]=t.useState(null),[y,R]=t.useState(!1),[j,L]=t.useState(!1),[d,w]=t.useState(null),[m,N]=t.useState(null),[z,C]=t.useState(!1),[U,k]=t.useState(!1),u=t.useCallback(async()=>{try{v(!0),r(null);const s=await fetch("/api/settings/auth/tokens/raw");if(!s.ok)throw new Error("Failed to fetch auth tokens");const l=await s.json();P(l)}catch(s){r(s instanceof Error?s.message:"Unknown error")}finally{v(!1)}},[]);t.useEffect(()=>{u(),o()},[u,o]),t.useEffect(()=>{if(p){const s=setTimeout(()=>f(null),3e3);return()=>clearTimeout(s)}},[p]),t.useEffect(()=>{if(x){const s=setTimeout(()=>r(null),5e3);return()=>clearTimeout(s)}},[x]);const F=async()=>{const s=d!==null&&d!==a?.apiKey.value,l=m!==null&&m!==a?.managementSecret.value;if(!(!s&&!l))try{c(!0),r(null);const h={};s&&(h.apiKey=d),l&&(h.managementSecret=m);const S=await fetch("/api/settings/auth/tokens",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)});if(!S.ok){const J=await S.json();throw new Error(J.error||"Failed to save tokens")}f("Tokens updated. Restart CLIProxy to apply."),w(null),N(null),await u(),await o()}catch(h){r(h instanceof Error?h.message:"Unknown error")}finally{c(!1)}},O=async()=>{try{c(!0),r(null);const s=await fetch("/api/settings/auth/tokens/regenerate-secret",{method:"POST"});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to regenerate secret")}f("New management secret generated. Restart CLIProxy to apply."),await u(),await o()}catch(s){r(s instanceof Error?s.message:"Unknown error")}finally{c(!1)}},$=async()=>{try{c(!0),r(null);const s=await fetch("/api/settings/auth/tokens/reset",{method:"POST"});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to reset tokens")}f("Tokens reset to defaults. Restart CLIProxy to apply."),w(null),N(null),await u(),await o()}catch(s){r(s instanceof Error?s.message:"Unknown error")}finally{c(!1)}},D=async()=>{a&&(await navigator.clipboard.writeText(a.apiKey.value),C(!0),setTimeout(()=>C(!1),2e3))},M=async()=>{a&&(await navigator.clipboard.writeText(a.managementSecret.value),k(!0),setTimeout(()=>k(!1),2e3))};if(g||!a)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(E,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const q=d??a.apiKey.value,B=m??a.managementSecret.value,G=d!==null&&d!==a.apiKey.value||m!==null&&m!==a.managementSecret.value;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${x||p?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[x&&e.jsxs(_,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(W,{className:"h-4 w-4"}),e.jsx(H,{children:x})]}),p&&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(X,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:p})]})]}),e.jsx(V,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure CLIProxy authentication tokens. Changes require CLIProxy restart."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:"API Key"}),a.apiKey.isCustom&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/50 dark:text-amber-300",children:"Custom"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used by Claude Code to authenticate with CLIProxy"}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(b,{type:y?"text":"password",value:q,onChange:s=>w(s.target.value),placeholder:"API key",disabled:n,className:"pr-20 font-mono text-sm"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:[e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>R(!y),children:y?e.jsx(K,{className:"w-4 h-4"}):e.jsx(A,{className:"w-4 h-4"})}),e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:D,disabled:!a.apiKey.value,children:z?e.jsx(T,{className:"w-4 h-4 text-green-600"}):e.jsx(I,{className:"w-4 h-4"})})]})]})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:"Management Secret"}),a.managementSecret.isCustom&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/50 dark:text-amber-300",children:"Custom"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used by CCS dashboard to access CLIProxy management APIs"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(b,{type:j?"text":"password",value:B,onChange:s=>N(s.target.value),placeholder:"Management secret",disabled:n,className:"pr-20 font-mono text-sm"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:[e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>L(!j),children:j?e.jsx(K,{className:"w-4 h-4"}):e.jsx(A,{className:"w-4 h-4"})}),e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:M,disabled:!a.managementSecret.value,children:U?e.jsx(T,{className:"w-4 h-4 text-green-600"}):e.jsx(I,{className:"w-4 h-4"})})]})]}),e.jsx(i,{variant:"outline",size:"sm",onClick:O,disabled:n,title:"Generate new secure secret",children:e.jsx(ee,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(i,{variant:"outline",size:"sm",onClick:$,disabled:n||!a.apiKey.isCustom&&!a.managementSecret.isCustom,className:"gap-2",children:[e.jsx(se,{className:"w-4 h-4"}),"Reset to Defaults"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Resets both API key and management secret to their default values."})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background flex gap-2",children:[e.jsxs(i,{variant:"outline",size:"sm",onClick:()=>{u(),o()},disabled:g||n,className:"flex-1",children:[e.jsx(E,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),"Refresh"]}),e.jsxs(i,{variant:"default",size:"sm",onClick:F,disabled:!G||n,className:"flex-1",children:[e.jsx(ae,{className:`w-4 h-4 mr-2 ${n?"animate-pulse":""}`}),n?"Saving...":"Save"]})]})]})}export{ue as default};
@@ -1,3 +0,0 @@
1
- import{j as e}from"./radix-ui-DP8--cuX.js";import{r as p}from"./react-vendor-CNOkPC89.js";import{u as Qe,a as fe,b as fs}from"./tanstack-C1q4365B.js";import{b as w,C as Be,a as Je,c as T,P as ae,L as ne,I as je,X as ve,Y as Ne,Z as we,_ as be,$ as ie,a0 as We,a1 as js,a2 as Ye,a3 as Xe,u as Ze,a4 as ye,a5 as Ce,a6 as ke,a7 as Ae,a8 as es,a9 as vs,aa as Fe,ab as Ue,B as _,ac as Ns,q as ss,m as Se,l as ws,ad as bs,ae as ys,af as Cs,ag as B,T as J,o as W,p as Y,ah as ks,ai as As,aj as Ss,ak as de,al as Ps,am as Ms,an as Ts,ao as se,ap as Ds,aq as Os,ar as Is,as as Es,H as _s,J as Ls,K as He,M as Ve,at as Rs,au as Fs,av as Us,aw as Hs,ax as Vs,ay as Gs,az as Ks,aA as $s,E as qs,G as zs,aB as Qs,aC as Bs,aD as Js,aE as Ws,aF as Ys,aG as Xs,S as Zs}from"./index-5ld5FlA0.js";import{t as F}from"./notifications-B2HqRBj7.js";import{b as ts,L as q,m as Pe,w as et,j as z,l as st,am as Me,a5 as $,n as Q,_ as Z,an as as,ao as re,Z as oe,I as tt,f as at,a0 as Te,ap as nt,ag as it,X as le,Y as ns,t as Ge,aq as rt,T as pe,s as te,ar as ot,as as lt,af as is,p as ct,at as dt,$ as mt,aj as ut,A as xt,au as pt,av as ht,S as gt,aw as Ke,ax as ft,ay as jt,U as vt,az as rs}from"./icons-TP-W6wBb.js";import{S as De,C as Nt}from"./confirm-dialog-BrDkVCMB.js";import{S as wt}from"./switch-BUYlYaJx.js";import{A as bt,a as yt,b as Ct,c as kt,d as At,e as St,f as Pt,g as Mt}from"./alert-dialog-BRQuLTE0.js";import"./utils-CzKF5WmX.js";import"./form-utils-C-pVd1--.js";import"./code-highlight-BRUf_pqB.js";const X={agy:{provider:"agy",displayName:"Antigravity",defaultModel:"gemini-claude-opus-4-5-thinking",models:[{id:"gemini-claude-opus-4-5-thinking",name:"Claude Opus 4.5 Thinking",description:"Most capable, extended thinking",presetMapping:{default:"gemini-claude-opus-4-5-thinking",opus:"gemini-claude-opus-4-5-thinking",sonnet:"gemini-claude-sonnet-4-5-thinking",haiku:"gemini-claude-sonnet-4-5"}},{id:"gemini-claude-sonnet-4-5-thinking",name:"Claude Sonnet 4.5 Thinking",description:"Balanced with extended thinking",presetMapping:{default:"gemini-claude-sonnet-4-5-thinking",opus:"gemini-claude-opus-4-5-thinking",sonnet:"gemini-claude-sonnet-4-5-thinking",haiku:"gemini-claude-sonnet-4-5"}},{id:"gemini-claude-sonnet-4-5",name:"Claude Sonnet 4.5",description:"Fast and capable",presetMapping:{default:"gemini-claude-sonnet-4-5",opus:"gemini-claude-opus-4-5-thinking",sonnet:"gemini-claude-sonnet-4-5",haiku:"gemini-claude-sonnet-4-5"}},{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",description:"Google latest model via Antigravity",presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",description:"Fast Gemini model via Antigravity",presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}}]},gemini:{provider:"gemini",displayName:"Gemini",defaultModel:"gemini-2.5-pro",models:[{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",tier:"paid",description:"Latest model, requires paid Google account",presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",tier:"paid",description:"Fast Gemini 3 model, requires paid Google account",presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro",description:"Stable, works with free Google account",presetMapping:{default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-2.5-flash"}}]},codex:{provider:"codex",displayName:"Codex",defaultModel:"gpt-5.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:"qwen-coder-plus",models:[{id:"qwen-coder-plus",name:"Qwen Coder Plus",description:"Alibaba code-focused model"},{id:"qwen-max",name:"Qwen Max",description:"Most capable Qwen model"}]},iflow:{provider:"iflow",displayName:"iFlow",defaultModel:"iflow-default",models:[{id:"iflow-default",name:"iFlow Default",description:"Default iFlow model"}]},kiro:{provider:"kiro",displayName:"Kiro (AWS)",defaultModel:"kiro-claude-sonnet-4-5",models:[{id:"kiro-claude-opus-4-5",name:"Kiro Claude Opus 4.5",description:"Claude Opus 4.5 via Kiro (2.2x credit)",presetMapping:{default:"kiro-claude-opus-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4-5",name:"Kiro Claude Sonnet 4.5",description:"Claude Sonnet 4.5 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4",name:"Kiro Claude Sonnet 4",description:"Claude Sonnet 4 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-haiku-4-5",name:"Kiro Claude Haiku 4.5",description:"Claude Haiku 4.5 via Kiro (0.4x credit)"}]},ghcp:{provider:"ghcp",displayName:"GitHub Copilot (OAuth)",defaultModel:"claude-sonnet-4.5",models:[{id:"claude-opus-4.5",name:"Claude Opus 4.5",description:"Anthropic Claude Opus 4.5 via GitHub Copilot",presetMapping:{default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4.5",name:"Claude Sonnet 4.5",description:"Anthropic Claude Sonnet 4.5 via GitHub Copilot",presetMapping:{default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4",name:"Claude Sonnet 4",description:"Anthropic Claude Sonnet 4 via GitHub Copilot"},{id:"claude-haiku-4.5",name:"Claude Haiku 4.5",description:"Anthropic Claude Haiku 4.5 via GitHub Copilot"},{id:"gpt-5.2",name:"GPT-5.2",description:"OpenAI GPT-5.2 via GitHub Copilot",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"}},{id:"gpt-5.1",name:"GPT-5.1",description:"OpenAI GPT-5.1 via GitHub Copilot"},{id:"gpt-5",name:"GPT-5",description:"OpenAI GPT-5 via GitHub Copilot"},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"OpenAI GPT-5 Mini via GitHub Copilot"},{id:"gemini-3-pro",name:"Gemini 3 Pro",description:"Google Gemini 3 Pro via GitHub Copilot"}]}},he=8317,me="ccs-internal-managed";async function Tt(){try{const s=await fetch("/api/settings/auth/tokens/raw");return s.ok?(await s.json())?.apiKey?.value??me:me}catch{return me}}async function ge(s,n){const t=X[s];if(!t)return{success:!1};const a=t.models[0],i=a?.presetMapping||{default:t.defaultModel,opus:t.defaultModel,sonnet:t.defaultModel,haiku:t.defaultModel},l=await Tt(),u={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${he}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:l,ANTHROPIC_MODEL:i.default,ANTHROPIC_DEFAULT_OPUS_MODEL:i.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:i.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:i.haiku}};try{return{success:(await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:u})})).ok,presetName:a?.name||t.defaultModel}}catch{return{success:!1}}}const $e=[{id:"gemini",name:"Google Gemini",description:"Gemini Pro/Flash models"},{id:"codex",name:"OpenAI Codex",description:"GPT-4 and codex models"},{id:"agy",name:"Antigravity",description:"Antigravity AI models"},{id:"qwen",name:"Alibaba Qwen",description:"Qwen Code models"},{id:"iflow",name:"iFlow",description:"iFlow AI models"},{id:"kiro",name:"Kiro (AWS)",description:"AWS CodeWhisperer models"},{id:"ghcp",name:"GitHub Copilot (OAuth)",description:"GitHub Copilot via OAuth"}],os=["provider","auth","variant","success"];function Dt(s){return s==="account"?1:os.indexOf(s)}function Ot({currentProgress:s,allSteps:n}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:n.map((t,a)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${s>=a?"bg-primary":"bg-muted"}`},t))})}function It({providers:s,onSelect:n}){return e.jsx("div",{className:"grid gap-2",children:s.map(t=>e.jsxs("button",{onClick:()=>n(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(ts,{className:"w-4 h-4 text-muted-foreground"})]},t.id))})}function Et({selectedProvider:s,providers:n,authCommand:t,isRefreshing:a,isPending:i,onBack:l,onStartAuth:c,onRefresh:u}){const[r,d]=p.useState(!1),h=async x=>{await navigator.clipboard.writeText(x),d(!0),setTimeout(()=>d(!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 ",n.find(x=>x.id===s)?.name," to add an account"]}),e.jsx(w,{onClick:c,disabled:i,className:"w-full gap-2",size:"lg",children:i?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{className:"w-4 h-4"}),"Authenticate in Browser"]})}),i&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Complete the OAuth flow in your browser..."})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or use terminal"})})]}),e.jsx(Be,{children:e.jsxs(Je,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(et,{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(w,{variant:"outline",size:"icon",onClick:()=>h(t),children:r?e.jsx(z,{className:"w-4 h-4 text-green-500"}):e.jsx(st,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(w,{variant:"ghost",onClick:l,disabled:i,children:[e.jsx(Me,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(w,{variant:"outline",onClick:u,disabled:a||i,children:[e.jsx($,{className:`w-4 h-4 mr-2 ${a?"animate-spin":""}`}),a?"Checking...":"Refresh Status"]})]})]})}function _t({accounts:s,privacyMode:n,onSelect:t,onAddNew:a,onBack:i}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Select an account (",s.length,")"]}),e.jsx("div",{className:"grid gap-2",children:s.map(l=>e.jsxs("button",{type:"button",onClick:()=>t(l),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(Q,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:T("font-medium",n&&ae),children:l.email||l.id}),l.isDefault&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Default account"})]})]}),e.jsx(ts,{className:"w-4 h-4 text-muted-foreground"})]},l.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:a,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(Pe,{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(w,{variant:"ghost",onClick:i,children:[e.jsx(Me,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}function Lt({selectedProvider:s,selectedAccount:n,variantName:t,modelName:a,isPending:i,privacyMode:l,onVariantNameChange:c,onModelChange:u,onBack:r,onSkip:d,onCreate:h}){return e.jsxs("div",{className:"space-y-4",children:[n&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx(Q,{className:"w-4 h-4"}),e.jsxs("span",{children:["Using:"," ",e.jsx("span",{className:T(l&&ae),children:n.email||n.id})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"variant-name",children:"Variant Name *"}),e.jsx(je,{id:"variant-name",value:t,onChange:x=>c(x.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(ne,{children:"Model"}),e.jsxs(ve,{value:a,onValueChange:u,children:[e.jsx(Ne,{children:e.jsx(we,{placeholder:"Select a model"})}),e.jsx(be,{children:X[s]?.models.map(x=>e.jsx(ie,{value:x.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:x.name}),x.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",x.description]})]})},x.id))})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Default: ",X[s]?.defaultModel||"provider default"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(w,{variant:"ghost",onClick:r,children:[e.jsx(Me,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{variant:"ghost",onClick:d,children:"Skip"}),e.jsx(w,{onClick:h,disabled:!t||i,children:i?"Creating...":"Create Variant"})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:"Skip if you just wanted to add an account without creating a variant"})]})}function Rt({variantName:s,onClose:n}){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(z,{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(Be,{children:e.jsxs(Je,{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(w,{onClick:n,className:"w-full",children:"Done"})]})}function Ft({open:s,onClose:n}){const[t,a]=p.useState("provider"),[i,l]=p.useState(""),[c,u]=p.useState(null),[r,d]=p.useState(""),[h,x]=p.useState(""),[g,o]=p.useState(!1),[b,A]=p.useState(!1),{data:v,refetch:O}=We(),k=js(),D=Ye(),P=Xe(),{privacyMode:L}=Ze(),y=v?.authStatus.find(N=>N.provider===i),j=p.useMemo(()=>y?.accounts||[],[y?.accounts]);p.useEffect(()=>{if(!s){const N=setTimeout(()=>{a("provider"),l(""),u(null),d(""),x(""),A(!1)},0);return()=>clearTimeout(N)}},[s]),p.useEffect(()=>{if(t==="auth"&&j.length>0&&!b){const N=setTimeout(()=>{a("account")},0);return()=>clearTimeout(N)}},[t,j,b]);const f=async()=>{o(!0),await O(),o(!1)},S=()=>{const N=(y?.accounts?.length||0)===0;D.mutate({provider:i},{onSuccess:async H=>{if(N){const V=await ge(i);V.success&&V.presetName?F.success(`Applied "${V.presetName}" preset`):V.success||F.warning("Account added, but failed to apply default preset")}H.account&&(u(H.account),a("variant")),O()}})},I=N=>{l(N),(v?.authStatus.find(ce=>ce.provider===N)?.accounts||[]).length===0?a("auth"):a("account")},R=N=>{u(N),a("variant")},U=async()=>{if(!(!r||!i))try{await k.mutateAsync({name:r,provider:i,model:h||void 0,account:c?.id}),a("success")}catch(N){console.error("Failed to create variant:",N)}},m=`ccs ${i} --auth --add`,C=Dt(t),M=N=>{if(!N&&(D.isPending&&i&&P.mutate(i),t==="success"||t==="provider")){n();return}};return e.jsx(ye,{open:s,onOpenChange:M,children:e.jsxs(Ce,{className:"sm:max-w-lg",onPointerDownOutside:N=>{t!=="success"&&t!=="provider"&&N.preventDefault()},onEscapeKeyDown:N=>{(D.isPending||k.isPending)&&N.preventDefault()},children:[e.jsxs(ke,{children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs(es,{children:[t==="provider"&&"Select a provider to get started",t==="auth"&&"Authenticate with your provider",t==="account"&&"Select which account to use",t==="variant"&&"Create your custom variant",t==="success"&&"Setup complete!"]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[t==="provider"&&e.jsx(It,{providers:$e,onSelect:I}),t==="auth"&&e.jsx(Et,{selectedProvider:i,providers:$e,authCommand:m,isRefreshing:g,isPending:D.isPending,onBack:()=>a("provider"),onStartAuth:S,onRefresh:f}),t==="account"&&e.jsx(_t,{accounts:j,privacyMode:L,onSelect:R,onAddNew:()=>{A(!0),a("auth")},onBack:()=>a("provider")}),t==="variant"&&e.jsx(Lt,{selectedProvider:i,selectedAccount:c,variantName:r,modelName:h,isPending:k.isPending,privacyMode:L,onVariantNameChange:d,onModelChange:x,onBack:()=>j.length>0?a("account"):a("provider"),onSkip:n,onCreate:U}),t==="success"&&e.jsx(Rt,{variantName:r,onClose:n})]}),e.jsx(Ot,{currentProgress:C,allSteps:os})]})})}function Ut({open:s,onClose:n,provider:t,displayName:a,isFirstAccount:i=!1}){const[l,c]=p.useState(""),u=Ye(),r=vs(),d=Xe(),h=t==="kiro",x=u.isPending||r.isPending,g=()=>{x&&d.mutate(t),c(""),n()},o=()=>{u.mutate({provider:t,nickname:l.trim()||void 0},{onSuccess:async()=>{const v=await ge(t);v.success&&v.presetName?i&&F.success(`Applied "${v.presetName}" preset`):v.success||F.warning("Account added, but failed to apply default preset. You may need to configure settings manually."),c(""),n()}})},b=()=>{r.mutate(void 0,{onSuccess:async()=>{const v=await ge("kiro");v.success&&v.presetName&&i&&F.success(`Applied "${v.presetName}" preset`),c(""),n()}})},A=v=>{v||g()};return e.jsx(ye,{open:s,onOpenChange:A,children:e.jsxs(Ce,{className:"sm:max-w-md",children:[e.jsxs(ke,{children:[e.jsxs(Ae,{children:["Add ",a," Account"]}),e.jsx(es,{children:h?"Authenticate via browser or import an existing token from Kiro IDE.":"Click the button below to authenticate a new account. A browser window will open for OAuth."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"nickname",children:"Nickname (optional)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(je,{id:"nickname",value:l,onChange:v=>c(v.target.value),placeholder:"e.g., work, personal",disabled:x,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"A friendly name to identify this account. Auto-generated from email if left empty."})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(w,{variant:"ghost",onClick:g,children:"Cancel"}),h&&e.jsx(w,{variant:"outline",onClick:b,disabled:x,children:r.isPending?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 mr-2 animate-spin"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(as,{className:"w-4 h-4 mr-2"}),"Import from IDE"]})}),e.jsx(w,{onClick:o,disabled:x,children:u.isPending?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 mr-2 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{className:"w-4 h-4 mr-2"}),"Authenticate"]})})]}),u.isPending&&e.jsx("p",{className:"text-sm text-center text-muted-foreground",children:"Complete the OAuth flow in your browser..."}),r.isPending&&e.jsx("p",{className:"text-sm text-center text-muted-foreground",children:"Importing token from Kiro IDE..."})]})]})})}const Ht=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function Vt(s){const n=s?.env||{};return Ht.filter(t=>!n[t]?.trim())}function Gt(s){const[n,t]=p.useState(null),[a,i]=p.useState(!1),l=Qe(),{data:c,isLoading:u,refetch:r}=fe({queryKey:["settings",s],queryFn:async()=>{const f=await fetch(`/api/settings/${s}/raw`);return f.ok?f.json():{profile:s,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${s}/settings.json`}}}),d=c?.settings,h=p.useMemo(()=>n!==null?n:d?JSON.stringify(d,null,2):`{
2
- "env": {}
3
- }`,[n,d]),x=p.useCallback(f=>{t(f)},[]),g=p.useMemo(()=>{try{return JSON.parse(h)}catch{return d||{env:{}}}},[h,d]),o=g?.env?.ANTHROPIC_MODEL,b=g?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,A=g?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,v=g?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,O=p.useCallback((f,S)=>{const I={...g?.env||{},[f]:S},R={...g,env:I};t(JSON.stringify(R,null,2))},[g]),k=p.useCallback(f=>{const S={...g?.env||{},...f},I={...g,env:S};t(JSON.stringify(I,null,2))},[g]),D=p.useMemo(()=>{try{return JSON.parse(h),!0}catch{return!1}},[h]),P=p.useMemo(()=>n===null?!1:n!==JSON.stringify(d,null,2),[n,d]),L=p.useMemo(()=>Vt(g),[g]),y=fs({mutationFn:async()=>{const f=JSON.parse(h),S=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:f,expectedMtime:c?.mtime})});if(S.status===409)throw new Error("CONFLICT");if(!S.ok)throw new Error("Failed to save");return S.json()},onSuccess:f=>{l.invalidateQueries({queryKey:["settings",s]}),t(null),f?.warning?F.success("Settings saved",{description:f.warning}):F.success("Settings saved")},onError:f=>{f.message==="CONFLICT"?i(!0):F.error(f.message)}}),j=async f=>{i(!1),f?(await r(),y.mutate()):t(null)};return{data:c,isLoading:u,refetch:r,rawJsonContent:h,rawJsonEdits:n,isRawJsonValid:D,hasChanges:P,currentSettings:g,currentModel:o,opusModel:b,sonnetModel:A,haikuModel:v,handleRawJsonChange:x,updateEnvValue:O,updateEnvValues:k,saveMutation:{mutate:()=>y.mutate(),isPending:y.isPending},conflictDialog:a,setConflictDialog:i,handleConflictResolve:j,missingRequiredFields:L}}function K({label:s,description:n,value:t,onChange:a,catalog:i,allModels:l,disabled:c}){const u=new Set(i?.models.map(r=>r.id)||[]);return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:s}),n&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:n})]}),e.jsxs(ve,{value:t||"",onValueChange:a,disabled:c,children:[e.jsx(Ne,{className:"h-9",children:e.jsx(we,{placeholder:"Select model",children:t&&e.jsx("span",{className:"truncate font-mono text-xs",children:t})})}),e.jsxs(be,{className:"max-h-[300px]",children:[i&&i.models.length>0&&e.jsxs(Fe,{children:[e.jsx(Ue,{className:"text-xs text-primary",children:"Recommended"}),i.models.map(r=>e.jsx(ie,{value:r.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.id}),r.tier==="paid"&&e.jsx(_,{variant:"outline",className:"text-[9px] h-4 px-1",children:"PAID"}),t===r.id&&e.jsx(z,{className:"w-3 h-3 text-primary ml-auto"})]})},r.id))]}),l.length>0&&e.jsxs(Fe,{children:[e.jsxs(Ue,{className:"text-xs text-muted-foreground",children:["All Models (",l.length,")"]}),l.filter(r=>!u.has(r.id)).map(r=>e.jsx(ie,{value:r.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.id}),t===r.id&&e.jsx(z,{className:"w-3 h-3 text-primary ml-auto"})]})},r.id))]}),(!i||i.models.length===0)&&l.length===0&&e.jsx("div",{className:"py-2 px-3 text-xs text-muted-foreground",children:"No models available"})]})]})]})}function Kt({open:s,onClose:n,currentValues:t,onApply:a,onSave:i,isSaving:l,catalog:c,allModels:u}){const[r,d]=p.useState(t),[h,x]=p.useState(""),g=o=>{o?(d(t),x("")):n()};return e.jsx(ye,{open:s,onOpenChange:g,children:e.jsxs(Ce,{className:"sm:max-w-md",children:[e.jsx(ke,{children:e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(Z,{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(ne,{htmlFor:"preset-name",children:"Preset Name (optional)"}),e.jsx(je,{id:"preset-name",value:h,onChange:o=>x(o.target.value),placeholder:"e.g., My Custom Config",className:"text-sm"})]}),e.jsx(De,{}),e.jsx(K,{label:"Default Model",description:"Used when no specific tier is requested",value:r.default,onChange:o=>d({...r,default:o}),catalog:c,allModels:u}),e.jsx(K,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:r.opus,onChange:o=>d({...r,opus:o}),catalog:c,allModels:u}),e.jsx(K,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:r.sonnet,onChange:o=>d({...r,sonnet:o}),catalog:c,allModels:u}),e.jsx(K,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:r.haiku,onChange:o=>d({...r,haiku:o}),catalog:c,allModels:u})]}),e.jsxs(Ns,{className:"gap-2 sm:gap-0",children:[e.jsx(w,{variant:"outline",onClick:n,children:"Cancel"}),i&&e.jsxs(w,{variant:"secondary",onClick:()=>i(r,h||void 0),disabled:l||!h.trim(),children:[l?e.jsx(q,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(re,{className:"w-4 h-4 mr-1"}),"Save Preset"]}),e.jsxs(w,{onClick:()=>a(r,h||void 0),children:[e.jsx(oe,{className:"w-4 h-4 mr-1"}),"Apply Preset"]})]})]})})}function ee({label:s,command:n}){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:n}),e.jsx(ss,{value:n,size:"icon",className:"h-6 w-6"})]})]})}function $t({provider:s,displayName:n,data:t,authStatus:a}){return e.jsx(Se,{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(tt,{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:n})]}),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(ss,{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"}),a.authenticated?e.jsxs(_,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(at,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(_,{variant:"outline",className:"w-fit text-muted-foreground",children:"Not connected"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(ee,{label:"Run with prompt",command:`ccs ${s} "your prompt"`}),e.jsx(ee,{label:"Change model",command:`ccs ${s} --config`}),e.jsx(ee,{label:"Add account",command:`ccs ${s} --add`}),e.jsx(ee,{label:"List accounts",command:`ccs ${s} --accounts`})]})]})]})})}const qt={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"},zt={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"}},Qt={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 Oe({provider:s,className:n,size:t="md"}){const a=s.toLowerCase(),i=zt[a]||{text:"text-gray-600",letter:s[0]?.toUpperCase()||"?"},l=Qt[t],c=qt[a];return e.jsx("div",{className:T("flex items-center justify-center rounded-md",c&&"bg-white p-1",l.container,n),children:c?e.jsx("img",{src:c,alt:`${s} logo`,className:T(l.icon,"object-contain")}):e.jsx("span",{className:T("font-semibold",i.text,l.text),children:i.letter})})}function Bt({displayName:s,logoProvider:n,provider:t,data:a,isLoading:i,hasChanges:l,isRawJsonValid:c,isSaving:u,isRemoteMode:r,port:d,onRefetch:h,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(Oe,{provider:n||t,size:"lg"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),r&&e.jsxs(_,{variant:"secondary",className:"text-xs gap-1 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:[e.jsx(Te,{className:"w-3 h-3"}),"Remote"]}),d&&e.jsxs(_,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(nt,{className:"w-3 h-3"}),":",d]}),!r&&a?.path&&e.jsx(_,{variant:"outline",className:"text-xs",children:a.path.replace(/^.*[\\/]/,"")})]}),r?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):a&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(a.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{variant:"ghost",size:"sm",onClick:h,disabled:i,children:e.jsx($,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsx(w,{size:"sm",onClick:x,disabled:u||!l||!c,children:u?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(it,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Jt({catalog:s,savedPresets:n,currentModel:t,opusModel:a,sonnetModel:i,haikuModel:l,providerModels:c,onApplyPreset:u,onUpdateEnvValue:r,onOpenCustomPreset:d,onDeletePreset:h,isDeletePending:x}){const g=s&&s.models.length>0||n.length>0;return e.jsxs(e.Fragment,{children:[g&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Z,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Apply pre-configured model mappings"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s?.models.slice(0,4).map(o=>e.jsxs(w,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>{const b=o.presetMapping||{default:o.id,opus:o.id,sonnet:o.id,haiku:o.id};u({ANTHROPIC_MODEL:b.default,ANTHROPIC_DEFAULT_OPUS_MODEL:b.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:b.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:b.haiku})},children:[e.jsx(oe,{className:"w-3 h-3"}),o.name]},o.id)),n.map(o=>e.jsxs("div",{className:"group relative",children:[e.jsxs(w,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{u({ANTHROPIC_MODEL:o.default,ANTHROPIC_DEFAULT_OPUS_MODEL:o.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:o.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:o.haiku})},children:[e.jsx(re,{className:"w-3 h-3 fill-current"}),o.name]}),e.jsx(w,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:b=>{b.stopPropagation(),h(o.name)},disabled:x,children:e.jsx(le,{className:"w-3 h-3"})})]},o.name)),e.jsxs(w,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1 border-primary/50 text-primary hover:bg-primary/10 hover:border-primary",onClick:d,children:[e.jsx(ns,{className:"w-3 h-3"}),"Custom"]})]})]}),e.jsx(De,{}),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(K,{label:"Default Model",description:"Used when no specific tier is requested",value:t,onChange:o=>r("ANTHROPIC_MODEL",o),catalog:s,allModels:c}),e.jsx(K,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:a,onChange:o=>r("ANTHROPIC_DEFAULT_OPUS_MODEL",o),catalog:s,allModels:c}),e.jsx(K,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:i,onChange:o=>r("ANTHROPIC_DEFAULT_SONNET_MODEL",o),catalog:s,allModels:c}),e.jsx(K,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:l,onChange:o=>r("ANTHROPIC_DEFAULT_HAIKU_MODEL",o),catalog:s,allModels:c})]})]})]})}function Wt(s){const n=Math.max(0,Math.min(100,s));return n<=20?"bg-destructive":n<=50?"bg-yellow-500":"bg-green-500"}function qe(s){if(!s)return"";try{const n=new Date(s),a=new Date().getTime()-n.getTime();if(a<0)return"just now";const i=Math.floor(a/(1e3*60)),l=Math.floor(a/(1e3*60*60)),c=Math.floor(a/(1e3*60*60*24));return c>0?`${c}d ago`:l>0?`${l}h ago`:i>0?`${i}m ago`:"just now"}catch{return""}}function Yt(s){if(!s)return!1;try{const n=new Date(s);return new Date().getTime()-n.getTime()<3600*1e3}catch{return!1}}function Xt({account:s,onSetDefault:n,onRemove:t,onPauseToggle:a,isRemoving:i,isPausingAccount:l,privacyMode:c,showQuota:u}){const{data:r}=ws(u),{data:d,isLoading:h}=bs(s.provider,s.id,u),x=r?.accountStats?.[s.email||s.id]?.lastUsedAt,g=Yt(x),o=d?.success?ys(d.models):null,b=d?.success&&d.models.length>0?Cs(d.models):null;return e.jsxs("div",{className:T("flex flex-col gap-2 p-3 rounded-lg border transition-colors",s.isDefault?"border-primary/30 bg-primary/5":"border-border hover:bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:T("flex items-center justify-center w-8 h-8 rounded-full",s.isDefault?"bg-primary/10":"bg-muted"),children:e.jsx(Q,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:T("font-medium text-sm",c&&ae),children:s.email||s.id}),s.isDefault&&e.jsxs(_,{variant:"secondary",className:"text-[10px] h-4 px-1.5 gap-0.5",children:[e.jsx(re,{className:"w-2.5 h-2.5 fill-current"}),"Default"]}),s.tier&&s.tier!=="unknown"&&e.jsx(_,{variant:"outline",className:T("text-[10px] h-4 px-1.5 uppercase",s.tier==="paid"&&"border-blue-500 text-blue-600",s.tier==="free"&&"border-gray-400 text-gray-500"),children:s.tier}),s.paused&&e.jsxs(_,{variant:"outline",className:"text-[10px] h-4 px-1.5 border-yellow-500 text-yellow-600",children:[e.jsx(Ge,{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(B,{children:e.jsxs(J,{children:[e.jsx(W,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(rt,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:T("font-mono max-w-[180px] truncate",c&&ae),title:s.projectId,children:s.projectId})]})}),e.jsx(Y,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"GCP Project ID (read-only)"})})]})}):e.jsx(B,{children:e.jsxs(J,{children:[e.jsx(W,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(pe,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:"Project ID: N/A"})]})}),e.jsx(Y,{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(te,{className:"w-3 h-3"}),"Last used: ",new Date(s.lastUsedAt).toLocaleDateString()]})]})]}),e.jsxs(ks,{children:[e.jsx(As,{asChild:!0,children:e.jsx(w,{variant:"ghost",size:"icon",className:"h-7 w-7",children:e.jsx(ot,{className:"w-4 h-4"})})}),e.jsxs(Ss,{align:"end",children:[!s.isDefault&&e.jsxs(de,{onClick:n,children:[e.jsx(re,{className:"w-4 h-4 mr-2"}),"Set as default"]}),a&&e.jsx(de,{onClick:()=>a(!s.paused),disabled:l,children:s.paused?e.jsxs(e.Fragment,{children:[e.jsx(lt,{className:"w-4 h-4 mr-2"}),l?"Resuming...":"Resume account"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{className:"w-4 h-4 mr-2"}),l?"Pausing...":"Pause account"]})}),e.jsxs(de,{className:"text-destructive focus:text-destructive",onClick:t,disabled:i,children:[e.jsx(is,{className:"w-4 h-4 mr-2"}),i?"Removing...":"Remove account"]})]})]})]}),u&&e.jsx("div",{className:"pl-11",children:h?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(q,{className:"w-3 h-3 animate-spin"}),e.jsx("span",{children:"Loading quota..."})]}):o!==null?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:g?e.jsxs(e.Fragment,{children:[e.jsx(ct,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["Active · ",qe(x)]})]}):x?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-muted-foreground",children:["Last used ",qe(x)]})]}):e.jsxs(e.Fragment,{children:[e.jsx(dt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not used yet"})]})}),e.jsx(B,{children:e.jsxs(J,{children:[e.jsx(W,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ps,{value:Math.max(0,Math.min(100,o)),className:"h-2 flex-1",indicatorClassName:Wt(o)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[o,"%"]})]})}),e.jsx(Y,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium",children:"Model Quotas:"}),Ms(d?.models||[]).map(A=>e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{className:"truncate",children:A.displayName||A.name}),e.jsxs("span",{className:"font-mono",children:[A.percentage,"%"]})]},A.name)),b&&e.jsxs("div",{className:"flex items-center gap-1.5 mt-2 pt-2 border-t border-border/50",children:[e.jsx(te,{className:"w-3 h-3 text-blue-400"}),e.jsxs("span",{className:"text-blue-400 font-medium",children:["Resets ",Ts(b)]})]})]})})]})})]}):d?.error||d&&!d.success?e.jsx(B,{children:e.jsxs(J,{children:[e.jsx(W,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(_,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx(mt,{className:"w-3 h-3"}),"N/A"]})})}),e.jsx(Y,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:d?.error||"Quota information unavailable"})})]})}):null})]})}function Zt({accounts:s,onAddAccount:n,onSetDefault:t,onRemoveAccount:a,onPauseToggle:i,isRemovingAccount:l,isPausingAccount:c,privacyMode:u,showQuota:r,isKiro:d,kiroNoIncognito:h,onKiroNoIncognitoChange:x,kiroSettingsLoading:g}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Accounts",s.length>0&&e.jsx(_,{variant:"secondary",className:"text-xs",children:s.length})]}),e.jsxs(w,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:n,children:[e.jsx(ns,{className:"w-3 h-3"}),"Add"]})]}),s.length>0?e.jsx("div",{className:"space-y-2",children:s.map(o=>e.jsx(Xt,{account:o,onSetDefault:()=>t(o.id),onRemove:()=>a(o.id),onPauseToggle:i?b=>i(o.id,b):void 0,isRemoving:l,isPausingAccount:c,privacyMode:u,showQuota:r},o.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(Q,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No accounts connected"}),e.jsx("p",{className:"text-xs opacity-70",children:"Add an account to get started"})]}),d&&x&&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(Te,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Use incognito"})]}),e.jsx(wt,{checked:!h,onCheckedChange:o=>x(!o),disabled:g,className:"scale-90"})]})})]})}function ea({provider:s,catalog:n,savedPresets:t,currentModel:a,opusModel:i,sonnetModel:l,haikuModel:c,providerModels:u,onApplyPreset:r,onUpdateEnvValue:d,onOpenCustomPreset:h,onDeletePreset:x,isDeletePending:g,accounts:o,onAddAccount:b,onSetDefault:A,onRemoveAccount:v,onPauseToggle:O,isRemovingAccount:k,isPausingAccount:D,privacyMode:P,isRemoteMode:L}){const y=s==="kiro",[j,f]=p.useState(!0),[S,I]=p.useState(!0),[R,U]=p.useState(!1),m=p.useCallback(async()=>{if(y)try{I(!0);const N=(await se.config.get()).cliproxy;f(N?.kiro_no_incognito??!0)}catch{f(!0)}finally{I(!1)}},[y]),C=p.useCallback(async M=>{f(M),U(!0);try{const N=await se.config.get(),H=N.cliproxy??{};await se.config.update({...N,cliproxy:{...H,kiro_no_incognito:M}})}catch{f(!M)}finally{U(!1)}},[]);return p.useEffect(()=>{m()},[m]),e.jsx(Se,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(Jt,{catalog:n,savedPresets:t,currentModel:a,opusModel:i,sonnetModel:l,haikuModel:c,providerModels:u,onApplyPreset:r,onUpdateEnvValue:d,onOpenCustomPreset:h,onDeletePreset:x,isDeletePending:g}),e.jsx(De,{}),e.jsx(Zt,{accounts:o,onAddAccount:b,onSetDefault:A,onRemoveAccount:v,onPauseToggle:O,isRemovingAccount:k,isPausingAccount:D,privacyMode:P,showQuota:s==="agy"&&!L,isKiro:y,kiroNoIncognito:j,onKiroNoIncognitoChange:C,kiroSettingsLoading:S||R})]})})}function ze({provider:s,displayName:n,authStatus:t,catalog:a,logoProvider:i,baseProvider:l,isRemoteMode:c,port:u,onAddAccount:r,onSetDefault:d,onRemoveAccount:h,onPauseToggle:x,isRemovingAccount:g,isPausingAccount:o}){const[b,A]=p.useState(!1),{privacyMode:v}=Ze(),{data:O}=Ds(),{data:k}=Os(s),D=Is(),P=Es(),L=k?.presets||[],y=l||s,j=p.useMemo(()=>{if(!O?.models)return[];const G={gemini:["google"],agy:["antigravity"],codex:["openai"],qwen:["alibaba","qwen"],iflow:["iflow"],kiro:["kiro","aws"],ghcp:["github","copilot"]}[y.toLowerCase()]||[y.toLowerCase()];return O.models.filter(Re=>G.some(gs=>Re.owned_by.toLowerCase().includes(gs)))},[O,y]),{data:f,isLoading:S,refetch:I,rawJsonContent:R,rawJsonEdits:U,isRawJsonValid:m,hasChanges:C,currentModel:M,opusModel:N,sonnetModel:H,haikuModel:V,handleRawJsonChange:ce,updateEnvValue:ls,updateEnvValues:Ie,saveMutation:Ee,conflictDialog:cs,handleConflictResolve:_e,missingRequiredFields:ds}=Gt(s),ms=t.accounts||[],{data:us}=fe({queryKey:["auth-tokens-raw"],queryFn:async()=>{const E=await fetch("/api/settings/auth/tokens/raw");return E.ok?E.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),Le=us?.apiKey?.value??"ccs-internal-managed",xs=E=>{Ie({ANTHROPIC_BASE_URL:`http://127.0.0.1:${u??he}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:Le,...E}),F.success(`Applied "${E.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},ps=(E,G)=>{Ie({ANTHROPIC_BASE_URL:`http://127.0.0.1:${u??he}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:Le,ANTHROPIC_MODEL:E.default,ANTHROPIC_DEFAULT_OPUS_MODEL:E.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:E.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:E.haiku}),F.success(`Applied ${G?`"${G}"`:"custom"} preset`),A(!1)},hs=(E,G)=>{if(!G){F.error("Please enter a preset name to save");return}D.mutate({profile:s,data:{name:G,...E}}),A(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Bt,{provider:s,displayName:n,logoProvider:i,data:f,isLoading:S,hasChanges:C,isRawJsonValid:m,isSaving:Ee.isPending,isRemoteMode:c,port:u,onRefetch:I,onSave:()=>Ee.mutate()}),S?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(q,{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(_s,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Ls,{className:"w-full",children:[e.jsx(He,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(He,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(Ve,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(ea,{provider:s,catalog:a,savedPresets:L,currentModel:M,opusModel:N,sonnetModel:H,haikuModel:V,providerModels:j,onApplyPreset:xs,onUpdateEnvValue:ls,onOpenCustomPreset:()=>A(!0),onDeletePreset:E=>P.mutate({profile:s,name:E}),isDeletePending:P.isPending,accounts:ms,onAddAccount:r,onSetDefault:d,onRemoveAccount:h,onPauseToggle:x,isRemovingAccount:g,isPausingAccount:o,privacyMode:v,isRemoteMode:c})}),e.jsx(Ve,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx($t,{provider:s,displayName:n,data:f,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(ut,{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(Rs,{rawJsonContent:R,isRawJsonValid:m,rawJsonEdits:U,onRawJsonChange:ce,profileEnv:f?.settings?.env,missingRequiredFields:ds})]})]}),e.jsx(Nt,{open:cs,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(Kt,{open:b,onClose:()=>A(!1),currentValues:{default:M||"",opus:N||"",sonnet:H||"",haiku:V||""},onApply:ps,onSave:hs,isSaving:D.isPending,catalog:a,allModels:j})]})}function ue(s,n){const t=s.replace(/-\d+$/,"").split(".").map(Number),a=n.replace(/-\d+$/,"").split(".").map(Number);for(let i=0;i<3;i++){if((t[i]||0)>(a[i]||0))return!0;if((t[i]||0)<(a[i]||0))return!1}return!1}function sa(s){if(!s)return"";const n=new Date(s).getTime(),a=Date.now()-n,i=Math.floor(a/(1e3*60*60)),l=Math.floor(a%(1e3*60*60)/(1e3*60));return i>0?`${i}h ${l}m`:`${l}m`}function ta(s){if(!s)return"";const n=Date.now()-s,t=Math.floor(n/(1e3*60)),a=Math.floor(n/(1e3*60*60));return t<1?"just now":t<60?`${t}m ago`:`${a}h ago`}function xe({icon:s,tooltip:n,onClick:t,disabled:a,isPending:i,className:l,variant:c="ghost"}){return e.jsxs(J,{children:[e.jsx(W,{asChild:!0,children:e.jsx(w,{variant:c==="destructive-ghost"?"ghost":c,size:"sm",className:T("h-7 w-7 p-0",c==="destructive-ghost"&&"hover:bg-destructive/10 hover:text-destructive hover:border-destructive/30",l),onClick:t,disabled:a,children:i?e.jsx($,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(s,{className:"w-3.5 h-3.5"})})}),e.jsx(Y,{side:"bottom",className:"text-xs",children:n})]})}function aa(){const{data:s,isLoading:n}=Fs(),{data:t}=Us(),{data:a,isLoading:i}=Hs(),l=Vs(),c=Gs(),u=Ks(),r=$s(),[d,h]=p.useState(!1),[x,g]=p.useState(""),[o,b]=p.useState(!1),[A,v]=p.useState(null),{data:O}=fe({queryKey:["cliproxy-server-config"],queryFn:()=>se.cliproxyServer.get(),staleTime:3e4}),k=O?.remote,D=k?.enabled&&k?.host,P=s?.running??!1,L=l.isPending||c.isPending||u.isPending||r.isPending,y=t?.hasUpdate??!1,j=t?.isStable===!1,f=t?.currentVersion,S=j?t?.maxStableVersion||a?.latestStable:t?.latestVersion,I=C=>{if(!C)return;const M=a?.maxStableVersion||"6.6.80";if(ue(C,M)){v(C),b(!0);return}r.mutate({version:C})},R=()=>{A&&r.mutate({version:A,force:!0}),b(!1),v(null)},U=()=>{b(!1),v(null)},m=D?(()=>{const C=k.protocol||"http",M=k.port||(C==="https"?443:80);return C==="https"&&M===443||C==="http"&&M===80?k.host:`${k.host}:${M}`})():null;return D?e.jsxs("div",{className:T("rounded-lg border p-3 transition-colors","border-blue-500/30 bg-blue-500/5"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Te,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium",children:"Remote Proxy"}),e.jsx(_,{variant:"secondary",className:"text-[10px] h-4 px-1.5 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:"Active"})]}),e.jsx(xt,{className:"w-3 h-3 text-blue-600"})]}),e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[e.jsx("div",{className:"flex items-center gap-1 mb-1",children:e.jsx("span",{className:"font-mono",children:m})}),e.jsx("p",{className:"text-[10px] text-muted-foreground/70 leading-tight",children:"Traffic auto-routed to remote server"})]})]}):e.jsx(B,{delayDuration:300,children:e.jsxs("div",{className:T("rounded-lg border p-3 transition-colors",P?"border-green-500/30 bg-green-500/5":"border-muted bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:T("w-2 h-2 rounded-full",P?"bg-green-500 animate-pulse":"bg-muted-foreground/30")}),e.jsx("span",{className:"text-sm font-medium",children:"CLIProxy Plus"})]}),e.jsx("div",{className:"flex items-center gap-1",children:n?e.jsx($,{className:"w-3 h-3 animate-spin text-muted-foreground"}):P?e.jsxs(e.Fragment,{children:[e.jsx(xe,{icon:pt,tooltip:"Restart",onClick:()=>u.mutate(),disabled:L,isPending:u.isPending}),e.jsx(xe,{icon:ht,tooltip:"Stop",onClick:()=>c.mutate(),disabled:L,isPending:c.isPending,variant:"destructive-ghost"}),e.jsx(xe,{icon:d?le:gt,tooltip:d?"Close":"Version settings",onClick:()=>h(!d),className:d?"bg-muted":void 0})]}):e.jsx(Ke,{className:"w-3 h-3 text-muted-foreground"})})]}),f&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[e.jsxs("span",{className:T("text-xs font-mono text-muted-foreground",j&&"text-amber-600 dark:text-amber-400"),children:["v",f]}),(y||j)&&S&&e.jsxs(_,{variant:"secondary",className:T("text-[10px] h-4 px-1.5 gap-0.5 cursor-pointer transition-colors",j?"bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-900/30 dark:text-amber-400 dark:hover:bg-amber-900/50":"bg-green-100 text-green-700 hover:bg-green-200 dark:bg-green-900/30 dark:text-green-400 dark:hover:bg-green-900/50"),onClick:()=>I(S),title:`Click to ${j?"downgrade":"update"}`,children:[j?e.jsx(ft,{className:"w-2.5 h-2.5"}):e.jsx(jt,{className:"w-2.5 h-2.5"}),S]})]}),P&&s&&e.jsxs("div",{className:"mt-2 flex items-center gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:["Port ",s.port]}),s.sessionCount!==void 0&&s.sessionCount>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(vt,{className:"w-3 h-3"}),s.sessionCount," session",s.sessionCount!==1?"s":""]}),s.startedAt&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(te,{className:"w-3 h-3"}),sa(s.startedAt)]})]}),P&&e.jsx(qs,{open:d,onOpenChange:h,children:e.jsxs(zs,{className:"mt-3 pt-3 border-t border-muted",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground mb-3",children:"Version Management"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ve,{value:x,onValueChange:g,disabled:i,children:[e.jsx(Ne,{className:"h-8 text-xs flex-1",children:e.jsx(we,{placeholder:"Select version to install..."})}),e.jsx(be,{children:a?.versions.slice(0,20).map(C=>{const M=a?.maxStableVersion&&ue(C,a.maxStableVersion);return e.jsx(ie,{value:C,className:"text-xs",children:e.jsxs("span",{className:"flex items-center gap-2",children:["v",C,C===a.latestStable&&e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"(stable)"}),M&&e.jsx("span",{className:"text-amber-600 dark:text-amber-400",children:"⚠"})]})},C)})})]}),e.jsxs(w,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1.5 px-3",onClick:()=>I(x),disabled:r.isPending||!x,children:[r.isPending?e.jsx($,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(as,{className:"w-3.5 h-3.5"}),"Install"]})]}),x&&a?.maxStableVersion&&ue(x,a.maxStableVersion)&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-amber-600 dark:text-amber-400",children:[e.jsx(pe,{className:"w-3.5 h-3.5 flex-shrink-0"}),e.jsxs("span",{children:["Versions above ",a.maxStableVersion," have known issues"]})]}),t?.checkedAt&&e.jsxs("div",{className:"mt-2 text-[10px] text-muted-foreground/60",children:["Last checked ",ta(t.checkedAt)]})]})}),!P&&e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not running"}),e.jsxs(w,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",onClick:()=>l.mutate(),disabled:l.isPending,children:[l.isPending?e.jsx($,{className:"w-3 h-3 animate-spin"}):e.jsx(Ke,{className:"w-3 h-3"}),"Start"]})]}),e.jsx(bt,{open:o,onOpenChange:b,children:e.jsxs(yt,{children:[e.jsxs(Ct,{children:[e.jsxs(kt,{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"w-5 h-5 text-amber-500"}),"Install Unstable Version?"]}),e.jsxs(At,{className:"space-y-2",children:[e.jsxs("p",{children:["You are about to install ",e.jsxs("strong",{children:["v",A]}),", which is above the maximum stable version"," ",e.jsxs("strong",{children:["v",a?.maxStableVersion||"6.6.80"]}),"."]}),e.jsx("p",{className:"text-amber-600 dark:text-amber-400",children:"This version has known stability issues and may cause unexpected behavior."}),e.jsx("p",{children:"Are you sure you want to proceed?"})]})]}),e.jsxs(St,{children:[e.jsx(Pt,{onClick:U,children:"Cancel"}),e.jsx(Mt,{onClick:R,className:"bg-amber-500 hover:bg-amber-600 text-white",children:"Install Anyway"})]})]})})]})})}function na({status:s,isSelected:n,onSelect:t}){const a=s.accounts?.length||0;return e.jsxs("button",{className:T("w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors cursor-pointer text-left",n?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:t,children:[e.jsx(Oe,{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}),a>0&&e.jsx(_,{variant:"secondary",className:"text-[10px] h-4 px-1",children:a})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:s.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(z,{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(le,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not connected"})]})})]})]})}function ia({variant:s,parentAuth:n,isSelected:t,onSelect:a,onDelete:i,isDeleting:l}){return e.jsxs("button",{className:T("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:a,children:[e.jsxs("div",{className:"relative",children:[e.jsx(Oe,{provider:s.provider,size:"sm"}),e.jsx(rs,{className:"w-2.5 h-2.5 absolute -bottom-0.5 -right-0.5 text-muted-foreground"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:s.name}),e.jsx(_,{variant:"outline",className:"text-[9px] h-4 px-1",children:"variant"})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:n?.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(z,{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(le,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Parent not connected"})]})})]}),e.jsx(w,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:c=>{c.stopPropagation(),i()},disabled:l,children:e.jsx(is,{className:"w-3 h-3"})})]})}function ra({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(oe,{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(w,{onClick:s,className:"gap-2",children:[e.jsx(Z,{className:"w-4 h-4"}),"Quick Setup"]})]})})}function va(){const s=Qe(),{data:n,isLoading:t}=We(),{data:a,isFetching:i}=Qs(),l=Bs(),c=Js(),u=Ws(),r=Ys(),d=Xs(),[h,x]=p.useState(null),[g,o]=p.useState(null),[b,A]=p.useState(!1),[v,O]=p.useState(null),k=p.useMemo(()=>n?.authStatus||[],[n?.authStatus]),D=n?.source==="remote",P=p.useMemo(()=>a?.variants||[],[a?.variants]),L=p.useMemo(()=>g?null:h&&k.some(m=>m.provider===h)?h:k.length>0?k[0].provider:null,[h,g,k]),y=k.find(m=>m.provider===L),j=P.find(m=>m.name===g),f=j?k.find(m=>m.provider===j.provider):void 0,S=()=>{s.invalidateQueries({queryKey:["cliproxy"]}),s.invalidateQueries({queryKey:["cliproxy-auth"]})},I=(m,C,M)=>{u.isPending||r.isPending||(M?u.mutate({provider:m,accountId:C}):r.mutate({provider:m,accountId:C}))},R=m=>{x(m),o(null)},U=m=>{o(m),x(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(oe,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"CLIProxy Plus"})]}),e.jsx(w,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:S,disabled:i,children:e.jsx($,{className:T("w-4 h-4",i&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"CCS-level account management"}),e.jsxs(w,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>A(!0),children:[e.jsx(Z,{className:"w-4 h-4"}),"Quick Setup"]})]}),e.jsx(Se,{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(m=>e.jsx(Zs,{className:"h-14 w-full rounded-lg"},m))}):e.jsx("div",{className:"space-y-1",children:k.map(m=>e.jsx(na,{status:m,isSelected:L===m.provider,onSelect:()=>R(m.provider)},m.provider))}),P.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(rs,{className:"w-3 h-3"}),"Variants"]}),e.jsx("div",{className:"space-y-1",children:P.map(m=>e.jsx(ia,{variant:m,parentAuth:k.find(C=>C.provider===m.provider),isSelected:g===m.name,onSelect:()=>U(m.name),onDelete:()=>d.mutate(m.name),isDeleting:d.isPending},m.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(aa,{})}),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:[k.length," provider",k.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(z,{className:"w-3 h-3 text-green-600"}),k.filter(m=>m.authenticated).length," connected"]})]})})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:j&&f?e.jsx(ze,{provider:j.name,displayName:`${j.name} (${j.provider} variant)`,authStatus:f,catalog:X[j.provider],logoProvider:j.provider,baseProvider:j.provider,isRemoteMode:D,port:j.port,onAddAccount:()=>O({provider:j.provider,displayName:f.displayName,isFirstAccount:(f.accounts?.length||0)===0}),onSetDefault:m=>l.mutate({provider:j.provider,accountId:m}),onRemoveAccount:m=>c.mutate({provider:j.provider,accountId:m}),onPauseToggle:(m,C)=>I(j.provider,m,C),isRemovingAccount:c.isPending,isPausingAccount:u.isPending||r.isPending}):y?e.jsx(ze,{provider:y.provider,displayName:y.displayName,authStatus:y,catalog:X[y.provider],isRemoteMode:D,onAddAccount:()=>O({provider:y.provider,displayName:y.displayName,isFirstAccount:(y.accounts?.length||0)===0}),onSetDefault:m=>l.mutate({provider:y.provider,accountId:m}),onRemoveAccount:m=>c.mutate({provider:y.provider,accountId:m}),onPauseToggle:(m,C)=>I(y.provider,m,C),isRemovingAccount:c.isPending,isPausingAccount:u.isPending||r.isPending}):e.jsx(ra,{onSetup:()=>A(!0)})}),e.jsx(Ft,{open:b,onClose:()=>A(!1)}),e.jsx(Ut,{open:v!==null,onClose:()=>O(null),provider:v?.provider||"",displayName:v?.displayName||"",isFirstAccount:v?.isFirstAccount||!1})]})}export{va as CliproxyPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-DP8--cuX.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-5ld5FlA0.js";import{D as we,a8 as ae,a9 as z,aa as re,y as ne,_ as ve,G as ke,ab as Ce,a5 as $e,w as Q,U as Se,Z as le,s as De,a2 as G,ac as Le,v as Te,b as Fe,ad as Re,ae as Me}from"./icons-TP-W6wBb.js";import{u as Pe,a as P}from"./tanstack-C1q4365B.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 l=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),r=s?.totalCost?Math.round(l/s.totalCost*100):0,i=[{title:"Total Tokens",value:s?.totalTokens??0,icon:we,format:o=>R(o),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:`${R(s?.totalInputTokens??0)} in / ${R(s?.totalOutputTokens??0)} out`},{title:"Total Cost",value:s?.totalCost??0,icon:ae,format:o=>`$${o.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:`$${s?.averageCostPerDay?.toFixed(2)??"0.00"}/day avg`},{title:"Cache Tokens",value:s?.totalCacheTokens??0,icon:z,format:o=>R(o),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:`$${l.toFixed(2)} (${r}% of cost)`},{title:"Input Cost",value:s?.tokenBreakdown?.input?.cost??0,icon:re,format:o=>`$${o.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:`${R(s?.tokenBreakdown?.input?.tokens??0)} tokens`},{title:"Output Cost",value:s?.tokenBreakdown?.output?.cost??0,icon:ne,format:o=>`$${o.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:`${R(s?.tokenBreakdown?.output?.tokens??0)} tokens`}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 xl:grid-cols-5 gap-4",children:i.map((o,n)=>{const c=o.icon;return e.jsx(p,{className:"hover:shadow-md transition-shadow",children:e.jsx(g,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:o.title}),e.jsx("p",{className:d("text-xl font-bold truncate",a&&y),children:o.format(o.value)}),o.subtitle&&e.jsx("p",{className:d("text-[10px] text-muted-foreground truncate",a&&y),children:o.subtitle})]}),e.jsx("div",{className:d("p-2 rounded-lg shrink-0",o.bgColor),children:e.jsx(c,{className:d("h-4 w-4",o.color)})})]})})},n)})})}function R(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ge({model:s}){const{privacyMode:t}=M(),a=We(s.ioRatio);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(I,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(I,{variant:a.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:d("text-lg font-bold",t&&y),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Cost"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:d("text-lg font-bold",t&&y),children:_e(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Tokens"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:d("space-y-1",t&&y),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:re}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:ne}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:z}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:z})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:"Input/Output Ratio"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:a.description})]})]})}function W({label:s,tokens:t,cost:a,color:l,icon:r}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:l}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",a.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(r,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:He(t)})]})]})]})}function We(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function He(s){return s.toLocaleString()}function _e(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}const ze="/api";function w(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0");return`${t}${a}${l}`}const T={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",w(s.startDate)),s?.endDate&&t.append("until",w(s.endDate)),s?.profile&&t.append("profile",s.profile),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 l=await a.json();return l.data||l}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,l]=f.useState(!1),[r,i]=f.useState(null),[o,n]=f.useState(null),[c,x]=f.useState("daily"),u=Xe(),m=f.useCallback(async()=>{l(!0);try{await u()}finally{l(!1)}},[u]),j=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:b,isLoading:v}=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();n({x:E.left+E.width/2,y:E.top+E.height/2}),i(F)},[]),me=f.useCallback(()=>{i(null),n(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:c,selectedModel:r,popoverPosition:o,summary:b,trends:C,hourlyData:A,models:U,sessions:_,status:K,isSummaryLoading:v,isTrendsLoading:$,isHourlyLoading:B,isModelsLoading:q,isSessionsLoading:O,isLoading:v||$||q||O,handleRefresh:m,handleTodayClick:ce,handleDateRangeChange:de,handleModelClick:ue,handlePopoverClose:me,lastUpdatedText:xe}}function ts({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from: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:l}){const[r,i]=fe.useState(!1),o=n=>!s||!s.from||!s.to||!n.from||!n.to?!1:k(s.from,"yyyy-MM-dd")===k(n.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(n.to,"yyyy-MM-dd");return e.jsxs("div",{className:d("flex items-center gap-2",l),children:[a.map(n=>e.jsx(H,{variant:o(n.range)?"default":"outline",size:"sm",onClick:()=>t(n.range),children:n.label},n.label)),e.jsxs(ee,{open:r,onOpenChange:i,children:[e.jsx(pe,{asChild:!0,children:e.jsxs(H,{id:"date",variant:"outline",className:d("w-auto min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[k(s.from,"LLL dd, y")," - ",k(s.to,"LLL dd, y")]}):k(s.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(se,{className:"w-auto p-0",align:"end",children:e.jsx(ge,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function as({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:l,isRefreshing:r,lastUpdatedText:i,viewMode:o}){return e.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Track usage & insights"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{variant:o==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(ts,{value:s,onChange:t,presets:[{label:"7D",range:{from: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:l,disabled:r,children:e.jsx($e,{className:`w-3.5 h-3.5 ${r?"animate-spin":""}`})})]})]})}function rs({data:s,isLoading:t,granularity:a="daily",className:l}){const{privacyMode:r}=M(),i=f.useMemo(()=>!s||s.length===0?[]:(a==="hourly"?s:[...s].reverse()).map(c=>{const x="hour"in c?c.hour:c.date;return{...c,dateFormatted:ns(x,a),costRounded:Number(c.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(h,{className:d("h-full w-full",l)});if(!s||s.length===0)return e.jsx("div",{className:d("h-full flex items-center justify-center",l),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const o=({x:n,y:c,payload:x,isRight:u})=>{const m=u?`$${x.value}`:X(Number(x.value));return e.jsx("text",{x:n,y:c,dy:4,textAnchor:u?"start":"end",fontSize:12,fill:"currentColor",className:d("fill-muted-foreground",r&&"blur-[4px]"),children:m})};return e.jsx("div",{className:d("w-full h-full",l),children:e.jsx(ie,{width:"100%",height:"100%",children:e.jsxs(Be,{data:i,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(Ue,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(qe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"left",orientation:"left",tick:n=>e.jsx(o,{...n,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:n=>e.jsx(o,{...n,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(oe,{content:({active:n,payload:c,label:x})=>{if(!n||!c||!c.length)return null;const u=c[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:x}),c.map((m,j)=>e.jsxs("p",{className:d("text-sm",r&&y),style:{color:m.color},children:[m.name,":"," ",m.name==="Tokens"?X(Number(m.value)||0):`$${m.value}`]},j)),"requests"in u&&e.jsxs("p",{className:d("text-sm text-muted-foreground mt-1",r&&y),children:["Requests: ",u.requests]})]})}}),e.jsx(Z,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(Z,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function ns(s,t){if(t==="hourly"){const[l,r]=s.split(" ");if(l&&r){const i=new Date(`${l}T${r}:00Z`);return k(i,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?k(a,"MMM yyyy"):k(a,"MMM dd")}function X(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ls({data:s,isLoading:t,className:a}){const{privacyMode:l}=M(),r=f.useMemo(()=>!s||s.length===0?[]:s.map(n=>({name:n.model,value:n.tokens,cost:n.cost,percentage:n.percentage,fill:te(n.model)})),[s]);if(t)return e.jsx(h,{className:d("h-[300px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:d("h-[300px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:"No model data available"})});const i=({active:n,payload:c})=>{if(!n||!c)return null;const x=c;if(!x.length)return null;const u=x[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:u.name}),e.jsxs("p",{className:d("text-muted-foreground",l&&y),children:[is(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:d("text-muted-foreground",l&&y),children:["$",u.cost.toFixed(4)]})]})},o=n=>n.percentage>5?`${n.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:d("w-full",a),children:e.jsx(ie,{width:"100%",height:250,children:e.jsxs(Ie,{children:[e.jsx(Oe,{data:r,cx:"50%",cy:"50%",labelLine:!1,label:o,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:r.map((n,c)=>e.jsx(Ke,{fill:n.fill,strokeWidth:1},`cell-${c}`))}),e.jsx(oe,{content:i})]})})})}function is(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function os({data:s,isLoading:t,className:a}){const{privacyMode:l}=M(),r=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,o=s.total,n=i.reduce((b,v)=>b+(v.inputTokens+v.outputTokens),0),c=Math.round(n/i.length),u=i.reduce((b,v)=>b+v.cost,0)/i.length,m=i[0],j=m?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",l&&y),children:["$",r.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx(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:i.projectPath.split("/").pop()}),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",l&&y),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[cs(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(p,{className:d("flex flex-col h-full",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(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 cs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function ds({className:s,isLoading:t}){const{data:a,isLoading:l}=je(),{data:r,isLoading:i,error:o}=Ne(a?.running);if(t||l||a?.running&&i)return e.jsxs(p,{className:d("flex flex-col h-full",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(p,{className:d("flex flex-col h-full border-dashed",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"secondary",className:"text-[10px] h-5",children:"Offline"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Start a CLIProxy session (gemini, codex, agy) to collect stats."})})]});if(o)return e.jsxs(p,{className:d("flex flex-col h-full border-destructive/50",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:o.message})})]});const c=r?.totalRequests??0,x=r?.quotaExceededCount??0,u=c-x,m=c>0?Math.round(u/c*100):100,j=r?.tokens?.total??0,b=Object.entries(r?.requestsByModel??{}).sort((C,$)=>$[1]-C[1]).slice(0,4),v=b.length>0?b[0][1]:1;return e.jsxs(p,{className:d("flex flex-col h-full overflow-hidden",s),children:[e.jsx(N,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(I,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(le,{className:"h-3 w-3 mr-0.5"}),"Running"]})]})}),e.jsx(g,{className:"p-0 flex-1 min-h-0",children:e.jsx(ye,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${m*.88} 88`,strokeLinecap:"round",className:m>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[m,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(c)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:x>0?`${x} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(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=xs(C);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:C,children:B}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:$})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${A}%`}})})]},C)})})]})]})})})]})}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function xs(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function us(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function ms({models:s,isLoading:t,onModelClick:a,privacyMode:l}){return e.jsxs(p,{className:"flex flex-col h-full min-h-0 shadow-sm lg:col-span-4",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ae,{className:"w-4 h-4"}),"Cost by Model"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(h,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((r,i)=>i.cost-r.cost).map(r=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:i=>a(r,i),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:te(r.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:r.model})]}),e.jsx(hs,{model:r}),e.jsx("span",{className:d("text-[10px] text-muted-foreground w-14 text-right shrink-0",l&&y),children:us(r.tokens)}),e.jsxs("span",{className:d("font-mono font-medium w-16 text-right shrink-0",l&&y),children:["$",r.cost.toFixed(2)]}),e.jsx(Fe,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},r.model)),e.jsx(fs,{})]})})]})}function hs({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=l=>s.cost>0?l/s.cost*100:0;return e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:t.input,width:`${a(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${a(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${a(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${a(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function fs(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:a,hasBorder:l})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:d("w-2 h-2 rounded-full",l&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function ps({viewMode:s,trends:t,hourlyData:a,models:l,sessions:r,isTrendsLoading:i,isHourlyLoading:o,isModelsLoading:n,isSessionsLoading:c,isSummaryLoading:x,onModelClick:u}){const{privacyMode:m}=M();return e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 gap-4",children:[e.jsxs(p,{className:"flex flex-col flex-1 min-h-0 max-h-[500px] overflow-hidden shadow-sm",children:[e.jsx(N,{className:"px-3 py-2 shrink-0",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Re,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(rs,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?o:i,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto lg:h-[180px] shrink-0",children:[e.jsx(ms,{models:l,isLoading:n,onModelClick:u,privacyMode:m}),e.jsxs(p,{className:"flex flex-col h-full min-h-0 shadow-sm lg:col-span-2",children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(ls,{data:l||[],isLoading:n,className:"h-full w-full"})})]}),e.jsx(os,{data:r,isLoading:c,className:"lg:col-span-2"}),e.jsx(ds,{isLoading:x,className:"lg:col-span-2"})]})]})}function Ss(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(p,{className:"flex flex-col min-h-[300px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-32"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(h,{className:"h-3 w-24"})]}),e.jsx(h,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(N,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(h,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"w-2 h-2 rounded-full"}),e.jsx(h,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Ds(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:l,handleRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:n,summary:c,isSummaryLoading:x,trends:u,hourlyData:m,models:j,sessions:b,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:$,isSessionsLoading:A,handleModelClick:B,selectedModel:U,popoverPosition:q,handlePopoverClose:_}=ss();return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden px-4 pt-4 pb-50 gap-4",children:[e.jsx(as,{dateRange:t,onDateRangeChange:a,onTodayClick:l,onRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:n}),e.jsx(Ee,{data:c,isLoading:x}),e.jsx(ps,{viewMode:n,trends:u,hourlyData:m,models:j,sessions:b,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:$,isSessionsLoading:A,isSummaryLoading:x,onModelClick:B}),e.jsxs(ee,{open:!!U,onOpenChange:O=>!O&&_(),children:[e.jsx(be,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:q?.x??0,top:q?.y??0,width:1,height:1}})}),e.jsx(se,{className:"w-80 p-3",side:"top",align:"center",children:U&&e.jsx(Ge,{model:U})})]})]})}export{Ds as AnalyticsPage,Ss as AnalyticsSkeleton};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-DP8--cuX.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{aO as he,aP as pe,ao as T,I as A,X as ge,Y as fe,Z as ye,_ as be,$ as z,b as Q,aQ as je,aL as W,aN as Y,m as ve}from"./index-5ld5FlA0.js";import{S as _}from"./switch-BUYlYaJx.js";import{t as Ne}from"./notifications-B2HqRBj7.js";import{aE as X,a5 as H,e as ke,p as Z,W as Ce,$ as Pe,aF as Se,aG as we,T as Ee,aH as Te}from"./icons-TP-W6wBb.js";import"./tanstack-C1q4365B.js";import"./utils-CzKF5WmX.js";import"./form-utils-C-pVd1--.js";import"./code-highlight-BRUf_pqB.js";function Ie(){const{state:t}=he(),s=pe(),[l,d]=n.useState(null),[u,y]=n.useState(null),[h,m]=n.useState(null),[b,j]=n.useState(null),[v,N]=n.useState(null),k=n.useCallback(async()=>{try{s.setProxyLoading(!0),s.setProxyError(null);const c=await T.cliproxyServer.get();s.setProxyConfig(c)}catch(c){s.setProxyError(c.message)}finally{s.setProxyLoading(!1)}},[s]),C=n.useCallback(async c=>{const i=t.proxyConfig;if(!i)return;const x={remote:{...i.remote,...c.remote},fallback:{...i.fallback,...c.fallback},local:{...i.local,...c.local}};s.setProxyConfig(x),s.setProxyTestResult(null);try{s.setProxySaving(!0),s.setProxyError(null);const r=await T.cliproxyServer.update(c);s.setProxyConfig(r),s.setProxySuccess(!0),setTimeout(()=>s.setProxySuccess(!1),1500)}catch(r){s.setProxyConfig(i),s.setProxyError(r.message)}finally{s.setProxySaving(!1)}},[t.proxyConfig,s]),P=n.useCallback(async c=>{const{host:i,port:x,protocol:r,authToken:S}=c;if(!i){s.setProxyError("Host is required");return}try{s.setProxyTesting(!0),s.setProxyError(null),s.setProxyTestResult(null);const o=x?parseInt(x,10):void 0,w=await T.cliproxyServer.test({host:i,port:o||void 0,protocol:r,authToken:S||void 0});s.setProxyTestResult(w)}catch(o){s.setProxyError(o.message)}finally{s.setProxyTesting(!1)}},[s]);return{config:t.proxyConfig,loading:t.proxyLoading,saving:t.proxySaving,error:t.proxyError,success:t.proxySuccess,testResult:t.proxyTestResult,testing:t.proxyTesting,editedHost:l,setEditedHost:d,editedPort:u,setEditedPort:y,editedAuthToken:h,setEditedAuthToken:m,editedManagementKey:b,setEditedManagementKey:j,editedLocalPort:v,setEditedLocalPort:N,fetchConfig:k,saveConfig:C,testConnection:P}}function Ae({config:t,saving:s,displayLocalPort:l,setEditedLocalPort:d,onSaveLocalPort:u,onSaveConfig:y}){const h=t.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Local Proxy"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Port"}),e.jsx(A,{type:"number",value:l,onChange:m=>d(m.target.value),onBlur:u,placeholder:"8317",className:"font-mono max-w-32",disabled:s})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Start local proxy automatically when needed"})]}),e.jsx(_,{checked:h.auto_start??!0,onCheckedChange:m=>y({local:{...h,auto_start:m}}),disabled:s})]})]})]})}function Le({config:t,saving:s,testing:l,testResult:d,displayHost:u,displayPort:y,displayAuthToken:h,displayManagementKey:m,setEditedHost:b,setEditedPort:j,setEditedAuthToken:v,setEditedManagementKey:N,onSaveHost:k,onSavePort:C,onSaveAuthToken:P,onSaveManagementKey:c,onSaveConfig:i,onTestConnection:x}){const r=t.remote,S=o=>o==="https"?443:8317;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(X,{className:"w-4 h-4"}),"Remote Server Configuration"]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Host"}),e.jsx(A,{value:u,onChange:o=>b(o.target.value),onBlur:k,placeholder:"192.168.1.100 or proxy.example.com",className:"font-mono",disabled:s})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:["Port"," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(default: ",S(t.remote.protocol||"http"),")"]})]}),e.jsx(A,{type:"text",inputMode:"numeric",value:y,onChange:o=>j(o.target.value.replace(/\D/g,"")),onBlur:C,placeholder:`Leave empty for ${S(t.remote.protocol||"http")}`,className:"font-mono",disabled:s})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Protocol"}),e.jsxs(ge,{value:t.remote.protocol||"http",onValueChange:o=>i({remote:{...r,protocol:o}}),disabled:s,children:[e.jsx(fe,{children:e.jsx(ye,{})}),e.jsxs(be,{children:[e.jsx(z,{value:"http",children:"HTTP"}),e.jsx(z,{value:"https",children:"HTTPS"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"API Key (optional)"}),e.jsx(A,{type:"password",value:h,onChange:o=>v(o.target.value),onBlur:P,placeholder:"For /v1/* API endpoints",className:"font-mono",disabled:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used for API requests to /v1/chat/completions"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Management Key (optional)"}),e.jsx(A,{type:"password",value:m,onChange:o=>N(o.target.value),onBlur:c,placeholder:"For /v0/management/* endpoints",className:"font-mono",disabled:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used for dashboard management APIs. Falls back to API Key if not set."})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(Q,{onClick:x,disabled:l||!u,variant:"outline",className:"w-full",children:l?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"w-4 h-4 mr-2 animate-spin"}),"Testing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"w-4 h-4 mr-2"}),"Test Connection"]})}),d&&e.jsx("div",{className:`p-3 rounded-md ${d.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:d.reachable?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsxs("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:["Connected (",d.latencyMs,"ms)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ce,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:d.error||"Connection failed"})]})})})]})]})}const q="ccs_debug_mode",_e=["kiro","ghcp"];function Ue(){const{config:t,loading:s,saving:l,error:d,success:u,testResult:y,testing:h,editedHost:m,setEditedHost:b,editedPort:j,setEditedPort:v,editedAuthToken:N,setEditedAuthToken:k,editedManagementKey:C,setEditedManagementKey:P,editedLocalPort:c,setEditedLocalPort:i,fetchConfig:x,saveConfig:r,testConnection:S}=Ie(),{fetchRawConfig:o}=je(),[w,J]=n.useState(()=>{try{return localStorage.getItem(q)==="true"}catch{return!1}}),ee=a=>{J(a);try{localStorage.setItem(q,String(a))}catch{}},[L,M]=n.useState("plus"),[$,O]=n.useState(!1),[te,se]=n.useState(!1),B=n.useCallback(async()=>{try{const a=await T.cliproxyServer.getBackend();M(a.backend)}catch(a){console.error("[Proxy] Failed to fetch backend:",a)}},[]),D=n.useCallback(async()=>{try{const g=(await T.cliproxy.list()).variants.some(f=>_e.includes(f.provider));se(g)}catch(a){console.error("[Proxy] Failed to check variants:",a)}},[]),V=async a=>{const g=L;M(a),O(!0);try{await T.cliproxyServer.updateBackend(a)}catch(f){(f instanceof Error?f.message:"Failed to save backend").includes("Proxy is running")&&Ne.error("Stop the proxy first to change backend"),console.error("[Proxy] Failed to save backend:",f),M(g)}finally{O(!1)}};if(n.useEffect(()=>{if(w&&t){const a={...t,remote:{...t.remote,auth_token:t.remote.auth_token?"[REDACTED]":void 0,management_key:t.remote.management_key?"[REDACTED]":void 0}};console.log("[CCS Debug] Debug mode enabled - proxy config:",a)}},[w,t]),n.useEffect(()=>{x(),o(),B(),D()},[x,o,B,D]),s||!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(H,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const p=t.remote.enabled??!1,E=t.remote,I=t.fallback,ae=t.remote.host??"",re=t.remote.port!==void 0?t.remote.port.toString():"",oe=t.remote.auth_token??"",ne=t.remote.management_key??"",le=(t.local.port??8317).toString(),K=m??ae,R=j??re,F=N??oe,G=C??ne,U=c??le,ce=()=>{const a=m??K;a!==t.remote.host&&r({remote:{...E,host:a}}),b(null)},de=()=>{const a=j??R,g=a===""?void 0:parseInt(a,10),f=g&&!isNaN(g)&&g>0?g:void 0;f!==t.remote.port&&r({remote:{...E,port:f}}),v(null)},ie=()=>{const a=N??F;a!==t.remote.auth_token&&r({remote:{...E,auth_token:a}}),k(null)},me=()=>{const a=C??G;a!==t.remote.management_key&&r({remote:{...E,management_key:a||void 0}}),P(null)},xe=()=>{const a=parseInt(c??U,10);!isNaN(a)&&a!==t.local.port&&r({local:{...t.local,port:a}}),i(null)},ue=()=>{S({host:K,port:R,protocol:t.remote.protocol||"http",authToken:F})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${d||u?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[d&&e.jsxs(W,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(Pe,{className:"h-4 w-4"}),e.jsx(Y,{children:d})]}),u&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(Z,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(ve,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure local or remote CLIProxy Plus connection for proxy-based profiles"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Connection Mode"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>r({remote:{...E,enabled:!1}}),disabled:l,className:`p-4 rounded-lg border-2 text-left transition-all ${p?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(Se,{className:`w-5 h-5 ${p?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:"Local"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Run CLIProxy Plus binary on this machine"})]}),e.jsxs("button",{onClick:()=>r({remote:{...E,enabled:!0}}),disabled:l,className:`p-4 rounded-lg border-2 text-left transition-all ${p?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(X,{className:`w-5 h-5 ${p?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:"Remote"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect to a remote CLIProxy Plus server"})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(we,{className:"w-4 h-4"}),"Backend Binary"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>V("plus"),disabled:$,className:`p-4 rounded-lg border-2 text-left transition-all ${L==="plus"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"font-medium",children:"CLIProxyAPIPlus"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-400",children:"Default"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Full provider support including Kiro and GitHub Copilot"})]}),e.jsxs("button",{onClick:()=>V("original"),disabled:$,className:`p-4 rounded-lg border-2 text-left transition-all ${L==="original"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("span",{className:"font-medium",children:"CLIProxyAPI"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Original binary (Gemini, Codex, Antigravity only)"})]})]}),L==="original"&&te&&e.jsxs(W,{variant:"destructive",className:"py-2",children:[e.jsx(Ee,{className:"h-4 w-4"}),e.jsx(Y,{children:"Existing Kiro/Copilot variants will not work with CLIProxyAPI. Switch to CLIProxyAPIPlus or remove those variants."})]})]}),p&&e.jsx(Le,{config:t,saving:l,testing:h,testResult:y,displayHost:K,displayPort:R,displayAuthToken:F,displayManagementKey:G,setEditedHost:b,setEditedPort:v,setEditedAuthToken:k,setEditedManagementKey:P,onSaveHost:ce,onSavePort:de,onSaveAuthToken:ie,onSaveManagementKey:me,onSaveConfig:r,onTestConnection:ue}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Fallback Settings"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Enable fallback to local"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use local proxy if remote is unreachable"})]}),e.jsx(_,{checked:I.enabled??!0,onCheckedChange:a=>r({fallback:{...I,enabled:a}}),disabled:l||!p})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start local proxy"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Automatically start local proxy on fallback"})]}),e.jsx(_,{checked:I.auto_start??!1,onCheckedChange:a=>r({fallback:{...I,auto_start:a}}),disabled:l||!p||!I.enabled})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(Te,{className:"w-4 h-4"}),"Advanced"]}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Debug Mode"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enable developer diagnostics in browser console"})]}),e.jsx(_,{checked:w,onCheckedChange:ee,disabled:l})]}),w&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 pl-0.5",children:"Debug mode enabled. Check browser console for detailed logs."})]})]}),!p&&e.jsx(Ae,{config:t,saving:l,displayLocalPort:U,setEditedLocalPort:i,onSaveLocalPort:xe,onSaveConfig:r})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(Q,{variant:"outline",size:"sm",onClick:()=>{x(),o(),B(),D()},disabled:s||l,className:"w-full",children:[e.jsx(H,{className:`w-4 h-4 mr-2 ${s?"animate-spin":""}`}),"Refresh"]})})]})}export{Ue as default};