@cadenza.io/core 3.20.0 → 3.21.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
@@ -352,7 +352,9 @@ interface Intent {
352
352
  output?: SchemaDefinition;
353
353
  }
354
354
  interface InquiryOptions {
355
- timeout: number;
355
+ timeout?: number;
356
+ rejectOnTimeout?: boolean;
357
+ includePendingTasks?: boolean;
356
358
  }
357
359
  declare class InquiryBroker extends SignalEmitter {
358
360
  static instance_: InquiryBroker;
@@ -394,6 +396,7 @@ declare class InquiryBroker extends SignalEmitter {
394
396
  addInquiry(inquiry: string): void;
395
397
  addIntent(intent: Intent): void;
396
398
  inquire(inquiry: string, context: AnyObject, options?: InquiryOptions): Promise<AnyObject>;
399
+ reset(): void;
397
400
  }
398
401
 
399
402
  /**
@@ -1546,12 +1549,15 @@ declare class SignalBroker {
1546
1549
  private flushGroup;
1547
1550
  private flushStrategy;
1548
1551
  clearSquashState(): void;
1552
+ private clearScheduledState;
1549
1553
  private scheduledBuckets;
1550
1554
  private scheduleTimer;
1551
1555
  schedule(signal: string, context: AnyObject, options?: EmitOptions): AbortController;
1552
1556
  private flushScheduled;
1553
1557
  private debouncedEmitters;
1554
1558
  private readonly MAX_DEBOUNCERS;
1559
+ private clearDebounceState;
1560
+ private clearThrottleState;
1555
1561
  debounce(signal: string, context: any, options?: {
1556
1562
  delayMs: number;
1557
1563
  }): void;
@@ -1799,6 +1805,253 @@ declare class GraphStandardRun extends GraphRunStrategy {
1799
1805
  export(): any;
1800
1806
  }
1801
1807
 
1808
+ type ActorLoadPolicy = "eager" | "lazy";
1809
+ type ActorWriteContract = "overwrite" | "patch" | "reducer";
1810
+ type ActorTaskMode = "read" | "write" | "meta";
1811
+ type ActorKind = "standard" | "meta";
1812
+ type ActorRuntimeReadGuard = "none" | "freeze-shallow";
1813
+ type ActorConsistencyProfileName = "strict" | "balanced" | "cached" | "async";
1814
+ interface ActorInvocationOptions {
1815
+ actorKey?: string;
1816
+ idempotencyKey?: string;
1817
+ }
1818
+ interface SessionPolicy {
1819
+ enabled?: boolean;
1820
+ idleTtlMs?: number;
1821
+ absoluteTtlMs?: number;
1822
+ extendIdleTtlOnRead?: boolean;
1823
+ }
1824
+ interface RetryPolicy {
1825
+ attempts?: number;
1826
+ delayMs?: number;
1827
+ maxDelayMs?: number;
1828
+ factor?: number;
1829
+ }
1830
+ interface IdempotencyPolicy {
1831
+ enabled?: boolean;
1832
+ mode?: "required" | "optional";
1833
+ rerunOnFailedDuplicate?: boolean;
1834
+ ttlMs?: number;
1835
+ }
1836
+ type ActorKeyDefinition = {
1837
+ source: "path";
1838
+ path: string;
1839
+ } | {
1840
+ source: "field";
1841
+ field: string;
1842
+ } | {
1843
+ source: "template";
1844
+ template: string;
1845
+ };
1846
+ interface ActorTaskBindingDefinition {
1847
+ taskName: string;
1848
+ mode?: ActorTaskMode;
1849
+ description?: string;
1850
+ }
1851
+ interface ActorStateDefinition<D extends Record<string, any>, R = AnyObject> {
1852
+ durable?: {
1853
+ initialState?: D | (() => D);
1854
+ schema?: AnyObject;
1855
+ description?: string;
1856
+ };
1857
+ runtime?: {
1858
+ initialState?: R | (() => R);
1859
+ schema?: AnyObject;
1860
+ description?: string;
1861
+ factoryToken?: string;
1862
+ factoryConfig?: AnyObject;
1863
+ };
1864
+ }
1865
+ interface ActorLifecycleDefinition {
1866
+ initTaskName?: string;
1867
+ initRoutineName?: string;
1868
+ initHandlerToken?: string;
1869
+ }
1870
+ interface ActorDefinition<D extends Record<string, any>, R = AnyObject> {
1871
+ name: string;
1872
+ description: string;
1873
+ defaultKey: string;
1874
+ kind?: ActorKind;
1875
+ loadPolicy?: ActorLoadPolicy;
1876
+ writeContract?: ActorWriteContract;
1877
+ consistencyProfile?: ActorConsistencyProfileName;
1878
+ retry?: RetryPolicy;
1879
+ idempotency?: IdempotencyPolicy;
1880
+ session?: SessionPolicy;
1881
+ runtimeReadGuard?: ActorRuntimeReadGuard;
1882
+ key?: ActorKeyDefinition;
1883
+ state?: ActorStateDefinition<D, R>;
1884
+ lifecycle?: ActorLifecycleDefinition;
1885
+ tasks?: ActorTaskBindingDefinition[];
1886
+ }
1887
+ interface ActorSpec<D extends Record<string, any>, R = AnyObject> {
1888
+ name: string;
1889
+ description?: string;
1890
+ state?: ActorStateDefinition<D, R>;
1891
+ initialState?: D | (() => D);
1892
+ initialDurableState?: D | (() => D);
1893
+ initialRuntimeState?: R | (() => R);
1894
+ defaultKey: string;
1895
+ init?: ActorInitHandler<D, R>;
1896
+ key?: ActorKeyDefinition;
1897
+ keyResolver?: (input: Record<string, any>) => string | undefined;
1898
+ loadPolicy?: ActorLoadPolicy;
1899
+ writeContract?: ActorWriteContract;
1900
+ kind?: ActorKind;
1901
+ retry?: RetryPolicy;
1902
+ idempotency?: IdempotencyPolicy;
1903
+ session?: SessionPolicy;
1904
+ consistencyProfile?: ActorConsistencyProfileName;
1905
+ runtimeReadGuard?: ActorRuntimeReadGuard;
1906
+ taskBindings?: ActorTaskBindingDefinition[];
1907
+ lifecycle?: ActorLifecycleDefinition;
1908
+ }
1909
+ interface ActorFactoryOptions<D extends Record<string, any> = Record<string, any>, R = AnyObject> {
1910
+ isMeta?: boolean;
1911
+ definitionSource?: ActorDefinition<D, R>;
1912
+ }
1913
+ interface ActorTaskBindingOptions {
1914
+ mode?: ActorTaskMode;
1915
+ touchSession?: boolean;
1916
+ }
1917
+ type ActorStateReducer<S> = (state: S, input: AnyObject) => S;
1918
+ interface ActorResolvedInvocationOptions {
1919
+ actorKey?: string;
1920
+ loadPolicy: ActorLoadPolicy;
1921
+ writeContract: ActorWriteContract;
1922
+ consistencyProfile?: ActorConsistencyProfileName;
1923
+ idempotencyKey?: string;
1924
+ touchSession: boolean;
1925
+ }
1926
+ interface ActorStateMutators<D extends Record<string, any>, R = AnyObject> {
1927
+ setDurable: (next: D | ActorStateReducer<D>) => void;
1928
+ patchDurable: (partial: Partial<D>) => void;
1929
+ reduceDurable: (reducer: ActorStateReducer<D>) => void;
1930
+ setRuntime: (next: R | ActorStateReducer<R>) => void;
1931
+ patchRuntime: (partial: Partial<R>) => void;
1932
+ reduceRuntime: (reducer: ActorStateReducer<R>) => void;
1933
+ }
1934
+ interface ActorStateStore<D extends Record<string, any>, R = AnyObject> extends ActorStateMutators<D, R> {
1935
+ durable: D;
1936
+ runtime: R;
1937
+ version: number;
1938
+ durableVersion: number;
1939
+ runtimeVersion: number;
1940
+ }
1941
+ interface ActorInitStateStore<D extends Record<string, any>, R = AnyObject> extends ActorStateMutators<D, R> {
1942
+ durable: D;
1943
+ runtime: R;
1944
+ }
1945
+ interface ActorTaskContext<D extends Record<string, any>, R = AnyObject> {
1946
+ state: D;
1947
+ durableState: D;
1948
+ runtimeState: R;
1949
+ store: ActorStateStore<D, R>;
1950
+ input: AnyObject;
1951
+ actor: {
1952
+ name: string;
1953
+ description?: string;
1954
+ key: string;
1955
+ version: number;
1956
+ durableVersion: number;
1957
+ runtimeVersion: number;
1958
+ kind: ActorKind;
1959
+ };
1960
+ options: ActorResolvedInvocationOptions;
1961
+ setState: (next: D | ActorStateReducer<D>) => void;
1962
+ patchState: (partial: Partial<D>) => void;
1963
+ reduceState: (reducer: ActorStateReducer<D>) => void;
1964
+ setDurableState: (next: D | ActorStateReducer<D>) => void;
1965
+ patchDurableState: (partial: Partial<D>) => void;
1966
+ reduceDurableState: (reducer: ActorStateReducer<D>) => void;
1967
+ setRuntimeState: (next: R | ActorStateReducer<R>) => void;
1968
+ patchRuntimeState: (partial: Partial<R>) => void;
1969
+ reduceRuntimeState: (reducer: ActorStateReducer<R>) => void;
1970
+ emit: (signal: string, payload?: AnyObject) => void;
1971
+ inquire: (inquiry: string, context?: AnyObject, options?: InquiryOptions) => Promise<AnyObject>;
1972
+ }
1973
+ type ActorTaskHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorTaskContext<D, R>) => TaskResult | ActorStateReducer<D> | Promise<TaskResult | ActorStateReducer<D>>;
1974
+ interface ActorInitResult<D extends Record<string, any>, R = AnyObject> {
1975
+ state?: D;
1976
+ durableState?: D;
1977
+ runtimeState?: R;
1978
+ }
1979
+ interface ActorInitContext<D extends Record<string, any>, R = AnyObject> {
1980
+ baseState: D;
1981
+ durableBaseState: D;
1982
+ runtimeBaseState: R;
1983
+ store: ActorInitStateStore<D, R>;
1984
+ input: AnyObject;
1985
+ actor: {
1986
+ name: string;
1987
+ description?: string;
1988
+ key: string;
1989
+ kind: ActorKind;
1990
+ };
1991
+ options: ActorResolvedInvocationOptions;
1992
+ setState: (next: D | ActorStateReducer<D>) => void;
1993
+ patchState: (partial: Partial<D>) => void;
1994
+ reduceState: (reducer: ActorStateReducer<D>) => void;
1995
+ setDurableState: (next: D | ActorStateReducer<D>) => void;
1996
+ patchDurableState: (partial: Partial<D>) => void;
1997
+ reduceDurableState: (reducer: ActorStateReducer<D>) => void;
1998
+ setRuntimeState: (next: R | ActorStateReducer<R>) => void;
1999
+ patchRuntimeState: (partial: Partial<R>) => void;
2000
+ reduceRuntimeState: (reducer: ActorStateReducer<R>) => void;
2001
+ }
2002
+ type ActorInitHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorInitContext<D, R>) => D | ActorInitResult<D, R> | void | Promise<D | ActorInitResult<D, R> | void>;
2003
+ interface ActorRuntimeFactoryContext<D extends Record<string, any> = Record<string, any>, R = AnyObject> {
2004
+ definition: ActorDefinition<D, R>;
2005
+ actor: {
2006
+ name: string;
2007
+ key: string;
2008
+ kind: ActorKind;
2009
+ };
2010
+ input: AnyObject;
2011
+ config?: AnyObject;
2012
+ }
2013
+ type ActorRuntimeFactory<R = AnyObject, D extends Record<string, any> = Record<string, any>> = (context: ActorRuntimeFactoryContext<D, R>) => R | Promise<R>;
2014
+ interface ActorDefinitionFactoryOptions<D extends Record<string, any> = Record<string, any>, R = AnyObject> {
2015
+ isMeta?: boolean;
2016
+ runtimeFactories?: Record<string, ActorRuntimeFactory<R, D>>;
2017
+ initHandlers?: Record<string, ActorInitHandler<D, R>>;
2018
+ }
2019
+ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2020
+ readonly spec: ActorSpec<D, R>;
2021
+ readonly kind: ActorKind;
2022
+ private readonly sourceDefinition?;
2023
+ private readonly stateByKey;
2024
+ private readonly sessionByKey;
2025
+ private readonly idempotencyByKey;
2026
+ private readonly initializedKeys;
2027
+ private readonly initializationByKey;
2028
+ private nextTaskBindingIndex;
2029
+ constructor(spec: ActorSpec<D, R>, options?: ActorFactoryOptions<D, R>);
2030
+ task(handler: ActorTaskHandler<D, R>, bindingOptions?: ActorTaskBindingOptions): TaskFunction;
2031
+ getState(actorKey?: string): D;
2032
+ getDurableState(actorKey?: string): D;
2033
+ getRuntimeState(actorKey?: string): R;
2034
+ getVersion(actorKey?: string): number;
2035
+ getDurableVersion(actorKey?: string): number;
2036
+ getRuntimeVersion(actorKey?: string): number;
2037
+ toDefinition(): ActorDefinition<D, R>;
2038
+ reset(actorKey?: string): void;
2039
+ private applyRuntimeReadGuard;
2040
+ private buildDefaultInvocationOptions;
2041
+ private primeInitialization;
2042
+ private normalizeInputContext;
2043
+ private resolveInvocationOptions;
2044
+ private resolveActorKey;
2045
+ private resolveActorKeyFromDefinition;
2046
+ private resolveInitialDurableState;
2047
+ private resolveInitialRuntimeState;
2048
+ private ensureStateRecord;
2049
+ private ensureInitialized;
2050
+ private touchSession;
2051
+ private runWithOptionalIdempotency;
2052
+ private getActiveIdempotencyRecord;
2053
+ }
2054
+
1802
2055
  interface TaskOptions {
1803
2056
  concurrency?: number;
1804
2057
  timeout?: number;
@@ -1829,6 +2082,7 @@ declare class Cadenza {
1829
2082
  static runner: GraphRunner;
1830
2083
  static metaRunner: GraphRunner;
1831
2084
  static registry: GraphRegistry;
2085
+ private static taskCache;
1832
2086
  static isBootstrapped: boolean;
1833
2087
  static mode: CadenzaMode;
1834
2088
  /**
@@ -1868,6 +2122,9 @@ declare class Cadenza {
1868
2122
  * @throws {Error} If the name is not a non-empty string.
1869
2123
  */
1870
2124
  static validateName(name: string): void;
2125
+ private static resolveTaskOptionsForActorTask;
2126
+ private static applyActorInitResult;
2127
+ private static createActorInitHandlerFromDefinition;
1871
2128
  /**
1872
2129
  * Executes the specified task or GraphRoutine with the given context using an internal runner.
1873
2130
  *
@@ -1912,6 +2169,8 @@ declare class Cadenza {
1912
2169
  static getRoutine(routineName: string): GraphRoutine | undefined;
1913
2170
  static defineIntent(intent: Intent): Intent;
1914
2171
  static inquire(inquiry: string, context: AnyObject, options?: InquiryOptions): Promise<any>;
2172
+ static createActor<D extends Record<string, any> = AnyObject, R = AnyObject>(spec: ActorSpec<D, R>, options?: ActorFactoryOptions): Actor<D, R>;
2173
+ static createActorFromDefinition<D extends Record<string, any> = AnyObject, R = AnyObject>(definition: ActorDefinition<D, R>, options?: ActorDefinitionFactoryOptions<D, R>): Actor<D, R>;
1915
2174
  /**
1916
2175
  * Creates and registers a new task with the specified parameters and options.
1917
2176
  * Tasks are the basic building blocks of Cadenza graphs and are responsible for executing logic.
@@ -2263,4 +2522,4 @@ declare class Cadenza {
2263
2522
  static reset(): void;
2264
2523
  }
2265
2524
 
2266
- export { type AnyObject, type CadenzaMode, type DebounceOptions, DebounceTask, type EmitOptions, EphemeralTask, type EphemeralTaskOptions, GraphContext, GraphRegistry, GraphRoutine, GraphRun, GraphRunner, InquiryBroker, type InquiryOptions, type Intent, type Schema, type SchemaConstraints, type SchemaDefinition, type SchemaType, SignalBroker, SignalEmitter, Task, type TaskFunction, type TaskOptions, type TaskResult, type ThrottleTagGetter, Cadenza as default };
2525
+ export { Actor, type ActorConsistencyProfileName, type ActorDefinition, type ActorDefinitionFactoryOptions, type ActorFactoryOptions, type ActorInitContext, type ActorInitHandler, type ActorInitResult, type ActorInitStateStore, type ActorInvocationOptions, type ActorKeyDefinition, type ActorKind, type ActorLifecycleDefinition, type ActorLoadPolicy, type ActorRuntimeFactory, type ActorRuntimeFactoryContext, type ActorRuntimeReadGuard, type ActorSpec, type ActorStateDefinition, type ActorStateReducer, type ActorStateStore, type ActorTaskBindingDefinition, type ActorTaskBindingOptions, type ActorTaskContext, type ActorTaskHandler, type ActorTaskMode, 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 };
package/dist/index.d.ts CHANGED
@@ -352,7 +352,9 @@ interface Intent {
352
352
  output?: SchemaDefinition;
353
353
  }
354
354
  interface InquiryOptions {
355
- timeout: number;
355
+ timeout?: number;
356
+ rejectOnTimeout?: boolean;
357
+ includePendingTasks?: boolean;
356
358
  }
357
359
  declare class InquiryBroker extends SignalEmitter {
358
360
  static instance_: InquiryBroker;
@@ -394,6 +396,7 @@ declare class InquiryBroker extends SignalEmitter {
394
396
  addInquiry(inquiry: string): void;
395
397
  addIntent(intent: Intent): void;
396
398
  inquire(inquiry: string, context: AnyObject, options?: InquiryOptions): Promise<AnyObject>;
399
+ reset(): void;
397
400
  }
398
401
 
399
402
  /**
@@ -1546,12 +1549,15 @@ declare class SignalBroker {
1546
1549
  private flushGroup;
1547
1550
  private flushStrategy;
1548
1551
  clearSquashState(): void;
1552
+ private clearScheduledState;
1549
1553
  private scheduledBuckets;
1550
1554
  private scheduleTimer;
1551
1555
  schedule(signal: string, context: AnyObject, options?: EmitOptions): AbortController;
1552
1556
  private flushScheduled;
1553
1557
  private debouncedEmitters;
1554
1558
  private readonly MAX_DEBOUNCERS;
1559
+ private clearDebounceState;
1560
+ private clearThrottleState;
1555
1561
  debounce(signal: string, context: any, options?: {
1556
1562
  delayMs: number;
1557
1563
  }): void;
@@ -1799,6 +1805,253 @@ declare class GraphStandardRun extends GraphRunStrategy {
1799
1805
  export(): any;
1800
1806
  }
1801
1807
 
1808
+ type ActorLoadPolicy = "eager" | "lazy";
1809
+ type ActorWriteContract = "overwrite" | "patch" | "reducer";
1810
+ type ActorTaskMode = "read" | "write" | "meta";
1811
+ type ActorKind = "standard" | "meta";
1812
+ type ActorRuntimeReadGuard = "none" | "freeze-shallow";
1813
+ type ActorConsistencyProfileName = "strict" | "balanced" | "cached" | "async";
1814
+ interface ActorInvocationOptions {
1815
+ actorKey?: string;
1816
+ idempotencyKey?: string;
1817
+ }
1818
+ interface SessionPolicy {
1819
+ enabled?: boolean;
1820
+ idleTtlMs?: number;
1821
+ absoluteTtlMs?: number;
1822
+ extendIdleTtlOnRead?: boolean;
1823
+ }
1824
+ interface RetryPolicy {
1825
+ attempts?: number;
1826
+ delayMs?: number;
1827
+ maxDelayMs?: number;
1828
+ factor?: number;
1829
+ }
1830
+ interface IdempotencyPolicy {
1831
+ enabled?: boolean;
1832
+ mode?: "required" | "optional";
1833
+ rerunOnFailedDuplicate?: boolean;
1834
+ ttlMs?: number;
1835
+ }
1836
+ type ActorKeyDefinition = {
1837
+ source: "path";
1838
+ path: string;
1839
+ } | {
1840
+ source: "field";
1841
+ field: string;
1842
+ } | {
1843
+ source: "template";
1844
+ template: string;
1845
+ };
1846
+ interface ActorTaskBindingDefinition {
1847
+ taskName: string;
1848
+ mode?: ActorTaskMode;
1849
+ description?: string;
1850
+ }
1851
+ interface ActorStateDefinition<D extends Record<string, any>, R = AnyObject> {
1852
+ durable?: {
1853
+ initialState?: D | (() => D);
1854
+ schema?: AnyObject;
1855
+ description?: string;
1856
+ };
1857
+ runtime?: {
1858
+ initialState?: R | (() => R);
1859
+ schema?: AnyObject;
1860
+ description?: string;
1861
+ factoryToken?: string;
1862
+ factoryConfig?: AnyObject;
1863
+ };
1864
+ }
1865
+ interface ActorLifecycleDefinition {
1866
+ initTaskName?: string;
1867
+ initRoutineName?: string;
1868
+ initHandlerToken?: string;
1869
+ }
1870
+ interface ActorDefinition<D extends Record<string, any>, R = AnyObject> {
1871
+ name: string;
1872
+ description: string;
1873
+ defaultKey: string;
1874
+ kind?: ActorKind;
1875
+ loadPolicy?: ActorLoadPolicy;
1876
+ writeContract?: ActorWriteContract;
1877
+ consistencyProfile?: ActorConsistencyProfileName;
1878
+ retry?: RetryPolicy;
1879
+ idempotency?: IdempotencyPolicy;
1880
+ session?: SessionPolicy;
1881
+ runtimeReadGuard?: ActorRuntimeReadGuard;
1882
+ key?: ActorKeyDefinition;
1883
+ state?: ActorStateDefinition<D, R>;
1884
+ lifecycle?: ActorLifecycleDefinition;
1885
+ tasks?: ActorTaskBindingDefinition[];
1886
+ }
1887
+ interface ActorSpec<D extends Record<string, any>, R = AnyObject> {
1888
+ name: string;
1889
+ description?: string;
1890
+ state?: ActorStateDefinition<D, R>;
1891
+ initialState?: D | (() => D);
1892
+ initialDurableState?: D | (() => D);
1893
+ initialRuntimeState?: R | (() => R);
1894
+ defaultKey: string;
1895
+ init?: ActorInitHandler<D, R>;
1896
+ key?: ActorKeyDefinition;
1897
+ keyResolver?: (input: Record<string, any>) => string | undefined;
1898
+ loadPolicy?: ActorLoadPolicy;
1899
+ writeContract?: ActorWriteContract;
1900
+ kind?: ActorKind;
1901
+ retry?: RetryPolicy;
1902
+ idempotency?: IdempotencyPolicy;
1903
+ session?: SessionPolicy;
1904
+ consistencyProfile?: ActorConsistencyProfileName;
1905
+ runtimeReadGuard?: ActorRuntimeReadGuard;
1906
+ taskBindings?: ActorTaskBindingDefinition[];
1907
+ lifecycle?: ActorLifecycleDefinition;
1908
+ }
1909
+ interface ActorFactoryOptions<D extends Record<string, any> = Record<string, any>, R = AnyObject> {
1910
+ isMeta?: boolean;
1911
+ definitionSource?: ActorDefinition<D, R>;
1912
+ }
1913
+ interface ActorTaskBindingOptions {
1914
+ mode?: ActorTaskMode;
1915
+ touchSession?: boolean;
1916
+ }
1917
+ type ActorStateReducer<S> = (state: S, input: AnyObject) => S;
1918
+ interface ActorResolvedInvocationOptions {
1919
+ actorKey?: string;
1920
+ loadPolicy: ActorLoadPolicy;
1921
+ writeContract: ActorWriteContract;
1922
+ consistencyProfile?: ActorConsistencyProfileName;
1923
+ idempotencyKey?: string;
1924
+ touchSession: boolean;
1925
+ }
1926
+ interface ActorStateMutators<D extends Record<string, any>, R = AnyObject> {
1927
+ setDurable: (next: D | ActorStateReducer<D>) => void;
1928
+ patchDurable: (partial: Partial<D>) => void;
1929
+ reduceDurable: (reducer: ActorStateReducer<D>) => void;
1930
+ setRuntime: (next: R | ActorStateReducer<R>) => void;
1931
+ patchRuntime: (partial: Partial<R>) => void;
1932
+ reduceRuntime: (reducer: ActorStateReducer<R>) => void;
1933
+ }
1934
+ interface ActorStateStore<D extends Record<string, any>, R = AnyObject> extends ActorStateMutators<D, R> {
1935
+ durable: D;
1936
+ runtime: R;
1937
+ version: number;
1938
+ durableVersion: number;
1939
+ runtimeVersion: number;
1940
+ }
1941
+ interface ActorInitStateStore<D extends Record<string, any>, R = AnyObject> extends ActorStateMutators<D, R> {
1942
+ durable: D;
1943
+ runtime: R;
1944
+ }
1945
+ interface ActorTaskContext<D extends Record<string, any>, R = AnyObject> {
1946
+ state: D;
1947
+ durableState: D;
1948
+ runtimeState: R;
1949
+ store: ActorStateStore<D, R>;
1950
+ input: AnyObject;
1951
+ actor: {
1952
+ name: string;
1953
+ description?: string;
1954
+ key: string;
1955
+ version: number;
1956
+ durableVersion: number;
1957
+ runtimeVersion: number;
1958
+ kind: ActorKind;
1959
+ };
1960
+ options: ActorResolvedInvocationOptions;
1961
+ setState: (next: D | ActorStateReducer<D>) => void;
1962
+ patchState: (partial: Partial<D>) => void;
1963
+ reduceState: (reducer: ActorStateReducer<D>) => void;
1964
+ setDurableState: (next: D | ActorStateReducer<D>) => void;
1965
+ patchDurableState: (partial: Partial<D>) => void;
1966
+ reduceDurableState: (reducer: ActorStateReducer<D>) => void;
1967
+ setRuntimeState: (next: R | ActorStateReducer<R>) => void;
1968
+ patchRuntimeState: (partial: Partial<R>) => void;
1969
+ reduceRuntimeState: (reducer: ActorStateReducer<R>) => void;
1970
+ emit: (signal: string, payload?: AnyObject) => void;
1971
+ inquire: (inquiry: string, context?: AnyObject, options?: InquiryOptions) => Promise<AnyObject>;
1972
+ }
1973
+ type ActorTaskHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorTaskContext<D, R>) => TaskResult | ActorStateReducer<D> | Promise<TaskResult | ActorStateReducer<D>>;
1974
+ interface ActorInitResult<D extends Record<string, any>, R = AnyObject> {
1975
+ state?: D;
1976
+ durableState?: D;
1977
+ runtimeState?: R;
1978
+ }
1979
+ interface ActorInitContext<D extends Record<string, any>, R = AnyObject> {
1980
+ baseState: D;
1981
+ durableBaseState: D;
1982
+ runtimeBaseState: R;
1983
+ store: ActorInitStateStore<D, R>;
1984
+ input: AnyObject;
1985
+ actor: {
1986
+ name: string;
1987
+ description?: string;
1988
+ key: string;
1989
+ kind: ActorKind;
1990
+ };
1991
+ options: ActorResolvedInvocationOptions;
1992
+ setState: (next: D | ActorStateReducer<D>) => void;
1993
+ patchState: (partial: Partial<D>) => void;
1994
+ reduceState: (reducer: ActorStateReducer<D>) => void;
1995
+ setDurableState: (next: D | ActorStateReducer<D>) => void;
1996
+ patchDurableState: (partial: Partial<D>) => void;
1997
+ reduceDurableState: (reducer: ActorStateReducer<D>) => void;
1998
+ setRuntimeState: (next: R | ActorStateReducer<R>) => void;
1999
+ patchRuntimeState: (partial: Partial<R>) => void;
2000
+ reduceRuntimeState: (reducer: ActorStateReducer<R>) => void;
2001
+ }
2002
+ type ActorInitHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorInitContext<D, R>) => D | ActorInitResult<D, R> | void | Promise<D | ActorInitResult<D, R> | void>;
2003
+ interface ActorRuntimeFactoryContext<D extends Record<string, any> = Record<string, any>, R = AnyObject> {
2004
+ definition: ActorDefinition<D, R>;
2005
+ actor: {
2006
+ name: string;
2007
+ key: string;
2008
+ kind: ActorKind;
2009
+ };
2010
+ input: AnyObject;
2011
+ config?: AnyObject;
2012
+ }
2013
+ type ActorRuntimeFactory<R = AnyObject, D extends Record<string, any> = Record<string, any>> = (context: ActorRuntimeFactoryContext<D, R>) => R | Promise<R>;
2014
+ interface ActorDefinitionFactoryOptions<D extends Record<string, any> = Record<string, any>, R = AnyObject> {
2015
+ isMeta?: boolean;
2016
+ runtimeFactories?: Record<string, ActorRuntimeFactory<R, D>>;
2017
+ initHandlers?: Record<string, ActorInitHandler<D, R>>;
2018
+ }
2019
+ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2020
+ readonly spec: ActorSpec<D, R>;
2021
+ readonly kind: ActorKind;
2022
+ private readonly sourceDefinition?;
2023
+ private readonly stateByKey;
2024
+ private readonly sessionByKey;
2025
+ private readonly idempotencyByKey;
2026
+ private readonly initializedKeys;
2027
+ private readonly initializationByKey;
2028
+ private nextTaskBindingIndex;
2029
+ constructor(spec: ActorSpec<D, R>, options?: ActorFactoryOptions<D, R>);
2030
+ task(handler: ActorTaskHandler<D, R>, bindingOptions?: ActorTaskBindingOptions): TaskFunction;
2031
+ getState(actorKey?: string): D;
2032
+ getDurableState(actorKey?: string): D;
2033
+ getRuntimeState(actorKey?: string): R;
2034
+ getVersion(actorKey?: string): number;
2035
+ getDurableVersion(actorKey?: string): number;
2036
+ getRuntimeVersion(actorKey?: string): number;
2037
+ toDefinition(): ActorDefinition<D, R>;
2038
+ reset(actorKey?: string): void;
2039
+ private applyRuntimeReadGuard;
2040
+ private buildDefaultInvocationOptions;
2041
+ private primeInitialization;
2042
+ private normalizeInputContext;
2043
+ private resolveInvocationOptions;
2044
+ private resolveActorKey;
2045
+ private resolveActorKeyFromDefinition;
2046
+ private resolveInitialDurableState;
2047
+ private resolveInitialRuntimeState;
2048
+ private ensureStateRecord;
2049
+ private ensureInitialized;
2050
+ private touchSession;
2051
+ private runWithOptionalIdempotency;
2052
+ private getActiveIdempotencyRecord;
2053
+ }
2054
+
1802
2055
  interface TaskOptions {
1803
2056
  concurrency?: number;
1804
2057
  timeout?: number;
@@ -1829,6 +2082,7 @@ declare class Cadenza {
1829
2082
  static runner: GraphRunner;
1830
2083
  static metaRunner: GraphRunner;
1831
2084
  static registry: GraphRegistry;
2085
+ private static taskCache;
1832
2086
  static isBootstrapped: boolean;
1833
2087
  static mode: CadenzaMode;
1834
2088
  /**
@@ -1868,6 +2122,9 @@ declare class Cadenza {
1868
2122
  * @throws {Error} If the name is not a non-empty string.
1869
2123
  */
1870
2124
  static validateName(name: string): void;
2125
+ private static resolveTaskOptionsForActorTask;
2126
+ private static applyActorInitResult;
2127
+ private static createActorInitHandlerFromDefinition;
1871
2128
  /**
1872
2129
  * Executes the specified task or GraphRoutine with the given context using an internal runner.
1873
2130
  *
@@ -1912,6 +2169,8 @@ declare class Cadenza {
1912
2169
  static getRoutine(routineName: string): GraphRoutine | undefined;
1913
2170
  static defineIntent(intent: Intent): Intent;
1914
2171
  static inquire(inquiry: string, context: AnyObject, options?: InquiryOptions): Promise<any>;
2172
+ static createActor<D extends Record<string, any> = AnyObject, R = AnyObject>(spec: ActorSpec<D, R>, options?: ActorFactoryOptions): Actor<D, R>;
2173
+ static createActorFromDefinition<D extends Record<string, any> = AnyObject, R = AnyObject>(definition: ActorDefinition<D, R>, options?: ActorDefinitionFactoryOptions<D, R>): Actor<D, R>;
1915
2174
  /**
1916
2175
  * Creates and registers a new task with the specified parameters and options.
1917
2176
  * Tasks are the basic building blocks of Cadenza graphs and are responsible for executing logic.
@@ -2263,4 +2522,4 @@ declare class Cadenza {
2263
2522
  static reset(): void;
2264
2523
  }
2265
2524
 
2266
- export { type AnyObject, type CadenzaMode, type DebounceOptions, DebounceTask, type EmitOptions, EphemeralTask, type EphemeralTaskOptions, GraphContext, GraphRegistry, GraphRoutine, GraphRun, GraphRunner, InquiryBroker, type InquiryOptions, type Intent, type Schema, type SchemaConstraints, type SchemaDefinition, type SchemaType, SignalBroker, SignalEmitter, Task, type TaskFunction, type TaskOptions, type TaskResult, type ThrottleTagGetter, Cadenza as default };
2525
+ export { Actor, type ActorConsistencyProfileName, type ActorDefinition, type ActorDefinitionFactoryOptions, type ActorFactoryOptions, type ActorInitContext, type ActorInitHandler, type ActorInitResult, type ActorInitStateStore, type ActorInvocationOptions, type ActorKeyDefinition, type ActorKind, type ActorLifecycleDefinition, type ActorLoadPolicy, type ActorRuntimeFactory, type ActorRuntimeFactoryContext, type ActorRuntimeReadGuard, type ActorSpec, type ActorStateDefinition, type ActorStateReducer, type ActorStateStore, type ActorTaskBindingDefinition, type ActorTaskBindingOptions, type ActorTaskContext, type ActorTaskHandler, type ActorTaskMode, 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 };