cartethyia 2.5.8 → 2.5.10

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 (157) hide show
  1. package/.env.example +7 -42
  2. package/README.md +11 -10
  3. package/dist/dashboard/assets/{BannedPage-BKAI54IA.js → BannedPage-Cd30Z0b9.js} +1 -1
  4. package/dist/dashboard/assets/BannedPage-Cd30Z0b9.js.gz +0 -0
  5. package/dist/dashboard/assets/{CliToolDetailPage-CkGvxrHu.js → CliToolDetailPage-wf5u-ww6.js} +1 -1
  6. package/dist/dashboard/assets/CliToolDetailPage-wf5u-ww6.js.gz +0 -0
  7. package/dist/dashboard/assets/{CliToolsPage-Cj8MYpeY.js → CliToolsPage-DykPvuck.js} +1 -1
  8. package/dist/dashboard/assets/CliToolsPage-DykPvuck.js.gz +0 -0
  9. package/dist/dashboard/assets/{CombosPage-BDXBEbWT.js → CombosPage-DwvSD3vs.js} +1 -1
  10. package/dist/dashboard/assets/CombosPage-DwvSD3vs.js.gz +0 -0
  11. package/dist/dashboard/assets/{ConsoleLogPage-49KH4z3l.js → ConsoleLogPage-CIr7KDex.js} +1 -1
  12. package/dist/dashboard/assets/ConsoleLogPage-CIr7KDex.js.gz +0 -0
  13. package/dist/dashboard/assets/{CustomizationPage-EHjBmNBZ.js → CustomizationPage-82X0DDdH.js} +1 -1
  14. package/dist/dashboard/assets/CustomizationPage-82X0DDdH.js.gz +0 -0
  15. package/dist/dashboard/assets/{HealthEventsModal-ByUTtj7j.js → HealthEventsModal-BYPucTTn.js} +1 -1
  16. package/dist/dashboard/assets/HealthEventsModal-BYPucTTn.js.gz +0 -0
  17. package/dist/dashboard/assets/{LoginPage-CYSCKT8S.js → LoginPage-CS5mPuVF.js} +1 -1
  18. package/dist/dashboard/assets/LoginPage-CS5mPuVF.js.gz +0 -0
  19. package/dist/dashboard/assets/{ModelPicker-C7pDb41R.js → ModelPicker-C0UCUsVJ.js} +1 -1
  20. package/dist/dashboard/assets/ModelPicker-C0UCUsVJ.js.gz +0 -0
  21. package/dist/dashboard/assets/{OverviewPage-Bu3iqBMm.js → OverviewPage-Dk_ew3YU.js} +1 -1
  22. package/dist/dashboard/assets/OverviewPage-Dk_ew3YU.js.gz +0 -0
  23. package/dist/dashboard/assets/{ProviderDetailPage-FHdgmgjU.js → ProviderDetailPage-CAiRn2Q0.js} +1 -1
  24. package/dist/dashboard/assets/ProviderDetailPage-CAiRn2Q0.js.gz +0 -0
  25. package/dist/dashboard/assets/{ProvidersPage-CCvYS9CF.js → ProvidersPage-vdja5ZPK.js} +1 -1
  26. package/dist/dashboard/assets/ProvidersPage-vdja5ZPK.js.gz +0 -0
  27. package/dist/dashboard/assets/{ProxyPage-HOl9cjxl.js → ProxyPage-BB4CNm4-.js} +1 -1
  28. package/dist/dashboard/assets/ProxyPage-BB4CNm4-.js.gz +0 -0
  29. package/dist/dashboard/assets/{QuotaPage-MUGzIpTK.js → QuotaPage-FEc4iNyq.js} +1 -1
  30. package/dist/dashboard/assets/QuotaPage-FEc4iNyq.js.gz +0 -0
  31. package/dist/dashboard/assets/{SettingsPage-CTdF5TCa.js → SettingsPage-Dlfi5L4N.js} +1 -1
  32. package/dist/dashboard/assets/SettingsPage-Dlfi5L4N.js.gz +0 -0
  33. package/dist/dashboard/assets/{SetupPage-Bra7rkKx.js → SetupPage-FadUOl9S.js} +1 -1
  34. package/dist/dashboard/assets/SetupPage-FadUOl9S.js.gz +0 -0
  35. package/dist/dashboard/assets/{SortableList-BRscd-vl.js → SortableList-Cfy6_Khv.js} +1 -1
  36. package/dist/dashboard/assets/SortableList-Cfy6_Khv.js.gz +0 -0
  37. package/dist/dashboard/assets/{StudioPage-BeevnFtM.js → StudioPage-CM92fgJf.js} +1 -1
  38. package/dist/dashboard/assets/StudioPage-CM92fgJf.js.gz +0 -0
  39. package/dist/dashboard/assets/{UsagePage-BWik9fpu.js → UsagePage-BT4MyQeT.js} +1 -1
  40. package/dist/dashboard/assets/UsagePage-BT4MyQeT.js.gz +0 -0
  41. package/dist/dashboard/assets/{app-BIt446yE.js → app-B7pVRhJ1.js} +1 -1
  42. package/dist/dashboard/assets/{app-BIt446yE.js.gz → app-B7pVRhJ1.js.gz} +0 -0
  43. package/dist/dashboard/assets/{badge-CR72dasT.js → badge-Bvyr7D0u.js} +1 -1
  44. package/dist/dashboard/assets/badge-Bvyr7D0u.js.gz +0 -0
  45. package/dist/dashboard/assets/{banner-CI9_eSfO.js → banner-DIvKAZih.js} +1 -1
  46. package/dist/dashboard/assets/banner-DIvKAZih.js.gz +0 -0
  47. package/dist/dashboard/assets/{card-DS7CQEsO.js → card-D5_gYIS_.js} +1 -1
  48. package/dist/dashboard/assets/card-D5_gYIS_.js.gz +0 -0
  49. package/dist/dashboard/assets/{clipboard-button-611pSsaX.js → clipboard-button-B6vDBtbm.js} +1 -1
  50. package/dist/dashboard/assets/clipboard-button-B6vDBtbm.js.gz +0 -0
  51. package/dist/dashboard/assets/{dialog-k37exjNt.js → dialog-CpjrgdwJ.js} +1 -1
  52. package/dist/dashboard/assets/dialog-CpjrgdwJ.js.gz +0 -0
  53. package/dist/dashboard/assets/{drawer-CX7N8ucR.js → drawer-BWmt3b5y.js} +1 -1
  54. package/dist/dashboard/assets/drawer-BWmt3b5y.js.gz +0 -0
  55. package/dist/dashboard/assets/{entry-B9Xvtnfj.js → entry-B-gvimrg.js} +1 -1
  56. package/dist/dashboard/assets/entry-B-gvimrg.js.gz +0 -0
  57. package/dist/dashboard/assets/{entry-CTP8AyiS.js → entry-C_oakV3z.js} +1 -1
  58. package/dist/dashboard/assets/entry-C_oakV3z.js.gz +0 -0
  59. package/dist/dashboard/assets/{entry-BqZ5vrM7.js → entry-Dj0cHfEc.js} +3 -3
  60. package/dist/dashboard/assets/entry-Dj0cHfEc.js.gz +0 -0
  61. package/dist/dashboard/assets/{github-badge-sltk1qUi.js → github-badge-RRHHWGxh.js} +1 -1
  62. package/dist/dashboard/assets/github-badge-RRHHWGxh.js.gz +0 -0
  63. package/dist/dashboard/assets/{index-9ARd3FIs.js → index-Bhey_rg_.js} +2 -2
  64. package/dist/dashboard/assets/index-Bhey_rg_.js.gz +0 -0
  65. package/dist/dashboard/assets/{inline-BhY2sSnO.js → inline-C2_EQ5Uf.js} +1 -1
  66. package/dist/dashboard/assets/inline-C2_EQ5Uf.js.gz +0 -0
  67. package/dist/dashboard/assets/{input-V1umFiBk.js → input-BMRlQ450.js} +1 -1
  68. package/dist/dashboard/assets/input-BMRlQ450.js.gz +0 -0
  69. package/dist/dashboard/assets/{layout-BBOYycyS.js → layout-XR5xP8ew.js} +1 -1
  70. package/dist/dashboard/assets/layout-XR5xP8ew.js.gz +0 -0
  71. package/dist/dashboard/assets/{list-row-1zzZYM0B.js → list-row-Cw07dioc.js} +1 -1
  72. package/dist/dashboard/assets/list-row-Cw07dioc.js.gz +0 -0
  73. package/dist/dashboard/assets/{numbers-DkfMR5Qs.js → numbers-DrdA9oSM.js} +1 -1
  74. package/dist/dashboard/assets/numbers-DrdA9oSM.js.gz +0 -0
  75. package/dist/dashboard/assets/{select-D_BBhBEF.js → select-CxVVB__N.js} +1 -1
  76. package/dist/dashboard/assets/select-CxVVB__N.js.gz +0 -0
  77. package/dist/dashboard/assets/{stack-BHTfXdz_.js → stack-uPOwM9Hs.js} +1 -1
  78. package/dist/dashboard/assets/stack-uPOwM9Hs.js.gz +0 -0
  79. package/dist/dashboard/assets/{state-mPDRlQkl.js → state-D1Yz79iL.js} +1 -1
  80. package/dist/dashboard/assets/state-D1Yz79iL.js.gz +0 -0
  81. package/dist/dashboard/assets/{switch-DOmJxg7H.js → switch-sevsRrRo.js} +1 -1
  82. package/dist/dashboard/assets/switch-sevsRrRo.js.gz +0 -0
  83. package/dist/dashboard/index.html +1 -1
  84. package/dist/dashboard/index.html.gz +0 -0
  85. package/dist/dashboard/precompressed-assets.json +40 -40
  86. package/package.json +1 -3
  87. package/scripts/cli/admin.ts +3 -0
  88. package/scripts/cli/console-menu.ts +299 -275
  89. package/scripts/cli/doctor.ts +1 -1
  90. package/scripts/cli/gateway.ts +1 -2
  91. package/scripts/{health.ts → cli/health.ts} +4 -4
  92. package/scripts/cli/main.ts +3 -0
  93. package/scripts/cli/prompt.ts +137 -107
  94. package/scripts/cli/start.ts +3 -0
  95. package/scripts/cli/tray.ts +167 -208
  96. package/src/config/package-paths.ts +24 -0
  97. package/src/console/backup/nine-router.ts +43 -9
  98. package/src/console/remote-support/service.ts +270 -114
  99. package/src/console/routing/pools/store.ts +1 -1
  100. package/src/console/updates/repository-updates.ts +40 -39
  101. package/src/observability/event-day-index.ts +1 -2
  102. package/src/protocol/registry.ts +2 -0
  103. package/src/providers/default-registry.ts +4 -0
  104. package/src/providers/discovery/openrouter-free-roster.ts +0 -1
  105. package/src/providers/integrations/buddy/buddy-catalog-shared.ts +3 -2
  106. package/src/providers/integrations/buddy/capabilities.ts +4 -0
  107. package/src/providers/integrations/buddy/codebuddy/cn-provider.ts +2 -1
  108. package/src/providers/integrations/github/github.ts +3 -1
  109. package/src/providers/integrations/opencode/provider.ts +2 -3
  110. package/src/providers/integrations/trae/trae-headers.ts +17 -48
  111. package/src/providers/integrations/trae/trae.ts +22 -24
  112. package/src/providers/operations/provider-credential-service.ts +29 -3
  113. package/src/providers/provider-probe.ts +3 -0
  114. package/dist/dashboard/assets/BannedPage-BKAI54IA.js.gz +0 -0
  115. package/dist/dashboard/assets/CliToolDetailPage-CkGvxrHu.js.gz +0 -0
  116. package/dist/dashboard/assets/CliToolsPage-Cj8MYpeY.js.gz +0 -0
  117. package/dist/dashboard/assets/CombosPage-BDXBEbWT.js.gz +0 -0
  118. package/dist/dashboard/assets/ConsoleLogPage-49KH4z3l.js.gz +0 -0
  119. package/dist/dashboard/assets/CustomizationPage-EHjBmNBZ.js.gz +0 -0
  120. package/dist/dashboard/assets/HealthEventsModal-ByUTtj7j.js.gz +0 -0
  121. package/dist/dashboard/assets/LoginPage-CYSCKT8S.js.gz +0 -0
  122. package/dist/dashboard/assets/ModelPicker-C7pDb41R.js.gz +0 -0
  123. package/dist/dashboard/assets/OverviewPage-Bu3iqBMm.js.gz +0 -0
  124. package/dist/dashboard/assets/ProviderDetailPage-FHdgmgjU.js.gz +0 -0
  125. package/dist/dashboard/assets/ProvidersPage-CCvYS9CF.js.gz +0 -0
  126. package/dist/dashboard/assets/ProxyPage-HOl9cjxl.js.gz +0 -0
  127. package/dist/dashboard/assets/QuotaPage-MUGzIpTK.js.gz +0 -0
  128. package/dist/dashboard/assets/SettingsPage-CTdF5TCa.js.gz +0 -0
  129. package/dist/dashboard/assets/SetupPage-Bra7rkKx.js.gz +0 -0
  130. package/dist/dashboard/assets/SortableList-BRscd-vl.js.gz +0 -0
  131. package/dist/dashboard/assets/StudioPage-BeevnFtM.js.gz +0 -0
  132. package/dist/dashboard/assets/UsagePage-BWik9fpu.js.gz +0 -0
  133. package/dist/dashboard/assets/badge-CR72dasT.js.gz +0 -0
  134. package/dist/dashboard/assets/banner-CI9_eSfO.js.gz +0 -0
  135. package/dist/dashboard/assets/card-DS7CQEsO.js.gz +0 -0
  136. package/dist/dashboard/assets/clipboard-button-611pSsaX.js.gz +0 -0
  137. package/dist/dashboard/assets/dialog-k37exjNt.js.gz +0 -0
  138. package/dist/dashboard/assets/drawer-CX7N8ucR.js.gz +0 -0
  139. package/dist/dashboard/assets/entry-B9Xvtnfj.js.gz +0 -0
  140. package/dist/dashboard/assets/entry-BqZ5vrM7.js.gz +0 -0
  141. package/dist/dashboard/assets/entry-CTP8AyiS.js.gz +0 -0
  142. package/dist/dashboard/assets/github-badge-sltk1qUi.js.gz +0 -0
  143. package/dist/dashboard/assets/index-9ARd3FIs.js.gz +0 -0
  144. package/dist/dashboard/assets/inline-BhY2sSnO.js.gz +0 -0
  145. package/dist/dashboard/assets/input-V1umFiBk.js.gz +0 -0
  146. package/dist/dashboard/assets/layout-BBOYycyS.js.gz +0 -0
  147. package/dist/dashboard/assets/list-row-1zzZYM0B.js.gz +0 -0
  148. package/dist/dashboard/assets/numbers-DkfMR5Qs.js.gz +0 -0
  149. package/dist/dashboard/assets/select-D_BBhBEF.js.gz +0 -0
  150. package/dist/dashboard/assets/stack-BHTfXdz_.js.gz +0 -0
  151. package/dist/dashboard/assets/state-mPDRlQkl.js.gz +0 -0
  152. package/dist/dashboard/assets/switch-DOmJxg7H.js.gz +0 -0
  153. package/scripts/build/aot.ts +0 -143
  154. package/scripts/build/build.ts +0 -24
  155. package/scripts/build/compile.ts +0 -88
  156. package/scripts/build/restart.ts +0 -120
  157. package/scripts/build/start.ts +0 -25
@@ -1,39 +1,40 @@
1
- /**
2
- * Public release discovery for the console's update indicator.
3
- *
4
- * The browser never talks to GitHub directly: a dashboard-side fetch would put
5
- * every console user's GitHub rate limit behind one shared, unauthenticated
6
- * origin, and a CORS or rate-limit failure would surface as a console error
7
- * nobody can act on. The request is made here, server-side, and any failure
8
- * degrades to "no update known" rather than an error the operator must read.
9
- *
10
- * Releases are read from the ALTERNATIVE repository (`risunCodex`), not the
11
- * primary: the primary repository is hidden from public view, so its releases
12
- * endpoint answers 404 and the console would report "no update known" forever —
13
- * a silent failure that reads exactly like "you are up to date".
14
- */
15
- const REPOSITORY = "risunCodex/Cartethyia";
16
-
17
- /** Timeout for one GitHub read. A hung read must not hold a console query open. */
18
- const REQUEST_TIMEOUT_MS = 10_000;
19
-
20
- export interface LatestRelease {
21
- readonly tag_name: string;
22
- readonly html_url: string;
23
- }
24
-
25
- /** Fetches the latest public release. Returns `null` when none is known. */
26
- export async function fetchLatestRelease(): Promise<LatestRelease | null> {
27
- try {
28
- const response = await fetch(`https://api.github.com/repos/${REPOSITORY}/releases/latest`, {
29
- headers: { accept: "application/vnd.github+json", "user-agent": "Cartethyia-updater" },
30
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
31
- });
32
- if (!response.ok) return null;
33
- const value = (await response.json()) as { readonly tag_name?: unknown; readonly html_url?: unknown };
34
- if (typeof value.tag_name !== "string" || typeof value.html_url !== "string") return null;
35
- return { tag_name: value.tag_name, html_url: value.html_url };
36
- } catch {
37
- return null;
38
- }
39
- }
1
+ /**
2
+ * Public release discovery for the console's update indicator.
3
+ *
4
+ * The browser never talks to GitHub directly: a dashboard-side fetch would put
5
+ * every console user's GitHub rate limit behind one shared, unauthenticated
6
+ * origin, and a CORS or rate-limit failure would surface as a console error
7
+ * nobody can act on. The request is made here, server-side, and any failure
8
+ * degrades to "no update known" rather than an error the operator must read.
9
+ *
10
+ * Releases are read from the primary repository `risunCodex/Cartethyia`. The
11
+ * historical original `risunCode/Cartethyia` is hidden from public view, so
12
+ * its releases endpoint answers 404; the primary is where releases are
13
+ * published and where this check must point so the update indicator does not
14
+ * silently read "no update known" forever.
15
+ */
16
+ const REPOSITORY = "risunCodex/Cartethyia";
17
+
18
+ /** Timeout for one GitHub read. A hung read must not hold a console query open. */
19
+ const REQUEST_TIMEOUT_MS = 10_000;
20
+
21
+ export interface LatestRelease {
22
+ readonly tag_name: string;
23
+ readonly html_url: string;
24
+ }
25
+
26
+ /** Fetches the latest public release. Returns `null` when none is known. */
27
+ export async function fetchLatestRelease(): Promise<LatestRelease | null> {
28
+ try {
29
+ const response = await fetch(`https://api.github.com/repos/${REPOSITORY}/releases/latest`, {
30
+ headers: { accept: "application/vnd.github+json", "user-agent": "Cartethyia-updater" },
31
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
32
+ });
33
+ if (!response.ok) return null;
34
+ const value = (await response.json()) as { readonly tag_name?: unknown; readonly html_url?: unknown };
35
+ if (typeof value.tag_name !== "string" || typeof value.html_url !== "string") return null;
36
+ return { tag_name: value.tag_name, html_url: value.html_url };
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
@@ -1,4 +1,4 @@
1
- import { mkdir, open, readFile, rename, stat, writeFile } from "node:fs/promises";
1
+ import { mkdir, open, readdir, readFile, rename, stat, writeFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import {
4
4
  accumulate,
@@ -382,7 +382,6 @@ export async function foldDayIndex(day: string): Promise<{ readonly folded: numb
382
382
 
383
383
  /** The days whose index should be folded, newest last. */
384
384
  export async function listEventDays(): Promise<readonly string[]> {
385
- const { readdir } = await import("node:fs/promises");
386
385
  const files = await readdir(TELEMETRY_EVENT_DIR).catch(() => [] as string[]);
387
386
  const days = new Set<string>();
388
387
  for (const file of files) {
@@ -110,6 +110,8 @@ async function loadCodec(wireFamily: WireFamily): Promise<CodecModule> {
110
110
  const cached = codecCache.get(wireFamily);
111
111
  if (cached !== undefined) return cached;
112
112
  const promise = (async (): Promise<CodecModule> => {
113
+ // dynamic-import: codec picked by wire family at request time; static
114
+ // imports here would couple every request path to every codec module.
113
115
  switch (wireFamily) {
114
116
  case "chat":
115
117
  return (await import("./request/chat")).chatCodecModule;
@@ -1,3 +1,7 @@
1
+ // dynamic-import-ok: lazy provider registry. Every entry is a
2
+ // `() => await import("./integrations/<name>/...")` so loading a provider
3
+ // pays only when the first request routes to it. Static imports here would
4
+ // drag every integration into memory at process start.
1
5
  import {
2
6
  GENERIC_API_KEY_SPECS,
3
7
  } from "./configured-openai-providers";
@@ -54,7 +54,6 @@ interface FreeRow {
54
54
  const FREE_ROWS: readonly FreeRow[] = [
55
55
  { id: "cohere/north-mini-code:free", ctx: 256_000, out: 64_000 },
56
56
  { id: "dots-studio/dots-3-note-preview:free", ctx: 512_000, out: 460_800, vision: true },
57
- { id: "minimax/minimax-m3.1-flash:free", ctx: 1_000_000, out: 524_288, vision: true },
58
57
  {
59
58
  id: "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free",
60
59
  ctx: 256_000,
@@ -123,6 +123,7 @@ export const BUDDY_PRO_ONLY_MODEL_IDS: ReadonlySet<string> = new Set([
123
123
  "gemini-3.8-flash",
124
124
  "grok-4.6",
125
125
  "grok-4.7",
126
+ "kimi-k3.1-pro-highspeed",
126
127
  ]);
127
128
 
128
129
  /**
@@ -259,7 +260,6 @@ export const BUDDY_SHARED_RAW: readonly BuddyRawEntry[] = [
259
260
  ["claude-sonnet-4.6", "Claude Sonnet 4.6", true, true, 200_000, 32_000],
260
261
  ["deepseek-v4.1-flash", "DeepSeek V4.1 Flash", true, true, 1_000_000, 384_000],
261
262
  ["deepseek-v4.1-flash-sg", "DeepSeek V4.1 Flash SG", true, true, 1_000_000, 128_000],
262
- ["deepseek-v4.1-pro", "DeepSeek V4.1 Pro", true, false, 1_000_000, 384_000],
263
263
  ["gemini-2.5-flash-image", "Gemini 2.5 Flash Image", true, true, 1_000_000, 64_000],
264
264
  ["gemini-3.0-pro-image", "Gemini 3.0 Pro Image", true, true, 1_000_000, 64_000],
265
265
  ["gemini-3.1-flash-image", "Gemini 3.1 Flash Image", true, true, 1_000_000, 64_000],
@@ -278,7 +278,6 @@ export const BUDDY_SHARED_RAW: readonly BuddyRawEntry[] = [
278
278
  ["gpt-5.6-sol", "GPT-5.6 Sol", true, true, 1_050_000, 128_000],
279
279
  ["gpt-5.6-terra", "GPT-5.6 Terra", true, true, 1_050_000, 128_000],
280
280
  ["gpt-6-luna", "GPT-6 Luna", true, true, 1_050_000, 128_000],
281
- ["deep-model", "Deep Model", true, true, null, null],
282
281
  ["gpt-6-sol", "GPT-6 Sol", true, true, 1_000_000, 128_000, true],
283
282
  ["gpt-6.1-sol", "GPT-6.1 Sol", true, true, 1_050_000, 128_000],
284
283
  ["gpt-image-2", "GPT-Image-2", true, true, 400_000, 128_000],
@@ -293,6 +292,8 @@ export const BUDDY_SHARED_RAW: readonly BuddyRawEntry[] = [
293
292
  ["kimi-k2.7", "Kimi K2.7", true, false, 256_000, 65_536],
294
293
  ["kimi-k2.8-preview", "Kimi K2.8 Preview", true, false, 1_048_576, 65_536],
295
294
  ["kimi-k3", "Kimi K3", true, false, 1_048_576, 131_072],
295
+ ["kimi-k3.1-pro", "Kimi K3.1 Pro", true, true, 1_000_000, 64_000],
296
+ ["kimi-k3.1-pro-highspeed", "Kimi K3.1 Pro Highspeed", true, true, 1_000_000, 64_000],
296
297
  ["minimax-m3", "MiniMax-M3", true, false, 512_000, 512_000],
297
298
  ["step-5-preview", "Step-5-Preview", true, true, 1_000_000, 64_000, true],
298
299
  ];
@@ -1,3 +1,7 @@
1
+ // dynamic-import-ok: lazy per-realm capability map. Each buddy regional
2
+ // product (cb/cbcn/workbuddy/workbuddycn) imports its adapter + oauth +
3
+ // discovery on first use so a deployment that only serves one realm never
4
+ // drags the others into memory.
1
5
  import type { ProviderModuleCapabilities } from "../../provider-capabilities";
2
6
  import { oauthCapability, quotaCapability } from "../../provider-capabilities";
3
7
 
@@ -114,7 +114,8 @@ export const CODEBUDDY_CN_RAW: readonly BuddyRawEntry[] = [
114
114
  ["kimi-k2.7", "Kimi K2.7", true, true, 256_000, 65_536],
115
115
  ["kimi-k2.6", "Kimi K2.6", true, true, 256_000, 262_144],
116
116
  ["kimi-k2.5", "Kimi K2.5", true, true, 164_000, 262_144],
117
- ["kimi-k3-1", "Kimi K3", true, true, 1_048_576, 131_072],
117
+ ["kimi-k3.1-pro", "Kimi K3.1 Pro", true, true, 1_000_000, 64_000],
118
+ ["kimi-k3.1-pro-highspeed", "Kimi K3.1 Pro Highspeed", true, true, 1_000_000, 64_000],
118
119
  ["hy3", "Hy3", true, true, 192_000, 64_000],
119
120
  ["hy4-preview", "Hy4 Preview", true, true, 1_000_000, 64_000],
120
121
  ["uto", "UTO", true, true, 256_000, 32_000],
@@ -422,6 +422,9 @@ class GithubAdapter extends OpenAICompatibleAdapter {
422
422
  const selectedModelId = autoDecision.modelId;
423
423
  let route = await githubModelRoute(selectedModelId, credential);
424
424
  if (route === undefined) {
425
+ // dynamic-import: discovery module is only loaded when the first
426
+ // request routes to a model id not in the bundled roster; off the hot
427
+ // path for most deployments.
425
428
  const { discoverGithubModels } = await import("./github-discovery");
426
429
  const outboundFetch = context.outbound_fetch;
427
430
  const fetcher = outboundFetch === undefined
@@ -655,7 +658,6 @@ class GithubAdapter extends OpenAICompatibleAdapter {
655
658
  : GITHUB_ENDPOINT_PATH;
656
659
  const url = `${this.#baseUrl(context).replace(/\/+$/, "")}${endpointPath}`;
657
660
  const outboundFetch = context.outbound_fetch ?? this.#fetch ?? globalThis.fetch;
658
- const { postUpstreamJson } = await import("../../../protocol/upstream/post-json");
659
661
  const upstream = await postUpstreamJson(url, headers, payload as Record<string, unknown>, context, outboundFetch);
660
662
  upstream.release();
661
663
  return upstream.res;
@@ -230,7 +230,6 @@ const FREE_AGENT_TOOL_SCHEMA = {
230
230
  required: [] as string[],
231
231
  } as const;
232
232
 
233
-
234
233
  function ensureFreeAgentRequest(request: CanonicalRequest): CanonicalRequest {
235
234
  const present: Record<string, true> = {};
236
235
  for (const tool of request.tools ?? []) present[tool.name] = true;
@@ -251,8 +250,6 @@ function ensureFreeAgentRequest(request: CanonicalRequest): CanonicalRequest {
251
250
  };
252
251
  }
253
252
 
254
-
255
-
256
253
  function completeOpenCodeToolSchemas(payload: Record<string, unknown>): void {
257
254
  if (!Array.isArray(payload.tools)) return;
258
255
  payload.tools = payload.tools.map((tool) => {
@@ -404,6 +401,8 @@ export async function discoverOpenCodeFreeModels(options: {
404
401
  readonly baseUrl: string;
405
402
  readonly fetcher?: typeof fetch;
406
403
  }): Promise<readonly ModelDefinition[] | null> {
404
+ // dynamic-import: cycle break -- the discovery helper imports this file's
405
+ // OPENCODE_FREE_SPEC to decide its request shape.
407
406
  const { fetchOpenAICompatibleModels } = await import("../../discovery/openai-model-discovery");
408
407
  const listed = await fetchOpenAICompatibleModels({
409
408
  baseUrl: options.baseUrl,
@@ -1,15 +1,18 @@
1
1
  // Trae request headers: auth + device fingerprint.
2
2
  //
3
- // The two realms do not authenticate the same way. CN sends
4
- // `Authorization: Cloud-IDE-JWT <token>`; intl overrides it to `Bearer <token>`
5
- // and additionally sends the *current* client version, because intl
6
- // `llm_raw_chat` answers `4015` (risk control) when the version is stale. That
7
- // is why the version here is resolved rather than pinned.
3
+ // Aligned with Trae 1.107.1 (Linux x64 bundle, unpacked from TRAE-linux-x64.rpm).
4
+ // The canonical client sends:
5
+ // - Authorization: Cloud-IDE-JWT <token> (both realms, no Bearer)
6
+ // - X-App-Id, x-plugin-channel, x-ide-version-code
7
+ // - X-Device-Cpu, X-Device-Id, X-Machine-Id, X-Device-Brand,
8
+ // X-Device-Type, X-Os-Version (all encodeURIComponent'd)
9
+ // - User-Agent: TraeClient/TTNet
8
10
  //
9
- // Sourced from the donor hub `Public/trae2api-hub` (`auth_headers` in
10
- // `trae_client.py`, `trae_device_headers` in `trae_fingerprint.py`).
11
+ // The donor's data-plane implementation and the native Agent transport both
12
+ // send x-ide-token alongside Authorization. Version headers remain separate:
13
+ // they are not universally required by Agent and commercial requests.
11
14
 
12
- import { createHash, randomUUID } from "node:crypto";
15
+ import { createHash } from "node:crypto";
13
16
  import {
14
17
  TRAE_APP_ID,
15
18
  TRAE_PLUGIN_CHANNEL,
@@ -58,23 +61,13 @@ export const TRAE_OS_VERSION = "Windows 11 Pro";
58
61
  /** Reported hardware brand, same reasoning as the OS string. */
59
62
  export const TRAE_DEVICE_BRAND = "Default string";
60
63
 
61
- /** Per-request correlation id. Random, not derived — decoupled from the device. */
62
- export function traeRequestId(): string {
63
- return randomUUID();
64
- }
65
-
66
64
  /** Inputs for {@link buildTraeHeaders}. */
67
65
  export interface TraeHeaderInput {
68
66
  readonly realm: TraeRealm;
69
- /** Access token, sent as both `x-ide-token` and the Authorization bearer. */
67
+ /** Access token, sent as both `x-ide-token` and Cloud-IDE-JWT. */
70
68
  readonly token: string;
71
69
  /** Account id the device fingerprint is derived from. */
72
70
  readonly uid: string;
73
- /**
74
- * Current client version, e.g. `3.6.2`. Sent by intl as `x-ide-version` and
75
- * `x-app-version`; a stale value is refused with 4015.
76
- */
77
- readonly clientVersion?: string;
78
71
  /** Version code sent as `x-ide-version-code`. */
79
72
  readonly versionCode?: string;
80
73
  /** True for the streaming chat call, which overrides `Accept`. */
@@ -99,28 +92,15 @@ export function buildTraeHeaders(input: TraeHeaderInput): Record<string, string>
99
92
  Authorization: `Cloud-IDE-JWT ${input.token}`,
100
93
  "Content-Type": "application/json",
101
94
  Accept: "application/json",
102
- "User-Agent": config.userAgent,
103
- "X-Device-Cpu": "Intel",
104
- "X-Device-Id": device.deviceId,
105
- "X-Machine-Id": device.machineId,
95
+ "User-Agent": "TraeClient/TTNet",
96
+ "X-Device-Cpu": encodeURIComponent("Intel"),
97
+ "X-Device-Id": encodeURIComponent(device.deviceId),
98
+ "X-Machine-Id": encodeURIComponent(device.machineId),
106
99
  "X-Device-Brand": encodeURIComponent(TRAE_DEVICE_BRAND),
107
- "X-Device-Type": "windows",
100
+ "X-Device-Type": encodeURIComponent("windows"),
108
101
  "X-Os-Version": encodeURIComponent(TRAE_OS_VERSION),
109
- "X-Request-Id": traeRequestId(),
110
102
  };
111
103
 
112
- if (input.realm === "intl") {
113
- // intl raw_chat requires Bearer (not Cloud-IDE-JWT) *and* the current
114
- // client version on four headers; a stale version is answered 4015.
115
- const version = input.clientVersion ?? intlVersionFallback(config.userAgent);
116
- headers["Authorization"] = `Bearer ${input.token}`;
117
- headers["x-ide-token"] = input.token;
118
- headers["x-ide-version"] = version;
119
- headers["x-app-version"] = version;
120
- headers["User-Agent"] = "TraeClient/TTNet";
121
- headers["store-country-code"] = "us";
122
- }
123
-
124
104
  if (input.stream === true) {
125
105
  headers["Accept"] = "text/event-stream";
126
106
  headers["Cache-Control"] = "no-cache";
@@ -136,14 +116,3 @@ export function buildTraeHeaders(input: TraeHeaderInput): Record<string, string>
136
116
  return headers;
137
117
  }
138
118
 
139
- /**
140
- * Last-resort intl version: the one baked into the realm's own User-Agent.
141
- *
142
- * Only reached when the version resolver has not answered yet. It is the
143
- * donor's last observed version rather than an invented number, so a cold
144
- * process sends something upstream has accepted before.
145
- */
146
- function intlVersionFallback(userAgent: string): string {
147
- const match = userAgent.match(/(\d+\.\d+\.\d+)/);
148
- return match?.[1] ?? "3.6.2";
149
- }
@@ -1,9 +1,8 @@
1
1
  // Trae adapter.
2
2
  //
3
3
  // Realm-aware: `trae` (intl) and `traecn` (CN) share this code but nothing of
4
- // the address, the authorization scheme, or the roster. The intl deployment
5
- // additionally gates on the *current* client version, which is why the version
6
- // here comes from `getTraeVersion()` (a live resolver) rather than a constant.
4
+ // the address or the roster. Both realms authenticate with
5
+ // `Authorization: Cloud-IDE-JWT <token>` per the Trae 1.107.1 bundle.
7
6
 
8
7
  import { GatewayError } from "../../../protocol/gateway-error";
9
8
  import type { CanonicalEvent, CanonicalRequest, CanonicalStopReason } from "../../../protocol/canonical-model";
@@ -16,7 +15,6 @@ import {
16
15
  type ProviderId,
17
16
  } from "../../provider-contracts";
18
17
  import { mapUpstreamHttpError } from "../../../transport/failure-policy";
19
- import { getTraeVersion } from "../../operations/client-versions";
20
18
  import { abortGatewayError, createUpstreamDeadlineLifecycle } from "../../operations/upstream-deadline";
21
19
  import { TRAE_CN_MODELS, TRAE_INTL_MODELS, traeMaxContextWindow } from "./trae-catalog";
22
20
  import { buildTraeHeaders } from "./trae-headers";
@@ -92,14 +90,6 @@ class TraeAdapter implements ProviderAdapter {
92
90
  readonly provider_id: ProviderId;
93
91
  private readonly realm: TraeRealm;
94
92
  private readonly fetchFn: typeof fetch;
95
- /**
96
- * Maps a frame's `index` to the call id seen for it.
97
- *
98
- * Argument fragments arrive without the id, so the association has to be
99
- * remembered between frames rather than read from the fragment itself.
100
- */
101
- readonly #toolCallIds = new Map<string, string>();
102
-
103
93
  constructor(options: TraeAdapterOptions = {}) {
104
94
  this.provider_id = (options.providerId ?? TRAE_PROVIDER_ID) as ProviderId;
105
95
  this.realm = options.realm ?? "intl";
@@ -124,9 +114,6 @@ class TraeAdapter implements ProviderAdapter {
124
114
  const outboundFetch =
125
115
  (context.outbound_fetch as unknown as typeof fetch | undefined) ?? this.fetchFn;
126
116
 
127
- // intl refuses a stale client version with 4015, so the resolved version is
128
- // part of every request rather than a startup detail.
129
- const version = getTraeVersion();
130
117
  const auth = traeAuth(secret, context.credential.account_id);
131
118
  const body = buildTraeChatBody(modelId, request, this.realm);
132
119
  /**
@@ -144,7 +131,6 @@ class TraeAdapter implements ProviderAdapter {
144
131
  realm: this.realm,
145
132
  token: auth.token,
146
133
  uid: auth.uid,
147
- clientVersion: version,
148
134
  stream: true,
149
135
  });
150
136
 
@@ -192,6 +178,9 @@ class TraeAdapter implements ProviderAdapter {
192
178
  yield { type: "response_start", sequence_number: seq++, model: requestModel } as CanonicalEvent;
193
179
  let stopReason: CanonicalStopReason = "stop";
194
180
  let usage: Record<string, unknown> | undefined;
181
+ // Tool ids are scoped to one stream. Argument-only frames from a later
182
+ // request must never inherit an earlier request's id at the same index.
183
+ const toolCallIds = new Map<string, string>();
195
184
  /**
196
185
  * Tool calls arrive fragmented across frames and the id is not repeated.
197
186
  *
@@ -212,8 +201,12 @@ class TraeAdapter implements ProviderAdapter {
212
201
  continue;
213
202
  }
214
203
  if (frame.event === "error") {
215
- const data = frame.data as { message?: unknown };
216
- const message = typeof data.message === "string" ? data.message : "Trae stream error";
204
+ const data = frame.data as { message?: unknown; code?: unknown };
205
+ const message = typeof data.message === "string" && data.message.length > 0
206
+ ? data.message
207
+ : typeof data.code === "number" || typeof data.code === "string"
208
+ ? `Trae stream error (upstream code ${data.code})`
209
+ : "Trae stream error";
217
210
  throw new GatewayError("platform_unavailable", 502, message, {}, "upstream");
218
211
  }
219
212
  if (typeof frame.data !== "object" || frame.data === null) continue;
@@ -245,7 +238,7 @@ class TraeAdapter implements ProviderAdapter {
245
238
  content: { kind: "reasoning", payload: null, summary: flatReasoning },
246
239
  } as CanonicalEvent;
247
240
  }
248
- yield* this.#toolCallDeltas(record["tool_calls"], announced, () => seq++);
241
+ yield* this.#toolCallDeltas(record["tool_calls"], announced, toolCallIds, () => seq++);
249
242
  if (typeof record["finish_reason"] === "string") {
250
243
  stopReason = STOP_REASONS[record["finish_reason"] as string] ?? "stop";
251
244
  }
@@ -277,8 +270,9 @@ class TraeAdapter implements ProviderAdapter {
277
270
  } as CanonicalEvent;
278
271
  }
279
272
  if (typeof payload["finish_reason"] === "string") {
280
- stopReason = STOP_REASONS[payload["finish_reason"]] ?? "stop";
273
+ stopReason = STOP_REASONS[payload["finish_reason"] as string] ?? "stop";
281
274
  }
275
+ yield* this.#toolCallDeltas(payload["tool_calls"], announced, toolCallIds, () => seq++);
282
276
  if (typeof payload["usage"] === "object" && payload["usage"] !== null) {
283
277
  usage = payload["usage"] as Record<string, unknown>;
284
278
  }
@@ -311,6 +305,7 @@ class TraeAdapter implements ProviderAdapter {
311
305
  async *#toolCallDeltas(
312
306
  raw: unknown,
313
307
  announced: Set<string>,
308
+ toolCallIds: Map<string, string>,
314
309
  nextSeq: () => number,
315
310
  ): AsyncIterable<CanonicalEvent> {
316
311
  if (!Array.isArray(raw)) return;
@@ -326,7 +321,7 @@ class TraeAdapter implements ProviderAdapter {
326
321
  const slot = `idx:${index}`;
327
322
 
328
323
  if (declaredId.length > 0) {
329
- this.#toolCallIds.set(slot, declaredId);
324
+ toolCallIds.set(slot, declaredId);
330
325
  // The closing frame repeats a known id with no payload; emitting it
331
326
  // again would append a duplicate empty call.
332
327
  if (announced.has(declaredId)) continue;
@@ -338,11 +333,11 @@ class TraeAdapter implements ProviderAdapter {
338
333
  name: name ?? "",
339
334
  arguments_delta: "",
340
335
  } as CanonicalEvent;
341
- continue;
336
+ if (args.length === 0) continue;
342
337
  }
343
338
 
344
339
  if (args.length === 0) continue;
345
- const id = this.#toolCallIds.get(slot);
340
+ const id = toolCallIds.get(slot);
346
341
  if (id === undefined) continue;
347
342
  yield {
348
343
  type: "tool_call_delta",
@@ -400,7 +395,10 @@ export async function discoverTraeModels(input: {
400
395
  readonly providerId?: string;
401
396
  /** Account region, so the listing is asked of the host that serves it. */
402
397
  readonly region?: string;
403
- }): Promise<readonly { id: string; ctx: number | undefined }[]> {
398
+ }): Promise<readonly {
399
+ id: string;
400
+ ctx: number | undefined;
401
+ }[]> {
404
402
  const headers = buildTraeHeaders({
405
403
  realm: input.realm,
406
404
  token: input.token,
@@ -152,14 +152,33 @@ export async function loadAccountWithFreshness(
152
152
  const row = rows[0];
153
153
  if (!row) return undefined;
154
154
  const lead = skewMs ?? refreshLeadMs(row.providerId);
155
+ // A refresh-capable OAuth account with no stored expiry is unknown-liveness:
156
+ // we have no evidence the access token still works. The old rule left
157
+ // `dueAt` undefined for these, so `resolveCredentialForAccount` skipped the
158
+ // refresh branch and dispatch sent the pasted token as-is. For a token that
159
+ // had already expired on another installation (a 9router/Omniroute import
160
+ // carrying `accessToken` + `refreshToken` + a past `expiresAt` that was
161
+ // dropped by validation, a hand-pasted OAuth bundle with no expiry field,
162
+ // or an upstream that stopped minting expiries) that produced the exact
163
+ // "re-authenticate" refusal the refresh grant exists to prevent. Marking the
164
+ // token due immediately refreshes it on first use; the sweep handles the
165
+ // normal case where `expires_at` is populated.
166
+ const hasRefreshGrant = row.refreshCiphertext != null;
167
+ const kindOauth = row.credentialKind === "oauth";
168
+ const unknownExpiryButRefreshable =
169
+ kindOauth && !row.staticToken && hasRefreshGrant && row.expiresAt == null;
155
170
  return {
156
171
  row,
157
172
  // A static token is never "due": it is used as issued and there is no
158
173
  // refresh to run, so the dispatch path must not treat it as stale.
159
174
  dueAt:
160
- row.staticToken || row.expiresAt == null
175
+ row.staticToken
161
176
  ? undefined
162
- : row.expiresAt.getTime() - lead,
177
+ : row.expiresAt != null
178
+ ? row.expiresAt.getTime() - lead
179
+ : unknownExpiryButRefreshable
180
+ ? 0
181
+ : undefined,
163
182
  };
164
183
  }
165
184
 
@@ -223,7 +242,14 @@ export async function resolveCredentialForAccount(
223
242
  if (row.credentialKind === "oauth" && oauth && dueAt !== undefined && dueAt <= Date.now()) {
224
243
  const refresher = await oauth.resolveRefresher(row.providerId);
225
244
  if (refresher) {
226
- secret = await oauth.refreshService.ensureFreshAccessToken(accountId, refresher) ?? undefined;
245
+ // Try to refresh. If it fails (refresh grant dead, upstream unreachable,
246
+ // etc.) keep the already-decrypted stale secret rather than wiping it:
247
+ // dispatch then sends the token we have, and the upstream's own 401 is
248
+ // the authoritative verdict. Wiping it here turned "token expired" into
249
+ // a credential-less GatewayError before the request ever left, which is
250
+ // worse than letting the server say so.
251
+ const refreshed = await oauth.refreshService.ensureFreshAccessToken(accountId, refresher);
252
+ if (refreshed) secret = refreshed;
227
253
  }
228
254
  }
229
255
 
@@ -87,6 +87,9 @@ export async function buildProviderProbeRequest(
87
87
  ): Promise<ProviderProbeRequest | undefined> {
88
88
  if (!isProbeableProvider(providerId)) return undefined;
89
89
 
90
+ // dynamic-import: cycle break -- opencode/provider transitively imports
91
+ // this module through the discovery helper; a static import deadlocks at
92
+ // load time.
90
93
  const { OPENCODE_FREE_SPEC } = await import("./integrations/opencode/provider");
91
94
  const spec = OPENCODE_FREE_SPEC;
92
95
  const source = probeRequest();