修复: token 汇总正确性(会话级双计/is_estimated跨端/流式usage传递) + is_estimated SELECT 缺失修复
This commit is contained in:
@@ -191,6 +191,8 @@ function parseConvMessages(rawMsgs: any[], fallbackPrefix: string): AiMessage[]
|
||||
cache_hit: m.prompt_cache_hit_tokens,
|
||||
cache_miss: m.prompt_cache_miss_tokens,
|
||||
reasoning: m.reasoning_tokens,
|
||||
// 消息级估算标记(DB 列,老消息 null → undefined):reload 逐条回显对齐 live 态 AiCompleted
|
||||
is_estimated: m.is_estimated,
|
||||
}
|
||||
: undefined,
|
||||
// 分项 token 消息级字段(详情面板直接读 msg.xxx,与实时态 useAiEvents 写入一致)
|
||||
|
||||
@@ -135,6 +135,9 @@ export function handleLifecycleEvent(event: AiChatEvent): boolean {
|
||||
state.convTokenTotal = { prompt: event.prompt_tokens, completion: event.completion_tokens, total: event.total_tokens }
|
||||
}
|
||||
// 每轮 token 写入最后一条 AI 消息,供 MessageList 逐条显示
|
||||
// 口径说明:后端 AiCompleted 每 loop 只发一次,携带本 loop 累计用量,故 live 态
|
||||
// 聚合到「最后一条 assistant」;reload(switchConversation)从 DB 逐条回显各轮本轮量
|
||||
// (消息级 token)。两者展示层级不同(live=loop 聚合,reload=单轮),属已接受口径。
|
||||
for (let i = state.messages.length - 1; i >= 0; i--) {
|
||||
const m = state.messages[i]
|
||||
if (m.role === 'assistant' && !m.isError) {
|
||||
|
||||
Reference in New Issue
Block a user