diff --git a/chatbot/src/App.jsx b/chatbot/src/App.jsx index f534d9b6d..ec7986389 100644 --- a/chatbot/src/App.jsx +++ b/chatbot/src/App.jsx @@ -10,17 +10,13 @@ import { useChat } from "./useChat"; import NativeApprovalPanel from "./NativeApprovalPanel"; import { useNativeApprovals } from "./useNativeApprovals"; import { AgentBrowserLinks } from "./agent-browser-links.js"; -import ActivityTrace, { ReplyTimeline } from "./ActivityTrace"; +import { AssistantTurn, LiveMessage, MessageTime, UserTurn, replyText } from "./ChatTurns"; import MessageInfo from "./MessageInfo"; import MessageHistory from "./MessageHistory"; import GenerationDiagnostics from "./GenerationDiagnostics"; -import { fullTime, messageSentAt, messageTimeLabel } from "./message-info.js"; import { activityForReply, - finalReply, generationStored, - hasTextSegments, - streamingAnswerOpen, } from "./activity"; import { api, @@ -39,17 +35,11 @@ import { projectPickerOptions, } from "./api"; import { - RichContent, CopyButton, Attachment, ArtifactPreview, ImageLightbox, } from "./RichContent"; -import KnowledgeSources from "./KnowledgeSources"; -import { - buildKnowledgeSummary, - formatTextForCopy, -} from "./knowledge-citations.js"; import { DraftCard } from "./SidePanel"; import ArtifactPanel from "./ArtifactPanel"; import { useWorkspaceChanges } from "./useWorkspaceChanges"; @@ -65,10 +55,9 @@ import { groupSessionHistory, scheduledSession, sessionProjectName } from "./ses import { runSessionState, sessionReplyStatus, sessionTooltip, sidebarReplyStatus } from "./session-status.js"; import { unreadReply, useReadReplies } from "./session-unread.js"; import ReferenceInput from "./ReferenceInput"; -import Participants, { Avatar, authorFor } from "./Participants"; +import Participants, { Avatar } from "./Participants"; import IssueContext from "./IssueContext"; import { insertMention } from "./mentions.js"; -import { elementTitle } from "./element-context.js"; import HarnessIcon from "./HarnessIcon"; import QueuedMessages from "./QueuedMessages"; import "./message-queue.css"; @@ -211,179 +200,9 @@ const readJSON = (key, fallback) => { return fallback; } }; -function MessageTime({ messages, index }) { - const date = messageSentAt(messages, index); - if (!date) return null; - return ( - - ); -} function copiedReply(message, generation, live) { - const steps = activityForReply(message, generation, live); - const text = parseReply(message).message; - const reply = hasTextSegments(steps) ? finalReply(text, steps) : text; - if (message?.knowledgeReads?.length > 0) { - const narrationTexts = steps - .filter((s) => s.kind === "text" && s.text) - .map((s) => s.text); - return formatTextForCopy(reply, message.knowledgeReads, [ - ...narrationTexts, - reply, - ]); - } - return reply; + return replyText(message, activityForReply(message, generation, live)); } -function ReplyHeading({ message, steps, deferredActivity }) { - return ( -
- -
- ); -} -function AssistantTurn({ message, steps, deferredActivity, assets, projectId, sessionId, local, readOnly, onCLIInstall }) { - const reply = parseReply(message); - const answer = hasTextSegments(steps) - ? finalReply(reply.message, steps) - : message; - const answerText = typeof answer === "string" ? answer : visibleText(answer); - const hasReads = - Array.isArray(message.knowledgeReads) && message.knowledgeReads.length > 0; - const knowledgeSummary = useMemo(() => { - if (!hasReads) return null; - const narrationTexts = steps - .filter((s) => s.kind === "text" && s.text) - .map((s) => s.text); - return buildKnowledgeSummary(message.knowledgeReads, [ - ...narrationTexts, - answerText, - ]); - }, [hasReads, message.knowledgeReads, steps, answerText]); - const [highlightedCite, setHighlightedCite] = useState(null); - const sourcesRef = useRef(null); - const highlightTimer = useRef(null); - useEffect(() => () => window.clearTimeout(highlightTimer.current), []); - const handleCitationClick = useCallback((citeIndex) => { - setHighlightedCite(citeIndex); - window.clearTimeout(highlightTimer.current); - highlightTimer.current = window.setTimeout(() => setHighlightedCite(null), 2000); - }, []); - return ( - <> - {hasTextSegments(steps) ? ( - - ) : ( - - )} -
- -
- - {message.failure && message.generationId && !local ? ( - - ) : message.unfinished ? ( -

本轮未完成 · {message.unfinished}

- ) : reply.stopped ? ( -

已停止,以上是停止前的内容。

- ) : null} - - ); -} -function LiveMessage({ live, generation, finished = false, local = false, readOnly = false, hasKnowledgeRefs = false, approvals = [] }) { - const steps = live.activity || []; - const textual = hasTextSegments(steps); - // A streamed paragraph followed by tool calls stays in the process above; - // only the paragraph still being written shows as the answer. - const answer = - live.draftMessage || - (textual - ? finished || streamingAnswerOpen(steps) - ? finalReply(live.answer, steps) - : "" - : live.answer); - return ( -
- {textual ? ( - - ) : ( -
- -
- )} - {answer ? ( - - ) : null} - {!finished && !local && !readOnly && generation?.id ? : null} - {finished ? ( -

- {generation?.status === "failed" && generation?.error - ? generation.error - : "已停止,以上是停止前的内容。"} -

- ) : null} -
- ); -} - function readIssueMention() { const params = new URLSearchParams(location.search); const issueId = params.get("mentionIssue") || ""; @@ -803,6 +622,10 @@ export default function App() { setQuickAccessOpen(true); return; } + if (event.data?.type === "agentflow-run-review-updated") { + setRunsRefresh((n) => n + 1); + return; + } if (event.data?.type !== "agentflow-chat-mention-issue") return; const issueId = String(event.data.issueId || ""); const projectId = String(event.data.projectId || ""); @@ -989,6 +812,15 @@ export default function App() { setPanel(true); setSelectedArtifact(a); } + function openRunNode(run, nodeId) { + openArtifact({ + kind: "run", + id: run.id, + runId: run.id, + name: run.workflowSnapshot?.name || "LOOP 运行", + nodeId, + }); + } function navigate(view, options = {}) { if (window.parent !== window) window.parent.postMessage( @@ -1659,6 +1491,14 @@ export default function App() {
{chat.session ? ( <> + {chat.session.runNodeReview && conversationRuns.some(({ id }) => id === chat.session.runId) ? ( + openRunNode( + conversationRuns.find(({ id }) => id === chat.session.runId), + chat.session.runNodeReview.nodeId, + )}> + + + ) : null} {conversationStarted ? navigate("runners")} /> : null} {projectName ? (
@@ -2326,82 +2166,52 @@ export default function App() { /> ) : null} {message.role === "user" ? ( -
- <> -
- - - { - authorFor(message, chat.session, chat.users) - .name - } - - -
-
{message.content}
- {message.references?.length ? ( -
- {message.references.map((ref) => ( - - {ref.type === "element" ? ( - - ) : ( - "@" - )} - {ref.name || ref.id} - - ))} -
+ +
+ {!chat.readOnly ? ( + <> + + setDialog({ + type: "edit", + index, + value: message.content, + fork: false, + }) + } + > + + + + setDialog({ + type: "edit", + index, + value: message.content, + fork: true, + }) + } + > + + + ) : null} -
- {!chat.readOnly ? ( - <> - - setDialog({ - type: "edit", - index, - value: message.content, - fork: false, - }) - } - > - - - - setDialog({ - type: "edit", - index, - value: message.content, - fork: true, - }) - } - > - - - - ) : null} - -
- -
+ +
+ ) : null} {message.attachments?.length ? (
@@ -2486,15 +2296,7 @@ export default function App() { users={chat.users} readOnly={chat.readOnly} onChanged={() => setRunsRefresh((n) => n + 1)} - onOpenNode={(run, nodeId) => - openArtifact({ - kind: "run", - id: run.id, - runId: run.id, - name: run.workflowSnapshot?.name || "LOOP 运行", - nodeId, - }) - } + onOpenNode={openRunNode} onAsk={(item) => { setText( `运行 ${item.runId} 的「${item.nodeName}」节点${item.kind === "failed" ? "失败了" : "在等待人工确认"},帮我分析具体卡在哪里、原因是什么、需要谁做什么。`, @@ -2937,6 +2739,7 @@ export default function App() { browserRequest={browserRequest} onBrowserRequestHandled={browserRequestHandled} onAddElement={chat.readOnly ? null : addElementReference} + onRunChanged={() => setRunsRefresh((n) => n + 1)} onClose={() => setPanel(false)} /> ) : null} diff --git a/chatbot/src/ArtifactFileRow.jsx b/chatbot/src/ArtifactFileRow.jsx new file mode 100644 index 000000000..309faf723 --- /dev/null +++ b/chatbot/src/ArtifactFileRow.jsx @@ -0,0 +1,63 @@ +import React from "react"; +import HarnessIcon from "./HarnessIcon"; +import { definitionTarget } from "./platform.js"; + +const icons = { + html: "globe", + slides: "monitor", + ppt: "monitor", + sop: "workflow", + "merge-request": "branch", + role: "user", + code: "stage-ide", +}; + +export default function ArtifactFileRow({ + artifact, + projectId, + selected, + onSelect, +}) { + const icon = artifact.mimeType?.startsWith("image/") + ? "image" + : icons[artifact.kind] || "doc"; + const target = definitionTarget(artifact, projectId); + const href = target?.href || (artifact.external ? artifact.url : ""); + const Row = href ? "a" : "button"; + const title = target + ? `${artifact.name} · ${target.label}` + : artifact.external + ? `${artifact.name} · 在代码仓库打开` + : artifact.name; + + return ( + onSelect(artifact) })} + > + + + + + {artifact.name} + + {target + ? `${artifact.kind === "sop" ? "LOOP" : "角色"} · ${artifact.asset?.status === "published" ? "已发布" : "已保存"}` + : artifact.source} + {artifact.size + ? ` · ${artifact.size < 1024 ? `${artifact.size} B` : `${Math.ceil(artifact.size / 1024)} KB`}` + : ""} + + + + + ); +} diff --git a/chatbot/src/ArtifactPanel.jsx b/chatbot/src/ArtifactPanel.jsx index 87f55f96e..248484120 100644 --- a/chatbot/src/ArtifactPanel.jsx +++ b/chatbot/src/ArtifactPanel.jsx @@ -2,8 +2,10 @@ import React, { useEffect, useRef, useState } from "react"; import HarnessIcon from "./HarnessIcon"; import { api, messageOffset } from "./api"; import { ArtifactPreview, RichContent } from "./RichContent"; +import ArtifactFileRow from "./ArtifactFileRow"; import { DraftCard } from "./SidePanel"; import SopRunPanel, { runStatus } from "./SopRunPanel"; +import { openRunPage } from "./sop-review.js"; import ChangesPanel from "./ChangesPanel"; import AgentBrowser from "./AgentBrowser"; import WorkspaceIDE from "./WorkspaceIDE"; @@ -15,14 +17,7 @@ import { definitionTarget, actionName } from "./platform.js"; import { useArtifactPanelLayout } from "./useArtifactPanelLayout"; import "./artifact-panel.css"; -const FileText = (props) => ; -const FileImage = (props) => ; -const FileCode = (props) => ; -const Presentation = (props) => ; -const Globe = (props) => ; const GitBranch = (props) => ; -const MergeRequest = (props) => ; -const UserRound = (props) => ; const ChevronLeft = (props) => ; const ChevronRight = (props) => ; const X = (props) => ; @@ -30,20 +25,6 @@ const ExternalLink = (props) => ( ); -export function artifactIcon(a) { - if (a.mimeType?.startsWith("image/")) return FileImage; - return ( - { - html: Globe, - slides: Presentation, - ppt: Presentation, - sop: GitBranch, - "merge-request": MergeRequest, - role: UserRound, - code: FileCode, - }[a.kind] || FileText - ); -} function DefinitionPreview({ artifact }) { const [data, setData] = useState(null), [error, setError] = useState(""); @@ -189,16 +170,19 @@ export default function ArtifactPanel({ onClose, open = true, view = "artifacts", + filesOnly = false, + layoutOptions, onViewChange = () => {}, workspaceChanges = null, workspaceRunId = "", browserRequest = null, onBrowserRequestHandled = () => {}, onAddElement = null, + onRunChanged, }) { const root = useRef(null); const searchInput = useRef(null); - const [nodeId, setNodeId] = useState(selected?.nodeId || null); + const [nodeId, setNodeId] = useState(selected?.kind === "run" ? selected.nodeId || null : null); const [search, setSearch] = useState(""); const browsing = view === "browser"; const coding = view === "ide"; @@ -258,10 +242,11 @@ export default function ArtifactPanel({ (browsing && workspaceRunId ? "agent-browser" : null) || (coding && workspaceRunId ? "workspace-ide" : null), open, + layoutOptions, ); useEffect( - () => setNodeId(selected?.nodeId || null), - [selected?.id, selected?.nodeId], + () => setNodeId(selected?.kind === "run" ? selected.nodeId || null : null), + [selected?.id, selected?.kind, selected?.nodeId], ); useEffect(() => setSearch(""), [chat.session?.id]); const selectedRun = @@ -362,50 +347,15 @@ export default function ArtifactPanel({ visibleMergeRequests.length + visibleRuns.length + visibleSubagents.length; - const row = (artifact) => { - const Icon = artifactIcon(artifact); - const target = definitionTarget(artifact, projectId); - // External deliverables (a submitted pull request) live on the code host, - // so the row opens them in a new tab instead of opening a local preview. - const href = target?.href || (artifact.external ? artifact.url : ""); - const Row = href ? "a" : "button"; - const title = target - ? `${artifact.name} · ${target.label}` - : artifact.external - ? `${artifact.name} · 在代码仓库打开` - : artifact.name; - return ( - setSelected(artifact) })} - > - - - - - {artifact.name} - - {target - ? `${artifact.kind === "sop" ? "LOOP" : "角色"} · ${artifact.asset?.status === "published" ? "已发布" : "已保存"}` - : artifact.source} - {artifact.size - ? ` · ${artifact.size < 1024 ? `${artifact.size} B` : `${Math.ceil(artifact.size / 1024)} KB`}` - : ""} - - - {href ? ( - - ) : ( - - )} - - ); - }; + const row = (artifact) => ( + + ); return ( <> {!layout.compact ? ( @@ -454,55 +404,59 @@ export default function ArtifactPanel({ 产物 {count} - - - + {!filesOnly ? ( + <> + + + + + ) : null}
{layout.compact ? ( @@ -646,6 +600,7 @@ export default function ArtifactPanel({ embedded selectedNodeId={nodeId} onSelectNode={setNodeId} + onChanged={onRunChanged} onClose={() => setSelected(null)} /> ) : selectedAgent?.deferredActivity ? ( @@ -728,10 +683,10 @@ export default function ArtifactPanel({

LOOP 运行

{visibleRuns.map((run) => ( +
+ openRunPage(run.id)} + > + + +
))}
) : null} diff --git a/chatbot/src/ChatTurns.jsx b/chatbot/src/ChatTurns.jsx new file mode 100644 index 000000000..f261c12ff --- /dev/null +++ b/chatbot/src/ChatTurns.jsx @@ -0,0 +1,256 @@ +import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import ActivityTrace, { ReplyTimeline } from "./ActivityTrace"; +import GenerationDiagnostics from "./GenerationDiagnostics"; +import HarnessIcon from "./HarnessIcon"; +import KnowledgeSources from "./KnowledgeSources"; +import { Avatar, authorFor } from "./Participants"; +import { RichContent } from "./RichContent"; +import { finalReply, hasTextSegments, streamingAnswerOpen } from "./activity"; +import { parseReply, visibleText } from "./api"; +import { elementTitle } from "./element-context.js"; +import { fullTime, messageSentAt, messageTimeLabel } from "./message-info.js"; +import { + buildKnowledgeSummary, + formatTextForCopy, +} from "./knowledge-citations.js"; + +export function MessageTime({ messages, index }) { + const date = messageSentAt(messages, index); + if (!date) return null; + return ( + + ); +} +export function UserTurn({ + message, + messages, + index, + session, + users, + author = authorFor(message, session, users), + body, + children, +}) { + return ( +
+
+ + {author.name} + +
+
{body ?? message.content}
+ {message.references?.length ? ( +
+ {message.references.map((ref) => ( + + {ref.type === "element" ? ( + + ) : ( + "@" + )} + {ref.name || ref.id} + + ))} +
+ ) : null} + {children} +
+ ); +} + +function narrationTexts(steps) { + return steps.filter((s) => s.kind === "text" && s.text).map((s) => s.text); +} + +export function replyText(message, steps) { + const text = parseReply(message).message; + const reply = hasTextSegments(steps) ? finalReply(text, steps) : text; + if (message?.knowledgeReads?.length > 0) { + return formatTextForCopy(reply, message.knowledgeReads, [ + ...narrationTexts(steps), + reply, + ]); + } + return reply; +} + +function ReplyHeading({ message, steps }) { + return ( +
+ +
+ ); +} +export function AssistantTurn({ + message, + steps, + assets, + projectId, + sessionId, + local, + readOnly, + onCLIInstall, +}) { + const reply = parseReply(message); + const answer = hasTextSegments(steps) + ? finalReply(reply.message, steps) + : message; + const answerText = typeof answer === "string" ? answer : visibleText(answer); + const hasReads = + Array.isArray(message.knowledgeReads) && message.knowledgeReads.length > 0; + const knowledgeSummary = useMemo(() => { + if (!hasReads) return null; + return buildKnowledgeSummary(message.knowledgeReads, [ + ...narrationTexts(steps), + answerText, + ]); + }, [hasReads, message.knowledgeReads, steps, answerText]); + const [highlightedCite, setHighlightedCite] = useState(null); + const sourcesRef = useRef(null); + const highlightTimer = useRef(null); + useEffect(() => () => window.clearTimeout(highlightTimer.current), []); + const handleCitationClick = useCallback((citeIndex) => { + setHighlightedCite(citeIndex); + window.clearTimeout(highlightTimer.current); + highlightTimer.current = window.setTimeout( + () => setHighlightedCite(null), + 2000, + ); + }, []); + return ( + <> + {hasTextSegments(steps) ? ( + + ) : ( + + )} +
+ +
+ + {message.failure && message.generationId && !local ? ( + + ) : message.unfinished ? ( +

本轮未完成 · {message.unfinished}

+ ) : reply.stopped ? ( +

已停止,以上是停止前的内容。

+ ) : null} + + ); +} +export function LiveMessage({ + live, + generation, + finished = false, + local = false, + readOnly = false, + hasKnowledgeRefs = false, + approvals = [], +}) { + const steps = live.activity || []; + const textual = hasTextSegments(steps); + // A streamed paragraph followed by tool calls stays in the process above; + // only the paragraph still being written shows as the answer. + const answer = + live.draftMessage || + (textual + ? finished || streamingAnswerOpen(steps) + ? finalReply(live.answer, steps) + : "" + : live.answer); + return ( +
+ {textual ? ( + + ) : ( +
+ +
+ )} + {answer ? ( + + ) : null} + {!finished && !local && !readOnly && generation?.id ? ( + + ) : null} + {finished ? ( +

+ {generation?.status === "failed" && generation?.error + ? generation.error + : "已停止,以上是停止前的内容。"} +

+ ) : null} +
+ ); +} diff --git a/chatbot/src/RichContent.jsx b/chatbot/src/RichContent.jsx index 5aafc086e..138e36525 100644 --- a/chatbot/src/RichContent.jsx +++ b/chatbot/src/RichContent.jsx @@ -707,9 +707,8 @@ function looksBinary(content) { return (head.match(/\uFFFD/g) || []).length > head.length * 0.1; } export function ArtifactPreview({ artifact, knowledgeReads = [], attempt }) { - const [text, setText] = useState(""); - const [error, setError] = useState(""); - const [mode, setMode] = useState("preview"); + const [loaded, setLoaded] = useState(null); + const [sourceView, setSourceView] = useState(false); const [highlightedCite, setHighlightedCite] = useState(null); const sourcesRef = useRef(null); const highlightTimer = useRef(null); @@ -722,11 +721,21 @@ export function ArtifactPreview({ artifact, knowledgeReads = [], attempt }) { 2000, ); }; + const { id, url, localDataUrl } = artifact || {}; + const current = + loaded?.id === id && + loaded?.url === url && + loaded?.localDataUrl === localDataUrl + ? loaded + : null; + const error = current?.error; + const mode = sourceView && current ? "source" : "preview"; const readable = !artifact?.mimeType || - /^(text\/|application\/(json|javascript|xml))/.test(artifact.mimeType); - const oversized = - Boolean(artifact?.url) && (artifact?.size || 0) > PREVIEW_MAX_BYTES; + /^(text\/|application\/(json|javascript|xml)|image\/svg\+xml)/i.test( + artifact.mimeType, + ); + const oversized = Boolean(url) && (artifact?.size || 0) > PREVIEW_MAX_BYTES; // An attached HTML file (e.g. a demo from the workspace) previews in the same // script-only sandbox as an html code block. const kind = @@ -735,58 +744,63 @@ export function ArtifactPreview({ artifact, knowledgeReads = [], attempt }) { ? "html" : artifact?.kind; useEffect(() => { - let current = true; - setText(""); - setError(""); - setMode("preview"); + let active = true; + setSourceView(false); + const finish = (text, error) => { + if (active) setLoaded({ id, url, localDataUrl, text, error }); + }; if ( readable && - artifact?.id?.startsWith("local-attachment-") && - /^data:[^,]*;base64,/.test(artifact.localDataUrl || "") + id?.startsWith("local-attachment-") && + /^data:[^,]*;base64,/.test(localDataUrl || "") ) { try { - const encoded = artifact.localDataUrl.slice( - artifact.localDataUrl.indexOf(",") + 1, - ); + const encoded = localDataUrl.slice(localDataUrl.indexOf(",") + 1); const bytes = Uint8Array.from(atob(encoded), (character) => character.charCodeAt(0), ); - setText(new TextDecoder().decode(bytes)); + finish(new TextDecoder().decode(bytes)); } catch { - setError("文件读取失败"); + finish("", "文件读取失败"); } - return () => { - current = false; - }; - } - if (artifact?.url && readable && !oversized) - fetch(artifact.url) + } else if (url && readable && !oversized) { + fetch(url) .then((r) => { if (!r.ok) throw Error("文件读取失败"); return r.text(); }) - .then((value) => { - if (current) setText(value); - }) - .catch((e) => { - if (current) setError(e.message); - }); + .then((value) => finish(value)) + .catch((e) => finish("", e.message)); + } else { + // Inline artifacts already carry their body in the message. + finish(""); + } return () => { - current = false; + active = false; }; - }, [artifact?.id, artifact?.url, artifact?.localDataUrl, readable, oversized]); + }, [id, url, localDataUrl, readable, oversized]); if (!artifact) return null; - const source = artifact.url ? text : (artifact.content ?? text); - const binary = Boolean(artifact.url) && looksBinary(text); + const source = + (url ? current?.text : (artifact.content ?? current?.text)) ?? ""; + const binary = Boolean(url) && looksBinary(current?.text || ""); const hasSource = typeof source === "string" && source.length > 0 && !error && !binary; const isMarkdown = artifact.mimeType?.startsWith("text/markdown") || ["markdown", "md"].includes(artifact.language?.toLowerCase()) || - /\.mdx?$/i.test(artifact.name || ""); + /\.(mdx?|markdown)$/i.test(artifact.name || ""); + const isDelimited = + /\.(csv|tsv)$/i.test(artifact.name || "") || + /^(text\/csv|text\/tab-separated-values)/i.test(artifact.mimeType || ""); + const isJSON = + /\.json$/i.test(artifact.name || "") || + /^application\/json/i.test(artifact.mimeType || ""); const canPreview = hasSource && - (["svg", "mermaid", "html", "slides", "ppt"].includes(kind) || isMarkdown); + (["svg", "mermaid", "html", "slides", "ppt"].includes(kind) || + isMarkdown || + isDelimited || + isJSON); const filteredReads = useMemo( () => filterKnowledgeReadsForAttempt( @@ -830,7 +844,7 @@ export function ArtifactPreview({ artifact, knowledgeReads = [], attempt }) { role="tab" className={mode === "preview" ? "is-selected" : ""} aria-selected={mode === "preview"} - onClick={() => setMode("preview")} + onClick={() => setSourceView(false)} > 预览 @@ -839,7 +853,7 @@ export function ArtifactPreview({ artifact, knowledgeReads = [], attempt }) { role="tab" className={mode === "source" ? "is-selected" : ""} aria-selected={mode === "source"} - onClick={() => setMode("source")} + onClick={() => setSourceView(true)} > 源码 @@ -892,6 +906,10 @@ export function ArtifactPreview({ artifact, knowledgeReads = [], attempt }) {
{error ? (

{error}

+ ) : mode === "source" && canPreview ? ( +
+            {source}
+          
) : artifact.mimeType?.startsWith("image/") && artifact.url ? ( ) : oversized ? (

文件较大,不在页面内预览,可通过右上角下载查看。

+ ) : (url || localDataUrl) && readable && !current ? ( +

+ 正在读取文件… +

) : binary ? (

此类型文件可通过右上角下载查看。

- ) : mode === "source" && canPreview ? ( -
-            {source}
-          
+ ) : !hasSource && readable ? ( +

文件为空

) : artifact.kind === "svg" ? (
) : null} + ) : hasSource && isDelimited ? ( + + ) : hasSource && isJSON ? ( +
+            {formattedArtifactJSON(source)}
+          
) : ( -
{source || "正在加载…"}
+
{source}
)}
); } + +function formattedArtifactJSON(source) { + try { + return JSON.stringify(JSON.parse(source), null, 2); + } catch { + return source; + } +} + +function DelimitedArtifact({ source, label, separator }) { + const rowLimit = 101; + const columnLimit = 30; + const rows = []; + let row = [], + field = "", + quoted = false, + truncated = false; + const pushField = () => { + if (row.length < columnLimit) row.push(field); + else truncated = true; + field = ""; + }; + let end = source.length; + while (end && (source[end - 1] === "\n" || source[end - 1] === "\r")) end--; + for (let i = source.charCodeAt(0) === 0xfeff ? 1 : 0; i < end; i++) { + const char = source[i]; + if (char === '"') { + if (quoted && source[i + 1] === '"') { + field += '"'; + i++; + } else { + quoted = !quoted; + } + } else if (!quoted && char === separator) { + pushField(); + } else if (!quoted && (char === "\n" || char === "\r")) { + pushField(); + rows.push(row); + row = []; + if (char === "\r" && source[i + 1] === "\n") i++; + if (rows.length >= rowLimit) { + truncated ||= i + 1 < end; + break; + } + } else { + field += char; + } + } + if (row.length || field) { + pushField(); + rows.push(row); + } + if (!rows.length) return

表格为空

; + const width = Math.max(...rows.map((cells) => cells.length)); + const cells = (values) => + Array.from({ length: width }, (_, index) => values[index] ?? ""); + return ( +
+ + + + {cells(rows[0]).map((name, index) => ( + + ))} + + + + {rows.slice(1).map((values, index) => ( + + {cells(values).map((value, column) => ( + + ))} + + ))} + +
+ {name} +
{value}
+ {truncated ? ( +

+ 预览最多显示 100 行、30 列,可下载查看完整数据。 +

+ ) : null} +
+ ); +} diff --git a/chatbot/src/RunAlerts.jsx b/chatbot/src/RunAlerts.jsx index f166fef02..d5768c4be 100644 --- a/chatbot/src/RunAlerts.jsx +++ b/chatbot/src/RunAlerts.jsx @@ -28,14 +28,6 @@ function readDismissed() { return []; } } -function openRunPage(runId) { - if (window.parent !== window) - window.parent.postMessage( - { type: "agentflow-chat-open-view", view: "runs", runId }, - location.origin, - ); - else location.href = `/#/runs/${encodeURIComponent(runId)}`; -} const prefersReducedMotion = () => !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches; @@ -95,15 +87,27 @@ export default function RunAlerts({ }; const items = runs .flatMap((run) => runProblems(run).map((problem) => ({ ...problem, run }))) - .filter((item) => !dismissed.includes(item.key)); + .filter((item) => item.kind !== "failed" || !dismissed.includes(item.key)); if (!items.length) return null; let entering = 0; for (const item of items) - if (!settled.current.has(item.key) && !slots.current.has(item.key)) + if (item.kind === "failed" && !settled.current.has(item.key) && !slots.current.has(item.key)) slots.current.set(item.key, entering++); return (
{items.map((item) => { + if (item.kind !== "failed") { + const actionable = !readOnly && !item.run.pauseRequested && item.run.reviewAccess?.canOperate !== false; + return ( + + ); + } const isSettled = settled.current.has(item.key); const order = isSettled ? 0 : (slots.current.get(item.key) ?? 0); const isLeaving = leaving.has(item.key); @@ -158,7 +162,6 @@ function RunAlert({ const [busy, setBusy] = useState(false), [error, setError] = useState(""); const { run } = item; - const failed = item.kind === "failed"; const hint = credentialHint(item.reason); const ownerId = run.executionContext?.responsibleUserId; const mine = !ownerId || ownerId === user?.id; @@ -180,13 +183,7 @@ function RunAlert({ const showFix = !!(hint && guide); // At most one filled button per card: fixing the credential comes first. const retryPrimary = !showFix || fixedSince; - const tag = busy - ? "重试中" - : failed - ? "执行失败" - : item.gate === "approval" - ? "人工门禁" - : "待确认"; + const tag = busy ? "重试中" : "执行失败"; async function retry() { setBusy(true); setError(""); @@ -206,7 +203,7 @@ function RunAlert({
) : null}
- {failed && !readOnly ? ( + {!readOnly && run.reviewAccess?.canOperate !== false ? ( - ) : null}