| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /**
- * 执行日志类型 → 中文标签 / CSS 类名 工具。
- *
- * <p>三处显示执行日志(ChatMessageList / WorkflowEditor / RunHistory)共用,
- * 统一颜色与中文文案。同时兼容两套命名:
- * <ul>
- * <li>chat 端 SSE 事件 {@code kind}:小写下划线(thinking / status / step / tool_progress /
- * tool_call / tool_result / todo_update / clarify_request)</li>
- * <li>工作流端 ExecutionLog {@code type}:大写下划线(INFO / TOOL_CALL / TOOL_RESULT /
- * THINKING / ERROR / STATUS / STEP / TOOL_PROGRESS / TODO_UPDATE / CLARIFY_REQUEST)</li>
- * </ul>
- *
- * <p>映射规则:忽略大小写 + 下划线/连字符归一化后匹配;查不到回退到 '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)。
- *
- * <p>用于执行日志渲染分支:工作流端 {@code ExecutionLog} 把工具名放在 {@code message}、
- * 参数摘要放在 {@code detail};与 chat 端 {@code ChatMessageLog} 的 {@code toolName + content}
- * 字段语义不同。渲染时对工具类日志把 {@code message} 高亮为 tool 列、{@code detail} 作为 msg 列,
- * 即可与 chat 端工具类日志的视觉完全一致。</p>
- */
- export function isToolLogType(type) {
- const t = normalizeType(type)
- return t === 'tool_call' || t === 'tool_result' || t === 'tool_progress'
- }
|