From 91a79afb432628d31cca21ff1fe0e7a834621382 Mon Sep 17 00:00:00 2001 From: roberttwang Date: Wed, 25 Nov 2026 16:11:18 +0800 Subject: [PATCH 01/15] feat(sop): review runs in node conversations --- chatbot/src/App.jsx | 271 ++------ chatbot/src/ArtifactFileRow.jsx | 63 ++ chatbot/src/ArtifactPanel.jsx | 196 +++--- chatbot/src/ChatTurns.jsx | 185 +++++ chatbot/src/RichContent.jsx | 201 ++++-- chatbot/src/RunAlerts.jsx | 47 +- chatbot/src/RunNodeActions.jsx | 193 +++++ chatbot/src/SopNodeChat.jsx | 344 +++++++++ chatbot/src/SopRunPanel.jsx | 811 ++++++++++++++-------- chatbot/src/SopRunReview.jsx | 149 ++++ chatbot/src/artifact-preview.css | 41 +- chatbot/src/main.jsx | 4 +- chatbot/src/run-alerts.css | 32 +- chatbot/src/runs.js | 12 +- chatbot/src/sop-review.css | 352 ++++++++++ chatbot/src/sop-review.js | 172 +++++ chatbot/src/useArtifactPanelLayout.js | 7 +- chatbot/src/useChat.js | 33 +- chatbot/tests/components.test.jsx | 50 +- docs/api/openapi.yaml | 64 ++ e2e/public/platform.spec.mjs | 9 +- e2e/ui/02-interactions.spec.mjs | 17 +- internal/domain/assistant.go | 16 +- internal/httpapi/assistant_run_node.go | 163 +++++ internal/httpapi/assistant_session.go | 3 +- internal/httpapi/assistant_shared.go | 19 +- internal/httpapi/assistant_shared_test.go | 113 +++ internal/httpapi/assistant_workbench.go | 6 +- internal/httpapi/helpers_cases_test.go | 12 + internal/httpapi/run_control.go | 31 + internal/httpapi/runs.go | 28 +- internal/httpapi/server.go | 2 + internal/repo/assistant.go | 2 + internal/repo/assistant_shared.go | 31 +- web/app.js | 29 +- web/app/runs.js | 73 +- web/product-v4.css | 125 ++++ 37 files changed, 3155 insertions(+), 751 deletions(-) create mode 100644 chatbot/src/ArtifactFileRow.jsx create mode 100644 chatbot/src/ChatTurns.jsx create mode 100644 chatbot/src/RunNodeActions.jsx create mode 100644 chatbot/src/SopNodeChat.jsx create mode 100644 chatbot/src/SopRunReview.jsx create mode 100644 chatbot/src/sop-review.css create mode 100644 chatbot/src/sop-review.js create mode 100644 internal/httpapi/assistant_run_node.go diff --git a/chatbot/src/App.jsx b/chatbot/src/App.jsx index 0469a78b7..13ecc9290 100644 --- a/chatbot/src/App.jsx +++ b/chatbot/src/App.jsx @@ -9,24 +9,18 @@ import React, { import { useChat } from "./useChat"; import NativeApprovalPanel from "./NativeApprovalPanel"; 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, attachmentURL, - parseReply, collectArtifacts, - visibleText, elapsedSeconds, formatElapsed, confirmationCaption, @@ -35,7 +29,6 @@ import { projectPickerOptions, } from "./api"; import { - RichContent, CopyButton, Attachment, ArtifactPreview, @@ -56,10 +49,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"; @@ -196,114 +188,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; - return hasTextSegments(steps) ? finalReply(text, steps) : text; -} -function ReplyHeading({ message, steps }) { - return ( -
- -
- ); -} -function AssistantTurn({ message, steps, assets, projectId, sessionId, local, readOnly, onCLIInstall }) { - const reply = parseReply(message); - const answer = hasTextSegments(steps) - ? finalReply(reply.message, steps) - : message; - return ( - <> - {hasTextSegments(steps) ? ( - - ) : ( - - )} -
- -
- {message.failure && message.generationId && !local ? ( - - ) : message.unfinished ? ( -

本轮未完成 · {message.unfinished}

- ) : reply.stopped ? ( -

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

- ) : null} - - ); + return replyText(message, activityForReply(message, generation, live)); } -function LiveMessage({ live, generation, finished = false, local = false, readOnly = false }) { - 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") || ""; @@ -649,6 +536,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 || ""); @@ -824,6 +715,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 || "SOP 运行", + nodeId, + }); + } function navigate(view, options = {}) { if (window.parent !== window) window.parent.postMessage( @@ -1349,6 +1249,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 ? (
@@ -1676,82 +1584,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 ? (
@@ -1834,15 +1712,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 || "SOP 运行", - nodeId, - }) - } + onOpenNode={openRunNode} onAsk={(item) => { setText( `运行 ${item.runId} 的「${item.nodeName}」节点${item.kind === "failed" ? "失败了" : "在等待人工确认"},帮我分析具体卡在哪里、原因是什么、需要谁做什么。`, @@ -2284,6 +2154,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..f653d2029 --- /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" ? "SOP" : "角色"} · ${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 fa2eef41a..51d219aef 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 } 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"; @@ -14,14 +16,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) => ; @@ -29,20 +24,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(""); @@ -188,16 +169,18 @@ export default function ArtifactPanel({ onClose, open = true, view = "artifacts", + filesOnly = false, 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,8 +241,8 @@ export default function ArtifactPanel({ open, ); 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 = @@ -360,50 +343,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" ? "SOP" : "角色"} · ${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 ? ( @@ -452,55 +400,59 @@ export default function ArtifactPanel({ 产物 {count} - - - + {!filesOnly ? ( + <> + + + + + ) : null}
{layout.compact ? ( @@ -644,6 +596,7 @@ export default function ArtifactPanel({ embedded selectedNodeId={nodeId} onSelectNode={setNodeId} + onChanged={onRunChanged} onClose={() => setSelected(null)} /> ) : selectedAgent ? ( @@ -709,10 +662,10 @@ export default function ArtifactPanel({

SOP 运行

{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..da76b7cec --- /dev/null +++ b/chatbot/src/ChatTurns.jsx @@ -0,0 +1,185 @@ +import React from "react"; +import ActivityTrace, { ReplyTimeline } from "./ActivityTrace"; +import GenerationDiagnostics from "./GenerationDiagnostics"; +import HarnessIcon from "./HarnessIcon"; +import { Avatar, authorFor } from "./Participants"; +import { RichContent } from "./RichContent"; +import { finalReply, hasTextSegments, streamingAnswerOpen } from "./activity"; +import { parseReply } from "./api"; +import { elementTitle } from "./element-context.js"; +import { fullTime, messageSentAt, messageTimeLabel } from "./message-info.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} +
+ ); +} + +export function replyText(message, steps) { + const text = parseReply(message).message; + return hasTextSegments(steps) ? finalReply(text, steps) : text; +} + +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; + 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, +}) { + 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 057311b47..d444b6fbf 100644 --- a/chatbot/src/RichContent.jsx +++ b/chatbot/src/RichContent.jsx @@ -539,12 +539,22 @@ export function Attachment({ attachment, sessionId, onOpen }) { ); } export function ArtifactPreview({ artifact }) { - const [text, setText] = useState(""); - const [error, setError] = useState(""); - const [mode, setMode] = useState("preview"); + const [loaded, setLoaded] = useState(null); + const [sourceView, setSourceView] = useState(false); + 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); + /^(text\/|application\/(json|javascript|xml)|image\/svg\+xml)/i.test( + artifact.mimeType, + ); // 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 = @@ -553,55 +563,61 @@ export function ArtifactPreview({ artifact }) { ? "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) - fetch(artifact.url) + } else if (url && readable) { + 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]); + }, [id, url, localDataUrl, readable]); if (!artifact) return null; - const source = artifact.url ? text : (artifact.content ?? text); + const source = + (url ? current?.text : (artifact.content ?? current?.text)) ?? ""; const hasSource = typeof source === "string" && source.length > 0 && !error; const isMarkdown = artifact.mimeType?.startsWith("text/markdown") || - ["markdown", "md"].includes(artifact.language?.toLowerCase()); + ["markdown", "md"].includes(artifact.language?.toLowerCase()) || + /\.(md|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); return (
@@ -627,7 +643,7 @@ export function ArtifactPreview({ artifact }) { role="tab" className={mode === "preview" ? "is-selected" : ""} aria-selected={mode === "preview"} - onClick={() => setMode("preview")} + onClick={() => setSourceView(false)} > 预览 @@ -636,7 +652,7 @@ export function ArtifactPreview({ artifact }) { role="tab" className={mode === "source" ? "is-selected" : ""} aria-selected={mode === "source"} - onClick={() => setMode("source")} + onClick={() => setSourceView(true)} > 源码 @@ -689,16 +705,22 @@ export function ArtifactPreview({ artifact }) {
{error ? (

{error}

+ ) : mode === "source" && canPreview ? ( +
+            {source}
+          
) : artifact.mimeType?.startsWith("image/") && artifact.url ? ( - ) : mode === "source" && canPreview ? ( -
-            {source}
-          
+ ) : (url || localDataUrl) && readable && !current ? ( +

+ 正在读取文件… +

+ ) : !hasSource && readable ? ( +

文件为空

) : artifact.kind === "svg" ? (
此类型文件可通过右上角下载查看。

) : isMarkdown ? ( + ) : 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 e9f9c9b01..9c7cac0b6 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}