stream

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChannelLLM       = "llm"
	ChannelFlow      = "flow"
	ChannelTools     = "tools"
	ChannelMessages  = "messages"
	ChannelLifecycle = "lifecycle"
	ChannelCustom    = "custom"
)

Variables

This section is empty.

Functions

func Interleave

func Interleave(frames ...<-chan Frame) <-chan Frame

Interleave merges multiple ordered frame channels into a single channel. Merging is round-robin across non-empty channels, falling back to Seq ordering when all channels have pending frames.

func Only

func Only(in <-chan Frame, channels ...string) <-chan Frame

Only returns a channel that forwards only frames whose Channel is in the allowed set. The custom channel always passes through.

func ValidateChannel

func ValidateChannel(name string) error

ValidateChannel returns an error if name is outside the canonical set.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer accumulates tokens and flushes on sentence boundary or timeout.

func NewBuffer

func NewBuffer(onFlush func(Frame), source string, timeout time.Duration) *Buffer

NewBuffer creates a streaming buffer that flushes via onFlush callback. Flush emits an llm-channel Frame with accumulated content.

func (*Buffer) Close

func (b *Buffer) Close()

Close flushes remaining content and stops the timer.

func (*Buffer) Write

func (b *Buffer) Write(token string)

Write appends a token to the buffer and flushes on sentence boundary.

type ErrInvalidChannel

type ErrInvalidChannel struct {
	Channel string
}

ErrInvalidChannel is returned when a channel name is not in the canonical set.

func (*ErrInvalidChannel) Error

func (e *ErrInvalidChannel) Error() string

type Frame

type Frame struct {
	Channel string
	Type    string
	Content string
	Event   string
	Source  string
	Seq     uint64
}

Frame represents a fine-grained streaming event emitted during agent execution.

func Turn

func Turn(ctx context.Context, ch <-chan Frame) ([]Frame, error)

Turn reads frames from ch until the current conversational turn ends. A turn ends when a lifecycle frame with Event "completed" is received (indicating the LLM call + tool calls loop finished). Returns all frames collected during the turn.

type RingBuffer

type RingBuffer struct {
	// contains filtered or unexported fields
}

RingBuffer is a non-blocking frame delivery channel with bounded capacity. Send never blocks. If the buffer is full, the oldest frame is dropped. Receive blocks when the buffer is empty.

func NewRingBuffer

func NewRingBuffer(cap int) *RingBuffer

NewRingBuffer creates a RingBuffer with the given capacity. Panics if cap < 1.

func (*RingBuffer) Chan

func (rb *RingBuffer) Chan() <-chan Frame

Chan returns a channel that receives frames from the ring buffer. The channel is closed when the ring buffer is closed and drained.

func (*RingBuffer) Close

func (rb *RingBuffer) Close()

Close closes the buffer. Pending frames can still be received.

func (*RingBuffer) Receive

func (rb *RingBuffer) Receive() (Frame, bool)

Receive returns the next frame, blocking if empty. Returns false if the buffer is closed and empty.

func (*RingBuffer) Send

func (rb *RingBuffer) Send(f Frame)

Send sends a frame non-blocking. Drops oldest if buffer is full.

Jump to

Keyboard shortcuts

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