# Help assistant

Status on 2026-11-25: implemented locally. Retrieval, authorization, the missing-key fallback and the model call are covered by tests with a mocked model. No request has been sent to OpenRouter, and the dialog has not been checked in a browser against a deployed backend.

Help & feedback, in the workspace menu at the top right, is for the people who use Hyperchat day to day. It has three parts.

## Get help

Type a question such as "How do I schedule a post?".

- **With an AI key saved for the workspace** (Settings → AI tools), Ask sends the question to the workspace's writing model and shows a short answer. Under the answer, "From the guide" lists the sections it used. Each one opens the full section.
- **Without an AI key**, the same box searches the guide as you type and shows the matching sections. Nothing is sent anywhere. The full guide is listed when the box is empty.
- Client reviewers always get the searchable guide. They cannot spend the workspace's AI requests.

What the assistant will not do:

- It does not take actions. It has no tools and cannot see or change contacts, messages, posts or settings. It tells the person where to click.
- It does not guess. If the guide has nothing for the question, it says so and offers Contact support.
- It does not show an answer it cannot tie to the guide. See the rules below.

The conversation is kept in the open dialog only. Closing the dialog clears it. There is no chat history table, and nothing about the question is stored. The last three turns are sent with a follow-up question so "and on my phone?" makes sense.

## Contact support

Shows an Email support button when a support email is configured. It opens the person's own email app with:

- To: the support email
- Subject: `Hyperchat help: <app section> (<workspace name>)`
- Body: the workspace name, the app section, the Hyperchat version, their last question, and prompts for what they were trying to do and what happened

Nothing is sent by Hyperchat. Without a support email the tab says that none is set up and to ask whoever set up the installation.

## Report a bug

The existing report for the agency or developer who runs the installation: the Getting started and Feedback & bugs links, the copyable report template, and the installation diagnostics command.

## Setting the support contact

For now the contact comes from two Convex environment variables:

```bash
npx convex env set SUPPORT_EMAIL help@youragency.example
npx convex env set SUPPORT_NAME "Your Agency"
```

`SUPPORT_EMAIL` must be one plain address. Anything else, such as two addresses or text with `?`, is ignored and treated as not set. This is deployment-wide: every workspace shows the same contact until per-agency settings exist.

## How an answer is produced

1. `helpAssistant:ask` checks workspace membership.
2. The question, plus earlier questions in the same dialog, is scored against the bundled guide with plain keyword matching (`searchGuide` in `src/lib/help-guide.ts`). The best four sections are kept. Sections with no matching word are left out.
3. If nothing matches and the agency has written no support notes, the answer is "the guide does not cover this" with a pointer to support. No model is called and no AI request is used.
4. Otherwise one AI request is reserved and only the matched sections, any support notes and the question are sent. The whole guide is never sent.
5. The model must return `covered`, `answer` and `usedSections`. The answer is shown only when `covered` is true and every listed section is one that was supplied. If `covered` is false the person sees the "not covered" message. If the reply is incomplete, malformed, or cites nothing or something it was not given, the AI text is discarded and the matching guide sections are shown instead with a one-line reason.
6. If the model cannot be reached, rejects the key or needs credits, the matching sections are shown with that reason.

Retrieval is keyword scoring: a word in a section's title counts most, then its keywords, its menu path and its text. A keyword phrase typed as written counts extra. It has no understanding of meaning, so an unusual phrasing can miss. That is the cost of keeping it simple and free of an embeddings service.

## The guide

`src/lib/help-guide.ts` holds about thirty short sections, one per area, each with a title, the menu path, keywords, a summary, three to seven steps and notes. It was written from `docs/USER_GUIDE.md` and the feature docs. Tests check that ids are unique, that each menu path only names areas present in the workspace menu, and that everyday questions land on the right section.

The assistant can only be as accurate as this file. When a feature or a label changes, change the matching section in the same release. Features without a section, for example SMS, are reported as not covered until a section is added.

## For the coordinator

| Piece | Location | Notes |
| --- | --- | --- |
| `helpAssistant:info` | query, any member including reviewers | `{ aiReady, support: { email, name } }` |
| `helpAssistant:ask` | action, members except reviewers | args `{ workspaceId, question, section?, history? }`, returns `{ mode, answer, sections, support, note? }` |
| `helpCredentials(ctx, workspaceId)` | `convex/helpAssistant.ts` | The one place Help gets AI credentials. Returns `{ apiKey, model }` or `null`. Today it calls `reserveWorkspaceAI`. Swap its body for plan credits. |
| `supportContact(ctx, workspaceId)` | `convex/supportContact.ts` | Returns `{ email, name, notes }`. Today it reads `SUPPORT_EMAIL` and `SUPPORT_NAME` with empty `notes`. Callers check membership first. |
| `notes` | from `supportContact` | Agency-written help text. Trimmed to 4,000 characters and sent as an extra source with the id `support-notes`. With notes present, a question the guide does not match still goes to the model, because the notes may answer it. |

`mode` is `answer` (grounded AI text), `uncovered` (nothing to answer from) or `guide` (matching sections only, with `note` saying why).

Help shares the workspace AI limits of 10 requests a minute and 200 a day with every other AI feature.

## Limits

- The model call needs a writing model that supports structured output, the same requirement as the inbox assistant.
- Answers are in the language of the guide, English. The guide is not translated.
- The assistant does not know which plan, role or connected accounts the person has, so it may describe a step their role cannot do. Sections say when a step needs an owner or administrator.
- Support notes are untested with real agency text. They are passed to the model as reference data with an instruction not to follow instructions inside them.
