@vettvangur/ai-sdk
v0.1.13
Published
Framework-agnostic AI chat client for server-rendered shells
Maintainers
Keywords
Readme
@vettvangur/ai-sdk
Framework-agnostic, unstyled AI chat primitives for server-rendered shells.
It exports protocol-v1 contracts, parsing and SSE stream-reading primitives, a headless chat session, and a DOM binding for a server-rendered shell. It does not include styles or project-specific tools.
<section data-ai-chat data-ai-chat-endpoint="/webapi/aichat/stream"
data-ai-chat-antiforgery-header="RequestVerificationToken" data-ai-chat-antiforgery-token="…">
<div data-ai-chat-thread></div>
<form data-ai-chat-form><textarea data-ai-chat-input></textarea><button data-ai-chat-send>Send</button></form>
<button type="button" data-ai-chat-reset>Reset</button>
</section>import { bindChat, createAiChatRegistry } from '@vettvangur/ai-sdk'
const registry = createAiChatRegistry()
registry.registerRenderer('weather', ({ document, data }) => {
const card = document.createElement('article')
card.textContent = String((data as { temperature?: unknown }).temperature ?? '')
return card
})
const chat = bindChat(document.querySelector('[data-ai-chat]')!, { registry })
// Call chat.destroy() when its server-rendered shell is removed.createChatSession() is available when a host owns its own rendering. It sends JSON POST requests
to the configured same-origin endpoint and reads its SSE response. Supply the antiforgery header
through bindChat options or the root attributes; blank header names or tokens are omitted.
tool_result payloads may select only registered tool renderers, an authored
template[data-template], or an authored template[data-ai-surface]. Named actions come only
from authored data-ai-action markup and receive an optional authored data-ai-action-value.
Neither server payloads nor model output become executable markup. Generic answer cards, links and
Markdown are rendered as safe DOM nodes. Host callbacks must return DOM nodes, not HTML strings.
The package accepts protocol-v1 events (delta, tool, tool_result, tool_done, done, and
error). Host-specific card rendering, embedded-component activation and styling remain host
responsibilities. Eimskip migration is deliberately outside this package.
