createGenUITools returns a set of tool definitions the model can call to read and mutate a JSON UI spec.
Creates tools that operate on a spec with shape { root, elements }. Options:
| Option | Required | Description |
|---|---|---|
contextId | Yes | String key for the current conversation/context |
getSpec(contextId) | Yes | Return current spec or null |
updateSpec(contextId, spec) | Yes | Persist the updated spec |
toolWrapper(toolName, execute) | Yes | Wrapper for every tool execution (logging, error handling, telemetry) |
createId | No | Id factory for new nodes (default: generates UI-{timestamp}-{random}) |
rootId | No | Root node id (default: "root") |
nodeHints | No | Override component registry used in prompts |
nodeNamesThatSupportChildren | No | Override list of node types that can have children |
{ id, props, replace? }; default merge, use replace: true to replace all){ parentId?, type, props? }; omit parentId to use root)nodeId, offset; negative = earlier, positive = later; clamped to valid range)All mutations are serialized so concurrent tool calls do not interleave writes.
Builds the reusable system instructions for JSON UI tooling. Use as the system option for streamText / generateText.
Options:
| Option | Default | Description |
|---|---|---|
additionalInstructions | — | App-specific text appended to the prompt |
requireLayoutReadBeforeAddingNodes | true | Whether to instruct the model to read layout before adding nodes |
styleHints | — | Override style metadata used in the prompt text |
Example: