@cadenza.io/core 3.24.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 CHANGED
@@ -854,8 +854,10 @@ declare class Task extends SignalEmitter implements Graph {
854
854
  readonly isEphemeral: boolean;
855
855
  readonly isDebounce: boolean;
856
856
  inputContextSchema: Schema;
857
+ hasExplicitInputContextSchema: boolean;
857
858
  validateInputContext: boolean;
858
859
  outputContextSchema: Schema;
860
+ hasExplicitOutputContextSchema: boolean;
859
861
  validateOutputContext: boolean;
860
862
  readonly retryCount: number;
861
863
  readonly retryDelay: number;
@@ -962,7 +964,10 @@ declare class Task extends SignalEmitter implements Graph {
962
964
  * @param {AnyObject} context - The input context to validate.
963
965
  * @return {true | AnyObject} - Returns `true` if validation succeeds, otherwise returns an error object containing details of the validation failure.
964
966
  */
965
- validateInput(context: AnyObject): true | AnyObject;
967
+ private getEffectiveValidationMode;
968
+ private warnMissingSchema;
969
+ private logValidationFailure;
970
+ validateInput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
966
971
  /**
967
972
  * Validates the output context using the provided schema and emits metadata if validation fails.
968
973
  *
@@ -970,7 +975,7 @@ declare class Task extends SignalEmitter implements Graph {
970
975
  * @return {true | AnyObject} Returns `true` if the output context is valid; otherwise, returns an object
971
976
  * containing error information when validation fails.
972
977
  */
973
- validateOutput(context: AnyObject): true | AnyObject;
978
+ validateOutput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
974
979
  /**
975
980
  * Executes a task within a given context, optionally emitting signals and reporting progress.
976
981
  *
@@ -2152,6 +2157,33 @@ interface TaskOptions {
2152
2157
  retryDelayFactor?: number;
2153
2158
  }
2154
2159
  type CadenzaMode = "dev" | "debug" | "verbose" | "production";
2160
+ type RuntimeValidationMode = "off" | "warn" | "enforce";
2161
+ interface RuntimeValidationPolicy {
2162
+ metaInput?: RuntimeValidationMode;
2163
+ metaOutput?: RuntimeValidationMode;
2164
+ businessInput?: RuntimeValidationMode;
2165
+ businessOutput?: RuntimeValidationMode;
2166
+ warnOnMissingMetaInputSchema?: boolean;
2167
+ warnOnMissingMetaOutputSchema?: boolean;
2168
+ warnOnMissingBusinessInputSchema?: boolean;
2169
+ warnOnMissingBusinessOutputSchema?: boolean;
2170
+ }
2171
+ interface RuntimeValidationScope {
2172
+ id: string;
2173
+ active?: boolean;
2174
+ startTaskNames?: string[];
2175
+ startRoutineNames?: string[];
2176
+ policy?: RuntimeValidationPolicy;
2177
+ }
2178
+ interface ResolvedRuntimeValidationPolicy {
2179
+ layer: "meta" | "business";
2180
+ inputMode: RuntimeValidationMode;
2181
+ outputMode: RuntimeValidationMode;
2182
+ warnOnMissingInputSchema: boolean;
2183
+ warnOnMissingOutputSchema: boolean;
2184
+ activeScopeIds: string[];
2185
+ }
2186
+ type RuntimeInquiryDelegate = (inquiry: string, context: AnyObject, options?: InquiryOptions) => Promise<any>;
2155
2187
  /**
2156
2188
  * Represents the core class of the Cadenza framework managing tasks, meta-tasks, signal emissions, and execution strategies.
2157
2189
  * All core components such as SignalBroker, GraphRunner, and GraphRegistry are initialized through this class, and it provides
@@ -2165,6 +2197,10 @@ declare class Cadenza {
2165
2197
  static registry: GraphRegistry;
2166
2198
  private static taskCache;
2167
2199
  private static actorCache;
2200
+ private static runtimeInquiryDelegate;
2201
+ private static runtimeValidationPolicy;
2202
+ private static runtimeValidationScopes;
2203
+ private static emittedMissingSchemaWarnings;
2168
2204
  static isBootstrapped: boolean;
2169
2205
  static mode: CadenzaMode;
2170
2206
  /**
@@ -2252,6 +2288,19 @@ declare class Cadenza {
2252
2288
  static getRoutine(routineName: string): GraphRoutine | undefined;
2253
2289
  static defineIntent(intent: Intent): Intent;
2254
2290
  static inquire(inquiry: string, context: AnyObject, options?: InquiryOptions): Promise<any>;
2291
+ static setRuntimeInquiryDelegate(delegate?: RuntimeInquiryDelegate): void;
2292
+ static resolveRuntimeInquiryDelegate(): RuntimeInquiryDelegate;
2293
+ static getRuntimeValidationPolicy(): RuntimeValidationPolicy;
2294
+ static setRuntimeValidationPolicy(policy?: RuntimeValidationPolicy): RuntimeValidationPolicy;
2295
+ static replaceRuntimeValidationPolicy(policy?: RuntimeValidationPolicy): RuntimeValidationPolicy;
2296
+ static clearRuntimeValidationPolicy(): void;
2297
+ static getRuntimeValidationScopes(): RuntimeValidationScope[];
2298
+ static upsertRuntimeValidationScope(scope: RuntimeValidationScope): RuntimeValidationScope;
2299
+ static removeRuntimeValidationScope(id: string): void;
2300
+ static clearRuntimeValidationScopes(): void;
2301
+ static applyRuntimeValidationScopesToContext(context: AnyObject, routineName: string, tasks: Task[]): AnyObject;
2302
+ static resolveRuntimeValidationPolicyForTask(task: Task, metadata?: AnyObject): ResolvedRuntimeValidationPolicy;
2303
+ static shouldEmitMissingSchemaWarning(cacheKey: string): boolean;
2255
2304
  /**
2256
2305
  * Creates an in-memory actor runtime instance.
2257
2306
  *
@@ -2617,4 +2666,4 @@ declare class Cadenza {
2617
2666
  static reset(): void;
2618
2667
  }
2619
2668
 
2620
- export { Actor, type ActorConsistencyProfileName, type ActorDefinition, type ActorFactoryOptions, type ActorInvocationOptions, type ActorKeyDefinition, type ActorKind, type ActorLoadPolicy, type ActorRuntimeReadGuard, type ActorSpec, type ActorStateDefinition, type ActorStateReducer, type ActorStateStore, type ActorTaskBindingDefinition, type ActorTaskBindingOptions, type ActorTaskContext, type ActorTaskHandler, type ActorTaskMode, type ActorTaskRuntimeMetadata, type ActorWriteContract, type AnyObject, type CadenzaMode, type DebounceOptions, DebounceTask, type EmitOptions, EphemeralTask, type EphemeralTaskOptions, GraphContext, GraphRegistry, GraphRoutine, GraphRun, GraphRunner, type IdempotencyPolicy, InquiryBroker, type InquiryOptions, type Intent, META_ACTOR_SESSION_STATE_PERSIST_INTENT, type RetryPolicy, type Schema, type SchemaConstraints, type SchemaDefinition, type SchemaType, type SessionPolicy, SignalBroker, SignalEmitter, Task, type TaskFunction, type TaskOptions, type TaskResult, type ThrottleTagGetter, Cadenza as default, getActorTaskRuntimeMetadata };
2669
+ export { Actor, type ActorConsistencyProfileName, type ActorDefinition, type ActorFactoryOptions, type ActorInvocationOptions, type ActorKeyDefinition, type ActorKind, type ActorLoadPolicy, type ActorRuntimeReadGuard, type ActorSpec, type ActorStateDefinition, type ActorStateReducer, type ActorStateStore, type ActorTaskBindingDefinition, type ActorTaskBindingOptions, type ActorTaskContext, type ActorTaskHandler, type ActorTaskMode, type ActorTaskRuntimeMetadata, type ActorWriteContract, type AnyObject, type CadenzaMode, type DebounceOptions, DebounceTask, type EmitOptions, EphemeralTask, type EphemeralTaskOptions, GraphContext, GraphRegistry, GraphRoutine, GraphRun, GraphRunner, type IdempotencyPolicy, InquiryBroker, type InquiryOptions, type Intent, META_ACTOR_SESSION_STATE_PERSIST_INTENT, type ResolvedRuntimeValidationPolicy, type RetryPolicy, type RuntimeValidationMode, type RuntimeValidationPolicy, type RuntimeValidationScope, type Schema, type SchemaConstraints, type SchemaDefinition, type SchemaType, type SessionPolicy, SignalBroker, SignalEmitter, Task, type TaskFunction, type TaskOptions, type TaskResult, type ThrottleTagGetter, Cadenza as default, getActorTaskRuntimeMetadata };
package/dist/index.d.ts CHANGED
@@ -854,8 +854,10 @@ declare class Task extends SignalEmitter implements Graph {
854
854
  readonly isEphemeral: boolean;
855
855
  readonly isDebounce: boolean;
856
856
  inputContextSchema: Schema;
857
+ hasExplicitInputContextSchema: boolean;
857
858
  validateInputContext: boolean;
858
859
  outputContextSchema: Schema;
860
+ hasExplicitOutputContextSchema: boolean;
859
861
  validateOutputContext: boolean;
860
862
  readonly retryCount: number;
861
863
  readonly retryDelay: number;
@@ -962,7 +964,10 @@ declare class Task extends SignalEmitter implements Graph {
962
964
  * @param {AnyObject} context - The input context to validate.
963
965
  * @return {true | AnyObject} - Returns `true` if validation succeeds, otherwise returns an error object containing details of the validation failure.
964
966
  */
965
- validateInput(context: AnyObject): true | AnyObject;
967
+ private getEffectiveValidationMode;
968
+ private warnMissingSchema;
969
+ private logValidationFailure;
970
+ validateInput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
966
971
  /**
967
972
  * Validates the output context using the provided schema and emits metadata if validation fails.
968
973
  *
@@ -970,7 +975,7 @@ declare class Task extends SignalEmitter implements Graph {
970
975
  * @return {true | AnyObject} Returns `true` if the output context is valid; otherwise, returns an object
971
976
  * containing error information when validation fails.
972
977
  */
973
- validateOutput(context: AnyObject): true | AnyObject;
978
+ validateOutput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
974
979
  /**
975
980
  * Executes a task within a given context, optionally emitting signals and reporting progress.
976
981
  *
@@ -2152,6 +2157,33 @@ interface TaskOptions {
2152
2157
  retryDelayFactor?: number;
2153
2158
  }
2154
2159
  type CadenzaMode = "dev" | "debug" | "verbose" | "production";
2160
+ type RuntimeValidationMode = "off" | "warn" | "enforce";
2161
+ interface RuntimeValidationPolicy {
2162
+ metaInput?: RuntimeValidationMode;
2163
+ metaOutput?: RuntimeValidationMode;
2164
+ businessInput?: RuntimeValidationMode;
2165
+ businessOutput?: RuntimeValidationMode;
2166
+ warnOnMissingMetaInputSchema?: boolean;
2167
+ warnOnMissingMetaOutputSchema?: boolean;
2168
+ warnOnMissingBusinessInputSchema?: boolean;
2169
+ warnOnMissingBusinessOutputSchema?: boolean;
2170
+ }
2171
+ interface RuntimeValidationScope {
2172
+ id: string;
2173
+ active?: boolean;
2174
+ startTaskNames?: string[];
2175
+ startRoutineNames?: string[];
2176
+ policy?: RuntimeValidationPolicy;
2177
+ }
2178
+ interface ResolvedRuntimeValidationPolicy {
2179
+ layer: "meta" | "business";
2180
+ inputMode: RuntimeValidationMode;
2181
+ outputMode: RuntimeValidationMode;
2182
+ warnOnMissingInputSchema: boolean;
2183
+ warnOnMissingOutputSchema: boolean;
2184
+ activeScopeIds: string[];
2185
+ }
2186
+ type RuntimeInquiryDelegate = (inquiry: string, context: AnyObject, options?: InquiryOptions) => Promise<any>;
2155
2187
  /**
2156
2188
  * Represents the core class of the Cadenza framework managing tasks, meta-tasks, signal emissions, and execution strategies.
2157
2189
  * All core components such as SignalBroker, GraphRunner, and GraphRegistry are initialized through this class, and it provides
@@ -2165,6 +2197,10 @@ declare class Cadenza {
2165
2197
  static registry: GraphRegistry;
2166
2198
  private static taskCache;
2167
2199
  private static actorCache;
2200
+ private static runtimeInquiryDelegate;
2201
+ private static runtimeValidationPolicy;
2202
+ private static runtimeValidationScopes;
2203
+ private static emittedMissingSchemaWarnings;
2168
2204
  static isBootstrapped: boolean;
2169
2205
  static mode: CadenzaMode;
2170
2206
  /**
@@ -2252,6 +2288,19 @@ declare class Cadenza {
2252
2288
  static getRoutine(routineName: string): GraphRoutine | undefined;
2253
2289
  static defineIntent(intent: Intent): Intent;
2254
2290
  static inquire(inquiry: string, context: AnyObject, options?: InquiryOptions): Promise<any>;
2291
+ static setRuntimeInquiryDelegate(delegate?: RuntimeInquiryDelegate): void;
2292
+ static resolveRuntimeInquiryDelegate(): RuntimeInquiryDelegate;
2293
+ static getRuntimeValidationPolicy(): RuntimeValidationPolicy;
2294
+ static setRuntimeValidationPolicy(policy?: RuntimeValidationPolicy): RuntimeValidationPolicy;
2295
+ static replaceRuntimeValidationPolicy(policy?: RuntimeValidationPolicy): RuntimeValidationPolicy;
2296
+ static clearRuntimeValidationPolicy(): void;
2297
+ static getRuntimeValidationScopes(): RuntimeValidationScope[];
2298
+ static upsertRuntimeValidationScope(scope: RuntimeValidationScope): RuntimeValidationScope;
2299
+ static removeRuntimeValidationScope(id: string): void;
2300
+ static clearRuntimeValidationScopes(): void;
2301
+ static applyRuntimeValidationScopesToContext(context: AnyObject, routineName: string, tasks: Task[]): AnyObject;
2302
+ static resolveRuntimeValidationPolicyForTask(task: Task, metadata?: AnyObject): ResolvedRuntimeValidationPolicy;
2303
+ static shouldEmitMissingSchemaWarning(cacheKey: string): boolean;
2255
2304
  /**
2256
2305
  * Creates an in-memory actor runtime instance.
2257
2306
  *
@@ -2617,4 +2666,4 @@ declare class Cadenza {
2617
2666
  static reset(): void;
2618
2667
  }
2619
2668
 
2620
- export { Actor, type ActorConsistencyProfileName, type ActorDefinition, type ActorFactoryOptions, type ActorInvocationOptions, type ActorKeyDefinition, type ActorKind, type ActorLoadPolicy, type ActorRuntimeReadGuard, type ActorSpec, type ActorStateDefinition, type ActorStateReducer, type ActorStateStore, type ActorTaskBindingDefinition, type ActorTaskBindingOptions, type ActorTaskContext, type ActorTaskHandler, type ActorTaskMode, type ActorTaskRuntimeMetadata, type ActorWriteContract, type AnyObject, type CadenzaMode, type DebounceOptions, DebounceTask, type EmitOptions, EphemeralTask, type EphemeralTaskOptions, GraphContext, GraphRegistry, GraphRoutine, GraphRun, GraphRunner, type IdempotencyPolicy, InquiryBroker, type InquiryOptions, type Intent, META_ACTOR_SESSION_STATE_PERSIST_INTENT, type RetryPolicy, type Schema, type SchemaConstraints, type SchemaDefinition, type SchemaType, type SessionPolicy, SignalBroker, SignalEmitter, Task, type TaskFunction, type TaskOptions, type TaskResult, type ThrottleTagGetter, Cadenza as default, getActorTaskRuntimeMetadata };
2669
+ export { Actor, type ActorConsistencyProfileName, type ActorDefinition, type ActorFactoryOptions, type ActorInvocationOptions, type ActorKeyDefinition, type ActorKind, type ActorLoadPolicy, type ActorRuntimeReadGuard, type ActorSpec, type ActorStateDefinition, type ActorStateReducer, type ActorStateStore, type ActorTaskBindingDefinition, type ActorTaskBindingOptions, type ActorTaskContext, type ActorTaskHandler, type ActorTaskMode, type ActorTaskRuntimeMetadata, type ActorWriteContract, type AnyObject, type CadenzaMode, type DebounceOptions, DebounceTask, type EmitOptions, EphemeralTask, type EphemeralTaskOptions, GraphContext, GraphRegistry, GraphRoutine, GraphRun, GraphRunner, type IdempotencyPolicy, InquiryBroker, type InquiryOptions, type Intent, META_ACTOR_SESSION_STATE_PERSIST_INTENT, type ResolvedRuntimeValidationPolicy, type RetryPolicy, type RuntimeValidationMode, type RuntimeValidationPolicy, type RuntimeValidationScope, type Schema, type SchemaConstraints, type SchemaDefinition, type SchemaType, type SessionPolicy, SignalBroker, SignalEmitter, Task, type TaskFunction, type TaskOptions, type TaskResult, type ThrottleTagGetter, Cadenza as default, getActorTaskRuntimeMetadata };
package/dist/index.js CHANGED
@@ -2676,7 +2676,8 @@ var GraphNode = class _GraphNode extends SignalEmitter {
2676
2676
  if (!this.divided && !this.processing) {
2677
2677
  this.processing = true;
2678
2678
  const inputValidation = this.task.validateInput(
2679
- this.isMeta() ? this.context.getMetadata() : this.context.getContext()
2679
+ this.isMeta() ? this.context.getFullContext() : this.context.getContext(),
2680
+ this.context.getMetadata()
2680
2681
  );
2681
2682
  if (inputValidation !== true) {
2682
2683
  this.onError(inputValidation.__validationErrors);
@@ -2769,7 +2770,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
2769
2770
  }
2770
2771
  }
2771
2772
  inquire(inquiry, context, options) {
2772
- return Cadenza.inquire(
2773
+ return Cadenza.resolveRuntimeInquiryDelegate()(
2773
2774
  inquiry,
2774
2775
  { ...context, __executionTraceId: this.executionTraceId },
2775
2776
  options
@@ -3011,7 +3012,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
3011
3012
  return this.divideAsync(current);
3012
3013
  }
3013
3014
  while (!current.done && current.value !== void 0) {
3014
- const outputValidation = this.task.validateOutput(current.value);
3015
+ const outputValidation = this.task.validateOutput(
3016
+ current.value,
3017
+ this.context.getMetadata()
3018
+ );
3015
3019
  if (outputValidation !== true) {
3016
3020
  this.onError(outputValidation.__validationErrors);
3017
3021
  break;
@@ -3023,7 +3027,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
3023
3027
  } else if (this.result !== void 0 && !this.errored) {
3024
3028
  newNodes.push(...this.generateNewNodes(this.result));
3025
3029
  if (typeof this.result !== "boolean") {
3026
- const outputValidation = this.task.validateOutput(this.result);
3030
+ const outputValidation = this.task.validateOutput(
3031
+ this.result,
3032
+ this.context.getMetadata()
3033
+ );
3027
3034
  if (outputValidation !== true) {
3028
3035
  this.onError(outputValidation.__validationErrors);
3029
3036
  }
@@ -3055,7 +3062,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
3055
3062
  async divideAsync(current) {
3056
3063
  const nextNodes = [];
3057
3064
  const _current = await current;
3058
- const outputValidation = this.task.validateOutput(_current.value);
3065
+ const outputValidation = this.task.validateOutput(
3066
+ _current.value,
3067
+ this.context.getMetadata()
3068
+ );
3059
3069
  if (outputValidation !== true) {
3060
3070
  this.onError(outputValidation.__validationErrors);
3061
3071
  return nextNodes;
@@ -3063,7 +3073,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
3063
3073
  nextNodes.push(...this.generateNewNodes(_current.value));
3064
3074
  }
3065
3075
  for await (const result of this.result) {
3066
- const outputValidation2 = this.task.validateOutput(result);
3076
+ const outputValidation2 = this.task.validateOutput(
3077
+ result,
3078
+ this.context.getMetadata()
3079
+ );
3067
3080
  if (outputValidation2 !== true) {
3068
3081
  this.onError(outputValidation2.__validationErrors);
3069
3082
  return [];
@@ -3510,6 +3523,11 @@ var GraphRunner = class extends SignalEmitter {
3510
3523
  context.__executionTraceId = executionTraceId;
3511
3524
  const routineExecId = context.__routineExecId ?? (0, import_uuid5.v4)();
3512
3525
  context.__routineExecId = routineExecId;
3526
+ Cadenza.applyRuntimeValidationScopesToContext(
3527
+ context,
3528
+ routineName,
3529
+ allTasks
3530
+ );
3513
3531
  const ctx = new GraphContext(context || {});
3514
3532
  if (!isSubMeta) {
3515
3533
  if (isNewTrace) {
@@ -4323,7 +4341,7 @@ var Task = class _Task extends SignalEmitter {
4323
4341
  * @param {number} [retryDelayMax=0] - The maximum delay (in milliseconds) allowed between retries.
4324
4342
  * @param {number} [retryDelayFactor=1] - The factor by which the retry delay increases after each attempt.
4325
4343
  */
4326
- constructor(name, task, description = "", concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, isSubMeta = false, isHidden = false, getTagCallback = void 0, inputSchema = { type: "object" }, validateInputContext = false, outputSchema = { type: "object" }, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
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) {
4327
4345
  super(isSubMeta || isHidden);
4328
4346
  this.version = 1;
4329
4347
  this.isMeta = false;
@@ -4336,8 +4354,10 @@ var Task = class _Task extends SignalEmitter {
4336
4354
  this.isEphemeral = false;
4337
4355
  this.isDebounce = false;
4338
4356
  this.inputContextSchema = { type: "object" };
4357
+ this.hasExplicitInputContextSchema = false;
4339
4358
  this.validateInputContext = false;
4340
4359
  this.outputContextSchema = { type: "object" };
4360
+ this.hasExplicitOutputContextSchema = false;
4341
4361
  this.validateOutputContext = false;
4342
4362
  this.retryCount = 0;
4343
4363
  this.retryDelay = 0;
@@ -4367,9 +4387,11 @@ var Task = class _Task extends SignalEmitter {
4367
4387
  this.isMeta = isMeta;
4368
4388
  this.isSubMeta = isSubMeta;
4369
4389
  this.isHidden = isHidden;
4370
- this.inputContextSchema = inputSchema;
4390
+ this.inputContextSchema = inputSchema ?? { type: "object" };
4391
+ this.hasExplicitInputContextSchema = inputSchema !== void 0;
4371
4392
  this.validateInputContext = validateInputContext;
4372
- this.outputContextSchema = outputSchema;
4393
+ this.outputContextSchema = outputSchema ?? { type: "object" };
4394
+ this.hasExplicitOutputContextSchema = outputSchema !== void 0;
4373
4395
  this.validateOutputContext = validateOutputContext;
4374
4396
  this.retryCount = retryCount;
4375
4397
  this.retryDelay = retryDelay;
@@ -4386,6 +4408,8 @@ var Task = class _Task extends SignalEmitter {
4386
4408
  "meta.task.destroyed",
4387
4409
  "meta.task.output_validation_failed",
4388
4410
  "meta.task.input_validation_failed",
4411
+ "meta.task.input_schema_missing",
4412
+ "meta.task.output_schema_missing",
4389
4413
  "meta.task.relationship_added",
4390
4414
  "meta.task.relationship_removed",
4391
4415
  "meta.task.layer_index_changed",
@@ -4474,9 +4498,9 @@ var Task = class _Task extends SignalEmitter {
4474
4498
  this.isSubMeta,
4475
4499
  this.isHidden,
4476
4500
  this.getTag,
4477
- this.inputContextSchema,
4501
+ this.hasExplicitInputContextSchema ? this.inputContextSchema : void 0,
4478
4502
  this.validateInputContext,
4479
- this.outputContextSchema,
4503
+ this.hasExplicitOutputContextSchema ? this.outputContextSchema : void 0,
4480
4504
  this.validateOutputContext,
4481
4505
  this.retryCount,
4482
4506
  this.retryDelay,
@@ -4523,9 +4547,11 @@ var Task = class _Task extends SignalEmitter {
4523
4547
  }
4524
4548
  setInputContextSchema(schema) {
4525
4549
  this.inputContextSchema = schema;
4550
+ this.hasExplicitInputContextSchema = true;
4526
4551
  }
4527
4552
  setOutputContextSchema(schema) {
4528
4553
  this.outputContextSchema = schema;
4554
+ this.hasExplicitOutputContextSchema = true;
4529
4555
  }
4530
4556
  setValidateInputContext(value) {
4531
4557
  this.validateInputContext = value;
@@ -4762,19 +4788,86 @@ var Task = class _Task extends SignalEmitter {
4762
4788
  * @param {AnyObject} context - The input context to validate.
4763
4789
  * @return {true | AnyObject} - Returns `true` if validation succeeds, otherwise returns an error object containing details of the validation failure.
4764
4790
  */
4765
- validateInput(context) {
4766
- if (this.validateInputContext) {
4767
- const validationResult = this.validateSchema(
4768
- context,
4769
- this.inputContextSchema
4770
- );
4771
- if (!validationResult.valid) {
4772
- this.emitWithMetadata("meta.task.input_validation_failed", {
4773
- __taskName: this.name,
4774
- __taskVersion: this.version,
4775
- __context: context,
4776
- __errors: validationResult.errors
4777
- });
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") {
4778
4871
  return {
4779
4872
  errored: true,
4780
4873
  __error: "Input context validation failed",
@@ -4791,19 +4884,27 @@ var Task = class _Task extends SignalEmitter {
4791
4884
  * @return {true | AnyObject} Returns `true` if the output context is valid; otherwise, returns an object
4792
4885
  * containing error information when validation fails.
4793
4886
  */
4794
- validateOutput(context) {
4795
- if (this.validateOutputContext) {
4796
- const validationResult = this.validateSchema(
4797
- context,
4798
- this.outputContextSchema
4799
- );
4800
- if (!validationResult.valid) {
4801
- this.emitWithMetadata("meta.task.output_validation_failed", {
4802
- __taskName: this.name,
4803
- __taskVersion: this.version,
4804
- __result: context,
4805
- __errors: validationResult.errors
4806
- });
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") {
4807
4908
  return {
4808
4909
  errored: true,
4809
4910
  __error: "Output context validation failed",
@@ -5194,6 +5295,7 @@ var Task = class _Task extends SignalEmitter {
5194
5295
  intentName,
5195
5296
  intent.input
5196
5297
  );
5298
+ this.hasExplicitInputContextSchema = true;
5197
5299
  }
5198
5300
  if (intent?.output) {
5199
5301
  this.outputContextSchema = this.mergeSchemaVariant(
@@ -5201,6 +5303,7 @@ var Task = class _Task extends SignalEmitter {
5201
5303
  intentName,
5202
5304
  intent.output
5203
5305
  );
5306
+ this.hasExplicitOutputContextSchema = true;
5204
5307
  }
5205
5308
  }
5206
5309
  return this;
@@ -6904,6 +7007,146 @@ var Cadenza = class {
6904
7007
  static async inquire(inquiry, context, options) {
6905
7008
  return this.inquiryBroker?.inquire(inquiry, context, options);
6906
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
+ }
6907
7150
  /**
6908
7151
  * Creates an in-memory actor runtime instance.
6909
7152
  *
@@ -7503,11 +7746,18 @@ var Cadenza = class {
7503
7746
  this.registry?.reset();
7504
7747
  this.taskCache.clear();
7505
7748
  this.actorCache.clear();
7749
+ this.runtimeInquiryDelegate = void 0;
7750
+ this.runtimeValidationPolicy = {};
7751
+ this.runtimeValidationScopes.clear();
7752
+ this.emittedMissingSchemaWarnings.clear();
7506
7753
  this.isBootstrapped = false;
7507
7754
  }
7508
7755
  };
7509
7756
  Cadenza.taskCache = /* @__PURE__ */ new Map();
7510
7757
  Cadenza.actorCache = /* @__PURE__ */ new Map();
7758
+ Cadenza.runtimeValidationPolicy = {};
7759
+ Cadenza.runtimeValidationScopes = /* @__PURE__ */ new Map();
7760
+ Cadenza.emittedMissingSchemaWarnings = /* @__PURE__ */ new Set();
7511
7761
  Cadenza.isBootstrapped = false;
7512
7762
  Cadenza.mode = "production";
7513
7763