feat: forward tool results to consumers (phase:"result") — v0.14.0 - #42
Merged
Conversation
The streaming chat() generator only recognized the older tool-result event shape (stream:"tool", phase:"end", data.output), which the current OpenClaw Gateway does not send — it emits phase:"result" with the tool in `name` and the payload in `result` (a toTranscriptToolResult object). The result: no tool_result chunk was ever produced, and all tool output was invisible to consumers. Handle both shapes, read the tool name from `name` (fallback `tool`), and set the chunk text to the tool's actual text output (content[].text joined) rather than a JSON-escaped envelope — so a structured marker a plugin writes into its output survives with literal quotes. Adds an exported toolResultText() helper. Unblocks Pinchy's agent→user file delivery (heypinchy/pinchy#703), which needs to observe a delivery marker in a plugin's tool output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The streaming
chat()generator only recognized the older tool-result event shape (stream:"tool",phase:"end",data.output). The current OpenClaw Gateway does not send that — it emitsphase:"result"with the tool innameand the payload inresult(atoTranscriptToolResultobject). So notool_resultchunk was ever produced, and all tool output was invisible to consumers.This surfaced building Pinchy's agent → user file delivery (heypinchy/pinchy#703): a plugin writes a delivery marker into its tool output, but the marker never reached the web layer because the
tool_resultchunk didn't exist.Change
phase:"end"(legacyoutput) andphase:"result"(currentresult).name, falling back to the legacytoolfield.content[].textitems oftoTranscriptToolResultjoined with newlines — via a new exportedtoolResultText()helper, rather than aJSON.stringifyenvelope. This preserves literal quotes so a structured marker (e.g.<pinchy:file name="…" />) survives to the consumer intact instead of being escaped (name=\"…\").Tests
TDD: a
chat.test.tsintegration test simulating the current Gateway'sphase:"result"tool event and asserting thetool_resultchunk carries the tool name + marker with literal quotes, plus focusedtoolResultTextunit tests (string / content-array / non-text items / fallback). Full suite green, typecheck/lint/format/build clean.Release
Minor bump
0.13.1 → 0.14.0(new exported helper + new observable streaming behavior; analogous to theagents.listminor in 0.12.0). CHANGELOG updated.