| 60 | provider: { |
| 61 | id: "github-copilot", |
| 62 | async models(provider, ctx) { |
| 63 | if (ctx.auth?.type !== "oauth") { |
| 64 | models = {} |
| 65 | return Object.fromEntries(Object.entries(provider.models).map(([id, model]) => [id, fix(model, base())])) |
| 66 | } |
| 67 | |
| 68 | const auth = ctx.auth |
| 69 | |
| 70 | return CopilotModels.get( |
| 71 | base(auth.enterpriseUrl), |
| 72 | { |
| 73 | ...(provider.options?.headers as Record<string, string> | undefined), |
| 74 | Authorization: `Bearer ${auth.refresh}`, |
| 75 | "User-Agent": `opencode/${InstallationVersion}`, |
| 76 | "X-GitHub-Api-Version": API_VERSION, |
| 77 | }, |
| 78 | provider.models, |
| 79 | ) |
| 80 | .then((result) => { |
| 81 | models = result.models |
| 82 | return Object.fromEntries( |
| 83 | Object.entries(result.models).filter(([, model]) => result.pickerEnabled.has(model.api.id)), |
| 84 | ) |
| 85 | }) |
| 86 | .catch((error) => { |
| 87 | models = {} |
| 88 | return Object.fromEntries( |
| 89 | Object.entries(provider.models).map(([id, model]) => [id, fix(model, base(auth.enterpriseUrl))]), |
| 90 | ) |
| 91 | }) |
| 92 | }, |
| 93 | }, |
| 94 | auth: { |
| 95 | provider: "github-copilot", |