diff --git a/x-pack/packages/kbn-ai-assistant/src/chat/chat_body.tsx b/x-pack/packages/kbn-ai-assistant/src/chat/chat_body.tsx index e1cf3fa83f4bc..12cb747d148c4 100644 --- a/x-pack/packages/kbn-ai-assistant/src/chat/chat_body.tsx +++ b/x-pack/packages/kbn-ai-assistant/src/chat/chat_body.tsx @@ -136,7 +136,7 @@ export function ChatBody({ const { conversation, messages, next, state, stop, saveTitle } = useConversation({ initialConversationId, - ...(!initialConversationId ? { initialMessages } : {}), + initialMessages, initialTitle, chatService, connectorId: connectors.selectedConnector, diff --git a/x-pack/packages/kbn-ai-assistant/src/chat/chat_flyout.tsx b/x-pack/packages/kbn-ai-assistant/src/chat/chat_flyout.tsx index 1343f5ed9a4bb..8388ab71d2fd0 100644 --- a/x-pack/packages/kbn-ai-assistant/src/chat/chat_flyout.tsx +++ b/x-pack/packages/kbn-ai-assistant/src/chat/chat_flyout.tsx @@ -47,6 +47,7 @@ export function ChatFlyout({ isOpen, onClose, navigateToConversation, + hidePreviousConversations, }: { initialTitle: string; initialMessages: Message[]; @@ -54,6 +55,7 @@ export function ChatFlyout({ isOpen: boolean; onClose: () => void; navigateToConversation?: (conversationId?: string) => void; + hidePreviousConversations?: boolean; }) { const { euiTheme } = useEuiTheme(); const breakpoint = useCurrentEuiBreakpoint(); @@ -174,84 +176,86 @@ export function ChatFlyout({ }} > - - - setConversationsExpanded(!conversationsExpanded)} - /> - - } - /> - - {conversationsExpanded ? ( - { - conversationList.deleteConversation(deletedConversationId).then(() => { - if (deletedConversationId === conversationId) { - setConversationId(undefined); - } - }); - }} - onConversationSelect={(nextConversationId) => { - setConversationId(nextConversationId); - }} - /> - ) : ( + {!hidePreviousConversations ? ( + - { - setConversationId(undefined); - }} + className={expandButtonClassName} + color="text" + data-test-subj="observabilityAiAssistantChatFlyoutButton" + iconType={conversationsExpanded ? 'transitionLeftIn' : 'transitionLeftOut'} + onClick={() => setConversationsExpanded(!conversationsExpanded)} /> } - className={newChatButtonClassName} /> - )} - + + {conversationsExpanded ? ( + { + conversationList.deleteConversation(deletedConversationId).then(() => { + if (deletedConversationId === conversationId) { + setConversationId(undefined); + } + }); + }} + onConversationSelect={(nextConversationId) => { + setConversationId(nextConversationId); + }} + /> + ) : ( + + { + setConversationId(undefined); + }} + /> + + } + className={newChatButtonClassName} + /> + )} + + ) : null} diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/public/service/create_service.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/public/service/create_service.ts index 07f967a4028d9..d3a75c5336c59 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/public/service/create_service.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/public/service/create_service.ts @@ -36,7 +36,11 @@ export function createService({ const screenContexts$ = new BehaviorSubject([ { starterPrompts: defaultStarterPrompts }, ]); - const predefinedConversation$ = new Subject<{ messages: Message[]; title?: string }>(); + const predefinedConversation$ = new Subject<{ + messages: Message[]; + title?: string; + hidePreviousConversations?: boolean; + }>(); const scope$ = new BehaviorSubject(scopes); @@ -104,8 +108,16 @@ export function createService({ ); }, conversations: { - openNewConversation: ({ messages, title }: { messages: Message[]; title?: string }) => { - predefinedConversation$.next({ messages, title }); + openNewConversation: ({ + messages, + title, + hidePreviousConversations = false, + }: { + messages: Message[]; + title?: string; + hidePreviousConversations?: boolean; + }) => { + predefinedConversation$.next({ messages, title, hidePreviousConversations }); }, predefinedConversation$: predefinedConversation$.asObservable(), }, diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/public/types.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/public/types.ts index becc21f59c5f4..c6fd1de83aca9 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/public/types.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/public/types.ts @@ -91,8 +91,16 @@ export interface ObservabilityAIAssistantChatService { } export interface ObservabilityAIAssistantConversationService { - openNewConversation: ({}: { messages: Message[]; title?: string }) => void; - predefinedConversation$: Observable<{ messages: Message[]; title?: string }>; + openNewConversation: ({}: { + messages: Message[]; + title?: string; + hidePreviousConversations?: boolean; + }) => void; + predefinedConversation$: Observable<{ + messages: Message[]; + title?: string; + hidePreviousConversations?: boolean; + }>; } export interface ObservabilityAIAssistantService { diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_app/public/components/nav_control/index.tsx b/x-pack/plugins/observability_solution/observability_ai_assistant_app/public/components/nav_control/index.tsx index 883317c02274f..af530d6f567ba 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_app/public/components/nav_control/index.tsx +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_app/public/components/nav_control/index.tsx @@ -103,9 +103,12 @@ export function NavControl() { }; }, [service.conversations.predefinedConversation$]); - const { messages, title } = useObservable(service.conversations.predefinedConversation$) ?? { + const { messages, title, hidePreviousConversations } = useObservable( + service.conversations.predefinedConversation$ + ) ?? { messages: [], title: undefined, + hidePreviousConversations: false, }; const theme = useTheme(); @@ -171,6 +174,7 @@ export function NavControl() { ) ); }} + hidePreviousConversations={hidePreviousConversations} /> ) : undefined}