@hexabot-ai/agentic 3.1.2-alpha.8 → 3.1.2-beta.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.
Files changed (69) hide show
  1. package/README.md +13 -5
  2. package/dist/cjs/action/abstract-action.js +8 -3
  3. package/dist/cjs/errors.js +41 -0
  4. package/dist/cjs/index.js +7 -1
  5. package/dist/cjs/step-executors/parallel-executor.js +238 -24
  6. package/dist/cjs/step-executors/skip-helpers.js +25 -1
  7. package/dist/cjs/step-executors/task-executor.js +77 -10
  8. package/dist/cjs/suspension-rebuilder.js +1 -24
  9. package/dist/cjs/utils/timeout.js +63 -8
  10. package/dist/cjs/utils/workflow-definition-resources.js +73 -0
  11. package/dist/cjs/workflow-runner.js +40 -17
  12. package/dist/esm/action/abstract-action.js +8 -3
  13. package/dist/esm/errors.js +33 -0
  14. package/dist/esm/index.js +2 -0
  15. package/dist/esm/step-executors/parallel-executor.js +239 -25
  16. package/dist/esm/step-executors/skip-helpers.js +23 -0
  17. package/dist/esm/step-executors/task-executor.js +77 -10
  18. package/dist/esm/suspension-rebuilder.js +1 -24
  19. package/dist/esm/utils/timeout.js +63 -8
  20. package/dist/esm/utils/workflow-definition-resources.js +68 -0
  21. package/dist/esm/workflow-runner.js +40 -17
  22. package/dist/types/action/abstract-action.d.ts +1 -1
  23. package/dist/types/action/abstract-action.d.ts.map +1 -1
  24. package/dist/types/action/action.types.d.ts +2 -1
  25. package/dist/types/action/action.types.d.ts.map +1 -1
  26. package/dist/types/context.d.ts +2 -1
  27. package/dist/types/context.d.ts.map +1 -1
  28. package/dist/types/errors.d.ts +10 -0
  29. package/dist/types/errors.d.ts.map +1 -0
  30. package/dist/types/index.d.ts +2 -0
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/step-executors/parallel-executor.d.ts +3 -4
  33. package/dist/types/step-executors/parallel-executor.d.ts.map +1 -1
  34. package/dist/types/step-executors/skip-helpers.d.ts +1 -0
  35. package/dist/types/step-executors/skip-helpers.d.ts.map +1 -1
  36. package/dist/types/step-executors/task-executor.d.ts.map +1 -1
  37. package/dist/types/step-executors/types.d.ts +9 -1
  38. package/dist/types/step-executors/types.d.ts.map +1 -1
  39. package/dist/types/suspension-rebuilder.d.ts.map +1 -1
  40. package/dist/types/utils/timeout.d.ts +4 -2
  41. package/dist/types/utils/timeout.d.ts.map +1 -1
  42. package/dist/types/utils/workflow-definition-resources.d.ts +16 -0
  43. package/dist/types/utils/workflow-definition-resources.d.ts.map +1 -0
  44. package/dist/types/workflow-event-emitter.d.ts +12 -13
  45. package/dist/types/workflow-event-emitter.d.ts.map +1 -1
  46. package/dist/types/workflow-runner.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/src/__tests__/suspension-rebuilder.test.ts +3 -42
  49. package/src/__tests__/workflow-definition-resources.test.ts +97 -0
  50. package/src/__tests__/workflow-runner.test.ts +58 -5
  51. package/src/action/__tests__/action.test.ts +2 -1
  52. package/src/action/abstract-action.ts +9 -1
  53. package/src/action/action.types.ts +2 -0
  54. package/src/context.ts +2 -0
  55. package/src/errors.ts +43 -0
  56. package/src/index.ts +10 -0
  57. package/src/step-executors/conditional-executor.test.ts +8 -3
  58. package/src/step-executors/loop-executor.test.ts +8 -3
  59. package/src/step-executors/parallel-executor.test.ts +191 -82
  60. package/src/step-executors/parallel-executor.ts +402 -34
  61. package/src/step-executors/skip-helpers.ts +41 -0
  62. package/src/step-executors/task-executor.test.ts +85 -21
  63. package/src/step-executors/task-executor.ts +94 -10
  64. package/src/step-executors/types.ts +14 -1
  65. package/src/suspension-rebuilder.ts +1 -53
  66. package/src/utils/timeout.ts +78 -8
  67. package/src/utils/workflow-definition-resources.ts +111 -0
  68. package/src/workflow-event-emitter.ts +13 -6
  69. package/src/workflow-runner.ts +59 -19
@@ -13,13 +13,17 @@ import {
13
13
  type WorkflowRunStatus,
14
14
  type WorkflowSnapshot,
15
15
  } from './context';
16
+ import { throwIfAborted } from './errors';
16
17
  import { RunnerRuntimeControl } from './runner-runtime-control';
17
18
  import { executeConditional as runConditionalExecutor } from './step-executors/conditional-executor';
18
19
  import { executeLoop as runLoopExecutor } from './step-executors/loop-executor';
19
20
  import { executeParallel as runParallelExecutor } from './step-executors/parallel-executor';
20
21
  import { wrapSuspensionContinuation } from './step-executors/suspension-continuation';
21
22
  import { executeTaskStep as runTaskExecutor } from './step-executors/task-executor';
22
- import type { StepExecutorEnv } from './step-executors/types';
23
+ import type {
24
+ StepExecutorEnv,
25
+ StepExecutorEnvForkOverrides,
26
+ } from './step-executors/types';
23
27
  import {
24
28
  rebuildSuspension,
25
29
  type SuspensionRebuilderDeps,
@@ -190,8 +194,10 @@ export class WorkflowRunner {
190
194
  throw new Error('Workflow state not initialized.');
191
195
  }
192
196
 
197
+ const env = this.createExecutorEnv();
198
+
193
199
  return this.runExecution(() =>
194
- this.executeFlow(this.compiled.flow, state, []),
200
+ this.executeFlow(this.compiled.flow, state, [], 0, env),
195
201
  );
196
202
  }
197
203
 
@@ -425,7 +431,7 @@ export class WorkflowRunner {
425
431
  private recordStepExecution(
426
432
  step: StepInfo,
427
433
  update: Partial<StepExecutionRecord>,
428
- ) {
434
+ ): StepExecutionRecord {
429
435
  const existing = this.stepLog[step.id];
430
436
  const base: StepExecutionRecord =
431
437
  existing ??
@@ -438,8 +444,7 @@ export class WorkflowRunner {
438
444
  existing?.context || update.context
439
445
  ? { ...existing?.context, ...update.context }
440
446
  : undefined;
441
-
442
- this.stepLog[step.id] = {
447
+ const nextRecord: StepExecutionRecord = {
443
448
  ...base,
444
449
  ...update,
445
450
  id: step.id,
@@ -447,6 +452,14 @@ export class WorkflowRunner {
447
452
  status: update.status ?? base.status,
448
453
  context: mergedContext,
449
454
  };
455
+
456
+ this.stepLog[step.id] = nextRecord;
457
+
458
+ return {
459
+ ...nextRecord,
460
+ context: nextRecord.context ? { ...nextRecord.context } : undefined,
461
+ error: nextRecord.error ? { ...nextRecord.error } : undefined,
462
+ };
450
463
  }
451
464
 
452
465
  /**
@@ -455,14 +468,28 @@ export class WorkflowRunner {
455
468
  * @returns A step executor environment bound to this runner.
456
469
  * @throws When the workflow context is missing.
457
470
  */
458
- private createExecutorEnv(): StepExecutorEnv {
459
- if (!this.context) {
471
+ private createExecutorEnv(
472
+ overrides: StepExecutorEnvForkOverrides = {},
473
+ ): StepExecutorEnv {
474
+ const context = overrides.context ?? this.context;
475
+ if (!context) {
460
476
  throw new Error('Workflow context is not attached.');
461
477
  }
462
478
 
463
- return {
479
+ const signal = overrides.signal ?? new AbortController().signal;
480
+ const setCurrentStep =
481
+ overrides.setCurrentStep ??
482
+ ((step?: StepInfo) => {
483
+ this.currentStep = step;
484
+ });
485
+ const captureTaskOutput =
486
+ overrides.captureTaskOutput ??
487
+ ((task: CompiledTask, state: ExecutionState, result: unknown) =>
488
+ this.captureTaskOutput(task, state, result));
489
+ const executorEnv: StepExecutorEnv = {
464
490
  compiled: this.compiled,
465
- context: this.context,
491
+ context,
492
+ signal,
466
493
  runId: this.runId,
467
494
  buildInstanceStepInfo: (step, iterationStack) =>
468
495
  this.buildInstanceStepInfo(step, iterationStack),
@@ -471,9 +498,7 @@ export class WorkflowRunner {
471
498
  recordStepExecution: (step, update) =>
472
499
  this.recordStepExecution(step, update),
473
500
  emit: (event, payload) => this.emit(event, payload),
474
- setCurrentStep: (step?: StepInfo) => {
475
- this.currentStep = step;
476
- },
501
+ setCurrentStep,
477
502
  beginStepExecution: (stepId) => {
478
503
  if (!this.runtimeControl) {
479
504
  return `${stepId}#1`;
@@ -500,12 +525,22 @@ export class WorkflowRunner {
500
525
  recordStepSuspendResult: (params) => {
501
526
  this.runtimeControl?.recordStepSuspendResult(params);
502
527
  },
503
- captureTaskOutput: (task, state, result) =>
504
- this.captureTaskOutput(task, state, result),
528
+ captureTaskOutput,
505
529
  executeFlow: (steps, state, path, startIndex) =>
506
- this.executeFlow(steps, state, path, startIndex),
507
- executeStep: (step, state, path) => this.executeStep(step, state, path),
530
+ this.executeFlow(steps, state, path, startIndex, executorEnv),
531
+ executeStep: (step, state, path) =>
532
+ this.executeStep(step, state, path, executorEnv),
533
+ fork: (forkOverrides) =>
534
+ this.createExecutorEnv({
535
+ context: forkOverrides.context ?? context,
536
+ signal: forkOverrides.signal ?? signal,
537
+ setCurrentStep: forkOverrides.setCurrentStep ?? setCurrentStep,
538
+ captureTaskOutput:
539
+ forkOverrides.captureTaskOutput ?? captureTaskOutput,
540
+ }),
508
541
  };
542
+
543
+ return executorEnv;
509
544
  }
510
545
 
511
546
  /**
@@ -545,16 +580,19 @@ export class WorkflowRunner {
545
580
  state: ExecutionState,
546
581
  path: Array<number | string>,
547
582
  startIndex = 0,
583
+ env = this.createExecutorEnv(),
548
584
  ): Promise<Suspension | void> {
549
585
  // Walk the flow sequentially; if a step suspends, wrap its continuation so we resume at the same index.
550
586
  for (let index = startIndex; index < steps.length; index += 1) {
587
+ throwIfAborted(env.signal);
588
+
551
589
  const step = steps[index];
552
590
  const stepPath = [...path, index];
553
- const suspension = await this.executeStep(step, state, stepPath);
591
+ const suspension = await this.executeStep(step, state, stepPath, env);
554
592
 
555
593
  if (suspension) {
556
594
  return wrapSuspensionContinuation(suspension, () =>
557
- this.executeFlow(steps, state, path, index + 1),
595
+ this.executeFlow(steps, state, path, index + 1, env),
558
596
  );
559
597
  }
560
598
  }
@@ -574,8 +612,10 @@ export class WorkflowRunner {
574
612
  step: CompiledStep,
575
613
  state: ExecutionState,
576
614
  path: Array<number | string>,
615
+ env = this.createExecutorEnv(),
577
616
  ): Promise<Suspension | void> {
578
- const env = this.createExecutorEnv();
617
+ throwIfAborted(env.signal);
618
+
579
619
  switch (step.type) {
580
620
  case StepType.Task:
581
621
  return runTaskExecutor(env, step, state, path);