Skip to content

Commit

Permalink
[9.0] [Security Solution] [AI Assistant] Update copy of the citations…
Browse files Browse the repository at this point in the history
… tour. (#210398) (#212018)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Security Solution] [AI Assistant] Update copy of the citations tour.
(#210398)](#210398)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Kenneth
Kreindler","email":"42113355+KDKHD@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-02-21T09:03:53Z","message":"[Security
Solution] [AI Assistant] Update copy of the citations tour.
(#210398)\n\n##
Summary\n\nAddresses\nhttps://github.com/elastic/security-docs/issues/6485#issuecomment-2639562221\n\nThis
PR updates the copy in the Citations and Anonymized values
tour\naccording to the figma linked in the issue. Furthermore, the PR
includes\nthe logic that disables the \"Show anonymized values\" and
\"Show\ncitations\" buttons in the assistant settings menu when the
conversation\ndoes not contain anonymized values or citations
respectivly.\n\n### How to test new copy is correct\n<img width=\"864\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/22bd2671-6d06-4e68-85f5-3c10d9974a4a\"\n/>\n\n\n-
Enable feature flag\n```yaml\n#
kibana.dev.yml\nxpack.securitySolution.enableExperimental:
['contentReferencesEnabled']\n```\n- Clear the
key\n`elasticAssistant.anonymizedValuesAndCitationsTourCompleted.v8.18`
from\nyour local storage if it exists.\n- Open Security assistant\n- Ask
the assistant a question about your alerts or a KB document,
the\nresponse should contain anonymized values or a citation.\n- The
tour with the new copy should appear (copy in screenshot above).\n*the
Anonymized values and citations will not appear if the knowledge\nbase
tour is currently open.\n\n### How to test assistant settings menu
changes:\n<img width=\"349\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/58e445d7-79c0-46ca-a245-bc2ab90eeb5d\"\n/>\n\n-
Enable feature flag\n```yaml\n#
kibana.dev.yml\nxpack.securitySolution.enableExperimental:
['contentReferencesEnabled']\n```\n- Open Security assistant\n- In a new
conversation, inside the settings menu, the \"Show anonymized\nvalues\"
and \"Show citations\" menu items should be disabled because
the\nconversation is empty and does not contain citations or
anonymized\nvalues.\n- Ask the assistant a question about a KB document
or Alert. The \"Show\ncitations\" menu item should become available if
the response contains\ncitations. The \"Show anonymized values\" menu
item will become available\nif the conversation contains replacements.
Hovering over the disabled\nmenu item will make a tooltip appear
explaining why it is disabled.\n*Sometimes the conversation will contain
replacements but the\nreplacements are not used in the messages. In that
case, the anonymized\nvalues menu item will not be disabled. This is a
known\n[issue](https://github.com/elastic/kibana/issues/208517).\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [X] Any text
added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[X]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [X] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [X] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[X] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [X] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [X] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"b59712fa8cc5709cb36da6914c61823411b6c1fe","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Security
Generative
AI","backport:version","v8.18.0","v9.1.0","v8.19.0"],"title":"[Security
Solution] [AI Assistant] Update copy of the citations
tour.","number":210398,"url":"https://github.com/elastic/kibana/pull/210398","mergeCommit":{"message":"[Security
Solution] [AI Assistant] Update copy of the citations tour.
(#210398)\n\n##
Summary\n\nAddresses\nhttps://github.com/elastic/security-docs/issues/6485#issuecomment-2639562221\n\nThis
PR updates the copy in the Citations and Anonymized values
tour\naccording to the figma linked in the issue. Furthermore, the PR
includes\nthe logic that disables the \"Show anonymized values\" and
\"Show\ncitations\" buttons in the assistant settings menu when the
conversation\ndoes not contain anonymized values or citations
respectivly.\n\n### How to test new copy is correct\n<img width=\"864\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/22bd2671-6d06-4e68-85f5-3c10d9974a4a\"\n/>\n\n\n-
Enable feature flag\n```yaml\n#
kibana.dev.yml\nxpack.securitySolution.enableExperimental:
['contentReferencesEnabled']\n```\n- Clear the
key\n`elasticAssistant.anonymizedValuesAndCitationsTourCompleted.v8.18`
from\nyour local storage if it exists.\n- Open Security assistant\n- Ask
the assistant a question about your alerts or a KB document,
the\nresponse should contain anonymized values or a citation.\n- The
tour with the new copy should appear (copy in screenshot above).\n*the
Anonymized values and citations will not appear if the knowledge\nbase
tour is currently open.\n\n### How to test assistant settings menu
changes:\n<img width=\"349\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/58e445d7-79c0-46ca-a245-bc2ab90eeb5d\"\n/>\n\n-
Enable feature flag\n```yaml\n#
kibana.dev.yml\nxpack.securitySolution.enableExperimental:
['contentReferencesEnabled']\n```\n- Open Security assistant\n- In a new
conversation, inside the settings menu, the \"Show anonymized\nvalues\"
and \"Show citations\" menu items should be disabled because
the\nconversation is empty and does not contain citations or
anonymized\nvalues.\n- Ask the assistant a question about a KB document
or Alert. The \"Show\ncitations\" menu item should become available if
the response contains\ncitations. The \"Show anonymized values\" menu
item will become available\nif the conversation contains replacements.
Hovering over the disabled\nmenu item will make a tooltip appear
explaining why it is disabled.\n*Sometimes the conversation will contain
replacements but the\nreplacements are not used in the messages. In that
case, the anonymized\nvalues menu item will not be disabled. This is a
known\n[issue](https://github.com/elastic/kibana/issues/208517).\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [X] Any text
added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[X]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [X] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [X] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[X] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [X] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [X] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"b59712fa8cc5709cb36da6914c61823411b6c1fe"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210398","number":210398,"mergeCommit":{"message":"[Security
Solution] [AI Assistant] Update copy of the citations tour.
(#210398)\n\n##
Summary\n\nAddresses\nhttps://github.com/elastic/security-docs/issues/6485#issuecomment-2639562221\n\nThis
PR updates the copy in the Citations and Anonymized values
tour\naccording to the figma linked in the issue. Furthermore, the PR
includes\nthe logic that disables the \"Show anonymized values\" and
\"Show\ncitations\" buttons in the assistant settings menu when the
conversation\ndoes not contain anonymized values or citations
respectivly.\n\n### How to test new copy is correct\n<img width=\"864\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/22bd2671-6d06-4e68-85f5-3c10d9974a4a\"\n/>\n\n\n-
Enable feature flag\n```yaml\n#
kibana.dev.yml\nxpack.securitySolution.enableExperimental:
['contentReferencesEnabled']\n```\n- Clear the
key\n`elasticAssistant.anonymizedValuesAndCitationsTourCompleted.v8.18`
from\nyour local storage if it exists.\n- Open Security assistant\n- Ask
the assistant a question about your alerts or a KB document,
the\nresponse should contain anonymized values or a citation.\n- The
tour with the new copy should appear (copy in screenshot above).\n*the
Anonymized values and citations will not appear if the knowledge\nbase
tour is currently open.\n\n### How to test assistant settings menu
changes:\n<img width=\"349\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/58e445d7-79c0-46ca-a245-bc2ab90eeb5d\"\n/>\n\n-
Enable feature flag\n```yaml\n#
kibana.dev.yml\nxpack.securitySolution.enableExperimental:
['contentReferencesEnabled']\n```\n- Open Security assistant\n- In a new
conversation, inside the settings menu, the \"Show anonymized\nvalues\"
and \"Show citations\" menu items should be disabled because
the\nconversation is empty and does not contain citations or
anonymized\nvalues.\n- Ask the assistant a question about a KB document
or Alert. The \"Show\ncitations\" menu item should become available if
the response contains\ncitations. The \"Show anonymized values\" menu
item will become available\nif the conversation contains replacements.
Hovering over the disabled\nmenu item will make a tooltip appear
explaining why it is disabled.\n*Sometimes the conversation will contain
replacements but the\nreplacements are not used in the messages. In that
case, the anonymized\nvalues menu item will not be disabled. This is a
known\n[issue](https://github.com/elastic/kibana/issues/208517).\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [X] Any text
added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[X]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [X] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [X] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[X] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [X] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [X] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"b59712fa8cc5709cb36da6914c61823411b6c1fe"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kenneth Kreindler <42113355+KDKHD@users.noreply.github.com>
  • Loading branch information
kibanamachine and KDKHD authored Feb 21, 2025
1 parent e980fee commit 225dced
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
*/

import { HttpSetup } from '@kbn/core/public';
import { API_VERSIONS, ApiConfig, Replacements } from '@kbn/elastic-assistant-common';
import {
API_VERSIONS,
ApiConfig,
MessageMetadata,
Replacements,
} from '@kbn/elastic-assistant-common';
import { API_ERROR } from '../translations';
import { getOptionalRequestParams } from '../helpers';
import { TraceOptions } from '../types';
Expand Down Expand Up @@ -34,6 +39,7 @@ export interface FetchConnectorExecuteResponse {
transactionId: string;
traceId: string;
};
metadata?: MessageMetadata;
}

export const fetchConnectorExecuteAction = async ({
Expand Down Expand Up @@ -110,6 +116,7 @@ export const fetchConnectorExecuteAction = async ({
transaction_id: string;
trace_id: string;
};
metadata?: MessageMetadata;
}>(`/internal/elastic_assistant/actions/connector/${apiConfig?.connectorId}/_execute`, {
method: 'POST',
body: JSON.stringify(requestBody),
Expand Down Expand Up @@ -144,6 +151,7 @@ export const fetchConnectorExecuteAction = async ({

return {
response: response.data,
metadata: response.metadata,
isError: false,
isStream: false,
traceData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ export const AssistantHeader: React.FC<Props> = ({
/>
</EuiFlexItem>
<EuiFlexItem id={AI_ASSISTANT_SETTINGS_MENU_CONTAINER_ID}>
<SettingsContextMenu isDisabled={isDisabled} onChatCleared={onChatCleared} />
<SettingsContextMenu
isDisabled={isDisabled}
onChatCleared={onChatCleared}
selectedConversation={selectedConversation}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,6 @@ export const CHAT_OPTIONS = i18n.translate(
}
);

const isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0;

export const ANONYMIZE_VALUES_TOOLTIP = i18n.translate(
'xpack.elasticAssistant.assistant.settings.anonymizeValues.tooltip',
{
values: { keyboardShortcut: isMac ? '⌥ + a' : 'Alt + a' },
defaultMessage:
'Toggle to reveal or hide field values in your chat stream. The data sent to the LLM is still anonymized based on settings in the Anonymization panel. Keyboard shortcut: {keyboardShortcut}',
}
);

export const SHOW_CITATIONS_TOOLTIP = i18n.translate(
'xpack.elasticAssistant.assistant.settings.showCitationsLabel.tooltip',
{
values: { keyboardShortcut: isMac ? '⌥ + c' : 'Alt + c' },
defaultMessage: 'Keyboard shortcut: {keyboardShortcut}',
}
);

export const CANCEL_BUTTON_TEXT = i18n.translate(
'xpack.elasticAssistant.assistant.resetConversationModal.cancelButtonText',
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 { alertConvo, conversationWithContentReferences } from '../../../mock/conversation';
import { Conversation } from '../../../..';
import { conversationContainsContentReferences, conversationContainsAnonymizedValues } from '.';

describe('conversation utils', () => {
it.each([
[undefined, false],
[conversationWithContentReferences, true],
[alertConvo, false],
])(
'conversationContainsContentReferences',
(conversation: Conversation | undefined, expected: boolean) => {
expect(conversationContainsContentReferences(conversation)).toBe(expected);
}
);

it.each([
[undefined, false],
[conversationWithContentReferences, false],
[alertConvo, true],
])(
'conversationContainsAnonymizedValues',
(conversation: Conversation | undefined, expected: boolean) => {
expect(conversationContainsAnonymizedValues(conversation)).toBe(expected);
}
);
});
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 { isEmpty } from 'lodash';
import { Conversation } from '../../../..';

export const conversationContainsContentReferences = (conversation?: Conversation): boolean => {
return (
conversation?.messages.some((message) => !isEmpty(message.metadata?.contentReferences)) ?? false
);
};

/** Checks if the conversations has replacements, not if the replacements are actually used */
export const conversationContainsAnonymizedValues = (conversation?: Conversation): boolean => {
return !isEmpty(conversation?.replacements);
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const getMessageFromRawResponse = (
timestamp: dateTimeString,
isError,
traceData: rawResponse.traceData,
metadata: rawResponse.metadata,
};
} else {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ import { ConversationSidePanel } from './conversations/conversation_sidepanel';
import { SelectedPromptContexts } from './prompt_editor/selected_prompt_contexts';
import { AssistantHeader } from './assistant_header';
import { AnonymizedValuesAndCitationsTour } from '../tour/anonymized_values_and_citations_tour';
import {
conversationContainsAnonymizedValues,
conversationContainsContentReferences,
} from './conversations/utils';

export const CONVERSATION_SIDE_PANEL_WIDTH = 220;

Expand Down Expand Up @@ -227,10 +231,12 @@ const AssistantComponent: React.FC<Props> = ({
const onKeyDown = useCallback(
(event: KeyboardEvent) => {
if (event.altKey && event.code === 'KeyC') {
if (!conversationContainsContentReferences(currentConversation)) return;
event.preventDefault();
setContentReferencesVisible(!contentReferencesVisible);
}
if (event.altKey && event.code === 'KeyA') {
if (!conversationContainsAnonymizedValues(currentConversation)) return;
event.preventDefault();
setShowAnonymizedValues(!showAnonymizedValues);
}
Expand All @@ -240,6 +246,7 @@ const AssistantComponent: React.FC<Props> = ({
contentReferencesVisible,
setShowAnonymizedValues,
showAnonymizedValues,
currentConversation,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,42 @@ import {
EuiHorizontalRule,
EuiToolTip,
EuiSwitchEvent,
EuiIcon,
} from '@elastic/eui';
import { css } from '@emotion/react';
import { FormattedMessage } from '@kbn/i18n-react';
import { KnowledgeBaseTour } from '../../../tour/knowledge_base';
import { AnonymizationSettingsManagement } from '../../../data_anonymization/settings/anonymization_settings_management';
import { useAssistantContext } from '../../../..';
import { Conversation, useAssistantContext } from '../../../..';
import * as i18n from '../../assistant_header/translations';
import { AlertsSettingsModal } from '../alerts_settings/alerts_settings_modal';
import { KNOWLEDGE_BASE_TAB } from '../const';
import { AI_ASSISTANT_MENU } from './translations';
import {
conversationContainsAnonymizedValues,
conversationContainsContentReferences,
} from '../../conversations/utils';

interface Params {
isDisabled?: boolean;
onChatCleared?: () => void;
selectedConversation?: Conversation;
}

const isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0;

const ConditionalWrap = ({
condition,
wrap,
children,
}: {
condition: boolean;
wrap: (children: React.ReactElement) => React.ReactElement;
children: React.ReactElement;
}) => (condition ? wrap(children) : children);

export const SettingsContextMenu: React.FC<Params> = React.memo(
({ isDisabled = false, onChatCleared }: Params) => {
({ isDisabled = false, onChatCleared, selectedConversation }: Params) => {
const { euiTheme } = useEuiTheme();
const {
navigateToApp,
Expand Down Expand Up @@ -117,6 +136,16 @@ export const SettingsContextMenu: React.FC<Params> = React.memo(
[setShowAnonymizedValues]
);

const selectedConversationHasCitations = useMemo(
() => conversationContainsContentReferences(selectedConversation),
[selectedConversation]
);

const selectedConversationHasAnonymizedValues = useMemo(
() => conversationContainsAnonymizedValues(selectedConversation),
[selectedConversation]
);

const items = useMemo(
() => [
<EuiContextMenuItem
Expand Down Expand Up @@ -174,43 +203,114 @@ export const SettingsContextMenu: React.FC<Params> = React.memo(
<h3>{i18n.CHAT_OPTIONS}</h3>
</EuiTitle>
<EuiHorizontalRule margin="none" />
<EuiToolTip
position="left"
key={'anonymize-values-tooltip'}
content={i18n.ANONYMIZE_VALUES_TOOLTIP}
<EuiContextMenuItem
aria-label={'anonymize-values'}
key={'anonymize-values'}
data-test-subj={'anonymize-values'}
>
<EuiFlexGroup direction="row" gutterSize="s" alignItems="center">
<EuiFlexItem grow={false}>
<ConditionalWrap
condition={!selectedConversationHasAnonymizedValues}
wrap={(children) => (
<EuiToolTip
position="top"
key={'disabled-anonymize-values-tooltip'}
content={
<FormattedMessage
id="xpack.elasticAssistant.assistant.settings.anonymizeValues.disabled.tooltip"
defaultMessage="This conversation does not contain anonymized fields."
/>
}
>
{children}
</EuiToolTip>
)}
>
<EuiSwitch
label={i18n.ANONYMIZE_VALUES}
checked={showAnonymizedValues}
onChange={onChangeShowAnonymizedValues}
compressed
disabled={!selectedConversationHasAnonymizedValues}
/>
</ConditionalWrap>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiToolTip
position="top"
key={'anonymize-values-tooltip'}
content={
<FormattedMessage
id="xpack.elasticAssistant.assistant.settings.anonymizeValues.tooltip"
defaultMessage="Toggle to reveal or obfuscate field values in your chat stream. The data sent to the LLM is still anonymized based on settings in the Anonymization panel. Keyboard shortcut: <bold>{keyboardShortcut}</bold>"
values={{
keyboardShortcut: isMac ? '⌥ + a' : 'Alt + a',
bold: (str) => <strong>{str}</strong>,
}}
/>
}
>
<EuiIcon tabIndex={0} type="iInCircle" />
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
</EuiContextMenuItem>

{contentReferencesEnabled && (
<EuiContextMenuItem
aria-label={'anonymize-values'}
key={'anonymize-values'}
data-test-subj={'anonymize-values'}
aria-label={'show-citations'}
key={'show-citations'}
data-test-subj={'show-citations'}
>
<EuiSwitch
label={i18n.ANONYMIZE_VALUES}
checked={showAnonymizedValues}
onChange={onChangeShowAnonymizedValues}
compressed
/>
<EuiFlexGroup direction="row" gutterSize="s" alignItems="center">
<EuiFlexItem grow={false}>
<ConditionalWrap
condition={!selectedConversationHasCitations}
wrap={(children) => (
<EuiToolTip
position="top"
key={'disabled-anonymize-values-tooltip'}
content={
<FormattedMessage
id="xpack.elasticAssistant.assistant.settings.showCitationsLabel.disabled.tooltip"
defaultMessage="This conversation does not contain citations."
/>
}
>
{children}
</EuiToolTip>
)}
>
<EuiSwitch
label={i18n.SHOW_CITATIONS}
checked={contentReferencesVisible}
onChange={onChangeContentReferencesVisible}
compressed
disabled={!selectedConversationHasCitations}
/>
</ConditionalWrap>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiToolTip
position="top"
key={'show-citations-tooltip'}
content={
<FormattedMessage
id="xpack.elasticAssistant.assistant.settings.showCitationsLabel.tooltip"
defaultMessage="Keyboard shortcut: <bold>{keyboardShortcut}</bold>"
values={{
keyboardShortcut: isMac ? '⌥ + c' : 'Alt + c',
bold: (str) => <strong>{str}</strong>,
}}
/>
}
>
<EuiIcon tabIndex={0} type="iInCircle" />
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
</EuiContextMenuItem>
</EuiToolTip>
{contentReferencesEnabled && (
<EuiToolTip
position="left"
key={'show-citations-tooltip'}
content={i18n.SHOW_CITATIONS_TOOLTIP}
>
<EuiContextMenuItem
aria-label={'show-citations'}
key={'show-citations'}
data-test-subj={'show-citations'}
>
<EuiSwitch
label={i18n.SHOW_CITATIONS}
checked={contentReferencesVisible}
onChange={onChangeContentReferencesVisible}
compressed
/>
</EuiContextMenuItem>
</EuiToolTip>
)}
<EuiHorizontalRule margin="none" />
<EuiContextMenuItem
Expand Down Expand Up @@ -242,6 +342,8 @@ export const SettingsContextMenu: React.FC<Params> = React.memo(
contentReferencesEnabled,
euiTheme.size.m,
euiTheme.size.xs,
selectedConversationHasCitations,
selectedConversationHasAnonymizedValues,
]
);

Expand Down
Loading

0 comments on commit 225dced

Please # to comment.