Skip to content
askdareDocumentation

    ADR-0040: Bots managed in a database: @boldare/askdare-studio

    • Status: Proposed. Planned in the roadmap ("The studio", own track), not started. Waiting on the audit and spike s12, whose task is written when the track is scheduled, and then the maintainer's answers to "Open questions", which stay open until s12 has gathered evidence for each.
    • Date: 2026-11-30
    • Extends: ADR-0016 (a second add-on with storage, beside @boldare/askdare-admin), ADR-0034 (decision 6: in an app that uses the studio, users and roles are managed in the console), ADR-0039 (a published revision is a prompt version). All stay accepted.
    • Touches: ADR-0004 (a new way to change what a bot does: an authenticated write from the console), ADR-0006 (a new package, and a new port in core's public API).

    Context

    Today a bot is code. defineBot in the app's askdare.config.ts sets its instructions, model, limits, tools, knowledge, texts, forms and handoff, and createChatHandler({ bots }) takes a fixed array. Every change is a commit, a review and a deploy. The console shows the configuration read-only (ADR-0032, decision 7), and access to the console is a list in code (ADR-0034, decision 4).

    That suits a developer who owns the bot. It doesn't suit:

    • an agency's client who wants to change the greeting, the opening hours in the instructions or a budget without asking the agency for a deploy;
    • a support or content team that iterates on instructions every week and wants to compare versions (ADR-0039) without a developer in the loop;
    • a team that manages people, who asked for users, invitations and role changes in the console, which ADR-0034 (decision 6) left to the app.

    Doing this in core would break core's promise that two environment variables are enough (ADR-0003, ADR-0016, "Admin in the core, with a database" rejected). Letting both code and a database configure the same bot gives two sources of truth: a deploy and a console edit overwrite each other, and askdare eval in CI (ADR-0035) no longer tests what runs.

    So this is a separate, opt-in product: a module that keeps bot configuration, console users and their roles in the app's own database, edited in the console, with code still deciding what the database is allowed to change.

    Decision

    1. A separate, opt-in package with its own releases

    • @boldare/askdare-studio (name to settle, question 1), in packages/askdare-studio/. It versions on its own, starting at 0.1.0, as @boldare/askdare-admin did in 0.7. Core gains only the port of decision 4.
    • Self-hosted, in the app. It runs in the app's Next.js server against the app's database. Boldare hosts nothing and sees nothing, so ADR-0016's rejection of a hosted dashboard stands.
    • Core stays database-free. An app without the studio changes nothing and pays nothing for it, in bundle size or setup.

    2. One source of truth per bot

    A bot is either in code (defineBot, as today) or in the studio. Never both.

    • One handler may mix them (question 5): createChatHandler({ bots: [supportBot, studio.bots()] }).
    • The same ID in both is a setup error on the first request, not a merge with an order of precedence.
    • Code bots show in the studio read-only, as the console's Bots view shows them today, marked "defined in code".
    • Moving a bot from code to the studio is an import: the studio reads the code bot's data fields (decision 3) into a draft, and the developer removes the defineBot once the draft is published. The reverse is an export to a defineBot snippet.

    3. Code registers capabilities, the database composes bots

    What the database may hold is limited to data. Anything that runs code, holds a secret or reaches the network is registered in code and picked by name.

    Part of a botWhere it lives in a studio bot
    Instructions, per language (strings only, question 4)Database
    Versions and the experiment's split (ADR-0039)Database: each published revision is a version
    Widget texts, greeting, theme choiceDatabase
    Model and its settings (ADR-0036)Database, picked from models, a list the app passes in code. The library still names no model (CLAUDE.md).
    Limits and budgetsDatabase, within ceilings set in code (limits in the studio's options). A stolen owner session can't lift a budget above them.
    Forms whose fields are data (ADR-0031)Database
    Handoff on or off, its textsDatabase. The transport (webhookHandoff, emailHandoff) is registered in code.
    A per-bot off switchDatabase, beside the app-wide kill switch, which stays an environment variable (ADR-0004)
    Tools (httpTool, MCP servers, custom tools)Registered in code by name; the database only turns them on per bot. No URL, header or MCP server address is typed in the console (SSRF, ADR-0038).
    KnowledgeRegistered in code (a vector store ID or a KnowledgeIndex), picked by name. Uploading documents from the console is later (decision 8).
    Guardrails, hooks (onUsage, onLead, onHandoff), stores, secrets, allowed origins, identityCode only

    The studio validates a draft with the same schema defineBot uses, plus the registry and ceiling checks, so a bot that would fail defineBot can't be published.

    4. Core gains a bot source port

    createChatHandler's bots accepts, beside BotHandles, a bot source: an object core asks for bots by ID and for the list, asynchronously. The studio is one implementation. A headless CMS or the app's own table could be another.

    • Shape, to settle in spike s12: list() and get(id) resolve published bot data, which core validates as defineBot does and caches per revision. Every bot core receives carries a revision ID, so a cache can tell an old bot from a new one.
    • Freshness: a short time-to-live plus a revision check (question 6), measured in s12. A change takes effect for new turns within that window. A turn in progress finishes with the bot it started with.
    • Failure: if the source is unreachable, core keeps the last bot it validated. Without one, the bot answers bot_unavailable, as a misconfigured model does today. It never falls back to defaults.
    • What s12 must check, because today they assume a fixed array:
      • getChatConfig and getEmbedConfig are synchronous; a studio bot needs async variants, or the page reads the bot's public part through the handler;
      • proxy.ts matches each bot's embedPath (ADR-0018) from the array;
      • grants are sealed with the bot's ID (ADR-0004). A bot deleted in the studio must answer as an unknown bot, and a conversation must keep its version (ADR-0039) across a new revision;
      • limits and budgets keyed by bot keep counting across revisions;
      • askdare eval (ADR-0035) runs a named revision, including a draft, so a change can be tested before it is published;
      • the cost of one database read per cache miss on a serverless cold start.
    • Public API: the source's type and the async config helpers, from @boldare/askdare/next, in a core minor (ADR-0006). The array keeps working unchanged.

    5. Drafts, published revisions and rollback

    • A bot has one draft and a history of published revisions. A revision never changes once published.
    • Publishing makes the draft the bot's revision for new conversations. The revision's name is its ADR-0039 version name, so reports, the admin store, the dashboard and askdare eval --version compare revisions with nothing new.
    • Rollback publishes an older revision again under a new revision name, so the history stays linear.
    • An experiment (ADR-0039) splits new conversations between published revisions.
    • The playground runs the draft for its user only. This is where "the console tries a change before it ships" lives, outside core.

    6. Users, roles and the audit log live in the studio

    In an app that uses the studio, the console manages who may sign in. This extends ADR-0034, decision 6 for these apps only; an app without the studio keeps allow in code.

    • Identity still comes from the app's sign-in, as the sub of the admin identity token (ADR-0032, decision 8). The studio stores no passwords. An invitation is a pending grant for an email or a sub, claimed at the first sign-in that matches it.
    • The studio supplies allow as a function (ADR-0034, decision 4, "a function form of allow"), so the check stays in core and the fingerprint still ends a session when its grant changes.
    • Roles stay ADR-0034's four (question 3):
      • developer edits drafts and runs them in the playground;
      • owner publishes, rolls back, manages users and changes limits and budgets (within code's ceilings).
    • Code wins over the database for access. ADMIN_SECRET stays an unscoped owner, and entries in code's allow show in the studio locked. This is the way back in when the database is wrong or empty: the first owner is whoever signs in with ADMIN_SECRET or is listed in code.
    • The last unscoped owner can't be removed or demoted from the console.
    • Every write is logged: who (the sub's pseudonym), when, which bot or user, and the change. The log holds configuration, never visitor data, and is readable by owner. It also answers ADR-0034's "who opened which transcript" later, if wanted.

    7. Security

    ADR-0004's rule stands: the chat's client never chooses the model, instructions, tools or knowledge. The studio adds a new writer, an authenticated console user, and with it a new threat: a stolen or malicious owner session rewrites a bot. Limits on the damage:

    • what can change is data within code's registry and ceilings (decision 3), so no new tool, URL, model or budget beyond the code's;
    • publishing needs owner, and every publish is in the audit log, with rollback one click away;
    • instructions written by staff are untrusted for rendering, like model output: shown as text in the console, never as HTML;
    • size caps on every field, checked on the server;
    • THREAT_MODEL.md gains the case "a console account rewrites a bot" when this is accepted.

    8. Storage and order of work

    • A StudioStore port with a contract test suite, memoryStudioStore() for tests and the e2e mock, and Postgres first (question 7). The data is relational (revisions, users, grants, the log), and Postgres is already an official add-on.
    • The studio's views mount in the console, as the dashboard add-on does (ADR-0032, host), so sign-in, roles, assets and the look are shared (question 2).
    • Order:
      1. the audit and spike s12: first an audit of everything in askdare that assumes bots are fixed code, then a prototype of what it marks as risky (a bot source backed by Postgres, the cache, and the checks in decision 4);
      2. the bot source in core, in a core minor (0.9 or 0.10, decided with the roadmap);
      3. studio 0.1.0: bots (instructions, texts, greeting, model and settings, limits, off switch), drafts, publish and rollback, users and roles, the audit log, memory and Postgres stores;
      4. later, each with its own task: forms, tools and knowledge picked from the registry, experiments in the UI, uploading documents to knowledge (through ADR-0037's FileStore and a server-side kb sync), Upstash if asked.

    Consequences

    • Teams without a developer at hand can run a bot, and an agency can hand a client the studio without handing over the code.
    • Users and roles can be managed in the console, for apps that choose the studio.
    • Code stays the safest path and the default. Nothing changes for apps that don't install the studio.
    • Core gains one port and async config helpers, a public API addition to design before 1.0's freeze.
    • The threat model grows a console writer; the registry and ceilings keep its reach to what code allows.
    • A studio bot isn't reviewed in a pull request. Review moves to drafts, the playground, askdare eval on a draft, the owner's publish and the audit log.
    • Another package to keep working: a store port, its contract tests, a Postgres schema with migrations, and console views.

    Alternatives considered

    • Configuration in the database inside core. Breaks ADR-0003's two-variable promise and makes every app pay for it. Rejected, as in ADR-0016.
    • Code and database configuring the same bot, merged field by field. Two sources of truth: every change raises "which wins". Rejected for decision 2.
    • A hosted studio run by Boldare. Bot configuration, and soon conversations, leave the owner's infrastructure, and askdare needs accounts and a backend. Rejected, as in ADR-0016.
    • A git-backed studio that turns each console edit into a pull request against askdare.config.ts. Keeps code as the only truth and review in place, but needs a GitHub token in the app, waits for a deploy per change, and doesn't serve people without a GitHub account. Possible later as a publish target of its own; not the first version.
    • Only a headless CMS integration (the app's CMS holds the instructions). The bot source of decision 4 allows it, but leaves users, roles, drafts and the audit log to every app.
    • Instructions as code functions stored by name in the database. Gives back BotContext, but turns the registry into a second defineBot. Strings per language first (question 4).

    Open questions

    Each has a recommendation; the maintainer settles them before this is accepted.

    1. Name. Recommended: @boldare/askdare-studio. Alternatives: askdare-cms, askdare-manage.
    2. Where the UI lives. Recommended: views in the console, mounted like the dashboard. Alternative: a page of its own, which duplicates sign-in and the look.
    3. Who publishes. Recommended: owner only, with drafts at developer, and no new role in 0.1. Alternative: a fifth role, editor, between reviewer and developer, who edits texts and drafts but spends no tokens; that changes ADR-0034's fixed set.
    4. Instructions. Recommended: strings per language, no templating in 0.1. Alternative: a few placeholders ({{locale}}, the signed-in user's name), each a small injection surface to review.
    5. Mixing code and studio bots in one handler. Recommended: allowed, with no shared IDs. Alternative: a handler is all code or all studio, which is simpler but forces a migration all at once.
    6. Freshness. Recommended: a time-to-live of about 30 seconds plus a revision check, tuned by s12. Alternative: invalidation pushed on publish, which a serverless deployment can't deliver to every instance.
    7. Stores. Recommended: memory and Postgres in 0.1. Alternative: Upstash too, which needs a key layout for revisions, users and the log with no queries.
    8. Knowledge in 0.1. Recommended: no; picked by name from code only. Uploading documents from the console waits for the file store (ADR-0037) and its own task.