@arronqzy/blueprint-dsl 1.0.3 → 1.0.4
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
CHANGED
package/src/behaviors/default.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { BehaviorRegistry } from "../core/behavior-registry.js";
|
|
|
9
9
|
|
|
10
10
|
const LIFECYCLE_SIGNAL_KEY = "__lifecycleSignal";
|
|
11
11
|
const BLUEPRINT_ACTIVATION_INPUT_KEY = "__blueprintActivationInput";
|
|
12
|
+
const UI_EVENT_PAYLOAD_KEY = "__uiEventPayload";
|
|
12
13
|
|
|
13
14
|
export function registerDefaultBehaviors(registry: BehaviorRegistry) {
|
|
14
15
|
registry.registerJS("logic-noop", async ({ io }) => {
|
|
@@ -41,4 +42,4 @@ export function registerDefaultBehaviors(registry: BehaviorRegistry) {
|
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
export { LIFECYCLE_SIGNAL_KEY, BLUEPRINT_ACTIVATION_INPUT_KEY };
|
|
45
|
+
export { LIFECYCLE_SIGNAL_KEY, BLUEPRINT_ACTIVATION_INPUT_KEY, UI_EVENT_PAYLOAD_KEY };
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
registerDefaultBehaviors,
|
|
39
39
|
BLUEPRINT_ACTIVATION_INPUT_KEY,
|
|
40
40
|
LIFECYCLE_SIGNAL_KEY,
|
|
41
|
+
UI_EVENT_PAYLOAD_KEY,
|
|
41
42
|
} from "../behaviors/default.js";
|
|
42
43
|
import { BehaviorRegistry } from "../core/behavior-registry.js";
|
|
43
44
|
import { Executor } from "../core/executor.js";
|
|
@@ -207,6 +208,69 @@ export class BlueprintGraphRunner {
|
|
|
207
208
|
this.cycleValidated = true;
|
|
208
209
|
}
|
|
209
210
|
|
|
211
|
+
private injectedInputs = new Map<string, Value>();
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 从视图交互触发指定蓝图节点:向该节点 in 口注入真信号并执行下游。
|
|
215
|
+
* payload 写入 scope(UI_EVENT_PAYLOAD_KEY)供 Logic 等节点读取。
|
|
216
|
+
*/
|
|
217
|
+
async triggerNode(nodeId: string, inputValue?: unknown): Promise<void> {
|
|
218
|
+
await this.ensureNoBlueprintCycle();
|
|
219
|
+
this.requireNode(nodeId);
|
|
220
|
+
const key = `${nodeId}:in`;
|
|
221
|
+
this.injectedInputs.set(key, createTrueSignal(inputValue ?? true));
|
|
222
|
+
try {
|
|
223
|
+
await this.runFromNodeWithUiPayload(nodeId, inputValue);
|
|
224
|
+
} finally {
|
|
225
|
+
this.injectedInputs.delete(key);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private async runFromNodeWithUiPayload(
|
|
230
|
+
nodeId: string,
|
|
231
|
+
inputValue?: unknown
|
|
232
|
+
) {
|
|
233
|
+
const queue: ExecutionToken[] = [
|
|
234
|
+
{
|
|
235
|
+
tokenId: createTokenId(),
|
|
236
|
+
nodeId,
|
|
237
|
+
nodeType: this.requireNode(nodeId).nodeType,
|
|
238
|
+
inPort: "in",
|
|
239
|
+
scope: cloneScope(),
|
|
240
|
+
},
|
|
241
|
+
];
|
|
242
|
+
queue[0]!.scope.vars.set(UI_EVENT_PAYLOAD_KEY, inputValue);
|
|
243
|
+
|
|
244
|
+
const executor = this.createExecutor(queue);
|
|
245
|
+
|
|
246
|
+
while (queue.length > 0) {
|
|
247
|
+
const token = queue.shift()!;
|
|
248
|
+
if (!this.syncTokenFromGraph(token)) continue;
|
|
249
|
+
try {
|
|
250
|
+
await executor.executeToken(token);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
this.setNodeOutput(
|
|
253
|
+
token.nodeId,
|
|
254
|
+
"out",
|
|
255
|
+
createFalseSignal(
|
|
256
|
+
error instanceof Error ? error.message : String(error)
|
|
257
|
+
)
|
|
258
|
+
);
|
|
259
|
+
const nextNodes = this.findSignalTargets(token.nodeId, "out");
|
|
260
|
+
for (const target of nextNodes) {
|
|
261
|
+
queue.push({
|
|
262
|
+
tokenId: createTokenId(),
|
|
263
|
+
nodeId: target.nodeId,
|
|
264
|
+
nodeType: target.nodeType,
|
|
265
|
+
inPort: target.inPort,
|
|
266
|
+
scope: token.scope,
|
|
267
|
+
correlationId: token.correlationId ?? token.tokenId,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
210
274
|
async emitLifecycle(phase: PageLifecyclePhase): Promise<void> {
|
|
211
275
|
await this.ensureNoBlueprintCycle();
|
|
212
276
|
const signal = createLifecycleSignal(phase);
|
|
@@ -1345,8 +1409,11 @@ export class BlueprintGraphRunner {
|
|
|
1345
1409
|
);
|
|
1346
1410
|
}
|
|
1347
1411
|
|
|
1348
|
-
/**
|
|
1412
|
+
/** 单端口多连线:任一为真则视为真(或语义);支持 triggerNode 注入的入口信号 */
|
|
1349
1413
|
private resolvePortInputValue(nodeId: string, port: string): Value | undefined {
|
|
1414
|
+
const injected = this.injectedInputs.get(`${nodeId}:${port}`);
|
|
1415
|
+
if (injected !== undefined) return injected;
|
|
1416
|
+
|
|
1350
1417
|
const inboundEdges = this.findInboundSignalEdges(nodeId, port);
|
|
1351
1418
|
if (inboundEdges.length === 0) return undefined;
|
|
1352
1419
|
|