From 175b59bf9bce83232ecddf5ba30b4bc6944c1237 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Fri, 22 Mar 2024 10:17:13 -0700 Subject: [PATCH 01/41] [Security AI Assistant] Removed connectorTypeTitle from the Conversation API required params. Replaced usage replaced with actionsClient on server and API call on the client (#179117) Current PR is fixing bug mentioned [here](https://github.com/elastic/kibana/pull/179007/files#pullrequestreview-1947890025) and reducing `connectorTypeTitle`/`llmType` params for AI assistant APIs. Streaming is working as it was before: https://github.com/elastic/kibana/assets/55110838/ff7c2ae8-288f-4cba-bb43-e45367845667 --- ...ost_actions_connector_execute_route.gen.ts | 1 - ...ctions_connector_execute_route.schema.yaml | 6 ----- .../conversations/common_attributes.gen.ts | 4 ---- .../common_attributes.schema.yaml | 4 ---- .../use_bulk_actions_conversations.test.ts | 2 +- .../impl/assistant/api/index.test.tsx | 11 ++++----- .../impl/assistant/api/index.tsx | 4 +--- .../conversation_selector/index.tsx | 1 - .../conversation_settings.test.tsx | 4 ---- .../conversation_settings.tsx | 5 ---- .../impl/assistant/helpers.test.ts | 17 ++++++-------- .../impl/assistant/helpers.ts | 6 ----- .../impl/assistant/index.test.tsx | 6 ++--- .../impl/assistant/index.tsx | 2 -- .../system_prompt/index.test.tsx | 3 --- .../system_prompt_settings.tsx | 2 -- .../evaluation_settings.tsx | 2 +- .../use_conversation/helpers.test.ts | 11 ++++----- .../assistant/use_conversation/index.test.tsx | 2 -- .../connector_selector/index.test.tsx | 10 ++------ .../connector_selector/index.tsx | 12 ++++------ .../connector_selector_inline.test.tsx | 11 ++++----- .../connector_selector_inline.tsx | 4 +--- .../connectorland/connector_setup/index.tsx | 10 +++----- .../use_load_connectors/index.tsx | 23 ------------------- .../impl/mock/connectors.ts | 2 -- .../impl/mock/conversation.ts | 3 --- .../__mocks__/conversations_schema.mock.ts | 5 ---- .../server/__mocks__/response.ts | 1 - .../conversations/create_conversation.test.ts | 3 --- .../conversations/create_conversation.ts | 1 - .../conversations/field_maps_configuration.ts | 5 ---- .../conversations/get_conversation.test.ts | 2 -- .../conversations/helpers.ts | 3 --- .../conversations/index.test.ts | 3 --- .../conversations/transforms.ts | 1 - .../conversations/types.ts | 2 -- .../conversations/update_conversation.test.ts | 3 --- .../conversations/update_conversation.ts | 2 -- .../ai_assistant_data_clients/find.test.ts | 3 --- .../ai_assistant_data_clients/index.test.ts | 2 -- .../server/lib/executor.test.ts | 1 + .../elastic_assistant/server/lib/executor.ts | 4 +++- .../lib/langchain/llm/actions_client_llm.ts | 4 +--- .../server/lib/parse_stream.test.ts | 8 +++---- .../server/lib/parse_stream.ts | 2 +- .../server/routes/evaluate/post_evaluate.ts | 1 - .../post_actions_connector_execute.test.ts | 22 +++++++++++++++++- .../routes/post_actions_connector_execute.ts | 10 +++++++- .../user_conversations/update_route.test.ts | 1 - .../assistant/get_comments/index.test.tsx | 2 -- .../public/assistant/get_comments/index.tsx | 9 ++++---- .../get_comments/stream/index.test.tsx | 17 +++++++++++++- .../assistant/get_comments/stream/index.tsx | 10 +++++--- .../stream/stream_observable.test.ts | 10 ++++---- .../get_comments/stream/stream_observable.ts | 14 +++++------ .../get_comments/stream/use_stream.test.tsx | 2 +- .../get_comments/stream/use_stream.tsx | 8 +++---- .../public/assistant/provider.test.tsx | 3 --- .../tests/actions/connector_types/bedrock.ts | 1 - .../trial_license_complete_tier/basic.ts | 3 +-- 61 files changed, 123 insertions(+), 213 deletions(-) diff --git a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/actions_connector/post_actions_connector_execute_route.gen.ts b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/actions_connector/post_actions_connector_execute_route.gen.ts index d8af61a2e2d9c..8224d2e32686d 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/actions_connector/post_actions_connector_execute_route.gen.ts +++ b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/actions_connector/post_actions_connector_execute_route.gen.ts @@ -40,7 +40,6 @@ export const ExecuteConnectorRequestBody = z.object({ isEnabledRAGAlerts: z.boolean().optional(), replacements: z.array(Replacement), size: z.number().optional(), - llmType: z.enum(['bedrock', 'openai']), }); export type ExecuteConnectorRequestBodyInput = z.input; diff --git a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/actions_connector/post_actions_connector_execute_route.schema.yaml b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/actions_connector/post_actions_connector_execute_route.schema.yaml index 936d28ce62589..6e36d8e8c2d81 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/actions_connector/post_actions_connector_execute_route.schema.yaml +++ b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/actions_connector/post_actions_connector_execute_route.schema.yaml @@ -26,7 +26,6 @@ paths: type: object required: - params - - llmType - replacements - subAction properties: @@ -61,11 +60,6 @@ paths: $ref: '../conversations/common_attributes.schema.yaml#/components/schemas/Replacement' size: type: number - llmType: - type: string - enum: - - bedrock - - openai responses: '200': description: Successful response diff --git a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/common_attributes.gen.ts b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/common_attributes.gen.ts index b95d0f8918705..04bf99a88fd0d 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/common_attributes.gen.ts +++ b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/common_attributes.gen.ts @@ -145,10 +145,6 @@ export const ApiConfig = z.object({ * connector Id */ connectorId: z.string(), - /** - * connector Type Title - */ - connectorTypeTitle: z.string(), /** * defaultSystemPromptId */ diff --git a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/common_attributes.schema.yaml b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/common_attributes.schema.yaml index 1359543f2e588..208f7017d16dc 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/common_attributes.schema.yaml +++ b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/common_attributes.schema.yaml @@ -117,14 +117,10 @@ components: type: object required: - connectorId - - connectorTypeTitle properties: connectorId: type: string description: connector Id - connectorTypeTitle: - type: string - description: connector Type Title defaultSystemPromptId: type: string description: defaultSystemPromptId diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/conversations/use_bulk_actions_conversations.test.ts b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/conversations/use_bulk_actions_conversations.test.ts index 011788adf083f..06351ad4b0827 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/conversations/use_bulk_actions_conversations.test.ts +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/conversations/use_bulk_actions_conversations.test.ts @@ -16,7 +16,7 @@ import { IToasts } from '@kbn/core-notifications-browser'; const conversation1 = { id: 'conversation1', title: 'Conversation 1', - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'default', messages: [ diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/index.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/index.test.tsx index 585dc12e8e7c7..c54cfa56b4898 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/index.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/index.test.tsx @@ -26,7 +26,6 @@ const mockHttp = { const apiConfig: Conversation['apiConfig'] = { connectorId: 'foo', - connectorTypeTitle: 'OpenAI', model: 'gpt-4', provider: OpenAiProviderType.OpenAi, }; @@ -53,7 +52,7 @@ describe('API tests', () => { expect(mockHttp.fetch).toHaveBeenCalledWith( '/internal/elastic_assistant/actions/connector/foo/_execute', { - body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false,"llmType":"openai"}', + body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false}', headers: { 'Content-Type': 'application/json' }, method: 'POST', signal: undefined, @@ -73,7 +72,7 @@ describe('API tests', () => { expect(mockHttp.fetch).toHaveBeenCalledWith( '/internal/elastic_assistant/actions/connector/foo/_execute', { - body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeStream","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":false,"llmType":"openai"}', + body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeStream","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":false}', method: 'POST', asResponse: true, rawResponse: true, @@ -99,7 +98,7 @@ describe('API tests', () => { expect(mockHttp.fetch).toHaveBeenCalledWith( '/internal/elastic_assistant/actions/connector/foo/_execute', { - body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[{"uuid":"auuid","value":"real.hostname"}],"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":true,"llmType":"openai","alertsIndexPattern":".alerts-security.alerts-default","allow":["a","b","c"],"allowReplacement":["b","c"],"size":30}', + body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[{"uuid":"auuid","value":"real.hostname"}],"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":true,"alertsIndexPattern":".alerts-security.alerts-default","allow":["a","b","c"],"allowReplacement":["b","c"],"size":30}', headers: { 'Content-Type': 'application/json', }, @@ -122,7 +121,7 @@ describe('API tests', () => { expect(mockHttp.fetch).toHaveBeenCalledWith( '/internal/elastic_assistant/actions/connector/foo/_execute', { - body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":false,"llmType":"openai"}', + body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":false}', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -145,7 +144,7 @@ describe('API tests', () => { expect(mockHttp.fetch).toHaveBeenCalledWith( '/internal/elastic_assistant/actions/connector/foo/_execute', { - body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":true,"llmType":"openai"}', + body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":true}', method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/index.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/index.tsx index bfd567d2f99ca..f5296bb07499a 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/index.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/index.tsx @@ -9,7 +9,7 @@ import { HttpSetup } from '@kbn/core/public'; import { IHttpFetchError } from '@kbn/core-http-browser'; import { ApiConfig, Replacement } from '@kbn/elastic-assistant-common'; import { API_ERROR } from '../translations'; -import { getOptionalRequestParams, llmTypeDictionary } from '../helpers'; +import { getOptionalRequestParams } from '../helpers'; export * from './conversations'; export interface FetchConnectorExecuteAction { @@ -53,7 +53,6 @@ export const fetchConnectorExecuteAction = async ({ signal, size, }: FetchConnectorExecuteAction): Promise => { - const llmType = llmTypeDictionary[apiConfig.connectorTypeTitle]; // TODO: Remove in part 3 of streaming work for security solution // tracked here: https://github.com/elastic/security-team/issues/7363 // In part 3 I will make enhancements to langchain to introduce streaming @@ -76,7 +75,6 @@ export const fetchConnectorExecuteAction = async ({ replacements, isEnabledKnowledgeBase, isEnabledRAGAlerts, - llmType, ...optionalRequestParams, }; diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_selector/index.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_selector/index.tsx index 7a7316c3e6678..17599dedd4176 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_selector/index.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_selector/index.tsx @@ -118,7 +118,6 @@ export const ConversationSelector: React.FC = React.memo( ? { apiConfig: { connectorId: defaultConnector.id, - connectorTypeTitle: defaultConnector.connectorTypeTitle, provider: defaultConnector.apiProvider, defaultSystemPromptId: defaultSystemPrompt?.id, }, diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_settings/conversation_settings.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_settings/conversation_settings.test.tsx index fdfea79f4b073..fb75b9d911dda 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_settings/conversation_settings.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_settings/conversation_settings.test.tsx @@ -102,7 +102,6 @@ const mockConnector = { id: 'cool-id-bro', actionTypeId: '.gen-ai', name: 'cool name', - connectorTypeTitle: 'OpenAI', }; jest.mock('../../../connectorland/connector_selector', () => ({ // @ts-ignore @@ -231,7 +230,6 @@ describe('ConversationSettings', () => { ...mockConvos[welcomeConvo.title], apiConfig: { connectorId: mockConnector.id, - connectorTypeTitle: 'OpenAI', model: undefined, provider: undefined, }, @@ -243,7 +241,6 @@ describe('ConversationSettings', () => { ...mockConvos[welcomeConvo.title], apiConfig: { connectorId: mockConnector.id, - connectorTypeTitle: 'OpenAI', model: undefined, provider: undefined, }, @@ -331,7 +328,6 @@ describe('ConversationSettings', () => { id: 'not-the-right-id', apiConfig: { connectorId: mockConnector.id, - connectorTypeTitle: 'OpenAI', model: undefined, provider: undefined, }, diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_settings/conversation_settings.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_settings/conversation_settings.tsx index 08485e7fca4e9..544d08b35e888 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_settings/conversation_settings.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/conversations/conversation_settings/conversation_settings.tsx @@ -47,7 +47,6 @@ export interface ConversationSettingsProps { */ export const ConversationSettings: React.FC = React.memo( ({ - actionTypeRegistry, allSystemPrompts, defaultConnector, selectedConversation, @@ -68,7 +67,6 @@ export const ConversationSettings: React.FC = React.m }, [allSystemPrompts, selectedConversation]); const { data: connectors, isSuccess: areConnectorsFetched } = useLoadConnectors({ - actionTypeRegistry, http, }); @@ -89,7 +87,6 @@ export const ConversationSettings: React.FC = React.m ? { apiConfig: { connectorId: defaultConnector.id, - connectorTypeTitle: defaultConnector.connectorTypeTitle, provider: defaultConnector.apiProvider, defaultSystemPromptId: defaultSystemPrompt?.id, }, @@ -231,7 +228,6 @@ export const ConversationSettings: React.FC = React.m apiConfig: { ...selectedConversation.apiConfig, connectorId: connector.id, - connectorTypeTitle: connector.connectorTypeTitle, provider: config?.apiProvider, model: config?.defaultModel, }, @@ -257,7 +253,6 @@ export const ConversationSettings: React.FC = React.m : {} ).apiConfig ?? {}), connectorId: connector?.id, - connectorTypeTitle: connector?.connectorTypeTitle, provider: config?.apiProvider, model: config?.defaultModel, }, diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/helpers.test.ts b/x-pack/packages/kbn-elastic-assistant/impl/assistant/helpers.test.ts index a63aa5b809aae..4bb9d099bc7c4 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/helpers.test.ts +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/helpers.test.ts @@ -23,7 +23,7 @@ describe('helpers', () => { category: 'assistant', theme: {}, messages: [], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], title: 'conversation_id', }; @@ -46,7 +46,7 @@ describe('helpers', () => { }, }, ], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'assistant', title: 'conversation_id', @@ -60,7 +60,7 @@ describe('helpers', () => { id: 'conversation_id', title: 'conversation_id', messages: enterpriseMessaging, - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'assistant', }; @@ -86,7 +86,7 @@ describe('helpers', () => { }, }, ], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], }; const result = getBlockBotConversation(conversation, isAssistantEnabled); @@ -102,7 +102,7 @@ describe('helpers', () => { title: 'conversation_id', category: 'assistant', messages: [], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], }; const result = getBlockBotConversation(conversation, isAssistantEnabled); @@ -124,7 +124,7 @@ describe('helpers', () => { }, }, ], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], }; const result = getBlockBotConversation(conversation, isAssistantEnabled); @@ -151,7 +151,6 @@ describe('helpers', () => { const connectors: AIConnector[] = [ { actionTypeId: '.gen-ai', - connectorTypeTitle: 'OpenAI', isPreconfigured: false, isDeprecated: false, referencedByCount: 0, @@ -175,7 +174,6 @@ describe('helpers', () => { const connectors: AIConnector[] = [ { actionTypeId: '.gen-ai', - connectorTypeTitle: 'OpenAI', isPreconfigured: false, isDeprecated: false, referencedByCount: 0, @@ -191,7 +189,6 @@ describe('helpers', () => { }, { actionTypeId: '.gen-ai', - connectorTypeTitle: 'OpenAI', isPreconfigured: false, isDeprecated: false, referencedByCount: 0, @@ -268,7 +265,7 @@ describe('helpers', () => { messages, category: 'assistant', theme: {}, - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], }; const baseConversations = { diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/helpers.ts b/x-pack/packages/kbn-elastic-assistant/impl/assistant/helpers.ts index b5308334dafbc..c78d7aee079d0 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/helpers.ts +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/helpers.ts @@ -118,9 +118,3 @@ export const getOptionalRequestParams = ({ ...optionalSize, }; }; - -export const llmTypeDictionary: Record = { - 'Amazon Bedrock': 'bedrock', - 'Azure OpenAI': 'openai', - OpenAI: 'openai', -}; diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/index.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/index.test.tsx index f7caee3462bc2..48733ce80cb9f 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/index.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/index.test.tsx @@ -50,7 +50,7 @@ const mockData = { title: 'Welcome', category: 'assistant', messages: [], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], }, 'electric sheep': { @@ -58,7 +58,7 @@ const mockData = { category: 'assistant', title: 'electric sheep', messages: [], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], }, }; @@ -169,7 +169,7 @@ describe('Assistant', () => { expect(chatSendSpy).toHaveBeenLastCalledWith( expect.objectContaining({ currentConversation: { - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'assistant', id: 'Welcome Id', diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/index.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/index.tsx index a322372e75395..64fffb8181678 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/index.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/index.tsx @@ -80,7 +80,6 @@ const AssistantComponent: React.FC = ({ setConversationTitle, }) => { const { - actionTypeRegistry, assistantTelemetry, augmentMessageCodeBlocks, assistantAvailability: { isAssistantEnabled }, @@ -136,7 +135,6 @@ const AssistantComponent: React.FC = ({ // Connector details const { data: connectors, isSuccess: areConnectorsFetched } = useLoadConnectors({ - actionTypeRegistry, http, }); const defaultConnector = useMemo(() => getDefaultConnector(connectors), [connectors]); diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/system_prompt/index.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/system_prompt/index.test.tsx index 2e45c4109b0ad..454c9bec9fa06 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/system_prompt/index.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/system_prompt/index.test.tsx @@ -23,7 +23,6 @@ const BASE_CONVERSATION: Conversation = { ...WELCOME_CONVERSATION, apiConfig: { connectorId: '123', - connectorTypeTitle: 'OpenAI', defaultSystemPromptId: mockSystemPrompt.id, }, }; @@ -377,7 +376,6 @@ describe('SystemPrompt', () => { category: 'assistant', apiConfig: { connectorId: '123', - connectorTypeTitle: 'OpenAI', defaultSystemPromptId: undefined, }, title: 'second', @@ -462,7 +460,6 @@ describe('SystemPrompt', () => { ...secondMockConversation, apiConfig: { connectorId: '123', - connectorTypeTitle: 'OpenAI', defaultSystemPromptId: mockSystemPrompt.id, }, }, diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/system_prompt/system_prompt_modal/system_prompt_settings.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/system_prompt/system_prompt_modal/system_prompt_settings.tsx index adc8157f9b49b..f49284f6a7175 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/system_prompt/system_prompt_modal/system_prompt_settings.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/prompt_editor/system_prompt/system_prompt_modal/system_prompt_settings.tsx @@ -144,7 +144,6 @@ export const SystemPromptSettings: React.FC = React.memo( apiConfig: { defaultSystemPromptId: getDefaultSystemPromptId(convo), connectorId: defaultConnector?.id ?? '', - connectorTypeTitle: defaultConnector?.connectorTypeTitle ?? '', }, }), })) @@ -211,7 +210,6 @@ export const SystemPromptSettings: React.FC = React.memo( [ conversationSettings, conversationsSettingsBulkActions, - defaultConnector?.connectorTypeTitle, defaultConnector?.id, selectedSystemPrompt, setConversationSettings, diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/settings/evaluation_settings/evaluation_settings.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/settings/evaluation_settings/evaluation_settings.tsx index f7f89ac1cfe17..09cdf6717ca6c 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/settings/evaluation_settings/evaluation_settings.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/settings/evaluation_settings/evaluation_settings.tsx @@ -53,7 +53,7 @@ interface Props { */ export const EvaluationSettings: React.FC = React.memo(({ onEvaluationSettingsChange }) => { const { actionTypeRegistry, basePath, http } = useAssistantContext(); - const { data: connectors } = useLoadConnectors({ actionTypeRegistry, http }); + const { data: connectors } = useLoadConnectors({ http }); const { data: evalResponse, mutate: performEvaluation, diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/use_conversation/helpers.test.ts b/x-pack/packages/kbn-elastic-assistant/impl/assistant/use_conversation/helpers.test.ts index 60f44d2314c4d..9d101b4423f26 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/use_conversation/helpers.test.ts +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/use_conversation/helpers.test.ts @@ -93,7 +93,6 @@ describe('useConversation helpers', () => { const conversation: Conversation = { apiConfig: { connectorId: '123', - connectorTypeTitle: 'OpenAI', defaultSystemPromptId: '3', }, category: 'assistant', @@ -111,7 +110,7 @@ describe('useConversation helpers', () => { test('should return the default (starred) isNewConversationDefault system prompt if conversation system prompt does not exist', () => { const conversationWithoutSystemPrompt: Conversation = { - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'assistant', id: '1', @@ -128,7 +127,7 @@ describe('useConversation helpers', () => { test('should return the default (starred) isNewConversationDefault system prompt if conversation system prompt does not exist within all system prompts', () => { const conversationWithoutSystemPrompt: Conversation = { - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'assistant', id: '4', // this id does not exist within allSystemPrompts @@ -145,7 +144,7 @@ describe('useConversation helpers', () => { test('should return the first prompt if both conversation system prompt and default new system prompt do not exist', () => { const conversationWithoutSystemPrompt: Conversation = { - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'assistant', id: '1', @@ -162,7 +161,7 @@ describe('useConversation helpers', () => { test('should return undefined if conversation system prompt does not exist and there are no system prompts', () => { const conversationWithoutSystemPrompt: Conversation = { - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'assistant', id: '1', @@ -179,7 +178,7 @@ describe('useConversation helpers', () => { test('should return undefined if conversation system prompt does not exist within all system prompts', () => { const conversationWithoutSystemPrompt: Conversation = { - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'assistant', id: '4', // this id does not exist within allSystemPrompts diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/use_conversation/index.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/use_conversation/index.test.tsx index fda09e1a148fb..29567aed6f1da 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/use_conversation/index.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/use_conversation/index.test.tsx @@ -36,7 +36,6 @@ const mockConvo = { messages: [message, anotherMessage], apiConfig: { connectorId: '123', - connectorTypeTitle: 'OpenAI', defaultSystemPromptId: 'default-system-prompt', }, }; @@ -69,7 +68,6 @@ describe('useConversation', () => { replacements: [], apiConfig: { connectorId: '123', - connectorTypeTitle: 'OpenAI', defaultSystemPromptId: 'default-system-prompt', }, title: mockConvo.title, diff --git a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector/index.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector/index.test.tsx index 0c984c03fc3e9..fbc89665b8bdf 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector/index.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector/index.test.tsx @@ -90,10 +90,7 @@ describe('Connector selector', () => { expect(getByTestId('connector-selector')).toBeInTheDocument(); fireEvent.click(getByTestId('connector-selector')); fireEvent.click(getByTestId(connectorTwo.id)); - expect(onConnectorSelectionChange).toHaveBeenCalledWith({ - ...connectorTwo, - connectorTypeTitle: 'OpenAI', - }); + expect(onConnectorSelectionChange).toHaveBeenCalledWith(connectorTwo); }); it('Calls onConnectorSelectionChange once new connector is saved', () => { const { getByTestId } = render( @@ -106,10 +103,7 @@ describe('Connector selector', () => { fireEvent.click(getByTestId('modal-mock')); - expect(onConnectorSelectionChange).toHaveBeenCalledWith({ - ...newConnector, - connectorTypeTitle: 'OpenAI', - }); + expect(onConnectorSelectionChange).toHaveBeenCalledWith(newConnector); expect(mockRefetchConnectors).toHaveBeenCalled(); expect(setIsOpen).toHaveBeenCalledWith(false); }); diff --git a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector/index.tsx b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector/index.tsx index 33b5cb030b5a9..c93b5b5c5c4a7 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector/index.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector/index.tsx @@ -30,8 +30,6 @@ interface Props { } export type AIConnector = ActionConnector & { - // ex: Bedrock, OpenAI - connectorTypeTitle: string; // related to OpenAI connectors, ex: Azure OpenAI, OpenAI apiProvider?: OpenAiProviderType; }; @@ -57,7 +55,7 @@ export const ConnectorSelector: React.FC = React.memo( isLoading: isLoadingConnectors, isFetching: isFetchingConnectors, refetch: refetchConnectors, - } = useLoadConnectors({ actionTypeRegistry, http }); + } = useLoadConnectors({ http }); const isLoading = isLoadingConnectors || isFetchingConnectors; const localIsDisabled = isDisabled || !assistantAvailability.hasConnectorsReadPrivilege; @@ -91,7 +89,8 @@ export const ConnectorSelector: React.FC = React.memo( () => (aiConnectors ?? []).map((connector) => { const connectorTypeTitle = - getGenAiConfig(connector)?.apiProvider ?? connector.connectorTypeTitle; + getGenAiConfig(connector)?.apiProvider ?? + getActionTypeTitle(actionTypeRegistry.get(connector.actionTypeId)); const connectorDetails = connector.isPreconfigured ? i18n.PRECONFIGURED_CONNECTOR : connectorTypeTitle; @@ -111,7 +110,7 @@ export const ConnectorSelector: React.FC = React.memo( ), }; }), - [aiConnectors, displayFancy] + [actionTypeRegistry, aiConnectors, displayFancy] ); // Only include add new connector option if user has privilege @@ -151,12 +150,11 @@ export const ConnectorSelector: React.FC = React.memo( (connector: ActionConnector) => { onConnectorSelectionChange({ ...connector, - connectorTypeTitle: getActionTypeTitle(actionTypeRegistry.get(connector.actionTypeId)), }); refetchConnectors?.(); cleanupAndCloseModal(); }, - [actionTypeRegistry, cleanupAndCloseModal, onConnectorSelectionChange, refetchConnectors] + [cleanupAndCloseModal, onConnectorSelectionChange, refetchConnectors] ); return ( diff --git a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.test.tsx index 03d829bf22adc..44cfd59bdbecc 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.test.tsx @@ -77,7 +77,7 @@ describe('ConnectorSelectorInline', () => { id: 'conversation_id', category: 'assistant', messages: [], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], title: 'conversation_id', }; @@ -98,7 +98,7 @@ describe('ConnectorSelectorInline', () => { id: 'conversation_id', category: 'assistant', messages: [], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], title: 'conversation_id', }; @@ -122,7 +122,7 @@ describe('ConnectorSelectorInline', () => { id: 'conversation_id', category: 'assistant', messages: [], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], title: 'conversation_id', }; @@ -143,12 +143,11 @@ describe('ConnectorSelectorInline', () => { expect(setApiConfig).toHaveBeenCalledWith({ apiConfig: { connectorId: connectorTwo.id, - connectorTypeTitle: 'OpenAI', model: undefined, provider: 'OpenAI', }, conversation: { - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], category: 'assistant', id: 'conversation_id', @@ -162,7 +161,7 @@ describe('ConnectorSelectorInline', () => { id: 'conversation_id', category: 'assistant', messages: [], - apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' }, + apiConfig: { connectorId: '123' }, replacements: [], title: 'conversation_id', }; diff --git a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.tsx b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.tsx index 4b05e93305163..842b921f54c35 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.tsx @@ -68,11 +68,10 @@ const placeholderButtonClassName = css` export const ConnectorSelectorInline: React.FC = React.memo( ({ isDisabled = false, selectedConnectorId, selectedConversation, onConnectorSelected }) => { const [isOpen, setIsOpen] = useState(false); - const { actionTypeRegistry, assistantAvailability, http } = useAssistantContext(); + const { assistantAvailability, http } = useAssistantContext(); const { setApiConfig } = useConversation(); const { data: aiConnectors } = useLoadConnectors({ - actionTypeRegistry, http, }); @@ -103,7 +102,6 @@ export const ConnectorSelectorInline: React.FC = React.memo( apiConfig: { ...selectedConversation.apiConfig, connectorId, - connectorTypeTitle: connector.connectorTypeTitle, // With the inline component, prefer config args to handle 'new connector' case provider: apiProvider ?? config?.apiProvider, model: model ?? config?.defaultModel, diff --git a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_setup/index.tsx b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_setup/index.tsx index b4db98b62d953..b57cf286d27f1 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_setup/index.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/connector_setup/index.tsx @@ -25,7 +25,7 @@ import * as i18n from '../translations'; import { useAssistantContext } from '../../assistant_context'; import { useLoadConnectors } from '../use_load_connectors'; import { AssistantAvatar } from '../../assistant/assistant_avatar/assistant_avatar'; -import { getActionTypeTitle, getGenAiConfig } from '../helpers'; +import { getGenAiConfig } from '../helpers'; const ConnectorButtonWrapper = styled.div` margin-bottom: 10px; @@ -58,7 +58,7 @@ export const useConnectorSetup = ({ data: connectors, isSuccess: areConnectorsFetched, refetch: refetchConnectors, - } = useLoadConnectors({ actionTypeRegistry, http }); + } = useLoadConnectors({ http }); const isConnectorConfigured = areConnectorsFetched && !!connectors?.length; const [isConnectorModalVisible, setIsConnectorModalVisible] = useState(false); @@ -175,16 +175,12 @@ export const useConnectorSetup = ({ const onSaveConnector = useCallback( async (connector: ActionConnector) => { const config = getGenAiConfig(connector); - // add action type title to new connector - const connectorTypeTitle = getActionTypeTitle(actionTypeRegistry.get(connector.actionTypeId)); // persist only the active conversation - const updatedConversation = await setApiConfig({ conversation, apiConfig: { ...conversation.apiConfig, connectorId: connector.id, - connectorTypeTitle, provider: config?.apiProvider, model: config?.defaultModel, }, @@ -197,7 +193,7 @@ export const useConnectorSetup = ({ setIsConnectorModalVisible(false); } }, - [actionTypeRegistry, conversation, onConversationUpdate, refetchConnectors, setApiConfig] + [conversation, onConversationUpdate, refetchConnectors, setApiConfig] ); return { diff --git a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/use_load_connectors/index.tsx b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/use_load_connectors/index.tsx index 0bb401bcd5469..b93c166a9c5d7 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/connectorland/use_load_connectors/index.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/connectorland/use_load_connectors/index.tsx @@ -10,13 +10,10 @@ import { useQuery } from '@tanstack/react-query'; import type { ServerError } from '@kbn/cases-plugin/public/types'; import { loadAllActions as loadConnectors } from '@kbn/triggers-actions-ui-plugin/public/common/constants'; import type { IHttpFetchError } from '@kbn/core-http-browser'; -import { ActionTypeRegistryContract } from '@kbn/triggers-actions-ui-plugin/public'; import { HttpSetup } from '@kbn/core-http-browser'; import { IToasts } from '@kbn/core-notifications-browser'; -import { useMemo } from 'react'; import { OpenAiProviderType } from '@kbn/stack-connectors-plugin/common/openai/constants'; import { AIConnector } from '../connector_selector'; -import { getActionTypeTitle } from '../helpers'; import * as i18n from '../translations'; /** @@ -26,7 +23,6 @@ import * as i18n from '../translations'; const QUERY_KEY = ['elastic-assistant, load-connectors']; export interface Props { - actionTypeRegistry: ActionTypeRegistryContract; http: HttpSetup; toasts?: IToasts; } @@ -37,27 +33,9 @@ const actionTypeKey = { }; export const useLoadConnectors = ({ - actionTypeRegistry, http, toasts, }: Props): UseQueryResult => { - const connectorDetails = useMemo( - () => - actionTypeRegistry - ? { - [actionTypeKey.bedrock]: getActionTypeTitle( - actionTypeRegistry.get(actionTypeKey.bedrock) - ), - [actionTypeKey.openai]: getActionTypeTitle( - actionTypeRegistry.get(actionTypeKey.openai) - ), - } - : { - [actionTypeKey.bedrock]: 'Amazon Bedrock', - [actionTypeKey.openai]: 'OpenAI', - }, - [actionTypeRegistry] - ); return useQuery( QUERY_KEY, async () => { @@ -70,7 +48,6 @@ export const useLoadConnectors = ({ ? [ { ...connector, - connectorTypeTitle: connectorDetails[connector.actionTypeId], apiProvider: !connector.isPreconfigured && !connector.isSystemAction && diff --git a/x-pack/packages/kbn-elastic-assistant/impl/mock/connectors.ts b/x-pack/packages/kbn-elastic-assistant/impl/mock/connectors.ts index 855cf6293d7a5..05b4e96d2b0da 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/mock/connectors.ts +++ b/x-pack/packages/kbn-elastic-assistant/impl/mock/connectors.ts @@ -34,7 +34,6 @@ export const mockActionTypes = [ export const mockConnectors: AIConnector[] = [ { id: 'connectorId', - connectorTypeTitle: 'OpenAI', name: 'Captain Connector', isMissingSecrets: false, actionTypeId: '.gen-ai', @@ -48,7 +47,6 @@ export const mockConnectors: AIConnector[] = [ }, { id: 'c29c28a0-20fe-11ee-9306-a1f4d42ec542', - connectorTypeTitle: 'OpenAI', name: 'Professor Connector', isMissingSecrets: false, actionTypeId: '.gen-ai', diff --git a/x-pack/packages/kbn-elastic-assistant/impl/mock/conversation.ts b/x-pack/packages/kbn-elastic-assistant/impl/mock/conversation.ts index 46625512a5fca..435e74c547256 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/mock/conversation.ts +++ b/x-pack/packages/kbn-elastic-assistant/impl/mock/conversation.ts @@ -23,7 +23,6 @@ export const alertConvo: Conversation = { ], apiConfig: { connectorId: 'c29c28a0-20fe-11ee-9306-a1f4d42ec542', - connectorTypeTitle: 'OpenAI', provider: OpenAiProviderType.OpenAi, }, replacements: [ @@ -42,7 +41,6 @@ export const emptyWelcomeConvo: Conversation = { replacements: [], apiConfig: { connectorId: 'c29c28a0-20fe-11ee-9306-a1f4d42ec542', - connectorTypeTitle: 'OpenAI', provider: OpenAiProviderType.OpenAi, }, }; @@ -74,7 +72,6 @@ export const customConvo: Conversation = { replacements: [], apiConfig: { connectorId: 'c29c28a0-20fe-11ee-9306-a1f4d42ec542', - connectorTypeTitle: 'OpenAI', provider: OpenAiProviderType.OpenAi, }, }; diff --git a/x-pack/plugins/elastic_assistant/server/__mocks__/conversations_schema.mock.ts b/x-pack/plugins/elastic_assistant/server/__mocks__/conversations_schema.mock.ts index aa88fab105266..e7914ccb60acd 100644 --- a/x-pack/plugins/elastic_assistant/server/__mocks__/conversations_schema.mock.ts +++ b/x-pack/plugins/elastic_assistant/server/__mocks__/conversations_schema.mock.ts @@ -65,7 +65,6 @@ export const getCreateConversationSchemaMock = (): ConversationCreateProps => ({ apiConfig: { connectorId: '1', defaultSystemPromptId: 'Default', - connectorTypeTitle: 'Test connector', model: 'model', }, excludeFromLastConversationStorage: false, @@ -91,7 +90,6 @@ export const getUpdateConversationSchemaMock = ( apiConfig: { connectorId: '2', defaultSystemPromptId: 'Default', - connectorTypeTitle: 'Test connector', model: 'model', }, excludeFromLastConversationStorage: false, @@ -131,7 +129,6 @@ export const getConversationMock = ( apiConfig: { connectorId: '1', defaultSystemPromptId: 'Default', - connectorTypeTitle: 'OpenAI', }, replacements: [], title: 'test', @@ -156,7 +153,6 @@ export const getQueryConversationParams = ( apiConfig: { connectorId: '2', defaultSystemPromptId: 'Default', - connectorTypeTitle: 'Test connector', model: 'model', }, category: 'assistant', @@ -180,7 +176,6 @@ export const getQueryConversationParams = ( apiConfig: { connectorId: '1', defaultSystemPromptId: 'Default', - connectorTypeTitle: 'Test connector', model: 'model', }, excludeFromLastConversationStorage: false, diff --git a/x-pack/plugins/elastic_assistant/server/__mocks__/response.ts b/x-pack/plugins/elastic_assistant/server/__mocks__/response.ts index 5ba6946c68688..3b71dfcfbb67c 100644 --- a/x-pack/plugins/elastic_assistant/server/__mocks__/response.ts +++ b/x-pack/plugins/elastic_assistant/server/__mocks__/response.ts @@ -69,7 +69,6 @@ export const getConversationResponseMock = ( title: 'test', apiConfig: { connectorId: '1', - connectorTypeTitle: 'test-connector', defaultSystemPromptId: 'default-system-prompt', model: 'test-model', provider: 'OpenAI', diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/create_conversation.test.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/create_conversation.test.ts index 5d6851538be0c..2ac98390ccef0 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/create_conversation.test.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/create_conversation.test.ts @@ -30,7 +30,6 @@ export const getCreateConversationMock = (): ConversationCreateProps => ({ title: 'test', apiConfig: { connectorId: '1', - connectorTypeTitle: 'test-connector', defaultSystemPromptId: 'default-system-prompt', model: 'test-model', provider: 'OpenAI', @@ -47,7 +46,6 @@ export const getConversationResponseMock = (): ConversationResponse => ({ title: 'test', apiConfig: { connectorId: '1', - connectorTypeTitle: 'test-connector', defaultSystemPromptId: 'default-system-prompt', model: 'test-model', provider: 'OpenAI', @@ -96,7 +94,6 @@ export const getSearchConversationMock = exclude_from_last_conversation_storage: false, api_config: { connector_id: 'c1', - connector_type_title: 'title-c-1', default_system_prompt_id: 'prompt-1', model: 'test', provider: 'Azure OpenAI', diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/create_conversation.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/create_conversation.ts index 6c50a1d44bbd7..7dc36f9d4bd36 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/create_conversation.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/create_conversation.ts @@ -86,7 +86,6 @@ export const transformToCreateScheme = ( api_config: apiConfig ? { connector_id: apiConfig.connectorId, - connector_type_title: apiConfig.connectorTypeTitle, default_system_prompt_id: apiConfig.defaultSystemPromptId, model: apiConfig.model, provider: apiConfig.provider, diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/field_maps_configuration.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/field_maps_configuration.ts index 9c2461ac928f5..870c71157813f 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/field_maps_configuration.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/field_maps_configuration.ts @@ -147,11 +147,6 @@ export const conversationsFieldMap: FieldMap = { array: false, required: false, }, - 'api_config.connector_type_title': { - type: 'keyword', - array: false, - required: false, - }, 'api_config.default_system_prompt_id': { type: 'keyword', array: false, diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/get_conversation.test.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/get_conversation.test.ts index 1ea3962c9def9..e0b10ab8df5c4 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/get_conversation.test.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/get_conversation.test.ts @@ -26,7 +26,6 @@ export const getConversationResponseMock = (): ConversationResponse => ({ timestamp: '2020-04-20T15:25:31.830Z', apiConfig: { connectorId: 'c1', - connectorTypeTitle: 'title-c-1', defaultSystemPromptId: 'prompt-1', model: 'test', provider: 'Azure OpenAI', @@ -79,7 +78,6 @@ export const getSearchConversationMock = exclude_from_last_conversation_storage: false, api_config: { connector_id: 'c1', - connector_type_title: 'title-c-1', default_system_prompt_id: 'prompt-1', model: 'test', provider: 'Azure OpenAI', diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/helpers.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/helpers.ts index 3d022c0063fa5..baaa0a6e94a9f 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/helpers.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/helpers.ts @@ -21,9 +21,6 @@ export const getUpdateScript = ({ if (params.assignEmpty == true || params.api_config.containsKey('connector_id')) { ctx._source.api_config.connector_id = params.api_config.connector_id; } - if (params.assignEmpty == true || params.api_config.containsKey('connector_type_title')) { - ctx._source.api_config.connector_type_title = params.api_config.connector_type_title; - } if (params.assignEmpty == true || params.api_config.containsKey('default_system_prompt_id')) { ctx._source.api_config.default_system_prompt_id = params.api_config.default_system_prompt_id; } diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/index.test.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/index.test.ts index ec1a36ceb3563..5e644861726a1 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/index.test.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/index.test.ts @@ -61,7 +61,6 @@ describe('AIAssistantConversationsDataClient', () => { api_config: { connector_id: 'bedbf764-b991-4115-a9fc-1cfeaef21046', model: 'anthropic.claude-v2', - connector_type_title: 'Amazon Bedrock', }, namespace: 'hghjghjghghjghg33', created_at: '2024-01-25T01:32:37.649Z', @@ -113,7 +112,6 @@ describe('AIAssistantConversationsDataClient', () => { expect(result).toEqual({ apiConfig: { connectorId: 'bedbf764-b991-4115-a9fc-1cfeaef21046', - connectorTypeTitle: 'Amazon Bedrock', defaultSystemPromptId: undefined, model: 'anthropic.claude-v2', provider: undefined, @@ -180,7 +178,6 @@ describe('AIAssistantConversationsDataClient', () => { params: { api_config: { connector_id: '2', - connector_type_title: 'Test connector', default_system_prompt_id: 'Default', model: 'model', provider: undefined, diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/transforms.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/transforms.ts index 05e1ae8d71f8a..fa70914d07e9b 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/transforms.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/transforms.ts @@ -36,7 +36,6 @@ export const transformESToConversations = ( ? { apiConfig: { connectorId: conversationSchema.api_config.connector_id, - connectorTypeTitle: conversationSchema.api_config.connector_type_title, defaultSystemPromptId: conversationSchema.api_config.default_system_prompt_id, model: conversationSchema.api_config.model, provider: conversationSchema.api_config.provider, diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/types.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/types.ts index 9eb4633c366ec..24ef8b2e8a941 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/types.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/types.ts @@ -39,7 +39,6 @@ export interface SearchEsConversationSchema { }>; api_config?: { connector_id: string; - connector_type_title: string; default_system_prompt_id?: string; provider?: Provider; model?: string; @@ -74,7 +73,6 @@ export interface CreateMessageSchema { }>; api_config?: { connector_id?: string; - connector_type_title?: string; default_system_prompt_id?: string; provider?: Provider; model?: string; diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/update_conversation.test.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/update_conversation.test.ts index 271b74d2b01c5..0d2679e839c71 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/update_conversation.test.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/update_conversation.test.ts @@ -21,7 +21,6 @@ export const getUpdateConversationOptionsMock = (): ConversationUpdateProps => ( title: 'test', apiConfig: { connectorId: '1', - connectorTypeTitle: 'test-connector', defaultSystemPromptId: 'default-system-prompt', model: 'test-model', provider: 'OpenAI', @@ -44,7 +43,6 @@ export const getConversationResponseMock = (): ConversationResponse => ({ title: 'test', apiConfig: { connectorId: '1', - connectorTypeTitle: 'test-connector', defaultSystemPromptId: 'default-system-prompt', model: 'test-model', provider: 'OpenAI', @@ -164,7 +162,6 @@ describe('transformToUpdateScheme', () => { title: 'test', api_config: { connector_id: '1', - connector_type_title: 'test-connector', default_system_prompt_id: 'default-system-prompt', model: 'test-model', provider: 'OpenAI', diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/update_conversation.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/update_conversation.ts index 348b2ae15aeba..8395c26f9916e 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/update_conversation.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/conversations/update_conversation.ts @@ -37,7 +37,6 @@ export interface UpdateConversationSchema { }>; api_config?: { connector_id?: string; - connector_type_title?: string; default_system_prompt_id?: string; provider?: Provider; model?: string; @@ -118,7 +117,6 @@ export const transformToUpdateScheme = ( title, api_config: { connector_id: apiConfig?.connectorId, - connector_type_title: apiConfig?.connectorTypeTitle, default_system_prompt_id: apiConfig?.defaultSystemPromptId, model: apiConfig?.model, provider: apiConfig?.provider, diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/find.test.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/find.test.ts index a16cf81fb8de3..bc4f8c574a8a9 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/find.test.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/find.test.ts @@ -25,7 +25,6 @@ export const findDocumentsResponseMock = (): ConversationResponse => ({ timestamp: '2020-04-20T15:25:31.830Z', apiConfig: { connectorId: 'c1', - connectorTypeTitle: 'title-c-1', defaultSystemPromptId: 'prompt-1', model: 'test', provider: 'Azure OpenAI', @@ -70,7 +69,6 @@ export const getSearchConversationMock = exclude_from_last_conversation_storage: false, api_config: { connector_id: 'c1', - connector_type_title: 'title-c-1', default_system_prompt_id: 'prompt-1', model: 'test', provider: 'Azure OpenAI', @@ -137,7 +135,6 @@ describe('findDocuments', () => { '@timestamp': '2020-04-20T15:25:31.830Z', api_config: { connector_id: 'c1', - connector_type_title: 'title-c-1', default_system_prompt_id: 'prompt-1', model: 'test', provider: 'Azure OpenAI', diff --git a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/index.test.ts b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/index.test.ts index e375b10425123..fa27331f6c6c5 100644 --- a/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/index.test.ts +++ b/x-pack/plugins/elastic_assistant/server/ai_assistant_data_clients/index.test.ts @@ -134,7 +134,6 @@ describe('AIAssistantDataClient', () => { api_config: { connector_id: 'bedbf764-b991-4115-a9fc-1cfeaef21046', model: 'anthropic.claude-v2', - connector_type_title: 'Amazon Bedrock', }, namespace: 'hghjghjghghjghg33', created_at: '2024-01-25T01:32:37.649Z', @@ -194,7 +193,6 @@ describe('AIAssistantDataClient', () => { '@timestamp': '2024-01-25T01:32:37.649Z', api_config: { connector_id: 'bedbf764-b991-4115-a9fc-1cfeaef21046', - connector_type_title: 'Amazon Bedrock', model: 'anthropic.claude-v2', }, created_at: '2024-01-25T01:32:37.649Z', diff --git a/x-pack/plugins/elastic_assistant/server/lib/executor.test.ts b/x-pack/plugins/elastic_assistant/server/lib/executor.test.ts index dedaad2331f41..7c41c32cc89c0 100644 --- a/x-pack/plugins/elastic_assistant/server/lib/executor.test.ts +++ b/x-pack/plugins/elastic_assistant/server/lib/executor.test.ts @@ -29,6 +29,7 @@ const testProps: Omit = { subAction: 'invokeAI', subActionParams: { messages: [{ content: 'hello', role: 'user' }] }, }, + llmType: '.bedrock', request, connectorId, onLlmResponse, diff --git a/x-pack/plugins/elastic_assistant/server/lib/executor.ts b/x-pack/plugins/elastic_assistant/server/lib/executor.ts index 7d5c917e2c890..a0a2c71c30d63 100644 --- a/x-pack/plugins/elastic_assistant/server/lib/executor.ts +++ b/x-pack/plugins/elastic_assistant/server/lib/executor.ts @@ -18,6 +18,7 @@ export interface Props { connectorId: string; params: InvokeAIActionsParams; request: KibanaRequest; + llmType: string; } interface StaticResponse { connector_id: string; @@ -44,6 +45,7 @@ export const executeAction = async ({ actions, params, connectorId, + llmType, request, }: Props): Promise => { const actionsClient = await actions.getActionsClientWithRequest(request); @@ -76,7 +78,7 @@ export const executeAction = async ({ } // do not await, blocks stream for UI - handleStreamStorage(readable, request.body.llmType, onLlmResponse); + handleStreamStorage(readable, llmType, onLlmResponse); return readable.pipe(new PassThrough()); }; diff --git a/x-pack/plugins/elastic_assistant/server/lib/langchain/llm/actions_client_llm.ts b/x-pack/plugins/elastic_assistant/server/lib/langchain/llm/actions_client_llm.ts index ff7086e148b54..b00d6b6233502 100644 --- a/x-pack/plugins/elastic_assistant/server/lib/langchain/llm/actions_client_llm.ts +++ b/x-pack/plugins/elastic_assistant/server/lib/langchain/llm/actions_client_llm.ts @@ -81,9 +81,7 @@ export class ActionsClientLlm extends LLM { subActionParams: { model: this.#request.body.model, messages: [assistantMessage], // the assistant message - ...(this.#request.body.llmType === 'openai' - ? { n: 1, stop: null, temperature: 0.2 } - : {}), + ...(this.llmType === '.gen-ai' ? { n: 1, stop: null, temperature: 0.2 } : {}), }, }, }; diff --git a/x-pack/plugins/elastic_assistant/server/lib/parse_stream.test.ts b/x-pack/plugins/elastic_assistant/server/lib/parse_stream.test.ts index 079824b11416d..331c026f8ed7c 100644 --- a/x-pack/plugins/elastic_assistant/server/lib/parse_stream.test.ts +++ b/x-pack/plugins/elastic_assistant/server/lib/parse_stream.test.ts @@ -52,11 +52,11 @@ describe('handleStreamStorage', () => { it('saves the final string successful streaming event', async () => { stream.complete(); - await handleStreamStorage(stream.transform, 'openai', onMessageSent); + await handleStreamStorage(stream.transform, '.gen-ai', onMessageSent); expect(onMessageSent).toHaveBeenCalledWith('Single.'); }); it('saves the error message on a failed streaming event', async () => { - const tokenPromise = handleStreamStorage(stream.transform, 'openai', onMessageSent); + const tokenPromise = handleStreamStorage(stream.transform, '.gen-ai', onMessageSent); stream.fail(); await expect(tokenPromise).resolves.not.toThrow(); @@ -73,11 +73,11 @@ describe('handleStreamStorage', () => { it('saves the final string successful streaming event', async () => { stream.complete(); - await handleStreamStorage(stream.transform, 'bedrock', onMessageSent); + await handleStreamStorage(stream.transform, '.bedrock', onMessageSent); expect(onMessageSent).toHaveBeenCalledWith('Simple.'); }); it('saves the error message on a failed streaming event', async () => { - const tokenPromise = handleStreamStorage(stream.transform, 'bedrock', onMessageSent); + const tokenPromise = handleStreamStorage(stream.transform, '.bedrock', onMessageSent); stream.fail(); await expect(tokenPromise).resolves.not.toThrow(); diff --git a/x-pack/plugins/elastic_assistant/server/lib/parse_stream.ts b/x-pack/plugins/elastic_assistant/server/lib/parse_stream.ts index fed0a1cfb37bd..834fc1ce788ae 100644 --- a/x-pack/plugins/elastic_assistant/server/lib/parse_stream.ts +++ b/x-pack/plugins/elastic_assistant/server/lib/parse_stream.ts @@ -18,7 +18,7 @@ export const handleStreamStorage: ( onMessageSent?: (content: string) => void ) => Promise = async (responseStream, llmType, onMessageSent) => { try { - const parser = llmType === 'bedrock' ? parseBedrockStream : parseOpenAIStream; + const parser = llmType === '.bedrock' ? parseBedrockStream : parseOpenAIStream; // TODO @steph add abort signal const parsedResponse = await parser(responseStream); if (onMessageSent) { diff --git a/x-pack/plugins/elastic_assistant/server/routes/evaluate/post_evaluate.ts b/x-pack/plugins/elastic_assistant/server/routes/evaluate/post_evaluate.ts index c0157d03a5abc..5a5dd8a8768a3 100644 --- a/x-pack/plugins/elastic_assistant/server/routes/evaluate/post_evaluate.ts +++ b/x-pack/plugins/elastic_assistant/server/routes/evaluate/post_evaluate.ts @@ -154,7 +154,6 @@ export const postEvaluateRoute = ( isEnabledKnowledgeBase: true, isEnabledRAGAlerts: true, conversationId: '', - llmType: 'openai', }, }; diff --git a/x-pack/plugins/elastic_assistant/server/routes/post_actions_connector_execute.test.ts b/x-pack/plugins/elastic_assistant/server/routes/post_actions_connector_execute.test.ts index 098c25c9c881b..48205e153f37b 100644 --- a/x-pack/plugins/elastic_assistant/server/routes/post_actions_connector_execute.test.ts +++ b/x-pack/plugins/elastic_assistant/server/routes/post_actions_connector_execute.test.ts @@ -20,7 +20,9 @@ import { INVOKE_ASSISTANT_SUCCESS_EVENT, } from '../lib/telemetry/event_based_telemetry'; import { getConversationResponseMock } from '../ai_assistant_data_clients/conversations/update_conversation.test'; +import { actionsClientMock } from '@kbn/actions-plugin/server/actions_client/actions_client.mock'; +const actionsClient = actionsClientMock.create(); jest.mock('../lib/build_response', () => ({ buildResponse: jest.fn().mockImplementation((x) => x), })); @@ -67,7 +69,9 @@ const existingConversation = getConversationResponseMock(); const reportEvent = jest.fn(); const mockContext = { elasticAssistant: { - actions: jest.fn(), + actions: { + getActionsClientWithRequest: jest.fn().mockResolvedValue(actionsClient), + }, getRegisteredTools: jest.fn(() => []), logger: loggingSystemMock.createLogger(), telemetry: { ...coreMock.createSetup().analytics, reportEvent }, @@ -136,6 +140,22 @@ describe('postActionsConnectorExecuteRoute', () => { beforeEach(() => { jest.clearAllMocks(); + actionsClient.getBulk.mockResolvedValue([ + { + id: '1', + isPreconfigured: false, + isSystemAction: false, + isDeprecated: false, + name: 'my name', + actionTypeId: '.gen-ai', + isMissingSecrets: false, + config: { + a: true, + b: true, + c: true, + }, + }, + ]); }); it('returns the expected response when isEnabledKnowledgeBase=false', async () => { diff --git a/x-pack/plugins/elastic_assistant/server/routes/post_actions_connector_execute.ts b/x-pack/plugins/elastic_assistant/server/routes/post_actions_connector_execute.ts index ee75fd92b6063..41cba9e51d7c8 100644 --- a/x-pack/plugins/elastic_assistant/server/routes/post_actions_connector_execute.ts +++ b/x-pack/plugins/elastic_assistant/server/routes/post_actions_connector_execute.ts @@ -65,6 +65,9 @@ export const postActionsConnectorExecuteRoute = ( const telemetry = assistantContext.telemetry; try { + // Get the actions plugin start contract from the request context for the agents + const actionsClient = await assistantContext.actions.getActionsClientWithRequest(request); + const authenticatedUser = assistantContext.getCurrentUser(); if (authenticatedUser == null) { return response.unauthorized({ @@ -188,6 +191,10 @@ export const postActionsConnectorExecuteRoute = ( } const connectorId = decodeURIComponent(request.params.connectorId); + const connectors = await actionsClient.getBulk({ + ids: [connectorId], + throwIfSystemAction: false, + }); // get the actions plugin start contract from the request context: const actions = (await context.elasticAssistant).actions; @@ -201,12 +208,13 @@ export const postActionsConnectorExecuteRoute = ( actions, request, connectorId, + llmType: connectors[0]?.actionTypeId, params: { subAction: request.body.subAction, subActionParams: { model: request.body.model, messages: [...(prevMessages ?? []), ...(newMessage ? [newMessage] : [])], - ...(request.body.llmType === 'openai' + ...(connectors[0]?.actionTypeId === '.gen-ai' ? { n: 1, stop: null, temperature: 0.2 } : {}), }, diff --git a/x-pack/plugins/elastic_assistant/server/routes/user_conversations/update_route.test.ts b/x-pack/plugins/elastic_assistant/server/routes/user_conversations/update_route.test.ts index 57aceaec745ec..31c5ba2d4a2e5 100644 --- a/x-pack/plugins/elastic_assistant/server/routes/user_conversations/update_route.test.ts +++ b/x-pack/plugins/elastic_assistant/server/routes/user_conversations/update_route.test.ts @@ -121,7 +121,6 @@ describe('Update conversation route', () => { ...getUpdateConversationSchemaMock(), apiConfig: { connectorId: '123', - connectorTypeTitle: 'OpenAI', defaultSystemPromptId: 'test', }, }, diff --git a/x-pack/plugins/security_solution/public/assistant/get_comments/index.test.tsx b/x-pack/plugins/security_solution/public/assistant/get_comments/index.test.tsx index c99d5c1e0d105..88380450974df 100644 --- a/x-pack/plugins/security_solution/public/assistant/get_comments/index.test.tsx +++ b/x-pack/plugins/security_solution/public/assistant/get_comments/index.test.tsx @@ -13,7 +13,6 @@ const user: ConversationRole = 'user'; const currentConversation = { apiConfig: { connectorId: 'c29c28a0-20fe-11ee-9306-a1f4d42ec542', - connectorTypeTitle: 'OpenAI', provider: OpenAiProviderType.OpenAi, }, replacements: [], @@ -49,7 +48,6 @@ describe('getComments', () => { category: 'assistant', apiConfig: { connectorId: 'c29c28a0-20fe-11ee-9306-a1f4d42ec542', - connectorTypeTitle: 'OpenAI', provider: OpenAiProviderType.OpenAi, }, replacements: [], diff --git a/x-pack/plugins/security_solution/public/assistant/get_comments/index.tsx b/x-pack/plugins/security_solution/public/assistant/get_comments/index.tsx index 0b4a2a600a5d1..42fd3f02f8da7 100644 --- a/x-pack/plugins/security_solution/public/assistant/get_comments/index.tsx +++ b/x-pack/plugins/security_solution/public/assistant/get_comments/index.tsx @@ -58,8 +58,7 @@ export const getComments = ({ const regenerateMessageOfConversation = () => { regenerateMessage(currentConversation.id); }; - - const connectorTypeTitle = currentConversation.apiConfig?.connectorTypeTitle ?? ''; + const connectorId = currentConversation.apiConfig?.connectorId ?? ''; const extraLoadingComment = isFetchingResponse ? [ @@ -69,7 +68,7 @@ export const getComments = ({ timestamp: '...', children: ( , children: ( ; @@ -36,6 +41,16 @@ describe('StreamComment', () => { pendingMessage: 'Test Message', setComplete: mockSetComplete, }); + const connectors: unknown[] = [ + { + id: 'hi', + name: 'OpenAI connector', + actionTypeId: '.gen-ai', + }, + ]; + jest.mocked(useFetchConnectorsQuery).mockReturnValue({ + data: connectors, + } as unknown as UseQueryResult>, unknown>); }); it('renders content correctly', () => { render(); diff --git a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/index.tsx b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/index.tsx index 1ee37aa618827..1f9bb9b7bc3c0 100644 --- a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/index.tsx +++ b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/index.tsx @@ -7,6 +7,7 @@ import React, { useEffect, useMemo, useRef } from 'react'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { useFetchConnectorsQuery } from '../../../detection_engine/rule_management/api/hooks/use_fetch_connectors_query'; import type { ContentMessage } from '..'; import { useStream } from './use_stream'; import { StopGeneratingButton } from './buttons/stop_generating_button'; @@ -20,7 +21,7 @@ interface Props { isFetching?: boolean; isControlsEnabled?: boolean; index: number; - connectorTypeTitle: string; + connectorId: string; reader?: ReadableStreamDefaultReader; refetchCurrentConversation: () => void; regenerateMessage: () => void; @@ -29,7 +30,7 @@ interface Props { export const StreamComment = ({ content, - connectorTypeTitle, + connectorId, index, isControlsEnabled = false, isError = false, @@ -39,10 +40,13 @@ export const StreamComment = ({ regenerateMessage, transformMessage, }: Props) => { + const { data: connectors } = useFetchConnectorsQuery(); + const llmType = connectors?.find((c) => c.id === connectorId)?.connector_type_id ?? '.gen-ai'; + const { error, isLoading, isStreaming, pendingMessage, setComplete } = useStream({ refetchCurrentConversation, content, - connectorTypeTitle, + llmType, reader, isError, }); diff --git a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/stream_observable.test.ts b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/stream_observable.test.ts index 54a5684d20442..c37fe502293ab 100644 --- a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/stream_observable.test.ts +++ b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/stream_observable.test.ts @@ -69,7 +69,7 @@ describe('getStreamObservable', () => { }); const source = getStreamObservable({ - connectorTypeTitle: 'Amazon Bedrock', + llmType: '.bedrock', isError: false, reader: typedReader, setLoading, @@ -142,7 +142,7 @@ describe('getStreamObservable', () => { }); const source = getStreamObservable({ - connectorTypeTitle: 'OpenAI', + llmType: '.gen-ai', isError: false, reader: typedReader, setLoading, @@ -215,7 +215,7 @@ describe('getStreamObservable', () => { }); const source = getStreamObservable({ - connectorTypeTitle: 'OpenAI', + llmType: '.gen-ai', isError: false, reader: typedReader, setLoading, @@ -268,7 +268,7 @@ describe('getStreamObservable', () => { }); const source = getStreamObservable({ - connectorTypeTitle: 'OpenAI', + llmType: '.gen-ai', isError: true, reader: typedReader, setLoading, @@ -299,7 +299,7 @@ describe('getStreamObservable', () => { // Simulate an error mockReader.read.mockRejectedValue(error); const source = getStreamObservable({ - connectorTypeTitle: 'OpenAI', + llmType: '.gen-ai', isError: false, reader: typedReader, setLoading, diff --git a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/stream_observable.ts b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/stream_observable.ts index ce7a38811f229..cbd1c518afd9a 100644 --- a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/stream_observable.ts +++ b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/stream_observable.ts @@ -14,7 +14,7 @@ import { API_ERROR } from '../translations'; const MIN_DELAY = 35; interface StreamObservable { - connectorTypeTitle: string; + llmType: string; reader: ReadableStreamDefaultReader; setLoading: Dispatch>; isError: boolean; @@ -28,7 +28,7 @@ interface StreamObservable { * @returns {Observable} An Observable that emits PromptObservableState */ export const getStreamObservable = ({ - connectorTypeTitle, + llmType, isError, reader, setLoading, @@ -163,17 +163,15 @@ export const getStreamObservable = ({ // this should never actually happen function badConnector() { observer.next({ - chunks: [ - `Invalid connector type - ${connectorTypeTitle} is not a supported GenAI connector.`, - ], - message: `Invalid connector type - ${connectorTypeTitle} is not a supported GenAI connector.`, + chunks: [`Invalid connector type - ${llmType} is not a supported GenAI connector.`], + message: `Invalid connector type - ${llmType} is not a supported GenAI connector.`, loading: false, }); observer.complete(); } - if (connectorTypeTitle === 'Amazon Bedrock') readBedrock(); - else if (connectorTypeTitle === 'OpenAI') readOpenAI(); + if (llmType === '.bedrock') readBedrock(); + else if (llmType === '.gen-ai') readOpenAI(); else badConnector(); return () => { diff --git a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/use_stream.test.tsx b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/use_stream.test.tsx index 9545b5db50202..4edf71bd5eda1 100644 --- a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/use_stream.test.tsx +++ b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/use_stream.test.tsx @@ -40,7 +40,7 @@ const defaultProps = { refetchCurrentConversation, reader: readerComplete, isError: false, - connectorTypeTitle: 'OpenAI', + llmType: '.gen-ai', }; describe('useStream', () => { beforeEach(() => { diff --git a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/use_stream.tsx b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/use_stream.tsx index bc75629deaf1a..c351e14d7dfc9 100644 --- a/x-pack/plugins/security_solution/public/assistant/get_comments/stream/use_stream.tsx +++ b/x-pack/plugins/security_solution/public/assistant/get_comments/stream/use_stream.tsx @@ -13,7 +13,7 @@ interface UseStreamProps { refetchCurrentConversation: () => void; isError: boolean; content?: string; - connectorTypeTitle: string; + llmType: string; reader?: ReadableStreamDefaultReader; } interface UseStream { @@ -39,7 +39,7 @@ interface UseStream { */ export const useStream = ({ content, - connectorTypeTitle, + llmType, reader, refetchCurrentConversation, isError, @@ -51,9 +51,9 @@ export const useStream = ({ const observer$ = useMemo( () => content == null && reader != null - ? getStreamObservable({ connectorTypeTitle, reader, setLoading, isError }) + ? getStreamObservable({ llmType, reader, setLoading, isError }) : getPlaceholderObservable(), - [content, isError, reader, connectorTypeTitle] + [content, isError, reader, llmType] ); const onCompleteStream = useCallback(() => { subscription?.unsubscribe(); diff --git a/x-pack/plugins/security_solution/public/assistant/provider.test.tsx b/x-pack/plugins/security_solution/public/assistant/provider.test.tsx index 78c07c847f017..b9a83f12f568f 100644 --- a/x-pack/plugins/security_solution/public/assistant/provider.test.tsx +++ b/x-pack/plugins/security_solution/public/assistant/provider.test.tsx @@ -18,7 +18,6 @@ const conversations = { isDefault: true, apiConfig: { connectorId: 'my-bedrock', - connectorTypeTitle: 'Amazon Bedrock', defaultSystemPromptId: 'default-system-prompt', }, replacements: { @@ -49,7 +48,6 @@ const conversations = { isDefault: true, apiConfig: { connectorId: 'my-gen-ai', - connectorTypeTitle: 'OpenAI', defaultSystemPromptId: 'default-system-prompt', }, messages: [ @@ -105,7 +103,6 @@ const conversations = { }, apiConfig: { connectorId: 'my-gen-ai', - connectorTypeTitle: 'OpenAI', defaultSystemPromptId: 'default-system-prompt', }, messages: [], diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/bedrock.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/bedrock.ts index 3b1cdeffde74e..abf9e435866a1 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/bedrock.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/bedrock.ts @@ -435,7 +435,6 @@ export default function bedrockTest({ getService }: FtrProviderContext) { message: 'Hello world', isEnabledKnowledgeBase: false, isEnabledRAGAlerts: false, - llmType: 'bedrock', replacements: [], }) .pipe(passThrough); diff --git a/x-pack/test/security_solution_api_integration/test_suites/genai/invoke_ai/trial_license_complete_tier/basic.ts b/x-pack/test/security_solution_api_integration/test_suites/genai/invoke_ai/trial_license_complete_tier/basic.ts index 7c83853d5d40a..86477a7277586 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/genai/invoke_ai/trial_license_complete_tier/basic.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/genai/invoke_ai/trial_license_complete_tier/basic.ts @@ -19,7 +19,6 @@ const mockRequest = { subAction: 'invokeAI', isEnabledKnowledgeBase: false, isEnabledRAGAlerts: false, - llmType: 'bedrock', replacements: [], }; @@ -85,7 +84,7 @@ export default ({ getService }: FtrProviderContext) => { it('should execute a chat completion', async () => { const response = await postActionsClientExecute( openaiActionId, - { ...mockRequest, llmType: 'openai' }, + { ...mockRequest }, supertest ); From 3a165855d5a3dd94fc556c869278ff6903c2782d Mon Sep 17 00:00:00 2001 From: Cee Chen <549407+cee-chen@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:06:11 -0700 Subject: [PATCH 02/41] Upgrade EUI to v93.4.0 (#178890) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `v93.3.0`⏩ `v93.4.0` --- ## [`v93.4.0`](https://github.com/elastic/eui/releases/v93.4.0) - Added the following properties to `EuiButtonGroup`'s `options` configs: `toolTipContent`, `toolTipProps`, and `title`. These new properties allow wrapping buttons in `EuiToolTips`, and additionally customizing or disabling the native browser `title` tooltip. ([#7461](https://github.com/elastic/eui/pull/7461)) - Enhanced `EuiResizeObserver` and `useResizeObserver`'s performance to not trigger page reflows on resize event ([#7575](https://github.com/elastic/eui/pull/7575)) - Updated `EuiSuperUpdateButton` to support custom button text via an optional `children` prop ([#7576](https://github.com/elastic/eui/pull/7576)) **Bug fixes** - Fixed `EuiFlyout` to not repeatedly remove/add a body class on resize ([#7462](https://github.com/elastic/eui/pull/7462)) - Fixed `EuiToast` title text to wrap instead of overflowing out of the container ([#7568](https://github.com/elastic/eui/pull/7568)) - Fixed a visual bug with `EuiHeaderBreadcrumbs` with popovers ([#7580](https://github.com/elastic/eui/pull/7580)) **Deprecations** - Deprecated `euiPalettePositive` and `euiPaletteNegative` in favour of a more culturally inclusive `euiPaletteGreen` and `euiPaletteRed` ([#7570](https://github.com/elastic/eui/pull/7570)) - Deprecated all charts theme exports in favor of `@elastic/charts` exports: ([#7572](https://github.com/elastic/eui/pull/7572)) - Deprecated `EUI_CHARTS_THEME_` in favor of `_THEME` from `@elastic/charts`. ([#7572](https://github.com/elastic/eui/pull/7572)) - Deprecated `EUI_SPARKLINE_THEME_PARTIAL` in favor of `useSparklineOverrides` theme from the kibana `charts` plugin `theme` service. **Accessibility** - Updated `EuiModal` to set an `aria-modal` attribute and a default `dialog` role ([#7564](https://github.com/elastic/eui/pull/7564)) - Updated `EuiConfirmModal` to set a default `alertdialog` role ([#7564](https://github.com/elastic/eui/pull/7564)) - Fixed `EuiModal` and `EuiConfirmModal` to properly trap Safari+VoiceOver's virtual cursor ([#7564](https://github.com/elastic/eui/pull/7564)) --- package.json | 2 +- .../ui/header/__snapshots__/header.test.tsx.snap | 2 +- .../__snapshots__/modal_service.test.tsx.snap | 6 ++++++ .../__snapshots__/list_header.test.tsx.snap | 2 ++ .../__snapshots__/edit_modal.test.tsx.snap | 2 ++ src/core/public/styles/_base.scss | 1 - src/dev/license_checker/config.ts | 2 +- .../charts/public/services/palettes/palettes.tsx | 8 ++++---- .../internal_dashboard_top_nav.tsx | 4 ++-- .../apps/dashboard/group1/url_field_formatter.ts | 1 + .../maps/public/classes/styles/color_palettes.ts | 12 ++++++------ .../scatterplot_matrix_vega_lite_spec.ts | 6 +++--- .../application/memory_usage/memory_item_colors.ts | 4 ++-- .../lens_attributes/heatmap_attributes.ts | 4 ++-- .../inventory_view/lib/get_color_palette.ts | 8 ++++---- .../components/header_actions/header_actions.tsx | 14 ++++++++++++-- .../__snapshots__/index.test.tsx.snap | 6 ++++++ .../timelines/bulk_add_to_timeline.cy.ts | 7 ++++++- .../cypress/screens/hosts/events.ts | 6 ++++++ .../cypress/tasks/alerts.ts | 5 +++-- .../cypress/tasks/common/event_table.ts | 10 +++++----- .../cypress/tasks/hosts/events.ts | 7 +++++++ yarn.lock | 8 ++++---- 23 files changed, 86 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index d6a952f436b47..aed319d891fd6 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "@elastic/ecs": "^8.11.1", "@elastic/elasticsearch": "^8.12.2", "@elastic/ems-client": "8.5.1", - "@elastic/eui": "93.3.0", + "@elastic/eui": "93.4.0", "@elastic/filesaver": "1.1.2", "@elastic/node-crypto": "1.2.1", "@elastic/numeral": "^2.5.1", diff --git a/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/header.test.tsx.snap b/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/header.test.tsx.snap index 209e2f1d0c113..f0bae81571603 100644 --- a/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/header.test.tsx.snap +++ b/packages/core/chrome/core-chrome-browser-internal/src/ui/header/__snapshots__/header.test.tsx.snap @@ -194,7 +194,7 @@ Array [ > diff --git a/packages/core/overlays/core-overlays-browser-internal/src/modal/__snapshots__/modal_service.test.tsx.snap b/packages/core/overlays/core-overlays-browser-internal/src/modal/__snapshots__/modal_service.test.tsx.snap index c93fae64cf361..ce53f3fbae63c 100644 --- a/packages/core/overlays/core-overlays-browser-internal/src/modal/__snapshots__/modal_service.test.tsx.snap +++ b/packages/core/overlays/core-overlays-browser-internal/src/modal/__snapshots__/modal_service.test.tsx.snap @@ -129,7 +129,9 @@ exports[`ModalService openConfirm() renders a mountpoint confirm message 2`] = ` data-eui="EuiFocusTrap" >