STREAMVIZ DOCUMENTATION

API reference

Public React, core, and protocol exports for StreamViz 0.1.
Public API contract

Imports documented on this page are the supported package surface. Internal renderer and iframe-runtime modules are not public API.

Entry points

Entry pointPurpose
streamvizConvenience entry point that re-exports React, core, and protocol APIs.
streamviz-react/reactReact renderer and public renderer types.
streamviz-react/coreProvider-independent partial JSON recovery and tool-call normalization.
streamviz-react/protocolModel-facing tool names, prompt builders, metadata, and authoring types.
streamviz-react/styles.cssComplete host renderer stylesheet. Import once.

StreamVisualization

tsx
import { StreamVisualization } from 'streamviz-react/react'
import 'streamviz-react/styles.css'

StreamVisualization renders partial HTML in a sandboxed iframe and crosses the interaction boundary only when final becomes true. VisualizeWidgetFrame remains available as a compatibility alias.

NameTypeRequiredDefaultDescription
titlestringYesShort artifact title; also used to derive export filenames.
codestringYesCurrent HTML source. It may be incomplete while the tool call is streaming.
exportCodestringYesBest source available for HTML export. Usually the same value as code.
loadingMessagestringYesPrimary status shown before renderable content is available.
loadingMessagesstring[]NoOrdered progress messages recovered from the tool call.
finalbooleanYesEnables the final document, scripts, and artifact actions.
showActionsbooleanNotrueShows copy and export controls after completion.
onSendPrompt(prompt: string) => voidNoReceives follow-up prompts sent through the artifact bridge.
notify(message, variant) => voidNoConnects success and error notifications to the host UI.
renderIcon(name, options) => ReactNodeNoMaps renderer action names to host icons.
writeImageToClipboard(dataUrl) => Promise<boolean> | booleanNoOptional clipboard bridge for desktop shells and restricted origins.
themeStreamVisualizationThemeNoSelects light, dark, or system mode and optional semantic token overrides.
cssVarNamesreadonly string[]NoAdvanced allowlist of host CSS variables forwarded into the iframe.

Minimal example

tsx
<StreamVisualization
title="Revenue analysis"
code={streamedHtml}
exportCode={streamedHtml}
loadingMessage="Rendering analysis"
final={toolCall.status === 'done'}
/>

Core exports

ts
import {
extractPartialJsonString,
extractPartialJsonStringArray,
extractVisualizeWidgetPayload,
getCachedVisualizeWidgetHeight,
setCachedVisualizeWidgetHeight,
visualizeWidgetSourceKey,
} from 'streamviz-react/core'

extractVisualizeWidgetPayload(tool)

Normalizes running and completed tool-call shapes. It never executes artifact code and does not require the outer streaming JSON object to be complete.

ts
type VisualizeWidgetPayload = {
title: string
code: string
exportCode: string
loadingMessage: string
loadingMessages: string[]
final: boolean
status: string
}

extractPartialJsonString(raw, key)

Returns the currently recoverable JSON string value. Missing keys and non-string values return an empty string.

extractPartialJsonStringArray(raw, key)

Returns all complete, non-empty string items currently recoverable from a JSON array.

Height-cache helpers

visualizeWidgetSourceKey(value) creates a stable compact cache key. getCachedVisualizeWidgetHeight(key) returns a cached height or null; setCachedVisualizeWidgetHeight(key, value) stores a bounded positive height. Storage failures are ignored because this cache is only a rendering hint.

Protocol exports

ts
import {
VISUALIZE_TYPES,
VISUALIZE_READ_ME_TOOL_NAME,
VISUALIZE_SHOW_WIDGET_TOOL_NAME,
buildVisualizeSystemPrompt,
buildVisualizeReadMeOutput,
buildVisualizeWidgetMetadata,
} from 'streamviz-react/protocol'
NameTypeRequiredDefaultDescription
buildVisualizeSystemPrompt() => stringNoBuilds the model instruction that routes visual requests through the two-tool protocol.
buildVisualizeReadMeTitle(type) => stringNoBuilds the host-visible title for a loaded authoring module.
buildVisualizeReadMeOutput({ type, content }) => stringNoWraps packaged authoring rules for the model.
buildVisualizeReadMeMetadata({ type, source }) => objectNoBuilds stable metadata for the read-me tool result.
buildVisualizeShowWidgetOutput(title) => stringNoBuilds the short assistant-facing completion output.
buildVisualizeWidgetMetadata(input) => objectNoBuilds the final persisted widget metadata.

Supported VisualizeType values are diagram, chart, interactive, mockup, and art. Protocol exports do not depend on React and can run in a backend, CLI, or agent runtime.

PreviousHost API