rax-flow-core 0.1.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 (132) hide show
  1. package/dist/cache/semantic-cache.d.ts +10 -0
  2. package/dist/cache/semantic-cache.d.ts.map +1 -0
  3. package/dist/cache/semantic-cache.js +50 -0
  4. package/dist/cache/semantic-cache.js.map +1 -0
  5. package/dist/governance/policies/pii-policy.d.ts +37 -0
  6. package/dist/governance/policies/pii-policy.d.ts.map +1 -0
  7. package/dist/governance/policies/pii-policy.js +177 -0
  8. package/dist/governance/policies/pii-policy.js.map +1 -0
  9. package/dist/graph/workflow-graph.d.ts +5 -0
  10. package/dist/graph/workflow-graph.d.ts.map +1 -0
  11. package/dist/graph/workflow-graph.js +38 -0
  12. package/dist/graph/workflow-graph.js.map +1 -0
  13. package/dist/index.d.ts +25 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +25 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/memory/graph-memory.d.ts +46 -0
  18. package/dist/memory/graph-memory.d.ts.map +1 -0
  19. package/dist/memory/graph-memory.js +122 -0
  20. package/dist/memory/graph-memory.js.map +1 -0
  21. package/dist/memory/local-vector-store.d.ts +36 -0
  22. package/dist/memory/local-vector-store.d.ts.map +1 -0
  23. package/dist/memory/local-vector-store.js +125 -0
  24. package/dist/memory/local-vector-store.js.map +1 -0
  25. package/dist/memory/memory-manager.d.ts +42 -0
  26. package/dist/memory/memory-manager.d.ts.map +1 -0
  27. package/dist/memory/memory-manager.js +98 -0
  28. package/dist/memory/memory-manager.js.map +1 -0
  29. package/dist/metrics/metrics-engine.d.ts +13 -0
  30. package/dist/metrics/metrics-engine.d.ts.map +1 -0
  31. package/dist/metrics/metrics-engine.js +27 -0
  32. package/dist/metrics/metrics-engine.js.map +1 -0
  33. package/dist/orchestrator/blueprint-committer.d.ts +69 -0
  34. package/dist/orchestrator/blueprint-committer.d.ts.map +1 -0
  35. package/dist/orchestrator/blueprint-committer.js +305 -0
  36. package/dist/orchestrator/blueprint-committer.js.map +1 -0
  37. package/dist/orchestrator/core-orchestrator.d.ts +168 -0
  38. package/dist/orchestrator/core-orchestrator.d.ts.map +1 -0
  39. package/dist/orchestrator/core-orchestrator.js +451 -0
  40. package/dist/orchestrator/core-orchestrator.js.map +1 -0
  41. package/dist/orchestrator/decomposition-engine.d.ts +41 -0
  42. package/dist/orchestrator/decomposition-engine.d.ts.map +1 -0
  43. package/dist/orchestrator/decomposition-engine.js +133 -0
  44. package/dist/orchestrator/decomposition-engine.js.map +1 -0
  45. package/dist/orchestrator/decomposition.d.ts +10 -0
  46. package/dist/orchestrator/decomposition.d.ts.map +1 -0
  47. package/dist/orchestrator/decomposition.js +15 -0
  48. package/dist/orchestrator/decomposition.js.map +1 -0
  49. package/dist/orchestrator/default-workflow.d.ts +59 -0
  50. package/dist/orchestrator/default-workflow.d.ts.map +1 -0
  51. package/dist/orchestrator/default-workflow.js +221 -0
  52. package/dist/orchestrator/default-workflow.js.map +1 -0
  53. package/dist/orchestrator/dynamic-planner.d.ts +46 -0
  54. package/dist/orchestrator/dynamic-planner.d.ts.map +1 -0
  55. package/dist/orchestrator/dynamic-planner.js +232 -0
  56. package/dist/orchestrator/dynamic-planner.js.map +1 -0
  57. package/dist/orchestrator/kernel-bridge.d.ts +57 -0
  58. package/dist/orchestrator/kernel-bridge.d.ts.map +1 -0
  59. package/dist/orchestrator/kernel-bridge.js +211 -0
  60. package/dist/orchestrator/kernel-bridge.js.map +1 -0
  61. package/dist/orchestrator/mutation-applier.d.ts +47 -0
  62. package/dist/orchestrator/mutation-applier.d.ts.map +1 -0
  63. package/dist/orchestrator/mutation-applier.js +253 -0
  64. package/dist/orchestrator/mutation-applier.js.map +1 -0
  65. package/dist/orchestrator/routing.d.ts +4 -0
  66. package/dist/orchestrator/routing.d.ts.map +1 -0
  67. package/dist/orchestrator/routing.js +41 -0
  68. package/dist/orchestrator/routing.js.map +1 -0
  69. package/dist/orchestrator/verify-fix.d.ts +79 -0
  70. package/dist/orchestrator/verify-fix.d.ts.map +1 -0
  71. package/dist/orchestrator/verify-fix.js +153 -0
  72. package/dist/orchestrator/verify-fix.js.map +1 -0
  73. package/dist/plugins/governance-plugin.d.ts +43 -0
  74. package/dist/plugins/governance-plugin.d.ts.map +1 -0
  75. package/dist/plugins/governance-plugin.js +88 -0
  76. package/dist/plugins/governance-plugin.js.map +1 -0
  77. package/dist/plugins/long-term-memory-plugin.d.ts +31 -0
  78. package/dist/plugins/long-term-memory-plugin.d.ts.map +1 -0
  79. package/dist/plugins/long-term-memory-plugin.js +67 -0
  80. package/dist/plugins/long-term-memory-plugin.js.map +1 -0
  81. package/dist/plugins/plugin-system.d.ts +29 -0
  82. package/dist/plugins/plugin-system.d.ts.map +1 -0
  83. package/dist/plugins/plugin-system.js +22 -0
  84. package/dist/plugins/plugin-system.js.map +1 -0
  85. package/dist/recovery/error-recovery.d.ts +15 -0
  86. package/dist/recovery/error-recovery.d.ts.map +1 -0
  87. package/dist/recovery/error-recovery.js +12 -0
  88. package/dist/recovery/error-recovery.js.map +1 -0
  89. package/dist/runtime/concurrency-scheduler.d.ts +2 -0
  90. package/dist/runtime/concurrency-scheduler.d.ts.map +1 -0
  91. package/dist/runtime/concurrency-scheduler.js +18 -0
  92. package/dist/runtime/concurrency-scheduler.js.map +1 -0
  93. package/dist/runtime/runtime-events.d.ts +59 -0
  94. package/dist/runtime/runtime-events.d.ts.map +1 -0
  95. package/dist/runtime/runtime-events.js +12 -0
  96. package/dist/runtime/runtime-events.js.map +1 -0
  97. package/dist/types/contracts.d.ts +127 -0
  98. package/dist/types/contracts.d.ts.map +1 -0
  99. package/dist/types/contracts.js +2 -0
  100. package/dist/types/contracts.js.map +1 -0
  101. package/dist/validator/structured-output-validator.d.ts +10 -0
  102. package/dist/validator/structured-output-validator.d.ts.map +1 -0
  103. package/dist/validator/structured-output-validator.js +19 -0
  104. package/dist/validator/structured-output-validator.js.map +1 -0
  105. package/package.json +18 -0
  106. package/src/cache/semantic-cache.ts +64 -0
  107. package/src/governance/policies/pii-policy.ts +213 -0
  108. package/src/graph/workflow-graph.ts +41 -0
  109. package/src/index.ts +25 -0
  110. package/src/memory/graph-memory.ts +150 -0
  111. package/src/memory/local-vector-store.ts +129 -0
  112. package/src/memory/memory-manager.ts +126 -0
  113. package/src/metrics/metrics-engine.ts +39 -0
  114. package/src/orchestrator/blueprint-committer.ts +351 -0
  115. package/src/orchestrator/core-orchestrator.ts +582 -0
  116. package/src/orchestrator/decomposition-engine.ts +165 -0
  117. package/src/orchestrator/decomposition.ts +25 -0
  118. package/src/orchestrator/default-workflow.ts +269 -0
  119. package/src/orchestrator/dynamic-planner.ts +277 -0
  120. package/src/orchestrator/kernel-bridge.ts +251 -0
  121. package/src/orchestrator/mutation-applier.ts +279 -0
  122. package/src/orchestrator/routing.ts +44 -0
  123. package/src/orchestrator/verify-fix.ts +218 -0
  124. package/src/plugins/governance-plugin.ts +106 -0
  125. package/src/plugins/long-term-memory-plugin.ts +72 -0
  126. package/src/plugins/plugin-system.ts +34 -0
  127. package/src/recovery/error-recovery.ts +23 -0
  128. package/src/runtime/concurrency-scheduler.ts +18 -0
  129. package/src/runtime/runtime-events.ts +27 -0
  130. package/src/types/contracts.ts +159 -0
  131. package/src/validator/structured-output-validator.ts +20 -0
  132. package/tsconfig.json +17 -0
@@ -0,0 +1,165 @@
1
+ import { Intent } from "../types/contracts.js";
2
+
3
+ export interface TaskChunk {
4
+ id: string;
5
+ description: string;
6
+ preferredAgent: string;
7
+ canRunInParallel: boolean;
8
+ }
9
+
10
+ export interface Subtask {
11
+ id: string;
12
+ title: string;
13
+ description: string;
14
+ estimatedDuration: number;
15
+ priority: number;
16
+ dependencies?: string[];
17
+ parallelizable: boolean;
18
+ complexity: "low" | "medium" | "high";
19
+ }
20
+
21
+ export class Decomposition {
22
+ async decompose(task: string, options?: { constraints?: { maxSubtasks?: number; maxDuration?: number } }): Promise<Subtask[]> {
23
+ const complexity = this.getComplexity(task);
24
+ const wordCount = task.split(" ").length;
25
+ const baseDuration = wordCount * 5;
26
+
27
+ const subtasks: Subtask[] = [
28
+ {
29
+ id: "analyze",
30
+ title: "Analyze Requirements",
31
+ description: `Analyze: ${task}`,
32
+ estimatedDuration: baseDuration * 0.2,
33
+ priority: 1,
34
+ parallelizable: false,
35
+ complexity
36
+ },
37
+ {
38
+ id: "design",
39
+ title: "Design Solution",
40
+ description: "Design technical solution",
41
+ estimatedDuration: baseDuration * 0.3,
42
+ priority: 2,
43
+ dependencies: ["analyze"],
44
+ parallelizable: false,
45
+ complexity
46
+ },
47
+ {
48
+ id: "implement",
49
+ title: "Implement",
50
+ description: "Implement the solution",
51
+ estimatedDuration: baseDuration * 0.3,
52
+ priority: 3,
53
+ dependencies: ["design"],
54
+ parallelizable: complexity === "low",
55
+ complexity
56
+ },
57
+ {
58
+ id: "test",
59
+ title: "Test & Validate",
60
+ description: "Test and validate",
61
+ estimatedDuration: baseDuration * 0.2,
62
+ priority: 4,
63
+ dependencies: ["implement"],
64
+ parallelizable: true,
65
+ complexity
66
+ }
67
+ ];
68
+
69
+ // Apply constraints
70
+ if (options?.constraints?.maxSubtasks) {
71
+ return subtasks.slice(0, Math.min(options.constraints.maxSubtasks, subtasks.length));
72
+ }
73
+
74
+ return subtasks;
75
+ }
76
+
77
+ private getComplexity(task: string): "low" | "medium" | "high" {
78
+ const complexKeywords = ["distributed", "replication", "concurrent", "async", "architecture"];
79
+ const hasComplex = complexKeywords.some(kw => task.toLowerCase().includes(kw));
80
+ const wordCount = task.split(" ").length;
81
+
82
+ if (hasComplex || wordCount > 15) return "high";
83
+ if (wordCount > 8) return "medium";
84
+ return "low";
85
+ }
86
+
87
+ async analyzeComplexity(task: string): Promise<{ complexity: "low" | "medium" | "high"; score: number }> {
88
+ const complexity = this.getComplexity(task);
89
+ const scoreMap = { low: 1, medium: 5, high: 9 };
90
+ return {
91
+ complexity,
92
+ score: scoreMap[complexity]
93
+ };
94
+ }
95
+
96
+ analyzeDependencies(subtasks: Subtask[]): Map<string, string[]> {
97
+ const deps = new Map<string, string[]>();
98
+ for (const task of subtasks) {
99
+ deps.set(task.id, task.dependencies || []);
100
+ }
101
+ return deps;
102
+ }
103
+
104
+ buildHierarchy(subtasks: Subtask[]) {
105
+ return {
106
+ id: "root",
107
+ title: "Main Task",
108
+ children: subtasks,
109
+ totalDuration: subtasks.reduce((sum, t) => sum + t.estimatedDuration, 0)
110
+ };
111
+ }
112
+
113
+ optimizeOrder(subtasks: Subtask[]): Subtask[] {
114
+ const sorted = [...subtasks].sort((a, b) => {
115
+ if (a.dependencies?.includes(b.id)) return 1;
116
+ if (b.dependencies?.includes(a.id)) return -1;
117
+ return a.priority - b.priority;
118
+ });
119
+ return sorted;
120
+ }
121
+
122
+ detectParallel(subtasks: Subtask[]): Subtask[][] {
123
+ const batches: Subtask[][] = [];
124
+ const processed = new Set<string>();
125
+
126
+ for (const task of subtasks) {
127
+ if (processed.has(task.id)) continue;
128
+
129
+ const batch: Subtask[] = [task];
130
+ processed.add(task.id);
131
+
132
+ if (task.parallelizable) {
133
+ for (const other of subtasks) {
134
+ if (!processed.has(other.id) && other.parallelizable) {
135
+ const canParallelize = !task.dependencies?.includes(other.id) && !other.dependencies?.includes(task.id);
136
+ if (canParallelize) {
137
+ batch.push(other);
138
+ processed.add(other.id);
139
+ }
140
+ }
141
+ }
142
+ }
143
+
144
+ batches.push(batch);
145
+ }
146
+
147
+ return batches;
148
+ }
149
+ }
150
+
151
+ export function decomposeTask(intent: Intent, prompt: string): TaskChunk[] {
152
+ const base = [
153
+ { id: "analyze", description: `Analyze: ${prompt}`, preferredAgent: "IntentClassifierAgent", canRunInParallel: false },
154
+ { id: "spec", description: "Draft technical specification", preferredAgent: "SpecAgent", canRunInParallel: false },
155
+ { id: "implement", description: "Produce implementation artifacts", preferredAgent: "CodeGeneratorAgent", canRunInParallel: intent !== "architecture" },
156
+ { id: "verify", description: "Run tests and validate schema", preferredAgent: "ValidatorAgent", canRunInParallel: true },
157
+ { id: "fix", description: "Fix detected issues", preferredAgent: "FixAgent", canRunInParallel: false }
158
+ ];
159
+
160
+ if (intent === "benchmark") {
161
+ base.push({ id: "benchmark", description: "Generate benchmark report", preferredAgent: "BenchmarkAgent", canRunInParallel: true });
162
+ }
163
+
164
+ return base;
165
+ }
@@ -0,0 +1,25 @@
1
+ import { Intent } from "../types/contracts.js";
2
+ export { Decomposition, Subtask } from "./decomposition-engine.js";
3
+
4
+ export interface TaskChunk {
5
+ id: string;
6
+ description: string;
7
+ preferredAgent: string;
8
+ canRunInParallel: boolean;
9
+ }
10
+
11
+ export function decomposeTask(intent: Intent, prompt: string): TaskChunk[] {
12
+ const base = [
13
+ { id: "analyze", description: `Analyze: ${prompt}`, preferredAgent: "IntentClassifierAgent", canRunInParallel: false },
14
+ { id: "spec", description: "Draft technical specification", preferredAgent: "SpecAgent", canRunInParallel: false },
15
+ { id: "implement", description: "Produce implementation artifacts", preferredAgent: "CodeGeneratorAgent", canRunInParallel: intent !== "architecture" },
16
+ { id: "verify", description: "Run tests and validate schema", preferredAgent: "ValidatorAgent", canRunInParallel: true },
17
+ { id: "fix", description: "Fix detected issues", preferredAgent: "FixAgent", canRunInParallel: false }
18
+ ];
19
+
20
+ if (intent === "benchmark") {
21
+ base.push({ id: "benchmark", description: "Generate benchmark report", preferredAgent: "BenchmarkAgent", canRunInParallel: true });
22
+ }
23
+
24
+ return base;
25
+ }
@@ -0,0 +1,269 @@
1
+ import { WorkflowGraph } from "../types/contracts.js";
2
+ import { TaskChunk } from "./decomposition.js";
3
+
4
+ export interface WorkflowStep {
5
+ id: string;
6
+ action?: Function | string;
7
+ condition?: () => boolean;
8
+ retries?: number;
9
+ timeout?: number;
10
+ }
11
+
12
+ export interface WorkflowDefinition {
13
+ id?: string;
14
+ steps: WorkflowStep[];
15
+ metadata?: Record<string, any>;
16
+ status?: string;
17
+ state?: Record<string, any>;
18
+ context?: Record<string, any>;
19
+ }
20
+
21
+ export class DefaultWorkflow {
22
+ private defaultSteps: WorkflowStep[] = [
23
+ { id: "init", action: () => {} },
24
+ { id: "process", action: () => {} },
25
+ { id: "finalize", action: () => {} }
26
+ ];
27
+ private workflowState: Record<string, any> = {};
28
+ private workflowStatus: string = "created";
29
+ private workflowContext: Record<string, any> = {};
30
+ private eventLog: string[] = [];
31
+ private savedState: Record<string, any> = {};
32
+
33
+ create(): WorkflowDefinition {
34
+ return {
35
+ id: `workflow_${Date.now()}`,
36
+ steps: JSON.parse(JSON.stringify(this.defaultSteps)),
37
+ status: "created",
38
+ state: {},
39
+ context: {}
40
+ };
41
+ }
42
+
43
+ async init(workflow?: WorkflowDefinition): Promise<WorkflowDefinition> {
44
+ const flow = workflow || this.create();
45
+ this.workflowStatus = "initialized";
46
+ this.eventLog.push("init");
47
+ return { ...flow, status: "initialized" };
48
+ }
49
+
50
+ async execute(flow: WorkflowDefinition, options?: { continueOnError?: boolean }): Promise<any> {
51
+ const results: any[] = [];
52
+ let completedSteps = 0;
53
+ this.workflowStatus = "running";
54
+ this.eventLog.push("start");
55
+
56
+ for (const step of flow.steps) {
57
+ try {
58
+ if (step.condition && !step.condition()) {
59
+ results.push({ stepId: step.id, status: "skipped" });
60
+ continue;
61
+ }
62
+ if (step.action && typeof step.action === 'function') {
63
+ await step.action();
64
+ }
65
+ results.push({ stepId: step.id, status: "completed" });
66
+ completedSteps++;
67
+ this.eventLog.push(step.id);
68
+ } catch (error) {
69
+ const errorMsg = error instanceof Error ? error.message : String(error);
70
+ this.eventLog.push(errorMsg);
71
+ if (!options?.continueOnError) {
72
+ results.push({ stepId: step.id, status: "failed", error });
73
+ throw error;
74
+ }
75
+ results.push({ stepId: step.id, status: "failed", error });
76
+ }
77
+ }
78
+
79
+ this.workflowStatus = "completed";
80
+ this.eventLog.push("end");
81
+ return { results, completedSteps, status: "completed" };
82
+ }
83
+
84
+ async executeSteps(steps: WorkflowStep[], context?: Record<string, any>): Promise<any[]> {
85
+ const results: any[] = [];
86
+ for (const step of steps) {
87
+ try {
88
+ if (step.action && typeof step.action === 'function') {
89
+ const result = await step.action();
90
+ results.push(result);
91
+ } else {
92
+ results.push(undefined);
93
+ }
94
+ } catch (error) {
95
+ results.push({ error });
96
+ }
97
+ }
98
+ return results;
99
+ }
100
+
101
+ validate(flow?: WorkflowDefinition): { isValid: boolean; errors: string[] } {
102
+ const errors: string[] = [];
103
+
104
+ if (!flow) {
105
+ return { isValid: true, errors };
106
+ }
107
+
108
+ if (!flow.steps || !Array.isArray(flow.steps)) {
109
+ errors.push("Workflow must have steps array");
110
+ } else if (flow.steps.length === 0) {
111
+ errors.push("Workflow must have at least one step");
112
+ }
113
+
114
+ return { isValid: errors.length === 0, errors };
115
+ }
116
+
117
+ clone(flow: WorkflowDefinition): WorkflowDefinition {
118
+ return JSON.parse(JSON.stringify(flow));
119
+ }
120
+
121
+ merge(...workflows: WorkflowDefinition[]): WorkflowDefinition {
122
+ const merged: WorkflowStep[] = [];
123
+ for (const workflow of workflows) {
124
+ merged.push(...(workflow.steps || []));
125
+ }
126
+ return {
127
+ id: `merged_${Date.now()}`,
128
+ steps: merged
129
+ };
130
+ }
131
+
132
+ listSteps(): string[] {
133
+ return this.defaultSteps.map(s => s.id);
134
+ }
135
+
136
+ getStep(stepId: string): WorkflowStep | undefined {
137
+ return this.defaultSteps.find(s => s.id === stepId);
138
+ }
139
+
140
+ addStep(step: WorkflowStep): void {
141
+ this.defaultSteps.push(step);
142
+ }
143
+
144
+ removeStep(stepId: string): boolean {
145
+ const idx = this.defaultSteps.findIndex(s => s.id === stepId);
146
+ if (idx >= 0) {
147
+ this.defaultSteps.splice(idx, 1);
148
+ return true;
149
+ }
150
+ return false;
151
+ }
152
+
153
+ toGraph(id: string): WorkflowGraph {
154
+ return {
155
+ id,
156
+ nodes: this.defaultSteps.map((step, index) => ({
157
+ id: step.id,
158
+ agent: "default",
159
+ dependsOn: index === 0 ? [] : [this.defaultSteps[index - 1].id]
160
+ }))
161
+ };
162
+ }
163
+
164
+ getState(): Record<string, any> {
165
+ return { ...this.workflowState };
166
+ }
167
+
168
+ setState(state: Record<string, any>): void {
169
+ this.workflowState = { ...this.workflowState, ...state };
170
+ }
171
+
172
+ getStatus(): string {
173
+ return this.workflowStatus;
174
+ }
175
+
176
+ pause(): void {
177
+ this.workflowStatus = "paused";
178
+ this.eventLog.push("pause");
179
+ }
180
+
181
+ resume(): void {
182
+ if (this.workflowStatus === "paused") {
183
+ this.workflowStatus = "running";
184
+ this.eventLog.push("resume");
185
+ }
186
+ }
187
+
188
+ cancel(): void {
189
+ this.workflowStatus = "cancelled";
190
+ this.eventLog.push("cancel");
191
+ }
192
+
193
+ async saveState(id?: string): Promise<void> {
194
+ const workflowId = id || `workflow_${Date.now()}`;
195
+ this.savedState[workflowId] = {
196
+ state: { ...this.workflowState },
197
+ status: this.workflowStatus,
198
+ context: { ...this.workflowContext }
199
+ };
200
+ }
201
+
202
+ async loadState(id: string): Promise<void> {
203
+ const saved = this.savedState[id];
204
+ if (saved) {
205
+ this.workflowState = saved.state;
206
+ this.workflowStatus = saved.status;
207
+ this.workflowContext = saved.context;
208
+ }
209
+ }
210
+
211
+ exportDefinition(): string {
212
+ return JSON.stringify({
213
+ steps: this.defaultSteps,
214
+ state: this.workflowState,
215
+ context: this.workflowContext
216
+ });
217
+ }
218
+
219
+ importDefinition(data: string): WorkflowDefinition {
220
+ const parsed = JSON.parse(data);
221
+ this.defaultSteps = parsed.steps || [];
222
+ this.workflowState = parsed.state || {};
223
+ this.workflowContext = parsed.context || {};
224
+ return {
225
+ id: `imported_${Date.now()}`,
226
+ steps: this.defaultSteps,
227
+ state: this.workflowState,
228
+ context: this.workflowContext
229
+ };
230
+ }
231
+
232
+ getTemplates(): Record<string, WorkflowDefinition> {
233
+ return {
234
+ basic: { id: "basic", steps: [{ id: "step1" }] },
235
+ sequential: { id: "sequential", steps: [{ id: "step1" }, { id: "step2" }] }
236
+ };
237
+ }
238
+
239
+ fromTemplate(templateName: string): WorkflowDefinition | undefined {
240
+ const templates = this.getTemplates();
241
+ return templates[templateName] ? JSON.parse(JSON.stringify(templates[templateName])) : undefined;
242
+ }
243
+
244
+ getEventLog(): string[] {
245
+ return [...this.eventLog];
246
+ }
247
+
248
+ setContextValue(key: string, value: any): void {
249
+ if (!this.workflowContext) {
250
+ this.workflowContext = {};
251
+ }
252
+ this.workflowContext[key] = value;
253
+ }
254
+
255
+ getContextValue(key: string): any {
256
+ return this.workflowContext?.[key];
257
+ }
258
+ }
259
+
260
+ export function chunksToWorkflow(id: string, chunks: TaskChunk[]): WorkflowGraph {
261
+ return {
262
+ id,
263
+ nodes: chunks.map((chunk, index) => ({
264
+ id: chunk.id,
265
+ agent: chunk.preferredAgent,
266
+ dependsOn: index === 0 ? [] : [chunks[index - 1].id]
267
+ }))
268
+ };
269
+ }