@cadenza.io/core 1.11.7 → 1.11.9

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
@@ -468,6 +468,8 @@ declare class Task extends SignalParticipant implements Graph {
468
468
  setOutputContextSchema(schema: SchemaDefinition): void;
469
469
  setValidateInputContext(value: boolean): void;
470
470
  setValidateOutputContext(value: boolean): void;
471
+ private emitWithMetadata;
472
+ private emitMetricsWithMetadata;
471
473
  /**
472
474
  * Validates a context deeply against a schema.
473
475
  * @param data - The data to validate (input context or output result).
@@ -639,7 +641,9 @@ declare class SignalBroker {
639
641
  */
640
642
  static get instance(): SignalBroker;
641
643
  private debug;
644
+ private verbose;
642
645
  setDebug(value: boolean): void;
646
+ setVerbose(value: boolean): void;
643
647
  protected validateSignalName(signalName: string): void;
644
648
  protected runner: GraphRunner | undefined;
645
649
  protected metaRunner: GraphRunner | undefined;
@@ -783,7 +787,7 @@ interface TaskOptions {
783
787
  retryDelayMax?: number;
784
788
  retryDelayFactor?: number;
785
789
  }
786
- type CadenzaMode = "dev" | "debug" | "production";
790
+ type CadenzaMode = "dev" | "debug" | "verbose" | "production";
787
791
  declare class Cadenza {
788
792
  static broker: SignalBroker;
789
793
  static runner: GraphRunner;
package/dist/index.d.ts CHANGED
@@ -468,6 +468,8 @@ declare class Task extends SignalParticipant implements Graph {
468
468
  setOutputContextSchema(schema: SchemaDefinition): void;
469
469
  setValidateInputContext(value: boolean): void;
470
470
  setValidateOutputContext(value: boolean): void;
471
+ private emitWithMetadata;
472
+ private emitMetricsWithMetadata;
471
473
  /**
472
474
  * Validates a context deeply against a schema.
473
475
  * @param data - The data to validate (input context or output result).
@@ -639,7 +641,9 @@ declare class SignalBroker {
639
641
  */
640
642
  static get instance(): SignalBroker;
641
643
  private debug;
644
+ private verbose;
642
645
  setDebug(value: boolean): void;
646
+ setVerbose(value: boolean): void;
643
647
  protected validateSignalName(signalName: string): void;
644
648
  protected runner: GraphRunner | undefined;
645
649
  protected metaRunner: GraphRunner | undefined;
@@ -783,7 +787,7 @@ interface TaskOptions {
783
787
  retryDelayMax?: number;
784
788
  retryDelayFactor?: number;
785
789
  }
786
- type CadenzaMode = "dev" | "debug" | "production";
790
+ type CadenzaMode = "dev" | "debug" | "verbose" | "production";
787
791
  declare class Cadenza {
788
792
  static broker: SignalBroker;
789
793
  static runner: GraphRunner;
package/dist/index.js CHANGED
@@ -76,6 +76,7 @@ var SignalBroker = class _SignalBroker {
76
76
  // execId -> emitted signals
77
77
  constructor() {
78
78
  this.debug = false;
79
+ this.verbose = false;
79
80
  this.signalObservers = /* @__PURE__ */ new Map();
80
81
  this.emitStacks = /* @__PURE__ */ new Map();
81
82
  this.addSignal("meta.signal_broker.added");
@@ -93,6 +94,9 @@ var SignalBroker = class _SignalBroker {
93
94
  setDebug(value) {
94
95
  this.debug = value;
95
96
  }
97
+ setVerbose(value) {
98
+ this.verbose = value;
99
+ }
96
100
  validateSignalName(signalName) {
97
101
  if (signalName.length > 100) {
98
102
  throw new Error(
@@ -196,8 +200,10 @@ var SignalBroker = class _SignalBroker {
196
200
  }
197
201
  }
198
202
  execute(signal, context) {
203
+ var _a;
199
204
  const isMeta = signal.startsWith("meta.");
200
205
  const isSubMeta = signal.startsWith("sub_meta.");
206
+ const isMetric = (_a = context.__signalEmission) == null ? void 0 : _a.isMetric;
201
207
  if (!isSubMeta && (!isMeta || this.debug)) {
202
208
  const emittedAt = Date.now();
203
209
  context.__signalEmission = {
@@ -214,7 +220,7 @@ var SignalBroker = class _SignalBroker {
214
220
  } else {
215
221
  delete context.__signalEmission;
216
222
  }
217
- if (this.debug) {
223
+ if (this.debug && (!isMetric || this.verbose)) {
218
224
  console.log(
219
225
  `Emitting signal ${signal} with context ${JSON.stringify(context)}`
220
226
  );
@@ -971,6 +977,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
971
977
  if (!this.task.isHidden) {
972
978
  data.__signalEmission = {
973
979
  taskId: this.task.id,
980
+ taskName: this.task.name,
974
981
  taskExecutionId: this.id
975
982
  };
976
983
  data.__metadata = {
@@ -984,7 +991,9 @@ var GraphNode = class _GraphNode extends SignalEmitter {
984
991
  if (!this.task.isHidden) {
985
992
  data.__signalEmission = {
986
993
  taskId: this.task.id,
987
- taskExecutionId: this.id
994
+ taskName: this.task.name,
995
+ taskExecutionId: this.id,
996
+ isMetric: true
988
997
  };
989
998
  data.__metadata = {
990
999
  __routineExecId: this.routineExecId
@@ -1536,7 +1545,7 @@ var Task = class extends SignalParticipant {
1536
1545
  * @edge Emits 'meta.task.created' with { __task: this } for seed.
1537
1546
  */
1538
1547
  constructor(name, task, description = "", concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, isSubMeta = false, isHidden = false, getTagCallback = void 0, inputSchema = void 0, validateInputContext = false, outputSchema = void 0, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
1539
- super();
1548
+ super(isSubMeta || isHidden);
1540
1549
  this.isMeta = false;
1541
1550
  this.isSubMeta = false;
1542
1551
  this.isHidden = false;
@@ -1584,7 +1593,7 @@ var Task = class extends SignalParticipant {
1584
1593
  }
1585
1594
  if (register && !this.isHidden && !this.isSubMeta) {
1586
1595
  const { __functionString, __getTagCallback } = this.export();
1587
- this.emit("meta.task.created", {
1596
+ this.emitWithMetadata("meta.task.created", {
1588
1597
  __task: {
1589
1598
  uuid: this.id,
1590
1599
  name: this.name,
@@ -1619,7 +1628,10 @@ var Task = class extends SignalParticipant {
1619
1628
  setGlobalId(id) {
1620
1629
  const oldId = this.id;
1621
1630
  this.id = id;
1622
- this.emit("meta.task.global_id_set", { __id: this.id, __oldId: oldId });
1631
+ this.emitWithMetadata("meta.task.global_id_set", {
1632
+ __id: this.id,
1633
+ __oldId: oldId
1634
+ });
1623
1635
  }
1624
1636
  setTimeout(timeout) {
1625
1637
  this.timeout = timeout;
@@ -1642,6 +1654,27 @@ var Task = class extends SignalParticipant {
1642
1654
  setValidateOutputContext(value) {
1643
1655
  this.validateOutputContext = value;
1644
1656
  }
1657
+ emitWithMetadata(signal, ctx = {}) {
1658
+ const data = { ...ctx };
1659
+ if (!this.isHidden && !this.isSubMeta) {
1660
+ data.__signalEmission = {
1661
+ taskId: this.id,
1662
+ taskName: this.name
1663
+ };
1664
+ }
1665
+ this.emit(signal, data);
1666
+ }
1667
+ emitMetricsWithMetadata(signal, ctx = {}) {
1668
+ const data = { ...ctx };
1669
+ if (!this.isHidden && !this.isSubMeta) {
1670
+ data.__signalEmission = {
1671
+ taskId: this.id,
1672
+ taskName: this.name,
1673
+ isMetric: true
1674
+ };
1675
+ }
1676
+ this.emitMetrics(signal, data);
1677
+ }
1645
1678
  /**
1646
1679
  * Validates a context deeply against a schema.
1647
1680
  * @param data - The data to validate (input context or output result).
@@ -1758,7 +1791,7 @@ var Task = class extends SignalParticipant {
1758
1791
  this.inputContextSchema
1759
1792
  );
1760
1793
  if (!validationResult.valid) {
1761
- this.emit("meta.task.input_validation_failed", {
1794
+ this.emitWithMetadata("meta.task.input_validation_failed", {
1762
1795
  __taskId: this.id,
1763
1796
  __taskName: this.name,
1764
1797
  __context: context,
@@ -1780,7 +1813,7 @@ var Task = class extends SignalParticipant {
1780
1813
  this.outputContextSchema
1781
1814
  );
1782
1815
  if (!validationResult.valid) {
1783
- this.emit("meta.task.outputValidationFailed", {
1816
+ this.emitWithMetadata("meta.task.outputValidationFailed", {
1784
1817
  __taskId: this.id,
1785
1818
  __result: context,
1786
1819
  __errors: validationResult.errors
@@ -1820,7 +1853,7 @@ var Task = class extends SignalParticipant {
1820
1853
  this.decouple(pred);
1821
1854
  throw new Error(`Cycle adding pred ${pred.name} to ${this.name}`);
1822
1855
  }
1823
- this.emit("meta.task.relationship_added", {
1856
+ this.emitMetricsWithMetadata("meta.task.relationship_added", {
1824
1857
  data: {
1825
1858
  taskId: this.id,
1826
1859
  predecessorTaskId: pred.id
@@ -1840,7 +1873,7 @@ var Task = class extends SignalParticipant {
1840
1873
  this.decouple(next);
1841
1874
  throw new Error(`Cycle adding next ${next.name} to ${this.name}`);
1842
1875
  }
1843
- this.emit("meta.task.relationship_added", {
1876
+ this.emitMetricsWithMetadata("meta.task.relationship_added", {
1844
1877
  data: {
1845
1878
  taskId: next.id,
1846
1879
  predecessorTaskId: this.id
@@ -1871,7 +1904,7 @@ var Task = class extends SignalParticipant {
1871
1904
  this.decouple(task);
1872
1905
  throw new Error(`Cycle adding onFail ${task.name} to ${this.name}`);
1873
1906
  }
1874
- this.emit("meta.task.on_fail_relationship_added", {
1907
+ this.emitMetricsWithMetadata("meta.task.on_fail_relationship_added", {
1875
1908
  data: {
1876
1909
  taskId: this.id,
1877
1910
  onFailTaskId: task.id
@@ -1915,7 +1948,7 @@ var Task = class extends SignalParticipant {
1915
1948
  );
1916
1949
  this.layerIndex = maxPred + 1;
1917
1950
  if (prevLayerIndex !== this.layerIndex) {
1918
- this.emit("meta.task.layer_index_changed", {
1951
+ this.emitMetricsWithMetadata("meta.task.layer_index_changed", {
1919
1952
  data: {
1920
1953
  layerIndex: this.layerIndex
1921
1954
  },
@@ -1961,7 +1994,7 @@ var Task = class extends SignalParticipant {
1961
1994
  this.predecessorTasks.clear();
1962
1995
  this.onFailTasks.clear();
1963
1996
  this.destroyed = true;
1964
- this.emit("meta.task.destroyed", {
1997
+ this.emitMetricsWithMetadata("meta.task.destroyed", {
1965
1998
  data: { deleted: true },
1966
1999
  filter: { uuid: this.id }
1967
2000
  });
@@ -3056,6 +3089,11 @@ var Cadenza = class {
3056
3089
  this.broker.setDebug(true);
3057
3090
  this.runner.setDebug(true);
3058
3091
  }
3092
+ if (mode === "verbose") {
3093
+ this.broker.setDebug(true);
3094
+ this.broker.setVerbose(true);
3095
+ this.runner.setDebug(true);
3096
+ }
3059
3097
  }
3060
3098
  /**
3061
3099
  * Validates a name for uniqueness and non-emptiness.