feat: v0.8.1 记忆深化 · 观测闭环 · 体验收口 — 窗口/输出上限全局单一配置 · 2478 用例全量回归 + E2E 冒烟
硬性契约:删除代码中一切写死的上下文窗口与最大输出上限(含六家模型元信息
钳制与全部兜底值)——唯一合法来源是设置面板「上下文长度」(llm.contextWindow)
与「最大输出上限」(llm.maxTokens),跨 Provider/模型原样透传。
P0 正确性收口:
- 迁移 11/12(SCHEMA_VERSION 5):记忆表 embedding 列 + 分 Provider 窗口键清理
- 记忆生命周期接线:会话终态清理 working memory / episodic 90 天 TTL / access_count 回写
- 回放缓冲模块化 + 会话终态清理(杜绝 4MB/会话内存滞留)
- i18n 收口:主进程 main-locale(zh/en,ui.locale 热切换)+ 渲染层 17 处出层
P1 能力演进:
- 本地向量混合检索:0.6×向量余弦 + 0.4×TF-IDF,Ollama embeddings 首次投产,
存量记忆惰性回填,嵌入不可用自动回退 TF-IDF
- MEMORY.md 维护闭环:固化去重消除截断盲区;两阶段维护(AI 建议 → 用户确认 →
原子改写 + 语义记忆双轨同步 + 审计);>50KB 告警
- 可观测闭环:cacheTokens 引擎→前端透传(Token 面板命中率/成本行)+ 输入框
上下文占用指示条
- MCP Prompts/Resources 对话可用:/mcp:{server}:{prompt} 与 @mcp:{server}:{uri}
P2 体验补全:
- 工具自定义策略(正则白/黑名单 + 频率 + 强制确认,热生效)
- 连续 ≥3 同类工具确认聚合为单弹框
- 会话消息游标分页(首屏 200 条向上翻页)
- 开机自启;Playwright + Electron E2E 冒烟(本地 mock LLM 零外联)
Review 回归修复:MCP 大小写失配 / 分页状态复位 / 清空=未配置语义(Number(null)=0
隐患)/ MEMORY.md 告警位置 / working_memories FK(迁移 13)/ 全局配置层废键清理;
附带根治权限加固启动时序、代理回环放行、safeStorage 降级、悬空 symlink 逃逸。
验证:typecheck/lint 0 问题;test:electron 2478/2478(0 跳过);E2E 2/2;
docs/v0.8.1-迭代实施清单.md 全项留档。
This commit is contained in:
@@ -205,12 +205,12 @@ describe('OpenAIAdapter — 推理模型拒图(ModelCapabilityError)', () =>
|
||||
|
||||
// ===== max_completion_tokens / max_tokens 路由 =====
|
||||
|
||||
describe('OpenAIAdapter — token 参数路由', () => {
|
||||
describe('OpenAIAdapter — token 参数路由(v0.8.1:原样透传,无模型钳制)', () => {
|
||||
it.each([
|
||||
['o3-mini', 63_488, 63_488, 'max_completion_tokens'],
|
||||
['o3-mini', 200_000, 100_000, 'max_completion_tokens'], // 上限 100000
|
||||
['gpt-4o', 63_488, 16_384, 'max_tokens'],
|
||||
['gpt-4.1', 63_488, 32_768, 'max_tokens'],
|
||||
['o3-mini', 200_000, 200_000, 'max_completion_tokens'], // 超过任何旧元信息上限 → 原样
|
||||
['gpt-4o', 63_488, 63_488, 'max_tokens'],
|
||||
['gpt-4.1', 63_488, 63_488, 'max_tokens'],
|
||||
] as const)('%s maxTokens=%d → %s=%d', async (model, requested, expected, field) => {
|
||||
const adapter = makeAdapter(model);
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
@@ -224,18 +224,18 @@ describe('OpenAIAdapter — token 参数路由', () => {
|
||||
expect(body[other]).toBeUndefined();
|
||||
});
|
||||
|
||||
it('o3-mini 未配置 maxTokens → 默认 32768(thinking 场景安全值)', async () => {
|
||||
it('o3-mini 未配置 maxTokens → 不下发 max_completion_tokens(无写死兜底)', async () => {
|
||||
const adapter = makeAdapter('o3-mini');
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
await adapter.send(makeRequest({ params: { temperature: 0, stream: false } }));
|
||||
expect(lastBody().max_completion_tokens).toBe(32_768);
|
||||
expect(lastBody().max_completion_tokens).toBeUndefined();
|
||||
});
|
||||
|
||||
it('非推理模型未配置 maxTokens → 默认模型上限', async () => {
|
||||
it('非推理模型未配置 maxTokens → 不下发 max_tokens(无写死兜底)', async () => {
|
||||
const adapter = makeAdapter('gpt-4o');
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
await adapter.send(makeRequest({ params: { temperature: 0, stream: false } }));
|
||||
expect(lastBody().max_tokens).toBe(16_384);
|
||||
expect(lastBody().max_tokens).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -277,23 +277,17 @@ describe('OpenAIAdapter — temperature 路由', () => {
|
||||
|
||||
// ===== getContextWindow 回退链 =====
|
||||
|
||||
describe('OpenAIAdapter — getContextWindow 回退链', () => {
|
||||
it('gpt-4.1 返回 1M 上下文', () => {
|
||||
expect(makeAdapter('gpt-4.1').getContextWindow()).toBe(1_000_000);
|
||||
});
|
||||
|
||||
it('o3-mini 返回 200K', () => {
|
||||
expect(makeAdapter('o3-mini').getContextWindow()).toBe(200_000);
|
||||
});
|
||||
|
||||
it('未知模型 → 兜底 128K(v0.7.4 P4-5 从 1M 降级)', () => {
|
||||
expect(makeAdapter('unknown-model-x').getContextWindow()).toBe(128_000);
|
||||
});
|
||||
|
||||
it('config.contextWindow 显式配置优先', () => {
|
||||
describe('OpenAIAdapter — getContextWindow(v0.8.1:唯一来源是设置面板配置)', () => {
|
||||
it('config.contextWindow 显式配置(llm.contextWindow 注入)返回配置值', () => {
|
||||
const adapter = makeAdapter('gpt-4o', { contextWindow: 64_000 });
|
||||
expect(adapter.getContextWindow()).toBe(64_000);
|
||||
});
|
||||
|
||||
it('未配置(任意模型,含已知/未知)→ 返回 0(引擎跳过压缩判定,无写死兜底)', () => {
|
||||
expect(makeAdapter('gpt-4.1').getContextWindow()).toBe(0);
|
||||
expect(makeAdapter('o3-mini').getContextWindow()).toBe(0);
|
||||
expect(makeAdapter('unknown-model-x').getContextWindow()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ===== listModels =====
|
||||
@@ -303,7 +297,9 @@ describe('OpenAIAdapter — listModels 动态发现与降级', () => {
|
||||
mockFetch.mockResolvedValue(okResponse({ data: [{ id: 'gpt-4o' }, { id: 'custom-model' }] }));
|
||||
const models = await makeAdapter('gpt-4o').listModels();
|
||||
expect(models).toHaveLength(2);
|
||||
expect(models[0]).toMatchObject({ id: 'gpt-4o', contextWindow: 128_000 });
|
||||
// v0.8.1: 元信息不再承载窗口/上限数值
|
||||
expect(models[0]).toMatchObject({ id: 'gpt-4o', name: 'GPT-4o' });
|
||||
expect(models[0].contextWindow).toBeUndefined();
|
||||
expect(models[1]).toEqual({ id: 'custom-model' });
|
||||
// /models 请求头携带 Bearer
|
||||
const [, init] = mockFetch.mock.calls[0] as [string, RequestInit];
|
||||
|
||||
Reference in New Issue
Block a user