dsh-dev-workbench 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@ DeepSeek Harness 原生插件,把 AI 助手、消息跟进、研发任务、
5
5
  - **AI 助手**:在统一会话中读取消息识别、资讯、知识和事项上下文,结合规则与 AI 处理操作,保留进度、结果及确认回执。
6
6
  - **办公跟进**:今日简报、待办与待回复、云之家会话阅读、持续消息识别和日报周报。
7
7
  - **研发协作**:Linky 工作项、本地工程、专属 Harness 会话、测试与独立审查。
8
- - **分析与复用**:多 AI 统一提问、开发工具与数据查询、历史搜索和带来源的知识问答。
8
+ - **分析与复用**:多 AI 统一提问、开发工具与数据查询、全局本地搜索,以及按空间和项目隔离的本地知识检索。
9
9
 
10
10
  [源码仓库](https://github.com/LongerWu2026/dsh-dev-workbench) · [版本与下载](https://github.com/LongerWu2026/dsh-dev-workbench/releases) · [npm](https://www.npmjs.com/package/dsh-dev-workbench) · [问题反馈](https://github.com/LongerWu2026/dsh-dev-workbench/issues)
11
11
 
@@ -22,7 +22,7 @@ DeepSeek Harness 原生插件,把 AI 助手、消息跟进、研发任务、
22
22
  通过 npm 安装下列版本;若 registry 或镜像暂未同步,可使用下一节的 GitHub 预构建包。
23
23
 
24
24
  ```sh
25
- dsh plugin --profile desktop add dsh-dev-workbench@0.4.1
25
+ dsh plugin --profile desktop add dsh-dev-workbench@0.4.3
26
26
  ```
27
27
 
28
28
  将 `desktop` 替换为实际宿主使用的 profile。使用指定版本便于核对安装结果;桌面端也可使用应用自己的插件管理入口。
@@ -32,7 +32,7 @@ dsh plugin --profile desktop add dsh-dev-workbench@0.4.1
32
32
  从 [Releases](https://github.com/LongerWu2026/dsh-dev-workbench/releases) 下载 `dsh-dev-workbench-<版本>.tgz`,或直接安装:
33
33
 
34
34
  ```sh
35
- dsh plugin --profile desktop add https://github.com/LongerWu2026/dsh-dev-workbench/releases/download/v0.4.1/dsh-dev-workbench-0.4.1.tgz
35
+ dsh plugin --profile desktop add https://github.com/LongerWu2026/dsh-dev-workbench/releases/download/v0.4.3/dsh-dev-workbench-0.4.3.tgz
36
36
  ```
37
37
 
38
38
  升级后按宿主机制重载插件组件或重启 Harness,再打开侧栏「智能工作台」。只刷新页面不会重新注册新增 Host 接口;遇到 `/api/workbench/...` 返回 404,先重载插件组件。升级前建议备份工作台数据,位置见下文。
@@ -52,14 +52,14 @@ dsh plugin --profile desktop add https://github.com/LongerWu2026/dsh-dev-workben
52
52
  | 模块 | 可以做什么 |
53
53
  | --- | --- |
54
54
  | 今日简报 | 聚合待办、待回复与日程,查看本轮资讯概览;全局或局部刷新并查看分步进度 |
55
- | AI 助手 | 侧栏管理系统及事项会话,支持历史、附件、引用事项、规则/AI 指令卡片及真实执行回执 |
55
+ | AI 助手 | 侧栏管理系统及事项会话,独立加载目录和正文,支持停止、工具进度、附件、引用及真实执行回执 |
56
56
  | 研发任务 | 读取 Linky 本人需求、用户故事和缺陷,关联工程、原生工作区和开发会话,组织分析、开发、测试、独立审查与人工确认 |
57
57
  | 办公工具(AI 助手内) | 生成日报周报、批量回复草稿和待办方案,恢复既有产物,在聊天中查看自动回复设置 |
58
58
  | 任务中心与待回复 | 独立管理交付与回复责任,支持搜索、筛选、状态切换、来源回查和确认后回复 |
59
59
  | AI 资讯 | 联网与 RSS 采集、读取原文、生成摘要和本轮概览,展开同批资讯或查看完整目录 |
60
- | 知识空间 | 保存候选知识、人工审核、限定项目和账号范围,检索原文并显示版本、行号与引用 |
60
+ | 知识空间 | 人工审核资料,按空间和项目隔离;关键词与可选本地语义检索,返回原文、版本、行号和引用 |
61
61
  | 多 AI 对话 | 同一问题发给选定厂商,逐轮切换查看回答,管理附件和本地历史,将选中回答保存为候选知识 |
62
- | 工作搜索 | 在工作台记录中查找任务、回复、资料与问答,回到对应内容继续处理 |
62
+ | 全局搜索 | 顶部搜索图标或 Cmd/Ctrl+K 查询已保存的待办、知识、资讯与消息,预览正文并回到原事项;快速查询不联网 |
63
63
  | 开发工具箱 | 数据连接、JSON、Diff、HTTP/MCP 调试、日志、SQL、正则、类型生成及常用转换工具 |
64
64
  | 研发协作 | 管理本地工程、启动命令,联动 VS Code、IDEA 和终端,查看运行日志 |
65
65
 
@@ -75,6 +75,12 @@ dsh plugin --profile desktop add https://github.com/LongerWu2026/dsh-dev-workben
75
75
 
76
76
  原生会话、附件和身份能力依赖宿主实际提供的服务;不可用时显示原因。升级后须重载插件 Host 和客户端,才能使用新增接口。详见[AI 助手介绍](docs/ASSISTANT-HUB-2026-11-01.md)、[附件与引用](docs/ASSISTANT-ATTACHMENTS-IDENTITY-2026-11-01.md)、[事项与原生会话绑定](docs/ASSISTANT-NATIVE-BINDING-2026-11-01.md)和[办公主题](docs/ASSISTANT-COMPACT-WORKSPACE-2026-11-01.md)。
77
77
 
78
+ ### 会话运行与后台模型
79
+
80
+ 助手目录与会话内容分别加载,单个请求失败可局部重试;切换会话保留草稿和阅读位置。用户原话与事项引用分别呈现,工具调用进度与最终回答分开展示。运行中的会话提供「停止」,收到取消确认后继续核对真实终态;连续作业暂停会跨重启保留,明确继续后才处理未完成项。已完成操作和历史结果继续保留。
81
+
82
+ 在「连接与设置 → 后台任务模型」可分别选择消息识别与资讯摘要模型,或沿用会话模型。保存设置不启动任务,新选择从下一轮生效;目录来自宿主已配置的服务商,不另行保存模型凭据,也不修改宿主默认模型。能力依赖当前宿主公开接口,不可用时显示具体提示。详见[停止与暂停](docs/ASSISTANT-STOP-2026-11-04.md)、[后台模型](docs/BACKGROUND-MODELS-2026-11-04.md)和[局部加载](docs/ASSISTANT-PARTIAL-LOADING-2026-11-04.md)。
83
+
78
84
  ### 消息提取、待办与回复
79
85
 
80
86
  消息按组织、账号、会话和原消息去重,保留来源及北京时间。聚焦未读消息、@本人、@全员及明确关联已有事项的跟进,普通已读聊天不会全量交给 AI。只采集和处理插件安装日期(北京时间)起的消息;升级、恢复与导入保留本机安装日期。
@@ -96,16 +102,30 @@ dsh plugin --profile desktop add https://github.com/LongerWu2026/dsh-dev-workben
96
102
  - 人工审查展示差异、测试退出码及审查意见。批准绑定当前代码内容,后续变化会使批准失效。批准与向 Linky 回写评论分别确认,评论回写不会代替代码提交、合并或发布。
97
103
  - npm 包包含 `harness-linky` CLI,可将 Linky 的 Codex 协议入口适配到官方 Harness ACP;配置及权限边界见[实施说明](docs/LINKY-DEVELOPMENT-IMPLEMENTATION-2026-10-31.md)。
98
104
 
99
- 页面使用方式及工程选择见[研发任务说明](docs/DEVELOPMENT-UX-2026-10-31.md)。完整真实业务修复与回写仍需用户在实际工作项中验证,隔离测试不代表业务已完成。
105
+ 研发目录支持列表与详情分栏,保留所选工作项、筛选及会话上下文,窄屏按可用空间展开。页面使用方式及工程选择见[研发任务说明](docs/DEVELOPMENT-UX-2026-10-31.md)。完整真实业务修复与回写仍需用户在实际工作项中验证,隔离测试不代表业务已完成。
106
+
107
+ ### 全局搜索
108
+
109
+ 点击顶部搜索图标或按 Cmd/Ctrl+K,在同一个弹窗中筛选并查找已保存的待办、知识、资讯和消息。可查看完整正文、打开原事项,或把当前结果交给对应助手会话继续处理。快速搜索只查本地记录,不把输入发送给企业 CLI 或互联网服务;联网搜索入口只预填可编辑指令,明确发送后才执行。详见[全局搜索说明](docs/GLOBAL-WORK-SEARCH-2026-11-03.md)。
100
110
 
101
111
  ### 多 AI 对话与历史
102
112
 
103
113
  内嵌 Kimi、智谱清言、豆包、元宝和千问,ChatGPT 可选。统一输入问题,选择发送厂商,每轮通过厂商标签查看回答;各厂商保持自己的官网会话,新厂商不会自动继承其他厂商的历史上下文。
104
114
 
115
+ 新增回答支持增量展示和 Markdown 排版,保留表格、代码语言及文件树结构;复制、导出和保存知识使用完整已采集正文。官网更新仍通过 DOM 观察获取,历史中已丢失的格式不会自动复原。各厂商的登录状态可单独检查,遇到登录或验证码由用户在官网完成。
116
+
105
117
  支持选择、粘贴和拖入图片或文档,发送前预览和移除。每次最多 5 个附件,单文件 10 MB、合计 20 MB;历史仅保留附件元数据,刷新后需重选原文件。回答可保存、搜索、重命名、归档或放入本地回收站,选中内容可加入候选知识。恢复采集只读取回答;仅明确未提交的厂商可由用户点击补发,提交结果不确定时不自动重发。
106
118
 
107
119
  登录、验证码、站点繁忙及附件格式受各厂商规则约束。**跨 Harness 重启的网页登录持久化需要另行适配宿主扩展,安装本插件不会自动修改桌面应用**;普通原版宿主不保证这一能力。详见[聊天与补发](docs/WEB-AI-CHAT-REDESIGN-2026-10-30.md)、[历史管理](docs/WEB-AI-LOCAL-HISTORY-2026-10-29.md)、[真实站点验证](docs/WEB-AI-LIVE-ACCEPTANCE-2026-10-30.md)及[可选 rc.5 宿主扩展](host-integration/rc5/README.md)。
108
120
 
121
+ ### 本地知识检索与范围隔离
122
+
123
+ 默认使用关键词检索;可在「知识空间 → 本地语义检索」中按需下载并启用本地模型。固定版本的 BGE-small-zh-v1.5 INT8 与 WASM 运行时合计约 47 MB,逐文件校验大小与 SHA-256,模型不捆绑进插件包。无需安装 Python 或 Ollama,下载完成后向量计算在本地 Worker 中执行,空闲时自动释放;模型未就绪或索引过多时回退关键词检索。
124
+
125
+ 当前项目检索同项目与同空间公共资料,其他空间、其他项目不会自动纳入;个人通用知识需明确允许跨空间复用。已确认且有效的资料可自动增量索引,原文回读校验资料版本和引用范围。这里的范围隔离用于个人本地工作台,不提供多人服务的成员权限认证。PDF、Word 和图片未解析时不会被当作已入库正文。详见[本地 RAG 与知识空间](docs/LOCAL-KNOWLEDGE-RAG-2026-11-02.md)。
126
+
127
+ 普通聊天的自动知识模式由模型按需查询已保存资料,不在每次发送前固定检索;实际查询后才显示知识依据。仅知识库模式仍先检索,未命中时不调用模型;关闭模式不自动查询。知识工具沿用当前会话的空间、项目和本轮引用范围,模型不能自行扩大范围。详见[按需检索](docs/KNOWLEDGE-ON-DEMAND-2026-11-04.md)。
128
+
109
129
  ### 开发工具与数据查询
110
130
 
111
131
  工具箱按工具展示输入和结果,可搜索、筛选并在当前页面保留切换前的输入。JSON 支持格式化、树形查看和路径复制;Diff 支持文本和 JSON 结构对比;HTTP 调试支持导入基础 cURL,导入本身不发送请求;另有 MCP Streamable HTTP 调试、日志筛选、正则、Cron、SQL 格式化、类型生成、YAML/CSV 转换等工具。AI 辅助需显式点击,沿用宿主助手。
@@ -131,7 +151,9 @@ AI 助手的办公工具将工作记录组织为回复草稿、日报周报和
131
151
  | 数据连接非密码配置 | `data-connections.json` |
132
152
  | 研发配置、任务和适配器记录 | `development/` |
133
153
  | 助手会话索引、事项绑定、操作与轮次回执 | `assistant-*.json` |
154
+ | 与原生请求配对的独立事项上下文 | `assistant-native-contexts/` |
134
155
  | 托管云之家 CLI | `tools/yunzhijia/` |
156
+ | 本地语义模型、运行时与派生向量索引 | `knowledge-engine/` |
135
157
 
136
158
  迁移工具提供预检、备份、关联检查、合并或替换。**现有业务导出不会包含独立的 `development/`,备份研发记录时须一并保存该目录。助手会话索引及回执保存在独立的 `assistant-*.json` 中,现有业务导出不包含这些文件;需要保留助手归属时也应一并备份。** 模型凭据、厂商登录状态和原生 Harness 会话另行管理。
137
159
 
@@ -139,7 +161,7 @@ AI 助手的办公工具将工作记录组织为回复草稿、日报周报和
139
161
 
140
162
  ## 开发与验证
141
163
 
142
- 源码采用 TypeScript 和 React/TSX:`src/host.ts` 为 Host 入口,`src/client.ts` 为 Client 入口,`src/shared/` 维护共享契约,`src/cli/harness-linky.ts` 为 CLI 入口。构建生成 `index.js`、`client.js` 和 `bin/harness-linky.mjs`;不要直接编辑生成文件。模块职责见[源码导航](src/README.md)。
164
+ 源码采用 TypeScript 和 React/TSX:`src/host.ts` 为 Host 入口,`src/client.ts` 为 Client 入口,`src/shared/` 维护共享契约,`src/cli/harness-linky.ts` 为 CLI 入口。构建生成 `index.js`、`client.js`、`bin/harness-linky.mjs` 和 `bin/knowledge-embedding-worker.mjs`;不要直接编辑生成文件。模块职责见[源码导航](src/README.md)。
143
165
 
144
166
  ```sh
145
167
  pnpm install --frozen-lockfile
@@ -230,3 +230,176 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
230
230
  OTHER DEALINGS IN THE SOFTWARE.
231
231
 
232
232
  For more information, please refer to <http://unlicense.org>
233
+
234
+
235
+ Optional downloaded local embedding components (not bundled into client.js/index.js):
236
+ - Hugging Face Transformers.js 3.8.1: Apache-2.0, https://github.com/huggingface/transformers.js
237
+ - ONNX Runtime Web (WASM build distributed with Transformers.js): MIT, https://github.com/microsoft/onnxruntime
238
+ - BAAI/bge-small-zh-v1.5 and Xenova ONNX conversion: MIT, https://huggingface.co/BAAI/bge-small-zh-v1.5 and https://huggingface.co/Xenova/bge-small-zh-v1.5
239
+ Assets are downloaded from their official published locations at fixed versions and verified against SHA-256. The plugin's worker adapts the official browser build to a local-only filesystem transport; pretrained weights are not modified.
240
+
241
+
242
+ --- Multi AI Markdown rendering ---
243
+
244
+ Bundled component: markdown-it 15.0.3
245
+ License: MIT
246
+ Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin.
247
+
248
+ Permission is hereby granted, free of charge, to any person
249
+ obtaining a copy of this software and associated documentation
250
+ files (the "Software"), to deal in the Software without
251
+ restriction, including without limitation the rights to use,
252
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
253
+ copies of the Software, and to permit persons to whom the
254
+ Software is furnished to do so, subject to the following
255
+ conditions:
256
+
257
+ The above copyright notice and this permission notice shall be
258
+ included in all copies or substantial portions of the Software.
259
+
260
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
261
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
262
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
263
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
264
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
265
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
266
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
267
+ OTHER DEALINGS IN THE SOFTWARE.
268
+
269
+
270
+ Bundled component: entities 8.1.0
271
+ License: BSD-2-Clause
272
+ Copyright (c) Felix Böhm
273
+ All rights reserved.
274
+
275
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
276
+
277
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
278
+
279
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
280
+
281
+ THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
282
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
283
+
284
+
285
+ Bundled component: linkify-it 6.1.0
286
+ License: MIT
287
+ Copyright (c) 2015 Vitaly Puzrin.
288
+
289
+ Permission is hereby granted, free of charge, to any person
290
+ obtaining a copy of this software and associated documentation
291
+ files (the "Software"), to deal in the Software without
292
+ restriction, including without limitation the rights to use,
293
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
294
+ copies of the Software, and to permit persons to whom the
295
+ Software is furnished to do so, subject to the following
296
+ conditions:
297
+
298
+ The above copyright notice and this permission notice shall be
299
+ included in all copies or substantial portions of the Software.
300
+
301
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
302
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
303
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
304
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
305
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
306
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
307
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
308
+ OTHER DEALINGS IN THE SOFTWARE.
309
+
310
+
311
+ Bundled component: mdurl 2.1.0
312
+ License: MIT
313
+ Copyright (c) 2015 Vitaly Puzrin, Alex Kocharin.
314
+
315
+ Permission is hereby granted, free of charge, to any person
316
+ obtaining a copy of this software and associated documentation
317
+ files (the "Software"), to deal in the Software without
318
+ restriction, including without limitation the rights to use,
319
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
320
+ copies of the Software, and to permit persons to whom the
321
+ Software is furnished to do so, subject to the following
322
+ conditions:
323
+
324
+ The above copyright notice and this permission notice shall be
325
+ included in all copies or substantial portions of the Software.
326
+
327
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
328
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
329
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
330
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
331
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
332
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
333
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
334
+ OTHER DEALINGS IN THE SOFTWARE.
335
+
336
+ --------------------------------------------------------------------------------
337
+
338
+ .parse() is based on Joyent's node.js `url` code:
339
+
340
+ Copyright Joyent, Inc. and other Node contributors. All rights reserved.
341
+ Permission is hereby granted, free of charge, to any person obtaining a copy
342
+ of this software and associated documentation files (the "Software"), to
343
+ deal in the Software without restriction, including without limitation the
344
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
345
+ sell copies of the Software, and to permit persons to whom the Software is
346
+ furnished to do so, subject to the following conditions:
347
+
348
+ The above copyright notice and this permission notice shall be included in
349
+ all copies or substantial portions of the Software.
350
+
351
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
352
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
353
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
354
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
355
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
356
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
357
+ IN THE SOFTWARE.
358
+
359
+
360
+ Bundled component: punycode.js 2.3.1
361
+ License: MIT
362
+ Copyright Mathias Bynens <https://mathiasbynens.be/>
363
+
364
+ Permission is hereby granted, free of charge, to any person obtaining
365
+ a copy of this software and associated documentation files (the
366
+ "Software"), to deal in the Software without restriction, including
367
+ without limitation the rights to use, copy, modify, merge, publish,
368
+ distribute, sublicense, and/or sell copies of the Software, and to
369
+ permit persons to whom the Software is furnished to do so, subject to
370
+ the following conditions:
371
+
372
+ The above copyright notice and this permission notice shall be
373
+ included in all copies or substantial portions of the Software.
374
+
375
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
376
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
377
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
378
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
379
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
380
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
381
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
382
+
383
+
384
+ Bundled component: uc.micro 3.0.0
385
+ License: MIT
386
+ Copyright Mathias Bynens <https://mathiasbynens.be/>
387
+
388
+ Permission is hereby granted, free of charge, to any person obtaining
389
+ a copy of this software and associated documentation files (the
390
+ "Software"), to deal in the Software without restriction, including
391
+ without limitation the rights to use, copy, modify, merge, publish,
392
+ distribute, sublicense, and/or sell copies of the Software, and to
393
+ permit persons to whom the Software is furnished to do so, subject to
394
+ the following conditions:
395
+
396
+ The above copyright notice and this permission notice shall be
397
+ included in all copies or substantial portions of the Software.
398
+
399
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
400
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
401
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
402
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
403
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
404
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
405
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ // src/host/knowledge/embedding-worker.ts
2
+ import { parentPort, workerData } from "node:worker_threads";
3
+ import { readFile } from "node:fs/promises";
4
+ import { resolve, sep } from "node:path";
5
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
+ var root = resolve(workerData.root);
7
+ var port = parentPort;
8
+ var pipeline;
9
+ async function initialize() {
10
+ const nodeProcess = globalThis.process;
11
+ Object.assign(globalThis, { self: globalThis, location: { href: pathToFileURL(resolve(root, "runtime/transformers.min.js")).href } });
12
+ let lib;
13
+ try {
14
+ globalThis.process = void 0;
15
+ lib = await import(pathToFileURL(resolve(root, "runtime/transformers.min.js")).href);
16
+ } finally {
17
+ globalThis.process = nodeProcess;
18
+ }
19
+ lib.env.allowRemoteModels = false;
20
+ lib.env.allowLocalModels = true;
21
+ lib.env.useBrowserCache = false;
22
+ lib.env.useFSCache = false;
23
+ lib.env.localModelPath = "http://workbench-model.local/";
24
+ Object.assign(lib.env.backends.onnx.wasm, { numThreads: 1, proxy: false, wasmPaths: pathToFileURL(resolve(root, "runtime") + sep).href });
25
+ globalThis.fetch = async (input) => {
26
+ const url = String(input), local = url.startsWith("http://workbench-model.local/") ? resolve(root, "models", decodeURIComponent(new URL(url).pathname).slice(1)) : url.startsWith("file:") ? fileURLToPath(url) : "";
27
+ if (!local || !resolve(local).startsWith(root + sep)) throw Error("本地向量运行时拒绝外部请求");
28
+ try {
29
+ return new Response(new Uint8Array(await readFile(local)));
30
+ } catch {
31
+ return new Response("", { status: 404 });
32
+ }
33
+ };
34
+ pipeline = await lib.pipeline("feature-extraction", "bge-small-zh", { device: "wasm", dtype: "q8" });
35
+ }
36
+ var ready = initialize();
37
+ port.on("message", async (message) => {
38
+ try {
39
+ await ready;
40
+ if (!Array.isArray(message.texts) || message.texts.length > 8 || message.texts.some((text) => typeof text !== "string" || text.length > 8e3)) throw Error("向量输入超过批次限制");
41
+ const texts = message.texts.map((text) => message.query ? "为这个句子生成表示以用于检索相关文章:" + text : text);
42
+ const output = await pipeline(texts, { pooling: "cls", normalize: true, truncation: true, max_length: 512 });
43
+ port.postMessage({ id: message.id, vectors: output.tolist(), rss: process.memoryUsage().rss });
44
+ } catch (error) {
45
+ port.postMessage({ id: message.id, error: String(error.message || error).slice(0, 300) });
46
+ }
47
+ });
48
+ ready.catch((error) => port.postMessage({ fatal: String(error.message || error).slice(0, 300) }));