feat: v0.7.3 成本收口 · 状态一致 · 死账清理 — Prompt Cache 根治 + SSRF DNS Pinning + 87 用例扩充全量回归
P1 修复面收口: Prompt Cache 根治(日期/记忆/附件三类易变内容出 system 入用户消息 前置块 user-context.ts, system 跨 run 字节级稳定; Anthropic system 块数组化 + cache_control ephemeral 断言, DeepSeek 自动缓存前缀命中 — 多轮对话输入 token 成本降数量级); 编辑重发/重新生成幽灵 Trace 双侧根治(DB truncateMessagesAfter 同步过滤 metadata.traceSteps + 前端 trimTraceStepsByAnchor 镜像, 严格小于锚点 时间戳, 同毫秒等值判废); sessions:deleteMessage 死通道全链路删除(渲染层零调用 + message_count 漂移面); Ollama vision 能力门控全链路(MetonaModelInfo .supportsVision 贯穿 adapter/IPC/store/UI, model-capabilities.ts 三道判定纯函数, 未知保守放行); 记忆固化节流(consolidation-policy 纯函数: 总开关 + 内容门控 [回答>=200字符或存在成功工具调用] + 会话级 10 分钟频率窗口, 三 memory.* 配置键) P2 安全纵深: SSRF DNS Pinning 关闭 rebinding 窗口(ssrf-guard 重构 resolvePublicAddresses 单源; ssrf-dispatcher 以 undici Agent.connect.lookup 钉死校验 IP, TLS SNI 保持原域名, 一次性 dispatcher 用后即毁; 代理激活显式 退化为仅入口校验); web_fetch 重写手动逐跳重定向循环(每跳先校验后连接, 替代 redirect:follow 内核跟跳的中间跳裸奔, 上限 5 跳); http_request 换用 pinned fetch; web_search 可达性预检加固(私有 URL 零请求 + 不跟跳, 3xx 视为 可达); Agent 浏览器 CORS 通配收紧为 Origin 回显 + Vary: Origin; ConfirmationHook.forgetSession 会话终态清理(会话删除/abort 联动/SubAgent 终结三处接线, 根治 rememberedDecisions 泄漏) P3 架构还债: agent.enableReflection 死配置全链路接线(main→shared→引擎→ Orchestrator→设置开关, REFLECTING 状态真实可达); AgentLoopConfig.timeoutMs 死字段删除; MemoryManager.cleanupExpired 挂入健康检查周期(expires_at 回收 管道真实化); buildSafeEnv 收敛 utils/safe-env.ts 单源(run_command 与 MCP stdio 共用, 终结双实现漂移); Trace 生命周期治理(metadata 只保留最近 20 个 run — keepRecentRuns 纯函数; JSONL 录制启动自动清理保留 200 个 + 设置页 手动清理); SLO/健康快照可视化(app:healthSnapshot IPC + 设置页只读卡片 + 审计链一键校验) P4 能力演进: 会话标题 LLM 自动生成(TitleGenerator — 每会话幂等/并发重入复用 同一 Promise/自定义标题不覆盖/失败静默回退, Sidebar 经 config:changed 实时 刷新); MCP 自动重连(5s/15s/60s 退避最多 3 次, reconnecting 状态机, teardownConnection 内部拆除保留簿记 — 用户断开/开关关闭即时取消, 设置页 显示第 N/3 次); 死循环检测 ABAB 乒乓模式(最近4轮 A→B→A→B 交替判定, 补齐 docs 第五章"两状态反复切换"检测契约); i18n 第三阶段(ChatInput/LLMSettings/ OnboardingWizard/MemoryViewer 主链路文案出层, zh-CN + en-US 双字典补齐) 测试: 737 → 824 用例(+87, 新增 8 个测试文件 + 扩展 3 个)。新覆盖: user-context 分组/空值收缩/拼接契约、context-builder 字节级稳定性、Anthropic cache_control 四态、consolidation-policy 九路判定矩阵、ssrf-dispatcher(pinned lookup/重定向 解析/IP 校验)、forget-session 会话隔离、trace-lifecycle run 淘汰、 trace-trim 严格小于边界、safe-env 净化矩阵、mcp-reconnect 退避状态机 (fake timers)、title-generator 并发重入、SQLite 侧 truncate×TRACE 联动 (Electron ABI)。测试驱动修复: GIT_*/ 注释终止块注释、重连计数被自身重试 前置断开重置(拆 teardownConnection 保留簿记)、TitleGenerator 幂等占位与 并发去重的检查顺序竞态(去重先于幂等) 版本: 0.7.3; README 同步(配置表新增 agent.enableReflection/memory.*/mcp.autoReconnect) 回归: typecheck 双端 0 错误; ESLint 0/0; 系统 Node 771 通过 53 跳过 (better-sqlite3 ABI); Electron ABI 全量 824/824 零跳过
This commit is contained in:
@@ -26,12 +26,19 @@ import { useAgentStore } from '@renderer/stores/agent-store';
|
||||
import { useSessionStore } from '@renderer/stores/session-store';
|
||||
import { useUIStore } from '@renderer/stores/ui-store';
|
||||
import { formatFileSize } from '@renderer/lib/formatters';
|
||||
import { PROVIDER_LABELS } from '@renderer/lib/constants';
|
||||
// v0.7.3 P1-4: 图片上传门控纯函数(总开关 × DeepSeek 命名防线 × Ollama 能力探测)
|
||||
import { supportsImageUpload } from '@renderer/lib/model-capabilities';
|
||||
// v0.7.3 P4-3: 文案出层(字典含注册副作用,须在 t() 使用前 import)
|
||||
import { t } from '@renderer/lib/i18n';
|
||||
import '@renderer/lib/i18n-strings';
|
||||
|
||||
const SLASH_COMMANDS = [
|
||||
{ id: 'tool', label: '/tool', description: '选择工具' },
|
||||
{ id: 'memory', label: '/memory', description: '搜索记忆' },
|
||||
{ id: 'clear', label: '/clear', description: '清空会话' },
|
||||
{ id: 'export', label: '/export', description: '导出 Markdown' },
|
||||
// v0.7.3 P4-3: 描述文案渲染时求值(i18next 字典注册是异步的,模块顶层固化会拿到 key 本体)
|
||||
const SLASH_COMMANDS: Array<{ id: string; label: string; description: () => string }> = [
|
||||
{ id: 'tool', label: '/tool', description: () => t('input.slash.tool') },
|
||||
{ id: 'memory', label: '/memory', description: () => t('input.slash.memory') },
|
||||
{ id: 'clear', label: '/clear', description: () => t('input.slash.clear') },
|
||||
{ id: 'export', label: '/export', description: () => t('input.slash.export') },
|
||||
];
|
||||
|
||||
const IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'];
|
||||
@@ -106,15 +113,14 @@ export function ChatInput(): React.JSX.Element {
|
||||
const model = useAgentStore((s) => s.model);
|
||||
// v0.5.4: 多模态总开关(llm.multimodalEnabled,设置/引导向导中配置)
|
||||
const multimodalEnabled = useAgentStore((s) => s.multimodalEnabled);
|
||||
|
||||
/**
|
||||
* v0.5.4: 图片上传双重判断 — 总开关 × 模型能力
|
||||
* - 开关关闭:即使模型支持多模态也不能上传(显式控制)
|
||||
* - 模型能力:DeepSeek 仅 vision 系列支持;其他五家 Provider 均支持
|
||||
*/
|
||||
const modelSupportsImages =
|
||||
provider !== 'deepseek' || (model.length > 0 && model.includes('vision'));
|
||||
const supportsImages = multimodalEnabled && modelSupportsImages;
|
||||
const modelVisionCaps = useAgentStore((s) => s.modelVisionCaps);
|
||||
const imageGate = supportsImageUpload({
|
||||
multimodalEnabled,
|
||||
provider,
|
||||
model,
|
||||
visionCaps: modelVisionCaps,
|
||||
});
|
||||
const supportsImages = imageGate.allowed;
|
||||
|
||||
// 草稿自动保存
|
||||
useEffect(() => {
|
||||
@@ -163,11 +169,12 @@ export function ChatInput(): React.JSX.Element {
|
||||
reader.onerror = () => reject(new Error('文本文件读取失败'));
|
||||
reader.readAsText(headBlob);
|
||||
});
|
||||
attachment.textContent += `\n\n[... 文件内容已截断:原始大小 ${formatFileSize(file.size)},仅包含前 ${formatFileSize(MAX_TEXT_ATTACHMENT_BYTES)}。如需完整内容请分段处理 ...]`;
|
||||
attachment.textContent += t('input.text.truncatedNote', {
|
||||
size: formatFileSize(file.size),
|
||||
limit: formatFileSize(MAX_TEXT_ATTACHMENT_BYTES),
|
||||
});
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) =>
|
||||
mod.default.warning(`文本附件 "${file.name}" 超过 512KB,已截断为前 512KB`),
|
||||
)
|
||||
.then((mod) => mod.default.warning(t('input.text.truncated', { name: file.name })))
|
||||
.catch(() => {});
|
||||
} else {
|
||||
attachment.textContent = await new Promise<string>((resolve, reject) => {
|
||||
@@ -196,9 +203,15 @@ export function ChatInput(): React.JSX.Element {
|
||||
if (filtered.length < fileArray.length && !supportsImages) {
|
||||
const skipped = fileArray.length - filtered.length;
|
||||
// v0.5.4: 区分拒绝原因 — 开关未开启 vs 当前模型不支持
|
||||
const reason = multimodalEnabled
|
||||
? `当前模型不支持图片(${provider} 需多模态模型),已跳过 ${skipped} 个图片文件`
|
||||
: `多模态未开启(设置 → LLM 配置),已跳过 ${skipped} 个图片文件`;
|
||||
const reason =
|
||||
imageGate.reason === 'disabled'
|
||||
? t('input.image.skipped.toggle', { count: skipped })
|
||||
: imageGate.reason === 'probed-no-vision'
|
||||
? t('input.image.skipped.probe', { count: skipped })
|
||||
: t('input.image.skipped.model', {
|
||||
provider: PROVIDER_LABELS[provider] ?? provider,
|
||||
count: skipped,
|
||||
});
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => {
|
||||
mod.default.warning(reason);
|
||||
@@ -218,7 +231,7 @@ export function ChatInput(): React.JSX.Element {
|
||||
if (successful.length === 0) {
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => {
|
||||
mod.default.error('文件读取失败,请检查文件是否损坏或被锁定');
|
||||
mod.default.error(t('input.file.readFailed'));
|
||||
})
|
||||
.catch(() => {});
|
||||
return;
|
||||
@@ -227,7 +240,7 @@ export function ChatInput(): React.JSX.Element {
|
||||
const failedCount = filtered.length - successful.length;
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => {
|
||||
mod.default.warning(`${failedCount} 个文件读取失败,已跳过`);
|
||||
mod.default.warning(t('input.file.partialFailed', { count: failedCount }));
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
@@ -522,7 +535,7 @@ export function ChatInput(): React.JSX.Element {
|
||||
</span>
|
||||
<span style={{ fontFamily: 'monospace', fontSize: 12 }}>{cmd.label}</span>
|
||||
<span style={{ color: 'var(--text-secondary, #64748b)', fontSize: 11 }}>
|
||||
{cmd.description}
|
||||
{cmd.description()}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -554,9 +567,9 @@ export function ChatInput(): React.JSX.Element {
|
||||
placeholder={
|
||||
configLoaded
|
||||
? toolsReady
|
||||
? '输入消息... (Cmd/Ctrl+Enter 发送, Cmd/Ctrl+Shift+Enter 换行, / 命令)'
|
||||
: '工具加载中...'
|
||||
: '正在加载配置...'
|
||||
? t('input.placeholder.ready')
|
||||
: t('input.placeholder.toolsLoading')
|
||||
: t('input.placeholder.configLoading')
|
||||
}
|
||||
disabled={isStreaming || !configLoaded || !toolsReady}
|
||||
multiline
|
||||
@@ -608,7 +621,7 @@ export function ChatInput(): React.JSX.Element {
|
||||
onClick={handleAbort}
|
||||
sx={{ height: 28, fontSize: 12 }}
|
||||
>
|
||||
<Square size={12} style={{ marginRight: 6 }} /> 中断
|
||||
<Square size={12} style={{ marginRight: 6 }} /> {t('input.abort')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
@@ -627,7 +640,7 @@ export function ChatInput(): React.JSX.Element {
|
||||
: 0.5,
|
||||
}}
|
||||
>
|
||||
<Send size={12} style={{ marginRight: 6 }} /> 发送
|
||||
<Send size={12} style={{ marginRight: 6 }} /> {t('input.send')}
|
||||
</Button>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
Reference in New Issue
Block a user