Skip to content

WebChat ​

WebChat is OpenPollen's built-in web chat channel, providing a real-time conversation interface with streaming responses.

Configuration ​

Enable WebChat in openpollen.json:

json5
{
  "channels": {
    "webchat": {
      "enabled": true,
      "port": 3001,
      "assistantName": "OpenPollen"
    }
  }
}
FieldTypeDefaultDescription
enabledbooleantrueEnable WebChat
portnumber3001HTTP + WebSocket service port
assistantNamestringOpenPollenAssistant name shown in UI

Architecture ​

WebChat uses WebSocket for bidirectional communication:

Browser UI  ←→  WebSocket  ←→  WebchatAdapter  ←→  MessageRouter  ←→  Agent

Connection Flow ​

  1. Client accesses the WebChat page via HTTP
  2. Page establishes a WebSocket connection
  3. Server performs protocol handshake (Protocol v3)
  4. On success, returns connId and supported methods
  5. Client sends RPC requests, server returns responses or events

WebSocket Protocol ​

OpenPollen WebChat uses a custom RPC protocol (v3) with three frame types:

Request Frame

json
{
  "type": "req",
  "id": "unique-id",
  "method": "chat.send",
  "params": { "text": "Hello" }
}

Response Frame

json
{
  "type": "res",
  "id": "unique-id",
  "ok": true,
  "payload": {}
}

Event Frame

json
{
  "type": "event",
  "event": "chat.delta",
  "payload": {
    "runId": "...",
    "state": "delta",
    "message": {
      "role": "assistant",
      "content": [{ "type": "text", "text": "Hello!" }]
    }
  }
}

Chat Event States ​

StateDescription
deltaStreaming output chunk
finalComplete response
errorError occurred
abortedUser interrupted

Error Codes ​

CodeDescription
INVALID_FRAMEInvalid frame format
METHOD_NOT_FOUNDMethod does not exist
UNAVAILABLEService unavailable
INTERNALInternal error
BAD_PARAMSInvalid parameters
ABORT_FAILEDAbort failed
SESSION_NOT_FOUNDSession not found

Features ​

  • Streaming responses: Agent replies pushed to browser in real-time
  • Session management: Supports /new, /resume commands
  • Heartbeat: Tick events sent every 30 seconds
  • Abort support: Users can cancel Agent execution mid-stream
  • History: Chat history persisted via Memory system