|
|
@@ -27,11 +27,12 @@ function base(enterpriseUrl?: string) {
|
|
|
return enterpriseUrl ? `https://copilot-api.${normalizeDomain(enterpriseUrl)}` : "https://api.githubcopilot.com"
|
|
|
}
|
|
|
|
|
|
-function fix(model: Model): Model {
|
|
|
+function fix(model: Model, url: string): Model {
|
|
|
return {
|
|
|
...model,
|
|
|
api: {
|
|
|
...model.api,
|
|
|
+ url,
|
|
|
npm: "@ai-sdk/github-copilot",
|
|
|
},
|
|
|
}
|
|
|
@@ -44,19 +45,23 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
|
|
id: "github-copilot",
|
|
|
async models(provider, ctx) {
|
|
|
if (ctx.auth?.type !== "oauth") {
|
|
|
- return Object.fromEntries(Object.entries(provider.models).map(([id, model]) => [id, fix(model)]))
|
|
|
+ return Object.fromEntries(Object.entries(provider.models).map(([id, model]) => [id, fix(model, base())]))
|
|
|
}
|
|
|
|
|
|
+ const auth = ctx.auth
|
|
|
+
|
|
|
return CopilotModels.get(
|
|
|
- base(ctx.auth.enterpriseUrl),
|
|
|
+ base(auth.enterpriseUrl),
|
|
|
{
|
|
|
- Authorization: `Bearer ${ctx.auth.refresh}`,
|
|
|
+ Authorization: `Bearer ${auth.refresh}`,
|
|
|
"User-Agent": `opencode/${Installation.VERSION}`,
|
|
|
},
|
|
|
provider.models,
|
|
|
).catch((error) => {
|
|
|
log.error("failed to fetch copilot models", { error })
|
|
|
- return Object.fromEntries(Object.entries(provider.models).map(([id, model]) => [id, fix(model)]))
|
|
|
+ return Object.fromEntries(
|
|
|
+ Object.entries(provider.models).map(([id, model]) => [id, fix(model, base(auth.enterpriseUrl))]),
|
|
|
+ )
|
|
|
})
|
|
|
},
|
|
|
},
|
|
|
@@ -66,10 +71,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
|
|
const info = await getAuth()
|
|
|
if (!info || info.type !== "oauth") return {}
|
|
|
|
|
|
- const baseURL = base(info.enterpriseUrl)
|
|
|
-
|
|
|
return {
|
|
|
- baseURL,
|
|
|
apiKey: "",
|
|
|
async fetch(request: RequestInfo | URL, init?: RequestInit) {
|
|
|
const info = await getAuth()
|