agentlang 0.3.0 → 0.3.1

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 (79) hide show
  1. package/README.md +276 -30
  2. package/out/api/http.d.ts.map +1 -1
  3. package/out/api/http.js +5 -3
  4. package/out/api/http.js.map +1 -1
  5. package/out/language/agentlang-validator.d.ts.map +1 -1
  6. package/out/language/agentlang-validator.js +24 -4
  7. package/out/language/agentlang-validator.js.map +1 -1
  8. package/out/language/generated/ast.d.ts +58 -7
  9. package/out/language/generated/ast.d.ts.map +1 -1
  10. package/out/language/generated/ast.js +82 -1
  11. package/out/language/generated/ast.js.map +1 -1
  12. package/out/language/generated/grammar.d.ts.map +1 -1
  13. package/out/language/generated/grammar.js +537 -216
  14. package/out/language/generated/grammar.js.map +1 -1
  15. package/out/language/main.cjs +614 -221
  16. package/out/language/main.cjs.map +2 -2
  17. package/out/runtime/agents/common.d.ts +11 -0
  18. package/out/runtime/agents/common.d.ts.map +1 -1
  19. package/out/runtime/agents/common.js +61 -1
  20. package/out/runtime/agents/common.js.map +1 -1
  21. package/out/runtime/exec-graph.d.ts.map +1 -1
  22. package/out/runtime/exec-graph.js +1 -7
  23. package/out/runtime/exec-graph.js.map +1 -1
  24. package/out/runtime/interpreter.d.ts.map +1 -1
  25. package/out/runtime/interpreter.js +45 -17
  26. package/out/runtime/interpreter.js.map +1 -1
  27. package/out/runtime/loader.d.ts +3 -4
  28. package/out/runtime/loader.d.ts.map +1 -1
  29. package/out/runtime/loader.js +91 -12
  30. package/out/runtime/loader.js.map +1 -1
  31. package/out/runtime/module.d.ts +34 -5
  32. package/out/runtime/module.d.ts.map +1 -1
  33. package/out/runtime/module.js +190 -18
  34. package/out/runtime/module.js.map +1 -1
  35. package/out/runtime/modules/ai.d.ts.map +1 -1
  36. package/out/runtime/modules/ai.js +15 -6
  37. package/out/runtime/modules/ai.js.map +1 -1
  38. package/out/runtime/modules/auth.d.ts.map +1 -1
  39. package/out/runtime/modules/auth.js +42 -43
  40. package/out/runtime/modules/auth.js.map +1 -1
  41. package/out/runtime/modules/core.js +1 -1
  42. package/out/runtime/modules/files.d.ts +18 -0
  43. package/out/runtime/modules/files.d.ts.map +1 -0
  44. package/out/runtime/modules/files.js +116 -0
  45. package/out/runtime/modules/files.js.map +1 -0
  46. package/out/runtime/util.d.ts +3 -1
  47. package/out/runtime/util.d.ts.map +1 -1
  48. package/out/runtime/util.js +16 -0
  49. package/out/runtime/util.js.map +1 -1
  50. package/out/setupClassic.d.ts +98 -0
  51. package/out/setupClassic.d.ts.map +1 -0
  52. package/out/setupClassic.js +38 -0
  53. package/out/setupClassic.js.map +1 -0
  54. package/out/setupCommon.d.ts +2 -0
  55. package/out/setupCommon.d.ts.map +1 -0
  56. package/out/setupCommon.js +33 -0
  57. package/out/setupCommon.js.map +1 -0
  58. package/out/setupExtended.d.ts +40 -0
  59. package/out/setupExtended.d.ts.map +1 -0
  60. package/out/setupExtended.js +67 -0
  61. package/out/setupExtended.js.map +1 -0
  62. package/out/syntaxes/agentlang.monarch.js +1 -1
  63. package/out/syntaxes/agentlang.monarch.js.map +1 -1
  64. package/package.json +183 -182
  65. package/src/api/http.ts +5 -3
  66. package/src/language/agentlang-validator.ts +29 -4
  67. package/src/language/agentlang.langium +15 -3
  68. package/src/language/generated/ast.ts +149 -7
  69. package/src/language/generated/grammar.ts +537 -216
  70. package/src/runtime/agents/common.ts +69 -1
  71. package/src/runtime/exec-graph.ts +1 -8
  72. package/src/runtime/interpreter.ts +47 -16
  73. package/src/runtime/loader.ts +105 -9
  74. package/src/runtime/module.ts +213 -24
  75. package/src/runtime/modules/ai.ts +12 -5
  76. package/src/runtime/modules/auth.ts +42 -43
  77. package/src/runtime/modules/core.ts +1 -1
  78. package/src/runtime/util.ts +19 -0
  79. package/src/syntaxes/agentlang.monarch.ts +1 -1
@@ -6,15 +6,23 @@ import { AdminSession } from './auth/defs.js';
6
6
  import { FetchModuleFn, PathAttributeName } from './defs.js';
7
7
  import { logger } from './logger.js';
8
8
  import { FlowStepPattern } from '../language/syntax.js';
9
- import { getAgentDirectives, getAgentDirectivesJson, getAgentGlossary, getAgentResponseSchema, getAgentScenarios, registerAgentDirectives, registerAgentGlossary, registerAgentResponseSchema, registerAgentScenarios, removeAgentDirectives, removeAgentGlossary, removeAgentResponseSchema, removeAgentScenarios, } from './agents/common.js';
9
+ import { getAgentDirectives, getAgentDirectivesJson, getAgentGlossary, getAgentGlossaryJson, getAgentResponseSchema, getAgentScenarios, getAgentScenariosJson, registerAgentDirectives, registerAgentGlossary, registerAgentResponseSchema, registerAgentScenarios, removeAgentDirectives, removeAgentGlossary, removeAgentResponseSchema, removeAgentScenarios, } from './agents/common.js';
10
10
  export class ModuleEntry {
11
11
  constructor(name, moduleName) {
12
+ this.taggedAsPublic = false;
12
13
  this.name = name;
13
14
  this.moduleName = moduleName;
14
15
  }
15
16
  getFqName() {
16
17
  return makeFqName(this.moduleName, this.name);
17
18
  }
19
+ setPublic(flag) {
20
+ this.taggedAsPublic = flag;
21
+ return this;
22
+ }
23
+ isPublic() {
24
+ return this.taggedAsPublic;
25
+ }
18
26
  }
19
27
  function normalizePropertyNames(props) {
20
28
  // Convert iterator to array for compatibility with different Node.js versions
@@ -452,6 +460,9 @@ export class Record extends ModuleEntry {
452
460
  const ms = `@meta ${JSON.stringify(metaObj)}`;
453
461
  scms = `${scms},\n ${ms}`;
454
462
  }
463
+ if (this.isPublic()) {
464
+ s = `@public ${s}`;
465
+ }
455
466
  return s.concat('\n{', scms, '\n}\n');
456
467
  }
457
468
  getUserAttributes() {
@@ -835,22 +846,28 @@ export class Agent extends Record {
835
846
  if (conds) {
836
847
  attrs.push(` directives ${conds}`);
837
848
  }
838
- const scns = getAgentScenarios(fqName);
849
+ const scns = getAgentScenariosJson(fqName);
839
850
  if (scns) {
840
- attrs.push(` scenarios ${JSON.stringify(scns)}`);
851
+ attrs.push(` scenarios ${scns}`);
841
852
  }
842
- const gls = getAgentGlossary(fqName);
853
+ const gls = getAgentGlossaryJson(fqName);
843
854
  if (gls) {
844
- attrs.push(` glossary ${JSON.stringify(gls)}`);
855
+ attrs.push(` glossary ${gls}`);
845
856
  }
846
857
  const rscm = getAgentResponseSchema(fqName);
847
858
  if (rscm) {
848
859
  attrs.push(` responseSchema ${rscm}`);
849
860
  }
850
- return `agent ${Agent.NormalizeName(this.name)}
861
+ const s = `agent ${Agent.NormalizeName(this.name)}
851
862
  {
852
863
  ${attrs.join(',\n')}
853
864
  }`;
865
+ if (this.isPublic()) {
866
+ return `@public ${s}`;
867
+ }
868
+ else {
869
+ return s;
870
+ }
854
871
  }
855
872
  static EscapeName(n) {
856
873
  if (n.endsWith(Agent.Suffix)) {
@@ -893,6 +910,10 @@ export class Event extends Record {
893
910
  super(...arguments);
894
911
  this.type = RecordType.EVENT;
895
912
  }
913
+ isSystemDefined() {
914
+ var _a;
915
+ return ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.get(SystemDefinedEvent)) === 'true';
916
+ }
896
917
  }
897
918
  var RelType;
898
919
  (function (RelType) {
@@ -911,7 +932,7 @@ export function newRelNodeEntry(nodeFqName, alias) {
911
932
  function relNodeEntryToString(node) {
912
933
  let n = `${node.origName}`;
913
934
  if (node.origAlias) {
914
- n = n.concat(` as ${node.origAlias}`);
935
+ n = n.concat(` @as ${node.origAlias}`);
915
936
  }
916
937
  return n;
917
938
  }
@@ -1093,10 +1114,10 @@ export class Relationship extends Record {
1093
1114
  }
1094
1115
  }
1095
1116
  export class Workflow extends ModuleEntry {
1096
- constructor(name, patterns, moduleName, generatedName = false) {
1117
+ constructor(name, patterns, moduleName, isPrePost = false) {
1097
1118
  super(name, moduleName);
1098
1119
  this.statements = patterns;
1099
- this.generatedName = generatedName;
1120
+ this.isPrePost = isPrePost;
1100
1121
  }
1101
1122
  async addStatement(stmtCode) {
1102
1123
  const result = await parseStatement(stmtCode);
@@ -1222,11 +1243,30 @@ export class Workflow extends ModuleEntry {
1222
1243
  statementsToStrings() {
1223
1244
  return this.statementsToStringsHelper(this.statements);
1224
1245
  }
1246
+ setPublic(flag) {
1247
+ super.setPublic(flag);
1248
+ if (!this.isPrePost) {
1249
+ const n = normalizeWorkflowName(this.name);
1250
+ const event = getEvent(n, this.moduleName);
1251
+ event.setPublic(flag);
1252
+ }
1253
+ return this;
1254
+ }
1225
1255
  toString() {
1226
- const n = this.generatedName ? untangleWorkflowName(this.name) : this.name;
1227
- let s = `workflow ${normalizeWorkflowName(n)} {\n`;
1256
+ const n = this.isPrePost ? untangleWorkflowName(this.name) : this.name;
1257
+ const nn = normalizeWorkflowName(n);
1258
+ let s = `workflow ${nn} {\n`;
1228
1259
  const ss = this.statementsToStringsHelper(this.statements);
1229
1260
  s = s.concat(joinStatements(ss));
1261
+ if (!this.isPrePost) {
1262
+ const event = getEvent(nn, this.moduleName);
1263
+ if ((event.isPublic() && event.isSystemDefined()) || this.isPublic()) {
1264
+ s = `@public ${s}`;
1265
+ }
1266
+ }
1267
+ else if (this.isPublic()) {
1268
+ s = `@public ${s}`;
1269
+ }
1230
1270
  return s.concat('\n}');
1231
1271
  }
1232
1272
  }
@@ -1310,6 +1350,48 @@ export class Flow extends ModuleEntry {
1310
1350
  }`;
1311
1351
  }
1312
1352
  }
1353
+ class Scenario extends ModuleEntry {
1354
+ constructor(def, moduleName) {
1355
+ super(def.name, moduleName);
1356
+ this.def = def;
1357
+ }
1358
+ toString() {
1359
+ var _a;
1360
+ const s = (_a = this.def.$cstNode) === null || _a === void 0 ? void 0 : _a.text;
1361
+ if (s) {
1362
+ return s;
1363
+ }
1364
+ throw new Error(`failed to generate code for scenario ${this.moduleName}/${this.name}`);
1365
+ }
1366
+ }
1367
+ class Directive extends ModuleEntry {
1368
+ constructor(def, moduleName) {
1369
+ super(def.name, moduleName);
1370
+ this.def = def;
1371
+ }
1372
+ toString() {
1373
+ var _a;
1374
+ const s = (_a = this.def.$cstNode) === null || _a === void 0 ? void 0 : _a.text;
1375
+ if (s) {
1376
+ return s;
1377
+ }
1378
+ throw new Error(`failed to generate code for directive ${this.moduleName}/${this.name}`);
1379
+ }
1380
+ }
1381
+ class GlossaryEntry extends ModuleEntry {
1382
+ constructor(def, moduleName) {
1383
+ super(def.name, moduleName);
1384
+ this.def = def;
1385
+ }
1386
+ toString() {
1387
+ var _a;
1388
+ const s = (_a = this.def.$cstNode) === null || _a === void 0 ? void 0 : _a.text;
1389
+ if (s) {
1390
+ return s;
1391
+ }
1392
+ throw new Error(`failed to generate code for glossaryEntry ${this.moduleName}/${this.name}`);
1393
+ }
1394
+ }
1313
1395
  export function flowGraphNext(graph, currentNode, onCondition) {
1314
1396
  var _a;
1315
1397
  if (!currentNode) {
@@ -1440,6 +1522,63 @@ export class Module {
1440
1522
  }
1441
1523
  return undefined;
1442
1524
  }
1525
+ addScenario(scn) {
1526
+ const entry = new Scenario(scn, this.name);
1527
+ this.addEntry(entry);
1528
+ return entry;
1529
+ }
1530
+ removeScenario(name) {
1531
+ let idx = -1;
1532
+ for (let i = 0; i < this.entries.length; ++i) {
1533
+ const entry = this.entries[i];
1534
+ if (entry.name === name && entry instanceof Scenario) {
1535
+ idx = i;
1536
+ break;
1537
+ }
1538
+ }
1539
+ if (idx >= 0) {
1540
+ this.entries.splice(idx, 1);
1541
+ }
1542
+ return this;
1543
+ }
1544
+ addDirective(dd) {
1545
+ const entry = new Directive(dd, this.name);
1546
+ this.addEntry(entry);
1547
+ return entry;
1548
+ }
1549
+ removeDirective(name) {
1550
+ let idx = -1;
1551
+ for (let i = 0; i < this.entries.length; ++i) {
1552
+ const entry = this.entries[i];
1553
+ if (entry.name === name && entry instanceof Directive) {
1554
+ idx = i;
1555
+ break;
1556
+ }
1557
+ }
1558
+ if (idx >= 0) {
1559
+ this.entries.splice(idx, 1);
1560
+ }
1561
+ return this;
1562
+ }
1563
+ addGlossaryEntry(ge) {
1564
+ const entry = new GlossaryEntry(ge, this.name);
1565
+ this.addEntry(entry);
1566
+ return entry;
1567
+ }
1568
+ removeGlossaryEntry(name) {
1569
+ let idx = -1;
1570
+ for (let i = 0; i < this.entries.length; ++i) {
1571
+ const entry = this.entries[i];
1572
+ if (entry.name === name && entry instanceof GlossaryEntry) {
1573
+ idx = i;
1574
+ break;
1575
+ }
1576
+ }
1577
+ if (idx >= 0) {
1578
+ this.entries.splice(idx, 1);
1579
+ }
1580
+ return this;
1581
+ }
1443
1582
  addStandaloneStatement(stmt) {
1444
1583
  const s = new StandaloneStatement(stmt, this.name);
1445
1584
  this.addEntry(s);
@@ -1465,6 +1604,12 @@ export class Module {
1465
1604
  throw new Error(`Entry ${entryName} not found in module ${this.name}`);
1466
1605
  return this.entries[idx];
1467
1606
  }
1607
+ getEntrySafe(entryName) {
1608
+ const idx = this.getEntryIndex(entryName);
1609
+ if (idx < 0)
1610
+ return undefined;
1611
+ return this.entries[idx];
1612
+ }
1468
1613
  getRecord(recordName) {
1469
1614
  const e = this.getEntry(recordName);
1470
1615
  if (e instanceof Record) {
@@ -1524,10 +1669,24 @@ export class Module {
1524
1669
  });
1525
1670
  }
1526
1671
  getWorkflowForEvent(eventName) {
1527
- return this.getEntry(asWorkflowName(eventName));
1672
+ const entry = this.getEntrySafe(asWorkflowName(eventName));
1673
+ if (entry)
1674
+ return entry;
1675
+ else
1676
+ return undefined;
1677
+ }
1678
+ eventIsPublic(eventName) {
1679
+ const entry = this.getEntry(eventName);
1680
+ if (entry instanceof Event) {
1681
+ return entry.isPublic();
1682
+ }
1683
+ return false;
1528
1684
  }
1529
1685
  isPrePostEvent(eventName) {
1530
- return this.getWorkflowForEvent(eventName).generatedName;
1686
+ const wf = this.getWorkflowForEvent(eventName);
1687
+ if (wf)
1688
+ return wf.isPrePost;
1689
+ return false;
1531
1690
  }
1532
1691
  isEntryOfType(t, name) {
1533
1692
  const entry = this.getEntriesOfType(t).find((v) => {
@@ -1703,6 +1862,10 @@ const TextualTypes = new Set(['String', 'Email', 'UUID', 'DateTime', 'Date', 'Ti
1703
1862
  function isTextualType(type) {
1704
1863
  return TextualTypes.has(type);
1705
1864
  }
1865
+ const NumericTypes = new Set(['Int', 'Number', 'Float', 'Decimal']);
1866
+ function isNumericType(type) {
1867
+ return NumericTypes.has(type);
1868
+ }
1706
1869
  export function isBuiltInType(type) {
1707
1870
  return builtInTypes.has(type);
1708
1871
  }
@@ -1824,6 +1987,9 @@ export function isArrayAttribute(attrSpec) {
1824
1987
  export function isObjectAttribute(attrSpec) {
1825
1988
  return getBooleanProperty('object', attrSpec);
1826
1989
  }
1990
+ export function isNumericAttribute(attrSpec) {
1991
+ return isNumericType(attrSpec.type);
1992
+ }
1827
1993
  export function getAttributeExpr(attrSpec) {
1828
1994
  return getAnyProperty('expr', attrSpec);
1829
1995
  }
@@ -1897,7 +2063,7 @@ function normalizeWorkflowName(n) {
1897
2063
  }
1898
2064
  return n;
1899
2065
  }
1900
- export function addWorkflow(name, moduleName = activeModule, statements, hdr) {
2066
+ export function addWorkflow(name, moduleName = activeModule, statements, hdr, ispub = false) {
1901
2067
  if (hdr) {
1902
2068
  name = prePostWorkflowName(hdr.tag, hdr.prefix, hdr.name, moduleName);
1903
2069
  }
@@ -1908,9 +2074,11 @@ export function addWorkflow(name, moduleName = activeModule, statements, hdr) {
1908
2074
  throw new Error(`Not an event, cannot attach workflow to ${entry.name}`);
1909
2075
  }
1910
2076
  else {
1911
- addEvent(name, moduleName);
1912
- const event = module.getEntry(name);
2077
+ const event = addEvent(name, moduleName);
1913
2078
  event.addMeta(SystemDefinedEvent, 'true');
2079
+ if (ispub) {
2080
+ event.setPublic(true);
2081
+ }
1914
2082
  }
1915
2083
  if (!statements)
1916
2084
  statements = new Array();
@@ -2239,7 +2407,11 @@ export class Instance {
2239
2407
  attrs.forEach((v, k) => {
2240
2408
  const attrSpec = this.record.schema.get(k);
2241
2409
  if (attrSpec) {
2242
- if ((isArrayAttribute(attrSpec) || isObjectAttribute(attrSpec)) && isString(v)) {
2410
+ const isstr = isString(v);
2411
+ if (isNumericAttribute(attrSpec) && isstr) {
2412
+ attrs.set(k, Number(v));
2413
+ }
2414
+ else if ((isArrayAttribute(attrSpec) || isObjectAttribute(attrSpec)) && isstr) {
2243
2415
  const obj = JSON.parse(v);
2244
2416
  attrs.set(k, obj);
2245
2417
  }
@@ -2533,7 +2705,7 @@ export function makeInstance(moduleName, entryName, attributes, queryAttributes,
2533
2705
  if (schema.size > 0) {
2534
2706
  attributes.forEach((value, key) => {
2535
2707
  if (!schema.has(key)) {
2536
- throw new Error(`Invalid attribute ${key} specified for ${moduleName}/${entryName}`);
2708
+ throw new Error(`Invalid attribute '${key}' specified for ${moduleName}/${entryName}`);
2537
2709
  }
2538
2710
  const spec = getAttributeSpec(schema, key);
2539
2711
  if (value != null && value != undefined)