feat: v0.7.0 四阶段全量迭代 — 修复面收口 · 安全纵深 · 架构还债 · 能力演进
P1 修复面收口: v0.6.3 截断自愈推全量(Anthropic/Ollama/非流式/引擎兜底); SSE 上游错误帧检测进重试通道; clearMessages 摘要游标根治; truncateResult 内联图片白名单统一; 前端四 bug(确认弹窗锁死/MemoryViewer/ Virtuoso Footer/abort 尾部过滤) + reasoning 缓冲跨迭代污染; 托盘通知过滤与新建会话死链接线 P2 安全纵深: MCP 审批闭环(ConfirmationHook×PolicyEngine 联动+重名拒注册); SSRF 收敛 ssrf-guard 共享模块 (web_fetch 双通道校验+重定向终态复检); Electron 加固(preload CJS 化→sandbox:true/CSP/权限白名单/will-navigate); run_command cmd.exe 白名单通道元字符守门; diff_viewer 10MB 预检; Anthropic thinking 预算下限; Agnes 思考显式关闭 P3 架构还债: OpenAICompatibleAdapter 中间基类收敛四家样板; 错误分类单轨化(删 mapError/getFetchSignal, 超时显式 ETIMEDOUT); PRAGMA user_version 迁移版本化; 死代码清理专项(cn.ts/SHORTCUTS/ContextMenu 分支/ getWindowState/modifiedArgs/sandbox 空壳); i18next 引入; a11y 第一轮; SearXNG 页批量草稿模型统一 P4 能力演进: Ollama pull 可取消/capabilities 探测/num_ctx 实测缓存; UpdateService feed 比对式自动更新 (app:updateCheck IPC + StatusBar 入口); MiMo providerOptions(web_search 服务端工具/strict JSON); web_fetch extract_mode=markdown(turndown); network.proxyUrl 全局代理(Chromium sessions+undici dispatcher) 测试: 264 → 507 用例(Electron ABI 全绿零跳过), 覆盖引擎压缩管线/重试竞速/MEMORY.md 闸门/file_editor 五操作/ filesystem 七工具实体夹具/git 真实仓库/SSE 错误帧/全线截断自愈/Provider 请求形态矩阵/SSRF 表测/钩子分级矩阵/ OutputValidator 全量/SLO 指标/MCP 安全纯函数/task_manager 链路/渲染层纯域/i18n 桥契约
This commit is contained in:
@@ -4,34 +4,26 @@
|
||||
* 基于 OpenAI 兼容 API。支持 Tool Calling、Thinking 模式、流式输出。
|
||||
* 模型: mimo-v2.5-pro(1M 上下文 / 131072 max_tokens)/ mimo-v2.5(1M 上下文 / 32768 max_tokens)
|
||||
*
|
||||
* 独立继承 BaseAdapter,通过 shared/openai-format 和 shared/sse-stream 复用
|
||||
* OpenAI 兼容格式构建和 SSE 流式解析逻辑。不与其他 Provider Adapter 耦合。
|
||||
*
|
||||
* 与 DeepSeek 适配器的关键差异:
|
||||
* - 使用 max_completion_tokens(非 max_tokens)
|
||||
* - thinking 参数结构与 DeepSeek 一致(thinking.type: "enabled"/"disabled")
|
||||
* - 不提供 /models 端点(listModels 回退到本地元数据)
|
||||
* - 不提供 /user/balance 端点
|
||||
* - tool_choice 仅支持 "auto"
|
||||
* v0.6.4 P3-1: 继承 OpenAICompatibleAdapter —— 传输/组装/回退链收敛到共享基类,
|
||||
* 本文件只保留 MiMo 差异点:max_completion_tokens 字段名、tool_choice 强制 "auto"、
|
||||
* 思考模式与 temperature/top_p 互斥、无 /models 端点(本地元数据列表)。
|
||||
*
|
||||
* @see apis/mimo-api-docs-20260715.html
|
||||
*/
|
||||
|
||||
import { BaseAdapter } from './base-adapter';
|
||||
import type { MetonaRequest, MetonaResponse, MetonaStreamEvent } from '../types';
|
||||
import { MetonaFinishReason } from '../types';
|
||||
import type { MetonaRequest } from '../types';
|
||||
import type { MetonaModelInfo } from '../types/metona-adapter';
|
||||
import { buildOpenAICompatibleMessages, buildOpenAICompatibleTools } from './shared/openai-format';
|
||||
import { parseSSEStream, parseOpenAICompatibleResponse } from './shared/sse-stream';
|
||||
import { OpenAICompatibleAdapter } from './shared/openai-compatible-base';
|
||||
|
||||
export class MimoAdapter extends BaseAdapter {
|
||||
export class MimoAdapter extends OpenAICompatibleAdapter {
|
||||
override readonly providerId: string = 'mimo';
|
||||
readonly supportedModels = ['mimo-v2.5-pro', 'mimo-v2.5'];
|
||||
readonly supportsToolCalling = true;
|
||||
readonly supportsThinking = true;
|
||||
|
||||
// MiMo 模型元信息
|
||||
// mimo-v2.5-pro: 1M 上下文(与 DeepSeek 一致)/ 131072 max_tokens;mimo-v2.5: 1M 上下文 / 32768 max_tokens
|
||||
// mimo-v2.5-pro: 1M 上下文 / 131072 max_tokens;mimo-v2.5: 1M 上下文 / 32768 max_tokens
|
||||
private static readonly MODEL_INFO: Record<string, MetonaModelInfo> = {
|
||||
'mimo-v2.5-pro': {
|
||||
id: 'mimo-v2.5-pro',
|
||||
@@ -53,83 +45,23 @@ export class MimoAdapter extends BaseAdapter {
|
||||
},
|
||||
};
|
||||
|
||||
// ===== POST /chat/completions (非流式) =====
|
||||
// ===== 共享基类差异声明 =====
|
||||
|
||||
async send(request: MetonaRequest): Promise<MetonaResponse> {
|
||||
const body = this.toNativeRequest(request, false);
|
||||
|
||||
// #24 修复: 使用 fetchWithTimeout 替代 getFetchSignal + fetch,确保 timer 清理
|
||||
const response = await this.fetchWithTimeout(
|
||||
`${this.config.baseURL}/chat/completions`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${this.config.apiKey}`,
|
||||
...this.config.headers,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
},
|
||||
this.config.timeoutMs ?? 120_000,
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
await this.throwHttpError(response, 'MiMo API error');
|
||||
}
|
||||
|
||||
const data = (await response.json()) as Record<string, unknown>;
|
||||
const parsed = parseOpenAICompatibleResponse(data);
|
||||
|
||||
return {
|
||||
meta: {
|
||||
requestId: request.meta.requestId,
|
||||
provider: this.providerId,
|
||||
model: (data.model as string) ?? this.config.defaultModel,
|
||||
latencyMs: 0,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
content: parsed.content,
|
||||
reasoningContent: parsed.reasoningContent,
|
||||
toolCalls: parsed.toolCalls,
|
||||
usage: parsed.usage,
|
||||
finishReason: parsed.finishReason as MetonaFinishReason,
|
||||
};
|
||||
protected override chatCompletionsUrl(): string {
|
||||
return `${this.config.baseURL}/chat/completions`;
|
||||
}
|
||||
|
||||
// ===== POST /chat/completions (流式) =====
|
||||
|
||||
async *sendStream(request: MetonaRequest): AsyncIterable<MetonaStreamEvent> {
|
||||
const body = this.toNativeRequest(request, true);
|
||||
|
||||
// #24 修复: 使用 fetchWithTimeout 替代 getFetchSignal + fetch,确保 timer 清理
|
||||
const response = await this.fetchWithTimeout(
|
||||
`${this.config.baseURL}/chat/completions`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${this.config.apiKey}`,
|
||||
...this.config.headers,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
},
|
||||
this.config.timeoutMs ?? 300_000,
|
||||
);
|
||||
|
||||
if (!response.ok || !response.body) {
|
||||
await this.throwHttpError(response, 'MiMo stream error');
|
||||
}
|
||||
|
||||
yield* parseSSEStream(
|
||||
// 非空断言:上方 if 已确保 response.body 不为 null
|
||||
response.body!,
|
||||
request.meta.requestId,
|
||||
request.meta.sessionId,
|
||||
request.meta.iteration,
|
||||
);
|
||||
protected override sendTimeoutMs(): number {
|
||||
return 120_000;
|
||||
}
|
||||
|
||||
// ===== 模型列表 =====
|
||||
protected override modelInfoTable(): Record<string, MetonaModelInfo> {
|
||||
return MimoAdapter.MODEL_INFO;
|
||||
}
|
||||
|
||||
protected override providerLabel(): string {
|
||||
return 'MiMo';
|
||||
}
|
||||
|
||||
/**
|
||||
* MiMo 官方未提供 /models 端点,直接返回本地元数据。
|
||||
@@ -138,37 +70,9 @@ export class MimoAdapter extends BaseAdapter {
|
||||
return this.supportedModels.map((id) => MimoAdapter.MODEL_INFO[id] ?? { id });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上下文窗口大小
|
||||
*
|
||||
* v0.3.1: 优先使用配置注入的 contextWindow,回退到 MODEL_INFO 默认值。
|
||||
* MiMo OpenAI 兼容 API 不支持 context_window 参数,此值仅用于
|
||||
* Engine 压缩判断和前端 UI 显示。
|
||||
*/
|
||||
override getContextWindow(): number {
|
||||
if (typeof this.config.contextWindow === 'number' && this.config.contextWindow > 0) {
|
||||
return this.config.contextWindow;
|
||||
}
|
||||
const modelInfo = MimoAdapter.MODEL_INFO[this.config.defaultModel];
|
||||
return modelInfo?.contextWindow ?? 1_000_000;
|
||||
}
|
||||
// ========== 协议参数映射(MiMo 差异点) ==========
|
||||
|
||||
// ========== 私有方法 ==========
|
||||
|
||||
/**
|
||||
* 构建 MiMo 原生请求体
|
||||
*
|
||||
* MiMo 特有参数:
|
||||
* - 多模态图片:user 消息的 images[] → OpenAI content 数组 [{type:"text"}, {type:"image_url"}]
|
||||
* 支持 HTTPS URL 或 base64 Data URI
|
||||
* - thinking: { type: "enabled" / "disabled" } — 与 DeepSeek 一致
|
||||
* - max_completion_tokens — 非 max_tokens(MiMo 使用新字段名)
|
||||
* - stream_options: { include_usage: true } — 流式返回 usage
|
||||
* - tool_choice: "auto" — MiMo 仅支持 auto
|
||||
*
|
||||
* 思考模式下 temperature/top_p 会被 API 强制覆盖,因此不传这两个参数。
|
||||
*/
|
||||
private toNativeRequest(request: MetonaRequest, stream: boolean): Record<string, unknown> {
|
||||
protected override toNativeRequest(request: MetonaRequest, stream: boolean): Record<string, unknown> {
|
||||
// v0.6.2: images 处理收敛至共享层(原索引对齐循环在孤立 tool 过滤后会错位)
|
||||
const messages = buildOpenAICompatibleMessages(request, true);
|
||||
const tools = buildOpenAICompatibleTools(request.tools);
|
||||
@@ -198,6 +102,24 @@ export class MimoAdapter extends BaseAdapter {
|
||||
body.tool_choice = 'auto';
|
||||
}
|
||||
|
||||
// v0.6.4 P4-3: MiMo 服务端内置工具透出 —— config.providerOptions.enableWebSearch
|
||||
// 开启后附加 {type:'web_search'} 服务端搜索工具(annotations 引用随响应返回,
|
||||
// 由上层归并为文本内容展示)。与客户端 tools 定义互不影响。
|
||||
const providerOptions = this.config.providerOptions as Record<string, unknown> | undefined;
|
||||
if (providerOptions?.['enableWebSearch'] === true) {
|
||||
const serverTools = body.tools
|
||||
? [...(body.tools as Array<Record<string, unknown>>), { type: 'web_search' }]
|
||||
: [{ type: 'web_search' }];
|
||||
body.tools = serverTools;
|
||||
if (!body.tool_choice) body.tool_choice = 'auto';
|
||||
}
|
||||
|
||||
// v0.6.4 P4-3: strict JSON 响应格式开关(response_format: json_object)——
|
||||
// 供结构化抽取类任务使用;与流式模式兼容性由服务端保证(文档标注支持子集)
|
||||
if (providerOptions?.['responseFormatJson'] === true) {
|
||||
body.response_format = { type: 'json_object' };
|
||||
}
|
||||
|
||||
// Thinking 模式(与 DeepSeek 参数结构一致)
|
||||
// MiMo API 默认 thinking.type = "enabled",必须显式发送 disabled 才能关闭
|
||||
if (request.params.thinkingEnabled === false) {
|
||||
|
||||
Reference in New Issue
Block a user