dsh-subscriptions 0.1.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 (150) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -0
  3. package/cordis.patch.yml +12 -0
  4. package/lib/auth/claude-code-creds.d.ts +23 -0
  5. package/lib/auth/claude-code-creds.js +172 -0
  6. package/lib/auth/device-flow.d.ts +55 -0
  7. package/lib/auth/device-flow.js +177 -0
  8. package/lib/auth/jwt.d.ts +10 -0
  9. package/lib/auth/jwt.js +25 -0
  10. package/lib/auth/oauth-flow.d.ts +91 -0
  11. package/lib/auth/oauth-flow.js +227 -0
  12. package/lib/auth/pkce.d.ts +31 -0
  13. package/lib/auth/pkce.js +35 -0
  14. package/lib/auth/rpc.d.ts +209 -0
  15. package/lib/auth/rpc.js +386 -0
  16. package/lib/auth/store.d.ts +196 -0
  17. package/lib/auth/store.js +468 -0
  18. package/lib/client/CursorCard.d.ts +9 -0
  19. package/lib/client/CursorCard.js +113 -0
  20. package/lib/client/ExternalUsageCards.d.ts +9 -0
  21. package/lib/client/ExternalUsageCards.js +72 -0
  22. package/lib/client/ImageGallery.d.ts +54 -0
  23. package/lib/client/ImageGallery.js +112 -0
  24. package/lib/client/ImageGenerateToolview.d.ts +48 -0
  25. package/lib/client/ImageGenerateToolview.js +133 -0
  26. package/lib/client/ProviderAccountManager.d.ts +13 -0
  27. package/lib/client/ProviderAccountManager.js +147 -0
  28. package/lib/client/ProviderModelEditor.d.ts +39 -0
  29. package/lib/client/ProviderModelEditor.js +107 -0
  30. package/lib/client/SpeedSelect.d.ts +71 -0
  31. package/lib/client/SpeedSelect.js +177 -0
  32. package/lib/client/SubscriptionUsageBadge.d.ts +116 -0
  33. package/lib/client/SubscriptionUsageBadge.js +543 -0
  34. package/lib/client/SubscriptionsSection.d.ts +140 -0
  35. package/lib/client/SubscriptionsSection.js +544 -0
  36. package/lib/client/UsageBadgeDisplaySetting.d.ts +7 -0
  37. package/lib/client/UsageBadgeDisplaySetting.js +36 -0
  38. package/lib/client/VideoGenerateToolview.d.ts +42 -0
  39. package/lib/client/VideoGenerateToolview.js +175 -0
  40. package/lib/client/account-preferences.d.ts +24 -0
  41. package/lib/client/account-preferences.js +21 -0
  42. package/lib/client/fast-command.d.ts +2 -0
  43. package/lib/client/fast-command.js +4 -0
  44. package/lib/client/host-contract.d.ts +90 -0
  45. package/lib/client/host-contract.js +101 -0
  46. package/lib/client/host-icons.d.ts +24 -0
  47. package/lib/client/host-icons.js +21 -0
  48. package/lib/client/index.d.ts +27 -0
  49. package/lib/client/index.js +136 -0
  50. package/lib/client/locales.d.ts +297 -0
  51. package/lib/client/locales.js +295 -0
  52. package/lib/client/subscription-card-styles.d.ts +3 -0
  53. package/lib/client/subscription-card-styles.js +53 -0
  54. package/lib/client/subscriptions-rpc.d.ts +14 -0
  55. package/lib/client/subscriptions-rpc.js +34 -0
  56. package/lib/client/usage-badge-preferences.d.ts +11 -0
  57. package/lib/client/usage-badge-preferences.js +41 -0
  58. package/lib/client.js +4472 -0
  59. package/lib/client.js.map +1 -0
  60. package/lib/compat.d.ts +36 -0
  61. package/lib/compat.js +20 -0
  62. package/lib/http.d.ts +6 -0
  63. package/lib/http.js +15 -0
  64. package/lib/index.d.ts +80 -0
  65. package/lib/index.js +14018 -0
  66. package/lib/model-defaults.d.ts +23 -0
  67. package/lib/model-defaults.js +237 -0
  68. package/lib/provider-settings.d.ts +39 -0
  69. package/lib/provider-settings.js +151 -0
  70. package/lib/providers/account-preferences.d.ts +41 -0
  71. package/lib/providers/account-preferences.js +153 -0
  72. package/lib/providers/accounts.d.ts +112 -0
  73. package/lib/providers/accounts.js +142 -0
  74. package/lib/providers/antigravity-oauth-client.d.ts +7 -0
  75. package/lib/providers/antigravity-oauth-client.js +7 -0
  76. package/lib/providers/antigravity.d.ts +110 -0
  77. package/lib/providers/antigravity.js +516 -0
  78. package/lib/providers/catalog-store.d.ts +48 -0
  79. package/lib/providers/catalog-store.js +243 -0
  80. package/lib/providers/claude-cli-version.d.ts +15 -0
  81. package/lib/providers/claude-cli-version.js +24 -0
  82. package/lib/providers/claude.d.ts +181 -0
  83. package/lib/providers/claude.js +680 -0
  84. package/lib/providers/codex-client-version.d.ts +8 -0
  85. package/lib/providers/codex-client-version.js +17 -0
  86. package/lib/providers/codex-search.d.ts +29 -0
  87. package/lib/providers/codex-search.js +198 -0
  88. package/lib/providers/codex.d.ts +229 -0
  89. package/lib/providers/codex.js +821 -0
  90. package/lib/providers/common.d.ts +389 -0
  91. package/lib/providers/common.js +656 -0
  92. package/lib/providers/copilot.d.ts +344 -0
  93. package/lib/providers/copilot.js +888 -0
  94. package/lib/providers/cursor-adapter.d.ts +15 -0
  95. package/lib/providers/cursor-adapter.js +39 -0
  96. package/lib/providers/cursor-auth.d.ts +43 -0
  97. package/lib/providers/cursor-auth.js +169 -0
  98. package/lib/providers/cursor-model-settings.d.ts +15 -0
  99. package/lib/providers/cursor-model-settings.js +51 -0
  100. package/lib/providers/cursor-usage.d.ts +9 -0
  101. package/lib/providers/cursor-usage.js +112 -0
  102. package/lib/providers/external-usage-controller.d.ts +19 -0
  103. package/lib/providers/external-usage-controller.js +32 -0
  104. package/lib/providers/external-usage.d.ts +8 -0
  105. package/lib/providers/external-usage.js +82 -0
  106. package/lib/providers/grok.d.ts +205 -0
  107. package/lib/providers/grok.js +713 -0
  108. package/lib/providers/image-pool.d.ts +30 -0
  109. package/lib/providers/image-pool.js +89 -0
  110. package/lib/providers/npm-cli-version.d.ts +56 -0
  111. package/lib/providers/npm-cli-version.js +98 -0
  112. package/lib/providers/pool-family.d.ts +56 -0
  113. package/lib/providers/pool-family.js +45 -0
  114. package/lib/providers/pool-health.d.ts +74 -0
  115. package/lib/providers/pool-health.js +150 -0
  116. package/lib/providers/pool-usage.d.ts +86 -0
  117. package/lib/providers/pool-usage.js +223 -0
  118. package/lib/providers/pool.d.ts +108 -0
  119. package/lib/providers/pool.js +368 -0
  120. package/lib/providers/rate-limit.d.ts +192 -0
  121. package/lib/providers/rate-limit.js +338 -0
  122. package/lib/tools/image-generate.d.ts +128 -0
  123. package/lib/tools/image-generate.js +438 -0
  124. package/lib/tools/registration.d.ts +15 -0
  125. package/lib/tools/registration.js +24 -0
  126. package/lib/tools/video-generate.d.ts +89 -0
  127. package/lib/tools/video-generate.js +257 -0
  128. package/lib/tools/x-search.d.ts +58 -0
  129. package/lib/tools/x-search.js +197 -0
  130. package/lib/translate/anthropic.d.ts +161 -0
  131. package/lib/translate/anthropic.js +515 -0
  132. package/lib/translate/antigravity-schema.d.ts +4 -0
  133. package/lib/translate/antigravity-schema.js +145 -0
  134. package/lib/translate/antigravity-thinking.d.ts +5 -0
  135. package/lib/translate/antigravity-thinking.js +44 -0
  136. package/lib/translate/antigravity.d.ts +114 -0
  137. package/lib/translate/antigravity.js +366 -0
  138. package/lib/translate/chat-completions.d.ts +120 -0
  139. package/lib/translate/chat-completions.js +382 -0
  140. package/lib/translate/resolved.d.ts +80 -0
  141. package/lib/translate/resolved.js +118 -0
  142. package/lib/translate/responses.d.ts +179 -0
  143. package/lib/translate/responses.js +408 -0
  144. package/lib/translate/sse.d.ts +21 -0
  145. package/lib/translate/sse.js +56 -0
  146. package/package.json +114 -0
  147. package/vendor/cursor/LICENSE +21 -0
  148. package/vendor/cursor/index.d.ts +18 -0
  149. package/vendor/cursor/index.js +3574 -0
  150. package/vendor/cursor/proto.js +254 -0
@@ -0,0 +1,243 @@
1
+ /**
2
+ * On-disk discovered-model-catalog cache at
3
+ * `~/.dsh/plugins/subscriptions/models.json` — the durable half of each
4
+ * provider's {@link ModelCatalogCache}. One entry per provider: the last
5
+ * successfully discovered catalog with its fetch time, so capability metadata
6
+ * (reasoning efforts) survives restarts and network failures.
7
+ *
8
+ * Unlike the auth store, this file is a cache: a missing, corrupt, or
9
+ * malformed file silently reads as absent, because the next successful
10
+ * discovery rewrites it. Loads are strictly validated — a malformed entry
11
+ * passed through `resolveModel` would make the harness's metadata validation
12
+ * throw on every call, which is worse than having no fallback at all.
13
+ */
14
+ import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
15
+ import { dirname } from 'node:path';
16
+ import { dshHomePath } from '@deepseek-ai/dsh-home-paths';
17
+ import { ReasoningEffortId } from '@deepseek-ai/dsh-llm';
18
+ /**
19
+ * Absolute path of the catalog store file.
20
+ * @returns `dshHomePath('plugins', 'subscriptions', 'models.json')`.
21
+ */
22
+ export function modelsFilePath() {
23
+ return dshHomePath('plugins', 'subscriptions', 'models.json');
24
+ }
25
+ /** The per-account section of the file, or undefined when absent or malformed. */
26
+ function accountSection(store, provider) {
27
+ const accounts = store.accounts;
28
+ if (typeof accounts !== 'object' || accounts === null || Array.isArray(accounts))
29
+ return undefined;
30
+ const section = accounts[provider];
31
+ if (typeof section !== 'object' || section === null || Array.isArray(section))
32
+ return undefined;
33
+ return section;
34
+ }
35
+ /** Validate one persisted reasoning block, or undefined when malformed. */
36
+ function sanitizeReasoning(value) {
37
+ if (typeof value !== 'object' || value === null)
38
+ return undefined;
39
+ const raw = value;
40
+ if (!Array.isArray(raw.efforts) || raw.efforts.length === 0)
41
+ return undefined;
42
+ const seen = new Set();
43
+ const efforts = [];
44
+ for (const entry of raw.efforts) {
45
+ if (typeof entry !== 'object' || entry === null)
46
+ return undefined;
47
+ const effort = entry;
48
+ if (typeof effort.id !== 'string' || effort.id.length === 0
49
+ || typeof effort.name !== 'string' || effort.name.length === 0
50
+ || (effort.description !== undefined && typeof effort.description !== 'string')
51
+ || seen.has(effort.id))
52
+ return undefined;
53
+ seen.add(effort.id);
54
+ efforts.push({
55
+ id: ReasoningEffortId(effort.id),
56
+ name: effort.name,
57
+ ...effort.description === undefined ? {} : { description: effort.description },
58
+ });
59
+ }
60
+ if (raw.defaultEffort !== undefined
61
+ && (typeof raw.defaultEffort !== 'string' || !seen.has(raw.defaultEffort)))
62
+ return undefined;
63
+ return {
64
+ efforts,
65
+ ...raw.defaultEffort === undefined ? {} : { defaultEffort: ReasoningEffortId(raw.defaultEffort) },
66
+ };
67
+ }
68
+ /** Validate one persisted model, or undefined when malformed. */
69
+ function sanitizeModel(value) {
70
+ if (typeof value !== 'object' || value === null)
71
+ return undefined;
72
+ const raw = value;
73
+ if (typeof raw.id !== 'string' || raw.id.length === 0
74
+ || typeof raw.name !== 'string' || raw.name.length === 0
75
+ || (raw.description !== undefined && typeof raw.description !== 'string')
76
+ || (raw.contextWindow !== undefined
77
+ && (typeof raw.contextWindow !== 'number' || !Number.isInteger(raw.contextWindow) || raw.contextWindow <= 0))
78
+ || (raw.maxContextWindow !== undefined
79
+ && (typeof raw.maxContextWindow !== 'number' || !Number.isSafeInteger(raw.maxContextWindow) || raw.maxContextWindow <= 0))
80
+ || (raw.maxOutputTokens !== undefined
81
+ && (typeof raw.maxOutputTokens !== 'number' || !Number.isSafeInteger(raw.maxOutputTokens) || raw.maxOutputTokens <= 0))
82
+ || (raw.priority !== undefined
83
+ && (typeof raw.priority !== 'number' || !Number.isFinite(raw.priority))))
84
+ return undefined;
85
+ const reasoning = raw.reasoning === undefined ? undefined : sanitizeReasoning(raw.reasoning);
86
+ if (raw.reasoning !== undefined && reasoning === undefined)
87
+ return undefined;
88
+ const thinkingType = raw.thinkingType;
89
+ if (thinkingType !== undefined && thinkingType !== 'enabled' && thinkingType !== 'adaptive')
90
+ return undefined;
91
+ const fastTier = raw.fastTier;
92
+ if (fastTier !== undefined && typeof fastTier !== 'boolean')
93
+ return undefined;
94
+ const copilotWire = raw.copilotWire;
95
+ if (copilotWire !== undefined && copilotWire !== 'chat-completions' && copilotWire !== 'responses') {
96
+ return undefined;
97
+ }
98
+ const copilotResponses = raw.copilotResponses;
99
+ if (copilotResponses !== undefined && typeof copilotResponses !== 'boolean')
100
+ return undefined;
101
+ const inputModalities = raw.inputModalities;
102
+ if (inputModalities !== undefined
103
+ && (!Array.isArray(inputModalities) || inputModalities.length === 0
104
+ || inputModalities.some(modality => modality !== 'text' && modality !== 'image')))
105
+ return undefined;
106
+ return {
107
+ id: raw.id,
108
+ name: raw.name,
109
+ ...raw.description === undefined ? {} : { description: raw.description },
110
+ ...raw.contextWindow === undefined ? {} : { contextWindow: raw.contextWindow },
111
+ ...raw.maxContextWindow === undefined ? {} : { maxContextWindow: raw.maxContextWindow },
112
+ ...raw.maxOutputTokens === undefined ? {} : { maxOutputTokens: raw.maxOutputTokens },
113
+ ...raw.priority === undefined ? {} : { priority: raw.priority },
114
+ ...reasoning === undefined ? {} : { reasoning },
115
+ ...thinkingType === undefined ? {} : { thinkingType: thinkingType },
116
+ ...fastTier === undefined ? {} : { fastTier },
117
+ ...copilotWire === undefined ? {} : { copilotWire: copilotWire },
118
+ ...copilotResponses === undefined ? {} : { copilotResponses },
119
+ ...inputModalities === undefined ? {} : { inputModalities: [...inputModalities] },
120
+ };
121
+ }
122
+ /**
123
+ * Validate one persisted snapshot. Strict: any malformed field drops the
124
+ * whole snapshot rather than repairing it — the next successful discovery
125
+ * rewrites the entry anyway.
126
+ * @param value - the raw per-provider file entry.
127
+ * @returns the validated snapshot, or undefined when unusable.
128
+ */
129
+ export function sanitizeSnapshot(value) {
130
+ if (typeof value !== 'object' || value === null)
131
+ return undefined;
132
+ const raw = value;
133
+ if (typeof raw.at !== 'number' || !Number.isFinite(raw.at))
134
+ return undefined;
135
+ if (!Array.isArray(raw.models) || raw.models.length === 0)
136
+ return undefined;
137
+ const seen = new Set();
138
+ const models = [];
139
+ for (const entry of raw.models) {
140
+ const model = sanitizeModel(entry);
141
+ if (model === undefined || seen.has(model.id))
142
+ return undefined;
143
+ seen.add(model.id);
144
+ models.push(model);
145
+ }
146
+ return { at: raw.at, models };
147
+ }
148
+ /** Read the whole file; missing or unparsable reads as an empty cache. */
149
+ async function readCatalogFile(path) {
150
+ let text;
151
+ try {
152
+ text = await readFile(path, 'utf8');
153
+ }
154
+ catch {
155
+ return {};
156
+ }
157
+ try {
158
+ const parsed = JSON.parse(text);
159
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
160
+ return {};
161
+ return parsed;
162
+ }
163
+ catch {
164
+ return {};
165
+ }
166
+ }
167
+ /** Persist the whole file atomically (tmp file + rename). */
168
+ async function writeCatalogFile(store, path) {
169
+ await mkdir(dirname(path), { recursive: true });
170
+ const tmp = `${path}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;
171
+ try {
172
+ await writeFile(tmp, JSON.stringify(store, null, 2));
173
+ await rename(tmp, path);
174
+ }
175
+ catch (error) {
176
+ await rm(tmp, { force: true });
177
+ throw error;
178
+ }
179
+ }
180
+ /**
181
+ * Build the durable half of one provider's catalog cache over the shared
182
+ * models.json file (concurrent writers are last-writer-wins, acceptable for
183
+ * a cache).
184
+ * @param provider - the provider route keying the file entry.
185
+ * @param path - store file path; defaults to {@link modelsFilePath}.
186
+ * @returns the persistence hooks for {@link ModelCatalogCache}.
187
+ */
188
+ export function catalogStore(provider, path = modelsFilePath()) {
189
+ return {
190
+ async load() {
191
+ return sanitizeSnapshot((await readCatalogFile(path))[provider]);
192
+ },
193
+ async save(snapshot) {
194
+ const store = await readCatalogFile(path);
195
+ store[provider] = snapshot;
196
+ await writeCatalogFile(store, path);
197
+ },
198
+ async clear() {
199
+ const store = await readCatalogFile(path);
200
+ if (store[provider] === undefined)
201
+ return;
202
+ delete store[provider];
203
+ await writeCatalogFile(store, path);
204
+ },
205
+ };
206
+ }
207
+ /**
208
+ * The durable half of one NON-default account's catalog cache. The provider
209
+ * entry belongs to the default account; every other account keeps its own
210
+ * snapshot under `accounts[provider][account]`, so a working secondary login
211
+ * survives restarts and network failures even when the default login is dead.
212
+ * @param provider - the provider route.
213
+ * @param account - the canonical account key.
214
+ * @param path - store file path; defaults to {@link modelsFilePath}.
215
+ * @returns the persistence hooks for {@link ModelCatalogCache}.
216
+ */
217
+ export function accountCatalogStore(provider, account, path = modelsFilePath()) {
218
+ return {
219
+ async load() {
220
+ const section = accountSection(await readCatalogFile(path), provider);
221
+ return section !== undefined && Object.hasOwn(section, account) ? sanitizeSnapshot(section[account]) : undefined;
222
+ },
223
+ async save(snapshot) {
224
+ const store = await readCatalogFile(path);
225
+ const accounts = typeof store.accounts === 'object' && store.accounts !== null && !Array.isArray(store.accounts)
226
+ ? store.accounts
227
+ : {};
228
+ const section = { ...accountSection(store, provider) ?? {}, [account]: snapshot };
229
+ store.accounts = { ...accounts, [provider]: section };
230
+ await writeCatalogFile(store, path);
231
+ },
232
+ async clear() {
233
+ const store = await readCatalogFile(path);
234
+ const section = accountSection(store, provider);
235
+ if (section === undefined || !Object.hasOwn(section, account))
236
+ return;
237
+ const rest = { ...section };
238
+ delete rest[account];
239
+ store.accounts = { ...store.accounts, [provider]: rest };
240
+ await writeCatalogFile(store, path);
241
+ },
242
+ };
243
+ }
@@ -0,0 +1,15 @@
1
+ import type { FetchFn } from './common.js';
2
+ import { NpmCliVersionCache } from './npm-cli-version.js';
3
+ /**
4
+ * Public metadata only: never send subscription credentials to this endpoint.
5
+ * `latest`, not `stable`: the endpoint gates new models on versions that
6
+ * reach `stable` about a week later.
7
+ */
8
+ export declare const CLAUDE_CLI_VERSION_URL = "https://registry.npmjs.org/@anthropic-ai%2fclaude-code/latest";
9
+ /**
10
+ * Lazy, shared-per-plugin lookup of Claude Code's newest release, never
11
+ * below the local CLI or the bundled fallback version.
12
+ */
13
+ export declare class ClaudeCliVersionCache extends NpmCliVersionCache {
14
+ constructor(fetchFn?: FetchFn, now?: () => number, timeoutMs?: number, detect?: () => string);
15
+ }
@@ -0,0 +1,24 @@
1
+ import { claudeCliVersionFloor } from './claude.js';
2
+ import { NpmCliVersionCache } from './npm-cli-version.js';
3
+ /**
4
+ * Public metadata only: never send subscription credentials to this endpoint.
5
+ * `latest`, not `stable`: the endpoint gates new models on versions that
6
+ * reach `stable` about a week later.
7
+ */
8
+ export const CLAUDE_CLI_VERSION_URL = 'https://registry.npmjs.org/@anthropic-ai%2fclaude-code/latest';
9
+ /**
10
+ * Lazy, shared-per-plugin lookup of Claude Code's newest release, never
11
+ * below the local CLI or the bundled fallback version.
12
+ */
13
+ export class ClaudeCliVersionCache extends NpmCliVersionCache {
14
+ constructor(fetchFn, now, timeoutMs, detect) {
15
+ super({
16
+ url: CLAUDE_CLI_VERSION_URL,
17
+ label: 'Claude Code',
18
+ floor: () => claudeCliVersionFloor(detect),
19
+ ...fetchFn === undefined ? {} : { fetchFn },
20
+ ...now === undefined ? {} : { now },
21
+ ...timeoutMs === undefined ? {} : { timeoutMs },
22
+ });
23
+ }
24
+ }
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Claude Pro/Max subscription provider: OAuth against claude.ai /
3
+ * platform.claude.com with the Claude Code client id, and streaming against
4
+ * the Anthropic Messages API with the Claude Code identity headers.
5
+ */
6
+ import { LlmAdapter } from '@deepseek-ai/dsh-llm';
7
+ import type { GenerateOptions, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, StreamChunk } from '@deepseek-ai/dsh-llm';
8
+ import type { FlowSpec } from '../auth/oauth-flow.js';
9
+ import type { ClaudeSession } from '../auth/store.js';
10
+ import type { PoolAdapter } from './pool.js';
11
+ import type { AttachmentStore } from '@deepseek-ai/dsh-attachment';
12
+ import type { TranslatableMessage } from '../translate/resolved.js';
13
+ import { AccountTokenManager } from './accounts.js';
14
+ import type { CatalogPersistence, DiscoveredModel, FetchFn, ModelEntry, ProviderUsage } from './common.js';
15
+ import type { CliVersion } from './npm-cli-version.js';
16
+ import type { RateLimitResetReader, RateLimitWait } from './rate-limit.js';
17
+ export declare const CLAUDE_CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
18
+ export declare const CLAUDE_AUTHORIZE_URL = "https://claude.ai/oauth/authorize";
19
+ export declare const CLAUDE_TOKEN_URL = "https://claude.ai/v1/oauth/token";
20
+ export declare const CLAUDE_API_URL = "https://api.anthropic.com/v1/messages?beta=true";
21
+ export declare const CLAUDE_PROFILE_URL = "https://api.anthropic.com/api/oauth/profile";
22
+ export declare const CLAUDE_MODELS_URL = "https://api.anthropic.com/v1/models?beta=true";
23
+ export declare const CLAUDE_SCOPE = "org:create_api_key user:profile user:inference user:sessions:claude_code user:mcp_servers user:file_upload";
24
+ export declare const CLAUDE_CALLBACK_PATH = "/callback";
25
+ /** Refresh when the access token has less than this much life left. */
26
+ export declare const CLAUDE_PREEMPT_MS: number;
27
+ /**
28
+ * Reads the reset instant of the Anthropic window that rejected a request.
29
+ *
30
+ * `anthropic-ratelimit-unified-*` is the subscription-plan family — the one
31
+ * Claude Code renders as "resets 3pm" — and is the only header that names the
32
+ * window which actually rejected this request. The per-bucket
33
+ * `anthropic-ratelimit-{requests,tokens,input-tokens,output-tokens}-reset`
34
+ * headers are deliberately not read: they are rollover snapshots attached to
35
+ * every response, so on a 429 they cannot say which bucket refused, and the
36
+ * earliest of them is typically the bucket that still had room — a wait that
37
+ * lands straight back in the closed window. They reach the operator through
38
+ * `rateLimitDiagnostics` instead.
39
+ */
40
+ export declare const claudeRateLimitReset: RateLimitResetReader;
41
+ /**
42
+ * The subscription endpoint only serves requests presenting as Claude Code,
43
+ * so these headers impersonate the CLI; the harness attribution user-agent
44
+ * cannot be sent here (one user-agent slot, and the CLI's wins). The endpoint
45
+ * also gates new models on the CLI version, so the version normally comes
46
+ * from npm (`ClaudeCliVersionCache`); this is only the offline floor.
47
+ */
48
+ export declare const CLAUDE_CLI_FALLBACK_VERSION = "2.1.283";
49
+ export declare function detectClaudeVersion(): string;
50
+ /**
51
+ * The lowest version to present: the local CLI or the bundled fallback,
52
+ * whichever is newer. An outdated local install must not pin requests to a
53
+ * version the endpoint already rejects for new models.
54
+ * @param detect - local CLI probe (injectable for tests).
55
+ */
56
+ export declare function claudeCliVersionFloor(detect?: () => string): CliVersion;
57
+ /** The User-Agent Claude Code sends at `version`. */
58
+ export declare function claudeCliUserAgent(version: string): string;
59
+ export declare const CLAUDE_BETA_FALLBACK: string;
60
+ /** Static claude flow facts for the OAuth flow engine. */
61
+ export declare const claudeFlow: FlowSpec;
62
+ /**
63
+ * Exchange an authorization code for a claude session (JSON grant).
64
+ * @param code - the authorization code from the callback.
65
+ * @param verifier - the PKCE verifier minted for the attempt.
66
+ * @param redirectUri - the attempt's redirect URI.
67
+ * @param state - the attempt's state (echoed to the token endpoint).
68
+ * @returns the session to store.
69
+ */
70
+ export declare function exchangeClaudeCode(code: string, verifier: string, redirectUri: string, state: string): Promise<ClaudeSession>;
71
+ /**
72
+ * Refresh a claude session (JSON grant echoing the issued scope).
73
+ * @param session - the stored session.
74
+ * @returns the fresh session to store.
75
+ */
76
+ export declare function refreshClaude(session: ClaudeSession): Promise<ClaudeSession>;
77
+ /**
78
+ * Whether a claude refresh failure means the login is permanently gone.
79
+ * @param error - the thrown refresh error.
80
+ * @returns true when re-login is the only fix.
81
+ */
82
+ export declare function isClaudePermanentRefreshError(error: unknown): boolean;
83
+ export declare const CLAUDE_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
84
+ /**
85
+ * Fetch the claude subscription usage from the OAuth usage endpoint (the
86
+ * source of Claude Code's `/usage` screen). Newer responses carry a
87
+ * structured `limits` array; older ones the flat `five_hour`/`seven_day*`
88
+ * buckets — both shapes are read, the array winning when it has entries.
89
+ * @param session - the stored session (used as-is; never refreshed here).
90
+ * @param fetchFn - fetch implementation (injectable for tests).
91
+ * @param signal - caller cancellation from the RPC transport.
92
+ * @param cliVersion - resolves the Claude Code version to present; defaults to the local floor.
93
+ * @returns the mapped usage snapshot.
94
+ */
95
+ export declare function fetchClaudeUsage(session: ClaudeSession, fetchFn?: FetchFn, signal?: AbortSignal, cliVersion?: () => Promise<string>): Promise<ProviderUsage>;
96
+ /**
97
+ * Fetch the live model catalog from the subscription endpoint. `signal`
98
+ * cancels the request; `cliVersion` resolves the Claude Code version to
99
+ * present (defaults to the local floor).
100
+ */
101
+ export declare function fetchClaudeModels(session: ClaudeSession, fetchFn?: FetchFn, signal?: AbortSignal, cliVersion?: () => Promise<string>): Promise<DiscoveredModel[]>;
102
+ /** Constructor dependencies for {@link ClaudeAdapter}. */
103
+ export interface ClaudeAdapterOptions {
104
+ models: readonly ModelEntry[];
105
+ streamIdleTimeoutMs: number;
106
+ tokens: AccountTokenManager<ClaudeSession>;
107
+ /** Late-bound pool facade (wired after adapter construction); pools list under their first member's provider. */
108
+ pool?: () => PoolAdapter | undefined;
109
+ /** Whether to fetch the live catalog when logged in (false when config `models` overrides). */
110
+ discovery: boolean;
111
+ fetchFn?: FetchFn;
112
+ onWarn?: (message: string) => void;
113
+ /** How long this route may hold a turn open waiting for a rate-limit window; defaults to waiting on, six-hour ceiling. */
114
+ rateLimit?: RateLimitWait;
115
+ /** Resolve the attachment service per request; absent means image requests fail loudly. */
116
+ resolveAttachments?: () => AttachmentStore | undefined;
117
+ /** Durable catalog store seeding capability metadata across restarts. */
118
+ catalogStore?: CatalogPersistence;
119
+ /**
120
+ * Per-model default reasoning effort override (the Settings page's picker).
121
+ * Returns the user-configured default for one model, or undefined to follow
122
+ * the provider's own default.
123
+ */
124
+ defaultEffortOf?: (model: string) => string | undefined;
125
+ /** Resolves the Claude Code version to present (npm-backed); absent means the local floor. */
126
+ resolveCliVersion?: () => Promise<string>;
127
+ }
128
+ /**
129
+ * Assemble the Anthropic request body.
130
+ *
131
+ * Extracted from the adapter so the wire shape — cache breakpoints above all —
132
+ * is testable without a network round trip. The message array is marked before
133
+ * it is placed so the breakpoints land on the blocks the body ships: one on the
134
+ * last `system` block (covering `tools` + `system`, which render ahead of it)
135
+ * and up to three across the history, Anthropic's four-slot maximum.
136
+ * @param options - the generate request.
137
+ * @param messages - conversation messages with images already resolved.
138
+ * @param maxTokens - the resolved output cap.
139
+ * @param thinking - the thinking parameter, when the model takes one.
140
+ * @param effort - the reasoning effort, when the model advertises efforts.
141
+ * @returns the JSON body to POST.
142
+ */
143
+ export declare function claudeRequestBody(options: GenerateOptions, messages: readonly TranslatableMessage[], maxTokens: number, thinking?: Record<string, unknown>, effort?: string): Record<string, unknown>;
144
+ /** Claude wire adapter: one instance serves the `claude` provider route. */
145
+ export declare class ClaudeAdapter extends LlmAdapter {
146
+ private readonly options;
147
+ private readonly catalog;
148
+ /** In-memory catalogs for non-default accounts (the persisted cache is the default's). */
149
+ private readonly accountCatalogs;
150
+ /** Account whose snapshot currently lives in {@link catalog}; cleared on default change. */
151
+ private catalogOwner;
152
+ constructor(options: ClaudeAdapterOptions);
153
+ private fetchCatalog;
154
+ /** Drop cached catalogs after login/logout so the next list does not reuse a stale plan. */
155
+ clearAccountCatalog(account?: string): void;
156
+ /** Persisted cache for the default account; a throwaway cache for any other. */
157
+ private catalogFor;
158
+ private discovered;
159
+ private staticModels;
160
+ providerInfo(provider: string): LlmProviderInfo;
161
+ providerRetryPolicy(provider: string): import("@deepseek-ai/dsh-llm").ResolvedRetryPolicy;
162
+ listModels(provider: string): Promise<readonly LlmModelInfo[]>;
163
+ /** The provider's own catalog: union of every account, or one account when named. */
164
+ listOwnModels(provider: string, account?: string, signal?: AbortSignal): Promise<readonly LlmModelInfo[]>;
165
+ resolveModel(provider: string, model: string): Promise<LlmResolvedModelInfo>;
166
+ /** Capability resolution of the provider's own models (the pool resolves members here). */
167
+ resolveOwnModel(provider: string, model: string): Promise<LlmResolvedModelInfo>;
168
+ stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
169
+ /** Pool seam: stream through one specific account instead of the default. */
170
+ streamAccount(options: GenerateOptions, account: string): AsyncIterable<StreamChunk>;
171
+ private streamCore;
172
+ /**
173
+ * `display: 'summarized'` is set explicitly on both shapes: `adaptive`-type
174
+ * models default to `display: 'omitted'`, which returns thinking blocks with
175
+ * an empty `thinking` field — without this override the "Think" panel would
176
+ * always render empty even though real reasoning (and billed thinking_tokens)
177
+ * ran.
178
+ */
179
+ private thinkingParam;
180
+ private request;
181
+ }