基于WebView2实现的Win11桌面框架,利用插件自定义
chunhualin1
2026-08-14 b84db8983d63a9a981083ebce1a139860c6bdf25
docs/architecture/llm-command-palette-architecture.md
@@ -10,13 +10,14 @@
- 插件前端只负责输入、模型选择和流式渲染。
- 插件前端只传 `mode`、`projectId`、`modelId`、`messages` 和请求参数,不直接传 provider、endpoint、API key、AiChat 密码或 Session Token。
- 宿主维护 LLM 模型注册表,每个模型可独立配置 `provider`、`endpoint`、`authRef` 和 `apiModel`。
- 宿主按 `modelId` 选择 provider adapter,并把不同供应商的流式响应统一转换成插件可消费的事件。
- 宿主维护 LLM 模型注册表,每个模型可独立配置 `provider`、`baseUrl`、`authRef` 和 `apiModel`。旧配置中的 `endpoint`(完整 `/chat/completions` URL)会规范化为 `baseUrl`。
- 宿主按 `modelId` 选择 provider adapter,并把不同供应商的流式响应统一转换成插件可消费的事件。聊天请求发往 `{baseUrl}/chat/completions`。
- API key 不进入插件前端资源、manifest 示例或普通日志。
- 插件运行模式由配置决定:
  - `provider-direct`:沿用当前供应商直连链路,并可调用 AiChat 记忆接口管理/召回记忆。
  - `aichat-api`:通过自有 AiChat API 登录、读取项目、发送聊天和订阅 SSE;插件侧不处理记忆。
- AiChat 统一 Host 默认固定为 `http://192.168.1.111:13000`,不从 AiChat 接口文档的环境表推导。
  - `provider-direct`:沿用当前供应商直连链路;仅在已配置 AiChat 账号时调用记忆接口。
  - `aichat-api`:通过自有 AiChat API 登录、读取项目、发送聊天和订阅 SSE;插件侧不处理记忆。AiChat 账号与项目均为可选。
- 提供商可配置 `providers[]`,宿主按 `GET {baseUrl}/models` 拉取模型列表;自定义 `models[]` 仍可手写。
- AiChat 统一 Host 默认固定为 `http://192.168.1.111:13000`,仅有默认 `baseUrl` 不算已配置,不会登录。
## Goals
@@ -126,19 +127,27 @@
  Bridge->>Runtime: GetLlmModels(pluginId, instanceId)
  Runtime->>Llm: GetAvailableModels(pluginId)
  Llm->>Registry: Load enabled model summaries
  Llm->>Llm: Merge custom models[] then providers[] catalogs
  Registry-->>Llm: model id, label, provider, supportsStreaming
  Llm-->>Runtime: safe model summaries
  Runtime-->>Bridge: summaries without endpoint/authRef
  Runtime-->>Bridge: summaries without baseUrl/endpoint/authRef
  Bridge-->>Plugin: Promise resolve
```
插件模型下拉只能拿到安全摘要:
插件模型下拉只能拿到安全摘要。展示名由宿主格式化:
```json
[
  {
    "id": "gpt-5.4",
    "label": "GPT-5.4",
    "id": "local-qwen",
    "label": "qwen2.5:14b(Custom)",
    "provider": "openai-compatible",
    "supportsStreaming": true,
    "enabled": true
  },
  {
    "id": "provider:deepseek:deepseek-v4-flash",
    "label": "deepseek-v4-flash(DeepSeek)",
    "provider": "openai-compatible",
    "supportsStreaming": true,
    "enabled": true
@@ -146,15 +155,15 @@
]
```
默认不返回 `endpoint`、`authRef`、API key 或其他敏感配置。管理窗口可以在受控 UI 中展示和编辑 endpoint,但插件前端不需要知道。
默认不返回 `baseUrl`、`endpoint`、`authRef`、API key 或其他敏感配置。`providers[]` 中一家失败不影响自定义模型和其他提供商。
`aichat-api` 模式下模型列表来自 AiChat `GET /api/chat/models`,返回同样的安全摘要结构:
`aichat-api` 模式下模型列表来自 AiChat `GET /api/chat/models`,展示 `{id}(AiChat)`;未配置账号时不登录,返回空列表:
```json
[
  {
    "id": "deepseek-v4-flash",
    "label": "deepseek-v4-flash",
    "label": "deepseek-v4-flash(AiChat)",
    "provider": "aichat",
    "supportsStreaming": true,
    "enabled": true
@@ -175,7 +184,7 @@
  Plugin->>Bridge: getProjects()
  Bridge->>Runtime: GetAiChatProjects(pluginId, instanceId)
  Runtime->>AiChat: GetProjectsAsync()
  Runtime->>AiChat: GetProjectsAsync() only when email is configured
  AiChat->>Session: EnsureSessionAsync()
  Session->>Session: Resolve passwordEnv before password
  Session->>Api: POST /api/auth/login
@@ -183,9 +192,19 @@
  AiChat->>Api: GET /api/projects with x-session-token
  Api-->>AiChat: projects
  AiChat-->>Runtime: safe project summaries
  Runtime-->>Bridge: project summaries
  Runtime-->>Bridge: { status, message, projects }
  Bridge-->>Plugin: Promise resolve
```
`llm.getProjects` 成功返回状态包,而不是把未配置/登录失败当成桥接错误:
| `status` | 前端展示 | 是否登录 |
| --- | --- | --- |
| `not-configured` | `Not configured` | 否;仅有默认 `baseUrl` 不算已配置 |
| `not-connected` | `Not connected`,tooltip 为原因 | 已尝试登录但失败 |
| `ready` | 真实项目名 | 是;不自动选第一项,仅当 `defaultProjectId` 仍在列表中才选中 |
未配置 AiChat 时不提供长期记忆:`canUseMemory` / `canViewMemory` / `canManageMemory` 全为 false,且不调用记忆查询/创建/删除/召回。`provider-direct` 仍可按所选模型直连提问。
项目摘要建议只返回插件 UI 需要的字段:
@@ -218,7 +237,7 @@
  Runtime->>Runtime: Validate plugin permission llm.stream
  Runtime->>Llm: StreamChatAsync(request)
  Llm->>Registry: Get model by modelId when provider-direct
  Registry-->>Llm: provider, endpoint, authRef, apiModel
  Registry-->>Llm: provider, baseUrl, authRef, apiModel
  Llm->>Secret: Resolve authRef
  Secret-->>Llm: credential or null
  Llm->>Adapter: StreamAsync(normalized request)
@@ -335,7 +354,7 @@
      "id": "gpt-5.4",
      "label": "GPT-5.4",
      "provider": "openai-compatible",
      "endpoint": "https://api.openai.example/v1/chat/completions",
      "baseUrl": "https://api.openai.example/v1",
      "authRef": "llm.openai.primary",
      "apiModel": "gpt-5.4",
      "supportsStreaming": true,
@@ -350,7 +369,7 @@
      "id": "deepseek-chat",
      "label": "DeepSeek",
      "provider": "deepseek",
      "endpoint": "https://api.deepseek.com/chat/completions",
      "baseUrl": "https://api.deepseek.com",
      "authRef": "llm.deepseek.primary",
      "apiModel": "deepseek-chat",
      "supportsStreaming": true,
@@ -365,7 +384,7 @@
      "id": "local-qwen",
      "label": "Local Qwen",
      "provider": "openai-compatible",
      "endpoint": "http://127.0.0.1:11434/v1/chat/completions",
      "baseUrl": "http://127.0.0.1:11434/v1",
      "authRef": null,
      "apiModel": "qwen2.5:14b",
      "supportsStreaming": true,
@@ -391,17 +410,38 @@
  "aichat": {
    "baseUrl": "http://192.168.1.111:13000",
    "account": {
      "email": "user@example.com",
      "email": null,
      "password": null,
      "passwordEnv": "MOLI_AICHAT_PASSWORD"
    },
    "defaultProjectId": "",
    "defaultProjectId": null,
    "memory": {
      "enabledInProviderDirect": true,
      "defaultScope": "PROJECT",
      "recallLimit": 8
    }
  },
  "providers": [
    {
      "id": "deepseek",
      "label": "DeepSeek",
      "baseUrl": "https://api.deepseek.com",
      "authRef": "llm_deepseek_api_key",
      "enabled": true
  }
  ],
  "models": [
    {
      "id": "local-qwen",
      "label": "qwen2.5:14b",
      "provider": "openai-compatible",
      "baseUrl": "http://127.0.0.1:11434/v1",
      "authRef": null,
      "apiModel": "qwen2.5:14b",
      "supportsStreaming": true,
      "enabled": true
    }
  ]
}
```
@@ -411,11 +451,16 @@
| --- | --- |
| `mode` | `provider-direct` 或 `aichat-api`,缺失时默认为 `provider-direct` |
| `aichat.baseUrl` | `http` 或 `https` 绝对 URL,默认 `http://192.168.1.111:13000` |
| `aichat.account.email` | 可为空;调用 AiChat API 前必须存在 |
| `aichat.account.email` | 可为空;非空才视为已配置 AiChat,才会登录 |
| `aichat.account.passwordEnv` | 可为空;存在时优先读取环境变量 |
| `aichat.account.password` | 可为空;只作为本地测试 fallback |
| `aichat.defaultProjectId` | 可为空;不为空时应存在于项目列表 |
| `aichat.defaultProjectId` | 可为空;不为空且仍在项目列表中才默认选中 |
| `aichat.memory.recallLimit` | `1..20` |
| `providers[].id` | 提供商 id,用于 `provider:{id}:{apiModel}` |
| `providers[].label` | 下拉展示 `apiModel(label)` |
| `providers[].baseUrl` | OpenAI-compatible 根地址;聊天走 `{baseUrl}/chat/completions`,拉模型走 `{baseUrl}/models` |
| `providers[].authRef` | 可为空 |
| `models[].baseUrl` | 自定义模型根地址;旧 `endpoint` 若以 `/chat/completions` 结尾会规范化为 `baseUrl` |
密码解析顺序:
@@ -434,7 +479,7 @@
| `models[].id` | 全局唯一,推荐 `provider-name` 或用户可读 id |
| `models[].label` | 1 到 40 字符,供下拉展示 |
| `models[].provider` | 必须存在对应 adapter |
| `models[].endpoint` | 必须是 `http` 或 `https` 绝对 URL |
| `models[].baseUrl` | 必须是 `http` 或 `https` 绝对 URL;旧 `endpoint` 兼容 |
| `models[].authRef` | 可为空;不为空时不得包含明文 key |
| `models[].apiModel` | 必填,发送给上游供应商的真实模型名 |
| `models[].timeoutMs` | 建议 `5000..300000` |