Skip to main content

AquaGPT — AI Assistant

The in-app AI assistant — a streaming, multi-agent chatbot that answers natural-language questions about your water data ("Analyse my water balance and share insights", "Show current water consumption across all meters").

  • Route: /aquagpt (in every app) → AquaAi (libs/aquaAi/src/AquaAi.jsx)
  • Permission: AQUAGPT (gates the sidebar entry — the route itself is unwrapped; see Permissions)
  • Library: libs/aquaAi/ — the live implementation
One feature, three libraries

"AquaGPT" is the product/route name; the live experience is served by libs/aquaAi/ (its header just reads "AI"). Two other AI libs exist but are not wired to any route — see Variants & legacy.


Which AI library is which

LibraryStatusWhere it runsWhat it is
aquaAiCurrent/aquagpt in all 5 appsStreaming multi-agent chatbot (this page)
aquagptLegacyNot routed (build alias only)First-gen, non-streaming chatbot with saved history
demoAquaGptDemoNot routed (demo alias only)Dummy-data sales prototype

How a message flows

Summary: The assistant talks to a separate AI-Agent microservice (not the main API). Your message is streamed over Server-Sent Events; the backend orchestrates several agents and streams their progress as thought cards, then streams the final answer token-by-token as markdown.


Backend & auth (it's a separate service)

AquaAi does not use the shared apiClient or the raw-JWT Authorization header. It calls a dedicated AI-Agent backend (Urls.getAIAgentBaseUrl(), always the Azure prod service) with fetch, using a session established from your AquaGen login:

EndpointMethodPurpose
/auth/token-loginPOSTCreate an AI session from your AquaGen loginResponse (on mount)
/auth/validatePOSTRevalidate a cached session (ecogpt_session)
/chat/streamPOST (SSE)Send a message and stream the agent run + answer
/feedbackPOSTSubmit a 👍 / 👎 on an answer
/auth/logoutPOSTEnd the session (on unmount)

A X-Source-Host header (the current hostname) tells the backend which app / industry context the question belongs to.


Components

ComponentWhat it isOn click
ComposerMultiline input (4000-char limit) with a live counterSend / Enter → streams the message
Header"AI" logo + actionsStop aborts the stream; New Chat resets the conversation
MessageListGroups messages; shows the welcome screen when empty
WelcomeScreenEmpty state with example promptsA prompt card sends that question
UserBubbleYour message + relative timestamp
AssistantBubbleThe streamed markdown answer (tables, code)Copy, Like, Dislike (feedback)
ThoughtCardCollapsible timeline of live agent activityExpand/collapse; a search chip opens a web search

Edge cases & guards

CaseHandling
Not logged in"Please login to AquaGen first" (needs a valid loginResponse token)
Initializing"Initializing AI…" spinner until the session is ready
Empty / too-long messageRejected (empty; > 4000 chars)
While answeringThinking shimmer + thought cards; a blinking cursor during token streaming
Send failure / abortAborts silently on Stop; other errors surface as an error message + error thought card
Conversation historyNone — there is no history API; New Chat wipes the session's messages

Underlying libraries

PurposeLibrary
Markdown answersreact-markdown + remark-gfm
Code highlightingreact-syntax-highlighter
Relative timesdate-fns (note: this lib uses date-fns, not the app-standard moment)
Streamingnative fetch + ReadableStream (no AI SDK)

Variants & legacy

aquagptLegacy (orphaned)

The first-generation AquaGPT chatbot: a sidebar of past conversations, non-streaming answers via the shared apiClient (gpt/aqua, gpt/responses/ndays), emoji reactions, and typing animation. Not imported by any route — only referenced in build aliases. Superseded by aquaAi.

demoAquaGptDemo (orphaned)

A sales/demo prototype built on canned dummy data (dummyData/previousChat.js, previousMessages.js). It posts an OpenAI-style chat-completions payload to a dev endpoint. Not routed anywhere — the demo app's /aquagpt route also renders the live aquaAi.


Code reference

FileRole
AquaAi.jsxPage entry + provider
store/AquaAiStore.jsxContext + reducer (messages, thought cards, session)
dataSource/authService.js · chatService.jsSession auth + SSE streaming
controller/useChatStream.js · useSessionManager.jsSend/parse messages; auto session login
components/ChatWindow.jsx + bubbles/cardsThe chat UI