flowneer 0.9.5 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -117,6 +117,7 @@ type StepFilter = string[] | ((meta: StepMeta) => boolean);
117
117
  interface FlowHooks<S = any, P extends Record<string, unknown> = Record<string, unknown>> {
118
118
  /** Fires once before the first step runs. */
119
119
  beforeFlow?: (shared: S, params: P) => void | Promise<void>;
120
+ /** Fires before each step body executes. Respects `StepFilter` when registered via `_setHooks`. */
120
121
  beforeStep?: (meta: StepMeta, shared: S, params: P) => void | Promise<void>;
121
122
  /**
122
123
  * Wraps step execution — call `next()` to invoke the step body.
@@ -124,13 +125,21 @@ interface FlowHooks<S = any, P extends Record<string, unknown> = Record<string,
124
125
  * Multiple `wrapStep` registrations are composed innermost-first.
125
126
  */
126
127
  wrapStep?: (meta: StepMeta, next: () => Promise<void>, shared: S, params: P) => Promise<void>;
128
+ /** Fires after each step body completes successfully. Respects `StepFilter` when registered via `_setHooks`. */
127
129
  afterStep?: (meta: StepMeta, shared: S, params: P) => void | Promise<void>;
128
130
  /**
129
131
  * Wraps individual functions within a `.parallel()` step.
130
132
  * `fnIndex` is the position within the fns array.
131
133
  */
132
134
  wrapParallelFn?: (meta: StepMeta, fnIndex: number, next: () => Promise<void>, shared: S, params: P) => Promise<void>;
135
+ /**
136
+ * Fires when a step throws, before the error is re-thrown.
137
+ * Use for logging or writing error details to `shared` — do not suppress the error here;
138
+ * use `wrapStep` with a try/catch for recovery instead.
139
+ * Respects `StepFilter` when registered via `_setHooks`.
140
+ */
133
141
  onError?: (meta: StepMeta, error: unknown, shared: S, params: P) => void | Promise<void>;
142
+ /** Fires once after the last step completes (or after a flow error). Not affected by `StepFilter`. */
134
143
  afterFlow?: (shared: S, params: P) => void | Promise<void>;
135
144
  /**
136
145
  * Fires after each loop iteration completes. `iteration` is zero-based.
@@ -143,6 +152,14 @@ interface FlowHooks<S = any, P extends Record<string, unknown> = Record<string,
143
152
  */
144
153
  onAnchorHit?: (anchorName: string, shared: S, params: P) => void | Promise<void>;
145
154
  }
155
+ /**
156
+ * The `this` type inside every plugin method. Extends the public `FlowBuilder`
157
+ * with `_setHooks` so plugins can register lifecycle hooks without casting to
158
+ * `any`.
159
+ */
160
+ type PluginContext = FlowBuilder<any, any> & {
161
+ _setHooks(hooks: Partial<FlowHooks<any, any>>, filter?: StepFilter): () => void;
162
+ };
146
163
  /**
147
164
  * A plugin is an object whose keys become methods on a `FlowBuilder.extend()` subclass prototype.
148
165
  * Each method receives the builder as `this` and should return `this` for chaining.
@@ -154,7 +171,7 @@ interface FlowHooks<S = any, P extends Record<string, unknown> = Record<string,
154
171
  * }
155
172
  * ```
156
173
  */
157
- type FlowneerPlugin = Record<string, (this: FlowBuilder<any, any>, ...args: any[]) => any>;
174
+ type FlowneerPlugin = Record<string, (this: PluginContext, ...args: any[]) => any>;
158
175
  type ResolvedHooks<S, P extends Record<string, unknown>> = {
159
176
  beforeFlow: NonNullable<FlowHooks<S, P>["beforeFlow"]>[];
160
177
  beforeStep: NonNullable<FlowHooks<S, P>["beforeStep"]>[];
@@ -302,6 +319,25 @@ declare class CoreFlowBuilder<S = any, P extends Record<string, unknown> = Recor
302
319
  transparent?: boolean;
303
320
  }): void;
304
321
  private _hooks;
322
+ /**
323
+ * Register lifecycle hooks on this flow instance at runtime.
324
+ *
325
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
326
+ * intended for consumers — app code, tests, or request-scoped instrumentation
327
+ * that needs to observe or modify a specific flow instance without defining a
328
+ * plugin.
329
+ *
330
+ * Returns a `dispose` function that removes the registered hooks when called.
331
+ *
332
+ * @example
333
+ * const dispose = flow.addHooks(
334
+ * { beforeStep: (meta) => console.log("->", meta.label) },
335
+ * ["llm:*"],
336
+ * );
337
+ * await flow.run(shared);
338
+ * dispose(); // removes the hooks
339
+ */
340
+ addHooks(hooks: Partial<FlowHooks<S, P>>, filter?: StepFilter): () => void;
305
341
  /**
306
342
  * Register lifecycle hooks (called by plugin methods, not by consumers).
307
343
  * Returns a dispose function that removes these hooks when called.
@@ -432,4 +468,4 @@ declare class FlowBuilder<S = any, P extends Record<string, unknown> = Record<st
432
468
  private _addFn;
433
469
  }
434
470
 
435
- export { type AnchorStep as A, type BatchStep as B, CoreFlowBuilder as C, type DagStep as D, FlowBuilder as F, type LoopStep as L, type NodeFn as N, type ParallelStep as P, type ResolvedHooks as R, type StepFilter as S, type Validator as V, type FlowneerPlugin as a, type NodeOptions as b, type FlowHooks as c, type StepMeta as d, type AugmentedState as e, type BranchStep as f, type FnStep as g, type NumberOrFn as h, type RunOptions as i, type Step as j, type StepContext as k, type StepHandler as l, type StreamEvent as m };
471
+ export { type AnchorStep as A, type BatchStep as B, CoreFlowBuilder as C, type DagStep as D, FlowBuilder as F, type LoopStep as L, type NodeFn as N, type ParallelStep as P, type ResolvedHooks as R, type StepFilter as S, type Validator as V, type FlowneerPlugin as a, type NodeOptions as b, type FlowHooks as c, type StepMeta as d, type AugmentedState as e, type BranchStep as f, type FnStep as g, type NumberOrFn as h, type PluginContext as i, type RunOptions as j, type Step as k, type StepContext as l, type StepHandler as m, type StreamEvent as n };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { F as FlowBuilder, c as FlowHooks, a as FlowneerPlugin, N as NodeFn, b as NodeOptions, h as NumberOrFn, i as RunOptions, d as StepMeta, m as StreamEvent, V as Validator } from './FlowBuilder-Bvf_nDeb.js';
1
+ export { F as FlowBuilder, c as FlowHooks, a as FlowneerPlugin, N as NodeFn, b as NodeOptions, h as NumberOrFn, j as RunOptions, d as StepMeta, n as StreamEvent, V as Validator } from './FlowBuilder-CwBQDOEN.js';
2
2
  export { Fragment, fragment } from './src/index.js';
3
3
  export { F as FlowError, I as InterruptError } from './errors-u-hq7p5N.js';
package/dist/index.js CHANGED
@@ -162,6 +162,27 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
162
162
  _hooks() {
163
163
  return this._hooksCache ??= buildHookCache(this._hooksList);
164
164
  }
165
+ /**
166
+ * Register lifecycle hooks on this flow instance at runtime.
167
+ *
168
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
169
+ * intended for consumers — app code, tests, or request-scoped instrumentation
170
+ * that needs to observe or modify a specific flow instance without defining a
171
+ * plugin.
172
+ *
173
+ * Returns a `dispose` function that removes the registered hooks when called.
174
+ *
175
+ * @example
176
+ * const dispose = flow.addHooks(
177
+ * { beforeStep: (meta) => console.log("->", meta.label) },
178
+ * ["llm:*"],
179
+ * );
180
+ * await flow.run(shared);
181
+ * dispose(); // removes the hooks
182
+ */
183
+ addHooks(hooks, filter) {
184
+ return this._setHooks(hooks, filter);
185
+ }
165
186
  /**
166
187
  * Register lifecycle hooks (called by plugin methods, not by consumers).
167
188
  * Returns a dispose function that removes these hooks when called.
@@ -1,4 +1,4 @@
1
- import { F as FlowBuilder, a as FlowneerPlugin } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { F as FlowBuilder, a as FlowneerPlugin } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  interface HumanNodeOptions<S = any, P extends Record<string, unknown> = Record<string, unknown>> {
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { a as FlowneerPlugin, N as NodeFn, b as NodeOptions, S as StepFilter } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { a as FlowneerPlugin, N as NodeFn, b as NodeOptions, S as StepFilter } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  declare module "../../Flowneer" {
4
4
  interface FlowBuilder<S, P> {
@@ -1,4 +1,4 @@
1
- import { F as FlowBuilder } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { F as FlowBuilder } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  /** Case-insensitive exact match. Returns 1.0 or 0.0. */
4
4
  declare function exactMatch(predicted: string, expected: string): number;
@@ -1,4 +1,4 @@
1
- import { a as FlowneerPlugin, N as NodeFn, b as NodeOptions } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { a as FlowneerPlugin, N as NodeFn, b as NodeOptions } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  /** A single node entry in the exported graph. */
4
4
  interface GraphNodeExport {
@@ -162,6 +162,27 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
162
162
  _hooks() {
163
163
  return this._hooksCache ??= buildHookCache(this._hooksList);
164
164
  }
165
+ /**
166
+ * Register lifecycle hooks on this flow instance at runtime.
167
+ *
168
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
169
+ * intended for consumers — app code, tests, or request-scoped instrumentation
170
+ * that needs to observe or modify a specific flow instance without defining a
171
+ * plugin.
172
+ *
173
+ * Returns a `dispose` function that removes the registered hooks when called.
174
+ *
175
+ * @example
176
+ * const dispose = flow.addHooks(
177
+ * { beforeStep: (meta) => console.log("->", meta.label) },
178
+ * ["llm:*"],
179
+ * );
180
+ * await flow.run(shared);
181
+ * dispose(); // removes the hooks
182
+ */
183
+ addHooks(hooks, filter) {
184
+ return this._setHooks(hooks, filter);
185
+ }
165
186
  /**
166
187
  * Register lifecycle hooks (called by plugin methods, not by consumers).
167
188
  * Returns a dispose function that removes these hooks when called.
@@ -11,7 +11,7 @@ export { parseJsonOutput, parseListOutput, parseMarkdownTable, parseRegexOutput
11
11
  export { Span, TelemetryDaemon, TelemetryExporter, TelemetryOptions, consoleExporter, otlpExporter, withTelemetry } from './telemetry/index.js';
12
12
  export { EvalResult, EvalSummary, ScoreFn, answerRelevance, containsMatch, exactMatch, f1Score, retrievalPrecision, retrievalRecall, runEvalSuite } from './eval/index.js';
13
13
  export { GraphEdge, GraphNode, withGraph } from './graph/index.js';
14
- import { S as StepFilter, a as FlowneerPlugin, d as StepMeta, F as FlowBuilder } from '../FlowBuilder-Bvf_nDeb.js';
14
+ import { S as StepFilter, a as FlowneerPlugin, d as StepMeta, F as FlowBuilder } from '../FlowBuilder-CwBQDOEN.js';
15
15
  import { F as FlowError } from '../errors-u-hq7p5N.js';
16
16
  export { validate } from './config/index.js';
17
17
  export { F as FlowConfig, a as FnRegistry, S as StepConfig, V as ValidationError, b as ValidationResult } from '../schema-CIqQAXqY.js';
@@ -256,6 +256,27 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
256
256
  _hooks() {
257
257
  return this._hooksCache ??= buildHookCache(this._hooksList);
258
258
  }
259
+ /**
260
+ * Register lifecycle hooks on this flow instance at runtime.
261
+ *
262
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
263
+ * intended for consumers — app code, tests, or request-scoped instrumentation
264
+ * that needs to observe or modify a specific flow instance without defining a
265
+ * plugin.
266
+ *
267
+ * Returns a `dispose` function that removes the registered hooks when called.
268
+ *
269
+ * @example
270
+ * const dispose = flow.addHooks(
271
+ * { beforeStep: (meta) => console.log("->", meta.label) },
272
+ * ["llm:*"],
273
+ * );
274
+ * await flow.run(shared);
275
+ * dispose(); // removes the hooks
276
+ */
277
+ addHooks(hooks, filter) {
278
+ return this._setHooks(hooks, filter);
279
+ }
259
280
  /**
260
281
  * Register lifecycle hooks (called by plugin methods, not by consumers).
261
282
  * Returns a dispose function that removes these hooks when called.
@@ -1,4 +1,4 @@
1
- import { S as StepFilter, a as FlowneerPlugin, V as Validator } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { S as StepFilter, a as FlowneerPlugin, V as Validator } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  declare module "../../Flowneer" {
4
4
  interface FlowBuilder<S, P> {
@@ -1,4 +1,4 @@
1
- import { a as FlowneerPlugin } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { a as FlowneerPlugin } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  /** A single message in conversational memory. */
4
4
  interface MemoryMessage {
@@ -1,4 +1,4 @@
1
- import { a as FlowneerPlugin } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { a as FlowneerPlugin } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  /** Send a message to a named channel on `shared.__channels`. */
4
4
  declare function sendTo<S extends Record<string, any>>(shared: S, channel: string, message: unknown): void;
@@ -1,4 +1,4 @@
1
- import { S as StepFilter, a as FlowneerPlugin, d as StepMeta } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { S as StepFilter, a as FlowneerPlugin, d as StepMeta } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  declare module "../../Flowneer" {
4
4
  interface FlowBuilder<S, P> {
@@ -1,4 +1,4 @@
1
- import { V as Validator } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { V as Validator } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  /**
4
4
  * Extract and parse JSON from a (possibly noisy) LLM response.
@@ -1,4 +1,4 @@
1
- import { d as StepMeta, S as StepFilter, a as FlowneerPlugin } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { d as StepMeta, S as StepFilter, a as FlowneerPlugin } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  /**
4
4
  * Events that can trigger a checkpoint save.
@@ -1,4 +1,4 @@
1
- import { N as NodeFn, S as StepFilter, a as FlowneerPlugin } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { N as NodeFn, S as StepFilter, a as FlowneerPlugin } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  declare module "../../Flowneer" {
4
4
  interface FlowBuilder<S, P> {
@@ -1,4 +1,4 @@
1
- import { c as FlowHooks, a as FlowneerPlugin } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { c as FlowHooks, a as FlowneerPlugin } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  interface Span {
4
4
  traceId: string;
@@ -1,4 +1,4 @@
1
- import { a as FlowneerPlugin } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { a as FlowneerPlugin } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  /** Describes a single parameter for a tool. */
4
4
  interface ToolParam {
@@ -1,4 +1,4 @@
1
- import { a as FlowneerPlugin, N as NodeFn, F as FlowBuilder } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { a as FlowneerPlugin, N as NodeFn, F as FlowBuilder } from '../../FlowBuilder-CwBQDOEN.js';
2
2
  import { ToolCall, ToolResult, ToolParam, Tool, ToolRegistry } from '../../plugins/tools/index.js';
3
3
 
4
4
  /**
@@ -212,6 +212,27 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
212
212
  _hooks() {
213
213
  return this._hooksCache ??= buildHookCache(this._hooksList);
214
214
  }
215
+ /**
216
+ * Register lifecycle hooks on this flow instance at runtime.
217
+ *
218
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
219
+ * intended for consumers — app code, tests, or request-scoped instrumentation
220
+ * that needs to observe or modify a specific flow instance without defining a
221
+ * plugin.
222
+ *
223
+ * Returns a `dispose` function that removes the registered hooks when called.
224
+ *
225
+ * @example
226
+ * const dispose = flow.addHooks(
227
+ * { beforeStep: (meta) => console.log("->", meta.label) },
228
+ * ["llm:*"],
229
+ * );
230
+ * await flow.run(shared);
231
+ * dispose(); // removes the hooks
232
+ */
233
+ addHooks(hooks, filter) {
234
+ return this._setHooks(hooks, filter);
235
+ }
215
236
  /**
216
237
  * Register lifecycle hooks (called by plugin methods, not by consumers).
217
238
  * Returns a dispose function that removes these hooks when called.
@@ -1,5 +1,5 @@
1
1
  import { S as StepConfig, a as FnRegistry, b as ValidationResult, F as FlowConfig } from '../../schema-CIqQAXqY.js';
2
- import { F as FlowBuilder } from '../../FlowBuilder-Bvf_nDeb.js';
2
+ import { F as FlowBuilder } from '../../FlowBuilder-CwBQDOEN.js';
3
3
 
4
4
  /** Recursive applicator passed to nested step builders (loop body, batch processor). */
5
5
  type ApplyFn = (steps: StepConfig[], flow: FlowBuilder<any, any>, registry: FnRegistry) => void;
@@ -162,6 +162,27 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
162
162
  _hooks() {
163
163
  return this._hooksCache ??= buildHookCache(this._hooksList);
164
164
  }
165
+ /**
166
+ * Register lifecycle hooks on this flow instance at runtime.
167
+ *
168
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
169
+ * intended for consumers — app code, tests, or request-scoped instrumentation
170
+ * that needs to observe or modify a specific flow instance without defining a
171
+ * plugin.
172
+ *
173
+ * Returns a `dispose` function that removes the registered hooks when called.
174
+ *
175
+ * @example
176
+ * const dispose = flow.addHooks(
177
+ * { beforeStep: (meta) => console.log("->", meta.label) },
178
+ * ["llm:*"],
179
+ * );
180
+ * await flow.run(shared);
181
+ * dispose(); // removes the hooks
182
+ */
183
+ addHooks(hooks, filter) {
184
+ return this._setHooks(hooks, filter);
185
+ }
165
186
  /**
166
187
  * Register lifecycle hooks (called by plugin methods, not by consumers).
167
188
  * Returns a dispose function that removes these hooks when called.
@@ -2,6 +2,6 @@ export { AgentState, ChatMessage, CreateAgentOptions, EvaluatorOptimizerOptions,
2
2
  export { ApplyFn, ConfigValidationError, CustomStepBuilder, JsonFlowBuilder, StepConfigBuilder } from './config/index.js';
3
3
  export { IterativeRagOptions, RagOptions, iterativeRag, ragPipeline } from './rag/index.js';
4
4
  export { ApprovalGateOptions, ClarifyLoopOptions, GenerateUntilValidOptions, MapReduceOptions, approvalGate, clarifyLoop, generateUntilValid, mapReduceLlm } from './pipeline/index.js';
5
- import '../FlowBuilder-Bvf_nDeb.js';
5
+ import '../FlowBuilder-CwBQDOEN.js';
6
6
  import '../plugins/tools/index.js';
7
7
  import '../schema-CIqQAXqY.js';
@@ -212,6 +212,27 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
212
212
  _hooks() {
213
213
  return this._hooksCache ??= buildHookCache(this._hooksList);
214
214
  }
215
+ /**
216
+ * Register lifecycle hooks on this flow instance at runtime.
217
+ *
218
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
219
+ * intended for consumers — app code, tests, or request-scoped instrumentation
220
+ * that needs to observe or modify a specific flow instance without defining a
221
+ * plugin.
222
+ *
223
+ * Returns a `dispose` function that removes the registered hooks when called.
224
+ *
225
+ * @example
226
+ * const dispose = flow.addHooks(
227
+ * { beforeStep: (meta) => console.log("->", meta.label) },
228
+ * ["llm:*"],
229
+ * );
230
+ * await flow.run(shared);
231
+ * dispose(); // removes the hooks
232
+ */
233
+ addHooks(hooks, filter) {
234
+ return this._setHooks(hooks, filter);
235
+ }
215
236
  /**
216
237
  * Register lifecycle hooks (called by plugin methods, not by consumers).
217
238
  * Returns a dispose function that removes these hooks when called.
@@ -1,4 +1,4 @@
1
- import { N as NodeFn, F as FlowBuilder } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { N as NodeFn, F as FlowBuilder } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  interface GenerateUntilValidOptions<S = any, P extends Record<string, unknown> = Record<string, unknown>> {
4
4
  /**
@@ -162,6 +162,27 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
162
162
  _hooks() {
163
163
  return this._hooksCache ??= buildHookCache(this._hooksList);
164
164
  }
165
+ /**
166
+ * Register lifecycle hooks on this flow instance at runtime.
167
+ *
168
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
169
+ * intended for consumers — app code, tests, or request-scoped instrumentation
170
+ * that needs to observe or modify a specific flow instance without defining a
171
+ * plugin.
172
+ *
173
+ * Returns a `dispose` function that removes the registered hooks when called.
174
+ *
175
+ * @example
176
+ * const dispose = flow.addHooks(
177
+ * { beforeStep: (meta) => console.log("->", meta.label) },
178
+ * ["llm:*"],
179
+ * );
180
+ * await flow.run(shared);
181
+ * dispose(); // removes the hooks
182
+ */
183
+ addHooks(hooks, filter) {
184
+ return this._setHooks(hooks, filter);
185
+ }
165
186
  /**
166
187
  * Register lifecycle hooks (called by plugin methods, not by consumers).
167
188
  * Returns a dispose function that removes these hooks when called.
@@ -1,4 +1,4 @@
1
- import { N as NodeFn, F as FlowBuilder } from '../../FlowBuilder-Bvf_nDeb.js';
1
+ import { N as NodeFn, F as FlowBuilder } from '../../FlowBuilder-CwBQDOEN.js';
2
2
 
3
3
  interface RagOptions<S = any, P extends Record<string, unknown> = Record<string, unknown>> {
4
4
  /** Retrieves relevant documents/chunks and writes them to shared state. */
@@ -162,6 +162,27 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
162
162
  _hooks() {
163
163
  return this._hooksCache ??= buildHookCache(this._hooksList);
164
164
  }
165
+ /**
166
+ * Register lifecycle hooks on this flow instance at runtime.
167
+ *
168
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
169
+ * intended for consumers — app code, tests, or request-scoped instrumentation
170
+ * that needs to observe or modify a specific flow instance without defining a
171
+ * plugin.
172
+ *
173
+ * Returns a `dispose` function that removes the registered hooks when called.
174
+ *
175
+ * @example
176
+ * const dispose = flow.addHooks(
177
+ * { beforeStep: (meta) => console.log("->", meta.label) },
178
+ * ["llm:*"],
179
+ * );
180
+ * await flow.run(shared);
181
+ * dispose(); // removes the hooks
182
+ */
183
+ addHooks(hooks, filter) {
184
+ return this._setHooks(hooks, filter);
185
+ }
165
186
  /**
166
187
  * Register lifecycle hooks (called by plugin methods, not by consumers).
167
188
  * Returns a dispose function that removes these hooks when called.
@@ -1,5 +1,5 @@
1
- import { F as FlowBuilder } from '../FlowBuilder-Bvf_nDeb.js';
2
- export { A as AnchorStep, e as AugmentedState, B as BatchStep, f as BranchStep, C as CoreFlowBuilder, D as DagStep, c as FlowHooks, a as FlowneerPlugin, g as FnStep, L as LoopStep, N as NodeFn, b as NodeOptions, h as NumberOrFn, P as ParallelStep, R as ResolvedHooks, i as RunOptions, j as Step, k as StepContext, S as StepFilter, l as StepHandler, d as StepMeta, m as StreamEvent, V as Validator } from '../FlowBuilder-Bvf_nDeb.js';
1
+ import { F as FlowBuilder } from '../FlowBuilder-CwBQDOEN.js';
2
+ export { A as AnchorStep, e as AugmentedState, B as BatchStep, f as BranchStep, C as CoreFlowBuilder, D as DagStep, c as FlowHooks, a as FlowneerPlugin, g as FnStep, L as LoopStep, N as NodeFn, b as NodeOptions, h as NumberOrFn, P as ParallelStep, i as PluginContext, R as ResolvedHooks, j as RunOptions, k as Step, l as StepContext, S as StepFilter, m as StepHandler, d as StepMeta, n as StreamEvent, V as Validator } from '../FlowBuilder-CwBQDOEN.js';
3
3
  export { F as FlowError, I as InterruptError } from '../errors-u-hq7p5N.js';
4
4
 
5
5
  /**
package/dist/src/index.js CHANGED
@@ -162,6 +162,27 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
162
162
  _hooks() {
163
163
  return this._hooksCache ??= buildHookCache(this._hooksList);
164
164
  }
165
+ /**
166
+ * Register lifecycle hooks on this flow instance at runtime.
167
+ *
168
+ * Unlike plugin methods (which use `_setHooks` internally), `addHooks` is
169
+ * intended for consumers — app code, tests, or request-scoped instrumentation
170
+ * that needs to observe or modify a specific flow instance without defining a
171
+ * plugin.
172
+ *
173
+ * Returns a `dispose` function that removes the registered hooks when called.
174
+ *
175
+ * @example
176
+ * const dispose = flow.addHooks(
177
+ * { beforeStep: (meta) => console.log("->", meta.label) },
178
+ * ["llm:*"],
179
+ * );
180
+ * await flow.run(shared);
181
+ * dispose(); // removes the hooks
182
+ */
183
+ addHooks(hooks, filter) {
184
+ return this._setHooks(hooks, filter);
185
+ }
165
186
  /**
166
187
  * Register lifecycle hooks (called by plugin methods, not by consumers).
167
188
  * Returns a dispose function that removes these hooks when called.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowneer",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "description": "Zero-dependency fluent flow builder for AI agents",
5
5
  "license": "MIT",
6
6
  "type": "module",