agentlang 0.7.0 → 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 (63) 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 +16 -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 +16 -1
  18. package/out/runtime/defs.d.ts.map +1 -1
  19. package/out/runtime/defs.js +29 -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/jsmodules.d.ts +8 -0
  29. package/out/runtime/jsmodules.d.ts.map +1 -1
  30. package/out/runtime/jsmodules.js +139 -22
  31. package/out/runtime/jsmodules.js.map +1 -1
  32. package/out/runtime/loader.d.ts +1 -0
  33. package/out/runtime/loader.d.ts.map +1 -1
  34. package/out/runtime/loader.js +9 -2
  35. package/out/runtime/loader.js.map +1 -1
  36. package/out/runtime/module-transform.d.ts +77 -0
  37. package/out/runtime/module-transform.d.ts.map +1 -0
  38. package/out/runtime/module-transform.js +201 -0
  39. package/out/runtime/module-transform.js.map +1 -0
  40. package/out/runtime/modules/ai.d.ts.map +1 -1
  41. package/out/runtime/modules/ai.js +18 -6
  42. package/out/runtime/modules/ai.js.map +1 -1
  43. package/out/runtime/modules/core.d.ts +5 -0
  44. package/out/runtime/modules/core.d.ts.map +1 -1
  45. package/out/runtime/modules/core.js +58 -6
  46. package/out/runtime/modules/core.js.map +1 -1
  47. package/out/syntaxes/agentlang.monarch.js +1 -1
  48. package/out/syntaxes/agentlang.monarch.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/api/http.ts +51 -25
  51. package/src/cli/main.ts +20 -0
  52. package/src/language/agentlang.langium +3 -1
  53. package/src/language/generated/ast.ts +32 -8
  54. package/src/language/generated/grammar.ts +215 -164
  55. package/src/runtime/defs.ts +47 -0
  56. package/src/runtime/exec-graph.ts +13 -0
  57. package/src/runtime/interpreter.ts +12 -0
  58. package/src/runtime/jsmodules.ts +189 -22
  59. package/src/runtime/loader.ts +10 -2
  60. package/src/runtime/module-transform.ts +277 -0
  61. package/src/runtime/modules/ai.ts +20 -6
  62. package/src/runtime/modules/core.ts +80 -5
  63. package/src/syntaxes/agentlang.monarch.ts +1 -1
@@ -15,6 +15,7 @@ import {
15
15
  parseAndEvaluateStatement,
16
16
  } from '../interpreter.js';
17
17
  import {
18
+ Agent,
18
19
  asJSONSchema,
19
20
  Decision,
20
21
  fetchModule,
@@ -663,12 +664,25 @@ Only return a pure JSON object with no extra text, annotations etc.`;
663
664
  if (entryName) {
664
665
  const hasmod = slimModules.has(moduleName);
665
666
  const defs = hasmod ? slimModules.get(moduleName) : new Array<string>();
666
- const entry = m.getEntry(entryName);
667
- const s =
668
- entry instanceof Record ? (entry as Record).toString_(true) : entry.toString();
669
- defs?.push(s);
670
- if (!hasmod && defs) {
671
- slimModules.set(moduleName, defs);
667
+ // Try to get entry directly first, then try as an agent (agents have _agent suffix)
668
+ let entry = m.getEntrySafe(entryName);
669
+ if (!entry) {
670
+ // Try with agent suffix - agents are stored with escaped names
671
+ entry = m.getEntrySafe(Agent.EscapeName(entryName));
672
+ }
673
+ if (entry) {
674
+ const s =
675
+ entry instanceof Record ? (entry as Record).toString_(true) : entry.toString();
676
+ // Add full qualified name comment so LLM knows how to reference it
677
+ const fqName = `${moduleName}/${entryName}`;
678
+ defs?.push(
679
+ `# Tool: ${fqName}\n# Use as: {${fqName} {...}} or {${fqName}? {...}}\n${s}`
680
+ );
681
+ if (!hasmod && defs) {
682
+ slimModules.set(moduleName, defs);
683
+ }
684
+ } else {
685
+ logger.warn(`Tool entry '${entryName}' not found in module '${moduleName}'`);
672
686
  }
673
687
  } else {
674
688
  tooldefs.push(fetchModule(moduleName).toString());
@@ -7,8 +7,17 @@ import {
7
7
  escapeSpecialChars,
8
8
  isString,
9
9
  restoreSpecialChars,
10
+ makeCoreModuleName,
10
11
  } from '../util.js';
11
- 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';
12
21
  import {
13
22
  Environment,
14
23
  evaluate,
@@ -20,7 +29,12 @@ import { logger } from '../logger.js';
20
29
  import { Statement } from '../../language/generated/ast.js';
21
30
  import { parseModule, parseStatements } from '../../language/parser.js';
22
31
  import { Resolver } from '../resolvers/interface.js';
23
- import { FlowSuspensionTag, ForceReadPermFlag, PathAttributeName } from '../defs.js';
32
+ import {
33
+ FlowSuspensionTag,
34
+ ForceReadPermFlag,
35
+ InternDynamicModule,
36
+ PathAttributeName,
37
+ } from '../defs.js';
24
38
  import { getMonitor, getMonitorsForEvent, Monitor } from '../monitor.js';
25
39
 
26
40
  const CoreModuleDefinition = `module ${DefaultModuleName}
@@ -127,6 +141,18 @@ workflow validateModule {
127
141
  await Core.validateModule(validateModule.data)
128
142
  }
129
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
+
130
156
  entity Migration {
131
157
  appVersion String @id,
132
158
  ups String @optional,
@@ -139,9 +165,18 @@ export const CoreModules: string[] = [];
139
165
  export function registerCoreModules() {
140
166
  DefaultModules.add(DefaultModuleName);
141
167
  CoreModules.push(CoreModuleDefinition);
142
- [auth, ai, files].forEach((mdef: string) => {
143
- CoreModules.push(mdef);
144
- DefaultModules.add(mdef);
168
+
169
+ // Map of module definitions to their names for proper DefaultModules registration
170
+ const coreModuleInfo: Array<{ def: string; name: string }> = [
171
+ { def: auth, name: makeCoreModuleName('auth') },
172
+ { def: ai, name: makeCoreModuleName('ai') },
173
+ { def: files, name: makeCoreModuleName('files') },
174
+ ];
175
+
176
+ coreModuleInfo.forEach(({ def, name }) => {
177
+ CoreModules.push(def);
178
+ // Add module NAME (not definition) to DefaultModules so flushAllModules() doesn't remove core modules
179
+ DefaultModules.add(name);
145
180
  });
146
181
  }
147
182
 
@@ -417,6 +452,46 @@ export async function validateModule(moduleDef: any): Promise<Instance> {
417
452
  }
418
453
  }
419
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
+
420
495
  const SqlSep = ';\n\n';
421
496
 
422
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
  '!=','*','+',',','-','-->','.','/',':',';','<','<=','<>','=','==','>','>=','?','@'