Repository navigation
Conversation
…-prop
Hosts can now pass a typed payload to AIChat/AIMessageDisplay as { type: 'custom', data } and render it through renderCustomContent(data, ctx), instead of encoding structured data into a sentinel-prefixed text block and decoding it in renderTextContent. Custom blocks render without the prose wrapper and render nothing when no renderer is passed. Text blocks never reach renderCustomContent.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deploying ui with
|
| Latest commit: |
94852d8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7b65e5b7.ui-6d0.pages.dev |
| Branch Preview URL: | https://feat-ai-custom-content-block.ui-6d0.pages.dev |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The documentation omits which chat surfaces support custom widgets and how hosts should preserve widget state when new turns cause remounting.
2 open issues
What changed in this PR
Adds host-rendered custom content blocks to AI chat messages, letting applications pass structured widget data directly instead of encoding it as text.
Changes:
- Adds the
customblock type andrenderCustomContentcallback toAIChatandAIMessageDisplay. - Renders custom widgets without a prose wrapper; blocks without a renderer produce no output.
- Documents the extension point and adds a Storybook example and focused unit tests.
| File | Description |
|---|---|
src/components/AI/types.ts |
Defines custom block payloads and the renderer callback type. |
src/components/AI/MAINTAINERS.md |
Documents the extension point and updates the block-type inventory. |
src/components/AI/AIMessage.tsx |
Invokes and forwards the custom renderer through message content. |
src/components/AI/AIMessage.test.tsx |
Tests callback context, wrapper behavior, missing renderers, and text isolation. |
src/components/AI/AIMessage.stories.tsx |
Documents custom blocks and demonstrates a structured-data widget. |
src/components/AI/AIChat.tsx |
Exposes the callback and forwards it to every message. |
src/components/AI/AIChat.stories.tsx |
Adds consumer-facing documentation for the new prop. |
Review effort: Balanced
…ets remount between turns Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.

Closes #760
Lets a host pass a typed object to
AIChat/AIMessageDisplayand render it itself, instead of encoding structured data into atextblock.Requested in review of mieweb/ozwell-workspace#521 (comment).
What & why
Ozwell shows a speaker-labelled recording with
TranscriptPlayer. The only way to put a host widget inside a message today isrenderTextContent, so the app JSON-encodes the transcript data behind a sentinel prefix, sends it as atextblock, and decodes it again inrenderTextContent. That round trip is fragile, and it means every text block, including what a user types, is checked for the marker.This PR adds a small, generic hook that follows the existing
renderTextContent/renderMessageFooterpattern:types.ts'custom'block type,data?: unknown, andAIRenderCustomContent = (data, ctx) => ReactNode(reusesAITextRenderContext).AIMessage.tsxContentBlockcallsrenderCustomContent(data, ctx)forcustomblocks, without theprosewrapper (widgets aren't prose). Threaded throughMessageContentBlocks/AIMessageDisplay.AIChat.tsxrenderCustomContentprop, passed to every message.AIChatModal/FloatingAIChatalready spread props.AIMessage/AIChatstory descriptions and argTypes, aWithCustomContentBlockstory, and aMAINTAINERS.mdnote. TheAIChatLimitations list which surfaces support custom blocks and that widgets remount when a new turn starts.Behaviour:
datais opaque to the library; hosts use their own discriminator (e.g.data.kind).renderCustomContent→ acustomblock renders nothing (same as any unknown block today).renderCustomContent.SuperChatrendersAIMessageContentitself and ignores unknown types, so it is unaffected.OzwellChatdoes not forward the new prop (no consumer needs it yet).Tests
New
AIMessageDisplay custom blocktests inAIMessage.test.tsx:renderCustomContentreceivesdataand{ messageId, streaming, role }, and its output is mounted outside.prose.customblock without a renderer renders nothing.textblock containing the old sentinel-encoded payload renders as plain text and never reachesrenderCustomContent.Checklist
pnpm typecheck && pnpm lint && pnpm format && pnpm testpass (190 files, 2724 tests)RTL
pnpm rtl:scanpasses