@flowgram.ai/variable-core 0.2.15 → 0.2.17

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/index.d.mts CHANGED
@@ -5,8 +5,18 @@ import { Subject, Observable, BehaviorSubject, Observer as Observer$1 } from 'rx
5
5
  export { Observer } from 'rxjs';
6
6
  import * as react from 'react';
7
7
 
8
+ /**
9
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
10
+ * SPDX-License-Identifier: MIT
11
+ */
12
+
8
13
  declare const VariableContainerModule: ContainerModule;
9
14
 
15
+ /**
16
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
17
+ * SPDX-License-Identifier: MIT
18
+ */
19
+
10
20
  declare const VariableEngineProvider: unique symbol;
11
21
  type VariableEngineProvider = () => VariableEngine;
12
22
 
@@ -22,8 +32,22 @@ declare class ScopeOutputData {
22
32
  };
23
33
  get variableEngine(): VariableEngine;
24
34
  get globalVariableTable(): IVariableTable;
35
+ /**
36
+ * @deprecated use onListOrAnyVarChange instead
37
+ */
25
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
+ */
26
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;
27
51
  protected _hasChanges: boolean;
28
52
  constructor(scope: Scope);
29
53
  /**
@@ -62,22 +86,30 @@ declare class ScopeAvailableData {
62
86
  protected variables$: Observable<VariableDeclaration[]>;
63
87
  protected anyVariableChange$: Observable<VariableDeclaration>;
64
88
  /**
65
- * 监听任意变量变化
66
- * @param observer 监听器,变量变化时会吐出值
89
+ * listen to any variable update in list
90
+ * @param observer
67
91
  * @returns
68
92
  */
69
93
  onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
70
94
  /**
71
- * 监听变量列表变化
95
+ * listen to variable list change
72
96
  * @param observer
73
97
  * @returns
74
98
  */
75
99
  onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
100
+ /**
101
+ * @deprecated
102
+ */
76
103
  protected onDataChangeEmitter: Emitter<VariableDeclaration<any>[]>;
104
+ protected onListOrAnyVarChangeEmitter: Emitter<VariableDeclaration<any>[]>;
77
105
  /**
78
- * 监听变量列表变化 + 任意子变量变化
106
+ * @deprecated use available.onListOrAnyVarChange instead
79
107
  */
80
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>[]>;
81
113
  constructor(scope: Scope);
82
114
  /**
83
115
  * 获取可消费变量
@@ -96,9 +128,21 @@ declare class ScopeAvailableData {
96
128
  * @param keyPath
97
129
  * @returns
98
130
  */
99
- getByKeyPath(keyPath?: string[]): VariableDeclaration | Property | undefined;
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;
100
139
  }
101
140
 
141
+ /**
142
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
143
+ * SPDX-License-Identifier: MIT
144
+ */
145
+
102
146
  type Observer<ActionType extends GlobalEventActionType = GlobalEventActionType> = (action: ActionType) => void;
103
147
  declare class ScopeEventData {
104
148
  readonly scope: Scope;
@@ -166,6 +210,27 @@ declare class Scope<ScopeMeta extends Record<string, any> = Record<string, any>>
166
210
  dispose(): void;
167
211
  onDispose: _flowgram_ai_utils.Event<void>;
168
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
+ * Retrieves a variable from the Scope by key.
222
+ *
223
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
224
+ * @returns The value of the variable, or undefined if not found.
225
+ */
226
+ getVar(key?: string): ASTNode<any, any> | undefined;
227
+ /**
228
+ * Clears a variable from the Scope by key.
229
+ *
230
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
231
+ * @returns The updated AST node.
232
+ */
233
+ clearVar(key?: string): void;
169
234
  }
170
235
 
171
236
  /**
@@ -225,7 +290,7 @@ declare abstract class ASTNode<JSON extends ASTNodeJSON = any, InjectOpts = any>
225
290
  /**
226
291
  * 节点的版本号,每 fireChange 一次 version + 1
227
292
  */
228
- private _version;
293
+ protected _version: number;
229
294
  /**
230
295
  * 更新锁
231
296
  */
@@ -324,6 +389,11 @@ declare abstract class ASTNode<JSON extends ASTNodeJSON = any, InjectOpts = any>
324
389
  [key: string]: unknown;
325
390
  }
326
391
 
392
+ /**
393
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
394
+ * SPDX-License-Identifier: MIT
395
+ */
396
+
327
397
  type ASTKindType = string;
328
398
  type Identifier = string;
329
399
  interface ASTNodeJSON {
@@ -394,6 +464,11 @@ interface GlobalEventActionType<Type = string, Payload = any, AST extends ASTNod
394
464
  ast?: AST;
395
465
  }
396
466
 
467
+ /**
468
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
469
+ * SPDX-License-Identifier: MIT
470
+ */
471
+
397
472
  type DataInjector = () => Record<string, any>;
398
473
  declare class ASTRegisters {
399
474
  protected injectors: Map<ASTKindType, DataInjector>;
@@ -422,6 +497,10 @@ declare class ASTRegisters {
422
497
  registerAST(ASTNode: ASTNodeRegistry, injector?: DataInjector): void;
423
498
  }
424
499
 
500
+ /**
501
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
502
+ * SPDX-License-Identifier: MIT
503
+ */
425
504
  declare enum ASTNodeFlags {
426
505
  None = 0,
427
506
  /**
@@ -442,6 +521,11 @@ declare enum ASTNodeFlags {
442
521
  VariableType = 120
443
522
  }
444
523
 
524
+ /**
525
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
526
+ * SPDX-License-Identifier: MIT
527
+ */
528
+
445
529
  /**
446
530
  * 通用数据 AST 节点,无子节点
447
531
  */
@@ -456,6 +540,11 @@ declare class DataNode<Data = any> extends ASTNode {
456
540
  partialUpdate(nextData: Data): void;
457
541
  }
458
542
 
543
+ /**
544
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
545
+ * SPDX-License-Identifier: MIT
546
+ */
547
+
459
548
  interface ListNodeJSON {
460
549
  list: ASTNodeJSON[];
461
550
  }
@@ -467,6 +556,11 @@ declare class ListNode extends ASTNode<ListNodeJSON> {
467
556
  toJSON(): ASTNodeJSON;
468
557
  }
469
558
 
559
+ /**
560
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
561
+ * SPDX-License-Identifier: MIT
562
+ */
563
+
470
564
  interface MapNodeJSON {
471
565
  map: [string, ASTNodeJSON][];
472
566
  }
@@ -494,6 +588,11 @@ declare class MapNode extends ASTNode<MapNodeJSON> {
494
588
  get(key: string): ASTNode | undefined;
495
589
  }
496
590
 
591
+ /**
592
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
593
+ * SPDX-License-Identifier: MIT
594
+ */
595
+
497
596
  declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
498
597
  flags: number;
499
598
  /**
@@ -513,28 +612,53 @@ declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any
513
612
  toJSON(): ASTNodeJSON;
514
613
  }
515
614
 
615
+ /**
616
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
617
+ * SPDX-License-Identifier: MIT
618
+ */
619
+
516
620
  declare class StringType extends BaseType {
517
621
  flags: ASTNodeFlags;
518
622
  static kind: string;
519
623
  fromJSON(): void;
520
624
  }
521
625
 
626
+ /**
627
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
628
+ * SPDX-License-Identifier: MIT
629
+ */
630
+
522
631
  declare class IntegerType extends BaseType {
523
632
  flags: ASTNodeFlags;
524
633
  static kind: string;
525
634
  fromJSON(): void;
526
635
  }
527
636
 
637
+ /**
638
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
639
+ * SPDX-License-Identifier: MIT
640
+ */
641
+
528
642
  declare class BooleanType extends BaseType {
529
643
  static kind: string;
530
644
  fromJSON(): void;
531
645
  }
532
646
 
647
+ /**
648
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
649
+ * SPDX-License-Identifier: MIT
650
+ */
651
+
533
652
  declare class NumberType extends BaseType {
534
653
  static kind: string;
535
654
  fromJSON(): void;
536
655
  }
537
656
 
657
+ /**
658
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
659
+ * SPDX-License-Identifier: MIT
660
+ */
661
+
538
662
  interface ArrayJSON {
539
663
  items?: ASTNodeJSONOrKind;
540
664
  }
@@ -555,6 +679,11 @@ declare class ArrayType extends BaseType<ArrayJSON> {
555
679
  toJSON(): ASTNodeJSON;
556
680
  }
557
681
 
682
+ /**
683
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
684
+ * SPDX-License-Identifier: MIT
685
+ */
686
+
558
687
  interface MapJSON {
559
688
  keyType?: ASTNodeJSONOrKind;
560
689
  valueType?: ASTNodeJSONOrKind;
@@ -574,6 +703,11 @@ declare class MapType extends BaseType<MapJSON> {
574
703
  toJSON(): ASTNodeJSON;
575
704
  }
576
705
 
706
+ /**
707
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
708
+ * SPDX-License-Identifier: MIT
709
+ */
710
+
577
711
  type PropertyJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
578
712
  key: string;
579
713
  };
@@ -581,6 +715,11 @@ declare class Property<VariableMeta = any> extends BaseVariableField<VariableMet
581
715
  static kind: string;
582
716
  }
583
717
 
718
+ /**
719
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
720
+ * SPDX-License-Identifier: MIT
721
+ */
722
+
584
723
  interface ObjectJSON<VariableMeta = any> {
585
724
  /**
586
725
  * Object 的 properties 一定是 Property 类型,因此业务可以不用填 kind
@@ -613,10 +752,20 @@ declare class ObjectType extends BaseType<ObjectJSON> {
613
752
  protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
614
753
  }
615
754
 
755
+ /**
756
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
757
+ * SPDX-License-Identifier: MIT
758
+ */
759
+
616
760
  interface UnionJSON {
617
761
  types?: ASTNodeJSONOrKind[];
618
762
  }
619
763
 
764
+ /**
765
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
766
+ * SPDX-License-Identifier: MIT
767
+ */
768
+
620
769
  interface CustomTypeJSON {
621
770
  typeName: string;
622
771
  }
@@ -628,6 +777,11 @@ declare class CustomType extends BaseType<CustomTypeJSON> {
628
777
  isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
629
778
  }
630
779
 
780
+ /**
781
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
782
+ * SPDX-License-Identifier: MIT
783
+ */
784
+
631
785
  type ExpressionRefs = (BaseVariableField | undefined)[];
632
786
  declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
633
787
  flags: ASTNodeFlags;
@@ -666,6 +820,11 @@ declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts
666
820
  constructor(params: CreateASTParams, opts?: InjectOpts);
667
821
  }
668
822
 
823
+ /**
824
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
825
+ * SPDX-License-Identifier: MIT
826
+ */
827
+
669
828
  interface KeyPathExpressionJSON$1 {
670
829
  keyPath: string[];
671
830
  }
@@ -687,6 +846,11 @@ declare class KeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpr
687
846
  toJSON(): ASTNodeJSON;
688
847
  }
689
848
 
849
+ /**
850
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
851
+ * SPDX-License-Identifier: MIT
852
+ */
853
+
690
854
  interface EnumerateExpressionJSON {
691
855
  enumerateFor: ASTNodeJSON;
692
856
  }
@@ -703,6 +867,11 @@ declare class EnumerateExpression extends BaseExpression<EnumerateExpressionJSON
703
867
  toJSON(): ASTNodeJSON;
704
868
  }
705
869
 
870
+ /**
871
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
872
+ * SPDX-License-Identifier: MIT
873
+ */
874
+
706
875
  interface KeyPathExpressionJSON {
707
876
  keyPath: string[];
708
877
  }
@@ -732,6 +901,11 @@ declare class KeyPathExpressionV2<CustomPathJSON extends ASTNodeJSON = KeyPathEx
732
901
  toJSON(): ASTNodeJSON;
733
902
  }
734
903
 
904
+ /**
905
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
906
+ * SPDX-License-Identifier: MIT
907
+ */
908
+
735
909
  interface WrapArrayExpressionJSON {
736
910
  wrapFor: ASTNodeJSON;
737
911
  }
@@ -769,9 +943,11 @@ declare abstract class BaseVariableField<VariableMeta = any> extends ASTNode<Bas
769
943
  * 父变量字段,通过由近而远的方式进行排序
770
944
  */
771
945
  get parentFields(): BaseVariableField[];
946
+ get keyPath(): string[];
772
947
  get meta(): VariableMeta;
773
948
  get type(): BaseType;
774
949
  get initializer(): BaseExpression | undefined;
950
+ get hash(): string;
775
951
  /**
776
952
  * 解析 VariableDeclarationJSON 从而生成变量声明节点
777
953
  */
@@ -819,6 +995,11 @@ declare class VariableDeclaration<VariableMeta = any> extends BaseVariableField<
819
995
  onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
820
996
  }
821
997
 
998
+ /**
999
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1000
+ * SPDX-License-Identifier: MIT
1001
+ */
1002
+
822
1003
  interface VariableDeclarationListJSON<VariableMeta = any> {
823
1004
  /**
824
1005
  * declarations 一定是 VariableDeclaration 类型,因此业务可以不用填 kind
@@ -958,9 +1139,19 @@ declare namespace ASTMatch {
958
1139
  }): node is TargetASTNode;
959
1140
  }
960
1141
 
1142
+ /**
1143
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1144
+ * SPDX-License-Identifier: MIT
1145
+ */
1146
+
961
1147
  declare const injectToAST: (serviceIdentifier: interfaces.ServiceIdentifier) => (target: any, propertyKey: string) => any;
962
1148
  declare const postConstructAST: () => (target: any, propertyKey: string) => void;
963
1149
 
1150
+ /**
1151
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1152
+ * SPDX-License-Identifier: MIT
1153
+ */
1154
+
964
1155
  /**
965
1156
  * isMatchAST is same as ASTMatch.is
966
1157
  * @param node
@@ -972,6 +1163,11 @@ declare function isMatchAST<TargetASTNode extends ASTNode>(node?: ASTNode, targe
972
1163
  new (...args: any[]): TargetASTNode;
973
1164
  }): node is TargetASTNode;
974
1165
 
1166
+ /**
1167
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1168
+ * SPDX-License-Identifier: MIT
1169
+ */
1170
+
975
1171
  interface ScopeChangeAction {
976
1172
  type: 'add' | 'delete' | 'update' | 'available';
977
1173
  scope: Scope;
@@ -986,8 +1182,9 @@ interface IVariableTable extends Disposable {
986
1182
  getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
987
1183
  getVariableByKey(key: string): VariableDeclaration | undefined;
988
1184
  dispose(): void;
1185
+ onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
989
1186
  onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
990
- onAnyChange(observer: () => void): Disposable;
1187
+ onListOrAnyVarChange(observer: () => void): Disposable;
991
1188
  }
992
1189
 
993
1190
  declare class VariableEngine implements Disposable {
@@ -1034,11 +1231,21 @@ declare const ScopeProvider: react.Provider<ScopeContextProps>;
1034
1231
  declare const useScopeContext: () => ScopeContextProps | null;
1035
1232
  declare const useCurrentScope: () => Scope<Record<string, any>>;
1036
1233
 
1234
+ /**
1235
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1236
+ * SPDX-License-Identifier: MIT
1237
+ */
1238
+
1037
1239
  /**
1038
1240
  * 获取作用域的可访问变量
1039
1241
  */
1040
1242
  declare function useScopeAvailable(): ScopeAvailableData;
1041
1243
 
1244
+ /**
1245
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1246
+ * SPDX-License-Identifier: MIT
1247
+ */
1248
+
1042
1249
  /**
1043
1250
  * 获取作用域的可访问变量
1044
1251
  */