Skip to content

Commit

Permalink
[8.x] [Security Assistant] Conversation pagination refactor (elastic#…
Browse files Browse the repository at this point in the history
…211831) (elastic#212997)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Assistant] Conversation pagination refactor
(elastic#211831)](elastic#211831)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"stephanie.milovic@elastic.co"},"sourceCommit":{"committedDate":"2025-03-03T20:41:20Z","message":"[Security
Assistant] Conversation pagination refactor
(elastic#211831)","sha":"095fc222aa541bf50f57c11958c16eb4c04a282c","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:
SecuritySolution","Team:Security Generative
AI","backport:version","v9.1.0","v8.19.0"],"title":"[Security Assistant]
Conversation pagination
refactor","number":211831,"url":"https://github.com/elastic/kibana/pull/211831","mergeCommit":{"message":"[Security
Assistant] Conversation pagination refactor
(elastic#211831)","sha":"095fc222aa541bf50f57c11958c16eb4c04a282c"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/211831","number":211831,"mergeCommit":{"message":"[Security
Assistant] Conversation pagination refactor
(elastic#211831)","sha":"095fc222aa541bf50f57c11958c16eb4c04a282c"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
stephmilovic authored and SoniaSanzV committed Mar 4, 2025
1 parent 6e858d5 commit 6928a29
Show file tree
Hide file tree
Showing 193 changed files with 4,685 additions and 5,993 deletions.
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

0 comments on commit 6928a29

Please sign in to comment.