/** * `github-copilot` wire family — GitHub Copilot subscription. * * Copilot's chat API is OpenAI chat/completions-compatible, so this extends * OpenAIProvider and only changes auth + base URL + headers: * - `Authorization: Bearer ` plus the Copilot editor headers * and `X-GitHub-Api-Version`. * - The base URL is derived from the Copilot token's `proxy-ep=` field * (e.g. https://api.individual.githubcopilot.com). * * Two tokens are involved: the long-lived GitHub OAuth token (stored as the * refresh token — it does NOT rotate) mints short-lived Copilot tokens via * `api.github.com/copilot_internal/v2/token`. This adapter refreshes the * Copilot token transparently (near-expiry + once on 401) and re-derives the * base URL from each new token. The API-key `openai` family is untouched. */ import type { Capabilities, Request } from '@wrongstack/core/types'; import { type CopilotTokenResult } from './github-copilot-token.js'; import type { OpenAIStreamState } from './presets/openai.js'; import { WireFormatProvider } from './wire-format.js'; import type { WireAdapterStreamOptions } from './wire-adapter.js'; import type { BuildBodyContext } from './model-output-limits.js'; export { type CopilotTokenResult, copilotBaseUrlFromToken, refreshCopilotToken, } from './github-copilot-token.js'; export interface CopilotCredentials { /** Current Copilot token (access). May be empty → minted on first request. */ copilotToken: string; /** Long-lived GitHub OAuth token (refresh; does not rotate). */ githubToken?: string | undefined; /** Copilot-token expiry, epoch ms. */ expiresAt?: number | undefined; } export interface GitHubCopilotProviderOptions { credentials: CopilotCredentials; id?: string | undefined; fetchImpl?: typeof fetch | undefined; capabilities?: Partial | undefined; streamOpts?: WireAdapterStreamOptions | undefined; onRefresh?: ((creds: { accessToken: string; expiresAt: number; }) => void) | undefined; refreshFn?: ((githubToken: string, signal?: AbortSignal) => Promise) | undefined; } export declare class GitHubCopilotProvider extends WireFormatProvider { readonly id: string; readonly capabilities: Capabilities; private copilotToken; private readonly githubToken; private apiBase; private readonly refreshFn; /** Shared OAuth refresh machinery — see packages/providers/src/oauth-refresh-coordinator.ts */ private readonly refreshCoordinator; constructor(opts: GitHubCopilotProviderOptions); stream(req: Request, opts: { signal: AbortSignal; }): AsyncGenerator; private ensureFreshToken; private doRefresh; protected buildUrl(_req: Request): string; /** * Copilot uses the legacy `max_tokens` field (OpenAI Chat Completions v1) * rather than the newer `max_completion_tokens` that `openaiWireFormat` * sends. Override buildBody to fix the field name after the preset runs. */ protected buildBody(req: Request, ctx: BuildBodyContext): Record; protected buildHeaders(_req: Request): Record; } //# sourceMappingURL=github-copilot.d.ts.map