@hexos/react-coreServer-Sent Events transport implementation for agent communication.
Default transport that works through all CDNs and proxies. Implements the
AgentTransport interface using HTTP POST requests with streaming
response bodies parsed as SSE (data: \{json\}\n\n lines).
Supports dynamic headers via async functions (e.g., refreshing JWT tokens), request cancellation via AbortController, and configurable approval endpoints for human-in-the-loop workflows.
Related: AgentConfig configures the connection, useAgent creates and manages the transport instance, TransportEvent defines the event types consumed from the SSE stream.
class SSETransport implements AgentTransport {
connect(config: AgentConfig) => Promise<void>;
send(message: TransportMessage) => void;
sendApproval(decision: ApprovalDecision) => Promise<void>;
onMessage(callback: (event: TransportEvent) => void) => () => void;
disconnect() => void;
}- Implements:
AgentTransport
connect
(config: AgentConfig) => PromiseStores the agent configuration for use in subsequent requests.
send
(message: TransportMessage) => voidSends a message to the agent endpoint and begins streaming the response.
Cancels any existing in-flight request before starting a new one. The response is parsed as SSE and events are emitted to registered listeners.
sendApproval
(decision: ApprovalDecision) => PromiseSends an approval decision to the server’s approval endpoint.
Posts an ApprovalDecision to the configured approval endpoint
(defaults to endpoint + '/approve'). Supports dynamic headers.
onMessage
(callback: (event: TransportEvent) => void) => () => voidRegisters a callback to receive transport events.
disconnect
() => voidDisconnects the transport, cancelling any in-flight requests and clearing all listeners.