diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/context_pills/index.test.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/context_pills/index.test.tsx
index 723ddf823dd1e..6d7706f7e0ece 100644
--- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/context_pills/index.test.tsx
+++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/context_pills/index.test.tsx
@@ -54,6 +54,30 @@ describe('ContextPills', () => {
});
});
+ it('does not render item if description is empty', () => {
+ render(
+
+ Promise.resolve('Context 2 data'),
+ id: 'context3',
+ tooltip: 'Context 2 tooltip',
+ },
+ }}
+ selectedPromptContexts={{}}
+ setSelectedPromptContexts={jest.fn()}
+ />
+
+ );
+ expect(screen.getByTestId(`pillButton-context2`)).toBeInTheDocument();
+ expect(screen.queryByTestId(`pillButton-context3`)).not.toBeInTheDocument();
+ });
+
it('invokes setSelectedPromptContexts() when the prompt is NOT already selected', async () => {
const context = mockPromptContexts.context1;
const setSelectedPromptContexts = jest.fn();
diff --git a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/context_pills/index.tsx b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/context_pills/index.tsx
index d3ae29643804e..a950b8457f826 100644
--- a/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/context_pills/index.tsx
+++ b/x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant/context_pills/index.tsx
@@ -67,7 +67,7 @@ const ContextPillsComponent: React.FC = ({
{description}
);
- return (
+ return description.length > 0 ? (
{selectedPromptContexts[id] != null ? (
button
@@ -75,7 +75,7 @@ const ContextPillsComponent: React.FC = ({
{button}
)}
- );
+ ) : null;
})}
);
diff --git a/x-pack/platform/plugins/private/translations/translations/fr-FR.json b/x-pack/platform/plugins/private/translations/translations/fr-FR.json
index 4a007574d47d4..4089fbbc3c2ef 100644
--- a/x-pack/platform/plugins/private/translations/translations/fr-FR.json
+++ b/x-pack/platform/plugins/private/translations/translations/fr-FR.json
@@ -7489,32 +7489,6 @@
"searchErrors.search.httpErrorTitle": "Impossible de se connecter au serveur Kibana",
"searchErrors.tsdbError.message": "Le champ {field} du type de série temporelle [compteur] a été utilisé avec une opération {op} non prise en charge.",
"searchErrors.tsdbError.tsdbCounterDocsLabel": "Pour en savoir plus sur les types de champs des séries temporelles et les agrégations compatibles [counter]",
- "xpack.searchIndexDocuments.documentList.description": "Affichage de {results} sur {total}. Nombre maximal de résultats de recherche de {maximum} documents.",
- "xpack.searchIndexDocuments.documentList.docsPerPage": "Nombre de documents par page déroulée",
- "xpack.searchIndexDocuments.documentList.pagination.itemsPerPage": "Documents par page : {docPerPage}",
- "xpack.searchIndexDocuments.documentList.paginationAriaLabel": "Pagination pour la liste de documents",
- "xpack.searchIndexDocuments.documentList.paginationOptions.option": "{docCount} documents",
- "xpack.searchIndexDocuments.documentList.resultLimit": "Seuls les {number} premiers résultats sont disponibles pour la pagination. Veuillez utiliser la barre de recherche pour filtrer vos résultats.",
- "xpack.searchIndexDocuments.documentList.resultLimitTitle": "Les résultats sont limités à {number} documents",
- "xpack.searchIndexDocuments.documents.searchField.placeholder": "Rechercher des documents dans cet index",
- "xpack.searchIndexDocuments.result.compactCard.header.metadata.title": "Métadonnées du document",
- "xpack.searchIndexDocuments.result.expandTooltip.allVisible": "Tous les champs sont visibles",
- "xpack.searchIndexDocuments.result.expandTooltip.showFewer": "Afficher {amount} champs en moins",
- "xpack.searchIndexDocuments.result.expandTooltip.showMore": "Afficher {amount} champs en plus",
- "xpack.searchIndexDocuments.result.fieldTypeAriaLabel": "Ce champ est du type {fieldType}",
- "xpack.searchIndexDocuments.result.fieldTypeButtonAriaLabel": "Afficher le type de ce champ",
- "xpack.searchIndexDocuments.result.header.compactCard.metadata.deleteDocument": "Supprimer le document",
- "xpack.searchIndexDocuments.result.header.compactCard.metadata.deleteDocumentToolTip": "Vous ne disposez pas d'autorisation pour supprimer des documents",
- "xpack.searchIndexDocuments.result.header.compactCard.metadata.score": "Score",
- "xpack.searchIndexDocuments.result.header.metadata.deleteDocument": "Supprimer le document",
- "xpack.searchIndexDocuments.result.header.metadata.icon.ariaLabel": "Métadonnées pour le document : {id}",
- "xpack.searchIndexDocuments.result.header.metadata.title": "Métadonnées du document",
- "xpack.searchIndexDocuments.result.title.id": "ID de document : {id}",
- "xpack.searchIndexDocuments.result.value.denseVector.copy": "Copier le vecteur",
- "xpack.searchIndexDocuments.result.value.denseVector.dimLabel": "{value} dimensions",
- "xpack.searchIndexDocuments.resultFields.contentstableHeaderLabel": "Contenu",
- "xpack.searchIndexDocuments.resultFields.fieldTypeHeaderLabel": "Champ",
- "xpack.searchIndexDocuments.resultFields.tableLabel": "Champs du document avec l'ID {documentId}",
"searchResponseWarnings.badgeButtonLabel": "{warningCount} {warningCount, plural, one {avertissement} other {avertissements}}",
"searchResponseWarnings.description.multipleClusters": "Ces clusters ont rencontré des problèmes lors du renvoi des données et les résultats pourraient être incomplets.",
"searchResponseWarnings.description.singleCluster": "Ce cluster a rencontré des problèmes lors du renvoi des données et les résultats pourraient être incomplets.",
diff --git a/x-pack/platform/plugins/private/translations/translations/ja-JP.json b/x-pack/platform/plugins/private/translations/translations/ja-JP.json
index d2ef12a85fc17..8ca6bb70f3437 100644
--- a/x-pack/platform/plugins/private/translations/translations/ja-JP.json
+++ b/x-pack/platform/plugins/private/translations/translations/ja-JP.json
@@ -7483,31 +7483,6 @@
"searchErrors.search.httpErrorTitle": "Kibanaサーバーに接続できません",
"searchErrors.tsdbError.message": "時系列タイプ[カウンター]のフィールド{field}が、サポートされていない処理{op}で使用されました。",
"searchErrors.tsdbError.tsdbCounterDocsLabel": "時系列フィールド型と[カウンター]対応集約の詳細",
- "xpack.searchIndexDocuments.documentList.description": "{results}/{total}件を表示しています。{maximum}ドキュメントが検索結果の最大数です。",
- "xpack.searchIndexDocuments.documentList.docsPerPage": "ページドロップダウンごとのドキュメント数",
- "xpack.searchIndexDocuments.documentList.pagination.itemsPerPage": "ページごとのドキュメント数:{docPerPage}",
- "xpack.searchIndexDocuments.documentList.paginationAriaLabel": "ドキュメントリストのページ制御",
- "xpack.searchIndexDocuments.documentList.resultLimit": "最初の{number}件の結果のみがページ制御できます。結果を絞り込むには、検索バーを使用してください。",
- "xpack.searchIndexDocuments.documentList.resultLimitTitle": "結果は{number}ドキュメントに制限されています。",
- "xpack.searchIndexDocuments.documents.searchField.placeholder": "このインデックスでドキュメントを検索",
- "xpack.searchIndexDocuments.result.compactCard.header.metadata.title": "ドキュメントメタデータ",
- "xpack.searchIndexDocuments.result.expandTooltip.allVisible": "すべてのフィールドが表示されます",
- "xpack.searchIndexDocuments.result.expandTooltip.showFewer": "表示するフィールド数を{amount}個減らす",
- "xpack.searchIndexDocuments.result.expandTooltip.showMore": "表示するフィールド数を{amount}個増やす",
- "xpack.searchIndexDocuments.result.fieldTypeAriaLabel": "このフィールドの型は{fieldType}です",
- "xpack.searchIndexDocuments.result.fieldTypeButtonAriaLabel": "このフィールドの型を表示",
- "xpack.searchIndexDocuments.result.header.compactCard.metadata.deleteDocument": "ドキュメントを削除",
- "xpack.searchIndexDocuments.result.header.compactCard.metadata.deleteDocumentToolTip": "ドキュメントを削除する権限がありません",
- "xpack.searchIndexDocuments.result.header.compactCard.metadata.score": "スコア",
- "xpack.searchIndexDocuments.result.header.metadata.deleteDocument": "ドキュメントを削除",
- "xpack.searchIndexDocuments.result.header.metadata.icon.ariaLabel": "ドキュメント{id}のメタデータ",
- "xpack.searchIndexDocuments.result.header.metadata.title": "ドキュメントメタデータ",
- "xpack.searchIndexDocuments.result.title.id": "ドキュメントID:{id}",
- "xpack.searchIndexDocuments.result.value.denseVector.copy": "ベクトルをコピー",
- "xpack.searchIndexDocuments.result.value.denseVector.dimLabel": "{value} dims",
- "xpack.searchIndexDocuments.resultFields.contentstableHeaderLabel": "目次",
- "xpack.searchIndexDocuments.resultFields.fieldTypeHeaderLabel": "フィールド",
- "xpack.searchIndexDocuments.resultFields.tableLabel": "ID {documentId}のドキュメントのフィールド",
"searchResponseWarnings.badgeButtonLabel": "{warningCount} {warningCount, plural, other {警告}}",
"searchResponseWarnings.description.multipleClusters": "これらのクラスターはデータの返送に問題があり、結果が不完全である可能性があります。",
"searchResponseWarnings.description.singleCluster": "このクラスターはデータの返送に問題があり、結果が不完全である可能性があります。",
diff --git a/x-pack/platform/plugins/private/translations/translations/zh-CN.json b/x-pack/platform/plugins/private/translations/translations/zh-CN.json
index f169e9bc4114d..21490d1e54a54 100644
--- a/x-pack/platform/plugins/private/translations/translations/zh-CN.json
+++ b/x-pack/platform/plugins/private/translations/translations/zh-CN.json
@@ -7494,32 +7494,6 @@
"searchErrors.search.httpErrorTitle": "无法连接到 Kibana 服务器",
"searchErrors.tsdbError.message": "时间序列类型 [计数器] 的字段 {field} 已用于不支持的操作 {op}。",
"searchErrors.tsdbError.tsdbCounterDocsLabel": "查看有关时序字段类型和 [计数器] 支持的聚合的更多信息",
- "xpack.searchIndexDocuments.documentList.description": "正在显示 {results} 个(共 {total} 个)。搜索结果最多包含 {maximum} 个文档。",
- "xpack.searchIndexDocuments.documentList.docsPerPage": "每页文档计数下拉列表",
- "xpack.searchIndexDocuments.documentList.pagination.itemsPerPage": "每页文档数:{docPerPage}",
- "xpack.searchIndexDocuments.documentList.paginationAriaLabel": "文档列表分页",
- "xpack.searchIndexDocuments.documentList.paginationOptions.option": "{docCount} 个文档",
- "xpack.searchIndexDocuments.documentList.resultLimit": "仅前 {number} 个结果可用于分页。请使用搜索栏筛选结果。",
- "xpack.searchIndexDocuments.documentList.resultLimitTitle": "结果仅限于 {number} 个文档",
- "xpack.searchIndexDocuments.documents.searchField.placeholder": "在此索引中搜索文档",
- "xpack.searchIndexDocuments.result.compactCard.header.metadata.title": "文档元数据",
- "xpack.searchIndexDocuments.result.expandTooltip.allVisible": "所有字段均可见",
- "xpack.searchIndexDocuments.result.expandTooltip.showFewer": "显示少于 {amount} 个字段",
- "xpack.searchIndexDocuments.result.expandTooltip.showMore": "显示多于 {amount} 个字段",
- "xpack.searchIndexDocuments.result.fieldTypeAriaLabel": "此字段类型为 {fieldType}",
- "xpack.searchIndexDocuments.result.fieldTypeButtonAriaLabel": "显示此字段的类型",
- "xpack.searchIndexDocuments.result.header.compactCard.metadata.deleteDocument": "删除文档",
- "xpack.searchIndexDocuments.result.header.compactCard.metadata.deleteDocumentToolTip": "您无权删除文档",
- "xpack.searchIndexDocuments.result.header.compactCard.metadata.score": "分数",
- "xpack.searchIndexDocuments.result.header.metadata.deleteDocument": "删除文档",
- "xpack.searchIndexDocuments.result.header.metadata.icon.ariaLabel": "以下文档的元数据:{id}",
- "xpack.searchIndexDocuments.result.header.metadata.title": "文档元数据",
- "xpack.searchIndexDocuments.result.title.id": "文档 ID:{id}",
- "xpack.searchIndexDocuments.result.value.denseVector.copy": "复制向量",
- "xpack.searchIndexDocuments.result.value.denseVector.dimLabel": "{value} 个维度",
- "xpack.searchIndexDocuments.resultFields.contentstableHeaderLabel": "内容",
- "xpack.searchIndexDocuments.resultFields.fieldTypeHeaderLabel": "字段",
- "xpack.searchIndexDocuments.resultFields.tableLabel": "ID 为 {documentId} 的文档的字段",
"searchResponseWarnings.badgeButtonLabel": "{warningCount} 个{warningCount, plural, other {警告}}",
"searchResponseWarnings.description.multipleClusters": "这些集群返回数据时出现问题,结果可能并不完整。",
"searchResponseWarnings.description.singleCluster": "此集群返回数据时出现问题,结果可能并不完整。",
diff --git a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/actions_cell.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/actions_cell.test.tsx
index 7b632e973090c..3dac7381cb395 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/actions_cell.test.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/actions_cell.test.tsx
@@ -12,13 +12,11 @@ import { ActionsCell } from './actions_cell';
import { useExpandableFlyoutApi } from '@kbn/expandable-flyout';
import type { EcsSecurityExtension as Ecs } from '@kbn/securitysolution-ecs';
import { MORE_ACTIONS_BUTTON_TEST_ID } from './more_actions_row_control_column';
-import { useAssistant } from '../../../hooks/alert_summary/use_assistant';
import { useAddToCaseActions } from '../../alerts_table/timeline_actions/use_add_to_case_actions';
import { useAlertTagsActions } from '../../alerts_table/timeline_actions/use_alert_tags_actions';
import { ROW_ACTION_FLYOUT_ICON_TEST_ID } from './open_flyout_row_control_column';
jest.mock('@kbn/expandable-flyout');
-jest.mock('../../../hooks/alert_summary/use_assistant');
jest.mock('../../alerts_table/timeline_actions/use_add_to_case_actions');
jest.mock('../../alerts_table/timeline_actions/use_alert_tags_actions');
@@ -27,10 +25,6 @@ describe('ActionsCell', () => {
(useExpandableFlyoutApi as jest.Mock).mockReturnValue({
openFlyout: jest.fn(),
});
- (useAssistant as jest.Mock).mockReturnValue({
- showAssistant: true,
- showAssistantOverlay: jest.fn(),
- });
(useAddToCaseActions as jest.Mock).mockReturnValue({
addToCaseActionItems: [],
});
@@ -51,7 +45,6 @@ describe('ActionsCell', () => {
const { getByTestId } = render();
expect(getByTestId(ROW_ACTION_FLYOUT_ICON_TEST_ID)).toBeInTheDocument();
- expect(getByTestId('newChatByTitle')).toBeInTheDocument();
expect(getByTestId(MORE_ACTIONS_BUTTON_TEST_ID)).toBeInTheDocument();
});
});
diff --git a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/actions_cell.tsx b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/actions_cell.tsx
index 9de99b9d88a33..e20e6bff894f6 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/actions_cell.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/actions_cell.tsx
@@ -9,7 +9,6 @@ import React, { memo } from 'react';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import type { Alert } from '@kbn/alerting-types';
import type { EcsSecurityExtension as Ecs } from '@kbn/securitysolution-ecs';
-import { AssistantRowControlColumn } from './assistant_row_control_column';
import { MoreActionsRowControlColumn } from './more_actions_row_control_column';
import { OpenFlyoutRowControlColumn } from './open_flyout_row_control_column';
@@ -37,9 +36,6 @@ export const ActionsCell = memo(({ alert, ecsAlert }: ActionsCellProps) => (
-
-
-
diff --git a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/assistant_row_control_column.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/assistant_row_control_column.test.tsx
deleted file mode 100644
index a7d3d903d50fc..0000000000000
--- a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/assistant_row_control_column.test.tsx
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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 { render } from '@testing-library/react';
-import { AssistantRowControlColumn } from './assistant_row_control_column';
-import type { Alert } from '@kbn/alerting-types';
-import { useAssistant } from '../../../hooks/alert_summary/use_assistant';
-
-jest.mock('../../../hooks/alert_summary/use_assistant');
-
-describe('AssistantRowControlColumn', () => {
- it('should render the icon button', () => {
- (useAssistant as jest.Mock).mockReturnValue({
- showAssistantOverlay: jest.fn(),
- });
-
- const alert: Alert = {
- _id: '_id',
- _index: '_index',
- };
-
- const { getByTestId } = render();
-
- expect(getByTestId('newChatByTitle')).toBeInTheDocument();
- expect(getByTestId('newChatByTitleIcon')).toBeInTheDocument();
- });
-
- it('should call the callback when clicked', () => {
- const showAssistantOverlay = jest.fn();
- (useAssistant as jest.Mock).mockReturnValue({
- showAssistantOverlay,
- });
-
- const alert: Alert = {
- _id: '_id',
- _index: '_index',
- };
-
- const { getByTestId } = render();
-
- const button = getByTestId('newChatByTitle');
- expect(button).toBeInTheDocument();
-
- button.click();
-
- expect(showAssistantOverlay).toHaveBeenCalled();
- });
-});
diff --git a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/assistant_row_control_column.tsx b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/assistant_row_control_column.tsx
deleted file mode 100644
index ef3a0d2cce090..0000000000000
--- a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/assistant_row_control_column.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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, { memo } from 'react';
-import type { Alert } from '@kbn/alerting-types';
-import { NewChatByTitle } from '@kbn/elastic-assistant/impl/new_chat_by_title';
-import { useAssistant } from '../../../hooks/alert_summary/use_assistant';
-
-export interface AssistantRowControlColumnProps {
- /**
- * Alert data passed from the renderCellValue callback via the AlertWithLegacyFormats interface
- */
- alert: Alert;
-}
-
-/**
- * Renders the assistant icon and opens the assistant flyout for the current alert when clicked.
- * This is used in the AI for SOC alert summary table.
- */
-export const AssistantRowControlColumn = memo(({ alert }: AssistantRowControlColumnProps) => {
- const { showAssistantOverlay } = useAssistant({ alert });
-
- return ;
-});
-
-AssistantRowControlColumn.displayName = 'AssistantRowControlColumn';
diff --git a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/table.tsx b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/table.tsx
index c745ae1412814..7a12d8e9e725d 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/table.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alert_summary/table/table.tsx
@@ -75,7 +75,7 @@ export const columns: EuiDataGridProps['columns'] = [
},
];
-export const ACTION_COLUMN_WIDTH = 98; // px
+export const ACTION_COLUMN_WIDTH = 72; // px
export const ALERT_TABLE_CONSUMERS: AlertsTableProps['consumers'] = [AlertConsumers.SIEM];
export const RULE_TYPE_IDS = [ESQL_RULE_TYPE_ID, QUERY_RULE_TYPE_ID];
export const ROW_HEIGHTS_OPTIONS = { defaultHeight: 40 };
diff --git a/x-pack/solutions/security/plugins/security_solution/public/detections/hooks/alert_summary/use_assistant.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/detections/hooks/alert_summary/use_assistant.test.tsx
deleted file mode 100644
index 52f638a29cb81..0000000000000
--- a/x-pack/solutions/security/plugins/security_solution/public/detections/hooks/alert_summary/use_assistant.test.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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 type { RenderHookResult } from '@testing-library/react';
-import { renderHook } from '@testing-library/react';
-import type { UseAssistantParams, UseAssistantResult } from './use_assistant';
-import { useAssistant } from './use_assistant';
-import { useAssistantOverlay } from '@kbn/elastic-assistant';
-import type { Alert } from '@kbn/alerting-types';
-
-jest.mock('@kbn/elastic-assistant');
-
-describe('useAssistant', () => {
- let hookResult: RenderHookResult;
-
- it('should return showAssistant true and a value for promptContextId', () => {
- const showAssistantOverlay = jest.fn();
- jest
- .mocked(useAssistantOverlay)
- .mockReturnValue({ showAssistantOverlay, promptContextId: '123' });
-
- const alert: Alert = {
- _id: '_id',
- _index: '_index',
- };
-
- hookResult = renderHook((props: UseAssistantParams) => useAssistant(props), {
- initialProps: { alert },
- });
-
- expect(hookResult.result.current.showAssistantOverlay).toEqual(showAssistantOverlay);
- });
-});
diff --git a/x-pack/solutions/security/plugins/security_solution/public/detections/hooks/alert_summary/use_assistant.ts b/x-pack/solutions/security/plugins/security_solution/public/detections/hooks/alert_summary/use_assistant.ts
deleted file mode 100644
index 555f562e2afa8..0000000000000
--- a/x-pack/solutions/security/plugins/security_solution/public/detections/hooks/alert_summary/use_assistant.ts
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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 { useAssistantOverlay } from '@kbn/elastic-assistant';
-import { useCallback, useMemo } from 'react';
-import { i18n } from '@kbn/i18n';
-import type { Alert } from '@kbn/alerting-types';
-import { flattenAlertType } from '../../utils/flatten_alert_type';
-import { getAlertFieldValueAsStringOrNull } from '../../utils/type_utils';
-import {
- PROMPT_CONTEXT_ALERT_CATEGORY,
- PROMPT_CONTEXTS,
-} from '../../../assistant/content/prompt_contexts';
-import {
- ALERT_SUMMARY_CONTEXT_DESCRIPTION,
- ALERT_SUMMARY_CONVERSATION_ID,
- ALERT_SUMMARY_VIEW_CONTEXT_TOOLTIP,
-} from '../../../common/components/event_details/translations';
-
-const SUMMARY_VIEW = i18n.translate('xpack.securitySolution.eventDetails.summaryView', {
- defaultMessage: 'summary',
-});
-
-export interface UseAssistantParams {
- /**
- * An array of field objects with category and value
- */
- alert: Alert;
-}
-
-export interface UseAssistantResult {
- /**
- * Function to show assistant overlay
- */
- showAssistantOverlay: (show: boolean) => void;
-}
-
-/**
- * Hook to return the assistant button visibility and prompt context id.
- * This is meant to be used in the AI for SOC tier, where the assistant is always enabled.
- */
-export const useAssistant = ({ alert }: UseAssistantParams): UseAssistantResult => {
- const getPromptContext = useCallback(async () => {
- const cleanedAlert: Alert = { ...alert };
-
- // remove all fields that start with signal. as these are legacy fields
- for (const key in cleanedAlert) {
- if (key.startsWith('signal.')) {
- delete cleanedAlert[key];
- }
- }
-
- // makes sure that we do not have any nested values as the getPromptContext is expecting the data in Record format
- return flattenAlertType(cleanedAlert);
- }, [alert]);
-
- const conversationTitle = useMemo(() => {
- const ruleName =
- getAlertFieldValueAsStringOrNull(alert, 'rule.name') ??
- getAlertFieldValueAsStringOrNull(alert, 'kibana.alert.rule.name') ??
- ALERT_SUMMARY_CONVERSATION_ID;
-
- const timestamp: string = getAlertFieldValueAsStringOrNull(alert, '@timestamp') ?? '';
-
- return `${ruleName} - ${timestamp}`;
- }, [alert]);
-
- const { showAssistantOverlay } = useAssistantOverlay(
- 'alert',
- conversationTitle,
- ALERT_SUMMARY_CONTEXT_DESCRIPTION(SUMMARY_VIEW),
- getPromptContext,
- null,
- PROMPT_CONTEXTS[PROMPT_CONTEXT_ALERT_CATEGORY].suggestedUserPrompt,
- ALERT_SUMMARY_VIEW_CONTEXT_TOOLTIP,
- true
- );
-
- return {
- showAssistantOverlay,
- };
-};