@cadenza.io/core 3.28.0 → 3.28.1

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
@@ -946,6 +946,9 @@ declare class GraphNode extends SignalEmitter implements Graph {
946
946
  * @return {string} The tag retrieved from the task within the given context.
947
947
  */
948
948
  getTag(): string;
949
+ private classifyBusinessRoutineLifecycle;
950
+ private getBusinessRoutineLifecycleDecision;
951
+ private rememberBusinessRoutineLifecycleDecision;
949
952
  /**
950
953
  * Schedules the current node/task on the specified graph layer if applicable.
951
954
  *
@@ -2123,7 +2126,7 @@ interface ActorTaskContext<D extends Record<string, any>, R = AnyObject> {
2123
2126
  /**
2124
2127
  * Handler signature used by `actor.task(...)`.
2125
2128
  */
2126
- type ActorTaskHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorTaskContext<D, R>) => TaskResult | ActorStateReducer<D> | Promise<TaskResult | ActorStateReducer<D>>;
2129
+ type ActorTaskHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorTaskContext<D, R>, emit: (signal: string, payload?: AnyObject) => void, inquire: (inquiry: string, context?: AnyObject, options?: InquiryOptions) => Promise<AnyObject>, tools: RuntimeTools, progressCallback: (progress: number) => void) => TaskResult | ActorStateReducer<D> | Promise<TaskResult | ActorStateReducer<D>>;
2127
2130
  interface ActorDurableStateHydration<D extends Record<string, any>> {
2128
2131
  durableState: D;
2129
2132
  durableVersion: number;
package/dist/index.d.ts CHANGED
@@ -946,6 +946,9 @@ declare class GraphNode extends SignalEmitter implements Graph {
946
946
  * @return {string} The tag retrieved from the task within the given context.
947
947
  */
948
948
  getTag(): string;
949
+ private classifyBusinessRoutineLifecycle;
950
+ private getBusinessRoutineLifecycleDecision;
951
+ private rememberBusinessRoutineLifecycleDecision;
949
952
  /**
950
953
  * Schedules the current node/task on the specified graph layer if applicable.
951
954
  *
@@ -2123,7 +2126,7 @@ interface ActorTaskContext<D extends Record<string, any>, R = AnyObject> {
2123
2126
  /**
2124
2127
  * Handler signature used by `actor.task(...)`.
2125
2128
  */
2126
- type ActorTaskHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorTaskContext<D, R>) => TaskResult | ActorStateReducer<D> | Promise<TaskResult | ActorStateReducer<D>>;
2129
+ type ActorTaskHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorTaskContext<D, R>, emit: (signal: string, payload?: AnyObject) => void, inquire: (inquiry: string, context?: AnyObject, options?: InquiryOptions) => Promise<AnyObject>, tools: RuntimeTools, progressCallback: (progress: number) => void) => TaskResult | ActorStateReducer<D> | Promise<TaskResult | ActorStateReducer<D>>;
2127
2130
  interface ActorDurableStateHydration<D extends Record<string, any>> {
2128
2131
  durableState: D;
2129
2132
  durableVersion: number;
package/dist/index.js CHANGED
@@ -2584,6 +2584,38 @@ var GraphNode = class _GraphNode extends SignalEmitter {
2584
2584
  getTag() {
2585
2585
  return this.task.getTag(this.context);
2586
2586
  }
2587
+ classifyBusinessRoutineLifecycle() {
2588
+ const fullContext = this.context?.getFullContext?.() ?? {};
2589
+ const metadata = fullContext.__metadata && typeof fullContext.__metadata === "object" ? fullContext.__metadata : {};
2590
+ if (this.task.isMeta || this.task.isSubMeta || this.task.isHidden) {
2591
+ return false;
2592
+ }
2593
+ if (fullContext.__isInquiry === true || fullContext.__isDeputy === true || metadata.__isInquiry === true || metadata.__isDeputy === true || metadata.__isSubMeta === true) {
2594
+ return false;
2595
+ }
2596
+ return true;
2597
+ }
2598
+ getBusinessRoutineLifecycleDecision() {
2599
+ const fullContext = this.context?.getFullContext?.() ?? {};
2600
+ const metadata = this.context?.getMetadata?.() ?? {};
2601
+ if (typeof metadata.__emitBusinessRoutineLifecycle === "boolean") {
2602
+ return metadata.__emitBusinessRoutineLifecycle;
2603
+ }
2604
+ if (typeof fullContext.__emitBusinessRoutineLifecycle === "boolean") {
2605
+ return fullContext.__emitBusinessRoutineLifecycle;
2606
+ }
2607
+ return this.classifyBusinessRoutineLifecycle();
2608
+ }
2609
+ rememberBusinessRoutineLifecycleDecision(value) {
2610
+ const fullContext = this.context?.getFullContext?.();
2611
+ const metadata = this.context?.getMetadata?.();
2612
+ if (fullContext && typeof fullContext === "object") {
2613
+ fullContext.__emitBusinessRoutineLifecycle = value;
2614
+ }
2615
+ if (metadata && typeof metadata === "object") {
2616
+ metadata.__emitBusinessRoutineLifecycle = value;
2617
+ }
2618
+ }
2587
2619
  /**
2588
2620
  * Schedules the current node/task on the specified graph layer if applicable.
2589
2621
  *
@@ -2709,17 +2741,23 @@ var GraphNode = class _GraphNode extends SignalEmitter {
2709
2741
  this.executionStart = Date.now();
2710
2742
  }
2711
2743
  if (this.previousNodes.length === 0) {
2712
- this.emitMetricsWithMetadata(
2713
- "meta.node.started_routine_execution",
2714
- {
2715
- data: {
2716
- isRunning: true,
2717
- started: formatTimestamp(this.executionStart)
2718
- },
2719
- filter: { uuid: this.routineExecId }
2720
- },
2721
- { squash: true, squashId: this.routineExecId }
2744
+ const shouldEmitBusinessRoutineLifecycle = this.getBusinessRoutineLifecycleDecision();
2745
+ this.rememberBusinessRoutineLifecycleDecision(
2746
+ shouldEmitBusinessRoutineLifecycle
2722
2747
  );
2748
+ if (shouldEmitBusinessRoutineLifecycle) {
2749
+ this.emitMetricsWithMetadata(
2750
+ "meta.node.started_routine_execution",
2751
+ {
2752
+ data: {
2753
+ isRunning: true,
2754
+ started: formatTimestamp(this.executionStart)
2755
+ },
2756
+ filter: { uuid: this.routineExecId }
2757
+ },
2758
+ { squash: true, squashId: this.routineExecId }
2759
+ );
2760
+ }
2723
2761
  }
2724
2762
  if (this.debug && !this.task.isSubMeta && !this.context.getMetadata().__isSubMeta || this.verbose) {
2725
2763
  this.log();
@@ -2788,21 +2826,23 @@ var GraphNode = class _GraphNode extends SignalEmitter {
2788
2826
  `meta.node.graph_completed:${this.routineExecId}`,
2789
2827
  context2
2790
2828
  );
2791
- this.emitMetricsWithMetadata(
2792
- "meta.node.ended_routine_execution",
2793
- {
2794
- data: {
2795
- isRunning: false,
2796
- isComplete: true,
2797
- resultContext: this.context.getContext(),
2798
- metaResultContext: this.context.getMetadata(),
2799
- progress: 1,
2800
- ended: formatTimestamp(end)
2829
+ if (this.getBusinessRoutineLifecycleDecision()) {
2830
+ this.emitMetricsWithMetadata(
2831
+ "meta.node.ended_routine_execution",
2832
+ {
2833
+ data: {
2834
+ isRunning: false,
2835
+ isComplete: true,
2836
+ resultContext: this.context.getContext(),
2837
+ metaResultContext: this.context.getMetadata(),
2838
+ progress: 1,
2839
+ ended: formatTimestamp(end)
2840
+ },
2841
+ filter: { uuid: this.routineExecId }
2801
2842
  },
2802
- filter: { uuid: this.routineExecId }
2803
- },
2804
- { squash: true, squashId: this.routineExecId }
2805
- );
2843
+ { squash: true, squashId: this.routineExecId }
2844
+ );
2845
+ }
2806
2846
  }
2807
2847
  return end;
2808
2848
  }
@@ -3689,7 +3729,7 @@ var GraphRunner = class extends SignalEmitter {
3689
3729
  allTasks
3690
3730
  );
3691
3731
  const ctx = new GraphContext(context || {});
3692
- if (!isSubMeta) {
3732
+ if (!isSubMeta && (!isMeta || this.debug)) {
3693
3733
  if (isNewTrace) {
3694
3734
  this.emitMetrics("meta.runner.new_trace", {
3695
3735
  data: {
@@ -4108,7 +4148,13 @@ var Actor = class {
4108
4148
  inquire: (inquiryName, inquiryContext = {}, options = {}) => inquire(inquiryName, inquiryContext, options),
4109
4149
  tools: resolvedTools
4110
4150
  };
4111
- const handlerResult = await handler(actorContext);
4151
+ const handlerResult = await handler(
4152
+ actorContext,
4153
+ actorContext.emit,
4154
+ actorContext.inquire,
4155
+ resolvedTools,
4156
+ resolvedProgressCallback
4157
+ );
4112
4158
  if (invocationOptions.writeContract === "reducer" && typeof handlerResult === "function") {
4113
4159
  reduceDurableState(handlerResult);
4114
4160
  }