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.
- package/LICENSE +21 -0
- package/README.md +129 -0
- package/cordis.patch.yml +12 -0
- package/lib/auth/claude-code-creds.d.ts +23 -0
- package/lib/auth/claude-code-creds.js +172 -0
- package/lib/auth/device-flow.d.ts +55 -0
- package/lib/auth/device-flow.js +177 -0
- package/lib/auth/jwt.d.ts +10 -0
- package/lib/auth/jwt.js +25 -0
- package/lib/auth/oauth-flow.d.ts +91 -0
- package/lib/auth/oauth-flow.js +227 -0
- package/lib/auth/pkce.d.ts +31 -0
- package/lib/auth/pkce.js +35 -0
- package/lib/auth/rpc.d.ts +209 -0
- package/lib/auth/rpc.js +386 -0
- package/lib/auth/store.d.ts +196 -0
- package/lib/auth/store.js +468 -0
- package/lib/client/CursorCard.d.ts +9 -0
- package/lib/client/CursorCard.js +113 -0
- package/lib/client/ExternalUsageCards.d.ts +9 -0
- package/lib/client/ExternalUsageCards.js +72 -0
- package/lib/client/ImageGallery.d.ts +54 -0
- package/lib/client/ImageGallery.js +112 -0
- package/lib/client/ImageGenerateToolview.d.ts +48 -0
- package/lib/client/ImageGenerateToolview.js +133 -0
- package/lib/client/ProviderAccountManager.d.ts +13 -0
- package/lib/client/ProviderAccountManager.js +147 -0
- package/lib/client/ProviderModelEditor.d.ts +39 -0
- package/lib/client/ProviderModelEditor.js +107 -0
- package/lib/client/SpeedSelect.d.ts +71 -0
- package/lib/client/SpeedSelect.js +177 -0
- package/lib/client/SubscriptionUsageBadge.d.ts +116 -0
- package/lib/client/SubscriptionUsageBadge.js +543 -0
- package/lib/client/SubscriptionsSection.d.ts +140 -0
- package/lib/client/SubscriptionsSection.js +544 -0
- package/lib/client/UsageBadgeDisplaySetting.d.ts +7 -0
- package/lib/client/UsageBadgeDisplaySetting.js +36 -0
- package/lib/client/VideoGenerateToolview.d.ts +42 -0
- package/lib/client/VideoGenerateToolview.js +175 -0
- package/lib/client/account-preferences.d.ts +24 -0
- package/lib/client/account-preferences.js +21 -0
- package/lib/client/fast-command.d.ts +2 -0
- package/lib/client/fast-command.js +4 -0
- package/lib/client/host-contract.d.ts +90 -0
- package/lib/client/host-contract.js +101 -0
- package/lib/client/host-icons.d.ts +24 -0
- package/lib/client/host-icons.js +21 -0
- package/lib/client/index.d.ts +27 -0
- package/lib/client/index.js +136 -0
- package/lib/client/locales.d.ts +297 -0
- package/lib/client/locales.js +295 -0
- package/lib/client/subscription-card-styles.d.ts +3 -0
- package/lib/client/subscription-card-styles.js +53 -0
- package/lib/client/subscriptions-rpc.d.ts +14 -0
- package/lib/client/subscriptions-rpc.js +34 -0
- package/lib/client/usage-badge-preferences.d.ts +11 -0
- package/lib/client/usage-badge-preferences.js +41 -0
- package/lib/client.js +4472 -0
- package/lib/client.js.map +1 -0
- package/lib/compat.d.ts +36 -0
- package/lib/compat.js +20 -0
- package/lib/http.d.ts +6 -0
- package/lib/http.js +15 -0
- package/lib/index.d.ts +80 -0
- package/lib/index.js +14018 -0
- package/lib/model-defaults.d.ts +23 -0
- package/lib/model-defaults.js +237 -0
- package/lib/provider-settings.d.ts +39 -0
- package/lib/provider-settings.js +151 -0
- package/lib/providers/account-preferences.d.ts +41 -0
- package/lib/providers/account-preferences.js +153 -0
- package/lib/providers/accounts.d.ts +112 -0
- package/lib/providers/accounts.js +142 -0
- package/lib/providers/antigravity-oauth-client.d.ts +7 -0
- package/lib/providers/antigravity-oauth-client.js +7 -0
- package/lib/providers/antigravity.d.ts +110 -0
- package/lib/providers/antigravity.js +516 -0
- package/lib/providers/catalog-store.d.ts +48 -0
- package/lib/providers/catalog-store.js +243 -0
- package/lib/providers/claude-cli-version.d.ts +15 -0
- package/lib/providers/claude-cli-version.js +24 -0
- package/lib/providers/claude.d.ts +181 -0
- package/lib/providers/claude.js +680 -0
- package/lib/providers/codex-client-version.d.ts +8 -0
- package/lib/providers/codex-client-version.js +17 -0
- package/lib/providers/codex-search.d.ts +29 -0
- package/lib/providers/codex-search.js +198 -0
- package/lib/providers/codex.d.ts +229 -0
- package/lib/providers/codex.js +821 -0
- package/lib/providers/common.d.ts +389 -0
- package/lib/providers/common.js +656 -0
- package/lib/providers/copilot.d.ts +344 -0
- package/lib/providers/copilot.js +888 -0
- package/lib/providers/cursor-adapter.d.ts +15 -0
- package/lib/providers/cursor-adapter.js +39 -0
- package/lib/providers/cursor-auth.d.ts +43 -0
- package/lib/providers/cursor-auth.js +169 -0
- package/lib/providers/cursor-model-settings.d.ts +15 -0
- package/lib/providers/cursor-model-settings.js +51 -0
- package/lib/providers/cursor-usage.d.ts +9 -0
- package/lib/providers/cursor-usage.js +112 -0
- package/lib/providers/external-usage-controller.d.ts +19 -0
- package/lib/providers/external-usage-controller.js +32 -0
- package/lib/providers/external-usage.d.ts +8 -0
- package/lib/providers/external-usage.js +82 -0
- package/lib/providers/grok.d.ts +205 -0
- package/lib/providers/grok.js +713 -0
- package/lib/providers/image-pool.d.ts +30 -0
- package/lib/providers/image-pool.js +89 -0
- package/lib/providers/npm-cli-version.d.ts +56 -0
- package/lib/providers/npm-cli-version.js +98 -0
- package/lib/providers/pool-family.d.ts +56 -0
- package/lib/providers/pool-family.js +45 -0
- package/lib/providers/pool-health.d.ts +74 -0
- package/lib/providers/pool-health.js +150 -0
- package/lib/providers/pool-usage.d.ts +86 -0
- package/lib/providers/pool-usage.js +223 -0
- package/lib/providers/pool.d.ts +108 -0
- package/lib/providers/pool.js +368 -0
- package/lib/providers/rate-limit.d.ts +192 -0
- package/lib/providers/rate-limit.js +338 -0
- package/lib/tools/image-generate.d.ts +128 -0
- package/lib/tools/image-generate.js +438 -0
- package/lib/tools/registration.d.ts +15 -0
- package/lib/tools/registration.js +24 -0
- package/lib/tools/video-generate.d.ts +89 -0
- package/lib/tools/video-generate.js +257 -0
- package/lib/tools/x-search.d.ts +58 -0
- package/lib/tools/x-search.js +197 -0
- package/lib/translate/anthropic.d.ts +161 -0
- package/lib/translate/anthropic.js +515 -0
- package/lib/translate/antigravity-schema.d.ts +4 -0
- package/lib/translate/antigravity-schema.js +145 -0
- package/lib/translate/antigravity-thinking.d.ts +5 -0
- package/lib/translate/antigravity-thinking.js +44 -0
- package/lib/translate/antigravity.d.ts +114 -0
- package/lib/translate/antigravity.js +366 -0
- package/lib/translate/chat-completions.d.ts +120 -0
- package/lib/translate/chat-completions.js +382 -0
- package/lib/translate/resolved.d.ts +80 -0
- package/lib/translate/resolved.js +118 -0
- package/lib/translate/responses.d.ts +179 -0
- package/lib/translate/responses.js +408 -0
- package/lib/translate/sse.d.ts +21 -0
- package/lib/translate/sse.js +56 -0
- package/package.json +114 -0
- package/vendor/cursor/LICENSE +21 -0
- package/vendor/cursor/index.d.ts +18 -0
- package/vendor/cursor/index.js +3574 -0
- package/vendor/cursor/proto.js +254 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grok (X Premium / xAI) subscription provider: OIDC-discovered OAuth against
|
|
3
|
+
* auth.x.ai with the Grok CLI client id, and streaming against the xAI
|
|
4
|
+
* Responses-style endpoint.
|
|
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 { GrokSession } from '../auth/store.js';
|
|
10
|
+
import type { PoolAdapter } from './pool.js';
|
|
11
|
+
import type { AttachmentStore } from '@deepseek-ai/dsh-attachment';
|
|
12
|
+
import type { ResponsesRequestInput } from '../translate/responses.js';
|
|
13
|
+
import { AccountTokenManager } from './accounts.js';
|
|
14
|
+
import type { CatalogPersistence, DiscoveredModel, FetchFn, ModelEntry, ProviderUsage } from './common.js';
|
|
15
|
+
import type { RateLimitResetReader, RateLimitWait } from './rate-limit.js';
|
|
16
|
+
export declare const GROK_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
17
|
+
export declare const GROK_DISCOVERY_URL = "https://auth.x.ai/.well-known/openid-configuration";
|
|
18
|
+
export declare const GROK_API_URL = "https://api.x.ai/v1/responses";
|
|
19
|
+
/** Refresh when the access token has less than this much life left. */
|
|
20
|
+
export declare const GROK_PREEMPT_MS: number;
|
|
21
|
+
/**
|
|
22
|
+
* Reads the reset instant of the xAI window that rejected a request.
|
|
23
|
+
*
|
|
24
|
+
* Body only. xAI serves the OpenAI-compatible `x-ratelimit-reset-*` family,
|
|
25
|
+
* whose values are rollover durations (`6m0s`) present on every response, one
|
|
26
|
+
* per bucket — on a 429 the earliest of them is usually a bucket with room
|
|
27
|
+
* (`0s` for the request bucket while the token bucket is the one exhausted),
|
|
28
|
+
* which would burn the whole retry budget in seconds. They reach the operator
|
|
29
|
+
* through `rateLimitDiagnostics` instead.
|
|
30
|
+
*/
|
|
31
|
+
export declare const grokRateLimitReset: RateLimitResetReader;
|
|
32
|
+
/** Discovered OIDC endpoints for the xAI authorization server. */
|
|
33
|
+
export interface GrokDiscovery {
|
|
34
|
+
authorizationEndpoint: string;
|
|
35
|
+
tokenEndpoint: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the xAI OIDC endpoints (cached after the first fetch).
|
|
39
|
+
* @returns validated authorization and token endpoints.
|
|
40
|
+
*/
|
|
41
|
+
export declare function grokDiscovery(): Promise<GrokDiscovery>;
|
|
42
|
+
/**
|
|
43
|
+
* Build the grok flow facts for the OAuth flow engine (async because the
|
|
44
|
+
* authorize URL comes from OIDC discovery).
|
|
45
|
+
* @returns the flow spec for one attempt.
|
|
46
|
+
*/
|
|
47
|
+
export declare function grokFlow(): Promise<FlowSpec>;
|
|
48
|
+
/**
|
|
49
|
+
* The subscription tier encoded in a grok access token's `tier` claim (no
|
|
50
|
+
* verification — same trust posture as the other claim reads).
|
|
51
|
+
* @param accessToken - the stored access token.
|
|
52
|
+
* @returns the display tier name, or undefined when the claim is absent.
|
|
53
|
+
*/
|
|
54
|
+
export declare function grokTierName(accessToken: string): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Exchange an authorization code for a grok session (form-encoded grant that
|
|
57
|
+
* echoes the PKCE challenge as well as the verifier, per the xAI flow).
|
|
58
|
+
* A 403 here means the X plan lacks the API OAuth entitlement.
|
|
59
|
+
* @param code - the authorization code from the callback.
|
|
60
|
+
* @param verifier - the PKCE verifier minted for the attempt.
|
|
61
|
+
* @param redirectUri - the attempt's redirect URI.
|
|
62
|
+
* @param challenge - the PKCE challenge sent at authorize time.
|
|
63
|
+
* @returns the session to store.
|
|
64
|
+
*/
|
|
65
|
+
export declare function exchangeGrokCode(code: string, verifier: string, redirectUri: string, challenge: string): Promise<GrokSession>;
|
|
66
|
+
/**
|
|
67
|
+
* Refresh a grok session (form-encoded grant).
|
|
68
|
+
* @param session - the stored session.
|
|
69
|
+
* @returns the fresh session to store.
|
|
70
|
+
*/
|
|
71
|
+
export declare function refreshGrok(session: GrokSession): Promise<GrokSession>;
|
|
72
|
+
/**
|
|
73
|
+
* Whether a grok refresh failure means the login is permanently gone.
|
|
74
|
+
* @param error - the thrown refresh error.
|
|
75
|
+
* @returns true when re-login is the only fix.
|
|
76
|
+
*/
|
|
77
|
+
export declare function isGrokPermanentRefreshError(error: unknown): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The Grok Build CLI chat proxy's billing endpoint (the source of the CLI's
|
|
80
|
+
* `/usage` "Usage limit" panel; see xai-org/grok-build
|
|
81
|
+
* `extensions/billing.rs`). Forwards to the backend `GetGrokCreditsConfig`.
|
|
82
|
+
*/
|
|
83
|
+
export declare const GROK_BILLING_URL = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
84
|
+
/**
|
|
85
|
+
* Fetch the grok subscription usage from the Grok Build CLI chat proxy. The
|
|
86
|
+
* newer credits config carries a ready-made percentage plus the current
|
|
87
|
+
* (typically weekly) period; the legacy shape carries cent-valued
|
|
88
|
+
* `monthlyLimit`/`used`, from which the percentage is derived.
|
|
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
|
+
* @returns the mapped usage snapshot.
|
|
93
|
+
*/
|
|
94
|
+
export declare function fetchGrokUsage(session: GrokSession, fetchFn?: FetchFn, signal?: AbortSignal): Promise<ProviderUsage>;
|
|
95
|
+
export declare const GROK_MODELS_URL = "https://api.x.ai/v1/models";
|
|
96
|
+
/**
|
|
97
|
+
* The Grok Build CLI chat proxy's model catalog — the only grok endpoint that
|
|
98
|
+
* advertises reasoning capability. The `api.x.ai/v1/models` and
|
|
99
|
+
* `/v1/language-models` payloads carry pricing, context, and aliases only, so
|
|
100
|
+
* effort metadata must come from here (the same source the official CLI's
|
|
101
|
+
* picker uses).
|
|
102
|
+
*/
|
|
103
|
+
export declare const GROK_CLI_MODELS_URL = "https://cli-chat-proxy.grok.com/v1/models";
|
|
104
|
+
/** Per-model metadata the CLI catalog contributes to a discovered model. */
|
|
105
|
+
type GrokCliModelMeta = Partial<Pick<DiscoveredModel, 'name' | 'description' | 'contextWindow' | 'reasoning'>>;
|
|
106
|
+
/**
|
|
107
|
+
* Fetch the CLI catalog and index its per-model metadata by model id.
|
|
108
|
+
* @param session - the stored session (used as-is; never refreshed here).
|
|
109
|
+
* @param fetchFn - fetch implementation (injectable for tests).
|
|
110
|
+
* @param signal - caller cancellation (pool-assembly timeout).
|
|
111
|
+
* @returns model id → contributed metadata.
|
|
112
|
+
*/
|
|
113
|
+
export declare function fetchGrokCliCatalog(session: GrokSession, fetchFn?: FetchFn, signal?: AbortSignal): Promise<Map<string, GrokCliModelMeta>>;
|
|
114
|
+
/**
|
|
115
|
+
* Fetch the live grok model list, enriched with the CLI catalog's per-model
|
|
116
|
+
* metadata (display name, context window, reasoning efforts). The api.x.ai
|
|
117
|
+
* list stays authoritative for which models exist; the CLI catalog is
|
|
118
|
+
* enrichment only, so its failure degrades to a plain list instead of taking
|
|
119
|
+
* discovery down. When enrichment is missing, last-known capability metadata
|
|
120
|
+
* is carried forward so a transient CLI outage cannot strip efforts a
|
|
121
|
+
* session already selected.
|
|
122
|
+
* @param session - the stored session (used as-is; never refreshed here).
|
|
123
|
+
* @param fetchFn - fetch implementation (injectable for tests).
|
|
124
|
+
* @param onWarn - warning sink for a failed CLI catalog fetch.
|
|
125
|
+
* @param previous - last-known catalog used to keep enrichment when the CLI
|
|
126
|
+
* catalog is down or omits a model.
|
|
127
|
+
* @param signal - caller cancellation (pool-assembly timeout).
|
|
128
|
+
* @returns discovered chat models in endpoint order.
|
|
129
|
+
*/
|
|
130
|
+
export declare function fetchGrokModels(session: GrokSession, fetchFn?: FetchFn, onWarn?: (message: string) => void, previous?: readonly DiscoveredModel[], signal?: AbortSignal): Promise<DiscoveredModel[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Build one xAI Responses request body (exported for tests, like
|
|
133
|
+
* {@link codexRequestBody}). The tool trio renders only when tools exist:
|
|
134
|
+
* A reported xAI 400 invalid-argument on tool-less calls motivated omitting
|
|
135
|
+
* tool controls when no tools are supplied. Keep this endpoint-specific
|
|
136
|
+
* compatibility measure separate from assumptions about other backends.
|
|
137
|
+
*/
|
|
138
|
+
export declare function grokRequestBody(options: GenerateOptions, resolved: ResponsesRequestInput): Record<string, unknown>;
|
|
139
|
+
/** Constructor dependencies for {@link GrokAdapter}. */
|
|
140
|
+
export interface GrokAdapterOptions {
|
|
141
|
+
models: readonly ModelEntry[];
|
|
142
|
+
streamIdleTimeoutMs: number;
|
|
143
|
+
tokens: AccountTokenManager<GrokSession>;
|
|
144
|
+
/** Late-bound pool facade (wired after adapter construction); pools list under their first member's provider. */
|
|
145
|
+
pool?: () => PoolAdapter | undefined;
|
|
146
|
+
/** Whether to fetch the live catalog when logged in (false when config `models` overrides). */
|
|
147
|
+
discovery: boolean;
|
|
148
|
+
/** Warning sink for discovery failures that fall back to the static catalog. */
|
|
149
|
+
onWarn?: (message: string) => void;
|
|
150
|
+
/** Fetch implementation for discovery (defaults to global fetch). */
|
|
151
|
+
fetchFn?: FetchFn;
|
|
152
|
+
/** Resolve the attachment service per request; absent means image requests fail loudly. */
|
|
153
|
+
resolveAttachments?: () => AttachmentStore | undefined;
|
|
154
|
+
/** Durable catalog store seeding capability metadata across restarts. */
|
|
155
|
+
catalogStore?: CatalogPersistence;
|
|
156
|
+
/**
|
|
157
|
+
* Per-model default reasoning effort override (the Settings page's picker).
|
|
158
|
+
* Returns the user-configured default for one model, or undefined to follow
|
|
159
|
+
* the provider's own default.
|
|
160
|
+
*/
|
|
161
|
+
defaultEffortOf?: (model: string) => string | undefined;
|
|
162
|
+
/** How long this route may hold a turn open waiting for a rate-limit window; defaults to waiting on, six-hour ceiling. */
|
|
163
|
+
rateLimit?: RateLimitWait;
|
|
164
|
+
}
|
|
165
|
+
/** Grok wire adapter: one instance serves the `grok` provider route. */
|
|
166
|
+
export declare class GrokAdapter extends LlmAdapter {
|
|
167
|
+
private readonly options;
|
|
168
|
+
private readonly catalog;
|
|
169
|
+
/** In-memory catalogs for non-default accounts (the persisted cache is the default's). */
|
|
170
|
+
private readonly accountCatalogs;
|
|
171
|
+
/** Account whose snapshot currently lives in {@link catalog}; cleared on default change. */
|
|
172
|
+
private catalogOwner;
|
|
173
|
+
constructor(options: GrokAdapterOptions);
|
|
174
|
+
/** Discovery fetcher: resolves the session through the refresh-aware path. */
|
|
175
|
+
private fetchCatalog;
|
|
176
|
+
/** Drop cached catalogs after login/logout so the next list does not reuse a stale plan. */
|
|
177
|
+
clearAccountCatalog(account?: string): void;
|
|
178
|
+
/** Persisted cache for the default account; a throwaway cache for any other. */
|
|
179
|
+
private catalogFor;
|
|
180
|
+
private listed;
|
|
181
|
+
providerInfo(provider: string): LlmProviderInfo;
|
|
182
|
+
providerRetryPolicy(provider: string): import("@deepseek-ai/dsh-llm").ResolvedRetryPolicy;
|
|
183
|
+
private staticModels;
|
|
184
|
+
listModels(provider: string): Promise<readonly LlmModelInfo[]>;
|
|
185
|
+
/** The provider's own catalog: union of every account, or one account when named. */
|
|
186
|
+
listOwnModels(provider: string, account?: string, signal?: AbortSignal): Promise<readonly LlmModelInfo[]>;
|
|
187
|
+
/**
|
|
188
|
+
* The discovered entry for one model. Resolved through the cache's
|
|
189
|
+
* stale-while-revalidate path: capability metadata must stay stable across
|
|
190
|
+
* a long conversation — a session that selected a reasoning effort calls
|
|
191
|
+
* this on EVERY step, and forgetting the efforts just because the TTL
|
|
192
|
+
* lapsed mid-turn would fail the call with UNSUPPORTED_REASONING_EFFORT
|
|
193
|
+
* before provider I/O.
|
|
194
|
+
*/
|
|
195
|
+
private discovered;
|
|
196
|
+
resolveModel(provider: string, model: string): Promise<LlmResolvedModelInfo>;
|
|
197
|
+
/** Capability resolution of the provider's own models (the pool resolves members here). */
|
|
198
|
+
resolveOwnModel(provider: string, model: string): Promise<LlmResolvedModelInfo>;
|
|
199
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
200
|
+
/** Pool seam: stream through one specific account instead of the default. */
|
|
201
|
+
streamAccount(options: GenerateOptions, account: string): AsyncIterable<StreamChunk>;
|
|
202
|
+
private streamCore;
|
|
203
|
+
private request;
|
|
204
|
+
}
|
|
205
|
+
export {};
|