feat: Add GitHub Copilot SDK provider integration (#661)

* feat: add GitHub Copilot SDK provider integration

Adds comprehensive GitHub Copilot SDK provider support including:
- CopilotProvider class with CLI detection and OAuth authentication check
- Copilot models definition with GPT-4o, Claude, and o1/o3 series models
- Settings UI integration with provider tab, model configuration, and navigation
- Onboarding flow integration with Copilot setup step
- Model selector integration for all phase-specific model dropdowns
- Persistence of enabled models and default model settings via API sync
- Server route for Copilot CLI status endpoint

https://claude.ai/code/session_01D26w7ZyEzP4H6Dor3ttk9d

* chore: update package-lock.json

https://claude.ai/code/session_01D26w7ZyEzP4H6Dor3ttk9d

* refactor: rename Copilot SDK to Copilot CLI and use GitHub icon

- Update all references from "GitHub Copilot SDK" to "GitHub Copilot CLI"
- Change install command from @github/copilot-sdk to @github/copilot
- Update CopilotIcon to use official GitHub Octocat logo
- Update error codes and comments throughout codebase

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: update Copilot model definitions and add dynamic model discovery

- Update COPILOT_MODEL_MAP with correct models from CLI (claude-sonnet-4.5,
  claude-haiku-4.5, claude-opus-4.5, claude-sonnet-4, gpt-5.x series, gpt-4.1,
  gemini-3-pro-preview)
- Change default Copilot model to copilot-claude-sonnet-4.5
- Add model caching methods to CopilotProvider (hasCachedModels,
  clearModelCache, refreshModels)
- Add API routes for dynamic model discovery:
  - GET /api/setup/copilot/models
  - POST /api/setup/copilot/models/refresh
  - POST /api/setup/copilot/cache/clear

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor: use @github/copilot-sdk instead of direct CLI calls

- Install @github/copilot-sdk package for proper SDK integration
- Rewrite CopilotProvider to use SDK's CopilotClient API
- Use client.createSession() for session management
- Handle SDK events (assistant.message, tool.execution_*, session.idle)
- Auto-approve permissions for autonomous agent operation
- Remove incorrect CLI flags (--mode, --output-format)
- Update default model to claude-sonnet-4.5

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: add Copilot and Gemini model support to model resolver

- Import isCopilotModel and isGeminiModel from types
- Add explicit checks for copilot- and gemini- prefixed models
- Pass through Copilot/Gemini models unchanged to their providers
- Update resolver documentation to list all supported providers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: pass working directory to Copilot SDK and reduce event noise

- Create CopilotClient per execution with correct cwd from options.cwd
- This ensures the CLI operates in the correct project directory, not the
  server's current directory
- Skip assistant.message_delta events (they create excessive noise)
- Only yield the final assistant.message event which has complete content
- Clean up client on completion and error paths

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: simplify Copilot SDK execution with sendAndWait

- Use sendAndWait() instead of manual event polling for more reliable
  execution
- Disable streaming (streaming: false) to simplify response handling
- Increase timeout to 10 minutes for agentic operations
- Still capture tool execution events for UI display
- Add more debug logging for troubleshooting
- This should fix the "invalid_request_body" error on subsequent calls

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: allow Copilot model IDs with claude-, gemini-, gpt- prefixes

Copilot's bare model IDs legitimately contain prefixes like claude-,
gemini-, gpt- because those are the actual model names from the
Copilot CLI (e.g., claude-sonnet-4.5, gemini-3-pro-preview, gpt-5.1).

The generic validateBareModelId function was incorrectly rejecting
these valid model IDs. Now we only check that the copilot- prefix
has been stripped by the ProviderFactory.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat: enable real-time streaming of tool events for Copilot

- Switch back to streaming mode (streaming: true) for real-time events
- Use async queue pattern to bridge SDK callbacks to async generator
- Events are now yielded as they happen, not batched at the end
- Tool calls (Read, Write, Edit, Bash, TodoWrite, etc.) show in real-time
- Better progress visibility during agentic operations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat: expand Copilot tool name and input normalization

Tool name mapping additions:
- view → Read (Copilot's file viewing tool)
- create_file → Write
- replace, patch → Edit
- run_shell_command, terminal → Bash
- search_file_content → Grep
- list_directory → Ls
- google_web_search → WebSearch
- report_intent → ReportIntent (Copilot-specific planning)
- think, plan → Think, Plan

Input normalization improvements:
- Read/Write/Edit: Map file, filename, filePath → file_path
- Bash: Map cmd, script → command
- Grep: Map query, search, regex → pattern

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: convert git+ssh to git+https in package-lock.json

The @electron/node-gyp dependency was resolved with a git+ssh URL
which fails in CI environments without SSH keys. Convert to HTTPS.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: address code review feedback for Copilot SDK provider

- Add guard for non-text prompts (vision not yet supported)
- Clear runtime model cache on fetch failure
- Fix race condition in async queue error handling
- Import CopilotAuthStatus from shared types
- Fix comment mismatch for default model constant
- Add auth-copilot and deauth-copilot routes
- Extract shared tool normalization utilities
- Create base model configuration UI component
- Add comprehensive unit tests for CopilotProvider
- Replace magic strings with constants
- Add debug logging for cleanup errors

* fix: address CodeRabbit review nitpicks

- Fix test mocks to include --version check for CLI detection
- Add aria-label for accessibility on refresh button
- Ensure default model checkbox always appears checked/enabled

* fix: address CodeRabbit review feedback

- Fix test mocks by creating fresh provider instances after mock setup
- Extract COPILOT_DISCONNECTED_MARKER_FILE constant to common.ts
- Add AUTONOMOUS MODE comment explaining auto-approval of permissions
- Improve tool-normalization with union types and null guards
- Handle 'canceled' (American spelling) status in todo normalization

* refactor: extract copilot connection logic to service and fix test mocks

- Create copilot-connection-service.ts with connect/disconnect logic
- Update auth-copilot and deauth-copilot routes to use service
- Fix test mocks for CLI detection:
  - Mock fs.existsSync for CLI path validation
  - Mock which/where command for CLI path detection

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Stefan de Vogelaere
2026-01-23 14:48:33 +01:00
committed by GitHub
parent 51a75ae589
commit 0b92349890
43 changed files with 3588 additions and 145 deletions

View File

@@ -0,0 +1,194 @@
/**
* GitHub Copilot CLI Model Definitions
*
* Defines available models for GitHub Copilot CLI integration.
* Based on https://github.com/github/copilot
*
* The CLI provides runtime model discovery, but we define common models
* for UI consistency and offline use.
*/
/**
* Copilot model configuration
*/
export interface CopilotModelConfig {
label: string;
description: string;
supportsVision: boolean;
supportsTools: boolean;
contextWindow?: number;
}
/**
* Available Copilot models via the GitHub Copilot CLI
*
* Model IDs use 'copilot-' prefix for consistent provider routing.
* When passed to the CLI, the prefix is stripped.
*
* Note: Actual available models depend on the user's Copilot subscription
* and can be discovered at runtime via the CLI's listModels() method.
*/
export const COPILOT_MODEL_MAP = {
// Claude models (Anthropic via GitHub Copilot)
'copilot-claude-sonnet-4.5': {
label: 'Claude Sonnet 4.5',
description: 'Anthropic Claude Sonnet 4.5 via GitHub Copilot.',
supportsVision: true,
supportsTools: true,
contextWindow: 200000,
},
'copilot-claude-haiku-4.5': {
label: 'Claude Haiku 4.5',
description: 'Fast and efficient Claude Haiku 4.5 via GitHub Copilot.',
supportsVision: true,
supportsTools: true,
contextWindow: 200000,
},
'copilot-claude-opus-4.5': {
label: 'Claude Opus 4.5',
description: 'Most capable Claude Opus 4.5 via GitHub Copilot.',
supportsVision: true,
supportsTools: true,
contextWindow: 200000,
},
'copilot-claude-sonnet-4': {
label: 'Claude Sonnet 4',
description: 'Anthropic Claude Sonnet 4 via GitHub Copilot.',
supportsVision: true,
supportsTools: true,
contextWindow: 200000,
},
// GPT-5 series (OpenAI via GitHub Copilot)
'copilot-gpt-5.2-codex': {
label: 'GPT-5.2 Codex',
description: 'OpenAI GPT-5.2 Codex for advanced coding tasks.',
supportsVision: true,
supportsTools: true,
contextWindow: 128000,
},
'copilot-gpt-5.1-codex-max': {
label: 'GPT-5.1 Codex Max',
description: 'Maximum capability GPT-5.1 Codex model.',
supportsVision: true,
supportsTools: true,
contextWindow: 128000,
},
'copilot-gpt-5.1-codex': {
label: 'GPT-5.1 Codex',
description: 'OpenAI GPT-5.1 Codex for coding tasks.',
supportsVision: true,
supportsTools: true,
contextWindow: 128000,
},
'copilot-gpt-5.2': {
label: 'GPT-5.2',
description: 'Latest OpenAI GPT-5.2 model.',
supportsVision: true,
supportsTools: true,
contextWindow: 128000,
},
'copilot-gpt-5.1': {
label: 'GPT-5.1',
description: 'OpenAI GPT-5.1 model.',
supportsVision: true,
supportsTools: true,
contextWindow: 128000,
},
'copilot-gpt-5': {
label: 'GPT-5',
description: 'OpenAI GPT-5 base model.',
supportsVision: true,
supportsTools: true,
contextWindow: 128000,
},
'copilot-gpt-5.1-codex-mini': {
label: 'GPT-5.1 Codex Mini',
description: 'Fast and efficient GPT-5.1 Codex Mini.',
supportsVision: true,
supportsTools: true,
contextWindow: 128000,
},
'copilot-gpt-5-mini': {
label: 'GPT-5 Mini',
description: 'Lightweight GPT-5 Mini model.',
supportsVision: true,
supportsTools: true,
contextWindow: 128000,
},
'copilot-gpt-4.1': {
label: 'GPT-4.1',
description: 'OpenAI GPT-4.1 model.',
supportsVision: true,
supportsTools: true,
contextWindow: 128000,
},
// Gemini models (Google via GitHub Copilot)
'copilot-gemini-3-pro-preview': {
label: 'Gemini 3 Pro Preview',
description: 'Google Gemini 3 Pro Preview via GitHub Copilot.',
supportsVision: true,
supportsTools: true,
contextWindow: 1000000,
},
} as const satisfies Record<string, CopilotModelConfig>;
/**
* Copilot model ID type (keys have copilot- prefix)
*/
export type CopilotModelId = keyof typeof COPILOT_MODEL_MAP;
/**
* Get all Copilot model IDs
*/
export function getAllCopilotModelIds(): CopilotModelId[] {
return Object.keys(COPILOT_MODEL_MAP) as CopilotModelId[];
}
/**
* Default Copilot model
*/
export const DEFAULT_COPILOT_MODEL: CopilotModelId = 'copilot-claude-sonnet-4.5';
/**
* GitHub Copilot authentication status
*/
export interface CopilotAuthStatus {
authenticated: boolean;
method: 'oauth' | 'cli' | 'none';
authType?: string;
login?: string;
host?: string;
statusMessage?: string;
error?: string;
}
/**
* Copilot CLI status (used for installation detection)
*/
export interface CopilotCliStatus {
installed: boolean;
version?: string;
path?: string;
auth?: CopilotAuthStatus;
error?: string;
}
/**
* Copilot model info from SDK runtime discovery
*/
export interface CopilotRuntimeModel {
id: string;
name: string;
capabilities?: {
supportsVision?: boolean;
maxInputTokens?: number;
maxOutputTokens?: number;
};
policy?: {
state: 'enabled' | 'disabled' | 'unconfigured';
terms?: string;
};
billing?: {
multiplier: number;
};
}

View File

@@ -253,6 +253,9 @@ export * from './opencode-models.js';
// Gemini types
export * from './gemini-models.js';
// Copilot types
export * from './copilot-models.js';
// Provider utilities
export {
PROVIDER_PREFIXES,
@@ -261,6 +264,7 @@ export {
isCodexModel,
isOpencodeModel,
isGeminiModel,
isCopilotModel,
getModelProvider,
stripProviderPrefix,
addProviderPrefix,

View File

@@ -11,6 +11,7 @@ import { CURSOR_MODEL_MAP, LEGACY_CURSOR_MODEL_MAP } from './cursor-models.js';
import { CLAUDE_MODEL_MAP, CODEX_MODEL_MAP } from './model.js';
import { OPENCODE_MODEL_CONFIG_MAP, LEGACY_OPENCODE_MODEL_MAP } from './opencode-models.js';
import { GEMINI_MODEL_MAP } from './gemini-models.js';
import { COPILOT_MODEL_MAP } from './copilot-models.js';
/** Provider prefix constants */
export const PROVIDER_PREFIXES = {
@@ -18,6 +19,7 @@ export const PROVIDER_PREFIXES = {
codex: 'codex-',
opencode: 'opencode-',
gemini: 'gemini-',
copilot: 'copilot-',
} as const;
/**
@@ -114,6 +116,28 @@ export function isGeminiModel(model: string | undefined | null): boolean {
return false;
}
/**
* Check if a model string represents a GitHub Copilot model
*
* @param model - Model string to check (e.g., "copilot-gpt-4o", "copilot-claude-3.5-sonnet")
* @returns true if the model is a Copilot model
*/
export function isCopilotModel(model: string | undefined | null): boolean {
if (!model || typeof model !== 'string') return false;
// Canonical format: copilot- prefix (e.g., "copilot-gpt-4o")
if (model.startsWith(PROVIDER_PREFIXES.copilot)) {
return true;
}
// Check if it's a known Copilot model ID (map keys include copilot- prefix)
if (model in COPILOT_MODEL_MAP) {
return true;
}
return false;
}
/**
* Check if a model string represents an OpenCode model
*
@@ -175,7 +199,11 @@ export function isOpencodeModel(model: string | undefined | null): boolean {
* @returns The provider type, defaults to 'claude' for unknown models
*/
export function getModelProvider(model: string | undefined | null): ModelProvider {
// Check Gemini first since it uses gemini- prefix
// Check Copilot first since it has a unique prefix
if (isCopilotModel(model)) {
return 'copilot';
}
// Check Gemini since it uses gemini- prefix
if (isGeminiModel(model)) {
return 'gemini';
}
@@ -248,6 +276,10 @@ export function addProviderPrefix(model: string, provider: ModelProvider): strin
if (!model.startsWith(PROVIDER_PREFIXES.gemini)) {
return `${PROVIDER_PREFIXES.gemini}${model}`;
}
} else if (provider === 'copilot') {
if (!model.startsWith(PROVIDER_PREFIXES.copilot)) {
return `${PROVIDER_PREFIXES.copilot}${model}`;
}
}
// Claude models don't use prefixes
return model;
@@ -284,6 +316,7 @@ export function normalizeModelString(model: string | undefined | null): string {
model.startsWith(PROVIDER_PREFIXES.codex) ||
model.startsWith(PROVIDER_PREFIXES.opencode) ||
model.startsWith(PROVIDER_PREFIXES.gemini) ||
model.startsWith(PROVIDER_PREFIXES.copilot) ||
model.startsWith('claude-')
) {
return model;

View File

@@ -11,6 +11,10 @@ import type { CursorModelId } from './cursor-models.js';
import { CURSOR_MODEL_MAP, getAllCursorModelIds } from './cursor-models.js';
import type { OpencodeModelId } from './opencode-models.js';
import { getAllOpencodeModelIds, DEFAULT_OPENCODE_MODEL } from './opencode-models.js';
import type { GeminiModelId } from './gemini-models.js';
import { getAllGeminiModelIds, DEFAULT_GEMINI_MODEL } from './gemini-models.js';
import type { CopilotModelId } from './copilot-models.js';
import { getAllCopilotModelIds, DEFAULT_COPILOT_MODEL } from './copilot-models.js';
import type { PromptCustomization } from './prompts.js';
import type { CodexSandboxMode, CodexApprovalPolicy } from './codex.js';
import type { ReasoningEffort } from './provider.js';
@@ -99,7 +103,7 @@ export function getThinkingTokenBudget(level: ThinkingLevel | undefined): number
}
/** ModelProvider - AI model provider for credentials and API key management */
export type ModelProvider = 'claude' | 'cursor' | 'codex' | 'opencode' | 'gemini';
export type ModelProvider = 'claude' | 'cursor' | 'codex' | 'opencode' | 'gemini' | 'copilot';
// ============================================================================
// Claude-Compatible Providers - Configuration for Claude-compatible API endpoints
@@ -895,6 +899,18 @@ export interface GlobalSettings {
/** Which dynamic OpenCode models are enabled (empty = all discovered) */
enabledDynamicModelIds?: string[];
// Gemini CLI Settings (global)
/** Which Gemini models are available in feature modal (empty = all) */
enabledGeminiModels?: GeminiModelId[];
/** Default Gemini model selection when switching to Gemini CLI */
geminiDefaultModel?: GeminiModelId;
// Copilot CLI Settings (global)
/** Which Copilot models are available in feature modal (empty = all) */
enabledCopilotModels?: CopilotModelId[];
/** Default Copilot model selection when switching to Copilot CLI */
copilotDefaultModel?: CopilotModelId;
// Provider Visibility Settings
/** Providers that are disabled and should not appear in model dropdowns */
disabledProviders?: ModelProvider[];
@@ -1316,6 +1332,10 @@ export const DEFAULT_GLOBAL_SETTINGS: GlobalSettings = {
enabledOpencodeModels: getAllOpencodeModelIds(), // Returns prefixed IDs
opencodeDefaultModel: DEFAULT_OPENCODE_MODEL, // Already prefixed
enabledDynamicModelIds: [],
enabledGeminiModels: getAllGeminiModelIds(), // Returns prefixed IDs
geminiDefaultModel: DEFAULT_GEMINI_MODEL, // Already prefixed
enabledCopilotModels: getAllCopilotModelIds(), // Returns prefixed IDs
copilotDefaultModel: DEFAULT_COPILOT_MODEL, // Already prefixed
disabledProviders: [],
keyboardShortcuts: DEFAULT_KEYBOARD_SHORTCUTS,
projects: [],