mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-12 14:53:25 +00:00
poll for models.dev changes
This commit is contained in:
parent
851e900982
commit
a0d2e53bde
1 changed files with 5 additions and 6 deletions
|
|
@ -50,18 +50,15 @@ export namespace ModelsDev {
|
|||
export type Provider = z.infer<typeof Provider>
|
||||
|
||||
export async function get() {
|
||||
refresh()
|
||||
const file = Bun.file(filepath)
|
||||
const result = await file.json().catch(() => {})
|
||||
if (result) {
|
||||
refresh()
|
||||
return result as Record<string, Provider>
|
||||
}
|
||||
refresh()
|
||||
if (result) return result as Record<string, Provider>
|
||||
const json = await data()
|
||||
return JSON.parse(json) as Record<string, Provider>
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
export async function refresh() {
|
||||
const file = Bun.file(filepath)
|
||||
log.info("refreshing")
|
||||
const result = await fetch("https://models.dev/api.json", {
|
||||
|
|
@ -72,3 +69,5 @@ export namespace ModelsDev {
|
|||
if (result && result.ok) await Bun.write(file, result)
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(() => ModelsDev.refresh(), 60 * 1000).unref()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue