@flowgram.ai/variable-core 0.1.0-alpha.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,1279 @@
1
+ import { ContainerModule, interfaces } from 'inversify';
2
+ import * as _flowgram_ai_utils from '@flowgram.ai/utils';
3
+ import { Disposable, Emitter, DisposableCollection, Event } from '@flowgram.ai/utils';
4
+ import { Subject, Observable, BehaviorSubject, Observer as Observer$1 } from 'rxjs';
5
+ export { Observer } from 'rxjs';
6
+ import * as react from 'react';
7
+
8
+ /**
9
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
10
+ * SPDX-License-Identifier: MIT
11
+ */
12
+
13
+ declare const VariableContainerModule: ContainerModule;
14
+
15
+ /**
16
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
17
+ * SPDX-License-Identifier: MIT
18
+ */
19
+
20
+ declare const VariableEngineProvider: unique symbol;
21
+ type VariableEngineProvider = () => VariableEngine;
22
+
23
+ /**
24
+ * 作用域输出
25
+ */
26
+ declare class ScopeOutputData {
27
+ readonly scope: Scope;
28
+ protected variableTable: IVariableTable;
29
+ protected memo: {
30
+ <T>(key: string | symbol, fn: () => T): T;
31
+ clear: (key?: (string | symbol) | undefined) => void;
32
+ };
33
+ get variableEngine(): VariableEngine;
34
+ get globalVariableTable(): IVariableTable;
35
+ /**
36
+ * @deprecated use onListOrAnyVarChange instead
37
+ */
38
+ get onDataChange(): _flowgram_ai_utils.Event<void>;
39
+ /**
40
+ * listen to variable list change
41
+ */
42
+ get onVariableListChange(): (observer: (variables: VariableDeclaration<any>[]) => void) => _flowgram_ai_utils.Disposable;
43
+ /**
44
+ * listen to any variable update in list
45
+ */
46
+ get onAnyVariableChange(): (observer: (changedVariable: VariableDeclaration<any>) => void) => _flowgram_ai_utils.Disposable;
47
+ /**
48
+ * listen to variable list change + any variable update in list
49
+ */
50
+ get onListOrAnyVarChange(): (observer: () => void) => _flowgram_ai_utils.Disposable;
51
+ protected _hasChanges: boolean;
52
+ constructor(scope: Scope);
53
+ /**
54
+ * Scope Output Variable Declarations
55
+ */
56
+ get variables(): VariableDeclaration[];
57
+ /**
58
+ * Output Variable Keys
59
+ */
60
+ get variableKeys(): string[];
61
+ addVariableToTable(variable: VariableDeclaration): void;
62
+ removeVariableFromTable(key: string): void;
63
+ getVariableByKey(key: string): VariableDeclaration<any> | undefined;
64
+ /**
65
+ *
66
+ */
67
+ notifyCoversChange(): void;
68
+ }
69
+
70
+ /**
71
+ * 作用域可用变量
72
+ */
73
+ declare class ScopeAvailableData {
74
+ readonly scope: Scope;
75
+ protected memo: {
76
+ <T>(key: string | symbol, fn: () => T): T;
77
+ clear: (key?: (string | symbol) | undefined) => void;
78
+ };
79
+ get globalVariableTable(): IVariableTable;
80
+ protected refresh$: Subject<void>;
81
+ protected _variables: VariableDeclaration[];
82
+ refresh(): void;
83
+ /**
84
+ * 监听
85
+ */
86
+ protected variables$: Observable<VariableDeclaration[]>;
87
+ protected anyVariableChange$: Observable<VariableDeclaration>;
88
+ /**
89
+ * listen to any variable update in list
90
+ * @param observer
91
+ * @returns
92
+ */
93
+ onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
94
+ /**
95
+ * listen to variable list change
96
+ * @param observer
97
+ * @returns
98
+ */
99
+ onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
100
+ /**
101
+ * @deprecated
102
+ */
103
+ protected onDataChangeEmitter: Emitter<VariableDeclaration<any>[]>;
104
+ protected onListOrAnyVarChangeEmitter: Emitter<VariableDeclaration<any>[]>;
105
+ /**
106
+ * @deprecated use available.onListOrAnyVarChange instead
107
+ */
108
+ onDataChange: _flowgram_ai_utils.Event<VariableDeclaration<any>[]>;
109
+ /**
110
+ * listen to variable list change + any variable drilldown change
111
+ */
112
+ onListOrAnyVarChange: _flowgram_ai_utils.Event<VariableDeclaration<any>[]>;
113
+ constructor(scope: Scope);
114
+ /**
115
+ * 获取可消费变量
116
+ */
117
+ get variables(): VariableDeclaration[];
118
+ /**
119
+ * 获取可访问的变量 keys
120
+ */
121
+ get variableKeys(): string[];
122
+ /**
123
+ * 返回依赖的作用域
124
+ */
125
+ get depScopes(): Scope[];
126
+ /**
127
+ * 通过 keyPath 找到可用变量
128
+ * @param keyPath
129
+ * @returns
130
+ */
131
+ getByKeyPath(keyPath?: string[]): BaseVariableField | undefined;
132
+ /**
133
+ * Track Variable Change (Includes type update and children update) By KeyPath
134
+ * @returns
135
+ */
136
+ trackByKeyPath(keyPath: string[] | undefined, cb: (variable?: BaseVariableField | undefined) => void, opts?: {
137
+ triggerOnInit?: boolean;
138
+ }): Disposable;
139
+ }
140
+
141
+ /**
142
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
143
+ * SPDX-License-Identifier: MIT
144
+ */
145
+
146
+ type Observer<ActionType extends GlobalEventActionType = GlobalEventActionType> = (action: ActionType) => void;
147
+ declare class ScopeEventData {
148
+ readonly scope: Scope;
149
+ event$: Subject<GlobalEventActionType>;
150
+ dispatch<ActionType extends GlobalEventActionType = GlobalEventActionType>(action: ActionType): void;
151
+ subscribe<ActionType extends GlobalEventActionType = GlobalEventActionType>(observer: Observer<ActionType>): Disposable;
152
+ on<ActionType extends GlobalEventActionType = GlobalEventActionType>(type: ActionType['type'], observer: Observer<ActionType>): Disposable;
153
+ constructor(scope: Scope);
154
+ }
155
+
156
+ interface IScopeConstructor {
157
+ new (options: {
158
+ id: string | symbol;
159
+ variableEngine: VariableEngine;
160
+ meta?: Record<string, any>;
161
+ }): Scope;
162
+ }
163
+ declare class Scope<ScopeMeta extends Record<string, any> = Record<string, any>> {
164
+ /**
165
+ * Scope 唯一索引
166
+ */
167
+ readonly id: string | symbol;
168
+ /**
169
+ * Scope 依赖变量引擎
170
+ */
171
+ readonly variableEngine: VariableEngine;
172
+ /**
173
+ * 作用域的基本元信息,包括作用域所在节点及一些 flag 信息,上层业务可以额外扩展
174
+ */
175
+ readonly meta: ScopeMeta;
176
+ /**
177
+ * 作用域 AST 根节点
178
+ * - Map<formItemKey, formItemValue>
179
+ */
180
+ readonly ast: MapNode;
181
+ /**
182
+ * 可用变量数据管理
183
+ */
184
+ readonly available: ScopeAvailableData;
185
+ /**
186
+ * 输出变量数据管理
187
+ */
188
+ readonly output: ScopeOutputData;
189
+ /**
190
+ * 作用域事件管理
191
+ */
192
+ readonly event: ScopeEventData;
193
+ /**
194
+ * 数据缓存
195
+ */
196
+ protected memo: {
197
+ <T>(key: string | symbol, fn: () => T): T;
198
+ clear: (key?: (string | symbol) | undefined) => void;
199
+ };
200
+ toDispose: DisposableCollection;
201
+ constructor(options: {
202
+ id: string | symbol;
203
+ variableEngine: VariableEngine;
204
+ meta?: ScopeMeta;
205
+ });
206
+ refreshCovers(): void;
207
+ refreshDeps(): void;
208
+ get depScopes(): Scope[];
209
+ get coverScopes(): Scope[];
210
+ dispose(): void;
211
+ onDispose: _flowgram_ai_utils.Event<void>;
212
+ get disposed(): boolean;
213
+ /**
214
+ * Sets a variable in the Scope with the default key 'outputs'.
215
+ *
216
+ * @param json - The JSON value to store.
217
+ * @returns The updated AST node.
218
+ */
219
+ setVar(json: ASTNodeJSON): ASTNode;
220
+ /**
221
+ * Sets a variable in the Scope by key.
222
+ *
223
+ * @param key - The key of the variable to set.
224
+ * @param json - The JSON value to store.
225
+ * @returns The updated AST node.
226
+ */
227
+ setVar(key: string, json: ASTNodeJSON): ASTNode;
228
+ /**
229
+ * Retrieves a variable from the Scope by key.
230
+ *
231
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
232
+ * @returns The value of the variable, or undefined if not found.
233
+ */
234
+ getVar(key?: string): ASTNode<any, any> | undefined;
235
+ /**
236
+ * Clears a variable from the Scope by key.
237
+ *
238
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
239
+ * @returns The updated AST node.
240
+ */
241
+ clearVar(key?: string): void;
242
+ }
243
+
244
+ /**
245
+ * 作用域依赖关系管理数据结构
246
+ * - ScopeOrder 可能存在多种实现方式,因此采取抽象类的方式,具体的实现由子类实现
247
+ */
248
+ declare abstract class ScopeChain {
249
+ readonly toDispose: DisposableCollection;
250
+ variableEngineProvider: VariableEngineProvider;
251
+ get variableEngine(): VariableEngine;
252
+ constructor();
253
+ /**
254
+ * 所有作用域依赖关系刷新
255
+ */
256
+ refreshAllChange(): void;
257
+ abstract getDeps(scope: Scope): Scope[];
258
+ abstract getCovers(scope: Scope): Scope[];
259
+ abstract sortAll(): Scope[];
260
+ dispose(): void;
261
+ get disposed(): boolean;
262
+ get onDispose(): Event<void>;
263
+ }
264
+
265
+ interface ASTNodeRegistry<JSON extends ASTNodeJSON = any, InjectOpts = any> {
266
+ kind: string;
267
+ new (params: CreateASTParams, injectOpts: InjectOpts): ASTNode<JSON>;
268
+ }
269
+ declare abstract class ASTNode<JSON extends ASTNodeJSON = any, InjectOpts = any> implements Disposable {
270
+ /**
271
+ * @deprecated
272
+ * 获取 ASTNode 注入的 opts
273
+ *
274
+ * 请使用 @injectToAst(XXXService) declare xxxService: XXXService 实现外部依赖注入
275
+ */
276
+ readonly opts?: InjectOpts;
277
+ /**
278
+ * 节点的唯一标识符,节点不指定则默认由 nanoid 生成,不可更改
279
+ * - 如需要生成新 key,则销毁当前节点并生成新的节点
280
+ */
281
+ readonly key: Identifier;
282
+ /**
283
+ * 节点类型
284
+ */
285
+ static readonly kind: ASTKindType;
286
+ /**
287
+ * 节点 Flags,记录一些 Flag 信息
288
+ */
289
+ readonly flags: number;
290
+ /**
291
+ * 节点所处的作用域
292
+ */
293
+ readonly scope: Scope;
294
+ /**
295
+ * 父节点
296
+ */
297
+ readonly parent: ASTNode | undefined;
298
+ /**
299
+ * 节点的版本号,每 fireChange 一次 version + 1
300
+ */
301
+ protected _version: number;
302
+ /**
303
+ * 更新锁
304
+ */
305
+ changeLocked: boolean;
306
+ /**
307
+ * Batch Update 相关参数
308
+ */
309
+ private _batch;
310
+ /**
311
+ * AST 节点变化事件,基于 Rxjs 实现
312
+ * - 使用了 BehaviorSubject, 在订阅时会自动触发一次事件,事件为当前值
313
+ */
314
+ readonly value$: BehaviorSubject<ASTNode>;
315
+ /**
316
+ * 子节点
317
+ */
318
+ protected _children: Set<ASTNode<any, any>>;
319
+ /**
320
+ * 删除节点处理事件列表
321
+ */
322
+ readonly toDispose: DisposableCollection;
323
+ /**
324
+ * 销毁时触发的回调
325
+ */
326
+ onDispose: _flowgram_ai_utils.Event<void>;
327
+ /**
328
+ * 构造函数
329
+ * @param createParams 创建 ASTNode 的必要参数
330
+ * @param injectOptions 依赖注入各种模块
331
+ */
332
+ constructor({ key, parent, scope }: CreateASTParams, opts?: InjectOpts);
333
+ /**
334
+ * AST 节点的类型
335
+ */
336
+ get kind(): string;
337
+ /**
338
+ * 解析 AST JSON 数据
339
+ * @param json AST JSON 数据
340
+ */
341
+ abstract fromJSON(json: JSON): void;
342
+ /**
343
+ * 获取当前节点所有子节点
344
+ */
345
+ get children(): ASTNode[];
346
+ /**
347
+ * 转化为 ASTNodeJSON
348
+ * @returns
349
+ */
350
+ toJSON(): ASTNodeJSON;
351
+ /**
352
+ * 创建子节点
353
+ * @param json 子节点的 AST JSON
354
+ * @returns
355
+ */
356
+ protected createChildNode<ChildNode extends ASTNode = ASTNode>(json: ASTNodeJSON): ChildNode;
357
+ /**
358
+ * 更新子节点,快速实现子节点更新消费逻辑
359
+ * @param keyInThis 当前对象上的指定 key
360
+ */
361
+ protected updateChildNodeByKey(keyInThis: keyof this, nextJSON?: ASTNodeJSON): void;
362
+ /**
363
+ * 批处理更新,批处理函数内所有的 fireChange 都合并成一个
364
+ * @param updater 批处理函数
365
+ * @returns
366
+ */
367
+ protected withBatchUpdate<ParamTypes extends any[], ReturnType>(updater: (...args: ParamTypes) => ReturnType): (...args: ParamTypes) => ReturnType;
368
+ /**
369
+ * 触发当前节点更新
370
+ */
371
+ fireChange(): void;
372
+ /**
373
+ * 节点的版本值
374
+ * - 通过 NodeA === NodeB && versionA === versionB 可以比较两者是否相等
375
+ */
376
+ get version(): number;
377
+ /**
378
+ * 节点唯一 hash 值
379
+ */
380
+ get hash(): string;
381
+ /**
382
+ * 监听 AST 节点的变化
383
+ * @param observer 监听回调
384
+ * @param selector 监听指定数据
385
+ * @returns
386
+ */
387
+ subscribe<Data = this>(observer: ObserverOrNext<Data>, { selector, debounceAnimation, triggerOnInit }?: SubscribeConfig<this, Data>): Disposable;
388
+ dispatchGlobalEvent<ActionType extends GlobalEventActionType = GlobalEventActionType>(event: Omit<ActionType, 'ast'>): void;
389
+ /**
390
+ * 销毁
391
+ */
392
+ dispose(): void;
393
+ get disposed(): boolean;
394
+ /**
395
+ * 节点扩展信息
396
+ */
397
+ [key: string]: unknown;
398
+ }
399
+
400
+ /**
401
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
402
+ * SPDX-License-Identifier: MIT
403
+ */
404
+
405
+ type ASTKindType = string;
406
+ type Identifier = string;
407
+ interface ASTNodeJSON {
408
+ kind?: ASTKindType;
409
+ key?: Identifier;
410
+ [key: string]: any;
411
+ }
412
+ /**
413
+ * 核心 AST 节点类型
414
+ */
415
+ declare enum ASTKind {
416
+ /**
417
+ * 类型相关
418
+ * - 内部默认实现一套基于 JSON 类型的类型 AST 节点
419
+ */
420
+ String = "String",
421
+ Number = "Number",
422
+ Integer = "Integer",
423
+ Boolean = "Boolean",
424
+ Object = "Object",
425
+ Array = "Array",
426
+ Map = "Map",
427
+ Union = "Union",
428
+ Any = "Any",
429
+ CustomType = "CustomType",
430
+ /**
431
+ * 声明
432
+ */
433
+ Property = "Property",
434
+ VariableDeclaration = "VariableDeclaration",
435
+ VariableDeclarationList = "VariableDeclarationList",
436
+ /**
437
+ * 表达式
438
+ */
439
+ KeyPathExpression = "KeyPathExpression",
440
+ EnumerateExpression = "EnumerateExpression",
441
+ WrapArrayExpression = "WrapArrayExpression",
442
+ /**
443
+ * 通用 AST 节点
444
+ */
445
+ ListNode = "ListNode",
446
+ DataNode = "DataNode",
447
+ MapNode = "MapNode"
448
+ }
449
+ interface CreateASTParams {
450
+ scope: Scope;
451
+ key?: Identifier;
452
+ parent?: ASTNode;
453
+ }
454
+ type ASTNodeJSONOrKind = string | ASTNodeJSON;
455
+ type ObserverOrNext<T> = Partial<Observer$1<T>> | ((value: T) => void);
456
+ interface SubscribeConfig<This, Data> {
457
+ debounceAnimation?: boolean;
458
+ triggerOnInit?: boolean;
459
+ selector?: (curr: This) => Data;
460
+ }
461
+ type GetKindJSON<KindType extends string, JSON extends ASTNodeJSON> = {
462
+ kind: KindType;
463
+ key?: Identifier;
464
+ } & JSON;
465
+ type GetKindJSONOrKind<KindType extends string, JSON extends ASTNodeJSON> = ({
466
+ kind: KindType;
467
+ key?: Identifier;
468
+ } & JSON) | KindType;
469
+ interface GlobalEventActionType<Type = string, Payload = any, AST extends ASTNode = ASTNode> {
470
+ type: Type;
471
+ payload?: Payload;
472
+ ast?: AST;
473
+ }
474
+
475
+ /**
476
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
477
+ * SPDX-License-Identifier: MIT
478
+ */
479
+
480
+ type DataInjector = () => Record<string, any>;
481
+ declare class ASTRegisters {
482
+ protected injectors: Map<ASTKindType, DataInjector>;
483
+ protected astMap: Map<ASTKindType, ASTNodeRegistry>;
484
+ /**
485
+ * 核心 AST 节点注册
486
+ */
487
+ constructor();
488
+ /**
489
+ * 创建 AST 节点
490
+ * @param param 创建参数
491
+ * @returns
492
+ */
493
+ createAST<ReturnNode extends ASTNode = ASTNode>(json: ASTNodeJSON, { parent, scope }: CreateASTParams): ReturnNode;
494
+ /**
495
+ * 根据 AST 节点类型获取节点 Registry
496
+ * @param kind
497
+ * @returns
498
+ */
499
+ getASTRegistryByKind(kind: ASTKindType): ASTNodeRegistry<any, any> | undefined;
500
+ /**
501
+ * 注册 AST 节点
502
+ * @param ASTNode
503
+ * @param injector
504
+ */
505
+ registerAST(ASTNode: ASTNodeRegistry, injector?: DataInjector): void;
506
+ }
507
+
508
+ /**
509
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
510
+ * SPDX-License-Identifier: MIT
511
+ */
512
+ declare enum ASTNodeFlags {
513
+ None = 0,
514
+ /**
515
+ * 变量字段
516
+ */
517
+ VariableField = 1,
518
+ /**
519
+ * 表达式
520
+ */
521
+ Expression = 4,
522
+ /**
523
+ * 变量类型
524
+ */
525
+ BasicType = 8,
526
+ DrilldownType = 16,
527
+ EnumerateType = 32,
528
+ UnionType = 64,
529
+ VariableType = 120
530
+ }
531
+
532
+ /**
533
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
534
+ * SPDX-License-Identifier: MIT
535
+ */
536
+
537
+ /**
538
+ * 通用数据 AST 节点,无子节点
539
+ */
540
+ declare class DataNode<Data = any> extends ASTNode {
541
+ static kind: string;
542
+ protected _data: Data;
543
+ get data(): Data;
544
+ fromJSON(json: Data): void;
545
+ toJSON(): {
546
+ kind: ASTKind;
547
+ } & Data;
548
+ partialUpdate(nextData: Data): void;
549
+ }
550
+
551
+ /**
552
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
553
+ * SPDX-License-Identifier: MIT
554
+ */
555
+
556
+ interface ListNodeJSON {
557
+ list: ASTNodeJSON[];
558
+ }
559
+ declare class ListNode extends ASTNode<ListNodeJSON> {
560
+ static kind: string;
561
+ protected _list: ASTNode[];
562
+ get list(): ASTNode[];
563
+ fromJSON({ list }: ListNodeJSON): void;
564
+ toJSON(): ASTNodeJSON;
565
+ }
566
+
567
+ /**
568
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
569
+ * SPDX-License-Identifier: MIT
570
+ */
571
+
572
+ interface MapNodeJSON {
573
+ map: [string, ASTNodeJSON][];
574
+ }
575
+ declare class MapNode extends ASTNode<MapNodeJSON> {
576
+ static kind: string;
577
+ protected map: Map<string, ASTNode>;
578
+ fromJSON({ map }: MapNodeJSON): void;
579
+ toJSON(): ASTNodeJSON;
580
+ /**
581
+ * 往 Map 中设置 ASTNode
582
+ * @param key ASTNode 的索引,
583
+ * @param json
584
+ */
585
+ set<Node extends ASTNode = ASTNode>(key: string, nextJSON: ASTNodeJSON): Node;
586
+ /**
587
+ * 移除指定 ASTNode
588
+ * @param key
589
+ */
590
+ remove(key: string): void;
591
+ /**
592
+ * 获取 ASTNode
593
+ * @param key
594
+ * @returns
595
+ */
596
+ get(key: string): ASTNode | undefined;
597
+ }
598
+
599
+ /**
600
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
601
+ * SPDX-License-Identifier: MIT
602
+ */
603
+
604
+ declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
605
+ flags: number;
606
+ /**
607
+ * 类型是否一致
608
+ * @param targetTypeJSON
609
+ */
610
+ isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
611
+ /**
612
+ * 可下钻类型需实现
613
+ * @param keyPath
614
+ */
615
+ getByKeyPath(keyPath?: string[]): BaseVariableField | undefined;
616
+ /**
617
+ * Get AST JSON for current base type
618
+ * @returns
619
+ */
620
+ toJSON(): ASTNodeJSON;
621
+ }
622
+
623
+ /**
624
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
625
+ * SPDX-License-Identifier: MIT
626
+ */
627
+
628
+ declare class StringType extends BaseType {
629
+ flags: ASTNodeFlags;
630
+ static kind: string;
631
+ fromJSON(): void;
632
+ }
633
+
634
+ /**
635
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
636
+ * SPDX-License-Identifier: MIT
637
+ */
638
+
639
+ declare class IntegerType extends BaseType {
640
+ flags: ASTNodeFlags;
641
+ static kind: string;
642
+ fromJSON(): void;
643
+ }
644
+
645
+ /**
646
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
647
+ * SPDX-License-Identifier: MIT
648
+ */
649
+
650
+ declare class BooleanType extends BaseType {
651
+ static kind: string;
652
+ fromJSON(): void;
653
+ }
654
+
655
+ /**
656
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
657
+ * SPDX-License-Identifier: MIT
658
+ */
659
+
660
+ declare class NumberType extends BaseType {
661
+ static kind: string;
662
+ fromJSON(): void;
663
+ }
664
+
665
+ /**
666
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
667
+ * SPDX-License-Identifier: MIT
668
+ */
669
+
670
+ interface ArrayJSON {
671
+ items?: ASTNodeJSONOrKind;
672
+ }
673
+ declare class ArrayType extends BaseType<ArrayJSON> {
674
+ flags: ASTNodeFlags;
675
+ static kind: string;
676
+ items: BaseType;
677
+ fromJSON({ items }: ArrayJSON): void;
678
+ get canDrilldownItems(): boolean;
679
+ getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
680
+ isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
681
+ /**
682
+ * Array 强比较
683
+ * @param targetTypeJSON
684
+ * @returns
685
+ */
686
+ protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
687
+ toJSON(): ASTNodeJSON;
688
+ }
689
+
690
+ /**
691
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
692
+ * SPDX-License-Identifier: MIT
693
+ */
694
+
695
+ interface MapJSON {
696
+ keyType?: ASTNodeJSONOrKind;
697
+ valueType?: ASTNodeJSONOrKind;
698
+ }
699
+ declare class MapType extends BaseType<MapJSON> {
700
+ static kind: string;
701
+ keyType: BaseType;
702
+ valueType: BaseType;
703
+ fromJSON({ keyType, valueType }: MapJSON): void;
704
+ isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
705
+ /**
706
+ * Map 强比较
707
+ * @param targetTypeJSON
708
+ * @returns
709
+ */
710
+ protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
711
+ toJSON(): ASTNodeJSON;
712
+ }
713
+
714
+ /**
715
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
716
+ * SPDX-License-Identifier: MIT
717
+ */
718
+
719
+ type PropertyJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
720
+ key: string;
721
+ };
722
+ declare class Property<VariableMeta = any> extends BaseVariableField<VariableMeta> {
723
+ static kind: string;
724
+ }
725
+
726
+ /**
727
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
728
+ * SPDX-License-Identifier: MIT
729
+ */
730
+
731
+ interface ObjectJSON<VariableMeta = any> {
732
+ /**
733
+ * Object 的 properties 一定是 Property 类型,因此业务可以不用填 kind
734
+ */
735
+ properties?: PropertyJSON<VariableMeta>[];
736
+ }
737
+ type ObjectPropertiesChangeAction = GlobalEventActionType<'ObjectPropertiesChange', {
738
+ prev: Property[];
739
+ next: Property[];
740
+ }, ObjectType>;
741
+ declare class ObjectType extends BaseType<ObjectJSON> {
742
+ flags: ASTNodeFlags;
743
+ static kind: string;
744
+ propertyTable: Map<string, Property>;
745
+ properties: Property[];
746
+ fromJSON({ properties }: ObjectJSON): void;
747
+ toJSON(): ASTNodeJSON;
748
+ /**
749
+ * 根据 KeyPath 找到对应的变量
750
+ * @param keyPath 变量路径
751
+ * @returns
752
+ */
753
+ getByKeyPath(keyPath: string[]): Property | undefined;
754
+ isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
755
+ /**
756
+ * Object 类型强比较
757
+ * @param targetTypeJSON
758
+ * @returns
759
+ */
760
+ protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
761
+ }
762
+
763
+ /**
764
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
765
+ * SPDX-License-Identifier: MIT
766
+ */
767
+
768
+ interface UnionJSON {
769
+ types?: ASTNodeJSONOrKind[];
770
+ }
771
+
772
+ /**
773
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
774
+ * SPDX-License-Identifier: MIT
775
+ */
776
+
777
+ interface CustomTypeJSON {
778
+ typeName: string;
779
+ }
780
+ declare class CustomType extends BaseType<CustomTypeJSON> {
781
+ static kind: string;
782
+ protected _typeName: string;
783
+ get typeName(): string;
784
+ fromJSON(json: CustomTypeJSON): void;
785
+ isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
786
+ }
787
+
788
+ /**
789
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
790
+ * SPDX-License-Identifier: MIT
791
+ */
792
+
793
+ type ExpressionRefs = (BaseVariableField | undefined)[];
794
+ declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
795
+ flags: ASTNodeFlags;
796
+ /**
797
+ * 获取全局变量表,方便表达式获取引用变量
798
+ */
799
+ get globalVariableTable(): IVariableTable;
800
+ /**
801
+ * 父变量字段,通过由近而远的方式进行排序
802
+ */
803
+ get parentFields(): BaseVariableField[];
804
+ /**
805
+ * 获取表达式引用的变量字段
806
+ * - 通常是 变量 VariableDeclaration,或者 属性 Property 节点
807
+ */
808
+ abstract getRefFields(): ExpressionRefs;
809
+ /**
810
+ * 表达式返回的数据类型
811
+ */
812
+ abstract returnType: BaseType | undefined;
813
+ /**
814
+ * 引用变量
815
+ */
816
+ protected _refs: ExpressionRefs;
817
+ get refs(): ExpressionRefs;
818
+ protected refreshRefs$: Subject<void>;
819
+ /**
820
+ * 刷新变量引用
821
+ */
822
+ refreshRefs(): void;
823
+ /**
824
+ * 监听引用变量变化
825
+ * 监听 [a.b.c] -> [a.b]
826
+ */
827
+ refs$: Observable<ExpressionRefs>;
828
+ constructor(params: CreateASTParams, opts?: InjectOpts);
829
+ }
830
+
831
+ /**
832
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
833
+ * SPDX-License-Identifier: MIT
834
+ */
835
+
836
+ interface KeyPathExpressionJSON$1 {
837
+ keyPath: string[];
838
+ }
839
+ declare class KeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON$1> extends BaseExpression<CustomPathJSON> {
840
+ static kind: string;
841
+ protected _keyPath: string[];
842
+ get keyPath(): string[];
843
+ getRefFields(): BaseVariableField[];
844
+ get returnType(): BaseType | undefined;
845
+ /**
846
+ * 业务重改该方法可快速定制自己的 Path 表达式
847
+ * - 只需要将业务的 Path 解析为变量系统的 KeyPath 即可
848
+ * @param json 业务定义的 Path 表达式
849
+ * @returns
850
+ */
851
+ protected parseToKeyPath(json: CustomPathJSON): string[];
852
+ fromJSON(json: CustomPathJSON): void;
853
+ constructor(params: CreateASTParams, opts: any);
854
+ toJSON(): ASTNodeJSON;
855
+ }
856
+
857
+ /**
858
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
859
+ * SPDX-License-Identifier: MIT
860
+ */
861
+
862
+ interface EnumerateExpressionJSON {
863
+ enumerateFor: ASTNodeJSON;
864
+ }
865
+ /**
866
+ * 遍历表达式,对列表进行遍历,获取遍历后的变量类型
867
+ */
868
+ declare class EnumerateExpression extends BaseExpression<EnumerateExpressionJSON> {
869
+ static kind: string;
870
+ protected _enumerateFor: BaseExpression | undefined;
871
+ get enumerateFor(): BaseExpression<any, any> | undefined;
872
+ get returnType(): BaseType | undefined;
873
+ getRefFields(): [];
874
+ fromJSON({ enumerateFor: expression }: EnumerateExpressionJSON): void;
875
+ toJSON(): ASTNodeJSON;
876
+ }
877
+
878
+ /**
879
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
880
+ * SPDX-License-Identifier: MIT
881
+ */
882
+
883
+ interface KeyPathExpressionJSON {
884
+ keyPath: string[];
885
+ }
886
+ /**
887
+ * 新版 KeyPathExpressionV2,相比旧版:
888
+ * - returnType 拷贝新一份,避免引用问题
889
+ * - 引入成环检测
890
+ */
891
+ declare class KeyPathExpressionV2<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON> extends BaseExpression<CustomPathJSON> {
892
+ static kind: string;
893
+ protected _keyPath: string[];
894
+ get keyPath(): string[];
895
+ getRefFields(): BaseVariableField[];
896
+ _returnType: BaseType;
897
+ get returnType(): BaseType<any, any>;
898
+ /**
899
+ * 业务重改该方法可快速定制自己的 Path 表达式
900
+ * - 只需要将业务的 Path 解析为变量系统的 KeyPath 即可
901
+ * @param json 业务定义的 Path 表达式
902
+ * @returns
903
+ */
904
+ protected parseToKeyPath(json: CustomPathJSON): string[];
905
+ fromJSON(json: CustomPathJSON): void;
906
+ getReturnTypeJSONByRef(_ref: BaseVariableField | undefined): ASTNodeJSON | undefined;
907
+ protected prevRefTypeHash: string | undefined;
908
+ constructor(params: CreateASTParams, opts: any);
909
+ toJSON(): ASTNodeJSON;
910
+ }
911
+
912
+ /**
913
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
914
+ * SPDX-License-Identifier: MIT
915
+ */
916
+
917
+ interface WrapArrayExpressionJSON {
918
+ wrapFor: ASTNodeJSON;
919
+ }
920
+ /**
921
+ * 遍历表达式,对列表进行遍历,获取遍历后的变量类型
922
+ */
923
+ declare class WrapArrayExpression extends BaseExpression<WrapArrayExpressionJSON> {
924
+ static kind: string;
925
+ protected _wrapFor: BaseExpression | undefined;
926
+ protected _returnType: BaseType | undefined;
927
+ get wrapFor(): BaseExpression<any, any> | undefined;
928
+ get returnType(): BaseType | undefined;
929
+ refreshReturnType(): void;
930
+ getRefFields(): [];
931
+ fromJSON({ wrapFor: expression }: WrapArrayExpressionJSON): void;
932
+ toJSON(): ASTNodeJSON;
933
+ protected init(): void;
934
+ }
935
+
936
+ /**
937
+ * 声明类 AST 节点
938
+ */
939
+ type BaseVariableFieldJSON<VariableMeta = any> = {
940
+ key?: Identifier;
941
+ type?: ASTNodeJSONOrKind;
942
+ initializer?: ASTNodeJSON;
943
+ meta?: VariableMeta;
944
+ };
945
+ declare abstract class BaseVariableField<VariableMeta = any> extends ASTNode<BaseVariableFieldJSON<VariableMeta>> {
946
+ flags: ASTNodeFlags;
947
+ protected _type?: BaseType;
948
+ protected _meta: VariableMeta;
949
+ protected _initializer?: BaseExpression;
950
+ /**
951
+ * 父变量字段,通过由近而远的方式进行排序
952
+ */
953
+ get parentFields(): BaseVariableField[];
954
+ get keyPath(): string[];
955
+ get meta(): VariableMeta;
956
+ get type(): BaseType;
957
+ get initializer(): BaseExpression | undefined;
958
+ get hash(): string;
959
+ /**
960
+ * 解析 VariableDeclarationJSON 从而生成变量声明节点
961
+ */
962
+ fromJSON({ type, initializer, meta }: BaseVariableFieldJSON<VariableMeta>): void;
963
+ updateType(type: BaseVariableFieldJSON['type']): void;
964
+ updateInitializer(nextInitializer?: BaseVariableFieldJSON['initializer']): void;
965
+ updateMeta(nextMeta: VariableMeta): void;
966
+ /**
967
+ * 根据 keyPath 去找下钻的变量字段
968
+ * @param keyPath
969
+ * @returns
970
+ */
971
+ getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
972
+ /**
973
+ * 监听类型变化
974
+ * @param observer
975
+ * @returns
976
+ */
977
+ onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
978
+ /**
979
+ * 转换为 JSON
980
+ * @returns
981
+ */
982
+ toJSON(): BaseVariableFieldJSON<VariableMeta> & {
983
+ kind: string;
984
+ };
985
+ }
986
+
987
+ /**
988
+ * 声明类 AST 节点
989
+ */
990
+ type VariableDeclarationJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
991
+ order?: number;
992
+ };
993
+ declare class VariableDeclaration<VariableMeta = any> extends BaseVariableField<VariableMeta> {
994
+ static kind: string;
995
+ protected _order: number;
996
+ get order(): number;
997
+ constructor(params: CreateASTParams);
998
+ /**
999
+ * 解析 VariableDeclarationJSON 从而生成变量声明节点
1000
+ */
1001
+ fromJSON({ order, ...rest }: VariableDeclarationJSON<VariableMeta>): void;
1002
+ updateOrder(order?: number): void;
1003
+ onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
1004
+ }
1005
+
1006
+ /**
1007
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1008
+ * SPDX-License-Identifier: MIT
1009
+ */
1010
+
1011
+ interface VariableDeclarationListJSON<VariableMeta = any> {
1012
+ /**
1013
+ * declarations 一定是 VariableDeclaration 类型,因此业务可以不用填 kind
1014
+ */
1015
+ declarations?: VariableDeclarationJSON<VariableMeta>[];
1016
+ startOrder?: number;
1017
+ }
1018
+ type VariableDeclarationListChangeAction = GlobalEventActionType<'VariableListChange', {
1019
+ prev: VariableDeclaration[];
1020
+ next: VariableDeclaration[];
1021
+ }, VariableDeclarationList>;
1022
+ declare class VariableDeclarationList extends ASTNode<VariableDeclarationListJSON> {
1023
+ static kind: string;
1024
+ declarationTable: Map<string, VariableDeclaration>;
1025
+ declarations: VariableDeclaration[];
1026
+ fromJSON({ declarations, startOrder }: VariableDeclarationListJSON): void;
1027
+ toJSON(): ASTNodeJSON;
1028
+ }
1029
+
1030
+ declare namespace ASTFactory {
1031
+ /**
1032
+ * 类型相关
1033
+ * @returns
1034
+ */
1035
+ const createString: () => {
1036
+ kind: ASTKind;
1037
+ };
1038
+ const createNumber: () => {
1039
+ kind: ASTKind;
1040
+ };
1041
+ const createBoolean: () => {
1042
+ kind: ASTKind;
1043
+ };
1044
+ const createInteger: () => {
1045
+ kind: ASTKind;
1046
+ };
1047
+ const createObject: (json: ObjectJSON) => {
1048
+ properties?: PropertyJSON<any>[] | undefined;
1049
+ kind: ASTKind;
1050
+ };
1051
+ const createArray: (json: ArrayJSON) => {
1052
+ items?: ASTNodeJSONOrKind | undefined;
1053
+ kind: ASTKind;
1054
+ };
1055
+ const createMap: (json: MapJSON) => {
1056
+ keyType?: ASTNodeJSONOrKind | undefined;
1057
+ valueType?: ASTNodeJSONOrKind | undefined;
1058
+ kind: ASTKind;
1059
+ };
1060
+ const createUnion: (json: UnionJSON) => {
1061
+ types?: ASTNodeJSONOrKind[] | undefined;
1062
+ kind: ASTKind;
1063
+ };
1064
+ const createCustomType: (json: CustomTypeJSON) => {
1065
+ typeName: string;
1066
+ kind: ASTKind;
1067
+ };
1068
+ /**
1069
+ * 声明相关
1070
+ */
1071
+ const createVariableDeclaration: <VariableMeta = any>(json: VariableDeclarationJSON<VariableMeta>) => {
1072
+ key?: string | undefined;
1073
+ type?: ASTNodeJSONOrKind | undefined;
1074
+ initializer?: ASTNodeJSON | undefined;
1075
+ meta?: VariableMeta | undefined;
1076
+ order?: number | undefined;
1077
+ kind: ASTKind;
1078
+ };
1079
+ const createProperty: <VariableMeta = any>(json: PropertyJSON<VariableMeta>) => {
1080
+ key: string;
1081
+ type?: ASTNodeJSONOrKind | undefined;
1082
+ initializer?: ASTNodeJSON | undefined;
1083
+ meta?: VariableMeta | undefined;
1084
+ kind: ASTKind;
1085
+ };
1086
+ const createVariableDeclarationList: (json: VariableDeclarationListJSON) => {
1087
+ declarations?: VariableDeclarationJSON<any>[] | undefined;
1088
+ startOrder?: number | undefined;
1089
+ kind: ASTKind;
1090
+ };
1091
+ /**
1092
+ * 表达式相关
1093
+ */
1094
+ const createEnumerateExpression: (json: EnumerateExpressionJSON) => {
1095
+ enumerateFor: ASTNodeJSON;
1096
+ kind: ASTKind;
1097
+ };
1098
+ const createKeyPathExpression: (json: KeyPathExpressionJSON$1) => {
1099
+ keyPath: string[];
1100
+ kind: ASTKind;
1101
+ };
1102
+ const createWrapArrayExpression: (json: WrapArrayExpressionJSON) => {
1103
+ wrapFor: ASTNodeJSON;
1104
+ kind: ASTKind;
1105
+ };
1106
+ /**
1107
+ * 通过 AST Class 创建
1108
+ */
1109
+ const create: <JSON_1 extends ASTNodeJSON>(targetType: {
1110
+ new (...args: any[]): ASTNode<JSON_1, any>;
1111
+ kind: string;
1112
+ }, json: JSON_1) => {
1113
+ kind: string;
1114
+ } & JSON_1;
1115
+ }
1116
+
1117
+ declare namespace ASTMatch {
1118
+ /**
1119
+ * 类型相关
1120
+ * @returns
1121
+ */
1122
+ const isString: (node?: ASTNode) => node is StringType;
1123
+ const isNumber: (node?: ASTNode) => node is NumberType;
1124
+ const isBoolean: (node?: ASTNode) => node is BooleanType;
1125
+ const isInteger: (node?: ASTNode) => node is IntegerType;
1126
+ const isObject: (node?: ASTNode) => node is ObjectType;
1127
+ const isArray: (node?: ASTNode) => node is ArrayType;
1128
+ const isMap: (node?: ASTNode) => node is MapType;
1129
+ const isCustomType: (node?: ASTNode) => node is CustomType;
1130
+ /**
1131
+ * 声明相关
1132
+ */
1133
+ const isVariableDeclaration: <VariableMeta = any>(node?: ASTNode) => node is VariableDeclaration<VariableMeta>;
1134
+ const isProperty: <VariableMeta = any>(node?: ASTNode) => node is Property<VariableMeta>;
1135
+ const isVariableDeclarationList: (node?: ASTNode) => node is VariableDeclarationList;
1136
+ /**
1137
+ * 表达式相关
1138
+ */
1139
+ const isEnumerateExpression: (node?: ASTNode) => node is EnumerateExpression;
1140
+ const isKeyPathExpression: (node?: ASTNode) => node is KeyPathExpression<KeyPathExpressionJSON$1>;
1141
+ /**
1142
+ * Check AST Match by ASTClass
1143
+ */
1144
+ function is<TargetASTNode extends ASTNode>(node?: ASTNode, targetType?: {
1145
+ kind: string;
1146
+ new (...args: any[]): TargetASTNode;
1147
+ }): node is TargetASTNode;
1148
+ }
1149
+
1150
+ /**
1151
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1152
+ * SPDX-License-Identifier: MIT
1153
+ */
1154
+
1155
+ declare const injectToAST: (serviceIdentifier: interfaces.ServiceIdentifier) => (target: any, propertyKey: string) => any;
1156
+ declare const postConstructAST: () => (target: any, propertyKey: string) => void;
1157
+
1158
+ /**
1159
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1160
+ * SPDX-License-Identifier: MIT
1161
+ */
1162
+
1163
+ /**
1164
+ * isMatchAST is same as ASTMatch.is
1165
+ * @param node
1166
+ * @param targetType
1167
+ * @returns
1168
+ */
1169
+ declare function isMatchAST<TargetASTNode extends ASTNode>(node?: ASTNode, targetType?: {
1170
+ kind: string;
1171
+ new (...args: any[]): TargetASTNode;
1172
+ }): node is TargetASTNode;
1173
+
1174
+ /**
1175
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1176
+ * SPDX-License-Identifier: MIT
1177
+ */
1178
+
1179
+ interface ScopeChangeAction {
1180
+ type: 'add' | 'delete' | 'update' | 'available';
1181
+ scope: Scope;
1182
+ }
1183
+ interface IVariableTable extends Disposable {
1184
+ parentTable?: IVariableTable;
1185
+ onDataChange: Event<void>;
1186
+ version: number;
1187
+ variables: VariableDeclaration[];
1188
+ variableKeys: string[];
1189
+ fireChange(): void;
1190
+ getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
1191
+ getVariableByKey(key: string): VariableDeclaration | undefined;
1192
+ dispose(): void;
1193
+ onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
1194
+ onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
1195
+ onListOrAnyVarChange(observer: () => void): Disposable;
1196
+ }
1197
+
1198
+ declare class VariableEngine implements Disposable {
1199
+ readonly chain: ScopeChain;
1200
+ readonly astRegisters: ASTRegisters;
1201
+ protected toDispose: DisposableCollection;
1202
+ protected memo: {
1203
+ <T>(key: string | symbol, fn: () => T): T;
1204
+ clear: (key?: (string | symbol) | undefined) => void;
1205
+ };
1206
+ protected scopeMap: Map<string | symbol, Scope<Record<string, any>>>;
1207
+ globalEvent$: Subject<GlobalEventActionType>;
1208
+ protected onScopeChangeEmitter: Emitter<ScopeChangeAction>;
1209
+ globalVariableTable: IVariableTable;
1210
+ onScopeChange: _flowgram_ai_utils.Event<ScopeChangeAction>;
1211
+ private readonly containerProvider;
1212
+ get container(): interfaces.Container;
1213
+ constructor(chain: ScopeChain, // 作用域依赖关系偏序集
1214
+ astRegisters: ASTRegisters);
1215
+ dispose(): void;
1216
+ getScopeById(scopeId: string | symbol): Scope | undefined;
1217
+ removeScopeById(scopeId: string | symbol): void;
1218
+ /**
1219
+ * Get Scope, if Scope exists and type is same, will use it directly
1220
+ * @param id scope id
1221
+ * @param meta scope meta, defined by user
1222
+ * @param ScopeConstructor scope constructor, default is Scope. you can extends Scope to create your own scope
1223
+ * @returns
1224
+ */
1225
+ createScope(id: string | symbol, meta?: Record<string, any>, options?: {
1226
+ ScopeConstructor?: IScopeConstructor;
1227
+ }): Scope;
1228
+ getAllScopes({ sort, }?: {
1229
+ sort?: boolean;
1230
+ }): Scope[];
1231
+ fireGlobalEvent(event: GlobalEventActionType): void;
1232
+ onGlobalEvent<ActionType extends GlobalEventActionType = GlobalEventActionType>(type: ActionType['type'], observer: (action: ActionType) => void): Disposable;
1233
+ }
1234
+
1235
+ interface ScopeContextProps {
1236
+ scope: Scope;
1237
+ }
1238
+ declare const ScopeProvider: react.Provider<ScopeContextProps>;
1239
+ declare const useScopeContext: () => ScopeContextProps | null;
1240
+ declare const useCurrentScope: () => Scope<Record<string, any>>;
1241
+
1242
+ /**
1243
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1244
+ * SPDX-License-Identifier: MIT
1245
+ */
1246
+
1247
+ /**
1248
+ * 获取作用域的可访问变量
1249
+ */
1250
+ declare function useScopeAvailable(): ScopeAvailableData;
1251
+
1252
+ /**
1253
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1254
+ * SPDX-License-Identifier: MIT
1255
+ */
1256
+
1257
+ /**
1258
+ * 获取作用域的可访问变量
1259
+ */
1260
+ declare function useAvailableVariables(): VariableDeclaration[];
1261
+
1262
+ interface RenameInfo {
1263
+ before: BaseVariableField;
1264
+ after: BaseVariableField;
1265
+ }
1266
+ declare class VariableFieldKeyRenameService {
1267
+ variableEngine: VariableEngine;
1268
+ toDispose: DisposableCollection;
1269
+ renameEmitter: Emitter<RenameInfo>;
1270
+ disposeInListEmitter: Emitter<BaseVariableField<any>>;
1271
+ onRename: _flowgram_ai_utils.Event<RenameInfo>;
1272
+ onDisposeInList: _flowgram_ai_utils.Event<BaseVariableField<any>>;
1273
+ handleFieldListChange(ast?: ASTNode, prev?: BaseVariableField[], next?: BaseVariableField[]): void;
1274
+ notifyFieldsDispose(prev?: BaseVariableField[], next?: BaseVariableField[]): void;
1275
+ init(): void;
1276
+ dispose(): void;
1277
+ }
1278
+
1279
+ export { ASTFactory, ASTKind, ASTMatch, ASTNode, ASTNodeFlags, type ASTNodeJSON, type ASTNodeRegistry, ASTRegisters, ArrayType, BaseExpression, BaseType, BaseVariableField, BooleanType, type CreateASTParams, CustomType, type CustomTypeJSON, DataNode, EnumerateExpression, type EnumerateExpressionJSON, type GetKindJSON, type GetKindJSONOrKind, type GlobalEventActionType, type IVariableTable, IntegerType, KeyPathExpression, type KeyPathExpressionJSON$1 as KeyPathExpressionJSON, KeyPathExpressionV2, ListNode, type ListNodeJSON, MapNode, type MapNodeJSON, MapType, NumberType, type ObjectJSON, type ObjectPropertiesChangeAction, ObjectType, Property, type PropertyJSON, Scope, ScopeChain, ScopeOutputData, ScopeProvider, StringType, type UnionJSON, VariableContainerModule, VariableDeclaration, type VariableDeclarationJSON, VariableDeclarationList, type VariableDeclarationListChangeAction, type VariableDeclarationListJSON, VariableEngine, VariableEngineProvider, VariableFieldKeyRenameService, WrapArrayExpression, type WrapArrayExpressionJSON, injectToAST, isMatchAST, postConstructAST, useAvailableVariables, useCurrentScope, useScopeAvailable, useScopeContext };