Skip to content

Commit 0868925

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/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/utils/recall_and_score.ts
1 parent 456ae8c commit 0868925

File tree

24 files changed

+281
-26
lines changed

24 files changed

+281
-26
lines changed

packages/kbn-optimizer/limits.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pageLoadAssetSize:
106106
newsfeed: 12371
107107
noDataPage: 1749
108108
observability: 107869
109-
observabilityAIAssistant: 46941
109+
observabilityAIAssistant: 52565
110110
observabilityAIAssistantApp: 18553
111111
observabilityAiAssistantManagement: 6438
112112
observabilityLogsExplorer: 4918

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import { useLicense } from '../hooks/use_license';
5757
import { PromptEditor } from '../prompt_editor/prompt_editor';
5858
import { useKibana } from '../hooks/use_kibana';
5959
import { ChatBanner } from './chat_banner';
60-
import { useConversationContextMenu } from '../hooks';
60+
import { useConversationContextMenu, useScopes } from '../hooks';
6161

6262
const fullHeightClassName = css`
6363
height: 100%;
@@ -167,6 +167,8 @@ export function ChatBody({
167167
false
168168
);
169169

170+
const scopes = useScopes();
171+
170172
const {
171173
conversation,
172174
conversationId,
@@ -247,11 +249,15 @@ export function ChatBody({
247249
conversation: { id, last_updated: lastUpdated },
248250
};
249251

252+
const connector = connectors.getConnector(connectors.selectedConnector || '');
253+
250254
chatService.sendAnalyticsEvent({
251255
type: ObservabilityAIAssistantTelemetryEventType.ChatFeedback,
252256
payload: {
253257
feedback,
254258
conversation: conversationWithoutMessagesAndTitle,
259+
connector,
260+
scopes,
255261
},
256262
});
257263
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ describe('ChatHeader', () => {
104104
error: undefined,
105105
selectConnector: (id: string) => {},
106106
reloadConnectors: () => {},
107+
getConnector: () => undefined,
107108
}}
108109
/>
109110
);
@@ -126,6 +127,7 @@ describe('ChatHeader', () => {
126127
error: undefined,
127128
selectConnector: (id: string) => {},
128129
reloadConnectors: () => {},
130+
getConnector: () => undefined,
129131
}}
130132
/>
131133
);
@@ -152,6 +154,7 @@ describe('ChatHeader', () => {
152154
error: undefined,
153155
selectConnector: (id: string) => {},
154156
reloadConnectors: () => {},
157+
getConnector: () => undefined,
155158
}}
156159
/>
157160
);
@@ -178,6 +181,7 @@ describe('ChatHeader', () => {
178181
error: undefined,
179182
selectConnector: (id: string) => {},
180183
reloadConnectors: () => {},
184+
getConnector: () => undefined,
181185
}}
182186
/>
183187
);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const mockConnectors: UseGenAIConnectorsResult = {
2828
selectedConnector: 'test-connector',
2929
selectConnector: jest.fn(),
3030
reloadConnectors: jest.fn(),
31+
getConnector: jest.fn(),
3132
};
3233

3334
jest.mock('@kbn/kibana-react-plugin/public', () => ({

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
@@ -17,6 +17,7 @@ import { useLastUsedPrompts } from '../hooks/use_last_used_prompts';
1717
import { PromptEditorFunction } from './prompt_editor_function';
1818
import { PromptEditorNaturalLanguage } from './prompt_editor_natural_language';
1919
import { useScopes } from '../hooks/use_scopes';
20+
import { useGenAIConnectors } from '../hooks';
2021

2122
export interface PromptEditorProps {
2223
disabled: boolean;
@@ -42,6 +43,7 @@ export function PromptEditor({
4243
onSubmit,
4344
}: PromptEditorProps) {
4445
const scopes = useScopes();
46+
const connectors = useGenAIConnectors();
4547
const containerRef = useRef<HTMLDivElement>(null);
4648

4749
const [mode, setMode] = useState<'prompt' | 'function'>(
@@ -102,15 +104,19 @@ export function PromptEditor({
102104

103105
setInnerMessage(undefined);
104106
setMode('prompt');
107+
const connector = connectors.getConnector(connectors.selectedConnector || '');
105108
onSendTelemetry({
106109
type: ObservabilityAIAssistantTelemetryEventType.UserSentPromptInChat,
107-
payload: { scopes },
110+
payload: {
111+
scopes,
112+
connector,
113+
},
108114
});
109115
} catch (_) {
110116
setInnerMessage(oldMessage);
111117
setMode(oldMessage.function_call?.name ? 'function' : 'prompt');
112118
}
113-
}, [addLastUsedPrompt, innerMessage, loading, onSendTelemetry, onSubmit, scopes]);
119+
}, [addLastUsedPrompt, innerMessage, loading, onSendTelemetry, onSubmit, scopes, connectors]);
114120

115121
// Submit on Enter
116122
useEffect(() => {

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

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

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

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

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+
};

0 commit comments

Comments
 (0)