@cadenza.io/core 3.19.5 → 3.20.0
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/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +92 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -342,7 +342,8 @@ type SchemaDefinition = {
|
|
|
342
342
|
description?: string;
|
|
343
343
|
strict?: boolean;
|
|
344
344
|
};
|
|
345
|
-
type
|
|
345
|
+
type SchemaMap = Record<string, SchemaDefinition>;
|
|
346
|
+
type Schema = SchemaDefinition | SchemaMap;
|
|
346
347
|
|
|
347
348
|
interface Intent {
|
|
348
349
|
name: string;
|
|
@@ -934,6 +935,10 @@ declare class Task extends SignalEmitter implements Graph {
|
|
|
934
935
|
* @return {void} This method does not return any value.
|
|
935
936
|
*/
|
|
936
937
|
emitMetricsWithMetadata(signal: string, ctx?: AnyObject): void;
|
|
938
|
+
private isSchemaDefinition;
|
|
939
|
+
private isDefaultAnyObjectSchema;
|
|
940
|
+
private mergeSchemaVariant;
|
|
941
|
+
private validateValueAgainstSchema;
|
|
937
942
|
/**
|
|
938
943
|
* Validates a data object against a specified schema definition and returns validation results.
|
|
939
944
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -342,7 +342,8 @@ type SchemaDefinition = {
|
|
|
342
342
|
description?: string;
|
|
343
343
|
strict?: boolean;
|
|
344
344
|
};
|
|
345
|
-
type
|
|
345
|
+
type SchemaMap = Record<string, SchemaDefinition>;
|
|
346
|
+
type Schema = SchemaDefinition | SchemaMap;
|
|
346
347
|
|
|
347
348
|
interface Intent {
|
|
348
349
|
name: string;
|
|
@@ -934,6 +935,10 @@ declare class Task extends SignalEmitter implements Graph {
|
|
|
934
935
|
* @return {void} This method does not return any value.
|
|
935
936
|
*/
|
|
936
937
|
emitMetricsWithMetadata(signal: string, ctx?: AnyObject): void;
|
|
938
|
+
private isSchemaDefinition;
|
|
939
|
+
private isDefaultAnyObjectSchema;
|
|
940
|
+
private mergeSchemaVariant;
|
|
941
|
+
private validateValueAgainstSchema;
|
|
937
942
|
/**
|
|
938
943
|
* Validates a data object against a specified schema definition and returns validation results.
|
|
939
944
|
*
|
package/dist/index.js
CHANGED
|
@@ -3753,8 +3753,8 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3753
3753
|
isSubMeta: this.isSubMeta,
|
|
3754
3754
|
validateInputContext: this.validateInputContext,
|
|
3755
3755
|
validateOutputContext: this.validateOutputContext,
|
|
3756
|
-
|
|
3757
|
-
|
|
3756
|
+
inputContextSchema: this.inputContextSchema,
|
|
3757
|
+
outputContextSchema: this.outputContextSchema,
|
|
3758
3758
|
signals: {
|
|
3759
3759
|
emits: Array.from(this.emitsSignals),
|
|
3760
3760
|
signalsToEmitAfter: Array.from(this.signalsToEmitAfter),
|
|
@@ -3883,6 +3883,51 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3883
3883
|
}
|
|
3884
3884
|
this.emitMetrics(signal, data);
|
|
3885
3885
|
}
|
|
3886
|
+
isSchemaDefinition(schema) {
|
|
3887
|
+
return !!schema && typeof schema === "object" && "type" in schema;
|
|
3888
|
+
}
|
|
3889
|
+
isDefaultAnyObjectSchema(schema) {
|
|
3890
|
+
return schema.type === "object" && !schema.strict && !schema.properties && !schema.required?.length && !schema.items && !schema.constraints && !schema.description;
|
|
3891
|
+
}
|
|
3892
|
+
mergeSchemaVariant(currentSchema, schemaKey, variant) {
|
|
3893
|
+
const schemaMap = {};
|
|
3894
|
+
if (this.isSchemaDefinition(currentSchema)) {
|
|
3895
|
+
if (!this.isDefaultAnyObjectSchema(currentSchema)) {
|
|
3896
|
+
schemaMap.default = currentSchema;
|
|
3897
|
+
}
|
|
3898
|
+
} else if (currentSchema && typeof currentSchema === "object") {
|
|
3899
|
+
Object.assign(schemaMap, currentSchema);
|
|
3900
|
+
}
|
|
3901
|
+
schemaMap[schemaKey] = variant;
|
|
3902
|
+
return schemaMap;
|
|
3903
|
+
}
|
|
3904
|
+
validateValueAgainstSchema(schema, key, value, path = "context") {
|
|
3905
|
+
if (this.isSchemaDefinition(schema)) {
|
|
3906
|
+
return this.validateProp(schema, key, value, path);
|
|
3907
|
+
}
|
|
3908
|
+
const errors = {};
|
|
3909
|
+
let checkedSchemas = 0;
|
|
3910
|
+
for (const candidate of Object.values(schema)) {
|
|
3911
|
+
if (!candidate || typeof candidate !== "object") {
|
|
3912
|
+
continue;
|
|
3913
|
+
}
|
|
3914
|
+
checkedSchemas += 1;
|
|
3915
|
+
const candidateErrors = this.validateValueAgainstSchema(
|
|
3916
|
+
candidate,
|
|
3917
|
+
key,
|
|
3918
|
+
value,
|
|
3919
|
+
path
|
|
3920
|
+
);
|
|
3921
|
+
if (Object.keys(candidateErrors).length === 0) {
|
|
3922
|
+
return {};
|
|
3923
|
+
}
|
|
3924
|
+
Object.assign(errors, candidateErrors);
|
|
3925
|
+
}
|
|
3926
|
+
if (checkedSchemas === 0) {
|
|
3927
|
+
return {};
|
|
3928
|
+
}
|
|
3929
|
+
return errors;
|
|
3930
|
+
}
|
|
3886
3931
|
/**
|
|
3887
3932
|
* Validates a data object against a specified schema definition and returns validation results.
|
|
3888
3933
|
*
|
|
@@ -3894,10 +3939,16 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3894
3939
|
*/
|
|
3895
3940
|
validateSchema(data, schema, path = "context") {
|
|
3896
3941
|
const errors = {};
|
|
3897
|
-
if (!schema || typeof schema !== "object"
|
|
3942
|
+
if (!schema || typeof schema !== "object") {
|
|
3898
3943
|
return { valid: true, errors };
|
|
3899
|
-
|
|
3900
|
-
|
|
3944
|
+
}
|
|
3945
|
+
if (!this.isSchemaDefinition(schema)) {
|
|
3946
|
+
let checkedSchemas = 0;
|
|
3947
|
+
for (const s of Object.values(schema)) {
|
|
3948
|
+
if (!s || typeof s !== "object") {
|
|
3949
|
+
continue;
|
|
3950
|
+
}
|
|
3951
|
+
checkedSchemas += 1;
|
|
3901
3952
|
const subValidation = this.validateSchema(data, s, path);
|
|
3902
3953
|
if (!subValidation.valid) {
|
|
3903
3954
|
Object.assign(errors, subValidation.errors);
|
|
@@ -3906,6 +3957,13 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3906
3957
|
return { valid: true, errors: {} };
|
|
3907
3958
|
}
|
|
3908
3959
|
}
|
|
3960
|
+
if (checkedSchemas === 0) {
|
|
3961
|
+
return { valid: true, errors };
|
|
3962
|
+
}
|
|
3963
|
+
return { valid: false, errors };
|
|
3964
|
+
}
|
|
3965
|
+
if (schema.type === "object" && (typeof data !== "object" || data === null || Array.isArray(data))) {
|
|
3966
|
+
errors[path] = `Expected 'object' for '${path}', got '${typeof data}'`;
|
|
3909
3967
|
return { valid: false, errors };
|
|
3910
3968
|
}
|
|
3911
3969
|
const required = schema.required || [];
|
|
@@ -3918,21 +3976,10 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3918
3976
|
for (const [key, value] of Object.entries(data)) {
|
|
3919
3977
|
if (key in properties) {
|
|
3920
3978
|
const prop = properties[key];
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
if (Object.keys(pe).length > 0) {
|
|
3926
|
-
Object.assign(propErrors, pe);
|
|
3927
|
-
} else {
|
|
3928
|
-
propErrors = {};
|
|
3929
|
-
break;
|
|
3930
|
-
}
|
|
3931
|
-
}
|
|
3932
|
-
Object.assign(errors, propErrors);
|
|
3933
|
-
} else {
|
|
3934
|
-
Object.assign(errors, this.validateProp(prop, key, value, path));
|
|
3935
|
-
}
|
|
3979
|
+
Object.assign(
|
|
3980
|
+
errors,
|
|
3981
|
+
this.validateValueAgainstSchema(prop, key, value, path)
|
|
3982
|
+
);
|
|
3936
3983
|
} else if (schema.strict) {
|
|
3937
3984
|
errors[`${path}.${key}`] = `Key '${key}' is not allowed`;
|
|
3938
3985
|
}
|
|
@@ -3963,23 +4010,13 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3963
4010
|
errors[`${path}.${key}`] = `Expected 'object' for '${key}', got '${typeof value}'`;
|
|
3964
4011
|
} else if (propType === "array" && prop.items) {
|
|
3965
4012
|
value.forEach((item, index) => {
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
} else {
|
|
3974
|
-
Object.assign(
|
|
3975
|
-
errors,
|
|
3976
|
-
this.validateProp(
|
|
3977
|
-
prop.items,
|
|
3978
|
-
key,
|
|
3979
|
-
item,
|
|
3980
|
-
`${path}.${key}[${index}]`
|
|
3981
|
-
)
|
|
3982
|
-
);
|
|
4013
|
+
const validation = this.validateSchema(
|
|
4014
|
+
item,
|
|
4015
|
+
prop.items,
|
|
4016
|
+
`${path}.${key}[${index}]`
|
|
4017
|
+
);
|
|
4018
|
+
if (!validation.valid) {
|
|
4019
|
+
Object.assign(errors, validation.errors);
|
|
3983
4020
|
}
|
|
3984
4021
|
});
|
|
3985
4022
|
} else if (propType === "object" && !Array.isArray(value) && value !== null) {
|
|
@@ -4462,10 +4499,18 @@ var Task = class _Task extends SignalEmitter {
|
|
|
4462
4499
|
Cadenza.inquiryBroker.observe(intentName, this);
|
|
4463
4500
|
const intent = Cadenza.inquiryBroker.intents.get(intentName);
|
|
4464
4501
|
if (intent?.input) {
|
|
4465
|
-
this.inputContextSchema =
|
|
4502
|
+
this.inputContextSchema = this.mergeSchemaVariant(
|
|
4503
|
+
this.inputContextSchema,
|
|
4504
|
+
intentName,
|
|
4505
|
+
intent.input
|
|
4506
|
+
);
|
|
4466
4507
|
}
|
|
4467
4508
|
if (intent?.output) {
|
|
4468
|
-
this.outputContextSchema =
|
|
4509
|
+
this.outputContextSchema = this.mergeSchemaVariant(
|
|
4510
|
+
this.outputContextSchema,
|
|
4511
|
+
intentName,
|
|
4512
|
+
intent.output
|
|
4513
|
+
);
|
|
4469
4514
|
}
|
|
4470
4515
|
}
|
|
4471
4516
|
return this;
|
|
@@ -5850,12 +5895,14 @@ var InquiryBroker = class _InquiryBroker extends SignalEmitter {
|
|
|
5850
5895
|
tasks: /* @__PURE__ */ new Set(),
|
|
5851
5896
|
registered: false
|
|
5852
5897
|
});
|
|
5853
|
-
this.
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5898
|
+
if (!this.intents.has(inquiry)) {
|
|
5899
|
+
this.addIntent({
|
|
5900
|
+
name: inquiry,
|
|
5901
|
+
description: "",
|
|
5902
|
+
input: { type: "object" },
|
|
5903
|
+
output: { type: "object" }
|
|
5904
|
+
});
|
|
5905
|
+
}
|
|
5859
5906
|
}
|
|
5860
5907
|
}
|
|
5861
5908
|
addIntent(intent) {
|