@@ -11,7 +11,7 @@ import path from "path"
1111import { CopilotModels } from "./models"
1212
1313const log = Log . create ( { service : "plugin.copilot" } )
14- const ttl = 5 * 60 * 1000
14+ const ttl = 60 * 60 * 1000
1515
1616function cachefile ( url : string ) {
1717 return path . join ( Global . Path . cache , `copilot-models-${ Hash . fast ( url ) } .json` )
@@ -67,15 +67,22 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
6767 "User-Agent" : `opencode/${ Installation . VERSION } ` ,
6868 }
6969
70- if ( ! fresh ( file ) ) {
71- CopilotModels . get ( url , headers , provider . models )
72- . then ( ( result ) => Filesystem . write ( file , JSON . stringify ( result ) ) )
73- . catch ( ( error ) => log . error ( "failed to fetch copilot models" , { error } ) )
70+ if ( fresh ( file ) ) {
71+ const cached = await Bun . file ( file )
72+ . json ( )
73+ . catch ( ( ) => undefined )
74+ if ( cached ) return cached as Record < string , Model >
7475 }
7576
76- const cached = await Filesystem . readJson < Record < string , Model > > ( file ) . catch ( ( ) => undefined )
77- if ( cached ) return cached
78- return Object . fromEntries ( Object . entries ( provider . models ) . map ( ( [ id , model ] ) => [ id , fix ( model ) ] ) )
77+ return CopilotModels . get ( url , headers , provider . models )
78+ . then ( async ( result ) => {
79+ await Bun . write ( file , JSON . stringify ( result ) )
80+ return result
81+ } )
82+ . catch ( ( error ) => {
83+ log . error ( "failed to fetch copilot models" , { error } )
84+ return Object . fromEntries ( Object . entries ( provider . models ) . map ( ( [ id , model ] ) => [ id , fix ( model ) ] ) )
85+ } )
7986 } ,
8087 } ,
8188 auth : {
0 commit comments