mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-02 23:23:45 +00:00
tweak: start bundling in some ai-sdk packages (#4649)
This commit is contained in:
@@ -4,10 +4,12 @@ import { Log } from "../util/log"
|
||||
import path from "path"
|
||||
import { NamedError } from "../util/error"
|
||||
import { readableStreamToText } from "bun"
|
||||
import { createRequire } from "module"
|
||||
import { Lock } from "../util/lock"
|
||||
|
||||
export namespace BunProc {
|
||||
const log = Log.create({ service: "bun" })
|
||||
const req = createRequire(import.meta.url)
|
||||
|
||||
export async function run(cmd: string[], options?: Bun.SpawnOptions.OptionsObject<any, any, any>) {
|
||||
log.info("running", {
|
||||
@@ -129,4 +131,22 @@ export namespace BunProc {
|
||||
await Bun.write(pkgjson.name!, JSON.stringify(parsed, null, 2))
|
||||
return mod
|
||||
}
|
||||
|
||||
export async function resolve(pkg: string) {
|
||||
const local = workspace(pkg)
|
||||
if (local) return local
|
||||
const dir = path.join(Global.Path.cache, "node_modules", pkg)
|
||||
const pkgjson = Bun.file(path.join(dir, "package.json"))
|
||||
const exists = await pkgjson.exists()
|
||||
if (exists) return dir
|
||||
}
|
||||
|
||||
function workspace(pkg: string) {
|
||||
try {
|
||||
const target = req.resolve(`${pkg}/package.json`)
|
||||
return path.dirname(target)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,13 +530,18 @@ export namespace Provider {
|
||||
const existing = s.sdk.get(key)
|
||||
if (existing) return existing
|
||||
|
||||
let installedPath: string
|
||||
if (!pkg.startsWith("file://")) {
|
||||
installedPath = await BunProc.install(pkg, "latest")
|
||||
} else {
|
||||
log.info("loading local provider", { pkg })
|
||||
installedPath = pkg
|
||||
}
|
||||
const installedPath = await (async () => {
|
||||
if (pkg.startsWith("file://")) {
|
||||
log.info("loading local provider", { pkg })
|
||||
return pkg
|
||||
}
|
||||
const resolved = await BunProc.resolve(pkg)
|
||||
if (resolved) {
|
||||
log.info("using preinstalled provider", { providerID: provider.id, pkg })
|
||||
return resolved
|
||||
}
|
||||
return BunProc.install(pkg, "latest")
|
||||
})()
|
||||
|
||||
// The `google-vertex-anthropic` provider points to the `@ai-sdk/google-vertex` package.
|
||||
// Ref: https://github.com/sst/models.dev/blob/0a87de42ab177bebad0620a889e2eb2b4a5dd4ab/providers/google-vertex-anthropic/provider.toml
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { iife } from "@/util/iife"
|
||||
import { MessageV2 } from "./message-v2"
|
||||
|
||||
export namespace SessionRetry {
|
||||
|
||||
Reference in New Issue
Block a user