stream

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package stream pumps an ai.LLMProvider's iter.Seq2[ai.Event, error] into Bubble Tea messages without buffering the response: each event arrives as an EventMsg carrying the tea.Cmd that re-arms the pump for the next event (the "channel re-arm" pattern DataTug chat used for HTTP/LLM streaming). The final message is always a DoneMsg, whether the stream completed, errored, or ctx was cancelled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(ctx context.Context, id string, seq iter.Seq2[ai.Event, error]) tea.Cmd

Start begins draining seq in a goroutine — never buffering the whole response — and returns the tea.Cmd producing the first message. ctx cancellation stops the goroutine promptly and the pump.

For a cancellation to reach the underlying provider request (not just stop this local pump), seq must itself have been built from ctx — e.g. provider.Stream(ctx, req) — so an adapter observing ctx.Done() can abort its own HTTP call and yield ai.ErrCodeCanceled. chatshell.Model.StartStream does this: it hands its per-stream ctx to the caller's seq-opening func before calling Start with that same ctx.

Types

type DoneMsg

type DoneMsg struct {
	ID  string
	Err error
}

DoneMsg ends a stream started with Start: seq was fully drained (Err nil), it yielded an error (Err set to that error), or ctx was cancelled (Err set to ctx.Err()).

type EventMsg

type EventMsg struct {
	ID    string
	Event ai.Event
	Next  tea.Cmd
}

EventMsg is one normalised stream event. Next re-arms the pump: a handler must return it as (part of) its tea.Cmd to receive the following event.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL