feat(cloud-agent): 操作记录 - 折叠成一行只报最新一步并支持展开完整记录
(cherry picked from commit fce39c847b046ec8b3f11a83f1e809a4a88100d6)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { agentCanvasActions, agentCanvasActionLabel } from "@/lib/canvas/agent-canvas-actions";
|
||||
import { Button } from "antd";
|
||||
import { Tooltip } from "@/components/ui/base/tooltip";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, type ClipboardEvent as ReactClipboardEvent, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent as ReactPointerEvent, type ReactNode } from "react";
|
||||
import { useCallback, useEffect, useId, useMemo, useRef, useState, type ClipboardEvent as ReactClipboardEvent, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent as ReactPointerEvent, type ReactNode } from "react";
|
||||
|
||||
import { motion, useReducedMotion } from "motion/react";
|
||||
import { ArrowLeft, ArrowUp, AtSign, Bookmark, CheckCircle2, ChevronDown, ChevronUp, CircleAlert, CircleDot, Clapperboard, Eye, HelpCircle, ImagePlus, Layers3, ListChecks, LoaderCircle, Palette, Pencil, Plus, RotateCcw, Shapes, Share2, ShoppingBag, Sparkles, Square, X, XCircle } from "lucide-react";
|
||||
@@ -13,7 +13,8 @@ import { CanvasResourceMentionTextarea } from "./canvas-resource-mention-textare
|
||||
import type { CanvasResourceReference } from "@/lib/canvas/canvas-resource-references";
|
||||
import type { Skill, SkillPreset } from "@/services/api/skills";
|
||||
import { buildSkillMentionReferences } from "@/services/skill-runtime";
|
||||
import { agentToolCategory, agentToolCategoryLabel, agentToolErrorClassLabel, agentToolStatus, friendlyAgentToolSummary } from "@/lib/canvas/agent-tool-presentation";
|
||||
import { agentToolCategory, agentToolCategoryLabel, agentToolErrorClassLabel, agentToolName, agentToolRetryLabel, agentToolStatus, friendlyAgentToolSummary } from "@/lib/canvas/agent-tool-presentation";
|
||||
import { agentOperationFailed, agentOperationLabel } from "@/lib/canvas/agent-operation-feed";
|
||||
import { agentToolRetry, type AgentToolRetryAttempt } from "@/lib/canvas/agent-tool-retry";
|
||||
|
||||
export type CloudAgentChatAttachment = { id: string; name: string; url: string };
|
||||
@@ -422,7 +423,7 @@ export function AgentToolCard({
|
||||
const retry = agentToolRetry(detail);
|
||||
const attempts = objectField(detail, "retryAttempts");
|
||||
if (retry && Array.isArray(attempts)) {
|
||||
const label = retry.status === "recovered" ? "自动纠正后已恢复" : retry.status === "exhausted" ? "自动纠正未完成" : "自动纠正记录";
|
||||
const label = agentToolRetryLabel(retry);
|
||||
return (
|
||||
<details data-agent-tool-retry className="min-w-0 flex-1 text-xs leading-5" style={{ color: theme.node.muted }}>
|
||||
<summary className="cursor-pointer rounded-sm focus-visible:outline focus-visible:outline-2" style={{ outlineColor: theme.node.muted }}>
|
||||
@@ -500,6 +501,61 @@ export function AgentToolCard({
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Agent 的操作记录(连续的 `role === "tool"` 消息)折成一行:只报最新一步,点击展开完整记录。
|
||||
*
|
||||
* 为什么默认收起:一轮运行的十几条工具记录会把正文挤出可视区,用户真正要读的是结论;
|
||||
* 展开状态用「用户覆盖 + 失败时默认展开」两段决定 —— 失败的操作不能被折进一行里看不见,
|
||||
* 但用户手动收起之后就不再自动弹开(跑动中新步骤只会追加,不会重置展开状态)。
|
||||
*/
|
||||
export function AgentOperationFeed({
|
||||
items,
|
||||
theme,
|
||||
references = [],
|
||||
onFocusNode,
|
||||
}: {
|
||||
items: CloudAgentChatMessage[];
|
||||
theme: (typeof canvasThemes)[keyof typeof canvasThemes];
|
||||
references?: CanvasResourceReference[];
|
||||
onFocusNode?: (nodeId: string) => void;
|
||||
}) {
|
||||
const [userExpanded, setUserExpanded] = useState<boolean | null>(null);
|
||||
const listId = useId();
|
||||
const latest = items[items.length - 1];
|
||||
if (!latest) return null;
|
||||
const latestState = toolCardState(latest.title || "工具执行", latest.text, latest.detail);
|
||||
const latestLabel = agentOperationLabel(latest);
|
||||
const failed = items.some((item) => agentOperationFailed(item));
|
||||
const expanded = userExpanded ?? failed;
|
||||
return (
|
||||
<div className={`agent-operation-feed${expanded ? " is-open" : ""}${failed ? " is-failed" : ""}`} data-agent-operation-feed>
|
||||
<button
|
||||
type="button"
|
||||
className="agent-operation-toggle"
|
||||
aria-expanded={expanded}
|
||||
aria-controls={listId}
|
||||
// aria-label 会顶掉可见文字,所以最新一步必须自己报出来。
|
||||
aria-label={`${expanded ? "收起" : "展开"} ${items.length} 步操作记录,最新一步:${latestLabel}`}
|
||||
onClick={() => setUserExpanded(!expanded)}
|
||||
>
|
||||
<span className="agent-operation-icon" style={{ color: latestState.color }} aria-hidden="true">
|
||||
{latestState.icon}
|
||||
</span>
|
||||
<span className="agent-operation-latest">{latestLabel}</span>
|
||||
{items.length > 1 ? <span className="agent-operation-count">{items.length} 步</span> : null}
|
||||
<ChevronDown className="agent-operation-chevron" aria-hidden="true" />
|
||||
</button>
|
||||
{expanded ? (
|
||||
<div id={listId} className="agent-operation-list">
|
||||
{items.map((item) => (
|
||||
<AgentChatMessage key={item.id} item={item} theme={theme} references={references} onFocusNode={onFocusNode} />
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function AgentWorkingMessage({ theme, label = WORKING_TEXT }: { theme: (typeof canvasThemes)[keyof typeof canvasThemes]; label?: string }) {
|
||||
return (
|
||||
<div role="status" aria-live="polite" className="agent-working-indicator" style={{ color: theme.node.muted }}>
|
||||
@@ -1178,10 +1234,6 @@ function toolCardState(title: string, text: string, detail?: unknown) {
|
||||
return { label: "处理中", color: "#64748b", softBg: "rgba(100,116,139,.04)", icon: <CircleDot className="size-4" />, isError: false };
|
||||
}
|
||||
|
||||
function agentToolName(title: string, detail?: unknown) {
|
||||
return String(objectField(detail, "toolName") || objectField(detail, "name") || objectField(detail, "tool") || title);
|
||||
}
|
||||
|
||||
function objectField(value: unknown, key: string) {
|
||||
return value && typeof value === "object" ? (value as Record<string, unknown>)[key] : undefined;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import { canvasThemes, type CanvasTheme } from "@/lib/canvas-theme";
|
||||
import { agentErrorPresentation, agentSubmissionErrorTitle } from "@/lib/canvas/agent-error-presentation";
|
||||
import { cancelAgentRun, getAgentCapabilities, getAgentProfile, getAgentRun, createAgentRun, decideAgentApproval, sendAgentInterjection, sendAgentMessage, subscribeAgentEvents, updateAgentProfile, type AgentEvent, type AgentPermissionMode, type AgentProfileScope, type AgentProfileView, type AgentReasoningMode, type AgentRun } from "@/services/api/agent";
|
||||
import { agentApprovalPresentation } from "@/lib/canvas/agent-approval-presentation";
|
||||
import { buildAgentFeedSegments } from "@/lib/canvas/agent-operation-feed";
|
||||
import { agentApprovalMatchesSettings, agentImageApproval } from "@/lib/canvas/agent-media-approval";
|
||||
import type { AgentMediaSettings } from "@/services/api/agent";
|
||||
import { CanvasAgentImageApprovalSettings } from "./canvas-agent-image-approval-settings";
|
||||
@@ -32,7 +33,7 @@ import { getActiveUserScope } from "@/lib/user-scope";
|
||||
import { applyAgentCanvasPatches, refreshCanvasAfterAgent, saveRemoteUserDataNow } from "@/services/user-data-sync";
|
||||
import { createAgentCanvasSync } from "@/services/agent-canvas-sync";
|
||||
import { buildSkillMentionReferences, resolveSkillMentions } from "@/services/skill-runtime";
|
||||
import { AgentChatComposer, AgentChatMessage, AgentPlanBar, AgentQuestionBar, AgentSceneCapsules, AgentWorkingMessage, AGENT_SCENE_DEFS, type AgentSceneBucket, type CloudAgentChatMessage, type CloudAgentPlanItem } from "./canvas-cloud-agent-chat-ui";
|
||||
import { AGENT_SCENE_DEFS, AgentChatComposer, AgentChatMessage, AgentOperationFeed, AgentPlanBar, AgentQuestionBar, AgentSceneCapsules, AgentWorkingMessage, type AgentSceneBucket, type CloudAgentChatMessage, type CloudAgentPlanItem } from "./canvas-cloud-agent-chat-ui";
|
||||
import { CanvasAgentSkillLibraryModal } from "./canvas-agent-skill-library-modal";
|
||||
import { CanvasCloudAgentSettings, agentPermissionLabel, agentPermissionMenuItems, agentPermissionVisual, type AgentContextKey } from "./canvas-cloud-agent-settings";
|
||||
import { useAgentPanelLayout } from "./use-agent-panel-layout";
|
||||
@@ -1241,6 +1242,9 @@ function AgentConversation({
|
||||
const contentRef = useRef<HTMLDivElement>(null);
|
||||
const followRef = useRef(true);
|
||||
const lastUserId = messages.findLast((item) => item.role === "user")?.id;
|
||||
// 连续的工具记录折成一行(只报最新一步),计划/提问载体由输入区上方的固定条渲染。
|
||||
const segments = useMemo(() => buildAgentFeedSegments(messages), [messages]);
|
||||
const lastMessage = messages.at(-1);
|
||||
|
||||
// 自己发送时恢复跟随;阅读旧消息时不让流式输出抢走滚动位置。
|
||||
useLayoutEffect(() => {
|
||||
@@ -1269,9 +1273,20 @@ function AgentConversation({
|
||||
}}>
|
||||
{!messages.length ? <AgentWelcome appearance={appearance} nodeCount={nodeCount} onChooseSkill={onChooseSkill} onDraftPrompt={onDraftPrompt} /> : null}
|
||||
<div ref={contentRef} className="agent-conversation-messages">
|
||||
{messages.map((item) => (
|
||||
<AgentChatMessage key={item.id} item={item} theme={theme} references={references} onFocusNode={onFocusNode} isStreaming={busy && !approval && item.streaming === true && item === messages.at(-1)} />
|
||||
))}
|
||||
{segments.map((segment) =>
|
||||
segment.kind === "operations" ? (
|
||||
<AgentOperationFeed key={segment.key} items={segment.items} theme={theme} references={references} onFocusNode={onFocusNode} />
|
||||
) : (
|
||||
<AgentChatMessage
|
||||
key={segment.key}
|
||||
item={segment.item}
|
||||
theme={theme}
|
||||
references={references}
|
||||
onFocusNode={onFocusNode}
|
||||
isStreaming={busy && !approval && segment.item.streaming === true && segment.item === lastMessage}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
{approval ? <ApprovalCard key={approval.approvalId} approval={approval} theme={theme} submitting={approvalSubmitting} onFocusNode={onFocusNode} onReasonChange={onApprovalReasonChange} onApprove={onApprove} onReject={onReject} /> : null}
|
||||
{busy && !approval ? (
|
||||
<AgentWorkingMessage theme={theme} label="正在处理当前画布" />
|
||||
|
||||
@@ -902,6 +902,144 @@
|
||||
.agent-tool-action-link { transition: none; }
|
||||
}
|
||||
|
||||
/*
|
||||
* 操作记录折叠行:一轮运行动辄十几条工具记录,逐条铺开会把正文挤出可视区。
|
||||
* 默认只报最新一步(配一道横着扫过的流光表示这行仍在推进),点击展开完整记录;
|
||||
* 失败时整行转红并默认展开(见 AgentOperationFeed 的 expanded 判定)。
|
||||
*/
|
||||
.agent-operation-feed {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.agent-operation-toggle {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
border: 0;
|
||||
border-radius: 9px;
|
||||
background: transparent;
|
||||
padding: 4px var(--space-2) 4px var(--space-1);
|
||||
color: color-mix(in srgb, var(--agent-ink, currentColor) 78%, transparent);
|
||||
font-size: var(--fs-caption);
|
||||
line-height: 18px;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
background-color 140ms ease,
|
||||
color 140ms ease;
|
||||
}
|
||||
|
||||
.agent-operation-toggle:hover {
|
||||
background: var(--agent-surface-soft, color-mix(in srgb, var(--foreground) 4%, transparent));
|
||||
color: var(--agent-ink, var(--foreground));
|
||||
}
|
||||
|
||||
.agent-operation-toggle:focus-visible {
|
||||
outline: 2px solid var(--agent-focus-ring, var(--foreground));
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
.agent-operation-icon {
|
||||
display: grid;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
flex: 0 0 auto;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
.agent-operation-icon svg {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
}
|
||||
|
||||
.agent-operation-latest {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/*
|
||||
* 流光:把文字本身当渐变蒙版,让一道高光扫过。底色与高光都从 --agent-ink 派生——不能用
|
||||
* currentColor,因为开启 background-clip 后 color 是 transparent,会自指成空。
|
||||
*/
|
||||
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
|
||||
.agent-operation-latest {
|
||||
background-image: linear-gradient(
|
||||
100deg,
|
||||
color-mix(in srgb, var(--agent-operation-ink, var(--agent-ink, currentColor)) 74%, transparent) 0%,
|
||||
color-mix(in srgb, var(--agent-operation-ink, var(--agent-ink, currentColor)) 74%, transparent) 42%,
|
||||
var(--agent-operation-ink, var(--agent-ink, currentColor)) 50%,
|
||||
color-mix(in srgb, var(--agent-operation-ink, var(--agent-ink, currentColor)) 74%, transparent) 58%,
|
||||
color-mix(in srgb, var(--agent-operation-ink, var(--agent-ink, currentColor)) 74%, transparent) 100%
|
||||
);
|
||||
background-position: 100% 0;
|
||||
background-size: 240% 100%;
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
animation: agent-operation-sheen 3.6s linear infinite;
|
||||
}
|
||||
}
|
||||
|
||||
/* 失败/被拒的一步:折叠行跟工具卡同一套红,不用主题色盖掉语义。 */
|
||||
.agent-operation-feed.is-failed .agent-operation-latest {
|
||||
--agent-operation-ink: #dc2626;
|
||||
}
|
||||
|
||||
.agent-operation-count {
|
||||
flex: 0 0 auto;
|
||||
border-radius: 999px;
|
||||
background: var(--agent-surface-soft, color-mix(in srgb, var(--foreground) 6%, transparent));
|
||||
padding: 1px var(--space-2);
|
||||
color: color-mix(in srgb, var(--agent-ink, currentColor) 62%, transparent);
|
||||
font-size: var(--fs-tiny);
|
||||
line-height: 16px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.agent-operation-chevron {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
flex: 0 0 auto;
|
||||
opacity: 0.55;
|
||||
transition: transform 180ms ease;
|
||||
}
|
||||
|
||||
.agent-operation-feed.is-open .agent-operation-chevron {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.agent-operation-list {
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.agent-operation-list > * + * {
|
||||
margin-top: var(--space-1);
|
||||
}
|
||||
|
||||
@keyframes agent-operation-sheen {
|
||||
from {
|
||||
background-position: 130% 0;
|
||||
}
|
||||
to {
|
||||
background-position: -30% 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.agent-operation-latest {
|
||||
animation: none;
|
||||
background-position: 0% 0;
|
||||
}
|
||||
.agent-operation-toggle,
|
||||
.agent-operation-chevron {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
.agent-composer-prompt-scroll {
|
||||
min-height: 60px;
|
||||
max-height: min(240px, 34vh);
|
||||
|
||||
Reference in New Issue
Block a user