-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[Security Assistant] EIS usage callout #221566
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
Merged
+1,464
−213
Merged
Changes from 31 commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
b080d0e
add EIS cost callout
angorayc 28f48ce
show EIS callout when it's selected
angorayc 3506eb5
conversation EIS message
angorayc f1cc5b5
use Elastic Managed LLM connector
angorayc 870f2ce
fix message
angorayc 3bc8d0a
wording
angorayc 8ca4174
Merge branch 'main' into issues/12656
angorayc f1686d7
add usage cost url
angorayc bf24095
Merge branch 'issues/12656' of github.com:angorayc/kibana into issues…
angorayc d07f6d5
i18n fix
angorayc 3857c09
unit tests
angorayc 9595228
code review
angorayc dd1a58d
Merge branch 'main' into issues/12656
angorayc ba4e25d
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 6470381
rm inferenceEnabled
angorayc 1673fb8
types
angorayc 47609c2
unit tests
angorayc 0e86066
fix up
angorayc c07d353
unit tests
angorayc ed2a90c
Merge branch 'issues/12656' of github.com:angorayc/kibana into issues…
angorayc ae4945b
unit tests
angorayc 73917f7
unit test
angorayc 5ceae9e
Merge branch 'main' of github.com:elastic/kibana into issues/12656
angorayc 7c33d1a
use different storage keys for each tour
angorayc 74ad42d
unit tests
angorayc dda3a25
Merge branch 'main' of github.com:elastic/kibana into issues/12656
angorayc e5c1d60
lint
angorayc d2de469
clean up
angorayc 4a872ae
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine 80e14eb
Merge branch 'main' into issues/12656
angorayc 3ff98f5
Merge branch 'main' into issues/12656
angorayc d4bf753
type
angorayc 10c7314
Merge branch 'issues/12656' of github.com:angorayc/kibana into issues…
angorayc c2061a4
type
angorayc 625b450
Merge branch 'main' into issues/12656
angorayc 6eaaa77
use docLinksServiceMock
angorayc 51fb3d1
Merge branch 'issues/12656' of github.com:angorayc/kibana into issues…
angorayc f14f8d8
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 200ef61
Merge branch 'main' of github.com:elastic/kibana into issues/12656
angorayc 9650631
Update x-pack/platform/packages/shared/kbn-elastic-assistant/impl/ass…
angorayc eb4c539
Update x-pack/solutions/security/plugins/security_solution/public/onb…
angorayc 92e2bca
review
angorayc ec64ef5
Merge branch 'issues/12656' of github.com:angorayc/kibana into issues…
angorayc a6239c4
Update x-pack/platform/packages/shared/kbn-elastic-assistant/impl/tou…
angorayc 5d6bea5
fix up
angorayc aea08c8
fix up
angorayc 5d24e64
lint
angorayc 3e06ade
rm esUiShared
angorayc 1a0893d
unit tests
angorayc 7e6d6c4
Merge branch 'main' of github.com:elastic/kibana into issues/12656
angorayc cd21fea
connector flyout
angorayc 9fa6031
i18n
angorayc 3a894d4
update i18n
angorayc 7af2ce0
copy
angorayc 3edb5fb
lint
angorayc cde945b
Update x-pack/platform/packages/shared/kbn-elastic-assistant/impl/ass…
angorayc e521150
Update x-pack/platform/packages/shared/kbn-elastic-assistant/impl/tou…
angorayc 554959d
Update x-pack/platform/packages/shared/kbn-elastic-assistant/impl/ass…
angorayc a4a877d
rm unused i18n
angorayc 59e895f
Merge branch 'main' into issues/12656
angorayc 8a0bf6e
Merge branch 'main' of github.com:elastic/kibana into issues/12656
angorayc 52aabb7
hide AnonymizedValuesAndCitationsTour when eis tour is active
angorayc 6dd7aa3
update links
angorayc 0e47f80
tests
angorayc bcebe8c
Merge branch 'main' into issues/12656
angorayc 3a5eb5b
Merge branch 'main' into issues/12656
angorayc 0c221b1
Merge branch 'main' into issues/12656
angorayc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...astic-assistant/impl/assistant/assistant_conversation_banner/elastic_llm_callout.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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 useLocalStorage from 'react-use/lib/useLocalStorage'; | ||
import { ElasticLlmCallout } from './elastic_llm_callout'; | ||
import { TestProviders } from '../../mock/test_providers/test_providers'; | ||
|
||
jest.mock('react-use/lib/useLocalStorage'); | ||
|
||
describe('ElasticLlmCallout', () => { | ||
const defaultProps = { | ||
showEISCallout: true, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
(useLocalStorage as jest.Mock).mockReturnValue([false, jest.fn()]); | ||
}); | ||
|
||
it('should not render when showEISCallout is false', () => { | ||
const { queryByTestId } = render(<ElasticLlmCallout showEISCallout={false} />, { | ||
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>, | ||
}); | ||
expect(queryByTestId('elasticLlmCallout')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render when tour is completed', () => { | ||
(useLocalStorage as jest.Mock).mockReturnValue([true, jest.fn()]); | ||
const { queryByTestId } = render( | ||
<TestProviders> | ||
<ElasticLlmCallout {...defaultProps} /> | ||
</TestProviders>, | ||
{ | ||
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>, | ||
} | ||
); | ||
|
||
expect(queryByTestId('elasticLlmCallout')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render links', () => { | ||
const { queryByTestId } = render( | ||
<TestProviders> | ||
<ElasticLlmCallout {...defaultProps} /> | ||
</TestProviders>, | ||
{ wrapper: ({ children }) => <TestProviders>{children}</TestProviders> } | ||
); | ||
expect(queryByTestId('elasticLlmUsageCostLink')).toHaveTextContent('additional costs incur'); | ||
expect(queryByTestId('elasticLlmConnectorLink')).toHaveTextContent('connector'); | ||
expect(queryByTestId('elasticLlmSettingsLink')).toHaveTextContent('Settings'); | ||
}); | ||
|
||
it('should show callout when showEISCallout changes to true', () => { | ||
const { rerender, queryByTestId } = render( | ||
<TestProviders> | ||
<ElasticLlmCallout showEISCallout={false} /> | ||
</TestProviders>, | ||
{ wrapper: ({ children }) => <TestProviders>{children}</TestProviders> } | ||
); | ||
expect(queryByTestId('elasticLlmCallout')).not.toBeInTheDocument(); | ||
|
||
rerender(<ElasticLlmCallout showEISCallout={true} />); | ||
expect(queryByTestId('elasticLlmCallout')).toBeInTheDocument(); | ||
}); | ||
}); |
122 changes: 122 additions & 0 deletions
122
...bn-elastic-assistant/impl/assistant/assistant_conversation_banner/elastic_llm_callout.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* 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, { useCallback, useEffect, useState } from 'react'; | ||
import useLocalStorage from 'react-use/lib/useLocalStorage'; | ||
|
||
import { css } from '@emotion/react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { EuiCallOut, EuiLink, useEuiTheme } from '@elastic/eui'; | ||
import { useAssistantContext } from '../../assistant_context'; | ||
import { useAssistantSpaceId } from '../use_space_aware_context'; | ||
import { NEW_FEATURES_TOUR_STORAGE_KEYS } from '../../tour/const'; | ||
import { useTourStorageKey } from '../../tour/common/hooks/use_tour_storage_key'; | ||
|
||
export const ElasticLlmCallout = ({ showEISCallout }: { showEISCallout: boolean }) => { | ||
const { | ||
getUrlForApp, | ||
docLinks: { | ||
links: { | ||
alerting: { elasticManagedLlmUsageCost: ELASTIC_LLM_USAGE_COST_LINK }, | ||
}, | ||
}, | ||
} = useAssistantContext(); | ||
const spaceId = useAssistantSpaceId(); | ||
const { euiTheme } = useEuiTheme(); | ||
const tourStorageKey = useTourStorageKey( | ||
NEW_FEATURES_TOUR_STORAGE_KEYS.CONVERSATION_CONNECTOR_ELASTIC_LLM | ||
); | ||
const [tourCompleted, setTourCompleted] = useLocalStorage<boolean>(tourStorageKey, false); | ||
const [showCallOut, setShowCallOut] = useState<boolean>(showEISCallout); | ||
|
||
const onDismiss = useCallback(() => { | ||
setShowCallOut(false); | ||
setTourCompleted(true); | ||
}, [setTourCompleted]); | ||
|
||
useEffect(() => { | ||
if (showEISCallout && !tourCompleted) { | ||
setShowCallOut(true); | ||
} else { | ||
setShowCallOut(false); | ||
} | ||
}, [showEISCallout, tourCompleted]); | ||
|
||
if (!showCallOut) { | ||
return; | ||
} | ||
|
||
return ( | ||
<EuiCallOut | ||
data-test-subj="elasticLlmCallout" | ||
onDismiss={onDismiss} | ||
iconType="iInCircle" | ||
title={i18n.translate('xpack.elasticAssistant.assistant.connectors.elasticLlmCallout.title', { | ||
defaultMessage: 'You are now using the Elastic-managed LLM connector', | ||
angorayc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
})} | ||
size="s" | ||
css={css` | ||
padding: ${euiTheme.size.s} !important; | ||
`} | ||
> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.elasticAssistant.assistant.connectors.tour.elasticLlmDescription" | ||
defaultMessage="A large language model (LLM) is required to power the AI Assistant and AI-driven features in Elastic. By default, Elastic uses its Elastic-managed LLM connector ({costLink}) when no custom connectors are available. You can always configure and use your own {connectorLink} and change the default in {settingsLink}." | ||
angorayc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
values={{ | ||
costLink: ( | ||
<EuiLink | ||
data-test-subj="elasticLlmUsageCostLink" | ||
href={ELASTIC_LLM_USAGE_COST_LINK} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
external | ||
> | ||
<FormattedMessage | ||
id="xpack.elasticAssistant.assistant.eisCallout.extraCost.label" | ||
defaultMessage="additional costs incur" | ||
/> | ||
</EuiLink> | ||
), | ||
connectorLink: ( | ||
<EuiLink | ||
data-test-subj="elasticLlmConnectorLink" | ||
href={getUrlForApp('management', { | ||
path: `/insightsAndAlerting/triggersActionsConnectors/connectors`, | ||
})} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
external | ||
> | ||
<FormattedMessage | ||
id="xpack.elasticAssistant.assistant.eisCallout.connector.label" | ||
defaultMessage="connector" | ||
/> | ||
</EuiLink> | ||
), | ||
settingsLink: ( | ||
<EuiLink | ||
data-test-subj="elasticLlmSettingsLink" | ||
href={getUrlForApp('management', { | ||
path: `/kibana/spaces/edit/${spaceId}`, | ||
})} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
external | ||
> | ||
<FormattedMessage | ||
id="xpack.elasticAssistant.assistant.eisCallout.settings.label" | ||
defaultMessage="Settings" | ||
/> | ||
</EuiLink> | ||
), | ||
}} | ||
/> | ||
</p> | ||
</EuiCallOut> | ||
); | ||
}; |
89 changes: 89 additions & 0 deletions
89
.../shared/kbn-elastic-assistant/impl/assistant/assistant_conversation_banner/index.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* 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, screen } from '@testing-library/react'; | ||
import { AssistantConversationBanner } from '.'; | ||
import { AIConnector, Conversation, useAssistantContext } from '../../..'; | ||
import { customConvo } from '../../mock/conversation'; | ||
|
||
jest.mock('../../..'); | ||
|
||
jest.mock('../../connectorland/connector_missing_callout', () => ({ | ||
ConnectorMissingCallout: () => <div data-test-subj="connector-missing-callout" />, | ||
})); | ||
|
||
jest.mock('./elastic_llm_callout', () => ({ | ||
ElasticLlmCallout: () => <div data-test-subj="elastic-llm-callout" />, | ||
})); | ||
|
||
describe('AssistantConversationBanner', () => { | ||
const setIsSettingsModalVisible = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders ConnectorMissingCallout when shouldShowMissingConnectorCallout is true', () => { | ||
(useAssistantContext as jest.Mock).mockReturnValue({ inferenceEnabled: true }); | ||
|
||
render( | ||
<AssistantConversationBanner | ||
isSettingsModalVisible={false} | ||
setIsSettingsModalVisible={setIsSettingsModalVisible} | ||
shouldShowMissingConnectorCallout={true} | ||
currentConversation={undefined} | ||
connectors={[]} | ||
/> | ||
); | ||
|
||
expect(screen.getByTestId('connector-missing-callout')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders ElasticLlmCallout when Elastic LLM is enabled', () => { | ||
(useAssistantContext as jest.Mock).mockReturnValue({ inferenceEnabled: true }); | ||
const mockConnectors = [ | ||
{ id: 'mockLLM', actionTypeId: '.inference', isPreconfigured: true }, | ||
] as AIConnector[]; | ||
|
||
const mockConversation = { | ||
...customConvo, | ||
id: 'mockConversation', | ||
apiConfig: { | ||
connectorId: 'mockLLM', | ||
actionTypeId: '.inference', | ||
}, | ||
} as Conversation; | ||
|
||
render( | ||
<AssistantConversationBanner | ||
isSettingsModalVisible={false} | ||
setIsSettingsModalVisible={setIsSettingsModalVisible} | ||
shouldShowMissingConnectorCallout={false} | ||
currentConversation={mockConversation} | ||
connectors={mockConnectors} | ||
/> | ||
); | ||
|
||
expect(screen.getByTestId('elastic-llm-callout')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders nothing when no conditions are met', () => { | ||
(useAssistantContext as jest.Mock).mockReturnValue({ inferenceEnabled: false }); | ||
|
||
const { container } = render( | ||
<AssistantConversationBanner | ||
isSettingsModalVisible={false} | ||
setIsSettingsModalVisible={setIsSettingsModalVisible} | ||
shouldShowMissingConnectorCallout={false} | ||
currentConversation={undefined} | ||
connectors={[]} | ||
/> | ||
); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
...kages/shared/kbn-elastic-assistant/impl/assistant/assistant_conversation_banner/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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 { AIConnector, Conversation, useAssistantContext } from '../../..'; | ||
import { isElasticManagedLlmConnector } from '../../connectorland/helpers'; | ||
import { ConnectorMissingCallout } from '../../connectorland/connector_missing_callout'; | ||
import { ElasticLlmCallout } from './elastic_llm_callout'; | ||
|
||
export const AssistantConversationBanner = React.memo( | ||
({ | ||
isSettingsModalVisible, | ||
setIsSettingsModalVisible, | ||
shouldShowMissingConnectorCallout, | ||
currentConversation, | ||
connectors, | ||
}: { | ||
isSettingsModalVisible: boolean; | ||
setIsSettingsModalVisible: React.Dispatch<React.SetStateAction<boolean>>; | ||
shouldShowMissingConnectorCallout: boolean; | ||
currentConversation: Conversation | undefined; | ||
connectors: AIConnector[] | undefined; | ||
}) => { | ||
const { inferenceEnabled } = useAssistantContext(); | ||
const showEISCallout = useMemo(() => { | ||
if (inferenceEnabled && currentConversation && currentConversation.id !== '') { | ||
if (currentConversation?.apiConfig?.connectorId) { | ||
return connectors?.some( | ||
(c) => | ||
c.id === currentConversation.apiConfig?.connectorId && isElasticManagedLlmConnector(c) | ||
); | ||
} | ||
} | ||
}, [inferenceEnabled, currentConversation, connectors]); | ||
if (shouldShowMissingConnectorCallout) { | ||
return ( | ||
<ConnectorMissingCallout | ||
isConnectorConfigured={(connectors?.length ?? 0) > 0} | ||
isSettingsModalVisible={isSettingsModalVisible} | ||
setIsSettingsModalVisible={setIsSettingsModalVisible} | ||
/> | ||
); | ||
} | ||
|
||
if (showEISCallout) { | ||
return <ElasticLlmCallout showEISCallout={showEISCallout} />; | ||
} | ||
|
||
return null; | ||
} | ||
); | ||
|
||
AssistantConversationBanner.displayName = 'AssistantConversationBanner'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.