Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [Security Assistant] Conversation pagination refactor (#211831) #212997

Merged
merged 2 commits into from
Mar 4, 2025
Merged
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
9 changes: 1 addition & 8 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40577,9 +40577,6 @@ components:
id:
description: The conversation id.
type: string
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand All @@ -40602,16 +40599,13 @@ components:
$ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory'
description: The conversation category.
createdAt:
description: The last time conversation was updated.
description: The time conversation was created.
type: string
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
id:
$ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString'
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand Down Expand Up @@ -40838,7 +40832,6 @@ components:
Security_AI_Assistant_API_FindConversationsSortField:
enum:
- created_at
- is_default
- title
- updated_at
type: string
Expand Down
9 changes: 1 addition & 8 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28763,9 +28763,6 @@ components:
id:
description: The conversation id.
type: string
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand All @@ -28788,16 +28785,13 @@ components:
$ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory'
description: The conversation category.
createdAt:
description: The last time conversation was updated.
description: The time conversation was created.
type: string
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
id:
$ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString'
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand Down Expand Up @@ -29024,7 +29018,6 @@ components:
Security_AI_Assistant_API_FindConversationsSortField:
enum:
- created_at
- is_default
- title
- updated_at
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,6 @@ components:
id:
description: The conversation id.
type: string
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand All @@ -1204,16 +1201,13 @@ components:
$ref: '#/components/schemas/ConversationCategory'
description: The conversation category.
createdAt:
description: The last time conversation was updated.
description: The time conversation was created.
type: string
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
id:
$ref: '#/components/schemas/NonEmptyString'
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand Down Expand Up @@ -1448,7 +1442,6 @@ components:
FindConversationsSortField:
enum:
- created_at
- is_default
- title
- updated_at
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,6 @@ components:
id:
description: The conversation id.
type: string
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand All @@ -1204,16 +1201,13 @@ components:
$ref: '#/components/schemas/ConversationCategory'
description: The conversation category.
createdAt:
description: The last time conversation was updated.
description: The time conversation was created.
type: string
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
id:
$ref: '#/components/schemas/NonEmptyString'
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand Down Expand Up @@ -1448,7 +1442,6 @@ components:
FindConversationsSortField:
enum:
- created_at
- is_default
- title
- updated_at
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export const ConversationResponse = z.object({
*/
updatedAt: z.string().optional(),
/**
* The last time conversation was updated.
* The time conversation was created.
*/
createdAt: z.string(),
replacements: Replacements.optional(),
Expand All @@ -340,10 +340,6 @@ export const ConversationResponse = z.object({
* LLM API configuration.
*/
apiConfig: ApiConfig.optional(),
/**
* Is default conversation.
*/
isDefault: z.boolean().optional(),
/**
* excludeFromLastConversationStorage.
*/
Expand Down Expand Up @@ -403,10 +399,6 @@ export const ConversationCreateProps = z.object({
* LLM API configuration.
*/
apiConfig: ApiConfig.optional(),
/**
* Is default conversation.
*/
isDefault: z.boolean().optional(),
/**
* excludeFromLastConversationStorage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ components:
description: The last time conversation was updated.
type: string
createdAt:
description: The last time conversation was updated.
description: The time conversation was created.
type: string
replacements:
$ref: '#/components/schemas/Replacements'
Expand All @@ -332,9 +332,6 @@ components:
apiConfig:
$ref: '#/components/schemas/ApiConfig'
description: LLM API configuration.
isDefault:
description: Is default conversation.
type: boolean
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
Expand Down Expand Up @@ -393,9 +390,6 @@ components:
apiConfig:
$ref: '#/components/schemas/ApiConfig'
description: LLM API configuration.
isDefault:
description: Is default conversation.
type: boolean
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ import { SortOrder } from '../common_attributes.gen';
import { ConversationResponse } from './common_attributes.gen';

export type FindConversationsSortField = z.infer<typeof FindConversationsSortField>;
export const FindConversationsSortField = z.enum([
'created_at',
'is_default',
'title',
'updated_at',
]);
export const FindConversationsSortField = z.enum(['created_at', 'title', 'updated_at']);
export type FindConversationsSortFieldEnum = typeof FindConversationsSortField.enum;
export const FindConversationsSortFieldEnum = FindConversationsSortField.enum;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,5 @@ components:
type: string
enum:
- 'created_at'
- 'is_default'
- 'title'
- 'updated_at'
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,40 @@ export const getConversationById = async ({
};

/**
* API call for getting all user conversations.
* API call for determining whether any user conversations exist
*
* @param {Object} options - The options object.
* @param {HttpSetup} options.http - HttpSetup
* @param {IToasts} [options.toasts] - IToasts
* @param {AbortSignal} [options.signal] - AbortSignal
*
* @returns {Promise<FetchConversationsResponse>}
* @returns {Promise<boolean>}
*/
export const getUserConversations = async ({
export const getUserConversationsExist = async ({
http,
signal,
toasts,
}: {
http: HttpSetup;
toasts?: IToasts;
signal?: AbortSignal | undefined;
}) => {
}): Promise<boolean> => {
try {
return await http.fetch<FetchConversationsResponse>(
const conversation = await http.fetch<FetchConversationsResponse>(
ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_FIND,
{
method: 'GET',
version: API_VERSIONS.public.v1,
signal,
query: {
per_page: 1,
page: 1,
// one field to keep request as small as possible
fields: ['title'],
},
}
);

return conversation.total > 0;
} catch (error) {
toasts?.addError(error.body && error.body.message ? new Error(error.body.message) : error, {
title: i18n.translate('xpack.elasticAssistant.conversations.getUserConversationsError', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ import { defaultAssistantFeatures } from '@kbn/elastic-assistant-common';
const http = {
fetch: jest.fn().mockResolvedValue(defaultAssistantFeatures),
};
const onFetch = jest.fn();

const defaultProps = {
http,
onFetch,
isAssistantEnabled: true,
} as unknown as UseFetchCurrentUserConversationsParams;

Expand All @@ -48,14 +45,16 @@ describe('useFetchCurrentUserConversations', () => {
method: 'GET',
query: {
page: 1,
per_page: 99,
fields: ['id', 'title', 'apiConfig', 'updatedAt'],
filter: undefined,
per_page: 28,
sort_field: 'updated_at',
sort_order: 'desc',
},
version: '2023-10-31',
signal: undefined,
}
);

expect(onFetch).toHaveBeenCalled();
});
});
});
Loading