@q1k-oss/behaviour-tree-workflows 0.0.4 → 0.0.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.
package/dist/index.js CHANGED
@@ -1045,6 +1045,21 @@ var Conditional = class extends CompositeNode {
1045
1045
  };
1046
1046
 
1047
1047
  // src/composites/for-each.ts
1048
+ function resolveFromBlackboard(blackboard, path2) {
1049
+ const parts = path2.split(".");
1050
+ const firstPart = parts[0];
1051
+ if (!firstPart) return void 0;
1052
+ let value = blackboard.get(firstPart);
1053
+ for (let i = 1; i < parts.length && value != null; i++) {
1054
+ const part = parts[i];
1055
+ if (part && typeof value === "object") {
1056
+ value = value[part];
1057
+ } else {
1058
+ return void 0;
1059
+ }
1060
+ }
1061
+ return value;
1062
+ }
1048
1063
  var ForEach = class extends CompositeNode {
1049
1064
  collectionKey;
1050
1065
  itemKey;
@@ -1068,7 +1083,7 @@ var ForEach = class extends CompositeNode {
1068
1083
  "ForEach requires at least one child (body)"
1069
1084
  );
1070
1085
  }
1071
- const collection = context.blackboard.get(this.collectionKey);
1086
+ const collection = this.collectionKey.includes(".") ? resolveFromBlackboard(context.blackboard, this.collectionKey) : context.blackboard.get(this.collectionKey);
1072
1087
  if (!collection) {
1073
1088
  this.log(`Collection '${this.collectionKey}' not found in blackboard`);
1074
1089
  this._status = "FAILURE" /* FAILURE */;
@@ -2548,74 +2563,153 @@ var setVariableSchema = createNodeSchema("SetVariable", {
2548
2563
  value: z6.unknown()
2549
2564
  });
2550
2565
 
2551
- // src/actions/llm-tool-call.schema.ts
2566
+ // src/utilities/math-op.schema.ts
2552
2567
  import { z as z7 } from "zod";
2553
- var toolDefinitionSchema = z7.object({
2554
- name: z7.string().min(1),
2555
- description: z7.string().min(1),
2556
- inputSchema: z7.record(z7.string(), z7.unknown())
2568
+ var mathOpSchema = createNodeSchema("MathOp", {
2569
+ expression: z7.string().min(1, "expression is required"),
2570
+ outputKey: z7.string().min(1, "outputKey is required"),
2571
+ round: z7.enum(["none", "round", "floor", "ceil"]).optional(),
2572
+ precision: z7.number().int().nonnegative().optional()
2573
+ });
2574
+
2575
+ // src/utilities/array-filter.schema.ts
2576
+ import { z as z8 } from "zod";
2577
+ var filterConditionSchema = z8.object({
2578
+ field: z8.string().min(1),
2579
+ operator: z8.enum([
2580
+ "eq",
2581
+ "ne",
2582
+ "gt",
2583
+ "lt",
2584
+ "gte",
2585
+ "lte",
2586
+ "in",
2587
+ "nin",
2588
+ "exists",
2589
+ "regex",
2590
+ "between",
2591
+ "contains"
2592
+ ]),
2593
+ value: z8.unknown().optional(),
2594
+ range: z8.tuple([z8.unknown(), z8.unknown()]).optional()
2595
+ });
2596
+ var arrayFilterSchema = createNodeSchema("ArrayFilter", {
2597
+ input: z8.string().min(1, "input is required"),
2598
+ outputKey: z8.string().min(1, "outputKey is required"),
2599
+ conditions: z8.array(filterConditionSchema).min(1, "at least one condition is required"),
2600
+ logic: z8.enum(["and", "or"]).optional()
2601
+ });
2602
+
2603
+ // src/utilities/aggregate.schema.ts
2604
+ import { z as z9 } from "zod";
2605
+ var aggregateOperationSchema = z9.object({
2606
+ type: z9.enum(["count", "sum", "avg", "min", "max"]),
2607
+ field: z9.string().optional(),
2608
+ as: z9.string().optional()
2609
+ });
2610
+ var aggregateSchema = createNodeSchema("Aggregate", {
2611
+ input: z9.string().min(1, "input is required"),
2612
+ outputKey: z9.string().min(1, "outputKey is required"),
2613
+ operations: z9.array(aggregateOperationSchema).min(1, "at least one operation is required"),
2614
+ groupBy: z9.string().optional()
2615
+ });
2616
+
2617
+ // src/utilities/threshold-check.schema.ts
2618
+ import { z as z10 } from "zod";
2619
+ var thresholdLevelSchema = z10.object({
2620
+ operator: z10.enum(["lte", "lt", "gte", "gt", "eq", "ne", "between"]),
2621
+ value: z10.unknown().optional(),
2622
+ range: z10.tuple([z10.unknown(), z10.unknown()]).optional(),
2623
+ label: z10.string().min(1, "label is required")
2624
+ });
2625
+ var thresholdCheckSchema = createNodeSchema("ThresholdCheck", {
2626
+ value: z10.unknown(),
2627
+ thresholds: z10.array(thresholdLevelSchema).min(1, "at least one threshold is required"),
2628
+ outputKey: z10.string().optional(),
2629
+ failOn: z10.array(z10.string()).optional()
2630
+ });
2631
+
2632
+ // src/utilities/data-transform.schema.ts
2633
+ import { z as z11 } from "zod";
2634
+ var transformMappingSchema = z11.object({
2635
+ target: z11.string().min(1, "target is required"),
2636
+ value: z11.unknown(),
2637
+ coerce: z11.enum(["string", "number", "boolean"]).optional()
2638
+ });
2639
+ var dataTransformSchema = createNodeSchema("DataTransform", {
2640
+ outputKey: z11.string().min(1, "outputKey is required"),
2641
+ mappings: z11.array(transformMappingSchema).min(1, "at least one mapping is required"),
2642
+ wrapInArray: z11.boolean().optional()
2643
+ });
2644
+
2645
+ // src/actions/llm-tool-call.schema.ts
2646
+ import { z as z12 } from "zod";
2647
+ var toolDefinitionSchema = z12.object({
2648
+ name: z12.string().min(1),
2649
+ description: z12.string().min(1),
2650
+ inputSchema: z12.record(z12.string(), z12.unknown())
2557
2651
  });
2558
2652
  var llmToolCallSchema = createNodeSchema("LLMToolCall", {
2559
- provider: z7.enum(["anthropic", "openai", "google", "ollama"]),
2560
- model: z7.string().min(1, "Model is required"),
2561
- systemPrompt: z7.string().optional(),
2562
- messagesKey: z7.string().min(1, "messagesKey is required"),
2563
- userMessageKey: z7.string().optional(),
2564
- toolsKey: z7.string().optional(),
2565
- tools: z7.array(toolDefinitionSchema).optional(),
2566
- temperature: z7.number().min(0).max(2).optional(),
2567
- maxTokens: z7.number().int().positive().optional(),
2568
- outputKey: z7.string().min(1, "outputKey is required")
2653
+ provider: z12.enum(["anthropic", "openai", "google", "ollama"]),
2654
+ model: z12.string().min(1, "Model is required"),
2655
+ systemPrompt: z12.string().optional(),
2656
+ messagesKey: z12.string().min(1, "messagesKey is required"),
2657
+ userMessageKey: z12.string().optional(),
2658
+ toolsKey: z12.string().optional(),
2659
+ tools: z12.array(toolDefinitionSchema).optional(),
2660
+ temperature: z12.number().min(0).max(2).optional(),
2661
+ maxTokens: z12.number().int().positive().optional(),
2662
+ outputKey: z12.string().min(1, "outputKey is required")
2569
2663
  });
2570
2664
 
2571
2665
  // src/actions/tool-executor.schema.ts
2572
- import { z as z8 } from "zod";
2666
+ import { z as z13 } from "zod";
2573
2667
  var toolExecutorSchema = createNodeSchema("ToolExecutor", {
2574
- responseKey: z8.string().min(1, "responseKey is required"),
2575
- messagesKey: z8.string().min(1, "messagesKey is required"),
2576
- outputKey: z8.string().optional()
2668
+ responseKey: z13.string().min(1, "responseKey is required"),
2669
+ messagesKey: z13.string().min(1, "messagesKey is required"),
2670
+ outputKey: z13.string().optional()
2577
2671
  });
2578
2672
 
2579
2673
  // src/actions/wait-for-signal.schema.ts
2580
- import { z as z9 } from "zod";
2674
+ import { z as z14 } from "zod";
2581
2675
  var waitForSignalSchema = createNodeSchema("WaitForSignal", {
2582
- signalName: z9.string().min(1, "signalName is required"),
2583
- signalKey: z9.string().optional(),
2584
- timeoutMs: z9.number().int().positive().optional().default(864e5),
2585
- outputKey: z9.string().min(1, "outputKey is required")
2676
+ signalName: z14.string().min(1, "signalName is required"),
2677
+ signalKey: z14.string().optional(),
2678
+ timeoutMs: z14.number().int().positive().optional().default(864e5),
2679
+ outputKey: z14.string().min(1, "outputKey is required")
2586
2680
  });
2587
2681
 
2588
2682
  // src/actions/tool-router.schema.ts
2589
- import { z as z10 } from "zod";
2590
- var toolDefinitionSchema2 = z10.object({
2591
- name: z10.string().min(1),
2592
- description: z10.string().min(1),
2593
- inputSchema: z10.record(z10.string(), z10.unknown())
2683
+ import { z as z15 } from "zod";
2684
+ var toolDefinitionSchema2 = z15.object({
2685
+ name: z15.string().min(1),
2686
+ description: z15.string().min(1),
2687
+ inputSchema: z15.record(z15.string(), z15.unknown())
2594
2688
  });
2595
- var ruleSchema = z10.object({
2596
- pattern: z10.string().min(1),
2597
- toolSets: z10.array(z10.string().min(1)).min(1)
2689
+ var ruleSchema = z15.object({
2690
+ pattern: z15.string().min(1),
2691
+ toolSets: z15.array(z15.string().min(1)).min(1)
2598
2692
  });
2599
2693
  var toolRouterSchema = createNodeSchema("ToolRouter", {
2600
- intentKey: z10.string().min(1, "intentKey is required"),
2601
- toolSets: z10.record(z10.string(), z10.array(toolDefinitionSchema2)),
2602
- defaultTools: z10.array(z10.string()).optional(),
2603
- rules: z10.array(ruleSchema).optional(),
2604
- outputKey: z10.string().min(1, "outputKey is required")
2694
+ intentKey: z15.string().min(1, "intentKey is required"),
2695
+ toolSets: z15.record(z15.string(), z15.array(toolDefinitionSchema2)),
2696
+ defaultTools: z15.array(z15.string()).optional(),
2697
+ rules: z15.array(ruleSchema).optional(),
2698
+ outputKey: z15.string().min(1, "outputKey is required")
2605
2699
  });
2606
2700
 
2607
2701
  // src/decorators/streaming-sink.schema.ts
2608
- import { z as z11 } from "zod";
2702
+ import { z as z16 } from "zod";
2609
2703
  var streamingSinkSchema = createNodeSchema("StreamingSink", {
2610
- channelId: z11.string().optional(),
2611
- channelKey: z11.string().optional()
2704
+ channelId: z16.string().optional(),
2705
+ channelKey: z16.string().optional()
2612
2706
  }).refine(
2613
2707
  (data) => data.channelId || data.channelKey,
2614
2708
  { message: "Either channelId or channelKey must be provided" }
2615
2709
  );
2616
2710
 
2617
2711
  // src/schemas/validation.ts
2618
- import { z as z12 } from "zod";
2712
+ import { z as z17 } from "zod";
2619
2713
  function zodErrorToConfigurationError(error, nodeType, nodeId) {
2620
2714
  const nodeIdentifier = nodeId ? `${nodeType}:${nodeId}` : nodeType;
2621
2715
  const issues = error.issues.map((issue) => {
@@ -2631,7 +2725,7 @@ function validateConfiguration(schema, config, nodeType, nodeId) {
2631
2725
  try {
2632
2726
  return schema.parse(config);
2633
2727
  } catch (error) {
2634
- if (error instanceof z12.ZodError) {
2728
+ if (error instanceof z17.ZodError) {
2635
2729
  throw zodErrorToConfigurationError(error, nodeType, nodeId);
2636
2730
  }
2637
2731
  throw error;
@@ -2650,14 +2744,14 @@ function safeValidateConfiguration(schema, config, nodeType, nodeId) {
2650
2744
  }
2651
2745
 
2652
2746
  // src/schemas/tree-definition.schema.ts
2653
- import { z as z13 } from "zod";
2654
- var treeDefSchemaObject = z13.object({
2655
- type: z13.string().min(1, "Node type is required"),
2656
- id: z13.string().optional(),
2657
- name: z13.string().optional(),
2658
- props: z13.record(z13.string(), z13.unknown()).optional(),
2659
- children: z13.array(
2660
- z13.lazy(() => treeDefinitionSchema)
2747
+ import { z as z18 } from "zod";
2748
+ var treeDefSchemaObject = z18.object({
2749
+ type: z18.string().min(1, "Node type is required"),
2750
+ id: z18.string().optional(),
2751
+ name: z18.string().optional(),
2752
+ props: z18.record(z18.string(), z18.unknown()).optional(),
2753
+ children: z18.array(
2754
+ z18.lazy(() => treeDefinitionSchema)
2661
2755
  ).optional()
2662
2756
  });
2663
2757
  var treeDefinitionSchema = treeDefSchemaObject;
@@ -2740,6 +2834,11 @@ var SchemaRegistry = class {
2740
2834
  this.register("BrowserAgent", browserAgentSchema);
2741
2835
  this.register("HumanTask", humanTaskSchema);
2742
2836
  this.register("SetVariable", setVariableSchema);
2837
+ this.register("MathOp", mathOpSchema);
2838
+ this.register("ArrayFilter", arrayFilterSchema);
2839
+ this.register("Aggregate", aggregateSchema);
2840
+ this.register("ThresholdCheck", thresholdCheckSchema);
2841
+ this.register("DataTransform", dataTransformSchema);
2743
2842
  this.register("LLMToolCall", llmToolCallSchema);
2744
2843
  this.register("ToolExecutor", toolExecutorSchema);
2745
2844
  this.register("WaitForSignal", waitForSignalSchema);
@@ -3460,6 +3559,547 @@ var SetVariable = class extends ActionNode {
3460
3559
  }
3461
3560
  };
3462
3561
 
3562
+ // src/utilities/math-op.ts
3563
+ function tokenize(expr) {
3564
+ const tokens = [];
3565
+ let i = 0;
3566
+ while (i < expr.length) {
3567
+ const ch = expr[i];
3568
+ if (ch === " " || ch === " ") {
3569
+ i++;
3570
+ continue;
3571
+ }
3572
+ if (ch === "(" || ch === ")") {
3573
+ tokens.push({ type: ch === "(" ? "lparen" : "rparen", value: ch });
3574
+ i++;
3575
+ continue;
3576
+ }
3577
+ if (ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%") {
3578
+ const prev = tokens.length > 0 ? tokens[tokens.length - 1] : void 0;
3579
+ const isUnary = ch === "-" && (tokens.length === 0 || prev?.type === "op" || prev?.type === "lparen");
3580
+ if (isUnary) {
3581
+ let numStr = "-";
3582
+ i++;
3583
+ while (i < expr.length && isDigitOrDot(expr[i])) {
3584
+ numStr += expr[i];
3585
+ i++;
3586
+ }
3587
+ if (numStr === "-") {
3588
+ tokens.push({ type: "number", value: -1 });
3589
+ tokens.push({ type: "op", value: "*" });
3590
+ } else {
3591
+ const num = parseFloat(numStr);
3592
+ if (isNaN(num)) throw new Error(`Invalid number: ${numStr}`);
3593
+ tokens.push({ type: "number", value: num });
3594
+ }
3595
+ continue;
3596
+ }
3597
+ tokens.push({ type: "op", value: ch });
3598
+ i++;
3599
+ continue;
3600
+ }
3601
+ if (isDigitOrDot(ch)) {
3602
+ let numStr = "";
3603
+ while (i < expr.length && isDigitOrDot(expr[i])) {
3604
+ numStr += expr[i];
3605
+ i++;
3606
+ }
3607
+ const num = parseFloat(numStr);
3608
+ if (isNaN(num)) throw new Error(`Invalid number: ${numStr}`);
3609
+ tokens.push({ type: "number", value: num });
3610
+ continue;
3611
+ }
3612
+ throw new Error(`Unexpected character: '${ch}' at position ${i}`);
3613
+ }
3614
+ return tokens;
3615
+ }
3616
+ function isDigitOrDot(ch) {
3617
+ return ch >= "0" && ch <= "9" || ch === ".";
3618
+ }
3619
+ function evaluate(tokens) {
3620
+ let pos = 0;
3621
+ function current() {
3622
+ return tokens[pos];
3623
+ }
3624
+ function parseExpr() {
3625
+ let left = parseTerm();
3626
+ let tok = current();
3627
+ while (tok && tok.type === "op" && (tok.value === "+" || tok.value === "-")) {
3628
+ const op = tok.value;
3629
+ pos++;
3630
+ const right = parseTerm();
3631
+ left = op === "+" ? left + right : left - right;
3632
+ tok = current();
3633
+ }
3634
+ return left;
3635
+ }
3636
+ function parseTerm() {
3637
+ let left = parseFactor();
3638
+ let tok = current();
3639
+ while (tok && tok.type === "op" && (tok.value === "*" || tok.value === "/" || tok.value === "%")) {
3640
+ const op = tok.value;
3641
+ pos++;
3642
+ const right = parseFactor();
3643
+ if ((op === "/" || op === "%") && right === 0) {
3644
+ throw new Error("Division by zero");
3645
+ }
3646
+ if (op === "*") left = left * right;
3647
+ else if (op === "/") left = left / right;
3648
+ else left = left % right;
3649
+ tok = current();
3650
+ }
3651
+ return left;
3652
+ }
3653
+ function parseFactor() {
3654
+ const tok = current();
3655
+ if (!tok) {
3656
+ throw new Error("Unexpected end of expression");
3657
+ }
3658
+ if (tok.type === "number") {
3659
+ pos++;
3660
+ return tok.value;
3661
+ }
3662
+ if (tok.type === "lparen") {
3663
+ pos++;
3664
+ const val = parseExpr();
3665
+ const closing = current();
3666
+ if (!closing || closing.type !== "rparen") {
3667
+ throw new Error("Missing closing parenthesis");
3668
+ }
3669
+ pos++;
3670
+ return val;
3671
+ }
3672
+ throw new Error(`Unexpected token: ${JSON.stringify(tok)}`);
3673
+ }
3674
+ const result = parseExpr();
3675
+ const remaining = current();
3676
+ if (remaining) {
3677
+ throw new Error(`Unexpected token after expression: ${JSON.stringify(remaining)}`);
3678
+ }
3679
+ return result;
3680
+ }
3681
+ function safeEvaluate(expression) {
3682
+ const tokens = tokenize(expression);
3683
+ if (tokens.length === 0) {
3684
+ throw new Error("Empty expression");
3685
+ }
3686
+ return evaluate(tokens);
3687
+ }
3688
+ function applyRounding(value, round, precision) {
3689
+ if (round === "none") return value;
3690
+ const factor = Math.pow(10, precision);
3691
+ const scaled = value * factor;
3692
+ switch (round) {
3693
+ case "round":
3694
+ return Math.round(scaled) / factor;
3695
+ case "floor":
3696
+ return Math.floor(scaled) / factor;
3697
+ case "ceil":
3698
+ return Math.ceil(scaled) / factor;
3699
+ default:
3700
+ return value;
3701
+ }
3702
+ }
3703
+ var MathOp = class extends ActionNode {
3704
+ expression;
3705
+ outputKey;
3706
+ round;
3707
+ precision;
3708
+ constructor(config) {
3709
+ super(config);
3710
+ this.expression = config.expression;
3711
+ this.outputKey = config.outputKey;
3712
+ this.round = config.round ?? "none";
3713
+ this.precision = config.precision ?? 0;
3714
+ }
3715
+ async executeTick(context) {
3716
+ try {
3717
+ const varCtx = {
3718
+ blackboard: context.blackboard,
3719
+ input: context.input,
3720
+ testData: context.testData
3721
+ };
3722
+ const resolved = resolveString(this.expression, varCtx);
3723
+ let result;
3724
+ if (typeof resolved === "number") {
3725
+ result = resolved;
3726
+ } else if (typeof resolved === "string") {
3727
+ result = safeEvaluate(resolved);
3728
+ } else {
3729
+ throw new Error(`Expression resolved to non-numeric type: ${typeof resolved}`);
3730
+ }
3731
+ if (!isFinite(result)) {
3732
+ throw new Error(`Expression result is not finite: ${result}`);
3733
+ }
3734
+ result = applyRounding(result, this.round, this.precision);
3735
+ context.blackboard.set(this.outputKey, result);
3736
+ this.log(`${this.expression} = ${result}`);
3737
+ return "SUCCESS" /* SUCCESS */;
3738
+ } catch (error) {
3739
+ this._lastError = error instanceof Error ? error.message : String(error);
3740
+ this.log(`MathOp failed: ${this._lastError}`);
3741
+ return "FAILURE" /* FAILURE */;
3742
+ }
3743
+ }
3744
+ };
3745
+
3746
+ // src/utilities/array-filter.ts
3747
+ function getFieldValue(item, path2) {
3748
+ if (item === null || item === void 0) return void 0;
3749
+ const parts = path2.split(".");
3750
+ let current = item;
3751
+ for (const part of parts) {
3752
+ if (current === null || current === void 0) return void 0;
3753
+ if (typeof current !== "object") return void 0;
3754
+ current = current[part];
3755
+ }
3756
+ return current;
3757
+ }
3758
+ function evaluateCondition(item, condition, resolvedValue, resolvedRange) {
3759
+ const fieldVal = getFieldValue(item, condition.field);
3760
+ switch (condition.operator) {
3761
+ case "eq":
3762
+ return fieldVal === resolvedValue;
3763
+ case "ne":
3764
+ return fieldVal !== resolvedValue;
3765
+ case "gt":
3766
+ return fieldVal > resolvedValue;
3767
+ case "lt":
3768
+ return fieldVal < resolvedValue;
3769
+ case "gte":
3770
+ return fieldVal >= resolvedValue;
3771
+ case "lte":
3772
+ return fieldVal <= resolvedValue;
3773
+ case "in":
3774
+ if (!Array.isArray(resolvedValue)) return false;
3775
+ return resolvedValue.includes(fieldVal);
3776
+ case "nin":
3777
+ if (!Array.isArray(resolvedValue)) return true;
3778
+ return !resolvedValue.includes(fieldVal);
3779
+ case "exists":
3780
+ const shouldExist = resolvedValue !== false;
3781
+ const exists = fieldVal !== null && fieldVal !== void 0;
3782
+ return shouldExist ? exists : !exists;
3783
+ case "regex": {
3784
+ if (typeof fieldVal !== "string" || typeof resolvedValue !== "string") return false;
3785
+ try {
3786
+ return new RegExp(resolvedValue).test(fieldVal);
3787
+ } catch {
3788
+ return false;
3789
+ }
3790
+ }
3791
+ case "between": {
3792
+ if (!resolvedRange) return false;
3793
+ const [min, max] = resolvedRange;
3794
+ return fieldVal >= min && fieldVal <= max;
3795
+ }
3796
+ case "contains": {
3797
+ if (typeof fieldVal === "string" && typeof resolvedValue === "string") {
3798
+ return fieldVal.includes(resolvedValue);
3799
+ }
3800
+ if (Array.isArray(fieldVal)) {
3801
+ return fieldVal.includes(resolvedValue);
3802
+ }
3803
+ return false;
3804
+ }
3805
+ default:
3806
+ return false;
3807
+ }
3808
+ }
3809
+ var ArrayFilter = class extends ActionNode {
3810
+ input;
3811
+ outputKey;
3812
+ conditions;
3813
+ logic;
3814
+ constructor(config) {
3815
+ super(config);
3816
+ this.input = config.input;
3817
+ this.outputKey = config.outputKey;
3818
+ this.conditions = config.conditions;
3819
+ this.logic = config.logic ?? "and";
3820
+ }
3821
+ async executeTick(context) {
3822
+ try {
3823
+ const varCtx = {
3824
+ blackboard: context.blackboard,
3825
+ input: context.input,
3826
+ testData: context.testData
3827
+ };
3828
+ const inputResolved = typeof this.input === "string" ? resolveValue(this.input, varCtx) : this.input;
3829
+ if (!Array.isArray(inputResolved)) {
3830
+ throw new Error(
3831
+ `Input is not an array: got ${inputResolved === null ? "null" : typeof inputResolved}`
3832
+ );
3833
+ }
3834
+ const resolvedConditions = this.conditions.map((c) => ({
3835
+ condition: c,
3836
+ value: c.value !== void 0 ? resolveValue(c.value, varCtx) : void 0,
3837
+ range: c.range ? [resolveValue(c.range[0], varCtx), resolveValue(c.range[1], varCtx)] : void 0
3838
+ }));
3839
+ const result = inputResolved.filter((item) => {
3840
+ const results = resolvedConditions.map(
3841
+ ({ condition, value, range }) => evaluateCondition(item, condition, value, range)
3842
+ );
3843
+ return this.logic === "and" ? results.every(Boolean) : results.some(Boolean);
3844
+ });
3845
+ context.blackboard.set(this.outputKey, result);
3846
+ this.log(`Filtered ${inputResolved.length} \u2192 ${result.length} items`);
3847
+ return "SUCCESS" /* SUCCESS */;
3848
+ } catch (error) {
3849
+ this._lastError = error instanceof Error ? error.message : String(error);
3850
+ this.log(`ArrayFilter failed: ${this._lastError}`);
3851
+ return "FAILURE" /* FAILURE */;
3852
+ }
3853
+ }
3854
+ };
3855
+
3856
+ // src/utilities/aggregate.ts
3857
+ function getFieldValue2(item, path2) {
3858
+ if (item === null || item === void 0) return void 0;
3859
+ const parts = path2.split(".");
3860
+ let current = item;
3861
+ for (const part of parts) {
3862
+ if (current === null || current === void 0) return void 0;
3863
+ if (typeof current !== "object") return void 0;
3864
+ current = current[part];
3865
+ }
3866
+ return current;
3867
+ }
3868
+ function computeAggregations(items, operations) {
3869
+ const result = {};
3870
+ for (const op of operations) {
3871
+ const key = op.as ?? (op.field ? `${op.type}_${op.field}` : op.type);
3872
+ if (op.type === "count") {
3873
+ result[key] = items.length;
3874
+ continue;
3875
+ }
3876
+ if (!op.field) {
3877
+ result[key] = null;
3878
+ continue;
3879
+ }
3880
+ const values = [];
3881
+ for (const item of items) {
3882
+ const raw = getFieldValue2(item, op.field);
3883
+ const num = typeof raw === "number" ? raw : parseFloat(String(raw));
3884
+ if (!isNaN(num)) values.push(num);
3885
+ }
3886
+ switch (op.type) {
3887
+ case "sum":
3888
+ result[key] = values.reduce((a, b) => a + b, 0);
3889
+ break;
3890
+ case "avg":
3891
+ result[key] = values.length > 0 ? values.reduce((a, b) => a + b, 0) / values.length : 0;
3892
+ break;
3893
+ case "min":
3894
+ result[key] = values.length > 0 ? Math.min(...values) : null;
3895
+ break;
3896
+ case "max":
3897
+ result[key] = values.length > 0 ? Math.max(...values) : null;
3898
+ break;
3899
+ }
3900
+ }
3901
+ return result;
3902
+ }
3903
+ var Aggregate = class extends ActionNode {
3904
+ input;
3905
+ outputKey;
3906
+ operations;
3907
+ groupBy;
3908
+ constructor(config) {
3909
+ super(config);
3910
+ this.input = config.input;
3911
+ this.outputKey = config.outputKey;
3912
+ this.operations = config.operations;
3913
+ this.groupBy = config.groupBy;
3914
+ }
3915
+ async executeTick(context) {
3916
+ try {
3917
+ const varCtx = {
3918
+ blackboard: context.blackboard,
3919
+ input: context.input,
3920
+ testData: context.testData
3921
+ };
3922
+ const inputResolved = typeof this.input === "string" ? resolveValue(this.input, varCtx) : this.input;
3923
+ if (!Array.isArray(inputResolved)) {
3924
+ throw new Error(
3925
+ `Input is not an array: got ${inputResolved === null ? "null" : typeof inputResolved}`
3926
+ );
3927
+ }
3928
+ if (!this.groupBy) {
3929
+ const result = computeAggregations(inputResolved, this.operations);
3930
+ context.blackboard.set(this.outputKey, result);
3931
+ this.log(`Aggregated ${inputResolved.length} items \u2192 ${JSON.stringify(result)}`);
3932
+ } else {
3933
+ const groups = {};
3934
+ for (const item of inputResolved) {
3935
+ const groupVal = getFieldValue2(item, this.groupBy);
3936
+ const groupKey = groupVal === null || groupVal === void 0 ? "__null__" : String(groupVal);
3937
+ if (!groups[groupKey]) groups[groupKey] = [];
3938
+ groups[groupKey].push(item);
3939
+ }
3940
+ const result = {};
3941
+ for (const [groupKey, groupItems] of Object.entries(groups)) {
3942
+ result[groupKey] = computeAggregations(groupItems, this.operations);
3943
+ }
3944
+ context.blackboard.set(this.outputKey, result);
3945
+ this.log(
3946
+ `Aggregated ${inputResolved.length} items into ${Object.keys(groups).length} groups`
3947
+ );
3948
+ }
3949
+ return "SUCCESS" /* SUCCESS */;
3950
+ } catch (error) {
3951
+ this._lastError = error instanceof Error ? error.message : String(error);
3952
+ this.log(`Aggregate failed: ${this._lastError}`);
3953
+ return "FAILURE" /* FAILURE */;
3954
+ }
3955
+ }
3956
+ };
3957
+
3958
+ // src/utilities/threshold-check.ts
3959
+ function evaluateThreshold(val, threshold, resolvedValue, resolvedRange) {
3960
+ switch (threshold.operator) {
3961
+ case "lte":
3962
+ return val <= resolvedValue;
3963
+ case "lt":
3964
+ return val < resolvedValue;
3965
+ case "gte":
3966
+ return val >= resolvedValue;
3967
+ case "gt":
3968
+ return val > resolvedValue;
3969
+ case "eq":
3970
+ return val === resolvedValue;
3971
+ case "ne":
3972
+ return val !== resolvedValue;
3973
+ case "between": {
3974
+ if (!resolvedRange) return false;
3975
+ return val >= resolvedRange[0] && val <= resolvedRange[1];
3976
+ }
3977
+ default:
3978
+ return false;
3979
+ }
3980
+ }
3981
+ var ThresholdCheck = class extends ActionNode {
3982
+ valueRef;
3983
+ thresholds;
3984
+ outputKey;
3985
+ failOn;
3986
+ constructor(config) {
3987
+ super(config);
3988
+ this.valueRef = config.value;
3989
+ this.thresholds = config.thresholds;
3990
+ this.outputKey = config.outputKey;
3991
+ this.failOn = config.failOn ?? [];
3992
+ }
3993
+ async executeTick(context) {
3994
+ try {
3995
+ const varCtx = {
3996
+ blackboard: context.blackboard,
3997
+ input: context.input,
3998
+ testData: context.testData
3999
+ };
4000
+ const resolved = typeof this.valueRef === "string" ? resolveValue(this.valueRef, varCtx) : this.valueRef;
4001
+ const numValue = typeof resolved === "number" ? resolved : parseFloat(String(resolved));
4002
+ if (isNaN(numValue)) {
4003
+ throw new Error(`Value is not numeric: ${JSON.stringify(resolved)}`);
4004
+ }
4005
+ let matchedLabel = "normal";
4006
+ for (const threshold of this.thresholds) {
4007
+ const thresholdValue = threshold.value !== void 0 ? resolveValue(threshold.value, varCtx) : void 0;
4008
+ const thresholdRange = threshold.range ? [resolveValue(threshold.range[0], varCtx), resolveValue(threshold.range[1], varCtx)] : void 0;
4009
+ if (evaluateThreshold(numValue, threshold, thresholdValue, thresholdRange)) {
4010
+ matchedLabel = threshold.label;
4011
+ break;
4012
+ }
4013
+ }
4014
+ if (this.outputKey) {
4015
+ context.blackboard.set(this.outputKey, matchedLabel);
4016
+ }
4017
+ this.log(`Value ${numValue} \u2192 ${matchedLabel}`);
4018
+ if (this.failOn.includes(matchedLabel)) {
4019
+ this._lastError = `Threshold breach: ${matchedLabel} (value: ${numValue})`;
4020
+ return "FAILURE" /* FAILURE */;
4021
+ }
4022
+ return "SUCCESS" /* SUCCESS */;
4023
+ } catch (error) {
4024
+ this._lastError = error instanceof Error ? error.message : String(error);
4025
+ this.log(`ThresholdCheck failed: ${this._lastError}`);
4026
+ return "FAILURE" /* FAILURE */;
4027
+ }
4028
+ }
4029
+ };
4030
+
4031
+ // src/utilities/data-transform.ts
4032
+ function setNestedValue(obj, path2, value) {
4033
+ const parts = path2.split(".");
4034
+ let current = obj;
4035
+ for (let i = 0; i < parts.length - 1; i++) {
4036
+ const part = parts[i];
4037
+ if (current[part] === void 0 || current[part] === null || typeof current[part] !== "object") {
4038
+ current[part] = {};
4039
+ }
4040
+ current = current[part];
4041
+ }
4042
+ const lastPart = parts[parts.length - 1];
4043
+ if (lastPart !== void 0) {
4044
+ current[lastPart] = value;
4045
+ }
4046
+ }
4047
+ function coerceValue(value, coerce) {
4048
+ switch (coerce) {
4049
+ case "string":
4050
+ return value === null || value === void 0 ? "" : String(value);
4051
+ case "number": {
4052
+ if (typeof value === "number") return value;
4053
+ const num = parseFloat(String(value));
4054
+ if (isNaN(num)) throw new Error(`Cannot coerce "${value}" to number`);
4055
+ return num;
4056
+ }
4057
+ case "boolean":
4058
+ if (typeof value === "boolean") return value;
4059
+ if (value === "true" || value === 1) return true;
4060
+ if (value === "false" || value === 0 || value === "" || value === null || value === void 0) return false;
4061
+ return Boolean(value);
4062
+ default:
4063
+ return value;
4064
+ }
4065
+ }
4066
+ var DataTransform = class extends ActionNode {
4067
+ outputKey;
4068
+ mappings;
4069
+ wrapInArray;
4070
+ constructor(config) {
4071
+ super(config);
4072
+ this.outputKey = config.outputKey;
4073
+ this.mappings = config.mappings;
4074
+ this.wrapInArray = config.wrapInArray ?? false;
4075
+ }
4076
+ async executeTick(context) {
4077
+ try {
4078
+ const varCtx = {
4079
+ blackboard: context.blackboard,
4080
+ input: context.input,
4081
+ testData: context.testData
4082
+ };
4083
+ const result = {};
4084
+ for (const mapping of this.mappings) {
4085
+ let resolved = resolveValue(mapping.value, varCtx);
4086
+ if (mapping.coerce) {
4087
+ resolved = coerceValue(resolved, mapping.coerce);
4088
+ }
4089
+ setNestedValue(result, mapping.target, resolved);
4090
+ }
4091
+ const output = this.wrapInArray ? [result] : result;
4092
+ context.blackboard.set(this.outputKey, output);
4093
+ this.log(`Built object with ${this.mappings.length} fields \u2192 ${this.outputKey}`);
4094
+ return "SUCCESS" /* SUCCESS */;
4095
+ } catch (error) {
4096
+ this._lastError = error instanceof Error ? error.message : String(error);
4097
+ this.log(`DataTransform failed: ${this._lastError}`);
4098
+ return "FAILURE" /* FAILURE */;
4099
+ }
4100
+ }
4101
+ };
4102
+
3463
4103
  // src/integrations/piece-executor.ts
3464
4104
  var PROVIDER_TO_PIECE = {
3465
4105
  // Google services
@@ -4988,6 +5628,11 @@ function registerStandardNodes(registry) {
4988
5628
  registry.register("LogMessage", LogMessage, { category: "action" });
4989
5629
  registry.register("RegexExtract", RegexExtract, { category: "action" });
4990
5630
  registry.register("SetVariable", SetVariable, { category: "action" });
5631
+ registry.register("MathOp", MathOp, { category: "action" });
5632
+ registry.register("ArrayFilter", ArrayFilter, { category: "action" });
5633
+ registry.register("Aggregate", Aggregate, { category: "action" });
5634
+ registry.register("ThresholdCheck", ThresholdCheck, { category: "action" });
5635
+ registry.register("DataTransform", DataTransform, { category: "action" });
4991
5636
  registry.register("IntegrationAction", IntegrationAction, { category: "action" });
4992
5637
  registry.register("PythonScript", PythonScript, { category: "action" });
4993
5638
  registry.register("ParseFile", ParseFile, { category: "action" });
@@ -5837,7 +6482,9 @@ function createObservabilitySinkHandler(config = {}) {
5837
6482
  }
5838
6483
  export {
5839
6484
  ActionNode,
6485
+ Aggregate,
5840
6486
  AlwaysCondition,
6487
+ ArrayFilter,
5841
6488
  BaseNode,
5842
6489
  BehaviorTree,
5843
6490
  BrowserAgent,
@@ -5850,6 +6497,7 @@ export {
5850
6497
  ConfigValidationError,
5851
6498
  ConfigurationError,
5852
6499
  CounterAction,
6500
+ DataTransform,
5853
6501
  DecoratorNode,
5854
6502
  Delay,
5855
6503
  ExecutionTracker,
@@ -5868,6 +6516,7 @@ export {
5868
6516
  LLMChat,
5869
6517
  LLMToolCall,
5870
6518
  LogMessage,
6519
+ MathOp,
5871
6520
  MemoryDataStore,
5872
6521
  MemorySequence,
5873
6522
  MockAction,
@@ -5899,6 +6548,7 @@ export {
5899
6548
  StructureValidationError,
5900
6549
  SubTree,
5901
6550
  SuccessNode,
6551
+ ThresholdCheck,
5902
6552
  Timeout,
5903
6553
  ToolExecutor,
5904
6554
  ToolRouter,
@@ -5929,6 +6579,7 @@ export {
5929
6579
  registerStandardNodes,
5930
6580
  resolveString,
5931
6581
  resolveValue,
6582
+ safeEvaluate,
5932
6583
  safeValidateConfiguration,
5933
6584
  schemaRegistry,
5934
6585
  semanticValidator,