# Page AI assistant

## Purpose

Add a right-side assistant drawer that answers questions using the active slide as context. Keep the deck usable when the assistant is not configured.

## Configuration

Collect these values in a settings panel:

- API Base URL, such as `https://api.openai.com/v1`;
- API Key in a password field;
- model name;
- optional system instruction supplied by the deck owner.

Use an OpenAI-compatible request to `{baseUrl}/chat/completions`. Normalize one trailing slash, but do not rewrite the user's host.

Store configuration in browser `localStorage` only after the user saves it. Never place a credential in source, URL parameters, console output, analytics, or exported screenshots. Show a note that local browser storage is appropriate only on a trusted device.

## Context policy

Build context from the active slide only:

1. slide number;
2. slide title;
3. visible slide text;
4. the learner's question.

Do not silently send the full deck, hidden speaker notes, prior slides, local files, or configuration values. Tell the user when no meaningful page text is available.

## Quick actions

Provide four concise entries:

- Explain this page;
- Extract key points;
- Give me one exercise hint;
- Ask a question.

Quick actions should populate or send an ordinary user message. They must not bypass the visible conversation history.

## Request and response behavior

- Disable Send while a request is running.
- Add a visible pending state and allow the drawer to close without losing the page.
- Submit `system` plus `user` messages; keep prior assistant turns only within the current browser session.
- Render assistant content as text, not raw HTML.
- Handle non-2xx responses, invalid JSON, network failure, empty response, and missing configuration.
- Never retry an authentication failure automatically.
- Keep a Clear conversation action separate from Clear saved configuration.

## Presentation behavior

- Open the drawer without covering the active page title on desktop.
- Use a full-height sheet on narrow screens.
- Hide the assistant button, drawer, dialog, and toast messages in print.
- Keep all assistant controls out of fullscreen projection unless the presenter opens them.
- Provide visible focus states, labels, Escape-to-close, and focus restoration.

