@cadenza.io/core 1.11.15 → 1.12.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
@@ -232,12 +232,15 @@ declare class GraphNode extends SignalEmitter implements Graph {
232
232
  emitWithMetadata(signal: string, ctx: AnyObject): void;
233
233
  emitMetricsWithMetadata(signal: string, ctx: AnyObject): void;
234
234
  onProgress(progress: number): void;
235
- postProcess(): void;
235
+ postProcess(): GraphNode[] | Promise<GraphNode[]>;
236
+ postProcessAsync(nextNodes: Promise<GraphNode[]>): Promise<GraphNode[]>;
237
+ finalize(): void;
236
238
  onError(error: unknown, errorData?: AnyObject): void;
237
239
  retry(prevResult?: any): Promise<TaskResult>;
238
240
  retryAsync(prevResult?: any): Promise<TaskResult>;
239
241
  delayRetry(): Promise<void>;
240
- divide(): GraphNode[];
242
+ divide(): GraphNode[] | Promise<GraphNode[]>;
243
+ divideAsync(current: Promise<IteratorResult<any>>): Promise<GraphNode[]>;
241
244
  generateNewNodes(result: any): GraphNode[];
242
245
  differentiate(task: Task): GraphNode;
243
246
  migrate(ctx: any): GraphNode;
package/dist/index.d.ts CHANGED
@@ -232,12 +232,15 @@ declare class GraphNode extends SignalEmitter implements Graph {
232
232
  emitWithMetadata(signal: string, ctx: AnyObject): void;
233
233
  emitMetricsWithMetadata(signal: string, ctx: AnyObject): void;
234
234
  onProgress(progress: number): void;
235
- postProcess(): void;
235
+ postProcess(): GraphNode[] | Promise<GraphNode[]>;
236
+ postProcessAsync(nextNodes: Promise<GraphNode[]>): Promise<GraphNode[]>;
237
+ finalize(): void;
236
238
  onError(error: unknown, errorData?: AnyObject): void;
237
239
  retry(prevResult?: any): Promise<TaskResult>;
238
240
  retryAsync(prevResult?: any): Promise<TaskResult>;
239
241
  delayRetry(): Promise<void>;
240
- divide(): GraphNode[];
242
+ divide(): GraphNode[] | Promise<GraphNode[]>;
243
+ divideAsync(current: Promise<IteratorResult<any>>): Promise<GraphNode[]>;
241
244
  generateNewNodes(result: any): GraphNode[];
242
245
  differentiate(task: Task): GraphNode;
243
246
  migrate(ctx: any): GraphNode;
package/dist/index.js CHANGED
@@ -934,7 +934,11 @@ var GraphNode = class _GraphNode extends SignalEmitter {
934
934
  if (this.result instanceof Promise) {
935
935
  return this.executeAsync();
936
936
  }
937
- this.postProcess();
937
+ const nextNodes = this.postProcess();
938
+ if (nextNodes instanceof Promise) {
939
+ return nextNodes;
940
+ }
941
+ this.nextNodes = nextNodes;
938
942
  }
939
943
  return this.nextNodes;
940
944
  }
@@ -950,7 +954,11 @@ var GraphNode = class _GraphNode extends SignalEmitter {
950
954
  }
951
955
  async executeAsync() {
952
956
  await this.workAsync();
953
- this.postProcess();
957
+ const nextNodes = this.postProcess();
958
+ if (nextNodes instanceof Promise) {
959
+ return nextNodes;
960
+ }
961
+ this.nextNodes = nextNodes;
954
962
  return this.nextNodes;
955
963
  }
956
964
  work() {
@@ -1036,7 +1044,20 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1036
1044
  if (Array.isArray(this.result)) {
1037
1045
  this.onError(`Returning arrays is not allowed. Returned: ${this.result}`);
1038
1046
  }
1039
- this.nextNodes = this.divide();
1047
+ const nextNodes = this.divide();
1048
+ if (nextNodes instanceof Promise) {
1049
+ return this.postProcessAsync(nextNodes);
1050
+ }
1051
+ this.nextNodes = nextNodes;
1052
+ this.finalize();
1053
+ return this.nextNodes;
1054
+ }
1055
+ async postProcessAsync(nextNodes) {
1056
+ this.nextNodes = await nextNodes;
1057
+ this.finalize();
1058
+ return this.nextNodes;
1059
+ }
1060
+ finalize() {
1040
1061
  if (this.nextNodes.length === 0) {
1041
1062
  this.completeSubgraph();
1042
1063
  }
@@ -1093,6 +1114,9 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1093
1114
  if (((_a = this.result) == null ? void 0 : _a.next) && typeof this.result.next === "function") {
1094
1115
  const generator = this.result;
1095
1116
  let current = generator.next();
1117
+ if (current instanceof Promise) {
1118
+ return this.divideAsync(current);
1119
+ }
1096
1120
  while (!current.done && current.value !== void 0) {
1097
1121
  const outputValidation = this.task.validateOutput(current.value);
1098
1122
  if (outputValidation !== true) {
@@ -1136,6 +1160,28 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1136
1160
  });
1137
1161
  return newNodes;
1138
1162
  }
1163
+ async divideAsync(current) {
1164
+ const nextNodes = [];
1165
+ const _current = await current;
1166
+ const outputValidation = this.task.validateOutput(_current.value);
1167
+ if (outputValidation !== true) {
1168
+ this.onError(outputValidation.__validationErrors);
1169
+ return nextNodes;
1170
+ } else {
1171
+ nextNodes.push(...this.generateNewNodes(_current.value));
1172
+ }
1173
+ for await (const result of this.result) {
1174
+ const outputValidation2 = this.task.validateOutput(result);
1175
+ if (outputValidation2 !== true) {
1176
+ this.onError(outputValidation2.__validationErrors);
1177
+ return [];
1178
+ } else {
1179
+ nextNodes.push(...this.generateNewNodes(result));
1180
+ }
1181
+ }
1182
+ this.divided = true;
1183
+ return nextNodes;
1184
+ }
1139
1185
  generateNewNodes(result) {
1140
1186
  const groupId = (0, import_uuid3.v4)();
1141
1187
  const newNodes = [];
@@ -3133,26 +3179,28 @@ var Cadenza = class {
3133
3179
  * @returns The created Task instance.
3134
3180
  * @throws Error if name is invalid or duplicate in registry.
3135
3181
  */
3136
- static createTask(name, func, description, options = {
3137
- concurrency: 0,
3138
- timeout: 0,
3139
- register: true,
3140
- isUnique: false,
3141
- isMeta: false,
3142
- isSubMeta: false,
3143
- isHidden: false,
3144
- getTagCallback: void 0,
3145
- inputSchema: void 0,
3146
- validateInputContext: false,
3147
- outputSchema: void 0,
3148
- validateOutputContext: false,
3149
- retryCount: 0,
3150
- retryDelay: 0,
3151
- retryDelayMax: 0,
3152
- retryDelayFactor: 1
3153
- }) {
3182
+ static createTask(name, func, description, options = {}) {
3154
3183
  this.bootstrap();
3155
3184
  this.validateName(name);
3185
+ options = {
3186
+ concurrency: 0,
3187
+ timeout: 0,
3188
+ register: true,
3189
+ isUnique: false,
3190
+ isMeta: false,
3191
+ isSubMeta: false,
3192
+ isHidden: false,
3193
+ getTagCallback: void 0,
3194
+ inputSchema: void 0,
3195
+ validateInputContext: false,
3196
+ outputSchema: void 0,
3197
+ validateOutputContext: false,
3198
+ retryCount: 0,
3199
+ retryDelay: 0,
3200
+ retryDelayMax: 0,
3201
+ retryDelayFactor: 1,
3202
+ ...options
3203
+ };
3156
3204
  return new Task(
3157
3205
  name,
3158
3206
  func,
@@ -3185,24 +3233,7 @@ var Cadenza = class {
3185
3233
  * @returns The created MetaTask instance.
3186
3234
  * @throws Error if name invalid or duplicate.
3187
3235
  */
3188
- static createMetaTask(name, func, description, options = {
3189
- concurrency: 0,
3190
- timeout: 0,
3191
- register: true,
3192
- isUnique: false,
3193
- isMeta: true,
3194
- isSubMeta: false,
3195
- isHidden: false,
3196
- getTagCallback: void 0,
3197
- inputSchema: void 0,
3198
- validateInputContext: false,
3199
- outputSchema: void 0,
3200
- validateOutputContext: false,
3201
- retryCount: 0,
3202
- retryDelay: 0,
3203
- retryDelayMax: 0,
3204
- retryDelayFactor: 1
3205
- }) {
3236
+ static createMetaTask(name, func, description, options = {}) {
3206
3237
  options.isMeta = true;
3207
3238
  return this.createTask(name, func, description, options);
3208
3239
  }
@@ -3216,24 +3247,7 @@ var Cadenza = class {
3216
3247
  * @returns The created UniqueTask.
3217
3248
  * @throws Error if invalid.
3218
3249
  */
3219
- static createUniqueTask(name, func, description, options = {
3220
- concurrency: 0,
3221
- timeout: 0,
3222
- register: true,
3223
- isUnique: true,
3224
- isMeta: false,
3225
- isSubMeta: false,
3226
- isHidden: false,
3227
- getTagCallback: void 0,
3228
- inputSchema: void 0,
3229
- validateInputContext: false,
3230
- outputSchema: void 0,
3231
- validateOutputContext: false,
3232
- retryCount: 0,
3233
- retryDelay: 0,
3234
- retryDelayMax: 0,
3235
- retryDelayFactor: 1
3236
- }) {
3250
+ static createUniqueTask(name, func, description, options = {}) {
3237
3251
  options.isUnique = true;
3238
3252
  return this.createTask(name, func, description, options);
3239
3253
  }
@@ -3245,25 +3259,9 @@ var Cadenza = class {
3245
3259
  * @param options Optional task options.
3246
3260
  * @returns The created UniqueMetaTask.
3247
3261
  */
3248
- static createUniqueMetaTask(name, func, description, options = {
3249
- concurrency: 0,
3250
- timeout: 0,
3251
- register: true,
3252
- isUnique: true,
3253
- isMeta: true,
3254
- isSubMeta: false,
3255
- isHidden: false,
3256
- getTagCallback: void 0,
3257
- inputSchema: void 0,
3258
- validateInputContext: false,
3259
- outputSchema: void 0,
3260
- validateOutputContext: false,
3261
- retryCount: 0,
3262
- retryDelay: 0,
3263
- retryDelayMax: 0,
3264
- retryDelayFactor: 1
3265
- }) {
3262
+ static createUniqueMetaTask(name, func, description, options = {}) {
3266
3263
  options.isMeta = true;
3264
+ options.isUnique = true;
3267
3265
  return this.createUniqueTask(name, func, description, options);
3268
3266
  }
3269
3267
  /**
@@ -3276,23 +3274,8 @@ var Cadenza = class {
3276
3274
  * @returns The created ThrottledTask.
3277
3275
  * @edge If no getter, throttles per task ID; use for resource protection.
3278
3276
  */
3279
- static createThrottledTask(name, func, throttledIdGetter = () => "default", description, options = {
3280
- concurrency: 1,
3281
- timeout: 0,
3282
- register: true,
3283
- isUnique: false,
3284
- isMeta: false,
3285
- isSubMeta: false,
3286
- isHidden: false,
3287
- inputSchema: void 0,
3288
- validateInputContext: false,
3289
- outputSchema: void 0,
3290
- validateOutputContext: false,
3291
- retryCount: 0,
3292
- retryDelay: 0,
3293
- retryDelayMax: 0,
3294
- retryDelayFactor: 1
3295
- }) {
3277
+ static createThrottledTask(name, func, throttledIdGetter = () => "default", description, options = {}) {
3278
+ options.concurrency = 1;
3296
3279
  options.getTagCallback = throttledIdGetter;
3297
3280
  return this.createTask(name, func, description, options);
3298
3281
  }
@@ -3305,23 +3288,7 @@ var Cadenza = class {
3305
3288
  * @param options Optional task options.
3306
3289
  * @returns The created ThrottledMetaTask.
3307
3290
  */
3308
- static createThrottledMetaTask(name, func, throttledIdGetter, description, options = {
3309
- concurrency: 0,
3310
- timeout: 0,
3311
- register: true,
3312
- isUnique: false,
3313
- isMeta: true,
3314
- isSubMeta: false,
3315
- isHidden: false,
3316
- inputSchema: void 0,
3317
- validateInputContext: false,
3318
- outputSchema: void 0,
3319
- validateOutputContext: false,
3320
- retryCount: 0,
3321
- retryDelay: 0,
3322
- retryDelayMax: 0,
3323
- retryDelayFactor: 1
3324
- }) {
3291
+ static createThrottledMetaTask(name, func, throttledIdGetter, description, options = {}) {
3325
3292
  options.isMeta = true;
3326
3293
  return this.createThrottledTask(
3327
3294
  name,
@@ -3341,24 +3308,26 @@ var Cadenza = class {
3341
3308
  * @returns The created DebounceTask.
3342
3309
  * @edge Multiple triggers within time collapse to one exec.
3343
3310
  */
3344
- static createDebounceTask(name, func, description, debounceTime = 1e3, options = {
3345
- concurrency: 0,
3346
- timeout: 0,
3347
- register: true,
3348
- leading: false,
3349
- trailing: true,
3350
- maxWait: 0,
3351
- isUnique: false,
3352
- isMeta: false,
3353
- isSubMeta: false,
3354
- isHidden: false,
3355
- inputSchema: void 0,
3356
- validateInputContext: false,
3357
- outputSchema: void 0,
3358
- validateOutputContext: false
3359
- }) {
3311
+ static createDebounceTask(name, func, description, debounceTime = 1e3, options = {}) {
3360
3312
  this.bootstrap();
3361
3313
  this.validateName(name);
3314
+ options = {
3315
+ concurrency: 0,
3316
+ timeout: 0,
3317
+ register: true,
3318
+ leading: false,
3319
+ trailing: true,
3320
+ maxWait: 0,
3321
+ isUnique: false,
3322
+ isMeta: false,
3323
+ isSubMeta: false,
3324
+ isHidden: false,
3325
+ inputSchema: void 0,
3326
+ validateInputContext: false,
3327
+ outputSchema: void 0,
3328
+ validateOutputContext: false,
3329
+ ...options
3330
+ };
3362
3331
  return new DebounceTask(
3363
3332
  name,
3364
3333
  func,
@@ -3389,22 +3358,7 @@ var Cadenza = class {
3389
3358
  * @param options Optional task options plus optional debounce config (e.g., leading/trailing).
3390
3359
  * @returns The created DebouncedMetaTask.
3391
3360
  */
3392
- static createDebounceMetaTask(name, func, description, debounceTime = 1e3, options = {
3393
- concurrency: 0,
3394
- timeout: 0,
3395
- register: true,
3396
- leading: false,
3397
- trailing: true,
3398
- maxWait: 0,
3399
- isUnique: false,
3400
- isMeta: false,
3401
- isSubMeta: false,
3402
- isHidden: false,
3403
- inputSchema: void 0,
3404
- validateInputContext: false,
3405
- outputSchema: void 0,
3406
- validateOutputContext: false
3407
- }) {
3361
+ static createDebounceMetaTask(name, func, description, debounceTime = 1e3, options = {}) {
3408
3362
  options.isMeta = true;
3409
3363
  return this.createDebounceTask(
3410
3364
  name,
@@ -3424,28 +3378,30 @@ var Cadenza = class {
3424
3378
  * @returns The created EphemeralTask.
3425
3379
  * @edge Destruction triggered post-exec via Node/Builder; emits meta-signal for cleanup.
3426
3380
  */
3427
- static createEphemeralTask(name, func, description, options = {
3428
- concurrency: 0,
3429
- timeout: 0,
3430
- register: true,
3431
- isUnique: false,
3432
- isMeta: false,
3433
- isSubMeta: false,
3434
- isHidden: false,
3435
- once: true,
3436
- destroyCondition: () => true,
3437
- getTagCallback: void 0,
3438
- inputSchema: void 0,
3439
- validateInputContext: false,
3440
- outputSchema: void 0,
3441
- validateOutputContext: false,
3442
- retryCount: 0,
3443
- retryDelay: 0,
3444
- retryDelayMax: 0,
3445
- retryDelayFactor: 1
3446
- }) {
3381
+ static createEphemeralTask(name, func, description, options = {}) {
3447
3382
  this.bootstrap();
3448
3383
  this.validateName(name);
3384
+ options = {
3385
+ concurrency: 0,
3386
+ timeout: 0,
3387
+ register: true,
3388
+ isUnique: false,
3389
+ isMeta: false,
3390
+ isSubMeta: false,
3391
+ isHidden: false,
3392
+ once: true,
3393
+ destroyCondition: () => true,
3394
+ getTagCallback: void 0,
3395
+ inputSchema: void 0,
3396
+ validateInputContext: false,
3397
+ outputSchema: void 0,
3398
+ validateOutputContext: false,
3399
+ retryCount: 0,
3400
+ retryDelay: 0,
3401
+ retryDelayMax: 0,
3402
+ retryDelayFactor: 1,
3403
+ ...options
3404
+ };
3449
3405
  return new EphemeralTask(
3450
3406
  name,
3451
3407
  func,
@@ -3478,26 +3434,7 @@ var Cadenza = class {
3478
3434
  * @param options Optional task options plus optional "once" (true) and "destroyCondition" (ctx => boolean).
3479
3435
  * @returns The created EphemeralMetaTask.
3480
3436
  */
3481
- static createEphemeralMetaTask(name, func, description, options = {
3482
- concurrency: 0,
3483
- timeout: 0,
3484
- register: true,
3485
- isUnique: false,
3486
- isMeta: true,
3487
- isSubMeta: false,
3488
- isHidden: false,
3489
- once: true,
3490
- destroyCondition: () => true,
3491
- getTagCallback: void 0,
3492
- inputSchema: void 0,
3493
- validateInputContext: false,
3494
- outputSchema: void 0,
3495
- validateOutputContext: false,
3496
- retryCount: 0,
3497
- retryDelay: 0,
3498
- retryDelayMax: 0,
3499
- retryDelayFactor: 1
3500
- }) {
3437
+ static createEphemeralMetaTask(name, func, description, options = {}) {
3501
3438
  options.isMeta = true;
3502
3439
  return this.createEphemeralTask(name, func, description, options);
3503
3440
  }