fix: 全面修复审计问题并优化系统提示词
**崩溃/挂死修复 (5):** - 统一 TrayManager.isQuitting 变量,修复 Cmd+Q 无法退出 - useAgentStream 闭包过期快照 → 每次 getState() - Agnes chatStream 添加 AbortSignal.timeout - SSE JSON.parse 添加 try-catch 保护 - Orchestrator setTools 污染 → save/restore 模式 **功能修复 (14):** - 上下文压缩实现 (每5轮 COMPRESSING 状态) - 修复 requestId 硬编码空串 - ConfigService.set() 保留已有 category - MemoryManager 新增 working 类型搜索 - PromptInjectionDefender 补全 sanitize() - Ollama: 补全 dynamicReminders + reasoningContent - openai-format: 所有 assistant 消息保留 reasoningContent - SSE: finish_reason 时提前 flush tool_calls - DeepSeek thinking effort 映射注释 - Ollama done_reason load→stop - RateLimitHook >= 边界修复 - WorkspaceService isValid 首次启动修复 - sessions:archive IPC handler - 托盘/窗口图标路径生产环境修复 **系统提示词优化:** - SOUL.md 存在时不显示兜底身份,原文放最前 - 兜底身份改为中文 (MetonaAI 自身描述) - 用户文本在前,附件内容在后 **文件上传:** - 非图片文件不再 base64 编码,保留 JSON 结构 - 用户文本优先于文件内容 **UI 修复:** - 首页 Logo 路径修复 (public/ + 相对路径) - TokenUsage contextWindow 动态计算 (Provider 感知) - 切换 Provider 同步 contextWindow - 托盘图标始终显示 Logo (状态由右键菜单展示)
This commit is contained in:
+19
-11
@@ -88,6 +88,7 @@ interface AgentState {
|
||||
// Provider
|
||||
provider: string;
|
||||
model: string;
|
||||
contextWindow: number;
|
||||
|
||||
// Actions
|
||||
setCurrentSession: (id: string | null) => void;
|
||||
@@ -124,6 +125,7 @@ export const useAgentStore = create<AgentState>((set, get) => ({
|
||||
streamingContent: '',
|
||||
provider: '',
|
||||
model: '',
|
||||
contextWindow: 1_000_000,
|
||||
|
||||
// ===== Actions =====
|
||||
|
||||
@@ -236,23 +238,17 @@ export const useAgentStore = create<AgentState>((set, get) => ({
|
||||
// 图片已在 images 参数中处理,跳过
|
||||
continue;
|
||||
}
|
||||
// 非图片文件:JSON 格式,Base64 编码内容
|
||||
// 非图片文件:JSON 结构化,原始文本内容(不编码)
|
||||
const ext = att.name.split('.').pop() ?? 'unknown';
|
||||
let base64Content = '';
|
||||
if (att.textContent) {
|
||||
base64Content = btoa(unescape(encodeURIComponent(att.textContent)));
|
||||
} else if (att.preview) {
|
||||
base64Content = att.preview.split(',')[1] ?? '';
|
||||
}
|
||||
const rawContent = att.textContent ?? '';
|
||||
parts.push(JSON.stringify({
|
||||
file_name: att.name,
|
||||
file_type: ext,
|
||||
context_encode: 'Base64',
|
||||
context: base64Content,
|
||||
content: rawContent,
|
||||
}));
|
||||
}
|
||||
llmContent = parts.length > 0
|
||||
? parts.join('\n') + (content ? '\n\n' + content : '')
|
||||
? (content ? content + '\n\n' : '') + parts.join('\n')
|
||||
: content;
|
||||
}
|
||||
|
||||
@@ -305,7 +301,19 @@ export const useAgentStore = create<AgentState>((set, get) => ({
|
||||
updateTokenUsage: (usage) =>
|
||||
set((s) => ({ tokenUsage: { ...s.tokenUsage, ...usage } })),
|
||||
|
||||
setProvider: (provider, model) => set({ provider, model }),
|
||||
setProvider: (provider, model) => {
|
||||
// DeepSeek/Agnes 固定 1M,Ollama 从配置读取
|
||||
const ollamaCtx = provider === 'ollama' ? 128_000 : 1_000_000;
|
||||
set({ provider, model, contextWindow: ollamaCtx });
|
||||
// 异步读取 Ollama 实际配置
|
||||
if (provider === 'ollama' && window.metona?.config?.get) {
|
||||
window.metona.config.get('ollama.numCtx').then((v) => {
|
||||
if (v != null && typeof v === 'number' && v > 0) {
|
||||
set({ contextWindow: v });
|
||||
}
|
||||
}).catch(() => {});
|
||||
}
|
||||
},
|
||||
|
||||
setMaxIterations: (max) => set({ maxIterations: max }),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user