@@ -27,11 +27,12 @@ function base(enterpriseUrl?: string) {
2727 return enterpriseUrl ? `https://copilot-api.${ normalizeDomain ( enterpriseUrl ) } ` : "https://api.githubcopilot.com"
2828}
2929
30- function fix ( model : Model ) : Model {
30+ function fix ( model : Model , url : string ) : Model {
3131 return {
3232 ...model ,
3333 api : {
3434 ...model . api ,
35+ url,
3536 npm : "@ai-sdk/github-copilot" ,
3637 } ,
3738 }
@@ -44,19 +45,23 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
4445 id : "github-copilot" ,
4546 async models ( provider , ctx ) {
4647 if ( ctx . auth ?. type !== "oauth" ) {
47- return Object . fromEntries ( Object . entries ( provider . models ) . map ( ( [ id , model ] ) => [ id , fix ( model ) ] ) )
48+ return Object . fromEntries ( Object . entries ( provider . models ) . map ( ( [ id , model ] ) => [ id , fix ( model , base ( ) ) ] ) )
4849 }
4950
51+ const auth = ctx . auth
52+
5053 return CopilotModels . get (
51- base ( ctx . auth . enterpriseUrl ) ,
54+ base ( auth . enterpriseUrl ) ,
5255 {
53- Authorization : `Bearer ${ ctx . auth . refresh } ` ,
56+ Authorization : `Bearer ${ auth . refresh } ` ,
5457 "User-Agent" : `opencode/${ Installation . VERSION } ` ,
5558 } ,
5659 provider . models ,
5760 ) . catch ( ( error ) => {
5861 log . error ( "failed to fetch copilot models" , { error } )
59- return Object . fromEntries ( Object . entries ( provider . models ) . map ( ( [ id , model ] ) => [ id , fix ( model ) ] ) )
62+ return Object . fromEntries (
63+ Object . entries ( provider . models ) . map ( ( [ id , model ] ) => [ id , fix ( model , base ( auth . enterpriseUrl ) ) ] ) ,
64+ )
6065 } )
6166 } ,
6267 } ,
@@ -66,10 +71,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
6671 const info = await getAuth ( )
6772 if ( ! info || info . type !== "oauth" ) return { }
6873
69- const baseURL = base ( info . enterpriseUrl )
70-
7174 return {
72- baseURL,
7375 apiKey : "" ,
7476 async fetch ( request : RequestInfo | URL , init ?: RequestInit ) {
7577 const info = await getAuth ( )
0 commit comments