@hexabot-ai/agentic 3.1.2-beta.1 → 3.1.2-beta.2

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.
@@ -12,6 +12,30 @@ exports.mergeSettings = exports.evaluateMapping = exports.evaluateValue = export
12
12
  const jsonata_1 = __importDefault(require("jsonata"));
13
13
  /** Basic object guard that rejects arrays and null. */
14
14
  const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
15
+ const resolveNestedExpressions = async (value, scope, seen = new WeakSet()) => {
16
+ if (typeof value === 'string' && value.startsWith('=')) {
17
+ return (0, exports.evaluateValue)((0, exports.compileValue)(value), scope);
18
+ }
19
+ if (Array.isArray(value)) {
20
+ if (seen.has(value)) {
21
+ return value;
22
+ }
23
+ seen.add(value);
24
+ return Promise.all(value.map((entry) => resolveNestedExpressions(entry, scope, seen)));
25
+ }
26
+ if (isPlainObject(value)) {
27
+ if (seen.has(value)) {
28
+ return value;
29
+ }
30
+ seen.add(value);
31
+ const entries = await Promise.all(Object.entries(value).map(async ([key, entry]) => [
32
+ key,
33
+ await resolveNestedExpressions(entry, scope, seen),
34
+ ]));
35
+ return Object.fromEntries(entries);
36
+ }
37
+ return value;
38
+ };
15
39
  const registerJsonataFunctions = (expression, registry) => {
16
40
  if (!registry) {
17
41
  return;
@@ -68,10 +92,11 @@ const evaluateMapping = async (mapping, scope) => {
68
92
  if (!mapping) {
69
93
  return {};
70
94
  }
71
- const result = {};
72
- for (const [key, compiled] of Object.entries(mapping)) {
73
- result[key] = await (0, exports.evaluateValue)(compiled, scope);
74
- }
95
+ const entries = await Promise.all(Object.entries(mapping).map(async ([key, compiled]) => [
96
+ key,
97
+ await resolveNestedExpressions(await (0, exports.evaluateValue)(compiled, scope), scope),
98
+ ]));
99
+ const result = Object.fromEntries(entries);
75
100
  return result;
76
101
  };
77
102
  exports.evaluateMapping = evaluateMapping;
@@ -6,6 +6,30 @@
6
6
  import jsonata from 'jsonata';
7
7
  /** Basic object guard that rejects arrays and null. */
8
8
  const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
9
+ const resolveNestedExpressions = async (value, scope, seen = new WeakSet()) => {
10
+ if (typeof value === 'string' && value.startsWith('=')) {
11
+ return evaluateValue(compileValue(value), scope);
12
+ }
13
+ if (Array.isArray(value)) {
14
+ if (seen.has(value)) {
15
+ return value;
16
+ }
17
+ seen.add(value);
18
+ return Promise.all(value.map((entry) => resolveNestedExpressions(entry, scope, seen)));
19
+ }
20
+ if (isPlainObject(value)) {
21
+ if (seen.has(value)) {
22
+ return value;
23
+ }
24
+ seen.add(value);
25
+ const entries = await Promise.all(Object.entries(value).map(async ([key, entry]) => [
26
+ key,
27
+ await resolveNestedExpressions(entry, scope, seen),
28
+ ]));
29
+ return Object.fromEntries(entries);
30
+ }
31
+ return value;
32
+ };
9
33
  const registerJsonataFunctions = (expression, registry) => {
10
34
  if (!registry) {
11
35
  return;
@@ -60,10 +84,11 @@ export const evaluateMapping = async (mapping, scope) => {
60
84
  if (!mapping) {
61
85
  return {};
62
86
  }
63
- const result = {};
64
- for (const [key, compiled] of Object.entries(mapping)) {
65
- result[key] = await evaluateValue(compiled, scope);
66
- }
87
+ const entries = await Promise.all(Object.entries(mapping).map(async ([key, compiled]) => [
88
+ key,
89
+ await resolveNestedExpressions(await evaluateValue(compiled, scope), scope),
90
+ ]));
91
+ const result = Object.fromEntries(entries);
67
92
  return result;
68
93
  };
69
94
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"workflow-values.d.ts","sourceRoot":"","sources":["../../src/workflow-values.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAc,KAAK,EAAE,MAAM,SAAS,CAAC;AAGjD,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,6BAA6B,GAAG,CAC1C,IA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AE,KACX,OAAO,CAAC;AAEb,MAAM,MAAM,qBAAqB,GAC7B,6BAA6B,GAC7B;IACE,cAAc,EAAE,6BAA6B,CAAC;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEN,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;AAE5E,MAAM,MAAM,mBAAmB,GAAG;IAChC,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;CAC5C,CAAC;AAsEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,OAAO,EACd,UAAU,mBAAmB,KAC5B,aASF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GACxB,UAAU,aAAa,EACvB,OAAO,eAAe,KACrB,OAAO,CAAC,OAAO,CAgBjB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,eAAe,GAAG,SAAS,EACpC,OAAO,eAAe,KACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBjC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,OAAO,CAAC,QAAQ,CAAC,EACxB,WAAW,OAAO,CAAC,QAAQ,CAAC,KAC3B,OAAO,CAAC,QAAQ,CAsBlB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexabot-ai/agentic",
3
- "version": "3.1.2-beta.1",
3
+ "version": "3.1.2-beta.2",
4
4
  "description": "Schemas and utilities for the Hexabot agentic workflow DSL.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -73,6 +73,25 @@ describe('workflow values', () => {
73
73
  });
74
74
  });
75
75
 
76
+ it('evaluates nested expressions inside literal objects', async () => {
77
+ const mapping = {
78
+ headers: compileValue({
79
+ nestedFiled: '=$input.headerValue',
80
+ }),
81
+ };
82
+ const values = await evaluateMapping(mapping, {
83
+ input: { headerValue: 'Bearer token-value' },
84
+ context: new TestContext().state,
85
+ output: {},
86
+ });
87
+
88
+ expect(values).toEqual({
89
+ headers: {
90
+ nestedFiled: 'Bearer token-value',
91
+ },
92
+ });
93
+ });
94
+
76
95
  it('handles missing mappings and deep merges settings', async () => {
77
96
  await expect(
78
97
  evaluateMapping(undefined, {
@@ -35,6 +35,44 @@ export type CompileValueOptions = {
35
35
  /** Basic object guard that rejects arrays and null. */
36
36
  const isPlainObject = (value: unknown): value is Record<string, unknown> =>
37
37
  typeof value === 'object' && value !== null && !Array.isArray(value);
38
+ const resolveNestedExpressions = async (
39
+ value: unknown,
40
+ scope: EvaluationScope,
41
+ seen: WeakSet<object> = new WeakSet(),
42
+ ): Promise<unknown> => {
43
+ if (typeof value === 'string' && value.startsWith('=')) {
44
+ return evaluateValue(compileValue(value), scope);
45
+ }
46
+
47
+ if (Array.isArray(value)) {
48
+ if (seen.has(value)) {
49
+ return value;
50
+ }
51
+ seen.add(value);
52
+
53
+ return Promise.all(
54
+ value.map((entry) => resolveNestedExpressions(entry, scope, seen)),
55
+ );
56
+ }
57
+
58
+ if (isPlainObject(value)) {
59
+ if (seen.has(value)) {
60
+ return value;
61
+ }
62
+ seen.add(value);
63
+
64
+ const entries = await Promise.all(
65
+ Object.entries(value).map(async ([key, entry]) => [
66
+ key,
67
+ await resolveNestedExpressions(entry, scope, seen),
68
+ ]),
69
+ );
70
+
71
+ return Object.fromEntries(entries);
72
+ }
73
+
74
+ return value;
75
+ };
38
76
  const registerJsonataFunctions = (
39
77
  expression: Expression,
40
78
  registry?: JsonataFunctionRegistry,
@@ -118,11 +156,16 @@ export const evaluateMapping = async (
118
156
  return {};
119
157
  }
120
158
 
121
- const result: Record<string, unknown> = {};
122
-
123
- for (const [key, compiled] of Object.entries(mapping)) {
124
- result[key] = await evaluateValue(compiled, scope);
125
- }
159
+ const entries = await Promise.all(
160
+ Object.entries(mapping).map(async ([key, compiled]) => [
161
+ key,
162
+ await resolveNestedExpressions(
163
+ await evaluateValue(compiled, scope),
164
+ scope,
165
+ ),
166
+ ]),
167
+ );
168
+ const result: Record<string, unknown> = Object.fromEntries(entries);
126
169
 
127
170
  return result;
128
171
  };