Class AssistantWebSocket

java.lang.Object
ecmwf.ecpds.master.plugin.http.AssistantWebSocket

@WebSocket public class AssistantWebSocket extends Object
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

    Constructors
    Constructor
    Description
    AssistantWebSocket(javax.servlet.http.HttpSession httpSession)
    Constructs a WebSocket instance bound to the given HTTP session.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onClose(int statusCode, String reason)
    Called when the WebSocket is closed.
    void
    onConnect(org.eclipse.jetty.websocket.api.Session session)
    Called when the WebSocket is connected.
    void
    Called on WebSocket error.
    void
    onMessage(String message)
    Called when a message is received from the client.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      @OnWebSocketMessage public void onMessage(String message)
      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

      @OnWebSocketClose public void onClose(int statusCode, String reason)
      Called when the WebSocket is closed.
      Parameters:
      statusCode - the close status code
      reason - the reason for closure
    • onError

      @OnWebSocketError public void onError(Throwable error)
      Called on WebSocket error.
      Parameters:
      error - the thrown error