Skip to content

Commit

Permalink
Merge branch 'main' into 161754-infra-ui-replace-node-details-flyout-…
Browse files Browse the repository at this point in the history
…with-asset-details-flyout-in-the-inventory-page
  • Loading branch information
jennypavlova authored Sep 25, 2023
2 parents 36d600a + e410533 commit 47449f8
Show file tree
Hide file tree
Showing 73 changed files with 1,673 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { isEmpty, pickBy } from 'lodash';
import moment from 'moment';
import url from 'url';
import type { InfraLocators } from '@kbn/infra-plugin/common/locators';
import type { ProfilingLocators } from '@kbn/profiling-plugin/public';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { AllDatasetsLocatorParams } from '@kbn/deeplinks-observability/locators';
import type { ProfilingLocators } from '@kbn/observability-shared-plugin/public';
import { Environment } from '../../../../common/environment_rt';
import type { Transaction } from '../../../../typings/es_schemas/ui/transaction';
import { getDiscoverHref } from '../links/discover_links/discover_link';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import {
SectionSubtitle,
SectionTitle,
} from '@kbn/observability-shared-plugin/public';
import { ProfilingLocators } from '@kbn/profiling-plugin/public';
import React, { useState } from 'react';
import { useLocation } from 'react-router-dom';
import useAsync from 'react-use/lib/useAsync';
import {
AllDatasetsLocatorParams,
ALL_DATASETS_LOCATOR_ID,
} from '@kbn/deeplinks-observability/locators';
import type { ProfilingLocators } from '@kbn/observability-shared-plugin/public';
import { useAnyOfApmParams } from '../../../hooks/use_apm_params';
import { ApmFeatureFlagName } from '../../../../common/apm_feature_flags';
import { Transaction } from '../../../../typings/es_schemas/ui/transaction';
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/enterprise_search/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { schema, TypeOf } from '@kbn/config-schema';
import { PluginInitializerContext, PluginConfigDescriptor } from '@kbn/core/server';

import { EnterpriseSearchPlugin, EnterpriseSearchPluginStart as PluginStart } from './plugin';
import { EnterpriseSearchPlugin } from './plugin';

export const plugin = (initializerContext: PluginInitializerContext) => {
return new EnterpriseSearchPlugin(initializerContext);
Expand Down Expand Up @@ -54,5 +54,3 @@ export const config: PluginConfigDescriptor<ConfigType> = {
};

export const CRAWLERS_INDEX = '.ent-search-actastic-crawler2_configurations_v2';

export type EnterpriseSearchPluginStart = PluginStart;
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

import { IScopedClusterClient } from '@kbn/core/server';

import { Connector } from '@kbn/search-connectors';

import { CONNECTORS_INDEX } from '../..';
import { CONNECTORS_INDEX, Connector } from '@kbn/search-connectors';

const CUSTOM_SCHEDULING = 'custom_scheduling';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { IScopedClusterClient } from '@kbn/core/server';

import { CONNECTORS_INDEX } from '../..';
import { CONNECTORS_INDEX } from '@kbn/search-connectors';

import {
CrawlerCustomScheduleMappingServer,
Expand Down
28 changes: 22 additions & 6 deletions x-pack/plugins/observability_ai_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import type { FromSchema } from 'json-schema-to-ts';
import type { JSONSchema } from 'json-schema-to-ts';
import React from 'react';
import { Observable } from 'rxjs';

export enum MessageRole {
System = 'system',
Expand All @@ -17,6 +18,12 @@ export enum MessageRole {
Elastic = 'elastic',
}

export interface PendingMessage {
message: Message['message'];
aborted?: boolean;
error?: any;
}

export interface Message {
'@timestamp': string;
message: {
Expand Down Expand Up @@ -74,21 +81,30 @@ export interface ContextDefinition {
description: string;
}

interface FunctionResponse {
content?: any;
data?: any;
type FunctionResponse =
| {
content?: any;
data?: any;
}
| Observable<PendingMessage>;

export enum FunctionVisibility {
System = 'system',
User = 'user',
All = 'all',
}

interface FunctionOptions<TParameters extends CompatibleJSONSchema = CompatibleJSONSchema> {
name: string;
description: string;
descriptionForUser: string;
visibility?: FunctionVisibility;
descriptionForUser?: string;
parameters: TParameters;
contexts: string[];
}

type RespondFunction<TArguments, TResponse extends FunctionResponse> = (
options: { arguments: TArguments; messages: Message[] },
options: { arguments: TArguments; messages: Message[]; connectorId: string },
signal: AbortSignal
) => Promise<TResponse>;

Expand All @@ -100,7 +116,7 @@ type RenderFunction<TArguments, TResponse extends FunctionResponse> = (options:
export interface FunctionDefinition {
options: FunctionOptions;
respond: (
options: { arguments: any; messages: Message[] },
options: { arguments: any; messages: Message[]; connectorId: string },
signal: AbortSignal
) => Promise<FunctionResponse>;
render?: RenderFunction<any, any>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ export function ChatBody({
onFeedback={timeline.onFeedback}
onRegenerate={timeline.onRegenerate}
onStopGenerating={timeline.onStopGenerating}
onActionClick={(payload) => {
setStickToBottom(true);
return timeline.onActionClick(payload);
}}
/>
</EuiPanel>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import { getRoleTranslation } from '../../utils/get_role_translation';
import type { Feedback } from '../feedback_buttons';
import { Message } from '../../../common';
import { FailedToLoadResponse } from '../message_panel/failed_to_load_response';
import { ChatActionClickHandler } from './types';

export interface ChatItemProps extends ChatTimelineItem {
onEditSubmit: (message: Message) => Promise<void>;
onFeedbackClick: (feedback: Feedback) => void;
onRegenerateClick: () => void;
onStopGeneratingClick: () => void;
onActionClick: ChatActionClickHandler;
}

const normalMessageClassName = css`
Expand Down Expand Up @@ -76,6 +78,7 @@ export function ChatItem({
onFeedbackClick,
onRegenerateClick,
onStopGeneratingClick,
onActionClick,
}: ChatItemProps) {
const accordionId = useGeneratedHtmlId({ prefix: 'chat' });

Expand Down Expand Up @@ -128,6 +131,7 @@ export function ChatItem({
functionCall={functionCall}
loading={loading}
onSubmit={handleInlineEditSubmit}
onActionClick={onActionClick}
/>
) : null;

Expand All @@ -147,9 +151,7 @@ export function ChatItem({

return (
<EuiComment
timelineAvatar={
<ChatItemAvatar loading={loading && !content} currentUser={currentUser} role={role} />
}
timelineAvatar={<ChatItemAvatar loading={loading} currentUser={currentUser} role={role} />}
username={getRoleTranslation(role)}
event={title}
actions={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import { MessageText } from '../message_panel/message_text';
import { ChatPromptEditor } from './chat_prompt_editor';
import { MessageRole, type Message } from '../../../common';
import { ChatActionClickHandler } from './types';

interface Props {
content: string | undefined;
Expand All @@ -22,16 +23,18 @@ interface Props {
loading: boolean;
editing: boolean;
onSubmit: (message: Message) => Promise<void>;
onActionClick: ChatActionClickHandler;
}
export function ChatItemContentInlinePromptEditor({
content,
functionCall,
editing,
loading,
onSubmit,
onActionClick,
}: Props) {
return !editing ? (
<MessageText content={content || ''} loading={loading} />
<MessageText content={content || ''} loading={loading} onActionClick={onActionClick} />
) : (
<ChatPromptEditor
disabled={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const defaultProps: ComponentProps<typeof Component> = {
onFeedback: () => {},
onRegenerate: () => {},
onStopGenerating: () => {},
onActionClick: async () => {},
};

export const ChatTimeline = Template.bind({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ChatWelcomePanel } from './chat_welcome_panel';
import type { Feedback } from '../feedback_buttons';
import type { Message } from '../../../common';
import { UseKnowledgeBaseResult } from '../../hooks/use_knowledge_base';
import { ChatActionClickHandler } from './types';

export interface ChatTimelineItem
extends Pick<Message['message'], 'role' | 'content' | 'function_call'> {
Expand Down Expand Up @@ -43,6 +44,7 @@ export interface ChatTimelineProps {
onFeedback: (item: ChatTimelineItem, feedback: Feedback) => void;
onRegenerate: (item: ChatTimelineItem) => void;
onStopGenerating: () => void;
onActionClick: ChatActionClickHandler;
}

export function ChatTimeline({
Expand All @@ -52,6 +54,7 @@ export function ChatTimeline({
onFeedback,
onRegenerate,
onStopGenerating,
onActionClick,
}: ChatTimelineProps) {
const filteredItems = items.filter((item) => !item.display.hide);

Expand All @@ -77,6 +80,7 @@ export function ChatTimeline({
return onEdit(item, message);
}}
onStopGeneratingClick={onStopGenerating}
onActionClick={onActionClick}
/>
))
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@elastic/eui';
import type { EuiSelectableOptionCheckedType } from '@elastic/eui/src/components/selectable/selectable_option';
import { i18n } from '@kbn/i18n';
import type { FunctionDefinition } from '../../../common/types';
import { type FunctionDefinition, FunctionVisibility } from '../../../common/types';
import { useObservabilityAIAssistantChatService } from '../../hooks/use_observability_ai_assistant_chat_service';

interface FunctionListOption {
Expand Down Expand Up @@ -175,12 +175,14 @@ function mapFunctions({
functions: FunctionDefinition[];
selectedFunctionName: string | undefined;
}) {
return functions.map((func) => ({
label: func.options.name,
searchableLabel: func.options.descriptionForUser,
checked:
func.options.name === selectedFunctionName
? ('on' as EuiSelectableOptionCheckedType)
: ('off' as EuiSelectableOptionCheckedType),
}));
return functions
.filter((func) => func.options.visibility !== FunctionVisibility.System)
.map((func) => ({
label: func.options.name,
searchableLabel: func.options.descriptionForUser || func.options.description,
checked:
func.options.name === selectedFunctionName
? ('on' as EuiSelectableOptionCheckedType)
: ('off' as EuiSelectableOptionCheckedType),
}));
}
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.
*/

type ChatActionClickPayloadBase<TType extends ChatActionClickType, TExtraProps extends {}> = {
type: TType;
} & TExtraProps;

type ChatActionClickPayloadExecuteEsql = ChatActionClickPayloadBase<
ChatActionClickType.executeEsqlQuery,
{ query: string }
>;

type ChatActionClickPayload = ChatActionClickPayloadExecuteEsql;

export enum ChatActionClickType {
executeEsqlQuery = 'executeEsqlQuery',
}

export type ChatActionClickHandler = (payload: ChatActionClickPayload) => Promise<unknown>;
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ function ChatContent({
return (
<>
<MessagePanel
body={<MessageText content={lastMessage?.message.content ?? ''} loading={loading} />}
body={
<MessageText
content={lastMessage?.message.content ?? ''}
loading={loading}
onActionClick={async () => {}}
/>
}
error={pendingMessage?.error}
controls={
loading ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Morbi dapibus sapien lacus, vitae suscipit ex egestas pharetra. In velit eros, f
Morbi non faucibus massa. Aliquam sed augue in eros ornare luctus sit amet cursus dolor. Pellentesque pellentesque lorem eu odio auctor convallis. Sed sodales felis at velit tempus tincidunt. Nulla sed ante cursus nibh mollis blandit. In mattis imperdiet tellus. Vestibulum nisl turpis, efficitur quis sollicitudin id, mollis in arcu. Vestibulum pulvinar tincidunt magna, vitae facilisis massa congue quis. Cras commodo efficitur tellus, et commodo risus rutrum at.`}
loading={false}
onActionClick={async () => {}}
/>
}
controls={
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 React from 'react';
import { ComponentMeta, ComponentStoryObj } from '@storybook/react';
import { ComponentProps } from 'react';
import { EuiPanel } from '@elastic/eui';
import { EsqlCodeBlock as Component } from './esql_code_block';

const meta: ComponentMeta<typeof Component> = {
component: Component,
title: 'app/Molecules/ES|QL Code Block',
};

export default meta;

const render = (props: ComponentProps<typeof Component>) => {
return (
<EuiPanel hasBorder hasShadow={false}>
<Component {...props} />
</EuiPanel>
);
};

export const Simple: ComponentStoryObj<typeof Component> = {
args: {
value: `FROM packetbeat-*
| STATS COUNT_DISTINCT(destination.domain)`,
},
render,
};
Loading

0 comments on commit 47449f8

Please sign in to comment.