@hexabot-ai/agentic 3.1.2-alpha.1 → 3.1.2-alpha.11

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 (35) hide show
  1. package/dist/cjs/index.js +4 -1
  2. package/dist/cjs/step-executors/loop-executor.js +26 -39
  3. package/dist/cjs/step-executors/parallel-executor.js +9 -15
  4. package/dist/cjs/step-executors/suspension-continuation.js +27 -0
  5. package/dist/cjs/suspension-rebuilder.js +61 -74
  6. package/dist/cjs/utils/workflow-definition-resources.js +73 -0
  7. package/dist/cjs/workflow-runner.js +2 -10
  8. package/dist/esm/index.js +1 -0
  9. package/dist/esm/step-executors/loop-executor.js +26 -39
  10. package/dist/esm/step-executors/parallel-executor.js +9 -15
  11. package/dist/esm/step-executors/suspension-continuation.js +24 -0
  12. package/dist/esm/suspension-rebuilder.js +61 -74
  13. package/dist/esm/utils/workflow-definition-resources.js +68 -0
  14. package/dist/esm/workflow-runner.js +2 -10
  15. package/dist/types/index.d.ts +1 -0
  16. package/dist/types/index.d.ts.map +1 -1
  17. package/dist/types/step-executors/loop-executor.d.ts.map +1 -1
  18. package/dist/types/step-executors/parallel-executor.d.ts.map +1 -1
  19. package/dist/types/step-executors/suspension-continuation.d.ts +10 -0
  20. package/dist/types/step-executors/suspension-continuation.d.ts.map +1 -0
  21. package/dist/types/suspension-rebuilder.d.ts.map +1 -1
  22. package/dist/types/utils/workflow-definition-resources.d.ts +16 -0
  23. package/dist/types/utils/workflow-definition-resources.d.ts.map +1 -0
  24. package/dist/types/workflow-runner.d.ts.map +1 -1
  25. package/package.json +2 -2
  26. package/src/__tests__/suspension-rebuilder.test.ts +43 -9
  27. package/src/__tests__/workflow-definition-resources.test.ts +97 -0
  28. package/src/__tests__/workflow-runner.test.ts +119 -1
  29. package/src/index.ts +8 -0
  30. package/src/step-executors/loop-executor.ts +49 -64
  31. package/src/step-executors/parallel-executor.ts +13 -20
  32. package/src/step-executors/suspension-continuation.ts +31 -0
  33. package/src/suspension-rebuilder.ts +94 -100
  34. package/src/utils/workflow-definition-resources.ts +111 -0
  35. package/src/workflow-runner.ts +4 -11
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2026 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+
7
+ import type { DefDefinition, WorkflowDefinition } from '../dsl.types';
8
+
9
+ export type WorkflowDefinitionResourceDescriptor = {
10
+ kind: string;
11
+ settingsKey: string;
12
+ };
13
+
14
+ export type WorkflowDefinitionResourceRefs = Record<string, string[]>;
15
+
16
+ export type WorkflowDefinitionResourceIdMaps = Record<
17
+ string,
18
+ Record<string, string>
19
+ >;
20
+
21
+ const getSettingsRef = (
22
+ definition: DefDefinition,
23
+ settingsKey: string,
24
+ ): string | null => {
25
+ const settings = definition.settings;
26
+ if (!settings || typeof settings !== 'object') {
27
+ return null;
28
+ }
29
+
30
+ const value = (settings as Record<string, unknown>)[settingsKey];
31
+
32
+ return typeof value === 'string' && value.trim() ? value : null;
33
+ };
34
+
35
+ /**
36
+ * Collect external resource IDs referenced by workflow definition defs.
37
+ */
38
+ export const collectWorkflowDefinitionResourceRefs = (
39
+ definition: WorkflowDefinition,
40
+ descriptors: WorkflowDefinitionResourceDescriptor[],
41
+ ): WorkflowDefinitionResourceRefs => {
42
+ const result = Object.fromEntries(
43
+ descriptors.map((descriptor) => [descriptor.kind, new Set<string>()]),
44
+ ) as Record<string, Set<string>>;
45
+
46
+ for (const def of Object.values(definition.defs ?? {})) {
47
+ for (const descriptor of descriptors) {
48
+ if (def.kind !== descriptor.kind) {
49
+ continue;
50
+ }
51
+
52
+ const ref = getSettingsRef(def, descriptor.settingsKey);
53
+ if (ref) {
54
+ result[descriptor.kind].add(ref);
55
+ }
56
+ }
57
+ }
58
+
59
+ return Object.fromEntries(
60
+ Object.entries(result).map(([kind, refs]) => [kind, Array.from(refs)]),
61
+ );
62
+ };
63
+
64
+ /**
65
+ * Rewrite external resource IDs referenced by workflow definition defs.
66
+ */
67
+ export const remapWorkflowDefinitionResourceRefs = (
68
+ definition: WorkflowDefinition,
69
+ descriptors: WorkflowDefinitionResourceDescriptor[],
70
+ idMaps: WorkflowDefinitionResourceIdMaps,
71
+ ): WorkflowDefinition => {
72
+ let didChange = false;
73
+ const nextDefs = Object.fromEntries(
74
+ Object.entries(definition.defs ?? {}).map(([defName, def]) => {
75
+ const descriptor = descriptors.find((item) => item.kind === def.kind);
76
+ if (!descriptor) {
77
+ return [defName, def];
78
+ }
79
+
80
+ const currentRef = getSettingsRef(def, descriptor.settingsKey);
81
+ const nextRef = currentRef
82
+ ? idMaps[descriptor.kind]?.[currentRef]
83
+ : undefined;
84
+ if (!currentRef || !nextRef || nextRef === currentRef) {
85
+ return [defName, def];
86
+ }
87
+
88
+ didChange = true;
89
+
90
+ return [
91
+ defName,
92
+ {
93
+ ...def,
94
+ settings: {
95
+ ...(def.settings ?? {}),
96
+ [descriptor.settingsKey]: nextRef,
97
+ },
98
+ },
99
+ ];
100
+ }),
101
+ ) as WorkflowDefinition['defs'];
102
+
103
+ if (!didChange) {
104
+ return definition;
105
+ }
106
+
107
+ return {
108
+ ...definition,
109
+ defs: nextDefs,
110
+ };
111
+ };
@@ -17,6 +17,7 @@ import { RunnerRuntimeControl } from './runner-runtime-control';
17
17
  import { executeConditional as runConditionalExecutor } from './step-executors/conditional-executor';
18
18
  import { executeLoop as runLoopExecutor } from './step-executors/loop-executor';
19
19
  import { executeParallel as runParallelExecutor } from './step-executors/parallel-executor';
20
+ import { wrapSuspensionContinuation } from './step-executors/suspension-continuation';
20
21
  import { executeTaskStep as runTaskExecutor } from './step-executors/task-executor';
21
22
  import type { StepExecutorEnv } from './step-executors/types';
22
23
  import {
@@ -552,17 +553,9 @@ export class WorkflowRunner {
552
553
  const suspension = await this.executeStep(step, state, stepPath);
553
554
 
554
555
  if (suspension) {
555
- return {
556
- ...suspension,
557
- continue: async (resumeData: unknown) => {
558
- const next = await suspension.continue(resumeData);
559
- if (next) {
560
- return next;
561
- }
562
-
563
- return this.executeFlow(steps, state, path, index + 1);
564
- },
565
- };
556
+ return wrapSuspensionContinuation(suspension, () =>
557
+ this.executeFlow(steps, state, path, index + 1),
558
+ );
566
559
  }
567
560
  }
568
561