trickle-observe 0.2.125 → 0.2.126
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/llm-observer.js +4 -0
- package/package.json +1 -1
- package/src/llm-observer.ts +6 -0
package/dist/llm-observer.js
CHANGED
|
@@ -496,12 +496,16 @@ function handleAnthropicStream(stream, params, startTime, debug) {
|
|
|
496
496
|
function captureAnthropicResponse(params, response, startTime, debug) {
|
|
497
497
|
const usage = response.usage || {};
|
|
498
498
|
const outputText = response.content?.map((c) => c.text || '').join('') || '';
|
|
499
|
+
const cacheRead = usage.cache_read_input_tokens || 0;
|
|
500
|
+
const cacheWrite = usage.cache_creation_input_tokens || 0;
|
|
499
501
|
const event = {
|
|
500
502
|
kind: 'llm_call', provider: 'anthropic', model: response.model || params.model || 'unknown',
|
|
501
503
|
durationMs: round(performance.now() - startTime),
|
|
502
504
|
inputTokens: usage.input_tokens || 0, outputTokens: usage.output_tokens || 0,
|
|
503
505
|
totalTokens: (usage.input_tokens || 0) + (usage.output_tokens || 0),
|
|
504
506
|
estimatedCostUsd: estimateCost(response.model || params.model || '', usage.input_tokens || 0, usage.output_tokens || 0),
|
|
507
|
+
...(cacheRead > 0 ? { cacheReadTokens: cacheRead } : {}),
|
|
508
|
+
...(cacheWrite > 0 ? { cacheWriteTokens: cacheWrite } : {}),
|
|
505
509
|
stream: false, finishReason: response.stop_reason || 'unknown',
|
|
506
510
|
temperature: params.temperature, maxTokens: params.max_tokens,
|
|
507
511
|
systemPrompt: typeof params.system === 'string' ? truncate(params.system, 200) : undefined,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trickle-observe",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.126",
|
|
4
4
|
"description": "Zero-code runtime observability for JavaScript/TypeScript. Auto-instruments Express, OpenAI, Anthropic, Gemini, MCP. Captures functions, variables, LLM calls, agent workflows.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/llm-observer.ts
CHANGED
|
@@ -67,6 +67,8 @@ interface LlmEvent {
|
|
|
67
67
|
outputTokens: number;
|
|
68
68
|
totalTokens: number;
|
|
69
69
|
estimatedCostUsd: number;
|
|
70
|
+
cacheReadTokens?: number;
|
|
71
|
+
cacheWriteTokens?: number;
|
|
70
72
|
stream: boolean;
|
|
71
73
|
finishReason: string;
|
|
72
74
|
temperature?: number;
|
|
@@ -486,12 +488,16 @@ function handleAnthropicStream(stream: any, params: any, startTime: number, debu
|
|
|
486
488
|
function captureAnthropicResponse(params: any, response: any, startTime: number, debug: boolean): void {
|
|
487
489
|
const usage = response.usage || {};
|
|
488
490
|
const outputText = response.content?.map((c: any) => c.text || '').join('') || '';
|
|
491
|
+
const cacheRead = usage.cache_read_input_tokens || 0;
|
|
492
|
+
const cacheWrite = usage.cache_creation_input_tokens || 0;
|
|
489
493
|
const event: LlmEvent = {
|
|
490
494
|
kind: 'llm_call', provider: 'anthropic', model: response.model || params.model || 'unknown',
|
|
491
495
|
durationMs: round(performance.now() - startTime),
|
|
492
496
|
inputTokens: usage.input_tokens || 0, outputTokens: usage.output_tokens || 0,
|
|
493
497
|
totalTokens: (usage.input_tokens || 0) + (usage.output_tokens || 0),
|
|
494
498
|
estimatedCostUsd: estimateCost(response.model || params.model || '', usage.input_tokens || 0, usage.output_tokens || 0),
|
|
499
|
+
...(cacheRead > 0 ? { cacheReadTokens: cacheRead } : {}),
|
|
500
|
+
...(cacheWrite > 0 ? { cacheWriteTokens: cacheWrite } : {}),
|
|
495
501
|
stream: false, finishReason: response.stop_reason || 'unknown',
|
|
496
502
|
temperature: params.temperature, maxTokens: params.max_tokens,
|
|
497
503
|
systemPrompt: typeof params.system === 'string' ? truncate(params.system, 200) : undefined,
|