diff --git a/chatbot/src/App.jsx b/chatbot/src/App.jsx index 644dae2fb..0daa1f6f3 100644 --- a/chatbot/src/App.jsx +++ b/chatbot/src/App.jsx @@ -248,8 +248,10 @@ function AssistantTurn({ message, steps, assets, projectId, sessionId, local, re ); } -function LiveMessage({ live, generation, finished = false, local = false, readOnly = false }) { +function LiveMessage({ live, generation, finished = false, local = false, readOnly = false, diagnosticMessage }) { const steps = live.activity || []; + const stopReason = generation?.status === "failed" && generation.error + ? generation.error : "已停止,以上是停止前的内容。"; 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. @@ -286,13 +288,7 @@ function LiveMessage({ live, generation, finished = false, local = false, readOn )} {answer ? : null} {!finished && !local && !readOnly && generation?.id ? : null} - {finished ? ( -

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

- ) : null} + {finished && stopReason !== diagnosticMessage ?

{stopReason}

: null} ); } @@ -952,6 +948,9 @@ export default function App() { })); }, [chat.activeId, chat.projectId]); const messages = chat.session?.messages || []; + const currentFailure = !chat.local && !chat.busy && chat.session?.id && chat.generation?.id && + chat.generation.failure && !messages.some(m => m.generationId === chat.generation.id && m.failure) + ? chat.generation.failure : null; const conversationStarted = Boolean( chat.activeId && chat.session?.id === chat.activeId && (messages.length || chat.busy || sidebarArtifacts.length || conversationRuns.length), @@ -1741,6 +1740,7 @@ export default function App() { live={chat.live} generation={chat.generation} finished + diagnosticMessage={currentFailure?.message} local={chat.local} readOnly={chat.readOnly} /> @@ -1749,7 +1749,7 @@ export default function App() { if (follow.current && scroll.current) scroll.current.scrollTop = scroll.current.scrollHeight; }} /> - {!chat.local && !chat.busy && chat.generation?.failure && !messages.some((m) => m.generationId === chat.generation.id && m.failure) ? : null} + {currentFailure ? : null} {!chat.local && !chat.readOnly && !chat.busy && chat.generation?.id && chat.generation.status === "cancelled" && !chat.generation.failure && !messages.some((m) => m.generationId === chat.generation.id) ? : null} { }); view.rerender(); expect(screen.getByText("中断原因")).toBeInTheDocument(); + chat.generation = { ...chat.generation, failure: { code: "TEST_ERROR", message: "中断原因" } }; + view.rerender(); + const diagnostics = screen.getByRole("region", { name: "本轮失败诊断" }); + expect(within(diagnostics).getByText("中断原因")).toBeInTheDocument(); + expect(screen.getAllByText("中断原因")).toHaveLength(1); + expect(screen.getByText("部分内容")).toBeInTheDocument(); + chat.generation = { ...chat.generation, error: "执行器已断开" }; + view.rerender(); + expect(screen.getByText("执行器已断开")).toBeInTheDocument(); Object.assign(chat, previous); }); diff --git a/docs/assets/qa/assistant-replies/failure-after.png b/docs/assets/qa/assistant-replies/failure-after.png new file mode 100644 index 000000000..599bfd862 Binary files /dev/null and b/docs/assets/qa/assistant-replies/failure-after.png differ diff --git a/docs/assets/qa/assistant-replies/failure-before.png b/docs/assets/qa/assistant-replies/failure-before.png new file mode 100644 index 000000000..239310b70 Binary files /dev/null and b/docs/assets/qa/assistant-replies/failure-before.png differ diff --git a/docs/assets/qa/assistant-replies/reply-after.png b/docs/assets/qa/assistant-replies/reply-after.png new file mode 100644 index 000000000..360cc9e0e Binary files /dev/null and b/docs/assets/qa/assistant-replies/reply-after.png differ diff --git a/e2e/ui/02-interactions.spec.mjs b/e2e/ui/02-interactions.spec.mjs index 510171dbe..b5bdfa49d 100644 --- a/e2e/ui/02-interactions.spec.mjs +++ b/e2e/ui/02-interactions.spec.mjs @@ -266,6 +266,7 @@ test('chat: asking AI about a failed run keeps the reply above the run alert', a track(`assistant session ${sid}`, () => del(`/api/assistant/sessions/${sid}`)); await put(`/api/assistant/sessions/${sid}`, { id: sid, title: `E2E 运行提醒 ${cfg.runTag}`, projectId: cfg.projectId, + executor: cfg.executor, model: cfg.modelID, messages: [ { role: 'user', content: '帮我跑一下这个 SOP' }, { role: 'assistant', content: JSON.stringify({ drafts: [], message: `已启动运行 ${run.id}` }) }, @@ -281,9 +282,21 @@ test('chat: asking AI about a failed run keeps the reply above the run alert', a : el.classList.contains('assistant') ? 'assistant' : '') .filter(Boolean).slice(-3).join(' > ')); await alert.getByRole('button', { name: '让 AI 分析' }).click(); + const submitted = page.waitForRequest(request => + request.method() === 'POST' && new URL(request.url()).pathname === '/api/assistant/generations'); await page.getByRole('button', { name: '发送消息' }).click(); + const payload = (await submitted).postDataJSON(); + expect(payload.executor).toBe(cfg.executor); + if (cfg.modelID) expect(payload.model).toBe(cfg.modelID); await expect.poll(tail).toBe('user > live > alert'); await expect.poll(tail, { timeout: 300_000 }).toBe('user > assistant > alert'); + // A provider error also renders an assistant message in this position. + const generation = await get(`/api/assistant/sessions/${sid}/generation?after=0`); + expect(generation.status, generation.failure?.code).toBe('completed'); + const saved = await get(`/api/assistant/sessions/${sid}`); + const reply = saved.messages.at(-1); + expect(reply.role).toBe('assistant'); + expect(reply.content.trim()).not.toBe(''); expect(errors).toEqual([]); });