@kaitranntt/ccs 7.19.2 → 7.20.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/ccs.js +6 -0
  2. package/dist/ccs.js.map +1 -1
  3. package/dist/cliproxy/cliproxy-executor.d.ts.map +1 -1
  4. package/dist/cliproxy/cliproxy-executor.js +4 -1
  5. package/dist/cliproxy/cliproxy-executor.js.map +1 -1
  6. package/dist/cliproxy/quota-fetcher.d.ts +6 -3
  7. package/dist/cliproxy/quota-fetcher.d.ts.map +1 -1
  8. package/dist/cliproxy/quota-fetcher.js +61 -17
  9. package/dist/cliproxy/quota-fetcher.js.map +1 -1
  10. package/dist/cliproxy/quota-manager.d.ts +2 -2
  11. package/dist/cliproxy/quota-manager.d.ts.map +1 -1
  12. package/dist/cliproxy/quota-manager.js +7 -7
  13. package/dist/cliproxy/quota-manager.js.map +1 -1
  14. package/dist/commands/cliproxy-command.d.ts.map +1 -1
  15. package/dist/commands/cliproxy-command.js +7 -6
  16. package/dist/commands/cliproxy-command.js.map +1 -1
  17. package/dist/commands/config-auth/disable-command.d.ts +10 -0
  18. package/dist/commands/config-auth/disable-command.d.ts.map +1 -0
  19. package/dist/commands/config-auth/disable-command.js +64 -0
  20. package/dist/commands/config-auth/disable-command.js.map +1 -0
  21. package/dist/commands/config-auth/index.d.ts +14 -0
  22. package/dist/commands/config-auth/index.d.ts.map +1 -0
  23. package/dist/commands/config-auth/index.js +84 -0
  24. package/dist/commands/config-auth/index.js.map +1 -0
  25. package/dist/commands/config-auth/setup-command.d.ts +13 -0
  26. package/dist/commands/config-auth/setup-command.d.ts.map +1 -0
  27. package/dist/commands/config-auth/setup-command.js +121 -0
  28. package/dist/commands/config-auth/setup-command.js.map +1 -0
  29. package/dist/commands/config-auth/show-command.d.ts +10 -0
  30. package/dist/commands/config-auth/show-command.d.ts.map +1 -0
  31. package/dist/commands/config-auth/show-command.js +79 -0
  32. package/dist/commands/config-auth/show-command.js.map +1 -0
  33. package/dist/commands/config-auth/types.d.ts +25 -0
  34. package/dist/commands/config-auth/types.d.ts.map +1 -0
  35. package/dist/commands/config-auth/types.js +8 -0
  36. package/dist/commands/config-auth/types.js.map +1 -0
  37. package/dist/commands/config-command.d.ts.map +1 -1
  38. package/dist/commands/config-command.js +37 -1
  39. package/dist/commands/config-command.js.map +1 -1
  40. package/dist/commands/help-command.d.ts.map +1 -1
  41. package/dist/commands/help-command.js +5 -0
  42. package/dist/commands/help-command.js.map +1 -1
  43. package/dist/commands/persist-command.d.ts +12 -0
  44. package/dist/commands/persist-command.d.ts.map +1 -0
  45. package/dist/commands/persist-command.js +565 -0
  46. package/dist/commands/persist-command.js.map +1 -0
  47. package/dist/config/unified-config-loader.d.ts +6 -1
  48. package/dist/config/unified-config-loader.d.ts.map +1 -1
  49. package/dist/config/unified-config-loader.js +41 -1
  50. package/dist/config/unified-config-loader.js.map +1 -1
  51. package/dist/config/unified-config-types.d.ts +22 -0
  52. package/dist/config/unified-config-types.d.ts.map +1 -1
  53. package/dist/config/unified-config-types.js +12 -1
  54. package/dist/config/unified-config-types.js.map +1 -1
  55. package/dist/ui/assets/accounts-Be6b-nwn.js +1 -0
  56. package/dist/ui/assets/{alert-dialog-CnDvl5IB.js → alert-dialog-CM5u0JHs.js} +1 -1
  57. package/dist/ui/assets/api-mj8kMJz1.js +1 -0
  58. package/dist/ui/assets/{auth-section-DbZac9VD.js → auth-section-nFosGq6Z.js} +1 -1
  59. package/dist/ui/assets/{charts-CJC4bH8P.js → charts-BBPXh0Ar.js} +1 -1
  60. package/dist/ui/assets/cliproxy-DlHYA8zi.js +3 -0
  61. package/dist/ui/assets/{cliproxy-control-panel-CP-dhv4O.js → cliproxy-control-panel-wKdIZ6WV.js} +1 -1
  62. package/dist/ui/assets/{code-highlight-DKN39ySy.js → code-highlight-BRUf_pqB.js} +1 -1
  63. package/dist/ui/assets/{confirm-dialog-w5D52_lL.js → confirm-dialog-BcIEdkmr.js} +1 -1
  64. package/dist/ui/assets/copilot-CK7anGeR.js +4 -0
  65. package/dist/ui/assets/{form-utils-kUVlZZAO.js → form-utils-C-pVd1--.js} +1 -1
  66. package/dist/ui/assets/globalenv-section-BgoWz-A2.js +1 -0
  67. package/dist/ui/assets/{health-BaRdlHhs.js → health-Clpm6LpQ.js} +1 -1
  68. package/dist/ui/assets/icons-WqZToXEO.js +1 -0
  69. package/dist/ui/assets/{index-BuLI32Lk.js → index-B3Y_vbPs.js} +1 -1
  70. package/dist/ui/assets/index-C3Ezj6Tb.js +1 -0
  71. package/dist/ui/assets/index-CDRTPpUQ.js +47 -0
  72. package/dist/ui/assets/index-CNsISHN_.css +1 -0
  73. package/dist/ui/assets/{index-CAdQ23xy.js → index-fYt7TJz8.js} +1 -1
  74. package/dist/ui/assets/{notifications-dJQY2-U6.js → notifications-B2HqRBj7.js} +1 -1
  75. package/dist/ui/assets/{radix-ui-CBgg0XeO.js → radix-ui-CFOhsBGh.js} +4 -4
  76. package/dist/ui/assets/{react-vendor-B_CU-WTZ.js → react-vendor-CNOkPC89.js} +2 -2
  77. package/dist/ui/assets/shared-C95GV4af.js +1 -0
  78. package/dist/ui/assets/{switch-Kx7oj3ow.js → switch-CUS7UF_z.js} +1 -1
  79. package/dist/ui/assets/{tanstack-CxYN0q6L.js → tanstack-U3Rle5gh.js} +1 -1
  80. package/dist/ui/index.html +9 -9
  81. package/dist/web-server/index.d.ts.map +1 -1
  82. package/dist/web-server/index.js +5 -0
  83. package/dist/web-server/index.js.map +1 -1
  84. package/dist/web-server/middleware/auth-middleware.d.ts +27 -0
  85. package/dist/web-server/middleware/auth-middleware.d.ts.map +1 -0
  86. package/dist/web-server/middleware/auth-middleware.js +116 -0
  87. package/dist/web-server/middleware/auth-middleware.js.map +1 -0
  88. package/dist/web-server/routes/auth-routes.d.ts +7 -0
  89. package/dist/web-server/routes/auth-routes.d.ts.map +1 -0
  90. package/dist/web-server/routes/auth-routes.js +108 -0
  91. package/dist/web-server/routes/auth-routes.js.map +1 -0
  92. package/dist/web-server/routes/index.d.ts.map +1 -1
  93. package/dist/web-server/routes/index.js +3 -0
  94. package/dist/web-server/routes/index.js.map +1 -1
  95. package/package.json +6 -1
  96. package/dist/ui/assets/accounts-CJISzCiC.js +0 -1
  97. package/dist/ui/assets/api-DP559Tqr.js +0 -1
  98. package/dist/ui/assets/card-nbrHgs37.js +0 -1
  99. package/dist/ui/assets/cliproxy-ssaB44zs.js +0 -3
  100. package/dist/ui/assets/copilot-DsYQqfFs.js +0 -4
  101. package/dist/ui/assets/globalenv-section-Bli3PW-y.js +0 -1
  102. package/dist/ui/assets/icons-CZDQWWm2.js +0 -1
  103. package/dist/ui/assets/index-B7MyxZLG.js +0 -47
  104. package/dist/ui/assets/index-BX0IVNt5.css +0 -1
  105. package/dist/ui/assets/index-DIrZx85u.js +0 -1
  106. package/dist/ui/assets/shared-CNbeCoBd.js +0 -1
@@ -24,16 +24,16 @@
24
24
  href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap"
25
25
  rel="stylesheet"
26
26
  />
27
- <script type="module" crossorigin src="/assets/index-B7MyxZLG.js"></script>
28
- <link rel="modulepreload" crossorigin href="/assets/react-vendor-B_CU-WTZ.js">
29
- <link rel="modulepreload" crossorigin href="/assets/radix-ui-CBgg0XeO.js">
30
- <link rel="modulepreload" crossorigin href="/assets/tanstack-CxYN0q6L.js">
31
- <link rel="modulepreload" crossorigin href="/assets/notifications-dJQY2-U6.js">
27
+ <script type="module" crossorigin src="/assets/index-CDRTPpUQ.js"></script>
28
+ <link rel="modulepreload" crossorigin href="/assets/react-vendor-CNOkPC89.js">
29
+ <link rel="modulepreload" crossorigin href="/assets/radix-ui-CFOhsBGh.js">
30
+ <link rel="modulepreload" crossorigin href="/assets/tanstack-U3Rle5gh.js">
31
+ <link rel="modulepreload" crossorigin href="/assets/notifications-B2HqRBj7.js">
32
+ <link rel="modulepreload" crossorigin href="/assets/icons-WqZToXEO.js">
32
33
  <link rel="modulepreload" crossorigin href="/assets/utils-CzKF5WmX.js">
33
- <link rel="modulepreload" crossorigin href="/assets/icons-CZDQWWm2.js">
34
- <link rel="modulepreload" crossorigin href="/assets/form-utils-kUVlZZAO.js">
35
- <link rel="modulepreload" crossorigin href="/assets/code-highlight-DKN39ySy.js">
36
- <link rel="stylesheet" crossorigin href="/assets/index-BX0IVNt5.css">
34
+ <link rel="modulepreload" crossorigin href="/assets/form-utils-C-pVd1--.js">
35
+ <link rel="modulepreload" crossorigin href="/assets/code-highlight-BRUf_pqB.js">
36
+ <link rel="stylesheet" crossorigin href="/assets/index-CNsISHN_.css">
37
37
  </head>
38
38
  <body>
39
39
  <div id="root"></div>
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web-server/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;AAGH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAGrC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB,GAAG,EAAE,eAAe,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAqEjF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web-server/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;AAGH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAIrC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB,GAAG,EAAE,eAAe,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CA2EjF"}
@@ -39,6 +39,7 @@ const http_1 = __importDefault(require("http"));
39
39
  const path_1 = __importDefault(require("path"));
40
40
  const ws_1 = require("ws");
41
41
  const websocket_1 = require("./websocket");
42
+ const auth_middleware_1 = require("./middleware/auth-middleware");
42
43
  /**
43
44
  * Start Express server with WebSocket support
44
45
  */
@@ -55,6 +56,10 @@ async function startServer(options) {
55
56
  }
56
57
  next(err);
57
58
  });
59
+ // Session middleware (for dashboard auth)
60
+ app.use((0, auth_middleware_1.createSessionMiddleware)());
61
+ // Auth middleware (protects API routes when enabled)
62
+ app.use(auth_middleware_1.authMiddleware);
58
63
  // REST API routes (modularized)
59
64
  const { apiRoutes } = await Promise.resolve().then(() => __importStar(require('./routes/index')));
60
65
  app.use('/api', apiRoutes);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/web-server/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sDAA8B;AAC9B,gDAAwB;AACxB,gDAAwB;AACxB,2BAAqC;AACrC,2CAA6C;AAc7C;;GAEG;AACI,KAAK,UAAU,WAAW,CAAC,OAAsB;IACtD,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;IACtB,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,oBAAe,CAAC,EAAE,MAAM,EA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AAI,EAAE,GAAG,EAAE;YAC/B,6DAA6D;YAC7D,uEAAuE;YACvE,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA3ED,kCA2EC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Dashboard Authentication Middleware
3
+ * Session-based auth with httpOnly cookies for CCS dashboard.
4
+ */
5
+ /// <reference types="qs" />
6
+ import type { Request, Response, NextFunction } from 'express';
7
+ declare module 'express-session' {
8
+ interface SessionData {
9
+ authenticated: boolean;
10
+ username: string;
11
+ }
12
+ }
13
+ /**
14
+ * Rate limiter for login attempts.
15
+ * 5 attempts per 15 minutes per IP.
16
+ */
17
+ export declare const loginRateLimiter: import("express-rate-limit").RateLimitRequestHandler;
18
+ /**
19
+ * Create session middleware configured for CCS dashboard.
20
+ */
21
+ export declare function createSessionMiddleware(): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
22
+ /**
23
+ * Auth middleware that protects all routes except public paths.
24
+ * Only active when dashboard_auth.enabled = true.
25
+ */
26
+ export declare function authMiddleware(req: Request, res: Response, next: NextFunction): void;
27
+ //# sourceMappingURL=auth-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../../../src/web-server/middleware/auth-middleware.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAU/D,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,WAAW;QACnB,aAAa,EAAE,OAAO,CAAC;QACvB,QAAQ,EAAE,MAAM,CAAC;KAClB;CACF;AA8CD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,sDAO3B,CAAC;AAEH;;GAEG;AACH,wBAAgB,uBAAuB,iJAetC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CA0BpF"}
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ /**
3
+ * Dashboard Authentication Middleware
4
+ * Session-based auth with httpOnly cookies for CCS dashboard.
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.authMiddleware = exports.createSessionMiddleware = exports.loginRateLimiter = void 0;
11
+ const express_session_1 = __importDefault(require("express-session"));
12
+ const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
13
+ const unified_config_loader_1 = require("../../config/unified-config-loader");
14
+ const crypto_1 = __importDefault(require("crypto"));
15
+ const fs_1 = __importDefault(require("fs"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const os_1 = __importDefault(require("os"));
18
+ /** Public paths that bypass auth (lowercase for case-insensitive matching) */
19
+ const PUBLIC_PATHS = ['/api/auth/login', '/api/auth/check', '/api/auth/setup', '/api/health'];
20
+ /** Path to persistent session secret file */
21
+ const SESSION_SECRET_PATH = path_1.default.join(os_1.default.homedir(), '.ccs', '.session-secret');
22
+ /**
23
+ * Generate or retrieve persistent session secret.
24
+ * Priority: ENV var > persisted file > generate new
25
+ */
26
+ function getSessionSecret() {
27
+ // 1. Check ENV var first
28
+ if (process.env.CCS_SESSION_SECRET) {
29
+ return process.env.CCS_SESSION_SECRET;
30
+ }
31
+ // 2. Try to read persisted secret
32
+ try {
33
+ if (fs_1.default.existsSync(SESSION_SECRET_PATH)) {
34
+ const secret = fs_1.default.readFileSync(SESSION_SECRET_PATH, 'utf-8').trim();
35
+ if (secret.length >= 32) {
36
+ return secret;
37
+ }
38
+ }
39
+ }
40
+ catch {
41
+ // Ignore read errors, generate new secret
42
+ }
43
+ // 3. Generate and persist new random secret
44
+ const newSecret = crypto_1.default.randomBytes(32).toString('hex');
45
+ try {
46
+ const dir = path_1.default.dirname(SESSION_SECRET_PATH);
47
+ if (!fs_1.default.existsSync(dir)) {
48
+ fs_1.default.mkdirSync(dir, { recursive: true });
49
+ }
50
+ fs_1.default.writeFileSync(SESSION_SECRET_PATH, newSecret, { mode: 0o600 });
51
+ }
52
+ catch (err) {
53
+ // Log warning - sessions won't persist across restarts
54
+ console.warn('[!] Failed to persist session secret:', err.message);
55
+ }
56
+ return newSecret;
57
+ }
58
+ /**
59
+ * Rate limiter for login attempts.
60
+ * 5 attempts per 15 minutes per IP.
61
+ */
62
+ exports.loginRateLimiter = (0, express_rate_limit_1.default)({
63
+ windowMs: 15 * 60 * 1000, // 15 minutes
64
+ max: 5, // 5 attempts
65
+ message: { error: 'Too many login attempts. Please try again later.' },
66
+ standardHeaders: true,
67
+ legacyHeaders: false,
68
+ skip: () => !(0, unified_config_loader_1.getDashboardAuthConfig)().enabled,
69
+ });
70
+ /**
71
+ * Create session middleware configured for CCS dashboard.
72
+ */
73
+ function createSessionMiddleware() {
74
+ const authConfig = (0, unified_config_loader_1.getDashboardAuthConfig)();
75
+ const maxAge = (authConfig.session_timeout_hours ?? 24) * 60 * 60 * 1000;
76
+ return (0, express_session_1.default)({
77
+ secret: getSessionSecret(),
78
+ resave: false,
79
+ saveUninitialized: false,
80
+ cookie: {
81
+ secure: false, // Local CLI uses HTTP
82
+ httpOnly: true,
83
+ maxAge,
84
+ sameSite: 'strict',
85
+ },
86
+ });
87
+ }
88
+ exports.createSessionMiddleware = createSessionMiddleware;
89
+ /**
90
+ * Auth middleware that protects all routes except public paths.
91
+ * Only active when dashboard_auth.enabled = true.
92
+ */
93
+ function authMiddleware(req, res, next) {
94
+ const authConfig = (0, unified_config_loader_1.getDashboardAuthConfig)();
95
+ // Skip auth if disabled
96
+ if (!authConfig.enabled) {
97
+ return next();
98
+ }
99
+ // Allow public paths (case-insensitive)
100
+ const pathLower = req.path.toLowerCase();
101
+ if (PUBLIC_PATHS.some((p) => pathLower.startsWith(p))) {
102
+ return next();
103
+ }
104
+ // Allow static assets and SPA routes (non-API)
105
+ if (!req.path.startsWith('/api/')) {
106
+ return next();
107
+ }
108
+ // Check session
109
+ if (req.session?.authenticated) {
110
+ return next();
111
+ }
112
+ // Unauthorized
113
+ res.status(401).json({ error: 'Authentication required' });
114
+ }
115
+ exports.authMiddleware = authMiddleware;
116
+ //# sourceMappingURL=auth-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-middleware.js","sourceRoot":"","sources":["../../../src/web-server/middleware/auth-middleware.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,sEAAsC;AACtC,4EAA2C;AAC3C,8EAA4E;AAC5E,oDAA4B;AAC5B,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AAUpB,8EAA8E;AAC9E,MAAM,YAAY,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAE9F,6CAA6C;AAC7C,MAAM,mBAAmB,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAE/E;;;GAGG;AACH,SAAS,gBAAgB;IACvB,yBAAyB;IACzB,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC;QACnC,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IACxC,CAAC;IAED,kCAAkC;IAClC,IAAI,CAAC;QACH,IAAI,YAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,YAAE,CAAC,YAAY,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;YACpE,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;gBACxB,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;IACH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IAEzE,OAAO,IAAA,yBAAO,EAAC;QACb,MAAM,EAAE,gBAAgB,EAAE;QAC1B,MAAM,EAAE,KAAK;QACb,iBAAiB,EAAE,KAAK;QACxB,MAAM,EAAE;YACN,MAAM,EAAE,KAAK,EAAE,sBAAsB;YACrC,QAAQ,EAAE,IAAI;YACd,MAAM;YACN,QAAQ,EAAE,QAAQ;SACnB;KACF,CAAC,CAAC;AACL,CAAC;AAfD,0DAeC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;IAC5E,MAAM,UAAU,GAAG,IAAA,8CAAsB,GAAE,CAAC;IAE5C,wBAAwB;IACxB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,wCAAwC;IACxC,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACzC,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,+CAA+C;IAC/C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,gBAAgB;IAChB,IAAI,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC;QAC/B,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,eAAe;IACf,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC,CAAC;AAC7D,CAAC;AA1BD,wCA0BC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Dashboard Authentication Routes
3
+ * Handles login, logout, session check, and setup status.
4
+ */
5
+ declare const router: import("express-serve-static-core").Router;
6
+ export default router;
7
+ //# sourceMappingURL=auth-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-routes.d.ts","sourceRoot":"","sources":["../../../src/web-server/routes/auth-routes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH,QAAA,MAAM,MAAM,4CAAW,CAAC;AA8FxB,eAAe,MAAM,CAAC"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ /**
3
+ * Dashboard Authentication Routes
4
+ * Handles login, logout, session check, and setup status.
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const express_1 = require("express");
11
+ const bcrypt_1 = __importDefault(require("bcrypt"));
12
+ const crypto_1 = __importDefault(require("crypto"));
13
+ const unified_config_loader_1 = require("../../config/unified-config-loader");
14
+ const auth_middleware_1 = require("../middleware/auth-middleware");
15
+ /**
16
+ * Timing-safe string comparison to prevent timing attacks.
17
+ * Returns true if strings match, false otherwise.
18
+ */
19
+ function timingSafeEqual(a, b) {
20
+ if (a.length !== b.length) {
21
+ // Still compare to avoid length-based timing leak
22
+ crypto_1.default.timingSafeEqual(Buffer.from(a), Buffer.from(a));
23
+ return false;
24
+ }
25
+ return crypto_1.default.timingSafeEqual(Buffer.from(a), Buffer.from(b));
26
+ }
27
+ const router = (0, express_1.Router)();
28
+ /**
29
+ * POST /api/auth/login
30
+ * Authenticate user with username/password.
31
+ * Rate limited: 5 attempts per 15 minutes.
32
+ */
33
+ router.post('/login', auth_middleware_1.loginRateLimiter, async (req, res) => {
34
+ const { username, password } = req.body;
35
+ if (!username || !password) {
36
+ res.status(400).json({ error: 'Username and password required' });
37
+ return;
38
+ }
39
+ const authConfig = (0, unified_config_loader_1.getDashboardAuthConfig)();
40
+ // Check if auth is configured
41
+ if (!authConfig.enabled || !authConfig.username || !authConfig.password_hash) {
42
+ res.status(400).json({ error: 'Authentication not configured' });
43
+ return;
44
+ }
45
+ // Validate bcrypt hash format to prevent bcrypt.compare errors
46
+ const isBcryptHash = /^\$2[aby]?\$\d{2}\$.{53}$/.test(authConfig.password_hash);
47
+ if (!isBcryptHash) {
48
+ res.status(500).json({ error: 'Invalid password hash format in config' });
49
+ return;
50
+ }
51
+ // Verify credentials (timing-safe comparison for username)
52
+ const usernameMatch = timingSafeEqual(username, authConfig.username);
53
+ const passwordMatch = await bcrypt_1.default.compare(password, authConfig.password_hash);
54
+ if (!usernameMatch || !passwordMatch) {
55
+ res.status(401).json({ error: 'Invalid credentials' });
56
+ return;
57
+ }
58
+ // Regenerate session to prevent session fixation, then set auth
59
+ req.session.regenerate((err) => {
60
+ if (err) {
61
+ res.status(500).json({ error: 'Session error' });
62
+ return;
63
+ }
64
+ req.session.authenticated = true;
65
+ req.session.username = username;
66
+ res.json({ success: true, username });
67
+ });
68
+ });
69
+ /**
70
+ * POST /api/auth/logout
71
+ * Clear session and log out user.
72
+ */
73
+ router.post('/logout', (req, res) => {
74
+ req.session.destroy((err) => {
75
+ if (err) {
76
+ res.status(500).json({ error: 'Failed to logout' });
77
+ return;
78
+ }
79
+ res.clearCookie('connect.sid');
80
+ res.json({ success: true });
81
+ });
82
+ });
83
+ /**
84
+ * GET /api/auth/check
85
+ * Check if user is authenticated and if auth is required.
86
+ */
87
+ router.get('/check', (req, res) => {
88
+ const authConfig = (0, unified_config_loader_1.getDashboardAuthConfig)();
89
+ res.json({
90
+ authRequired: authConfig.enabled,
91
+ authenticated: req.session?.authenticated ?? false,
92
+ username: req.session?.username ?? null,
93
+ });
94
+ });
95
+ /**
96
+ * GET /api/auth/setup
97
+ * Check if authentication is properly configured.
98
+ */
99
+ router.get('/setup', (_req, res) => {
100
+ const authConfig = (0, unified_config_loader_1.getDashboardAuthConfig)();
101
+ res.json({
102
+ enabled: authConfig.enabled,
103
+ configured: !!(authConfig.username && authConfig.password_hash),
104
+ sessionTimeoutHours: authConfig.session_timeout_hours ?? 24,
105
+ });
106
+ });
107
+ exports.default = router;
108
+ //# sourceMappingURL=auth-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-routes.js","sourceRoot":"","sources":["../../../src/web-server/routes/auth-routes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,qCAA8D;AAC9D,oDAA4B;AAC5B,oDAA4B;AAC5B,8EAA4E;AAC5E,mEAAiE;AAEjE;;;GAGG;AACH,SAAS,eAAe,CAAC,CAAS,EAAE,CAAS;IAC3C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,kDAAkD;QAClD,gBAAM,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,gBAAM,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,kCAAgB,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;IAC5E,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;IAExC,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC3B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gCAAgC,EAAE,CAAC,CAAC;QAClE,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,IAAA,8CAAsB,GAAE,CAAC;IAE5C,8BAA8B;IAC9B,IAAI,CAAC,UAAU,CAAC,OAAO,IAAI,C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/D,mBAAmB,EAAE,UAAU,CAAC,qBAAqB,IAAI,EAAE;KAC5D,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,kBAAe,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/web-server/routes/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH,eAAO,MAAM,SAAS,4CAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/web-server/routes/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,eAAO,MAAM,SAAS,4CAAW,CAAC"}
@@ -25,6 +25,7 @@ const cliproxy_stats_routes_1 = __importDefault(require("./cliproxy-stats-routes
25
25
  const copilot_routes_1 = __importDefault(require("./copilot-routes"));
26
26
  const misc_routes_1 = __importDefault(require("./misc-routes"));
27
27
  const proxy_routes_1 = __importDefault(require("./proxy-routes"));
28
+ const auth_routes_1 = __importDefault(require("./auth-routes"));
28
29
  // Create the main API router
29
30
  exports.apiRoutes = (0, express_1.Router)();
30
31
  // ==================== Profile & Settings ====================
@@ -37,6 +38,8 @@ exports.apiRoutes.use('/accounts', account_routes_1.default);
37
38
  exports.apiRoutes.use('/config', config_routes_1.default);
38
39
  // ==================== Health Checks ====================
39
40
  exports.apiRoutes.use('/health', health_routes_1.default);
41
+ // ==================== Dashboard Auth ====================
42
+ exports.apiRoutes.use('/auth', auth_routes_1.default);
40
43
  // ==================== CLIProxy ====================
41
44
  // Variants, auth, accounts, stats, status, models, error logs
42
45
  exports.apiRoutes.use('/cliproxy', variant_routes_1.default);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web-server/routes/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,qCAAiC;AAEjC,wBAAwB;AACxB,sEAA6C;AAC7C,sEAA6C;AAC7C,oEAA2C;AAC3C,oEAA2C;AAC3C,wEAA+C;AAC/C,sEAA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AC,UAAU,EAAE,wBAAa,CAAC,CAAC;AAEzC,qEAAqE;AACrE,iBAAS,CAAC,GAAG,CAAC,kBAAkB,EAAE,sBAAoB,CAAC,CAAC;AAExD,wEAAwE;AACxE,iBAAS,CAAC,GAAG,CAAC,GAAG,EAAE,qBAAU,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaitranntt/ccs",
3
- "version": "7.19.2",
3
+ "version": "7.20.0-dev.1",
4
4
  "description": "Claude Code Switch - Instant profile switching between Claude Sonnet 4.5 and GLM 4.6",
5
5
  "keywords": [
6
6
  "cli",
@@ -81,11 +81,13 @@
81
81
  "postinstall": "node scripts/postinstall.js"
82
82
  },
83
83
  "dependencies": {
84
+ "bcrypt": "^6.0.0",
84
85
  "boxen": "^5.1.2",
85
86
  "chalk": "^4.1.2",
86
87
  "chokidar": "^3.6.0",
87
88
  "cli-table3": "^0.6.5",
88
89
  "express": "^4.18.2",
90
+ "express-session": "^1.18.2",
89
91
  "get-port": "^5.1.1",
90
92
  "gradient-string": "^2.0.2",
91
93
  "js-yaml": "^4.1.1",
@@ -104,8 +106,11 @@
104
106
  "@semantic-release/npm": "^13.1.3",
105
107
  "@semantic-release/release-notes-generator": "^14.1.0",
106
108
  "@tailwindcss/vite": "^4.1.17",
109
+ "@types/bcrypt": "^6.0.0",
107
110
  "@types/chokidar": "^2.1.7",
108
111
  "@types/express": "^4.17.21",
112
+ "@types/express-rate-limit": "6.0.0",
113
+ "@types/express-session": "^1.18.2",
109
114
  "@types/js-yaml": "^4.0.9",
110
115
  "@types/node": "^20.19.25",
111
116
  "@types/ws": "^8.5.10",
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-CBgg0XeO.js";import{r as p}from"./react-vendor-B_CU-WTZ.js";import{a as D,u as b,b as N,d as A,f as y,g as T}from"./tanstack-CxYN0q6L.js";import{c as m,af as f,a as d,$ as k,a0 as R,a1 as S,a2 as z,a3 as P,L as C,I as q}from"./index-B7MyxZLG.js";import{A as F,a as _,b as K,c as L,d as M,e as $,f as E,g as H}from"./alert-dialog-CnDvl5IB.js";import{t as u}from"./notifications-dJQY2-U6.js";import{R as O,j,a9 as Q,t as I,l as v,O as B}from"./icons-CZDQWWm2.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function U({className:t,...s}){return e.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:e.jsx("table",{"data-slot":"table",className:m("w-full caption-bottom text-sm",t),...s})})}function V({className:t,...s}){return e.jsx("thead",{"data-slot":"table-header",className:m("[&_tr]:border-b",t),...s})}function Z({className:t,...s}){return e.jsx("tbody",{"data-slot":"table-body",className:m("[&_tr:last-child]:border-0",t),...s})}function w({className:t,...s}){return e.jsx("tr",{"data-slot":"table-row",className:m("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",t),...s})}function G({className:t,...s}){return e.jsx("th",{"data-slot":"table-head",className:m("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",t),...s})}function J({className:t,...s}){return e.jsx("td",{"data-slot":"table-cell",className:m("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",t),...s})}function W(){return D({queryKey:["accounts"],queryFn:()=>f.accounts.list()})}function X(){const t=b();return N({mutationFn:s=>f.accounts.setDefault(s),onSuccess:(s,l)=>{t.invalidateQueries({queryKey:["accounts"]}),u.success(`Default account set to "${l}"`)},onError:s=>{u.error(s.message)}})}function Y(){const t=b();return N({mutationFn:()=>f.accounts.resetDefault(),onSuccess:()=>{t.invalidateQueries({queryKey:["accounts"]}),u.success("Default account reset to CCS")},onError:s=>{u.error(s.message)}})}function ee(){const t=b();return N({mutationFn:s=>f.accounts.delete(s),onSuccess:(s,l)=>{t.invalidateQueries({queryKey:["accounts"]}),u.success(`Account "${l}" deleted`)},onError:s=>{u.error(s.message)}})}function se({data:t,defaultAccount:s}){const l=X(),i=ee(),r=Y(),[c,o]=p.useState(null),x=A({data:t,columns:[{accessorKey:"name",header:"Name",size:200,cell:({row:a})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:a.original.name}),a.original.name===s&&e.jsx("span",{className:"text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded border border-primary/20",children:"default"})]})},{accessorKey:"type",header:"Type",size:100,cell:({row:a})=>e.jsx("span",{className:"capitalize text-muted-foreground",children:a.original.type||"oauth"})},{accessorKey:"created",header:"Created",size:150,cell:({row:a})=>{const n=new Date(a.original.created);return e.jsx("span",{className:"text-muted-foreground",children:n.toLocaleDateString()})}},{accessorKey:"last_used",header:"Last Used",size:150,cell:({row:a})=>{if(!a.original.last_used)return e.jsx("span",{className:"text-muted-foreground/50",children:"-"});const n=new Date(a.original.last_used);return e.jsx("span",{className:"text-muted-foreground",children:n.toLocaleDateString()})}},{id:"actions",header:"Actions",size:180,cell:({row:a})=>{const n=a.original.name===s,h=l.isPending||i.isPending;return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(d,{variant:n?"secondary":"default",size:"sm",className:"h-8 px-2",disabled:n||h,onClick:()=>l.mutate(a.original.name),children:[e.jsx(j,{className:`w-3 h-3 mr-1 ${n?"opacity-50":""}`}),n?"Active":"Set Default"]}),e.jsx(d,{variant:"ghost",size:"sm",className:"h-8 px-2 text-destructive hover:text-destructive hover:bg-destructive/10",disabled:n||h,onClick:()=>o(a.original.name),title:n?"Cannot delete default account":"Delete account",children:e.jsx(Q,{className:"w-4 h-4"})})]})}}],getCoreRowModel:T()});return t.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:["No accounts found. Use"," ",e.jsx("code",{className:"text-sm bg-muted px-1 rounded",children:"ccs auth create"})," to add accounts."]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"border rounded-md",children:e.jsxs(U,{children:[e.jsx(V,{children:x.getHeaderGroups().map(a=>e.jsx(w,{children:a.headers.map(n=>{const h={name:"w-[200px]",type:"w-[100px]",created:"w-[150px]",last_used:"w-[150px]",actions:"w-[180px]"}[n.id]||"w-auto";return e.jsx(G,{className:h,children:n.isPlaceholder?null:y(n.column.columnDef.header,n.getContext())},n.id)})},a.id))}),e.jsx(Z,{children:x.getRowModel().rows.map(a=>e.jsx(w,{children:a.getVisibleCells().map(n=>e.jsx(J,{children:y(n.column.columnDef.cell,n.getContext())},n.id))},a.id))})]})}),s&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(d,{variant:"outline",size:"sm",onClick:()=>r.mutate(),disabled:r.isPending,children:[e.jsx(O,{className:"w-4 h-4 mr-2"}),"Reset to CCS Default"]})})]}),e.jsx(F,{open:!!c,onOpenChange:a=>!a&&o(null),children:e.jsxs(_,{children:[e.jsxs(K,{children:[e.jsx(L,{children:"Delete Account"}),e.jsxs(M,{children:['Are you sure you want to delete the account "',c,'"? This will remove the profile and all its session data. This action cannot be undone.']})]}),e.jsxs($,{children:[e.jsx(E,{children:"Cancel"}),e.jsx(H,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{c&&(i.mutate(c),o(null))},children:"Delete"})]})]})})]})}function te({open:t,onClose:s}){const[l,i]=p.useState(""),[r,c]=p.useState(!1),o=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(l),g=l?`ccs auth create ${l}`:"ccs auth create <name>",x=async()=>{o&&(await navigator.clipboard.writeText(g),c(!0),setTimeout(()=>c(!1),2e3))},a=()=>{i(""),c(!1),s()};return e.jsx(k,{open:t,onOpenChange:n=>!n&&a(),children:e.jsxs(R,{className:"sm:max-w-md",children:[e.jsxs(S,{children:[e.jsx(z,{children:"Create New Account"}),e.jsx(P,{children:"Auth profiles require Claude CLI login. Run the command below in your terminal."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"profile-name",children:"Profile Name"}),e.jsx(q,{id:"profile-name",value:l,onChange:n=>i(n.target.value),placeholder:"e.g., work, personal, client",autoComplete:"off"}),l&&!o&&e.jsx("p",{className:"text-xs text-destructive",children:"Name must start with a letter and contain only letters, numbers, dashes, or underscores."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Command"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-md font-mono text-sm",children:[e.jsx(I,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsx("code",{className:"flex-1 break-all",children:g}),e.jsx(d,{variant:"ghost",size:"sm",className:"shrink-0 h-8 px-2",onClick:x,disabled:!o,children:r?e.jsx(j,{className:"w-4 h-4 text-green-500"}):e.jsx(v,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsx("p",{children:"After running the command:"}),e.jsxs("ol",{className:"list-decimal list-inside pl-2 space-y-0.5",children:[e.jsx("li",{children:"Complete the Claude login in your browser"}),e.jsx("li",{children:"Return here and refresh to see the new account"})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(d,{variant:"ghost",onClick:a,children:"Close"}),e.jsx(d,{onClick:x,disabled:!o,children:r?e.jsxs(e.Fragment,{children:[e.jsx(j,{className:"w-4 h-4 mr-2"}),"Copied!"]}):e.jsxs(e.Fragment,{children:[e.jsx(v,{className:"w-4 h-4 mr-2"}),"Copy Command"]})})]})]})]})})}function xe(){const{data:t,isLoading:s,refetch:l}=W(),[i,r]=p.useState(!1);return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Accounts"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage multi-account Claude sessions (profiles.json)"})]}),e.jsxs(d,{onClick:()=>r(!0),children:[e.jsx(B,{className:"w-4 h-4 mr-2"}),"Create Account"]})]}),s?e.jsx("div",{className:"text-muted-foreground",children:"Loading accounts..."}):e.jsx(se,{data:t?.accounts||[],defaultAccount:t?.default??null,onRefresh:l}),e.jsx(te,{open:i,onClose:()=>r(!1)})]})}export{xe as AccountsPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-CBgg0XeO.js";import{r as c}from"./react-vendor-B_CU-WTZ.js";import{B as S,c as E,T as Ne,k as ve,l as be,a as g,I as y,i as I,L as T,m as M,n as ne,o as we,s as Ce,p as ye,q as Oe,S as W,r as L,t as $,v as re,w as Ae,x as Ee,y as ie,z as le,A as ce,D as Te,E as _e,F as X,G as Z,R as ke,H as q,J as Se,K as Pe,M as Re,N as Le}from"./index-B7MyxZLG.js";import{u as Me,a as De,b as Ie}from"./tanstack-CxYN0q6L.js";import{C as B,S as ee}from"./confirm-dialog-w5D52_lL.js";import{t as Q}from"./notifications-dJQY2-U6.js";import{a0 as U,a9 as oe,L as G,aa as Ue,E as He,d as Fe,O as D,I as Ke,ab as de,Q as V,b as xe,ac as ze,N as Je,ad as $e,m as me,X as Be,Z as ue,ae as Qe,_ as qe,V as he,af as Ge,n as fe}from"./icons-CZDQWWm2.js";import{C as Ve,b as Ye,c as We,d as Xe,a as Ze}from"./card-nbrHgs37.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";import"./alert-dialog-CnDvl5IB.js";function es({className:s,showTooltip:t=!0}){const i=e.jsxs(S,{variant:"outline",className:E("bg-accent/10 border-accent/30 text-accent","dark:bg-accent/20 dark:border-accent/40 dark:text-accent-foreground",s),children:[e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"mr-1 h-3 w-3"}),"OpenRouter"]});return t?e.jsxs(Ne,{children:[e.jsx(ve,{asChild:!0,children:i}),e.jsx(be,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):i}function se(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(i=>i.test(s))}function pe(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function ss(s){return{opus:s.ANTHROPIC_DEFAULT_OPUS_MODEL||void 0,sonnet:s.ANTHROPIC_DEFAULT_SONNET_MODEL||void 0,haiku:s.ANTHROPIC_DEFAULT_HAIKU_MODEL||void 0}}function ts(s,t){const i={...s};return t.opus?i.ANTHROPIC_DEFAULT_OPUS_MODEL=t.opus:delete i.ANTHROPIC_DEFAULT_OPUS_MODEL,t.sonnet?i.ANTHROPIC_DEFAULT_SONNET_MODEL=t.sonnet:delete i.ANTHROPIC_DEFAULT_SONNET_MODEL,t.haiku?i.ANTHROPIC_DEFAULT_HAIKU_MODEL=t.haiku:delete i.ANTHROPIC_DEFAULT_HAIKU_MODEL,i}function as({profileName:s,data:t,settings:i,isLoading:l,isSaving:d,hasChanges:f,isRawJsonValid:x,onRefresh:n,onDelete:o,onSave:m}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),t?.path&&e.jsx(S,{variant:"outline",className:"text-xs",children:t.path.replace(/^.*\//,"")}),pe(i)&&e.jsx(es,{className:"ml-1"})]}),t&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(t.mtime).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{variant:"ghost",size:"sm",onClick:n,disabled:l,children:e.jsx(U,{className:`w-4 h-4 ${l?"animate-spin":""}`})}),o&&e.jsx(g,{variant:"ghost",size:"sm",onClick:o,children:e.jsx(oe,{className:"w-4 h-4 text-destructive"})}),e.jsx(g,{size:"sm",onClick:m,disabled:d||!f||!x,children:d?e.jsxs(e.Fragment,{children:[e.jsx(G,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ue,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function ge({label:s,...t}){const[i,l]=c.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[s&&e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"relative",children:[e.jsx(y,{type:i?"text":"password",className:"pr-10 font-mono",...t}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>l(!i),tabIndex:-1,children:i?e.jsx(He,{className:"w-4 h-4"}):e.jsx(Fe,{className:"w-4 h-4"})})]})]})}function ns({currentSettings:s,newEnvKey:t,newEnvValue:i,onNewEnvKeyChange:l,onNewEnvValueChange:d,onEnvValueChange:f,onAddEnvVar:x}){return e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-4",children:s?.env&&Object.keys(s.env).length>0?e.jsx(e.Fragment,{children:Object.entries(s.env).map(([n,o])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(T,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[n,se(n)&&e.jsx(S,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:"sensitive"})]}),se(n)?e.jsx(ge,{value:o,onChange:m=>f(n,m.target.value),className:"font-mono text-sm h-8"}):e.jsx(y,{value:o,onChange:m=>f(n,m.target.value),className:"font-mono text-sm h-8"})]},n))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed text-sm",children:[e.jsx("p",{children:"No environment variables configured."}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:"Add variables using the input below or edit the JSON directly."})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(y,{placeholder:"VARIABLE_NAME",value:t,onChange:n=>l(n.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:n=>n.key==="Enter"&&t.trim()&&x()}),e.jsx(y,{placeholder:"value",value:i,onChange:n=>d(n.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:n=>n.key==="Enter"&&t.trim()&&x()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:x,disabled:!t.trim(),children:e.jsx(D,{className:"w-4 h-4"})})]})]})]})}function rs({profileName:s,data:t}){return e.jsx(I,{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(Ke,{className:"w-4 h-4"}),"Profile Information"]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Profile Name"}),e.jsx("span",{className:"font-mono",children:t.profile})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:t.path}),e.jsx(M,{value:t.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Last Modified"}),e.jsx("span",{className:"text-xs",children:new Date(t.mtime).toLocaleString()})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"Run with profile"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs ",s,' "prompt"']}),e.jsx(M,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"Set as default"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs default ",s]}),e.jsx(M,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function is({value:s,onChange:t,placeholder:i="Search models...",className:l}){const[d,f]=c.useState(""),[x,n]=c.useState(null),{models:o,isLoading:m,isError:j,isFetching:O}=ne(),A=we(),N=c.useMemo(()=>Ce(o,d,{category:x??void 0}),[o,d,x]),b=c.useMemo(()=>ye(o,2),[o]),k=!d.trim()&&!x,_=c.useMemo(()=>{const r={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};N.forEach(a=>{r[a.category].push(a)});for(const a of Object.keys(r))r[a]=Oe(r[a]);return r},[N]),C=c.useCallback(()=>{A()},[A]),p=o.find(r=>r.id===s);return m&&o.length===0?e.jsxs("div",{className:E("space-y-2",l),children:[e.jsx(W,{className:"h-10 w-full"}),e.jsx(W,{className:"h-32 w-full"})]}):e.jsxs("div",{className:E("space-y-2 w-full min-w-0 overflow-hidden",l),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(de,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(y,{value:d,onChange:r=>f(r.target.value),placeholder:i,className:"pl-9"})]}),e.jsx(g,{variant:"outline",size:"icon",onClick:C,disabled:O,title:"Refresh models",children:O?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(U,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(S,{variant:x===null?"default":"outline",className:"cursor-pointer",onClick:()=>n(null),children:["All (",o.length,")"]}),Object.keys(L).map(r=>{const a=_[r].length;return a===0?null:e.jsxs(S,{variant:x===r?"default":"outline",className:"cursor-pointer",onClick:()=>n(r),children:[L[r]," (",a,")"]},r)})]}),p&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:p.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[$(p.pricing)," |"," ",re(p.context_length)]})]}),e.jsx(I,{className:"h-72 w-full rounded-md border",children:j?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(g,{variant:"link",onClick:C,children:"Retry"})]}):N.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',d,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[k&&b.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-muted-foreground bg-background sticky top-0 mb-2 flex items-center gap-1.5 py-1.5 text-xs font-semibold border-b pb-2",children:[e.jsx(V,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:b.map(r=>e.jsx(te,{model:r,isSelected:r.id===s,onClick:()=>t(r.id),showAge:!0},r.id))})]}),Object.keys(L).map(r=>{const a=_[r];return a.length===0?null:e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground bg-background sticky top-0 mb-2 py-1.5 text-xs font-semibold border-b pb-2",children:L[r]}),e.jsx("div",{className:"space-y-1",children:a.map(v=>e.jsx(te,{model:v,isSelected:v.id===s,onClick:()=>t(v.id)},v.id))})]},r)})]})})]})}function te({model:s,isSelected:t,onClick:i,showAge:l=!1}){return e.jsxs("button",{type:"button",onClick:i,className:E("group flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors","hover:bg-accent hover:text-accent-foreground",t&&"bg-accent text-accent-foreground"),children:[e.jsx("span",{className:"flex-1 min-w-0 truncate font-medium",children:s.name}),e.jsxs("span",{className:E("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",t?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[l&&s.created&&e.jsx(S,{variant:"outline",className:E("text-[10px] px-1",t?"border-accent-foreground/30 text-accent-foreground/80":"text-accent border-accent/30 group-hover:text-accent-foreground/80 group-hover:border-accent-foreground/30"),children:Ae(s.created)}),s.isFree?e.jsx(S,{variant:"secondary",className:E("text-[10px] px-1",t?"bg-accent-foreground/20 text-accent-foreground":"group-hover:bg-accent-foreground/20 group-hover:text-accent-foreground"),children:"Free"}):s.isExacto?e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",className:E("text-[10px] px-1 border-emerald-500/50 text-emerald-600",t?"border-accent-foreground/30 text-accent-foreground/80":"group-hover:border-accent-foreground/30 group-hover:text-accent-foreground/80"),children:"Exacto"}),e.jsx("span",{className:"tabular-nums",children:$(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:$(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:re(s.context_length)})]})]})}function ls({selectedModel:s,value:t,onChange:i,className:l}){const{models:d}=ne(),f=c.useMemo(()=>s?Ee(s,d):{},[s,d]),x=()=>{i(f)},n=(m,j)=>{i({...t,[m]:j||void 0})},o=s&&Object.keys(f).length>0;return e.jsxs(ie,{className:E("group",l),children:[e.jsxs(le,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(xe,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-90"}),"Model Tier Mapping",e.jsx("span",{className:"text-muted-foreground font-normal",children:"(Advanced)"})]}),e.jsxs(ce,{className:"space-y-3 pt-3",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Configure different models for Claude Code's opus/sonnet/haiku tiers."}),o&&e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:x,children:[e.jsx(ze,{className:"mr-1 h-4 w-4"}),"Auto-suggest based on ",s?.split("/")[0]]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-opus",className:"text-right",children:"Opus"}),e.jsx(y,{id:"tier-opus",value:t.opus??"",onChange:m=>n("opus",m.target.value),placeholder:"e.g., anthropic/claude-opus-4"})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-sonnet",className:"text-right",children:"Sonnet"}),e.jsx(y,{id:"tier-sonnet",value:t.sonnet??"",onChange:m=>n("sonnet",m.target.value),placeholder:"e.g., anthropic/claude-sonnet-4"})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-haiku",className:"text-right",children:"Haiku"}),e.jsx(y,{id:"tier-haiku",value:t.haiku??"",onChange:m=>n("haiku",m.target.value),placeholder:"e.g., anthropic/claude-3.5-haiku"})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:"These set ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL."})]})]})}function cs({profileName:s,data:t,currentSettings:i,newEnvKey:l,newEnvValue:d,onNewEnvKeyChange:f,onNewEnvValueChange:x,onEnvValueChange:n,onAddEnvVar:o,onEnvBulkChange:m}){const j=pe(i),O=i?.env,A=c.useMemo(()=>ss(O??{}),[O]),N=O??{},b=a=>{if(m){const v={...N,ANTHROPIC_MODEL:a,ANTHROPIC_DEFAULT_OPUS_MODEL:a,ANTHROPIC_DEFAULT_SONNET_MODEL:a,ANTHROPIC_DEFAULT_HAIKU_MODEL:a};m(v)}else n("ANTHROPIC_MODEL",a),n("ANTHROPIC_DEFAULT_OPUS_MODEL",a),n("ANTHROPIC_DEFAULT_SONNET_MODEL",a),n("ANTHROPIC_DEFAULT_HAIKU_MODEL",a);Q.success("Applied model to all tiers",{duration:2e3})},k=a=>{if(m){const v=ts(N,a);m(v)}else a.opus!==void 0&&n("ANTHROPIC_DEFAULT_OPUS_MODEL",a.opus||""),a.sonnet!==void 0&&n("ANTHROPIC_DEFAULT_SONNET_MODEL",a.sonnet||""),a.haiku!==void 0&&n("ANTHROPIC_DEFAULT_HAIKU_MODEL",a.haiku||"")},[_,C]=c.useState(!1),p=new Set(["ANTHROPIC_AUTH_TOKEN"]),r=Object.entries(N).filter(([a])=>!p.has(a));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(Te,{defaultValue:"env",className:"h-full w-full min-w-0 flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(_e,{className:"w-full",children:[e.jsx(X,{value:"env",className:"flex-1",children:j?"Configuration":"Environment Variables"}),e.jsx(X,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col min-w-0",children:[e.jsx(Z,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:j?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsxs("div",{className:"h-full overflow-y-auto overflow-x-hidden p-4 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{className:"text-sm font-medium",children:"Model Selection"}),e.jsx(is,{value:N.ANTHROPIC_MODEL,onChange:b,placeholder:"Search OpenRouter models..."})]}),e.jsx(ls,{selectedModel:N.ANTHROPIC_MODEL,value:A,onChange:k}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"API Key"}),e.jsx(ge,{value:N.ANTHROPIC_AUTH_TOKEN||"",onChange:a=>n("ANTHROPIC_AUTH_TOKEN",a.target.value),placeholder:"sk-or-v1-...",className:"font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your API key from"," ",e.jsx("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"openrouter.ai/keys"})]})]}),r.length>0&&e.jsxs(ie,{open:_,onOpenChange:C,children:[e.jsxs(le,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(xe,{className:E("h-4 w-4 transition-transform",_&&"rotate-90")}),e.jsx(Je,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",r.length,")"]})]}),e.jsx(ce,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:r.map(([a,v])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a}),e.jsx(y,{value:v,onChange:R=>n(a,R.target.value),className:"font-mono text-xs h-8"})]},a))})})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(y,{placeholder:"VARIABLE_NAME",value:l,onChange:a=>f(a.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:a=>a.key==="Enter"&&l.trim()&&o()}),e.jsx(y,{placeholder:"value",value:d,onChange:a=>x(a.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:a=>a.key==="Enter"&&l.trim()&&o()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:o,disabled:!l.trim(),children:e.jsx(D,{className:"w-4 h-4"})})]})]})]}):e.jsx(ns,{currentSettings:i,newEnvKey:l,newEnvValue:d,onNewEnvKeyChange:f,onNewEnvValueChange:x,onEnvValueChange:n,onAddEnvVar:o})}),e.jsx(Z,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(rs,{profileName:s,data:t})})]})]})})}function os({profileName:s,onDelete:t,onHasChangesUpdate:i}){const[l,d]=c.useState({}),[f,x]=c.useState(!1),[n,o]=c.useState(null),[m,j]=c.useState(""),[O,A]=c.useState(""),N=Me(),{data:b,isLoading:k,isError:_,refetch:C}=De({queryKey:["settings",s],queryFn:async()=>{const h=await fetch(`/api/settings/${s}/raw`);if(!h.ok)throw new Error(`Failed to load settings: ${h.status}`);return h.json()}}),p=b?.settings,r=c.useMemo(()=>{if(n!==null)try{return JSON.parse(n)}catch{}if(p)return{...p,env:{...p.env,...l}}},[p,l,n]),a=c.useMemo(()=>n!==null?n:p?JSON.stringify(p,null,2):"",[n,p]),v=c.useCallback(h=>{o(h)},[]),R=(h,w)=>{const P={...r?.env||{},[h]:w};d(J=>({...J,[h]:w})),o(JSON.stringify({...r,env:P},null,2))},H=h=>{const w={...r?.env||{},...h};d(P=>({...P,...h})),o(JSON.stringify({...r,env:w},null,2))},F=()=>{if(!m.trim())return;const h=m.trim(),w=O,P={...r?.env||{},[h]:w};d(J=>({...J,[h]:w})),o(JSON.stringify({...r,env:P},null,2)),j(""),A("")},u=c.useMemo(()=>{try{return JSON.parse(a),!0}catch{return!1}},[a]),K=c.useMemo(()=>n!==null?n!==JSON.stringify(p,null,2):Object.keys(l).length>0,[n,l,p]),je=c.useMemo(()=>{const h=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],w=r?.env||{};return h.filter(P=>!w[P]?.trim())},[r]);c.useEffect(()=>{i?.(K)},[K,i]);const z=Ie({mutationFn:async()=>{let h;try{h=JSON.parse(a)}catch{h={...b?.settings,env:{...b?.settings?.env,...l}}}const w=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:h,expectedMtime:b?.mtime})});if(w.status===409)throw new Error("CONFLICT");if(!w.ok)throw new Error("Failed to save");return w.json()},onSuccess:()=>{N.invalidateQueries({queryKey:["settings",s]}),N.invalidateQueries({queryKey:["profiles"]}),d({}),o(null),Q.success("Settings saved")},onError:h=>{h.message==="CONFLICT"?x(!0):Q.error(h.message)}}),Y=async h=>{x(!1),h?(await C(),z.mutate()):(d({}),o(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(as,{profileName:s,data:b,settings:r,isLoading:k,isSaving:z.isPending,hasChanges:K,isRawJsonValid:u,onRefresh:()=>C(),onDelete:t,onSave:()=>z.mutate()}),k?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(G,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):_?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load settings."}),e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>C(),children:[e.jsx(U,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5 min-w-0",children:e.jsx(cs,{profileName:s,data:b,currentSettings:r,newEnvKey:m,newEnvValue:O,onNewEnvKeyChange:j,onNewEnvValueChange:A,onEnvValueChange:R,onEnvBulkChange:H,onAddEnvVar:F})}),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($e,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(ke,{rawJsonContent:a,isRawJsonValid:u,rawJsonEdits:n,settings:p,onChange:v,missingRequiredFields:je})]})]}),e.jsx(B,{open:f,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>Y(!0),onCancel:()=>Y(!1)})]},s)}const ae="ccs:openrouter-banner-dismissed";function ds({onCreateClick:s}){const[t,i]=c.useState(!0),{modelCount:l,isLoading:d}=q();c.useEffect(()=>{const x=localStorage.getItem(ae)==="true";i(x)},[]);const f=()=>{localStorage.setItem(ae,"true"),i(!0)};return t?null:e.jsx("div",{className:"bg-gradient-to-r from-accent to-accent/90 text-white px-4 py-3 relative shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-4 max-w-screen-xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"p-1.5 bg-white/20 rounded-md shrink-0",children:e.jsx(V,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"NEW: OpenRouter Integration"}),e.jsxs("p",{className:"text-xs text-white/80 truncate",children:["Browse ",d?"300+":`${l}+`," models from OpenAI, Anthropic, Google, Meta and more."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(g,{size:"sm",variant:"secondary",onClick:s,className:"bg-white text-accent hover:bg-white/90 h-8",children:"Try it now"}),e.jsxs("a",{href:"https://openrouter.ai",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-white/80 hover:text-white hidden sm:flex items-center gap-1",children:["Learn more",e.jsx(me,{className:"w-3 h-3"})]}),e.jsxs(g,{size:"icon",variant:"ghost",onClick:f,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(Be,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function xs({onOpenRouterClick:s,onCustomClick:t}){const{modelCount:i,isLoading:l}=q();return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20 p-8",children:e.jsxs("div",{className:"max-w-lg w-full space-y-6",children:[e.jsxs(Ve,{className:"border-accent/30 dark:border-accent/40 bg-gradient-to-br from-accent/5 to-background dark:from-accent/10",children:[e.jsxs(Ye,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-accent/10 dark:bg-accent/20",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"w-6 h-6"})}),e.jsx(S,{variant:"secondary",className:"bg-accent/10 text-accent dark:bg-accent/20 dark:text-accent-foreground",children:"Recommended"})]}),e.jsx(We,{className:"text-xl",children:"Start with OpenRouter"}),e.jsxs(Xe,{className:"text-base",children:["Access ",l?"300+":`${i}+`," models from OpenAI, Anthropic, Google, Meta and more - all through one API."]})]}),e.jsxs(Ze,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ue,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:"One API, all providers"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(V,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:"Model tier mapping"})]})]}),e.jsxs(g,{onClick:s,className:"w-full bg-accent hover:bg-accent/90 text-white",size:"lg",children:["Create OpenRouter Profile",e.jsx(Qe,{className:"w-4 h-4 ml-2"})]}),e.jsxs("p",{className:"text-xs text-center text-muted-foreground",children:["Get your API key at"," ",e.jsxs("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-1",children:["openrouter.ai/keys",e.jsx(me,{className:"w-3 h-3"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ee,{className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),e.jsx(ee,{className:"flex-1"})]}),e.jsx(g,{variant:"outline",onClick:t,className:"w-full",children:"Create Custom API Profile"})]})})}function ms({onCreateClick:s}){const{modelCount:t,isLoading:i}=q();return e.jsx("div",{className:"p-3 border-t bg-gradient-to-r from-accent/5 to-accent/10 dark:from-accent/10 dark:to-accent/15",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-accent/10 dark:bg-accent/20 rounded shrink-0",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"",className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-accent dark:text-accent-foreground",children:"OpenRouter"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground truncate",children:[i?"300+":`${t}+`," models available"]})]}),e.jsxs(g,{size:"sm",variant:"ghost",onClick:s,className:"h-7 px-2 text-accent hover:text-accent hover:bg-accent/10 dark:hover:bg-accent/20",children:[e.jsx(ue,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function As(){const{data:s,isLoading:t,isError:i,refetch:l}=Se(),d=Pe(),[f,x]=c.useState(null),[n,o]=c.useState(""),[m,j]=c.useState(!1),[O,A]=c.useState("normal"),[N,b]=c.useState(null),[k,_]=c.useState(!1),[C,p]=c.useState(null);Re();const r=c.useMemo(()=>s?.profiles||[],[s?.profiles]),a=c.useMemo(()=>r.filter(u=>u.name.toLowerCase().includes(n.toLowerCase())),[r,n]),v=f?r.find(u=>u.name===f):null,R=u=>{d.mutate(u,{onSuccess:()=>{f===u&&x(null),b(null)}})},H=u=>{j(!1),k&&f!==null?p(u):x(u)},F=u=>{k&&f!==u?p(u):x(u)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:[e.jsx(ds,{onCreateClick:()=>j(!0)}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"API Profiles"})]}),e.jsxs(g,{size:"sm",onClick:()=>{j(!0)},children:[e.jsx(D,{className:"w-4 h-4 mr-1"}),"New"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(de,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(y,{placeholder:"Search profiles...",className:"pl-8 h-9",value:n,onChange:u=>o(u.target.value)})]})]}),e.jsx(I,{className:"flex-1",children:t?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading profiles..."}):i?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(he,{className:"w-12 h-12 mx-auto text-destructive/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Failed to load profiles"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Unable to fetch API profiles. Please try again."})]}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>l(),children:[e.jsx(U,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):a.length===0?e.jsx("div",{className:"p-4 text-center",children:r.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(Ge,{className:"w-12 h-12 mx-auto text-muted-foreground/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"No API profiles yet"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Create your first profile to connect to custom API endpoints"})]}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>{j(!0)},children:[e.jsx(D,{className:"w-4 h-4 mr-1"}),"Create Profile"]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground py-4",children:['No profiles match "',n,'"']})}):e.jsx("div",{className:"p-2 space-y-1",children:a.map(u=>e.jsx(us,{profile:u,isSelected:f===u.name,onSelect:()=>F(u.name),onDelete:()=>b(u.name)},u.name))})}),r.length>0&&e.jsx("div",{className:"p-3 border-t bg-background text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[r.length," profile",r.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(fe,{className:"w-3 h-3 text-green-600"}),r.filter(u=>u.configured).length," configured"]})]})}),e.jsx(ms,{onCreateClick:()=>{A("openrouter"),j(!0)}})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:v?e.jsx(os,{profileName:v.name,onDelete:()=>b(v.name),onHasChangesUpdate:_},v.name):e.jsx(xs,{onOpenRouterClick:()=>{A("openrouter"),j(!0)},onCustomClick:()=>{A("normal"),j(!0)}})})]}),e.jsx(Le,{open:m,onOpenChange:j,onSuccess:H,initialMode:O}),e.jsx(B,{open:!!N,title:"Delete Profile",description:`Are you sure you want to delete "${N}"? This will remove the settings file and cannot be undone.`,confirmText:"Delete",variant:"destructive",onConfirm:()=>N&&R(N),onCancel:()=>b(null)}),e.jsx(B,{open:!!C,title:"Unsaved Changes",description:`You have unsaved changes in "${f}". Discard and switch to "${C}"?`,confirmText:"Discard & Switch",variant:"destructive",onConfirm:()=>{_(!1),x(C),p(null)},onCancel:()=>p(null)})]})}function us({profile:s,isSelected:t,onSelect:i,onDelete:l}){return e.jsxs("div",{className:E("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:i,children:[s.configured?e.jsx(fe,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(he,{className:"w-4 h-4 text-yellow-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground truncate flex-1",children:s.settingsPath}),e.jsx(M,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(g,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:d=>{d.stopPropagation(),l()},children:e.jsx(oe,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{As as ApiPage};
@@ -1 +0,0 @@
1
- import{j as r}from"./radix-ui-CBgg0XeO.js";import"./react-vendor-B_CU-WTZ.js";import{c as d}from"./index-B7MyxZLG.js";function n({className:a,...t}){return r.jsx("div",{"data-slot":"card",className:d("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",a),...t})}function c({className:a,...t}){return r.jsx("div",{"data-slot":"card-header",className:d("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",a),...t})}function i({className:a,...t}){return r.jsx("div",{"data-slot":"card-title",className:d("leading-none font-semibold",a),...t})}function l({className:a,...t}){return r.jsx("div",{"data-slot":"card-description",className:d("text-muted-foreground text-sm",a),...t})}function u({className:a,...t}){return r.jsx("div",{"data-slot":"card-content",className:d("px-6",a),...t})}export{n as C,u as a,c as b,i as c,l as d};