From 0bfbe8a928022a91c05094a4f0a0249463d641e9 Mon Sep 17 00:00:00 2001 From: Davis McPhee Date: Wed, 5 Jun 2024 21:16:46 -0300 Subject: [PATCH] Fix mappedDoc in createLogsAIAssistantRenderer and revert change to LogAIAssistant --- .../public/components/log_ai_assistant/index.tsx | 6 +++--- .../public/components/log_ai_assistant/log_ai_assistant.tsx | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/index.tsx b/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/index.tsx index 465f1f3f66eff..484af6e4a0809 100644 --- a/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/index.tsx +++ b/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/index.tsx @@ -22,12 +22,12 @@ export function createLogAIAssistant({ export const createLogsAIAssistantRenderer = (LogAIAssistantRender: ReturnType) => ({ doc }: ObservabilityLogsAIAssistantFeatureRenderDeps) => { - const mappedDoc = useMemo( + const mappedDoc = useMemo( () => ({ fields: Object.entries(doc.flattened).map(([field, value]) => ({ field, - value, - })) as LogAIAssistantDocument['fields'], + value: Array.isArray(value) ? value : [value], + })), }), [doc] ); diff --git a/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx b/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx index 49d4fbc01c2e4..3e1b6fced3337 100644 --- a/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx +++ b/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx @@ -51,8 +51,7 @@ export const LogAIAssistant = ({ return undefined; } - const messageValue = doc.fields.find((field) => field.field === 'message')?.value; - const message = Array.isArray(messageValue) ? messageValue[0] : messageValue; + const message = doc.fields.find((field) => field.field === 'message')?.value[0]; return getContextualInsightMessages({ message: `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?`,