dsh-connect-trae 3.0.1 → 3.3.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 +178 -0
- package/README.en.md +3 -2
- package/README.md +3 -2
- package/lib/client.js +912 -370
- package/lib/index.d.ts +118 -7
- package/lib/index.js +375 -54
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -572,6 +572,20 @@ declare function parseTraeAuthValue(value: string): unknown;
|
|
|
572
572
|
declare function parseTraeStorageDocument(text: string): unknown;
|
|
573
573
|
//#endregion
|
|
574
574
|
//#region src/identity.d.ts
|
|
575
|
+
/**
|
|
576
|
+
* The per-install ECDSA P-256 keypair the official client registers with the
|
|
577
|
+
* device, and signs its token-refresh proof with.
|
|
578
|
+
*
|
|
579
|
+
* It lives in the same `storage.json` as the credential, under
|
|
580
|
+
* `iCubeAuthInfo://icube-dc:<deviceId>`, encrypted with the same codec — so the
|
|
581
|
+
* key that PROVES a device is the key stored beside the login it protects.
|
|
582
|
+
* Without it the new refresh contract cannot be satisfied at all (the server
|
|
583
|
+
* rejects a proof signed by any other key with `20403 Token device not match`).
|
|
584
|
+
*/
|
|
585
|
+
interface TraeDeviceKeyPair {
|
|
586
|
+
privateKeyPEM: string;
|
|
587
|
+
publicKeyPEM: string;
|
|
588
|
+
}
|
|
575
589
|
interface TraeIdentity {
|
|
576
590
|
edition: TraeEdition;
|
|
577
591
|
machineId: string;
|
|
@@ -581,6 +595,15 @@ interface TraeIdentity {
|
|
|
581
595
|
deviceBrand?: string;
|
|
582
596
|
deviceCpu?: string;
|
|
583
597
|
osVersion?: string;
|
|
598
|
+
/**
|
|
599
|
+
* Device display name; the official client sends the OS account's full name.
|
|
600
|
+
* Optional because the new refresh contract does not read it.
|
|
601
|
+
*/
|
|
602
|
+
deviceName?: string;
|
|
603
|
+
/** Device model, e.g. `MacBookPro18,2`. Optional; not required by the server. */
|
|
604
|
+
deviceModel?: string;
|
|
605
|
+
/** The install's registered device keypair, when `storage.json` carries one. */
|
|
606
|
+
deviceKeyPair?: TraeDeviceKeyPair;
|
|
584
607
|
platform: NodeJS.Platform;
|
|
585
608
|
}
|
|
586
609
|
interface TraeIdentityReadOptions {
|
|
@@ -1156,16 +1179,46 @@ declare class TraeGatedUpstreamClient implements TraeUpstreamClient {
|
|
|
1156
1179
|
}
|
|
1157
1180
|
//#endregion
|
|
1158
1181
|
//#region src/refresh.d.ts
|
|
1159
|
-
/**
|
|
1182
|
+
/**
|
|
1183
|
+
* Stable device identity for the DeviceInfo body, sourced from the app's own
|
|
1184
|
+
* storage. Every field except `deviceId`/`machineId` is optional: the server
|
|
1185
|
+
* requires `DeviceID`, `PlatformCode` and `DeviceType` (verified: dropping
|
|
1186
|
+
* `DeviceType` yields `20403`, dropping `MachineID` does not), so a machine that
|
|
1187
|
+
* cannot read the cosmetic fields must still be able to refresh.
|
|
1188
|
+
*/
|
|
1160
1189
|
interface TraeRefreshDevice {
|
|
1161
1190
|
deviceId: string;
|
|
1162
1191
|
machineId: string;
|
|
1192
|
+
deviceName?: string;
|
|
1193
|
+
deviceModel?: string;
|
|
1194
|
+
deviceBrand?: string;
|
|
1195
|
+
deviceCpu?: string;
|
|
1196
|
+
osVersion?: string;
|
|
1197
|
+
appVersion?: string;
|
|
1198
|
+
/**
|
|
1199
|
+
* The install's registered keypair, read from `storage.json`. Its presence is
|
|
1200
|
+
* exactly what decides whether the CURRENT contract can be attempted: without
|
|
1201
|
+
* it there is no proof to sign, and the server would answer `20405`.
|
|
1202
|
+
*/
|
|
1203
|
+
deviceKeyPair?: {
|
|
1204
|
+
privateKeyPEM: string;
|
|
1205
|
+
publicKeyPEM: string;
|
|
1206
|
+
};
|
|
1163
1207
|
}
|
|
1164
1208
|
/**
|
|
1165
|
-
* Exchange a refresh token for a fresh access token
|
|
1166
|
-
*
|
|
1167
|
-
*
|
|
1168
|
-
*
|
|
1209
|
+
* Exchange a refresh token for a fresh access token.
|
|
1210
|
+
*
|
|
1211
|
+
* The CURRENT contract is attempted first whenever it is possible at all — it is
|
|
1212
|
+
* what the shipped clients use. It needs the install's device keypair; without
|
|
1213
|
+
* one there is nothing to sign, so the request is skipped rather than sent to be
|
|
1214
|
+
* rejected with `20405`.
|
|
1215
|
+
*
|
|
1216
|
+
* The SUPERSEDED contract is then tried as a fallback, which is what keeps older
|
|
1217
|
+
* installs and CLI-only machines working; it carries no device block but the
|
|
1218
|
+
* SAME per-edition ClientID, because that split belongs to the OAuth client
|
|
1219
|
+
* rather than to the endpoint (see {@link legacyBody}). When both are impossible
|
|
1220
|
+
* or both fail, the error names every attempt so a "sign in again" verdict is
|
|
1221
|
+
* diagnosable rather than mysterious.
|
|
1169
1222
|
*/
|
|
1170
1223
|
declare function refreshTraeCredential(credential: TraeCredential, signal?: AbortSignal, device?: TraeRefreshDevice): Promise<TraeRefreshOutcome>;
|
|
1171
1224
|
//#endregion
|
|
@@ -1561,9 +1614,20 @@ declare const TRAE_USAGE_PATH = "/plugins/dsh-connect-trae/usage";
|
|
|
1561
1614
|
* labels the button as consuming a small amount.
|
|
1562
1615
|
*/
|
|
1563
1616
|
declare const TRAE_MODELS_TEST_PATH = "/plugins/dsh-connect-trae/models/test";
|
|
1617
|
+
/**
|
|
1618
|
+
* Per-account status (check-in / credits / subscription) for the account table.
|
|
1619
|
+
*
|
|
1620
|
+
* Each row of the account table reads its OWN state through this route — a CN
|
|
1621
|
+
* row carries its check-in state and balance, an ai row its subscription.
|
|
1622
|
+
* POST with the accountId in the body: one upstream read per account, paid
|
|
1623
|
+
* only when the table is actually shown.
|
|
1624
|
+
*/
|
|
1625
|
+
declare const TRAE_ACCOUNT_STATUS_PATH = "/plugins/dsh-connect-trae/account-status";
|
|
1564
1626
|
/**
|
|
1565
1627
|
* Plugin-owned daily check-in claim endpoint. POST, loopback-only, and the only
|
|
1566
|
-
* route in this plugin that changes upstream account state.
|
|
1628
|
+
* route in this plugin that changes upstream account state. The accountId in
|
|
1629
|
+
* the body names WHICH account to claim for, so the button can sit in each
|
|
1630
|
+
* account row.
|
|
1567
1631
|
*/
|
|
1568
1632
|
declare const TRAE_CHECKIN_PATH = "/plugins/dsh-connect-trae/checkin";
|
|
1569
1633
|
/** Query parameter naming the region a card request addresses. */
|
|
@@ -1586,6 +1650,12 @@ interface TraeWebCreditAccount {
|
|
|
1586
1650
|
displayDesc: string;
|
|
1587
1651
|
remain: number;
|
|
1588
1652
|
size: number;
|
|
1653
|
+
/**
|
|
1654
|
+
* When this pack lapses, in epoch milliseconds, taken from the upstream's own
|
|
1655
|
+
* `end_time`. Absent when the upstream reported no usable time (0 / missing),
|
|
1656
|
+
* so a consumer can tell "no date" apart from "1970".
|
|
1657
|
+
*/
|
|
1658
|
+
expiresAtMs?: number;
|
|
1589
1659
|
}
|
|
1590
1660
|
/** Aggregated usage/credit answer rendered by the plugin card. */
|
|
1591
1661
|
interface TraeWebCredits {
|
|
@@ -1730,6 +1800,31 @@ interface TraeWebAppLogin {
|
|
|
1730
1800
|
edition: 'cn' | 'sg' | 'solo' | 'solo-sg';
|
|
1731
1801
|
region: TraeRegion;
|
|
1732
1802
|
}
|
|
1803
|
+
/**
|
|
1804
|
+
* The per-account state shown inside an account row of the card's table.
|
|
1805
|
+
*
|
|
1806
|
+
* Every locally detected account in a region is rendered as a row; the
|
|
1807
|
+
* interesting per-account facts differ by region, which is why this is a union
|
|
1808
|
+
* of the three surfaces the card previously showed only for the BOUND account:
|
|
1809
|
+
*
|
|
1810
|
+
* - CN rows carry their own check-in state (Trae keys the daily reward per
|
|
1811
|
+
* ACCOUNT, and the one-per-device tally per DEVICE, see {@link TraeWebCheckin})
|
|
1812
|
+
* and their Work/General balances.
|
|
1813
|
+
* - ai rows carry their own subscription / trial status.
|
|
1814
|
+
*
|
|
1815
|
+
* Each field is optional: a read that fails keeps the row visible (perhaps
|
|
1816
|
+
* without a figure) rather than dropping the account and its switch.
|
|
1817
|
+
*/
|
|
1818
|
+
interface TraeWebAccountState {
|
|
1819
|
+
/** The account this state belongs to. */
|
|
1820
|
+
id: string;
|
|
1821
|
+
/** CN: today's check-in state of this account (absent for ai rows). */
|
|
1822
|
+
checkin?: TraeWebCheckin;
|
|
1823
|
+
/** CN: this account's Work/General balances (absent for ai rows). */
|
|
1824
|
+
credits?: TraeWebCredits;
|
|
1825
|
+
/** ai: this account's subscription / trial status (absent for CN rows). */
|
|
1826
|
+
payStatus?: TraeWebPayStatus;
|
|
1827
|
+
}
|
|
1733
1828
|
interface TraeWebCreditAlternative {
|
|
1734
1829
|
id: string;
|
|
1735
1830
|
accountName: string;
|
|
@@ -1930,6 +2025,22 @@ interface TraeUsageRouteOptions {
|
|
|
1930
2025
|
* exhausted-account hint is simply not offered.
|
|
1931
2026
|
*/
|
|
1932
2027
|
creditsOfAccount?(region: TraeRegion, accountId: string): Promise<TraeWebCredits | undefined>;
|
|
2028
|
+
/**
|
|
2029
|
+
* Per-account status for one row of the card's account table: CN → check-in
|
|
2030
|
+
* + balances, ai → subscription. Read without changing which account is
|
|
2031
|
+
* bound. Optional: when absent the account rows show no check-in/credits/
|
|
2032
|
+
* subscription figures (the table still lists each account and its switch).
|
|
2033
|
+
*/
|
|
2034
|
+
accountStateOf?(region: TraeRegion, accountId: string): Promise<TraeWebAccountState | undefined>;
|
|
2035
|
+
/**
|
|
2036
|
+
* Claim today's check-in reward for ONE named account, without moving the
|
|
2037
|
+
* binding. Optional: absent means the per-row claim button is disabled (the
|
|
2038
|
+
* check-in surface simply is not offered).
|
|
2039
|
+
*/
|
|
2040
|
+
claimCheckinOf?(region: TraeRegion, accountId: string): Promise<{
|
|
2041
|
+
claim: TraeCheckinClaim;
|
|
2042
|
+
checkin: TraeCheckinStatus;
|
|
2043
|
+
} | undefined>;
|
|
1933
2044
|
/**
|
|
1934
2045
|
* The account the Trae app is signed in to right now, when it differs from
|
|
1935
2046
|
* the bound one (issue #29). Optional: absent means the card's follow hint
|
|
@@ -2193,4 +2304,4 @@ declare function asVolatile<S>(schema: S): S;
|
|
|
2193
2304
|
declare const Config: z<Config>;
|
|
2194
2305
|
declare function apply(ctx: Context, config: Config): void;
|
|
2195
2306
|
//#endregion
|
|
2196
|
-
export { Config, FALLBACK_TRAE_MODELS, FALLBACK_TRAE_MODELS_AI, REGION_GATEWAYS, type RawChatDelta, type RawChatMessage, type RawChatTool, SseDecoder, type SseEvent, TRAE_AI_PROVIDER, TRAE_CHECKIN_PATH, TRAE_CN_AGENT_TASK_PATH, TRAE_CN_TITLE_PATH, TRAE_MODELS_TEST_PATH, TRAE_MODEL_DETAIL_FUNCTIONS, TRAE_MODEL_DETAIL_PATH, TRAE_PAY_BASE, TRAE_PROBE_TIMEOUT_MS, 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_STATE_DB_FILENAME, TRAE_STREAM_IDLE_TIMEOUT_MS, TRAE_USAGE_PATH, TRAE_VERSION_CODE_FALLBACK, type TraeActivityRule, type TraeAdapter, type TraeCachedModelConfig, TraeCatalog, type TraeChatResult, type TraeCheckinClaim, 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 TraeModelProbeVerdict, type TraeModelsTestResponse, type TraeObservedModelConfig, type TraeProbeResult, type TraeProbeVerdict, 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 TraeWebAppLogin, type TraeWebCheckin, type TraeWebCheckinClaim, type TraeWebCredits, type TraeWebUsage, type TraeWireModel, UnconfiguredTraeUpstreamClient, apply, applyContextBudgets, applyImageSelection, applyReasoningEffort, asVolatile, bridgeTraeSoloStream, buildTraeAgentTaskBody, buildTraeCnHeaders, buildTraeFusionRawChatEnvelope, buildTraeModelDetailRequest, buildTraeRawChatDraft, buildTraeRawChatRuntimeConfig, classifyProbeError, classifyProbeResult, classifyTraeRawChatFailure, configuredAccountsOf, createTraeAdapter, createTraeRawGateway, createTraeShim, decodeRawChatChunk, decodeTraeEvent, decryptTraeStorageValue, deriveCatalog, describeIdShape, describeNameShape, discoveredCatalog, fallbackModelsFor, followAppLoginEnabled, hashTraeRawChatArg, identityHeaders, inject, legacyTraeOwnAuthPath, maskUserPath, mergeTraeModelSources, name, nextRegionEnabled, nextRegionSlots, normalizeTraeCredential, normalizeTraeVersionCode, parseObservedModelConfig, parseReasoningCapability, parseTraeAuthValue, parseTraeCachedModel, parseTraeModelExtraConfigLogLine, parseTraeRawChatBehaviorConfig, parseTraeRemoteModel, parseTraeStorageDocument, pickTraeStorageIdentity, prepareSoloBody, probeBody, probeModelsSequentially, probeOneModel, probeTraeRawChatCapability, rawCapabilityDiagnostic, rawCapabilityFingerprint, readTraeCachedModel, readTraeCliIdentity, readTraeIdentity, refreshTraeCredential, regionEnabled, regionEnabledOf, regionOfCredential, regionOfEdition, regionOfHost, regionOfTraeProvider, regionOfTraeStatusUrl, regionOfUserRegion, regionStateOf, registerTraeUsageRoute, resolveTraeIdentity, resolveTraeRawRuntime, sanitizeCatalog, settingsNamespaceOf, traeEndpoint, traeInputModalities, traeModelDisplayName, traeOwnAuthPath, traeRawChatExtraInfo, traeStateDatabaseCandidates, traeStorageCandidates, traeWebUsage, traeWindowsAppNames, unwrapVolatile, unwrapVolatileDeep, withTraeRegion };
|
|
2307
|
+
export { Config, FALLBACK_TRAE_MODELS, FALLBACK_TRAE_MODELS_AI, REGION_GATEWAYS, type RawChatDelta, type RawChatMessage, type RawChatTool, SseDecoder, type SseEvent, TRAE_ACCOUNT_STATUS_PATH, TRAE_AI_PROVIDER, TRAE_CHECKIN_PATH, TRAE_CN_AGENT_TASK_PATH, TRAE_CN_TITLE_PATH, TRAE_MODELS_TEST_PATH, TRAE_MODEL_DETAIL_FUNCTIONS, TRAE_MODEL_DETAIL_PATH, TRAE_PAY_BASE, TRAE_PROBE_TIMEOUT_MS, 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_STATE_DB_FILENAME, TRAE_STREAM_IDLE_TIMEOUT_MS, TRAE_USAGE_PATH, TRAE_VERSION_CODE_FALLBACK, type TraeActivityRule, type TraeAdapter, type TraeCachedModelConfig, TraeCatalog, type TraeChatResult, type TraeCheckinClaim, 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 TraeModelProbeVerdict, type TraeModelsTestResponse, type TraeObservedModelConfig, type TraeProbeResult, type TraeProbeVerdict, 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 TraeWebAccountState, type TraeWebActivity, type TraeWebAppLogin, type TraeWebCheckin, type TraeWebCheckinClaim, type TraeWebCredits, type TraeWebUsage, type TraeWireModel, UnconfiguredTraeUpstreamClient, apply, applyContextBudgets, applyImageSelection, applyReasoningEffort, asVolatile, bridgeTraeSoloStream, buildTraeAgentTaskBody, buildTraeCnHeaders, buildTraeFusionRawChatEnvelope, buildTraeModelDetailRequest, buildTraeRawChatDraft, buildTraeRawChatRuntimeConfig, classifyProbeError, classifyProbeResult, classifyTraeRawChatFailure, configuredAccountsOf, createTraeAdapter, createTraeRawGateway, createTraeShim, decodeRawChatChunk, decodeTraeEvent, decryptTraeStorageValue, deriveCatalog, describeIdShape, describeNameShape, discoveredCatalog, fallbackModelsFor, followAppLoginEnabled, hashTraeRawChatArg, identityHeaders, inject, legacyTraeOwnAuthPath, maskUserPath, mergeTraeModelSources, name, nextRegionEnabled, nextRegionSlots, normalizeTraeCredential, normalizeTraeVersionCode, parseObservedModelConfig, parseReasoningCapability, parseTraeAuthValue, parseTraeCachedModel, parseTraeModelExtraConfigLogLine, parseTraeRawChatBehaviorConfig, parseTraeRemoteModel, parseTraeStorageDocument, pickTraeStorageIdentity, prepareSoloBody, probeBody, probeModelsSequentially, probeOneModel, probeTraeRawChatCapability, rawCapabilityDiagnostic, rawCapabilityFingerprint, readTraeCachedModel, readTraeCliIdentity, readTraeIdentity, refreshTraeCredential, regionEnabled, regionEnabledOf, regionOfCredential, regionOfEdition, regionOfHost, regionOfTraeProvider, regionOfTraeStatusUrl, regionOfUserRegion, regionStateOf, registerTraeUsageRoute, resolveTraeIdentity, resolveTraeRawRuntime, sanitizeCatalog, settingsNamespaceOf, traeEndpoint, traeInputModalities, traeModelDisplayName, traeOwnAuthPath, traeRawChatExtraInfo, traeStateDatabaseCandidates, traeStorageCandidates, traeWebUsage, traeWindowsAppNames, unwrapVolatile, unwrapVolatileDeep, withTraeRegion };
|