From 7f3c2d538736b62f83ccd488df165611eb8441a9 Mon Sep 17 00:00:00 2001 From: Marco Antonio Ghiani Date: Tue, 31 Oct 2023 13:39:15 +0100 Subject: [PATCH 1/8] feat(logs-shared): extract LogAIAssistant component --- .../components/log_ai_assistant/index.tsx | 25 ++++ .../log_ai_assistant/log_ai_assistant.tsx | 82 +++++++++++++ .../log_ai_assistant/translations.ts | 21 ++++ .../log_entry_flyout/log_entry_flyout.tsx | 109 +++--------------- x-pack/plugins/logs_shared/public/index.ts | 4 + x-pack/plugins/logs_shared/public/plugin.ts | 13 ++- x-pack/plugins/logs_shared/public/types.ts | 2 + 7 files changed, 162 insertions(+), 94 deletions(-) create mode 100644 x-pack/plugins/logs_shared/public/components/log_ai_assistant/index.tsx create mode 100644 x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx create mode 100644 x-pack/plugins/logs_shared/public/components/log_ai_assistant/translations.ts diff --git a/x-pack/plugins/logs_shared/public/components/log_ai_assistant/index.tsx b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/index.tsx new file mode 100644 index 0000000000000..a4df6c50cbafd --- /dev/null +++ b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/index.tsx @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import React from 'react'; +import { Optional } from '@kbn/utility-types'; +import { dynamic } from '../../../common/dynamic'; +import type { LogAIAssistantProps } from './log_ai_assistant'; + +export const LogAIAssistant = dynamic(() => import('./log_ai_assistant')); + +interface LogAIAssistantFactoryDeps { + observabilityAIAssistant: LogAIAssistantProps['aiAssistant']; +} + +export function createLogAIAssistant({ observabilityAIAssistant }: LogAIAssistantFactoryDeps) { + return ({ + aiAssistant = observabilityAIAssistant, + ...props + }: Optional) => ( + + ); +} diff --git a/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx new file mode 100644 index 0000000000000..7e4e28294d748 --- /dev/null +++ b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx @@ -0,0 +1,82 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { useMemo } from 'react'; +import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { + ContextualInsight, + type Message, + ObservabilityAIAssistantPluginStart, + MessageRole, +} from '@kbn/observability-ai-assistant-plugin/public'; +import { LogEntry } from '../../../common/search_strategies/log_entries/log_entry'; +import { explainLogMessageTitle, similarLogMessagesTitle } from './translations'; + +export interface LogAIAssistantProps { + aiAssistant: ObservabilityAIAssistantPluginStart; + doc: LogEntry | undefined; +} + +export function LogAIAssistant({ aiAssistant, doc }: LogAIAssistantProps) { + const explainLogMessageMessages = useMemo(() => { + if (!doc) { + return undefined; + } + + const now = new Date().toISOString(); + + return [ + { + '@timestamp': now, + message: { + role: MessageRole.User, + content: `I'm looking at a log entry. Can you explain me what the log message means? Where it could be coming from, whether it is expected and whether it is an issue. Here's the context, serialized: ${JSON.stringify( + { logEntry: { fields: doc.fields } } + )} `, + }, + }, + ]; + }, [doc]); + + const similarLogMessageMessages = useMemo(() => { + if (!doc) { + return undefined; + } + + const now = new Date().toISOString(); + + const message = doc.fields.find((field) => field.field === 'message')?.value[0]; + + return [ + { + '@timestamp': now, + message: { + role: MessageRole.User, + content: `I'm looking at a log entry. Can you construct a Kibana KQL query that I can enter in the search bar that gives me similar log entries, based on the \`message\` field: ${message}`, + }, + }, + ]; + }, [doc]); + + return ( + + {aiAssistant.isEnabled() && explainLogMessageMessages ? ( + + + + ) : null} + {aiAssistant.isEnabled() && similarLogMessageMessages ? ( + + + + ) : null} + + ); +} + +// eslint-disable-next-line import/no-default-export +export default LogAIAssistant; diff --git a/x-pack/plugins/logs_shared/public/components/log_ai_assistant/translations.ts b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/translations.ts new file mode 100644 index 0000000000000..db6e6b9be1ecf --- /dev/null +++ b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/translations.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { i18n } from '@kbn/i18n'; + +export const explainLogMessageTitle = i18n.translate( + 'xpack.logsShared.logFlyout.explainLogMessageTitle', + { + defaultMessage: "What's this message?", + } +); + +export const similarLogMessagesTitle = i18n.translate( + 'xpack.logsShared.logFlyout.similarLogMessagesTitle', + { + defaultMessage: 'How do I find similar log messages?', + } +); diff --git a/x-pack/plugins/logs_shared/public/components/logging/log_entry_flyout/log_entry_flyout.tsx b/x-pack/plugins/logs_shared/public/components/logging/log_entry_flyout/log_entry_flyout.tsx index 2573ef02aaf01..62634f2aeba13 100644 --- a/x-pack/plugins/logs_shared/public/components/logging/log_entry_flyout/log_entry_flyout.tsx +++ b/x-pack/plugins/logs_shared/public/components/logging/log_entry_flyout/log_entry_flyout.tsx @@ -16,26 +16,19 @@ import { EuiTitle, } from '@elastic/eui'; import { OverlayRef } from '@kbn/core/public'; -import { DataPublicPluginStart } from '@kbn/data-plugin/public'; import type { Query } from '@kbn/es-query'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; -import { createKibanaReactContext, useKibana } from '@kbn/kibana-react-plugin/public'; -import { - ContextualInsight, - MessageRole, - ObservabilityAIAssistantPluginStart, - ObservabilityAIAssistantProvider, - useObservabilityAIAssistant, - type Message, -} from '@kbn/observability-ai-assistant-plugin/public'; -import React, { useCallback, useEffect, useMemo, useRef } from 'react'; +import { createKibanaReactContext } from '@kbn/kibana-react-plugin/public'; +import React, { useCallback, useEffect, useRef } from 'react'; +import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; import { LogViewReference } from '../../../../common/log_views'; import { TimeKey } from '../../../../common/time'; import { useLogEntry } from '../../../containers/logs/log_entry'; import { CenteredEuiFlyoutBody } from '../../centered_flyout_body'; import { DataSearchErrorCallout } from '../../data_search_error_callout'; import { DataSearchProgress } from '../../data_search_progress'; +import LogAIAssistant from '../../log_ai_assistant/log_ai_assistant'; import { LogEntryActionsMenu } from './log_entry_actions_menu'; import { LogEntryFieldsTable } from './log_entry_fields_table'; @@ -51,10 +44,7 @@ export const useLogEntryFlyout = (logViewReference: LogViewReference) => { const { services: { http, data, uiSettings, application, observabilityAIAssistant }, overlays: { openFlyout }, - } = useKibana<{ - data: DataPublicPluginStart; - observabilityAIAssistant?: ObservabilityAIAssistantPluginStart; - }>(); + } = useKibanaContextForPlugin(); const closeLogEntryFlyout = useCallback(() => { flyoutRef.current?.close(); @@ -67,17 +57,16 @@ export const useLogEntryFlyout = (logViewReference: LogViewReference) => { data, uiSettings, application, + observabilityAIAssistant, }); flyoutRef.current = openFlyout( - - - + ); }, @@ -111,6 +100,10 @@ export const LogEntryFlyout = ({ onSetFieldFilter, logViewReference, }: LogEntryFlyoutProps) => { + const { + services: { observabilityAIAssistant }, + } = useKibanaContextForPlugin(); + const { cancelRequest: cancelLogEntryRequest, errors: logEntryErrors, @@ -130,48 +123,6 @@ export const LogEntryFlyout = ({ } }, [fetchLogEntry, logViewReference, logEntryId]); - const explainLogMessageMessages = useMemo(() => { - if (!logEntry) { - return undefined; - } - - const now = new Date().toISOString(); - - return [ - { - '@timestamp': now, - message: { - role: MessageRole.User, - content: `I'm looking at a log entry. Can you explain me what the log message means? Where it could be coming from, whether it is expected and whether it is an issue. Here's the context, serialized: ${JSON.stringify( - { logEntry: { fields: logEntry.fields } } - )} `, - }, - }, - ]; - }, [logEntry]); - - const similarLogMessageMessages = useMemo(() => { - if (!logEntry) { - return undefined; - } - - const now = new Date().toISOString(); - - const message = logEntry.fields.find((field) => field.field === 'message')?.value[0]; - - return [ - { - '@timestamp': now, - message: { - role: MessageRole.User, - content: `I'm looking at a log entry. Can you construct a Kibana KQL query that I can enter in the search bar that gives me similar log entries, based on the \`message\` field: ${message}`, - }, - }, - ]; - }, [logEntry]); - - const aiAssistant = useObservabilityAIAssistant(); - return ( @@ -232,22 +183,9 @@ export const LogEntryFlyout = ({ } > - {aiAssistant.isEnabled() && explainLogMessageMessages ? ( - - - - ) : null} - {aiAssistant.isEnabled() && similarLogMessageMessages ? ( - - - - ) : null} + + + @@ -268,17 +206,6 @@ export const LogEntryFlyout = ({ ); }; -const explainLogMessageTitle = i18n.translate('xpack.logsShared.logFlyout.explainLogMessageTitle', { - defaultMessage: "What's this message?", -}); - -const similarLogMessagesTitle = i18n.translate( - 'xpack.logsShared.logFlyout.similarLogMessagesTitle', - { - defaultMessage: 'How do I find similar log messages?', - } -); - const loadingProgressMessage = i18n.translate('xpack.logsShared.logFlyout.loadingMessage', { defaultMessage: 'Searching log entry in shards', }); diff --git a/x-pack/plugins/logs_shared/public/index.ts b/x-pack/plugins/logs_shared/public/index.ts index 708dc52b2c7f0..873d202b1af7d 100644 --- a/x-pack/plugins/logs_shared/public/index.ts +++ b/x-pack/plugins/logs_shared/public/index.ts @@ -46,8 +46,12 @@ export { useColumnWidths, } from './components/logging/log_text_stream/log_entry_column'; export { LogEntryFlyout } from './components/logging/log_entry_flyout'; +export type { LogAIAssistantProps } from './components/log_ai_assistant/log_ai_assistant'; export type { LogStreamProps } from './components/log_stream/log_stream'; +export const LogAIAssistant = dynamic( + () => import('./components/log_ai_assistant/log_ai_assistant') +); export const LogStream = dynamic(() => import('./components/log_stream/log_stream')); export const LogColumnHeader = dynamic( () => import('./components/logging/log_text_stream/column_headers') diff --git a/x-pack/plugins/logs_shared/public/plugin.ts b/x-pack/plugins/logs_shared/public/plugin.ts index 47ded2e3df835..092e95570db7f 100644 --- a/x-pack/plugins/logs_shared/public/plugin.ts +++ b/x-pack/plugins/logs_shared/public/plugin.ts @@ -6,6 +6,7 @@ */ import { CoreStart } from '@kbn/core/public'; +import { createLogAIAssistant } from './components/log_ai_assistant'; import { LogViewsService } from './services/log_views'; import { LogsSharedClientPluginClass, LogsSharedClientStartDeps } from './types'; @@ -23,14 +24,20 @@ export class LogsSharedPlugin implements LogsSharedClientPluginClass { } public start(core: CoreStart, plugins: LogsSharedClientStartDeps) { + const { http } = core; + const { data, dataViews, observabilityAIAssistant } = plugins; + const logViews = this.logViews.start({ - http: core.http, - dataViews: plugins.dataViews, - search: plugins.data.search, + http, + dataViews, + search: data.search, }); + const LogAIAssistant = createLogAIAssistant({ observabilityAIAssistant }); + return { logViews, + LogAIAssistant, }; } diff --git a/x-pack/plugins/logs_shared/public/types.ts b/x-pack/plugins/logs_shared/public/types.ts index f2563ccb3433f..e67f83e4becc0 100644 --- a/x-pack/plugins/logs_shared/public/types.ts +++ b/x-pack/plugins/logs_shared/public/types.ts @@ -15,6 +15,7 @@ import type { CoreSetup, CoreStart, Plugin as PluginClass } from '@kbn/core/public'; import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; +import { ObservabilityAIAssistantPluginStart } from '@kbn/observability-ai-assistant-plugin/public'; import { UiActionsStart } from '@kbn/ui-actions-plugin/public'; // import type { OsqueryPluginStart } from '../../osquery/public'; import { LogViewsServiceSetup, LogViewsServiceStart } from './services/log_views'; @@ -34,6 +35,7 @@ export interface LogsSharedClientSetupDeps {} export interface LogsSharedClientStartDeps { data: DataPublicPluginStart; dataViews: DataViewsPublicPluginStart; + observabilityAIAssistant: ObservabilityAIAssistantPluginStart; uiActions: UiActionsStart; } From d9f7777ad1a636aa62d59d376f60c4683d17e6b7 Mon Sep 17 00:00:00 2001 From: Marco Antonio Ghiani Date: Fri, 3 Nov 2023 11:01:34 +0100 Subject: [PATCH 2/8] feat(logs-shared): finalize component extraction --- .../components/log_ai_assistant/log_ai_assistant.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx index 7e4e28294d748..bce36a6d28dc6 100644 --- a/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx +++ b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx @@ -13,12 +13,16 @@ import { ObservabilityAIAssistantPluginStart, MessageRole, } from '@kbn/observability-ai-assistant-plugin/public'; -import { LogEntry } from '../../../common/search_strategies/log_entries/log_entry'; +import { LogEntryField } from '../../../common'; import { explainLogMessageTitle, similarLogMessagesTitle } from './translations'; +export interface LogAIAssistantDocument { + fields: LogEntryField[]; +} + export interface LogAIAssistantProps { aiAssistant: ObservabilityAIAssistantPluginStart; - doc: LogEntry | undefined; + doc: LogAIAssistantDocument | undefined; } export function LogAIAssistant({ aiAssistant, doc }: LogAIAssistantProps) { From 6840a02e666ac3604da677ed9ce8e87634eae201 Mon Sep 17 00:00:00 2001 From: Marco Antonio Ghiani Date: Mon, 6 Nov 2023 17:11:46 +0100 Subject: [PATCH 3/8] feat(log-explorer): wip ai assistant integration --- .../components/log_explorer/customizations.ts | 0 .../components/log_explorer/log_explorer.tsx | 8 +++-- .../public/components/log_explorer/types.ts | 25 +++++++++++++++ .../customizations/custom_flyout_content.tsx | 32 +++++++++++++------ .../customizations/log_explorer_profile.tsx | 14 ++++++-- .../hooks/use_log_explorer_customizations.ts | 17 ++++++++++ x-pack/plugins/log_explorer/public/index.ts | 4 +++ .../observability_log_explorer/kibana.jsonc | 1 + .../flyout_content.tsx | 31 ++++++++++++++++++ .../log_explorer_customizations/index.ts | 15 +++++++++ .../public/routes/main/main_route.tsx | 18 +++++++++-- 11 files changed, 148 insertions(+), 17 deletions(-) create mode 100644 x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts create mode 100644 x-pack/plugins/log_explorer/public/components/log_explorer/types.ts create mode 100644 x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts create mode 100644 x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx create mode 100644 x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/index.ts diff --git a/x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts b/x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/x-pack/plugins/log_explorer/public/components/log_explorer/log_explorer.tsx b/x-pack/plugins/log_explorer/public/components/log_explorer/log_explorer.tsx index 0612713085224..57736dd4b96dd 100644 --- a/x-pack/plugins/log_explorer/public/components/log_explorer/log_explorer.tsx +++ b/x-pack/plugins/log_explorer/public/components/log_explorer/log_explorer.tsx @@ -17,6 +17,7 @@ import { createLogExplorerProfileCustomizations } from '../../customizations/log import { createPropertyGetProxy } from '../../utils/proxies'; import { LogExplorerProfileContext } from '../../state_machines/log_explorer_profile'; import { LogExplorerStartDeps } from '../../types'; +import { LogExplorerCustomizations } from './types'; export interface CreateLogExplorerArgs { core: CoreStart; @@ -29,6 +30,7 @@ export interface LogExplorerStateContainer { } export interface LogExplorerProps { + customizations?: LogExplorerCustomizations; scopedHistory: ScopedHistory; state$?: BehaviorSubject; } @@ -44,10 +46,10 @@ export const createLogExplorer = ({ core, plugins }: CreateLogExplorerArgs) => { uiSettings: createUiSettingsServiceProxy(core.uiSettings), }; - return ({ scopedHistory, state$ }: LogExplorerProps) => { + return ({ customizations = {}, scopedHistory, state$ }: LogExplorerProps) => { const logExplorerCustomizations = useMemo( - () => [createLogExplorerProfileCustomizations({ core, plugins, state$ })], - [state$] + () => [createLogExplorerProfileCustomizations({ core, customizations, plugins, state$ })], + [customizations, state$] ); return ( diff --git a/x-pack/plugins/log_explorer/public/components/log_explorer/types.ts b/x-pack/plugins/log_explorer/public/components/log_explorer/types.ts new file mode 100644 index 0000000000000..2b366cce7c55c --- /dev/null +++ b/x-pack/plugins/log_explorer/public/components/log_explorer/types.ts @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { DataTableRecord } from '@kbn/discover-utils/types'; + +export type RenderPreviousContent = () => React.ReactNode; + +export interface LogExplorerFlyoutContentProps { + doc: DataTableRecord; +} + +export type FlyoutRenderContent = ( + renderPreviousContent: RenderPreviousContent, + props: LogExplorerFlyoutContentProps +) => React.ReactNode; + +export interface LogExplorerCustomizations { + flyout?: { + renderContent?: FlyoutRenderContent; + }; +} diff --git a/x-pack/plugins/log_explorer/public/customizations/custom_flyout_content.tsx b/x-pack/plugins/log_explorer/public/customizations/custom_flyout_content.tsx index a4b473119744a..8c35ae3a8eead 100644 --- a/x-pack/plugins/log_explorer/public/customizations/custom_flyout_content.tsx +++ b/x-pack/plugins/log_explorer/public/customizations/custom_flyout_content.tsx @@ -5,10 +5,11 @@ * 2.0. */ -import React from 'react'; +import React, { useCallback } from 'react'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { FlyoutDetail } from '../components/flyout_detail/flyout_detail'; import { FlyoutProps } from '../components/flyout_detail'; +import { useLogExplorerCustomizationsContext } from '../hooks/use_log_explorer_customizations'; export const CustomFlyoutContent = ({ actions, @@ -16,16 +17,27 @@ export const CustomFlyoutContent = ({ doc, renderDefaultContent, }: FlyoutProps) => { - return ( - - {/* Apply custom Log Explorer detail */} - - - - {/* Restore default content */} - {renderDefaultContent()} - + const { flyout } = useLogExplorerCustomizationsContext(); + + const renderPreviousContent = useCallback( + () => ( + <> + {/* Apply custom Log Explorer detail */} + + + + {/* Restore default content */} + {renderDefaultContent()} + + ), + [actions, dataView, doc, renderDefaultContent] ); + + const content = flyout?.renderContent + ? flyout?.renderContent(renderPreviousContent, { doc }) + : renderPreviousContent(); + + return {content}; }; // eslint-disable-next-line import/no-default-export diff --git a/x-pack/plugins/log_explorer/public/customizations/log_explorer_profile.tsx b/x-pack/plugins/log_explorer/public/customizations/log_explorer_profile.tsx index 85d1284752977..ed770d1790ce9 100644 --- a/x-pack/plugins/log_explorer/public/customizations/log_explorer_profile.tsx +++ b/x-pack/plugins/log_explorer/public/customizations/log_explorer_profile.tsx @@ -14,6 +14,8 @@ import { LogExplorerProfileStateService } from '../state_machines/log_explorer_p import { LogExplorerStateContainer } from '../components/log_explorer'; import { LogExplorerStartDeps } from '../types'; import { useKibanaContextForPluginProvider } from '../utils/use_kibana'; +import { LogExplorerCustomizations } from '../components/log_explorer/types'; +import { LogExplorerCustomizationsProvider } from '../hooks/use_log_explorer_customizations'; const LazyCustomDatasetFilters = dynamic(() => import('./custom_dataset_filters')); const LazyCustomDatasetSelector = dynamic(() => import('./custom_dataset_selector')); @@ -21,12 +23,18 @@ const LazyCustomFlyoutContent = dynamic(() => import('./custom_flyout_content')) export interface CreateLogExplorerProfileCustomizationsDeps { core: CoreStart; + customizations?: LogExplorerCustomizations; plugins: LogExplorerStartDeps; state$?: BehaviorSubject; } export const createLogExplorerProfileCustomizations = - ({ core, plugins, state$ }: CreateLogExplorerProfileCustomizationsDeps): CustomizationCallback => + ({ + core, + customizations: logExplorerCustomizations, + plugins, + state$, + }: CreateLogExplorerProfileCustomizationsDeps): CustomizationCallback => async ({ customizations, stateContainer }) => { const { data, dataViews, discover } = plugins; // Lazy load dependencies @@ -127,7 +135,9 @@ export const createLogExplorerProfileCustomizations = return ( - + + + ); }, diff --git a/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts b/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts new file mode 100644 index 0000000000000..0557e17761cb4 --- /dev/null +++ b/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import createContainer from 'constate'; +import { LogExplorerCustomizations } from '../components/log_explorer/types'; + +interface UseLogExplorerCustomizationsDeps { + value: LogExplorerCustomizations; +} + +const useLogExplorerCustomizations = ({ value }: UseLogExplorerCustomizationsDeps) => value; + +export const [LogExplorerCustomizationsProvider, useLogExplorerCustomizationsContext] = + createContainer(useLogExplorerCustomizations); diff --git a/x-pack/plugins/log_explorer/public/index.ts b/x-pack/plugins/log_explorer/public/index.ts index 00750926517e6..1ca7f37aa4c9b 100644 --- a/x-pack/plugins/log_explorer/public/index.ts +++ b/x-pack/plugins/log_explorer/public/index.ts @@ -10,6 +10,10 @@ import type { LogExplorerConfig } from '../common/plugin_config'; import { LogExplorerPlugin } from './plugin'; export type { LogExplorerPluginSetup, LogExplorerPluginStart } from './types'; export type { LogExplorerStateContainer } from './components/log_explorer'; +export type { + LogExplorerCustomizations, + LogExplorerFlyoutContentProps, +} from './components/log_explorer/types'; export function plugin(context: PluginInitializerContext) { return new LogExplorerPlugin(context); diff --git a/x-pack/plugins/observability_log_explorer/kibana.jsonc b/x-pack/plugins/observability_log_explorer/kibana.jsonc index 7ac940de86dd4..6f871e114a035 100644 --- a/x-pack/plugins/observability_log_explorer/kibana.jsonc +++ b/x-pack/plugins/observability_log_explorer/kibana.jsonc @@ -15,6 +15,7 @@ "data", "discover", "logExplorer", + "logsShared", "observabilityShared", "share", "kibanaUtils", diff --git a/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx b/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx new file mode 100644 index 0000000000000..e0cb6aa9e6975 --- /dev/null +++ b/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx @@ -0,0 +1,31 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { + LogExplorerCustomizations, + LogExplorerFlyoutContentProps, +} from '@kbn/log-explorer-plugin/public'; +import React from 'react'; +import { useKibanaContextForPlugin } from '../utils/use_kibana'; + +const ObservabilityLogAIAssistant = ({ doc }: LogExplorerFlyoutContentProps) => { + const { services } = useKibanaContextForPlugin(); + const { LogAIAssistant } = services.logsShared; + + return ; +}; + +export const renderFlyoutContent: Required['flyout']['renderContent'] = ( + renderPreviousContent, + props +) => { + return ( + <> + {renderPreviousContent()} + + + ); +}; diff --git a/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/index.ts b/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/index.ts new file mode 100644 index 0000000000000..a86b47e92cf01 --- /dev/null +++ b/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/index.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { LogExplorerCustomizations } from '@kbn/log-explorer-plugin/public'; +import { renderFlyoutContent } from './flyout_content'; + +export const createLogExplorerCustomizations = (): LogExplorerCustomizations => ({ + flyout: { + renderContent: renderFlyoutContent, + }, +}); diff --git a/x-pack/plugins/observability_log_explorer/public/routes/main/main_route.tsx b/x-pack/plugins/observability_log_explorer/public/routes/main/main_route.tsx index aece8474f0390..020cf5a868e6d 100644 --- a/x-pack/plugins/observability_log_explorer/public/routes/main/main_route.tsx +++ b/x-pack/plugins/observability_log_explorer/public/routes/main/main_route.tsx @@ -6,8 +6,9 @@ */ import { CoreStart } from '@kbn/core/public'; -import React, { useState } from 'react'; +import React, { useMemo, useState } from 'react'; import { BehaviorSubject } from 'rxjs'; +import { LogExplorerCustomizations } from '@kbn/log-explorer-plugin/public'; import { LogExplorerTopNavMenu } from '../../components/log_explorer_top_nav_menu'; import { ObservabilityLogExplorerPageTemplate } from '../../components/page_template'; import { noBreadcrumbs, useBreadcrumbs } from '../../utils/breadcrumbs'; @@ -31,6 +32,15 @@ export const ObservablityLogExplorerMainRoute = ({ const [state$] = useState(() => new BehaviorSubject({})); + const customizations: LogExplorerCustomizations = useMemo( + () => ({ + flyout: { + renderContent: (renderPreviousContent) => renderPreviousContent(), + }, + }), + [] + ); + return ( <> - + ); From 40ad917534fbe7c3ad8e56fc59d89dad3e2b4911 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:56:29 +0000 Subject: [PATCH 4/8] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../public/components/log_explorer/customizations.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts b/x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts index e69de29bb2d1d..1fec1c76430eb 100644 --- a/x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts +++ b/x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts @@ -0,0 +1,6 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ From 966bb1a553ae03c3f28161facf9059f203d65e40 Mon Sep 17 00:00:00 2001 From: Marco Antonio Ghiani Date: Tue, 7 Nov 2023 12:05:46 +0100 Subject: [PATCH 5/8] feat(log-explorer): mvp ai assistant integration --- .../customizations/custom_flyout_content.tsx | 13 +++++++--- .../hooks/use_log_explorer_customizations.ts | 4 +-- .../components/log_ai_assistant/index.tsx | 21 ++++++++------- .../log_ai_assistant.mock.tsx} | 4 +++ .../log_ai_assistant/log_ai_assistant.tsx | 26 ++++++++++++++++--- .../log_entry_flyout/log_entry_flyout.tsx | 2 +- x-pack/plugins/logs_shared/public/index.ts | 1 + x-pack/plugins/logs_shared/public/mocks.tsx | 2 ++ x-pack/plugins/logs_shared/public/types.ts | 2 ++ .../flyout_content.tsx | 26 ++++++++++++++++--- .../public/routes/main/main_route.tsx | 11 ++------ .../public/types.ts | 2 ++ 12 files changed, 83 insertions(+), 31 deletions(-) rename x-pack/plugins/{log_explorer/public/components/log_explorer/customizations.ts => logs_shared/public/components/log_ai_assistant/log_ai_assistant.mock.tsx} (69%) diff --git a/x-pack/plugins/log_explorer/public/customizations/custom_flyout_content.tsx b/x-pack/plugins/log_explorer/public/customizations/custom_flyout_content.tsx index 8c35ae3a8eead..e7a5b7ed35915 100644 --- a/x-pack/plugins/log_explorer/public/customizations/custom_flyout_content.tsx +++ b/x-pack/plugins/log_explorer/public/customizations/custom_flyout_content.tsx @@ -26,18 +26,23 @@ export const CustomFlyoutContent = ({ - {/* Restore default content */} - {renderDefaultContent()} ), - [actions, dataView, doc, renderDefaultContent] + [actions, dataView, doc] ); const content = flyout?.renderContent ? flyout?.renderContent(renderPreviousContent, { doc }) : renderPreviousContent(); - return {content}; + return ( + + {/* Apply custom Log Explorer detail */} + {content} + {/* Restore default content */} + {renderDefaultContent()} + + ); }; // eslint-disable-next-line import/no-default-export diff --git a/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts b/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts index 0557e17761cb4..9f00a369e1cf1 100644 --- a/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts +++ b/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts @@ -8,10 +8,10 @@ import createContainer from 'constate'; import { LogExplorerCustomizations } from '../components/log_explorer/types'; interface UseLogExplorerCustomizationsDeps { - value: LogExplorerCustomizations; + value?: LogExplorerCustomizations; } -const useLogExplorerCustomizations = ({ value }: UseLogExplorerCustomizationsDeps) => value; +const useLogExplorerCustomizations = ({ value = {} }: UseLogExplorerCustomizationsDeps) => value; export const [LogExplorerCustomizationsProvider, useLogExplorerCustomizationsContext] = createContainer(useLogExplorerCustomizations); diff --git a/x-pack/plugins/logs_shared/public/components/log_ai_assistant/index.tsx b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/index.tsx index a4df6c50cbafd..8cf9b2da45c06 100644 --- a/x-pack/plugins/logs_shared/public/components/log_ai_assistant/index.tsx +++ b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/index.tsx @@ -4,22 +4,25 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import React from 'react'; +import React, { ComponentType } from 'react'; import { Optional } from '@kbn/utility-types'; import { dynamic } from '../../../common/dynamic'; -import type { LogAIAssistantProps } from './log_ai_assistant'; +import type { LogAIAssistantDeps } from './log_ai_assistant'; export const LogAIAssistant = dynamic(() => import('./log_ai_assistant')); interface LogAIAssistantFactoryDeps { - observabilityAIAssistant: LogAIAssistantProps['aiAssistant']; + observabilityAIAssistant: LogAIAssistantDeps['observabilityAIAssistant']; } -export function createLogAIAssistant({ observabilityAIAssistant }: LogAIAssistantFactoryDeps) { - return ({ - aiAssistant = observabilityAIAssistant, - ...props - }: Optional) => ( - +export type LogAIAssistantComponent = ComponentType< + Optional +>; + +export function createLogAIAssistant({ + observabilityAIAssistant: aiAssistant, +}: LogAIAssistantFactoryDeps): LogAIAssistantComponent { + return ({ observabilityAIAssistant = aiAssistant, ...props }) => ( + ); } diff --git a/x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.mock.tsx similarity index 69% rename from x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts rename to x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.mock.tsx index 1fec1c76430eb..9ece10dff8188 100644 --- a/x-pack/plugins/log_explorer/public/components/log_explorer/customizations.ts +++ b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.mock.tsx @@ -4,3 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ + +import React from 'react'; + +export const createLogAIAssistantMock = () => jest.fn().mockReturnValue(
); diff --git a/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx index bce36a6d28dc6..335a02ab3a05e 100644 --- a/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx +++ b/x-pack/plugins/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx @@ -12,6 +12,8 @@ import { type Message, ObservabilityAIAssistantPluginStart, MessageRole, + ObservabilityAIAssistantProvider, + useObservabilityAIAssistant, } from '@kbn/observability-ai-assistant-plugin/public'; import { LogEntryField } from '../../../common'; import { explainLogMessageTitle, similarLogMessagesTitle } from './translations'; @@ -21,11 +23,16 @@ export interface LogAIAssistantDocument { } export interface LogAIAssistantProps { - aiAssistant: ObservabilityAIAssistantPluginStart; doc: LogAIAssistantDocument | undefined; } -export function LogAIAssistant({ aiAssistant, doc }: LogAIAssistantProps) { +export interface LogAIAssistantDeps extends LogAIAssistantProps { + observabilityAIAssistant: ObservabilityAIAssistantPluginStart; +} + +export const LogAIAssistant = withProviders(({ doc }: LogAIAssistantProps) => { + const aiAssistant = useObservabilityAIAssistant(); + const explainLogMessageMessages = useMemo(() => { if (!doc) { return undefined; @@ -80,7 +87,20 @@ export function LogAIAssistant({ aiAssistant, doc }: LogAIAssistantProps) { ) : null} ); -} +}); // eslint-disable-next-line import/no-default-export export default LogAIAssistant; + +function withProviders(Component: React.FunctionComponent) { + return function ComponentWithProviders({ + observabilityAIAssistant, + ...props + }: LogAIAssistantDeps) { + return ( + + + + ); + }; +} diff --git a/x-pack/plugins/logs_shared/public/components/logging/log_entry_flyout/log_entry_flyout.tsx b/x-pack/plugins/logs_shared/public/components/logging/log_entry_flyout/log_entry_flyout.tsx index 62634f2aeba13..b66e864c2a499 100644 --- a/x-pack/plugins/logs_shared/public/components/logging/log_entry_flyout/log_entry_flyout.tsx +++ b/x-pack/plugins/logs_shared/public/components/logging/log_entry_flyout/log_entry_flyout.tsx @@ -184,7 +184,7 @@ export const LogEntryFlyout = ({ > - + diff --git a/x-pack/plugins/logs_shared/public/index.ts b/x-pack/plugins/logs_shared/public/index.ts index 873d202b1af7d..58f22fe48bccb 100644 --- a/x-pack/plugins/logs_shared/public/index.ts +++ b/x-pack/plugins/logs_shared/public/index.ts @@ -37,6 +37,7 @@ export { useLogSummary, WithSummary } from './containers/logs/log_summary'; export { useLogEntryFlyout } from './components/logging/log_entry_flyout'; // Shared components +export type { LogAIAssistantDocument } from './components/log_ai_assistant/log_ai_assistant'; export type { LogEntryStreamItem, LogEntryColumnWidths, diff --git a/x-pack/plugins/logs_shared/public/mocks.tsx b/x-pack/plugins/logs_shared/public/mocks.tsx index 963480d8fd90f..a9b0ebd6a6aa3 100644 --- a/x-pack/plugins/logs_shared/public/mocks.tsx +++ b/x-pack/plugins/logs_shared/public/mocks.tsx @@ -5,11 +5,13 @@ * 2.0. */ +import { createLogAIAssistantMock } from './components/log_ai_assistant/log_ai_assistant.mock'; import { createLogViewsServiceStartMock } from './services/log_views/log_views_service.mock'; import { LogsSharedClientStartExports } from './types'; export const createLogsSharedPluginStartMock = (): jest.Mocked => ({ logViews: createLogViewsServiceStartMock(), + LogAIAssistant: createLogAIAssistantMock(), }); export const _ensureTypeCompatibility = (): LogsSharedClientStartExports => diff --git a/x-pack/plugins/logs_shared/public/types.ts b/x-pack/plugins/logs_shared/public/types.ts index e67f83e4becc0..c0379c6fc21fb 100644 --- a/x-pack/plugins/logs_shared/public/types.ts +++ b/x-pack/plugins/logs_shared/public/types.ts @@ -17,6 +17,7 @@ import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; import { ObservabilityAIAssistantPluginStart } from '@kbn/observability-ai-assistant-plugin/public'; import { UiActionsStart } from '@kbn/ui-actions-plugin/public'; +import { LogAIAssistantComponent } from './components/log_ai_assistant'; // import type { OsqueryPluginStart } from '../../osquery/public'; import { LogViewsServiceSetup, LogViewsServiceStart } from './services/log_views'; @@ -27,6 +28,7 @@ export interface LogsSharedClientSetupExports { export interface LogsSharedClientStartExports { logViews: LogViewsServiceStart; + LogAIAssistant: LogAIAssistantComponent; } // eslint-disable-next-line @typescript-eslint/no-empty-interface diff --git a/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx b/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx index e0cb6aa9e6975..1d5fb7fe9ae78 100644 --- a/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx +++ b/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx @@ -4,18 +4,22 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +import { EuiFlexItem } from '@elastic/eui'; import { LogExplorerCustomizations, LogExplorerFlyoutContentProps, } from '@kbn/log-explorer-plugin/public'; -import React from 'react'; +import type { LogAIAssistantDocument } from '@kbn/logs-shared-plugin/public'; +import React, { useMemo } from 'react'; import { useKibanaContextForPlugin } from '../utils/use_kibana'; const ObservabilityLogAIAssistant = ({ doc }: LogExplorerFlyoutContentProps) => { const { services } = useKibanaContextForPlugin(); const { LogAIAssistant } = services.logsShared; - return ; + const mappedDoc = useMemo(() => mapDocToAIAssistantFormat(doc), [doc]); + + return ; }; export const renderFlyoutContent: Required['flyout']['renderContent'] = ( @@ -25,7 +29,23 @@ export const renderFlyoutContent: Required['flyout'][ return ( <> {renderPreviousContent()} - + + + ); }; + +/** + * Utils + */ +const mapDocToAIAssistantFormat = (doc: LogExplorerFlyoutContentProps['doc']) => { + if (!doc) return; + + return { + fields: Object.entries(doc.flattened).map(([field, value]) => ({ + field, + value, + })) as LogAIAssistantDocument['fields'], + }; +}; diff --git a/x-pack/plugins/observability_log_explorer/public/routes/main/main_route.tsx b/x-pack/plugins/observability_log_explorer/public/routes/main/main_route.tsx index 020cf5a868e6d..e17f92a46c23b 100644 --- a/x-pack/plugins/observability_log_explorer/public/routes/main/main_route.tsx +++ b/x-pack/plugins/observability_log_explorer/public/routes/main/main_route.tsx @@ -8,13 +8,13 @@ import { CoreStart } from '@kbn/core/public'; import React, { useMemo, useState } from 'react'; import { BehaviorSubject } from 'rxjs'; -import { LogExplorerCustomizations } from '@kbn/log-explorer-plugin/public'; import { LogExplorerTopNavMenu } from '../../components/log_explorer_top_nav_menu'; import { ObservabilityLogExplorerPageTemplate } from '../../components/page_template'; import { noBreadcrumbs, useBreadcrumbs } from '../../utils/breadcrumbs'; import { useKibanaContextForPlugin } from '../../utils/use_kibana'; import { ObservabilityLogExplorerAppMountParameters } from '../../types'; import { LazyOriginInterpreter } from '../../state_machines/origin_interpreter/src/lazy_component'; +import { createLogExplorerCustomizations } from '../../log_explorer_customizations'; export interface ObservablityLogExplorerMainRouteProps { appParams: ObservabilityLogExplorerAppMountParameters; core: CoreStart; @@ -32,14 +32,7 @@ export const ObservablityLogExplorerMainRoute = ({ const [state$] = useState(() => new BehaviorSubject({})); - const customizations: LogExplorerCustomizations = useMemo( - () => ({ - flyout: { - renderContent: (renderPreviousContent) => renderPreviousContent(), - }, - }), - [] - ); + const customizations = useMemo(() => createLogExplorerCustomizations(), []); return ( <> diff --git a/x-pack/plugins/observability_log_explorer/public/types.ts b/x-pack/plugins/observability_log_explorer/public/types.ts index 82045faea76e8..8b315ad206ce4 100644 --- a/x-pack/plugins/observability_log_explorer/public/types.ts +++ b/x-pack/plugins/observability_log_explorer/public/types.ts @@ -12,6 +12,7 @@ import { ObservabilitySharedPluginStart } from '@kbn/observability-shared-plugin import { ServerlessPluginStart } from '@kbn/serverless/public'; import { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public'; import { AppMountParameters, ScopedHistory } from '@kbn/core/public'; +import { LogsSharedClientStartExports } from '@kbn/logs-shared-plugin/public'; import { ObservabilityLogExplorerLocators, ObservabilityLogExplorerLocationState, @@ -33,6 +34,7 @@ export interface ObservabilityLogExplorerStartDeps { data: DataPublicPluginStart; discover: DiscoverStart; logExplorer: LogExplorerPluginStart; + logsShared: LogsSharedClientStartExports; observabilityShared: ObservabilitySharedPluginStart; serverless?: ServerlessPluginStart; share: SharePluginStart; From d76ee0fdf2aa22476e9a5664f48042b64363b166 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:10:53 +0000 Subject: [PATCH 6/8] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/plugins/observability_log_explorer/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/observability_log_explorer/tsconfig.json b/x-pack/plugins/observability_log_explorer/tsconfig.json index 7266e097dae62..109b54b929ec7 100644 --- a/x-pack/plugins/observability_log_explorer/tsconfig.json +++ b/x-pack/plugins/observability_log_explorer/tsconfig.json @@ -33,7 +33,8 @@ "@kbn/core-mount-utils-browser-internal", "@kbn/xstate-utils", "@kbn/shared-ux-utility", - "@kbn/ui-theme" + "@kbn/ui-theme", + "@kbn/logs-shared-plugin" ], "exclude": [ "target/**/*" From f9e521bef31466f0c163cdbebb44586325dc153b Mon Sep 17 00:00:00 2001 From: Marco Antonio Ghiani Date: Tue, 7 Nov 2023 12:28:55 +0100 Subject: [PATCH 7/8] feat(log-explorer): update types --- .../public/customizations/log_explorer_profile.tsx | 2 +- .../public/hooks/use_log_explorer_customizations.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/log_explorer/public/customizations/log_explorer_profile.tsx b/x-pack/plugins/log_explorer/public/customizations/log_explorer_profile.tsx index ed770d1790ce9..628ff40babc22 100644 --- a/x-pack/plugins/log_explorer/public/customizations/log_explorer_profile.tsx +++ b/x-pack/plugins/log_explorer/public/customizations/log_explorer_profile.tsx @@ -23,7 +23,7 @@ const LazyCustomFlyoutContent = dynamic(() => import('./custom_flyout_content')) export interface CreateLogExplorerProfileCustomizationsDeps { core: CoreStart; - customizations?: LogExplorerCustomizations; + customizations: LogExplorerCustomizations; plugins: LogExplorerStartDeps; state$?: BehaviorSubject; } diff --git a/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts b/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts index 9f00a369e1cf1..0557e17761cb4 100644 --- a/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts +++ b/x-pack/plugins/log_explorer/public/hooks/use_log_explorer_customizations.ts @@ -8,10 +8,10 @@ import createContainer from 'constate'; import { LogExplorerCustomizations } from '../components/log_explorer/types'; interface UseLogExplorerCustomizationsDeps { - value?: LogExplorerCustomizations; + value: LogExplorerCustomizations; } -const useLogExplorerCustomizations = ({ value = {} }: UseLogExplorerCustomizationsDeps) => value; +const useLogExplorerCustomizations = ({ value }: UseLogExplorerCustomizationsDeps) => value; export const [LogExplorerCustomizationsProvider, useLogExplorerCustomizationsContext] = createContainer(useLogExplorerCustomizations); From 5a6919b50c8e7ccf8f954510e06d3b457dbdad04 Mon Sep 17 00:00:00 2001 From: Marco Antonio Ghiani Date: Tue, 7 Nov 2023 14:48:11 +0100 Subject: [PATCH 8/8] fix(log-explorer): reinit assistant on document change --- .../public/log_explorer_customizations/flyout_content.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx b/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx index 1d5fb7fe9ae78..53d34a71a7237 100644 --- a/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx +++ b/x-pack/plugins/observability_log_explorer/public/log_explorer_customizations/flyout_content.tsx @@ -19,7 +19,7 @@ const ObservabilityLogAIAssistant = ({ doc }: LogExplorerFlyoutContentProps) => const mappedDoc = useMemo(() => mapDocToAIAssistantFormat(doc), [doc]); - return ; + return ; }; export const renderFlyoutContent: Required['flyout']['renderContent'] = (