@arronqzy/blueprint-dsl 1.0.8 → 1.0.10

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.
@@ -0,0 +1,778 @@
1
+ type Value = any;
2
+ type PortSpec = {
3
+ name: string;
4
+ kind: "data" | "flow";
5
+ optional?: boolean;
6
+ };
7
+ type NodeDefinition = {
8
+ type: string;
9
+ inputs: PortSpec[];
10
+ outputs: PortSpec[];
11
+ behavior: {
12
+ kind: "js" | "blueprint";
13
+ ref: string;
14
+ };
15
+ };
16
+ type ExecutionToken = {
17
+ tokenId: string;
18
+ nodeId: string;
19
+ nodeType: string;
20
+ inPort: string;
21
+ scope: Scope;
22
+ correlationId?: string;
23
+ };
24
+ type Scope = {
25
+ parent?: Scope;
26
+ vars: Map<string, Value>;
27
+ };
28
+
29
+ /** 页面生命周期阶段 */
30
+ declare const PAGE_LIFECYCLE_PHASES: readonly ["created", "beforeMount", "mounted", "updated", "beforeDestroy", "destroy", "activated", "deactivated", "blueprintActivated"];
31
+ type PageLifecyclePhase = (typeof PAGE_LIFECYCLE_PHASES)[number];
32
+ type LifecycleSignal = {
33
+ /** 触发的生命周期枚举 */
34
+ phase: PageLifecyclePhase;
35
+ /** 触发时刻(Unix 毫秒时间戳) */
36
+ timestamp: number;
37
+ /** ISO 8601 时间字符串,便于下游节点展示或日志 */
38
+ isoTime: string;
39
+ };
40
+ declare const PAGE_LIFECYCLE_LABELS: Record<PageLifecyclePhase, string>;
41
+ declare function createLifecycleSignal(phase: PageLifecyclePhase): LifecycleSignal;
42
+
43
+ /** 真信号:节点正常执行完成时的输出 */
44
+ type TrueSignal<T = Value> = {
45
+ kind: "true";
46
+ value: T;
47
+ timestamp: number;
48
+ isoTime: string;
49
+ };
50
+ /** 假信号:节点执行出错时的输出 */
51
+ type FalseSignal = {
52
+ kind: "false";
53
+ error: string;
54
+ timestamp: number;
55
+ isoTime: string;
56
+ };
57
+ type NodeSignal<T = Value> = TrueSignal<T> | FalseSignal;
58
+ declare function isTrueSignal<T = Value>(signal: unknown): signal is TrueSignal<T>;
59
+ declare function isFalseSignal(signal: unknown): signal is FalseSignal;
60
+ declare function createTrueSignal<T = Value>(value: T): TrueSignal<T>;
61
+ declare function createFalseSignal(error: string): FalseSignal;
62
+ /**
63
+ * 同一输入端口连 n 条线时的「或」语义:任一为真则端口为真;
64
+ * 若无真且存在假信号则合并为假;全无连线则为 undefined。
65
+ */
66
+ declare function combinePortSignalsOr(values: Array<Value | undefined>): Value | undefined;
67
+
68
+ /** 嵌套蓝图执行完成后各节点的端口输出 */
69
+ type BlueprintNodeOutputs = Record<string, Record<string, Value>>;
70
+ /** 蓝图引用节点真信号携带的输出值 */
71
+ type BlueprintRefOutput = {
72
+ nodeId: string;
73
+ nodeType: string;
74
+ libraryBlueprintId: string;
75
+ blueprintName?: string;
76
+ /** 嵌套蓝图各节点 out 端口的信号输出 */
77
+ nestedOutputs: BlueprintNodeOutputs;
78
+ };
79
+
80
+ type BehaviorContext = {
81
+ token: ExecutionToken;
82
+ io: {
83
+ getInput(name: string): Promise<Value>;
84
+ setOutput(name: string, value: Value): void;
85
+ emitFlow(port?: string): void;
86
+ };
87
+ };
88
+ type BehaviorFn = (ctx: BehaviorContext) => Promise<void>;
89
+
90
+ type JSBehavior = {
91
+ kind: "js";
92
+ run: BehaviorFn;
93
+ };
94
+ type BlueprintBehavior = {
95
+ kind: "blueprint";
96
+ blueprintId: string;
97
+ };
98
+ type Behavior = JSBehavior | BlueprintBehavior;
99
+ declare class BehaviorRegistry {
100
+ private map;
101
+ registerJS(id: string, fn: BehaviorFn): void;
102
+ registerBlueprint(id: string, blueprintId: string): void;
103
+ get(id: string): Behavior;
104
+ }
105
+
106
+ type ExecutorDeps = {
107
+ getNodeDefinition(type: string): NodeDefinition;
108
+ behaviors: BehaviorRegistry;
109
+ runBlueprint: (args: {
110
+ blueprintId: string;
111
+ token: ExecutionToken;
112
+ }) => Promise<void>;
113
+ getInputValue: (token: ExecutionToken, port: string) => Promise<Value>;
114
+ setNodeOutput: (token: ExecutionToken, port: string, value: Value) => void;
115
+ emitFlow: (token: ExecutionToken, outPort: string) => void;
116
+ };
117
+ declare class Executor {
118
+ private deps;
119
+ constructor(deps: ExecutorDeps);
120
+ executeToken(token: ExecutionToken): Promise<void>;
121
+ }
122
+
123
+ declare const LIFECYCLE_SIGNAL_KEY = "__lifecycleSignal";
124
+ declare const BLUEPRINT_ACTIVATION_INPUT_KEY = "__blueprintActivationInput";
125
+ declare const UI_EVENT_PAYLOAD_KEY = "__uiEventPayload";
126
+ declare const VIEW_EVENT_SIGNAL_KEY = "__viewEventSignal";
127
+ declare function registerDefaultBehaviors(registry: BehaviorRegistry): void;
128
+
129
+ type SwaggerApiEndpoint = {
130
+ method: FetchHttpMethod;
131
+ path: string;
132
+ summary?: string;
133
+ operationId?: string;
134
+ };
135
+ type ParsedSwaggerDocument = {
136
+ apiBaseUrl: string;
137
+ endpoints: SwaggerApiEndpoint[];
138
+ };
139
+ declare function parseSwaggerDocument(spec: unknown, docsUrl: string): ParsedSwaggerDocument;
140
+ declare function buildEndpointFullUrl(apiBaseUrl: string, pathOrEndpoint: string | Pick<SwaggerApiEndpoint, "path">): string;
141
+ declare function buildEndpointSuggestions(apiBaseUrl: string, endpoints: SwaggerApiEndpoint[]): {
142
+ fullUrl: string;
143
+ label: string;
144
+ method: FetchHttpMethod;
145
+ path: string;
146
+ summary?: string;
147
+ operationId?: string;
148
+ }[];
149
+ declare function filterEndpointSuggestions(suggestions: ReturnType<typeof buildEndpointSuggestions>, query: string): {
150
+ fullUrl: string;
151
+ label: string;
152
+ method: FetchHttpMethod;
153
+ path: string;
154
+ summary?: string;
155
+ operationId?: string;
156
+ }[];
157
+
158
+ declare const FETCH_HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
159
+ type FetchHttpMethod = (typeof FETCH_HTTP_METHODS)[number];
160
+ declare const FETCH_RESPONSE_TYPES: readonly ["json", "text"];
161
+ type FetchResponseType = (typeof FETCH_RESPONSE_TYPES)[number];
162
+ declare const FETCH_CREDENTIALS: readonly ["omit", "same-origin", "include"];
163
+ declare const FETCH_MODES: readonly ["cors", "no-cors", "same-origin", "navigate"];
164
+ declare const FETCH_CACHES: readonly ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
165
+ declare const FETCH_REDIRECTS: readonly ["follow", "error", "manual"];
166
+ type FetchUrlInputMode = "swagger" | "manual";
167
+ type FetchRequestConfig = {
168
+ url: string;
169
+ method?: FetchHttpMethod;
170
+ headers?: Record<string, string>;
171
+ /**
172
+ * 请求头编辑器原文。可写 JSON,也可整段写成 `{scope?...}`。
173
+ * 运行时优先按该字段解析,避免未加引号的模板在 JSON.parse 时被丢掉。
174
+ */
175
+ headersJson?: string;
176
+ body?: string;
177
+ credentials?: RequestCredentials;
178
+ mode?: RequestMode;
179
+ cache?: RequestCache;
180
+ redirect?: RequestRedirect;
181
+ responseType?: FetchResponseType;
182
+ timeoutMs?: number;
183
+ /** Swagger / OpenAPI 文档 JSON 地址 */
184
+ swaggerDocsUrl?: string;
185
+ /** API 主机或基础路径,可与接口 path 组合 */
186
+ apiBaseUrl?: string;
187
+ /** 从 Swagger 文档解析出的接口列表 */
188
+ swaggerEndpoints?: SwaggerApiEndpoint[];
189
+ /** 请求 URL 输入方式:接口联想或手动输入 */
190
+ urlInputMode?: FetchUrlInputMode;
191
+ };
192
+ declare const DEFAULT_FETCH_REQUEST_CONFIG: FetchRequestConfig;
193
+ /** 合并默认项与节点上保存的 fetch 配置,供运行时发起请求 */
194
+ declare function normalizeFetchRequestConfig(config?: FetchRequestConfig): FetchRequestConfig;
195
+ type FetchResultValue = {
196
+ status: number;
197
+ statusText: string;
198
+ url: string;
199
+ data: unknown;
200
+ };
201
+ /** 解析 fetch 节点的最终请求 URL,避免对已有主机信息的地址重复拼接 apiBaseUrl */
202
+ declare function resolveFetchRequestUrl(config: Pick<FetchRequestConfig, "url" | "apiBaseUrl">): string;
203
+ type ExecuteFetchOptions = {
204
+ signal?: AbortSignal;
205
+ /** 调试模式下 HTTP 非 2xx 仍返回响应体,不抛错 */
206
+ allowHttpError?: boolean;
207
+ };
208
+ declare function executeFetch(config: FetchRequestConfig, options?: ExecuteFetchOptions): Promise<FetchResultValue>;
209
+
210
+ declare function hasScopeTemplate(value: string): boolean;
211
+ declare function evaluateScopeExpression(expression: string, scope: unknown): unknown;
212
+ declare function stringifyScopeValue(value: unknown): string;
213
+ /** 将 `{scope?.a}` 替换为求值结果;无模板时原样返回 */
214
+ declare function evaluateScopeTemplate(template: string, scope: unknown): string;
215
+ /**
216
+ * 在 JSON 文本中替换 `{scope?...}`:
217
+ * - 位于字符串内时写入转义后的内容
218
+ * - 位于值位置时写入 JSON 字面量(对象/数组/字符串/数字)
219
+ */
220
+ declare function evaluateScopeTemplateInJson(template: string, scope: unknown): string;
221
+ declare function looksLikeJsonText(text: string): boolean;
222
+
223
+ type ScopeAutocompleteState = {
224
+ templateStart: number;
225
+ cursor: number;
226
+ path: string[];
227
+ partialKey: string;
228
+ };
229
+ /** 解析光标处未闭合的 scope 模版表达式 */
230
+ declare function parseScopeAutocomplete(text: string, cursor: number, scope: unknown): ScopeAutocompleteState | null;
231
+ declare function getScopeAutocompleteSuggestions(scope: unknown, state: ScopeAutocompleteState): string[];
232
+ declare function buildScopeExpression(path: string[], selectedKey: string): string;
233
+ declare function applyScopeAutocompleteSelection(text: string, state: ScopeAutocompleteState, selectedKey: string): {
234
+ value: string;
235
+ cursor: number;
236
+ };
237
+
238
+ type IncomingNodeSource = {
239
+ id: string;
240
+ label?: string;
241
+ name?: string;
242
+ nodeType?: string;
243
+ type?: string;
244
+ role?: string;
245
+ };
246
+ type IncomingGraphEdge = {
247
+ source: string;
248
+ target: string;
249
+ sourceHandle?: string;
250
+ targetHandle?: string;
251
+ };
252
+ type IncomingNodeScopeEntry = {
253
+ id: string;
254
+ name: string;
255
+ type: string;
256
+ role?: string;
257
+ port: string;
258
+ kind: "true" | "false" | "pending";
259
+ value?: unknown;
260
+ error?: string;
261
+ timestamp?: number;
262
+ isoTime?: string;
263
+ };
264
+ type IncomingNodeScope = IncomingNodeScopeEntry | Record<string, IncomingNodeScopeEntry>;
265
+ /** 尚无上游数据时,仍可联想 scope 的固定字段 */
266
+ declare const FETCH_SCOPE_AUTOCOMPLETE_FALLBACK: IncomingNodeScopeEntry;
267
+ declare function resolveFetchScopeAutocompleteRoot(scope: unknown): unknown;
268
+ declare function createIncomingNodeScopeEntry(node: IncomingNodeSource | undefined, port: string, output: unknown): IncomingNodeScopeEntry;
269
+ declare function buildIncomingNodeScope(entries: IncomingNodeScopeEntry[]): IncomingNodeScope | undefined;
270
+ declare function collectIncomingNodeScopeEntries(options: {
271
+ targetNodeId: string;
272
+ targetPort?: string;
273
+ nodes: IncomingNodeSource[];
274
+ edges: IncomingGraphEdge[];
275
+ getOutput?: (nodeId: string, port: string) => unknown;
276
+ }): IncomingNodeScopeEntry[];
277
+ declare function resolveFetchIncomingScope(options: {
278
+ fetchNodeId: string;
279
+ inputPort?: string;
280
+ nodes: IncomingNodeSource[];
281
+ edges: IncomingGraphEdge[];
282
+ getOutput?: (nodeId: string, port: string) => unknown;
283
+ fallbackInput?: unknown;
284
+ }): IncomingNodeScope | undefined;
285
+ declare function latestTraceOutputsByNode(entries: Array<{
286
+ nodeId: string;
287
+ outputs?: Record<string, unknown>;
288
+ }>): Record<string, Record<string, unknown>>;
289
+ declare function parseJsonText(text: string): {
290
+ ok: true;
291
+ value: unknown;
292
+ } | {
293
+ ok: false;
294
+ error: string;
295
+ };
296
+ declare function validateFetchJsonText(text: string, options?: {
297
+ allowEmpty?: boolean;
298
+ }): {
299
+ ok: true;
300
+ } | {
301
+ ok: false;
302
+ error: string;
303
+ };
304
+ declare function resolveFetchBody(body: string | undefined, scope?: unknown): string | undefined;
305
+ declare function getFetchBodyValidationError(body: string | undefined, resolvedBody?: string): string | null;
306
+ declare function getFetchHeadersValidationError(config: FetchRequestConfig, scope?: unknown): string | null;
307
+ /** `{scope?...}` 整段表达式,区别于 JSON 对象 `{ "Authorization": "..." }` */
308
+ declare function isWholeScopeExpression(text: string): boolean;
309
+ /** 将请求头编辑器原文解析为对象;支持 JSON 内模板,也支持整段 `{scope?...}` */
310
+ declare function parseFetchHeadersJson(text: string, scope?: unknown): Record<string, string> | undefined;
311
+ declare function draftFetchHeadersText(config: FetchRequestConfig): string;
312
+ declare function resolveFetchHeaders(config: FetchRequestConfig, scope?: unknown): Record<string, string> | undefined;
313
+ /** 用上游 scope 解析 fetch 表单中的 URL / Base URL / headers / body */
314
+ declare function applyFetchConfigScope(config: FetchRequestConfig, scope: unknown): FetchRequestConfig;
315
+ declare function fetchConfigHasScopeTemplate(config: FetchRequestConfig): boolean;
316
+
317
+ type JsonNodeConfig = {
318
+ jsonString: string;
319
+ };
320
+ declare const DEFAULT_JSON_NODE_CONFIG: JsonNodeConfig;
321
+ declare function validateJsonString(jsonString: string): {
322
+ ok: true;
323
+ value: unknown;
324
+ } | {
325
+ ok: false;
326
+ error: string;
327
+ };
328
+ declare function parseJsonConfig(config: JsonNodeConfig): unknown;
329
+
330
+ type StorageKind = "session" | "local";
331
+ type StorageReadConfig = {
332
+ storage: StorageKind;
333
+ key: string;
334
+ };
335
+ type StorageSetConfig = {
336
+ storages: StorageKind[];
337
+ key: string;
338
+ value: string;
339
+ };
340
+ type StorageNodeConfig = {
341
+ read: StorageReadConfig;
342
+ set: StorageSetConfig;
343
+ };
344
+ declare const STORAGE_KINDS: StorageKind[];
345
+ declare const DEFAULT_STORAGE_NODE_CONFIG: StorageNodeConfig;
346
+ type WebStorageLike = {
347
+ getItem(key: string): string | null;
348
+ setItem(key: string, value: string): void;
349
+ };
350
+ type StorageAccessors = {
351
+ session?: WebStorageLike | null;
352
+ local?: WebStorageLike | null;
353
+ };
354
+ declare function uniqueStorageKinds(kinds?: readonly unknown[]): StorageKind[];
355
+ declare function normalizeStorageConfig(config?: Partial<StorageNodeConfig> | null): StorageNodeConfig;
356
+ declare function isStorageReadConfigured(config: Pick<StorageNodeConfig, "read">): boolean;
357
+ declare function isStorageSetConfigured(config: Pick<StorageNodeConfig, "set">): boolean;
358
+ declare function resolveStorageWriteValue(template: string, scope: unknown): unknown;
359
+ declare function serializeStorageValue(value: unknown): string;
360
+ declare function deserializeStorageValue(raw: string | null): unknown;
361
+ /** 先设置再读取。未配置设置则不写入;未配置读取则返回空。 */
362
+ declare function executeStorageConfig(config: StorageNodeConfig, incomingScope: unknown, accessors?: StorageAccessors | null): unknown;
363
+
364
+ type LogicNodeConfig = {
365
+ /** 用户手写的 update(input) 函数脚本 */
366
+ sourceCode: string;
367
+ };
368
+ declare const DEFAULT_LOGIC_NODE_CONFIG: LogicNodeConfig;
369
+ declare function validateLogicSourceCode(sourceCode: string): {
370
+ ok: true;
371
+ } | {
372
+ ok: false;
373
+ error: string;
374
+ };
375
+ declare function executeLogicConfig(config: LogicNodeConfig, input: unknown): unknown;
376
+
377
+ type ClockNodeConfig = {
378
+ /** 两次输出之间的间隔秒数 */
379
+ intervalSeconds: number;
380
+ /** 输出值中的时间格式化模板,支持 YYYY、MM、DD、HH、mm、ss */
381
+ timeFormat: string;
382
+ /** 收到真信号后的输出次数,默认 1 */
383
+ outputCount: number;
384
+ /** 收到真信号后立即输出第一次,再按间隔继续;关闭则首次也等待 n 秒 */
385
+ emitImmediately: boolean;
386
+ };
387
+ type ClockSignalOutput = {
388
+ /** 按 timeFormat 格式化后的当前时间 */
389
+ formatted: string;
390
+ /** Unix 毫秒时间戳 */
391
+ timestamp: number;
392
+ /** ISO 8601 时间字符串 */
393
+ isoTime: string;
394
+ };
395
+ declare const DEFAULT_CLOCK_NODE_CONFIG: ClockNodeConfig;
396
+ declare function normalizeClockConfig(config?: Partial<ClockNodeConfig> | null): ClockNodeConfig;
397
+ declare function validateClockScheduleConfig(config: ClockNodeConfig): {
398
+ ok: true;
399
+ } | {
400
+ ok: false;
401
+ error: string;
402
+ };
403
+ /** 将 Date 格式化为指定模板(YYYY/MM/DD/HH/mm/ss) */
404
+ declare function formatClockTime(date: Date, pattern: string): string;
405
+ declare function buildClockSignalValue(config: ClockNodeConfig, now?: Date): ClockSignalOutput;
406
+ /**
407
+ * 第 tickIndex 次输出(从 0 起)相对调度起点的目标延迟(毫秒)。
408
+ * - 立即发送且次数 > 1:第 1 次为 0,其余依次为 m、2m…
409
+ * - 未立即发送:依次为 m、2m、3m…
410
+ */
411
+ declare function getClockTickDelayOffsetMs(config: ClockNodeConfig, tickIndex: number): number;
412
+ /** 距离第 tickIndex 次输出还应等待的毫秒数(基于调度起点) */
413
+ declare function getClockTickWaitMs(config: ClockNodeConfig, tickIndex: number, scheduleStartMs: number, nowMs?: number): number;
414
+ /** 停止指定会话的时钟调度 */
415
+ declare function stopClockSchedule(sessionKey: string): void;
416
+ declare function isClockScheduleActive(sessionKey: string): boolean;
417
+ /** 中止时钟:取消剩余 tick,并标记会话供下游传播循环检测 */
418
+ declare function abortClockSession(sessionKey: string): void;
419
+ declare function isClockSessionAborted(sessionKey: string): boolean;
420
+ declare function clearClockSessionAbort(sessionKey: string): void;
421
+ /**
422
+ * 按配置依次触发 onTick;新的调度会取消同 sessionKey 的上一次调度。
423
+ * 返回取消函数。
424
+ */
425
+ declare function startClockSchedule(options: {
426
+ sessionKey: string;
427
+ config: ClockNodeConfig;
428
+ onTick: () => void | Promise<void>;
429
+ onSettled?: () => void;
430
+ }): () => void;
431
+ /** 停止全部时钟调度(如蓝图面板卸载时) */
432
+ declare function stopAllClockSchedules(): void;
433
+
434
+ /** 视图事件节点可监听的常用 DOM 事件 */
435
+ declare const VIEW_EVENT_TYPES: readonly ["click", "dblclick", "contextmenu", "mouseenter", "mouseleave"];
436
+ type ViewEventType = (typeof VIEW_EVENT_TYPES)[number];
437
+ type ViewEventNodeConfig = {
438
+ /** 监听的事件类型,至少一项;默认 click */
439
+ eventTypes: ViewEventType[];
440
+ };
441
+ declare const DEFAULT_VIEW_EVENT_NODE_CONFIG: ViewEventNodeConfig;
442
+ declare function isViewEventType(value: unknown): value is ViewEventType;
443
+ declare function normalizeViewEventConfig(config?: Partial<ViewEventNodeConfig> | null): ViewEventNodeConfig;
444
+ /** 可序列化的 DOM 事件快照(原生 Event 无法作为蓝图信号传递) */
445
+ type ViewEventSnapshot = {
446
+ type: string;
447
+ timeStamp: number;
448
+ clientX?: number;
449
+ clientY?: number;
450
+ pageX?: number;
451
+ pageY?: number;
452
+ button?: number;
453
+ altKey?: boolean;
454
+ ctrlKey?: boolean;
455
+ metaKey?: boolean;
456
+ shiftKey?: boolean;
457
+ };
458
+ /** 触发该事件的视图节点摘要 */
459
+ type ViewEventNodeSnapshot = {
460
+ id: string;
461
+ name?: string;
462
+ materialType?: string;
463
+ x?: number;
464
+ y?: number;
465
+ width?: number;
466
+ height?: number;
467
+ layerId?: string;
468
+ };
469
+ /** 事件节点向下游发出的真信号 value */
470
+ type ViewEventSignal = {
471
+ /** 触发事件(可序列化快照) */
472
+ event: ViewEventSnapshot;
473
+ /** 触发节点 */
474
+ node: ViewEventNodeSnapshot;
475
+ /** 触发的事件类型 */
476
+ eventType: ViewEventType;
477
+ };
478
+ declare function snapshotDomEvent(event: {
479
+ type: string;
480
+ timeStamp?: number;
481
+ clientX?: number;
482
+ clientY?: number;
483
+ pageX?: number;
484
+ pageY?: number;
485
+ button?: number;
486
+ altKey?: boolean;
487
+ ctrlKey?: boolean;
488
+ metaKey?: boolean;
489
+ shiftKey?: boolean;
490
+ }): ViewEventSnapshot;
491
+ declare function snapshotViewEventNode(node: Partial<ViewEventNodeSnapshot> & {
492
+ id: string;
493
+ }): ViewEventNodeSnapshot;
494
+ declare function createViewEventSignal(input: {
495
+ event: ViewEventSnapshot;
496
+ node: ViewEventNodeSnapshot;
497
+ eventType: ViewEventType;
498
+ }): ViewEventSignal;
499
+ declare function collectArmedViewEventNodeIds(nodes: Array<{
500
+ id: string;
501
+ nodeType?: string;
502
+ lifecyclePhase?: string;
503
+ }>, edges: Array<{
504
+ source: string;
505
+ target: string;
506
+ }>, eventNodeType: string, lifecycleNodeType: string, firedPhases: ReadonlySet<string>): Set<string>;
507
+ /** 仅收集已由生命周期注册的事件节点绑定 */
508
+ declare function collectArmedViewEventBindings(nodes: Array<{
509
+ id: string;
510
+ nodeType?: string;
511
+ lifecyclePhase?: string;
512
+ viewElementIds?: string[];
513
+ eventConfig?: Partial<ViewEventNodeConfig> | null;
514
+ }>, edges: Array<{
515
+ source: string;
516
+ target: string;
517
+ }>, eventNodeType: string, lifecycleNodeType: string, firedPhases: ReadonlySet<string>): Map<string, Set<ViewEventType>>;
518
+ declare function collectViewEventBindings(nodes: Array<{
519
+ id?: string;
520
+ nodeType?: string;
521
+ viewElementIds?: string[];
522
+ eventConfig?: Partial<ViewEventNodeConfig> | null;
523
+ }>, eventNodeType: string, armedNodeIds?: ReadonlySet<string>): Map<string, Set<ViewEventType>>;
524
+
525
+ type ExecutionTraceEntry = {
526
+ id: string;
527
+ nodeId: string;
528
+ nodeLabel?: string;
529
+ nodeType: string;
530
+ startedAt: number;
531
+ finishedAt: number;
532
+ isoTime: string;
533
+ inputs: Record<string, unknown>;
534
+ outputs: Record<string, unknown>;
535
+ error?: string;
536
+ /** 时钟节点第几次 tick(从 1 开始) */
537
+ clockTickIndex?: number;
538
+ /** 时钟节点本次调度总 tick 数 */
539
+ clockTickTotal?: number;
540
+ };
541
+ type ExecutionRunRecord = {
542
+ runId: string;
543
+ blueprintId: string | null;
544
+ blueprintName: string;
545
+ lifecycleNodeId: string;
546
+ lifecycleNodeLabel?: string;
547
+ lifecyclePhase?: string;
548
+ startedAt: number;
549
+ finishedAt?: number;
550
+ status: "running" | "completed" | "paused" | "failed";
551
+ entries: ExecutionTraceEntry[];
552
+ };
553
+ declare function serializeTraceValue(value: Value | undefined): unknown;
554
+ declare function createTraceEntryId(): string;
555
+
556
+ declare const BLUEPRINT_NODE_TYPE = "Blueprint";
557
+ declare const DEFAULT_LOGIC_NODE_TYPE = "Logic";
558
+ declare const LIFECYCLE_NODE_TYPE = "Lifecycle";
559
+ declare const FETCH_NODE_TYPE = "DataFetch";
560
+ declare const JSON_NODE_TYPE = "JsonNode";
561
+ declare const STORAGE_NODE_TYPE = "StorageNode";
562
+ declare const CLOCK_NODE_TYPE = "Clock";
563
+ declare const AND_NODE_TYPE = "AndLogic";
564
+ declare const VIEW_NODE_TYPE = "ViewBind";
565
+ declare const EVENT_NODE_TYPE = "ViewEvent";
566
+ /** 蓝图引用节点:单入单出,收到真信号后执行嵌套蓝图 */
567
+ declare const blueprintNodeDefinition: NodeDefinition;
568
+ declare const defaultLogicNodeDefinition: NodeDefinition;
569
+ /** 生命周期钩子节点:无入流,触发后向下游发出真/假信号 */
570
+ declare const lifecycleNodeDefinition: NodeDefinition;
571
+ /** 数据源获取:收到真信号后发起 fetch,成功/失败输出对应信号 */
572
+ declare const fetchNodeDefinition: NodeDefinition;
573
+ /** JSON 解析:收到真信号后将配置的 JSON 转为 object 输出 */
574
+ declare const jsonNodeDefinition: NodeDefinition;
575
+ /** 存储节点:收到真信号后先写入再读取 sessionStorage / localStorage */
576
+ declare const storageNodeDefinition: NodeDefinition;
577
+ /** 时钟节点:收到真信号后按间隔输出含当前时间的真信号 */
578
+ declare const clockNodeDefinition: NodeDefinition;
579
+ /** 并运算:两路输入均为真时输出真信号;单端口多连线按「或」合并 */
580
+ declare const andLogicNodeDefinition: NodeDefinition;
581
+ /** 视图绑定节点:收到信号后为关联视图元素写入 scope,并向下游透传 */
582
+ declare const viewBindNodeDefinition: NodeDefinition;
583
+ /** 视图事件节点:输入必须来自生命周期节点,对应阶段触发后注册事件,视图事件发生时输出真信号 */
584
+ declare const viewEventNodeDefinition: NodeDefinition;
585
+ declare const nodeDefinitionRegistry: Record<string, NodeDefinition>;
586
+ declare function getNodeDefinition(type: string): NodeDefinition;
587
+
588
+ type RunnableGraphNode = {
589
+ id: string;
590
+ nodeType: string;
591
+ label?: string;
592
+ role?: string;
593
+ lifecyclePhase?: PageLifecyclePhase;
594
+ /** 蓝图库记录 id,Blueprint 节点引用嵌套蓝图时使用 */
595
+ libraryBlueprintId?: string;
596
+ blueprintName?: string;
597
+ /** 视图绑定节点关联的视图画布元素 id */
598
+ viewElementIds?: string[];
599
+ fetchConfig?: FetchRequestConfig;
600
+ jsonConfig?: JsonNodeConfig;
601
+ storageConfig?: StorageNodeConfig;
602
+ logicConfig?: LogicNodeConfig;
603
+ clockConfig?: ClockNodeConfig;
604
+ eventConfig?: ViewEventNodeConfig;
605
+ };
606
+ type RunnableGraphEdge = {
607
+ source: string;
608
+ target: string;
609
+ sourceHandle?: string;
610
+ targetHandle?: string;
611
+ };
612
+ type RunnableGraph = {
613
+ nodes: RunnableGraphNode[];
614
+ edges: RunnableGraphEdge[];
615
+ /** 为 true 时调试/执行不因假信号阻塞队列 */
616
+ allowFalseSignalPropagation?: boolean;
617
+ };
618
+ type LibraryBlueprintResolver = (libraryBlueprintId: string) => Promise<RunnableGraph | null>;
619
+ type ViewScopeUpdateCallback = (viewElementIds: string[], scope: unknown) => void;
620
+ type DebugProgressCallback = (entries: ExecutionTraceEntry[]) => void;
621
+ declare class BlueprintGraphRunner {
622
+ private graph;
623
+ private behaviors;
624
+ private outputs;
625
+ private resolveLibraryBlueprint?;
626
+ private debugQueue;
627
+ private debugExecutor;
628
+ private traceEntries;
629
+ private debugHistory;
630
+ private rootLibraryBlueprintId?;
631
+ private resolveBlueprintName?;
632
+ private cycleValidated;
633
+ private debugProgressCallback;
634
+ private onViewScopeUpdate?;
635
+ constructor(graph: RunnableGraph, options?: {
636
+ resolveLibraryBlueprint?: LibraryBlueprintResolver;
637
+ rootLibraryBlueprintId?: string | null;
638
+ resolveBlueprintName?: (libraryBlueprintId: string) => string;
639
+ onViewScopeUpdate?: ViewScopeUpdateCallback;
640
+ });
641
+ ensureNoBlueprintCycle(): Promise<void>;
642
+ private injectedInputs;
643
+ /**
644
+ * 从视图交互触发指定蓝图节点:向该节点 in 口注入真信号并执行下游。
645
+ * payload 写入 scope(UI_EVENT_PAYLOAD_KEY)供 Logic 等节点读取。
646
+ */
647
+ triggerNode(nodeId: string, inputValue?: unknown): Promise<void>;
648
+ private runFromNodeWithUiPayload;
649
+ emitLifecycle(phase: PageLifecyclePhase): Promise<void>;
650
+ /**
651
+ * 嵌套蓝图被引用且父级传入真信号时,触发 blueprintActivated 生命周期节点,
652
+ * 并将父级输入值写入 scope 供节点输出。
653
+ */
654
+ emitBlueprintActivated(inputValue: unknown, parentScope?: Scope): Promise<void>;
655
+ /**
656
+ * 视图节点触发事件时,匹配已注册(上游生命周期已触发)且绑定了该元素、事件类型的事件节点,发出真信号。
657
+ */
658
+ emitViewEvent(payload: ViewEventSignal, armedNodeIds?: ReadonlySet<string>): Promise<void>;
659
+ /** 时钟节点单次输出:向下游传播含当前时间的真信号 */
660
+ propagateClockOutput(nodeId: string, parentScope?: Scope, sessionKey?: string): Promise<void>;
661
+ private clockScopeId;
662
+ private startClockSchedule;
663
+ /** 中止指定时钟节点:停止剩余 tick 与正在执行的下游任务 */
664
+ abortClockNode(nodeId: string): void;
665
+ /** 从所有无入流 signal 的节点开始执行(嵌套蓝图调用) */
666
+ runFromFlowEntries(parentScope?: Scope, options?: {
667
+ preserveOutputs?: boolean;
668
+ }): Promise<BlueprintNodeOutputs>;
669
+ getNodeOutputs(): BlueprintNodeOutputs;
670
+ getTraceEntries(): ExecutionTraceEntry[];
671
+ isDebugSessionActive(): boolean;
672
+ isDebugQueueEmpty(): boolean;
673
+ /** 调试过程中同步最新蓝图拓扑与节点配置 */
674
+ updateGraph(graph: RunnableGraph): void;
675
+ /**
676
+ * 按当前图结构重建待执行队列。
677
+ * 已有 trace 时,从最后执行的节点按最新出边重新入队;便于编辑连线后继续单步调试。
678
+ */
679
+ refreshPendingQueueFromLatestGraph(): void;
680
+ canDebugStepBack(): boolean;
681
+ debugStepBack(): boolean;
682
+ private captureDebugSnapshot;
683
+ private restoreDebugSnapshot;
684
+ private pushDebugSnapshot;
685
+ beginDebugSession(lifecycleNodeId: string): void;
686
+ /** 调试中修改生命周期阶段后,同步队列头部的 scope 信号 */
687
+ refreshDebugLifecycleScope(lifecycleNodeId: string): void;
688
+ private applyLifecycleScopeForNode;
689
+ clearDebugSession(): void;
690
+ debugStep(nodeLabelById?: Record<string, string>, onProgress?: DebugProgressCallback): Promise<{
691
+ done: boolean;
692
+ entry?: ExecutionTraceEntry;
693
+ haltedByFalseSignal?: boolean;
694
+ }>;
695
+ private notifyDebugProgress;
696
+ private awaitClockDelay;
697
+ private buildTraceInputsForNode;
698
+ private appendDebugTraceEntry;
699
+ private enqueueDebugTargets;
700
+ private runDebugTokenSubqueue;
701
+ private executeDebugToken;
702
+ /**
703
+ * 调试模式下执行完整时钟序列:等待 n 次输出(含间隔),
704
+ * 每次更新 trace / 画布高亮,并同步跑完当次下游链。
705
+ */
706
+ private executeClockScheduleForDebug;
707
+ isDebugHaltedByFalseOutput(nodeId?: string): boolean;
708
+ private isFalseOutputNode;
709
+ private haltDebugQueueOnFalseOutput;
710
+ debugRunAll(nodeLabelById?: Record<string, string>, onProgress?: DebugProgressCallback): Promise<ExecutionTraceEntry[]>;
711
+ private registerBlueprintRefBehavior;
712
+ private registerFetchBehavior;
713
+ private registerLogicBehavior;
714
+ private registerJsonBehavior;
715
+ private registerStorageBehavior;
716
+ private registerClockBehavior;
717
+ private registerAndBehavior;
718
+ private registerViewBindBehavior;
719
+ private runFromNode;
720
+ private createExecutor;
721
+ private findSignalEntryNodes;
722
+ private collectOutputs;
723
+ private requireNode;
724
+ /** 队列中的 token 可能是在节点改类型(如视图绑定)之前入队的,执行前与最新图对齐 */
725
+ private syncTokenFromGraph;
726
+ private syncDebugQueueWithLatestGraph;
727
+ private findSignalTargets;
728
+ private findInboundSignalEdges;
729
+ private buildFetchIncomingScope;
730
+ /** 单端口多连线:任一为真则视为真(或语义);支持 triggerNode 注入的入口信号 */
731
+ private resolvePortInputValue;
732
+ private findInboundSignalEdge;
733
+ private getNodeOutput;
734
+ private setNodeOutput;
735
+ }
736
+
737
+ declare const BLUEPRINT_CALL_STACK_KEY = "__blueprintCallStack";
738
+ declare class BlueprintCycleError extends Error {
739
+ readonly cycleIds: string[];
740
+ constructor(cycleIds: string[], message: string);
741
+ }
742
+ declare function collectBlueprintLibraryRefs(graph: RunnableGraph): string[];
743
+ declare function formatBlueprintCycleMessage(cycleIds: string[], resolveName?: (libraryBlueprintId: string) => string): string;
744
+ type BlueprintCycleCheckOptions = {
745
+ rootGraph: RunnableGraph;
746
+ /** 当前蓝图对应的蓝图库 id;工作区蓝图未入库时为 null */
747
+ rootLibraryBlueprintId?: string | null;
748
+ resolveLibraryBlueprint: LibraryBlueprintResolver;
749
+ resolveBlueprintName?: (libraryBlueprintId: string) => string;
750
+ };
751
+ type BlueprintCycleCheckResult = {
752
+ ok: true;
753
+ } | {
754
+ ok: false;
755
+ cycleIds: string[];
756
+ message: string;
757
+ };
758
+ declare function detectBlueprintReferenceCycle(options: BlueprintCycleCheckOptions): Promise<BlueprintCycleCheckResult>;
759
+ declare function assertNoBlueprintReferenceCycle(options: BlueprintCycleCheckOptions): Promise<void>;
760
+ declare function resolveBlueprintCallStack(scopeStack: string[] | undefined, rootLibraryBlueprintId?: string | null): string[];
761
+ declare function detectRuntimeBlueprintCycle(callStack: string[], targetLibraryBlueprintId: string, resolveName?: (libraryBlueprintId: string) => string): BlueprintCycleCheckResult;
762
+
763
+ declare function buildClockSessionKey(scopeId: string, nodeId: string): string;
764
+ declare function abortClockNode(scopeId: string, nodeId: string): void;
765
+ declare function scheduleClockOutputs(options: {
766
+ sessionKey: string;
767
+ config: ClockNodeConfig;
768
+ onTick: () => void | Promise<void>;
769
+ onSettled?: () => void;
770
+ }): () => void;
771
+
772
+ declare function createClockOutputValue(config: ClockNodeConfig): ClockSignalOutput;
773
+
774
+ declare function isClockNodeActive(nodeId: string): boolean;
775
+ declare function getActiveClockNodeIds(): string[];
776
+ declare function subscribeActiveClockNodes(listener: () => void): () => boolean;
777
+
778
+ export { AND_NODE_TYPE, BLUEPRINT_ACTIVATION_INPUT_KEY, BLUEPRINT_CALL_STACK_KEY, BLUEPRINT_NODE_TYPE, type Behavior, type BehaviorContext, type BehaviorFn, BehaviorRegistry, type BlueprintCycleCheckOptions, type BlueprintCycleCheckResult, BlueprintCycleError, BlueprintGraphRunner, type BlueprintNodeOutputs, type BlueprintRefOutput, CLOCK_NODE_TYPE, type ClockNodeConfig, type ClockSignalOutput, DEFAULT_CLOCK_NODE_CONFIG, DEFAULT_FETCH_REQUEST_CONFIG, DEFAULT_JSON_NODE_CONFIG, DEFAULT_LOGIC_NODE_CONFIG, DEFAULT_LOGIC_NODE_TYPE, DEFAULT_STORAGE_NODE_CONFIG, DEFAULT_VIEW_EVENT_NODE_CONFIG, EVENT_NODE_TYPE, type ExecuteFetchOptions, type ExecutionRunRecord, type ExecutionToken, type ExecutionTraceEntry, Executor, type ExecutorDeps, FETCH_CACHES, FETCH_CREDENTIALS, FETCH_HTTP_METHODS, FETCH_MODES, FETCH_NODE_TYPE, FETCH_REDIRECTS, FETCH_RESPONSE_TYPES, FETCH_SCOPE_AUTOCOMPLETE_FALLBACK, type FalseSignal, type FetchHttpMethod, type FetchRequestConfig, type FetchResponseType, type FetchResultValue, type FetchUrlInputMode, type IncomingGraphEdge, type IncomingNodeScope, type IncomingNodeScopeEntry, type IncomingNodeSource, JSON_NODE_TYPE, type JsonNodeConfig, LIFECYCLE_NODE_TYPE, LIFECYCLE_SIGNAL_KEY, type LibraryBlueprintResolver, type LifecycleSignal, type LogicNodeConfig, type NodeDefinition, type NodeSignal, PAGE_LIFECYCLE_LABELS, PAGE_LIFECYCLE_PHASES, type PageLifecyclePhase, type ParsedSwaggerDocument, type PortSpec, type RunnableGraph, type RunnableGraphEdge, type RunnableGraphNode, STORAGE_KINDS, STORAGE_NODE_TYPE, type Scope, type ScopeAutocompleteState, type StorageAccessors, type StorageKind, type StorageNodeConfig, type StorageReadConfig, type StorageSetConfig, type SwaggerApiEndpoint, type TrueSignal, UI_EVENT_PAYLOAD_KEY, VIEW_EVENT_SIGNAL_KEY, VIEW_EVENT_TYPES, VIEW_NODE_TYPE, type Value, type ViewEventNodeConfig, type ViewEventNodeSnapshot, type ViewEventSignal, type ViewEventSnapshot, type ViewEventType, type ViewScopeUpdateCallback, type WebStorageLike, abortClockNode, abortClockSession, andLogicNodeDefinition, applyFetchConfigScope, applyScopeAutocompleteSelection, assertNoBlueprintReferenceCycle, blueprintNodeDefinition, buildClockSessionKey, buildClockSignalValue, buildEndpointFullUrl, buildEndpointSuggestions, buildIncomingNodeScope, buildScopeExpression, clearClockSessionAbort, clockNodeDefinition, collectArmedViewEventBindings, collectArmedViewEventNodeIds, collectBlueprintLibraryRefs, collectIncomingNodeScopeEntries, collectViewEventBindings, combinePortSignalsOr, createClockOutputValue, createFalseSignal, createIncomingNodeScopeEntry, createLifecycleSignal, createTraceEntryId, createTrueSignal, createViewEventSignal, defaultLogicNodeDefinition, deserializeStorageValue, detectBlueprintReferenceCycle, detectRuntimeBlueprintCycle, draftFetchHeadersText, evaluateScopeExpression, evaluateScopeTemplate, evaluateScopeTemplateInJson, executeFetch, executeLogicConfig, executeStorageConfig, fetchConfigHasScopeTemplate, fetchNodeDefinition, filterEndpointSuggestions, formatBlueprintCycleMessage, formatClockTime, getActiveClockNodeIds, getClockTickDelayOffsetMs, getClockTickWaitMs, getFetchBodyValidationError, getFetchHeadersValidationError, getNodeDefinition, getScopeAutocompleteSuggestions, hasScopeTemplate, isClockNodeActive, isClockScheduleActive, isClockSessionAborted, isFalseSignal, isStorageReadConfigured, isStorageSetConfigured, isTrueSignal, isViewEventType, isWholeScopeExpression, jsonNodeDefinition, latestTraceOutputsByNode, lifecycleNodeDefinition, looksLikeJsonText, nodeDefinitionRegistry, normalizeClockConfig, normalizeFetchRequestConfig, normalizeStorageConfig, normalizeViewEventConfig, parseFetchHeadersJson, parseJsonConfig, parseJsonText, parseScopeAutocomplete, parseSwaggerDocument, registerDefaultBehaviors, resolveBlueprintCallStack, resolveFetchBody, resolveFetchHeaders, resolveFetchIncomingScope, resolveFetchRequestUrl, resolveFetchScopeAutocompleteRoot, resolveStorageWriteValue, scheduleClockOutputs, serializeStorageValue, serializeTraceValue, snapshotDomEvent, snapshotViewEventNode, startClockSchedule, stopAllClockSchedules, stopClockSchedule, storageNodeDefinition, stringifyScopeValue, subscribeActiveClockNodes, uniqueStorageKinds, validateClockScheduleConfig, validateFetchJsonText, validateJsonString, validateLogicSourceCode, viewBindNodeDefinition, viewEventNodeDefinition };