Angular bindings
Angular bindings for @dudko.dev/agent-web,
the in-browser LLM agent. One function, injectAgent: the agent’s chat state as Angular
signals, plus its methods - run, stop, steer, consent, questions - tied to your component’s
life.
It is headless: no component, no markup, no styles. You draw the chat your way. If you want the
whole chat ready-made, use <dd-agent-chat> instead.
It is thin. Everything the agent does in a view - building it, folding its events into state,
consent and question queues, steering, other tabs, usage - is
@dudko.dev/agent-web-ui’s
createAgentController. This package only makes its snapshot a signal and its life Angular’s.
The family
Section titled “The family”One planning loop: two agents, and the layers that put its chat on a page. Every package has its page at agent.dudko.dev/docs. The live demo and the app are built on them.
| Package | What it is |
|---|---|
@dudko.dev/agent |
The agent in Node: stdio and HTTP MCP servers, OAuth 2.1, a REPL CLI, persistence and resume |
@dudko.dev/agent-web |
The same agent in a browser tab, with no backend: your own key or a local WebGPU model |
@dudko.dev/agent-web-ui |
Its chat with no framework: the state, a controller, labels in 33 languages, Markdown |
@dudko.dev/agent-web-react |
React: the useAgent hook and a ready chat panel |
@dudko.dev/agent-web-element |
<dd-agent-chat>: the whole chat as a web component, for a page on any stack |
@dudko.dev/agent-web-vue |
Vue 3: the useAgent() composable |
@dudko.dev/agent-web-angular (this package) |
Angular: injectAgent(), the chat state as signals |
@dudko.dev/agent-web-svelte |
Svelte 4 and 5: createAgent(), the chat state as a store |
Install
Section titled “Install”npm install @dudko.dev/agent-web-angular @dudko.dev/agent-web# and the model providers you use, e.g.npm install @ai-sdk/google@angular/core17 or newer (signals) and@dudko.dev/agent-webare peers: your app’s own copies.@dudko.dev/agent-web-uicomes with it (a regular dependency, imported, not bundled).- Plain ESM / CJS. The package is a few plain functions over
@angular/core(inject,signal,computed,effect,DestroyRef). No decorator, no@Injectable, no component - so there is nothing for the Angular compiler to do. It was not built with ng-packagr and needs no partial compilation or linker. Any Angular build (the CLI’s esbuild or webpack builder, Vite, Analog) imports it like any other ESM package. - Zone-less friendly. The state is signals only. With
provideZonelessChangeDetection()the view updates when a signal changes; with zone.js it updates as usual.
import { Component } from '@angular/core'import { VaultCredentialStore } from '@dudko.dev/agent-web'import { injectAgent } from '@dudko.dev/agent-web-angular'
const credentials = new VaultCredentialStore() // keys encrypted at rest, in IndexedDB// once, e.g. from a settings form: await credentials.setApiKey('google', key)
@Component({ selector: 'app-assistant', standalone: true, template: ` @for (m of agent.messages(); track m.id) { <p [class]="m.role">{{ m.content }}@if (m.pending) { … }</p> }
@for (a of agent.pendingApprovals(); track a.id) { <div role="alertdialog"> Run <code>{{ a.name }}</code>? <button (click)="agent.approve(a.id)">Allow</button> <button (click)="agent.approve(a.id, { remember: true })">Always</button> <button (click)="agent.deny(a.id)">Deny</button> </div> }
@for (q of agent.pendingQuestions(); track q.id) { <fieldset> <legend>{{ q.question }}</legend> @for (o of q.options; track o.label) { <button (click)="agent.answerQuestion(q.id, { choice: [o.label] })">{{ o.label }}</button> } <button (click)="agent.answerQuestion(q.id, { declined: true })">Skip</button> </fieldset> }
<form (submit)="send($event, box)"> <input #box [disabled]="!agent.isReady() && !agent.isRunning()" /> @if (agent.isRunning()) { <button type="button" (click)="agent.stop()">Stop</button> } @else { <button [disabled]="!agent.isReady()">Send</button> } </form> <small>{{ agent.status() }} · {{ agent.state().totalUsage.totalTokens }} tokens</small> `,})export class AssistantComponent { readonly agent = injectAgent({ model: { providerType: 'google', model: 'gemini-3.5-flash', credentialRef: 'google' }, credentials, toolApproval: { mode: 'ask-writes' }, // a tool that writes waits in pendingApprovals() askUser: true, // the model may ask; its questions wait in pendingQuestions() })
send(event: Event, box: HTMLInputElement) { event.preventDefault() const text = box.value.trim() if (!text) return box.value = '' // While a run goes on, a message steers it (shown to the model at its next step); // otherwise it starts a new run. if (!this.agent.send(text)) void this.agent.run(text) }}injectAgent(config, options?)
Section titled “injectAgent(config, options?)”Call it in an injection context: a field initializer or the constructor of a component,
directive or service, or inside runInInjectionContext(injector, …). Elsewhere it throws
(NG0203), unless you pass options.injector.
config- the agent’sBrowserAgentConfig(@dudko.dev/agent-web), as a value or aSignal<BrowserAgentConfig>.options- the controller’s options (AgentControllerOptionsof@dudko.dev/agent-web-ui/controller), plusinjector:
| Option | Default | What it does |
|---|---|---|
injector |
the current injection context’s | The injector whose life the agent shares (its DestroyRef and PLATFORM_ID). Lets you call injectAgent outside an injection context. |
autoStart |
true |
Build the agent at once. false: wait for reload(). |
approvals |
true |
Route tool-consent requests into pendingApprovals (when the config has no toolApproval.onRequest of its own). |
questions |
true |
Route the model’s questions (askUser) into pendingQuestions (when the config has no onQuestion of its own). |
followUp |
true |
A message sent while the answer was being written, which the run never showed the model, is sent as the next message. |
watch |
true |
Follow this conversation’s run in another tab of the site (needs a shared memory, e.g. IndexedDBStore). |
maxEvents |
200 |
The raw event log’s cap (0: no cap). |
onEvent |
- | Called for every raw agent event, after the state took it. |
appToolGrants |
the page’s | Where “always allow” for MCP Apps’ tools is kept. |
What it returns (InjectedAgent)
Section titled “What it returns (InjectedAgent)”Signals (read-only):
| Signal | Type | |
|---|---|---|
state |
Signal<AgentControllerSnapshot> |
Everything: the AgentUiState (plan, steps, tool calls, subagents, the streamed answer, totalUsage, events, queued, undelivered, remote, …), isReady, isRunning, pendingApprovals, pendingQuestions, approvalMode, sessionId. |
isReady |
Signal<boolean> |
The agent is built and nothing runs (here, or for this conversation in another tab). |
isRunning |
Signal<boolean> |
A run goes on: this tab’s, or this conversation’s in another tab. |
status |
Signal<'idle' | 'initializing' | 'ready' | 'running' | 'error'> |
|
messages |
Signal<ChatMessage[]> |
The transcript: { id, role, content, pending, steps?, attachments?, … }. |
pendingApprovals |
Signal<ApprovalView[]> |
Tool calls waiting for consent: { id, name, input, readOnly, … }. |
pendingQuestions |
Signal<PendingQuestion[]> |
The model’s questions: { id, question, options, multiple, allowOther, expiresAt? }. |
approvalMode |
Signal<ToolApprovalMode> |
The consent policy in effect. |
agent |
Signal<Agent | undefined> |
The built agent, once ready. |
Methods - the controller’s own functions (they keep their identity; pass them around freely):
run(goal, { label?, images?, files?, attachments? }), stop(), send(text) (steer the run in
flight; false when none), approve(id, { remember? }), deny(id, reason?),
answerQuestion(id, answer) ({ choice: [label] }, { other: text }, { declined: true }),
setApprovalMode(mode), reset(), reload(), loadChat({ sessionId, messages?, totalUsage? }),
compact(), stopSubagent(id), forgetSkill(name), sendUndelivered(),
discardUndelivered(), sendRemote(text), stopRemote(), approveAppToolCall(call, signal?),
sampleForApp(request, approve, signal?). Each is documented on AgentControllerActions in
@dudko.dev/agent-web-ui.
controller - the AgentController underneath (undefined on the server), for anything the
signals do not cover. Do not dispose() it yourself: the injector does.
What is reactive, and how
Section titled “What is reactive, and how”stateis set from the controller’ssubscribe. The controller keeps the same snapshot object until something changes, and a signal skips a value it already holds - sostatechanges exactly when the agent’s state does, never with the same value twice.isReady,messages, … arecomputedoverstate. Each keeps its value while its part is the same object: a template that reads onlymessages()is not re-checked when the mode changes.- The write is
untracked, so a method called inside your owneffectupdates the signals on every supported Angular (17 included, where an effect may not write signals by default).
A config that changes
Section titled “A config that changes”Pass a Signal when the agent’s config changes over time - another model, a new API key:
readonly model = signal<'gemini-3.5-flash' | 'gemini-3.5-pro'>('gemini-3.5-flash')readonly config = computed(() => ({ model: { providerType: 'google', model: this.model(), credentialRef: 'google' }, credentials,}))readonly agent = injectAgent(this.config)- A new object from the signal rebuilds the agent. The transcript stays.
- The same object never rebuilds. A
computedgives a new object only when what it reads changed - keep it that way (do not build the config in a template or a getter). - It is applied by an
effect, so it happens when Angular runs effects (in change detection, or right after the signal changed when zone-less). - A plain value is read once. To rebuild with the same config, call
reload().
Lifecycle and teardown
Section titled “Lifecycle and teardown”- The controller is made at once, in
injectAgent- in the browser. The agent starts building then (unlessautoStart: false). - When the injector is destroyed - the component goes away, or the service’s injector - the controller is disposed: the run in flight is aborted, its consent requests are denied and its questions declined, the other-tab channels are closed, the timers cleared, the subscription dropped. The signals keep their last value; the methods do nothing from then on.
- In a service (
providedIn: 'root'), the agent lives as long as the application.
Server-side rendering
Section titled “Server-side rendering”On the server (PLATFORM_ID is not 'browser') no controller is made: no agent is built, no
model is called, no IndexedDB or BroadcastChannel is touched. The signals hold the initial
snapshot (status 'idle', no messages) and the methods do nothing (run resolves undefined,
send returns false). In the browser the controller is made as usual.
With hydration, the browser’s first value differs from the server’s ('initializing', not
'idle'). Keep markup that depends on the agent’s status out of the server render, e.g. in
@defer (on idle) { … }, or render it the same way for both.
The chat in 33 languages
Section titled “The chat in 33 languages”The chat’s strings, translated, come with @dudko.dev/agent-web-ui - one chunk per language,
loaded when asked for:
import { defaultLabels, mergeLabels, type AgentLabels } from '@dudko.dev/agent-web-ui'import { loadAgentLabels } from '@dudko.dev/agent-web-ui/locales'
readonly labels = signal<AgentLabels>(defaultLabels)constructor() { loadAgentLabels(navigator.language).then((l) => this.labels.set(mergeLabels(defaultLabels, l)))}// template: <button>{{ labels().send }}</button>The languages and how a tag is matched:
@dudko.dev/agent-web-ui’s “In your language”.
Markdown
Section titled “Markdown”The model answers in Markdown. Never put it into [innerHTML]. @dudko.dev/agent-web-ui/markdown
parses it into a small tree that you draw as elements - raw HTML stays text, a link is only
http(s) or mailto, no picture is loaded:
import { Component, computed, input } from '@angular/core'import { NgTemplateOutlet } from '@angular/common'import { parseMarkdownCached } from '@dudko.dev/agent-web-ui/markdown'
@Component({ selector: 'app-md', standalone: true, imports: [NgTemplateOutlet], template: ` <ng-template #runs let-runs> @for (r of runs; track $index) { @switch (r.t) { @case ('text') { {{ r.v }} } @case ('br') { <br /> } @case ('code') { <code>{{ r.v }}</code> } @case ('strong') { <strong><ng-container *ngTemplateOutlet="runs; context: { $implicit: r.c }" /></strong> } @case ('em') { <em><ng-container *ngTemplateOutlet="runs; context: { $implicit: r.c }" /></em> } @case ('del') { <del><ng-container *ngTemplateOutlet="runs; context: { $implicit: r.c }" /></del> } @case ('link') { <a [href]="r.href" target="_blank" rel="noopener noreferrer"><ng-container *ngTemplateOutlet="runs; context: { $implicit: r.c }" /></a> } @case ('file') { <ng-container *ngTemplateOutlet="runs; context: { $implicit: r.c }" /> } } } </ng-template> @for (b of blocks(); track $index) { @switch (b.t) { @case ('p') { <p><ng-container *ngTemplateOutlet="runs; context: { $implicit: b.c }" /></p> } @case ('h') { <h4><ng-container *ngTemplateOutlet="runs; context: { $implicit: b.c }" /></h4> } @case ('code') { <pre><code>{{ b.v }}</code></pre> } @case ('hr') { <hr /> } @case ('list') { <ul> @for (i of b.items; track $index) { <li><ng-container *ngTemplateOutlet="runs; context: { $implicit: i.c }" /></li> } </ul> } } } `,})export class MarkdownComponent { readonly text = input.required<string>() readonly blocks = computed(() => parseMarkdownCached(this.text()))}Quotes, tables, nested lists and the parser for an answer still being written
(parseMarkdownStreaming) are in
@dudko.dev/agent-web-ui’s “Markdown”.
Need the whole chat?
Section titled “Need the whole chat?”Use @dudko.dev/agent-web-element:
the complete chat (transcript, Markdown, tool calls, consent, questions, saved chats, workspace,
MCP Apps, voice, 33 languages) as one standard web component. Angular renders it with
CUSTOM_ELEMENTS_SCHEMA:
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'import '@dudko.dev/agent-web-element'import { config } from './agent'
@Component({ selector: 'app-help', standalone: true, schemas: [CUSTOM_ELEMENTS_SCHEMA], template: `<dd-agent-chat [config]="config" lang="fr" (dd-agent-run-end)="onEnd($event)"></dd-agent-chat>`,})export class HelpComponent { config = config onEnd(e: Event) { console.log((e as CustomEvent).detail.result?.final) }}What it does not do
Section titled “What it does not do”- No components, no markup, no CSS. (
<dd-agent-chat>has them.) - No logic of its own. Whatever the agent does in a view is the controller’s, in
@dudko.dev/agent-web-ui; a fix there reaches React, the web component and this package alike. - No
Observables. Need one?toObservable(agent.state)from@angular/core/rxjs-interop.
License
Section titled “License”MIT © Siarhei Dudko
Ask about the agents
What you write goes to the project's server and an AI model. Answers can be wrong.
Loading the chat…