Skip to content

Commit

Permalink
[Security Solution] Security Assistant: bootstraps the @kbn/elastic-a…
Browse files Browse the repository at this point in the history
…ssistant package #11

- bootstraps the `@kbn/elastic-assistant` package in `x-pack/packages/kbn-elastic-assistant`
  • Loading branch information
andrew-goldstein authored May 18, 2023
1 parent 56b8cab commit f8577a0
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ module.exports = {
// front end and common typescript and javascript files only
files: [
'x-pack/plugins/ecs_data_quality_dashboard/common/**/*.{js,mjs,ts,tsx}',
'x-pack/packages/kbn-elastic-assistant/**/*.{js,mjs,ts,tsx}',
'x-pack/packages/security-solution/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/security_solution/public/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/security_solution/common/**/*.{js,mjs,ts,tsx}',
Expand Down Expand Up @@ -1007,13 +1008,15 @@ module.exports = {
// This should be a very small set as most linter rules are useful for tests as well.
files: [
'x-pack/plugins/ecs_data_quality_dashboard/**/*.{ts,tsx}',
'x-pack/packages/kbn-elastic-assistant/**/*.{ts,tsx}',
'x-pack/packages/security-solution/**/*.{ts,tsx}',
'x-pack/plugins/security_solution/**/*.{ts,tsx}',
'x-pack/plugins/timelines/**/*.{ts,tsx}',
'x-pack/plugins/cases/**/*.{ts,tsx}',
],
excludedFiles: [
'x-pack/plugins/ecs_data_quality_dashboard/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/packages/kbn-elastic-assistant/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/packages/security-solution/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/plugins/security_solution/**/*.{test,mock,test_helper}.{ts,tsx}',
'x-pack/plugins/timelines/**/*.{test,mock,test_helper}.{ts,tsx}',
Expand All @@ -1027,6 +1030,7 @@ module.exports = {
// typescript only for front and back end
files: [
'x-pack/plugins/ecs_data_quality_dashboard/**/*.{ts,tsx}',
'x-pack/packages/kbn-elastic-assistant/**/*.{ts,tsx}',
'x-pack/packages/security-solution/**/*.{ts,tsx}',
'x-pack/plugins/security_solution/**/*.{ts,tsx}',
'x-pack/plugins/timelines/**/*.{ts,tsx}',
Expand Down Expand Up @@ -1059,6 +1063,7 @@ module.exports = {
// typescript and javascript for front and back end
files: [
'x-pack/plugins/ecs_data_quality_dashboard/**/*.{js,mjs,ts,tsx}',
'x-pack/packages/kbn-elastic-assistant/**/*.{js,mjs,ts,tsx}',
'x-pack/packages/security-solution/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/security_solution/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/timelines/**/*.{js,mjs,ts,tsx}',
Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ packages/kbn-docs-utils @elastic/kibana-operations
packages/kbn-dom-drag-drop @elastic/kibana-visualizations @elastic/kibana-data-discovery
packages/kbn-ebt-tools @elastic/kibana-core
packages/kbn-ecs @elastic/kibana-core @elastic/security-threat-hunting-investigations
x-pack/packages/kbn-elastic-assistant @elastic/security-solution
x-pack/packages/security-solution/ecs_data_quality_dashboard @elastic/security-threat-hunting-investigations
x-pack/plugins/ecs_data_quality_dashboard @elastic/security-threat-hunting-investigations
test/plugin_functional/plugins/elasticsearch_client_plugin @elastic/kibana-core
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@
"@kbn/ecs": "link:packages/kbn-ecs",
"@kbn/ecs-data-quality-dashboard": "link:x-pack/packages/security-solution/ecs_data_quality_dashboard",
"@kbn/ecs-data-quality-dashboard-plugin": "link:x-pack/plugins/ecs_data_quality_dashboard",
"@kbn/elastic-assistant": "link:x-pack/packages/kbn-elastic-assistant",
"@kbn/elasticsearch-client-plugin": "link:test/plugin_functional/plugins/elasticsearch_client_plugin",
"@kbn/elasticsearch-client-xpack-plugin": "link:x-pack/test/plugin_api_integration/plugins/elasticsearch_client",
"@kbn/embeddable-enhanced-plugin": "link:x-pack/plugins/embeddable_enhanced",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-babel-preset/styled_components_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
/src[\/\\]plugins[\/\\](kibana_react)[\/\\]/,
/x-pack[\/\\]plugins[\/\\](apm|beats_management|cases|fleet|infra|lists|observability|observability_shared|exploratory_view|osquery|security_solution|timelines|synthetics|ux)[\/\\]/,
/x-pack[\/\\]test[\/\\]plugin_functional[\/\\]plugins[\/\\]resolver_test[\/\\]/,
/x-pack[\/\\]packages[\/\\]elastic_assistant[\/\\]/,
/x-pack[\/\\]packages[\/\\]security-solution[\/\\]ecs_data_quality_dashboard[\/\\]/,
],
};
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@
"@kbn/ecs-data-quality-dashboard/*": ["x-pack/packages/security-solution/ecs_data_quality_dashboard/*"],
"@kbn/ecs-data-quality-dashboard-plugin": ["x-pack/plugins/ecs_data_quality_dashboard"],
"@kbn/ecs-data-quality-dashboard-plugin/*": ["x-pack/plugins/ecs_data_quality_dashboard/*"],
"@kbn/elastic-assistant": ["x-pack/packages/kbn-elastic-assistant"],
"@kbn/elastic-assistant/*": ["x-pack/packages/kbn-elastic-assistant/*"],
"@kbn/elasticsearch-client-plugin": ["test/plugin_functional/plugins/elasticsearch_client_plugin"],
"@kbn/elasticsearch-client-plugin/*": ["test/plugin_functional/plugins/elasticsearch_client_plugin/*"],
"@kbn/elasticsearch-client-xpack-plugin": ["x-pack/test/plugin_api_integration/plugins/elasticsearch_client"],
Expand Down
20 changes: 20 additions & 0 deletions x-pack/packages/kbn-elastic-assistant/README.md
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
```
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.
*/

import React from 'react';
import { render } from '@testing-library/react';

import { HelloWorld } from '.';

describe('HelloWorld', () => {
it('renders the hello world text', () => {
const { getByTestId } = render(<HelloWorld />);
const helloWorldText = getByTestId('helloWorld');

expect(helloWorldText).toBeInTheDocument();
});
});
18 changes: 18 additions & 0 deletions x-pack/packages/kbn-elastic-assistant/impl/hello_world/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 * as i18n from './translations';

const HelloWorldComponent: React.FC = () => (
<div data-test-subj="helloWorld">{i18n.HELLO_WORLD}</div>
);

HelloWorldComponent.displayName = 'HelloWorldComponent';

export const HelloWorld = React.memo(HelloWorldComponent);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 HELLO_WORLD = i18n.translate('packages.elasticAssistant.helloWorld.helloWorld', {
defaultMessage: 'Hello world',
});
8 changes: 8 additions & 0 deletions x-pack/packages/kbn-elastic-assistant/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 { HelloWorld } from './impl/hello_world';
23 changes: 23 additions & 0 deletions x-pack/packages/kbn-elastic-assistant/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/

module.exports = {
coverageDirectory:
'<rootDir>/target/kibana-coverage/jest/x-pack/packages/kbn_elastic_assistant_impl',
coverageReporters: ['text', 'html'],
collectCoverageFrom: [
'<rootDir>/x-pack/packages/kbn-elastic-assistant/impl/**/*.{ts,tsx}',
'!<rootDir>/x-pack/packages/kbn-elastic-assistant/impl/{__test__,__snapshots__,__examples__,*mock*,tests,test_helpers,integration_tests,types}/**/*',
'!<rootDir>/x-pack/packages/kbn-elastic-assistant/impl/*mock*.{ts,tsx}',
'!<rootDir>/x-pack/packages/kbn-elastic-assistant/impl/*.test.{ts,tsx}',
'!<rootDir>/x-pack/packages/kbn-elastic-assistant/impl/*.d.ts',
'!<rootDir>/x-pack/packages/kbn-elastic-assistant/impl/*.config.ts',
],
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/packages/kbn-elastic-assistant'],
};
5 changes: 5 additions & 0 deletions x-pack/packages/kbn-elastic-assistant/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "@kbn/elastic-assistant",
"owner": "@elastic/security-solution",
"type": "shared-browser"
}
6 changes: 6 additions & 0 deletions x-pack/packages/kbn-elastic-assistant/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/elastic-assistant",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}
9 changes: 9 additions & 0 deletions x-pack/packages/kbn-elastic-assistant/setup_tests.ts
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.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import '@testing-library/jest-dom';
25 changes: 25 additions & 0 deletions x-pack/packages/kbn-elastic-assistant/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/i18n",
"@kbn/i18n-react",
"@kbn/ui-theme",
"@kbn/core-http-browser",
"@kbn/core-http-browser-mocks",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { HelloWorld } from '@kbn/elastic-assistant';
import { isEmpty } from 'lodash/fp';
import {
EuiButtonIcon,
Expand Down Expand Up @@ -148,9 +149,14 @@ export const ExpandableEventTitle = React.memo<ExpandableEventTitleProps>(
<EuiFlexItem grow={false}>
<EuiFlexGroup alignItems="center" direction="row" gutterSize="none">
{promptContextId != null && (
<EuiFlexItem grow={false}>
<NewChat promptContextId={promptContextId} />
</EuiFlexItem>
<>
<EuiFlexItem grow={false}>
<HelloWorld />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<NewChat promptContextId={promptContextId} />
</EuiFlexItem>
</>
)}
{isAlert && alertDetailsLink && (
<EuiFlexItem grow={false}>
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/security_solution/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@kbn/kibana-react-plugin",
"@kbn/core-chrome-browser",
"@kbn/ecs-data-quality-dashboard",
"@kbn/elastic-assistant",
"@kbn/data-views-plugin",
"@kbn/datemath",
"@kbn/ui-theme",
Expand Down
11 changes: 5 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4014,6 +4014,10 @@
version "0.0.0"
uid ""

"@kbn/elastic-assistant@link:x-pack/packages/kbn-elastic-assistant":
version "0.0.0"
uid ""

"@kbn/elasticsearch-client-plugin@link:test/plugin_functional/plugins/elasticsearch_client_plugin":
version "0.0.0"
uid ""
Expand Down Expand Up @@ -29588,12 +29592,7 @@ write-file-atomic@^4.0.1:
imurmurhash "^0.1.4"
signal-exit "^3.0.7"

[email protected]:
version "8.13.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==

ws@>=8.13.0:
[email protected], ws@>=8.13.0:
version "8.13.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==
Expand Down

0 comments on commit f8577a0

Please sign in to comment.