-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Elastic Security Assistant #156933
Merged
andrew-goldstein
merged 53 commits into
elastic:main
from
spong:security-assistant-playground
Jun 2, 2023
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
562e5d9
Hiiiiii world
spong 199af3c
[Security Solution] Security Assistant: useSecurityAssistantQuery hoo…
andrew-goldstein 6b9298e
Adds overlay assistant, new quick prompt pills, and cleans up assista…
spong 77af478
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 3473f39
Adds conversation selector, custom localstorage keys, and UI cleanup
spong 767523c
[Security Solution] Security Assistant: context provider hooks #6
andrew-goldstein 8a66b9c
Removes self from state jail
spong f9f58f5
Extracts and fixes conversation selector and adds createConversation …
spong 7964a64
Brings back localstorage support and updates localstorage hook to sup…
spong 07ac4f3
Adds support for autofocusing prompt when opening timeline or selecti…
spong a3ddec0
Adds new useSecurityAssistantOverlay hook for programmatically openin…
spong 521f26a
[Security Solution] Security Assistant: Prompt Editor / Sends System …
andrew-goldstein 41d7233
- previews the prompt context before sending it (#8)
andrew-goldstein 734012a
Adds new markdown parser for send to timeline actions for eql, kql an…
spong 8a9aef8
Factored out codeblock analysis, fixed styling in timeline, extracted…
spong 8b05944
[Security Solution] Security Assistant: Add note to Timeline #9
andrew-goldstein a7f4db3
Adds selected rules as prompt context, fixes some styling and ux
spong 0aa6690
Fixes data issue with translations
spong e10e191
Fixes sent to timeline action render issue
spong 56b8cab
[Security Solution] Security Assistant: fixes i18n errors (#10)
andrew-goldstein f8577a0
[Security Solution] Security Assistant: bootstraps the @kbn/elastic-a…
andrew-goldstein a5be762
[Security Solution] Security Assistant: Moves the assistant to the @k…
andrew-goldstein c1ca34f
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong e055574
[Security Solution] Security Assistant: fixes linter issues (#13)
andrew-goldstein 456c5d1
[Security Solution] Security Assistant: take out the trash (icon) (#14)
andrew-goldstein 7de6b51
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 6d567fe
Integrates with GenAI Connector
spong 42e86e3
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 578fb89
[Security Solution] Security Assistant: Reduces the public API surfac…
andrew-goldstein cb99251
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 893c7c9
Removes export of OpenAiProviderType that was added in main
spong 7f81b1b
Swathe of usability and bugfixes around connector integration
spong 2caa3cc
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 6f2f1bc
[Security Solution] Security Assistant: Data Quality dashboard _New C…
andrew-goldstein e821e36
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 4aa6401
Adds CRUD for QuickPrompts and extracts them and base PromptContexts …
spong b235e15
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 705f9ee
i18n updates from James
spong 4385ffd
[Security Solution] Security Assistant: adds the assistantEnabled fea…
andrew-goldstein 313b7ef
Fixes from PR review and desk testing
spong d527032
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 7df9859
Updating api error language
spong 93bbcdb
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 6154e21
[Security Solution] Security Assistant: fixes project lint errors (#18)
andrew-goldstein 0bed49d
[Security Solution] Security Assistant: updates CODEOWNERS (#19)
andrew-goldstein 71f0da8
Removes space key listener to resolve cypress issues
spong ff5d0dd
[Security Solution] Security Assistant: updates mocks (#20)
andrew-goldstein dca195e
Test fixes, i18n update, and additional feature flag conditional
spong 52657fa
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong c19347b
Fixes prompt submit issue
spong 435a988
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong be6c41f
Skips flakey cypress test
spong 542f3e5
Merge branch 'main' of github.com:elastic/kibana into security-assist…
spong 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 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
Validating CODEOWNERS rules …
This file contains 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 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 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 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 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 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,20 @@ | ||
# @kbn/elastic-assistant | ||
|
||
The `Elastic Assistant` is a user interface for interacting with generative AIs, like `ChatGPT`. | ||
|
||
This package provides: | ||
|
||
- Components for rendering the `Elastic Assistant` | ||
- Hooks for passing context (for example, fields in an alert) to the `Elastic Assistant`, enabling users to include this content in their queries | ||
|
||
## Maintainers | ||
|
||
Maintained by the Security Solution team | ||
|
||
## Running unit tests with code coverage | ||
|
||
To (interactively) run unit tests with code coverage, run the following command: | ||
|
||
```sh | ||
cd $KIBANA_HOME && node scripts/jest --watch x-pack/packages/kbn-elastic-assistant --coverage | ||
``` |
84 changes: 84 additions & 0 deletions
84
x-pack/packages/kbn-elastic-assistant/impl/assistant/api.tsx
This file contains 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,84 @@ | ||
/* | ||
* 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 { OpenAiProviderType } from '@kbn/stack-connectors-plugin/public/common'; | ||
|
||
import { HttpSetup } from '@kbn/core-http-browser'; | ||
import type { Message } from '../assistant_context/types'; | ||
import { Conversation } from '../assistant_context/types'; | ||
import { API_ERROR } from './translations'; | ||
|
||
export interface FetchConnectorExecuteAction { | ||
apiConfig: Conversation['apiConfig']; | ||
http: HttpSetup; | ||
messages: Message[]; | ||
signal?: AbortSignal | undefined; | ||
} | ||
|
||
export const fetchConnectorExecuteAction = async ({ | ||
http, | ||
messages, | ||
apiConfig, | ||
signal, | ||
}: FetchConnectorExecuteAction): Promise<string> => { | ||
const outboundMessages = messages.map((msg) => ({ | ||
role: msg.role, | ||
content: msg.content, | ||
})); | ||
|
||
const body = | ||
apiConfig?.provider === OpenAiProviderType.OpenAi | ||
? { | ||
model: 'gpt-3.5-turbo', | ||
messages: outboundMessages, | ||
n: 1, | ||
stop: null, | ||
temperature: 0.2, | ||
} | ||
: { | ||
messages: outboundMessages, | ||
}; | ||
|
||
const requestBody = { | ||
params: { | ||
subActionParams: { | ||
body: JSON.stringify(body), | ||
}, | ||
subAction: 'test', | ||
}, | ||
}; | ||
|
||
try { | ||
// TODO: Find return type for this API | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const response = await http.fetch<any>( | ||
`/api/actions/connector/${apiConfig?.connectorId}/_execute`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(requestBody), | ||
signal, | ||
} | ||
); | ||
|
||
const data = response.data; | ||
if (response.status !== 'ok') { | ||
return API_ERROR; | ||
} | ||
|
||
if (data.choices && data.choices.length > 0 && data.choices[0].message.content) { | ||
const result = data.choices[0].message.content.trim(); | ||
return result; | ||
} else { | ||
return API_ERROR; | ||
} | ||
} catch (error) { | ||
return API_ERROR; | ||
} | ||
}; |
90 changes: 90 additions & 0 deletions
90
x-pack/packages/kbn-elastic-assistant/impl/assistant/assistant_overlay/index.tsx
This file contains 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,90 @@ | ||
/* | ||
* 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 { EuiModal } from '@elastic/eui'; | ||
|
||
import useEvent from 'react-use/lib/useEvent'; | ||
// eslint-disable-next-line @kbn/eslint/module_migration | ||
import styled from 'styled-components'; | ||
import { ShowAssistantOverlayProps, useAssistantContext } from '../../assistant_context'; | ||
import { Assistant } from '..'; | ||
import { WELCOME_CONVERSATION_TITLE } from '../use_conversation/translations'; | ||
|
||
const isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0; | ||
|
||
const StyledEuiModal = styled(EuiModal)` | ||
min-width: 1200px; | ||
max-height: 100%; | ||
height: 100%; | ||
`; | ||
|
||
/** | ||
* Modal container for Security Assistant conversations, receiving the page contents as context, plus whatever | ||
* component currently has focus and any specific context it may provide through the SAssInterface. | ||
*/ | ||
export const AssistantOverlay: React.FC = React.memo(() => { | ||
const [isModalVisible, setIsModalVisible] = useState(false); | ||
const [conversationId, setConversationId] = useState<string | undefined>( | ||
WELCOME_CONVERSATION_TITLE | ||
); | ||
const [promptContextId, setPromptContextId] = useState<string | undefined>(); | ||
const { setShowAssistantOverlay } = useAssistantContext(); | ||
|
||
// Bind `showAssistantOverlay` in SecurityAssistantContext to this modal instance | ||
const showOverlay = useCallback( | ||
() => | ||
({ | ||
showOverlay: so, | ||
promptContextId: pid, | ||
conversationId: cid, | ||
}: ShowAssistantOverlayProps) => { | ||
setIsModalVisible(so); | ||
setPromptContextId(pid); | ||
setConversationId(cid); | ||
}, | ||
[setIsModalVisible] | ||
); | ||
useEffect(() => { | ||
setShowAssistantOverlay(showOverlay); | ||
}, [setShowAssistantOverlay, showOverlay]); | ||
|
||
// Register keyboard listener to show the modal when cmd + ; is pressed | ||
const onKeyDown = useCallback( | ||
(event: KeyboardEvent) => { | ||
if (event.key === ';' && (isMac ? event.metaKey : event.ctrlKey)) { | ||
event.preventDefault(); | ||
setIsModalVisible(!isModalVisible); | ||
} | ||
}, | ||
[isModalVisible] | ||
); | ||
useEvent('keydown', onKeyDown); | ||
|
||
// Modal control functions | ||
const cleanupAndCloseModal = useCallback(() => { | ||
setIsModalVisible(false); | ||
setPromptContextId(undefined); | ||
setConversationId(conversationId); | ||
}, [conversationId]); | ||
|
||
const handleCloseModal = useCallback(() => { | ||
cleanupAndCloseModal(); | ||
}, [cleanupAndCloseModal]); | ||
|
||
return ( | ||
<> | ||
{isModalVisible && ( | ||
<StyledEuiModal onClose={handleCloseModal}> | ||
<Assistant conversationId={conversationId} promptContextId={promptContextId} /> | ||
</StyledEuiModal> | ||
)} | ||
</> | ||
); | ||
}); | ||
|
||
AssistantOverlay.displayName = 'AssistantOverlay'; |
15 changes: 15 additions & 0 deletions
15
x-pack/packages/kbn-elastic-assistant/impl/assistant/assistant_overlay/translations.ts
This file contains 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,15 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const CANCEL_BUTTON = i18n.translate( | ||
'xpack.elasticAssistant.assistant.overlay.CancelButton', | ||
{ | ||
defaultMessage: 'Cancel', | ||
} | ||
); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fine for the first iteration, but as an alternative to the connector API we can use
ActionsClient
and I prefer it better, because it will be easier to tune its methods to the custom needs like bringing streams functionality.I was thinking maybe that will be more extendable architecture if that logic will be outside of that package. And
handleSendMessage
could be a consumer callback with the Connector way integration or some other method for sending messages.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh gosh, I totally missed there was a client! Thank you -- this will be much preferred 👍. Made a note to swap to the client (but probably won't do in this initial PR if that's okay).