Skip to main content
OpenHarness integrates with AI SDK 5’s data stream protocol, so you can stream agent sessions directly to useChat-based React and Vue UIs.

toResponse()

Both Session and Conversation provide two methods for streaming to the client:
  • toUIMessageStream(input) — returns a ReadableStream<UIMessageChunk> that maps session events to AI SDK 5 typed chunks
  • toResponse(input, options) — wraps the stream in an HTTP Response with SSE headers, ready to return from any route handler

Next.js Example

app/api/chat/route.ts

Resumable Streams

The direct toResponse(input, { signal: req.signal }) pattern is enough for simple request-bound chat. For resumable chat, the server must decouple the active run from the HTTP response:
  • POST starts or attaches to a server-owned run for the chat id.
  • Client disconnect removes only that subscriber; it should not abort the run.
  • GET ${endpoint}/${id}/stream returns the active stream, or 204 when no stream is running.
  • Cancellation should be a separate server-side action.
React and Vue clients can enable reconnects with resume: true and customize the GET endpoint with prepareReconnectToStreamRequest.

Custom Data Parts

The stream emits all standard AI SDK 5 chunk types (text-delta, reasoning-delta, tool-input-available, tool-output-available, start, finish, etc.) plus custom OpenHarness data parts for subagent activity, compaction, retry, and turn lifecycle:

Using Data Part Types

If you’re building custom UI components that consume the stream directly, the core package exports typed data part types and guards: