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+
- Kalam CLI
Quick start
From the example folder:
kalam dev starts the local server, applies kalam/schema.sql, regenerates src/schema.generated.ts, and runs both the browser app and agent worker from [dev.processes].
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 |
kalam.toml | kalam dev project config |
kalam/schema.sql | USER table, STREAM table, topic route, seed data |
kalam/migrations/0001_init.sql | Initial migration |
Credentials
kalam dev uses the local development account:
- user:
root - password:
kalamdb123
Both the browser and worker use this account for the local demo.
Troubleshooting
Server health check
Agent running but no reply
Reset local state and reapply the migration:
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