Files
CatoandClaude Opus 5.5 ebe51fa38e feat(auth): every way in on AccountKit's own screens (#289)
* feat(auth): every way in on AccountKit's own screens

Botsmann signed people in against OrangeCat's GoTrue (auth.users). It now
runs on AccountKit (@bitbaum/accountkit 0.23) with AccountKit's own forms:
/auth/signin offers email and password, an emailed sign-in link, a
passkey, recovery through the mailed link and the second factor;
/auth/signup is sign-up; /account carries the account panel ("Sign-in and
security" in the account menu). "Continue with OrangeCat" and the shared
sign-in show when their clients are set, the link and recovery when mail
is. The GoTrue routes (/api/auth/signin, signup, forgot-password,
resend-verification, profile) and pages (callback, forgot-password,
reset-password, verify-email) and the cookie-session client are gone.

AccountKit's tables live in a host accounts database (drizzle/, loki
accounts-db.conf); the data stays in the botsmann supabase schema, which
every route already read with the service-role client. verifyUser now reads
AccountKit's session; /api/user/profile moves onto it too. New accounts get
uuid ids, and migration 013 drops the person columns' keys to auth.users,
which a new person's id is not in. Nothing is deleted. The profile editor
writes AccountKit's name and image.

Existing people keep their rows: scripts/db/accountkit-people.sql lists
everyone who owns rows with their OrangeCat actor id, and
scripts/db/accountkit-import.sql gives each an account under the same id,
linked to OrangeCat by that actor id, never by address (loki
accountkit-supabase.yml rehearses it rolled back, then imports).

Pages were served with public, max-age=3600 to every browser, account pages
included: after sign-out the browser showed its cached /account. /account
and /auth/* are now private, no-store. The account menu's trigger has a name.

tests/__tests__/accounts runs the ways in and the import on the committed
migration; browser-smoke.yml's account job rehearses the import and runs
the browser journey against the production build with AccountKit's real
mail caught by a sink.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

* fix(auth): send a signed-out visitor to sign in with the router

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

* ci(auth): the shared sign-in's button is matched by how it starts

AccountKit 0.24 names only the providers Morulia publishes, so the label
changes with Morulia.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

* ci(auth): expect the shared sign-in only once Morulia publishes a provider

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

* ci: run the checks on the journey change

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-02 23:27:16 +01:00

6.4 KiB

Botsmann

Domain-specialized AI professionals, not another generic chatbot wrapper.

License: MIT TypeScript Next.js Live


The Professionals

Six built-in specialists. Each with scoped knowledge, calibrated personality, and domain-specific system prompts.

Professional Domain Specialty
Lex Legal Contract review, case analysis, regulatory compliance
Imhotep Health Evidence-based insights, research assistance
Nerd Research Systematization, web scraping, discovery
Heidi Language German/Swiss German, translation, culture
Muse Art Style analysis, composition, art history
Trident Business Project management, technical guidance

SSOT: data/bots.ts. Each bot defines system_prompt, expertise[], interests[], communicationStyle (formality/verbosity/empathy), navConfig, and display metadata. Document access is scoped per professional -- Lex sees legal, business, and general docs only.


Architecture

Multi-LLM Routing

Three-tier provider strategy with graceful fallback:

Priority Provider Model Cost
1 Ollama (local) llama3.2:latest Free, self-hosted
2 Groq (cloud) llama-3.1-8b-instant Free tier
3 OpenRouter (cloud) Claude 3.5 Sonnet, GPT-4, Gemini, Grok, Llama, Mistral Paid

Local first, free cloud second, paid cloud last. Users can override via settings. If a provider key is invalid, the system falls back silently to the next tier.

Entry point: lib/llm-client.ts -- generateWithBestProvider() handles selection, timeout (30s), and fallback logic.

RAG Knowledge Retrieval

Zero-cost client-side embeddings with server-side semantic search.

  • Embeddings: Xenova/all-MiniLM-L6-v2 (384-dimensional) via Transformers.js -- runs entirely in the browser, no API calls
  • Chunking: 500-token chunks, 50-token overlap, sentence-aligned boundaries
  • Search: supabase.rpc('match_documents') using pgvector cosine similarity
  • Context limits: 8000 chars for RAG chat, 4000 for professional chat
  • Sources: Returned with document name, preview snippet, and similarity score
  • Timeout: 8s for embedding generation

Privacy Model

Every table enforces Row Level Security. No exceptions.

  • User documents isolated by user_id -- no cross-user data leakage
  • API keys stored encrypted per-user
  • Four-layer prompt injection defense:
    1. sanitizeSystemPrompt() -- prevents instruction override
    2. sanitizeUserMessage() -- removes malicious payloads
    3. sanitizeConversationHistory() -- validates message format
    4. wrapUserContext() -- XML-like delimiters separate data from instructions

Custom Bot Creation

Users build their own specialists:

  • Templates: Memorial, historical, functional, magical, helper
  • Personality: Big Five trait sliders with full editor
  • Knowledge: Upload text, audio, video, images as a custom knowledge base
  • System prompts: Fully user-defined
  • Entity levels: Spark, Aware, Learned, Wise, Evolved, Transcendent

API Design

Standardized response format (SSOT: lib/api/responses.ts):

// Success
{ success: true, data: {...}, meta?: { total, page } }

// Error
{ success: false, error: "Message", details?: [...] }

Rate limits: 20 req/60s for chat, 15 req/60s for professional chat.


Tech Stack

Layer Technology
Frontend Next.js 16, React 19, TypeScript 6, Tailwind CSS 4
LLM Groq, OpenRouter (100+ models), Ollama (local)
Database Supabase PostgreSQL 15 + pgvector
Embeddings Transformers.js (all-MiniLM-L6-v2, 384d)
Auth @bitbaum/accountkit (accounts database beside the schema)
Email AWS SES
Deployment Self-hosted on Hetzner (behind Caddy); GitHub Actions CI

Quick Start

Prerequisites

  • Node.js 24 (see .nvmrc)
  • A Supabase project with pgvector enabled
  • At least one LLM provider key (Groq is free)

Setup

git clone https://github.com/bitbaum/botsmann.git
cd botsmann
pnpm install

Environment

cp .env.example .env.local

Required variables:

NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
GROQ_API_KEY=your-groq-key

Optional (for multi-model support):

OPENROUTER_API_KEY=your-openrouter-key
OLLAMA_BASE_URL=http://localhost:11434

Optional (visitor feedback FAB — must be set at next build, not only at runtime):

LOKI_FEEDBACK_TOKEN=fcw_…

Run

pnpm run dev

Open http://localhost:3000.


Project Structure

botsmann/
  app/                    # Next.js 16 app router
    api/                  # API routes (thin HTTP layer)
    (routes)/             # Page routes
  components/             # UI components (no business logic)
  data/
    bots.ts               # SSOT: professional definitions
  hooks/                  # Data fetching, state management
  lib/
    api/
      responses.ts        # SSOT: API response format
    llm-client.ts         # Multi-provider LLM routing
    embeddings/           # Transformers.js integration
    security/             # Prompt injection defense layers
  public/                 # Static assets
  supabase/
    migrations/           # Database schema + pgvector setup

License

MIT