From 8a3ff92518ae120d0ed26c9a574e1472cba0d2e8 Mon Sep 17 00:00:00 2001 From: weichen Date: Wed, 7 Oct 2026 16:34:27 +0000 Subject: [PATCH] Add last-request and cache fields to Usage (N3 WP6) Why: the loop now emits Last* and cache token usage; the product run record needs the same fields for display and accounting (additive JSON, old records deserialize as zero values). Evidence: GOWORK=off go build + go test green. Impact: additive only. Refs: Agent-Native#35, N3 plan WP6 --- model.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/model.go b/model.go index 49f4554..9d7d6c4 100644 --- a/model.go +++ b/model.go @@ -208,6 +208,12 @@ type Usage struct { TotalTokens int `json:"totalTokens"` DurationMs float64 `json:"durationMs"` ToolCalls int `json:"toolCalls"` + // 以下四项是 N3 的计费拆分(additive;旧记录为零值省略): + // Last* 是最近一次请求的用量(上一请求),Cache* 是缓存命中累计。 + LastPromptTokens int `json:"lastPromptTokens,omitempty"` + LastCompletionTokens int `json:"lastCompletionTokens,omitempty"` + CacheReadTokens int `json:"cacheReadTokens,omitempty"` + CacheWriteTokens int `json:"cacheWriteTokens,omitempty"` // Model 是实际给出这段用量的模型。空表示当时没有记录。 Model string `json:"model,omitempty"` } -- 2.54.0