feat: 升级至 v0.2.3 — Token 估算优化、工具确认超时改进、工作空间标签页

1. Token 估算优化(核心改进):新增 token-estimator.ts 智能字符估算(中文 1.5 token/字、ASCII 0.25 token/字),替换三处旧的 length/2 粗略估算,中文场景准确度从 ~50% 提升到 ~90%

2. 工具确认超时改进:超时时间可配置(30s~600s)、超时 toast 通知、ConfirmationDialog 倒计时 UI(进度条 + 最后 10 秒红色脉冲动画)、SettingsModal 新增配置入口

3. 详情栏新增 Workspace 标签页:workspace:getInfo IPC + WorkspaceViewer 组件(文件预览、目录状态、在文件管理器打开)
This commit is contained in:
thzxx
2026-07-12 14:20:05 +08:00
parent 0363176215
commit 1eabed9b70
13 changed files with 563 additions and 35 deletions
+14 -9
View File
@@ -17,6 +17,7 @@
import type { MetonaContext, MetonaMemoryItem, MetonaMessage, MetonaSystemPrompt, MetonaToolDef } from '../types';
import type { WorkspaceFiles } from '../../services/workspace.service';
import { estimateStringTokens } from '../utils/token-estimator';
interface ContextBuildParams {
userInput: string;
@@ -245,6 +246,8 @@ Use tools when needed to gather information or perform actions. Think step by st
/**
* Token 估算
* 使用智能字符估算:中文 1.5 token/字,ASCII 0.25 token/字,其他 1 token/字
* @see electron/harness/utils/token-estimator.ts
*/
private estimateTokens(
history: MetonaMessage[],
@@ -256,22 +259,24 @@ Use tools when needed to gather information or perform actions. Think step by st
let total = 0;
// System Prompt
total += Math.ceil((systemPrompt.roleDefinition?.length ?? 0) / 2);
total += Math.ceil((systemPrompt.outputConstraints?.length ?? 0) / 2);
total += Math.ceil((systemPrompt.safetyGuidelines?.length ?? 0) / 2);
total += Math.ceil((systemPrompt.dynamicReminders?.length ?? 0) / 2);
total += estimateStringTokens(systemPrompt.roleDefinition ?? '');
total += estimateStringTokens(systemPrompt.outputConstraints ?? '');
total += estimateStringTokens(systemPrompt.safetyGuidelines ?? '');
total += estimateStringTokens(systemPrompt.dynamicReminders ?? '');
// 历史消息
for (const msg of history) total += Math.ceil(msg.content.length / 2);
// 历史消息(每条加 4 token 结构性开销)
for (const msg of history) {
total += estimateStringTokens(msg.content) + 4;
}
// 记忆
for (const mem of memories) total += Math.ceil(mem.content.length / 2);
for (const mem of memories) total += estimateStringTokens(mem.content);
// 工具定义
for (const tool of tools) total += Math.ceil((tool.name.length + tool.description.length) / 2);
for (const tool of tools) total += estimateStringTokens(tool.name + tool.description);
// 用户输入
total += Math.ceil(userInput.length / 2);
total += estimateStringTokens(userInput);
return total;
}