mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-20 05:41:58 +00:00
可点击证据第二期:取数链路打通、问数据的答案逐段可点;发布前自动修复
一、可点击证据第二期
取数链路
- 智能体、工具节点、代码节点、知识检索取数时都记进证据台账;报告目录按台账编出 Q1… / K1…
- 报告可以引用快照里的一格([[v:Q1.r0.gmv]]),也可以由系统从快照生成整张表([[table:Q1 cols=… rows=0-4]]),
表里每一格都是可点的片段;取值一律以快照为准,取回快照时复验哈希
- 口径卡表达式新增 cell(x, row, column),lineage 精确到单元格
- 智能体开 cite_fields(配合 output_schema)后,循环结束做一次结构化抽取,每个字段标出取自哪次查询的哪一格,
再到快照里核对:一致记 verified;不一致以快照为准并告警;查不到的记为空值,永远不兜底成 0
- 代码节点新增 evidence_role(source / compute)和 code_sha;沙箱算出来的数不能被报告直接引用,要进口径卡
- 查询快照记下列类型,文本列按文本渲染(年份 "2026" 不再显示成「2,026」)
- 升级前发起的运行(停在审批上的)一律走旧逻辑:新的 task 只追加在循环之后,恢复时不会错号
证据接口与面板
- 片段链接上查询步骤:SQL、被引用的行加前后各 2 行、高亮到格;数据源可设 mask_columns 遮罩列,
遮罩在查询时记进快照,数据源事后改名或删除也照样遮罩(在有身份体系之前,遮罩只减少暴露,不是安全边界)
- 输入来源写明核对结果(与快照一致 / 模型报的值和快照不一致 / 没查到记为空);口径卡缺输入时也给出完整的链
- 受管出具要在契约里声明 cells 才能引用单元格;受管与否记在所钉版本上,改画布不再让受管版本的正式运行降级
- 口径卡可以用 caliber_from 钉住另一个已发布工作流里的口径卡,上游有新版本时按 upgrade_policy 处置,
和子工作流同一套规则;子工作流节点也补上了升版处置的配置项
Copilot、校验与报错
- 问数据的答案里有数字时,搭 input → 智能体 → 报告 → 出口,报告直接引用查过的单元格
- 写 SQL 前核对数据源的表结构,SQL 里出现表结构里没有的列会被打回
- 不再搭「智能体文字 → 转换节点解析 JSON」这种图;转换节点的 JSON 报错分清是上游模型写坏了、
模板里裸插了模型文字(给出 | json 的改法),还是模板本身写错了
- 工具节点遇到「查询失败」「SQL 被拒绝」判为失败;发起运行前检查绑定的工具是否存在,不存在时直接拒绝并给出入口
二、发布前自动修复
- 问题带上机器编号(code)和修复 id;新增只读接口 POST /api/workflows/{id}/publish-check 和 /autofix
- 修复分三类:答案唯一、不降低要求的一键修复;要人拿主意的给选项(不替人选);结构性问题交给 Copilot
- 一律先预览,不自动保存、不自动发布;删节点、删契约、放宽审批、关掉 strict、改级别等降低要求的改动一律拒绝,
Copilot 的方案也要过这一关;应用后重跑检查,错误必须变少且不能冒出新的
- 发布弹窗打开就先检查;问题面板新增「发布前检查」,平时就能看到、就地修掉
- 门禁修正:契约有 report_from 时不再要求 narrative(模板⑨可以发成受管);全图默认审批为「全部放行」时同样拦下
- 修掉画布保存会抹掉全图默认(defaults)的老问题:以前任何一次保存都会把它清空,审批 always 因此被悄悄放宽
验证(沙箱):tsc 干净,生产构建通过,pytest 2268 passed(两遍),check-all 17 项检查、3915 项全过
(新增 check-publish);关键行为做了变异验证、全部抓到。
This commit is contained in:
@@ -11,10 +11,12 @@
|
||||
* 不存在)。其余几种先把外观定下,后续期接上时不用再各处补。
|
||||
*/
|
||||
|
||||
import { EVIDENCE_STATE_LABEL, EVIDENCE_TEXT, evidenceTally } from './terms'
|
||||
import { EVIDENCE_KIND_LABEL, EVIDENCE_STATE_LABEL, EVIDENCE_TEXT, UPGRADE_POLICY_LABEL, evidenceTally } from './terms'
|
||||
import { NONE, formatNumber, shortId } from './format'
|
||||
import type {
|
||||
EvidenceBlock, EvidenceDocData, EvidenceFieldRef, EvidenceGraph, EvidenceSeal, EvidenceSegment,
|
||||
EvidenceSegmentDetail, EvidenceStep, EvidenceUnit, EvidenceViolation, ReviewResult,
|
||||
EvidenceBlock, EvidenceCaliberSource, EvidenceCaliberUpgrade, EvidenceDocData, EvidenceFieldRef, EvidenceGraph,
|
||||
EvidenceInput, EvidenceLocator, EvidenceSeal, EvidenceSegment, EvidenceSegmentDetail, EvidenceStep, EvidenceUnit,
|
||||
EvidenceViolation, ReviewResult,
|
||||
} from '../types'
|
||||
import type { MarkSpec } from '../run/Markdown'
|
||||
|
||||
@@ -54,7 +56,7 @@ export const EVIDENCE_STATE: Record<EvidenceStateCode, EvidenceStateMeta> = {
|
||||
code: 'deterministic', label: EVIDENCE_STATE_LABEL.deterministic, line: 'solid', glyph: '',
|
||||
color: 'var(--st-done)', decoration: mix('--st-done', 60), soft: 'var(--st-done-soft)',
|
||||
alert: false, phase: 1,
|
||||
hint: '数字由系统从口径卡取值、按口径卡的格式渲染,不是模型写的',
|
||||
hint: '由系统从证据(口径卡、查询快照、运行输入)里取值、按确定的规则渲染,不是模型写的',
|
||||
},
|
||||
supported: {
|
||||
code: 'supported', label: EVIDENCE_STATE_LABEL.supported, line: 'badge', glyph: '◆',
|
||||
@@ -123,19 +125,210 @@ export function unitText(unit: Pick<EvidenceUnit, 'segments'>): string {
|
||||
return (unit.segments ?? []).filter((s) => s.kind !== 'structural').map((s) => s.text).join('')
|
||||
}
|
||||
|
||||
/** 片段的来源说一句:「口径卡指标 环比增幅」「运行输入 week」 */
|
||||
/**
|
||||
* 片段的来源说一句:「口径卡指标 环比增幅」「运行输入 week」「查询 Q3 · 第 6 行 · amount」。
|
||||
* 单元格先看 cite 的种类:查询条目在目录里是 query,引用它的一格是 cell
|
||||
*/
|
||||
export function sourceOf(seg: EvidenceSegment, doc?: Pick<EvidenceDocData, 'catalog'> | null): string {
|
||||
const cite = seg.cite
|
||||
if (!cite) return ''
|
||||
const entry = cite.alias ? doc?.catalog?.[cite.alias] : undefined
|
||||
if (cite.kind === 'cell' || (cite.kind !== 'metric' && cite.kind !== 'input' && entry?.kind === 'query')) {
|
||||
const where = locatorText(cite.locator)
|
||||
return [EVIDENCE_TEXT.query(cite.alias ?? ''), where].filter(Boolean).join(' · ')
|
||||
}
|
||||
if (cite.kind === 'metric' || entry?.kind === 'metric') {
|
||||
const name = entry?.name ?? cite.locator?.metric ?? cite.ref ?? ''
|
||||
return name ? `口径卡指标 ${name}` : '口径卡指标'
|
||||
return name ? `${EVIDENCE_KIND_LABEL.metric} ${name}` : EVIDENCE_KIND_LABEL.metric
|
||||
}
|
||||
if (cite.kind === 'input' || entry?.kind === 'input') {
|
||||
return `运行输入 ${entry?.locator?.field ?? cite.locator?.field ?? cite.ref ?? ''}`.trim()
|
||||
return `${EVIDENCE_KIND_LABEL.input} ${entry?.locator?.field ?? cite.locator?.field ?? cite.ref ?? ''}`.trim()
|
||||
}
|
||||
return cite.alias ?? cite.ref ?? ''
|
||||
const kind = cite.kind ? EVIDENCE_KIND_LABEL[cite.kind] : ''
|
||||
return [kind, cite.alias ?? cite.ref].filter(Boolean).join(' ')
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询快照里的位置怎么说:「第 6 行 · amount」「第 1–5 行 · amount」「第 1–5 行 · week、amount」。
|
||||
* 行号给人看从 1 数(引用原文 Q3.r5 里的 r5 从 0 数,面板另把原文摆出来)
|
||||
*/
|
||||
export function locatorText(loc: EvidenceLocator | null | undefined): string {
|
||||
if (!loc) return ''
|
||||
const ints = (v: unknown) => (typeof v === 'number' && Number.isInteger(v) && v >= 0 ? v : null)
|
||||
let rows = ''
|
||||
const row = ints(loc.row)
|
||||
if (row != null) rows = `第 ${formatNumber(row + 1)} 行`
|
||||
else if (Array.isArray(loc.rows) && loc.rows.length) {
|
||||
const a = ints(loc.rows[0])
|
||||
const b = ints(loc.rows[loc.rows.length - 1])
|
||||
if (a != null && b != null) rows = a === b ? `第 ${formatNumber(a + 1)} 行` : `第 ${formatNumber(a + 1)}–${formatNumber(b + 1)} 行`
|
||||
}
|
||||
const cols = typeof loc.column === 'string' && loc.column ? loc.column
|
||||
: loc.columns && typeof loc.columns === 'object' ? Object.values(loc.columns).filter((c) => typeof c === 'string').join('、')
|
||||
: ''
|
||||
return [rows, cols].filter(Boolean).join(' · ')
|
||||
}
|
||||
|
||||
/** 证据里的值怎么写:数带千分位、不丢小数;布尔写是否;拿不到写「—」 */
|
||||
export function evidenceValue(v: unknown): string {
|
||||
if (v == null || v === '') return NONE
|
||||
if (typeof v === 'number') return Number.isFinite(v) ? v.toLocaleString('en-US', { maximumFractionDigits: 20 }) : String(v)
|
||||
if (typeof v === 'boolean') return v ? '是' : '否'
|
||||
if (typeof v === 'object') return JSON.stringify(v)
|
||||
return String(v)
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询步骤的窗口:接口只给被引用的行加前后各 2 行。
|
||||
*
|
||||
* - offset:rows[0] 在快照里是第几行;没给就当从 0 开始、也不说位置
|
||||
* - marks:要高亮的行,换算成窗口里的下标。highlight.rows 按快照行号给(方案第 5 节);
|
||||
* 全都落在窗口里才这么认,否则看它们是不是本来就是窗口下标(row_offset 之前的号、老接口)
|
||||
* - windowed:窗口没盖住整份快照,要说「仅显示被引用的行及前后各 2 行」
|
||||
*/
|
||||
export function queryWindow(step: Pick<EvidenceStep,
|
||||
'rows' | 'columns' | 'row_offset' | 'row_index' | 'total_rows' | 'highlight'>): {
|
||||
columns: string[]; rows: unknown[][]
|
||||
/** 每一行在快照里是第几行(从 0 数);不知道时是 null */
|
||||
index: number[] | null
|
||||
total: number | null
|
||||
marks: number[]; cols: string[]
|
||||
/** 精确到格的高亮:[窗口下标, 列名];接口没给时 null,按 marks × cols 画 */
|
||||
cells: [number, string][] | null
|
||||
windowed: boolean
|
||||
/** 「第 4–8、10–12 行」:窗口在快照里的位置,从 1 数;不知道时 '' */
|
||||
span: string
|
||||
} {
|
||||
const rows = Array.isArray(step.rows) ? step.rows.filter(Array.isArray) as unknown[][] : []
|
||||
const columns = Array.isArray(step.columns) ? step.columns.map(String) : []
|
||||
const int = (v: unknown) => (typeof v === 'number' && Number.isInteger(v) && v >= 0 ? v : null)
|
||||
const total = int(step.total_rows)
|
||||
// 行号:row_index 一行一个(窗口可以不连续)最准;只有 row_offset 时按连续的算
|
||||
const given = Array.isArray(step.row_index) ? step.row_index.map(int) : null
|
||||
const offset = int(step.row_offset)
|
||||
const index = given && given.length === rows.length && given.every((r) => r != null) ? given as number[]
|
||||
: offset != null ? rows.map((_, i) => offset + i)
|
||||
: null
|
||||
const toWindow = (r: number): number => {
|
||||
if (index) {
|
||||
const at = index.indexOf(r)
|
||||
if (at >= 0) return at
|
||||
}
|
||||
return -1
|
||||
}
|
||||
const inWindow = (r: number) => r >= 0 && r < rows.length
|
||||
// 行号按快照认(方案第 5 节),认得出几个标几个:窗口被截到 MAX_WINDOW_ROWS 时后面几行不在窗口里,
|
||||
// 不能因此一行都不标。一个都认不出、却都落在窗口里的,当成窗口下标(老接口);认不出的是 -1
|
||||
const place = (list: number[]): number[] | null => {
|
||||
const hit = list.map(toWindow)
|
||||
return hit.some((i) => i >= 0) ? hit : list.every(inWindow) ? list : null
|
||||
}
|
||||
const wanted = (Array.isArray(step.highlight?.rows) ? step.highlight.rows : []).map(int).filter((r): r is number => r != null)
|
||||
const marks = ((wanted.length && place(wanted)) || []).filter((i) => i >= 0)
|
||||
const cols = (Array.isArray(step.highlight?.cols) ? step.highlight.cols : []).map(String).filter((c) => columns.includes(c))
|
||||
const rawCells = (Array.isArray(step.highlight?.cells) ? step.highlight.cells : [])
|
||||
.filter((c) => Array.isArray(c) && int(c[0]) != null && columns.includes(String(c[1])))
|
||||
const cellRows = rawCells.length ? place(rawCells.map((c) => c[0] as number)) : null
|
||||
const placed = cellRows ? rawCells.map((c, i) => [cellRows[i], String(c[1])] as [number, string]).filter(([r]) => r >= 0) : []
|
||||
const cells = placed.length ? placed : null
|
||||
const windowed = !!index && total != null && index.length < total
|
||||
return { columns, rows, index, total, marks, cols, cells, windowed, span: index ? spanText(index) : '' }
|
||||
}
|
||||
|
||||
/** [3,4,5,6,7,9,10,11] → 「第 4–8、10–12 行」(从 1 数) */
|
||||
function spanText(index: number[]): string {
|
||||
if (!index.length) return ''
|
||||
const sorted = [...index].sort((a, b) => a - b)
|
||||
const parts: string[] = []
|
||||
let start = sorted[0]
|
||||
let prev = sorted[0]
|
||||
for (const r of [...sorted.slice(1), Number.NaN]) {
|
||||
if (r === prev + 1) { prev = r; continue }
|
||||
parts.push(start === prev ? formatNumber(start + 1) : `${formatNumber(start + 1)}–${formatNumber(prev + 1)}`)
|
||||
start = r
|
||||
prev = r
|
||||
}
|
||||
return `第 ${parts.join('、')} 行`
|
||||
}
|
||||
|
||||
/**
|
||||
* 这个输入对应链里的哪一个查询步骤:先按快照工件认,再按接口补的全局编号(input.query、
|
||||
* input.cell 的前缀)认。agent 字段的 ref 是那个节点内部的编号,不拿它对。认不出返回 -1
|
||||
*/
|
||||
export function queryOf(
|
||||
input: Pick<EvidenceInput, 'artifact' | 'query' | 'cell'>, queries: Pick<EvidenceStep, 'artifact' | 'alias'>[],
|
||||
): number {
|
||||
if (input.artifact) {
|
||||
const i = queries.findIndex((q) => q.artifact === input.artifact)
|
||||
if (i >= 0) return i
|
||||
}
|
||||
const alias = input.query || (typeof input.cell === 'string' ? input.cell.split('.')[0] : '')
|
||||
return alias ? queries.findIndex((q) => q.alias === alias) : -1
|
||||
}
|
||||
|
||||
export type SourceTone = 'ok' | 'warn' | 'alert' | 'muted'
|
||||
|
||||
/**
|
||||
* 输入来源那一行说什么、多醒目。
|
||||
*
|
||||
* - agent 字段(开了 cite_fields):与快照一致 / 模型报 X 快照是 Y 已按快照取值 / 没查到记为空;
|
||||
* unresolved 和 missing(模型写了 from: null)同一种说法:值都是空的,没有兜底成 0
|
||||
* - cell() 取数:与快照一致 / 算的时候用的值和快照不一样(值没被换掉,照实说)/ 核对不到
|
||||
* - 代码节点:取数角色提醒(核对不到快照),计算角色醒目(沙箱里的算术不该绕开口径卡)
|
||||
* - 其余(运行输入、老运行):一期的 ok / missing
|
||||
*/
|
||||
export function inputSource(input: EvidenceInput): { tone: SourceTone; text: string; reason?: string } {
|
||||
const status = input.status ?? ''
|
||||
if (input.via === 'agent_field') {
|
||||
if (status === 'verified') return { tone: 'ok', text: EVIDENCE_TEXT.sourceVerified }
|
||||
if (status === 'mismatch') {
|
||||
return { tone: 'warn', text: EVIDENCE_TEXT.sourceMismatch(evidenceValue(input.model_value), evidenceValue(input.value)) }
|
||||
}
|
||||
return { tone: 'warn', text: EVIDENCE_TEXT.sourceEmpty, reason: input.reason || undefined }
|
||||
}
|
||||
if (input.via === 'tool_cell') {
|
||||
if (status === 'verified') return { tone: 'ok', text: EVIDENCE_TEXT.sourceVerified }
|
||||
if (status === 'mismatch') {
|
||||
return { tone: 'warn', text: EVIDENCE_TEXT.cellMismatch(evidenceValue(input.value),
|
||||
evidenceValue(input.snapshot_value !== undefined ? input.snapshot_value : input.value)) }
|
||||
}
|
||||
if (input.value == null) return { tone: 'warn', text: EVIDENCE_TEXT.sourceEmpty, reason: input.reason || undefined }
|
||||
return { tone: 'warn', text: EVIDENCE_TEXT.cellUnresolved, reason: input.reason || undefined }
|
||||
}
|
||||
if (input.via === 'code') {
|
||||
return input.role === 'source'
|
||||
? { tone: 'warn', text: EVIDENCE_TEXT.codeSource(input.node_id ?? '') }
|
||||
: { tone: 'alert', text: EVIDENCE_TEXT.codeCompute(input.node_id ?? '') }
|
||||
}
|
||||
if (status === 'missing' || input.value == null) return { tone: 'warn', text: EVIDENCE_TEXT.inputMissing }
|
||||
return { tone: 'muted', text: '' }
|
||||
}
|
||||
|
||||
/** 值得在「输入来源」里单独列一行的输入:能核对到快照的、代码节点的、缺的 */
|
||||
export const notableInput = (input: EvidenceInput): boolean =>
|
||||
input.via === 'agent_field' || input.via === 'tool_cell' || input.via === 'code'
|
||||
|| input.status === 'missing' || input.value == null
|
||||
|
||||
/**
|
||||
* 口径卡钉在哪:「口径卡「周报口径」v3,来自「销售周报」v5」。工作流名接口没给就按目录找,
|
||||
* 再没有就写工作流 id 的前几位——不写 undefined
|
||||
*/
|
||||
export function caliberSourceText(
|
||||
caliber: string | undefined, version: string | undefined,
|
||||
from: EvidenceCaliberSource | null | undefined, workflowName?: string,
|
||||
): string | null {
|
||||
if (!from || typeof from !== 'object' || (!from.workflow_id && !from.workflow_name)) return null
|
||||
const wf = from.workflow_name || workflowName || (from.workflow_id ? shortId(from.workflow_id, 12) : NONE)
|
||||
const v = from.workflow_version != null && from.workflow_version !== '' ? `v${String(from.workflow_version).replace(/^v/, '')}` : ''
|
||||
return EVIDENCE_TEXT.caliberFrom(caliber ?? '', version ?? '', wf, v)
|
||||
}
|
||||
|
||||
/** 升版处置那一句:「上游已有 v6,按「并排双印新旧口径」处置」。没有升版(null、没写 latest / policy)返回 null */
|
||||
export function caliberUpgradeText(up: EvidenceCaliberUpgrade | null | undefined): string | null {
|
||||
if (!up || typeof up !== 'object' || (!up.policy && !up.policy_label)) return null
|
||||
const latest = up.latest != null && String(up.latest) !== '' ? `v${String(up.latest).replace(/^v/, '')}` : null
|
||||
const policy = up.policy_label || (up.policy ? UPGRADE_POLICY_LABEL[up.policy] ?? up.policy : '')
|
||||
return EVIDENCE_TEXT.caliberUpgrade(latest, policy)
|
||||
}
|
||||
|
||||
/** 无证据的原因:裸数字,还是引用解析不了(带后端给的人话原因) */
|
||||
|
||||
@@ -36,6 +36,13 @@ export interface RunErrorExplain {
|
||||
fixFirst?: boolean
|
||||
/** fix 的站内地址,比笼统的「去工具库」更准:直接打开要改的那一项 */
|
||||
fixTo?: string
|
||||
/** 入口上写什么(「去数据页接入」)。不给就按 fix 的默认说法 */
|
||||
fixLabel?: string
|
||||
/**
|
||||
* 该去改的节点(名字)和出错的不是同一个:整形节点解析上游的文字失败,毛病在上游那个
|
||||
* 模型节点,打开整形节点的设置什么也改不了
|
||||
*/
|
||||
fixNode?: string
|
||||
/** 原文,放进「技术细节」 */
|
||||
raw: string
|
||||
}
|
||||
@@ -61,6 +68,58 @@ export function stripClassPrefix(text: string): string {
|
||||
return s.trim()
|
||||
}
|
||||
|
||||
/** 后端 io.TEMPLATE_HINT:模板渲染出来不是合法 JSON、又说不出是哪一处时的老说法 */
|
||||
const TEMPLATE_HINT = '检查模板里的引号、逗号,字符串值要用 | json 过滤器输出'
|
||||
|
||||
/** 后端 app/api/runs.py 的 TOOL_MISSING:发起运行时发现绑定的工具在本机不存在 */
|
||||
export const RUN_TOOL_MISSING = 'run_tool_missing'
|
||||
const DATA_TOOL = /^db_(?:query|schema)__/
|
||||
|
||||
/**
|
||||
* 「绑定的工具在本机不存在:「X」(调用工具)绑的 db_query__nope;「团队」的成员「研究员」绑的 mcp:a/b。
|
||||
* 去数据页接入,或在节点里重新选」。数据源工具(db_query__ / db_schema__)要去数据页接入,自定义和
|
||||
* MCP 工具去工具页;两种都缺时入口按第一个缺的走,话里两边都说到
|
||||
*/
|
||||
function explainToolMissing(plain: string, raw: string, coded = false): RunErrorExplain | null {
|
||||
const m = plain.match(/^绑定的工具在本机不存在[::]\s*([\s\S]+)$/)
|
||||
// 带着机读码、话却改了说法:照样按这一类讲,名字认不出就只给工具页
|
||||
if (!m && !coded) return null
|
||||
const body = (m ? m[1] : plain).trim()
|
||||
const cut = body.lastIndexOf('。')
|
||||
const list = (cut >= 0 ? body.slice(0, cut) : body).trim()
|
||||
const advice = cut >= 0 ? body.slice(cut + 1).trim() : ''
|
||||
// 超过 8 处时后端在最后一个名字后面接「等 N 处」:那个「等」不是名字的一部分
|
||||
const names = [...list.matchAll(/绑的\s*([^\s;;,,。]+)/g)].map((x) => x[1].replace(/等$/, '')).filter(Boolean)
|
||||
const first = names[0] ?? ''
|
||||
const others = names.filter((n) => !DATA_TOOL.test(n))
|
||||
const toData = DATA_TOOL.test(first) || (!names.length && /数据页/.test(advice))
|
||||
const fixTo = toData ? '/data'
|
||||
: !others.length ? '/tools'
|
||||
: others.every((n) => n.startsWith('mcp:')) ? '/tools/mcp'
|
||||
: others.every((n) => !n.startsWith('mcp:')) ? '/tools/custom' : '/tools'
|
||||
return {
|
||||
title: names.length === 1 ? `绑定的工具「${first}」在本机不存在` : '绑定的工具在本机不存在',
|
||||
reason: `${endStop(list)}这次运行没有发起,前面的节点一个都没跑。`,
|
||||
action: `${endStop(advice || (toData ? '去数据页接入,或在节点里重新选' : '去工具页接入,或在节点里重新选'))}接入之后重新运行。`,
|
||||
continuable: false,
|
||||
fix: 'tools',
|
||||
fixTo,
|
||||
fixLabel: toData ? '去数据页接入' : '去工具页接入',
|
||||
raw,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起运行那一下被拒的报错(POST /runs 的 ApiError)。只认「绑定的工具在本机不存在」:认机读码
|
||||
* run_tool_missing,老后端没码时认原话。别的交给 toast 的通用翻译,返回 null
|
||||
*/
|
||||
export function explainStartError(e: unknown): RunErrorExplain | null {
|
||||
const code = e && typeof e === 'object' ? (e as { code?: unknown }).code : undefined
|
||||
const text = e instanceof Error ? e.message : typeof e === 'string' ? e : ''
|
||||
if (code !== RUN_TOOL_MISSING && !/^绑定的工具在本机不存在/.test(text)) return null
|
||||
return explainToolMissing(stripClassPrefix(text), text, code === RUN_TOOL_MISSING)
|
||||
}
|
||||
|
||||
/** 直达某个自定义工具的编辑框(工具页读 ?edit= 打开它)。fixTo 和工具库里的「去改」共用 */
|
||||
export const customToolEditPath = (name: string) => `/tools/custom?edit=${encodeURIComponent(name)}`
|
||||
|
||||
@@ -135,6 +194,45 @@ export function explainRunError(error: string | null | undefined, detail?: strin
|
||||
if (!text) {
|
||||
return { title: '运行失败,但没有留下原因', action: '打开「原始事件」看最后几条记录。', continuable: true, raw }
|
||||
}
|
||||
// 整形节点按 JSON 解析失败(后端 io._json_error)。两种原话:出错的位置落在上游模型写的文字里时
|
||||
// 点名上游(模板没错,别让人去查模板);否则是模板本身写错了。两种都是图的问题:原样接着跑
|
||||
// 拿到的还是同一段文字、同一份模板,只会再失败一次,所以不给「接着跑」,指到画布上去改
|
||||
// 标题、原因、怎么办都照原话切,不改写:展开区据此认出原话已经说完了,不再整段贴一遍。
|
||||
// 放在最前:原话里带着用户起的节点名(「查询超时订单」「额度查询」),排在后面会被超时、限流、
|
||||
// 连不上那几条按整句关键词抢走,又把「接着跑」给回来
|
||||
const upstream = plain.match(/^(上游「([^」]+)」输出的不是合法 JSON([^)]*))[,,]\s*([^;;]*)[;;]\s*([\s\S]+)$/)
|
||||
if (upstream) {
|
||||
return {
|
||||
title: upstream[1],
|
||||
reason: `${endStop(upstream[3].trim())}模板本身没有写错。`,
|
||||
action: `${endStop(upstream[4].trim())}原样接着跑拿到的还是同一段文字,会再失败一次。`,
|
||||
continuable: false,
|
||||
fix: 'canvas',
|
||||
// 要改的是写出这段文字的上游,不是整形节点:入口指到上游去
|
||||
fixNode: upstream[2],
|
||||
raw,
|
||||
}
|
||||
}
|
||||
const badJson = plain.match(/^(模板渲染出来的不是合法 JSON([^)]*))[。.]?\s*([\s\S]*)$/)
|
||||
if (badJson) {
|
||||
const hint = badJson[2].trim()
|
||||
// 后端点名了模板里是哪一处、该怎么改(加 | json、去掉引号、取出来是空的):照它说,
|
||||
// 不再追加「改用 output_schema」——那句指的是另一条路,和它给的改法对不上。
|
||||
// 只有老的笼统说法(或者什么都没说)才补这一句
|
||||
const pointed = hint.startsWith('模板里 {{')
|
||||
return {
|
||||
title: badJson[1],
|
||||
action: `${endStop(hint || TEMPLATE_HINT)}`
|
||||
+ (pointed ? '改完再运行。' : '模板里插的是 agent / 模型写的文字时,改用 output_schema + cite_fields 让它交结构化数据。改完再运行。'),
|
||||
continuable: false,
|
||||
fix: 'canvas',
|
||||
raw,
|
||||
}
|
||||
}
|
||||
// 发起就被拒:绑定的工具在本机不存在(POST /runs 422 run_tool_missing)。这次运行根本没开始,
|
||||
// 谈不上接着跑;去接入,或者回画布重新选
|
||||
const missingTool = explainToolMissing(plain, raw)
|
||||
if (missingTool) return missingTool
|
||||
// 工具库里存着的坏参数定义。它不在这次运行的快照里:到工具页改好,回来原样接着跑
|
||||
// 就能过;不先改,接着跑还是同样的失败
|
||||
const broken = explainBrokenTools(plain, raw)
|
||||
|
||||
@@ -230,8 +230,136 @@ export const EVIDENCE_TEXT = {
|
||||
docMismatch: '成果字段和报告文档对不上,按普通文本显示',
|
||||
docOtherRun: '证据文档不是这次运行写的,按普通文本显示',
|
||||
ambiguous: (candidates: string[]) => `出处不唯一:候选 ${candidates.join('、')}`,
|
||||
|
||||
// ---- 第二期:查询步骤、输入来源、口径卡来源 ----
|
||||
query: (alias: string) => `查询 ${alias}`.trim(),
|
||||
copySql: '复制 SQL',
|
||||
/** 窗口外的行:面板只拿到被引用的行加前后各 2 行 */
|
||||
windowed: '仅显示被引用的行及前后各 2 行',
|
||||
openSnapshot: '打开完整快照',
|
||||
snapshotTitle: (alias: string) => `查询 ${alias} · 完整快照`,
|
||||
masked: '已遮罩',
|
||||
/** 面板底部:被遮罩的列 + 遮罩不是安全边界(用户拍板写明) */
|
||||
maskNote: (cols: string[]) =>
|
||||
`已遮罩的列:${cols.join('、')}。在有身份体系之前,遮罩只减少暴露,不是安全边界:完整快照、工件接口里仍是原值`,
|
||||
queryMissing: '查询的行要从证据接口取,这一次没取到',
|
||||
queryPending: '正在取查询的行…',
|
||||
queryHash: '查询快照取回时哈希对不上,疑似被改过:这些行不能当证据',
|
||||
truncatedSnapshot: '查询撞了行数上限,库里还有更多',
|
||||
windowCut: (n: number) => `被引用的行太多,这里只列了前 ${formatNumber(n)} 行,其余看完整快照`,
|
||||
sources: '输入来源',
|
||||
gotoQuery: (alias: string) => `看查询 ${alias}`.trim(),
|
||||
sourceVerified: '与快照一致',
|
||||
sourceMismatch: (told: string, truth: string) => `模型报 ${told},快照是 ${truth},已按快照取值`,
|
||||
/** cell() 取数:算的时候用的值和快照不一样,值没有被换掉,照实说上游改写过 */
|
||||
cellMismatch: (used: string, truth: string) => `算的时候用的是 ${used},快照里是 ${truth}:上游改写过这份结果`,
|
||||
sourceEmpty: '没查到,记为空,没有兜底成 0',
|
||||
cellUnresolved: '核对不到查询快照',
|
||||
codeCompute: (node: string) =>
|
||||
`代码节点${node ? `「${node}」` : ''}算出来的数(计算):沙箱里的算术系统核对不了,业务计算要写进口径卡`,
|
||||
codeSource: (node: string) =>
|
||||
`来自代码节点${node ? `「${node}」` : ''}(标为取数):沙箱跑出来的结果,系统核对不到查询快照`,
|
||||
inputMissing: '缺:上游没给出这个值',
|
||||
caliberFrom: (caliber: string, version: string, workflow: string, wfVersion: string) =>
|
||||
`口径卡「${caliber || '—'}」${version},来自「${workflow}」${wfVersion}`,
|
||||
caliberUpgrade: (latest: string | null, policy: string) =>
|
||||
`${latest ? `上游已有 ${latest}` : '上游有新版本'},按「${policy}」处置`,
|
||||
} as const
|
||||
|
||||
/**
|
||||
* 口径升版的三种处置,和后端 governance.UPGRADE_POLICY_LABELS 同一套说法。子工作流和
|
||||
* 钉版本的口径卡(caliber_from)共用
|
||||
*/
|
||||
export const UPGRADE_POLICY_LABEL: Record<string, string> = {
|
||||
recompute: '用新口径回算历史',
|
||||
dual: '并排双印新旧口径',
|
||||
incomparable: '标注与历史不可比',
|
||||
}
|
||||
|
||||
/**
|
||||
* 子工作流钉住版本后的升版处置说明。选项和口径卡的那个下拉是同一份(检查器直接借用口径卡
|
||||
* 的字段定义),这里只换掉说明里「和谁同一套」那半句
|
||||
*/
|
||||
export const SUBGRAPH_UPGRADE_HELP = '钉住的那一版之后,被嵌的工作流又发了新版本:正式运行前必须声明怎么处置,'
|
||||
+ '和钉住别处的口径卡是同一套规则;声明了就照它执行,并记进运行记录'
|
||||
|
||||
/** 上游在钉住的那一版之后又发了版:子工作流和口径卡的提醒同一句 */
|
||||
export const upgradeNewerText = (latest: number, pinned: number) =>
|
||||
`上游已有 v${latest}(钉的是 v${pinned}):正式运行前要在下面声明升版处置,否则会被挡住`
|
||||
|
||||
/**
|
||||
* 发布前检查与自动修复:发布弹窗和问题面板的「发布前检查」共用一套说法。
|
||||
* 原则写在话里:修复只出预览、人确认了才存草稿,永远不替人发布
|
||||
*/
|
||||
export const PUBLISH_FIX_TEXT = {
|
||||
section: '发布前检查',
|
||||
lint: '校验',
|
||||
checking: '正在做发布前检查…',
|
||||
unsupported: '这个后端还没有发布前检查:点「发布」时门禁照旧检查,拦下的问题会列在这里',
|
||||
failed: '发布前检查没做成',
|
||||
retry: '重试',
|
||||
recheck: '重新检查',
|
||||
run: '检查',
|
||||
stale: '画布改过了,结果可能已经过时',
|
||||
blocked: (n: number) => `发布前检查:会被门禁拦下 ${n} 处`,
|
||||
gateBlocked: (n: number) => `门禁拦下了 ${n} 处,改完再发布`,
|
||||
passed: '发布前检查通过:没有会被门禁拦下的问题',
|
||||
warnings: (n: number) => `另有 ${n} 条提示`,
|
||||
fixAll: (n: number) => `一键修复可自动修的 ${n} 处`,
|
||||
fixOne: '修复',
|
||||
fixHint: (label: string) => `先看预览:${label}`,
|
||||
choose: '预览',
|
||||
chooseFirst: '先选好再预览',
|
||||
multiple: '可以多选',
|
||||
suggested: '建议',
|
||||
assist: '交给 Copilot',
|
||||
assistHint: '让 Copilot 试着改剩下的问题。它改的同样只是预览,要人拿主意的会原样问你',
|
||||
locked: (why: string) => `${why}。现在不能修复`,
|
||||
previewing: '正在生成修复预览…',
|
||||
assisting: 'Copilot 正在试着修,可能要几十秒…',
|
||||
stop: '停下',
|
||||
previewTitle: (n: number) => `修复预览 · ${n} 处改动`,
|
||||
noChange: '这一次没有可以应用的改动',
|
||||
rejected: '没有采用',
|
||||
assistSaid: 'Copilot',
|
||||
questions: 'Copilot 需要你拿主意',
|
||||
afterOk: '应用后门禁不再拦',
|
||||
afterLeft: (n: number) => `应用后还剩 ${n} 处会被拦下`,
|
||||
apply: '应用并重新检查',
|
||||
discard: '放弃',
|
||||
applyNote: '应用后存成新的草稿版本,再重新检查一遍;不会自动发布',
|
||||
dirtyNote: '画布上还有没保存的改动,应用时会一起存进草稿',
|
||||
saving: '正在保存草稿…',
|
||||
rechecking: '正在重新检查…',
|
||||
saveFailed: '草稿没保存上',
|
||||
saveFailedHint: '修复已经放到画布上(可以撤销);保存成功之前不能发布',
|
||||
retrySave: '重试保存',
|
||||
stalePreview: '预览之后画布又改过了,这份预览对不上了:重新检查一次再修',
|
||||
autofixMissing: '这个后端还不支持自动修复:照提示手动改,或者打开助手描述一遍',
|
||||
autofixFailed: '修复预览没生成出来',
|
||||
applied: (n: number, version?: number) => `已应用 ${n} 处修复${version != null ? `,存为 v${version}` : ''}`,
|
||||
saveNote: (labels: string[]) => `发布前修复:${labels[0] ?? ''}${labels.length > 1 ? ` 等 ${labels.length} 处` : ''}`,
|
||||
/** 撤销栈里这一步叫什么 */
|
||||
undoLabel: (n: number) => `发布前修复(${n} 处)`,
|
||||
pendingPreview: '先应用或放弃修复预览',
|
||||
unsaved: '修复还没保存上',
|
||||
whole: '整张工作流',
|
||||
} as const
|
||||
|
||||
/** 证据的种类怎么叫:aria-label、面板标题、出处那一句 */
|
||||
export const EVIDENCE_KIND_LABEL: Record<string, string> = {
|
||||
metric: '口径卡指标',
|
||||
input: '运行输入',
|
||||
cell: '查询结果',
|
||||
query: '查询结果',
|
||||
table: '整表',
|
||||
retrieval: '知识库检索',
|
||||
node_output: '代码节点的产出',
|
||||
entity: '表或字段',
|
||||
column: '字段',
|
||||
quote: '引文',
|
||||
}
|
||||
|
||||
/**
|
||||
* MCP / 自定义工具的信任档:工具页的三选一、工具徽标、审批卡的「始终允许」共用这一份。
|
||||
* 「始终允许」只指 always;审批卡上那个按钮设的是 gated,按钮字短,说明里写全
|
||||
|
||||
Reference in New Issue
Block a user