Chat With AI
A small Vite + React example for the ask-message flow: user sends a message, an agent worker replies, and every open tab sees updates live.
Source: examples/chat-with-ai/
There is no external AI API call — the agent returns a deterministic demo reply so you can run everything locally without API keys.
What it does
- The browser writes a user message into
chat_demo.messageswith the ORM chat_demo.ai_inboxreceives those inserts as a topicsrc/agent.tsrunsrunConsumer()from@kalamdb/consumer- The agent writes progress rows into
chat_demo.agent_events - The agent commits one assistant reply back into
chat_demo.messages - Every open browser tab sees the rows through live subscriptions
Prerequisites
- Node.js 18+
- KalamDB on port 2900
Quick start
Start KalamDB (Docker example):
From the example folder:
Run the agent worker in one terminal:
Run the browser app in another terminal:
Open the Vite URL (usually http://127.0.0.1:5173).
What to try
Type a short message such as:
You should see your user row, live agent progress, and then a final AI reply: row. Open a second browser tab to confirm live updates arrive there too.
The write path (browser)
The agent path (worker)
Setup creates the topic route:
Files worth reading
| File | Purpose |
|---|---|
src/App.tsx | Browser client, ORM insert, live subscriptions |
src/schema.generated.ts | Generated table definitions and row types |
src/agent.ts | Topic consumer and reply worker |
chat-app.sql | USER table, STREAM table, namespace setup |
setup.mjs | Local bootstrap using the kalam CLI |
Credentials
npm run setup creates or reuses:
- user:
admin - password:
kalamdb123
Both the browser and worker use this account for the local demo.
Troubleshooting
Setup cannot reach KalamDB
Agent running but no reply
Re-run setup so the topic route exists:
Next steps
- React AI Chat — full
@kalamdb/reactchat with approvals and attachments - TypeScript Chat Quickstart — docs-only minimal path
- Summarizer Agent — worker-only enrichment pattern