Skip to content

Commit d3385ab

Browse files
committed
Add connector and scope information to Obs AI Assistant EBT events (elastic#234550)
Closes elastic#232546 ## Summary Add connector and scope information to Obs AI Assistant EBT events ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... (cherry picked from commit b3a75dc) # Conflicts: # packages/kbn-optimizer/limits.yml # x-pack/platform/packages/shared/kbn-ai-assistant/src/chat/chat_body.tsx # x-pack/platform/packages/shared/kbn-ai-assistant/src/chat/chat_header.test.tsx # x-pack/platform/packages/shared/kbn-ai-assistant/src/chat/welcome_message.test.tsx # x-pack/platform/plugins/shared/observability_ai_assistant/public/analytics/schemas/user_sent_prompt.ts # x-pack/platform/plugins/shared/observability_ai_assistant/server/analytics/recall_ranking.ts # x-pack/platform/plugins/shared/observability_ai_assistant/server/functions/context.ts # x-pack/platform/plugins/shared/observability_ai_assistant/server/functions/context/utils/recall_and_score.test.ts # x-pack/platform/plugins/shared/observability_ai_assistant/server/functions/context/utils/recall_and_score.ts # x-pack/platform/plugins/shared/observability_ai_assistant/server/routes/chat/route.ts
1 parent a920abe commit d3385ab

File tree

20 files changed

+252
-23
lines changed

20 files changed

+252
-23
lines changed

x-pack/platform/packages/shared/kbn-ai-assistant/src/chat/chat_body.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { useLicense } from '../hooks/use_license';
5050
import { PromptEditor } from '../prompt_editor/prompt_editor';
5151
import { deserializeMessage } from '../utils/deserialize_message';
5252
import { useKibana } from '../hooks/use_kibana';
53+
import { useScopes } from '../hooks';
5354

5455
const fullHeightClassName = css`
5556
height: 100%;
@@ -145,6 +146,8 @@ export function ChatBody({
145146
false
146147
);
147148

149+
const scopes = useScopes();
150+
148151
const { conversation, messages, next, state, stop, saveTitle } = useConversation({
149152
initialConversationId,
150153
initialMessages,
@@ -216,11 +219,15 @@ export function ChatBody({
216219
conversation: { id, last_updated: lastUpdated, token_count: tokenCount },
217220
};
218221

222+
const connector = connectors.getConnector(connectors.selectedConnector || '');
223+
219224
chatService.sendAnalyticsEvent({
220225
type: ObservabilityAIAssistantTelemetryEventType.ChatFeedback,
221226
payload: {
222227
feedback,
223228
conversation: conversationWithoutMessagesAndTitle,
229+
connector,
230+
scopes,
224231
},
225232
});
226233
}

x-pack/platform/packages/shared/kbn-ai-assistant/src/chat/chat_header.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe('ChatHeader', () => {
7474
error: undefined,
7575
selectConnector: (id: string) => {},
7676
reloadConnectors: () => {},
77+
getConnector: () => undefined,
7778
}}
7879
/>
7980
);
@@ -96,6 +97,7 @@ describe('ChatHeader', () => {
9697
error: undefined,
9798
selectConnector: (id: string) => {},
9899
reloadConnectors: () => {},
100+
getConnector: () => undefined,
99101
}}
100102
/>
101103
);

x-pack/platform/packages/shared/kbn-ai-assistant/src/hooks/__storybook_mocks__/use_genai_connectors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ export function useGenAIConnectors(): UseGenAIConnectorsResult {
1515
selectedConnector: 'foo',
1616
selectConnector: (id: string) => {},
1717
reloadConnectors: () => {},
18+
getConnector: () => undefined,
1819
};
1920
}

x-pack/platform/packages/shared/kbn-ai-assistant/src/prompt_editor/prompt_editor.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { FunctionListPopover } from '../chat/function_list_popover';
1919
import { PromptEditorFunction } from './prompt_editor_function';
2020
import { PromptEditorNaturalLanguage } from './prompt_editor_natural_language';
2121
import { useScopes } from '../hooks/use_scopes';
22+
import { useGenAIConnectors } from '../hooks';
2223

2324
export interface PromptEditorProps {
2425
disabled: boolean;
@@ -44,6 +45,7 @@ export function PromptEditor({
4445
onSubmit,
4546
}: PromptEditorProps) {
4647
const scopes = useScopes();
48+
const connectors = useGenAIConnectors();
4749
const containerRef = useRef<HTMLDivElement>(null);
4850

4951
const [mode, setMode] = useState<'prompt' | 'function'>(
@@ -123,15 +125,19 @@ export function PromptEditor({
123125

124126
setInnerMessage(undefined);
125127
setMode('prompt');
128+
const connector = connectors.getConnector(connectors.selectedConnector || '');
126129
onSendTelemetry({
127130
type: ObservabilityAIAssistantTelemetryEventType.UserSentPromptInChat,
128-
payload: { scopes },
131+
payload: {
132+
scopes,
133+
connector,
134+
},
129135
});
130136
} catch (_) {
131137
setInnerMessage(oldMessage);
132138
setMode(oldMessage.function_call?.name ? 'function' : 'prompt');
133139
}
134-
}, [addLastUsedPrompt, innerMessage, loading, onSendTelemetry, onSubmit, scopes]);
140+
}, [addLastUsedPrompt, innerMessage, loading, onSendTelemetry, onSubmit, scopes, connectors]);
135141

136142
// Submit on Enter
137143
useEffect(() => {

x-pack/platform/plugins/shared/actions/server/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export type {
2525
ActionsApiRequestHandlerContext,
2626
} from './types';
2727

28-
export type { ConnectorWithExtraFindData as FindActionResult } from './application/connector/types';
28+
export type {
29+
ConnectorWithExtraFindData as FindActionResult,
30+
Connector,
31+
} from './application/connector/types';
2932

3033
export type { PluginSetupContract, PluginStartContract } from './plugin';
3134

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
export { type Connector, connectorSchema } from './schemas/connector';
9+
export { type Scope, scopeSchema } from './schemas/scope';
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { RootSchema } from '@kbn/core/public';
9+
import type { InferenceConnector } from '../../utils/get_inference_connector';
10+
11+
export interface Connector {
12+
connector: InferenceConnector | undefined;
13+
}
14+
15+
export const connectorSchema: RootSchema<Connector['connector']> = {
16+
connectorId: {
17+
type: 'text',
18+
_meta: {
19+
description: 'The id of the connector.',
20+
},
21+
},
22+
name: {
23+
type: 'text',
24+
_meta: {
25+
description: 'The name of the connector.',
26+
},
27+
},
28+
type: {
29+
type: 'text',
30+
_meta: {
31+
description: 'The action type id of the connector.',
32+
},
33+
},
34+
modelFamily: {
35+
type: 'text',
36+
_meta: {
37+
description: 'The model family of the connector.',
38+
},
39+
},
40+
modelProvider: {
41+
type: 'text',
42+
_meta: {
43+
description: 'The model provider of the connector.',
44+
},
45+
},
46+
modelId: {
47+
type: 'text',
48+
_meta: {
49+
description: 'The model id of the connector, if applicable.',
50+
optional: true,
51+
},
52+
},
53+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { SchemaValue } from '@kbn/core/public';
9+
import type { AssistantScope } from '@kbn/ai-assistant-common';
10+
11+
export interface Scope {
12+
scopes: AssistantScope[];
13+
}
14+
15+
export const scopeSchema: SchemaValue<AssistantScope[]> = {
16+
type: 'array',
17+
items: {
18+
type: 'text',
19+
_meta: {
20+
description: 'Scope of the AI Assistant',
21+
},
22+
},
23+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { Connector } from '@kbn/actions-plugin/server';
9+
import {
10+
getConnectorProvider,
11+
getConnectorFamily,
12+
getConnectorModel,
13+
connectorToInference,
14+
type InferenceConnectorType,
15+
type ModelFamily,
16+
type ModelProvider,
17+
} from '@kbn/inference-common';
18+
19+
export interface InferenceConnector {
20+
connectorId: string;
21+
name: string;
22+
type: InferenceConnectorType;
23+
modelFamily: ModelFamily;
24+
modelProvider: ModelProvider;
25+
modelId: string | undefined;
26+
}
27+
28+
export const getInferenceConnectorInfo = (
29+
connector?: Connector
30+
): InferenceConnector | undefined => {
31+
if (!connector) {
32+
return;
33+
}
34+
const inferenceConnector = connectorToInference(connector);
35+
const modelFamily = getConnectorFamily(inferenceConnector);
36+
const modelProvider = getConnectorProvider(inferenceConnector);
37+
const modelId = getConnectorModel(inferenceConnector);
38+
return {
39+
connectorId: inferenceConnector.connectorId,
40+
name: inferenceConnector.name,
41+
type: inferenceConnector.type,
42+
modelFamily,
43+
modelProvider,
44+
modelId,
45+
};
46+
};

x-pack/platform/plugins/shared/observability_ai_assistant/public/analytics/schemas/chat_feedback.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ import type { EventTypeOpts } from '@kbn/core/public';
99
import type { Conversation } from '../../../common';
1010
import type { Feedback } from '../../components/buttons/feedback_buttons';
1111
import { ObservabilityAIAssistantTelemetryEventType } from '../telemetry_event_type';
12+
import {
13+
type Connector,
14+
type Scope,
15+
connectorSchema,
16+
scopeSchema,
17+
} from '../../../common/analytics';
1218

13-
export interface ChatFeedback {
19+
export interface ChatFeedback extends Connector, Scope {
1420
feedback: Feedback;
1521
conversation: Omit<Omit<Conversation, 'messages'>, 'conversation'> & {
1622
conversation: Omit<Conversation['conversation'], 'title'>;
@@ -115,5 +121,9 @@ export const chatFeedbackEventSchema: EventTypeOpts<ChatFeedback> = {
115121
},
116122
},
117123
},
124+
connector: {
125+
properties: connectorSchema,
126+
},
127+
scopes: scopeSchema,
118128
},
119129
};

0 commit comments

Comments
 (0)