Skip to content

Commit 7b3bb9a

Browse files
jquensejquenserekram1-node
authored
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>
1 parent dc38f22 commit 7b3bb9a

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

packages/opencode/src/tool/registry.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,17 @@ export const layer: Layer.Layer<
135135
worktree: ctx.worktree,
136136
}
137137
const result = yield* Effect.promise(() => def.execute(args as any, pluginCtx))
138+
const output = typeof result === "string" ? result : result.output
139+
const metadata = typeof result === "string" ? {} : (result.metadata ?? {})
138140
const info = yield* agent.get(toolCtx.agent)
139-
const out = yield* truncate.output(result, {}, info)
141+
const out = yield* truncate.output(output, {}, info)
140142
return {
141143
title: "",
142-
output: out.truncated ? out.content : result,
144+
output: out.truncated ? out.content : output,
143145
metadata: {
146+
...metadata,
144147
truncated: out.truncated,
145-
outputPath: out.truncated ? out.outputPath : undefined,
148+
...(out.truncated && { outputPath: out.outputPath }),
146149
},
147150
}
148151
}),

packages/plugin/src/tool.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ type AskInput = {
2727
metadata: { [key: string]: any }
2828
}
2929

30+
export type ToolResult = string | { output: string; metadata?: { [key: string]: any } }
31+
3032
export function tool<Args extends z.ZodRawShape>(input: {
3133
description: string
3234
args: Args
33-
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>
35+
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<ToolResult>
3436
}) {
3537
return input
3638
}

0 commit comments

Comments
 (0)