dsh-connect-trae 2.10.0 → 3.0.1

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/lib/index.d.ts CHANGED
@@ -475,12 +475,35 @@ declare class TraeCredentialStore {
475
475
  selectAccount(accountId: string | undefined): void;
476
476
  candidates(): TraeStorageCandidate[];
477
477
  /**
478
- * Deterministic default when no account is explicitly selected: the first
479
- * discovered account. This is NOT credit-seeking — it never reorders accounts
480
- * to find one with general credits. The plugin bills exactly the account the
481
- * user selected, or the first account when nothing has been selected yet.
478
+ * Deterministic default when no account is explicitly selected: the account
479
+ * the Trae desktop app is signed in to RIGHT NOW, else the first discovered
480
+ * one. This is NOT credit-seeking — it never reorders accounts to find one
481
+ * with general credits. The plugin bills exactly the account the user
482
+ * selected, the app's current sign-in when nothing has been selected, and
483
+ * only then the first account.
484
+ *
485
+ * The app's live sign-in outranks the plugin's own refreshed copies (issue
486
+ * #29): after the user switches accounts in Trae, the desktop storage file
487
+ * holds the NEW login while the plugin's copy of the old one still resolves,
488
+ * so a bare `credentials[0]` kept defaulting to a sign-in the app has
489
+ * abandoned — and `dsh-connect-workbuddy`, whose `preferred()` ranks the live
490
+ * file first, followed the app instead. Ordering only: the VALUE behind an
491
+ * account id is still whichever copy expires later (`readAll`), so a refresh
492
+ * the plugin performed is never discarded by this preference.
482
493
  */
483
494
  private preferred;
495
+ /**
496
+ * The account the Trae app is signed in to right now, when that differs from
497
+ * the account this store is bound to (issue #29).
498
+ *
499
+ * This is a READ, not a rebind: `current()` keeps resolving the bound
500
+ * account verbatim so billing never moves without a decision — the store
501
+ * only reports the mismatch, and the card (hint row) or the host (follow
502
+ * switch) turns it into a settings write the user can see and undo. Absent
503
+ * when nothing is live, when the live account IS the bound one, or when the
504
+ * binding itself already fell through to the live account.
505
+ */
506
+ liveLogin(): Promise<TraeAccountChoice | undefined>;
484
507
  accounts(): Promise<TraeAccountChoice[]>;
485
508
  current(): Promise<TraeCredential | undefined>;
486
509
  /**
@@ -1690,14 +1713,23 @@ interface TraeWebAccount {
1690
1713
  selected: boolean;
1691
1714
  }
1692
1715
  /**
1693
- * Another account on this machine that still has credit, surfaced only while
1694
- * the BOUND account is exhausted (issue #25).
1716
+ * The account the Trae desktop app is signed in to right now, when it differs
1717
+ * from the one this plugin is bound to (issue #29).
1695
1718
  *
1696
- * The account switch is persisted, so a user whose bound account ran out sees
1697
- * a permanently zeroed card with no explanation. This carries just enough to
1698
- * name the alternative in the UI — identity plus the two CN credit buckets —
1699
- * and is only ever produced by a read-only upstream call.
1700
- */
1719
+ * Reported on the usage document so the card can offer one-click follow without
1720
+ * an extra round trip; also written back on a POST to the accounts refresh
1721
+ * route when the client confirms it saw the hint. Absent whenever the two
1722
+ * agree or the app is not readable — a healthy document carries no extra
1723
+ * fields and the plugin never bills from this value directly: the FOLLOW is a
1724
+ * settings write of `accounts.<region>`, made by the card or by the host's
1725
+ * follow switch, never a silent rebind here.
1726
+ */
1727
+ interface TraeWebAppLogin {
1728
+ id: string;
1729
+ accountName: string;
1730
+ edition: 'cn' | 'sg' | 'solo' | 'solo-sg';
1731
+ region: TraeRegion;
1732
+ }
1701
1733
  interface TraeWebCreditAlternative {
1702
1734
  id: string;
1703
1735
  accountName: string;
@@ -1738,6 +1770,33 @@ declare function unwrapVolatile<T>(value: T): T;
1738
1770
  * value is never touched.
1739
1771
  */
1740
1772
  declare function unwrapVolatileDeep<T>(value: T): T;
1773
+ /**
1774
+ * Read the per-region account selections out of a settings value.
1775
+ *
1776
+ * SHARED because `accounts` now has TWO writers: the card, and the composer
1777
+ * panel's account table (2.14.0). Two writers of one field must use one merge
1778
+ * rule, or they drift — and the rule is not obvious.
1779
+ *
1780
+ * Deep-unwraps first: on DSH 0.1.7 a volatile field arrives as a `{get(): T}`
1781
+ * live reference, which passes the `typeof === 'object'` check and would be
1782
+ * returned as if it were the map. Every lookup on it is then `undefined`, and
1783
+ * the merge (`{ ...configured, [region]: id }`) would spread a reference into
1784
+ * `{get: <function>}` — dropping the other region's selection and leaking a
1785
+ * function into the settings document.
1786
+ */
1787
+ declare function configuredAccountsOf(configured: unknown): Record<string, string>;
1788
+ /**
1789
+ * Whether the host-side "follow the Trae app's sign-in" switch is on (issue
1790
+ * #29). Absent reads as OFF, so an existing configuration keeps the strict
1791
+ * bind it shipped with and the switch is an opt-in — the same opt-out
1792
+ * semantics as {@link regionEnabledOf}, for the same reason: a config written
1793
+ * before this field existed cannot ask for behavior it never declared.
1794
+ *
1795
+ * Reads the whole settings section (or the bare field); deep-unwraps first
1796
+ * because on DSH 0.1.7 a volatile field arrives as a `{get(): T}` live
1797
+ * reference, whose `typeof === 'object'` would otherwise pass a naive check.
1798
+ */
1799
+ declare function followAppLoginEnabled(configured: unknown): boolean;
1741
1800
  /**
1742
1801
  * Build the next `regions` settings value for the card's save. The write
1743
1802
  * targets ONLY the signed-in account's region slot; every other region's slot
@@ -1828,6 +1887,15 @@ type TraeWebUsage = {
1828
1887
  * other case so a healthy account never pays for the extra read.
1829
1888
  */
1830
1889
  alternatives?: readonly TraeWebCreditAlternative[];
1890
+ /**
1891
+ * Present only when the Trae app's CURRENT sign-in differs from the
1892
+ * account this plugin is bound to (issue #29): the card then offers a
1893
+ * one-click follow instead of making the user hunt the account dropdown
1894
+ * after every app-side sign-out. Absent in every other case — a healthy
1895
+ * document costs no extra read beyond the accounts scan the document
1896
+ * already runs.
1897
+ */
1898
+ appLogin?: TraeWebAppLogin;
1831
1899
  /**
1832
1900
  * Daily check-in state (CN only). Absent on the international region,
1833
1901
  * whose check-in surface does not exist — probed 2026-09-24: the
@@ -1862,6 +1930,14 @@ interface TraeUsageRouteOptions {
1862
1930
  * exhausted-account hint is simply not offered.
1863
1931
  */
1864
1932
  creditsOfAccount?(region: TraeRegion, accountId: string): Promise<TraeWebCredits | undefined>;
1933
+ /**
1934
+ * The account the Trae app is signed in to right now, when it differs from
1935
+ * the bound one (issue #29). Optional: absent means the card's follow hint
1936
+ * simply is not offered (a test harness or a host without the store's scan).
1937
+ * Read-only — the HOST never rebinds from this value; the follow is a
1938
+ * settings write, made by the card or by the host's follow switch.
1939
+ */
1940
+ liveLogin?(region: TraeRegion): Promise<TraeWebAppLogin | undefined>;
1865
1941
  /** The requested region's last-refreshed raw directory (one entry per upstream model). */
1866
1942
  displayModels(region: TraeRegion): readonly TraeModelInfo[];
1867
1943
  /** The user's model selection in the requested region, stored as model id (= Trae name). */
@@ -2023,21 +2099,42 @@ interface Config {
2023
2099
  */
2024
2100
  accounts?: Partial<Record<TraeRegion, string>>;
2025
2101
  /**
2026
- * Show the CN account's general credit balance as a permanent line at the
2027
- * bottom of the DSH sidebar (issue #26, contributed by JiewiW).
2102
+ * Show the credit readout in the composer tool row: `Trae CN · <n>`, rendered
2103
+ * ONLY while the session's selected model belongs to this plugin, clickable
2104
+ * for the account/balances panel.
2028
2105
  *
2029
- * ON by default and opt-out since 2.9.1. It was opt-in first, on the theory
2030
- * that a user who never asked for a periodic usage read should not get one —
2031
- * but the switch lived only in the plugin card, and the card is not reachable
2032
- * in every host: a market plugin can own the Plugins tab and never dispatch
2033
- * `plugins.bundle.config`, so the line was permanently off with no discoverable
2034
- * way to turn it on. The line now carries its own on/off control in the
2035
- * sidebar, which is reachable exactly where the feature renders.
2106
+ * This field first gated the sidebar credit line (issue #26, contributed by
2107
+ * JiewiW); when that line was removed in 2.13.0 the composer readout replaced
2108
+ * it and rendered unconditionally; 2.13.3 restores the switch, because the
2109
+ * user went looking for it and a readout inside the SHARED composer row
2110
+ * deserves the same opt-in the sidebar line had. The field is REUSED so an
2111
+ * existing `true` keeps the readout on across the upgrade.
2036
2112
  *
2037
- * Declared volatile alongside `accounts`/`regions` so the settings form can
2038
- * both read and write it.
2113
+ * OFF by default. The card's checkbox is the only writer, so exactly one path
2114
+ * can change it. Declared volatile alongside `accounts`/`regions` so the
2115
+ * settings form can both read and write it.
2039
2116
  */
2040
2117
  showPointsInMainUi?: boolean;
2118
+ /**
2119
+ * Follow the Trae desktop app's CURRENT sign-in instead of staying bound to
2120
+ * the account the user (or the default) picked earlier (issue #29).
2121
+ *
2122
+ * When the app switches accounts, the old binding kept billing the previous
2123
+ * account forever while `dsh-connect-workbuddy` followed the app
2124
+ * automatically — every Trae sign-out then needed a manual switch here. With
2125
+ * this switch ON, each settings re-apply rebinds `accounts.<region>` to
2126
+ * whatever the app is signed in to right now (the live login outranks the
2127
+ * plugin's own refreshed copies, see `TraeCredentialStore.preferred`).
2128
+ *
2129
+ * OFF by default: an existing configuration keeps the strict bind it
2130
+ * shipped with, because silently switching billing accounts is exactly what
2131
+ * `current()`'s no-fallback rule exists to prevent — the user opts in. When
2132
+ * OFF, the card still shows a one-click hint (its own settings write), so
2133
+ * the report in #29 is solved on both paths without any behavior change
2134
+ * nobody asked for. Declared volatile so the card's switch can read and
2135
+ * write it on the 0.1.7 settings form.
2136
+ */
2137
+ followAppLogin?: boolean;
2041
2138
  /**
2042
2139
  * Per-region model state, keyed `cn` | `ai`. The CN and international apps
2043
2140
  * expose different rosters, so each keeps its own directory and selection
@@ -2096,4 +2193,4 @@ declare function asVolatile<S>(schema: S): S;
2096
2193
  declare const Config: z<Config>;
2097
2194
  declare function apply(ctx: Context, config: Config): void;
2098
2195
  //#endregion
2099
- 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 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, createTraeAdapter, createTraeRawGateway, createTraeShim, decodeRawChatChunk, decodeTraeEvent, decryptTraeStorageValue, deriveCatalog, describeIdShape, describeNameShape, discoveredCatalog, fallbackModelsFor, 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 };
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 };