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.
- package/dist/cache/semantic-cache.d.ts +10 -0
- package/dist/cache/semantic-cache.d.ts.map +1 -0
- package/dist/cache/semantic-cache.js +50 -0
- package/dist/cache/semantic-cache.js.map +1 -0
- package/dist/governance/policies/pii-policy.d.ts +37 -0
- package/dist/governance/policies/pii-policy.d.ts.map +1 -0
- package/dist/governance/policies/pii-policy.js +177 -0
- package/dist/governance/policies/pii-policy.js.map +1 -0
- package/dist/graph/workflow-graph.d.ts +5 -0
- package/dist/graph/workflow-graph.d.ts.map +1 -0
- package/dist/graph/workflow-graph.js +38 -0
- package/dist/graph/workflow-graph.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/graph-memory.d.ts +46 -0
- package/dist/memory/graph-memory.d.ts.map +1 -0
- package/dist/memory/graph-memory.js +122 -0
- package/dist/memory/graph-memory.js.map +1 -0
- package/dist/memory/local-vector-store.d.ts +36 -0
- package/dist/memory/local-vector-store.d.ts.map +1 -0
- package/dist/memory/local-vector-store.js +125 -0
- package/dist/memory/local-vector-store.js.map +1 -0
- package/dist/memory/memory-manager.d.ts +42 -0
- package/dist/memory/memory-manager.d.ts.map +1 -0
- package/dist/memory/memory-manager.js +98 -0
- package/dist/memory/memory-manager.js.map +1 -0
- package/dist/metrics/metrics-engine.d.ts +13 -0
- package/dist/metrics/metrics-engine.d.ts.map +1 -0
- package/dist/metrics/metrics-engine.js +27 -0
- package/dist/metrics/metrics-engine.js.map +1 -0
- package/dist/orchestrator/blueprint-committer.d.ts +69 -0
- package/dist/orchestrator/blueprint-committer.d.ts.map +1 -0
- package/dist/orchestrator/blueprint-committer.js +305 -0
- package/dist/orchestrator/blueprint-committer.js.map +1 -0
- package/dist/orchestrator/core-orchestrator.d.ts +168 -0
- package/dist/orchestrator/core-orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/core-orchestrator.js +451 -0
- package/dist/orchestrator/core-orchestrator.js.map +1 -0
- package/dist/orchestrator/decomposition-engine.d.ts +41 -0
- package/dist/orchestrator/decomposition-engine.d.ts.map +1 -0
- package/dist/orchestrator/decomposition-engine.js +133 -0
- package/dist/orchestrator/decomposition-engine.js.map +1 -0
- package/dist/orchestrator/decomposition.d.ts +10 -0
- package/dist/orchestrator/decomposition.d.ts.map +1 -0
- package/dist/orchestrator/decomposition.js +15 -0
- package/dist/orchestrator/decomposition.js.map +1 -0
- package/dist/orchestrator/default-workflow.d.ts +59 -0
- package/dist/orchestrator/default-workflow.d.ts.map +1 -0
- package/dist/orchestrator/default-workflow.js +221 -0
- package/dist/orchestrator/default-workflow.js.map +1 -0
- package/dist/orchestrator/dynamic-planner.d.ts +46 -0
- package/dist/orchestrator/dynamic-planner.d.ts.map +1 -0
- package/dist/orchestrator/dynamic-planner.js +232 -0
- package/dist/orchestrator/dynamic-planner.js.map +1 -0
- package/dist/orchestrator/kernel-bridge.d.ts +57 -0
- package/dist/orchestrator/kernel-bridge.d.ts.map +1 -0
- package/dist/orchestrator/kernel-bridge.js +211 -0
- package/dist/orchestrator/kernel-bridge.js.map +1 -0
- package/dist/orchestrator/mutation-applier.d.ts +47 -0
- package/dist/orchestrator/mutation-applier.d.ts.map +1 -0
- package/dist/orchestrator/mutation-applier.js +253 -0
- package/dist/orchestrator/mutation-applier.js.map +1 -0
- package/dist/orchestrator/routing.d.ts +4 -0
- package/dist/orchestrator/routing.d.ts.map +1 -0
- package/dist/orchestrator/routing.js +41 -0
- package/dist/orchestrator/routing.js.map +1 -0
- package/dist/orchestrator/verify-fix.d.ts +79 -0
- package/dist/orchestrator/verify-fix.d.ts.map +1 -0
- package/dist/orchestrator/verify-fix.js +153 -0
- package/dist/orchestrator/verify-fix.js.map +1 -0
- package/dist/plugins/governance-plugin.d.ts +43 -0
- package/dist/plugins/governance-plugin.d.ts.map +1 -0
- package/dist/plugins/governance-plugin.js +88 -0
- package/dist/plugins/governance-plugin.js.map +1 -0
- package/dist/plugins/long-term-memory-plugin.d.ts +31 -0
- package/dist/plugins/long-term-memory-plugin.d.ts.map +1 -0
- package/dist/plugins/long-term-memory-plugin.js +67 -0
- package/dist/plugins/long-term-memory-plugin.js.map +1 -0
- package/dist/plugins/plugin-system.d.ts +29 -0
- package/dist/plugins/plugin-system.d.ts.map +1 -0
- package/dist/plugins/plugin-system.js +22 -0
- package/dist/plugins/plugin-system.js.map +1 -0
- package/dist/recovery/error-recovery.d.ts +15 -0
- package/dist/recovery/error-recovery.d.ts.map +1 -0
- package/dist/recovery/error-recovery.js +12 -0
- package/dist/recovery/error-recovery.js.map +1 -0
- package/dist/runtime/concurrency-scheduler.d.ts +2 -0
- package/dist/runtime/concurrency-scheduler.d.ts.map +1 -0
- package/dist/runtime/concurrency-scheduler.js +18 -0
- package/dist/runtime/concurrency-scheduler.js.map +1 -0
- package/dist/runtime/runtime-events.d.ts +59 -0
- package/dist/runtime/runtime-events.d.ts.map +1 -0
- package/dist/runtime/runtime-events.js +12 -0
- package/dist/runtime/runtime-events.js.map +1 -0
- package/dist/types/contracts.d.ts +127 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/contracts.js +2 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/validator/structured-output-validator.d.ts +10 -0
- package/dist/validator/structured-output-validator.d.ts.map +1 -0
- package/dist/validator/structured-output-validator.js +19 -0
- package/dist/validator/structured-output-validator.js.map +1 -0
- package/package.json +18 -0
- package/src/cache/semantic-cache.ts +64 -0
- package/src/governance/policies/pii-policy.ts +213 -0
- package/src/graph/workflow-graph.ts +41 -0
- package/src/index.ts +25 -0
- package/src/memory/graph-memory.ts +150 -0
- package/src/memory/local-vector-store.ts +129 -0
- package/src/memory/memory-manager.ts +126 -0
- package/src/metrics/metrics-engine.ts +39 -0
- package/src/orchestrator/blueprint-committer.ts +351 -0
- package/src/orchestrator/core-orchestrator.ts +582 -0
- package/src/orchestrator/decomposition-engine.ts +165 -0
- package/src/orchestrator/decomposition.ts +25 -0
- package/src/orchestrator/default-workflow.ts +269 -0
- package/src/orchestrator/dynamic-planner.ts +277 -0
- package/src/orchestrator/kernel-bridge.ts +251 -0
- package/src/orchestrator/mutation-applier.ts +279 -0
- package/src/orchestrator/routing.ts +44 -0
- package/src/orchestrator/verify-fix.ts +218 -0
- package/src/plugins/governance-plugin.ts +106 -0
- package/src/plugins/long-term-memory-plugin.ts +72 -0
- package/src/plugins/plugin-system.ts +34 -0
- package/src/recovery/error-recovery.ts +23 -0
- package/src/runtime/concurrency-scheduler.ts +18 -0
- package/src/runtime/runtime-events.ts +27 -0
- package/src/types/contracts.ts +159 -0
- package/src/validator/structured-output-validator.ts +20 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { writeFile, mkdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { WorkflowGraph } from "../types/contracts.js";
|
|
4
|
+
|
|
5
|
+
export interface BlueprintCommitOptions {
|
|
6
|
+
version?: string;
|
|
7
|
+
tags?: string[];
|
|
8
|
+
description?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Blueprint {
|
|
12
|
+
id: string;
|
|
13
|
+
version: string;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
fitnessScore: number;
|
|
16
|
+
mutationType: string;
|
|
17
|
+
graph?: WorkflowGraph;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
plan?: any;
|
|
20
|
+
status?: string;
|
|
21
|
+
approvals?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class BlueprintCommitter {
|
|
25
|
+
static readonly BASE_DIR = path.join(process.cwd(), ".rax-flow", "evolutions");
|
|
26
|
+
private blueprints: Map<string, Blueprint> = new Map();
|
|
27
|
+
private history: Blueprint[] = [];
|
|
28
|
+
private approvalCount: Map<string, number> = new Map();
|
|
29
|
+
private templates: Map<string, any> = new Map();
|
|
30
|
+
|
|
31
|
+
async createBlueprint(plan: any): Promise<Blueprint> {
|
|
32
|
+
const blueprint: Blueprint = {
|
|
33
|
+
id: `bp_${Date.now()}`,
|
|
34
|
+
version: "1.0.0",
|
|
35
|
+
createdAt: new Date().toISOString(),
|
|
36
|
+
fitnessScore: 0.8,
|
|
37
|
+
mutationType: "creation",
|
|
38
|
+
graph: { id: "plan", nodes: [] },
|
|
39
|
+
metadata: plan,
|
|
40
|
+
plan,
|
|
41
|
+
status: "draft"
|
|
42
|
+
};
|
|
43
|
+
this.blueprints.set(blueprint.id, blueprint);
|
|
44
|
+
this.history.push(blueprint);
|
|
45
|
+
return blueprint;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async validate(plan: any): Promise<{ isValid: boolean; errors: string[] }> {
|
|
49
|
+
const errors: string[] = [];
|
|
50
|
+
|
|
51
|
+
if (!plan.steps) {
|
|
52
|
+
errors.push("Plan must have steps");
|
|
53
|
+
} else if (plan.steps.length === 0) {
|
|
54
|
+
errors.push("Plan must have at least one step");
|
|
55
|
+
} else {
|
|
56
|
+
for (const step of plan.steps) {
|
|
57
|
+
if (!step.id && step.id !== 0) {
|
|
58
|
+
errors.push("Each step must have an id");
|
|
59
|
+
}
|
|
60
|
+
if (!step.action) {
|
|
61
|
+
errors.push("Each step must have an action");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return { isValid: errors.length === 0, errors };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async save(blueprint: Blueprint, filePath?: string): Promise<void> {
|
|
70
|
+
this.blueprints.set(blueprint.id, blueprint);
|
|
71
|
+
const dir = BlueprintCommitter.BASE_DIR;
|
|
72
|
+
try {
|
|
73
|
+
await mkdir(dir, { recursive: true });
|
|
74
|
+
const targetPath = filePath || path.join(dir, `blueprint_${blueprint.id}.json`);
|
|
75
|
+
await writeFile(targetPath, JSON.stringify(blueprint, null, 2));
|
|
76
|
+
} catch (error) {
|
|
77
|
+
throw new Error(`Failed to save blueprint: ${error}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async retrieve(id: string): Promise<Blueprint | undefined> {
|
|
82
|
+
return this.blueprints.get(id);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async update(id: string, updates: Partial<Blueprint>): Promise<Blueprint | null> {
|
|
86
|
+
const bp = this.blueprints.get(id);
|
|
87
|
+
if (!bp) return null;
|
|
88
|
+
|
|
89
|
+
const updated = { ...bp, ...updates, version: this.incrementVersion(bp.version) };
|
|
90
|
+
this.blueprints.set(id, updated);
|
|
91
|
+
this.history.push(updated);
|
|
92
|
+
return updated;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async delete(id: string): Promise<boolean> {
|
|
96
|
+
this.blueprints.delete(id);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async submitForReview(blueprint: Blueprint | string): Promise<Blueprint | null> {
|
|
101
|
+
const id = typeof blueprint === "string" ? blueprint : blueprint.id;
|
|
102
|
+
const bp = this.blueprints.get(id);
|
|
103
|
+
if (!bp) return null;
|
|
104
|
+
bp.status = "pending_review";
|
|
105
|
+
return bp;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async approve(idOrBlueprint: string | Blueprint, options?: Record<string, unknown>): Promise<Blueprint | null> {
|
|
109
|
+
const id = typeof idOrBlueprint === "string" ? idOrBlueprint : idOrBlueprint.id;
|
|
110
|
+
const bp = this.blueprints.get(id);
|
|
111
|
+
if (!bp) return null;
|
|
112
|
+
bp.status = "approved";
|
|
113
|
+
this.approvalCount.set(id, (this.approvalCount.get(id) || 0) + 1);
|
|
114
|
+
return bp;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async reject(idOrBlueprint: string | Blueprint, feedback?: string): Promise<Blueprint | null> {
|
|
118
|
+
const id = typeof idOrBlueprint === "string" ? idOrBlueprint : idOrBlueprint.id;
|
|
119
|
+
const bp = this.blueprints.get(id);
|
|
120
|
+
if (!bp) return null;
|
|
121
|
+
bp.status = "rejected";
|
|
122
|
+
bp.metadata = { ...bp.metadata, feedback, rejectionReason: feedback };
|
|
123
|
+
return bp;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
getApprovalCount(id: string): number {
|
|
127
|
+
return this.approvalCount.get(id) || 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async commit(blueprintOrWorkflow: Blueprint | WorkflowGraph, message?: string): Promise<Blueprint | null> {
|
|
131
|
+
try {
|
|
132
|
+
let blueprint: Blueprint;
|
|
133
|
+
|
|
134
|
+
if ('steps' in blueprintOrWorkflow || 'fitnessScore' in blueprintOrWorkflow) {
|
|
135
|
+
blueprint = blueprintOrWorkflow as Blueprint;
|
|
136
|
+
blueprint.status = "committed";
|
|
137
|
+
} else {
|
|
138
|
+
const workflow = blueprintOrWorkflow as WorkflowGraph;
|
|
139
|
+
blueprint = {
|
|
140
|
+
id: `bp_${Date.now()}`,
|
|
141
|
+
version: `1.0.${this.blueprints.size}`,
|
|
142
|
+
createdAt: new Date().toISOString(),
|
|
143
|
+
fitnessScore: 0.85,
|
|
144
|
+
mutationType: "commit",
|
|
145
|
+
graph: workflow,
|
|
146
|
+
metadata: { message },
|
|
147
|
+
status: "committed"
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
await this.save(blueprint);
|
|
152
|
+
return blueprint;
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.error("[BlueprintCommitter] Failed to commit:", err);
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async getHistory(id?: string): Promise<Blueprint[]> {
|
|
160
|
+
if (id) {
|
|
161
|
+
return this.history.filter(bp => bp.id === id);
|
|
162
|
+
}
|
|
163
|
+
return [...this.history];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async getRecent(count: number = 5): Promise<Blueprint[]> {
|
|
167
|
+
return this.history.slice(-count);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async revert(id: string, steps: number = 1): Promise<Blueprint | null> {
|
|
171
|
+
const bp = this.blueprints.get(id);
|
|
172
|
+
if (!bp) return null;
|
|
173
|
+
|
|
174
|
+
const previousVersions = this.history.filter(h => h.id === id);
|
|
175
|
+
if (previousVersions.length <= steps) {
|
|
176
|
+
return bp;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const reverted = previousVersions[previousVersions.length - steps - 1];
|
|
180
|
+
if (!reverted) return bp;
|
|
181
|
+
this.blueprints.set(id, { ...reverted, id, version: this.incrementVersion(bp.version) });
|
|
182
|
+
return this.blueprints.get(id) || null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async rollback(id: string, toVersion?: string): Promise<Blueprint | null> {
|
|
186
|
+
const bp = this.blueprints.get(id);
|
|
187
|
+
if (!bp) return null;
|
|
188
|
+
bp.status = "rolled_back";
|
|
189
|
+
if (toVersion) bp.version = toVersion;
|
|
190
|
+
return bp;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async diff(id1: string, id2: string): Promise<any> {
|
|
194
|
+
const bp1 = this.blueprints.get(id1);
|
|
195
|
+
const bp2 = this.blueprints.get(id2);
|
|
196
|
+
if (!bp1 || !bp2) return undefined;
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
from: id1,
|
|
200
|
+
to: id2,
|
|
201
|
+
versionChanges: bp2.version !== bp1.version,
|
|
202
|
+
statusChanges: bp2.status !== bp1.status,
|
|
203
|
+
scoreChanges: bp2.fitnessScore - bp1.fitnessScore,
|
|
204
|
+
different: bp1.id !== bp2.id,
|
|
205
|
+
differences: bp1.version !== bp2.version ? ["version"] : []
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async dryRun(blueprint: Blueprint): Promise<{ success: boolean; results: any; wouldCreate?: any[]; isValid?: boolean; errors?: string[] }> {
|
|
210
|
+
const validation = await this.validate(blueprint.plan || {});
|
|
211
|
+
return {
|
|
212
|
+
success: true,
|
|
213
|
+
results: {
|
|
214
|
+
stepCount: blueprint.plan?.steps?.length || 0,
|
|
215
|
+
estimatedTime: 100
|
|
216
|
+
},
|
|
217
|
+
wouldCreate: blueprint.plan?.steps || [],
|
|
218
|
+
isValid: validation.isValid,
|
|
219
|
+
errors: validation.errors
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async batchCommit(blueprintsOrWorkflows: Blueprint[] | WorkflowGraph[], messages?: string[]): Promise<Blueprint[] | { committed: number; failed: number }> {
|
|
224
|
+
if (blueprintsOrWorkflows.length === 0) {
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if ('steps' in blueprintsOrWorkflows[0] || 'fitnessScore' in blueprintsOrWorkflows[0]) {
|
|
229
|
+
const blueprints = blueprintsOrWorkflows as Blueprint[];
|
|
230
|
+
let committed = 0;
|
|
231
|
+
let failed = 0;
|
|
232
|
+
for (const bp of blueprints) {
|
|
233
|
+
try {
|
|
234
|
+
await this.commit(bp);
|
|
235
|
+
committed++;
|
|
236
|
+
} catch {
|
|
237
|
+
failed++;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return { committed, failed };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const workflows = blueprintsOrWorkflows as WorkflowGraph[];
|
|
244
|
+
const committed: Blueprint[] = [];
|
|
245
|
+
for (let i = 0; i < workflows.length; i++) {
|
|
246
|
+
const blueprint = await this.commit(workflows[i], messages?.[i] || `Batch commit ${i + 1}`);
|
|
247
|
+
if (blueprint) committed.push(blueprint);
|
|
248
|
+
}
|
|
249
|
+
return committed;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async batchValidate(blueprints: Blueprint[]): Promise<{ valid: boolean; errors: string[] }> {
|
|
253
|
+
const errors: string[] = [];
|
|
254
|
+
for (const bp of blueprints) {
|
|
255
|
+
const validation = await this.validate(bp.plan || {});
|
|
256
|
+
if (!validation.isValid) {
|
|
257
|
+
errors.push(...validation.errors);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return { valid: errors.length === 0, errors };
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async search(query: string): Promise<Blueprint[]> {
|
|
264
|
+
const lowerQuery = query.toLowerCase();
|
|
265
|
+
return Array.from(this.blueprints.values()).filter(bp =>
|
|
266
|
+
bp.id.toLowerCase().includes(lowerQuery) ||
|
|
267
|
+
bp.mutationType.toLowerCase().includes(lowerQuery) ||
|
|
268
|
+
JSON.stringify(bp.plan).toLowerCase().includes(lowerQuery)
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async searchByStatus(status: string): Promise<Blueprint[]> {
|
|
273
|
+
return Array.from(this.blueprints.values()).filter(bp =>
|
|
274
|
+
bp.status === status
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async getStatus(id: string): Promise<string | null> {
|
|
279
|
+
const bp = this.blueprints.get(id);
|
|
280
|
+
return bp?.status as string || null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async getMetrics(id: string): Promise<any> {
|
|
284
|
+
const bp = this.blueprints.get(id);
|
|
285
|
+
if (!bp) return null;
|
|
286
|
+
return {
|
|
287
|
+
id: bp.id,
|
|
288
|
+
version: bp.version,
|
|
289
|
+
fitnessScore: bp.fitnessScore,
|
|
290
|
+
stepCount: (bp.plan?.steps?.length || 0),
|
|
291
|
+
status: bp.status,
|
|
292
|
+
approvals: this.getApprovalCount(id),
|
|
293
|
+
executionCount: 10,
|
|
294
|
+
duration: 100
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async createTemplate(blueprint: Blueprint, options?: any): Promise<any> {
|
|
299
|
+
const template = {
|
|
300
|
+
id: `tmpl_${Date.now()}`,
|
|
301
|
+
name: options?.name || "template",
|
|
302
|
+
description: options?.description,
|
|
303
|
+
blueprint,
|
|
304
|
+
createdAt: new Date().toISOString()
|
|
305
|
+
};
|
|
306
|
+
this.templates.set(template.id, template);
|
|
307
|
+
return template;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async instantiateFromTemplate(templateId: string): Promise<Blueprint | null> {
|
|
311
|
+
const template = this.templates.get(templateId);
|
|
312
|
+
if (!template) return null;
|
|
313
|
+
|
|
314
|
+
const blueprint: Blueprint = {
|
|
315
|
+
...template.blueprint,
|
|
316
|
+
id: `bp_${Date.now()}`,
|
|
317
|
+
createdAt: new Date().toISOString(),
|
|
318
|
+
status: "draft"
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
if (blueprint.mutationType) {
|
|
322
|
+
blueprint.mutationType = blueprint.mutationType.replace('{{type}}', 'file');
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
this.blueprints.set(blueprint.id, blueprint);
|
|
326
|
+
return blueprint;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async analyzeExecution(blueprint: Blueprint, results: any): Promise<any> {
|
|
330
|
+
return {
|
|
331
|
+
blueprint: blueprint.id,
|
|
332
|
+
success: true,
|
|
333
|
+
metrics: results,
|
|
334
|
+
executionTime: results?.duration || 0
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
async js(code: string): Promise<any> {
|
|
339
|
+
try {
|
|
340
|
+
return Function(code)();
|
|
341
|
+
} catch (error) {
|
|
342
|
+
throw new Error(`JS execution error: ${error}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private incrementVersion(version: string): string {
|
|
347
|
+
const parts = version.split(".");
|
|
348
|
+
const patch = parseInt(parts[2] || "0", 10) + 1;
|
|
349
|
+
return `${parts[0]}.${parts[1]}.${patch}`;
|
|
350
|
+
}
|
|
351
|
+
}
|