fix(frontend): render plain-object tool results in beautified view#4401
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The beautified JSON view dropped tool-message parts that were plain
objects with no part `type`, for example an n8n tool result shaped like
{message, endpoints}. getMessagePartText matched no branch for them and
returned null, so the chat bubble rendered empty.
It now falls back to formatted JSON for typeless object parts, which
keeps the whole object visible. Typed media parts (image_url, file) are
still left to their own renderers, so they are not dumped as JSON. A
stringified tool result already parses through tryParseJsonString, so it
renders structured as well.
Also adds an RFC tracking the three tool-call round-trip issues, of which
this is the display-only one.
235dcb0 to
77ac31d
Compare
711af91 to
8c88386
Compare
23447af
into
feat/trace-overview-parameters
Summary
The beautified JSON view in the trace drawer rendered an empty bubble for some tool messages.
A
toolmessage often carries a structured result rather than a plain string. For example, an n8n tool returns[{ "message": "n8n Tool Webhook", "endpoints": {...} }]. The view turns message content into parts and asksgetMessagePartTextfor the text of each part. That function only understood a fixed set of shapes: text parts, the AI-SDKtool-callandtool-resultenvelopes, and objects with atextorcontentfield. A plain object like{message, endpoints}matched none of them, so the function returnednulland the part was dropped. The bubble showed nothing.The fix adds one gated fallback. When a part is an object that carries no part
type, we render the whole object as formatted JSON instead of dropping it, so the reader sees the full tool result. Typed media parts (image_url,file) still returnnulland continue to use their own renderers, so they are not dumped as raw JSON. A tool result that arrives as a JSON string already parses throughtryParseJsonString, so it now renders as structured text as well.This is the display-only piece of a larger set of tool-call issues. The branch also adds an RFC at
docs/designs/tool-call-roundtrip/rfc.mdthat documents all three problems we found (ingestion dropping LangChain tool calls, the playground load collapsing multi-assistant turns, and this rendering gap) so the remaining two are tracked.Testing
Verified locally
Ran ESLint with
--fixonBeautifiedJsonView.tsx. It passed with no errors. Traced the example tool content throughgetMessageContentDisplayandgetMessagePartTextby hand to confirm a{message, endpoints}part now returns formatted JSON instead ofnull.Added or updated tests
N/A. This is a small display fallback in a presentational helper. Open to adding a unit test for
getMessagePartTextif preferred.QA follow-up
Open a trace whose
toolmessage content is a structured object (for example an n8n tool result) in the trace drawer beautified view. Confirm the bubble now shows the full object. Spot-check that normal text messages, AI-SDK tool-call and tool-result envelopes, and image and file attachments still render exactly as before.Demo
UI change. A screen recording is still pending. I could not capture one in this environment, so this needs a screenshot or short video before merge.
Checklist