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:
hailin 2026-01-23 08:27:03 -08:00
parent 849a4a3099
commit dd66c3a892
2 changed files with 9 additions and 2 deletions

View File

@ -370,7 +370,7 @@ export class ClaudeAgentService implements OnModuleInit {
totalInputTokens += finalMsg.usage.input_tokens || 0;
totalOutputTokens += finalMsg.usage.output_tokens || 0;
// 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;
totalCacheReadTokens += usage.cache_read_input_tokens || 0;
}

View File

@ -11,7 +11,14 @@ import { TokenUsageEntity } from '../../domain/entities/token-usage.entity';
* - Cache write: $3.75/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': {
input: 3 / 1_000_000,
output: 15 / 1_000_000,