@cadenza.io/core 3.23.0 → 3.25.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 +56 -3
- package/dist/index.d.ts +56 -3
- package/dist/index.js +328 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +327 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ __export(index_exports, {
|
|
|
29
29
|
GraphRun: () => GraphRun,
|
|
30
30
|
GraphRunner: () => GraphRunner,
|
|
31
31
|
InquiryBroker: () => InquiryBroker,
|
|
32
|
+
META_ACTOR_SESSION_STATE_PERSIST_INTENT: () => META_ACTOR_SESSION_STATE_PERSIST_INTENT,
|
|
32
33
|
SignalBroker: () => SignalBroker,
|
|
33
34
|
SignalEmitter: () => SignalEmitter,
|
|
34
35
|
Task: () => Task,
|
|
@@ -2675,7 +2676,8 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
2675
2676
|
if (!this.divided && !this.processing) {
|
|
2676
2677
|
this.processing = true;
|
|
2677
2678
|
const inputValidation = this.task.validateInput(
|
|
2678
|
-
this.isMeta() ? this.context.
|
|
2679
|
+
this.isMeta() ? this.context.getFullContext() : this.context.getContext(),
|
|
2680
|
+
this.context.getMetadata()
|
|
2679
2681
|
);
|
|
2680
2682
|
if (inputValidation !== true) {
|
|
2681
2683
|
this.onError(inputValidation.__validationErrors);
|
|
@@ -2768,7 +2770,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
2768
2770
|
}
|
|
2769
2771
|
}
|
|
2770
2772
|
inquire(inquiry, context, options) {
|
|
2771
|
-
return Cadenza.
|
|
2773
|
+
return Cadenza.resolveRuntimeInquiryDelegate()(
|
|
2772
2774
|
inquiry,
|
|
2773
2775
|
{ ...context, __executionTraceId: this.executionTraceId },
|
|
2774
2776
|
options
|
|
@@ -3010,7 +3012,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
3010
3012
|
return this.divideAsync(current);
|
|
3011
3013
|
}
|
|
3012
3014
|
while (!current.done && current.value !== void 0) {
|
|
3013
|
-
const outputValidation = this.task.validateOutput(
|
|
3015
|
+
const outputValidation = this.task.validateOutput(
|
|
3016
|
+
current.value,
|
|
3017
|
+
this.context.getMetadata()
|
|
3018
|
+
);
|
|
3014
3019
|
if (outputValidation !== true) {
|
|
3015
3020
|
this.onError(outputValidation.__validationErrors);
|
|
3016
3021
|
break;
|
|
@@ -3022,7 +3027,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
3022
3027
|
} else if (this.result !== void 0 && !this.errored) {
|
|
3023
3028
|
newNodes.push(...this.generateNewNodes(this.result));
|
|
3024
3029
|
if (typeof this.result !== "boolean") {
|
|
3025
|
-
const outputValidation = this.task.validateOutput(
|
|
3030
|
+
const outputValidation = this.task.validateOutput(
|
|
3031
|
+
this.result,
|
|
3032
|
+
this.context.getMetadata()
|
|
3033
|
+
);
|
|
3026
3034
|
if (outputValidation !== true) {
|
|
3027
3035
|
this.onError(outputValidation.__validationErrors);
|
|
3028
3036
|
}
|
|
@@ -3054,7 +3062,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
3054
3062
|
async divideAsync(current) {
|
|
3055
3063
|
const nextNodes = [];
|
|
3056
3064
|
const _current = await current;
|
|
3057
|
-
const outputValidation = this.task.validateOutput(
|
|
3065
|
+
const outputValidation = this.task.validateOutput(
|
|
3066
|
+
_current.value,
|
|
3067
|
+
this.context.getMetadata()
|
|
3068
|
+
);
|
|
3058
3069
|
if (outputValidation !== true) {
|
|
3059
3070
|
this.onError(outputValidation.__validationErrors);
|
|
3060
3071
|
return nextNodes;
|
|
@@ -3062,7 +3073,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
3062
3073
|
nextNodes.push(...this.generateNewNodes(_current.value));
|
|
3063
3074
|
}
|
|
3064
3075
|
for await (const result of this.result) {
|
|
3065
|
-
const outputValidation2 = this.task.validateOutput(
|
|
3076
|
+
const outputValidation2 = this.task.validateOutput(
|
|
3077
|
+
result,
|
|
3078
|
+
this.context.getMetadata()
|
|
3079
|
+
);
|
|
3066
3080
|
if (outputValidation2 !== true) {
|
|
3067
3081
|
this.onError(outputValidation2.__validationErrors);
|
|
3068
3082
|
return [];
|
|
@@ -3509,6 +3523,11 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
3509
3523
|
context.__executionTraceId = executionTraceId;
|
|
3510
3524
|
const routineExecId = context.__routineExecId ?? (0, import_uuid5.v4)();
|
|
3511
3525
|
context.__routineExecId = routineExecId;
|
|
3526
|
+
Cadenza.applyRuntimeValidationScopesToContext(
|
|
3527
|
+
context,
|
|
3528
|
+
routineName,
|
|
3529
|
+
allTasks
|
|
3530
|
+
);
|
|
3512
3531
|
const ctx = new GraphContext(context || {});
|
|
3513
3532
|
if (!isSubMeta) {
|
|
3514
3533
|
if (isNewTrace) {
|
|
@@ -3663,6 +3682,7 @@ var TaskIterator = class {
|
|
|
3663
3682
|
// src/actors/Actor.ts
|
|
3664
3683
|
var ACTOR_TASK_METADATA = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
|
|
3665
3684
|
var ACTOR_INVOCATION_OPTIONS_KEY = "__actorOptions";
|
|
3685
|
+
var META_ACTOR_SESSION_STATE_PERSIST_INTENT = "meta-actor-session-state-persist";
|
|
3666
3686
|
function deepClone(value) {
|
|
3667
3687
|
if (value === void 0 || value === null || typeof value !== "object" || value instanceof Date) {
|
|
3668
3688
|
return value;
|
|
@@ -3921,10 +3941,19 @@ var Actor = class {
|
|
|
3921
3941
|
if (invocationOptions.writeContract === "reducer" && typeof handlerResult === "function") {
|
|
3922
3942
|
reduceDurableState(handlerResult);
|
|
3923
3943
|
}
|
|
3944
|
+
const nextDurableVersion = stateRecord.version + (durableStateChanged ? 1 : 0);
|
|
3945
|
+
if (durableStateChanged) {
|
|
3946
|
+
await this.persistDurableStateIfConfigured(
|
|
3947
|
+
actorKey,
|
|
3948
|
+
nextDurableState,
|
|
3949
|
+
nextDurableVersion,
|
|
3950
|
+
inquire
|
|
3951
|
+
);
|
|
3952
|
+
}
|
|
3924
3953
|
const writeTimestamp = Date.now();
|
|
3925
3954
|
if (durableStateChanged) {
|
|
3926
3955
|
stateRecord.durableState = cloneForDurableState(nextDurableState);
|
|
3927
|
-
stateRecord.version
|
|
3956
|
+
stateRecord.version = nextDurableVersion;
|
|
3928
3957
|
stateRecord.lastDurableWriteAt = writeTimestamp;
|
|
3929
3958
|
}
|
|
3930
3959
|
if (runtimeStateChanged) {
|
|
@@ -4232,6 +4261,34 @@ var Actor = class {
|
|
|
4232
4261
|
}
|
|
4233
4262
|
return record;
|
|
4234
4263
|
}
|
|
4264
|
+
async persistDurableStateIfConfigured(actorKey, durableState, durableVersion, inquire) {
|
|
4265
|
+
const shouldPersist = this.spec.session?.persistDurableState ?? false;
|
|
4266
|
+
if (!shouldPersist) {
|
|
4267
|
+
return;
|
|
4268
|
+
}
|
|
4269
|
+
const timeoutMs = normalizePositiveInteger(this.spec.session?.persistenceTimeoutMs) ?? 5e3;
|
|
4270
|
+
const response = await inquire(
|
|
4271
|
+
META_ACTOR_SESSION_STATE_PERSIST_INTENT,
|
|
4272
|
+
{
|
|
4273
|
+
actor_name: this.spec.name,
|
|
4274
|
+
actor_version: 1,
|
|
4275
|
+
actor_key: actorKey,
|
|
4276
|
+
durable_state: cloneForDurableState(durableState),
|
|
4277
|
+
durable_version: durableVersion,
|
|
4278
|
+
expires_at: null
|
|
4279
|
+
},
|
|
4280
|
+
{
|
|
4281
|
+
timeout: timeoutMs,
|
|
4282
|
+
rejectOnTimeout: true
|
|
4283
|
+
}
|
|
4284
|
+
);
|
|
4285
|
+
if (!isObject2(response) || response.__success !== true || response.persisted !== true) {
|
|
4286
|
+
const reason = isObject2(response) ? response.__error ?? response.error : void 0;
|
|
4287
|
+
throw new Error(
|
|
4288
|
+
`Actor "${this.spec.name}" durable state persistence failed for key "${actorKey}"${reason ? `: ${String(reason)}` : ""}`
|
|
4289
|
+
);
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4235
4292
|
emitActorCreatedSignal() {
|
|
4236
4293
|
Cadenza.signalBroker.registerEmittedSignal("meta.actor.created");
|
|
4237
4294
|
const definition = sanitizeActorMetadataValue(
|
|
@@ -4284,7 +4341,7 @@ var Task = class _Task extends SignalEmitter {
|
|
|
4284
4341
|
* @param {number} [retryDelayMax=0] - The maximum delay (in milliseconds) allowed between retries.
|
|
4285
4342
|
* @param {number} [retryDelayFactor=1] - The factor by which the retry delay increases after each attempt.
|
|
4286
4343
|
*/
|
|
4287
|
-
constructor(name, task, description = "", concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, isSubMeta = false, isHidden = false, getTagCallback = void 0, inputSchema
|
|
4344
|
+
constructor(name, task, description = "", concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, isSubMeta = false, isHidden = false, getTagCallback = void 0, inputSchema, validateInputContext = false, outputSchema, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
|
|
4288
4345
|
super(isSubMeta || isHidden);
|
|
4289
4346
|
this.version = 1;
|
|
4290
4347
|
this.isMeta = false;
|
|
@@ -4297,8 +4354,10 @@ var Task = class _Task extends SignalEmitter {
|
|
|
4297
4354
|
this.isEphemeral = false;
|
|
4298
4355
|
this.isDebounce = false;
|
|
4299
4356
|
this.inputContextSchema = { type: "object" };
|
|
4357
|
+
this.hasExplicitInputContextSchema = false;
|
|
4300
4358
|
this.validateInputContext = false;
|
|
4301
4359
|
this.outputContextSchema = { type: "object" };
|
|
4360
|
+
this.hasExplicitOutputContextSchema = false;
|
|
4302
4361
|
this.validateOutputContext = false;
|
|
4303
4362
|
this.retryCount = 0;
|
|
4304
4363
|
this.retryDelay = 0;
|
|
@@ -4328,9 +4387,11 @@ var Task = class _Task extends SignalEmitter {
|
|
|
4328
4387
|
this.isMeta = isMeta;
|
|
4329
4388
|
this.isSubMeta = isSubMeta;
|
|
4330
4389
|
this.isHidden = isHidden;
|
|
4331
|
-
this.inputContextSchema = inputSchema;
|
|
4390
|
+
this.inputContextSchema = inputSchema ?? { type: "object" };
|
|
4391
|
+
this.hasExplicitInputContextSchema = inputSchema !== void 0;
|
|
4332
4392
|
this.validateInputContext = validateInputContext;
|
|
4333
|
-
this.outputContextSchema = outputSchema;
|
|
4393
|
+
this.outputContextSchema = outputSchema ?? { type: "object" };
|
|
4394
|
+
this.hasExplicitOutputContextSchema = outputSchema !== void 0;
|
|
4334
4395
|
this.validateOutputContext = validateOutputContext;
|
|
4335
4396
|
this.retryCount = retryCount;
|
|
4336
4397
|
this.retryDelay = retryDelay;
|
|
@@ -4347,6 +4408,8 @@ var Task = class _Task extends SignalEmitter {
|
|
|
4347
4408
|
"meta.task.destroyed",
|
|
4348
4409
|
"meta.task.output_validation_failed",
|
|
4349
4410
|
"meta.task.input_validation_failed",
|
|
4411
|
+
"meta.task.input_schema_missing",
|
|
4412
|
+
"meta.task.output_schema_missing",
|
|
4350
4413
|
"meta.task.relationship_added",
|
|
4351
4414
|
"meta.task.relationship_removed",
|
|
4352
4415
|
"meta.task.layer_index_changed",
|
|
@@ -4435,9 +4498,9 @@ var Task = class _Task extends SignalEmitter {
|
|
|
4435
4498
|
this.isSubMeta,
|
|
4436
4499
|
this.isHidden,
|
|
4437
4500
|
this.getTag,
|
|
4438
|
-
this.inputContextSchema,
|
|
4501
|
+
this.hasExplicitInputContextSchema ? this.inputContextSchema : void 0,
|
|
4439
4502
|
this.validateInputContext,
|
|
4440
|
-
this.outputContextSchema,
|
|
4503
|
+
this.hasExplicitOutputContextSchema ? this.outputContextSchema : void 0,
|
|
4441
4504
|
this.validateOutputContext,
|
|
4442
4505
|
this.retryCount,
|
|
4443
4506
|
this.retryDelay,
|
|
@@ -4484,9 +4547,11 @@ var Task = class _Task extends SignalEmitter {
|
|
|
4484
4547
|
}
|
|
4485
4548
|
setInputContextSchema(schema) {
|
|
4486
4549
|
this.inputContextSchema = schema;
|
|
4550
|
+
this.hasExplicitInputContextSchema = true;
|
|
4487
4551
|
}
|
|
4488
4552
|
setOutputContextSchema(schema) {
|
|
4489
4553
|
this.outputContextSchema = schema;
|
|
4554
|
+
this.hasExplicitOutputContextSchema = true;
|
|
4490
4555
|
}
|
|
4491
4556
|
setValidateInputContext(value) {
|
|
4492
4557
|
this.validateInputContext = value;
|
|
@@ -4723,19 +4788,86 @@ var Task = class _Task extends SignalEmitter {
|
|
|
4723
4788
|
* @param {AnyObject} context - The input context to validate.
|
|
4724
4789
|
* @return {true | AnyObject} - Returns `true` if validation succeeds, otherwise returns an error object containing details of the validation failure.
|
|
4725
4790
|
*/
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4791
|
+
getEffectiveValidationMode(direction, metadata = {}) {
|
|
4792
|
+
const resolvedPolicy = Cadenza.resolveRuntimeValidationPolicyForTask(
|
|
4793
|
+
this,
|
|
4794
|
+
metadata
|
|
4795
|
+
);
|
|
4796
|
+
const policyMode = direction === "input" ? resolvedPolicy.inputMode : resolvedPolicy.outputMode;
|
|
4797
|
+
const isExplicit = direction === "input" ? this.validateInputContext : this.validateOutputContext;
|
|
4798
|
+
return {
|
|
4799
|
+
resolvedPolicy,
|
|
4800
|
+
mode: isExplicit ? "enforce" : policyMode,
|
|
4801
|
+
warnOnMissingSchema: direction === "input" ? resolvedPolicy.warnOnMissingInputSchema : resolvedPolicy.warnOnMissingOutputSchema,
|
|
4802
|
+
hasExplicitSchema: direction === "input" ? this.hasExplicitInputContextSchema : this.hasExplicitOutputContextSchema,
|
|
4803
|
+
schema: direction === "input" ? this.inputContextSchema : this.outputContextSchema
|
|
4804
|
+
};
|
|
4805
|
+
}
|
|
4806
|
+
warnMissingSchema(direction, metadata = {}) {
|
|
4807
|
+
const resolvedPolicy = Cadenza.resolveRuntimeValidationPolicyForTask(
|
|
4808
|
+
this,
|
|
4809
|
+
metadata
|
|
4810
|
+
);
|
|
4811
|
+
const cacheKey = `${this.name}:${this.version}:${direction}:${resolvedPolicy.layer}`;
|
|
4812
|
+
if (!Cadenza.shouldEmitMissingSchemaWarning(cacheKey)) {
|
|
4813
|
+
return;
|
|
4814
|
+
}
|
|
4815
|
+
const ctx = {
|
|
4816
|
+
__taskName: this.name,
|
|
4817
|
+
__taskVersion: this.version,
|
|
4818
|
+
__layer: resolvedPolicy.layer,
|
|
4819
|
+
__activeScopeIds: resolvedPolicy.activeScopeIds
|
|
4820
|
+
};
|
|
4821
|
+
this.emitWithMetadata(`meta.task.${direction}_schema_missing`, ctx);
|
|
4822
|
+
console.warn(
|
|
4823
|
+
`[CADENZA_VALIDATION] Missing ${direction} schema for task '${this.name}'`,
|
|
4824
|
+
{
|
|
4825
|
+
taskName: this.name,
|
|
4826
|
+
taskVersion: this.version,
|
|
4827
|
+
direction,
|
|
4828
|
+
layer: resolvedPolicy.layer,
|
|
4829
|
+
activeScopeIds: resolvedPolicy.activeScopeIds
|
|
4830
|
+
}
|
|
4831
|
+
);
|
|
4832
|
+
}
|
|
4833
|
+
logValidationFailure(direction, validationErrors, metadata = {}) {
|
|
4834
|
+
const resolvedPolicy = Cadenza.resolveRuntimeValidationPolicyForTask(
|
|
4835
|
+
this,
|
|
4836
|
+
metadata
|
|
4837
|
+
);
|
|
4838
|
+
console.error(
|
|
4839
|
+
`[CADENZA_VALIDATION] ${direction} validation failed for task '${this.name}'`,
|
|
4840
|
+
{
|
|
4841
|
+
taskName: this.name,
|
|
4842
|
+
taskVersion: this.version,
|
|
4843
|
+
direction,
|
|
4844
|
+
layer: resolvedPolicy.layer,
|
|
4845
|
+
activeScopeIds: resolvedPolicy.activeScopeIds,
|
|
4846
|
+
errors: validationErrors
|
|
4847
|
+
}
|
|
4848
|
+
);
|
|
4849
|
+
}
|
|
4850
|
+
validateInput(context, metadata = {}) {
|
|
4851
|
+
const config = this.getEffectiveValidationMode("input", metadata);
|
|
4852
|
+
if (config.mode === "off") {
|
|
4853
|
+
return true;
|
|
4854
|
+
}
|
|
4855
|
+
if (!config.hasExplicitSchema) {
|
|
4856
|
+
if (config.warnOnMissingSchema) {
|
|
4857
|
+
this.warnMissingSchema("input", metadata);
|
|
4858
|
+
}
|
|
4859
|
+
return true;
|
|
4860
|
+
}
|
|
4861
|
+
const validationResult = this.validateSchema(context, config.schema);
|
|
4862
|
+
if (!validationResult.valid) {
|
|
4863
|
+
this.emitWithMetadata("meta.task.input_validation_failed", {
|
|
4864
|
+
__taskName: this.name,
|
|
4865
|
+
__taskVersion: this.version,
|
|
4866
|
+
__context: context,
|
|
4867
|
+
__errors: validationResult.errors
|
|
4868
|
+
});
|
|
4869
|
+
this.logValidationFailure("input", validationResult.errors, metadata);
|
|
4870
|
+
if (config.mode === "enforce") {
|
|
4739
4871
|
return {
|
|
4740
4872
|
errored: true,
|
|
4741
4873
|
__error: "Input context validation failed",
|
|
@@ -4752,19 +4884,27 @@ var Task = class _Task extends SignalEmitter {
|
|
|
4752
4884
|
* @return {true | AnyObject} Returns `true` if the output context is valid; otherwise, returns an object
|
|
4753
4885
|
* containing error information when validation fails.
|
|
4754
4886
|
*/
|
|
4755
|
-
validateOutput(context) {
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
if (
|
|
4762
|
-
this.
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4887
|
+
validateOutput(context, metadata = {}) {
|
|
4888
|
+
const config = this.getEffectiveValidationMode("output", metadata);
|
|
4889
|
+
if (config.mode === "off") {
|
|
4890
|
+
return true;
|
|
4891
|
+
}
|
|
4892
|
+
if (!config.hasExplicitSchema) {
|
|
4893
|
+
if (config.warnOnMissingSchema) {
|
|
4894
|
+
this.warnMissingSchema("output", metadata);
|
|
4895
|
+
}
|
|
4896
|
+
return true;
|
|
4897
|
+
}
|
|
4898
|
+
const validationResult = this.validateSchema(context, config.schema);
|
|
4899
|
+
if (!validationResult.valid) {
|
|
4900
|
+
this.emitWithMetadata("meta.task.output_validation_failed", {
|
|
4901
|
+
__taskName: this.name,
|
|
4902
|
+
__taskVersion: this.version,
|
|
4903
|
+
__result: context,
|
|
4904
|
+
__errors: validationResult.errors
|
|
4905
|
+
});
|
|
4906
|
+
this.logValidationFailure("output", validationResult.errors, metadata);
|
|
4907
|
+
if (config.mode === "enforce") {
|
|
4768
4908
|
return {
|
|
4769
4909
|
errored: true,
|
|
4770
4910
|
__error: "Output context validation failed",
|
|
@@ -5155,6 +5295,7 @@ var Task = class _Task extends SignalEmitter {
|
|
|
5155
5295
|
intentName,
|
|
5156
5296
|
intent.input
|
|
5157
5297
|
);
|
|
5298
|
+
this.hasExplicitInputContextSchema = true;
|
|
5158
5299
|
}
|
|
5159
5300
|
if (intent?.output) {
|
|
5160
5301
|
this.outputContextSchema = this.mergeSchemaVariant(
|
|
@@ -5162,6 +5303,7 @@ var Task = class _Task extends SignalEmitter {
|
|
|
5162
5303
|
intentName,
|
|
5163
5304
|
intent.output
|
|
5164
5305
|
);
|
|
5306
|
+
this.hasExplicitOutputContextSchema = true;
|
|
5165
5307
|
}
|
|
5166
5308
|
}
|
|
5167
5309
|
return this;
|
|
@@ -6865,6 +7007,146 @@ var Cadenza = class {
|
|
|
6865
7007
|
static async inquire(inquiry, context, options) {
|
|
6866
7008
|
return this.inquiryBroker?.inquire(inquiry, context, options);
|
|
6867
7009
|
}
|
|
7010
|
+
static setRuntimeInquiryDelegate(delegate) {
|
|
7011
|
+
this.runtimeInquiryDelegate = delegate;
|
|
7012
|
+
}
|
|
7013
|
+
static resolveRuntimeInquiryDelegate() {
|
|
7014
|
+
return this.runtimeInquiryDelegate ?? ((inquiry, context, options) => this.inquire(inquiry, context, options));
|
|
7015
|
+
}
|
|
7016
|
+
static getRuntimeValidationPolicy() {
|
|
7017
|
+
return { ...this.runtimeValidationPolicy };
|
|
7018
|
+
}
|
|
7019
|
+
static setRuntimeValidationPolicy(policy = {}) {
|
|
7020
|
+
this.runtimeValidationPolicy = {
|
|
7021
|
+
...this.runtimeValidationPolicy,
|
|
7022
|
+
...policy
|
|
7023
|
+
};
|
|
7024
|
+
this.emittedMissingSchemaWarnings.clear();
|
|
7025
|
+
return this.getRuntimeValidationPolicy();
|
|
7026
|
+
}
|
|
7027
|
+
static replaceRuntimeValidationPolicy(policy = {}) {
|
|
7028
|
+
this.runtimeValidationPolicy = { ...policy };
|
|
7029
|
+
this.emittedMissingSchemaWarnings.clear();
|
|
7030
|
+
return this.getRuntimeValidationPolicy();
|
|
7031
|
+
}
|
|
7032
|
+
static clearRuntimeValidationPolicy() {
|
|
7033
|
+
this.runtimeValidationPolicy = {};
|
|
7034
|
+
this.emittedMissingSchemaWarnings.clear();
|
|
7035
|
+
}
|
|
7036
|
+
static getRuntimeValidationScopes() {
|
|
7037
|
+
return Array.from(this.runtimeValidationScopes.values()).map((scope) => ({
|
|
7038
|
+
...scope,
|
|
7039
|
+
startTaskNames: scope.startTaskNames ? [...scope.startTaskNames] : void 0,
|
|
7040
|
+
startRoutineNames: scope.startRoutineNames ? [...scope.startRoutineNames] : void 0,
|
|
7041
|
+
policy: scope.policy ? { ...scope.policy } : void 0
|
|
7042
|
+
}));
|
|
7043
|
+
}
|
|
7044
|
+
static upsertRuntimeValidationScope(scope) {
|
|
7045
|
+
if (!scope.id?.trim()) {
|
|
7046
|
+
throw new Error("Runtime validation scope id is required");
|
|
7047
|
+
}
|
|
7048
|
+
const normalizedScope = {
|
|
7049
|
+
id: scope.id,
|
|
7050
|
+
active: scope.active !== false,
|
|
7051
|
+
startTaskNames: scope.startTaskNames ? [...new Set(scope.startTaskNames)] : void 0,
|
|
7052
|
+
startRoutineNames: scope.startRoutineNames ? [...new Set(scope.startRoutineNames)] : void 0,
|
|
7053
|
+
policy: scope.policy ? { ...scope.policy } : void 0
|
|
7054
|
+
};
|
|
7055
|
+
this.runtimeValidationScopes.set(scope.id, normalizedScope);
|
|
7056
|
+
this.emittedMissingSchemaWarnings.clear();
|
|
7057
|
+
return {
|
|
7058
|
+
...normalizedScope,
|
|
7059
|
+
startTaskNames: normalizedScope.startTaskNames ? [...normalizedScope.startTaskNames] : void 0,
|
|
7060
|
+
startRoutineNames: normalizedScope.startRoutineNames ? [...normalizedScope.startRoutineNames] : void 0,
|
|
7061
|
+
policy: normalizedScope.policy ? { ...normalizedScope.policy } : void 0
|
|
7062
|
+
};
|
|
7063
|
+
}
|
|
7064
|
+
static removeRuntimeValidationScope(id) {
|
|
7065
|
+
this.runtimeValidationScopes.delete(id);
|
|
7066
|
+
this.emittedMissingSchemaWarnings.clear();
|
|
7067
|
+
}
|
|
7068
|
+
static clearRuntimeValidationScopes() {
|
|
7069
|
+
this.runtimeValidationScopes.clear();
|
|
7070
|
+
this.emittedMissingSchemaWarnings.clear();
|
|
7071
|
+
}
|
|
7072
|
+
static applyRuntimeValidationScopesToContext(context, routineName, tasks) {
|
|
7073
|
+
const existingScopeIds = /* @__PURE__ */ new Set();
|
|
7074
|
+
const metadataScopeIds = context.__metadata?.__runtimeValidationScopeIds;
|
|
7075
|
+
const rootScopeIds = context.__runtimeValidationScopeIds;
|
|
7076
|
+
if (Array.isArray(rootScopeIds)) {
|
|
7077
|
+
rootScopeIds.forEach((id) => existingScopeIds.add(id));
|
|
7078
|
+
}
|
|
7079
|
+
if (Array.isArray(metadataScopeIds)) {
|
|
7080
|
+
metadataScopeIds.forEach((id) => existingScopeIds.add(id));
|
|
7081
|
+
}
|
|
7082
|
+
const taskNames = new Set(tasks.map((task) => task.name));
|
|
7083
|
+
for (const scope of this.runtimeValidationScopes.values()) {
|
|
7084
|
+
if (scope.active === false) {
|
|
7085
|
+
continue;
|
|
7086
|
+
}
|
|
7087
|
+
const matchesRoutine = scope.startRoutineNames?.includes(routineName) === true;
|
|
7088
|
+
const matchesTask = scope.startTaskNames?.some((taskName) => taskNames.has(taskName)) === true;
|
|
7089
|
+
if (matchesRoutine || matchesTask) {
|
|
7090
|
+
existingScopeIds.add(scope.id);
|
|
7091
|
+
}
|
|
7092
|
+
}
|
|
7093
|
+
if (existingScopeIds.size > 0) {
|
|
7094
|
+
const scopeIds = Array.from(existingScopeIds);
|
|
7095
|
+
context.__runtimeValidationScopeIds = scopeIds;
|
|
7096
|
+
context.__metadata = {
|
|
7097
|
+
...context.__metadata ?? {},
|
|
7098
|
+
__runtimeValidationScopeIds: scopeIds
|
|
7099
|
+
};
|
|
7100
|
+
}
|
|
7101
|
+
return context;
|
|
7102
|
+
}
|
|
7103
|
+
static resolveRuntimeValidationPolicyForTask(task, metadata = {}) {
|
|
7104
|
+
const layer = task.isMeta || task.isSubMeta || metadata.__isSubMeta ? "meta" : "business";
|
|
7105
|
+
const activeScopeIds = /* @__PURE__ */ new Set();
|
|
7106
|
+
const rootScopeIds = metadata.__runtimeValidationScopeIds;
|
|
7107
|
+
const nestedScopeIds = metadata.__metadata?.__runtimeValidationScopeIds;
|
|
7108
|
+
if (Array.isArray(rootScopeIds)) {
|
|
7109
|
+
rootScopeIds.forEach((id) => activeScopeIds.add(id));
|
|
7110
|
+
}
|
|
7111
|
+
if (Array.isArray(nestedScopeIds)) {
|
|
7112
|
+
nestedScopeIds.forEach((id) => activeScopeIds.add(id));
|
|
7113
|
+
}
|
|
7114
|
+
const mergedPolicy = {
|
|
7115
|
+
...this.runtimeValidationPolicy
|
|
7116
|
+
};
|
|
7117
|
+
for (const scopeId of activeScopeIds) {
|
|
7118
|
+
const scope = this.runtimeValidationScopes.get(scopeId);
|
|
7119
|
+
if (!scope?.policy || scope.active === false) {
|
|
7120
|
+
continue;
|
|
7121
|
+
}
|
|
7122
|
+
Object.assign(mergedPolicy, scope.policy);
|
|
7123
|
+
}
|
|
7124
|
+
if (layer === "meta") {
|
|
7125
|
+
return {
|
|
7126
|
+
layer,
|
|
7127
|
+
inputMode: mergedPolicy.metaInput ?? "off",
|
|
7128
|
+
outputMode: mergedPolicy.metaOutput ?? "off",
|
|
7129
|
+
warnOnMissingInputSchema: mergedPolicy.warnOnMissingMetaInputSchema === true,
|
|
7130
|
+
warnOnMissingOutputSchema: mergedPolicy.warnOnMissingMetaOutputSchema === true,
|
|
7131
|
+
activeScopeIds: Array.from(activeScopeIds)
|
|
7132
|
+
};
|
|
7133
|
+
}
|
|
7134
|
+
return {
|
|
7135
|
+
layer,
|
|
7136
|
+
inputMode: mergedPolicy.businessInput ?? "off",
|
|
7137
|
+
outputMode: mergedPolicy.businessOutput ?? "off",
|
|
7138
|
+
warnOnMissingInputSchema: mergedPolicy.warnOnMissingBusinessInputSchema === true,
|
|
7139
|
+
warnOnMissingOutputSchema: mergedPolicy.warnOnMissingBusinessOutputSchema === true,
|
|
7140
|
+
activeScopeIds: Array.from(activeScopeIds)
|
|
7141
|
+
};
|
|
7142
|
+
}
|
|
7143
|
+
static shouldEmitMissingSchemaWarning(cacheKey) {
|
|
7144
|
+
if (this.emittedMissingSchemaWarnings.has(cacheKey)) {
|
|
7145
|
+
return false;
|
|
7146
|
+
}
|
|
7147
|
+
this.emittedMissingSchemaWarnings.add(cacheKey);
|
|
7148
|
+
return true;
|
|
7149
|
+
}
|
|
6868
7150
|
/**
|
|
6869
7151
|
* Creates an in-memory actor runtime instance.
|
|
6870
7152
|
*
|
|
@@ -7464,11 +7746,18 @@ var Cadenza = class {
|
|
|
7464
7746
|
this.registry?.reset();
|
|
7465
7747
|
this.taskCache.clear();
|
|
7466
7748
|
this.actorCache.clear();
|
|
7749
|
+
this.runtimeInquiryDelegate = void 0;
|
|
7750
|
+
this.runtimeValidationPolicy = {};
|
|
7751
|
+
this.runtimeValidationScopes.clear();
|
|
7752
|
+
this.emittedMissingSchemaWarnings.clear();
|
|
7467
7753
|
this.isBootstrapped = false;
|
|
7468
7754
|
}
|
|
7469
7755
|
};
|
|
7470
7756
|
Cadenza.taskCache = /* @__PURE__ */ new Map();
|
|
7471
7757
|
Cadenza.actorCache = /* @__PURE__ */ new Map();
|
|
7758
|
+
Cadenza.runtimeValidationPolicy = {};
|
|
7759
|
+
Cadenza.runtimeValidationScopes = /* @__PURE__ */ new Map();
|
|
7760
|
+
Cadenza.emittedMissingSchemaWarnings = /* @__PURE__ */ new Set();
|
|
7472
7761
|
Cadenza.isBootstrapped = false;
|
|
7473
7762
|
Cadenza.mode = "production";
|
|
7474
7763
|
|
|
@@ -7485,6 +7774,7 @@ var index_default = Cadenza;
|
|
|
7485
7774
|
GraphRun,
|
|
7486
7775
|
GraphRunner,
|
|
7487
7776
|
InquiryBroker,
|
|
7777
|
+
META_ACTOR_SESSION_STATE_PERSIST_INTENT,
|
|
7488
7778
|
SignalBroker,
|
|
7489
7779
|
SignalEmitter,
|
|
7490
7780
|
Task,
|