Files
code_of_conquest_dnd/api
Phillip Tarrant 45d5f0360b test(api): keep test_endpoints hermetic after /dm/narrate wiring
/dm/narrate now makes a real Ollama call (Task 7). The role-endpoint
loop tests in test_endpoints.py had no mock, so every default pytest
run was silently hitting a live Ollama instance on localhost:11434 —
breaking the hermetic-suite constraint. Add an autouse fixture that
stubs narrate.ollama_client.chat and narrate.call_log.record so all
five endpoints stay hermetic; assertions (200 on valid, 422 on
invalid) are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-10 08:31:42 -05:00
..
2026-07-09 11:17:54 -05:00
2026-07-09 11:17:54 -05:00

/api — FastAPI proxy

The guarding proxy from charter §4. Not a generic API — it exists to keep the API key, the prompts, and the model routing server-side, and to log every call from day one.

Stack: Python, FastAPI. Models: Ollama (dev/staging) → Replicate (prod), routed per-role server-side.

Role endpoints (charter §4)

POST /dm/narrate      Narrator    — scene/outcome prose        (good model)
POST /dm/adjudicate   Adjudicator — free text → legal action   (small/fast, strict JSON)
POST /dm/improvise    Improviser  — minor sandboxed event       (charter §7 limits)
POST /npc/speak       NPC         — voice one character          (bounded moves, §6)
POST /party/banter    Banter      — companion callbacks          (cacheable, §9)

The client does not know which model serves a role or what the prompt is.

Responsibilities

  • Auth · metering (retrofit later — middleware + Stripe webhook, §4)
  • Prompt ownership — prompts live in prompts/, never in the client
  • Model routing — role → model is config, a deploy not a client patch
  • Logging — log seed and full prompt with every call (§10) for replay/eval

Contracts

Every AI response is untrusted (§2). Parse, validate, be ready to discard. One retry on parse failure, then authored fallback (§12).

See docs/ for endpoint schemas, model routing, and deploy notes.