dsh-connect-trae 1.4.2 → 2.0.0
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/CHANGELOG.md +37 -0
- package/README.en.md +15 -9
- package/README.md +15 -9
- package/lib/client.js +268 -76
- package/lib/index.d.ts +345 -51
- package/lib/index.js +781 -234
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -33,6 +33,62 @@ interface TraeDiscoveredModel {
|
|
|
33
33
|
/** Parse only capabilities explicitly advertised by Trae's remote model API. */
|
|
34
34
|
declare function parseTraeRemoteModel(value: unknown): TraeDiscoveredModel | undefined;
|
|
35
35
|
//#endregion
|
|
36
|
+
//#region src/paths.d.ts
|
|
37
|
+
type TraeEdition = 'cn' | 'sg' | 'solo' | 'solo-sg';
|
|
38
|
+
/**
|
|
39
|
+
* Where a local sign-in was persisted. `desktop` candidates hold an Electron
|
|
40
|
+
* `globalStorage/storage.json` whose auth value is encrypted; `cli` candidates
|
|
41
|
+
* hold a bare JWT written by the Trae CLI, which needs no decryption.
|
|
42
|
+
*/
|
|
43
|
+
type TraeCredentialSource = 'desktop' | 'cli';
|
|
44
|
+
interface TraeStorageCandidate {
|
|
45
|
+
edition: TraeEdition;
|
|
46
|
+
path: string;
|
|
47
|
+
source: TraeCredentialSource;
|
|
48
|
+
}
|
|
49
|
+
declare function traeStorageCandidates(platform?: NodeJS.Platform, home?: string, env?: NodeJS.ProcessEnv): TraeStorageCandidate[];
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/region.d.ts
|
|
52
|
+
/** Storage/routing bucket: the CN service or the international (ai) service. */
|
|
53
|
+
type TraeRegion = 'cn' | 'ai';
|
|
54
|
+
/** One region's upstream gateway bases. */
|
|
55
|
+
interface TraeRegionGateways {
|
|
56
|
+
/** Chat + agent API base (the `llm_utils_chat` / raw-chat family). */
|
|
57
|
+
readonly chat: string;
|
|
58
|
+
/** SOLO remote model directory base (`/api/remote/v1`). */
|
|
59
|
+
readonly remote: string;
|
|
60
|
+
/** Pay/status API base; the credential's own host is preferred when known. */
|
|
61
|
+
readonly pay: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Verified gateway bases per region (docs/INTL_SG_EVIDENCE.md §2).
|
|
65
|
+
* The AI gateway is shared by both international installs (Trae desktop and
|
|
66
|
+
* TRAE SOLO); its mchost shards (`api16/api22-normal-alisg.mchost.guru`)
|
|
67
|
+
* answer the same bytes but stay internal — `coresg-normal.trae.ai` is the
|
|
68
|
+
* single stable entry point.
|
|
69
|
+
*/
|
|
70
|
+
declare const REGION_GATEWAYS: Readonly<Record<TraeRegion, TraeRegionGateways>>;
|
|
71
|
+
/** Region for an edition label: the international installs belong to `ai`. */
|
|
72
|
+
declare function regionOfEdition(edition: TraeEdition): TraeRegion;
|
|
73
|
+
/**
|
|
74
|
+
* Region from the credential's `userRegion` claim. The desktop storage spells
|
|
75
|
+
* it as an object (`{"region":"CN","_aiRegion":"CN"}`); the app logs also
|
|
76
|
+
* spell the bare value lowercase (`"sg"`). Both are accepted, case-blind.
|
|
77
|
+
*/
|
|
78
|
+
declare function regionOfUserRegion(value: unknown): TraeRegion | undefined;
|
|
79
|
+
/** Region from a credential host (`.trae.ai` → ai, `.trae.cn`/`.trae.com.cn` → cn). */
|
|
80
|
+
declare function regionOfHost(host: string | undefined): TraeRegion | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Region of a credential: the `userRegion` claim wins, the host suffix is the
|
|
83
|
+
* fallback, and the edition label is the last resort. Every level is derived
|
|
84
|
+
* from data the credential itself carries, so no user configuration is needed.
|
|
85
|
+
*/
|
|
86
|
+
declare function regionOfCredential(credential: {
|
|
87
|
+
edition: TraeEdition;
|
|
88
|
+
host?: string;
|
|
89
|
+
userRegion?: string;
|
|
90
|
+
}): TraeRegion;
|
|
91
|
+
//#endregion
|
|
36
92
|
//#region src/catalog.d.ts
|
|
37
93
|
type TraeInputModality = 'text' | 'image';
|
|
38
94
|
/**
|
|
@@ -56,6 +112,21 @@ interface TraeModelInfo {
|
|
|
56
112
|
}
|
|
57
113
|
/** Bootstrap catalog: identity only where current Trae metadata has not been fetched yet. */
|
|
58
114
|
declare const FALLBACK_TRAE_MODELS: readonly TraeModelInfo[];
|
|
115
|
+
/**
|
|
116
|
+
* Bootstrap catalog for the international (ai) region, captured from the
|
|
117
|
+
* live `coresg-normal.trae.ai/api/remote/v1/models` directory on 2026-09-15
|
|
118
|
+
* (docs/INTL_SG_EVIDENCE.md §3). The two rosters barely overlap (the CN list
|
|
119
|
+
* has no Gemini/GPT/MiniMax entries), so an international account must never
|
|
120
|
+
* be seeded with the CN list. Like the CN fallback it is replaced by the live
|
|
121
|
+
* refresh; image input stays the user's explicit opt-in (`imageModelIds`).
|
|
122
|
+
*/
|
|
123
|
+
declare const FALLBACK_TRAE_MODELS_AI: readonly TraeModelInfo[];
|
|
124
|
+
/**
|
|
125
|
+
* Static fallback directory for a region. Each region keeps its own model
|
|
126
|
+
* slot in settings; the fallback must match the region so an account never
|
|
127
|
+
* shows the other region's roster.
|
|
128
|
+
*/
|
|
129
|
+
declare function fallbackModelsFor(region: TraeRegion): readonly TraeModelInfo[];
|
|
59
130
|
/** Exact DSH modalities for one catalog entry; absent metadata is text-only. */
|
|
60
131
|
declare function traeInputModalities(model: Pick<TraeModelInfo, 'input'>): TraeInputModality[];
|
|
61
132
|
/**
|
|
@@ -127,6 +198,12 @@ declare function sanitizeCatalog(catalog: readonly TraeModelInfo[]): TraeModelIn
|
|
|
127
198
|
declare function deriveCatalog(catalog: readonly TraeModelInfo[], enabled: ReadonlySet<string>, budgets?: Readonly<Record<string, TraeContextBudget | undefined>>): TraeModelInfo[];
|
|
128
199
|
declare class TraeCatalog {
|
|
129
200
|
private models;
|
|
201
|
+
/**
|
|
202
|
+
* @param region Seeds the static fallback for this region; each region's
|
|
203
|
+
* provider must never serve the other region's roster before its first live
|
|
204
|
+
* refresh lands.
|
|
205
|
+
*/
|
|
206
|
+
constructor(region?: TraeRegion);
|
|
130
207
|
current(): readonly TraeModelInfo[];
|
|
131
208
|
set(models: readonly TraeModelInfo[]): void;
|
|
132
209
|
}
|
|
@@ -172,11 +249,28 @@ interface TraeShimOptions {
|
|
|
172
249
|
declare function createTraeShim(options: TraeShimOptions): TraeShim;
|
|
173
250
|
//#endregion
|
|
174
251
|
//#region src/adapter.d.ts
|
|
252
|
+
/** Provider route this bundle owns for the domestic (CN) gateway. */
|
|
175
253
|
declare const TRAE_PROVIDER = "trae";
|
|
254
|
+
/**
|
|
255
|
+
* Provider route this bundle owns for the international (trae.ai) gateway.
|
|
256
|
+
* Named `-global` to match the plugin family's convention (`workbuddy-global`);
|
|
257
|
+
* the internal region bucket stays `ai`, which is the gateway/protocol name.
|
|
258
|
+
*/
|
|
259
|
+
declare const TRAE_AI_PROVIDER = "trae-global";
|
|
260
|
+
/** The provider id each region registers as. */
|
|
261
|
+
declare const TRAE_PROVIDERS: Readonly<Record<TraeRegion, string>>;
|
|
262
|
+
/** Human-readable provider names, shown in the DSH model picker. */
|
|
263
|
+
declare const TRAE_PROVIDER_DISPLAY_NAMES: Readonly<Record<TraeRegion, string>>;
|
|
264
|
+
/** Region a provider route id belongs to. */
|
|
265
|
+
declare function regionOfTraeProvider(provider: string): TraeRegion | undefined;
|
|
176
266
|
declare const TRAE_STREAM_IDLE_TIMEOUT_MS = 300000;
|
|
177
267
|
interface TraeAdapterOptions {
|
|
178
268
|
shim: TraeShim;
|
|
179
269
|
catalog: TraeCatalog;
|
|
270
|
+
/** Provider route id this instance serves; defaults to the CN route. */
|
|
271
|
+
provider?: string;
|
|
272
|
+
/** pi-ai provider name and profile display name; defaults to the CN name. */
|
|
273
|
+
displayName?: string;
|
|
180
274
|
resolveAttachments?: () => AttachmentStore | undefined;
|
|
181
275
|
}
|
|
182
276
|
interface TraeAdapter {
|
|
@@ -185,21 +279,6 @@ interface TraeAdapter {
|
|
|
185
279
|
}
|
|
186
280
|
declare function createTraeAdapter(options: TraeAdapterOptions): TraeAdapter;
|
|
187
281
|
//#endregion
|
|
188
|
-
//#region src/paths.d.ts
|
|
189
|
-
type TraeEdition = 'cn' | 'sg' | 'solo' | 'solo-sg';
|
|
190
|
-
/**
|
|
191
|
-
* Where a local sign-in was persisted. `desktop` candidates hold an Electron
|
|
192
|
-
* `globalStorage/storage.json` whose auth value is encrypted; `cli` candidates
|
|
193
|
-
* hold a bare JWT written by the Trae CLI, which needs no decryption.
|
|
194
|
-
*/
|
|
195
|
-
type TraeCredentialSource = 'desktop' | 'cli';
|
|
196
|
-
interface TraeStorageCandidate {
|
|
197
|
-
edition: TraeEdition;
|
|
198
|
-
path: string;
|
|
199
|
-
source: TraeCredentialSource;
|
|
200
|
-
}
|
|
201
|
-
declare function traeStorageCandidates(platform?: NodeJS.Platform, home?: string, env?: NodeJS.ProcessEnv): TraeStorageCandidate[];
|
|
202
|
-
//#endregion
|
|
203
282
|
//#region src/auth.d.ts
|
|
204
283
|
interface TraeCredential {
|
|
205
284
|
accessToken: string;
|
|
@@ -207,6 +286,12 @@ interface TraeCredential {
|
|
|
207
286
|
userId: string;
|
|
208
287
|
accountName?: string;
|
|
209
288
|
host: string;
|
|
289
|
+
/**
|
|
290
|
+
* Region claim from the decrypted storage document (`userRegion.region`,
|
|
291
|
+
* 'CN' | 'SG', possibly lowercase). Drives the routing bucket together with
|
|
292
|
+
* `host`; see `regionOfCredential`.
|
|
293
|
+
*/
|
|
294
|
+
userRegion?: string;
|
|
210
295
|
expiresAtMs: number;
|
|
211
296
|
refreshExpiresAtMs?: number;
|
|
212
297
|
edition: TraeEdition;
|
|
@@ -224,6 +309,14 @@ interface TraeCredentialStoreOptions {
|
|
|
224
309
|
edition?: TraeEdition | 'auto';
|
|
225
310
|
accountId?: string;
|
|
226
311
|
ownPath?: string;
|
|
312
|
+
/**
|
|
313
|
+
* Region this store serves. When set, only credentials whose own claim maps
|
|
314
|
+
* to this region are discovered, selected, or refreshed — the two regions'
|
|
315
|
+
* stores run side by side without seeing each other's accounts.
|
|
316
|
+
*/
|
|
317
|
+
region?: TraeRegion;
|
|
318
|
+
/** Legacy single-copy path read as a migration source; injectable for tests. */
|
|
319
|
+
legacyOwnPath?: string;
|
|
227
320
|
refresh: (credential: TraeCredential) => Promise<TraeRefreshOutcome>;
|
|
228
321
|
refreshMarginMs?: number;
|
|
229
322
|
}
|
|
@@ -231,6 +324,8 @@ interface TraeAccountChoice {
|
|
|
231
324
|
id: string;
|
|
232
325
|
accountName: string;
|
|
233
326
|
edition: TraeEdition;
|
|
327
|
+
/** Routing bucket of this account (`cn` | `ai`), derived from its credential. */
|
|
328
|
+
region: TraeRegion;
|
|
234
329
|
source: 'desktop' | 'dsh' | 'cli';
|
|
235
330
|
tokenExpiresAtMs: number;
|
|
236
331
|
selected: boolean;
|
|
@@ -246,17 +341,50 @@ interface TraeCandidateFailure {
|
|
|
246
341
|
reason: 'missing' | 'unreadable' | 'invalid';
|
|
247
342
|
message?: string;
|
|
248
343
|
}
|
|
249
|
-
|
|
344
|
+
/**
|
|
345
|
+
* Plugin-owned copy path for one region. Each region's store refreshes into
|
|
346
|
+
* its own file so two simultaneously signed-in regions never overwrite each
|
|
347
|
+
* other's refreshed token.
|
|
348
|
+
*/
|
|
349
|
+
declare function traeOwnAuthPath(region: TraeRegion): string;
|
|
350
|
+
/**
|
|
351
|
+
* Pre-dual-provider single-copy path. Still read as a migration source (a
|
|
352
|
+
* legacy credential serves the region it belongs to until that region's own
|
|
353
|
+
* first refresh writes the per-region file), and removed by `logout`.
|
|
354
|
+
*/
|
|
355
|
+
declare function legacyTraeOwnAuthPath(): string;
|
|
250
356
|
declare function normalizeTraeCredential(raw: unknown, edition: TraeEdition, source: TraeCredential['source']): TraeCredential | undefined;
|
|
251
357
|
declare class TraeCredentialStore {
|
|
252
358
|
private storagePathOverride;
|
|
253
359
|
private edition;
|
|
254
360
|
private accountId;
|
|
255
|
-
private readonly
|
|
361
|
+
private readonly region;
|
|
362
|
+
private readonly ownPathExplicit;
|
|
363
|
+
private readonly legacyOwnPath;
|
|
364
|
+
private readonly legacyOwnPathExplicit;
|
|
256
365
|
private readonly refresh;
|
|
257
366
|
private readonly refreshMarginMs;
|
|
258
367
|
private inflight;
|
|
259
368
|
constructor(options: TraeCredentialStoreOptions);
|
|
369
|
+
/** Whether a credential's own claim belongs to this store's region. */
|
|
370
|
+
private matchesRegion;
|
|
371
|
+
/**
|
|
372
|
+
* The path this store refreshes into: the per-region file for a
|
|
373
|
+
* region-scoped store, the legacy single file otherwise, or an explicitly
|
|
374
|
+
* injected path in tests.
|
|
375
|
+
*/
|
|
376
|
+
ownAuthPath(): string;
|
|
377
|
+
/**
|
|
378
|
+
* Every plugin-owned copy to read, most preferred first. A region-scoped
|
|
379
|
+
* store reads the legacy single copy as its migration source (readAll's
|
|
380
|
+
* region filter drops it when it carries the other region's credential); an
|
|
381
|
+
* unscoped store reads everything so diagnostics see both regions.
|
|
382
|
+
*
|
|
383
|
+
* With an explicitly injected own path the legacy source is read ONLY when
|
|
384
|
+
* it was injected too — a test that pins one file must not accidentally see
|
|
385
|
+
* the real machine's legacy copy.
|
|
386
|
+
*/
|
|
387
|
+
private ownCandidates;
|
|
260
388
|
setSource(storagePath: string | undefined, edition?: TraeEdition | 'auto', accountId?: string): void;
|
|
261
389
|
selectAccount(accountId: string | undefined): void;
|
|
262
390
|
candidates(): TraeStorageCandidate[];
|
|
@@ -277,7 +405,20 @@ declare class TraeCredentialStore {
|
|
|
277
405
|
source?: TraeCredential['source'];
|
|
278
406
|
}>;
|
|
279
407
|
desktopFilePresent(): Promise<boolean>;
|
|
408
|
+
/**
|
|
409
|
+
* Remove every plugin-owned copy this store could read (per-region file,
|
|
410
|
+
* legacy single file, and their lock siblings); the desktop storage files
|
|
411
|
+
* are untouched. A region store's logout therefore also clears the legacy
|
|
412
|
+
* migration source — deliberate: `logout` is the user's "forget what the
|
|
413
|
+
* plugin stored" action, not a per-account toggle.
|
|
414
|
+
*/
|
|
280
415
|
logout(): Promise<void>;
|
|
416
|
+
/**
|
|
417
|
+
* Every local credential of this store's region, deduplicated by account id.
|
|
418
|
+
* A region-scoped store sees only its own region's credentials: the other
|
|
419
|
+
* region's accounts are invisible to selection, refresh, and status alike,
|
|
420
|
+
* which is what keeps the two regions' providers from cross-billing.
|
|
421
|
+
*/
|
|
281
422
|
private readAll;
|
|
282
423
|
/**
|
|
283
424
|
* Which paths were tried and why each one failed. Read-only and token-free:
|
|
@@ -292,7 +433,11 @@ declare class TraeCredentialStore {
|
|
|
292
433
|
/** Parse one candidate file's text into a credential, or throw. */
|
|
293
434
|
private credentialFrom;
|
|
294
435
|
private readDesktopAll;
|
|
295
|
-
|
|
436
|
+
/**
|
|
437
|
+
* Every readable plugin-owned copy, in candidate order; absent or corrupt
|
|
438
|
+
* files are skipped rather than propagated.
|
|
439
|
+
*/
|
|
440
|
+
private readOwns;
|
|
296
441
|
private refreshNow;
|
|
297
442
|
}
|
|
298
443
|
//#endregion
|
|
@@ -456,11 +601,19 @@ type TraeHeaderProfile = 'agent-task' | 'model-detail' | 'raw-chat' | 'native-cu
|
|
|
456
601
|
declare const TRAE_VERSION_CODE_FALLBACK = "20260716";
|
|
457
602
|
/** Keep a purely numeric build version; fall back when it cannot bind. */
|
|
458
603
|
declare function normalizeTraeVersionCode(buildVersion: string | undefined): string;
|
|
459
|
-
|
|
604
|
+
/**
|
|
605
|
+
* Headers shared by every Trae edition. The same shape is accepted by both
|
|
606
|
+
* gateways (verified read-only on the international gateway 2026-09-15,
|
|
607
|
+
* docs/INTL_SG_EVIDENCE.md §2.3: identical `x-app-id`, identity headers, and
|
|
608
|
+
* `Cloud-IDE-JWT` auth), so there is no per-edition branch any more.
|
|
609
|
+
*/
|
|
610
|
+
declare function buildTraeHeaders(credential: TraeCredential, identity: TraeIdentity, options?: {
|
|
460
611
|
appId?: string;
|
|
461
612
|
requestId?: string;
|
|
462
613
|
profile?: TraeHeaderProfile;
|
|
463
614
|
}): Record<string, string>;
|
|
615
|
+
/** Backwards-compatible alias; the headers are no longer CN-specific. */
|
|
616
|
+
declare const buildTraeCnHeaders: typeof buildTraeHeaders;
|
|
464
617
|
declare function traeEndpoint(baseUrl: string, path: string): string;
|
|
465
618
|
//#endregion
|
|
466
619
|
//#region src/raw-chat.d.ts
|
|
@@ -749,8 +902,18 @@ declare class TraeGatedUpstreamClient implements TraeUpstreamClient {
|
|
|
749
902
|
}
|
|
750
903
|
//#endregion
|
|
751
904
|
//#region src/refresh.d.ts
|
|
752
|
-
/**
|
|
753
|
-
|
|
905
|
+
/** Stable device identity for the DeviceInfo body, sourced from the app's own storage. */
|
|
906
|
+
interface TraeRefreshDevice {
|
|
907
|
+
deviceId: string;
|
|
908
|
+
machineId: string;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Exchange a refresh token for a fresh access token, following the calling
|
|
912
|
+
* edition's verified contract. `device` is only used by editions whose
|
|
913
|
+
* official client sends a DeviceInfo body; when it cannot be resolved the
|
|
914
|
+
* field is omitted rather than sent empty.
|
|
915
|
+
*/
|
|
916
|
+
declare function refreshTraeCredential(credential: TraeCredential, signal?: AbortSignal, device?: TraeRefreshDevice): Promise<TraeRefreshOutcome>;
|
|
754
917
|
//#endregion
|
|
755
918
|
//#region src/sse.d.ts
|
|
756
919
|
interface SseEvent {
|
|
@@ -874,11 +1037,13 @@ declare class TraeDelegatingUpstreamClient implements TraeUpstreamClient {
|
|
|
874
1037
|
/**
|
|
875
1038
|
* Read-only Trae usage/credits client.
|
|
876
1039
|
*
|
|
877
|
-
*
|
|
878
|
-
* `docs/USAGE_API_RESEARCH.md`)
|
|
879
|
-
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
1040
|
+
* CN sources the verified `api.trae.cn` pay/ug endpoints (see
|
|
1041
|
+
* `docs/USAGE_API_RESEARCH.md`); the international (ai) region is
|
|
1042
|
+
* subscription-based and reads `ide_user_pay_status` on its own gateway
|
|
1043
|
+
* (verified 2026-09-15, docs/INTL_SG_EVIDENCE.md §4). All queries are
|
|
1044
|
+
* read-only and do not consume Trae credits. The per-session consumption
|
|
1045
|
+
* detail table is deliberately not included: the endpoint returns no rows
|
|
1046
|
+
* for the current account, so we only expose what is actually retrievable.
|
|
882
1047
|
*/
|
|
883
1048
|
declare const TRAE_PAY_BASE = "https://api.trae.cn";
|
|
884
1049
|
interface TraeUsageOptions {
|
|
@@ -887,6 +1052,28 @@ interface TraeUsageOptions {
|
|
|
887
1052
|
baseUrl?: string;
|
|
888
1053
|
timeoutMs?: number;
|
|
889
1054
|
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Subscription/pay status of an international (ai) account, parsed from the
|
|
1057
|
+
* `ide_user_pay_status` answer. The international region has no Work-credit
|
|
1058
|
+
* packs, so this — not `snapshot` — is its usage surface.
|
|
1059
|
+
*/
|
|
1060
|
+
interface TraePayStatus {
|
|
1061
|
+
isDollarUsageBilling: boolean;
|
|
1062
|
+
hasPackage: boolean;
|
|
1063
|
+
isPayFreshman: boolean;
|
|
1064
|
+
inTrial: boolean;
|
|
1065
|
+
trialEndTimeMs: number;
|
|
1066
|
+
enableSoloLite: boolean;
|
|
1067
|
+
enableSoloBuilder: boolean;
|
|
1068
|
+
enableSoloCoder: boolean;
|
|
1069
|
+
enableSoloWeb: boolean;
|
|
1070
|
+
/** The fission (referral) program window and cap, when exposed. */
|
|
1071
|
+
fission?: {
|
|
1072
|
+
startTimeMs: number;
|
|
1073
|
+
expireTimeMs: number;
|
|
1074
|
+
maxUsage: number;
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
890
1077
|
interface TraeUsageSummary {
|
|
891
1078
|
totalAmount: number;
|
|
892
1079
|
consumedAmount: number;
|
|
@@ -940,8 +1127,29 @@ declare class TraeUsageClient {
|
|
|
940
1127
|
private readonly baseUrl;
|
|
941
1128
|
private readonly timeoutMs;
|
|
942
1129
|
constructor(options: TraeUsageOptions);
|
|
1130
|
+
/** Region of the current credential; `cn` when unresolvable. */
|
|
1131
|
+
private currentRegion;
|
|
1132
|
+
/**
|
|
1133
|
+
* Pay base for the current credential's region. An explicit baseUrl (tests,
|
|
1134
|
+
* diagnostics) pins the endpoint; otherwise CN uses `api.trae.cn` and the
|
|
1135
|
+
* international region its own verified pay gateway.
|
|
1136
|
+
*/
|
|
1137
|
+
private payBase;
|
|
943
1138
|
private authedHeaders;
|
|
944
1139
|
private post;
|
|
1140
|
+
/**
|
|
1141
|
+
* Subscription/pay status of an international (ai) account. The CN region
|
|
1142
|
+
* never calls this (its contract is unverified there); the ai region uses
|
|
1143
|
+
* this instead of the Work-credit `snapshot`.
|
|
1144
|
+
*/
|
|
1145
|
+
payStatus(signal?: AbortSignal): Promise<TraePayStatus>;
|
|
1146
|
+
/**
|
|
1147
|
+
* The Work-credit endpoints are CN-only. The international region is
|
|
1148
|
+
* subscription-based and must read {@link payStatus} instead; guarding here
|
|
1149
|
+
* keeps the card's degraded `creditsError` message diagnosable rather than
|
|
1150
|
+
* letting an ai credential hit an unverified path on its pay gateway.
|
|
1151
|
+
*/
|
|
1152
|
+
private requireCnRegion;
|
|
945
1153
|
/** Total entitlements / credits and per-pack breakdown. */
|
|
946
1154
|
snapshot(signal?: AbortSignal): Promise<TraeUsageSnapshot>;
|
|
947
1155
|
/** Daily check-in status. */
|
|
@@ -953,13 +1161,23 @@ declare class TraeUsageClient {
|
|
|
953
1161
|
}
|
|
954
1162
|
//#endregion
|
|
955
1163
|
//#region src/status-paths.d.ts
|
|
956
|
-
/**
|
|
957
|
-
* Node-free constants and types shared by the Host and browser halves.
|
|
958
|
-
* Mirrors the `dsh-workbuddy-connect` status-route pattern so the plugin card
|
|
959
|
-
* stays consistent with that project's external presentation.
|
|
960
|
-
*/
|
|
961
1164
|
/** Plugin-owned usage endpoint consumed by its browser half. */
|
|
962
1165
|
declare const TRAE_USAGE_PATH = "/plugins/dsh-connect-trae/usage";
|
|
1166
|
+
/** Query parameter naming the region a card request addresses. */
|
|
1167
|
+
declare const TRAE_REGION_PARAM = "region";
|
|
1168
|
+
/** Every region, in card tab order. */
|
|
1169
|
+
declare const TRAE_REGIONS: readonly TraeRegion[];
|
|
1170
|
+
/**
|
|
1171
|
+
* Address one region's status route. The two regions are separate provider
|
|
1172
|
+
* stacks; every card request carries the region whose tab the user is on.
|
|
1173
|
+
*/
|
|
1174
|
+
declare function withTraeRegion(path: string, region: TraeRegion): string;
|
|
1175
|
+
/**
|
|
1176
|
+
* Read the region parameter off a status-route URL. Absent means the domestic
|
|
1177
|
+
* tab (`cn`); a present-but-unknown value returns undefined so the route can
|
|
1178
|
+
* answer 400 instead of guessing.
|
|
1179
|
+
*/
|
|
1180
|
+
declare function regionOfTraeStatusUrl(url: string): TraeRegion | undefined;
|
|
963
1181
|
/** One credit pack and its remaining credit. */
|
|
964
1182
|
interface TraeWebCreditAccount {
|
|
965
1183
|
displayDesc: string;
|
|
@@ -1006,6 +1224,8 @@ interface TraeWebAccount {
|
|
|
1006
1224
|
id: string;
|
|
1007
1225
|
accountName: string;
|
|
1008
1226
|
edition: 'cn' | 'sg' | 'solo' | 'solo-sg';
|
|
1227
|
+
/** Routing bucket of this account, derived from its credential. */
|
|
1228
|
+
region: TraeRegion;
|
|
1009
1229
|
source: 'desktop' | 'dsh' | 'cli';
|
|
1010
1230
|
tokenExpiresAtMs: number;
|
|
1011
1231
|
selected: boolean;
|
|
@@ -1018,6 +1238,23 @@ interface TraeWebSearchPath {
|
|
|
1018
1238
|
reason: 'missing' | 'unreadable' | 'invalid';
|
|
1019
1239
|
message?: string;
|
|
1020
1240
|
}
|
|
1241
|
+
/** Subscription status of an international (ai) account, rendered instead of the CN credit packs. */
|
|
1242
|
+
interface TraeWebPayStatus {
|
|
1243
|
+
isDollarUsageBilling: boolean;
|
|
1244
|
+
hasPackage: boolean;
|
|
1245
|
+
isPayFreshman: boolean;
|
|
1246
|
+
inTrial: boolean;
|
|
1247
|
+
trialEndTimeMs: number;
|
|
1248
|
+
enableSoloLite: boolean;
|
|
1249
|
+
enableSoloBuilder: boolean;
|
|
1250
|
+
enableSoloCoder: boolean;
|
|
1251
|
+
enableSoloWeb: boolean;
|
|
1252
|
+
fission?: {
|
|
1253
|
+
startTimeMs: number;
|
|
1254
|
+
expireTimeMs: number;
|
|
1255
|
+
maxUsage: number;
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1021
1258
|
/** The JSON document the plugin card renders. */
|
|
1022
1259
|
type TraeWebUsage = {
|
|
1023
1260
|
status: 'signed-out';
|
|
@@ -1029,6 +1266,8 @@ type TraeWebUsage = {
|
|
|
1029
1266
|
accountId: string;
|
|
1030
1267
|
accountName: string;
|
|
1031
1268
|
tokenExpiresAtMs: number;
|
|
1269
|
+
/** Which per-region model directory and selection this account owns. */
|
|
1270
|
+
region: TraeRegion;
|
|
1032
1271
|
accounts: readonly TraeWebAccount[];
|
|
1033
1272
|
models: readonly TraeWebModel[];
|
|
1034
1273
|
enabledModelIds: readonly string[];
|
|
@@ -1039,29 +1278,43 @@ type TraeWebUsage = {
|
|
|
1039
1278
|
};
|
|
1040
1279
|
credits?: TraeWebCredits;
|
|
1041
1280
|
creditsError?: string;
|
|
1281
|
+
/** Subscription status of an international account (region ai only). */
|
|
1282
|
+
payStatus?: TraeWebPayStatus;
|
|
1283
|
+
payStatusError?: string;
|
|
1042
1284
|
} | {
|
|
1043
1285
|
status: 'error';
|
|
1044
1286
|
message: string;
|
|
1045
1287
|
};
|
|
1046
1288
|
//#endregion
|
|
1047
1289
|
//#region src/web-status.d.ts
|
|
1048
|
-
/**
|
|
1290
|
+
/**
|
|
1291
|
+
* Constructor dependencies. Everything region-specific is addressed by the
|
|
1292
|
+
* region the request names: the two regions are separate provider stacks, so
|
|
1293
|
+
* the card must be served the directory, selection, and credits of the tab the
|
|
1294
|
+
* user is on.
|
|
1295
|
+
*/
|
|
1049
1296
|
interface TraeUsageRouteOptions {
|
|
1050
|
-
store
|
|
1051
|
-
|
|
1052
|
-
/** The
|
|
1053
|
-
|
|
1054
|
-
/** The
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1297
|
+
/** The region-scoped credential store backing each region's requests. */
|
|
1298
|
+
store(region: TraeRegion): TraeCredentialStore;
|
|
1299
|
+
/** The region-scoped usage client (CN work credits / international pay status). */
|
|
1300
|
+
client(region: TraeRegion): TraeUsageClient;
|
|
1301
|
+
/** The requested region's last-refreshed raw directory (one entry per upstream model). */
|
|
1302
|
+
displayModels(region: TraeRegion): readonly TraeModelInfo[];
|
|
1303
|
+
/** The user's model selection in the requested region, stored as model id (= Trae name). */
|
|
1304
|
+
enabledModelIds(region: TraeRegion): readonly string[];
|
|
1305
|
+
/** Re-read one region's live directory from the upstream. */
|
|
1306
|
+
discoverModels?(region: TraeRegion, signal?: AbortSignal): Promise<readonly TraeModelInfo[]>;
|
|
1307
|
+
/** Raw-Chat capability state of the requested region. */
|
|
1308
|
+
rawDiagnostic?(region: TraeRegion): TraeRawDiagnostic;
|
|
1058
1309
|
}
|
|
1059
1310
|
/**
|
|
1060
|
-
* Assemble
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1311
|
+
* Assemble one region's card document. `region` is the tab the card is on; the
|
|
1312
|
+
* region-scoped store already answers with only that region's accounts, so the
|
|
1313
|
+
* document's model slots and account list are that region's by construction.
|
|
1314
|
+
* Sign-in state is read-only; credit is a live billing answer whose failure
|
|
1315
|
+
* degrades to `creditsError` rather than failing the whole document.
|
|
1063
1316
|
*/
|
|
1064
|
-
declare function traeWebUsage(deps: TraeUsageRouteOptions): Promise<TraeWebUsage>;
|
|
1317
|
+
declare function traeWebUsage(deps: TraeUsageRouteOptions, region: TraeRegion): Promise<TraeWebUsage>;
|
|
1065
1318
|
/** Mount the GET usage route on an optional webServer context. */
|
|
1066
1319
|
declare function registerTraeUsageRoute(ctx: Context, deps: TraeUsageRouteOptions): void;
|
|
1067
1320
|
//#endregion
|
|
@@ -1077,23 +1330,64 @@ declare const inject: string[];
|
|
|
1077
1330
|
* so no branding is needed for either host generation.
|
|
1078
1331
|
*/
|
|
1079
1332
|
declare const TRAE_SETTINGS_NS = "trae";
|
|
1333
|
+
/** One region's saved model state: its own directory and the user's selection within it. */
|
|
1334
|
+
interface TraeRegionState {
|
|
1335
|
+
/** The last-refreshed raw directory for this region; what the card displays. */
|
|
1336
|
+
lastCatalog?: TraeModelInfo[];
|
|
1337
|
+
/** The user's selection in this region, as model ids (= Trae name). */
|
|
1338
|
+
enabledModelIds?: string[];
|
|
1339
|
+
/** Models the user explicitly enabled for image input in this region. */
|
|
1340
|
+
imageModelIds?: string[];
|
|
1341
|
+
/** Local DSH context budget per model in this region. */
|
|
1342
|
+
contextBudgets?: Record<string, number>;
|
|
1343
|
+
}
|
|
1080
1344
|
interface Config {
|
|
1081
1345
|
authFile?: string;
|
|
1082
1346
|
edition?: 'auto' | 'cn' | 'sg' | 'solo' | 'solo-sg';
|
|
1083
|
-
/**
|
|
1347
|
+
/**
|
|
1348
|
+
* @deprecated Legacy single-slot account selector from before the dual
|
|
1349
|
+
* provider split. It is attributed to whichever region the account actually
|
|
1350
|
+
* belongs to (resolved once at startup from the local account scan); new
|
|
1351
|
+
* writes go to {@link Config.accounts}.
|
|
1352
|
+
*/
|
|
1084
1353
|
accountId?: string;
|
|
1085
|
-
/**
|
|
1354
|
+
/**
|
|
1355
|
+
* Per-region account selections, keyed `cn` | `ai`. Each region's tab writes
|
|
1356
|
+
* its own slot; tokens remain outside settings.
|
|
1357
|
+
*/
|
|
1358
|
+
accounts?: Partial<Record<TraeRegion, string>>;
|
|
1359
|
+
/**
|
|
1360
|
+
* Per-region model state, keyed `cn` | `ai`. The CN and international apps
|
|
1361
|
+
* expose different rosters, so each keeps its own directory and selection
|
|
1362
|
+
* and switching accounts never drops the other region's picks.
|
|
1363
|
+
*/
|
|
1364
|
+
regions?: Partial<Record<TraeRegion, TraeRegionState>>;
|
|
1365
|
+
/**
|
|
1366
|
+
* @deprecated Legacy single-slot fields from before the region split. They
|
|
1367
|
+
* predate international support and are read as the CN region's state when
|
|
1368
|
+
* `regions.cn` is absent; new writes go to `regions`.
|
|
1369
|
+
*/
|
|
1086
1370
|
lastCatalog?: TraeModelInfo[];
|
|
1087
|
-
/**
|
|
1371
|
+
/** @deprecated See {@link Config.lastCatalog}. */
|
|
1088
1372
|
enabledModelIds?: string[];
|
|
1089
|
-
/**
|
|
1373
|
+
/** @deprecated See {@link Config.lastCatalog}. */
|
|
1090
1374
|
contextBudgets?: Record<string, number>;
|
|
1091
|
-
/**
|
|
1375
|
+
/** @deprecated See {@link Config.lastCatalog}. */
|
|
1092
1376
|
imageModelIds?: string[];
|
|
1093
|
-
/** Legacy generated runtime catalog; kept for backwards compatibility. */
|
|
1377
|
+
/** @deprecated Legacy generated runtime catalog; kept for backwards compatibility. */
|
|
1094
1378
|
models?: TraeModelInfo[];
|
|
1095
1379
|
}
|
|
1380
|
+
/**
|
|
1381
|
+
* One region's saved state. A config written before the region split has only
|
|
1382
|
+
* the flat fields: those were always captured from the CN endpoint (the
|
|
1383
|
+
* plugin had no international support), so they are read as the CN state and
|
|
1384
|
+
* only when no explicit CN slot exists. The ai region never inherits them —
|
|
1385
|
+
* that inheritance is exactly the bug where a stale CN directory would be
|
|
1386
|
+
* intersected with the international catalog and silently drop the user's
|
|
1387
|
+
* picks (the same failure workbuddy fixed with its region split).
|
|
1388
|
+
*/
|
|
1389
|
+
declare function regionStateOf(config: Config, region: TraeRegion): TraeRegionState;
|
|
1096
1390
|
declare const Config: z<Config>;
|
|
1097
1391
|
declare function apply(ctx: Context, config: Config): void;
|
|
1098
1392
|
//#endregion
|
|
1099
|
-
export { Config, FALLBACK_TRAE_MODELS, type RawChatDelta, type RawChatMessage, type RawChatTool, SseDecoder, type SseEvent, TRAE_CN_AGENT_TASK_PATH, TRAE_CN_TITLE_PATH, TRAE_MODEL_DETAIL_FUNCTIONS, TRAE_MODEL_DETAIL_PATH, TRAE_PAY_BASE, TRAE_PROVIDER, TRAE_RAW_CHAT_V1_PATH, TRAE_RAW_CHAT_V2_PATH, TRAE_REASONING_EFFORTS, TRAE_SETTINGS_NS, TRAE_SOLO_CHAT_PATH, TRAE_SOLO_FUNCTION, TRAE_SOLO_MODELS_PATH, TRAE_SOLO_REMOTE_BASE, TRAE_STREAM_IDLE_TIMEOUT_MS, TRAE_USAGE_PATH, TRAE_VERSION_CODE_FALLBACK, type TraeActivityRule, type TraeCachedModelConfig, TraeCatalog, type TraeChatResult, type TraeCheckinStatus, type TraeContextBudget, type TraeCredential, TraeCredentialStore, TraeDelegatingUpstreamClient, type TraeDiscoveredModel, type TraeDiscoveredReasoning, type TraeEdition, TraeFallbackUpstreamClient, type TraeFallbackUpstreamOptions, type TraeFusionRawChatEnvelope, TraeGatedUpstreamClient, type TraeGatedUpstreamOptions, type TraeIdentity, type TraeInputModality, type TraeModelDetailRequest, type TraeModelInfo, type TraeObservedModelConfig, TraeRawCapabilityController, type TraeRawCapabilityControllerOptions, type TraeRawCapabilitySnapshot, TraeRawCapabilityState, type TraeRawChatBehaviorConfig, type TraeRawChatCapability, type TraeRawChatClientOptions, type TraeRawChatConfig, type TraeRawChatFailureReason, type TraeRawChatRuntimeConfig, TraeRawChatUpstreamClient, type TraeRawDiagnostic, type TraeRawDiagnosticState, type TraeRawGateway, type TraeRawGatewayOptions, type TraeRawResolverResult, type TraeReasoningCapability, type TraeReasoningEffort, type TraeShim, TraeSoloBridge, type TraeSoloClientOptions, TraeSoloRemoteCatalogClient, type TraeSoloRemoteCatalogOptions, TraeSoloUpstreamClient, type TraeStorageCandidate, type TraeStreamEvent, type TraeUpstreamClient, TraeUsageClient, type TraeUsageOptions, type TraeUsagePack, type TraeUsageRouteOptions, type TraeUsageSnapshot, type TraeUsageSummary, type TraeUsageView, type TraeWebActivity, type TraeWebCheckin, type TraeWebCredits, type TraeWebUsage, type TraeWireModel, UnconfiguredTraeUpstreamClient, apply, applyContextBudgets, applyImageSelection, applyReasoningEffort, bridgeTraeSoloStream, buildTraeAgentTaskBody, buildTraeCnHeaders, buildTraeFusionRawChatEnvelope, buildTraeModelDetailRequest, buildTraeRawChatDraft, buildTraeRawChatRuntimeConfig, classifyTraeRawChatFailure, createTraeAdapter, createTraeRawGateway, createTraeShim, decodeRawChatChunk, decodeTraeEvent, decryptTraeStorageValue, deriveCatalog, discoveredCatalog, hashTraeRawChatArg, identityHeaders, inject, mergeTraeModelSources, name, normalizeTraeCredential, normalizeTraeVersionCode, parseObservedModelConfig, parseReasoningCapability, parseTraeAuthValue, parseTraeCachedModel, parseTraeModelExtraConfigLogLine, parseTraeRawChatBehaviorConfig, parseTraeRemoteModel, parseTraeStorageDocument, pickTraeStorageIdentity, prepareSoloBody, probeTraeRawChatCapability, rawCapabilityDiagnostic, rawCapabilityFingerprint, readTraeCachedModel, readTraeIdentity, refreshTraeCredential, registerTraeUsageRoute, resolveTraeRawRuntime, sanitizeCatalog, traeEndpoint, traeInputModalities, traeModelDisplayName, traeOwnAuthPath, traeRawChatExtraInfo, traeStorageCandidates, traeWebUsage };
|
|
1393
|
+
export { Config, FALLBACK_TRAE_MODELS, FALLBACK_TRAE_MODELS_AI, REGION_GATEWAYS, type RawChatDelta, type RawChatMessage, type RawChatTool, SseDecoder, type SseEvent, TRAE_AI_PROVIDER, TRAE_CN_AGENT_TASK_PATH, TRAE_CN_TITLE_PATH, TRAE_MODEL_DETAIL_FUNCTIONS, TRAE_MODEL_DETAIL_PATH, TRAE_PAY_BASE, TRAE_PROVIDER, TRAE_PROVIDERS, TRAE_PROVIDER_DISPLAY_NAMES, TRAE_RAW_CHAT_V1_PATH, TRAE_RAW_CHAT_V2_PATH, TRAE_REASONING_EFFORTS, TRAE_REGIONS, TRAE_REGION_PARAM, TRAE_SETTINGS_NS, TRAE_SOLO_CHAT_PATH, TRAE_SOLO_FUNCTION, TRAE_SOLO_MODELS_PATH, TRAE_SOLO_REMOTE_BASE, TRAE_STREAM_IDLE_TIMEOUT_MS, TRAE_USAGE_PATH, TRAE_VERSION_CODE_FALLBACK, type TraeActivityRule, type TraeAdapter, type TraeCachedModelConfig, TraeCatalog, type TraeChatResult, type TraeCheckinStatus, type TraeContextBudget, type TraeCredential, TraeCredentialStore, TraeDelegatingUpstreamClient, type TraeDiscoveredModel, type TraeDiscoveredReasoning, type TraeEdition, TraeFallbackUpstreamClient, type TraeFallbackUpstreamOptions, type TraeFusionRawChatEnvelope, TraeGatedUpstreamClient, type TraeGatedUpstreamOptions, type TraeIdentity, type TraeInputModality, type TraeModelDetailRequest, type TraeModelInfo, type TraeObservedModelConfig, TraeRawCapabilityController, type TraeRawCapabilityControllerOptions, type TraeRawCapabilitySnapshot, TraeRawCapabilityState, type TraeRawChatBehaviorConfig, type TraeRawChatCapability, type TraeRawChatClientOptions, type TraeRawChatConfig, type TraeRawChatFailureReason, type TraeRawChatRuntimeConfig, TraeRawChatUpstreamClient, type TraeRawDiagnostic, type TraeRawDiagnosticState, type TraeRawGateway, type TraeRawGatewayOptions, type TraeRawResolverResult, type TraeReasoningCapability, type TraeReasoningEffort, type TraeRefreshDevice, type TraeRegion, type TraeRegionGateways, TraeRegionState, type TraeShim, TraeSoloBridge, type TraeSoloClientOptions, TraeSoloRemoteCatalogClient, type TraeSoloRemoteCatalogOptions, TraeSoloUpstreamClient, type TraeStorageCandidate, type TraeStreamEvent, type TraeUpstreamClient, TraeUsageClient, type TraeUsageOptions, type TraeUsagePack, type TraeUsageRouteOptions, type TraeUsageSnapshot, type TraeUsageSummary, type TraeUsageView, type TraeWebActivity, type TraeWebCheckin, type TraeWebCredits, type TraeWebUsage, type TraeWireModel, UnconfiguredTraeUpstreamClient, apply, applyContextBudgets, applyImageSelection, applyReasoningEffort, bridgeTraeSoloStream, buildTraeAgentTaskBody, buildTraeCnHeaders, buildTraeFusionRawChatEnvelope, buildTraeModelDetailRequest, buildTraeRawChatDraft, buildTraeRawChatRuntimeConfig, classifyTraeRawChatFailure, createTraeAdapter, createTraeRawGateway, createTraeShim, decodeRawChatChunk, decodeTraeEvent, decryptTraeStorageValue, deriveCatalog, discoveredCatalog, fallbackModelsFor, hashTraeRawChatArg, identityHeaders, inject, legacyTraeOwnAuthPath, mergeTraeModelSources, name, normalizeTraeCredential, normalizeTraeVersionCode, parseObservedModelConfig, parseReasoningCapability, parseTraeAuthValue, parseTraeCachedModel, parseTraeModelExtraConfigLogLine, parseTraeRawChatBehaviorConfig, parseTraeRemoteModel, parseTraeStorageDocument, pickTraeStorageIdentity, prepareSoloBody, probeTraeRawChatCapability, rawCapabilityDiagnostic, rawCapabilityFingerprint, readTraeCachedModel, readTraeIdentity, refreshTraeCredential, regionOfCredential, regionOfEdition, regionOfHost, regionOfTraeProvider, regionOfTraeStatusUrl, regionOfUserRegion, regionStateOf, registerTraeUsageRoute, resolveTraeRawRuntime, sanitizeCatalog, traeEndpoint, traeInputModalities, traeModelDisplayName, traeOwnAuthPath, traeRawChatExtraInfo, traeStorageCandidates, traeWebUsage, withTraeRegion };
|