feat(react-ui): allow rich content components in StepsItem details#759
Open
Shinyaigeek wants to merge 1 commit into
Open
feat(react-ui): allow rich content components in StepsItem details#759Shinyaigeek wants to merge 1 commit into
Shinyaigeek wants to merge 1 commit into
Conversation
StepsItem's details prop was typed z.string() in the genui schema, so LLMs could only express procedural steps as a single markdown string — no CodeBlock, Image, or other content components, even though the runtime and the React component layer (details: React.ReactNode) already handle them. Widen the schema to z.union([z.string(), z.array(StepsItemDetailsChildUnion)]) where the new union allows TextContent, MarkDownRenderer, CodeBlock, Image, and ImageBlock. The union is intentionally narrower than SectionContentChildUnion: procedural steps need prose, code, and images, and referencing Steps from its own item schema would be circular. String details keep rendering through MarkDownRenderer, so existing programs are unaffected; the renderer's existing renderNode branch already renders element arrays. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Motivation
StepsItem'sdetailsprop isz.string()in the genui schema, which means an LLM can only express a step's body as one markdown string. Procedural content — installation guides, usage instructions — often needs realCodeBlock,Image, orMarkDownRenderercomponents alongside prose (as requested in user feedback asking fordetailsto accept rich content similar toSectionItem'scontent).Notably, only the schema blocks this: the React component layer already types
details: React.ReactNode, and the genui renderer already has a non-string branch that rendersdetailsthroughrenderNode:openui/packages/react-ui/src/genui-lib/Steps/index.tsx
Lines 30 to 36 in 69c8aae
With
details: z.string(), therenderNode(details)arm was unreachable dead code — the receiving side existed, only the schema kept the door shut.Change
detailsbecomesz.union([z.string(), z.array(StepsItemDetailsChildUnion)])StepsItemDetailsChildUnion=TextContent | MarkDownRenderer | CodeBlock | Image | ImageBlock. Kept intentionally narrower thanSectionContentChildUnion: procedural steps need prose/code/images, referencingStepsfrom its own item schema would be circular, and a small union keeps the prompt signature compact. The exact set of components that should qualify as rich content is open to discussion — I kept it to prose, code, and images, but happy to adjust.ReactElement→ReactNode) and a description update; the existingrenderNodebranch handles arrays as-is.The prompt signature the LLM sees changes from
to
Screenshots
Live Vite harness rendering
openuiLibrary. Each page shows the prompt signature fromopenuiLibrary.toSpec()at the top, panel A with string details, and panel B with component details.Before
details: string— panel B's program renders only because the runtime never validated children against the schema; the LLM never sees this form.After
The signature advertises the union, and panel B exercises all five members in one
Steps:TextContent(steps 1, 3),MarkDownRendererwithcardvariant (step 2),CodeBlock(steps 1–3),Image(step 3 diagram),ImageBlock(step 4).Backward compatibility
String
detailsstill renders throughMarkDownRenderer, so existing programs and prompts are unaffected.Verification
openuiLibrary: string details (unchanged) and an example exercising all five union members inside oneStepsopenuiLibrary.toSpec()signature updated as above;toJSONSchema()expands toanyOf: [{type: "string"}, {items: {anyOf: [$ref …]}}]with correct$defsrefsreact-uivitest: 6 passed;lang-corevitest: 76 passedtsc --noEmiterror count identical before/after the change (pre-existing react-headless d.ts drift only)🤖 Generated with Claude Code