Skip to content

feat: add GitHub Copilot Provider that support agent mode #7010 #7072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/types/src/provider-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const providerNames = [
"zai",
"fireworks",
"io-intelligence",
"copilot",
] as const

export const providerNamesSchema = z.enum(providerNames)
Expand Down Expand Up @@ -288,6 +289,10 @@ const ioIntelligenceSchema = apiModelIdProviderModelSchema.extend({
ioIntelligenceApiKey: z.string().optional(),
})

const copilotSchema = baseProviderSettingsSchema.extend({
copilotModelId: z.string().optional(),
})

const defaultSchema = z.object({
apiProvider: z.undefined(),
})
Expand Down Expand Up @@ -324,6 +329,7 @@ export const providerSettingsSchemaDiscriminated = z.discriminatedUnion("apiProv
zaiSchema.merge(z.object({ apiProvider: z.literal("zai") })),
fireworksSchema.merge(z.object({ apiProvider: z.literal("fireworks") })),
ioIntelligenceSchema.merge(z.object({ apiProvider: z.literal("io-intelligence") })),
copilotSchema.merge(z.object({ apiProvider: z.literal("copilot") })),
defaultSchema,
])

Expand Down Expand Up @@ -360,6 +366,7 @@ export const providerSettingsSchema = z.object({
...zaiSchema.shape,
...fireworksSchema.shape,
...ioIntelligenceSchema.shape,
...copilotSchema.shape,
...codebaseIndexProviderSchema.shape,
})

Expand All @@ -386,6 +393,7 @@ export const MODEL_ID_KEYS: Partial<keyof ProviderSettings>[] = [
"litellmModelId",
"huggingFaceModelId",
"ioIntelligenceModelId",
"copilotModelId",
]

export const getModelId = (settings: ProviderSettings): string | undefined => {
Expand Down
16 changes: 16 additions & 0 deletions packages/types/src/providers/copilot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const copilotDefaultModelId = "claude-sonnet-4"

export const GITHUB_CLIENT_ID = "Iv1.b507a08c87ecfe98"
export const GITHUB_DEVICE_CODE_URL = "https://github.com/login/device/code"
export const GITHUB_ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token"
export const GITHUB_API_KEY_URL = "https://api.github.com/copilot_internal/v2/token"
export const GITHUB_COPILOT_API_BASE = "https://api.githubcopilot.com/"

export const COPILOT_DEFAULT_HEADER = {
accept: "application/json",
"content-type": "application/json",
"editor-version": "vscode/1.85.1",
"editor-plugin-version": "copilot/1.155.0",
"user-agent": "GithubCopilot/1.155.0",
"accept-encoding": "gzip,deflate,br",
}
1 change: 1 addition & 0 deletions packages/types/src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from "./xai.js"
export * from "./doubao.js"
export * from "./zai.js"
export * from "./fireworks.js"
export * from "./copilot.js"
3 changes: 3 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
DoubaoHandler,
ZAiHandler,
FireworksHandler,
CopilotHandler,
} from "./providers"

export interface SingleCompletionHandler {
Expand Down Expand Up @@ -140,6 +141,8 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
return new FireworksHandler(options)
case "io-intelligence":
return new IOIntelligenceHandler(options)
case "copilot":
return new CopilotHandler(options)
default:
apiProvider satisfies "gemini-cli" | undefined
return new AnthropicHandler(options)
Expand Down
Loading
Loading