@json-render/chat
Chat SDK renderer. Turn JSON specs into Chat SDK cards, which each adapter posts in its native format: Block Kit on Slack, Adaptive Cards on Teams, and the card format of the other platforms.
Install
See the Chat SDK example for a playground that previews generated messages as Slack renders them.
schema
The chat element schema for specs. Use with defineCatalog from core.
The root element is a Card. Every component maps to a Chat SDK card element.
| Component | Chat SDK element |
|---|---|
Card | The card itself. An inner Card renders as a titled section, since cards cannot nest. |
Section | section |
Text | text, with markdown content |
Fields and Field | fields and field |
Table | table |
Chart | chart, as a pie, bar, line, or area chart |
Divider | divider |
Image | image |
Actions, Button, and LinkButton | actions, button, and link-button |
streamCard
Stream a model's spec into a chat message. streamCard posts the card once its root element exists, edits the message as elements arrive, and finishes with a validated card.
The target is any object with Chat SDK's post(card) method that returns a message with edit(card), such as a Thread or a Channel.
| Option | Description |
|---|---|
updateIntervalMs | Minimum time between message edits while the spec streams. Defaults to 500, the interval Chat SDK uses for streaming with post and edit. |
limits | Platform limits to enforce on the final card. See validation and limits. |
maxElements | Maximum number of elements and table rows the spec may expand to. See state and repeat. |
components | Component definitions. Defaults to the standard components. |
If the final spec is invalid, streamCard throws CardSpecError after the partial message is visible, so you can retry or edit the message.
toCard
Convert a complete spec to a CardElement. Post the result with thread.post(card).
toPartialCard(spec) returns a best-effort card for a spec that is still streaming. It keeps the elements whose props validate and returns null until the root Card exists.
State and repeat
Specs can read from spec.state. toCard resolves $state, $item, $index, and $template expressions, drops elements whose visible condition is false, and renders the children of an element with repeat once per item. A Table with repeat uses its rows as a template, with one copy per item. A Table whose rows resolve to objects matches each header to the key with the same name.
A Fields, Actions, or Section left without children, for example after a repeat over an empty array, is omitted, since platforms reject empty groups. A posted message has no inputs, so $bindState and $bindItem have no effect.
Expansion stops at maxElements, which defaults to 1000 elements and table rows, so nested repeats over state cannot grow without bound. toCard throws CardSpecError when a spec goes past it, and toPartialCard keeps what was expanded so far.
Validation and limits
toCard validates the props of every element against its component schema and checks the structure of the spec, for example that a component without slots has no children and that the root Card has a title, an image, or a child. It throws CardSpecError, whose issues array has one readable entry per problem. Send the issues back to the model to get a corrected spec.
Platforms cap what a message can hold, and Chat SDK adapters degrade content past those caps. For example, the Slack adapter turns a second table into a code block. Pass limits to reject the spec instead.
| Limit | Description |
|---|---|
tables | Tables per message |
charts | Charts per message |
fields | Fields per Fields element |
tableRows | Table rows, including the header |
tableColumns | Table columns |
chartTitle | Characters in a chart title |
chartLabel | Characters in a chart category, series, or segment label |
chartSeries | Series in a chart, or segments in a pie chart |
chartPoints | Categories in a bar, line, or area chart |