The website chat assistant
The public assistant on the school website. Who can call it, what it can look up, how it sends an enquiry, and what it streams back.
Visitors to the school website can chat with an assistant named after the school, for example Example Secondary School AI. It answers from the school's published knowledge base and, when someone sounds like a future parent, offers to have the office call them back.
It is a different system from Rover. It runs inside the API server, not the worker. It has three tools, no staff data, and no memory between visits.
Who can call it
Two routes, both under /api/v1/public-ai. Neither takes a user token. Both take a school API key from API tokens, and the key decides which school's data is used.
| Method and path | operationId | Returns |
|---|---|---|
GET /public-ai/config | publicAiConfig | The school name, logo, brand colour, assistant name, and intro, so a widget can draw itself before the first message |
POST /public-ai/chat | publicAiChat | The reply, streamed as server-sent events |
Both accept a secret or a publishable key. A publishable key only works from one of its allowed origins. Otherwise the answer is 403. A missing, revoked, or unknown key is 401.
ApiKeyRateLimitGuard allows 60 requests a minute per key. A publishable key also gets 10 a minute per visitor IP. A secret key skips the IP limit, because its calls come from the school's own server, not a visitor's browser. Over either limit, the answer is 429. The counters are kept in Redis.
The website calls these routes from the visitor's browser, so publicAiCors answers any origin's preflight on /api/v1/public-ai/ and never allows credentials. The key guard then decides whether that origin may use the key.
config is cached by the browser for five minutes (Cache-Control: private, max-age=300). The assistant name falls back to the school name plus AI when the school has not set one.
Sending a message
The body is the whole conversation so far, oldest first:
{
"messages": [
{ "role": "user", "content": "What are the fees for S1?" }
]
}There must be 1 to 50 messages, each at most 4,000 characters, and the last must be from the user. Otherwise the answer is 400 with The last message must be from the user. The server keeps only the last 50 even if more arrive. The website's client trims to 50 before it sends.
Nothing is stored. The server does not save the conversation, and the website sends the full history each time.
What streams back
The response is text/event-stream. Each data: line is one JSON event:
| Event | Meaning |
|---|---|
{ "type": "text", "delta": "..." } | The next piece of the reply |
{ "type": "tool", "name": "...", "status": "started" } | The assistant started a tool. The widget can show that it is looking something up |
{ "type": "tool", "name": "...", "status": "finished" } | That tool returned |
{ "type": "error", "message": "Something went wrong. Please try again." } | The turn failed |
{ "type": "done" } | Always the last event, after success or failure |
The HTTP status is 200 even when the turn fails, because the stream has already started. Read the events, not the status. If the visitor closes the page, the run is cancelled and no error event is sent.
What the assistant can do
buildPublicAiTools gives the model up to three tools:
| Tool | What it does | When it fails |
|---|---|---|
search_knowledge_base | Hybrid search over public knowledge-base documents only, 5 results by default, at most 10 | Returns Search is not available right now. |
get_knowledge_base_document | Reads one document in full by id. A document that is not public is treated as missing | Returns This document is not available. |
create_enquiry | Sends an enquiry to the school office with name, phone, subject, message, and optionally email and class. Returns the enquiry reference | Returns The enquiry could not be sent. |
A tool never throws to the model. Every failure becomes one of those plain sentences, and the real error is logged.
create_enquiry is only offered when the school's admissions feature is on, because EnquiryService.create refuses enquiries when it is off. The enquiry it creates is the same kind a website form creates, and it appears in the staff enquiries list. See Enquiries.
How it is told to behave
buildPublicAiPrompt builds the instructions for each turn from the school's name, campuses, contact email and phone, and the assistant name and intro in the school's settings. In short, the instructions tell the model four things.
- Search first. Search before answering any factual question about fees, dates, requirements, or rules. Never guess one.
- Treat a joining question as a new family. Treat anyone who asks about joining as a possible new family, and offer a call back without pressure.
- Collect contact details slowly. Ask for a name and phone number one question at a time, read a one-line summary back, and call
create_enquiryonly after the visitor agrees. - Keep answers short. Answer in plain English, without repeating itself.
When the school has no phone or email in its settings, the prompt makes the call back the main way to reach the school.
The model name is PUBLIC_AI_MODEL. When that is empty the config falls back to OPENAI_MODEL. This client was not re-opened, so this page does not say which host that call uses. Rover's own chat models are on Config and environment.
On the website
The widget is app/components/naalya-chat/widget.tsx, mounted in app/routes/_layout.tsx, so it appears on every page that uses the main layout. Its client in app/lib/naalya-chat/client.ts fetches config once, sends the trimmed history to chat, and reads the stream. Website setup is on The API client.
Sources
Read in code, not run against a live model.
Naalya-APIatfbb63d5178bcfe171292daebb19b6cbdac025a44:apps/server/src/app/public-ai/public-ai.controller.ts,public-ai.service.ts(streamTurn,HISTORY_LIMIT,configForTenant,setupForTenant),public-ai.tools.ts,public-ai.events.ts(mapAgentStream),public-ai.prompt.ts,public-ai.cors.ts,dto/public-ai-chat.dto.ts(LastMessageFromUser),apps/server/src/app/api-key/guards/api-key-rate-limit.guard.ts(PER_KEY,PER_IP), andlibs/shared/src/config/env.config.ts(PUBLIC_AI_MODEL).Naalya-Websiteatd96eec937d68d801c4b0f22ac45ac83e85c1c129:app/lib/naalya-chat/client.ts(HISTORY_LIMIT),app/components/naalya-chat/widget.tsx,app/routes/_layout.tsx.
AI helpers on staff screens
The small one-shot AI calls behind buttons like Suggest, Triage, and Rewrite, and the rule they all follow.
Knowledge base
Staff-written school docs, embedded in a worker and searched with pgvector plus full-text, fused by reciprocal rank. Used by Rover, applicants and the social agent.