waterfall

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package waterfall provides generic middleware chains matching core/waterfall. Agent, tool, approval, plan, and goal interception share an onion model: handlers run in registration order, may modify a shared payload, and control continuation. Calling next enters downstream middleware; omitting it short-circuits. Handlers may transform downstream errors and run post-processing after next returns. Each handler may call next only once; repeated calls panic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain[T any] struct {
	// contains filtered or unexported fields
}

Chain is an ordered middleware chain.

func New

func New[T any](handlers ...Handler[T]) *Chain[T]

New builds a chain in the supplied order. Even an empty chain uses a nonnil slice so later Use calls do not mistake it for an uninitialized zero value.

func (*Chain[T]) Run

func (c *Chain[T]) Run(ctx context.Context, payload *T) error

Run starts at the first handler. Errors stop execution; omitting next short-circuits with the handler's own return value.

func (*Chain[T]) RunSafe

func (c *Chain[T]) RunSafe(ctx context.Context, payload *T) (err error)

RunSafe converts chain panics into errors. Use it at external callback boundaries so one injected tool panic cannot crash the whole turn.

func (*Chain[T]) RunWithTerminal

func (c *Chain[T]) RunWithTerminal(ctx context.Context, payload *T, terminal NextFunc) error

RunWithTerminal runs a per-call terminal inside the middleware chain without mutating it.

func (*Chain[T]) Use

func (c *Chain[T]) Use(handlers ...Handler[T]) *Chain[T]

Use appends middleware during construction and panics on a zero-value Chain. Callers must not mutate a chain concurrently with execution.

type Handler

type Handler[T any] func(payload *T, next NextFunc) error

Handler receives a shared mutable payload and next. Omitting next short-circuits; a returned error terminates the chain and is returned to Run's caller.

type NextFunc

type NextFunc func() error

NextFunc invokes downstream middleware and returns its error, or nil on success.

Jump to

Keyboard shortcuts

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