@omnicross/daemon 0.4.2 → 0.4.3

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/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { Logger, OutboundApiServerConfig, ProviderConfigSource, TransformerService, Transformer, ResolvedTransformerChain, ApiServerSettingsStore, PricingStore, AutomaticPricingSource, OutboundPermission, OutboundKeyDb, OutboundKeyDbRow, OutboundKeyPolicy, PricingEngine as PricingEngine$1, OpenAIOperationRegistry } from '@omnicross/core';
2
2
  import { SearchRuntime, SearchFrontendModes } from '@omnicross/core/search';
3
3
  import { ApiKeyPoolService } from '@omnicross/core/completion/ApiKeyPoolService';
4
- import { AllowanceSchedulingConfig, AccountProbeConfig, OutboundKeyDb as OutboundKeyDb$1, VoucherDb, KeySpendReader, OutboundApiServer, ImagesServerConfig } from '@omnicross/core/outbound-api';
4
+ import { AllowanceSchedulingConfig, AccountProbeConfig, ImageProviderId, OutboundKeyDb as OutboundKeyDb$1, VoucherDb, KeySpendReader, OutboundApiServer, ImagesServerConfig } from '@omnicross/core/outbound-api';
5
5
  import { RouteLeaseManager, ProviderProxy } from '@omnicross/core/provider-proxy';
6
6
  import { UsageRecorder, PricingEngine } from '@omnicross/core/usage';
7
7
  import { SubscriptionCredentialStore, FetchLike, CodexImageCapabilityEvidenceSource, CodexImageCapabilityEvidenceRequest, CodexImageCapabilityEvidence, CodexImageCapabilityObservation, ImageExecutionScheduler, ImageExecutionAccountKey, ImageExecutionSchedulerRequest, ImageExecutionSchedulerGrant, SubscriptionAccountService, SubscriptionProviderRegistry } from '@omnicross/subscriptions';
8
8
  import { AccountAllowanceSnapshot, AllowanceWindow } from '@omnicross/contracts/account-allowance-types';
9
- import { ClaudeTokenConfig, CodexTokenConfig, GeminiTokenConfig, KimiTokenConfig, GrokTokenConfig, CopilotTokenConfig, AccountTokensConfig, ProxyConfig, SubscriptionAccountSanitized, AccountClientIdentity, SubscriptionAccountEntry } from '@omnicross/contracts/account-tokens-types';
9
+ import { ClaudeTokenConfig, CodexTokenConfig, GeminiTokenConfig, KimiTokenConfig, GrokTokenConfig, CopilotTokenConfig, AntigravityTokenConfig, AccountTokensConfig, ProxyConfig, SubscriptionAccountSanitized, AccountClientIdentity, SubscriptionAccountEntry } from '@omnicross/contracts/account-tokens-types';
10
10
  import * as _omnicross_contracts_subscription_types from '@omnicross/contracts/subscription-types';
11
11
  import { OpenCodeGoTokenConfig, SubscriptionProviderId } from '@omnicross/contracts/subscription-types';
12
12
  import { AccountAllowanceStore } from '@omnicross/core/pipeline/AccountAllowanceStore';
@@ -602,6 +602,32 @@ interface ResolvedAdminConfig {
602
602
  }
603
603
  /** The default admin port (distinct from the 8765 outbound server). */
604
604
  declare const DEFAULT_ADMIN_PORT = 8766;
605
+ /**
606
+ * Per-provider behavior flags for the antigravity subscription.
607
+ */
608
+ interface AntigravityProviderConfig {
609
+ /**
610
+ * Enable the production→sandbox endpoint failover for retryable antigravity
611
+ * upstream failures (design D5). DEFAULT OFF — with the switch off a
612
+ * retryable failure surfaces the original error semantics unchanged.
613
+ */
614
+ sandboxFailover?: boolean;
615
+ }
616
+ /**
617
+ * Per-provider identity config for the OpenCodeGo subscription
618
+ * (opencodego-egress-identity).
619
+ */
620
+ interface OpenCodeGoProviderConfig {
621
+ /**
622
+ * The `user-agent` every OpenCodeGo egress presents to opencode.ai (relay
623
+ * traffic AND the background usage poll). An app embedding omnicross sets
624
+ * its own identity here (e.g. `elftia/1.2.0`); absent ⇒ the product default
625
+ * `omnicross/<version>`. opencode.ai's announcement asks proxy tools to
626
+ * identify themselves clearly — a bare relay falls to Node's generic `node`
627
+ * UA, exactly the shape their traffic monitoring flags. NON-SECRET.
628
+ */
629
+ userAgent?: string;
630
+ }
605
631
  /** The full daemon config. */
606
632
  interface DaemonConfig {
607
633
  providers: DaemonProviderConfig[];
@@ -621,6 +647,16 @@ interface DaemonConfig {
621
647
  * lifetime per-key spend the outbound key policy seeds from.
622
648
  */
623
649
  usage?: UsageRetentionConfig;
650
+ /**
651
+ * Optional antigravity-subscription behavior flags (sandbox failover et al).
652
+ * Absent ⇒ every default (failover OFF).
653
+ */
654
+ antigravity?: AntigravityProviderConfig;
655
+ /**
656
+ * Optional OpenCodeGo identity config (outbound user-agent). Absent ⇒ the
657
+ * product default `omnicross/<version>` on every opencode.ai egress.
658
+ */
659
+ opencodego?: OpenCodeGoProviderConfig;
624
660
  }
625
661
  /** Apply defaults to a (possibly absent) admin block: enabled, port 8766,
626
662
  * loopback, no token. NOTE: an EXPLICIT `port: 0` is honored as "bind an
@@ -678,7 +714,7 @@ type AtomicFileReplace = (targetPath: string, contents: string) => void;
678
714
  */
679
715
 
680
716
  /** Provider id → owned contract field names. */
681
- type DaemonProvider = 'claude' | 'codex' | 'gemini' | 'opencodego' | 'kimi' | 'grok' | 'copilot';
717
+ type DaemonProvider = 'claude' | 'codex' | 'gemini' | 'opencodego' | 'kimi' | 'grok' | 'copilot' | 'antigravity';
682
718
  interface AccountMetadataPatch {
683
719
  label?: string;
684
720
  enabled?: boolean;
@@ -807,7 +843,7 @@ type ExternalCliReader = (provider: ExternalCliProvider) => ExternalCliCredentia
807
843
  * shapes), keyed by `SubscriptionProviderId` the daemon admin layer validates
808
844
  * the wire body to one of these before calling the writer.
809
845
  */
810
- type SubscriptionTokenBlock = ClaudeTokenConfig | CodexTokenConfig | GeminiTokenConfig | OpenCodeGoTokenConfig | KimiTokenConfig | GrokTokenConfig | CopilotTokenConfig;
846
+ type SubscriptionTokenBlock = ClaudeTokenConfig | CodexTokenConfig | GeminiTokenConfig | OpenCodeGoTokenConfig | KimiTokenConfig | GrokTokenConfig | CopilotTokenConfig | AntigravityTokenConfig;
811
847
  declare class JsonSubscriptionCredentialStore implements SubscriptionCredentialStore {
812
848
  private readonly tokensPath;
813
849
  private readonly box;
@@ -934,13 +970,32 @@ declare class JsonSubscriptionCredentialStore implements SubscriptionCredentialS
934
970
  * the retry instead of looping on a dead token).
935
971
  */
936
972
  refreshCopilotToken(): Promise<boolean>;
973
+ /**
974
+ * Refresh the Antigravity (Google) OAuth access token. Like gemini, the
975
+ * Google token endpoint does NOT return a refresh_token on refresh, so this
976
+ * writes ONLY access+expiresAt (+status/lastRefreshedAt) and DELIBERATELY
977
+ * preserves the stored `refreshToken` — plus the account's `projectId`
978
+ * (a handshake product; the post-refresh re-validation is the refresh
979
+ * scheduler's hook, not this write) and `email`. HONEST `false` when no
980
+ * refresh_token.
981
+ */
982
+ refreshAntigravityToken(): Promise<boolean>;
983
+ /**
984
+ * Post-refresh project re-validation hook (antigravity design D8): after a
985
+ * successful antigravity token refresh, re-run the Code Assist project
986
+ * handshake and write the (possibly rotated) `projectId` back to the account.
987
+ * A handshake FAILURE keeps the stored projectId untouched (logged) so the
988
+ * account keeps serving with the last-known-good project until a later
989
+ * refresh succeeds. Returns whether the handshake produced a project.
990
+ */
991
+ revalidateAntigravityProject(accountId: string): Promise<boolean>;
937
992
  /**
938
993
  * Refresh a SPECIFIC managed account by id (background scheduler sweep and
939
994
  * account-pool resolution). It uses only that account's stored refresh
940
995
  * token. Coalesced per `provider:id`; on failure flags ONLY that account
941
996
  * `expired`.
942
997
  */
943
- refreshAccountById(provider: 'claude' | 'codex' | 'gemini' | 'kimi' | 'grok' | 'copilot', id: string): Promise<boolean>;
998
+ refreshAccountById(provider: 'claude' | 'codex' | 'gemini' | 'kimi' | 'grok' | 'copilot' | 'antigravity', id: string): Promise<boolean>;
944
999
  /**
945
1000
  * Resolve a SPECIFIC account's access token by id (design D6). Mirrors each
946
1001
  * provider's ACTIVE-getter policy, keyed by id: claude returns the stored token
@@ -1686,6 +1741,59 @@ declare class GeminiAllowanceCollector {
1686
1741
  private unsupportedSnapshot;
1687
1742
  }
1688
1743
 
1744
+ /**
1745
+ * AntigravityAllowanceCollector — the antigravity subscription's quota via the
1746
+ * Code Assist internal quotaSummary RPC (antigravity-subscription-provider
1747
+ * design D6).
1748
+ *
1749
+ * Probes `POST ${daily-cloudcode-pa}/v1internal:retrieveUserQuotaSummary` per
1750
+ * antigravity account (Bearer access token + the antigravity/hub UA the
1751
+ * inference path also carries), parsing the rolling 5h + weekly DUAL buckets —
1752
+ * split by counter family (Google / Anthropic / OpenAI) — into per-model-family
1753
+ * allowance windows: `remainingFraction` (0–1) → used percent, `resetTime` →
1754
+ * resetsAt, `disabled` → the window's hard-block flag. The shared
1755
+ * counter-family ←→ model-family map lives in core (`antigravityQuotaFamily`).
1756
+ *
1757
+ * FALLBACK: when the summary RPC fails, `v1internal:fetchAvailableModels`'s
1758
+ * per-model `quotaInfo` is the legacy source — the collect then updates from
1759
+ * it instead. A total failure NEVER clears the existing windows (stale-marking
1760
+ * only), mirroring the sibling collectors.
1761
+ *
1762
+ * Mirrors the sibling collectors' cache contract: 5-minute cache, per-account
1763
+ * in-flight merging, one 401/403→refresh→retry. Unlike gemini (per-model
1764
+ * fractions, display-only), antigravity IS in the allowance scheduling
1765
+ * whitelist — the account-level dual buckets fit the worst-window rule.
1766
+ *
1767
+ * @module @omnicross/daemon/allowance/AntigravityAllowanceCollector
1768
+ */
1769
+
1770
+ interface AntigravityAllowanceCredentialReader {
1771
+ getAccessTokenForAccount(providerId: 'antigravity', accountId: string): Promise<string | null>;
1772
+ refreshAccountToken(providerId: 'antigravity', accountId: string): Promise<boolean>;
1773
+ }
1774
+ type AntigravityAllowanceFetch = (url: string, init: RequestInit, accountId: string) => Promise<Response>;
1775
+ interface AntigravityAllowanceCollectOptions {
1776
+ force?: boolean;
1777
+ refreshAheadMs?: number;
1778
+ }
1779
+ declare class AntigravityAllowanceCollector {
1780
+ private readonly credentials;
1781
+ private readonly store;
1782
+ private readonly fetchImpl;
1783
+ private readonly now;
1784
+ private readonly inFlight;
1785
+ constructor(credentials: AntigravityAllowanceCredentialReader, store?: AccountAllowanceStore, fetchImpl?: AntigravityAllowanceFetch, now?: () => number);
1786
+ collectMany(accounts: readonly SubscriptionAccountEntry<AntigravityTokenConfig>[], options?: AntigravityAllowanceCollectOptions): Promise<AccountAllowanceSnapshot[]>;
1787
+ collect(account: SubscriptionAccountEntry<AntigravityTokenConfig>, options?: AntigravityAllowanceCollectOptions): Promise<AccountAllowanceSnapshot>;
1788
+ private isCacheValid;
1789
+ private fetchAccount;
1790
+ /** One upstream round-trip with the antigravity/hub masquerade UA. */
1791
+ private request;
1792
+ private snapshot;
1793
+ private failureSnapshot;
1794
+ private unsupportedSnapshot;
1795
+ }
1796
+
1689
1797
  /**
1690
1798
  * OpenCodeGo usage collector.
1691
1799
  *
@@ -1733,8 +1841,8 @@ declare class OpenCodeGoAllowanceCollector {
1733
1841
  * literals — extending them all would make the overloads conflict.
1734
1842
  */
1735
1843
  interface AccountAllowanceCredentialReader {
1736
- getAccessTokenForAccount(providerId: 'claude' | 'codex' | 'kimi' | 'opencodego' | 'grok' | 'copilot' | 'gemini', accountId: string): Promise<string | null>;
1737
- refreshAccountToken(providerId: 'claude' | 'codex' | 'kimi' | 'grok' | 'copilot' | 'gemini', accountId: string): Promise<boolean>;
1844
+ getAccessTokenForAccount(providerId: 'claude' | 'codex' | 'kimi' | 'opencodego' | 'grok' | 'copilot' | 'gemini' | 'antigravity', accountId: string): Promise<string | null>;
1845
+ refreshAccountToken(providerId: 'claude' | 'codex' | 'kimi' | 'grok' | 'copilot' | 'gemini' | 'antigravity', accountId: string): Promise<boolean>;
1738
1846
  getFullConfig(): Promise<AccountTokensConfig>;
1739
1847
  }
1740
1848
  interface AccountAllowanceFilter {
@@ -1756,7 +1864,8 @@ declare class AccountAllowanceService {
1756
1864
  readonly copilotCollector: CopilotAllowanceCollector;
1757
1865
  readonly opencodegoCollector: OpenCodeGoAllowanceCollector;
1758
1866
  readonly geminiCollector: GeminiAllowanceCollector;
1759
- constructor(credentials: AccountAllowanceCredentialReader, store?: AccountAllowanceStore, collector?: ClaudeAllowanceCollector, codexCollector?: CodexAllowanceCollector, kimiCollector?: KimiAllowanceCollector, opencodegoCollector?: OpenCodeGoAllowanceCollector, grokCollector?: GrokAllowanceCollector, copilotCollector?: CopilotAllowanceCollector, geminiCollector?: GeminiAllowanceCollector, now?: () => number);
1867
+ readonly antigravityCollector: AntigravityAllowanceCollector;
1868
+ constructor(credentials: AccountAllowanceCredentialReader, store?: AccountAllowanceStore, collector?: ClaudeAllowanceCollector, codexCollector?: CodexAllowanceCollector, kimiCollector?: KimiAllowanceCollector, opencodegoCollector?: OpenCodeGoAllowanceCollector, grokCollector?: GrokAllowanceCollector, copilotCollector?: CopilotAllowanceCollector, geminiCollector?: GeminiAllowanceCollector, antigravityCollector?: AntigravityAllowanceCollector, now?: () => number);
1760
1869
  /**
1761
1870
  * Read all/filtered snapshots. Claude's and Codex's five-minute caches are
1762
1871
  * refreshed lazily on read (Codex polls `/backend-api/wham/usage`; the
@@ -1782,6 +1891,8 @@ declare class AccountAllowanceService {
1782
1891
  refreshGrok(accountId?: string): Promise<AccountAllowanceSnapshot[]>;
1783
1892
  /** Force-refresh Gemini usage (Code Assist retrieveUserQuota) for one/all accounts. */
1784
1893
  refreshGemini(accountId?: string): Promise<AccountAllowanceSnapshot[]>;
1894
+ /** Force-refresh Antigravity usage (quotaSummary dual buckets) for one/all accounts. */
1895
+ refreshAntigravity(accountId?: string): Promise<AccountAllowanceSnapshot[]>;
1785
1896
  /**
1786
1897
  * Keep Claude + Codex + Kimi snapshots warm for allowance-aware routing. All
1787
1898
  * collectors preserve their cache + per-account in-flight coalescing; a tick
@@ -2277,14 +2388,22 @@ interface ImageRuntimeManagerStatus {
2277
2388
  readonly draining: readonly ImageRuntimeGenerationStatus[];
2278
2389
  }
2279
2390
  type ImageRuntimeSafeUnavailableReason = ImageCapabilityUnavailableReason | 'disabled' | 'runtime_unavailable';
2391
+
2280
2392
  interface ImageRuntimeCapabilityInspection {
2281
2393
  readonly generationId: string;
2282
2394
  readonly enabled: boolean;
2283
2395
  readonly available: boolean;
2284
- readonly providerId?: 'codex-subscription';
2396
+ readonly providerId?: ImageProviderId;
2285
2397
  readonly model?: string;
2286
2398
  readonly reason?: ImageRuntimeSafeUnavailableReason;
2287
2399
  readonly capabilities?: ImageCapabilities;
2400
+ /**
2401
+ * Route-table keys whose ROUTED provider's fresh capability intersection
2402
+ * affirms them (multi-provider-image-generation 6.1: /v1/models lists
2403
+ * routed-model × fresh-evidence). Absent on synthetic/legacy generations —
2404
+ * `listAvailableModels` then falls back to the single-model shape.
2405
+ */
2406
+ readonly routedModels?: readonly string[];
2288
2407
  }
2289
2408
  interface ImageRuntimeResourceStatus {
2290
2409
  readonly queue: Readonly<{
@@ -2836,6 +2955,37 @@ declare class IntegrationManager {
2836
2955
  private renderInstalled;
2837
2956
  }
2838
2957
 
2958
+ /**
2959
+ * accountsAntigravityOAuth — the daemon admin API's ANTIGRAVITY interactive
2960
+ * OAuth path (`POST /accounts/antigravity/oauth/start` +
2961
+ * `GET /accounts/antigravity/oauth/:sessionId/status`).
2962
+ *
2963
+ * Modeled on the codex loopback flow (`accountsCodexOAuth`): antigravity's
2964
+ * redirect is a FIXED loopback `http://127.0.0.1:51121/oauth-callback`, so the
2965
+ * flow is ASYNC + POLLED — `start` arms the one-shot loopback listener, kicks
2966
+ * the capture→exchange→email→project-handshake→persist chain off ASYNC, and
2967
+ * returns ONLY `{ authUrl, sessionId }` (public — client_id + state). The app
2968
+ * opens `authUrl`; the browser redirects to the loopback; the daemon captures
2969
+ * the `code`, validates `state`, exchanges it, resolves the userinfo email and
2970
+ * the Code Assist project (the antigravity dialect of the shared resolver),
2971
+ * and persists the minted token through the encrypted credential store. The
2972
+ * app POLLS `status` until `done`/`error`.
2973
+ *
2974
+ * SECRET SPINE (same invariant as codex/grok): the minted access/refresh token
2975
+ * NEVER crosses to the client — it lands ONLY in the encrypted store. The
2976
+ * poll `status` body is TOKEN-FREE (`{ state, message? }`). Port 51121 is a
2977
+ * single resource → only ONE antigravity sign-in may be in flight (409).
2978
+ *
2979
+ * REUSES the `@omnicross/subscriptions` antigravity flow + the CLI's
2980
+ * `awaitLoopbackCode` listener (parameterized binding) — it does NOT rebuild
2981
+ * the authorize/exchange/handshake logic.
2982
+ *
2983
+ * @module @omnicross/daemon/admin/accountsAntigravityOAuth
2984
+ */
2985
+
2986
+ /** The loopback-listener fn (injected so tests need not bind a real port). */
2987
+ type AntigravityLoopbackFn = (state: string, timeoutMs?: number, signal?: AbortSignal) => Promise<string>;
2988
+
2839
2989
  /**
2840
2990
  * cliLaunch — the admin API's "launch a coding CLI in a terminal, pointed at the
2841
2991
  * daemon" surface (dashboard parity with the desktop app's Code CLI tab).
@@ -2994,6 +3144,8 @@ interface AccountAllowanceAdminReader {
2994
3144
  refreshCopilot?(accountId?: string): Promise<AccountAllowanceSnapshot[]>;
2995
3145
  /** Optional: Gemini Code-Assist quota refresh (absent on older daemons). */
2996
3146
  refreshGemini?(accountId?: string): Promise<AccountAllowanceSnapshot[]>;
3147
+ /** Optional: Antigravity quotaSummary refresh (absent on older daemons). */
3148
+ refreshAntigravity?(accountId?: string): Promise<AccountAllowanceSnapshot[]>;
2997
3149
  removeAccountSnapshot?(providerId: SubscriptionProviderId, accountId: string): void;
2998
3150
  removeProviderSnapshots?(providerId: SubscriptionProviderId): void;
2999
3151
  getSchedulingStatus?(): AccountAllowanceSchedulingStatus;
@@ -3153,6 +3305,16 @@ interface AdminApiDeps {
3153
3305
  * polled shape; one sign-in at a time. Wired in `bootstrap.ts`.
3154
3306
  */
3155
3307
  readonly copilotSessions: CodexOAuthSessionStore;
3308
+ /** Antigravity interactive OAuth (loopback 51121) — the async flow store. */
3309
+ readonly antigravitySessions: CodexOAuthSessionStore;
3310
+ /** The one-shot 127.0.0.1:51121 listener (test seam like `codexAwaitLoopback`). */
3311
+ readonly antigravityAwaitLoopback: AntigravityLoopbackFn;
3312
+ /**
3313
+ * Resolve the ACTIVE antigravity account's access token for the dynamic
3314
+ * model-catalog probe (secret used daemon-side only; the route is
3315
+ * secret-free). Optional for older tests; absent → static-only catalog.
3316
+ */
3317
+ readonly resolveAntigravityAccessToken?: () => Promise<string | null>;
3156
3318
  /**
3157
3319
  * Codex loopback listener (app-parity-2 child 5) — defaults to `awaitLoopbackCode`
3158
3320
  * (binds 127.0.0.1:1455) in `bootstrap.ts`; tests inject a mock so no real port
@@ -3648,10 +3810,12 @@ declare class MountedResponsesImageStateStore implements ResponsesImageStateStor
3648
3810
  interface ImageDoctorLocalSnapshot {
3649
3811
  readonly config: Readonly<{
3650
3812
  enabled: boolean;
3651
- provider: 'codex-subscription';
3813
+ provider: ImageProviderId;
3652
3814
  model: string;
3653
3815
  valid: boolean;
3654
3816
  errorCount: number;
3817
+ /** Distinct providers the routing table names (doctor per-provider rows). */
3818
+ routedProviders: readonly ImageProviderId[];
3655
3819
  }>;
3656
3820
  readonly roots: Readonly<{
3657
3821
  valid: boolean;
@@ -3675,11 +3839,18 @@ interface ImageDoctorLocalSnapshot {
3675
3839
  invalidRows: number;
3676
3840
  imagesAuthorizedRows: number;
3677
3841
  }>;
3842
+ /** The Codex-subscription account backing codex-routed image models. */
3678
3843
  readonly account: Readonly<{
3679
3844
  present: boolean;
3680
3845
  usable: boolean;
3681
3846
  reason: 'ready' | 'missing' | 'unavailable';
3682
3847
  }>;
3848
+ /** The Antigravity-subscription account backing NanoBanana image models. */
3849
+ readonly antigravityAccount: Readonly<{
3850
+ present: boolean;
3851
+ usable: boolean;
3852
+ reason: 'ready' | 'missing' | 'unavailable';
3853
+ }>;
3683
3854
  readonly evidence: Readonly<FileCodexImageCapabilityEvidenceStatus & {
3684
3855
  valid: boolean;
3685
3856
  }>;
@@ -4600,6 +4771,11 @@ interface DaemonPaths {
4600
4771
  * so tests need not bind `127.0.0.1:1455`. Absent → the real `awaitLoopbackCode`.
4601
4772
  */
4602
4773
  codexAwaitLoopback?: CodexLoopbackFn;
4774
+ /**
4775
+ * TEST SEAM (optional): override the antigravity loopback listener so tests
4776
+ * need not bind 127.0.0.1:51121. Absent → the real awaitLoopbackCode.
4777
+ */
4778
+ antigravityAwaitLoopback?: AntigravityLoopbackFn;
4603
4779
  /**
4604
4780
  * TEST SEAM (optional): override the OAuth token-exchange fetch so tests need not
4605
4781
  * hit a real token endpoint. Absent → the global `fetch`.