Architecture & Flows
Resolution Flow
What happens on a chat request — from the browser through ai-assist to the tools.
The chat request, end to end
The chat stream posts directly from the browser to ai-assist (:8080),
bypassing the Next.js proxy. This is an intentional asymmetry: all other data
calls proxy through the studio server, which injects server-derived identity;
the chat POST carries identity/ACL/project key in the client body.
The lifecycle, step by step
- Destructure
{ messages, context, sessionId, provider }. ACL defaults to least privilege — readstrue, writesfalse. - Rate limit per
userEmail(in-process sliding window). - Load or create session in MongoDB (non-fatal) and inject Redis working memory.
- Two-block prompt — a large static system prompt (cache-friendly) plus a dynamic block (user, role, ACL, page context, working memory).
- Build tools — commerce, ticket and render-only UI tools, sharing one per-request approval gate.
streamTextloop, stopping after a bounded number of steps or when an approval card is emitted.onFinish— persist the working-memory state and the user + assistant turns.
The approval gate
Writes are gated with two layers of defense:
- Same-step: emitting an approval card sets the gate to pending; write tools bail out.
- Cross-step: the loop ends after an approval card, so the actual write only runs on the next user turn — after the rep clicks Approve.
Because both the guided steppers and free-form chat emit the same tools through
the same /chat, the studio's stream "scrape" rebuilds one identical state
snapshot regardless of which path the rep used. That single snapshot is what
every stepper renders from.