agentlang 0.6.2 → 0.6.4
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/cli/main.d.ts.map +1 -1
- package/out/cli/main.js +2 -0
- package/out/cli/main.js.map +1 -1
- package/out/language/generated/grammar.d.ts.map +1 -1
- package/out/language/generated/grammar.js +10 -0
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/main.cjs +10 -0
- package/out/language/main.cjs.map +2 -2
- package/out/runtime/api.d.ts +6 -0
- package/out/runtime/api.d.ts.map +1 -0
- package/out/runtime/api.js +6 -0
- package/out/runtime/api.js.map +1 -0
- package/out/runtime/auth/cognito.d.ts.map +1 -1
- package/out/runtime/auth/cognito.js +2 -2
- package/out/runtime/auth/cognito.js.map +1 -1
- package/out/runtime/interpreter.d.ts +1 -0
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +19 -11
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/loader.d.ts.map +1 -1
- package/out/runtime/loader.js +33 -18
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +15 -7
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/database.js +16 -1
- package/out/runtime/resolvers/sqldb/database.js.map +1 -1
- package/out/runtime/util.d.ts +7 -0
- package/out/runtime/util.d.ts.map +1 -1
- package/out/runtime/util.js +39 -0
- package/out/runtime/util.js.map +1 -1
- package/package.json +2 -2
- package/src/cli/main.ts +2 -0
- package/src/language/agentlang.langium +2 -2
- package/src/language/generated/grammar.ts +10 -0
- package/src/runtime/api.ts +9 -0
- package/src/runtime/auth/cognito.ts +2 -1
- package/src/runtime/interpreter.ts +21 -10
- package/src/runtime/loader.ts +33 -18
- package/src/runtime/module.ts +16 -7
- package/src/runtime/resolvers/sqldb/database.ts +16 -4
- package/src/runtime/util.ts +52 -0
|
@@ -414,15 +414,27 @@ export async function vectorStoreSearch(
|
|
|
414
414
|
return [];
|
|
415
415
|
}
|
|
416
416
|
try {
|
|
417
|
+
let hasGlobalPerms = ctx.isPermitted();
|
|
418
|
+
if (!hasGlobalPerms) {
|
|
419
|
+
const userId = ctx.getUserId();
|
|
420
|
+
const fqName = ctx.resourceFqName;
|
|
421
|
+
const env: Environment = ctx.activeEnv;
|
|
422
|
+
hasGlobalPerms = await canUserRead(userId, fqName, env);
|
|
423
|
+
}
|
|
417
424
|
const vecTableName = tableName + VectorSuffix;
|
|
418
425
|
const qb = getDatasourceForTransaction(ctx.txnId).getRepository(tableName).manager;
|
|
419
426
|
const { default: pgvector } = await import('pgvector');
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
427
|
+
let ownersJoinCond: string = '';
|
|
428
|
+
if (!hasGlobalPerms) {
|
|
429
|
+
const ot = ownersTable(tableName);
|
|
430
|
+
ownersJoinCond = `inner join ${ot} on
|
|
431
|
+
${ot}.path = ${vecTableName}.id and ${ot}.user_id = '${ctx.authInfo.userId}' and ${ot}.r = true`;
|
|
432
|
+
}
|
|
433
|
+
const sql = `select ${vecTableName}.id from ${vecTableName} ${ownersJoinCond} order by embedding <-> $1 LIMIT ${limit}`;
|
|
434
|
+
return await qb.query(sql, [pgvector.toSql(searchVec)]);
|
|
424
435
|
} catch (err: any) {
|
|
425
436
|
logger.error(`Vector store search failed - ${err}`);
|
|
437
|
+
return [];
|
|
426
438
|
}
|
|
427
439
|
}
|
|
428
440
|
|
package/src/runtime/util.ts
CHANGED
|
@@ -585,3 +585,55 @@ export function validateIdFormat(idAttrName: string, idAttrValue: any) {
|
|
|
585
585
|
export function nameContainsSepEscape(n: string): boolean {
|
|
586
586
|
return n.indexOf(IdSepEscape) >= 0;
|
|
587
587
|
}
|
|
588
|
+
|
|
589
|
+
export function generateUrlSafePassword(length: number = 8): string {
|
|
590
|
+
const upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
591
|
+
const lower = 'abcdefghijklmnopqrstuvwxyz';
|
|
592
|
+
const digits = '0123456789';
|
|
593
|
+
const special = '-_.~';
|
|
594
|
+
|
|
595
|
+
const chars = [
|
|
596
|
+
upper[Math.floor(Math.random() * upper.length)],
|
|
597
|
+
lower[Math.floor(Math.random() * lower.length)],
|
|
598
|
+
digits[Math.floor(Math.random() * digits.length)],
|
|
599
|
+
special[Math.floor(Math.random() * special.length)],
|
|
600
|
+
];
|
|
601
|
+
|
|
602
|
+
const all = upper + lower + digits + special;
|
|
603
|
+
for (let i = chars.length; i < length; ++i) {
|
|
604
|
+
chars.push(all[Math.floor(Math.random() * all.length)]);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
for (let i = chars.length - 1; i > 0; i--) {
|
|
608
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
609
|
+
[chars[i], chars[j]] = [chars[j], chars[i]];
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
return chars.join('');
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const JS_PREFIX = '#js';
|
|
616
|
+
|
|
617
|
+
export function preprocessRawConfig(rawConfig: any): any {
|
|
618
|
+
const keys = Object.keys(rawConfig);
|
|
619
|
+
keys.forEach((k: any) => {
|
|
620
|
+
const v = rawConfig[k];
|
|
621
|
+
if (isString(v) && v.startsWith(JS_PREFIX)) {
|
|
622
|
+
const s = v.substring(3).trim();
|
|
623
|
+
rawConfig[k] = eval(s);
|
|
624
|
+
} else if (typeof v == 'object') {
|
|
625
|
+
preprocessRawConfig(v);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
return rawConfig;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// interface for reading secrets from a secret-store
|
|
632
|
+
type ReadSecret = (k: string, configuration?: any) => any;
|
|
633
|
+
declare global {
|
|
634
|
+
function readSecret(k: string, configuration?: any): any;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export function setScecretReader(f: ReadSecret) {
|
|
638
|
+
globalThis.readSecret = f;
|
|
639
|
+
}
|