Help us shape the future of Go! Take the 2026 Go Developer Survey

stream

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package stream bridges provider event channels to Bubble Tea commands.

Providers emit events on a <-chan provider.Event channel. Bubble Tea requires commands (tea.Cmd) that return tea.Msg values. This package provides the glue between the two.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrainToString

func DrainToString(ch <-chan provider.Event) (string, error)

DrainToString reads all events from a channel synchronously and returns the concatenated text. Used by one-shot CLI mode where no TUI is running. Returns the full response and the first error encountered (if any).

func NextEvent

func NextEvent(ch <-chan provider.Event) tea.Cmd

NextEvent returns a tea.Cmd that reads one event from the channel and converts it to the appropriate tea.Msg.

The returned Cmd should be chained: after handling a TokenMsg, schedule another NextEvent() to read the next token. Stop chaining on DoneMsg or ErrorMsg.

Usage in your Update():

case stream.TokenMsg:
    m.response += msg.Content
    return m, stream.NextEvent(m.eventChan)
case stream.DoneMsg:
    // done — don't chain
case stream.ErrorMsg:
    // handle error — don't chain

Types

type DoneMsg

type DoneMsg struct{}

DoneMsg signals that the provider has finished generating.

type ErrorMsg

type ErrorMsg struct {
	Err error
}

ErrorMsg carries an error from the provider stream.

type StatusMsg

type StatusMsg struct {
	Content string
}

StatusMsg carries a provider status update (e.g. "thinking…").

type TokenMsg

type TokenMsg struct {
	Content string
}

TokenMsg carries a single streamed text token from the provider.

Jump to

Keyboard shortcuts

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