@ai-gui/vanilla
v0.29.2
Published
Framework-free DOM adapter for AIGUI — stream LLM output straight into the DOM.
Downloads
6,293
Maintainers
Readme
@ai-gui/vanilla
Vanilla-DOM adapter for AIGUI — renders a streaming LLM response into a plain DOM element, no framework required.
Install
pnpm add @ai-gui/core @ai-gui/vanillaUsage
import { ActionRegistry, CardRegistry, CardStore, createActionRuntime } from "@ai-gui/core"
import { createRenderer } from "@ai-gui/vanilla"
const registry = new CardRegistry()
registry.register({
type: "weather",
description: "Weather summary",
// HTMLElement remains supported. Return a VanillaCardInstance for stateful cards.
render: (data: any, { state, onAction }: any) => {
const el = document.createElement("div")
el.textContent = `${data.city} — ${data.tempC}°C`
return {
element: el,
update(next: any, context: any) {
el.textContent = `${next.city} — ${next.tempC}°C (${context.state.status})`
},
destroy() {},
}
},
})
const actions = new ActionRegistry()
actions.register({ type: "refresh", run: async (params, { signal }) => fetch("/api/weather", { signal }) })
const cardStore = new CardStore({ registry })
const actionRuntime = createActionRuntime({ registry: actions, cardStore })
const r = createRenderer(document.getElementById("out")!, {
registry,
cardStore,
actionRuntime,
onCardAction: (action) => console.log("observed", action),
})
await r.feed(response.body!) // r.push(chunk) / r.reset() / r.destroy()Exports
createRenderer(el, { registry?, cardStore?, plugins?, sanitize?, rawHtml?, actionRuntime?, onCardAction?, onNodeClick? })→{ push, setText, feed, reset, destroy, setTheme, setPlugins, exportImages }.pluginsalso takes a loader —() => import("@ai-gui/plugin-mermaid").then(m => [m.mermaid()])— and the renderer reparses what it buffered when the chunk lands.onNodeClick(node, event)reports which parsed block a click landed in;event.targetis the exact element clicked inside it.
VanillaCardInstanceis{ element, update(data, { state, onAction }), destroy? }. Its host andelementstay mounted while AST data, store data, or action state changes.- Legacy factories returning an
HTMLElementremain supported. For cards with anidand acardStore, the adapter may rebuild that child element after store updates so it displays current data. - Cards with a valid top-level
idregister their initial data in the supplied externalCardStore. The adapter subscribes but never clears that store; a shared store updates every renderer displaying the same card id.
destroy() tears down the host and cleans up any mounted interactive widgets. See the root README for cards, plugins, and buildSystemPrompt.
