feat:Credits不足进行跳转到web端的重置界面

This commit is contained in:
Roe-xin
2026-01-12 21:03:37 +08:00
parent 25966bc1e2
commit 58113fb109
2 changed files with 388 additions and 188 deletions

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,10 @@ import { ChatHistoryManager } from "./chatHistoryManager";
import { dialogManager, DialogSession } from "../services/dialogService"; import { dialogManager, DialogSession } from "../services/dialogService";
import { userInteractionManager } from "../services/userInteraction"; import { userInteractionManager } from "../services/userInteraction";
import { healthCheck } from "../services/apiClient"; import { healthCheck } from "../services/apiClient";
import { checkBalanceBeforeSend, fetchBalance } from "../services/creditsService"; import {
checkBalanceBeforeSend,
fetchBalance,
} from "../services/creditsService";
import type { RunMode, ServiceTier } from "../types/api"; import type { RunMode, ServiceTier } from "../types/api";
@ -39,7 +42,7 @@ export async function handleUserMessage(
text: string, text: string,
extensionPath?: string, extensionPath?: string,
mode?: RunMode, mode?: RunMode,
serviceTier?: ServiceTier // 新增:服务等级参数 serviceTier?: ServiceTier // 新增:服务等级参数
) { ) {
console.log("收到用户消息:", text); console.log("收到用户消息:", text);
@ -78,7 +81,9 @@ export async function handleUserMessage(
"去充值" "去充值"
); );
if (selection === "去充值") { if (selection === "去充值") {
vscode.env.openExternal(vscode.Uri.parse("https://iccoder.com/recharge")); vscode.env.openExternal(
vscode.Uri.parse("https://iccoder.com/memberCenter")
);
} }
// 恢复输入状态 // 恢复输入状态
panel.webview.postMessage({ panel.webview.postMessage({
@ -92,7 +97,14 @@ export async function handleUserMessage(
// 尝试使用后端服务 // 尝试使用后端服务
if (useBackendService && extensionPath) { if (useBackendService && extensionPath) {
try { try {
await handleUserMessageWithBackend(panel, text, extensionPath, mode, undefined, serviceTier); await handleUserMessageWithBackend(
panel,
text,
extensionPath,
mode,
undefined,
serviceTier
);
return; return;
} catch (error) { } catch (error) {
console.error("后端服务不可用:", error); console.error("后端服务不可用:", error);
@ -128,7 +140,7 @@ async function handleUserMessageWithBackend(
extensionPath: string, extensionPath: string,
mode?: RunMode, mode?: RunMode,
reuseTaskId?: string, // 可选,复用现有 taskId用于 Plan 模式确认后继续执行) reuseTaskId?: string, // 可选,复用现有 taskId用于 Plan 模式确认后继续执行)
serviceTier?: ServiceTier // 新增:服务等级参数 serviceTier?: ServiceTier // 新增:服务等级参数
): Promise<void> { ): Promise<void> {
const historyManager = ChatHistoryManager.getInstance(); const historyManager = ChatHistoryManager.getInstance();
@ -137,10 +149,18 @@ async function handleUserMessageWithBackend(
const taskIdToUse = reuseTaskId || historyManager.getCurrentTaskId(); const taskIdToUse = reuseTaskId || historyManager.getCurrentTaskId();
// 创建会话dialogManager 会自动处理旧会话的中止) // 创建会话dialogManager 会自动处理旧会话的中止)
currentSession = dialogManager.createSession(extensionPath, taskIdToUse || undefined); currentSession = dialogManager.createSession(
extensionPath,
taskIdToUse || undefined
);
// 保存 taskId 用于后续操作(如压缩) // 保存 taskId 用于后续操作(如压缩)
lastTaskId = currentSession.getTaskId(); lastTaskId = currentSession.getTaskId();
console.log("[MessageHandler] 创建会话: taskId=", lastTaskId, "来源=", taskIdToUse ? "historyManager" : "新生成"); console.log(
"[MessageHandler] 创建会话: taskId=",
lastTaskId,
"来源=",
taskIdToUse ? "historyManager" : "新生成"
);
// 显示状态栏 // 显示状态栏
panel.webview.postMessage({ panel.webview.postMessage({
@ -297,7 +317,7 @@ async function handleUserMessageWithBackend(
}, },
}, },
mode, mode,
serviceTier // 传递服务等级 serviceTier // 传递服务等级
); );
}); });
} }
@ -380,7 +400,14 @@ export async function handlePlanAction(
extensionPath: string, extensionPath: string,
serviceTier?: ServiceTier serviceTier?: ServiceTier
): Promise<void> { ): Promise<void> {
console.log("[handlePlanAction] action:", action, "planTitle:", planTitle, "serviceTier:", serviceTier); console.log(
"[handlePlanAction] action:",
action,
"planTitle:",
planTitle,
"serviceTier:",
serviceTier
);
switch (action) { switch (action) {
case "confirm": case "confirm":