|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <div v-if="items.length" class="ai-trace" :class="{ 'is-active': active }">
|
|
|
|
|
|
|
+ <div v-if="items.length || subagentRuns.length" class="ai-trace" :class="{ 'is-active': active }">
|
|
|
<!-- 汇总行:折叠态只留这一行 -->
|
|
<!-- 汇总行:折叠态只留这一行 -->
|
|
|
<button class="ai-trace__head" type="button" :aria-expanded="expanded" @click="toggle">
|
|
<button class="ai-trace__head" type="button" :aria-expanded="expanded" @click="toggle">
|
|
|
<span class="ai-trace__caret" :class="{ 'is-open': expanded }">
|
|
<span class="ai-trace__caret" :class="{ 'is-open': expanded }">
|
|
@@ -13,6 +13,27 @@
|
|
|
|
|
|
|
|
<!-- 过程:思考与工具按执行顺序逐行排列,对齐桌面端扁平时间线 -->
|
|
<!-- 过程:思考与工具按执行顺序逐行排列,对齐桌面端扁平时间线 -->
|
|
|
<div v-show="expanded" class="ai-trace__body">
|
|
<div v-show="expanded" class="ai-trace__body">
|
|
|
|
|
+ <!-- 子代理:与工具调用同属执行流水,随主流程实时出现;结束后仍在本条消息里可回看 -->
|
|
|
|
|
+ <div v-if="subagentRuns.length" class="ai-trace__subagents">
|
|
|
|
|
+ <div
|
|
|
|
|
+ v-for="run in subagentRuns"
|
|
|
|
|
+ :key="run.source"
|
|
|
|
|
+ class="ai-trace__row is-subagent"
|
|
|
|
|
+ :class="`is-${run.status}`"
|
|
|
|
|
+ >
|
|
|
|
|
+ <span class="ai-trace__icon" :class="{ 'is-running': run.status === 'running' }">
|
|
|
|
|
+ <Icon
|
|
|
|
|
+ :icon="run.status === 'failed' ? 'mdi:alert-circle-outline' : run.status === 'running' ? 'mdi:loading' : 'mdi:check-circle-outline'"
|
|
|
|
|
+ :size="13"
|
|
|
|
|
+ />
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <span class="ai-trace__name">子代理 {{ run.alias || '' }}</span>
|
|
|
|
|
+ <span class="ai-trace__arg">{{ subagentStatusText(run) }}</span>
|
|
|
|
|
+ <span class="ai-trace__spacer"></span>
|
|
|
|
|
+ <span class="ai-trace__meta">{{ subagentDurationText(run) }}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
<template v-for="item in items" :key="item.key">
|
|
<template v-for="item in items" :key="item.key">
|
|
|
<!-- 思考:默认整段展开(输出过程中不要折起来),点行可收起 -->
|
|
<!-- 思考:默认整段展开(输出过程中不要折起来),点行可收起 -->
|
|
|
<template v-if="item.kind === 'think'">
|
|
<template v-if="item.kind === 'think'">
|
|
@@ -109,7 +130,7 @@
|
|
|
* (思考 i → 工具 i,多余的顺序接到末尾)近似排列。要精确还原需后端落库时一并保存事件顺序。
|
|
* (思考 i → 工具 i,多余的顺序接到末尾)近似排列。要精确还原需后端落库时一并保存事件顺序。
|
|
|
*/
|
|
*/
|
|
|
import { computed, defineAsyncComponent, onBeforeUnmount, ref, watch } from 'vue';
|
|
import { computed, defineAsyncComponent, onBeforeUnmount, ref, watch } from 'vue';
|
|
|
- import type { ToolStep } from '../api/types';
|
|
|
|
|
|
|
+ import type { SubagentRun, ToolStep } from '../api/types';
|
|
|
import type { TraceNode } from '../store/chatStream';
|
|
import type { TraceNode } from '../store/chatStream';
|
|
|
import { toolLabel } from '../utils/constants';
|
|
import { toolLabel } from '../utils/constants';
|
|
|
import { parseGraphToolStep } from '../utils/graphToolData';
|
|
import { parseGraphToolStep } from '../utils/graphToolData';
|
|
@@ -129,6 +150,8 @@
|
|
|
thinkingActive?: boolean;
|
|
thinkingActive?: boolean;
|
|
|
/** 工具调用步骤 */
|
|
/** 工具调用步骤 */
|
|
|
steps?: ToolStep[];
|
|
steps?: ToolStep[];
|
|
|
|
|
+ /** 子代理运行态(实时,不落库;与工具调用一起进执行流水) */
|
|
|
|
|
+ subagentRuns?: SubagentRun[];
|
|
|
/** 执行时序(本次流式期间由 store 按 SSE 到达顺序记录) */
|
|
/** 执行时序(本次流式期间由 store 按 SSE 到达顺序记录) */
|
|
|
trace?: TraceNode[];
|
|
trace?: TraceNode[];
|
|
|
/** 所属消息是否仍在流式输出 */
|
|
/** 所属消息是否仍在流式输出 */
|
|
@@ -142,6 +165,7 @@
|
|
|
thinking: '',
|
|
thinking: '',
|
|
|
thinkingActive: false,
|
|
thinkingActive: false,
|
|
|
steps: () => [],
|
|
steps: () => [],
|
|
|
|
|
+ subagentRuns: () => [],
|
|
|
trace: () => [],
|
|
trace: () => [],
|
|
|
active: false,
|
|
active: false,
|
|
|
messageId: '',
|
|
messageId: '',
|
|
@@ -417,12 +441,33 @@
|
|
|
|
|
|
|
|
const metaText = computed(() => {
|
|
const metaText = computed(() => {
|
|
|
const parts: string[] = [];
|
|
const parts: string[] = [];
|
|
|
|
|
+ const subagentCount = props.subagentRuns?.length || 0;
|
|
|
|
|
+ if (subagentCount) parts.push(`${subagentCount} 个子代理`);
|
|
|
const toolCount = (props.steps || []).length;
|
|
const toolCount = (props.steps || []).length;
|
|
|
if (toolCount) parts.push(`${toolCount} 步工具调用`);
|
|
if (toolCount) parts.push(`${toolCount} 步工具调用`);
|
|
|
if (elapsedText.value) parts.push(elapsedText.value);
|
|
if (elapsedText.value) parts.push(elapsedText.value);
|
|
|
return parts.join(' · ');
|
|
return parts.join(' · ');
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ /** 子代理行状态文案:运行中显示当前工具与耗时,结束显示完成/失败 */
|
|
|
|
|
+ function subagentStatusText(run: SubagentRun): string {
|
|
|
|
|
+ if (run.status === 'running') {
|
|
|
|
|
+ return run.currentTool ? `调用 ${run.currentTool}` : '处理中';
|
|
|
|
|
+ }
|
|
|
|
|
+ if (run.status === 'failed') {
|
|
|
|
|
+ return run.error ? `失败:${run.error}` : '失败';
|
|
|
|
|
+ }
|
|
|
|
|
+ return '已完成';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function subagentDurationText(run: SubagentRun): string {
|
|
|
|
|
+ const ms = run.status === 'running' ? run.elapsedMs : run.durationMs ?? run.elapsedMs;
|
|
|
|
|
+ if (!ms || ms < 0) return '';
|
|
|
|
|
+ if (ms < 1000) return `${ms}ms`;
|
|
|
|
|
+ const seconds = ms / 1000;
|
|
|
|
|
+ return seconds < 60 ? `${seconds.toFixed(1)}s` : `${Math.floor(seconds / 60)}m${Math.round(seconds % 60)}s`;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/* ---------------- 图标与摘要 ---------------- */
|
|
/* ---------------- 图标与摘要 ---------------- */
|
|
|
|
|
|
|
|
const TOOL_ICONS: Record<string, string> = {
|
|
const TOOL_ICONS: Record<string, string> = {
|
|
@@ -686,6 +731,39 @@
|
|
|
&__graph {
|
|
&__graph {
|
|
|
margin: 4px 0 var(--ai-sp-2);
|
|
margin: 4px 0 var(--ai-sp-2);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /* 子代理执行行:与工具行同构,运行中旋转;完成/失败用图标与颜色区分 */
|
|
|
|
|
+ &__subagents {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ flex-direction: column;
|
|
|
|
|
+ gap: 2px;
|
|
|
|
|
+ margin: 2px 0 6px;
|
|
|
|
|
+ padding-bottom: 4px;
|
|
|
|
|
+ border-bottom: 1px dashed var(--ai-border);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ &__row.is-subagent {
|
|
|
|
|
+ cursor: default;
|
|
|
|
|
+
|
|
|
|
|
+ .ai-trace__icon.is-running {
|
|
|
|
|
+ animation: ai-trace-spin 1s linear infinite;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ &.is-completed .ai-trace__icon {
|
|
|
|
|
+ color: var(--success-color, #389e0d);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ &.is-failed .ai-trace__icon {
|
|
|
|
|
+ color: @error-color;
|
|
|
|
|
+ opacity: 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @keyframes ai-trace-spin {
|
|
|
|
|
+ to {
|
|
|
|
|
+ transform: rotate(360deg);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@keyframes ai-trace-pulse {
|
|
@keyframes ai-trace-pulse {
|