fix(conversation): resolve TypeScript type errors in token tracking
- Fix Usage type cast by using unknown intermediate type - Add PricingTier interface and proper Record type for PRICING Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
849a4a3099
commit
dd66c3a892
|
|
@ -370,7 +370,7 @@ export class ClaudeAgentService implements OnModuleInit {
|
||||||
totalInputTokens += finalMsg.usage.input_tokens || 0;
|
totalInputTokens += finalMsg.usage.input_tokens || 0;
|
||||||
totalOutputTokens += finalMsg.usage.output_tokens || 0;
|
totalOutputTokens += finalMsg.usage.output_tokens || 0;
|
||||||
// Prompt Caching 的 tokens (如果 API 返回)
|
// Prompt Caching 的 tokens (如果 API 返回)
|
||||||
const usage = finalMsg.usage as Record<string, number>;
|
const usage = finalMsg.usage as unknown as Record<string, number>;
|
||||||
totalCacheCreationTokens += usage.cache_creation_input_tokens || 0;
|
totalCacheCreationTokens += usage.cache_creation_input_tokens || 0;
|
||||||
totalCacheReadTokens += usage.cache_read_input_tokens || 0;
|
totalCacheReadTokens += usage.cache_read_input_tokens || 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,14 @@ import { TokenUsageEntity } from '../../domain/entities/token-usage.entity';
|
||||||
* - Cache write: $3.75/MTok
|
* - Cache write: $3.75/MTok
|
||||||
* - Cache read: $0.30/MTok
|
* - Cache read: $0.30/MTok
|
||||||
*/
|
*/
|
||||||
const PRICING = {
|
interface PricingTier {
|
||||||
|
input: number;
|
||||||
|
output: number;
|
||||||
|
cacheWrite: number;
|
||||||
|
cacheRead: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PRICING: Record<string, PricingTier> = {
|
||||||
'claude-sonnet-4-20250514': {
|
'claude-sonnet-4-20250514': {
|
||||||
input: 3 / 1_000_000,
|
input: 3 / 1_000_000,
|
||||||
output: 15 / 1_000_000,
|
output: 15 / 1_000_000,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue