Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion packages/opencode/src/plugin/github-copilot/copilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ function getUrls(domain: string) {
}

function base(enterpriseUrl?: string) {
return enterpriseUrl ? `https://copilot-api.${normalizeDomain(enterpriseUrl)}` : "https://api.githubcopilot.com"
const domain = enterpriseUrl ? normalizeDomain(enterpriseUrl) : undefined
return !domain || domain.toLowerCase() === "github.com"
? "https://api.githubcopilot.com"
: `https://copilot-api.${domain}`
}

// Check if a message is a synthetic user msg used to attach an image from a tool call
Expand Down
38 changes: 38 additions & 0 deletions packages/opencode/test/plugin/github-copilot-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,41 @@ test("remaps fallback oauth model urls to the enterprise host", async () => {
expect(models.claude.api.url).toBe("https://copilot-api.ghe.example.com")
expect(models.claude.api.npm).toBe("@ai-sdk/github-copilot")
})

test("uses the public Copilot host for github.com OAuth accounts", async () => {
const urls: string[] = []
globalThis.fetch = mock((input: RequestInfo | URL) => {
urls.push(input instanceof URL ? input.href : typeof input === "string" ? input : input.url)
return Promise.resolve(new Response(JSON.stringify({ data: [] }), { status: 200 }))
}) as unknown as typeof fetch

const hooks = await CopilotAuthPlugin({
client: {} as never,
project: {} as never,
directory: "",
worktree: "",
experimental_workspace: {
register() {},
},
serverUrl: new URL("https://example.com"),
$: {} as never,
})

await hooks.provider!.models!(
{
id: "github-copilot",
models: {},
} as never,
{
auth: {
type: "oauth",
refresh: "token",
access: "token",
expires: Date.now() + 60_000,
enterpriseUrl: "github.com",
} as never,
},
)

expect(urls).toEqual(["https://api.githubcopilot.com/models"])
})
Loading