Skip to main content
The EnclaveJS streaming protocol enables real-time communication between clients and the execution runtime. It uses NDJSON (Newline Delimited JSON) for efficient streaming with optional end-to-end encryption.

Protocol Overview

Event Types

session_init

Sent when a session starts:

stdout

Captured console output:

log

Structured log messages:

tool_call

Request for tool execution:

tool_result_applied

Confirmation that tool result was applied:

heartbeat

Keep-alive message:

final

Session completed:

error

Execution error:

NDJSON Format

Events are sent as newline-delimited JSON:
Benefits:
  • Streaming-friendly - Parse events as they arrive
  • Memory efficient - No buffering entire response
  • Simple parsing - Split by newline, parse each line

Tool Call Flow

When the runtime needs to call a tool:

Submitting Tool Results

End-to-End Encryption

Optional encryption using ECDH key exchange + AES-256-GCM:

Key Exchange

Encrypted Events

Configuration

Reconnection

The protocol supports reconnection with event replay:

Sequence Tracking

Events include sequence numbers for ordering:
On reconnection, the client sends the last received sequence number to resume from that point.

Event Filtering

Filter events to reduce bandwidth:

Protocol Constants