Files
Convivo/docs/backend/feedback-ai.md
T

126 lines
7.3 KiB
Markdown

# Feedback AI Summaries
Attendees submit ratings and comments through the existing event and session
feedback forms. Admin generates summaries manually in **Activity > Event feedback**
or **Activity > Session feedback**. Each session has an independent button.
There is no background generation and no provider call on feedback submission.
## Configuration
**Settings > Feedback AI** stores one global configuration for all events:
- **LLM endpoint:** the complete HTTPS URL of an OpenAI-compatible Chat
Completions API, for example `https://api.openai.com/v1/chat/completions`.
The server does not append a path. URLs with embedded credentials, query
parameters or fragments are rejected.
- **Model:** the provider's model identifier, maximum 200 characters.
- **API key:** optional; sent as `Authorization: Bearer <key>`. Leaving this
field blank preserves an existing key. The checkbox explicitly removes it.
Changing the endpoint requires entering or clearing the key to prevent
forwarding a previously stored credential to a different endpoint.
The endpoint must resolve to public IP addresses. HTTP, localhost, private
networks, link-local metadata endpoints and reserved IP ranges are not supported.
DNS lookups have a 10-second timeout. Results are validated and the HTTPS
connection is pinned to a validated
address, preserving TLS hostname verification. Redirects are not followed.
Private Ollama installations need a public, authenticated HTTPS gateway exposing
the compatible API. Azure-style `api-key` headers and native Responses/Ollama APIs
are not implemented by this adapter.
Stored keys are server-only: `llm_settings` has RLS enabled and no grants for
anonymous or authenticated clients. Authenticated admins use the sidecar routes,
which return only endpoint, model, update time and `has_api_key`. The key is stored
in the protected database table, not encrypted by this feature; privileged
database operators and database backups can access it.
## API and Generation
All routes below require the Admin user's bearer token, verified with Supabase
Auth `/auth/v1/user`, followed by the existing contact admin rule (`is_admin` or
an existing `@appe.at` contact). They return `Cache-Control: no-store`.
| Route | Purpose |
| --- | --- |
| `GET /sidecar/llm-settings` | Read redacted configuration. |
| `PUT /sidecar/llm-settings` | Save `{ endpoint, model, api_key? }`. |
| `POST /sidecar/feedback-summary` | Generate `{ scope: "event", event_id }` or `{ scope: "session", event_id, session_id }`. |
The sidecar checks that the event exists and that a selected session belongs to
it. It reads all feedback in ordered 500-row pages, selecting only `rating` and
`comment`. The LLM receives the scope, event/session title, response count, ratings
and comments; contact names, associated email columns, IDs and timestamps are
excluded. Free-text comments can still contain personal information supplied by
attendees: use an approved provider and appropriate privacy/retention terms.
Requests contain `model`, `stream: false` and system/user `messages`. The response
must contain a nonempty string at `choices[0].message.content`. The prompt asks
for sentiment, strengths, concerns and actionable improvements in the predominant
comment language (English for rating-only feedback), without inventing evidence.
Feedback content is explicitly treated as untrusted input. Output is displayed as
plain text, never HTML; AI output still requires human review.
No-feedback requests fail before calling the provider. Generation also requires
saved configuration. Input is capped at approximately 190 KB of feedback (the
adapter additionally caps its complete input at 200 KB). Provider calls time out
after 60 seconds; output is capped at 100 KB and summaries at 20,000 characters.
Provider failures return sanitized errors, without raw provider bodies or keys.
Concurrent generation of the same target is rejected in the single sidecar
process; this is not a distributed lock across replicas.
## Persistence and Permissions
Migration [20261011163332_feedback_ai_summaries.sql](../../supabase/migrations/20261011163332_feedback_ai_summaries.sql)
adds `llm_settings` and `feedback_summaries`. Only the service role writes them.
Summary reads are restricted to admins by RLS; attendees cannot read these
organizer summaries. A successful generation upserts the latest result for its
scope and target, storing response count, model, generation timestamp and a
SHA-256 fingerprint of the exact rating/comment snapshot. It does not overwrite
ratings or comments. Deleting its event or session cascades the summary.
The UI restores saved summaries and offers manual regeneration. A provider
failure leaves the previous summary untouched. A response-count change is shown;
same-count comment edits are not currently flagged by the UI even though the
saved fingerprint records the generation snapshot. There is no summary history.
Activity reads event-scoped feedback in ordered pages, so counts and available
session controls are not truncated by the database API's row limit. Mobile tabs
wrap into two columns and feedback tables scroll within their own containers.
The old `evaluate_session_feedback` RPC is a deprecated stub with client execution
revoked. Its Schedule button and legacy AI state display were removed. The
legacy `sessions.ai_generated_feedback` field is not used to store these summaries.
Attendee feedback submission, points and average-rating behavior are unchanged.
## Local Validation
The migration was applied alone to the local database and recorded in its ledger;
older pending migrations were not applied. No seed or reset was run. Production
deployment is not included in this change.
For an alternate local instance, leaving the existing servers intact:
```sh
PORT=3003 SUPABASE_URL=http://127.0.0.1:54321 SESSIONIZE_SYNC_INTERVAL_MS=0 PRETIX_SYNC_INTERVAL_MS=2147483647 node apps/sidecar/src/server.js
SIDECAR_TARGET=http://127.0.0.1:3003 npm run dev --prefix apps/admin -- --host 127.0.0.1 --port 3004 --strictPort
```
This preview sidecar has no immediate Sessionize poll, and its Pretix loop has a
long interval. These values are for isolated local validation only, not deployment.
The usual Admin proxy target remains port 3002 when `SIDECAR_TARGET` is unset.
See [tests](./tests.md#feedback-ai-summary-regression) for automated checks.
For this validation, the existing Admin on `http://127.0.0.1:3001` is connected to
the updated sidecar on port 3003 through the ignored local file
`apps/admin/.env.development.local` (`SIDECAR_TARGET=http://127.0.0.1:3003`).
This preserves the existing allowlisted magic-link callback. The isolated 3004
preview was used for mocked browser testing and then stopped; real magic-link
login on another port requires allowlisting its exact callback first. Auth
configuration and existing server processes were not changed or stopped.
Validation passed: 28 sidecar tests, eight rollback-only SQL assertions, the
54-test combined browser regression suite, Admin build, test TypeScript and
editor checks. Desktop/mobile screenshots were inspected, including explicit
grid and bounding-box checks for the mobile feedback tabs and summary panel.
A real local Auth smoke used a disposable confirmed account, verified redacted
settings and no-feedback rejection through the proxy, then deleted its account,
contact and inactive event. No mail or provider request was sent.