Browse Source

fix: preserve plugin tool metadata in execute result (#22827)

Co-authored-by: jquense <jquense@ramp.com>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Jason Quense 4 tháng trước cách đây
mục cha
commit
7b3bb9a761
2 tập tin đã thay đổi với 9 bổ sung4 xóa
  1. 6 3
      packages/opencode/src/tool/registry.ts
  2. 3 1
      packages/plugin/src/tool.ts

+ 6 - 3
packages/opencode/src/tool/registry.ts

@@ -135,14 +135,17 @@ export const layer: Layer.Layer<
                   worktree: ctx.worktree,
                 }
                 const result = yield* Effect.promise(() => def.execute(args as any, pluginCtx))
+                const output = typeof result === "string" ? result : result.output
+                const metadata = typeof result === "string" ? {} : (result.metadata ?? {})
                 const info = yield* agent.get(toolCtx.agent)
-                const out = yield* truncate.output(result, {}, info)
+                const out = yield* truncate.output(output, {}, info)
                 return {
                   title: "",
-                  output: out.truncated ? out.content : result,
+                  output: out.truncated ? out.content : output,
                   metadata: {
+                    ...metadata,
                     truncated: out.truncated,
-                    outputPath: out.truncated ? out.outputPath : undefined,
+                    ...(out.truncated && { outputPath: out.outputPath }),
                   },
                 }
               }),

+ 3 - 1
packages/plugin/src/tool.ts

@@ -27,10 +27,12 @@ type AskInput = {
   metadata: { [key: string]: any }
 }
 
+export type ToolResult = string | { output: string; metadata?: { [key: string]: any } }
+
 export function tool<Args extends z.ZodRawShape>(input: {
   description: string
   args: Args
-  execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>
+  execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<ToolResult>
 }) {
   return input
 }