import type { IOpenAiModelConnection } from './index.js'; export declare const OPENAI_CHATGPT_CODEX_BASE_URL = "https://chatgpt.com/backend-api/codex"; export declare const OPENAI_CHATGPT_DEFAULT_ORIGINATOR = "smartai"; /** Whether a failed ChatGPT request reached the provider: `notSent` never did, `outcomeUnknown` may have. */ export type TOpenAiChatGptRequestOutcome = 'notSent' | 'outcomeUnknown'; export declare class OpenAiChatGptAuthError extends Error { status?: number; body?: string; requestOutcome?: TOpenAiChatGptRequestOutcome; retryAfterMs?: number; constructor(message: string, options?: { status?: number; body?: string; requestOutcome?: TOpenAiChatGptRequestOutcome; retryAfterMs?: number; }); } /** * Access to ChatGPT with its identity stated by whoever issued it. * * `accountId` is optional only because a legacy login's token may carry no workspace claim; a request * then goes out without a `ChatGPT-Account-ID` header. Model connections require the workspace and take * `IOpenAiChatGptAccess`. */ export interface IOpenAiChatGptReadAccess { readonly accessToken: string; /** The ChatGPT workspace the token was issued for, sent as `ChatGPT-Account-ID`. */ readonly accountId?: string; /** Sent as `X-OpenAI-Fedramp: true` when set. */ readonly isFedrampAccount: boolean; } /** * Access to one ChatGPT workspace, as an account authority resolves it. * * The workspace and residency are the authority's statement and are used as given: this package never * reads them back out of the token, because the claims have one owner, and it is the authority. */ export interface IOpenAiChatGptAccess extends IOpenAiChatGptReadAccess { readonly accountId: string; } /** Resolved access, optionally stamped with the authority's generation of that access token. */ export interface IOpenAiChatGptAccessGrant extends IOpenAiChatGptAccess { /** * The authority's generation of this access token. When it is set and the provider rejects the token, * the connection resolves once more naming this generation, so the authority can renew exactly that * token, and sends the request again. */ readonly generation?: number; } export interface IOpenAiChatGptAccessResolveRequest { /** The provider request signal. A resolver should pass it through to its authority. */ readonly signal: AbortSignal; /** The generation of the access token the provider has just rejected with 401. */ readonly rejectedGeneration?: number; } /** The workspace and residency a connection is pinned to for its lifetime. */ export interface IOpenAiChatGptWorkspaceIdentity { readonly accountId: string; readonly isFedrampAccount: boolean; } export interface IOpenAiChatGptAccessConnectionOptions { /** Stable provider originator header. Defaults to `smartai`. */ readonly originator?: string; /** Optional underlying transport. Defaults to the current global fetch. */ readonly fetch?: typeof fetch; } export interface IOpenAiChatGptResolvingConnectionOptions extends IOpenAiChatGptAccessConnectionOptions { /** Every resolved access must state exactly this workspace and residency. */ readonly expectedIdentity: IOpenAiChatGptWorkspaceIdentity; /** Resolves current access immediately before every provider network request. */ readonly resolveAccess: (request: IOpenAiChatGptAccessResolveRequest) => Promise; } /** The headers a ChatGPT backend request authenticates with. Shared by inference and the model catalog. */ export declare function createOpenAiChatGptAccessHeaders(accessArg: IOpenAiChatGptReadAccess, originatorArg?: string): Record; /** * A ChatGPT connection that resolves its access before every provider HTTP request. * * The workspace and residency are pinned at construction; an access that states anything else stops the * request before the transport is called. A provider 401 is answered once: when the rejected access carried * a `generation`, the connection resolves again with `rejectedGeneration` and sends the request a second * time with the new access. A 401 that cannot be retried, and a second 401, fail with an * `OpenAiChatGptAuthError` whose `status` is 401. */ export declare const createOpenAiChatGptResolvingModelConnection: (optionsArg: IOpenAiChatGptResolvingConnectionOptions) => IOpenAiModelConnection; /** * A ChatGPT connection for one fixed access, with the workspace and residency its issuer stated. * * It sends exactly the access it was given, and a provider 401 fails with an `OpenAiChatGptAuthError` * whose `status` is 401. Use `createOpenAiChatGptResolvingModelConnection` when an authority renews the * access. */ export declare const createOpenAiChatGptAccessModelConnection: (accessArg: IOpenAiChatGptAccess, optionsArg?: IOpenAiChatGptAccessConnectionOptions) => IOpenAiModelConnection;