Use case
Collaborative board
A sticky-note board you edit by hand or by voice. The AI adds, moves and removes notes while you talk.
Connect the assistant on the right to open the board.
Not connected.
What it does
- Board state lives in the agent and syncs over the data channel.
- The AI edits notes with tools, so voice and mouse changes show up together.
- Share a link to invite someone into the same board.
How it's built
This is the llm-board template. "Deploy this" creates a project with exactly these files, and you can edit them from there.
import { defineAgent, sendToClient } from "@voicethere/agent";
import {
createLlmAgent,
defineTool,
type CreateLlmAgentOptions,
} from "@voicethere/agent/llm";
import { openai } from "@voicethere/agent/llm/openai";
import config from "./voicethere.llm.json";
import systemPrompt from "./prompt.md";
import {
Board,
parseBoardMessage,
type BoardMessage,
type NoteColor,
} from "./board";
import { BOARD_TOOL_SPECS } from "./tool-specs";
// Boards are room-scoped. A client joins a room with { type: "board.join",
// room }; every session in the room sees the same board. A session that never
// joins has a private room of its own ("s:" + sessionId; clients cannot name
// it because room ids match /^[a-z0-9-]{6,40}$/). One agent process serves
// many sessions, so a single process-wide board would show visitors each
// other's notes. A room's board is deleted when its last session leaves.
const boards = new Map<string, Board>();
const roomOf = new Map<string, string>();
const members = new Map<string, Set<string>>();
// Ids of sessions that ended, newest last, capped. A tool call or data message
// that arrives after the session ended must not bring its private room back,
// or the board would leak for the life of the process.
const MAX_ENDED = 1000;
const ended = new Set<string>();
function markEnded(sessionId: string): void {
ended.delete(sessionId);
ended.add(sessionId);
if (ended.size > MAX_ENDED) {
const oldest = ended.values().next().value;
if (oldest !== undefined) ended.delete(oldest);
}
}
const SESSION_ENDED = "The session has ended.";
function roomFor(sessionId: string): string | null {
if (ended.has(sessionId)) return null;
let room = roomOf.get(sessionId);
if (!room) {
room = `s:${sessionId}`;
enter(sessionId, room);
}
return room;
}
function enter(sessionId: string, room: string): void {
roomOf.set(sessionId, room);
let set = members.get(room);
if (!set) {
set = new Set();
members.set(room, set);
}
set.add(sessionId);
}
function leave(sessionId: string): void {
const room = roomOf.get(sessionId);
if (!room) return;
roomOf.delete(sessionId);
const set = members.get(room);
set?.delete(sessionId);
if (!set || set.size === 0) {
members.delete(room);
boards.delete(room);
}
}
function boardFor(sessionId: string): Board | null {
const room = roomFor(sessionId);
if (!room) return null;
let board = boards.get(room);
if (!board) {
board = new Board();
boards.set(room, board);
}
return board;
}
/** Sends the room's board to every session in it. */
function broadcast(sessionId: string): void {
const room = roomFor(sessionId);
const board = boardFor(sessionId);
if (!room || !board) return;
const payload = { type: "board", notes: board.list() };
for (const member of members.get(room) ?? []) {
sendToClient(member, payload);
}
}
function apply(sessionId: string, m: BoardMessage): void {
if (ended.has(sessionId)) return;
const board = boardFor(sessionId);
if (!board) return;
switch (m.type) {
case "board.join": {
if (roomOf.get(sessionId) !== m.room) {
leave(sessionId);
enter(sessionId, m.room);
}
break;
}
case "note.add":
board.add({ ...m, author: "user" });
break;
case "note.update": {
const { type: _type, id, ...patch } = m;
board.update(id, patch);
break;
}
case "note.remove":
board.remove(m.id);
break;
case "board.sync":
// Only the requester gets the board.
sendToClient(sessionId, {
type: "board",
notes: board.list(),
});
return;
}
broadcast(sessionId);
}
const listNotes = defineTool({
...BOARD_TOOL_SPECS.list_notes,
handler: (_args, ctx) => {
const board = boardFor(ctx.sessionId);
if (!board) return SESSION_ENDED;
const notes = board.list();
if (notes.length === 0) return "The board is empty.";
return notes
.map((n) => `${n.id}: ${n.text} (${n.color}, ${n.author})`)
.join("\n");
},
});
const addNote = defineTool<{ text: string; color?: NoteColor }>({
...BOARD_TOOL_SPECS.add_note,
handler: ({ text, color }, ctx) => {
const board = boardFor(ctx.sessionId);
if (!board) return SESSION_ENDED;
const res = board.add({ text, color, author: "ai" });
if (!res.ok) return res.error;
broadcast(ctx.sessionId);
return `Added note ${res.value.id}.`;
},
});
const updateNote = defineTool<{
id: string;
text?: string;
color?: NoteColor;
x?: number;
y?: number;
}>({
...BOARD_TOOL_SPECS.update_note,
handler: ({ id, ...patch }, ctx) => {
const board = boardFor(ctx.sessionId);
if (!board) return SESSION_ENDED;
const res = board.update(id, patch);
if (!res.ok) return res.error;
broadcast(ctx.sessionId);
return `Updated note ${id}.`;
},
});
export const boardTools = [listNotes, addNote, updateNote];
export function createBoardAgent(over: Partial<CreateLlmAgentOptions> = {}) {
const llm = createLlmAgent({
config,
systemPrompt,
tools: boardTools,
providers: [openai],
...over,
});
return {
...llm,
onDataChannelMessage(
ctx: Parameters<NonNullable<typeof llm.onDataChannelMessage>>[0],
) {
const m = parseBoardMessage(ctx.message);
if (m) {
apply(ctx.sessionId, m);
return;
}
return llm.onDataChannelMessage?.(ctx);
},
onSessionStart(ctx: Parameters<NonNullable<typeof llm.onSessionStart>>[0]) {
ended.delete(ctx.sessionId);
return llm.onSessionStart?.(ctx);
},
onSessionEnd(ctx: { sessionId: string }) {
leave(ctx.sessionId);
markEnded(ctx.sessionId);
return llm.onSessionEnd?.(ctx);
},
};
}
defineAgent(createBoardAgent());
export const NOTE_COLORS = ["yellow", "blue", "green", "pink"] as const;
export type NoteColor = (typeof NOTE_COLORS)[number];
export const MAX_NOTES = 60;
/** Room ids a client may join. A session that never joins has a private room. */
export const ROOM_RE = /^[a-z0-9-]{6,40}$/;
export const MAX_NOTE_TEXT = 200;
export type Note = {
id: string;
/** 1 to 200 characters. */
text: string;
/** 0 to 1, left to right. */
x: number;
/** 0 to 1, top to bottom. */
y: number;
color: NoteColor;
author: "user" | "ai";
};
export type NotePatch = {
text?: string;
x?: number;
y?: number;
color?: NoteColor;
};
export type AddInput = {
text: string;
x?: number;
y?: number;
color?: NoteColor;
author: "user" | "ai";
};
/** Client to agent messages. Anything else is not a board message. */
export type BoardMessage =
| {
type: "note.add";
text: string;
x?: number;
y?: number;
color?: NoteColor;
}
| {
type: "note.update";
id: string;
text?: string;
x?: number;
y?: number;
color?: NoteColor;
}
| { type: "note.remove"; id: string }
| { type: "board.sync" }
| { type: "board.join"; room: string };
export type BoardResult<T> =
{ ok: true; value: T } | { ok: false; error: string };
function validText(v: unknown): v is string {
return typeof v === "string" && v.length >= 1 && v.length <= MAX_NOTE_TEXT;
}
function unit(v: unknown): v is number {
return typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 1;
}
function color(v: unknown): v is NoteColor {
return (
typeof v === "string" && (NOTE_COLORS as readonly string[]).includes(v)
);
}
/** A free spot on a 6 by 5 grid: the first cell no note sits on, else the first cell. */
export function freeSlot(notes: readonly Note[]): { x: number; y: number } {
const cols = 6;
const rows = 5;
for (let i = 0; i < cols * rows; i++) {
const x = (i % cols) / cols + 0.04;
const y = Math.floor(i / cols) / rows + 0.04;
const taken = notes.some(
(n) => Math.abs(n.x - x) < 0.01 && Math.abs(n.y - y) < 0.01,
);
if (!taken) return { x, y };
}
return { x: 0.04, y: 0.04 };
}
export class Board {
private notes = new Map<string, Note>();
private seq = 0;
add(input: AddInput): BoardResult<Note> {
if (!validText(input.text)) {
return {
ok: false,
error: `note text must be 1 to ${MAX_NOTE_TEXT} characters`,
};
}
if (this.notes.size >= MAX_NOTES)
return { ok: false, error: "board is full" };
if (input.x !== undefined && !unit(input.x))
return { ok: false, error: "x must be between 0 and 1" };
if (input.y !== undefined && !unit(input.y))
return { ok: false, error: "y must be between 0 and 1" };
if (input.color !== undefined && !color(input.color))
return { ok: false, error: "unknown color" };
const slot = freeSlot(this.list());
this.seq += 1;
const note: Note = {
id: `n${this.seq}`,
text: input.text,
x: input.x ?? slot.x,
y: input.y ?? slot.y,
color: input.color ?? "yellow",
author: input.author,
};
this.notes.set(note.id, note);
return { ok: true, value: note };
}
update(id: string, patch: NotePatch): BoardResult<Note> {
const note = this.notes.get(id);
if (!note) return { ok: false, error: `No note with id ${id}.` };
if (patch.text !== undefined && !validText(patch.text)) {
return {
ok: false,
error: `note text must be 1 to ${MAX_NOTE_TEXT} characters`,
};
}
if (patch.x !== undefined && !unit(patch.x))
return { ok: false, error: "x must be between 0 and 1" };
if (patch.y !== undefined && !unit(patch.y))
return { ok: false, error: "y must be between 0 and 1" };
if (patch.color !== undefined && !color(patch.color))
return { ok: false, error: "unknown color" };
const next: Note = {
...note,
...(patch.text !== undefined ? { text: patch.text } : {}),
...(patch.x !== undefined ? { x: patch.x } : {}),
...(patch.y !== undefined ? { y: patch.y } : {}),
...(patch.color !== undefined ? { color: patch.color } : {}),
};
this.notes.set(id, next);
return { ok: true, value: next };
}
remove(id: string): boolean {
return this.notes.delete(id);
}
list(): Note[] {
return [...this.notes.values()];
}
}
export function parseBoardMessage(msg: unknown): BoardMessage | null {
if (!msg || typeof msg !== "object") return null;
const m = msg as Record<string, unknown>;
switch (m.type) {
case "board.sync":
return { type: "board.sync" };
case "board.join":
return typeof m.room === "string" && ROOM_RE.test(m.room)
? { type: "board.join", room: m.room }
: null;
case "note.remove":
return typeof m.id === "string" && m.id
? { type: "note.remove", id: m.id }
: null;
case "note.add": {
if (typeof m.text !== "string") return null;
return {
type: "note.add",
text: m.text,
...(m.x !== undefined ? { x: m.x as number } : {}),
...(m.y !== undefined ? { y: m.y as number } : {}),
...(m.color !== undefined ? { color: m.color as NoteColor } : {}),
};
}
case "note.update": {
if (typeof m.id !== "string" || !m.id) return null;
return {
type: "note.update",
id: m.id,
...(m.text !== undefined ? { text: m.text as string } : {}),
...(m.x !== undefined ? { x: m.x as number } : {}),
...(m.y !== undefined ? { y: m.y as number } : {}),
...(m.color !== undefined ? { color: m.color as NoteColor } : {}),
};
}
default:
return null;
}
}
What it costs
9.8 credits per minute on VoiceThere, plus about $0.0011 per minute to the model vendor.
Measured on 2026-11-09 from a real demo session. See pricing.