@superatomai/sdk-node 0.0.27 → 0.0.28-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 +1228 -44
- package/dist/index.d.ts +1228 -44
- package/dist/index.js +12203 -4935
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12190 -4938
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -59,7 +59,18 @@ declare class Logger {
|
|
|
59
59
|
* Log debug message (only shown for verbose level)
|
|
60
60
|
*/
|
|
61
61
|
debug(...args: any[]): void;
|
|
62
|
+
/**
|
|
63
|
+
* Write to log file
|
|
64
|
+
*/
|
|
62
65
|
file(...args: any[]): void;
|
|
66
|
+
/**
|
|
67
|
+
* Clear the log file (call at start of new user request)
|
|
68
|
+
*/
|
|
69
|
+
clearFile(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Log LLM method prompts with clear labeling
|
|
72
|
+
*/
|
|
73
|
+
logLLMPrompt(methodName: string, promptType: 'system' | 'user', content: string | object | any[]): void;
|
|
63
74
|
}
|
|
64
75
|
declare const logger: Logger;
|
|
65
76
|
|
|
@@ -90,7 +101,27 @@ declare const DSLRendererPropsSchema$1: z.ZodObject<{
|
|
|
90
101
|
deps?: string[] | undefined;
|
|
91
102
|
}>, "many">>;
|
|
92
103
|
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
93
|
-
render: z.ZodType<any, z.ZodTypeDef, any
|
|
104
|
+
render: z.ZodOptional<z.ZodType<any, z.ZodTypeDef, any>>;
|
|
105
|
+
pages: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
106
|
+
id: z.ZodString;
|
|
107
|
+
name: z.ZodString;
|
|
108
|
+
order: z.ZodNumber;
|
|
109
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
110
|
+
render: z.ZodType<any, z.ZodTypeDef, any>;
|
|
111
|
+
}, "strip", z.ZodTypeAny, {
|
|
112
|
+
id: string;
|
|
113
|
+
name: string;
|
|
114
|
+
order: number;
|
|
115
|
+
icon?: string | undefined;
|
|
116
|
+
render?: any;
|
|
117
|
+
}, {
|
|
118
|
+
id: string;
|
|
119
|
+
name: string;
|
|
120
|
+
order: number;
|
|
121
|
+
icon?: string | undefined;
|
|
122
|
+
render?: any;
|
|
123
|
+
}>, "many">>;
|
|
124
|
+
defaultPageId: z.ZodOptional<z.ZodString>;
|
|
94
125
|
query: z.ZodOptional<z.ZodObject<{
|
|
95
126
|
graphql: z.ZodOptional<z.ZodString>;
|
|
96
127
|
sql: z.ZodOptional<z.ZodString>;
|
|
@@ -129,6 +160,7 @@ declare const DSLRendererPropsSchema$1: z.ZodObject<{
|
|
|
129
160
|
dependencies?: string[] | undefined;
|
|
130
161
|
} | undefined;
|
|
131
162
|
props?: Record<string, any> | undefined;
|
|
163
|
+
render?: any;
|
|
132
164
|
states?: Record<string, any> | undefined;
|
|
133
165
|
methods?: Record<string, {
|
|
134
166
|
fn: string;
|
|
@@ -139,7 +171,14 @@ declare const DSLRendererPropsSchema$1: z.ZodObject<{
|
|
|
139
171
|
deps?: string[] | undefined;
|
|
140
172
|
}[] | undefined;
|
|
141
173
|
data?: Record<string, any> | undefined;
|
|
142
|
-
|
|
174
|
+
pages?: {
|
|
175
|
+
id: string;
|
|
176
|
+
name: string;
|
|
177
|
+
order: number;
|
|
178
|
+
icon?: string | undefined;
|
|
179
|
+
render?: any;
|
|
180
|
+
}[] | undefined;
|
|
181
|
+
defaultPageId?: string | undefined;
|
|
143
182
|
}, {
|
|
144
183
|
id: string;
|
|
145
184
|
name?: string | undefined;
|
|
@@ -153,6 +192,7 @@ declare const DSLRendererPropsSchema$1: z.ZodObject<{
|
|
|
153
192
|
dependencies?: string[] | undefined;
|
|
154
193
|
} | undefined;
|
|
155
194
|
props?: Record<string, any> | undefined;
|
|
195
|
+
render?: any;
|
|
156
196
|
states?: Record<string, any> | undefined;
|
|
157
197
|
methods?: Record<string, {
|
|
158
198
|
fn: string;
|
|
@@ -163,7 +203,14 @@ declare const DSLRendererPropsSchema$1: z.ZodObject<{
|
|
|
163
203
|
deps?: string[] | undefined;
|
|
164
204
|
}[] | undefined;
|
|
165
205
|
data?: Record<string, any> | undefined;
|
|
166
|
-
|
|
206
|
+
pages?: {
|
|
207
|
+
id: string;
|
|
208
|
+
name: string;
|
|
209
|
+
order: number;
|
|
210
|
+
icon?: string | undefined;
|
|
211
|
+
render?: any;
|
|
212
|
+
}[] | undefined;
|
|
213
|
+
defaultPageId?: string | undefined;
|
|
167
214
|
}>;
|
|
168
215
|
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
169
216
|
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
@@ -181,6 +228,7 @@ declare const DSLRendererPropsSchema$1: z.ZodObject<{
|
|
|
181
228
|
dependencies?: string[] | undefined;
|
|
182
229
|
} | undefined;
|
|
183
230
|
props?: Record<string, any> | undefined;
|
|
231
|
+
render?: any;
|
|
184
232
|
states?: Record<string, any> | undefined;
|
|
185
233
|
methods?: Record<string, {
|
|
186
234
|
fn: string;
|
|
@@ -191,7 +239,14 @@ declare const DSLRendererPropsSchema$1: z.ZodObject<{
|
|
|
191
239
|
deps?: string[] | undefined;
|
|
192
240
|
}[] | undefined;
|
|
193
241
|
data?: Record<string, any> | undefined;
|
|
194
|
-
|
|
242
|
+
pages?: {
|
|
243
|
+
id: string;
|
|
244
|
+
name: string;
|
|
245
|
+
order: number;
|
|
246
|
+
icon?: string | undefined;
|
|
247
|
+
render?: any;
|
|
248
|
+
}[] | undefined;
|
|
249
|
+
defaultPageId?: string | undefined;
|
|
195
250
|
};
|
|
196
251
|
data?: Record<string, any> | undefined;
|
|
197
252
|
context?: Record<string, any> | undefined;
|
|
@@ -209,6 +264,7 @@ declare const DSLRendererPropsSchema$1: z.ZodObject<{
|
|
|
209
264
|
dependencies?: string[] | undefined;
|
|
210
265
|
} | undefined;
|
|
211
266
|
props?: Record<string, any> | undefined;
|
|
267
|
+
render?: any;
|
|
212
268
|
states?: Record<string, any> | undefined;
|
|
213
269
|
methods?: Record<string, {
|
|
214
270
|
fn: string;
|
|
@@ -219,7 +275,14 @@ declare const DSLRendererPropsSchema$1: z.ZodObject<{
|
|
|
219
275
|
deps?: string[] | undefined;
|
|
220
276
|
}[] | undefined;
|
|
221
277
|
data?: Record<string, any> | undefined;
|
|
222
|
-
|
|
278
|
+
pages?: {
|
|
279
|
+
id: string;
|
|
280
|
+
name: string;
|
|
281
|
+
order: number;
|
|
282
|
+
icon?: string | undefined;
|
|
283
|
+
render?: any;
|
|
284
|
+
}[] | undefined;
|
|
285
|
+
defaultPageId?: string | undefined;
|
|
223
286
|
};
|
|
224
287
|
data?: Record<string, any> | undefined;
|
|
225
288
|
context?: Record<string, any> | undefined;
|
|
@@ -292,6 +355,7 @@ declare const DSLRendererPropsSchema: z.ZodObject<{
|
|
|
292
355
|
dependencies?: string[] | undefined;
|
|
293
356
|
} | undefined;
|
|
294
357
|
props?: Record<string, any> | undefined;
|
|
358
|
+
render?: any;
|
|
295
359
|
states?: Record<string, any> | undefined;
|
|
296
360
|
methods?: Record<string, {
|
|
297
361
|
fn: string;
|
|
@@ -302,7 +366,6 @@ declare const DSLRendererPropsSchema: z.ZodObject<{
|
|
|
302
366
|
deps?: string[] | undefined;
|
|
303
367
|
}[] | undefined;
|
|
304
368
|
data?: Record<string, any> | undefined;
|
|
305
|
-
render?: any;
|
|
306
369
|
}, {
|
|
307
370
|
id: string;
|
|
308
371
|
name?: string | undefined;
|
|
@@ -316,6 +379,7 @@ declare const DSLRendererPropsSchema: z.ZodObject<{
|
|
|
316
379
|
dependencies?: string[] | undefined;
|
|
317
380
|
} | undefined;
|
|
318
381
|
props?: Record<string, any> | undefined;
|
|
382
|
+
render?: any;
|
|
319
383
|
states?: Record<string, any> | undefined;
|
|
320
384
|
methods?: Record<string, {
|
|
321
385
|
fn: string;
|
|
@@ -326,7 +390,6 @@ declare const DSLRendererPropsSchema: z.ZodObject<{
|
|
|
326
390
|
deps?: string[] | undefined;
|
|
327
391
|
}[] | undefined;
|
|
328
392
|
data?: Record<string, any> | undefined;
|
|
329
|
-
render?: any;
|
|
330
393
|
}>;
|
|
331
394
|
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
332
395
|
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
@@ -344,6 +407,7 @@ declare const DSLRendererPropsSchema: z.ZodObject<{
|
|
|
344
407
|
dependencies?: string[] | undefined;
|
|
345
408
|
} | undefined;
|
|
346
409
|
props?: Record<string, any> | undefined;
|
|
410
|
+
render?: any;
|
|
347
411
|
states?: Record<string, any> | undefined;
|
|
348
412
|
methods?: Record<string, {
|
|
349
413
|
fn: string;
|
|
@@ -354,7 +418,6 @@ declare const DSLRendererPropsSchema: z.ZodObject<{
|
|
|
354
418
|
deps?: string[] | undefined;
|
|
355
419
|
}[] | undefined;
|
|
356
420
|
data?: Record<string, any> | undefined;
|
|
357
|
-
render?: any;
|
|
358
421
|
};
|
|
359
422
|
data?: Record<string, any> | undefined;
|
|
360
423
|
context?: Record<string, any> | undefined;
|
|
@@ -372,6 +435,7 @@ declare const DSLRendererPropsSchema: z.ZodObject<{
|
|
|
372
435
|
dependencies?: string[] | undefined;
|
|
373
436
|
} | undefined;
|
|
374
437
|
props?: Record<string, any> | undefined;
|
|
438
|
+
render?: any;
|
|
375
439
|
states?: Record<string, any> | undefined;
|
|
376
440
|
methods?: Record<string, {
|
|
377
441
|
fn: string;
|
|
@@ -382,7 +446,6 @@ declare const DSLRendererPropsSchema: z.ZodObject<{
|
|
|
382
446
|
deps?: string[] | undefined;
|
|
383
447
|
}[] | undefined;
|
|
384
448
|
data?: Record<string, any> | undefined;
|
|
385
|
-
render?: any;
|
|
386
449
|
};
|
|
387
450
|
data?: Record<string, any> | undefined;
|
|
388
451
|
context?: Record<string, any> | undefined;
|
|
@@ -563,60 +626,295 @@ declare const IncomingMessageSchema: z.ZodObject<{
|
|
|
563
626
|
payload?: unknown;
|
|
564
627
|
}>;
|
|
565
628
|
type IncomingMessage = z.infer<typeof IncomingMessageSchema>;
|
|
629
|
+
declare const ComponentSchema: z.ZodObject<{
|
|
630
|
+
id: z.ZodString;
|
|
631
|
+
name: z.ZodString;
|
|
632
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
633
|
+
isDisplayComp: z.ZodOptional<z.ZodBoolean>;
|
|
634
|
+
type: z.ZodString;
|
|
635
|
+
description: z.ZodString;
|
|
636
|
+
props: z.ZodObject<{
|
|
637
|
+
query: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>>;
|
|
638
|
+
title: z.ZodOptional<z.ZodString>;
|
|
639
|
+
description: z.ZodOptional<z.ZodString>;
|
|
640
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
641
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
642
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
643
|
+
query: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>>;
|
|
644
|
+
title: z.ZodOptional<z.ZodString>;
|
|
645
|
+
description: z.ZodOptional<z.ZodString>;
|
|
646
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
647
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
648
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
649
|
+
query: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>>;
|
|
650
|
+
title: z.ZodOptional<z.ZodString>;
|
|
651
|
+
description: z.ZodOptional<z.ZodString>;
|
|
652
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
653
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
654
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
655
|
+
category: z.ZodOptional<z.ZodString>;
|
|
656
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
657
|
+
}, "strip", z.ZodTypeAny, {
|
|
658
|
+
id: string;
|
|
659
|
+
type: string;
|
|
660
|
+
name: string;
|
|
661
|
+
description: string;
|
|
662
|
+
props: {
|
|
663
|
+
description?: string | undefined;
|
|
664
|
+
query?: string | {} | null | undefined;
|
|
665
|
+
title?: string | undefined;
|
|
666
|
+
config?: Record<string, unknown> | undefined;
|
|
667
|
+
actions?: any[] | undefined;
|
|
668
|
+
} & {
|
|
669
|
+
[k: string]: unknown;
|
|
670
|
+
};
|
|
671
|
+
displayName?: string | undefined;
|
|
672
|
+
isDisplayComp?: boolean | undefined;
|
|
673
|
+
category?: string | undefined;
|
|
674
|
+
keywords?: string[] | undefined;
|
|
675
|
+
}, {
|
|
676
|
+
id: string;
|
|
677
|
+
type: string;
|
|
678
|
+
name: string;
|
|
679
|
+
description: string;
|
|
680
|
+
props: {
|
|
681
|
+
description?: string | undefined;
|
|
682
|
+
query?: string | {} | null | undefined;
|
|
683
|
+
title?: string | undefined;
|
|
684
|
+
config?: Record<string, unknown> | undefined;
|
|
685
|
+
actions?: any[] | undefined;
|
|
686
|
+
} & {
|
|
687
|
+
[k: string]: unknown;
|
|
688
|
+
};
|
|
689
|
+
displayName?: string | undefined;
|
|
690
|
+
isDisplayComp?: boolean | undefined;
|
|
691
|
+
category?: string | undefined;
|
|
692
|
+
keywords?: string[] | undefined;
|
|
693
|
+
}>;
|
|
694
|
+
type Component = z.infer<typeof ComponentSchema>;
|
|
695
|
+
declare const OutputFieldSchema: z.ZodObject<{
|
|
696
|
+
name: z.ZodString;
|
|
697
|
+
type: z.ZodEnum<["string", "number", "boolean", "date"]>;
|
|
698
|
+
description: z.ZodString;
|
|
699
|
+
}, "strip", z.ZodTypeAny, {
|
|
700
|
+
type: "string" | "number" | "boolean" | "date";
|
|
701
|
+
name: string;
|
|
702
|
+
description: string;
|
|
703
|
+
}, {
|
|
704
|
+
type: "string" | "number" | "boolean" | "date";
|
|
705
|
+
name: string;
|
|
706
|
+
description: string;
|
|
707
|
+
}>;
|
|
708
|
+
type OutputField = z.infer<typeof OutputFieldSchema>;
|
|
709
|
+
declare const OutputSchema: z.ZodObject<{
|
|
710
|
+
description: z.ZodString;
|
|
711
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
712
|
+
name: z.ZodString;
|
|
713
|
+
type: z.ZodEnum<["string", "number", "boolean", "date"]>;
|
|
714
|
+
description: z.ZodString;
|
|
715
|
+
}, "strip", z.ZodTypeAny, {
|
|
716
|
+
type: "string" | "number" | "boolean" | "date";
|
|
717
|
+
name: string;
|
|
718
|
+
description: string;
|
|
719
|
+
}, {
|
|
720
|
+
type: "string" | "number" | "boolean" | "date";
|
|
721
|
+
name: string;
|
|
722
|
+
description: string;
|
|
723
|
+
}>, "many">;
|
|
724
|
+
}, "strip", z.ZodTypeAny, {
|
|
725
|
+
description: string;
|
|
726
|
+
fields: {
|
|
727
|
+
type: "string" | "number" | "boolean" | "date";
|
|
728
|
+
name: string;
|
|
729
|
+
description: string;
|
|
730
|
+
}[];
|
|
731
|
+
}, {
|
|
732
|
+
description: string;
|
|
733
|
+
fields: {
|
|
734
|
+
type: "string" | "number" | "boolean" | "date";
|
|
735
|
+
name: string;
|
|
736
|
+
description: string;
|
|
737
|
+
}[];
|
|
738
|
+
}>;
|
|
739
|
+
type ToolOutputSchema = z.infer<typeof OutputSchema>;
|
|
566
740
|
declare const ToolSchema: z.ZodObject<{
|
|
567
741
|
id: z.ZodString;
|
|
568
742
|
name: z.ZodString;
|
|
569
743
|
description: z.ZodString;
|
|
744
|
+
/** Tool type: "source" = routed through SourceAgent, "direct" = called directly by MainAgent */
|
|
745
|
+
toolType: z.ZodOptional<z.ZodEnum<["source", "direct"]>>;
|
|
746
|
+
/** Full untruncated schema for source agent (all columns visible) */
|
|
747
|
+
fullSchema: z.ZodOptional<z.ZodString>;
|
|
570
748
|
params: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
571
749
|
fn: z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodAny>;
|
|
750
|
+
outputSchema: z.ZodOptional<z.ZodObject<{
|
|
751
|
+
description: z.ZodString;
|
|
752
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
753
|
+
name: z.ZodString;
|
|
754
|
+
type: z.ZodEnum<["string", "number", "boolean", "date"]>;
|
|
755
|
+
description: z.ZodString;
|
|
756
|
+
}, "strip", z.ZodTypeAny, {
|
|
757
|
+
type: "string" | "number" | "boolean" | "date";
|
|
758
|
+
name: string;
|
|
759
|
+
description: string;
|
|
760
|
+
}, {
|
|
761
|
+
type: "string" | "number" | "boolean" | "date";
|
|
762
|
+
name: string;
|
|
763
|
+
description: string;
|
|
764
|
+
}>, "many">;
|
|
765
|
+
}, "strip", z.ZodTypeAny, {
|
|
766
|
+
description: string;
|
|
767
|
+
fields: {
|
|
768
|
+
type: "string" | "number" | "boolean" | "date";
|
|
769
|
+
name: string;
|
|
770
|
+
description: string;
|
|
771
|
+
}[];
|
|
772
|
+
}, {
|
|
773
|
+
description: string;
|
|
774
|
+
fields: {
|
|
775
|
+
type: "string" | "number" | "boolean" | "date";
|
|
776
|
+
name: string;
|
|
777
|
+
description: string;
|
|
778
|
+
}[];
|
|
779
|
+
}>>;
|
|
572
780
|
}, "strip", z.ZodTypeAny, {
|
|
573
781
|
id: string;
|
|
574
782
|
params: Record<string, string>;
|
|
575
783
|
name: string;
|
|
576
784
|
description: string;
|
|
577
785
|
fn: (args_0: any, ...args: unknown[]) => any;
|
|
786
|
+
toolType?: "source" | "direct" | undefined;
|
|
787
|
+
fullSchema?: string | undefined;
|
|
788
|
+
outputSchema?: {
|
|
789
|
+
description: string;
|
|
790
|
+
fields: {
|
|
791
|
+
type: "string" | "number" | "boolean" | "date";
|
|
792
|
+
name: string;
|
|
793
|
+
description: string;
|
|
794
|
+
}[];
|
|
795
|
+
} | undefined;
|
|
578
796
|
}, {
|
|
579
797
|
id: string;
|
|
580
798
|
params: Record<string, string>;
|
|
581
799
|
name: string;
|
|
582
800
|
description: string;
|
|
583
801
|
fn: (args_0: any, ...args: unknown[]) => any;
|
|
802
|
+
toolType?: "source" | "direct" | undefined;
|
|
803
|
+
fullSchema?: string | undefined;
|
|
804
|
+
outputSchema?: {
|
|
805
|
+
description: string;
|
|
806
|
+
fields: {
|
|
807
|
+
type: "string" | "number" | "boolean" | "date";
|
|
808
|
+
name: string;
|
|
809
|
+
description: string;
|
|
810
|
+
}[];
|
|
811
|
+
} | undefined;
|
|
584
812
|
}>;
|
|
585
813
|
type Tool$1 = z.infer<typeof ToolSchema>;
|
|
586
814
|
type CollectionOperation = 'getMany' | 'getOne' | 'query' | 'mutation' | 'updateOne' | 'deleteOne' | 'createOne';
|
|
587
815
|
type CollectionHandler<TParams = any, TResult = any> = (params: TParams) => Promise<TResult> | TResult;
|
|
588
816
|
type LLMProvider = 'anthropic' | 'groq' | 'gemini' | 'openai';
|
|
589
817
|
|
|
818
|
+
type DatabaseType = 'postgresql' | 'mssql' | 'snowflake' | 'mysql';
|
|
819
|
+
/**
|
|
820
|
+
* Model strategy for controlling which models are used for different tasks
|
|
821
|
+
* - 'best': Use the best model (e.g., Sonnet) for all tasks - highest quality, higher cost
|
|
822
|
+
* - 'fast': Use the fast model (e.g., Haiku) for all tasks - lower quality, lower cost
|
|
823
|
+
* - 'balanced': Use best model for complex tasks, fast model for simple tasks (default)
|
|
824
|
+
*/
|
|
825
|
+
type ModelStrategy = 'best' | 'fast' | 'balanced';
|
|
826
|
+
/**
|
|
827
|
+
* Model configuration for DASH_COMP flow (dashboard component picking)
|
|
828
|
+
* Allows separate control of models used for component selection
|
|
829
|
+
*/
|
|
830
|
+
interface DashCompModelConfig {
|
|
831
|
+
/**
|
|
832
|
+
* Primary model for DASH_COMP requests
|
|
833
|
+
* Format: "provider/model-name" (e.g., "anthropic/claude-sonnet-4-5-20250929")
|
|
834
|
+
*/
|
|
835
|
+
model?: string;
|
|
836
|
+
/**
|
|
837
|
+
* Fast model for simpler DASH_COMP tasks (optional)
|
|
838
|
+
* Format: "provider/model-name" (e.g., "anthropic/claude-haiku-4-5-20251001")
|
|
839
|
+
*/
|
|
840
|
+
fastModel?: string;
|
|
841
|
+
}
|
|
590
842
|
interface SuperatomSDKConfig {
|
|
591
843
|
url?: string;
|
|
592
844
|
apiKey?: string;
|
|
593
845
|
projectId: string;
|
|
594
|
-
userId?: string;
|
|
595
846
|
type?: string;
|
|
596
847
|
bundleDir?: string;
|
|
597
848
|
promptsDir?: string;
|
|
849
|
+
databaseType?: DatabaseType;
|
|
598
850
|
ANTHROPIC_API_KEY?: string;
|
|
599
851
|
GROQ_API_KEY?: string;
|
|
600
852
|
GEMINI_API_KEY?: string;
|
|
601
853
|
OPENAI_API_KEY?: string;
|
|
602
854
|
LLM_PROVIDERS?: LLMProvider[];
|
|
603
855
|
logLevel?: LogLevel;
|
|
856
|
+
/**
|
|
857
|
+
* Model selection strategy for LLM API calls:
|
|
858
|
+
* - 'best': Use best model for all tasks (highest quality, higher cost)
|
|
859
|
+
* - 'fast': Use fast model for all tasks (lower quality, lower cost)
|
|
860
|
+
* - 'balanced': Use best model for complex tasks, fast model for simple tasks (default)
|
|
861
|
+
*/
|
|
862
|
+
modelStrategy?: ModelStrategy;
|
|
863
|
+
/**
|
|
864
|
+
* Model for the main agent (routing + analysis).
|
|
865
|
+
* Format: "provider/model-name" (e.g., "anthropic/claude-haiku-4-5-20251001")
|
|
866
|
+
* If not set, uses the provider's default model.
|
|
867
|
+
*/
|
|
868
|
+
mainAgentModel?: string;
|
|
869
|
+
/**
|
|
870
|
+
* Model for source agents (per-source query generation).
|
|
871
|
+
* Format: "provider/model-name" (e.g., "anthropic/claude-haiku-4-5-20251001")
|
|
872
|
+
* If not set, uses the provider's default model.
|
|
873
|
+
*/
|
|
874
|
+
sourceAgentModel?: string;
|
|
875
|
+
/**
|
|
876
|
+
* Separate model configuration for DASH_COMP flow (dashboard component picking)
|
|
877
|
+
* If not provided, falls back to provider-based model selection
|
|
878
|
+
*/
|
|
879
|
+
dashCompModels?: DashCompModelConfig;
|
|
880
|
+
/**
|
|
881
|
+
* Similarity threshold for conversation search (semantic matching)
|
|
882
|
+
* Value between 0 and 1 (e.g., 0.8 = 80% similarity required)
|
|
883
|
+
* Higher values require closer matches, lower values allow more distant matches
|
|
884
|
+
* Default: 0.8
|
|
885
|
+
*/
|
|
886
|
+
conversationSimilarityThreshold?: number;
|
|
887
|
+
/**
|
|
888
|
+
* Query cache TTL (Time To Live) in minutes
|
|
889
|
+
* Cached query results expire after this duration
|
|
890
|
+
* Default: 5 minutes
|
|
891
|
+
*/
|
|
892
|
+
queryCacheTTL?: number;
|
|
893
|
+
/**
|
|
894
|
+
* Dashboard conversation history TTL (Time To Live) in minutes
|
|
895
|
+
* Per-dashboard conversation histories expire after this duration
|
|
896
|
+
* Default: 30 minutes
|
|
897
|
+
*/
|
|
898
|
+
dashboardHistoryTTL?: number;
|
|
604
899
|
}
|
|
605
900
|
|
|
606
901
|
declare const KbNodesQueryFiltersSchema: z.ZodObject<{
|
|
607
902
|
query: z.ZodOptional<z.ZodString>;
|
|
608
903
|
category: z.ZodOptional<z.ZodString>;
|
|
609
904
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
610
|
-
|
|
905
|
+
type: z.ZodOptional<z.ZodEnum<["global", "user", "query"]>>;
|
|
906
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
611
907
|
}, "strip", z.ZodTypeAny, {
|
|
908
|
+
type?: "query" | "user" | "global" | undefined;
|
|
612
909
|
query?: string | undefined;
|
|
613
910
|
category?: string | undefined;
|
|
614
|
-
createdBy?:
|
|
911
|
+
createdBy?: string | undefined;
|
|
615
912
|
tags?: string[] | undefined;
|
|
616
913
|
}, {
|
|
914
|
+
type?: "query" | "user" | "global" | undefined;
|
|
617
915
|
query?: string | undefined;
|
|
618
916
|
category?: string | undefined;
|
|
619
|
-
createdBy?:
|
|
917
|
+
createdBy?: string | undefined;
|
|
620
918
|
tags?: string[] | undefined;
|
|
621
919
|
}>;
|
|
622
920
|
type KbNodesQueryFilters = z.infer<typeof KbNodesQueryFiltersSchema>;
|
|
@@ -628,109 +926,126 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
|
|
|
628
926
|
content: z.ZodOptional<z.ZodString>;
|
|
629
927
|
category: z.ZodOptional<z.ZodString>;
|
|
630
928
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
929
|
+
type: z.ZodOptional<z.ZodEnum<["global", "user", "query"]>>;
|
|
930
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
931
|
+
updatedBy: z.ZodOptional<z.ZodString>;
|
|
932
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
634
933
|
query: z.ZodOptional<z.ZodString>;
|
|
635
934
|
filters: z.ZodOptional<z.ZodObject<{
|
|
636
935
|
query: z.ZodOptional<z.ZodString>;
|
|
637
936
|
category: z.ZodOptional<z.ZodString>;
|
|
638
937
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
639
|
-
|
|
938
|
+
type: z.ZodOptional<z.ZodEnum<["global", "user", "query"]>>;
|
|
939
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
640
940
|
}, "strip", z.ZodTypeAny, {
|
|
941
|
+
type?: "query" | "user" | "global" | undefined;
|
|
641
942
|
query?: string | undefined;
|
|
642
943
|
category?: string | undefined;
|
|
643
|
-
createdBy?:
|
|
944
|
+
createdBy?: string | undefined;
|
|
644
945
|
tags?: string[] | undefined;
|
|
645
946
|
}, {
|
|
947
|
+
type?: "query" | "user" | "global" | undefined;
|
|
646
948
|
query?: string | undefined;
|
|
647
949
|
category?: string | undefined;
|
|
648
|
-
createdBy?:
|
|
950
|
+
createdBy?: string | undefined;
|
|
649
951
|
tags?: string[] | undefined;
|
|
650
952
|
}>>;
|
|
651
953
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
652
954
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
653
955
|
}, "strip", z.ZodTypeAny, {
|
|
654
956
|
id?: number | undefined;
|
|
957
|
+
type?: "query" | "user" | "global" | undefined;
|
|
655
958
|
query?: string | undefined;
|
|
656
959
|
title?: string | undefined;
|
|
657
960
|
category?: string | undefined;
|
|
658
|
-
userId?:
|
|
961
|
+
userId?: string | undefined;
|
|
659
962
|
limit?: number | undefined;
|
|
660
963
|
filters?: {
|
|
964
|
+
type?: "query" | "user" | "global" | undefined;
|
|
661
965
|
query?: string | undefined;
|
|
662
966
|
category?: string | undefined;
|
|
663
|
-
createdBy?:
|
|
967
|
+
createdBy?: string | undefined;
|
|
664
968
|
tags?: string[] | undefined;
|
|
665
969
|
} | undefined;
|
|
666
|
-
createdBy?:
|
|
667
|
-
updatedBy?:
|
|
970
|
+
createdBy?: string | undefined;
|
|
971
|
+
updatedBy?: string | undefined;
|
|
972
|
+
offset?: number | undefined;
|
|
668
973
|
tags?: string[] | undefined;
|
|
669
974
|
content?: string | undefined;
|
|
670
|
-
offset?: number | undefined;
|
|
671
975
|
}, {
|
|
672
976
|
id?: number | undefined;
|
|
977
|
+
type?: "query" | "user" | "global" | undefined;
|
|
673
978
|
query?: string | undefined;
|
|
674
979
|
title?: string | undefined;
|
|
675
980
|
category?: string | undefined;
|
|
676
|
-
userId?:
|
|
981
|
+
userId?: string | undefined;
|
|
677
982
|
limit?: number | undefined;
|
|
678
983
|
filters?: {
|
|
984
|
+
type?: "query" | "user" | "global" | undefined;
|
|
679
985
|
query?: string | undefined;
|
|
680
986
|
category?: string | undefined;
|
|
681
|
-
createdBy?:
|
|
987
|
+
createdBy?: string | undefined;
|
|
682
988
|
tags?: string[] | undefined;
|
|
683
989
|
} | undefined;
|
|
684
|
-
createdBy?:
|
|
685
|
-
updatedBy?:
|
|
990
|
+
createdBy?: string | undefined;
|
|
991
|
+
updatedBy?: string | undefined;
|
|
992
|
+
offset?: number | undefined;
|
|
686
993
|
tags?: string[] | undefined;
|
|
687
994
|
content?: string | undefined;
|
|
688
|
-
offset?: number | undefined;
|
|
689
995
|
}>>;
|
|
690
996
|
}, "strip", z.ZodTypeAny, {
|
|
691
997
|
operation: "create" | "getOne" | "update" | "delete" | "getAll" | "search" | "getByCategory" | "getByUser" | "getCategories" | "getTags";
|
|
692
998
|
data?: {
|
|
693
999
|
id?: number | undefined;
|
|
1000
|
+
type?: "query" | "user" | "global" | undefined;
|
|
694
1001
|
query?: string | undefined;
|
|
695
1002
|
title?: string | undefined;
|
|
696
1003
|
category?: string | undefined;
|
|
697
|
-
userId?:
|
|
1004
|
+
userId?: string | undefined;
|
|
698
1005
|
limit?: number | undefined;
|
|
699
1006
|
filters?: {
|
|
1007
|
+
type?: "query" | "user" | "global" | undefined;
|
|
700
1008
|
query?: string | undefined;
|
|
701
1009
|
category?: string | undefined;
|
|
702
|
-
createdBy?:
|
|
1010
|
+
createdBy?: string | undefined;
|
|
703
1011
|
tags?: string[] | undefined;
|
|
704
1012
|
} | undefined;
|
|
705
|
-
createdBy?:
|
|
706
|
-
updatedBy?:
|
|
1013
|
+
createdBy?: string | undefined;
|
|
1014
|
+
updatedBy?: string | undefined;
|
|
1015
|
+
offset?: number | undefined;
|
|
707
1016
|
tags?: string[] | undefined;
|
|
708
1017
|
content?: string | undefined;
|
|
709
|
-
offset?: number | undefined;
|
|
710
1018
|
} | undefined;
|
|
711
1019
|
}, {
|
|
712
1020
|
operation: "create" | "getOne" | "update" | "delete" | "getAll" | "search" | "getByCategory" | "getByUser" | "getCategories" | "getTags";
|
|
713
1021
|
data?: {
|
|
714
1022
|
id?: number | undefined;
|
|
1023
|
+
type?: "query" | "user" | "global" | undefined;
|
|
715
1024
|
query?: string | undefined;
|
|
716
1025
|
title?: string | undefined;
|
|
717
1026
|
category?: string | undefined;
|
|
718
|
-
userId?:
|
|
1027
|
+
userId?: string | undefined;
|
|
719
1028
|
limit?: number | undefined;
|
|
720
1029
|
filters?: {
|
|
1030
|
+
type?: "query" | "user" | "global" | undefined;
|
|
721
1031
|
query?: string | undefined;
|
|
722
1032
|
category?: string | undefined;
|
|
723
|
-
createdBy?:
|
|
1033
|
+
createdBy?: string | undefined;
|
|
724
1034
|
tags?: string[] | undefined;
|
|
725
1035
|
} | undefined;
|
|
726
|
-
createdBy?:
|
|
727
|
-
updatedBy?:
|
|
1036
|
+
createdBy?: string | undefined;
|
|
1037
|
+
updatedBy?: string | undefined;
|
|
1038
|
+
offset?: number | undefined;
|
|
728
1039
|
tags?: string[] | undefined;
|
|
729
1040
|
content?: string | undefined;
|
|
730
|
-
offset?: number | undefined;
|
|
731
1041
|
} | undefined;
|
|
732
1042
|
}>;
|
|
733
1043
|
type KbNodesRequestPayload = z.infer<typeof KbNodesRequestPayloadSchema>;
|
|
1044
|
+
interface T_RESPONSE {
|
|
1045
|
+
success: boolean;
|
|
1046
|
+
data?: any;
|
|
1047
|
+
errors: string[];
|
|
1048
|
+
}
|
|
734
1049
|
|
|
735
1050
|
/**
|
|
736
1051
|
* UserManager class to handle CRUD operations on users with file persistence
|
|
@@ -995,6 +1310,7 @@ type SystemPrompt = string | Anthropic.Messages.TextBlockParam[];
|
|
|
995
1310
|
interface LLMMessages {
|
|
996
1311
|
sys: SystemPrompt;
|
|
997
1312
|
user: string;
|
|
1313
|
+
prefill?: string;
|
|
998
1314
|
}
|
|
999
1315
|
interface LLMOptions {
|
|
1000
1316
|
model?: string;
|
|
@@ -1047,6 +1363,11 @@ declare class LLM {
|
|
|
1047
1363
|
private static _groqStream;
|
|
1048
1364
|
private static _geminiText;
|
|
1049
1365
|
private static _geminiStream;
|
|
1366
|
+
/**
|
|
1367
|
+
* Recursively strip unsupported JSON Schema properties for Gemini
|
|
1368
|
+
* Gemini doesn't support: additionalProperties, $schema, etc.
|
|
1369
|
+
*/
|
|
1370
|
+
private static _cleanSchemaForGemini;
|
|
1050
1371
|
private static _geminiStreamWithTools;
|
|
1051
1372
|
private static _openaiText;
|
|
1052
1373
|
private static _openaiStream;
|
|
@@ -1493,6 +1814,120 @@ declare const CONTEXT_CONFIG: {
|
|
|
1493
1814
|
MAX_CONVERSATION_CONTEXT_BLOCKS: number;
|
|
1494
1815
|
};
|
|
1495
1816
|
|
|
1817
|
+
/**
|
|
1818
|
+
* LLM Usage Logger - Tracks token usage, costs, and timing for all LLM API calls
|
|
1819
|
+
*/
|
|
1820
|
+
interface LLMUsageEntry {
|
|
1821
|
+
timestamp: string;
|
|
1822
|
+
requestId: string;
|
|
1823
|
+
provider: string;
|
|
1824
|
+
model: string;
|
|
1825
|
+
method: string;
|
|
1826
|
+
inputTokens: number;
|
|
1827
|
+
outputTokens: number;
|
|
1828
|
+
cacheReadTokens?: number;
|
|
1829
|
+
cacheWriteTokens?: number;
|
|
1830
|
+
totalTokens: number;
|
|
1831
|
+
costUSD: number;
|
|
1832
|
+
durationMs: number;
|
|
1833
|
+
toolCalls?: number;
|
|
1834
|
+
success: boolean;
|
|
1835
|
+
error?: string;
|
|
1836
|
+
}
|
|
1837
|
+
declare class LLMUsageLogger {
|
|
1838
|
+
private logStream;
|
|
1839
|
+
private logPath;
|
|
1840
|
+
private enabled;
|
|
1841
|
+
private sessionStats;
|
|
1842
|
+
constructor();
|
|
1843
|
+
private initLogStream;
|
|
1844
|
+
private writeHeader;
|
|
1845
|
+
/**
|
|
1846
|
+
* Calculate cost based on token usage and model
|
|
1847
|
+
*/
|
|
1848
|
+
calculateCost(model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheWriteTokens?: number): number;
|
|
1849
|
+
/**
|
|
1850
|
+
* Log an LLM API call
|
|
1851
|
+
*/
|
|
1852
|
+
log(entry: LLMUsageEntry): void;
|
|
1853
|
+
/**
|
|
1854
|
+
* Log session summary (call at end of request)
|
|
1855
|
+
*/
|
|
1856
|
+
logSessionSummary(requestContext?: string): void;
|
|
1857
|
+
/**
|
|
1858
|
+
* Reset session stats (call at start of new user request)
|
|
1859
|
+
*/
|
|
1860
|
+
resetSession(): void;
|
|
1861
|
+
/**
|
|
1862
|
+
* Reset the log file for a new request (clears previous logs)
|
|
1863
|
+
* Call this at the start of each USER_PROMPT_REQ
|
|
1864
|
+
*/
|
|
1865
|
+
resetLogFile(requestContext?: string): void;
|
|
1866
|
+
/**
|
|
1867
|
+
* Get current session stats
|
|
1868
|
+
*/
|
|
1869
|
+
getSessionStats(): {
|
|
1870
|
+
totalCalls: number;
|
|
1871
|
+
totalInputTokens: number;
|
|
1872
|
+
totalOutputTokens: number;
|
|
1873
|
+
totalCacheReadTokens: number;
|
|
1874
|
+
totalCacheWriteTokens: number;
|
|
1875
|
+
totalCostUSD: number;
|
|
1876
|
+
totalDurationMs: number;
|
|
1877
|
+
};
|
|
1878
|
+
/**
|
|
1879
|
+
* Generate a unique request ID
|
|
1880
|
+
*/
|
|
1881
|
+
generateRequestId(): string;
|
|
1882
|
+
}
|
|
1883
|
+
declare const llmUsageLogger: LLMUsageLogger;
|
|
1884
|
+
|
|
1885
|
+
/**
|
|
1886
|
+
* User Prompt Error Logger - Captures detailed errors for USER_PROMPT_REQ
|
|
1887
|
+
* Logs full error details including raw strings for parse failures
|
|
1888
|
+
*/
|
|
1889
|
+
declare class UserPromptErrorLogger {
|
|
1890
|
+
private logStream;
|
|
1891
|
+
private logPath;
|
|
1892
|
+
private enabled;
|
|
1893
|
+
private hasErrors;
|
|
1894
|
+
constructor();
|
|
1895
|
+
/**
|
|
1896
|
+
* Reset the error log file for a new request
|
|
1897
|
+
*/
|
|
1898
|
+
resetLogFile(requestContext?: string): void;
|
|
1899
|
+
/**
|
|
1900
|
+
* Log a JSON parse error with the raw string that failed
|
|
1901
|
+
*/
|
|
1902
|
+
logJsonParseError(context: string, rawString: string, error: Error): void;
|
|
1903
|
+
/**
|
|
1904
|
+
* Log a general error with full details
|
|
1905
|
+
*/
|
|
1906
|
+
logError(context: string, error: Error | string, additionalData?: Record<string, any>): void;
|
|
1907
|
+
/**
|
|
1908
|
+
* Log a SQL query error with the full query
|
|
1909
|
+
*/
|
|
1910
|
+
logSqlError(query: string, error: Error | string, params?: any[]): void;
|
|
1911
|
+
/**
|
|
1912
|
+
* Log an LLM API error
|
|
1913
|
+
*/
|
|
1914
|
+
logLlmError(provider: string, model: string, method: string, error: Error | string, requestData?: any): void;
|
|
1915
|
+
/**
|
|
1916
|
+
* Log tool execution error
|
|
1917
|
+
*/
|
|
1918
|
+
logToolError(toolName: string, toolInput: any, error: Error | string): void;
|
|
1919
|
+
/**
|
|
1920
|
+
* Write final summary if there were errors
|
|
1921
|
+
*/
|
|
1922
|
+
writeSummary(): void;
|
|
1923
|
+
/**
|
|
1924
|
+
* Check if any errors were logged
|
|
1925
|
+
*/
|
|
1926
|
+
hadErrors(): boolean;
|
|
1927
|
+
private write;
|
|
1928
|
+
}
|
|
1929
|
+
declare const userPromptErrorLogger: UserPromptErrorLogger;
|
|
1930
|
+
|
|
1496
1931
|
/**
|
|
1497
1932
|
* BM25L Reranker for hybrid semantic search
|
|
1498
1933
|
*
|
|
@@ -1621,14 +2056,710 @@ declare function rerankConversationResults<T extends {
|
|
|
1621
2056
|
bm25Score: number;
|
|
1622
2057
|
}>;
|
|
1623
2058
|
|
|
1624
|
-
|
|
2059
|
+
/**
|
|
2060
|
+
* QueryExecutionService - Handles all query execution, validation, and retry logic
|
|
2061
|
+
* Extracted from BaseLLM for better separation of concerns
|
|
2062
|
+
*/
|
|
2063
|
+
|
|
2064
|
+
/**
|
|
2065
|
+
* Context for component when requesting query fix
|
|
2066
|
+
*/
|
|
2067
|
+
interface ComponentContext {
|
|
2068
|
+
name: string;
|
|
2069
|
+
type: string;
|
|
2070
|
+
title?: string;
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Result of query validation
|
|
2074
|
+
*/
|
|
2075
|
+
interface QueryValidationResult {
|
|
2076
|
+
component: Component | null;
|
|
2077
|
+
queryKey: string;
|
|
2078
|
+
result: any;
|
|
2079
|
+
validated: boolean;
|
|
2080
|
+
}
|
|
2081
|
+
/**
|
|
2082
|
+
* Result of batch query validation
|
|
2083
|
+
*/
|
|
2084
|
+
interface BatchValidationResult {
|
|
2085
|
+
components: Component[];
|
|
2086
|
+
queryResults: Map<string, any>;
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Configuration for QueryExecutionService
|
|
2090
|
+
*/
|
|
2091
|
+
interface QueryExecutionServiceConfig {
|
|
2092
|
+
defaultLimit: number;
|
|
2093
|
+
getModelForTask: (taskType: 'simple' | 'complex') => string;
|
|
2094
|
+
getApiKey: (apiKey?: string) => string | undefined;
|
|
2095
|
+
providerName: string;
|
|
2096
|
+
}
|
|
2097
|
+
/**
|
|
2098
|
+
* QueryExecutionService handles all query-related operations
|
|
2099
|
+
*/
|
|
2100
|
+
declare class QueryExecutionService {
|
|
2101
|
+
private config;
|
|
2102
|
+
constructor(config: QueryExecutionServiceConfig);
|
|
2103
|
+
/**
|
|
2104
|
+
* Get the cache key for a query
|
|
2105
|
+
* This ensures the cache key matches what the frontend will send
|
|
2106
|
+
*/
|
|
2107
|
+
getQueryCacheKey(query: any): string;
|
|
2108
|
+
/**
|
|
2109
|
+
* Execute a query against the database
|
|
2110
|
+
* @param query - The SQL query to execute (string or object with sql/values)
|
|
2111
|
+
* @param collections - Collections object containing database execute function
|
|
2112
|
+
* @returns Object with result data and cache key
|
|
2113
|
+
*/
|
|
2114
|
+
executeQuery(query: any, collections: any): Promise<{
|
|
2115
|
+
result: any;
|
|
2116
|
+
cacheKey: string;
|
|
2117
|
+
}>;
|
|
2118
|
+
/**
|
|
2119
|
+
* Request the LLM to fix a failed SQL query
|
|
2120
|
+
* @param failedQuery - The query that failed execution
|
|
2121
|
+
* @param errorMessage - The error message from the failed execution
|
|
2122
|
+
* @param componentContext - Context about the component
|
|
2123
|
+
* @param apiKey - Optional API key
|
|
2124
|
+
* @returns Fixed query string
|
|
2125
|
+
*/
|
|
2126
|
+
requestQueryFix(failedQuery: string, errorMessage: string, componentContext: ComponentContext, apiKey?: string): Promise<string>;
|
|
2127
|
+
/**
|
|
2128
|
+
* Validate a single component's query with retry logic
|
|
2129
|
+
* @param component - The component to validate
|
|
2130
|
+
* @param collections - Collections object containing database execute function
|
|
2131
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2132
|
+
* @returns Validation result with component, query key, and result
|
|
2133
|
+
*/
|
|
2134
|
+
validateSingleQuery(component: Component, collections: any, apiKey?: string): Promise<QueryValidationResult>;
|
|
2135
|
+
/**
|
|
2136
|
+
* Validate multiple component queries in parallel
|
|
2137
|
+
* @param components - Array of components with potential queries
|
|
2138
|
+
* @param collections - Collections object containing database execute function
|
|
2139
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2140
|
+
* @returns Object with validated components and query results map
|
|
2141
|
+
*/
|
|
2142
|
+
validateComponentQueries(components: Component[], collections: any, apiKey?: string): Promise<BatchValidationResult>;
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
/**
|
|
2146
|
+
* StreamBuffer - Buffered streaming utility for smoother text delivery
|
|
2147
|
+
* Batches small chunks together and flushes at regular intervals
|
|
2148
|
+
*/
|
|
2149
|
+
type StreamCallback = (chunk: string) => void;
|
|
2150
|
+
/**
|
|
2151
|
+
* StreamBuffer class for managing buffered streaming output
|
|
2152
|
+
* Provides smooth text delivery by batching small chunks
|
|
2153
|
+
*/
|
|
2154
|
+
declare class StreamBuffer {
|
|
2155
|
+
private buffer;
|
|
2156
|
+
private flushTimer;
|
|
2157
|
+
private callback;
|
|
2158
|
+
private fullText;
|
|
2159
|
+
constructor(callback?: StreamCallback);
|
|
2160
|
+
/**
|
|
2161
|
+
* Check if the buffer has a callback configured
|
|
2162
|
+
*/
|
|
2163
|
+
hasCallback(): boolean;
|
|
2164
|
+
/**
|
|
2165
|
+
* Get all text that has been written (including already flushed)
|
|
2166
|
+
*/
|
|
2167
|
+
getFullText(): string;
|
|
2168
|
+
/**
|
|
2169
|
+
* Write a chunk to the buffer
|
|
2170
|
+
* Large chunks or chunks with newlines are flushed immediately
|
|
2171
|
+
* Small chunks are batched and flushed after a short interval
|
|
2172
|
+
*
|
|
2173
|
+
* @param chunk - Text chunk to write
|
|
2174
|
+
*/
|
|
2175
|
+
write(chunk: string): void;
|
|
2176
|
+
/**
|
|
2177
|
+
* Flush the buffer immediately
|
|
2178
|
+
* Call this before tool execution or other operations that need clean output
|
|
2179
|
+
*/
|
|
2180
|
+
flush(): void;
|
|
2181
|
+
/**
|
|
2182
|
+
* Internal flush implementation
|
|
2183
|
+
*/
|
|
2184
|
+
private flushNow;
|
|
2185
|
+
/**
|
|
2186
|
+
* Clean up resources
|
|
2187
|
+
* Call this when done with the buffer
|
|
2188
|
+
*/
|
|
2189
|
+
dispose(): void;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
/**
|
|
2193
|
+
* ToolExecutorService - Handles execution of SQL queries and external tools
|
|
2194
|
+
* Extracted from BaseLLM.generateTextResponse for better separation of concerns
|
|
2195
|
+
*/
|
|
2196
|
+
|
|
2197
|
+
/**
|
|
2198
|
+
* External tool definition
|
|
2199
|
+
*/
|
|
2200
|
+
interface ExternalTool {
|
|
2201
|
+
id: string;
|
|
2202
|
+
name: string;
|
|
2203
|
+
description?: string;
|
|
2204
|
+
/** Tool type: "source" = routed through SourceAgent, "direct" = called directly by MainAgent */
|
|
2205
|
+
toolType?: 'source' | 'direct';
|
|
2206
|
+
/** Full untruncated schema for source agent (all columns visible) */
|
|
2207
|
+
fullSchema?: string;
|
|
2208
|
+
/** Schema size tier: small (≤50 tables), medium (51-200), large (201-500), very_large (500+) */
|
|
2209
|
+
schemaTier?: string;
|
|
2210
|
+
/** Schema search function for very_large tier — keyword search over entities */
|
|
2211
|
+
schemaSearchFn?: (keywords: string[]) => string;
|
|
2212
|
+
fn: (input: any) => Promise<any>;
|
|
2213
|
+
limit?: number;
|
|
2214
|
+
outputSchema?: any;
|
|
2215
|
+
executionType?: 'immediate' | 'deferred';
|
|
2216
|
+
userProvidedData?: any;
|
|
2217
|
+
params?: Record<string, any>;
|
|
2218
|
+
}
|
|
2219
|
+
/**
|
|
2220
|
+
* Executed tool tracking info
|
|
2221
|
+
*/
|
|
2222
|
+
interface ExecutedToolInfo {
|
|
2223
|
+
id: string;
|
|
2224
|
+
name: string;
|
|
2225
|
+
params: any;
|
|
2226
|
+
result: {
|
|
2227
|
+
_totalRecords: number;
|
|
2228
|
+
_recordsShown: number;
|
|
2229
|
+
_metadata?: any;
|
|
2230
|
+
_sampleData: any[];
|
|
2231
|
+
};
|
|
2232
|
+
outputSchema?: any;
|
|
2233
|
+
sourceSchema?: string;
|
|
2234
|
+
sourceType?: string;
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
/**
|
|
2238
|
+
* Task types for model selection
|
|
2239
|
+
* - 'complex': Text generation, component matching, parameter adaptation (uses best model in balanced mode)
|
|
2240
|
+
* - 'simple': Classification, action generation (uses fast model in balanced mode)
|
|
2241
|
+
*/
|
|
2242
|
+
type TaskType = 'complex' | 'simple';
|
|
2243
|
+
interface BaseLLMConfig {
|
|
2244
|
+
model?: string;
|
|
2245
|
+
fastModel?: string;
|
|
2246
|
+
defaultLimit?: number;
|
|
2247
|
+
apiKey?: string;
|
|
2248
|
+
/**
|
|
2249
|
+
* Model selection strategy:
|
|
2250
|
+
* - 'best': Use best model for all tasks (highest quality, higher cost)
|
|
2251
|
+
* - 'fast': Use fast model for all tasks (lower quality, lower cost)
|
|
2252
|
+
* - 'balanced': Use best model for complex tasks, fast model for simple tasks (default)
|
|
2253
|
+
*/
|
|
2254
|
+
modelStrategy?: ModelStrategy;
|
|
2255
|
+
conversationSimilarityThreshold?: number;
|
|
2256
|
+
}
|
|
2257
|
+
/**
|
|
2258
|
+
* BaseLLM abstract class for AI-powered component generation and matching
|
|
2259
|
+
* Provides common functionality for all LLM providers
|
|
2260
|
+
*/
|
|
2261
|
+
declare abstract class BaseLLM {
|
|
2262
|
+
protected model: string;
|
|
2263
|
+
protected fastModel: string;
|
|
2264
|
+
protected defaultLimit: number;
|
|
2265
|
+
protected apiKey?: string;
|
|
2266
|
+
protected modelStrategy: ModelStrategy;
|
|
2267
|
+
protected conversationSimilarityThreshold: number;
|
|
2268
|
+
protected queryService: QueryExecutionService;
|
|
2269
|
+
constructor(config?: BaseLLMConfig);
|
|
2270
|
+
/**
|
|
2271
|
+
* Get the appropriate model based on task type and model strategy
|
|
2272
|
+
* @param taskType - 'complex' for text generation/matching, 'simple' for classification/actions
|
|
2273
|
+
* @returns The model string to use for this task
|
|
2274
|
+
*/
|
|
2275
|
+
protected getModelForTask(taskType: TaskType): string;
|
|
2276
|
+
/**
|
|
2277
|
+
* Set the model strategy at runtime
|
|
2278
|
+
* @param strategy - 'best', 'fast', or 'balanced'
|
|
2279
|
+
*/
|
|
2280
|
+
setModelStrategy(strategy: ModelStrategy): void;
|
|
2281
|
+
/**
|
|
2282
|
+
* Get the current model strategy
|
|
2283
|
+
* @returns The current model strategy
|
|
2284
|
+
*/
|
|
2285
|
+
getModelStrategy(): ModelStrategy;
|
|
2286
|
+
/**
|
|
2287
|
+
* Set the conversation similarity threshold at runtime
|
|
2288
|
+
* @param threshold - Value between 0 and 1 (e.g., 0.8 = 80% similarity required)
|
|
2289
|
+
*/
|
|
2290
|
+
setConversationSimilarityThreshold(threshold: number): void;
|
|
2291
|
+
/**
|
|
2292
|
+
* Get the current conversation similarity threshold
|
|
2293
|
+
* @returns The current threshold value
|
|
2294
|
+
*/
|
|
2295
|
+
getConversationSimilarityThreshold(): number;
|
|
2296
|
+
/**
|
|
2297
|
+
* Get the default model for this provider (used for complex tasks like text generation)
|
|
2298
|
+
*/
|
|
2299
|
+
protected abstract getDefaultModel(): string;
|
|
2300
|
+
/**
|
|
2301
|
+
* Get the default fast model for this provider (used for simple tasks: classification, matching, actions)
|
|
2302
|
+
* Should return a cheaper/faster model like Haiku for Anthropic
|
|
2303
|
+
*/
|
|
2304
|
+
protected abstract getDefaultFastModel(): string;
|
|
2305
|
+
/**
|
|
2306
|
+
* Get the default API key from environment
|
|
2307
|
+
*/
|
|
2308
|
+
protected abstract getDefaultApiKey(): string | undefined;
|
|
2309
|
+
/**
|
|
2310
|
+
* Get the provider name (for logging)
|
|
2311
|
+
*/
|
|
2312
|
+
protected abstract getProviderName(): string;
|
|
2313
|
+
/**
|
|
2314
|
+
* Get the API key (from instance, parameter, or environment)
|
|
2315
|
+
*/
|
|
2316
|
+
protected getApiKey(apiKey?: string): string | undefined;
|
|
2317
|
+
/**
|
|
2318
|
+
* Check if a component contains a Form (data_modification component)
|
|
2319
|
+
* Forms have hardcoded defaultValues that become stale when cached
|
|
2320
|
+
* This checks both single Form components and Forms inside MultiComponentContainer
|
|
2321
|
+
*/
|
|
2322
|
+
protected containsFormComponent(component: any): boolean;
|
|
2323
|
+
/**
|
|
2324
|
+
* Match components from text response suggestions and generate follow-up questions
|
|
2325
|
+
* Takes a text response with component suggestions (c1:type format) and matches with available components
|
|
2326
|
+
* Also generates title, description, and intelligent follow-up questions (actions) based on the analysis
|
|
2327
|
+
* All components are placed in a default MultiComponentContainer layout
|
|
2328
|
+
* @param analysisContent - The text response containing component suggestions
|
|
2329
|
+
* @param components - List of available components
|
|
2330
|
+
* @param apiKey - Optional API key
|
|
2331
|
+
* @param componentStreamCallback - Optional callback to stream primary KPI component as soon as it's identified
|
|
2332
|
+
* @returns Object containing matched components, layout title/description, and follow-up actions
|
|
2333
|
+
*/
|
|
2334
|
+
matchComponentsFromAnalysis(analysisContent: string, components: Component[], userPrompt: string, apiKey?: string, componentStreamCallback?: (component: Component) => void, deferredTools?: any[], executedTools?: any[], collections?: any, userId?: string): Promise<{
|
|
2335
|
+
components: Component[];
|
|
2336
|
+
layoutTitle: string;
|
|
2337
|
+
layoutDescription: string;
|
|
2338
|
+
actions: Action[];
|
|
2339
|
+
}>;
|
|
2340
|
+
/**
|
|
2341
|
+
* Classify user question into category and detect external tools needed
|
|
2342
|
+
* Determines if question is for data analysis, requires external tools, or needs text response
|
|
2343
|
+
*/
|
|
2344
|
+
classifyQuestionCategory(userPrompt: string, apiKey?: string, conversationHistory?: string, externalTools?: any[]): Promise<{
|
|
2345
|
+
category: 'data_analysis' | 'data_modification' | 'general';
|
|
2346
|
+
externalTools: Array<{
|
|
2347
|
+
type: string;
|
|
2348
|
+
name: string;
|
|
2349
|
+
description: string;
|
|
2350
|
+
parameters: Record<string, any>;
|
|
2351
|
+
}>;
|
|
2352
|
+
dataAnalysisType?: 'visualization' | 'calculation' | 'comparison' | 'trend';
|
|
2353
|
+
reasoning: string;
|
|
2354
|
+
confidence: number;
|
|
2355
|
+
}>;
|
|
2356
|
+
/**
|
|
2357
|
+
* Adapt UI block parameters based on current user question
|
|
2358
|
+
* Takes a matched UI block from semantic search and modifies its props to answer the new question
|
|
2359
|
+
* Also adapts the cached text response to match the new question
|
|
2360
|
+
*/
|
|
2361
|
+
adaptUIBlockParameters(currentUserPrompt: string, originalUserPrompt: string, matchedUIBlock: any, apiKey?: string, cachedTextResponse?: string): Promise<{
|
|
2362
|
+
success: boolean;
|
|
2363
|
+
adaptedComponent?: Component;
|
|
2364
|
+
adaptedTextResponse?: string;
|
|
2365
|
+
parametersChanged?: Array<{
|
|
2366
|
+
field: string;
|
|
2367
|
+
reason: string;
|
|
2368
|
+
}>;
|
|
2369
|
+
explanation: string;
|
|
2370
|
+
}>;
|
|
2371
|
+
/**
|
|
2372
|
+
* Generate text-based response for user question
|
|
2373
|
+
* This provides conversational text responses instead of component generation
|
|
2374
|
+
* Supports tool calling for query execution with automatic retry on errors (max 3 attempts)
|
|
2375
|
+
* After generating text response, if components are provided, matches suggested components
|
|
2376
|
+
*/
|
|
2377
|
+
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>;
|
|
2378
|
+
/**
|
|
2379
|
+
* Main orchestration function with semantic search and multi-step classification
|
|
2380
|
+
* NEW FLOW (Recommended):
|
|
2381
|
+
* 1. Semantic search: Check previous conversations (>60% match)
|
|
2382
|
+
* - If match found → Adapt UI block parameters and return
|
|
2383
|
+
* 2. Category classification: Determine if data_analysis, requires_external_tools, or text_response
|
|
2384
|
+
* 3. Route appropriately based on category and response mode
|
|
2385
|
+
*/
|
|
2386
|
+
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>;
|
|
2387
|
+
/**
|
|
2388
|
+
* Generate next questions that the user might ask based on the original prompt and generated component
|
|
2389
|
+
* This helps provide intelligent suggestions for follow-up queries
|
|
2390
|
+
* For general/conversational questions without components, pass textResponse instead
|
|
2391
|
+
*/
|
|
2392
|
+
generateNextQuestions(originalUserPrompt: string, component?: Component | null, componentData?: Record<string, unknown>, apiKey?: string, conversationHistory?: string, textResponse?: string): Promise<string[]>;
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
interface AnthropicLLMConfig extends BaseLLMConfig {
|
|
2396
|
+
}
|
|
2397
|
+
/**
|
|
2398
|
+
* AnthropicLLM class for handling AI-powered component generation and matching using Anthropic Claude
|
|
2399
|
+
*/
|
|
2400
|
+
declare class AnthropicLLM extends BaseLLM {
|
|
2401
|
+
constructor(config?: AnthropicLLMConfig);
|
|
2402
|
+
protected getDefaultModel(): string;
|
|
2403
|
+
protected getDefaultFastModel(): string;
|
|
2404
|
+
protected getDefaultApiKey(): string | undefined;
|
|
2405
|
+
protected getProviderName(): string;
|
|
2406
|
+
}
|
|
2407
|
+
declare const anthropicLLM: AnthropicLLM;
|
|
2408
|
+
|
|
2409
|
+
interface GroqLLMConfig extends BaseLLMConfig {
|
|
2410
|
+
}
|
|
2411
|
+
/**
|
|
2412
|
+
* GroqLLM class for handling AI-powered component generation and matching using Groq
|
|
2413
|
+
*/
|
|
2414
|
+
declare class GroqLLM extends BaseLLM {
|
|
2415
|
+
constructor(config?: GroqLLMConfig);
|
|
2416
|
+
protected getDefaultModel(): string;
|
|
2417
|
+
protected getDefaultFastModel(): string;
|
|
2418
|
+
protected getDefaultApiKey(): string | undefined;
|
|
2419
|
+
protected getProviderName(): string;
|
|
2420
|
+
}
|
|
2421
|
+
declare const groqLLM: GroqLLM;
|
|
2422
|
+
|
|
2423
|
+
interface GeminiLLMConfig extends BaseLLMConfig {
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* GeminiLLM class for handling AI-powered component generation and matching using Google Gemini
|
|
2427
|
+
*/
|
|
2428
|
+
declare class GeminiLLM extends BaseLLM {
|
|
2429
|
+
constructor(config?: GeminiLLMConfig);
|
|
2430
|
+
protected getDefaultModel(): string;
|
|
2431
|
+
protected getDefaultFastModel(): string;
|
|
2432
|
+
protected getDefaultApiKey(): string | undefined;
|
|
2433
|
+
protected getProviderName(): string;
|
|
2434
|
+
}
|
|
2435
|
+
declare const geminiLLM: GeminiLLM;
|
|
2436
|
+
|
|
2437
|
+
interface OpenAILLMConfig extends BaseLLMConfig {
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* OpenAILLM class for handling AI-powered component generation and matching using OpenAI GPT models
|
|
2441
|
+
*/
|
|
2442
|
+
declare class OpenAILLM extends BaseLLM {
|
|
2443
|
+
constructor(config?: OpenAILLMConfig);
|
|
2444
|
+
protected getDefaultModel(): string;
|
|
2445
|
+
protected getDefaultFastModel(): string;
|
|
2446
|
+
protected getDefaultApiKey(): string | undefined;
|
|
2447
|
+
protected getProviderName(): string;
|
|
2448
|
+
}
|
|
2449
|
+
declare const openaiLLM: OpenAILLM;
|
|
2450
|
+
|
|
2451
|
+
/**
|
|
2452
|
+
* Query Cache - Two separate stores with different lifetimes:
|
|
2453
|
+
*
|
|
2454
|
+
* 1. `cache` (query string → result data) — TTL-based, for avoiding re-execution of recently validated queries.
|
|
2455
|
+
* 2. `queryIdCache` (queryId → SQL) — permanent (server lifetime), because queryIds are persisted
|
|
2456
|
+
* in dashboard widgets and must remain resolvable across page reloads and idle periods.
|
|
2457
|
+
* Only the cached *data* inside a queryId entry expires; the SQL mapping itself never does.
|
|
2458
|
+
*/
|
|
2459
|
+
declare class QueryCache {
|
|
2460
|
+
private cache;
|
|
2461
|
+
private queryIdCache;
|
|
2462
|
+
private ttlMs;
|
|
2463
|
+
private cleanupInterval;
|
|
2464
|
+
constructor();
|
|
2465
|
+
/**
|
|
2466
|
+
* Set the cache TTL (Time To Live)
|
|
2467
|
+
* @param minutes - TTL in minutes (default: 10)
|
|
2468
|
+
*/
|
|
2469
|
+
setTTL(minutes: number): void;
|
|
2470
|
+
/**
|
|
2471
|
+
* Get the current TTL in minutes
|
|
2472
|
+
*/
|
|
2473
|
+
getTTL(): number;
|
|
2474
|
+
/**
|
|
2475
|
+
* Store query result in cache
|
|
2476
|
+
* Key is the exact query string (or JSON for parameterized queries)
|
|
2477
|
+
*/
|
|
2478
|
+
set(query: string, data: any): void;
|
|
2479
|
+
/**
|
|
2480
|
+
* Get cached result if exists and not expired
|
|
2481
|
+
*/
|
|
2482
|
+
get(query: string): any | null;
|
|
2483
|
+
/**
|
|
2484
|
+
* Check if query exists in cache (not expired)
|
|
2485
|
+
*/
|
|
2486
|
+
has(query: string): boolean;
|
|
2487
|
+
/**
|
|
2488
|
+
* Remove a specific query from cache
|
|
2489
|
+
*/
|
|
2490
|
+
delete(query: string): void;
|
|
2491
|
+
/**
|
|
2492
|
+
* Clear all cached entries
|
|
2493
|
+
*/
|
|
2494
|
+
clear(): void;
|
|
2495
|
+
/**
|
|
2496
|
+
* Get cache statistics
|
|
2497
|
+
*/
|
|
2498
|
+
getStats(): {
|
|
2499
|
+
size: number;
|
|
2500
|
+
queryIdCount: number;
|
|
2501
|
+
oldestEntryAge: number | null;
|
|
2502
|
+
};
|
|
2503
|
+
/**
|
|
2504
|
+
* Start periodic cleanup of expired entries.
|
|
2505
|
+
* Only cleans the data cache — queryIdCache entries are permanent (server lifetime)
|
|
2506
|
+
* because queryIds are persisted in dashboard widgets.
|
|
2507
|
+
*/
|
|
2508
|
+
private startCleanup;
|
|
2509
|
+
/**
|
|
2510
|
+
* Generate a unique query ID
|
|
2511
|
+
*/
|
|
2512
|
+
private generateQueryId;
|
|
2513
|
+
/**
|
|
2514
|
+
* Store a query by ID. Returns the generated queryId.
|
|
2515
|
+
* The query is stored server-side; only the queryId is sent to the frontend.
|
|
2516
|
+
*/
|
|
2517
|
+
storeQuery(query: any, data?: any): string;
|
|
2518
|
+
/**
|
|
2519
|
+
* Get a stored query by its ID.
|
|
2520
|
+
* The SQL mapping never expires (queryIds are persisted in dashboard widgets).
|
|
2521
|
+
* Cached data may be null if it was evicted by the cleanup interval.
|
|
2522
|
+
*/
|
|
2523
|
+
getQuery(queryId: string): {
|
|
2524
|
+
query: any;
|
|
2525
|
+
data: any;
|
|
2526
|
+
} | null;
|
|
2527
|
+
/**
|
|
2528
|
+
* Update cached data for a queryId
|
|
2529
|
+
*/
|
|
2530
|
+
setQueryData(queryId: string, data: any): void;
|
|
2531
|
+
/**
|
|
2532
|
+
* Stop cleanup interval (for graceful shutdown)
|
|
2533
|
+
*/
|
|
2534
|
+
destroy(): void;
|
|
2535
|
+
}
|
|
2536
|
+
declare const queryCache: QueryCache;
|
|
2537
|
+
|
|
2538
|
+
/**
|
|
2539
|
+
* Manages conversation history scoped per user + dashboard.
|
|
2540
|
+
* Each user-dashboard pair has its own isolated history that expires after a configurable TTL.
|
|
2541
|
+
*/
|
|
2542
|
+
declare class DashboardConversationHistory {
|
|
2543
|
+
private histories;
|
|
2544
|
+
private ttlMs;
|
|
2545
|
+
private maxEntries;
|
|
2546
|
+
private cleanupInterval;
|
|
2547
|
+
constructor();
|
|
2548
|
+
/**
|
|
2549
|
+
* Set the TTL for dashboard histories
|
|
2550
|
+
* @param minutes - TTL in minutes
|
|
2551
|
+
*/
|
|
2552
|
+
setTTL(minutes: number): void;
|
|
2553
|
+
/**
|
|
2554
|
+
* Set max entries per dashboard
|
|
2555
|
+
*/
|
|
2556
|
+
setMaxEntries(max: number): void;
|
|
2557
|
+
/**
|
|
2558
|
+
* Add a conversation entry for a user's dashboard
|
|
2559
|
+
*/
|
|
2560
|
+
addEntry(dashboardId: string, userPrompt: string, componentSummary: string, userId?: string): void;
|
|
2561
|
+
/**
|
|
2562
|
+
* Get formatted conversation history for a user's dashboard
|
|
2563
|
+
*/
|
|
2564
|
+
getHistory(dashboardId: string, userId?: string): string;
|
|
2565
|
+
/**
|
|
2566
|
+
* Clear history for a specific user's dashboard
|
|
2567
|
+
*/
|
|
2568
|
+
clearDashboard(dashboardId: string, userId?: string): void;
|
|
2569
|
+
/**
|
|
2570
|
+
* Clear all dashboard histories
|
|
2571
|
+
*/
|
|
2572
|
+
clearAll(): void;
|
|
2573
|
+
/**
|
|
2574
|
+
* Start periodic cleanup of expired histories
|
|
2575
|
+
*/
|
|
2576
|
+
private startCleanup;
|
|
2577
|
+
/**
|
|
2578
|
+
* Stop cleanup interval (for graceful shutdown)
|
|
2579
|
+
*/
|
|
2580
|
+
destroy(): void;
|
|
2581
|
+
}
|
|
2582
|
+
declare const dashboardConversationHistory: DashboardConversationHistory;
|
|
2583
|
+
|
|
2584
|
+
/**
|
|
2585
|
+
* Multi-Agent Architecture Types
|
|
2586
|
+
*
|
|
2587
|
+
* Defines interfaces for the hierarchical agent system:
|
|
2588
|
+
* - Main Agent: ONE LLM.streamWithTools() call with source agent tools
|
|
2589
|
+
* - Source Agents: independent agents that query individual data sources
|
|
2590
|
+
*
|
|
2591
|
+
* The main agent sees only source summaries. When it calls a source tool,
|
|
2592
|
+
* the SourceAgent runs independently (own LLM, own retries) and returns clean data.
|
|
2593
|
+
*/
|
|
2594
|
+
|
|
2595
|
+
/**
|
|
2596
|
+
* Per-entity detail: name, row count, and column names.
|
|
2597
|
+
* Gives the main agent enough context to route to the right source.
|
|
2598
|
+
*/
|
|
2599
|
+
interface EntityDetail {
|
|
2600
|
+
/** Entity name (table, sheet, endpoint) */
|
|
2601
|
+
name: string;
|
|
2602
|
+
/** Approximate row count */
|
|
2603
|
+
rowCount?: number;
|
|
2604
|
+
/** Column/field names */
|
|
2605
|
+
columns: string[];
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* Representation of a data source for the main agent.
|
|
2609
|
+
* Contains entity names WITH column names so the LLM can route accurately.
|
|
2610
|
+
*/
|
|
2611
|
+
interface SourceSummary {
|
|
2612
|
+
/** Source ID (matches tool ID prefix) */
|
|
2613
|
+
id: string;
|
|
2614
|
+
/** Human-readable source name */
|
|
2615
|
+
name: string;
|
|
2616
|
+
/** Source type: postgres, excel, rest_api, etc. */
|
|
2617
|
+
type: string;
|
|
2618
|
+
/** Brief description of what data this source contains */
|
|
2619
|
+
description: string;
|
|
2620
|
+
/** Detailed entity info with column names for routing */
|
|
2621
|
+
entityDetails: EntityDetail[];
|
|
2622
|
+
/** The tool ID associated with this source */
|
|
2623
|
+
toolId: string;
|
|
2624
|
+
}
|
|
2625
|
+
/**
|
|
2626
|
+
* What a source agent returns after querying its data source.
|
|
2627
|
+
* The main agent uses this to analyze and compose the final response.
|
|
2628
|
+
*/
|
|
2629
|
+
interface SourceAgentResult {
|
|
2630
|
+
/** Source ID */
|
|
2631
|
+
sourceId: string;
|
|
2632
|
+
/** Source name */
|
|
2633
|
+
sourceName: string;
|
|
2634
|
+
/** Whether the query succeeded */
|
|
2635
|
+
success: boolean;
|
|
2636
|
+
/** Result data rows */
|
|
2637
|
+
data: any[];
|
|
2638
|
+
/** Metadata about the query execution */
|
|
2639
|
+
metadata: SourceAgentMetadata;
|
|
2640
|
+
/** Tool execution info for the last successful query (backward compat) */
|
|
2641
|
+
executedTool: ExecutedToolInfo;
|
|
2642
|
+
/** All successful tool executions (primary + follow-up queries) */
|
|
2643
|
+
allExecutedTools?: ExecutedToolInfo[];
|
|
2644
|
+
/** Error message if failed */
|
|
2645
|
+
error?: string;
|
|
2646
|
+
}
|
|
2647
|
+
interface SourceAgentMetadata {
|
|
2648
|
+
/** Total rows that matched the query (before limit) */
|
|
2649
|
+
totalRowsMatched: number;
|
|
2650
|
+
/** Rows actually returned (after limit) */
|
|
2651
|
+
rowsReturned: number;
|
|
2652
|
+
/** Whether the result was truncated by the row limit */
|
|
2653
|
+
isLimited: boolean;
|
|
2654
|
+
/** The query/params that were executed */
|
|
2655
|
+
queryExecuted?: string;
|
|
2656
|
+
/** Execution time in milliseconds */
|
|
2657
|
+
executionTimeMs: number;
|
|
2658
|
+
}
|
|
2659
|
+
/**
|
|
2660
|
+
* The complete response from the multi-agent system.
|
|
2661
|
+
* Contains everything needed for text display + component generation.
|
|
2662
|
+
*/
|
|
2663
|
+
interface AgentResponse {
|
|
2664
|
+
/** Generated text response (analysis of the data) */
|
|
2665
|
+
text: string;
|
|
2666
|
+
/** All executed tools across all source agents (for component generation) */
|
|
2667
|
+
executedTools: ExecutedToolInfo[];
|
|
2668
|
+
/** Individual results from each source agent */
|
|
2669
|
+
sourceResults: SourceAgentResult[];
|
|
2670
|
+
}
|
|
2671
|
+
/**
|
|
2672
|
+
* Configuration for the multi-agent system.
|
|
2673
|
+
* Controls limits, models, and behavior.
|
|
2674
|
+
*/
|
|
2675
|
+
interface AgentConfig {
|
|
2676
|
+
/** Max rows a source agent can return (default: 50) */
|
|
2677
|
+
maxRowsPerSource: number;
|
|
2678
|
+
/** Model for the main agent (routing + analysis in one LLM call) */
|
|
2679
|
+
mainAgentModel: string;
|
|
2680
|
+
/** Model for source agent query generation */
|
|
2681
|
+
sourceAgentModel: string;
|
|
2682
|
+
/** API key for LLM calls */
|
|
2683
|
+
apiKey?: string;
|
|
2684
|
+
/** Max retry attempts per source agent */
|
|
2685
|
+
maxRetries: number;
|
|
2686
|
+
/** Max tool calling iterations for the main agent loop */
|
|
2687
|
+
maxIterations: number;
|
|
2688
|
+
/** Global knowledge base context (static, same for all users/questions — cached in system prompt) */
|
|
2689
|
+
globalKnowledgeBase?: string;
|
|
2690
|
+
/** Per-request knowledge base context (user-specific + query-matched — dynamic, not cached) */
|
|
2691
|
+
knowledgeBaseContext?: string;
|
|
2692
|
+
}
|
|
2693
|
+
/**
|
|
2694
|
+
* Default agent configuration
|
|
2695
|
+
*/
|
|
2696
|
+
declare const DEFAULT_AGENT_CONFIG: AgentConfig;
|
|
2697
|
+
|
|
2698
|
+
/**
|
|
2699
|
+
* Main Agent (Orchestrator)
|
|
2700
|
+
*
|
|
2701
|
+
* A single LLM.streamWithTools() call that handles everything:
|
|
2702
|
+
* - Routing: decides which source(s) to query based on summaries
|
|
2703
|
+
* - Querying: calls source tools (each wraps an independent SourceAgent)
|
|
2704
|
+
* - Direct tools: calls pre-built function tools directly with LLM-provided params
|
|
2705
|
+
* - Re-querying: if data is wrong/incomplete, calls tools again with modified intent
|
|
2706
|
+
* - Analysis: generates final text response from the data
|
|
2707
|
+
*
|
|
2708
|
+
* Two tool types:
|
|
2709
|
+
* - "source" tools: main agent sees summaries, SourceAgent handles SQL generation independently
|
|
2710
|
+
* - "direct" tools: main agent calls fn() directly with structured params (no SourceAgent)
|
|
2711
|
+
*/
|
|
2712
|
+
|
|
2713
|
+
declare class MainAgent {
|
|
2714
|
+
private externalTools;
|
|
2715
|
+
private config;
|
|
2716
|
+
private streamBuffer;
|
|
2717
|
+
constructor(externalTools: ExternalTool[], config: AgentConfig, streamBuffer?: StreamBuffer);
|
|
2718
|
+
/**
|
|
2719
|
+
* Handle a user question using the multi-agent system.
|
|
2720
|
+
*
|
|
2721
|
+
* This is ONE LLM.streamWithTools() call. The LLM:
|
|
2722
|
+
* 1. Sees source summaries + direct tool descriptions in system prompt
|
|
2723
|
+
* 2. Decides which tool(s) to call (routing)
|
|
2724
|
+
* 3. Source tools → SourceAgent runs independently → returns data
|
|
2725
|
+
* 4. Direct tools → fn() called directly with LLM params → returns data
|
|
2726
|
+
* 5. Generates final analysis text
|
|
2727
|
+
*/
|
|
2728
|
+
handleQuestion(userPrompt: string, apiKey?: string, conversationHistory?: string, streamCallback?: (chunk: string) => void): Promise<AgentResponse>;
|
|
2729
|
+
/**
|
|
2730
|
+
* Execute a direct tool — call fn() with LLM-provided params, no SourceAgent.
|
|
2731
|
+
*/
|
|
2732
|
+
private handleDirectTool;
|
|
2733
|
+
/**
|
|
2734
|
+
* Build the main agent's system prompt with source summaries and direct tool descriptions.
|
|
2735
|
+
*/
|
|
2736
|
+
private buildSystemPrompt;
|
|
2737
|
+
/**
|
|
2738
|
+
* Build tool definitions for source tools — summary-only descriptions.
|
|
2739
|
+
* The full schema is inside the SourceAgent which runs independently.
|
|
2740
|
+
*/
|
|
2741
|
+
private buildSourceToolDefinitions;
|
|
2742
|
+
/**
|
|
2743
|
+
* Build tool definitions for direct tools — expose their actual params.
|
|
2744
|
+
* These are called directly by the main agent LLM, no SourceAgent.
|
|
2745
|
+
*/
|
|
2746
|
+
private buildDirectToolDefinitions;
|
|
2747
|
+
/**
|
|
2748
|
+
* Format a source agent's result as a clean string for the main agent LLM.
|
|
2749
|
+
*/
|
|
2750
|
+
private formatResultForMainAgent;
|
|
2751
|
+
/**
|
|
2752
|
+
* Get source summaries (for external inspection/debugging).
|
|
2753
|
+
*/
|
|
2754
|
+
getSourceSummaries(): SourceSummary[];
|
|
2755
|
+
}
|
|
2756
|
+
|
|
1625
2757
|
type MessageTypeHandler = (message: IncomingMessage) => void | Promise<void>;
|
|
1626
2758
|
declare class SuperatomSDK {
|
|
1627
2759
|
private ws;
|
|
1628
2760
|
private url;
|
|
1629
2761
|
private apiKey?;
|
|
1630
2762
|
private projectId;
|
|
1631
|
-
private userId;
|
|
1632
2763
|
private type;
|
|
1633
2764
|
private bundleDir;
|
|
1634
2765
|
private messageHandlers;
|
|
@@ -1644,9 +2775,19 @@ declare class SuperatomSDK {
|
|
|
1644
2775
|
private geminiApiKey;
|
|
1645
2776
|
private openaiApiKey;
|
|
1646
2777
|
private llmProviders;
|
|
2778
|
+
private databaseType;
|
|
2779
|
+
private modelStrategy;
|
|
2780
|
+
private mainAgentModel;
|
|
2781
|
+
private sourceAgentModel;
|
|
2782
|
+
private dashCompModels?;
|
|
2783
|
+
private conversationSimilarityThreshold;
|
|
1647
2784
|
private userManager;
|
|
1648
2785
|
private dashboardManager;
|
|
1649
2786
|
private reportManager;
|
|
2787
|
+
private pingInterval;
|
|
2788
|
+
private lastPong;
|
|
2789
|
+
private readonly PING_INTERVAL_MS;
|
|
2790
|
+
private readonly PONG_TIMEOUT_MS;
|
|
1650
2791
|
constructor(config: SuperatomSDKConfig);
|
|
1651
2792
|
/**
|
|
1652
2793
|
* Initialize PromptLoader and load prompts into memory
|
|
@@ -1686,9 +2827,11 @@ declare class SuperatomSDK {
|
|
|
1686
2827
|
*/
|
|
1687
2828
|
private handleMessage;
|
|
1688
2829
|
/**
|
|
1689
|
-
* Send a message to the Superatom service
|
|
2830
|
+
* Send a message to the Superatom service.
|
|
2831
|
+
* Returns true if the message was sent, false if the WebSocket is not connected.
|
|
2832
|
+
* Does NOT throw on closed connections — callers can check the return value if needed.
|
|
1690
2833
|
*/
|
|
1691
|
-
send(message: Message):
|
|
2834
|
+
send(message: Message): boolean;
|
|
1692
2835
|
/**
|
|
1693
2836
|
* Register a message handler to receive all messages
|
|
1694
2837
|
*/
|
|
@@ -1714,6 +2857,19 @@ declare class SuperatomSDK {
|
|
|
1714
2857
|
*/
|
|
1715
2858
|
addCollection<TParams = any, TResult = any>(collectionName: string, operation: CollectionOperation | string, handler: CollectionHandler<TParams, TResult>): void;
|
|
1716
2859
|
private handleReconnect;
|
|
2860
|
+
/**
|
|
2861
|
+
* Start heartbeat to keep WebSocket connection alive
|
|
2862
|
+
* Sends PING every 3 minutes to prevent idle timeout from cloud infrastructure
|
|
2863
|
+
*/
|
|
2864
|
+
private startHeartbeat;
|
|
2865
|
+
/**
|
|
2866
|
+
* Stop the heartbeat interval
|
|
2867
|
+
*/
|
|
2868
|
+
private stopHeartbeat;
|
|
2869
|
+
/**
|
|
2870
|
+
* Handle PONG response from server
|
|
2871
|
+
*/
|
|
2872
|
+
private handlePong;
|
|
1717
2873
|
private storeComponents;
|
|
1718
2874
|
/**
|
|
1719
2875
|
* Set tools for the SDK instance
|
|
@@ -1723,6 +2879,34 @@ declare class SuperatomSDK {
|
|
|
1723
2879
|
* Get the stored tools
|
|
1724
2880
|
*/
|
|
1725
2881
|
getTools(): Tool$1[];
|
|
2882
|
+
/**
|
|
2883
|
+
* Apply model strategy to all LLM provider singletons
|
|
2884
|
+
* @param strategy - 'best', 'fast', or 'balanced'
|
|
2885
|
+
*/
|
|
2886
|
+
private applyModelStrategy;
|
|
2887
|
+
/**
|
|
2888
|
+
* Set model strategy at runtime
|
|
2889
|
+
* @param strategy - 'best', 'fast', or 'balanced'
|
|
2890
|
+
*/
|
|
2891
|
+
setModelStrategy(strategy: ModelStrategy): void;
|
|
2892
|
+
/**
|
|
2893
|
+
* Get current model strategy
|
|
2894
|
+
*/
|
|
2895
|
+
getModelStrategy(): ModelStrategy;
|
|
2896
|
+
/**
|
|
2897
|
+
* Apply conversation similarity threshold to all LLM provider singletons
|
|
2898
|
+
* @param threshold - Value between 0 and 1 (e.g., 0.8 = 80% similarity required)
|
|
2899
|
+
*/
|
|
2900
|
+
private applyConversationSimilarityThreshold;
|
|
2901
|
+
/**
|
|
2902
|
+
* Set conversation similarity threshold at runtime
|
|
2903
|
+
* @param threshold - Value between 0 and 1 (e.g., 0.8 = 80% similarity required)
|
|
2904
|
+
*/
|
|
2905
|
+
setConversationSimilarityThreshold(threshold: number): void;
|
|
2906
|
+
/**
|
|
2907
|
+
* Get current conversation similarity threshold
|
|
2908
|
+
*/
|
|
2909
|
+
getConversationSimilarityThreshold(): number;
|
|
1726
2910
|
}
|
|
1727
2911
|
|
|
1728
|
-
export { type Action, BM25L, type BM25LOptions, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LogLevel, type Message, type
|
|
2912
|
+
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, SuperatomSDK, type SuperatomSDKConfig, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, type ToolOutputSchema, UIBlock, UILogCollector, type User, UserManager, type UsersData, anthropicLLM, dashboardConversationHistory, geminiLLM, groqLLM, hybridRerank, llmUsageLogger, logger, openaiLLM, queryCache, rerankChromaResults, rerankConversationResults, userPromptErrorLogger };
|