@superatomai/sdk-node 0.0.38 → 0.0.40
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 +115 -1
- package/dist/index.d.ts +115 -1
- package/dist/index.js +1117 -235
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1114 -234
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1548,6 +1548,120 @@ declare const CONTEXT_CONFIG: {
|
|
|
1548
1548
|
MAX_CONVERSATION_CONTEXT_BLOCKS: number;
|
|
1549
1549
|
};
|
|
1550
1550
|
|
|
1551
|
+
/**
|
|
1552
|
+
* LLM Usage Logger - Tracks token usage, costs, and timing for all LLM API calls
|
|
1553
|
+
*/
|
|
1554
|
+
interface LLMUsageEntry {
|
|
1555
|
+
timestamp: string;
|
|
1556
|
+
requestId: string;
|
|
1557
|
+
provider: string;
|
|
1558
|
+
model: string;
|
|
1559
|
+
method: string;
|
|
1560
|
+
inputTokens: number;
|
|
1561
|
+
outputTokens: number;
|
|
1562
|
+
cacheReadTokens?: number;
|
|
1563
|
+
cacheWriteTokens?: number;
|
|
1564
|
+
totalTokens: number;
|
|
1565
|
+
costUSD: number;
|
|
1566
|
+
durationMs: number;
|
|
1567
|
+
toolCalls?: number;
|
|
1568
|
+
success: boolean;
|
|
1569
|
+
error?: string;
|
|
1570
|
+
}
|
|
1571
|
+
declare class LLMUsageLogger {
|
|
1572
|
+
private logStream;
|
|
1573
|
+
private logPath;
|
|
1574
|
+
private enabled;
|
|
1575
|
+
private sessionStats;
|
|
1576
|
+
constructor();
|
|
1577
|
+
private initLogStream;
|
|
1578
|
+
private writeHeader;
|
|
1579
|
+
/**
|
|
1580
|
+
* Calculate cost based on token usage and model
|
|
1581
|
+
*/
|
|
1582
|
+
calculateCost(model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheWriteTokens?: number): number;
|
|
1583
|
+
/**
|
|
1584
|
+
* Log an LLM API call
|
|
1585
|
+
*/
|
|
1586
|
+
log(entry: LLMUsageEntry): void;
|
|
1587
|
+
/**
|
|
1588
|
+
* Log session summary (call at end of request)
|
|
1589
|
+
*/
|
|
1590
|
+
logSessionSummary(requestContext?: string): void;
|
|
1591
|
+
/**
|
|
1592
|
+
* Reset session stats (call at start of new user request)
|
|
1593
|
+
*/
|
|
1594
|
+
resetSession(): void;
|
|
1595
|
+
/**
|
|
1596
|
+
* Reset the log file for a new request (clears previous logs)
|
|
1597
|
+
* Call this at the start of each USER_PROMPT_REQ
|
|
1598
|
+
*/
|
|
1599
|
+
resetLogFile(requestContext?: string): void;
|
|
1600
|
+
/**
|
|
1601
|
+
* Get current session stats
|
|
1602
|
+
*/
|
|
1603
|
+
getSessionStats(): {
|
|
1604
|
+
totalCalls: number;
|
|
1605
|
+
totalInputTokens: number;
|
|
1606
|
+
totalOutputTokens: number;
|
|
1607
|
+
totalCacheReadTokens: number;
|
|
1608
|
+
totalCacheWriteTokens: number;
|
|
1609
|
+
totalCostUSD: number;
|
|
1610
|
+
totalDurationMs: number;
|
|
1611
|
+
};
|
|
1612
|
+
/**
|
|
1613
|
+
* Generate a unique request ID
|
|
1614
|
+
*/
|
|
1615
|
+
generateRequestId(): string;
|
|
1616
|
+
}
|
|
1617
|
+
declare const llmUsageLogger: LLMUsageLogger;
|
|
1618
|
+
|
|
1619
|
+
/**
|
|
1620
|
+
* User Prompt Error Logger - Captures detailed errors for USER_PROMPT_REQ
|
|
1621
|
+
* Logs full error details including raw strings for parse failures
|
|
1622
|
+
*/
|
|
1623
|
+
declare class UserPromptErrorLogger {
|
|
1624
|
+
private logStream;
|
|
1625
|
+
private logPath;
|
|
1626
|
+
private enabled;
|
|
1627
|
+
private hasErrors;
|
|
1628
|
+
constructor();
|
|
1629
|
+
/**
|
|
1630
|
+
* Reset the error log file for a new request
|
|
1631
|
+
*/
|
|
1632
|
+
resetLogFile(requestContext?: string): void;
|
|
1633
|
+
/**
|
|
1634
|
+
* Log a JSON parse error with the raw string that failed
|
|
1635
|
+
*/
|
|
1636
|
+
logJsonParseError(context: string, rawString: string, error: Error): void;
|
|
1637
|
+
/**
|
|
1638
|
+
* Log a general error with full details
|
|
1639
|
+
*/
|
|
1640
|
+
logError(context: string, error: Error | string, additionalData?: Record<string, any>): void;
|
|
1641
|
+
/**
|
|
1642
|
+
* Log a SQL query error with the full query
|
|
1643
|
+
*/
|
|
1644
|
+
logSqlError(query: string, error: Error | string, params?: any[]): void;
|
|
1645
|
+
/**
|
|
1646
|
+
* Log an LLM API error
|
|
1647
|
+
*/
|
|
1648
|
+
logLlmError(provider: string, model: string, method: string, error: Error | string, requestData?: any): void;
|
|
1649
|
+
/**
|
|
1650
|
+
* Log tool execution error
|
|
1651
|
+
*/
|
|
1652
|
+
logToolError(toolName: string, toolInput: any, error: Error | string): void;
|
|
1653
|
+
/**
|
|
1654
|
+
* Write final summary if there were errors
|
|
1655
|
+
*/
|
|
1656
|
+
writeSummary(): void;
|
|
1657
|
+
/**
|
|
1658
|
+
* Check if any errors were logged
|
|
1659
|
+
*/
|
|
1660
|
+
hadErrors(): boolean;
|
|
1661
|
+
private write;
|
|
1662
|
+
}
|
|
1663
|
+
declare const userPromptErrorLogger: UserPromptErrorLogger;
|
|
1664
|
+
|
|
1551
1665
|
/**
|
|
1552
1666
|
* BM25L Reranker for hybrid semantic search
|
|
1553
1667
|
*
|
|
@@ -1798,4 +1912,4 @@ declare class SuperatomSDK {
|
|
|
1798
1912
|
getTools(): Tool$1[];
|
|
1799
1913
|
}
|
|
1800
1914
|
|
|
1801
|
-
export { type Action, BM25L, type BM25LOptions, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type DatabaseType, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LogLevel, type Message, type RerankedResult, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, hybridRerank, logger, rerankChromaResults, rerankConversationResults };
|
|
1915
|
+
export { type Action, BM25L, type BM25LOptions, 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 RerankedResult, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, hybridRerank, llmUsageLogger, logger, rerankChromaResults, rerankConversationResults, userPromptErrorLogger };
|
package/dist/index.d.ts
CHANGED
|
@@ -1548,6 +1548,120 @@ declare const CONTEXT_CONFIG: {
|
|
|
1548
1548
|
MAX_CONVERSATION_CONTEXT_BLOCKS: number;
|
|
1549
1549
|
};
|
|
1550
1550
|
|
|
1551
|
+
/**
|
|
1552
|
+
* LLM Usage Logger - Tracks token usage, costs, and timing for all LLM API calls
|
|
1553
|
+
*/
|
|
1554
|
+
interface LLMUsageEntry {
|
|
1555
|
+
timestamp: string;
|
|
1556
|
+
requestId: string;
|
|
1557
|
+
provider: string;
|
|
1558
|
+
model: string;
|
|
1559
|
+
method: string;
|
|
1560
|
+
inputTokens: number;
|
|
1561
|
+
outputTokens: number;
|
|
1562
|
+
cacheReadTokens?: number;
|
|
1563
|
+
cacheWriteTokens?: number;
|
|
1564
|
+
totalTokens: number;
|
|
1565
|
+
costUSD: number;
|
|
1566
|
+
durationMs: number;
|
|
1567
|
+
toolCalls?: number;
|
|
1568
|
+
success: boolean;
|
|
1569
|
+
error?: string;
|
|
1570
|
+
}
|
|
1571
|
+
declare class LLMUsageLogger {
|
|
1572
|
+
private logStream;
|
|
1573
|
+
private logPath;
|
|
1574
|
+
private enabled;
|
|
1575
|
+
private sessionStats;
|
|
1576
|
+
constructor();
|
|
1577
|
+
private initLogStream;
|
|
1578
|
+
private writeHeader;
|
|
1579
|
+
/**
|
|
1580
|
+
* Calculate cost based on token usage and model
|
|
1581
|
+
*/
|
|
1582
|
+
calculateCost(model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheWriteTokens?: number): number;
|
|
1583
|
+
/**
|
|
1584
|
+
* Log an LLM API call
|
|
1585
|
+
*/
|
|
1586
|
+
log(entry: LLMUsageEntry): void;
|
|
1587
|
+
/**
|
|
1588
|
+
* Log session summary (call at end of request)
|
|
1589
|
+
*/
|
|
1590
|
+
logSessionSummary(requestContext?: string): void;
|
|
1591
|
+
/**
|
|
1592
|
+
* Reset session stats (call at start of new user request)
|
|
1593
|
+
*/
|
|
1594
|
+
resetSession(): void;
|
|
1595
|
+
/**
|
|
1596
|
+
* Reset the log file for a new request (clears previous logs)
|
|
1597
|
+
* Call this at the start of each USER_PROMPT_REQ
|
|
1598
|
+
*/
|
|
1599
|
+
resetLogFile(requestContext?: string): void;
|
|
1600
|
+
/**
|
|
1601
|
+
* Get current session stats
|
|
1602
|
+
*/
|
|
1603
|
+
getSessionStats(): {
|
|
1604
|
+
totalCalls: number;
|
|
1605
|
+
totalInputTokens: number;
|
|
1606
|
+
totalOutputTokens: number;
|
|
1607
|
+
totalCacheReadTokens: number;
|
|
1608
|
+
totalCacheWriteTokens: number;
|
|
1609
|
+
totalCostUSD: number;
|
|
1610
|
+
totalDurationMs: number;
|
|
1611
|
+
};
|
|
1612
|
+
/**
|
|
1613
|
+
* Generate a unique request ID
|
|
1614
|
+
*/
|
|
1615
|
+
generateRequestId(): string;
|
|
1616
|
+
}
|
|
1617
|
+
declare const llmUsageLogger: LLMUsageLogger;
|
|
1618
|
+
|
|
1619
|
+
/**
|
|
1620
|
+
* User Prompt Error Logger - Captures detailed errors for USER_PROMPT_REQ
|
|
1621
|
+
* Logs full error details including raw strings for parse failures
|
|
1622
|
+
*/
|
|
1623
|
+
declare class UserPromptErrorLogger {
|
|
1624
|
+
private logStream;
|
|
1625
|
+
private logPath;
|
|
1626
|
+
private enabled;
|
|
1627
|
+
private hasErrors;
|
|
1628
|
+
constructor();
|
|
1629
|
+
/**
|
|
1630
|
+
* Reset the error log file for a new request
|
|
1631
|
+
*/
|
|
1632
|
+
resetLogFile(requestContext?: string): void;
|
|
1633
|
+
/**
|
|
1634
|
+
* Log a JSON parse error with the raw string that failed
|
|
1635
|
+
*/
|
|
1636
|
+
logJsonParseError(context: string, rawString: string, error: Error): void;
|
|
1637
|
+
/**
|
|
1638
|
+
* Log a general error with full details
|
|
1639
|
+
*/
|
|
1640
|
+
logError(context: string, error: Error | string, additionalData?: Record<string, any>): void;
|
|
1641
|
+
/**
|
|
1642
|
+
* Log a SQL query error with the full query
|
|
1643
|
+
*/
|
|
1644
|
+
logSqlError(query: string, error: Error | string, params?: any[]): void;
|
|
1645
|
+
/**
|
|
1646
|
+
* Log an LLM API error
|
|
1647
|
+
*/
|
|
1648
|
+
logLlmError(provider: string, model: string, method: string, error: Error | string, requestData?: any): void;
|
|
1649
|
+
/**
|
|
1650
|
+
* Log tool execution error
|
|
1651
|
+
*/
|
|
1652
|
+
logToolError(toolName: string, toolInput: any, error: Error | string): void;
|
|
1653
|
+
/**
|
|
1654
|
+
* Write final summary if there were errors
|
|
1655
|
+
*/
|
|
1656
|
+
writeSummary(): void;
|
|
1657
|
+
/**
|
|
1658
|
+
* Check if any errors were logged
|
|
1659
|
+
*/
|
|
1660
|
+
hadErrors(): boolean;
|
|
1661
|
+
private write;
|
|
1662
|
+
}
|
|
1663
|
+
declare const userPromptErrorLogger: UserPromptErrorLogger;
|
|
1664
|
+
|
|
1551
1665
|
/**
|
|
1552
1666
|
* BM25L Reranker for hybrid semantic search
|
|
1553
1667
|
*
|
|
@@ -1798,4 +1912,4 @@ declare class SuperatomSDK {
|
|
|
1798
1912
|
getTools(): Tool$1[];
|
|
1799
1913
|
}
|
|
1800
1914
|
|
|
1801
|
-
export { type Action, BM25L, type BM25LOptions, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type DatabaseType, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LogLevel, type Message, type RerankedResult, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, hybridRerank, logger, rerankChromaResults, rerankConversationResults };
|
|
1915
|
+
export { type Action, BM25L, type BM25LOptions, 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 RerankedResult, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, hybridRerank, llmUsageLogger, logger, rerankChromaResults, rerankConversationResults, userPromptErrorLogger };
|