Class AssistantWebSocket
java.lang.Object
ecmwf.ecpds.master.plugin.http.AssistantWebSocket
WebSocket endpoint for streaming AI assistant interactions to clients.
Supports bidirectional communication between the client and AssistantService. Each WebSocket maintains a
conversation per HTTP session, streams AI-generated tokens in real time, and supports cancellation and heartbeat
pings.
Features:
- Streaming tokens from AI assistant to client
- Maintains per-session chat history
- Heartbeat pings to prevent WebSocket timeouts
- Context-aware AI queries using JSON context
- Graceful cancellation on disconnect or error
- Token batching to reduce message overhead
-
Constructor Summary
ConstructorsConstructorDescriptionAssistantWebSocket(javax.servlet.http.HttpSession httpSession) Constructs a WebSocket instance bound to the given HTTP session. -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled when the WebSocket is closed.voidonConnect(org.eclipse.jetty.websocket.api.Session session) Called when the WebSocket is connected.voidCalled on WebSocket error.voidCalled when a message is received from the client.
-
Constructor Details
-
AssistantWebSocket
public AssistantWebSocket(javax.servlet.http.HttpSession httpSession) Constructs a WebSocket instance bound to the given HTTP session.- Parameters:
httpSession- the HTTP session for maintaining conversation state
-
-
Method Details
-
onConnect
@OnWebSocketConnect public void onConnect(org.eclipse.jetty.websocket.api.Session session) Called when the WebSocket is connected.Schedules periodic token flush and heartbeat ping tasks, and sets idle timeout.
- Parameters:
session- the connected WebSocket session
-
onMessage
Called when a message is received from the client.Expected JSON format:
{ "question": "user question", "context": { ... optional AI context ... } }Supports cancellation messages:{ "type": "cancel" }- Parameters:
message- the raw JSON message from the client
-
onClose
Called when the WebSocket is closed.- Parameters:
statusCode- the close status codereason- the reason for closure
-
onError
Called on WebSocket error.- Parameters:
error- the thrown error
-