/** * GitHub Copilot OAuth flow * * Inspired by: * - pi-mono: https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/utils/oauth/github-copilot.ts * - opencode: https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/plugin/github-copilot/copilot.ts * * Storage layout in AuthStorage: * - `refresh` holds the long-lived GitHub OAuth access token (used to mint Copilot tokens). * - `access` holds the short-lived Copilot bearer token (~30 minutes). * - `expires` is the Copilot bearer expiry (ms epoch, with a 5-minute safety buffer). * - `enterpriseUrl` is the GitHub Enterprise hostname, or undefined for github.com. */ import type { OAuthCredentials, OAuthProviderInterface } from '../types.js'; export type GitHubCopilotCredentials = OAuthCredentials & { enterpriseUrl?: string; }; export declare const COPILOT_USER_AGENT = "GitHubCopilotChat/0.35.0"; /** Headers that Copilot endpoints expect from a VS Code-like client. */ export declare const COPILOT_HEADERS: { readonly 'User-Agent': "GitHubCopilotChat/0.35.0"; readonly 'Editor-Version': "vscode/1.107.0"; readonly 'Editor-Plugin-Version': "copilot-chat/0.35.0"; readonly 'Copilot-Integration-Id': "vscode-chat"; }; /** * Normalize a user-entered Enterprise URL/domain into a hostname (e.g. `company.ghe.com`). * Returns null for an empty input or an unparseable URL. */ export declare function normalizeDomain(input: string): string | null; /** * Resolve the Copilot API base URL. * Prefers the `proxy-ep` parsed from the bearer token, then falls back to enterprise/individual defaults. */ export declare function getGitHubCopilotBaseUrl(token?: string, enterpriseDomain?: string): string; /** * Refresh the short-lived Copilot bearer token using the long-lived GitHub OAuth token. * * `refreshToken` here is the GitHub OAuth access token; the Copilot endpoint returns a * fresh bearer token (`token`) and absolute expiry (`expires_at`, seconds since epoch). */ export declare function refreshGitHubCopilotToken(refreshToken: string, enterpriseDomain?: string, signal?: AbortSignal): Promise; /** * Login with GitHub Copilot OAuth (device-code flow). * * Prompts for an optional GitHub Enterprise URL/domain, performs the device-code flow, * then exchanges the GitHub OAuth token for a Copilot bearer token. */ export declare function loginGitHubCopilot(options: { onAuth: (url: string, instructions?: string) => void; onPrompt: (prompt: { message: string; placeholder?: string; allowEmpty?: boolean; }) => Promise; onProgress?: (message: string) => void; signal?: AbortSignal; }): Promise; /** * Filtered, normalized entry from the Copilot `/models` API. * * The full API payload includes a lot of capability metadata; we only keep the bits * we need to expose models in `listAvailableModels()` and route requests sensibly. */ export type CopilotModelEntry = { /** Stable model id (e.g. `claude-sonnet-4.5`, `gpt-4.1`). */ id: string; /** Human-readable display name (e.g. `Claude Sonnet 4.5`). */ name: string; /** Vendor field from the API (e.g. `Anthropic`, `OpenAI`). */ vendor: string; /** * Endpoints the model exposes (e.g. `/chat/completions`, `/responses`, `/v1/messages`). * Empty when the API didn't return `supported_endpoints` for this entry. */ supportedEndpoints: string[]; /** True when `supported_endpoints` includes `/v1/messages` (Anthropic-shaped Copilot model). */ isAnthropicShaped: boolean; /** True when `capabilities.supports.vision` is true. */ supportsVision: boolean; /** True when the model supports tool calling. */ supportsToolCalls: boolean; }; /** * Fetch the Copilot model list available to the current subscription. * * Hits `${baseURL}/models` with the Copilot bearer token, filters to * `model_picker_enabled === true && policy.state !== 'disabled'`, and returns * a normalized list. Mirrors opencode's filtering rules. * * Inspired by: * - opencode: https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/plugin/github-copilot/models.ts */ export declare function fetchCopilotModels(opts: { baseUrl: string; bearerToken: string; signal?: AbortSignal; }): Promise; export declare const githubCopilotOAuthProvider: OAuthProviderInterface; //# sourceMappingURL=github-copilot.d.ts.map