agentlang 0.3.5 → 0.3.7
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 +82 -29
- package/out/api/http.js +2 -2
- package/out/api/http.js.map +1 -1
- package/out/extension/main.cjs +250 -250
- package/out/extension/main.cjs.map +2 -2
- package/out/language/generated/ast.js +0 -1
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/main.cjs +502 -502
- package/out/language/main.cjs.map +3 -3
- package/out/language/syntax.js +8 -8
- package/out/language/syntax.js.map +1 -1
- package/out/runtime/auth/cognito.js +2 -2
- package/out/runtime/auth/cognito.js.map +1 -1
- package/out/runtime/exec-graph.d.ts.map +1 -1
- package/out/runtime/exec-graph.js +6 -5
- package/out/runtime/exec-graph.js.map +1 -1
- package/out/runtime/interpreter.js +49 -49
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/jsmodules.js +6 -6
- package/out/runtime/jsmodules.js.map +1 -1
- package/out/runtime/loader.js +6 -6
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +72 -66
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.js +5 -5
- 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 +21 -18
- package/out/runtime/modules/auth.js.map +1 -1
- package/out/runtime/modules/core.js +1 -1
- package/out/runtime/modules/core.js.map +1 -1
- package/out/runtime/openapi.js +2 -2
- package/out/runtime/openapi.js.map +1 -1
- package/out/runtime/relgraph.js +1 -1
- package/out/runtime/relgraph.js.map +1 -1
- package/out/runtime/resolvers/authinfo.js +2 -2
- package/out/runtime/resolvers/authinfo.js.map +1 -1
- package/out/runtime/resolvers/interface.js +1 -1
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/registry.js +1 -1
- package/out/runtime/resolvers/registry.js.map +1 -1
- package/out/runtime/resolvers/sqldb/database.js +11 -11
- package/out/runtime/resolvers/sqldb/database.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +4 -4
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/util.js +5 -5
- package/out/runtime/util.js.map +1 -1
- package/out/utils/runtime.d.ts.map +1 -1
- package/out/utils/runtime.js +4 -2
- package/out/utils/runtime.js.map +1 -1
- package/package.json +184 -182
- package/src/api/http.ts +2 -2
- package/src/language/generated/ast.ts +1 -1
- package/src/language/syntax.ts +8 -8
- package/src/runtime/auth/cognito.ts +107 -2
- package/src/runtime/auth/interface.ts +1 -0
- package/src/runtime/exec-graph.ts +6 -5
- package/src/runtime/interpreter.ts +49 -49
- package/src/runtime/jsmodules.ts +6 -6
- package/src/runtime/loader.ts +6 -6
- package/src/runtime/module.ts +71 -66
- package/src/runtime/modules/ai.ts +5 -5
- package/src/runtime/modules/auth.ts +54 -20
- package/src/runtime/modules/core.ts +1 -1
- package/src/runtime/openapi.ts +2 -2
- package/src/runtime/relgraph.ts +1 -1
- package/src/runtime/resolvers/authinfo.ts +2 -2
- package/src/runtime/resolvers/interface.ts +1 -1
- package/src/runtime/resolvers/registry.ts +1 -1
- package/src/runtime/resolvers/sqldb/database.ts +11 -11
- package/src/runtime/resolvers/sqldb/impl.ts +4 -4
- package/src/runtime/util.ts +5 -5
- package/src/utils/runtime.ts +3 -3
package/src/runtime/module.ts
CHANGED
|
@@ -232,7 +232,7 @@ function normalizeMetaValue(metaValue: any): any {
|
|
|
232
232
|
return v.array.vals.map((value: Statement) => {
|
|
233
233
|
return normalizeMetaValue(value.pattern.expr);
|
|
234
234
|
});
|
|
235
|
-
} else if (v.bool
|
|
235
|
+
} else if (v.bool !== undefined) {
|
|
236
236
|
return v.bool == 'true' ? true : false;
|
|
237
237
|
} else if (v.id) {
|
|
238
238
|
return v.id;
|
|
@@ -305,7 +305,7 @@ export class Record extends ModuleEntry {
|
|
|
305
305
|
? cloneParentSchema(parentEntryName, moduleName)
|
|
306
306
|
: newRecordSchema();
|
|
307
307
|
const attributes: AttributeDefinition[] | undefined = scm ? scm.attributes : undefined;
|
|
308
|
-
if (attributes
|
|
308
|
+
if (attributes !== undefined) {
|
|
309
309
|
attributes.forEach((a: AttributeDefinition) => {
|
|
310
310
|
verifyAttribute(a);
|
|
311
311
|
let props: Map<string, any> | undefined = asPropertiesMap(a.properties);
|
|
@@ -318,7 +318,7 @@ export class Record extends ModuleEntry {
|
|
|
318
318
|
rp.setModuleName(this.moduleName);
|
|
319
319
|
fp = rp.asFqName();
|
|
320
320
|
}
|
|
321
|
-
if (props
|
|
321
|
+
if (props === undefined) {
|
|
322
322
|
props = new Map();
|
|
323
323
|
}
|
|
324
324
|
props.set('ref', escapeFqName(fp));
|
|
@@ -334,14 +334,14 @@ export class Record extends ModuleEntry {
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
if (a.expr) {
|
|
337
|
-
if (props
|
|
337
|
+
if (props === undefined) {
|
|
338
338
|
props = new Map();
|
|
339
339
|
}
|
|
340
340
|
props.set('expr', a.expr).set('optional', true);
|
|
341
341
|
}
|
|
342
342
|
const isObjectType: boolean = t == 'Map' || !isBuiltInType(t);
|
|
343
343
|
if (isArrayType || isObjectType || enumValues || oneOfRef) {
|
|
344
|
-
if (props
|
|
344
|
+
if (props === undefined) {
|
|
345
345
|
props = new Map<string, any>();
|
|
346
346
|
}
|
|
347
347
|
if (isArrayType) props.set('array', true);
|
|
@@ -369,14 +369,14 @@ export class Record extends ModuleEntry {
|
|
|
369
369
|
if (prepostTrigs) {
|
|
370
370
|
prepostTrigs.forEach((ppt: PrePostTriggerDefinition) => {
|
|
371
371
|
if (ppt.after) {
|
|
372
|
-
if (this.afterTriggers
|
|
372
|
+
if (this.afterTriggers === undefined) {
|
|
373
373
|
this.afterTriggers = new Map();
|
|
374
374
|
}
|
|
375
375
|
ppt.after.triggers.entries.forEach((te: TriggerEntry) => {
|
|
376
376
|
if (this.afterTriggers) this.afterTriggers.set(asCrudType(te.on), asTriggerInfo(te));
|
|
377
377
|
});
|
|
378
378
|
} else if (ppt.before) {
|
|
379
|
-
if (this.beforeTriggers
|
|
379
|
+
if (this.beforeTriggers === undefined) {
|
|
380
380
|
this.beforeTriggers = new Map();
|
|
381
381
|
}
|
|
382
382
|
ppt.before.triggers.entries.forEach((te: TriggerEntry) => {
|
|
@@ -389,7 +389,7 @@ export class Record extends ModuleEntry {
|
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
private addOneOfRefAttribute(s: string): Record {
|
|
392
|
-
if (this.oneOfRefAttributes
|
|
392
|
+
if (this.oneOfRefAttributes === undefined) {
|
|
393
393
|
this.oneOfRefAttributes = [];
|
|
394
394
|
}
|
|
395
395
|
this.oneOfRefAttributes.push(s);
|
|
@@ -397,7 +397,7 @@ export class Record extends ModuleEntry {
|
|
|
397
397
|
}
|
|
398
398
|
|
|
399
399
|
public addAfterTrigger(te: any): Record {
|
|
400
|
-
if (this.afterTriggers
|
|
400
|
+
if (this.afterTriggers === undefined) {
|
|
401
401
|
this.afterTriggers = new Map();
|
|
402
402
|
}
|
|
403
403
|
this.afterTriggers?.set(asCrudType(te.on), asTriggerInfo(te));
|
|
@@ -405,7 +405,7 @@ export class Record extends ModuleEntry {
|
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
public addBeforeTrigger(te: any): Record {
|
|
408
|
-
if (this.beforeTriggers
|
|
408
|
+
if (this.beforeTriggers === undefined) {
|
|
409
409
|
this.beforeTriggers = new Map();
|
|
410
410
|
}
|
|
411
411
|
this.beforeTriggers?.set(asCrudType(te.on), asTriggerInfo(te));
|
|
@@ -464,7 +464,7 @@ export class Record extends ModuleEntry {
|
|
|
464
464
|
if (this.schema.has(n)) {
|
|
465
465
|
throw new Error(`Attribute named ${n} already exists in ${this.moduleName}.${this.name}`);
|
|
466
466
|
}
|
|
467
|
-
if (attrSpec.properties
|
|
467
|
+
if (attrSpec.properties !== undefined) {
|
|
468
468
|
normalizePropertyNames(attrSpec.properties);
|
|
469
469
|
}
|
|
470
470
|
this.schema.set(n, attrSpec);
|
|
@@ -493,7 +493,7 @@ export class Record extends ModuleEntry {
|
|
|
493
493
|
findAttribute(predic: Function): AttributeEntry | undefined {
|
|
494
494
|
for (const k of this.schema.keys()) {
|
|
495
495
|
const attrSpec: AttributeSpec | undefined = this.schema.get(k);
|
|
496
|
-
if (attrSpec
|
|
496
|
+
if (attrSpec !== undefined) {
|
|
497
497
|
if (predic(attrSpec))
|
|
498
498
|
return {
|
|
499
499
|
name: k,
|
|
@@ -507,9 +507,9 @@ export class Record extends ModuleEntry {
|
|
|
507
507
|
hasRefTo(modName: string, entryName: string): boolean {
|
|
508
508
|
if (
|
|
509
509
|
this.findAttribute((attrSpec: AttributeSpec) => {
|
|
510
|
-
if (attrSpec.properties
|
|
510
|
+
if (attrSpec.properties !== undefined) {
|
|
511
511
|
const ref: Path | undefined = attrSpec.properties.get('ref');
|
|
512
|
-
if (ref
|
|
512
|
+
if (ref !== undefined) {
|
|
513
513
|
if (ref.getModuleName() == modName && ref.getEntryName() == entryName) {
|
|
514
514
|
return true;
|
|
515
515
|
}
|
|
@@ -526,7 +526,7 @@ export class Record extends ModuleEntry {
|
|
|
526
526
|
const e: AttributeEntry | undefined = this.findAttribute((attrSpec: AttributeSpec) => {
|
|
527
527
|
return isIdAttribute(attrSpec);
|
|
528
528
|
});
|
|
529
|
-
if (e
|
|
529
|
+
if (e !== undefined) {
|
|
530
530
|
return e.name;
|
|
531
531
|
}
|
|
532
532
|
return undefined;
|
|
@@ -629,14 +629,14 @@ function cloneParentSchema(parentName: string, currentModuleName: string): Recor
|
|
|
629
629
|
}
|
|
630
630
|
|
|
631
631
|
function asPropertiesMap(props: PropertyDefinition[]): Map<string, any> | undefined {
|
|
632
|
-
if (props
|
|
632
|
+
if (props !== undefined && props.length > 0) {
|
|
633
633
|
const result: Map<string, any> = new Map<string, any>();
|
|
634
634
|
props.forEach((p: PropertyDefinition) => {
|
|
635
635
|
const n: string = p.name.substring(1);
|
|
636
|
-
if (p.value
|
|
636
|
+
if (p.value !== undefined && p.value.pairs !== undefined && p.value.pairs.length > 0) {
|
|
637
637
|
if (p.value.pairs.length == 1) {
|
|
638
638
|
const kvp: KvPair = p.value.pairs[0];
|
|
639
|
-
if (kvp.key
|
|
639
|
+
if (kvp.key === undefined) {
|
|
640
640
|
result.set(n, normalizeKvPairValue(kvp));
|
|
641
641
|
} else {
|
|
642
642
|
const v: Map<string, any> = new Map<string, any>();
|
|
@@ -647,7 +647,7 @@ function asPropertiesMap(props: PropertyDefinition[]): Map<string, any> | undefi
|
|
|
647
647
|
const v: Map<string, any> = new Map<string, any>();
|
|
648
648
|
p.value.pairs.forEach((kvp: KvPair) => {
|
|
649
649
|
let k: string = 'null';
|
|
650
|
-
if (kvp.key
|
|
650
|
+
if (kvp.key !== undefined) k = kvp.key;
|
|
651
651
|
v.set(k, normalizeKvPairValue(kvp));
|
|
652
652
|
});
|
|
653
653
|
result.set(n, v);
|
|
@@ -663,7 +663,7 @@ function asPropertiesMap(props: PropertyDefinition[]): Map<string, any> | undefi
|
|
|
663
663
|
|
|
664
664
|
function maybeProcessRefProperty(props: Map<string, any>): Map<string, any> {
|
|
665
665
|
const v: string | undefined = props.get('ref');
|
|
666
|
-
if (v
|
|
666
|
+
if (v !== undefined) {
|
|
667
667
|
const parts: Path = nameToPath(v);
|
|
668
668
|
if (!parts.hasModule()) {
|
|
669
669
|
parts.setModuleName(activeModule);
|
|
@@ -675,24 +675,24 @@ function maybeProcessRefProperty(props: Map<string, any>): Map<string, any> {
|
|
|
675
675
|
|
|
676
676
|
function normalizeKvPairValue(kvp: KvPair): any | null {
|
|
677
677
|
const v: Literal | undefined = kvp.value;
|
|
678
|
-
if (v
|
|
679
|
-
if (v.str
|
|
678
|
+
if (v === undefined) return true;
|
|
679
|
+
if (v.str !== undefined) {
|
|
680
680
|
return v.str;
|
|
681
|
-
} else if (v.num
|
|
681
|
+
} else if (v.num !== undefined) {
|
|
682
682
|
return v.num;
|
|
683
|
-
} else if (v.bool
|
|
684
|
-
return v.bool
|
|
685
|
-
} else if (v.id
|
|
683
|
+
} else if (v.bool !== undefined) {
|
|
684
|
+
return v.bool === 'true' ? true : false;
|
|
685
|
+
} else if (v.id !== undefined) {
|
|
686
686
|
return v.id;
|
|
687
|
-
} else if (v.ref
|
|
687
|
+
} else if (v.ref !== undefined) {
|
|
688
688
|
return v.ref;
|
|
689
|
-
} else if (v.fnCall
|
|
689
|
+
} else if (v.fnCall !== undefined) {
|
|
690
690
|
const fncall: FnCall = v.fnCall;
|
|
691
691
|
if (fncall.args.length > 0) {
|
|
692
692
|
throw new Error('Cannot allow arguments in properties function-call');
|
|
693
693
|
}
|
|
694
694
|
return fncall.name + '()';
|
|
695
|
-
} else if (v.array
|
|
695
|
+
} else if (v.array !== undefined) {
|
|
696
696
|
return v.array;
|
|
697
697
|
}
|
|
698
698
|
return null;
|
|
@@ -755,7 +755,7 @@ export class RbacSpecification {
|
|
|
755
755
|
perms.forEach((v: string) => {
|
|
756
756
|
const idx: any = v.toUpperCase();
|
|
757
757
|
const a: any = RbacPermissionFlag[idx];
|
|
758
|
-
if (a
|
|
758
|
+
if (a === undefined) {
|
|
759
759
|
throw new Error(`Not a valid RBAC permission - ${v}`);
|
|
760
760
|
}
|
|
761
761
|
ps.add(a);
|
|
@@ -1140,7 +1140,7 @@ function asRelNodeEntry(n: NodeDefinition): RelationshipNode {
|
|
|
1140
1140
|
modName = path.getModuleName();
|
|
1141
1141
|
}
|
|
1142
1142
|
let alias = entryName;
|
|
1143
|
-
if (n.alias
|
|
1143
|
+
if (n.alias !== undefined) {
|
|
1144
1144
|
alias = n.alias;
|
|
1145
1145
|
}
|
|
1146
1146
|
return {
|
|
@@ -1227,14 +1227,14 @@ export class Relationship extends Record {
|
|
|
1227
1227
|
}
|
|
1228
1228
|
|
|
1229
1229
|
hasBooleanFlagSet(flag: string): boolean {
|
|
1230
|
-
if (this.properties
|
|
1230
|
+
if (this.properties !== undefined) {
|
|
1231
1231
|
return this.properties.get(flag) == true;
|
|
1232
1232
|
}
|
|
1233
1233
|
return false;
|
|
1234
1234
|
}
|
|
1235
1235
|
|
|
1236
1236
|
private setProperty(p: string, v: any): Relationship {
|
|
1237
|
-
if (this.properties
|
|
1237
|
+
if (this.properties === undefined) {
|
|
1238
1238
|
this.properties = new Map();
|
|
1239
1239
|
}
|
|
1240
1240
|
this.properties.set(p, v);
|
|
@@ -1661,7 +1661,7 @@ export function flowGraphNext(
|
|
|
1661
1661
|
const c = node.on?.findIndex((v: string) => {
|
|
1662
1662
|
return v == onCondition;
|
|
1663
1663
|
});
|
|
1664
|
-
if (c
|
|
1664
|
+
if (c !== undefined) {
|
|
1665
1665
|
const next = node.next[c];
|
|
1666
1666
|
const r = graph.find((n: FlowGraphNode) => {
|
|
1667
1667
|
return n.label == next;
|
|
@@ -2075,7 +2075,7 @@ export class Module {
|
|
|
2075
2075
|
const r: Record = v as Record;
|
|
2076
2076
|
return r.name == name;
|
|
2077
2077
|
});
|
|
2078
|
-
return entry
|
|
2078
|
+
return entry !== undefined;
|
|
2079
2079
|
}
|
|
2080
2080
|
|
|
2081
2081
|
isEntity(name: string): boolean {
|
|
@@ -2200,7 +2200,7 @@ export function isModule(name: string): boolean {
|
|
|
2200
2200
|
|
|
2201
2201
|
export function fetchModule(moduleName: string): Module {
|
|
2202
2202
|
const module: Module | undefined = moduleDb.get(moduleName);
|
|
2203
|
-
if (module
|
|
2203
|
+
if (module === undefined) {
|
|
2204
2204
|
throw new Error(`Module not found - ${moduleName}`);
|
|
2205
2205
|
}
|
|
2206
2206
|
return module;
|
|
@@ -2289,14 +2289,14 @@ export function isValidType(type: string): boolean {
|
|
|
2289
2289
|
}
|
|
2290
2290
|
|
|
2291
2291
|
function checkType(type: string | undefined): void {
|
|
2292
|
-
if (type
|
|
2292
|
+
if (type === undefined) throw new Error('Attribute type is required');
|
|
2293
2293
|
if (!isValidType(type)) {
|
|
2294
2294
|
console.log(chalk.red(`WARN: type not found - ${type}`));
|
|
2295
2295
|
}
|
|
2296
2296
|
}
|
|
2297
2297
|
|
|
2298
2298
|
function validateProperties(props: PropertyDefinition[] | undefined): void {
|
|
2299
|
-
if (props
|
|
2299
|
+
if (props !== undefined) {
|
|
2300
2300
|
props.forEach((p: PropertyDefinition) => {
|
|
2301
2301
|
if (!propertyNames.has(p.name)) throw new Error(`Invalid property ${p.name}`);
|
|
2302
2302
|
});
|
|
@@ -2313,9 +2313,9 @@ export function defaultAttributes(schema: RecordSchema): Map<string, any> {
|
|
|
2313
2313
|
const result: Map<string, any> = new Map<string, any>();
|
|
2314
2314
|
schema.forEach((v: AttributeSpec, k: string) => {
|
|
2315
2315
|
const props: Map<string, any> | undefined = v.properties;
|
|
2316
|
-
if (props
|
|
2316
|
+
if (props !== undefined) {
|
|
2317
2317
|
const d: any | undefined = props.get('default');
|
|
2318
|
-
if (d
|
|
2318
|
+
if (d !== undefined) {
|
|
2319
2319
|
result.set(k, d);
|
|
2320
2320
|
}
|
|
2321
2321
|
}
|
|
@@ -2327,7 +2327,7 @@ export function passwordAttributes(schema: RecordSchema): Set<string> | undefine
|
|
|
2327
2327
|
let result: Set<string> | undefined = undefined;
|
|
2328
2328
|
schema.forEach((v: AttributeSpec, k: string) => {
|
|
2329
2329
|
if (v.type == 'Password') {
|
|
2330
|
-
if (result
|
|
2330
|
+
if (result === undefined) {
|
|
2331
2331
|
result = new Set<string>();
|
|
2332
2332
|
}
|
|
2333
2333
|
result?.add(k);
|
|
@@ -2340,7 +2340,7 @@ export function objectAttributes(schema: RecordSchema): Array<string> | undefine
|
|
|
2340
2340
|
let result: Array<string> | undefined;
|
|
2341
2341
|
schema.forEach((v: AttributeSpec, k: string) => {
|
|
2342
2342
|
if (isObjectAttribute(v)) {
|
|
2343
|
-
if (result
|
|
2343
|
+
if (result === undefined) result = new Array<string>();
|
|
2344
2344
|
result.push(k);
|
|
2345
2345
|
}
|
|
2346
2346
|
});
|
|
@@ -2348,21 +2348,21 @@ export function objectAttributes(schema: RecordSchema): Array<string> | undefine
|
|
|
2348
2348
|
}
|
|
2349
2349
|
|
|
2350
2350
|
function getBooleanProperty(propName: string, attrSpec: AttributeSpec): boolean {
|
|
2351
|
-
if (attrSpec.properties
|
|
2351
|
+
if (attrSpec.properties !== undefined) {
|
|
2352
2352
|
return attrSpec.properties.get(propName) == true;
|
|
2353
2353
|
}
|
|
2354
2354
|
return false;
|
|
2355
2355
|
}
|
|
2356
2356
|
|
|
2357
2357
|
function getAnyProperty(propName: string, attrSpec: AttributeSpec): any | undefined {
|
|
2358
|
-
if (attrSpec.properties
|
|
2358
|
+
if (attrSpec.properties !== undefined) {
|
|
2359
2359
|
return attrSpec.properties.get(propName);
|
|
2360
2360
|
}
|
|
2361
2361
|
return undefined;
|
|
2362
2362
|
}
|
|
2363
2363
|
|
|
2364
2364
|
function setAnyProperty(propName: string, value: any, attrSpec: AttributeSpec): AttributeSpec {
|
|
2365
|
-
if (attrSpec.properties
|
|
2365
|
+
if (attrSpec.properties === undefined) {
|
|
2366
2366
|
attrSpec.properties = new Map();
|
|
2367
2367
|
}
|
|
2368
2368
|
attrSpec.properties.set(propName, value);
|
|
@@ -2494,7 +2494,7 @@ export function addRelationship(
|
|
|
2494
2494
|
n2 = nodes[1];
|
|
2495
2495
|
}
|
|
2496
2496
|
let propsMap: Map<string, any> | undefined;
|
|
2497
|
-
if (props
|
|
2497
|
+
if (props !== undefined) propsMap = asPropertiesMap(props);
|
|
2498
2498
|
return module.addEntry(
|
|
2499
2499
|
new Relationship(name, type, n1, n2, moduleName, scm, propsMap)
|
|
2500
2500
|
) as Relationship;
|
|
@@ -2794,7 +2794,7 @@ function filterBetweenRelationshipsForEntity(
|
|
|
2794
2794
|
predic: Function,
|
|
2795
2795
|
allBetweenRels?: Relationship[]
|
|
2796
2796
|
): Relationship[] {
|
|
2797
|
-
if (allBetweenRels
|
|
2797
|
+
if (allBetweenRels === undefined) {
|
|
2798
2798
|
allBetweenRels = getAllBetweenRelationships();
|
|
2799
2799
|
}
|
|
2800
2800
|
const p = new Path(moduleName, entityName);
|
|
@@ -2927,7 +2927,7 @@ export function removeEvent(name: string, moduleName = activeModule): boolean {
|
|
|
2927
2927
|
|
|
2928
2928
|
function getAttributeSpec(attrsSpec: RecordSchema, attrName: string): AttributeSpec {
|
|
2929
2929
|
const spec: AttributeSpec | undefined = attrsSpec.get(attrName);
|
|
2930
|
-
if (spec
|
|
2930
|
+
if (spec === undefined) {
|
|
2931
2931
|
throw new Error(`Failed to find spec for attribute ${attrName}`);
|
|
2932
2932
|
}
|
|
2933
2933
|
return spec;
|
|
@@ -2963,7 +2963,7 @@ function validateType(attrName: string, attrValue: any, attrSpec: AttributeSpec)
|
|
|
2963
2963
|
}
|
|
2964
2964
|
let predic = getCheckPredicate(attrSpec);
|
|
2965
2965
|
predic = predic ? predic : builtInChecks.get(attrSpec.type);
|
|
2966
|
-
if (predic
|
|
2966
|
+
if (predic !== undefined) {
|
|
2967
2967
|
if (isArrayAttribute(attrSpec)) {
|
|
2968
2968
|
if (!(attrValue instanceof Array)) {
|
|
2969
2969
|
throw new Error(`${attrName} expects an array of values`);
|
|
@@ -3061,7 +3061,12 @@ export class Instance {
|
|
|
3061
3061
|
}
|
|
3062
3062
|
|
|
3063
3063
|
lookup(k: string): any {
|
|
3064
|
-
|
|
3064
|
+
const v = this.attributes.get(k);
|
|
3065
|
+
if (v === undefined) {
|
|
3066
|
+
return this.getRelatedInstances(k);
|
|
3067
|
+
} else {
|
|
3068
|
+
return v;
|
|
3069
|
+
}
|
|
3065
3070
|
}
|
|
3066
3071
|
|
|
3067
3072
|
lookupQueryVal(k: string): any {
|
|
@@ -3176,24 +3181,24 @@ export class Instance {
|
|
|
3176
3181
|
}
|
|
3177
3182
|
|
|
3178
3183
|
queryAttributesAsObject(): object {
|
|
3179
|
-
if (this.queryAttributes
|
|
3184
|
+
if (this.queryAttributes !== undefined) {
|
|
3180
3185
|
return Object.fromEntries(this.queryAttributes);
|
|
3181
3186
|
}
|
|
3182
3187
|
return {};
|
|
3183
3188
|
}
|
|
3184
3189
|
|
|
3185
3190
|
queryAttributeValuesAsObject(): object {
|
|
3186
|
-
if (this.queryAttributeValues
|
|
3191
|
+
if (this.queryAttributeValues !== undefined) {
|
|
3187
3192
|
return Object.fromEntries(this.queryAttributeValues);
|
|
3188
3193
|
}
|
|
3189
3194
|
return {};
|
|
3190
3195
|
}
|
|
3191
3196
|
|
|
3192
3197
|
addQuery(attrName: string, op: string = '=', attrVal: any = undefined) {
|
|
3193
|
-
if (this.queryAttributes
|
|
3198
|
+
if (this.queryAttributes === undefined) this.queryAttributes = newInstanceAttributes();
|
|
3194
3199
|
this.queryAttributes.set(attrName, op);
|
|
3195
|
-
if (attrVal
|
|
3196
|
-
if (this.queryAttributeValues
|
|
3200
|
+
if (attrVal !== undefined) {
|
|
3201
|
+
if (this.queryAttributeValues === undefined)
|
|
3197
3202
|
this.queryAttributeValues = newInstanceAttributes();
|
|
3198
3203
|
this.queryAttributeValues.set(attrName, attrVal);
|
|
3199
3204
|
}
|
|
@@ -3207,11 +3212,11 @@ export class Instance {
|
|
|
3207
3212
|
}
|
|
3208
3213
|
|
|
3209
3214
|
attachRelatedInstances(relName: string, insts: Instance | Instance[]) {
|
|
3210
|
-
if (this.relatedInstances
|
|
3215
|
+
if (this.relatedInstances === undefined) {
|
|
3211
3216
|
this.relatedInstances = new Map<string, Array<Instance>>();
|
|
3212
3217
|
}
|
|
3213
3218
|
let relInsts: Array<Instance> | undefined = this.relatedInstances.get(relName);
|
|
3214
|
-
if (relInsts
|
|
3219
|
+
if (relInsts === undefined) {
|
|
3215
3220
|
relInsts = new Array<Instance>();
|
|
3216
3221
|
}
|
|
3217
3222
|
if (insts instanceof Instance) {
|
|
@@ -3226,7 +3231,7 @@ export class Instance {
|
|
|
3226
3231
|
}
|
|
3227
3232
|
|
|
3228
3233
|
detachAllRelatedInstance() {
|
|
3229
|
-
if (this.relatedInstances
|
|
3234
|
+
if (this.relatedInstances !== undefined) {
|
|
3230
3235
|
this.relatedInstances?.clear();
|
|
3231
3236
|
this.relatedInstances = undefined;
|
|
3232
3237
|
this.attributes.delete('->');
|
|
@@ -3234,7 +3239,7 @@ export class Instance {
|
|
|
3234
3239
|
}
|
|
3235
3240
|
|
|
3236
3241
|
mergeRelatedInstances() {
|
|
3237
|
-
if (this.relatedInstances
|
|
3242
|
+
if (this.relatedInstances !== undefined) {
|
|
3238
3243
|
this.relatedInstances.forEach((v: Instance[], k: string) => {
|
|
3239
3244
|
this.attributes.set(k, v);
|
|
3240
3245
|
});
|
|
@@ -3259,7 +3264,7 @@ export class Instance {
|
|
|
3259
3264
|
}
|
|
3260
3265
|
|
|
3261
3266
|
addContextData(k: string, v: any): Instance {
|
|
3262
|
-
if (this.contextData
|
|
3267
|
+
if (this.contextData === undefined) {
|
|
3263
3268
|
this.contextData = new Map();
|
|
3264
3269
|
}
|
|
3265
3270
|
this.contextData.set(k, v);
|
|
@@ -3269,7 +3274,7 @@ export class Instance {
|
|
|
3269
3274
|
getContextData(k: string, notFoundValue?: any): any {
|
|
3270
3275
|
if (this.contextData) {
|
|
3271
3276
|
const v: any = this.contextData.get(k);
|
|
3272
|
-
if (v
|
|
3277
|
+
if (v === undefined) return notFoundValue;
|
|
3273
3278
|
return v;
|
|
3274
3279
|
}
|
|
3275
3280
|
return notFoundValue;
|
|
@@ -3296,7 +3301,7 @@ export class Instance {
|
|
|
3296
3301
|
this.record.schema.forEach((attrSpec: AttributeSpec, n: string) => {
|
|
3297
3302
|
const expr = getAttributeExpr(attrSpec);
|
|
3298
3303
|
if (expr) {
|
|
3299
|
-
if (result
|
|
3304
|
+
if (result === undefined) {
|
|
3300
3305
|
result = new Map<string, Expr>();
|
|
3301
3306
|
}
|
|
3302
3307
|
result.set(n, expr);
|
|
@@ -3373,7 +3378,7 @@ function maybeSetDefaultAttributeValues(
|
|
|
3373
3378
|
const defAttrs = defaultAttributes(schema);
|
|
3374
3379
|
defAttrs.forEach((v: any, k: string) => {
|
|
3375
3380
|
const cv = attributes.get(k);
|
|
3376
|
-
if (cv
|
|
3381
|
+
if (cv === undefined || cv === null) {
|
|
3377
3382
|
if (isString(v)) {
|
|
3378
3383
|
if (v == 'uuid()') {
|
|
3379
3384
|
v = crypto.randomUUID();
|
|
@@ -3421,7 +3426,7 @@ export function makeInstance(
|
|
|
3421
3426
|
throw new Error(`Invalid attribute '${key}' specified for ${moduleName}/${entryName}`);
|
|
3422
3427
|
}
|
|
3423
3428
|
const spec: AttributeSpec = getAttributeSpec(schema, key);
|
|
3424
|
-
if (value
|
|
3429
|
+
if (value !== null && value !== undefined) validateType(key, value, spec);
|
|
3425
3430
|
});
|
|
3426
3431
|
}
|
|
3427
3432
|
if (!queryAttributes && !queryAll) {
|
|
@@ -3557,7 +3562,7 @@ export function isTimer(eventInst: Instance): boolean {
|
|
|
3557
3562
|
|
|
3558
3563
|
export function isAgentEvent(record: Record): boolean {
|
|
3559
3564
|
const flag = record.getMeta(IsAgentEventMeta);
|
|
3560
|
-
return flag
|
|
3565
|
+
return flag !== undefined && flag == 'y';
|
|
3561
3566
|
}
|
|
3562
3567
|
|
|
3563
3568
|
export function isAgentEventInstance(eventInst: Instance): boolean {
|
|
@@ -3583,7 +3588,7 @@ export function getEntityRbacRules(entityFqName: string): RbacSpecification[] |
|
|
|
3583
3588
|
if (m && m.isEntity(en)) {
|
|
3584
3589
|
const entity = getEntity(en, mn);
|
|
3585
3590
|
return entity?.getRbacSpecifications()?.filter((spec: RbacSpecification) => {
|
|
3586
|
-
return spec.expression
|
|
3591
|
+
return spec.expression !== undefined;
|
|
3587
3592
|
});
|
|
3588
3593
|
}
|
|
3589
3594
|
return undefined;
|
|
@@ -270,7 +270,7 @@ export class AgentInstance {
|
|
|
270
270
|
Only return a pure JSON object with no extra text, annotations etc.`;
|
|
271
271
|
}
|
|
272
272
|
const spad = env.getScratchPad();
|
|
273
|
-
if (spad
|
|
273
|
+
if (spad !== undefined) {
|
|
274
274
|
if (finalInstruction.indexOf('{{') > 0) {
|
|
275
275
|
return AgentInstance.maybeRewriteTemplatePatterns(spad, finalInstruction);
|
|
276
276
|
} else {
|
|
@@ -311,7 +311,7 @@ Only return a pure JSON object with no extra text, annotations etc.`;
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
getFqName(): string {
|
|
314
|
-
if (this.fqName
|
|
314
|
+
if (this.fqName === undefined) {
|
|
315
315
|
this.fqName = makeFqName(this.moduleName, this.name);
|
|
316
316
|
}
|
|
317
317
|
return this.fqName;
|
|
@@ -328,7 +328,7 @@ Only return a pure JSON object with no extra text, annotations etc.`;
|
|
|
328
328
|
|
|
329
329
|
maybeAddScratchData(env: Environment): AgentInstance {
|
|
330
330
|
const obj: any = env.getLastResult();
|
|
331
|
-
if (obj === null || obj
|
|
331
|
+
if (obj === null || obj === undefined) return this;
|
|
332
332
|
let r: Instance | Instance[] | undefined = undefined;
|
|
333
333
|
if (
|
|
334
334
|
obj instanceof Instance ||
|
|
@@ -419,7 +419,7 @@ Only return a pure JSON object with no extra text, annotations etc.`;
|
|
|
419
419
|
this.toolsArray.forEach((n: string) => {
|
|
420
420
|
const v = GlobalEnvironment.lookup(n);
|
|
421
421
|
if (v) {
|
|
422
|
-
if (result
|
|
422
|
+
if (result === undefined) {
|
|
423
423
|
result = new Array<any>();
|
|
424
424
|
}
|
|
425
425
|
result.push(v);
|
|
@@ -542,7 +542,7 @@ export async function findProviderForLLM(
|
|
|
542
542
|
env: Environment
|
|
543
543
|
): Promise<AgentServiceProvider> {
|
|
544
544
|
let p: AgentServiceProvider | undefined = ProviderDb.get(llmName);
|
|
545
|
-
if (p
|
|
545
|
+
if (p === undefined) {
|
|
546
546
|
const result: Instance[] = await parseAndEvaluateStatement(
|
|
547
547
|
`{${CoreAIModuleName}/${LlmEntityName} {name? "${llmName}"}}`,
|
|
548
548
|
undefined,
|
|
@@ -340,6 +340,10 @@ entity Session {
|
|
|
340
340
|
@public workflow acceptInvitation {
|
|
341
341
|
await Auth.acceptInvitationUser(acceptInvitation.email, acceptInvitation.tempPassword, acceptInvitation.newPassword)
|
|
342
342
|
}
|
|
343
|
+
|
|
344
|
+
@public workflow callback {
|
|
345
|
+
await Auth.callbackUser(callback.code)
|
|
346
|
+
}
|
|
343
347
|
`;
|
|
344
348
|
|
|
345
349
|
const evalEvent = makeEventEvaluator(CoreAuthModuleName);
|
|
@@ -607,10 +611,10 @@ export async function findUserRoles(userId: string, env: Environment): Promise<R
|
|
|
607
611
|
const inst: Instance | undefined = result ? (result[0] as Instance) : undefined;
|
|
608
612
|
if (inst) {
|
|
609
613
|
let roles: Instance[] | undefined = inst.getRelatedInstances('UserRole');
|
|
610
|
-
if (roles
|
|
614
|
+
if (roles === undefined) {
|
|
611
615
|
roles = [];
|
|
612
616
|
}
|
|
613
|
-
if (DefaultRoleInstance
|
|
617
|
+
if (DefaultRoleInstance === undefined) {
|
|
614
618
|
DefaultRoleInstance = makeInstance(
|
|
615
619
|
CoreAuthModuleName,
|
|
616
620
|
'Role',
|
|
@@ -664,7 +668,7 @@ export async function userHasPermissions(
|
|
|
664
668
|
return true;
|
|
665
669
|
}
|
|
666
670
|
let userRoles: string[] | null | undefined = UserRoleCache.get(userId);
|
|
667
|
-
if (userRoles
|
|
671
|
+
if (!userRoles) {
|
|
668
672
|
const roles: any = await findUserRoles(userId, env);
|
|
669
673
|
userRoles = [];
|
|
670
674
|
if (roles) {
|
|
@@ -680,6 +684,7 @@ export async function userHasPermissions(
|
|
|
680
684
|
UserRoleCache.set(userId, userRoles);
|
|
681
685
|
}
|
|
682
686
|
if (
|
|
687
|
+
userRoles &&
|
|
683
688
|
userRoles.find((role: string) => {
|
|
684
689
|
return role === 'admin';
|
|
685
690
|
})
|
|
@@ -692,21 +697,23 @@ export async function userHasPermissions(
|
|
|
692
697
|
perms.has(RbacPermissionFlag.UPDATE),
|
|
693
698
|
perms.has(RbacPermissionFlag.DELETE),
|
|
694
699
|
];
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
if (
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
700
|
+
if (userRoles !== null) {
|
|
701
|
+
for (let i = 0; i < userRoles.length; ++i) {
|
|
702
|
+
const permInsts: RbacPermission[] | undefined = RolePermissionsCache.get(userRoles[i]);
|
|
703
|
+
if (permInsts) {
|
|
704
|
+
if (
|
|
705
|
+
permInsts.find((p: RbacPermission) => {
|
|
706
|
+
return (
|
|
707
|
+
p.resourceFqName == resourceFqName &&
|
|
708
|
+
(c ? isSqlTrue(p.c) : true) &&
|
|
709
|
+
(r ? isSqlTrue(p.r) : true) &&
|
|
710
|
+
(u ? isSqlTrue(p.u) : true) &&
|
|
711
|
+
(d ? isSqlTrue(p.d) : true)
|
|
712
|
+
);
|
|
713
|
+
})
|
|
714
|
+
)
|
|
715
|
+
return true;
|
|
716
|
+
}
|
|
710
717
|
}
|
|
711
718
|
}
|
|
712
719
|
return false;
|
|
@@ -878,6 +885,32 @@ export async function loginUser(
|
|
|
878
885
|
}
|
|
879
886
|
}
|
|
880
887
|
|
|
888
|
+
export async function callbackUser(code: string, env: Environment): Promise<string | object> {
|
|
889
|
+
let result: string | object = '';
|
|
890
|
+
try {
|
|
891
|
+
await fetchAuthImpl().callback(code, env, (r: SessionInfo) => {
|
|
892
|
+
UserRoleCache.set(r.userId, null);
|
|
893
|
+
if (r.idToken && r.accessToken && r.refreshToken) {
|
|
894
|
+
result = {
|
|
895
|
+
id_token: r.idToken,
|
|
896
|
+
access_token: r.accessToken,
|
|
897
|
+
refresh_token: r.refreshToken,
|
|
898
|
+
token_type: 'Bearer',
|
|
899
|
+
expires_in: 3600,
|
|
900
|
+
userId: r.userId,
|
|
901
|
+
sessionId: r.sessionId,
|
|
902
|
+
};
|
|
903
|
+
} else {
|
|
904
|
+
result = `${r.userId}/${r.sessionId}`;
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
return result;
|
|
908
|
+
} catch (err: any) {
|
|
909
|
+
logger.error(`Callback failed for ${code}: ${err.message}`);
|
|
910
|
+
throw err;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
881
914
|
async function logoutSession(userId: string, sess: Instance, env: Environment): Promise<Result> {
|
|
882
915
|
const sessId = sess.lookup('id');
|
|
883
916
|
const tok = sess.lookup('authToken');
|
|
@@ -1030,7 +1063,7 @@ async function verifySessionToken(token: string, env?: Environment): Promise<Act
|
|
|
1030
1063
|
const f = async () => {
|
|
1031
1064
|
try {
|
|
1032
1065
|
const sess: Instance = await findSession(sessId, env);
|
|
1033
|
-
if (sess
|
|
1066
|
+
if (sess !== undefined) {
|
|
1034
1067
|
await fetchAuthImpl().verifyToken(sess.lookup('authToken'), env);
|
|
1035
1068
|
return { sessionId: sessId, userId: parts[0] };
|
|
1036
1069
|
} else {
|
|
@@ -1194,7 +1227,8 @@ export function requireAuth(moduleName: string, eventName: string): boolean {
|
|
|
1194
1227
|
eventName == 'forgotPassword' ||
|
|
1195
1228
|
eventName == 'confirmForgotPassword' ||
|
|
1196
1229
|
eventName == 'refreshToken' ||
|
|
1197
|
-
eventName == 'acceptInvitation'
|
|
1230
|
+
eventName == 'acceptInvitation' ||
|
|
1231
|
+
eventName == 'callback');
|
|
1198
1232
|
return !f;
|
|
1199
1233
|
} else {
|
|
1200
1234
|
return false;
|
|
@@ -84,7 +84,7 @@ export function setTimerRunning(timerInst: Instance) {
|
|
|
84
84
|
export async function maybeCancelTimer(name: string, timer: NodeJS.Timeout, env: Environment) {
|
|
85
85
|
await parseAndEvaluateStatement(`{agentlang/timer {name? "${name}"}}`, undefined, env).then(
|
|
86
86
|
(result: any) => {
|
|
87
|
-
if (result
|
|
87
|
+
if (result === null || (result instanceof Array && result.length == 0)) {
|
|
88
88
|
clearInterval(timer);
|
|
89
89
|
}
|
|
90
90
|
}
|