agentlang 0.0.3 → 0.0.5
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/README.md +16 -47
- package/out/api/http.d.ts.map +1 -1
- package/out/api/http.js +39 -19
- package/out/api/http.js.map +1 -1
- package/out/cli/main.d.ts +1 -3
- package/out/cli/main.d.ts.map +1 -1
- package/out/cli/main.js +6 -12
- package/out/cli/main.js.map +1 -1
- package/out/language/generated/ast.d.ts +98 -19
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +144 -26
- 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 +1000 -305
- 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 +1097 -312
- package/out/language/main.cjs.map +2 -2
- package/out/language/parser.js +13 -6
- package/out/language/parser.js.map +1 -1
- package/out/runtime/agents/common.d.ts +1 -1
- package/out/runtime/agents/common.d.ts.map +1 -1
- package/out/runtime/agents/common.js +1 -1
- package/out/runtime/auth/cognito.d.ts +4 -1
- package/out/runtime/auth/cognito.d.ts.map +1 -1
- package/out/runtime/auth/cognito.js +540 -73
- package/out/runtime/auth/cognito.js.map +1 -1
- package/out/runtime/auth/defs.d.ts +3 -0
- package/out/runtime/auth/defs.d.ts.map +1 -1
- package/out/runtime/auth/defs.js +17 -1
- package/out/runtime/auth/defs.js.map +1 -1
- package/out/runtime/auth/interface.d.ts +6 -1
- package/out/runtime/auth/interface.d.ts.map +1 -1
- package/out/runtime/defs.d.ts +21 -0
- package/out/runtime/defs.d.ts.map +1 -1
- package/out/runtime/defs.js +35 -0
- package/out/runtime/defs.js.map +1 -1
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +45 -36
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/loader.d.ts +4 -2
- package/out/runtime/loader.d.ts.map +1 -1
- package/out/runtime/loader.js +164 -29
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/module.d.ts +49 -5
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +214 -9
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.d.ts +7 -5
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +50 -24
- package/out/runtime/modules/ai.js.map +1 -1
- package/out/runtime/modules/auth.d.ts +17 -1
- package/out/runtime/modules/auth.d.ts.map +1 -1
- package/out/runtime/modules/auth.js +295 -32
- package/out/runtime/modules/auth.js.map +1 -1
- package/out/runtime/modules/core.d.ts.map +1 -1
- package/out/runtime/modules/core.js +3 -1
- package/out/runtime/modules/core.js.map +1 -1
- package/out/runtime/relgraph.d.ts.map +1 -1
- package/out/runtime/relgraph.js +2 -2
- package/out/runtime/relgraph.js.map +1 -1
- package/out/runtime/resolvers/interface.d.ts +37 -2
- package/out/runtime/resolvers/interface.d.ts.map +1 -1
- package/out/runtime/resolvers/interface.js +103 -5
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/registry.d.ts +3 -2
- package/out/runtime/resolvers/registry.d.ts.map +1 -1
- package/out/runtime/resolvers/registry.js +3 -0
- package/out/runtime/resolvers/registry.js.map +1 -1
- package/out/runtime/resolvers/sqldb/database.d.ts +4 -2
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/database.js +43 -4
- package/out/runtime/resolvers/sqldb/database.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +7 -3
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/state.d.ts +31 -3
- package/out/runtime/state.d.ts.map +1 -1
- package/out/runtime/state.js +11 -1
- package/out/runtime/state.js.map +1 -1
- package/out/runtime/util.d.ts +5 -0
- package/out/runtime/util.d.ts.map +1 -1
- package/out/runtime/util.js +27 -0
- package/out/runtime/util.js.map +1 -1
- package/out/syntaxes/agentlang.monarch.js +2 -2
- package/out/syntaxes/agentlang.monarch.js.map +1 -1
- package/out/utils/http.d.ts +2 -0
- package/out/utils/http.d.ts.map +1 -0
- package/out/utils/http.js +5 -0
- package/out/utils/http.js.map +1 -0
- package/package.json +8 -6
- package/src/api/http.ts +41 -17
- package/src/cli/main.ts +6 -12
- package/src/language/agentlang.langium +35 -10
- package/src/language/generated/ast.ts +257 -45
- package/src/language/generated/grammar.ts +1000 -305
- package/src/language/generated/module.ts +1 -1
- package/src/language/parser.ts +12 -8
- package/src/runtime/agents/common.ts +1 -1
- package/src/runtime/auth/cognito.ts +605 -74
- package/src/runtime/auth/defs.ts +17 -1
- package/src/runtime/auth/interface.ts +6 -1
- package/src/runtime/defs.ts +45 -0
- package/src/runtime/interpreter.ts +43 -34
- package/src/runtime/loader.ts +172 -30
- package/src/runtime/module.ts +257 -10
- package/src/runtime/modules/ai.ts +52 -28
- package/src/runtime/modules/auth.ts +343 -40
- package/src/runtime/modules/core.ts +3 -1
- package/src/runtime/relgraph.ts +2 -8
- package/src/runtime/resolvers/interface.ts +141 -6
- package/src/runtime/resolvers/registry.ts +5 -2
- package/src/runtime/resolvers/sqldb/database.ts +55 -4
- package/src/runtime/resolvers/sqldb/impl.ts +8 -7
- package/src/runtime/state.ts +11 -1
- package/src/runtime/util.ts +29 -0
- package/src/syntaxes/agentlang.monarch.ts +2 -2
- package/src/utils/http.ts +5 -0
- package/src/index.ts +0 -29
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { evaluate } from '../interpreter.js';
|
|
2
|
+
import { logger } from '../logger.js';
|
|
3
|
+
import {
|
|
4
|
+
Instance,
|
|
5
|
+
InstanceAttributes,
|
|
6
|
+
makeInstance,
|
|
7
|
+
newInstanceAttributes,
|
|
8
|
+
Relationship,
|
|
9
|
+
} from '../module.js';
|
|
10
|
+
import { splitFqName } from '../util.js';
|
|
2
11
|
|
|
3
12
|
export class ResolverAuthInfo {
|
|
4
13
|
userId: string;
|
|
@@ -24,6 +33,16 @@ export type JoinInfo = {
|
|
|
24
33
|
subJoins: JoinInfo[] | undefined;
|
|
25
34
|
};
|
|
26
35
|
|
|
36
|
+
const subscriptionEvents: Map<string, string> = new Map<string, string>();
|
|
37
|
+
|
|
38
|
+
export function setSubscriptionEvent(fqEventName: string, resolverName: string) {
|
|
39
|
+
subscriptionEvents.set(resolverName, fqEventName);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getSubscriptionEvent(resolverName: string): string | undefined {
|
|
43
|
+
return subscriptionEvents.get(resolverName);
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
export class Resolver {
|
|
28
47
|
protected authInfo: ResolverAuthInfo = DefaultAuthInfo;
|
|
29
48
|
protected userData: any;
|
|
@@ -31,6 +50,10 @@ export class Resolver {
|
|
|
31
50
|
|
|
32
51
|
static Default = new Resolver();
|
|
33
52
|
|
|
53
|
+
constructor(name?: string) {
|
|
54
|
+
if (name) this.name = name;
|
|
55
|
+
}
|
|
56
|
+
|
|
34
57
|
public setAuthInfo(authInfo: ResolverAuthInfo): Resolver {
|
|
35
58
|
this.authInfo = authInfo;
|
|
36
59
|
return this;
|
|
@@ -49,8 +72,8 @@ export class Resolver {
|
|
|
49
72
|
return this.name;
|
|
50
73
|
}
|
|
51
74
|
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
protected notImpl(method: string) {
|
|
76
|
+
logger.warn(`Method ${method} not implemented in resolver ${this.name}`);
|
|
54
77
|
}
|
|
55
78
|
|
|
56
79
|
public onSetPath(moduleName: string, entryName: string): any {
|
|
@@ -147,14 +170,126 @@ export class Resolver {
|
|
|
147
170
|
|
|
148
171
|
// Return a transactionId
|
|
149
172
|
public async startTransaction(): Promise<any> {
|
|
150
|
-
|
|
173
|
+
this.notImpl('startTransaction()');
|
|
174
|
+
return 1;
|
|
151
175
|
}
|
|
152
176
|
|
|
153
177
|
public async commitTransaction(txnId: string): Promise<any> {
|
|
154
178
|
return this.notImpl(`commitTransaction(${txnId})`);
|
|
155
179
|
}
|
|
156
180
|
|
|
157
|
-
public async rollbackTransaction(
|
|
158
|
-
return this.notImpl(`rollbackTransaction(${
|
|
181
|
+
public async rollbackTransaction(txnId: string): Promise<any> {
|
|
182
|
+
return this.notImpl(`rollbackTransaction(${txnId})`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
public async subscribe(): Promise<any> {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
public async onSubscription(result: any): Promise<any> {
|
|
190
|
+
if (result != undefined) {
|
|
191
|
+
const eventName = getSubscriptionEvent(this.name);
|
|
192
|
+
if (eventName) {
|
|
193
|
+
const path = splitFqName(eventName);
|
|
194
|
+
const inst = makeInstance(
|
|
195
|
+
path.getModuleName(),
|
|
196
|
+
path.getEntryName(),
|
|
197
|
+
newInstanceAttributes().set('data', result)
|
|
198
|
+
);
|
|
199
|
+
return await evaluate(inst);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
type MaybeFunction = Function | undefined;
|
|
206
|
+
|
|
207
|
+
export type GenericResolverMethods = {
|
|
208
|
+
create: MaybeFunction;
|
|
209
|
+
upsert: MaybeFunction;
|
|
210
|
+
update: MaybeFunction;
|
|
211
|
+
query: MaybeFunction;
|
|
212
|
+
delete: MaybeFunction;
|
|
213
|
+
startTransaction: MaybeFunction;
|
|
214
|
+
commitTransaction: MaybeFunction;
|
|
215
|
+
rollbackTransaction: MaybeFunction;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export type GenericResolverSubscription = {
|
|
219
|
+
subscribe: MaybeFunction;
|
|
220
|
+
onSubscriptionEvent: string;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export class GenericResolver extends Resolver {
|
|
224
|
+
implementation: GenericResolverMethods | undefined;
|
|
225
|
+
subs: GenericResolverSubscription | undefined;
|
|
226
|
+
|
|
227
|
+
constructor(name: string, implementation?: GenericResolverMethods) {
|
|
228
|
+
super(name);
|
|
229
|
+
this.implementation = implementation;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public override async createInstance(inst: Instance): Promise<any> {
|
|
233
|
+
if (this.implementation?.create) {
|
|
234
|
+
return await this.implementation.create(this, inst);
|
|
235
|
+
} else {
|
|
236
|
+
return await super.createInstance(inst);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public override async upsertInstance(inst: Instance): Promise<any> {
|
|
241
|
+
if (this.implementation?.upsert) {
|
|
242
|
+
return await this.implementation.upsert(this, inst);
|
|
243
|
+
}
|
|
244
|
+
return await super.upsertInstance(inst);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public override async updateInstance(inst: Instance, newAttrs: InstanceAttributes): Promise<any> {
|
|
248
|
+
if (this.implementation?.update) {
|
|
249
|
+
return await this.implementation.update(this, inst, newAttrs);
|
|
250
|
+
}
|
|
251
|
+
return await super.updateInstance(inst, newAttrs);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public override async queryInstances(inst: Instance, queryAll: boolean): Promise<any> {
|
|
255
|
+
if (this.implementation?.query) {
|
|
256
|
+
return await this.implementation.query(this, inst, queryAll);
|
|
257
|
+
}
|
|
258
|
+
return await super.queryInstances(inst, queryAll);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public override async deleteInstance(inst: Instance | Instance[], purge: boolean): Promise<any> {
|
|
262
|
+
if (this.implementation?.delete) {
|
|
263
|
+
return await this.implementation.delete(this, inst, purge);
|
|
264
|
+
}
|
|
265
|
+
return await super.deleteInstance(inst, purge);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public override async startTransaction(): Promise<any> {
|
|
269
|
+
if (this.implementation?.startTransaction) {
|
|
270
|
+
return await this.implementation.startTransaction(this);
|
|
271
|
+
}
|
|
272
|
+
return await super.startTransaction();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
public override async commitTransaction(txnId: string): Promise<any> {
|
|
276
|
+
if (this.implementation?.commitTransaction) {
|
|
277
|
+
return await this.implementation.commitTransaction(this, txnId);
|
|
278
|
+
}
|
|
279
|
+
return await super.commitTransaction(txnId);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public override async rollbackTransaction(txnId: string): Promise<any> {
|
|
283
|
+
if (this.implementation?.rollbackTransaction) {
|
|
284
|
+
return await this.implementation.rollbackTransaction(this, txnId);
|
|
285
|
+
}
|
|
286
|
+
return await super.rollbackTransaction(txnId);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
override async subscribe() {
|
|
290
|
+
if (this.subs?.subscribe) {
|
|
291
|
+
await this.subs.subscribe(this);
|
|
292
|
+
}
|
|
293
|
+
await super.subscribe();
|
|
159
294
|
}
|
|
160
295
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Resolver } from './interface.js';
|
|
1
|
+
import { Resolver, setSubscriptionEvent } from './interface.js';
|
|
2
2
|
|
|
3
3
|
type MakeResolver = () => Resolver;
|
|
4
4
|
const resolverDb: Map<string, MakeResolver> = new Map<string, MakeResolver>();
|
|
5
5
|
const resolverPathMappings: Map<string, string> = new Map<string, string>();
|
|
6
6
|
|
|
7
|
-
export function registerResolver(name: string, r: MakeResolver) {
|
|
7
|
+
export function registerResolver(name: string, r: MakeResolver): string {
|
|
8
8
|
resolverDb.set(name, r);
|
|
9
|
+
return name;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export function setResolver(fqEntryName: string, resolverName: string) {
|
|
@@ -16,6 +17,8 @@ export function setResolver(fqEntryName: string, resolverName: string) {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
export const setSubscription = setSubscriptionEvent;
|
|
21
|
+
|
|
19
22
|
export function getResolverNameForPath(fqEntryName: string): string | undefined {
|
|
20
23
|
return resolverPathMappings.get(fqEntryName);
|
|
21
24
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
InstanceAttributes,
|
|
15
15
|
newInstanceAttributes,
|
|
16
16
|
RbacPermissionFlag,
|
|
17
|
+
RbacSpecification,
|
|
17
18
|
Relationship,
|
|
18
19
|
} from '../../module.js';
|
|
19
20
|
import pgvector from 'pgvector';
|
|
@@ -29,13 +30,15 @@ export class DbContext {
|
|
|
29
30
|
resourceFqName: string;
|
|
30
31
|
activeEnv: Environment;
|
|
31
32
|
private needAuthCheckFlag: boolean = true;
|
|
33
|
+
rbacRules: RbacSpecification[] | undefined;
|
|
32
34
|
|
|
33
35
|
constructor(
|
|
34
36
|
resourceFqName: string,
|
|
35
37
|
authInfo: ResolverAuthInfo,
|
|
36
38
|
activeEnv: Environment,
|
|
37
39
|
txnId?: string,
|
|
38
|
-
inKernelMode?: boolean
|
|
40
|
+
inKernelMode?: boolean,
|
|
41
|
+
rbacRules?: RbacSpecification[]
|
|
39
42
|
) {
|
|
40
43
|
this.resourceFqName = resourceFqName;
|
|
41
44
|
this.authInfo = authInfo;
|
|
@@ -44,6 +47,7 @@ export class DbContext {
|
|
|
44
47
|
if (inKernelMode != undefined) {
|
|
45
48
|
this.inKernelMode = inKernelMode;
|
|
46
49
|
}
|
|
50
|
+
this.rbacRules = rbacRules;
|
|
47
51
|
}
|
|
48
52
|
private static GlobalDbContext: DbContext | undefined;
|
|
49
53
|
|
|
@@ -93,6 +97,12 @@ export class DbContext {
|
|
|
93
97
|
return this;
|
|
94
98
|
}
|
|
95
99
|
|
|
100
|
+
switchAuthCheck(flag: boolean): boolean {
|
|
101
|
+
const old = this.needAuthCheckFlag;
|
|
102
|
+
this.needAuthCheckFlag = flag;
|
|
103
|
+
return old;
|
|
104
|
+
}
|
|
105
|
+
|
|
96
106
|
isPermitted(): boolean {
|
|
97
107
|
return this.inKernelMode || !this.needAuthCheckFlag;
|
|
98
108
|
}
|
|
@@ -379,8 +389,29 @@ export async function insertRows(
|
|
|
379
389
|
}
|
|
380
390
|
if (hasPerm) {
|
|
381
391
|
await insertRowsHelper(tableName, rows, ctx, doUpsert);
|
|
382
|
-
if (!
|
|
383
|
-
|
|
392
|
+
if (!doUpsert) {
|
|
393
|
+
if (!ctx.isInKernelMode()) {
|
|
394
|
+
await createOwnership(tableName, rows, ctx);
|
|
395
|
+
}
|
|
396
|
+
if (ctx.rbacRules) {
|
|
397
|
+
for (let i = 0; i < ctx.rbacRules.length; ++i) {
|
|
398
|
+
const rbacRule = ctx.rbacRules[i];
|
|
399
|
+
const e = rbacRule.expression;
|
|
400
|
+
if (e) {
|
|
401
|
+
const [selfRef, userRef] = e.lhs.startsWith('this.') ? [e.lhs, e.rhs] : [e.rhs, e.lhs];
|
|
402
|
+
if (userRef == 'auth.user') {
|
|
403
|
+
const attr = selfRef.split('.')[1];
|
|
404
|
+
for (let j = 0; j < rows.length; ++j) {
|
|
405
|
+
const r: any = rows[j];
|
|
406
|
+
const userId = r[attr];
|
|
407
|
+
if (userId) {
|
|
408
|
+
await createLimitedOwnership(tableName, [r], userId, rbacRule.permissions, ctx);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
384
415
|
}
|
|
385
416
|
} else {
|
|
386
417
|
throw new UnauthorisedError({ opr: 'insert', entity: tableName });
|
|
@@ -430,13 +461,33 @@ export async function insertBetweenRow(
|
|
|
430
461
|
|
|
431
462
|
const PathKey = PathAttributeName as keyof object;
|
|
432
463
|
|
|
464
|
+
const AllPerms = new Set<RbacPermissionFlag>()
|
|
465
|
+
.add(RbacPermissionFlag.CREATE)
|
|
466
|
+
.add(RbacPermissionFlag.READ)
|
|
467
|
+
.add(RbacPermissionFlag.UPDATE)
|
|
468
|
+
.add(RbacPermissionFlag.DELETE);
|
|
469
|
+
|
|
433
470
|
async function createOwnership(tableName: string, rows: object[], ctx: DbContext): Promise<void> {
|
|
471
|
+
await createLimitedOwnership(tableName, rows, ctx.authInfo.userId, AllPerms, ctx);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
async function createLimitedOwnership(
|
|
475
|
+
tableName: string,
|
|
476
|
+
rows: object[],
|
|
477
|
+
userId: string,
|
|
478
|
+
perms: Set<RbacPermissionFlag>,
|
|
479
|
+
ctx: DbContext
|
|
480
|
+
): Promise<void> {
|
|
434
481
|
const ownerRows: object[] = [];
|
|
435
482
|
rows.forEach((r: object) => {
|
|
436
483
|
ownerRows.push({
|
|
437
484
|
id: crypto.randomUUID(),
|
|
438
485
|
path: r[PathKey],
|
|
439
|
-
user_id:
|
|
486
|
+
user_id: userId,
|
|
487
|
+
c: perms.has(RbacPermissionFlag.CREATE),
|
|
488
|
+
r: perms.has(RbacPermissionFlag.READ),
|
|
489
|
+
d: perms.has(RbacPermissionFlag.DELETE),
|
|
490
|
+
u: perms.has(RbacPermissionFlag.UPDATE),
|
|
440
491
|
});
|
|
441
492
|
});
|
|
442
493
|
const tname = ownersTable(tableName);
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
getAllBetweenRelationships,
|
|
7
7
|
getAllOneToOneRelationshipsForEntity,
|
|
8
8
|
getBetweenInstanceNodeValues,
|
|
9
|
+
getEntityRbacRules,
|
|
9
10
|
Instance,
|
|
10
11
|
InstanceAttributes,
|
|
11
12
|
isBetweenRelationship,
|
|
@@ -72,7 +73,8 @@ export class SqlDbResolver extends Resolver {
|
|
|
72
73
|
this.authInfo,
|
|
73
74
|
activeEnv,
|
|
74
75
|
this.txnId,
|
|
75
|
-
activeEnv.isInKernelMode()
|
|
76
|
+
activeEnv.isInKernelMode(),
|
|
77
|
+
getEntityRbacRules(resourceFqName)
|
|
76
78
|
);
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -151,12 +153,11 @@ export class SqlDbResolver extends Resolver {
|
|
|
151
153
|
let result = SqlDbResolver.EmptyResultSet;
|
|
152
154
|
|
|
153
155
|
const tableName = asTableName(inst.moduleName, inst.name);
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
);
|
|
156
|
+
const fqName = inst.getFqName();
|
|
157
|
+
const ctx = this.getDbContext(fqName);
|
|
158
|
+
const qattrs: any = queryAll ? undefined : inst.queryAttributesAsObject();
|
|
159
|
+
const qvals: any = queryAll ? undefined : inst.queryAttributeValuesAsObject();
|
|
160
|
+
const rslt: any = await getMany(tableName, qattrs, qvals, ctx);
|
|
160
161
|
if (rslt instanceof Array) {
|
|
161
162
|
result = new Array<Instance>();
|
|
162
163
|
rslt.forEach((r: object) => {
|
package/src/runtime/state.ts
CHANGED
|
@@ -38,7 +38,17 @@ export const ConfigSchema = z.object({
|
|
|
38
38
|
enabled: z.boolean().default(false),
|
|
39
39
|
})
|
|
40
40
|
.optional(),
|
|
41
|
-
|
|
41
|
+
rbac: z
|
|
42
|
+
.object({
|
|
43
|
+
enabled: z.boolean().default(false),
|
|
44
|
+
roles: z.array(z.string()).optional(),
|
|
45
|
+
})
|
|
46
|
+
.optional(),
|
|
47
|
+
auth: z
|
|
48
|
+
.object({
|
|
49
|
+
enabled: z.boolean().default(false),
|
|
50
|
+
})
|
|
51
|
+
.optional(),
|
|
42
52
|
auditTrail: z
|
|
43
53
|
.object({
|
|
44
54
|
enabled: z.boolean().default(false),
|
package/src/runtime/util.ts
CHANGED
|
@@ -88,6 +88,14 @@ export async function invokeModuleFn(
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
export function getModuleFn(fqFnName: string): Function | undefined {
|
|
92
|
+
const refs: string[] = splitRefs(fqFnName);
|
|
93
|
+
const m = importedModules.get(refs[0]);
|
|
94
|
+
if (m != undefined) {
|
|
95
|
+
return m[refs[1]];
|
|
96
|
+
} else return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
91
99
|
export function isNumber(x: any): boolean {
|
|
92
100
|
return typeof x === 'number';
|
|
93
101
|
}
|
|
@@ -111,6 +119,14 @@ function asString(s: MaybeString): string {
|
|
|
111
119
|
else return s;
|
|
112
120
|
}
|
|
113
121
|
|
|
122
|
+
export function restoreSpecialChars(s: string) {
|
|
123
|
+
return s.replaceAll('"e;', '"');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function escapeSpecialChars(s: string) {
|
|
127
|
+
return s.replaceAll('"', '"e;');
|
|
128
|
+
}
|
|
129
|
+
|
|
114
130
|
export class Path {
|
|
115
131
|
private moduleName: MaybeString;
|
|
116
132
|
private entryName: MaybeString;
|
|
@@ -256,6 +272,7 @@ export function arrayEquals(a: Array<any>, b: Array<any>) {
|
|
|
256
272
|
}
|
|
257
273
|
|
|
258
274
|
export const DefaultModuleName = 'agentlang';
|
|
275
|
+
export const DefaultModules = new Set();
|
|
259
276
|
|
|
260
277
|
export function makeCoreModuleName(n: string): string {
|
|
261
278
|
return DefaultModuleName + '_' + n;
|
|
@@ -511,3 +528,15 @@ export function walkDownInstancePath(path: string): [string, string, string | un
|
|
|
511
528
|
}
|
|
512
529
|
return [moduleName, entryName, undefined, parts];
|
|
513
530
|
}
|
|
531
|
+
|
|
532
|
+
export function areSetsEqual<T>(set1: Set<T>, set2: Set<T>): boolean {
|
|
533
|
+
if (set1.size !== set2.size) {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
for (const item of set1) {
|
|
537
|
+
if (!set2.has(item)) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Monarch syntax highlighting for the agentlang language.
|
|
2
2
|
export default {
|
|
3
3
|
keywords: [
|
|
4
|
-
'@after','@async','@before','@enum','@expr','@meta','@oneof','@rbac','@ref','@with_unique','allow','and','as','await','between','catch','contains','create','delete','else','entity','error','event','extends','false','for','if','import','in','into','like','module','not','not_found','or','purge','read','record','relationship','roles','true','update','upsert','where','workflow'
|
|
4
|
+
'@actions','@after','@async','@before','@enum','@expr','@meta','@oneof','@rbac','@ref','@upsert','@with_unique','agent','allow','and','as','await','between','catch','contains','create','delete','else','entity','error','event','extends','false','for','if','import','in','into','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','roles','subscribe','true','update','upsert','where','workflow'
|
|
5
5
|
],
|
|
6
6
|
operators: [
|
|
7
7
|
'*','+',',','-','.','/',':',';','<','<=','<>','=','>','>=','?','@'
|
|
@@ -12,7 +12,7 @@ export default {
|
|
|
12
12
|
initial: [
|
|
13
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: /([
|
|
15
|
+
{ regex: /("(((\\([\s\S]))|((?!(((\\|")|\r)|\n))[\s\S]*?))|(\r?\n))*")/, action: {"token":"string"} },
|
|
16
16
|
{ regex: /-?[0-9]+/, action: {"token":"number"} },
|
|
17
17
|
{ include: '@whitespace' },
|
|
18
18
|
{ regex: /@symbols/, action: { cases: { '@operators': {"token":"operator"}, '@default': {"token":""} }} },
|
package/src/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// Main exports for the agentlang runtime
|
|
2
|
-
export * from './runtime/defs.js';
|
|
3
|
-
export * from './runtime/module.js';
|
|
4
|
-
export * from './runtime/interpreter.js';
|
|
5
|
-
export * from './runtime/loader.js';
|
|
6
|
-
export * from './runtime/state.js';
|
|
7
|
-
export * from './runtime/util.js';
|
|
8
|
-
export * from './runtime/logger.js';
|
|
9
|
-
|
|
10
|
-
// Export auth interfaces
|
|
11
|
-
export * from './runtime/auth/defs.js';
|
|
12
|
-
export * from './runtime/auth/interface.js';
|
|
13
|
-
|
|
14
|
-
// Export agent interfaces
|
|
15
|
-
export * from './runtime/agents/common.js';
|
|
16
|
-
export * from './runtime/agents/provider.js';
|
|
17
|
-
export * from './runtime/agents/registry.js';
|
|
18
|
-
|
|
19
|
-
// Export resolver interfaces
|
|
20
|
-
export * from './runtime/resolvers/interface.js';
|
|
21
|
-
export * from './runtime/resolvers/registry.js';
|
|
22
|
-
|
|
23
|
-
// Export modules
|
|
24
|
-
export * from './runtime/modules/core.js';
|
|
25
|
-
export * from './runtime/modules/auth.js';
|
|
26
|
-
export * from './runtime/modules/ai.js';
|
|
27
|
-
|
|
28
|
-
// Export CLI utilities
|
|
29
|
-
export * from './cli/cli-util.js';
|