Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Hide "stop generation" and regenerate button based on feature flag #414

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const configSchema = schema.object({
feedback: schema.boolean({ defaultValue: true }),
allowRenameConversation: schema.boolean({ defaultValue: true }),
deleteConversation: schema.boolean({ defaultValue: true }),
regenerateMessage: schema.boolean({ defaultValue: true }),
}),
incontextInsight: schema.object({
enabled: schema.boolean({ defaultValue: true }),
Expand Down
51 changes: 49 additions & 2 deletions public/tabs/chat/chat_page_content.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ import * as chatStateHookExports from '../../hooks/use_chat_state';
import * as chatActionHookExports from '../../hooks/use_chat_actions';
import { IMessage } from '../../../common/types/chat_saved_object_attributes';
import { getIncontextInsightRegistry } from '../../services';
import { setupConfigSchemaMock } from '../../../test/config_schema_mock';

jest.mock('../../services');

jest.mock('./messages/message_bubble', () => {
return {
MessageBubble: ({ children }: { children?: React.ReactNode }) => (
<div aria-label="chat message bubble">{children}</div>
MessageBubble: ({
children,
showRegenerate,
}: {
children?: React.ReactNode;
showRegenerate?: boolean;
}) => (
<div aria-label="chat message bubble" data-test-subj={`showRegenerate-${showRegenerate}`}>
{children}
</div>
),
};
});
Expand All @@ -37,6 +46,10 @@ describe('<ChatPageContent />', () => {
const abortActionMock = jest.fn();
const executeActionMock = jest.fn();

beforeAll(() => {
setupConfigSchemaMock();
});

beforeEach(() => {
jest.spyOn(chatContextExports, 'useChatContext').mockReturnValue({
conversationId: 'test_conversation_id',
Expand Down Expand Up @@ -226,4 +239,38 @@ describe('<ChatPageContent />', () => {
fireEvent.click(screen.getByText('What are the indices in my cluster?'));
expect(executeActionMock).toHaveBeenCalled();
});

it('should not show regenerate button when feature flag is false', () => {
setupConfigSchemaMock({
chat: {
regenerateMessage: false,
},
});

jest.spyOn(chatStateHookExports, 'useChatState').mockReturnValue({
chatState: {
messages: [
{
type: 'input',
content: 'what indices are in my cluster?',
contentType: 'text',
},
{
type: 'output',
content: 'here are the indices in your cluster: .kibana',
contentType: 'markdown',
suggestedActions: [{ actionType: 'send_as_input', message: 'suggested action mock' }],
},
],
llmResponding: true,
interactions: [],
},
chatStateDispatch: jest.fn(),
});

const { queryAllByTestId } = render(
<ChatPageContent messagesLoading={false} onRefresh={jest.fn()} />
);
expect(queryAllByTestId(`showRegenerate-false`).length).toEqual(2);
});
});
36 changes: 21 additions & 15 deletions public/tabs/chat/chat_page_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { MessageContent } from './messages/message_content';
import { SuggestionBubble } from './suggestions/suggestion_bubble';
import { getIncontextInsightRegistry } from '../../services';

import { getConfigSchema } from '../../services';

interface ChatPageContentProps {
messagesLoading: boolean;
messagesLoadingError?: Error;
Expand All @@ -37,6 +39,7 @@ export const ChatPageContent: React.FC<ChatPageContentProps> = React.memo((props
const loading = props.messagesLoading || chatState.llmResponding;
const chatActions = useChatActions();
const registry = getIncontextInsightRegistry();
const configSchema = getConfigSchema();

useLayoutEffect(() => {
pageEndRef.current?.scrollIntoView();
Expand Down Expand Up @@ -126,7 +129,7 @@ export const ChatPageContent: React.FC<ChatPageContentProps> = React.memo((props
<MessageBubble
message={message}
showActionBar={isChatOutput}
showRegenerate={isLatestOutput}
showRegenerate={isLatestOutput && configSchema.chat.regenerateMessage}
shouldActionBarVisibleOnHover={!isLatestOutput}
onRegenerate={chatActions.regenerate}
interaction={interaction}
Expand All @@ -144,20 +147,23 @@ export const ChatPageContent: React.FC<ChatPageContentProps> = React.memo((props
<MessageBubble loading showActionBar={false} />
</>
)}
{chatState.llmResponding && chatContext.conversationId && (
<div style={{ marginLeft: '55px', marginTop: 10 }}>
<EuiFlexGroup alignItems="flexStart" direction="column" gutterSize="s">
<EuiFlexItem>
<SuggestionBubble
content="Stop generating response"
color="default"
iconType="crossInACircleFilled"
onClick={() => chatActions.abortAction(chatContext.conversationId)}
/>
</EuiFlexItem>
</EuiFlexGroup>
</div>
)}

{configSchema.chat.regenerateMessage &&
chatState.llmResponding &&
chatContext.conversationId && (
<div style={{ marginLeft: '55px', marginTop: 10 }}>
<EuiFlexGroup alignItems="flexStart" direction="column" gutterSize="s">
<EuiFlexItem>
<SuggestionBubble
content="Stop generating response"
color="default"
iconType="crossInACircleFilled"
onClick={() => chatActions.abortAction(chatContext.conversationId)}
/>
</EuiFlexItem>
</EuiFlexGroup>
</div>
)}
{chatState.llmError && (
<EuiEmptyPrompt
iconType="alert"
Expand Down
1 change: 1 addition & 0 deletions test/config_schema_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const getMockConfigSchema = (
feedback: true,
allowRenameConversation: true,
deleteConversation: true,
regenerateMessage: true,
...(overrides.chat || {}),
},
incontextInsight: { enabled: true },
Expand Down
Loading