@memberjunction/ai-agents 5.38.0 → 5.40.0
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/AgentRunner.d.ts +23 -0
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +81 -26
- package/dist/AgentRunner.js.map +1 -1
- package/dist/ArtifactToolManager.d.ts +13 -0
- package/dist/ArtifactToolManager.d.ts.map +1 -1
- package/dist/ArtifactToolManager.js +60 -1
- package/dist/ArtifactToolManager.js.map +1 -1
- package/dist/agent-run-watchdog.d.ts +109 -0
- package/dist/agent-run-watchdog.d.ts.map +1 -0
- package/dist/agent-run-watchdog.js +278 -0
- package/dist/agent-run-watchdog.js.map +1 -0
- package/dist/agent-types/loop-agent-prompt-params.d.ts +13 -0
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +3 -1
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +12 -3
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +41 -2
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/artifact-tools/DataSnapshotToolLibrary.js +2 -2
- package/dist/artifact-tools/JSONToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/JSONToolLibrary.js +7 -1
- package/dist/artifact-tools/JSONToolLibrary.js.map +1 -1
- package/dist/base-agent.d.ts +69 -1
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +294 -24
- package/dist/base-agent.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/pipeline/coerce.d.ts +43 -0
- package/dist/pipeline/coerce.d.ts.map +1 -0
- package/dist/pipeline/coerce.js +92 -0
- package/dist/pipeline/coerce.js.map +1 -0
- package/dist/pipeline/index.d.ts +20 -0
- package/dist/pipeline/index.d.ts.map +1 -0
- package/dist/pipeline/index.js +20 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/jsonpath-eval.d.ts +29 -0
- package/dist/pipeline/jsonpath-eval.d.ts.map +1 -0
- package/dist/pipeline/jsonpath-eval.js +144 -0
- package/dist/pipeline/jsonpath-eval.js.map +1 -0
- package/dist/pipeline/operators.d.ts +15 -0
- package/dist/pipeline/operators.d.ts.map +1 -0
- package/dist/pipeline/operators.js +332 -0
- package/dist/pipeline/operators.js.map +1 -0
- package/dist/pipeline/path.d.ts +16 -0
- package/dist/pipeline/path.d.ts.map +1 -0
- package/dist/pipeline/path.js +34 -0
- package/dist/pipeline/path.js.map +1 -0
- package/dist/pipeline/pipeline-docs.d.ts +6 -0
- package/dist/pipeline/pipeline-docs.d.ts.map +1 -0
- package/dist/pipeline/pipeline-docs.js +137 -0
- package/dist/pipeline/pipeline-docs.js.map +1 -0
- package/dist/pipeline/pipeline-executor.d.ts +72 -0
- package/dist/pipeline/pipeline-executor.d.ts.map +1 -0
- package/dist/pipeline/pipeline-executor.js +326 -0
- package/dist/pipeline/pipeline-executor.js.map +1 -0
- package/dist/pipeline/pipeline-registry.d.ts +24 -0
- package/dist/pipeline/pipeline-registry.d.ts.map +1 -0
- package/dist/pipeline/pipeline-registry.js +28 -0
- package/dist/pipeline/pipeline-registry.js.map +1 -0
- package/dist/pipeline/pipeline.types.d.ts +89 -0
- package/dist/pipeline/pipeline.types.d.ts.map +1 -0
- package/dist/pipeline/pipeline.types.js +13 -0
- package/dist/pipeline/pipeline.types.js.map +1 -0
- package/dist/pipeline/predicate.d.ts +23 -0
- package/dist/pipeline/predicate.d.ts.map +1 -0
- package/dist/pipeline/predicate.js +306 -0
- package/dist/pipeline/predicate.js.map +1 -0
- package/dist/pipeline/providers/action-provider.d.ts +21 -0
- package/dist/pipeline/providers/action-provider.d.ts.map +1 -0
- package/dist/pipeline/providers/action-provider.js +24 -0
- package/dist/pipeline/providers/action-provider.js.map +1 -0
- package/dist/pipeline/providers/artifact-tool-provider.d.ts +20 -0
- package/dist/pipeline/providers/artifact-tool-provider.d.ts.map +1 -0
- package/dist/pipeline/providers/artifact-tool-provider.js +27 -0
- package/dist/pipeline/providers/artifact-tool-provider.js.map +1 -0
- package/dist/pipeline/providers/serialize.d.ts +23 -0
- package/dist/pipeline/providers/serialize.d.ts.map +1 -0
- package/dist/pipeline/providers/serialize.js +99 -0
- package/dist/pipeline/providers/serialize.js.map +1 -0
- package/dist/pipeline/template.d.ts +18 -0
- package/dist/pipeline/template.d.ts.map +1 -0
- package/dist/pipeline/template.js +47 -0
- package/dist/pipeline/template.js.map +1 -0
- package/package.json +19 -17
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { getValue, getValues } from './path.js';
|
|
2
|
+
import { parsePredicate, evaluatePredicate } from './predicate.js';
|
|
3
|
+
import { valueToText } from './coerce.js';
|
|
4
|
+
// ─── helpers ───
|
|
5
|
+
function requireArray(input, op) {
|
|
6
|
+
if (!Array.isArray(input)) {
|
|
7
|
+
throw new Error(`"${op}" expects an array but received ${describe(input)}.${nonArrayHint(input)}`);
|
|
8
|
+
}
|
|
9
|
+
return input;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Guard for the text-only operators (`head`/`tail`): reject arrays and point the agent at the
|
|
13
|
+
* array equivalent. Keeps the verb choice unambiguous — `head`/`tail` operate on text LINES,
|
|
14
|
+
* `first`/`last` operate on array ELEMENTS — instead of both silently slicing arrays.
|
|
15
|
+
*/
|
|
16
|
+
function rejectArray(input, op, arrayOp) {
|
|
17
|
+
if (Array.isArray(input)) {
|
|
18
|
+
throw new Error(`"${op}" operates on text only; for the ${input.length}-element array use "${arrayOp}" instead.`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function describe(v) {
|
|
22
|
+
if (Array.isArray(v))
|
|
23
|
+
return 'an array';
|
|
24
|
+
if (v === null)
|
|
25
|
+
return 'null';
|
|
26
|
+
return `a ${typeof v}`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* When an array operator gets a non-array OBJECT, it's almost always because the upstream value is an
|
|
30
|
+
* envelope wrapping the real collection (e.g. `{ Results: [...] }`). List the keys and, if one holds
|
|
31
|
+
* an array, suggest the exact `jsonpath` to extract it — so the agent self-corrects next turn from
|
|
32
|
+
* the message alone (the data isn't in its context). Returns '' for non-objects.
|
|
33
|
+
*/
|
|
34
|
+
function nonArrayHint(input) {
|
|
35
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
const keys = Object.keys(input);
|
|
39
|
+
const arrayKey = keys.find((k) => Array.isArray(input[k]));
|
|
40
|
+
const path = arrayKey ? `$.${arrayKey}[*]` : '$.<field>[*]';
|
|
41
|
+
return (` Got an object with keys [${keys.join(', ')}].` +
|
|
42
|
+
` If the array is nested under a field, extract it first with a {"jsonpath":"${path}"} stage.`);
|
|
43
|
+
}
|
|
44
|
+
function asString(args, op) {
|
|
45
|
+
if (typeof args !== 'string' || args.trim() === '') {
|
|
46
|
+
throw new Error(`"${op}" requires a non-empty string argument.`);
|
|
47
|
+
}
|
|
48
|
+
return args;
|
|
49
|
+
}
|
|
50
|
+
function asInt(args, op) {
|
|
51
|
+
const n = typeof args === 'number' ? args : parseInt(String(args), 10);
|
|
52
|
+
if (!Number.isFinite(n)) {
|
|
53
|
+
throw new Error(`"${op}" requires a numeric argument.`);
|
|
54
|
+
}
|
|
55
|
+
return Math.trunc(n);
|
|
56
|
+
}
|
|
57
|
+
function lastSegment(path) {
|
|
58
|
+
return (path.split('.').pop() ?? path).replace(/\[.*\]$/, '');
|
|
59
|
+
}
|
|
60
|
+
/** Numeric when both sides are numeric; else lexicographic on string forms. */
|
|
61
|
+
function compareValues(a, b) {
|
|
62
|
+
const na = Number(a);
|
|
63
|
+
const nb = Number(b);
|
|
64
|
+
if (Number.isFinite(na) && Number.isFinite(nb)) {
|
|
65
|
+
return na - nb;
|
|
66
|
+
}
|
|
67
|
+
const sa = a == null ? '' : String(a);
|
|
68
|
+
const sb = b == null ? '' : String(b);
|
|
69
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
70
|
+
}
|
|
71
|
+
function toLines(input) {
|
|
72
|
+
return valueToText(input).split('\n');
|
|
73
|
+
}
|
|
74
|
+
/** Reduce a list of numbers by an aggregation op. Empty → null (no numeric values in the group). */
|
|
75
|
+
function applyAggregate(op, nums) {
|
|
76
|
+
if (nums.length === 0)
|
|
77
|
+
return null;
|
|
78
|
+
if (op === 'sum')
|
|
79
|
+
return nums.reduce((a, b) => a + b, 0);
|
|
80
|
+
if (op === 'avg')
|
|
81
|
+
return nums.reduce((a, b) => a + b, 0) / nums.length;
|
|
82
|
+
if (op === 'min')
|
|
83
|
+
return Math.min(...nums);
|
|
84
|
+
return Math.max(...nums);
|
|
85
|
+
}
|
|
86
|
+
// ─── object operators ───
|
|
87
|
+
const Where = {
|
|
88
|
+
name: 'where',
|
|
89
|
+
description: 'Keep array elements matching a predicate, e.g. "Balance > 0 and Status == \'Open\'".',
|
|
90
|
+
argsHint: 'predicate string (==, !=, <, >, <=, >=, contains, startsWith, endsWith, matches, in; and/or/not)',
|
|
91
|
+
apply(input, args) {
|
|
92
|
+
const arr = requireArray(input, 'where');
|
|
93
|
+
const ast = parsePredicate(asString(args, 'where'));
|
|
94
|
+
return arr.filter((el) => evaluatePredicate(ast, el));
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
const Select = {
|
|
98
|
+
name: 'select',
|
|
99
|
+
description: 'Project field(s) from each element. One field → array of values; many → array of objects.',
|
|
100
|
+
argsHint: 'a field path string, or an array of field paths',
|
|
101
|
+
apply(input, args) {
|
|
102
|
+
const fields = (Array.isArray(args) ? args : [args]).map((f) => asString(f, 'select'));
|
|
103
|
+
const project = (el) => {
|
|
104
|
+
if (fields.length === 1) {
|
|
105
|
+
return getValue(el, fields[0]) ?? null;
|
|
106
|
+
}
|
|
107
|
+
return fields.reduce((o, f) => {
|
|
108
|
+
o[lastSegment(f)] = getValue(el, f) ?? null;
|
|
109
|
+
return o;
|
|
110
|
+
}, {});
|
|
111
|
+
};
|
|
112
|
+
if (Array.isArray(input)) {
|
|
113
|
+
return input.map(project);
|
|
114
|
+
}
|
|
115
|
+
// Projecting off a non-array object that has a nested array, where none of the requested
|
|
116
|
+
// fields exist on the outer object, is the classic "forgot to extract the collection"
|
|
117
|
+
// mistake — fail loudly with the extraction hint instead of silently returning null (which
|
|
118
|
+
// would only surface as a confusing error one stage later).
|
|
119
|
+
const allMissing = fields.every((f) => getValue(input, f) === undefined);
|
|
120
|
+
if (allMissing && input !== null && typeof input === 'object' && Object.values(input).some(Array.isArray)) {
|
|
121
|
+
throw new Error(`"select" found none of [${fields.join(', ')}] on this value.${nonArrayHint(input)}`);
|
|
122
|
+
}
|
|
123
|
+
return project(input);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
const Sort = {
|
|
127
|
+
name: 'sort',
|
|
128
|
+
description: 'Sort an array by field(s). Prefix a field with "-" for descending.',
|
|
129
|
+
argsHint: 'a field path string (e.g. "-Balance"), or an array of them',
|
|
130
|
+
apply(input, args) {
|
|
131
|
+
const arr = requireArray(input, 'sort');
|
|
132
|
+
const keys = (Array.isArray(args) ? args : [args]).map((k) => asString(k, 'sort'));
|
|
133
|
+
return [...arr].sort((a, b) => {
|
|
134
|
+
for (const key of keys) {
|
|
135
|
+
const desc = key.startsWith('-');
|
|
136
|
+
const path = desc ? key.slice(1) : key;
|
|
137
|
+
const c = compareValues(getValue(a, path), getValue(b, path));
|
|
138
|
+
if (c !== 0) {
|
|
139
|
+
return desc ? -c : c;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return 0;
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
const First = {
|
|
147
|
+
name: 'first',
|
|
148
|
+
description: 'Keep the first N elements of an array.',
|
|
149
|
+
argsHint: 'a number N',
|
|
150
|
+
apply(input, args) {
|
|
151
|
+
return requireArray(input, 'first').slice(0, Math.max(0, asInt(args, 'first')));
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
const Last = {
|
|
155
|
+
name: 'last',
|
|
156
|
+
description: 'Keep the last N elements of an array.',
|
|
157
|
+
argsHint: 'a number N',
|
|
158
|
+
apply(input, args) {
|
|
159
|
+
const arr = requireArray(input, 'last');
|
|
160
|
+
const n = Math.max(0, asInt(args, 'last'));
|
|
161
|
+
return arr.slice(Math.max(0, arr.length - n));
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
const Count = {
|
|
165
|
+
name: 'count',
|
|
166
|
+
description: 'Replace the value with its size: array length, object key count, or string length.',
|
|
167
|
+
argsHint: 'no arguments',
|
|
168
|
+
apply(input) {
|
|
169
|
+
if (Array.isArray(input))
|
|
170
|
+
return input.length;
|
|
171
|
+
if (typeof input === 'string')
|
|
172
|
+
return input.length;
|
|
173
|
+
if (input !== null && typeof input === 'object')
|
|
174
|
+
return Object.keys(input).length;
|
|
175
|
+
return input == null ? 0 : 1;
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const Distinct = {
|
|
179
|
+
name: 'distinct',
|
|
180
|
+
description: 'Remove duplicate array elements, optionally by a field path.',
|
|
181
|
+
argsHint: 'optional field path to dedupe by; omit (or pass true) to dedupe whole elements',
|
|
182
|
+
apply(input, args) {
|
|
183
|
+
const arr = requireArray(input, 'distinct');
|
|
184
|
+
// A non-empty string arg dedupes by that field path; anything else (omitted, `true`, `{}`)
|
|
185
|
+
// dedupes by the whole element — so `{ "distinct": true }` after a `select` works as expected.
|
|
186
|
+
const field = typeof args === 'string' && args.trim() !== '' ? args : null;
|
|
187
|
+
const seen = new Set();
|
|
188
|
+
const keyOf = (el) => field ? valueToText(getValue(el, field) ?? null) : valueToText(el);
|
|
189
|
+
return arr.filter((el) => {
|
|
190
|
+
const k = keyOf(el);
|
|
191
|
+
if (seen.has(k))
|
|
192
|
+
return false;
|
|
193
|
+
seen.add(k);
|
|
194
|
+
return true;
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
const Flatten = {
|
|
199
|
+
name: 'flatten',
|
|
200
|
+
description: 'Flatten a nested array one level.',
|
|
201
|
+
argsHint: 'no arguments',
|
|
202
|
+
apply(input) {
|
|
203
|
+
return requireArray(input, 'flatten').flatMap((el) => (Array.isArray(el) ? el : [el]));
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
const GroupBy = {
|
|
207
|
+
name: 'groupBy',
|
|
208
|
+
description: 'Group array elements by field(s) and aggregate. Each group gets a "count"; optionally add ' +
|
|
209
|
+
'sum/avg/min/max of a numeric field (output keys like "sum_Amount"). This is how you answer ' +
|
|
210
|
+
'analytical questions over large data without returning the rows.',
|
|
211
|
+
argsHint: 'a field path (count per group), or { "by": <field | [fields]>, "sum"?: field, "avg"?: field, "min"?: field, "max"?: field }',
|
|
212
|
+
apply(input, args) {
|
|
213
|
+
const arr = requireArray(input, 'groupBy');
|
|
214
|
+
const cfg = typeof args === 'string' ? { by: args } : args ?? {};
|
|
215
|
+
const byList = Array.isArray(cfg.by) ? cfg.by : [cfg.by];
|
|
216
|
+
if (cfg.by == null || byList.some((f) => typeof f !== 'string' || f.trim() === '')) {
|
|
217
|
+
throw new Error('groupBy needs a "by" field — the field to group on, e.g. { "by": "Category", "sum": "Amount" }.');
|
|
218
|
+
}
|
|
219
|
+
const byFields = byList;
|
|
220
|
+
const aggSpecs = ['sum', 'avg', 'min', 'max']
|
|
221
|
+
.filter((op) => cfg[op] != null)
|
|
222
|
+
.map((op) => {
|
|
223
|
+
const field = cfg[op];
|
|
224
|
+
if (typeof field !== 'string' || field.trim() === '') {
|
|
225
|
+
throw new Error(`groupBy "${op}" needs a numeric field name, e.g. { "by": "Category", "${op}": "Amount" }.`);
|
|
226
|
+
}
|
|
227
|
+
return { op, field };
|
|
228
|
+
});
|
|
229
|
+
const groups = new Map();
|
|
230
|
+
for (const el of arr) {
|
|
231
|
+
const key = {};
|
|
232
|
+
for (const f of byFields) {
|
|
233
|
+
key[lastSegment(f)] = getValue(el, f) ?? null;
|
|
234
|
+
}
|
|
235
|
+
const mapKey = valueToText(byFields.map((f) => getValue(el, f) ?? null));
|
|
236
|
+
const existing = groups.get(mapKey);
|
|
237
|
+
if (existing) {
|
|
238
|
+
existing.rows.push(el);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
groups.set(mapKey, { key, rows: [el] });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return [...groups.values()].map(({ key, rows }) => {
|
|
245
|
+
const out = { ...key, count: rows.length };
|
|
246
|
+
for (const { op, field } of aggSpecs) {
|
|
247
|
+
const nums = rows.map((r) => Number(getValue(r, field))).filter((n) => Number.isFinite(n));
|
|
248
|
+
out[`${op}_${lastSegment(field)}`] = applyAggregate(op, nums);
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
});
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
const JsonPath = {
|
|
255
|
+
name: 'jsonpath',
|
|
256
|
+
description: 'Extract value(s) at a JSONPath (member/index/[*]/.. ). One match → the value; many → an array.',
|
|
257
|
+
argsHint: 'a JSONPath string, e.g. "$.Results[*].Status"',
|
|
258
|
+
apply(input, args) {
|
|
259
|
+
const matches = getValues(input, asString(args, 'jsonpath'));
|
|
260
|
+
if (matches.length === 0)
|
|
261
|
+
return null;
|
|
262
|
+
return matches.length === 1 ? matches[0] : matches;
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
// ─── text operators (coerce-to-text) ───
|
|
266
|
+
const Lines = {
|
|
267
|
+
name: 'lines',
|
|
268
|
+
description: 'Split a string value into an array of lines (so object operators can work on it).',
|
|
269
|
+
argsHint: 'no arguments',
|
|
270
|
+
apply(input) {
|
|
271
|
+
return toLines(input);
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
const Grep = {
|
|
275
|
+
name: 'grep',
|
|
276
|
+
description: 'Keep matching lines/elements by regex. On a string → matching lines (joined); on an array → matching elements.',
|
|
277
|
+
argsHint: '{ "pattern": "regex", "ignoreCase"?: bool, "invert"?: bool } or a bare pattern string',
|
|
278
|
+
apply(input, args) {
|
|
279
|
+
const opts = typeof args === 'string' ? { pattern: args } : args;
|
|
280
|
+
const pattern = asString(opts?.pattern, 'grep');
|
|
281
|
+
const flags = opts?.ignoreCase ? 'i' : '';
|
|
282
|
+
const invert = opts?.invert === true;
|
|
283
|
+
let regex;
|
|
284
|
+
try {
|
|
285
|
+
regex = new RegExp(pattern, flags);
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
throw new Error(`Invalid grep pattern "${pattern}": ${e.message}`);
|
|
289
|
+
}
|
|
290
|
+
const keep = (line) => regex.test(line) !== invert;
|
|
291
|
+
if (Array.isArray(input)) {
|
|
292
|
+
return input.filter((el) => keep(valueToText(el)));
|
|
293
|
+
}
|
|
294
|
+
return toLines(input).filter(keep).join('\n');
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
const Head = {
|
|
298
|
+
name: 'head',
|
|
299
|
+
description: 'First N LINES of a string (text only — use `first` for the first N array elements).',
|
|
300
|
+
argsHint: 'a number N',
|
|
301
|
+
apply(input, args) {
|
|
302
|
+
rejectArray(input, 'head', 'first');
|
|
303
|
+
const n = Math.max(0, asInt(args, 'head'));
|
|
304
|
+
return toLines(input).slice(0, n).join('\n');
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
const Tail = {
|
|
308
|
+
name: 'tail',
|
|
309
|
+
description: 'Last N LINES of a string (text only — use `last` for the last N array elements).',
|
|
310
|
+
argsHint: 'a number N',
|
|
311
|
+
apply(input, args) {
|
|
312
|
+
rejectArray(input, 'tail', 'last');
|
|
313
|
+
const n = Math.max(0, asInt(args, 'tail'));
|
|
314
|
+
const lines = toLines(input);
|
|
315
|
+
return lines.slice(Math.max(0, lines.length - n)).join('\n');
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
const ALL = [
|
|
319
|
+
Where, Select, Sort, First, Last, Count, Distinct, Flatten, GroupBy, JsonPath, Lines, Grep, Head, Tail,
|
|
320
|
+
];
|
|
321
|
+
const BY_NAME = new Map(ALL.map((o) => [o.name, o]));
|
|
322
|
+
/** All operators, in catalog order (for docs). */
|
|
323
|
+
export function GetAllOperators() {
|
|
324
|
+
return ALL;
|
|
325
|
+
}
|
|
326
|
+
/** Resolve an operator by verb name (exact, lowercase verbs). */
|
|
327
|
+
export function GetOperator(name) {
|
|
328
|
+
return BY_NAME.get(name);
|
|
329
|
+
}
|
|
330
|
+
/** Reserved verbs that are NOT operators (control constructs + capability stages). */
|
|
331
|
+
export const CONTROL_VERBS = new Set(['tool', 'map', 'let']);
|
|
332
|
+
//# sourceMappingURL=operators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../../src/pipeline/operators.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,kBAAkB;AAElB,SAAS,YAAY,CAAC,KAAgB,EAAE,EAAU;IAC9C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,IAAI,EAAE,mCAAmC,QAAQ,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACvG,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,KAAgB,EAAE,EAAU,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AE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CACzG,CAAC;AAEF,MAAM,OAAO,GAA0C,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5F,kDAAkD;AAClD,MAAM,UAAU,eAAe;IAC3B,OAAO,GAAG,CAAC;AACf,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,WAAW,CAAC,IAAY;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The one field-path grammar reused across `where`, `select`, `sort`, and `{{...}}`
|
|
3
|
+
* templating. Accepts root-relative paths (`Status`, `Customer.Email`, `Items[*].SKU`) as well as
|
|
4
|
+
* absolute (`$.Results[*].Name`). Built on the eval-free JSONPath evaluator — paths are parsed,
|
|
5
|
+
* never `eval`'d, so LLM-authored paths can't execute code.
|
|
6
|
+
*
|
|
7
|
+
* @module @memberjunction/ai-agents
|
|
8
|
+
*/
|
|
9
|
+
import { PipeValue } from './pipeline.types.js';
|
|
10
|
+
/** All values matching `path` within `value`. */
|
|
11
|
+
export declare function getValues(value: PipeValue, path: string): PipeValue[];
|
|
12
|
+
/** First value matching `path`, or undefined. Used by where/sort/template (single-valued contexts). */
|
|
13
|
+
export declare function getValue(value: PipeValue, path: string): PipeValue | undefined;
|
|
14
|
+
/** Field names available on an object value (for field-listing error messages). */
|
|
15
|
+
export declare function fieldNames(value: PipeValue): string[];
|
|
16
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/pipeline/path.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAe7C,iDAAiD;AACjD,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,CAErE;AAED,uGAAuG;AACvG,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAG9E;AAED,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,EAAE,CAUrD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { parseJsonPath, evaluateJsonPath } from './jsonpath-eval.js';
|
|
2
|
+
/** Normalize a relative path to absolute JSONPath form. `$`/`$.x` pass through; `x.y` → `$.x.y`. */
|
|
3
|
+
function toAbsolute(path) {
|
|
4
|
+
const p = path.trim();
|
|
5
|
+
if (p === '' || p === '$') {
|
|
6
|
+
return '$';
|
|
7
|
+
}
|
|
8
|
+
if (p.startsWith('$')) {
|
|
9
|
+
return p;
|
|
10
|
+
}
|
|
11
|
+
return p.startsWith('[') ? `$${p}` : `$.${p}`;
|
|
12
|
+
}
|
|
13
|
+
/** All values matching `path` within `value`. */
|
|
14
|
+
export function getValues(value, path) {
|
|
15
|
+
return evaluateJsonPath(parseJsonPath(toAbsolute(path)), value);
|
|
16
|
+
}
|
|
17
|
+
/** First value matching `path`, or undefined. Used by where/sort/template (single-valued contexts). */
|
|
18
|
+
export function getValue(value, path) {
|
|
19
|
+
const vs = getValues(value, path);
|
|
20
|
+
return vs.length > 0 ? vs[0] : undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Field names available on an object value (for field-listing error messages). */
|
|
23
|
+
export function fieldNames(value) {
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
// Surface the element fields — that's what `where`/`select` operate on.
|
|
26
|
+
const first = value.find((v) => v !== null && typeof v === 'object' && !Array.isArray(v));
|
|
27
|
+
return first ? Object.keys(first) : [];
|
|
28
|
+
}
|
|
29
|
+
if (value !== null && typeof value === 'object') {
|
|
30
|
+
return Object.keys(value);
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/pipeline/path.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAElE,oGAAoG;AACpG,SAAS,UAAU,CAAC,IAAY;IAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACtB,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QACxB,OAAO,GAAG,CAAC;IACf,CAAC;IACD,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,CAAC,CAAC;IACb,CAAC;IACD,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;AAClD,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,SAAS,CAAC,KAAgB,EAAE,IAAY;IACpD,OAAO,gBAAgB,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAgB,CAAC;AACnF,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,QAAQ,CAAC,KAAgB,EAAE,IAAY;IACnD,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClC,OAAO,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7C,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,UAAU,CAAC,KAAgB;IACvC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,wEAAwE;QACxE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1F,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAgC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the pipeline docs. Returns '' when there are no sources — a pipeline's first stage must be
|
|
3
|
+
* a capability (Action/artifact tool), so with none available pipelines are impossible.
|
|
4
|
+
*/
|
|
5
|
+
export declare function BuildPipelineToolDocs(sourceToolNames: string[]): string;
|
|
6
|
+
//# sourceMappingURL=pipeline-docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-docs.d.ts","sourceRoot":"","sources":["../../src/pipeline/pipeline-docs.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,MAAM,EAAE,GAAG,MAAM,CA2IvE"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Generates the `pipeline` tool documentation injected into the agent's system prompt
|
|
3
|
+
* (`_PIPELINE_TOOLS`). Teaches the value model, the verb catalog, the field-path grammar, and a few
|
|
4
|
+
* worked examples. Pure function.
|
|
5
|
+
*
|
|
6
|
+
* @module @memberjunction/ai-agents
|
|
7
|
+
*/
|
|
8
|
+
import { GetAllOperators } from './operators.js';
|
|
9
|
+
const MAX_SOURCES_LISTED = 50;
|
|
10
|
+
/**
|
|
11
|
+
* Build the pipeline docs. Returns '' when there are no sources — a pipeline's first stage must be
|
|
12
|
+
* a capability (Action/artifact tool), so with none available pipelines are impossible.
|
|
13
|
+
*/
|
|
14
|
+
export function BuildPipelineToolDocs(sourceToolNames) {
|
|
15
|
+
if (sourceToolNames.length === 0) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
const operators = GetAllOperators()
|
|
19
|
+
.map((o) => `- **${o.name}** — ${o.description} _(args: ${o.argsHint})_`)
|
|
20
|
+
.join('\n');
|
|
21
|
+
return [
|
|
22
|
+
'## Agent Pipelines',
|
|
23
|
+
'',
|
|
24
|
+
'Run a multi-step dataflow **server-side** so large intermediate results never enter your context. ' +
|
|
25
|
+
'Set `nextStep.type` to `"Pipeline"` and provide `nextStep.pipeline.steps` (a flat array); ' +
|
|
26
|
+
'**values flow between stages as structured JSON** ' +
|
|
27
|
+
'(arrays/objects), PowerShell-style — stages bind to fields, you do NOT re-parse text. Only the ' +
|
|
28
|
+
'FINAL stage\'s value is returned to you. Reach for this whenever a step produces a large payload ' +
|
|
29
|
+
'and you only need a slice/shape of it, or to chain several actions without paying context for the ' +
|
|
30
|
+
'data passing between them.',
|
|
31
|
+
'',
|
|
32
|
+
'### Keep the final value SMALL',
|
|
33
|
+
'Only the FINAL stage\'s value is returned to you — every intermediate stays server-side, so those tokens ' +
|
|
34
|
+
'are saved. Make the last stage small: end with `select`/`count`/`first`, and **inside `map`, extract or ' +
|
|
35
|
+
'reduce each element** (e.g. `grep` then `count`, or `select` a few fields). Do NOT let a `map` return ' +
|
|
36
|
+
'whole fetched pages/records — that large payload would become your final value. Fetch big, return small.',
|
|
37
|
+
'',
|
|
38
|
+
'### Stage kinds (one verb per stage)',
|
|
39
|
+
'- **Capability:** `{ "tool": "<name>", "with": { ...params }, "pipeInto": "<paramName>" }` — run an ' +
|
|
40
|
+
'Action/artifact tool. `pipeInto` puts the whole upstream value into that param; omit it for a ' +
|
|
41
|
+
'source (first stage). Params may use `{{ path }}` templates over the upstream value (`$`) or ' +
|
|
42
|
+
'map/let bindings.',
|
|
43
|
+
'- **Operators** (pure, applied to the upstream value):',
|
|
44
|
+
operators,
|
|
45
|
+
'- **`map`:** `{ "map": { "as": "row", "do": [ ...sub-stages ] } }` — run the sub-pipeline once per ' +
|
|
46
|
+
'array element (`{{row.field}}` available inside). **`map` REPLACES the array with each element\'s ' +
|
|
47
|
+
'FINAL sub-stage value** — it does NOT add a field to existing rows. Use it for per-element *actions/' +
|
|
48
|
+
'transforms* (e.g. send an email per row), NOT to compute a column. To filter/sort/aggregate or keep ' +
|
|
49
|
+
'fields, use the operators directly (`where`/`select`/`sort`/`groupBy`) — no `map` needed.',
|
|
50
|
+
'- **`let`:** `{ "let": { "name": "x", "value": [ ...sub-stages ] } }` — capture a result as `{{x}}` ' +
|
|
51
|
+
'for later stages; the main stream passes through unchanged (use for joins/correlation).',
|
|
52
|
+
'',
|
|
53
|
+
'### Field paths',
|
|
54
|
+
'Used by `where`/`select`/`sort`/templates: `Status`, `Customer.Email`, `Results[0].Name`, `Items[*].SKU`. ' +
|
|
55
|
+
'`where` predicates support `== != < > <= >= contains startsWith endsWith matches in` and `and/or/not`, ' +
|
|
56
|
+
'e.g. `Balance > 0 and Status == \'Open\'`.',
|
|
57
|
+
'',
|
|
58
|
+
'### Input shapes — operators need an ARRAY',
|
|
59
|
+
'`where`/`select`/`sort`/`distinct`/`first`/`last` operate on an **array of objects**. Tabular tools ' +
|
|
60
|
+
'(`get_rows`) already hand you that array of row objects — pipe them straight into `where`/`select`, ' +
|
|
61
|
+
'no unwrapping needed. If a source instead returns a wrapper object (e.g. `{ "Results": [...] }`), ' +
|
|
62
|
+
'extract the array first with a `{ "jsonpath": "$.Results[*]" }` stage. When an operator reports ' +
|
|
63
|
+
'"expects an array but received an object", read the listed keys and add exactly that `jsonpath` stage.',
|
|
64
|
+
'',
|
|
65
|
+
'### Sources available now',
|
|
66
|
+
sourceToolNames.slice(0, MAX_SOURCES_LISTED).map((n) => `\`${n}\``).join(', ') +
|
|
67
|
+
(sourceToolNames.length > MAX_SOURCES_LISTED ? ', …' : '') +
|
|
68
|
+
' (artifact tools take an `artifactId` param).',
|
|
69
|
+
'',
|
|
70
|
+
'### Examples',
|
|
71
|
+
'```json',
|
|
72
|
+
JSON.stringify({
|
|
73
|
+
nextStep: {
|
|
74
|
+
type: 'Pipeline',
|
|
75
|
+
pipeline: {
|
|
76
|
+
steps: [
|
|
77
|
+
{ tool: sourceToolNames[0], with: {} },
|
|
78
|
+
{ where: "Status == 'Rejected'" },
|
|
79
|
+
{ select: ['ID', 'Email'] },
|
|
80
|
+
{ first: 10 },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
}, null, 2),
|
|
85
|
+
'```',
|
|
86
|
+
'Batch action chain (intermediates never in context):',
|
|
87
|
+
'```json',
|
|
88
|
+
JSON.stringify({
|
|
89
|
+
nextStep: {
|
|
90
|
+
type: 'Pipeline',
|
|
91
|
+
pipeline: {
|
|
92
|
+
steps: [
|
|
93
|
+
{ tool: sourceToolNames[0], with: {} },
|
|
94
|
+
{ where: 'Balance > 0' },
|
|
95
|
+
{ map: { as: 'row', do: [{ tool: sourceToolNames[0], with: { Note: '{{row.ID}}' } }] } },
|
|
96
|
+
{ count: true },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
}, null, 2),
|
|
101
|
+
'```',
|
|
102
|
+
'Tabular artifact tool — `get_rows` yields the row objects directly; filter and shape them with no unwrapping:',
|
|
103
|
+
'```json',
|
|
104
|
+
JSON.stringify({
|
|
105
|
+
nextStep: {
|
|
106
|
+
type: 'Pipeline',
|
|
107
|
+
pipeline: {
|
|
108
|
+
steps: [
|
|
109
|
+
{ tool: 'get_rows', with: { artifactId: 'A', start: 0, count: 500 } },
|
|
110
|
+
{ where: "Department == 'Engineering' and Status == 'Active'" },
|
|
111
|
+
{ select: ['EmployeeID', 'Name', 'Region'] },
|
|
112
|
+
{ distinct: 'Region' },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
}, null, 2),
|
|
117
|
+
'```',
|
|
118
|
+
'Analytical question over a LARGE file — aggregate server-side, return a tiny summary (the raw ' +
|
|
119
|
+
'rows never enter your context, so this works even when the file is too big to read whole):',
|
|
120
|
+
'```json',
|
|
121
|
+
JSON.stringify({
|
|
122
|
+
nextStep: {
|
|
123
|
+
type: 'Pipeline',
|
|
124
|
+
pipeline: {
|
|
125
|
+
steps: [
|
|
126
|
+
{ tool: 'get_full', with: { artifactId: 'A' } },
|
|
127
|
+
{ groupBy: { by: 'Category', sum: 'Amount', avg: 'Amount' } },
|
|
128
|
+
{ sort: '-sum_Amount' },
|
|
129
|
+
{ first: 10 },
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
}, null, 2),
|
|
134
|
+
'```',
|
|
135
|
+
].join('\n');
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=pipeline-docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-docs.js","sourceRoot":"","sources":["../../src/pipeline/pipeline-docs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,eAAyB;IAC3D,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,EAAE,CAAC;IACd,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AAE;wBAC5C,EAAE,QAAQ,EAAE,QAAQ,EAAE;qBACzB;iBACJ;aACJ;SACJ,EACD,IAAI,EACJ,CAAC,CACJ;QACD,KAAK;QACL,gGAAgG;YAC5F,4FAA4F;QAChG,SAAS;QACT,IAAI,CAAC,SAAS,CACV;YACI,QAAQ,EAAE;gBACN,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE;oBACN,KAAK,EAAE;wBACH,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE;wBAC/C,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE;wBAC7D,EAAE,IAAI,EAAE,aAAa,EAAE;wBACvB,EAAE,KAAK,EAAE,EAAE,EAAE;qBAChB;iBACJ;aACJ;SACJ,EACD,IAAI,EACJ,CAAC,CACJ;QACD,KAAK;KACR,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The Agent Pipeline executor — runs a server-side dataflow over {@link PipeValue}s.
|
|
3
|
+
*
|
|
4
|
+
* Stage kinds:
|
|
5
|
+
* - operator (`where`/`select`/…) — pure, applied directly.
|
|
6
|
+
* - `tool` — an Action/artifact tool; params get `{{template}}` resolution + optional `pipeInto`
|
|
7
|
+
* (the whole upstream value injected into a named param).
|
|
8
|
+
* - `map` — run a sub-pipeline per element of an array (bounded concurrency, caps, fail-policy).
|
|
9
|
+
* - `let` — run a sub-pipeline, bind its result to a name for later `{{name}}` use; stream unchanged.
|
|
10
|
+
*
|
|
11
|
+
* Only top-level stages produce log records; `map`/`let` summarize. Fails fast with an agent-facing
|
|
12
|
+
* message (never echoes a piped value; field-errors list available fields).
|
|
13
|
+
*
|
|
14
|
+
* @module @memberjunction/ai-agents
|
|
15
|
+
*/
|
|
16
|
+
import { PipelineStage, PipelineExecutionResult } from './pipeline.types.js';
|
|
17
|
+
import { PipelineToolRegistry } from './pipeline-registry.js';
|
|
18
|
+
export declare const MAX_PIPELINE_STAGES = 20;
|
|
19
|
+
export declare const MAX_MAP_ELEMENTS = 1000;
|
|
20
|
+
export declare const MAP_CONCURRENCY = 8;
|
|
21
|
+
/** Default wall-clock budget for an entire pipeline (incl. all map/let sub-pipelines). */
|
|
22
|
+
export declare const DEFAULT_PIPELINE_DEADLINE_MS = 120000;
|
|
23
|
+
/** Optional runtime controls for a pipeline execution. */
|
|
24
|
+
export interface PipelineExecutorOptions {
|
|
25
|
+
/** Wall-clock budget for the whole pipeline. Checked between stages + map batches. */
|
|
26
|
+
deadlineMs?: number;
|
|
27
|
+
/** Caller cancellation; honored at the same checkpoints as the deadline. */
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
export declare class PipelineExecutor {
|
|
31
|
+
private readonly registry;
|
|
32
|
+
private readonly maxStages;
|
|
33
|
+
/**
|
|
34
|
+
* Total bytes produced by every stage anywhere in the tree (incl. map/let sub-pipelines).
|
|
35
|
+
* INSTANCE state, not shared: a fresh executor is created per pipeline run (see
|
|
36
|
+
* `base-agent.executePipelineAsStep`), so concurrent agent turns each get their own counter —
|
|
37
|
+
* this is never read/written across parallel runs. Do NOT make PipelineExecutor a singleton.
|
|
38
|
+
*/
|
|
39
|
+
private producedBytes;
|
|
40
|
+
/** Absolute wall-clock deadline (epoch ms) for this run; set at the start of {@link Execute}. */
|
|
41
|
+
private deadlineAt;
|
|
42
|
+
private readonly deadlineMs;
|
|
43
|
+
private readonly signal?;
|
|
44
|
+
constructor(registry: PipelineToolRegistry, maxStages?: number, opts?: PipelineExecutorOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Throw if the run has been cancelled or has blown its wall-clock budget. Checked between
|
|
47
|
+
* top-level stages, before each `map` batch, and before each sub-pipeline stage — so a long
|
|
48
|
+
* `map` over many elements (or a chain of slow Actions) can't run unbounded. NOTE: this bounds
|
|
49
|
+
* wall-clock *between* stage invocations; it does not interrupt a single in-flight Action mid-call
|
|
50
|
+
* (that needs Action-level cancellation — a follow-up once the Action layer accepts an AbortSignal).
|
|
51
|
+
*/
|
|
52
|
+
private checkAbort;
|
|
53
|
+
/** Validate + run a pipeline. Returns a structured result; never throws on stage failure. */
|
|
54
|
+
Execute(stages: PipelineStage[]): Promise<PipelineExecutionResult>;
|
|
55
|
+
private validateShape;
|
|
56
|
+
/** Dispatch one stage. Never throws — converts errors into a failed outcome. */
|
|
57
|
+
private runStage;
|
|
58
|
+
private runOperatorStage;
|
|
59
|
+
private runToolStage;
|
|
60
|
+
private runMapStage;
|
|
61
|
+
private runLetStage;
|
|
62
|
+
/** Run a sub-pipeline (map/let) with no top-level record-keeping; fails fast internally. */
|
|
63
|
+
private runStages;
|
|
64
|
+
private failure;
|
|
65
|
+
/**
|
|
66
|
+
* Bytes the LLM never saw: everything produced anywhere in the tree (top-level + every map/let
|
|
67
|
+
* sub-pipeline stage) minus the single final value that is returned. Map/let internal fetches
|
|
68
|
+
* (e.g. full pages fetched per element) are counted here, not just top-level stages.
|
|
69
|
+
*/
|
|
70
|
+
private computeSaved;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=pipeline-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-executor.d.ts","sourceRoot":"","sources":["../../src/pipeline/pipeline-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAEH,aAAa,EAEb,uBAAuB,EAE1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAK3D,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC,0FAA0F;AAC1F,eAAO,MAAM,4BAA4B,SAAU,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