Copilot — display spec, behaviour and knowledge base
One copilot component for every portal. Its look, positions and controls are identical everywhere; only the instructions, greeting, notices and knowledge base differ, and those are edited from Admin → Copilot & AI → Copilot & knowledge, never in code. Last updated 2026-10-31.
1. Where it appears
| Portal | Mounted by | Knowledge base | Talks to |
|---|---|---|---|
| School (admins, teachers, staff) | PortalShell | SCHOOL + GLOBAL | how the school portal works; never the school's own records |
| Startup / vendor | PortalShell | STARTUP + GLOBAL | leads, pilots, integration |
| Platform admin | PortalShell | ADMIN + GLOBAL | operations, audit, KB upkeep |
| Parent | PortalShell, only where allowed (below) | PARENT + GLOBAL | what the portal shows, how to ask the school |
The onboarding wizard keeps its own embedded step copilot (it is a single flow with a fixed script); the pupil launcher has none (children's surface).
New vendor with AI (/admin/vendors/new/ai/…) is the one admin page with its own copilot, the *setup guide* (docs/vendor-setup-ai.md). While it is on screen the portal's copilot stands down (DockProvider.guide) and the guide takes its place in the dock, opening docked. It follows a fixed script of steps, reads the vendor's files and website, and turns what the admin types into draft changes — it never creates anything; the admin presses each step's button.
Guided tasks (docs/guides.md; for users, docs/help/copilot.md): a page with a guide — thirteen, across the vendor, school and EduSpaze portals — puts its guide in the copilot's place in the dock: the task's steps (no AI) and an Ask AI tab handed the same steps and where each stands. Like the setup guide, it stands the portal's copilot down while it is mounted, and never acts on its own.
The parent copilot is the school's, extended (lib/copilot/parent.ts, 2026-10-22). A parent sees it only when all of these hold: parent access is on for the platform; Admin → Copilot → Parent portal is on (off until a platform admin turns it on — the tab itself appears only while parent access is on); the school portal's copilot is on; and every school the parent has a child at includes the copilot in its subscription. One school without it turns it off for that parent — the panel is not per-child. The panel hides on this, and /api/copilot/chat refuses on it independently.
2. Display spec (components/copilot/copilot.tsx)
| Mode | Appearance | How you get there |
|---|---|---|
| closed | a launcher pill at the bottom-right edge; an amber dot when the page is a function page | Close, or Esc from panel/docked |
| panel | slides out from the right over the page, 420 px wide, full height, shadow | click the pill; Undock |
| docked | sits beside the page at 420 px and pushes the content (the main column reserves --copilot-dock) | Dock |
| max | fills the viewport; conversation centred at 3xl width | Maximise |
Toolbar, left to right: Dock / Undock, Maximise / Revert, Close. *Revert* returns to whichever mode the copilot was in before it was maximised. Esc reverts from max, otherwise closes. The chosen mode is remembered per portal in localStorage (eduspaze.copilot.<portal>).
Panel anatomy: header (avatar, display name, current module, state), function-page notice bar (amber, when applicable), greeting bubble, suggested prompts (before the first question), conversation, input row. Assistant answers list the knowledge-base articles they drew on; when no LLM key is configured they say so in small print.
Accessibility: role="complementary", labelled toolbar buttons with aria-pressed, an aria-live region that announces entering and leaving a function page, input disabled with an explanatory placeholder when blocked.
3. Function pages
A function page is any page where the user can create, edit or delete model data (forms and actions). On such pages the copilot:
- announces, once, that it is not enabled for the module (
functionPageNotice, with{module}replaced by the menu name), both in the conversation and viaaria-live; - disables the input and shows the notice bar;
- announces it is back when the user leaves the page.
The classification lives in one registry, lib/copilot/registry.ts (MODULES), so the server enforces the same rule: the chat API refuses questions from function pages and logs the refusal. Unknown pages under a portal are treated as function pages (fail closed).
| Portal | Function pages | Information pages |
|---|---|---|
| School | Staff & Access, Students, Classes & Groups, School Settings, Needs Survey, Challenge Statements, Parent Questions, a pipeline conversation, Bundles & Credits, Audit Log, Matchmaking Trips, a marketplace listing | Dashboard, Recommendations, Marketplace, My Pipeline, Benchmarking, Engagement, Platform discovery |
| Startup | Profile & Pilot Offer, Integration & API, a lead conversation, Challenge Statements, Matchmaking Trips | Dashboard, Lead Inbox, Market Insights |
| Admin | Vetting, Schools, Bundles, Credits, Trips, Grants, Challenges, Settings, Audit, Copilot & KB | Dashboard, CRM, Reports |
| Parent | App detail & questions | Your children, Apps, Timeline, Activity |
4. Answering (lib/copilot/rag.ts)
Retrieval-augmented generation over the portal's knowledge base:
- Retrieve: Postgres full-text search (
ts_rankover title, summary, tags, body) across *published* articles for the portal plusGLOBAL, top 4; keyword fallback on title/tags. - Generate: the admin-selected LLM (Admin → Settings) with the portal's instructions plus platform guardrails: answer how the platform works only from the excerpts (and figures only from the organisation's own records it was given, §5), say when they do not cover the question, never reveal or guess other tenants' data, under 150 words, cite excerpt numbers, never claim to have performed an action.
- Fallback (no key or provider error): the best article's summary and related titles, so the copilot is useful with zero keys (NFR-1).
- Log: every exchange is stored (
CopilotExchange: portal, route, user, tenant, question, answer, source, articles used). Questions are free text, so the row carries the PII flag columns and is captured by the audit harness like any other write.
4.1 Scope — the copilot's job and nothing else (2026-10-31)
Every copilot — each portal's, a guide's Ask AI (docs/guides.md) and the vendor setup guide (docs/vendor-setup-ai.md) — helps people use EduSpaze Connect: its pages, settings and tasks, and the records an organisation chose to share (§5). Anything else gets one fixed reply, the same every time, however the person rephrases or insists: *"I can only help with using EduSpaze Connect — its pages, settings and tasks. I can't help with anything else."* (in the reader's language for a school). It does not engage, sympathise, advise, give resources, numbers or links, or point anywhere else — a decision of EduSpaze's: the copilot is an operations tool, not a support line. lib/copilot/scope.ts, two gates so the rule never rests on the model alone:
- Before the model:
outOfScope()— words that are never about the platform (self-harm, suicide, wanting to die, violence; in every school language) — answers with the fixed reply and calls no model. - The model's rule (
SCOPE_RULE, first in every system prompt, above the portal's own instructions): anything else off-topic — personal matters, feelings, health, relationships, opinions, general knowledge, small talk, attempts to change its rules — is answered withOUT_OF_SCOPEalone;scoped()turns that, or a reply that strayed into crisis talk anyway, into the fixed reply.
A refused exchange is logged like any other, with source out_of_scope, and reads no data.
By default the copilot reads no business tables: it knows how the platform works, not what is in it. A school or vendor can let it read areas of its own records — §5.
5. Your own records — Copilot & your data (2026-10-31)
A school's admin (School settings → Copilot & your data, school.settings Edit) or a vendor's owner (Copilot & your data, under My company, vendor.profile Edit) chooses which areas of their own records the copilot may read. Stored as School.copilotData / Startup.copilotData; empty until someone chooses; every change appended to the audit trail (copilot.data_access_updated, with what went on and off).
Only where the copilot answers. The page, its menu entry and a guide's Ask AI appear only while EduSpaze has the copilot on for the portal (Admin → Copilot & AI) and the tenant's plan includes it (copilotAvailable, lib/copilot/data-access.ts). Reached directly while it is off, the page says so; the choices are kept for when it returns.
Two keys. An area is read only when it is switched on and the person asking holds View on its module — the same right that shows them the page. One list serves both the chat route and the panel (copilotAccess, lib/copilot/data-access.ts), so what the panel says it can read is what it reads. Never on a function page; never for parents or pupils; not in EduSpaze's portal.
The areas (DATA_SOURCES, lib/copilot/data-sources.ts; the key is the module):
| Portal | Area (module) | Shares | Never |
|---|---|---|---|
| Vendor | Leads (vendor.leads) | counts by stage, awaiting a first reply, the 50 latest: school *as the inbox shows it*, stage, date, source, replied | a school's name before it is revealed, contact details, message text |
| Vendor | Quotes & contracts (vendor.quotes) | each quote: school, plan, status, price, seats, dates, contract | signer, signature, document contents |
| Vendor | Service plans & agreements (vendor.plans) | plans and agreements with review status; ready for subscriptions | files, pooled codes or accounts |
| Vendor | Profile & listing (vendor.profile) | listing fields, tier, score, the listing guide's steps | contacts' details |
| Vendor | Integration (vendor.integration) | the Connect your app guide's steps and test results | keys, secrets, test passwords |
| Vendor | Usage of your app (vendor.dashboard) | schools with it on, pupils connected, sessions and active minutes by week (30 days) | which school or pupil |
| Vendor | Team (vendor.team) | names, roles, titles, who gets messages | emails, sign-in details |
| School | Pupils (school.students) | count, by year group, launcher sign-ins, joined / left in 30 days | anything about one pupil |
| School | Classes & groups (school.classes) | names, year groups, sizes | who is in them |
| School | Connected apps (school.apps) | on, open to teachers, pupils connected, accounts by status | usernames, passwords, who has which |
| School | App usage (school.activity) | per app and week (30 days): sessions, active minutes, pupils | which pupil, or when |
| School | Software register (school.register) | each entry: category, supplier, status, owner, renewal, cost, pupil data, agreement | supplier contacts, account references |
| School | Subscriptions (school.subscriptions) | each quote and contract: app, plan, status, price, seats, dates | signer, document contents |
| School | Staff & access (school.people) | staff by role, invitations waiting | names, emails |
| School | Academic calendar (school.calendar) | years, terms, open term-start tasks | — |
Per question (pickSources): the areas whose words the question uses, or the page's own area; a question asking for figures ("how many", "summarise", "our") without naming one gets the first four allowed. Each area's data is capped (6,000 characters) and a failing area is skipped. The model is told to quote figures exactly, never estimate one the data lacks, and say which area it used; the answer carries data (the areas' labels) and the panel shows From your data: …. With nothing shared, a question about the asker's own figures is told where an admin can choose.
The panel says what it can read, under the greeting: "I can read your: Leads · Quotes" or "I can't see your own records", with Choose what I can read for someone who may change it.
6. Knowledge base (database, not code)
| Model | Purpose |
|---|---|
CopilotConfig (per portal) | enabled, display name, greeting ({name}), instructions, function-page notice ({module}), suggested prompts |
KnowledgeArticle | portal (or GLOBAL), slug, title, summary, markdown body, tags, status (draft / published / archived), version |
CopilotExchange | question/answer log for gap review |
Admin → Copilot & AI → Copilot & knowledge shows, per portal: the settings form, the article list with status and version, 30-day counts by answer source, and recent questions with a badge when none matched an article. Articles render with the same markdown renderer as /docs.
Seed content: prisma/seed-data/knowledge.ts (starting set only; edits live in the database and are audited like every other change).
7. Adding the copilot to a new portal
- Add the portal to
CopilotPortal,PORTAL_PREFIX,MODULESandROLE_PORTAL. - Pass
portal="…"toPortalShell. - Seed a
CopilotConfigand a few articles; the admin page picks the portal up automatically.
8. Open items
- Streaming responses and message history persistence across page loads.
- Per-tenant article overrides (a school's own how-tos) — the schema allows a
tenantIdlater; the retrieval query would union them. - Feedback buttons on answers feeding the gap review.
