flowneer 0.9.0 → 0.9.1

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.
Files changed (38) hide show
  1. package/dist/{FlowBuilder-B_BIRk3f.d.ts → FlowBuilder-CqWK42bA.d.ts} +2 -2
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +14 -11
  4. package/dist/plugins/agent/index.d.ts +1 -1
  5. package/dist/plugins/config/index.d.ts +2 -2
  6. package/dist/plugins/dev/index.d.ts +37 -2
  7. package/dist/plugins/dev/index.js +32 -0
  8. package/dist/plugins/eval/index.d.ts +1 -1
  9. package/dist/plugins/graph/index.d.ts +1 -1
  10. package/dist/plugins/index.d.ts +2 -2
  11. package/dist/plugins/index.js +157 -127
  12. package/dist/plugins/llm/index.d.ts +4 -4
  13. package/dist/plugins/llm/index.js +47 -38
  14. package/dist/plugins/memory/index.d.ts +1 -1
  15. package/dist/plugins/messaging/index.d.ts +1 -1
  16. package/dist/plugins/observability/index.d.ts +4 -4
  17. package/dist/plugins/observability/index.js +41 -32
  18. package/dist/plugins/output/index.d.ts +1 -1
  19. package/dist/plugins/persistence/index.d.ts +4 -4
  20. package/dist/plugins/persistence/index.js +56 -47
  21. package/dist/plugins/resilience/index.d.ts +3 -3
  22. package/dist/plugins/resilience/index.js +38 -32
  23. package/dist/plugins/telemetry/index.d.ts +1 -1
  24. package/dist/plugins/tools/index.d.ts +1 -1
  25. package/dist/presets/agent/index.d.ts +1 -1
  26. package/dist/presets/agent/index.js +14 -11
  27. package/dist/presets/config/index.d.ts +25 -11
  28. package/dist/presets/config/index.js +75 -103
  29. package/dist/presets/index.d.ts +4 -4
  30. package/dist/presets/index.js +152 -103
  31. package/dist/presets/pipeline/index.d.ts +165 -2
  32. package/dist/presets/pipeline/index.js +91 -11
  33. package/dist/presets/rag/index.d.ts +1 -1
  34. package/dist/presets/rag/index.js +14 -11
  35. package/dist/{schema-DFNzcQP5.d.ts → schema-CIqQAXqY.d.ts} +10 -1
  36. package/dist/src/index.d.ts +2 -2
  37. package/dist/src/index.js +14 -11
  38. package/package.json +1 -1
@@ -238,8 +238,8 @@ declare class CoreFlowBuilder<S = any, P extends Record<string, unknown> = Recor
238
238
  * The base class prototype is never touched, so different `extend()`
239
239
  * calls are fully isolated from each other.
240
240
  *
241
- * Plugins are applied in array order; later entries can override earlier
242
- * ones for the same method name.
241
+ * Duplicate method names across plugins (or colliding with an existing
242
+ * prototype method) throw immediately to prevent silent overwrites.
243
243
  *
244
244
  * @example
245
245
  * const AppFlow = FlowBuilder.extend([withTiming, withRateLimit]);
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, g as NumberOrFn, h as RunOptions, d as StepMeta, l as StreamEvent, V as Validator } from './FlowBuilder-B_BIRk3f.js';
1
+ export { F as FlowBuilder, c as FlowHooks, a as FlowneerPlugin, N as NodeFn, b as NodeOptions, g as NumberOrFn, h as RunOptions, d as StepMeta, l as StreamEvent, V as Validator } from './FlowBuilder-CqWK42bA.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
@@ -23,15 +23,13 @@ var InterruptError = class extends Error {
23
23
  // src/core/utils.ts
24
24
  function matchesFilter(filter, meta) {
25
25
  if (!Array.isArray(filter)) return filter(meta);
26
- if (meta.label === void 0) return false;
27
26
  const label = meta.label;
28
- return filter.some((pattern) => {
29
- if (!pattern.includes("*")) return pattern === label;
30
- const re = new RegExp(
31
- "^" + pattern.split("*").map((s) => s.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*") + "$"
32
- );
33
- return re.test(label);
34
- });
27
+ if (label === void 0) return false;
28
+ return filter.some(
29
+ (p) => p.includes("*") ? new RegExp(
30
+ "^" + p.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*") + "$"
31
+ ).test(label) : p === label
32
+ );
35
33
  }
36
34
  function resolveNumber(val, fallback, shared, params) {
37
35
  if (val === void 0) return fallback;
@@ -166,8 +164,8 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
166
164
  * The base class prototype is never touched, so different `extend()`
167
165
  * calls are fully isolated from each other.
168
166
  *
169
- * Plugins are applied in array order; later entries can override earlier
170
- * ones for the same method name.
167
+ * Duplicate method names across plugins (or colliding with an existing
168
+ * prototype method) throw immediately to prevent silent overwrites.
171
169
  *
172
170
  * @example
173
171
  * const AppFlow = FlowBuilder.extend([withTiming, withRateLimit]);
@@ -179,11 +177,16 @@ var CoreFlowBuilder = class _CoreFlowBuilder {
179
177
  static extend(plugins) {
180
178
  const Extended = class extends this {
181
179
  };
180
+ const methods = {};
182
181
  for (const plugin of plugins) {
183
182
  for (const [name, fn] of Object.entries(plugin)) {
184
- Extended.prototype[name] = fn;
183
+ if (name in methods || name in Extended.prototype) {
184
+ throw new Error(`Plugin method collision: "${name}"`);
185
+ }
186
+ methods[name] = fn;
185
187
  }
186
188
  }
189
+ Object.assign(Extended.prototype, methods);
187
190
  return Extended;
188
191
  }
189
192
  // -------------------------------------------------------------------------
@@ -1,4 +1,4 @@
1
- import { F as FlowBuilder, a as FlowneerPlugin } from '../../FlowBuilder-B_BIRk3f.js';
1
+ import { F as FlowBuilder, a as FlowneerPlugin } from '../../FlowBuilder-CqWK42bA.js';
2
2
 
3
3
  interface HumanNodeOptions<S = any, P extends Record<string, unknown> = Record<string, unknown>> {
4
4
  /**
@@ -1,5 +1,5 @@
1
- import { a as FnRegistry, b as ValidationResult } from '../../schema-DFNzcQP5.js';
2
- export { A as AnchorStepConfig, B as BatchStepConfig, c as BranchStepConfig, F as FlowConfig, d as FnStepConfig, L as LoopStepConfig, P as ParallelStepConfig, S as StepConfig, V as ValidationError } from '../../schema-DFNzcQP5.js';
1
+ import { a as FnRegistry, b as ValidationResult } from '../../schema-CIqQAXqY.js';
2
+ export { A as AnchorStepConfig, B as BatchStepConfig, c as BranchStepConfig, F as FlowConfig, d as FnStepConfig, L as LoopStepConfig, P as ParallelStepConfig, S as StepConfig, V as ValidationError } from '../../schema-CIqQAXqY.js';
3
3
 
4
4
  /**
5
5
  * Validate a raw config object + registry without building anything.
@@ -1,4 +1,4 @@
1
- import { a as FlowneerPlugin, N as NodeFn, b as NodeOptions } from '../../FlowBuilder-B_BIRk3f.js';
1
+ import { a as FlowneerPlugin, N as NodeFn, b as NodeOptions, S as StepFilter } from '../../FlowBuilder-CqWK42bA.js';
2
2
 
3
3
  declare module "../../Flowneer" {
4
4
  interface FlowBuilder<S, P> {
@@ -130,4 +130,39 @@ declare module "../../Flowneer" {
130
130
  }
131
131
  declare const withFlowAnalyzer: FlowneerPlugin;
132
132
 
133
- export { type PathMap, type PathNode, type TraceEvent, type TraceHandle, type TraceReport, withAtomicUpdates, withDryRun, withFlowAnalyzer, withMocks, withStepLimit };
133
+ interface DebuggerHooks {
134
+ /** Pause before a step runs. Default: `true`. */
135
+ beforeStep?: boolean;
136
+ /** Pause after a step completes. Default: `false`. */
137
+ afterStep?: boolean;
138
+ /** Pause when a step throws. Default: `false`. */
139
+ onError?: boolean;
140
+ /** Pause once before the step body and once after (inside the wrapper). Default: `false`. */
141
+ wrapStep?: boolean;
142
+ }
143
+ declare module "../../Flowneer" {
144
+ interface FlowBuilder<S, P> {
145
+ /**
146
+ * Drops a `debugger` statement at the selected lifecycle points.
147
+ * Attach DevTools / `--inspect` breakpoints and step through live flow state.
148
+ *
149
+ * @param filter Limit to specific steps by label or predicate (optional).
150
+ * @param hooks Which lifecycle points to pause at. Defaults to `{ beforeStep: true }`.
151
+ *
152
+ * @example
153
+ * // Pause before every step
154
+ * new AppFlow().withDebugger().then(myStep).run(shared);
155
+ *
156
+ * @example
157
+ * // Pause only on "llm:*" steps, before and after
158
+ * new AppFlow()
159
+ * .withDebugger(["llm:*"], { beforeStep: true, afterStep: true })
160
+ * .then(callLlm)
161
+ * .run(shared);
162
+ */
163
+ withDebugger(filter?: StepFilter, hooks?: DebuggerHooks): this;
164
+ }
165
+ }
166
+ declare const withDebugger: FlowneerPlugin;
167
+
168
+ export { type DebuggerHooks, type PathMap, type PathNode, type TraceEvent, type TraceHandle, type TraceReport, withAtomicUpdates, withDebugger, withDryRun, withFlowAnalyzer, withMocks, withStepLimit };
@@ -179,8 +179,40 @@ var withFlowAnalyzer = {
179
179
  };
180
180
  }
181
181
  };
182
+
183
+ // plugins/dev/withDebugger.ts
184
+ var withDebugger = {
185
+ withDebugger(filter, hooks = { beforeStep: true }) {
186
+ const registered = {};
187
+ if (hooks.beforeStep) {
188
+ registered.beforeStep = (meta, shared, params) => {
189
+ debugger;
190
+ };
191
+ }
192
+ if (hooks.afterStep) {
193
+ registered.afterStep = (meta, shared, params) => {
194
+ debugger;
195
+ };
196
+ }
197
+ if (hooks.onError) {
198
+ registered.onError = (meta, error, shared, params) => {
199
+ debugger;
200
+ };
201
+ }
202
+ if (hooks.wrapStep) {
203
+ registered.wrapStep = async (meta, next, shared, params) => {
204
+ debugger;
205
+ await next();
206
+ debugger;
207
+ };
208
+ }
209
+ this._setHooks(registered, filter);
210
+ return this;
211
+ }
212
+ };
182
213
  export {
183
214
  withAtomicUpdates,
215
+ withDebugger,
184
216
  withDryRun,
185
217
  withFlowAnalyzer,
186
218
  withMocks,
@@ -1,4 +1,4 @@
1
- import { F as FlowBuilder } from '../../FlowBuilder-B_BIRk3f.js';
1
+ import { F as FlowBuilder } from '../../FlowBuilder-CqWK42bA.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-B_BIRk3f.js';
1
+ import { a as FlowneerPlugin, N as NodeFn, b as NodeOptions } from '../../FlowBuilder-CqWK42bA.js';
2
2
 
3
3
  /** A single node entry in the exported graph. */
4
4
  interface GraphNodeExport {
@@ -11,10 +11,10 @@ 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-B_BIRk3f.js';
14
+ import { S as StepFilter, a as FlowneerPlugin, d as StepMeta, F as FlowBuilder } from '../FlowBuilder-CqWK42bA.js';
15
15
  import { F as FlowError } from '../errors-u-hq7p5N.js';
16
16
  export { validate } from './config/index.js';
17
- export { F as FlowConfig, a as FnRegistry, S as StepConfig, V as ValidationError, b as ValidationResult } from '../schema-DFNzcQP5.js';
17
+ export { F as FlowConfig, a as FnRegistry, S as StepConfig, V as ValidationError, b as ValidationResult } from '../schema-CIqQAXqY.js';
18
18
 
19
19
  /**
20
20
  * Behaviour when a compliance violation is detected.
@@ -33,52 +33,61 @@ var init_withReplay = __esm({
33
33
 
34
34
  // plugins/observability/withTiming.ts
35
35
  var withTiming = {
36
- withTiming() {
36
+ withTiming(filter) {
37
37
  const starts = /* @__PURE__ */ new Map();
38
- this._setHooks({
39
- beforeStep: (meta) => {
40
- starts.set(meta.index, Date.now());
38
+ this._setHooks(
39
+ {
40
+ beforeStep: (meta) => {
41
+ starts.set(meta.index, Date.now());
42
+ },
43
+ afterStep: (meta, shared) => {
44
+ const start = starts.get(meta.index) ?? Date.now();
45
+ if (!shared.__timings) shared.__timings = {};
46
+ shared.__timings[meta.index] = Date.now() - start;
47
+ starts.delete(meta.index);
48
+ }
41
49
  },
42
- afterStep: (meta, shared) => {
43
- const start = starts.get(meta.index) ?? Date.now();
44
- if (!shared.__timings) shared.__timings = {};
45
- shared.__timings[meta.index] = Date.now() - start;
46
- starts.delete(meta.index);
47
- }
48
- });
50
+ filter
51
+ );
49
52
  return this;
50
53
  }
51
54
  };
52
55
 
53
56
  // plugins/observability/withHistory.ts
54
57
  var withHistory = {
55
- withHistory() {
56
- this._setHooks({
57
- afterStep: (meta, shared) => {
58
- if (!Array.isArray(shared.__history)) shared.__history = [];
59
- const { __history: _h, ...rest } = shared;
60
- shared.__history.push({
61
- index: meta.index,
62
- type: meta.type,
63
- snapshot: { ...rest }
64
- });
65
- }
66
- });
58
+ withHistory(filter) {
59
+ this._setHooks(
60
+ {
61
+ afterStep: (meta, shared) => {
62
+ if (!Array.isArray(shared.__history)) shared.__history = [];
63
+ const { __history: _h, ...rest } = shared;
64
+ shared.__history.push({
65
+ index: meta.index,
66
+ type: meta.type,
67
+ snapshot: { ...rest }
68
+ });
69
+ }
70
+ },
71
+ filter
72
+ );
67
73
  return this;
68
74
  }
69
75
  };
70
76
 
71
77
  // plugins/observability/withVerbose.ts
72
78
  var withVerbose = {
73
- withVerbose() {
74
- this._setHooks({
75
- afterStep: (meta, shared) => {
76
- console.log(
77
- `[flowneer] step ${meta.index} (${meta.type}):`,
78
- JSON.stringify(shared, null, 2)
79
- );
80
- }
81
- });
79
+ withVerbose(filter) {
80
+ this._setHooks(
81
+ {
82
+ afterStep: (meta, shared) => {
83
+ console.log(
84
+ `[flowneer] step ${meta.index} (${meta.type}):`,
85
+ JSON.stringify(shared, null, 2)
86
+ );
87
+ }
88
+ },
89
+ filter
90
+ );
82
91
  return this;
83
92
  }
84
93
  };
@@ -120,23 +129,26 @@ var withInterrupts = {
120
129
 
121
130
  // plugins/resilience/withFallback.ts
122
131
  var withFallback = {
123
- withFallback(fn) {
124
- this._setHooks({
125
- wrapStep: async (meta, next, shared, params) => {
126
- try {
127
- await next();
128
- } catch (e) {
129
- if (e instanceof InterruptError) throw e;
130
- shared.__fallbackError = {
131
- stepIndex: meta.index,
132
- stepType: meta.type,
133
- message: e instanceof Error ? e.message : String(e),
134
- stack: e instanceof Error ? e.stack : void 0
135
- };
136
- await fn(shared, params);
132
+ withFallback(fn, filter) {
133
+ this._setHooks(
134
+ {
135
+ wrapStep: async (meta, next, shared, params) => {
136
+ try {
137
+ await next();
138
+ } catch (e) {
139
+ if (e instanceof InterruptError) throw e;
140
+ shared.__fallbackError = {
141
+ stepIndex: meta.index,
142
+ stepType: meta.type,
143
+ message: e instanceof Error ? e.message : String(e),
144
+ stack: e instanceof Error ? e.stack : void 0
145
+ };
146
+ await fn(shared, params);
147
+ }
137
148
  }
138
- }
139
- });
149
+ },
150
+ filter
151
+ );
140
152
  return this;
141
153
  }
142
154
  };
@@ -176,23 +188,26 @@ var withCircuitBreaker = {
176
188
 
177
189
  // plugins/resilience/withTimeout.ts
178
190
  var withTimeout = {
179
- withTimeout(ms) {
180
- this._setHooks({
181
- wrapStep: (meta, next) => {
182
- let handle;
183
- return Promise.race([
184
- next().finally(() => clearTimeout(handle)),
185
- new Promise(
186
- (_, reject) => handle = setTimeout(
187
- () => reject(
188
- new Error(`step ${meta.index} timed out after ${ms}ms`)
189
- ),
190
- ms
191
+ withTimeout(ms, filter) {
192
+ this._setHooks(
193
+ {
194
+ wrapStep: (meta, next) => {
195
+ let handle;
196
+ return Promise.race([
197
+ next().finally(() => clearTimeout(handle)),
198
+ new Promise(
199
+ (_, reject) => handle = setTimeout(
200
+ () => reject(
201
+ new Error(`step ${meta.index} timed out after ${ms}ms`)
202
+ ),
203
+ ms
204
+ )
191
205
  )
192
- )
193
- ]);
194
- }
195
- });
206
+ ]);
207
+ }
208
+ },
209
+ filter
210
+ );
196
211
  return this;
197
212
  }
198
213
  };
@@ -240,39 +255,45 @@ var withCycles = {
240
255
 
241
256
  // plugins/persistence/withCheckpoint.ts
242
257
  var withCheckpoint = {
243
- withCheckpoint(store) {
244
- this._setHooks({
245
- afterStep: async (meta, shared) => {
246
- await store.save(meta.index, shared);
247
- }
248
- });
258
+ withCheckpoint(store, filter) {
259
+ this._setHooks(
260
+ {
261
+ afterStep: async (meta, shared) => {
262
+ await store.save(meta.index, shared);
263
+ }
264
+ },
265
+ filter
266
+ );
249
267
  return this;
250
268
  }
251
269
  };
252
270
 
253
271
  // plugins/persistence/withAuditLog.ts
254
272
  var withAuditLog = {
255
- withAuditLog(store) {
273
+ withAuditLog(store, filter) {
256
274
  const clone = (v) => JSON.parse(JSON.stringify(v));
257
- this._setHooks({
258
- afterStep: async (meta, shared) => {
259
- await store.append({
260
- stepIndex: meta.index,
261
- type: meta.type,
262
- timestamp: Date.now(),
263
- shared: clone(shared)
264
- });
275
+ this._setHooks(
276
+ {
277
+ afterStep: async (meta, shared) => {
278
+ await store.append({
279
+ stepIndex: meta.index,
280
+ type: meta.type,
281
+ timestamp: Date.now(),
282
+ shared: clone(shared)
283
+ });
284
+ },
285
+ onError: (meta, err2, shared) => {
286
+ store.append({
287
+ stepIndex: meta.index,
288
+ type: meta.type,
289
+ timestamp: Date.now(),
290
+ shared: clone(shared),
291
+ error: err2 instanceof Error ? err2.message : String(err2)
292
+ });
293
+ }
265
294
  },
266
- onError: (meta, err2, shared) => {
267
- store.append({
268
- stepIndex: meta.index,
269
- type: meta.type,
270
- timestamp: Date.now(),
271
- shared: clone(shared),
272
- error: err2 instanceof Error ? err2.message : String(err2)
273
- });
274
- }
275
- });
295
+ filter
296
+ );
276
297
  return this;
277
298
  }
278
299
  };
@@ -297,31 +318,34 @@ function diffObjects(prev, curr) {
297
318
  }
298
319
  var versionCounter = 0;
299
320
  var withVersionedCheckpoint = {
300
- withVersionedCheckpoint(store) {
321
+ withVersionedCheckpoint(store, filter) {
301
322
  let prevSnapshot = {};
302
323
  let lastVersion = null;
303
- this._setHooks({
304
- beforeFlow: (shared) => {
305
- prevSnapshot = JSON.parse(JSON.stringify(shared));
306
- lastVersion = null;
324
+ this._setHooks(
325
+ {
326
+ beforeFlow: (shared) => {
327
+ prevSnapshot = JSON.parse(JSON.stringify(shared));
328
+ lastVersion = null;
329
+ },
330
+ afterStep: async (meta, shared) => {
331
+ const curr = JSON.parse(JSON.stringify(shared));
332
+ const diff = diffObjects(prevSnapshot, curr);
333
+ if (Object.keys(diff).length === 0) return;
334
+ const version = `v${++versionCounter}`;
335
+ const entry = {
336
+ version,
337
+ stepIndex: meta.index,
338
+ diff,
339
+ parentVersion: lastVersion,
340
+ timestamp: Date.now()
341
+ };
342
+ await store.save(entry);
343
+ lastVersion = version;
344
+ prevSnapshot = curr;
345
+ }
307
346
  },
308
- afterStep: async (meta, shared) => {
309
- const curr = JSON.parse(JSON.stringify(shared));
310
- const diff = diffObjects(prevSnapshot, curr);
311
- if (Object.keys(diff).length === 0) return;
312
- const version = `v${++versionCounter}`;
313
- const entry = {
314
- version,
315
- stepIndex: meta.index,
316
- diff,
317
- parentVersion: lastVersion,
318
- timestamp: Date.now()
319
- };
320
- await store.save(entry);
321
- lastVersion = version;
322
- prevSnapshot = curr;
323
- }
324
- });
347
+ filter
348
+ );
325
349
  return this;
326
350
  },
327
351
  resumeFrom(version, store) {
@@ -344,29 +368,35 @@ var withVersionedCheckpoint = {
344
368
 
345
369
  // plugins/llm/withTokenBudget.ts
346
370
  var withTokenBudget = {
347
- withTokenBudget(limit) {
348
- this._setHooks({
349
- beforeStep: (_meta, shared) => {
350
- const used = shared.tokensUsed ?? 0;
351
- if (used >= limit) {
352
- throw new Error(`token budget exceeded: ${used} >= ${limit}`);
371
+ withTokenBudget(limit, filter) {
372
+ this._setHooks(
373
+ {
374
+ beforeStep: (_meta, shared) => {
375
+ const used = shared.tokensUsed ?? 0;
376
+ if (used >= limit) {
377
+ throw new Error(`token budget exceeded: ${used} >= ${limit}`);
378
+ }
353
379
  }
354
- }
355
- });
380
+ },
381
+ filter
382
+ );
356
383
  return this;
357
384
  }
358
385
  };
359
386
 
360
387
  // plugins/llm/withCostTracker.ts
361
388
  var withCostTracker = {
362
- withCostTracker() {
363
- this._setHooks({
364
- afterStep: (_meta, shared) => {
365
- const stepCost = shared.__stepCost ?? 0;
366
- shared.__cost = (shared.__cost ?? 0) + stepCost;
367
- delete shared.__stepCost;
368
- }
369
- });
389
+ withCostTracker(filter) {
390
+ this._setHooks(
391
+ {
392
+ afterStep: (_meta, shared) => {
393
+ const stepCost = shared.__stepCost ?? 0;
394
+ shared.__cost = (shared.__cost ?? 0) + stepCost;
395
+ delete shared.__stepCost;
396
+ }
397
+ },
398
+ filter
399
+ );
370
400
  return this;
371
401
  }
372
402
  };
@@ -1,4 +1,4 @@
1
- import { a as FlowneerPlugin, S as StepFilter, V as Validator } from '../../FlowBuilder-B_BIRk3f.js';
1
+ import { S as StepFilter, a as FlowneerPlugin, V as Validator } from '../../FlowBuilder-CqWK42bA.js';
2
2
 
3
3
  declare module "../../Flowneer" {
4
4
  interface FlowBuilder<S, P> {
@@ -6,7 +6,7 @@ declare module "../../Flowneer" {
6
6
  * Aborts the flow before any step if `shared.tokensUsed >= limit`.
7
7
  * Steps are responsible for incrementing `shared.tokensUsed`.
8
8
  */
9
- withTokenBudget(limit: number): this;
9
+ withTokenBudget(limit: number, filter?: StepFilter): this;
10
10
  }
11
11
  }
12
12
  declare const withTokenBudget: FlowneerPlugin;
@@ -17,7 +17,7 @@ declare module "../../Flowneer" {
17
17
  * Accumulates `shared.__stepCost` (set by each step) into `shared.__cost`.
18
18
  * Clears `__stepCost` after each step so it is never double-counted.
19
19
  */
20
- withCostTracker(): this;
20
+ withCostTracker(filter?: StepFilter): this;
21
21
  }
22
22
  }
23
23
  declare const withCostTracker: FlowneerPlugin;
@@ -102,7 +102,7 @@ declare module "../../Flowneer" {
102
102
  * .startWith(async (s) => { s.__llmOutput = await callLlm("..."); })
103
103
  * .then((s) => { console.log(s.__structuredOutput); });
104
104
  */
105
- withStructuredOutput<T = unknown>(validator: Validator<T>, options?: StructuredOutputOptions): this;
105
+ withStructuredOutput<T = unknown>(validator: Validator<T>, options?: StructuredOutputOptions, filter?: StepFilter): this;
106
106
  }
107
107
  }
108
108
  declare const withStructuredOutput: FlowneerPlugin;