cartethyia 2.5.9 → 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.
- package/.env.example +7 -42
- package/README.md +11 -10
- package/dist/dashboard/assets/{BannedPage-Brvuj_Eb.js → BannedPage-Cd30Z0b9.js} +1 -1
- package/dist/dashboard/assets/BannedPage-Cd30Z0b9.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-CqfXtI3y.js → CliToolDetailPage-wf5u-ww6.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-wf5u-ww6.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-GQeS91bg.js → CliToolsPage-DykPvuck.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-DykPvuck.js.gz +0 -0
- package/dist/dashboard/assets/{CombosPage-BDRsTXBB.js → CombosPage-DwvSD3vs.js} +1 -1
- package/dist/dashboard/assets/CombosPage-DwvSD3vs.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-zP8AFHX0.js → ConsoleLogPage-CIr7KDex.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-CIr7KDex.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-BmfrNZ14.js → CustomizationPage-82X0DDdH.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-82X0DDdH.js.gz +0 -0
- package/dist/dashboard/assets/{HealthEventsModal-Dn3M6WZc.js → HealthEventsModal-BYPucTTn.js} +1 -1
- package/dist/dashboard/assets/HealthEventsModal-BYPucTTn.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-DoreIgm8.js → LoginPage-CS5mPuVF.js} +1 -1
- package/dist/dashboard/assets/LoginPage-CS5mPuVF.js.gz +0 -0
- package/dist/dashboard/assets/{ModelPicker-C7pDb41R.js → ModelPicker-C0UCUsVJ.js} +1 -1
- package/dist/dashboard/assets/ModelPicker-C0UCUsVJ.js.gz +0 -0
- package/dist/dashboard/assets/{OverviewPage-CvvD1Ugk.js → OverviewPage-Dk_ew3YU.js} +1 -1
- package/dist/dashboard/assets/OverviewPage-Dk_ew3YU.js.gz +0 -0
- package/dist/dashboard/assets/{ProviderDetailPage-Clbn1gsW.js → ProviderDetailPage-CAiRn2Q0.js} +1 -1
- package/dist/dashboard/assets/ProviderDetailPage-CAiRn2Q0.js.gz +0 -0
- package/dist/dashboard/assets/{ProvidersPage-BnoPgA7w.js → ProvidersPage-vdja5ZPK.js} +1 -1
- package/dist/dashboard/assets/ProvidersPage-vdja5ZPK.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-Bq_TGgdb.js → ProxyPage-BB4CNm4-.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-BB4CNm4-.js.gz +0 -0
- package/dist/dashboard/assets/{QuotaPage-D9DHXvom.js → QuotaPage-FEc4iNyq.js} +1 -1
- package/dist/dashboard/assets/QuotaPage-FEc4iNyq.js.gz +0 -0
- package/dist/dashboard/assets/{SettingsPage-7xV8WkWL.js → SettingsPage-Dlfi5L4N.js} +1 -1
- package/dist/dashboard/assets/SettingsPage-Dlfi5L4N.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-Day3mCOn.js → SetupPage-FadUOl9S.js} +1 -1
- package/dist/dashboard/assets/SetupPage-FadUOl9S.js.gz +0 -0
- package/dist/dashboard/assets/{SortableList-DQxllnB5.js → SortableList-Cfy6_Khv.js} +1 -1
- package/dist/dashboard/assets/SortableList-Cfy6_Khv.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-uMExoWu1.js → StudioPage-CM92fgJf.js} +1 -1
- package/dist/dashboard/assets/{StudioPage-uMExoWu1.js.gz → StudioPage-CM92fgJf.js.gz} +0 -0
- package/dist/dashboard/assets/{UsagePage-DXa1oR-4.js → UsagePage-BT4MyQeT.js} +1 -1
- package/dist/dashboard/assets/UsagePage-BT4MyQeT.js.gz +0 -0
- package/dist/dashboard/assets/{app-BIt446yE.js → app-B7pVRhJ1.js} +1 -1
- package/dist/dashboard/assets/{app-BIt446yE.js.gz → app-B7pVRhJ1.js.gz} +0 -0
- package/dist/dashboard/assets/{badge-CR72dasT.js → badge-Bvyr7D0u.js} +1 -1
- package/dist/dashboard/assets/badge-Bvyr7D0u.js.gz +0 -0
- package/dist/dashboard/assets/{banner-CI9_eSfO.js → banner-DIvKAZih.js} +1 -1
- package/dist/dashboard/assets/banner-DIvKAZih.js.gz +0 -0
- package/dist/dashboard/assets/{card-DS7CQEsO.js → card-D5_gYIS_.js} +1 -1
- package/dist/dashboard/assets/card-D5_gYIS_.js.gz +0 -0
- package/dist/dashboard/assets/{clipboard-button-611pSsaX.js → clipboard-button-B6vDBtbm.js} +1 -1
- package/dist/dashboard/assets/clipboard-button-B6vDBtbm.js.gz +0 -0
- package/dist/dashboard/assets/{dialog-k37exjNt.js → dialog-CpjrgdwJ.js} +1 -1
- package/dist/dashboard/assets/dialog-CpjrgdwJ.js.gz +0 -0
- package/dist/dashboard/assets/{drawer-CX7N8ucR.js → drawer-BWmt3b5y.js} +1 -1
- package/dist/dashboard/assets/drawer-BWmt3b5y.js.gz +0 -0
- package/dist/dashboard/assets/{entry-B9Xvtnfj.js → entry-B-gvimrg.js} +1 -1
- package/dist/dashboard/assets/entry-B-gvimrg.js.gz +0 -0
- package/dist/dashboard/assets/{entry-CTP8AyiS.js → entry-C_oakV3z.js} +1 -1
- package/dist/dashboard/assets/entry-C_oakV3z.js.gz +0 -0
- package/dist/dashboard/assets/{entry-ByMGkR3C.js → entry-Dj0cHfEc.js} +3 -3
- package/dist/dashboard/assets/entry-Dj0cHfEc.js.gz +0 -0
- package/dist/dashboard/assets/{github-badge-sltk1qUi.js → github-badge-RRHHWGxh.js} +1 -1
- package/dist/dashboard/assets/github-badge-RRHHWGxh.js.gz +0 -0
- package/dist/dashboard/assets/{index-z3zDOSMM.js → index-Bhey_rg_.js} +2 -2
- package/dist/dashboard/assets/index-Bhey_rg_.js.gz +0 -0
- package/dist/dashboard/assets/{inline-BhY2sSnO.js → inline-C2_EQ5Uf.js} +1 -1
- package/dist/dashboard/assets/inline-C2_EQ5Uf.js.gz +0 -0
- package/dist/dashboard/assets/{input-V1umFiBk.js → input-BMRlQ450.js} +1 -1
- package/dist/dashboard/assets/input-BMRlQ450.js.gz +0 -0
- package/dist/dashboard/assets/{layout-BBOYycyS.js → layout-XR5xP8ew.js} +1 -1
- package/dist/dashboard/assets/layout-XR5xP8ew.js.gz +0 -0
- package/dist/dashboard/assets/{list-row-1zzZYM0B.js → list-row-Cw07dioc.js} +1 -1
- package/dist/dashboard/assets/list-row-Cw07dioc.js.gz +0 -0
- package/dist/dashboard/assets/{numbers-DkfMR5Qs.js → numbers-DrdA9oSM.js} +1 -1
- package/dist/dashboard/assets/numbers-DrdA9oSM.js.gz +0 -0
- package/dist/dashboard/assets/{select-C6MMiaio.js → select-CxVVB__N.js} +1 -1
- package/dist/dashboard/assets/select-CxVVB__N.js.gz +0 -0
- package/dist/dashboard/assets/{stack-BHTfXdz_.js → stack-uPOwM9Hs.js} +1 -1
- package/dist/dashboard/assets/stack-uPOwM9Hs.js.gz +0 -0
- package/dist/dashboard/assets/{state-mPDRlQkl.js → state-D1Yz79iL.js} +1 -1
- package/dist/dashboard/assets/state-D1Yz79iL.js.gz +0 -0
- package/dist/dashboard/assets/{switch-DOmJxg7H.js → switch-sevsRrRo.js} +1 -1
- package/dist/dashboard/assets/switch-sevsRrRo.js.gz +0 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +40 -40
- package/package.json +1 -3
- package/scripts/cli/admin.ts +3 -0
- package/scripts/cli/console-menu.ts +299 -275
- package/scripts/cli/doctor.ts +1 -1
- package/scripts/cli/gateway.ts +1 -2
- package/scripts/{health.ts → cli/health.ts} +4 -4
- package/scripts/cli/main.ts +3 -0
- package/scripts/cli/prompt.ts +137 -107
- package/scripts/cli/start.ts +3 -0
- package/scripts/cli/tray.ts +167 -208
- package/src/config/package-paths.ts +24 -0
- package/src/console/remote-support/service.ts +270 -114
- package/src/console/routing/pools/store.ts +1 -1
- package/src/console/updates/repository-updates.ts +40 -39
- package/src/observability/event-day-index.ts +1 -2
- package/src/protocol/registry.ts +2 -0
- package/src/providers/default-registry.ts +4 -0
- package/src/providers/integrations/buddy/capabilities.ts +4 -0
- package/src/providers/integrations/github/github.ts +3 -1
- package/src/providers/integrations/opencode/provider.ts +2 -0
- package/src/providers/integrations/trae/trae-headers.ts +17 -48
- package/src/providers/integrations/trae/trae.ts +22 -24
- package/src/providers/provider-probe.ts +3 -0
- package/dist/dashboard/assets/BannedPage-Brvuj_Eb.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-CqfXtI3y.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-GQeS91bg.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-BDRsTXBB.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-zP8AFHX0.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-BmfrNZ14.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-Dn3M6WZc.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-DoreIgm8.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-C7pDb41R.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-CvvD1Ugk.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-Clbn1gsW.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-BnoPgA7w.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-Bq_TGgdb.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-D9DHXvom.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-7xV8WkWL.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-Day3mCOn.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-DQxllnB5.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-DXa1oR-4.js.gz +0 -0
- package/dist/dashboard/assets/badge-CR72dasT.js.gz +0 -0
- package/dist/dashboard/assets/banner-CI9_eSfO.js.gz +0 -0
- package/dist/dashboard/assets/card-DS7CQEsO.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-611pSsaX.js.gz +0 -0
- package/dist/dashboard/assets/dialog-k37exjNt.js.gz +0 -0
- package/dist/dashboard/assets/drawer-CX7N8ucR.js.gz +0 -0
- package/dist/dashboard/assets/entry-B9Xvtnfj.js.gz +0 -0
- package/dist/dashboard/assets/entry-ByMGkR3C.js.gz +0 -0
- package/dist/dashboard/assets/entry-CTP8AyiS.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-sltk1qUi.js.gz +0 -0
- package/dist/dashboard/assets/index-z3zDOSMM.js.gz +0 -0
- package/dist/dashboard/assets/inline-BhY2sSnO.js.gz +0 -0
- package/dist/dashboard/assets/input-V1umFiBk.js.gz +0 -0
- package/dist/dashboard/assets/layout-BBOYycyS.js.gz +0 -0
- package/dist/dashboard/assets/list-row-1zzZYM0B.js.gz +0 -0
- package/dist/dashboard/assets/numbers-DkfMR5Qs.js.gz +0 -0
- package/dist/dashboard/assets/select-C6MMiaio.js.gz +0 -0
- package/dist/dashboard/assets/stack-BHTfXdz_.js.gz +0 -0
- package/dist/dashboard/assets/state-mPDRlQkl.js.gz +0 -0
- package/dist/dashboard/assets/switch-DOmJxg7H.js.gz +0 -0
- package/scripts/build/aot.ts +0 -143
- package/scripts/build/build.ts +0 -24
- package/scripts/build/compile.ts +0 -88
- package/scripts/build/restart.ts +0 -120
- package/scripts/build/start.ts +0 -25
|
@@ -401,6 +401,8 @@ export async function discoverOpenCodeFreeModels(options: {
|
|
|
401
401
|
readonly baseUrl: string;
|
|
402
402
|
readonly fetcher?: typeof fetch;
|
|
403
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.
|
|
404
406
|
const { fetchOpenAICompatibleModels } = await import("../../discovery/openai-model-discovery");
|
|
405
407
|
const listed = await fetchOpenAICompatibleModels({
|
|
406
408
|
baseUrl: options.baseUrl,
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
// Trae request headers: auth + device fingerprint.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
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
|
-
//
|
|
10
|
-
//
|
|
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
|
|
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
|
|
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":
|
|
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
|
|
5
|
-
//
|
|
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"
|
|
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
|
-
|
|
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 =
|
|
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 {
|
|
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,
|
|
@@ -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();
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/scripts/build/aot.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Elysia AOT build script — Requirement 181, 182
|
|
3
|
-
*
|
|
4
|
-
* This script performs ahead-of-time compilation of the Elysia application,
|
|
5
|
-
* precompiling route handlers, TypeBox schemas, and default-value merging at
|
|
6
|
-
* build time. The precompiled result is loaded at runtime, eliminating
|
|
7
|
-
* repeated compilation on startup.
|
|
8
|
-
*
|
|
9
|
-
* Usage: bun run scripts/build/aot.ts
|
|
10
|
-
* Output: dist/ with compiled artifact ready for Bun.build --compile
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { aot } from "elysia/plugin/aot/bun";
|
|
14
|
-
|
|
15
|
-
const typeboxCompileBridge = {
|
|
16
|
-
name: "cartethyia-elysia-typebox-compile",
|
|
17
|
-
setup(build: {
|
|
18
|
-
onLoad: (
|
|
19
|
-
options: { filter: RegExp },
|
|
20
|
-
callback: (args: { path: string }) => Promise<{ contents: string; loader: "js" }>,
|
|
21
|
-
) => void;
|
|
22
|
-
}): void {
|
|
23
|
-
build.onLoad(
|
|
24
|
-
{ filter: /[\\/]elysia[\\/]dist[\\/]type[\\/]validator[\\/]index\.js$/ },
|
|
25
|
-
async ({ path }) => {
|
|
26
|
-
const contents = await Bun.file(path).text();
|
|
27
|
-
return {
|
|
28
|
-
contents: contents.replaceAll(
|
|
29
|
-
"SchemaCompile(this.schema)",
|
|
30
|
-
"SchemaCompile({}, this.schema)",
|
|
31
|
-
),
|
|
32
|
-
loader: "js",
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Bun.build configuration for AOT compilation (Requirement 181.4).
|
|
41
|
-
*/
|
|
42
|
-
interface BuildConfig {
|
|
43
|
-
entrypoints: string[];
|
|
44
|
-
outdir: string;
|
|
45
|
-
target: string;
|
|
46
|
-
plugins: unknown[];
|
|
47
|
-
/** Compile-time constant substitution, e.g. baking `process.env.NODE_ENV`. */
|
|
48
|
-
define: Record<string, string>;
|
|
49
|
-
/** Keep Elysia on its ESM build so its TypeBox bridge is statically bundled. */
|
|
50
|
-
alias: Record<string, string>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Bun.build result structure with diagnostics.
|
|
55
|
-
*/
|
|
56
|
-
interface BuildResult {
|
|
57
|
-
logs: Array<{ message: string }>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Core AOT build logic, exported for testing.
|
|
62
|
-
* Compiles route handlers and schemas; fails if diagnostics are emitted.
|
|
63
|
-
* Terminates the process explicitly after completion.
|
|
64
|
-
*
|
|
65
|
-
* @param buildFn - Function to call Bun.build (injected for testing)
|
|
66
|
-
* @param exitFn - Function to call process.exit (injected for testing)
|
|
67
|
-
*/
|
|
68
|
-
export async function buildAOT(
|
|
69
|
-
buildFn: (config: BuildConfig) => Promise<BuildResult> = Bun.build as unknown as (
|
|
70
|
-
config: BuildConfig
|
|
71
|
-
) => Promise<BuildResult>,
|
|
72
|
-
exitFn: (code: number) => never = process.exit as unknown as (code: number) => never,
|
|
73
|
-
): Promise<void> {
|
|
74
|
-
// Bun bakes `process.env.NODE_ENV` into the output as a literal, so the value
|
|
75
|
-
// substituted here is the value every consumer of `dist/main.js` sees forever
|
|
76
|
-
// after. `production` is required so the logger does not attach the
|
|
77
|
-
// `pino-pretty` transport: that transport spawns a worker thread which loads
|
|
78
|
-
// `real-require`, not present in a standalone executable, so a development
|
|
79
|
-
// build bundles a logger that crashes on first use. The migrations folder is
|
|
80
|
-
// not part of this decision — `resolveMigrationsFolder()` resolves
|
|
81
|
-
// `<cwd>/migrations` unconditionally and fails loudly when it is missing.
|
|
82
|
-
//
|
|
83
|
-
// Substituted through `define` rather than by assigning `process.env`, because
|
|
84
|
-
// this module is imported by tests that run in the same process as everything
|
|
85
|
-
// else — mutating the environment here would flip `NODE_ENV` for every later
|
|
86
|
-
// suite in that process. `scripts/build/compile.ts` passes the same define.
|
|
87
|
-
try {
|
|
88
|
-
const result = await buildFn({
|
|
89
|
-
entrypoints: ["src/main.ts"],
|
|
90
|
-
outdir: "dist",
|
|
91
|
-
target: "bun",
|
|
92
|
-
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
93
|
-
plugins: [typeboxCompileBridge, aot("src/main.ts", { strip: false })],
|
|
94
|
-
alias: { elysia: "elysia/dist/index.mjs" },
|
|
95
|
-
// `strip: false` keeps the runtime handler JIT reachable. The default
|
|
96
|
-
// `'auto'` stubs it out whenever its frozen replay proves no route needs
|
|
97
|
-
// it, but this application registers routes whose handlers are not all
|
|
98
|
-
// reconstructable from the frozen manifest — with the stub in place, the
|
|
99
|
-
// first request to such a route throws "handler compiler JIT was stripped
|
|
100
|
-
// (strip mode) but a route needed runtime compilation" and the listener
|
|
101
|
-
// never comes up. Stripping also collapses TypeBox, which is what makes
|
|
102
|
-
// a compiled binary fail on a bare `require("typebox/type")`; keeping the
|
|
103
|
-
// JIT present keeps TypeBox wired the ordinary way.
|
|
104
|
-
});
|
|
105
|
-
const outputPath = "dist/main.js";
|
|
106
|
-
const outputFile = Bun.file(outputPath);
|
|
107
|
-
if (await outputFile.exists()) {
|
|
108
|
-
const output = await outputFile.text();
|
|
109
|
-
const patchedOutput = output
|
|
110
|
-
.replaceAll("Compile2(this.schema)", "Compile2({}, this.schema)")
|
|
111
|
-
.replaceAll(
|
|
112
|
-
"this.tb.buildResult.external.variables.some(isAsyncPredicate)",
|
|
113
|
-
"(this.tb.buildResult?.external?.variables ?? []).some(isAsyncPredicate)",
|
|
114
|
-
);
|
|
115
|
-
await Bun.write(outputPath, patchedOutput);
|
|
116
|
-
}
|
|
117
|
-
// Treat any diagnostics (warnings or errors) as build failures
|
|
118
|
-
if (result.logs.length > 0) {
|
|
119
|
-
for (const log of result.logs) {
|
|
120
|
-
console.error(`[AOT diagnostic] ${log.message}`);
|
|
121
|
-
}
|
|
122
|
-
// Fail the build if diagnostics were emitted
|
|
123
|
-
exitFn(1);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
console.log("[AOT] Build succeeded; precompiled manifest ready");
|
|
127
|
-
} catch (error) {
|
|
128
|
-
console.error("[AOT] Build failed:", error);
|
|
129
|
-
exitFn(1);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Terminate immediately after successful build. Do not wait for any
|
|
133
|
-
// long-running resources (DB pools, Redis clients) that may have been
|
|
134
|
-
// initialized during the dry-run phase (Requirement 181.6).
|
|
135
|
-
exitFn(0);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (import.meta.main) {
|
|
139
|
-
buildAOT().catch(() => {
|
|
140
|
-
// Already handled by exitFn; this catch is just for safety.
|
|
141
|
-
process.exit(1);
|
|
142
|
-
});
|
|
143
|
-
}
|
package/scripts/build/build.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
|
|
3
|
-
const projectRoot = resolve(import.meta.dir, "..", "..");
|
|
4
|
-
const steps = [
|
|
5
|
-
{ label: "Dashboard", args: ["run", "dashboard:build"] },
|
|
6
|
-
{ label: "AOT", args: ["run", "build:aot"] },
|
|
7
|
-
{ label: "Standalone binary", args: ["run", "build:binary"] },
|
|
8
|
-
] as const;
|
|
9
|
-
|
|
10
|
-
for (const step of steps) {
|
|
11
|
-
console.log(`[build] ${step.label}`);
|
|
12
|
-
const child = Bun.spawn(["bun", ...step.args], {
|
|
13
|
-
cwd: projectRoot,
|
|
14
|
-
stdin: "inherit",
|
|
15
|
-
stdout: "inherit",
|
|
16
|
-
stderr: "inherit",
|
|
17
|
-
});
|
|
18
|
-
const exitCode = await child.exited;
|
|
19
|
-
if (exitCode !== 0) {
|
|
20
|
-
console.error(`[build] ${step.label} failed with exit code ${exitCode}`);
|
|
21
|
-
process.exitCode = exitCode;
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
}
|
package/scripts/build/compile.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compiles the standalone gateway binary from the AOT build output.
|
|
3
|
-
*
|
|
4
|
-
* Two things here are load-bearing and neither is obvious:
|
|
5
|
-
*
|
|
6
|
-
* 1. **The entry is `dist/main.js`, not `src/main.ts`.** `aot.ts` runs
|
|
7
|
-
* Elysia's AOT plugin, which rewrites TypeBox imports into statically wired
|
|
8
|
-
* mirrors in its output. Bundling the raw source instead discards that work,
|
|
9
|
-
* and Elysia's CommonJS build reaches TypeBox through a lazy
|
|
10
|
-
* `require("typebox/type")` that the bundler cannot follow — the compiled
|
|
11
|
-
* binary then dies at startup with `Cannot find module 'typebox/type'`,
|
|
12
|
-
* because a standalone executable has no node_modules to resolve against.
|
|
13
|
-
*
|
|
14
|
-
* 2. **`NODE_ENV` is set to `production` here, at build time, because Bun bakes
|
|
15
|
-
* it into the binary.** `bun build --compile` replaces `process.env.NODE_ENV`
|
|
16
|
-
* with a literal, so the value present when this runs is the value the
|
|
17
|
-
* binary reports forever after — a runtime `NODE_ENV=production` cannot
|
|
18
|
-
* change it. What depends on it is the logger: the `pino-pretty` transport
|
|
19
|
-
* is attached only in development, and that transport spawns a worker thread
|
|
20
|
-
* loading `real-require`, which a standalone executable does not carry. A
|
|
21
|
-
* binary built without this line therefore bundles a logger that crashes on
|
|
22
|
-
* first use. The migrations folder is not part of this decision —
|
|
23
|
-
* `resolveMigrationsFolder()` resolves `<cwd>/migrations` unconditionally.
|
|
24
|
-
*
|
|
25
|
-
* Usage: `bun run scripts/build/compile.ts [--outfile dist/cartethyia]`
|
|
26
|
-
*/
|
|
27
|
-
const DEFAULT_OUTFILE = "dist/cartethyia";
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The artifact path `bun build --compile` actually writes for `outfile`.
|
|
31
|
-
*
|
|
32
|
-
* Bun appends `.exe` when it compiles for Windows, so the extensionless
|
|
33
|
-
* `dist/cartethyia` handed to it never exists on that platform. This is the one
|
|
34
|
-
* place that knows where the compiled binary lands; `start-production.ts`
|
|
35
|
-
* resolves its target from here instead of re-deriving the name, because a
|
|
36
|
-
* launcher that probed the requested path reported "run bun run build first"
|
|
37
|
-
* immediately after a successful build.
|
|
38
|
-
*/
|
|
39
|
-
export function compiledBinaryPath(outfile: string = DEFAULT_OUTFILE): string {
|
|
40
|
-
return process.platform === "win32" && !outfile.toLowerCase().endsWith(".exe")
|
|
41
|
-
? `${outfile}.exe`
|
|
42
|
-
: outfile;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Reads `--outfile <path>`, falling back to a positional path or the default. */
|
|
46
|
-
export function resolveOutfile(argv: readonly string[]): string {
|
|
47
|
-
const flag = argv.indexOf("--outfile");
|
|
48
|
-
if (flag !== -1) {
|
|
49
|
-
const value = argv[flag + 1];
|
|
50
|
-
if (value === undefined || value.length === 0) {
|
|
51
|
-
throw new Error("--outfile requires a path");
|
|
52
|
-
}
|
|
53
|
-
return value;
|
|
54
|
-
}
|
|
55
|
-
return argv.find((arg) => arg.length > 0 && !arg.startsWith("-")) ?? DEFAULT_OUTFILE;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function buildBinary(
|
|
59
|
-
outfile: string = DEFAULT_OUTFILE,
|
|
60
|
-
buildFn: typeof Bun.build = Bun.build,
|
|
61
|
-
): Promise<void> {
|
|
62
|
-
// Baked into the output; see the note above before changing it. Substituted
|
|
63
|
-
// through `define` rather than by assigning `process.env`, because this module
|
|
64
|
-
// is imported by tests in the same process — mutating the environment would
|
|
65
|
-
// flip `NODE_ENV` for every later suite in that process.
|
|
66
|
-
const result = await buildFn({
|
|
67
|
-
entrypoints: ["dist/main.js"],
|
|
68
|
-
minify: true,
|
|
69
|
-
target: "bun",
|
|
70
|
-
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
71
|
-
compile: {
|
|
72
|
-
outfile,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
if (result.logs.length > 0) {
|
|
77
|
-
for (const log of result.logs) console.error(`[binary] ${log.message}`);
|
|
78
|
-
throw new Error(`binary build emitted ${result.logs.length} diagnostic(s)`);
|
|
79
|
-
}
|
|
80
|
-
console.log(`[binary] compiled ${compiledBinaryPath(outfile)}`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (import.meta.main) {
|
|
84
|
-
await buildBinary(resolveOutfile(process.argv.slice(2))).catch((error: unknown) => {
|
|
85
|
-
console.error("[binary] build failed:", error);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
});
|
|
88
|
-
}
|