# Samara guest chat

Anna Nexus Labs LLC · behindtheveil369.net

## Scope

Text conversation, explicitly recorded and reviewed voice, read-aloud responses,
private saved journals/check-ins/orientation notes/system maps, optional guided
reflection worksheets, present-oriented grounding, and direct human-help links.
The existing products page remains at `/products`.

## Access and consent

Sites dispatch supplies authenticated user headers. Every record operation is
scoped to that identity. All mutations require a matching same-origin header.
Live chat, transcription, and read-aloud accept anonymous guests with explicit
processing consent. No ChatGPT account or visitor API key is needed. Optional
account-backed saved records remain authenticated and isolated. Guest chat is
not persisted; guest cookies never grant access to private records.

Guest cookies use HMAC-SHA256 with the server-only `SAMARA_SESSION_SECRET`,
256-bit random tokens, a 24-hour expiry, HttpOnly, Secure, and SameSite=Strict.
The Responses API receives a hashed safety identifier, never an email or raw
cookie. Same-origin validation applies to all AI requests, signed in or not.

D1 enforces atomic per-counter reservations across all AI endpoints: 30 calls
per visitor and 100 calls site-wide per UTC day, plus 6 per visitor and 10
site-wide per minute. Calls are reserved before contacting OpenAI and include
failures. Clearing cookies can reset a guest allowance but cannot reset the
shared site caps. Text input/history, output tokens, TTS characters, and upload
bytes are bounded. These are request ceilings, not a guaranteed dollar budget.


## AI setup

`OPENAI_API_KEY` must be a Sites runtime secret, never browser code or Git.
The default text model is `gpt-4.1-mini`; `OPENAI_MODEL` is configurable.
The existing API credential is reused. A new credential requires the secure OpenAI Developers API-key skill.
The review build does not contain a key. Do not claim live inference passes
until chat, transcription, and read-aloud have been exercised with a real key.

## Data boundaries

Records are server-stored and account-scoped, not end-to-end encrypted.
Chat is held only in tab memory and is not saved as a journal. Text inference
receives up to ten recent messages. Journal and system-map records are never
retrieved for inference. Latest orientation note is optional explicit context
in text chat, presented as a lower-priority unverified user report. Voice
requests exclude saved notes and prior conversation. Audio is submitted for
transcription only after recording stops; cancel discards it. Transcript edits
invalidate the review checkbox. Playback is AI-generated, not a human voice.
Responses use `store:false`; this does not guarantee zero provider retention.

## Tests

`npm test` checks the reviewed-voice policy and API behavior against an isolated
SQLite database and a mocked provider. It covers auth, same-origin checks,
account isolation, CRUD, body limits, malformed input, anonymous sessions, cookie tampering,
consent, voice review, private context exclusion, note opt-in, missing key,
shared quota exhaustion, burst throttling, billing errors, and provider failures. These are not live model tests.
`node_modules/.bin/tsc --noEmit` checks application types.
`npm run build` produces the deployment artifact.

## Support boundaries and sources

The worksheets are optional reflection aids, not diagnostic tools or clinically
validated treatment. Samara cannot diagnose, monitor emergencies, contact
support on a user's behalf, recover memories, or infer parts from voice.
Source links checked October 3, 2026:

- https://988lifeline.org/
- https://www.nhs.uk/mental-health/conditions/dissociative-disorders/
- https://developers.openai.com/api/docs/guides/your-data
- https://developers.openai.com/api/docs/guides/speech-to-text
- https://developers.openai.com/api/docs/guides/text-to-speech

## Publishing

Sites owns source synchronization, deployment, runtime secrets, and database
migrations. The site retains its existing project identity and audience.
The Samara record schema is in `db/schema.ts`; generated migrations are in
`drizzle/`. Do not rewrite applied migrations.
