dsh-data-cleaning-agent 0.8.16 → 0.8.17
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/CHANGELOG.md +9 -0
- package/README.en.md +1 -1
- package/README.md +3 -3
- package/docs/RELEASE-0.8.17.md +26 -0
- package/lib/client.js +184 -49
- package/lib/qcc-command.js +25 -6
- package/lib/skill-enrich.js +3 -1
- package/lib/web.js +6 -2
- package/lib/workflow-contract.js +1 -1
- package/lib/workflow-execution.js +74 -0
- package/lib/workflow.js +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.8.17] - 2026-09-08
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- 提示词向导和工作台统一生成 Host 执行凭证;发送已确认范围后不再重复询问额度、源文件路径或写回确认。
|
|
11
|
+
- Host 在高层工具内完成工作流与新 XLSX/异常清单交付,不依赖对话模型编写脚本或页面持续轮询;原始文件不覆盖。
|
|
12
|
+
- 独立清洗会话切换、刷新可恢复业务归属;侧栏入口重开当前工作台,保存任务绑定以访问下载。持久化绑定仅包含会话 ID 与任务 ID。
|
|
13
|
+
- 版本冲突阻止旧说明再次查询,命令重放幂等;候选歧义仍需人工选择,部分失败提供下载并允许显式重试。
|
|
14
|
+
- 修复后台刷新覆盖任务历史导航,并覆盖 DSH root/session 分离实例的事件交接。
|
|
15
|
+
|
|
7
16
|
## [0.8.16] - 2026-09-08
|
|
8
17
|
|
|
9
18
|
### Changed
|
package/README.en.md
CHANGED
|
@@ -8,7 +8,7 @@ Related agents: [数据清洗补全](https://github.com/duhu2000/dsh-data-cleani
|
|
|
8
8
|
|
|
9
9
|
> A data cleaning & completion agent plugin for DeepSeek Harness: local CSV/XLSX/JSON engine plus optional Qichacha (QCC) MCP enterprise-data enrichment. Initiated and maintained by the Qichacha (QCC) team.
|
|
10
10
|
>
|
|
11
|
-
> Current source version / 当前源码版本: **0.8.
|
|
11
|
+
> Current source version / 当前源码版本: **0.8.17** (stable release)
|
|
12
12
|
|
|
13
13
|
This release unifies spreadsheet previews, column mapping, and enrichment scope across the prompt wizard and workbench. Mapping statuses use color and text; mapped fields automatically enter the scope, with optional extra fields collapsed. Multiple confirmed output columns may share a non-identity field while preserving non-empty values. It fixes saved drafts resetting the scope to five defaults and detects stale Host versions. Preparing a draft does not query QCC; sending starts execution. Fully restart DSH after upgrading. Existing download artifacts are not rewritten.
|
|
14
14
|
|
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# dsh-data-cleaning-agent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
本版统一向导与工作台的 Host 执行闭环:发送后自动生成新 Excel,原文件不修改,工作台入口可恢复;发布记录见 [发布说明](docs/RELEASE-0.8.17.md)。
|
|
4
4
|
|
|
5
5
|
## 安装与三分钟上手
|
|
6
6
|
|
|
7
7
|
数据清洗补全智能体:面向 Excel/CSV/JSON 企业名单,提供数据清洗、表格清洗、清洗补全、去重、企业数据补全与字段补全,支持企查查 MCP 和结果导出。
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
dsh plugin --profile web add dsh-data-cleaning-agent@0.8.
|
|
10
|
+
dsh plugin --profile web add dsh-data-cleaning-agent@0.8.17
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
请先满足下文的 DSH、连接器及侧边栏依赖要求;安装后完整停止并重启对应 Profile。
|
|
@@ -25,7 +25,7 @@ dsh plugin --profile web add dsh-data-cleaning-agent@0.8.16
|
|
|
25
25
|
|
|
26
26
|
> 在 DeepSeek Harness 中清洗、补全、画像企业名单数据的智能体插件:本地 CSV/XLSX/JSON 引擎 + 可选企查查(Qichacha/QCC)MCP 企业数据补全,由企查查(Qichacha/QCC)团队发起并维护。
|
|
27
27
|
>
|
|
28
|
-
> 当前源码版本 / Current source version: **0.8.
|
|
28
|
+
> 当前源码版本 / Current source version: **0.8.17**(正式版本)
|
|
29
29
|
|
|
30
30
|
本版上传表格后展示完整清单及空白数量,用绿色、琥珀色、红色及文字区分已通过、待确认和未匹配映射。已映射字段自动纳入补全范围,额外字段默认折叠;多个原列可经确认使用同一非主体字段,分别补空并保留非空原值。修复 Host 草稿重置为默认五字段的问题,增加前后端版本错配提示。生成说明不查询,发送才执行;升级后需完整重启 DSH,历史下载文件不自动改写。
|
|
31
31
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# dsh-data-cleaning-agent v0.8.17
|
|
2
|
+
|
|
3
|
+
## 本版改进
|
|
4
|
+
|
|
5
|
+
发送在向导或右侧工作台确认的任务说明后,由同一个 Host 高层工具负责匹配、补全、生成新的 XLSX 与异常清单,并将下载绑定到任务。无需再次确认额度或提供源文件路径;不覆盖上传的原始文件,不由模型运行 Bash 拼装替代报表。
|
|
6
|
+
|
|
7
|
+
- 保留已确认原列、多列共用补全字段、仅补空白及非空 0/false 保护。
|
|
8
|
+
- 真正的多候选在工作台确认;授权、限流等异常不自动重试或扩大范围。
|
|
9
|
+
- 过期任务 revision 在查询前阻断;同一命令重放不重复扣量。
|
|
10
|
+
- 刷新与切换后恢复独立清洗会话;侧栏重新打开当前工作台。Host 生成文件不依赖页面存在,已保存结果可跨 Host 重启下载。
|
|
11
|
+
- 只在浏览器保存会话 ID → 任务 ID 绑定,不持久化原始名单。执行中的 Host 进程不可强制重启;尚未生成的命令、候选与运行明细仍可能过期,不能自动重新查询。
|
|
12
|
+
- 未选外部字段时不发起 QCC 调用,可使用工作台本地清洗与导出。
|
|
13
|
+
|
|
14
|
+
## 验证
|
|
15
|
+
|
|
16
|
+
241 项自动化测试、10 组浏览器回归通过。使用合成数据和隔离的 ToolRuntime/Chromium,不调用真实企查查账号、不修改客户测试文件。覆盖真实 XLSX 内容回读、双列补空、原值保护、重放幂等、候选续跑、部分失败重试、磁盘写入失败及恢复下载。浏览器覆盖浅色/深色与五种视口,分离 root/session 实例验证向导凭证交接。
|
|
17
|
+
|
|
18
|
+
## 升级
|
|
19
|
+
|
|
20
|
+
保存未完成任务后安装:
|
|
21
|
+
|
|
22
|
+
`dsh plugin --profile web add dsh-data-cleaning-agent@0.8.17`
|
|
23
|
+
|
|
24
|
+
完整重启对应 DSH Profile 并刷新页面;仅刷新浏览器不会更新 Host。旧对话中的普通提示词不会自动改成新凭证,请在升级后的工作台重新生成。历史导出不会被改写。本次发布不自动重启或安装到本机正在运行的 DSH。
|
|
25
|
+
|
|
26
|
+
回滚可安装 0.8.16,但会失去本版 Host 自动交付与会话恢复逻辑。共享字段内核、AI 填表版本均不变。
|
package/lib/client.js
CHANGED
|
@@ -1231,10 +1231,27 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
1231
1231
|
];
|
|
1232
1232
|
const CLEANING_SESSION_EVENT = 'dsh:data-cleaning-session-ownership';
|
|
1233
1233
|
let activeCleaningSessionId = null;
|
|
1234
|
+
const TASK_BINDINGS_KEY = 'dsh.data-cleaning-agent.task-bindings.v1';
|
|
1235
|
+
const ownedSessionId = (id) => /^session-dsh-data-cleaning-agent-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(id || ''));
|
|
1236
|
+
function readTaskBindings() {
|
|
1237
|
+
try {
|
|
1238
|
+
const value = JSON.parse(window.localStorage?.getItem(TASK_BINDINGS_KEY) || '{}');
|
|
1239
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
1240
|
+
} catch { return {}; }
|
|
1241
|
+
}
|
|
1242
|
+
function bindTask(sessionId, taskId) {
|
|
1243
|
+
if (!ownedSessionId(sessionId)) return;
|
|
1244
|
+
try {
|
|
1245
|
+
const bindings = readTaskBindings();
|
|
1246
|
+
delete bindings[sessionId];
|
|
1247
|
+
bindings[sessionId] = taskId;
|
|
1248
|
+
window.localStorage?.setItem(TASK_BINDINGS_KEY, JSON.stringify(Object.fromEntries(Object.entries(bindings).slice(-200))));
|
|
1249
|
+
} catch {}
|
|
1250
|
+
}
|
|
1234
1251
|
|
|
1235
1252
|
try {
|
|
1236
1253
|
// 旧版本持久化过 sessionId;但 DSH 会复用空白新会话,无法仅凭 ID 判断入口来源。
|
|
1237
|
-
//
|
|
1254
|
+
// 清除旧的无前缀归属标记;新的独立会话前缀可安全恢复,不认领其它智能体会话。
|
|
1238
1255
|
for (const key of CLEANING_SESSION_STORAGE_KEYS) window.sessionStorage?.removeItem(key);
|
|
1239
1256
|
} catch (_error) {
|
|
1240
1257
|
// sessionStorage 可能被禁用;内存态不受影响。
|
|
@@ -1331,10 +1348,12 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
1331
1348
|
};
|
|
1332
1349
|
const leaveSubsystem = () => {
|
|
1333
1350
|
const sessionId = activeCleaningSessionId;
|
|
1334
|
-
if (sessionId) clearCleaningDraft(ctx, sessionId, true);
|
|
1351
|
+
if (sessionId && !ownedSessionId(sessionId)) clearCleaningDraft(ctx, sessionId, true);
|
|
1335
1352
|
deactivateCleaningSession(sessionId);
|
|
1336
1353
|
};
|
|
1337
|
-
//
|
|
1354
|
+
// Only our independently-created native session namespace may regain ownership.
|
|
1355
|
+
const initialSession = ctx.sessions?.list?.getSnapshot?.()?.current;
|
|
1356
|
+
if (ownedSessionId(initialSession)) markCleaningSession(initialSession);
|
|
1338
1357
|
clearStaleDefaultDraft();
|
|
1339
1358
|
// DSH 会在插件 apply() 之后异步恢复 composer draft。在首屏稳定期内
|
|
1340
1359
|
// 监听 DOM 变化并仅清理完全匹配本插件默认文案,或同时命中
|
|
@@ -1359,6 +1378,9 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
1359
1378
|
const nextSessionId = selected.current;
|
|
1360
1379
|
if (activeCleaningSessionId && nextSessionId !== activeCleaningSessionId) {
|
|
1361
1380
|
leaveSubsystem();
|
|
1381
|
+
}
|
|
1382
|
+
if (!activeCleaningSessionId && ownedSessionId(nextSessionId)) {
|
|
1383
|
+
markCleaningSession(nextSessionId);
|
|
1362
1384
|
} else if (!activeCleaningSessionId) {
|
|
1363
1385
|
clearStaleDefaultDraft();
|
|
1364
1386
|
}
|
|
@@ -1408,14 +1430,15 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
1408
1430
|
lines.push(`需要补全的字段 / 维度:${enrichLabels.length ? enrichLabels.join('、') : '不调用外部补全,仅输出本地清洗结果'}。`);
|
|
1409
1431
|
if (mode === 'excel' && config.headers?.length) {
|
|
1410
1432
|
const pairs = config.mappings || [];
|
|
1411
|
-
lines.push(`原表共 ${config.headers.length}
|
|
1433
|
+
lines.push(`原表共 ${config.headers.length} 列。新文件原列补空映射:${pairs.map((item) => `「${item.sourceField}」←${resultFieldLabel(item.targetField)}`).join(';') || '暂无'}。`);
|
|
1412
1434
|
const skipped = config.headers.filter((header) => !pairs.some((item) => item.sourceField === header));
|
|
1413
1435
|
if (skipped.length) lines.push(`暂不补全的原列:${skipped.join('、')};保留原值,不猜测或用相近指标替代。`);
|
|
1414
1436
|
const added = (config.enrichmentKeys || []).filter((id) => !pairs.some((item) => item.targetField === id));
|
|
1415
1437
|
lines.push(`仅补已确认原列的空白单元格,保留非空值(含 0)。多个原列可共用一个补全字段,查询按主体与工具去重。额外新增字段:${added.map(resultFieldLabel).join('、') || '无'}。`);
|
|
1416
1438
|
}
|
|
1417
1439
|
lines.push(`处理规则:优先使用${anchorLabels.length ? anchorLabels.join('、') : '企业名称、统一社会信用代码或注册号'}精确匹配;${config.matchRules?.manualReviewAmbiguous === false ? '精确匹配失败时直接输出未匹配记录' : '精确匹配失败时再进入模糊候选,存在多个候选必须暂停并让我确认,不得默认选择第一项'}。`);
|
|
1418
|
-
lines.push('
|
|
1440
|
+
lines.push('发送即确认执行工作台已配置的范围,不再重复确认额度或写回。企查查连接、套餐额度和费用均由当前用户自己的账号承担。缺失或无权限字段请留空并标记原因,不得编造。');
|
|
1441
|
+
lines.push('交付方式:Host 自动生成新的清洗补全结果 XLSX,在工作台下载。不得修改上传源文件,不索要本地路径,不使用 Bash 或另行编写导出脚本。');
|
|
1419
1442
|
lines.push('完成后保留来源原值、标准主体、匹配状态与字段来源,并提供结果和待复核清单的导出。');
|
|
1420
1443
|
return lines.join('\n\n');
|
|
1421
1444
|
}
|
|
@@ -1662,6 +1685,7 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
1662
1685
|
function cacheWorkflowTask(actions, sessionId, task) {
|
|
1663
1686
|
if (!task) return null;
|
|
1664
1687
|
if (sessionId) workflowTaskBySession.set(String(sessionId), task);
|
|
1688
|
+
bindTask(sessionId, task.id);
|
|
1665
1689
|
actions.setWorkflowTask(task);
|
|
1666
1690
|
if (task.title) actions.setTaskTitle(task.title);
|
|
1667
1691
|
if (Array.isArray(task.objectives)) actions.setObjectives(task.objectives);
|
|
@@ -1692,10 +1716,17 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
1692
1716
|
return cacheWorkflowTask(actions, sessionId, response.task);
|
|
1693
1717
|
}
|
|
1694
1718
|
|
|
1695
|
-
async function ensureWorkflowTask(actions, sessionId, draft = {}) {
|
|
1719
|
+
async function ensureWorkflowTask(actions, sessionId, draft = {}, restoreStage = true) {
|
|
1696
1720
|
const key = String(sessionId || 'unassigned');
|
|
1697
1721
|
const cached = workflowTaskBySession.get(key);
|
|
1698
1722
|
if (cached) return cacheWorkflowTask(actions, sessionId, cached);
|
|
1723
|
+
const saved = readTaskBindings()[key];
|
|
1724
|
+
if (ownedSessionId(key) && /^dcw-[a-zA-Z0-9-]+$/.test(saved || '')) {
|
|
1725
|
+
const response = await requestJson(`/data-cleaning/api/workflow/tasks/${encodeURIComponent(saved)}`);
|
|
1726
|
+
const task = cacheWorkflowTask(actions, sessionId, response.task);
|
|
1727
|
+
if (restoreStage) actions.setStep(task.stage || 'upload');
|
|
1728
|
+
return task;
|
|
1729
|
+
}
|
|
1699
1730
|
return createWorkflowTask(actions, sessionId, draft);
|
|
1700
1731
|
}
|
|
1701
1732
|
|
|
@@ -1748,6 +1779,69 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
1748
1779
|
return cacheWorkflowTask(actions, sessionId, response.task);
|
|
1749
1780
|
}
|
|
1750
1781
|
|
|
1782
|
+
async function stageConfirmedWorkflow(actions, sessionId, expected = null) {
|
|
1783
|
+
const host = await requestJson('/data-cleaning/api/g5/capabilities');
|
|
1784
|
+
if (host?.workflowExecutionVersion !== 1) throw new Error('页面与 Host 版本不一致。请保存任务后升级并完整重启 DSH;当前 Host 不支持自动生成结果文件。');
|
|
1785
|
+
let task = await ensureWorkflowTask(actions, sessionId);
|
|
1786
|
+
if (expected) {
|
|
1787
|
+
const sameSet = (a, b) => JSON.stringify([...(a || [])].sort()) === JSON.stringify([...(b || [])].sort());
|
|
1788
|
+
if (!sameSet(task.fieldSelection, expected.enrichmentKeys)
|
|
1789
|
+
|| (expected.mode === 'excel' && (task.source?.fileName !== expected.fileName
|
|
1790
|
+
|| task.source?.rowCount !== expected.entryCount
|
|
1791
|
+
|| JSON.stringify(task.mappings) !== JSON.stringify(expected.mappings)))) {
|
|
1792
|
+
throw new Error('工作台保存的范围与向导不一致,请重试确认;未生成执行凭证。');
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
const runtime = runtimeFor(task.id, false);
|
|
1796
|
+
if (!task.fieldSelection?.length) throw new Error('当前未选择企查查补全字段。请在规则页选择补全字段,或使用工作台本地清洗与结果导出;不会发起企查查调用。');
|
|
1797
|
+
if (!runtime?.rows?.length) throw new Error('Host 名单尚未载入,请先解析数据。');
|
|
1798
|
+
if (task.state === 'uploaded') task = await workflowAction(actions, sessionId, task, 'rules', {
|
|
1799
|
+
objectives: task.objectives, fieldSelection: task.fieldSelection, mappings: task.mappings, matchRules: task.matchRules,
|
|
1800
|
+
});
|
|
1801
|
+
if (task.state === 'rules_confirmed') task = await workflowAction(actions, sessionId, task, 'quality', {
|
|
1802
|
+
summary: qualitySummaryFor(runtime.rows, task.mappings),
|
|
1803
|
+
});
|
|
1804
|
+
const response = await requestJson('/data-cleaning/api/g5/commands', 'POST', {
|
|
1805
|
+
kind: 'enrich', workflowOwned: true, expectedRevision: task.revision, taskId: task.id,
|
|
1806
|
+
rows: runtime.rows, headers: runtime.headers, fieldSelection: task.fieldSelection,
|
|
1807
|
+
});
|
|
1808
|
+
if (!response.command?.commandId || !response.command?.prompt) throw new Error('Host 未返回执行凭证;未发送任务。');
|
|
1809
|
+
return response.command;
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
async function refreshHostedTask(actions, sessionId, taskId, run, navigate = true) {
|
|
1813
|
+
const response = await requestJson(`/data-cleaning/api/workflow/tasks/${encodeURIComponent(taskId)}`);
|
|
1814
|
+
const selectedTask = workflowTaskBySession.get(String(sessionId));
|
|
1815
|
+
if (selectedTask && selectedTask.id !== taskId) return response.task;
|
|
1816
|
+
if (selectedTask && selectedTask.revision > response.task.revision) return selectedTask;
|
|
1817
|
+
workflowTaskBySession.set(String(sessionId), response.task);
|
|
1818
|
+
bindTask(sessionId, taskId);
|
|
1819
|
+
if (isCleaningSession(sessionId)) {
|
|
1820
|
+
if (!run && response.task.qccRunId && ['review_required', 'partial'].includes(response.task.state)) {
|
|
1821
|
+
try { run = await requestJson(`/data-cleaning/api/g5/run/${encodeURIComponent(response.task.qccRunId)}`); }
|
|
1822
|
+
catch { actions.setError('Host 中的候选或重试数据已失效。已有结果仍可下载;重新查询需新建任务,不会自动重复扣量。'); }
|
|
1823
|
+
}
|
|
1824
|
+
if (!isCleaningSession(sessionId) || workflowTaskBySession.get(String(sessionId))?.id !== taskId) return response.task;
|
|
1825
|
+
cacheWorkflowTask(actions, sessionId, response.task);
|
|
1826
|
+
if (run) {
|
|
1827
|
+
actions.setQccRun(run);
|
|
1828
|
+
const runtime = runtimeFor(taskId);
|
|
1829
|
+
runtime.resultRows.qcc = run.rows;
|
|
1830
|
+
if (!runtime.rows.length) { runtime.rows = run.rows; runtime.headers = response.task.source?.headers || run.headers || []; }
|
|
1831
|
+
}
|
|
1832
|
+
if (navigate) actions.setStep(response.task.stage || 'upload');
|
|
1833
|
+
}
|
|
1834
|
+
return response.task;
|
|
1835
|
+
}
|
|
1836
|
+
function watchHostedCommand(actions, sessionId, command) {
|
|
1837
|
+
void waitForQccCommand(command.commandId, 1800).then(async (completed) => {
|
|
1838
|
+
await refreshHostedTask(actions, sessionId, command.taskId, completed.run);
|
|
1839
|
+
if (completed.state === 'failed') throw new Error(completed.error?.message || 'Host 执行失败,请在工作台查看状态。');
|
|
1840
|
+
}).catch((error) => {
|
|
1841
|
+
if (isCleaningSession(sessionId)) actions.setError(error.message || String(error));
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1751
1845
|
/** 工作台 store:入口按钮与工作台共享 open,并保存当前 taskId 的可持久化 UI 元数据。 */
|
|
1752
1846
|
function createWorkbenchStore() {
|
|
1753
1847
|
return defineStore({
|
|
@@ -1944,6 +2038,11 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
1944
2038
|
async function startCleaningSession(ctx) {
|
|
1945
2039
|
const workspace = ctx.workspaces.list.getSnapshot();
|
|
1946
2040
|
const current = ctx.sessions.list.getSnapshot().current;
|
|
2041
|
+
if (ownedSessionId(current)) {
|
|
2042
|
+
markCleaningSession(current);
|
|
2043
|
+
requestWorkbenchOpen(workflowTaskBySession.get(String(current))?.stage || 'upload', current);
|
|
2044
|
+
return current;
|
|
2045
|
+
}
|
|
1947
2046
|
const items = Array.isArray(workspace.items) ? workspace.items : [];
|
|
1948
2047
|
const currentWorkspace = current === undefined
|
|
1949
2048
|
? undefined
|
|
@@ -2040,6 +2139,7 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
2040
2139
|
const WORKBENCH_OPEN_EVENT = 'dsh:data-cleaning-workbench-open';
|
|
2041
2140
|
const WORKBENCH_DATASET_EVENT = 'dsh:data-cleaning-workbench-dataset';
|
|
2042
2141
|
const WORKBENCH_DRAFT_EVENT = 'dsh:data-cleaning-workbench-draft';
|
|
2142
|
+
const WORKBENCH_PREPARE_EVENT = 'dsh:data-cleaning-workbench-prepare';
|
|
2043
2143
|
|
|
2044
2144
|
// session scope 不能复用 root scope 的 store handle。DSH 当前会分别物化 root/session
|
|
2045
2145
|
// 插槽组件,因此以 document 事件跨 scope 通知;闭包引用仅作为无 DOM 测试降级。
|
|
@@ -2057,6 +2157,14 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
2057
2157
|
if (rootWorkbenchActions) openWorkbench(rootWorkbenchActions, step, sessionId);
|
|
2058
2158
|
}
|
|
2059
2159
|
|
|
2160
|
+
function requestPreparedWorkflow(sessionId, config) {
|
|
2161
|
+
return new Promise((resolve, reject) => {
|
|
2162
|
+
const event = document.createEvent('CustomEvent');
|
|
2163
|
+
event.initCustomEvent(WORKBENCH_PREPARE_EVENT, false, true, { sessionId, config, resolve, reject });
|
|
2164
|
+
if (document.dispatchEvent(event)) reject(new Error('工作台尚未就绪,请稍后重试。'));
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2060
2168
|
/** 把提示词生成器解析出的完整表格交给 root 工作台,不把整表塞进模型上下文。 */
|
|
2061
2169
|
function requestWorkbenchDataset(result, sessionId, source) {
|
|
2062
2170
|
if (typeof document !== 'undefined'
|
|
@@ -2667,7 +2775,7 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
2667
2775
|
imageCommandId: imageCommand?.commandId ?? '',
|
|
2668
2776
|
imageState: imageCommand?.state ?? null,
|
|
2669
2777
|
});
|
|
2670
|
-
const generatePrompt = () => {
|
|
2778
|
+
const generatePrompt = async () => {
|
|
2671
2779
|
const sourceError = validateSource();
|
|
2672
2780
|
if (sourceError) { setError(sourceError); return; }
|
|
2673
2781
|
if (!anchorKeys.length) { setError('请至少选择一个企业主体匹配主键。'); return; }
|
|
@@ -2687,17 +2795,10 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
2687
2795
|
removeImage(sessionId, imageAttachment);
|
|
2688
2796
|
setImageAttachment(null);
|
|
2689
2797
|
}
|
|
2690
|
-
const prompt = buildTaskPrompt(config);
|
|
2691
|
-
try {
|
|
2692
|
-
inputActions.setDraft(prompt);
|
|
2693
|
-
const updatedInput = getInputSnapshot?.(sessionId);
|
|
2694
|
-
if (updatedInput && updatedInput.draft !== prompt) throw new Error('当前对话尚未接收任务说明,请稍后重试回填。');
|
|
2695
|
-
} catch (draftError) {
|
|
2696
|
-
setError(draftError instanceof Error ? draftError.message : String(draftError));
|
|
2697
|
-
return;
|
|
2698
|
-
}
|
|
2699
2798
|
if (mode === 'text') {
|
|
2700
2799
|
requestWorkbenchDataset(entriesToDataset(config.entries), sessionId, { type: 'text', fileName: '' });
|
|
2800
|
+
} else if (mode === 'excel' && spreadsheetData) {
|
|
2801
|
+
requestWorkbenchDataset(spreadsheetData, sessionId, { type: spreadsheetData.fmt || 'xlsx', fileName: spreadsheetFileName });
|
|
2701
2802
|
}
|
|
2702
2803
|
requestWorkbenchDraft({
|
|
2703
2804
|
title: `企业数据清洗补全任务 · ${config.entryCount || '待解析'} 条`,
|
|
@@ -2707,6 +2808,20 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
2707
2808
|
...(mode === 'excel' ? { mappings: spreadsheetMappings } : {}),
|
|
2708
2809
|
source: { type: mode === 'excel' ? 'xlsx' : mode, fileName: config.fileName || '', rowCount: config.entryCount || 0 },
|
|
2709
2810
|
}, sessionId);
|
|
2811
|
+
setBusy(true);
|
|
2812
|
+
try {
|
|
2813
|
+
let prompt = buildTaskPrompt(config);
|
|
2814
|
+
if (mode !== 'image' || imageCommand?.state === 'completed') {
|
|
2815
|
+
const command = await requestPreparedWorkflow(sessionId, config);
|
|
2816
|
+
prompt = command.prompt + '\n\n' + buildTaskPrompt(config);
|
|
2817
|
+
}
|
|
2818
|
+
inputActions.setDraft(prompt);
|
|
2819
|
+
const updatedInput = getInputSnapshot?.(sessionId);
|
|
2820
|
+
if (updatedInput && updatedInput.draft !== prompt) throw new Error('当前对话尚未接收任务说明,请稍后重试回填。');
|
|
2821
|
+
} catch (draftError) {
|
|
2822
|
+
setError(draftError instanceof Error ? draftError.message : String(draftError));
|
|
2823
|
+
return;
|
|
2824
|
+
} finally { setBusy(false); }
|
|
2710
2825
|
setError(null);
|
|
2711
2826
|
setOpen(false);
|
|
2712
2827
|
setTimeout(() => {
|
|
@@ -3355,6 +3470,14 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
3355
3470
|
});
|
|
3356
3471
|
}
|
|
3357
3472
|
};
|
|
3473
|
+
const handlePrepare = (event) => {
|
|
3474
|
+
event.preventDefault();
|
|
3475
|
+
const { sessionId, config, resolve, reject } = event.detail;
|
|
3476
|
+
queueWorkflowOperation(sessionId, () => stageConfirmedWorkflow(actions, sessionId, config)).then((command) => {
|
|
3477
|
+
watchHostedCommand(actions, sessionId, command);
|
|
3478
|
+
resolve(command);
|
|
3479
|
+
}, reject);
|
|
3480
|
+
};
|
|
3358
3481
|
const handleDraft = (event) => {
|
|
3359
3482
|
event?.preventDefault?.();
|
|
3360
3483
|
const detail = event?.detail ?? {};
|
|
@@ -3374,12 +3497,14 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
3374
3497
|
document.addEventListener(WORKBENCH_OPEN_EVENT, handleOpen);
|
|
3375
3498
|
document.addEventListener(WORKBENCH_DATASET_EVENT, handleDataset);
|
|
3376
3499
|
document.addEventListener(WORKBENCH_DRAFT_EVENT, handleDraft);
|
|
3500
|
+
document.addEventListener(WORKBENCH_PREPARE_EVENT, handlePrepare);
|
|
3377
3501
|
}
|
|
3378
3502
|
return () => {
|
|
3379
3503
|
if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
|
|
3380
3504
|
document.removeEventListener(WORKBENCH_OPEN_EVENT, handleOpen);
|
|
3381
3505
|
document.removeEventListener(WORKBENCH_DATASET_EVENT, handleDataset);
|
|
3382
3506
|
document.removeEventListener(WORKBENCH_DRAFT_EVENT, handleDraft);
|
|
3507
|
+
document.removeEventListener(WORKBENCH_PREPARE_EVENT, handlePrepare);
|
|
3383
3508
|
}
|
|
3384
3509
|
stopJobsPolling();
|
|
3385
3510
|
if (rootWorkbenchActions === actions) rootWorkbenchActions = null;
|
|
@@ -3393,14 +3518,34 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
3393
3518
|
if (!disposed) actions.setWorkflowContract(response.contract);
|
|
3394
3519
|
}).catch(() => {});
|
|
3395
3520
|
loadWorkflowTasks(actions);
|
|
3396
|
-
if (activeSessionId
|
|
3397
|
-
queueWorkflowOperation(activeSessionId,
|
|
3521
|
+
if (activeSessionId) {
|
|
3522
|
+
queueWorkflowOperation(activeSessionId, async () => {
|
|
3523
|
+
const task = await ensureWorkflowTask(actions, activeSessionId, {}, step !== 'history');
|
|
3524
|
+
await refreshHostedTask(actions, activeSessionId, task.id, null, false);
|
|
3525
|
+
}).catch((taskError) => {
|
|
3398
3526
|
if (!disposed) actions.setError(taskError instanceof Error ? taskError.message : String(taskError));
|
|
3399
3527
|
});
|
|
3400
3528
|
}
|
|
3401
3529
|
return () => { disposed = true; };
|
|
3402
3530
|
}, [open, activeSessionId, actions]);
|
|
3403
3531
|
|
|
3532
|
+
// Reopening during execution follows Host metadata, even when the original
|
|
3533
|
+
// command watcher was lost on page reload. This performs no QCC calls.
|
|
3534
|
+
react.useEffect(() => {
|
|
3535
|
+
if (!open || !workflowTask?.id || !['matching', 'enriching'].includes(workflowTask.state)) return undefined;
|
|
3536
|
+
let disposed = false, timer;
|
|
3537
|
+
const poll = async () => {
|
|
3538
|
+
try {
|
|
3539
|
+
const task = await refreshHostedTask(actions, activeSessionId, workflowTask.id, null, false);
|
|
3540
|
+
if (disposed) return;
|
|
3541
|
+
if (['matching', 'enriching'].includes(task.state)) timer = setTimeout(poll, 2000);
|
|
3542
|
+
else if (step === 'match' || step === 'enrich') actions.setStep(task.stage || step);
|
|
3543
|
+
} catch (error) { if (!disposed) actions.setError(error.message); }
|
|
3544
|
+
};
|
|
3545
|
+
timer = setTimeout(poll, 2000);
|
|
3546
|
+
return () => { disposed = true; clearTimeout(timer); };
|
|
3547
|
+
}, [open, workflowTask?.id, workflowTask?.state, activeSessionId, step, actions]);
|
|
3548
|
+
|
|
3404
3549
|
// 非模态右栏会覆盖 Host 的中央画布;按实际重叠量把 composer 能力栏左移,
|
|
3405
3550
|
// 保证 Mockup 中的五个入口在窄桌面视口仍可见、可点击。展开态专注工作台,
|
|
3406
3551
|
// 不强行挤压到不足一栏的剩余区域。
|
|
@@ -3624,6 +3769,10 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
3624
3769
|
const reviewRequired = Number(summary.ambiguous ?? run.reviewQueue?.length ?? 0);
|
|
3625
3770
|
const currentTask = workflowTaskBySession.get(String(activeSessionId || 'unassigned')) ?? cachedTask;
|
|
3626
3771
|
let current = currentTask;
|
|
3772
|
+
if (currentTask?.qccRunId === run.runId && ['completed', 'partial', 'review_required', 'export_ready'].includes(currentTask.state)) {
|
|
3773
|
+
actions.setStep(currentTask.stage || 'download');
|
|
3774
|
+
return currentTask;
|
|
3775
|
+
}
|
|
3627
3776
|
// partial 表示上一轮仍有失败项。重试成功后可直接重进 enrichment,
|
|
3628
3777
|
// 无需伪造一次新的 match 转换;若重试产生候选,再回到人工核验。
|
|
3629
3778
|
if (currentTask?.state !== 'partial' || reviewRequired > 0) {
|
|
@@ -3664,14 +3813,16 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
3664
3813
|
if (!activeSessionId || typeof sendSessionCommand !== 'function') {
|
|
3665
3814
|
throw new Error('当前会话无法提交数据清洗补全企查查任务');
|
|
3666
3815
|
}
|
|
3816
|
+
const latest = workflowTaskBySession.get(String(activeSessionId)) ?? cachedTask;
|
|
3667
3817
|
const prepared = await api('/data-cleaning/api/g5/commands', {
|
|
3668
|
-
...payload,
|
|
3818
|
+
...payload, workflowOwned: true, expectedRevision: latest.revision,
|
|
3669
3819
|
...(payload.kind === 'enrich' ? {} : { confirmPaidCalls: true }),
|
|
3670
3820
|
});
|
|
3671
3821
|
const command = prepared?.command;
|
|
3672
3822
|
if (!command?.commandId || !command?.prompt) throw new Error('Host 未返回有效的企查查任务命令');
|
|
3673
3823
|
await sendSessionCommand(activeSessionId, command.prompt);
|
|
3674
3824
|
const completedCommand = await waitForQccCommand(command.commandId);
|
|
3825
|
+
await refreshHostedTask(actions, activeSessionId, command.taskId, completedCommand.run);
|
|
3675
3826
|
if (completedCommand.state === 'failed') {
|
|
3676
3827
|
const commandError = new Error(completedCommand.error?.message || '智能体企查查任务执行失败');
|
|
3677
3828
|
commandError.code = completedCommand.error?.code;
|
|
@@ -3681,40 +3832,14 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
3681
3832
|
return completedCommand.run;
|
|
3682
3833
|
};
|
|
3683
3834
|
|
|
3684
|
-
const prepareEditableQccCommand = async (
|
|
3835
|
+
const prepareEditableQccCommand = async () => {
|
|
3685
3836
|
if (!activeSessionId || typeof setSessionDraft !== 'function') {
|
|
3686
3837
|
throw new Error('当前会话无法回填可编辑的数据清洗补全任务说明');
|
|
3687
3838
|
}
|
|
3688
|
-
const
|
|
3689
|
-
if (host?.draftPreparationVersion !== 2 || host?.multipleOutputColumns !== true) {
|
|
3690
|
-
throw new Error('页面与 Host 版本不一致。请先保存或导出现有任务,再升级并重启 DSH、刷新页面。生成任务说明不需要勾选费用确认。');
|
|
3691
|
-
}
|
|
3692
|
-
const prepared = await api('/data-cleaning/api/g5/commands', {
|
|
3693
|
-
...payload,
|
|
3694
|
-
});
|
|
3695
|
-
const command = prepared?.command;
|
|
3696
|
-
if (!command?.commandId || !command?.prompt) throw new Error('Host 未返回有效的企查查任务命令');
|
|
3697
|
-
actions.setQccCapabilities({ capabilities: { ready: true } });
|
|
3839
|
+
const command = await queueWorkflowOperation(activeSessionId, () => stageConfirmedWorkflow(actions, activeSessionId));
|
|
3698
3840
|
setSessionDraft(activeSessionId, command.prompt);
|
|
3699
3841
|
actions.close();
|
|
3700
|
-
|
|
3701
|
-
// 发送权仍在用户手中:草稿回填不会调用 QCC。用户发送后,
|
|
3702
|
-
// Agent-owned 工具改变 command 状态;本地安全轮询只读取结果并回写工作流。
|
|
3703
|
-
void waitForQccCommand(command.commandId, 1800).then(async (completedCommand) => {
|
|
3704
|
-
if (completedCommand.state === 'failed') {
|
|
3705
|
-
const commandError = new Error(completedCommand.error?.message || '智能体企查查任务执行失败');
|
|
3706
|
-
commandError.code = completedCommand.error?.code;
|
|
3707
|
-
throw commandError;
|
|
3708
|
-
}
|
|
3709
|
-
if (!completedCommand.run) throw new Error('智能体企查查任务完成但结果已失效');
|
|
3710
|
-
await queueWorkflowOperation(activeSessionId, () => applyQccRun(completedCommand.run));
|
|
3711
|
-
}).catch(async (commandError) => {
|
|
3712
|
-
if (['QCC_NOT_CONNECTED', 'QCC_TOOL_UNAVAILABLE', 'QCC_AUTH_REQUIRED'].includes(commandError?.code)) {
|
|
3713
|
-
const latest = workflowTaskBySession.get(String(activeSessionId || 'unassigned')) ?? cachedTask;
|
|
3714
|
-
try { await workflowAction(actions, activeSessionId, latest, 'authorization-required'); } catch (_workflowError) {}
|
|
3715
|
-
}
|
|
3716
|
-
actions.setError(commandError instanceof Error ? commandError.message : String(commandError));
|
|
3717
|
-
});
|
|
3842
|
+
watchHostedCommand(actions, activeSessionId, command);
|
|
3718
3843
|
return command;
|
|
3719
3844
|
};
|
|
3720
3845
|
|
|
@@ -3842,7 +3967,17 @@ body:has(.dcAgentPromptBackdrop) { overflow: hidden; }
|
|
|
3842
3967
|
}
|
|
3843
3968
|
};
|
|
3844
3969
|
|
|
3845
|
-
const resumeWorkflowTask = (task) => {
|
|
3970
|
+
const resumeWorkflowTask = async (task) => {
|
|
3971
|
+
try {
|
|
3972
|
+
workflowTaskBySession.set(String(activeSessionId), task);
|
|
3973
|
+
task = await refreshHostedTask(actions, activeSessionId, task.id);
|
|
3974
|
+
if (task.qccRunId) {
|
|
3975
|
+
try {
|
|
3976
|
+
const response = await api(`/data-cleaning/api/g5/run/${encodeURIComponent(task.qccRunId)}`);
|
|
3977
|
+
actions.setQccRun(response);
|
|
3978
|
+
} catch { /* Expired run data does not prevent persisted artifact downloads. */ }
|
|
3979
|
+
}
|
|
3980
|
+
} catch (error) { actions.setError(error.message); return; }
|
|
3846
3981
|
workflowTaskBySession.set(String(activeSessionId || 'unassigned'), task);
|
|
3847
3982
|
actions.setWorkflowTask(task);
|
|
3848
3983
|
actions.setTaskTitle(task.title);
|
package/lib/qcc-command.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* and lets this high-level tool perform the paid calls with exec.token.
|
|
8
8
|
*/
|
|
9
9
|
import { randomUUID } from 'node:crypto';
|
|
10
|
+
import { WorkflowError } from './workflow.js';
|
|
10
11
|
import { QccBridgeError } from './qcc.js';
|
|
11
12
|
import { fieldLabel, normalizeFieldSelection } from './workflow-contract.js';
|
|
12
13
|
|
|
@@ -21,6 +22,7 @@ function clone(value) {
|
|
|
21
22
|
|
|
22
23
|
function safeError(error) {
|
|
23
24
|
if (error instanceof QccBridgeError) return error.toJSON();
|
|
25
|
+
if (error instanceof WorkflowError) return { code: error.code, message: error.message, retryable: false };
|
|
24
26
|
return new QccBridgeError('QCC_COMMAND_FAILED', 'Data-cleaning QCC command failed', {
|
|
25
27
|
retryable: false,
|
|
26
28
|
}).toJSON();
|
|
@@ -45,6 +47,8 @@ function normalizedInput(input = {}) {
|
|
|
45
47
|
return {
|
|
46
48
|
kind,
|
|
47
49
|
taskId,
|
|
50
|
+
workflowOwned: input.workflowOwned === true,
|
|
51
|
+
workflowRevision: input.workflowRevision,
|
|
48
52
|
rows: clone(rows),
|
|
49
53
|
headers: Array.isArray(input.headers) ? input.headers.map(String) : [],
|
|
50
54
|
nameField: String(input.nameField ?? 'name'),
|
|
@@ -59,6 +63,8 @@ function normalizedInput(input = {}) {
|
|
|
59
63
|
kind,
|
|
60
64
|
taskId,
|
|
61
65
|
runId,
|
|
66
|
+
workflowOwned: input.workflowOwned === true,
|
|
67
|
+
workflowRevision: input.workflowRevision,
|
|
62
68
|
companyName: requiredText(input.companyName, 'QCC_REVIEW_NOT_PENDING', 'A company name is required'),
|
|
63
69
|
selectedCreditNo: requiredText(input.selectedCreditNo, 'QCC_CANDIDATE_INVALID', 'A selected credit number is required'),
|
|
64
70
|
};
|
|
@@ -66,7 +72,7 @@ function normalizedInput(input = {}) {
|
|
|
66
72
|
const companyNames = [...new Set((Array.isArray(input.companyNames) ? input.companyNames : [])
|
|
67
73
|
.map((name) => String(name).trim()).filter(Boolean))];
|
|
68
74
|
if (companyNames.length === 0) throw new QccBridgeError('QCC_RETRY_EMPTY', 'At least one failed company must be selected');
|
|
69
|
-
return { kind, taskId, runId, companyNames };
|
|
75
|
+
return { kind, taskId, runId, companyNames, workflowOwned: input.workflowOwned === true, workflowRevision: input.workflowRevision };
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
export function serializeQccCommandPrompt(command) {
|
|
@@ -99,11 +105,15 @@ export function serializeQccCommandPrompt(command) {
|
|
|
99
105
|
'',
|
|
100
106
|
`发送本说明后,请仅调用一次数据清洗补全执行工具(${TOOL_QCC_COMMAND}),参数只传递上述安全任务凭证。`,
|
|
101
107
|
'不要要求重复粘贴企业名单,不要直接调用 mcp__qcc-* 工具,不要重试、扩大名单或追加字段。',
|
|
108
|
+
input.workflowOwned
|
|
109
|
+
? '发送即执行已确认方案,不再询问额度或写回确认。Host 会自动生成新的清洗补全结果 XLSX,原始上传文件不修改。不要寻找源文件路径、运行 Bash、编写导出脚本或另行覆盖源文件。'
|
|
110
|
+
: '这是兼容模式命令,返回工作台查看结果并导出。不要另行寻找或覆盖源文件;如需自动交付新 Excel,请在最新版工作台重新生成任务说明。',
|
|
111
|
+
'高层工具返回后只汇报真实状态,并提示返回数据清洗补全工作台下载;主体多候选或真实授权异常才需要人工处理。',
|
|
102
112
|
].join('\n');
|
|
103
113
|
}
|
|
104
114
|
|
|
105
115
|
export class QccCommandStore {
|
|
106
|
-
constructor({ bridge, runs, clock = () => Date.now(), ttlMs = DEFAULT_TTL_MS, maxCommands = DEFAULT_MAX_COMMANDS } = {}) {
|
|
116
|
+
constructor({ bridge, runs, clock = () => Date.now(), ttlMs = DEFAULT_TTL_MS, maxCommands = DEFAULT_MAX_COMMANDS, lifecycle } = {}) {
|
|
107
117
|
if (!bridge || !runs) throw new TypeError('QccCommandStore requires bridge and runs');
|
|
108
118
|
this.bridge = bridge;
|
|
109
119
|
this.runs = runs;
|
|
@@ -111,6 +121,7 @@ export class QccCommandStore {
|
|
|
111
121
|
this.ttlMs = ttlMs;
|
|
112
122
|
this.maxCommands = maxCommands;
|
|
113
123
|
this.commands = new Map();
|
|
124
|
+
this.lifecycle = lifecycle;
|
|
114
125
|
}
|
|
115
126
|
|
|
116
127
|
cleanup(reserveSlot = false) {
|
|
@@ -171,6 +182,8 @@ export class QccCommandStore {
|
|
|
171
182
|
runId: record.runId,
|
|
172
183
|
error: record.error,
|
|
173
184
|
estimate: record.estimate,
|
|
185
|
+
workflowOwned: record.input.workflowOwned === true,
|
|
186
|
+
delivery: record.delivery ?? null,
|
|
174
187
|
expiresInMs: this.ttlMs,
|
|
175
188
|
});
|
|
176
189
|
}
|
|
@@ -190,15 +203,18 @@ export class QccCommandStore {
|
|
|
190
203
|
if (record.promise) return record.promise;
|
|
191
204
|
record.state = 'running';
|
|
192
205
|
record.updatedAt = new Date(this.clock()).toISOString();
|
|
193
|
-
record.promise = this.
|
|
194
|
-
.then((
|
|
206
|
+
record.promise = Promise.resolve().then(() => this.lifecycle?.beforeRun(record))
|
|
207
|
+
.then(() => this.execute(record, execution))
|
|
208
|
+
.then(async (run) => {
|
|
195
209
|
record.runId = run.runId;
|
|
210
|
+
record.delivery = await this.lifecycle?.complete(record, run);
|
|
196
211
|
record.state = 'completed';
|
|
197
212
|
record.updatedAt = new Date(this.clock()).toISOString();
|
|
198
213
|
record.touchedAtMs = this.clock();
|
|
199
214
|
return this.toolResult(record, run);
|
|
200
215
|
})
|
|
201
|
-
.catch((error) => {
|
|
216
|
+
.catch(async (error) => {
|
|
217
|
+
try { await this.lifecycle?.failed(record, error); } catch { /* Preserve the original execution failure. */ }
|
|
202
218
|
record.error = safeError(error);
|
|
203
219
|
record.state = 'failed';
|
|
204
220
|
record.updatedAt = new Date(this.clock()).toISOString();
|
|
@@ -244,6 +260,7 @@ export class QccCommandStore {
|
|
|
244
260
|
runId: run.runId,
|
|
245
261
|
state: run.state,
|
|
246
262
|
summary: run.summary,
|
|
263
|
+
...(record.delivery ? { deliveryState: record.delivery.state, artifactCount: record.delivery.artifacts.length } : {}),
|
|
247
264
|
});
|
|
248
265
|
}
|
|
249
266
|
}
|
|
@@ -267,6 +284,8 @@ export function registerQccCommandTool(tools, commands) {
|
|
|
267
284
|
taskId: { type: 'string' },
|
|
268
285
|
runId: { type: 'string' },
|
|
269
286
|
state: { type: 'string' },
|
|
287
|
+
deliveryState: { type: 'string' },
|
|
288
|
+
artifactCount: { type: 'integer' },
|
|
270
289
|
summary: {
|
|
271
290
|
type: 'object',
|
|
272
291
|
additionalProperties: false,
|
|
@@ -288,7 +307,7 @@ export function registerQccCommandTool(tools, commands) {
|
|
|
288
307
|
},
|
|
289
308
|
render: (_args, value) => [{
|
|
290
309
|
type: 'text',
|
|
291
|
-
text:
|
|
310
|
+
text: `数据清洗补全:${value.summary?.enriched ?? 0}/${value.summary?.totalRows ?? 0} 条已补全。${value.artifactCount ? 'Host 已生成新的结果 XLSX,请返回工作台「结果下载」。源文件未修改,无需再次确认或提供路径。' : value.deliveryState === 'review_required' ? '存在多候选,请返回工作台确认主体。' : '请返回工作台查看任务状态。'}`,
|
|
292
311
|
}],
|
|
293
312
|
},
|
|
294
313
|
async execute(args, exec) {
|
package/lib/skill-enrich.js
CHANGED
|
@@ -56,7 +56,9 @@ export function registerEnrichSkill(skills) {
|
|
|
56
56
|
'',
|
|
57
57
|
'Workbench execution request (highest priority):',
|
|
58
58
|
'- If the visible user message is the readable data-cleaning task summary generated by the workbench, contains a `安全任务凭证` beginning with `dcq-`, and explicitly requests `data_cleaning_qcc_run`, treat that credential as `commandId`, call the high-level tool exactly once with only `commandId`, then stop.',
|
|
59
|
-
'- The Host already holds the rows, billing confirmation and field selection. Do not ask the user to paste rows, do not call any `mcp__qcc-*` tool directly, do not retry, and do not expand the batch.',
|
|
59
|
+
'- The Host already holds the rows, billing confirmation and field selection. Sending the visible staged scope is the execution confirmation: do not ask again about quota or writing a file. Do not ask the user to paste rows, do not call any `mcp__qcc-*` tool directly, do not retry, and do not expand the batch.',
|
|
60
|
+
'- The Host automatically creates a NEW enriched Excel and attaches downloads to this workflow task. Never use Bash, search the filesystem, request the original path, overwrite the source workbook, or create substitute CSV reports for a workbench task. Report delivery only from the high-level tool result; unresolved entity candidates are confirmed in the workbench.',
|
|
61
|
+
'- If a message says the workbench holds its source but has no valid dcq- credential, return to the workbench to regenerate the task description. Do not fall back to free-form MCP or filesystem execution.',
|
|
60
62
|
'',
|
|
61
63
|
'Workflow:',
|
|
62
64
|
'1. Check QCC availability first: run `qcc_oauth_status`. If not connected, tell the user to run `qcc_oauth_connect` first and stop. If the token is expired, guide the user to `qcc_oauth_connect` (it reuses the grant and refreshes without a new authorization page).',
|
package/lib/web.js
CHANGED
|
@@ -16,6 +16,7 @@ import { PHASE3_BATCH_LIMITS, Phase3BatchService, Phase3RunStore } from './qcc-p
|
|
|
16
16
|
import { publicWorkflowContract } from './workflow-contract.js';
|
|
17
17
|
import { DataCleaningWorkflowStore, WorkflowError } from './workflow.js';
|
|
18
18
|
import { ArtifactError, WorkflowArtifactStore } from './artifacts.js';
|
|
19
|
+
import { createWorkflowExecution } from './workflow-execution.js';
|
|
19
20
|
import {
|
|
20
21
|
ImageIntakeError,
|
|
21
22
|
ImageIntakeStore,
|
|
@@ -305,7 +306,8 @@ export function mountWebRoutes(wctx, { logger, report, TOOL_NAME, SKILL_NAME })
|
|
|
305
306
|
const qccBridge = new QccHostBridge({ tools, logger });
|
|
306
307
|
const imageIntake = new ImageIntakeStore({ tools });
|
|
307
308
|
const g5Runs = new G5RunStore();
|
|
308
|
-
const
|
|
309
|
+
const execution = createWorkflowExecution({ getWorkflow: () => getWorkflow(), artifacts: wctx.fs ? new WorkflowArtifactStore({ fs: wctx.fs }) : null });
|
|
310
|
+
const qccCommands = new QccCommandStore({ bridge: qccBridge, runs: g5Runs, lifecycle: execution });
|
|
309
311
|
if (typeof tools?.register === 'function') {
|
|
310
312
|
disposers.push(registerQccCommandTool(tools, qccCommands));
|
|
311
313
|
disposers.push(registerImageIntakeTool(tools, imageIntake));
|
|
@@ -620,6 +622,7 @@ export function mountWebRoutes(wctx, { logger, report, TOOL_NAME, SKILL_NAME })
|
|
|
620
622
|
draftPreparationVersion: 2,
|
|
621
623
|
draftPaidCallConfirmationRequired: false,
|
|
622
624
|
multipleOutputColumns: true,
|
|
625
|
+
workflowExecutionVersion: 1,
|
|
623
626
|
idempotencyRequired: true,
|
|
624
627
|
candidateResume: true,
|
|
625
628
|
manualRetry: true,
|
|
@@ -650,7 +653,7 @@ export function mountWebRoutes(wctx, { logger, report, TOOL_NAME, SKILL_NAME })
|
|
|
650
653
|
ok: true,
|
|
651
654
|
marker: 'g5-agent-command',
|
|
652
655
|
paidCalls: false,
|
|
653
|
-
command: qccCommands.prepare(payload),
|
|
656
|
+
command: qccCommands.prepare(payload.workflowOwned ? await execution.prepare(payload) : payload),
|
|
654
657
|
});
|
|
655
658
|
}
|
|
656
659
|
if (rest.length === 1 && req.method === 'GET') {
|
|
@@ -665,6 +668,7 @@ export function mountWebRoutes(wctx, { logger, report, TOOL_NAME, SKILL_NAME })
|
|
|
665
668
|
if (error instanceof SyntaxError) {
|
|
666
669
|
return writeJson(res, 400, { ok: false, code: 'DC_BAD_JSON', message: 'Request body must be valid JSON.' });
|
|
667
670
|
}
|
|
671
|
+
if (error instanceof WorkflowError) return writeWorkflowError(res, error);
|
|
668
672
|
return writeQccError(res, error);
|
|
669
673
|
}
|
|
670
674
|
});
|
package/lib/workflow-contract.js
CHANGED
|
@@ -88,7 +88,7 @@ const TRANSITIONS = Object.freeze({
|
|
|
88
88
|
export_ready: ['enriching', 'completed', 'failed', 'cancelled'],
|
|
89
89
|
parse_failed: ['draft', 'uploaded', 'cancelled'],
|
|
90
90
|
authorization_required: ['matching', 'enriching', 'failed', 'cancelled'],
|
|
91
|
-
partial: ['review_required', 'enriching', 'export_ready', 'authorization_required', 'completed', 'failed', 'cancelled'],
|
|
91
|
+
partial: ['matching', 'review_required', 'enriching', 'export_ready', 'authorization_required', 'completed', 'failed', 'cancelled'],
|
|
92
92
|
failed: ['draft', 'uploaded', 'rules_confirmed', 'diagnosed', 'matching', 'enriching', 'cancelled'],
|
|
93
93
|
completed: [],
|
|
94
94
|
cancelled: [],
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { WorkflowError } from './workflow.js';
|
|
2
|
+
|
|
3
|
+
// Execution owns finalization: closing a browser must not interrupt result delivery.
|
|
4
|
+
export function createWorkflowExecution({ getWorkflow, artifacts }) {
|
|
5
|
+
const requireStore = async () => {
|
|
6
|
+
const store = await getWorkflow();
|
|
7
|
+
if (!store || !artifacts) throw new WorkflowError('DC_DELIVERY_UNAVAILABLE', 'Host 任务存储或下载服务不可用,请升级 DSH。', 503);
|
|
8
|
+
return store;
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
async prepare(payload) {
|
|
12
|
+
const store = await requireStore();
|
|
13
|
+
const task = await store.require(payload.taskId);
|
|
14
|
+
if (!['rules_confirmed', 'diagnosed', 'review_required', 'partial'].includes(task.state)) {
|
|
15
|
+
throw new WorkflowError('DC_EXECUTION_STATE', '请先在工作台确认规则;进行中或已完成任务不能重复启动。', 409);
|
|
16
|
+
}
|
|
17
|
+
if (Number(payload.expectedRevision) !== task.revision) throw new WorkflowError('DC_WORKFLOW_REVISION_CONFLICT', '任务已更新,请重新生成说明。', 409);
|
|
18
|
+
if ((!payload.kind || payload.kind === 'enrich') && !['rules_confirmed', 'diagnosed'].includes(task.state)) {
|
|
19
|
+
throw new WorkflowError('DC_EXECUTION_STATE', '请通过候选确认或失败重试继续当前任务。', 409);
|
|
20
|
+
}
|
|
21
|
+
if (payload.kind && payload.kind !== 'enrich' && payload.runId !== task.qccRunId) throw new WorkflowError('DC_RUN_MISMATCH', '执行结果不属于当前任务。', 409);
|
|
22
|
+
if (!payload.kind || payload.kind === 'enrich') {
|
|
23
|
+
if (!Array.isArray(payload.rows) || payload.rows.length !== task.source?.rowCount) throw new WorkflowError('DC_SOURCE_MISMATCH', '任务名单数量不一致,请重新载入。', 409);
|
|
24
|
+
}
|
|
25
|
+
if (!task.fieldSelection.length) throw new WorkflowError('DC_FIELDS_REQUIRED', '未选择外部补全字段,请使用本地清洗与导出。', 400);
|
|
26
|
+
const primary = task.mappings.find((m) => m.targetField === 'company_name')
|
|
27
|
+
?? task.mappings.find((m) => m.targetField === 'credit_no')
|
|
28
|
+
?? task.mappings.find((m) => m.targetField === 'reg_no');
|
|
29
|
+
return { ...payload, workflowOwned: true, workflowRevision: task.revision,
|
|
30
|
+
fieldSelection: task.fieldSelection, headers: task.source?.headers || [],
|
|
31
|
+
nameField: primary?.sourceField || payload.nameField };
|
|
32
|
+
},
|
|
33
|
+
async beforeRun(record) {
|
|
34
|
+
if (!record.input.workflowOwned) return;
|
|
35
|
+
const store = await requireStore();
|
|
36
|
+
const task = await store.require(record.taskId);
|
|
37
|
+
if (task.revision !== record.input.workflowRevision) throw new WorkflowError('DC_WORKFLOW_REVISION_CONFLICT', '说明已失效,请返回工作台重新生成;未执行查询。', 409);
|
|
38
|
+
await store.startMatch(task.id, { expectedRevision: task.revision });
|
|
39
|
+
record.workflowStarted = true;
|
|
40
|
+
},
|
|
41
|
+
async failed(record, error) {
|
|
42
|
+
if (!record.input.workflowOwned || !record.workflowStarted) return;
|
|
43
|
+
const store = await requireStore();
|
|
44
|
+
const task = await store.require(record.taskId);
|
|
45
|
+
if (['completed', 'cancelled', 'failed'].includes(task.state)) return;
|
|
46
|
+
if (['QCC_AUTH_REQUIRED', 'QCC_NOT_CONNECTED', 'QCC_TOOL_UNAVAILABLE'].includes(error.code)) {
|
|
47
|
+
await store.requireAuthorization(task.id, { expectedRevision: task.revision });
|
|
48
|
+
} else {
|
|
49
|
+
await store.recordFailure(task.id, { expectedRevision: task.revision, code: error.code || 'DC_DELIVERY_FAILED' });
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
async complete(record, run) {
|
|
53
|
+
if (!record.input.workflowOwned) return;
|
|
54
|
+
const store = await requireStore();
|
|
55
|
+
let task = await store.require(record.taskId);
|
|
56
|
+
const s = run.summary || {};
|
|
57
|
+
const total = Number(s.totalRows ?? run.rows.length);
|
|
58
|
+
const review = Number(s.ambiguous ?? 0);
|
|
59
|
+
task = await store.recordMatch(task.id, { expectedRevision: task.revision, qccRunId: run.runId,
|
|
60
|
+
summary: { total, exact: Number(s.enriched || 0) + Number(s.fieldReview || 0), candidate: review,
|
|
61
|
+
unresolved: Number(s.unresolved || 0) + Number(s.missingName || 0), failed: Number(s.failed || 0), reviewRequired: review } });
|
|
62
|
+
if (review) return { state: task.state, artifacts: [], taskId: task.id };
|
|
63
|
+
task = await store.startEnrichment(task.id, { expectedRevision: task.revision });
|
|
64
|
+
task = await store.recordEnrichment(task.id, { expectedRevision: task.revision, qccRunId: run.runId,
|
|
65
|
+
summary: { total, completed: Number(s.enriched || 0), unchanged: Number(s.unresolved || 0) + Number(s.missingName || 0),
|
|
66
|
+
failed: Number(s.failed || 0), reviewRequired: Number(s.fieldReview || 0), callsUsed: run.audit?.length || 0 } });
|
|
67
|
+
const bundle = await artifacts.createBundle(task.id, { rows: run.rows, headers: task.source?.headers || run.headers,
|
|
68
|
+
mappings: task.mappings, fieldSelection: task.fieldSelection,
|
|
69
|
+
baseName: (task.source?.fileName || task.title).replace(/\.[^.]+$/, '') + '-清洗补全结果' });
|
|
70
|
+
task = await store.recordExport(task.id, { expectedRevision: task.revision, artifacts: bundle, preservePartial: true });
|
|
71
|
+
return { state: task.state, artifacts: task.artifacts, taskId: task.id };
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
package/lib/workflow.js
CHANGED
|
@@ -384,7 +384,7 @@ export class DataCleaningWorkflowStore {
|
|
|
384
384
|
throw new WorkflowError('DC_WORKFLOW_ARTIFACT_REQUIRED', 'At least one Host artifact reference is required.', 400);
|
|
385
385
|
}
|
|
386
386
|
return {
|
|
387
|
-
state: 'completed',
|
|
387
|
+
state: input.preservePartial === true && record.state === 'partial' ? 'partial' : 'completed',
|
|
388
388
|
stage: 'download',
|
|
389
389
|
artifacts: [...record.artifacts, ...artifacts].slice(-20),
|
|
390
390
|
error: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-data-cleaning-agent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.17",
|
|
4
4
|
"description": "Data cleaning and data enrichment for CSV/XLSX/JSON enterprise lists in DeepSeek Harness, including spreadsheet cleaning, deduplication, profiling, optional Qichacha MCP and exports.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"docs/RELEASE-0.8.0.md",
|
|
40
40
|
"docs/RELEASE-0.8.1.md",
|
|
41
41
|
"docs/RELEASE-0.8.16.md",
|
|
42
|
+
"docs/RELEASE-0.8.17.md",
|
|
42
43
|
"docs/TEMPLATE-MAPPING-ACCEPTANCE.md",
|
|
43
44
|
"docs/UI-WORKFLOW-V2.md",
|
|
44
45
|
"docs/UI-WORKFLOW-V2-MIGRATION.md",
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
"scripts": {
|
|
50
51
|
"test:ui": "node scripts/ui-layout-regression.mjs",
|
|
51
52
|
"test": "node --test",
|
|
52
|
-
"lint": "node --check lib/index.js && node --check lib/engine.js && node --check lib/artifacts.js && node --check lib/image-intake.js && node --check lib/tools.js && node --check lib/skill.js && node --check lib/qcc-field-catalog.js && node --check lib/qcc-phase2.js && node --check lib/qcc-phase3.js && node --check lib/qcc-phase3-batch.js && node --check lib/qcc-phase2-acceptance.js && node --check lib/skill-enrich.js && node --check lib/jobs.js && node --check lib/workflow-contract.js && node --check lib/workflow.js && node --check lib/qcc-safety.js && node --check lib/qcc.js && node --check lib/qcc-command.js && node --check lib/qcc-runs.js && node --check lib/web.js && node --check lib/client.js && node --check scripts/check-readme-version.mjs && node --check scripts/check-market-registration.mjs && node --check scripts/g5-e2e.mjs && node --check scripts/phase3-e2e.mjs && node --check scripts/phase2-acceptance.mjs",
|
|
53
|
+
"lint": "node --check lib/index.js && node --check lib/engine.js && node --check lib/artifacts.js && node --check lib/image-intake.js && node --check lib/tools.js && node --check lib/skill.js && node --check lib/qcc-field-catalog.js && node --check lib/qcc-phase2.js && node --check lib/qcc-phase3.js && node --check lib/qcc-phase3-batch.js && node --check lib/qcc-phase2-acceptance.js && node --check lib/skill-enrich.js && node --check lib/jobs.js && node --check lib/workflow-contract.js && node --check lib/workflow.js && node --check lib/workflow-execution.js && node --check lib/qcc-safety.js && node --check lib/qcc.js && node --check lib/qcc-command.js && node --check lib/qcc-runs.js && node --check lib/web.js && node --check lib/client.js && node --check scripts/check-readme-version.mjs && node --check scripts/check-market-registration.mjs && node --check scripts/g5-e2e.mjs && node --check scripts/phase3-e2e.mjs && node --check scripts/phase2-acceptance.mjs",
|
|
53
54
|
"docs:check": "node scripts/check-readme-version.mjs",
|
|
54
55
|
"marketing:check": "node scripts/check-marketing.mjs",
|
|
55
56
|
"verify-pack": "node scripts/verify-pack.mjs",
|