/** * 执行日志类型 → 中文标签 / CSS 类名 工具。 * *

三处显示执行日志(ChatMessageList / WorkflowEditor / RunHistory)共用, * 统一颜色与中文文案。同时兼容两套命名: *

* *

映射规则:忽略大小写 + 下划线/连字符归一化后匹配;查不到回退到 'info'。 */ /** 全量类型 → 中文标签(小写形式为 key) */ const LOG_LABELS = { info: '信息', thinking: '思考', status: '状态', step: '步骤', tool_progress: '工具进度', tool_call: '调用', tool_result: '返回', todo_update: '待办', clarify_request: '提问', error: '错误' } /** * 把任意形式的类型({@code 'TOOL_CALL'} / {@code 'tool_call'} / {@code 'tool-call'}) * 归一化为小写下划线形式。 */ function normalizeType(type) { if (!type) return 'info' return String(type).trim().toLowerCase().replace(/-/g, '_') } /** * 取类型的中文标签。 * * @param {string} type 任意形式的类型字符串 * @returns {string} 中文标签;未知类型回退到 type 原文或 '日志' */ export function logTypeLabel(type) { const key = normalizeType(type) return LOG_LABELS[key] || type || '日志' } /** * 取类型的 CSS 类名后缀(不含前缀)。 * 例:{@code 'TOOL_CALL'} → {@code 'tool_call'},配合模板里 {@code 'log-type-' + suffix} 使用。 */ export function logTypeSuffix(type) { return normalizeType(type) } /** * 是否为工具类日志(TOOL_CALL / TOOL_RESULT / TOOL_PROGRESS)。 * *

用于执行日志渲染分支:工作流端 {@code ExecutionLog} 把工具名放在 {@code message}、 * 参数摘要放在 {@code detail};与 chat 端 {@code ChatMessageLog} 的 {@code toolName + content} * 字段语义不同。渲染时对工具类日志把 {@code message} 高亮为 tool 列、{@code detail} 作为 msg 列, * 即可与 chat 端工具类日志的视觉完全一致。

*/ export function isToolLogType(type) { const t = normalizeType(type) return t === 'tool_call' || t === 'tool_result' || t === 'tool_progress' }