@grimoirelabs/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/builders/expressions.d.ts +33 -0
- package/dist/builders/expressions.d.ts.map +1 -0
- package/dist/builders/expressions.js +57 -0
- package/dist/builders/expressions.js.map +1 -0
- package/dist/builders/index.d.ts +44 -0
- package/dist/builders/index.d.ts.map +1 -0
- package/dist/builders/index.js +32 -0
- package/dist/builders/index.js.map +1 -0
- package/dist/builders/spell-builder.d.ts +124 -0
- package/dist/builders/spell-builder.d.ts.map +1 -0
- package/dist/builders/spell-builder.js +299 -0
- package/dist/builders/spell-builder.js.map +1 -0
- package/dist/builders/step-builder.d.ts +212 -0
- package/dist/builders/step-builder.d.ts.map +1 -0
- package/dist/builders/step-builder.js +499 -0
- package/dist/builders/step-builder.js.map +1 -0
- package/dist/compiler/expression-parser.d.ts +14 -0
- package/dist/compiler/expression-parser.d.ts.map +1 -0
- package/dist/compiler/expression-parser.js +460 -0
- package/dist/compiler/expression-parser.js.map +1 -0
- package/dist/compiler/grimoire/ast.d.ts +450 -0
- package/dist/compiler/grimoire/ast.d.ts.map +1 -0
- package/dist/compiler/grimoire/ast.js +19 -0
- package/dist/compiler/grimoire/ast.js.map +1 -0
- package/dist/compiler/grimoire/errors.d.ts +65 -0
- package/dist/compiler/grimoire/errors.d.ts.map +1 -0
- package/dist/compiler/grimoire/errors.js +86 -0
- package/dist/compiler/grimoire/errors.js.map +1 -0
- package/dist/compiler/grimoire/index.d.ts +24 -0
- package/dist/compiler/grimoire/index.d.ts.map +1 -0
- package/dist/compiler/grimoire/index.js +63 -0
- package/dist/compiler/grimoire/index.js.map +1 -0
- package/dist/compiler/grimoire/parser.d.ts +135 -0
- package/dist/compiler/grimoire/parser.d.ts.map +1 -0
- package/dist/compiler/grimoire/parser.js +2148 -0
- package/dist/compiler/grimoire/parser.js.map +1 -0
- package/dist/compiler/grimoire/tokenizer.d.ts +59 -0
- package/dist/compiler/grimoire/tokenizer.d.ts.map +1 -0
- package/dist/compiler/grimoire/tokenizer.js +509 -0
- package/dist/compiler/grimoire/tokenizer.js.map +1 -0
- package/dist/compiler/grimoire/transformer.d.ts +71 -0
- package/dist/compiler/grimoire/transformer.d.ts.map +1 -0
- package/dist/compiler/grimoire/transformer.js +1011 -0
- package/dist/compiler/grimoire/transformer.js.map +1 -0
- package/dist/compiler/index.d.ts +45 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +97 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/ir-generator.d.ts +16 -0
- package/dist/compiler/ir-generator.d.ts.map +1 -0
- package/dist/compiler/ir-generator.js +997 -0
- package/dist/compiler/ir-generator.js.map +1 -0
- package/dist/compiler/validator.d.ts +15 -0
- package/dist/compiler/validator.d.ts.map +1 -0
- package/dist/compiler/validator.js +401 -0
- package/dist/compiler/validator.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/circuit-breaker.d.ts +59 -0
- package/dist/runtime/circuit-breaker.d.ts.map +1 -0
- package/dist/runtime/circuit-breaker.js +155 -0
- package/dist/runtime/circuit-breaker.js.map +1 -0
- package/dist/runtime/context.d.ts +92 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/context.js +219 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/error-classifier.d.ts +16 -0
- package/dist/runtime/error-classifier.d.ts.map +1 -0
- package/dist/runtime/error-classifier.js +38 -0
- package/dist/runtime/error-classifier.js.map +1 -0
- package/dist/runtime/expression-evaluator.d.ts +36 -0
- package/dist/runtime/expression-evaluator.d.ts.map +1 -0
- package/dist/runtime/expression-evaluator.js +391 -0
- package/dist/runtime/expression-evaluator.js.map +1 -0
- package/dist/runtime/index.d.ts +12 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +11 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/interpreter.d.ts +59 -0
- package/dist/runtime/interpreter.d.ts.map +1 -0
- package/dist/runtime/interpreter.js +414 -0
- package/dist/runtime/interpreter.js.map +1 -0
- package/dist/runtime/skills/registry.d.ts +11 -0
- package/dist/runtime/skills/registry.d.ts.map +1 -0
- package/dist/runtime/skills/registry.js +73 -0
- package/dist/runtime/skills/registry.js.map +1 -0
- package/dist/runtime/sqlite-state-store.d.ts +28 -0
- package/dist/runtime/sqlite-state-store.d.ts.map +1 -0
- package/dist/runtime/sqlite-state-store.js +180 -0
- package/dist/runtime/sqlite-state-store.js.map +1 -0
- package/dist/runtime/state-store.d.ts +52 -0
- package/dist/runtime/state-store.d.ts.map +1 -0
- package/dist/runtime/state-store.js +32 -0
- package/dist/runtime/state-store.js.map +1 -0
- package/dist/runtime/steps/action.d.ts +17 -0
- package/dist/runtime/steps/action.d.ts.map +1 -0
- package/dist/runtime/steps/action.js +430 -0
- package/dist/runtime/steps/action.js.map +1 -0
- package/dist/runtime/steps/advisory.d.ts +28 -0
- package/dist/runtime/steps/advisory.d.ts.map +1 -0
- package/dist/runtime/steps/advisory.js +209 -0
- package/dist/runtime/steps/advisory.js.map +1 -0
- package/dist/runtime/steps/compute.d.ts +9 -0
- package/dist/runtime/steps/compute.d.ts.map +1 -0
- package/dist/runtime/steps/compute.js +74 -0
- package/dist/runtime/steps/compute.js.map +1 -0
- package/dist/runtime/steps/conditional.d.ts +14 -0
- package/dist/runtime/steps/conditional.d.ts.map +1 -0
- package/dist/runtime/steps/conditional.js +58 -0
- package/dist/runtime/steps/conditional.js.map +1 -0
- package/dist/runtime/steps/emit.d.ts +9 -0
- package/dist/runtime/steps/emit.d.ts.map +1 -0
- package/dist/runtime/steps/emit.js +70 -0
- package/dist/runtime/steps/emit.js.map +1 -0
- package/dist/runtime/steps/halt.d.ts +9 -0
- package/dist/runtime/steps/halt.d.ts.map +1 -0
- package/dist/runtime/steps/halt.js +19 -0
- package/dist/runtime/steps/halt.js.map +1 -0
- package/dist/runtime/steps/loop.d.ts +14 -0
- package/dist/runtime/steps/loop.d.ts.map +1 -0
- package/dist/runtime/steps/loop.js +109 -0
- package/dist/runtime/steps/loop.js.map +1 -0
- package/dist/runtime/steps/parallel.d.ts +9 -0
- package/dist/runtime/steps/parallel.d.ts.map +1 -0
- package/dist/runtime/steps/parallel.js +87 -0
- package/dist/runtime/steps/parallel.js.map +1 -0
- package/dist/runtime/steps/pipeline.d.ts +9 -0
- package/dist/runtime/steps/pipeline.d.ts.map +1 -0
- package/dist/runtime/steps/pipeline.js +125 -0
- package/dist/runtime/steps/pipeline.js.map +1 -0
- package/dist/runtime/steps/try.d.ts +13 -0
- package/dist/runtime/steps/try.d.ts.map +1 -0
- package/dist/runtime/steps/try.js +222 -0
- package/dist/runtime/steps/try.js.map +1 -0
- package/dist/runtime/steps/wait.d.ts +9 -0
- package/dist/runtime/steps/wait.d.ts.map +1 -0
- package/dist/runtime/steps/wait.js +38 -0
- package/dist/runtime/steps/wait.js.map +1 -0
- package/dist/types/actions.d.ts +162 -0
- package/dist/types/actions.d.ts.map +1 -0
- package/dist/types/actions.js +5 -0
- package/dist/types/actions.js.map +1 -0
- package/dist/types/execution.d.ts +276 -0
- package/dist/types/execution.d.ts.map +1 -0
- package/dist/types/execution.js +5 -0
- package/dist/types/execution.js.map +1 -0
- package/dist/types/expressions.d.ts +100 -0
- package/dist/types/expressions.d.ts.map +1 -0
- package/dist/types/expressions.js +48 -0
- package/dist/types/expressions.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/ir.d.ts +187 -0
- package/dist/types/ir.d.ts.map +1 -0
- package/dist/types/ir.js +5 -0
- package/dist/types/ir.js.map +1 -0
- package/dist/types/policy.d.ts +123 -0
- package/dist/types/policy.d.ts.map +1 -0
- package/dist/types/policy.js +5 -0
- package/dist/types/policy.js.map +1 -0
- package/dist/types/primitives.d.ts +76 -0
- package/dist/types/primitives.d.ts.map +1 -0
- package/dist/types/primitives.js +10 -0
- package/dist/types/primitives.js.map +1 -0
- package/dist/types/steps.d.ts +226 -0
- package/dist/types/steps.d.ts.map +1 -0
- package/dist/types/steps.js +5 -0
- package/dist/types/steps.js.map +1 -0
- package/dist/venues/index.d.ts +6 -0
- package/dist/venues/index.d.ts.map +1 -0
- package/dist/venues/index.js +26 -0
- package/dist/venues/index.js.map +1 -0
- package/dist/venues/types.d.ts +40 -0
- package/dist/venues/types.d.ts.map +1 -0
- package/dist/venues/types.js +5 -0
- package/dist/venues/types.js.map +1 -0
- package/dist/wallet/executor.d.ts +109 -0
- package/dist/wallet/executor.d.ts.map +1 -0
- package/dist/wallet/executor.js +354 -0
- package/dist/wallet/executor.js.map +1 -0
- package/dist/wallet/index.d.ts +14 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +13 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/wallet/keystore.d.ts +44 -0
- package/dist/wallet/keystore.d.ts.map +1 -0
- package/dist/wallet/keystore.js +296 -0
- package/dist/wallet/keystore.js.map +1 -0
- package/dist/wallet/provider.d.ts +111 -0
- package/dist/wallet/provider.d.ts.map +1 -0
- package/dist/wallet/provider.js +309 -0
- package/dist/wallet/provider.js.map +1 -0
- package/dist/wallet/tx-builder.d.ts +85 -0
- package/dist/wallet/tx-builder.d.ts.map +1 -0
- package/dist/wallet/tx-builder.js +290 -0
- package/dist/wallet/tx-builder.js.map +1 -0
- package/dist/wallet/types.d.ts +116 -0
- package/dist/wallet/types.d.ts.map +1 -0
- package/dist/wallet/types.js +86 -0
- package/dist/wallet/types.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advisory Step Executor
|
|
3
|
+
* Uses fallback outputs (no tool execution yet).
|
|
4
|
+
*/
|
|
5
|
+
import { incrementAdvisoryCalls, setBinding } from "../context.js";
|
|
6
|
+
import { createEvalContext, evaluateAsync } from "../expression-evaluator.js";
|
|
7
|
+
export async function executeAdvisoryStep(step, ctx, ledger, handler) {
|
|
8
|
+
ledger.emit({ type: "step_started", stepId: step.id, kind: "advisory" });
|
|
9
|
+
const tooling = ctx.advisorTooling?.[step.advisor];
|
|
10
|
+
const skills = tooling?.skills?.length ? tooling.skills : undefined;
|
|
11
|
+
const allowedTools = tooling?.allowedTools?.length ? tooling.allowedTools : undefined;
|
|
12
|
+
const mcp = tooling?.mcp?.length ? tooling.mcp : undefined;
|
|
13
|
+
ledger.emit({
|
|
14
|
+
type: "advisory_started",
|
|
15
|
+
advisor: step.advisor,
|
|
16
|
+
prompt: step.prompt,
|
|
17
|
+
skills,
|
|
18
|
+
allowedTools,
|
|
19
|
+
mcp,
|
|
20
|
+
schema: schemaToEvent(step.outputSchema),
|
|
21
|
+
});
|
|
22
|
+
incrementAdvisoryCalls(ctx);
|
|
23
|
+
const advisorDef = ctx.spell.advisors.find((advisor) => advisor.name === step.advisor);
|
|
24
|
+
const handlerInput = {
|
|
25
|
+
advisor: step.advisor,
|
|
26
|
+
prompt: step.prompt,
|
|
27
|
+
model: advisorDef?.model,
|
|
28
|
+
outputSchema: step.outputSchema,
|
|
29
|
+
timeout: step.timeout,
|
|
30
|
+
skills,
|
|
31
|
+
allowedTools,
|
|
32
|
+
mcp,
|
|
33
|
+
context: {
|
|
34
|
+
params: buildParamsSnapshot(ctx),
|
|
35
|
+
bindings: Object.fromEntries(ctx.bindings),
|
|
36
|
+
state: {
|
|
37
|
+
persistent: Object.fromEntries(ctx.state.persistent),
|
|
38
|
+
ephemeral: Object.fromEntries(ctx.state.ephemeral),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
let output;
|
|
43
|
+
let usedFallback = false;
|
|
44
|
+
try {
|
|
45
|
+
if (handler) {
|
|
46
|
+
const handlerOutput = await withTimeout(handler(handlerInput), step.timeout);
|
|
47
|
+
output = coerceToSchema(handlerOutput, step.outputSchema);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const evalCtx = createEvalContext(ctx);
|
|
51
|
+
const fallbackValue = await evaluateAsync(step.fallback, evalCtx);
|
|
52
|
+
output = coerceToSchema(fallbackValue, step.outputSchema);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
57
|
+
if (handler) {
|
|
58
|
+
let fallbackValue;
|
|
59
|
+
try {
|
|
60
|
+
const evalCtx = createEvalContext(ctx);
|
|
61
|
+
fallbackValue = await evaluateAsync(step.fallback, evalCtx);
|
|
62
|
+
output = coerceToSchema(fallbackValue, step.outputSchema);
|
|
63
|
+
usedFallback = true;
|
|
64
|
+
ledger.emit({
|
|
65
|
+
type: "advisory_failed",
|
|
66
|
+
advisor: step.advisor,
|
|
67
|
+
error: message,
|
|
68
|
+
fallback: fallbackValue,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (fallbackError) {
|
|
72
|
+
const fallbackMessage = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
|
|
73
|
+
ledger.emit({
|
|
74
|
+
type: "advisory_failed",
|
|
75
|
+
advisor: step.advisor,
|
|
76
|
+
error: fallbackMessage,
|
|
77
|
+
fallback: fallbackValue,
|
|
78
|
+
});
|
|
79
|
+
ledger.emit({ type: "step_failed", stepId: step.id, error: fallbackMessage });
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
stepId: step.id,
|
|
83
|
+
error: fallbackMessage,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
ledger.emit({
|
|
89
|
+
type: "advisory_failed",
|
|
90
|
+
advisor: step.advisor,
|
|
91
|
+
error: message,
|
|
92
|
+
fallback: undefined,
|
|
93
|
+
});
|
|
94
|
+
ledger.emit({ type: "step_failed", stepId: step.id, error: message });
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
stepId: step.id,
|
|
98
|
+
error: message,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
setBinding(ctx, step.outputBinding, output);
|
|
103
|
+
ledger.emit({ type: "advisory_completed", advisor: step.advisor, output });
|
|
104
|
+
ledger.emit({ type: "step_completed", stepId: step.id, result: output });
|
|
105
|
+
return {
|
|
106
|
+
success: true,
|
|
107
|
+
stepId: step.id,
|
|
108
|
+
output,
|
|
109
|
+
fallback: usedFallback || undefined,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function coerceToSchema(value, schema) {
|
|
113
|
+
if (schema.type === "boolean") {
|
|
114
|
+
return Boolean(value);
|
|
115
|
+
}
|
|
116
|
+
if (schema.type === "number") {
|
|
117
|
+
if (typeof value === "number")
|
|
118
|
+
return value;
|
|
119
|
+
const num = Number.parseFloat(String(value));
|
|
120
|
+
return Number.isFinite(num) ? num : 0;
|
|
121
|
+
}
|
|
122
|
+
if (schema.type === "enum") {
|
|
123
|
+
const values = schema.values ?? [];
|
|
124
|
+
if (values.length === 0)
|
|
125
|
+
return value;
|
|
126
|
+
if (typeof value === "string" && values.includes(value))
|
|
127
|
+
return value;
|
|
128
|
+
return values[0];
|
|
129
|
+
}
|
|
130
|
+
if (schema.type === "string") {
|
|
131
|
+
return typeof value === "string" ? value : String(value);
|
|
132
|
+
}
|
|
133
|
+
if (schema.type === "object") {
|
|
134
|
+
if (!schema.fields) {
|
|
135
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
const result = {};
|
|
141
|
+
const input = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
142
|
+
for (const [key, fieldSchema] of Object.entries(schema.fields)) {
|
|
143
|
+
const fieldValue = input[key];
|
|
144
|
+
result[key] = coerceToSchema(fieldValue, fieldSchema);
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
if (schema.type === "array") {
|
|
149
|
+
if (!Array.isArray(value))
|
|
150
|
+
return [];
|
|
151
|
+
if (!schema.items)
|
|
152
|
+
return value;
|
|
153
|
+
return value.map((item) => coerceToSchema(item, schema.items));
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
function buildParamsSnapshot(ctx) {
|
|
158
|
+
const params = {};
|
|
159
|
+
for (const param of ctx.spell.params) {
|
|
160
|
+
params[param.name] = ctx.bindings.get(param.name);
|
|
161
|
+
}
|
|
162
|
+
return params;
|
|
163
|
+
}
|
|
164
|
+
function withTimeout(promise, timeoutSeconds) {
|
|
165
|
+
if (!Number.isFinite(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
166
|
+
return promise;
|
|
167
|
+
}
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
const ms = timeoutSeconds * 1000;
|
|
170
|
+
const timer = setTimeout(() => reject(new Error(`Advisory timed out after ${timeoutSeconds}s`)), ms);
|
|
171
|
+
promise.then((value) => {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
resolve(value);
|
|
174
|
+
}, (error) => {
|
|
175
|
+
clearTimeout(timer);
|
|
176
|
+
reject(error);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function schemaToEvent(schema) {
|
|
181
|
+
switch (schema.type) {
|
|
182
|
+
case "boolean":
|
|
183
|
+
return { type: "boolean" };
|
|
184
|
+
case "number":
|
|
185
|
+
return { type: "number", min: schema.min, max: schema.max };
|
|
186
|
+
case "enum":
|
|
187
|
+
return { type: "enum", values: schema.values };
|
|
188
|
+
case "string":
|
|
189
|
+
return {
|
|
190
|
+
type: "string",
|
|
191
|
+
minLength: schema.minLength,
|
|
192
|
+
maxLength: schema.maxLength,
|
|
193
|
+
pattern: schema.pattern,
|
|
194
|
+
};
|
|
195
|
+
case "object":
|
|
196
|
+
return {
|
|
197
|
+
type: "object",
|
|
198
|
+
fields: schema.fields
|
|
199
|
+
? Object.fromEntries(Object.entries(schema.fields).map(([key, value]) => [key, schemaToEvent(value)]))
|
|
200
|
+
: undefined,
|
|
201
|
+
};
|
|
202
|
+
case "array":
|
|
203
|
+
return {
|
|
204
|
+
type: "array",
|
|
205
|
+
items: schema.items ? schemaToEvent(schema.items) : undefined,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=advisory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advisory.js","sourceRoot":"","sources":["../../../src/runtime/steps/advisory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAuB9E,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAkB,EAClB,GAAqB,EACrB,MAAsB,EACtB,OAAyB;IAEzB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACpE,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;IACtF,MAAM,GAAG,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC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,CAAC,OAAO;aACxB,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,MAAM,CAAC,MAAM;oBACnB,CAAC,CAAC,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CACjF;oBACH,CAAC,CAAC,SAAS;aACd,CAAC;QACJ,KAAK,OAAO;YACV,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;aAC9D,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute Step Executor
|
|
3
|
+
* Evaluates expressions and stores results in bindings
|
|
4
|
+
*/
|
|
5
|
+
import type { ExecutionContext, StepResult } from "../../types/execution.js";
|
|
6
|
+
import type { ComputeStep } from "../../types/steps.js";
|
|
7
|
+
import type { InMemoryLedger } from "../context.js";
|
|
8
|
+
export declare function executeComputeStep(step: ComputeStep, ctx: ExecutionContext, ledger: InMemoryLedger): Promise<StepResult>;
|
|
9
|
+
//# sourceMappingURL=compute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../../src/runtime/steps/compute.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,UAAU,CAAC,CAyDrB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute Step Executor
|
|
3
|
+
* Evaluates expressions and stores results in bindings
|
|
4
|
+
*/
|
|
5
|
+
import { setBinding } from "../context.js";
|
|
6
|
+
import { createEvalContext, evaluateAsync } from "../expression-evaluator.js";
|
|
7
|
+
export async function executeComputeStep(step, ctx, ledger) {
|
|
8
|
+
ledger.emit({ type: "step_started", stepId: step.id, kind: "compute" });
|
|
9
|
+
try {
|
|
10
|
+
const evalCtx = createEvalContext(ctx);
|
|
11
|
+
// Evaluate each assignment in order
|
|
12
|
+
for (const { variable, expression } of step.assignments) {
|
|
13
|
+
const value = await evaluateAsync(expression, evalCtx);
|
|
14
|
+
// Store in bindings
|
|
15
|
+
setBinding(ctx, variable, value);
|
|
16
|
+
// Also update evalCtx bindings for subsequent expressions
|
|
17
|
+
evalCtx.bindings.set(variable, value);
|
|
18
|
+
// Log binding
|
|
19
|
+
ledger.emit({
|
|
20
|
+
type: "binding_set",
|
|
21
|
+
name: variable,
|
|
22
|
+
value: serializeValue(value),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
ledger.emit({
|
|
26
|
+
type: "step_completed",
|
|
27
|
+
stepId: step.id,
|
|
28
|
+
result: {
|
|
29
|
+
assignments: step.assignments.map((a) => ({
|
|
30
|
+
variable: a.variable,
|
|
31
|
+
value: serializeValue(ctx.bindings.get(a.variable)),
|
|
32
|
+
})),
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
success: true,
|
|
37
|
+
stepId: step.id,
|
|
38
|
+
output: Object.fromEntries(step.assignments.map((a) => [a.variable, ctx.bindings.get(a.variable)])),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43
|
+
ledger.emit({
|
|
44
|
+
type: "step_failed",
|
|
45
|
+
stepId: step.id,
|
|
46
|
+
error: message,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
stepId: step.id,
|
|
51
|
+
error: message,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Serialize a value for logging (handle bigint, etc.)
|
|
57
|
+
*/
|
|
58
|
+
function serializeValue(value) {
|
|
59
|
+
if (typeof value === "bigint") {
|
|
60
|
+
return value.toString();
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
return value.map(serializeValue);
|
|
64
|
+
}
|
|
65
|
+
if (typeof value === "object" && value !== null) {
|
|
66
|
+
const result = {};
|
|
67
|
+
for (const [k, v] of Object.entries(value)) {
|
|
68
|
+
result[k] = serializeValue(v);
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=compute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute.js","sourceRoot":"","sources":["../../../src/runtime/steps/compute.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE9E,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAiB,EACjB,GAAqB,EACrB,MAAsB;IAEtB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAExE,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAA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AE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAEvE,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,KAAK,EAAE,OAAO;SACf,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,KAAK,EAAE,OAAO;SACf,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,MAAM,GAA4B,EAAE,CAAC;QAC3C,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3C,MAAM,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional Step Executor
|
|
3
|
+
* Evaluates condition and executes appropriate branch
|
|
4
|
+
*/
|
|
5
|
+
import type { ExecutionContext, StepResult } from "../../types/execution.js";
|
|
6
|
+
import type { ConditionalStep } from "../../types/steps.js";
|
|
7
|
+
import type { InMemoryLedger } from "../context.js";
|
|
8
|
+
export interface ConditionalResult extends StepResult {
|
|
9
|
+
condition: boolean;
|
|
10
|
+
executedBranch: "then" | "else" | "none";
|
|
11
|
+
branchSteps: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare function executeConditionalStep(step: ConditionalStep, ctx: ExecutionContext, ledger: InMemoryLedger): Promise<ConditionalResult>;
|
|
14
|
+
//# sourceMappingURL=conditional.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional.d.ts","sourceRoot":"","sources":["../../../src/runtime/steps/conditional.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACzC,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,eAAe,EACrB,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,iBAAiB,CAAC,CAyD5B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional Step Executor
|
|
3
|
+
* Evaluates condition and executes appropriate branch
|
|
4
|
+
*/
|
|
5
|
+
import { createEvalContext, evaluateAsync } from "../expression-evaluator.js";
|
|
6
|
+
export async function executeConditionalStep(step, ctx, ledger) {
|
|
7
|
+
ledger.emit({ type: "step_started", stepId: step.id, kind: "conditional" });
|
|
8
|
+
try {
|
|
9
|
+
const evalCtx = createEvalContext(ctx);
|
|
10
|
+
// Evaluate condition
|
|
11
|
+
const conditionValue = await evaluateAsync(step.condition, evalCtx);
|
|
12
|
+
const condition = Boolean(conditionValue);
|
|
13
|
+
// Determine which branch to execute
|
|
14
|
+
let executedBranch;
|
|
15
|
+
let branchSteps;
|
|
16
|
+
if (condition) {
|
|
17
|
+
executedBranch = step.thenSteps.length > 0 ? "then" : "none";
|
|
18
|
+
branchSteps = step.thenSteps;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
executedBranch = step.elseSteps.length > 0 ? "else" : "none";
|
|
22
|
+
branchSteps = step.elseSteps;
|
|
23
|
+
}
|
|
24
|
+
ledger.emit({
|
|
25
|
+
type: "step_completed",
|
|
26
|
+
stepId: step.id,
|
|
27
|
+
result: {
|
|
28
|
+
condition,
|
|
29
|
+
executedBranch,
|
|
30
|
+
branchSteps,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
success: true,
|
|
35
|
+
stepId: step.id,
|
|
36
|
+
condition,
|
|
37
|
+
executedBranch,
|
|
38
|
+
branchSteps,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43
|
+
ledger.emit({
|
|
44
|
+
type: "step_failed",
|
|
45
|
+
stepId: step.id,
|
|
46
|
+
error: message,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
stepId: step.id,
|
|
51
|
+
error: message,
|
|
52
|
+
condition: false,
|
|
53
|
+
executedBranch: "none",
|
|
54
|
+
branchSteps: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=conditional.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional.js","sourceRoot":"","sources":["../../../src/runtime/steps/conditional.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM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QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAEvE,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,KAAK,EAAE,OAAO;SACf,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,KAAK,EAAE,OAAO;YACd,SAAS,EAAE,KAAK;YAChB,cAAc,EAAE,MAAM;YACtB,WAAW,EAAE,EAAE;SAChB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emit Step Executor
|
|
3
|
+
* Records an event to the ledger
|
|
4
|
+
*/
|
|
5
|
+
import type { ExecutionContext, StepResult } from "../../types/execution.js";
|
|
6
|
+
import type { EmitStep } from "../../types/steps.js";
|
|
7
|
+
import type { InMemoryLedger } from "../context.js";
|
|
8
|
+
export declare function executeEmitStep(step: EmitStep, ctx: ExecutionContext, ledger: InMemoryLedger): Promise<StepResult>;
|
|
9
|
+
//# sourceMappingURL=emit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../src/runtime/steps/emit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,wBAAsB,eAAe,CACnC,IAAI,EAAE,QAAQ,EACd,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,UAAU,CAAC,CAmDrB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emit Step Executor
|
|
3
|
+
* Records an event to the ledger
|
|
4
|
+
*/
|
|
5
|
+
import { createEvalContext, evaluateAsync } from "../expression-evaluator.js";
|
|
6
|
+
export async function executeEmitStep(step, ctx, ledger) {
|
|
7
|
+
ledger.emit({ type: "step_started", stepId: step.id, kind: "emit" });
|
|
8
|
+
try {
|
|
9
|
+
const evalCtx = createEvalContext(ctx);
|
|
10
|
+
// Evaluate all data expressions
|
|
11
|
+
const data = {};
|
|
12
|
+
for (const [key, expr] of Object.entries(step.data)) {
|
|
13
|
+
data[key] = await evaluateAsync(expr, evalCtx);
|
|
14
|
+
}
|
|
15
|
+
// Emit the custom event
|
|
16
|
+
// Note: This is a user-defined event, not a system event
|
|
17
|
+
// We log it as a step completion with the event data
|
|
18
|
+
ledger.emit({
|
|
19
|
+
type: "event_emitted",
|
|
20
|
+
stepId: step.id,
|
|
21
|
+
event: step.event,
|
|
22
|
+
data: serializeData(data),
|
|
23
|
+
});
|
|
24
|
+
ledger.emit({
|
|
25
|
+
type: "step_completed",
|
|
26
|
+
stepId: step.id,
|
|
27
|
+
result: {
|
|
28
|
+
event: step.event,
|
|
29
|
+
data: serializeData(data),
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
success: true,
|
|
34
|
+
stepId: step.id,
|
|
35
|
+
output: { event: step.event, data },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
40
|
+
ledger.emit({
|
|
41
|
+
type: "step_failed",
|
|
42
|
+
stepId: step.id,
|
|
43
|
+
error: message,
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
stepId: step.id,
|
|
48
|
+
error: message,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Serialize data for logging (handle bigint, etc.)
|
|
54
|
+
*/
|
|
55
|
+
function serializeData(data) {
|
|
56
|
+
const result = {};
|
|
57
|
+
for (const [key, value] of Object.entries(data)) {
|
|
58
|
+
if (typeof value === "bigint") {
|
|
59
|
+
result[key] = value.toString();
|
|
60
|
+
}
|
|
61
|
+
else if (Array.isArray(value)) {
|
|
62
|
+
result[key] = value.map((v) => (typeof v === "bigint" ? v.toString() : v));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
result[key] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=emit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../../src/runtime/steps/emit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE9E,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,IAAc,EACd,GAAqB,EACrB,MAAsB;IAEtB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAErE,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAEvC,gCAAgC;QAChC,MAAM,IAAI,GAA4B,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,wBAAwB;QACxB,yDAAyD;QACzD,qDAAqD;QACrD,MAAM,CAAC,IAAI,CAAC;YACV,IAA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AC;QACjC,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7E,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Halt Step Executor
|
|
3
|
+
* Stops execution immediately
|
|
4
|
+
*/
|
|
5
|
+
import type { ExecutionContext, StepResult } from "../../types/execution.js";
|
|
6
|
+
import type { HaltStep } from "../../types/steps.js";
|
|
7
|
+
import type { InMemoryLedger } from "../context.js";
|
|
8
|
+
export declare function executeHaltStep(step: HaltStep, _ctx: ExecutionContext, ledger: InMemoryLedger): Promise<StepResult>;
|
|
9
|
+
//# sourceMappingURL=halt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"halt.d.ts","sourceRoot":"","sources":["../../../src/runtime/steps/halt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,wBAAsB,eAAe,CACnC,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,UAAU,CAAC,CAerB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Halt Step Executor
|
|
3
|
+
* Stops execution immediately
|
|
4
|
+
*/
|
|
5
|
+
export async function executeHaltStep(step, _ctx, ledger) {
|
|
6
|
+
ledger.emit({ type: "step_started", stepId: step.id, kind: "halt" });
|
|
7
|
+
ledger.emit({
|
|
8
|
+
type: "step_completed",
|
|
9
|
+
stepId: step.id,
|
|
10
|
+
result: { halted: true, reason: step.reason },
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
success: true,
|
|
14
|
+
stepId: step.id,
|
|
15
|
+
halted: true,
|
|
16
|
+
output: { reason: step.reason },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=halt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"halt.js","sourceRoot":"","sources":["../../../src/runtime/steps/halt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,IAAc,EACd,IAAsB,EACtB,MAAsB;IAEtB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAErE,MAAM,CAAC,IAAI,CAAC;QACV,IAAI,EAAE,gBAAgB;QACtB,MAAM,EAAE,IAAI,CAAC,EAAE;QACf,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;KAC9C,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,IAAI,CAAC,EAAE;QACf,MAAM,EAAE,IAAI;QACZ,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;KAChC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop Step Executor
|
|
3
|
+
* Executes steps repeatedly based on loop type
|
|
4
|
+
*/
|
|
5
|
+
import type { ExecutionContext, StepResult } from "../../types/execution.js";
|
|
6
|
+
import type { LoopStep } from "../../types/steps.js";
|
|
7
|
+
import type { InMemoryLedger } from "../context.js";
|
|
8
|
+
import { type EvalContext } from "../expression-evaluator.js";
|
|
9
|
+
export interface LoopResult extends StepResult {
|
|
10
|
+
iterations: number;
|
|
11
|
+
results: unknown[];
|
|
12
|
+
}
|
|
13
|
+
export declare function executeLoopStep(step: LoopStep, ctx: ExecutionContext, ledger: InMemoryLedger, executeStepById: (stepId: string, ctx: ExecutionContext, evalCtx?: EvalContext) => Promise<StepResult>): Promise<LoopResult>;
|
|
14
|
+
//# sourceMappingURL=loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../../src/runtime/steps/loop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,KAAK,WAAW,EAAoC,MAAM,4BAA4B,CAAC;AAEhG,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB;AAED,wBAAsB,eAAe,CACnC,IAAI,EAAE,QAAQ,EACd,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,cAAc,EACtB,eAAe,EAAE,CACf,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,gBAAgB,EACrB,OAAO,CAAC,EAAE,WAAW,KAClB,OAAO,CAAC,UAAU,CAAC,GACvB,OAAO,CAAC,UAAU,CAAC,CAuHrB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop Step Executor
|
|
3
|
+
* Executes steps repeatedly based on loop type
|
|
4
|
+
*/
|
|
5
|
+
import { createEvalContext, evaluateAsync } from "../expression-evaluator.js";
|
|
6
|
+
export async function executeLoopStep(step, ctx, ledger, executeStepById) {
|
|
7
|
+
ledger.emit({ type: "step_started", stepId: step.id, kind: "loop" });
|
|
8
|
+
const results = [];
|
|
9
|
+
let iterations = 0;
|
|
10
|
+
try {
|
|
11
|
+
const evalCtx = createEvalContext(ctx);
|
|
12
|
+
switch (step.loopType.type) {
|
|
13
|
+
case "repeat": {
|
|
14
|
+
// Fixed number of iterations
|
|
15
|
+
const count = Math.min(step.loopType.count, step.maxIterations);
|
|
16
|
+
for (let i = 0; i < count; i++) {
|
|
17
|
+
evalCtx.index = i;
|
|
18
|
+
iterations++;
|
|
19
|
+
ctx.bindings.set("index", i);
|
|
20
|
+
for (const bodyStepId of step.bodySteps) {
|
|
21
|
+
const result = await executeStepById(bodyStepId, ctx, evalCtx);
|
|
22
|
+
if (!result.success) {
|
|
23
|
+
throw new Error(`Loop body step '${bodyStepId}' failed: ${result.error}`);
|
|
24
|
+
}
|
|
25
|
+
results.push(result.output);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case "for": {
|
|
31
|
+
// Iterate over array
|
|
32
|
+
const source = await evaluateAsync(step.loopType.source, evalCtx);
|
|
33
|
+
if (!Array.isArray(source)) {
|
|
34
|
+
throw new Error("For loop source must be an array");
|
|
35
|
+
}
|
|
36
|
+
const items = source.slice(0, step.maxIterations);
|
|
37
|
+
for (let i = 0; i < items.length; i++) {
|
|
38
|
+
evalCtx.item = items[i];
|
|
39
|
+
evalCtx.index = i;
|
|
40
|
+
iterations++;
|
|
41
|
+
// Set loop variable in bindings
|
|
42
|
+
ctx.bindings.set(step.loopType.variable, items[i]);
|
|
43
|
+
ctx.bindings.set("item", items[i]);
|
|
44
|
+
ctx.bindings.set("index", i);
|
|
45
|
+
for (const bodyStepId of step.bodySteps) {
|
|
46
|
+
const result = await executeStepById(bodyStepId, ctx, evalCtx);
|
|
47
|
+
if (!result.success) {
|
|
48
|
+
throw new Error(`Loop body step '${bodyStepId}' failed: ${result.error}`);
|
|
49
|
+
}
|
|
50
|
+
results.push(result.output);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case "until": {
|
|
56
|
+
// Loop until condition is true
|
|
57
|
+
while (iterations < step.maxIterations) {
|
|
58
|
+
const condition = await evaluateAsync(step.loopType.condition, evalCtx);
|
|
59
|
+
if (condition) {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
evalCtx.index = iterations;
|
|
63
|
+
iterations++;
|
|
64
|
+
ctx.bindings.set("index", iterations - 1);
|
|
65
|
+
for (const bodyStepId of step.bodySteps) {
|
|
66
|
+
const result = await executeStepById(bodyStepId, ctx, evalCtx);
|
|
67
|
+
if (!result.success) {
|
|
68
|
+
throw new Error(`Loop body step '${bodyStepId}' failed: ${result.error}`);
|
|
69
|
+
}
|
|
70
|
+
results.push(result.output);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Store output if binding specified
|
|
77
|
+
if (step.outputBinding) {
|
|
78
|
+
ctx.bindings.set(step.outputBinding, results);
|
|
79
|
+
}
|
|
80
|
+
ledger.emit({
|
|
81
|
+
type: "step_completed",
|
|
82
|
+
stepId: step.id,
|
|
83
|
+
result: { iterations, resultsCount: results.length },
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
success: true,
|
|
87
|
+
stepId: step.id,
|
|
88
|
+
iterations,
|
|
89
|
+
results,
|
|
90
|
+
output: results,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
95
|
+
ledger.emit({
|
|
96
|
+
type: "step_failed",
|
|
97
|
+
stepId: step.id,
|
|
98
|
+
error: message,
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
stepId: step.id,
|
|
103
|
+
error: message,
|
|
104
|
+
iterations,
|
|
105
|
+
results,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=loop.js.map
|