agentlang 0.7.9 → 0.7.11
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/out/api/http.d.ts.map +1 -1
- package/out/api/http.js +8 -1
- package/out/api/http.js.map +1 -1
- package/out/cli/main.d.ts.map +1 -1
- package/out/cli/main.js +33 -2
- package/out/cli/main.js.map +1 -1
- package/out/extension/main.cjs +250 -250
- package/out/extension/main.cjs.map +2 -2
- package/out/language/agentlang-validator.d.ts +1 -2
- package/out/language/agentlang-validator.d.ts.map +1 -1
- package/out/language/agentlang-validator.js +0 -39
- package/out/language/agentlang-validator.js.map +1 -1
- package/out/language/generated/ast.d.ts +62 -11
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +75 -3
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/generated/grammar.d.ts.map +1 -1
- package/out/language/generated/grammar.js +758 -239
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/main.cjs +1370 -824
- package/out/language/main.cjs.map +4 -4
- package/out/language/parser.d.ts +1 -0
- package/out/language/parser.d.ts.map +1 -1
- package/out/language/parser.js +44 -7
- package/out/language/parser.js.map +1 -1
- package/out/language/syntax.d.ts +1 -1
- package/out/language/syntax.d.ts.map +1 -1
- package/out/language/syntax.js +22 -13
- package/out/language/syntax.js.map +1 -1
- package/out/runtime/api.d.ts +2 -0
- package/out/runtime/api.d.ts.map +1 -1
- package/out/runtime/api.js +5 -0
- package/out/runtime/api.js.map +1 -1
- package/out/runtime/auth/cognito.d.ts.map +1 -1
- package/out/runtime/auth/cognito.js +4 -4
- package/out/runtime/auth/cognito.js.map +1 -1
- package/out/runtime/defs.d.ts +5 -0
- package/out/runtime/defs.d.ts.map +1 -1
- package/out/runtime/defs.js +16 -0
- package/out/runtime/defs.js.map +1 -1
- package/out/runtime/exec-graph.js +1 -1
- package/out/runtime/exec-graph.js.map +1 -1
- package/out/runtime/interpreter.d.ts +6 -1
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +144 -112
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/loader.d.ts +1 -1
- package/out/runtime/loader.d.ts.map +1 -1
- package/out/runtime/loader.js +74 -27
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/module.d.ts +41 -11
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +238 -50
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +13 -6
- package/out/runtime/modules/ai.js.map +1 -1
- package/out/runtime/modules/auth.d.ts +2 -1
- package/out/runtime/modules/auth.d.ts.map +1 -1
- package/out/runtime/modules/auth.js +93 -3
- package/out/runtime/modules/auth.js.map +1 -1
- package/out/runtime/modules/core.d.ts +7 -5
- package/out/runtime/modules/core.d.ts.map +1 -1
- package/out/runtime/modules/core.js +93 -16
- package/out/runtime/modules/core.js.map +1 -1
- package/out/runtime/monitor.d.ts.map +1 -1
- package/out/runtime/monitor.js +1 -0
- package/out/runtime/monitor.js.map +1 -1
- package/out/runtime/resolvers/interface.d.ts +6 -1
- package/out/runtime/resolvers/interface.d.ts.map +1 -1
- package/out/runtime/resolvers/interface.js +2 -2
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/sqldb/database.d.ts +19 -2
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/database.js +107 -21
- package/out/runtime/resolvers/sqldb/database.js.map +1 -1
- package/out/runtime/resolvers/sqldb/dbutil.d.ts +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/dbutil.js +25 -3
- package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.d.ts +3 -2
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +80 -6
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/state.d.ts +58 -0
- package/out/runtime/state.d.ts.map +1 -1
- package/out/runtime/state.js +12 -0
- package/out/runtime/state.js.map +1 -1
- package/out/runtime/util.d.ts +1 -1
- package/out/runtime/util.d.ts.map +1 -1
- package/out/runtime/util.js +27 -13
- package/out/runtime/util.js.map +1 -1
- package/out/setupClassic.d.ts +98 -0
- package/out/setupClassic.d.ts.map +1 -0
- package/out/setupClassic.js +38 -0
- package/out/setupClassic.js.map +1 -0
- package/out/setupCommon.d.ts +2 -0
- package/out/setupCommon.d.ts.map +1 -0
- package/out/setupCommon.js +33 -0
- package/out/setupCommon.js.map +1 -0
- package/out/setupExtended.d.ts +40 -0
- package/out/setupExtended.d.ts.map +1 -0
- package/out/setupExtended.js +67 -0
- package/out/setupExtended.js.map +1 -0
- package/out/syntaxes/agentlang.monarch.js +1 -1
- package/out/syntaxes/agentlang.monarch.js.map +1 -1
- package/package.json +187 -185
- package/src/api/http.ts +8 -0
- package/src/cli/main.ts +38 -2
- package/src/language/agentlang-validator.ts +1 -51
- package/src/language/agentlang.langium +17 -4
- package/src/language/generated/ast.ts +147 -13
- package/src/language/generated/grammar.ts +758 -239
- package/src/language/parser.ts +43 -8
- package/src/language/syntax.ts +25 -12
- package/src/runtime/api.ts +8 -0
- package/src/runtime/defs.ts +8 -0
- package/src/runtime/interpreter.ts +104 -76
- package/src/runtime/loader.ts +75 -25
- package/src/runtime/module.ts +194 -32
- package/src/runtime/modules/ai.ts +10 -4
- package/src/runtime/modules/auth.ts +1 -0
- package/src/runtime/modules/core.ts +99 -23
- package/src/runtime/monitor.ts +1 -0
- package/src/runtime/resolvers/interface.ts +9 -2
- package/src/runtime/resolvers/sqldb/database.ts +68 -17
- package/src/runtime/resolvers/sqldb/dbutil.ts +28 -6
- package/src/runtime/resolvers/sqldb/impl.ts +86 -14
- package/src/runtime/state.ts +14 -0
- package/src/runtime/util.ts +25 -12
- package/src/syntaxes/agentlang.monarch.ts +1 -1
|
@@ -10,13 +10,14 @@ import { AdminSession, AdminUserId } from './auth/defs.js';
|
|
|
10
10
|
import { AgentInstance, AgentEntityName, AgentFqName, findAgentByName, trimGeneratedCode, } from './modules/ai.js';
|
|
11
11
|
import { logger } from './logger.js';
|
|
12
12
|
import { FlowSuspensionTag, ParentAttributeName, PathAttributeName, PathAttributeNameQuery, } from './defs.js';
|
|
13
|
-
import { addCreateAudit, addDeleteAudit, addUpdateAudit, createSuspension, flushMonitoringData,
|
|
13
|
+
import { addCreateAudit, addDeleteAudit, addUpdateAudit, createSuspension, flushMonitoringData, triggerTimer, } from './modules/core.js';
|
|
14
14
|
import { invokeModuleFn } from './jsmodules.js';
|
|
15
15
|
import { invokeOpenApiEvent, isOpenApiEventInstance } from './openapi.js';
|
|
16
16
|
import { fetchDoc } from './docs.js';
|
|
17
17
|
import { getAgentFlow } from './agents/flows.js';
|
|
18
18
|
import { isMonitoringEnabled } from './state.js';
|
|
19
19
|
import { Monitor, MonitorEntry } from './monitor.js';
|
|
20
|
+
import { detailedDiff } from 'deep-object-diff';
|
|
20
21
|
const EmptyResult = null;
|
|
21
22
|
export function isEmptyResult(r) {
|
|
22
23
|
return r == EmptyResult;
|
|
@@ -76,7 +77,7 @@ export class Environment extends Instance {
|
|
|
76
77
|
}
|
|
77
78
|
this.preGeneratedSuspensionId = crypto.randomUUID();
|
|
78
79
|
}
|
|
79
|
-
static from(parent, name, isAsync = false) {
|
|
80
|
+
static from(parent, name, isAsync = false, mergeScratchPad = false) {
|
|
80
81
|
const env = new Environment(name, parent);
|
|
81
82
|
if (isAsync) {
|
|
82
83
|
env.activeResolvers = new Map();
|
|
@@ -84,6 +85,11 @@ export class Environment extends Instance {
|
|
|
84
85
|
env.activeCatchHandlers = new Array();
|
|
85
86
|
env.preGeneratedSuspensionId = parent.preGeneratedSuspensionId;
|
|
86
87
|
}
|
|
88
|
+
if (mergeScratchPad && parent.scratchPad) {
|
|
89
|
+
Object.keys(parent.scratchPad).forEach((k) => {
|
|
90
|
+
env.bind(k, parent.scratchPad[k]);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
87
93
|
return env;
|
|
88
94
|
}
|
|
89
95
|
static fromInstance(inst) {
|
|
@@ -359,6 +365,10 @@ export class Environment extends Instance {
|
|
|
359
365
|
getActiveModuleName() {
|
|
360
366
|
return this.activeModule;
|
|
361
367
|
}
|
|
368
|
+
setActiveModuleName(n) {
|
|
369
|
+
this.activeModule = n;
|
|
370
|
+
return this;
|
|
371
|
+
}
|
|
362
372
|
switchActiveModuleName(newModuleName) {
|
|
363
373
|
const oldModuleName = this.activeModule;
|
|
364
374
|
this.activeModule = newModuleName;
|
|
@@ -1082,6 +1092,7 @@ async function patternToInstance(entryName, attributes, env) {
|
|
|
1082
1092
|
const attrs = newInstanceAttributes();
|
|
1083
1093
|
let qattrs;
|
|
1084
1094
|
let qattrVals;
|
|
1095
|
+
let aggregates;
|
|
1085
1096
|
const isQueryAll = entryName.endsWith(QuerySuffix);
|
|
1086
1097
|
if (isQueryAll) {
|
|
1087
1098
|
entryName = entryName.slice(0, entryName.length - 1);
|
|
@@ -1089,23 +1100,30 @@ async function patternToInstance(entryName, attributes, env) {
|
|
|
1089
1100
|
if (attributes) {
|
|
1090
1101
|
for (let i = 0; i < attributes.length; ++i) {
|
|
1091
1102
|
const a = attributes[i];
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
if (
|
|
1097
|
-
|
|
1103
|
+
if (a.value !== undefined) {
|
|
1104
|
+
await evaluateExpression(a.value, env);
|
|
1105
|
+
const v = env.getLastResult();
|
|
1106
|
+
let aname = a.name;
|
|
1107
|
+
if (aname.endsWith(QuerySuffix)) {
|
|
1108
|
+
if (isQueryAll) {
|
|
1109
|
+
throw new Error(`Cannot specifiy query attribute ${aname} here`);
|
|
1110
|
+
}
|
|
1111
|
+
if (qattrs === undefined)
|
|
1112
|
+
qattrs = newInstanceAttributes();
|
|
1113
|
+
if (qattrVals === undefined)
|
|
1114
|
+
qattrVals = newInstanceAttributes();
|
|
1115
|
+
aname = aname.slice(0, aname.length - 1);
|
|
1116
|
+
qattrs.set(aname, a.op === undefined ? '=' : a.op);
|
|
1117
|
+
qattrVals.set(aname, v);
|
|
1118
|
+
}
|
|
1119
|
+
else {
|
|
1120
|
+
attrs.set(aname, v);
|
|
1098
1121
|
}
|
|
1099
|
-
if (qattrs === undefined)
|
|
1100
|
-
qattrs = newInstanceAttributes();
|
|
1101
|
-
if (qattrVals === undefined)
|
|
1102
|
-
qattrVals = newInstanceAttributes();
|
|
1103
|
-
aname = aname.slice(0, aname.length - 1);
|
|
1104
|
-
qattrs.set(aname, a.op === undefined ? '=' : a.op);
|
|
1105
|
-
qattrVals.set(aname, v);
|
|
1106
1122
|
}
|
|
1107
|
-
else {
|
|
1108
|
-
|
|
1123
|
+
else if (a.aggregate !== undefined) {
|
|
1124
|
+
if (aggregates === undefined)
|
|
1125
|
+
aggregates = new Map();
|
|
1126
|
+
aggregates.set(escapeQueryName(a.name), { name: a.aggregate.name, args: a.aggregate.args });
|
|
1109
1127
|
}
|
|
1110
1128
|
}
|
|
1111
1129
|
}
|
|
@@ -1117,7 +1135,11 @@ async function patternToInstance(entryName, attributes, env) {
|
|
|
1117
1135
|
if (p.hasEntry())
|
|
1118
1136
|
entryName = p.getEntryName();
|
|
1119
1137
|
}
|
|
1120
|
-
|
|
1138
|
+
const inst = makeInstance(moduleName, entryName, attrs, qattrs, qattrVals, isQueryAll);
|
|
1139
|
+
if (aggregates !== undefined) {
|
|
1140
|
+
return inst.setAggregates(aggregates);
|
|
1141
|
+
}
|
|
1142
|
+
return inst;
|
|
1121
1143
|
}
|
|
1122
1144
|
async function instanceFromSource(crud, env) {
|
|
1123
1145
|
if (crud.source) {
|
|
@@ -1168,6 +1190,14 @@ async function maybeValidateOneOfRefs(inst, env) {
|
|
|
1168
1190
|
}
|
|
1169
1191
|
}
|
|
1170
1192
|
}
|
|
1193
|
+
function maybeSetQueryClauses(inst, crud) {
|
|
1194
|
+
if (crud.groupByClause) {
|
|
1195
|
+
inst.setGroupBy(crud.groupByClause.colNames);
|
|
1196
|
+
}
|
|
1197
|
+
if (crud.orderByClause) {
|
|
1198
|
+
inst.setOrderBy(crud.orderByClause.colNames, crud.orderByClause.order === '@desc');
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1171
1201
|
async function evaluateCrudMap(crud, env) {
|
|
1172
1202
|
var _a, _b, _c;
|
|
1173
1203
|
if (!env.isInUpsertMode() && crud.upsert.length > 0) {
|
|
@@ -1180,8 +1210,10 @@ async function evaluateCrudMap(crud, env) {
|
|
|
1180
1210
|
const moduleName = inst.moduleName;
|
|
1181
1211
|
const attrs = inst.attributes;
|
|
1182
1212
|
const qattrs = inst.queryAttributes;
|
|
1183
|
-
const
|
|
1213
|
+
const onlyAggregates = inst.aggregates !== undefined && qattrs === undefined;
|
|
1214
|
+
const isQueryAll = onlyAggregates || crud.name.endsWith(QuerySuffix);
|
|
1184
1215
|
const distinct = crud.distinct.length > 0;
|
|
1216
|
+
maybeSetQueryClauses(inst, crud);
|
|
1185
1217
|
if (attrs.size > 0) {
|
|
1186
1218
|
await maybeValidateOneOfRefs(inst, env);
|
|
1187
1219
|
}
|
|
@@ -1192,8 +1224,8 @@ async function evaluateCrudMap(crud, env) {
|
|
|
1192
1224
|
if (qattrs === undefined && !isQueryAll) {
|
|
1193
1225
|
throw new Error(`Pattern for ${entryName} with 'into' clause must be a query`);
|
|
1194
1226
|
}
|
|
1195
|
-
if (crud.
|
|
1196
|
-
await evaluateJoinQuery(crud.
|
|
1227
|
+
if (crud.joins.length > 0) {
|
|
1228
|
+
await evaluateJoinQuery(crud.joins, crud.into, crud.where, inst, distinct, env);
|
|
1197
1229
|
}
|
|
1198
1230
|
else {
|
|
1199
1231
|
await evaluateJoinQueryWithRelationships(crud.into, inst, crud.relationships, distinct, env);
|
|
@@ -1211,7 +1243,7 @@ async function evaluateCrudMap(crud, env) {
|
|
|
1211
1243
|
const res = await getResolverForPath(entryName, moduleName, env);
|
|
1212
1244
|
let r;
|
|
1213
1245
|
await computeExprAttributes(inst, undefined, undefined, env);
|
|
1214
|
-
setMetaAttributes(inst.attributes, env);
|
|
1246
|
+
await setMetaAttributes(inst.attributes, env);
|
|
1215
1247
|
if (env.isInUpsertMode()) {
|
|
1216
1248
|
await runPreUpdateEvents(inst, env);
|
|
1217
1249
|
r = await res.upsertInstance(inst);
|
|
@@ -1323,7 +1355,7 @@ async function evaluateCrudMap(crud, env) {
|
|
|
1323
1355
|
await computeExprAttributes(lastRes[i], (_b = crud.body) === null || _b === void 0 ? void 0 : _b.attributes, attrs, env);
|
|
1324
1356
|
env.attributes.set('__patch', attrs);
|
|
1325
1357
|
await runPreUpdateEvents(lastRes[i], env);
|
|
1326
|
-
setMetaAttributes(attrs, env, true);
|
|
1358
|
+
await setMetaAttributes(attrs, env, true);
|
|
1327
1359
|
const finalInst = await resolver.updateInstance(lastRes[i], attrs);
|
|
1328
1360
|
await runPostUpdateEvents(finalInst, lastRes[i], env);
|
|
1329
1361
|
res.push(finalInst);
|
|
@@ -1381,47 +1413,6 @@ async function handleDocEvent(inst, env) {
|
|
|
1381
1413
|
await parseAndEvaluateStatement(`{${CoreAIModuleName}/Document {title "${title}", content "${s}"}}`, undefined, env);
|
|
1382
1414
|
}
|
|
1383
1415
|
}
|
|
1384
|
-
function triggerTimer(timerInst) {
|
|
1385
|
-
const dur = timerInst.lookup('duration');
|
|
1386
|
-
const unit = timerInst.lookup('unit');
|
|
1387
|
-
let millisecs = 0;
|
|
1388
|
-
switch (unit) {
|
|
1389
|
-
case 'millisecond': {
|
|
1390
|
-
millisecs = dur;
|
|
1391
|
-
break;
|
|
1392
|
-
}
|
|
1393
|
-
case 'second': {
|
|
1394
|
-
millisecs = dur * 1000;
|
|
1395
|
-
break;
|
|
1396
|
-
}
|
|
1397
|
-
case 'minute': {
|
|
1398
|
-
millisecs = dur * 60 * 1000;
|
|
1399
|
-
break;
|
|
1400
|
-
}
|
|
1401
|
-
case 'hour': {
|
|
1402
|
-
millisecs = dur * 60 * 60 * 1000;
|
|
1403
|
-
break;
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
const eventName = nameToPath(timerInst.lookup('trigger'));
|
|
1407
|
-
const m = eventName.hasModule() ? eventName.getModuleName() : timerInst.moduleName;
|
|
1408
|
-
const n = eventName.getEntryName();
|
|
1409
|
-
const inst = makeInstance(m, n, newInstanceAttributes());
|
|
1410
|
-
const name = timerInst.lookup('name');
|
|
1411
|
-
const timer = setInterval(async () => {
|
|
1412
|
-
const env = new Environment();
|
|
1413
|
-
try {
|
|
1414
|
-
await evaluate(inst, (result) => logger.debug(`Timer ${name} ran with result ${result}`), env);
|
|
1415
|
-
await env.commitAllTransactions();
|
|
1416
|
-
await maybeCancelTimer(name, timer, env);
|
|
1417
|
-
}
|
|
1418
|
-
catch (reason) {
|
|
1419
|
-
logger.error(`Timer ${name} raised error: ${reason}`);
|
|
1420
|
-
}
|
|
1421
|
-
}, millisecs);
|
|
1422
|
-
setTimerRunning(timerInst);
|
|
1423
|
-
return timerInst;
|
|
1424
|
-
}
|
|
1425
1416
|
async function computeExprAttributes(inst, origAttrs, updatedAttrs, env) {
|
|
1426
1417
|
const exprAttrs = inst.getExprAttributes();
|
|
1427
1418
|
if (exprAttrs || origAttrs) {
|
|
@@ -1452,7 +1443,7 @@ async function computeExprAttributes(inst, origAttrs, updatedAttrs, env) {
|
|
|
1452
1443
|
for (let i = 0; i < origAttrs.length; ++i) {
|
|
1453
1444
|
const a = origAttrs[i];
|
|
1454
1445
|
const n = a.name;
|
|
1455
|
-
if (!n.endsWith(QuerySuffix) && updatedAttrs.has(n)) {
|
|
1446
|
+
if (!n.endsWith(QuerySuffix) && updatedAttrs.has(n) && a.value !== undefined) {
|
|
1456
1447
|
await evaluateExpression(a.value, newEnv);
|
|
1457
1448
|
const v = newEnv.getLastResult();
|
|
1458
1449
|
updatedAttrs.set(n, v);
|
|
@@ -1462,21 +1453,58 @@ async function computeExprAttributes(inst, origAttrs, updatedAttrs, env) {
|
|
|
1462
1453
|
}
|
|
1463
1454
|
}
|
|
1464
1455
|
}
|
|
1465
|
-
async function
|
|
1456
|
+
async function evalWhereClauses(whereSpec, env) {
|
|
1457
|
+
const result = new Array();
|
|
1458
|
+
const e = new Environment(undefined, env);
|
|
1459
|
+
for (let i = 0; i < whereSpec.clauses.length; ++i) {
|
|
1460
|
+
const c = whereSpec.clauses[i];
|
|
1461
|
+
await evaluateExpression(c.rhs, e);
|
|
1462
|
+
result.push({
|
|
1463
|
+
attrName: escapeQueryName(c.lhs),
|
|
1464
|
+
op: c.op === undefined ? '=' : c.op,
|
|
1465
|
+
qval: e.getLastResult(),
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
return result;
|
|
1469
|
+
}
|
|
1470
|
+
async function evaluateJoinQuery(joinSpec, intoSpec, whereSpec, inst, distinct, env) {
|
|
1466
1471
|
const normIntoSpec = new Map();
|
|
1472
|
+
let aggregates;
|
|
1467
1473
|
intoSpec.entries.forEach((entry) => {
|
|
1468
|
-
|
|
1474
|
+
if (entry.attribute !== undefined)
|
|
1475
|
+
normIntoSpec.set(entry.alias, entry.attribute);
|
|
1476
|
+
else {
|
|
1477
|
+
if (aggregates === undefined)
|
|
1478
|
+
aggregates = new Map();
|
|
1479
|
+
if (entry.aggregate !== undefined)
|
|
1480
|
+
aggregates === null || aggregates === void 0 ? void 0 : aggregates.set(entry.alias, entry.aggregate);
|
|
1481
|
+
}
|
|
1469
1482
|
});
|
|
1483
|
+
if (aggregates !== undefined) {
|
|
1484
|
+
inst.setAggregates(aggregates);
|
|
1485
|
+
}
|
|
1486
|
+
const clauses = whereSpec ? await evalWhereClauses(whereSpec, env) : undefined;
|
|
1470
1487
|
const resolver = await getResolverForPath(inst.name, inst.moduleName, env);
|
|
1471
|
-
const result = await resolver.queryByJoin(inst, [], normIntoSpec, distinct, joinSpec);
|
|
1488
|
+
const result = await resolver.queryByJoin(inst, [], normIntoSpec, distinct, joinSpec, clauses);
|
|
1472
1489
|
const transformedResult = transformDateFieldsInJoinResult(result);
|
|
1473
1490
|
env.setLastResult(transformedResult);
|
|
1474
1491
|
}
|
|
1475
1492
|
async function evaluateJoinQueryWithRelationships(intoSpec, inst, relationships, distinct, env) {
|
|
1476
1493
|
const normIntoSpec = new Map();
|
|
1494
|
+
let aggregates;
|
|
1477
1495
|
intoSpec.entries.forEach((entry) => {
|
|
1478
|
-
|
|
1496
|
+
if (entry.attribute !== undefined)
|
|
1497
|
+
normIntoSpec.set(entry.alias, entry.attribute);
|
|
1498
|
+
else {
|
|
1499
|
+
if (aggregates === undefined)
|
|
1500
|
+
aggregates = new Map();
|
|
1501
|
+
if (entry.aggregate !== undefined)
|
|
1502
|
+
aggregates === null || aggregates === void 0 ? void 0 : aggregates.set(entry.alias, entry.aggregate);
|
|
1503
|
+
}
|
|
1479
1504
|
});
|
|
1505
|
+
if (aggregates !== undefined) {
|
|
1506
|
+
inst.setAggregates(aggregates);
|
|
1507
|
+
}
|
|
1480
1508
|
const moduleName = inst.moduleName;
|
|
1481
1509
|
let joinsSpec = new Array();
|
|
1482
1510
|
for (let i = 0; i < relationships.length; ++i) {
|
|
@@ -1709,7 +1737,10 @@ async function iterateOnFlow(flow, rootAgent, msg, env) {
|
|
|
1709
1737
|
Important: Return only the next flow-step or DONE. Do not return any additional description, like your thinking process.\n`;
|
|
1710
1738
|
env.setFlowContext(initContext);
|
|
1711
1739
|
await agentInvoke(rootAgent, s, env);
|
|
1712
|
-
|
|
1740
|
+
const rootModuleName = rootAgent.moduleName;
|
|
1741
|
+
let preprocResult = await preprocessStep(env.getLastResult().trim(), rootModuleName, env);
|
|
1742
|
+
let step = preprocResult.step;
|
|
1743
|
+
let needAgentProcessing = preprocResult.needAgentProcessing;
|
|
1713
1744
|
let context = initContext;
|
|
1714
1745
|
let stepc = 0;
|
|
1715
1746
|
const iterId = crypto.randomUUID();
|
|
@@ -1719,6 +1750,7 @@ async function iterateOnFlow(flow, rootAgent, msg, env) {
|
|
|
1719
1750
|
if (monitoringEnabled) {
|
|
1720
1751
|
env.flagMonitorEntryAsFlow().incrementMonitor();
|
|
1721
1752
|
}
|
|
1753
|
+
let isfxc = false;
|
|
1722
1754
|
try {
|
|
1723
1755
|
while (step != 'DONE' && !executedSteps.has(step)) {
|
|
1724
1756
|
if (stepc > MaxFlowSteps) {
|
|
@@ -1726,20 +1758,27 @@ async function iterateOnFlow(flow, rootAgent, msg, env) {
|
|
|
1726
1758
|
}
|
|
1727
1759
|
executedSteps.add(step);
|
|
1728
1760
|
++stepc;
|
|
1729
|
-
const agent =
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1761
|
+
const agent = needAgentProcessing
|
|
1762
|
+
? AgentInstance.FromFlowStep(step, rootAgent, context)
|
|
1763
|
+
: undefined;
|
|
1764
|
+
if (agent) {
|
|
1765
|
+
console.debug(`\n---------------------------------------------------\n`);
|
|
1766
|
+
console.debug(`Starting to execute flow step ${step} with agent ${agent.name} with iteration ID ${iterId} and context: \n${context}`);
|
|
1767
|
+
isfxc = agent.isFlowExecutor();
|
|
1768
|
+
const isdec = agent.isDecisionExecutor();
|
|
1769
|
+
if (isfxc || isdec)
|
|
1770
|
+
env.setFlowContext(context);
|
|
1771
|
+
else
|
|
1772
|
+
env.setFlowContext(initContext);
|
|
1773
|
+
if (monitoringEnabled) {
|
|
1774
|
+
env.appendEntryToMonitor(step);
|
|
1775
|
+
}
|
|
1776
|
+
const inst = agent.swapInstruction('');
|
|
1777
|
+
await agentInvoke(agent, inst, env);
|
|
1778
|
+
}
|
|
1779
|
+
else {
|
|
1780
|
+
rootAgent.maybeAddScratchData(env);
|
|
1740
1781
|
}
|
|
1741
|
-
const inst = agent.swapInstruction('');
|
|
1742
|
-
await agentInvoke(agent, inst, env);
|
|
1743
1782
|
if (monitoringEnabled)
|
|
1744
1783
|
env.setMonitorEntryResult(env.getLastResult());
|
|
1745
1784
|
if (env.isSuspended()) {
|
|
@@ -1753,13 +1792,15 @@ async function iterateOnFlow(flow, rootAgent, msg, env) {
|
|
|
1753
1792
|
console.debug(`\n----> Completed execution of step ${step}, iteration id ${iterId} with result:\n${rs}`);
|
|
1754
1793
|
context = `${context}\n${step} --> ${rs}\n`;
|
|
1755
1794
|
if (isfxc) {
|
|
1756
|
-
|
|
1795
|
+
preprocResult = await preprocessStep(rs.trim(), rootModuleName, env);
|
|
1757
1796
|
}
|
|
1758
1797
|
else {
|
|
1759
1798
|
env.setFlowContext(context);
|
|
1760
1799
|
await agentInvoke(rootAgent, `${s}\n${context}`, env);
|
|
1761
|
-
|
|
1800
|
+
preprocResult = await preprocessStep(env.getLastResult().trim(), rootModuleName, env);
|
|
1762
1801
|
}
|
|
1802
|
+
step = preprocResult.step;
|
|
1803
|
+
needAgentProcessing = preprocResult.needAgentProcessing;
|
|
1763
1804
|
}
|
|
1764
1805
|
}
|
|
1765
1806
|
finally {
|
|
@@ -1767,30 +1808,15 @@ async function iterateOnFlow(flow, rootAgent, msg, env) {
|
|
|
1767
1808
|
}
|
|
1768
1809
|
console.debug(`No more flow steps, completed iteration ${iterId} on flow:\n${flow}`);
|
|
1769
1810
|
}
|
|
1770
|
-
async function preprocessStep(spec, env) {
|
|
1811
|
+
async function preprocessStep(spec, activeModuleName, env) {
|
|
1812
|
+
let needAgentProcessing = true;
|
|
1771
1813
|
if (spec.startsWith('{')) {
|
|
1772
|
-
const
|
|
1773
|
-
const
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
const step = crudMap.name;
|
|
1777
|
-
if (crudMap.body) {
|
|
1778
|
-
crudMap.body.attributes.forEach((sa) => {
|
|
1779
|
-
var _a;
|
|
1780
|
-
const v = (_a = sa.value.$cstNode) === null || _a === void 0 ? void 0 : _a.text;
|
|
1781
|
-
if (v)
|
|
1782
|
-
env.setTemplateMapping(sa.name, v);
|
|
1783
|
-
});
|
|
1784
|
-
}
|
|
1785
|
-
return step;
|
|
1786
|
-
}
|
|
1787
|
-
else {
|
|
1788
|
-
throw new Error(`Invalid step - ${spec}`);
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
else {
|
|
1792
|
-
return spec;
|
|
1814
|
+
const newEnv = Environment.from(env, env.name + '_flow_eval', false, true).setActiveModuleName(activeModuleName);
|
|
1815
|
+
const r = await parseAndEvaluateStatement(spec, undefined, newEnv);
|
|
1816
|
+
env.setLastResult(r);
|
|
1817
|
+
needAgentProcessing = false;
|
|
1793
1818
|
}
|
|
1819
|
+
return { step: spec, needAgentProcessing };
|
|
1794
1820
|
}
|
|
1795
1821
|
export async function handleOpenApiEvent(eventInst, env) {
|
|
1796
1822
|
const r = await invokeOpenApiEvent(eventInst.moduleName, eventInst.name, eventInst.attributesAsObject());
|
|
@@ -1841,7 +1867,7 @@ export async function maybeDeleteQueriedInstances(queryEnv, env, purge = false)
|
|
|
1841
1867
|
const inst = queryEnv.getLastResult();
|
|
1842
1868
|
let resolver = Resolver.Default;
|
|
1843
1869
|
if (inst instanceof Array) {
|
|
1844
|
-
if (inst.length > 0
|
|
1870
|
+
if (inst.length > 0) {
|
|
1845
1871
|
resolver = await getResolverForPath(inst[0].name, inst[0].moduleName, queryEnv);
|
|
1846
1872
|
const finalResult = new Array();
|
|
1847
1873
|
for (let i = 0; i < inst.length; ++i) {
|
|
@@ -1856,7 +1882,7 @@ export async function maybeDeleteQueriedInstances(queryEnv, env, purge = false)
|
|
|
1856
1882
|
queryEnv.setLastResult(inst);
|
|
1857
1883
|
}
|
|
1858
1884
|
}
|
|
1859
|
-
else
|
|
1885
|
+
else {
|
|
1860
1886
|
resolver = await getResolverForPath(inst.name, inst.moduleName, queryEnv);
|
|
1861
1887
|
await runPreDeleteEvents(inst, env);
|
|
1862
1888
|
const r = await resolver.deleteInstance(inst, purge);
|
|
@@ -2103,7 +2129,7 @@ async function runPreCreateEvents(inst, env) {
|
|
|
2103
2129
|
}
|
|
2104
2130
|
export async function runPostCreateEvents(inst, env) {
|
|
2105
2131
|
if (inst.requireAudit()) {
|
|
2106
|
-
await addCreateAudit(inst.getPath(), env);
|
|
2132
|
+
await addCreateAudit(inst.getPath(), env, { original: inst.userAttributesAsObject() });
|
|
2107
2133
|
}
|
|
2108
2134
|
await runPrePostEvents(CrudType.CREATE, false, inst, env);
|
|
2109
2135
|
}
|
|
@@ -2112,7 +2138,13 @@ async function runPreUpdateEvents(inst, env) {
|
|
|
2112
2138
|
}
|
|
2113
2139
|
export async function runPostUpdateEvents(inst, oldInst, env) {
|
|
2114
2140
|
if (inst.requireAudit()) {
|
|
2115
|
-
|
|
2141
|
+
let diff;
|
|
2142
|
+
if (oldInst !== undefined) {
|
|
2143
|
+
const oldAttrs = oldInst.userAttributesAsObject();
|
|
2144
|
+
const d = detailedDiff(oldAttrs, inst.userAttributesAsObject());
|
|
2145
|
+
diff = { original: oldAttrs, updated: d.updated };
|
|
2146
|
+
}
|
|
2147
|
+
await addUpdateAudit(inst.getPath(), diff, env);
|
|
2116
2148
|
}
|
|
2117
2149
|
await runPrePostEvents(CrudType.UPDATE, false, inst, env);
|
|
2118
2150
|
}
|
|
@@ -2121,7 +2153,7 @@ async function runPreDeleteEvents(inst, env) {
|
|
|
2121
2153
|
}
|
|
2122
2154
|
export async function runPostDeleteEvents(inst, env) {
|
|
2123
2155
|
if (inst.requireAudit()) {
|
|
2124
|
-
await addDeleteAudit(inst.getPath(), inst, env);
|
|
2156
|
+
await addDeleteAudit(inst.getPath(), { deleted: inst.userAttributesAsObject() }, env);
|
|
2125
2157
|
}
|
|
2126
2158
|
await runPrePostEvents(CrudType.DELETE, false, inst, env);
|
|
2127
2159
|
}
|