Skip to content

Commit 6e825b2

Browse files
committed
feat: add Copilot that support agent mode
- Implemented the Copilot component with authentication and model selection features. - Added tests for the Copilot component covering authentication, error handling, and model management. - Updated localization files to include Copilot-related strings in multiple languages. - Enhanced model validation functions to support Copilot models. - Integrated Copilot into the settings provider index and updated hooks to handle selected models.
1 parent 48af73d commit 6e825b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2682
-1
lines changed

packages/types/src/provider-settings.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const providerNames = [
4747
"zai",
4848
"fireworks",
4949
"io-intelligence",
50+
"copilot",
5051
] as const
5152

5253
export const providerNamesSchema = z.enum(providerNames)
@@ -288,6 +289,10 @@ const ioIntelligenceSchema = apiModelIdProviderModelSchema.extend({
288289
ioIntelligenceApiKey: z.string().optional(),
289290
})
290291

292+
const copilotSchema = baseProviderSettingsSchema.extend({
293+
copilotModelId: z.string().optional(),
294+
})
295+
291296
const defaultSchema = z.object({
292297
apiProvider: z.undefined(),
293298
})
@@ -324,6 +329,7 @@ export const providerSettingsSchemaDiscriminated = z.discriminatedUnion("apiProv
324329
zaiSchema.merge(z.object({ apiProvider: z.literal("zai") })),
325330
fireworksSchema.merge(z.object({ apiProvider: z.literal("fireworks") })),
326331
ioIntelligenceSchema.merge(z.object({ apiProvider: z.literal("io-intelligence") })),
332+
copilotSchema.merge(z.object({ apiProvider: z.literal("copilot") })),
327333
defaultSchema,
328334
])
329335

@@ -360,6 +366,7 @@ export const providerSettingsSchema = z.object({
360366
...zaiSchema.shape,
361367
...fireworksSchema.shape,
362368
...ioIntelligenceSchema.shape,
369+
...copilotSchema.shape,
363370
...codebaseIndexProviderSchema.shape,
364371
})
365372

@@ -386,6 +393,7 @@ export const MODEL_ID_KEYS: Partial<keyof ProviderSettings>[] = [
386393
"litellmModelId",
387394
"huggingFaceModelId",
388395
"ioIntelligenceModelId",
396+
"copilotModelId",
389397
]
390398

391399
export const getModelId = (settings: ProviderSettings): string | undefined => {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const copilotDefaultModelId = "claude-sonnet-4"
2+
3+
export const GITHUB_CLIENT_ID = "Iv1.b507a08c87ecfe98"
4+
export const GITHUB_DEVICE_CODE_URL = "https://github.com/login/device/code"
5+
export const GITHUB_ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token"
6+
export const GITHUB_API_KEY_URL = "https://api.github.com/copilot_internal/v2/token"
7+
export const GITHUB_COPILOT_API_BASE = "https://api.githubcopilot.com/"
8+
9+
export const COPILOT_DEFAULT_HEADER = {
10+
accept: "application/json",
11+
"content-type": "application/json",
12+
"editor-version": "vscode/1.85.1",
13+
"editor-plugin-version": "copilot/1.155.0",
14+
"user-agent": "GithubCopilot/1.155.0",
15+
"accept-encoding": "gzip,deflate,br",
16+
}

packages/types/src/providers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export * from "./xai.js"
2525
export * from "./doubao.js"
2626
export * from "./zai.js"
2727
export * from "./fireworks.js"
28+
export * from "./copilot.js"

src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
DoubaoHandler,
3737
ZAiHandler,
3838
FireworksHandler,
39+
CopilotHandler,
3940
} from "./providers"
4041

4142
export interface SingleCompletionHandler {
@@ -140,6 +141,8 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
140141
return new FireworksHandler(options)
141142
case "io-intelligence":
142143
return new IOIntelligenceHandler(options)
144+
case "copilot":
145+
return new CopilotHandler(options)
143146
default:
144147
apiProvider satisfies "gemini-cli" | undefined
145148
return new AnthropicHandler(options)

0 commit comments

Comments
 (0)