agentlang 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/out/api/http.d.ts.map +1 -1
  2. package/out/api/http.js +46 -26
  3. package/out/api/http.js.map +1 -1
  4. package/out/cli/main.d.ts +1 -0
  5. package/out/cli/main.d.ts.map +1 -1
  6. package/out/cli/main.js +15 -2
  7. package/out/cli/main.js.map +1 -1
  8. package/out/language/generated/ast.d.ts +15 -6
  9. package/out/language/generated/ast.d.ts.map +1 -1
  10. package/out/language/generated/ast.js +15 -2
  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 +215 -164
  14. package/out/language/generated/grammar.js.map +1 -1
  15. package/out/language/main.cjs +227 -166
  16. package/out/language/main.cjs.map +2 -2
  17. package/out/runtime/defs.d.ts +7 -1
  18. package/out/runtime/defs.d.ts.map +1 -1
  19. package/out/runtime/defs.js +22 -1
  20. package/out/runtime/defs.js.map +1 -1
  21. package/out/runtime/exec-graph.d.ts.map +1 -1
  22. package/out/runtime/exec-graph.js +8 -0
  23. package/out/runtime/exec-graph.js.map +1 -1
  24. package/out/runtime/interpreter.d.ts +2 -1
  25. package/out/runtime/interpreter.d.ts.map +1 -1
  26. package/out/runtime/interpreter.js +10 -0
  27. package/out/runtime/interpreter.js.map +1 -1
  28. package/out/runtime/loader.d.ts +1 -0
  29. package/out/runtime/loader.d.ts.map +1 -1
  30. package/out/runtime/loader.js +6 -0
  31. package/out/runtime/loader.js.map +1 -1
  32. package/out/runtime/modules/core.d.ts +5 -0
  33. package/out/runtime/modules/core.d.ts.map +1 -1
  34. package/out/runtime/modules/core.js +47 -2
  35. package/out/runtime/modules/core.js.map +1 -1
  36. package/out/setupClassic.d.ts +98 -0
  37. package/out/setupClassic.d.ts.map +1 -0
  38. package/out/setupClassic.js +38 -0
  39. package/out/setupClassic.js.map +1 -0
  40. package/out/setupCommon.d.ts +2 -0
  41. package/out/setupCommon.d.ts.map +1 -0
  42. package/out/setupCommon.js +33 -0
  43. package/out/setupCommon.js.map +1 -0
  44. package/out/setupExtended.d.ts +40 -0
  45. package/out/setupExtended.d.ts.map +1 -0
  46. package/out/setupExtended.js +67 -0
  47. package/out/setupExtended.js.map +1 -0
  48. package/out/syntaxes/agentlang.monarch.js +1 -1
  49. package/out/syntaxes/agentlang.monarch.js.map +1 -1
  50. package/package.json +186 -185
  51. package/src/api/http.ts +51 -25
  52. package/src/cli/main.ts +20 -0
  53. package/src/language/agentlang.langium +3 -1
  54. package/src/language/generated/ast.ts +31 -7
  55. package/src/language/generated/grammar.ts +215 -164
  56. package/src/runtime/defs.ts +27 -0
  57. package/src/runtime/exec-graph.ts +13 -0
  58. package/src/runtime/interpreter.ts +12 -0
  59. package/src/runtime/loader.ts +7 -0
  60. package/src/runtime/modules/core.ts +67 -2
  61. package/src/syntaxes/agentlang.monarch.ts +1 -1
@@ -125,6 +125,7 @@ export enum SubGraphType {
125
125
  PURGE,
126
126
  RETURN,
127
127
  AGENT,
128
+ THROW,
128
129
  NONE,
129
130
  }
130
131
 
@@ -406,3 +407,29 @@ export function isRuntimeMode_generate_migration(): boolean {
406
407
  export function isRuntimeMode_undo_migration(): boolean {
407
408
  return RuntimeMode === RuntimeModeTag.UNDO_MIGRATION;
408
409
  }
410
+
411
+ let UpdateEventEndpoints: Function | undefined;
412
+ let UpdateEntityEndpoints: Function | undefined;
413
+
414
+ export function setEventEndpointsUpdater(f: Function) {
415
+ UpdateEventEndpoints = f;
416
+ }
417
+
418
+ export function setEntityEndpointsUpdater(f: Function) {
419
+ UpdateEntityEndpoints = f;
420
+ }
421
+
422
+ export function updateEndpoints(moduleName: string) {
423
+ if (UpdateEventEndpoints !== undefined) {
424
+ UpdateEventEndpoints(moduleName);
425
+ }
426
+ if (UpdateEntityEndpoints !== undefined) {
427
+ UpdateEntityEndpoints(moduleName);
428
+ }
429
+ }
430
+
431
+ export let InternDynamicModule: Function | undefined;
432
+
433
+ export function setInternDynamicModuleFn(f: Function) {
434
+ InternDynamicModule = f;
435
+ }
@@ -13,6 +13,7 @@ import {
13
13
  Purge,
14
14
  Return,
15
15
  Statement,
16
+ ThrowError,
16
17
  } from '../language/generated/ast.js';
17
18
  import { parseModule, parseStatement } from '../language/parser.js';
18
19
  import { ExecGraph, ExecGraphNode, ExecGraphWalker, SubGraphType } from './defs.js';
@@ -157,6 +158,15 @@ class GraphGenerator extends PatternHandler {
157
158
  this.handleSubPattern(SubGraphType.RETURN, ret.pattern, env);
158
159
  }
159
160
 
161
+ override async handleThrow(throwErr: ThrowError, env: Environment) {
162
+ const handler = new GraphGenerator();
163
+ await handler.handleExpression(
164
+ throwErr.reason,
165
+ Environment.from(env).setActiveUserData(throwErr.reason)
166
+ );
167
+ this.addSubGraph(SubGraphType.THROW, handler.getGraph(), env);
168
+ }
169
+
160
170
  getGraph(): ExecGraph {
161
171
  return this.graph;
162
172
  }
@@ -261,6 +271,9 @@ export async function executeGraph(execGraph: ExecGraph, env: Environment): Prom
261
271
  case SubGraphType.RETURN:
262
272
  await executeReturnSubGraph(subg, env);
263
273
  return;
274
+ case SubGraphType.THROW:
275
+ await evaluateExpression(subg.getRootNodes()[0].code as Expr, env);
276
+ throw new Error(env.getLastResult());
264
277
  default:
265
278
  throw new Error(`Invalid sub-graph type: ${node.subGraphType}`);
266
279
  }
@@ -27,6 +27,7 @@ import {
27
27
  SelectIntoSpec,
28
28
  SetAttribute,
29
29
  Statement,
30
+ ThrowError,
30
31
  } from '../language/generated/ast.js';
31
32
  import {
32
33
  maybeInstanceAsString,
@@ -1217,6 +1218,10 @@ export class PatternHandler {
1217
1218
  async handleReturn(ret: Return, env: Environment) {
1218
1219
  await evaluatePattern(ret.pattern, env);
1219
1220
  }
1221
+
1222
+ async handleThrow(throwErr: ThrowError, env: Environment) {
1223
+ await evaluateThrowError(throwErr, env);
1224
+ }
1220
1225
  }
1221
1226
 
1222
1227
  const DefaultPatternHandler = new PatternHandler();
@@ -1243,9 +1248,16 @@ export async function evaluatePattern(
1243
1248
  } else if (pat.return) {
1244
1249
  await handler.handleReturn(pat.return, env);
1245
1250
  env.markForReturn();
1251
+ } else if (pat.throwError) {
1252
+ await handler.handleThrow(pat.throwError, env);
1246
1253
  }
1247
1254
  }
1248
1255
 
1256
+ async function evaluateThrowError(throwErr: ThrowError, env: Environment) {
1257
+ await evaluateExpression(throwErr.reason, env);
1258
+ throw new Error(env.getLastResult());
1259
+ }
1260
+
1249
1261
  async function evaluateFullTextSearch(fts: FullTextSearch, env: Environment): Promise<void> {
1250
1262
  let n = escapeQueryName(fts.name);
1251
1263
  if (!isFqName(n)) {
@@ -1137,6 +1137,13 @@ export async function parseAndIntern(code: string, moduleName?: string) {
1137
1137
  await internModule(r.parseResult.value);
1138
1138
  }
1139
1139
 
1140
+ export async function refreshModuleDefinition(moduleName: string, moduleDefinition: string) {
1141
+ removeModule(moduleName);
1142
+ const r = await parse(moduleDefinition);
1143
+ maybeRaiseParserErrors(r);
1144
+ await internModule(r.parseResult.value);
1145
+ }
1146
+
1140
1147
  export async function internModule(
1141
1148
  module: ModuleDefinition,
1142
1149
  moduleFileName?: string
@@ -9,7 +9,15 @@ import {
9
9
  restoreSpecialChars,
10
10
  makeCoreModuleName,
11
11
  } from '../util.js';
12
- import { Instance, isInstanceOfType, makeInstance, newInstanceAttributes } from '../module.js';
12
+ import {
13
+ fetchModule,
14
+ Instance,
15
+ isInstanceOfType,
16
+ isModule,
17
+ makeInstance,
18
+ newInstanceAttributes,
19
+ removeModule,
20
+ } from '../module.js';
13
21
  import {
14
22
  Environment,
15
23
  evaluate,
@@ -21,7 +29,12 @@ import { logger } from '../logger.js';
21
29
  import { Statement } from '../../language/generated/ast.js';
22
30
  import { parseModule, parseStatements } from '../../language/parser.js';
23
31
  import { Resolver } from '../resolvers/interface.js';
24
- import { FlowSuspensionTag, ForceReadPermFlag, PathAttributeName } from '../defs.js';
32
+ import {
33
+ FlowSuspensionTag,
34
+ ForceReadPermFlag,
35
+ InternDynamicModule,
36
+ PathAttributeName,
37
+ } from '../defs.js';
25
38
  import { getMonitor, getMonitorsForEvent, Monitor } from '../monitor.js';
26
39
 
27
40
  const CoreModuleDefinition = `module ${DefaultModuleName}
@@ -128,6 +141,18 @@ workflow validateModule {
128
141
  await Core.validateModule(validateModule.data)
129
142
  }
130
143
 
144
+ entity Module {
145
+ name String @id,
146
+ definition String
147
+ }
148
+
149
+ resolver moduleResolver [agentlang/Module] {
150
+ create Core.createModule,
151
+ update Core.updateModule,
152
+ delete Core.deleteModule,
153
+ query Core.getModule
154
+ }
155
+
131
156
  entity Migration {
132
157
  appVersion String @id,
133
158
  ups String @optional,
@@ -427,6 +452,46 @@ export async function validateModule(moduleDef: any): Promise<Instance> {
427
452
  }
428
453
  }
429
454
 
455
+ export async function internModuleHelper(
456
+ name: string,
457
+ definition: string
458
+ ): Promise<string | undefined> {
459
+ if (InternDynamicModule !== undefined) {
460
+ return await InternDynamicModule(name, definition);
461
+ } else {
462
+ return undefined;
463
+ }
464
+ }
465
+
466
+ export async function createModule(_: Resolver, inst: Instance) {
467
+ await internModuleHelper(inst.lookup('name'), inst.lookup('definition'));
468
+ return inst;
469
+ }
470
+
471
+ export async function updateModule(r: Resolver, inst: Instance) {
472
+ return await createModule(r, inst);
473
+ }
474
+
475
+ export async function deleteModule(_: Resolver, inst: Instance) {
476
+ removeModule(inst.lookup('name'));
477
+ return inst;
478
+ }
479
+
480
+ export async function getModule(_: Resolver, inst: Instance) {
481
+ const p = inst.lookupQueryVal(PathAttributeName);
482
+ if (p !== undefined) {
483
+ const idx = p.lastIndexOf('/');
484
+ const n = p.substring(idx + 1);
485
+ if (isModule(n)) {
486
+ const m = fetchModule(n);
487
+ const defn = inst.lookup('definition') || m.toString();
488
+ const attrs = newInstanceAttributes().set('name', n).set('definition', defn);
489
+ return [makeInstance('agentlang', 'Module', attrs)];
490
+ }
491
+ }
492
+ return null;
493
+ }
494
+
430
495
  const SqlSep = ';\n\n';
431
496
 
432
497
  export async function saveMigration(
@@ -1,7 +1,7 @@
1
1
  // Monarch syntax highlighting for the agentlang language.
2
2
  export default {
3
3
  keywords: [
4
- '@actions','@after','@as','@async','@before','@catch','@distinct','@enum','@expr','@from','@full_join','@inner_join','@into','@join','@left_join','@meta','@oneof','@public','@rbac','@ref','@right_join','@then','@upsert','@with_unique','agent','agentlang/retry','allow','and','attempts','await','backoff','between','case','commitTransaction','contains','create','decision','delete','directive','else','entity','error','event','extends','false','flow','for','glossaryEntry','if','import','in','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','rollbackTransaction','scenario','startTransaction','subscribe','true','update','upsert','where','workflow'
4
+ '@actions','@after','@as','@async','@before','@catch','@distinct','@enum','@expr','@from','@full_join','@inner_join','@into','@join','@left_join','@meta','@oneof','@public','@rbac','@ref','@right_join','@then','@upsert','@with_unique','agent','agentlang/retry','allow','and','attempts','await','backoff','between','case','commitTransaction','contains','create','decision','delete','directive','else','entity','error','event','extends','false','flow','for','glossaryEntry','if','import','in','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','rollbackTransaction','scenario','startTransaction','subscribe','throw','true','update','upsert','where','workflow'
5
5
  ],
6
6
  operators: [
7
7
  '!=','*','+',',','-','-->','.','/',':',';','<','<=','<>','=','==','>','>=','?','@'