@cadenza.io/core 3.23.0 → 3.24.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
@@ -1854,6 +1854,8 @@ interface SessionPolicy {
1854
1854
  idleTtlMs?: number;
1855
1855
  absoluteTtlMs?: number;
1856
1856
  extendIdleTtlOnRead?: boolean;
1857
+ persistDurableState?: boolean;
1858
+ persistenceTimeoutMs?: number;
1857
1859
  }
1858
1860
  /**
1859
1861
  * Task retry policy metadata for actor definitions/specs.
@@ -2056,6 +2058,7 @@ interface ActorTaskRuntimeMetadata {
2056
2058
  mode: ActorTaskMode;
2057
2059
  forceMeta: boolean;
2058
2060
  }
2061
+ declare const META_ACTOR_SESSION_STATE_PERSIST_INTENT = "meta-actor-session-state-persist";
2059
2062
  /**
2060
2063
  * Reads actor metadata from a wrapped task function if available.
2061
2064
  */
@@ -2126,6 +2129,7 @@ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2126
2129
  private touchSession;
2127
2130
  private runWithOptionalIdempotency;
2128
2131
  private getActiveIdempotencyRecord;
2132
+ private persistDurableStateIfConfigured;
2129
2133
  private emitActorCreatedSignal;
2130
2134
  }
2131
2135
 
@@ -2613,4 +2617,4 @@ declare class Cadenza {
2613
2617
  static reset(): void;
2614
2618
  }
2615
2619
 
2616
- 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, 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 };
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 };
package/dist/index.d.ts CHANGED
@@ -1854,6 +1854,8 @@ interface SessionPolicy {
1854
1854
  idleTtlMs?: number;
1855
1855
  absoluteTtlMs?: number;
1856
1856
  extendIdleTtlOnRead?: boolean;
1857
+ persistDurableState?: boolean;
1858
+ persistenceTimeoutMs?: number;
1857
1859
  }
1858
1860
  /**
1859
1861
  * Task retry policy metadata for actor definitions/specs.
@@ -2056,6 +2058,7 @@ interface ActorTaskRuntimeMetadata {
2056
2058
  mode: ActorTaskMode;
2057
2059
  forceMeta: boolean;
2058
2060
  }
2061
+ declare const META_ACTOR_SESSION_STATE_PERSIST_INTENT = "meta-actor-session-state-persist";
2059
2062
  /**
2060
2063
  * Reads actor metadata from a wrapped task function if available.
2061
2064
  */
@@ -2126,6 +2129,7 @@ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2126
2129
  private touchSession;
2127
2130
  private runWithOptionalIdempotency;
2128
2131
  private getActiveIdempotencyRecord;
2132
+ private persistDurableStateIfConfigured;
2129
2133
  private emitActorCreatedSignal;
2130
2134
  }
2131
2135
 
@@ -2613,4 +2617,4 @@ declare class Cadenza {
2613
2617
  static reset(): void;
2614
2618
  }
2615
2619
 
2616
- 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, 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 };
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 };
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,
@@ -3663,6 +3664,7 @@ var TaskIterator = class {
3663
3664
  // src/actors/Actor.ts
3664
3665
  var ACTOR_TASK_METADATA = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
3665
3666
  var ACTOR_INVOCATION_OPTIONS_KEY = "__actorOptions";
3667
+ var META_ACTOR_SESSION_STATE_PERSIST_INTENT = "meta-actor-session-state-persist";
3666
3668
  function deepClone(value) {
3667
3669
  if (value === void 0 || value === null || typeof value !== "object" || value instanceof Date) {
3668
3670
  return value;
@@ -3921,10 +3923,19 @@ var Actor = class {
3921
3923
  if (invocationOptions.writeContract === "reducer" && typeof handlerResult === "function") {
3922
3924
  reduceDurableState(handlerResult);
3923
3925
  }
3926
+ const nextDurableVersion = stateRecord.version + (durableStateChanged ? 1 : 0);
3927
+ if (durableStateChanged) {
3928
+ await this.persistDurableStateIfConfigured(
3929
+ actorKey,
3930
+ nextDurableState,
3931
+ nextDurableVersion,
3932
+ inquire
3933
+ );
3934
+ }
3924
3935
  const writeTimestamp = Date.now();
3925
3936
  if (durableStateChanged) {
3926
3937
  stateRecord.durableState = cloneForDurableState(nextDurableState);
3927
- stateRecord.version += 1;
3938
+ stateRecord.version = nextDurableVersion;
3928
3939
  stateRecord.lastDurableWriteAt = writeTimestamp;
3929
3940
  }
3930
3941
  if (runtimeStateChanged) {
@@ -4232,6 +4243,34 @@ var Actor = class {
4232
4243
  }
4233
4244
  return record;
4234
4245
  }
4246
+ async persistDurableStateIfConfigured(actorKey, durableState, durableVersion, inquire) {
4247
+ const shouldPersist = this.spec.session?.persistDurableState ?? false;
4248
+ if (!shouldPersist) {
4249
+ return;
4250
+ }
4251
+ const timeoutMs = normalizePositiveInteger(this.spec.session?.persistenceTimeoutMs) ?? 5e3;
4252
+ const response = await inquire(
4253
+ META_ACTOR_SESSION_STATE_PERSIST_INTENT,
4254
+ {
4255
+ actor_name: this.spec.name,
4256
+ actor_version: 1,
4257
+ actor_key: actorKey,
4258
+ durable_state: cloneForDurableState(durableState),
4259
+ durable_version: durableVersion,
4260
+ expires_at: null
4261
+ },
4262
+ {
4263
+ timeout: timeoutMs,
4264
+ rejectOnTimeout: true
4265
+ }
4266
+ );
4267
+ if (!isObject2(response) || response.__success !== true || response.persisted !== true) {
4268
+ const reason = isObject2(response) ? response.__error ?? response.error : void 0;
4269
+ throw new Error(
4270
+ `Actor "${this.spec.name}" durable state persistence failed for key "${actorKey}"${reason ? `: ${String(reason)}` : ""}`
4271
+ );
4272
+ }
4273
+ }
4235
4274
  emitActorCreatedSignal() {
4236
4275
  Cadenza.signalBroker.registerEmittedSignal("meta.actor.created");
4237
4276
  const definition = sanitizeActorMetadataValue(
@@ -7485,6 +7524,7 @@ var index_default = Cadenza;
7485
7524
  GraphRun,
7486
7525
  GraphRunner,
7487
7526
  InquiryBroker,
7527
+ META_ACTOR_SESSION_STATE_PERSIST_INTENT,
7488
7528
  SignalBroker,
7489
7529
  SignalEmitter,
7490
7530
  Task,