Skip to content

Commit 0ffe4ce

Browse files
committed
[Security Solution] [AI Assistant] Update LLM connector selector component (#236811)
## Summary Summarize your PR. If it involves visual changes include a screenshot or gif. Update the connector selector component within the security solution to use the shared component from `x-pack/platform/packages/shared/ai-assistant/ai-assistant-connector-selector-action/connector_selectable.tsx`. Security AI Assistant: <img width="1717" height="556" alt="image" src="https://github.com/user-attachments/assets/a9d46c3f-c92e-4fa5-9982-c42c50092902" /> Attack Discovery: <img width="2680" height="933" alt="image" src="https://github.com/user-attachments/assets/b87b2b46-dca1-4964-ae01-c811d56f21b4" /> Security Get Started: <img width="1570" height="1525" alt="image" src="https://github.com/user-attachments/assets/1e10a767-0d85-4726-ad2c-c55e492f560b" /> Automatic migration Get Started: <img width="1420" height="1004" alt="image" src="https://github.com/user-attachments/assets/b146e52b-c92c-4493-8a2d-033579eeca34" /> ### How to test: 1. Enable the feature flag: ``` // kibana.dev.yml feature_flags.overrides.aiAssistant.defaultLlmSettingEnabled: true ``` 2. Start Kibana 3. Go to Stack management > GenAi setting and in the default llm setting select a default LLM and check the checkbox below, making only the default LLM available. 4. Go to the security solution and open the assistant. Verify that only the default LLM you have selected is available. Also, verify the new LLM selector component is used (see screenshots above). 5. Go to attack discovery, and in the run configuration, again check that only your default LLM is available to be selected. Also ensure the new LLM selector component is used (see screenshot above). 6. Go to the Security solution getting started page and check that the new component is used in the Security tab and in the Automatic Migrations tab (see screenshot above). ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [X] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [X] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [X] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [X] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [X] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [X] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [X] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [X] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com> (cherry picked from commit b7b1747) # Conflicts: # x-pack/platform/packages/shared/kbn-elastic-assistant-common/tsconfig.json # x-pack/platform/packages/shared/kbn-elastic-assistant/impl/connectorland/connector_selector/index.tsx # x-pack/platform/packages/shared/kbn-elastic-assistant/tsconfig.json # x-pack/solutions/security/packages/connectors/src/connector_selector.test.tsx # x-pack/solutions/security/packages/connectors/src/connector_selector.tsx # x-pack/solutions/security/plugins/security_solution/public/common/hooks/use_ai_connectors.ts # x-pack/solutions/security/plugins/security_solution/public/onboarding/components/onboarding_body/cards/common/connectors/connector_cards.test.tsx # x-pack/solutions/security/plugins/security_solution/public/onboarding/components/onboarding_body/cards/common/connectors/connector_selector_panel.test.tsx # x-pack/solutions/security/plugins/security_solution/public/onboarding/components/onboarding_body/cards/common/connectors/connector_selector_panel.tsx # x-pack/solutions/security/plugins/security_solution/public/onboarding/components/onboarding_body/cards/siem_migrations/ai_connector/connectors_check_complete.ts # x-pack/solutions/security/plugins/security_solution/public/siem_migrations/common/components/start_migration_modal/index.test.tsx # x-pack/solutions/security/plugins/security_solution/public/siem_migrations/common/components/start_migration_modal/index.tsx # x-pack/solutions/security/test/security_solution_cypress/cypress/tasks/assistant.ts # x-pack/test/security_solution_cypress/cypress/tasks/api_calls/connectors.ts
1 parent fa769ce commit 0ffe4ce

22 files changed

Lines changed: 811 additions & 296 deletions

File tree

x-pack/platform/packages/shared/ai-assistant/ai-assistant-connector-selector-action/connector_selectable.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ describe('ConnectorSelectable', () => {
5555
];
5656

5757
allConnectors.forEach((connector) => {
58+
expect(screen.queryByText(connector.label)).toBeInTheDocument();
5859
expect(connector['data-test-subj']).toBeDefined();
5960
expect(screen.queryByTestId(connector['data-test-subj']!)).toBeInTheDocument();
60-
expect(screen.queryByText(connector.label)).toBeInTheDocument();
6161
});
6262

6363
expect(allConnectors.length).toBe(6);

x-pack/platform/packages/shared/ai-assistant/ai-assistant-connector-selector-action/connector_selectable.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import { ConnectorSelectableFooter } from './connector_selectable_footer';
1313

1414
export type ConnectorSelectableProps = Pick<
1515
ConnectorSelectableComponentProps,
16-
'value' | 'onValueChange' | 'customConnectors' | 'preConfiguredConnectors' | 'defaultConnectorId'
16+
| 'value'
17+
| 'onValueChange'
18+
| 'customConnectors'
19+
| 'preConfiguredConnectors'
20+
| 'defaultConnectorId'
21+
| 'renderOption'
22+
| 'data-test-subj'
1723
> &
1824
Pick<ConnectorSelectableFooterProps, 'onAddConnectorClick' | 'onManageConnectorsClick'>;
1925

@@ -36,6 +42,8 @@ export const ConnectorSelectable: React.FC<ConnectorSelectableProps> = (props) =
3642
preConfiguredConnectors={props.preConfiguredConnectors}
3743
defaultConnectorId={props.defaultConnectorId}
3844
footer={footer}
45+
renderOption={props.renderOption}
46+
data-test-subj={props['data-test-subj']}
3947
/>
4048
);
4149
};

x-pack/platform/packages/shared/ai-assistant/ai-assistant-connector-selector-action/connector_selectable_component.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import React, { useMemo, useState } from 'react';
9-
import type { EuiSelectableOption } from '@elastic/eui';
9+
import type { EuiSelectableOption, EuiSelectableProps } from '@elastic/eui';
1010
import { EuiBadge, EuiPanel, EuiSelectable } from '@elastic/eui';
1111
import type { EuiSelectableLIOption } from '@elastic/eui/src/components/selectable/selectable_option';
1212
import { translations as i8n } from './connector_selector.translations';
@@ -31,6 +31,9 @@ export interface ConnectorSelectableComponentProps<
3131
onValueChange?: (value: string, option: EuiSelectableOption<T>) => void;
3232
/** Selectable footer component */
3333
footer?: React.ReactElement;
34+
35+
/** Render option component */
36+
renderOption?: EuiSelectableProps['renderOption'];
3437
}
3538

3639
export const ConnectorSelectableComponent = <T extends { value: string } = { value: string }>(
@@ -63,6 +66,7 @@ export const ConnectorSelectableComponent = <T extends { value: string } = { val
6366
key: connector.value,
6467
checked: connector.value === selectedValue ? 'on' : undefined,
6568
append: connector.value === props.defaultConnectorId ? defaultConnectorBadge : undefined,
69+
'data-test-subj': connector['data-test-subj'] ?? connector.value,
6670
})),
6771
[props.preConfiguredConnectors, selectedValue, props.defaultConnectorId, defaultConnectorBadge]
6872
);
@@ -74,6 +78,7 @@ export const ConnectorSelectableComponent = <T extends { value: string } = { val
7478
key: connector.value,
7579
checked: connector.value === selectedValue ? 'on' : undefined,
7680
append: connector.value === props.defaultConnectorId ? defaultConnectorBadge : undefined,
81+
'data-test-subj': connector['data-test-subj'] ?? connector.value,
7782
})),
7883
[props.customConnectors, selectedValue, props.defaultConnectorId, defaultConnectorBadge]
7984
);
@@ -124,6 +129,7 @@ export const ConnectorSelectableComponent = <T extends { value: string } = { val
124129
singleSelection
125130
options={options}
126131
onChange={handleChange}
132+
renderOption={props.renderOption}
127133
>
128134
{(list) => (
129135
<>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { SettingsStart } from '@kbn/core-ui-settings-browser';
9+
import {
10+
GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR,
11+
GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR_DEFAULT_ONLY,
12+
} from '@kbn/management-settings-ids';
13+
import { getAvailableAiConnectors } from './get_available_connectors';
14+
15+
describe('getAvailableConnectors', () => {
16+
const connectors = [
17+
{
18+
id: 'connectorId1',
19+
},
20+
{
21+
id: 'connectorId2',
22+
},
23+
{
24+
id: 'connectorId3',
25+
},
26+
];
27+
28+
const settingsClientGet = jest.fn().mockImplementation((settingKey) => {
29+
if (settingKey === GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR) {
30+
return 'connectorId1';
31+
}
32+
if (settingKey === GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR_DEFAULT_ONLY) {
33+
return false;
34+
}
35+
});
36+
37+
const settings = {
38+
client: {
39+
get: settingsClientGet,
40+
},
41+
} as unknown as SettingsStart;
42+
43+
it('should return all connectors if default connector is not set', () => {
44+
const result = getAvailableAiConnectors({
45+
allAiConnectors: connectors,
46+
settings,
47+
});
48+
49+
expect(result).toEqual(connectors);
50+
});
51+
52+
it('should return only the default connector if default connector only is set', () => {
53+
settingsClientGet.mockImplementation((settingKey) => {
54+
if (settingKey === GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR) {
55+
return 'connectorId1';
56+
}
57+
if (settingKey === GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR_DEFAULT_ONLY) {
58+
return true;
59+
}
60+
});
61+
62+
const result = getAvailableAiConnectors({
63+
allAiConnectors: connectors,
64+
settings,
65+
});
66+
67+
expect(result.length).toEqual(1);
68+
expect(result[0].id).toEqual('connectorId1');
69+
});
70+
71+
it('should return all connectors if default connector only is set but default connector is not found', () => {
72+
settingsClientGet.mockImplementation((settingKey) => {
73+
if (settingKey === GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR) {
74+
return 'unknownConnectorId';
75+
}
76+
if (settingKey === GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR_DEFAULT_ONLY) {
77+
return true;
78+
}
79+
});
80+
81+
const result = getAvailableAiConnectors({
82+
allAiConnectors: connectors,
83+
settings,
84+
});
85+
86+
expect(result).toEqual(connectors);
87+
});
88+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { SettingsStart } from '@kbn/core-ui-settings-browser';
9+
import {
10+
GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR,
11+
GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR_DEFAULT_ONLY,
12+
} from '@kbn/management-settings-ids';
13+
14+
interface Props<T extends { id: string }> {
15+
allAiConnectors: T[];
16+
settings: SettingsStart;
17+
}
18+
19+
/**
20+
* Get the available AI connectors based on the default AI connector settings. This is only a
21+
* client side filter and does not make any API calls.
22+
*
23+
* @param allAiConnectors - The list of all AI connectors.
24+
* @param settings - Kibana SettingsStart.
25+
* @returns The available AI connectors.
26+
*/
27+
export const getAvailableAiConnectors = <T extends { id: string }>({
28+
allAiConnectors,
29+
settings,
30+
}: Props<T>): T[] => {
31+
const defaultAiConnectorId = settings.client.get<string>(GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR);
32+
const defaultAiConnectorOnly = settings.client.get<boolean>(
33+
GEN_AI_SETTINGS_DEFAULT_AI_CONNECTOR_DEFAULT_ONLY,
34+
false
35+
);
36+
37+
const availableConnectors = allAiConnectors.filter((connector) => {
38+
if (defaultAiConnectorOnly) {
39+
return connector.id === defaultAiConnectorId;
40+
}
41+
return true;
42+
});
43+
44+
const aiConnectors = availableConnectors.length > 0 ? availableConnectors : allAiConnectors;
45+
46+
return aiConnectors;
47+
};

x-pack/platform/packages/shared/kbn-elastic-assistant/impl/connectorland/connector_selector/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('Connector selector', () => {
7171
</TestProviders>
7272
);
7373
fireEvent.click(getByTestId('connector-selector'));
74-
expect(getByTestId('addNewConnectorButton')).toBeInTheDocument();
74+
expect(getByTestId('aiAssistantAddConnectorButton')).toBeInTheDocument();
7575
});
7676
it('renders with provided selected connector', () => {
7777
const { getByTestId } = render(
@@ -100,7 +100,7 @@ describe('Connector selector', () => {
100100
</TestProviders>
101101
);
102102
fireEvent.click(getByTestId('connector-selector'));
103-
fireEvent.click(getByTestId('addNewConnectorButton'));
103+
fireEvent.click(getByTestId('aiAssistantAddConnectorButton'));
104104

105105
fireEvent.click(getByTestId('modal-mock'));
106106

0 commit comments

Comments
 (0)