Skip to content

Commit

Permalink
[Security AI Assistant] Changing chat related internal APIs to become…
Browse files Browse the repository at this point in the history
… public (elastic#188139)

## Summary

In this PR Security Gen AI related APIs are changed from internal to
public.

Conversations APIs:
- POST/PUT/GET/DELETE
`"/api/security_ai_assistant/current_user/conversations/{id}"`
- GET `"/api/security_ai_assistant/current_user/conversations/_find"`

Prompts APIs:

- POST `"/api/security_ai_assistant/prompts/_bulk_action"`
- GET `"/api/security_ai_assistant/current_user/conversations/_find"`

Anonymization APIs:

- POST `"/api/security_ai_assistant/anonymization_fields/_bulk_action"`
- GET `"/api/security_ai_assistant/anonymization_fields/_find"`
  • Loading branch information
YulNaumenko authored Jul 12, 2024
1 parent 3df635e commit 1d5cf48
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 53 deletions.
12 changes: 7 additions & 5 deletions x-pack/packages/kbn-elastic-assistant-common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ export const ELASTIC_AI_ASSISTANT_INTERNAL_API_VERSION = '1';
export const ELASTIC_AI_ASSISTANT_URL = '/api/security_ai_assistant';
export const ELASTIC_AI_ASSISTANT_INTERNAL_URL = '/internal/elastic_assistant';

export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL = `${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/current_user/conversations`;
export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL = `${ELASTIC_AI_ASSISTANT_URL}/current_user/conversations`;
export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID = `${ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL}/{id}`;
export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID_MESSAGES = `${ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID}/messages`;

export const ELASTIC_AI_ASSISTANT_INTERNAL_CONVERSATIONS_URL = `${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/current_user/conversations`;
export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID_MESSAGES = `${ELASTIC_AI_ASSISTANT_INTERNAL_CONVERSATIONS_URL}/{id}/messages`;

export const ELASTIC_AI_ASSISTANT_CHAT_COMPLETE_URL = `${ELASTIC_AI_ASSISTANT_URL}/chat/complete`;

export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BULK_ACTION = `${ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL}/_bulk_action`;
export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BULK_ACTION = `${ELASTIC_AI_ASSISTANT_INTERNAL_CONVERSATIONS_URL}/_bulk_action`;
export const ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_FIND = `${ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL}/_find`;

export const ELASTIC_AI_ASSISTANT_PROMPTS_URL = `${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/prompts`;
export const ELASTIC_AI_ASSISTANT_PROMPTS_URL = `${ELASTIC_AI_ASSISTANT_URL}/prompts`;
export const ELASTIC_AI_ASSISTANT_PROMPTS_URL_BULK_ACTION = `${ELASTIC_AI_ASSISTANT_PROMPTS_URL}/_bulk_action`;
export const ELASTIC_AI_ASSISTANT_PROMPTS_URL_FIND = `${ELASTIC_AI_ASSISTANT_PROMPTS_URL}/_find`;

export const ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL = `${ELASTIC_AI_ASSISTANT_INTERNAL_URL}/anonymization_fields`;
export const ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL = `${ELASTIC_AI_ASSISTANT_URL}/anonymization_fields`;
export const ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_BULK_ACTION = `${ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL}/_bulk_action`;
export const ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_FIND = `${ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL}/_find`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('bulkUpdateAnonymizationFields', () => {
ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_BULK_ACTION,
{
method: 'POST',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
body: JSON.stringify({
create: [],
update: [],
Expand All @@ -71,7 +71,7 @@ describe('bulkUpdateAnonymizationFields', () => {
ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_BULK_ACTION,
{
method: 'POST',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
body: JSON.stringify({
create: [anonymizationField1, anonymizationField2],
update: [],
Expand All @@ -93,7 +93,7 @@ describe('bulkUpdateAnonymizationFields', () => {
ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_BULK_ACTION,
{
method: 'POST',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
body: JSON.stringify({
update: [anonymizationField1, anonymizationField2],
delete: { ids: [] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const bulkUpdateAnonymizationFields = async (
ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_BULK_ACTION,
{
method: 'POST',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
body: JSON.stringify(anonymizationFieldsActions),
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ describe('useFetchAnonymizationFields', () => {
const { waitForNextUpdate } = renderHook(() => useFetchAnonymizationFields());
await waitForNextUpdate();
expect(http.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/anonymization_fields/_find',
'/api/security_ai_assistant/anonymization_fields/_find',
{
method: 'GET',
query: {
page: 1,
per_page: 1000,
},
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
signal: undefined,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const CACHING_KEYS = [
ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_FIND,
QUERY.page,
QUERY.per_page,
API_VERSIONS.internal.v1,
API_VERSIONS.public.v1,
];

export const useFetchAnonymizationFields = (payload?: UseFetchAnonymizationFieldsParams) => {
Expand All @@ -50,7 +50,7 @@ export const useFetchAnonymizationFields = (payload?: UseFetchAnonymizationField
async () =>
http.fetch(ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_FIND, {
method: 'GET',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
query: QUERY,
signal: payload?.signal,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ describe('conversations api', () => {
await waitForNextUpdate();

expect(deleteProps.http.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/current_user/conversations/test',
'/api/security_ai_assistant/current_user/conversations/test',
{
method: 'DELETE',
signal: undefined,
version: '1',
version: '2023-10-31',
}
);
expect(toasts.addError).not.toHaveBeenCalled();
Expand All @@ -62,11 +62,11 @@ describe('conversations api', () => {
await waitForNextUpdate();

expect(getProps.http.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/current_user/conversations/test',
'/api/security_ai_assistant/current_user/conversations/test',
{
method: 'GET',
signal: undefined,
version: '1',
version: '2023-10-31',
}
);
expect(toasts.addError).not.toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getConversationById = async ({
try {
const response = await http.fetch(`${ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL}/${id}`, {
method: 'GET',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
signal,
});

Expand Down Expand Up @@ -84,7 +84,7 @@ export const getUserConversations = async ({
ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_FIND,
{
method: 'GET',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
signal,
}
);
Expand Down Expand Up @@ -125,7 +125,7 @@ export const createConversation = async ({
try {
const response = await http.post(ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL, {
body: JSON.stringify(conversation),
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
signal,
});

Expand Down Expand Up @@ -168,7 +168,7 @@ export const deleteConversation = async ({
try {
const response = await http.fetch(`${ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL}/${id}`, {
method: 'DELETE',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
signal,
});

Expand Down Expand Up @@ -237,7 +237,7 @@ export const updateConversation = async ({
headers: {
'Content-Type': 'application/json',
},
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
signal,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ describe('useFetchCurrentUserConversations', () => {
);
await waitForNextUpdate();
expect(defaultProps.http.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/current_user/conversations/_find',
'/api/security_ai_assistant/current_user/conversations/_find',
{
method: 'GET',
query: {
page: 1,
perPage: 100,
},
version: '1',
version: '2023-10-31',
signal: undefined,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const CONVERSATIONS_QUERY_KEYS = [
ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_FIND,
query.page,
query.perPage,
API_VERSIONS.internal.v1,
API_VERSIONS.public.v1,
];

export const useFetchCurrentUserConversations = ({
Expand All @@ -62,7 +62,7 @@ export const useFetchCurrentUserConversations = ({
async () =>
http.fetch<FetchConversationsResponse>(ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_FIND, {
method: 'GET',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
query,
signal,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('bulkUpdatePrompts', () => {

expect(httpMock.fetch).toHaveBeenCalledWith(ELASTIC_AI_ASSISTANT_PROMPTS_URL_BULK_ACTION, {
method: 'POST',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
body: JSON.stringify({
create: [],
update: [],
Expand All @@ -69,7 +69,7 @@ describe('bulkUpdatePrompts', () => {

expect(httpMock.fetch).toHaveBeenCalledWith(ELASTIC_AI_ASSISTANT_PROMPTS_URL_BULK_ACTION, {
method: 'POST',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
body: JSON.stringify({
create: [prompt1, prompt2],
update: [],
Expand All @@ -88,7 +88,7 @@ describe('bulkUpdatePrompts', () => {

expect(httpMock.fetch).toHaveBeenCalledWith(ELASTIC_AI_ASSISTANT_PROMPTS_URL_BULK_ACTION, {
method: 'POST',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
body: JSON.stringify({
update: [prompt1, prompt2],
delete: { ids: [] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const bulkUpdatePrompts = async (
ELASTIC_AI_ASSISTANT_PROMPTS_URL_BULK_ACTION,
{
method: 'POST',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
body: JSON.stringify(prompts),
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ describe('useFetchPrompts', () => {
await act(async () => {
const { waitForNextUpdate } = renderHook(() => useFetchPrompts());
await waitForNextUpdate();
expect(http.fetch).toHaveBeenCalledWith('/internal/elastic_assistant/prompts/_find', {
expect(http.fetch).toHaveBeenCalledWith('/api/security_ai_assistant/prompts/_find', {
method: 'GET',
query: {
page: 1,
per_page: 1000,
filter: 'consumer:*',
},
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
signal: undefined,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ export const useFetchPrompts = (payload?: UseFetchPromptsParams) => {
QUERY.page,
QUERY.per_page,
QUERY.filter,
API_VERSIONS.internal.v1,
API_VERSIONS.public.v1,
];

return useQuery<FindPromptsResponse, unknown, FindPromptsResponse>(
CACHING_KEYS,
async () =>
http.fetch(ELASTIC_AI_ASSISTANT_PROMPTS_URL_FIND, {
method: 'GET',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
query: QUERY,
signal: payload?.signal,
}),
Expand Down Expand Up @@ -87,7 +87,7 @@ export const getPrompts = async ({
try {
return await http.fetch<FindPromptsResponse>(ELASTIC_AI_ASSISTANT_PROMPTS_URL_FIND, {
method: 'GET',
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
signal,
});
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const bulkActionAnonymizationFieldsRoute = (
) => {
router.versioned
.post({
access: 'internal',
access: 'public',
path: ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_BULK_ACTION,
options: {
tags: ['access:securitySolution-updateAIAssistantAnonymization'],
Expand All @@ -129,7 +129,7 @@ export const bulkActionAnonymizationFieldsRoute = (
})
.addVersion(
{
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
validate: {
request: {
body: buildRouteValidationWithZod(PerformBulkActionRequestBody),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export const findAnonymizationFieldsRoute = (
) => {
router.versioned
.get({
access: 'internal',
access: 'public',
path: ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_FIND,
options: {
tags: ['access:elasticAssistant'],
},
})
.addVersion(
{
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
validate: {
request: {
query: buildRouteValidationWithZod(FindAnonymizationFieldsRequestQuery),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const buildBulkResponse = (
export const bulkPromptsRoute = (router: ElasticAssistantPluginRouter, logger: Logger) => {
router.versioned
.post({
access: 'internal',
access: 'public',
path: ELASTIC_AI_ASSISTANT_PROMPTS_URL_BULK_ACTION,
options: {
tags: ['access:elasticAssistant'],
Expand All @@ -123,7 +123,7 @@ export const bulkPromptsRoute = (router: ElasticAssistantPluginRouter, logger: L
})
.addVersion(
{
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
validate: {
request: {
body: buildRouteValidationWithZod(PerformBulkActionRequestBody),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import { UPGRADE_LICENSE_MESSAGE, hasAIAssistantLicense } from '../helpers';
export const findPromptsRoute = (router: ElasticAssistantPluginRouter, logger: Logger) => {
router.versioned
.get({
access: 'internal',
access: 'public',
path: ELASTIC_AI_ASSISTANT_PROMPTS_URL_FIND,
options: {
tags: ['access:elasticAssistant'],
},
})
.addVersion(
{
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
validate: {
request: {
query: buildRouteValidationWithZod(FindPromptsRequestQuery),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { performChecks } from '../helpers';
export const createConversationRoute = (router: ElasticAssistantPluginRouter): void => {
router.versioned
.post({
access: 'internal',
access: 'public',
path: ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL,

options: {
Expand All @@ -30,7 +30,7 @@ export const createConversationRoute = (router: ElasticAssistantPluginRouter): v
})
.addVersion(
{
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
validate: {
request: {
body: buildRouteValidationWithZod(ConversationCreateProps),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import { UPGRADE_LICENSE_MESSAGE, hasAIAssistantLicense } from '../helpers';
export const deleteConversationRoute = (router: ElasticAssistantPluginRouter) => {
router.versioned
.delete({
access: 'internal',
access: 'public',
path: ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID,
options: {
tags: ['access:elasticAssistant'],
},
})
.addVersion(
{
version: API_VERSIONS.internal.v1,
version: API_VERSIONS.public.v1,
validate: {
request: {
params: buildRouteValidationWithZod(DeleteConversationRequestParams),
Expand Down
Loading

0 comments on commit 1d5cf48

Please sign in to comment.