integrate models.dev

This commit is contained in:
Dax Raad 2025-06-22 19:10:59 -04:00
parent 5e46d98c86
commit 0542cf7e69
3 changed files with 4 additions and 43 deletions

View file

@ -1,37 +1,3 @@
{ {
"$schema": "https://opencode.ai/config.json", "$schema": "https://opencode.ai/config.json"
"provider": {
"github-copilot": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.githubcopilot.com"
},
"models": {
"gpt-4o": {
"name": "gpt-4o"
},
"gpt-4.1": {
"name": "gpt-4.1"
},
"claude-sonnet-4": {
"name": "claude-sonnet-4"
},
"claude-3.7-sonnet": {
"name": "claude-3.7-sonnet"
},
"o1": {
"name": "o1"
},
"o3-mini": {
"name": "o3-mini"
},
"gemini-2.5-pro": {
"name": "gemini-2.5-pro"
},
"gemini-2.0-flash-001": {
"name": "gemini-2.0-flash-001"
}
}
}
}
} }

View file

@ -94,8 +94,7 @@ export namespace AuthGithubCopilot {
export async function access() { export async function access() {
const info = await Auth.get("github-copilot") const info = await Auth.get("github-copilot")
if (!info || info.type !== "oauth") return if (!info || info.type !== "oauth") return
if (info.access && info.expires > Date.now()) if (info.access && info.expires > Date.now()) return info.access
return { access: info.access, api: "https://api.githubcopilot.com" }
// Get new Copilot API token // Get new Copilot API token
const response = await fetch(COPILOT_API_KEY_URL, { const response = await fetch(COPILOT_API_KEY_URL, {
@ -120,10 +119,7 @@ export namespace AuthGithubCopilot {
expires: tokenData.expires_at * 1000, expires: tokenData.expires_at * 1000,
}) })
return { return tokenData.token
access: tokenData.token,
api: tokenData.endpoints.api,
}
} }
export const DeviceCodeError = NamedError.create( export const DeviceCodeError = NamedError.create(

View file

@ -83,13 +83,12 @@ export namespace Provider {
return { return {
options: { options: {
apiKey: "", apiKey: "",
baseURL: info.api,
async fetch(input: any, init: any) { async fetch(input: any, init: any) {
const token = await AuthGithubCopilot.access() const token = await AuthGithubCopilot.access()
if (!token) throw new Error("GitHub Copilot authentication expired") if (!token) throw new Error("GitHub Copilot authentication expired")
const headers = { const headers = {
...init.headers, ...init.headers,
Authorization: `Bearer ${token.access}`, Authorization: `Bearer ${token}`,
"User-Agent": "GithubCopilot/1.155.0", "User-Agent": "GithubCopilot/1.155.0",
"Editor-Version": "vscode/1.85.1", "Editor-Version": "vscode/1.85.1",
"Editor-Plugin-Version": "copilot/1.155.0", "Editor-Plugin-Version": "copilot/1.155.0",