instant-ctrl-flow-logic 0.1.1 → 0.1.2
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/package.json +2 -3
- package/src/handlers.ts +11 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instant-ctrl-flow-logic",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "InstantCtrlFlow 引擎:xnl bundle 加载 → 行为树编译 → 无状态单次执行",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"src"
|
|
20
20
|
],
|
|
21
21
|
"publishConfig": {
|
|
22
|
-
"access": "public"
|
|
23
|
-
"registry": "https://registry.npmjs.com"
|
|
22
|
+
"access": "public"
|
|
24
23
|
}
|
|
25
24
|
}
|
package/src/handlers.ts
CHANGED
|
@@ -93,6 +93,7 @@ export interface FlowDecisionContext {
|
|
|
93
93
|
export interface FlowDecisionHooks {
|
|
94
94
|
begin(ifPath: string): FlowDecisionContext;
|
|
95
95
|
record(decision: FlowBranchDecision): Promise<void> | void;
|
|
96
|
+
runtimeForNode?(nodeId: string, runtime: InstantCtrlFlowRuntime): InstantCtrlFlowRuntime;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
class FlowFunctionLoader {
|
|
@@ -100,8 +101,13 @@ class FlowFunctionLoader {
|
|
|
100
101
|
constructor(
|
|
101
102
|
private spec: FlowBundleSpec,
|
|
102
103
|
private resolveCode: FlowCodeResolver,
|
|
104
|
+
private runtimeHooks?: FlowDecisionHooks,
|
|
103
105
|
) {}
|
|
104
106
|
|
|
107
|
+
runtimeForNode(nodeId: string, runtime: InstantCtrlFlowRuntime): InstantCtrlFlowRuntime {
|
|
108
|
+
return this.runtimeHooks?.runtimeForNode?.(nodeId, runtime) ?? runtime;
|
|
109
|
+
}
|
|
110
|
+
|
|
105
111
|
load(src: string, nodeId: string): Promise<FlowCodeFunction> {
|
|
106
112
|
let loaded = this.cache.get(src);
|
|
107
113
|
if (!loaded) {
|
|
@@ -128,7 +134,8 @@ function configOf(ctx: Ctx): NodeConfig {
|
|
|
128
134
|
async function callCode(ctx: Ctx, loader: FlowFunctionLoader, src: string): Promise<unknown> {
|
|
129
135
|
const state = flowStateOf(ctx);
|
|
130
136
|
const fn = await loader.load(src, ctx.node.Key);
|
|
131
|
-
|
|
137
|
+
const runtime = (ctx.runtime ?? {}) as InstantCtrlFlowRuntime;
|
|
138
|
+
return fn(loader.runtimeForNode(ctx.node.Key, runtime), state.current, configOf(ctx).config ?? {});
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
function fail(state: FlowExecutionState, error: unknown): BehaviorResult {
|
|
@@ -277,7 +284,7 @@ class StrategyStartHandler implements ActionHandler<CtrlFlowNodeType, INodeConfi
|
|
|
277
284
|
if (state.returned) return BehaviorResult.Success;
|
|
278
285
|
const key = String(configOf(ctx).fallbackKey);
|
|
279
286
|
state.current = state.fallbackInputs[key];
|
|
280
|
-
state.fault
|
|
287
|
+
delete state.fault;
|
|
281
288
|
return BehaviorResult.Success;
|
|
282
289
|
}
|
|
283
290
|
}
|
|
@@ -288,7 +295,7 @@ class FallbackStartHandler implements ActionHandler<CtrlFlowNodeType, INodeConfi
|
|
|
288
295
|
if (state.returned) return BehaviorResult.Success;
|
|
289
296
|
const key = String(configOf(ctx).fallbackKey);
|
|
290
297
|
state.fallbackInputs[key] = state.current;
|
|
291
|
-
state.fault
|
|
298
|
+
delete state.fault;
|
|
292
299
|
return BehaviorResult.Success;
|
|
293
300
|
}
|
|
294
301
|
}
|
|
@@ -440,7 +447,7 @@ export function createFlowHandlers(
|
|
|
440
447
|
executeBody?: FlowBodyExecutor,
|
|
441
448
|
executeTarget?: FlowTargetExecutor,
|
|
442
449
|
): Record<string, ActionHandler<CtrlFlowNodeType, INodeConfig>> {
|
|
443
|
-
const loader = new FlowFunctionLoader(spec, resolveCode);
|
|
450
|
+
const loader = new FlowFunctionLoader(spec, resolveCode, decisionHooks);
|
|
444
451
|
const activeDecisions = new Map<string, FlowDecisionContext>();
|
|
445
452
|
return {
|
|
446
453
|
'flow.Run': new RunHandler(loader),
|