feat: 扩展 cache creation token 细分统计与 effective_input_tokens 计费逻辑

- 新增 cache_creation_ephemeral_5m/1h_input_tokens 字段,区分不同 TTL 的缓存写入 token
- 引入 effective_input_tokens(扣除 cache read 后的有效输入 token),暴露给 usage 接口
- billing 规则生成器支持 5m/1h ephemeral cache 独立定价与分级计费
- usage_mapper 增加 Claude/Anthropic 格式映射,修复 OpenAI responses 格式字段兼容性
- 迁移逻辑增强:支持 checksum 容错、applied/pending 数量日志、逐步执行信息输出
- executor 抽离 LocalExecutionRequestOutcome 类型,统一 sync/stream 路径返回语义
- provider-transport auth 层新增 complete passthrough headers 构建逻辑
- 前端 usage 类型全面补充 effective_input_tokens、cache_creation_tokens、total_input_context 字段
This commit is contained in:
fawney19
2026-04-10 17:44:55 +08:00
parent 5014e2f5fd
commit 010ab127e2
64 changed files with 4217 additions and 477 deletions
@@ -110,6 +110,7 @@ export function useUsageData(options: UseUsageDataOptions) {
model: item.model,
request_count: item.request_count || 0,
total_tokens: item.total_tokens || 0,
effective_input_tokens: typeof raw.effective_input_tokens === 'number' ? raw.effective_input_tokens : 0,
total_input_context: typeof raw.total_input_context === 'number' ? raw.total_input_context : 0,
output_tokens: typeof raw.output_tokens === 'number' ? raw.output_tokens : 0,
cache_read_tokens: typeof raw.cache_read_tokens === 'number' ? raw.cache_read_tokens : 0,
@@ -129,6 +130,7 @@ export function useUsageData(options: UseUsageDataOptions) {
provider: item.provider,
requests: item.request_count,
totalTokens: item.total_tokens || 0,
effectiveInputTokens: item.effective_input_tokens || 0,
totalInputContext: item.total_input_context || 0,
outputTokens: item.output_tokens || 0,
cacheReadTokens: item.cache_read_tokens || 0,
@@ -151,6 +153,7 @@ export function useUsageData(options: UseUsageDataOptions) {
api_format: item.api_format,
request_count: item.request_count || 0,
total_tokens: item.total_tokens || 0,
effective_input_tokens: item.effective_input_tokens || 0,
total_input_context: item.total_input_context || 0,
output_tokens: item.output_tokens || 0,
cache_read_tokens: item.cache_read_tokens || 0,
@@ -188,6 +191,7 @@ export function useUsageData(options: UseUsageDataOptions) {
model: item.model,
request_count: item.requests || 0,
total_tokens: item.total_tokens || 0,
effective_input_tokens: item.effective_input_tokens || 0,
total_input_context: item.total_input_context || 0,
output_tokens: item.output_tokens || 0,
cache_read_tokens: item.cache_read_tokens || 0,
@@ -201,6 +205,7 @@ export function useUsageData(options: UseUsageDataOptions) {
provider: item.provider,
requests: item.requests || 0,
totalTokens: item.total_tokens || 0,
effectiveInputTokens: item.effective_input_tokens || 0,
totalInputContext: item.total_input_context || 0,
outputTokens: item.output_tokens || 0,
cacheReadTokens: item.cache_read_tokens || 0,
@@ -234,6 +239,7 @@ export function useUsageData(options: UseUsageDataOptions) {
api_format: item.api_format,
request_count: item.request_count || 0,
total_tokens: item.total_tokens || 0,
effective_input_tokens: item.effective_input_tokens || 0,
total_input_context: item.total_input_context || 0,
output_tokens: item.output_tokens || 0,
cache_read_tokens: item.cache_read_tokens || 0,
@@ -384,6 +390,7 @@ export function useUsageData(options: UseUsageDataOptions) {
status: mergedStatus,
provider: protectProvider ? existing.provider : (record.provider || existing.provider),
input_tokens: existing.input_tokens || record.input_tokens,
effective_input_tokens: existing.effective_input_tokens ?? record.effective_input_tokens,
output_tokens: existing.output_tokens || record.output_tokens,
cache_creation_input_tokens: existing.cache_creation_input_tokens ?? record.cache_creation_input_tokens,
cache_read_input_tokens: existing.cache_read_input_tokens ?? record.cache_read_input_tokens,