Skip to content

Commit

Permalink
[AI Assistant] Set scope and rename to Observability and Search (elas…
Browse files Browse the repository at this point in the history
…tic#196322)

## Summary

This renames the Observability AI Assistant in some places to AI
Assistant for Observability and Search. It also makes the scope
multi-valued on both sides.

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit 26ec293)
  • Loading branch information
sphilipse committed Oct 24, 2024
1 parent 407d794 commit 1c50205
Show file tree
Hide file tree
Showing 74 changed files with 523 additions and 518 deletions.
2 changes: 1 addition & 1 deletion docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ Elastic.
|{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/observability_ai_assistant_management/README.md[observabilityAiAssistantManagement]
|The observabilityAiAssistantManagement plugin manages the Ai Assistant for Observability management section.
|The observabilityAiAssistantManagement plugin manages the Ai Assistant for Observability and Search management section.
|{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/observability_logs_explorer/README.md[observabilityLogsExplorer]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function AiAssistantSelectionPage() {
isDisabled={!observabilityAIAssistantEnabled}
title={i18n.translate(
'aiAssistantManagementSelection.aiAssistantSelectionPage.observabilityLabel',
{ defaultMessage: 'Elastic AI Assistant for Observability' }
{ defaultMessage: 'Elastic AI Assistant for Observability and Search' }
)}
titleSize="xs"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ export class AIAssistantManagementSelectionPlugin
core.uiSettings.register({
[PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY]: {
name: i18n.translate('aiAssistantManagementSelection.preferredAIAssistantTypeSettingName', {
defaultMessage: 'Observability AI Assistant scope',
defaultMessage: 'AI Assistant for Observability and Search visibility',
}),
category: [DEFAULT_APP_CATEGORIES.observability.id],
value: this.config.preferredAIAssistantType,
description: i18n.translate(
'aiAssistantManagementSelection.preferredAIAssistantTypeSettingDescription',
{
defaultMessage:
'<em>[technical preview]</em> Whether to show the Observability AI Assistant menu item in Observability, everywhere, or nowhere.',
'<em>[technical preview]</em> Whether to show the AI Assistant menu item in Observability and Search, everywhere, or nowhere.',
values: {
em: (chunks) => `<em>${chunks}</em>`,
},
Expand All @@ -77,7 +77,7 @@ export class AIAssistantManagementSelectionPlugin
optionLabels: {
[AIAssistantType.Default]: i18n.translate(
'aiAssistantManagementSelection.preferredAIAssistantTypeSettingValueDefault',
{ defaultMessage: 'Observability only (default)' }
{ defaultMessage: 'Observability and Search only (default)' }
),
[AIAssistantType.Observability]: i18n.translate(
'aiAssistantManagementSelection.preferredAIAssistantTypeSettingValueObservability',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

import type { AssistantScope } from '../types';

export function filterScopes<T extends { scopes?: AssistantScope[] }>(scope?: AssistantScope) {
export function filterScopes<T extends { scopes?: AssistantScope[] }>(
scopeFilters?: AssistantScope[]
) {
return function (value: T): boolean {
if (!scope || !value) {
if (!scopeFilters || !value) {
return true;
}
return value?.scopes ? value.scopes.includes(scope) || value.scopes.includes('all') : true;
return value?.scopes
? value.scopes.some((scope) => [...scopeFilters, 'all'].includes(scope))
: true;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { euiThemeVars } from '@kbn/ui-theme';
import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
import type { AssistantScope } from '@kbn/ai-assistant-common';
import { isEqual } from 'lodash';
import { useKibana } from '../hooks/use_kibana';
import { ConversationList, ChatBody, ChatInlineEditingContent } from '../chat';
import { useConversationKey } from '../hooks/use_conversation_key';
Expand All @@ -27,15 +28,15 @@ interface ConversationViewProps {
navigateToConversation: (nextConversationId?: string) => void;
getConversationHref?: (conversationId: string) => string;
newConversationHref?: string;
scope?: AssistantScope;
scopes?: AssistantScope[];
}

export const ConversationView: React.FC<ConversationViewProps> = ({
conversationId,
navigateToConversation,
getConversationHref,
newConversationHref,
scope,
scopes,
}) => {
const { euiTheme } = useEuiTheme();

Expand All @@ -61,10 +62,10 @@ export const ConversationView: React.FC<ConversationViewProps> = ({
);

useEffect(() => {
if (scope) {
service.setScope(scope);
if (scopes && !isEqual(scopes, service.getScopes())) {
service.setScopes(scopes);
}
}, [scope, service]);
}, [scopes, service]);

const { key: bodyKey, updateConversationIdInPlace } = useConversationKey(conversationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export function useConversation() {
stop: () => {},
messages: [],
saveTitle: () => {},
scope: 'all',
scopes: ['all'],
};
}
2 changes: 1 addition & 1 deletion x-pack/packages/kbn-ai-assistant/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
export * from './use_ai_assistant_app_service';
export * from './use_ai_assistant_chat_service';
export * from './use_knowledge_base';
export * from './use_scope';
export * from './use_scopes';
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const mockService: MockedService = {
predefinedConversation$: new Observable(),
},
navigate: jest.fn().mockReturnValue(of()),
scope$: new BehaviorSubject<AssistantScope>('all') as MockedService['scope$'],
setScope: jest.fn(),
getScope: jest.fn(),
scope$: new BehaviorSubject<AssistantScope[]>(['all']) as MockedService['scope$'],
setScopes: jest.fn(),
getScopes: jest.fn(),
};

const mockChatService = createMockChatService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useAIAssistantAppService } from './use_ai_assistant_app_service';
import { useKibana } from './use_kibana';
import { useOnce } from './use_once';
import { useAbortableAsync } from './use_abortable_async';
import { useScope } from './use_scope';
import { useScopes } from './use_scopes';

function createNewConversation({
title = EMPTY_CONVERSATION_TITLE,
Expand Down Expand Up @@ -62,7 +62,7 @@ export function useConversation({
onConversationUpdate,
}: UseConversationProps): UseConversationResult {
const service = useAIAssistantAppService();
const scope = useScope();
const scopes = useScopes();

const {
services: {
Expand Down Expand Up @@ -122,7 +122,7 @@ export function useConversation({
onConversationUpdate?.({ conversation: event.conversation });
},
persist: true,
scope,
scopes,
});

const [displayedConversationId, setDisplayedConversationId] = useState(initialConversationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import { useObservable } from 'react-use/lib';
import { useAIAssistantAppService } from './use_ai_assistant_app_service';

export const useScope = () => {
export const useScopes = () => {
const service = useAIAssistantAppService();
const scope = useObservable(service.scope$);
return scope || 'all';
const scopes = useObservable(service.scope$);
return scopes || ['all'];
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createMockChatService = (): MockedChatService => {
content: '',
},
}),
getScope: jest.fn(),
getScopes: jest.fn(),
};
return mockChatService;
};
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export function registerGetApmDatasetInfoFunction({
`,
},
};
},
['observability']
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function registerGetApmDownstreamDependenciesFunction({
randomSampler,
}),
};
},
['observability']
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export function registerGetApmServicesListFunction({
arguments: args,
}),
};
},
['observability']
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ export function registerGetApmTimeseriesFunction({
content: timeseries.map((series): Omit<ApmTimeseries, 'data'> => omit(series, 'data')),
data: timeseries,
};
},
['observability']
}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export function registerAssistantFunctions({
ruleDataClient: IRuleDataClient;
plugins: APMRouteHandlerResources['plugins'];
}): RegistrationCallback {
return async ({ resources, functions: { registerFunction } }) => {
return async ({ resources, functions: { registerFunction }, scopes }) => {
if (!scopes.includes('observability')) {
return;
}
const apmRouteHandlerResources: MinimalAPMRouteHandlerResources = {
context: resources.context,
request: resources.request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
import type { JSONSchema7TypeName } from 'json-schema';
import type { Observable } from 'rxjs';
import type { AssistantScope } from '@kbn/ai-assistant-common';
import { ChatCompletionChunkEvent, MessageAddEvent } from '../conversation_complete';
import { FunctionVisibility } from './function_visibility';
export { FunctionVisibility };
Expand Down Expand Up @@ -42,7 +41,6 @@ export interface FunctionDefinition<TParameters extends CompatibleJSONSchema = a
visibility?: FunctionVisibility;
descriptionForUser?: string;
parameters?: TParameters;
scopes?: AssistantScope[];
}

export type FunctionRegistry = Map<string, FunctionDefinition>;
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function ChatContent({
}) {
const service = useObservabilityAIAssistant();
const chatService = useObservabilityAIAssistantChatService();
const scope = chatService.getScope();
const scopes = chatService.getScopes();

const initialMessagesRef = useRef(initialMessages);

Expand All @@ -69,7 +69,7 @@ function ChatContent({
initialMessages,
persist: false,
disableFunctions: true,
scope,
scopes,
});

const lastAssistantResponse = getLastMessageOfType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const mockChatService: MockedChatService = {
role: MessageRole.System,
},
}),
getScope: jest.fn(),
getScopes: jest.fn(),
};

const addErrorMock = jest.fn();
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('useChat', () => {
service: {
getScreenContexts: () => [],
} as unknown as ObservabilityAIAssistantService,
scope: 'observability',
scopes: ['observability'],
} as UseChatProps,
});
});
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('useChat', () => {
service: {
getScreenContexts: () => [],
} as unknown as ObservabilityAIAssistantService,
scope: 'observability',
scopes: ['observability'],
} as UseChatProps,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface UseChatPropsWithoutContext {
disableFunctions?: boolean;
onConversationUpdate?: (event: ConversationCreateEvent | ConversationUpdateEvent) => void;
onChatComplete?: (messages: Message[]) => void;
scope: AssistantScope;
scopes: AssistantScope[];
}

export type UseChatProps = Omit<UseChatPropsWithoutContext, 'notifications'>;
Expand All @@ -72,7 +72,7 @@ function useChatWithoutContext({
onChatComplete,
persist,
disableFunctions,
scope,
scopes,
}: UseChatPropsWithoutContext): UseChatResult {
const [chatState, setChatState] = useState(ChatState.Ready);
const systemMessage = useMemo(() => {
Expand Down Expand Up @@ -165,7 +165,7 @@ function useChatWithoutContext({
disableFunctions: disableFunctions ?? false,
signal: abortControllerRef.current.signal,
conversationId,
scope,
scopes,
});

function getPendingMessages() {
Expand Down Expand Up @@ -264,7 +264,7 @@ function useChatWithoutContext({
disableFunctions,
service,
systemMessage,
scope,
scopes,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const mockChatService: ObservabilityAIAssistantChatService = {
content: 'System',
},
}),
getScope: jest.fn(),
getScopes: jest.fn(),
};

export const mockService: ObservabilityAIAssistantService = {
Expand All @@ -64,9 +64,9 @@ export const mockService: ObservabilityAIAssistantService = {
predefinedConversation$: new Observable(),
},
navigate: async () => of(),
setScope: jest.fn(),
getScope: jest.fn(),
scope$: new BehaviorSubject<AssistantScope>('all'),
setScopes: jest.fn(),
getScopes: jest.fn(),
scope$: new BehaviorSubject<AssistantScope[]>(['all']),
};

function createSetupContract(): ObservabilityAIAssistantPublicSetup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class ObservabilityAIAssistantPlugin
coreStart.application.capabilities.observabilityAIAssistant[
aiAssistantCapabilities.show
] === true,
scope: this.scopeFromConfig || 'observability',
scopes: this.scopeFromConfig ? [this.scopeFromConfig] : ['all'],
scopeIsMutable: !!this.scopeFromConfig,
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('complete', () => {
disableFunctions: false,
signal: new AbortController().signal,
...params,
scope: 'all',
scopes: ['all'],
},
requestCallback
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function complete(
disableFunctions,
signal,
instructions,
scope,
scopes,
}: {
client: Pick<ObservabilityAIAssistantChatService, 'chat' | 'complete'>;
getScreenContexts: () => ObservabilityAIAssistantScreenContext[];
Expand All @@ -66,7 +66,7 @@ export function complete(
screenContexts,
conversationId,
instructions,
scope,
scopes,
},
},
}).pipe(shareReplay());
Expand Down Expand Up @@ -133,7 +133,7 @@ export function complete(
persist,
disableFunctions,
instructions,
scope,
scopes,
},
requestCallback
).subscribe(subscriber);
Expand Down
Loading

0 comments on commit 1c50205

Please sign in to comment.