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.
Files changed (131) hide show
  1. package/out/api/http.d.ts.map +1 -1
  2. package/out/api/http.js +8 -1
  3. package/out/api/http.js.map +1 -1
  4. package/out/cli/main.d.ts.map +1 -1
  5. package/out/cli/main.js +33 -2
  6. package/out/cli/main.js.map +1 -1
  7. package/out/extension/main.cjs +250 -250
  8. package/out/extension/main.cjs.map +2 -2
  9. package/out/language/agentlang-validator.d.ts +1 -2
  10. package/out/language/agentlang-validator.d.ts.map +1 -1
  11. package/out/language/agentlang-validator.js +0 -39
  12. package/out/language/agentlang-validator.js.map +1 -1
  13. package/out/language/generated/ast.d.ts +62 -11
  14. package/out/language/generated/ast.d.ts.map +1 -1
  15. package/out/language/generated/ast.js +75 -3
  16. package/out/language/generated/ast.js.map +1 -1
  17. package/out/language/generated/grammar.d.ts.map +1 -1
  18. package/out/language/generated/grammar.js +758 -239
  19. package/out/language/generated/grammar.js.map +1 -1
  20. package/out/language/main.cjs +1370 -824
  21. package/out/language/main.cjs.map +4 -4
  22. package/out/language/parser.d.ts +1 -0
  23. package/out/language/parser.d.ts.map +1 -1
  24. package/out/language/parser.js +44 -7
  25. package/out/language/parser.js.map +1 -1
  26. package/out/language/syntax.d.ts +1 -1
  27. package/out/language/syntax.d.ts.map +1 -1
  28. package/out/language/syntax.js +22 -13
  29. package/out/language/syntax.js.map +1 -1
  30. package/out/runtime/api.d.ts +2 -0
  31. package/out/runtime/api.d.ts.map +1 -1
  32. package/out/runtime/api.js +5 -0
  33. package/out/runtime/api.js.map +1 -1
  34. package/out/runtime/auth/cognito.d.ts.map +1 -1
  35. package/out/runtime/auth/cognito.js +4 -4
  36. package/out/runtime/auth/cognito.js.map +1 -1
  37. package/out/runtime/defs.d.ts +5 -0
  38. package/out/runtime/defs.d.ts.map +1 -1
  39. package/out/runtime/defs.js +16 -0
  40. package/out/runtime/defs.js.map +1 -1
  41. package/out/runtime/exec-graph.js +1 -1
  42. package/out/runtime/exec-graph.js.map +1 -1
  43. package/out/runtime/interpreter.d.ts +6 -1
  44. package/out/runtime/interpreter.d.ts.map +1 -1
  45. package/out/runtime/interpreter.js +144 -112
  46. package/out/runtime/interpreter.js.map +1 -1
  47. package/out/runtime/loader.d.ts +1 -1
  48. package/out/runtime/loader.d.ts.map +1 -1
  49. package/out/runtime/loader.js +74 -27
  50. package/out/runtime/loader.js.map +1 -1
  51. package/out/runtime/module.d.ts +41 -11
  52. package/out/runtime/module.d.ts.map +1 -1
  53. package/out/runtime/module.js +238 -50
  54. package/out/runtime/module.js.map +1 -1
  55. package/out/runtime/modules/ai.d.ts.map +1 -1
  56. package/out/runtime/modules/ai.js +13 -6
  57. package/out/runtime/modules/ai.js.map +1 -1
  58. package/out/runtime/modules/auth.d.ts +2 -1
  59. package/out/runtime/modules/auth.d.ts.map +1 -1
  60. package/out/runtime/modules/auth.js +93 -3
  61. package/out/runtime/modules/auth.js.map +1 -1
  62. package/out/runtime/modules/core.d.ts +7 -5
  63. package/out/runtime/modules/core.d.ts.map +1 -1
  64. package/out/runtime/modules/core.js +93 -16
  65. package/out/runtime/modules/core.js.map +1 -1
  66. package/out/runtime/monitor.d.ts.map +1 -1
  67. package/out/runtime/monitor.js +1 -0
  68. package/out/runtime/monitor.js.map +1 -1
  69. package/out/runtime/resolvers/interface.d.ts +6 -1
  70. package/out/runtime/resolvers/interface.d.ts.map +1 -1
  71. package/out/runtime/resolvers/interface.js +2 -2
  72. package/out/runtime/resolvers/interface.js.map +1 -1
  73. package/out/runtime/resolvers/sqldb/database.d.ts +19 -2
  74. package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
  75. package/out/runtime/resolvers/sqldb/database.js +107 -21
  76. package/out/runtime/resolvers/sqldb/database.js.map +1 -1
  77. package/out/runtime/resolvers/sqldb/dbutil.d.ts +1 -0
  78. package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -1
  79. package/out/runtime/resolvers/sqldb/dbutil.js +25 -3
  80. package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -1
  81. package/out/runtime/resolvers/sqldb/impl.d.ts +3 -2
  82. package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
  83. package/out/runtime/resolvers/sqldb/impl.js +80 -6
  84. package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
  85. package/out/runtime/state.d.ts +58 -0
  86. package/out/runtime/state.d.ts.map +1 -1
  87. package/out/runtime/state.js +12 -0
  88. package/out/runtime/state.js.map +1 -1
  89. package/out/runtime/util.d.ts +1 -1
  90. package/out/runtime/util.d.ts.map +1 -1
  91. package/out/runtime/util.js +27 -13
  92. package/out/runtime/util.js.map +1 -1
  93. package/out/setupClassic.d.ts +98 -0
  94. package/out/setupClassic.d.ts.map +1 -0
  95. package/out/setupClassic.js +38 -0
  96. package/out/setupClassic.js.map +1 -0
  97. package/out/setupCommon.d.ts +2 -0
  98. package/out/setupCommon.d.ts.map +1 -0
  99. package/out/setupCommon.js +33 -0
  100. package/out/setupCommon.js.map +1 -0
  101. package/out/setupExtended.d.ts +40 -0
  102. package/out/setupExtended.d.ts.map +1 -0
  103. package/out/setupExtended.js +67 -0
  104. package/out/setupExtended.js.map +1 -0
  105. package/out/syntaxes/agentlang.monarch.js +1 -1
  106. package/out/syntaxes/agentlang.monarch.js.map +1 -1
  107. package/package.json +187 -185
  108. package/src/api/http.ts +8 -0
  109. package/src/cli/main.ts +38 -2
  110. package/src/language/agentlang-validator.ts +1 -51
  111. package/src/language/agentlang.langium +17 -4
  112. package/src/language/generated/ast.ts +147 -13
  113. package/src/language/generated/grammar.ts +758 -239
  114. package/src/language/parser.ts +43 -8
  115. package/src/language/syntax.ts +25 -12
  116. package/src/runtime/api.ts +8 -0
  117. package/src/runtime/defs.ts +8 -0
  118. package/src/runtime/interpreter.ts +104 -76
  119. package/src/runtime/loader.ts +75 -25
  120. package/src/runtime/module.ts +194 -32
  121. package/src/runtime/modules/ai.ts +10 -4
  122. package/src/runtime/modules/auth.ts +1 -0
  123. package/src/runtime/modules/core.ts +99 -23
  124. package/src/runtime/monitor.ts +1 -0
  125. package/src/runtime/resolvers/interface.ts +9 -2
  126. package/src/runtime/resolvers/sqldb/database.ts +68 -17
  127. package/src/runtime/resolvers/sqldb/dbutil.ts +28 -6
  128. package/src/runtime/resolvers/sqldb/impl.ts +86 -14
  129. package/src/runtime/state.ts +14 -0
  130. package/src/runtime/util.ts +25 -12
  131. package/src/syntaxes/agentlang.monarch.ts +1 -1
@@ -3,7 +3,7 @@ import { isRelNodes, isLiteral, } from '../language/generated/ast.js';
3
3
  import { Path, nameToPath, isString, isNumber, isBoolean, isFqName, makeFqName, DefaultModuleName, DefaultModules, joinStatements, isMinusZero, now, findMetaSchema, findAllPrePostTriggerSchema, asCrudType, isPath, findUqCompositeAttributes, escapeFqName, encryptPassword, splitFqName, splitRefs, forceAsFqName, validateIdFormat, nameContainsSepEscape, registerInitFunction, ScratchModuleName, } from './util.js';
4
4
  import { parseStatement } from '../language/parser.js';
5
5
  import { AdminSession } from './auth/defs.js';
6
- import { FetchModuleFn, PathAttributeName } from './defs.js';
6
+ import { FetchModuleFn, getUserTenantId, PathAttributeName, TenantAttributeName, } from './defs.js';
7
7
  import { logger } from './logger.js';
8
8
  import { CasePattern, FlowStepPattern } from '../language/syntax.js';
9
9
  import { getAgentDirectives, getAgentDirectivesJson, getAgentGlossary, getAgentGlossaryJson, getAgentResponseSchema, getAgentScenarios, getAgentScenariosJson, registerAgentDirectives, registerAgentGlossary, registerAgentResponseSchema, registerAgentScenarios, removeAgentDirectives, removeAgentGlossary, removeAgentResponseSchema, removeAgentScenarios, } from './agents/common.js';
@@ -118,7 +118,7 @@ function attributePropertyValueToString(propName, propValue, attrType) {
118
118
  return ss.join(',');
119
119
  }
120
120
  else if (propName == 'default') {
121
- if (isTextualType(attrType) && propValue != 'now()' && propValue != 'uuid()') {
121
+ if (isTextualType(attrType) && !defaultValueIsFunctionCall(propValue)) {
122
122
  return `"${propValue}"`;
123
123
  }
124
124
  }
@@ -326,6 +326,41 @@ export class Record extends ModuleEntry {
326
326
  (_a = this.beforeTriggers) === null || _a === void 0 ? void 0 : _a.set(asCrudType(te.on), asTriggerInfo(te));
327
327
  return this;
328
328
  }
329
+ getSecretAttributes() {
330
+ const result = new Array();
331
+ this.schema.forEach((spec, n) => {
332
+ var _a;
333
+ if (((_a = spec.properties) === null || _a === void 0 ? void 0 : _a.get('secret')) === true) {
334
+ result.push(n);
335
+ }
336
+ });
337
+ return result;
338
+ }
339
+ isGlobal() {
340
+ var _a;
341
+ return ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.get('global')) === true;
342
+ }
343
+ getWriteOnlyAttributes() {
344
+ const fqn = this.getFqName();
345
+ const cachedResult = Record.WriteOnlyAttributes.get(fqn);
346
+ if (cachedResult !== undefined) {
347
+ if (cachedResult.length === 0)
348
+ return undefined;
349
+ return cachedResult;
350
+ }
351
+ else {
352
+ const result = new Array();
353
+ this.schema.forEach((spec, n) => {
354
+ var _a;
355
+ if (((_a = spec.properties) === null || _a === void 0 ? void 0 : _a.get('writeonly')) === true) {
356
+ result.push(n);
357
+ }
358
+ });
359
+ const finalResult = result.concat(this.getSecretAttributes());
360
+ Record.WriteOnlyAttributes.set(fqn, finalResult);
361
+ return finalResult;
362
+ }
363
+ }
329
364
  getCompositeUniqueAttributes() {
330
365
  return this.compositeUqAttributes;
331
366
  }
@@ -346,6 +381,7 @@ export class Record extends ModuleEntry {
346
381
  this.meta = newMeta();
347
382
  }
348
383
  this.meta.set(k, v);
384
+ return this;
349
385
  }
350
386
  getMeta(k) {
351
387
  if (this.meta) {
@@ -372,6 +408,10 @@ export class Record extends ModuleEntry {
372
408
  return undefined;
373
409
  }
374
410
  }
411
+ resetUserAttrs() {
412
+ this.userAttrNames = undefined;
413
+ this.userAttrsSchema = undefined;
414
+ }
375
415
  addAttribute(n, attrSpec) {
376
416
  if (this.schema.has(n)) {
377
417
  throw new Error(`Attribute named ${n} already exists in ${this.moduleName}.${this.name}`);
@@ -380,10 +420,12 @@ export class Record extends ModuleEntry {
380
420
  normalizePropertyNames(attrSpec.properties);
381
421
  }
382
422
  this.schema.set(n, attrSpec);
423
+ this.resetUserAttrs();
383
424
  return this;
384
425
  }
385
426
  removeAttribute(n) {
386
427
  this.schema.delete(n);
428
+ this.resetUserAttrs();
387
429
  return this;
388
430
  }
389
431
  reorderAttributes(desiredOrder) {
@@ -478,8 +520,10 @@ export class Record extends ModuleEntry {
478
520
  toString() {
479
521
  return this.toString_();
480
522
  }
481
- toString_(internParentSchema = false) {
482
- if (this.type == RecordType.EVENT && this.meta && this.meta.get(SystemDefinedEvent)) {
523
+ toString_(internParentSchema = false, toolCall = false) {
524
+ var _a, _b;
525
+ const isevent = this.type == RecordType.EVENT;
526
+ if (isevent && ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.get(SystemDefinedEvent)) && !toolCall) {
483
527
  return '';
484
528
  }
485
529
  let s = `${RecordType[this.type].toLowerCase()} ${this.name}`;
@@ -510,9 +554,24 @@ export class Record extends ModuleEntry {
510
554
  scms = `${scms},\n @rbac [${rbs.join(',\n')}]`;
511
555
  }
512
556
  if (this.meta && this.meta.size > 0) {
513
- const metaObj = Object.fromEntries(this.meta);
514
- const ms = `@meta ${JSON.stringify(metaObj)}`;
515
- scms = `${scms},\n ${ms}`;
557
+ let metaObj = undefined;
558
+ if (isevent && isAgentEvent(this) && toolCall) {
559
+ const m = new Map();
560
+ (_b = this.meta) === null || _b === void 0 ? void 0 : _b.forEach((v, k) => {
561
+ if (!(k === IsAgentEventMeta || k === EventAgentName || k === DocumentationMetaTag))
562
+ m.set(k, v);
563
+ });
564
+ if (m.size > 0) {
565
+ metaObj = Object.fromEntries(m);
566
+ }
567
+ }
568
+ else {
569
+ metaObj = Object.fromEntries(this.meta);
570
+ }
571
+ if (metaObj) {
572
+ const ms = `@meta ${JSON.stringify(metaObj)}`;
573
+ scms = `${scms},\n ${ms}`;
574
+ }
516
575
  }
517
576
  if (this.isPublic()) {
518
577
  s = `@public ${s}`;
@@ -520,18 +579,25 @@ export class Record extends ModuleEntry {
520
579
  return s.concat('\n{', scms, '\n}\n');
521
580
  }
522
581
  getUserAttributes() {
523
- const recSchema = newRecordSchema();
524
- this.schema.forEach((attrSpec, n) => {
525
- if (!isSystemAttribute(attrSpec)) {
526
- recSchema.set(n, attrSpec);
527
- }
528
- });
529
- return recSchema;
582
+ if (this.userAttrsSchema === undefined) {
583
+ this.userAttrsSchema = newRecordSchema();
584
+ this.schema.forEach((attrSpec, n) => {
585
+ var _a;
586
+ if (!isSystemAttribute(attrSpec)) {
587
+ (_a = this.userAttrsSchema) === null || _a === void 0 ? void 0 : _a.set(n, attrSpec);
588
+ }
589
+ });
590
+ }
591
+ return this.userAttrsSchema;
530
592
  }
531
593
  getUserAttributeNames() {
532
- return [...this.getUserAttributes().keys()];
594
+ if (this.userAttrNames === undefined) {
595
+ this.userAttrNames = new Set([...this.getUserAttributes().keys()]);
596
+ }
597
+ return this.userAttrNames;
533
598
  }
534
599
  }
600
+ Record.WriteOnlyAttributes = new Map();
535
601
  function fetchModuleByEntryName(entryName, suspectModuleName) {
536
602
  if (isFqName(entryName)) {
537
603
  const path = nameToPath(entryName);
@@ -955,11 +1021,12 @@ const SysAttr_CreatedSpec = asSystemAttribute({
955
1021
  properties: new Map().set('default', 'now()'),
956
1022
  });
957
1023
  const SysAttr_LastModifiedSpec = SysAttr_CreatedSpec;
958
- const SysAttr_CreatedBySpec = asSystemAttribute({
1024
+ const SysAttr_OptionalString = asSystemAttribute({
959
1025
  type: 'String',
960
1026
  properties: new Map().set('optional', true),
961
1027
  });
962
- const SysAttr_LastModifiedBySpec = SysAttr_CreatedBySpec;
1028
+ const SysAttr_CreatedBySpec = SysAttr_OptionalString;
1029
+ const SysAttr_LastModifiedBySpec = SysAttr_OptionalString;
963
1030
  export class Entity extends Record {
964
1031
  constructor(name, moduleName, scm, parentEntryName) {
965
1032
  super(name, moduleName, scm, parentEntryName);
@@ -1345,16 +1412,22 @@ export class Workflow extends ModuleEntry {
1345
1412
  return s.concat('\n}');
1346
1413
  }
1347
1414
  }
1415
+ function splitFlowSteps(flow) {
1416
+ var _a;
1417
+ const steps = new Array();
1418
+ (_a = flow.body) === null || _a === void 0 ? void 0 : _a.entries.forEach((fe) => {
1419
+ var _a;
1420
+ steps.push(((_a = fe.$cstNode) === null || _a === void 0 ? void 0 : _a.text) || '');
1421
+ });
1422
+ return steps;
1423
+ }
1348
1424
  export class Flow extends ModuleEntry {
1349
1425
  constructor(name, moduleName, flow) {
1350
1426
  super(name, moduleName);
1351
- this.flowSteps = new Array();
1352
- flow === null || flow === void 0 ? void 0 : flow.split('\n').forEach((step) => {
1353
- const s = step.trim();
1354
- if (s.length > 0) {
1355
- this.flowSteps.push(s);
1356
- }
1357
- });
1427
+ if (flow)
1428
+ this.flowSteps = splitFlowSteps(flow);
1429
+ else
1430
+ this.flowSteps = new Array();
1358
1431
  }
1359
1432
  getFlow() {
1360
1433
  return this.flowSteps.join('\n');
@@ -1374,10 +1447,11 @@ export class Flow extends ModuleEntry {
1374
1447
  stepsCount() {
1375
1448
  return this.flowSteps.length;
1376
1449
  }
1377
- toGraph() {
1450
+ async toGraph() {
1378
1451
  const result = new Array();
1379
- this.flowSteps.forEach((s) => {
1380
- const fp = FlowStepPattern.Parse(s);
1452
+ for (let i = 0; i < this.flowSteps.length; ++i) {
1453
+ const s = this.flowSteps[i];
1454
+ const fp = await FlowStepPattern.Parse(s);
1381
1455
  if (fp.condition) {
1382
1456
  const orig = result.find((v) => {
1383
1457
  return v.label == fp.first;
@@ -1404,7 +1478,7 @@ export class Flow extends ModuleEntry {
1404
1478
  next: [fp.next],
1405
1479
  });
1406
1480
  }
1407
- });
1481
+ }
1408
1482
  return result;
1409
1483
  }
1410
1484
  static asFlowName(n) {
@@ -1518,6 +1592,10 @@ export class Retry extends ModuleEntry {
1518
1592
  factor: undefined,
1519
1593
  };
1520
1594
  }
1595
+ setBackoffStrategy(s) {
1596
+ this.backoff.strategy = s;
1597
+ return this;
1598
+ }
1521
1599
  setExponentialBackoff() {
1522
1600
  this.backoff.strategy = 'e';
1523
1601
  return this;
@@ -1545,6 +1623,18 @@ export class Retry extends ModuleEntry {
1545
1623
  }
1546
1624
  return this;
1547
1625
  }
1626
+ setBackoffMagnitude(m) {
1627
+ if (m[0] === 's') {
1628
+ this.backoff.magnitude = 's';
1629
+ }
1630
+ else if (m.startsWith('milli')) {
1631
+ this.backoff.magnitude = 'ms';
1632
+ }
1633
+ else {
1634
+ this.backoff.magnitude = 'm';
1635
+ }
1636
+ return this;
1637
+ }
1548
1638
  setBackoffMagnitudeAsMilliseconds() {
1549
1639
  this.backoff.magnitude = 'ms';
1550
1640
  return this;
@@ -1702,6 +1792,21 @@ export class Module {
1702
1792
  this.entries.push(entry);
1703
1793
  return entry;
1704
1794
  }
1795
+ addImport(entry) {
1796
+ var _a;
1797
+ if (this.imports === undefined) {
1798
+ this.imports = new Array();
1799
+ }
1800
+ (_a = this.imports) === null || _a === void 0 ? void 0 : _a.push(entry);
1801
+ return this;
1802
+ }
1803
+ removeImportAt(index) {
1804
+ var _a;
1805
+ if (index >= 0) {
1806
+ (_a = this.imports) === null || _a === void 0 ? void 0 : _a.splice(index, 1);
1807
+ }
1808
+ return this;
1809
+ }
1705
1810
  getConfigEntity() {
1706
1811
  return this.getEntityEntries().find((e) => {
1707
1812
  return e.isConfigEntity();
@@ -1720,8 +1825,8 @@ export class Module {
1720
1825
  removeAgent(agentName) {
1721
1826
  return this.removeEntry(Agent.EscapeName(agentName));
1722
1827
  }
1723
- addFlow(name, flowString) {
1724
- const flow = new Flow(Flow.asFlowName(name), this.name, flowString);
1828
+ addFlow(name, flowDef) {
1829
+ const flow = new Flow(Flow.asFlowName(name), this.name, flowDef);
1725
1830
  this.addEntry(flow);
1726
1831
  return flow;
1727
1832
  }
@@ -2069,6 +2174,14 @@ export class Module {
2069
2174
  });
2070
2175
  return names;
2071
2176
  }
2177
+ getBetweenRelationshipNames() {
2178
+ const names = [];
2179
+ this.getRelationshipEntries().forEach((re) => {
2180
+ if (re.isBetween())
2181
+ names.push(re.name);
2182
+ });
2183
+ return names;
2184
+ }
2072
2185
  isContainsRelationship(entryName) {
2073
2186
  if (this.hasEntry(entryName)) {
2074
2187
  const entry = this.getEntry(entryName);
@@ -2085,16 +2198,42 @@ export class Module {
2085
2198
  }
2086
2199
  return false;
2087
2200
  }
2201
+ importsAsString() {
2202
+ if (this.imports !== undefined) {
2203
+ const ss = new Array();
2204
+ this.imports.forEach((me) => {
2205
+ ss.push(`import "${me.path}" @as ${me.name}`);
2206
+ });
2207
+ return `\n${ss.join('\n')}\n`;
2208
+ }
2209
+ return '';
2210
+ }
2088
2211
  toString() {
2089
2212
  const ss = [];
2090
2213
  this.entries.forEach((me) => {
2091
- if (me instanceof Event && isAgentEvent(me)) {
2214
+ if (me instanceof Event && me.isSystemDefined()) {
2092
2215
  return;
2093
2216
  }
2094
2217
  ss.push(me.toString());
2095
2218
  });
2096
- return `module ${this.name}\n\n${ss.join('\n')}`;
2219
+ return `module ${this.name}\n${this.importsAsString()}\n${ss.join('\n')}`;
2220
+ }
2221
+ }
2222
+ let GlobalRetries = undefined;
2223
+ export function addGlobalRetry(r) {
2224
+ if (GlobalRetries === undefined) {
2225
+ GlobalRetries = new Array();
2097
2226
  }
2227
+ GlobalRetries === null || GlobalRetries === void 0 ? void 0 : GlobalRetries.push(r);
2228
+ return r;
2229
+ }
2230
+ export function getGlobalRetry(name) {
2231
+ if (GlobalRetries !== undefined) {
2232
+ return GlobalRetries.find((r) => {
2233
+ return r.name === name;
2234
+ });
2235
+ }
2236
+ return undefined;
2098
2237
  }
2099
2238
  let browserModuleDb;
2100
2239
  const getModuleDb = function () {
@@ -2204,6 +2343,8 @@ export const propertyNames = new Set([
2204
2343
  '@fk',
2205
2344
  '@ref',
2206
2345
  '@readonly',
2346
+ '@writeonly',
2347
+ '@secret',
2207
2348
  '@enum',
2208
2349
  '@oneof',
2209
2350
  '@comment',
@@ -2268,7 +2409,8 @@ export function defaultAttributes(schema) {
2268
2409
  export function passwordAttributes(schema) {
2269
2410
  let result = undefined;
2270
2411
  schema.forEach((v, k) => {
2271
- if (v.type == 'Password') {
2412
+ var _a;
2413
+ if (v.type == 'Password' || ((_a = v.properties) === null || _a === void 0 ? void 0 : _a.get('secret')) === true) {
2272
2414
  if (result === undefined) {
2273
2415
  result = new Set();
2274
2416
  }
@@ -2372,7 +2514,7 @@ export function addEvent(name, moduleName = activeModule, scm, ext) {
2372
2514
  const module = fetchModule(moduleName);
2373
2515
  const event = module.addEntry(new Event(name, moduleName, scm, ext));
2374
2516
  if (module.getAgent(name)) {
2375
- event.addMeta(IsAgentEventMeta, 'y');
2517
+ defineAgentEvent(moduleName, name);
2376
2518
  }
2377
2519
  return event;
2378
2520
  }
@@ -2574,6 +2716,14 @@ export function getEvent(name, moduleName) {
2574
2716
  }
2575
2717
  throw new Error(`Event ${fr.entryName} not found in module ${fr.moduleName}`);
2576
2718
  }
2719
+ export function maybeGetEvent(name, moduleName) {
2720
+ try {
2721
+ return getEvent(name, moduleName);
2722
+ }
2723
+ catch (_a) {
2724
+ return undefined;
2725
+ }
2726
+ }
2577
2727
  export function getRecord(name, moduleName) {
2578
2728
  const fr = fetchModuleByEntryName(name, moduleName);
2579
2729
  if (fr.module.isRecord(fr.entryName)) {
@@ -2738,6 +2888,7 @@ export function newInstanceAttributes() {
2738
2888
  const EmptyInstanceAttributes = newInstanceAttributes();
2739
2889
  export class Instance {
2740
2890
  constructor(record, moduleName, name, attributes, queryAttributes, queryAttributeValues) {
2891
+ this.orderByDesc = false;
2741
2892
  this.___id = crypto.randomUUID();
2742
2893
  this.record = record;
2743
2894
  this.name = name;
@@ -2809,6 +2960,19 @@ export class Instance {
2809
2960
  getPath() {
2810
2961
  return this.lookup(PathAttributeName);
2811
2962
  }
2963
+ setAggregates(aggregates) {
2964
+ this.aggregates = aggregates;
2965
+ return this;
2966
+ }
2967
+ setGroupBy(n) {
2968
+ this.groupBy = n;
2969
+ return this;
2970
+ }
2971
+ setOrderBy(n, desc = false) {
2972
+ this.orderBy = n;
2973
+ this.orderByDesc = desc;
2974
+ return this;
2975
+ }
2812
2976
  asSerializableObject() {
2813
2977
  const obj = {
2814
2978
  AL_INSTANCE: true,
@@ -2885,6 +3049,15 @@ export class Instance {
2885
3049
  });
2886
3050
  return Object.fromEntries(attrs);
2887
3051
  }
3052
+ userAttributesAsObject(forSerialization = false) {
3053
+ const attrs = newInstanceAttributes();
3054
+ const userAttrNames = this.getAllUserAttributeNames();
3055
+ this.attributes.forEach((v, k) => {
3056
+ if (userAttrNames.has(k))
3057
+ attrs.set(k, Instance.asSerializableValue(v, forSerialization));
3058
+ });
3059
+ return Object.fromEntries(attrs);
3060
+ }
2888
3061
  static stringifyObjects(attributes) {
2889
3062
  const attrs = newInstanceAttributes();
2890
3063
  attributes.forEach((v, k) => {
@@ -2912,6 +3085,10 @@ export class Instance {
2912
3085
  }
2913
3086
  return {};
2914
3087
  }
3088
+ getQueryValue(k) {
3089
+ var _a;
3090
+ return (_a = this.queryAttributeValues) === null || _a === void 0 ? void 0 : _a.get(k);
3091
+ }
2915
3092
  addQuery(attrName, op = '=', attrVal = undefined) {
2916
3093
  if (this.queryAttributes === undefined)
2917
3094
  this.queryAttributes = newInstanceAttributes();
@@ -3088,17 +3265,22 @@ export function findIdAttribute(inst) {
3088
3265
  }
3089
3266
  return undefined;
3090
3267
  }
3268
+ function defaultValueIsFunctionCall(dv) {
3269
+ return dv.endsWith('()');
3270
+ }
3091
3271
  function maybeSetDefaultAttributeValues(schema, attributes) {
3092
3272
  const defAttrs = defaultAttributes(schema);
3093
3273
  defAttrs.forEach((v, k) => {
3094
3274
  const cv = attributes.get(k);
3095
3275
  if (cv === undefined || cv === null) {
3096
3276
  if (isString(v)) {
3097
- if (v == 'uuid()') {
3098
- v = crypto.randomUUID();
3099
- }
3100
- else if (v == 'now()') {
3101
- v = now();
3277
+ if (defaultValueIsFunctionCall(v)) {
3278
+ try {
3279
+ v = eval(v);
3280
+ }
3281
+ catch (_a) {
3282
+ v = (0, eval)(`globalThis.${v}`);
3283
+ }
3102
3284
  }
3103
3285
  }
3104
3286
  attributes.set(k, v);
@@ -3217,22 +3399,27 @@ function markAsAgentEvent(event) {
3217
3399
  return event;
3218
3400
  }
3219
3401
  export function defineAgentEvent(moduleName, agentName, instruction) {
3220
- const module = fetchModule(moduleName);
3221
- const event = new Event(agentName, moduleName);
3222
- markAsAgentEvent(event)
3223
- .addAttribute('message', { type: 'Any' })
3224
- .addAttribute('chatId', asOptionalAttribute({ type: 'String' }))
3225
- .addAttribute('mode', asSystemAttribute(asOptionalAttribute({ type: 'String' })))
3226
- .addMeta(EventAgentName, agentName);
3402
+ let event = maybeGetEvent(agentName, moduleName);
3403
+ const newEvent = event === undefined;
3404
+ if (event === undefined) {
3405
+ event = new Event(agentName, moduleName)
3406
+ .addAttribute('message', { type: 'Any' })
3407
+ .addAttribute('chatId', asOptionalAttribute({ type: 'String' }))
3408
+ .addAttribute('mode', asSystemAttribute(asOptionalAttribute({ type: 'String' })))
3409
+ .addMeta(SystemDefinedEvent, 'true');
3410
+ }
3411
+ markAsAgentEvent(event).addMeta(EventAgentName, agentName);
3227
3412
  if (instruction) {
3228
3413
  event.addMeta(DocumentationMetaTag, `This event will trigger an agent which has the instruction - "${instruction}".
3229
3414
  So make sure to pass all relevant information in the 'message' attribute of this event.`);
3230
3415
  }
3416
+ const module = fetchModule(moduleName);
3231
3417
  const agent = module.getAgent(agentName);
3232
3418
  if (agent && agent.isPublic()) {
3233
3419
  event.setPublic(true);
3234
3420
  }
3235
- module.addEntry(event);
3421
+ if (newEvent)
3422
+ module.addEntry(event);
3236
3423
  }
3237
3424
  export function isTimer(eventInst) {
3238
3425
  return eventInst.getFqName() == 'agentlang/timer';
@@ -3320,16 +3507,17 @@ export function getAttributeNames(entityFqName) {
3320
3507
  const scm = fetchModule(parts.getModuleName()).getRecord(parts.getEntryName()).schema;
3321
3508
  return [...scm.keys()];
3322
3509
  }
3323
- export function setMetaAttributes(attrs, env, inUpdateMode = false) {
3510
+ export async function setMetaAttributes(attrs, env, inUpdateMode = false) {
3324
3511
  const user = env.getActiveUser();
3325
3512
  attrs.set(SysAttr_LastModified, now()).set(SysAttr_LastModifiedBy, user);
3326
3513
  if (!inUpdateMode && attrs.get(SysAttr_CreatedBy) === undefined) {
3327
3514
  attrs.set(SysAttr_CreatedBy, user);
3328
3515
  }
3516
+ attrs.set(TenantAttributeName, await getUserTenantId(user, env));
3329
3517
  }
3330
- export function setAllMetaAttributes(attrs, env, inUpdateMode = false) {
3518
+ export async function setAllMetaAttributes(attrs, env, inUpdateMode = false) {
3331
3519
  attrs.set(SysAttr_Created, now());
3332
- setMetaAttributes(attrs, env, inUpdateMode);
3520
+ await setMetaAttributes(attrs, env, inUpdateMode);
3333
3521
  }
3334
3522
  function linkEventName(moduleName, relName, unlink) {
3335
3523
  const tag = unlink ? 'unlink' : 'link';