agentlang 0.9.4 → 0.9.6

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 (105) hide show
  1. package/out/api/http.js +8 -2
  2. package/out/api/http.js.map +1 -1
  3. package/out/extension/main.cjs +253 -253
  4. package/out/extension/main.cjs.map +2 -2
  5. package/out/language/generated/ast.d.ts +1997 -151
  6. package/out/language/generated/ast.d.ts.map +1 -1
  7. package/out/language/generated/ast.js +2113 -1263
  8. package/out/language/generated/ast.js.map +1 -1
  9. package/out/language/generated/grammar.d.ts +1 -1
  10. package/out/language/generated/grammar.d.ts.map +1 -1
  11. package/out/language/generated/grammar.js +649 -762
  12. package/out/language/generated/grammar.js.map +1 -1
  13. package/out/language/generated/module.d.ts +1 -1
  14. package/out/language/generated/module.js +1 -1
  15. package/out/language/main.cjs +6401 -4072
  16. package/out/language/main.cjs.map +4 -4
  17. package/out/language/parser.js +8 -8
  18. package/out/language/parser.js.map +1 -1
  19. package/out/runtime/agents/common.d.ts +7 -1
  20. package/out/runtime/agents/common.d.ts.map +1 -1
  21. package/out/runtime/agents/common.js +101 -0
  22. package/out/runtime/agents/common.js.map +1 -1
  23. package/out/runtime/agents/impl/anthropic.js +4 -4
  24. package/out/runtime/agents/impl/anthropic.js.map +1 -1
  25. package/out/runtime/agents/impl/openai.js +4 -4
  26. package/out/runtime/agents/impl/openai.js.map +1 -1
  27. package/out/runtime/auth/defs.d.ts +1 -1
  28. package/out/runtime/auth/defs.js +1 -1
  29. package/out/runtime/defs.d.ts +1 -1
  30. package/out/runtime/defs.js +1 -1
  31. package/out/runtime/exec-graph.d.ts.map +1 -1
  32. package/out/runtime/exec-graph.js +5 -0
  33. package/out/runtime/exec-graph.js.map +1 -1
  34. package/out/runtime/interpreter.d.ts +4 -0
  35. package/out/runtime/interpreter.d.ts.map +1 -1
  36. package/out/runtime/interpreter.js +20 -4
  37. package/out/runtime/interpreter.js.map +1 -1
  38. package/out/runtime/loader.d.ts.map +1 -1
  39. package/out/runtime/loader.js +43 -6
  40. package/out/runtime/loader.js.map +1 -1
  41. package/out/runtime/module.d.ts +18 -3
  42. package/out/runtime/module.d.ts.map +1 -1
  43. package/out/runtime/module.js +62 -4
  44. package/out/runtime/module.js.map +1 -1
  45. package/out/runtime/modules/ai.d.ts +18 -2
  46. package/out/runtime/modules/ai.d.ts.map +1 -1
  47. package/out/runtime/modules/ai.js +271 -21
  48. package/out/runtime/modules/ai.js.map +1 -1
  49. package/out/runtime/modules/auth.d.ts.map +1 -1
  50. package/out/runtime/modules/auth.js +11 -5
  51. package/out/runtime/modules/auth.js.map +1 -1
  52. package/out/runtime/resolvers/interface.d.ts +1 -1
  53. package/out/runtime/resolvers/interface.d.ts.map +1 -1
  54. package/out/runtime/resolvers/interface.js.map +1 -1
  55. package/out/runtime/resolvers/sqldb/database.d.ts +1 -0
  56. package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
  57. package/out/runtime/resolvers/sqldb/database.js +19 -10
  58. package/out/runtime/resolvers/sqldb/database.js.map +1 -1
  59. package/out/runtime/resolvers/sqldb/impl.d.ts +1 -1
  60. package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
  61. package/out/runtime/resolvers/sqldb/impl.js +2 -2
  62. package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
  63. package/out/runtime/state.d.ts +37 -367
  64. package/out/runtime/state.d.ts.map +1 -1
  65. package/out/runtime/state.js +3 -0
  66. package/out/runtime/state.js.map +1 -1
  67. package/out/setupClassic.d.ts +98 -0
  68. package/out/setupClassic.d.ts.map +1 -0
  69. package/out/setupClassic.js +38 -0
  70. package/out/setupClassic.js.map +1 -0
  71. package/out/setupCommon.d.ts +2 -0
  72. package/out/setupCommon.d.ts.map +1 -0
  73. package/out/setupCommon.js +33 -0
  74. package/out/setupCommon.js.map +1 -0
  75. package/out/setupExtended.d.ts +40 -0
  76. package/out/setupExtended.d.ts.map +1 -0
  77. package/out/setupExtended.js +67 -0
  78. package/out/setupExtended.js.map +1 -0
  79. package/out/syntaxes/agentlang.monarch.js +4 -4
  80. package/out/syntaxes/agentlang.monarch.js.map +1 -1
  81. package/out/utils/runtime.d.ts +7 -6
  82. package/out/utils/runtime.d.ts.map +1 -1
  83. package/package.json +185 -187
  84. package/src/api/http.ts +8 -2
  85. package/src/language/agentlang.langium +8 -2
  86. package/src/language/generated/ast.ts +2204 -1322
  87. package/src/language/generated/grammar.ts +649 -762
  88. package/src/language/generated/module.ts +1 -1
  89. package/src/language/parser.ts +8 -8
  90. package/src/runtime/agents/common.ts +107 -0
  91. package/src/runtime/agents/impl/anthropic.ts +4 -4
  92. package/src/runtime/agents/impl/openai.ts +4 -4
  93. package/src/runtime/auth/defs.ts +1 -1
  94. package/src/runtime/defs.ts +1 -1
  95. package/src/runtime/exec-graph.ts +4 -0
  96. package/src/runtime/interpreter.ts +23 -4
  97. package/src/runtime/loader.ts +43 -4
  98. package/src/runtime/module.ts +80 -3
  99. package/src/runtime/modules/ai.ts +391 -19
  100. package/src/runtime/modules/auth.ts +11 -5
  101. package/src/runtime/resolvers/interface.ts +1 -1
  102. package/src/runtime/resolvers/sqldb/database.ts +20 -11
  103. package/src/runtime/resolvers/sqldb/impl.ts +3 -3
  104. package/src/runtime/state.ts +4 -0
  105. package/src/syntaxes/agentlang.monarch.ts +4 -4
@@ -1,3 +1,4 @@
1
+ import 'reflect-metadata';
1
2
  import {
2
3
  DataSource,
3
4
  EntityManager,
@@ -44,6 +45,7 @@ import {
44
45
  import { saveMigration } from '../../modules/core.js';
45
46
  import { getAppSpec } from '../../loader.js';
46
47
  import { WhereClause } from '../interface.js';
48
+ import { AppConfig } from '../../state.js';
47
49
 
48
50
  export let defaultDataSource: DataSource | undefined;
49
51
 
@@ -227,7 +229,7 @@ function makeSqliteDataSource(
227
229
  const synchronize = needSync();
228
230
  //const runMigrations = isRuntimeMode_migration() || isRuntimeMode_undo_migration() || !synchronize;
229
231
  return new DataSource({
230
- type: 'sqlite',
232
+ type: 'better-sqlite3',
231
233
  database: config?.dbname || mkDbName(),
232
234
  synchronize: synchronize,
233
235
  entities: entities,
@@ -322,9 +324,7 @@ function makeSqljsDataSource(
322
324
  });
323
325
  }
324
326
 
325
- const DbType = 'sqlite';
326
-
327
- function getDbType(config?: DatabaseConfig): string {
327
+ function forceGetDbType(config: DatabaseConfig | undefined): string {
328
328
  if (config?.type) return config.type;
329
329
  let envType: string | undefined;
330
330
  try {
@@ -334,6 +334,13 @@ function getDbType(config?: DatabaseConfig): string {
334
334
  } catch {}
335
335
  if (envType) return envType;
336
336
  if (isBrowser()) return 'sqljs';
337
+ return 'sqlite';
338
+ }
339
+
340
+ let DbType: string | undefined;
341
+
342
+ function getDbType(config: DatabaseConfig | undefined): string {
343
+ if (DbType === undefined) DbType = forceGetDbType(config);
337
344
  return DbType;
338
345
  }
339
346
 
@@ -357,16 +364,16 @@ function getDsFunction(
357
364
  }
358
365
 
359
366
  export function isUsingSqlite(): boolean {
360
- return getDbType() == 'sqlite';
367
+ return getDbType(AppConfig?.store) == 'sqlite';
361
368
  }
362
369
 
363
370
  export function isUsingSqljs(): boolean {
364
- return getDbType() == 'sqljs';
371
+ return getDbType(AppConfig?.store) == 'sqljs';
365
372
  }
366
373
 
367
374
  export function isVectorStoreSupported(): boolean {
368
375
  // Only Postgres supports pgvector
369
- return getDbType() === 'postgres';
376
+ return getDbType(AppConfig?.store) === 'postgres';
370
377
  }
371
378
 
372
379
  export async function initDatabase(config: DatabaseConfig | undefined) {
@@ -402,7 +409,7 @@ export async function initDatabase(config: DatabaseConfig | undefined) {
402
409
  await initVectorStore(vectEnts, DbContext.getGlobalContext());
403
410
  }
404
411
  } else {
405
- throw new Error(`Unsupported database type - ${DbType}`);
412
+ throw new Error(`Unsupported database type - ${getDbType(AppConfig?.store)}`);
406
413
  }
407
414
  }
408
415
  }
@@ -453,7 +460,7 @@ export async function addRowForFullTextSearch(
453
460
 
454
461
  export async function initVectorStore(tableNames: string[], ctx: DbContext) {
455
462
  if (!isVectorStoreSupported()) {
456
- logger.info(`Vector store not supported for ${getDbType()}, skipping init...`);
463
+ logger.info(`Vector store not supported for ${getDbType(AppConfig?.store)}, skipping init...`);
457
464
  return;
458
465
  }
459
466
  let notInited = true;
@@ -474,6 +481,7 @@ export async function initVectorStore(tableNames: string[], ctx: DbContext) {
474
481
  `CREATE TABLE IF NOT EXISTS ${vecTableName} (
475
482
  id varchar PRIMARY KEY,
476
483
  embedding vector(${DefaultVectorDimension}),
484
+ ${TenantAttributeName} varchar,
477
485
  __is_deleted__ boolean default false
478
486
  )`
479
487
  );
@@ -510,7 +518,8 @@ ${ot}.path = ${vecTableName}.id and ${ot}.user_id = '${ctx.authInfo.userId}' and
510
518
  and ${ot}.${TenantAttributeName} = '${tenantId}' and ${vecTableName}.${TenantAttributeName} = '${tenantId}'`;
511
519
  }
512
520
  const sql = `select ${vecTableName}.id from ${vecTableName} ${ownersJoinCond} order by embedding <-> $1 LIMIT ${limit}`;
513
- return await qb.query(sql, [pgvector.toSql(searchVec)]);
521
+ const args = pgvector.toSql(searchVec);
522
+ return await qb.query(sql, [args]);
514
523
  } catch (err: any) {
515
524
  logger.error(`Vector store search failed - ${err}`);
516
525
  return [];
@@ -528,7 +537,7 @@ export async function vectorStoreSearchEntryExists(
528
537
  const vecTableName = tableName + VectorSuffix;
529
538
  const tenantId = await ctx.getTenantId();
530
539
  const result: any[] = await qb.query(
531
- `select id from ${vecTableName} where id = $1 abd ${TenantAttributeName} = '${tenantId}'`,
540
+ `select id from ${vecTableName} where id = $1 and ${TenantAttributeName} = '${tenantId}'`,
532
541
  [id]
533
542
  );
534
543
  return result !== null && result.length > 0;
@@ -553,13 +553,13 @@ export class SqlDbResolver extends Resolver {
553
553
  entryName: string,
554
554
  moduleName: string,
555
555
  query: string,
556
- options?: Map<string, any>
556
+ options?: any
557
557
  ): Promise<any> {
558
558
  const queryVec = await this.embeddings.embedQuery(query);
559
559
  const ctx = this.getDbContext(makeFqName(moduleName, entryName));
560
560
  let limit = 5;
561
- if (options && options.has('limit')) {
562
- limit = options.get('limit') as number;
561
+ if (options && options.limit) {
562
+ limit = options.limit as number;
563
563
  }
564
564
  return await vectorStoreSearch(asTableReference(moduleName, entryName), queryVec, limit, ctx);
565
565
  }
@@ -200,4 +200,8 @@ export class TtlCache<T> {
200
200
  delete(key: string) {
201
201
  this.store.delete(key);
202
202
  }
203
+
204
+ clear() {
205
+ this.store.clear();
206
+ }
203
207
  }
@@ -1,7 +1,7 @@
1
1
  // Monarch syntax highlighting for the agentlang language.
2
2
  export default {
3
3
  keywords: [
4
- '@actions','@after','@as','@asc','@async','@before','@catch','@desc','@distinct','@enum','@expr','@from','@full_join','@groupBy','@inner_join','@into','@join','@left_join','@meta','@oneof','@orderBy','@public','@rbac','@ref','@right_join','@then','@upsert','@where','@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'
4
+ '@actions','@after','@as','@asc','@async','@before','@catch','@desc','@distinct','@enum','@expr','@from','@full_join','@groupBy','@inner_join','@into','@join','@left_join','@meta','@oneof','@orderBy','@public','@rbac','@ref','@right_join','@then','@upsert','@where','@withRole','@with_unique','agent','agentlang/retry','allow','and','attempts','await','backoff','between','case','commitTransaction','contains','create','decision','delete','directive','else','entity','error','eval','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
  '!=','*','+',',','-','-->','.','/',':',';','<','<=','<>','=','==','>','>=','?','@'
@@ -10,10 +10,10 @@ export default {
10
10
 
11
11
  tokenizer: {
12
12
  initial: [
13
- { regex: /(([_a-zA-Z][\w_]*)(\/([_a-zA-Z][\w_]*))?)/, action: { cases: { '@keywords': {"token":"keyword"}, '@default': {"token":"string"} }} },
13
+ { regex: /(?:[_a-zA-Z][\w_]*)(\/(?:[_a-zA-Z][\w_]*))?/, action: { cases: { '@keywords': {"token":"keyword"}, '@default': {"token":"string"} }} },
14
14
  { regex: /[_a-zA-Z][\w_]*/, action: { cases: { '@keywords': {"token":"keyword"}, '@default': {"token":"string"} }} },
15
- { regex: /("(((\\([\s\S]))|((?!(((\\|")|\r)|\n))[\s\S]*?))|(\r?\n))*")/, action: {"token":"string"} },
16
- { regex: /(`(((\\([\s\S]))|((?!(((\\|`)|\r)|\n))[\s\S]*?))|(\r?\n))*`)/, action: {"token":"string"} },
15
+ { regex: /"(\\(?:[\s\S])|(?:(?!(\\|"|\r|\n))[\s\S]*?)|\r?\n)*"/, action: {"token":"string"} },
16
+ { regex: /`(\\(?:[\s\S])|(?:(?!(\\|`|\r|\n))[\s\S]*?)|\r?\n)*`/, action: {"token":"string"} },
17
17
  { regex: /-?[0-9]+/, action: {"token":"number"} },
18
18
  { include: '@whitespace' },
19
19
  { regex: /@symbols/, action: { cases: { '@operators': {"token":"operator"}, '@default': {"token":""} }} },