Vue 3 bindings
Vue 3 bindings for @dudko.dev/agent-web,
the in-browser LLM agent. One composable, useAgent(), gives you the agent as Vue state - the
transcript, the status, tool calls waiting for consent, the model’s questions - and the methods
to drive it: run, stop, approve, deny, answerQuestion and the rest. The agent lives as
long as your component (or effect scope) does.
It is headless and thin: no components, no styles, no logic of its own. Everything the agent
does in a view is
@dudko.dev/agent-web-ui’s controller
(createAgentController) - the same one React’s useAgent wraps. This package only turns it into
refs and ties it to Vue’s lifecycle.
Need the whole chat, ready-made? Use <dd-agent-chat> from
@dudko.dev/agent-web-element - the
full chat (Markdown answers, tool calls, consent prompts, saved chats, files, MCP Apps, 33
languages) as a web component that works in a Vue template:
<script setup lang="ts">import '@dudko.dev/agent-web-element'import { config } from './agent' // { model, credentials, tools, … }</script>
<template> <dd-agent-chat :config.prop="config" lang="de" /></template>(with isCustomElement: (tag) => tag === 'dd-agent-chat' in the Vue plugin’s
template.compilerOptions - see its README). Use this package when you draw the chat yourself.
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 (this package) |
Vue 3: the useAgent() composable |
@dudko.dev/agent-web-angular |
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 i @dudko.dev/agent-web-vue @dudko.dev/agent-web vue# and the provider(s) your config uses, e.g.npm i @ai-sdk/googlevue (3.4 or later) and @dudko.dev/agent-web (the core, one per page) are peer dependencies.
@dudko.dev/agent-web-ui comes with this package.
A chat in one component
Section titled “A chat in one component”<script setup lang="ts">import { ref } from 'vue'import { MemoryCredentialStore, type BrowserAgentConfig } from '@dudko.dev/agent-web'import { useAgent } from '@dudko.dev/agent-web-vue'
// A constant (or a shallowRef you replace): a NEW object builds a new agent.const config: BrowserAgentConfig = { model: { providerType: 'google', model: 'gemini-2.5-flash', credentialRef: 'google' }, credentials: new MemoryCredentialStore({ google: import.meta.env.VITE_GOOGLE_KEY }), toolApproval: { mode: 'ask-writes' }, // writes wait for approve / deny askUser: true, // the model may ask the person (pendingQuestions)}
const { status, isReady, isRunning, messages, pendingApprovals, pendingQuestions, run, stop, approve, deny, answerQuestion,} = useAgent(config)
const draft = ref('')const send = () => { const text = draft.value.trim() if (!text) return draft.value = '' void run(text)}</script>
<template> <p>{{ status }}</p>
<ul> <li v-for="m in messages" :key="m.id" :class="m.role"> {{ m.content }}<span v-if="m.pending">…</span> </li> </ul>
<div v-for="a in pendingApprovals" :key="a.id"> Allow <code>{{ a.name }}</code>? <button @click="approve(a.id)">Allow</button> <button @click="approve(a.id, { remember: true })">Always</button> <button @click="deny(a.id)">Deny</button> </div>
<div v-for="q in pendingQuestions" :key="q.id"> <p>{{ q.question }}</p> <button v-for="o in q.options" :key="o.label" @click="answerQuestion(q.id, { choice: [o.label] })"> {{ o.label }} </button> <button @click="answerQuestion(q.id, { declined: true })">Skip</button> </div>
<form @submit.prevent="send"> <input v-model="draft" aria-label="Message" /> <button v-if="isRunning" type="button" @click="stop">Stop</button> <button v-else :disabled="!isReady">Send</button> </form></template>Model text is text: render it with {{ }} (or the Markdown tree below), never v-html.
useAgent(config, options?)
Section titled “useAgent(config, options?)”Call it in a component’s setup / <script setup>, or inside an effectScope() (a store, a
composable of your own). Called anywhere else it throws: nothing would dispose the agent.
| Argument | Type | What it does |
|---|---|---|
config |
MaybeRefOrGetter<BrowserAgentConfig> |
The core’s createAgent config: a value, a Ref or a getter. A new object builds a new agent (the transcript stays); the same object never does, however often a getter re-runs. Keep it stable - a constant, a shallowRef you replace, a computed. It is given to the core raw (toRaw): a ref({...}) works too. |
options |
MaybeRefOrGetter<UseAgentOptions> |
The controller’s options: onEvent (every raw event), autoStart (default true; false waits for reload()), maxEvents, approvals, questions, followUp, watch, appToolGrants. A new value is handed over live, without a rebuild (a changed autoStart rebuilds). |
What it returns
Section titled “What it returns”State - all read-only, all reactive:
| Field | Type | What it is |
|---|---|---|
state |
Readonly<ShallowRef<AgentControllerSnapshot>> |
Everything: the AgentUiState (plan, steps and tool calls, messages, totalUsage, subagents, questions, writtenFiles, undelivered, queued, error, …) plus isRunning, isReady, pendingApprovals, pendingQuestions, approvalMode, sessionId. |
status |
ComputedRef<'idle' | 'initializing' | 'ready' | 'running' | 'error'> |
Where the agent is. |
isReady |
ComputedRef<boolean> |
Built, and nothing runs. |
isRunning |
ComputedRef<boolean> |
A run of this tab - or of this conversation in another tab - goes on. |
messages |
ComputedRef<ChatMessage[]> |
The transcript; an answer being written has pending: true and grows as it streams. |
pendingApprovals |
ComputedRef<ApprovalView[]> |
Tool calls waiting for consent (id, name, input, readOnly, …). |
pendingQuestions |
ComputedRef<PendingQuestion[]> |
The model’s questions (ask_user, with askUser on): id, question, options, multiple, allowOther, expiresAt. |
approvalMode |
ComputedRef<ToolApprovalMode> |
The consent policy in effect. |
agent |
Readonly<ShallowRef<Agent | undefined>> |
The built core agent, once ready. |
How it is reactive. The controller keeps one frozen snapshot and makes a new one on every
change; useAgent puts it into a shallowRef from the controller’s subscribe. Nothing is deep:
the snapshot is not wrapped in proxies, and a change that changes nothing makes no update. The
computed refs read the snapshot, so a template that shows isReady re-renders only when
isReady changes.
Methods - plain functions, the same for the component’s life (destructure them freely):
| Method | What it does |
|---|---|
run(goal, { label?, images?, files?, attachments? }) |
Run a goal; resolves with the core’s RunResult, or undefined when it could not start. |
stop() |
Abort this tab’s run. |
send(text) |
Say something to the running agent (it reads it at the next boundary); false when nothing runs. |
approve(id, { remember? }) / deny(id, reason?) |
Answer a consent request; remember allows the tool for the rest of the agent’s life. |
answerQuestion(id, answer) |
{ choice: [label] }, { other: text } (with allowOther) or { declined: true }; false when no such question waits. |
setApprovalMode(mode) |
Switch the consent policy live. |
reset() / reload() |
Clear the conversation (and the agent’s memory of it) / build the agent again (after a new key). |
loadChat({ sessionId, messages?, totalUsage? }) |
Switch to another conversation. |
sendUndelivered() / discardUndelivered() |
What a stopped run never showed the agent: send it now, or drop it. |
stopSubagent(id), forgetSkill(name), compact() |
Stop one helper; delete one of the agent’s lessons; summarise the stored transcript. |
sendRemote(text) / stopRemote() |
Reach this conversation’s run in another tab. |
approveAppToolCall(call, signal?), sampleForApp(…) |
For a host of MCP Apps: an app’s tool call through the agent’s consent, an app’s completion through the agent’s model. |
Each is documented in full on the controller’s types (AgentControllerActions, re-exported here).
Lifecycle
Section titled “Lifecycle”- Created in
onBeforeMountinside a component, at once inside aneffectScope. Until then - insetup, during a server render - the state iscreateInitialAgentSnapshot(config)(status'idle'), and the calls that change the view or the agent to come (loadChat,reset,reload,setApprovalMode,discardUndelivered) wait for it and reach it in order;runresolvesundefined. - Disposed in
onScopeDispose: the component unmounting, orscope.stop(). The run is aborted, its consent requests denied and questions declined, the other-tab channels closed; the state stays as it was and every method becomes a no-op.
Server rendering (Nuxt, Vite SSR)
Section titled “Server rendering (Nuxt, Vite SSR)”The agent is never created on the server. In a component that is Vue’s own contract: mount hooks
do not run there, so the server renders the initial snapshot (status: 'idle') and the browser
builds the agent after hydration. Outside a component (an effectScope, a Pinia setup store)
useAgent creates nothing where there is no window. If your store runs on both sides and you
would rather not call it on the server at all, guard it yourself:
if (!import.meta.env.SSR) useAgent(config) (Nuxt: import.meta.client). Keys belong in the
browser anyway: the core’s vault (VaultCredentialStore) lives there.
One agent for a subtree: provideAgent / injectAgent
Section titled “One agent for a subtree: provideAgent / injectAgent”A chat split into components (the transcript, the composer, the prompts) shares one agent:
// Chat.vue (the root)const agent = provideAgent(config, options) // = useAgent(...), provided to descendants
// Composer.vue (anywhere below)const { run, isReady } = injectAgent() // throws when no ancestor provided oneAGENT_KEY is the injection key, for your own provide / inject.
The chat in 33 languages
Section titled “The chat in 33 languages”The chat’s words in 33 languages are data in @dudko.dev/agent-web-ui/locales - each language a
chunk of its own, loaded on demand:
import { shallowRef } from 'vue'import { defaultLabels, mergeLabels } from '@dudko.dev/agent-web-ui'import { loadAgentLabels } from '@dudko.dev/agent-web-ui/locales'
const labels = shallowRef(defaultLabels)loadAgentLabels(navigator.language).then((l) => (labels.value = mergeLabels(defaultLabels, l)))// {{ labels.stop }}, {{ labels.approve }}, …Markdown answers
Section titled “Markdown answers”Answers are Markdown. @dudko.dev/agent-web-ui/markdown parses them into a safe tree (no HTML
from the model, only http(s) / mailto links), with a streaming parser for an answer still
being written. Draw the tree with h():
import { h, type VNode } from 'vue'import { parseMarkdownCached, type MarkdownBlock, type MarkdownInline } from '@dudko.dev/agent-web-ui/markdown'
const inline = (runs: MarkdownInline[]): (VNode | string)[] => runs.map((r) => { switch (r.t) { case 'text': return r.v case 'br': return h('br') case 'code': return h('code', r.v) case 'link': return h('a', { href: r.href, target: '_blank', rel: 'noreferrer noopener' }, inline(r.c)) case 'file': return h('span', inline(r.c)) default: return h({ strong: 'strong', em: 'em', del: 'del' }[r.t], inline(r.c)) } })const block = (b: MarkdownBlock): VNode => { switch (b.t) { case 'p': return h('p', inline(b.c)) case 'h': return h(`h${b.level}`, inline(b.c)) case 'code': return h('pre', h('code', b.v)) case 'quote': return h('blockquote', b.c.map(block)) case 'hr': return h('hr') case 'list': return h(b.ordered ? 'ol' : 'ul', b.items.map((i) => h('li', [...inline(i.c), i.sub && block(i.sub)]))) case 'table': return h('table', [ h('thead', h('tr', b.head.map((c) => h('th', inline(c))))), h('tbody', b.rows.map((row) => h('tr', row.map((c) => h('td', inline(c)))))), ]) }}export const Markdown = (props: { text: string }) => h('div', parseMarkdownCached(props.text).map(block))For a message still streaming (m.pending), parseMarkdownStreaming keeps what was drawn stable
as the rest arrives.
What this package does not do
Section titled “What this package does not do”- No components and no CSS (use
<dd-agent-chat>, or the ui package’sstyles.csswith your own markup). - No agent logic: building the agent, folding its events, consent, questions, other tabs - all of it is the ui package’s controller. A change there reaches React, the web component and Vue alike.
License
Section titled “License”MIT - see LICENSE. Part of the dudko-dev/agents monorepo.
Ask about the agents
What you write goes to the project's server and an AI model. Answers can be wrong.
Loading the chat…