Revert: all refactor commits migrating from Bun.file() to Filesystem module

This commit is contained in:
Dax Raad
2026-02-18 19:41:14 -05:00
parent 3a07dd8d96
commit 568eccb4c6
25 changed files with 216 additions and 294 deletions

View File

@@ -5,7 +5,6 @@ import z from "zod"
import { Installation } from "../installation"
import { Flag } from "../flag/flag"
import { lazy } from "@/util/lazy"
import { Filesystem } from "../util/filesystem"
// Try to import bundled snapshot (generated at build time)
// Falls back to undefined in dev mode when snapshot doesn't exist
@@ -86,7 +85,8 @@ export namespace ModelsDev {
}
export const Data = lazy(async () => {
const result = await Filesystem.readJson(Flag.OPENCODE_MODELS_PATH ?? filepath).catch(() => {})
const file = Bun.file(Flag.OPENCODE_MODELS_PATH ?? filepath)
const result = await file.json().catch(() => {})
if (result) return result
// @ts-ignore
const snapshot = await import("./models-snapshot")
@@ -104,6 +104,7 @@ export namespace ModelsDev {
}
export async function refresh() {
const file = Bun.file(filepath)
const result = await fetch(`${url()}/api.json`, {
headers: {
"User-Agent": Installation.USER_AGENT,
@@ -115,7 +116,7 @@ export namespace ModelsDev {
})
})
if (result && result.ok) {
await Filesystem.write(filepath, await result.text())
await Bun.write(file, await result.text())
ModelsDev.Data.reset()
}
}

View File

@@ -16,7 +16,6 @@ import { Flag } from "../flag/flag"
import { iife } from "@/util/iife"
import { Global } from "../global"
import path from "path"
import { Filesystem } from "../util/filesystem"
// Direct imports for bundled providers
import { createAmazonBedrock, type AmazonBedrockProviderSettings } from "@ai-sdk/amazon-bedrock"
@@ -1292,9 +1291,8 @@ export namespace Provider {
if (cfg.model) return parseModel(cfg.model)
const providers = await list()
const recent = (await Filesystem.readJson<{ recent?: { providerID: string; modelID: string }[] }>(
path.join(Global.Path.state, "model.json"),
)
const recent = (await Bun.file(path.join(Global.Path.state, "model.json"))
.json()
.then((x) => (Array.isArray(x.recent) ? x.recent : []))
.catch(() => [])) as { providerID: string; modelID: string }[]
for (const entry of recent) {