@odla-ai/chat
v0.2.0
Published
Channels, threads, DMs, and AI participants for odla apps — a Slack/Groups-style messaging layer built natively on odla-db's realtime engine. Schema + default-deny CEL rules + an injectable client, so humans and agents chat over the same rule-governed gra
Maintainers
Readme
@odla-ai/chat
Channels, threads, DMs, and AI participants for odla apps — a Slack/Groups-style messaging layer built natively on odla-db's realtime engine. Chat is a schema + default-deny CEL rules + an injectable client; humans and agents chat over the same rule-governed graph. No server to run — it rides the existing odla-db Durable Object.
import { createChatClient } from "@odla-ai/chat";
import { init } from "@odla-ai/db/client";
const db = init({ appId, endpoint: "wss://db.odla.ai", getToken });
const chat = createChatClient(db, { selfId: myAuthId, selfEmail, displayName });
const { id } = await chat.createChannel({ slug: "general", name: "General", kind: "public" });
const channel = await chat.getChannel(id);
if (!channel) throw new Error("channel creation did not become visible");
const unsub = chat.subscribeChannel(id, (messages) => render(messages));
await chat.sendMessage(channel, { body: "hello" });Model
Access is denormalized (no graph edges, to fit odla-db's single-hop ref and
pre-commit rule evaluation): a channel's memberIds (json) is the auth roster for
private/dm channels; messages and reactions carry a denormalized visibility +
audience. chat_membership rows are the per-user index and read-state, not the
source of truth for access. Message ordering + pagination use the indexed
createdAt cursor.
Pieces
CHAT_SCHEMA— push to/app/:id/schema.CHAT_RULES/chatRules({ orgDomain })— install at/app/:id/admin/rules.createChatClient(db, self)— the UI-facing client (channels, DMs, messages, feeds, threads, reactions, read-state, typing/presence).chatSkill({ db, channelId, self })— a@odla-ai/aiSkill so an agent reads and posts as a bot member.botTrigger({ id, agentId, persona, mention })— the commit-trigger config to register at/app/:id/admin/triggers; the odla-db commit hook fires it on human messages and dispatches to the chat-agent worker.chatIntegration— a descriptor bundling the schema, rules, and provisioning steps.
Chat-agent credentials
The optional @odla/chat-agent Worker fails closed unless
CHAT_DISPATCH_SECRET is configured. It does not accept a platform-wide DB
admin token. Store ODLA_BOT_TOKENS as a Worker secret containing a JSON map
from exact tenant id to a scoped app key, for example:
{ "my-app--dev": "odla_sk_...", "my-app": "odla_sk_..." }Mint each key with mode: "rules", the five chat_* namespaces, and only the
provider secret it needs, such as secrets: ["anthropic_api_key"]. The worker
has no wildcard tenant or machine-token fallback.
See this installed README and the exported TypeScript declarations/JSDoc for the version-matched API. The rendered public reference is at https://odla.ai/docs/packages/chat.
License
MIT
