-
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
[Observability AI Assistant] Create first Starter prompts #178907
Changes from 17 commits
675ac0f
482d705
a3d91ee
7567cf7
aa8a7ed
7f0fcdc
7643392
492707a
3afa675
6b4ea31
a6d081a
cdd6175
3ac8172
819ff0c
9a60c35
37e89df
e9a102b
d2200a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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 { useEffect } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import type { NoDataConfig } from '@kbn/shared-ux-page-kibana-template'; | ||
import type { ApmPluginStartDeps } from '../plugin'; | ||
|
||
export function useDefaultAiAssistantStarterPromptsForAPM({ | ||
hasApmData, | ||
hasApmIntegrations, | ||
noDataConfig, | ||
}: { | ||
hasApmData: boolean; | ||
hasApmIntegrations: boolean; | ||
noDataConfig?: NoDataConfig; | ||
}) { | ||
const { observabilityAIAssistant } = useKibana<ApmPluginStartDeps>().services; | ||
|
||
let screenDescription = ''; | ||
|
||
if (!hasApmData && !hasApmIntegrations) { | ||
screenDescription = | ||
'The user does not have the APM integration installed and does not have APM data.'; | ||
} else { | ||
screenDescription = hasApmData | ||
? 'The user has APM data.' | ||
: 'The user does not have APM data.'; | ||
screenDescription = hasApmIntegrations | ||
? `${screenDescription} The user has the APM integration installed.` | ||
: `${screenDescription} The user does not have the APM integration installed.`; | ||
} | ||
|
||
if (noDataConfig !== undefined) { | ||
screenDescription = `${screenDescription} The user is looking at a screen that tells them they do not have any data.`; | ||
} | ||
|
||
useEffect(() => { | ||
return observabilityAIAssistant?.service.setScreenContext({ | ||
screenDescription, | ||
starterPrompts: [ | ||
...(hasApmData | ||
? [] | ||
: [ | ||
{ | ||
title: i18n.translate( | ||
'xpack.apm.aiAssistant.starterPrompts.explainNoData.title', | ||
{ defaultMessage: 'Explain' } | ||
), | ||
prompt: i18n.translate( | ||
'xpack.apm.aiAssistant.starterPrompts.explainNoData.prompt', | ||
{ defaultMessage: "Why don't I see any data?" } | ||
), | ||
icon: 'sparkles', | ||
}, | ||
]), | ||
], | ||
}); | ||
}, [ | ||
hasApmData, | ||
hasApmIntegrations, | ||
noDataConfig, | ||
screenDescription, | ||
observabilityAIAssistant?.service, | ||
]); | ||
} |
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 { useLoadRuleTypesQuery } from '@kbn/triggers-actions-ui-plugin/public'; | ||
import { useMemo } from 'react'; | ||
import { useKibana } from '../utils/kibana_react'; | ||
import { useGetFilteredRuleTypes } from './use_get_filtered_rule_types'; | ||
|
||
export function useGetAvailableRulesWithDescriptions() { | ||
const filteredRuleTypes = useGetFilteredRuleTypes(); | ||
|
||
const { | ||
triggersActionsUi: { ruleTypeRegistry }, | ||
} = useKibana().services; | ||
|
||
const { | ||
ruleTypesState: { data: ruleTypes }, | ||
} = useLoadRuleTypesQuery({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
filteredRuleTypes, | ||
}); | ||
|
||
return useMemo(() => { | ||
const ruleTypesFromRuleTypeRegistry = ruleTypeRegistry.list(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return Array.from(ruleTypes).map(([id, rule]) => { | ||
return { | ||
id, | ||
name: rule.name, | ||
description: ruleTypesFromRuleTypeRegistry.find((f) => f.id === id)?.description || '', | ||
}; | ||
}); | ||
}, [ruleTypeRegistry, ruleTypes]); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ import { getAlertSummaryTimeRange } from '../../utils/alert_summary_widget'; | |
import { observabilityAlertFeatureIds } from '../../../common/constants'; | ||
import { ALERTS_URL_STORAGE_KEY } from '../../../common/constants'; | ||
import { HeaderMenu } from '../overview/components/header_menu/header_menu'; | ||
import { useGetAvailableRulesWithDescriptions } from '../../hooks/use_get_available_rules_with_descriptions'; | ||
|
||
const ALERTS_SEARCH_BAR_ID = 'alerts-search-bar-o11y'; | ||
const ALERTS_PER_PAGE = 50; | ||
|
@@ -54,6 +55,7 @@ function InternalAlertsPage() { | |
}, | ||
http, | ||
notifications: { toasts }, | ||
observabilityAIAssistant, | ||
share: { | ||
url: { locators }, | ||
}, | ||
|
@@ -72,6 +74,31 @@ function InternalAlertsPage() { | |
|
||
const filteredRuleTypes = useGetFilteredRuleTypes(); | ||
|
||
const { setScreenContext } = observabilityAIAssistant?.service || {}; | ||
|
||
const ruleTypesWithDescriptions = useGetAvailableRulesWithDescriptions(); | ||
|
||
useEffect(() => { | ||
return setScreenContext?.({ | ||
data: ruleTypesWithDescriptions.map((rule) => ({ | ||
name: rule.id, | ||
value: `${rule.name} ${rule.description}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use |
||
description: `An available rule is ${rule.name}.`, | ||
})), | ||
starterPrompts: [ | ||
{ | ||
title: i18n.translate('xpack.observability.app.starterPrompts.explainRules.title', { | ||
defaultMessage: 'Explain', | ||
}), | ||
prompt: i18n.translate('xpack.observability.app.starterPrompts.explainRules.prompt', { | ||
defaultMessage: `Can you explain the rule types that are available?`, | ||
}), | ||
icon: 'sparkles', | ||
}, | ||
], | ||
}); | ||
}, [filteredRuleTypes, ruleTypesWithDescriptions, setScreenContext]); | ||
|
||
const onBrushEnd: BrushEndListener = (brushEvent) => { | ||
const { x } = brushEvent as XYBrushEvent; | ||
if (x) { | ||
|
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.
useGetFilteredRuleTypes();
only returnsid
s, noname
ordescription