feat:显示资源点

- 登录之后就获取资源点并持久化
- 显示剩余资源点到页面上
- 一轮对话完成之后重新获取资源点并且更新缓存
This commit is contained in:
Roe-xin
2026-01-12 19:09:19 +08:00
parent 3c93c07afd
commit 25966bc1e2
7 changed files with 116 additions and 12 deletions

View File

@ -18,7 +18,7 @@ import { ChatHistoryManager } from "./chatHistoryManager";
import { dialogManager, DialogSession } from "../services/dialogService";
import { userInteractionManager } from "../services/userInteraction";
import { healthCheck } from "../services/apiClient";
import { checkBalanceBeforeSend } from "../services/creditsService";
import { checkBalanceBeforeSend, fetchBalance } from "../services/creditsService";
import type { RunMode, ServiceTier } from "../types/api";
@ -200,6 +200,17 @@ async function handleUserMessageWithBackend(
// 最后一次发送完整的段落
console.log("[MessageHandler] 对话完成, 段落数:", segments.length);
// 对话完成后重新获取余额(因为已经消耗了 Credits
try {
console.log("[MessageHandler] 对话完成,重新获取余额...");
const newBalance = await fetchBalance();
if (newBalance !== null) {
console.log("[MessageHandler] 余额已更新:", newBalance);
}
} catch (error) {
console.error("[MessageHandler] 获取余额失败:", error);
}
const result = await panel.webview.postMessage({
command: "updateSegments",
segments: segments,