Uh oh!
There was an error while loading. Please reload this page.
feat(plugin): add ToolResult type for structured tool responses - #6544
feat(plugin): add ToolResult type for structured tool responses#6544aryasaatvik wants to merge 5 commits into
Conversation
aryasaatvik
commented
Jan 4, 2026
@rekram1-node can you take a look? |
0fa0047 to
d2ef4f0CompareThanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
- Add ToolResult interface to @opencode-ai/plugin
- Update execute signature to Promise<string | ToolResult>
- Enables plugin tools to return {title, metadata, output}- Add ToolResult interface to @opencode-ai/plugin for structured tool responses - Update execute signature to accept string | ToolResult - Add runtime detection in fromPlugin to preserve title and metadata - Extract Tool.Result interface for clarity in opencode package - Maintain backward compatibility with string-only results
c0c0acf to
f35c3daCompare## Problem
Plugin tools could only return a plain string. This prevented:
- Structured responses with titles, metadata, and attachments
- Real-time streaming updates during long-running operations
- Subagent result propagation (tool counts, progress, etc.)
## Solution
Add ToolResult interface and metadata() method to plugin SDK:
- ToolResult interface: { title, metadata, output, attachments? }
- ctx.metadata(): Emit streaming updates during execution
- Backward compatible: tools can still return plain strings
- Core extraction: Tool.Result interface for unified typing
## Changes
- packages/plugin/src/tool.ts - Add ToolResult interface, metadata() method
- packages/opencode/src/tool/tool.ts - Extract Tool.Result interface
- packages/opencode/src/tool/registry.ts - Handle structured results in fromPlugin
## Usage
```typescript
import { tool, type ToolResult } from "@opencode-ai/plugin"
export default tool({
description: "My tool",
args: { input: z.string() },
async execute(args, ctx): Promise<ToolResult> {
ctx.metadata({ title: "Processing...", metadata: { step: 1 } })
// ... work ...
return {
title: "Done",
metadata: { count: 42 },
output: "Result text"
}
}
})
```
## Related
- Resolvesanomalyco#7590
Patchwork-Source: fix/plugin-tool-metadata-persistence
Patchwork-PR: anomalyco#6544
Patchwork-Squashed: 2026-01-12T21:07:21.648ZSo I made a very similar PR here #12050 because I apparently suck at searching through GitHub issues and PRs. The only major difference is that I added a test to ensure it works as expected and added more of the missing fields to the If you want to keep the test and types, feel free to merge/copy them into this PR (and then I can close mine out). Obviously I'm a fan of your solution because we basically wrote the same thing 😆! |
f802701 to
f1ae801CompareClosing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Problem
Plugin tools could only return a plain string. This prevented:
Solution
Add ToolResult interface and metadata() method to plugin SDK:
Changes
Usage
Related