MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / getAIChatTokenUsage

Method getAIChatTokenUsage

packages/node-runtime/src/ai/chats.ts:837–857  ·  view source on GitHub ↗
(aiChatId: string)

Source from the content-addressed store, hash-verified

835 }
836
837 getAIChatTokenUsage(aiChatId: string): TokenUsageData {
838 const rows = this.getActivePathRows(aiChatId)
839 const result: TokenUsageData = {
840 promptTokens: 0,
841 completionTokens: 0,
842 totalTokens: 0,
843 cacheReadTokens: 0,
844 cacheWriteTokens: 0,
845 }
846 for (const row of rows) {
847 if (row.tokenUsage) {
848 const usage = JSON.parse(row.tokenUsage) as TokenUsageData
849 result.promptTokens += usage.promptTokens
850 result.completionTokens += usage.completionTokens
851 result.totalTokens += usage.totalTokens
852 result.cacheReadTokens! += usage.cacheReadTokens || 0
853 result.cacheWriteTokens! += usage.cacheWriteTokens || 0
854 }
855 }
856 return result
857 }
858
859 // ==================== Debug context ====================
860

Callers

nothing calls this directly

Calls 2

getActivePathRowsMethod · 0.95
parseMethod · 0.80

Tested by

no test coverage detected