Просмотр исходного кода

core: fix custom tool loading to properly resolve module paths

Dax Raad 1 месяц назад
Родитель
Сommit
3c2fda4d91
1 измененных файлов с 4 добавлено и 1 удалено
  1. 4 1
      packages/opencode/src/tool/registry.ts

+ 4 - 1
packages/opencode/src/tool/registry.ts

@@ -30,6 +30,7 @@ import { Truncate } from "./truncation"
 import { ApplyPatchTool } from "./apply_patch"
 import { Glob } from "../util/glob"
 import { pathToFileURL } from "url"
+import { createRequire } from "module"
 
 export namespace ToolRegistry {
   const log = Log.create({ service: "tool.registry" })
@@ -45,7 +46,9 @@ export namespace ToolRegistry {
     if (matches.length) await Config.waitForDependencies()
     for (const match of matches) {
       const namespace = path.basename(match, path.extname(match))
-      const mod = await import(pathToFileURL(match).href)
+      const require = createRequire(match)
+      const resolved = require.resolve(match)
+      const mod = await import(pathToFileURL(resolved).href)
       for (const [id, def] of Object.entries<ToolDefinition>(mod)) {
         custom.push(fromPlugin(id === "default" ? namespace : `${namespace}_${id}`, def))
       }