From 5ec4f1cc8df0ff386819c320f41f7644bcd7efe9 Mon Sep 17 00:00:00 2001 From: Sihan He Date: Fri, 20 Dec 2024 11:55:07 +0800 Subject: [PATCH] Add flag for trace view Signed-off-by: Sihan He --- common/types/config.ts | 1 + .../generate_popover_body.tsx | 3 ++ public/tabs/chat/messages/message_action.tsx | 4 +- .../chat/messages/message_bubble.test.tsx | 47 +++++++++++++++++++ public/tabs/chat/messages/message_bubble.tsx | 5 +- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/common/types/config.ts b/common/types/config.ts index 2b92644f..698f00bf 100644 --- a/common/types/config.ts +++ b/common/types/config.ts @@ -9,6 +9,7 @@ export const configSchema = schema.object({ enabled: schema.boolean({ defaultValue: true }), chat: schema.object({ enabled: schema.boolean({ defaultValue: false }), + trace: schema.boolean({ defaultValue: true }), }), incontextInsight: schema.object({ enabled: schema.boolean({ defaultValue: true }), diff --git a/public/components/incontext_insight/generate_popover_body.tsx b/public/components/incontext_insight/generate_popover_body.tsx index ede3a119..7233fba3 100644 --- a/public/components/incontext_insight/generate_popover_body.tsx +++ b/public/components/incontext_insight/generate_popover_body.tsx @@ -321,6 +321,7 @@ export const GeneratePopoverBody: React.FC<{ }; const renderInnerFooter = () => { + const traceTip = 'Insight With RAG'; return ( { @@ -332,6 +333,7 @@ export const GeneratePopoverBody: React.FC<{ onViewTrace={() => { setShowInsight(true); }} + traceTip={traceTip} usageCollection={usageCollection} isOnTrace={showInsight} metricAppName={metricAppName} @@ -345,6 +347,7 @@ export const GeneratePopoverBody: React.FC<{ showFeedback showTraceIcon={insightAvailable} onViewTrace={() => {}} + traceTip={traceTip} usageCollection={usageCollection} isOnTrace={showInsight} metricAppName={metricAppName} diff --git a/public/tabs/chat/messages/message_action.tsx b/public/tabs/chat/messages/message_action.tsx index e2b84b24..d1cbdca9 100644 --- a/public/tabs/chat/messages/message_action.tsx +++ b/public/tabs/chat/messages/message_action.tsx @@ -22,6 +22,7 @@ interface MessageActionsProps { showTraceIcon?: boolean; isOnTrace?: boolean; traceInteractionId?: string; + traceTip?: string; onViewTrace?: () => void; shouldActionBarVisibleOnHover?: boolean; isFullWidth?: boolean; @@ -44,6 +45,7 @@ export const MessageActions: React.FC = ({ showTraceIcon = false, isOnTrace = false, traceInteractionId = null, + traceTip = 'info', onViewTrace, shouldActionBarVisibleOnHover = false, isFullWidth = false, @@ -146,7 +148,7 @@ export const MessageActions: React.FC = ({ trace: { show: showTraceIcon && onViewTrace, component: renderButtonWithTooltip( - 'Insight with RAG', + traceTip, ', () => { const reportUiStatsMock = jest.fn(); beforeEach(() => { + jest.spyOn(services, 'getConfigSchema').mockReturnValue({ chat: { trace: true } }); jest .spyOn(useFeedbackHookExports, 'useFeedback') .mockReturnValue({ feedbackResult: undefined, sendFeedback: sendFeedbackMock }); @@ -289,4 +291,49 @@ describe('', () => { ); expect(screen.queryByTestId('trace-icon-bar')).toBeNull(); }); + + it('should control view trace through config flag', () => { + render( + + ); + expect(screen.queryByTestId('trace-icon-bar1')).toBeVisible(); + + jest.spyOn(services, 'getConfigSchema').mockReturnValue({ chat: { trace: false } }); + render( + + ); + expect(screen.queryByTestId('trace-icon-bar2')).toBeNull(); + }); }); diff --git a/public/tabs/chat/messages/message_bubble.tsx b/public/tabs/chat/messages/message_bubble.tsx index d86997b1..7764325e 100644 --- a/public/tabs/chat/messages/message_bubble.tsx +++ b/public/tabs/chat/messages/message_bubble.tsx @@ -17,6 +17,7 @@ import React from 'react'; import { IconType } from '@elastic/eui/src/components/icon/icon'; import { MessageActions } from './message_action'; import { useCore } from '../../../contexts'; +import { getConfigSchema } from '../../../services'; // TODO: Replace with getChrome().logos.Chat.url import { useChatActions } from '../../../hooks'; @@ -123,6 +124,7 @@ export const MessageBubble: React.FC = React.memo((props) => } const fullWidth = props.message.fullWidth; + const configSchema = getConfigSchema(); return ( = React.memo((props) => interaction={props.interaction} message={props.message as IOutput} showFeedback={showFeedback} - showTraceIcon={!!props.message.interactionId} + showTraceIcon={configSchema.chat.trace && !!props.message.interactionId} + traceTip="How was this generated?" traceInteractionId={props.message.interactionId || ''} onViewTrace={() => { const message = props.message as IOutput;