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.
- package/out/api/http.js +8 -2
- package/out/api/http.js.map +1 -1
- package/out/extension/main.cjs +253 -253
- package/out/extension/main.cjs.map +2 -2
- package/out/language/generated/ast.d.ts +1997 -151
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +2113 -1263
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/generated/grammar.d.ts +1 -1
- package/out/language/generated/grammar.d.ts.map +1 -1
- package/out/language/generated/grammar.js +649 -762
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/generated/module.d.ts +1 -1
- package/out/language/generated/module.js +1 -1
- package/out/language/main.cjs +6401 -4072
- package/out/language/main.cjs.map +4 -4
- package/out/language/parser.js +8 -8
- package/out/language/parser.js.map +1 -1
- package/out/runtime/agents/common.d.ts +7 -1
- package/out/runtime/agents/common.d.ts.map +1 -1
- package/out/runtime/agents/common.js +101 -0
- package/out/runtime/agents/common.js.map +1 -1
- package/out/runtime/agents/impl/anthropic.js +4 -4
- package/out/runtime/agents/impl/anthropic.js.map +1 -1
- package/out/runtime/agents/impl/openai.js +4 -4
- package/out/runtime/agents/impl/openai.js.map +1 -1
- package/out/runtime/auth/defs.d.ts +1 -1
- package/out/runtime/auth/defs.js +1 -1
- package/out/runtime/defs.d.ts +1 -1
- package/out/runtime/defs.js +1 -1
- package/out/runtime/exec-graph.d.ts.map +1 -1
- package/out/runtime/exec-graph.js +5 -0
- package/out/runtime/exec-graph.js.map +1 -1
- package/out/runtime/interpreter.d.ts +4 -0
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +20 -4
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/loader.d.ts.map +1 -1
- package/out/runtime/loader.js +43 -6
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/module.d.ts +18 -3
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +62 -4
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.d.ts +18 -2
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +271 -21
- package/out/runtime/modules/ai.js.map +1 -1
- package/out/runtime/modules/auth.d.ts.map +1 -1
- package/out/runtime/modules/auth.js +11 -5
- package/out/runtime/modules/auth.js.map +1 -1
- package/out/runtime/resolvers/interface.d.ts +1 -1
- package/out/runtime/resolvers/interface.d.ts.map +1 -1
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/sqldb/database.d.ts +1 -0
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/database.js +19 -10
- package/out/runtime/resolvers/sqldb/database.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.d.ts +1 -1
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +2 -2
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/state.d.ts +37 -367
- package/out/runtime/state.d.ts.map +1 -1
- package/out/runtime/state.js +3 -0
- package/out/runtime/state.js.map +1 -1
- package/out/setupClassic.d.ts +98 -0
- package/out/setupClassic.d.ts.map +1 -0
- package/out/setupClassic.js +38 -0
- package/out/setupClassic.js.map +1 -0
- package/out/setupCommon.d.ts +2 -0
- package/out/setupCommon.d.ts.map +1 -0
- package/out/setupCommon.js +33 -0
- package/out/setupCommon.js.map +1 -0
- package/out/setupExtended.d.ts +40 -0
- package/out/setupExtended.d.ts.map +1 -0
- package/out/setupExtended.js +67 -0
- package/out/setupExtended.js.map +1 -0
- package/out/syntaxes/agentlang.monarch.js +4 -4
- package/out/syntaxes/agentlang.monarch.js.map +1 -1
- package/out/utils/runtime.d.ts +7 -6
- package/out/utils/runtime.d.ts.map +1 -1
- package/package.json +185 -187
- package/src/api/http.ts +8 -2
- package/src/language/agentlang.langium +8 -2
- package/src/language/generated/ast.ts +2204 -1322
- package/src/language/generated/grammar.ts +649 -762
- package/src/language/generated/module.ts +1 -1
- package/src/language/parser.ts +8 -8
- package/src/runtime/agents/common.ts +107 -0
- package/src/runtime/agents/impl/anthropic.ts +4 -4
- package/src/runtime/agents/impl/openai.ts +4 -4
- package/src/runtime/auth/defs.ts +1 -1
- package/src/runtime/defs.ts +1 -1
- package/src/runtime/exec-graph.ts +4 -0
- package/src/runtime/interpreter.ts +23 -4
- package/src/runtime/loader.ts +43 -4
- package/src/runtime/module.ts +80 -3
- package/src/runtime/modules/ai.ts +391 -19
- package/src/runtime/modules/auth.ts +11 -5
- package/src/runtime/resolvers/interface.ts +1 -1
- package/src/runtime/resolvers/sqldb/database.ts +20 -11
- package/src/runtime/resolvers/sqldb/impl.ts +3 -3
- package/src/runtime/state.ts +4 -0
- 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: '
|
|
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
|
-
|
|
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 - ${
|
|
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
|
-
|
|
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
|
|
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?:
|
|
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.
|
|
562
|
-
limit = options.
|
|
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
|
}
|
package/src/runtime/state.ts
CHANGED
|
@@ -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: /(
|
|
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: /
|
|
16
|
-
{ regex:
|
|
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":""} }} },
|