Documentation
¶
Overview ¶
Package waterfall 提供泛型中间件链(Waterfall)原语。
对齐上游:packages/core/waterfall
设计动机:
- omnix 的 agent/pre-step / agent/request / tools/pre-execute / tools/execute / tools/post-execute / tools/result 以及 approval / plan / goal 注入等所有"多级拦截"场景 都遵循同一套洋葱模型:中间件按注册顺序依次进入,可改写 payload,可决定是否放行到下一级;
- 本包用一套泛型实现复用所有场景,避免为每种拦截点各写一套链式调用代码。
语义约定:
- Handler 收到共享 payload 指针与 next();调用 next() 表示放行到下一级, 不调用 next() 即短路(链在此终止);
- next() 返回下游错误,中间件可吞掉、改写或继续向上传播;
- next() 同一中间件内只允许调用一次(重复调用 panic,防止逻辑错误);
- Handler 在调用 next() 之后仍可继续执行(洋葱后置处理),实现 pre/post 双层拦截。
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 是一条已排序的中间件链。
func (*Chain[T]) Run ¶
Run 从链首开始执行整条链。
- 任一中间件返回 error → 立即终止并返回该错误;
- 任一中间件未调用 next() → 短路,返回 nil(或该中间件自己的返回值)。
func (*Chain[T]) RunSafe ¶
RunSafe 同 Run,但将链执行过程中可能抛出的 panic 转为错误返回。 用于与外部回调(如用户注入的工具实现)交互的边界,避免单个 panic 拖垮整个 turn。
func (*Chain[T]) RunWithTerminal ¶
RunWithTerminal runs a per-call terminal inside the middleware chain without mutating it.
Click to show internal directories.
Click to hide internal directories.