AI Chat API
Public contracts exported from the core and AG-UI secondary entry points.
Chat component
Use tng-ai-chat for the standard controlled presentation and interaction layer.
| Name | Returns / kind | Purpose |
|---|---|---|
| TngAiChatComponent | component | Controlled professional chat shell with transcript, composer, run controls, history, auto-scroll, and bounded rendering. |
| headerComponent | Type<unknown> | null | Replaces the default header with a trusted local Angular component. |
| partRenderers | readonly TngAiMessagePartRenderer[] | Maps exact trusted part types or namespaced extension names to local components. |
| TNG_AI_CHAT_HEADER_CONTEXT | InjectionToken | Reactive title, status, identity, and busy context for a custom header. |
| TNG_AI_MESSAGE_PART_CONTEXT | InjectionToken | Reactive message, part, state, and typed action channel for a custom renderer. |
| provideTngAiMessagePartRenderer(renderer) | Provider | Registers a trusted feature- or application-scoped custom part component. |
Core types
Import these from @tailng-ui/ai.
| Name | Returns / kind | Purpose |
|---|---|---|
| TngAiThread | type | Conversation identity, timestamps, title, and JSON-safe metadata. |
| TngAiRun | type | Run identity, lifecycle status, error, usage, and metadata. |
| TngAiMessage | type | Canonical message envelope containing ordered message parts. |
| TngAiMessagePart | union | Text, reasoning, tool, file, source, data, activity, UI, extension, or unsupported content. |
| TngAiActionRequest | union | Submit, stop, retry, edit, feedback, approval, and history intents emitted by a UI. |
| TngAiPartRegistry<T> | class | Explicit registry for namespaced extension renderers. |
Chat store
TngAiChatStore keeps records normalized and ordered by thread.
| Name | Returns / kind | Purpose |
|---|---|---|
| snapshot() | TngAiChatStoreSnapshot | Returns normalized thread, run, message, and per-thread order maps. |
| upsertThread(thread) | void | Adds or replaces a thread record. |
| upsertRun(run) | void | Adds or replaces a run record. |
| upsertMessage(message, position?) | void | Adds or updates a message without duplicating identity. |
| selectMessages(threadId) | readonly TngAiMessage[] | Returns a cached ordered projection for one thread. |
| clearThread(threadId) | void | Clears the thread and its runs and messages. |
| dispose() | void | Clears all records and rejects later writes with a diagnostic. |
History controller
TngAiHistoryController coordinates bounded, cursor-based loading.
| Name | Returns / kind | Purpose |
|---|---|---|
| loadBefore(threadId, cursor?, limit?) | Promise<TngAiHistoryLoadResult> | Loads and prepends the previous cursor page. |
| retry(threadId) | Promise<TngAiHistoryLoadResult> | Retries the last request recorded for a thread. |
| state(threadId) | TngAiHistoryState | Reads loading, cursor, exhaustion, and error state. |
| activateThread(threadId) | void | Aborts history work belonging to inactive threads. |
| dispose() | void | Aborts all active requests. |
AG-UI adapter
Import these from @tailng-ui/ai/ag-ui. @ag-ui/core is an optional peer dependency.
| Name | Returns / kind | Purpose |
|---|---|---|
| validateTngAgUiEvent(value, options?) | TngAgUiValidationResult | Checks JSON limits, profile support, and the official AG-UI schema. |
| new TngAgUiReducer(store, options?) | TngAgUiReducer | Creates an AG-UI event reducer over a normalized chat store. |
| reducer.reduce(value) | TngAgUiReduceResult | Validates and applies one event or returns a diagnostic. |
| reducer.diagnostics() | readonly TngAgUiReducerDiagnostic[] | Returns bounded reducer diagnostics for observability. |