dsh-total-quality 2.0.55 → 2.0.57
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 +51 -47
- package/LICENSE.md +37 -37
- package/README.en.md +32 -30
- package/README.md +90 -88
- package/agent-host.cjs +277 -277
- package/client.js +199 -92
- package/cordis.patch.yml +5 -5
- package/docs/enterprise-onboarding.md +10 -10
- package/docs/technical-reference.md +223 -223
- package/host.cjs +91 -124
- package/llm-bridge.cjs +234 -234
- package/locale/en.json +5 -5
- package/locale/zh.json +5 -5
- package/package.json +3 -2
- package/public/app.css +3 -0
- package/public/app.js +6 -2
- package/public/index.html +8 -9
- package/public/js/api.js +152 -152
- package/public/js/assistant-history.js +62 -62
- package/public/js/material-library.js +100 -100
- package/public/js/mobile-preview.js +119 -0
- package/public/js/pages-company-knowledge.js +9 -32
- package/public/js/pages-core.js +232 -232
- package/public/js/pages-growth.js +148 -148
- package/public/js/pages-qms.js +1 -1
- package/public/js/pages-qtools.js +410 -410
- package/public/js/pages-thanks.js +71 -71
- package/public/js/plugin-updates.js +53 -0
- package/public/js/quality-workflow.js +205 -205
- package/public/js/survey-dates.js +41 -41
- package/public/js/survey-knowledge.js +301 -301
- package/public/js/tool-wizards.js +621 -621
- package/public/js/ui.js +467 -467
- package/public/js/voice-capture-worklet.js +30 -30
- package/public/js/xiaozhi-voice.js +264 -264
- package/public/js/xiaozhi.js +468 -468
- package/public/platform-help.html +426 -426
- package/public/platform-site/assets/0468a68574112812.css +10703 -10703
- package/public/platform-site/assets/159e086d35adfa1c.css +2094 -2094
- package/public/platform-site/assets/169e3159cade0d9f.css +98 -98
- package/public/platform-site/assets/22b917c4a3d4ae3d.svg +14 -14
- package/public/platform-site/assets/476f9254ccf723e7.css +8265 -8265
- package/public/platform-site/assets/85a0a4fb4416ded9.css +120 -120
- package/public/platform-site/assets/a3b272383226f6d9.svg +135 -135
- package/public/platform-site/assets/fd16dc5f3cc9d97e.svg +104 -104
- package/public/platform-site/assets/qip-favicon.svg +5 -5
- package/public/platform-site/index.html +279 -279
- package/public/platform-site/offline.js +261 -261
- package/public/platform-site/qip-brand.css +566 -566
- package/public/platform-site/qip-module-guides.js +237 -237
- package/public/responsive.css +103 -101
- package/public/vendor/markdown-it-15.0.3.LICENSE +22 -22
- package/public/vendor/markdown-it-15.0.3.umd.min.js +13 -13
- package/public/workbench.css +7 -7
- package/public/xiaozhi.css +292 -292
- package/resources/qms-templates/019ffb58f24ed48d.docx +0 -0
- package/resources/qms-templates/04a69165fc15143a.docx +0 -0
- package/resources/qms-templates/09af69358c989a63.docx +0 -0
- package/resources/qms-templates/0e7ac77844e45311.docx +0 -0
- package/resources/qms-templates/12446a1b5e173c71.docx +0 -0
- package/resources/qms-templates/15ae40f67f9a3efc.docx +0 -0
- package/resources/qms-templates/18a69bbebf2ece7f.docx +0 -0
- package/resources/qms-templates/1978faa989134f02.docx +0 -0
- package/resources/qms-templates/1a30e121de752f7b.docx +0 -0
- package/resources/qms-templates/1b88907969ea7d4c.docx +0 -0
- package/resources/qms-templates/1e92b808722bf90a.docx +0 -0
- package/resources/qms-templates/2091cad340dc0e7f.docx +0 -0
- package/resources/qms-templates/271ae1002c896ed7.docx +0 -0
- package/resources/qms-templates/280ce53e5d3b5fcf.docx +0 -0
- package/resources/qms-templates/28ca8e4ede0adf6d.docx +0 -0
- package/resources/qms-templates/2ac6675f3cb1f993.docx +0 -0
- package/resources/qms-templates/2c3b799389909d8b.docx +0 -0
- package/resources/qms-templates/2c51038ba2cc3264.docx +0 -0
- package/resources/qms-templates/30c888851d16d764.docx +0 -0
- package/resources/qms-templates/3459fc4daaa2743d.docx +0 -0
- package/resources/qms-templates/3751dafc335e0e80.docx +0 -0
- package/resources/qms-templates/38798cd4298cd2db.docx +0 -0
- package/resources/qms-templates/38f551f9d738ab0a.docx +0 -0
- package/resources/qms-templates/3c85a23ea17018b4.docx +0 -0
- package/resources/qms-templates/3cdb7d14caf1b852.docx +0 -0
- package/resources/qms-templates/3f23239bb6b3e1db.docx +0 -0
- package/resources/qms-templates/42a5b9efeeaa8007.docx +0 -0
- package/resources/qms-templates/47352aafe9b8dac1.docx +0 -0
- package/resources/qms-templates/495359b1e3cbb8fe.docx +0 -0
- package/resources/qms-templates/4ca6920464785166.docx +0 -0
- package/resources/qms-templates/4ce862582a7791be.docx +0 -0
- package/resources/qms-templates/54c9a02a10991b9e.docx +0 -0
- package/resources/qms-templates/5aeb8fddf5f3693f.docx +0 -0
- package/resources/qms-templates/5d7e5576b0e73be7.docx +0 -0
- package/resources/qms-templates/5db3a40edac37791.docx +0 -0
- package/resources/qms-templates/5ffa21eb78eb6f77.docx +0 -0
- package/resources/qms-templates/60d0fbcb709b7161.docx +0 -0
- package/resources/qms-templates/63e1d3a166756095.docx +0 -0
- package/resources/qms-templates/65c724c080d32f10.docx +0 -0
- package/resources/qms-templates/674bd7826c6cbac2.docx +0 -0
- package/resources/qms-templates/677e851acca1b879.docx +0 -0
- package/resources/qms-templates/6bf15feb1a0d2a8d.docx +0 -0
- package/resources/qms-templates/6c3889c7d0918db9.docx +0 -0
- package/resources/qms-templates/6c4c349eeb0a96a8.docx +0 -0
- package/resources/qms-templates/6c5befbd33f759c1.docx +0 -0
- package/resources/qms-templates/6df8367901347508.docx +0 -0
- package/resources/qms-templates/71db51997037692b.docx +0 -0
- package/resources/qms-templates/78a8ef8c76510c99.docx +0 -0
- package/resources/qms-templates/8397bfd1c0a1b013.docx +0 -0
- package/resources/qms-templates/84d750cf858b60a1.docx +0 -0
- package/resources/qms-templates/880de58a4b334533.docx +0 -0
- package/resources/qms-templates/88c37d1b87d9b78c.docx +0 -0
- package/resources/qms-templates/88e9cd42f1849462.docx +0 -0
- package/resources/qms-templates/8956597403be35b6.docx +0 -0
- package/resources/qms-templates/94675c810a233e1f.docx +0 -0
- package/resources/qms-templates/94dff59dd7ebec6e.docx +0 -0
- package/resources/qms-templates/9670b9cd02141594.docx +0 -0
- package/resources/qms-templates/98c373ebd7b5163d.docx +0 -0
- package/resources/qms-templates/a4078cf2378a9388.docx +0 -0
- package/resources/qms-templates/a5b110c7ef917139.docx +0 -0
- package/resources/qms-templates/aec75820e45774be.docx +0 -0
- package/resources/qms-templates/b31c085e281d230c.docx +0 -0
- package/resources/qms-templates/b7c1c3c72f8ffeef.docx +0 -0
- package/resources/qms-templates/b81b82eaa5c8f422.docx +0 -0
- package/resources/qms-templates/b92a2fa31f75f137.docx +0 -0
- package/resources/qms-templates/b96c54ae9cfffc54.docx +0 -0
- package/resources/qms-templates/bc47cfd626c010e7.docx +0 -0
- package/resources/qms-templates/be60792734afca69.docx +0 -0
- package/resources/qms-templates/c0018d8ae9ad19e1.docx +0 -0
- package/resources/qms-templates/c171027c964c8be3.docx +0 -0
- package/resources/qms-templates/c4b93d71f5d98b4b.docx +0 -0
- package/resources/qms-templates/c531da29fcb3090f.docx +0 -0
- package/resources/qms-templates/c88eddd43358d015.docx +0 -0
- package/resources/qms-templates/cb978da542f0d892.docx +0 -0
- package/resources/qms-templates/ccde4a94532a8d36.docx +0 -0
- package/resources/qms-templates/cf3fb1e20ae6f24d.docx +0 -0
- package/resources/qms-templates/d231b4982fc8113e.docx +0 -0
- package/resources/qms-templates/d3c55aa5ed14055c.docx +0 -0
- package/resources/qms-templates/db45c44a00a13349.docx +0 -0
- package/resources/qms-templates/db849a41210f54e0.docx +0 -0
- package/resources/qms-templates/dba9ce363d83ddc8.docx +0 -0
- package/resources/qms-templates/dca3ea4c95eb2225.docx +0 -0
- package/resources/qms-templates/dfa4220d2b6b8131.docx +0 -0
- package/resources/qms-templates/dfa51222c777734f.docx +0 -0
- package/resources/qms-templates/e07ea511507e14f5.docx +0 -0
- package/resources/qms-templates/e0a2e00c03458dfa.docx +0 -0
- package/resources/qms-templates/e0e802f46b6764d1.docx +0 -0
- package/resources/qms-templates/e53fc85717f2852b.docx +0 -0
- package/resources/qms-templates/e9dd82d5e54520e5.docx +0 -0
- package/resources/qms-templates/ea7bfc22c06d82a9.docx +0 -0
- package/resources/qms-templates/ecf0db9f37294536.docx +0 -0
- package/resources/qms-templates/f05fcfc87e82ff39.docx +0 -0
- package/resources/qms-templates/fb9e56a17c4a4f97.docx +0 -0
- package/resources/qms-templates/manifest.json +932 -0
- package/src/data/seed-sme.js +317 -317
- package/src/data/seed.js +879 -879
- package/src/lib/backup-identity.js +57 -57
- package/src/lib/chat-answer.js +225 -225
- package/src/lib/chat-context.js +99 -99
- package/src/lib/company-library.js +28 -19
- package/src/lib/data-import.js +217 -217
- package/src/lib/data-sources.js +118 -118
- package/src/lib/demo-data.js +27 -1
- package/src/lib/employee-intake.js +84 -84
- package/src/lib/growth.js +53 -53
- package/src/lib/intake-packets.js +119 -119
- package/src/lib/issue-intake.js +88 -88
- package/src/lib/kb-revision.js +214 -214
- package/src/lib/llm.js +279 -279
- package/src/lib/model-error.js +14 -14
- package/src/lib/privacy.js +26 -26
- package/src/lib/qms-drafting.js +194 -194
- package/src/lib/qms-jobs.js +11 -7
- package/src/lib/qms-manual-review.js +185 -185
- package/src/lib/qms-procedure-review.js +109 -109
- package/src/lib/qms-templates.js +358 -326
- package/src/lib/qms.js +369 -369
- package/src/lib/quality-priority.js +100 -100
- package/src/lib/quality-state.js +92 -92
- package/src/lib/quality-workflow.js +65 -65
- package/src/lib/retrieval.js +159 -159
- package/src/lib/spc.js +127 -127
- package/src/lib/voice-hotwords.txt +22 -22
- package/src/lib/voice-text.js +13 -13
- package/src/lib/voice-worker.js +72 -72
- package/src/lib/voice.js +330 -330
- package/src/lib/workbench-notices.js +49 -49
- package/src/lib/workbench.js +103 -106
- package/src/package.json +3 -3
- package/src/tools/analysis.js +306 -306
- package/src/tools/data.js +596 -596
- package/src/tools/docs.js +430 -430
- package/src/tools/registry.js +57 -57
- package/tools-dsh.cjs +153 -153
- package//345/256/211/350/243/205/350/257/264/346/230/216.md +33 -25
- 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 -17
- package//350/207/252/346/243/200.cjs +88 -88
- package/public/js/remote-knowledge.js +0 -165
- package/public/js/workbench-notices.js +0 -67
- package/public/remote-knowledge-help.html +0 -35
- package/public/remote-knowledge.css +0 -40
- package/src/lib/remote-knowledge.js +0 -284
package/src/lib/chat-context.js
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const timeFrame = /今天|今日|昨天|昨日|昨晚|明天|明日|后天|目前|当前|现在|本周|这周|上周|本月|上月|近[一二三四五六七八九十\d两]+[天日周月]|近[期几]天|近期|最近/;
|
|
4
|
-
const dataRequest = /有.{0,5}(哪些|什么|多少|几[条件个起])|列[一出下]|清单|列表|最该|最值得|要盯|重点|优先|统计|汇总|排名|记录|数据|进度|情况|结果|趋势|怎么回事/;
|
|
5
|
-
const operationalStatus = /高风险|A级|待办|在办|逾期|超期|到期|截止|未关闭|待处理|待确认|在整改|待验收|过程异常|质量风险/;
|
|
6
|
-
const referenceRequest = /知识库|专家资料|专家经验|经验卡|相似案例|历史案例|相似问题|查找.{0,10}(手册|文件|标准|资料)|体系文件|供应商资料|控制程序|作业指导书|质量手册|检验规程|(?:按|根据|依据|对照|参考).{0,18}(制度|文件|标准|规范|程序|手册)|(?:标准|规范|制度|程序文件).{0,12}(要求|规定|条款|内容|原文)|(?:ISO\s?\d+|IATF\s?\d+|\bGB\/T\s?\d+)/i;
|
|
7
|
-
const methods = /(?:抽样|检验|巡检|校验).{0,10}(?:多少|频次|周期|间隔)|验收标准|操作规范|怎么(做|用|判|查|处理|排查)|如何(做|用|判|查询|处理|排查|制定)|方法|步骤|原理|为什么/;
|
|
8
|
-
const narrow = /供应商|来料|研发|试产|车间|工厂|批次|客户投诉|(?:CT|QP|QI|SCAR|RDP|QRQC)-[a-z0-9-]+|明天|明日|后天|本周|这周|下周|昨[天日晚]|(?:未来|接下来|近)[一二三四五六七八九十\d两]+[天日周]|产品[甲乙丙丁A-Z0-9]|只看|仅看|仅列|仅查|按.{0,4}(车间|部门|负责人|客户|产品|批次)|前[一二三四五六七八九十\d]+|[一二三四五六七八九十\d]+[件条项个]|分析原因|根因|为什么/i;
|
|
9
|
-
const priorityBrief = /(?:今天|今日|现在|当前).{0,8}(?:最该|最值得|最要|有什么要盯|最重要|重点关注)|(?:今天|今日).{0,12}(?:需要|应该|该|要).{0,6}(?:优先|关注|处理|注意|盯)/;
|
|
10
|
-
const catalogRequest = /知识库.{0,14}(?:有(?:哪些|什么|多少|几份)(?:.{0,6}(?:文件|文档|资料|目录)|[吗??。]|$)|(?:文件清单|文件列表|目录)(?:[吗??。]|$)|也不知道)|(?:列出|查看|看看|统计).{0,12}知识库.{0,10}(?:文件|文档|资料|目录)|(?:知道|能.{0,3}(?:看到|读取|查到)).{0,10}知识库.{0,10}(?:文件|目录)/;
|
|
11
|
-
|
|
12
|
-
function route(question, history = []) {
|
|
13
|
-
const current = question.normalize('NFKC').trim();
|
|
14
|
-
const lastQuestion = history.findLast((item) => item.role === 'user')?.content;
|
|
15
|
-
const followUp = typeof lastQuestion === 'string' && current.length < 50 &&
|
|
16
|
-
/^(那|这|它|再|刚才|其中|继续|上面)|^(谁负责|什么时候到期|到哪一步|哪条最急)/.test(current);
|
|
17
|
-
const query = followUp ? current + '\n' + lastQuestion.slice(0, 500) : current;
|
|
18
|
-
const explicitReference = referenceRequest.test(current) || (followUp && referenceRequest.test(query));
|
|
19
|
-
const brief = priorityBrief.test(query);
|
|
20
|
-
const lookUpData = brief || (timeFrame.test(query) && (dataRequest.test(query) || operationalStatus.test(query))) ||
|
|
21
|
-
(operationalStatus.test(query) && dataRequest.test(query));
|
|
22
|
-
const documents = explicitReference || (!lookUpData && methods.test(query));
|
|
23
|
-
const ranking = brief || (/(高风险|A级|质量风险)/i.test(current) && /到期|逾期|超期/.test(current) && dataRequest.test(current));
|
|
24
|
-
const priority = lookUpData && ranking && !documents && !narrow.test(current) && !followUp;
|
|
25
|
-
const catalog = catalogRequest.test(current) && !/远程知识库|文件[^。??]{0,12}(?:提到|包含|含有|规定了)/.test(current);
|
|
26
|
-
const companyOnly = /(?:企业|公司)知识库/.test(query) && !/远程知识库|专家资料|供应商资料/.test(current);
|
|
27
|
-
return { documents, liveOnly: lookUpData && !documents, priority, catalog, companyOnly, query };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function resolve(question, history, baseline, {llm,signal,mask}) {
|
|
31
|
-
const current = question.normalize('NFKC').trim();
|
|
32
|
-
if (!llm || !/[\p{L}\p{N}]/u.test(current) ||
|
|
33
|
-
/^(?:你好|您好|在吗|谢谢|hi|hello)[\s\p{P}]*$/iu.test(current)) return baseline;
|
|
34
|
-
const previous = history.findLast(row=>row.role==='user' && typeof row.content==='string')?.content || '';
|
|
35
|
-
let result;
|
|
36
|
-
try {
|
|
37
|
-
result = await llm.complete({
|
|
38
|
-
system:'只识别全质平台用户需要的查询类型,不回答正文,不执行操作。只输出 JSON {"action":"类型","terms":["检索词"]}。' +
|
|
39
|
-
'catalog:想知道公司已有、存档或可查阅的文件、制度、模板、资料有哪些或多少,或询问平台对企业文件的可见性。' +
|
|
40
|
-
'company:想核对本企业一份文件、标准、附件的存在、版本、规定或具体内容。' +
|
|
41
|
-
'references
|
|
42
|
-
'platform:要查平台事项、审批、测量、供应商记录等业务数据,或要求执行平台动作。' +
|
|
43
|
-
'general:一般方法、术语、闲聊或其他不需要查企业资料的问题。无需出现「知识库」等关键词;按句意和必要的上文判断。' +
|
|
44
|
-
'比如「能给我看看厂里已经归档了些什么吗」是 catalog,「咱们收货随机抽几件」是 company,' +
|
|
45
|
-
'「一般怎么制定抽样方案」是 general,「今早车间哪些异常还挂着」是 platform。' +
|
|
46
|
-
'仅 company 或 references 写最多 4 个有区分度的中文检索词,可加入同义叫法,绝不编造编号、型号或文件名。',
|
|
47
|
-
user:mask(JSON.stringify({当前问题:current.slice(0,1600),上一条问题:previous.slice(0,450)})),
|
|
48
|
-
maxTokens:240, reasoning:false,
|
|
49
|
-
signal:AbortSignal.any([signal,AbortSignal.timeout(10000)].filter(Boolean)),
|
|
50
|
-
});
|
|
51
|
-
if (result.finishReason && result.finishReason!=='stop') return baseline;
|
|
52
|
-
const {action,terms} = JSON.parse(String(result.text||'').trim().replace(/^```(?:json)?\s*|\s*```$/g,''));
|
|
53
|
-
if (action==='catalog') return {...baseline,catalog:true,documents:true,liveOnly:false,priority:false};
|
|
54
|
-
if (action==='platform') return {...baseline,catalog:false,documents:false,liveOnly:true};
|
|
55
|
-
if (action==='general') return {...baseline,catalog:false,documents:false,liveOnly:false,priority:false,general:true};
|
|
56
|
-
if (action==='company' || action==='references') {
|
|
57
|
-
const expansion = Array.isArray(terms) ? terms.filter(term=>typeof term==='string' && term.trim() && term.length<=36).slice(0,4) : [];
|
|
58
|
-
return {...baseline,catalog:false,documents:true,liveOnly:false,priority:false,resolvedDocuments:true,
|
|
59
|
-
companyOnly:action==='company' || baseline.companyOnly,query:[baseline.query,...expansion].join(' ')};
|
|
60
|
-
}
|
|
61
|
-
} catch {
|
|
62
|
-
signal?.throwIfAborted();
|
|
63
|
-
}
|
|
64
|
-
return baseline;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const segmenter = new Intl.Segmenter('zh', { granularity: 'word' });
|
|
68
|
-
const generic = /^(今天|今日|昨天|目前|现在|当前|近期|最近|有哪些|哪些|什么|怎么|如何|资料|文件|知识库|专家|经验|专家经验|案例|类似|相似|找找|查找|查询|请问|根据|结合|能否|帮忙|质量|风险|高风险|质量风险|问题|报告|规定|要求|过程|管理|质量管理|业务|工作|事项|优先级|处理|分析|进行|完成|相关|需要|一下|已经|检索|标准|规范|方法|步骤|内容|具体|原文|讲讲|到期|以及|看看|查看|记录|核对|核实|参考|说明|怎样|通常|平台|已有|列出|缺项|即将|优先|值得|注意|的|the|and|what|how)$/i;
|
|
69
|
-
|
|
70
|
-
function knowledgeTerms(query) {
|
|
71
|
-
const text = query.normalize('NFKC').toLowerCase();
|
|
72
|
-
const tokens = [...segmenter.segment(text)].filter((part) => part.isWordLike).map((part) => part.segment);
|
|
73
|
-
const ids = text.match(/\b(?:iatf|iso|gb\/t)\s*\d{3,}(?:[:.-]\d+)*|\b[a-z]{2,}-[a-z0-9]+(?:-[a-z0-9]+)*\b/gi) || [];
|
|
74
|
-
return [...new Set([...ids, ...tokens])].filter((token) => token.length >= 2 && !generic.test(token));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function relevantSources(rows, terms, max = 6) {
|
|
78
|
-
const compact = (text) => String(text || '').normalize('NFKC').toLowerCase().replace(/\s+/g, '');
|
|
79
|
-
const scored = rows.flatMap((row) => {
|
|
80
|
-
const title = compact(row.title);
|
|
81
|
-
const content = title + '\n' + compact(row.excerpt);
|
|
82
|
-
const titleHits = terms.filter((term) => title.includes(compact(term)));
|
|
83
|
-
const contentHits = terms.filter((term) => content.includes(compact(term)));
|
|
84
|
-
// A title can establish a direct match. A lone short term in prose cannot
|
|
85
|
-
// override the rest of a multi-topic query.
|
|
86
|
-
const direct = titleHits.some((term) => term.length >= 3) || (terms.length === 1 && titleHits.length);
|
|
87
|
-
const supported = terms.length > 1 ? contentHits.length >= 2 : contentHits.some((term) => term.length >= 3);
|
|
88
|
-
return terms.length && (direct || supported) ? [{ row, score: titleHits.length * 4 + contentHits.length }] : [];
|
|
89
|
-
}).sort((a, b) => b.score - a.score);
|
|
90
|
-
const seen = new Set();
|
|
91
|
-
return scored.flatMap(({ row }) => {
|
|
92
|
-
const key = row.url || row.cardId || row.title;
|
|
93
|
-
if (seen.has(key)) return [];
|
|
94
|
-
seen.add(key);
|
|
95
|
-
return [row];
|
|
96
|
-
}).slice(0, max);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
module.exports = { route, resolve, knowledgeTerms, relevantSources };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const timeFrame = /今天|今日|昨天|昨日|昨晚|明天|明日|后天|目前|当前|现在|本周|这周|上周|本月|上月|近[一二三四五六七八九十\d两]+[天日周月]|近[期几]天|近期|最近/;
|
|
4
|
+
const dataRequest = /有.{0,5}(哪些|什么|多少|几[条件个起])|列[一出下]|清单|列表|最该|最值得|要盯|重点|优先|统计|汇总|排名|记录|数据|进度|情况|结果|趋势|怎么回事/;
|
|
5
|
+
const operationalStatus = /高风险|A级|待办|在办|逾期|超期|到期|截止|未关闭|待处理|待确认|在整改|待验收|过程异常|质量风险/;
|
|
6
|
+
const referenceRequest = /知识库|专家资料|专家经验|经验卡|相似案例|历史案例|相似问题|查找.{0,10}(手册|文件|标准|资料)|体系文件|供应商资料|控制程序|作业指导书|质量手册|检验规程|(?:按|根据|依据|对照|参考).{0,18}(制度|文件|标准|规范|程序|手册)|(?:标准|规范|制度|程序文件).{0,12}(要求|规定|条款|内容|原文)|(?:ISO\s?\d+|IATF\s?\d+|\bGB\/T\s?\d+)/i;
|
|
7
|
+
const methods = /(?:抽样|检验|巡检|校验).{0,10}(?:多少|频次|周期|间隔)|验收标准|操作规范|怎么(做|用|判|查|处理|排查)|如何(做|用|判|查询|处理|排查|制定)|方法|步骤|原理|为什么/;
|
|
8
|
+
const narrow = /供应商|来料|研发|试产|车间|工厂|批次|客户投诉|(?:CT|QP|QI|SCAR|RDP|QRQC)-[a-z0-9-]+|明天|明日|后天|本周|这周|下周|昨[天日晚]|(?:未来|接下来|近)[一二三四五六七八九十\d两]+[天日周]|产品[甲乙丙丁A-Z0-9]|只看|仅看|仅列|仅查|按.{0,4}(车间|部门|负责人|客户|产品|批次)|前[一二三四五六七八九十\d]+|[一二三四五六七八九十\d]+[件条项个]|分析原因|根因|为什么/i;
|
|
9
|
+
const priorityBrief = /(?:今天|今日|现在|当前).{0,8}(?:最该|最值得|最要|有什么要盯|最重要|重点关注)|(?:今天|今日).{0,12}(?:需要|应该|该|要).{0,6}(?:优先|关注|处理|注意|盯)/;
|
|
10
|
+
const catalogRequest = /知识库.{0,14}(?:有(?:哪些|什么|多少|几份)(?:.{0,6}(?:文件|文档|资料|目录)|[吗??。]|$)|(?:文件清单|文件列表|目录)(?:[吗??。]|$)|也不知道)|(?:列出|查看|看看|统计).{0,12}知识库.{0,10}(?:文件|文档|资料|目录)|(?:知道|能.{0,3}(?:看到|读取|查到)).{0,10}知识库.{0,10}(?:文件|目录)/;
|
|
11
|
+
|
|
12
|
+
function route(question, history = []) {
|
|
13
|
+
const current = question.normalize('NFKC').trim();
|
|
14
|
+
const lastQuestion = history.findLast((item) => item.role === 'user')?.content;
|
|
15
|
+
const followUp = typeof lastQuestion === 'string' && current.length < 50 &&
|
|
16
|
+
/^(那|这|它|再|刚才|其中|继续|上面)|^(谁负责|什么时候到期|到哪一步|哪条最急)/.test(current);
|
|
17
|
+
const query = followUp ? current + '\n' + lastQuestion.slice(0, 500) : current;
|
|
18
|
+
const explicitReference = referenceRequest.test(current) || (followUp && referenceRequest.test(query));
|
|
19
|
+
const brief = priorityBrief.test(query);
|
|
20
|
+
const lookUpData = brief || (timeFrame.test(query) && (dataRequest.test(query) || operationalStatus.test(query))) ||
|
|
21
|
+
(operationalStatus.test(query) && dataRequest.test(query));
|
|
22
|
+
const documents = explicitReference || (!lookUpData && methods.test(query));
|
|
23
|
+
const ranking = brief || (/(高风险|A级|质量风险)/i.test(current) && /到期|逾期|超期/.test(current) && dataRequest.test(current));
|
|
24
|
+
const priority = lookUpData && ranking && !documents && !narrow.test(current) && !followUp;
|
|
25
|
+
const catalog = catalogRequest.test(current) && !/远程知识库|文件[^。??]{0,12}(?:提到|包含|含有|规定了)/.test(current);
|
|
26
|
+
const companyOnly = /(?:企业|公司)知识库/.test(query) && !/远程知识库|专家资料|供应商资料/.test(current);
|
|
27
|
+
return { documents, liveOnly: lookUpData && !documents, priority, catalog, companyOnly, query };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function resolve(question, history, baseline, {llm,signal,mask}) {
|
|
31
|
+
const current = question.normalize('NFKC').trim();
|
|
32
|
+
if (!llm || !/[\p{L}\p{N}]/u.test(current) ||
|
|
33
|
+
/^(?:你好|您好|在吗|谢谢|hi|hello)[\s\p{P}]*$/iu.test(current)) return baseline;
|
|
34
|
+
const previous = history.findLast(row=>row.role==='user' && typeof row.content==='string')?.content || '';
|
|
35
|
+
let result;
|
|
36
|
+
try {
|
|
37
|
+
result = await llm.complete({
|
|
38
|
+
system:'只识别全质平台用户需要的查询类型,不回答正文,不执行操作。只输出 JSON {"action":"类型","terms":["检索词"]}。' +
|
|
39
|
+
'catalog:想知道公司已有、存档或可查阅的文件、制度、模板、资料有哪些或多少,或询问平台对企业文件的可见性。' +
|
|
40
|
+
'company:想核对本企业一份文件、标准、附件的存在、版本、规定或具体内容。' +
|
|
41
|
+
'references:明确需要专家、供应商资料或相似案例作为依据。' +
|
|
42
|
+
'platform:要查平台事项、审批、测量、供应商记录等业务数据,或要求执行平台动作。' +
|
|
43
|
+
'general:一般方法、术语、闲聊或其他不需要查企业资料的问题。无需出现「知识库」等关键词;按句意和必要的上文判断。' +
|
|
44
|
+
'比如「能给我看看厂里已经归档了些什么吗」是 catalog,「咱们收货随机抽几件」是 company,' +
|
|
45
|
+
'「一般怎么制定抽样方案」是 general,「今早车间哪些异常还挂着」是 platform。' +
|
|
46
|
+
'仅 company 或 references 写最多 4 个有区分度的中文检索词,可加入同义叫法,绝不编造编号、型号或文件名。',
|
|
47
|
+
user:mask(JSON.stringify({当前问题:current.slice(0,1600),上一条问题:previous.slice(0,450)})),
|
|
48
|
+
maxTokens:240, reasoning:false,
|
|
49
|
+
signal:AbortSignal.any([signal,AbortSignal.timeout(10000)].filter(Boolean)),
|
|
50
|
+
});
|
|
51
|
+
if (result.finishReason && result.finishReason!=='stop') return baseline;
|
|
52
|
+
const {action,terms} = JSON.parse(String(result.text||'').trim().replace(/^```(?:json)?\s*|\s*```$/g,''));
|
|
53
|
+
if (action==='catalog') return {...baseline,catalog:true,documents:true,liveOnly:false,priority:false};
|
|
54
|
+
if (action==='platform') return {...baseline,catalog:false,documents:false,liveOnly:true};
|
|
55
|
+
if (action==='general') return {...baseline,catalog:false,documents:false,liveOnly:false,priority:false,general:true};
|
|
56
|
+
if (action==='company' || action==='references') {
|
|
57
|
+
const expansion = Array.isArray(terms) ? terms.filter(term=>typeof term==='string' && term.trim() && term.length<=36).slice(0,4) : [];
|
|
58
|
+
return {...baseline,catalog:false,documents:true,liveOnly:false,priority:false,resolvedDocuments:true,
|
|
59
|
+
companyOnly:action==='company' || baseline.companyOnly,query:[baseline.query,...expansion].join(' ')};
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
signal?.throwIfAborted();
|
|
63
|
+
}
|
|
64
|
+
return baseline;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const segmenter = new Intl.Segmenter('zh', { granularity: 'word' });
|
|
68
|
+
const generic = /^(今天|今日|昨天|目前|现在|当前|近期|最近|有哪些|哪些|什么|怎么|如何|资料|文件|知识库|专家|经验|专家经验|案例|类似|相似|找找|查找|查询|请问|根据|结合|能否|帮忙|质量|风险|高风险|质量风险|问题|报告|规定|要求|过程|管理|质量管理|业务|工作|事项|优先级|处理|分析|进行|完成|相关|需要|一下|已经|检索|标准|规范|方法|步骤|内容|具体|原文|讲讲|到期|以及|看看|查看|记录|核对|核实|参考|说明|怎样|通常|平台|已有|列出|缺项|即将|优先|值得|注意|的|the|and|what|how)$/i;
|
|
69
|
+
|
|
70
|
+
function knowledgeTerms(query) {
|
|
71
|
+
const text = query.normalize('NFKC').toLowerCase();
|
|
72
|
+
const tokens = [...segmenter.segment(text)].filter((part) => part.isWordLike).map((part) => part.segment);
|
|
73
|
+
const ids = text.match(/\b(?:iatf|iso|gb\/t)\s*\d{3,}(?:[:.-]\d+)*|\b[a-z]{2,}-[a-z0-9]+(?:-[a-z0-9]+)*\b/gi) || [];
|
|
74
|
+
return [...new Set([...ids, ...tokens])].filter((token) => token.length >= 2 && !generic.test(token));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function relevantSources(rows, terms, max = 6) {
|
|
78
|
+
const compact = (text) => String(text || '').normalize('NFKC').toLowerCase().replace(/\s+/g, '');
|
|
79
|
+
const scored = rows.flatMap((row) => {
|
|
80
|
+
const title = compact(row.title);
|
|
81
|
+
const content = title + '\n' + compact(row.excerpt);
|
|
82
|
+
const titleHits = terms.filter((term) => title.includes(compact(term)));
|
|
83
|
+
const contentHits = terms.filter((term) => content.includes(compact(term)));
|
|
84
|
+
// A title can establish a direct match. A lone short term in prose cannot
|
|
85
|
+
// override the rest of a multi-topic query.
|
|
86
|
+
const direct = titleHits.some((term) => term.length >= 3) || (terms.length === 1 && titleHits.length);
|
|
87
|
+
const supported = terms.length > 1 ? contentHits.length >= 2 : contentHits.some((term) => term.length >= 3);
|
|
88
|
+
return terms.length && (direct || supported) ? [{ row, score: titleHits.length * 4 + contentHits.length }] : [];
|
|
89
|
+
}).sort((a, b) => b.score - a.score);
|
|
90
|
+
const seen = new Set();
|
|
91
|
+
return scored.flatMap(({ row }) => {
|
|
92
|
+
const key = row.url || row.cardId || row.title;
|
|
93
|
+
if (seen.has(key)) return [];
|
|
94
|
+
seen.add(key);
|
|
95
|
+
return [row];
|
|
96
|
+
}).slice(0, max);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = { route, resolve, knowledgeTerms, relevantSources };
|
|
@@ -14,7 +14,9 @@ const expertScope = (slug) => 'expert:' + slug;
|
|
|
14
14
|
const versionColumns = ['documentNumber', 'revision', 'effectiveFrom', 'product', 'process', 'supersedes', 'revisionState'];
|
|
15
15
|
const fileFields = 'id,folderId,name,size,sha,createdAt,indexStatus,chunkCount,legacyOriginal,' + versionColumns.join(',');
|
|
16
16
|
const today = () => new Date().toLocaleDateString('en-CA');
|
|
17
|
-
const
|
|
17
|
+
const companyVisible = `NOT (d.legacyOriginal=1 AND d.legacySource<>'' AND d.revisionState='uncontrolled'
|
|
18
|
+
AND d.sha IN (SELECT sha FROM hidden_platform_templates))`;
|
|
19
|
+
const effective = `(d.purgedAt='' AND ${companyVisible} AND ((d.revisionState='uncontrolled' AND NOT EXISTS (
|
|
18
20
|
SELECT 1 FROM documents newer WHERE newer.supersedes=d.id AND
|
|
19
21
|
newer.revisionState IN ('released','withdrawn') AND newer.effectiveFrom<=?
|
|
20
22
|
)) OR
|
|
@@ -69,7 +71,7 @@ function validateName(value, max) {
|
|
|
69
71
|
return name;
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
function open(root) {
|
|
74
|
+
function open(root, { hiddenTemplateDigests = [] } = {}) {
|
|
73
75
|
const originals = path.join(root, 'enterprise-knowledge-files');
|
|
74
76
|
fs.mkdirSync(originals, { recursive: true });
|
|
75
77
|
const db = new DatabaseSync(path.join(root, 'enterprise-knowledge.db'));
|
|
@@ -172,8 +174,12 @@ function open(root) {
|
|
|
172
174
|
db.exec('CREATE INDEX IF NOT EXISTS document_versions ON documents(documentNumber,product,process,effectiveFrom)');
|
|
173
175
|
db.exec('CREATE INDEX IF NOT EXISTS document_replacements ON documents(supersedes,effectiveFrom)');
|
|
174
176
|
});
|
|
177
|
+
db.exec('CREATE TEMP TABLE hidden_platform_templates (sha TEXT PRIMARY KEY)');
|
|
178
|
+
const hideTemplate = db.prepare('INSERT INTO hidden_platform_templates VALUES (?)');
|
|
179
|
+
for (const digest of hiddenTemplateDigests) hideTemplate.run(digest);
|
|
175
180
|
const stored = (id, suffix = '.original') => path.join(originals, id + suffix);
|
|
176
181
|
const row = db.prepare('SELECT ' + fileFields + ',purgedAt FROM documents WHERE id=?');
|
|
182
|
+
const hiddenTemplate = db.prepare('SELECT 1 FROM documents d WHERE id=? AND NOT ' + companyVisible);
|
|
177
183
|
const active = db.prepare('SELECT ' + fileFields + ' FROM documents d WHERE id=? AND ' + effective);
|
|
178
184
|
const previewRow = db.prepare('SELECT * FROM revision_previews WHERE id=? AND owner=?');
|
|
179
185
|
const remove = (filename) => {
|
|
@@ -614,21 +620,28 @@ function open(root) {
|
|
|
614
620
|
return {
|
|
615
621
|
searchableCount() {
|
|
616
622
|
return db.prepare(`SELECT count(*) AS count FROM documents d JOIN folders f ON f.id=d.folderId
|
|
617
|
-
WHERE
|
|
623
|
+
WHERE f.scope='company' AND d.chunkCount>0 AND ${effective}`)
|
|
618
624
|
.get(today(), today(), today()).count;
|
|
619
625
|
},
|
|
620
|
-
list() {
|
|
621
|
-
const folders = db.prepare('SELECT id,parentId,name,scope,pinned FROM folders ORDER BY position, name COLLATE NOCASE').all()
|
|
626
|
+
list(scope) {
|
|
627
|
+
const folders = db.prepare('SELECT id,parentId,name,scope,pinned FROM folders ORDER BY position, name COLLATE NOCASE').all()
|
|
628
|
+
.filter(folder => !scope || folder.scope===scope);
|
|
629
|
+
const ids = new Set(folders.map(folder=>folder.id));
|
|
622
630
|
const files = db.prepare('SELECT ' + fileFields + ', ' + effective + ' AS effective, ' +
|
|
623
|
-
'(SELECT state FROM matter_intake WHERE documentId=d.id) AS matterState FROM documents d WHERE purgedAt=\'\'
|
|
631
|
+
'(SELECT state FROM matter_intake WHERE documentId=d.id) AS matterState FROM documents d WHERE purgedAt=\'\' AND ' +
|
|
632
|
+
companyVisible + ' ORDER BY createdAt DESC,rowid DESC').all(today(), today(), today())
|
|
633
|
+
.filter(file=>ids.has(file.folderId));
|
|
624
634
|
return { folders, files };
|
|
625
635
|
},
|
|
636
|
+
requireCompanyFolder(id) {
|
|
637
|
+
if (folder(id).scope!=='company') fail(404, '目录不存在,请刷新后重试');
|
|
638
|
+
},
|
|
626
639
|
saveFolder, removeFolder, upload, removeDocument, setVersion, search, passages, documentText,
|
|
627
640
|
remoteDocuments,remoteDocument,remoteSearch,
|
|
628
641
|
revisionSource, createRevisionPreview, revisionPreview, rejectRevision, excessRevisions, pruneRevisions,migrateRevisionOwners,
|
|
629
|
-
document(id) {
|
|
642
|
+
document(id, scope) {
|
|
630
643
|
const found = row.get(id);
|
|
631
|
-
if (!found) fail(404, '文件不存在');
|
|
644
|
+
if (!found || hiddenTemplate.get(id) || scope && folder(found.folderId).scope!==scope) fail(404, '文件不存在');
|
|
632
645
|
if (found.purgedAt) fail(410, '旧版已按保留规则清理');
|
|
633
646
|
return { ...found, filename: stored(id) };
|
|
634
647
|
},
|
|
@@ -733,32 +746,28 @@ async function answer(library, llm, input, signal, progress = {}) {
|
|
|
733
746
|
const followUp = /^(?:那|那么|这个|这种|刚才|上面|它|继续|展开|再说|进一步|具体呢|举个例)/.test(question);
|
|
734
747
|
const query = followUp && priorQuestions.length ? question + '\n' + priorQuestions.at(-1) : question;
|
|
735
748
|
const hits = casual ? [] : library.search(query, scope);
|
|
736
|
-
const sources = hits.map(({ id, name, folderId, folderName, text, part, documentNumber, revision, effectiveFrom, scope: origin }, index) => ({
|
|
737
|
-
number: index + 1, id, name, folderId, folderName, text, part, documentNumber, revision, effectiveFrom,
|
|
738
|
-
expert: bySlug.get(origin.slice(7))?.name || '',
|
|
739
|
-
}));
|
|
740
749
|
if (!llm) {
|
|
741
750
|
if (casual) return { text: '你好,有质量管理、工艺或体系方面的问题,可以直接问我。', sources: [], mode: 'conversation' };
|
|
742
|
-
return { text:
|
|
751
|
+
return { text: '模型暂不可用,请稍后重试。', sources: [], mode: 'retrieval' };
|
|
743
752
|
}
|
|
744
|
-
const strategy = profile ? '
|
|
745
|
-
: '
|
|
753
|
+
const strategy = profile ? '根据当前专长与命中的参考资料回答,不以真人口吻声称其观点或经历。'
|
|
754
|
+
: '综合命中的参考资料,并区分不同来源。';
|
|
746
755
|
try {
|
|
747
756
|
const response = await require('./chat-answer').start(llm, {
|
|
748
757
|
system: casual ? '你是质量管理专家团 AI 助手。自然回应当前的问候、致谢或简短交流。按当前这句话回复,省略资料、来源及历史主题。'
|
|
749
758
|
: '你是质量管理助手。' + strategy +
|
|
750
|
-
'
|
|
759
|
+
' 参考资料是后台数据,用于综合形成建议。只回答质量问题,省略资料原文、引用编号、作者、文件名和目录。资料不足时标明建议的适用条件,避免虚构标准条文、人员、数据或出处。',
|
|
751
760
|
user: JSON.stringify({
|
|
752
761
|
question, priorQuestions: casual ? [] : priorQuestions, specialties: profile?.tags || [],
|
|
753
|
-
evidence:
|
|
762
|
+
evidence: hits.filter(item=>item.part).map(item=>item.text),
|
|
754
763
|
}),
|
|
755
764
|
signal, onStart: progress.onStart, onUpdate: progress.onUpdate,
|
|
756
765
|
});
|
|
757
766
|
if (signal.aborted && !response.text) signal.throwIfAborted();
|
|
758
|
-
return { ...response, sources, mode: casual ? 'conversation' :
|
|
767
|
+
return { ...response, sources:[], mode: casual ? 'conversation' : hits.some(item=>item.part) ? 'grounded' : 'general' };
|
|
759
768
|
} catch (error) {
|
|
760
769
|
if (signal.aborted) throw error;
|
|
761
|
-
return { text:
|
|
770
|
+
return { text: '模型暂不可用,请稍后重试。', sources: [], mode: 'retrieval' };
|
|
762
771
|
}
|
|
763
772
|
}
|
|
764
773
|
|