@superatomai/sdk-node 0.0.4-mds → 0.0.4-s
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/README.md +942 -942
- package/dist/index.d.mts +888 -53
- package/dist/index.d.ts +888 -53
- package/dist/index.js +6307 -1615
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5510 -814
- package/dist/index.mjs.map +1 -1
- package/dist/userResponse/scripts/script-bootstrap.d.mts +2 -0
- package/dist/userResponse/scripts/script-bootstrap.d.ts +2 -0
- package/dist/userResponse/scripts/script-bootstrap.js +253 -0
- package/dist/userResponse/scripts/script-bootstrap.js.map +1 -0
- package/dist/userResponse/scripts/script-bootstrap.mjs +251 -0
- package/dist/userResponse/scripts/script-bootstrap.mjs.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -741,6 +741,10 @@ declare const ToolSchema: z.ZodObject<{
|
|
|
741
741
|
id: z.ZodString;
|
|
742
742
|
name: z.ZodString;
|
|
743
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>;
|
|
744
748
|
params: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
745
749
|
fn: z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodAny>;
|
|
746
750
|
outputSchema: z.ZodOptional<z.ZodObject<{
|
|
@@ -773,12 +777,22 @@ declare const ToolSchema: z.ZodObject<{
|
|
|
773
777
|
description: string;
|
|
774
778
|
}[];
|
|
775
779
|
}>>;
|
|
780
|
+
/** Cache policy. `false` = never cache (live data, write ops). Mirrors HTTP `Cache-Control: no-store`. */
|
|
781
|
+
cache: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodObject<{
|
|
782
|
+
ttlMs: z.ZodOptional<z.ZodNumber>;
|
|
783
|
+
}, "strip", z.ZodTypeAny, {
|
|
784
|
+
ttlMs?: number | undefined;
|
|
785
|
+
}, {
|
|
786
|
+
ttlMs?: number | undefined;
|
|
787
|
+
}>]>>;
|
|
776
788
|
}, "strip", z.ZodTypeAny, {
|
|
777
789
|
id: string;
|
|
778
790
|
params: Record<string, string>;
|
|
779
791
|
name: string;
|
|
780
792
|
description: string;
|
|
781
793
|
fn: (args_0: any, ...args: unknown[]) => any;
|
|
794
|
+
toolType?: "source" | "direct" | undefined;
|
|
795
|
+
fullSchema?: string | undefined;
|
|
782
796
|
outputSchema?: {
|
|
783
797
|
description: string;
|
|
784
798
|
fields: {
|
|
@@ -787,12 +801,17 @@ declare const ToolSchema: z.ZodObject<{
|
|
|
787
801
|
description: string;
|
|
788
802
|
}[];
|
|
789
803
|
} | undefined;
|
|
804
|
+
cache?: false | {
|
|
805
|
+
ttlMs?: number | undefined;
|
|
806
|
+
} | undefined;
|
|
790
807
|
}, {
|
|
791
808
|
id: string;
|
|
792
809
|
params: Record<string, string>;
|
|
793
810
|
name: string;
|
|
794
811
|
description: string;
|
|
795
812
|
fn: (args_0: any, ...args: unknown[]) => any;
|
|
813
|
+
toolType?: "source" | "direct" | undefined;
|
|
814
|
+
fullSchema?: string | undefined;
|
|
796
815
|
outputSchema?: {
|
|
797
816
|
description: string;
|
|
798
817
|
fields: {
|
|
@@ -801,6 +820,9 @@ declare const ToolSchema: z.ZodObject<{
|
|
|
801
820
|
description: string;
|
|
802
821
|
}[];
|
|
803
822
|
} | undefined;
|
|
823
|
+
cache?: false | {
|
|
824
|
+
ttlMs?: number | undefined;
|
|
825
|
+
} | undefined;
|
|
804
826
|
}>;
|
|
805
827
|
type Tool$1 = z.infer<typeof ToolSchema>;
|
|
806
828
|
type CollectionOperation = 'getMany' | 'getOne' | 'query' | 'mutation' | 'updateOne' | 'deleteOne' | 'createOne';
|
|
@@ -852,6 +874,18 @@ interface SuperatomSDKConfig {
|
|
|
852
874
|
* - 'balanced': Use best model for complex tasks, fast model for simple tasks (default)
|
|
853
875
|
*/
|
|
854
876
|
modelStrategy?: ModelStrategy;
|
|
877
|
+
/**
|
|
878
|
+
* Model for the main agent (routing + analysis).
|
|
879
|
+
* Format: "provider/model-name" (e.g., "anthropic/claude-haiku-4-5-20251001")
|
|
880
|
+
* If not set, uses the provider's default model.
|
|
881
|
+
*/
|
|
882
|
+
mainAgentModel?: string;
|
|
883
|
+
/**
|
|
884
|
+
* Model for source agents (per-source query generation).
|
|
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
|
+
sourceAgentModel?: string;
|
|
855
889
|
/**
|
|
856
890
|
* Separate model configuration for DASH_COMP flow (dashboard component picking)
|
|
857
891
|
* If not provided, falls back to provider-based model selection
|
|
@@ -870,6 +904,12 @@ interface SuperatomSDKConfig {
|
|
|
870
904
|
* Default: 5 minutes
|
|
871
905
|
*/
|
|
872
906
|
queryCacheTTL?: number;
|
|
907
|
+
/**
|
|
908
|
+
* Dashboard conversation history TTL (Time To Live) in minutes
|
|
909
|
+
* Per-dashboard conversation histories expire after this duration
|
|
910
|
+
* Default: 30 minutes
|
|
911
|
+
*/
|
|
912
|
+
dashboardHistoryTTL?: number;
|
|
873
913
|
}
|
|
874
914
|
|
|
875
915
|
declare const KbNodesQueryFiltersSchema: z.ZodObject<{
|
|
@@ -877,18 +917,18 @@ declare const KbNodesQueryFiltersSchema: z.ZodObject<{
|
|
|
877
917
|
category: z.ZodOptional<z.ZodString>;
|
|
878
918
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
879
919
|
type: z.ZodOptional<z.ZodEnum<["global", "user", "query"]>>;
|
|
880
|
-
createdBy: z.ZodOptional<z.
|
|
920
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
881
921
|
}, "strip", z.ZodTypeAny, {
|
|
882
922
|
type?: "query" | "user" | "global" | undefined;
|
|
883
923
|
query?: string | undefined;
|
|
884
924
|
category?: string | undefined;
|
|
885
|
-
createdBy?:
|
|
925
|
+
createdBy?: string | undefined;
|
|
886
926
|
tags?: string[] | undefined;
|
|
887
927
|
}, {
|
|
888
928
|
type?: "query" | "user" | "global" | undefined;
|
|
889
929
|
query?: string | undefined;
|
|
890
930
|
category?: string | undefined;
|
|
891
|
-
createdBy?:
|
|
931
|
+
createdBy?: string | undefined;
|
|
892
932
|
tags?: string[] | undefined;
|
|
893
933
|
}>;
|
|
894
934
|
type KbNodesQueryFilters = z.infer<typeof KbNodesQueryFiltersSchema>;
|
|
@@ -901,27 +941,27 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
|
|
|
901
941
|
category: z.ZodOptional<z.ZodString>;
|
|
902
942
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
903
943
|
type: z.ZodOptional<z.ZodEnum<["global", "user", "query"]>>;
|
|
904
|
-
createdBy: z.ZodOptional<z.
|
|
905
|
-
updatedBy: z.ZodOptional<z.
|
|
906
|
-
userId: z.ZodOptional<z.
|
|
944
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
945
|
+
updatedBy: z.ZodOptional<z.ZodString>;
|
|
946
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
907
947
|
query: z.ZodOptional<z.ZodString>;
|
|
908
948
|
filters: z.ZodOptional<z.ZodObject<{
|
|
909
949
|
query: z.ZodOptional<z.ZodString>;
|
|
910
950
|
category: z.ZodOptional<z.ZodString>;
|
|
911
951
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
912
952
|
type: z.ZodOptional<z.ZodEnum<["global", "user", "query"]>>;
|
|
913
|
-
createdBy: z.ZodOptional<z.
|
|
953
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
914
954
|
}, "strip", z.ZodTypeAny, {
|
|
915
955
|
type?: "query" | "user" | "global" | undefined;
|
|
916
956
|
query?: string | undefined;
|
|
917
957
|
category?: string | undefined;
|
|
918
|
-
createdBy?:
|
|
958
|
+
createdBy?: string | undefined;
|
|
919
959
|
tags?: string[] | undefined;
|
|
920
960
|
}, {
|
|
921
961
|
type?: "query" | "user" | "global" | undefined;
|
|
922
962
|
query?: string | undefined;
|
|
923
963
|
category?: string | undefined;
|
|
924
|
-
createdBy?:
|
|
964
|
+
createdBy?: string | undefined;
|
|
925
965
|
tags?: string[] | undefined;
|
|
926
966
|
}>>;
|
|
927
967
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
@@ -932,17 +972,17 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
|
|
|
932
972
|
query?: string | undefined;
|
|
933
973
|
title?: string | undefined;
|
|
934
974
|
category?: string | undefined;
|
|
935
|
-
userId?:
|
|
975
|
+
userId?: string | undefined;
|
|
936
976
|
limit?: number | undefined;
|
|
937
977
|
filters?: {
|
|
938
978
|
type?: "query" | "user" | "global" | undefined;
|
|
939
979
|
query?: string | undefined;
|
|
940
980
|
category?: string | undefined;
|
|
941
|
-
createdBy?:
|
|
981
|
+
createdBy?: string | undefined;
|
|
942
982
|
tags?: string[] | undefined;
|
|
943
983
|
} | undefined;
|
|
944
|
-
createdBy?:
|
|
945
|
-
updatedBy?:
|
|
984
|
+
createdBy?: string | undefined;
|
|
985
|
+
updatedBy?: string | undefined;
|
|
946
986
|
offset?: number | undefined;
|
|
947
987
|
tags?: string[] | undefined;
|
|
948
988
|
content?: string | undefined;
|
|
@@ -952,17 +992,17 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
|
|
|
952
992
|
query?: string | undefined;
|
|
953
993
|
title?: string | undefined;
|
|
954
994
|
category?: string | undefined;
|
|
955
|
-
userId?:
|
|
995
|
+
userId?: string | undefined;
|
|
956
996
|
limit?: number | undefined;
|
|
957
997
|
filters?: {
|
|
958
998
|
type?: "query" | "user" | "global" | undefined;
|
|
959
999
|
query?: string | undefined;
|
|
960
1000
|
category?: string | undefined;
|
|
961
|
-
createdBy?:
|
|
1001
|
+
createdBy?: string | undefined;
|
|
962
1002
|
tags?: string[] | undefined;
|
|
963
1003
|
} | undefined;
|
|
964
|
-
createdBy?:
|
|
965
|
-
updatedBy?:
|
|
1004
|
+
createdBy?: string | undefined;
|
|
1005
|
+
updatedBy?: string | undefined;
|
|
966
1006
|
offset?: number | undefined;
|
|
967
1007
|
tags?: string[] | undefined;
|
|
968
1008
|
content?: string | undefined;
|
|
@@ -975,17 +1015,17 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
|
|
|
975
1015
|
query?: string | undefined;
|
|
976
1016
|
title?: string | undefined;
|
|
977
1017
|
category?: string | undefined;
|
|
978
|
-
userId?:
|
|
1018
|
+
userId?: string | undefined;
|
|
979
1019
|
limit?: number | undefined;
|
|
980
1020
|
filters?: {
|
|
981
1021
|
type?: "query" | "user" | "global" | undefined;
|
|
982
1022
|
query?: string | undefined;
|
|
983
1023
|
category?: string | undefined;
|
|
984
|
-
createdBy?:
|
|
1024
|
+
createdBy?: string | undefined;
|
|
985
1025
|
tags?: string[] | undefined;
|
|
986
1026
|
} | undefined;
|
|
987
|
-
createdBy?:
|
|
988
|
-
updatedBy?:
|
|
1027
|
+
createdBy?: string | undefined;
|
|
1028
|
+
updatedBy?: string | undefined;
|
|
989
1029
|
offset?: number | undefined;
|
|
990
1030
|
tags?: string[] | undefined;
|
|
991
1031
|
content?: string | undefined;
|
|
@@ -998,17 +1038,17 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
|
|
|
998
1038
|
query?: string | undefined;
|
|
999
1039
|
title?: string | undefined;
|
|
1000
1040
|
category?: string | undefined;
|
|
1001
|
-
userId?:
|
|
1041
|
+
userId?: string | undefined;
|
|
1002
1042
|
limit?: number | undefined;
|
|
1003
1043
|
filters?: {
|
|
1004
1044
|
type?: "query" | "user" | "global" | undefined;
|
|
1005
1045
|
query?: string | undefined;
|
|
1006
1046
|
category?: string | undefined;
|
|
1007
|
-
createdBy?:
|
|
1047
|
+
createdBy?: string | undefined;
|
|
1008
1048
|
tags?: string[] | undefined;
|
|
1009
1049
|
} | undefined;
|
|
1010
|
-
createdBy?:
|
|
1011
|
-
updatedBy?:
|
|
1050
|
+
createdBy?: string | undefined;
|
|
1051
|
+
updatedBy?: string | undefined;
|
|
1012
1052
|
offset?: number | undefined;
|
|
1013
1053
|
tags?: string[] | undefined;
|
|
1014
1054
|
content?: string | undefined;
|
|
@@ -1280,6 +1320,715 @@ declare class ReportManager {
|
|
|
1280
1320
|
getReportCount(): number;
|
|
1281
1321
|
}
|
|
1282
1322
|
|
|
1323
|
+
/**
|
|
1324
|
+
* StreamBuffer - Buffered streaming utility for smoother text delivery
|
|
1325
|
+
* Batches small chunks together and flushes at regular intervals
|
|
1326
|
+
*/
|
|
1327
|
+
type StreamCallback = (chunk: string) => void;
|
|
1328
|
+
/**
|
|
1329
|
+
* StreamBuffer class for managing buffered streaming output
|
|
1330
|
+
* Provides smooth text delivery by batching small chunks
|
|
1331
|
+
*/
|
|
1332
|
+
declare class StreamBuffer {
|
|
1333
|
+
private buffer;
|
|
1334
|
+
private flushTimer;
|
|
1335
|
+
private callback;
|
|
1336
|
+
private fullText;
|
|
1337
|
+
constructor(callback?: StreamCallback);
|
|
1338
|
+
/**
|
|
1339
|
+
* Check if the buffer has a callback configured
|
|
1340
|
+
*/
|
|
1341
|
+
hasCallback(): boolean;
|
|
1342
|
+
/**
|
|
1343
|
+
* Get all text that has been written (including already flushed)
|
|
1344
|
+
*/
|
|
1345
|
+
getFullText(): string;
|
|
1346
|
+
/**
|
|
1347
|
+
* Write a chunk to the buffer
|
|
1348
|
+
* Large chunks or chunks with newlines are flushed immediately
|
|
1349
|
+
* Small chunks are batched and flushed after a short interval
|
|
1350
|
+
*
|
|
1351
|
+
* @param chunk - Text chunk to write
|
|
1352
|
+
*/
|
|
1353
|
+
write(chunk: string): void;
|
|
1354
|
+
/**
|
|
1355
|
+
* Flush the buffer immediately
|
|
1356
|
+
* Call this before tool execution or other operations that need clean output
|
|
1357
|
+
*/
|
|
1358
|
+
flush(): void;
|
|
1359
|
+
/**
|
|
1360
|
+
* Internal flush implementation
|
|
1361
|
+
*/
|
|
1362
|
+
private flushNow;
|
|
1363
|
+
/**
|
|
1364
|
+
* Clean up resources
|
|
1365
|
+
* Call this when done with the buffer
|
|
1366
|
+
*/
|
|
1367
|
+
dispose(): void;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* ToolExecutorService - Handles execution of SQL queries and external tools
|
|
1372
|
+
* Extracted from BaseLLM.generateTextResponse for better separation of concerns
|
|
1373
|
+
*/
|
|
1374
|
+
|
|
1375
|
+
/**
|
|
1376
|
+
* External tool definition
|
|
1377
|
+
*/
|
|
1378
|
+
interface ExternalTool {
|
|
1379
|
+
id: string;
|
|
1380
|
+
name: string;
|
|
1381
|
+
description?: string;
|
|
1382
|
+
/** Tool type: "source" = routed through SourceAgent, "direct" = called directly by MainAgent */
|
|
1383
|
+
toolType?: 'source' | 'direct';
|
|
1384
|
+
/** Full untruncated schema for source agent (all columns visible) */
|
|
1385
|
+
fullSchema?: string;
|
|
1386
|
+
/** Schema size tier: small (≤50 tables), medium (51-200), large (201-500), very_large (500+) */
|
|
1387
|
+
schemaTier?: string;
|
|
1388
|
+
/** Schema search function for very_large tier — keyword search over entities */
|
|
1389
|
+
schemaSearchFn?: (keywords: string[]) => string;
|
|
1390
|
+
fn: (input: any) => Promise<any>;
|
|
1391
|
+
limit?: number;
|
|
1392
|
+
outputSchema?: any;
|
|
1393
|
+
executionType?: 'immediate' | 'deferred';
|
|
1394
|
+
userProvidedData?: any;
|
|
1395
|
+
params?: Record<string, any>;
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* Executed tool tracking info
|
|
1399
|
+
*/
|
|
1400
|
+
interface ExecutedToolInfo {
|
|
1401
|
+
id: string;
|
|
1402
|
+
name: string;
|
|
1403
|
+
params: any;
|
|
1404
|
+
result: {
|
|
1405
|
+
_totalRecords: number;
|
|
1406
|
+
_recordsShown: number;
|
|
1407
|
+
_metadata?: any;
|
|
1408
|
+
_sampleData: any[];
|
|
1409
|
+
};
|
|
1410
|
+
outputSchema?: any;
|
|
1411
|
+
sourceSchema?: string;
|
|
1412
|
+
sourceType?: string;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* Multi-Agent Architecture Types
|
|
1417
|
+
*
|
|
1418
|
+
* Defines interfaces for the hierarchical agent system:
|
|
1419
|
+
* - Main Agent: ONE LLM.streamWithTools() call with source agent tools
|
|
1420
|
+
* - Source Agents: independent agents that query individual data sources
|
|
1421
|
+
*
|
|
1422
|
+
* The main agent sees only source summaries. When it calls a source tool,
|
|
1423
|
+
* the SourceAgent runs independently (own LLM, own retries) and returns clean data.
|
|
1424
|
+
*/
|
|
1425
|
+
|
|
1426
|
+
/**
|
|
1427
|
+
* Per-entity detail: name, row count, and column names.
|
|
1428
|
+
* Gives the main agent enough context to route to the right source.
|
|
1429
|
+
*/
|
|
1430
|
+
interface EntityDetail {
|
|
1431
|
+
/** Entity name (table, sheet, endpoint) */
|
|
1432
|
+
name: string;
|
|
1433
|
+
/** Approximate row count */
|
|
1434
|
+
rowCount?: number;
|
|
1435
|
+
/** Column/field names */
|
|
1436
|
+
columns: string[];
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Representation of a data source for the main agent.
|
|
1440
|
+
* Contains entity names WITH column names so the LLM can route accurately.
|
|
1441
|
+
*/
|
|
1442
|
+
interface SourceSummary {
|
|
1443
|
+
/** Source ID (matches tool ID prefix) */
|
|
1444
|
+
id: string;
|
|
1445
|
+
/** Human-readable source name */
|
|
1446
|
+
name: string;
|
|
1447
|
+
/** Source type: postgres, excel, rest_api, etc. */
|
|
1448
|
+
type: string;
|
|
1449
|
+
/** Brief description of what data this source contains */
|
|
1450
|
+
description: string;
|
|
1451
|
+
/** Detailed entity info with column names for routing */
|
|
1452
|
+
entityDetails: EntityDetail[];
|
|
1453
|
+
/** The tool ID associated with this source */
|
|
1454
|
+
toolId: string;
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* What a source agent returns after querying its data source.
|
|
1458
|
+
* The main agent uses this to analyze and compose the final response.
|
|
1459
|
+
*/
|
|
1460
|
+
interface SourceAgentResult {
|
|
1461
|
+
/** Source ID */
|
|
1462
|
+
sourceId: string;
|
|
1463
|
+
/** Source name */
|
|
1464
|
+
sourceName: string;
|
|
1465
|
+
/** Whether the query succeeded */
|
|
1466
|
+
success: boolean;
|
|
1467
|
+
/** Result data rows */
|
|
1468
|
+
data: any[];
|
|
1469
|
+
/** Metadata about the query execution */
|
|
1470
|
+
metadata: SourceAgentMetadata;
|
|
1471
|
+
/** Tool execution info for the last successful query (backward compat) */
|
|
1472
|
+
executedTool: ExecutedToolInfo;
|
|
1473
|
+
/** All successful tool executions (primary + follow-up queries) */
|
|
1474
|
+
allExecutedTools?: ExecutedToolInfo[];
|
|
1475
|
+
/** Error message if failed */
|
|
1476
|
+
error?: string;
|
|
1477
|
+
}
|
|
1478
|
+
interface SourceAgentMetadata {
|
|
1479
|
+
/** Total rows that matched the query (before limit) */
|
|
1480
|
+
totalRowsMatched: number;
|
|
1481
|
+
/** Rows actually returned (after limit) */
|
|
1482
|
+
rowsReturned: number;
|
|
1483
|
+
/** Whether the result was truncated by the row limit */
|
|
1484
|
+
isLimited: boolean;
|
|
1485
|
+
/** The query/params that were executed */
|
|
1486
|
+
queryExecuted?: string;
|
|
1487
|
+
/** Execution time in milliseconds */
|
|
1488
|
+
executionTimeMs: number;
|
|
1489
|
+
}
|
|
1490
|
+
/**
|
|
1491
|
+
* A pre-built, multi-step UI flow registered with the SDK.
|
|
1492
|
+
*
|
|
1493
|
+
* When the main agent decides a user's question matches a workflow's whenToUse
|
|
1494
|
+
* trigger, it picks the workflow instead of running source agents / generating
|
|
1495
|
+
* dashboard components. The LLM extracts the workflow's required props from the
|
|
1496
|
+
* prompt (using `propsSchema` as the tool input_schema) and the SDK returns the
|
|
1497
|
+
* workflow component directly — no analysis text, no chart generation. The
|
|
1498
|
+
* frontend renders the registered workflow component with the LLM-extracted
|
|
1499
|
+
* props.
|
|
1500
|
+
*/
|
|
1501
|
+
interface WorkflowDescriptor {
|
|
1502
|
+
/** Unique workflow id (used as the LLM tool name) */
|
|
1503
|
+
id: string;
|
|
1504
|
+
/** Component name on the frontend (matches the registered React component) */
|
|
1505
|
+
name: string;
|
|
1506
|
+
/** Short human-readable description of what this workflow does */
|
|
1507
|
+
description: string;
|
|
1508
|
+
/**
|
|
1509
|
+
* 1–2 sentence trigger condition. The LLM uses this to decide if the
|
|
1510
|
+
* user's prompt matches this workflow. Be specific — e.g.
|
|
1511
|
+
* "User wants to *initiate* an inventory transfer (review + submit POs),
|
|
1512
|
+
* not just see analysis or charts."
|
|
1513
|
+
*/
|
|
1514
|
+
whenToUse: string;
|
|
1515
|
+
/**
|
|
1516
|
+
* JSON-schema-style description of the props the workflow needs. Becomes
|
|
1517
|
+
* the LLM tool's input_schema, so the model fills these from the prompt.
|
|
1518
|
+
* Use the same shape as `params` on direct tools — string descriptors with
|
|
1519
|
+
* an optional "(optional)" suffix.
|
|
1520
|
+
*
|
|
1521
|
+
* Example:
|
|
1522
|
+
* ```
|
|
1523
|
+
* {
|
|
1524
|
+
* selectedStore: 'object — { id, name } of the source branch',
|
|
1525
|
+
* minROI: 'number (optional) — only show transfers with ROI ≥ this',
|
|
1526
|
+
* }
|
|
1527
|
+
* ```
|
|
1528
|
+
*/
|
|
1529
|
+
propsSchema: Record<string, string>;
|
|
1530
|
+
/**
|
|
1531
|
+
* Optional: static prop defaults merged with LLM-extracted props before
|
|
1532
|
+
* the component is returned. Useful for things like the embedded
|
|
1533
|
+
* `externalTool` config that the workflow uses to fetch its own data.
|
|
1534
|
+
*/
|
|
1535
|
+
defaultProps?: Record<string, any>;
|
|
1536
|
+
}
|
|
1537
|
+
/**
|
|
1538
|
+
* The workflow selection captured during a routing call.
|
|
1539
|
+
* Set on AgentResponse when the LLM picks a workflow tool.
|
|
1540
|
+
*/
|
|
1541
|
+
interface SelectedWorkflow {
|
|
1542
|
+
/** Component name (matches WorkflowDescriptor.name) */
|
|
1543
|
+
name: string;
|
|
1544
|
+
/** Props extracted from the prompt + merged with workflow.defaultProps */
|
|
1545
|
+
props: Record<string, any>;
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* The complete response from the multi-agent system.
|
|
1549
|
+
* Contains everything needed for text display + component generation.
|
|
1550
|
+
*/
|
|
1551
|
+
interface AgentResponse {
|
|
1552
|
+
/** Generated text response (analysis of the data) */
|
|
1553
|
+
text: string;
|
|
1554
|
+
/** All executed tools across all source agents (for component generation) */
|
|
1555
|
+
executedTools: ExecutedToolInfo[];
|
|
1556
|
+
/** Individual results from each source agent */
|
|
1557
|
+
sourceResults: SourceAgentResult[];
|
|
1558
|
+
/**
|
|
1559
|
+
* Populated when MainAgent wrote AND successfully executed a script during its turn.
|
|
1560
|
+
* Caller (agent-user-response.ts) persists it via ScriptStore.save().
|
|
1561
|
+
* Absent when MainAgent didn't write one (trivial question / all attempts failed).
|
|
1562
|
+
*/
|
|
1563
|
+
savedScript?: AgentWrittenScript;
|
|
1564
|
+
/**
|
|
1565
|
+
* Set when the LLM routed the question to a registered workflow component.
|
|
1566
|
+
* When present, the upstream caller should skip component generation and
|
|
1567
|
+
* return this workflow as the response.
|
|
1568
|
+
*/
|
|
1569
|
+
workflow?: SelectedWorkflow;
|
|
1570
|
+
}
|
|
1571
|
+
/**
|
|
1572
|
+
* A script MainAgent authored + verified during its turn. Shape aligns with
|
|
1573
|
+
* what ScriptStore.save() needs — minus store-assigned fields (id, timestamps, counts).
|
|
1574
|
+
*/
|
|
1575
|
+
interface AgentWrittenScript {
|
|
1576
|
+
/**
|
|
1577
|
+
* `ScriptRecipe.id` of the draft that was authored + verified during this turn.
|
|
1578
|
+
* The caller passes this to `ScriptStore.promoteToVerified(recipeId, …)` to
|
|
1579
|
+
* flip the draft to verified status and (when possible) drop the turn-suffix
|
|
1580
|
+
* from its filename.
|
|
1581
|
+
*/
|
|
1582
|
+
recipeId: string;
|
|
1583
|
+
name: string;
|
|
1584
|
+
intentDescription: string;
|
|
1585
|
+
tags: string[];
|
|
1586
|
+
parameters: Array<{
|
|
1587
|
+
name: string;
|
|
1588
|
+
type: 'string' | 'number' | 'date' | 'date_range' | 'enum' | 'boolean';
|
|
1589
|
+
required: boolean;
|
|
1590
|
+
default?: any;
|
|
1591
|
+
enumValues?: Record<string, string>;
|
|
1592
|
+
description: string;
|
|
1593
|
+
}>;
|
|
1594
|
+
scriptBody: string;
|
|
1595
|
+
/** Source IDs referenced by the script (extracted from ctx.query calls) */
|
|
1596
|
+
sourceIds: string[];
|
|
1597
|
+
/** Tables referenced in the script's SQL (regex-extracted) */
|
|
1598
|
+
tables: string[];
|
|
1599
|
+
/** Executed queries from the verified run — fed to component generation */
|
|
1600
|
+
executedQueries: Array<{
|
|
1601
|
+
sourceId: string;
|
|
1602
|
+
sourceName: string;
|
|
1603
|
+
sql: string;
|
|
1604
|
+
data: any[];
|
|
1605
|
+
count: number;
|
|
1606
|
+
totalCount?: number;
|
|
1607
|
+
executionTimeMs: number;
|
|
1608
|
+
/**
|
|
1609
|
+
* True for synthetic entries (ctx.emit datasets, the computed:_final
|
|
1610
|
+
* post-JS data). The component generator routes virtual sources through
|
|
1611
|
+
* the script_dataset sentinel toolId so the frontend resolves them via
|
|
1612
|
+
* queryCache instead of attempting to re-execute SQL.
|
|
1613
|
+
*/
|
|
1614
|
+
virtual?: boolean;
|
|
1615
|
+
}>;
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Configuration for the multi-agent system.
|
|
1619
|
+
* Controls limits, models, and behavior.
|
|
1620
|
+
*/
|
|
1621
|
+
interface AgentConfig {
|
|
1622
|
+
/** Max rows a source agent can return (default: 50) */
|
|
1623
|
+
maxRowsPerSource: number;
|
|
1624
|
+
/** Model for the main agent (routing + analysis in one LLM call) */
|
|
1625
|
+
mainAgentModel: string;
|
|
1626
|
+
/** Model for source agent query generation */
|
|
1627
|
+
sourceAgentModel: string;
|
|
1628
|
+
/** API key for LLM calls */
|
|
1629
|
+
apiKey?: string;
|
|
1630
|
+
/** Max retry attempts per source agent */
|
|
1631
|
+
maxRetries: number;
|
|
1632
|
+
/** Max tool calling iterations for the main agent loop */
|
|
1633
|
+
maxIterations: number;
|
|
1634
|
+
/** Global knowledge base context (static, same for all users/questions — cached in system prompt) */
|
|
1635
|
+
globalKnowledgeBase?: string;
|
|
1636
|
+
/** Per-request knowledge base context (user-specific + query-matched — dynamic, not cached) */
|
|
1637
|
+
knowledgeBaseContext?: string;
|
|
1638
|
+
/** Collections registry (ChromaDB search hooks) for embedding-based schema + source search */
|
|
1639
|
+
collections?: any;
|
|
1640
|
+
/** Optional project ID for scoping embedding searches */
|
|
1641
|
+
projectId?: string;
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Default agent configuration
|
|
1645
|
+
*/
|
|
1646
|
+
declare const DEFAULT_AGENT_CONFIG: AgentConfig;
|
|
1647
|
+
|
|
1648
|
+
/**
|
|
1649
|
+
* Script Flow Types
|
|
1650
|
+
*
|
|
1651
|
+
* Defines interfaces for the script-based query architecture:
|
|
1652
|
+
* - ScriptRecipe: metadata for matching, validation, and quality tracking
|
|
1653
|
+
* - ScriptResult: output from executing a script
|
|
1654
|
+
* - ScriptMatch: result from the LLM-based script matcher
|
|
1655
|
+
*/
|
|
1656
|
+
/**
|
|
1657
|
+
* Recipe metadata stored alongside each script.
|
|
1658
|
+
* Used for matching, validation, and quality tracking.
|
|
1659
|
+
*/
|
|
1660
|
+
interface ScriptRecipe {
|
|
1661
|
+
/** Unique script identifier */
|
|
1662
|
+
id: string;
|
|
1663
|
+
/** Version number (incremented on regeneration) */
|
|
1664
|
+
version: number;
|
|
1665
|
+
/** Human-readable name (e.g., "Revenue by Dimension") */
|
|
1666
|
+
name: string;
|
|
1667
|
+
/** Natural language description of what this script does */
|
|
1668
|
+
intentDescription: string;
|
|
1669
|
+
/** Keyword tags for quick filtering */
|
|
1670
|
+
tags: string[];
|
|
1671
|
+
/** Source tool IDs this script queries (e.g., ["mssql-abc123_query"]) */
|
|
1672
|
+
sourceIds: string[];
|
|
1673
|
+
/** Table names used (for future schema drift detection) */
|
|
1674
|
+
tables: string[];
|
|
1675
|
+
/** Parameter definitions — what can vary */
|
|
1676
|
+
parameters: ScriptParameter[];
|
|
1677
|
+
/** The script function body as a string */
|
|
1678
|
+
scriptBody: string;
|
|
1679
|
+
/** Times this script was used successfully */
|
|
1680
|
+
successCount: number;
|
|
1681
|
+
/** Times this script failed */
|
|
1682
|
+
failureCount: number;
|
|
1683
|
+
/** ISO timestamp of last usage */
|
|
1684
|
+
lastUsed: string;
|
|
1685
|
+
/** Original user question that created this script */
|
|
1686
|
+
createdFrom: string;
|
|
1687
|
+
/** ISO timestamp */
|
|
1688
|
+
createdAt: string;
|
|
1689
|
+
/** ISO timestamp */
|
|
1690
|
+
updatedAt: string;
|
|
1691
|
+
/**
|
|
1692
|
+
* `recipe.id` of the parent this script was forked from.
|
|
1693
|
+
* Undefined for root scripts (those written from scratch by MainAgent).
|
|
1694
|
+
* See backend/docs/SCRIPT-FLOW-FORK-ADAPT.md.
|
|
1695
|
+
*/
|
|
1696
|
+
parentId?: string;
|
|
1697
|
+
/** 0 for root scripts; `parent.forkDepth + 1` for forks. Capped at 3. */
|
|
1698
|
+
forkDepth?: number;
|
|
1699
|
+
/**
|
|
1700
|
+
* Brief description of what this fork changed vs its parent
|
|
1701
|
+
* (sourced from the matcher's `modificationHint`).
|
|
1702
|
+
*/
|
|
1703
|
+
forkReason?: string;
|
|
1704
|
+
/**
|
|
1705
|
+
* Lifecycle stage of this recipe on disk.
|
|
1706
|
+
* - 'draft': written by MainAgent's write_script during a turn; filtered out
|
|
1707
|
+
* of `ScriptStore.getAll()` so the matcher never picks it.
|
|
1708
|
+
* Filename is suffixed with `turnId` to keep concurrent turns
|
|
1709
|
+
* from clobbering each other's drafts.
|
|
1710
|
+
* - 'verified': promoted after `execute_script` succeeded; the matcher sees it.
|
|
1711
|
+
* Filename drops the turn suffix unless a verified file with
|
|
1712
|
+
* the same slug already exists (collision case keeps the suffix).
|
|
1713
|
+
*
|
|
1714
|
+
* Recipes loaded from disk without this field default to 'verified' so
|
|
1715
|
+
* existing scripts keep working unchanged.
|
|
1716
|
+
*/
|
|
1717
|
+
status?: 'draft' | 'verified';
|
|
1718
|
+
/**
|
|
1719
|
+
* Per-turn unique suffix used for draft filenames (e.g. `1714745623-x9k2`).
|
|
1720
|
+
* Set when the draft is saved; carried until the recipe is promoted.
|
|
1721
|
+
*/
|
|
1722
|
+
turnId?: string;
|
|
1723
|
+
/**
|
|
1724
|
+
* Last execution error captured by `recordDraftError` while the recipe was
|
|
1725
|
+
* still a draft. Lets users open the draft .json file and see why it failed
|
|
1726
|
+
* without grepping logs. Cleared on promotion to 'verified'.
|
|
1727
|
+
*/
|
|
1728
|
+
lastError?: {
|
|
1729
|
+
phase: 'compile' | 'runtime' | 'timeout' | 'ipc';
|
|
1730
|
+
message: string;
|
|
1731
|
+
at: string;
|
|
1732
|
+
attempt: number;
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
interface ScriptParameter {
|
|
1736
|
+
/** Parameter name (used in script body as params.name) */
|
|
1737
|
+
name: string;
|
|
1738
|
+
/** Parameter type */
|
|
1739
|
+
type: 'string' | 'number' | 'date' | 'date_range' | 'enum' | 'boolean';
|
|
1740
|
+
/** Whether this parameter is required */
|
|
1741
|
+
required: boolean;
|
|
1742
|
+
/** Default value if not provided */
|
|
1743
|
+
default?: any;
|
|
1744
|
+
/** For enum type — maps user-facing values to internal values */
|
|
1745
|
+
enumValues?: Record<string, string>;
|
|
1746
|
+
/** Human-readable description (used in the matcher LLM prompt) */
|
|
1747
|
+
description: string;
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
/**
|
|
1751
|
+
* ScriptStore — Persistent Storage for Script Recipes
|
|
1752
|
+
*
|
|
1753
|
+
* Layout:
|
|
1754
|
+
* scripts-store/
|
|
1755
|
+
* metadata/<name>.json ← recipe metadata (params, tables, counts, ...)
|
|
1756
|
+
* <name>.ts ← the getData() function body, editable in your IDE
|
|
1757
|
+
*
|
|
1758
|
+
* Each VM deployment is a single project, so no project ID prefix needed.
|
|
1759
|
+
* Legacy single-file format (JSON with embedded scriptBody) is still loadable
|
|
1760
|
+
* for backwards compatibility and auto-migrated to the split format on next save.
|
|
1761
|
+
*/
|
|
1762
|
+
|
|
1763
|
+
/**
|
|
1764
|
+
* Input for `ScriptStore.saveDraft()`. Identifies the draft by `recipeId` so
|
|
1765
|
+
* retries within the same turn overwrite the same files (or omit `recipeId`
|
|
1766
|
+
* on the first call to mint a fresh draft).
|
|
1767
|
+
*/
|
|
1768
|
+
interface SaveDraftInput {
|
|
1769
|
+
/** Reuse an existing draft (retry); omit to mint a new one. */
|
|
1770
|
+
recipeId?: string;
|
|
1771
|
+
/** Per-turn unique suffix, stable across retries within the turn. */
|
|
1772
|
+
turnId: string;
|
|
1773
|
+
name: string;
|
|
1774
|
+
intentDescription: string;
|
|
1775
|
+
tags: string[];
|
|
1776
|
+
parameters: ScriptParameter[];
|
|
1777
|
+
scriptBody: string;
|
|
1778
|
+
createdFrom: string;
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Lineage + provenance fields applied when a draft is promoted to verified.
|
|
1782
|
+
* MainAgent gathers `sourceIds` and `tables` from the verified execution; the
|
|
1783
|
+
* caller (agent-user-response.ts) supplies the optional fork lineage.
|
|
1784
|
+
*/
|
|
1785
|
+
interface PromoteToVerifiedInput {
|
|
1786
|
+
sourceIds: string[];
|
|
1787
|
+
tables: string[];
|
|
1788
|
+
parentId?: string;
|
|
1789
|
+
forkDepth?: number;
|
|
1790
|
+
forkReason?: string;
|
|
1791
|
+
}
|
|
1792
|
+
declare class ScriptStore {
|
|
1793
|
+
private recipes;
|
|
1794
|
+
private storeDir;
|
|
1795
|
+
private loaded;
|
|
1796
|
+
constructor(baseDir?: string);
|
|
1797
|
+
private metadataDir;
|
|
1798
|
+
/**
|
|
1799
|
+
* Filename base for a recipe. Drafts include the per-turn suffix so two
|
|
1800
|
+
* concurrent turns can never clobber each other's draft files; verified
|
|
1801
|
+
* recipes use the bare slug.
|
|
1802
|
+
*/
|
|
1803
|
+
private fileBaseName;
|
|
1804
|
+
/**
|
|
1805
|
+
* Absolute path to the .ts file for a recipe. Callers (e.g. ScriptRunner,
|
|
1806
|
+
* MainAgent's execute_script) use this to hand off the path to the tsx child.
|
|
1807
|
+
*/
|
|
1808
|
+
getScriptPath(recipe: ScriptRecipe): string;
|
|
1809
|
+
/**
|
|
1810
|
+
* Absolute path to the metadata JSON for a recipe.
|
|
1811
|
+
*/
|
|
1812
|
+
private getMetadataPath;
|
|
1813
|
+
/**
|
|
1814
|
+
* Get all VERIFIED recipes — drafts are filtered out so the matcher never
|
|
1815
|
+
* considers an unverified script. Loads from disk on first access.
|
|
1816
|
+
*/
|
|
1817
|
+
getAll(): ScriptRecipe[];
|
|
1818
|
+
/**
|
|
1819
|
+
* Get a recipe by ID — returns drafts as well as verified scripts.
|
|
1820
|
+
* Used by MainAgent and the promotion path.
|
|
1821
|
+
*/
|
|
1822
|
+
get(id: string): ScriptRecipe | null;
|
|
1823
|
+
/**
|
|
1824
|
+
* Number of verified recipes (matches `getAll().length`).
|
|
1825
|
+
*/
|
|
1826
|
+
count(): number;
|
|
1827
|
+
/**
|
|
1828
|
+
* Save a recipe (create or update).
|
|
1829
|
+
* File is named after the script: "order-status-distribution.json"
|
|
1830
|
+
*/
|
|
1831
|
+
save(recipe: ScriptRecipe): void;
|
|
1832
|
+
/**
|
|
1833
|
+
* Persist (or update) a draft recipe to disk. Always writes immediately so
|
|
1834
|
+
* the `.ts` body is visible in the IDE the moment MainAgent calls
|
|
1835
|
+
* `write_script`. Within one turn, retries that pass the same `recipeId`
|
|
1836
|
+
* overwrite the same files (the LLM rewriting itself); a fresh `recipeId`
|
|
1837
|
+
* is minted only on the first call of the turn.
|
|
1838
|
+
*
|
|
1839
|
+
* Filename includes the `turnId` suffix so concurrent turns never collide.
|
|
1840
|
+
*/
|
|
1841
|
+
saveDraft(input: SaveDraftInput): ScriptRecipe;
|
|
1842
|
+
/**
|
|
1843
|
+
* Stamp the draft with the most recent execution failure so it is visible
|
|
1844
|
+
* in the metadata JSON without grepping logs. No-op if the recipe doesn't
|
|
1845
|
+
* exist or has already been promoted.
|
|
1846
|
+
*/
|
|
1847
|
+
recordDraftError(recipeId: string, err: {
|
|
1848
|
+
phase: 'compile' | 'runtime' | 'timeout' | 'ipc';
|
|
1849
|
+
message: string;
|
|
1850
|
+
attempt: number;
|
|
1851
|
+
}): void;
|
|
1852
|
+
/**
|
|
1853
|
+
* Promote a successfully-executed draft into a verified script.
|
|
1854
|
+
*
|
|
1855
|
+
* - Renames the on-disk files from `<slug>-<turnId>.{ts,json}` to the bare
|
|
1856
|
+
* `<slug>.{ts,json}`. If a verified file with the same slug already exists
|
|
1857
|
+
* (concurrent turn won the race, or a prior session has it), the recipe
|
|
1858
|
+
* keeps its turn-suffixed filename so we never overwrite verified work —
|
|
1859
|
+
* the matcher keys on `recipe.id`, so two siblings with similar slugs is fine.
|
|
1860
|
+
* - Flips `status: 'verified'`, clears `lastError`, applies provenance
|
|
1861
|
+
* (`sourceIds`, `tables`) and optional fork lineage.
|
|
1862
|
+
*/
|
|
1863
|
+
promoteToVerified(recipeId: string, input: PromoteToVerifiedInput): ScriptRecipe | null;
|
|
1864
|
+
/**
|
|
1865
|
+
* Drop a draft from disk + memory (e.g. when an outer error path wants to
|
|
1866
|
+
* clean up). Per the agreed policy, MainAgent's normal failure path does
|
|
1867
|
+
* NOT call this — failed drafts are kept on disk for the user to inspect.
|
|
1868
|
+
*/
|
|
1869
|
+
discardDraft(recipeId: string): void;
|
|
1870
|
+
/**
|
|
1871
|
+
* Delete a recipe by ID.
|
|
1872
|
+
*/
|
|
1873
|
+
delete(id: string): void;
|
|
1874
|
+
/**
|
|
1875
|
+
* Record a successful execution for a recipe.
|
|
1876
|
+
*/
|
|
1877
|
+
recordSuccess(id: string): void;
|
|
1878
|
+
/**
|
|
1879
|
+
* Record a failed execution for a recipe.
|
|
1880
|
+
*/
|
|
1881
|
+
recordFailure(id: string): void;
|
|
1882
|
+
/**
|
|
1883
|
+
* Get the failure rate for a recipe (0 to 1).
|
|
1884
|
+
* Returns 0 if the recipe has fewer than 5 total uses.
|
|
1885
|
+
*/
|
|
1886
|
+
getFailureRate(id: string): number;
|
|
1887
|
+
private ensureLoaded;
|
|
1888
|
+
/**
|
|
1889
|
+
* Convert a script name to a safe filename.
|
|
1890
|
+
* "Order Status Distribution" → "order-status-distribution"
|
|
1891
|
+
*/
|
|
1892
|
+
private toFileName;
|
|
1893
|
+
/**
|
|
1894
|
+
* Load all script files from disk.
|
|
1895
|
+
*
|
|
1896
|
+
* Supports two layouts:
|
|
1897
|
+
* - New (preferred): metadata/<name>.json + <name>.ts
|
|
1898
|
+
* - Legacy: <name>.json with embedded scriptBody (auto-migrated on next save)
|
|
1899
|
+
*/
|
|
1900
|
+
private loadAllFromDisk;
|
|
1901
|
+
/**
|
|
1902
|
+
* Save a recipe to disk in split format:
|
|
1903
|
+
* metadata/<name>.json (metadata, no scriptBody)
|
|
1904
|
+
* <name>.ts (just the function body)
|
|
1905
|
+
*
|
|
1906
|
+
* If a legacy top-level <name>.json exists for the same recipe, remove it
|
|
1907
|
+
* so we don't end up with duplicate sources of truth.
|
|
1908
|
+
*/
|
|
1909
|
+
private saveRecipeToDisk;
|
|
1910
|
+
/**
|
|
1911
|
+
* Delete a recipe's files from disk (both metadata + body, plus any legacy file).
|
|
1912
|
+
*/
|
|
1913
|
+
private deleteRecipeFromDisk;
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
/**
|
|
1917
|
+
* Main Agent (Orchestrator)
|
|
1918
|
+
*
|
|
1919
|
+
* A single LLM.streamWithTools() call that handles everything:
|
|
1920
|
+
* - Routing: decides which source(s) to query based on summaries
|
|
1921
|
+
* - Querying: calls source tools (each wraps an independent SourceAgent)
|
|
1922
|
+
* - Direct tools: calls pre-built function tools directly with LLM-provided params
|
|
1923
|
+
* - Re-querying: if data is wrong/incomplete, calls tools again with modified intent
|
|
1924
|
+
* - Analysis: generates final text response from the data
|
|
1925
|
+
*
|
|
1926
|
+
* Two tool types:
|
|
1927
|
+
* - "source" tools: main agent sees summaries, SourceAgent handles SQL generation independently
|
|
1928
|
+
* - "direct" tools: main agent calls fn() directly with structured params (no SourceAgent)
|
|
1929
|
+
*/
|
|
1930
|
+
|
|
1931
|
+
declare class MainAgent {
|
|
1932
|
+
private externalTools;
|
|
1933
|
+
private workflows;
|
|
1934
|
+
private config;
|
|
1935
|
+
private streamBuffer;
|
|
1936
|
+
/**
|
|
1937
|
+
* Optional: when provided, MainAgent exposes the `write_script` /
|
|
1938
|
+
* `execute_script` tools to the LLM and persists drafts to disk via the
|
|
1939
|
+
* store. Headless callers (alert analyzer, metric resolver) omit these to
|
|
1940
|
+
* suppress script authoring entirely — drafts would otherwise leak onto
|
|
1941
|
+
* disk with no caller to promote or clean them up.
|
|
1942
|
+
*/
|
|
1943
|
+
private scriptStore;
|
|
1944
|
+
private turnId;
|
|
1945
|
+
private createdFromPrompt;
|
|
1946
|
+
private scriptState;
|
|
1947
|
+
constructor(externalTools: ExternalTool[], config: AgentConfig, scriptStore?: ScriptStore, turnId?: string, streamBuffer?: StreamBuffer, workflows?: WorkflowDescriptor[]);
|
|
1948
|
+
private get scriptingEnabled();
|
|
1949
|
+
/**
|
|
1950
|
+
* Handle a user question using the multi-agent system.
|
|
1951
|
+
*
|
|
1952
|
+
* This is ONE LLM.streamWithTools() call. The LLM:
|
|
1953
|
+
* 1. Sees source summaries + direct tool descriptions in system prompt
|
|
1954
|
+
* 2. Decides which tool(s) to call (routing)
|
|
1955
|
+
* 3. Source tools → SourceAgent runs independently → returns data
|
|
1956
|
+
* 4. Direct tools → fn() called directly with LLM params → returns data
|
|
1957
|
+
* 5. Generates final analysis text
|
|
1958
|
+
*/
|
|
1959
|
+
handleQuestion(userPrompt: string, apiKey?: string, conversationHistory?: string, streamCallback?: (chunk: string) => void): Promise<AgentResponse>;
|
|
1960
|
+
private handleWriteScript;
|
|
1961
|
+
private handleExecuteScript;
|
|
1962
|
+
/**
|
|
1963
|
+
* Build the AgentWrittenScript payload the caller will hand to
|
|
1964
|
+
* `ScriptStore.promoteToVerified()`. Only returned when a verified
|
|
1965
|
+
* successful execution is on record.
|
|
1966
|
+
*/
|
|
1967
|
+
private buildSavedScript;
|
|
1968
|
+
private normalizeParameterList;
|
|
1969
|
+
/**
|
|
1970
|
+
* Use the schema embedding collection to pre-select relevant tables for
|
|
1971
|
+
* this source + intent. Returns a formatted schema block if confidence is
|
|
1972
|
+
* high (top match ≥ 0.55 and ≥3 candidates), otherwise null.
|
|
1973
|
+
*
|
|
1974
|
+
* When this returns a block, we can skip the SourceAgent's `search_schema`
|
|
1975
|
+
* loop and reduce iteration budget. When it returns null, the SourceAgent
|
|
1976
|
+
* falls back to the existing LLM-driven keyword search (same as today).
|
|
1977
|
+
*/
|
|
1978
|
+
private preResolveSchema;
|
|
1979
|
+
/**
|
|
1980
|
+
* Execute a direct tool — call fn() with LLM-provided params, no SourceAgent.
|
|
1981
|
+
*/
|
|
1982
|
+
private handleDirectTool;
|
|
1983
|
+
/**
|
|
1984
|
+
* Build the main agent's system prompt with source summaries, direct tool descriptions,
|
|
1985
|
+
* and workflow component descriptions.
|
|
1986
|
+
*/
|
|
1987
|
+
private buildSystemPrompt;
|
|
1988
|
+
/**
|
|
1989
|
+
* Build tool definitions for source tools — summary-only descriptions.
|
|
1990
|
+
* The full schema is inside the SourceAgent which runs independently.
|
|
1991
|
+
*/
|
|
1992
|
+
private buildSourceToolDefinitions;
|
|
1993
|
+
/**
|
|
1994
|
+
* Build tool definitions for direct tools — expose their actual params.
|
|
1995
|
+
* These are called directly by the main agent LLM, no SourceAgent.
|
|
1996
|
+
*/
|
|
1997
|
+
private buildDirectToolDefinitions;
|
|
1998
|
+
/**
|
|
1999
|
+
* Capture a workflow selection. We do NOT execute anything — the LLM has
|
|
2000
|
+
* already extracted the props it wants the workflow rendered with. We
|
|
2001
|
+
* record the selection (via the capture callback) and return a short
|
|
2002
|
+
* acknowledgement so the LLM ends its turn cleanly without writing
|
|
2003
|
+
* analysis text or calling more tools.
|
|
2004
|
+
*/
|
|
2005
|
+
private handleWorkflow;
|
|
2006
|
+
/**
|
|
2007
|
+
* Build LLM tool definitions for workflow components. The workflow's
|
|
2008
|
+
* propsSchema becomes the tool's input_schema so the LLM extracts props
|
|
2009
|
+
* directly from the prompt — same mechanic as direct tools.
|
|
2010
|
+
*/
|
|
2011
|
+
private buildWorkflowToolDefinitions;
|
|
2012
|
+
/**
|
|
2013
|
+
* Format a source agent's result as a clean string for the main agent LLM.
|
|
2014
|
+
*/
|
|
2015
|
+
private formatResultForMainAgent;
|
|
2016
|
+
/**
|
|
2017
|
+
* Get source summaries (for external inspection/debugging).
|
|
2018
|
+
*/
|
|
2019
|
+
getSourceSummaries(): SourceSummary[];
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
/**
|
|
2023
|
+
* Represents an action that can be performed on a UIBlock
|
|
2024
|
+
*/
|
|
2025
|
+
interface Action {
|
|
2026
|
+
id: string;
|
|
2027
|
+
name: string;
|
|
2028
|
+
type: string;
|
|
2029
|
+
[key: string]: any;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
1283
2032
|
type SystemPrompt = string | Anthropic.Messages.TextBlockParam[];
|
|
1284
2033
|
interface LLMMessages {
|
|
1285
2034
|
sys: SystemPrompt;
|
|
@@ -1434,16 +2183,6 @@ declare class UILogCollector {
|
|
|
1434
2183
|
setUIBlockId(uiBlockId: string): void;
|
|
1435
2184
|
}
|
|
1436
2185
|
|
|
1437
|
-
/**
|
|
1438
|
-
* Represents an action that can be performed on a UIBlock
|
|
1439
|
-
*/
|
|
1440
|
-
interface Action {
|
|
1441
|
-
id: string;
|
|
1442
|
-
name: string;
|
|
1443
|
-
type: string;
|
|
1444
|
-
[key: string]: any;
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
2186
|
/**
|
|
1448
2187
|
* UIBlock represents a single user and assistant message block in a thread
|
|
1449
2188
|
* Contains user question, component metadata, component data, text response, and available actions
|
|
@@ -1626,12 +2365,20 @@ declare class Thread {
|
|
|
1626
2365
|
|
|
1627
2366
|
/**
|
|
1628
2367
|
* ThreadManager manages all threads globally
|
|
1629
|
-
* Provides methods to create, retrieve, and delete threads
|
|
2368
|
+
* Provides methods to create, retrieve, and delete threads.
|
|
2369
|
+
* Includes automatic cleanup to prevent unbounded memory growth.
|
|
1630
2370
|
*/
|
|
1631
2371
|
declare class ThreadManager {
|
|
1632
2372
|
private static instance;
|
|
1633
2373
|
private threads;
|
|
2374
|
+
private cleanupInterval;
|
|
2375
|
+
private readonly threadTtlMs;
|
|
1634
2376
|
private constructor();
|
|
2377
|
+
/**
|
|
2378
|
+
* Periodically remove threads older than 7 days.
|
|
2379
|
+
* Runs every hour to avoid frequent iteration over the map.
|
|
2380
|
+
*/
|
|
2381
|
+
private startCleanup;
|
|
1635
2382
|
/**
|
|
1636
2383
|
* Get singleton instance of ThreadManager
|
|
1637
2384
|
*/
|
|
@@ -2331,18 +3078,30 @@ declare class OpenAILLM extends BaseLLM {
|
|
|
2331
3078
|
declare const openaiLLM: OpenAILLM;
|
|
2332
3079
|
|
|
2333
3080
|
/**
|
|
2334
|
-
* Query Cache
|
|
2335
|
-
*
|
|
3081
|
+
* Query Cache — Two mechanisms:
|
|
3082
|
+
*
|
|
3083
|
+
* 1. `cache` (query string → result data) — TTL-based with max size, for avoiding re-execution
|
|
3084
|
+
* of recently validated queries. True LRU eviction: reads bubble entries to the back via
|
|
3085
|
+
* delete+re-set so the oldest *unused* entry is evicted, not the oldest *inserted*.
|
|
3086
|
+
*
|
|
3087
|
+
* 2. Encrypted queryId tokens — SQL is encrypted into the queryId itself (self-contained).
|
|
3088
|
+
* No server-side storage needed for SQL mappings. The token is decrypted on each request.
|
|
3089
|
+
* This eliminates the unbounded queryIdCache that previously grew forever and caused
|
|
3090
|
+
* memory bloat (hundreds of MBs after thousands of queries).
|
|
3091
|
+
*
|
|
3092
|
+
* Result data can still be cached temporarily via the data cache (mechanism 1).
|
|
2336
3093
|
*/
|
|
2337
3094
|
declare class QueryCache {
|
|
2338
3095
|
private cache;
|
|
2339
|
-
private queryIdCache;
|
|
2340
3096
|
private ttlMs;
|
|
3097
|
+
private maxCacheSize;
|
|
2341
3098
|
private cleanupInterval;
|
|
3099
|
+
private readonly algorithm;
|
|
3100
|
+
private encryptionKey;
|
|
2342
3101
|
constructor();
|
|
2343
3102
|
/**
|
|
2344
3103
|
* Set the cache TTL (Time To Live)
|
|
2345
|
-
* @param minutes - TTL in minutes (default:
|
|
3104
|
+
* @param minutes - TTL in minutes (default: 10)
|
|
2346
3105
|
*/
|
|
2347
3106
|
setTTL(minutes: number): void;
|
|
2348
3107
|
/**
|
|
@@ -2350,12 +3109,16 @@ declare class QueryCache {
|
|
|
2350
3109
|
*/
|
|
2351
3110
|
getTTL(): number;
|
|
2352
3111
|
/**
|
|
2353
|
-
* Store query result in cache
|
|
2354
|
-
*
|
|
3112
|
+
* Store query result in data cache.
|
|
3113
|
+
* If the key already exists, it's removed first so the re-insert places it
|
|
3114
|
+
* at the back of the iteration order (LRU). Eviction only fires when adding
|
|
3115
|
+
* a genuinely new key past the size limit.
|
|
2355
3116
|
*/
|
|
2356
3117
|
set(query: string, data: any): void;
|
|
2357
3118
|
/**
|
|
2358
|
-
* Get cached result if exists and not expired
|
|
3119
|
+
* Get cached result if exists and not expired.
|
|
3120
|
+
* On hit, re-inserts the entry so it moves to the back of the Map's
|
|
3121
|
+
* iteration order — turning FIFO eviction into true LRU.
|
|
2359
3122
|
*/
|
|
2360
3123
|
get(query: string): any | null;
|
|
2361
3124
|
/**
|
|
@@ -2375,30 +3138,37 @@ declare class QueryCache {
|
|
|
2375
3138
|
*/
|
|
2376
3139
|
getStats(): {
|
|
2377
3140
|
size: number;
|
|
3141
|
+
queryIdCount: number;
|
|
2378
3142
|
oldestEntryAge: number | null;
|
|
2379
3143
|
};
|
|
2380
3144
|
/**
|
|
2381
|
-
* Start periodic cleanup of expired entries
|
|
3145
|
+
* Start periodic cleanup of expired data cache entries.
|
|
2382
3146
|
*/
|
|
2383
3147
|
private startCleanup;
|
|
2384
3148
|
/**
|
|
2385
|
-
*
|
|
3149
|
+
* Encrypt a payload into a self-contained token.
|
|
3150
|
+
*/
|
|
3151
|
+
private encrypt;
|
|
3152
|
+
/**
|
|
3153
|
+
* Decrypt a token back to the original payload.
|
|
2386
3154
|
*/
|
|
2387
|
-
private
|
|
3155
|
+
private decrypt;
|
|
2388
3156
|
/**
|
|
2389
|
-
* Store a query by
|
|
2390
|
-
* The
|
|
3157
|
+
* Store a query by generating an encrypted token as queryId.
|
|
3158
|
+
* The SQL is encrypted INTO the token — nothing stored in memory.
|
|
3159
|
+
* If data is provided, it's cached temporarily in the data cache.
|
|
2391
3160
|
*/
|
|
2392
3161
|
storeQuery(query: any, data?: any): string;
|
|
2393
3162
|
/**
|
|
2394
|
-
* Get a stored query by its
|
|
3163
|
+
* Get a stored query by decrypting its token.
|
|
3164
|
+
* Returns the SQL + any cached result data.
|
|
2395
3165
|
*/
|
|
2396
3166
|
getQuery(queryId: string): {
|
|
2397
3167
|
query: any;
|
|
2398
3168
|
data: any;
|
|
2399
3169
|
} | null;
|
|
2400
3170
|
/**
|
|
2401
|
-
* Update cached data for a queryId
|
|
3171
|
+
* Update cached data for a queryId token
|
|
2402
3172
|
*/
|
|
2403
3173
|
setQueryData(queryId: string, data: any): void;
|
|
2404
3174
|
/**
|
|
@@ -2408,6 +3178,52 @@ declare class QueryCache {
|
|
|
2408
3178
|
}
|
|
2409
3179
|
declare const queryCache: QueryCache;
|
|
2410
3180
|
|
|
3181
|
+
/**
|
|
3182
|
+
* Manages conversation history scoped per user + dashboard.
|
|
3183
|
+
* Each user-dashboard pair has its own isolated history that expires after a configurable TTL.
|
|
3184
|
+
*/
|
|
3185
|
+
declare class DashboardConversationHistory {
|
|
3186
|
+
private histories;
|
|
3187
|
+
private ttlMs;
|
|
3188
|
+
private maxEntries;
|
|
3189
|
+
private cleanupInterval;
|
|
3190
|
+
constructor();
|
|
3191
|
+
/**
|
|
3192
|
+
* Set the TTL for dashboard histories
|
|
3193
|
+
* @param minutes - TTL in minutes
|
|
3194
|
+
*/
|
|
3195
|
+
setTTL(minutes: number): void;
|
|
3196
|
+
/**
|
|
3197
|
+
* Set max entries per dashboard
|
|
3198
|
+
*/
|
|
3199
|
+
setMaxEntries(max: number): void;
|
|
3200
|
+
/**
|
|
3201
|
+
* Add a conversation entry for a user's dashboard
|
|
3202
|
+
*/
|
|
3203
|
+
addEntry(dashboardId: string, userPrompt: string, componentSummary: string, userId?: string): void;
|
|
3204
|
+
/**
|
|
3205
|
+
* Get formatted conversation history for a user's dashboard
|
|
3206
|
+
*/
|
|
3207
|
+
getHistory(dashboardId: string, userId?: string): string;
|
|
3208
|
+
/**
|
|
3209
|
+
* Clear history for a specific user's dashboard
|
|
3210
|
+
*/
|
|
3211
|
+
clearDashboard(dashboardId: string, userId?: string): void;
|
|
3212
|
+
/**
|
|
3213
|
+
* Clear all dashboard histories
|
|
3214
|
+
*/
|
|
3215
|
+
clearAll(): void;
|
|
3216
|
+
/**
|
|
3217
|
+
* Start periodic cleanup of expired histories
|
|
3218
|
+
*/
|
|
3219
|
+
private startCleanup;
|
|
3220
|
+
/**
|
|
3221
|
+
* Stop cleanup interval (for graceful shutdown)
|
|
3222
|
+
*/
|
|
3223
|
+
destroy(): void;
|
|
3224
|
+
}
|
|
3225
|
+
declare const dashboardConversationHistory: DashboardConversationHistory;
|
|
3226
|
+
|
|
2411
3227
|
type MessageTypeHandler = (message: IncomingMessage) => void | Promise<void>;
|
|
2412
3228
|
declare class SuperatomSDK {
|
|
2413
3229
|
private ws;
|
|
@@ -2424,6 +3240,7 @@ declare class SuperatomSDK {
|
|
|
2424
3240
|
private collections;
|
|
2425
3241
|
private components;
|
|
2426
3242
|
private tools;
|
|
3243
|
+
private workflows;
|
|
2427
3244
|
private anthropicApiKey;
|
|
2428
3245
|
private groqApiKey;
|
|
2429
3246
|
private geminiApiKey;
|
|
@@ -2431,6 +3248,9 @@ declare class SuperatomSDK {
|
|
|
2431
3248
|
private llmProviders;
|
|
2432
3249
|
private databaseType;
|
|
2433
3250
|
private modelStrategy;
|
|
3251
|
+
private mainAgentModel;
|
|
3252
|
+
private sourceAgentModel;
|
|
3253
|
+
private dashCompModels?;
|
|
2434
3254
|
private conversationSimilarityThreshold;
|
|
2435
3255
|
private userManager;
|
|
2436
3256
|
private dashboardManager;
|
|
@@ -2478,9 +3298,11 @@ declare class SuperatomSDK {
|
|
|
2478
3298
|
*/
|
|
2479
3299
|
private handleMessage;
|
|
2480
3300
|
/**
|
|
2481
|
-
* Send a message to the Superatom service
|
|
3301
|
+
* Send a message to the Superatom service.
|
|
3302
|
+
* Returns true if the message was sent, false if the WebSocket is not connected.
|
|
3303
|
+
* Does NOT throw on closed connections — callers can check the return value if needed.
|
|
2482
3304
|
*/
|
|
2483
|
-
send(message: Message):
|
|
3305
|
+
send(message: Message): boolean;
|
|
2484
3306
|
/**
|
|
2485
3307
|
* Register a message handler to receive all messages
|
|
2486
3308
|
*/
|
|
@@ -2528,6 +3350,19 @@ declare class SuperatomSDK {
|
|
|
2528
3350
|
* Get the stored tools
|
|
2529
3351
|
*/
|
|
2530
3352
|
getTools(): Tool$1[];
|
|
3353
|
+
/**
|
|
3354
|
+
* Register workflow components for the SDK instance.
|
|
3355
|
+
*
|
|
3356
|
+
* Workflows are pre-built multi-step UI flows the main agent can pick when
|
|
3357
|
+
* the user's prompt matches a workflow's `whenToUse` trigger. Picking a
|
|
3358
|
+
* workflow short-circuits analysis text + dashboard component generation —
|
|
3359
|
+
* the workflow component is returned directly, with the LLM-extracted props.
|
|
3360
|
+
*/
|
|
3361
|
+
setWorkflows(workflows: WorkflowDescriptor[]): void;
|
|
3362
|
+
/**
|
|
3363
|
+
* Get the registered workflow components.
|
|
3364
|
+
*/
|
|
3365
|
+
getWorkflows(): WorkflowDescriptor[];
|
|
2531
3366
|
/**
|
|
2532
3367
|
* Apply model strategy to all LLM provider singletons
|
|
2533
3368
|
* @param strategy - 'best', 'fast', or 'balanced'
|
|
@@ -2558,4 +3393,4 @@ declare class SuperatomSDK {
|
|
|
2558
3393
|
getConversationSimilarityThreshold(): number;
|
|
2559
3394
|
}
|
|
2560
3395
|
|
|
2561
|
-
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, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, type ToolOutputSchema, UIBlock, UILogCollector, type User, UserManager, type UsersData, anthropicLLM, geminiLLM, groqLLM, hybridRerank, llmUsageLogger, logger, openaiLLM, queryCache, rerankChromaResults, rerankConversationResults, userPromptErrorLogger };
|
|
3396
|
+
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 };
|