@superatomai/sdk-node 0.0.38-mds → 0.0.39-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 +395 -302
- package/dist/index.d.ts +395 -302
- package/dist/index.js +191 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +191 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1306,6 +1306,360 @@ declare class ReportManager {
|
|
|
1306
1306
|
getReportCount(): number;
|
|
1307
1307
|
}
|
|
1308
1308
|
|
|
1309
|
+
/**
|
|
1310
|
+
* StreamBuffer - Buffered streaming utility for smoother text delivery
|
|
1311
|
+
* Batches small chunks together and flushes at regular intervals
|
|
1312
|
+
*/
|
|
1313
|
+
type StreamCallback = (chunk: string) => void;
|
|
1314
|
+
/**
|
|
1315
|
+
* StreamBuffer class for managing buffered streaming output
|
|
1316
|
+
* Provides smooth text delivery by batching small chunks
|
|
1317
|
+
*/
|
|
1318
|
+
declare class StreamBuffer {
|
|
1319
|
+
private buffer;
|
|
1320
|
+
private flushTimer;
|
|
1321
|
+
private callback;
|
|
1322
|
+
private fullText;
|
|
1323
|
+
constructor(callback?: StreamCallback);
|
|
1324
|
+
/**
|
|
1325
|
+
* Check if the buffer has a callback configured
|
|
1326
|
+
*/
|
|
1327
|
+
hasCallback(): boolean;
|
|
1328
|
+
/**
|
|
1329
|
+
* Get all text that has been written (including already flushed)
|
|
1330
|
+
*/
|
|
1331
|
+
getFullText(): string;
|
|
1332
|
+
/**
|
|
1333
|
+
* Write a chunk to the buffer
|
|
1334
|
+
* Large chunks or chunks with newlines are flushed immediately
|
|
1335
|
+
* Small chunks are batched and flushed after a short interval
|
|
1336
|
+
*
|
|
1337
|
+
* @param chunk - Text chunk to write
|
|
1338
|
+
*/
|
|
1339
|
+
write(chunk: string): void;
|
|
1340
|
+
/**
|
|
1341
|
+
* Flush the buffer immediately
|
|
1342
|
+
* Call this before tool execution or other operations that need clean output
|
|
1343
|
+
*/
|
|
1344
|
+
flush(): void;
|
|
1345
|
+
/**
|
|
1346
|
+
* Internal flush implementation
|
|
1347
|
+
*/
|
|
1348
|
+
private flushNow;
|
|
1349
|
+
/**
|
|
1350
|
+
* Clean up resources
|
|
1351
|
+
* Call this when done with the buffer
|
|
1352
|
+
*/
|
|
1353
|
+
dispose(): void;
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* ToolExecutorService - Handles execution of SQL queries and external tools
|
|
1358
|
+
* Extracted from BaseLLM.generateTextResponse for better separation of concerns
|
|
1359
|
+
*/
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* External tool definition
|
|
1363
|
+
*/
|
|
1364
|
+
interface ExternalTool {
|
|
1365
|
+
id: string;
|
|
1366
|
+
name: string;
|
|
1367
|
+
description?: string;
|
|
1368
|
+
/** Tool type: "source" = routed through SourceAgent, "direct" = called directly by MainAgent */
|
|
1369
|
+
toolType?: 'source' | 'direct';
|
|
1370
|
+
/** Full untruncated schema for source agent (all columns visible) */
|
|
1371
|
+
fullSchema?: string;
|
|
1372
|
+
/** Schema size tier: small (≤50 tables), medium (51-200), large (201-500), very_large (500+) */
|
|
1373
|
+
schemaTier?: string;
|
|
1374
|
+
/** Schema search function for very_large tier — keyword search over entities */
|
|
1375
|
+
schemaSearchFn?: (keywords: string[]) => string;
|
|
1376
|
+
fn: (input: any) => Promise<any>;
|
|
1377
|
+
limit?: number;
|
|
1378
|
+
outputSchema?: any;
|
|
1379
|
+
executionType?: 'immediate' | 'deferred';
|
|
1380
|
+
userProvidedData?: any;
|
|
1381
|
+
params?: Record<string, any>;
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Executed tool tracking info
|
|
1385
|
+
*/
|
|
1386
|
+
interface ExecutedToolInfo {
|
|
1387
|
+
id: string;
|
|
1388
|
+
name: string;
|
|
1389
|
+
params: any;
|
|
1390
|
+
result: {
|
|
1391
|
+
_totalRecords: number;
|
|
1392
|
+
_recordsShown: number;
|
|
1393
|
+
_metadata?: any;
|
|
1394
|
+
_sampleData: any[];
|
|
1395
|
+
};
|
|
1396
|
+
outputSchema?: any;
|
|
1397
|
+
sourceSchema?: string;
|
|
1398
|
+
sourceType?: string;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
/**
|
|
1402
|
+
* Multi-Agent Architecture Types
|
|
1403
|
+
*
|
|
1404
|
+
* Defines interfaces for the hierarchical agent system:
|
|
1405
|
+
* - Main Agent: ONE LLM.streamWithTools() call with source agent tools
|
|
1406
|
+
* - Source Agents: independent agents that query individual data sources
|
|
1407
|
+
*
|
|
1408
|
+
* The main agent sees only source summaries. When it calls a source tool,
|
|
1409
|
+
* the SourceAgent runs independently (own LLM, own retries) and returns clean data.
|
|
1410
|
+
*/
|
|
1411
|
+
|
|
1412
|
+
/**
|
|
1413
|
+
* Per-entity detail: name, row count, and column names.
|
|
1414
|
+
* Gives the main agent enough context to route to the right source.
|
|
1415
|
+
*/
|
|
1416
|
+
interface EntityDetail {
|
|
1417
|
+
/** Entity name (table, sheet, endpoint) */
|
|
1418
|
+
name: string;
|
|
1419
|
+
/** Approximate row count */
|
|
1420
|
+
rowCount?: number;
|
|
1421
|
+
/** Column/field names */
|
|
1422
|
+
columns: string[];
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Representation of a data source for the main agent.
|
|
1426
|
+
* Contains entity names WITH column names so the LLM can route accurately.
|
|
1427
|
+
*/
|
|
1428
|
+
interface SourceSummary {
|
|
1429
|
+
/** Source ID (matches tool ID prefix) */
|
|
1430
|
+
id: string;
|
|
1431
|
+
/** Human-readable source name */
|
|
1432
|
+
name: string;
|
|
1433
|
+
/** Source type: postgres, excel, rest_api, etc. */
|
|
1434
|
+
type: string;
|
|
1435
|
+
/** Brief description of what data this source contains */
|
|
1436
|
+
description: string;
|
|
1437
|
+
/** Detailed entity info with column names for routing */
|
|
1438
|
+
entityDetails: EntityDetail[];
|
|
1439
|
+
/** The tool ID associated with this source */
|
|
1440
|
+
toolId: string;
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* What a source agent returns after querying its data source.
|
|
1444
|
+
* The main agent uses this to analyze and compose the final response.
|
|
1445
|
+
*/
|
|
1446
|
+
interface SourceAgentResult {
|
|
1447
|
+
/** Source ID */
|
|
1448
|
+
sourceId: string;
|
|
1449
|
+
/** Source name */
|
|
1450
|
+
sourceName: string;
|
|
1451
|
+
/** Whether the query succeeded */
|
|
1452
|
+
success: boolean;
|
|
1453
|
+
/** Result data rows */
|
|
1454
|
+
data: any[];
|
|
1455
|
+
/** Metadata about the query execution */
|
|
1456
|
+
metadata: SourceAgentMetadata;
|
|
1457
|
+
/** Tool execution info for the last successful query (backward compat) */
|
|
1458
|
+
executedTool: ExecutedToolInfo;
|
|
1459
|
+
/** All successful tool executions (primary + follow-up queries) */
|
|
1460
|
+
allExecutedTools?: ExecutedToolInfo[];
|
|
1461
|
+
/** Error message if failed */
|
|
1462
|
+
error?: string;
|
|
1463
|
+
}
|
|
1464
|
+
interface SourceAgentMetadata {
|
|
1465
|
+
/** Total rows that matched the query (before limit) */
|
|
1466
|
+
totalRowsMatched: number;
|
|
1467
|
+
/** Rows actually returned (after limit) */
|
|
1468
|
+
rowsReturned: number;
|
|
1469
|
+
/** Whether the result was truncated by the row limit */
|
|
1470
|
+
isLimited: boolean;
|
|
1471
|
+
/** The query/params that were executed */
|
|
1472
|
+
queryExecuted?: string;
|
|
1473
|
+
/** Execution time in milliseconds */
|
|
1474
|
+
executionTimeMs: number;
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* A pre-built, multi-step UI flow registered with the SDK.
|
|
1478
|
+
*
|
|
1479
|
+
* When the main agent decides a user's question matches a workflow's whenToUse
|
|
1480
|
+
* trigger, it picks the workflow instead of running source agents / generating
|
|
1481
|
+
* dashboard components. The LLM extracts the workflow's required props from the
|
|
1482
|
+
* prompt (using `propsSchema` as the tool input_schema) and the SDK returns the
|
|
1483
|
+
* workflow component directly — no analysis text, no chart generation. The
|
|
1484
|
+
* frontend renders the registered workflow component with the LLM-extracted
|
|
1485
|
+
* props.
|
|
1486
|
+
*/
|
|
1487
|
+
interface WorkflowDescriptor {
|
|
1488
|
+
/** Unique workflow id (used as the LLM tool name) */
|
|
1489
|
+
id: string;
|
|
1490
|
+
/** Component name on the frontend (matches the registered React component) */
|
|
1491
|
+
name: string;
|
|
1492
|
+
/** Short human-readable description of what this workflow does */
|
|
1493
|
+
description: string;
|
|
1494
|
+
/**
|
|
1495
|
+
* 1–2 sentence trigger condition. The LLM uses this to decide if the
|
|
1496
|
+
* user's prompt matches this workflow. Be specific — e.g.
|
|
1497
|
+
* "User wants to *initiate* an inventory transfer (review + submit POs),
|
|
1498
|
+
* not just see analysis or charts."
|
|
1499
|
+
*/
|
|
1500
|
+
whenToUse: string;
|
|
1501
|
+
/**
|
|
1502
|
+
* JSON-schema-style description of the props the workflow needs. Becomes
|
|
1503
|
+
* the LLM tool's input_schema, so the model fills these from the prompt.
|
|
1504
|
+
* Use the same shape as `params` on direct tools — string descriptors with
|
|
1505
|
+
* an optional "(optional)" suffix.
|
|
1506
|
+
*
|
|
1507
|
+
* Example:
|
|
1508
|
+
* ```
|
|
1509
|
+
* {
|
|
1510
|
+
* selectedStore: 'object — { id, name } of the source branch',
|
|
1511
|
+
* minROI: 'number (optional) — only show transfers with ROI ≥ this',
|
|
1512
|
+
* }
|
|
1513
|
+
* ```
|
|
1514
|
+
*/
|
|
1515
|
+
propsSchema: Record<string, string>;
|
|
1516
|
+
/**
|
|
1517
|
+
* Optional: static prop defaults merged with LLM-extracted props before
|
|
1518
|
+
* the component is returned. Useful for things like the embedded
|
|
1519
|
+
* `externalTool` config that the workflow uses to fetch its own data.
|
|
1520
|
+
*/
|
|
1521
|
+
defaultProps?: Record<string, any>;
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* The workflow selection captured during a routing call.
|
|
1525
|
+
* Set on AgentResponse when the LLM picks a workflow tool.
|
|
1526
|
+
*/
|
|
1527
|
+
interface SelectedWorkflow {
|
|
1528
|
+
/** Component name (matches WorkflowDescriptor.name) */
|
|
1529
|
+
name: string;
|
|
1530
|
+
/** Props extracted from the prompt + merged with workflow.defaultProps */
|
|
1531
|
+
props: Record<string, any>;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* The complete response from the multi-agent system.
|
|
1535
|
+
* Contains everything needed for text display + component generation.
|
|
1536
|
+
*/
|
|
1537
|
+
interface AgentResponse {
|
|
1538
|
+
/** Generated text response (analysis of the data) */
|
|
1539
|
+
text: string;
|
|
1540
|
+
/** All executed tools across all source agents (for component generation) */
|
|
1541
|
+
executedTools: ExecutedToolInfo[];
|
|
1542
|
+
/** Individual results from each source agent */
|
|
1543
|
+
sourceResults: SourceAgentResult[];
|
|
1544
|
+
/**
|
|
1545
|
+
* Set when the LLM routed the question to a registered workflow component.
|
|
1546
|
+
* When present, the upstream caller should skip component generation and
|
|
1547
|
+
* return this workflow as the response.
|
|
1548
|
+
*/
|
|
1549
|
+
workflow?: SelectedWorkflow;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Configuration for the multi-agent system.
|
|
1553
|
+
* Controls limits, models, and behavior.
|
|
1554
|
+
*/
|
|
1555
|
+
interface AgentConfig {
|
|
1556
|
+
/** Max rows a source agent can return (default: 50) */
|
|
1557
|
+
maxRowsPerSource: number;
|
|
1558
|
+
/** Model for the main agent (routing + analysis in one LLM call) */
|
|
1559
|
+
mainAgentModel: string;
|
|
1560
|
+
/** Model for source agent query generation */
|
|
1561
|
+
sourceAgentModel: string;
|
|
1562
|
+
/** API key for LLM calls */
|
|
1563
|
+
apiKey?: string;
|
|
1564
|
+
/** Max retry attempts per source agent */
|
|
1565
|
+
maxRetries: number;
|
|
1566
|
+
/** Max tool calling iterations for the main agent loop */
|
|
1567
|
+
maxIterations: number;
|
|
1568
|
+
/** Global knowledge base context (static, same for all users/questions — cached in system prompt) */
|
|
1569
|
+
globalKnowledgeBase?: string;
|
|
1570
|
+
/** Per-request knowledge base context (user-specific + query-matched — dynamic, not cached) */
|
|
1571
|
+
knowledgeBaseContext?: string;
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Default agent configuration
|
|
1575
|
+
*/
|
|
1576
|
+
declare const DEFAULT_AGENT_CONFIG: AgentConfig;
|
|
1577
|
+
|
|
1578
|
+
/**
|
|
1579
|
+
* Main Agent (Orchestrator)
|
|
1580
|
+
*
|
|
1581
|
+
* A single LLM.streamWithTools() call that handles everything:
|
|
1582
|
+
* - Routing: decides which source(s) to query based on summaries
|
|
1583
|
+
* - Querying: calls source tools (each wraps an independent SourceAgent)
|
|
1584
|
+
* - Direct tools: calls pre-built function tools directly with LLM-provided params
|
|
1585
|
+
* - Re-querying: if data is wrong/incomplete, calls tools again with modified intent
|
|
1586
|
+
* - Analysis: generates final text response from the data
|
|
1587
|
+
*
|
|
1588
|
+
* Two tool types:
|
|
1589
|
+
* - "source" tools: main agent sees summaries, SourceAgent handles SQL generation independently
|
|
1590
|
+
* - "direct" tools: main agent calls fn() directly with structured params (no SourceAgent)
|
|
1591
|
+
*/
|
|
1592
|
+
|
|
1593
|
+
declare class MainAgent {
|
|
1594
|
+
private externalTools;
|
|
1595
|
+
private workflows;
|
|
1596
|
+
private config;
|
|
1597
|
+
private streamBuffer;
|
|
1598
|
+
constructor(externalTools: ExternalTool[], config: AgentConfig, streamBuffer?: StreamBuffer, workflows?: WorkflowDescriptor[]);
|
|
1599
|
+
/**
|
|
1600
|
+
* Handle a user question using the multi-agent system.
|
|
1601
|
+
*
|
|
1602
|
+
* This is ONE LLM.streamWithTools() call. The LLM:
|
|
1603
|
+
* 1. Sees source summaries + direct tool descriptions in system prompt
|
|
1604
|
+
* 2. Decides which tool(s) to call (routing)
|
|
1605
|
+
* 3. Source tools → SourceAgent runs independently → returns data
|
|
1606
|
+
* 4. Direct tools → fn() called directly with LLM params → returns data
|
|
1607
|
+
* 5. Generates final analysis text
|
|
1608
|
+
*/
|
|
1609
|
+
handleQuestion(userPrompt: string, apiKey?: string, conversationHistory?: string, streamCallback?: (chunk: string) => void): Promise<AgentResponse>;
|
|
1610
|
+
/**
|
|
1611
|
+
* Execute a direct tool — call fn() with LLM-provided params, no SourceAgent.
|
|
1612
|
+
*/
|
|
1613
|
+
private handleDirectTool;
|
|
1614
|
+
/**
|
|
1615
|
+
* Build the main agent's system prompt with source summaries, direct tool descriptions,
|
|
1616
|
+
* and workflow component descriptions.
|
|
1617
|
+
*/
|
|
1618
|
+
private buildSystemPrompt;
|
|
1619
|
+
/**
|
|
1620
|
+
* Build tool definitions for source tools — summary-only descriptions.
|
|
1621
|
+
* The full schema is inside the SourceAgent which runs independently.
|
|
1622
|
+
*/
|
|
1623
|
+
private buildSourceToolDefinitions;
|
|
1624
|
+
/**
|
|
1625
|
+
* Build tool definitions for direct tools — expose their actual params.
|
|
1626
|
+
* These are called directly by the main agent LLM, no SourceAgent.
|
|
1627
|
+
*/
|
|
1628
|
+
private buildDirectToolDefinitions;
|
|
1629
|
+
/**
|
|
1630
|
+
* Capture a workflow selection. We do NOT execute anything — the LLM has
|
|
1631
|
+
* already extracted the props it wants the workflow rendered with. We
|
|
1632
|
+
* record the selection (via the capture callback) and return a short
|
|
1633
|
+
* acknowledgement so the LLM ends its turn cleanly without writing
|
|
1634
|
+
* analysis text or calling more tools.
|
|
1635
|
+
*/
|
|
1636
|
+
private handleWorkflow;
|
|
1637
|
+
/**
|
|
1638
|
+
* Build LLM tool definitions for workflow components. The workflow's
|
|
1639
|
+
* propsSchema becomes the tool's input_schema so the LLM extracts props
|
|
1640
|
+
* directly from the prompt — same mechanic as direct tools.
|
|
1641
|
+
*/
|
|
1642
|
+
private buildWorkflowToolDefinitions;
|
|
1643
|
+
/**
|
|
1644
|
+
* Format a source agent's result as a clean string for the main agent LLM.
|
|
1645
|
+
*/
|
|
1646
|
+
private formatResultForMainAgent;
|
|
1647
|
+
/**
|
|
1648
|
+
* Get source summaries (for external inspection/debugging).
|
|
1649
|
+
*/
|
|
1650
|
+
getSourceSummaries(): SourceSummary[];
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
/**
|
|
1654
|
+
* Represents an action that can be performed on a UIBlock
|
|
1655
|
+
*/
|
|
1656
|
+
interface Action {
|
|
1657
|
+
id: string;
|
|
1658
|
+
name: string;
|
|
1659
|
+
type: string;
|
|
1660
|
+
[key: string]: any;
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1309
1663
|
type SystemPrompt = string | Anthropic.Messages.TextBlockParam[];
|
|
1310
1664
|
interface LLMMessages {
|
|
1311
1665
|
sys: SystemPrompt;
|
|
@@ -1460,16 +1814,6 @@ declare class UILogCollector {
|
|
|
1460
1814
|
setUIBlockId(uiBlockId: string): void;
|
|
1461
1815
|
}
|
|
1462
1816
|
|
|
1463
|
-
/**
|
|
1464
|
-
* Represents an action that can be performed on a UIBlock
|
|
1465
|
-
*/
|
|
1466
|
-
interface Action {
|
|
1467
|
-
id: string;
|
|
1468
|
-
name: string;
|
|
1469
|
-
type: string;
|
|
1470
|
-
[key: string]: any;
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
1817
|
/**
|
|
1474
1818
|
* UIBlock represents a single user and assistant message block in a thread
|
|
1475
1819
|
* Contains user question, component metadata, component data, text response, and available actions
|
|
@@ -2115,131 +2459,39 @@ declare class QueryExecutionService {
|
|
|
2115
2459
|
getQueryCacheKey(query: any): string;
|
|
2116
2460
|
/**
|
|
2117
2461
|
* Execute a query against the database
|
|
2118
|
-
* @param query - The SQL query to execute (string or object with sql/values)
|
|
2119
|
-
* @param collections - Collections object containing database execute function
|
|
2120
|
-
* @returns Object with result data and cache key
|
|
2121
|
-
*/
|
|
2122
|
-
executeQuery(query: any, collections: any): Promise<{
|
|
2123
|
-
result: any;
|
|
2124
|
-
cacheKey: string;
|
|
2125
|
-
}>;
|
|
2126
|
-
/**
|
|
2127
|
-
* Request the LLM to fix a failed SQL query
|
|
2128
|
-
* @param failedQuery - The query that failed execution
|
|
2129
|
-
* @param errorMessage - The error message from the failed execution
|
|
2130
|
-
* @param componentContext - Context about the component
|
|
2131
|
-
* @param apiKey - Optional API key
|
|
2132
|
-
* @returns Fixed query string
|
|
2133
|
-
*/
|
|
2134
|
-
requestQueryFix(failedQuery: string, errorMessage: string, componentContext: ComponentContext, apiKey?: string): Promise<string>;
|
|
2135
|
-
/**
|
|
2136
|
-
* Validate a single component's query with retry logic
|
|
2137
|
-
* @param component - The component to validate
|
|
2138
|
-
* @param collections - Collections object containing database execute function
|
|
2139
|
-
* @param apiKey - Optional API key for LLM calls
|
|
2140
|
-
* @returns Validation result with component, query key, and result
|
|
2141
|
-
*/
|
|
2142
|
-
validateSingleQuery(component: Component, collections: any, apiKey?: string): Promise<QueryValidationResult>;
|
|
2143
|
-
/**
|
|
2144
|
-
* Validate multiple component queries in parallel
|
|
2145
|
-
* @param components - Array of components with potential queries
|
|
2146
|
-
* @param collections - Collections object containing database execute function
|
|
2147
|
-
* @param apiKey - Optional API key for LLM calls
|
|
2148
|
-
* @returns Object with validated components and query results map
|
|
2149
|
-
*/
|
|
2150
|
-
validateComponentQueries(components: Component[], collections: any, apiKey?: string): Promise<BatchValidationResult>;
|
|
2151
|
-
}
|
|
2152
|
-
|
|
2153
|
-
/**
|
|
2154
|
-
* StreamBuffer - Buffered streaming utility for smoother text delivery
|
|
2155
|
-
* Batches small chunks together and flushes at regular intervals
|
|
2156
|
-
*/
|
|
2157
|
-
type StreamCallback = (chunk: string) => void;
|
|
2158
|
-
/**
|
|
2159
|
-
* StreamBuffer class for managing buffered streaming output
|
|
2160
|
-
* Provides smooth text delivery by batching small chunks
|
|
2161
|
-
*/
|
|
2162
|
-
declare class StreamBuffer {
|
|
2163
|
-
private buffer;
|
|
2164
|
-
private flushTimer;
|
|
2165
|
-
private callback;
|
|
2166
|
-
private fullText;
|
|
2167
|
-
constructor(callback?: StreamCallback);
|
|
2168
|
-
/**
|
|
2169
|
-
* Check if the buffer has a callback configured
|
|
2170
|
-
*/
|
|
2171
|
-
hasCallback(): boolean;
|
|
2172
|
-
/**
|
|
2173
|
-
* Get all text that has been written (including already flushed)
|
|
2174
|
-
*/
|
|
2175
|
-
getFullText(): string;
|
|
2176
|
-
/**
|
|
2177
|
-
* Write a chunk to the buffer
|
|
2178
|
-
* Large chunks or chunks with newlines are flushed immediately
|
|
2179
|
-
* Small chunks are batched and flushed after a short interval
|
|
2180
|
-
*
|
|
2181
|
-
* @param chunk - Text chunk to write
|
|
2462
|
+
* @param query - The SQL query to execute (string or object with sql/values)
|
|
2463
|
+
* @param collections - Collections object containing database execute function
|
|
2464
|
+
* @returns Object with result data and cache key
|
|
2182
2465
|
*/
|
|
2183
|
-
|
|
2466
|
+
executeQuery(query: any, collections: any): Promise<{
|
|
2467
|
+
result: any;
|
|
2468
|
+
cacheKey: string;
|
|
2469
|
+
}>;
|
|
2184
2470
|
/**
|
|
2185
|
-
*
|
|
2186
|
-
*
|
|
2471
|
+
* Request the LLM to fix a failed SQL query
|
|
2472
|
+
* @param failedQuery - The query that failed execution
|
|
2473
|
+
* @param errorMessage - The error message from the failed execution
|
|
2474
|
+
* @param componentContext - Context about the component
|
|
2475
|
+
* @param apiKey - Optional API key
|
|
2476
|
+
* @returns Fixed query string
|
|
2187
2477
|
*/
|
|
2188
|
-
|
|
2478
|
+
requestQueryFix(failedQuery: string, errorMessage: string, componentContext: ComponentContext, apiKey?: string): Promise<string>;
|
|
2189
2479
|
/**
|
|
2190
|
-
*
|
|
2480
|
+
* Validate a single component's query with retry logic
|
|
2481
|
+
* @param component - The component to validate
|
|
2482
|
+
* @param collections - Collections object containing database execute function
|
|
2483
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2484
|
+
* @returns Validation result with component, query key, and result
|
|
2191
2485
|
*/
|
|
2192
|
-
|
|
2486
|
+
validateSingleQuery(component: Component, collections: any, apiKey?: string): Promise<QueryValidationResult>;
|
|
2193
2487
|
/**
|
|
2194
|
-
*
|
|
2195
|
-
*
|
|
2488
|
+
* Validate multiple component queries in parallel
|
|
2489
|
+
* @param components - Array of components with potential queries
|
|
2490
|
+
* @param collections - Collections object containing database execute function
|
|
2491
|
+
* @param apiKey - Optional API key for LLM calls
|
|
2492
|
+
* @returns Object with validated components and query results map
|
|
2196
2493
|
*/
|
|
2197
|
-
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
/**
|
|
2201
|
-
* ToolExecutorService - Handles execution of SQL queries and external tools
|
|
2202
|
-
* Extracted from BaseLLM.generateTextResponse for better separation of concerns
|
|
2203
|
-
*/
|
|
2204
|
-
|
|
2205
|
-
/**
|
|
2206
|
-
* External tool definition
|
|
2207
|
-
*/
|
|
2208
|
-
interface ExternalTool {
|
|
2209
|
-
id: string;
|
|
2210
|
-
name: string;
|
|
2211
|
-
description?: string;
|
|
2212
|
-
/** Tool type: "source" = routed through SourceAgent, "direct" = called directly by MainAgent */
|
|
2213
|
-
toolType?: 'source' | 'direct';
|
|
2214
|
-
/** Full untruncated schema for source agent (all columns visible) */
|
|
2215
|
-
fullSchema?: string;
|
|
2216
|
-
/** Schema size tier: small (≤50 tables), medium (51-200), large (201-500), very_large (500+) */
|
|
2217
|
-
schemaTier?: string;
|
|
2218
|
-
/** Schema search function for very_large tier — keyword search over entities */
|
|
2219
|
-
schemaSearchFn?: (keywords: string[]) => string;
|
|
2220
|
-
fn: (input: any) => Promise<any>;
|
|
2221
|
-
limit?: number;
|
|
2222
|
-
outputSchema?: any;
|
|
2223
|
-
executionType?: 'immediate' | 'deferred';
|
|
2224
|
-
userProvidedData?: any;
|
|
2225
|
-
params?: Record<string, any>;
|
|
2226
|
-
}
|
|
2227
|
-
/**
|
|
2228
|
-
* Executed tool tracking info
|
|
2229
|
-
*/
|
|
2230
|
-
interface ExecutedToolInfo {
|
|
2231
|
-
id: string;
|
|
2232
|
-
name: string;
|
|
2233
|
-
params: any;
|
|
2234
|
-
result: {
|
|
2235
|
-
_totalRecords: number;
|
|
2236
|
-
_recordsShown: number;
|
|
2237
|
-
_metadata?: any;
|
|
2238
|
-
_sampleData: any[];
|
|
2239
|
-
};
|
|
2240
|
-
outputSchema?: any;
|
|
2241
|
-
sourceSchema?: string;
|
|
2242
|
-
sourceType?: string;
|
|
2494
|
+
validateComponentQueries(components: Component[], collections: any, apiKey?: string): Promise<BatchValidationResult>;
|
|
2243
2495
|
}
|
|
2244
2496
|
|
|
2245
2497
|
/**
|
|
@@ -2597,179 +2849,6 @@ declare class DashboardConversationHistory {
|
|
|
2597
2849
|
}
|
|
2598
2850
|
declare const dashboardConversationHistory: DashboardConversationHistory;
|
|
2599
2851
|
|
|
2600
|
-
/**
|
|
2601
|
-
* Multi-Agent Architecture Types
|
|
2602
|
-
*
|
|
2603
|
-
* Defines interfaces for the hierarchical agent system:
|
|
2604
|
-
* - Main Agent: ONE LLM.streamWithTools() call with source agent tools
|
|
2605
|
-
* - Source Agents: independent agents that query individual data sources
|
|
2606
|
-
*
|
|
2607
|
-
* The main agent sees only source summaries. When it calls a source tool,
|
|
2608
|
-
* the SourceAgent runs independently (own LLM, own retries) and returns clean data.
|
|
2609
|
-
*/
|
|
2610
|
-
|
|
2611
|
-
/**
|
|
2612
|
-
* Per-entity detail: name, row count, and column names.
|
|
2613
|
-
* Gives the main agent enough context to route to the right source.
|
|
2614
|
-
*/
|
|
2615
|
-
interface EntityDetail {
|
|
2616
|
-
/** Entity name (table, sheet, endpoint) */
|
|
2617
|
-
name: string;
|
|
2618
|
-
/** Approximate row count */
|
|
2619
|
-
rowCount?: number;
|
|
2620
|
-
/** Column/field names */
|
|
2621
|
-
columns: string[];
|
|
2622
|
-
}
|
|
2623
|
-
/**
|
|
2624
|
-
* Representation of a data source for the main agent.
|
|
2625
|
-
* Contains entity names WITH column names so the LLM can route accurately.
|
|
2626
|
-
*/
|
|
2627
|
-
interface SourceSummary {
|
|
2628
|
-
/** Source ID (matches tool ID prefix) */
|
|
2629
|
-
id: string;
|
|
2630
|
-
/** Human-readable source name */
|
|
2631
|
-
name: string;
|
|
2632
|
-
/** Source type: postgres, excel, rest_api, etc. */
|
|
2633
|
-
type: string;
|
|
2634
|
-
/** Brief description of what data this source contains */
|
|
2635
|
-
description: string;
|
|
2636
|
-
/** Detailed entity info with column names for routing */
|
|
2637
|
-
entityDetails: EntityDetail[];
|
|
2638
|
-
/** The tool ID associated with this source */
|
|
2639
|
-
toolId: string;
|
|
2640
|
-
}
|
|
2641
|
-
/**
|
|
2642
|
-
* What a source agent returns after querying its data source.
|
|
2643
|
-
* The main agent uses this to analyze and compose the final response.
|
|
2644
|
-
*/
|
|
2645
|
-
interface SourceAgentResult {
|
|
2646
|
-
/** Source ID */
|
|
2647
|
-
sourceId: string;
|
|
2648
|
-
/** Source name */
|
|
2649
|
-
sourceName: string;
|
|
2650
|
-
/** Whether the query succeeded */
|
|
2651
|
-
success: boolean;
|
|
2652
|
-
/** Result data rows */
|
|
2653
|
-
data: any[];
|
|
2654
|
-
/** Metadata about the query execution */
|
|
2655
|
-
metadata: SourceAgentMetadata;
|
|
2656
|
-
/** Tool execution info for the last successful query (backward compat) */
|
|
2657
|
-
executedTool: ExecutedToolInfo;
|
|
2658
|
-
/** All successful tool executions (primary + follow-up queries) */
|
|
2659
|
-
allExecutedTools?: ExecutedToolInfo[];
|
|
2660
|
-
/** Error message if failed */
|
|
2661
|
-
error?: string;
|
|
2662
|
-
}
|
|
2663
|
-
interface SourceAgentMetadata {
|
|
2664
|
-
/** Total rows that matched the query (before limit) */
|
|
2665
|
-
totalRowsMatched: number;
|
|
2666
|
-
/** Rows actually returned (after limit) */
|
|
2667
|
-
rowsReturned: number;
|
|
2668
|
-
/** Whether the result was truncated by the row limit */
|
|
2669
|
-
isLimited: boolean;
|
|
2670
|
-
/** The query/params that were executed */
|
|
2671
|
-
queryExecuted?: string;
|
|
2672
|
-
/** Execution time in milliseconds */
|
|
2673
|
-
executionTimeMs: number;
|
|
2674
|
-
}
|
|
2675
|
-
/**
|
|
2676
|
-
* The complete response from the multi-agent system.
|
|
2677
|
-
* Contains everything needed for text display + component generation.
|
|
2678
|
-
*/
|
|
2679
|
-
interface AgentResponse {
|
|
2680
|
-
/** Generated text response (analysis of the data) */
|
|
2681
|
-
text: string;
|
|
2682
|
-
/** All executed tools across all source agents (for component generation) */
|
|
2683
|
-
executedTools: ExecutedToolInfo[];
|
|
2684
|
-
/** Individual results from each source agent */
|
|
2685
|
-
sourceResults: SourceAgentResult[];
|
|
2686
|
-
}
|
|
2687
|
-
/**
|
|
2688
|
-
* Configuration for the multi-agent system.
|
|
2689
|
-
* Controls limits, models, and behavior.
|
|
2690
|
-
*/
|
|
2691
|
-
interface AgentConfig {
|
|
2692
|
-
/** Max rows a source agent can return (default: 50) */
|
|
2693
|
-
maxRowsPerSource: number;
|
|
2694
|
-
/** Model for the main agent (routing + analysis in one LLM call) */
|
|
2695
|
-
mainAgentModel: string;
|
|
2696
|
-
/** Model for source agent query generation */
|
|
2697
|
-
sourceAgentModel: string;
|
|
2698
|
-
/** API key for LLM calls */
|
|
2699
|
-
apiKey?: string;
|
|
2700
|
-
/** Max retry attempts per source agent */
|
|
2701
|
-
maxRetries: number;
|
|
2702
|
-
/** Max tool calling iterations for the main agent loop */
|
|
2703
|
-
maxIterations: number;
|
|
2704
|
-
/** Global knowledge base context (static, same for all users/questions — cached in system prompt) */
|
|
2705
|
-
globalKnowledgeBase?: string;
|
|
2706
|
-
/** Per-request knowledge base context (user-specific + query-matched — dynamic, not cached) */
|
|
2707
|
-
knowledgeBaseContext?: string;
|
|
2708
|
-
}
|
|
2709
|
-
/**
|
|
2710
|
-
* Default agent configuration
|
|
2711
|
-
*/
|
|
2712
|
-
declare const DEFAULT_AGENT_CONFIG: AgentConfig;
|
|
2713
|
-
|
|
2714
|
-
/**
|
|
2715
|
-
* Main Agent (Orchestrator)
|
|
2716
|
-
*
|
|
2717
|
-
* A single LLM.streamWithTools() call that handles everything:
|
|
2718
|
-
* - Routing: decides which source(s) to query based on summaries
|
|
2719
|
-
* - Querying: calls source tools (each wraps an independent SourceAgent)
|
|
2720
|
-
* - Direct tools: calls pre-built function tools directly with LLM-provided params
|
|
2721
|
-
* - Re-querying: if data is wrong/incomplete, calls tools again with modified intent
|
|
2722
|
-
* - Analysis: generates final text response from the data
|
|
2723
|
-
*
|
|
2724
|
-
* Two tool types:
|
|
2725
|
-
* - "source" tools: main agent sees summaries, SourceAgent handles SQL generation independently
|
|
2726
|
-
* - "direct" tools: main agent calls fn() directly with structured params (no SourceAgent)
|
|
2727
|
-
*/
|
|
2728
|
-
|
|
2729
|
-
declare class MainAgent {
|
|
2730
|
-
private externalTools;
|
|
2731
|
-
private config;
|
|
2732
|
-
private streamBuffer;
|
|
2733
|
-
constructor(externalTools: ExternalTool[], config: AgentConfig, streamBuffer?: StreamBuffer);
|
|
2734
|
-
/**
|
|
2735
|
-
* Handle a user question using the multi-agent system.
|
|
2736
|
-
*
|
|
2737
|
-
* This is ONE LLM.streamWithTools() call. The LLM:
|
|
2738
|
-
* 1. Sees source summaries + direct tool descriptions in system prompt
|
|
2739
|
-
* 2. Decides which tool(s) to call (routing)
|
|
2740
|
-
* 3. Source tools → SourceAgent runs independently → returns data
|
|
2741
|
-
* 4. Direct tools → fn() called directly with LLM params → returns data
|
|
2742
|
-
* 5. Generates final analysis text
|
|
2743
|
-
*/
|
|
2744
|
-
handleQuestion(userPrompt: string, apiKey?: string, conversationHistory?: string, streamCallback?: (chunk: string) => void): Promise<AgentResponse>;
|
|
2745
|
-
/**
|
|
2746
|
-
* Execute a direct tool — call fn() with LLM-provided params, no SourceAgent.
|
|
2747
|
-
*/
|
|
2748
|
-
private handleDirectTool;
|
|
2749
|
-
/**
|
|
2750
|
-
* Build the main agent's system prompt with source summaries and direct tool descriptions.
|
|
2751
|
-
*/
|
|
2752
|
-
private buildSystemPrompt;
|
|
2753
|
-
/**
|
|
2754
|
-
* Build tool definitions for source tools — summary-only descriptions.
|
|
2755
|
-
* The full schema is inside the SourceAgent which runs independently.
|
|
2756
|
-
*/
|
|
2757
|
-
private buildSourceToolDefinitions;
|
|
2758
|
-
/**
|
|
2759
|
-
* Build tool definitions for direct tools — expose their actual params.
|
|
2760
|
-
* These are called directly by the main agent LLM, no SourceAgent.
|
|
2761
|
-
*/
|
|
2762
|
-
private buildDirectToolDefinitions;
|
|
2763
|
-
/**
|
|
2764
|
-
* Format a source agent's result as a clean string for the main agent LLM.
|
|
2765
|
-
*/
|
|
2766
|
-
private formatResultForMainAgent;
|
|
2767
|
-
/**
|
|
2768
|
-
* Get source summaries (for external inspection/debugging).
|
|
2769
|
-
*/
|
|
2770
|
-
getSourceSummaries(): SourceSummary[];
|
|
2771
|
-
}
|
|
2772
|
-
|
|
2773
2852
|
type MessageTypeHandler = (message: IncomingMessage) => void | Promise<void>;
|
|
2774
2853
|
declare class SuperatomSDK {
|
|
2775
2854
|
private ws;
|
|
@@ -2786,6 +2865,7 @@ declare class SuperatomSDK {
|
|
|
2786
2865
|
private collections;
|
|
2787
2866
|
private components;
|
|
2788
2867
|
private tools;
|
|
2868
|
+
private workflows;
|
|
2789
2869
|
private anthropicApiKey;
|
|
2790
2870
|
private groqApiKey;
|
|
2791
2871
|
private geminiApiKey;
|
|
@@ -2895,6 +2975,19 @@ declare class SuperatomSDK {
|
|
|
2895
2975
|
* Get the stored tools
|
|
2896
2976
|
*/
|
|
2897
2977
|
getTools(): Tool$1[];
|
|
2978
|
+
/**
|
|
2979
|
+
* Register workflow components for the SDK instance.
|
|
2980
|
+
*
|
|
2981
|
+
* Workflows are pre-built multi-step UI flows the main agent can pick when
|
|
2982
|
+
* the user's prompt matches a workflow's `whenToUse` trigger. Picking a
|
|
2983
|
+
* workflow short-circuits analysis text + dashboard component generation —
|
|
2984
|
+
* the workflow component is returned directly, with the LLM-extracted props.
|
|
2985
|
+
*/
|
|
2986
|
+
setWorkflows(workflows: WorkflowDescriptor[]): void;
|
|
2987
|
+
/**
|
|
2988
|
+
* Get the registered workflow components.
|
|
2989
|
+
*/
|
|
2990
|
+
getWorkflows(): WorkflowDescriptor[];
|
|
2898
2991
|
/**
|
|
2899
2992
|
* Apply model strategy to all LLM provider singletons
|
|
2900
2993
|
* @param strategy - 'best', 'fast', or 'balanced'
|
|
@@ -2925,4 +3018,4 @@ declare class SuperatomSDK {
|
|
|
2925
3018
|
getConversationSimilarityThreshold(): number;
|
|
2926
3019
|
}
|
|
2927
3020
|
|
|
2928
|
-
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 };
|
|
3021
|
+
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 };
|