Yolk SDK
Build guides

Stream to React

Connect a browser chat UI to a Yolk route with client and React helpers.

Use @yolk-sdk/agent/client to consume a stream, then project events into UI state with @yolk-sdk/agent/react.

Install

pnpm add @yolk-sdk/agent@canary react react-dom effect@4.2.0

Consume a route stream

import { Stream } from 'effect'
import { streamAgentEventStreamUntilTerminal } from '@yolk-sdk/agent/client'

const stream = streamAgentEventStreamUntilTerminal({
  endpoint: '/api/agent',
  sessionId: 'browser-session',
  messages
})

for await (const event of Stream.toAsyncIterable(stream)) {
  // project into UI state
}

Build replay-safe state

import { Stream } from 'effect'
import {
  applyAgentEventToChatProjection,
  makeAgentChatEventProjectionState
} from '@yolk-sdk/agent/react'
import { streamAgentEventStreamUntilTerminal } from '@yolk-sdk/agent/client'

let projection = makeAgentChatEventProjectionState()
const stream = streamAgentEventStreamUntilTerminal({
  endpoint: '/api/agent',
  sessionId: 'browser-session',
  messages
})

for await (const event of Stream.toAsyncIterable(stream)) {
  projection = applyAgentEventToChatProjection(projection, event)
}

Use projection state for durable streams where reconnect may replay overlapping events. Use simpler reducers only for ephemeral one-shot streams.

What your UI owns

Yolk is headless. You render the input, message list, attachment UX, retry state, stop button, approval prompts, and question prompts.

On this page