From c8ccfba96076ff908163f6a5067fa4c974f248e5 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 20 Jul 2026 16:07:12 +0800 Subject: [PATCH] fix: the input of agent chat would be replaced if conversation history updated (#39289) --- .../chat/answer/__tests__/operation.spec.tsx | 8 + .../base/chat/chat/answer/operation.tsx | 3 +- .../base/chat/chat/context-provider.tsx | 2 + web/app/components/base/chat/chat/context.ts | 1 + web/app/components/base/chat/chat/index.tsx | 3 + .../preview/__tests__/chat.spec.tsx | 270 ++++-- .../components/preview/build-chat.tsx | 105 ++- .../components/preview/chat-config.ts | 263 ++++++ .../components/preview/chat-conversation.tsx | 309 +++++++ .../components/preview/chat-history.ts | 161 ++++ .../components/preview/chat-runtime.tsx | 788 +----------------- .../components/preview/chat-session.tsx | 200 +++++ .../components/preview/preview-chat.tsx | 50 +- 13 files changed, 1254 insertions(+), 909 deletions(-) create mode 100644 web/features/agent-v2/agent-detail/configure/components/preview/chat-config.ts create mode 100644 web/features/agent-v2/agent-detail/configure/components/preview/chat-conversation.tsx create mode 100644 web/features/agent-v2/agent-detail/configure/components/preview/chat-history.ts create mode 100644 web/features/agent-v2/agent-detail/configure/components/preview/chat-session.tsx diff --git a/web/app/components/base/chat/chat/answer/__tests__/operation.spec.tsx b/web/app/components/base/chat/chat/answer/__tests__/operation.spec.tsx index 9b00d812c2f..32a6af71fed 100644 --- a/web/app/components/base/chat/chat/answer/__tests__/operation.spec.tsx +++ b/web/app/components/base/chat/chat/answer/__tests__/operation.spec.tsx @@ -177,6 +177,7 @@ const mockContextValue: ChatContextValue = { config: makeChatConfig({ supportFeedback: true }), onFeedback: vi.fn().mockResolvedValue(undefined), onRegenerate: vi.fn(), + showRegenerate: false, onAnnotationAdded: vi.fn(), onAnnotationEdited: vi.fn(), onAnnotationRemoved: vi.fn(), @@ -263,6 +264,7 @@ describe('Operation', () => { mockContextValue.onAnnotationEdited = vi.fn() mockContextValue.onAnnotationRemoved = vi.fn() mockContextValue.readonly = false + mockContextValue.showRegenerate = false mockProviderContext.plan.usage.annotatedResponse = 0 mockProviderContext.enableBilling = false mockAddAnnotation.mockResolvedValue({ id: 'ann-new', account: { name: 'Test User' } }) @@ -286,6 +288,12 @@ describe('Operation', () => { expect(screen.queryByRole('button', { name: 'operation.regenerate' })).not.toBeInTheDocument() }) + it('should show regenerate button when explicitly enabled without a chat input', () => { + mockContextValue.showRegenerate = true + renderOperation({ ...baseProps, noChatInput: true }) + expect(screen.getByRole('button', { name: 'operation.regenerate' })).toBeInTheDocument() + }) + it('should show TTS button when text_to_speech is enabled', () => { mockContextValue.config = makeChatConfig({ text_to_speech: { enabled: true } }) renderOperation() diff --git a/web/app/components/base/chat/chat/answer/operation.tsx b/web/app/components/base/chat/chat/answer/operation.tsx index a2bed1066c1..7d6f14b5556 100644 --- a/web/app/components/base/chat/chat/answer/operation.tsx +++ b/web/app/components/base/chat/chat/answer/operation.tsx @@ -86,6 +86,7 @@ function Operation({ onAnnotationRemoved, onFeedback, onRegenerate, + showRegenerate, readonly, } = useChatContext() const [isShowReplyModal, setIsShowReplyModal] = useState(false) @@ -389,7 +390,7 @@ function Operation({