Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { useLicense } from '../hooks/use_license';
import { PromptEditor } from '../prompt_editor/prompt_editor';
import { deserializeMessage } from '../utils/deserialize_message';
import { useKibana } from '../hooks/use_kibana';
import { useScopes } from '../hooks';

const fullHeightClassName = css`
height: 100%;
Expand Down Expand Up @@ -145,6 +146,8 @@ export function ChatBody({
false
);

const scopes = useScopes();

const { conversation, messages, next, state, stop, saveTitle } = useConversation({
initialConversationId,
initialMessages,
Expand Down Expand Up @@ -216,11 +219,15 @@ export function ChatBody({
conversation: { id, last_updated: lastUpdated, token_count: tokenCount },
};

const connector = connectors.getConnector(connectors.selectedConnector || '');

chatService.sendAnalyticsEvent({
type: ObservabilityAIAssistantTelemetryEventType.ChatFeedback,
payload: {
feedback,
conversation: conversationWithoutMessagesAndTitle,
connector,
scopes,
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('ChatHeader', () => {
error: undefined,
selectConnector: (id: string) => {},
reloadConnectors: () => {},
getConnector: () => undefined,
}}
/>
);
Expand All @@ -96,6 +97,7 @@ describe('ChatHeader', () => {
error: undefined,
selectConnector: (id: string) => {},
reloadConnectors: () => {},
getConnector: () => undefined,
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export function useGenAIConnectors(): UseGenAIConnectorsResult {
selectedConnector: 'foo',
selectConnector: (id: string) => {},
reloadConnectors: () => {},
getConnector: () => undefined,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FunctionListPopover } from '../chat/function_list_popover';
import { PromptEditorFunction } from './prompt_editor_function';
import { PromptEditorNaturalLanguage } from './prompt_editor_natural_language';
import { useScopes } from '../hooks/use_scopes';
import { useGenAIConnectors } from '../hooks';

export interface PromptEditorProps {
disabled: boolean;
Expand All @@ -44,6 +45,7 @@ export function PromptEditor({
onSubmit,
}: PromptEditorProps) {
const scopes = useScopes();
const connectors = useGenAIConnectors();
const containerRef = useRef<HTMLDivElement>(null);

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

setInnerMessage(undefined);
setMode('prompt');
const connector = connectors.getConnector(connectors.selectedConnector || '');
onSendTelemetry({
type: ObservabilityAIAssistantTelemetryEventType.UserSentPromptInChat,
payload: { scopes },
payload: {
scopes,
connector,
},
});
} catch (_) {
setInnerMessage(oldMessage);
setMode(oldMessage.function_call?.name ? 'function' : 'prompt');
}
}, [addLastUsedPrompt, innerMessage, loading, onSendTelemetry, onSubmit, scopes]);
}, [addLastUsedPrompt, innerMessage, loading, onSendTelemetry, onSubmit, scopes, connectors]);

// Submit on Enter
useEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion x-pack/platform/plugins/shared/actions/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export type {
ActionsApiRequestHandlerContext,
} from './types';

export type { ConnectorWithExtraFindData as FindActionResult } from './application/connector/types';
export type {
ConnectorWithExtraFindData as FindActionResult,
Connector,
} from './application/connector/types';

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { type Connector, connectorSchema } from './schemas/connector';
export { type Scope, scopeSchema } from './schemas/scope';
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { RootSchema } from '@kbn/core/public';
import type { InferenceConnector } from '../../utils/get_inference_connector';

export interface Connector {
connector: InferenceConnector | undefined;
}

export const connectorSchema: RootSchema<Connector['connector']> = {
connectorId: {
type: 'text',
_meta: {
description: 'The id of the connector.',
},
},
name: {
type: 'text',
_meta: {
description: 'The name of the connector.',
},
},
type: {
type: 'text',
_meta: {
description: 'The action type id of the connector.',
},
},
modelFamily: {
type: 'text',
_meta: {
description: 'The model family of the connector.',
},
},
modelProvider: {
type: 'text',
_meta: {
description: 'The model provider of the connector.',
},
},
modelId: {
type: 'text',
_meta: {
description: 'The model id of the connector, if applicable.',
optional: true,
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { SchemaValue } from '@kbn/core/public';
import type { AssistantScope } from '@kbn/ai-assistant-common';

export interface Scope {
scopes: AssistantScope[];
}

export const scopeSchema: SchemaValue<AssistantScope[]> = {
type: 'array',
items: {
type: 'text',
_meta: {
description: 'Scope of the AI Assistant',
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { Connector } from '@kbn/actions-plugin/server';
import {
getConnectorProvider,
getConnectorFamily,
getConnectorModel,
connectorToInference,
type InferenceConnectorType,
type ModelFamily,
type ModelProvider,
} from '@kbn/inference-common';

export interface InferenceConnector {
connectorId: string;
name: string;
type: InferenceConnectorType;
modelFamily: ModelFamily;
modelProvider: ModelProvider;
modelId: string | undefined;
}

export const getInferenceConnectorInfo = (
connector?: Connector
): InferenceConnector | undefined => {
if (!connector) {
return;
}
const inferenceConnector = connectorToInference(connector);
const modelFamily = getConnectorFamily(inferenceConnector);
const modelProvider = getConnectorProvider(inferenceConnector);
const modelId = getConnectorModel(inferenceConnector);
return {
connectorId: inferenceConnector.connectorId,
name: inferenceConnector.name,
type: inferenceConnector.type,
modelFamily,
modelProvider,
modelId,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ import type { EventTypeOpts } from '@kbn/core/public';
import type { Conversation } from '../../../common';
import type { Feedback } from '../../components/buttons/feedback_buttons';
import { ObservabilityAIAssistantTelemetryEventType } from '../telemetry_event_type';
import {
type Connector,
type Scope,
connectorSchema,
scopeSchema,
} from '../../../common/analytics';

export interface ChatFeedback {
export interface ChatFeedback extends Connector, Scope {
feedback: Feedback;
conversation: Omit<Omit<Conversation, 'messages'>, 'conversation'> & {
conversation: Omit<Conversation['conversation'], 'title'>;
Expand Down Expand Up @@ -115,5 +121,9 @@ export const chatFeedbackEventSchema: EventTypeOpts<ChatFeedback> = {
},
},
},
connector: {
properties: connectorSchema,
},
scopes: scopeSchema,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
import type { EventTypeOpts } from '@kbn/core/public';
import type { Feedback } from '../../components/buttons/feedback_buttons';
import { ObservabilityAIAssistantTelemetryEventType } from '../telemetry_event_type';
import {
type Connector,
type Scope,
connectorSchema,
scopeSchema,
} from '../../../common/analytics';

export interface InsightFeedback {
export interface InsightFeedback extends Connector, Scope {
feedback: Feedback;
}

Expand All @@ -22,5 +28,9 @@ export const insightFeedbackEventSchema: EventTypeOpts<InsightFeedback> = {
description: 'Whether the user has deemed this response useful or not',
},
},
connector: {
properties: connectorSchema,
},
scopes: scopeSchema,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@

import type { EventTypeOpts } from '@kbn/core/public';
import { ObservabilityAIAssistantTelemetryEventType } from '../telemetry_event_type';
import {
type Connector,
type Scope,
connectorSchema,
scopeSchema,
} from '../../../common/analytics';

export interface InsightResponse {
export interface InsightResponse extends Connector, Scope {
'@timestamp': string;
}

Expand All @@ -21,5 +27,9 @@ export const insightResponseEventSchema: EventTypeOpts<InsightResponse> = {
description: 'The timestamp of the last response from the LLM.',
},
},
connector: {
properties: connectorSchema,
},
scopes: scopeSchema,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
*/

import type { EventTypeOpts } from '@kbn/core/public';
import { AssistantScope } from '@kbn/ai-assistant-common';
import { ObservabilityAIAssistantTelemetryEventType } from '../telemetry_event_type';
import {
type Connector,
type Scope,
connectorSchema,
scopeSchema,
} from '../../../common/analytics';

export interface UserSentPrompt {
scopes: AssistantScope[];
}
export interface UserSentPrompt extends Connector, Scope {}

export const userSentPromptEventSchema: EventTypeOpts<UserSentPrompt> = {
eventType: ObservabilityAIAssistantTelemetryEventType.UserSentPromptInChat,
schema: {
scopes: {
type: 'array',
items: {
type: 'text',
_meta: { description: 'Scope of the AI Assistant' },
},
scopes: scopeSchema,
connector: {
properties: connectorSchema,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function ChatContent({
const service = useObservabilityAIAssistant();
const chatService = useObservabilityAIAssistantChatService();
const scopes = chatService.getScopes();
const connectors = useGenAIConnectors();

const initialMessagesRef = useRef(initialMessages);

Expand All @@ -92,14 +93,17 @@ function ChatContent({

useEffect(() => {
if (state !== ChatState.Loading && lastAssistantResponse) {
const connector = connectors.getConnector(connectors.selectedConnector || '');
chatService.sendAnalyticsEvent({
type: ObservabilityAIAssistantTelemetryEventType.InsightResponse,
payload: {
'@timestamp': lastAssistantResponse['@timestamp'],
connector,
scopes,
},
});
}
}, [state, lastAssistantResponse, chatService]);
}, [state, lastAssistantResponse, chatService, connectors, scopes]);

return (
<>
Expand All @@ -124,10 +128,13 @@ function ChatContent({
<FeedbackButtons
onClickFeedback={(feedback) => {
if (lastAssistantResponse) {
const connector = connectors.getConnector(connectors.selectedConnector || '');
chatService.sendAnalyticsEvent({
type: ObservabilityAIAssistantTelemetryEventType.InsightFeedback,
payload: {
feedback,
connector,
scopes,
},
});
}
Expand Down
Loading