@kaitranntt/ccs 7.78.1 → 7.79.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 (173) hide show
  1. package/dist/bin/ccsxp-runtime.d.ts +1 -0
  2. package/dist/bin/ccsxp-runtime.d.ts.map +1 -1
  3. package/dist/bin/ccsxp-runtime.js +2 -0
  4. package/dist/bin/ccsxp-runtime.js.map +1 -1
  5. package/dist/channels/official-channels-runtime.d.ts.map +1 -1
  6. package/dist/channels/official-channels-runtime.js +11 -0
  7. package/dist/channels/official-channels-runtime.js.map +1 -1
  8. package/dist/channels/official-channels-store.d.ts.map +1 -1
  9. package/dist/channels/official-channels-store.js +3 -4
  10. package/dist/channels/official-channels-store.js.map +1 -1
  11. package/dist/cliproxy/auth/oauth-handler.d.ts.map +1 -1
  12. package/dist/cliproxy/auth/oauth-handler.js +21 -0
  13. package/dist/cliproxy/auth/oauth-handler.js.map +1 -1
  14. package/dist/cliproxy/auth/oauth-start-failure-guidance.d.ts +22 -0
  15. package/dist/cliproxy/auth/oauth-start-failure-guidance.d.ts.map +1 -0
  16. package/dist/cliproxy/auth/oauth-start-failure-guidance.js +82 -0
  17. package/dist/cliproxy/auth/oauth-start-failure-guidance.js.map +1 -0
  18. package/dist/cliproxy/executor/claude-launcher.d.ts.map +1 -1
  19. package/dist/cliproxy/executor/claude-launcher.js +22 -9
  20. package/dist/cliproxy/executor/claude-launcher.js.map +1 -1
  21. package/dist/cliproxy/executor/session-bridge.d.ts +16 -1
  22. package/dist/cliproxy/executor/session-bridge.d.ts.map +1 -1
  23. package/dist/cliproxy/executor/session-bridge.js +86 -54
  24. package/dist/cliproxy/executor/session-bridge.js.map +1 -1
  25. package/dist/commands/config-command-options.d.ts.map +1 -1
  26. package/dist/commands/config-command-options.js +4 -2
  27. package/dist/commands/config-command-options.js.map +1 -1
  28. package/dist/commands/config-command.js +1 -1
  29. package/dist/commands/config-command.js.map +1 -1
  30. package/dist/commands/config-dashboard-host.d.ts +1 -0
  31. package/dist/commands/config-dashboard-host.d.ts.map +1 -1
  32. package/dist/commands/config-dashboard-host.js +2 -1
  33. package/dist/commands/config-dashboard-host.js.map +1 -1
  34. package/dist/dispatcher/flows/settings-flow.d.ts.map +1 -1
  35. package/dist/dispatcher/flows/settings-flow.js +21 -10
  36. package/dist/dispatcher/flows/settings-flow.js.map +1 -1
  37. package/dist/dispatcher/profile-resolver.d.ts.map +1 -1
  38. package/dist/dispatcher/profile-resolver.js +14 -1
  39. package/dist/dispatcher/profile-resolver.js.map +1 -1
  40. package/dist/management/checks/profile-check.d.ts.map +1 -1
  41. package/dist/management/checks/profile-check.js +2 -3
  42. package/dist/management/checks/profile-check.js.map +1 -1
  43. package/dist/management/checks/symlink-check.d.ts.map +1 -1
  44. package/dist/management/checks/symlink-check.js +2 -3
  45. package/dist/management/checks/symlink-check.js.map +1 -1
  46. package/dist/management/checks/system-check.d.ts.map +1 -1
  47. package/dist/management/checks/system-check.js +1 -1
  48. package/dist/management/checks/system-check.js.map +1 -1
  49. package/dist/management/instance-directory.d.ts +4 -0
  50. package/dist/management/instance-directory.d.ts.map +1 -0
  51. package/dist/management/instance-directory.js +54 -0
  52. package/dist/management/instance-directory.js.map +1 -0
  53. package/dist/management/instance-manager.d.ts.map +1 -1
  54. package/dist/management/instance-manager.js +2 -10
  55. package/dist/management/instance-manager.js.map +1 -1
  56. package/dist/management/shared-manager.d.ts.map +1 -1
  57. package/dist/management/shared-manager.js +6 -16
  58. package/dist/management/shared-manager.js.map +1 -1
  59. package/dist/proxy/proxy-daemon-entry.js +46 -3
  60. package/dist/proxy/proxy-daemon-entry.js.map +1 -1
  61. package/dist/proxy/proxy-daemon-state.d.ts +2 -0
  62. package/dist/proxy/proxy-daemon-state.d.ts.map +1 -1
  63. package/dist/proxy/proxy-daemon-state.js +42 -4
  64. package/dist/proxy/proxy-daemon-state.js.map +1 -1
  65. package/dist/proxy/proxy-daemon.d.ts.map +1 -1
  66. package/dist/proxy/proxy-daemon.js +11 -6
  67. package/dist/proxy/proxy-daemon.js.map +1 -1
  68. package/dist/proxy/transformers/sse-stream-transformer.d.ts.map +1 -1
  69. package/dist/proxy/transformers/sse-stream-transformer.js +1 -0
  70. package/dist/proxy/transformers/sse-stream-transformer.js.map +1 -1
  71. package/dist/shared/toml-object.d.ts.map +1 -1
  72. package/dist/shared/toml-object.js +6 -2
  73. package/dist/shared/toml-object.js.map +1 -1
  74. package/dist/targets/codex-adapter.d.ts +1 -0
  75. package/dist/targets/codex-adapter.d.ts.map +1 -1
  76. package/dist/targets/codex-adapter.js +18 -1
  77. package/dist/targets/codex-adapter.js.map +1 -1
  78. package/dist/targets/codex-cliproxy-provider-config.d.ts +16 -0
  79. package/dist/targets/codex-cliproxy-provider-config.d.ts.map +1 -0
  80. package/dist/targets/codex-cliproxy-provider-config.js +156 -0
  81. package/dist/targets/codex-cliproxy-provider-config.js.map +1 -0
  82. package/dist/targets/target-runtime-compatibility.js +1 -1
  83. package/dist/targets/target-runtime-compatibility.js.map +1 -1
  84. package/dist/ui/assets/{accounts-CW9bbE4S.js → accounts-BQu3Aeey.js} +1 -1
  85. package/dist/ui/assets/{alert-dialog-ClPYGzV3.js → alert-dialog-DC1l1GRX.js} +1 -1
  86. package/dist/ui/assets/{api-BjpAFHdA.js → api-BTbrbjic.js} +1 -1
  87. package/dist/ui/assets/{auth-section-wl4-fzwD.js → auth-section-BsSVWOMp.js} +1 -1
  88. package/dist/ui/assets/{backups-section-CRfyOhtX.js → backups-section-BGHYHASS.js} +1 -1
  89. package/dist/ui/assets/{channels-DH0HkSGX.js → channels-vJ8L4j-z.js} +1 -1
  90. package/dist/ui/assets/{checkbox-CTpEjpTH.js → checkbox-Dgd2ucy2.js} +1 -1
  91. package/dist/ui/assets/{claude-extension-BQOBO5Au.js → claude-extension-B3ern4Ad.js} +1 -1
  92. package/dist/ui/assets/cliproxy-CGljI0Or.js +4 -0
  93. package/dist/ui/assets/{cliproxy-ai-providers-DoUPKyI5.js → cliproxy-ai-providers-DxoCNEaQ.js} +1 -1
  94. package/dist/ui/assets/{cliproxy-control-panel-CvjXdHw9.js → cliproxy-control-panel-BJ3Mliy1.js} +1 -1
  95. package/dist/ui/assets/codex-DBGHPn0v.js +30 -0
  96. package/dist/ui/assets/{confirm-dialog-CYj_LLWN.js → confirm-dialog-nDFNrH0F.js} +1 -1
  97. package/dist/ui/assets/{copilot-ZCJeM_Zk.js → copilot-CE_Z3NB0.js} +1 -1
  98. package/dist/ui/assets/{cursor-CtBjQ1_j.js → cursor-YzGsSR_d.js} +1 -1
  99. package/dist/ui/assets/{droid-BLmzMBtN.js → droid-C-ItViCi.js} +1 -1
  100. package/dist/ui/assets/{globalenv-section-0ENDeVbM.js → globalenv-section-C9gSGyZ8.js} +1 -1
  101. package/dist/ui/assets/{health-BEnDHk-j.js → health-DEeA97sQ.js} +1 -1
  102. package/dist/ui/assets/index-B71yJlMj.css +1 -0
  103. package/dist/ui/assets/{index-Cip18A41.js → index-BPVO-QAw.js} +1 -1
  104. package/dist/ui/assets/index-BRZp_Csi.js +72 -0
  105. package/dist/ui/assets/{index-O9Qq-UJq.js → index-BYUwpOeA.js} +1 -1
  106. package/dist/ui/assets/{index-ClMz157R.js → index-D2r_fAW5.js} +1 -1
  107. package/dist/ui/assets/{index-B3xma6R0.js → index-DGiziSVQ.js} +1 -1
  108. package/dist/ui/assets/{index-C04Kst21.js → index-DwG6bbUr.js} +1 -1
  109. package/dist/ui/assets/{index-DrCrZ7r1.js → index-Dwtj4wGT.js} +1 -1
  110. package/dist/ui/assets/{logs-DQxVdsHm.js → logs-Mt2W7M3G.js} +1 -1
  111. package/dist/ui/assets/{masked-input-eN6tFUjN.js → masked-input-5TJ4LSuz.js} +1 -1
  112. package/dist/ui/assets/{proxy-status-widget-50UIM6S8.js → proxy-status-widget-BQOAlYsb.js} +1 -1
  113. package/dist/ui/assets/raw-json-settings-editor-panel-Fg4WMiuD.js +1 -0
  114. package/dist/ui/assets/{searchable-select-JO0gngYE.js → searchable-select-CPJn5vA1.js} +1 -1
  115. package/dist/ui/assets/{separator-AoncAA6l.js → separator-BrQkfpAp.js} +1 -1
  116. package/dist/ui/assets/{shared-BTv96-3y.js → shared-BlkDl2HF.js} +1 -1
  117. package/dist/ui/assets/{table-BM_YK49c.js → table-DRzNRkpJ.js} +1 -1
  118. package/dist/ui/assets/{updates-eo4H4NOg.js → updates-BQNeSzLj.js} +1 -1
  119. package/dist/ui/assets/{use-accounts-ELLatpzU.js → use-accounts-B6AXtlfF.js} +1 -1
  120. package/dist/ui/index.html +2 -2
  121. package/dist/utils/browser/claude-tool-args.d.ts.map +1 -1
  122. package/dist/utils/browser/claude-tool-args.js +4 -0
  123. package/dist/utils/browser/claude-tool-args.js.map +1 -1
  124. package/dist/utils/claude-detector.d.ts.map +1 -1
  125. package/dist/utils/claude-detector.js +2 -1
  126. package/dist/utils/claude-detector.js.map +1 -1
  127. package/dist/utils/claude-subcommand-detector.d.ts +45 -0
  128. package/dist/utils/claude-subcommand-detector.d.ts.map +1 -0
  129. package/dist/utils/claude-subcommand-detector.js +179 -0
  130. package/dist/utils/claude-subcommand-detector.js.map +1 -0
  131. package/dist/utils/image-analysis/claude-tool-args.d.ts.map +1 -1
  132. package/dist/utils/image-analysis/claude-tool-args.js +4 -0
  133. package/dist/utils/image-analysis/claude-tool-args.js.map +1 -1
  134. package/dist/utils/shell-executor.d.ts +4 -2
  135. package/dist/utils/shell-executor.d.ts.map +1 -1
  136. package/dist/utils/shell-executor.js +59 -7
  137. package/dist/utils/shell-executor.js.map +1 -1
  138. package/dist/utils/websearch/claude-tool-args.d.ts.map +1 -1
  139. package/dist/utils/websearch/claude-tool-args.js +5 -0
  140. package/dist/utils/websearch/claude-tool-args.js.map +1 -1
  141. package/dist/web-server/health/profile-checks.d.ts.map +1 -1
  142. package/dist/web-server/health/profile-checks.js +2 -3
  143. package/dist/web-server/health/profile-checks.js.map +1 -1
  144. package/dist/web-server/health/symlink-checks.d.ts.map +1 -1
  145. package/dist/web-server/health/symlink-checks.js +2 -3
  146. package/dist/web-server/health/symlink-checks.js.map +1 -1
  147. package/dist/web-server/index.d.ts.map +1 -1
  148. package/dist/web-server/index.js +80 -20
  149. package/dist/web-server/index.js.map +1 -1
  150. package/dist/web-server/middleware/auth-middleware.d.ts +5 -0
  151. package/dist/web-server/middleware/auth-middleware.d.ts.map +1 -1
  152. package/dist/web-server/middleware/auth-middleware.js +73 -1
  153. package/dist/web-server/middleware/auth-middleware.js.map +1 -1
  154. package/dist/web-server/routes/cliproxy-auth-routes.d.ts.map +1 -1
  155. package/dist/web-server/routes/cliproxy-auth-routes.js +30 -3
  156. package/dist/web-server/routes/cliproxy-auth-routes.js.map +1 -1
  157. package/dist/web-server/routes/codex-routes.d.ts.map +1 -1
  158. package/dist/web-server/routes/codex-routes.js +7 -0
  159. package/dist/web-server/routes/codex-routes.js.map +1 -1
  160. package/dist/web-server/routes/settings-routes.d.ts.map +1 -1
  161. package/dist/web-server/routes/settings-routes.js +92 -14
  162. package/dist/web-server/routes/settings-routes.js.map +1 -1
  163. package/dist/web-server/usage/aggregator.d.ts.map +1 -1
  164. package/dist/web-server/usage/aggregator.js +2 -5
  165. package/dist/web-server/usage/aggregator.js.map +1 -1
  166. package/lib/hooks/image-analyzer-transformer.cjs +49 -3
  167. package/lib/mcp/ccs-browser-server.cjs +153 -6
  168. package/package.json +1 -1
  169. package/dist/ui/assets/cliproxy-qUbiZjec.js +0 -3
  170. package/dist/ui/assets/codex-BeeazJpw.js +0 -27
  171. package/dist/ui/assets/index-Bs28kNJN.js +0 -72
  172. package/dist/ui/assets/index-D2_yb3d2.css +0 -1
  173. package/dist/ui/assets/raw-json-settings-editor-panel-DqKmVWL-.js +0 -1
@@ -151,6 +151,8 @@ const DEFAULT_DRAG_STEPS = 5;
151
151
  const MAX_POINTER_ACTIONS = 25;
152
152
  const SESSION_START_SETTLE_WINDOW_MS = 250;
153
153
  const MAX_ARTIFACT_FILE_BYTES = 5 * 1024 * 1024;
154
+ const MAX_LOCAL_TRANSFER_FILE_BYTES = 10 * 1024 * 1024;
155
+ const MAX_LOCAL_TRANSFER_FILES = 10;
154
156
  const SAFE_ARTIFACT_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
155
157
  const SESSION_CANCELED_ERROR_CODE = 'SESSION_CANCELED';
156
158
 
@@ -177,6 +179,37 @@ const recentDownloads = [];
177
179
  const interceptSessionsByPageId = new Map();
178
180
  let browserDownloadSession = null;
179
181
  let sessionDownloadDir = '';
182
+ const SENSITIVE_LOCAL_PATH_SEGMENTS = new Set([
183
+ '.ssh',
184
+ '.gnupg',
185
+ '.aws',
186
+ '.azure',
187
+ '.kube',
188
+ '.docker',
189
+ '.npmrc',
190
+ '.netrc',
191
+ '.pypirc',
192
+ '.config',
193
+ '.claude',
194
+ '.ccs',
195
+ ]);
196
+ const SENSITIVE_LOCAL_FILE_NAMES = new Set([
197
+ '.env',
198
+ 'id_rsa',
199
+ 'id_dsa',
200
+ 'id_ecdsa',
201
+ 'id_ed25519',
202
+ 'known_hosts',
203
+ 'authorized_keys',
204
+ 'credentials',
205
+ 'credentials.json',
206
+ 'config.json',
207
+ 'settings.json',
208
+ 'history',
209
+ '.bash_history',
210
+ '.zsh_history',
211
+ '.fish_history',
212
+ ]);
180
213
  const MAX_RECENT_REQUESTS = 100;
181
214
  const MAX_RECENT_DOWNLOADS = 100;
182
215
  const FETCH_FAIL_ERROR_REASON = 'Failed';
@@ -1438,10 +1471,105 @@ function getSessionDownloadPath() {
1438
1471
  return sessionDownloadDir;
1439
1472
  }
1440
1473
 
1474
+ function splitConfiguredPathRoots(value) {
1475
+ return String(value || '')
1476
+ .split(path.delimiter)
1477
+ .map((entry) => entry.trim())
1478
+ .filter(Boolean)
1479
+ .map((entry) => path.resolve(entry));
1480
+ }
1481
+
1482
+ function getDownloadSafeRoots() {
1483
+ return [
1484
+ getSessionDownloadPath(),
1485
+ ...splitConfiguredPathRoots(process.env.CCS_BROWSER_DOWNLOAD_ROOTS),
1486
+ ];
1487
+ }
1488
+
1489
+ function getUploadSafeRoots() {
1490
+ return [
1491
+ getSessionDownloadPath(),
1492
+ ...splitConfiguredPathRoots(process.env.CCS_BROWSER_UPLOAD_ROOTS),
1493
+ ];
1494
+ }
1495
+
1496
+ function getNearestExistingAncestor(candidatePath) {
1497
+ let currentPath = candidatePath;
1498
+ while (!fs.existsSync(currentPath)) {
1499
+ const parentPath = path.dirname(currentPath);
1500
+ if (parentPath === currentPath) {
1501
+ return currentPath;
1502
+ }
1503
+ currentPath = parentPath;
1504
+ }
1505
+ return currentPath;
1506
+ }
1507
+
1508
+ function resolveExistingRoot(rootPath) {
1509
+ fs.mkdirSync(rootPath, { recursive: true });
1510
+ return fs.realpathSync(rootPath);
1511
+ }
1512
+
1513
+ function resolvePathWithRealAncestor(candidatePath) {
1514
+ const resolvedPath = path.resolve(candidatePath);
1515
+ const ancestorPath = getNearestExistingAncestor(resolvedPath);
1516
+ const realAncestorPath = fs.realpathSync(ancestorPath);
1517
+ const relativeSuffix = path.relative(ancestorPath, resolvedPath);
1518
+ return relativeSuffix ? path.resolve(realAncestorPath, relativeSuffix) : realAncestorPath;
1519
+ }
1520
+
1521
+ function isPathInsideRoot(candidatePath, rootPath) {
1522
+ const relativePath = path.relative(rootPath, candidatePath);
1523
+ return relativePath === '' || (!relativePath.startsWith('..') && !path.isAbsolute(relativePath));
1524
+ }
1525
+
1526
+ function findContainingRoot(candidatePath, rootPaths) {
1527
+ return rootPaths.find((rootPath) => isPathInsideRoot(candidatePath, rootPath)) || '';
1528
+ }
1529
+
1530
+ function getLocalPathSegments(candidatePath, rootPath) {
1531
+ const rootSegments = path.resolve(rootPath).split(path.sep).filter(Boolean);
1532
+ const relativePath = path.relative(rootPath, candidatePath);
1533
+ const relativeSegments = relativePath.split(path.sep).filter(Boolean);
1534
+ return [...rootSegments, ...relativeSegments];
1535
+ }
1536
+
1537
+ function assertNoSensitiveLocalPathSegments(candidatePath, rootPath, label) {
1538
+ const segments = getLocalPathSegments(candidatePath, rootPath);
1539
+ for (const segment of segments) {
1540
+ const normalizedSegment = segment.toLowerCase();
1541
+ if (normalizedSegment.startsWith('.') || SENSITIVE_LOCAL_PATH_SEGMENTS.has(normalizedSegment)) {
1542
+ throw new Error(`${label} cannot include hidden or sensitive path segment: ${segment}`);
1543
+ }
1544
+ }
1545
+
1546
+ const fileName = path.basename(candidatePath).toLowerCase();
1547
+ if (SENSITIVE_LOCAL_FILE_NAMES.has(fileName)) {
1548
+ throw new Error(
1549
+ `${label} cannot reference sensitive file name: ${path.basename(candidatePath)}`
1550
+ );
1551
+ }
1552
+ }
1553
+
1441
1554
  function ensureWritableDirectory(downloadPath) {
1442
- fs.mkdirSync(downloadPath, { recursive: true });
1443
- fs.accessSync(downloadPath, fs.constants.W_OK);
1444
- return downloadPath;
1555
+ const resolvedPath = path.resolve(downloadPath);
1556
+ const candidatePath = resolvePathWithRealAncestor(resolvedPath);
1557
+ const safeRoots = getDownloadSafeRoots().map(resolveExistingRoot);
1558
+ const containingRoot = findContainingRoot(candidatePath, safeRoots);
1559
+ if (!containingRoot) {
1560
+ throw new Error(
1561
+ 'downloadPath must be inside the browser session download directory or a CCS_BROWSER_DOWNLOAD_ROOTS entry'
1562
+ );
1563
+ }
1564
+ assertNoSensitiveLocalPathSegments(candidatePath, containingRoot, 'downloadPath');
1565
+
1566
+ fs.mkdirSync(resolvedPath, { recursive: true });
1567
+ const realDownloadPath = fs.realpathSync(resolvedPath);
1568
+ if (!isPathInsideRoot(realDownloadPath, containingRoot)) {
1569
+ throw new Error('downloadPath cannot traverse outside the allowed download root');
1570
+ }
1571
+ fs.accessSync(realDownloadPath, fs.constants.W_OK);
1572
+ return realDownloadPath;
1445
1573
  }
1446
1574
 
1447
1575
  function pushRecentDownload(entry) {
@@ -2418,16 +2546,35 @@ function buildFileInputHandleExpression(selector, nth, frameSelector, pierceShad
2418
2546
  }
2419
2547
 
2420
2548
  function validateLocalFiles(files) {
2549
+ if (files.length > MAX_LOCAL_TRANSFER_FILES) {
2550
+ throw new Error(`files exceeds maximum of ${MAX_LOCAL_TRANSFER_FILES}`);
2551
+ }
2552
+
2553
+ const safeRoots = getUploadSafeRoots().map(resolveExistingRoot);
2421
2554
  return files.map((filePath) => {
2422
2555
  const resolvedPath = path.resolve(filePath);
2423
2556
  if (!fs.existsSync(resolvedPath)) {
2424
2557
  throw new Error(`file does not exist: ${resolvedPath}`);
2425
2558
  }
2426
- const stat = fs.statSync(resolvedPath);
2559
+ const realFilePath = fs.realpathSync(resolvedPath);
2560
+ const containingRoot = findContainingRoot(realFilePath, safeRoots);
2561
+ if (!containingRoot) {
2562
+ throw new Error(
2563
+ 'file must be inside the browser session download directory or a CCS_BROWSER_UPLOAD_ROOTS entry'
2564
+ );
2565
+ }
2566
+ assertNoSensitiveLocalPathSegments(realFilePath, containingRoot, 'file');
2567
+
2568
+ const stat = fs.statSync(realFilePath);
2427
2569
  if (!stat.isFile()) {
2428
- throw new Error(`file is not a regular file: ${resolvedPath}`);
2570
+ throw new Error(`file is not a regular file: ${realFilePath}`);
2571
+ }
2572
+ if (stat.size > MAX_LOCAL_TRANSFER_FILE_BYTES) {
2573
+ throw new Error(
2574
+ `file exceeds maximum size of ${MAX_LOCAL_TRANSFER_FILE_BYTES} bytes: ${realFilePath}`
2575
+ );
2429
2576
  }
2430
- return resolvedPath;
2577
+ return realFilePath;
2431
2578
  });
2432
2579
  }
2433
2580
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaitranntt/ccs",
3
- "version": "7.78.1",
3
+ "version": "7.79.1",
4
4
  "description": "Claude Code Switch - Instant profile switching between Claude, GLM, Kimi, and more",
5
5
  "keywords": [
6
6
  "cli",
@@ -1,3 +0,0 @@
1
- import{j as e}from"./radix-ui-nu4wz29m.js";import{r as c}from"./react-vendor-Bjx91N7w.js";import{a as ft,u as Qt,b as Ss}from"./tanstack-bhJxV1h8.js";import{a8 as As,a as W,d as K,C as Jt,b as Xt,a9 as Yt,aa as Zt,c as X,P as vt,B as H,ab as ue,L as Y,I as de,r as ze,s as Ge,t as Be,v as Ve,w as ye,ac as es,ad as ts,ae as Ms,af as Ps,ag as Ds,u as ss,ah as jt,ai as bt,aj as Nt,ak as yt,W as me,al as as,am as Et,an as Is,ao as Ts,ap as Je,aq as ns,Y as $e,ar as Es,as as Rt,at as _t,au as Rs,av as _s,aw as Os,ax as Ls,ay as Fs,az as Us,aA as Ks,aB as Hs,aC as Ot,aD as qs,x as is,aE as zs,n as kt,aF as Gs,aG as wt,aH as Lt,aI as rs,aJ as Bs,m as Vs,aK as $s,aL as Ws,aM as ct,T as ut,p as mt,q as pt,aN as Qs,aO as Js,aP as Xs,aQ as Ft,aR as Ys,aS as Zs,aT as ea,aU as ta,aV as sa,aW as aa,Q as na,R as ia,U as Ut,V as Kt,aX as ra,aY as oa,aZ as la,a_ as da,a$ as ca,b0 as ua,b1 as ma,b2 as pa,b3 as xa,b4 as ha,b5 as ga,b6 as fa,b7 as va,S as ja}from"./index-Bs28kNJN.js";import{C as xt}from"./default-ports-1QQSffYX.js";import{t as B}from"./notifications-B4_o8bcr.js";import{C as os,L as ce,p as ke,$ as ba,m as we,o as ls,aG as Ct,R as St,q as Pe,aa as De,T as Xe,a7 as Ht,aH as ds,aF as Na,z as At,Z as Ie,_ as cs,i as ya,u as us,aI as ka,au as wa,X as Mt,a9 as ms,J as ps,D as xs,aJ as Ca,at as hs,aK as Sa,ax as Aa,aL as gs}from"./icons-DzKUh8vG.js";import{R as We,A as qt,D as it,i as Ma,a as Pa}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{C as Qe}from"./checkbox-CTpEjpTH.js";import{C as Da}from"./confirm-dialog-CYj_LLWN.js";import{S as Pt}from"./separator-AoncAA6l.js";import{S as Ia}from"./searchable-select-JO0gngYE.js";import{P as Ta}from"./proxy-status-widget-50UIM6S8.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./code-highlight-D4E79GKQ.js";import"./alert-dialog-ClPYGzV3.js";const se="gemini-3.1-pro-high",Ce="gemini-3.1-pro-low",Ea=Object.freeze({"gemini-3-pro-high":se,"gemini-3.1-pro-high":se,"gemini-3-pro-low":Ce,"gemini-3.1-pro-low":Ce,"gemini-3-pro-preview":se,"gemini-3-pro-preview-customtools":se,"gemini-3.1-pro-preview":se,"gemini-3.1-pro-preview-customtools":se,"gemini-3-1-pro-preview":se,"gemini-3-1-pro-preview-customtools":se}),fs=Object.freeze({"gemini-3-pro-preview":"gemini-3.1-pro-preview","gemini-3.1-pro-preview":"gemini-3-pro-preview","gemini-3-flash-preview":"gemini-3.1-flash-preview","gemini-3.1-flash-preview":"gemini-3-flash-preview"}),Ra=/^gemini-(\d+(?:[.-]\d+)*)-(pro|flash)-preview(-customtools)?$/i,_a=["agy/","gcli/"];function J(t){return As(t).toLowerCase()}function Oa(t){const a=t.trim(),s=a.toLowerCase();for(const n of _a)if(s.startsWith(n))return a.slice(n.length);return a}function La(t){return t.replace(/-customtools$/i,"")}function Fa(t){return Ea[J(t)]}function Ye(t){const a=J(t),s=a.match(Ra);if(!s)return null;const[,n,i,d]=s;return{normalizedId:a,version:n.split(/[.-]/).map(o=>Number(o)),family:i,customtools:!!d,dottedVersion:n.includes(".")}}function vs(t,a){const s=Math.max(t.length,a.length);for(let n=0;n<s;n+=1){const i=t[n]??0,d=a[n]??0;if(i!==d)return i>d?1:-1}return 0}function Ua(t,a,s){if(t.customtools!==a.customtools)return t.customtools?1:-1;const n=vs(t.version,a.version);if(n!==0)return n>0?-1:1;const i=+(t.dottedVersion===s.dottedVersion),d=+(a.dottedVersion===s.dottedVersion);return i!==d?d-i:t.normalizedId.localeCompare(a.normalizedId)}function zt(t,a){const s=J(a);return t.find(n=>J(n.id)===s)?.id}function Ka(t,a){const s=Ye(t);return!s||a.length===0?void 0:a.map(i=>{const d=Ye(i.id);return!d||d.family!==s.family?null:{id:i.id,info:d}}).filter(i=>!!i).sort((i,d)=>Ua(i.info,d.info,s))[0]?.id}const xe={agy:{provider:"agy",displayName:"Antigravity",defaultModel:"claude-opus-4-6-thinking",models:[{id:"claude-opus-4-6-thinking",name:"Claude Opus 4.6 Thinking",description:"Latest flagship, extended thinking",extendedContext:!1,presetMapping:{default:"claude-opus-4-6-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",description:"Latest Sonnet with thinking budget support",presetMapping:{default:"claude-sonnet-4-6",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:se,name:"Gemini Pro High",description:"Current Antigravity Gemini Pro route with higher reasoning budget",extendedContext:!0,presetMapping:{default:se,opus:se,sonnet:se,haiku:"gemini-3-1-flash-preview"}},{id:Ce,name:"Gemini Pro Low",description:"Current Antigravity Gemini Pro route with the lighter quota tier",extendedContext:!0,presetMapping:{default:Ce,opus:Ce,sonnet:Ce,haiku:"gemini-3-1-flash-preview"}},{id:"gemini-3-1-flash-preview",name:"Gemini Flash",description:"Resolves to the best advertised Gemini Flash preview via Antigravity",extendedContext:!0,presetMapping:{default:"gemini-3-1-flash-preview",opus:se,sonnet:se,haiku:"gemini-3-1-flash-preview"}}]},gemini:{provider:"gemini",displayName:"Gemini",defaultModel:"gemini-2.5-pro",models:[{id:"gemini-3.1-pro-preview",name:"Gemini Pro",tier:"paid",description:"Uses the best advertised Gemini Pro preview when Google exposes one",extendedContext:!0,presetMapping:{default:"gemini-3.1-pro-preview",opus:"gemini-3.1-pro-preview",sonnet:"gemini-3.1-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini Flash",tier:"paid",description:"Uses the best advertised Gemini Flash preview when Google exposes one",extendedContext:!0,presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3.1-pro-preview",sonnet:"gemini-3.1-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro",description:"Stable, works with free Google account",extendedContext:!0,presetMapping:{default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-2.5-flash"}}]},codex:{provider:"codex",displayName:"Codex",defaultModel:"gpt-5.4",models:[{id:"gpt-5.5",name:"GPT-5.5",tier:"paid",description:"Newest Codex-released GPT-5 family model; falls back to GPT-5.4 on free plans",codexMaxEffort:"xhigh",codexServiceTiers:["fast"],presetMapping:{default:"gpt-5.5",opus:"gpt-5.5",sonnet:"gpt-5.5",haiku:"gpt-5.4-mini"}},{id:"gpt-5.4",name:"GPT-5.4",description:"Recommended Codex default for most coding and agentic tasks",codexMaxEffort:"xhigh",codexServiceTiers:["fast"],presetMapping:{default:"gpt-5.4",opus:"gpt-5.4",sonnet:"gpt-5.4",haiku:"gpt-5.4-mini"}},{id:"gpt-5.4-mini",name:"GPT-5.4 Mini",description:"Fast, lower-cost Codex option for lighter tasks and haiku-tier routing",codexMaxEffort:"high",presetMapping:{default:"gpt-5.4-mini",opus:"gpt-5.4",sonnet:"gpt-5.4",haiku:"gpt-5.4-mini"}},{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",tier:"paid",description:"Previous flagship coding model whose capabilities now power GPT-5.4",codexMaxEffort:"xhigh",presetMapping:{default:"gpt-5.3-codex",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5.4-mini"}},{id:"gpt-5.3-codex-spark",name:"GPT-5.3 Codex Spark",tier:"paid",description:"Research preview model for ChatGPT Pro subscribers, optimized for near-instant coding iteration",codexMaxEffort:"xhigh",presetMapping:{default:"gpt-5.3-codex-spark",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5.4-mini"}},{id:"gpt-5.2",name:"GPT-5.2",description:"Previous general-purpose Codex model",codexMaxEffort:"xhigh",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.2",haiku:"gpt-5.4-mini"}}]},qwen:{provider:"qwen",displayName:"Qwen",defaultModel:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Code-focused model (1M context)",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship model (256K context)",presetMapping:{default:"qwen3-max",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max-preview",name:"Qwen3 Max Preview",description:"Preview with thinking support (256K)",presetMapping:{default:"qwen3-max-preview",opus:"qwen3-max-preview",sonnet:"qwen3-max",haiku:"qwen3-coder-flash"}},{id:"qwen3-235b",name:"Qwen3 235B",description:"Large 235B A22B model",presetMapping:{default:"qwen3-235b",opus:"qwen3-max",sonnet:"qwen3-235b",haiku:"qwen3-coder-flash"}},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language multimodal"},{id:"qwen3-coder-flash",name:"Qwen3 Coder Flash",description:"Fast code generation"},{id:"qwen3-32b",name:"Qwen3 32B",description:"Qwen3 32B model"}]},iflow:{provider:"iflow",displayName:"iFlow",defaultModel:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Recommended default for iFlow accounts",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-coder-plus",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-plus"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship Qwen model via iFlow"},{id:"kimi-k2",name:"Kimi K2",description:"Kimi model currently available via iFlow"},{id:"deepseek-v3.2",name:"DeepSeek V3.2",description:"Current DeepSeek V3.2 model via iFlow"},{id:"deepseek-r1",name:"DeepSeek R1",description:"Reasoning-focused DeepSeek model"},{id:"glm-4.6",name:"GLM 4.6",description:"Zhipu GLM 4.6 via iFlow"},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language model"}]},kimi:{provider:"kimi",displayName:"Kimi (Moonshot)",defaultModel:"kimi-k2.5",models:[{id:"kimi-k2.5",name:"Kimi K2.5",description:"Latest multimodal model (262K context)",presetMapping:{default:"kimi-k2.5",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking",description:"Extended reasoning model",presetMapping:{default:"kimi-k2-thinking",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2",name:"Kimi K2",description:"Flagship coding model"}]},kiro:{provider:"kiro",displayName:"Kiro (AWS)",defaultModel:"kiro-claude-sonnet-4-6",models:[{id:"kiro-claude-opus-4-6",name:"Kiro Claude Opus 4.6",description:"Claude Opus 4.6 via Kiro (2.2x credit)",presetMapping:{default:"kiro-claude-opus-4-6",opus:"kiro-claude-opus-4-6",sonnet:"kiro-claude-sonnet-4-6",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4-6",name:"Kiro Claude Sonnet 4.6",description:"Claude Sonnet 4.6 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4-6",opus:"kiro-claude-opus-4-6",sonnet:"kiro-claude-sonnet-4-6",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-opus-4-5",name:"Kiro Claude Opus 4.5",description:"Claude Opus 4.5 via Kiro (2.2x credit)",presetMapping:{default:"kiro-claude-opus-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4-5",name:"Kiro Claude Sonnet 4.5",description:"Claude Sonnet 4.5 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4",name:"Kiro Claude Sonnet 4",description:"Claude Sonnet 4 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-haiku-4-5",name:"Kiro Claude Haiku 4.5",description:"Claude Haiku 4.5 via Kiro (0.4x credit)"}]},ghcp:{provider:"ghcp",displayName:"GitHub Copilot (OAuth)",defaultModel:"claude-sonnet-4.5",models:[{id:"claude-opus-4.5",name:"Claude Opus 4.5",description:"Anthropic Claude Opus 4.5 via GitHub Copilot",presetMapping:{default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4.5",name:"Claude Sonnet 4.5",description:"Anthropic Claude Sonnet 4.5 via GitHub Copilot",presetMapping:{default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4",name:"Claude Sonnet 4",description:"Anthropic Claude Sonnet 4 via GitHub Copilot"},{id:"claude-haiku-4.5",name:"Claude Haiku 4.5",description:"Anthropic Claude Haiku 4.5 via GitHub Copilot"},{id:"gpt-5.2",name:"GPT-5.2",description:"OpenAI GPT-5.2 via GitHub Copilot",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"}},{id:"gpt-5.1",name:"GPT-5.1",description:"OpenAI GPT-5.1 via GitHub Copilot"},{id:"gpt-5",name:"GPT-5",description:"OpenAI GPT-5 via GitHub Copilot"},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"OpenAI GPT-5 Mini via GitHub Copilot"},{id:"gemini-3-pro",name:"Gemini 3 Pro",description:"Google Gemini 3 Pro via GitHub Copilot"}]},claude:{provider:"claude",displayName:"Claude (Anthropic)",defaultModel:"claude-sonnet-4-6",models:[{id:"claude-opus-4-7",name:"Claude Opus 4.7",description:"Latest flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-7",opus:"claude-opus-4-7",sonnet:"claude-sonnet-4-6",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-opus-4-6",name:"Claude Opus 4.6",description:"Previous flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-6",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",description:"Balanced performance and speed",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-6",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5",description:"Most capable Claude model",extendedContext:!0,presetMapping:{default:"claude-opus-4-5-20251101",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5",description:"Balanced performance and speed",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-5-20250929",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4",description:"Previous generation Sonnet",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-20250514",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-20250514",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5",description:"Fast and efficient"}]}};function Ae(t,a){if(!t)return;const s=J(a);if(t.provider==="agy"){const o=Fa(s);if(o){const l=t.models.find(r=>r.id===o);if(l)return l}}const n=fs[s.toLowerCase()],i=t.models.find(o=>o.id===s||o.id===n);if(i)return i;const d=Ye(s);if(d)return t.models.map(o=>({model:o,info:Ye(o.id)})).filter(o=>!!(o.info&&o.info.family===d.family)).sort((o,l)=>vs(l.info.version,o.info.version))[0]?.model}function Ha(t){if(t==="free")return"free";if(typeof t=="string"&&t.trim().length>0)return"paid"}function qa(t,a){const s=xe[t.toLowerCase()];if(!a||a.models.length===0)return s;const n=a.models.map(l=>({id:l.id,owned_by:a.provider})),i=a.models.map(l=>{const r=Ae(s,l.id);return{...l,name:l.name||r?.name||l.id,tier:r?.tier??Ha(l.tier),description:l.description??r?.description,broken:r?.broken,issueUrl:r?.issueUrl,deprecated:r?.deprecated,deprecationReason:r?.deprecationReason,extendedContext:l.extendedContext??r?.extendedContext,presetMapping:r?.presetMapping}}),d=s?.defaultModel?Se(s.defaultModel,n):void 0,o=typeof d=="string"&&n.some(l=>J(l.id)===J(d));return{provider:a.provider,displayName:a.displayName||s?.displayName||t,defaultModel:o?d:a.defaultModel,models:i}}function Dt(t){const a={},s=new Set([...Object.keys(xe),...Object.keys(t??{})]);for(const n of s){const i=qa(n,t?.[n]);i&&(a[n]=i)}return a}function js(t,a,s){const n=Ae(s,a);return n||Ae(xe[t.toLowerCase()],a)}function Se(t,a=[]){const s=J(t),n=Ka(s,a);if(n)return n;const i=zt(a,s);if(i)return i;const d=fs[s];return(d?zt(a,d):void 0)??s}function za(t,a=[]){return{default:Se(t.default,a),opus:Se(t.opus,a),sonnet:Se(t.sonnet,a),haiku:Se(t.haiku,a)}}function It(t,a=[]){if(!t)return[];const s=xe[t.provider.toLowerCase()]??t,n=new Set;return s.models.map(i=>{const d=Se(i.id,a),o=i.presetMapping?za(i.presetMapping,a):void 0,l=t.models.find(r=>J(r.id)===J(d));return{...i,id:d,name:l?.name||i.name,description:l?.description??i.description,presetMapping:o}}).filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))}function Ga(t,a,s=[]){const n=t.trim().toLowerCase();if(!a||!n)return[];const i=xe[n]??a,d=It(a,s),o=new Set(d.map(p=>J(p.id))),l=new Set(d.map(p=>Ae(i,p.id)?.id).filter(p=>!!p).map(p=>J(p))),r=new Set,m=new Set(s.map(p=>J(p.id)));return s.filter(p=>{const j=J(p.id),g=Oa(p.id),h=La(g),E=Ae(i,g)??Ae(i,h);if(o.has(J(g))||j!==J(g)&&m.has(J(g)))return!1;const k=J(h);if(k!==J(g)&&m.has(k))return!1;const D=E?J(E.id):k;return E&&l.has(D)||r.has(D)||!E&&n==="agy"?!1:(r.add(D),!0)})}function Ba(t,a,s){return js(t,a,s)?.extendedContext===!0}const rt="ccs-internal-managed";async function Va(){try{const t=await fetch("/api/settings/auth/tokens/raw");return t.ok?(await t.json())?.apiKey?.value??rt:rt}catch{return rt}}async function $a(t,a){if(a)return a;try{const s=await fetch("/api/cliproxy/catalog");if(!s.ok)return xe[t];const n=await s.json();return Dt(n.catalogs)[t]??xe[t]}catch{return xe[t]}}async function ht(t,a,s){const n=await $a(t,s);if(!n)return{success:!1};const i=n.models.find(m=>m.id===n.defaultModel)||n.models[0],d=i?.presetMapping||{default:n.defaultModel,opus:n.defaultModel,sonnet:n.defaultModel,haiku:n.defaultModel},o=await Va(),r={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${xt}/api/provider/${t}`,ANTHROPIC_AUTH_TOKEN:o,ANTHROPIC_MODEL:d.default,ANTHROPIC_DEFAULT_OPUS_MODEL:d.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:d.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:d.haiku}};try{return{success:(await fetch(`/api/settings/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:r})})).ok,presetName:i?.name||n.defaultModel}}catch{return{success:!1}}}function Wa({currentProgress:t,allSteps:a}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:a.map((s,n)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${t>=n?"bg-primary":"bg-muted"}`},s))})}function Qa({providers:t,onSelect:a}){return e.jsx("div",{className:"grid gap-2",children:t.map(s=>e.jsxs("button",{onClick:()=>a(s.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:s.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.description})]}),e.jsx(os,{className:"w-4 h-4 text-muted-foreground"})]},s.id))})}function Ja({selectedProvider:t,providers:a,authCommand:s,isRefreshing:n,isPending:i,onBack:d,onStartAuth:o,onRefresh:l}){const{t:r}=W(),[m,p]=c.useState(!1),j=async g=>{await navigator.clipboard.writeText(g),p(!0),setTimeout(()=>p(!1),2e3)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:r("setupWizard.authStep.authenticateWith",{provider:a.find(g=>g.id===t)?.name})}),e.jsx(K,{onClick:o,disabled:i,className:"w-full gap-2",size:"lg",children:i?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 animate-spin"}),r("setupWizard.authStep.authenticating")]}):e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"w-4 h-4"}),r("setupWizard.authStep.authenticateInBrowser")]})}),i&&e.jsx("p",{className:"text-xs text-muted-foreground",children:r("setupWizard.authStep.completeOAuth")})]}),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:r("setupWizard.authStep.orUseTerminal")})})]}),e.jsx(Jt,{children:e.jsxs(Xt,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ba,{className:"w-4 h-4"}),r("setupWizard.authStep.runCommandHint")]}),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:s}),e.jsx(K,{variant:"outline",size:"icon",onClick:()=>j(s),children:m?e.jsx(we,{className:"w-4 h-4 text-green-500"}):e.jsx(ls,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(K,{variant:"ghost",onClick:d,disabled:i,children:[e.jsx(Ct,{className:"w-4 h-4 mr-2"}),r("setupWizard.authStep.back")]}),e.jsxs(K,{variant:"outline",onClick:l,disabled:n||i,children:[e.jsx(St,{className:`w-4 h-4 mr-2 ${n?"animate-spin":""}`}),r(n?"setupWizard.authStep.checking":"setupWizard.authStep.refreshStatus")]})]})]})}function Xa({accounts:t,privacyMode:a,onSelect:s,onAddNew:n,onBack:i}){const{t:d}=W();return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:d("setupWizard.accountStep.selectAccount",{count:t.length})}),e.jsx("div",{className:"grid gap-2 max-h-[320px] overflow-y-auto pr-1",children:t.map(o=>{const l=Yt(o.id,o.email,o.tokenFile),r=o.provider?.toLowerCase()==="codex"?Zt(l):null;return e.jsxs("button",{type:"button",onClick:()=>s(o),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(Pe,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:X("font-medium",a&&vt),children:l.email}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[r?.label?e.jsx(H,{variant:"outline",className:X("text-[10px] h-4 px-1.5 border-transparent",r.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":r.audience==="free"?"bg-slate-200/70 text-slate-700 dark:bg-slate-700/40 dark:text-slate-200":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:r.label}):l.audienceLabel?e.jsx(H,{variant:"outline",className:X("text-[10px] h-4 px-1.5 border-transparent",l.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":l.audience==="free"?"bg-slate-200/70 text-slate-700 dark:bg-slate-700/40 dark:text-slate-200":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:l.audienceLabel}):null,!r?.label&&l.detailLabel&&e.jsx(H,{variant:"outline",className:"text-[10px] h-4 px-1.5",children:l.detailLabel}),o.isDefault&&e.jsx("span",{className:"text-xs text-muted-foreground",children:d("setupWizard.accountStep.defaultAccount")})]})]})]}),e.jsx(os,{className:"w-4 h-4 text-muted-foreground"})]},o.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:d("setupWizard.accountStep.or")})})]}),e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 p-3 border-2 border-dashed border-primary/50 rounded-lg hover:border-primary hover:bg-primary/5 transition-colors text-left",onClick:n,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(ke,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary",children:d("setupWizard.accountStep.addNewAccount")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:d("setupWizard.accountStep.addNewAccountDesc")})]})]}),e.jsx("div",{className:"flex items-center justify-between pt-2",children:e.jsxs(K,{variant:"ghost",onClick:i,children:[e.jsx(Ct,{className:"w-4 h-4 mr-2"}),d("setupWizard.accountStep.back")]})})]})}const Gt="__custom__";function Ya({selectedProvider:t,catalog:a,selectedAccount:s,variantName:n,modelName:i,isPending:d,privacyMode:o,onVariantNameChange:l,onModelChange:r,onBack:m,onSkip:p,onCreate:j}){const{t:g}=W(),h=a||xe[t],E=h?.models||[],k=i&&!E.some(f=>f.id===i),[D,S]=c.useState(k),C=t==="agy"&&i.trim().length>0?ue(i):!1,y=s?Yt(s.id,s.email,s.tokenFile):null,w=t==="codex"&&y?Zt(y):null,x=f=>{f===Gt?(S(!0),r("")):(S(!1),r(f))};return e.jsxs("div",{className:"space-y-4",children:[s&&e.jsxs("div",{className:"flex items-start gap-2 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx(Pe,{className:"w-4 h-4"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("span",{children:[g("setupVariant.using")," ",e.jsx("span",{className:X(o&&vt),children:y?.email})]}),(y?.audienceLabel||y?.detailLabel)&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[w?.label?e.jsx(H,{variant:"outline",className:X("text-[10px] h-4 px-1.5 border-transparent",w.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":w.audience==="free"?"bg-slate-200/70 text-slate-700 dark:bg-slate-700/40 dark:text-slate-200":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:w.label}):y?.audienceLabel?e.jsx(H,{variant:"outline",className:X("text-[10px] h-4 px-1.5 border-transparent",y.audience==="business"?"bg-sky-500/12 text-sky-700 dark:text-sky-300":y.audience==="free"?"bg-slate-200/70 text-slate-700 dark:bg-slate-700/40 dark:text-slate-200":"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300"),children:y.audienceLabel}):null,!w?.label&&y?.detailLabel&&e.jsx(H,{variant:"outline",className:"text-[10px] h-4 px-1.5",children:y.detailLabel})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"variant-name",children:g("setupVariant.variantNameRequired")}),e.jsx(de,{id:"variant-name",value:n,onChange:f=>l(f.target.value),placeholder:g("setupVariant.variantNamePlaceholder")}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[g("setupVariant.invokeHintPrefix")," ccs ",n||"<name>",' "prompt"']})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{children:g("setupVariant.model")}),D?e.jsxs("div",{className:"space-y-2",children:[e.jsx(de,{value:i,onChange:f=>r(f.target.value),placeholder:g("setupVariant.modelPlaceholder")}),C&&e.jsx("p",{className:"text-xs text-destructive",children:g("providerEditor.agyDenylist")}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>{S(!1),t==="agy"&&ue(i)&&r("")},children:g("setupVariant.choosePresetInstead")})]}):e.jsxs(ze,{value:E.some(f=>f.id===i)?i:"",onValueChange:x,children:[e.jsx(Ge,{children:e.jsx(Be,{placeholder:g("setupVariant.selectModel")})}),e.jsxs(Ve,{children:[E.map(f=>e.jsx(ye,{value:f.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:f.name}),f.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",f.description]})]})},f.id)),e.jsx(ye,{value:Gt,children:e.jsx("span",{className:"text-primary",children:g("setupVariant.customModelName")})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:D?g("setupVariant.enterAnyModel"):g("setupVariant.defaultModel",{model:h?.defaultModel||g("setupVariant.providerDefault")})})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(K,{variant:"ghost",onClick:m,children:[e.jsx(Ct,{className:"w-4 h-4 mr-2"}),g("setupVariant.back")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{variant:"ghost",onClick:p,children:g("setupVariant.skip")}),e.jsx(K,{onClick:j,disabled:!n||d||C,children:g(d?"setupVariant.creating":"setupVariant.createVariant")})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:g("setupVariant.skipHint")})]})}function Za({variantName:t,onClose:a}){const{t:s}=W();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(we,{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:s("setupWizard.successStep.title")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("setupWizard.successStep.subtitle")})]}),e.jsx(Jt,{children:e.jsxs(Xt,{className:"p-4 space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:s("setupWizard.successStep.usage")}),e.jsxs("code",{className:"block px-3 py-2 bg-muted rounded-md font-mono text-sm",children:["ccs ",t,' "your prompt here"']})]})}),e.jsx(K,{onClick:a,className:"w-full",children:s("setupWizard.successStep.done")})]})}function en({open:t,onClose:a}){const[s,n]=c.useState("provider"),[i,d]=c.useState(""),[o,l]=c.useState(null),[r,m]=c.useState(""),[p,j]=c.useState(""),[g,h]=c.useState(!1),[E,k]=c.useState(!1),{data:D,refetch:S}=es(),{data:C}=ts(),y=Ms(),w=Ps(),x=Ds(),{privacyMode:f}=ss(),I=D?.authStatus.find(R=>R.provider===i),u=c.useMemo(()=>I?.accounts||[],[I?.accounts]),T=c.useMemo(()=>Dt(C?.catalogs),[C?.catalogs]),N=!!C;c.useEffect(()=>{if(!t){const R=setTimeout(()=>{n("provider"),d(""),l(null),m(""),j(""),k(!1)},0);return()=>clearTimeout(R)}},[t]),c.useEffect(()=>{if(s==="auth"&&u.length>0&&!E){const R=setTimeout(()=>{n("account")},0);return()=>clearTimeout(R)}},[s,u,E]);const z=async()=>{h(!0),await S(),h(!1)},P=()=>{const R=(I?.accounts?.length||0)===0;w.mutate({provider:i},{onSuccess:async b=>{if(R){const Q=await ht(i,void 0,N?T[i]:void 0);Q.success&&Q.presetName?B.success(`Applied "${Q.presetName}" preset`):Q.success||B.warning(me.t("commonToast.accountAddedPresetFailed"))}b.account&&(l(b.account),n("variant")),S()}})},_=R=>{d(R),(D?.authStatus.find(te=>te.provider===R)?.accounts||[]).length===0?n("auth"):n("account")},F=R=>{l(R),n("variant")},G=async()=>{if(!(!r||!i))try{await y.mutateAsync({name:r,provider:i,model:p||void 0,account:o?.id}),n("success")}catch(R){console.error("Failed to create variant:",R)}},V=`ccs ${i} --auth --add`,q=Ts(s),A=R=>{if(!R&&(w.isPending&&i&&x.mutate(i),s==="success"||s==="provider")){a();return}};return e.jsx(jt,{open:t,onOpenChange:A,children:e.jsxs(bt,{className:"sm:max-w-lg",onPointerDownOutside:R=>{s!=="success"&&s!=="provider"&&R.preventDefault()},onEscapeKeyDown:R=>{(w.isPending||y.isPending)&&R.preventDefault()},children:[e.jsxs(Nt,{children:[e.jsxs(yt,{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-5 h-5 text-primary"}),me.t("setupWizard.title")]}),e.jsxs(as,{children:[s==="provider"&&me.t("setupWizard.stepProviderDesc"),s==="auth"&&me.t("setupWizard.stepAuthDesc"),s==="account"&&me.t("setupWizard.stepAccountDesc"),s==="variant"&&me.t("setupWizard.stepVariantDesc"),s==="success"&&me.t("setupWizard.stepSuccessDesc")]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[s==="provider"&&e.jsx(Qa,{providers:Et,onSelect:_}),s==="auth"&&e.jsx(Ja,{selectedProvider:i,providers:Et,authCommand:V,isRefreshing:g,isPending:w.isPending,onBack:()=>n("provider"),onStartAuth:P,onRefresh:z}),s==="account"&&e.jsx(Xa,{accounts:u,privacyMode:f,onSelect:F,onAddNew:()=>{k(!0),n("auth")},onBack:()=>n("provider")}),s==="variant"&&e.jsx(Ya,{selectedProvider:i,catalog:T[i],selectedAccount:o,variantName:r,modelName:p,isPending:y.isPending,privacyMode:f,onVariantNameChange:m,onModelChange:j,onBack:()=>u.length>0?n("account"):n("provider"),onSkip:a,onCreate:G}),s==="success"&&e.jsx(Za,{variantName:r,onClose:a})]}),e.jsx(Wa,{currentProgress:q,allSteps:Is})]})})}const tn=3e3,sn=300*1e3,an=3;function ot(t){t.invalidateQueries({queryKey:["cliproxy-catalog"]}),t.invalidateQueries({queryKey:["cliproxy-models"]})}async function lt(t){const a=await t.text();if(!a)return{};try{return JSON.parse(a)}catch{const s=t.status>=400?`Request failed with status ${t.status}`:void 0;return s?{error:s}:{}}}const fe={provider:null,isAuthenticating:!1,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:!1};function nn(){const{t}=W(),[a,s]=c.useState(fe),n=c.useRef(fe),i=c.useRef(0),d=c.useRef(null),o=c.useRef(null),l=c.useRef(0),r=c.useRef(0),m=c.useRef(!1),p=ft(),j=c.useCallback(S=>S===i.current,[]),g=c.useCallback(()=>{o.current&&(clearInterval(o.current),o.current=null),r.current=0},[]);c.useEffect(()=>()=>{d.current?.abort(),g(),m.current=!1},[g]),c.useEffect(()=>{n.current=a},[a]);const h=c.useCallback(async(S,C,y)=>{if(j(y)){if(Date.now()-l.current>sn){g(),j(y)&&s(w=>({...w,isAuthenticating:!1,error:t("toasts.providerAuthTimeout")}));return}try{const w=await fetch(`/api/cliproxy/auth/${S}/status?state=${encodeURIComponent(C)}`);if(!j(y))return;const x=await w.json();if(r.current=0,x.status==="ok"){if(!(typeof x.account=="object"&&x.account!==null)){g();const I=t("toasts.providerAccountRegistrationFailed");B.error(I),s(u=>({...u,isAuthenticating:!1,error:I}));return}g(),p.invalidateQueries({queryKey:["cliproxy-auth"]}),p.invalidateQueries({queryKey:["cliproxy-accounts"]}),p.invalidateQueries({queryKey:["account-quota"]}),ot(p),B.success(t("toasts.providerAuthSuccess",{provider:S})),m.current=!1,s(fe)}else if(x.status==="auth_url"){const f=x.url||x.auth_url;f&&(s(I=>({...I,authUrl:f})),m.current||(m.current=!0,window.open(f,"_blank")))}else if(x.status==="device_code"){g();const f=x.user_code&&x.verification_url?`Open ${x.verification_url} and enter code: ${x.user_code}`:"Switch to Device Code method and try again.";B.error(t("toasts.providerDeviceCodeInCallback")),s(I=>({...I,isAuthenticating:!1,error:f}))}else if(x.status==="error"){g();const f=x.error||"Authentication failed";B.error(f),s(I=>({...I,isAuthenticating:!1,error:f}))}}catch(w){if(!j(y)||(r.current+=1,r.current<an))return;g();const x=w instanceof Error&&w.message.trim().length>0?w.message:t("toasts.providerLostStatusEndpoint");B.error(x),s(f=>({...f,isAuthenticating:!1,error:x}))}}},[j,p,g,t]),E=c.useCallback(async(S,C)=>{if(!Je(S)){s({...fe,error:t("toasts.providerUnknown",{provider:S})});return}d.current?.abort(),g(),m.current=!1,r.current=0;const y=new AbortController,w=i.current+1;i.current=w,d.current=y;const f=(C?.flowType||(ns(S)?"device_code":"authorization_code"))==="device_code",I=C?.startEndpoint||(f?"start":"start-url"),u={nickname:C?.nickname,kiroMethod:C?.kiroMethod,kiroIDCStartUrl:C?.kiroIDCStartUrl,kiroIDCRegion:C?.kiroIDCRegion,kiroIDCFlow:C?.kiroIDCFlow,gitlabAuthMode:C?.gitlabAuthMode,gitlabBaseUrl:C?.gitlabBaseUrl,gitlabPersonalAccessToken:C?.gitlabPersonalAccessToken,riskAcknowledgement:C?.riskAcknowledgement};s({provider:S,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:f});try{if(I==="start")fetch(`/api/cliproxy/auth/${S}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u),signal:y.signal}).then(async T=>{if(!j(w))return;const N=await lt(T);if(!j(w))return;const z=N.success===!0,P=typeof N.account=="object"&&N.account!==null;if(T.ok&&z&&P)p.invalidateQueries({queryKey:["cliproxy-auth"]}),p.invalidateQueries({queryKey:["cliproxy-accounts"]}),p.invalidateQueries({queryKey:["account-quota"]}),ot(p),m.current=!1,s(fe);else{const _=typeof N.error=="string"?N.error:t(z?"toasts.providerAccountRegistrationFailed":"auth.loginFailed");B.error(_),s(F=>({...F,isAuthenticating:!1,error:_}))}}).catch(T=>{if(!j(w)||T instanceof Error&&T.name==="AbortError")return;const N=T instanceof Error?T.message:"Authentication failed";B.error(N),s(z=>({...z,isAuthenticating:!1,error:N}))});else{const T=await fetch(`/api/cliproxy/auth/${S}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u),signal:y.signal});if(!j(w))return;const N=await lt(T);if(!j(w))return;const z=N.success===!0;if(!T.ok||!z){const G=(N.error==="plus_oauth_credentials_missing"||N.error==="plus_oauth_url_missing_client_id")&&typeof N.message=="string"?N.message:typeof N.error=="string"?N.error:t("toasts.providerStartOAuthFailed");throw new Error(G)}const P=typeof N.authUrl=="string"?N.authUrl:null,_=typeof N.state=="string"?N.state:null;if(s(F=>({...F,authUrl:P,oauthState:_})),P&&(m.current=!0,window.open(P,"_blank")),_){if(l.current=Date.now(),!P){if(await h(S,_,w),!j(w))return;const F=n.current;if(!F.isAuthenticating||F.provider!==S)return}o.current=setInterval(()=>{h(S,_,w)},tn)}}}catch(T){if(!j(w))return;if(T instanceof Error&&T.name==="AbortError"){m.current=!1,s(fe);return}const N=T instanceof Error?T.message:t("auth.loginFailed");B.error(N),s(z=>({...z,isAuthenticating:!1,error:N}))}},[j,h,g,p,t]),k=c.useCallback(()=>{const S=a.provider;i.current+=1,d.current?.abort(),g(),m.current=!1,s(fe),S&&$e.cliproxy.auth.cancel(S).catch(()=>{})},[a.provider,g]),D=c.useCallback(async S=>{if(!a.provider)return;const C=i.current,y=a.provider;s(w=>({...w,isSubmittingCallback:!0,error:null}));try{const w=await fetch(`/api/cliproxy/auth/${y}/submit-callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirectUrl:S})});if(!j(C))return;const x=await lt(w);if(!j(C))return;const f=x.success===!0,I=x.status==="wait",u=typeof x.account=="object"&&x.account!==null;if(w.ok&&I)s(T=>({...T,isSubmittingCallback:!1,error:null}));else if(w.ok&&f&&u)g(),p.invalidateQueries({queryKey:["cliproxy-auth"]}),p.invalidateQueries({queryKey:["cliproxy-accounts"]}),p.invalidateQueries({queryKey:["account-quota"]}),ot(p),B.success(t("toasts.providerAuthSuccess",{provider:y})),s(fe);else{const T=typeof x.error=="string"?x.error:t(f?"toasts.providerAccountRegistrationFailed":"toasts.providerCallbackFailed");throw new Error(T)}}catch(w){if(!j(C))return;const x=w instanceof Error?w.message:t("toasts.providerSubmitCallbackFailed");B.error(x),s(f=>({...f,isSubmittingCallback:!1,error:x}))}},[j,a.provider,p,g,t]);return c.useMemo(()=>({...a,startAuth:E,cancelAuth:k,submitCallback:D}),[a,E,k,D])}function gt({className:t,compact:a=!1,showAcknowledgement:s=!1,acknowledgementPhrase:n=We,acknowledgementText:i="",onAcknowledgementTextChange:d,disabled:o=!1,showProxySettingsLink:l=!1}){const{t:r}=W(),m=r("accountSafetyWarning.title"),p=r("accountSafetyWarning.subtitle"),j=r("accountSafetyWarning.firstLine"),g=r("accountSafetyWarning.secondLine"),h="https://github.com/kaitranntt/ccs/issues/509",E=r("accountSafetyWarning.issueLabel"),k=r("accountSafetyWarning.proxySettingsLabel");return a?e.jsx("section",{role:"alert",className:X("border-b border-amber-200/70 bg-amber-50/45 dark:bg-amber-950/5",t),children:e.jsxs("div",{className:"flex flex-col gap-3 px-6 py-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-6 w-6 items-center justify-center rounded-md bg-amber-500/12 text-amber-700 dark:text-amber-300",children:e.jsx(Xe,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-xs font-semibold leading-5",children:m}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:p})]}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:j}),e.jsx("p",{className:"text-xs font-medium leading-5 text-amber-900 dark:text-amber-200",children:g})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:justify-end",children:[e.jsxs("a",{href:h,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 rounded-md border border-amber-500/25 bg-background/90 px-2 py-1 text-[11px] font-medium text-amber-800 transition-colors hover:bg-amber-500/10 dark:text-amber-200",children:[E,e.jsx(ke,{className:"h-3 w-3"})]}),l?e.jsxs("a",{href:"/settings?tab=proxy",className:"inline-flex items-center gap-1 rounded-md border border-amber-500/25 bg-background/90 px-2 py-1 text-[11px] font-medium text-amber-800 transition-colors hover:bg-amber-500/10 dark:text-amber-200",children:[e.jsx(Ht,{className:"h-3 w-3"}),k]}):null,e.jsx(H,{variant:"outline",className:"border-amber-500/40 text-[10px] text-amber-700 dark:text-amber-300",children:"High Risk"})]})]})}):e.jsxs("section",{role:"alert",className:X("relative overflow-hidden rounded-xl border border-amber-500/30 bg-gradient-to-br from-amber-50 via-background to-rose-50/70 shadow-sm dark:from-amber-950/20 dark:to-rose-950/20",t),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-amber-500 via-orange-500 to-rose-500"}),e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-amber-500/15 text-amber-700 dark:text-amber-400",children:e.jsx(Xe,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:m}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p})]})]}),e.jsx(H,{variant:"outline",className:"border-amber-500/40 text-amber-700 dark:text-amber-300",children:"High Risk"})]}),e.jsxs("div",{className:"space-y-2 text-sm leading-relaxed",children:[e.jsx("p",{children:j}),e.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-200",children:g}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"CCS is provided as-is and does not take responsibility for suspension, bans, or access loss from upstream providers."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("a",{href:h,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:[E,e.jsx(ke,{className:"h-3.5 w-3.5"})]}),l&&e.jsxs("a",{href:"/settings?tab=proxy",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:[e.jsx(Ht,{className:"h-3.5 w-3.5"}),k]}),e.jsx("span",{className:"rounded-md border border-border/70 bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground",children:"Applies to CLI and dashboard auth"})]}),s&&d&&e.jsxs("div",{className:"rounded-lg border border-amber-500/25 bg-amber-500/5 p-2.5",children:[e.jsxs(Y,{htmlFor:"account-risk-ack-text",className:"text-xs leading-5",children:["Type exact phrase to continue:"," ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono",children:n})]}),e.jsx(de,{id:"account-risk-ack-text",value:i,onChange:D=>d(D.target.value),placeholder:n,disabled:o,className:"mt-2 font-mono text-xs"})]})]})]})}function rn({className:t,value:a,onChange:s,disabled:n=!1}){const{t:i}=W(),d=[a.reviewedIssue509,a.understandsBanRisk,a.acceptsFullResponsibility,a.typedPhrase.trim().replace(/\s+/g," ").toUpperCase()===qt].filter(Boolean).length,o=d/4*100,l=r=>{s({...a,...r})};return e.jsxs("section",{role:"alert",className:X("relative overflow-hidden rounded-xl border border-rose-500/35 bg-gradient-to-br from-rose-50 via-background to-amber-50/70 p-4 shadow-sm dark:from-rose-950/20 dark:to-amber-950/20",t),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-rose-500 via-orange-500 to-amber-500"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-rose-500/15 text-rose-700 dark:text-rose-300",children:e.jsx(Xe,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:i("antigravityChecklist.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("antigravityChecklist.subtitle")})]})]}),e.jsx(H,{variant:"outline",className:"border-rose-500/40 text-rose-700 dark:text-rose-300",children:i("antigravityChecklist.mandatory")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:i("antigravityChecklist.completion")}),e.jsx("span",{children:i("antigravityChecklist.stepsCount",{current:d})})]}),e.jsx(Es,{value:o,className:"h-2"})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/20 bg-rose-500/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Qe,{id:"agy-step-reviewed-issue",checked:a.reviewedIssue509,onCheckedChange:r=>l({reviewedIssue509:!!r}),disabled:n}),e.jsx(Y,{htmlFor:"agy-step-reviewed-issue",className:"text-xs leading-5",children:"Step 1: I reviewed issue #509 and understand AGY OAuth can trigger account bans/suspensions."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Qe,{id:"agy-step-understands-risk",checked:a.understandsBanRisk,onCheckedChange:r=>l({understandsBanRisk:!!r}),disabled:n}),e.jsx(Y,{htmlFor:"agy-step-understands-risk",className:"text-xs leading-5",children:"Step 2: I understand this OAuth action is my own decision and I accept the upstream risk."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Qe,{id:"agy-step-accept-responsibility",checked:a.acceptsFullResponsibility,onCheckedChange:r=>l({acceptsFullResponsibility:!!r}),disabled:n}),e.jsx(Y,{htmlFor:"agy-step-accept-responsibility",className:"text-xs leading-5",children:"Step 3: I accept full responsibility. CCS is not liable for suspension, bans, or access loss."})]})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-amber-500/25 bg-amber-500/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-200",children:[e.jsx(ds,{className:"h-3.5 w-3.5"}),"Step 4: Type exact phrase to continue"]}),e.jsx(de,{value:a.typedPhrase,onChange:r=>l({typedPhrase:r.target.value}),placeholder:qt,disabled:n,className:"font-mono text-xs"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-rose-500/30 bg-rose-500/10 px-2.5 py-1 font-medium text-rose-800 transition-colors hover:bg-rose-500/15 dark:text-rose-200",children:["Read issue #509",e.jsx(ke,{className:"h-3.5 w-3.5"})]})})]})]})}function on(t){return t.trim().replace(/\s+/g," ").toUpperCase()}function ln({open:t,onClose:a,provider:s,displayName:n,catalog:i,isFirstAccount:d=!1}){const[o,l]=c.useState(""),[r,m]=c.useState(""),[p,j]=c.useState(!1),[g,h]=c.useState(null),[E,k]=c.useState(""),[D,S]=c.useState(it),[C,y]=c.useState(!1),[w,x]=c.useState(!1),[f,I]=c.useState(Rt),[u,T]=c.useState(""),[N,z]=c.useState(""),[P,_]=c.useState(_t),[F,G]=c.useState("oauth"),[V,q]=c.useState(""),[A,R]=c.useState(""),{t:b}=W(),Q=c.useRef(!1),te=c.useRef(0),ne=c.useRef(!1),U=nn(),ae=Rs(),$=s==="kiro",Z=s==="gitlab",ie=s==="agy"||s==="gemini",v=s==="gemini"&&!C,O=s==="agy"&&!C,be=ie&&w,Te=Ma(D),Ee=on(E)===We,et=ns(s),Re=_s(f),he=$&&f==="idc",Ne=$&&Ls(f),Me=$?Os(f,P):void 0,tt=$?Us(f):void 0,st=$?Me==="device_code":et,re=U.isAuthenticating||ae.isPending,_e=o.trim(),Oe=u.trim(),Le=N.trim(),Fe=V.trim(),L=A.trim(),ee=g||U.error,oe=c.useCallback(async()=>{const M=await fetch("/api/settings/auth/antigravity-risk");if(!M.ok)throw new Error("Failed to load power user mode setting");return(await M.json()).antigravityAckBypass===!0},[]),ge=c.useCallback(async({pendingMessage:M=null,disabledMessage:pe=null}={})=>{const nt=++te.current;x(!0),M!==null&&h(M);try{const Ue=await oe();return te.current!==nt||(y(Ue),pe?h(Ue?null:pe):M!==null&&h(null)),Ue}catch{return te.current!==nt||(y(!1),h(pe??b("addAccountDialog.powerUserLoadFailed")),ne.current||(ne.current=!0,B.error(b("addAccountDialog.powerUserLoadFailed")))),!1}finally{te.current===nt&&x(!1)}},[oe,b]),at=()=>{l(""),m(""),j(!1),h(null),k(""),S(it),y(!1),x(!1),I(Rt),T(""),z(""),_(_t),G("oauth"),q(""),R(""),te.current+=1,ne.current=!1,Q.current=!1,a()};c.useEffect(()=>{t&&(k(""),S(it),h(null))},[s,t]),c.useEffect(()=>()=>{te.current+=1},[]),c.useEffect(()=>{if(!t||!ie){te.current+=1,y(!1),x(!1);return}ge()},[t,s,ie,ge]),c.useEffect(()=>{if(!t||s!=="agy"||!U.error||!C)return;const M=U.error.toLowerCase();(M.includes("agy_risk_ack_required")||M.includes("responsibility acknowledgement")||M.includes("responsibility checklist"))&&ge({pendingMessage:b("addAccountDialog.powerUserLoading"),disabledMessage:b("addAccountDialog.powerUserUnavailableRetry")})},[U.error,t,C,s,ge,b]),c.useEffect(()=>{!U.isAuthenticating&&!U.error&&U.provider===null&&t&&Q.current&&(Q.current=!1,(async()=>{try{const pe=await ht(s,void 0,i);pe.success&&pe.presetName&&d&&B.success(`Applied "${pe.presetName}" preset`)}catch{}at()})())},[U.isAuthenticating,U.error,U.provider]);const Tt=()=>{U.cancelAuth(),at()},Ns=async()=>{U.authUrl&&(await navigator.clipboard.writeText(U.authUrl),j(!0),setTimeout(()=>j(!1),2e3))},ys=()=>{r.trim()&&U.submitCallback(r.trim())},ks=()=>{if(be){h(b("addAccountDialog.powerUserLoading"));return}if(O&&!Te){h("Complete all Antigravity responsibility steps before authenticating this provider.");return}if(v&&!Ee){h(`Type "${We}" to acknowledge the account safety warning before authenticating this provider.`);return}if(h(null),he&&!Oe){h("IDC Start URL is required for Kiro IAM Identity Center login.");return}if(Z&&F==="pat"&&!L){h(b("addAccountDialog.gitlabPatRequired"));return}Q.current=!0,U.startAuth(s,{nickname:_e||void 0,kiroMethod:$?f:void 0,kiroIDCStartUrl:he?Oe:void 0,kiroIDCRegion:he&&Le?Le:void 0,kiroIDCFlow:he?P:void 0,gitlabAuthMode:Z?F:void 0,gitlabBaseUrl:Z&&Fe?Fe:void 0,gitlabPersonalAccessToken:Z&&F==="pat"&&L?L:void 0,flowType:$?Me:void 0,startEndpoint:$?tt:Z&&F==="pat"?"start":void 0,riskAcknowledgement:O?{version:Pa,reviewedIssue509:D.reviewedIssue509,understandsBanRisk:D.understandsBanRisk,acceptsFullResponsibility:D.acceptsFullResponsibility,typedPhrase:D.typedPhrase}:void 0})},ws=()=>{Q.current=!0,ae.mutate(void 0,{onSuccess:async()=>{const M=await ht("kiro",void 0,i);M.success&&M.presetName&&d&&B.success(`Applied "${M.presetName}" preset`),at()}})},Cs=M=>{M||Tt()},le=U.isAuthenticating;return e.jsx(jt,{open:t,onOpenChange:Cs,children:e.jsxs(bt,{className:"sm:max-w-md",onInteractOutside:M=>{le&&M.preventDefault()},children:[e.jsxs(Nt,{children:[e.jsx(yt,{children:b("addAccountDialog.title",{displayName:n})}),e.jsx(as,{children:b($?"addAccountDialog.descKiro":st?"addAccountDialog.descDeviceCode":"addAccountDialog.descOauth")})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[O&&!le&&e.jsx(rn,{value:D,onChange:M=>{S(M),h(null)},disabled:re}),ie&&C&&!le&&e.jsxs("div",{className:"rounded-lg border border-amber-400/35 bg-amber-50/70 p-3 text-xs text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/25 dark:text-amber-100",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5 font-semibold",children:[e.jsx(ds,{className:"h-3.5 w-3.5"}),b("addAccountDialog.powerUserEnabled")]}),b("addAccountDialog.powerUserSkipped")]}),v&&!le&&e.jsx(gt,{showAcknowledgement:!0,acknowledgementPhrase:We,acknowledgementText:E,onAcknowledgementTextChange:M=>{k(M),h(null)},disabled:re}),$&&!le&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"kiro-auth-method",children:b("addAccountDialog.authMethod")}),e.jsxs(ze,{value:f,onValueChange:M=>{I(M),h(null)},children:[e.jsx(Ge,{id:"kiro-auth-method",children:e.jsx(Be,{placeholder:b("addAccountDialog.selectKiroAuthMethod")})}),e.jsx(Ve,{children:Fs.map(M=>e.jsx(ye,{value:M.id,children:M.label},M.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Re.description}),Ne&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["If your browser does not return automatically after login, CCS can accept the final",e.jsx("span",{className:"mx-1 rounded bg-muted px-1.5 py-0.5 font-mono text-[11px]",children:"kiro://..."}),"callback URL in the next step."]})]}),he&&!le&&e.jsxs("div",{className:"space-y-4 rounded-lg border border-border/60 bg-muted/20 p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"kiro-idc-start-url",children:"IDC Start URL"}),e.jsx(de,{id:"kiro-idc-start-url",value:u,onChange:M=>{T(M.target.value),h(null)},placeholder:"https://d-xxx.awsapps.com/start",disabled:re}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Required for organization IAM Identity Center login."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"kiro-idc-region",children:"IDC Region"}),e.jsx(de,{id:"kiro-idc-region",value:N,onChange:M=>{z(M.target.value),h(null)},placeholder:"us-east-1",disabled:re}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Leave blank to use the upstream default region."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"kiro-idc-flow",children:"IDC Flow"}),e.jsxs(ze,{value:P,onValueChange:M=>{_(M),h(null)},children:[e.jsx(Ge,{id:"kiro-idc-flow",children:e.jsx(Be,{placeholder:"{/* TODO i18n: missing key */}Select IDC flow"})}),e.jsxs(Ve,{children:[e.jsx(ye,{value:"authcode",children:"Authorization Code"}),e.jsx(ye,{value:"device",children:"Device Code"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Auth Code opens a browser and may need the final callback URL pasted back. Device Code shows a verification code instead."})]})]}),Z&&!le&&e.jsxs("div",{className:"space-y-4 rounded-lg border border-border/60 bg-muted/20 p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"gitlab-auth-mode",children:b("addAccountDialog.gitlabAuthMethod")}),e.jsxs(ze,{value:F,onValueChange:M=>{G(M),h(null)},children:[e.jsx(Ge,{id:"gitlab-auth-mode",children:e.jsx(Be,{placeholder:b("addAccountDialog.selectGitlabAuthMethod")})}),e.jsxs(Ve,{children:[e.jsx(ye,{value:"oauth",children:b("addAccountDialog.gitlabAuthOAuth")}),e.jsx(ye,{value:"pat",children:b("addAccountDialog.gitlabAuthPat")})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:b("addAccountDialog.gitlabAuthHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"gitlab-base-url",children:b("addAccountDialog.gitlabUrl")}),e.jsx(de,{id:"gitlab-base-url",value:V,onChange:M=>{q(M.target.value),h(null)},placeholder:b("addAccountDialog.gitlabUrlPlaceholder"),disabled:re}),e.jsx("p",{className:"text-xs text-muted-foreground",children:b("addAccountDialog.gitlabUrlHint")})]}),F==="pat"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"gitlab-pat",children:b("addAccountDialog.gitlabPat")}),e.jsx(de,{id:"gitlab-pat",type:"password",value:A,onChange:M=>{R(M.target.value),h(null)},placeholder:b("addAccountDialog.gitlabPatPlaceholder"),disabled:re}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[b("addAccountDialog.gitlabPatHint")," ",e.jsx("span",{className:"font-mono",children:"api"})," and"," ",e.jsx("span",{className:"font-mono",children:"read_user"})," scopes."]})]})]}),!le&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"nickname",children:b("addAccountDialog.nicknameOptional")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(de,{id:"nickname",value:o,onChange:M=>{l(M.target.value),h(null)},placeholder:b("addAccountDialog.nicknamePlaceholder"),disabled:re,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:b("addAccountDialog.nicknameOptionalHint")})]}),le&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx(ce,{className:"w-4 h-4 inline mr-2 animate-spin"}),b("addAccountDialog.waitingForAuth")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:U.isDeviceCodeFlow?b("addAccountDialog.deviceCodeHint"):Ne?"Complete sign-in in your browser. If it does not return automatically, paste the final kiro:// callback URL below.":b("addAccountDialog.browserHint")})]}),U.authUrl&&!U.isDeviceCodeFlow&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{className:"text-xs",children:b("addAccountDialog.openUrlLabel")}),e.jsxs("div",{className:"p-3 bg-muted rounded-md",children:[e.jsx("p",{className:"text-xs text-muted-foreground break-all font-mono line-clamp-3",children:U.authUrl}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(K,{variant:"outline",size:"sm",onClick:Ns,children:p?e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"w-3 h-3 mr-1"}),b("addAccountDialog.copied")]}):e.jsxs(e.Fragment,{children:[e.jsx(ls,{className:"w-3 h-3 mr-1"}),b("addAccountDialog.copy")]})}),e.jsxs(K,{variant:"outline",size:"sm",onClick:()=>{if(!U.authUrl)return;const M=window.open(U.authUrl,"_blank");(!M||M.closed||typeof M.closed>"u")&&B.warning(b("addAccountDialog.popupBlocked"),{duration:5e3})},children:[e.jsx(ke,{className:"w-3 h-3 mr-1"}),b("addAccountDialog.open")]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"callback-url",className:"text-xs",children:Ne?"Browser did not return? Paste the final kiro:// callback URL:":b("addAccountDialog.redirectPasteLabel")}),e.jsx(de,{id:"callback-url",value:r,onChange:M=>m(M.target.value),placeholder:Ne?"kiro://kiro.kiroAgent/authenticate-success?code=...&state=...":b("addAccountDialog.callbackPlaceholder"),className:"font-mono text-xs"}),e.jsx(K,{variant:"secondary",size:"sm",onClick:ys,disabled:!r.trim()||U.isSubmittingCallback,children:U.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-3 h-3 mr-1 animate-spin"}),b("addAccountDialog.submitting")]}):b("addAccountDialog.submitCallback")})]})]}),!U.authUrl&&!U.isDeviceCodeFlow&&e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:Ne?"Preparing the Kiro sign-in URL. If it does not open automatically, it will appear here shortly.":b("addAccountDialog.preparingUrl")})]}),ee&&e.jsx("p",{className:"text-xs text-center text-destructive",children:ee}),ae.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(ce,{className:"w-4 h-4 inline mr-2 animate-spin"}),b("addAccountDialog.importingToken")]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(K,{variant:"ghost",onClick:Tt,children:b("addAccountDialog.cancel")}),$&&!le&&e.jsx(K,{variant:"outline",onClick:ws,disabled:re,children:ae.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2 animate-spin"}),b("addAccountDialog.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Na,{className:"w-4 h-4 mr-2"}),b("addAccountDialog.importFromIde")]})}),!le&&e.jsxs(K,{onClick:ks,disabled:re||be||O&&!Te||v&&!Ee,children:[e.jsx(ke,{className:"w-4 h-4 mr-2"}),b("addAccountDialog.authenticate")]})]})]})]})})}const dn=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function cn(t){const a=t?.env||{};return dn.filter(s=>!a[s]?.trim())}function un(t,a){const[s,n]=c.useState(null),[i,d]=c.useState(!1),o=ft(),{data:l,isLoading:r,refetch:m}=Qt({queryKey:["settings",t],queryFn:async()=>{const P=await fetch(`/api/settings/${t}/raw`);if(!P.ok){const _=t==="cursor"?`~/.ccs/cliproxy/providers/${t}.settings.json`:Je(t)?`~/.ccs/${t}.settings.json`:`~/.ccs/profiles/${t}/settings.json`;return{profile:t,settings:{env:{}},mtime:Date.now(),path:_}}return P.json()}}),p=l?.settings,j=c.useMemo(()=>s!==null?s:p?JSON.stringify(p,null,2):`{
2
- "env": {}
3
- }`,[s,p]),g=c.useCallback(P=>{n(P)},[]),h=c.useMemo(()=>{try{return JSON.parse(j)}catch{return p||{env:{}}}},[j,p]),E=h?.env?.ANTHROPIC_MODEL,k=h?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,D=h?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,S=h?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,C=c.useMemo(()=>Ks(h?.env||{}),[h]),y=c.useCallback((P,_)=>Hs(P,_,{supportsExtendedContext:F=>Ba(t,F,a)}),[a,t]),w=c.useCallback((P,_)=>{const F={...h?.env||{},[P]:_},G=Ot(P)?y(F,C):F;delete G.CCS_EXTENDED_CONTEXT;const V={...h,env:G};n(JSON.stringify(V,null,2))},[y,h,C]),x=c.useCallback(P=>{const _=h?.env||{},F=y(_,P);delete F.CCS_EXTENDED_CONTEXT;const G={...h,env:F};n(JSON.stringify(G,null,2))},[y,h]),f=c.useCallback(P=>{const _={...h?.env||{},...P},G=Object.keys(P).some(Ot)?y(_,C):_;delete G.CCS_EXTENDED_CONTEXT;const V={...h,env:G};n(JSON.stringify(V,null,2))},[y,h,C]),I=c.useMemo(()=>{try{return JSON.parse(j),!0}catch{return!1}},[j]),u=c.useMemo(()=>s===null?!1:s!==JSON.stringify(p,null,2),[s,p]),T=c.useMemo(()=>cn(h),[h]),N=Ss({mutationFn:async()=>{const P=JSON.parse(j),_=await fetch(`/api/settings/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:P,expectedMtime:l?.mtime})});if(_.status===409)throw new Error("CONFLICT");if(!_.ok)throw new Error("Failed to save");return _.json()},onSuccess:P=>{o.invalidateQueries({queryKey:["settings",t]}),n(null),P?.warning?B.success(me.t("settings.saved"),{description:P.warning}):B.success(me.t("settings.saved"))},onError:P=>{P.message==="CONFLICT"?d(!0):B.error(P.message)}}),z=async P=>{d(!1),P?(await m(),N.mutate()):n(null)};return{data:l,isLoading:r,refetch:m,rawJsonContent:j,rawJsonEdits:s,isRawJsonValid:I,hasChanges:u,currentSettings:h,currentModel:E,opusModel:k,sonnetModel:D,haikuModel:S,extendedContextEnabled:C,toggleExtendedContext:x,handleRawJsonChange:g,updateEnvValue:w,updateEnvValues:f,saveMutation:{mutate:()=>N.mutate(),isPending:N.isPending},conflictDialog:i,setConflictDialog:d,handleConflictResolve:z,missingRequiredFields:T}}const mn=/-(medium|high|xhigh|fast)$/i,pn=["medium","high","xhigh"];function xn(t){return t?.trim()??""}function Ze(t){let a=xn(t),s,n;for(let i=0;i<2;i+=1){const d=a.match(mn);if(!d?.[1])break;const o=d[1].toLowerCase();if(o==="fast"){if(n)break;n="fast"}else{if(s)break;s=o}a=a.slice(0,-d[0].length)}return{baseModel:a,effort:s,serviceTier:n}}function bs(t){return Ze(t).effort}function hn(t){return Ze(t).serviceTier}function gn(t){return Ze(t).baseModel}function Bt(t,a){const s=Ze(t),n=s.baseModel;return!n||!a?s.serviceTier?`${n}-${s.serviceTier}`:n:[n,a,s.serviceTier].filter(Boolean).join("-")}function fn(t,a,s=[]){if(!a){const o=bs(t);return[Bt(t,o)]}const n=gn(t),i=[],d=o=>{const l=o?Bt(n,o):n;i.push(l);for(const r of s)i.push(`${l}-${r}`)};d(void 0);for(const o of pn)if(d(o),o===a)break;return i}function vn(t,a){if(!t)return null;const s=bs(t);return s?{label:`Pinned ${s}`,explicit:!0}:{label:"Auto effort",explicit:!1}}function jn({label:t}){return e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:t})}function Ke({modelId:t}){const a=vn(t);return a?e.jsx(H,{variant:a.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:a.label}):null}function He({modelId:t}){const a=hn(t);return a?e.jsx(H,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:a}):null}function Vt(t,a){if(!t)return"";if(!a?.prefix)return t;const s=`${a.prefix}/`;return t.startsWith(s)?t.slice(s.length):t}function qe(t,a){return a?.recommendedModelId??t}function dt(t,a,s,n){return n?fn(s,t,a):[s]}function je({label:t,description:a,value:s,onChange:n,catalog:i,allModels:d,routing:o,disabled:l}){const{t:r}=W(),m=i?.provider==="codex",p=c.useMemo(()=>It(i,d),[d,i]),j=c.useMemo(()=>Ga(i?.provider??"",i,d),[d,i]),g=new Set(p.map(x=>x.id)),h=c.useMemo(()=>new Map((o?.models??[]).map(x=>[x.modelId.toLowerCase(),x])),[o]),E=c.useMemo(()=>new Set(p.flatMap(x=>dt(x.codexMaxEffort,x.codexServiceTiers,qe(x.id,h.get(x.id.toLowerCase())),m))),[m,p,h]),k=c.useMemo(()=>h.get(Vt(s,o).toLowerCase()),[o,h,s]),D=p.flatMap(x=>{const f=h.get(x.id.toLowerCase());return dt(x.codexMaxEffort,x.codexServiceTiers,qe(x.id,f),m).map(u=>({value:u,groupKey:"recommended",searchText:`${u} ${x.id} ${x.name} ${f?.recommendedModelId??""}`,keywords:[x.tier??"",i?.provider??""],triggerContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u}),f?.pinnedAvailable?e.jsx(H,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:f.prefix}):null,m&&e.jsx(Ke,{modelId:u}),m&&e.jsx(He,{modelId:u})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u}),x.tier==="paid"&&e.jsx(jn,{label:r("providerModelSelector.paid")}),f?.unprefixedStatus==="shadowed"?e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.shadowed")}):null,f?.unprefixedStatus==="prefix-only"?e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.prefixOnly")}):null,m&&e.jsx(Ke,{modelId:u}),m&&e.jsx(He,{modelId:u})]})}))}),S=j.filter(x=>!g.has(x.id)).filter(x=>!E.has(qe(x.id,h.get(x.id.toLowerCase())))).flatMap(x=>{const f=h.get(x.id.toLowerCase());return dt(void 0,void 0,qe(x.id,f),m).map(u=>({value:u,groupKey:"all",searchText:`${u} ${x.id} ${f?.recommendedModelId??""}`,keywords:[x.owned_by],triggerContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u}),f?.pinnedAvailable?e.jsx(H,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:f.prefix}):null,m&&e.jsx(Ke,{modelId:u}),m&&e.jsx(He,{modelId:u})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:u}),f?.unprefixedStatus==="shadowed"?e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.shadowed")}):null,f?.unprefixedStatus==="prefix-only"?e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.prefixOnly")}):null,m&&e.jsx(Ke,{modelId:u}),m&&e.jsx(He,{modelId:u})]})}))}),C=!!s&&!D.some(x=>x.value===s)&&!S.some(x=>x.value===s),y=s?{value:s,groupKey:"current",searchText:s,triggerContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:s}),e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.current")})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:s}),e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.current")})]})}:null,w=D.length+S.length>0;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:t}),a&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:a})]}),e.jsx(Ia,{value:s||void 0,onChange:n,disabled:l,placeholder:r("providerModelSelector.selectModel"),searchPlaceholder:r("searchableSelect.searchModels"),emptyText:r(w?"searchableSelect.noResults":"providerModelSelector.noModelsAvailable"),triggerClassName:"h-9",groups:[...C&&y?[{key:"current",label:e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providerModelSelector.currentValue")})}]:[],{key:"recommended",label:e.jsx("span",{className:"text-xs text-primary",children:r("providerModelSelector.recommended")})},...S.length>0?[{key:"all",label:e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providerModelSelector.allModelsCount",{count:S.length})})}]:[]],options:[...C&&y?[y]:[],...D,...S]}),k?e.jsxs("div",{className:X("rounded-md border px-2.5 py-2 text-[11px]",k.unprefixedStatus==="safe"?"border-border/70 bg-muted/25 text-muted-foreground":"border-amber-300/60 bg-amber-50 text-amber-900 dark:border-amber-500/30 dark:bg-amber-950/25 dark:text-amber-100"),children:[e.jsxs("div",{className:"font-medium",children:[k.pinnedAvailable?r("providerModelSelector.preferredPinnedModel"):r("providerModelSelector.pinnedRouteStatus")," ",e.jsx("code",{children:k.pinnedAvailable?k.recommendedModelId:k.pinnedModelId})]}),e.jsx("p",{className:"mt-1 leading-5",children:k.summary})]}):null,s&&!k&&Vt(s,o)!==s?e.jsx("div",{className:"rounded-md border border-amber-300/60 bg-amber-50 px-2.5 py-2 text-[11px] text-amber-900 dark:border-amber-500/30 dark:bg-amber-950/25 dark:text-amber-100",children:r("providerModelSelector.pinnedModelNotAdvertised",{model:s})}):null]})}function $t(t,a){const s=n=>a?.models.find(d=>d.modelId.toLowerCase()===n.toLowerCase())?.recommendedModelId??n;return{default:s(t.default),opus:s(t.opus),sonnet:s(t.sonnet),haiku:s(t.haiku)}}function bn({open:t,onClose:a,currentValues:s,onApply:n,onSave:i,isSaving:d,catalog:o,allModels:l,routing:r}){const{t:m}=W(),[p,j]=c.useState($t(s,r)),[g,h]=c.useState(""),E=k=>{k?(j($t(s,r)),h("")):a()};return e.jsx(jt,{open:t,onOpenChange:E,children:e.jsxs(bt,{className:"sm:max-w-md",children:[e.jsx(Nt,{children:e.jsxs(yt,{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4"}),m("customPresetDialog.title")]})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"preset-name",children:m("customPresetDialog.presetNameOptional")}),e.jsx(de,{id:"preset-name",value:g,onChange:k=>h(k.target.value),placeholder:m("customPresetDialog.presetNamePlaceholder"),className:"text-sm"})]}),e.jsx(Pt,{}),o?.provider==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground rounded-md border bg-muted/30 px-2.5 py-2",children:[m("customPresetDialog.codexTipPrefix")," ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and"," ",e.jsx("code",{children:"-xhigh"})," ",m("customPresetDialog.codexTipSuffix")]}),e.jsx(je,{label:m("customPresetDialog.defaultModel"),description:m("customPresetDialog.defaultModelDesc"),value:p.default,onChange:k=>j({...p,default:k}),catalog:o,allModels:l,routing:r}),e.jsx(je,{label:m("customPresetDialog.opusModel"),description:m("customPresetDialog.opusModelDesc"),value:p.opus,onChange:k=>j({...p,opus:k}),catalog:o,allModels:l,routing:r}),e.jsx(je,{label:m("customPresetDialog.sonnetModel"),description:m("customPresetDialog.sonnetModelDesc"),value:p.sonnet,onChange:k=>j({...p,sonnet:k}),catalog:o,allModels:l,routing:r}),e.jsx(je,{label:m("customPresetDialog.haikuModel"),description:m("customPresetDialog.haikuModelDesc"),value:p.haiku,onChange:k=>j({...p,haiku:k}),catalog:o,allModels:l,routing:r})]}),e.jsxs(qs,{className:"gap-2 sm:gap-0",children:[e.jsx(K,{variant:"outline",onClick:a,children:m("customPresetDialog.cancel")}),i&&e.jsxs(K,{variant:"secondary",onClick:()=>i(p,g||void 0),disabled:d||!g.trim(),children:[d?e.jsx(ce,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(At,{className:"w-4 h-4 mr-1"}),m("customPresetDialog.savePreset")]}),e.jsxs(K,{onClick:()=>n(p,g||void 0),children:[e.jsx(Ie,{className:"w-4 h-4 mr-1"}),m("customPresetDialog.applyPreset")]})]})]})})}function ve({label:t,command:a}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:t}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:a}),e.jsx(is,{value:a,size:"icon",className:"h-6 w-6"})]})]})}function Nn({provider:t,displayName:a,baseProvider:s,defaultTarget:n,data:i,authStatus:d,supportsModelConfig:o=!1}){const{t:l}=W(),r=n||"claude",m=r==="droid",p=t==="codex",j=s||d.provider||t,g=zs(j),h=r==="claude"?`ccs ${t}`:`ccs ${t} --target claude`,E=`${h} --config`,k=`${h} --auth --add`,D=`${h} --accounts`;return e.jsx(kt,{className:"h-full",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(cs,{className:"w-4 h-4"}),"Provider Information"]}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:l("providerEditor.provider")}),e.jsx("span",{className:"font-mono",children:a})]}),i&&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:l("providerEditor.filePath")}),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:i.path}),e.jsx(is,{value:i.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:l("providerEditor.lastModified")}),e.jsx("span",{className:"text-xs",children:new Date(i.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:l("providerEditor.status")}),d.authenticated?e.jsxs(H,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(ya,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(H,{variant:"outline",className:"w-fit text-muted-foreground",children:"Not connected"})]}),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:l("providerEditor.defaultTarget")}),e.jsx("span",{className:"font-mono",children:r})]}),g&&e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-start",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:l("providerConfig.trackLabel")}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"font-mono",children:l(g.labelKey)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[l(g.hintKey),Gs(j)?` ${l("providerConfig.plusTrackNote")}`:""]})]})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:l("providerEditor.quickUsage")}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(ve,{label:"Run with prompt",command:`ccs ${t} "your prompt"`}),p&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{label:"Run on native Codex (shortcut)",command:'ccsxp "your prompt"'}),e.jsx(ve,{label:"Run on native Codex (--target)",command:`ccs ${t} --target codex "your prompt"`})]}),e.jsx(ve,{label:m?"Droid alias (explicit)":"Run on Droid",command:`ccs-droid ${t} "your prompt"`}),e.jsx(ve,{label:m?"Override to Claude":"Run on Droid (--target)",command:`ccs ${t} --target ${m?"claude":"droid"} "your prompt"`}),o&&e.jsx(ve,{label:r==="claude"?"Change model":"Change model (Claude target)",command:E}),e.jsx(ve,{label:r==="claude"?"Add account":"Add account (Claude target)",command:k}),e.jsx(ve,{label:r==="claude"?"List accounts":"List accounts (Claude target)",command:D}),r!=="claude"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Account and model-management flags stay on Claude target. Codex and Droid runtime launches reject those CLIProxy management commands."})]})]})]})})}function yn(t){const a=t.replace(/\\/g,"/"),n=a.lastIndexOf("/cliproxy/providers/");return n!==-1?a.slice(n+1):a.replace(/^.*\//,"")}function kn({displayName:t,logoProvider:a,provider:s,data:n,isLoading:i,hasChanges:d,isRawJsonValid:o,isSaving:l,isRemoteMode:r,port:m,onRefetch:p,onSave:j}){const{t:g}=W();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(wt,{provider:a||s,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:t}),r&&e.jsxs(H,{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(us,{className:"w-3 h-3"}),"Remote"]}),m&&e.jsxs(H,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(ka,{className:"w-3 h-3"}),":",m]}),!r&&n?.path&&e.jsx(H,{variant:"outline",className:"text-xs",children:yn(n.path)})]}),r?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):n&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[g("providerEditor.lastModified"),": ",new Date(n.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{variant:"ghost",size:"sm",onClick:p,disabled:i,children:e.jsx(St,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsx(K,{size:"sm",onClick:j,disabled:l||!d||!o,children:l?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(wa,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function wn({models:t,provider:a,enabled:s,onToggle:n,disabled:i,className:d}){const{t:o}=W();if(t.length===0)return null;const l=t.some(p=>Lt(p.id)),r=t.some(p=>!Lt(p.id));let m="Compatible mappings stay on standard context unless you turn this on.";return l&&r?m="Gemini-compatible mappings can use 1M automatically. Claude mappings stay plain unless you turn this on.":l&&(m="Gemini-compatible mappings can use 1M by default. Turn this off to keep standard context."),e.jsxs("div",{className:X("rounded-lg border p-3 space-y-2",s?"border-primary/50 bg-primary/5":"border-border bg-muted/30",d),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ie,{className:X("w-4 h-4",s?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:"text-sm font-medium",children:o("extendedContext.extendedContext")}),e.jsx(H,{variant:s?"default":"secondary",className:"text-[10px] h-5 px-1.5",children:"1M tokens"})]}),e.jsx(rs,{checked:s,onCheckedChange:n,disabled:i})]}),e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(cs,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{children:["Applies the explicit ",e.jsx("code",{children:"[1m]"})," long-context suffix to compatible saved mappings."]}),e.jsx("p",{className:"text-[10px]",children:m}),e.jsxs("p",{className:"text-amber-600 dark:text-amber-500",children:["CCS only saves ",e.jsx("code",{children:"[1m]"}),". Provider pricing and entitlement are separate, and some accounts can still return 429 extra-usage errors for long-context requests."]})]})]})]})}function Cn(t,a){const s=t.presetMapping||{default:t.id,opus:t.id,sonnet:t.id,haiku:t.id};return{ANTHROPIC_MODEL:a(s.default),ANTHROPIC_DEFAULT_OPUS_MODEL:a(s.opus),ANTHROPIC_DEFAULT_SONNET_MODEL:a(s.sonnet),ANTHROPIC_DEFAULT_HAIKU_MODEL:a(s.haiku)}}function Sn({catalog:t,savedPresets:a,currentModel:s,opusModel:n,sonnetModel:i,haikuModel:d,providerModels:o,routing:l,provider:r,extendedContextEnabled:m,onExtendedContextToggle:p,onApplyPreset:j,onUpdateEnvValue:g,onOpenCustomPreset:h,onDeletePreset:E,isDeletePending:k}){const{t:D}=W(),S=(l?.models??[]).some(u=>u.pinnedAvailable),C=c.useMemo(()=>new Map((l?.models??[]).map(u=>[u.modelId.toLowerCase(),u])),[l]),y=u=>C.get(u.toLowerCase())?.recommendedModelId??u,w=c.useMemo(()=>{if(!t)return[];const u=[s,n,i,d].filter(N=>!!N).map(N=>Bs(N));return[...new Set(u)].map(N=>js(t.provider,N,t)).filter(N=>!!N?.extendedContext)},[t,s,n,i,d]),x=c.useMemo(()=>It(t,o),[t,o]),f=c.useMemo(()=>{const u=x.filter(N=>N.presetMapping);return u.length===0?[]:u.some(N=>N.tier==="paid")?[{key:"free",label:"Free Tier",description:"Available on free or paid plans",badgeClassName:"text-[10px] bg-green-100 text-green-700 border-green-200",iconClassName:"text-green-600",models:u.filter(N=>N.tier!=="paid")},{key:"paid",label:"Paid Tier",description:"Requires paid access",badgeClassName:"text-[10px] bg-amber-100 text-amber-700 border-amber-200",iconClassName:"text-amber-700",models:u.filter(N=>N.tier==="paid")}].filter(N=>N.models.length>0):[{key:"default",models:u.slice(0,4)}]},[x]),I=f.length>0||a.length>0;return e.jsxs(e.Fragment,{children:[I&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:D("providerEditor.presets")}),e.jsxs("div",{className:"space-y-4",children:[f.map(u=>e.jsxs("div",{children:["label"in u&&u.label&&e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(H,{variant:"outline",className:u.badgeClassName,children:u.label}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:u.description})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:u.models.map(T=>e.jsxs(K,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>j(Cn(T,y)),children:[e.jsx(Ie,{className:`w-3 h-3 ${"iconClassName"in u?u.iconClassName:""}`}),T.name]},T.id))})]},u.key)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.map(u=>e.jsxs("div",{className:"group relative",children:[e.jsxs(K,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{j({ANTHROPIC_MODEL:y(u.default),ANTHROPIC_DEFAULT_OPUS_MODEL:y(u.opus),ANTHROPIC_DEFAULT_SONNET_MODEL:y(u.sonnet),ANTHROPIC_DEFAULT_HAIKU_MODEL:y(u.haiku)})},children:[e.jsx(At,{className:"w-3 h-3 fill-current"}),u.name]}),e.jsx(K,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:T=>{T.stopPropagation(),E(u.name)},disabled:k,children:e.jsx(Mt,{className:"w-3 h-3"})})]},u.name)),e.jsxs(K,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1 border-primary/50 text-primary hover:bg-primary/10 hover:border-primary",onClick:h,children:[e.jsx(ms,{className:"w-3 h-3"}),"Custom"]})]})]})]}),e.jsx(Pt,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:D("providerEditor.modelMapping")}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Configure which models to use for each tier"}),l?e.jsx("p",{className:"text-[11px] text-muted-foreground mb-3 rounded-md border bg-muted/30 px-2.5 py-2",children:S?e.jsxs(e.Fragment,{children:["Preferred pinned model names use the ",e.jsxs("code",{children:[l.prefix,"/"]})," prefix. Unprefixed names can still resolve to a different backend when providers overlap."]}):e.jsxs(e.Fragment,{children:["Managed pinning for ",e.jsxs("code",{children:[l.prefix,"/"]})," is not currently advertised by the proxy. Unprefixed names may still be ambiguous until prefix repair completes."]})}):null,r==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mb-3 rounded-md border bg-muted/30 px-2.5 py-2",children:["Codex tip: suffixes ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and ",e.jsx("code",{children:"-xhigh"})," ","pin reasoning effort. ",e.jsx("code",{children:"-fast"})," enables the Codex fast service tier on models that support it, including combined forms such as ",e.jsx("code",{children:"gpt-5.4-high-fast"}),"."]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(je,{label:"Default Model",description:"Used when no specific tier is requested",value:s,onChange:u=>g("ANTHROPIC_MODEL",u),catalog:t,allModels:o,routing:l}),w.length>0&&p&&e.jsx(wn,{models:w,provider:r,enabled:m??!1,onToggle:p}),e.jsx(je,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:n,onChange:u=>g("ANTHROPIC_DEFAULT_OPUS_MODEL",u),catalog:t,allModels:o,routing:l}),e.jsx(je,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:i,onChange:u=>g("ANTHROPIC_DEFAULT_SONNET_MODEL",u),catalog:t,allModels:o,routing:l}),e.jsx(je,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:d,onChange:u=>g("ANTHROPIC_DEFAULT_HAIKU_MODEL",u),catalog:t,allModels:o,routing:l})]})]})]})}function An(t,a,s){return t?e.jsx(ct,{children:e.jsxs(ut,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Sa,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:X("font-mono max-w-[180px] truncate",a&&vt),title:t,children:t})]})}),e.jsx(pt,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:s("providerEditor.gcpProjectIdReadonly")})})]})}):e.jsx(ct,{children:e.jsxs(ut,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(Xe,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:s("providerEditor.projectIdNA")})]})}),e.jsx(pt,{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:s("providerEditor.missingProjectId")}),e.jsx("p",{children:s("providerEditor.missingProjectIdHint")})]})})]})})}function Mn({account:t,onSetDefault:a,onRemove:s,onPauseToggle:n,isRemoving:i,isPausingAccount:d,privacyMode:o,showQuota:l,selectable:r,selected:m,onSelectChange:p}){const{t:j}=W(),g=t.provider.toLowerCase(),{data:h}=Vs(l),{data:E,isLoading:k}=$s(g,t.id,l),D=Ws(h,t)?.lastUsedAt,S=r||n?e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r&&e.jsx("button",{type:"button",onClick:()=>p?.(!m),className:X("flex items-center justify-center w-5 h-5 rounded border-2 transition-colors shrink-0",m?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/30 hover:border-primary/50"),"aria-label":m?"Deselect account":"Select account",children:m&&e.jsx(we,{className:"w-3 h-3"})}),n&&e.jsx(ct,{children:e.jsxs(ut,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(K,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>n(!t.paused),disabled:d,children:d?e.jsx(ce,{className:"w-4 h-4 animate-spin"}):t.paused?e.jsx(ps,{className:"w-4 h-4 text-emerald-500"}):e.jsx(xs,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(pt,{side:"top",children:t.paused?"Resume account":"Pause account"})]})})]}):void 0,C=e.jsxs(Qs,{children:[e.jsx(Js,{asChild:!0,children:e.jsx(K,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(Ca,{className:"w-4 h-4"})})}),e.jsxs(Xs,{align:"end",children:[!t.isDefault&&e.jsxs(Ft,{onClick:a,children:[e.jsx(At,{className:"w-4 h-4 mr-2"}),"Set as default"]}),e.jsxs(Ft,{className:"text-destructive focus:text-destructive",onClick:s,disabled:i,children:[e.jsx(hs,{className:"w-4 h-4 mr-2"}),i?"Removing...":"Remove account"]})]})]});return e.jsx("div",{className:X("rounded-lg border p-3 transition-colors overflow-hidden",t.isDefault?"border-primary/30 bg-primary/5":"border-border hover:bg-muted/30",t.paused&&"opacity-75",m&&"ring-2 ring-primary/50 bg-primary/5"),children:e.jsx(Ys,{mode:"detailed",provider:t.provider,accountId:t.id,email:t.email,displayEmail:t.email||t.id,tokenFile:t.tokenFile,tier:t.tier,isDefault:t.isDefault,paused:t.paused,privacyMode:o,showQuota:l,quota:E,quotaLoading:k,runtimeLastUsed:D,beforeIdentity:S,headerEnd:C,bodySlot:t.provider==="agy"?An(t.projectId,o,j):null,quotaInsetClassName:"pl-11"})})}function Pn({selectedCount:t,onPauseSelected:a,onResumeSelected:s,onClearSelection:n,isPausing:i,isResuming:d}){if(t<1)return null;const o=i||d;return e.jsxs("div",{className:"flex items-center gap-3 p-2 bg-muted/50 rounded-lg border mt-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[t," selected"]}),e.jsx(K,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:n,disabled:o,children:"Clear"}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(K,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:a,disabled:o,children:[i?e.jsx(ce,{className:"w-3 h-3 animate-spin"}):e.jsx(xs,{className:"w-3 h-3"}),"Pause Selected"]}),e.jsxs(K,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:s,disabled:o,children:[d?e.jsx(ce,{className:"w-3 h-3 animate-spin"}):e.jsx(ps,{className:"w-3 h-3"}),"Resume Selected"]})]})]})}function Dn({accounts:t,onAddAccount:a,onSetDefault:s,onRemoveAccount:n,onPauseToggle:i,onSoloMode:d,onBulkPause:o,onBulkResume:l,isRemovingAccount:r,isPausingAccount:m,isSoloingAccount:p,isBulkPausing:j,isBulkResuming:g,privacyMode:h,showQuota:E,isKiro:k,kiroNoIncognito:D,onKiroNoIncognitoChange:S,kiroSettingsLoading:C}){const{t:y}=W(),[w,x]=c.useState(new Set),f=c.useMemo(()=>new Set(t.map(A=>A.id)),[t]),I=c.useMemo(()=>new Set([...w].filter(A=>f.has(A))),[w,f]),u=!!(o&&l),T=I.size,N=t.length>0&&I.size===t.length,z=I.size>0&&I.size<t.length,P=c.useCallback(A=>{x(R=>{const b=new Set(R);return b.has(A)?b.delete(A):b.add(A),b})},[]),_=c.useCallback(()=>{x(new Set(t.map(A=>A.id)))},[t]),F=c.useCallback(()=>{x(new Set)},[]),G=c.useCallback(()=>{N?F():_()},[N,_,F]),V=c.useCallback(()=>{o&&I.size>0&&(o(Array.from(I)),x(new Set))},[o,I]),q=c.useCallback(()=>{l&&I.size>0&&(l(Array.from(I)),x(new Set))},[l,I]);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:[u&&t.length>0&&e.jsx(Qe,{checked:N,onCheckedChange:G,"aria-label":"Select all accounts",className:z?"data-[state=checked]:bg-primary/50":"",...z?{"data-state":"indeterminate"}:{}}),e.jsx(Pe,{className:"w-4 h-4"}),"Accounts",t.length>0&&e.jsx(H,{variant:"secondary",className:"text-xs",children:t.length})]}),e.jsxs(K,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:a,children:[e.jsx(ms,{className:"w-3 h-3"}),"Add"]})]}),u&&T>0&&e.jsx(Pn,{selectedCount:T,onPauseSelected:V,onResumeSelected:q,onClearSelection:F,isPausing:!!j,isResuming:!!g}),t.length>0?e.jsx("div",{className:"space-y-2",children:t.map(A=>e.jsx(Mn,{account:A,onSetDefault:()=>s(A.id),onRemove:()=>n(A.id),onPauseToggle:i?R=>i(A.id,R):void 0,onSoloMode:d?()=>d(A.id):void 0,isRemoving:r,isPausingAccount:m,isSoloingAccount:p,privacyMode:h,showQuota:E,selectable:u,selected:I.has(A.id),onSelectChange:()=>P(A.id)},A.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(Pe,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:y("providerEditor.noAccountsConnected")}),e.jsx("p",{className:"text-xs opacity-70",children:y("providerEditor.addAccountToStart")})]}),k&&S&&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(us,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:y("providerEditor.useIncognito")})]}),e.jsx(rs,{checked:!D,onCheckedChange:A=>S(!A),disabled:C,className:"scale-90"})]})})]})}function In({provider:t,catalog:a,savedPresets:s,currentModel:n,opusModel:i,sonnetModel:d,haikuModel:o,providerModels:l,routing:r,extendedContextEnabled:m,onExtendedContextToggle:p,onApplyPreset:j,onUpdateEnvValue:g,onOpenCustomPreset:h,onDeletePreset:E,isDeletePending:k,accounts:D,onAddAccount:S,onSetDefault:C,onRemoveAccount:y,onPauseToggle:w,onSoloMode:x,onBulkPause:f,onBulkResume:I,isRemovingAccount:u,isPausingAccount:T,isSoloingAccount:N,isBulkPausing:z,isBulkResuming:P,privacyMode:_,isRemoteMode:F}){const G=t.toLowerCase(),V=(Zs.includes(G)||["anthropic","antigravity","gemini-cli","copilot","github-copilot"].includes(G))&&!F,q=t==="kiro",[A,R]=c.useState(!0),[b,Q]=c.useState(!0),[te,ne]=c.useState(!1),U=c.useCallback(async()=>{if(q)try{Q(!0);const Z=(await $e.config.get()).cliproxy;R(Z?.kiro_no_incognito??!0)}catch{R(!0)}finally{Q(!1)}},[q]),ae=c.useCallback(async $=>{R($),ne(!0);try{const Z=await $e.config.get(),ie=Z.cliproxy??{};await $e.config.update({...Z,cliproxy:{...ie,kiro_no_incognito:$}})}catch{R(!$)}finally{ne(!1)}},[]);return c.useEffect(()=>{U()},[U]),e.jsx(kt,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(Sn,{catalog:a,savedPresets:s,currentModel:n,opusModel:i,sonnetModel:d,haikuModel:o,providerModels:l,routing:r,provider:t,extendedContextEnabled:m,onExtendedContextToggle:p,onApplyPreset:j,onUpdateEnvValue:g,onOpenCustomPreset:h,onDeletePreset:E,isDeletePending:k}),e.jsx(Pt,{}),e.jsx(Dn,{accounts:D,onAddAccount:S,onSetDefault:C,onRemoveAccount:y,onPauseToggle:w,onSoloMode:x,onBulkPause:f,onBulkResume:I,isRemovingAccount:u,isPausingAccount:T,isSoloingAccount:N,isBulkPausing:z,isBulkResuming:P,privacyMode:_,showQuota:V,isKiro:q,kiroNoIncognito:A,onKiroNoIncognitoChange:ae,kiroSettingsLoading:b||te})]})})}function Wt({provider:t,displayName:a,authStatus:s,catalog:n,routing:i,logoProvider:d,baseProvider:o,isRemoteMode:l,port:r,defaultTarget:m,topNotice:p,onAddAccount:j,onSetDefault:g,onRemoveAccount:h,onPauseToggle:E,onSoloMode:k,onBulkPause:D,onBulkResume:S,isRemovingAccount:C,isPausingAccount:y,isSoloingAccount:w,isBulkPausing:x,isBulkResuming:f}){const[I,u]=c.useState(!1),{privacyMode:T}=ss(),{t:N}=W(),{data:z}=ea(),{data:P}=ta(t),_=sa(),F=aa(),G=o||t,V=G.toLowerCase()==="agy",q=c.useMemo(()=>{const L=P?.presets||[];return V?L.filter(ee=>!ue(ee.default)&&!ue(ee.opus)&&!ue(ee.sonnet)&&!ue(ee.haiku)):L},[V,P?.presets]),A=c.useMemo(()=>{if(!z?.models)return[];const ee={gemini:["google"],agy:["antigravity"],codex:["openai"],cursor:["cursor"],gitlab:["gitlab","duo"],codebuddy:["codebuddy"],qwen:["alibaba","qwen"],iflow:["iflow"],kilo:["kilo"],kiro:["kiro","aws"],ghcp:["github","copilot"],kimi:["kimi","moonshot"]}[G.toLowerCase()]||[G.toLowerCase()];return z.models.filter(oe=>ee.some(ge=>oe.owned_by.toLowerCase().includes(ge))?V?!ue(oe.id):!0:!1)},[V,z,G]),R=(o||t).toLowerCase(),{data:b,isLoading:Q,refetch:te,rawJsonContent:ne,rawJsonEdits:U,isRawJsonValid:ae,hasChanges:$,currentModel:Z,opusModel:ie,sonnetModel:v,haikuModel:O,extendedContextEnabled:be,toggleExtendedContext:Te,handleRawJsonChange:Ee,updateEnvValue:et,updateEnvValues:Re,saveMutation:he,conflictDialog:Ne,handleConflictResolve:Me,missingRequiredFields:tt}=un(t,n),st=c.useMemo(()=>(s.accounts||[]).map(L=>({...L,provider:L.provider||o||t})),[s.accounts,o,t]),{data:re}=Qt({queryKey:["auth-tokens-raw"],queryFn:async()=>{const L=await fetch("/api/settings/auth/tokens/raw");return L.ok?L.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),_e=re?.apiKey?.value??"ccs-internal-managed",Oe=L=>{if(V&&[L.ANTHROPIC_MODEL,L.ANTHROPIC_DEFAULT_OPUS_MODEL,L.ANTHROPIC_DEFAULT_SONNET_MODEL,L.ANTHROPIC_DEFAULT_HAIKU_MODEL].some(oe=>typeof oe=="string"&&ue(oe))){B.error(N("providerEditor.agyDenylist"));return}Re({ANTHROPIC_BASE_URL:`http://127.0.0.1:${r??xt}/api/provider/${R}`,ANTHROPIC_AUTH_TOKEN:_e,...L}),B.success(`Applied "${L.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},Le=(L,ee)=>{if(V&&[L.default,L.opus,L.sonnet,L.haiku].some(ge=>ue(ge))){B.error(N("providerEditor.agyDenylist"));return}Re({ANTHROPIC_BASE_URL:`http://127.0.0.1:${r??xt}/api/provider/${R}`,ANTHROPIC_AUTH_TOKEN:_e,ANTHROPIC_MODEL:L.default,ANTHROPIC_DEFAULT_OPUS_MODEL:L.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:L.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:L.haiku}),B.success(`Applied ${ee?`"${ee}"`:"custom"} preset`),u(!1)},Fe=(L,ee)=>{if(!ee){B.error(me.t("commonToast.enterPresetName"));return}if(V&&[L.default,L.opus,L.sonnet,L.haiku].some(oe=>ue(oe))){B.error(N("providerEditor.agyDenylist"));return}_.mutate({profile:t,data:{name:ee,...L}}),u(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(kn,{provider:t,displayName:a,logoProvider:d,data:b,isLoading:Q,hasChanges:$,isRawJsonValid:ae,isSaving:he.isPending,isRemoteMode:l,port:r,onRefetch:te,onSave:()=>he.mutate()}),p?e.jsx("div",{className:"border-b bg-muted/10 px-4 py-3",children:p}):null,Q?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(ce,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:N("providerEditor.loadingSettings")})]}):e.jsxs("div",{className:"min-h-0 flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-muted/5",children:e.jsxs(na,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(ia,{className:"w-full",children:[e.jsx(Ut,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(Ut,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(Kt,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(In,{provider:t,catalog:n,savedPresets:q,currentModel:Z,opusModel:ie,sonnetModel:v,haikuModel:O,providerModels:A,routing:i,extendedContextEnabled:be,onExtendedContextToggle:Te,onApplyPreset:Oe,onUpdateEnvValue:et,onOpenCustomPreset:()=>u(!0),onDeletePreset:L=>F.mutate({profile:t,name:L}),isDeletePending:F.isPending,accounts:st,onAddAccount:j,onSetDefault:g,onRemoveAccount:h,onPauseToggle:E,onSoloMode:k,onBulkPause:D,onBulkResume:S,isRemovingAccount:C,isPausingAccount:y,isSoloingAccount:w,isBulkPausing:x,isBulkResuming:f,privacyMode:T,isRemoteMode:l})}),e.jsx(Kt,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(Nn,{provider:t,displayName:a,baseProvider:o,defaultTarget:m,data:b,authStatus:s,supportsModelConfig:!!n})})]})]})}),e.jsxs("div",{className:"flex min-h-0 min-w-0 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(Aa,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:[N("rawEditorSection.rawConfig")," (JSON)"]})]}),e.jsx(ra,{rawJsonContent:ne,isRawJsonValid:ae,rawJsonEdits:U,onRawJsonChange:Ee,profileEnv:b?.settings?.env,missingRequiredFields:tt})]})]}),e.jsx(Da,{open:Ne,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>Me(!0),onCancel:()=>Me(!1)}),e.jsx(bn,{open:I,onClose:()=>u(!1),currentValues:{default:Z||"",opus:ie||"",sonnet:v||"",haiku:O||""},onApply:Le,onSave:Fe,isSaving:_.isPending,catalog:n,allModels:A,routing:i})]})}function Tn({status:t,isSelected:a,onSelect:s}){const{t:n}=W(),i=t.accounts?.length||0;return e.jsxs("button",{className:X("w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors cursor-pointer text-left",a?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:s,children:[e.jsx(wt,{provider:t.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:t.displayName}),i>0&&e.jsx(H,{variant:"secondary",className:"text-[10px] h-4 px-1",children:i})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:t.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-green-600",children:n("cliproxyPage.connected")})]}):e.jsxs(e.Fragment,{children:[e.jsx(Mt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("cliproxyPage.notConnected")})]})})]})]})}function En({variant:t,parentAuth:a,isSelected:s,onSelect:n,onDelete:i,isDeleting:d}){const{t:o}=W(),l=()=>{n()};return e.jsxs("div",{role:"button",tabIndex:0,className:X("group w-full flex items-center gap-3 px-3 py-2 rounded-lg transition-colors cursor-pointer text-left pl-6",s?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:l,onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),l())},children:[e.jsxs("div",{className:"relative",children:[e.jsx(wt,{provider:t.provider,size:"sm"}),e.jsx(gs,{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:t.name}),e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1",children:o("cliproxyPage.variant")}),e.jsx(H,{variant:"outline",className:"text-[9px] h-4 px-1 uppercase",children:t.target||"claude"})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:a?.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:o("cliproxyPage.viaProvider",{provider:t.provider})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Mt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:o("cliproxyPage.parentNotConnected")})]})})]}),e.jsx(K,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:r=>{r.stopPropagation(),i()},disabled:d,children:e.jsx(hs,{className:"w-3 h-3"})})]})}function Rn({onSetup:t}){const{t:a}=W();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(Ie,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:a("cliproxyPage.emptyTitle")}),e.jsx("p",{className:"text-muted-foreground mb-4",children:a("cliproxyPage.emptyDesc")}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-6",children:[a("cliproxyPage.emptyControlPanelPrefix")," ",e.jsx("a",{href:"/cliproxy/control-panel",className:"text-primary hover:underline",children:a("cliproxyPage.controlPanel")}),"."]}),e.jsxs(K,{onClick:t,className:"gap-2",children:[e.jsx(De,{className:"w-4 h-4"}),a("cliproxyPage.quickSetup")]})]})})}function Yn(){const{t}=W(),a=ft(),{data:s,isLoading:n}=es(),{data:i,isFetching:d}=oa(),{data:o}=ts(),{data:l}=la(),r=da(),m=ca(),p=ua(),j=ma(),g=pa(),h=xa(),E=ha(),k=ga(),[D,S]=c.useState(()=>{if(typeof window<"u"){const O=new URLSearchParams(window.location.search).get("provider")?.trim().toLowerCase();return O&&Je(O)?O:localStorage.getItem("cliproxy-selected-provider")}return null}),[C,y]=c.useState(null),[w,x]=c.useState(!1),[f,I]=c.useState(()=>{if(typeof window>"u")return null;const v=new URLSearchParams(window.location.search),O=v.get("provider")?.trim().toLowerCase();return v.get("action")!=="auth"||!O||!Je(O)?null:{provider:O,displayName:fa(O),isFirstAccount:!1}}),u=c.useMemo(()=>s?.authStatus||[],[s?.authStatus]),T=c.useMemo(()=>va(u,v=>v.provider),[u]),N=s?.source==="remote",z=c.useMemo(()=>i?.variants||[],[i?.variants]),P=c.useMemo(()=>Dt(o?.catalogs),[o?.catalogs]),_=o?.routing??{},F=!!o,G=v=>{S(v),v&&localStorage.setItem("cliproxy-selected-provider",v)},V=c.useMemo(()=>C?null:D&&u.some(v=>v.provider===D)?D:u.length>0&&(u.find(O=>(O.accounts?.length||0)>0)?.provider||u[0]?.provider)||null,[D,C,u]),q=u.find(v=>v.provider===V),A=z.find(v=>v.name===C),R=A?u.find(v=>v.provider===A.provider):void 0,b=(A?.provider||q?.provider||"").toLowerCase().trim(),Q=b==="gemini"||b==="agy",te=()=>{a.invalidateQueries({queryKey:["cliproxy"]}),a.invalidateQueries({queryKey:["cliproxy-auth"]}),a.invalidateQueries({queryKey:["cliproxy-catalog"]}),a.invalidateQueries({queryKey:["cliproxy-models"]})},ne=(v,O,be)=>{p.isPending||j.isPending||(be?p.mutate({provider:v,accountId:O}):j.mutate({provider:v,accountId:O}))},U=(v,O)=>{g.isPending||g.mutate({provider:v,accountId:O})},ae=(v,O)=>{h.isPending||h.mutate({provider:v,accountIds:O})},$=(v,O)=>{E.isPending||E.mutate({provider:v,accountIds:O})},Z=v=>{G(v),y(null)},ie=v=>{y(v),G(null)};return e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",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(Ie,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:l?.backendLabel??"CLIProxy"})]}),e.jsx(K,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:te,disabled:d,children:e.jsx(St,{className:X("w-4 h-4",d&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:t("cliproxyPage.accountManagement")}),e.jsxs(K,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>x(!0),children:[e.jsx(De,{className:"w-4 h-4"}),t("cliproxyPage.quickSetup")]})]}),e.jsx(kt,{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:t("cliproxyPage.providers")}),n?e.jsx("div",{className:"space-y-2 px-2",children:[1,2,3,4].map(v=>e.jsx(ja,{className:"h-14 w-full rounded-lg"},v))}):e.jsx("div",{className:"space-y-4",children:T.map(v=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"px-3",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:t(v.labelKey)}),e.jsx("p",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:t(v.hintKey)})]}),e.jsx("div",{className:"space-y-1",children:v.items.map(O=>e.jsx(Tn,{status:O,isSelected:V===O.provider,onSelect:()=>Z(O.provider)},O.provider))})]},v.id))}),z.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(gs,{className:"w-3 h-3"}),t("cliproxyPage.variants")]}),e.jsx("div",{className:"space-y-1",children:z.map(v=>e.jsx(En,{variant:v,parentAuth:u.find(O=>O.provider===v.provider),isSelected:C===v.name,onSelect:()=>ie(v.name),onDelete:()=>k.mutate(v.name),isDeleting:k.isPending},v.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(Ta,{})}),e.jsx("div",{className:"p-3 border-t bg-background text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:t("cliproxyPage.providerCount",{count:u.length})}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"w-3 h-3 text-green-600"}),t("cliproxyPage.connectedCount",{count:u.filter(v=>v.authenticated).length})]})]})})]}),e.jsx("div",{className:"flex-1 flex min-w-0 flex-col overflow-hidden bg-background",children:A&&R?e.jsx(e.Fragment,{children:e.jsx(Wt,{provider:A.name,displayName:t("cliproxyPage.variantDisplay",{name:A.name,provider:A.provider}),authStatus:R,catalog:P[A.provider],routing:_[A.provider],logoProvider:A.provider,baseProvider:A.provider,defaultTarget:A.target,isRemoteMode:N,port:A.port,topNotice:Q?e.jsx(gt,{compact:!0,showProxySettingsLink:!0}):void 0,onAddAccount:()=>I({provider:A.provider,displayName:R.displayName,isFirstAccount:(R.accounts?.length||0)===0}),onSetDefault:v=>r.mutate({provider:A.provider,accountId:v}),onRemoveAccount:v=>m.mutate({provider:A.provider,accountId:v}),onPauseToggle:(v,O)=>ne(A.provider,v,O),onSoloMode:v=>U(A.provider,v),onBulkPause:v=>ae(A.provider,v),onBulkResume:v=>$(A.provider,v),isRemovingAccount:m.isPending,isPausingAccount:p.isPending||j.isPending,isSoloingAccount:g.isPending,isBulkPausing:h.isPending,isBulkResuming:E.isPending})}):q?e.jsx(e.Fragment,{children:e.jsx(Wt,{provider:q.provider,displayName:q.displayName,authStatus:q,catalog:P[q.provider],routing:_[q.provider],isRemoteMode:N,topNotice:Q?e.jsx(gt,{compact:!0,showProxySettingsLink:!0}):void 0,onAddAccount:()=>I({provider:q.provider,displayName:q.displayName,isFirstAccount:(q.accounts?.length||0)===0}),onSetDefault:v=>r.mutate({provider:q.provider,accountId:v}),onRemoveAccount:v=>m.mutate({provider:q.provider,accountId:v}),onPauseToggle:(v,O)=>ne(q.provider,v,O),onSoloMode:v=>U(q.provider,v),onBulkPause:v=>ae(q.provider,v),onBulkResume:v=>$(q.provider,v),isRemovingAccount:m.isPending,isPausingAccount:p.isPending||j.isPending,isSoloingAccount:g.isPending,isBulkPausing:h.isPending,isBulkResuming:E.isPending})}):e.jsx(Rn,{onSetup:()=>x(!0)})}),e.jsx(en,{open:w,onClose:()=>x(!1)}),e.jsx(ln,{open:f!==null,onClose:()=>I(null),provider:f?.provider||"",displayName:f?.displayName||"",catalog:F&&f?.provider?P[f.provider]:void 0,isFirstAccount:f?.isFirstAccount||!1})]})}export{Yn as CliproxyPage};