agentlang 0.3.4 → 0.3.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/README.md +82 -29
- package/out/api/http.js +2 -2
- package/out/api/http.js.map +1 -1
- package/out/language/syntax.js +8 -8
- package/out/language/syntax.js.map +1 -1
- package/out/runtime/auth/cognito.d.ts +2 -0
- package/out/runtime/auth/cognito.d.ts.map +1 -1
- package/out/runtime/auth/cognito.js +86 -2
- package/out/runtime/auth/cognito.js.map +1 -1
- package/out/runtime/auth/interface.d.ts +1 -0
- package/out/runtime/auth/interface.d.ts.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.d.ts.map +1 -1
- package/out/runtime/interpreter.js +52 -71
- 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 +5 -0
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +123 -67
- 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 +1 -0
- package/out/runtime/modules/auth.d.ts.map +1 -1
- package/out/runtime/modules/auth.js +54 -19
- 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 +2 -2
- package/out/utils/runtime.js.map +1 -1
- package/package.json +4 -3
- package/src/api/http.ts +2 -2
- 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 +52 -69
- package/src/runtime/jsmodules.ts +6 -6
- package/src/runtime/loader.ts +6 -6
- package/src/runtime/module.ts +122 -67
- 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 +2 -2
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;
|
|
@@ -1806,6 +1806,13 @@ export class Module {
|
|
|
1806
1806
|
});
|
|
1807
1807
|
}
|
|
1808
1808
|
|
|
1809
|
+
getAllDecisionsForAgent(agentName: string): Decision[] {
|
|
1810
|
+
const n = `${agentName}.`;
|
|
1811
|
+
return this.getAllDecisions().filter((d: Decision) => {
|
|
1812
|
+
return d.name.startsWith(n);
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1809
1816
|
removeDecision(name: string): boolean {
|
|
1810
1817
|
for (let i = 0; i < this.entries.length; ++i) {
|
|
1811
1818
|
const entry = this.entries[i];
|
|
@@ -1839,6 +1846,13 @@ export class Module {
|
|
|
1839
1846
|
});
|
|
1840
1847
|
}
|
|
1841
1848
|
|
|
1849
|
+
getAllScenariosForAgent(agentName: string): Scenario[] {
|
|
1850
|
+
const n = `${agentName}.`;
|
|
1851
|
+
return this.getAllScenarios().filter((s: Scenario) => {
|
|
1852
|
+
return s.name.startsWith(n);
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1842
1856
|
removeScenario(name: string): Module {
|
|
1843
1857
|
for (let i = 0; i < this.entries.length; ++i) {
|
|
1844
1858
|
const entry = this.entries[i];
|
|
@@ -1872,6 +1886,13 @@ export class Module {
|
|
|
1872
1886
|
});
|
|
1873
1887
|
}
|
|
1874
1888
|
|
|
1889
|
+
getAllDirectivesForAgent(agentName: string): Directive[] {
|
|
1890
|
+
const n = `${agentName}.`;
|
|
1891
|
+
return this.getAllDirectives().filter((d: Directive) => {
|
|
1892
|
+
return d.name.startsWith(n);
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1875
1896
|
removeDirective(name: string): Module {
|
|
1876
1897
|
for (let i = 0; i < this.entries.length; ++i) {
|
|
1877
1898
|
const entry = this.entries[i];
|
|
@@ -1905,6 +1926,13 @@ export class Module {
|
|
|
1905
1926
|
});
|
|
1906
1927
|
}
|
|
1907
1928
|
|
|
1929
|
+
getAllGlossaryEntriesForAgent(agentName: string): GlossaryEntry[] {
|
|
1930
|
+
const n = `${agentName}.`;
|
|
1931
|
+
return this.getAllGlossaryEntries().filter((ge: GlossaryEntry) => {
|
|
1932
|
+
return ge.name.startsWith(n);
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1908
1936
|
removeGlossaryEntry(name: string): Module {
|
|
1909
1937
|
for (let i = 0; i < this.entries.length; ++i) {
|
|
1910
1938
|
const entry = this.entries[i];
|
|
@@ -2047,7 +2075,7 @@ export class Module {
|
|
|
2047
2075
|
const r: Record = v as Record;
|
|
2048
2076
|
return r.name == name;
|
|
2049
2077
|
});
|
|
2050
|
-
return entry
|
|
2078
|
+
return entry !== undefined;
|
|
2051
2079
|
}
|
|
2052
2080
|
|
|
2053
2081
|
isEntity(name: string): boolean {
|
|
@@ -2172,7 +2200,7 @@ export function isModule(name: string): boolean {
|
|
|
2172
2200
|
|
|
2173
2201
|
export function fetchModule(moduleName: string): Module {
|
|
2174
2202
|
const module: Module | undefined = moduleDb.get(moduleName);
|
|
2175
|
-
if (module
|
|
2203
|
+
if (module === undefined) {
|
|
2176
2204
|
throw new Error(`Module not found - ${moduleName}`);
|
|
2177
2205
|
}
|
|
2178
2206
|
return module;
|
|
@@ -2261,14 +2289,14 @@ export function isValidType(type: string): boolean {
|
|
|
2261
2289
|
}
|
|
2262
2290
|
|
|
2263
2291
|
function checkType(type: string | undefined): void {
|
|
2264
|
-
if (type
|
|
2292
|
+
if (type === undefined) throw new Error('Attribute type is required');
|
|
2265
2293
|
if (!isValidType(type)) {
|
|
2266
2294
|
console.log(chalk.red(`WARN: type not found - ${type}`));
|
|
2267
2295
|
}
|
|
2268
2296
|
}
|
|
2269
2297
|
|
|
2270
2298
|
function validateProperties(props: PropertyDefinition[] | undefined): void {
|
|
2271
|
-
if (props
|
|
2299
|
+
if (props !== undefined) {
|
|
2272
2300
|
props.forEach((p: PropertyDefinition) => {
|
|
2273
2301
|
if (!propertyNames.has(p.name)) throw new Error(`Invalid property ${p.name}`);
|
|
2274
2302
|
});
|
|
@@ -2285,9 +2313,9 @@ export function defaultAttributes(schema: RecordSchema): Map<string, any> {
|
|
|
2285
2313
|
const result: Map<string, any> = new Map<string, any>();
|
|
2286
2314
|
schema.forEach((v: AttributeSpec, k: string) => {
|
|
2287
2315
|
const props: Map<string, any> | undefined = v.properties;
|
|
2288
|
-
if (props
|
|
2316
|
+
if (props !== undefined) {
|
|
2289
2317
|
const d: any | undefined = props.get('default');
|
|
2290
|
-
if (d
|
|
2318
|
+
if (d !== undefined) {
|
|
2291
2319
|
result.set(k, d);
|
|
2292
2320
|
}
|
|
2293
2321
|
}
|
|
@@ -2299,7 +2327,7 @@ export function passwordAttributes(schema: RecordSchema): Set<string> | undefine
|
|
|
2299
2327
|
let result: Set<string> | undefined = undefined;
|
|
2300
2328
|
schema.forEach((v: AttributeSpec, k: string) => {
|
|
2301
2329
|
if (v.type == 'Password') {
|
|
2302
|
-
if (result
|
|
2330
|
+
if (result === undefined) {
|
|
2303
2331
|
result = new Set<string>();
|
|
2304
2332
|
}
|
|
2305
2333
|
result?.add(k);
|
|
@@ -2312,7 +2340,7 @@ export function objectAttributes(schema: RecordSchema): Array<string> | undefine
|
|
|
2312
2340
|
let result: Array<string> | undefined;
|
|
2313
2341
|
schema.forEach((v: AttributeSpec, k: string) => {
|
|
2314
2342
|
if (isObjectAttribute(v)) {
|
|
2315
|
-
if (result
|
|
2343
|
+
if (result === undefined) result = new Array<string>();
|
|
2316
2344
|
result.push(k);
|
|
2317
2345
|
}
|
|
2318
2346
|
});
|
|
@@ -2320,21 +2348,21 @@ export function objectAttributes(schema: RecordSchema): Array<string> | undefine
|
|
|
2320
2348
|
}
|
|
2321
2349
|
|
|
2322
2350
|
function getBooleanProperty(propName: string, attrSpec: AttributeSpec): boolean {
|
|
2323
|
-
if (attrSpec.properties
|
|
2351
|
+
if (attrSpec.properties !== undefined) {
|
|
2324
2352
|
return attrSpec.properties.get(propName) == true;
|
|
2325
2353
|
}
|
|
2326
2354
|
return false;
|
|
2327
2355
|
}
|
|
2328
2356
|
|
|
2329
2357
|
function getAnyProperty(propName: string, attrSpec: AttributeSpec): any | undefined {
|
|
2330
|
-
if (attrSpec.properties
|
|
2358
|
+
if (attrSpec.properties !== undefined) {
|
|
2331
2359
|
return attrSpec.properties.get(propName);
|
|
2332
2360
|
}
|
|
2333
2361
|
return undefined;
|
|
2334
2362
|
}
|
|
2335
2363
|
|
|
2336
2364
|
function setAnyProperty(propName: string, value: any, attrSpec: AttributeSpec): AttributeSpec {
|
|
2337
|
-
if (attrSpec.properties
|
|
2365
|
+
if (attrSpec.properties === undefined) {
|
|
2338
2366
|
attrSpec.properties = new Map();
|
|
2339
2367
|
}
|
|
2340
2368
|
attrSpec.properties.set(propName, value);
|
|
@@ -2466,7 +2494,7 @@ export function addRelationship(
|
|
|
2466
2494
|
n2 = nodes[1];
|
|
2467
2495
|
}
|
|
2468
2496
|
let propsMap: Map<string, any> | undefined;
|
|
2469
|
-
if (props
|
|
2497
|
+
if (props !== undefined) propsMap = asPropertiesMap(props);
|
|
2470
2498
|
return module.addEntry(
|
|
2471
2499
|
new Relationship(name, type, n1, n2, moduleName, scm, propsMap)
|
|
2472
2500
|
) as Relationship;
|
|
@@ -2766,7 +2794,7 @@ function filterBetweenRelationshipsForEntity(
|
|
|
2766
2794
|
predic: Function,
|
|
2767
2795
|
allBetweenRels?: Relationship[]
|
|
2768
2796
|
): Relationship[] {
|
|
2769
|
-
if (allBetweenRels
|
|
2797
|
+
if (allBetweenRels === undefined) {
|
|
2770
2798
|
allBetweenRels = getAllBetweenRelationships();
|
|
2771
2799
|
}
|
|
2772
2800
|
const p = new Path(moduleName, entityName);
|
|
@@ -2899,7 +2927,7 @@ export function removeEvent(name: string, moduleName = activeModule): boolean {
|
|
|
2899
2927
|
|
|
2900
2928
|
function getAttributeSpec(attrsSpec: RecordSchema, attrName: string): AttributeSpec {
|
|
2901
2929
|
const spec: AttributeSpec | undefined = attrsSpec.get(attrName);
|
|
2902
|
-
if (spec
|
|
2930
|
+
if (spec === undefined) {
|
|
2903
2931
|
throw new Error(`Failed to find spec for attribute ${attrName}`);
|
|
2904
2932
|
}
|
|
2905
2933
|
return spec;
|
|
@@ -2935,7 +2963,7 @@ function validateType(attrName: string, attrValue: any, attrSpec: AttributeSpec)
|
|
|
2935
2963
|
}
|
|
2936
2964
|
let predic = getCheckPredicate(attrSpec);
|
|
2937
2965
|
predic = predic ? predic : builtInChecks.get(attrSpec.type);
|
|
2938
|
-
if (predic
|
|
2966
|
+
if (predic !== undefined) {
|
|
2939
2967
|
if (isArrayAttribute(attrSpec)) {
|
|
2940
2968
|
if (!(attrValue instanceof Array)) {
|
|
2941
2969
|
throw new Error(`${attrName} expects an array of values`);
|
|
@@ -3033,7 +3061,12 @@ export class Instance {
|
|
|
3033
3061
|
}
|
|
3034
3062
|
|
|
3035
3063
|
lookup(k: string): any {
|
|
3036
|
-
|
|
3064
|
+
const v = this.attributes.get(k);
|
|
3065
|
+
if (v === undefined) {
|
|
3066
|
+
return this.getRelatedInstances(k);
|
|
3067
|
+
} else {
|
|
3068
|
+
return v;
|
|
3069
|
+
}
|
|
3037
3070
|
}
|
|
3038
3071
|
|
|
3039
3072
|
lookupQueryVal(k: string): any {
|
|
@@ -3059,7 +3092,7 @@ export class Instance {
|
|
|
3059
3092
|
const relsObj: any = {};
|
|
3060
3093
|
this.relatedInstances.forEach((insts: Instance[], relName: string) => {
|
|
3061
3094
|
relsObj[relName] = insts.map((inst: Instance) => {
|
|
3062
|
-
return inst
|
|
3095
|
+
return maybeInstanceAsString(inst);
|
|
3063
3096
|
});
|
|
3064
3097
|
});
|
|
3065
3098
|
obj.relatedInstances = relsObj;
|
|
@@ -3148,24 +3181,24 @@ export class Instance {
|
|
|
3148
3181
|
}
|
|
3149
3182
|
|
|
3150
3183
|
queryAttributesAsObject(): object {
|
|
3151
|
-
if (this.queryAttributes
|
|
3184
|
+
if (this.queryAttributes !== undefined) {
|
|
3152
3185
|
return Object.fromEntries(this.queryAttributes);
|
|
3153
3186
|
}
|
|
3154
3187
|
return {};
|
|
3155
3188
|
}
|
|
3156
3189
|
|
|
3157
3190
|
queryAttributeValuesAsObject(): object {
|
|
3158
|
-
if (this.queryAttributeValues
|
|
3191
|
+
if (this.queryAttributeValues !== undefined) {
|
|
3159
3192
|
return Object.fromEntries(this.queryAttributeValues);
|
|
3160
3193
|
}
|
|
3161
3194
|
return {};
|
|
3162
3195
|
}
|
|
3163
3196
|
|
|
3164
3197
|
addQuery(attrName: string, op: string = '=', attrVal: any = undefined) {
|
|
3165
|
-
if (this.queryAttributes
|
|
3198
|
+
if (this.queryAttributes === undefined) this.queryAttributes = newInstanceAttributes();
|
|
3166
3199
|
this.queryAttributes.set(attrName, op);
|
|
3167
|
-
if (attrVal
|
|
3168
|
-
if (this.queryAttributeValues
|
|
3200
|
+
if (attrVal !== undefined) {
|
|
3201
|
+
if (this.queryAttributeValues === undefined)
|
|
3169
3202
|
this.queryAttributeValues = newInstanceAttributes();
|
|
3170
3203
|
this.queryAttributeValues.set(attrName, attrVal);
|
|
3171
3204
|
}
|
|
@@ -3179,11 +3212,11 @@ export class Instance {
|
|
|
3179
3212
|
}
|
|
3180
3213
|
|
|
3181
3214
|
attachRelatedInstances(relName: string, insts: Instance | Instance[]) {
|
|
3182
|
-
if (this.relatedInstances
|
|
3215
|
+
if (this.relatedInstances === undefined) {
|
|
3183
3216
|
this.relatedInstances = new Map<string, Array<Instance>>();
|
|
3184
3217
|
}
|
|
3185
3218
|
let relInsts: Array<Instance> | undefined = this.relatedInstances.get(relName);
|
|
3186
|
-
if (relInsts
|
|
3219
|
+
if (relInsts === undefined) {
|
|
3187
3220
|
relInsts = new Array<Instance>();
|
|
3188
3221
|
}
|
|
3189
3222
|
if (insts instanceof Instance) {
|
|
@@ -3198,7 +3231,7 @@ export class Instance {
|
|
|
3198
3231
|
}
|
|
3199
3232
|
|
|
3200
3233
|
detachAllRelatedInstance() {
|
|
3201
|
-
if (this.relatedInstances
|
|
3234
|
+
if (this.relatedInstances !== undefined) {
|
|
3202
3235
|
this.relatedInstances?.clear();
|
|
3203
3236
|
this.relatedInstances = undefined;
|
|
3204
3237
|
this.attributes.delete('->');
|
|
@@ -3206,7 +3239,7 @@ export class Instance {
|
|
|
3206
3239
|
}
|
|
3207
3240
|
|
|
3208
3241
|
mergeRelatedInstances() {
|
|
3209
|
-
if (this.relatedInstances
|
|
3242
|
+
if (this.relatedInstances !== undefined) {
|
|
3210
3243
|
this.relatedInstances.forEach((v: Instance[], k: string) => {
|
|
3211
3244
|
this.attributes.set(k, v);
|
|
3212
3245
|
});
|
|
@@ -3231,7 +3264,7 @@ export class Instance {
|
|
|
3231
3264
|
}
|
|
3232
3265
|
|
|
3233
3266
|
addContextData(k: string, v: any): Instance {
|
|
3234
|
-
if (this.contextData
|
|
3267
|
+
if (this.contextData === undefined) {
|
|
3235
3268
|
this.contextData = new Map();
|
|
3236
3269
|
}
|
|
3237
3270
|
this.contextData.set(k, v);
|
|
@@ -3241,7 +3274,7 @@ export class Instance {
|
|
|
3241
3274
|
getContextData(k: string, notFoundValue?: any): any {
|
|
3242
3275
|
if (this.contextData) {
|
|
3243
3276
|
const v: any = this.contextData.get(k);
|
|
3244
|
-
if (v
|
|
3277
|
+
if (v === undefined) return notFoundValue;
|
|
3245
3278
|
return v;
|
|
3246
3279
|
}
|
|
3247
3280
|
return notFoundValue;
|
|
@@ -3268,7 +3301,7 @@ export class Instance {
|
|
|
3268
3301
|
this.record.schema.forEach((attrSpec: AttributeSpec, n: string) => {
|
|
3269
3302
|
const expr = getAttributeExpr(attrSpec);
|
|
3270
3303
|
if (expr) {
|
|
3271
|
-
if (result
|
|
3304
|
+
if (result === undefined) {
|
|
3272
3305
|
result = new Map<string, Expr>();
|
|
3273
3306
|
}
|
|
3274
3307
|
result.set(n, expr);
|
|
@@ -3286,6 +3319,28 @@ export class Instance {
|
|
|
3286
3319
|
}
|
|
3287
3320
|
}
|
|
3288
3321
|
|
|
3322
|
+
export function maybeInstanceAsString(result: any): string {
|
|
3323
|
+
if (!isString(result)) {
|
|
3324
|
+
try {
|
|
3325
|
+
if (result instanceof Instance) {
|
|
3326
|
+
const inst = result as Instance;
|
|
3327
|
+
return JSON.stringify(inst.asSerializableObject());
|
|
3328
|
+
} else if (result instanceof Array) {
|
|
3329
|
+
return `[${(result as Array<any>)
|
|
3330
|
+
.map((r: any) => {
|
|
3331
|
+
return maybeInstanceAsString(r);
|
|
3332
|
+
})
|
|
3333
|
+
.join(',')}]`;
|
|
3334
|
+
} else {
|
|
3335
|
+
return JSON.stringify(result);
|
|
3336
|
+
}
|
|
3337
|
+
} catch (reason: any) {
|
|
3338
|
+
logger.error(`Failed to serialize object to string - ${reason}`);
|
|
3339
|
+
return `${result}`;
|
|
3340
|
+
}
|
|
3341
|
+
} else return result;
|
|
3342
|
+
}
|
|
3343
|
+
|
|
3289
3344
|
export function objectAsInstanceAttributes(obj: object | undefined): InstanceAttributes {
|
|
3290
3345
|
const attrs: InstanceAttributes = newInstanceAttributes();
|
|
3291
3346
|
if (obj) {
|
|
@@ -3323,7 +3378,7 @@ function maybeSetDefaultAttributeValues(
|
|
|
3323
3378
|
const defAttrs = defaultAttributes(schema);
|
|
3324
3379
|
defAttrs.forEach((v: any, k: string) => {
|
|
3325
3380
|
const cv = attributes.get(k);
|
|
3326
|
-
if (cv
|
|
3381
|
+
if (cv === undefined || cv === null) {
|
|
3327
3382
|
if (isString(v)) {
|
|
3328
3383
|
if (v == 'uuid()') {
|
|
3329
3384
|
v = crypto.randomUUID();
|
|
@@ -3371,7 +3426,7 @@ export function makeInstance(
|
|
|
3371
3426
|
throw new Error(`Invalid attribute '${key}' specified for ${moduleName}/${entryName}`);
|
|
3372
3427
|
}
|
|
3373
3428
|
const spec: AttributeSpec = getAttributeSpec(schema, key);
|
|
3374
|
-
if (value
|
|
3429
|
+
if (value !== null && value !== undefined) validateType(key, value, spec);
|
|
3375
3430
|
});
|
|
3376
3431
|
}
|
|
3377
3432
|
if (!queryAttributes && !queryAll) {
|
|
@@ -3507,7 +3562,7 @@ export function isTimer(eventInst: Instance): boolean {
|
|
|
3507
3562
|
|
|
3508
3563
|
export function isAgentEvent(record: Record): boolean {
|
|
3509
3564
|
const flag = record.getMeta(IsAgentEventMeta);
|
|
3510
|
-
return flag
|
|
3565
|
+
return flag !== undefined && flag == 'y';
|
|
3511
3566
|
}
|
|
3512
3567
|
|
|
3513
3568
|
export function isAgentEventInstance(eventInst: Instance): boolean {
|
|
@@ -3533,7 +3588,7 @@ export function getEntityRbacRules(entityFqName: string): RbacSpecification[] |
|
|
|
3533
3588
|
if (m && m.isEntity(en)) {
|
|
3534
3589
|
const entity = getEntity(en, mn);
|
|
3535
3590
|
return entity?.getRbacSpecifications()?.filter((spec: RbacSpecification) => {
|
|
3536
|
-
return spec.expression
|
|
3591
|
+
return spec.expression !== undefined;
|
|
3537
3592
|
});
|
|
3538
3593
|
}
|
|
3539
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,
|