Skip to content

WebSocket

OpenMotoko uses WebSocket for real-time communication between the API server and clients (web UI, channel adapters, external integrations).

ws://localhost:3457/ws

Connect with either:

  • Session cookie: same cookie from POST /api/auth/login
  • Token query parameter: ws://localhost:3457/ws?token=your-session-token

Unauthenticated connections are rejected.

const ws = new WebSocket('ws://localhost:3457/ws')
ws.onopen = () => {
console.log('Connected')
}
ws.onmessage = (event) => {
const data = JSON.parse(event.data)
console.log(data.type, data)
}
ws.onclose = () => {
console.log('Disconnected')
}

All events follow this structure:

{
"type": "event:name",
"timestamp": 1700000000000,
"...fields": "specific to event type"
}
EventFieldsDescription
message:receivedconversationId, role, contentUser message received
message:sentconversationId, role, contentAgent message sent
EventFieldsDescription
llm:streamconversationId, chunkStreaming token chunk
llm:completeconversationId, tokens, costGeneration complete
EventFieldsDescription
tool:calledconversationId, toolName, argsTool invocation started
tool:resultconversationId, toolName, resultTool returned result
EventFieldsDescription
cost:updatedconversationId, provider, model, costToken cost recorded
EventFieldsDescription
skill:activatedskillId, conversationIdSkill was used
EventFieldsDescription
channel:messagechannelId, channelType, contentMessage from external channel
EventFieldsDescription
scheduler:startedtaskId, taskNameTask execution began
scheduler:completedtaskId, taskName, durationTask finished
scheduler:failedtaskId, taskName, errorTask errored
EventFieldsDescription
artifact:createdartifactId, conversationId, title, artifactTypeNew artifact
artifact:updatedartifactId, conversationId, title, versionArtifact modified
EventFieldsDescription
agent:spawnedagentId, parentId, name, modelSub-agent created
agent:completedagentId, parentId, name, output, durationMsSub-agent done
agent:failedagentId, parentId, name, output, durationMsSub-agent errored
EventFieldsDescription
intent:createdintentId, summary, requiresApprovalAction intent created
intent:resolvedintentId, statusIntent approved/rejected
EventFieldsDescription
config:changedtimestampConfiguration was updated