Picadabra Docs

Streaming

Server-Sent Events for real-time data streaming.

Overview

Picadabra uses Server-Sent Events (SSE) for streaming responses. The client returns an AsyncIterable that yields events as they arrive.

client.stream()

Stream task execution with real-time updates.

const  = await .({
	: 'generate',
	: { : 'Hello, world!' },
})

for await (const  of ) {
	switch (.) {
		case 'data':
			.('Chunk:', .)
			break
		case 'error':
			.('Error:', .)
			break
		case 'done':
			.('Stream completed')
			break
	}
}

Event Types

TypeDescriptionFields
dataIncremental data chunkid?, data
errorError occurred during streamid?, error: string
doneStream completed successfullyid?

Cancellation

Use AbortController to cancel a stream:

const  = new ()

// Cancel after 5 seconds
(() => .(), 5000)

const  = await .(
	{ : 'generate', : { : 'Long task...' } },
	{ : . },
)

try {
	for await (const  of ) {
		.()
	}
} catch () {
	if ( instanceof  && . === 'AbortError') {
		.('Stream cancelled')
	}
}

Framework Integration

For React applications, see React Integration for TanStack Query integration with automatic state management.

How is this guide?