Browse Source

Refactor AI SDK provider loading to use BunProc.install

Simplifies provider installation by using BunProc.install() instead of manual path construction and file system checks.

🤖 Generated with [OpenCode](https://opencode.ai)

Co-Authored-By: OpenCode <[email protected]>
Dax Raad 8 months ago
parent
commit
f03637b1fc
1 changed files with 2 additions and 14 deletions
  1. 2 14
      packages/opencode/src/provider/provider.ts

+ 2 - 14
packages/opencode/src/provider/provider.ts

@@ -181,21 +181,9 @@ export namespace Provider {
       const s = await state()
       const existing = s.sdk.get(providerID)
       if (existing) return existing
-      const dir = path.join(
-        Global.Path.cache,
-        `node_modules`,
-        `@ai-sdk`,
-        providerID,
+      const mod = await import(
+        await BunProc.install(`@ai-sdk/${providerID}`, "alpha")
       )
-      if (!(await Bun.file(path.join(dir, "package.json")).exists())) {
-        log.info("installing", {
-          providerID,
-        })
-        await BunProc.run(["add", `@ai-sdk/${providerID}@alpha`], {
-          cwd: Global.Path.cache,
-        })
-      }
-      const mod = await import(path.join(dir))
       const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
       const loaded = fn(s.providers[providerID]?.options)
       s.sdk.set(providerID, loaded)