Chat Stream
ngx-prompt-kit original — not part of ibelick/prompt-kit
readChatStream() reduces an SSE chat stream — tokens, tool calls/results, done/error — into handler callbacks and resolves with the terminal result. You supply an adapt() from your backend's payload shape, so it works over any tool-calling backend.
Examples
Reduce a stream
Runs readChatStream() over a simulated HttpClient event stream: tokens accumulate, tool calls/results are recorded, and the done payload resolves the promise.
import { readChatStream } from 'ngx-prompt-kit/streaming';
const result = await readChatStream(events$, (data) => {
const p = JSON.parse(data);
if (p.type === 'chunk') return { kind: 'token', text: p.text };
if (p.type === 'done') return { kind: 'done', result: p.result };
return null;
}, { onToken: (t) => stream.append(t) });Installation
readChatStream() ships with the streaming utility.
ng generate ngx-prompt-kit:streaming