Sfoglia il codice sorgente

feat(hook): add tool.definition hook for plugins to modify tool description and parameters (#4956)

Spoon 6 mesi fa
parent
commit
1608565c80
2 ha cambiato i file con 13 aggiunte e 1 eliminazioni
  1. 9 1
      packages/opencode/src/tool/registry.ts
  2. 4 0
      packages/plugin/src/index.ts

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

@@ -149,9 +149,17 @@ export namespace ToolRegistry {
         })
         .map(async (t) => {
           using _ = log.time(t.id)
+          const tool = await t.init({ agent })
+          const output = {
+            description: tool.description,
+            parameters: tool.parameters,
+          }
+          await Plugin.trigger("tool.definition", { toolID: t.id }, output)
           return {
             id: t.id,
-            ...(await t.init({ agent })),
+            ...tool,
+            description: output.description,
+            parameters: output.parameters,
           }
         }),
     )

+ 4 - 0
packages/plugin/src/index.ts

@@ -224,4 +224,8 @@ export interface Hooks {
     input: { sessionID: string; messageID: string; partID: string },
     output: { text: string },
   ) => Promise<void>
+  /**
+   * Modify tool definitions (description and parameters) sent to LLM
+   */
+  "tool.definition"?: (input: { toolID: string }, output: { description: string; parameters: any }) => Promise<void>
 }