Know who is asking
Memory belongs to a person, so WorkBot first needs to know who is asking. On Day 5, src/proxy.ts gave every browser an anonymous visitor cookie, and for now that cookie is the person's identity, read in one function. Sign-in arrives on Day 30, and with it per-tenant scoping, which keeps each customer's data apart.
Study first
- Read about cookies from
next/headers, which is request-time. It works anywhere in a route handler, or in a Server Function, which runs on the server when the page calls it. On a page under Cache Components, the rendering model from Day 1, it must run inside aSuspenseboundary.
Build
- Write
src/lib/visitor.ts, wherevisitorId()returns the cookie's value, orundefinedfor an API request without the cookie. - Change
src/lib/analytics.tsxto read the id throughvisitorId(), instead of from the cookie jar.
Done when
pnpm testpasses.- A
curlto/api/chatwithout the cookie still gets an answer.
Technical notes
- A caller without an id gets no memory, so WorkBot reads nothing for it and keeps nothing. A shared "anonymous" bucket would mix strangers' facts.

