dsh-plugin-subscription-usage 0.0.0-stage → 0.2.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.
Files changed (169) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +50 -2
  3. package/cordis.patch.yml +5 -0
  4. package/icon.svg +9 -0
  5. package/lib/auth/claude-code-creds.d.ts +23 -0
  6. package/lib/auth/claude-code-creds.js +172 -0
  7. package/lib/auth/device-flow.d.ts +55 -0
  8. package/lib/auth/device-flow.js +177 -0
  9. package/lib/auth/jwt.d.ts +10 -0
  10. package/lib/auth/jwt.js +25 -0
  11. package/lib/auth/oauth-flow.d.ts +91 -0
  12. package/lib/auth/oauth-flow.js +227 -0
  13. package/lib/auth/pkce.d.ts +31 -0
  14. package/lib/auth/pkce.js +35 -0
  15. package/lib/auth/rpc.d.ts +233 -0
  16. package/lib/auth/rpc.js +501 -0
  17. package/lib/auth/store.d.ts +198 -0
  18. package/lib/auth/store.js +473 -0
  19. package/lib/client/Footer.d.ts +3 -0
  20. package/lib/client/Footer.js +73 -0
  21. package/lib/client/Gauge.d.ts +28 -0
  22. package/lib/client/Gauge.js +139 -0
  23. package/lib/client/ImageGallery.d.ts +54 -0
  24. package/lib/client/ImageGallery.js +112 -0
  25. package/lib/client/ImageGenerateToolview.d.ts +48 -0
  26. package/lib/client/ImageGenerateToolview.js +130 -0
  27. package/lib/client/Notice.d.ts +15 -0
  28. package/lib/client/Notice.js +93 -0
  29. package/lib/client/ProviderCard.d.ts +35 -0
  30. package/lib/client/ProviderCard.js +240 -0
  31. package/lib/client/SpeedSelect.d.ts +72 -0
  32. package/lib/client/SpeedSelect.js +214 -0
  33. package/lib/client/Usage.d.ts +7 -0
  34. package/lib/client/Usage.js +83 -0
  35. package/lib/client/VideoGenerateToolview.d.ts +42 -0
  36. package/lib/client/VideoGenerateToolview.js +172 -0
  37. package/lib/client/context.d.ts +16 -0
  38. package/lib/client/context.js +11 -0
  39. package/lib/client/fast-command.d.ts +2 -0
  40. package/lib/client/fast-command.js +4 -0
  41. package/lib/client/hooks.d.ts +2 -0
  42. package/lib/client/hooks.js +10 -0
  43. package/lib/client/index.d.ts +3 -0
  44. package/lib/client/index.js +113 -0
  45. package/lib/client/locales.d.ts +139 -0
  46. package/lib/client/locales.js +267 -0
  47. package/lib/client/meter.d.ts +91 -0
  48. package/lib/client/meter.js +196 -0
  49. package/lib/client/prefs.d.ts +51 -0
  50. package/lib/client/prefs.js +71 -0
  51. package/lib/client/rpc.d.ts +161 -0
  52. package/lib/client/rpc.js +31 -0
  53. package/lib/client/store.d.ts +67 -0
  54. package/lib/client/store.js +129 -0
  55. package/lib/client/styles.d.ts +7 -0
  56. package/lib/client/styles.js +176 -0
  57. package/lib/client.js +3933 -0
  58. package/lib/client.js.map +1 -0
  59. package/lib/compat.d.ts +55 -0
  60. package/lib/compat.js +20 -0
  61. package/lib/http.d.ts +134 -0
  62. package/lib/http.js +431 -0
  63. package/lib/index.d.ts +121 -0
  64. package/lib/index.js +13399 -0
  65. package/lib/json-text.d.ts +2 -0
  66. package/lib/json-text.js +4 -0
  67. package/lib/model-defaults.d.ts +23 -0
  68. package/lib/model-defaults.js +238 -0
  69. package/lib/model-speeds.d.ts +10 -0
  70. package/lib/model-speeds.js +48 -0
  71. package/lib/models-directory.d.ts +17 -0
  72. package/lib/models-directory.js +25 -0
  73. package/lib/provider-settings.d.ts +55 -0
  74. package/lib/provider-settings.js +215 -0
  75. package/lib/providers/account-preferences.d.ts +46 -0
  76. package/lib/providers/account-preferences.js +188 -0
  77. package/lib/providers/accounts.d.ts +113 -0
  78. package/lib/providers/accounts.js +142 -0
  79. package/lib/providers/antigravity-oauth-client.d.ts +7 -0
  80. package/lib/providers/antigravity-oauth-client.js +7 -0
  81. package/lib/providers/antigravity.d.ts +119 -0
  82. package/lib/providers/antigravity.js +552 -0
  83. package/lib/providers/catalog-refresh.d.ts +4 -0
  84. package/lib/providers/catalog-refresh.js +30 -0
  85. package/lib/providers/catalog-store.d.ts +47 -0
  86. package/lib/providers/catalog-store.js +283 -0
  87. package/lib/providers/claude-cli-version.d.ts +15 -0
  88. package/lib/providers/claude-cli-version.js +24 -0
  89. package/lib/providers/claude.d.ts +212 -0
  90. package/lib/providers/claude.js +726 -0
  91. package/lib/providers/codex-client-version.d.ts +8 -0
  92. package/lib/providers/codex-client-version.js +17 -0
  93. package/lib/providers/codex-search.d.ts +29 -0
  94. package/lib/providers/codex-search.js +198 -0
  95. package/lib/providers/codex.d.ts +253 -0
  96. package/lib/providers/codex.js +930 -0
  97. package/lib/providers/common.d.ts +415 -0
  98. package/lib/providers/common.js +679 -0
  99. package/lib/providers/copilot.d.ts +365 -0
  100. package/lib/providers/copilot.js +956 -0
  101. package/lib/providers/grok.d.ts +214 -0
  102. package/lib/providers/grok.js +750 -0
  103. package/lib/providers/image-pool.d.ts +30 -0
  104. package/lib/providers/image-pool.js +89 -0
  105. package/lib/providers/npm-cli-version.d.ts +56 -0
  106. package/lib/providers/npm-cli-version.js +98 -0
  107. package/lib/providers/pool-family.d.ts +56 -0
  108. package/lib/providers/pool-family.js +45 -0
  109. package/lib/providers/pool-health.d.ts +91 -0
  110. package/lib/providers/pool-health.js +164 -0
  111. package/lib/providers/pool-usage.d.ts +106 -0
  112. package/lib/providers/pool-usage.js +302 -0
  113. package/lib/providers/pool.d.ts +115 -0
  114. package/lib/providers/pool.js +461 -0
  115. package/lib/providers/rate-limit.d.ts +192 -0
  116. package/lib/providers/rate-limit.js +338 -0
  117. package/lib/providers/replay.d.ts +4 -0
  118. package/lib/providers/replay.js +37 -0
  119. package/lib/providers/reset-redemption.d.ts +20 -0
  120. package/lib/providers/reset-redemption.js +70 -0
  121. package/lib/tools/image-generate.d.ts +128 -0
  122. package/lib/tools/image-generate.js +438 -0
  123. package/lib/tools/registration.d.ts +16 -0
  124. package/lib/tools/registration.js +25 -0
  125. package/lib/tools/usage.d.ts +62 -0
  126. package/lib/tools/usage.js +89 -0
  127. package/lib/tools/video-generate.d.ts +89 -0
  128. package/lib/tools/video-generate.js +257 -0
  129. package/lib/tools/x-search.d.ts +58 -0
  130. package/lib/tools/x-search.js +197 -0
  131. package/lib/translate/anthropic.d.ts +180 -0
  132. package/lib/translate/anthropic.js +534 -0
  133. package/lib/translate/antigravity-images.d.ts +11 -0
  134. package/lib/translate/antigravity-images.js +62 -0
  135. package/lib/translate/antigravity-schema.d.ts +4 -0
  136. package/lib/translate/antigravity-schema.js +145 -0
  137. package/lib/translate/antigravity-thinking.d.ts +5 -0
  138. package/lib/translate/antigravity-thinking.js +44 -0
  139. package/lib/translate/antigravity.d.ts +120 -0
  140. package/lib/translate/antigravity.js +412 -0
  141. package/lib/translate/chat-completions.d.ts +120 -0
  142. package/lib/translate/chat-completions.js +382 -0
  143. package/lib/translate/resolved.d.ts +98 -0
  144. package/lib/translate/resolved.js +186 -0
  145. package/lib/translate/responses.d.ts +192 -0
  146. package/lib/translate/responses.js +443 -0
  147. package/lib/translate/sse.d.ts +21 -0
  148. package/lib/translate/sse.js +62 -0
  149. package/lib/usage/headers.d.ts +21 -0
  150. package/lib/usage/headers.js +64 -0
  151. package/lib/usage/pace.d.ts +53 -0
  152. package/lib/usage/pace.js +48 -0
  153. package/lib/usage/service.d.ts +64 -0
  154. package/lib/usage/service.js +104 -0
  155. package/lib/usage-providers/common.d.ts +23 -0
  156. package/lib/usage-providers/common.js +28 -0
  157. package/lib/usage-providers/index.d.ts +42 -0
  158. package/lib/usage-providers/index.js +71 -0
  159. package/lib/usage-providers/keys.d.ts +11 -0
  160. package/lib/usage-providers/keys.js +52 -0
  161. package/lib/usage-providers/kimi.d.ts +4 -0
  162. package/lib/usage-providers/kimi.js +52 -0
  163. package/lib/usage-providers/ollama-cloud.d.ts +4 -0
  164. package/lib/usage-providers/ollama-cloud.js +42 -0
  165. package/lib/usage-providers/zai.d.ts +5 -0
  166. package/lib/usage-providers/zai.js +53 -0
  167. package/locale/en.json +6 -0
  168. package/locale/zh.json +6 -0
  169. package/package.json +115 -4
@@ -0,0 +1,365 @@
1
+ /**
2
+ * GitHub Copilot subscription provider: OAuth device-authorization flow with
3
+ * the VS Code Copilot Chat client id, a GitHub-token → Copilot-token exchange
4
+ * against `copilot_internal/v2/token`, and streaming against two upstream
5
+ * protocols chosen per model: the OpenAI-compatible chat completions endpoint
6
+ * for models whose catalog entry lists `/chat/completions`, and the Responses
7
+ * endpoint for the newer model families (gpt-5.5/5.6, …) that only list
8
+ * `/responses`. Both upstreams are stream-only.
9
+ *
10
+ * Two token generations are in play: the long-lived GitHub OAuth token (kept
11
+ * as the session's `refreshToken`) and the ~30-minute Copilot API token it
12
+ * exchanges into (the session's `accessToken`). A TokenManager "refresh" is a
13
+ * fresh exchange, so the standard preempt/401-retry machinery applies
14
+ * unchanged.
15
+ */
16
+ import { LlmAdapter } from '@deepseek-ai/dsh-llm';
17
+ import type { GenerateOptions, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, StreamChunk } from '@deepseek-ai/dsh-llm';
18
+ import type { DeviceFlowSpec } from '../auth/device-flow.js';
19
+ import type { CopilotSession } from '../auth/store.js';
20
+ import type { PoolAdapter } from './pool.js';
21
+ import type { AttachmentStore } from '@deepseek-ai/dsh-attachment';
22
+ import type { ReasoningReplayItem, ResponsesRequestInput, ResponsesStreamEvent } from '../translate/responses.js';
23
+ import { AccountTokenManager } from './accounts.js';
24
+ import type { CatalogPersistence, DiscoveredModel, FetchFn, ModelEntry, ProviderUsage } from './common.js';
25
+ import type { RateLimitWait } from './rate-limit.js';
26
+ /**
27
+ * Client id of the VS Code Copilot Chat GitHub App (pi-mono and
28
+ * copilot2api-go use the same value): the app is pre-authorized for the
29
+ * Copilot internal token exchange, a self-registered OAuth App is not.
30
+ */
31
+ export declare const COPILOT_CLIENT_ID = "Iv1.b507a08c87ecfe98";
32
+ export declare const COPILOT_DEVICE_CODE_URL = "https://github.com/login/device/code";
33
+ export declare const COPILOT_DEVICE_TOKEN_URL = "https://github.com/login/oauth/access_token";
34
+ export declare const COPILOT_TOKEN_URL = "https://api.github.com/copilot_internal/v2/token";
35
+ export declare const GITHUB_USER_URL = "https://api.github.com/user";
36
+ export declare const COPILOT_API_URL = "https://api.githubcopilot.com/chat/completions";
37
+ /** Responses endpoint for models whose catalog entry only lists `/responses`. */
38
+ export declare const COPILOT_RESPONSES_URL = "https://api.githubcopilot.com/responses";
39
+ export declare const COPILOT_MODELS_URL = "https://api.githubcopilot.com/models";
40
+ /** Refresh when the Copilot API token has less than this much life left. */
41
+ export declare const COPILOT_PREEMPT_MS: number;
42
+ /**
43
+ * The VS Code update feed answers a JSON array of version strings, latest
44
+ * stable first. The Copilot API rejects requests whose Editor-Version is too
45
+ * old with `401 IDE token expired`, so the version is resolved live (cached
46
+ * for a day) instead of hardcoded — a stale hardcode bricks every request.
47
+ */
48
+ export declare const VSCODE_RELEASES_URL = "https://update.code.visualstudio.com/api/releases/stable";
49
+ /** Last-known-good VS Code version when the feed is unreachable. */
50
+ export declare const FALLBACK_VSCODE_VERSION = "1.107.0";
51
+ /**
52
+ * Resolve the VS Code version presented as Editor-Version: the latest stable
53
+ * from the update feed, cached for a day, falling back to a pinned version
54
+ * when the feed fails. Concurrent resolves coalesce behind one fetch.
55
+ * @param fetchFn - fetch implementation (injectable for tests).
56
+ * @param forceRefresh - bypass the cache (a 401 `IDE token expired` retry).
57
+ * @returns a `major.minor.patch` version string.
58
+ */
59
+ export declare function latestVsCodeVersion(fetchFn?: FetchFn, forceRefresh?: boolean): Promise<string>;
60
+ /**
61
+ * The device-flow facts for the auth controller's DeviceFlowManager.
62
+ * @returns the flow spec for one attempt.
63
+ */
64
+ export declare function copilotDeviceFlow(): DeviceFlowSpec;
65
+ /**
66
+ * Header set presenting requests as the VS Code Copilot Chat extension; the
67
+ * Copilot API rejects traffic without an editor identity.
68
+ * @param hasVision - whether the request carries image input.
69
+ * @param vscodeVersion - Editor-Version value from {@link latestVsCodeVersion}.
70
+ * @returns headers to merge into Copilot API requests.
71
+ */
72
+ export declare function copilotHeaders(hasVision?: boolean, vscodeVersion?: string): Record<string, string>;
73
+ /** The freshly exchanged Copilot API token half of a session. */
74
+ interface CopilotTokenPair {
75
+ accessToken: string;
76
+ expiresAt: number;
77
+ }
78
+ /**
79
+ * Exchange a long-lived GitHub OAuth token for a short-lived Copilot API
80
+ * token. A 401/403 means the GitHub token is revoked or the account lost its
81
+ * Copilot subscription — permanent, re-login required.
82
+ * @param githubToken - the GitHub OAuth token from the device flow.
83
+ * @param fetchFn - fetch implementation (injectable for tests).
84
+ * @returns the Copilot API token and its expiry.
85
+ */
86
+ export declare function exchangeCopilotToken(githubToken: string, fetchFn?: FetchFn): Promise<CopilotTokenPair>;
87
+ /** GitHub's Copilot account endpoint; it reports the monthly premium-request quota. */
88
+ export declare const COPILOT_USER_URL = "https://api.github.com/copilot_internal/user";
89
+ /**
90
+ * Monthly premium-request usage of one Copilot account. Chat and completions
91
+ * report `unlimited` on paid plans and are skipped; a plan without a premium
92
+ * quota returns no windows.
93
+ * @param githubToken - the GitHub OAuth token from the device flow (not the Copilot API token).
94
+ */
95
+ export declare function fetchCopilotUsage(githubToken: string, fetchFn?: FetchFn, signal?: AbortSignal): Promise<ProviderUsage>;
96
+ /** Length of the calendar month that ends at `resetsAt` (the quota resets on the 1st, UTC). */
97
+ export declare function monthBefore(resetsAt: number): number;
98
+ /**
99
+ * Complete a device-flow login: exchange the GitHub token for a Copilot API
100
+ * token and read the GitHub login name for the status display.
101
+ * @param githubToken - the GitHub OAuth token the device flow released.
102
+ * @param fetchFn - fetch implementation (injectable for tests).
103
+ * @returns the session to store.
104
+ */
105
+ export declare function completeCopilotLogin(githubToken: string, fetchFn?: FetchFn): Promise<CopilotSession>;
106
+ /**
107
+ * Refresh a copilot session: re-exchange the long-lived GitHub token for a
108
+ * fresh Copilot API token.
109
+ * @param session - the stored session.
110
+ * @param fetchFn - fetch implementation (injectable for tests).
111
+ * @returns the fresh session to store.
112
+ */
113
+ export declare function refreshCopilot(session: CopilotSession, fetchFn?: FetchFn): Promise<CopilotSession>;
114
+ /**
115
+ * Whether a copilot refresh failure means the login is permanently gone.
116
+ * @param error - the thrown refresh error.
117
+ * @returns true when re-login is the only fix (GitHub token revoked or the subscription lost).
118
+ */
119
+ export declare function isCopilotPermanentRefreshError(error: unknown): boolean;
120
+ /**
121
+ * Fetch the live Copilot model list. Models hidden from the picker or
122
+ * disabled by policy are excluded, as are models able to speak neither
123
+ * protocol this adapter knows: an entry listing `/chat/completions` speaks
124
+ * the chat wire, one listing only `/responses` (the newer GPT families,
125
+ * e.g. gpt-5.6) speaks the Responses wire, and the choice is recorded on the
126
+ * discovered entry so requests pick the matching endpoint; an entry listing
127
+ * BOTH endpoints additionally records `/responses` availability, which
128
+ * {@link copilotRequestWire} uses to reroute tools+effort requests. Vision
129
+ * support from the catalog becomes the model's input modalities, and a
130
+ * non-empty `supports.reasoning_effort` array becomes the model's selectable
131
+ * reasoning efforts (the endpoint discloses no default, so none is claimed).
132
+ * @param session - the stored session (used as-is; never refreshed here).
133
+ * @param fetchFn - fetch implementation (injectable for tests).
134
+ * @param signal - caller cancellation (pool-assembly timeout).
135
+ * @returns discovered chat models in endpoint order.
136
+ */
137
+ export declare function fetchCopilotModels(session: CopilotSession, fetchFn?: FetchFn, signal?: AbortSignal): Promise<DiscoveredModel[]>;
138
+ /** Which upstream protocol one Copilot model speaks. */
139
+ export type CopilotWire = 'chat-completions' | 'responses';
140
+ /**
141
+ * The wire protocol for one model: the discovered catalog entry's recorded
142
+ * choice, defaulting to chat completions for unknown models (static-catalog
143
+ * and no-discovery configurations, and models listing both endpoints).
144
+ * @param entry - the discovered catalog entry, when known.
145
+ * @returns the protocol the request for this model must speak.
146
+ */
147
+ export declare function copilotWireFor(entry: DiscoveredModel | undefined): CopilotWire;
148
+ /**
149
+ * The upstream protocol for ONE REQUEST: the model's default wire, except
150
+ * that a dual-protocol model defaulting to chat completions must reroute to
151
+ * Responses when the request combines function tools with a reasoning effort
152
+ * — Copilot rejects exactly that combination on /chat/completions with
153
+ * HTTP 400 invalid_request_body ("Function tools with reasoning_effort are
154
+ * not supported … use /v1/responses or set reasoning_effort to 'none'",
155
+ * observed on gpt-5.4) while /responses serves it. Effort 'none' stays on
156
+ * the chat wire (the API allows the combination there), and models not
157
+ * listing /responses never reroute.
158
+ * @param entry - the discovered catalog entry, when known.
159
+ * @param options - the harness generate options (tools + effort only).
160
+ * @returns the protocol the request for this model must speak.
161
+ */
162
+ export declare function copilotRequestWire(entry: DiscoveredModel | undefined, options: Pick<GenerateOptions, 'tools' | 'reasoningEffort'>): CopilotWire;
163
+ /**
164
+ * The chat completions request body for one generation. The output cap rides
165
+ * `max_completion_tokens` — the newer OpenAI-family models on Copilot reject
166
+ * the legacy `max_tokens` parameter outright (HTTP 400 "Unsupported
167
+ * parameter"), and the rest of the catalog accepts the new spelling.
168
+ * @param options - the harness generate options.
169
+ * @param messages - translated wire messages (images pre-resolved).
170
+ * @returns the JSON body.
171
+ */
172
+ export declare function copilotChatRequestBody(options: GenerateOptions, messages: Record<string, unknown>[]): Record<string, unknown>;
173
+ /**
174
+ * The Responses request body for one generation (the wire the `/responses`-
175
+ * only model families speak). Usage arrives on `response.completed`.
176
+ * @param options - the harness generate options.
177
+ * @param resolved - translated instructions + input (images pre-resolved).
178
+ * @returns the JSON body.
179
+ */
180
+ export declare function copilotResponsesRequestBody(options: GenerateOptions, resolved: ResponsesRequestInput): Record<string, unknown>;
181
+ /**
182
+ * Rewrite Copilot's Responses-gateway item ids into stable per-item keys.
183
+ * Unlike chatgpt.com's Responses backend, the Copilot gateway mints a FRESH
184
+ * opaque `item.id`/`item_id` on every event of one response (the `added`,
185
+ * each delta, and the `done` all differ), which defeats id-keyed block
186
+ * assembly in the shared translator: text fragments would each open their
187
+ * own block, `done` would synthesize duplicates, and a function call whose
188
+ * arguments arrive whole only on `done` (the deltas carry empty strings)
189
+ * would close empty. The stable key derives from the event's `output_index`
190
+ * — the item's position in the response's output array, which survives the
191
+ * gateway's per-event id churn even when two items' events interleave on
192
+ * the wire (parallel tool calls do exactly that). Events without an
193
+ * `output_index` fall back to the key of the last `output_item.added`, which
194
+ * is only correct while one item's events stay contiguous — the pre-
195
+ * interleaving behavior, kept for gateways that omit the field; with no
196
+ * `added` seen yet they key to `copilot-item-0` as before. Function-call
197
+ * identity additionally rides the gateway-stable `call_id`.
198
+ */
199
+ export declare class CopilotResponsesItemNormalizer {
200
+ private readonly onCaptured?;
201
+ private adds;
202
+ private lastKey;
203
+ /** Call ids and completed reasoning items collected for the open response. */
204
+ private capturedCallIds;
205
+ private capturedReasoning;
206
+ /**
207
+ * @param onCaptured - fired at each `response.completed` that produced BOTH
208
+ * function calls and completed reasoning items, receiving the response's
209
+ * call ids and replayable reasoning items so the adapter can replay them
210
+ * on the next request.
211
+ */
212
+ constructor(onCaptured?: ((callIds: string[], items: ReasoningReplayItem[]) => void) | undefined);
213
+ /**
214
+ * [2026-08-23]-[a single arrival-order ordinal mis-buckets every event after
215
+ * a second item's `added`, mangling interleaved parallel tool calls;
216
+ * output_index is the only correlator the gateway keeps stable]-[changes
217
+ * keys only for streams that carry output_index; no-index streams keep the
218
+ * old last-added-key behavior byte for byte]
219
+ */
220
+ private keyFor;
221
+ /**
222
+ * Rewrite one parsed Responses event.
223
+ * @param event - the event as parsed off the wire.
224
+ * @returns the event with a stable item key.
225
+ */
226
+ push(event: ResponsesStreamEvent): ResponsesStreamEvent;
227
+ }
228
+ /** Constructor dependencies for {@link CopilotAdapter}. */
229
+ export interface CopilotAdapterOptions {
230
+ /**
231
+ * Observes every upstream reply before its status is checked, with the
232
+ * resolved account key. Usage headers ride both 2xx and 429 replies.
233
+ */
234
+ onResponse?: (response: Response, account: string, sessionId: string | undefined) => void;
235
+ models: readonly ModelEntry[];
236
+ streamIdleTimeoutMs: number;
237
+ tokens: AccountTokenManager<CopilotSession>;
238
+ /** Late-bound pool facade (wired after adapter construction); pools list under their first member's provider. */
239
+ pool?: () => PoolAdapter | undefined;
240
+ /** Whether to fetch the live catalog when logged in (false when config `models` overrides). */
241
+ discovery: boolean;
242
+ /** Warning sink for discovery failures that fall back to the static catalog. */
243
+ onWarn?: (message: string) => void;
244
+ /** Fetch implementation for discovery (defaults to the proxy-aware fetch). */
245
+ fetchFn?: FetchFn;
246
+ /** Resolve the attachment service per request; absent means image requests fail loudly. */
247
+ resolveAttachments?: () => AttachmentStore | undefined;
248
+ /** Durable catalog store seeding capability metadata across restarts. */
249
+ catalogStore?: CatalogPersistence;
250
+ onCatalogChanged?: () => void;
251
+ accountCatalogStore?: (account: string) => CatalogPersistence;
252
+ /** How long this route may hold a turn open waiting for a rate-limit window; defaults to waiting on, six-hour ceiling. */
253
+ rateLimit?: RateLimitWait;
254
+ /**
255
+ * Per-model default reasoning effort override (the Settings page's picker).
256
+ * Returns the user-configured default for one model, or undefined to follow
257
+ * the provider's own default.
258
+ */
259
+ defaultEffortOf?: (model: string) => string | undefined;
260
+ }
261
+ /** Copilot wire adapter: one instance serves the `copilot` provider route. */
262
+ export declare class CopilotAdapter extends LlmAdapter {
263
+ private readonly options;
264
+ private readonly catalog;
265
+ /** In-memory catalogs for non-default accounts (the persisted cache is the default's). */
266
+ private readonly accountCatalogs;
267
+ private accountCatalogsInvalidated;
268
+ private readonly invalidatedAccounts;
269
+ /** Account whose snapshot currently lives in {@link catalog}; cleared on default change. */
270
+ private catalogOwner;
271
+ /**
272
+ * [2026-08-23]-[a reasoning model continuing a tool chain must get its
273
+ * reasoning back or it restarts from scratch every tool round trip; the
274
+ * items live in ADAPTER memory because dsh-llm's reasoning ContentBlock is
275
+ * a closed shape that cannot carry them through the harness]-[entries are
276
+ * namespaced per ACCOUNT × CONVERSATION × MODEL, idle out via a sliding
277
+ * TTL, and the whole store is dropped on auth transitions, so replay
278
+ * degrades to the old behavior instead of leaking across contexts]
279
+ */
280
+ private readonly replayByScope;
281
+ /** Call-id entries kept per scope; see {@link captureReasoning}. */
282
+ private static readonly REPLAY_CALL_LIMIT;
283
+ /** Conversation scopes kept at once; bounds memory when many sessions interleave. */
284
+ private static readonly REPLAY_SCOPE_LIMIT;
285
+ /** How long a captured entry stays replayable; tool round trips take minutes, not hours. */
286
+ private static readonly REPLAY_TTL_MS;
287
+ constructor(options: CopilotAdapterOptions);
288
+ /** Discovery fetcher: resolves the session through the refresh-aware path. */
289
+ private fetchCatalog;
290
+ /** Drop cached catalogs after login/logout so the next list does not reuse a stale plan. */
291
+ clearAccountCatalog(account?: string): void;
292
+ /** Default and secondary accounts each seed their own persisted catalog. */
293
+ private catalogFor;
294
+ providerInfo(provider: string): LlmProviderInfo;
295
+ providerRetryPolicy(provider: string): import("@deepseek-ai/dsh-llm").ResolvedRetryPolicy;
296
+ private staticModels;
297
+ listModels(provider: string): Promise<readonly LlmModelInfo[]>;
298
+ /** The provider's own catalog: union of every account, or one account when named. */
299
+ listOwnModels(provider: string, account?: string, signal?: AbortSignal, preferCached?: boolean): Promise<readonly LlmModelInfo[]>;
300
+ /**
301
+ * The discovered entry for one model. Resolved through the cache's
302
+ * stale-while-revalidate path: capability metadata must stay stable across
303
+ * a long conversation — a mid-turn refetch must neither block nor fail the
304
+ * call before provider I/O.
305
+ */
306
+ private discovered;
307
+ /**
308
+ * [2026-08-23]-[a manually configured responses-only model combined with
309
+ * `discovery:false` left discovered() undefined, so copilotRequestWire
310
+ * silently defaulted to /chat/completions and the request 404/400'd at the
311
+ * gateway; an explicit config wire must win over catalog inference]-[config
312
+ * `models[].wire` now routes the request even without discovery]
313
+ */
314
+ private configuredWireEntry;
315
+ /**
316
+ * The replay scope isolating one ACCOUNT × CONVERSATION × MODEL. The
317
+ * account identity is the session's long-lived GitHub token (stable across
318
+ * Copilot-token refreshes, different per GitHub login); the conversation is
319
+ * the loop-stamped `sessionId`, falling back to the first message's id
320
+ * when a hand-built request carries no session stamp. Identity-free
321
+ * requests have no replay scope; the model separates
322
+ * wire families. A call id captured in one scope is invisible to every
323
+ * other scope, so reused ids cannot leak reasoning across accounts,
324
+ * conversations, or models.
325
+ */
326
+ private replayScope;
327
+ /**
328
+ * Store one response's completed reasoning items behind every call id it
329
+ * produced, inside one replay scope. Retention: a CONSUMED entry is kept —
330
+ * every later round of the same conversation replays ALL its earlier
331
+ * function_calls — until it idles out of the TTL (see {@link replayFor})
332
+ * or the per-scope entry cap evicts it oldest-first. All calls of one
333
+ * response share ONE entry object: toResponsesInput dedupes replays by
334
+ * array reference, so parallel calls replay the items once instead of once
335
+ * per call.
336
+ */
337
+ private captureReasoning;
338
+ /**
339
+ * The replay items for one call id in one scope, when still fresh. The TTL
340
+ * bounds IDLE time, not total age: a hit refreshes the entry (and its
341
+ * eviction recency), so an ongoing conversation keeps its chain alive
342
+ * while a conversation that stopped asking forgets within the TTL. An
343
+ * absent or aged-out entry answers `undefined` — the no-replay
344
+ * degradation, never an error.
345
+ */
346
+ private replayFor;
347
+ /**
348
+ * Drop every captured replay entry. Lookup correctness never depends on
349
+ * the call — the scope already carries the account identity — but the host
350
+ * wiring invokes this on every copilot auth transition (login, logout,
351
+ * credential death) so a switched account's memory never holds the
352
+ * previous account's encrypted reasoning at all; conversation teardown is
353
+ * bounded by the TTL and the caps.
354
+ */
355
+ clearReplayState(): void;
356
+ resolveModel(provider: string, model: string): Promise<LlmResolvedModelInfo>;
357
+ /** Capability resolution of the provider's own models (the pool resolves members here). */
358
+ resolveOwnModel(provider: string, model: string): Promise<LlmResolvedModelInfo>;
359
+ stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
360
+ /** Pool seam: stream through one specific account instead of the default. */
361
+ streamAccount(options: GenerateOptions, account: string): AsyncIterable<StreamChunk>;
362
+ private streamCore;
363
+ private request;
364
+ }
365
+ export {};