@kaitranntt/ccs 7.73.1 → 7.74.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/README.md +5 -1
  2. package/config/base-claude.settings.json +1 -1
  3. package/dist/ccs.js +68 -18
  4. package/dist/ccs.js.map +1 -1
  5. package/dist/cliproxy/account-safety.d.ts +11 -0
  6. package/dist/cliproxy/account-safety.d.ts.map +1 -1
  7. package/dist/cliproxy/account-safety.js +114 -1
  8. package/dist/cliproxy/account-safety.js.map +1 -1
  9. package/dist/cliproxy/binary/types.d.ts +3 -3
  10. package/dist/cliproxy/binary/types.d.ts.map +1 -1
  11. package/dist/cliproxy/binary/types.js +3 -3
  12. package/dist/cliproxy/binary/types.js.map +1 -1
  13. package/dist/cliproxy/binary-manager.d.ts +11 -14
  14. package/dist/cliproxy/binary-manager.d.ts.map +1 -1
  15. package/dist/cliproxy/binary-manager.js +56 -42
  16. package/dist/cliproxy/binary-manager.js.map +1 -1
  17. package/dist/cliproxy/catalog-cache.d.ts.map +1 -1
  18. package/dist/cliproxy/catalog-cache.js +7 -0
  19. package/dist/cliproxy/catalog-cache.js.map +1 -1
  20. package/dist/cliproxy/codex-plan-compatibility.d.ts.map +1 -1
  21. package/dist/cliproxy/codex-plan-compatibility.js +1 -0
  22. package/dist/cliproxy/codex-plan-compatibility.js.map +1 -1
  23. package/dist/cliproxy/codex-reasoning-proxy.d.ts +4 -0
  24. package/dist/cliproxy/codex-reasoning-proxy.d.ts.map +1 -1
  25. package/dist/cliproxy/codex-reasoning-proxy.js +41 -20
  26. package/dist/cliproxy/codex-reasoning-proxy.js.map +1 -1
  27. package/dist/cliproxy/config/env-builder.d.ts.map +1 -1
  28. package/dist/cliproxy/config/env-builder.js +0 -57
  29. package/dist/cliproxy/config/env-builder.js.map +1 -1
  30. package/dist/cliproxy/config/thinking-config.d.ts.map +1 -1
  31. package/dist/cliproxy/config/thinking-config.js +9 -1
  32. package/dist/cliproxy/config/thinking-config.js.map +1 -1
  33. package/dist/cliproxy/executor/env-resolver.d.ts.map +1 -1
  34. package/dist/cliproxy/executor/env-resolver.js +2 -2
  35. package/dist/cliproxy/executor/env-resolver.js.map +1 -1
  36. package/dist/cliproxy/executor/https-tunnel-policy.d.ts +17 -0
  37. package/dist/cliproxy/executor/https-tunnel-policy.d.ts.map +1 -0
  38. package/dist/cliproxy/executor/https-tunnel-policy.js +20 -0
  39. package/dist/cliproxy/executor/https-tunnel-policy.js.map +1 -0
  40. package/dist/cliproxy/executor/index.d.ts.map +1 -1
  41. package/dist/cliproxy/executor/index.js +50 -16
  42. package/dist/cliproxy/executor/index.js.map +1 -1
  43. package/dist/cliproxy/model-catalog.d.ts +1 -1
  44. package/dist/cliproxy/model-catalog.d.ts.map +1 -1
  45. package/dist/cliproxy/model-catalog.js +30 -1
  46. package/dist/cliproxy/model-catalog.js.map +1 -1
  47. package/dist/cliproxy/model-config.d.ts.map +1 -1
  48. package/dist/cliproxy/model-config.js +1 -8
  49. package/dist/cliproxy/model-config.js.map +1 -1
  50. package/dist/cliproxy/model-id-normalizer.d.ts +2 -2
  51. package/dist/cliproxy/model-id-normalizer.d.ts.map +1 -1
  52. package/dist/cliproxy/model-id-normalizer.js +20 -9
  53. package/dist/cliproxy/model-id-normalizer.js.map +1 -1
  54. package/dist/cliproxy/platform-detector.d.ts +5 -6
  55. package/dist/cliproxy/platform-detector.d.ts.map +1 -1
  56. package/dist/cliproxy/platform-detector.js +5 -6
  57. package/dist/cliproxy/platform-detector.js.map +1 -1
  58. package/dist/cliproxy/quota-manager.d.ts.map +1 -1
  59. package/dist/cliproxy/quota-manager.js +25 -2
  60. package/dist/cliproxy/quota-manager.js.map +1 -1
  61. package/dist/cliproxy/services/binary-service.d.ts.map +1 -1
  62. package/dist/cliproxy/services/binary-service.js +7 -14
  63. package/dist/cliproxy/services/binary-service.js.map +1 -1
  64. package/dist/cliproxy/services/variant-service.d.ts +2 -2
  65. package/dist/cliproxy/services/variant-service.js +2 -2
  66. package/dist/cliproxy/services/variant-settings.d.ts.map +1 -1
  67. package/dist/cliproxy/services/variant-settings.js +2 -4
  68. package/dist/cliproxy/services/variant-settings.js.map +1 -1
  69. package/dist/cliproxy/thinking-validator.d.ts +6 -1
  70. package/dist/cliproxy/thinking-validator.d.ts.map +1 -1
  71. package/dist/cliproxy/thinking-validator.js +22 -2
  72. package/dist/cliproxy/thinking-validator.js.map +1 -1
  73. package/dist/cliproxy/tool-sanitization-proxy.d.ts +4 -0
  74. package/dist/cliproxy/tool-sanitization-proxy.d.ts.map +1 -1
  75. package/dist/cliproxy/tool-sanitization-proxy.js +49 -27
  76. package/dist/cliproxy/tool-sanitization-proxy.js.map +1 -1
  77. package/dist/cliproxy/types.d.ts +3 -4
  78. package/dist/cliproxy/types.d.ts.map +1 -1
  79. package/dist/cliproxy/types.js.map +1 -1
  80. package/dist/commands/browser-command.d.ts.map +1 -1
  81. package/dist/commands/browser-command.js +243 -12
  82. package/dist/commands/browser-command.js.map +1 -1
  83. package/dist/commands/cliproxy/help-subcommand.d.ts.map +1 -1
  84. package/dist/commands/cliproxy/help-subcommand.js +2 -2
  85. package/dist/commands/cliproxy/help-subcommand.js.map +1 -1
  86. package/dist/commands/command-catalog.d.ts +1 -1
  87. package/dist/commands/command-catalog.d.ts.map +1 -1
  88. package/dist/commands/command-catalog.js +4 -2
  89. package/dist/commands/command-catalog.js.map +1 -1
  90. package/dist/commands/completion-backend.d.ts.map +1 -1
  91. package/dist/commands/completion-backend.js +21 -0
  92. package/dist/commands/completion-backend.js.map +1 -1
  93. package/dist/commands/config-thinking-command.js +1 -1
  94. package/dist/commands/config-thinking-command.js.map +1 -1
  95. package/dist/commands/proxy-command.d.ts +1 -0
  96. package/dist/commands/proxy-command.d.ts.map +1 -1
  97. package/dist/commands/proxy-command.js +105 -25
  98. package/dist/commands/proxy-command.js.map +1 -1
  99. package/dist/config/unified-config-loader.d.ts.map +1 -1
  100. package/dist/config/unified-config-loader.js +32 -6
  101. package/dist/config/unified-config-loader.js.map +1 -1
  102. package/dist/config/unified-config-types.d.ts +17 -2
  103. package/dist/config/unified-config-types.d.ts.map +1 -1
  104. package/dist/config/unified-config-types.js +10 -2
  105. package/dist/config/unified-config-types.js.map +1 -1
  106. package/dist/cursor/cursor-anthropic-translator.d.ts.map +1 -1
  107. package/dist/cursor/cursor-anthropic-translator.js +17 -3
  108. package/dist/cursor/cursor-anthropic-translator.js.map +1 -1
  109. package/dist/cursor/cursor-anthropic-types.d.ts +3 -0
  110. package/dist/cursor/cursor-anthropic-types.d.ts.map +1 -1
  111. package/dist/cursor/cursor-default-models.d.ts +1 -1
  112. package/dist/cursor/cursor-default-models.d.ts.map +1 -1
  113. package/dist/cursor/cursor-default-models.js +11 -1
  114. package/dist/cursor/cursor-default-models.js.map +1 -1
  115. package/dist/delegation/headless-executor.d.ts.map +1 -1
  116. package/dist/delegation/headless-executor.js +29 -2
  117. package/dist/delegation/headless-executor.js.map +1 -1
  118. package/dist/glmt/delta-accumulator.d.ts +4 -0
  119. package/dist/glmt/delta-accumulator.d.ts.map +1 -1
  120. package/dist/glmt/delta-accumulator.js +17 -5
  121. package/dist/glmt/delta-accumulator.js.map +1 -1
  122. package/dist/glmt/pipeline/stream-parser.d.ts +0 -3
  123. package/dist/glmt/pipeline/stream-parser.d.ts.map +1 -1
  124. package/dist/glmt/pipeline/stream-parser.js +20 -27
  125. package/dist/glmt/pipeline/stream-parser.js.map +1 -1
  126. package/dist/glmt/pipeline/tool-call-handler.d.ts +0 -7
  127. package/dist/glmt/pipeline/tool-call-handler.d.ts.map +1 -1
  128. package/dist/glmt/pipeline/tool-call-handler.js +15 -24
  129. package/dist/glmt/pipeline/tool-call-handler.js.map +1 -1
  130. package/dist/proxy/index.d.ts +1 -0
  131. package/dist/proxy/index.d.ts.map +1 -1
  132. package/dist/proxy/index.js +1 -0
  133. package/dist/proxy/index.js.map +1 -1
  134. package/dist/proxy/proxy-daemon-entry.js +2 -1
  135. package/dist/proxy/proxy-daemon-entry.js.map +1 -1
  136. package/dist/proxy/proxy-daemon-paths.d.ts +9 -3
  137. package/dist/proxy/proxy-daemon-paths.d.ts.map +1 -1
  138. package/dist/proxy/proxy-daemon-paths.js +21 -6
  139. package/dist/proxy/proxy-daemon-paths.js.map +1 -1
  140. package/dist/proxy/proxy-daemon-state.d.ts +10 -5
  141. package/dist/proxy/proxy-daemon-state.d.ts.map +1 -1
  142. package/dist/proxy/proxy-daemon-state.js +81 -12
  143. package/dist/proxy/proxy-daemon-state.js.map +1 -1
  144. package/dist/proxy/proxy-daemon.d.ts +4 -3
  145. package/dist/proxy/proxy-daemon.d.ts.map +1 -1
  146. package/dist/proxy/proxy-daemon.js +351 -92
  147. package/dist/proxy/proxy-daemon.js.map +1 -1
  148. package/dist/proxy/proxy-port-resolver.d.ts +9 -0
  149. package/dist/proxy/proxy-port-resolver.d.ts.map +1 -0
  150. package/dist/proxy/proxy-port-resolver.js +62 -0
  151. package/dist/proxy/proxy-port-resolver.js.map +1 -0
  152. package/dist/proxy/server/messages-route.d.ts.map +1 -1
  153. package/dist/proxy/server/messages-route.js +2 -7
  154. package/dist/proxy/server/messages-route.js.map +1 -1
  155. package/dist/proxy/server/proxy-server.d.ts.map +1 -1
  156. package/dist/proxy/server/proxy-server.js +35 -23
  157. package/dist/proxy/server/proxy-server.js.map +1 -1
  158. package/dist/proxy/transformers/request-transformer.d.ts.map +1 -1
  159. package/dist/proxy/transformers/request-transformer.js +23 -18
  160. package/dist/proxy/transformers/request-transformer.js.map +1 -1
  161. package/dist/targets/claude-adapter.d.ts.map +1 -1
  162. package/dist/targets/claude-adapter.js +2 -2
  163. package/dist/targets/claude-adapter.js.map +1 -1
  164. package/dist/targets/codex-adapter.d.ts.map +1 -1
  165. package/dist/targets/codex-adapter.js +1 -1
  166. package/dist/targets/codex-adapter.js.map +1 -1
  167. package/dist/targets/droid-config-manager.d.ts.map +1 -1
  168. package/dist/targets/droid-config-manager.js +40 -0
  169. package/dist/targets/droid-config-manager.js.map +1 -1
  170. package/dist/targets/target-resolver.d.ts.map +1 -1
  171. package/dist/targets/target-resolver.js +15 -0
  172. package/dist/targets/target-resolver.js.map +1 -1
  173. package/dist/ui/assets/{accounts-BNSlujHd.js → accounts-BGE0yjYy.js} +1 -1
  174. package/dist/ui/assets/{alert-dialog-DHK6l5WN.js → alert-dialog-DuiOADsV.js} +1 -1
  175. package/dist/ui/assets/{api-Bixmu-o6.js → api-Guj515aS.js} +1 -1
  176. package/dist/ui/assets/{auth-section-BXHLEs4g.js → auth-section-SAQbhr1I.js} +1 -1
  177. package/dist/ui/assets/{backups-section-BWGX4IT_.js → backups-section-DDvlWpiu.js} +1 -1
  178. package/dist/ui/assets/{channels-Du6Q5wGz.js → channels-BplAqAOq.js} +1 -1
  179. package/dist/ui/assets/{checkbox-CdduUSQP.js → checkbox-BOkFW5T7.js} +1 -1
  180. package/dist/ui/assets/{claude-extension-D407M3LZ.js → claude-extension-n_MuC68N.js} +1 -1
  181. package/dist/ui/assets/cliproxy-WWj2GyJE.js +3 -0
  182. package/dist/ui/assets/{cliproxy-ai-providers-BRrCP6ap.js → cliproxy-ai-providers-B70CiXmm.js} +1 -1
  183. package/dist/ui/assets/{cliproxy-control-panel-_Yccw80J.js → cliproxy-control-panel-B7FrWnuW.js} +1 -1
  184. package/dist/ui/assets/codex-BoljmCX9.js +27 -0
  185. package/dist/ui/assets/{confirm-dialog-0poiyBAw.js → confirm-dialog-D73zMOJ7.js} +1 -1
  186. package/dist/ui/assets/{copilot-8xH7Nk9a.js → copilot-CmS0DhuS.js} +1 -1
  187. package/dist/ui/assets/{cursor-Dgg-ni59.js → cursor-btzq1F22.js} +1 -1
  188. package/dist/ui/assets/{droid-CDpc1L0C.js → droid-Dt-4f5BE.js} +1 -1
  189. package/dist/ui/assets/{globalenv-section-CcdoEVNK.js → globalenv-section-DWWZ9ERp.js} +1 -1
  190. package/dist/ui/assets/{health-dj20C2Gn.js → health-CuzprvVL.js} +1 -1
  191. package/dist/ui/assets/icons-DyorC3Xk.js +1 -0
  192. package/dist/ui/assets/{index-CQp8Tx8Q.js → index-CA5Km3DW.js} +1 -1
  193. package/dist/ui/assets/{index-DumrYfrM.js → index-CHCBgQxw.js} +1 -1
  194. package/dist/ui/assets/index-ClrCKbzh.js +1 -0
  195. package/dist/ui/assets/index-DEqhujvv.js +9 -0
  196. package/dist/ui/assets/index-DPiX3K4c.js +1 -0
  197. package/dist/ui/assets/{index-CJgNAOTk.js → index-DQXr3j8J.js} +1 -1
  198. package/dist/ui/assets/index-DhAjOd4r.js +72 -0
  199. package/dist/ui/assets/{logs-qfToZXwm.js → logs-CabVgAOr.js} +1 -1
  200. package/dist/ui/assets/{masked-input-BMznu3pB.js → masked-input-4lwOg03z.js} +1 -1
  201. package/dist/ui/assets/{proxy-status-widget-BaDK8Rtz.js → proxy-status-widget-C6Ctzus0.js} +1 -1
  202. package/dist/ui/assets/{raw-json-settings-editor-panel-DgDt3Vlv.js → raw-json-settings-editor-panel-upVhpuik.js} +1 -1
  203. package/dist/ui/assets/{searchable-select-7ZDkhIXd.js → searchable-select-DkL__exx.js} +1 -1
  204. package/dist/ui/assets/{separator-BjiPsa_I.js → separator-fWUi3UIY.js} +1 -1
  205. package/dist/ui/assets/{shared-B-IiUz1s.js → shared-I-FRJqTw.js} +1 -1
  206. package/dist/ui/assets/{table-BrWMZ3pU.js → table-D3mrbj8H.js} +1 -1
  207. package/dist/ui/assets/{updates-CxJ8al_e.js → updates-2HIhdejN.js} +1 -1
  208. package/dist/ui/index.html +2 -2
  209. package/dist/utils/browser/browser-policy.d.ts +22 -0
  210. package/dist/utils/browser/browser-policy.d.ts.map +1 -0
  211. package/dist/utils/browser/browser-policy.js +65 -0
  212. package/dist/utils/browser/browser-policy.js.map +1 -0
  213. package/dist/utils/browser/browser-settings.d.ts +11 -2
  214. package/dist/utils/browser/browser-settings.d.ts.map +1 -1
  215. package/dist/utils/browser/browser-settings.js +65 -42
  216. package/dist/utils/browser/browser-settings.js.map +1 -1
  217. package/dist/utils/browser/browser-setup.d.ts +21 -0
  218. package/dist/utils/browser/browser-setup.d.ts.map +1 -0
  219. package/dist/utils/browser/browser-setup.js +68 -0
  220. package/dist/utils/browser/browser-setup.js.map +1 -0
  221. package/dist/utils/browser/browser-status.d.ts +8 -5
  222. package/dist/utils/browser/browser-status.d.ts.map +1 -1
  223. package/dist/utils/browser/browser-status.js +97 -33
  224. package/dist/utils/browser/browser-status.js.map +1 -1
  225. package/dist/utils/browser/index.d.ts +7 -3
  226. package/dist/utils/browser/index.d.ts.map +1 -1
  227. package/dist/utils/browser/index.js +15 -1
  228. package/dist/utils/browser/index.js.map +1 -1
  229. package/dist/utils/config-manager.d.ts +5 -0
  230. package/dist/utils/config-manager.d.ts.map +1 -1
  231. package/dist/utils/config-manager.js +16 -3
  232. package/dist/utils/config-manager.js.map +1 -1
  233. package/dist/utils/hooks/get-image-analysis-hook-env.d.ts.map +1 -1
  234. package/dist/utils/hooks/get-image-analysis-hook-env.js +7 -3
  235. package/dist/utils/hooks/get-image-analysis-hook-env.js.map +1 -1
  236. package/dist/utils/shell-executor.d.ts +14 -0
  237. package/dist/utils/shell-executor.d.ts.map +1 -1
  238. package/dist/utils/shell-executor.js +98 -23
  239. package/dist/utils/shell-executor.js.map +1 -1
  240. package/dist/web-server/middleware/auth-middleware.d.ts +2 -2
  241. package/dist/web-server/middleware/auth-middleware.d.ts.map +1 -1
  242. package/dist/web-server/middleware/auth-middleware.js.map +1 -1
  243. package/dist/web-server/model-pricing.d.ts.map +1 -1
  244. package/dist/web-server/model-pricing.js +7 -0
  245. package/dist/web-server/model-pricing.js.map +1 -1
  246. package/dist/web-server/routes/browser-routes.d.ts.map +1 -1
  247. package/dist/web-server/routes/browser-routes.js +76 -10
  248. package/dist/web-server/routes/browser-routes.js.map +1 -1
  249. package/dist/web-server/services/cliproxy-dashboard-install-service.d.ts.map +1 -1
  250. package/dist/web-server/services/cliproxy-dashboard-install-service.js +1 -2
  251. package/dist/web-server/services/cliproxy-dashboard-install-service.js.map +1 -1
  252. package/lib/mcp/ccs-browser-server.cjs +5727 -424
  253. package/package.json +5 -3
  254. package/scripts/ci-parity-gate.sh +11 -3
  255. package/scripts/ensure-deps.sh +18 -0
  256. package/scripts/run-test-bucket.js +186 -0
  257. package/dist/ui/assets/cliproxy-BcXcp3jL.js +0 -3
  258. package/dist/ui/assets/codex-C-Aq41_4.js +0 -27
  259. package/dist/ui/assets/icons-Dmi9qMuE.js +0 -1
  260. package/dist/ui/assets/index-B2ffORVS.js +0 -9
  261. package/dist/ui/assets/index-BPjLIQ2v.js +0 -1
  262. package/dist/ui/assets/index-DJiXf8E8.js +0 -1
  263. package/dist/ui/assets/index-TR572mqL.js +0 -72
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaitranntt/ccs",
3
- "version": "7.73.1",
3
+ "version": "7.74.0-dev.2",
4
4
  "description": "Claude Code Switch - Instant profile switching between Claude, GLM, Kimi, and more",
5
5
  "keywords": [
6
6
  "cli",
@@ -70,12 +70,14 @@
70
70
  "lint:fix": "eslint src/ --fix",
71
71
  "format": "prettier --write src/",
72
72
  "format:check": "prettier --check src/",
73
- "validate": "bun run typecheck && bun run lint:fix && bun run format:check && bun run test:all",
73
+ "validate": "bun run typecheck && bun run lint && bun run format:check && bun run test:fast",
74
74
  "validate:ci-parity": "bash scripts/ci-parity-gate.sh",
75
75
  "verify:bundle": "node scripts/verify-bundle.js",
76
76
  "test": "bun run build && bun run test:all",
77
77
  "test:ci": "bun run test:all",
78
- "test:all": "bun test tests/unit tests/integration tests/npm",
78
+ "test:fast": "node scripts/run-test-bucket.js fast",
79
+ "test:slow": "node scripts/run-test-bucket.js slow",
80
+ "test:all": "node scripts/run-test-bucket.js all",
79
81
  "test:unit": "bun test tests/unit",
80
82
  "test:npm": "bun test tests/npm/",
81
83
  "test:native": "bash tests/native/unix/edge-cases.sh",
@@ -45,7 +45,9 @@ echo "[i] Pre-push CI parity gate"
45
45
  echo " branch: $CURRENT_BRANCH"
46
46
  echo " base: $BASE_BRANCH"
47
47
 
48
- git fetch origin "$BASE_BRANCH" --quiet || true
48
+ if git ls-remote --exit-code --heads origin "$BASE_BRANCH" >/dev/null 2>&1; then
49
+ git fetch origin "$BASE_BRANCH" --quiet
50
+ fi
49
51
  if git show-ref --verify --quiet "refs/remotes/origin/$BASE_BRANCH"; then
50
52
  if ! git merge-base --is-ancestor "origin/$BASE_BRANCH" HEAD; then
51
53
  echo "[X] Branch '$CURRENT_BRANCH' is behind origin/$BASE_BRANCH."
@@ -55,8 +57,14 @@ if git show-ref --verify --quiet "refs/remotes/origin/$BASE_BRANCH"; then
55
57
  fi
56
58
  fi
57
59
 
58
- echo "[i] Running CI-equivalent local checks..."
60
+ echo "[i] Running CI-parity local checks..."
61
+ # `set -euo pipefail` above makes every step fail fast. Keep these commands
62
+ # explicit so parity drift is visible when CI changes.
63
+ bun run typecheck
64
+ bun run lint
65
+ bun run format:check
59
66
  bun run build:all
60
- bun run validate
67
+ bun run test:all
68
+ CCS_E2E_SKIP_BUILD=1 bun run test:e2e
61
69
 
62
70
  echo "[OK] CI parity gate passed."
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ UI_DIR="$ROOT_DIR/ui"
6
+
7
+ ensure_root_deps() {
8
+ echo "[deps] Syncing root dependencies"
9
+ (cd "$ROOT_DIR" && bun install --frozen-lockfile)
10
+ }
11
+
12
+ ensure_ui_deps() {
13
+ echo "[deps] Syncing UI dependencies"
14
+ (cd "$UI_DIR" && bun install --frozen-lockfile)
15
+ }
16
+
17
+ ensure_root_deps
18
+ ensure_ui_deps
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const { spawnSync } = require('node:child_process');
6
+
7
+ const rootDir = path.resolve(__dirname, '..');
8
+ const candidateRoots = ['tests/unit', 'tests/integration', 'tests/npm'];
9
+ // Add a `.ts` test to `slowTests` when ANY of these apply:
10
+ // 1. It spawns a child process (CLI, bun test, node, gh, etc.).
11
+ // 2. It binds a port, starts a server, or talks to localhost.
12
+ // 3. It reads a real file from `dist/` or the repo root at runtime.
13
+ // 4. It waits on a timer > 500ms or a filesystem watcher.
14
+ // 5. A single run consistently takes > 1500ms on reference hardware.
15
+ // Tests that literally reference `dist/` in source are auto-forced slow by
16
+ // `readsBuiltDist`. This list is the manual catch-all for `.ts` tests that
17
+ // meet the criteria above without the literal `dist/` string.
18
+ // `tests/unit/scripts/run-test-bucket.test.js` verifies every path here exists
19
+ // (catches deletion drift) but CANNOT detect new undeclared slow tests.
20
+ // Automated perf-budget enforcement tracked in issue #1071.
21
+ const slowTests = [
22
+ 'tests/integration/cursor-daemon-lifecycle.test.ts',
23
+ 'tests/integration/proxy/daemon-lifecycle.test.ts',
24
+ 'tests/unit/commands/persist-command-handler.test.ts',
25
+ 'tests/unit/hooks/browser-mcp-advanced-interactions.test.ts',
26
+ 'tests/unit/hooks/browser-mcp-downloads-and-files.test.ts',
27
+ 'tests/unit/hooks/browser-mcp-navigation-and-query.test.ts',
28
+ 'tests/unit/hooks/browser-mcp-orchestration-and-artifacts.test.ts',
29
+ 'tests/unit/hooks/browser-mcp-recording-and-replay.test.ts',
30
+ 'tests/unit/hooks/browser-mcp-session-and-intercepts.test.ts',
31
+ 'tests/unit/targets/codex-runtime-integration.test.ts',
32
+ 'tests/unit/targets/codex-settings-bridge-launch.test.ts',
33
+ 'tests/unit/targets/droid-command-routing-integration.test.ts',
34
+ 'tests/unit/targets/droid-config-manager.test.ts',
35
+ 'tests/unit/targets/settings-profile-browser-launch.test.ts',
36
+ 'tests/unit/targets/settings-profile-image-analysis-launch.test.ts',
37
+ 'tests/unit/targets/settings-profile-websearch-launch.test.ts',
38
+ 'tests/unit/web-server/cursor-routes.test.ts',
39
+ 'tests/unit/web-server/websearch-routes.test.ts',
40
+ ];
41
+ // CommonJS-heavy JS suites stay slow by default because many of them mutate
42
+ // module cache or process state. Opt them into `test:fast` only after they are
43
+ // proven stable in the mixed fast bucket.
44
+ const fastJsTests = new Set([
45
+ 'tests/unit/flag-parsing-simple.test.js',
46
+ ]);
47
+
48
+ const filePattern = /(\.test\.(c|m)?[jt]s|\.spec\.(c|m)?[jt]s|-test\.(c|m)?[jt]s)$/;
49
+
50
+ function collectFiles(dir, files = []) {
51
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
52
+ const fullPath = path.join(dir, entry.name);
53
+ if (entry.isDirectory()) {
54
+ collectFiles(fullPath, files);
55
+ continue;
56
+ }
57
+
58
+ if (filePattern.test(entry.name)) {
59
+ files.push(path.relative(rootDir, fullPath).split(path.sep).join('/'));
60
+ }
61
+ }
62
+
63
+ return files;
64
+ }
65
+
66
+ function readsBuiltDist(relativePath) {
67
+ const source = fs.readFileSync(path.join(rootDir, relativePath), 'utf8');
68
+ return source.includes('dist/');
69
+ }
70
+
71
+ function getDiscoveredTests() {
72
+ return candidateRoots
73
+ .flatMap((relativeDir) => collectFiles(path.join(rootDir, relativeDir)))
74
+ .sort();
75
+ }
76
+
77
+ function shouldForceSlow(file) {
78
+ if (file.startsWith('tests/npm/')) {
79
+ return true;
80
+ }
81
+
82
+ if (/\.(c|m)?js$/.test(file) && !fastJsTests.has(file)) {
83
+ return true;
84
+ }
85
+
86
+ return readsBuiltDist(file);
87
+ }
88
+
89
+ function getSlowSet() {
90
+ const discovered = getDiscoveredTests();
91
+ const forceSlow = discovered.filter((file) => shouldForceSlow(file));
92
+ return new Set([...slowTests, ...forceSlow]);
93
+ }
94
+
95
+ function selectBucket(name) {
96
+ const discovered = getDiscoveredTests();
97
+ const slowSet = getSlowSet();
98
+
99
+ return name === 'slow'
100
+ ? [...slowSet].sort()
101
+ : discovered.filter((file) => !slowSet.has(file));
102
+ }
103
+
104
+ function ensureBuildForSlowBucket() {
105
+ if (fs.existsSync(path.join(rootDir, 'dist', 'ccs.js'))) {
106
+ return 0;
107
+ }
108
+
109
+ const build = spawnSync('bun', ['run', 'build'], {
110
+ cwd: rootDir,
111
+ stdio: 'inherit',
112
+ shell: process.platform === 'win32',
113
+ });
114
+
115
+ return build.status ?? 1;
116
+ }
117
+
118
+ function runBucket(name) {
119
+ const selected = selectBucket(name);
120
+
121
+ if (selected.length === 0) {
122
+ console.error(`[X] No tests matched the '${name}' bucket.`);
123
+ return 1;
124
+ }
125
+
126
+ if (name === 'slow') {
127
+ const buildStatus = ensureBuildForSlowBucket();
128
+ if (buildStatus !== 0) {
129
+ return buildStatus;
130
+ }
131
+ }
132
+
133
+ // Slow bucket forces sequential execution because it spawns subprocesses,
134
+ // binds ports, and touches shared state — parallelism causes flakes.
135
+ // Fast bucket keeps bun's default parallelism for speed.
136
+ const bunArgs = name === 'slow'
137
+ ? ['test', '--max-concurrency=1', ...selected]
138
+ : ['test', ...selected];
139
+
140
+ const result = spawnSync('bun', bunArgs, {
141
+ cwd: rootDir,
142
+ stdio: 'inherit',
143
+ shell: process.platform === 'win32',
144
+ });
145
+
146
+ return result.status ?? 1;
147
+ }
148
+
149
+ function main(args = process.argv.slice(2)) {
150
+ const bucket = args[0];
151
+
152
+ if (!['fast', 'slow', 'all'].includes(bucket)) {
153
+ console.error('[X] Usage: node scripts/run-test-bucket.js <fast|slow|all>');
154
+ return 1;
155
+ }
156
+
157
+ if (bucket === 'all') {
158
+ let exitCode = 0;
159
+
160
+ for (const name of ['fast', 'slow']) {
161
+ const status = runBucket(name);
162
+ if (status !== 0) {
163
+ exitCode = status;
164
+ }
165
+ }
166
+
167
+ return exitCode;
168
+ }
169
+
170
+ return runBucket(bucket);
171
+ }
172
+
173
+ if (require.main === module) {
174
+ process.exit(main());
175
+ }
176
+
177
+ module.exports = {
178
+ slowTests,
179
+ fastJsTests,
180
+ readsBuiltDist,
181
+ shouldForceSlow,
182
+ getDiscoveredTests,
183
+ getSlowSet,
184
+ selectBucket,
185
+ main,
186
+ };
@@ -1,3 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as c}from"./react-vendor-CNOkPC89.js";import{a as xt,u as Vt,b as Ns}from"./tanstack-CrmUhA7Z.js";import{a8 as ys,a as $,d as K,C as Bt,b as $t,a9 as Wt,aa as Qt,c as X,P as ht,B as z,ab as ue,L as Y,I as le,r as qe,s as ze,t as Ge,v as Ve,w as ye,ac as Jt,ad as Xt,ae as ws,af as ks,ag as Cs,u as Yt,ah as gt,ai as ft,aj as vt,ak as jt,W as me,al as Zt,am as Dt,an as As,ao as Ss,ap as Qe,aq as es,Y as Be,ar as Ps,as as It,at as Tt,au as Ms,av as Ds,aw as Is,ax as Ts,ay as Es,az as Ls,aA as Rs,aB as Os,aC as Et,aD as _s,x as ts,n as bt,aE as Nt,aF as Lt,aG as ss,aH as Fs,m as Us,aI as Ks,aJ as Hs,aK as ot,T as lt,p as dt,q as ct,aL as qs,aM as zs,aN as Gs,aO as Rt,aP as Vs,aQ as Bs,aR as $s,aS as Ws,aT as Qs,aU as Js,Q as Xs,R as Ys,U as Ot,V as _t,aV as Zs,aW as ea,aX as ta,aY as sa,aZ as aa,a_ as na,a$ as ia,b0 as ra,b1 as oa,b2 as la,b3 as da,b4 as ca,S as ua}from"./index-TR572mqL.js";import{C as ut}from"./default-ports-1QQSffYX.js";import{t as B}from"./notifications-B2HqRBj7.js";import{C as as,L as de,p as we,$ as ma,m as ke,o as ns,aG as yt,R as wt,q as Me,aa as De,T as Je,a7 as Ft,aH as is,aF as pa,z as kt,Z as Ie,_ as rs,i as xa,u as os,aI as ha,au as ga,X as Ct,a9 as ls,J as ds,D as cs,aJ as fa,at as us,aK as va,ax as ja,aL as ms}from"./icons-Dmi9qMuE.js";import{R as $e,A as Ut,D as at,i as ba,a as Na}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{C as We}from"./checkbox-CdduUSQP.js";import{C as ya}from"./confirm-dialog-0poiyBAw.js";import{S as At}from"./separator-BjiPsa_I.js";import{S as wa}from"./searchable-select-7ZDkhIXd.js";import{P as ka}from"./proxy-status-widget-BaDK8Rtz.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-DHK6l5WN.js";const se="gemini-3.1-pro-high",Ce="gemini-3.1-pro-low",Ca=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}),ps=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"}),Aa=/^gemini-(\d+(?:[.-]\d+)*)-(pro|flash)-preview(-customtools)?$/i,Sa=["agy/","gcli/"];function Q(t){return ys(t).toLowerCase()}function Pa(t){const a=t.trim(),s=a.toLowerCase();for(const n of Sa)if(s.startsWith(n))return a.slice(n.length);return a}function Ma(t){return t.replace(/-customtools$/i,"")}function Da(t){return Ca[Q(t)]}function Xe(t){const a=Q(t),s=a.match(Aa);if(!s)return null;const[,n,i,u]=s;return{normalizedId:a,version:n.split(/[.-]/).map(o=>Number(o)),family:i,customtools:!!u,dottedVersion:n.includes(".")}}function xs(t,a){const s=Math.max(t.length,a.length);for(let n=0;n<s;n+=1){const i=t[n]??0,u=a[n]??0;if(i!==u)return i>u?1:-1}return 0}function Ia(t,a,s){if(t.customtools!==a.customtools)return t.customtools?1:-1;const n=xs(t.version,a.version);if(n!==0)return n>0?-1:1;const i=+(t.dottedVersion===s.dottedVersion),u=+(a.dottedVersion===s.dottedVersion);return i!==u?u-i:t.normalizedId.localeCompare(a.normalizedId)}function Kt(t,a){const s=Q(a);return t.find(n=>Q(n.id)===s)?.id}function Ta(t,a){const s=Xe(t);return!s||a.length===0?void 0:a.map(i=>{const u=Xe(i.id);return!u||u.family!==s.family?null:{id:i.id,info:u}}).filter(i=>!!i).sort((i,u)=>Ia(i.info,u.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-codex",models:[{id:"gpt-5-codex",name:"GPT-5 Codex",description:"Cross-plan safe Codex default",presetMapping:{default:"gpt-5-codex",opus:"gpt-5-codex",sonnet:"gpt-5-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5-codex-mini",name:"GPT-5 Codex Mini",description:"Faster and cheaper Codex option",presetMapping:{default:"gpt-5-codex-mini",opus:"gpt-5-codex",sonnet:"gpt-5-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"Legacy mini model ID kept for backwards compatibility",presetMapping:{default:"gpt-5-mini",opus:"gpt-5-codex",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"}},{id:"gpt-5.1-codex-mini",name:"GPT-5.1 Codex Mini",description:"Legacy fast Codex mini model",presetMapping:{default:"gpt-5.1-codex-mini",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini"}},{id:"gpt-5.1-codex-max",name:"GPT-5.1 Codex Max",description:"Higher-effort Codex model with xhigh support",presetMapping:{default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini"}},{id:"gpt-5.2-codex",name:"GPT-5.2 Codex",description:"Cross-plan Codex model with xhigh support",presetMapping:{default:"gpt-5.2-codex",opus:"gpt-5.2-codex",sonnet:"gpt-5.2-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",tier:"paid",description:"Paid Codex plans only",presetMapping:{default:"gpt-5.3-codex",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5.3-codex-spark",name:"GPT-5.3 Codex Spark",tier:"paid",description:"Paid Codex plans only, ultra-fast coding model",presetMapping:{default:"gpt-5.3-codex-spark",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5-codex-mini"}},{id:"gpt-5.4",name:"GPT-5.4",tier:"paid",description:"Paid Codex plans only, latest GPT-5 family model",presetMapping:{default:"gpt-5.4",opus:"gpt-5.4",sonnet:"gpt-5.4",haiku:"gpt-5-codex-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-6",name:"Claude Opus 4.6",description:"Latest flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-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 Se(t,a){if(!t)return;const s=Q(a);if(t.provider==="agy"){const o=Da(s);if(o){const l=t.models.find(r=>r.id===o);if(l)return l}}const n=ps[s.toLowerCase()],i=t.models.find(o=>o.id===s||o.id===n);if(i)return i;const u=Xe(s);if(u)return t.models.map(o=>({model:o,info:Xe(o.id)})).filter(o=>!!(o.info&&o.info.family===u.family)).sort((o,l)=>xs(l.info.version,o.info.version))[0]?.model}function Ea(t){if(t==="free")return"free";if(typeof t=="string"&&t.trim().length>0)return"paid"}function La(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=Se(s,l.id);return{...l,name:l.name||r?.name||l.id,tier:r?.tier??Ea(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}}),u=s?.defaultModel?Ae(s.defaultModel,n):void 0,o=typeof u=="string"&&n.some(l=>Q(l.id)===Q(u));return{provider:a.provider,displayName:a.displayName||s?.displayName||t,defaultModel:o?u:a.defaultModel,models:i}}function St(t){const a={},s=new Set([...Object.keys(xe),...Object.keys(t??{})]);for(const n of s){const i=La(n,t?.[n]);i&&(a[n]=i)}return a}function hs(t,a,s){const n=Se(s,a);return n||Se(xe[t.toLowerCase()],a)}function Ae(t,a=[]){const s=Q(t),n=Ta(s,a);if(n)return n;const i=Kt(a,s);if(i)return i;const u=ps[s];return(u?Kt(a,u):void 0)??s}function Ra(t,a=[]){return{default:Ae(t.default,a),opus:Ae(t.opus,a),sonnet:Ae(t.sonnet,a),haiku:Ae(t.haiku,a)}}function Pt(t,a=[]){if(!t)return[];const s=xe[t.provider.toLowerCase()]??t,n=new Set;return s.models.map(i=>{const u=Ae(i.id,a),o=i.presetMapping?Ra(i.presetMapping,a):void 0,l=t.models.find(r=>Q(r.id)===Q(u));return{...i,id:u,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 Oa(t,a,s=[]){const n=t.trim().toLowerCase();if(!a||!n)return[];const i=xe[n]??a,u=Pt(a,s),o=new Set(u.map(p=>Q(p.id))),l=new Set(u.map(p=>Se(i,p.id)?.id).filter(p=>!!p).map(p=>Q(p))),r=new Set,h=new Set(s.map(p=>Q(p.id)));return s.filter(p=>{const v=Q(p.id),x=Pa(p.id),m=Ma(x),T=Se(i,x)??Se(i,m);if(o.has(Q(x))||v!==Q(x)&&h.has(Q(x)))return!1;const k=Q(m);if(k!==Q(x)&&h.has(k))return!1;const D=T?Q(T.id):k;return T&&l.has(D)||r.has(D)||!T&&n==="agy"?!1:(r.add(D),!0)})}function _a(t,a,s){return hs(t,a,s)?.extendedContext===!0}const nt="ccs-internal-managed";async function Fa(){try{const t=await fetch("/api/settings/auth/tokens/raw");return t.ok?(await t.json())?.apiKey?.value??nt:nt}catch{return nt}}async function Ua(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 St(n.catalogs)[t]??xe[t]}catch{return xe[t]}}async function mt(t,a,s){const n=await Ua(t,s);if(!n)return{success:!1};const i=n.models.find(h=>h.id===n.defaultModel)||n.models[0],u=i?.presetMapping||{default:n.defaultModel,opus:n.defaultModel,sonnet:n.defaultModel,haiku:n.defaultModel},o=await Fa(),r={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${ut}/api/provider/${t}`,ANTHROPIC_AUTH_TOKEN:o,ANTHROPIC_MODEL:u.default,ANTHROPIC_DEFAULT_OPUS_MODEL:u.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:u.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:u.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 Ka({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 Ha({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(as,{className:"w-4 h-4 text-muted-foreground"})]},s.id))})}function qa({selectedProvider:t,providers:a,authCommand:s,isRefreshing:n,isPending:i,onBack:u,onStartAuth:o,onRefresh:l}){const{t:r}=$(),[h,p]=c.useState(!1),v=async x=>{await navigator.clipboard.writeText(x),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(x=>x.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(de,{className:"w-4 h-4 animate-spin"}),r("setupWizard.authStep.authenticating")]}):e.jsxs(e.Fragment,{children:[e.jsx(we,{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(Bt,{children:e.jsxs($t,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ma,{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:()=>v(s),children:h?e.jsx(ke,{className:"w-4 h-4 text-green-500"}):e.jsx(ns,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(K,{variant:"ghost",onClick:u,disabled:i,children:[e.jsx(yt,{className:"w-4 h-4 mr-2"}),r("setupWizard.authStep.back")]}),e.jsxs(K,{variant:"outline",onClick:l,disabled:n||i,children:[e.jsx(wt,{className:`w-4 h-4 mr-2 ${n?"animate-spin":""}`}),r(n?"setupWizard.authStep.checking":"setupWizard.authStep.refreshStatus")]})]})]})}function za({accounts:t,privacyMode:a,onSelect:s,onAddNew:n,onBack:i}){const{t:u}=$();return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:u("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=Wt(o.id,o.email,o.tokenFile),r=o.provider?.toLowerCase()==="codex"?Qt(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(Me,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:X("font-medium",a&&ht),children:l.email}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[r?.label?e.jsx(z,{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(z,{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(z,{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:u("setupWizard.accountStep.defaultAccount")})]})]})]}),e.jsx(as,{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:u("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(we,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary",children:u("setupWizard.accountStep.addNewAccount")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:u("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(yt,{className:"w-4 h-4 mr-2"}),u("setupWizard.accountStep.back")]})})]})}const Ht="__custom__";function Ga({selectedProvider:t,catalog:a,selectedAccount:s,variantName:n,modelName:i,isPending:u,privacyMode:o,onVariantNameChange:l,onModelChange:r,onBack:h,onSkip:p,onCreate:v}){const{t:x}=$(),m=a||xe[t],T=m?.models||[],k=i&&!T.some(j=>j.id===i),[D,A]=c.useState(k),C=t==="agy"&&i.trim().length>0?ue(i):!1,y=s?Wt(s.id,s.email,s.tokenFile):null,w=t==="codex"&&y?Qt(y):null,d=j=>{j===Ht?(A(!0),r("")):(A(!1),r(j))};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(Me,{className:"w-4 h-4"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("span",{children:[x("setupVariant.using")," ",e.jsx("span",{className:X(o&&ht),children:y?.email})]}),(y?.audienceLabel||y?.detailLabel)&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[w?.label?e.jsx(z,{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(z,{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(z,{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:x("setupVariant.variantNameRequired")}),e.jsx(le,{id:"variant-name",value:n,onChange:j=>l(j.target.value),placeholder:x("setupVariant.variantNamePlaceholder")}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[x("setupVariant.invokeHintPrefix")," ccs ",n||"<name>",' "prompt"']})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{children:x("setupVariant.model")}),D?e.jsxs("div",{className:"space-y-2",children:[e.jsx(le,{value:i,onChange:j=>r(j.target.value),placeholder:x("setupVariant.modelPlaceholder")}),C&&e.jsx("p",{className:"text-xs text-destructive",children:x("providerEditor.agyDenylist")}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>{A(!1),t==="agy"&&ue(i)&&r("")},children:x("setupVariant.choosePresetInstead")})]}):e.jsxs(qe,{value:T.some(j=>j.id===i)?i:"",onValueChange:d,children:[e.jsx(ze,{children:e.jsx(Ge,{placeholder:x("setupVariant.selectModel")})}),e.jsxs(Ve,{children:[T.map(j=>e.jsx(ye,{value:j.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:j.name}),j.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",j.description]})]})},j.id)),e.jsx(ye,{value:Ht,children:e.jsx("span",{className:"text-primary",children:x("setupVariant.customModelName")})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:D?x("setupVariant.enterAnyModel"):x("setupVariant.defaultModel",{model:m?.defaultModel||x("setupVariant.providerDefault")})})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(K,{variant:"ghost",onClick:h,children:[e.jsx(yt,{className:"w-4 h-4 mr-2"}),x("setupVariant.back")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{variant:"ghost",onClick:p,children:x("setupVariant.skip")}),e.jsx(K,{onClick:v,disabled:!n||u||C,children:x(u?"setupVariant.creating":"setupVariant.createVariant")})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:x("setupVariant.skipHint")})]})}function Va({variantName:t,onClose:a}){const{t:s}=$();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(ke,{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(Bt,{children:e.jsxs($t,{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 Ba({open:t,onClose:a}){const[s,n]=c.useState("provider"),[i,u]=c.useState(""),[o,l]=c.useState(null),[r,h]=c.useState(""),[p,v]=c.useState(""),[x,m]=c.useState(!1),[T,k]=c.useState(!1),{data:D,refetch:A}=Jt(),{data:C}=Xt(),y=ws(),w=ks(),d=Cs(),{privacyMode:j}=Yt(),I=D?.authStatus.find(L=>L.provider===i),g=c.useMemo(()=>I?.accounts||[],[I?.accounts]),M=c.useMemo(()=>St(C?.catalogs),[C?.catalogs]),N=!!C;c.useEffect(()=>{if(!t){const L=setTimeout(()=>{n("provider"),u(""),l(null),h(""),v(""),k(!1)},0);return()=>clearTimeout(L)}},[t]),c.useEffect(()=>{if(s==="auth"&&g.length>0&&!T){const L=setTimeout(()=>{n("account")},0);return()=>clearTimeout(L)}},[s,g,T]);const G=async()=>{m(!0),await A(),m(!1)},P=()=>{const L=(I?.accounts?.length||0)===0;w.mutate({provider:i},{onSuccess:async b=>{if(L){const J=await mt(i,void 0,N?M[i]:void 0);J.success&&J.presetName?B.success(`Applied "${J.presetName}" preset`):J.success||B.warning(me.t("commonToast.accountAddedPresetFailed"))}b.account&&(l(b.account),n("variant")),A()}})},R=L=>{u(L),(D?.authStatus.find(Z=>Z.provider===L)?.accounts||[]).length===0?n("auth"):n("account")},E=L=>{l(L),n("variant")},V=async()=>{if(!(!r||!i))try{await y.mutateAsync({name:r,provider:i,model:p||void 0,account:o?.id}),n("success")}catch(L){console.error("Failed to create variant:",L)}},O=`ccs ${i} --auth --add`,H=Ss(s),F=L=>{if(!L&&(w.isPending&&i&&d.mutate(i),s==="success"||s==="provider")){a();return}};return e.jsx(gt,{open:t,onOpenChange:F,children:e.jsxs(ft,{className:"sm:max-w-lg",onPointerDownOutside:L=>{s!=="success"&&s!=="provider"&&L.preventDefault()},onEscapeKeyDown:L=>{(w.isPending||y.isPending)&&L.preventDefault()},children:[e.jsxs(vt,{children:[e.jsxs(jt,{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-5 h-5 text-primary"}),me.t("setupWizard.title")]}),e.jsxs(Zt,{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(Ha,{providers:Dt,onSelect:R}),s==="auth"&&e.jsx(qa,{selectedProvider:i,providers:Dt,authCommand:O,isRefreshing:x,isPending:w.isPending,onBack:()=>n("provider"),onStartAuth:P,onRefresh:G}),s==="account"&&e.jsx(za,{accounts:g,privacyMode:j,onSelect:E,onAddNew:()=>{k(!0),n("auth")},onBack:()=>n("provider")}),s==="variant"&&e.jsx(Ga,{selectedProvider:i,catalog:M[i],selectedAccount:o,variantName:r,modelName:p,isPending:y.isPending,privacyMode:j,onVariantNameChange:h,onModelChange:v,onBack:()=>g.length>0?n("account"):n("provider"),onSkip:a,onCreate:V}),s==="success"&&e.jsx(Va,{variantName:r,onClose:a})]}),e.jsx(Ka,{currentProgress:H,allSteps:As})]})})}const $a=3e3,Wa=300*1e3,Qa=3;function it(t){t.invalidateQueries({queryKey:["cliproxy-catalog"]}),t.invalidateQueries({queryKey:["cliproxy-models"]})}async function rt(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 Ja(){const{t}=$(),[a,s]=c.useState(fe),n=c.useRef(fe),i=c.useRef(0),u=c.useRef(null),o=c.useRef(null),l=c.useRef(0),r=c.useRef(0),h=c.useRef(!1),p=xt(),v=c.useCallback(A=>A===i.current,[]),x=c.useCallback(()=>{o.current&&(clearInterval(o.current),o.current=null),r.current=0},[]);c.useEffect(()=>()=>{u.current?.abort(),x(),h.current=!1},[x]),c.useEffect(()=>{n.current=a},[a]);const m=c.useCallback(async(A,C,y)=>{if(v(y)){if(Date.now()-l.current>Wa){x(),v(y)&&s(w=>({...w,isAuthenticating:!1,error:t("toasts.providerAuthTimeout")}));return}try{const w=await fetch(`/api/cliproxy/auth/${A}/status?state=${encodeURIComponent(C)}`);if(!v(y))return;const d=await w.json();if(r.current=0,d.status==="ok"){if(!(typeof d.account=="object"&&d.account!==null)){x();const I=t("toasts.providerAccountRegistrationFailed");B.error(I),s(g=>({...g,isAuthenticating:!1,error:I}));return}x(),p.invalidateQueries({queryKey:["cliproxy-auth"]}),p.invalidateQueries({queryKey:["cliproxy-accounts"]}),p.invalidateQueries({queryKey:["account-quota"]}),it(p),B.success(t("toasts.providerAuthSuccess",{provider:A})),h.current=!1,s(fe)}else if(d.status==="auth_url"){const j=d.url||d.auth_url;j&&(s(I=>({...I,authUrl:j})),h.current||(h.current=!0,window.open(j,"_blank")))}else if(d.status==="device_code"){x();const j=d.user_code&&d.verification_url?`Open ${d.verification_url} and enter code: ${d.user_code}`:"Switch to Device Code method and try again.";B.error(t("toasts.providerDeviceCodeInCallback")),s(I=>({...I,isAuthenticating:!1,error:j}))}else if(d.status==="error"){x();const j=d.error||"Authentication failed";B.error(j),s(I=>({...I,isAuthenticating:!1,error:j}))}}catch(w){if(!v(y)||(r.current+=1,r.current<Qa))return;x();const d=w instanceof Error&&w.message.trim().length>0?w.message:t("toasts.providerLostStatusEndpoint");B.error(d),s(j=>({...j,isAuthenticating:!1,error:d}))}}},[v,p,x,t]),T=c.useCallback(async(A,C)=>{if(!Qe(A)){s({...fe,error:t("toasts.providerUnknown",{provider:A})});return}u.current?.abort(),x(),h.current=!1,r.current=0;const y=new AbortController,w=i.current+1;i.current=w,u.current=y;const j=(C?.flowType||(es(A)?"device_code":"authorization_code"))==="device_code",I=C?.startEndpoint||(j?"start":"start-url"),g={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:A,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:j});try{if(I==="start")fetch(`/api/cliproxy/auth/${A}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g),signal:y.signal}).then(async M=>{if(!v(w))return;const N=await rt(M);if(!v(w))return;const G=N.success===!0,P=typeof N.account=="object"&&N.account!==null;if(M.ok&&G&&P)p.invalidateQueries({queryKey:["cliproxy-auth"]}),p.invalidateQueries({queryKey:["cliproxy-accounts"]}),p.invalidateQueries({queryKey:["account-quota"]}),it(p),h.current=!1,s(fe);else{const R=typeof N.error=="string"?N.error:t(G?"toasts.providerAccountRegistrationFailed":"auth.loginFailed");B.error(R),s(E=>({...E,isAuthenticating:!1,error:R}))}}).catch(M=>{if(!v(w)||M instanceof Error&&M.name==="AbortError")return;const N=M instanceof Error?M.message:"Authentication failed";B.error(N),s(G=>({...G,isAuthenticating:!1,error:N}))});else{const M=await fetch(`/api/cliproxy/auth/${A}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g),signal:y.signal});if(!v(w))return;const N=await rt(M);if(!v(w))return;const G=N.success===!0;if(!M.ok||!G){const E=typeof N.error=="string"?N.error:t("toasts.providerStartOAuthFailed");throw new Error(E)}const P=typeof N.authUrl=="string"?N.authUrl:null,R=typeof N.state=="string"?N.state:null;if(s(E=>({...E,authUrl:P,oauthState:R})),P&&(h.current=!0,window.open(P,"_blank")),R){if(l.current=Date.now(),!P){if(await m(A,R,w),!v(w))return;const E=n.current;if(!E.isAuthenticating||E.provider!==A)return}o.current=setInterval(()=>{m(A,R,w)},$a)}}}catch(M){if(!v(w))return;if(M instanceof Error&&M.name==="AbortError"){h.current=!1,s(fe);return}const N=M instanceof Error?M.message:t("auth.loginFailed");B.error(N),s(G=>({...G,isAuthenticating:!1,error:N}))}},[v,m,x,p,t]),k=c.useCallback(()=>{const A=a.provider;i.current+=1,u.current?.abort(),x(),h.current=!1,s(fe),A&&Be.cliproxy.auth.cancel(A).catch(()=>{})},[a.provider,x]),D=c.useCallback(async A=>{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:A})});if(!v(C))return;const d=await rt(w);if(!v(C))return;const j=d.success===!0,I=d.status==="wait",g=typeof d.account=="object"&&d.account!==null;if(w.ok&&I)s(M=>({...M,isSubmittingCallback:!1,error:null}));else if(w.ok&&j&&g)x(),p.invalidateQueries({queryKey:["cliproxy-auth"]}),p.invalidateQueries({queryKey:["cliproxy-accounts"]}),p.invalidateQueries({queryKey:["account-quota"]}),it(p),B.success(t("toasts.providerAuthSuccess",{provider:y})),s(fe);else{const M=typeof d.error=="string"?d.error:t(j?"toasts.providerAccountRegistrationFailed":"toasts.providerCallbackFailed");throw new Error(M)}}catch(w){if(!v(C))return;const d=w instanceof Error?w.message:t("toasts.providerSubmitCallbackFailed");B.error(d),s(j=>({...j,isSubmittingCallback:!1,error:d}))}},[v,a.provider,p,x,t]);return c.useMemo(()=>({...a,startAuth:T,cancelAuth:k,submitCallback:D}),[a,T,k,D])}function pt({className:t,compact:a=!1,showAcknowledgement:s=!1,acknowledgementPhrase:n=$e,acknowledgementText:i="",onAcknowledgementTextChange:u,disabled:o=!1,showProxySettingsLink:l=!1}){const{t:r}=$(),h=r("accountSafetyWarning.title"),p=r("accountSafetyWarning.subtitle"),v=r("accountSafetyWarning.firstLine"),x=r("accountSafetyWarning.secondLine"),m="https://github.com/kaitranntt/ccs/issues/509",T=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(Je,{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:h}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:p})]}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:v}),e.jsx("p",{className:"text-xs font-medium leading-5 text-amber-900 dark:text-amber-200",children:x})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:justify-end",children:[e.jsxs("a",{href:m,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:[T,e.jsx(we,{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(Ft,{className:"h-3 w-3"}),k]}):null,e.jsx(z,{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(Je,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:h}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p})]})]}),e.jsx(z,{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:v}),e.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-200",children:x}),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:m,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:[T,e.jsx(we,{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(Ft,{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&&u&&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(le,{id:"account-risk-ack-text",value:i,onChange:D=>u(D.target.value),placeholder:n,disabled:o,className:"mt-2 font-mono text-xs"})]})]})]})}function Xa({className:t,value:a,onChange:s,disabled:n=!1}){const{t:i}=$(),u=[a.reviewedIssue509,a.understandsBanRisk,a.acceptsFullResponsibility,a.typedPhrase.trim().replace(/\s+/g," ").toUpperCase()===Ut].filter(Boolean).length,o=u/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(Je,{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(z,{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:u})})]}),e.jsx(Ps,{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(We,{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(We,{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(We,{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(is,{className:"h-3.5 w-3.5"}),"Step 4: Type exact phrase to continue"]}),e.jsx(le,{value:a.typedPhrase,onChange:r=>l({typedPhrase:r.target.value}),placeholder:Ut,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(we,{className:"h-3.5 w-3.5"})]})})]})]})}function Ya(t){return t.trim().replace(/\s+/g," ").toUpperCase()}function Za({open:t,onClose:a,provider:s,displayName:n,catalog:i,isFirstAccount:u=!1}){const[o,l]=c.useState(""),[r,h]=c.useState(""),[p,v]=c.useState(!1),[x,m]=c.useState(null),[T,k]=c.useState(""),[D,A]=c.useState(at),[C,y]=c.useState(!1),[w,d]=c.useState(!1),[j,I]=c.useState(It),[g,M]=c.useState(""),[N,G]=c.useState(""),[P,R]=c.useState(Tt),[E,V]=c.useState("oauth"),[O,H]=c.useState(""),[F,L]=c.useState(""),{t:b}=$(),J=c.useRef(!1),Z=c.useRef(0),ne=c.useRef(!1),U=Ja(),ae=Ms(),W=s==="kiro",ee=s==="gitlab",f=s==="agy"||s==="gemini",q=s==="gemini"&&!C,ce=s==="agy"&&!C,Te=f&&w,Ee=ba(D),Le=Ya(T)===$e,Ye=es(s),Re=Ds(j),he=W&&j==="idc",Ne=W&&Ts(j),Pe=W?Is(j,P):void 0,Ze=W?Ls(j):void 0,et=W?Pe==="device_code":Ye,ie=U.isAuthenticating||ae.isPending,Oe=o.trim(),_e=g.trim(),Fe=N.trim(),Ue=O.trim(),_=F.trim(),te=x||U.error,re=c.useCallback(async()=>{const S=await fetch("/api/settings/auth/antigravity-risk");if(!S.ok)throw new Error("Failed to load power user mode setting");return(await S.json()).antigravityAckBypass===!0},[]),ge=c.useCallback(async({pendingMessage:S=null,disabledMessage:pe=null}={})=>{const st=++Z.current;d(!0),S!==null&&m(S);try{const Ke=await re();return Z.current!==st||(y(Ke),pe?m(Ke?null:pe):S!==null&&m(null)),Ke}catch{return Z.current!==st||(y(!1),m(pe??b("addAccountDialog.powerUserLoadFailed")),ne.current||(ne.current=!0,B.error(b("addAccountDialog.powerUserLoadFailed")))),!1}finally{Z.current===st&&d(!1)}},[re,b]),tt=()=>{l(""),h(""),v(!1),m(null),k(""),A(at),y(!1),d(!1),I(It),M(""),G(""),R(Tt),V("oauth"),H(""),L(""),Z.current+=1,ne.current=!1,J.current=!1,a()};c.useEffect(()=>{t&&(k(""),A(at),m(null))},[s,t]),c.useEffect(()=>()=>{Z.current+=1},[]),c.useEffect(()=>{if(!t||!f){Z.current+=1,y(!1),d(!1);return}ge()},[t,s,f,ge]),c.useEffect(()=>{if(!t||s!=="agy"||!U.error||!C)return;const S=U.error.toLowerCase();(S.includes("agy_risk_ack_required")||S.includes("responsibility acknowledgement")||S.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&&J.current&&(J.current=!1,(async()=>{try{const pe=await mt(s,void 0,i);pe.success&&pe.presetName&&u&&B.success(`Applied "${pe.presetName}" preset`)}catch{}tt()})())},[U.isAuthenticating,U.error,U.provider]);const Mt=()=>{U.cancelAuth(),tt()},gs=async()=>{U.authUrl&&(await navigator.clipboard.writeText(U.authUrl),v(!0),setTimeout(()=>v(!1),2e3))},fs=()=>{r.trim()&&U.submitCallback(r.trim())},vs=()=>{if(Te){m(b("addAccountDialog.powerUserLoading"));return}if(ce&&!Ee){m("Complete all Antigravity responsibility steps before authenticating this provider.");return}if(q&&!Le){m(`Type "${$e}" to acknowledge the account safety warning before authenticating this provider.`);return}if(m(null),he&&!_e){m("IDC Start URL is required for Kiro IAM Identity Center login.");return}if(ee&&E==="pat"&&!_){m(b("addAccountDialog.gitlabPatRequired"));return}J.current=!0,U.startAuth(s,{nickname:Oe||void 0,kiroMethod:W?j:void 0,kiroIDCStartUrl:he?_e:void 0,kiroIDCRegion:he&&Fe?Fe:void 0,kiroIDCFlow:he?P:void 0,gitlabAuthMode:ee?E:void 0,gitlabBaseUrl:ee&&Ue?Ue:void 0,gitlabPersonalAccessToken:ee&&E==="pat"&&_?_:void 0,flowType:W?Pe:void 0,startEndpoint:W?Ze:ee&&E==="pat"?"start":void 0,riskAcknowledgement:ce?{version:Na,reviewedIssue509:D.reviewedIssue509,understandsBanRisk:D.understandsBanRisk,acceptsFullResponsibility:D.acceptsFullResponsibility,typedPhrase:D.typedPhrase}:void 0})},js=()=>{J.current=!0,ae.mutate(void 0,{onSuccess:async()=>{const S=await mt("kiro",void 0,i);S.success&&S.presetName&&u&&B.success(`Applied "${S.presetName}" preset`),tt()}})},bs=S=>{S||Mt()},oe=U.isAuthenticating;return e.jsx(gt,{open:t,onOpenChange:bs,children:e.jsxs(ft,{className:"sm:max-w-md",onInteractOutside:S=>{oe&&S.preventDefault()},children:[e.jsxs(vt,{children:[e.jsx(jt,{children:b("addAccountDialog.title",{displayName:n})}),e.jsx(Zt,{children:b(W?"addAccountDialog.descKiro":et?"addAccountDialog.descDeviceCode":"addAccountDialog.descOauth")})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[ce&&!oe&&e.jsx(Xa,{value:D,onChange:S=>{A(S),m(null)},disabled:ie}),f&&C&&!oe&&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(is,{className:"h-3.5 w-3.5"}),b("addAccountDialog.powerUserEnabled")]}),b("addAccountDialog.powerUserSkipped")]}),q&&!oe&&e.jsx(pt,{showAcknowledgement:!0,acknowledgementPhrase:$e,acknowledgementText:T,onAcknowledgementTextChange:S=>{k(S),m(null)},disabled:ie}),W&&!oe&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"kiro-auth-method",children:b("addAccountDialog.authMethod")}),e.jsxs(qe,{value:j,onValueChange:S=>{I(S),m(null)},children:[e.jsx(ze,{id:"kiro-auth-method",children:e.jsx(Ge,{placeholder:b("addAccountDialog.selectKiroAuthMethod")})}),e.jsx(Ve,{children:Es.map(S=>e.jsx(ye,{value:S.id,children:S.label},S.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&&!oe&&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(le,{id:"kiro-idc-start-url",value:g,onChange:S=>{M(S.target.value),m(null)},placeholder:"https://d-xxx.awsapps.com/start",disabled:ie}),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(le,{id:"kiro-idc-region",value:N,onChange:S=>{G(S.target.value),m(null)},placeholder:"us-east-1",disabled:ie}),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(qe,{value:P,onValueChange:S=>{R(S),m(null)},children:[e.jsx(ze,{id:"kiro-idc-flow",children:e.jsx(Ge,{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."})]})]}),ee&&!oe&&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(qe,{value:E,onValueChange:S=>{V(S),m(null)},children:[e.jsx(ze,{id:"gitlab-auth-mode",children:e.jsx(Ge,{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(le,{id:"gitlab-base-url",value:O,onChange:S=>{H(S.target.value),m(null)},placeholder:b("addAccountDialog.gitlabUrlPlaceholder"),disabled:ie}),e.jsx("p",{className:"text-xs text-muted-foreground",children:b("addAccountDialog.gitlabUrlHint")})]}),E==="pat"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"gitlab-pat",children:b("addAccountDialog.gitlabPat")}),e.jsx(le,{id:"gitlab-pat",type:"password",value:F,onChange:S=>{L(S.target.value),m(null)},placeholder:b("addAccountDialog.gitlabPatPlaceholder"),disabled:ie}),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."]})]})]}),!oe&&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(Me,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(le,{id:"nickname",value:o,onChange:S=>{l(S.target.value),m(null)},placeholder:b("addAccountDialog.nicknamePlaceholder"),disabled:ie,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:b("addAccountDialog.nicknameOptionalHint")})]}),oe&&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(de,{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:gs,children:p?e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"w-3 h-3 mr-1"}),b("addAccountDialog.copied")]}):e.jsxs(e.Fragment,{children:[e.jsx(ns,{className:"w-3 h-3 mr-1"}),b("addAccountDialog.copy")]})}),e.jsxs(K,{variant:"outline",size:"sm",onClick:()=>{if(!U.authUrl)return;const S=window.open(U.authUrl,"_blank");(!S||S.closed||typeof S.closed>"u")&&B.warning(b("addAccountDialog.popupBlocked"),{duration:5e3})},children:[e.jsx(we,{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(le,{id:"callback-url",value:r,onChange:S=>h(S.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:fs,disabled:!r.trim()||U.isSubmittingCallback,children:U.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(de,{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")})]}),te&&e.jsx("p",{className:"text-xs text-center text-destructive",children:te}),ae.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(de,{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:Mt,children:b("addAccountDialog.cancel")}),W&&!oe&&e.jsx(K,{variant:"outline",onClick:js,disabled:ie,children:ae.isPending?e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"w-4 h-4 mr-2 animate-spin"}),b("addAccountDialog.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(pa,{className:"w-4 h-4 mr-2"}),b("addAccountDialog.importFromIde")]})}),!oe&&e.jsxs(K,{onClick:vs,disabled:ie||Te||ce&&!Ee||q&&!Le,children:[e.jsx(we,{className:"w-4 h-4 mr-2"}),b("addAccountDialog.authenticate")]})]})]})]})})}const en=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function tn(t){const a=t?.env||{};return en.filter(s=>!a[s]?.trim())}function sn(t,a){const[s,n]=c.useState(null),[i,u]=c.useState(!1),o=xt(),{data:l,isLoading:r,refetch:h}=Vt({queryKey:["settings",t],queryFn:async()=>{const P=await fetch(`/api/settings/${t}/raw`);if(!P.ok){const R=t==="cursor"?`~/.ccs/cliproxy/providers/${t}.settings.json`:Qe(t)?`~/.ccs/${t}.settings.json`:`~/.ccs/profiles/${t}/settings.json`;return{profile:t,settings:{env:{}},mtime:Date.now(),path:R}}return P.json()}}),p=l?.settings,v=c.useMemo(()=>s!==null?s:p?JSON.stringify(p,null,2):`{
2
- "env": {}
3
- }`,[s,p]),x=c.useCallback(P=>{n(P)},[]),m=c.useMemo(()=>{try{return JSON.parse(v)}catch{return p||{env:{}}}},[v,p]),T=m?.env?.ANTHROPIC_MODEL,k=m?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,D=m?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,A=m?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,C=c.useMemo(()=>Rs(m?.env||{}),[m]),y=c.useCallback((P,R)=>Os(P,R,{supportsExtendedContext:E=>_a(t,E,a)}),[a,t]),w=c.useCallback((P,R)=>{const E={...m?.env||{},[P]:R},V=Et(P)?y(E,C):E;delete V.CCS_EXTENDED_CONTEXT;const O={...m,env:V};n(JSON.stringify(O,null,2))},[y,m,C]),d=c.useCallback(P=>{const R=m?.env||{},E=y(R,P);delete E.CCS_EXTENDED_CONTEXT;const V={...m,env:E};n(JSON.stringify(V,null,2))},[y,m]),j=c.useCallback(P=>{const R={...m?.env||{},...P},V=Object.keys(P).some(Et)?y(R,C):R;delete V.CCS_EXTENDED_CONTEXT;const O={...m,env:V};n(JSON.stringify(O,null,2))},[y,m,C]),I=c.useMemo(()=>{try{return JSON.parse(v),!0}catch{return!1}},[v]),g=c.useMemo(()=>s===null?!1:s!==JSON.stringify(p,null,2),[s,p]),M=c.useMemo(()=>tn(m),[m]),N=Ns({mutationFn:async()=>{const P=JSON.parse(v),R=await fetch(`/api/settings/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:P,expectedMtime:l?.mtime})});if(R.status===409)throw new Error("CONFLICT");if(!R.ok)throw new Error("Failed to save");return R.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"?u(!0):B.error(P.message)}}),G=async P=>{u(!1),P?(await h(),N.mutate()):n(null)};return{data:l,isLoading:r,refetch:h,rawJsonContent:v,rawJsonEdits:s,isRawJsonValid:I,hasChanges:g,currentSettings:m,currentModel:T,opusModel:k,sonnetModel:D,haikuModel:A,extendedContextEnabled:C,toggleExtendedContext:d,handleRawJsonChange:x,updateEnvValue:w,updateEnvValues:j,saveMutation:{mutate:()=>N.mutate(),isPending:N.isPending},conflictDialog:i,setConflictDialog:u,handleConflictResolve:G,missingRequiredFields:M}}const an=/-(medium|high|xhigh)$/i;function nn(t){if(!t)return;const a=t.trim().match(an);if(a?.[1])return a[1].toLowerCase()}function rn(t,a){if(!t)return null;const s=nn(t);return s?{label:`Pinned ${s}`,explicit:!0}:{label:"Auto effort",explicit:!1}}function on({label:t}){return e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:t})}function He({modelId:t}){const a=rn(t);return a?e.jsx(z,{variant:a.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:a.label}):null}function qt(t,a){if(!t)return"";if(!a?.prefix)return t;const s=`${a.prefix}/`;return t.startsWith(s)?t.slice(s.length):t}function ve(t,a){return a?.recommendedModelId??t}function be({label:t,description:a,value:s,onChange:n,catalog:i,allModels:u,routing:o,disabled:l}){const{t:r}=$(),h=i?.provider==="codex",p=c.useMemo(()=>Pt(i,u),[u,i]),v=c.useMemo(()=>Oa(i?.provider??"",i,u),[u,i]),x=new Set(p.map(d=>d.id)),m=c.useMemo(()=>new Map((o?.models??[]).map(d=>[d.modelId.toLowerCase(),d])),[o]),T=c.useMemo(()=>new Set(p.map(d=>ve(d.id,m.get(d.id.toLowerCase())))),[p,m]),k=c.useMemo(()=>m.get(qt(s,o).toLowerCase()),[o,m,s]),D=p.map(d=>({value:ve(d.id,m.get(d.id.toLowerCase())),groupKey:"recommended",searchText:`${d.id} ${d.name} ${m.get(d.id.toLowerCase())?.recommendedModelId??""}`,keywords:[d.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:ve(d.id,m.get(d.id.toLowerCase()))}),m.get(d.id.toLowerCase())?.pinnedAvailable?e.jsx(z,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:m.get(d.id.toLowerCase())?.prefix}):null,h&&e.jsx(He,{modelId:d.id})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:ve(d.id,m.get(d.id.toLowerCase()))}),d.tier==="paid"&&e.jsx(on,{label:r("providerModelSelector.paid")}),m.get(d.id.toLowerCase())?.unprefixedStatus==="shadowed"?e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.shadowed")}):null,m.get(d.id.toLowerCase())?.unprefixedStatus==="prefix-only"?e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.prefixOnly")}):null,h&&e.jsx(He,{modelId:d.id})]})})),A=v.filter(d=>!x.has(d.id)).filter(d=>!T.has(ve(d.id,m.get(d.id.toLowerCase())))).map(d=>({value:ve(d.id,m.get(d.id.toLowerCase())),groupKey:"all",searchText:`${d.id} ${m.get(d.id.toLowerCase())?.recommendedModelId??""}`,keywords:[d.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:ve(d.id,m.get(d.id.toLowerCase()))}),m.get(d.id.toLowerCase())?.pinnedAvailable?e.jsx(z,{variant:"secondary",className:"text-[9px] h-4 px-1 uppercase",children:m.get(d.id.toLowerCase())?.prefix}):null,h&&e.jsx(He,{modelId:d.id})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:ve(d.id,m.get(d.id.toLowerCase()))}),m.get(d.id.toLowerCase())?.unprefixedStatus==="shadowed"?e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.shadowed")}):null,m.get(d.id.toLowerCase())?.unprefixedStatus==="prefix-only"?e.jsx(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.prefixOnly")}):null,h&&e.jsx(He,{modelId:d.id})]})})),C=!!s&&!D.some(d=>d.value===s)&&!A.some(d=>d.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(z,{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(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:r("providerModelSelector.current")})]})}:null,w=D.length+A.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(wa,{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")})},...A.length>0?[{key:"all",label:e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providerModelSelector.allModelsCount",{count:A.length})})}]:[]],options:[...C&&y?[y]:[],...D,...A]}),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&&qt(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 zt(t,a){const s=n=>a?.models.find(u=>u.modelId.toLowerCase()===n.toLowerCase())?.recommendedModelId??n;return{default:s(t.default),opus:s(t.opus),sonnet:s(t.sonnet),haiku:s(t.haiku)}}function ln({open:t,onClose:a,currentValues:s,onApply:n,onSave:i,isSaving:u,catalog:o,allModels:l,routing:r}){const{t:h}=$(),[p,v]=c.useState(zt(s,r)),[x,m]=c.useState(""),T=k=>{k?(v(zt(s,r)),m("")):a()};return e.jsx(gt,{open:t,onOpenChange:T,children:e.jsxs(ft,{className:"sm:max-w-md",children:[e.jsx(vt,{children:e.jsxs(jt,{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4"}),h("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:h("customPresetDialog.presetNameOptional")}),e.jsx(le,{id:"preset-name",value:x,onChange:k=>m(k.target.value),placeholder:h("customPresetDialog.presetNamePlaceholder"),className:"text-sm"})]}),e.jsx(At,{}),o?.provider==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground rounded-md border bg-muted/30 px-2.5 py-2",children:[h("customPresetDialog.codexTipPrefix")," ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and"," ",e.jsx("code",{children:"-xhigh"})," ",h("customPresetDialog.codexTipSuffix")]}),e.jsx(be,{label:h("customPresetDialog.defaultModel"),description:h("customPresetDialog.defaultModelDesc"),value:p.default,onChange:k=>v({...p,default:k}),catalog:o,allModels:l,routing:r}),e.jsx(be,{label:h("customPresetDialog.opusModel"),description:h("customPresetDialog.opusModelDesc"),value:p.opus,onChange:k=>v({...p,opus:k}),catalog:o,allModels:l,routing:r}),e.jsx(be,{label:h("customPresetDialog.sonnetModel"),description:h("customPresetDialog.sonnetModelDesc"),value:p.sonnet,onChange:k=>v({...p,sonnet:k}),catalog:o,allModels:l,routing:r}),e.jsx(be,{label:h("customPresetDialog.haikuModel"),description:h("customPresetDialog.haikuModelDesc"),value:p.haiku,onChange:k=>v({...p,haiku:k}),catalog:o,allModels:l,routing:r})]}),e.jsxs(_s,{className:"gap-2 sm:gap-0",children:[e.jsx(K,{variant:"outline",onClick:a,children:h("customPresetDialog.cancel")}),i&&e.jsxs(K,{variant:"secondary",onClick:()=>i(p,x||void 0),disabled:u||!x.trim(),children:[u?e.jsx(de,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(kt,{className:"w-4 h-4 mr-1"}),h("customPresetDialog.savePreset")]}),e.jsxs(K,{onClick:()=>n(p,x||void 0),children:[e.jsx(Ie,{className:"w-4 h-4 mr-1"}),h("customPresetDialog.applyPreset")]})]})]})})}function je({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(ts,{value:a,size:"icon",className:"h-6 w-6"})]})]})}function dn({provider:t,displayName:a,defaultTarget:s,data:n,authStatus:i,supportsModelConfig:u=!1}){const{t:o}=$(),l=s||"claude",r=l==="droid",h=t==="codex",p=l==="claude"?`ccs ${t}`:`ccs ${t} --target claude`,v=`${p} --config`,x=`${p} --auth --add`,m=`${p} --accounts`;return e.jsx(bt,{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(rs,{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:o("providerEditor.provider")}),e.jsx("span",{className:"font-mono",children:a})]}),n&&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:o("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:n.path}),e.jsx(ts,{value:n.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:o("providerEditor.lastModified")}),e.jsx("span",{className:"text-xs",children:new Date(n.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:o("providerEditor.status")}),i.authenticated?e.jsxs(z,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(xa,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(z,{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:o("providerEditor.defaultTarget")}),e.jsx("span",{className:"font-mono",children:l})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:o("providerEditor.quickUsage")}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(je,{label:"Run with prompt",command:`ccs ${t} "your prompt"`}),h&&e.jsxs(e.Fragment,{children:[e.jsx(je,{label:"Run on native Codex (shortcut)",command:'ccsxp "your prompt"'}),e.jsx(je,{label:"Run on native Codex (--target)",command:`ccs ${t} --target codex "your prompt"`})]}),e.jsx(je,{label:r?"Droid alias (explicit)":"Run on Droid",command:`ccs-droid ${t} "your prompt"`}),e.jsx(je,{label:r?"Override to Claude":"Run on Droid (--target)",command:`ccs ${t} --target ${r?"claude":"droid"} "your prompt"`}),u&&e.jsx(je,{label:l==="claude"?"Change model":"Change model (Claude target)",command:v}),e.jsx(je,{label:l==="claude"?"Add account":"Add account (Claude target)",command:x}),e.jsx(je,{label:l==="claude"?"List accounts":"List accounts (Claude target)",command:m}),l!=="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 cn(t){const a=t.replace(/\\/g,"/"),n=a.lastIndexOf("/cliproxy/providers/");return n!==-1?a.slice(n+1):a.replace(/^.*\//,"")}function un({displayName:t,logoProvider:a,provider:s,data:n,isLoading:i,hasChanges:u,isRawJsonValid:o,isSaving:l,isRemoteMode:r,port:h,onRefetch:p,onSave:v}){const{t:x}=$();return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Nt,{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(z,{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(os,{className:"w-3 h-3"}),"Remote"]}),h&&e.jsxs(z,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(ha,{className:"w-3 h-3"}),":",h]}),!r&&n?.path&&e.jsx(z,{variant:"outline",className:"text-xs",children:cn(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:[x("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(wt,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsx(K,{size:"sm",onClick:v,disabled:l||!u||!o,children:l?e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ga,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function mn({models:t,provider:a,enabled:s,onToggle:n,disabled:i,className:u}){const{t:o}=$();if(t.length===0)return null;const l=t.some(p=>Lt(p.id)),r=t.some(p=>!Lt(p.id));let h="Compatible mappings stay on standard context unless you turn this on.";return l&&r?h="Gemini-compatible mappings can use 1M automatically. Claude mappings stay plain unless you turn this on.":l&&(h="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",u),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(z,{variant:s?"default":"secondary",className:"text-[10px] h-5 px-1.5",children:"1M tokens"})]}),e.jsx(ss,{checked:s,onCheckedChange:n,disabled:i})]}),e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(rs,{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:h}),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 pn(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 xn({catalog:t,savedPresets:a,currentModel:s,opusModel:n,sonnetModel:i,haikuModel:u,providerModels:o,routing:l,provider:r,extendedContextEnabled:h,onExtendedContextToggle:p,onApplyPreset:v,onUpdateEnvValue:x,onOpenCustomPreset:m,onDeletePreset:T,isDeletePending:k}){const{t:D}=$(),A=(l?.models??[]).some(g=>g.pinnedAvailable),C=c.useMemo(()=>new Map((l?.models??[]).map(g=>[g.modelId.toLowerCase(),g])),[l]),y=g=>C.get(g.toLowerCase())?.recommendedModelId??g,w=c.useMemo(()=>{if(!t)return[];const g=[s,n,i,u].filter(N=>!!N).map(N=>Fs(N));return[...new Set(g)].map(N=>hs(t.provider,N,t)).filter(N=>!!N?.extendedContext)},[t,s,n,i,u]),d=c.useMemo(()=>Pt(t,o),[t,o]),j=c.useMemo(()=>{const g=d.filter(N=>N.presetMapping);return g.length===0?[]:g.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:g.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:g.filter(N=>N.tier==="paid")}].filter(N=>N.models.length>0):[{key:"default",models:g.slice(0,4)}]},[d]),I=j.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:[j.map(g=>e.jsxs("div",{children:["label"in g&&g.label&&e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(z,{variant:"outline",className:g.badgeClassName,children:g.label}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:g.description})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:g.models.map(M=>e.jsxs(K,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>v(pn(M,y)),children:[e.jsx(Ie,{className:`w-3 h-3 ${"iconClassName"in g?g.iconClassName:""}`}),M.name]},M.id))})]},g.key)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.map(g=>e.jsxs("div",{className:"group relative",children:[e.jsxs(K,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{v({ANTHROPIC_MODEL:y(g.default),ANTHROPIC_DEFAULT_OPUS_MODEL:y(g.opus),ANTHROPIC_DEFAULT_SONNET_MODEL:y(g.sonnet),ANTHROPIC_DEFAULT_HAIKU_MODEL:y(g.haiku)})},children:[e.jsx(kt,{className:"w-3 h-3 fill-current"}),g.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:M=>{M.stopPropagation(),T(g.name)},disabled:k,children:e.jsx(Ct,{className:"w-3 h-3"})})]},g.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:m,children:[e.jsx(ls,{className:"w-3 h-3"}),"Custom"]})]})]})]}),e.jsx(At,{}),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:A?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. Unsuffixed models use Thinking settings."]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(be,{label:"Default Model",description:"Used when no specific tier is requested",value:s,onChange:g=>x("ANTHROPIC_MODEL",g),catalog:t,allModels:o,routing:l}),w.length>0&&p&&e.jsx(mn,{models:w,provider:r,enabled:h??!1,onToggle:p}),e.jsx(be,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:n,onChange:g=>x("ANTHROPIC_DEFAULT_OPUS_MODEL",g),catalog:t,allModels:o,routing:l}),e.jsx(be,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:i,onChange:g=>x("ANTHROPIC_DEFAULT_SONNET_MODEL",g),catalog:t,allModels:o,routing:l}),e.jsx(be,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:u,onChange:g=>x("ANTHROPIC_DEFAULT_HAIKU_MODEL",g),catalog:t,allModels:o,routing:l})]})]})]})}function hn(t,a,s){return t?e.jsx(ot,{children:e.jsxs(lt,{children:[e.jsx(dt,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(va,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:X("font-mono max-w-[180px] truncate",a&&ht),title:t,children:t})]})}),e.jsx(ct,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:s("providerEditor.gcpProjectIdReadonly")})})]})}):e.jsx(ot,{children:e.jsxs(lt,{children:[e.jsx(dt,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(Je,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:s("providerEditor.projectIdNA")})]})}),e.jsx(ct,{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 gn({account:t,onSetDefault:a,onRemove:s,onPauseToggle:n,isRemoving:i,isPausingAccount:u,privacyMode:o,showQuota:l,selectable:r,selected:h,onSelectChange:p}){const{t:v}=$(),x=t.provider.toLowerCase(),{data:m}=Us(l),{data:T,isLoading:k}=Ks(x,t.id,l),D=Hs(m,t)?.lastUsedAt,A=r||n?e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r&&e.jsx("button",{type:"button",onClick:()=>p?.(!h),className:X("flex items-center justify-center w-5 h-5 rounded border-2 transition-colors shrink-0",h?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/30 hover:border-primary/50"),"aria-label":h?"Deselect account":"Select account",children:h&&e.jsx(ke,{className:"w-3 h-3"})}),n&&e.jsx(ot,{children:e.jsxs(lt,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(K,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>n(!t.paused),disabled:u,children:u?e.jsx(de,{className:"w-4 h-4 animate-spin"}):t.paused?e.jsx(ds,{className:"w-4 h-4 text-emerald-500"}):e.jsx(cs,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(ct,{side:"top",children:t.paused?"Resume account":"Pause account"})]})})]}):void 0,C=e.jsxs(qs,{children:[e.jsx(zs,{asChild:!0,children:e.jsx(K,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(fa,{className:"w-4 h-4"})})}),e.jsxs(Gs,{align:"end",children:[!t.isDefault&&e.jsxs(Rt,{onClick:a,children:[e.jsx(kt,{className:"w-4 h-4 mr-2"}),"Set as default"]}),e.jsxs(Rt,{className:"text-destructive focus:text-destructive",onClick:s,disabled:i,children:[e.jsx(us,{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",h&&"ring-2 ring-primary/50 bg-primary/5"),children:e.jsx(Vs,{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:T,quotaLoading:k,runtimeLastUsed:D,beforeIdentity:A,headerEnd:C,bodySlot:t.provider==="agy"?hn(t.projectId,o,v):null,quotaInsetClassName:"pl-11"})})}function fn({selectedCount:t,onPauseSelected:a,onResumeSelected:s,onClearSelection:n,isPausing:i,isResuming:u}){if(t<1)return null;const o=i||u;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(de,{className:"w-3 h-3 animate-spin"}):e.jsx(cs,{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:[u?e.jsx(de,{className:"w-3 h-3 animate-spin"}):e.jsx(ds,{className:"w-3 h-3"}),"Resume Selected"]})]})]})}function vn({accounts:t,onAddAccount:a,onSetDefault:s,onRemoveAccount:n,onPauseToggle:i,onSoloMode:u,onBulkPause:o,onBulkResume:l,isRemovingAccount:r,isPausingAccount:h,isSoloingAccount:p,isBulkPausing:v,isBulkResuming:x,privacyMode:m,showQuota:T,isKiro:k,kiroNoIncognito:D,onKiroNoIncognitoChange:A,kiroSettingsLoading:C}){const{t:y}=$(),[w,d]=c.useState(new Set),j=c.useMemo(()=>new Set(t.map(F=>F.id)),[t]),I=c.useMemo(()=>new Set([...w].filter(F=>j.has(F))),[w,j]),g=!!(o&&l),M=I.size,N=t.length>0&&I.size===t.length,G=I.size>0&&I.size<t.length,P=c.useCallback(F=>{d(L=>{const b=new Set(L);return b.has(F)?b.delete(F):b.add(F),b})},[]),R=c.useCallback(()=>{d(new Set(t.map(F=>F.id)))},[t]),E=c.useCallback(()=>{d(new Set)},[]),V=c.useCallback(()=>{N?E():R()},[N,R,E]),O=c.useCallback(()=>{o&&I.size>0&&(o(Array.from(I)),d(new Set))},[o,I]),H=c.useCallback(()=>{l&&I.size>0&&(l(Array.from(I)),d(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:[g&&t.length>0&&e.jsx(We,{checked:N,onCheckedChange:V,"aria-label":"Select all accounts",className:G?"data-[state=checked]:bg-primary/50":"",...G?{"data-state":"indeterminate"}:{}}),e.jsx(Me,{className:"w-4 h-4"}),"Accounts",t.length>0&&e.jsx(z,{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(ls,{className:"w-3 h-3"}),"Add"]})]}),g&&M>0&&e.jsx(fn,{selectedCount:M,onPauseSelected:O,onResumeSelected:H,onClearSelection:E,isPausing:!!v,isResuming:!!x}),t.length>0?e.jsx("div",{className:"space-y-2",children:t.map(F=>e.jsx(gn,{account:F,onSetDefault:()=>s(F.id),onRemove:()=>n(F.id),onPauseToggle:i?L=>i(F.id,L):void 0,onSoloMode:u?()=>u(F.id):void 0,isRemoving:r,isPausingAccount:h,isSoloingAccount:p,privacyMode:m,showQuota:T,selectable:g,selected:I.has(F.id),onSelectChange:()=>P(F.id)},F.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(Me,{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&&A&&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(os,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:y("providerEditor.useIncognito")})]}),e.jsx(ss,{checked:!D,onCheckedChange:F=>A(!F),disabled:C,className:"scale-90"})]})})]})}function jn({provider:t,catalog:a,savedPresets:s,currentModel:n,opusModel:i,sonnetModel:u,haikuModel:o,providerModels:l,routing:r,extendedContextEnabled:h,onExtendedContextToggle:p,onApplyPreset:v,onUpdateEnvValue:x,onOpenCustomPreset:m,onDeletePreset:T,isDeletePending:k,accounts:D,onAddAccount:A,onSetDefault:C,onRemoveAccount:y,onPauseToggle:w,onSoloMode:d,onBulkPause:j,onBulkResume:I,isRemovingAccount:g,isPausingAccount:M,isSoloingAccount:N,isBulkPausing:G,isBulkResuming:P,privacyMode:R,isRemoteMode:E}){const V=t.toLowerCase(),O=(Bs.includes(V)||["anthropic","antigravity","gemini-cli","copilot","github-copilot"].includes(V))&&!E,H=t==="kiro",[F,L]=c.useState(!0),[b,J]=c.useState(!0),[Z,ne]=c.useState(!1),U=c.useCallback(async()=>{if(H)try{J(!0);const ee=(await Be.config.get()).cliproxy;L(ee?.kiro_no_incognito??!0)}catch{L(!0)}finally{J(!1)}},[H]),ae=c.useCallback(async W=>{L(W),ne(!0);try{const ee=await Be.config.get(),f=ee.cliproxy??{};await Be.config.update({...ee,cliproxy:{...f,kiro_no_incognito:W}})}catch{L(!W)}finally{ne(!1)}},[]);return c.useEffect(()=>{U()},[U]),e.jsx(bt,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(xn,{catalog:a,savedPresets:s,currentModel:n,opusModel:i,sonnetModel:u,haikuModel:o,providerModels:l,routing:r,provider:t,extendedContextEnabled:h,onExtendedContextToggle:p,onApplyPreset:v,onUpdateEnvValue:x,onOpenCustomPreset:m,onDeletePreset:T,isDeletePending:k}),e.jsx(At,{}),e.jsx(vn,{accounts:D,onAddAccount:A,onSetDefault:C,onRemoveAccount:y,onPauseToggle:w,onSoloMode:d,onBulkPause:j,onBulkResume:I,isRemovingAccount:g,isPausingAccount:M,isSoloingAccount:N,isBulkPausing:G,isBulkResuming:P,privacyMode:R,showQuota:O,isKiro:H,kiroNoIncognito:F,onKiroNoIncognitoChange:ae,kiroSettingsLoading:b||Z})]})})}function Gt({provider:t,displayName:a,authStatus:s,catalog:n,routing:i,logoProvider:u,baseProvider:o,isRemoteMode:l,port:r,defaultTarget:h,topNotice:p,onAddAccount:v,onSetDefault:x,onRemoveAccount:m,onPauseToggle:T,onSoloMode:k,onBulkPause:D,onBulkResume:A,isRemovingAccount:C,isPausingAccount:y,isSoloingAccount:w,isBulkPausing:d,isBulkResuming:j}){const[I,g]=c.useState(!1),{privacyMode:M}=Yt(),{t:N}=$(),{data:G}=$s(),{data:P}=Ws(t),R=Qs(),E=Js(),V=o||t,O=V.toLowerCase()==="agy",H=c.useMemo(()=>{const _=P?.presets||[];return O?_.filter(te=>!ue(te.default)&&!ue(te.opus)&&!ue(te.sonnet)&&!ue(te.haiku)):_},[O,P?.presets]),F=c.useMemo(()=>{if(!G?.models)return[];const te={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"]}[V.toLowerCase()]||[V.toLowerCase()];return G.models.filter(re=>te.some(ge=>re.owned_by.toLowerCase().includes(ge))?O?!ue(re.id):!0:!1)},[O,G,V]),L=(o||t).toLowerCase(),{data:b,isLoading:J,refetch:Z,rawJsonContent:ne,rawJsonEdits:U,isRawJsonValid:ae,hasChanges:W,currentModel:ee,opusModel:f,sonnetModel:q,haikuModel:ce,extendedContextEnabled:Te,toggleExtendedContext:Ee,handleRawJsonChange:Le,updateEnvValue:Ye,updateEnvValues:Re,saveMutation:he,conflictDialog:Ne,handleConflictResolve:Pe,missingRequiredFields:Ze}=sn(t,n),et=c.useMemo(()=>(s.accounts||[]).map(_=>({..._,provider:_.provider||o||t})),[s.accounts,o,t]),{data:ie}=Vt({queryKey:["auth-tokens-raw"],queryFn:async()=>{const _=await fetch("/api/settings/auth/tokens/raw");return _.ok?_.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),Oe=ie?.apiKey?.value??"ccs-internal-managed",_e=_=>{if(O&&[_.ANTHROPIC_MODEL,_.ANTHROPIC_DEFAULT_OPUS_MODEL,_.ANTHROPIC_DEFAULT_SONNET_MODEL,_.ANTHROPIC_DEFAULT_HAIKU_MODEL].some(re=>typeof re=="string"&&ue(re))){B.error(N("providerEditor.agyDenylist"));return}Re({ANTHROPIC_BASE_URL:`http://127.0.0.1:${r??ut}/api/provider/${L}`,ANTHROPIC_AUTH_TOKEN:Oe,..._}),B.success(`Applied "${_.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},Fe=(_,te)=>{if(O&&[_.default,_.opus,_.sonnet,_.haiku].some(ge=>ue(ge))){B.error(N("providerEditor.agyDenylist"));return}Re({ANTHROPIC_BASE_URL:`http://127.0.0.1:${r??ut}/api/provider/${L}`,ANTHROPIC_AUTH_TOKEN:Oe,ANTHROPIC_MODEL:_.default,ANTHROPIC_DEFAULT_OPUS_MODEL:_.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:_.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:_.haiku}),B.success(`Applied ${te?`"${te}"`:"custom"} preset`),g(!1)},Ue=(_,te)=>{if(!te){B.error(me.t("commonToast.enterPresetName"));return}if(O&&[_.default,_.opus,_.sonnet,_.haiku].some(re=>ue(re))){B.error(N("providerEditor.agyDenylist"));return}R.mutate({profile:t,data:{name:te,..._}}),g(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(un,{provider:t,displayName:a,logoProvider:u,data:b,isLoading:J,hasChanges:W,isRawJsonValid:ae,isSaving:he.isPending,isRemoteMode:l,port:r,onRefetch:Z,onSave:()=>he.mutate()}),p?e.jsx("div",{className:"border-b bg-muted/10 px-4 py-3",children:p}):null,J?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(de,{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(Xs,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Ys,{className:"w-full",children:[e.jsx(Ot,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(Ot,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(_t,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(jn,{provider:t,catalog:n,savedPresets:H,currentModel:ee,opusModel:f,sonnetModel:q,haikuModel:ce,providerModels:F,routing:i,extendedContextEnabled:Te,onExtendedContextToggle:Ee,onApplyPreset:_e,onUpdateEnvValue:Ye,onOpenCustomPreset:()=>g(!0),onDeletePreset:_=>E.mutate({profile:t,name:_}),isDeletePending:E.isPending,accounts:et,onAddAccount:v,onSetDefault:x,onRemoveAccount:m,onPauseToggle:T,onSoloMode:k,onBulkPause:D,onBulkResume:A,isRemovingAccount:C,isPausingAccount:y,isSoloingAccount:w,isBulkPausing:d,isBulkResuming:j,privacyMode:M,isRemoteMode:l})}),e.jsx(_t,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(dn,{provider:t,displayName:a,defaultTarget:h,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(ja,{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(Zs,{rawJsonContent:ne,isRawJsonValid:ae,rawJsonEdits:U,onRawJsonChange:Le,profileEnv:b?.settings?.env,missingRequiredFields:Ze})]})]}),e.jsx(ya,{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:()=>Pe(!0),onCancel:()=>Pe(!1)}),e.jsx(ln,{open:I,onClose:()=>g(!1),currentValues:{default:ee||"",opus:f||"",sonnet:q||"",haiku:ce||""},onApply:Fe,onSave:Ue,isSaving:R.isPending,catalog:n,allModels:F,routing:i})]})}function bn({status:t,isSelected:a,onSelect:s}){const{t:n}=$(),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(Nt,{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(z,{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(ke,{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(Ct,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n("cliproxyPage.notConnected")})]})})]})]})}function Nn({variant:t,parentAuth:a,isSelected:s,onSelect:n,onDelete:i,isDeleting:u}){const{t:o}=$(),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(Nt,{provider:t.provider,size:"sm"}),e.jsx(ms,{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(z,{variant:"outline",className:"text-[9px] h-4 px-1",children:o("cliproxyPage.variant")}),e.jsx(z,{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(ke,{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(Ct,{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:u,children:e.jsx(us,{className:"w-3 h-3"})})]})}function yn({onSetup:t}){const{t:a}=$();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 Kn(){const{t}=$(),a=xt(),{data:s,isLoading:n}=Jt(),{data:i,isFetching:u}=ea(),{data:o}=Xt(),{data:l}=ta(),r=sa(),h=aa(),p=na(),v=ia(),x=ra(),m=oa(),T=la(),k=da(),[D,A]=c.useState(()=>{if(typeof window<"u"){const q=new URLSearchParams(window.location.search).get("provider")?.trim().toLowerCase();return q&&Qe(q)?q:localStorage.getItem("cliproxy-selected-provider")}return null}),[C,y]=c.useState(null),[w,d]=c.useState(!1),[j,I]=c.useState(()=>{if(typeof window>"u")return null;const f=new URLSearchParams(window.location.search),q=f.get("provider")?.trim().toLowerCase();return f.get("action")!=="auth"||!q||!Qe(q)?null:{provider:q,displayName:ca(q),isFirstAccount:!1}}),g=c.useMemo(()=>s?.authStatus||[],[s?.authStatus]),M=s?.source==="remote",N=c.useMemo(()=>i?.variants||[],[i?.variants]),G=c.useMemo(()=>St(o?.catalogs),[o?.catalogs]),P=o?.routing??{},R=!!o,E=f=>{A(f),f&&localStorage.setItem("cliproxy-selected-provider",f)},V=c.useMemo(()=>C?null:D&&g.some(f=>f.provider===D)?D:g.length>0&&(g.find(q=>(q.accounts?.length||0)>0)?.provider||g[0]?.provider)||null,[D,C,g]),O=g.find(f=>f.provider===V),H=N.find(f=>f.name===C),F=H?g.find(f=>f.provider===H.provider):void 0,L=(H?.provider||O?.provider||"").toLowerCase().trim(),b=L==="gemini"||L==="agy",J=()=>{a.invalidateQueries({queryKey:["cliproxy"]}),a.invalidateQueries({queryKey:["cliproxy-auth"]}),a.invalidateQueries({queryKey:["cliproxy-catalog"]}),a.invalidateQueries({queryKey:["cliproxy-models"]})},Z=(f,q,ce)=>{p.isPending||v.isPending||(ce?p.mutate({provider:f,accountId:q}):v.mutate({provider:f,accountId:q}))},ne=(f,q)=>{x.isPending||x.mutate({provider:f,accountId:q})},U=(f,q)=>{m.isPending||m.mutate({provider:f,accountIds:q})},ae=(f,q)=>{T.isPending||T.mutate({provider:f,accountIds:q})},W=f=>{E(f),y(null)},ee=f=>{y(f),E(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:J,disabled:u,children:e.jsx(wt,{className:X("w-4 h-4",u&&"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:()=>d(!0),children:[e.jsx(De,{className:"w-4 h-4"}),t("cliproxyPage.quickSetup")]})]}),e.jsx(bt,{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(f=>e.jsx(ua,{className:"h-14 w-full rounded-lg"},f))}):e.jsx("div",{className:"space-y-1",children:g.map(f=>e.jsx(bn,{status:f,isSelected:V===f.provider,onSelect:()=>W(f.provider)},f.provider))}),N.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(ms,{className:"w-3 h-3"}),t("cliproxyPage.variants")]}),e.jsx("div",{className:"space-y-1",children:N.map(f=>e.jsx(Nn,{variant:f,parentAuth:g.find(q=>q.provider===f.provider),isSelected:C===f.name,onSelect:()=>ee(f.name),onDelete:()=>k.mutate(f.name),isDeleting:k.isPending},f.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(ka,{})}),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:g.length})}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ke,{className:"w-3 h-3 text-green-600"}),t("cliproxyPage.connectedCount",{count:g.filter(f=>f.authenticated).length})]})]})})]}),e.jsx("div",{className:"flex-1 flex min-w-0 flex-col overflow-hidden bg-background",children:H&&F?e.jsx(e.Fragment,{children:e.jsx(Gt,{provider:H.name,displayName:t("cliproxyPage.variantDisplay",{name:H.name,provider:H.provider}),authStatus:F,catalog:G[H.provider],routing:P[H.provider],logoProvider:H.provider,baseProvider:H.provider,defaultTarget:H.target,isRemoteMode:M,port:H.port,topNotice:b?e.jsx(pt,{compact:!0,showProxySettingsLink:!0}):void 0,onAddAccount:()=>I({provider:H.provider,displayName:F.displayName,isFirstAccount:(F.accounts?.length||0)===0}),onSetDefault:f=>r.mutate({provider:H.provider,accountId:f}),onRemoveAccount:f=>h.mutate({provider:H.provider,accountId:f}),onPauseToggle:(f,q)=>Z(H.provider,f,q),onSoloMode:f=>ne(H.provider,f),onBulkPause:f=>U(H.provider,f),onBulkResume:f=>ae(H.provider,f),isRemovingAccount:h.isPending,isPausingAccount:p.isPending||v.isPending,isSoloingAccount:x.isPending,isBulkPausing:m.isPending,isBulkResuming:T.isPending})}):O?e.jsx(e.Fragment,{children:e.jsx(Gt,{provider:O.provider,displayName:O.displayName,authStatus:O,catalog:G[O.provider],routing:P[O.provider],isRemoteMode:M,topNotice:b?e.jsx(pt,{compact:!0,showProxySettingsLink:!0}):void 0,onAddAccount:()=>I({provider:O.provider,displayName:O.displayName,isFirstAccount:(O.accounts?.length||0)===0}),onSetDefault:f=>r.mutate({provider:O.provider,accountId:f}),onRemoveAccount:f=>h.mutate({provider:O.provider,accountId:f}),onPauseToggle:(f,q)=>Z(O.provider,f,q),onSoloMode:f=>ne(O.provider,f),onBulkPause:f=>U(O.provider,f),onBulkResume:f=>ae(O.provider,f),isRemovingAccount:h.isPending,isPausingAccount:p.isPending||v.isPending,isSoloingAccount:x.isPending,isBulkPausing:m.isPending,isBulkResuming:T.isPending})}):e.jsx(yn,{onSetup:()=>d(!0)})}),e.jsx(Ba,{open:w,onClose:()=>d(!1)}),e.jsx(Za,{open:j!==null,onClose:()=>I(null),provider:j?.provider||"",displayName:j?.displayName||"",catalog:R&&j?.provider?G[j.provider]:void 0,isFirstAccount:j?.isFirstAccount||!1})]})}export{Kn as CliproxyPage};