dsh-total-quality 0.0.0-stage → 2.0.0
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/CONTRIBUTING.md +34 -0
- package/LICENSE.md +37 -0
- package/README.md +102 -2
- package/agent-host.cjs +255 -0
- package/client.js +115 -0
- package/cordis.patch.yml +5 -0
- package/db.cjs +261 -0
- package/host.cjs +1075 -0
- package/icon.svg +14 -0
- package/index.js +83 -0
- package/llm-bridge.cjs +167 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +81 -4
- package/public/app.css +504 -0
- package/public/app.js +1316 -0
- package/public/assets/wechat-support-blue.svg +9 -0
- package/public/index.html +129 -0
- package/public/js/api.js +81 -0
- package/public/js/pages-analytics.js +263 -0
- package/public/js/pages-cockpit.js +308 -0
- package/public/js/pages-core.js +359 -0
- package/public/js/pages-kb.js +339 -0
- package/public/js/pages-qms.js +321 -0
- package/public/js/pages-system.js +178 -0
- package/public/js/tool-wizards.js +498 -0
- package/public/js/ui.js +343 -0
- package/src/agent.js +338 -0
- package/src/data/seed-sme.js +318 -0
- package/src/data/seed.js +880 -0
- package/src/lib/llm.js +279 -0
- package/src/lib/office.js +1978 -0
- package/src/lib/qms.js +369 -0
- package/src/lib/retrieval.js +155 -0
- package/src/lib/stats.js +2767 -0
- package/src/lib/store.js +279 -0
- package/src/package.json +3 -0
- package/src/tools/analysis.js +333 -0
- package/src/tools/business.js +1021 -0
- package/src/tools/data.js +592 -0
- package/src/tools/docs.js +321 -0
- package/src/tools/registry.js +57 -0
- package/tools-dsh.cjs +149 -0
- package//345/256/211/350/243/205/350/257/264/346/230/216.md +83 -0
- package//346/234/254/346/234/272/347/213/254/347/253/213/345/256/211/350/243/205/350/257/264/346/230/216.md +17 -0
- package//350/207/252/346/243/200.cjs +88 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# 参与贡献
|
|
2
|
+
|
|
3
|
+
## 本地开发
|
|
4
|
+
|
|
5
|
+
本插件使用原生 JavaScript,没有前端构建步骤。
|
|
6
|
+
通过 DeepSeek Harness 安装本地插件目录,页面修改后刷新;宿主修改后重新加载或重装 bundle。
|
|
7
|
+
|
|
8
|
+
提交前运行:
|
|
9
|
+
|
|
10
|
+
node --check index.js
|
|
11
|
+
node --check host.cjs
|
|
12
|
+
node --check public/app.js
|
|
13
|
+
node 自检.cjs
|
|
14
|
+
|
|
15
|
+
自检使用临时数据目录,验证文件、Node/SQLite、建库、工具数量和 Cpk 计算。
|
|
16
|
+
UI 修改需要核对实际页面与窄屏布局;二维码修改需核对识别内容不变。
|
|
17
|
+
|
|
18
|
+
## 目录
|
|
19
|
+
|
|
20
|
+
- index.js、host.cjs:宿主入口、HTTP、业务服务。
|
|
21
|
+
- client.js:DSH 侧栏入口与 iframe。
|
|
22
|
+
- public/:页面、样式与服务二维码。
|
|
23
|
+
- src/tools/:数据、统计、业务与报告工具。
|
|
24
|
+
- src/lib/:SQLite 写穿、统计、文档与体系文件。
|
|
25
|
+
- src/data/:程序生成的样例数据。
|
|
26
|
+
- tools-dsh.cjs:16 个 qip_real_* 宿主工具。
|
|
27
|
+
|
|
28
|
+
## 修改约定
|
|
29
|
+
|
|
30
|
+
维持 /qip-real/、qip_real_*、QIP_REAL_DATA_DIR 的隔离关系。
|
|
31
|
+
报告下载链接和前端 API 路径应同步检查。
|
|
32
|
+
不要提交本机数据库、登录凭据、真实企业数据、日志、node_modules 或生成的报告。
|
|
33
|
+
功能或安装方式变化时同步更新 README.md 和安装说明.md。
|
|
34
|
+
提问题请附页面、复现步骤与期望行为;提交一个清晰的变更,并保留 MIT 版权与许可声明。
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 全质开源质量平台贡献者 / Quanzhi Open-Source Quality Platform contributors
|
|
4
|
+
|
|
5
|
+
本插件(`dsh-total-quality`,含 Host 半、Client 半、统计/文档引擎移植与页面资源)以 MIT 许可开源发布。
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 中文说明(非法律文本,仅供理解)
|
|
28
|
+
|
|
29
|
+
- **您可以**:商用、修改、二次开发、私有化部署、再分发,无需付费、无需获得额外授权。
|
|
30
|
+
- **您需要**:保留本许可与版权声明;对外分发时随包附带本文件。
|
|
31
|
+
- **不含**:本插件不附带任何厂商的私有数据、客户资料或商用证书文件;初始数据均为程序生成的合成样例,仅供试用与培训。
|
|
32
|
+
- **免责**:软件按「现状」提供,不承诺适用性;用于实际生产前,请自行复核体系文件条文与统计结论。
|
|
33
|
+
|
|
34
|
+
## 第三方依赖
|
|
35
|
+
|
|
36
|
+
- DeepSeek Harness(宿主)、Node.js / `node:sqlite`、以及任何随包安装的 npm 依赖,遵循其各自许可。
|
|
37
|
+
- 浏览器侧的图标为系统 emoji 字符,不包含第三方图标字体资源。
|
package/README.md
CHANGED
|
@@ -1,3 +1,103 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 全质开源质量平台 · DeepSeek Harness 插件
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
插件包名:`dsh-total-quality`。源代码仓库:[total-quality/dsh-total-quality](https://github.com/total-quality/dsh-total-quality)。
|
|
4
|
+
|
|
5
|
+
本地运行的中小企业质量管理与改进平台。基础版本 2.0.0,本次整理版包含独立安装隔离、蓝色服务二维码及配套说明。
|
|
6
|
+
源代码按 MIT 许可提供,见 LICENSE.md。
|
|
7
|
+
|
|
8
|
+
## 主要功能
|
|
9
|
+
|
|
10
|
+
| 模块 | 内容 |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| 质量驾驶舱 | 运行中枢、确认与纠正、执行跟进、接收与追溯、经验与标准 |
|
|
13
|
+
| AI 工作台 | AI 改进工作台、质量问题库、质量改进项目、QRQC、报表中心 |
|
|
14
|
+
| 统计工具 | SPC 控制图、八大判异准则、Cp/Cpk/Pp/Ppk、统计检验、MSA、DOE、FMEA 等 |
|
|
15
|
+
| 体系文件 | 质量手册、程序文件、三层次文件 |
|
|
16
|
+
| 知识与团队 | 知识经验与员工成长 |
|
|
17
|
+
| 系统 | 插件架构、移动端、审计日志、系统设置 |
|
|
18
|
+
| 文件导出 | Word 报告、Excel 或 CSV 数据 |
|
|
19
|
+
|
|
20
|
+
首次启动由程序创建合成样例数据:48 条质量问题、5 个课题、2 个关键特性、600 条测量值、16 条知识经验、12 名成员和 8 场 QRQC。
|
|
21
|
+
这些是试用与培训数据,实际生产分析需要导入自己的业务数据。
|
|
22
|
+
|
|
23
|
+
## 安装与打开
|
|
24
|
+
|
|
25
|
+
完整步骤见 [安装说明](安装说明.md)。
|
|
26
|
+
|
|
27
|
+
在 Harness 的“添加插件”中输入 `dsh-total-quality` 安装。使用 CLI web profile 时,在已安装 DSH 与 pnpm 的终端中执行:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
dsh plugin --profile web add dsh-total-quality
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
安装完成后,在当前 Harness 的左侧栏打开“全质开源质量平台”。若提示重新加载,按提示重新加载宿主。
|
|
34
|
+
包名用于安装;页面地址仍是 `/qip-real/`,数据目录和 `qip_real_*` 工具前缀保持不变。
|
|
35
|
+
|
|
36
|
+
将 qip-real 文件夹解压到固定位置,在目标 Harness 的会话里让智能体调用 plugin_manager / install_bundle,安装该文件夹的绝对路径。
|
|
37
|
+
安装后侧栏入口为“全质开源质量平台”,整页应用地址为 http://127.0.0.1:<DSH端口>/qip-real/。
|
|
38
|
+
包内不是独立监听端口的网页服务器,需要由 DSH 加载。
|
|
39
|
+
|
|
40
|
+
本次在 Windows、Node 24.19.0、DSH 0.2.2-rc.1 的 web profile 中安装并做基础检查。
|
|
41
|
+
其他环境需要核对其 DSH bundle、web 客户端和 node:sqlite 支持情况。
|
|
42
|
+
|
|
43
|
+
## 独立安装与数据
|
|
44
|
+
|
|
45
|
+
本版使用独立页面 /qip-real/、宿主工具 qip_real_*、品牌缓存 qip-real.brand。
|
|
46
|
+
默认数据位于 DSH_HOME/qip-real/data/;未设置 DSH_HOME 时使用用户目录下的 .dsh/qip-real/data/。
|
|
47
|
+
|
|
48
|
+
~/.dsh/qip-real/data/
|
|
49
|
+
qip-sme.db SQLite 业务数据库
|
|
50
|
+
qip-db-sme.json JSON 快照
|
|
51
|
+
reports/ 生成的报告与导出文件
|
|
52
|
+
|
|
53
|
+
可用 QIP_REAL_DATA_DIR 指定其他数据目录。与原插件并存时应使用不同目录。
|
|
54
|
+
插件代码与数据分开存放;升级前请备份数据,关闭 DSH 后复制整个 data 文件夹,以包含可能存在的 SQLite WAL 文件。
|
|
55
|
+
|
|
56
|
+
## 模型
|
|
57
|
+
|
|
58
|
+
通过 Harness 的 LLM 服务调用模型,复用其配置与登录态。
|
|
59
|
+
默认选择 deepseek-official / deepseek-flash;可用 QIP_LLM_PROVIDER、QIP_LLM_MODEL 覆盖。
|
|
60
|
+
无法解析默认模型时,桥接层会尝试回落 Harness 当前模型。
|
|
61
|
+
在“系统设置 → 模型接入”查看状态;“测试连通性”会发送实际模型请求,可能产生账号用量。
|
|
62
|
+
本地存储不会自动同步到 GitHub;使用 AI 时,模型请求仍会将相关输入交给 Harness 配置的模型服务。
|
|
63
|
+
|
|
64
|
+
## 16 个宿主工具
|
|
65
|
+
|
|
66
|
+
qip_real_overview
|
|
67
|
+
qip_real_spc_list_chars
|
|
68
|
+
qip_real_spc_rule_check
|
|
69
|
+
qip_real_spc_capability
|
|
70
|
+
qip_real_spc_control_chart
|
|
71
|
+
qip_real_measurements
|
|
72
|
+
qip_real_issue_search
|
|
73
|
+
qip_real_issue_create
|
|
74
|
+
qip_real_project_list
|
|
75
|
+
qip_real_project_advance
|
|
76
|
+
qip_real_knowledge_search
|
|
77
|
+
qip_real_risk_scan
|
|
78
|
+
qip_real_benefit_calc
|
|
79
|
+
qip_real_report_generate
|
|
80
|
+
qip_real_data_export
|
|
81
|
+
qip_real_db_status
|
|
82
|
+
|
|
83
|
+
对话示例:“使用全质独立插件列出关键特性,然后计算 CT-A01 近 30 天的 Cpk。”
|
|
84
|
+
先列出实际特性,再选择数据库中存在的编号。
|
|
85
|
+
|
|
86
|
+
## 服务二维码
|
|
87
|
+
|
|
88
|
+
“运行中枢”右侧采用蓝色微信二维码,颜色 #3a6ddf。
|
|
89
|
+
下方文字:免费服务微信:周一到周六,早8:00至晚8:00
|
|
90
|
+
资源位于 public/assets/wechat-support-blue.svg,由原始二维码内嵌并作显示颜色映射。
|
|
91
|
+
|
|
92
|
+
## 开发与自检
|
|
93
|
+
|
|
94
|
+
没有前端构建步骤,采用原生 JavaScript 与 ESM/CommonJS。
|
|
95
|
+
|
|
96
|
+
node --check index.js
|
|
97
|
+
node --check host.cjs
|
|
98
|
+
node --check public/app.js
|
|
99
|
+
node 自检.cjs
|
|
100
|
+
|
|
101
|
+
自检在临时目录建库并计算 Cpk,不使用正式数据目录,不需要联网或登录模型。
|
|
102
|
+
修改 public/ 页面资源后刷新;修改宿主代码后重新加载或重装 dsh-total-quality bundle。
|
|
103
|
+
更详细的接口与目录说明见源文件,以及 [贡献指南](CONTRIBUTING.md)。
|
package/agent-host.cjs
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* 智能体内核(内置实现)—— 改走 Harness 内置真实 DeepSeek 模型
|
|
4
|
+
* ------------------------------------------------------------------
|
|
5
|
+
* 与内置 src/agent.js 的区别只有一处:不再用「OpenAI 兼容 + API Key」直连,
|
|
6
|
+
* 而是把每一轮推理交给 DeepSeek Harness 的 ctx.llm(真实 DeepSeek)。
|
|
7
|
+
*
|
|
8
|
+
* 工具编排协议:每轮模型只输出一个 JSON(ReAct):
|
|
9
|
+
* 调工具 {"thought":"...","tool":"工具名","args":{...}}
|
|
10
|
+
* 给结论 {"thought":"...","final":"Markdown 回答"}
|
|
11
|
+
* 这样不依赖各供应商 function-calling 的差异,任何 Harness 模型都能稳定编排。
|
|
12
|
+
*
|
|
13
|
+
* 护栏沿用内置实现:结论要有出处、三类动作人工确认、VIN/手机号脱敏、全程审计。
|
|
14
|
+
*/
|
|
15
|
+
const store = require('./src/lib/store');
|
|
16
|
+
const base = require('./src/agent');
|
|
17
|
+
const registry = base.registry;
|
|
18
|
+
|
|
19
|
+
const runtime = { llm: null };
|
|
20
|
+
function setRuntime(next) { Object.assign(runtime, next || {}); }
|
|
21
|
+
|
|
22
|
+
const CONFIRM_HINT = '该动作属于「对外发送 / 对外承诺 / 项目关闭」类,系统已挂起为待确认项;请告诉用户点击确认后才会真正执行,不要声称已经执行。';
|
|
23
|
+
|
|
24
|
+
/* ---------------- 工具筛选与目录 ---------------- */
|
|
25
|
+
|
|
26
|
+
function pluginFilter(settings) {
|
|
27
|
+
const plugins = (settings && settings.plugins) || {};
|
|
28
|
+
const disabled = new Set();
|
|
29
|
+
Object.keys(plugins).forEach((k) => { if (plugins[k] && plugins[k].enabled === false) disabled.add(plugins[k].name); });
|
|
30
|
+
return (t) => !disabled.has(t.plugin);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function signatureOf(params) {
|
|
34
|
+
const props = (params && params.properties) || {};
|
|
35
|
+
const required = new Set((params && params.required) || []);
|
|
36
|
+
return Object.keys(props)
|
|
37
|
+
.map((key) => (required.has(key) ? key : key + '?'))
|
|
38
|
+
.join(', ');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function catalogText(tools) {
|
|
42
|
+
return tools
|
|
43
|
+
.map((t) => '- ' + t.name + '(' + signatureOf(t.parameters) + '):[' + t.plugin + '] ' + t.label +
|
|
44
|
+
(t.description ? ' — ' + String(t.description).replace(/\s+/g, ' ').slice(0, 140) : ''))
|
|
45
|
+
.join('\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function protocolText(tools, maxRounds) {
|
|
49
|
+
return [
|
|
50
|
+
'',
|
|
51
|
+
'# 工具调用协议(必须严格遵守)',
|
|
52
|
+
'您有两类输出,二选一;**每轮只输出一个 JSON 对象**,不要输出 Markdown 代码块以外的任何解释文字。',
|
|
53
|
+
'1) 需要取数/执行动作时:',
|
|
54
|
+
'{"thought":"为什么调用、期望拿到什么","tool":"工具名","args":{参数对象}}',
|
|
55
|
+
'2) 已经可以回答时:',
|
|
56
|
+
'{"thought":"本轮推理摘要","final":"给用户的完整中文 Markdown 回答"}',
|
|
57
|
+
'',
|
|
58
|
+
'规则:',
|
|
59
|
+
'- tool 必须是下面清单里的名字,禁止编造;args 按括号里的参数签名给,缺省参数可以省略。',
|
|
60
|
+
'- 每轮只调用一个工具;拿到工具结果后再决定下一步。最多 ' + maxRounds + ' 轮。',
|
|
61
|
+
'- 回答里的每一个数字都必须来自工具返回值;没有工具数据支撑的判断只能写成「假设」,并给出验证方法。',
|
|
62
|
+
'- 需要人工确认的动作会被系统挂起,不要在回答里声称它已经执行。',
|
|
63
|
+
'',
|
|
64
|
+
'# 可用工具(共 ' + tools.length + ' 个,全部真实执行)',
|
|
65
|
+
catalogText(tools),
|
|
66
|
+
'',
|
|
67
|
+
].join('\n');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* ---------------- 解析模型输出 ---------------- */
|
|
71
|
+
|
|
72
|
+
function parseAction(raw) {
|
|
73
|
+
const text = String(raw || '');
|
|
74
|
+
const fenced = /```(?:json)?\s*([\s\S]*?)```/i.exec(text);
|
|
75
|
+
const body = fenced ? fenced[1] : text;
|
|
76
|
+
const start = body.indexOf('{');
|
|
77
|
+
const end = body.lastIndexOf('}');
|
|
78
|
+
if (start >= 0 && end > start) {
|
|
79
|
+
try {
|
|
80
|
+
const obj = JSON.parse(body.slice(start, end + 1));
|
|
81
|
+
if (obj && typeof obj === 'object') {
|
|
82
|
+
if (typeof obj.tool === 'string' && obj.tool) {
|
|
83
|
+
return { thought: obj.thought ? String(obj.thought) : '', tool: obj.tool, args: obj.args && typeof obj.args === 'object' ? obj.args : {} };
|
|
84
|
+
}
|
|
85
|
+
if (typeof obj.final === 'string') return { thought: obj.thought ? String(obj.thought) : '', final: obj.final };
|
|
86
|
+
if (typeof obj.answer === 'string') return { thought: obj.thought ? String(obj.thought) : '', final: obj.answer };
|
|
87
|
+
}
|
|
88
|
+
} catch (_) { /* 不是 JSON:按普通回答处理 */ }
|
|
89
|
+
}
|
|
90
|
+
return { thought: '', final: text.trim() };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function truncate(text, max) {
|
|
94
|
+
return text && text.length > max ? text.slice(0, max) + '…[已截断]' : text;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function buildUserMessage({ question, history, transcript }) {
|
|
98
|
+
const lines = [];
|
|
99
|
+
if (history && history.length) {
|
|
100
|
+
lines.push('<历史对话>');
|
|
101
|
+
for (const item of history) lines.push((item.role === 'user' ? '用户:' : '助手:') + truncate(String(item.content || ''), 1200));
|
|
102
|
+
lines.push('</历史对话>');
|
|
103
|
+
lines.push('');
|
|
104
|
+
}
|
|
105
|
+
lines.push('<用户当前问题>');
|
|
106
|
+
lines.push(question);
|
|
107
|
+
lines.push('</用户当前问题>');
|
|
108
|
+
if (transcript && transcript.length) {
|
|
109
|
+
lines.push('');
|
|
110
|
+
lines.push('<已执行的工具调用与真实返回>');
|
|
111
|
+
for (const step of transcript) {
|
|
112
|
+
lines.push('[工具] ' + step.name + ' 参数=' + JSON.stringify(step.args || {}));
|
|
113
|
+
lines.push('[真实返回] ' + truncate(step.resultText, 6000));
|
|
114
|
+
}
|
|
115
|
+
lines.push('</已执行的工具调用与真实返回>');
|
|
116
|
+
}
|
|
117
|
+
lines.push('');
|
|
118
|
+
lines.push('现在请继续:要么按协议输出下一个工具调用,要么输出最终回答。');
|
|
119
|
+
return lines.join('\n');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* ---------------- 主循环 ---------------- */
|
|
123
|
+
|
|
124
|
+
async function run(p, onEvent) {
|
|
125
|
+
const emit = (event) => { try { if (onEvent) onEvent(event); } catch (_) { /* 前端已断开 */ } };
|
|
126
|
+
const settings = p.settings || store.db.settings || {};
|
|
127
|
+
const agentCfg = settings.agent || {};
|
|
128
|
+
const maxRounds = Math.min(Math.max(Number(agentCfg.maxRounds) || 8, 1), 16);
|
|
129
|
+
const llm = runtime.llm;
|
|
130
|
+
|
|
131
|
+
if (!llm) {
|
|
132
|
+
emit({ type: 'error', code: 'NO_MODEL', message: 'Harness 当前没有可用模型,插件无法发起真实对话。请先在 Harness 里完成 DeepSeek 模型接入。' });
|
|
133
|
+
return { ok: false, code: 'NO_MODEL' };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const tools = registry.all().filter(pluginFilter(settings));
|
|
137
|
+
const byName = new Map(tools.map((t) => [t.name, t]));
|
|
138
|
+
emit({ type: 'start', model: (runtime.model && runtime.model.model) || 'DeepSeek', tools: tools.length, rounds: maxRounds });
|
|
139
|
+
|
|
140
|
+
const system = base.buildSystemPrompt(settings) + protocolText(tools, maxRounds);
|
|
141
|
+
const history = (p.history || []).slice(-24);
|
|
142
|
+
const mask = (text) => (agentCfg.maskSensitive === false ? String(text) : base.maskSensitive(String(text)));
|
|
143
|
+
const question = mask(p.text || '');
|
|
144
|
+
|
|
145
|
+
const trace = [];
|
|
146
|
+
const pending = [];
|
|
147
|
+
const transcript = [];
|
|
148
|
+
let round = 0;
|
|
149
|
+
let finalText = '';
|
|
150
|
+
let usage = null;
|
|
151
|
+
let lastModel = null;
|
|
152
|
+
|
|
153
|
+
while (round < maxRounds) {
|
|
154
|
+
round += 1;
|
|
155
|
+
emit({ type: 'round', round });
|
|
156
|
+
|
|
157
|
+
let result;
|
|
158
|
+
try {
|
|
159
|
+
result = await llm.complete({
|
|
160
|
+
system,
|
|
161
|
+
user: buildUserMessage({ question, history, transcript }),
|
|
162
|
+
maxTokens: 3200,
|
|
163
|
+
signal: p.signal,
|
|
164
|
+
});
|
|
165
|
+
} catch (err) {
|
|
166
|
+
emit({ type: 'error', message: err.message, round });
|
|
167
|
+
return { ok: false, error: err.message, rounds: round, trace, pending };
|
|
168
|
+
}
|
|
169
|
+
lastModel = result.model;
|
|
170
|
+
if (result.usage) usage = result.usage;
|
|
171
|
+
|
|
172
|
+
const action = parseAction(result.text);
|
|
173
|
+
if (action.thought) {
|
|
174
|
+
emit({ type: 'reasoning', text: action.thought });
|
|
175
|
+
emit({ type: 'reasoning_done', length: action.thought.length });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!action.tool) {
|
|
179
|
+
finalText = action.final || '(模型没有返回内容)';
|
|
180
|
+
emit({ type: 'content', text: finalText });
|
|
181
|
+
emit({ type: 'done', content: finalText, rounds: round, trace, pending, model: lastModel });
|
|
182
|
+
return { ok: true, content: finalText, trace, pending, rounds: round, model: lastModel, usage };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const tool = byName.get(action.tool);
|
|
186
|
+
const callId = 'tc-' + Date.now().toString(36) + '-' + round;
|
|
187
|
+
if (!tool) {
|
|
188
|
+
const summary = '✖ 工具不存在:' + action.tool;
|
|
189
|
+
emit({ type: 'tool_call', id: callId, name: action.tool, label: action.tool, plugin: '未知', args: action.args });
|
|
190
|
+
emit({ type: 'tool_result', id: callId, name: action.tool, label: action.tool, plugin: '未知', ok: false, summary, ms: 0, result: { ok: false, error: summary } });
|
|
191
|
+
transcript.push({ name: action.tool, args: action.args, resultText: JSON.stringify({ ok: false, error: '工具不存在,请从清单中选择' }) });
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
emit({ type: 'tool_call', id: callId, name: tool.name, label: tool.label, plugin: tool.plugin, args: action.args, write: tool.write, confirm: tool.confirm });
|
|
196
|
+
|
|
197
|
+
// 护栏:三类动作挂起,等人工确认
|
|
198
|
+
if (registry.needsConfirm(tool.name, agentCfg.confirmActions)) {
|
|
199
|
+
const item = {
|
|
200
|
+
id: 'PA-' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6),
|
|
201
|
+
tool: tool.name, label: tool.label, plugin: tool.plugin, args: action.args,
|
|
202
|
+
sessionId: p.sessionId, createdAt: new Date().toISOString(), status: 'pending',
|
|
203
|
+
};
|
|
204
|
+
store.col('pendingActions').insert(item);
|
|
205
|
+
pending.push(item);
|
|
206
|
+
emit({ type: 'confirm_required', id: item.id, name: tool.name, label: tool.label, plugin: tool.plugin, args: action.args });
|
|
207
|
+
const pendingPayload = { ok: true, status: '已挂起等待人工确认', 待确认编号: item.id, 说明: CONFIRM_HINT };
|
|
208
|
+
emit({ type: 'tool_result', id: callId, name: tool.name, label: tool.label, plugin: tool.plugin, ok: true, summary: '⏸ 已挂起待人工确认', ms: 0, result: pendingPayload });
|
|
209
|
+
transcript.push({ name: tool.name, args: action.args, resultText: JSON.stringify(pendingPayload) });
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const started = Date.now();
|
|
214
|
+
let output;
|
|
215
|
+
try {
|
|
216
|
+
output = await tool.run(action.args || {}, { outputDir: p.outputDir });
|
|
217
|
+
} catch (err) {
|
|
218
|
+
output = { ok: false, error: '工具执行异常:' + err.message };
|
|
219
|
+
}
|
|
220
|
+
if (output && typeof output.then === 'function') output = await output;
|
|
221
|
+
const ms = Date.now() - started;
|
|
222
|
+
const ok = !(output && output.ok === false);
|
|
223
|
+
const summary = base.summarize(tool.name, output);
|
|
224
|
+
|
|
225
|
+
trace.push({ name: tool.name, label: tool.label, plugin: tool.plugin, args: action.args, summary, ms, ok });
|
|
226
|
+
try {
|
|
227
|
+
store.audit({
|
|
228
|
+
user: '当前用户', plugin: tool.plugin, action: tool.label,
|
|
229
|
+
params: action.args, resultSummary: summary, purpose: '智能体调用(Harness 内置 DeepSeek)',
|
|
230
|
+
});
|
|
231
|
+
} catch (_) { /* 审计失败不影响主流程 */ }
|
|
232
|
+
|
|
233
|
+
emit({ type: 'tool_result', id: callId, name: tool.name, label: tool.label, plugin: tool.plugin, ok, summary, ms, result: output });
|
|
234
|
+
transcript.push({ name: tool.name, args: action.args, resultText: JSON.stringify(output) });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const tail = '\n\n(已达到最大工具调用轮次 ' + maxRounds + ',如需继续请分步提问。)';
|
|
238
|
+
finalText += tail;
|
|
239
|
+
emit({ type: 'content', text: tail });
|
|
240
|
+
emit({ type: 'done', content: finalText, rounds: round, trace, pending, truncated: true, model: lastModel });
|
|
241
|
+
return { ok: true, content: finalText, trace, pending, rounds: round, truncated: true, model: lastModel, usage };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
module.exports = {
|
|
245
|
+
run,
|
|
246
|
+
setRuntime,
|
|
247
|
+
runtime,
|
|
248
|
+
morningReport: base.morningReport,
|
|
249
|
+
executePending: base.executePending,
|
|
250
|
+
rejectPending: base.rejectPending,
|
|
251
|
+
summarize: base.summarize,
|
|
252
|
+
buildSystemPrompt: base.buildSystemPrompt,
|
|
253
|
+
maskSensitive: base.maskSensitive,
|
|
254
|
+
registry,
|
|
255
|
+
};
|
package/client.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 质量平台插件 —— Client 半
|
|
3
|
+
* ------------------------------------------------------------------
|
|
4
|
+
* 在左侧栏注册一级入口,在主面板注册整页应用。
|
|
5
|
+
* 应用本体是 Host 半在 /qip-real/ 提供的完整 Web 应用(真实 REST + SSE),
|
|
6
|
+
* 这里用同源 iframe 承载:样式/脚本完全隔离,不与 Harness 抢全局,
|
|
7
|
+
* 应用里的 fetch('/qip-real/api/...')、SSE、文件下载都按浏览器同源正常工作。
|
|
8
|
+
*/
|
|
9
|
+
window.__ModuleLoader__.load({
|
|
10
|
+
id: 'qip-real',
|
|
11
|
+
factory: (require) => {
|
|
12
|
+
const React = require('react')
|
|
13
|
+
const h = React.createElement
|
|
14
|
+
const BASE = '/qip-real'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 平台显示名:应用会在启动时把「初始设置」里的公司名称写进 localStorage,
|
|
18
|
+
* 这里同步读取,左侧栏一级入口的标题就跟着公司名称走。
|
|
19
|
+
*/
|
|
20
|
+
const DEFAULT_BRAND = '全质开源质量平台'
|
|
21
|
+
let brandVar = ''
|
|
22
|
+
function brand() {
|
|
23
|
+
if (brandVar) return brandVar
|
|
24
|
+
try {
|
|
25
|
+
const v = window.localStorage && window.localStorage.getItem('qip-real.brand')
|
|
26
|
+
return (v && v.trim()) || DEFAULT_BRAND
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return DEFAULT_BRAND
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const FRAME_STYLE = {
|
|
33
|
+
flex: '1 1 0',
|
|
34
|
+
minHeight: 0,
|
|
35
|
+
width: '100%',
|
|
36
|
+
height: '100%',
|
|
37
|
+
border: '0',
|
|
38
|
+
display: 'block',
|
|
39
|
+
background: '#f2f4f8',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const HOST_STYLE = {
|
|
43
|
+
flex: '1 1 0',
|
|
44
|
+
minHeight: 0,
|
|
45
|
+
display: 'flex',
|
|
46
|
+
flexDirection: 'column',
|
|
47
|
+
overflow: 'hidden',
|
|
48
|
+
background: '#f2f4f8',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function QipPage() {
|
|
52
|
+
return h(
|
|
53
|
+
'div',
|
|
54
|
+
{ style: HOST_STYLE },
|
|
55
|
+
h('iframe', {
|
|
56
|
+
src: BASE + '/?v=' + Date.now(),
|
|
57
|
+
title: brand(),
|
|
58
|
+
style: FRAME_STYLE,
|
|
59
|
+
allow: 'clipboard-write',
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function QipIcon() {
|
|
65
|
+
return h(
|
|
66
|
+
'svg',
|
|
67
|
+
{
|
|
68
|
+
width: 20,
|
|
69
|
+
height: 20,
|
|
70
|
+
viewBox: '0 0 24 24',
|
|
71
|
+
fill: 'none',
|
|
72
|
+
stroke: 'currentColor',
|
|
73
|
+
strokeWidth: 1.8,
|
|
74
|
+
strokeLinecap: 'round',
|
|
75
|
+
strokeLinejoin: 'round',
|
|
76
|
+
'aria-hidden': 'true',
|
|
77
|
+
},
|
|
78
|
+
h('path', { d: 'M12 3 5.5 5.8v5.1c0 4.3 2.7 8 6.5 9.3 3.8-1.3 6.5-5 6.5-9.3V5.8L12 3Z' }),
|
|
79
|
+
h('path', { d: 'm9 12 2.1 2.1L15.5 9.6' }),
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
inject: ['slots'],
|
|
85
|
+
apply(ctx) {
|
|
86
|
+
// 先问一次后端:即便应用页面还没打开过,左侧菜单也能拿到公司名称
|
|
87
|
+
fetch(BASE + '/api/brand')
|
|
88
|
+
.then((r) => r.json())
|
|
89
|
+
.then((d) => {
|
|
90
|
+
if (d && typeof d.brand === 'string' && d.brand.trim()) {
|
|
91
|
+
brandVar = d.brand.trim()
|
|
92
|
+
try { window.localStorage.setItem('qip-real.brand', brandVar) } catch (e) { /* ignore */ }
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
.catch(() => {})
|
|
96
|
+
ctx.slots.inject('main', () =>
|
|
97
|
+
ctx.slots.register({ name: 'main', key: 'qip-real' }, QipPage),
|
|
98
|
+
)
|
|
99
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
100
|
+
ctx.slots.register(
|
|
101
|
+
{
|
|
102
|
+
name: 'sidebar.panellist',
|
|
103
|
+
id: 'qip-real',
|
|
104
|
+
order: 7,
|
|
105
|
+
label: () => brand(),
|
|
106
|
+
},
|
|
107
|
+
QipIcon,
|
|
108
|
+
),
|
|
109
|
+
)
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
|