@superatomai/sdk-node 0.0.52 → 0.0.53-mds
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 +875 -71
- package/dist/index.d.ts +875 -71
- package/dist/index.js +14499 -8324
- package/dist/index.mjs +14470 -8305
- package/package.json +3 -2
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,12 @@ interface DBUIBlock {
|
|
|
10
10
|
component: Record<string, any> | null;
|
|
11
11
|
analysis: string | null;
|
|
12
12
|
user_prompt: string;
|
|
13
|
+
/**
|
|
14
|
+
* One line naming what the component actually showed. componentData is not
|
|
15
|
+
* persisted, so without this a rehydrated turn tells a later question only that
|
|
16
|
+
* some component existed — and a follow-up about it has nothing to refer to.
|
|
17
|
+
*/
|
|
18
|
+
data_summary?: string | null;
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
/**
|
|
@@ -59,7 +65,18 @@ declare class Logger {
|
|
|
59
65
|
* Log debug message (only shown for verbose level)
|
|
60
66
|
*/
|
|
61
67
|
debug(...args: any[]): void;
|
|
68
|
+
/**
|
|
69
|
+
* Write to log file
|
|
70
|
+
*/
|
|
62
71
|
file(...args: any[]): void;
|
|
72
|
+
/**
|
|
73
|
+
* Clear the log file (call at start of new user request)
|
|
74
|
+
*/
|
|
75
|
+
clearFile(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Log LLM method prompts with clear labeling
|
|
78
|
+
*/
|
|
79
|
+
logLLMPrompt(methodName: string, promptType: 'system' | 'user', content: string | object | any[]): void;
|
|
63
80
|
}
|
|
64
81
|
declare const logger: Logger;
|
|
65
82
|
|
|
@@ -623,19 +640,19 @@ declare const ComponentSchema: z.ZodObject<{
|
|
|
623
640
|
type: z.ZodString;
|
|
624
641
|
description: z.ZodString;
|
|
625
642
|
props: z.ZodObject<{
|
|
626
|
-
query: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]
|
|
643
|
+
query: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>>;
|
|
627
644
|
title: z.ZodOptional<z.ZodString>;
|
|
628
645
|
description: z.ZodOptional<z.ZodString>;
|
|
629
646
|
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
630
647
|
actions: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
631
648
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
632
|
-
query: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]
|
|
649
|
+
query: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>>;
|
|
633
650
|
title: z.ZodOptional<z.ZodString>;
|
|
634
651
|
description: z.ZodOptional<z.ZodString>;
|
|
635
652
|
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
636
653
|
actions: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
637
654
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
638
|
-
query: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]
|
|
655
|
+
query: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>>;
|
|
639
656
|
title: z.ZodOptional<z.ZodString>;
|
|
640
657
|
description: z.ZodOptional<z.ZodString>;
|
|
641
658
|
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
@@ -650,7 +667,7 @@ declare const ComponentSchema: z.ZodObject<{
|
|
|
650
667
|
description: string;
|
|
651
668
|
props: {
|
|
652
669
|
description?: string | undefined;
|
|
653
|
-
query?: string | {} | undefined;
|
|
670
|
+
query?: string | {} | null | undefined;
|
|
654
671
|
title?: string | undefined;
|
|
655
672
|
config?: Record<string, unknown> | undefined;
|
|
656
673
|
actions?: any[] | undefined;
|
|
@@ -668,7 +685,7 @@ declare const ComponentSchema: z.ZodObject<{
|
|
|
668
685
|
description: string;
|
|
669
686
|
props: {
|
|
670
687
|
description?: string | undefined;
|
|
671
|
-
query?: string | {} | undefined;
|
|
688
|
+
query?: string | {} | null | undefined;
|
|
672
689
|
title?: string | undefined;
|
|
673
690
|
config?: Record<string, unknown> | undefined;
|
|
674
691
|
actions?: any[] | undefined;
|
|
@@ -730,6 +747,10 @@ declare const ToolSchema: z.ZodObject<{
|
|
|
730
747
|
id: z.ZodString;
|
|
731
748
|
name: z.ZodString;
|
|
732
749
|
description: z.ZodString;
|
|
750
|
+
/** Tool type: "source" = routed through SourceAgent, "direct" = called directly by MainAgent */
|
|
751
|
+
toolType: z.ZodOptional<z.ZodEnum<["source", "direct"]>>;
|
|
752
|
+
/** Full untruncated schema for source agent (all columns visible) */
|
|
753
|
+
fullSchema: z.ZodOptional<z.ZodString>;
|
|
733
754
|
params: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
734
755
|
fn: z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodAny>;
|
|
735
756
|
outputSchema: z.ZodOptional<z.ZodObject<{
|
|
@@ -762,12 +783,22 @@ declare const ToolSchema: z.ZodObject<{
|
|
|
762
783
|
description: string;
|
|
763
784
|
}[];
|
|
764
785
|
}>>;
|
|
786
|
+
/** Cache policy. `false` = never cache (live data, write ops). Mirrors HTTP `Cache-Control: no-store`. */
|
|
787
|
+
cache: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodObject<{
|
|
788
|
+
ttlMs: z.ZodOptional<z.ZodNumber>;
|
|
789
|
+
}, "strip", z.ZodTypeAny, {
|
|
790
|
+
ttlMs?: number | undefined;
|
|
791
|
+
}, {
|
|
792
|
+
ttlMs?: number | undefined;
|
|
793
|
+
}>]>>;
|
|
765
794
|
}, "strip", z.ZodTypeAny, {
|
|
766
795
|
id: string;
|
|
767
796
|
params: Record<string, string>;
|
|
768
797
|
name: string;
|
|
769
798
|
description: string;
|
|
770
799
|
fn: (args_0: any, ...args: unknown[]) => any;
|
|
800
|
+
toolType?: "source" | "direct" | undefined;
|
|
801
|
+
fullSchema?: string | undefined;
|
|
771
802
|
outputSchema?: {
|
|
772
803
|
description: string;
|
|
773
804
|
fields: {
|
|
@@ -776,12 +807,17 @@ declare const ToolSchema: z.ZodObject<{
|
|
|
776
807
|
description: string;
|
|
777
808
|
}[];
|
|
778
809
|
} | undefined;
|
|
810
|
+
cache?: false | {
|
|
811
|
+
ttlMs?: number | undefined;
|
|
812
|
+
} | undefined;
|
|
779
813
|
}, {
|
|
780
814
|
id: string;
|
|
781
815
|
params: Record<string, string>;
|
|
782
816
|
name: string;
|
|
783
817
|
description: string;
|
|
784
818
|
fn: (args_0: any, ...args: unknown[]) => any;
|
|
819
|
+
toolType?: "source" | "direct" | undefined;
|
|
820
|
+
fullSchema?: string | undefined;
|
|
785
821
|
outputSchema?: {
|
|
786
822
|
description: string;
|
|
787
823
|
fields: {
|
|
@@ -790,6 +826,9 @@ declare const ToolSchema: z.ZodObject<{
|
|
|
790
826
|
description: string;
|
|
791
827
|
}[];
|
|
792
828
|
} | undefined;
|
|
829
|
+
cache?: false | {
|
|
830
|
+
ttlMs?: number | undefined;
|
|
831
|
+
} | undefined;
|
|
793
832
|
}>;
|
|
794
833
|
type Tool$1 = z.infer<typeof ToolSchema>;
|
|
795
834
|
type CollectionOperation = 'getMany' | 'getOne' | 'query' | 'mutation' | 'updateOne' | 'deleteOne' | 'createOne';
|
|
@@ -841,27 +880,68 @@ interface SuperatomSDKConfig {
|
|
|
841
880
|
* - 'balanced': Use best model for complex tasks, fast model for simple tasks (default)
|
|
842
881
|
*/
|
|
843
882
|
modelStrategy?: ModelStrategy;
|
|
883
|
+
/**
|
|
884
|
+
* Model for the main agent (routing + analysis).
|
|
885
|
+
* Format: "provider/model-name" (e.g., "anthropic/claude-haiku-4-5-20251001")
|
|
886
|
+
* If not set, uses the provider's default model.
|
|
887
|
+
*/
|
|
888
|
+
mainAgentModel?: string;
|
|
889
|
+
/**
|
|
890
|
+
* Model for source agents (per-source query generation).
|
|
891
|
+
* Format: "provider/model-name" (e.g., "anthropic/claude-haiku-4-5-20251001")
|
|
892
|
+
* If not set, uses the provider's default model.
|
|
893
|
+
*/
|
|
894
|
+
sourceAgentModel?: string;
|
|
844
895
|
/**
|
|
845
896
|
* Separate model configuration for DASH_COMP flow (dashboard component picking)
|
|
846
897
|
* If not provided, falls back to provider-based model selection
|
|
847
898
|
*/
|
|
848
899
|
dashCompModels?: DashCompModelConfig;
|
|
900
|
+
/**
|
|
901
|
+
* Similarity threshold for conversation search (semantic matching)
|
|
902
|
+
* Value between 0 and 1 (e.g., 0.8 = 80% similarity required)
|
|
903
|
+
* Higher values require closer matches, lower values allow more distant matches
|
|
904
|
+
* Default: 0.8
|
|
905
|
+
*/
|
|
906
|
+
conversationSimilarityThreshold?: number;
|
|
907
|
+
/**
|
|
908
|
+
* Query cache TTL (Time To Live) in minutes
|
|
909
|
+
* Cached query results expire after this duration
|
|
910
|
+
* Default: 5 minutes
|
|
911
|
+
*/
|
|
912
|
+
queryCacheTTL?: number;
|
|
913
|
+
/**
|
|
914
|
+
* Byte budget for cached query results, in MB.
|
|
915
|
+
* The cache evicts least-recently-used entries to stay under it, so a long TTL
|
|
916
|
+
* cannot grow the process until the host kills it. Keep it well below the
|
|
917
|
+
* process memory limit. Default: 1024 MB
|
|
918
|
+
*/
|
|
919
|
+
queryCacheMaxMB?: number;
|
|
920
|
+
/**
|
|
921
|
+
* Dashboard conversation history TTL (Time To Live) in minutes
|
|
922
|
+
* Per-dashboard conversation histories expire after this duration
|
|
923
|
+
* Default: 30 minutes
|
|
924
|
+
*/
|
|
925
|
+
dashboardHistoryTTL?: number;
|
|
849
926
|
}
|
|
850
927
|
|
|
851
928
|
declare const KbNodesQueryFiltersSchema: z.ZodObject<{
|
|
852
929
|
query: z.ZodOptional<z.ZodString>;
|
|
853
930
|
category: z.ZodOptional<z.ZodString>;
|
|
854
931
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
855
|
-
|
|
932
|
+
type: z.ZodOptional<z.ZodEnum<["global", "user", "query"]>>;
|
|
933
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
856
934
|
}, "strip", z.ZodTypeAny, {
|
|
935
|
+
type?: "query" | "user" | "global" | undefined;
|
|
857
936
|
query?: string | undefined;
|
|
858
937
|
category?: string | undefined;
|
|
859
|
-
createdBy?:
|
|
938
|
+
createdBy?: string | undefined;
|
|
860
939
|
tags?: string[] | undefined;
|
|
861
940
|
}, {
|
|
941
|
+
type?: "query" | "user" | "global" | undefined;
|
|
862
942
|
query?: string | undefined;
|
|
863
943
|
category?: string | undefined;
|
|
864
|
-
createdBy?:
|
|
944
|
+
createdBy?: string | undefined;
|
|
865
945
|
tags?: string[] | undefined;
|
|
866
946
|
}>;
|
|
867
947
|
type KbNodesQueryFilters = z.infer<typeof KbNodesQueryFiltersSchema>;
|
|
@@ -873,106 +953,118 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
|
|
|
873
953
|
content: z.ZodOptional<z.ZodString>;
|
|
874
954
|
category: z.ZodOptional<z.ZodString>;
|
|
875
955
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
956
|
+
type: z.ZodOptional<z.ZodEnum<["global", "user", "query"]>>;
|
|
957
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
958
|
+
updatedBy: z.ZodOptional<z.ZodString>;
|
|
959
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
879
960
|
query: z.ZodOptional<z.ZodString>;
|
|
880
961
|
filters: z.ZodOptional<z.ZodObject<{
|
|
881
962
|
query: z.ZodOptional<z.ZodString>;
|
|
882
963
|
category: z.ZodOptional<z.ZodString>;
|
|
883
964
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
884
|
-
|
|
965
|
+
type: z.ZodOptional<z.ZodEnum<["global", "user", "query"]>>;
|
|
966
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
885
967
|
}, "strip", z.ZodTypeAny, {
|
|
968
|
+
type?: "query" | "user" | "global" | undefined;
|
|
886
969
|
query?: string | undefined;
|
|
887
970
|
category?: string | undefined;
|
|
888
|
-
createdBy?:
|
|
971
|
+
createdBy?: string | undefined;
|
|
889
972
|
tags?: string[] | undefined;
|
|
890
973
|
}, {
|
|
974
|
+
type?: "query" | "user" | "global" | undefined;
|
|
891
975
|
query?: string | undefined;
|
|
892
976
|
category?: string | undefined;
|
|
893
|
-
createdBy?:
|
|
977
|
+
createdBy?: string | undefined;
|
|
894
978
|
tags?: string[] | undefined;
|
|
895
979
|
}>>;
|
|
896
980
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
897
981
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
898
982
|
}, "strip", z.ZodTypeAny, {
|
|
899
983
|
id?: number | undefined;
|
|
984
|
+
type?: "query" | "user" | "global" | undefined;
|
|
900
985
|
query?: string | undefined;
|
|
901
986
|
title?: string | undefined;
|
|
902
987
|
category?: string | undefined;
|
|
903
|
-
userId?:
|
|
988
|
+
userId?: string | undefined;
|
|
904
989
|
limit?: number | undefined;
|
|
905
990
|
filters?: {
|
|
991
|
+
type?: "query" | "user" | "global" | undefined;
|
|
906
992
|
query?: string | undefined;
|
|
907
993
|
category?: string | undefined;
|
|
908
|
-
createdBy?:
|
|
994
|
+
createdBy?: string | undefined;
|
|
909
995
|
tags?: string[] | undefined;
|
|
910
996
|
} | undefined;
|
|
911
|
-
createdBy?:
|
|
912
|
-
updatedBy?:
|
|
997
|
+
createdBy?: string | undefined;
|
|
998
|
+
updatedBy?: string | undefined;
|
|
999
|
+
offset?: number | undefined;
|
|
913
1000
|
tags?: string[] | undefined;
|
|
914
1001
|
content?: string | undefined;
|
|
915
|
-
offset?: number | undefined;
|
|
916
1002
|
}, {
|
|
917
1003
|
id?: number | undefined;
|
|
1004
|
+
type?: "query" | "user" | "global" | undefined;
|
|
918
1005
|
query?: string | undefined;
|
|
919
1006
|
title?: string | undefined;
|
|
920
1007
|
category?: string | undefined;
|
|
921
|
-
userId?:
|
|
1008
|
+
userId?: string | undefined;
|
|
922
1009
|
limit?: number | undefined;
|
|
923
1010
|
filters?: {
|
|
1011
|
+
type?: "query" | "user" | "global" | undefined;
|
|
924
1012
|
query?: string | undefined;
|
|
925
1013
|
category?: string | undefined;
|
|
926
|
-
createdBy?:
|
|
1014
|
+
createdBy?: string | undefined;
|
|
927
1015
|
tags?: string[] | undefined;
|
|
928
1016
|
} | undefined;
|
|
929
|
-
createdBy?:
|
|
930
|
-
updatedBy?:
|
|
1017
|
+
createdBy?: string | undefined;
|
|
1018
|
+
updatedBy?: string | undefined;
|
|
1019
|
+
offset?: number | undefined;
|
|
931
1020
|
tags?: string[] | undefined;
|
|
932
1021
|
content?: string | undefined;
|
|
933
|
-
offset?: number | undefined;
|
|
934
1022
|
}>>;
|
|
935
1023
|
}, "strip", z.ZodTypeAny, {
|
|
936
1024
|
operation: "create" | "getOne" | "update" | "delete" | "getAll" | "search" | "getByCategory" | "getByUser" | "getCategories" | "getTags";
|
|
937
1025
|
data?: {
|
|
938
1026
|
id?: number | undefined;
|
|
1027
|
+
type?: "query" | "user" | "global" | undefined;
|
|
939
1028
|
query?: string | undefined;
|
|
940
1029
|
title?: string | undefined;
|
|
941
1030
|
category?: string | undefined;
|
|
942
|
-
userId?:
|
|
1031
|
+
userId?: string | undefined;
|
|
943
1032
|
limit?: number | undefined;
|
|
944
1033
|
filters?: {
|
|
1034
|
+
type?: "query" | "user" | "global" | undefined;
|
|
945
1035
|
query?: string | undefined;
|
|
946
1036
|
category?: string | undefined;
|
|
947
|
-
createdBy?:
|
|
1037
|
+
createdBy?: string | undefined;
|
|
948
1038
|
tags?: string[] | undefined;
|
|
949
1039
|
} | undefined;
|
|
950
|
-
createdBy?:
|
|
951
|
-
updatedBy?:
|
|
1040
|
+
createdBy?: string | undefined;
|
|
1041
|
+
updatedBy?: string | undefined;
|
|
1042
|
+
offset?: number | undefined;
|
|
952
1043
|
tags?: string[] | undefined;
|
|
953
1044
|
content?: string | undefined;
|
|
954
|
-
offset?: number | undefined;
|
|
955
1045
|
} | undefined;
|
|
956
1046
|
}, {
|
|
957
1047
|
operation: "create" | "getOne" | "update" | "delete" | "getAll" | "search" | "getByCategory" | "getByUser" | "getCategories" | "getTags";
|
|
958
1048
|
data?: {
|
|
959
1049
|
id?: number | undefined;
|
|
1050
|
+
type?: "query" | "user" | "global" | undefined;
|
|
960
1051
|
query?: string | undefined;
|
|
961
1052
|
title?: string | undefined;
|
|
962
1053
|
category?: string | undefined;
|
|
963
|
-
userId?:
|
|
1054
|
+
userId?: string | undefined;
|
|
964
1055
|
limit?: number | undefined;
|
|
965
1056
|
filters?: {
|
|
1057
|
+
type?: "query" | "user" | "global" | undefined;
|
|
966
1058
|
query?: string | undefined;
|
|
967
1059
|
category?: string | undefined;
|
|
968
|
-
createdBy?:
|
|
1060
|
+
createdBy?: string | undefined;
|
|
969
1061
|
tags?: string[] | undefined;
|
|
970
1062
|
} | undefined;
|
|
971
|
-
createdBy?:
|
|
972
|
-
updatedBy?:
|
|
1063
|
+
createdBy?: string | undefined;
|
|
1064
|
+
updatedBy?: string | undefined;
|
|
1065
|
+
offset?: number | undefined;
|
|
973
1066
|
tags?: string[] | undefined;
|
|
974
1067
|
content?: string | undefined;
|
|
975
|
-
offset?: number | undefined;
|
|
976
1068
|
} | undefined;
|
|
977
1069
|
}>;
|
|
978
1070
|
type KbNodesRequestPayload = z.infer<typeof KbNodesRequestPayloadSchema>;
|
|
@@ -1241,6 +1333,360 @@ declare class ReportManager {
|
|
|
1241
1333
|
getReportCount(): number;
|
|
1242
1334
|
}
|
|
1243
1335
|
|
|
1336
|
+
/**
|
|
1337
|
+
* StreamBuffer - Buffered streaming utility for smoother text delivery
|
|
1338
|
+
* Batches small chunks together and flushes at regular intervals
|
|
1339
|
+
*/
|
|
1340
|
+
type StreamCallback = (chunk: string) => void;
|
|
1341
|
+
/**
|
|
1342
|
+
* StreamBuffer class for managing buffered streaming output
|
|
1343
|
+
* Provides smooth text delivery by batching small chunks
|
|
1344
|
+
*/
|
|
1345
|
+
declare class StreamBuffer {
|
|
1346
|
+
private buffer;
|
|
1347
|
+
private flushTimer;
|
|
1348
|
+
private callback;
|
|
1349
|
+
private fullText;
|
|
1350
|
+
constructor(callback?: StreamCallback);
|
|
1351
|
+
/**
|
|
1352
|
+
* Check if the buffer has a callback configured
|
|
1353
|
+
*/
|
|
1354
|
+
hasCallback(): boolean;
|
|
1355
|
+
/**
|
|
1356
|
+
* Get all text that has been written (including already flushed)
|
|
1357
|
+
*/
|
|
1358
|
+
getFullText(): string;
|
|
1359
|
+
/**
|
|
1360
|
+
* Write a chunk to the buffer
|
|
1361
|
+
* Large chunks or chunks with newlines are flushed immediately
|
|
1362
|
+
* Small chunks are batched and flushed after a short interval
|
|
1363
|
+
*
|
|
1364
|
+
* @param chunk - Text chunk to write
|
|
1365
|
+
*/
|
|
1366
|
+
write(chunk: string): void;
|
|
1367
|
+
/**
|
|
1368
|
+
* Flush the buffer immediately
|
|
1369
|
+
* Call this before tool execution or other operations that need clean output
|
|
1370
|
+
*/
|
|
1371
|
+
flush(): void;
|
|
1372
|
+
/**
|
|
1373
|
+
* Internal flush implementation
|
|
1374
|
+
*/
|
|
1375
|
+
private flushNow;
|
|
1376
|
+
/**
|
|
1377
|
+
* Clean up resources
|
|
1378
|
+
* Call this when done with the buffer
|
|
1379
|
+
*/
|
|
1380
|
+
dispose(): void;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
/**
|
|
1384
|
+
* ToolExecutorService - Handles execution of SQL queries and external tools
|
|
1385
|
+
* Extracted from BaseLLM.generateTextResponse for better separation of concerns
|
|
1386
|
+
*/
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* External tool definition
|
|
1390
|
+
*/
|
|
1391
|
+
interface ExternalTool {
|
|
1392
|
+
id: string;
|
|
1393
|
+
name: string;
|
|
1394
|
+
description?: string;
|
|
1395
|
+
/** Tool type: "source" = routed through SourceAgent, "direct" = called directly by MainAgent */
|
|
1396
|
+
toolType?: 'source' | 'direct';
|
|
1397
|
+
/** Full untruncated schema for source agent (all columns visible) */
|
|
1398
|
+
fullSchema?: string;
|
|
1399
|
+
/** Schema size tier: small (≤50 tables), medium (51-200), large (201-500), very_large (500+) */
|
|
1400
|
+
schemaTier?: string;
|
|
1401
|
+
/** Schema search function for very_large tier — keyword search over entities */
|
|
1402
|
+
schemaSearchFn?: (keywords: string[]) => string;
|
|
1403
|
+
fn: (input: any) => Promise<any>;
|
|
1404
|
+
limit?: number;
|
|
1405
|
+
outputSchema?: any;
|
|
1406
|
+
executionType?: 'immediate' | 'deferred';
|
|
1407
|
+
userProvidedData?: any;
|
|
1408
|
+
params?: Record<string, any>;
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Executed tool tracking info
|
|
1412
|
+
*/
|
|
1413
|
+
interface ExecutedToolInfo {
|
|
1414
|
+
id: string;
|
|
1415
|
+
name: string;
|
|
1416
|
+
params: any;
|
|
1417
|
+
result: {
|
|
1418
|
+
_totalRecords: number;
|
|
1419
|
+
_recordsShown: number;
|
|
1420
|
+
_metadata?: any;
|
|
1421
|
+
_sampleData: any[];
|
|
1422
|
+
};
|
|
1423
|
+
outputSchema?: any;
|
|
1424
|
+
sourceSchema?: string;
|
|
1425
|
+
sourceType?: string;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* Multi-Agent Architecture Types
|
|
1430
|
+
*
|
|
1431
|
+
* Defines interfaces for the hierarchical agent system:
|
|
1432
|
+
* - Main Agent: ONE LLM.streamWithTools() call with source agent tools
|
|
1433
|
+
* - Source Agents: independent agents that query individual data sources
|
|
1434
|
+
*
|
|
1435
|
+
* The main agent sees only source summaries. When it calls a source tool,
|
|
1436
|
+
* the SourceAgent runs independently (own LLM, own retries) and returns clean data.
|
|
1437
|
+
*/
|
|
1438
|
+
|
|
1439
|
+
/**
|
|
1440
|
+
* Per-entity detail: name, row count, and column names.
|
|
1441
|
+
* Gives the main agent enough context to route to the right source.
|
|
1442
|
+
*/
|
|
1443
|
+
interface EntityDetail {
|
|
1444
|
+
/** Entity name (table, sheet, endpoint) */
|
|
1445
|
+
name: string;
|
|
1446
|
+
/** Approximate row count */
|
|
1447
|
+
rowCount?: number;
|
|
1448
|
+
/** Column/field names */
|
|
1449
|
+
columns: string[];
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Representation of a data source for the main agent.
|
|
1453
|
+
* Contains entity names WITH column names so the LLM can route accurately.
|
|
1454
|
+
*/
|
|
1455
|
+
interface SourceSummary {
|
|
1456
|
+
/** Source ID (matches tool ID prefix) */
|
|
1457
|
+
id: string;
|
|
1458
|
+
/** Human-readable source name */
|
|
1459
|
+
name: string;
|
|
1460
|
+
/** Source type: postgres, excel, rest_api, etc. */
|
|
1461
|
+
type: string;
|
|
1462
|
+
/** Brief description of what data this source contains */
|
|
1463
|
+
description: string;
|
|
1464
|
+
/** Detailed entity info with column names for routing */
|
|
1465
|
+
entityDetails: EntityDetail[];
|
|
1466
|
+
/** The tool ID associated with this source */
|
|
1467
|
+
toolId: string;
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* What a source agent returns after querying its data source.
|
|
1471
|
+
* The main agent uses this to analyze and compose the final response.
|
|
1472
|
+
*/
|
|
1473
|
+
interface SourceAgentResult {
|
|
1474
|
+
/** Source ID */
|
|
1475
|
+
sourceId: string;
|
|
1476
|
+
/** Source name */
|
|
1477
|
+
sourceName: string;
|
|
1478
|
+
/** Whether the query succeeded */
|
|
1479
|
+
success: boolean;
|
|
1480
|
+
/** Result data rows */
|
|
1481
|
+
data: any[];
|
|
1482
|
+
/** Metadata about the query execution */
|
|
1483
|
+
metadata: SourceAgentMetadata;
|
|
1484
|
+
/** Tool execution info for the last successful query (backward compat) */
|
|
1485
|
+
executedTool: ExecutedToolInfo;
|
|
1486
|
+
/** All successful tool executions (primary + follow-up queries) */
|
|
1487
|
+
allExecutedTools?: ExecutedToolInfo[];
|
|
1488
|
+
/** Error message if failed */
|
|
1489
|
+
error?: string;
|
|
1490
|
+
}
|
|
1491
|
+
interface SourceAgentMetadata {
|
|
1492
|
+
/** Total rows that matched the query (before limit) */
|
|
1493
|
+
totalRowsMatched: number;
|
|
1494
|
+
/** Rows actually returned (after limit) */
|
|
1495
|
+
rowsReturned: number;
|
|
1496
|
+
/** Whether the result was truncated by the row limit */
|
|
1497
|
+
isLimited: boolean;
|
|
1498
|
+
/** The query/params that were executed */
|
|
1499
|
+
queryExecuted?: string;
|
|
1500
|
+
/** Execution time in milliseconds */
|
|
1501
|
+
executionTimeMs: number;
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* A pre-built, multi-step UI flow registered with the SDK.
|
|
1505
|
+
*
|
|
1506
|
+
* When the main agent decides a user's question matches a workflow's whenToUse
|
|
1507
|
+
* trigger, it picks the workflow instead of running source agents / generating
|
|
1508
|
+
* dashboard components. The LLM extracts the workflow's required props from the
|
|
1509
|
+
* prompt (using `propsSchema` as the tool input_schema) and the SDK returns the
|
|
1510
|
+
* workflow component directly — no analysis text, no chart generation. The
|
|
1511
|
+
* frontend renders the registered workflow component with the LLM-extracted
|
|
1512
|
+
* props.
|
|
1513
|
+
*/
|
|
1514
|
+
interface WorkflowDescriptor {
|
|
1515
|
+
/** Unique workflow id (used as the LLM tool name) */
|
|
1516
|
+
id: string;
|
|
1517
|
+
/** Component name on the frontend (matches the registered React component) */
|
|
1518
|
+
name: string;
|
|
1519
|
+
/** Short human-readable description of what this workflow does */
|
|
1520
|
+
description: string;
|
|
1521
|
+
/**
|
|
1522
|
+
* 1–2 sentence trigger condition. The LLM uses this to decide if the
|
|
1523
|
+
* user's prompt matches this workflow. Be specific — e.g.
|
|
1524
|
+
* "User wants to *initiate* an inventory transfer (review + submit POs),
|
|
1525
|
+
* not just see analysis or charts."
|
|
1526
|
+
*/
|
|
1527
|
+
whenToUse: string;
|
|
1528
|
+
/**
|
|
1529
|
+
* JSON-schema-style description of the props the workflow needs. Becomes
|
|
1530
|
+
* the LLM tool's input_schema, so the model fills these from the prompt.
|
|
1531
|
+
* Use the same shape as `params` on direct tools — string descriptors with
|
|
1532
|
+
* an optional "(optional)" suffix.
|
|
1533
|
+
*
|
|
1534
|
+
* Example:
|
|
1535
|
+
* ```
|
|
1536
|
+
* {
|
|
1537
|
+
* selectedStore: 'object — { id, name } of the source branch',
|
|
1538
|
+
* minROI: 'number (optional) — only show transfers with ROI ≥ this',
|
|
1539
|
+
* }
|
|
1540
|
+
* ```
|
|
1541
|
+
*/
|
|
1542
|
+
propsSchema: Record<string, string>;
|
|
1543
|
+
/**
|
|
1544
|
+
* Optional: static prop defaults merged with LLM-extracted props before
|
|
1545
|
+
* the component is returned. Useful for things like the embedded
|
|
1546
|
+
* `externalTool` config that the workflow uses to fetch its own data.
|
|
1547
|
+
*/
|
|
1548
|
+
defaultProps?: Record<string, any>;
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1551
|
+
* The workflow selection captured during a routing call.
|
|
1552
|
+
* Set on AgentResponse when the LLM picks a workflow tool.
|
|
1553
|
+
*/
|
|
1554
|
+
interface SelectedWorkflow {
|
|
1555
|
+
/** Component name (matches WorkflowDescriptor.name) */
|
|
1556
|
+
name: string;
|
|
1557
|
+
/** Props extracted from the prompt + merged with workflow.defaultProps */
|
|
1558
|
+
props: Record<string, any>;
|
|
1559
|
+
}
|
|
1560
|
+
/**
|
|
1561
|
+
* The complete response from the multi-agent system.
|
|
1562
|
+
* Contains everything needed for text display + component generation.
|
|
1563
|
+
*/
|
|
1564
|
+
interface AgentResponse {
|
|
1565
|
+
/** Generated text response (analysis of the data) */
|
|
1566
|
+
text: string;
|
|
1567
|
+
/** All executed tools across all source agents (for component generation) */
|
|
1568
|
+
executedTools: ExecutedToolInfo[];
|
|
1569
|
+
/** Individual results from each source agent */
|
|
1570
|
+
sourceResults: SourceAgentResult[];
|
|
1571
|
+
/**
|
|
1572
|
+
* Set when the LLM routed the question to a registered workflow component.
|
|
1573
|
+
* When present, the upstream caller should skip component generation and
|
|
1574
|
+
* return this workflow as the response.
|
|
1575
|
+
*/
|
|
1576
|
+
workflow?: SelectedWorkflow;
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Configuration for the multi-agent system.
|
|
1580
|
+
* Controls limits, models, and behavior.
|
|
1581
|
+
*/
|
|
1582
|
+
interface AgentConfig {
|
|
1583
|
+
/** Max rows a source agent can return (default: 50) */
|
|
1584
|
+
maxRowsPerSource: number;
|
|
1585
|
+
/** Model for the main agent (routing + analysis in one LLM call) */
|
|
1586
|
+
mainAgentModel: string;
|
|
1587
|
+
/** Model for source agent query generation */
|
|
1588
|
+
sourceAgentModel: string;
|
|
1589
|
+
/** API key for LLM calls */
|
|
1590
|
+
apiKey?: string;
|
|
1591
|
+
/** Max retry attempts per source agent */
|
|
1592
|
+
maxRetries: number;
|
|
1593
|
+
/** Max tool calling iterations for the main agent loop */
|
|
1594
|
+
maxIterations: number;
|
|
1595
|
+
/** Global knowledge base context (static, same for all users/questions — cached in system prompt) */
|
|
1596
|
+
globalKnowledgeBase?: string;
|
|
1597
|
+
/** Per-request knowledge base context (user-specific + query-matched — dynamic, not cached) */
|
|
1598
|
+
knowledgeBaseContext?: string;
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Default agent configuration
|
|
1602
|
+
*/
|
|
1603
|
+
declare const DEFAULT_AGENT_CONFIG: AgentConfig;
|
|
1604
|
+
|
|
1605
|
+
/**
|
|
1606
|
+
* Main Agent (Orchestrator)
|
|
1607
|
+
*
|
|
1608
|
+
* A single LLM.streamWithTools() call that handles everything:
|
|
1609
|
+
* - Routing: decides which source(s) to query based on summaries
|
|
1610
|
+
* - Querying: calls source tools (each wraps an independent SourceAgent)
|
|
1611
|
+
* - Direct tools: calls pre-built function tools directly with LLM-provided params
|
|
1612
|
+
* - Re-querying: if data is wrong/incomplete, calls tools again with modified intent
|
|
1613
|
+
* - Analysis: generates final text response from the data
|
|
1614
|
+
*
|
|
1615
|
+
* Two tool types:
|
|
1616
|
+
* - "source" tools: main agent sees summaries, SourceAgent handles SQL generation independently
|
|
1617
|
+
* - "direct" tools: main agent calls fn() directly with structured params (no SourceAgent)
|
|
1618
|
+
*/
|
|
1619
|
+
|
|
1620
|
+
declare class MainAgent {
|
|
1621
|
+
private externalTools;
|
|
1622
|
+
private workflows;
|
|
1623
|
+
private config;
|
|
1624
|
+
private streamBuffer;
|
|
1625
|
+
constructor(externalTools: ExternalTool[], config: AgentConfig, streamBuffer?: StreamBuffer, workflows?: WorkflowDescriptor[]);
|
|
1626
|
+
/**
|
|
1627
|
+
* Handle a user question using the multi-agent system.
|
|
1628
|
+
*
|
|
1629
|
+
* This is ONE LLM.streamWithTools() call. The LLM:
|
|
1630
|
+
* 1. Sees source summaries + direct tool descriptions in system prompt
|
|
1631
|
+
* 2. Decides which tool(s) to call (routing)
|
|
1632
|
+
* 3. Source tools → SourceAgent runs independently → returns data
|
|
1633
|
+
* 4. Direct tools → fn() called directly with LLM params → returns data
|
|
1634
|
+
* 5. Generates final analysis text
|
|
1635
|
+
*/
|
|
1636
|
+
handleQuestion(userPrompt: string, apiKey?: string, conversationHistory?: string, streamCallback?: (chunk: string) => void): Promise<AgentResponse>;
|
|
1637
|
+
/**
|
|
1638
|
+
* Execute a direct tool — call fn() with LLM-provided params, no SourceAgent.
|
|
1639
|
+
*/
|
|
1640
|
+
private handleDirectTool;
|
|
1641
|
+
/**
|
|
1642
|
+
* Build the main agent's system prompt with source summaries, direct tool descriptions,
|
|
1643
|
+
* and workflow component descriptions.
|
|
1644
|
+
*/
|
|
1645
|
+
private buildSystemPrompt;
|
|
1646
|
+
/**
|
|
1647
|
+
* Build tool definitions for source tools — summary-only descriptions.
|
|
1648
|
+
* The full schema is inside the SourceAgent which runs independently.
|
|
1649
|
+
*/
|
|
1650
|
+
private buildSourceToolDefinitions;
|
|
1651
|
+
/**
|
|
1652
|
+
* Build tool definitions for direct tools — expose their actual params.
|
|
1653
|
+
* These are called directly by the main agent LLM, no SourceAgent.
|
|
1654
|
+
*/
|
|
1655
|
+
private buildDirectToolDefinitions;
|
|
1656
|
+
/**
|
|
1657
|
+
* Capture a workflow selection. We do NOT execute anything — the LLM has
|
|
1658
|
+
* already extracted the props it wants the workflow rendered with. We
|
|
1659
|
+
* record the selection (via the capture callback) and return a short
|
|
1660
|
+
* acknowledgement so the LLM ends its turn cleanly without writing
|
|
1661
|
+
* analysis text or calling more tools.
|
|
1662
|
+
*/
|
|
1663
|
+
private handleWorkflow;
|
|
1664
|
+
/**
|
|
1665
|
+
* Build LLM tool definitions for workflow components. The workflow's
|
|
1666
|
+
* propsSchema becomes the tool's input_schema so the LLM extracts props
|
|
1667
|
+
* directly from the prompt — same mechanic as direct tools.
|
|
1668
|
+
*/
|
|
1669
|
+
private buildWorkflowToolDefinitions;
|
|
1670
|
+
/**
|
|
1671
|
+
* Format a source agent's result as a clean string for the main agent LLM.
|
|
1672
|
+
*/
|
|
1673
|
+
private formatResultForMainAgent;
|
|
1674
|
+
/**
|
|
1675
|
+
* Get source summaries (for external inspection/debugging).
|
|
1676
|
+
*/
|
|
1677
|
+
getSourceSummaries(): SourceSummary[];
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
/**
|
|
1681
|
+
* Represents an action that can be performed on a UIBlock
|
|
1682
|
+
*/
|
|
1683
|
+
interface Action {
|
|
1684
|
+
id: string;
|
|
1685
|
+
name: string;
|
|
1686
|
+
type: string;
|
|
1687
|
+
[key: string]: any;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1244
1690
|
type SystemPrompt = string | Anthropic.Messages.TextBlockParam[];
|
|
1245
1691
|
interface LLMMessages {
|
|
1246
1692
|
sys: SystemPrompt;
|
|
@@ -1253,6 +1699,7 @@ interface LLMOptions {
|
|
|
1253
1699
|
temperature?: number;
|
|
1254
1700
|
topP?: number;
|
|
1255
1701
|
apiKey?: string;
|
|
1702
|
+
baseURL?: string;
|
|
1256
1703
|
partial?: (chunk: string) => void;
|
|
1257
1704
|
}
|
|
1258
1705
|
interface Tool {
|
|
@@ -1275,6 +1722,16 @@ declare class LLM {
|
|
|
1275
1722
|
* @returns Normalized system prompt for Anthropic API
|
|
1276
1723
|
*/
|
|
1277
1724
|
private static _normalizeSystemPrompt;
|
|
1725
|
+
/**
|
|
1726
|
+
* Strip unpaired UTF-16 surrogates from every text field of a message set.
|
|
1727
|
+
*
|
|
1728
|
+
* A lone surrogate (from mid-pair string slicing or corrupt source data)
|
|
1729
|
+
* serializes to a bare `\udXXX` escape that strict JSON parsers — including
|
|
1730
|
+
* the one on Anthropic's API — reject with "no low surrogate in string",
|
|
1731
|
+
* failing the whole request. Sanitizing here, at the single boundary every
|
|
1732
|
+
* provider call flows through, guarantees no request can carry one.
|
|
1733
|
+
*/
|
|
1734
|
+
private static _sanitizeMessages;
|
|
1278
1735
|
/**
|
|
1279
1736
|
* Log cache usage metrics from Anthropic API response
|
|
1280
1737
|
* Shows cache hits, costs, and savings
|
|
@@ -1291,6 +1748,15 @@ declare class LLM {
|
|
|
1291
1748
|
* "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
|
|
1292
1749
|
*/
|
|
1293
1750
|
private static _parseModel;
|
|
1751
|
+
/**
|
|
1752
|
+
* Map an Anthropic model id (e.g. "claude-sonnet-4-5-20250929") to the OpenRouter slug
|
|
1753
|
+
* (e.g. "claude-sonnet-4.5"). OpenRouter slugs drop the date suffix and use dotted versions.
|
|
1754
|
+
*/
|
|
1755
|
+
private static _toOpenRouterSlug;
|
|
1756
|
+
private static _openrouterOptions;
|
|
1757
|
+
private static _openrouterText;
|
|
1758
|
+
private static _openrouterStream;
|
|
1759
|
+
private static _openrouterStreamWithTools;
|
|
1294
1760
|
private static _anthropicText;
|
|
1295
1761
|
private static _anthropicStream;
|
|
1296
1762
|
private static _anthropicStreamWithTools;
|
|
@@ -1298,6 +1764,11 @@ declare class LLM {
|
|
|
1298
1764
|
private static _groqStream;
|
|
1299
1765
|
private static _geminiText;
|
|
1300
1766
|
private static _geminiStream;
|
|
1767
|
+
/**
|
|
1768
|
+
* Recursively strip unsupported JSON Schema properties for Gemini
|
|
1769
|
+
* Gemini doesn't support: additionalProperties, $schema, etc.
|
|
1770
|
+
*/
|
|
1771
|
+
private static _cleanSchemaForGemini;
|
|
1301
1772
|
private static _geminiStreamWithTools;
|
|
1302
1773
|
private static _openaiText;
|
|
1303
1774
|
private static _openaiStream;
|
|
@@ -1390,25 +1861,13 @@ declare class UILogCollector {
|
|
|
1390
1861
|
setUIBlockId(uiBlockId: string): void;
|
|
1391
1862
|
}
|
|
1392
1863
|
|
|
1393
|
-
/**
|
|
1394
|
-
* Represents an action that can be performed on a UIBlock
|
|
1395
|
-
*/
|
|
1396
|
-
interface Action {
|
|
1397
|
-
id: string;
|
|
1398
|
-
name: string;
|
|
1399
|
-
type: string;
|
|
1400
|
-
[key: string]: any;
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
/**
|
|
1404
|
-
* UIBlock represents a single user and assistant message block in a thread
|
|
1405
|
-
* Contains user question, component metadata, component data, text response, and available actions
|
|
1406
|
-
*/
|
|
1407
1864
|
declare class UIBlock {
|
|
1408
1865
|
private id;
|
|
1409
1866
|
private userQuestion;
|
|
1410
1867
|
private generatedComponentMetadata;
|
|
1411
1868
|
private componentData;
|
|
1869
|
+
/** Digest read back from storage; componentData is not persisted. */
|
|
1870
|
+
private restoredDataSummary;
|
|
1412
1871
|
private textResponse;
|
|
1413
1872
|
private actions;
|
|
1414
1873
|
private createdAt;
|
|
@@ -1420,8 +1879,11 @@ declare class UIBlock {
|
|
|
1420
1879
|
* @param actions - Optional array of available actions
|
|
1421
1880
|
* @param id - Optional custom ID, generates UUID if not provided
|
|
1422
1881
|
* @param textResponse - Optional text response from LLM
|
|
1882
|
+
* @param createdAt - Optional original timestamp. Needed when a block is rebuilt from
|
|
1883
|
+
* storage: conversation context is ordered by this, so defaulting to now would make
|
|
1884
|
+
* a restored turn look newer than the live one.
|
|
1423
1885
|
*/
|
|
1424
|
-
constructor(userQuestion: string, componentData?: Record<string, any>, generatedComponentMetadata?: Record<string, any>, actions?: Action[], id?: string, textResponse?: string | null);
|
|
1886
|
+
constructor(userQuestion: string, componentData?: Record<string, any>, generatedComponentMetadata?: Record<string, any>, actions?: Action[], id?: string, textResponse?: string | null, createdAt?: Date, restoredDataSummary?: string | null);
|
|
1425
1887
|
/**
|
|
1426
1888
|
* Get the UIBlock ID
|
|
1427
1889
|
*/
|
|
@@ -1467,6 +1929,16 @@ declare class UIBlock {
|
|
|
1467
1929
|
* Set or update component data with size and row limits
|
|
1468
1930
|
*/
|
|
1469
1931
|
setComponentData(data: Record<string, any>): void;
|
|
1932
|
+
/**
|
|
1933
|
+
* One line describing the data this block's component was built from, for
|
|
1934
|
+
* conversation context. Reads the summary the data handler already stored —
|
|
1935
|
+
* record counts and the result's non-array aggregates — so a later turn can
|
|
1936
|
+
* refer to what was shown instead of guessing at it.
|
|
1937
|
+
*
|
|
1938
|
+
* Generic by construction: whatever scalar aggregates a tool returns are what
|
|
1939
|
+
* appear here, with no knowledge of any particular tool or domain.
|
|
1940
|
+
*/
|
|
1941
|
+
getDataSummaryLine(maxChars?: number): string | null;
|
|
1470
1942
|
/**
|
|
1471
1943
|
* Set or update text response
|
|
1472
1944
|
*/
|
|
@@ -1513,6 +1985,16 @@ declare class UIBlock {
|
|
|
1513
1985
|
toJSON(): Record<string, any>;
|
|
1514
1986
|
}
|
|
1515
1987
|
|
|
1988
|
+
/** One stored turn, as a host's conversation collection hands it back. */
|
|
1989
|
+
interface HydratedTurn {
|
|
1990
|
+
id: string;
|
|
1991
|
+
userQuestion?: string;
|
|
1992
|
+
textResponse?: string | null;
|
|
1993
|
+
componentMetadata?: Record<string, any>;
|
|
1994
|
+
/** Compact digest of the data the turn's component was built from, if stored. */
|
|
1995
|
+
dataSummary?: string | null;
|
|
1996
|
+
createdAt?: Date | string;
|
|
1997
|
+
}
|
|
1516
1998
|
/**
|
|
1517
1999
|
* Thread represents a conversation thread containing multiple UIBlocks
|
|
1518
2000
|
* Each UIBlock in a thread represents a user question and assistant response pair
|
|
@@ -1521,6 +2003,7 @@ declare class Thread {
|
|
|
1521
2003
|
private id;
|
|
1522
2004
|
private uiblocks;
|
|
1523
2005
|
private createdAt;
|
|
2006
|
+
private hydrated;
|
|
1524
2007
|
/**
|
|
1525
2008
|
* Creates a new Thread instance
|
|
1526
2009
|
* @param id - Optional custom ID, generates UUID if not provided
|
|
@@ -1534,6 +2017,14 @@ declare class Thread {
|
|
|
1534
2017
|
* Add a UIBlock to the thread
|
|
1535
2018
|
*/
|
|
1536
2019
|
addUIBlock(uiblock: UIBlock): void;
|
|
2020
|
+
/**
|
|
2021
|
+
* Rebuild past turns from storage so a thread survives a restart or a new session.
|
|
2022
|
+
* Once only, and never over a block already held: anything in memory is the live
|
|
2023
|
+
* copy and may carry state the stored row does not.
|
|
2024
|
+
*/
|
|
2025
|
+
hydrate(turns: HydratedTurn[]): number;
|
|
2026
|
+
/** Whether hydration has already been attempted, successful or not. */
|
|
2027
|
+
isHydrated(): boolean;
|
|
1537
2028
|
/**
|
|
1538
2029
|
* Get a UIBlock by ID
|
|
1539
2030
|
*/
|
|
@@ -1582,12 +2073,20 @@ declare class Thread {
|
|
|
1582
2073
|
|
|
1583
2074
|
/**
|
|
1584
2075
|
* ThreadManager manages all threads globally
|
|
1585
|
-
* Provides methods to create, retrieve, and delete threads
|
|
2076
|
+
* Provides methods to create, retrieve, and delete threads.
|
|
2077
|
+
* Includes automatic cleanup to prevent unbounded memory growth.
|
|
1586
2078
|
*/
|
|
1587
2079
|
declare class ThreadManager {
|
|
1588
2080
|
private static instance;
|
|
1589
2081
|
private threads;
|
|
2082
|
+
private cleanupInterval;
|
|
2083
|
+
private readonly threadTtlMs;
|
|
1590
2084
|
private constructor();
|
|
2085
|
+
/**
|
|
2086
|
+
* Periodically remove threads older than 7 days.
|
|
2087
|
+
* Runs every hour to avoid frequent iteration over the map.
|
|
2088
|
+
*/
|
|
2089
|
+
private startCleanup;
|
|
1591
2090
|
/**
|
|
1592
2091
|
* Get singleton instance of ThreadManager
|
|
1593
2092
|
*/
|
|
@@ -1986,6 +2485,92 @@ declare function rerankConversationResults<T extends {
|
|
|
1986
2485
|
bm25Score: number;
|
|
1987
2486
|
}>;
|
|
1988
2487
|
|
|
2488
|
+
/**
|
|
2489
|
+
* QueryExecutionService - Handles all query execution, validation, and retry logic
|
|
2490
|
+
* Extracted from BaseLLM for better separation of concerns
|
|
2491
|
+
*/
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* Context for component when requesting query fix
|
|
2495
|
+
*/
|
|
2496
|
+
interface ComponentContext {
|
|
2497
|
+
name: string;
|
|
2498
|
+
type: string;
|
|
2499
|
+
title?: string;
|
|
2500
|
+
}
|
|
2501
|
+
/**
|
|
2502
|
+
* Result of query validation
|
|
2503
|
+
*/
|
|
2504
|
+
interface QueryValidationResult {
|
|
2505
|
+
component: Component | null;
|
|
2506
|
+
queryKey: string;
|
|
2507
|
+
result: any;
|
|
2508
|
+
validated: boolean;
|
|
2509
|
+
}
|
|
2510
|
+
/**
|
|
2511
|
+
* Result of batch query validation
|
|
2512
|
+
*/
|
|
2513
|
+
interface BatchValidationResult {
|
|
2514
|
+
components: Component[];
|
|
2515
|
+
queryResults: Map<string, any>;
|
|
2516
|
+
}
|
|
2517
|
+
/**
|
|
2518
|
+
* Configuration for QueryExecutionService
|
|
2519
|
+
*/
|
|
2520
|
+
interface QueryExecutionServiceConfig {
|
|
2521
|
+
defaultLimit: number;
|
|
2522
|
+
getModelForTask: (taskType: 'simple' | 'complex') => string;
|
|
2523
|
+
getApiKey: (apiKey?: string) => string | undefined;
|
|
2524
|
+
providerName: string;
|
|
2525
|
+
}
|
|
2526
|
+
/**
|
|
2527
|
+
* QueryExecutionService handles all query-related operations
|
|
2528
|
+
*/
|
|
2529
|
+
declare class QueryExecutionService {
|
|
2530
|
+
private config;
|
|
2531
|
+
constructor(config: QueryExecutionServiceConfig);
|
|
2532
|
+
/**
|
|
2533
|
+
* Get the cache key for a query
|
|
2534
|
+
* This ensures the cache key matches what the frontend will send
|
|
2535
|
+
*/
|
|
2536
|
+
getQueryCacheKey(query: any): string;
|
|
2537
|
+
/**
|
|
2538
|
+
* Execute a query against the database
|
|
2539
|
+
* @param query - The SQL query to execute (string or object with sql/values)
|
|
2540
|
+
* @param collections - Collections object containing database execute function
|
|
2541
|
+
* @returns Object with result data and cache key
|
|
2542
|
+
*/
|
|
2543
|
+
executeQuery(query: any, collections: any): Promise<{
|
|
2544
|
+
result: any;
|
|
2545
|
+
cacheKey: string;
|
|
2546
|
+
}>;
|
|
2547
|
+
/**
|
|
2548
|
+
* Request the LLM to fix a failed SQL query
|
|
2549
|
+
* @param failedQuery - The query that failed execution
|
|
2550
|
+
* @param errorMessage - The error message from the failed execution
|
|
2551
|
+
* @param componentContext - Context about the component
|
|
2552
|
+
* @param apiKey - Optional API key
|
|
2553
|
+
* @returns Fixed query string
|
|
2554
|
+
*/
|
|
2555
|
+
requestQueryFix(failedQuery: string, errorMessage: string, componentContext: ComponentContext, apiKey?: string): Promise<string>;
|
|
2556
|
+
/**
|
|
2557
|
+
* Validate a single component's query with retry logic
|
|
2558
|
+
* @param component - The component to validate
|
|
2559
|
+
* @param collections - Collections object containing database execute function
|
|
2560
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2561
|
+
* @returns Validation result with component, query key, and result
|
|
2562
|
+
*/
|
|
2563
|
+
validateSingleQuery(component: Component, collections: any, apiKey?: string): Promise<QueryValidationResult>;
|
|
2564
|
+
/**
|
|
2565
|
+
* Validate multiple component queries in parallel
|
|
2566
|
+
* @param components - Array of components with potential queries
|
|
2567
|
+
* @param collections - Collections object containing database execute function
|
|
2568
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2569
|
+
* @returns Object with validated components and query results map
|
|
2570
|
+
*/
|
|
2571
|
+
validateComponentQueries(components: Component[], collections: any, apiKey?: string): Promise<BatchValidationResult>;
|
|
2572
|
+
}
|
|
2573
|
+
|
|
1989
2574
|
/**
|
|
1990
2575
|
* Task types for model selection
|
|
1991
2576
|
* - 'complex': Text generation, component matching, parameter adaptation (uses best model in balanced mode)
|
|
@@ -2004,6 +2589,7 @@ interface BaseLLMConfig {
|
|
|
2004
2589
|
* - 'balanced': Use best model for complex tasks, fast model for simple tasks (default)
|
|
2005
2590
|
*/
|
|
2006
2591
|
modelStrategy?: ModelStrategy;
|
|
2592
|
+
conversationSimilarityThreshold?: number;
|
|
2007
2593
|
}
|
|
2008
2594
|
/**
|
|
2009
2595
|
* BaseLLM abstract class for AI-powered component generation and matching
|
|
@@ -2015,6 +2601,8 @@ declare abstract class BaseLLM {
|
|
|
2015
2601
|
protected defaultLimit: number;
|
|
2016
2602
|
protected apiKey?: string;
|
|
2017
2603
|
protected modelStrategy: ModelStrategy;
|
|
2604
|
+
protected conversationSimilarityThreshold: number;
|
|
2605
|
+
protected queryService: QueryExecutionService;
|
|
2018
2606
|
constructor(config?: BaseLLMConfig);
|
|
2019
2607
|
/**
|
|
2020
2608
|
* Get the appropriate model based on task type and model strategy
|
|
@@ -2032,6 +2620,16 @@ declare abstract class BaseLLM {
|
|
|
2032
2620
|
* @returns The current model strategy
|
|
2033
2621
|
*/
|
|
2034
2622
|
getModelStrategy(): ModelStrategy;
|
|
2623
|
+
/**
|
|
2624
|
+
* Set the conversation similarity threshold at runtime
|
|
2625
|
+
* @param threshold - Value between 0 and 1 (e.g., 0.8 = 80% similarity required)
|
|
2626
|
+
*/
|
|
2627
|
+
setConversationSimilarityThreshold(threshold: number): void;
|
|
2628
|
+
/**
|
|
2629
|
+
* Get the current conversation similarity threshold
|
|
2630
|
+
* @returns The current threshold value
|
|
2631
|
+
*/
|
|
2632
|
+
getConversationSimilarityThreshold(): number;
|
|
2035
2633
|
/**
|
|
2036
2634
|
* Get the default model for this provider (used for complex tasks like text generation)
|
|
2037
2635
|
*/
|
|
@@ -2067,11 +2665,10 @@ declare abstract class BaseLLM {
|
|
|
2067
2665
|
* @param analysisContent - The text response containing component suggestions
|
|
2068
2666
|
* @param components - List of available components
|
|
2069
2667
|
* @param apiKey - Optional API key
|
|
2070
|
-
* @param logCollector - Optional log collector
|
|
2071
2668
|
* @param componentStreamCallback - Optional callback to stream primary KPI component as soon as it's identified
|
|
2072
2669
|
* @returns Object containing matched components, layout title/description, and follow-up actions
|
|
2073
2670
|
*/
|
|
2074
|
-
matchComponentsFromAnalysis(analysisContent: string, components: Component[],
|
|
2671
|
+
matchComponentsFromAnalysis(analysisContent: string, components: Component[], userPrompt: string, apiKey?: string, componentStreamCallback?: (component: Component) => void, deferredTools?: any[], executedTools?: any[], collections?: any, userId?: string): Promise<{
|
|
2075
2672
|
components: Component[];
|
|
2076
2673
|
layoutTitle: string;
|
|
2077
2674
|
layoutDescription: string;
|
|
@@ -2081,7 +2678,7 @@ declare abstract class BaseLLM {
|
|
|
2081
2678
|
* Classify user question into category and detect external tools needed
|
|
2082
2679
|
* Determines if question is for data analysis, requires external tools, or needs text response
|
|
2083
2680
|
*/
|
|
2084
|
-
classifyQuestionCategory(userPrompt: string, apiKey?: string,
|
|
2681
|
+
classifyQuestionCategory(userPrompt: string, apiKey?: string, conversationHistory?: string, externalTools?: any[]): Promise<{
|
|
2085
2682
|
category: 'data_analysis' | 'data_modification' | 'general';
|
|
2086
2683
|
externalTools: Array<{
|
|
2087
2684
|
type: string;
|
|
@@ -2098,7 +2695,7 @@ declare abstract class BaseLLM {
|
|
|
2098
2695
|
* Takes a matched UI block from semantic search and modifies its props to answer the new question
|
|
2099
2696
|
* Also adapts the cached text response to match the new question
|
|
2100
2697
|
*/
|
|
2101
|
-
adaptUIBlockParameters(currentUserPrompt: string, originalUserPrompt: string, matchedUIBlock: any, apiKey?: string,
|
|
2698
|
+
adaptUIBlockParameters(currentUserPrompt: string, originalUserPrompt: string, matchedUIBlock: any, apiKey?: string, cachedTextResponse?: string): Promise<{
|
|
2102
2699
|
success: boolean;
|
|
2103
2700
|
adaptedComponent?: Component;
|
|
2104
2701
|
adaptedTextResponse?: string;
|
|
@@ -2113,13 +2710,8 @@ declare abstract class BaseLLM {
|
|
|
2113
2710
|
* This provides conversational text responses instead of component generation
|
|
2114
2711
|
* Supports tool calling for query execution with automatic retry on errors (max 3 attempts)
|
|
2115
2712
|
* After generating text response, if components are provided, matches suggested components
|
|
2116
|
-
* @param streamCallback - Optional callback function to receive text chunks as they stream
|
|
2117
|
-
* @param collections - Collection registry for executing database queries via database.execute
|
|
2118
|
-
* @param components - Optional list of available components for matching suggestions
|
|
2119
|
-
* @param externalTools - Optional array of external tools (email, calendar, etc.) that can be called
|
|
2120
|
-
* @param category - Question category ('data_analysis' | 'data_modification' | 'general'). For data_modification, answer component streaming is skipped. For general, component generation is skipped entirely.
|
|
2121
2713
|
*/
|
|
2122
|
-
generateTextResponse(userPrompt: string, apiKey?: string,
|
|
2714
|
+
generateTextResponse(userPrompt: string, apiKey?: string, conversationHistory?: string, streamCallback?: (chunk: string) => void, collections?: any, components?: Component[], externalTools?: any[], category?: 'data_analysis' | 'data_modification' | 'general', userId?: string): Promise<T_RESPONSE>;
|
|
2123
2715
|
/**
|
|
2124
2716
|
* Main orchestration function with semantic search and multi-step classification
|
|
2125
2717
|
* NEW FLOW (Recommended):
|
|
@@ -2127,19 +2719,14 @@ declare abstract class BaseLLM {
|
|
|
2127
2719
|
* - If match found → Adapt UI block parameters and return
|
|
2128
2720
|
* 2. Category classification: Determine if data_analysis, requires_external_tools, or text_response
|
|
2129
2721
|
* 3. Route appropriately based on category and response mode
|
|
2130
|
-
*
|
|
2131
|
-
* @param responseMode - 'component' for component generation (default), 'text' for text responses
|
|
2132
|
-
* @param streamCallback - Optional callback function to receive text chunks as they stream (only for text mode)
|
|
2133
|
-
* @param collections - Collection registry for executing database queries (required for text mode)
|
|
2134
|
-
* @param externalTools - Optional array of external tools (email, calendar, etc.) that can be called (only for text mode)
|
|
2135
2722
|
*/
|
|
2136
|
-
handleUserRequest(userPrompt: string, components: Component[], apiKey?: string,
|
|
2723
|
+
handleUserRequest(userPrompt: string, components: Component[], apiKey?: string, conversationHistory?: string, responseMode?: 'component' | 'text', streamCallback?: (chunk: string) => void, collections?: any, externalTools?: any[], userId?: string): Promise<T_RESPONSE>;
|
|
2137
2724
|
/**
|
|
2138
2725
|
* Generate next questions that the user might ask based on the original prompt and generated component
|
|
2139
2726
|
* This helps provide intelligent suggestions for follow-up queries
|
|
2140
2727
|
* For general/conversational questions without components, pass textResponse instead
|
|
2141
2728
|
*/
|
|
2142
|
-
generateNextQuestions(originalUserPrompt: string, component?: Component | null, componentData?: Record<string, unknown>, apiKey?: string,
|
|
2729
|
+
generateNextQuestions(originalUserPrompt: string, component?: Component | null, componentData?: Record<string, unknown>, apiKey?: string, conversationHistory?: string, textResponse?: string): Promise<string[]>;
|
|
2143
2730
|
}
|
|
2144
2731
|
|
|
2145
2732
|
interface AnthropicLLMConfig extends BaseLLMConfig {
|
|
@@ -2198,7 +2785,176 @@ declare class OpenAILLM extends BaseLLM {
|
|
|
2198
2785
|
}
|
|
2199
2786
|
declare const openaiLLM: OpenAILLM;
|
|
2200
2787
|
|
|
2201
|
-
|
|
2788
|
+
/**
|
|
2789
|
+
* Query Cache — Two mechanisms:
|
|
2790
|
+
*
|
|
2791
|
+
* 1. `cache` (query string → result data) — TTL-based with max size, for avoiding re-execution
|
|
2792
|
+
* of recently validated queries. True LRU eviction: reads bubble entries to the back via
|
|
2793
|
+
* delete+re-set so the oldest *unused* entry is evicted, not the oldest *inserted*.
|
|
2794
|
+
*
|
|
2795
|
+
* 2. Encrypted queryId tokens — SQL is encrypted into the queryId itself (self-contained).
|
|
2796
|
+
* No server-side storage needed for SQL mappings. The token is decrypted on each request.
|
|
2797
|
+
* This eliminates the unbounded queryIdCache that previously grew forever and caused
|
|
2798
|
+
* memory bloat (hundreds of MBs after thousands of queries).
|
|
2799
|
+
*
|
|
2800
|
+
* Result data can still be cached temporarily via the data cache (mechanism 1).
|
|
2801
|
+
*/
|
|
2802
|
+
declare class QueryCache {
|
|
2803
|
+
private cache;
|
|
2804
|
+
private ttlMs;
|
|
2805
|
+
private maxCacheSize;
|
|
2806
|
+
private maxCacheBytes;
|
|
2807
|
+
private currentBytes;
|
|
2808
|
+
private cleanupInterval;
|
|
2809
|
+
private readonly algorithm;
|
|
2810
|
+
private encryptionKey;
|
|
2811
|
+
constructor();
|
|
2812
|
+
/**
|
|
2813
|
+
* Set the byte budget for cached result data.
|
|
2814
|
+
* @param megabytes - Budget in MB. Keep it well under the process memory limit.
|
|
2815
|
+
*/
|
|
2816
|
+
setMaxBytes(megabytes: number): void;
|
|
2817
|
+
/** Current estimated bytes held by the data cache. */
|
|
2818
|
+
getCurrentBytes(): number;
|
|
2819
|
+
/**
|
|
2820
|
+
* Rough retained size of a result, in bytes.
|
|
2821
|
+
*
|
|
2822
|
+
* Sampled rather than exact: stringifying a multi-megabyte result on every set()
|
|
2823
|
+
* would allocate the very memory this budget exists to protect. Estimated from a
|
|
2824
|
+
* few rows of the largest array in the payload, at 2 bytes per UTF-16 char.
|
|
2825
|
+
* Both error directions are safe — under-estimating evicts less than ideal,
|
|
2826
|
+
* over-estimating evicts more, and a miss only re-runs the query.
|
|
2827
|
+
*/
|
|
2828
|
+
private estimateBytes;
|
|
2829
|
+
/** Largest array at the top level or one level in — where result rows live. */
|
|
2830
|
+
private largestArray;
|
|
2831
|
+
/** Drop least-recently-used entries until the budget is satisfied. */
|
|
2832
|
+
private evictUntilUnderBudget;
|
|
2833
|
+
/**
|
|
2834
|
+
* Set the cache TTL (Time To Live)
|
|
2835
|
+
* @param minutes - TTL in minutes (default: 10)
|
|
2836
|
+
*/
|
|
2837
|
+
setTTL(minutes: number): void;
|
|
2838
|
+
/**
|
|
2839
|
+
* Get the current TTL in minutes
|
|
2840
|
+
*/
|
|
2841
|
+
getTTL(): number;
|
|
2842
|
+
/**
|
|
2843
|
+
* Store query result in data cache.
|
|
2844
|
+
* If the key already exists, it's removed first so the re-insert places it
|
|
2845
|
+
* at the back of the iteration order (LRU). Eviction only fires when adding
|
|
2846
|
+
* a genuinely new key past the size limit.
|
|
2847
|
+
*/
|
|
2848
|
+
set(query: string, data: any): void;
|
|
2849
|
+
/**
|
|
2850
|
+
* Get cached result if exists and not expired.
|
|
2851
|
+
* On hit, re-inserts the entry so it moves to the back of the Map's
|
|
2852
|
+
* iteration order — turning FIFO eviction into true LRU.
|
|
2853
|
+
*/
|
|
2854
|
+
get(query: string): any | null;
|
|
2855
|
+
/**
|
|
2856
|
+
* Check if query exists in cache (not expired)
|
|
2857
|
+
*/
|
|
2858
|
+
has(query: string): boolean;
|
|
2859
|
+
/**
|
|
2860
|
+
* Remove a specific query from cache
|
|
2861
|
+
*/
|
|
2862
|
+
delete(query: string): void;
|
|
2863
|
+
/**
|
|
2864
|
+
* Clear all cached entries
|
|
2865
|
+
*/
|
|
2866
|
+
clear(): void;
|
|
2867
|
+
/**
|
|
2868
|
+
* Get cache statistics
|
|
2869
|
+
*/
|
|
2870
|
+
getStats(): {
|
|
2871
|
+
size: number;
|
|
2872
|
+
queryIdCount: number;
|
|
2873
|
+
oldestEntryAge: number | null;
|
|
2874
|
+
};
|
|
2875
|
+
/**
|
|
2876
|
+
* Start periodic cleanup of expired data cache entries.
|
|
2877
|
+
*/
|
|
2878
|
+
private startCleanup;
|
|
2879
|
+
/**
|
|
2880
|
+
* Encrypt a payload into a self-contained token.
|
|
2881
|
+
*/
|
|
2882
|
+
private encrypt;
|
|
2883
|
+
/**
|
|
2884
|
+
* Decrypt a token back to the original payload.
|
|
2885
|
+
*/
|
|
2886
|
+
private decrypt;
|
|
2887
|
+
/**
|
|
2888
|
+
* Store a query by generating an encrypted token as queryId.
|
|
2889
|
+
* The SQL is encrypted INTO the token — nothing stored in memory.
|
|
2890
|
+
* If data is provided, it's cached temporarily in the data cache.
|
|
2891
|
+
*/
|
|
2892
|
+
storeQuery(query: any, data?: any): string;
|
|
2893
|
+
/**
|
|
2894
|
+
* Get a stored query by decrypting its token.
|
|
2895
|
+
* Returns the SQL + any cached result data.
|
|
2896
|
+
*/
|
|
2897
|
+
getQuery(queryId: string): {
|
|
2898
|
+
query: any;
|
|
2899
|
+
data: any;
|
|
2900
|
+
} | null;
|
|
2901
|
+
/**
|
|
2902
|
+
* Update cached data for a queryId token
|
|
2903
|
+
*/
|
|
2904
|
+
setQueryData(queryId: string, data: any): void;
|
|
2905
|
+
/**
|
|
2906
|
+
* Stop cleanup interval (for graceful shutdown)
|
|
2907
|
+
*/
|
|
2908
|
+
destroy(): void;
|
|
2909
|
+
}
|
|
2910
|
+
declare const queryCache: QueryCache;
|
|
2911
|
+
|
|
2912
|
+
/**
|
|
2913
|
+
* Manages conversation history scoped per user + dashboard.
|
|
2914
|
+
* Each user-dashboard pair has its own isolated history that expires after a configurable TTL.
|
|
2915
|
+
*/
|
|
2916
|
+
declare class DashboardConversationHistory {
|
|
2917
|
+
private histories;
|
|
2918
|
+
private ttlMs;
|
|
2919
|
+
private maxEntries;
|
|
2920
|
+
private cleanupInterval;
|
|
2921
|
+
constructor();
|
|
2922
|
+
/**
|
|
2923
|
+
* Set the TTL for dashboard histories
|
|
2924
|
+
* @param minutes - TTL in minutes
|
|
2925
|
+
*/
|
|
2926
|
+
setTTL(minutes: number): void;
|
|
2927
|
+
/**
|
|
2928
|
+
* Set max entries per dashboard
|
|
2929
|
+
*/
|
|
2930
|
+
setMaxEntries(max: number): void;
|
|
2931
|
+
/**
|
|
2932
|
+
* Add a conversation entry for a user's dashboard
|
|
2933
|
+
*/
|
|
2934
|
+
addEntry(dashboardId: string, userPrompt: string, componentSummary: string, userId?: string): void;
|
|
2935
|
+
/**
|
|
2936
|
+
* Get formatted conversation history for a user's dashboard
|
|
2937
|
+
*/
|
|
2938
|
+
getHistory(dashboardId: string, userId?: string): string;
|
|
2939
|
+
/**
|
|
2940
|
+
* Clear history for a specific user's dashboard
|
|
2941
|
+
*/
|
|
2942
|
+
clearDashboard(dashboardId: string, userId?: string): void;
|
|
2943
|
+
/**
|
|
2944
|
+
* Clear all dashboard histories
|
|
2945
|
+
*/
|
|
2946
|
+
clearAll(): void;
|
|
2947
|
+
/**
|
|
2948
|
+
* Start periodic cleanup of expired histories
|
|
2949
|
+
*/
|
|
2950
|
+
private startCleanup;
|
|
2951
|
+
/**
|
|
2952
|
+
* Stop cleanup interval (for graceful shutdown)
|
|
2953
|
+
*/
|
|
2954
|
+
destroy(): void;
|
|
2955
|
+
}
|
|
2956
|
+
declare const dashboardConversationHistory: DashboardConversationHistory;
|
|
2957
|
+
|
|
2202
2958
|
type MessageTypeHandler = (message: IncomingMessage) => void | Promise<void>;
|
|
2203
2959
|
declare class SuperatomSDK {
|
|
2204
2960
|
private ws;
|
|
@@ -2215,6 +2971,8 @@ declare class SuperatomSDK {
|
|
|
2215
2971
|
private collections;
|
|
2216
2972
|
private components;
|
|
2217
2973
|
private tools;
|
|
2974
|
+
private workflows;
|
|
2975
|
+
private registryWaiters;
|
|
2218
2976
|
private anthropicApiKey;
|
|
2219
2977
|
private groqApiKey;
|
|
2220
2978
|
private geminiApiKey;
|
|
@@ -2222,6 +2980,10 @@ declare class SuperatomSDK {
|
|
|
2222
2980
|
private llmProviders;
|
|
2223
2981
|
private databaseType;
|
|
2224
2982
|
private modelStrategy;
|
|
2983
|
+
private mainAgentModel;
|
|
2984
|
+
private sourceAgentModel;
|
|
2985
|
+
private dashCompModels?;
|
|
2986
|
+
private conversationSimilarityThreshold;
|
|
2225
2987
|
private userManager;
|
|
2226
2988
|
private dashboardManager;
|
|
2227
2989
|
private reportManager;
|
|
@@ -2268,9 +3030,11 @@ declare class SuperatomSDK {
|
|
|
2268
3030
|
*/
|
|
2269
3031
|
private handleMessage;
|
|
2270
3032
|
/**
|
|
2271
|
-
* Send a message to the Superatom service
|
|
3033
|
+
* Send a message to the Superatom service.
|
|
3034
|
+
* Returns true if the message was sent, false if the WebSocket is not connected.
|
|
3035
|
+
* Does NOT throw on closed connections — callers can check the return value if needed.
|
|
2272
3036
|
*/
|
|
2273
|
-
send(message: Message):
|
|
3037
|
+
send(message: Message): boolean;
|
|
2274
3038
|
/**
|
|
2275
3039
|
* Register a message handler to receive all messages
|
|
2276
3040
|
*/
|
|
@@ -2318,6 +3082,32 @@ declare class SuperatomSDK {
|
|
|
2318
3082
|
* Get the stored tools
|
|
2319
3083
|
*/
|
|
2320
3084
|
getTools(): Tool$1[];
|
|
3085
|
+
/**
|
|
3086
|
+
* Register workflow components for the SDK instance.
|
|
3087
|
+
*
|
|
3088
|
+
* Workflows are pre-built multi-step UI flows the main agent can pick when
|
|
3089
|
+
* the user's prompt matches a workflow's `whenToUse` trigger. Picking a
|
|
3090
|
+
* workflow short-circuits analysis text + dashboard component generation —
|
|
3091
|
+
* the workflow component is returned directly, with the LLM-extracted props.
|
|
3092
|
+
*/
|
|
3093
|
+
setWorkflows(workflows: WorkflowDescriptor[]): void;
|
|
3094
|
+
/**
|
|
3095
|
+
* Make sure the agent has a tool surface before answering a prompt.
|
|
3096
|
+
*
|
|
3097
|
+
* Components and workflows are pushed by the browser once per page load and
|
|
3098
|
+
* kept only in memory, so a backend restart leaves both lists empty until
|
|
3099
|
+
* someone reloads a tab. The agent still answers — with no workflows to route
|
|
3100
|
+
* to and no components to render — which looks like a model regression rather
|
|
3101
|
+
* than lost state. Ask the client to re-send instead, and proceed regardless
|
|
3102
|
+
* so a stale or silent client degrades no worse than it does today.
|
|
3103
|
+
*/
|
|
3104
|
+
private ensureRegistry;
|
|
3105
|
+
/** Release anyone blocked in ensureRegistry() now that the list has arrived. */
|
|
3106
|
+
private resolveRegistryWaiters;
|
|
3107
|
+
/**
|
|
3108
|
+
* Get the registered workflow components.
|
|
3109
|
+
*/
|
|
3110
|
+
getWorkflows(): WorkflowDescriptor[];
|
|
2321
3111
|
/**
|
|
2322
3112
|
* Apply model strategy to all LLM provider singletons
|
|
2323
3113
|
* @param strategy - 'best', 'fast', or 'balanced'
|
|
@@ -2332,6 +3122,20 @@ declare class SuperatomSDK {
|
|
|
2332
3122
|
* Get current model strategy
|
|
2333
3123
|
*/
|
|
2334
3124
|
getModelStrategy(): ModelStrategy;
|
|
3125
|
+
/**
|
|
3126
|
+
* Apply conversation similarity threshold to all LLM provider singletons
|
|
3127
|
+
* @param threshold - Value between 0 and 1 (e.g., 0.8 = 80% similarity required)
|
|
3128
|
+
*/
|
|
3129
|
+
private applyConversationSimilarityThreshold;
|
|
3130
|
+
/**
|
|
3131
|
+
* Set conversation similarity threshold at runtime
|
|
3132
|
+
* @param threshold - Value between 0 and 1 (e.g., 0.8 = 80% similarity required)
|
|
3133
|
+
*/
|
|
3134
|
+
setConversationSimilarityThreshold(threshold: number): void;
|
|
3135
|
+
/**
|
|
3136
|
+
* Get current conversation similarity threshold
|
|
3137
|
+
*/
|
|
3138
|
+
getConversationSimilarityThreshold(): number;
|
|
2335
3139
|
}
|
|
2336
3140
|
|
|
2337
|
-
export { type Action, BM25L, type BM25LOptions, type BaseLLMConfig, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type DatabaseType, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, type Message, type ModelStrategy, type OutputField, type RerankedResult,
|
|
3141
|
+
export { type Action, type AgentConfig, type AgentResponse, BM25L, type BM25LOptions, type BaseLLMConfig, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, DEFAULT_AGENT_CONFIG, type DatabaseType, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, MainAgent, type Message, type ModelStrategy, type OutputField, type RerankedResult, STORAGE_CONFIG, type SelectedWorkflow, SuperatomSDK, type SuperatomSDKConfig, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, type ToolOutputSchema, UIBlock, UILogCollector, type User, UserManager, type UsersData, type WorkflowDescriptor, anthropicLLM, dashboardConversationHistory, geminiLLM, groqLLM, hybridRerank, llmUsageLogger, logger, openaiLLM, queryCache, rerankChromaResults, rerankConversationResults, userPromptErrorLogger };
|