feat: 升级至 v0.3.1 — 全量代码审计修复 + 安全增强
本次升级基于完整代码审查,修复 Critical/High/Medium/Low 四级共 96 项问题, 并通过返工审计修复 10 项遗留问题,tsc 双端类型检查零错误。 Critical (10/10 完成): - C-4: command.ts 接入 shell-quote 进行 token-level 注入检测,替代原有正则匹配 可防御 r"m" -rf /、$'rm'、$(echo rm) 等字符串拼接绕过 High (11/11 完成): - 竞态保护、Promise.allSettled、AbortController 资源泄漏、IPC 参数校验等 Medium (55/55 完成): - 事务保护、敏感数据脱敏、枚举校验、MUI v9 Stack prop 迁移、 React 组件 cancelled 标志、类型收窄等 Low (20/20 完成): - 辅助方法提取(flushToolCallBuffer/scoreAndPushMemory/tryAddColumn 等) - nanoid 统一替代 Date.now()+Math.random() - confirm() 替换为 MUI Dialog、useMemo 缓存、魔法数字命名化等 返工审计修复 (10/10 完成): - L-11: LogsSettings 残留的原生 confirm()/alert() 全部替换为 MUI Dialog/Alert - M-53: MemoryViewer handleSearch 独立 ref,修复 searching 状态卡死 - M-42: 脱敏短值(length <= 4)泄露修复 - M-47: tasks:update 补全 title/description 类型校验 - L-9: ollama.adapter 非流式路径 nanoid 统一 - M-45: audit:query limit 策略与 memory:listAll 一致化 - SettingsModal handleConfirmRemove 补全 try/catch + loadServers cleanup - L-15: CommandPalette useMemo 补全 sessions 响应式依赖 - useAgentStream 事件类型补全 seq/timestamp 字段 新增依赖: shell-quote + @types/shell-quote 版本号: 0.3.0 -> 0.3.1
This commit is contained in:
@@ -3,11 +3,37 @@
|
||||
*
|
||||
* 所有 LLM Provider 适配器必须实现此接口。
|
||||
*
|
||||
* H-2 修复: 接口对齐规范
|
||||
* @see docs/MetonaAI-Desktop 内部API请求与响应标准.html
|
||||
* - provider → providerId(规范要求)
|
||||
* - chat → send(规范要求)
|
||||
* - chatStream → sendStream(规范要求)
|
||||
* - 新增 getContextWindow()(规范要求)
|
||||
* - listModels 返回 MetonaModelInfo[](规范要求)
|
||||
*/
|
||||
|
||||
import type { MetonaRequest, MetonaResponse, MetonaStreamEvent } from './index';
|
||||
|
||||
/**
|
||||
* H-2 修复: 新增 MetonaModelInfo 类型 — 规范要求的模型元信息
|
||||
*/
|
||||
export interface MetonaModelInfo {
|
||||
/** 模型 ID(如 'deepseek-v4-pro') */
|
||||
id: string;
|
||||
/** 模型显示名称(如 'DeepSeek V4 Pro') */
|
||||
name?: string;
|
||||
/** 上下文窗口大小(token 数) */
|
||||
contextWindow?: number;
|
||||
/** 最大输出 token 数 */
|
||||
maxOutputTokens?: number;
|
||||
/** 是否支持 Tool Calling */
|
||||
supportsToolCalling?: boolean;
|
||||
/** 是否支持 Thinking / Reasoning */
|
||||
supportsThinking?: boolean;
|
||||
/** 模型描述 */
|
||||
description?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider 适配器配置
|
||||
*/
|
||||
@@ -37,10 +63,10 @@ export interface AdapterConfig {
|
||||
* 铁律:外部 API 原始类型不得穿透到此接口之外
|
||||
*/
|
||||
export interface IMetonaProviderAdapter {
|
||||
/** Provider 标识 */
|
||||
readonly provider: string;
|
||||
/** H-2 修复: Provider 标识(规范要求使用 providerId) */
|
||||
readonly providerId: string;
|
||||
|
||||
/** 支持的模型列表 */
|
||||
/** 支持的模型列表(保留作为便捷访问) */
|
||||
readonly supportedModels: string[];
|
||||
|
||||
/** 是否支持 Tool Calling */
|
||||
@@ -50,15 +76,32 @@ export interface IMetonaProviderAdapter {
|
||||
readonly supportsThinking: boolean;
|
||||
|
||||
/**
|
||||
* 发送非流式请求
|
||||
* H-2 修复: 获取上下文窗口大小(token 数)
|
||||
* 规范要求的方法,用于 Engine 估算上下文使用率
|
||||
* @returns 上下文窗口大小(token 数)
|
||||
*/
|
||||
chat(request: MetonaRequest): Promise<MetonaResponse>;
|
||||
getContextWindow(): number;
|
||||
|
||||
/**
|
||||
* 发送流式请求
|
||||
* H-2 修复: 发送非流式请求(规范要求使用 send)
|
||||
*/
|
||||
send(request: MetonaRequest): Promise<MetonaResponse>;
|
||||
|
||||
/**
|
||||
* H-2 修复: 发送流式请求(规范要求使用 sendStream)
|
||||
* @returns AsyncIterable 逐事件推送 MetonaStreamEvent
|
||||
*/
|
||||
chatStream(request: MetonaRequest): AsyncIterable<MetonaStreamEvent>;
|
||||
sendStream(request: MetonaRequest): AsyncIterable<MetonaStreamEvent>;
|
||||
|
||||
/**
|
||||
* C-2 修复: 注入外部 AbortSignal,用于关联 Engine 的 abortController
|
||||
*
|
||||
* Engine 在调用 send/sendStream 前注入 signal,使用户 abort 能中断正在进行的 fetch,
|
||||
* 避免资源泄漏。Adapter 应将此 signal 与自身的 timeout signal 合并。
|
||||
*
|
||||
* @see project_memory.md — engine must use AbortController to avoid resource leaks on abort()
|
||||
*/
|
||||
setAbortSignal?(signal: AbortSignal | undefined): void;
|
||||
|
||||
/**
|
||||
* 检查 Provider 可用性
|
||||
@@ -66,7 +109,7 @@ export interface IMetonaProviderAdapter {
|
||||
healthCheck(): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* 列出可用模型(可选)
|
||||
* H-2 修复: 列出可用模型(规范要求返回 MetonaModelInfo[])
|
||||
*/
|
||||
listModels?(): Promise<string[]>;
|
||||
listModels?(): Promise<MetonaModelInfo[]>;
|
||||
}
|
||||
|
||||
@@ -73,8 +73,13 @@ export interface MetonaConstraints {
|
||||
export interface MetonaMessage {
|
||||
role: 'system' | 'user' | 'assistant' | 'tool';
|
||||
|
||||
/** 文本内容(纯文本或 Markdown) */
|
||||
content: string;
|
||||
/**
|
||||
* 文本内容(纯文本或 Markdown)
|
||||
*
|
||||
* C-6 修复: 允许 null — assistant 消息仅有 tool_calls 时 content 必须为 null
|
||||
* @see project_memory.md — Assistant messages with tool_calls must set content to null
|
||||
*/
|
||||
content: string | null;
|
||||
|
||||
/** (仅 assistant)思考/推理内容 */
|
||||
reasoningContent?: string;
|
||||
|
||||
@@ -79,6 +79,11 @@ export interface MetonaResponse {
|
||||
// ===== 流式事件 =====
|
||||
|
||||
export enum MetonaStreamEventType {
|
||||
// H-1 修复: 补齐 THINKING_START / THINKING_END — 用于显式标记思考阶段的边界
|
||||
// 规范来源: docs/MetonaAI-Desktop 内部API请求与响应标准.html
|
||||
// 时序: THINKING_START → REASONING_DELTA* → THINKING_END → TEXT_DELTA*
|
||||
THINKING_START = 'thinking_start',
|
||||
THINKING_END = 'thinking_end',
|
||||
TEXT_DELTA = 'text_delta',
|
||||
REASONING_DELTA = 'reasoning_delta',
|
||||
TOOL_CALL_DELTA = 'tool_call_delta',
|
||||
@@ -188,4 +193,9 @@ export enum MetonaErrorCode {
|
||||
USER_ABORTED = 'user_aborted',
|
||||
TIMEOUT = 'timeout',
|
||||
UNKNOWN = 'unknown',
|
||||
|
||||
// H-11 修复: Engine 内部使用的伪错误码,用于重试时通知前端清空已累积的 delta 缓冲区
|
||||
// 注意:这不是真正的错误,仅作为 ERROR 事件的特殊标记,engine 会过滤此事件不转发到 UI
|
||||
// 之前使用 'RETRY' as never 绕过类型检查,现在改为正式枚举值以确保类型安全
|
||||
RETRY = 'retry',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user