AI Chat examples
Compose the independent core pieces around your transport and presentation layer, then map validated application extensions to real Angular components.
Working chat demo
Type hi, choose one of twelve prompts grouped across Forms, Data, Navigation & layout, and Feedback, and watch real AG-UI events reduce into the normalized store. The assistant streams a correlated render_component tool lifecycle before an allowlisted TailNG datepicker, chart, validated TailNG preview into the transcript. Options include date controls, autocomplete, slider, charts, table, accordion, tabs, stepper, tags, and progress. Stop and retry a response or prepend a cursor-loaded history page. New content stays in view while you follow the conversation; scrolling up pauses that behavior and shows a Jump to latest control. The simulation is deterministic and runs entirely in this page.
AG-UI component assistant
- TailNG Assistant
Type “hi” to choose a TailNG component for me to render.
Safe component renderers
AG-UI carries the run, message, and tool lifecycle. Component choices are application-owned extension parts. Validate their version and payload at the boundary, then resolve only known IDs from a local registry. Never accept a selector, import path, Angular template, or HTML from an agent response.
Resolve an allowlisted component preview
import type { TngAiExtensionPart } from '@tailng-ui/ai';
type PreviewId =
| 'release-date'
| 'project-date-range'
| 'assignee-search'
| 'rollout-slider'
| 'monthly-installs'
| 'adoption-trend'
| 'team-table'
| 'release-faq'
| 'release-tabs'
| 'release-steps'
| 'release-status'
| 'release-progress';
function resolvePreview(part: TngAiExtensionPart): PreviewId | undefined {
if (part.name !== 'tailng.dev/component-preview') return undefined;
const value = part.value as Record<string, unknown>;
if (value?.version !== 1 || typeof value.previewId !== 'string') return undefined;
switch (value.previewId) {
case 'release-date':
case 'project-date-range':
case 'assignee-search':
case 'rollout-slider':
case 'monthly-installs':
case 'adoption-trend':
case 'team-table':
case 'release-faq':
case 'release-tabs':
case 'release-steps':
case 'release-status':
case 'release-progress':
return value.previewId;
default:
return undefined;
}
}Materialize a completed component tool call
import type { TngAiExtensionPart } from '@tailng-ui/ai';
const previewIds = new Set([
'release-date', 'project-date-range', 'assignee-search', 'rollout-slider',
'monthly-installs', 'adoption-trend', 'team-table', 'release-faq',
'release-tabs', 'release-steps', 'release-status', 'release-progress',
]);
function materializeCompletedTool(
tool: { name: string; status: string; input: { previewId?: unknown } },
): TngAiExtensionPart | undefined {
if (tool.name !== 'render_component' || tool.status !== 'complete') return undefined;
const previewId = tool.input.previewId;
if (typeof previewId !== 'string' || !previewIds.has(previewId)) return undefined;
return {
id: `preview-${previewId}`,
type: 'extension',
name: 'tailng.dev/component-preview',
value: { version: 1, previewId },
};
}Normalized store
Store each entity once and derive an ordered message projection only for the active thread.
Create and read a chat store
import { TngAiChatStore } from '@tailng-ui/ai';
const store = new TngAiChatStore();
store.upsertThread({ id: 'thread-7', title: 'Release review' });
store.upsertMessage({
id: 'message-1',
threadId: 'thread-7',
role: 'user',
status: 'complete',
parts: [{ id: 'part-1', type: 'text', format: 'plain', text: 'Is it ready?' }],
});
const visibleMessages = store.selectMessages('thread-7');Cursor history
Return messages oldest-to-newest within each page. The controller validates the page and prepends it without duplicating IDs.
Load older messages on demand
import { TngAiChatStore, TngAiHistoryController, type TngAiHistorySource } from '@tailng-ui/ai';
const source: TngAiHistorySource = {
async loadBefore({ threadId, cursor, limit, signal }) {
const url = new URL(`/api/threads/${threadId}/messages`, location.origin);
if (cursor) url.searchParams.set('before', cursor);
url.searchParams.set('limit', String(limit));
const response = await fetch(url, { signal });
if (!response.ok) throw new Error(`History failed: ${response.status}`);
return response.json();
},
};
const history = new TngAiHistoryController(new TngAiChatStore(), source, {
pageSize: 40,
maxPageSize: 100,
});
await history.loadBefore('thread-7');AG-UI streaming
Pass decoded transport events to one reducer. Read the store after applied events and schedule rendering at most once per animation frame.
Reduce AG-UI events
import type { Event } from '@ag-ui/core';
import { TngAiChatStore } from '@tailng-ui/ai';
import { TngAgUiReducer } from '@tailng-ui/ai/ag-ui';
const store = new TngAiChatStore();
const reducer = new TngAgUiReducer(store, { profile: 'required-chat' });
function onAgentEvent(event: Event): void {
const result = reducer.reduce(event);
if (!result.applied) {
console.warn('Rejected AG-UI event', result.diagnostic);
}
}Long-chat memory checklist
- Use cursor pagination instead of offset pagination or full-thread hydration.
- Virtualize transcript rows and overscan only a small screen-adjacent window.
- Batch token deltas before triggering Angular change detection.
- Move Markdown parsing, highlighting, and large attachment work off the hot render path.
- Evict inactive thread pages while retaining cursors, summaries, and unsent drafts.
- Abort history and streaming work when a thread is closed or replaced.