P0 会话可靠性收口(根治"模型思考着会话就停止"): - P0-1 finish_reason 全链路贯通:DONE 事件与 IterationStep 新增 finishReason,OpenAI 共享 SSE / Anthropic message_delta.stop_reason / Ollama done_reason 三路采集,TRACE 层弃用硬编码 'stop' 记录真值 - P0-2 空响应守卫 + 降级重试:零产出流→可重试错误走退避;思考耗尽输出预算(reasoning-only + length)→自动关闭思考降级重试一次;仍失败→OUTPUT_LENGTH_EXCEEDED 结构化错误 + 故障转移;附带根治 abort 恰逢零工具调用轮被 COMPLETED 抢占的真实缺陷 - P0-3 思考×能力×预算三对齐:DeepSeek/MiMo/Agnes/Ollama 四家 supportsThinking=false 强制不发思考参数;小输出预算告警;设置页联动提示 - P0-4 渲染层可见性:截断/空完成/友好错误三类提示,i18n 全部出层 - P0-5 回归四件套:reasoning-only 终止判定、集成级空闲超时、504 引擎重试归类、思考中 abort→USER_INTERRUPT、P4-2 强制收尾路径 FEAT-1:LLM 设置新增「最大输出上限」——Provider 支持矩阵显隐 + 模型上限钳制提示 + 超限保存警告 + llm.maxTokens 热生效 P1 修复面收口: - 渲染层三缺陷根治:后台会话回放缓冲(2000 条/4MB 有界 + agent:getReplayState + 事件总线)+ abort 双层自愈 + sendMessage 收尾兜底 + 中断卡片清扫 - 工具 abort 信号全覆盖:web_search/web_fetch/http_request/code_search/git 系列/delegate_task 全部接入引擎中断;web_search 时间预算收敛(720s→≤240s);移除伪造 ToolExecutionContext 与死代码 - 安全:本地 Pinned CONNECT 代理根治浏览器通道 DNS rebinding(校验期 IP pinning,可注入 resolver 表测);配置 URL 域名解析深校验(DeepCheckSoftFailure 软失败);SSE 空 error 帧防御修复;Ollama generate/embed AbortSignal.any 合并 - 缺陷清单:UTF-16 BOM 读取、tmp 同毫秒碰撞(nanoid 后缀)、code_search JS 回退参数对称(case_sensitive/前后文独立)、list_directory include_node_modules、崩溃自愈退避(60s 窗 ≥3 次停 reload)、MemoryViewer/Sidebar i18n 收口 P2 能力演进: - 会话回收站:SCHEMA_VERSION 3 + 迁移 10(deleted_at,存在性守卫),软删除/恢复/彻底删除/30 天自动清理(启动+24h),searchMessages 聚合剔除,Sidebar 回收站面板 - 会话回放播放器:sessions:listRecordings/readRecording(白名单+目录边界+20MB 上限),SessionReplayPlayer 时间轴/步进/变速,Trace 面板入口 - electron-updater 自动更新:双轨(手动 feed 比对保留),生产环境启动静默检查 + update:status 广播 + app:updateInstall + LogsSettings UpdatePanel + builder publish 配置 - @ 文件提及:workspace.listFiles/readFileClip(边界/512KB/NUL 拒绝/MEMORY.md 保护),ChatInput Fuse 联想+键盘导航+附件管线注入 - MCP Resources/Prompts 发现:可选能力 try/catch 降级,mcp:listServerContents,MCPSettings 展开视图 - 文档对齐:内部 API 标准 HTML(Adapter 清单补 MiMo/已实现注记/STREAM_RESET/DONE.finishReason/ repetition_truncation 映射);README v0.8.0 亮点表 P3 测试基建: - 新增 4 个测试文件:engine-stream-contract(6)、engine-stream-reliability(4:集成空闲超时/504 重试/思考中 abort/P4-2 强制收尾)、thinking-capability-gate(7)、pinned-proxy(9,含深校验 5)、session-trash(5,DB 域)、use-agent-stream hook 级(5)、agent.test 回放缓冲(2) - 契约更新:orchestrator 被中断 SubAgent success=false(abort 优先级修复语义)、SSE 空 error 帧、UTF-16 正常读取、DeepSeek 未配置思考显式 disabled、迁移矩阵 v2→3 - 弱断言根治:registry WEBP 单向断言、hooks-contracts 自比恒真、memory 空 token 补强 全量验证:typecheck 0 错误 / lint 0 问题 / 系统 Node 2144 通过(301 DB 用例按 ABI 跳过)/ Electron ABI 2445/2445 全量通过 0 跳过
160 lines
5.7 KiB
TypeScript
160 lines
5.7 KiB
TypeScript
/**
|
|
* v0.8.0 P0-3: 思考参数 × 模型能力 门控矩阵。
|
|
*
|
|
* 根因回顾:MODEL_INFO 标注 supportsThinking:false 的模型(如
|
|
* deepseek-v4-flash-vision-exp)此前仍被发送 thinking 参数 —— 思考耗尽输出
|
|
* 预算(8192 上限)导致 finish_reason=length 空回复、会话静默停止。
|
|
* 本文件钉住四家 Provider 的能力门控行为与输出预算告警前置条件。
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { DeepSeekAdapter } from '../deepseek.adapter';
|
|
import { AgnesAdapter } from '../agnes-ai.adapter';
|
|
import { MimoAdapter } from '../mimo.adapter';
|
|
import { OllamaAdapter } from '../ollama.adapter';
|
|
import type { MetonaRequest } from '../../types';
|
|
|
|
const SYSTEM_PROMPT = {
|
|
roleDefinition: 'test',
|
|
outputConstraints: '',
|
|
safetyGuidelines: '',
|
|
};
|
|
|
|
function makeRequest(overrides?: Partial<MetonaRequest['params']>): MetonaRequest {
|
|
return {
|
|
meta: {
|
|
sessionId: 's',
|
|
iteration: 1,
|
|
requestId: 'r',
|
|
timestamp: Date.now(),
|
|
agentVersion: '1.0.0',
|
|
},
|
|
systemPrompt: SYSTEM_PROMPT,
|
|
messages: [{ role: 'user', content: 'hi', timestamp: Date.now() }],
|
|
params: {
|
|
maxTokens: 63488,
|
|
temperature: 0,
|
|
stream: true,
|
|
thinkingEnabled: true,
|
|
thinkingEffort: 'max',
|
|
...overrides,
|
|
},
|
|
};
|
|
}
|
|
|
|
function asNative(
|
|
adapter: unknown,
|
|
): (req: MetonaRequest, stream: boolean) => Record<string, unknown> {
|
|
return (
|
|
adapter as { toNativeRequest: (r: MetonaRequest, s: boolean) => Record<string, unknown> }
|
|
).toNativeRequest.bind(adapter);
|
|
}
|
|
|
|
describe('P0-3 thinking capability gate', () => {
|
|
it('DeepSeek: vision-exp (supportsThinking:false) → thinking disabled, no reasoning_effort, max_tokens clamped to 8192', async () => {
|
|
const adapter = new DeepSeekAdapter({
|
|
provider: 'deepseek',
|
|
baseURL: 'https://api.deepseek.com',
|
|
apiKey: 'k',
|
|
defaultModel: 'deepseek-v4-flash-vision-exp',
|
|
});
|
|
const body = asNative(adapter)(makeRequest(), false);
|
|
expect(body.thinking).toEqual({ type: 'disabled' });
|
|
expect(body.reasoning_effort).toBeUndefined();
|
|
expect(body.max_tokens).toBe(8192);
|
|
});
|
|
|
|
it('DeepSeek: pro (supportsThinking:true) → thinking enabled + reasoning_effort mapped (max→max)', async () => {
|
|
const adapter = new DeepSeekAdapter({
|
|
provider: 'deepseek',
|
|
baseURL: 'https://api.deepseek.com',
|
|
apiKey: 'k',
|
|
defaultModel: 'deepseek-v4-pro',
|
|
});
|
|
const body = asNative(adapter)(makeRequest(), false);
|
|
expect(body.thinking).toEqual({ type: 'enabled' });
|
|
expect(body.reasoning_effort).toBe('max');
|
|
});
|
|
|
|
it('Agnes: supportsThinking:false model → enable_thinking:false', async () => {
|
|
const adapter = new AgnesAdapter({
|
|
provider: 'agnes',
|
|
baseURL: 'https://apihub.agnes-ai.com/v1',
|
|
apiKey: 'k',
|
|
defaultModel: 'agnes-2.0-flash',
|
|
});
|
|
// 临时改写元信息模拟"不支持思考"的模型,结束后恢复
|
|
const table = AgnesAdapter['MODEL_INFO'] as Record<string, { supportsThinking: boolean }>;
|
|
const original = table['agnes-2.0-flash'].supportsThinking;
|
|
table['agnes-2.0-flash'].supportsThinking = false;
|
|
try {
|
|
const body = asNative(adapter)(makeRequest(), false);
|
|
expect(body.chat_template_kwargs).toEqual({ enable_thinking: false });
|
|
} finally {
|
|
table['agnes-2.0-flash'].supportsThinking = original;
|
|
}
|
|
});
|
|
|
|
it('Agnes: supportsThinking:true model → enable_thinking:true', async () => {
|
|
const adapter = new AgnesAdapter({
|
|
provider: 'agnes',
|
|
baseURL: 'https://apihub.agnes-ai.com/v1',
|
|
apiKey: 'k',
|
|
defaultModel: 'agnes-2.0-flash',
|
|
});
|
|
const body = asNative(adapter)(makeRequest(), false);
|
|
expect(body.chat_template_kwargs).toEqual({ enable_thinking: true });
|
|
});
|
|
|
|
it('MiMo: supportsThinking:false model → thinking disabled + temperature passthrough', async () => {
|
|
const adapter = new MimoAdapter({
|
|
provider: 'mimo',
|
|
baseURL: 'https://api.xiaomimimo.com/v1',
|
|
apiKey: 'k',
|
|
defaultModel: 'mimo-v2.5-pro',
|
|
});
|
|
const table = MimoAdapter['MODEL_INFO'] as Record<string, { supportsThinking: boolean }>;
|
|
const original = table['mimo-v2.5-pro'].supportsThinking;
|
|
table['mimo-v2.5-pro'].supportsThinking = false;
|
|
try {
|
|
const body = asNative(adapter)(makeRequest(), false);
|
|
expect(body.thinking).toEqual({ type: 'disabled' });
|
|
expect(body.temperature).toBe(0);
|
|
} finally {
|
|
table['mimo-v2.5-pro'].supportsThinking = original;
|
|
}
|
|
});
|
|
|
|
it('Ollama: probed no-thinking (cachedThinkingSupport=false) → no think parameter', async () => {
|
|
const adapter = new OllamaAdapter({
|
|
provider: 'ollama',
|
|
baseURL: 'http://localhost:11434',
|
|
apiKey: '',
|
|
defaultModel: 'qwen3:latest',
|
|
});
|
|
(adapter as unknown as { cachedThinkingSupport: boolean | null }).cachedThinkingSupport = false;
|
|
const body = await (
|
|
adapter as unknown as {
|
|
toNativeRequest: (r: MetonaRequest) => Promise<Record<string, unknown>>;
|
|
}
|
|
).toNativeRequest(makeRequest());
|
|
expect(body.think).toBeUndefined();
|
|
});
|
|
|
|
it('Ollama: probe unknown (null) fails open → think parameter present', async () => {
|
|
const adapter = new OllamaAdapter({
|
|
provider: 'ollama',
|
|
baseURL: 'http://localhost:11434',
|
|
apiKey: '',
|
|
defaultModel: 'qwen3:latest',
|
|
});
|
|
(adapter as unknown as { cachedThinkingSupport: boolean | null }).cachedThinkingSupport = null;
|
|
const body = await (
|
|
adapter as unknown as {
|
|
toNativeRequest: (r: MetonaRequest) => Promise<Record<string, unknown>>;
|
|
}
|
|
).toNativeRequest(makeRequest());
|
|
expect(body.think).toBe(true); // effort=max → true
|
|
});
|
|
});
|