agentworkshop 0.12.0 → 0.13.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/.output/nitro.json +1 -1
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/2f96705b-cf57-4bde-87a4-1b818b268f0f.json +1 -0
- package/.output/server/chunks/_/nitro.mjs +1102 -1088
- package/.output/server/package.json +1 -1
- package/README-zh.md +18 -6
- package/README.md +20 -6
- package/config.yml +1 -1
- package/docs/cli.en.md +1 -1
- package/docs/cli.md +1 -1
- package/docs/plugin-idd-rag-contract.md +87 -0
- package/docs/plugins.en.md +2 -2
- package/docs/plugins.md +2 -2
- package/docs/sdk.en.md +1 -1
- package/docs/sdk.md +1 -1
- package/package.json +2 -1
- package/scripts/onboarding/sim-twin.mjs +27 -15
- package/server/plugins-builtin/diag-bridge/host/deposit.mjs +232 -0
- package/server/plugins-builtin/diag-bridge/host/diagnosis.mjs +121 -38
- package/server/plugins-builtin/diag-bridge/host/external-v1.mjs +213 -0
- package/server/plugins-builtin/diag-bridge/host/helpers.mjs +4 -2
- package/server/plugins-builtin/diag-bridge/host/intents.mjs +65 -62
- package/server/plugins-builtin/diag-bridge/host/plugin.mjs +351 -82
- package/server/plugins-builtin/diag-bridge/host/receipt.mjs +83 -0
- package/server/plugins-builtin/diag-bridge/host/sweep.mjs +70 -91
- package/server/plugins-builtin/diag-bridge/i18n.json +4 -0
- package/server/plugins-builtin/rag-bridge/i18n.json +18 -0
- package/server/plugins-builtin/rag-bridge/index.mjs +556 -68
- package/server/services/workshop/agents/industrial/optimization-tools.ts +12 -1
- package/server/services/workshop/tools/policy.ts +16 -1
- package/.output/public/_nuxt/builds/meta/577f464e-672a-4c4e-a3c8-dc8c1b38930d.json +0 -1
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
* (由 server/plugins-builtin/diag-bridge/index.mjs 按职责拆出;内容逐行原文搬运)
|
|
4
4
|
*/
|
|
5
5
|
import { AUTO_COOLDOWN_MS, DEFAULT_BASE, MIN } from './constants.mjs'
|
|
6
|
-
import { absoluteUrl, authHeadersOf, authHint, autoEnabledOf, autoRulesOf, baseOf, diagTokenOf, harnessOf, jget, jpatch, kvRuns, mapResultsError, parseAutoRules, probeResults, resultsAllowAnnotateOf, resultsAllowWorkerOf, resultsDefaultLimitOf, resultsEnabledOf, resultsMdMaxOf, runKey } from './helpers.mjs'
|
|
6
|
+
import { absoluteUrl, authHeadersOf, authHint, autoEnabledOf, autoRulesOf, baseOf, diagTokenOf, harnessOf, jget, jpatch, jpost, kvRuns, mapResultsError, parseAutoRules, probeResults, resultsAllowAnnotateOf, resultsAllowWorkerOf, resultsDefaultLimitOf, resultsEnabledOf, resultsMdMaxOf, runKey } from './helpers.mjs'
|
|
7
|
+
import { awaitingMaxMinutesOf, contractModeOf, mapV1Error, normalizeResult, v1Chat, v1Result, v1Stop, v1Task } from './external-v1.mjs'
|
|
8
|
+
import { isTerminal } from './receipt.mjs'
|
|
9
|
+
import { depositRunToRag } from './deposit.mjs'
|
|
7
10
|
import { snapshotCore } from './snapshot.mjs'
|
|
8
11
|
import { startDiagnosis } from './diagnosis.mjs'
|
|
9
12
|
import { uploadExportDataset } from './exports.mjs'
|
|
@@ -22,15 +25,22 @@ function registerDiagnosticTool(ctx, tool) {
|
|
|
22
25
|
catch {
|
|
23
26
|
return { text: '无法确认频道模式,拒绝产线诊断工具。', isError: true }
|
|
24
27
|
}
|
|
25
|
-
|
|
28
|
+
const out = await handler(args, agent)
|
|
29
|
+
// WS-4 S3:工具调用计数(health 可见;失败分类由 isError 记 err)
|
|
30
|
+
try {
|
|
31
|
+
const key = `usage.${tool.name}.${out?.isError ? 'err' : 'ok'}`
|
|
32
|
+
ctx.kv.set(key, Number(ctx.kv.get(key) ?? 0) + 1)
|
|
33
|
+
}
|
|
34
|
+
catch { /* 计数失败不影响调用 */ }
|
|
35
|
+
return out
|
|
26
36
|
},
|
|
27
37
|
})
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
export default {
|
|
31
41
|
name: 'diag-bridge',
|
|
32
|
-
version: '2.
|
|
33
|
-
description: '深度诊断桥接 v2.
|
|
42
|
+
version: '2.4.0',
|
|
43
|
+
description: '深度诊断桥接 v2.4:external v1 主契约(capabilities 定轨/legacy 回退)+ 全 7 意图透传 + 异步任务式分析 + daq-export 数据集多文件分析 + 同步等待/异步回执 + diag_chat 续聊 / diag_stop 停止 + 结果库检索。报告完成后可 diag_deposit 一键入库知识库。',
|
|
34
44
|
auth: 'user',
|
|
35
45
|
client: './client.mjs', // 前端面板(插件页注入;i18n 见 i18n.json)
|
|
36
46
|
// 插件配置分组(声明式):连接 / 执行 / 自动化 三个独立分区
|
|
@@ -45,6 +55,8 @@ export default {
|
|
|
45
55
|
{ key: 'base_url', type: 'string', default: DEFAULT_BASE, group: 'default', labelKey: 'plugin.diag-bridge.settings.base_url', label: '诊断服务地址', description: 'industrial-deep-diagnostic 后端(http/https,host 限 127.0.0.1/localhost);保存即热生效' },
|
|
46
56
|
{ key: 'token', type: 'string', default: '', group: 'default', labelKey: 'plugin.diag-bridge.settings.token', label: '诊断 API Token', description: '诊断服务开启鉴权时(v4 起默认强制)的 API Token(Authorization: Bearer);空=匿名;保存即热生效' },
|
|
47
57
|
{ key: 'harness', type: 'string', default: '', group: 'run', labelKey: 'plugin.diag-bridge.settings.harness', label: '诊断引擎', description: 'diag_run 用的引擎 id(omp/claude/mock 等;空=取 kv/omp);无 Anthropic key 的机器请用 omp' },
|
|
58
|
+
{ key: 'contract', type: 'string', default: 'auto', group: 'default', labelKey: 'plugin.diag-bridge.settings.contract', label: 'IDD 契约', description: 'auto=提交前探测 /capabilities 定轨(推荐);v1=强制 external v1;legacy=强制旧 /api/diagnosis 路径(回归保障)' },
|
|
59
|
+
{ key: 'awaiting_max_minutes', type: 'number', default: 30, min: 1, max: 1440, group: 'run', labelKey: 'plugin.diag-bridge.settings.awaiting_max_minutes', label: '等待人工介入上限(分钟)', description: 'run 处于 awaiting_input 时保持产线单飞锁;超过该时长转 expired 并发送提示性回执' },
|
|
48
60
|
{ key: 'max_turns', type: 'number', default: 0, min: 0, max: 2000, group: 'run', labelKey: 'plugin.diag-bridge.settings.max_turns', label: '诊断最大轮数', description: 'diagnosis/start 的 maxTurns(0=取 kv/内置默认 220)' },
|
|
49
61
|
{ key: 'max_minutes', type: 'number', default: 0, min: 0, max: 720, group: 'run', labelKey: 'plugin.diag-bridge.settings.max_minutes', label: '诊断超时(分钟)', description: 'diagnosis/start 的 timeoutMinutes(0=取 kv/内置默认 40)' },
|
|
50
62
|
{ key: 'auto_enabled', type: 'boolean', default: false, group: 'auto', labelKey: 'plugin.diag-bridge.settings.auto_enabled', label: '自动诊断', description: 'daq:sample 越限命中规则时自动发起深度诊断(每产线冷却 30 分钟)' },
|
|
@@ -119,7 +131,7 @@ export default {
|
|
|
119
131
|
registerDiagnosticTool(ctx, {
|
|
120
132
|
name: 'diag_run',
|
|
121
133
|
label: '发起分析',
|
|
122
|
-
description: '发起 IDD 后台分析任务(提交即返 task_id
|
|
134
|
+
description: '发起 IDD 后台分析任务(提交即返 task_id;完成后平台自动回执,也可 diag_status 查询)。analysis_intent 选分析模式,由 IDD 对应 skill 执行(全 7 意图:深度诊断/稳定报告/快筛/DOE/经验挖掘/优化战役/改善建议)。数据来源三选一:① line+时间窗(平台 DAQ 快照);② data_path(诊断服务内文件);③ export_id(推荐,daq_export 数据集)。契约 auto=提交前 capabilities 定轨(v1 优先,老后端回退 legacy)。',
|
|
123
135
|
parameters: {
|
|
124
136
|
type: 'object',
|
|
125
137
|
properties: {
|
|
@@ -131,17 +143,22 @@ export default {
|
|
|
131
143
|
question: { type: 'string', description: '分析问题(缺省按意图自动生成情景化提示词;业务要求特殊时才覆写)' },
|
|
132
144
|
analysis_intent: {
|
|
133
145
|
type: 'string',
|
|
134
|
-
enum: ['deep-diagnosis', 'stability-report', 'quick-screen', 'doe-analysis', 'experience-mining', 'optimizer-campaign'],
|
|
135
|
-
description: '分析模式(缺省 deep-diagnosis)
|
|
146
|
+
enum: ['deep-diagnosis', 'stability-report', 'quick-screen', 'doe-analysis', 'experience-mining', 'optimizer-campaign', 'improvement-advisory'],
|
|
147
|
+
description: '分析模式(缺省 deep-diagnosis)。根因→deep-diagnosis;健康度评分→stability-report;异常清单→quick-screen;多因子试验→doe-analysis;调参经验→experience-mining;寻优推荐工况→optimizer-campaign;改善建议(A/B/C 分级+验证/回滚)→improvement-advisory',
|
|
136
148
|
},
|
|
137
149
|
scene: { type: 'string', description: '场景名(缺省 <line>_diag);场景为自由标签,分析管线按数据特征自适应' },
|
|
138
150
|
mode: { type: 'string', enum: ['async', 'sync'], description: 'async(缺省)=提交即返后台跑;sync=同步等待完成(最长 sync_timeout_s,超时自动转后台继续)。建议改用 wait/wait_seconds(语义更直白)' },
|
|
139
151
|
sync_timeout_s: { type: 'number', description: 'sync 模式等待上限秒(缺省 240,上限 540)' },
|
|
140
152
|
wait: { type: 'boolean', description: '是否等待结果(推荐):true=本次调用挂起直到任务终态——成功/失败都返回完整结果,任务未完不返回;false=提交即返 task_id 后台跑(等价 mode=async)' },
|
|
141
153
|
wait_seconds: { type: 'number', description: 'wait=true 的等待上限秒(缺省 600,上限 1800);窗口内未完则如实返回 running 态与 task_id,任务转后台继续并仍会自动回执' },
|
|
142
|
-
harness: { type: 'string', description: '分析引擎按次覆盖(omp/claude/mock
|
|
143
|
-
model: { type: 'string', description: '可选:引擎模型按次覆盖(合法性由 IDD
|
|
144
|
-
permission_mode: { type: 'string', description: '可选:引擎权限模式按次覆盖(
|
|
154
|
+
harness: { type: 'string', description: '分析引擎按次覆盖(omp/claude/mock;缺省用插件设置,推荐 omp)' },
|
|
155
|
+
model: { type: 'string', description: '可选:引擎模型按次覆盖(合法性由 IDD 校验;external v1 无此字段时忽略)' },
|
|
156
|
+
permission_mode: { type: 'string', description: '可选:引擎权限模式按次覆盖(external v1 无此字段时忽略)' },
|
|
157
|
+
ontology_mode: { type: 'string', enum: ['auto', 'full', 'reuse', 'extend'], description: '本体策略(仅 deep-diagnosis/stability-report/quick-screen/doe-analysis;其它意图传了会被 IDD 拒绝)' },
|
|
158
|
+
ontology_scene: { type: 'string', description: '本体场景名(可选,配合 ontology_mode)' },
|
|
159
|
+
ontology_source: { type: 'string', description: '本体来源(可选,配合 ontology_mode;如已有本体文件)' },
|
|
160
|
+
preprocessing_mode: { type: 'string', enum: ['single_primary', 'integrate_merge'], description: '预处理模式(仅 stability-report:single_primary=单主数据源/integrate_merge=多源合并)' },
|
|
161
|
+
report_language: { type: 'string', enum: ['zh', 'en'], description: '报告语言(缺省 zh)' },
|
|
145
162
|
},
|
|
146
163
|
required: [],
|
|
147
164
|
},
|
|
@@ -178,30 +195,34 @@ export default {
|
|
|
178
195
|
let dataPaths
|
|
179
196
|
let via = ''
|
|
180
197
|
let manifest = null
|
|
198
|
+
// 数据集所属产线(manifest.lines[0]):export 模式若未显式传 line,用它做产线锁与归因,
|
|
199
|
+
// 避免所有离线数据集都挤在 'offline-data' 单锁上,也让 diag_stop/diag_chat 的产线授权可判定。
|
|
200
|
+
let datasetLine = ''
|
|
181
201
|
if (exportId) {
|
|
182
202
|
const up = await uploadExportDataset(ctx, exportId)
|
|
183
203
|
if (!up.ok) return { text: up.error, isError: true }
|
|
184
204
|
dataPaths = up.dataPaths
|
|
185
205
|
manifest = up.manifest
|
|
206
|
+
datasetLine = String((Array.isArray(manifest?.lines) ? manifest.lines[0]?.lineId : '') ?? '').trim()
|
|
186
207
|
const nodeCount = Array.isArray(manifest?.nodes) ? manifest.nodes.length : dataPaths.length - 1
|
|
187
208
|
const win = manifest?.window ? `窗口 ${String(manifest.window.from ?? '').slice(0, 16)} ~ ${String(manifest.window.to ?? '').slice(0, 16)}` : ''
|
|
188
209
|
via = `数据集 ${up.folder}(${nodeCount} 节点全量时序 + manifest,${win})`
|
|
189
210
|
}
|
|
190
211
|
|
|
191
|
-
//
|
|
212
|
+
// 问题缺省:export 数据集模式自动组题(带节点数与场景备注);其余模式留空,
|
|
213
|
+
// 由 startDiagnosis 按 analysis_intent 生成对应模板(否则稳定性/快筛等意图
|
|
214
|
+
// 的 objective 会被"深度根因诊断"文案污染 —— 实测 v2.4 前一直如此)。
|
|
192
215
|
let question = args.question ? String(args.question) : ''
|
|
193
|
-
if (!question) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
question = `${lineNames} 产线数据集深度根因诊断(${via})${note}`
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
question = `${line || 'offline-data'} 产线该时窗数据深度根因诊断`
|
|
201
|
-
}
|
|
216
|
+
if (!question && manifest) {
|
|
217
|
+
const lineNames = (Array.isArray(manifest.lines) ? manifest.lines : []).map(l => l?.lineName || l?.lineId).filter(Boolean).join('、') || line || 'offline'
|
|
218
|
+
const note = manifest.note ? `;场景备注:${String(manifest.note).slice(0, 200)}` : ''
|
|
219
|
+
question = `${lineNames} 产线数据集分析(${via})${note}`
|
|
202
220
|
}
|
|
203
221
|
const r = await startDiagnosis(ctx, {
|
|
204
|
-
line: line || 'offline-data',
|
|
222
|
+
line: line || datasetLine || 'offline-data',
|
|
223
|
+
// 授权作用域:显式 line 才纳入产线可读面;纯离线数据集(lineScope='')不按产线拒,
|
|
224
|
+
// 其读取面已由 daq_export/数据集归属约束。stop/chat 用 lineScope 判定。
|
|
225
|
+
lineScope: line,
|
|
205
226
|
fromMs, toMs,
|
|
206
227
|
question,
|
|
207
228
|
scene: args.scene ? String(args.scene) : '',
|
|
@@ -212,58 +233,84 @@ export default {
|
|
|
212
233
|
analysisIntent: args.analysis_intent ? String(args.analysis_intent) : undefined,
|
|
213
234
|
model: args.model ? String(args.model) : undefined,
|
|
214
235
|
permissionMode: args.permission_mode ? String(args.permission_mode) : undefined,
|
|
236
|
+
ontologyMode: args.ontology_mode ? String(args.ontology_mode) : undefined,
|
|
237
|
+
ontologyScene: args.ontology_scene ? String(args.ontology_scene) : undefined,
|
|
238
|
+
ontologySource: args.ontology_source ? String(args.ontology_source) : undefined,
|
|
239
|
+
preprocessingMode: args.preprocessing_mode ? String(args.preprocessing_mode) : undefined,
|
|
240
|
+
reportLanguage: args.report_language ? String(args.report_language) : undefined,
|
|
215
241
|
// 归因(分发层注入的调用方上下文):诊断完成后平台据此把结果回执给发起 Agent
|
|
216
242
|
agentId: agent?.agentId ?? '',
|
|
217
243
|
channelId: agent?.channelId ?? '',
|
|
218
244
|
})
|
|
219
245
|
if (!r.ok) return { text: r.error, isError: true }
|
|
220
246
|
if (!via) via = dataPathDirect ? `离线数据 ${r.csvPath}` : `产线 ${line} 窗口 ${new Date(fromMs).toISOString()} ~ ${new Date(toMs).toISOString()} 快照 ${r.rows} 行 × ${r.nodes} 节点`
|
|
247
|
+
const contractTag = `contract=${r.contract}`
|
|
248
|
+
const notes = Array.isArray(r.notes) && r.notes.length ? `\n注意:${r.notes.join(';')}` : ''
|
|
249
|
+
const base = baseOf(ctx)
|
|
250
|
+
|
|
251
|
+
/** 按 run 契约轮询一次远端状态(等待循环与 sweep 同源语义) */
|
|
252
|
+
const pollOnce = async () => {
|
|
253
|
+
if (r.contract === 'v1') {
|
|
254
|
+
const q = await v1Task(ctx, r.taskId || r.runId, 8000)
|
|
255
|
+
if (!q.ok) {
|
|
256
|
+
const e = new Error(mapV1Error(q, { base: base ?? '' }))
|
|
257
|
+
e.status = q.status
|
|
258
|
+
throw e
|
|
259
|
+
}
|
|
260
|
+
return q.body?.data ?? {}
|
|
261
|
+
}
|
|
262
|
+
return (await jget(ctx, `${base}/api/diagnosis/tasks/${encodeURIComponent(r.runId)}`, 8000)).data ?? {}
|
|
263
|
+
}
|
|
221
264
|
|
|
222
265
|
// 等待语义:wait=true 显式挂起到终态(成功/失败都给完整结果);兼容旧 mode=sync。
|
|
223
266
|
// 挂起期间 Agent 的回合被本工具调用占住——结构上保证"任务未完不能标记完成"。
|
|
224
267
|
const wantWait = args.wait === true || (args.wait === undefined && args.wait_seconds === undefined && String(args.mode ?? '').toLowerCase() === 'sync')
|
|
225
|
-
if (wantWait) {
|
|
226
|
-
const base = baseOf(ctx)
|
|
268
|
+
if (wantWait && base) {
|
|
227
269
|
const timeoutS = args.wait === true
|
|
228
270
|
? Math.min(Math.max(Number(args.wait_seconds) || 600, 10), 1800)
|
|
229
271
|
: Math.min(Math.max(Number(args.sync_timeout_s) || 240, 10), 540)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return { text: `同步等待中止 task_id=${r.runId}:${lastPollError}。任务可能仍在后台运行;修复后可用 diag_status(run_id=${r.runId}) 查询,完成后平台仍会回执。`, isError: true }
|
|
245
|
-
}
|
|
272
|
+
const deadline = Date.now() + timeoutS * 1000
|
|
273
|
+
let lastPollError = ''
|
|
274
|
+
while (Date.now() < deadline) {
|
|
275
|
+
await new Promise(resolve => setTimeout(resolve, 5000))
|
|
276
|
+
let st = null
|
|
277
|
+
try {
|
|
278
|
+
st = await pollOnce()
|
|
279
|
+
lastPollError = ''
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
lastPollError = String(err?.message ?? err)
|
|
283
|
+
// 鉴权失败/任务不存在:继续等只会空耗到超时,直接如实返回
|
|
284
|
+
if ([401, 403, 404].includes(Number(err?.status ?? 0)) || /HTTP (401|403|404)/.test(lastPollError)) {
|
|
285
|
+
return { text: `同步等待中止 task_id=${r.runId}:${lastPollError}\n任务可能仍在后台运行;修复后用 diag_status(run_id=${r.runId}) 查询,完成后平台仍会回执。(${contractTag})`, isError: true }
|
|
246
286
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
287
|
+
}
|
|
288
|
+
const status = String(st?.status ?? r.status ?? 'running')
|
|
289
|
+
const norm = normalizeResult(st)
|
|
290
|
+
if (status === 'awaiting_input') {
|
|
291
|
+
// 不自称完成:如实返回需要人工介入,任务继续占锁(老化上限见插件设置)
|
|
292
|
+
return { text: `⏸ 分析任务 ${r.runId}(${via},${contractTag})进入 awaiting_input:等待人工介入(例如引擎权限确认)。本工具不再挂起;请在 IDD 控制台处理后用 diag_status(run_id=${r.runId}) 查结果(超过 ${awaitingMaxMinutesOf(ctx)} 分钟未处理将转 expired 并回执),或 diag_stop 停止。` }
|
|
293
|
+
}
|
|
294
|
+
if (status === 'completed') {
|
|
295
|
+
// 已同步拿到结果,认领回执防 sweep 补送重复
|
|
296
|
+
try {
|
|
297
|
+
const notify = await ctx.services.get('notify')
|
|
298
|
+
await notify?.claim?.('diag_run', r.runId)
|
|
257
299
|
}
|
|
258
|
-
|
|
259
|
-
|
|
300
|
+
catch { /* 未接线时忽略 */ }
|
|
301
|
+
const rep = norm.reportPath ?? '-'
|
|
302
|
+
return {
|
|
303
|
+
text: `✅ 同步诊断完成 task_id=${r.runId}(${via},${contractTag})\n评分=${norm.score ?? '-'} 结论=${norm.verdict ?? '-'}\nreport_md_path=${rep}${norm.reportUrl ? `\nreport_url=${norm.reportUrl}` : ''}\n总结:${String(norm.summary ?? '').slice(0, 800)}\n结果已存分析结果台账(diag_results / diag_result_get 可随时复查)。${notes}\n\n入库知识库:调用 diag_deposit(run_id=${r.runId})(一键入 aw-docs 文档库并检索自查);若要沉淀结构化经验,再用 kb_agent(action=ingest, 目标 aw-industrial)。`,
|
|
260
304
|
}
|
|
261
305
|
}
|
|
262
|
-
|
|
306
|
+
if (['failed', 'stopped', 'interrupted', 'expired'].includes(status)) {
|
|
307
|
+
return { text: `分析任务 ${r.runId} 以 ${status} 结束:${norm.error ?? '详见 diag_status'}(${contractTag})`, isError: true }
|
|
308
|
+
}
|
|
263
309
|
}
|
|
310
|
+
return { text: `已发起${intentLabel(r.intent)}任务 task_id=${r.runId}(${via},${contractTag})。等待 ${timeoutS}s 窗口内未完(仍在后台运行${lastPollError ? `(最近一次轮询失败:${lastPollError})` : ''})——任务结果会存入分析结果台账;完成后平台会自动把结果回执到你的信箱并唤醒你;也可 diag_status(run_id=${r.runId}) 主动查询。注入的分析问题:${r.question}${notes}` }
|
|
264
311
|
}
|
|
265
312
|
return {
|
|
266
|
-
text: `已发起「${intentLabel(r.intent)}」异步分析任务 task_id=${r.runId}(${via})。IDD 在后台以对应 skill 协议执行,Channel 无需等待——可继续其他任务;完成后平台会自动把结果回执到你的信箱并唤醒你(空闲时也可用 diag_status(run_id=${r.runId})
|
|
313
|
+
text: `已发起「${intentLabel(r.intent)}」异步分析任务 task_id=${r.runId}(${via},${contractTag})。IDD 在后台以对应 skill 协议执行,Channel 无需等待——可继续其他任务;完成后平台会自动把结果回执到你的信箱并唤醒你(空闲时也可用 diag_status(run_id=${r.runId}) 主动查询;完成后按指引把报告入库知识库)。注入的分析问题:${r.question}${notes}`,
|
|
267
314
|
}
|
|
268
315
|
}
|
|
269
316
|
catch (err) {
|
|
@@ -275,7 +322,7 @@ export default {
|
|
|
275
322
|
registerDiagnosticTool(ctx, {
|
|
276
323
|
name: 'diag_status',
|
|
277
324
|
label: '分析任务状态',
|
|
278
|
-
description: '查询后台分析任务进度:传 run_id 看单条实时状态(
|
|
325
|
+
description: '查询后台分析任务进度:传 run_id 看单条实时状态(完成时含评分/结论/总结/报告路径与在线 URL;awaiting_input 会提示需人工介入),不传看最近 5 条概要。适用全部 7 意图(深度诊断/稳定报告/快筛/DOE/经验挖掘/优化战役/改善建议)。',
|
|
279
326
|
parameters: {
|
|
280
327
|
type: 'object',
|
|
281
328
|
properties: {
|
|
@@ -297,23 +344,24 @@ export default {
|
|
|
297
344
|
}
|
|
298
345
|
const meta = ctx.kv.get(runKey(id))
|
|
299
346
|
const base = baseOf(ctx)
|
|
347
|
+
const contract = String(meta?.contract ?? contractModeOf(ctx))
|
|
300
348
|
let st = null
|
|
301
349
|
let remoteError = ''
|
|
302
350
|
if (base) {
|
|
303
351
|
try {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
score: st.result.score ?? null,
|
|
312
|
-
judge_verdict: st.result.verdict ?? null,
|
|
313
|
-
summary: st.result.summary ?? '',
|
|
314
|
-
report_path: st.result.report_md_path ?? st.report_path ?? null,
|
|
315
|
-
error_message: st.result.error ?? st.error_message ?? null,
|
|
352
|
+
if (contract === 'v1') {
|
|
353
|
+
// v1:任务条目自带 result/files(refreshTask 已聚合完成结果)
|
|
354
|
+
const q = await v1Task(ctx, meta?.taskId || id, 8000)
|
|
355
|
+
if (!q.ok) {
|
|
356
|
+
const e = new Error(mapV1Error(q, { base }))
|
|
357
|
+
e.status = q.status
|
|
358
|
+
throw e
|
|
316
359
|
}
|
|
360
|
+
st = q.body?.data ?? null
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
// legacy:v2.1 走任务管理面 /tasks/:id(result.report_md_path 为绝对路径)
|
|
364
|
+
st = (await jget(ctx, `${base}/api/diagnosis/tasks/${encodeURIComponent(id)}`, 8000)).data ?? null
|
|
317
365
|
}
|
|
318
366
|
}
|
|
319
367
|
catch (err) {
|
|
@@ -324,16 +372,23 @@ export default {
|
|
|
324
372
|
if (!st && !meta) {
|
|
325
373
|
return { text: `诊断 ${id} 不存在或诊断服务不可达${remoteError ? `(${remoteError})` : ''}。`, isError: true }
|
|
326
374
|
}
|
|
327
|
-
const status = st?.
|
|
375
|
+
const status = String(st?.status ?? st?.engineStatus ?? meta?.status ?? 'unknown')
|
|
376
|
+
const norm = st
|
|
377
|
+
? normalizeResult(st)
|
|
378
|
+
: normalizeResult({
|
|
379
|
+
result: { score: meta?.score, verdict: meta?.verdict, summary: meta?.summary, error: meta?.error },
|
|
380
|
+
files: { report_md_path: meta?.reportPath ?? null, report_md_url: meta?.reportUrl ?? null },
|
|
381
|
+
})
|
|
328
382
|
// 终态经轮询面亲自看到 → 认领结果所有权,取消平台的事后补送(先到先得)
|
|
329
|
-
if (
|
|
383
|
+
if (isTerminal(status)) {
|
|
330
384
|
const notify = await ctx.services.get('notify').catch(() => null)
|
|
331
385
|
notify?.claim?.('diag_run', id)
|
|
332
386
|
}
|
|
333
387
|
const parts = [
|
|
334
388
|
`run_id=${id}`,
|
|
389
|
+
`contract=${contract}`,
|
|
335
390
|
`name=${st?.name ?? meta?.name ?? '?'}`,
|
|
336
|
-
`产线=${meta?.line ?? st?.scene_name ?? '?'}`,
|
|
391
|
+
`产线=${meta?.line ?? st?.scene_name ?? st?.scene ?? '?'}`,
|
|
337
392
|
`意图=${meta?.intent ?? 'deep-diagnosis'}(${intentLabel(meta?.intent ?? 'deep-diagnosis')})`,
|
|
338
393
|
`状态=${status}`,
|
|
339
394
|
`来源=${meta?.source ?? '?'}`,
|
|
@@ -341,21 +396,27 @@ export default {
|
|
|
341
396
|
if (meta?.fromMs && meta?.toMs) parts.push(`窗口=${new Date(meta.fromMs).toISOString()} ~ ${new Date(meta.toMs).toISOString()}`)
|
|
342
397
|
if (meta?.question) parts.push(`问题=${meta.question}`)
|
|
343
398
|
if (status === 'completed') {
|
|
344
|
-
|
|
345
|
-
parts.push(
|
|
346
|
-
parts.push(
|
|
347
|
-
|
|
348
|
-
parts.push(`
|
|
399
|
+
parts.push(`评分=${norm.score ?? meta?.score ?? '-'}`)
|
|
400
|
+
parts.push(`结论=${norm.verdict ?? meta?.verdict ?? '-'}`)
|
|
401
|
+
if (norm.summary) parts.push(`总结=${String(norm.summary).slice(0, 600)}`)
|
|
402
|
+
parts.push(`report_md_path=${norm.reportPath ?? meta?.reportPath ?? '-'}`)
|
|
403
|
+
if (norm.reportUrl || meta?.reportUrl) parts.push(`report_url=${norm.reportUrl ?? meta?.reportUrl}`)
|
|
349
404
|
parts.push('')
|
|
350
|
-
parts.push('✅
|
|
351
|
-
parts.push(`
|
|
352
|
-
parts.push('
|
|
405
|
+
parts.push('✅ 分析完成,报告已就绪。入库 RAG 文档库(缺省 aw-docs)请调用 diag_deposit 工具:')
|
|
406
|
+
parts.push(` diag_deposit(run_id=${id}) → 返回 doc_path 与检索自查命中;同 run 重试幂等。`)
|
|
407
|
+
parts.push('需要结构化经验沉淀时再用 kb_agent(action=ingest,模式 async,目标 aw-industrial)。')
|
|
408
|
+
}
|
|
409
|
+
if (status === 'awaiting_input') {
|
|
410
|
+
const sinceMs = Number(meta?.awaitingSince ?? 0)
|
|
411
|
+
const waitedMin = sinceMs ? Math.round((Date.now() - sinceMs) / 60000) : 0
|
|
412
|
+
parts.push(`⏸ 等待人工介入(awaiting_input):${waitedMin ? `已等待 ${waitedMin} 分钟;` : ''}产线单飞锁保持;超过 ${awaitingMaxMinutesOf(ctx)} 分钟未处理将转 expired 并回执。`)
|
|
413
|
+
parts.push('处理方式:到 IDD 控制台完成人工确认后继续;或 diag_stop(run_id=…) 停止。')
|
|
353
414
|
}
|
|
354
|
-
if (
|
|
415
|
+
if (['failed', 'stopped', 'interrupted', 'expired'].includes(status)) parts.push(`错误=${norm.error ?? meta?.error ?? '-'}`)
|
|
355
416
|
if (!st) {
|
|
356
417
|
parts.push(`(远端查询失败:${remoteError || '诊断服务不可达'};以上为本地记录)`)
|
|
357
|
-
if (remoteError.includes('HTTP 404') && ['queued', 'running'].includes(String(meta?.status))) {
|
|
358
|
-
parts.push(
|
|
418
|
+
if ((remoteError.includes('HTTP 404') || remoteError.includes('不存在')) && ['queued', 'running', 'awaiting_input'].includes(String(meta?.status))) {
|
|
419
|
+
parts.push(`远端任务已不存在(可能被 IDD 清理或服务重启);sweep 将在连续 3 轮确认后把本地状态收敛为 ${contract === 'v1' ? 'expired' : 'failed'} 并回执,不会永久占用产线单飞锁。`)
|
|
359
420
|
}
|
|
360
421
|
}
|
|
361
422
|
return { text: parts.join('\n') }
|
|
@@ -366,6 +427,181 @@ export default {
|
|
|
366
427
|
},
|
|
367
428
|
})
|
|
368
429
|
|
|
430
|
+
// ── 工具 ×2:续聊 / 停止(WS-2 I7/I8;run 归属 + 产线可读面收敛) ──────────
|
|
431
|
+
const runMetaOrDeny = async (id, agent) => {
|
|
432
|
+
const meta = ctx.kv.get(runKey(id))
|
|
433
|
+
if (!meta) {
|
|
434
|
+
return { denied: { text: `run ${id} 不在本插件台账:只能对平台发起过的分析续聊/停止(用 diag_status 查 run_id)。`, isError: true } }
|
|
435
|
+
}
|
|
436
|
+
const line = String(meta.lineScope ?? meta.line ?? '').trim()
|
|
437
|
+
if (line && agent?.agentId) {
|
|
438
|
+
try {
|
|
439
|
+
const scope = await ctx.services.get('agentScope')
|
|
440
|
+
const readable = scope.readableLines(agent.agentId)
|
|
441
|
+
if (!readable.includes(line)) {
|
|
442
|
+
return { denied: { text: `产线「${line}」不在你的可读范围。你的可读产线:${readable.length ? readable.join(', ') : '(无)'}。`, isError: true } }
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
catch (err) {
|
|
446
|
+
return { denied: { text: `产线授权校验不可用,已拒绝本次操作:${err?.message ?? err}。`, isError: true } }
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return { meta }
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
registerDiagnosticTool(ctx, {
|
|
453
|
+
name: 'diag_chat',
|
|
454
|
+
label: '分析任务续聊',
|
|
455
|
+
description: '向一条诊断 run 发追问(claude/omp/goose/mock 走原生会话续聊,其它引擎受控重建)。run_id 来自 diag_run/diag_status。运行中的 run 会被 IDD 拒绝(RUN_NOT_IDLE:先 diag_stop 或等终态)。只读追问,不改产线。',
|
|
456
|
+
parameters: {
|
|
457
|
+
type: 'object',
|
|
458
|
+
properties: {
|
|
459
|
+
run_id: { type: 'string', description: '诊断 run_id(平台发起过的 run)' },
|
|
460
|
+
message: { type: 'string', description: '追问内容(如"把第 3 条告警的证据链展开")' },
|
|
461
|
+
},
|
|
462
|
+
required: ['run_id', 'message'],
|
|
463
|
+
},
|
|
464
|
+
roles: ['lead', 'worker'],
|
|
465
|
+
riskClass: 'read',
|
|
466
|
+
noRefs: true,
|
|
467
|
+
handler: async (args, agent) => {
|
|
468
|
+
try {
|
|
469
|
+
const id = String(args.run_id ?? '').trim()
|
|
470
|
+
const message = String(args.message ?? '').trim()
|
|
471
|
+
if (!id || !message) return { text: 'run_id 与 message 都必填。', isError: true }
|
|
472
|
+
const guard = await runMetaOrDeny(id, agent)
|
|
473
|
+
if (guard.denied) return guard.denied
|
|
474
|
+
const meta = guard.meta
|
|
475
|
+
const contract = String(meta.contract ?? contractModeOf(ctx))
|
|
476
|
+
if (contract !== 'v1') {
|
|
477
|
+
return { text: `续聊依赖 external v1 契约,该 run 为 legacy(contract=${contract})。请把插件设置 contract 设为 auto/v1 后重新 diag_run,再续聊。`, isError: true }
|
|
478
|
+
}
|
|
479
|
+
const r = await v1Chat(ctx, meta.runId || id, message)
|
|
480
|
+
if (!r.ok) return { text: `续聊失败:${mapV1Error(r, { base: baseOf(ctx) ?? '' })}`, isError: true }
|
|
481
|
+
const d = r.body?.data ?? {}
|
|
482
|
+
const resumed = d.resumed === true
|
|
483
|
+
return { text: `status=ok run_id=${id} delivered=${d.delivered} mode=${d.mode ?? '?'} resumed=${resumed}\n追问已投递${resumed ? '(原生会话续聊)' : '(受控重建:该引擎无原生 resume,IDD 会重放上下文)'}。` }
|
|
484
|
+
}
|
|
485
|
+
catch (err) {
|
|
486
|
+
return { text: `diag_chat 异常:${err?.message ?? err}`, isError: true }
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
})
|
|
490
|
+
|
|
491
|
+
registerDiagnosticTool(ctx, {
|
|
492
|
+
name: 'diag_stop',
|
|
493
|
+
label: '停止分析任务',
|
|
494
|
+
description: '停止一条运行中的诊断 run(契约自动路由 v1/legacy)。已终态时返回可读说明(无需再停)。写类操作:会记录操作者与 run 到平台审计,便于归因。停止后 sweep 仍会收敛状态并回执。',
|
|
495
|
+
parameters: {
|
|
496
|
+
type: 'object',
|
|
497
|
+
properties: {
|
|
498
|
+
run_id: { type: 'string', description: '诊断 run_id(平台发起过的 run)' },
|
|
499
|
+
},
|
|
500
|
+
required: ['run_id'],
|
|
501
|
+
},
|
|
502
|
+
roles: ['lead', 'worker'],
|
|
503
|
+
riskClass: 'write',
|
|
504
|
+
noRefs: true,
|
|
505
|
+
handler: async (args, agent) => {
|
|
506
|
+
try {
|
|
507
|
+
const id = String(args.run_id ?? '').trim()
|
|
508
|
+
if (!id) return { text: 'run_id 必填。', isError: true }
|
|
509
|
+
const guard = await runMetaOrDeny(id, agent)
|
|
510
|
+
if (guard.denied) return guard.denied
|
|
511
|
+
const meta = guard.meta
|
|
512
|
+
if (isTerminal(meta.status)) {
|
|
513
|
+
return { text: `run ${id} 已是终态(${meta.status}),无需停止。详情用 diag_status(run_id=${id})。` }
|
|
514
|
+
}
|
|
515
|
+
const contract = String(meta.contract ?? contractModeOf(ctx))
|
|
516
|
+
let r
|
|
517
|
+
if (contract === 'v1') {
|
|
518
|
+
r = await v1Stop(ctx, meta.runId || id)
|
|
519
|
+
if (!r.ok) {
|
|
520
|
+
const msg = mapV1Error(r, { base: baseOf(ctx) ?? '' })
|
|
521
|
+
return { text: `停止失败:${msg}`, isError: true }
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
const base = baseOf(ctx)
|
|
526
|
+
if (!base) return { text: 'diag.base_url 非法。', isError: true }
|
|
527
|
+
try {
|
|
528
|
+
await jpost(ctx, `${base}/api/diagnosis/stop/${encodeURIComponent(id)}`, {}, 15000)
|
|
529
|
+
}
|
|
530
|
+
catch (err) {
|
|
531
|
+
return { text: `停止失败:${String(err?.message ?? err)}`, isError: true }
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
ctx.kv.set(runKey(id), { ...meta, status: 'stopped', completedAt: Date.now(), deliverPending: Boolean(meta.agentId) })
|
|
535
|
+
await recordLineAudit({
|
|
536
|
+
actor: agent?.agentId ?? 'unknown', actorName: agent?.name ?? '', actorKind: 'agent',
|
|
537
|
+
action: 'diag.run.stop', kind: 'write', scope: 'system',
|
|
538
|
+
targetKind: 'run', targetId: id,
|
|
539
|
+
summary: `停止诊断 run(${meta.line ?? 'offline'},contract=${contract})`,
|
|
540
|
+
detail: { runId: meta.runId || id, taskId: meta.taskId ?? null, channelId: agent?.channelId ?? '', role: agent?.role ?? '' },
|
|
541
|
+
})
|
|
542
|
+
return { text: `status=stopped run_id=${id} contract=${contract}\n已停止该分析;状态收敛与回执由巡检完成(也可 diag_status 查询)。` }
|
|
543
|
+
}
|
|
544
|
+
catch (err) {
|
|
545
|
+
return { text: `diag_stop 异常:${err?.message ?? err}`, isError: true }
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
})
|
|
549
|
+
|
|
550
|
+
// ── 工具 ×1:诊断报告入库(WS-3;C1 闭环) ────────────────────────────────
|
|
551
|
+
registerDiagnosticTool(ctx, {
|
|
552
|
+
name: 'diag_deposit',
|
|
553
|
+
label: '诊断报告入库',
|
|
554
|
+
description: '把一条已完成的诊断报告一键入库 RAG 文档库(缺省 aw-docs)并做检索自查:返回 doc_path 与命中数。run_id 来自 diag_run/diag_status。写类:同 run 重试幂等(同名不重复建);报告为空可读失败、不落半截文档。经验沉淀仍用 kb_agent。',
|
|
555
|
+
parameters: {
|
|
556
|
+
type: 'object',
|
|
557
|
+
properties: {
|
|
558
|
+
run_id: { type: 'string', description: '已完成的诊断 run_id' },
|
|
559
|
+
kb: { type: 'string', description: '目标知识库名(缺省取 rag-bridge docs_kb=aw-docs)' },
|
|
560
|
+
title: { type: 'string', description: '文档标题(缺省 <line>_<intent>_<runId>;同名视为已入库)' },
|
|
561
|
+
},
|
|
562
|
+
required: ['run_id'],
|
|
563
|
+
},
|
|
564
|
+
roles: ['lead', 'worker'],
|
|
565
|
+
riskClass: 'write',
|
|
566
|
+
noRefs: true,
|
|
567
|
+
handler: async (args, agent) => {
|
|
568
|
+
try {
|
|
569
|
+
const id = String(args.run_id ?? '').trim()
|
|
570
|
+
if (!id) return { text: 'run_id 必填(已完成诊断的 run_id)。', isError: true }
|
|
571
|
+
const guard = await runMetaOrDeny(id, agent)
|
|
572
|
+
if (guard.denied) return guard.denied
|
|
573
|
+
const meta = guard.meta
|
|
574
|
+
const r = await depositRunToRag(ctx, {
|
|
575
|
+
runId: id,
|
|
576
|
+
meta,
|
|
577
|
+
kb: args.kb ? String(args.kb) : '',
|
|
578
|
+
title: args.title ? String(args.title) : '',
|
|
579
|
+
})
|
|
580
|
+
if (!r.ok) return { text: `诊断报告入库失败:${r.error}`, isError: true }
|
|
581
|
+
await recordLineAudit({
|
|
582
|
+
actor: agent?.agentId ?? 'unknown', actorName: agent?.name ?? '', actorKind: 'agent',
|
|
583
|
+
action: 'diag.report.deposit', kind: 'write', scope: 'system',
|
|
584
|
+
targetKind: 'run', targetId: id,
|
|
585
|
+
summary: `诊断报告入库 ${r.kbName}:${r.docPath}(${r.reportChars} 字符,检索命中=${r.verified})`,
|
|
586
|
+
detail: { runId: id, docPath: r.docPath, kbId: r.kbId, channelId: agent?.channelId ?? '', role: agent?.role ?? '' },
|
|
587
|
+
})
|
|
588
|
+
return {
|
|
589
|
+
text: [
|
|
590
|
+
`status=ok doc_path=${r.docPath} kb=${r.kbName} run_id=${id} chars=${r.reportChars} index=${r.indexState} tags=${r.tagsState} search=${r.verified ? 'hit' : 'miss'} hits=${r.hits} mode=${r.searchMode}`,
|
|
591
|
+
`✅ 报告已入库 ${r.kbName}(评分=${r.score ?? '-'} 结论=${r.verdict ?? '-'})。`,
|
|
592
|
+
r.verified
|
|
593
|
+
? `检索自查通过:${r.searchMode} 命中 doc_path(共 ${r.hits} 条候选)。`
|
|
594
|
+
: `检索自查未命中(索引可见性窗口);可稍后用 rag-bridge 的 kb_doc_search(query=标题) 复核,文档已落盘:${r.docPath}`,
|
|
595
|
+
'下一步:kb_doc_read(doc_path) 核对正文;需要结构化经验沉淀时用 kb_agent(action=ingest 入 aw-industrial)。',
|
|
596
|
+
].join('\n'),
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
catch (err) {
|
|
600
|
+
return { text: `diag_deposit 异常:${err?.message ?? err}`, isError: true }
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
})
|
|
604
|
+
|
|
369
605
|
// ── 工具 ×3:分析结果库(§16;默认关闭,results_enabled 开启) ────────────
|
|
370
606
|
// 可见性注意:结果库按 IDD Token 属主聚合,平台内不按产线隔离 —— 所以
|
|
371
607
|
// 读面默认只给 lead(worker 可在 handler 内按设置热放开)、写面双闸门(设置 + lead + IDD 属主校验)。
|
|
@@ -381,7 +617,7 @@ export default {
|
|
|
381
617
|
type: 'object',
|
|
382
618
|
properties: {
|
|
383
619
|
q: { type: 'string', description: '关键词(匹配 title/description/summary/scene/tags,大小写不敏感)' },
|
|
384
|
-
intent: { type: 'string', enum: ['deep-diagnosis', 'stability-report', 'quick-screen', 'doe-analysis', 'experience-mining', 'optimizer-campaign'], description: '按分析模式过滤' },
|
|
620
|
+
intent: { type: 'string', enum: ['deep-diagnosis', 'stability-report', 'quick-screen', 'doe-analysis', 'experience-mining', 'optimizer-campaign', 'improvement-advisory'], description: '按分析模式过滤' },
|
|
385
621
|
category_id: { type: 'string', description: '按结果分类 id 过滤(见 /results/categories)' },
|
|
386
622
|
tag: { type: 'string', description: '按标签精确匹配' },
|
|
387
623
|
scene: { type: 'string', description: '按场景名精确匹配' },
|
|
@@ -563,6 +799,14 @@ export default {
|
|
|
563
799
|
const runs = kvRuns(ctx)
|
|
564
800
|
const byStatus = {}
|
|
565
801
|
for (const { meta } of runs) byStatus[meta?.status ?? 'unknown'] = (byStatus[meta?.status ?? 'unknown'] ?? 0) + 1
|
|
802
|
+
// WS-4 S3:工具调用计数(ok/err 分账;与 rag-bridge health 同口径)
|
|
803
|
+
const toolCounters = {}
|
|
804
|
+
for (const [k, v] of Object.entries(ctx.kv.all())) {
|
|
805
|
+
const m = /^usage\.(.+)\.(ok|err)$/.exec(k)
|
|
806
|
+
if (!m) continue
|
|
807
|
+
toolCounters[m[1]] ??= { ok: 0, err: 0 }
|
|
808
|
+
toolCounters[m[1]][m[2]] = Number(v) || 0
|
|
809
|
+
}
|
|
566
810
|
const base = baseOf(ctx)
|
|
567
811
|
let remote
|
|
568
812
|
let tokenState = { configured: Boolean(diagTokenOf(ctx)), accepted: null }
|
|
@@ -612,12 +856,14 @@ export default {
|
|
|
612
856
|
return {
|
|
613
857
|
plugin: ctx.name,
|
|
614
858
|
base: base ?? String(ctx.kv.get('diag.base_url') || DEFAULT_BASE),
|
|
859
|
+
contract: contractModeOf(ctx),
|
|
615
860
|
harness: harnessOf(ctx),
|
|
616
861
|
auth: diagTokenOf(ctx) ? 'bearer' : 'anonymous',
|
|
617
862
|
/** Token 配置态 + 实测是否被上游接受(401/403 → false;网络不通 → null) */
|
|
618
863
|
token: tokenState,
|
|
619
864
|
remote,
|
|
620
865
|
runs: { total: runs.length, byStatus },
|
|
866
|
+
toolCounters,
|
|
621
867
|
}
|
|
622
868
|
})
|
|
623
869
|
|
|
@@ -729,6 +975,29 @@ export default {
|
|
|
729
975
|
}
|
|
730
976
|
const base = baseOf(ctx)
|
|
731
977
|
if (!base) return { success: false, error: 'diag.base_url 非法' }
|
|
978
|
+
const contract = String(meta?.contract ?? contractModeOf(ctx))
|
|
979
|
+
if (contract === 'v1') {
|
|
980
|
+
// v1:终态结果稳定可读(report_md 内联 + files.report_md_url);运行中 409
|
|
981
|
+
const q = await v1Result(ctx, meta?.taskId || runId, 15000)
|
|
982
|
+
if (!q.ok) {
|
|
983
|
+
if (q.status === 409) return { success: false, error: `诊断 ${runId} 尚未到终态(EXTERNAL_TASK_RUNNING),报告未就绪` }
|
|
984
|
+
return { success: false, error: mapV1Error(q, { base }) }
|
|
985
|
+
}
|
|
986
|
+
const d = q.body?.data ?? {}
|
|
987
|
+
if (String(d.status ?? '') !== 'completed') {
|
|
988
|
+
return { success: false, error: `诊断 ${runId} 状态 ${d.status ?? 'unknown'},报告未就绪` }
|
|
989
|
+
}
|
|
990
|
+
const norm = normalizeResult(d)
|
|
991
|
+
return {
|
|
992
|
+
success: true,
|
|
993
|
+
run_id: runId,
|
|
994
|
+
run_name: d.name ?? meta?.name ?? '',
|
|
995
|
+
report: {
|
|
996
|
+
content: norm.reportMd || '(报告正文未内联到结果信封;请用 url 打开完整报告)',
|
|
997
|
+
url: norm.reportUrl ? absoluteUrl(base, norm.reportUrl) : '',
|
|
998
|
+
},
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
732
1001
|
const st = (await jget(ctx, `${base}/api/diagnosis/tasks/${encodeURIComponent(runId)}`, 8000)).data ?? {}
|
|
733
1002
|
if (String(st.status ?? '') !== 'completed') {
|
|
734
1003
|
return { success: false, error: `诊断 ${runId} 状态 ${st.status ?? 'unknown'},报告未就绪` }
|
|
@@ -846,6 +1115,6 @@ export default {
|
|
|
846
1115
|
}
|
|
847
1116
|
})
|
|
848
1117
|
|
|
849
|
-
ctx.logger.info('diag-bridge
|
|
1118
|
+
ctx.logger.info('diag-bridge 就绪(v2.4):工具 diag_run/diag_status/diag_chat/diag_stop/diag_deposit/diag_results/diag_result_get/diag_result_annotate + 路由 health/runs/snapshot/report/results;external v1 定轨;轮询 15s 已启动')
|
|
850
1119
|
},
|
|
851
1120
|
}
|