@wrongstack/providers 0.265.1 → 0.267.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/dist/index.d.ts +222 -2
- package/dist/index.js +993 -256
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _wrongstack_core from '@wrongstack/core';
|
|
1
2
|
import { Provider, Capabilities, Request, Response, StreamEvent, ProviderError, TextBlock, Message, Tool, WireFamily, ProviderFactory, Usage, StopReason, ModelsRegistry, CustomModelDefinition, ContentBlock, Logger, ProviderConfig } from '@wrongstack/core';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -107,7 +108,7 @@ interface AnthropicProviderOptions {
|
|
|
107
108
|
streamOpts?: WireAdapterStreamOptions | undefined;
|
|
108
109
|
}
|
|
109
110
|
declare class AnthropicProvider extends WireAdapter {
|
|
110
|
-
readonly id
|
|
111
|
+
readonly id: string;
|
|
111
112
|
readonly capabilities: Capabilities;
|
|
112
113
|
private readonly opts;
|
|
113
114
|
constructor(opts: AnthropicProviderOptions);
|
|
@@ -295,6 +296,212 @@ declare class GoogleProvider extends WireAdapter {
|
|
|
295
296
|
private buildGenConfig;
|
|
296
297
|
}
|
|
297
298
|
|
|
299
|
+
/**
|
|
300
|
+
* `openai-codex` wire family — the ChatGPT-backend Responses API.
|
|
301
|
+
*
|
|
302
|
+
* This is the transport used by "Sign in with ChatGPT" (OAuth) credentials.
|
|
303
|
+
* It speaks the OpenAI **Responses** wire format (NOT chat/completions) and
|
|
304
|
+
* targets `https://chatgpt.com/backend-api/codex/responses`, authenticating
|
|
305
|
+
* with the OAuth access token + `chatgpt-account-id` header. It deliberately
|
|
306
|
+
* leaves the API-key `openai` family (api.openai.com/chat/completions)
|
|
307
|
+
* untouched — the two coexist as separate providers.
|
|
308
|
+
*
|
|
309
|
+
* Token lifecycle: the access token is short-lived. This adapter refreshes it
|
|
310
|
+
* transparently — before a request when it is near expiry, and once more on a
|
|
311
|
+
* 401 — using the stored refresh token, then invokes `onRefresh` so the CLI
|
|
312
|
+
* can persist the rotated tokens back to the vault.
|
|
313
|
+
*
|
|
314
|
+
* The refresh endpoint + client id are duplicated here (rather than imported
|
|
315
|
+
* from the CLI) to respect the package layering: `providers` must not depend
|
|
316
|
+
* on `cli`. They are tiny constants that match the CLI login module.
|
|
317
|
+
*/
|
|
318
|
+
|
|
319
|
+
interface CodexOAuthTokens {
|
|
320
|
+
access: string;
|
|
321
|
+
refresh: string;
|
|
322
|
+
/** Absolute expiry in epoch milliseconds. */
|
|
323
|
+
expires: number;
|
|
324
|
+
}
|
|
325
|
+
/** Refresh an expired Codex access token using its refresh token. */
|
|
326
|
+
declare function refreshCodexAccessToken(refreshToken: string, signal?: AbortSignal): Promise<CodexOAuthTokens>;
|
|
327
|
+
/** Extract `chatgpt_account_id` from an access-token JWT, or null. */
|
|
328
|
+
declare function extractAccountId(token: string): string | null;
|
|
329
|
+
interface CodexCredentials {
|
|
330
|
+
/** The OAuth access token (a JWT). */
|
|
331
|
+
accessToken: string;
|
|
332
|
+
/** The refresh token, used to mint a new access token before/at expiry. */
|
|
333
|
+
refreshToken?: string | undefined;
|
|
334
|
+
/** Access-token expiry, epoch ms. When absent, refresh only fires on 401. */
|
|
335
|
+
expiresAt?: number | undefined;
|
|
336
|
+
/** Cached ChatGPT account id. Re-derived from the live token when missing. */
|
|
337
|
+
accountId?: string | undefined;
|
|
338
|
+
}
|
|
339
|
+
interface OpenAICodexProviderOptions {
|
|
340
|
+
credentials: CodexCredentials;
|
|
341
|
+
baseUrl?: string | undefined;
|
|
342
|
+
id?: string | undefined;
|
|
343
|
+
fetchImpl?: typeof fetch | undefined;
|
|
344
|
+
capabilities?: Partial<Capabilities> | undefined;
|
|
345
|
+
streamOpts?: WireAdapterStreamOptions | undefined;
|
|
346
|
+
/**
|
|
347
|
+
* Persist rotated tokens after a successful refresh. The CLI wires this to
|
|
348
|
+
* write back to the encrypted config so the new access/refresh pair survive
|
|
349
|
+
* the session.
|
|
350
|
+
*/
|
|
351
|
+
onRefresh?: ((creds: {
|
|
352
|
+
accessToken: string;
|
|
353
|
+
refreshToken: string;
|
|
354
|
+
expiresAt: number;
|
|
355
|
+
accountId: string | undefined;
|
|
356
|
+
}) => void) | undefined;
|
|
357
|
+
/** Override the refresh call (tests). */
|
|
358
|
+
refreshFn?: ((refreshToken: string, signal?: AbortSignal) => Promise<CodexOAuthTokens>) | undefined;
|
|
359
|
+
/**
|
|
360
|
+
* Reasoning effort for the Codex (gpt-5.x) reasoning models. Sent as
|
|
361
|
+
* `reasoning.effort` with `summary: 'auto'` so chain-of-thought streams back
|
|
362
|
+
* as thinking deltas. Default 'medium'. Set 'none' to omit reasoning entirely.
|
|
363
|
+
*/
|
|
364
|
+
reasoningEffort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | undefined;
|
|
365
|
+
}
|
|
366
|
+
declare class OpenAICodexProvider extends WireAdapter {
|
|
367
|
+
readonly id: string;
|
|
368
|
+
readonly capabilities: Capabilities;
|
|
369
|
+
private access;
|
|
370
|
+
private refresh;
|
|
371
|
+
private expiresAt;
|
|
372
|
+
private accountId;
|
|
373
|
+
private readonly onRefresh;
|
|
374
|
+
private readonly refreshFn;
|
|
375
|
+
private readonly reasoningEffort;
|
|
376
|
+
constructor(opts: OpenAICodexProviderOptions);
|
|
377
|
+
stream(req: Request, opts: {
|
|
378
|
+
signal: AbortSignal;
|
|
379
|
+
}): AsyncIterable<StreamEvent>;
|
|
380
|
+
private ensureFreshToken;
|
|
381
|
+
private doRefresh;
|
|
382
|
+
protected buildUrl(_req: Request): string;
|
|
383
|
+
protected buildHeaders(_req: Request): Record<string, string>;
|
|
384
|
+
protected buildBody(req: Request): Record<string, unknown>;
|
|
385
|
+
protected parseStream(body: ReadableStream<Uint8Array> | NodeJS.ReadableStream | null, fallbackModel: string): AsyncIterable<StreamEvent>;
|
|
386
|
+
protected translateError(status: number, text: string): ProviderError;
|
|
387
|
+
}
|
|
388
|
+
/** Normalize a base URL to the `/codex/responses` endpoint. */
|
|
389
|
+
declare function resolveCodexUrl(baseUrl: string | undefined): string;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* `anthropic-oauth` wire family — Claude Pro/Max via "Sign in with Claude".
|
|
393
|
+
*
|
|
394
|
+
* Same wire as the API-key `anthropic` family (api.anthropic.com/v1/messages),
|
|
395
|
+
* but authenticated with an OAuth access token instead of an API key. Three
|
|
396
|
+
* things differ from the API-key path, all REQUIRED for the subscription
|
|
397
|
+
* backend to accept the request:
|
|
398
|
+
* 1. `Authorization: Bearer <access>` (no `x-api-key`).
|
|
399
|
+
* 2. `anthropic-beta: claude-code-20250219,oauth-2025-04-20`.
|
|
400
|
+
* 3. The first system block MUST be exactly the Claude Code identity line —
|
|
401
|
+
* Anthropic rejects OAuth requests whose system prompt doesn't lead with it.
|
|
402
|
+
*
|
|
403
|
+
* The API-key `anthropic` family is untouched. Tokens self-refresh (near-expiry
|
|
404
|
+
* + once on 401) via the refresh token; rotated tokens persist through the same
|
|
405
|
+
* `setOAuthTokenPersister` hook the codex family uses.
|
|
406
|
+
*/
|
|
407
|
+
|
|
408
|
+
/** Required first system block for OAuth/subscription requests. */
|
|
409
|
+
declare const CLAUDE_CODE_SYSTEM_PROMPT = "You are Claude Code, Anthropic's official CLI for Claude.";
|
|
410
|
+
interface AnthropicOAuthTokens {
|
|
411
|
+
access: string;
|
|
412
|
+
refresh: string;
|
|
413
|
+
/** Absolute expiry in epoch milliseconds. */
|
|
414
|
+
expires: number;
|
|
415
|
+
}
|
|
416
|
+
/** Refresh an expired Claude OAuth access token. */
|
|
417
|
+
declare function refreshAnthropicOAuthToken(refreshToken: string, signal?: AbortSignal): Promise<AnthropicOAuthTokens>;
|
|
418
|
+
interface AnthropicOAuthCredentials {
|
|
419
|
+
accessToken: string;
|
|
420
|
+
refreshToken?: string | undefined;
|
|
421
|
+
expiresAt?: number | undefined;
|
|
422
|
+
}
|
|
423
|
+
interface AnthropicOAuthProviderOptions {
|
|
424
|
+
credentials: AnthropicOAuthCredentials;
|
|
425
|
+
baseUrl?: string | undefined;
|
|
426
|
+
id?: string | undefined;
|
|
427
|
+
fetchImpl?: typeof fetch | undefined;
|
|
428
|
+
streamOpts?: WireAdapterStreamOptions | undefined;
|
|
429
|
+
onRefresh?: ((creds: {
|
|
430
|
+
accessToken: string;
|
|
431
|
+
refreshToken: string;
|
|
432
|
+
expiresAt: number;
|
|
433
|
+
}) => void) | undefined;
|
|
434
|
+
refreshFn?: ((refreshToken: string, signal?: AbortSignal) => Promise<AnthropicOAuthTokens>) | undefined;
|
|
435
|
+
}
|
|
436
|
+
declare class AnthropicOAuthProvider extends AnthropicProvider {
|
|
437
|
+
readonly id: string;
|
|
438
|
+
readonly capabilities: Capabilities;
|
|
439
|
+
private access;
|
|
440
|
+
private refresh;
|
|
441
|
+
private expiresAt;
|
|
442
|
+
private readonly onRefresh;
|
|
443
|
+
private readonly refreshFn;
|
|
444
|
+
constructor(opts: AnthropicOAuthProviderOptions);
|
|
445
|
+
stream(req: Request, opts: {
|
|
446
|
+
signal: AbortSignal;
|
|
447
|
+
}): AsyncGenerator<StreamEvent, void, any>;
|
|
448
|
+
/** Map Claude-Code-cased tool_use names in the stream back to real names. */
|
|
449
|
+
private remapToolNames;
|
|
450
|
+
private ensureFreshToken;
|
|
451
|
+
private doRefresh;
|
|
452
|
+
protected buildHeaders(_req: Request): Record<string, string>;
|
|
453
|
+
protected buildBody(req: Request): Record<string, unknown>;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** Derive the Copilot API base URL from a Copilot token's `proxy-ep` field. */
|
|
457
|
+
declare function copilotBaseUrlFromToken(token: string | undefined): string;
|
|
458
|
+
interface CopilotTokenResult {
|
|
459
|
+
/** The short-lived Copilot token (the access token used for chat). */
|
|
460
|
+
token: string;
|
|
461
|
+
/** Absolute expiry in epoch milliseconds. */
|
|
462
|
+
expires: number;
|
|
463
|
+
}
|
|
464
|
+
/** Mint a fresh Copilot token from the long-lived GitHub OAuth token. */
|
|
465
|
+
declare function refreshCopilotToken(githubToken: string, signal?: AbortSignal): Promise<CopilotTokenResult>;
|
|
466
|
+
interface CopilotCredentials {
|
|
467
|
+
/** Current Copilot token (access). May be empty → minted on first request. */
|
|
468
|
+
copilotToken: string;
|
|
469
|
+
/** Long-lived GitHub OAuth token (refresh; does not rotate). */
|
|
470
|
+
githubToken?: string | undefined;
|
|
471
|
+
/** Copilot-token expiry, epoch ms. */
|
|
472
|
+
expiresAt?: number | undefined;
|
|
473
|
+
}
|
|
474
|
+
interface GitHubCopilotProviderOptions {
|
|
475
|
+
credentials: CopilotCredentials;
|
|
476
|
+
id?: string | undefined;
|
|
477
|
+
fetchImpl?: typeof fetch | undefined;
|
|
478
|
+
capabilities?: Partial<Capabilities> | undefined;
|
|
479
|
+
streamOpts?: WireAdapterStreamOptions | undefined;
|
|
480
|
+
onRefresh?: ((creds: {
|
|
481
|
+
accessToken: string;
|
|
482
|
+
refreshToken: string;
|
|
483
|
+
expiresAt: number;
|
|
484
|
+
}) => void) | undefined;
|
|
485
|
+
refreshFn?: ((githubToken: string, signal?: AbortSignal) => Promise<CopilotTokenResult>) | undefined;
|
|
486
|
+
}
|
|
487
|
+
declare class GitHubCopilotProvider extends OpenAIProvider {
|
|
488
|
+
readonly capabilities: Capabilities;
|
|
489
|
+
private copilotToken;
|
|
490
|
+
private readonly githubToken;
|
|
491
|
+
private expiresAt;
|
|
492
|
+
private apiBase;
|
|
493
|
+
private readonly onRefresh;
|
|
494
|
+
private readonly refreshFn;
|
|
495
|
+
constructor(opts: GitHubCopilotProviderOptions);
|
|
496
|
+
stream(req: Request, opts: {
|
|
497
|
+
signal: AbortSignal;
|
|
498
|
+
}): AsyncGenerator<_wrongstack_core.StreamEvent, void, any>;
|
|
499
|
+
private ensureFreshToken;
|
|
500
|
+
private doRefresh;
|
|
501
|
+
protected buildUrl(_req: Request): string;
|
|
502
|
+
protected buildHeaders(_req: Request): Record<string, string>;
|
|
503
|
+
}
|
|
504
|
+
|
|
298
505
|
/**
|
|
299
506
|
* Singleton gate for stream debug logging.
|
|
300
507
|
*
|
|
@@ -608,6 +815,19 @@ interface BuildFactoriesOptions {
|
|
|
608
815
|
/** Used to log unsupported families during boot. */
|
|
609
816
|
log?: Logger | undefined;
|
|
610
817
|
}
|
|
818
|
+
/** Rotated-token payload handed to the OAuth persister after a refresh. */
|
|
819
|
+
interface OAuthRefreshedTokens {
|
|
820
|
+
accessToken: string;
|
|
821
|
+
refreshToken: string;
|
|
822
|
+
expiresAt: number;
|
|
823
|
+
/** ChatGPT account id (codex only); undefined for other OAuth families. */
|
|
824
|
+
accountId?: string | undefined;
|
|
825
|
+
}
|
|
826
|
+
/** @deprecated use OAuthRefreshedTokens */
|
|
827
|
+
type CodexRefreshedTokens = OAuthRefreshedTokens;
|
|
828
|
+
declare function setOAuthTokenPersister(fn: ((providerId: string, creds: OAuthRefreshedTokens) => void) | undefined): void;
|
|
829
|
+
/** @deprecated use setOAuthTokenPersister */
|
|
830
|
+
declare const setCodexTokenPersister: typeof setOAuthTokenPersister;
|
|
611
831
|
/**
|
|
612
832
|
* Build one ProviderFactory per provider known to models.dev. The factory's
|
|
613
833
|
* `create(cfg)` resolves the wire-family at construction time and returns the
|
|
@@ -621,4 +841,4 @@ declare function buildProviderFactoriesFromRegistry(opts: BuildFactoriesOptions)
|
|
|
621
841
|
*/
|
|
622
842
|
declare function makeProviderFromConfig(id: string, cfg: ProviderConfig): Provider;
|
|
623
843
|
|
|
624
|
-
export { AnthropicProvider, type AnthropicProviderOptions, type BuildFactoriesOptions, CAPABILITIES_BY_FAMILY, type CompatibilityQuirks, type ConvertOptions, type DebugStreamCallback, type DebugStreamStats, GoogleProvider, type GoogleProviderOptions, type OpenAIChoice, type OpenAICompatibleOptions, OpenAICompatibleProvider, type OpenAIMessage, OpenAIProvider, type OpenAIProviderOptions, type OpenAIToolCall, WireAdapter, type WireAdapterStreamOptions, type WireFactoryOptions, type WireFormatConfig, WireFormatProvider, anthropicWireFormat, buildProviderFactoriesFromRegistry, capabilitiesFor, capabilitiesForFamily, contentFromAnthropic, contentFromOpenAI, createWireFormatFactory, defaultDebugStreamCallback, defineWireFormat, googleWireFormat, isDebugStreamEnabled, makeProviderFromConfig, messagesToOpenAI, mistralWireFormat, normalizeAnthropic, normalizeOpenAI, openaiWireFormat, parseProviderHttpError, pushDebugChunkStats, setDebugStreamCallback, setDebugStreamEnabled, toolsToAnthropic, toolsToOpenAI };
|
|
844
|
+
export { type AnthropicOAuthCredentials, AnthropicOAuthProvider, type AnthropicOAuthProviderOptions, type AnthropicOAuthTokens, AnthropicProvider, type AnthropicProviderOptions, type BuildFactoriesOptions, CAPABILITIES_BY_FAMILY, CLAUDE_CODE_SYSTEM_PROMPT, type CodexCredentials, type CodexOAuthTokens, type CodexRefreshedTokens, type CompatibilityQuirks, type ConvertOptions, type CopilotCredentials, type CopilotTokenResult, type DebugStreamCallback, type DebugStreamStats, GitHubCopilotProvider, type GitHubCopilotProviderOptions, GoogleProvider, type GoogleProviderOptions, type OAuthRefreshedTokens, type OpenAIChoice, OpenAICodexProvider, type OpenAICodexProviderOptions, type OpenAICompatibleOptions, OpenAICompatibleProvider, type OpenAIMessage, OpenAIProvider, type OpenAIProviderOptions, type OpenAIToolCall, WireAdapter, type WireAdapterStreamOptions, type WireFactoryOptions, type WireFormatConfig, WireFormatProvider, anthropicWireFormat, buildProviderFactoriesFromRegistry, capabilitiesFor, capabilitiesForFamily, contentFromAnthropic, contentFromOpenAI, copilotBaseUrlFromToken, createWireFormatFactory, defaultDebugStreamCallback, defineWireFormat, extractAccountId, googleWireFormat, isDebugStreamEnabled, makeProviderFromConfig, messagesToOpenAI, mistralWireFormat, normalizeAnthropic, normalizeOpenAI, openaiWireFormat, parseProviderHttpError, pushDebugChunkStats, refreshAnthropicOAuthToken, refreshCodexAccessToken, refreshCopilotToken, resolveCodexUrl, setCodexTokenPersister, setDebugStreamCallback, setDebugStreamEnabled, setOAuthTokenPersister, toolsToAnthropic, toolsToOpenAI };
|