Files
tajniak81andClaude Opus 5.5 78b7710090 Add AI chat, writing actions, workspace embeddings and an MCP server
Phase E of the AFFiNE parity plan (ADR-15):

- internal/ai: OpenAI-compatible, Anthropic (official Go SDK) and Ollama
  drivers; BYOK profiles per workspace and for the instance, with keys
  encrypted by DOCWELL_SECRET_KEY, failover order, a test call and usage
  counters.
- Embeddings: an indexer that follows PocketBase like the search index,
  chunks pages along their blocks and keeps vectors in a bbolt file in
  the data dir (no cgo); progress, ignored pages and extra files.
- Chat sessions scoped to a page, space or workspace, streamed as
  server-sent events, with citations to pages and blocks, fork and
  history; retrieval only from pages the asker can read.
- Writing actions (rewrite, fix, shorter, longer, summarise, translate,
  continue, custom) in the editor's selection toolbar.
- POST /mcp: MCP over Streamable HTTP with personal API tokens; read
  tokens search and read pages, write tokens also create and update them.
- Web app chat panel (Ctrl+J), workspace AI settings, an admin AI page,
  OpenAPI, generated clients, migration and translations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 21:58:22 +01:00

2.3 KiB

HTTP API

docwell-server's API is described in api/openapi.yaml (OpenAPI 3.1). It is the source of truth: the web, desktop and mobile apps use clients generated from it.

  • Base path: /api/v1.
  • Authentication: for scripts and integrations, create an API token under Your account → API tokens and send it as Authorization: Bearer dw_…. A token acts as you, with your access; read only tokens can only make GET requests, and no token can manage tokens or two-step sign-in. Apps sign in with POST /api/v1/auth/login instead and send the returned session token the same way (refresh it with POST /api/v1/auth/refresh). Accounts with two-step sign-in answer 401 {"error":"totp_required","challenge":"…"}; finish with POST /api/v1/auth/totp/verify {"challenge","code"}.
  • Errors are JSON: {"error": "<code>", "message": "...", "fields": {...}}, where fields holds per-field messages for validation errors.
  • File links (/api/v1/files/{id}) also accept ?token= with a short-lived token from POST /api/v1/files/token, because <img> tags cannot send headers.

Health checks for load balancers: GET /healthz (process up) and GET /readyz (database reachable).

MCP

POST /mcp is a Model Context Protocol server (Streamable HTTP, JSON responses). Authenticate with an API token. Tools: list_workspaces, list_spaces, list_pages, search, read_page (Markdown) and ask (the workspace's AI, with sources); write tokens also get create_page and update_page (replace or append Markdown). For example, in an MCP client's configuration:

{ "mcpServers": { "docwell": { "type": "http", "url": "https://wiki.example.com/mcp",
  "headers": { "Authorization": "Bearer dw_…" } } } }

AI chat answers (POST /api/v1/ai/sessions/{id}/messages) and writing actions (POST /api/v1/workspaces/{id}/ai/write) stream as server-sent events; see the OpenAPI file for the events.

Example

TOKEN=$(curl -s -X POST https://wiki.example.com/api/v1/auth/login \
  -H 'Content-Type: application/json' \
  -d '{"email":"me@example.com","password":"..."}' | jq -r .token)

curl -s https://wiki.example.com/api/v1/workspaces -H "Authorization: Bearer $TOKEN"