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

[Security Assistant] Conversation pagination refactor #211831

Merged
merged 100 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
5d6161c
remove base conversations
stephmilovic Feb 6, 2025
4453b31
test fixing
stephmilovic Feb 6, 2025
35933e4
rm isDefault param
stephmilovic Feb 6, 2025
840869f
more, working
stephmilovic Feb 7, 2025
5640671
date category
stephmilovic Feb 10, 2025
465f5ae
Merge branch 'main' into convo_pagination
stephmilovic Feb 10, 2025
b4a9ad8
minimal field fetching
stephmilovic Feb 10, 2025
768fcee
infinite query
stephmilovic Feb 11, 2025
2c4a586
type fixing
stephmilovic Feb 11, 2025
e2ddd2d
management wip
stephmilovic Feb 12, 2025
bbc762c
progress
stephmilovic Feb 13, 2025
584ef5a
fixes
stephmilovic Feb 13, 2025
9af0a98
slowly, slowly
stephmilovic Feb 14, 2025
984805f
system prompt close
stephmilovic Feb 14, 2025
3ae8d77
better
stephmilovic Feb 14, 2025
734395d
type wrestling
stephmilovic Feb 18, 2025
adb6708
conversations settings table fix
stephmilovic Feb 18, 2025
4647797
quick prompt management cleanup
stephmilovic Feb 18, 2025
6a0ff13
kb settings
stephmilovic Feb 18, 2025
a3339bb
attack discovery invoke
stephmilovic Feb 18, 2025
624872c
lastConversationId => lastConversation
stephmilovic Feb 19, 2025
49fce1c
better
stephmilovic Feb 19, 2025
ec79d13
unique conversation names for alerts/events
stephmilovic Feb 19, 2025
a891f48
Merge branch 'main' into convo_pagination
stephmilovic Feb 19, 2025
85e319c
prompt context fix
stephmilovic Feb 19, 2025
c6e83ee
DQD
stephmilovic Feb 19, 2025
0b0a84d
rule toolbar + rule status failed
stephmilovic Feb 19, 2025
65323ba
better
stephmilovic Feb 19, 2025
26c8f89
revert new chat by title changes
stephmilovic Feb 19, 2025
b586e99
unrevert
stephmilovic Feb 19, 2025
0d523a9
Merge branch 'main' into convo_pagination
stephmilovic Feb 20, 2025
8d59721
anon updater
stephmilovic Feb 20, 2025
ca47324
anon updater
stephmilovic Feb 20, 2025
37cc51a
fix prompt context
stephmilovic Feb 20, 2025
eea73d1
alert settings modal
stephmilovic Feb 20, 2025
d2f0085
modal refactor
stephmilovic Feb 20, 2025
acdc2c9
system prompt fixing
stephmilovic Feb 20, 2025
87c4494
deleted unused definitions
stephmilovic Feb 20, 2025
e3ccc69
cleanup
stephmilovic Feb 20, 2025
8966acf
add pagination observer to system prompt conversation menu
stephmilovic Feb 21, 2025
126bbd8
test/types
stephmilovic Feb 21, 2025
f173681
more tests
stephmilovic Feb 21, 2025
521281a
test fixing
stephmilovic Feb 21, 2025
8961f2f
Merge branch 'main' into convo_pagination
stephmilovic Feb 21, 2025
ae45ca0
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Feb 21, 2025
ee46ab3
[CI] Auto-commit changed files from 'yarn openapi:bundle'
kibanamachine Feb 21, 2025
66c2444
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Feb 21, 2025
c27ddbe
fix translation and lint
stephmilovic Feb 21, 2025
d8d74e3
fix tanstack import
stephmilovic Feb 21, 2025
f9aa064
Merge branch 'convo_pagination' of github.com:stephmilovic/kibana int…
stephmilovic Feb 21, 2025
7b241c2
type fix
stephmilovic Feb 21, 2025
b2a646b
fix more type
stephmilovic Feb 21, 2025
753eca6
Merge branch 'main' into convo_pagination
stephmilovic Feb 21, 2025
a98afcf
fix translations
stephmilovic Feb 21, 2025
950a97e
fixes
stephmilovic Feb 22, 2025
3786f91
skip
stephmilovic Feb 22, 2025
51b3495
fix cypress serverless
stephmilovic Feb 24, 2025
8c48cde
Merge branch 'main' into convo_pagination
stephmilovic Feb 24, 2025
c4ba41c
more cypress
stephmilovic Feb 24, 2025
45b48cf
unskip conversation cypress
stephmilovic Feb 24, 2025
8c36b93
Refactored create conversations script to use Elasticsearch client AP…
stephmilovic Feb 24, 2025
5237974
[CI] Auto-commit changed files from 'yarn openapi:bundle'
kibanamachine Feb 24, 2025
1066feb
more tests
stephmilovic Feb 24, 2025
012a26a
Merge branch 'convo_pagination' of github.com:stephmilovic/kibana int…
stephmilovic Feb 24, 2025
946525c
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Feb 24, 2025
2df74c4
useCb
stephmilovic Feb 24, 2025
263e838
fix
stephmilovic Feb 24, 2025
1fa102e
id to ''
stephmilovic Feb 24, 2025
a01aad0
Merge branch 'convo_pagination' of github.com:stephmilovic/kibana int…
stephmilovic Feb 24, 2025
c756d20
lint fix
stephmilovic Feb 25, 2025
f7ed3da
rm log
stephmilovic Feb 25, 2025
0ba887c
always refetch after chat send
stephmilovic Feb 25, 2025
4e4c963
DQD updates
stephmilovic Feb 25, 2025
62d6e91
type fix
stephmilovic Feb 25, 2025
958dbbc
Merge branch 'main' into convo_pagination
stephmilovic Feb 25, 2025
2136e97
system prompt fix
stephmilovic Feb 25, 2025
8c8a77b
fix type
stephmilovic Feb 25, 2025
d7e6ad6
use snakeCase from lodash
stephmilovic Feb 25, 2025
397fa53
PR comments
stephmilovic Feb 25, 2025
4657855
i18n
stephmilovic Feb 25, 2025
0d8876b
feat: reverting DQD comment suggestions with tweaks
kapral18 Feb 26, 2025
f7f905c
fix quick prompts
stephmilovic Feb 26, 2025
bc10348
Merge branch 'main' into convo_pagination
elasticmachine Feb 26, 2025
f92589a
Merge branch 'main' into convo_pagination
stephmilovic Feb 26, 2025
b7e23af
Merge branch 'main' into convo_pagination
elasticmachine Feb 26, 2025
134d9dc
better error handling
stephmilovic Feb 26, 2025
767e766
Merge branch 'convo_pagination' of github.com:stephmilovic/kibana int…
stephmilovic Feb 26, 2025
a47544e
Merge branch 'main' into convo_pagination
stephmilovic Feb 26, 2025
c3b0d44
fix streaming save
stephmilovic Feb 26, 2025
3dc557f
some system prompt fixes
stephmilovic Feb 27, 2025
bb88cd9
Merge branch 'main' into convo_pagination
elasticmachine Feb 27, 2025
00cfadb
memoize current user conversation data
stephmilovic Feb 27, 2025
d7a240b
Merge branch 'convo_pagination' of github.com:stephmilovic/kibana int…
stephmilovic Feb 27, 2025
3eb4780
test fix
stephmilovic Feb 27, 2025
f7d1eb1
Merge branch 'main' into convo_pagination
elasticmachine Mar 3, 2025
deeadfe
fix
stephmilovic Mar 3, 2025
8347cd8
Merge branch 'convo_pagination' of github.com:stephmilovic/kibana int…
stephmilovic Mar 3, 2025
97d1b18
Merge branch 'main' into convo_pagination
stephmilovic Mar 3, 2025
d73450f
lint
stephmilovic Mar 3, 2025
93d8e62
other spots
stephmilovic Mar 3, 2025
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
12 changes: 4 additions & 8 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44793,15 +44793,15 @@ components:
category:
$ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory'
description: The conversation category.
createdAt:
description: Set the creation date.
type: string
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
id:
description: The conversation id.
type: string
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand All @@ -44824,16 +44824,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 @@ -45051,7 +45048,6 @@ components:
Security_AI_Assistant_API_FindConversationsSortField:
enum:
- created_at
- is_default
- title
- updated_at
type: string
Expand Down
12 changes: 4 additions & 8 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51370,15 +51370,15 @@ components:
category:
$ref: '#/components/schemas/Security_AI_Assistant_API_ConversationCategory'
description: The conversation category.
createdAt:
description: Set the creation date.
type: string
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
id:
description: The conversation id.
type: string
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand All @@ -51401,16 +51401,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 @@ -51628,7 +51625,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 @@ -1173,15 +1173,15 @@ components:
category:
$ref: '#/components/schemas/ConversationCategory'
description: The conversation category.
createdAt:
description: Set the creation date.
type: string
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
id:
description: The conversation id.
type: string
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand All @@ -1204,16 +1204,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 @@ -1441,7 +1438,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 @@ -1173,15 +1173,15 @@ components:
category:
$ref: '#/components/schemas/ConversationCategory'
description: The conversation category.
createdAt:
description: Set the creation date.
type: string
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
id:
description: The conversation id.
type: string
isDefault:
description: Is default conversation.
type: boolean
messages:
description: The conversation messages.
items:
Expand All @@ -1204,16 +1204,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 @@ -1441,7 +1438,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,15 +399,15 @@ export const ConversationCreateProps = z.object({
* LLM API configuration.
*/
apiConfig: ApiConfig.optional(),
/**
* Is default conversation.
*/
isDefault: z.boolean().optional(),
/**
* excludeFromLastConversationStorage.
*/
excludeFromLastConversationStorage: z.boolean().optional(),
replacements: Replacements.optional(),
/**
* Set the creation date.
*/
createdAt: z.string().optional(),
});

export type ConversationMessageCreateProps = z.infer<typeof ConversationMessageCreateProps>;
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
Comment on lines -335 to -337
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WRT API breaking changes since the Conversations API is already public -- this is only an issue if it's still included as request validation with fail, correct? This seems fine given adoption and functionality here, so if anything maybe we just make a note to mention in the release notes?

excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
Expand Down Expand Up @@ -393,14 +390,14 @@ components:
apiConfig:
$ref: '#/components/schemas/ApiConfig'
description: LLM API configuration.
isDefault:
description: Is default conversation.
type: boolean
excludeFromLastConversationStorage:
description: excludeFromLastConversationStorage.
type: boolean
replacements:
$ref: '#/components/schemas/Replacements'
createdAt:
description: Set the creation date.
type: string

ConversationMessageCreateProps:
type: object
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'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: due to this change in only returning a subset of fields, the users array will now appear empty, ala:

image

Discussed w/ @stephmilovic, and we may want to remove users as an empty array from the response since this usually indicates a global resource (at least in the sense of the KB entries). The route has current_user in it, so probably not a big deal and should be clear to consumers, but something to consider if/when we add support for global/shared conversations.

filter: undefined,
per_page: 28,
sort_field: 'updated_at',
sort_order: 'desc',
},
version: '2023-10-31',
signal: undefined,
}
);

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