Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] defend insights langgraph upgrade #211038

Merged
merged 4 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2507,6 +2507,8 @@ x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/defend
x-pack/plugins/elastic_assistant/server/__mocks__/defend_insights_schema.mock.ts @elastic/security-defend-workflows
x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/defend_insights @elastic/security-defend-workflows
x-pack/plugins/elastic_assistant/server/routes/defend_insights @elastic/security-defend-workflows
x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights @elastic/security-defend-workflows
x-pack/solutions/security/plugins/elastic_assistant/server/routes/defend_insights @elastic/security-defend-workflows
/x-pack/solutions/security/plugins/security_solution/public/common/components/response_actions @elastic/security-defend-workflows
/x-pack/solutions/security/plugins/security_solution_serverless/public/upselling/pages/osquery_automated_response_actions.tsx @elastic/security-defend-workflows

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ export const ELASTIC_AI_ASSISTANT_EVALUATE_URL =
`${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/evaluate` as const;

// Defend insights
export const DEFEND_INSIGHTS_TOOL_ID = 'defend-insights';
export const DEFEND_INSIGHTS_ID = 'defend-insights';
export const DEFEND_INSIGHTS = `${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/defend_insights`;
export const DEFEND_INSIGHTS_BY_ID = `${DEFEND_INSIGHTS}/{id}`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { isRawDataValid } from '../is_raw_data_valid';
import type { MaybeRawData } from '../types';
import { isRawDataValid } from '../is_raw_data_valid';

/** Returns the raw data if it valid, or a default if it's not */
export const getRawDataOrDefault = (rawData: MaybeRawData): Record<string, unknown[]> =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { estypes } from '@elastic/elasticsearch';
import { DefendInsightStatus, DefendInsightType } from '@kbn/elastic-assistant-common';

import type { EsDefendInsightSchema } from '../ai_assistant_data_clients/defend_insights/types';
import type { EsDefendInsightSchema } from '../lib/defend_insights/persistence/types';

export const getDefendInsightsSearchEsMock = () => {
const searchResponse: estypes.SearchResponse<EsDefendInsightSchema> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* 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 { DefendInsightStatus, DefendInsightType } from '@kbn/elastic-assistant-common';

import type { EsDefendInsightSchema } from '../lib/defend_insights/persistence/types';

export const getParsedDefendInsightsMock = (timestamp: string): EsDefendInsightSchema[] => [
{
'@timestamp': timestamp,
created_at: timestamp,
updated_at: timestamp,
last_viewed_at: timestamp,
users: [
{
id: 'u_mGBROF_q5bmFCATbLXAcCwKa0k8JvONAwSruelyKA5E_0',
name: 'elastic',
},
],
status: DefendInsightStatus.Enum.succeeded,
api_config: {
action_type_id: '.bedrock',
connector_id: 'ac4e19d1-e2e2-49af-bf4b-59428473101c',
model: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
},
endpoint_ids: ['6e09ec1c-644c-4148-a02d-be451c35400d'],
insight_type: DefendInsightType.Enum.incompatible_antivirus,
insights: [
{
group: 'windows_defenders',
events: [],
},
],
namespace: 'default',
id: '655c52ec-49ee-4d20-87e5-7edd6d8f84e8',
generation_intervals: [
{
date: timestamp,
duration_ms: 13113,
},
],
average_interval_ms: 13113,
events_context_count: 100,
replacements: [
{
uuid: '2009c67b-89b8-43d9-b502-2c32f71875a0',
value: 'root',
},
{
uuid: '9f7f91b6-6853-48b7-bfb8-403f5efb2364',
value: 'joey-dev-default-3539',
},
],
},
{
'@timestamp': timestamp,
created_at: timestamp,
updated_at: timestamp,
last_viewed_at: timestamp,
users: [
{
id: '00468e82-e37f-4224-80c1-c62e594c74b1',
name: 'ubuntu',
},
],
status: DefendInsightStatus.Enum.succeeded,
api_config: {
action_type_id: '.bedrock',
connector_id: 'bc5e19d1-e2e2-49af-bf4b-59428473101d',
model: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
},
endpoint_ids: ['b557bb12-8206-44b6-b2a5-dbcce5b1e65e'],
insight_type: DefendInsightType.Enum.noisy_process_tree,
insights: [
{
group: 'linux_security',
events: [],
},
],
namespace: 'default',
id: '7a1b52ec-49ee-4d20-87e5-7edd6d8f84e9',
generation_intervals: [
{
date: timestamp,
duration_ms: 13113,
},
],
average_interval_ms: 13113,
events_context_count: 100,
replacements: [
{
uuid: '3119c67b-89b8-43d9-b502-2c32f71875b1',
value: 'ubuntu',
},
{
uuid: '8e7f91b6-6853-48b7-bfb8-403f5efb2365',
value: 'ubuntu-dev-default-3540',
},
],
},
];

export const getRawDefendInsightsMock = (timestamp: string) =>
JSON.stringify(getParsedDefendInsightsMock(timestamp));
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from '../ai_assistant_data_clients/knowledge_base';
import { defaultAssistantFeatures } from '@kbn/elastic-assistant-common';
import { AttackDiscoveryDataClient } from '../lib/attack_discovery/persistence';
import { DefendInsightsDataClient } from '../ai_assistant_data_clients/defend_insights';
import { DefendInsightsDataClient } from '../lib/defend_insights/persistence';
import { authenticatedUser } from './user';

export const createMockClients = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { omit } from 'lodash';
import { InstallationStatus } from '@kbn/product-doc-base-plugin/common/install_status';
import { TrainedModelsProvider } from '@kbn/ml-plugin/server/shared_services/providers';
import { attackDiscoveryFieldMap } from '../lib/attack_discovery/persistence/field_maps_configuration/field_maps_configuration';
import { defendInsightsFieldMap } from '../ai_assistant_data_clients/defend_insights/field_maps_configuration';
import { defendInsightsFieldMap } from '../lib/defend_insights/persistence/field_maps_configuration';
import { getDefaultAnonymizationFields } from '../../common/anonymization';
import { AssistantResourceNames, GetElser } from '../types';
import {
Expand Down Expand Up @@ -49,7 +49,7 @@ import {
GetAIAssistantKnowledgeBaseDataClientParams,
} from '../ai_assistant_data_clients/knowledge_base';
import { AttackDiscoveryDataClient } from '../lib/attack_discovery/persistence';
import { DefendInsightsDataClient } from '../ai_assistant_data_clients/defend_insights';
import { DefendInsightsDataClient } from '../lib/defend_insights/persistence';
import { createGetElserId, ensureProductDocumentationInstalled } from './helpers';
import { hasAIAssistantLicense } from '../routes/helpers';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* 2.0.
*/

import { EndpointError } from '../../../../common/endpoint/errors';

export class InvalidDefendInsightTypeError extends EndpointError {
export class InvalidDefendInsightTypeError extends Error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making elastic/security-defend-workflows CODEOWNERS of:

  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights
  • x-pack/solutions/security/plugins/elastic_assistant/server/routes/defend_insights

as that would cover most of the files below that are (by default) are owned by elastic/security-generative-ai:

Files by Code Owner

elastic/security-defend-workflows

  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/errors.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/schema/incompatible_antivirus.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/schema/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/prompts/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/get_events/get_file_events_query.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/get_events/index.test.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/get_events/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/index.test.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/prompts/incompatible_antivirus.ts
  • x-pack/solutions/security/plugins/security_solution/server/endpoint/services/workflow_insights/builders/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/endpoint/services/workflow_insights/index.test.ts
  • x-pack/solutions/security/plugins/security_solution/server/endpoint/services/workflow_insights/index.ts

elastic/security-generative-ai

  • x-pack/solutions/security/plugins/elastic_assistant/server/mocks/raw_defend_insights.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/errors.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/constants.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_end/helpers/get_generate_or_end_decision/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_end/helpers/get_generate_or_end_decision/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_end/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_end/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_refine_or_end/helpers/get_generate_or_refine_or_end_decision/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_refine_or_end/helpers/get_generate_or_refine_or_end_decision/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_refine_or_end/helpers/get_should_end/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_refine_or_end/helpers/get_should_end/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_refine_or_end/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/generate_or_refine_or_end/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/helpers/get_has_results/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/helpers/get_has_results/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/refine_or_end/helpers/get_refine_or_end_decision/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/refine_or_end/helpers/get_refine_or_end_decision/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/refine_or_end/helpers/get_should_end/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/refine_or_end/helpers/get_should_end/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/refine_or_end/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/refine_or_end/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/retrieve_anonymized_events_or_generate/get_retrieve_or_generate/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/retrieve_anonymized_events_or_generate/get_retrieve_or_generate/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/retrieve_anonymized_events_or_generate/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/edges/retrieve_anonymized_events_or_generate/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/helpers/get_max_hallucination_failures_reached/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/helpers/get_max_hallucination_failures_reached/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/helpers/get_max_retries_reached/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/helpers/get_max_retries_reached/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/mock/mock_anonymization_fields.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/mock/mock_anonymized_events.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/mock/mock_defend_insights.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/mock/mock_file_events_query_results.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/helpers/discard_previous_generations/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/helpers/discard_previous_generations/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/helpers/get_anonymized_events_from_state/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/helpers/get_anonymized_events_from_state/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/helpers/get_events_context_prompt/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/helpers/get_events_context_prompt/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/helpers/get_use_unrefined_results/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/helpers/get_use_unrefined_results/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/schema/incompatible_antivirus.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/schema/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/add_trailing_backticks_if_necessary/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/add_trailing_backticks_if_necessary/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/extract_json/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/extract_json/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/generations_are_repeating/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/generations_are_repeating/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_chain_with_format_instructions/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_chain_with_format_instructions/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_combined/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_combined/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_combined_prompt/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_combined_prompt/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_continue_prompt/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_continue_prompt/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_output_parser/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/get_output_parser/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/parse_combined_or_throw/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/prompts/incompatible_antivirus.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/prompts/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/response_is_hallucinated/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/response_is_hallucinated/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/refine/helpers/discard_previous_refinements/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/refine/helpers/discard_previous_refinements/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/refine/helpers/get_combined_refine_prompt/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/refine/helpers/get_combined_refine_prompt/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/refine/helpers/get_default_refine_prompt/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/refine/helpers/get_use_unrefined_results/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/refine/helpers/get_use_unrefined_results/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/refine/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/retriever/anonymized_events_retriever/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/retriever/anonymized_events_retriever/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/retriever/helpers/get_anonymized_events/get_events/get_file_events_query.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/retriever/helpers/get_anonymized_events/get_events/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/retriever/helpers/get_anonymized_events/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/retriever/helpers/get_anonymized_events/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/retriever/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/retriever/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/state/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/state/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/types.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/persistence/field_maps_configuration.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/persistence/get_defend_insight.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/persistence/get_defend_insight.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/persistence/helpers.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/persistence/helpers.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/persistence/index.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/persistence/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/persistence/types.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/langchain/graphs/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/plugin.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/routes/defend_insights/helpers.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/routes/defend_insights/helpers.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/routes/defend_insights/post_defend_insights.test.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/routes/defend_insights/post_defend_insights.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/routes/defend_insights/translations.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/routes/evaluate/get_graphs_from_names/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/services/app_context.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/types.ts

elastic/security-solution

  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/errors.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/schema/incompatible_antivirus.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/generate/schema/index.ts
  • x-pack/solutions/security/plugins/elastic_assistant/server/lib/defend_insights/graphs/default_defend_insights_graph/nodes/helpers/prompts/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/get_events/get_file_events_query.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/get_events/index.test.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/get_events/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/index.test.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/defend_insights/prompts/incompatible_antivirus.ts
  • x-pack/solutions/security/plugins/security_solution/server/assistant/tools/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/endpoint/services/workflow_insights/builders/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/endpoint/services/workflow_insights/index.test.ts
  • x-pack/solutions/security/plugins/security_solution/server/endpoint/services/workflow_insights/index.ts
  • x-pack/solutions/security/plugins/security_solution/server/plugin.ts

constructor() {
super('invalid defend insight type');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

// LangGraph metadata
export const DEFEND_INSIGHTS_GRAPH_RUN_NAME = 'Defend insights';

// Limits
export const DEFAULT_MAX_GENERATION_ATTEMPTS = 10;
export const DEFAULT_MAX_HALLUCINATION_FAILURES = 5;
export const DEFAULT_MAX_REPEATED_GENERATIONS = 3;

export const NodeType = {
GENERATE_NODE: 'generate',
REFINE_NODE: 'refine',
RETRIEVE_ANONYMIZED_EVENTS_NODE: 'retrieve_anonymized_events',
} as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 { getGenerateOrEndDecision } from '.';

describe('getGenerateOrEndDecision', () => {
it('returns "end" when hasZeroEvents is true', () => {
const result = getGenerateOrEndDecision(true);

expect(result).toEqual('end');
});

it('returns "generate" when hasZeroEvents is false', () => {
const result = getGenerateOrEndDecision(false);

expect(result).toEqual('generate');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

export const getGenerateOrEndDecision = (hasZeroEvents: boolean): 'end' | 'generate' =>
hasZeroEvents ? 'end' : 'generate';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline? move to index? Use NodeTypes from https://github.com/elastic/kibana/pull/211038/files#diff-b7356ce4767fd2e0962d8160c7164f221504c54b4707a1f1a0d903eb4a7b6f11 ?

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 { loggerMock } from '@kbn/logging-mocks';

import { getGenerateOrEndEdge } from '.';
import type { GraphState } from '../../types';

const logger = loggerMock.create();

const graphState: GraphState = {
insights: null,
prompt: 'prompt',
anonymizedEvents: [
{
metadata: {},
pageContent:
'@timestamp,2024-10-10T21:01:24.148Z\n' +
'_id,e809ffc5e0c2e731c1f146e0f74250078136a87574534bf8e9ee55445894f7fc\n' +
'host.name,e1cb3cf0-30f3-4f99-a9c8-518b955c6f90\n' +
'user.name,039c15c5-3964-43e7-a891-42fe2ceeb9ff',
},
{
metadata: {},
pageContent:
'@timestamp,2024-10-10T21:01:24.148Z\n' +
'_id,c675d7eb6ee181d788b474117bae8d3ed4bdc2168605c330a93dd342534fb02b\n' +
'host.name,e1cb3cf0-30f3-4f99-a9c8-518b955c6f90\n' +
'user.name,039c15c5-3964-43e7-a891-42fe2ceeb9ff',
},
],
combinedGenerations: 'generations',
combinedRefinements: 'refinements',
errors: [],
generationAttempts: 0,
generations: [],
hallucinationFailures: 0,
maxGenerationAttempts: 10,
maxHallucinationFailures: 5,
maxRepeatedGenerations: 10,
refinements: [],
refinePrompt: 'refinePrompt',
replacements: {},
unrefinedResults: null,
};

describe('getGenerateOrEndEdge', () => {
beforeEach(() => jest.clearAllMocks());

it("returns 'end' when there are zero events", () => {
const state: GraphState = {
...graphState,
anonymizedEvents: [], // <-- zero events
};

const edge = getGenerateOrEndEdge(logger);
const result = edge(state);

expect(result).toEqual('end');
});

it("returns 'generate' when there are events", () => {
const edge = getGenerateOrEndEdge(logger);
const result = edge(graphState);

expect(result).toEqual('generate');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 { Logger } from '@kbn/core/server';

import type { GraphState } from '../../types';
import { getGenerateOrEndDecision } from './helpers/get_generate_or_end_decision';

export const getGenerateOrEndEdge = (logger?: Logger) => {
const edge = (state: GraphState): 'end' | 'generate' => {
logger?.debug(() => '---GENERATE OR END---');
const { anonymizedEvents } = state;

const hasZeroEvents = !anonymizedEvents.length;

const decision = getGenerateOrEndDecision(hasZeroEvents);

logger?.debug(
() => `generatOrEndEdge evaluated the following (derived) state:\n${JSON.stringify(
{
anonymizedEvents: anonymizedEvents.length,
hasZeroEvents,
},
null,
2
)}
\n---GENERATE OR END: ${decision}---`
);
return decision;
};

return edge;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 { getGenerateOrRefineOrEndDecision } from '.';

describe('getGenerateOrRefineOrEndDecision', () => {
it("returns 'end' if getShouldEnd returns true", () => {
const result = getGenerateOrRefineOrEndDecision({
hasUnrefinedResults: false,
hasZeroEvents: true,
maxHallucinationFailuresReached: true,
maxRetriesReached: true,
});

expect(result).toEqual('end');
});

it("returns 'refine' if hasUnrefinedResults is true and getShouldEnd returns false", () => {
const result = getGenerateOrRefineOrEndDecision({
hasUnrefinedResults: true,
hasZeroEvents: false,
maxHallucinationFailuresReached: false,
maxRetriesReached: false,
});

expect(result).toEqual('refine');
});

it("returns 'generate' if hasUnrefinedResults is false and getShouldEnd returns false", () => {
const result = getGenerateOrRefineOrEndDecision({
hasUnrefinedResults: false,
hasZeroEvents: false,
maxHallucinationFailuresReached: false,
maxRetriesReached: false,
});

expect(result).toEqual('generate');
});
});
Loading