|
@@ -1,5 +1,9 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <div v-if="items.length || subagentRuns.length" class="ai-trace" :class="{ 'is-active': active }">
|
|
|
|
|
|
|
+ <div
|
|
|
|
|
+ v-if="items.length || subagentRuns.length || backgroundTasks.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 }">
|
|
@@ -34,6 +38,32 @@
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
+ <!-- 后台子代理任务:挂在本轮执行流水里,不再出现在输入框上方/建议词之后 -->
|
|
|
|
|
+ <div v-if="backgroundTasks.length" class="ai-trace__subagents">
|
|
|
|
|
+ <div
|
|
|
|
|
+ v-for="task in backgroundTasks"
|
|
|
|
|
+ :key="task.taskId"
|
|
|
|
|
+ class="ai-trace__row is-background"
|
|
|
|
|
+ :class="`is-${task.status}`"
|
|
|
|
|
+ >
|
|
|
|
|
+ <span class="ai-trace__icon" :class="{ 'is-running': isTaskRunning(task) }">
|
|
|
|
|
+ <Icon :icon="taskIcon(task)" :size="13" />
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <span class="ai-trace__name">后台子代理 {{ task.alias || '' }}</span>
|
|
|
|
|
+ <span class="ai-trace__arg">{{ taskStatusText(task) }}</span>
|
|
|
|
|
+ <span class="ai-trace__spacer"></span>
|
|
|
|
|
+ <span class="ai-trace__meta">{{ taskTimeText(task) }}</span>
|
|
|
|
|
+ <button
|
|
|
|
|
+ v-if="isTaskRunning(task)"
|
|
|
|
|
+ type="button"
|
|
|
|
|
+ class="ai-trace__cancel"
|
|
|
|
|
+ @click="emit('cancelTask', task.taskId)"
|
|
|
|
|
+ >
|
|
|
|
|
+ 取消
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </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'">
|
|
@@ -130,7 +160,7 @@
|
|
|
* (思考 i → 工具 i,多余的顺序接到末尾)近似排列。要精确还原需后端落库时一并保存事件顺序。
|
|
* (思考 i → 工具 i,多余的顺序接到末尾)近似排列。要精确还原需后端落库时一并保存事件顺序。
|
|
|
*/
|
|
*/
|
|
|
import { computed, defineAsyncComponent, onBeforeUnmount, ref, watch } from 'vue';
|
|
import { computed, defineAsyncComponent, onBeforeUnmount, ref, watch } from 'vue';
|
|
|
- import type { SubagentRun, ToolStep } from '../api/types';
|
|
|
|
|
|
|
+ import type { SubagentRun, SubagentTask, 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';
|
|
@@ -152,6 +182,8 @@
|
|
|
steps?: ToolStep[];
|
|
steps?: ToolStep[];
|
|
|
/** 子代理运行态(实时,不落库;与工具调用一起进执行流水) */
|
|
/** 子代理运行态(实时,不落库;与工具调用一起进执行流水) */
|
|
|
subagentRuns?: SubagentRun[];
|
|
subagentRuns?: SubagentRun[];
|
|
|
|
|
+ /** 本条消息发起的后台子代理任务(运行中/已完成/失败) */
|
|
|
|
|
+ backgroundTasks?: SubagentTask[];
|
|
|
/** 执行时序(本次流式期间由 store 按 SSE 到达顺序记录) */
|
|
/** 执行时序(本次流式期间由 store 按 SSE 到达顺序记录) */
|
|
|
trace?: TraceNode[];
|
|
trace?: TraceNode[];
|
|
|
/** 所属消息是否仍在流式输出 */
|
|
/** 所属消息是否仍在流式输出 */
|
|
@@ -166,6 +198,7 @@
|
|
|
thinkingActive: false,
|
|
thinkingActive: false,
|
|
|
steps: () => [],
|
|
steps: () => [],
|
|
|
subagentRuns: () => [],
|
|
subagentRuns: () => [],
|
|
|
|
|
+ backgroundTasks: () => [],
|
|
|
trace: () => [],
|
|
trace: () => [],
|
|
|
active: false,
|
|
active: false,
|
|
|
messageId: '',
|
|
messageId: '',
|
|
@@ -173,6 +206,10 @@
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ const emit = defineEmits<{
|
|
|
|
|
+ cancelTask: [taskId: string];
|
|
|
|
|
+ }>();
|
|
|
|
|
+
|
|
|
/** 每个 get_case_graph 工具步骤对应一个图谱块,渲染在该工具调用下方 */
|
|
/** 每个 get_case_graph 工具步骤对应一个图谱块,渲染在该工具调用下方 */
|
|
|
const graphItemsByStep = computed(() => {
|
|
const graphItemsByStep = computed(() => {
|
|
|
const map = new Map<string, NonNullable<ReturnType<typeof parseGraphToolStep>>>();
|
|
const map = new Map<string, NonNullable<ReturnType<typeof parseGraphToolStep>>>();
|
|
@@ -443,6 +480,8 @@
|
|
|
const parts: string[] = [];
|
|
const parts: string[] = [];
|
|
|
const subagentCount = props.subagentRuns?.length || 0;
|
|
const subagentCount = props.subagentRuns?.length || 0;
|
|
|
if (subagentCount) parts.push(`${subagentCount} 个子代理`);
|
|
if (subagentCount) parts.push(`${subagentCount} 个子代理`);
|
|
|
|
|
+ const taskCount = props.backgroundTasks?.length || 0;
|
|
|
|
|
+ if (taskCount) parts.push(`${taskCount} 个后台任务`);
|
|
|
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);
|
|
@@ -468,6 +507,51 @@
|
|
|
return seconds < 60 ? `${seconds.toFixed(1)}s` : `${Math.floor(seconds / 60)}m${Math.round(seconds % 60)}s`;
|
|
return seconds < 60 ? `${seconds.toFixed(1)}s` : `${Math.floor(seconds / 60)}m${Math.round(seconds % 60)}s`;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /* ---------------- 后台子代理任务 ---------------- */
|
|
|
|
|
+
|
|
|
|
|
+ function isTaskRunning(task: SubagentTask): boolean {
|
|
|
|
|
+ return task.status === 'running' || task.status === 'pending';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function taskIcon(task: SubagentTask): string {
|
|
|
|
|
+ if (isTaskRunning(task)) return 'mdi:loading';
|
|
|
|
|
+ if (task.status === 'failed') return 'mdi:alert-circle-outline';
|
|
|
|
|
+ if (task.status === 'cancelled') return 'mdi:cancel';
|
|
|
|
|
+ return 'mdi:check-circle-outline';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function taskStatusText(task: SubagentTask): string {
|
|
|
|
|
+ switch (task.status) {
|
|
|
|
|
+ case 'running':
|
|
|
|
|
+ return '运行中';
|
|
|
|
|
+ case 'pending':
|
|
|
|
|
+ return '排队中';
|
|
|
|
|
+ case 'completed':
|
|
|
|
|
+ return '已完成';
|
|
|
|
|
+ case 'failed':
|
|
|
|
|
+ return task.errorSummary ? `失败:${task.errorSummary}` : '失败';
|
|
|
|
|
+ case 'cancelled':
|
|
|
|
|
+ return '已取消';
|
|
|
|
|
+ default:
|
|
|
|
|
+ return task.status;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 已结束显示总耗时;运行中显示已运行时长(轮询触发重渲染,秒级刷新) */
|
|
|
|
|
+ function taskTimeText(task: SubagentTask): string {
|
|
|
|
|
+ const start = task.startedAt ? Date.parse(task.startedAt) : NaN;
|
|
|
|
|
+ const end = task.finishedAt
|
|
|
|
|
+ ? Date.parse(task.finishedAt)
|
|
|
|
|
+ : isTaskRunning(task)
|
|
|
|
|
+ ? Date.now()
|
|
|
|
|
+ : NaN;
|
|
|
|
|
+ if (Number.isNaN(start) || Number.isNaN(end)) return '';
|
|
|
|
|
+ const ms = Math.max(0, end - start);
|
|
|
|
|
+ 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> = {
|
|
@@ -758,6 +842,44 @@
|
|
|
opacity: 1;
|
|
opacity: 1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ &__row.is-background {
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ &.is-cancelled .ai-trace__icon {
|
|
|
|
|
+ opacity: 0.6;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ &__cancel {
|
|
|
|
|
+ flex: 0 0 auto;
|
|
|
|
|
+ height: 20px;
|
|
|
|
|
+ padding: 0 6px;
|
|
|
|
|
+ font-size: 11px;
|
|
|
|
|
+ color: var(--ai-text-2);
|
|
|
|
|
+ background: transparent;
|
|
|
|
|
+ border: 1px solid var(--ai-border);
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+ cursor: pointer;
|
|
|
|
|
+
|
|
|
|
|
+ &:hover {
|
|
|
|
|
+ color: var(--ai-text);
|
|
|
|
|
+ border-color: var(--ai-border-strong);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@keyframes ai-trace-spin {
|
|
@keyframes ai-trace-spin {
|